coze-bridge 0.2.7-alpha.11 → 0.2.7-alpha.12
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 +91 -91
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,25 +5,25 @@ 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&&ms(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(_s){let d=
|
|
13
|
-
`),{cause:
|
|
14
|
-
`,r)}var hn=rt(()=>{"use strict"});import{promises as Wl,readdirSync as mm}from"node:fs";import{homedir as wm}from"node:os";import{sep as _m,join as Ce,resolve as Kl}from"node:path";function Z(t){let e=t??wm(),r=Ce(e,".coze"),i=Ce(r,"bridge"),o=Ce(i,"lib"),c=Ce(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ce(o,"index.js"),binDir:Ce(i,"bin"),pidFile:Ce(i,"bridge.pid"),portFile:Ce(i,"bridge.port"),tokenFile:Ce(i,"bridge.token"),patTokenFile:Ce(i,"pat-token"),agentEnvFile:Ce(i,"agent-env.json"),logFile:Ce(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ce(c,"daemon-stdio.log"),installLock:Ce(i,"install.lock"),configFile:Ce(i,"config.json"),agentsRoot:Ce(r,"agents")}}function Ve(t,e=Z()){let r=Ce(e.agentsRoot,t);return{root:r,config:Ce(r,"config.json"),workspace:Ce(r,"workspace"),logs:Ce(r,"logs")}}function Ss(t=Z()){try{return mm(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function li(t,e){let r=await Wl.realpath(Kl(t)).catch(()=>null);if(!r)return!1;let i=await Wl.realpath(Kl(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+_m)}var Re=rt(()=>{"use strict"});var As={};La(As,{AGENT_CONFIG_FILE_MODE:()=>Is,enforceAgentConfigMode:()=>Em,loadAgentConfig:()=>Pe,persistAgentSessions:()=>ui,persistAgentSkills:()=>fi,saveAgentConfig:()=>Ue});import{chmod as ym,stat as bm}from"node:fs/promises";function Pe(t,e){return ln(Ve(t,e).config)}function Ue(t,e){return fn(Ve(t.agentId,e).config,t,{mode:Is})}async function Em(t,e){if(process.platform==="win32")return;let r=Ve(t,e).config;try{let i=await bm(r);if(!i.isFile())return;let o=i.mode&511;o!==Is&&(await ym(r,Is),$l.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;$l.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ui(t,e,r){let i=await Pe(t,r);i&&(i.sessions=Object.fromEntries(e),await Ue(i,r))}async function fi(t,e,r){let i=await Pe(t,r);i&&(i.skills=e,await Ue(i,r))}var $l,Is,xn=rt(()=>{"use strict";hn();ne();Re();$l=j("agent-config"),Is=384});var ja=ce((PA,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 Ts=ce(Xl=>{var Yl={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 Tm(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(Yl))Xl[t]=Tm(Yl[t])});var ru=ce((OA,nu)=>{var Cm=pe("fs"),Be=pe("path"),Ql=ja(),Rm=Ts(),Pm=typeof process=="object"&&process.platform==="win32",eu=t=>typeof t=="object"&&t!==null,tu=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 Ie(t){this.sep=Be.sep,this.fs=Cm,eu(t)&&eu(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}nu.exports=Ie;Ie.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 Rm.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ie.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=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,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var x=Be.dirname(t);c.fs.exists(x,function(g){g||c.makeDir(x),c.fs.open(t,"w",438,function(m,S){m?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ie.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Be.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&d.push(Be.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(f,o,c)))}),d}return r(t,void 0,!0)};Ie.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=Be.join(t,u),r.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Be.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(g,m){if(g)return e(g);i=i.concat(m),--d||e(null,i)}):--d||e(null,i))})})})};Ie.prototype.getAttributes=function(){};Ie.prototype.setAttributes=function(){};Ie.crc32update=function(t,e){return tu[(t^e)&255]^t>>>8};Ie.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ie.crc32update(r,t[i++]);return~r>>>0};Ie.methodToString=function(t){switch(t){case Ql.STORED:return"STORED ("+t+")";case Ql.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 r=t.length>>>0;for(let i=r-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 r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Be.normalize(Be.join(t,r.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,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ie.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};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,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};Ie.isWin=Pm;Ie.crcTable=tu});var su=ce((LA,iu)=>{var Dm=pe("path");iu.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=Dm.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 au=ce((NA,ou)=>{ou.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var mr=ce((MA,gr)=>{gr.exports=ru();gr.exports.Constants=ja();gr.exports.Errors=Ts();gr.exports.FileAttr=su();gr.exports.decoder=au()});var du=ce((BA,cu)=>{var pn=mr(),z=pn.Constants;cu.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,f=0,x=0,g=0,m=0,S=0,_=0,v=0;t|=pn.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,O=b=>Math.max(0,b)&255;return o=pn.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 pn.fromDOS2Date(this.timeval)},set time(b){b=new Date(b),this.timeval=pn.fromDate2DOS(b)},get timeval(){return o},set timeval(b){o=A(b)},get timeHighByte(){return O(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 f},set fileNameLength(b){f=b},get extraLength(){return x},set extraLength(b){x=b},get extraLocalLength(){return I.extraLen},set extraLocalLength(b){I.extraLen=b},get commentLength(){return g},set commentLength(b){g=b},get diskNumStart(){return m},set diskNumStart(b){m=A(b)},get inAttr(){return S},set inAttr(b){S=A(b)},get attr(){return _},set attr(b){_=A(b)},get fileAttr(){return(_||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+f+x+g},get realDataOffset(){return v+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(b){var P=b.slice(v,v+z.LOCHDR);if(P.readUInt32LE(0)!==z.LOCSIG)throw pn.Errors.INVALID_LOC();I.version=P.readUInt16LE(z.LOCVER),I.flags=P.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=P.readUInt16LE(z.LOCHOW),I.time=P.readUInt32LE(z.LOCTIM),I.crc=P.readUInt32LE(z.LOCCRC),I.compressedSize=P.readUInt32LE(z.LOCSIZ),I.size=P.readUInt32LE(z.LOCLEN),I.fnameLen=P.readUInt16LE(z.LOCNAM),I.extraLen=P.readUInt16LE(z.LOCEXT);let L=v+z.LOCHDR+I.fnameLen,F=L+I.extraLen;return b.slice(L,F)},loadFromBinary:function(b){if(b.length!==z.CENHDR||b.readUInt32LE(0)!==z.CENSIG)throw pn.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),f=b.readUInt16LE(z.CENNAM),x=b.readUInt16LE(z.CENEXT),g=b.readUInt16LE(z.CENCOM),m=b.readUInt16LE(z.CENDSK),S=b.readUInt16LE(z.CENATT),_=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(f,z.LOCNAM),b.writeUInt16LE(I.extraLen,z.LOCEXT),b},centralHeaderToBinary:function(){var b=Buffer.alloc(z.CENHDR+f+x+g);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(f,z.CENNAM),b.writeUInt16LE(x,z.CENEXT),b.writeUInt16LE(g,z.CENCOM),b.writeUInt16LE(m,z.CENDSK),b.writeUInt16LE(S,z.CENATT),b.writeUInt32LE(_,z.CENATX),b.writeUInt32LE(v,z.CENOFF),b},toJSON:function(){let b=function(P){return P+" bytes"};return{made:t,version:e,flags:r,method:pn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:b(d),size:b(u),fileNameLength:b(f),extraLength:b(x),commentLength:b(g),diskNumStart:m,inAttr:S,attr:_,offset:v,centralHeaderSize:b(z.CENHDR+f+x+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var uu=ce((FA,lu)=>{var wr=mr(),Ee=wr.Constants;lu.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 wr.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=wr.readBigUInt64LE(c,Ee.ZIP64SUB),e=wr.readBigUInt64LE(c,Ee.ZIP64TOT),r=wr.readBigUInt64LE(c,Ee.ZIP64SIZE),i=wr.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 f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wa=ce(qa=>{qa.EntryHeader=du();qa.MainHeader=uu()});var hu=ce((UA,fu)=>{fu.exports=function(t){var e=pe("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var x=0;x<c.length;x++){var g=c[x];g.copy(u,f),f+=g.length}i&&i(u)}),o.end(t)}}}});var pu=ce((HA,xu)=>{var Om=+(process.versions?process.versions.node:"").split(".")[0]||0;xu.exports=function(t,e){var r=pe("zlib");let i=Om>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],u=0;c.on("data",function(f){d.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var g=0;g<d.length;g++){var m=d[g];m.copy(f,x),x+=m.length}o&&o(f)}),c.end(t)}}}});var yu=ce((GA,_u)=>{"use strict";var{randomFillSync:gu}=pe("crypto"),Lm=Ts(),Nm=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}),wu=(t,e)=>Math.imul(t,e)>>>0,mu=(t,e)=>Nm[(t^e)&255]^t>>>8,hi=()=>typeof gu=="function"?gu(Buffer.alloc(12)):hi.node();hi.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 Cs={genSalt:hi};function Rs(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])}Rs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=mu(e[0],t),e[1]+=e[0]&255,e[1]=wu(e[1],134775813)+1,e[2]=mu(e[2],e[1]>>>24),t};Rs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return wu(t,t^1)>>8&255};function Mm(t){let e=new Rs(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 Bm(t){let e=new Rs(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 Fm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Mm(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Lm.WRONG_PASSWORD();return i(t.slice(12))}function zm(t){Buffer.isBuffer(t)&&t.length>=12?Cs.genSalt=function(){return t.slice(0,12)}:t==="node"?Cs.genSalt=hi.node:Cs.genSalt=hi}function Um(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Bm(r),c=Cs.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)}_u.exports={decrypt:Fm,encrypt:Um,_salter:zm}});var bu=ce(Ps=>{Ps.Deflater=hu();Ps.Inflater=pu();Ps.ZipCrypto=yu()});var $a=ce((qA,Eu)=>{var de=mr(),Hm=Wa(),Ae=de.Constants,Ka=bu();Eu.exports=function(t,e){var r=new Hm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let g=t,m=typeof g.decoder=="object"?g.decoder:de.decoder;x=m.hasOwnProperty("efs")?m.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(b){if(!r.flags_desc&&!r.localHeader.flags_desc){if(de.crc32(b)!==r.localHeader.crc)return!1}else{let P={},L=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(L)==Ae.LOCSIG||e.readUInt32LE(L)==Ae.CENSIG)throw de.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==Ae.EXTSIG)P.crc=e.readUInt32LE(L+Ae.EXTCRC),P.compressedSize=e.readUInt32LE(L+Ae.EXTSIZ),P.size=e.readUInt32LE(L+Ae.EXTLEN);else if(e.readUInt16LE(L+12)===19280)P.crc=e.readUInt32LE(L+Ae.EXTCRC-4),P.compressedSize=e.readUInt32LE(L+Ae.EXTSIZ-4),P.size=e.readUInt32LE(L+Ae.EXTLEN-4);else throw de.Errors.DESCRIPTOR_UNKNOWN();if(P.compressedSize!==r.compressedSize||P.size!==r.size||P.crc!==r.crc)throw de.Errors.DESCRIPTOR_FAULTY();if(de.crc32(b)!==P.crc)return!1}return!0}function v(b,P,L){if(typeof P>"u"&&typeof b=="string"&&(L=b,b=void 0),c)return b&&P&&P(Buffer.alloc(0),de.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=S();if(F.length===0)return b&&P&&P(F),F;if(r.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw de.Errors.INVALID_PASS_PARAM();F=Ka.ZipCrypto.decrypt(F,r,L)}var M=Buffer.alloc(r.size);switch(r.method){case de.Constants.STORED:if(F.copy(M),_(M))return b&&P&&P(M),M;throw b&&P&&P(M,de.Errors.BAD_CRC()),de.Errors.BAD_CRC();case de.Constants.DEFLATED:var J=new Ka.Inflater(F,r.size);if(b)J.inflateAsync(function(V){V.copy(V,0),P&&(_(V)?P(V):P(V,de.Errors.BAD_CRC()))});else{if(J.inflate(M).copy(M,0),!_(M))throw de.Errors.BAD_CRC(`"${m.decode(i)}"`);return M}break;default:throw b&&P&&P(Buffer.alloc(0),de.Errors.UNKNOWN_METHOD()),de.Errors.UNKNOWN_METHOD()}}function I(b,P){if((!d||!d.length)&&Buffer.isBuffer(e))return b&&P&&P(S()),S();if(d.length&&!c){var L;switch(r.method){case de.Constants.STORED:return r.compressedSize=r.size,L=Buffer.alloc(d.length),d.copy(L),b&&P&&P(L),L;default:case de.Constants.DEFLATED:var F=new Ka.Deflater(d);if(b)F.deflateAsync(function(J){L=Buffer.alloc(J.length),r.compressedSize=J.length,J.copy(L),P&&P(L)});else{var M=F.deflate();return r.compressedSize=M.length,M}F=null;break}}else if(b&&P)P(Buffer.alloc(0));else return Buffer.alloc(0)}function A(b,P){return de.readBigUInt64LE(b,P)}function C(b){try{for(var P=0,L,F,M;P+4<b.length;)L=b.readUInt16LE(P),P+=2,F=b.readUInt16LE(P),P+=2,M=b.slice(P,P+F),P+=F,Ae.ID_ZIP64===L&&O(M)}catch{throw de.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(b){var P,L,F,M;b.length>=Ae.EF_ZIP64_SCOMP&&(P=A(b,Ae.EF_ZIP64_SUNCOMP),r.size===Ae.EF_ZIP64_OR_32&&(r.size=P)),b.length>=Ae.EF_ZIP64_RHO&&(L=A(b,Ae.EF_ZIP64_SCOMP),r.compressedSize===Ae.EF_ZIP64_OR_32&&(r.compressedSize=L)),b.length>=Ae.EF_ZIP64_DSN&&(F=A(b,Ae.EF_ZIP64_RHO),r.offset===Ae.EF_ZIP64_OR_32&&(r.offset=F)),b.length>=Ae.EF_ZIP64_DSN+4&&(M=b.readUInt32LE(Ae.EF_ZIP64_DSN),r.diskNumStart===Ae.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return m.decode(i)},get rawEntryName(){return i},set entryName(b){i=de.toBuffer(b,m.encode);var P=i[i.length-1];c=P===47||P===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 m.decode(o)},set comment(b){if(o=de.toBuffer(b,m.encode),r.commentLength=o.length,o.length>65535)throw de.Errors.COMMENT_TOO_LONG()},get name(){var b=m.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,P){r.changed?b(d):v(!0,b,P)},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(),P=de.Constants.CENHDR;return i.copy(b,P),P+=i.length,u.copy(b,P),P+=r.extraLength,o.copy(b,P),b},packLocalHeader:function(){let b=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let P=r.localHeaderToBinary(),L=Buffer.alloc(P.length+i.length+r.extraLocalLength);return P.copy(L,b),b+=P.length,i.copy(L,b),b+=i.length,f.copy(L,b),b+=f.length,L},toJSON:function(){let b=function(P){return"<"+(P&&P.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 Iu=ce((WA,Su)=>{var vu=$a(),Gm=Wa(),Je=mr();Su.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Gm.MainHeader,d=!1,u=null;let f=new Set,x=e,{noSort:g,decoder:m}=x;t?v(x.readEntries):d=!0;function S(){let A=new Set;for(let C of Object.keys(i)){let O=C.split("/");if(O.pop(),!!O.length)for(let b=0;b<O.length;b++){let P=O.slice(0,b+1).join("/")+"/";A.add(P)}}for(let C of A)if(!(C in i)){let O=new vu(x);O.entryName=C,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,f.add(O)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/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 O=A,b=new vu(x,t);b.header=t.slice(O,O+=Je.Constants.CENHDR),b.entryName=t.slice(O,O+=b.header.fileNameLength),b.header.extraLength&&(b.extra=t.slice(O,O+=b.header.extraLength)),b.header.commentLength&&(b.comment=t.slice(O,O+b.header.commentLength)),A+=b.header.centralHeaderSize,r[C]=b,i[b.entryName]=b}f.clear(),S()}function v(A){var C=t.length-Je.Constants.ENDHDR,O=Math.max(0,C-65535),b=O,P=t.length,L=-1,F=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(O=0),C;C>=b;C--)if(t[C]===80){if(t.readUInt32LE(C)===Je.Constants.ENDSIG){L=C,F=C,P=C+Je.Constants.ENDHDR,b=C-Je.Constants.END64HDR;continue}if(t.readUInt32LE(C)===Je.Constants.END64SIG){b=O;continue}if(t.readUInt32LE(C)===Je.Constants.ZIP64SIG){L=C,P=C+Je.readBigUInt64LE(t,C+Je.Constants.ZIP64SIZE)+Je.Constants.ZIP64LEAD;break}}if(L==-1)throw Je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(L,P)),c.commentLength&&(o=t.slice(F+Je.Constants.ENDHDR)),A&&_()}function I(){r.length>1&&!g&&r.sort((A,C)=>A.entryName.toLowerCase().localeCompare(C.entryName.toLowerCase()))}return{get entries(){return d||_(),r.filter(A=>!f.has(A))},get comment(){return m.decode(o)},set comment(A){o=Je.toBuffer(A,m.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||_(),i[A]||null},setEntry:function(A){d||_(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,C=!0){d||_();let O=i[A];this.getEntryChildren(O,C).map(P=>P.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||_();let C=i[A],O=r.indexOf(C);O>=0&&(r.splice(O,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,C=!0){if(d||_(),typeof A=="object")if(A.isDirectory&&C){let O=[],b=A.entryName;for(let P of r)P.entryName.startsWith(b)&&O.push(P);return O}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||_(),I();let A=[],C=[],O=0,b=0;c.size=0,c.offset=0;let P=0;for(let M of this.entries){let J=M.getCompressedData();M.header.offset=b;let V=M.packLocalHeader(),re=V.length+J.length;b+=re,A.push(V),A.push(J);let X=M.packCentralHeader();C.push(X),c.size+=X.length,O+=re+X.length,P++}O+=c.mainHeaderSize,c.offset=b,c.totalEntries=P,b=0;let L=Buffer.alloc(O);for(let M of A)M.copy(L,b),b+=M.length;for(let M of C)M.copy(L,b),b+=M.length;let F=c.toBinary();return o&&o.copy(F,Je.Constants.ENDHDR),F.copy(L,b),t=L,d=!1,L},toAsyncBuffer:function(A,C,O,b){try{d||_(),I();let P=[],L=[],F=0,M=0,J=0;c.size=0,c.offset=0;let V=function(re){if(re.length>0){let X=re.shift(),se=X.entryName+X.extra.toString();O&&O(se),X.getCompressedDataAsync(function(ae){b&&b(se),X.header.offset=M;let D=X.packLocalHeader(),U=D.length+ae.length;M+=U,P.push(D),P.push(ae);let W=X.packCentralHeader();L.push(W),c.size+=W.length,F+=U+W.length,J++,V(re)})}else{F+=c.mainHeaderSize,c.offset=M,c.totalEntries=J,M=0;let X=Buffer.alloc(F);P.forEach(function(ae){ae.copy(X,M),M+=ae.length}),L.forEach(function(ae){ae.copy(X,M),M+=ae.length});let se=c.toBinary();o&&o.copy(se,Je.Constants.ENDHDR),se.copy(X,M),t=X,d=!1,A(X)}};V(Array.from(this.entries))}catch(P){C(P)}}}}});var Tu=ce((KA,ku)=>{var Se=mr(),ve=pe("path"),jm=$a(),qm=Iu(),Bn=(...t)=>Se.findLast(t,e=>typeof e=="boolean"),Au=(...t)=>Se.findLast(t,e=>typeof e=="string"),Wm=(...t)=>Se.findLast(t,e=>typeof e=="function"),Km={noSort:!1,readEntries:!1,method:Se.Constants.NONE,fs:null};ku.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Km);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 qm(r,i),{canonical:d,sanitize:u,zipnamefix:f}=Se;function x(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(ve.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function g(_){let{join:v,normalize:I,sep:A}=ve.posix;return v(ve.isAbsolute(_)?"/":".",I(A+_.split("\\").join(A)+A))}function m(_){return _ instanceof RegExp?(function(v){return function(I){return v.test(I)}})(_):typeof _!="function"?()=>!0:_}let S=(_,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",ve.relative(_,v)+I};return{readFile:function(_,v){var I=x(_);return I&&I.getData(v)||null},childCount:function(_){let v=x(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var I=x(_);I?I.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var I=x(_);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,I){var A=x(_);A?A.getDataAsync(function(C,O){if(O){v(C,O);return}C&&C.length?v(C.toString(I||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var I=x(_);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(_){var v=x(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var I=x(_);I&&(I.comment=v)},getZipEntryComment:function(_){var v=x(_);return v&&v.comment||""},updateFile:function(_,v){var I=x(_);I&&I.setData(v)},addLocalFile:function(_,v,I,A){if(o.fs.existsSync(_)){v=v?g(v):"";let C=ve.win32.basename(ve.win32.normalize(_));v+=I||C;let O=o.fs.statSync(_),b=O.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);O.isDirectory()&&(v+=o.sep),this.addFile(v,b,A,O)}else throw Se.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let I=ve.resolve(_.localPath),{comment:A}=_,{zipPath:C,zipName:O}=_,b=this;o.fs.stat(I,function(P,L){if(P)return v(P,!1);C=C?g(C):"";let F=ve.win32.basename(ve.win32.normalize(I));if(C+=O||F,L.isFile())o.fs.readFile(I,function(M,J){return M?v(M,!1):(b.addFile(C,J,A,L),setImmediate(v,void 0,!0))});else if(L.isDirectory())return C+=o.sep,b.addFile(C,Buffer.alloc(0),A,L),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,I){if(I=m(I),v=v?g(v):"",_=ve.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),C=this;if(A.length)for(let O of A){let b=ve.join(v,S(_,O));I(b)&&C.addLocalFile(O,ve.dirname(b))}}else throw Se.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,I,A){A=m(A),I=I?g(I):"",_=ve.normalize(_);var C=this;o.fs.open(_,"r",function(O){if(O&&O.code==="ENOENT")v(void 0,Se.Errors.FILE_NOT_FOUND(_));else if(O)v(void 0,O);else{var b=o.findFiles(_),P=-1,L=function(){if(P+=1,P<b.length){var F=b[P],M=S(_,F).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(F,function(J,V){J&&v(void 0,J),V.isFile()?o.fs.readFile(F,function(re,X){re?v(void 0,re):(C.addFile(I+M,X,"",V),L())}):(C.addFile(I+M+"/",Buffer.alloc(0),"",V),L())}):process.nextTick(()=>{L()})}else v(!0,void 0)};L()}})},addLocalFolderAsync2:function(_,v){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=ve.resolve(g(_.localPath));let{zipPath:A,filter:C,namefix:O}=_;C instanceof RegExp?C=(function(L){return function(F){return L.test(F)}})(C):typeof C!="function"&&(C=function(){return!0}),A=A?g(A):"",O=="latin1"&&(O=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=L=>L);let b=L=>ve.join(A,O(S(localPath,L))),P=L=>ve.win32.basename(ve.win32.normalize(O(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?v(void 0,Se.Errors.FILE_NOT_FOUND(localPath)):L?v(void 0,L):o.findFilesAsync(localPath,function(F,M){if(F)return v(F);M=M.filter(J=>C(b(J))),M.length||v(void 0,!1),setImmediate(M.reverse().reduce(function(J,V){return function(re,X){if(re||X===!1)return setImmediate(J,re,!1);I.addLocalFileAsync({localPath:V,zipPath:ve.dirname(b(V)),zipName:P(V)},J)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(C,O)=>{C&&A(C),O&&I(this)})})},addFile:function(_,v,I,A){_=f(_);let C=x(_),O=C!=null;O||(C=new jm(i),C.entryName=_),C.comment=I||"";let b=typeof A=="object"&&A instanceof o.fs.Stats;b&&(C.header.time=A.mtime);var P=C.isDirectory?16:0;let L=C.isDirectory?16384:32768;return b?L|=4095&A.mode:typeof A=="number"?L|=4095&A:L|=C.isDirectory?493:420,P=(P|L<<16)>>>0,C.attr=P,C.setData(v),O||c.setEntry(C),C},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return x(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,I,A,C,O){A=Bn(!1,A),C=Bn(!1,C),I=Bn(!0,I),O=Au(C,O);var b=x(_);if(!b)throw Se.Errors.NO_ENTRY();var P=d(b.entryName),L=u(v,O&&!b.isDirectory?O:I?P:ve.basename(P));if(b.isDirectory){var F=c.getEntryChildren(b);return F.forEach(function(V){if(V.isDirectory)return;var re=V.getData();if(!re)throw Se.Errors.CANT_EXTRACT_FILE();var X=d(V.entryName),se=u(v,I?X:ve.basename(X));let ae=C?V.header.fileAttr:void 0;o.writeFileTo(se,re,A,ae)}),!0}var M=b.getData(c.password);if(!M)throw Se.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!A)throw Se.Errors.CANT_OVERRIDE();let J=C?_.header.fileAttr:void 0;return o.writeFileTo(L,M,A,J),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,v,I,A){if(I=Bn(!1,I),A=Au(I,A),v=Bn(!1,v),!c)throw Se.Errors.NO_ZIP();c.entries.forEach(function(C){var O=u(_,d(C.entryName));if(C.isDirectory){o.makeDir(O);return}var b=C.getData(A);if(!b)throw Se.Errors.CANT_EXTRACT_FILE();let P=I?C.header.fileAttr:void 0;o.writeFileTo(O,b,v,P);try{o.fs.utimesSync(O,C.header.time,C.header.time)}catch{throw Se.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,I,A){if(A=Wm(v,I,A),I=Bn(!1,I),v=Bn(!1,v),!A)return new Promise((L,F)=>{this.extractAllToAsync(_,v,I,function(M){M?F(M):L(this)})});if(!c){A(Se.Errors.NO_ZIP());return}_=ve.resolve(_);let C=L=>u(_,ve.normalize(d(L.entryName))),O=(L,F)=>new Error(L+': "'+F+'"'),b=[],P=[];c.entries.forEach(L=>{L.isDirectory?b.push(L):P.push(L)});for(let L of b){let F=C(L),M=I?L.header.fileAttr:void 0;try{o.makeDir(F),M&&o.fs.chmodSync(F,M),o.fs.utimesSync(F,L.header.time,L.header.time)}catch{A(O("Unable to create folder",F))}}P.reverse().reduce(function(L,F){return function(M){if(M)L(M);else{let J=ve.normalize(d(F.entryName)),V=u(_,J);F.getDataAsync(function(re,X){if(X)L(X);else if(!re)L(Se.Errors.CANT_EXTRACT_FILE());else{let se=I?F.header.fileAttr:void 0;o.writeFileToAsync(V,re,v,se,function(ae){ae||L(O("Unable to write file",V)),o.fs.utimes(V,F.header.time,F.header.time,function(D){D?L(O("Unable to set times",V)):L()})})}})}}},A)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(_,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((C,O)=>{!_&&i.filename&&(_=i.filename),_||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(b=>{let P=L=>L?C(L):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,b,I,A,P)},O)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,I,A){return typeof _=="function"?(c.toAsyncBuffer(_,v,I,A),null):c.compressToBuffer()}}}});import{execFile as Y_,spawn as X_,spawnSync as l2}from"node:child_process";import{promisify as Q_}from"node:util";function ty(t){if(process.platform!=="win32")return!1;if(Jf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Jf,"").toLowerCase();return ey.has(r)}function Zf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return ty(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function st(t,e=[],r={}){return X_(t,e,Zf(t,r))}function Yf(t,e=[],r={}){return ny(t,e,Zf(t,r))}var ey,Jf,ny,Zt=rt(()=>{"use strict";ey=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Jf=/\.(cmd|bat|ps1)$/i;ny=Q_(Y_)});var Xt=ce((ZR,Bh)=>{"use strict";var Nh=["nodebuffer","arraybuffer","fragments"],Mh=typeof Blob<"u";Mh&&Nh.push("blob");Bh.exports={BINARY_TYPES:Nh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Mh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ts=ce((YR,Ho)=>{"use strict";var{EMPTY_BUFFER:ev}=Xt(),kd=Buffer[Symbol.species];function tv(t,e){if(t.length===0)return ev;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 kd(r.buffer,r.byteOffset,i):r}function Fh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function zh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function nv(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Td(t){if(Td.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new kd(t):ArrayBuffer.isView(t)?e=new kd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Td.readOnly=!1),e}Ho.exports={concat:tv,mask:Fh,toArrayBuffer:nv,toBuffer:Td,unmask:zh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=pe("bufferutil");Ho.exports.mask=function(e,r,i,o,c){c<48?Fh(e,r,i,o,c):t.mask(e,r,i,o,c)},Ho.exports.unmask=function(e,r){e.length<32?zh(e,r):t.unmask(e,r)}}catch{}});var Gh=ce((XR,Hh)=>{"use strict";var Uh=Symbol("kDone"),Cd=Symbol("kRun"),Rd=class{constructor(e){this[Uh]=()=>{this.pending--,this[Cd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Cd]()}[Cd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Uh])}}};Hh.exports=Rd});var Wr=ce((QR,Kh)=>{"use strict";var ns=pe("zlib"),jh=ts(),rv=Gh(),{kStatusCode:qh}=Xt(),iv=Buffer[Symbol.species],sv=Buffer.from([0,0,255,255]),jo=Symbol("permessage-deflate"),Qt=Symbol("total-length"),jr=Symbol("callback"),Dn=Symbol("buffers"),qr=Symbol("error"),Go,Pd=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,!Go){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Go=new rv(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[jr];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){Go.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){Go.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"?ns.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=ns.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[jo]=this,this._inflate[Qt]=0,this._inflate[Dn]=[],this._inflate.on("error",av),this._inflate.on("data",Wh)}this._inflate[jr]=i,this._inflate.write(e),r&&this._inflate.write(sv),this._inflate.flush(()=>{let c=this._inflate[qr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=jh.concat(this._inflate[Dn],this._inflate[Qt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Qt]=0,this._inflate[Dn]=[],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"?ns.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=ns.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Qt]=0,this._deflate[Dn]=[],this._deflate.on("data",ov)}this._deflate[jr]=i,this._deflate.write(e),this._deflate.flush(ns.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=jh.concat(this._deflate[Dn],this._deflate[Qt]);r&&(c=new iv(c.buffer,c.byteOffset,c.length-4)),this._deflate[jr]=null,this._deflate[Qt]=0,this._deflate[Dn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Kh.exports=Pd;function ov(t){this[Dn].push(t),this[Qt]+=t.length}function Wh(t){if(this[Qt]+=t.length,this[jo]._maxPayload<1||this[Qt]<=this[jo]._maxPayload){this[Dn].push(t);return}this[qr]=new RangeError("Max payload size exceeded"),this[qr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[qr][qh]=1009,this.removeListener("data",Wh),this.reset()}function av(t){if(this[jo]._inflate=null,this[qr]){this[jr](this[qr]);return}t[qh]=1007,this[jr](t)}});var Kr=ce((eP,qo)=>{"use strict";var{isUtf8:$h}=pe("buffer"),{hasBlob:cv}=Xt(),dv=[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 lv(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Dd(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 uv(t){return cv&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}qo.exports={isBlob:uv,isValidStatusCode:lv,isValidUTF8:Dd,tokenChars:dv};if($h)qo.exports.isValidUTF8=function(t){return t.length<24?Dd(t):$h(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=pe("utf-8-validate");qo.exports.isValidUTF8=function(e){return e.length<32?Dd(e):t(e)}}catch{}});var Bd=ce((tP,ex)=>{"use strict";var{Writable:fv}=pe("stream"),Vh=Wr(),{BINARY_TYPES:hv,EMPTY_BUFFER:Jh,kStatusCode:xv,kWebSocket:pv}=Xt(),{concat:Od,toArrayBuffer:gv,unmask:mv}=ts(),{isValidStatusCode:wv,isValidUTF8:Zh}=Kr(),Wo=Buffer[Symbol.species],pt=0,Yh=1,Xh=2,Qh=3,Ld=4,Nd=5,Ko=6,Md=class extends fv{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hv[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[pv]=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=pt}_write(e,r,i){if(this._opcode===8&&this._state==pt)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 Wo(i.buffer,i.byteOffset+e,i.length-e),new Wo(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 Wo(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 pt:this.getInfo(e);break;case Yh:this.getPayloadLength16(e);break;case Xh:this.getPayloadLength64(e);break;case Qh:this.getMask();break;case Ld:this.getData(e);break;case Nd:case Ko:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[Vh.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=Yh:this._payloadLength===127?this._state=Xh: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=Qh:this._state=Ld}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Ld}getData(e){let r=Jh;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&&mv(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Nd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[Vh.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===pt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=pt;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=Od(i,r):this._binaryType==="arraybuffer"?o=gv(Od(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=pt):(this._state=Ko,setImmediate(()=>{this.emit("message",o,!0),this._state=pt,this.startLoop(e)}))}else{let o=Od(i,r);if(!this._skipUTF8Validation&&!Zh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===Nd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=pt):(this._state=Ko,setImmediate(()=>{this.emit("message",o,!1),this._state=pt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Jh),this.end();else{let i=e.readUInt16BE(0);if(!wv(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Wo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Zh(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=pt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=pt):(this._state=Ko,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=pt,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[xv]=o,d}};ex.exports=Md});var Ud=ce((rP,rx)=>{"use strict";var{Duplex:nP}=pe("stream"),{randomFillSync:_v}=pe("crypto"),tx=Wr(),{EMPTY_BUFFER:yv,kWebSocket:bv,NOOP:Ev}=Xt(),{isBlob:$r,isValidStatusCode:vv}=Kr(),{mask:nx,toBuffer:er}=ts(),gt=Symbol("kByteLength"),Sv=Buffer.alloc(4),$o=8*1024,tr,Vr=$o,It=0,Iv=1,Av=2,Fd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=It,this.onerror=Ev,this[bv]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||Sv,r.generateMask?r.generateMask(i):(Vr===$o&&(tr===void 0&&(tr=Buffer.alloc($o)),_v(tr,0,$o),Vr=0),i[0]=tr[Vr++],i[1]=tr[Vr++],i[2]=tr[Vr++],i[3]=tr[Vr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[gt]!==void 0?u=r[gt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=f,f===126?x.writeUInt16BE(u,2):f===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(nx(e,i,x,c,u),[x]):(nx(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=yv;else{if(typeof e!="number"||!vv(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={[gt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==It?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):$r(e)?(o=e.size,c=!1):(e=er(e),o=e.length,c=er.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};$r(e)?this._state!==It?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==It?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):$r(e)?(o=e.size,c=!1):(e=er(e),o=e.length,c=er.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};$r(e)?this._state!==It?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==It?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[tx.extensionName],c=r.binary?2:1,d=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):$r(e)?(u=e.size,f=!1):(e=er(e),u=e.length,f=er.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={[gt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:d};$r(e)?this._state!==It?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==It?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[gt],this._state=Av,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(zd,this,u,o);return}this._bufferedBytes-=i[gt];let d=er(c);r?this.dispatch(d,r,i,o):(this._state=It,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(kv,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[tx.extensionName];this._bufferedBytes+=i[gt],this._state=Iv,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");zd(this,f,o);return}this._bufferedBytes-=i[gt],this._state=It,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===It&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][gt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][gt],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)}};rx.exports=Fd;function zd(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 kv(t,e,r){zd(t,e,r),t.onerror(e)}});var fx=ce((iP,ux)=>{"use strict";var{kForOnEventAttribute:rs,kListener:Hd}=Xt(),ix=Symbol("kCode"),sx=Symbol("kData"),ox=Symbol("kError"),ax=Symbol("kMessage"),cx=Symbol("kReason"),Jr=Symbol("kTarget"),dx=Symbol("kType"),lx=Symbol("kWasClean"),en=class{constructor(e){this[Jr]=null,this[dx]=e}get target(){return this[Jr]}get type(){return this[dx]}};Object.defineProperty(en.prototype,"target",{enumerable:!0});Object.defineProperty(en.prototype,"type",{enumerable:!0});var nr=class extends en{constructor(e,r={}){super(e),this[ix]=r.code===void 0?0:r.code,this[cx]=r.reason===void 0?"":r.reason,this[lx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[ix]}get reason(){return this[cx]}get wasClean(){return this[lx]}};Object.defineProperty(nr.prototype,"code",{enumerable:!0});Object.defineProperty(nr.prototype,"reason",{enumerable:!0});Object.defineProperty(nr.prototype,"wasClean",{enumerable:!0});var Zr=class extends en{constructor(e,r={}){super(e),this[ox]=r.error===void 0?null:r.error,this[ax]=r.message===void 0?"":r.message}get error(){return this[ox]}get message(){return this[ax]}};Object.defineProperty(Zr.prototype,"error",{enumerable:!0});Object.defineProperty(Zr.prototype,"message",{enumerable:!0});var is=class extends en{constructor(e,r={}){super(e),this[sx]=r.data===void 0?null:r.data}get data(){return this[sx]}};Object.defineProperty(is.prototype,"data",{enumerable:!0});var Tv={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[rs]&&o[Hd]===e&&!o[rs])return;let i;if(t==="message")i=function(c,d){let u=new is("message",{data:d?c:c.toString()});u[Jr]=this,Vo(e,this,u)};else if(t==="close")i=function(c,d){let u=new nr("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Jr]=this,Vo(e,this,u)};else if(t==="error")i=function(c){let d=new Zr("error",{error:c,message:c.message});d[Jr]=this,Vo(e,this,d)};else if(t==="open")i=function(){let c=new en("open");c[Jr]=this,Vo(e,this,c)};else return;i[rs]=!!r[rs],i[Hd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Hd]===e&&!r[rs]){this.removeListener(t,r);break}}};ux.exports={CloseEvent:nr,ErrorEvent:Zr,Event:en,EventTarget:Tv,MessageEvent:is};function Vo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Jo=ce((sP,hx)=>{"use strict";var{tokenChars:ss}=Kr();function Ft(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Cv(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,f=-1,x=-1,g=-1,m=0;for(;m<t.length;m++)if(x=t.charCodeAt(m),d===void 0)if(g===-1&&ss[x]===1)f===-1&&(f=m);else if(m!==0&&(x===32||x===9))g===-1&&f!==-1&&(g=m);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${m}`);g===-1&&(g=m);let _=t.slice(f,g);x===44?(Ft(e,_,r),r=Object.create(null)):d=_,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${m}`);else if(u===void 0)if(g===-1&&ss[x]===1)f===-1&&(f=m);else if(x===32||x===9)g===-1&&f!==-1&&(g=m);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${m}`);g===-1&&(g=m),Ft(r,t.slice(f,g),!0),x===44&&(Ft(e,d,r),r=Object.create(null),d=void 0),f=g=-1}else if(x===61&&f!==-1&&g===-1)u=t.slice(f,m),f=g=-1;else throw new SyntaxError(`Unexpected character at index ${m}`);else if(o){if(ss[x]!==1)throw new SyntaxError(`Unexpected character at index ${m}`);f===-1?f=m:i||(i=!0),o=!1}else if(c)if(ss[x]===1)f===-1&&(f=m);else if(x===34&&f!==-1)c=!1,g=m;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${m}`);else if(x===34&&t.charCodeAt(m-1)===61)c=!0;else if(g===-1&&ss[x]===1)f===-1&&(f=m);else if(f!==-1&&(x===32||x===9))g===-1&&(g=m);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${m}`);g===-1&&(g=m);let _=t.slice(f,g);i&&(_=_.replace(/\\/g,""),i=!1),Ft(r,u,_),x===44&&(Ft(e,d,r),r=Object.create(null),d=void 0),u=void 0,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${m}`);if(f===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=m);let S=t.slice(f,g);return d===void 0?Ft(e,S,r):(u===void 0?Ft(r,S,!0):i?Ft(r,u,S.replace(/\\/g,"")):Ft(r,u,S),Ft(e,d,r)),e}function Rv(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(", ")}hx.exports={format:Rv,parse:Cv}});var Qo=ce((cP,Ax)=>{"use strict";var Pv=pe("events"),Dv=pe("https"),Ov=pe("http"),gx=pe("net"),Lv=pe("tls"),{randomBytes:Nv,createHash:Mv}=pe("crypto"),{Duplex:oP,Readable:aP}=pe("stream"),{URL:Gd}=pe("url"),On=Wr(),Bv=Bd(),Fv=Ud(),{isBlob:zv}=Kr(),{BINARY_TYPES:xx,CLOSE_TIMEOUT:Uv,EMPTY_BUFFER:Zo,GUID:Hv,kForOnEventAttribute:jd,kListener:Gv,kStatusCode:jv,kWebSocket:We,NOOP:mx}=Xt(),{EventTarget:{addEventListener:qv,removeEventListener:Wv}}=fx(),{format:Kv,parse:$v}=Jo(),{toBuffer:Vv}=ts(),_x=Symbol("kAborted"),qd=[8,13],tn=["CONNECTING","OPEN","CLOSING","CLOSED"],Jv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ye=class t extends Pv{constructor(e,r,i){super(),this._binaryType=xx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Zo,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]),yx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xx.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 Bv({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,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",Xv),o.on("drain",Qv),o.on("error",eS),o.on("message",tS),o.on("ping",nS),o.on("pong",rS),c.onerror=iS,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",vx),e.on("data",Xo),e.on("end",Sx),e.on("error",Ix),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[On.extensionName]&&this._extensions[On.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Ex(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){Wd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Zo,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){Wd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Zo,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){Wd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[On.extensionName]||(o.compress=!1),this._sender.send(e||Zo,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:tn.indexOf("CONNECTING")});Object.defineProperty(ye.prototype,"CONNECTING",{enumerable:!0,value:tn.indexOf("CONNECTING")});Object.defineProperty(ye,"OPEN",{enumerable:!0,value:tn.indexOf("OPEN")});Object.defineProperty(ye.prototype,"OPEN",{enumerable:!0,value:tn.indexOf("OPEN")});Object.defineProperty(ye,"CLOSING",{enumerable:!0,value:tn.indexOf("CLOSING")});Object.defineProperty(ye.prototype,"CLOSING",{enumerable:!0,value:tn.indexOf("CLOSING")});Object.defineProperty(ye,"CLOSED",{enumerable:!0,value:tn.indexOf("CLOSED")});Object.defineProperty(ye.prototype,"CLOSED",{enumerable:!0,value:tn.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[jd])return e[Gv];return null},set(e){for(let r of this.listeners(t))if(r[jd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[jd]:!0})}})});ye.prototype.addEventListener=qv;ye.prototype.removeEventListener=Wv;Ax.exports=ye;function yx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Uv,protocolVersion:qd[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,!qd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${qd.join(", ")})`);let c;if(e instanceof Gd)c=e;else try{c=new Gd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",f;if(c.protocol!=="ws:"&&!d&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;Yo(t,I);return}let x=d?443:80,g=Nv(16).toString("base64"),m=d?Dv.request:Ov.request,S=new Set,_;if(o.createConnection=o.createConnection||(d?Yv:Zv),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":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new On({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Kv({[On.extensionName]:_.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Jv.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=m(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=m(o);o.timeout&&v.on("timeout",()=>{dt(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[_x]||(v=t._req=null,Yo(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){dt(t,v,"Maximum redirects exceeded");return}v.abort();let O;try{O=new Gd(A,e)}catch{let P=new SyntaxError(`Invalid URL: ${A}`);Yo(t,P);return}yx(t,O,r,i)}else t.emit("unexpected-response",v,I)||dt(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,C)=>{if(t.emit("upgrade",I),t.readyState!==ye.CONNECTING)return;v=t._req=null;let O=I.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){dt(t,A,"Invalid Upgrade header");return}let b=Mv("sha1").update(g+Hv).digest("base64");if(I.headers["sec-websocket-accept"]!==b){dt(t,A,"Invalid Sec-WebSocket-Accept header");return}let P=I.headers["sec-websocket-protocol"],L;if(P!==void 0?S.size?S.has(P)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){dt(t,A,L);return}P&&(t._protocol=P);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 M;try{M=$v(F)}catch{dt(t,A,"Invalid Sec-WebSocket-Extensions header");return}let J=Object.keys(M);if(J.length!==1||J[0]!==On.extensionName){dt(t,A,"Server indicated an extension that was not requested");return}try{_.accept(M[On.extensionName])}catch{dt(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[On.extensionName]=_}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 Yo(t,e){t._readyState=ye.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Zv(t){return t.path=t.socketPath,gx.connect(t)}function Yv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=gx.isIP(t.host)?"":t.host),Lv.connect(t)}function dt(t,e,r){t._readyState=ye.CLOSING;let i=new Error(r);Error.captureStackTrace(i,dt),e.setHeader?(e[_x]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Yo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Wd(t,e,r){if(e){let i=zv(e)?e.size:Vv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${tn[t.readyState]})`);process.nextTick(r,i)}}function Xv(t,e){let r=this[We];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[We]!==void 0&&(r._socket.removeListener("data",Xo),process.nextTick(bx,r._socket),t===1005?r.close():r.close(t,e))}function Qv(){let t=this[We];t.isPaused||t._socket.resume()}function eS(t){let e=this[We];e._socket[We]!==void 0&&(e._socket.removeListener("data",Xo),process.nextTick(bx,e._socket),e.close(t[jv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function px(){this[We].emitClose()}function tS(t,e){this[We].emit("message",t,e)}function nS(t){let e=this[We];e._autoPong&&e.pong(t,!this._isServer,mx),e.emit("ping",t)}function rS(t){this[We].emit("pong",t)}function bx(t){t.resume()}function iS(t){let e=this[We];e.readyState!==ye.CLOSED&&(e.readyState===ye.OPEN&&(e._readyState=ye.CLOSING,Ex(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Ex(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function vx(){let t=this[We];if(this.removeListener("close",vx),this.removeListener("data",Xo),this.removeListener("end",Sx),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",px),t._receiver.on("finish",px))}function Xo(t){this[We]._receiver.write(t)||this.pause()}function Sx(){let t=this[We];t._readyState=ye.CLOSING,t._receiver.end(),this.end()}function Ix(){let t=this[We];this.removeListener("error",Ix),this.on("error",mx),t&&(t._readyState=ye.CLOSING,this.destroy())}});var Rx=ce((lP,Cx)=>{"use strict";var dP=Qo(),{Duplex:sS}=pe("stream");function kx(t){t.emit("close")}function oS(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Tx(t){this.removeListener("error",Tx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function aS(t,e){let r=!0,i=new sS({...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(kx,i);return}let d=!1;t.once("error",function(f){d=!0,c(f)}),t.once("close",function(){d||c(o),process.nextTick(kx,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",oS),i.on("error",Tx),i}Cx.exports=aS});var Kd=ce((uP,Px)=>{"use strict";var{tokenChars:cS}=Kr();function dS(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&&cS[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}Px.exports={parse:dS}});var Fx=ce((hP,Bx)=>{"use strict";var lS=pe("events"),ea=pe("http"),{Duplex:fP}=pe("stream"),{createHash:uS}=pe("crypto"),Dx=Jo(),rr=Wr(),fS=Kd(),hS=Qo(),{CLOSE_TIMEOUT:xS,GUID:pS,kWebSocket:gS}=Xt(),mS=/^[+/0-9A-Za-z]{22}==$/,Ox=0,Lx=1,Mx=2,$d=class extends lS{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:xS,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:hS,...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=ea.createServer((i,o)=>{let c=ea.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=wS(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=Ox}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Mx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(os,this);return}if(e&&this.once("close",e),this._state!==Lx)if(this._state=Lx,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(os,this):process.nextTick(os,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{os(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",Nx);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){ir(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){ir(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!mS.test(c)){ir(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){ir(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){as(r,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=fS.parse(f)}catch{ir(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let g=e.headers["sec-websocket-extensions"],m={};if(this.options.perMessageDeflate&&g!==void 0){let S=new rr({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=Dx.parse(g);_[rr.extensionName]&&(S.accept(_[rr.extensionName]),m[rr.extensionName]=S)}catch{ir(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,v,I,A)=>{if(!_)return as(r,v||401,I,A);this.completeUpgrade(m,c,x,e,r,i,o)});return}if(!this.options.verifyClient(S))return as(r,401)}this.completeUpgrade(m,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[gS])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ox)return as(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${uS("sha1").update(r+pS).digest("base64")}`],g=new this.options.WebSocket(null,void 0,this.options);if(i.size){let m=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;m&&(x.push(`Sec-WebSocket-Protocol: ${m}`),g._protocol=m)}if(e[rr.extensionName]){let m=e[rr.extensionName].params,S=Dx.format({[rr.extensionName]:[m]});x.push(`Sec-WebSocket-Extensions: ${S}`),g._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
8
|
+
var zg=Object.create;var Oa=Object.defineProperty;var Ug=Object.getOwnPropertyDescriptor;var qg=Object.getOwnPropertyNames;var Gg=Object.getPrototypeOf,Hg=Object.prototype.hasOwnProperty;var he=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),La=(t,e)=>{for(var n in e)Oa(t,n,{get:e[n],enumerable:!0})},jg=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qg(e))!Hg.call(t,o)&&o!==n&&Oa(t,o,{get:()=>e[o],enumerable:!(i=Ug(e,o))||i.enumerable});return t};var jt=(t,e,n)=>(n=t!=null?zg(Gg(t)):{},jg(e||!t||!t.__esModule?Oa(n,"default",{value:t,enumerable:!0}):n,t));function Ye(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var fr=et(()=>{"use strict"});import{createWriteStream as Wg,mkdirSync as Kg,readdirSync as $g,unlinkSync as Vg}from"node:fs";import{join as Ol}from"node:path";function Bn(t){let e=n=>String(n).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function hr(t,e){return`${t}-${e}.log`}function Na(t,e){let n=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!n||n[1]!==e?null:n[2]??null}function Jg(t,e,n){let i=a=>{let[d,u,f]=a.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>n}function ms(t,e,n,i){let o;try{o=$g(t)}catch{return}for(let a of o){let d=Na(a,e);if(d&&Jg(d,n,i))try{Vg(Ol(t,a))}catch{}}}var di,Ma=et(()=>{"use strict";di=class{constructor(e,n,i){this.dir=e;this.prefix=n;this.opts=i;this.clock=i.clock??(()=>Bn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let n=this.clock();n!==this.currentDate&&this.rotate(n),this.stream?.write(e)}rotate(e){this.stream?.end();try{Kg(this.dir,{recursive:!0});let n=Wg(Ol(this.dir,hr(this.prefix,e)),{flags:"a"});n.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
|
|
9
|
+
`)),this.stream=n}catch(n){process.stderr.write(`[log-sink] rotate failed: ${String(n)}
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&ms(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 Yg,mkdirSync as Zg}from"node:fs";import{join as Xg}from"node:path";function Nl(t){let e=t.retentionDays??tm,n=t.clock??(()=>Bn(new Date));_s={bridgeSink:new di(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:n}),agentSinks:new Map,makeAgentSink:o=>new di(t.agentLogsDir(o),"agent",{retentionDays:e,clock:n})};let i=n();ms(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])ms(t.agentLogsDir(o),"agent",i,e)}function nm(t,e){let n=t.agentSinks.get(e);return n||(n=t.makeAgentSink(e),t.agentSinks.set(e,n)),n}function Ml(t){Ba=t}function Bl(t){return xr[Ba]<=xr[t]}function Fl(t,e){let n=xr[t];return n===void 0?!0:n>=xr[e]}function ys(t){Ll={...t}}function zl(t){let e=(u,f=2)=>String(u).padStart(f,"0"),n=-t.getTimezoneOffset(),i=n>=0?"+":"-",o=Math.abs(n),a=e(Math.floor(o/60)),d=e(o%60);return`${Bn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${a}:${d}`}function lt(t,e,n,i,o){try{let a=`${JSON.stringify({ts:zl(new Date),level:e,module:n,msg:i,...o})}
|
|
11
|
+
`;Zg(t,{recursive:!0}),Yg(Xg(t,hr("bridge",Bn(new Date))),a)}catch{}}function rm(t,e){if(t)return t;let n=e?.agentId;return typeof n=="string"&&n.length>0?n:void 0}function ws(t,e,n,i,o){if(xr[t]<xr[Ba])return;let a=`${JSON.stringify({ts:zl(new Date),level:t,module:e,msg:n,...Ll,...i})}
|
|
12
|
+
`;if(_s){let d=rm(o,i),u=d?nm(_s,d):_s.bridgeSink;try{u.write(a)}catch{process.stderr.write(a)}return}t==="error"||t==="warn"?em.write(a):Qg.write(a)}function q(t,e){return{debug:(n,i)=>ws("debug",t,n,i,e),info:(n,i)=>ws("info",t,n,i,e),warn:(n,i)=>ws("warn",t,n,i,e),error:(n,i)=>ws("error",t,n,i,e),child:n=>q(`${t}.${n}`,e),forAgent:n=>q(t,n)}}var xr,Ba,Qg,em,Ll,tm,_s,re=et(()=>{"use strict";fr();Ma();xr={debug:10,info:20,warn:30,error:40},Ba=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Qg=process.stdout,em=process.stderr,Ll={},tm=Ye("COZE_BRIDGE_LOG_RETENTION_DAYS",30),_s=null});var k,Ke=et(()=>{"use strict";k=class extends Error{code;retriable;cause;constructor(e,n,i){super(n),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Hl={};La(Hl,{ACP_WRAPPER_NPM_PACKAGES:()=>bs,_resetAcpInstallerForTests:()=>dm,_setBinaryPathCacheForTests:()=>lm,buildAcpSpawn:()=>li,ensureAcpInstalled:()=>gr,getAcpBinaryPath:()=>vs,pickWhichLine:()=>Ua,probeAcpVersion:()=>cm,resolveAcpCommand:()=>Gl});import{readFileSync as Ul}from"node:fs";import{createRequire as im}from"node:module";import{dirname as sm,resolve as om}from"node:path";function za(t){if(t!=="codex")return;let e=process.env.COZE_BRIDGE_CODEX_ACP_BIN?.trim();return e||void 0}function Ua(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 n=i=>e.find(o=>o.toLowerCase().endsWith(i));return n(".cmd")??n(".exe")??n(".bat")??n(".ps1")??e[0]}function am(t){let e=ql.resolve(`${t.npmPackage}/package.json`),n=sm(e),i=JSON.parse(Ul(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 om(n,o)}async function gr(t,e){let n=Fa[t];if(!n)throw new k("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=pr.get(t);if(i)return i;let o=za(t);if(o)return pr.set(t,o),Es.info("acp wrapper overridden by env",{framework:t,path:o}),o;try{let a=am(n);return pr.set(t,a),Es.info("acp wrapper resolved",{framework:t,binary:n.binary,path:a}),a}catch(a){throw Es.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:n.npmPackage,err:String(a)}),new k("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${n.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:a})}}async function cm(t){let e=Fa[t];if(e)try{let n=ql.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(Ul(n,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(n){Es.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(n)});return}}function vs(t){return pr.get(t)}function Gl(t,e){if(e)return e;let n=za(t);if(n)return n;let i=vs(t);if(!i)throw new k("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return i}function li(t,e,n){if(e)return{command:e,args:[...n]};let i=za(t);if(i)return{command:i,args:[...n]};let o=Gl(t);return{command:process.execPath,args:[o,...n]}}function dm(){pr.clear()}function lm(t,e){pr.set(t,e)}var Es,Fa,bs,ql,pr,dn=et(()=>{"use strict";Ke();re();Es=q("agents.acp-installer"),Fa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},bs=Object.values(Fa).filter(t=>t!==void 0).map(t=>t.npmPackage),ql=im(import.meta.url),pr=new Map});import{chmod as fm,mkdir as hm,readFile as xm,rename as pm,rm as gm,writeFile as mm}from"node:fs/promises";import{dirname as wm}from"node:path";async function ln(t){try{let e=await xm(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function un(t,e,n){await hm(wm(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await mm(i,e,{encoding:"utf8",mode:n?.mode}),await pm(i,t),n?.mode!==void 0&&await fm(t,n.mode)}catch(o){throw await gm(i,{force:!0}).catch(()=>{}),o}}async function fn(t,e,n){await un(t,`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,n)}var hn=et(()=>{"use strict"});import{promises as Kl,readdirSync as _m}from"node:fs";import{homedir as ym}from"node:os";import{sep as Em,join as ke,resolve as $l}from"node:path";function Z(t){let e=t??ym(),n=ke(e,".coze"),i=ke(n,"bridge"),o=ke(i,"lib"),a=ke(i,"logs");return{cozeRoot:n,bridgeRoot:i,libDir:o,libEntry:ke(o,"index.js"),binDir:ke(i,"bin"),pidFile:ke(i,"bridge.pid"),portFile:ke(i,"bridge.port"),tokenFile:ke(i,"bridge.token"),patTokenFile:ke(i,"pat-token"),agentEnvFile:ke(i,"agent-env.json"),logFile:ke(i,"bridge.log"),bridgeLogsDir:a,daemonStdioLog:ke(a,"daemon-stdio.log"),installLock:ke(i,"install.lock"),configFile:ke(i,"config.json"),agentsRoot:ke(n,"agents")}}function $e(t,e=Z()){let n=ke(e.agentsRoot,t);return{root:n,config:ke(n,"config.json"),workspace:ke(n,"workspace"),logs:ke(n,"logs")}}function Ss(t=Z()){try{return _m(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ui(t,e){let n=await Kl.realpath($l(t)).catch(()=>null);if(!n)return!1;let i=await Kl.realpath($l(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?n.toLowerCase():n,a=process.platform==="win32"?i.toLowerCase():i;return o===a||o.startsWith(a+Em)}var Te=et(()=>{"use strict"});var As={};La(As,{AGENT_CONFIG_FILE_MODE:()=>Is,enforceAgentConfigMode:()=>Sm,loadAgentConfig:()=>Ce,persistAgentSessions:()=>fi,persistAgentSkills:()=>hi,saveAgentConfig:()=>Fe});import{chmod as bm,stat as vm}from"node:fs/promises";function Ce(t,e){return ln($e(t,e).config)}function Fe(t,e){return fn($e(t.agentId,e).config,t,{mode:Is})}async function Sm(t,e){if(process.platform==="win32")return;let n=$e(t,e).config;try{let i=await vm(n);if(!i.isFile())return;let o=i.mode&511;o!==Is&&(await bm(n,Is),Vl.warn("agent config mode auto-corrected to 0600",{path:n,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Vl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:n,err:String(i)})}}async function fi(t,e,n){let i=await Ce(t,n);i&&(i.sessions=Object.fromEntries(e),await Fe(i,n))}async function hi(t,e,n){let i=await Ce(t,n);i&&(i.skills=e,await Fe(i,n))}var Vl,Is,xn=et(()=>{"use strict";hn();re();Te();Vl=q("agent-config"),Is=384});var Ha=ae((OI,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 Ts=ae(Ql=>{var Xl={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 Dm(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(Xl))Ql[t]=Dm(Xl[t])});var iu=ae((NI,ru)=>{var Rm=he("fs"),Le=he("path"),eu=Ha(),Pm=Ts(),Om=typeof process=="object"&&process.platform==="win32",tu=t=>typeof t=="object"&&t!==null,nu=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 ve(t){this.sep=Le.sep,this.fs=Rm,tu(t)&&tu(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}ru.exports=ve;ve.prototype.makeDir=function(t){let e=this;function n(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(a){if(!(!a||a.substr(-1,1)===":")){o+=e.sep+a;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 Pm.FILE_IN_THE_WAY(`"${o}"`)}})}n(t)};ve.prototype.writeFileTo=function(t,e,n,i){let o=this;if(o.fs.existsSync(t)){if(!n)return!1;var a=o.fs.statSync(t);if(a.isDirectory())return!1}var d=Le.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};ve.prototype.writeFileToAsync=function(t,e,n,i,o){typeof i=="function"&&(o=i,i=void 0);let a=this;a.fs.exists(t,function(d){if(d&&!n)return o(!1);a.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var x=Le.dirname(t);a.fs.exists(x,function(g){g||a.makeDir(x),a.fs.open(t,"w",438,function(w,S){w?a.fs.chmod(t,438,function(){a.fs.open(t,"w",438,function(_,b){a.fs.write(b,e,0,e.length,0,function(){a.fs.close(b,function(){a.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?a.fs.write(S,e,0,e.length,0,function(){a.fs.close(S,function(){a.fs.chmod(t,i||438,function(){o(!0)})})}):a.fs.chmod(t,i||438,function(){o(!0)})})})})})};ve.prototype.findFiles=function(t){let e=this;function n(i,o,a){typeof o=="boolean"&&(a=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Le.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&d.push(Le.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&a&&(d=d.concat(n(f,o,a)))}),d}return n(t,void 0,!0)};ve.prototype.findFilesAsync=function(t,e){let n=this,i=[];n.fs.readdir(t,function(o,a){if(o)return e(o);let d=a.length;if(!d)return e(null,i);a.forEach(function(u){u=Le.join(t,u),n.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Le.normalize(u)+(x.isDirectory()?n.sep:"")),x.isDirectory()?n.findFilesAsync(u,function(g,w){if(g)return e(g);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};ve.prototype.getAttributes=function(){};ve.prototype.setAttributes=function(){};ve.crc32update=function(t,e){return nu[(t^e)&255]^t>>>8};ve.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,n=-1;for(let i=0;i<e;)n=ve.crc32update(n,t[i++]);return~n>>>0};ve.methodToString=function(t){switch(t){case eu.STORED:return"STORED ("+t+")";case eu.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};ve.canonical=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};ve.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.posix.join(".",e)};ve.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]};ve.sanitize=function(t,e){t=Le.resolve(Le.normalize(t));for(var n=e.split("/"),i=0,o=n.length;i<o;i++){var a=Le.normalize(Le.join(t,n.slice(i,o).join(Le.sep)));if(a.indexOf(t)===0)return a}return Le.normalize(Le.join(t,Le.basename(e)))};ve.toBuffer=function(e,n){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?n(e):Buffer.alloc(0)};ve.readBigUInt64LE=function(t,e){let n=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+n};ve.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)};ve.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};ve.isWin=Om;ve.crcTable=nu});var ou=ae((MI,su)=>{var Lm=he("path");su.exports=function(t,{fs:e}){var n=t||"",i=a(),o=null;function a(){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=Lm.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 cu=ae((BI,au)=>{au.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var _r=ae((FI,wr)=>{wr.exports=iu();wr.exports.Constants=Ha();wr.exports.Errors=Ts();wr.exports.FileAttr=ou();wr.exports.decoder=cu()});var lu=ae((zI,du)=>{var pn=_r(),z=pn.Constants;du.exports=function(){var t=20,e=10,n=0,i=0,o=0,a=0,d=0,u=0,f=0,x=0,g=0,w=0,S=0,_=0,b=0;t|=pn.isWin?2560:768,n|=z.FLG_EFS;let I={extraLen:0},A=y=>Math.max(0,y)>>>0,T=y=>Math.max(0,y)&65535,P=y=>Math.max(0,y)&255;return o=pn.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&z.FLG_EFS)>0},set flags_efs(y){y?n|=z.FLG_EFS:n&=~z.FLG_EFS},get flags_desc(){return(n&z.FLG_DESC)>0},set flags_desc(y){y?n|=z.FLG_DESC:n&=~z.FLG_DESC},get method(){return i},set method(y){switch(y){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=y},get time(){return pn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=pn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return P(o>>>8)},get crc(){return a},set crc(y){a=A(y)},get compressedSize(){return d},set compressedSize(y){d=A(y)},get size(){return u},set size(y){u=A(y)},get fileNameLength(){return f},set fileNameLength(y){f=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return g},set commentLength(y){g=y},get diskNumStart(){return w},set diskNumStart(y){w=A(y)},get inAttr(){return S},set inAttr(y){S=A(y)},get attr(){return _},set attr(y){_=A(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return b},set offset(y){b=A(y)},get encrypted(){return(n&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+f+x+g},get realDataOffset(){return b+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var D=y.slice(b,b+z.LOCHDR);if(D.readUInt32LE(0)!==z.LOCSIG)throw pn.Errors.INVALID_LOC();I.version=D.readUInt16LE(z.LOCVER),I.flags=D.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=D.readUInt16LE(z.LOCHOW),I.time=D.readUInt32LE(z.LOCTIM),I.crc=D.readUInt32LE(z.LOCCRC),I.compressedSize=D.readUInt32LE(z.LOCSIZ),I.size=D.readUInt32LE(z.LOCLEN),I.fnameLen=D.readUInt16LE(z.LOCNAM),I.extraLen=D.readUInt16LE(z.LOCEXT);let L=b+z.LOCHDR+I.fnameLen,B=L+I.extraLen;return y.slice(L,B)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw pn.Errors.INVALID_CEN();t=y.readUInt16LE(z.CENVEM),e=y.readUInt16LE(z.CENVER),n=y.readUInt16LE(z.CENFLG),i=y.readUInt16LE(z.CENHOW),o=y.readUInt32LE(z.CENTIM),a=y.readUInt32LE(z.CENCRC),d=y.readUInt32LE(z.CENSIZ),u=y.readUInt32LE(z.CENLEN),f=y.readUInt16LE(z.CENNAM),x=y.readUInt16LE(z.CENEXT),g=y.readUInt16LE(z.CENCOM),w=y.readUInt16LE(z.CENDSK),S=y.readUInt16LE(z.CENATT),_=y.readUInt32LE(z.CENATX),b=y.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(z.LOCHDR);return y.writeUInt32LE(z.LOCSIG,0),y.writeUInt16LE(e,z.LOCVER),y.writeUInt16LE(n,z.LOCFLG),y.writeUInt16LE(i,z.LOCHOW),y.writeUInt32LE(o,z.LOCTIM),y.writeUInt32LE(a,z.LOCCRC),y.writeUInt32LE(d,z.LOCSIZ),y.writeUInt32LE(u,z.LOCLEN),y.writeUInt16LE(f,z.LOCNAM),y.writeUInt16LE(I.extraLen,z.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(z.CENHDR+f+x+g);return y.writeUInt32LE(z.CENSIG,0),y.writeUInt16LE(t,z.CENVEM),y.writeUInt16LE(e,z.CENVER),y.writeUInt16LE(n,z.CENFLG),y.writeUInt16LE(i,z.CENHOW),y.writeUInt32LE(o,z.CENTIM),y.writeUInt32LE(a,z.CENCRC),y.writeUInt32LE(d,z.CENSIZ),y.writeUInt32LE(u,z.CENLEN),y.writeUInt16LE(f,z.CENNAM),y.writeUInt16LE(x,z.CENEXT),y.writeUInt16LE(g,z.CENCOM),y.writeUInt16LE(w,z.CENDSK),y.writeUInt16LE(S,z.CENATT),y.writeUInt32LE(_,z.CENATX),y.writeUInt32LE(b,z.CENOFF),y},toJSON:function(){let y=function(D){return D+" bytes"};return{made:t,version:e,flags:n,method:pn.methodToString(i),time:this.time,crc:"0x"+a.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(f),extraLength:y(x),commentLength:y(g),diskNumStart:w,inAttr:S,attr:_,offset:b,centralHeaderSize:y(z.CENHDR+f+x+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var fu=ae((UI,uu)=>{var yr=_r(),ye=yr.Constants;uu.exports=function(){var t=0,e=0,n=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(a){t=e=a},get totalEntries(){return e},set totalEntries(a){e=t=a},get size(){return n},set size(a){n=a},get offset(){return i},set offset(a){i=a},get commentLength(){return o},set commentLength(a){o=a},get mainHeaderSize(){return ye.ENDHDR+o},loadFromBinary:function(a){if((a.length!==ye.ENDHDR||a.readUInt32LE(0)!==ye.ENDSIG)&&(a.length<ye.ZIP64HDR||a.readUInt32LE(0)!==ye.ZIP64SIG))throw yr.Errors.INVALID_END();a.readUInt32LE(0)===ye.ENDSIG?(t=a.readUInt16LE(ye.ENDSUB),e=a.readUInt16LE(ye.ENDTOT),n=a.readUInt32LE(ye.ENDSIZ),i=a.readUInt32LE(ye.ENDOFF),o=a.readUInt16LE(ye.ENDCOM)):(t=yr.readBigUInt64LE(a,ye.ZIP64SUB),e=yr.readBigUInt64LE(a,ye.ZIP64TOT),n=yr.readBigUInt64LE(a,ye.ZIP64SIZE),i=yr.readBigUInt64LE(a,ye.ZIP64OFF),o=0)},toBinary:function(){var a=Buffer.alloc(ye.ENDHDR+o);return a.writeUInt32LE(ye.ENDSIG,0),a.writeUInt32LE(0,4),a.writeUInt16LE(t,ye.ENDSUB),a.writeUInt16LE(e,ye.ENDTOT),a.writeUInt32LE(n,ye.ENDSIZ),a.writeUInt32LE(i,ye.ENDOFF),a.writeUInt16LE(o,ye.ENDCOM),a.fill(" ",ye.ENDHDR),a},toJSON:function(){let a=function(d,u){let f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:n+" bytes",offset:a(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wa=ae(ja=>{ja.EntryHeader=lu();ja.MainHeader=fu()});var xu=ae((GI,hu)=>{hu.exports=function(t){var e=he("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),a=[],d=0;o.on("data",function(u){a.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var x=0;x<a.length;x++){var g=a[x];g.copy(u,f),f+=g.length}i&&i(u)}),o.end(t)}}}});var gu=ae((HI,pu)=>{var Nm=+(process.versions?process.versions.node:"").split(".")[0]||0;pu.exports=function(t,e){var n=he("zlib");let i=Nm>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return n.inflateRawSync(t,i)},inflateAsync:function(o){var a=n.createInflateRaw(i),d=[],u=0;a.on("data",function(f){d.push(f),u+=f.length}),a.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var g=0;g<d.length;g++){var w=d[g];w.copy(f,x),x+=w.length}o&&o(f)}),a.end(t)}}}});var Eu=ae((jI,yu)=>{"use strict";var{randomFillSync:mu}=he("crypto"),Mm=Ts(),Bm=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}),_u=(t,e)=>Math.imul(t,e)>>>0,wu=(t,e)=>Bm[(t^e)&255]^t>>>8,xi=()=>typeof mu=="function"?mu(Buffer.alloc(12)):xi.node();xi.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 Cs={genSalt:xi};function Ds(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])}Ds.prototype.updateKeys=function(t){let e=this.keys;return e[0]=wu(e[0],t),e[1]+=e[0]&255,e[1]=_u(e[1],134775813)+1,e[2]=wu(e[2],e[1]>>>24),t};Ds.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return _u(t,t^1)>>8&255};function Fm(t){let e=new Ds(t);return function(n){let i=Buffer.alloc(n.length),o=0;for(let a of n)i[o++]=e.updateKeys(a^e.next());return i}}function zm(t){let e=new Ds(t);return function(n,i,o=0){i||(i=Buffer.alloc(n.length));for(let a of n){let d=e.next();i[o++]=a^d,e.updateKeys(a)}return i}}function Um(t,e,n){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Fm(n),o=i(t.slice(0,12)),a=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==a)throw Mm.WRONG_PASSWORD();return i(t.slice(12))}function qm(t){Buffer.isBuffer(t)&&t.length>=12?Cs.genSalt=function(){return t.slice(0,12)}:t==="node"?Cs.genSalt=xi.node:Cs.genSalt=xi}function Gm(t,e,n,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=zm(n),a=Cs.genSalt();a[11]=e.crc>>>24&255,i&&(a[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(a,d),o(t,d,12)}yu.exports={decrypt:Um,encrypt:Gm,_salter:qm}});var bu=ae(Rs=>{Rs.Deflater=xu();Rs.Inflater=gu();Rs.ZipCrypto=Eu()});var $a=ae((KI,vu)=>{var ce=_r(),Hm=Wa(),Se=ce.Constants,Ka=bu();vu.exports=function(t,e){var n=new Hm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),a=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let g=t,w=typeof g.decoder=="object"?g.decoder:ce.decoder;x=w.hasOwnProperty("efs")?w.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=n.loadLocalHeaderFromBinary(e),e.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function _(y){if(!n.flags_desc&&!n.localHeader.flags_desc){if(ce.crc32(y)!==n.localHeader.crc)return!1}else{let D={},L=n.realDataOffset+n.compressedSize;if(e.readUInt32LE(L)==Se.LOCSIG||e.readUInt32LE(L)==Se.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==Se.EXTSIG)D.crc=e.readUInt32LE(L+Se.EXTCRC),D.compressedSize=e.readUInt32LE(L+Se.EXTSIZ),D.size=e.readUInt32LE(L+Se.EXTLEN);else if(e.readUInt16LE(L+12)===19280)D.crc=e.readUInt32LE(L+Se.EXTCRC-4),D.compressedSize=e.readUInt32LE(L+Se.EXTSIZ-4),D.size=e.readUInt32LE(L+Se.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==n.compressedSize||D.size!==n.size||D.crc!==n.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(y)!==D.crc)return!1}return!0}function b(y,D,L){if(typeof D>"u"&&typeof y=="string"&&(L=y,y=void 0),a)return y&&D&&D(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=S();if(B.length===0)return y&&D&&D(B),B;if(n.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw ce.Errors.INVALID_PASS_PARAM();B=Ka.ZipCrypto.decrypt(B,n,L)}var M=Buffer.alloc(n.size);switch(n.method){case ce.Constants.STORED:if(B.copy(M),_(M))return y&&D&&D(M),M;throw y&&D&&D(M,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var Y=new Ka.Inflater(B,n.size);if(y)Y.inflateAsync(function(J){J.copy(J,0),D&&(_(J)?D(J):D(J,ce.Errors.BAD_CRC()))});else{if(Y.inflate(M).copy(M,0),!_(M))throw ce.Errors.BAD_CRC(`"${w.decode(i)}"`);return M}break;default:throw y&&D&&D(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(y,D){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&D&&D(S()),S();if(d.length&&!a){var L;switch(n.method){case ce.Constants.STORED:return n.compressedSize=n.size,L=Buffer.alloc(d.length),d.copy(L),y&&D&&D(L),L;default:case ce.Constants.DEFLATED:var B=new Ka.Deflater(d);if(y)B.deflateAsync(function(Y){L=Buffer.alloc(Y.length),n.compressedSize=Y.length,Y.copy(L),D&&D(L)});else{var M=B.deflate();return n.compressedSize=M.length,M}B=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,D){return ce.readBigUInt64LE(y,D)}function T(y){try{for(var D=0,L,B,M;D+4<y.length;)L=y.readUInt16LE(D),D+=2,B=y.readUInt16LE(D),D+=2,M=y.slice(D,D+B),D+=B,Se.ID_ZIP64===L&&P(M)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(y){var D,L,B,M;y.length>=Se.EF_ZIP64_SCOMP&&(D=A(y,Se.EF_ZIP64_SUNCOMP),n.size===Se.EF_ZIP64_OR_32&&(n.size=D)),y.length>=Se.EF_ZIP64_RHO&&(L=A(y,Se.EF_ZIP64_SCOMP),n.compressedSize===Se.EF_ZIP64_OR_32&&(n.compressedSize=L)),y.length>=Se.EF_ZIP64_DSN&&(B=A(y,Se.EF_ZIP64_RHO),n.offset===Se.EF_ZIP64_OR_32&&(n.offset=B)),y.length>=Se.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(Se.EF_ZIP64_DSN),n.diskNumStart===Se.EF_ZIP64_OR_16&&(n.diskNumStart=M))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=ce.toBuffer(y,w.encode);var D=i[i.length-1];a=D===47||D===92,n.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},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=ce.toBuffer(y,w.encode),n.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return a?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return a},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=ce.toBuffer(y,ce.decoder.encode),!a&&d.length?(n.size=d.length,n.method=ce.Constants.DEFLATED,n.crc=ce.crc32(y),n.changed=!0):n.method=ce.Constants.STORED},getData:function(y){return n.changed?d:b(!1,null,y)},getDataAsync:function(y,D){n.changed?y(d):b(!0,y,D)},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(),D=ce.Constants.CENHDR;return i.copy(y,D),D+=i.length,u.copy(y,D),D+=n.extraLength,o.copy(y,D),y},packLocalHeader:function(){let y=0;n.flags_efs=this.efs,n.extraLocalLength=f.length;let D=n.localHeaderToBinary(),L=Buffer.alloc(D.length+i.length+n.extraLocalLength);return D.copy(L,y),y+=D.length,i.copy(L,y),y+=i.length,f.copy(L,y),y+=f.length,L},toJSON:function(){let y=function(D){return"<"+(D&&D.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Au=ae(($I,Iu)=>{var Su=$a(),jm=Wa(),Ve=_r();Iu.exports=function(t,e){var n=[],i={},o=Buffer.alloc(0),a=new jm.MainHeader,d=!1,u=null;let f=new Set,x=e,{noSort:g,decoder:w}=x;t?b(x.readEntries):d=!0;function S(){let A=new Set;for(let T of Object.keys(i)){let P=T.split("/");if(P.pop(),!!P.length)for(let y=0;y<P.length;y++){let D=P.slice(0,y+1).join("/")+"/";A.add(D)}}for(let T of A)if(!(T in i)){let P=new Su(x);P.entryName=T,P.attr=16,P.temporary=!0,n.push(P),i[P.entryName]=P,f.add(P)}}function _(){if(d=!0,i={},a.diskEntries>(t.length-a.offset)/Ve.Constants.CENHDR)throw Ve.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(a.diskEntries);for(var A=a.offset,T=0;T<n.length;T++){var P=A,y=new Su(x,t);y.header=t.slice(P,P+=Ve.Constants.CENHDR),y.entryName=t.slice(P,P+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(P,P+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(P,P+y.header.commentLength)),A+=y.header.centralHeaderSize,n[T]=y,i[y.entryName]=y}f.clear(),S()}function b(A){var T=t.length-Ve.Constants.ENDHDR,P=Math.max(0,T-65535),y=P,D=t.length,L=-1,B=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),T;T>=y;T--)if(t[T]===80){if(t.readUInt32LE(T)===Ve.Constants.ENDSIG){L=T,B=T,D=T+Ve.Constants.ENDHDR,y=T-Ve.Constants.END64HDR;continue}if(t.readUInt32LE(T)===Ve.Constants.END64SIG){y=P;continue}if(t.readUInt32LE(T)===Ve.Constants.ZIP64SIG){L=T,D=T+Ve.readBigUInt64LE(t,T+Ve.Constants.ZIP64SIZE)+Ve.Constants.ZIP64LEAD;break}}if(L==-1)throw Ve.Errors.INVALID_FORMAT();a.loadFromBinary(t.slice(L,D)),a.commentLength&&(o=t.slice(B+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=>!f.has(A))},get comment(){return w.decode(o)},set comment(A){o=Ve.toBuffer(A,w.encode),a.commentLength=o.length},getEntryCount:function(){return d?n.length:a.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,a.totalEntries=n.length},deleteFile:function(A,T=!0){d||_();let P=i[A];this.getEntryChildren(P,T).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||_();let T=i[A],P=n.indexOf(T);P>=0&&(n.splice(P,1),delete i[A],a.totalEntries=n.length)},getEntryChildren:function(A,T=!0){if(d||_(),typeof A=="object")if(A.isDirectory&&T){let P=[],y=A.entryName;for(let D of n)D.entryName.startsWith(y)&&P.push(D);return P}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=[],P=0,y=0;a.size=0,a.offset=0;let D=0;for(let M of this.entries){let Y=M.getCompressedData();M.header.offset=y;let J=M.packLocalHeader(),ie=J.length+Y.length;y+=ie,A.push(J),A.push(Y);let Q=M.packCentralHeader();T.push(Q),a.size+=Q.length,P+=ie+Q.length,D++}P+=a.mainHeaderSize,a.offset=y,a.totalEntries=D,y=0;let L=Buffer.alloc(P);for(let M of A)M.copy(L,y),y+=M.length;for(let M of T)M.copy(L,y),y+=M.length;let B=a.toBinary();return o&&o.copy(B,Ve.Constants.ENDHDR),B.copy(L,y),t=L,d=!1,L},toAsyncBuffer:function(A,T,P,y){try{d||_(),I();let D=[],L=[],B=0,M=0,Y=0;a.size=0,a.offset=0;let J=function(ie){if(ie.length>0){let Q=ie.shift(),te=Q.entryName+Q.extra.toString();P&&P(te),Q.getCompressedDataAsync(function(oe){y&&y(te),Q.header.offset=M;let R=Q.packLocalHeader(),U=R.length+oe.length;M+=U,D.push(R),D.push(oe);let H=Q.packCentralHeader();L.push(H),a.size+=H.length,B+=U+H.length,Y++,J(ie)})}else{B+=a.mainHeaderSize,a.offset=M,a.totalEntries=Y,M=0;let Q=Buffer.alloc(B);D.forEach(function(oe){oe.copy(Q,M),M+=oe.length}),L.forEach(function(oe){oe.copy(Q,M),M+=oe.length});let te=a.toBinary();o&&o.copy(te,Ve.Constants.ENDHDR),te.copy(Q,M),t=Q,d=!1,A(Q)}};J(Array.from(this.entries))}catch(D){T(D)}}}}});var Cu=ae((VI,Tu)=>{var be=_r(),Ee=he("path"),Wm=$a(),Km=Au(),Fn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),ku=(...t)=>be.findLast(t,e=>typeof e=="string"),$m=(...t)=>be.findLast(t,e=>typeof e=="function"),Vm={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};Tu.exports=function(t,e){let n=null,i=Object.assign(Object.create(null),Vm);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=be.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new be(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=be.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=be.Constants.FILE,i.filename=t,n=o.fs.readFileSync(t);else throw be.Errors.INVALID_FILENAME();let a=new Km(n,i),{canonical:d,sanitize:u,zipnamefix:f}=be;function x(_){if(_&&a){var b;if(typeof _=="string"&&(b=a.getEntry(Ee.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(b=a.getEntry(_.entryName)),b)return b}return null}function g(_){let{join:b,normalize:I,sep:A}=Ee.posix;return b(Ee.isAbsolute(_)?"/":".",I(A+_.split("\\").join(A)+A))}function w(_){return _ instanceof RegExp?(function(b){return function(I){return b.test(I)}})(_):typeof _!="function"?()=>!0:_}let S=(_,b)=>{let I=b.slice(-1);return I=I===o.sep?o.sep:"",Ee.relative(_,b)+I};return{readFile:function(_,b){var I=x(_);return I&&I.getData(b)||null},childCount:function(_){let b=x(_);if(b)return a.getChildCount(b)},readFileAsync:function(_,b){var I=x(_);I?I.getDataAsync(b):b(null,"getEntry failed for:"+_)},readAsText:function(_,b){var I=x(_);if(I){var A=I.getData();if(A&&A.length)return A.toString(b||"utf8")}return""},readAsTextAsync:function(_,b,I){var A=x(_);A?A.getDataAsync(function(T,P){if(P){b(T,P);return}T&&T.length?b(T.toString(I||"utf8")):b("")}):b("")},deleteFile:function(_,b=!0){var I=x(_);I&&a.deleteFile(I.entryName,b)},deleteEntry:function(_){var b=x(_);b&&a.deleteEntry(b.entryName)},addZipComment:function(_){a.comment=_},getZipComment:function(){return a.comment||""},addZipEntryComment:function(_,b){var I=x(_);I&&(I.comment=b)},getZipEntryComment:function(_){var b=x(_);return b&&b.comment||""},updateFile:function(_,b){var I=x(_);I&&I.setData(b)},addLocalFile:function(_,b,I,A){if(o.fs.existsSync(_)){b=b?g(b):"";let T=Ee.win32.basename(Ee.win32.normalize(_));b+=I||T;let P=o.fs.statSync(_),y=P.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);P.isDirectory()&&(b+=o.sep),this.addFile(b,y,A,P)}else throw be.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,b){_=typeof _=="object"?_:{localPath:_};let I=Ee.resolve(_.localPath),{comment:A}=_,{zipPath:T,zipName:P}=_,y=this;o.fs.stat(I,function(D,L){if(D)return b(D,!1);T=T?g(T):"";let B=Ee.win32.basename(Ee.win32.normalize(I));if(T+=P||B,L.isFile())o.fs.readFile(I,function(M,Y){return M?b(M,!1):(y.addFile(T,Y,A,L),setImmediate(b,void 0,!0))});else if(L.isDirectory())return T+=o.sep,y.addFile(T,Buffer.alloc(0),A,L),setImmediate(b,void 0,!0)})},addLocalFolder:function(_,b,I){if(I=w(I),b=b?g(b):"",_=Ee.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),T=this;if(A.length)for(let P of A){let y=Ee.join(b,S(_,P));I(y)&&T.addLocalFile(P,Ee.dirname(y))}}else throw be.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,b,I,A){A=w(A),I=I?g(I):"",_=Ee.normalize(_);var T=this;o.fs.open(_,"r",function(P){if(P&&P.code==="ENOENT")b(void 0,be.Errors.FILE_NOT_FOUND(_));else if(P)b(void 0,P);else{var y=o.findFiles(_),D=-1,L=function(){if(D+=1,D<y.length){var B=y[D],M=S(_,B).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(B,function(Y,J){Y&&b(void 0,Y),J.isFile()?o.fs.readFile(B,function(ie,Q){ie?b(void 0,ie):(T.addFile(I+M,Q,"",J),L())}):(T.addFile(I+M+"/",Buffer.alloc(0),"",J),L())}):process.nextTick(()=>{L()})}else b(!0,void 0)};L()}})},addLocalFolderAsync2:function(_,b){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=Ee.resolve(g(_.localPath));let{zipPath:A,filter:T,namefix:P}=_;T instanceof RegExp?T=(function(L){return function(B){return L.test(B)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?g(A):"",P=="latin1"&&(P=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=L=>L);let y=L=>Ee.join(A,P(S(localPath,L))),D=L=>Ee.win32.basename(Ee.win32.normalize(P(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?b(void 0,be.Errors.FILE_NOT_FOUND(localPath)):L?b(void 0,L):o.findFilesAsync(localPath,function(B,M){if(B)return b(B);M=M.filter(Y=>T(y(Y))),M.length||b(void 0,!1),setImmediate(M.reverse().reduce(function(Y,J){return function(ie,Q){if(ie||Q===!1)return setImmediate(Y,ie,!1);I.addLocalFileAsync({localPath:J,zipPath:Ee.dirname(y(J)),zipName:D(J)},Y)}},b))})})},addLocalFolderPromise:function(_,b){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},b),(T,P)=>{T&&A(T),P&&I(this)})})},addFile:function(_,b,I,A){_=f(_);let T=x(_),P=T!=null;P||(T=new Wm(i),T.entryName=_),T.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(T.header.time=A.mtime);var D=T.isDirectory?16:0;let L=T.isDirectory?16384:32768;return y?L|=4095&A.mode:typeof A=="number"?L|=4095&A:L|=T.isDirectory?493:420,D=(D|L<<16)>>>0,T.attr=D,T.setData(b),P||a.setEntry(T),T},getEntries:function(_){return a.password=_,a?a.entries:[]},getEntry:function(_){return x(_)},getEntryCount:function(){return a.getEntryCount()},forEach:function(_){return a.forEach(_)},extractEntryTo:function(_,b,I,A,T,P){A=Fn(!1,A),T=Fn(!1,T),I=Fn(!0,I),P=ku(T,P);var y=x(_);if(!y)throw be.Errors.NO_ENTRY();var D=d(y.entryName),L=u(b,P&&!y.isDirectory?P:I?D:Ee.basename(D));if(y.isDirectory){var B=a.getEntryChildren(y);return B.forEach(function(J){if(J.isDirectory)return;var ie=J.getData();if(!ie)throw be.Errors.CANT_EXTRACT_FILE();var Q=d(J.entryName),te=u(b,I?Q:Ee.basename(Q));let oe=T?J.header.fileAttr:void 0;o.writeFileTo(te,ie,A,oe)}),!0}var M=y.getData(a.password);if(!M)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!A)throw be.Errors.CANT_OVERRIDE();let Y=T?_.header.fileAttr:void 0;return o.writeFileTo(L,M,A,Y),!0},test:function(_){if(!a)return!1;for(var b in a.entries)try{if(b.isDirectory)continue;var I=a.entries[b].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,b,I,A){if(I=Fn(!1,I),A=ku(I,A),b=Fn(!1,b),!a)throw be.Errors.NO_ZIP();a.entries.forEach(function(T){var P=u(_,d(T.entryName));if(T.isDirectory){o.makeDir(P);return}var y=T.getData(A);if(!y)throw be.Errors.CANT_EXTRACT_FILE();let D=I?T.header.fileAttr:void 0;o.writeFileTo(P,y,b,D);try{o.fs.utimesSync(P,T.header.time,T.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,b,I,A){if(A=$m(b,I,A),I=Fn(!1,I),b=Fn(!1,b),!A)return new Promise((L,B)=>{this.extractAllToAsync(_,b,I,function(M){M?B(M):L(this)})});if(!a){A(be.Errors.NO_ZIP());return}_=Ee.resolve(_);let T=L=>u(_,Ee.normalize(d(L.entryName))),P=(L,B)=>new Error(L+': "'+B+'"'),y=[],D=[];a.entries.forEach(L=>{L.isDirectory?y.push(L):D.push(L)});for(let L of y){let B=T(L),M=I?L.header.fileAttr:void 0;try{o.makeDir(B),M&&o.fs.chmodSync(B,M),o.fs.utimesSync(B,L.header.time,L.header.time)}catch{A(P("Unable to create folder",B))}}D.reverse().reduce(function(L,B){return function(M){if(M)L(M);else{let Y=Ee.normalize(d(B.entryName)),J=u(_,Y);B.getDataAsync(function(ie,Q){if(Q)L(Q);else if(!ie)L(be.Errors.CANT_EXTRACT_FILE());else{let te=I?B.header.fileAttr:void 0;o.writeFileToAsync(J,ie,b,te,function(oe){oe||L(P("Unable to write file",J)),o.fs.utimes(J,B.header.time,B.header.time,function(R){R?L(P("Unable to set times",J)):L()})})}})}}},A)()},writeZip:function(_,b){if(arguments.length===1&&typeof _=="function"&&(b=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=a.compressToBuffer();if(I){var A=o.writeFileTo(_,I,!0);typeof b=="function"&&b(A?null:new Error("failed"),"")}}},writeZipPromise:function(_,b){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},b);return new Promise((T,P)=>{!_&&i.filename&&(_=i.filename),_||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=L=>L?T(L):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,A,D)},P)})},toBufferPromise:function(){return new Promise((_,b)=>{a.toAsyncBuffer(_,b)})},toBuffer:function(_,b,I,A){return typeof _=="function"?(a.toAsyncBuffer(_,b,I,A),null):a.compressToBuffer()}}}});import{execFile as Q_,spawn as ey,spawnSync as fk}from"node:child_process";import{promisify as ty}from"node:util";function ry(t){if(process.platform!=="win32")return!1;if(Yf.test(t))return!0;let n=(t.split(/[/\\]/).pop()??t).replace(Yf,"").toLowerCase();return ny.has(n)}function Zf(t,e){if(process.platform!=="win32")return e??{};let n={...e??{}};return ry(t)&&n.shell===void 0&&(n.shell=!0),n.windowsHide===void 0&&(n.windowsHide=!0),n}function rt(t,e=[],n={}){return ey(t,e,Zf(t,n))}function Xf(t,e=[],n={}){return iy(t,e,Zf(t,n))}var ny,Yf,iy,Zt=et(()=>{"use strict";ny=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Yf=/\.(cmd|bat|ps1)$/i;iy=ty(Q_)});var Qt=ae((XD,Fh)=>{"use strict";var Mh=["nodebuffer","arraybuffer","fragments"],Bh=typeof Blob<"u";Bh&&Mh.push("blob");Fh.exports={BINARY_TYPES:Mh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Bh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ts=ae((QD,qo)=>{"use strict";var{EMPTY_BUFFER:nv}=Qt(),kd=Buffer[Symbol.species];function rv(t,e){if(t.length===0)return nv;if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let a=t[o];n.set(a,i),i+=a.length}return i<e?new kd(n.buffer,n.byteOffset,i):n}function zh(t,e,n,i,o){for(let a=0;a<o;a++)n[i+a]=t[a]^e[a&3]}function Uh(t,e){for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function iv(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Td(t){if(Td.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new kd(t):ArrayBuffer.isView(t)?e=new kd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Td.readOnly=!1),e}qo.exports={concat:rv,mask:zh,toArrayBuffer:iv,toBuffer:Td,unmask:Uh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=he("bufferutil");qo.exports.mask=function(e,n,i,o,a){a<48?zh(e,n,i,o,a):t.mask(e,n,i,o,a)},qo.exports.unmask=function(e,n){e.length<32?Uh(e,n):t.unmask(e,n)}}catch{}});var Hh=ae((eR,Gh)=>{"use strict";var qh=Symbol("kDone"),Cd=Symbol("kRun"),Dd=class{constructor(e){this[qh]=()=>{this.pending--,this[Cd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Cd]()}[Cd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[qh])}}};Gh.exports=Dd});var Vr=ae((tR,$h)=>{"use strict";var ns=he("zlib"),jh=ts(),sv=Hh(),{kStatusCode:Wh}=Qt(),ov=Buffer[Symbol.species],av=Buffer.from([0,0,255,255]),Ho=Symbol("permessage-deflate"),en=Symbol("total-length"),Kr=Symbol("callback"),Pn=Symbol("buffers"),$r=Symbol("error"),Go,Rd=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,!Go){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Go=new sv(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[Kr];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 a=+o;if(!Number.isInteger(a)||a<8||a>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=a}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let a=+o;if(!Number.isInteger(a)||a<8||a>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=a}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){Go.add(o=>{this._decompress(e,n,(a,d)=>{o(),i(a,d)})})}compress(e,n,i){Go.add(o=>{this._compress(e,n,(a,d)=>{o(),i(a,d)})})}_decompress(e,n,i){let o=this._isServer?"client":"server";if(!this._inflate){let a=`${o}_max_window_bits`,d=typeof this.params[a]!="number"?ns.Z_DEFAULT_WINDOWBITS:this.params[a];this._inflate=ns.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Ho]=this,this._inflate[en]=0,this._inflate[Pn]=[],this._inflate.on("error",dv),this._inflate.on("data",Kh)}this._inflate[Kr]=i,this._inflate.write(e),n&&this._inflate.write(av),this._inflate.flush(()=>{let a=this._inflate[$r];if(a){this._inflate.close(),this._inflate=null,i(a);return}let d=jh.concat(this._inflate[Pn],this._inflate[en]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[en]=0,this._inflate[Pn]=[],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 a=`${o}_max_window_bits`,d=typeof this.params[a]!="number"?ns.Z_DEFAULT_WINDOWBITS:this.params[a];this._deflate=ns.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[en]=0,this._deflate[Pn]=[],this._deflate.on("data",cv)}this._deflate[Kr]=i,this._deflate.write(e),this._deflate.flush(ns.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let a=jh.concat(this._deflate[Pn],this._deflate[en]);n&&(a=new ov(a.buffer,a.byteOffset,a.length-4)),this._deflate[Kr]=null,this._deflate[en]=0,this._deflate[Pn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,a)})}};$h.exports=Rd;function cv(t){this[Pn].push(t),this[en]+=t.length}function Kh(t){if(this[en]+=t.length,this[Ho]._maxPayload<1||this[en]<=this[Ho]._maxPayload){this[Pn].push(t);return}this[$r]=new RangeError("Max payload size exceeded"),this[$r].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[$r][Wh]=1009,this.removeListener("data",Kh),this.reset()}function dv(t){if(this[Ho]._inflate=null,this[$r]){this[Kr](this[$r]);return}t[Wh]=1007,this[Kr](t)}});var Jr=ae((nR,jo)=>{"use strict";var{isUtf8:Vh}=he("buffer"),{hasBlob:lv}=Qt(),uv=[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 fv(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Pd(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 hv(t){return lv&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}jo.exports={isBlob:hv,isValidStatusCode:fv,isValidUTF8:Pd,tokenChars:uv};if(Vh)jo.exports.isValidUTF8=function(t){return t.length<24?Pd(t):Vh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=he("utf-8-validate");jo.exports.isValidUTF8=function(e){return e.length<32?Pd(e):t(e)}}catch{}});var Bd=ae((rR,tx)=>{"use strict";var{Writable:xv}=he("stream"),Jh=Vr(),{BINARY_TYPES:pv,EMPTY_BUFFER:Yh,kStatusCode:gv,kWebSocket:mv}=Qt(),{concat:Od,toArrayBuffer:wv,unmask:_v}=ts(),{isValidStatusCode:yv,isValidUTF8:Zh}=Jr(),Wo=Buffer[Symbol.species],xt=0,Xh=1,Qh=2,ex=3,Ld=4,Nd=5,Ko=6,Md=class extends xv{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||pv[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[mv]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=xt}_write(e,n,i){if(this._opcode===8&&this._state==xt)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 Wo(i.buffer,i.byteOffset+e,i.length-e),new Wo(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 Wo(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 xt:this.getInfo(e);break;case Xh:this.getPayloadLength16(e);break;case Qh:this.getPayloadLength64(e);break;case ex:this.getMask();break;case Ld:this.getData(e);break;case Nd:case Ko: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[Jh.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=Xh:this._payloadLength===127?this._state=Qh: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=ex:this._state=Ld}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Ld}getData(e){let n=Yh;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&&_v(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._compressed){this._state=Nd,this.decompress(n,e);return}n.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(n)),this.dataMessage(e)}decompress(e,n){this._extensions[Jh.extensionName].decompress(e,this._fin,(o,a)=>{if(o)return n(o);if(a.length){if(this._messageLength+=a.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}this._fragments.push(a)}this.dataMessage(n),this._state===xt&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=xt;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=Od(i,n):this._binaryType==="arraybuffer"?o=wv(Od(i,n)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=xt):(this._state=Ko,setImmediate(()=>{this.emit("message",o,!0),this._state=xt,this.startLoop(e)}))}else{let o=Od(i,n);if(!this._skipUTF8Validation&&!Zh(o)){let a=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(a);return}this._state===Nd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=xt):(this._state=Ko,setImmediate(()=>{this.emit("message",o,!1),this._state=xt,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Yh),this.end();else{let i=e.readUInt16BE(0);if(!yv(i)){let a=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(a);return}let o=new Wo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Zh(o)){let a=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(a);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=xt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=xt):(this._state=Ko,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=xt,this.startLoop(n)}))}createError(e,n,i,o,a){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(d,this.createError),d.code=a,d[gv]=o,d}};tx.exports=Md});var Ud=ae((sR,ix)=>{"use strict";var{Duplex:iR}=he("stream"),{randomFillSync:Ev}=he("crypto"),nx=Vr(),{EMPTY_BUFFER:bv,kWebSocket:vv,NOOP:Sv}=Qt(),{isBlob:Yr,isValidStatusCode:Iv}=Jr(),{mask:rx,toBuffer:tr}=ts(),pt=Symbol("kByteLength"),Av=Buffer.alloc(4),$o=8*1024,nr,Zr=$o,It=0,kv=1,Tv=2,Fd=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=It,this.onerror=Sv,this[vv]=void 0}static frame(e,n){let i,o=!1,a=2,d=!1;n.mask&&(i=n.maskBuffer||Av,n.generateMask?n.generateMask(i):(Zr===$o&&(nr===void 0&&(nr=Buffer.alloc($o)),Ev(nr,0,$o),Zr=0),i[0]=nr[Zr++],i[1]=nr[Zr++],i[2]=nr[Zr++],i[3]=nr[Zr++]),d=(i[0]|i[1]|i[2]|i[3])===0,a=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 f=u;u>=65536?(a+=8,f=127):u>125&&(a+=2,f=126);let x=Buffer.allocUnsafe(o?u+a:a);return x[0]=n.fin?n.opcode|128:n.opcode,n.rsv1&&(x[0]|=64),x[1]=f,f===126?x.writeUInt16BE(u,2):f===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),n.mask?(x[1]|=128,x[a-4]=i[0],x[a-3]=i[1],x[a-2]=i[2],x[a-1]=i[3],d?[x,e]:o?(rx(e,i,x,a,u),[x]):(rx(e,i,e,0,u),[x,e])):[x,e]}close(e,n,i,o){let a;if(e===void 0)a=bv;else{if(typeof e!="number"||!Iv(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)a=Buffer.allocUnsafe(2),a.writeUInt16BE(e,0);else{let u=Buffer.byteLength(n);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");a=Buffer.allocUnsafe(2+u),a.writeUInt16BE(e,0),typeof n=="string"?a.write(n,2):a.set(n,2)}}let d={[pt]:a.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==It?this.enqueue([this.dispatch,a,!1,d,o]):this.sendFrame(t.frame(a,d),o)}ping(e,n,i){let o,a;if(typeof e=="string"?(o=Buffer.byteLength(e),a=!1):Yr(e)?(o=e.size,a=!1):(e=tr(e),o=e.length,a=tr.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:a,rsv1:!1};Yr(e)?this._state!==It?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==It?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,n,i){let o,a;if(typeof e=="string"?(o=Buffer.byteLength(e),a=!1):Yr(e)?(o=e.size,a=!1):(e=tr(e),o=e.length,a=tr.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:a,rsv1:!1};Yr(e)?this._state!==It?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==It?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,n,i){let o=this._extensions[nx.extensionName],a=n.binary?2:1,d=n.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Yr(e)?(u=e.size,f=!1):(e=tr(e),u=e.length,f=tr.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,a=0),n.fin&&(this._firstFragment=!0);let x={[pt]:u,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:a,readOnly:f,rsv1:d};Yr(e)?this._state!==It?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==It?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,n,i,o){this._bufferedBytes+=i[pt],this._state=Tv,e.arrayBuffer().then(a=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(zd,this,u,o);return}this._bufferedBytes-=i[pt];let d=tr(a);n?this.dispatch(d,n,i,o):(this._state=It,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(a=>{process.nextTick(Cv,this,a,o)})}dispatch(e,n,i,o){if(!n){this.sendFrame(t.frame(e,i),o);return}let a=this._extensions[nx.extensionName];this._bufferedBytes+=i[pt],this._state=kv,a.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");zd(this,f,o);return}this._bufferedBytes-=i[pt],this._state=It,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===It&&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)}};ix.exports=Fd;function zd(t,e,n){typeof n=="function"&&n(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],a=o[o.length-1];typeof a=="function"&&a(e)}}function Cv(t,e,n){zd(t,e,n),t.onerror(e)}});var hx=ae((oR,fx)=>{"use strict";var{kForOnEventAttribute:rs,kListener:qd}=Qt(),sx=Symbol("kCode"),ox=Symbol("kData"),ax=Symbol("kError"),cx=Symbol("kMessage"),dx=Symbol("kReason"),Xr=Symbol("kTarget"),lx=Symbol("kType"),ux=Symbol("kWasClean"),tn=class{constructor(e){this[Xr]=null,this[lx]=e}get target(){return this[Xr]}get type(){return this[lx]}};Object.defineProperty(tn.prototype,"target",{enumerable:!0});Object.defineProperty(tn.prototype,"type",{enumerable:!0});var rr=class extends tn{constructor(e,n={}){super(e),this[sx]=n.code===void 0?0:n.code,this[dx]=n.reason===void 0?"":n.reason,this[ux]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[sx]}get reason(){return this[dx]}get wasClean(){return this[ux]}};Object.defineProperty(rr.prototype,"code",{enumerable:!0});Object.defineProperty(rr.prototype,"reason",{enumerable:!0});Object.defineProperty(rr.prototype,"wasClean",{enumerable:!0});var Qr=class extends tn{constructor(e,n={}){super(e),this[ax]=n.error===void 0?null:n.error,this[cx]=n.message===void 0?"":n.message}get error(){return this[ax]}get message(){return this[cx]}};Object.defineProperty(Qr.prototype,"error",{enumerable:!0});Object.defineProperty(Qr.prototype,"message",{enumerable:!0});var is=class extends tn{constructor(e,n={}){super(e),this[ox]=n.data===void 0?null:n.data}get data(){return this[ox]}};Object.defineProperty(is.prototype,"data",{enumerable:!0});var Dv={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[rs]&&o[qd]===e&&!o[rs])return;let i;if(t==="message")i=function(a,d){let u=new is("message",{data:d?a:a.toString()});u[Xr]=this,Vo(e,this,u)};else if(t==="close")i=function(a,d){let u=new rr("close",{code:a,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Xr]=this,Vo(e,this,u)};else if(t==="error")i=function(a){let d=new Qr("error",{error:a,message:a.message});d[Xr]=this,Vo(e,this,d)};else if(t==="open")i=function(){let a=new tn("open");a[Xr]=this,Vo(e,this,a)};else return;i[rs]=!!n[rs],i[qd]=e,n.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[qd]===e&&!n[rs]){this.removeListener(t,n);break}}};fx.exports={CloseEvent:rr,ErrorEvent:Qr,Event:tn,EventTarget:Dv,MessageEvent:is};function Vo(t,e,n){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var Jo=ae((aR,xx)=>{"use strict";var{tokenChars:ss}=Jr();function Ft(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,a=!1,d,u,f=-1,x=-1,g=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),d===void 0)if(g===-1&&ss[x]===1)f===-1&&(f=w);else if(w!==0&&(x===32||x===9))g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);x===44?(Ft(e,_,n),n=Object.create(null)):d=_,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(g===-1&&ss[x]===1)f===-1&&(f=w);else if(x===32||x===9)g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w),Ft(n,t.slice(f,g),!0),x===44&&(Ft(e,d,n),n=Object.create(null),d=void 0),f=g=-1}else if(x===61&&f!==-1&&g===-1)u=t.slice(f,w),f=g=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(ss[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);f===-1?f=w:i||(i=!0),o=!1}else if(a)if(ss[x]===1)f===-1&&(f=w);else if(x===34&&f!==-1)a=!1,g=w;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(x===34&&t.charCodeAt(w-1)===61)a=!0;else if(g===-1&&ss[x]===1)f===-1&&(f=w);else if(f!==-1&&(x===32||x===9))g===-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);i&&(_=_.replace(/\\/g,""),i=!1),Ft(n,u,_),x===44&&(Ft(e,d,n),n=Object.create(null),d=void 0),u=void 0,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(f===-1||a||x===32||x===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=w);let S=t.slice(f,g);return d===void 0?Ft(e,S,n):(u===void 0?Ft(n,S,!0):i?Ft(n,u,S.replace(/\\/g,"")):Ft(n,u,S),Ft(e,d,n)),e}function Pv(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 a=i[o];return Array.isArray(a)||(a=[a]),a.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}xx.exports={format:Pv,parse:Rv}});var Qo=ae((lR,kx)=>{"use strict";var Ov=he("events"),Lv=he("https"),Nv=he("http"),mx=he("net"),Mv=he("tls"),{randomBytes:Bv,createHash:Fv}=he("crypto"),{Duplex:cR,Readable:dR}=he("stream"),{URL:Gd}=he("url"),On=Vr(),zv=Bd(),Uv=Ud(),{isBlob:qv}=Jr(),{BINARY_TYPES:px,CLOSE_TIMEOUT:Gv,EMPTY_BUFFER:Yo,GUID:Hv,kForOnEventAttribute:Hd,kListener:jv,kStatusCode:Wv,kWebSocket:He,NOOP:_x}=Qt(),{EventTarget:{addEventListener:Kv,removeEventListener:$v}}=hx(),{format:Vv,parse:Jv}=Jo(),{toBuffer:Yv}=ts(),yx=Symbol("kAborted"),jd=[8,13],nn=["CONNECTING","OPEN","CLOSING","CLOSED"],Zv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,we=class t extends Ov{constructor(e,n,i){super(),this._binaryType=px[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Yo,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]),Ex(this,e,n,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){px.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 zv({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),a=new Uv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=a,this._socket=e,o[He]=this,a[He]=this,e[He]=this,o.on("conclude",eS),o.on("drain",tS),o.on("error",nS),o.on("message",rS),o.on("ping",iS),o.on("pong",sS),a.onerror=oS,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",Sx),e.on("data",Xo),e.on("end",Ix),e.on("error",Ax),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[On.extensionName]&&this._extensions[On.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){at(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,n,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),vx(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){Wd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||Yo,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){Wd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.pong(e||Yo,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){Wd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[On.extensionName]||(o.compress=!1),this._sender.send(e||Yo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){at(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(we,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(we.prototype,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(we,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(we.prototype,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(we,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(we.prototype,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(we,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});Object.defineProperty(we.prototype,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(we.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(we.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Hd])return e[jv];return null},set(e){for(let n of this.listeners(t))if(n[Hd]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Hd]:!0})}})});we.prototype.addEventListener=Kv;we.prototype.removeEventListener=$v;kx.exports=we;function Ex(t,e,n,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Gv,protocolVersion:jd[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,!jd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${jd.join(", ")})`);let a;if(e instanceof Gd)a=e;else try{a=new Gd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}a.protocol==="http:"?a.protocol="ws:":a.protocol==="https:"&&(a.protocol="wss:"),t._url=a.href;let d=a.protocol==="wss:",u=a.protocol==="ws+unix:",f;if(a.protocol!=="ws:"&&!d&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!a.pathname?f="The URL's pathname is empty":a.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;Zo(t,I);return}let x=d?443:80,g=Bv(16).toString("base64"),w=d?Lv.request:Nv.request,S=new Set,_;if(o.createConnection=o.createConnection||(d?Qv:Xv),o.defaultPort=o.defaultPort||x,o.port=a.port||x,o.host=a.hostname.startsWith("[")?a.hostname.slice(1,-1):a.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=a.pathname+a.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new On({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Vv({[On.extensionName]:_.offer()})),n.length){for(let I of n){if(typeof I!="string"||!Zv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.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),(a.username||a.password)&&(o.auth=`${a.username}:${a.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let b;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:a.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:a.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")),b=t._req=w(o),t._redirects&&t.emit("redirect",t.url,b)}else b=t._req=w(o);o.timeout&&b.on("timeout",()=>{at(t,b,"Opening handshake has timed out")}),b.on("error",I=>{b===null||b[yx]||(b=t._req=null,Zo(t,I))}),b.on("response",I=>{let A=I.headers.location,T=I.statusCode;if(A&&o.followRedirects&&T>=300&&T<400){if(++t._redirects>o.maxRedirects){at(t,b,"Maximum redirects exceeded");return}b.abort();let P;try{P=new Gd(A,e)}catch{let D=new SyntaxError(`Invalid URL: ${A}`);Zo(t,D);return}Ex(t,P,n,i)}else t.emit("unexpected-response",b,I)||at(t,b,`Unexpected server response: ${I.statusCode}`)}),b.on("upgrade",(I,A,T)=>{if(t.emit("upgrade",I),t.readyState!==we.CONNECTING)return;b=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){at(t,A,"Invalid Upgrade header");return}let y=Fv("sha1").update(g+Hv).digest("base64");if(I.headers["sec-websocket-accept"]!==y){at(t,A,"Invalid Sec-WebSocket-Accept header");return}let D=I.headers["sec-websocket-protocol"],L;if(D!==void 0?S.size?S.has(D)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){at(t,A,L);return}D&&(t._protocol=D);let B=I.headers["sec-websocket-extensions"];if(B!==void 0){if(!_){at(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=Jv(B)}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(M);if(Y.length!==1||Y[0]!==On.extensionName){at(t,A,"Server indicated an extension that was not requested");return}try{_.accept(M[On.extensionName])}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[On.extensionName]=_}t.setSocket(A,T,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(b,t):b.end()}function Zo(t,e){t._readyState=we.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Xv(t){return t.path=t.socketPath,mx.connect(t)}function Qv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=mx.isIP(t.host)?"":t.host),Mv.connect(t)}function at(t,e,n){t._readyState=we.CLOSING;let i=new Error(n);Error.captureStackTrace(i,at),e.setHeader?(e[yx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Zo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Wd(t,e,n){if(e){let i=qv(e)?e.size:Yv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(n){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${nn[t.readyState]})`);process.nextTick(n,i)}}function eS(t,e){let n=this[He];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[He]!==void 0&&(n._socket.removeListener("data",Xo),process.nextTick(bx,n._socket),t===1005?n.close():n.close(t,e))}function tS(){let t=this[He];t.isPaused||t._socket.resume()}function nS(t){let e=this[He];e._socket[He]!==void 0&&(e._socket.removeListener("data",Xo),process.nextTick(bx,e._socket),e.close(t[Wv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function gx(){this[He].emitClose()}function rS(t,e){this[He].emit("message",t,e)}function iS(t){let e=this[He];e._autoPong&&e.pong(t,!this._isServer,_x),e.emit("ping",t)}function sS(t){this[He].emit("pong",t)}function bx(t){t.resume()}function oS(t){let e=this[He];e.readyState!==we.CLOSED&&(e.readyState===we.OPEN&&(e._readyState=we.CLOSING,vx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function vx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Sx(){let t=this[He];if(this.removeListener("close",Sx),this.removeListener("data",Xo),this.removeListener("end",Ix),t._readyState=we.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[He]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",gx),t._receiver.on("finish",gx))}function Xo(t){this[He]._receiver.write(t)||this.pause()}function Ix(){let t=this[He];t._readyState=we.CLOSING,t._receiver.end(),this.end()}function Ax(){let t=this[He];this.removeListener("error",Ax),this.on("error",_x),t&&(t._readyState=we.CLOSING,this.destroy())}});var Rx=ae((fR,Dx)=>{"use strict";var uR=Qo(),{Duplex:aS}=he("stream");function Tx(t){t.emit("close")}function cS(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Cx(t){this.removeListener("error",Cx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function dS(t,e){let n=!0,i=new aS({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(a,d){let u=!d&&i._readableState.objectMode?a.toString():a;i.push(u)||t.pause()}),t.once("error",function(a){i.destroyed||(n=!1,i.destroy(a))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,a){if(t.readyState===t.CLOSED){a(o),process.nextTick(Tx,i);return}let d=!1;t.once("error",function(f){d=!0,a(f)}),t.once("close",function(){d||a(o),process.nextTick(Tx,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,a,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,a,d)});return}t.send(o,d)},i.on("end",cS),i.on("error",Cx),i}Dx.exports=dS});var Kd=ae((hR,Px)=>{"use strict";var{tokenChars:lS}=Jr();function uS(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&&lS[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 a=t.slice(n,o);if(e.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);return e.add(a),e}Px.exports={parse:uS}});var zx=ae((pR,Fx)=>{"use strict";var fS=he("events"),ea=he("http"),{Duplex:xR}=he("stream"),{createHash:hS}=he("crypto"),Ox=Jo(),ir=Vr(),xS=Kd(),pS=Qo(),{CLOSE_TIMEOUT:gS,GUID:mS,kWebSocket:wS}=Qt(),_S=/^[+/0-9A-Za-z]{22}==$/,Lx=0,Nx=1,Bx=2,$d=class extends fS{constructor(e,n){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:gS,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:pS,...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=ea.createServer((i,o)=>{let a=ea.STATUS_CODES[426];o.writeHead(426,{"Content-Length":a.length,"Content-Type":"text/plain"}),o.end(a)}),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=yS(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,a,d)=>{this.handleUpgrade(o,a,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Lx}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===Bx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(os,this);return}if(e&&this.once("close",e),this._state!==Nx)if(this._state=Nx,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(os,this):process.nextTick(os,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{os(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",Mx);let a=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){sr(this,e,n,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){sr(this,e,n,400,"Invalid Upgrade header");return}if(a===void 0||!_S.test(a)){sr(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){sr(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){as(n,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=xS.parse(f)}catch{sr(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 S=new ir({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=Ox.parse(g);_[ir.extensionName]&&(S.accept(_[ir.extensionName]),w[ir.extensionName]=S)}catch{sr(this,e,n,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,(_,b,I,A)=>{if(!_)return as(n,b||401,I,A);this.completeUpgrade(w,a,x,e,n,i,o)});return}if(!this.options.verifyClient(S))return as(n,401)}this.completeUpgrade(w,a,x,e,n,i,o)}completeUpgrade(e,n,i,o,a,d,u){if(!a.readable||!a.writable)return a.destroy();if(a[wS])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Lx)return as(a,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${hS("sha1").update(n+mS).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&&(x.push(`Sec-WebSocket-Protocol: ${w}`),g._protocol=w)}if(e[ir.extensionName]){let w=e[ir.extensionName].params,S=Ox.format({[ir.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${S}`),g._extensions=e}this.emit("headers",x,o),a.write(x.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),
|
|
16
|
+
`)),a.removeListener("error",Mx),g.setSocket(a,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(g),g.on("close",()=>{this.clients.delete(g),this._shouldEmitClose&&!this.clients.size&&process.nextTick(os,this)})),u(g,o)}};Fx.exports=$d;function yS(t,e){for(let n of Object.keys(e))t.on(n,e[n]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function os(t){t._state=Bx,t.emit("close")}function Mx(){this.destroy()}function as(t,e,n,i){n=n||ea.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${ea.STATUS_CODES[e]}\r
|
|
17
17
|
`+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
|
|
18
18
|
`)+`\r
|
|
19
19
|
\r
|
|
20
|
-
`+r)}function ir(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,ir),t.emit("wsClientError",d,r,e)}else as(r,i,o,c)}});var Yx=ce(ze=>{"use strict";function ia(){let t=["zw5KCg9PBNq","BeXjCKK","q09otKvdveK","Aw5L","rNzSCgW","t2rQBKW","Cgf5Bg9Hzeu","tg9Nsuq","reXUt2q","ruzhAMi","vwjWAwy","x2LZtM9Kzq","Cg9W","CMvXDwLYzwq","yw51Ce1LC3m","Aw5KzxGGB3u","D3bPCLa","suzQDxm","zMXVB3i","qxjwBLm","vgDtBve","rKDkqM4","rvjst1i","DgfIyxnL","z2vtEw5J","B25JBg9Zzq","wfftseC","yNL0zu9MzNm","DMTbuwS","BMvLzf9Hy2S","y3v1Cey","DuvxAKq","q1zwDgS","Aw9Ul2PZB24","rNr3AMO","CgLUz19VBMm","ihn1y2nLC3m","wMjguwm","pxv0zI04","rujPvxO","A0PuCNy","CuXsEuO","CMvTB3zLq2G","BgLZDgvUtMu","rK1cCMO","AgfUz2u","sMzcuwK","uxDSB1K","x21LC3nHz2u","sgXQsNK","s3L4r3u","u2TPCcbWyxm","ywX3yxLZ","rLjptLrjrvi","BwLdv0y","vgvosMm","x3DZ","Aw51t1O","CMvZzxrfBMq","t1bftL9fuLi","zKjWBfK","x2rYB3bhBg8","ueXHELy","C2nYAxb0","qvf2r2e","sMPirxG","tevhvKO","B25tDgfYDfi","revwq2G","AxnmB25N","CMvZzxrdB3u","A2LJC1K","uePJzwC","wu1yzwi","q0jrtMu","A0Xts3O","BM1Ur1q","BgfctgK","nNW0Fdm","zLfSrfy","x2XPC3rLBMu","uLrIshy","zuHLt3m","shHIsM0","BgvUz3rO","sLPpA3a","tMjWA1e","yNzxAu4","vfH1y1e","wvPKz2e","mZqYotu2mePLCeHQza","yNPsuey","CMvJzwL2zwq","CuTnAhG","z2HLDgC","DLPxsxu","zeHAtum","te1Kz00","z0jKwgG","CgLUz09Uy2u","Dg9oDw1Izxi","x3vYBa","ywXSq3vYC28","rM1Ot0G","B3nLrxzLBNq","weDnCfm","BNruCMLLC0m","DxrVuMvJB24","BwvZ","u2vYDMLJzvC","qNH2yM0","vxbKyxrLq28","rLDt","v1nXDwW","AKH6uuy","CLnWuei","uuzmsvq","AvnlALm","rwvuEKO","y1fQDLK","zxv2vxe","BwLUzW","qw55Cwe","uerzyM4","q2HhAvG","yMrFzgLK","mtb3Cej6Cvi","q2PprgK","rNjVBNrPzxi","yu1XrgS","twTPyMy","zw1PDa","ruz3tuu","qLnktMq","shvVzhm","zKTZwgO","BM5Ly3q","rKjmB2i","v05iB2S","wursy2e","B3fWCvG","zM9YrwfJAa","ugXNrvO","t2zYuMy","Dgv4sgi","svfUvNq","qLPjAxi","uurxEMG","yKv6v1G","BLPdwwS","v2Hguhm","B2jQzwn0u3q","sLnZzuy","AgfZt3DUuhi","yM9KEq","zwnVBM5Ly3q","C1PKs2G","ywrKq291BNq","rxjYB3jdB2q","qKzlre4","EvvJwxm","zgLZCgf0y2G","ENv0uMy","uMvHzcbWyxm","y09Wzw4","ywr2yw5Jzq","yKnWB0e","y0frCem","vMX0qMe","twvZC2fNzuu","AurUsuu","uMDXvMK","y1fxzu4","CgjICdi","wMHcA1O","zgjPthq","qwjVCNrfCNi","D3nZoI8V","CKLpA3i","yNvMzMvYzwq","t3bLBKv2zw4","uM9ZuKi","q1Pts00","vw94ve0","B3bmqLa","EwD6tuS","Aw5KzxHpzG","rw9SAhy","CLzHBhvLCW","vLjjwNK","r0X6z1y","tvHqsLu","yxbWBgLJyxq","sLDyuxu","B3LhAey","igzHAwWSig0","y2vWDhm","EeTOEMC","Dev2zw50","AuLlt2u","whbRAve","DcbSAw1PDa","whzIvgW","we1ruKO","D2fZq2XLyw4","qKPHvw4","C2HPzNq","uLjpuG","AKfHwxi","sLnptLa","ywj6rfe","r0XVz2C","Aw9U","D25qwvC","A0f0qLK","Dgv4Dc9WBge","C1zZENa","Cg93","y2P1qvm","x29UtwvZC2e","vfDUALu","t0vHDeG","x2zVCM1HDeu","s3H3EKy","y29UC3rYDwm","sg1VshG","v3nWDuC","vwz4Bee","zK5JCNa","v3Lxtxu","mNWWFdn8nhW","C0jf","C0ruAgm","DND2AKW","B3v0sw50zxi","Bu9lt0S","DujbAuC","CK90Aha","uhDAy28","zgvSzxrLrge","Dg9iyxnO","x29UvgLTzw8","A2v3AhG","wuvkDwq","DMvY","zgPwBNy","AgvKtwf4uMu","yuDitvq","x3DZsw5ZDge","EfvZzuvUDG","ENHmz0y","zxjFCw9Zx2e","x3bPBMDqB24","zxrxB3jRq2G","DM1WCwO","txruCw8","z0rlr1e","yxrLq291BNq","Dg9cExrLC0W","C2v0u3rVCMe","wvHwDfe","u3PrCNq","zw5HyMXLuw8","tK5rAg8","zw5XDwv1zq","Ahr0Chm6","ug56Dgi","rNjXuw4","DNH6rxa","zM9UuMK","B25fCNjVCG","wgzxAxm","DeXpzNi","u3rvwwW","thnvu2O","v1n0vvO","D0DlBwy","wNbTvwq","ywzqzMS","yw5Hz2vY","zfzmy3O","tK10rwi","o2nOyxjZzxq","zLzyyvq","y2HnyxHuCMK","DLDpr3a","suvtx0vsuK8","zxjYtM8","rNb2zhu","C0nVDw50zxi","vvjiq00","yLPzqM4","C0Xf","A2v5","CKfxBue","q3rIEeC","ve9fq0O","vuvdsKW","vLPkrg0","Ag5cs2m","sgrxsg4","Ef9MCM9UDgK","B25pCgvU","wwvkyxu","BeHHBMrSzxi","uwzTEwi","yxrHlcbKyxq","u0DKvfe","CM92AwrLigi","ELDlDfy","CMvJB25Uzwm","C2v0","yMLUyxj5","z1bJwge","DeHNzLO","BMzUu2i","rMzzzuO","swLvyu4","qK16uLy","z1L5qKK","swrSr1m","zcWG","AM9PBG","zu5TyLu","ywXS","ALv5tNq","zvvOz3y","CMvWBgfJzq","tNv0vwC","DeHhBvu","mNWXFdn8mhW","yvfjqNe","zw5fDMvUDa","CMvKDwnL","tfnZBha","zgjHuhi","CxnMzvG","C3bSAwnL","zw5JB2rPBMC","yuPhEw4","zMDet0W","AejnrvC","ze1YwLK","CNHiB0O","u2vKyuy","wMjxBLq","ywnRx2nVzgu","BMDuAw1LCG","x2nYzwf0zvm","x2rItMfTzq","y29Kzq","Ae1LC3nHz2u","thvmAg4","ywjVCNq","ywDiuei","s3jryK8","zcWGDw5RBM8","uvPABhm","vgHlr2W","t1bftG","re1XCfy","zMTjvhm","CgvYC2LZDgu","y1n5Cvi","DKvMDee","B2zMBgLUzq","yNvMzMvY","s2vguKi","zg9Uzq","zMPdqKC","s0zIs3q","yKDpCvO","sLD4zfy","A25dqvu","zvvYBa","vKD2CfK","v29rB1y","zMLUza","yM5kvgW","u1nRtuK","C2vYDMLJzq","C3rYAw5N","BejXELm","x2jPBMfYEvq","tg9NsurozxC","v2rTzK0","qvLpDgG","y29UBMvJDgK","AefSzgi","CLvWzw8","A3zbrMC","q3rHv08","mNWXFdb8nhW","vKPWug4","rM12tg4","yxGGCMv0CMK","x3nLBMrby2S","uu94CwO","yMPryuK","DgvmB2Djre4","BMfly0O","shnrte0","r0LUsfK","yM1zA3K","B0TVtNy","AefJA01LC3m","ELnjA0i","CMvHzhDYAxq","tgD6tMO","DMnqCKu","uNvQwNi","yNL0zxm","zxjFCw9Z","AfbiEgy","s1HZvKe","tezhvfG","ign1CNnVCIa","t3DysgW","wKXftey","zLfiqxu","yw1LoIa","ufvfveG","whPjsMi","Dg9cExrLC0i","zgvMAw5Luhi","CxjMt0C","mtjhBMLWzMO","Dhr3Awq","x0vysvnu","DvDxB0C","yunPB1q","reHwwe8","u3rYyxrLz3K","ywDLu2HVDW","x2nSzwfYugK","vuzNs0m","tLrkvei","rLzSChu","BwfUDwfSihi","D1fMuLK","y1jdrfC","zNjVBuj5Dgu","zsbHihn0CMK","rejIEuG","DffUBNm","AwXK","yw5Nzq","twjcqMq","wKTkq3O","CMvZB2X2zq","wxn0wMW","AwrI","teH2wu0","C1z0ENq","zw5NDgG","CMfUzg9T","vwjqvMu","Afzizw0","x2fKzfDZtgK","zuzADei","x2n1CNnVCKy","BwvY","vffktKK","z1Pgrey","C2vUzf9Hy2S","nxWXFdr8nG","tNvcrgK","s0zPB1y","s1nyBwW","CMnMr3G","Eg1dDKe","x3jLywr5q2W","vNnvwu0","Dg5rDNy","zNjVBu51Bwi","z1HXB1i","tNfYwee","oxWXmhWW","Ec1TC2CTy3u","y29Uy2f0","B25LCNjVCG","quLQsue","Bhm6ia","x2LZqNjVD3m","ruXtCNy","CMLPtwq","B2HRDxe","x2vUzhbVAw4","Bxj5sLy","C3rVCcbPBw0","rKLmrv9ot1q","y2XVC2veqG","zxjrCw8","vvjfAem","txzyyvO","y3vKrxa","EfLVwfi","Ec11C2uT","yxjzs3e","C3jJ","DuLYwgi","uvzHwMC","DeLUDgvYy2u","yMfSrxzLBNq","whznqNa","CMXUugm","rxjqBuK","DgvzueG","Bg9NsurozxC","yuPyveW","C0XPC3rLBMu","twTnEMC","t3zQAu4","tg5hBgW","A1z0rMe","zhnLz08","y3jLyxrLuMu","wMPIBwO","uuzHzfi","x3jLBw92zvC","zwL6sKi","t1botuK","swfWANq","EeHprNm","yKvpveG","sKDgwxa","u3fUDxC","x2DLBMvYyxq","Ahvht3a","CNr6uMu","BNzqEvm","Dg9mB3DLCKm","zNjVBNrPzxi","x29Uq2XVC2u","vLrgwwC","s1npyxy","AxDTDvC","ufviEhu","yNL0zuXLBMC","EfD3qxK","wxPkA2K","DwrksfO","tuvtu0fhrv8","twLZC2LUzYa","y3vYC29Y","rw1QCgm","y3jLyxrLt2i","Bg9N","qK5cBLy","z0HLBe4","qwz3BLK","z2rKy1a","A1bgCKC","B0DWANa","De1QCLO","CM9YrxzLBNq","Egjey1y","EhnSzMu","uhbXAxC","ywDL","txvwExK","AxnrB1nnzxm","y2f0y2G","CgfYC2u","wg1syw8","mMX4yLPXzq","DLPxyNi","CMTVBLO","sMrlDgO","B3bLCNr5","CMzgCgu","zwTtv1G","twjowwq","vxHTrMC","zu5HvfO","ywDLsgLKzq","Bwf4tg9ZC0m","wev6AKK","BKXzCw8","DNfyveu","B3jRzxjhBg8","sLvHweq","uwPvD1a","sK90B1i","yM9L","AMHOufi","BePoBxe","B2PUA1K","wvjhwfO","BMCGB3iGyw4","B3vUDa","vMnIBvy","nxWY","q09XCfi","ChH4qMO","vfjszu8","rvLSquy","CuzKB3e","vvLoCKC","AxbpBuK","Cgjrrxi","y3r4","Cu1Wt3e","DcbVzIbYyw4","vhLyu2e","AwfPzxO","zxjFBxnNAwq","AgrxD0i","u2TdD2S","EeTbzuC","ywz5A0C","zM9PrKq","rMHkEMu","B25mAw5L","Ehv4twG","sMTpzve","thf5Cu4","zvHJq0C","y2ffCNu","z2v0q3vYCMu","nNWZFdD8mxW","t3PMv2C","x3bYzwzPEa","tLnLrxa","DMfSDwu","wentDg0","DhDNvMK","DxbKyxrLq3u","AgLNAa","D29iCvK","x2LUAxrqCM8","x3bYB3rVy28","vhPTA2q","v3jcu2S","rw5yuNu","D3j3u2S","Bg93","yMLUza","DxjS","CNHtv1y","vgXQt2q","B2nRzxrtDwm","ig1LC3nHz2u","ufvjqvq","u0DKDva","x2n1CNnVCK0","y29UDgLUDwu","yujwteK","zNDZxZeUmc4","zw5HyMXLvhi","z2v0t3DUuhi","wujrzxy","wKH4ugu","vgf6v3K","zvPUqLm","rg9vvha","x2rLC3rYB3K","yxKSihrYEsa","CMLrBeW","D0TNww4","zufJAW","BwLUAvbYB2C","AxnrB1nby2S","y2XVC2u","CMLLC0nVDw4","AMrnzg8","yxjUuMG","wKffC2u","rNHRwLi","z2vrDwv1zuW","DNnzswC","y3vYC29Yx24","txrxCLK","rLzMuNe","AxnbCNjHEq","z2vjBMzVu3K","x3jLy29UBMu","B25TzxnZywC","rNDNAMq","zxjHDg9Y","BgHcB3C","y3jLyxrLtwu","zxH0ugf5Bg8","z2v0","BfrPBwvVDxq","yMDovNy","zu5gD1a","zhDPu0K","Aw50zwDLCIa","q2zTD0e","B2XKvMvYC2K","vxnvvNK","D2DOq2O","uMvJB25Uzwm","uxf0t2C","ihrPBwvVDxq","sg9SwgO","Dw5RBM93BIa","sLfuBhG","Efrurw52","v3PhD3y","y3rOzMG","ELP6thK","De1HBMfNzxi","s0PIqxC","D0jmzK4","BxPHBxK","DNz5z1m","DvLzrgm","vMjTBw4","BKz1y0O","r2TnB0C","AevYCM9Yrxy","CvLSv3u","y1fQBgC","x2nSzwfYvgK","q3Pjy3O","C3vJy2vZCW","q0Xpu0LorW","yxnZAwDU","C3rVCMu","wfjhu1C","ANrTC1K","zM9Yy2u","DxnLCKLW","rxjIrxC","ANzsvxC","ugTlqu4","y01LC1C","CgLUz1rPBwu","sNL5qLe","C3H6EgO","Dg9hzw5LCMe","z2v0u3rVCMe","y3vYDMfSDwu","tvHqwNG","ven1D20","uerOs3q","AwXSihvZzsa","B25tDg9Wsw0","vMrqrvG","q0Xpu0ve","q3vZDg9Trxi","DerzCNG","ALnQwvu","u3bezwq","t2PWywe","A01kruK","C3bvv3C","B2zMC2v0","C3vIC3rYAw4","CNbuA2m","DNfSz3G","t0PHBhq","rNfRu2G","q1j3DNC","tujlt2G","x2rLyNvN","zw1LBNq","B2nRzxrgywK","su5tvefova","t01mwvK","C3rLBMvYCW","nZDZAfDQqKu","l3DZl3yY","r1vlz1K","wNvYAgC","u2vxsLq","BwvZC2fNztO","ihbYB3rVy28","zMvY","Cgz0q1u","BMDLza","ugvPvLa","EhbmANK","DxDMzfe","s3byzeC","ywrK","AvnVBxq","CNnVCKzPBgu","BKXPBMu","B2zM","CMvUDevUzha","rwvhwMy","vMzet2S","DeHHtvq","B25nzxnZywC","y29UDgv4Da","qwvAsvO","igfYCMf5yNu","CuPsvLu","r3P5tK4","wKr4uw4","vM9Wt08","yK9OqLK","ugj2q3e","z2v0qwXS","t1vIz28","BwzWv0K","DhjPzxmGCMu","vuLdu1m","BMrWB2LUDca","qKnOt0y","vfn0Dwi","qun3yxe","BhHRy3i","sxHcreq","DhjPzxm","yMfJA3vWigu","uKrdCLu","B0HpweS","BgLUzw5V","DxbNCMfKzw4","yvnYruK","CNnVCL92ywW","zgf0yq","ywrKrxzLBNq","zMzmAw5L","CwXvteW","r0DoA2u","t1H6AxO","AKXdEwm","BMvY","B1nnweW","sLnyzw0","sKrPr3e","y3vYCMvUDeu","AgvHzgvYCW","ufbqv2C","DLPsCuW","BgLTAxq","CLrVyNC","B25dBg9Zzq","x194x21Zz18","zv9ZDwnJzxm","Cg9PBNrdB24","zMzLCG","BLjAwNu","ywztyxu","vvnuqKu","uej0B28","BgvY","zMLN","tgzmvvm","B3jRig9MzMW","CMfTugfYyw0","ELzOCuO","C2v0zgi","vM9cuKK","yKnTyw0","yKDwveO","ueXdt0G","D2LSBfjLy28","CxDKtKW","qwzcvNe","DuT0uNy","reDPy3a","BezgwLy","zgvS","AwjfCK4","D0Lvu1C","qu1TExC","zw50","zwrPyxrLBhK","zNjVBujPDhm","BMfTzq","y2vZC0HHBMq","tKLzuei","AgfZ","BwLZzq","s3DqrNy","id4G","B3DYzfm","vfD5Aw8","DLP1y28","C0vxsMG","Cu9dBMW","sNHewxO","rMLLruC","ywXSB2nvBNm","Ew1yA1i","zKfSA1C","CMv0CNLdB3u","y2XLyxi","vvDJB2K","B0Dxuue","tgjmy2q","z2v0q3vYC28","uxvtyue","ihjLy29UBMu","v2vIu29JA2u","wwvUruO","vMvHDMq","v0frBKq","r2DQt1O","yNPfBwi","AwXLtMfTzq","txLMCg0","ALL4A0u","x3nVy2TLDa","A0T2sNu","D24GCMvHC28","tgTKAwW","CMvHzfvjBNq","Bhv4B08","rxn2Auq","A2v5CW","yNLozNe","ruTnEKi","y2XLyxjtDg8","yLLkueq","B3nLza","zw5JB2rLrNi","z2fHBKi","Aw5JBhvKzxm","DhjHBNnHy3q","yKnmvg0","ywnOzwq","svfSr1K","CK9PvxG","EerkEgy","wuH0t1u","BgruB0G","ywXSzwqGBxu","C2DPza","q3D1rMC","vxDbBeC","DMvYC2LVBG","x29WDgLVBNm","y3vZDg9Tshq","zKP0rhm","Dw5ZAwDUzwq","ywDLrxzLBNq","qNPlweu","vgTksMy","C2f1qMK","zMviDu4","wer6Awi","zxPdBhu","Bwf4uMv0CMK","x29Ut3bLBG","Cu16uLe","tgLZDgvUzxi","quXm","D1PnBK4","BKTTDeK","vxvvEfi","swH5wxu","AwDdDey","sLjeshe","zxHLtLC","y2HLy2Tszwe","z2v0qwXSs2u","x1fVu01HBMe","AxnszwfKEq","Dg9zzgK","r1vxwwG","suLKv3m","vLDQwg8","C3rYAw5NAwy","y29UBMvJDeu","ywzL","AufQwxC","DLL1ENe","BMCGzMfPBgu","ihzHBgLKihm","DwPiBNa","AxnFywnR","CfjUA3G","zw5HyMXLqxu","x25HDMLNyxq","B25VCgvU","CgrXC0y","C0jtwha","tg9JAW","rMPwEvC","ywzKtLi","ugD2D2m","tgT1qxG","A01nveu","EMflz04","ywrVwuq","zwfJyvO","s01Jy1e","zxH0zw5ZAw8","ANriv3u","x3bPBMDmB3m","DeTpq3e","uhjPBwfYEuS","shbcuMK","rhfkEK8","y0f1C1K","Aw5Lza","DMvUDa","BMrWB2LUDfq","Evv2C1G","y29UBMvJDca","r0fVvha","vgLTzw91Da","B3bLBIa","mNW0Fdf8m3W","z2vY","CwzfC2W","DxvkqLC","Egr6y3e","CxnxwhG","CMfNzvn5BMm","DgHLBG","uKLjsui","u3Dpsvu","AvfSrxO","y291BNq","vfPNuM8","z2v0sxrLBq","sLL4t2m","ChjVDg9JB2W","r3znEMC","CMzts0q","tMvXAuG","CeTcB2O","x0rctMfTzq","vM9fuLi","uvDuwKG","zwn0","BvHIBLi","rKvIDfm","te9TzLa","rKHxzLi","zNjVBuHHC2G","yMLUyxj5vhK","EejSuLC","vMvhBe0","Dhj1y3rVCIa","DvjhChi","ChjVDg90Exa","txrSq3G","zw50tgLZDgu","Aw5KzxG","tuPvr3e","vKLqAMK","ignVzgu6ia","tNjlvNG","uNnIB2G","B25szwnLAxy","mxWWFdn8nhW","wejVBMq","vKjpwgO","mtK2nZa5nhfKyK54ta","r1LqEuy","Ce5OtKy","q0vnCei","u0jLqxi","x2HHBMrSzva","AenSB3nLrxy","wLbHCgq","DK5NEfy","x21PBMLoyxy","C29YDa","yufRCgu","u2HHCMvKv28","D0fzA1G","DxfQB3G","sfvnu3C","sgP2DfK","Bfv0sg0","q2n4zuG","Dgv4DfbHEwW","EuvzA1e","ALDbAMi","D0DMt2C","ANnOBeS","CMvTB3zLrxy","rfzJz1C","D0XMC1u","D1LPvg8","zNjHBwvuExa","D2LPsNK","DMjrsfe","zNLrvum","z1j3DK0","DuLIuvq","qLfMy2O","x2HHBMrSzvi","reiGzMfPBgu","CNjVCK1LC3m","q1nAEKS","DuvjBgi","y3vYC29Yx2y","otm5nZmWwhLMDe1U","AxnAzxjV","BKDbC3q","tKfyDfK","uwPXuMu","rgf4wwq","suPiqNO","t0jdC2i","zfDVCMTLCKC","z056vxC","v2zSs2q","EgLqqLC","wvPcwLy","yNjfyva","sgv6zvu","yxnL","z0vIELK","DuHhyNm","zNvUy3rPB24","Dg9Y","zxHrCvO","BwvKAwf0zwW","rwfmEva","x2LZsw5PDa","CMnzzwS","DeLK","vLH4sLq","Dxr5A3m","yxDgBwK","x3bPBMC","Du9nD2W","B3bLCNr5tMe","AMfyzxe","CunQEgS","z3vmwfe","BNrLCG","vMnwEeO","B25Uzwn0Aw4","CNzHBfzHBhu","rxzLBNq","D3m6lY8","q294yNe","CMvQzwn0","EeThr2y","ntuXnNbLqK9sDW","yKP4wvK","x19LC01Vzhu","thDesw4","zMvtDwu","zwzIzuy","zMzfB0W","x2LUAxq","CgLUz0XVC3m","EKT3z2y","qvvXweW","twTXvLq","zgv2AwnLx2K","yML0uvi","v0jPAKu","yxjhvhy","B3bLBKrc","z2X1tKS","DhLWzq","Cgf5Bg9Hza","yLfoBKK","BwXbwfi","swP1sxC","vuLUuLy","AejSEMe","rMfkuwG","vw5gseW","DgrmseG","BxnNsuq","qLzRAfm","DMLJzuLeig8","ExLmvMW","t3v4vvG","CxLPsxy","Bwrisvi","yMDIsu8","zKLzDLq","B25ozxr3B3i","s2XHywO","DMz1thi","we1xC04","C3L0Ce0","vfDjrfy","D2vMDfu","BNrfBMrWB2K","y0jIu00","BgLUzq","BMCGDxjSoIa","yxv0BW","u2LJvfe","ysbTDxn0igi","mtaWmdi3yK5cv2nz","BxrszeG","z2D4thq","x2nVBM5Ly3q","AwXLx25HBwu","tKfusvzfx0u","CezMBgy","uKzSBKe","qNPdBKG","swHRy2G","zMX1C2HfEha","C2fNzq","BM9Uzv9UB24","u1vAt2W","wwfUywi","zv90Aw1LB3u","z2u6ia","zuXeAum","CMfTzq","wMPSsMC","BMnLq2XVC2u","CgvVB0W","lcbOB3n0BMe","yvrqv2e","x2rPC2nVBM4","u3Dwr1m","ihrVihjLDhi","tKDFrvjst1i","y3jLyxrLq2W","yw1Lu3bHy2u","ChvZAa","B0HPAgK","DgLTzw91DcW","y29UBMvJDa","DfvRtei","D1HIy0S","s2PZu0W","sKj6ufC","y2HHCKnVzgu","wfrKA2S","ihrPBwvZ","DhDVCMTdAge","tufyx1jfvfi","yufRwvO","DLvYBxq","B3jL","DgvZDa","r21Ps1G","Eu9psu8","DunQqMG","Bg9IywXty28","q3z5uMq","BwHLz0C","zxvqsvK","rNvKvMi","AurPyuG","yMXVy2TLza","CMvHC29U","ufrxzfq","CM92AwrLihC","zwD5EfO","BNbrzNO","x2HHBMrSzu8","wwHdyxy","seruqNG","B1vtA0e","tfforge","BMnVzgLUzW","BMrLEa","tePeB0W","ugvHB3C","BwvZC2fNzv8","AfD1uvq","EePyuKu","tuzju3G","ALfAz0C","CgXLyxnLiha","zMLSDgvY","tvLzELK","zgvSzxrL","y2fSBa","v1nkywm","qu9uvxG","wKPYuNm","sxHVuvC","tMjuCvO","Aw47y2HHCNm","u2vXsuq","vLrmv1u","tLDqDvK","CMvZDwX0","ywWGy3vYC28","aaaaaaaaaaa","ywnRtxnNswq","AxjLza","wNnjyvO","rgjKtLO","svzSsee","AfjWswC","r0XdyNy","C3bSAxq","ugPRChK","BNrbBMrvCgq","q29Kzq","B0jiCeS","CNzHBa","wuD1CMK","u0Hcuxu","t1PwswO","B0jZEuO","DfbQueG","y3LeA1C","rNvxu20","x2TLEvbHDgG","A1ffww8","BhzdB08","txbSBgm","AgvHzgvY","y2XVC2uSihC","CgfNzxnOB3C","AvnVthO","n3WYFdb8m3W","ENjLuwe","yLPxqxi","zxjYtxnN","mteXmdm5mJfYzMDsvg4","vhvmAe8","yw1L","qxzTywm","C2DbBuG","uNjTt2S","x2LUDgvYDMe","y2uGBM90igK","DKHIDMe","CMvHzg9UBhK","zxf1ywXZ","D3jPDgvvAw4","AKzxAhu","DND1Bfa","suDps3y","Beryrxm","DgfYz2v0","zMLSzw5HBwu","B3bLBG","Cg5MC1O","m3WW","y29TCgXLDgu","C1rTA3i","Cu1Uqvy","x3fVC0rc","yKTSCxy","zLnbB2G","thr6ANC","u3LVvu0","zMfNqLC","zwvKzwq","sfj3DNK","zvDoBMS","q2zQsgK","igXHCMDLCIa","q29UzMLN","qw1VDw50","wxjrtvm","Axnby2TdBgu","x29UugfNzu4","sLvjyuC","qvvVDuq","rfvsqK0","tg9Kt3q","z2vOu0m","zgDwCKq","u2rtugK","DxrMofDYAxq","EvjLy29UBMu","vKnHBeu","vwHwy00","CezJzvO","CM92AwrLihy","tffMyLO","tu1wt2e","Afrsuhy","x3nLCuLK","v2LUzg93","C2v0sxrLBq","BM93","CePuBMK","x3DHAxq","uLL2ANi","yNLL","uu9WCw0","Dw50","wxHMtMO","Aw1LCYbPBIa","vvHKtNO","A25MAgW","C3fnq2S","CuThrwe","tw9KDwXL","rffzyvi","Chv0","vvnIt2y","C29iCuW","CxrrCgO","z0H4vwG","zhfWufy","qwjNCNC","uxvLDwu","rwHxvNG","CwX6t20","ywnRx2LK","q291BNq","Ae9oDeO","y3ruAw1LB3u","teTAqKG","EKP1qui","BenTwMi","vM15Dg8","A0nRDuW","EwziAwm","BMv4DcGPigm","yw5ZzM9YBvq","mdaWmdaWmda","Cg9PBNrbBMq","qLvqB1i","uwXJyuu","Dw5KzwzPBMu","CuXvvw8","DhrJy24","z29PBMCGyxC","DMfSDwvZ","x2LZtwLUAvq","B3jLtMfTzxm","y2HUEuq","DMvYC2LVBMm","s3H4v2q","vhDwA3e","BeHLuKq","vgfN","wKHKBMC","De9tBfi","AhPhr2O","BvPkDvG","u21QteO","Cxzizve","vNbRwhq","zvzhrg8","A3LsD1G","ExLoDhK","DeDwA0e","ChrVCG","Cgf5Bg9Hzfq","igzPzwXKoIa","CYbPBNn0yw4","C3nHz2vfDMu","C2vUza","yxbWBhK","sMjzseW","Ehzsseu","B25SAw5L","u1H4zxm","Cw9Z","AvrYDxC","C0LYAK4","BwPczgi","yvDvq1u","CM92AwrLige","wLLWtNi","B2nRzxq","zxbqqwO","q3HMsuS","Aw5N","B2fK","zMv1vfy","x2DLDeLUDgu","x2n1CNnVCK4","DwLwBeq","vgTdwgq","AeHAwKG","BezSDxnO","ywnOzwqSihC","DKPmvKy","y2HLy2TdDxi","qxHtBMG","wezcBKy","wxHuD0u","t3r5qva","zM9SD04","A1n0yxr1C0m","uxnRrxe","B3jdqw4","CMvWBgfJzui","FdH8n3WXFde","Efvewwu","C29Tzq","DgHHBIbSB2m","y3jLyxrLt3a","BKHhsNq","sxDnuvG","zxHWB3j0CW","C2XPy2u","tuPmBMy","x2LZtwLUAvC","B0H1qum","ywXty29Wzq","CYbWyxjHBxm","zNjVBunOyxi","zxj2AwnL","vg1RBfm","BwfW","BML0AwfSAxO","icSG","r3riDfe","rvDUELO","BenRsMi","z1rPBwvVDxq","wMzrq0i","CKHUzxq","AwDHDg9Yt24","rMvUyLe","C2PAChG","v09Wrfy","D3j2D3O","B29dv1K","CMvHzhLtDge","wMDruKy","D05fzfq","vMfisNC","t0jtEuy","ExbL","wK5xEMW","Bwu6ia","z3Drtg0","ywnRDxbfBMq","x3bHDgHlzxK","ChPTz2S","Bwv0Ag9K","zMzmEhK","y3jLyxrLrxi","Dg9tDhjPBMC","x2LZv29YA2u","B3jpBMXPBMu","Dfv3Cfi","y3vYCMvUDeK","BIWGAg9ZDg4","uvP5s2m","y3vYC29YlNm","Aw9UvgLTzw8","lcbTyxGGCMu","CKHPqMW","zxjYB3i","Cgu6ia","q3vZDg9Tq2W","x29UrxjYB3i","vwvfBhy","AxmGDw5Kzwy","rLHQrwW","yxv0B21HDgK","CevHv1i","t3nqwNu","rgvPvw8","rhbfAxm","Cw9Zx18","wg5KvKS","wLbRu3K","ALrMr3O","EgPjuMi","Bg5VteC","tLPLvLK","vgrNru4","qwXiwwW","rgvKAwnHDgu","wfjps2y","u0TgCfe","y29SBM8","ChjVy2vZCW","ANLKEMy","Du9Zs3K","zxjFywnRx20","odeYmJCYAgncBgnq","DuHKBMK","x2rPC3bHDgm","sMLruge","AMfovgy","C2ziDe4","t3jUtNa","DwXnBee","x2LUAxrhBg8","Dgv4Dc9Qyxy","wNrfD1q","BwvZC2fNzq","Dxrjza","A0vxy20","CMTLCKDSB2i","tw5ozue","qvrOyKe","y29UBMvJDfm","wKX6D0u","EeDev0W","wK1tvhu","y1bQwfm","rgnpteu"];return ia=function(){return t},ia()}var B=H;(function(t,e){let r=H,i=t();for(;;)try{if(-parseInt(r(1144))/1*(parseInt(r(526))/2)+-parseInt(r(387))/3*(parseInt(r(1522))/4)+parseInt(r(1671))/5*(-parseInt(r(1008))/6)+-parseInt(r(1093))/7+parseInt(r(1635))/8+parseInt(r(1269))/9+parseInt(r(1049))/10*(parseInt(r(724))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(ia,751490);function H(t,e){t=t-226;let r=ia(),i=r[t];if(H.YlotUJ===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",m="";for(let S=0,_,v,I=0;v=f.charAt(I++);~v&&(_=S%4?_*64+v:v,S++%4)?g+=String.fromCharCode(255&_>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,_=g.length;S<_;S++)m+="%"+("00"+g.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(m)};H.KsncnC=o,H.fVVaAN={},H.YlotUJ=!0}let c=r[0],d=t+c,u=H.fVVaAN[d];return u?i=u:(i=H.KsncnC(i),H.fVVaAN[d]=i),i}var AS=Object[B(385)+B(530)],kS=Object[B(611)+B(1080)+B(1653)],Kx=(t,e)=>function(){return t&&(e=(0,t[{OmdnF:function(o,c){return o(c)}}.OmdnF(kS,t)[0]])(t=0)),e},TS=(t,e)=>{let r=B,i={sBSXp:function(c,d,u,f){return c(d,u,f)}};for(var o in e)i[r(934)](AS,t,o,{get:e[o],enumerable:!0})};function CS(){return Hx||(Hx=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function RS(){let t=B;return Gx||(Gx=[IDBCursor[t(995)+"e"][t(1710)],IDBCursor[t(995)+"e"][t(607)],IDBCursor[t(995)+"e"][t(607)+t(949)+"ey"]])}function PS(t){let e=B,r={ErbEw:function(o,c){return o<c},bKlqv:function(o,c){return o<<c},BWpoo:function(o,c){return o&c},bknxQ:function(o,c){return o>>>c},ldToH:function(o,c,d,u){return o(c,d,u)},VZJDm:e(678),GtHtQ:"error",MMVOa:function(o,c){return o(c)},EgGBj:function(o,c){return o!==c},cepts:e(1542),tDYrx:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={nHGJt:function(f,x){return r[H(686)](f,x)},YBQev:function(f,x){return r[H(1294)](f,x)},Vmyto:function(f,x){return r.BWpoo(f,x)},eVGDo:function(f,x){return f|x},dwXPN:function(f,x){return r.ErbEw(f,x)},xJXRE:function(f,x){return r.bknxQ(f,x)},aerzs:function(f,x){return f&x},qfEsl:function(f,x,g,m){return r[H(883)](f,x,g,m)},LOmfP:r[d(259)],ZjlJg:r[d(1455)],OZVIj:function(f,x){return f(x)},tUkLB:function(f,x){return r[d(1323)](f,x)},NeqiH:function(f){return f()},vxzEp:function(f,x){return r[d(1323)](f,x)}};if(r.EgGBj(d(1542),r[d(1741)])){let f={QuSaA:function(g,m){return u[d(1440)](g,m)},fonRi:function(g,m){return g>>>m},riiMd:function(g,m){return u[d(612)](g,m)},wLfsU:function(g,m){return u[d(1360)](g,m)},YrQMS:function(g,m){return u[d(1389)](g,m)},bjQaI:function(g,m){return u.dwXPN(g,m)},UICSS:function(g,m){return u[d(1217)](g,m)},bGVTJ:function(g,m){return g<<m},BcZoe:function(g,m){return u.aerzs(g,m)},CtbxG:function(g,m){return u[d(1389)](g,m)},LodOt:function(g,m){return g>m},NNQho:function(g,m,S,_){return u[d(963)](g,m,S,_)}},x=4294967295;return function(g,m,S=!0){let _=d;if(x=(127&g[m])>>>0,f.QuSaA(g[m++],128))return{value:S?x:0|x,offset:m};if(x=f[_(230)](x|f[_(446)](f[_(1034)](127,g[m]),7),0),f[_(849)](g[m++],128))return{value:S?x:f[_(1306)](0,x),offset:m};if(x=f.YrQMS(x,f.wLfsU(127,g[m])<<14)>>>0,f[_(359)](g[m++],128))return{value:S?x:0|x,offset:m};if(x=f[_(761)](x|f[_(811)](f.BcZoe(127,g[m]),21),0),f.QuSaA(g[m++],128))return{value:S?x:f[_(1306)](0,x),offset:m};if(x=(x|(15&g[m])<<28)>>>0,f[_(359)](g[m++],128))return{value:S?x:f[_(256)](0,x),offset:m};if(f[_(1312)](m+=5,g[_(1629)]))throw m=g[_(1629)],f[_(1808)](_0x25f90e,m,10,g.length);return{value:S?x:0|x,offset:m}}}else{let f=()=>{let m=d;t[m(1032)+m(997)+"ner"](u[m(987)],x),t[m(1032)+m(997)+m(783)](u[m(1163)],g)},x=()=>{let m=d;u[m(1252)](o,u[m(1178)](Ut,t[m(1234)])),u[m(979)](f)},g=()=>{u[d(229)](c,t.error),u.NeqiH(f)};t[d(777)+d(903)](d(678),x),t.addEventListener(r[d(1455)],g)}});return i[e(968)](o=>{let c=e;r[c(704)](o,IDBCursor)&&Jd[c(272)](o,t)})[e(523)](()=>{}),oa[e(272)](i,t),i}function DS(t){let e=B,r={BChOF:e(1470),dHZMC:e(689),dbiLt:"error",pNhNF:function(o){return o()},UWcoi:e(1721)+"or",qBqgB:e(1290)};if(sa[e(829)](t))return;let i=new Promise((o,c)=>{let d=e,u={kJTrv:function(m,S){return m(S)},aSrEI:r[d(845)]},f=()=>{let m=d;r[m(763)]===r[m(1641)]?_0xf6203d.createObjectStore(_0x3e6c9f,{keyPath:_0x528044}):(t["removeEv"+m(997)+"ner"](m(1290),x),t[m(1032)+m(997)+"ner"](r[m(1720)],g),t[m(1032)+m(997)+m(783)](m(314),g))},x=()=>{let m=d;r[m(1010)](o),r[m(1010)](f)},g=()=>{let m=d;u[m(1585)](c,t[m(1493)]||new DOMException(u[m(774)],u[m(774)])),f()};t[d(777)+d(903)](r.qBqgB,x),t["addEvent"+d(903)](r[d(1720)],g),t[d(777)+d(903)]("abort",g)});sa.set(t,i)}function OS(t){aa={hPHxf:function(i,o){return i(o)}}[B(374)](t,aa)}function LS(t){let e=B,r={dsegO:function(i,o){return i(o)},OuxUX:function(i,o){return i(o)},sTeiH:function(i,o){return i===o},bzEmb:function(i){return i()}};return r.sTeiH(t,IDBDatabase[e(995)+"e"]["transact"+e(1757)])&&!("objectSt"+e(1375)in IDBTransaction[e(995)+"e"])?function(i,...o){let c=e,d=t[c(1224)](r[c(476)](cs,this),i,...o);return Vd.set(d,i.sort?i[c(1018)]():[i]),Ut(d)}:r[e(856)](RS)[e(875)](t)?function(...i){let o=e;return t[o(1399)](r[o(1125)](cs,this),i),Ut(Jd[o(644)](this))}:function(...i){let o=e;return r[o(476)](Ut,t[o(1399)](r[o(476)](cs,this),i))}}function NS(t){let e=B,r={SpDed:e(1067),djVnv:function(i,o){return i(o)},FdMdl:function(i,o,c){return i(o,c)},ImYSu:function(i){return i()}};return typeof t===r[e(706)]?r[e(1790)](LS,t):(t instanceof IDBTransaction&&r[e(1790)](DS,t),r.FdMdl($x,t,r.ImYSu(CS))?new Proxy(t,aa):t)}function Ut(t){let e=B,r={kKpcS:function(o,c){return o(c)}};if(t instanceof IDBRequest)return PS(t);if(na[e(829)](t))return na[e(644)](t);let i=r.kKpcS(NS,t);return i!==t&&(na[e(272)](t,i),oa[e(272)](i,t)),i}var $x,Hx,Gx,Jd,sa,Vd,na,oa,aa,cs,jx=Kx({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={QlTbE:function(r,i){return r(i)},OPNMI:function(r,i){return r===i},TgSmQ:t(329),SmjLJ:function(r,i){return r===i},pFflf:function(r,i){return r===i},mdHIR:function(r,i){return r!==i},XMQRJ:t(923),GUWYh:function(r,i){return r(i)},jvRUw:function(r,i){return r instanceof i},vqXTE:function(r,i){return r===i},CfjHi:function(r,i){return r===i}};$x=(r,i)=>i[t(1437)](o=>r instanceof o),Jd=new WeakMap,sa=new WeakMap,Vd=new WeakMap,na=new WeakMap,oa=new WeakMap,aa={get(r,i,o){let c=t,d={BUPoR:function(u,f){return e.QlTbE(u,f)}};if(r instanceof IDBTransaction){if(e[c(482)](i,e.TgSmQ))return sa.get(r);if(e[c(1386)](i,"objectSt"+c(1375)))return r["objectSt"+c(1375)]||Vd.get(r);if(e[c(1150)](i,c(681)))return e[c(1127)](e[c(1748)],e.XMQRJ)?d[c(1367)](_0x3748f1,_0x39012f):o[c(1696)+c(1375)][1]?void 0:o[c(1696)+c(1189)](o[c(1696)+"oreNames"][0])}return e[c(917)](Ut,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(687)](r,IDBTransaction)&&(e[o(540)](i,e[o(1565)])||e[o(1302)](i,"store"))?!0:i in r}},cs=r=>oa.get(r)}}),Vx={};TS(Vx,{deleteDB:()=>BS,openDB:()=>MS,unwrap:()=>cs,wrap:()=>Ut});function MS(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=B,u={OtyAP:function(g,m){return g||m},eacaZ:function(g,m){return g===m},zZzLy:d(964),cddnx:d(672),YqLwr:function(g,m,S,_,v){return g(m,S,_,v)},tOSlR:function(g,m){return g(m)},rSpPB:d(624),MnZuj:d(1377)+d(1590),IxBDD:d(773)+d(1299),bCpoA:d(1200)},f=indexedDB[d(1287)](t,e),x=Ut(f);return i&&f[d(777)+d(903)](u[d(767)],g=>{let m=d,S={TWyio:function(_,v){return u[H(1429)](_,v)}};if(u[m(943)](u[m(663)],u.cddnx)){let _=this[m(1293)][m(694)+m(1569)](this._prefix),v=_0x43cdf5[m(524)](S[m(834)](_,"{}"));return v[_0x2846b4]=void 0,this[m(1293)][m(1804)+m(1569)](this[m(583)],_0x7dfc7e[m(920)+"y"](v))}else u.YqLwr(i,u[m(1383)](Ut,f[m(1234)]),g[m(651)+"on"],g.newVersion,Ut(f[m(876)+"ion"]))}),r&&f[d(777)+"Listener"](u[d(1711)],()=>r()),x[d(968)](g=>{let m=d;c&&g[m(777)+m(903)](u[m(1660)],()=>c()),o&&g["addEvent"+m(903)](u.MnZuj,()=>o())}).catch(()=>{}),x}function BS(t,{blocked:e}={}){let r=B,i={fKsXj:r(1200),JdKtj:function(c,d){return c(d)}},o=indexedDB[r(1784)+r(1568)](t);return e&&o[r(777)+r(903)](i[r(1680)],()=>e()),i[r(529)](Ut,o)[r(968)](()=>{})}function qx(t,e){let r=B,i={uOMwl:r(368)+"e",gehSC:r(1278),WAQnD:function(f,x){return f instanceof x},UECJL:function(f,x){return f in x},zWKtV:function(f,x){return f!==x},rfSKD:function(f,x){return f in x}};if(!(i[r(854)](t,IDBDatabase)&&!i[r(258)](e,t)&&typeof e===r(342)))return;if(ra[r(644)](e))return ra[r(644)](e);let o=e.replace(/FromIndex$/,""),c=i[r(270)](e,o),d=Zx.includes(o);if(!i[r(978)](o,(c?IDBIndex:IDBObjectStore)[r(995)+"e"])||!(d||Jx[r(875)](o)))return;let u=async function(f,...x){let g=r,m=this[g(876)+g(1757)](f,d?i[g(1079)]:i[g(1313)]),S=m[g(681)];return c&&(S=S[g(998)](x[g(1751)]())),(await Promise[g(285)]([S[o](...x),d&&m[g(329)]]))[0]};return ra[r(272)](e,u),u}var Jx,Zx,ra,FS=Kx({"node_modules/idb/build/index.js"(){let t=B,e={lUtHm:t(1005)+t(553),LwDIn:function(o){return o()},cAQpC:function(o,c){return o(c)},pftCU:t(644),Qgrxa:"getKey",Wpewf:"getAllKeys",MtTqo:"count",aMqDk:t(1343),BQfcj:t(1223),hAldb:t(844)},r=e[t(1025)][t(1244)]("|"),i=0;for(;;){switch(r[i++]){case"0":e[t(1096)](jx);continue;case"1":e[t(1096)](jx);continue;case"2":e[t(1712)](OS,o=>({...o,get:(c,d,u)=>qx(c,d)||o.get(c,d,u),has:(c,d)=>!!qx(c,d)||o.has(c,d)}));continue;case"3":Jx=[e[t(732)],e.Qgrxa,t(757),e.Wpewf,e[t(1800)]];continue;case"4":Zx=[e[t(1674)],"add",e[t(1042)],e[t(349)]];continue;case"5":ra=new Map;continue}break}}}),zS={idb:function(t){let e=B;t[e(1442)]=Promise[e(410)]()[e(968)](()=>(FS(),Vx)).then(function(r){return r})}},Wx={};function zt(t){let e=B,r={kEWcm:e(291)+"4",hVHem:function(u,f){return u!==f}},i=r[e(1535)][e(1244)]("|"),o=0;for(;;){switch(i[o++]){case"0":zS[t](d,d[e(1442)],zt);continue;case"1":if(r[e(418)](void 0,c))return c[e(1442)];continue;case"2":var c=Wx[t];continue;case"3":var d=Wx[t]={exports:{}};continue;case"4":return d[e(1442)]}break}}zt.d=(t,e)=>{let r=H;for(var i in e)zt.o(e,i)&&!zt.o(t,i)&&Object[r(385)+r(530)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=B;zt.o=(e,r)=>Object[t(995)+"e"][t(1698)+t(530)][t(1224)](e,r)})(),(()=>{let t=B,e={dwiSI:function(r,i){return r!==i},uCZpD:t(1520),hzGGj:function(r,i){return r!=i},OJalt:t(1341)};zt.r=r=>{let i=t;if(e[i(648)]("KNejT",e.uCZpD))e[i(1384)](i(1369)+"d",typeof Symbol)&&Symbol.toStringTag&&Object[i(385)+"operty"](r,Symbol[i(1482)+i(1381)],{value:e[i(714)]}),Object["definePr"+i(530)](r,"__esModule",{value:!0});else return _0x5c5ede}})();var Oe={};(()=>{let t=B,e={Veavd:t(1592),erQqo:t(1026),Ftwjj:function(a,n){return a(n)},IFjus:function(a,n){return a+n},wrvwz:function(a,n){return a*n},EeTzJ:function(a,n){return a*n},sauBi:function(a,n){return a+n},xWwAy:function(a,n,s){return a(n,s)},JfBQi:function(a,n){return a(n)},sZdKh:function(a,n){return a+n},Anyqa:function(a,n){return a(n)},cyDkW:"0000",ZLELF:"ffff",eWNnk:function(a,n){return a!==n},CygMg:t(691),sjZpx:t(908),eNFwP:function(a,n){return a(n)},TRReO:t(1365)+t(1365)+t(1365)+t(1365),wXbcK:function(a,n){return a>n},bvWiN:function(a,n){return a<n},FieEG:function(a,n){return a-n},jLYbA:function(a,n){return a-n},XfWis:function(a,n){return a<n},JZOkp:function(a,n){return a===n},FGJBn:function(a,n){return a!==n},udJHZ:function(a,n){return a!==n},AIjIA:function(a,n){return a!==n},bzRPF:function(a,n,s){return a(n,s)},gXqoR:t(316),cZTop:function(a,n){return a(n)},BFKDN:function(a,n){return a(n)},VoERR:function(a,n){return a>>>n},CVVtk:function(a,n){return a(n)},zMmHh:"Missing "+t(1558)+" field: key",dMrZY:function(a,n){return a===n},VXxJT:t(504)+t(1558)+t(1395)+t(585),xmCvA:function(a,n,s){return a(n,s)},bJxYY:function(a,n){return a(n)},oGpjp:function(a,n,s){return a(n,s)},cAusY:function(a,n){return a-n},ymXkR:function(a,n,s){return a(n,s)},FmvLn:function(a,n){return a!==n},JRDHq:function(a,n,s){return a(n,s)},YMXeb:function(a,n,s){return a(n,s)},bgbIO:function(a,n){return a!==n},Qfmyb:"uTjTk",xDJxf:function(a,n,s){return a(n,s)},EsviD:function(a,n){return a(n)},xYoXR:function(a,n){return a===n},eHeOs:"XcdvF",PlgEZ:function(a,n,s){return a(n,s)},qCjxk:t(1739),Tzmkd:t(277),QZyKc:function(a){return a()},QDWzh:function(a,n,s){return a(n,s)},iaiez:function(a,n,s){return a(n,s)},RDCrU:function(a,n,s){return a(n,s)},OvjiN:function(a,n,s){return a(n,s)},DqAQR:function(a,n,s){return a(n,s)},LkuAx:function(a,n){return a!==n},vZRqL:function(a,n,s){return a(n,s)},nmnGT:function(a,n,s){return a(n,s)},Pgvwc:function(a,n){return a!==n},TkCXd:function(a,n,s){return a(n,s)},VeGlM:function(a,n){return a!==n},fQHAu:t(789),weftU:function(a,n){return a>>>n},KxwzF:function(a,n){return a(n)},ujHnp:t(1007),ffEoL:t(712),cRCDW:function(a,n){return a(n)},USbOf:function(a,n,s){return a(n,s)},uBAiG:function(a,n,s){return a(n,s)},JQTlx:t(504)+t(1558)+t(1395)+t(1231),ZLzwE:function(a,n){return a===n},tKOCq:t(504)+t(1558)+t(1395)+t(341),qLRyJ:function(a,n){return a===n},NutUg:t(504)+t(1558)+t(1395)+t(1479),TeNJc:function(a,n){return a+n},TQJNI:function(a,n){return a(n)},jshlK:function(a,n,s){return a(n,s)},NMtEb:function(a,n){return a(n)},pnfsZ:function(a,n,s){return a(n,s)},mtRdH:function(a,n){return a+n},SUZOl:"Unimplemented ty"+t(1494),ooCWY:function(a,n){return a>=n},GAoTp:t(1609),LyBmA:t(1596)+t(1746),SwOIU:function(a,n){return a||n},vmpqj:function(a,n){return a!==n},wZMnN:function(a,n){return a!==n},YzJki:t(1216),TmklS:function(a,n){return a*n},epPAj:function(a,n){return a>n},zutRf:function(a,n){return a>n},ffLxy:t(1708)+t(1746),UoxTM:function(a,n,s){return a(n,s)},KyxGu:function(a,n){return a<n},OsPZu:function(a,n){return a&n},KSOav:function(a,n){return a>=n},FenbQ:function(a,n){return a+n},WrBSk:function(a,n){return a!==n},bCLTm:function(a,n){return a|n},LsUSj:function(a,n){return a<<n},xKhzg:function(a,n){return a&n},vsYIg:function(a,n){return a&n},rcfGx:function(a,n){return a(n)},yUvsX:function(a,n){return a&n},MnNeA:function(a,n){return a+n},wKgYn:function(a,n){return a+n},TZgRo:function(a,n){return a|n},YDRca:function(a,n){return a|n},OfrRf:function(a,n){return a&n},vwulP:function(a,n){return a&n},cQjlg:function(a,n){return a&n},fVXaT:function(a,n){return a<=n},YRGXZ:function(a,n){return a+n},jaNTf:function(a,n){return a+n},iIKOe:function(a,n){return a!==n},EFGjb:function(a,n){return a&n},KSXml:function(a,n){return a<<n},ZDxQn:function(a,n){return a|n},JUIaG:function(a,n){return a&n},rkonZ:function(a,n){return a<<n},BJaUn:function(a,n){return a&n},HjvtY:function(a,n){return a&n},BZIir:function(a,n){return a&n},KpXdG:function(a,n,s){return a(n,s)},sEWJh:function(a,n){return a>>n},pFceZ:function(a,n){return a+n},FxkZR:function(a,n){return a&n},ELSrv:function(a,n,s){return a(n,s)},wrwSk:t(624),FjVyW:function(a,n,s){return a(n,s)},wGfOg:function(a,n){return a<n},JGFYp:function(a,n){return a>=n},kvAFg:function(a,n){return a<n},kPFrG:function(a,n){return a+n},gRwvM:function(a,n){return a-n},DVcgW:function(a,n){return a+n},oSMXL:function(a,n){return a<n},LQfbZ:function(a,n){return a<n},HmoHx:function(a,n){return a===n},RmObT:t(1426),dqpPV:t(1146),MXPZx:function(a,n){return a<n},LEGVJ:function(a,n){return a>>n},DGicp:function(a,n){return a<n},huGOp:function(a,n){return a|n},WdmfM:function(a,n){return a|n},ZbWnT:function(a,n){return a&n},bjbLl:function(a,n){return a|n},XndVK:function(a,n){return a&n},eVptV:function(a,n){return a>>n},SSkMI:function(a,n){return a|n},YxTwE:function(a,n){return a&n},PLCOH:function(a,n,s){return a(n,s)},CBQNe:function(a,n){return a+n},tHGmU:t(1011),vMwnc:"QnhoF",lFFZV:function(a,n){return a<<n},XvMBp:function(a,n){return a-n},sVtzt:function(a,n){return a===n},sTmkr:"XMezd",uKtRv:function(a,n){return a>=n},Ltzjw:t(634),AqHFX:"qDkpQ",oGWQA:function(a,n){return a|n},IdlGS:function(a,n){return a&n},arGTv:t(678),TOECJ:"ping_onc"+t(1159)+"t",fjCBG:function(a,n){return a===n},dVLcz:t(375),Vbmmn:t(1638),URHCM:function(a,n){return a(n)},WoQoV:function(a,n){return a&n},ZJrRs:function(a,n){return a(n)},rcYek:function(a,n){return a&n},rHnet:function(a,n){return a&n},exQqZ:function(a,n){return a(n)},soHqL:function(a,n){return a&n},wIUSW:function(a,n){return a(n)},IQlGY:function(a,n){return a<<n},feSue:function(a,n){return a(n)},MtWrY:function(a,n){return a(n)},SicTQ:function(a,n){return a<<n},fyQUC:function(a,n){return a|n},uIbQT:function(a,n){return a>>>n},TyXSa:function(a,n){return a|n},fBplY:function(a,n){return a>>>n},HljJy:function(a,n){return a<<n},xBlRW:function(a,n){return a===n},fQlDV:function(a,n){return a===n},xSRAq:function(a,n){return a<n},Huods:function(a,n){return a<n},peooL:function(a,n,s){return a(n,s)},MkMzg:function(a,n){return a&n},aWUCU:function(a,n){return a>>>n},iSKjS:function(a,n){return a+n},ZAFTO:function(a,n){return a!==n},nKmtI:function(a,n){return a|n},dsBxG:function(a,n){return a&n},tGVkA:function(a,n){return a&n},SXxes:function(a,n){return a!==n},MJUGq:function(a,n){return a&n},adoYD:function(a,n){return a!==n},bGOqZ:function(a,n){return a>>>n},utyks:function(a,n){return a>>>n},XEzjI:function(a,n){return a+n},rfFpe:function(a,n){return a|n},QFLIT:function(a,n){return a|n},folwN:function(a,n){return a&n},ZhBkZ:function(a,n){return a>>>n},IwMQX:function(a,n){return a|n},jtmsY:function(a,n){return a+n},JBzPW:function(a,n){return a>>>n},pzmgk:function(a,n){return a|n},XDzib:function(a,n){return a&n},MvXaZ:function(a,n){return a!=n},LFGTX:function(a,n){return a instanceof n},aAkYZ:function(a,n){return a!=n},VIPji:t(342),USTBE:t(1737)+t(1578),Fvlpl:function(a,n){return a==n},TStub:t(1760)+t(1230)+"et=utf-8",QOxqj:function(a,n){return a|n},DbdNZ:function(a,n){return a===n},CCfSd:function(a,n){return a|n},OEatH:function(a,n){return a|n},mfpWI:function(a,n){return a|n},hdWwB:function(a,n){return a|n},qwdNL:function(a,n){return a<<n},hBMEW:function(a,n){return a<<n},ZHxPe:function(a,n){return a|n},kyRwX:function(a,n){return a<<n},SyoUM:function(a,n){return a<<n},Lkdil:function(a,n){return a|n},UhVcM:function(a,n){return a<<n},GUKgY:function(a,n){return a!==n},qFdoq:t(861),JYxOc:t(1062),lnoLG:function(a,n){return a<<n},eFZtB:function(a,n){return a>>>n},vZuco:function(a,n){return a|n},HUMSw:function(a,n){return a|n},bEzWX:function(a,n,s){return a(n,s)},wAYkX:function(a,n){return a>>>n},OMLYY:function(a,n){return a&n},sqMCk:t(1735),ohkuq:function(a,n){return a<=n},aIKMI:function(a,n){return a>=n},qJRVU:function(a,n){return a/n},DBbyH:function(a,n){return a>>>n},sVszp:function(a,n){return a>>>n},ZYpmD:function(a,n){return a+n},oUSkA:function(a,n){return a*n},xjIRb:function(a,n){return a>>>n},IQnVt:function(a,n){return a!==n},JAsWR:t(1659),HRwvy:function(a,n){return a&n},FEIUD:function(a,n){return a&n},NIYPB:function(a,n){return a>>>n},jTfGz:function(a,n){return a+n},AfBVq:function(a,n){return a>>>n},QjqRe:function(a,n){return a+n},UvtfA:function(a,n){return a<<n},EWnzZ:function(a,n){return a|n},agHPB:function(a,n){return a<<n},naKcJ:function(a,n){return a===n},MOknu:function(a,n){return a>>>n},usCqh:function(a,n){return a>>>n},VcbmV:function(a,n){return a===n},gluNK:function(a,n){return a===n},rcBIn:function(a,n){return a+n},aJGyn:function(a,n){return a+n},wYiTo:function(a,n){return a!=n},GmiKX:"Module",EhWVx:t(1095)+"le",xslfe:"SpQVJ",SKFpQ:function(a,n){return a>>>n},FHWfR:function(a,n){return a>>>n},nZCYk:function(a,n){return a>>>n},lBuKS:function(a,n){return a>>>n},PxGxp:function(a,n){return a>>>n},OXziz:function(a,n){return a&n},lbaOn:function(a,n){return a>>>n},SBeAr:function(a,n){return a&n},NRWTk:function(a,n){return a>>>n},qlzOm:function(a,n){return a>>>n},ibErN:function(a,n){return a&n},YenEJ:function(a,n){return a>>>n},bOhBY:function(a,n){return a===n},gNzUw:t(1197),HpBRi:t(1149)+t(1752),IjuIw:t(1547)+"NG_ERROR",nLYqo:t(1186)+"IES_ERROR",VpkXt:"MESSAGE_"+t(1567),fNcrp:"OPEN_ERROR",fSAoh:"2|0|5|1|"+t(1623),cXGOx:t(961)+"0",HsQLM:"error",EBiUz:t(801),Ppqiw:"wXdFt",DqJzO:function(a,n){return a===n},OwXHl:function(a,n){return a-n},vcPrE:function(a,n){return a===n},hTRPv:function(a,n){return a+n},PZuxx:"Unhandled error.",oqpqX:function(a,n){return a===n},JxDYz:"QLJqE",afPfk:function(a,n,s){return a(n,s)},CjODi:function(a,n,s){return a(n,s)},kicsY:t(1287),pAFVN:"iartn",gEbzY:function(a,n,s){return a(n,s)},AUouD:t(1533),RYvjr:function(a,n){return a===n},mkxgq:"egolN",MBKOh:function(a,n){return a||n},FuWSm:t(1369)+"d",IIdWs:function(a,n){return a<=n},hHZZH:t(1363)+t(884)+"ltiple t"+t(1336)+t(1518),guLXQ:function(a,n){return a===n},hnBKc:"QHKEK",jAaYr:t(641),xKGGf:function(a,n){return a<n},osuRB:function(a,n){return a<=n},YZdga:function(a,n){return a>=n},VoBRI:function(a,n){return a|n},PUETH:function(a,n){return a&n},AfwnY:function(a,n){return a>=n},Cljnv:function(a,n){return a<n},ESWmp:function(a,n){return a|n},HolXj:function(a,n){return a|n},Mpllc:function(a,n){return a<<n},laBLi:function(a,n){return a&n},HdWHn:function(a,n){return a>=n},WhFPs:function(a,n){return a|n},zwKzc:function(a,n){return a<<n},XRGSW:function(a,n){return a<<n},TljOd:function(a,n){return a&n},iSomt:function(a,n){return a+n},YhNqF:function(a,n){return a+n},NAXtY:function(a,n,s){return a(n,s)},vwvjL:function(a,n){return a+n},JDiGq:function(a,n){return a!==n},TwVkq:t(1626),PbvCq:function(a,n){return a|n},Klaaj:function(a,n){return a===n},jYxkE:function(a,n){return a&n},NWPuY:function(a,n){return a&n},QVaZg:function(a,n){return a+n},knfhl:t(1009),eNmbU:"4|2|1|5|"+t(1289),XvbTl:function(a,n){return a&n},xdzcq:function(a,n){return a>>n},pzsYl:function(a,n){return a|n},ctVml:function(a,n){return a+n},KJbAw:function(a,n){return a<<n},FmhOH:function(a,n){return a&n},QZZls:function(a,n){return a|n},VJpPn:function(a,n){return a>>n},TazWy:function(a,n){return a-n},zreQa:function(a,n,s,l){return a(n,s,l)},nRZZu:function(a,n){return a&n},COqpR:function(a,n){return a|n},WBijE:function(a,n){return a>=n},kQEYo:function(a,n){return a<<n},EdQUb:function(a,n){return a&n},OBCsb:function(a,n){return a<<n},CwuFg:function(a,n){return a&n},GnzBc:function(a,n){return a&n},PwZco:t(533),yelKe:function(a,n){return a!=n},oBHpK:function(a,n){return a instanceof n},yntpu:function(a,n){return a instanceof n},eizJB:function(a,n){return a!=n},qMpOq:function(a,n){return a!==n},TkJJf:t(434),jFWhu:function(a,n){return a==n},gJfRX:"ppe",iljMj:function(a,n){return a<n},zSIkB:function(a,n){return a<<n},AlHYl:function(a,n){return a(n)},KFioV:t(1608),OhzIP:function(a,n){return a+n},VcVxJ:"http",dDOVw:"&jscallback=frontierJSONP",lCmZb:t(304),Ubpif:"WrnPW",vvygS:function(a,n,s){return a(n,s)},xGDWL:"KpWaS",FhcZr:t(412),RFlnA:function(a){return a()},uEWjD:function(a,n){return a!==n},WSJac:t(491),BSJNd:t(1404),wGKmf:"message_id",qKGEa:t(752),bZYBn:t(1382),JWXQu:function(a,n){return a===n},PTWdT:t(1357),XGMpS:function(a,n){return a||n},zVhqJ:function(a,n){return a||n},FBLob:t(1385),VEEVP:function(a,n){return a|n},fDlQt:function(a,n){return a<<n},pJTni:function(a,n){return a>>>n},gaanB:function(a,n){return a|n},NbpkQ:function(a,n){return a|n},yUcYs:function(a,n){return a<<n},Eolhv:"Fakgr",wghCj:function(a,n){return a||n},NCuPW:function(a,n){return a!==n},igCtF:t(1019),qMnAV:function(a,n){return a||n},JWxdV:function(a,n){return a||n},diKAQ:"init QoS"+t(1044)+"d",FudVb:function(a,n,s){return a(n,s)},sxzxj:t(667),KxxWd:"kFMPX",tUwpR:function(a,n){return a(n)},inuOZ:function(a,n){return a===n},awFmi:t(495),cjuAS:t(262)+t(373),FMBrj:function(a,n,s,l){return a(n,s,l)},DLnOd:t(262)+t(1796)+"ck",knCAU:t(262)+"er_is_ack",XpkiQ:t(262)+t(1521)+t(885),FaJQh:function(a,n,s){return a(n,s)},kVtFa:function(a,n){return a(n)},gBdXh:t(547),Abgrw:t(1574),VltBa:function(a,n,s,l){return a(n,s,l)},DHVXO:function(a,n){return a&&n},WNHok:t(928),dLUkY:t(1353),sjFqs:t(307),pKBoj:function(a){return a()},xrQlo:function(a,n){return a instanceof n},qrfOG:function(a,n){return a===n},StUYl:t(1736),MYYzY:function(a,n){return a instanceof n},UgEyZ:function(a,n){return a instanceof n},ZpmUd:t(1737)+t(1578)+t(243)+t(1583),XMWsN:t(1156)+"e",toYdi:t(273),iRvtt:t(996),eLDiC:function(a,n){return a(n)},JSXem:t(1507),BzKXE:function(a,n){return a(n)},nbgaj:function(a,n){return a&n},IGOKv:function(a,n){return a+n},DQYaR:function(a,n){return a(n)},riQlL:function(a,n){return a(n)},UwAlG:t(1560)+t(564)+t(1160),lDXEs:t(1454),fFthv:function(a,n){return a||n},WOpDV:t(832),VGvpY:t(649)+"too large",aJfBp:function(a,n){return a>=n},RgqVi:function(a,n,s,l){return a(n,s,l)},afdNR:function(a,n){return a!==n},miCWF:"IuTis",rAWmA:t(1669),HRlSG:t(353)+"3",egyxZ:function(a,n){return a<n},aGHMT:function(a,n){return a+n},UInRV:function(a,n,s,l){return a(n,s,l)},ErPmI:function(a,n,s){return a(n,s)},aJXTL:function(a,n,s){return a(n,s)},woHqY:t(1332),qsfeX:function(a,n,s){return a(n,s)},yfHic:t(1372)+"ay, netw"+t(805)+t(1548),lBmSl:t(1277),ygzMK:function(a,n){return a|n},atvvg:function(a,n){return a|n},Myfpm:function(a,n){return a+n},kRFsc:function(a,n){return a<<n},HeJJR:function(a,n){return a+n},XROKf:function(a,n){return a+n},feHuN:function(a,n){return a<<n},PDYbn:function(a,n){return a+n},qtQpj:function(a,n){return a>>>n},UbPVe:function(a,n){return a&n},OBSyF:function(a,n){return a>>>n},PJceg:function(a,n){return a&n},WzGwv:function(a,n){return a+n},kMJEI:function(a,n){return a+n},VZWyD:function(a,n){return a&n},XFBnF:function(a,n){return a+n},YxfNj:function(a,n){return a&n},tPjPH:function(a,n){return a+n},ETgde:function(a,n){return a&n},qMzRQ:function(a,n){return a|n},JORMo:function(a,n){return a>>>n},NTJTB:function(a,n){return a<<n},ulMlA:function(a,n){return a&n},uWWoG:function(a,n){return a&n},XCStm:function(a,n){return a|n},eUhgv:t(941),SfoKz:function(a,n){return a!==n},qyiIv:t(1066),AMmyw:function(a,n){return a<n},VWjXo:function(a,n){return a+n},pEaWR:t(1489)+t(1450),SedaF:t(1261),IJHBz:function(a,n,s,l){return a(n,s,l)},CvyRd:function(a,n,s,l){return a(n,s,l)},CtaWO:function(a,n){return a(n)},opLBP:function(a,n){return a(n)},hBlza:"cursor_f"+t(1148),jtHWu:function(a,n){return a<n},vWOGp:function(a,n,s){return a(n,s)},yyLVl:function(a,n,s,l){return a(n,s,l)},GInHY:function(a,n){return a+n},gZeOR:function(a,n,s){return a(n,s)},PLazV:"cursor_n"+t(1271),SzQrt:t(461),sgAmH:t(1647)+t(1733),uwfdQ:t(904),gqMtd:function(a,n,s,l){return a(n,s,l)},euvUq:"CONTINUE",pbQEr:function(a,n,s,l){return a(n,s,l)},QuLEP:t(808),tMjrZ:function(a,n){return a(n)},kAtBY:function(a,n){return a(n)},rxSWV:function(a,n){return a===n},CWhYg:t(1380),npQfz:"GQDkj",MuVyy:"siqRR",UfxlA:t(478),LBZou:t(1573),LgzNj:function(a,n,s,l){return a(n,s,l)},twgVi:function(a,n){return a&&n},YZBZV:function(a){return a()},oHihi:function(a,n){return a===n},rHiBl:t(639),luxoO:t(311),JOtoR:function(a,n,s,l){return a(n,s,l)},uCjBh:t(262)+t(567),ihAMz:function(a,n,s,l){return a(n,s,l)},bitQR:"x-msg-qos",moUow:t(439)+t(775)+"ue",Ojpaa:function(a){return a()},TCuwm:function(a,n){return a+n},teYPH:function(a){return a()},rVsQW:function(a){return a()},EvirC:function(a){return a()},ojKlR:function(a,n){return a(n)},FmWEr:function(a){return a()},KCgju:function(a,n){return a!==n},xpLjy:function(a){return a()},orCAn:function(a){return a()},VfDOk:function(a){return a()},JUaXD:t(1538),AmtMi:function(a,n,s){return a(n,s)},rtzRe:function(a,n){return a!==n},tHaMT:function(a,n){return a(n)},EeGZf:function(a,n,s){return a(n,s)},RrmOk:function(a,n,s){return a(n,s)},WspuG:t(1067),iwmuW:function(a,n,s){return a(n,s)},uvGHw:function(a,n){return a===n},LMdgM:t(1015),hWtXh:function(a,n,s,l){return a(n,s,l)},qsWXx:t(1597),bEYBs:t(1532),WyWMu:function(a,n){return a!==n},WSqul:t(716),OrnNp:function(a,n){return a>>>n},tpnva:function(a,n){return a<n},iQlEz:function(a,n){return a|n},cQjvY:function(a,n){return a(n)},yZFgY:"arraybuf"+t(731),uHdni:function(a,n){return a/n},JSseF:"auto",arYKq:function(a,n){return a===n},SZxVL:function(a,n,s){return a(n,s)},RCnla:t(450)+t(824)+t(850)+"ct",fIYvT:t(1402),BNBnV:t(326),GGNke:"pagehide",Iapjt:t(1263),LfLUS:t(666),SGduP:t(226),aTPWa:t(1722),nGAst:t(1089),cthfh:t(1670),UASUx:t(388),vZWbr:function(a,n){return a||n},ANuIA:"please p"+t(269)+"ddID, de"+t(1123)+"r ttwID",LnGll:function(a,n,s){return a(n,s)},vUrmt:t(609)+"0",EYlAF:function(a,n){return a+n},FrqQn:function(a,n){return a+n},bYJPD:function(a,n){return a+n},CfmwA:function(a,n,s){return a(n,s)},DMqpV:function(a,n){return a===n},vYuzq:t(427),WStUZ:t(1119),cQWeN:"start",Peaow:function(a,n){return a-n},ADYkz:t(1228),xKAeG:function(a,n){return a(n)},aCioT:function(a,n){return a(n)},kLSKz:"curvalue",YstZl:"service-"+t(826),mXbnR:"service",HDTBx:function(a,n,s,l){return a(n,s,l)},UxmFg:"name",RIIIB:function(a,n,s,l){return a(n,s,l)},UeElv:t(734),PUHxu:function(a,n){return a-n},ojnkY:function(a,n){return a>n},qLUUo:t(688),NSeEp:t(405),WYviK:t(1270),ACwaq:function(a,n,s){return a(n,s)},flBks:function(a,n){return a!==n},qlULL:"vZWIu",foiFD:"timeout",wskHU:function(a,n){return a===n},gHelN:t(1196),UXdNz:"IhCgO",XTdkk:t(1372)+t(618)+t(271)+"ting ser"+t(1789),wNEdT:function(a,n,s){return a(n,s)},YhCav:t(1176)+" try rec"+t(1086)+"g",xswvC:function(a,n){return a(n)},GLogg:t(425),vNgxV:function(a,n){return a(n)},DcOLE:function(a){return a()},BMzRV:function(a,n){return a===n},SeWJT:"yNnxM",iTruw:function(a,n){return a+n},VsUYM:function(a,n){return a>n},KFbKt:function(a,n){return a!==n},arnRh:t(292),xiPBW:function(a,n,s){return a(n,s)},ThKGl:function(a,n,s){return a(n,s)},QWTZH:t(880),IiUaN:function(a,n){return a!==n},fkITs:"oTOOo",uYYDc:"ack",KeFRB:function(a,n,s){return a(n,s)},ekSWX:t(1229),ezClu:t(451)+t(389),GLCbv:t(1561),DURBM:function(a,n){return a+n},hRpIg:t(1262)+t(1396)+t(1276)+t(1453)+"ed",vEftA:t(1262)+"s already closed",LuLhn:function(a,n,s){return a(n,s)},YeJau:t(1368),RecMJ:t(929),TXucQ:function(a,n){return a==n},LShPX:"please p"+t(1409)+" valid d"+t(267)+t(1143)+t(403)+t(550)+t(750)+t(797),ipOmI:"number",JiQPa:function(a,n){return a!=n},QFadR:function(a,n){return a instanceof n},TWIDV:function(a,n){return a(n)},vJLVF:function(a,n){return a(n)},BDBsv:t(1220)+t(1409)+t(926)+t(1450),HxbJm:function(a,n){return a===n},SwVGS:t(1809),ZNWzl:function(a,n){return a|n},fJtDs:function(a,n){return a<<n},sIrjN:function(a,n){return a<<n},ZfQCB:"RulfP",vqlgx:t(869),arTBy:function(a,n){return a==n},jLCyc:t(399)+t(1700)+t(1414),lLIrI:function(a,n){return a===n},Fpvdu:t(1358),AAfMp:"ZJJVG",wQXQc:function(a,n){return a(n)},MJLnf:t(1580)+t(795)+"s",xbDcV:t(1236),XBond:function(a,n){return a*n},nFucJ:function(a,n){return a!=n},hONtJ:function(a,n){return a===n},KjsSL:t(1326),rUpeo:function(a,n){return a!=n},sfHtN:function(a,n){return a!=n},KMccQ:function(a,n){return a===n},kCkuL:t(1514)+t(1057)+t(1194)+"pe",Ihkch:function(a,n){return a===n},cBbSM:"Object",oHOXK:function(a,n){return a!=n},EaLyP:function(a,n){return a!=n},TdgEN:function(a,n){return a===n},eCONu:t(1020)+t(1536)+t(1447),gCyOq:function(a,n){return a===n},LJDoL:function(a,n){return a!=n},mjBdb:function(a,n){return a!=n},texHb:function(a,n,s){return a(n,s)}};zt.r(Oe),zt.d(Oe,{FWS:()=>Ng,CustomErrorEvent:()=>gl,createCloseEvent:()=>wt,ReconnectEvent:()=>pl,createErrorEvent:()=>lt,decodedFrame:()=>rn,createOpenEvent:()=>El,CustomCloseEvent:()=>ml,createReconnectEvent:()=>Sa,FrontierMessageEvent:()=>_l,encodeFrame:()=>Gt,createMessageEvent:()=>bl,OpenEvent:()=>yl,ErrorCode:()=>on,Event:()=>ar,MessageEvent:()=>wl});let r="";function i(a=""){let n=t;if(e[n(853)]!==e[n(453)]){let l=""+Date[n(1328)](),h=r||(r=e[n(1579)](f,a)),w=Math.random().toString(16)[n(1443)](-6);return e[n(1562)](e[n(1562)]("02",l),h)+w}else _0x528b3e[n(508)](_0x5981cd)}function o(){let a=t;return e[a(1465)](1e4,Date[a(1328)]())+Math[a(1563)](e[a(1663)](1e4,Math[a(416)]()))}function c(a){let n=t;return e.sauBi(Array(8)[n(283)]("0"),e[n(500)](parseInt,a,10)[n(1482)](2))[n(1443)](-8)}function d(a){let n=t;return e[n(1562)](e[n(1579)](Array,4)[n(283)]("0"),e.xWwAy(parseInt,a,2).toString(16))[n(1443)](-4)}function u(a){let n=t,s=a[n(1244)](/\./)[n(1452)](w=>c(w)),l=[];return l[0]=e[n(1591)](d,e[n(1701)](s[0],s[1])),l[1]=e[n(1667)](d,e[n(896)](s[2],s[3])),[e.cyDkW,e.cyDkW,e[n(1255)],e.cyDkW,e[n(1255)],e[n(379)],l[0],l[1]][n(283)]("")}function f(a){let n=t;if(e[n(1301)](e.CygMg,e[n(1463)])){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(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(1190)](a);return s?e.eNFwP(u,a):l?e[n(647)](x,a):e[n(556)]}else return this[n(787)+n(955)+n(625)+"t"]=1,this[n(1486)+n(1212)]++,this[n(1545)+"s"][this[n(1486)+"ndex"]]}function x(a){let n=t,s="",l=[],h=0,w=0,y=!0,E=e[n(1255)];if(e.wXbcK(a[n(1731)]("::"),-1)){let p=a[n(1244)]("::");for(let T=0;e[n(1632)](T,p.length);T++){let N=p[T];if(e[n(1179)](N[n(1731)](":"),0)){let G=N.split(":");y&&(h=G.length),w+=G[n(1629)];for(let K=0;e.bvWiN(K,G[n(1629)]);K++)if(G[K].length!==4){let fe=E.substring(0,e[n(839)](4,G[K].length)),Me=fe.concat(G[K]);l.push(Me)}else l[n(1174)](G[K]);y=!1}else{if(N[n(1629)]!==4){let G=E[n(711)+"g"](0,e.jLYbA(4,N[n(1629)])),K=G[n(440)](N);l.push(K)}else l.push(N);y&&(h+=1),w+=1,y=!1}}let R="";for(let T=0;e[n(232)](T,8-w);T++)R=R[n(440)](E);for(let T=0;e.bvWiN(T,l[n(1629)]);T++)e.JZOkp(T,h)?(s=s[n(440)](R),s=s[n(440)](l[T])):s=s.concat(l[T]);return s}{let p=a.split(":");for(let R=0;R<p.length;R++){let T=p[R];if(e[n(1566)](4,p[R][n(1629)])){let N=E.substring(0,4-p[R][n(1629)]),G=N[n(440)](T);s=s[n(440)](G)}else s=s[n(440)](T)}return s}}function g(a,n){let s=t,l=a[s(254)];e[s(502)](void 0,l)&&(e[s(500)](me,n,10),U(n,l));let h=a[s(585)];e.AIjIA(void 0,h)&&(e[s(1636)](me,n,18),U(n,h))}function m(a){let n=t;if(e.JZOkp(e[n(436)],n(316))){let s={};e:for(;!e.cZTop(V,a);){let l=e[n(1704)](he,a);switch(e[n(982)](l,3)){case 0:break e;case 1:s[n(254)]=D(a,e[n(1577)](he,a));break;case 2:s[n(585)]=D(a,e[n(1591)](he,a));break;default:e[n(1636)](C,a,7&l)}}if(e[n(1630)](void 0,s[n(254)]))throw new Error(e.zMmHh);if(e[n(303)](void 0,s[n(585)]))throw new Error(e[n(1075)]);return s}else return _0x56eafd?.[n(338)](s=>s.key===_0x1c99ed)?.value}function S(a){let n=t,s=P();return e[n(431)](_,a,s),e[n(1094)](M,s)}function _(a,n){let s=t,l={Coxbq:function(ee,oe){return e.XfWis(ee,oe)},LqyqN:function(ee,oe,Ye){return e.oGpjp(ee,oe,Ye)},VdPEX:function(ee,oe,Ye){return e[H(431)](ee,oe,Ye)},fgDOL:function(ee,oe,Ye){return e[H(1636)](ee,oe,Ye)},GgjOZ:function(ee,oe){return e[H(1701)](ee,oe)},BuBHQ:function(ee,oe){return e[H(952)](ee,oe)}},h=a.SeqID;e[s(1566)](void 0,h)&&(e[s(841)](me,n,8),mt(n,h));let w=a.LogID;e[s(355)](void 0,w)&&(e[s(910)](me,n,16),e[s(1618)](mt,n,w));let y=a[s(341)];if(e.bgbIO(void 0,y))if(e[s(303)]("uTjTk",e[s(266)]))e.xDJxf(me,n,24),e.xmCvA(mt,n,e.EsviD(O,y));else{let ee=0,oe=[];for(;l[s(1090)](ee,_0x4d7055[s(499)+"th"]);){let{offset:Ye}=l[s(577)](_0x220c4b,_0x5be621,ee);ee=Ye;let cn={cursor_name:"",cursor:0,service:0},{value:Da,offset:si}=l[s(701)](_0x5b951e,_0x5c5816,ee);cn.service=Da,ee=si;let{value:gs,offset:oi}=l[s(301)](_0xb8d46f,_0x163555,ee);ee=oi,cn[s(632)+s(1271)]=_0x35e570(_0x5122ad,ee,l[s(855)](ee,gs)),ee+=gs;let{value:ai,offset:Mg}=_0x379e23(_0x6ce8fa,ee);cn[s(505)]=ai[s(1645)](),ee=Mg,oe.push(cn)}return oe}let E=a[s(1479)];if(E!==void 0)if(e[s(457)](e[s(1627)],e[s(1627)]))e[s(1687)](me,n,32),e[s(881)](mt,n,e[s(1579)](O,E));else return this.endpoints[this["currentI"+s(1212)]];let p=a.headers;if(e[s(1301)](void 0,p))for(let ee of p)if(e[s(442)](e[s(1082)],e[s(593)])){e.xmCvA(me,n,42);let oe=e[s(1488)](P);g(ee,oe),e[s(1692)](me,n,oe.limit),W(n,oe),L(oe)}else{let oe=_0x3ce0ef[s(711)+"g"](0,PehJNN.BuBHQ(4,_0x976bfa[_0x42e1fa].length)),Ye=oe[s(440)](_0x55ec58[_0x11d74c]);_0x2435bc[s(1174)](Ye)}let R=a[s(1551)+s(1211)];e[s(1128)](void 0,R)&&(e.JRDHq(me,n,50),e.iaiez(U,n,R));let T=a["payloadT"+s(1472)];T!==void 0&&(e[s(500)](me,n,58),e[s(770)](U,n,T));let N=a[s(1112)];N!==void 0&&(e[s(1692)](me,n,66),e[s(473)](me,n,N[s(1629)]),e.DqAQR(ae,n,N));let G=a.LogIDNew;e[s(939)](void 0,G)&&(e[s(790)](me,n,74),e[s(1621)](U,n,G));let K=a.serverTiming;e[s(938)](void 0,K)&&(e[s(1420)](me,n,82),e.JRDHq(U,n,K));let fe=a.msgID;e[s(442)](void 0,fe)&&(me(n,90),e.RDCrU(U,n,fe));let Me=a.frameType;e[s(502)](void 0,Me)&&(e.oGpjp(me,n,96),mt(n,e.eNFwP(O,Me)))}function v(a){return I(F(a))}function I(a){let n=t,s={gPcXa:function(l){return e[H(1488)](l)}};if(e.VeGlM(e[n(380)],n(1132))){let l={};e:for(;!V(a);){let h=he(a);switch(e.weftU(h,3)){case 0:break e;case 1:l[n(1231)]=e.bzRPF(At,a,!0);break;case 2:l[n(1552)]=e[n(500)](At,a,!0);break;case 3:l.service=e[n(866)](he,a);break;case 4:l[n(1479)]=e[n(1768)](he,a);break;case 5:if(e[n(303)](e[n(927)],e[n(1099)])){let w=this["_endpoin"+n(664)]?.[n(580)+"ntEndpoint"]();this._debug(n(960)+w),s[n(274)](_0x1a77a9)}else{let w=e[n(401)](A,a);(l[n(788)]||(l.headers=[]))[n(1174)](e[n(1667)](m,a)),a.limit=w;break}case 6:l["payloadE"+n(1211)]=e[n(1692)](D,a,e[n(1591)](he,a));break;case 7:l[n(1394)+n(1472)]=e.USbOf(D,a,e.bJxYY(he,a));break;case 8:l[n(1112)]=e.OvjiN(se,a,e[n(866)](he,a));break;case 9:l[n(345)]=D(a,e.bJxYY(he,a));break;case 10:l["serverTi"+n(1666)]=D(a,e.CVVtk(he,a));break;case 11:l[n(1121)]=D(a,e[n(1579)](he,a));break;case 12:l[n(1036)+"e"]=e[n(1579)](he,a);break;default:e[n(1781)](C,a,7&h)}}if(e[n(457)](void 0,l.SeqID))throw new Error(e[n(659)]);if(e[n(1630)](void 0,l[n(1552)]))throw new Error("Missing "+n(1558)+n(1395)+n(1552));if(e[n(1540)](void 0,l[n(341)]))throw new Error(e[n(948)]);if(e[n(1586)](void 0,l[n(1479)]))throw new Error(e[n(289)]);return l}else return this[n(860)][n(1467)+"te"]}function A(a){let n=t,s=he(a),l=a[n(791)];return a[n(791)]=e[n(1600)](a[n(710)],s),l}function C(a,n){let s=t;switch(n){case 0:for(;128&e[s(423)](te,a););break;case 2:e[s(1031)](J,a,e[s(242)](he,a));break;case 5:e[s(1288)](J,a,4);break;case 1:e[s(500)](J,a,8);break;default:throw new Error(e[s(1145)](e[s(1157)],n))}}function O(a){let n=t;return a|=0,{low:a,high:a>>31,unsigned:e[n(1466)](a,0)}}let b=[];function P(){let a=t,n=b[a(1557)]();return n?(n[a(710)]=n[a(791)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function L(a){b[t(1174)](a)}function F(a){let n=t;if(n(652)===n(575))this[n(1017)+n(1461)+n(1139)]=_0x166aa8,_0x1ecbb7?this[n(1206)+n(741)]():this[n(1206)+"ffLine"]();else return{bytes:a,offset:0,limit:a.length}}function M(a){let n=t,s=a.bytes,l=a[n(791)];return s[n(1629)]===l?s:s.subarray(0,l)}function J(a,n){let s=t;if(s(1609)===e[s(958)]){if(e[s(1179)](e[s(1562)](a.offset,n),a.limit))throw new Error(e.LyBmA);a.offset+=n}else _0x240956.log(_0x48a18a)}function V(a){let n=t,s={vbQHQ:function(l,h){return e[H(970)](l,h)},GXUgh:n(342),AYOth:function(l,h){return e.vmpqj(l,h)},UYNrG:n(399)+n(1700)+n(1414)};if(e[n(905)](e[n(501)],e.YzJki)){let{url:l}=s[n(1038)](_0x4b2ce6,{}),h=_0x26308c[n(635)](l)?l:s.GXUgh==typeof l?[l]:[];_0x2c2e13&&_0xbd6c50[n(680)](this[n(889)],_0x32db67),h&&h.length?this["_endpoin"+n(664)]=new _0x4d9cb0(h,this._options[n(900)+"es"]):this[n(448)+n(664)]?.[n(1603)+n(796)+n(803)](),this["_pingLos"+n(250)]?.[n(1615)+n(1084)](this[n(889)][n(1101)+n(1354)]),this[n(432)+n(872)]=!1,this[n(1601)]&&s[n(347)](this[n(1601)][n(1467)+"te"],this.CLOSED)?this[n(1168)+n(984)](1e3,s[n(559)],!0):(this._isInit=!0,this._connect())}else return e.ooCWY(a[n(710)],a[n(791)])}function re(a,n){let s=t,l=a[s(372)],h=a.offset,w=a[s(791)],y=e.sauBi(h,n);if(e.wXbcK(y,l[s(1629)])){let E=new Uint8Array(e[s(1451)](2,y));E[s(272)](l),a[s(372)]=E}return a[s(710)]=y,e.epPAj(y,w)&&(a[s(791)]=y),h}function X(a,n){let s=t,l=a[s(710)];if(e[s(1707)](e.TeNJc(l,n),a[s(791)]))throw new Error(e[s(1480)]);return a[s(710)]+=n,l}function se(a,n){let s=t,l=e.DqAQR(X,a,n);return a[s(372)].subarray(l,e[s(1562)](l,n))}function ae(a,n){let s=t,l=e.nmnGT(re,a,n[s(1629)]);a[s(372)][s(272)](n,l)}function D(a,n){let s=t,l=e[s(1728)](X,a,n),h=String[s(1449)+s(1247)],w=a[s(372)],y="\uFFFD",E="";for(let p=0;e[s(1595)](p,n);p++){let R=w[e.TeNJc(p,l)],T,N,G,K;e[s(1586)](128&R,0)?E+=h(R):e.qLRyJ(e[s(1502)](224,R),192)?e.KSOav(p+1,n)?E+=y:(T=w[e[s(1462)](e[s(1145)](p,l),1)],e[s(594)](e[s(1502)](192,T),128)?E+=y:(K=e[s(877)](e[s(235)](e[s(1742)](31,R),6),e[s(631)](63,T)),e[s(1632)](K,128)?E+=y:(E+=e[s(430)](h,K),p++))):e[s(956)](240,R)==224?e[s(1537)](p,2)>=n?E+=y:(T=w[e[s(1600)](p,l)+1],N=w[e[s(1537)](e[s(620)](p,l),2)],e[s(355)](e[s(973)](T,e[s(235)](N,8))&49344,32896)?E+=y:(K=e[s(1684)](e[s(235)](e.OfrRf(15,R),12)|e[s(235)](e[s(1282)](63,T),6),e[s(675)](63,N)),e[s(1595)](K,2048)||e[s(496)](K,55296)&&e[s(244)](K,57343)?E+=y:(E+=e[s(401)](h,K),p+=2))):(248&R)==240?e[s(496)](p+3,n)?E+=y:(T=w[e[s(1562)](e[s(549)](p,l),1)],N=w[e[s(1526)](e[s(1701)](p,l),2)],G=w[e[s(1562)](p,l)+3],e[s(1744)](e[s(1554)](e[s(1684)](e[s(877)](T,e[s(429)](N,8)),e.LsUSj(G,16)),12632256),8421504)?E+=y:(K=e[s(973)](e[s(753)](e[s(753)](e.KSXml(e[s(1309)](7,R),18),e[s(528)](e[s(1750)](63,T),12)),e[s(235)](e[s(1024)](63,N),6)),e[s(1691)](63,G)),K<65536||e[s(1412)](K,1114111)?E+=y:(K-=65536,E+=e[s(737)](h,e[s(620)](e.sEWJh(K,10),55296),e[s(1320)](e[s(629)](1023,K),56320)),p+=3))):E+=y}return E}function U(a,n){let s=t,l=n[s(1629)],h=0;for(let E=0;e.wGfOg(E,l);E++){let p=n[s(1182)+"At"](E);e[s(486)](p,55296)&&e.fVXaT(p,56319)&&e[s(351)](e[s(513)](E,1),l)&&(p=e[s(1040)](e[s(1033)](p<<10,n.charCodeAt(++E)),56613888)),h+=e[s(351)](p,128)?1:e[s(784)](p,2048)?2:p<65536?3:4}e[s(500)](me,a,h);let w=re(a,h),y=a[s(372)];for(let E=0;e[s(1322)](E,l);E++){let p=n[s(1182)+"At"](E);if(p>=55296&&e[s(244)](p,56319)&&e[s(1537)](E,1)<l&&(p=e.FieEG((p<<10)+n[s(1182)+"At"](++E),56613888)),e.kvAFg(p,128))y[w++]=p;else if(e.HmoHx(e.RmObT,e[s(1348)])){if(this[s(448)+"tManager"]?.[s(912)+s(245)+"es"]()){let T=this[s(448)+"tManager"]?.["getCurre"+s(1137)+"nt"]();this[s(1524)+s(1014)+"ent"](e[s(445)](_0x712199,e[s(596)],{code:1006,reason:s(957)+T+(s(656)+s(1491)+s(760)+s(878)),wasClean:!0}))}else{let T=this[s(889)][s(271)+s(463)+"ptor"](_0x52f5c1,_0x538a5f);this[s(1524)+"hCloseEvent"](e[s(936)](_0x3fcebe,e.wrwSk,{code:_0x10c457,reason:_0x5a3c98,wasClean:!0,willReconnect:T})),T&&this[s(1147)]()}return}else e[s(696)](p,2048)?y[w++]=e[s(631)](e[s(1611)](p,6),31)|192:(e[s(817)](p,65536)?y[w++]=e[s(877)](e.BZIir(e[s(836)](p,12),15),224):(y[w++]=e[s(489)](e[s(1282)](e[s(836)](p,18),7),240),y[w++]=e.WdmfM(e[s(306)](e[s(1611)](p,12),63),128)),y[w++]=e.bjbLl(e[s(1506)](e.eVptV(p,6),63),128)),y[w++]=e[s(340)](e[s(1428)](63,p),128)}}function W(a,n){let s=t,l=e[s(812)](re,a,n.limit),h=a[s(372)],w=n[s(372)];for(let y=0,E=n[s(791)];e[s(351)](y,E);y++)h[y+l]=w[y]}function te(a){return a[t(372)][X(a,1)]}function Ze(a,n){let s=t,l={DEVCh:function(h,w){return e[H(1619)](h,w)},jSjYU:function(h,w){return h*w},QOpqm:function(h,w){return e[H(1663)](h,w)}};if(e[s(290)]===e.vMwnc)return qQLJEN[s(1613)](qQLJEN[s(705)](1e4,_0x3bcfec[s(1328)]()),_0x26fa06[s(1563)](qQLJEN[s(1333)](1e4,_0x5e0e74.random())));{let h=re(a,1);a[s(372)][h]=n}}function he(a){let n=t,s=0,l=0,h;do h=e[n(423)](te,a),e[n(1322)](s,32)&&(l|=e[n(818)](e[n(1554)](127,h),s)),s+=7;while(128&h);return l}function me(a,n){let s=t,l={eNaTZ:function(h,w){return h!==w},AeZIZ:function(h,w){return e[H(465)](h,w)}};if(e.sVtzt(e[s(1291)],e[s(1291)])){for(n>>>=0;e[s(816)](n,128);)if(e[s(905)](e[s(1296)],e.AqHFX))e[s(500)](Ze,a,e.oGWQA(e[s(281)](127,n),128)),n>>>=7;else{let h=_0x567584[_0x3679c4];if(LXdWmT[s(535)](4,_0x55975e[_0xc2a5d6][s(1629)])){let w=_0xd9da2[s(711)+"g"](0,LXdWmT[s(749)](4,_0xecfc00[_0x593d4a][s(1629)])),y=w.concat(h);_0x4c3df1=_0x460747[s(440)](y)}else _0xec9691=_0x12c136[s(440)](h)}Ze(a,n)}else return _0x41ce9e?_0x4810f3[s(402)+s(253)](_0x24dd0f,_0x4c7305):_0x24760e[s(402)+s(1776)](_0x107f34,_0x331267)}function At(a,n){let s=t;if(e[s(330)](e[s(241)],e[s(670)]))_0x129889(e[s(1108)]),this[s(742)](s(1580)+"e_success",_0xbcc3eb),this[s(742)](e.TOECJ,_0x2262f3);else{let l=0,h=0,w=0,y;return y=e[s(251)](te,a),l=e[s(337)](127,y),128&y&&(y=e[s(1227)](te,a),l|=e[s(1073)](127,y)<<7,e[s(956)](128,y)&&(y=e.EsviD(te,a),l|=e[s(818)](127&y,14),128&y&&(y=te(a),l|=e[s(1309)](127,y)<<21,e[s(1460)](128,y)&&(y=e[s(1069)](te,a),h=e[s(1345)](127,y),e[s(1024)](128,y)&&(y=e[s(821)](te,a),h|=e[s(879)](127&y,7),128&y&&(y=e.URHCM(te,a),h|=e[s(235)](e[s(1073)](127,y),14),e[s(675)](128,y)&&(y=e[s(430)](te,a),h|=e[s(235)](e[s(1688)](127,y),21),128&y&&(y=e[s(1097)](te,a),w=e[s(1345)](127,y),e[s(281)](128,y)&&(y=e.MtWrY(te,a),w|=e.KSXml(e.yUvsX(127,y),7)))))))))),{low:l|e[s(1142)](h,28),high:e[s(1039)](e.uIbQT(h,4),w<<24),unsigned:n}}}function mt(a,n){let s=t,l=e.uIbQT(n[s(597)],0),h=e[s(565)](e[s(1605)](n[s(597)],28),e[s(1594)](n[s(589)],4))>>>0,w=e[s(982)](n[s(589)],24),y=e.xBlRW(0,w)?e.fQlDV(0,h)?e[s(1595)](l,16384)?l<128?1:2:e[s(1595)](l,2097152)?3:4:e.bvWiN(h,16384)?e.xSRAq(h,128)?5:6:e[s(1679)](h,2097152)?7:8:w<128?9:10,E=e[s(1165)](re,a,y),p=a.bytes;switch(y){case 10:p[E+9]=e[s(472)](e[s(1408)](w,7),1);case 9:p[e[s(1662)](E,8)]=e.ZAFTO(9,y)?e.nKmtI(128,w):e.dsBxG(127,w);case 8:p[e[s(896)](E,7)]=e[s(939)](8,y)?h>>>21|128:e[s(1392)](h>>>21,127);case 7:p[E+6]=e[s(1403)](7,y)?e[s(906)](h>>>14,128):e[s(999)](h>>>14,127);case 6:p[E+5]=e[s(942)](6,y)?e[s(346)](e[s(332)](h,7),128):e[s(1076)](h,7)&127;case 5:p[e[s(538)](E,4)]=y!==5?e[s(531)](128,h):e[s(1024)](127,h);case 4:p[E+3]=y!==4?e.QFLIT(e[s(1136)](l,21),128):e[s(1430)](e[s(1719)](l,21),127);case 3:p[e[s(1537)](E,2)]=e[s(992)](3,y)?e[s(1441)](e[s(1041)](l,14),128):l>>>14&127;case 2:p[e[s(683)](E,1)]=e.VeGlM(2,y)?e[s(1181)](l,7)|128:e[s(1750)](e.uIbQT(l,7),127);case 1:p[E]=e[s(442)](1,y)?e[s(1478)](128,l):e[s(898)](127,l)}}function rn(a){return v(a)}function Gt(a){return e[t(1667)](S,a)}let sn=65536,ni=e[t(517)],be=e[t(1209)](sn,sn),Te=e[t(1006)](be,be),or=Te/2,Ne=String[t(995)+"e"].charCodeAt;class xe{constructor(n,s,l){let h=t;if(h(1726)!=="xbxTP")this[h(1614)]=!0,this.low=e[h(358)](0,n),this.high=e[h(565)](0,s),this[h(892)]=!!l;else try{return e[h(455)](h(342),typeof _0x13e559)&&(_0x4138c0 instanceof _0x36175d||_0x4c7c52[h(327)]&&e[h(376)](_0x508f9c[h(327)],_0x2a4a78))||e.aAkYZ(e.VIPji,typeof _0x1bdc34)?"":(_0x248e12[h(524)](_0x8584e7),e.USTBE)}catch{return e.Fvlpl("string",typeof _0x1c87ee)?e[h(764)]:""}}static isLong(n){let s=t;return n&&e[s(1240)](!0,n[s(1614)])}static fromBits(n,s,l){return new xe(n,s,l)}static fromBytes(n,s,l){let h=t;return l?xe[h(402)+"sLE"](n,s):xe[h(402)+h(1776)](n,s)}static[t(402)+t(253)](n,s){let l=t;return new xe(e.CCfSd(e.rfFpe(e.IwMQX(n[0],e.rkonZ(n[1],8)),n[2]<<16),e.IQlGY(n[3],24)),e[l(1766)](e[l(759)](e[l(568)](n[4],e[l(814)](n[5],8)),e[l(302)](n[6],16)),e[l(235)](n[7],24)),s)}static[t(402)+t(1776)](n,s){let l=t;return new xe(e[l(613)](e[l(906)](e.YDRca(e[l(1390)](n[4],24),e[l(1297)](n[5],16)),e.hBMEW(n[6],8)),n[7]),e[l(346)](e[l(863)](n[0]<<24|e[l(1319)](n[1],16),e.SicTQ(n[2],8)),n[3]),s)}static[t(989)](n){let s=t;return e[s(726)](e[s(558)],e[s(975)])?e[s(303)](n,ni)?xl:new xe(e.VoERR(e[s(340)](Ne.call(n,0),Ne[s(1224)](n,1)<<8)|e[s(1510)](Ne[s(1224)](n,2),16)|Ne.call(n,3)<<24,0),e[s(420)](e[s(835)](e[s(1023)](Ne.call(n,4),e[s(1319)](Ne.call(n,5),8))|Ne.call(n,6)<<16,e.IQlGY(Ne[s(1224)](n,7),24)),0),!0):this[s(1374)+"T"]||this[s(1445)+"X"]?this["_miniNav"+s(1461)+"line"]:(this[s(444)+"er"]||this[s(1483)+"r"])&&this[s(889)][s(1588)+"tworkCha"+s(733)]?_0x49c93b[s(574)]:!0}[t(1785)](){let n=t,s={PDhKt:function(l,h,w){return e[H(1693)](l,h,w)},KwPFv:function(l,h){return e[H(1322)](l,h)},BVkhS:function(l,h){return l+h}};if(e[n(1770)](n(1002),"NrKVx"))return String[n(1449)+n(1247)](e[n(956)](255,this.low),e[n(1345)](this.low>>>8,255),e[n(1073)](e[n(1021)](this.low,16),255),e[n(420)](this[n(597)],24),e[n(898)](255,this[n(589)]),e.MkMzg(e[n(1719)](this[n(589)],8),255),e[n(722)](this[n(589)]>>>16,255),e[n(982)](this.high,24));{let l=ELrqFa[n(698)](_0x5aeefe,_0x311ddb,_0x5b2a07[n(791)]),h=_0x540814[n(372)],w=_0x2fdae5[n(372)];for(let y=0,E=_0x3a774c.limit;ELrqFa[n(831)](y,E);y++)h[ELrqFa[n(1122)](y,l)]=w[y]}}static[t(435)+"er"](n,s=!0){let l=t;if(isNaN(n))return s?$p:xl;if(s){if(l(1735)!==e[l(1339)])this[l(1154)+"ired"]();else if(n>=Te)return Jp}else{if(e[l(447)](n,-or))return Zp;if(e.aIKMI(e.IFjus(n,1),or))return Vp}return xe[l(825)](n%be|0,e[l(613)](e[l(751)](n,be),0),s)}[t(1645)](){let n=t;return this[n(892)]?e.wrvwz(e[n(404)](this.high,0),be)+e[n(1761)](this[n(597)],0):e.ZYpmD(e[n(1209)](this[n(589)],be),e[n(1509)](this.low,0))}[t(1050)](){let n=t;if(e[n(1690)](e.JAsWR,e.JAsWR)){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1190)](_0x110aa0),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]))/.test(_0x17786e);return s?_0x50e02c(_0x1b0b14):l?_0x233326(_0x42b3fd):e[n(556)]}else return e[n(991)](0,this[n(589)])&&e[n(1240)](0,this.low)}[t(738)](n){let s=t;xe[s(1614)](n)||(n=xe[s(435)+"er"](n));let l=e[s(1136)](this[s(589)],16),h=65535&this.high,w=e[s(1605)](this.low,16),y=e[s(1300)](65535,this.low),E=e[s(1605)](n[s(589)],16),p=e.FEIUD(65535,n[s(589)]),R=e[s(828)](n[s(597)],16),T=e[s(337)](65535,n[s(597)]),N=0,G=0,K=0,fe=0;return fe+=e.DVcgW(y,T),K+=e[s(332)](fe,16),fe&=65535,K+=e[s(620)](w,R),G+=e[s(1719)](K,16),K&=65535,G+=e[s(1508)](h,p),N+=e[s(815)](G,16),G&=65535,N+=e.QjqRe(l,E),N&=65535,xe[s(825)](e[s(358)](e.UvtfA(K,16),fe),e[s(1456)](e.agHPB(N,16),G),this.unsigned)}[t(1279)](n){let s=t;return xe[s(1614)](n)||(n=xe[s(435)+"er"](n)),e[s(1301)](this[s(892)],n[s(892)])&&e[s(361)](e.MOknu(this[s(589)],31),1)&&e[s(1624)](e.usCqh(n[s(589)],31),1)?!1:e[s(552)](this[s(589)],n.high)&&e[s(1240)](this[s(597)],n[s(597)])}addOne(){let n=t;return e[n(1110)](-1,this[n(597)])&&e[n(1770)](-1,this.high)?xe[n(825)](0,0,this[n(892)]):this.low===-1?xe[n(825)](0,e.rcBIn(this[n(589)],1),this[n(892)]):xe[n(825)](e[n(300)](this[n(597)],1),this[n(589)],this[n(892)])}toBytes(n){let s=t;return n?this[s(1803)+"E"]():this[s(384)+"E"]()}toBytesLE(){let n=t,s={Bxvbm:function(l,h){return e[H(1035)](l,h)},qvHeQ:e[n(1191)],ZsIaZ:e[n(1351)]};if(e[n(518)]!=="vDFEj"){let l=this.high,h=this[n(597)];return[e[n(337)](255,h),e[n(675)](h>>>8,255),e[n(1516)](h,16)&255,e[n(988)](h,24),255&l,e.BZIir(e[n(1694)](l,8),255),e[n(337)](e.lBuKS(l,16),255),e[n(982)](l,24)]}else{let l={oBsyJ:function(h,w){let y=n;return fMphUz[y(1655)](h,w)},tLOfr:fMphUz[n(1387)],JbYHL:fMphUz[n(1239)]};_0x497834.r=h=>{let w=n;l[w(1253)](w(1369)+"d",typeof _0x2ff858)&&_0x2f183a[w(1482)+w(1381)]&&_0x37ea2a["definePr"+w(530)](h,_0x21c82f[w(1482)+w(1381)],{value:l[w(233)]}),_0x4e2d83[w(385)+"operty"](h,l[w(1400)],{value:!0})}}}[t(384)+"E"](){let n=t,s=this[n(589)],l=this[n(597)];return[e.PxGxp(s,24),e[n(999)](e[n(1041)](s,16),255),e[n(781)](e.lbaOn(s,8),255),e[n(1012)](255,s),e.NRWTk(l,24),l>>>16&255,e.nZCYk(l,8)&255,e.EFGjb(255,l)]}}let xl=new xe(0,0,!1),$p=new xe(0,0,!0),Vp=xe[t(825)](-1,2147483647,!1),Jp=xe[t(825)](-1,-1,!0),Zp=xe.fromBits(0,-2147483648,!1);var on=(function(a){let n=t,s={NqrXA:function(l,h){return e.xKhzg(l,h)},fagBW:function(l,h){return e[H(1352)](l,h)},Sqnuw:function(l,h){return e[H(956)](l,h)},BzCnH:function(l,h){return e.ZhBkZ(l,h)},Pcmav:function(l,h){return e[H(1506)](l,h)},FVlpu:function(l,h){return e[H(820)](l,h)},QskEq:function(l,h){return e.YenEJ(l,h)}};if(e[n(755)](e[n(1058)],e[n(1058)]))return a[a[e.HpBRi]=5001]=e[n(950)],a[a[n(1547)+n(1171)]=5002]=e[n(1115)],a[a[e[n(539)]]=5003]=e.nLYqo,a[a[e[n(1388)]]=5004]=n(503)+n(1567),a[a[e[n(1773)]]=5005]=n(1604)+"OR",a;{let l=this[n(589)],h=this.low;return[QXYYeB[n(437)](255,h),QXYYeB[n(1298)](h,8)&255,QXYYeB.Sqnuw(QXYYeB[n(1152)](h,16),255),QXYYeB.BzCnH(h,24),QXYYeB.Pcmav(255,l),QXYYeB[n(398)](QXYYeB[n(1432)](l,8),255),QXYYeB[n(487)](l>>>16,255),QXYYeB[n(1432)](l,24)]}})({});class ar{constructor(n){let s=t;this[s(1111)]=n,this[s(1285)]=null}}class pl extends ar{constructor(n,s){let l=t;super(n),this[l(1533)]=s&&s[l(1533)]||null}}class gl extends ar{constructor(n,s){let l=t,h=e[l(1295)].split("|"),w=0;for(;;){switch(h[w++]){case"0":this[l(1493)]=s&&s[l(1493)]||null;continue;case"1":this[l(1286)]=s&&s[l(1286)]||"";continue;case"2":super(n);continue;case"3":this.code=s&&s[l(311)]||5001;continue;case"4":this[l(1533)]=s&&s[l(1533)]||"";continue;case"5":this[l(1517)]=s&&s[l(1517)]||0;continue;case"6":this[l(772)]=s&&s[l(772)]||0;continue}break}}}class ml extends ar{constructor(n,s){let l=t,h=e.cXGOx[l(1244)]("|"),w=0;for(;;){switch(h[w++]){case"0":this[l(813)+l(1681)]=s&&s["willReco"+l(1681)]||!1;continue;case"1":this[l(1201)]=s&&s.reason||"";continue;case"2":super(n);continue;case"3":this[l(1749)]=s&&s[l(1749)]||!1;continue;case"4":this.code=s&&s[l(311)]||0;continue}break}}}class wl extends ar{constructor(n,s){let l=t;super(n),this[l(776)]=s&&s.data||null}}class _l extends wl{constructor(n,s){let l=t;super(n),this.data=s&&s.data||null,this.message=s&&s[l(1533)]||null}}class yl extends ar{constructor(n,s){let l=t;super(n),this[l(776)]=s&&s[l(776)]||null}}function lt(a,{message:n,code:s,error:l}){return new gl(a,{message:n,code:s,error:l})}function wt(a,{code:n,reason:s,wasClean:l,willReconnect:h}){return new ml(a,{code:n,reason:s,wasClean:l,willReconnect:h})}function bl(a,{data:n,message:s}){return new _l(a,{data:n,message:s})}function El(a,{data:n}){return new yl(a,{data:n})}function Sa(a,{message:n}){return new pl(a,{message:n})}class vl{constructor(n,s){let l=t;this[l(1545)+"s"]=n,this[l(900)+"es"]=s,this[l(1486)+l(1212)]=0,this[l(787)+"ndpointT"+l(625)+"t"]=0}[t(1603)+t(796)+t(803)](){let n=t,s={qYlWu:e[n(362)],CxfIK:function(l,h,w){return e[n(1420)](l,h,w)},Zurhg:function(l,h,w){return l(h,w)}};if(e[n(1584)]===e[n(519)])if(e[n(376)](_0x5adf87,_0x171578)){let l=_0x451b2e[n(327)][n(1443)](_0x121897.byteOffset,e[n(896)](_0x280dbf[n(499)+"th"],_0x583fde[n(1572)+"et"]));this[n(860)]&&this._socket.send({data:l,fail:h=>{let w=n;this.emit(s[w(674)],s[w(1413)](_0x49242a,s[w(674)],{message:this["_formatE"+w(1045)+w(520)](h)}))}})}else this[n(860)]&&this[n(860)][n(1398)]({data:_0x536c69,fail:l=>{let h=n;this[h(1676)](s[h(674)],s[h(727)](_0x580e85,s[h(674)],{message:this["_formatE"+h(1045)+"age"](l)}))}});else this[n(1486)+n(1212)]=0,this[n(787)+n(955)+n(625)+"t"]=0}resetTries(){let n=t;this["currentEndpointT"+n(625)+"t"]=0}getCurrentEndpoint(){let n=t;return this[n(1545)+"s"][this[n(1486)+n(1212)]]}[t(580)+"ntEndpoi"+t(1651)+t(551)](){let n=t;return this[n(787)+n(955)+n(625)+"t"]}[t(912)+"chMaxTries"](){let n=t;return!!(e.ooCWY(this[n(1486)+n(1212)],this.endpoints[n(1629)])||e[n(951)](this[n(1486)+"ndex"],e[n(378)](this.endpoints.length,1))&&e[n(370)](this[n(787)+n(955)+n(625)+"t"],this[n(900)+"es"]))}[t(1425)+t(743)+"ointReac"+t(1791)+t(768)](){let n=t;return e[n(1549)](this["currentI"+n(1212)],this[n(1545)+"s"][n(1629)])?!0:e[n(1412)](this[n(787)+"ndpointT"+n(625)+"t"],this[n(900)+"es"])}[t(1434)+t(1476)+t(1366)+"UpdateCo"+t(1334)](){let n=t;return this["currentE"+n(955)+n(625)+"t"]=1,this[n(1486)+"ndex"]++,this[n(1545)+"s"][this["currentI"+n(1212)]]}["getCurre"+t(1137)+t(1246)+t(1802)](){let n=t;return this[n(787)+"ndpointTriesCount"]++,this[n(580)+n(1137)+"nt"]()}}let cr=(e[t(671)](e[t(1256)],typeof globalThis)&&e[t(1355)](e[t(1180)],globalThis[t(1769)+"tor"].name)||e[t(671)](e[t(1256)],typeof window)&&t(1326)===window.constructor[t(826)])&&e[t(350)](e[t(1256)],typeof document),Nn=e[t(1527)](e[t(1256)],typeof globalThis)&&(e[t(755)]("Object",globalThis[t(1769)+t(1068)][t(826)])||e[t(944)](e[t(1361)],globalThis.constructor[t(826)]))&&e[t(1187)]("undefined",typeof tt),ri=(e[t(1256)]!=typeof globalThis&&e[t(1153)](e[t(1138)],globalThis[t(1769)+t(1068)][t(826)])||e[t(1281)](e.FuWSm,typeof globalThis)||e[t(771)](e[t(1256)],typeof globalThis)&&!!globalThis.WeixinJSBridge)&&typeof wx<"u",ii=e[t(1071)](e[t(1256)],typeof globalThis)&&(e[t(279)](e[t(1361)],globalThis[t(1769)+t(1068)][t(826)])||e[t(1512)](e.eCONu,globalThis[t(1769)+t(1068)][t(826)])||t(1654)+t(541)+"balScope"===globalThis[t(1769)+t(1068)][t(826)])&&e[t(1256)]!=typeof self,Yp=e[t(1527)](e.FuWSm,typeof globalThis)&&e.gCyOq(e[t(1138)],globalThis[t(1769)+t(1068)][t(826)])&&e[t(1213)](e[t(1256)],typeof global)&&e[t(303)](e.cBbSM,global[t(1769)+t(1068)][t(826)])&&e[t(771)](e[t(1256)],typeof process)&&!!process[t(888)];class Ia{constructor(){let n=t;this[n(1625)+"rs"]={}}[t(1676)](n,...s){let l=t,h=this[l(1625)+"rs"][n];if(h)h[l(1443)]()[l(1686)](w=>w.fn[l(1399)](w[l(562)],s));else if(e[l(362)]===n&&!this.onerror){let w=s.length&&s[0];if(e.LFGTX(w,Error))throw w;let y=new Error(e[l(1324)](e.PZuxx,w?e[l(1033)](" ("+w.message,")"):""));throw y[l(748)]=w,w}return this}off(n,s){let l=t;if(e[l(1685)](void 0,n))this[l(1625)+"rs"]={};else if(e.JZOkp(void 0,s))this[l(1625)+"rs"][n]=null;else if(e[l(838)]===e[l(838)]){let h=this[l(1625)+"rs"][n];if(h)for(let w=0;w<h[l(1629)];)h[w].fn===s?h.splice(w,1):++w}else _0x10c0d3[l(1174)](_0x26215e);return this}on(n,s,l){let h=t;return(this._listeners[n]||(this[h(1625)+"rs"][n]=[]))[h(1174)]({fn:s,ctx:l||this}),this}}class Xp extends Ia{_formatErrorMessage(n){let s=t;return n[s(1268)]||n[s(248)]?(s(729)+" "+(n[s(1268)]||"")+s(1001)+(n[s(248)]||"")).trim():JSON[s(920)+"y"](n)}constructor(n,s,l){let h=t;super(),this._socket=null,ri&&wx[h(1539)+h(1411)]&&(this[h(860)]=wx[h(1539)+h(1411)]({url:n,protocols:s,header:l,fail:this[h(309)+h(720)+"lHandler"][h(598)](this),success:this[h(309)+h(602)+h(827)+"ler"].bind(this)})),Nn&&tt["connectS"+h(1411)]&&(this[h(860)]=tt["connectS"+h(1411)]({url:n,protocols:s,header:l,fail:this[h(309)+"ocketFai"+h(265)][h(598)](this),success:this["_createS"+h(602)+h(827)+h(802)][h(598)](this)}))}[t(309)+t(602)+t(827)+t(802)](){let n=t;Promise[n(410)]()[n(968)](()=>{this._addWsListeners()})}[t(309)+t(720)+t(265)](n){let s=t;Promise[s(410)]().then(()=>{let l=s,h=e[l(239)](lt,e.HsQLM,{message:this[l(1767)+"rrorMess"+l(520)](n)});this.emit(l(1493),h);let w=wt(l(624),{reason:this[l(1767)+l(1045)+l(520)](n)});this[l(1676)](e.wrwSk,w)})}["_addWsLi"+t(723)](){let n=t,s={zxLgF:e.pAFVN,caEru:e[n(596)],gYyBI:function(l,h,w){return e[n(1065)](l,h,w)},kewhx:e[n(1310)]};this[n(860)][n(263)](l=>{let h=n;this[h(1676)](h(1287),e[h(1672)](El,e[h(1616)],{...l,data:l[h(1268)]||""}))}),this[n(860)][n(793)](l=>{let h=n;if(s[h(1795)]==="KFcTx")return h(493)+"_"+this[h(981)];this[h(1676)](s[h(579)],s[h(280)](wt,s[h(579)],{...l}))}),this[n(860)][n(747)+"e"](l=>{let h=n;this[h(1676)](s[h(1787)],s[h(280)](bl,s[h(1787)],{...l}))}),this[n(860)][n(231)](l=>{let h=n;this[h(1676)](e[h(362)],e[h(1165)](lt,e[h(362)],{...l,message:l[h(1268)]||""}))})}[t(1398)](n){let s=t,l={eXcCG:e[s(362)],VCalE:function(h,w,y){return h(w,y)}};if(e[s(376)](n,Uint8Array)){let h=n.buffer.slice(n[s(1572)+"et"],n[s(499)+"th"]+n[s(1572)+"et"]);this._socket&&this[s(860)][s(1398)]({data:h,fail:w=>{let y=s;this.emit(e.HsQLM,e[y(1065)](lt,e.HsQLM,{message:this[y(1767)+y(1045)+"age"](w)}))}})}else this[s(860)]&&this._socket[s(1398)]({data:n,fail:h=>{let w=s;this[w(1676)](l[w(578)],l[w(1318)](lt,l[w(578)],{message:this[w(1767)+w(1045)+w(520)](h)}))}})}[t(624)](n,s){let l=t;this[l(860)]&&this[l(860)][l(624)]({code:n,reason:s})}[t(777)+t(903)](n,s){this.on(n,s)}["removeEv"+t(997)+t(783)](n,s){let l=t;if(e[l(1331)](e.mkxgq,l(758)))return _0x4cccc7[l(1280)+"t8"]?_0x4193d1[l(1280)+"t8"](_0x21c3cc,_0x4bba14):_0xdbe052[_0x1fef4b]=255&_0x54779f,e[l(1462)](_0x2d9ee5,1);this[l(742)](n,s)}get[t(1467)+"te"](){let n=t;return this._socket[n(1467)+"te"]}get[t(990)+"pe"](){let n=t;return this._socket[n(990)+"pe"]}set binaryType(n){}get url(){let n=t;return this._socket[n(599)]}get protocol(){let n=t;return this[n(860)][n(976)]}get extensions(){let n=t;return this[n(860)][n(945)+"ns"]}get[t(1724)+"Amount"](){return 0}}function Qp(a,n){let s=t;if(n)return new n(a[s(599)],a.protocol);if(e[s(717)](ri,Nn))return new Xp(a[s(599)],a[s(976)],a[s(788)]);if((cr||ii)&&e.wYiTo(e[s(1256)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(599)],a[s(976)+"s"])}function eg(a){let n=t;return!!(a||ri&&wx["connectS"+n(1411)]||Nn&&tt[n(1539)+n(1411)]||(cr||ii)&&e[n(1187)](n(1369)+"d",typeof WebSocket)&&WebSocket)}function Sl(a,n,s){let l=t,h=-1;async function w(y){let E=H;if(e[E(502)](E(466),E(646)))return e[E(918)](y,h)?Promise[E(1091)](new Error(e[E(1421)])):(h=y,e[E(1083)](y,s[E(1629)])?Promise[E(410)]():s[y][E(598)](a)(n,w[E(598)](null,e[E(1701)](y,1))));++_0x5a319d,_0x26fa89+=4}e[l(1768)](w,0)}function Il(a){let n=t;if(e[n(939)](e[n(260)],e.hnBKc))_0x34da19[n(1699)][n(1587)+n(406)](_0x2715b5);else{let s=0,l=0;for(let h=0;h<a[n(1629)];++h)e[n(1753)]!==e.jAaYr?this[n(1374)+"T"]||this[n(1445)+"X"]?this[n(1308)+n(1798)+"ange"]():this._isBrowser&&this["_initGlo"+n(464)+n(903)]():(l=a[n(1182)+"At"](h),e[n(1092)](l,128)?s+=1:e[n(817)](l,2048)?s+=2:e.OXziz(64512,l)===55296&&e[n(1430)](64512,a[n(1182)+"At"](e.TeNJc(h,1)))===56320?(++h,s+=4):s+=3);return s}}function Al(a,n,s){let l=t;if(e[l(784)](s-n,1))return"";let h="";for(let w=n;w<s;){let y=a[w++];if(e.osuRB(y,127))h+=String[l(1449)+l(1247)](y);else if(e[l(1634)](y,192)&&y<224)h+=String[l(1449)+"Code"](e.VoBRI(e[l(879)](31&y,6),e[l(382)](63,a[w++])));else if(e[l(511)](y,224)&&e.Cljnv(y,240))h+=String[l(1449)+l(1247)](e.ESWmp(e[l(657)](e.Mpllc(15&y,12),e[l(1554)](63,a[w++])<<6),e[l(1622)](63,a[w++])));else if(e[l(261)](y,240)){let E=e[l(1040)](e.QOxqj(e[l(489)](e.WhFPs(e.zwKzc(7&y,18),e[l(682)](e[l(601)](63,a[w++]),12)),e[l(1297)](e.rHnet(63,a[w++]),6)),63&a[w++]),65536);h+=String[l(1449)+"Code"](e[l(739)](55296,e[l(836)](E,10))),h+=String["fromChar"+l(1247)](e.YhNqF(56320,e[l(382)](1023,E)))}}return h}function Aa(a,n,s){let l=t,h={hIRsm:function(p,R){return e[H(1209)](p,R)},chnyD:function(p,R){return e.eFZtB(p,R)},afSau:function(p,R){return e[H(1778)](p,R)}},w=s,y,E;for(let p=0;e[l(1595)](p,a[l(1629)]);++p)if(e[l(786)](e[l(1379)],e[l(1379)]))this.emit(e[l(362)],e[l(1052)](_0x3b3617,l(1493),{message:this["_formatE"+l(1045)+l(520)](_0x932840)}));else if(y=a[l(1182)+"At"](p),e.oSMXL(y,128))n[s++]=y;else if(e[l(1322)](y,2048))n[s++]=e[l(756)](e[l(836)](y,6),192),n[s++]=e[l(973)](63&y,128);else if(e[l(1131)](e[l(859)](64512,y),55296)&&e[l(1586)](e[l(1233)](64512,E=a[l(1182)+"At"](e[l(462)](p,1))),56320))if(e[l(951)](e[l(1338)],e[l(1338)])){let R=e[l(284)][l(1244)]("|"),T=0;for(;;){switch(R[T++]){case"0":n[s++]=e[l(1695)](e.XvbTl(63,y),128);continue;case"1":n[s++]=e[l(1023)](e.xdzcq(y,18),240);continue;case"2":++p;continue;case"3":n[s++]=e.pzsYl(e.sEWJh(y,6)&63,128);continue;case"4":y=e.ctVml(65536+e[l(665)](1023&y,10),e[l(1648)](1023,E));continue;case"5":n[s++]=e[l(756)](e[l(820)](e[l(1611)](y,12),63),128);continue}break}}else return this[l(892)]?vKpThw.hIRsm(this.high>>>0,_0x102e1b)+vKpThw[l(1376)](this[l(597)],0):vKpThw[l(799)](this[l(589)]*_0x835475,vKpThw[l(1376)](this[l(597)],0));else n[s++]=e[l(318)](e[l(836)](y,12),224),n[s++]=e[l(354)](y,6)&63|128,n[s++]=e[l(877)](63&y,128);return e[l(614)](s,w)}async function kl(a){let n=t;if(e[n(1549)]("string",typeof a)){let s=new Uint8Array(Il(a));return e[n(1266)](Aa,a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[n(327)],a[n(1572)+"et"],a[n(499)+"th"])}function tg(a){let n=t,s={lBqzS:function(l,h){return l<=h},zGEzz:function(l,h){return e[H(1107)](l,h)},uRGpr:function(l,h){return e[H(817)](l,h)},AnVyZ:function(l,h){return l|h},fAlkW:function(l,h){return e.XndVK(l,h)},MFISx:function(l,h){return l&h},NqZZD:function(l,h){return l<h},EFwME:function(l,h){return e[H(1258)](l,h)},Qdnny:function(l,h){return e.EdQUb(l,h)},Emjpc:function(l,h){return e[H(1039)](l,h)},CZSKM:function(l,h){return e[H(489)](l,h)},Mkibf:function(l,h){return e[H(1056)](l,h)},cuupF:function(l,h){return l&h},LqEZy:function(l,h){return e[H(682)](l,h)},uRPAt:function(l,h){return e[H(886)](l,h)},zKwgf:function(l,h){return e.GnzBc(l,h)},YGuri:function(l,h){return e[H(513)](l,h)},XzIJb:function(l,h){return e[H(1611)](l,h)},RujZr:function(l,h){return e.kPFrG(l,h)}};if(e[n(942)](e.PwZco,e[n(1783)])){let l=_0x4d8b8c[_0x2f40fa++];if(vVAjFB[n(343)](l,127))_0x5959cc+=_0x193015[n(1449)+"Code"](l);else if(vVAjFB.zGEzz(l,192)&&vVAjFB[n(994)](l,224))_0x5c66b9+=_0x334db0["fromChar"+n(1247)](vVAjFB.AnVyZ(vVAjFB[n(842)](31,l)<<6,vVAjFB[n(1218)](63,_0x247482[_0x45dfc9++])));else if(vVAjFB.zGEzz(l,224)&&vVAjFB.NqZZD(l,240))_0x27c406+=_0x1375f0[n(1449)+n(1247)](vVAjFB[n(1677)](vVAjFB.Qdnny(15,l),12)|(63&_0x2a8bc6[_0x20933b++])<<6|63&_0x411006[_0x571e2e++]);else if(l>=240){let h=vVAjFB[n(506)](vVAjFB[n(1727)](vVAjFB[n(1727)](vVAjFB[n(1675)](vVAjFB[n(1575)](7,l),18),vVAjFB.LqEZy(vVAjFB.uRPAt(63,_0x12c44d[_0x118bb1++]),12)),vVAjFB[n(1675)](63&_0x4f23a6[_0x30f049++],6)),vVAjFB[n(1102)](63,_0x61200a[_0x5c1d8d++]))-65536;_0x38a63c+=_0x22beac[n(1449)+n(1247)](vVAjFB[n(1250)](55296,vVAjFB[n(383)](h,10))),_0x3c1262+=_0x47018f[n(1449)+"Code"](vVAjFB[n(371)](56320,vVAjFB[n(842)](1023,h)))}}else try{return e.yelKe("string",typeof a)&&(e[n(1248)](a,ArrayBuffer)||a[n(327)]&&e.yntpu(a.buffer,ArrayBuffer))||e[n(481)](e.VIPji,typeof a)?"":(JSON[n(524)](a),e[n(800)])}catch{if(e[n(563)](n(276),e[n(895)]))return e[n(1281)](e[n(1e3)],typeof a)?"text/pla"+n(1230)+"et=utf-8":"";_0x53c044<65536?_0x41203f[_0x3fcb1d++]=e.rfFpe(e[n(798)](e[n(965)](_0x35839b,12),15),224):(_0x17218e[_0xdb3e2e++]=e[n(554)](_0x32c48>>18&7,240),_0x3fbbbd[_0x3b2181++]=e[n(798)](_0x135c01>>12,63)|128),_0x1244cd[_0x225ead++]=e[n(906)](e[n(354)](_0x3c494b,6)&63,128)}}let ng=(a,n)=>{let s=t;switch(a){case s(545):case e.gJfRX:return{[s(458)+a]:1,"x-tt-env":n};default:return{}}};class rg{constructor(n){let s=t;this[s(537)+s(551)]=n,this[s(972)]=0}[t(1702)](){let n=t;this[n(972)]++}[t(912)+"chMaxCount"](){let n=t;return this[n(972)]>=this[n(537)+n(551)]}["resetCou"+t(1084)](n=0){let s=t;this["maxLossC"+s(551)]=n,this[s(972)]=0}}async function ig(a){let n=t,s={SGdTQ:function(l,h){return e[H(1513)](l,h)},xUDYe:"unknown "+n(1201),OdjnL:e[n(428)],spUWw:function(l,h){return e.OhzIP(l,h)},DaxYd:e[n(1085)],DpEis:e.dDOVw,GGvLb:function(l,h){return e.Pgvwc(l,h)},DWHEI:e[n(1359)]};if(e[n(594)](e[n(1555)],e[n(1555)]))_0x4eb8b3=e[n(423)](_0x1925d1,_0x5a47bc),e.iljMj(_0x3eb19f,32)&&(_0x33d590|=e[n(367)](e[n(1747)](127,_0x35f73b),_0x5aa449)),_0x11a604+=7;else return new Promise(l=>{let h=n;if(!cr)return l(h(658)+"reason");try{let w=document["createEl"+h(719)](s[h(1550)]);window[h(493)+h(1754)]=y=>{let E=h;document[E(1699)][E(1587)+E(406)](w),window[E(493)+E(1754)]=void 0,s[E(268)](l,y&&y.msg||s[E(1436)])},w[h(1111)]=h(1531)+"ascript",w[h(460)]=s[h(709)](a[h(288)](/^ws/,s[h(1054)]),s[h(1504)]);try{document[h(1699)]["appendCh"+h(406)](w)}catch{if(s.GGvLb(s.DWHEI,h(1158)))document.body[h(1587)+h(406)](w);else return this[h(1601)]?this[h(1601)].extensions:""}}catch{window[h(493)+h(1754)]=void 0,s[h(268)](l,s[h(1436)])}})}function an(a,n,s){let l=t;return!!a?.find(h=>h[l(254)]===n&&h.value===s)}function dr(a,n){let s=t;return a?.find(l=>l[s(254)]===n)?.[s(585)]}let ka=null;async function sg(){let a=t;if(e.eWNnk(a(555),e[a(1541)]))return ka||(ka=Promise[a(410)]()[a(968)](zt.bind(zt,e.FhcZr))),ka;e[a(668)](_0x420704,_0x1943c8,96),_0xf7d9e2(_0x585281,e[a(1591)](_0x334d0f,_0x4e7c5c))}class og extends Ia{constructor(n,s){let l=t;super(),this[l(310)]=n,this[l(1257)]=s,this[l(1293)]=void 0,this[l(591)+"mise"]=null}async[t(1109)](){await this[t(1100)]()}async[t(1100)](){let n=t;if(!this[n(1293)]){if(this[n(591)+n(830)])return this[n(591)+n(830)];try{let s=this._dbName,l=this[n(1257)];this._initPromise=(async()=>{let h=n,{openDB:w}=await e[h(1151)](sg);this[h(1293)]=await w(h(493)+"_"+s,1,{upgrade(y){y[h(507)+"jectStore"](s,{keyPath:l})}})})(),await this[n(591)+n(830)]}catch(s){console[n(508)](s)}finally{this[n(591)+n(830)]=null}}}async[t(644)](n){let s=t;try{return await this[s(1100)](),this[s(1293)]?.[s(644)](this._dbName,n)}catch(l){if(e.DbdNZ(s(1264),e[s(1225)])){let h=_0x3aa2e9[s(1244)](":");for(let w=0;e.kvAFg(w,h[s(1629)]);w++){let y=h[w];if(e[s(1576)](4,h[w][s(1629)])){let E=_0x54a8fd[s(711)+"g"](0,4-h[w][s(1629)]),p=E[s(440)](y);_0x12b1ec=_0x389563[s(440)](p)}else _0x87c6cd=_0xf93b98[s(440)](y)}return _0x1d36ed}else console[s(508)](l)}}async set(n,s){let l=t;return await this[l(1100)](),this[l(1293)]?.[l(1343)](this[l(310)],n)}async del(n){let s=t;try{return await this[s(1100)](),this[s(1293)]?.delete(this[s(310)],n)}catch(l){e[s(938)](e[s(1340)],e[s(252)])?console.log(l):(this[s(1275)+s(645)+"Id"]=null,this[s(1275)+"l"]=36e5,this[s(1293)]=_0xf25d06(e[s(1678)],e[s(237)]))}}async[t(844)](){let n=t;try{return await this._init(),this[n(1293)]?.clear(this._dbName)}catch(s){console.log(s)}}async[t(867)](){let n=t;return await this[n(1100)](),this._qosDB?.[n(913)+"ys"](this[n(310)])}async[t(757)](){let n=t;return await this[n(1100)](),this[n(1293)]?.[n(757)](this[n(310)])}async[t(452)](){let n=t,s={jQLvD:function(l,h){return e[H(1738)](l,h)},FqkSh:function(l,h){return e.fjCBG(l,h)}};try{this[n(1293)]?.[n(624)](),this[n(1293)]=void 0}catch(l){if(e[n(414)](e[n(1202)],n(1003))){if(nwshwb.jQLvD(void 0,_0x4f0dec))this[n(1625)+"rs"]={};else if(nwshwb[n(715)](void 0,_0x4b1d12))this[n(1625)+"rs"][_0x5be987]=null;else{let h=this[n(1625)+"rs"][_0xce325e];if(h)for(let w=0;w<h.length;)h[w].fn===_0x3d58e2?h[n(298)](w,1):++w}return this}else console[n(508)](l)}}get[t(915)](){let n=t;try{return!!this[n(1293)]}catch(s){return console[n(508)](s),!1}}}class ag{constructor(n,s){let l=t;this[l(981)]=n,this[l(1477)]=s,this[l(1293)]=localStorage}async[t(1109)](){}get _prefix(){let n=t;return n(493)+"_"+this[n(981)]}async get(n){let s=t,l=this[s(1293)][s(974)](this[s(583)]);return JSON[s(524)](l||"{}")[n]}async[t(272)](n,s){let l=t,h=this[l(1293)].getItem(this[l(583)]),w=JSON[l(524)](e[l(1650)](h,"{}"));return w[s||n[this[l(1477)]]]=n,this._qosDB.setItem(this[l(583)],JSON[l(920)+"y"](w)),s||n[this._pathKey]}async[t(819)](n){let s=t,l=this._qosDB.getItem(this[s(583)]),h=JSON.parse(e[s(807)](l,"{}"));return h[n]=void 0,this[s(1293)][s(1327)](this._prefix,JSON[s(920)+"y"](h))}async[t(844)](){return this[t(1293)].clear()}async keys(){let n=t,s=this[n(1293)][n(974)](this[n(583)]),l=JSON[n(524)](e[n(717)](s,"{}"));return Object[n(867)](l)}async getAll(){let n=t,s=this[n(1293)][n(974)](this[n(583)]),l=JSON[n(524)](e[n(970)](s,"{}"));return Object[n(1373)](l)}closeDB(){let n=t;return e[n(1682)]!==n(1385)?this._ws?this[n(1601)][n(990)+"pe"]:this[n(344)+n(1472)]:Promise[n(410)]()}get[t(915)](){return!!this[t(1293)]}}class cg{constructor(n,s){let l=t;this[l(981)]=n,this[l(1477)]=s,this[l(1293)]=Nn?tt:ri?wx:null}async[t(1109)](){}get _prefix(){let n=t;return e.LkuAx("rIOkr",n(1723))?e.xYoXR(_0x149307,_0x57b376)?_0x114b5b:new _0xcfba76(e.aWUCU(e.VEEVP(_0xecebc7[n(1224)](_0x2df498,0),e.fDlQt(_0x24e34f[n(1224)](_0x139a23,1),8))|_0x219d74[n(1224)](_0x128c5d,2)<<16|e[n(1260)](_0x347b03[n(1224)](_0x133a83,3),24),0),e[n(1329)](e[n(874)](e[n(1631)](e[n(1661)](_0x2fb758[n(1224)](_0x411e9b,4),_0x47944c.call(_0x197847,5)<<8),e[n(1705)](_0x4aa7b2.call(_0x5316f9,6),16)),e[n(1594)](_0x5321f3[n(1224)](_0x4fa59d,7),24)),0),!0):"frontier_"+this[n(981)]}async[t(644)](n){let s=t;if(e[s(1732)]==="Fakgr"){let l=this[s(1293)][s(694)+s(1569)](this[s(583)]);return JSON[s(524)](l||"{}")[n]}else throw this[s(1147)+s(935)]=!1,_0x3197d9}async[t(272)](n,s){let l=t,h=this[l(1293)]["getStora"+l(1569)](this[l(583)]),w=JSON.parse(e[l(653)](h,"{}"));return w[s||n[this._pathKey]]=n,this[l(1293)][l(1804)+l(1569)](this._prefix,JSON[l(920)+"y"](w)),s||n[this[l(1477)]]}async[t(819)](n){let s=t,l=this[s(1293)]["getStora"+s(1569)](this[s(583)]),h=JSON[s(524)](e[s(970)](l,"{}"));return h[n]=void 0,this[s(1293)][s(1804)+s(1569)](this[s(583)],JSON.stringify(h))}async[t(844)](){let n=t,s={iDiaH:function(l,h,w,y){return l(h,w,y)},afykG:e.HsQLM};if(e.NCuPW(e[n(909)],n(1019)))try{s[n(1199)](_0x3c338f,this,_0x18558b,[_0x29e12a,_0x4c9181,_0x4b3deb])}catch(l){let h=_0x377b49(s[n(571)],{message:l[n(1533)],code:_0x1be3b4[n(1604)+"OR"],error:l});this[n(1524)+n(673)+n(823)](h)}else return this[n(1293)][n(870)+"rageSync"]()}async keys(){let n=t,s=this._qosDB[n(694)+"geInfoSync"](this[n(583)]),l=JSON.parse(e.zVhqJ(s,"{}"));return Object[n(867)](l)}async[t(757)](){let n=t,s=this[n(1293)][n(694)+n(636)+"nc"](this._prefix),l=JSON.parse(s||"{}");return Object[n(1373)](l)}closeDB(){return Promise.resolve()}get[t(915)](){return!!this[t(1293)]}}function Tl(a,n){let s=t;if(e[s(1292)](Nn,Nn))return new cg(a,n);if((cr||ii)&&s(1369)+"d"!=typeof indexedDB)return new og(a,n);if(e[s(333)](cr,ii)&&e[s(1256)]!=typeof localStorage)return new ag(a,n);throw new Error(e.diKAQ)}class dg{constructor(){let n=t;this[n(1275)+"lTimeoutId"]=null,this[n(1275)+"l"]=36e5,this._qosDB=e[n(1198)](Tl,"qos",e[n(237)])}async["_interva"+t(1422)](){let n=t;e[n(1579)](clearInterval,this["_interva"+n(645)+"Id"]),this[n(1275)+n(645)+"Id"]=e[n(936)](setInterval,()=>{let s=n,l={EXkVQ:e[s(1310)]};e.WrBSk(s(1347),e[s(692)])?this[s(1154)+"ired"]():(this.emit(l.EXkVQ,_0x2a5573),this.onmessage&&this[s(638)+"e"](_0x247af3))},this[n(1275)+"l"])}async[t(1109)](){let n=t;await this[n(1293)][n(1109)]()[n(968)](()=>{let s=n;this[s(1275)+s(1422)]()})}async[t(1154)+t(1238)](){let n=t,s={lvCoO:function(w){return e[H(1488)](w)},SAoVa:function(w,y){return e[H(370)](w,y)},mOKOK:e[n(1378)]};(await this[n(1293)]?.[n(757)]()||[])[n(1221)](({timestamp:w})=>w<Date[n(1328)]())[n(1686)](w=>{let y=n,E={byNfq:function(p){return s[H(1259)](p)}};s.SAoVa(s[y(1780)],s[y(1780)])?this[y(1293)]?.[y(819)](w[y(1215)+"id"]):(ejaqWQ[y(868)](_0x452492),_0x336e04())})}async del(n){let s=t;return this[s(1293)]?.[s(819)](n)}async[t(272)](n,s){return this[t(1293)]?.set({message_id:n,timestamp:s})}async[t(644)](n){return this._qosDB?.get(n)}async[t(452)](){let n=t;e[n(1485)](clearInterval,this["_interva"+n(645)+"Id"]),await this[n(1293)]?.closeDB()}get[t(915)](){let n=t,s={ZAEse:function(l,h,w){return e[H(445)](l,h,w)},cudEp:e.HsQLM,gZFDF:function(l,h,w){return e[H(881)](l,h,w)},uqZLA:e[n(596)]};if(e[n(1602)](e[n(1077)],e[n(1077)]))return this[n(1293)]?.isReady;_0x3968f3[n(410)]()[n(968)](()=>{let l=n,h=XcEiKm[l(628)](_0x165ae1,XcEiKm[l(456)],{message:this[l(1767)+"rrorMessage"](_0x4e59ce)});this.emit(XcEiKm[l(456)],h);let w=XcEiKm[l(424)](_0x55ed61,l(624),{reason:this[l(1767)+l(1045)+l(520)](_0x1ce0f4)});this[l(1676)](XcEiKm.uqZLA,w)})}}function Ta(a){let n=t,s=!!this[n(889)][n(1807)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e.zreQa(an,a[n(1533)][n(788)],e[n(1763)],"2"),h=l&&e[n(1589)](an,a[n(1533)][n(788)],e[n(1553)],"1"),w=l&&e[n(1589)](an,a[n(1533)][n(788)],e.knCAU,"1"),y=w?e.xmCvA(dr,a[n(1533)].headers,e[n(1745)])?.[n(1244)](",")[n(1221)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:h,isAckCleanupMessage:w,ackMsgIds:y}}async function Cl(){let a=t;if(e.fQlDV(a(547),e[a(1643)]))return this[a(914)+a(962)]||(this[a(914)+a(962)]=new dg),this[a(914)+a(962)][a(915)]||await this["_QoSMana"+a(962)][a(1109)](),this[a(914)+a(962)];{let n=e.QZyKc(_0x13ba83);return e[a(1118)](_0x562e23,_0x489e28,n),e[a(475)](_0x27a7fd,n)}}async function lg(a,n){let s=t,{enableAutoAck:l}=this[s(889)],h=e[s(1266)](an,a[s(1533)][s(788)],e[s(1349)],"1"),w=e[s(1713)](an,a[s(1533)][s(788)],"is_ack","1"),y=Ta.call(this,a);if(e[s(392)](l,h)){let{SeqID:E,LogID:p,service:R,LogIDNew:T,method:N}=a[s(1533)];this[s(357)]({SeqID:E,LogID:p,LogIDNew:T,service:R,method:N,headers:[{key:e[s(1683)],value:"1"},{key:e.dLUkY,value:e[s(653)](T,"")},{key:e.sjFqs,value:"0"}]})}w&&!y[s(623)]&&this[s(1524)+"hAckMess"+s(893)](a),e[s(1151)](n)}async function ug(a,n){let s=t;this._debug(s(1637),a[s(1533)]),e.pKBoj(n)}async function fg(a,n){let s=t,l=rn(await kl(a[s(776)]));try{if(e.xrQlo(l[s(1112)],Uint8Array))if(e[s(386)](e.StUYl,e[s(234)])){let h=e[s(1222)](this[s(889)][s(1551)+"ncoding"],Object)?{force:!!this[s(889)][s(1551)+s(1211)][s(684)],encoding:this._options[s(1551)+s(1211)][s(299)]?this[s(889)][s(1551)+s(1211)].encoding.replace(/\s/g,"").toLowerCase():""}:{force:!1,encoding:this._options["payloadE"+s(1211)]?this[s(889)][s(1551)+s(1211)].replace(/\s/g,"")[s(492)+"ase"]():""},w=l[s(1551)+s(1211)]?l[s(1551)+s(1211)][s(288)](/\s/g,"")["toLowerC"+s(1064)]():"",y=e.UgEyZ(this[s(889)][s(1394)+s(1472)],Object)?{force:!!this._options["payloadT"+s(1472)].force,type:this[s(889)][s(1394)+s(1472)][s(1111)]?this[s(889)][s(1394)+"ype"][s(1111)][s(288)](/\s/g,"")[s(492)+s(1064)]():""}:{force:!1,type:this[s(889)]["payloadT"+s(1472)]?this._options[s(1394)+s(1472)][s(288)](/\s/g,"")[s(492)+s(1064)]():""},E=l[s(1394)+s(1472)]?l[s(1394)+s(1472)][s(288)](/\s/g,"")[s(492)+"ase"]():"",p=y[s(684)]?y[s(1111)]:E||y.type,R=h[s(684)]?h[s(299)]:w||h[s(299)],T=[e[s(764)],"applicat"+s(1578),e[s(238)],e.VIPji],N=[e[s(1133)],e[s(916)]];this[s(889)][s(610)+s(1364)+s(643)+"ad"]&&T.includes(p)&&(!R||N[s(875)](R))?l.textPayload=Al(l[s(1112)],0,l[s(1112)][s(499)+"th"]):l["textPayl"+s(1415)]=""}else this._ws&&this._ws.send(_0x2f64ae),this[s(1593)+s(1350)][_0x129d4e]=null;else l[s(1027)+s(1415)]=""}catch(h){if(e[s(1301)](e.iRvtt,"MtlCx"))return this[s(1601)]?this[s(1601)].protocol:"";l[s(1027)+"oad"]="",console.log(h)}a[s(1533)]=l,e[s(980)](n)}function hg(a,n,s){let l={feuTV:function(p,R){return e[H(1342)](p,R)}},h=s||8192,w=e.uIbQT(h,1),y=null,E=h;return function(p){let R=H;if(p<1||p>w)return e[R(1161)](a,p);e[R(1707)](e[R(1145)](E,p),h)&&(e[R(785)]!==R(413)?(y=e[R(894)](a,h),E=0):(_0x16fd80=l[R(1416)](_0x8ac7af,_0x1b0c09),_0x4f541b=0));let T=n[R(1224)](y,E,E+=p);return e.nbgaj(7,E)&&(E=e[R(1283)](7|E,1)),T}}let xg=4294967295;function pg(a,n,s){let l=t;return e[l(619)](RangeError,e[l(549)](e[l(1053)](e.hTRPv(e[l(1778)](e[l(887)],a),e[l(1284)]),e.fFthv(n,1))+e[l(1464)],s))}function gg(a,n,s){let l=t;if(s>xg)throw new Error(e[l(336)]);let h=3;for(;e.aJfBp(h,0);){let w=e[l(1742)](255,s);e[l(1716)](Ra,w,a,e[l(1562)](n,h)),s>>>=8,h--}return n+4}function mg(a,n){let s=t;if(e[s(937)](e[s(1599)],"MDBSD")){let l=0,h=n,w=n+4;for(;h<w;){let{value:y,offset:E}=e.FaJQh(Ca,a,h);h=E,l=e[s(332)](e[s(682)](l,8),0),l+=y}return{value:l,offset:w}}else{let l=e.pnfsZ(_0xd8b2b1,_0x38cdf,_0xce29e2.length);_0x5e8d18[s(372)][s(272)](_0x48e45f,l)}}function wg(a,n,s){let l=t;if(e[l(1110)](e[l(255)],l(1669))){let h=e.HRlSG.split("|"),w=0;for(;;){switch(h[w++]){case"0":if(n[l(1316)+"e"])return n[l(1316)+"e"](a,s)+s;continue;case"1":if(e[l(1204)](a[l(1629)],40))return e.XEzjI(e.zreQa(Aa,a,n,s),s);continue;case"2":if(!a)return s;continue;case"3":return e[l(1792)](e[l(1116)](Aa,a,n,s),s);case"4":if(n.write)return e[l(683)](n.write(a,s),s);continue}break}}else this[l(1601)]&&this[l(1601)][l(1398)](_0x2a63c1),this[l(718)](l(425),_0x1ffd7e)}function _g(a,n){let s=t;if(e.lBmSl!=="vHbva"){if(this["_clearPi"+s(308)](),this[s(676)+"mer"](),this["_removeW"+s(471)+"rs"](),this[s(1793)+s(1164)](1e3,_0x33b805),this[s(1147)+s(935)]=!1,_0xb03a3a&&this[s(931)+s(1484)]()&&!this[s(432)+"osed"]){if(this[s(448)+s(664)]?.[s(912)+s(245)+"es"]()){let h=this[s(448)+s(664)]?.[s(580)+"ntEndpoint"]();this[s(1524)+s(1014)+"ent"](e[s(1672)](_0x191003,s(624),{code:1006,reason:s(957)+h+(" timeout"+s(1491)+"tries re"+s(878)),wasClean:!0}))}else{let h=this[s(889)]["reconnec"+s(463)+s(1393)](_0x532043,_0x18eee5);this[s(1524)+s(1014)+s(823)](e[s(467)](_0x1b4a8b,s(624),{code:_0x52c3c4,reason:_0x369e7f,wasClean:!0,willReconnect:h})),h&&this[s(1147)]()}return}this._navigatorOnline()||this[s(432)+s(872)]?this[s(1524)+s(1014)+s(823)](e[s(470)](_0x5bd123,s(624),{code:_0x294ec1,reason:e[s(590)]})):this[s(1524)+s(1014)+s(823)](e[s(297)](_0x14719c,e.wrwSk,{code:1006,reason:e[s(1362)]})),this[s(1601)]=null,this[s(448)+s(664)]?.[s(1603)+s(796)+s(803)](),this[s(947)+s(250)]?.[s(1615)+"nter"]()}else{let l=new xe(e.ygzMK(e.atvvg(e[s(753)](e[s(429)](a[e[s(1508)](n,4)],24),e[s(302)](a[e[s(858)](n,5)],16)),e.kRFsc(a[e.HeJJR(n,6)],8)),a[e[s(1515)](n,7)]),e[s(1039)](e[s(846)](e[s(665)](a[n+0],24),e[s(897)](a[e.CBQNe(n,1)],16)),e[s(235)](a[e[s(1668)](n,2)],8))|a[e[s(1283)](n,3)],!0);return n+=8,{value:l,offset:e[s(1537)](n,8)}}}function yg(a,n,s){let l=t,h=a[l(597)],w=a.high;return n[s]=e[l(1346)](w,24),n[e[l(1145)](s,1)]=e[l(417)](w>>>16,255),n[s+2]=e.EdQUb(e[l(1471)](w,8),255),n[e.CBQNe(s,3)]=e[l(1617)](255,w),n[s+4]=e[l(852)](h,24),n[e[l(661)](s,5)]=h>>>16&255,n[e.kMJEI(s,6)]=e.VZWyD(e[l(982)](h,8),255),n[e[l(1427)](s,7)]=e[l(1335)](255,h),s+=8,s}function Ca(a,n){let s=t;return a.readUInt8?{value:a[s(864)+"8"](n),offset:e[s(1254)](n,1)}:{value:e.ETgde(255,a[n]),offset:e[s(1619)](n,1)}}function Ra(a,n,s){let l=t;return n[l(1280)+"t8"]?n[l(1280)+"t8"](a,s):n[s]=255&a,e[l(1792)](s,1)}let bg=function(a){return new Uint8Array(a)},Eg=e[t(1407)](t(1369)+"d",typeof Buffer)?Buffer[t(840)+t(922)]:e[t(1689)](hg,bg,Uint8Array[t(995)+"e"].subarray);(()=>{let a=t,n={QqtOg:function(s,l,h){return e[H(566)](s,l,h)},ZKJCz:function(s,l){return e[H(902)](s,l)},UFgKC:function(s,l){return e.JORMo(s,l)},VTLWU:function(s,l){return e[H(1766)](s,l)},oHuAC:function(s,l){return e[H(397)](s,l)},PUlII:function(s,l){return e.OfrRf(s,l)},wQfRY:function(s,l){return s<l},LlckZ:function(s,l){return e[H(1529)](s,l)},LSslp:function(s,l){return e.aWUCU(s,l)},SHBQu:function(s,l){return e[H(1661)](s,l)},yyNty:function(s,l){return e[H(390)](s,l)},GvMzg:function(s,l){return s>>>l},CzIcz:function(s,l){return e[H(586)](s,l)},dgVrD:function(s,l){return s<<l},uqjox:function(s,l){return e.OXziz(s,l)},PvfGo:function(s,l){return e.TZgRo(s,l)},GOdJb:function(s,l){return e[H(1770)](s,l)},bmYky:e[a(287)]};if(e.SfoKz(a(626),e[a(1126)])){let s=4294967295;return function(l,h,w=!0){let y=a,E={oKoNv:function(p,R,T){return n[H(655)](p,R,T)},iDnIE:function(p,R,T){return p(R,T)}};if(s=(127&l[h])>>>0,l[h++]<128)return{value:w?s:n[y(409)](0,s),offset:h};if(s=n[y(396)](n[y(1232)](s,n[y(1446)](n.PUlII(127,l[h]),7)),0),n[y(400)](l[h++],128))return{value:w?s:0|s,offset:h};if(s=n[y(396)](n.VTLWU(s,n.LlckZ(127,l[h])<<14),0),n.wQfRY(l[h++],128))return{value:w?s:0|s,offset:h};if(s=n[y(295)](n[y(1251)](s,n[y(1391)](127,l[h])<<21),0),l[h++]<128)return{value:w?s:n.SHBQu(0,s),offset:h};if(s=n[y(977)](n[y(677)](s,n[y(1314)](n[y(1022)](15,l[h]),28)),0),n[y(400)](l[h++],128))return{value:w?s:n.PvfGo(0,s),offset:h};if((h+=5)>l[y(1629)]){if(n.GOdJb(n[y(364)],n.bmYky))throw h=l[y(1629)],pg(h,10,l[y(1629)]);QOchTb[y(365)](_0x51dca0,_0x16df78,32),QOchTb[y(1715)](_0x213a44,_0x101ce5,_0x1d9aca(_0x1bfc42))}return{value:w?s:n.ZKJCz(0,s),offset:h}}}else _0x57d7f1[a(1442)]=_0x2b4a73[a(410)]()[a(968)](()=>(_0x1e0977(),_0x36032d))[a(968)](function(s){return s})})();let vg=16,Pa=32;function Sg(a){let n=t,s=0,l={};for(let h=0;e[n(822)](h,a[n(1629)]);h++)l[a[h][n(632)+n(1271)]]=e[n(647)](Il,a[h]["cursor_n"+n(1271)]),s+=e.VWjXo(14,l[a[h][n(632)+n(1271)]]);return[s,l]}function Rl(a,n,s){let l=t,h={ghetg:e[l(1501)],OzfWg:e[l(305)],yEYkQ:function(R,T,N,G){return e[l(1055)](R,T,N,G)},xHOFs:l(341),dMuHh:function(R,T,N,G){return e[l(1266)](R,T,N,G)},UREhC:l(826),AUqXL:function(R,T,N,G){return e[l(1195)](R,T,N,G)},nvKCg:l(695)},[w,y]=e[l(352)](Sg,a),E=e[l(1729)](Eg,w),p=0;return a[l(1686)](R=>{let T=l;console[T(508)](h[T(1639)],R,R[T(341)]),p=Ra(0,E,p),console[T(508)](h[T(582)],p),p=h[T(1028)](gg,E,p,R[T(341)]||0),console[T(508)](h[T(484)],p),p=Ra(y[R[T(632)+"ame"]],E,p),console[T(508)]("service-name",p),p=h.dMuHh(wg,R[T(632)+T(1271)],E,p),console[T(508)](h[T(454)],p),p=h[T(1103)](yg,xe[T(435)+"er"](R[T(505)]||n),E,p),console[T(508)](h.nvKCg,p)}),{frameType:Pa,headers:[{key:e[l(1117)],value:s}],payload:E}}function Ig(a){let n=t,s=0,l=[];for(;e[n(946)](s,a[n(499)+"th"]);){let{offset:h}=Ca(a,s);s=h;let w={cursor_name:"",cursor:0,service:0},{value:y,offset:E}=e[n(246)](mg,a,s);w[n(341)]=y,s=E;let{value:p,offset:R}=e[n(1636)](Ca,a,s);s=R,w["cursor_n"+n(1271)]=e[n(1124)](Al,a,s,e[n(363)](s,p)),s+=p;let{value:T,offset:N}=e.gZeOR(_g,a,s);w[n(505)]=T[n(1645)](),s=N,l[n(1174)](w)}return l}function Ag(){let a=t;return{frameType:Pa,headers:[{key:e[a(1117)],value:a(451)+a(389)}],payload:void 0}}class kg{constructor(n,s,l){let h=t;this[h(1418)+h(1173)]=n,this[h(421)+h(857)]=s,this[h(1593)+h(393)]=l,this._qosDB=Tl(this["_cursorN"+h(1173)],e[h(1607)])}async[t(1109)](){let n=t;await this[n(1293)][n(1109)]()}async[t(848)+"rs"](){let n=t;if(n(1788)===e[n(1806)])_0x5a151f.textPayload="",_0x1e0816[n(508)](_0x68aa8e);else{if(!this[n(1293)][n(915)])return;let s=this[n(1593)+n(393)],l=await this._qosDB[n(757)]();switch(console[n(508)](e[n(1273)],l),s){case e[n(736)]:return l&&l[n(1629)]?e.gqMtd(Rl,l,0,this[n(421)+"ileName"]):void 0;case n(721):return;case e[n(1665)]:return l&&l[n(1629)]?e[n(561)](Rl,l,0,this["_cursorF"+n(857)]):Ag()}}}async[t(272)](n,s,l){let h=t;return console[h(508)](e.QuLEP,n,s,l),this[h(1293)].set({cursor_name:n,cursor:s,service:l})}async setCursors(n){let s=t,l=e[s(515)](Ig,n);for(let h of l)console[s(508)]("setcursor",l),await this[s(1293)].set(h)}async get(n){let s=t;return e[s(600)](e.CWhYg,s(1380))?(await this[s(1293)][s(644)](n))?.[s(505)]:(_0x5af790[s(1399)](_0x310c10(this),_0x3d6676),zaAFMi[s(1759)](_0x86ac04,_0x3d9e56.get(this)))}async[t(452)](){let n=t;e[n(1205)]===e[n(521)]?(this._dispatchMessageEvent(_0x1423bf),_0x34635c[n(272)](_0x3c7ab2,_0x2a2e94,_0x5c6155[n(1533)].service)):await this[n(1293)][n(452)]()}[t(588)+"rsorFileName"](n){let s=t,l={kMMTE:function(h,w){return h(w)}};if(e[s(1331)]("heVDW",e[s(1772)])){let h={efbeF:function(w,y){let E=s;return CKBiob[E(940)](w,y)}};return function(...w){let y=s;return _0x17ccb5[y(1399)](_0x4c35a9(this),w),h[y(1098)](_0x5e04a6,_0x276547[y(644)](this))}}else this[s(421)+"ileName"]=n}get isReady(){let n=t;if(e.LBZou==="vkAQk")return this[n(1293)][n(915)]}}let Tg=t(794)+t(1505);async function Pl(a){let n=t;if(e[n(1175)](e[n(1492)],e[n(1492)])){if(!this._options[n(1807)+"S"])return null;let{aID:s,fpID:l,messageStrategy:h}=this[n(889)],w=a||Tg;try{return this[n(606)+n(240)]?a&&this[n(606)+n(240)][n(588)+n(740)+"Name"](a):this._cursorManager=new kg(l+"_"+s+"_"+w,w,h),this["_cursorM"+n(240)][n(915)]||await this[n(606)+n(240)][n(1109)](),this["_cursorM"+n(240)]}catch{return null}}else{let{enableAutoAck:s}=this[n(889)],l=e[n(369)](_0x39f663,_0x12c094[n(1533)].headers,n(1574),"1"),h=_0x54125b(_0x27910f.message.headers,n(928),"1"),w=_0x602ad6.call(this,_0x49bdc6);if(e[n(587)](s,l)){let{SeqID:y,LogID:E,service:p,LogIDNew:R,method:T}=_0x27f756.message;this[n(357)]({SeqID:y,LogID:E,LogIDNew:R,service:p,method:T,headers:[{key:e[n(1683)],value:"1"},{key:"ack_id",value:e.XGMpS(R,"")},{key:n(307),value:"0"}]})}h&&!w[n(623)]&&this._dispatchAckMessageEvent(_0x24517a),e[n(1061)](_0x38de0e)}}async function Cg(a,n){let s=t,l=e[s(1716)](an,a[s(1533)][s(788)],e[s(865)],"-1"),h=e[s(544)](an,a[s(1533)][s(788)],e[s(1683)],"1"),w=e[s(1344)](dr,a[s(1533)].headers,e[s(1193)]),y=Number(e[s(445)](dr,a[s(1533)][s(788)],s(262)+"er_ttl"))||0,E=Ta[s(1224)](this,a),p=e.ihAMz(an,a.message.headers,e[s(1106)],"2"),R=e.gZeOR(dr,a[s(1533)][s(788)],"x-msg-cursor_name"),T=Number(dr(a[s(1533)][s(788)],e.moUow));if(E.isQoSAck)return e[s(707)](n);let N=E[s(522)+"sage"]?await Cl[s(1224)](this):null;if(e[s(1412)](a.message[s(341)],0)&&h&&!l||a[s(1533)][s(341)]>0){if(w&&E[s(522)+s(1155)]&&N)return!!!await N.get(w)&&(this[s(1524)+s(312)+s(1088)](a),await N[s(272)](w,e[s(697)](Date[s(1328)](),y))),n();if(p){let G=await Pl[s(1224)](this);if(!G)return this["_dispatc"+s(312)+s(1088)](a),e[s(707)](n);let K=await G.get(R)??-1;if(e[s(1030)](K,T))this[s(1524)+s(312)+s(1088)](a),G[s(272)](R,T,a[s(1533)][s(341)]);else throw new Error("recevied"+s(603)+s(377)+T+(s(1303)+s(1438)+s(1235)+"r ")+K);return e[s(468)](n)}return this[s(1524)+s(312)+s(1088)](a),n()}}async function Rg(a,n){let s=t,l=Ta[s(1224)](this,a);if(!l.isQoSMessage)return e.QZyKc(n);let h=await Cl[s(1224)](this);if(l[s(1307)+s(1559)+"age"]&&l[s(1237)+"s"][s(1629)])for(let w of l[s(1237)+"s"])await h[s(819)](w);e.rVsQW(n)}async function Pg(a,n){let s=t,l=a.message.frameType===vg,h=a[s(1533)].frameType===Pa;if(e[s(392)](!l,!h))return e[s(468)](n);let w=dr(a[s(1533)].headers,e[s(1117)]);if(!w)return e.EvirC(n);let y=await Pl[s(1224)](this,w);if(!y)return e.QZyKc(n);if(l){let E=await y[s(848)+"rs"](),p={frameType:E?.[s(1036)+"e"],SeqID:xe[s(435)+"er"](this[s(1325)]++),LogID:xe[s(435)+"er"](this[s(889)].logIDGenerator()),service:9e3,method:5,headers:E?.headers,payload:E?.[s(1112)]},R=e.ojKlR(S,p);this[s(1601)]&&this._ws[s(1467)+"te"]&&this[s(1601)][s(1398)](R)}if(h){let E=a[s(1533)][s(1112)];E&&y.setCursors(E)}}let Dg=async function(a,n){let s=t;this._isInit=!1,clearTimeout(this[s(1147)+s(1490)+s(1534)]),e.FmWEr(n)},Og=async function(a,n){let s=t;if(!this[s(1601)]||e.KCgju(this[s(1601)][s(1467)+"te"],this[s(320)]))return e[s(735)](n);let{pingInterval:l}=this[s(889)];this[s(448)+s(664)]?.[s(1603)+s(796)+s(803)]();for(let w=0;w<this["_message"+s(1350)][s(1629)];w++){let y=this[s(1593)+s(1350)][w];if(e[s(1685)](this._ws[s(1467)+"te"],this[s(320)])&&e[s(905)](null,y))this[s(1601)]&&this._ws[s(1398)](y),this[s(1593)+"Queue"][w]=null;else break}this[s(1593)+"Queue"]=this[s(1593)+s(1350)][s(1221)](w=>!!w),this[s(1797)+"gTimeoutId"]=e.vWOGp(setTimeout,()=>this[s(1078)](),l),this._dispatchOpenEvent(a),this._isBrowser&&this[s(1601)]&&(this[s(1601)].binaryType=this[s(344)+s(1472)]);let h=this["_endpoin"+s(664)]?.[s(580)+s(1137)+"nt"]();this[s(718)](s(960)+h+s(1581)),e[s(1433)](n)},Lg=async function(a,n){let s=t,l=this[s(448)+s(664)]?.[s(580)+s(1137)+"nt"]();this[s(718)]("open "+l),e[s(745)](n)};class Ng extends Ia{constructor(n){let s=t,l={CSZzK:e[s(1771)],bZWAr:function(E,p){return e.kAtBY(E,p)},FEbtS:function(E,p){return E instanceof p},lCkJb:function(E,p,R){return e[s(497)](E,p,R)},xvRHE:function(E){return e.VfDOk(E)},jUyNt:function(E,p){return e.Cljnv(E,p)},Pnztb:function(E,p){return e.uvGHw(E,p)},yOOIO:e[s(1642)],VRIZy:s(608),Avmac:s(1475),YXVtQ:function(E,p,R,T){return e.hWtXh(E,p,R,T)},jydzf:function(E,p,R){return e.OvjiN(E,p,R)},Pjkpy:s(658)+"reason",ZZrCo:function(E,p){return E+p},owrdS:function(E,p){return e[s(370)](E,p)},cPjXS:e[s(966)],gDKGQ:e.bEYBs,xSncK:s(678),uiVlD:function(E,p){return E===p},IVlHA:function(E,p){return e[s(1774)](E,p)},JkOeQ:e[s(1658)],DeiUo:function(E,p,R,T){return E(p,R,T)},XQSHG:s(1493),bnJTl:function(E,p){return e[s(1528)](E,p)},VopOO:function(E,p){return E&p},eZnBS:function(E,p){return E>p},jQZgG:function(E,p,R,T){return e[s(1713)](E,p,R,T)},sytpM:function(E,p){return E<<p},dbaPr:function(E,p){return E|p},LbLcd:function(E,p){return e.tpnva(E,p)},ZaYSh:function(E,p){return e[s(971)](E,p)},pdqsF:function(E,p){return e[s(1664)](E,p)},dKPnD:function(E,p){return E+p},rLuvn:function(E,p){return e[s(1650)](E,p)},mlAXR:function(E,p,R){return e[s(1781)](E,p,R)}};super(),this["_miniNav"+s(1461)+s(1139)]=!0,this[s(444)+"er"]=cr,this[s(1556)]=Yp,this._isMiniTT=Nn,this._isMiniWX=ri,this[s(1483)+"r"]=ii,this[s(1593)+s(1350)]=[],this._endpointManager=null,this[s(432)+s(872)]=!1,this[s(344)+s(1472)]=e.yZFgY,this[s(1147)+s(935)]=!1,this[s(1147)+s(1490)+"utId"]=null,this[s(637)+s(1356)+s(1074)]=null,this[s(1797)+s(1458)+"Id"]=null,this[s(1325)]=0,this._isInit=!1,this[s(1646)]="",this["_QoSMana"+s(962)]=null,this[s(606)+s(240)]=null,this[s(947)+s(250)]=null,this._protocols=s(1718),this.CLOSED=3,this[s(1547)+"NG"]=0,this[s(320)]=1,this[s(679)]=2,this._onOpen=E=>{let p=s;if(l.Pnztb(l[p(1192)],p(1511)))return typeof _0x41640d===cvGrqL[p(1046)]?cvGrqL[p(1267)](_0x23ecd5,_0x4120e3):(cvGrqL[p(986)](_0x424096,_0x48de55)&&_0x2fedd7(_0x646790),cvGrqL[p(1457)](_0x52a2fa,_0x51f897,cvGrqL[p(1401)](_0x18b5e6))?new _0x1bd52b(_0x5c6512,_0x3b544f):_0x29649f);try{if(l[p(227)](l[p(1734)],l[p(1272)])){let R=this._listeners[_0x3804da];if(R)for(let T=0;cvGrqL[p(286)](T,R.length);)cvGrqL[p(227)](R[T].fn,_0x1d2429)?R[p(298)](T,1):++T}else l[p(1805)](Sl,this,E,[Dg,Og,Lg])}catch(R){let T=l[p(1519)](lt,p(1493),{message:R.message,code:on.OPEN_ERROR,error:R});this["_dispatc"+p(673)+"ent"](T)}},this[s(1764)+"ge"]=async E=>{let p=s,R={QjUwP:"error",ZbFQc:function(G,K){return l.ZZrCo(G,K)}},{pingInterval:T,pingFrequency:N}=this[p(889)];if(l.Pnztb("hi",E[p(776)])&&l[p(833)](l[p(1543)],N)||l[p(227)](p(1141),N))if(l[p(1801)]==="hsPcq"){let G=_0x6849d2[p(327)][p(1443)](_0x4f8583[p(1572)+"et"],kLyetw[p(1582)](_0x4e2704[p(499)+"th"],_0xe0b66c.byteOffset));this[p(860)]&&this[p(860)][p(1398)]({data:G,fail:K=>{let fe=p;this.emit(kLyetw[fe(543)],_0x3529f6(kLyetw[fe(543)],{message:this[fe(1767)+fe(1045)+fe(520)](K)}))}})}else this[p(395)+"ngTimer"](),this.emit(p(1580)+p(795)+"s",l.xSncK),this[p(1797)+"gTimeoutId"]=l[p(1519)](setTimeout,this[p(1078)][p(598)](this),T);if(!l[p(1419)]("hi",E[p(776)]))try{l[p(1241)](l.JkOeQ,l[p(576)])?(_0xfc895[p(493)+p(1754)]=void 0,cvGrqL[p(1267)](_0x5678e9,cvGrqL[p(1245)])):l[p(1503)](Sl,this,E,[fg,lg,Rg,Pg,Cg,ug])}catch(G){let K=lt(l[p(1571)],{message:G[p(1533)],code:on.MESSAGE_ERROR,error:G});this[p(1524)+p(673)+p(823)](K)}},this[s(1496)]=E=>{let p=s,R={MbBBd:"11|3|4|5|0|6|2|9"+p(1435)+"0",bQNnI:function(T,N){return l[p(339)](T,N)},jhhPR:function(T,N){return l.VopOO(T,N)},abzDQ:function(T,N){return l[p(615)](T,N)},jWAjb:function(T,N,G,K){return l[p(1219)](T,N,G,K)},bCmam:function(T,N){return l[p(1134)](T,N)},AOTUx:function(T,N){return l[p(754)](T,N)},sDThc:function(T,N){return l[p(296)](T,N)},mvEBt:function(T,N){return T|N},SdSPi:function(T,N){return l[p(754)](T,N)},zYvEn:function(T,N){return l[p(847)](T,N)},PUIAT:function(T,N){return l[p(296)](T,N)},lxkcr:function(T,N){return l.LbLcd(T,N)},qOCnl:function(T,N){return l.dbaPr(T,N)},tdLHH:function(T,N){return T<<N},gddcP:function(T,N){return l.ZaYSh(T,N)},jhYVc:function(T,N){return l.dbaPr(T,N)},ZgQRF:function(T,N){return T>>>N},wiiJy:function(T,N){return l[p(933)](T,N)},cSyqR:function(T,N){return l.dKPnD(T,N)},TWnjU:function(T,N){return l.rLuvn(T,N)},DoUTp:function(T,N){return l.bnJTl(T,N)}};if(p(882)===p(1610)){let T=R[p(408)][p(1244)]("|"),N=0;for(;;){switch(T[N++]){case"0":_0x38f887=PseXBp.bQNnI(_0x5165da|PseXBp[p(546)](127,_0x2b3f84[_0x3479db])<<14,0);continue;case"1":if(PseXBp[p(1755)](_0x1e24c2+=5,_0x44c921.length))throw _0x3434d9=_0x3654a0[p(1629)],PseXBp[p(1029)](_0x4e78ab,_0x5272ac,10,_0x1d4112.length);continue;case"2":_0x3267e3=PseXBp.bQNnI(_0x2d9aca|PseXBp[p(810)](PseXBp[p(1226)](127,_0x1e236d[_0xf22b2]),21),0);continue;case"3":if(_0x4dcdac[_0x33b758++]<128)return{value:_0x4e66f9?_0x3242c0:PseXBp[p(1777)](0,_0x1221b8),offset:_0x203bf3};continue;case"4":_0x486f5b=PseXBp.bQNnI(PseXBp.mvEBt(_0x475b3b,PseXBp[p(810)](PseXBp[p(1315)](127,_0x190fe6[_0x4da3be]),7)),0);continue;case"5":if(PseXBp.zYvEn(_0x489a47[_0x4d2f07++],128))return{value:_0x4a205d?_0xc2157e:PseXBp[p(604)](0,_0x1f7b9d),offset:_0x1a134c};continue;case"6":if(PseXBp[p(766)](_0xa460d0[_0x479e4a++],128))return{value:_0xc37bbd?_0x1b52f1:PseXBp[p(604)](0,_0x44338b),offset:_0x535d42};continue;case"7":if(PseXBp[p(766)](_0x35460a[_0x76f7c9++],128))return{value:_0x51c41b?_0x1420ea:PseXBp[p(837)](0,_0x2e3eec),offset:_0x11587d};continue;case"8":_0x15efc8=PseXBp[p(1113)](PseXBp[p(604)](_0x7d0dcf,PseXBp[p(1120)](PseXBp[p(1226)](15,_0x3fbe06[_0x321f08]),28)),0);continue;case"9":if(PseXBp.zYvEn(_0x56544b[_0x427b4c++],128))return{value:_0x4e7c87?_0x55255b:PseXBp[p(512)](0,_0x5d607a),offset:_0x69938d};continue;case"10":return{value:_0x49f4d2?_0x290a9d:PseXBp.jhYVc(0,_0x2b3bed),offset:_0x523955};case"11":_0x51df8e=PseXBp[p(1468)](127&_0x71e635[_0x320f63],0);continue}break}}else{let T=this[p(448)+p(664)]?.[p(912)+p(245)+"es"](),N=this[p(448)+p(664)]?.[p(580)+p(1137)+"nt"]();if(T&&!E[p(1533)])if(l[p(833)](p(1047),"nlRmf")){let G=PseXBp[p(1765)](_0x3074aa,8192),K=PseXBp[p(616)](G,1),fe=null,Me=G;return function(ee){let oe=p;if(ee<1||PseXBp[oe(1755)](ee,K))return _0x2c36cd(ee);PseXBp[oe(1755)](Me+ee,G)&&(fe=PseXBp[oe(1037)](_0x2664eb,G),Me=0);let Ye=_0x32b0bc[oe(1224)](fe,Me,Me+=ee);return 7&Me&&(Me=PseXBp[oe(324)](PseXBp[oe(837)](7,Me),1)),Ye}}else{let G=p(957)+N+(p(1740)+p(356)+"es reached");this[p(1524)+p(673)+p(823)](l[p(1457)](lt,p(1493),{message:G,code:on[p(1186)+p(247)+"R"],error:E}));return}this[p(1601)]&&l.owrdS(this[p(1601)].readyState,this.OPEN)&&this["_disconn"+p(984)](),this[p(1524)+"hErrorEvent"](l[p(1114)](lt,l[p(1571)],{message:E[p(1533)],code:on[p(1149)+p(1752)],error:E}))}},this[s(494)]=async E=>{let p=s;this[p(676)+p(422)](),this[p(395)+p(308)](),this[p(480)+p(471)+"rs"](),this._ws=null,this[p(1147)+"Lock"]=!1;let R=this["_endpoin"+p(664)]?.[p(912)+"chMaxTries"]();if(!R&&this[p(931)+p(1484)]()&&!this["_readyCl"+p(872)])if(e.eWNnk(e[p(542)],e[p(542)])){let T=255&_0x2c43a4;_0x1c8416(T,_0x33632a,_0x1e7118+_0x3b877f),_0x1a42f8>>>=8,_0x2b6b44--}else{let T=this[p(448)+"tManager"]?.["getCurre"+p(1137)+"nt"](),N=this[p(889)][p(271)+p(463)+"ptor"](E[p(311)],E[p(1201)]);this[p(1524)+p(1014)+p(823)](wt(p(624),{code:1006,reason:E[p(1201)]||"connecting faile"+p(317)+"wn reaso"+p(1487)+p(381)+T,willReconnect:N})),N&&this[p(1147)]();return}if(e[p(1799)](1e3,E[p(311)])&&this[p(432)+p(872)]){this[p(1524)+"hCloseEv"+p(823)](e.AmtMi(wt,e[p(596)],{code:1e3,reason:e[p(590)]})),this[p(448)+"tManager"]?.[p(1603)+p(796)+p(803)](),this._pingLossCounter?.[p(1615)+p(1084)]();return}if(e.rtzRe(1e3,E[p(311)])&&R){let T=this[p(448)+"tManager"]?.[p(580)+p(1137)+"nt"](),N=E[p(1201)];N||(N=await e[p(746)](ig,this._url)),N="connecti"+p(925)+p(282)+N+(p(1166)+p(1474))+T+(p(1491)+p(760)+p(878)),this[p(1524)+p(1014)+"ent"](e[p(744)](wt,p(624),{code:E.code,reason:N}));let G=p(957)+T+(p(1740)+"ax retries reached");this[p(1524)+p(673)+p(823)](e[p(1274)](lt,e[p(362)],{message:G,code:on["MAX_RETR"+p(247)+"R"]})),this[p(448)+p(664)]?.[p(1603)+p(796)+p(803)](),this[p(947)+p(250)]?.[p(1615)+p(1084)]();return}if(e[p(1744)](1e3,E[p(311)])&&!E[p(1201)]){let T=this[p(448)+p(664)]?.[p(580)+p(1137)+"nt"]();this[p(1524)+p(1014)+p(823)](e[p(881)](wt,"close",{code:E[p(311)],reason:p(348)+p(925)+"d, unkno"+p(862)+p(1487)+p(381)+T})),this[p(448)+p(664)]?.[p(1603)+"pointCon"+p(803)](),this["_pingLos"+p(250)]?.[p(1615)+p(1084)]();return}this[p(1524)+p(1014)+p(823)](E),this["_endpoin"+p(664)]?.[p(1603)+p(796)+p(803)](),this[p(947)+"sCounter"]?.[p(1615)+p(1084)]()},this[s(1570)]=null,this[s(441)]=null,this.onmessage=null,this.onopen=null,this[s(1612)+"econnect"]=null,this[s(1004)+s(621)]=null,this[s(700)+s(1070)+s(1317)+"ct"]=null,this[s(1206)+s(741)]=this[s(1206)+s(741)][s(598)](this),this[s(1206)+s(778)]=this["_handleO"+s(778)][s(598)](this),this[s(1013)+"ageHide"]=this["_handleP"+s(536)].bind(this),this[s(1013)+s(394)]=this._handlePageShow.bind(this),this[s(889)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1523)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(1697)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1665)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:w}=n,y=Array[s(635)](h)?h:e.jFWhu(e.VIPji,typeof h)?[h]:[];if(!y||e[s(459)](0,y.length))throw new Error(s(1220)+s(1321)+"alid url");if(!eg(w))throw new Error("please p"+s(1203)+s(1448)+", WebSocket cons"+s(993)+s(1498)+s(953));Object[s(680)](this[s(889)],n),this[s(448)+"tManager"]=new vl(y,this._options[s(900)+"es"]),this[s(947)+s(250)]=new rg(this[s(889)][s(1101)+s(1354)]),this[s(889)][s(1500)+"cOpen"]&&(this._isInit=!0,this._connect()),this._options[s(1588)+s(1185)+"nged"]&&(this._isMiniTT||this[s(1445)+"X"]?this[s(1308)+"etWorkChange"]():this[s(444)+"er"]&&this[s(1530)+s(464)+"Listener"]())}["_handleO"+t(741)](){let n=t;this[n(889)]["disableA"+n(1652)+"nect"]||this["_readyCl"+n(872)]||this["_handleR"+n(1700)]()}[t(1206)+"ffLine"](){let n=t;this[n(617)+n(851)+"t"]();let s=e.SZxVL(Sa,n(271)+"t",{message:e.RCnla});this["onStopImmediatel"+n(1317)+"ct"]&&this[n(700)+"mediatel"+n(1317)+"ct"](s)}[t(1530)+"balEvent"+t(903)](){let n=t;this[n(444)+"er"]&&window[n(777)+n(903)](e[n(1129)],this[n(1206)+n(741)]),this[n(444)+"er"]&&window["addEvent"+n(903)](e.BNBnV,this["_handleO"+n(778)]),this[n(444)+"er"]&&window.addEventListener(e.GGNke,this["_handleP"+n(536)]),this[n(444)+"er"]&&window[n(777)+n(903)](e[n(483)],this["_handleP"+n(394)])}["_dropGlo"+t(464)+t(903)](){let n=t;this[n(444)+"er"]&&window[n(1032)+n(997)+n(783)](e[n(1129)],this._handleOnLine),this[n(444)+"er"]&&window[n(1032)+n(997)+"ner"](e[n(509)],this[n(1206)+"ffLine"]),this[n(444)+"er"]&&window[n(1032)+n(997)+n(783)](e[n(780)],this[n(1013)+n(536)]),this[n(444)+"er"]&&window[n(1032)+n(997)+n(783)](e.Iapjt,this["_handleP"+n(394)])}["_handleP"+t(536)](n){let s=t;!n[s(323)+"d"]&&(this[s(444)+"er"]&&window[s(1032)+s(997)+s(783)](e[s(780)],this[s(1013)+"ageHide"]),this[s(444)+"er"]&&window["removeEv"+s(997)+s(783)](e[s(483)],this._handlePageShow),this.close()),this[s(444)+"er"]&&window[s(1032)+s(997)+"ner"](e[s(1129)],this[s(1206)+"nLine"]),this._isBrowser&&window[s(1032)+"entListener"](e[s(509)],this[s(1206)+s(778)])}[t(1013)+t(394)](n){let s=t;n[s(323)+"d"]&&(e[s(1624)](s(666),e[s(804)])?(this["_navigat"+s(1484)]()&&(!this[s(1601)]||e[s(938)](this._ws[s(1467)+"te"],this[s(320)])||this[s(1601)][s(1467)+"te"]!==this.CONNECTING)&&this[s(1206)+s(741)](),this[s(444)+"er"]&&window[s(777)+"Listener"](e[s(1129)],this["_handleO"+s(741)]),this[s(444)+"er"]&&window["addEvent"+s(903)](e.BNBnV,this[s(1206)+s(778)])):(!_0x52151e[s(323)+"d"]&&(this[s(444)+"er"]&&_0x3edb4f[s(1032)+"entListe"+s(783)](e[s(780)],this[s(1013)+s(536)]),this[s(444)+"er"]&&_0x1855ff[s(1032)+s(997)+s(783)](s(1263),this[s(1013)+s(394)]),this[s(624)]()),this[s(444)+"er"]&&_0x493ccc["removeEventListe"+s(783)](e[s(1129)],this[s(1206)+s(741)]),this._isBrowser&&_0x464909[s(1032)+s(997)+s(783)](s(326),this._handleOffLine)))}async[t(488)+t(335)](n){let s=t,{fpID:l,deviceID:h,bddID:w,ttwID:y,accessKey:E,aID:p,customParams:R={},enableAutoAck:T,enableQoS:N,QoSLevel:G,env:K}=this[s(889)],fe,Me,ee;this._isBrowser||this._isMiniWX||this._isMiniTT?(fe=location&&e[s(605)]==location[s(976)]?e[s(1167)]:e[s(1051)],Me=n.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),ee=/^wss(.*:\/\/)/[s(1190)](n)?n:""+fe+Me):(fe=e[s(1167)],Me=n[s(288)](/(^http)((?:[s]*:\/\/))/,""),ee=/(^ws)((?:[s]*:\/\/))/.test(Me)?Me:""+fe+Me);let oe=w?e[s(662)]:y?e.UASUx:s(1105)+"d",Ye=w||y||h;if(e[s(527)](!Ye,!oe))throw new Error(e.ANuIA);let cn=e.WspuG==typeof R?await e[s(745)](R):R,Da=K?e[s(474)](ng,K[s(1794)],K[s(660)]):{},si=Object[s(680)]({device_platform:"web",version_code:e[s(1188)],access_key:E,fpid:l,aid:p,[oe]:Ye,xsack:T?1:0,xaack:T?1:0,xsqos:N?1:0,qos_level:N?G:void 0,qos_sdk_version:2,...Da},cn),gs=Object[s(867)](si)[s(294)]((oi,ai)=>si[ai]!==void 0?""+oi+(oi?"&":"?")+ai+"="+si[ai]:oi,"");return ee+s(725)+gs}async[t(1147)](){let n=t;if(!(this[n(1147)+n(935)]||this._readyClosed)){this[n(1147)+n(935)]=!0;try{let s=this[n(448)+"tManager"]?.[n(1425)+n(743)+"ointReac"+n(1791)+n(768)](),{timeoutInterval:l}=this[n(889)];if(s){let w=this["_endpoin"+n(664)]?.[n(580)+"ntEndpoint"](),y=this["_endpoin"+n(664)]?.["replaceB"+n(1476)+"pointAnd"+n(1656)+n(1334)](),E=this[n(448)+n(664)]?.["getCurre"+n(1137)+"ntTriesC"+n(551)]();if(y){let p=n(957)+w+(n(656)+n(1491)+"tries re"+n(1423)+n(699)+n(769)+n(762))+y+(n(1170)+"y"),R=e[n(514)](lt,n(1493),{message:p,code:on[n(1186)+"IES_ERROR"]});this[n(718)](p),this[n(1524)+"hErrorEvent"](R),this[n(1646)]=await this[n(488)+"eUrl"](y),this[n(718)](n(957)+y+" "+E+" times"),this["_removeW"+n(471)+"rs"]()}else{let p="connect "+w+(n(656)+n(1491)+n(760)+"ached");this._debug(p),this[n(1524)+"hErrorEvent"](e[n(650)](lt,e.HsQLM,{message:p,code:on[n(1186)+n(247)+"R"]}));return}}else{let w=this[n(448)+n(664)]?.[n(580)+n(1137)+n(1246)+"ateCount"](),y=this[n(448)+n(664)]?.["getCurre"+n(1137)+"ntTriesC"+n(551)]();this[n(1646)]=await this[n(488)+n(335)](e[n(527)](w,"")),this[n(718)](n(957)+w+" "+y+n(1184)),this[n(480)+n(471)+"rs"]()}if(this[n(1072)])this._isInit=!1;else{if(e[n(321)](e[n(924)],e[n(236)]))return e[n(1577)](_0x488c94,e[n(557)](e[n(708)](e[n(228)](e[n(871)](e[n(919)](e[n(887)],_0x4c9ecc),e[n(1284)]),_0x56023d||1),e[n(1464)]),_0x394672));{let w=Sa("reconnect",{message:e[n(1717)]});this[n(1612)+n(1700)]&&this[n(1612)+"econnect"](w)}}let h=this[n(448)+"tManager"]?.[n(580)+n(1137)+n(1651)+n(551)]()||0;e[n(1179)](h,1)&&await this[n(1330)](e[n(1214)](h,1)),this[n(718)](n(348)+n(1140)+this[n(1646)]+(n(730)+n(443))+this[n(592)+"ls"]),this[n(1601)]=e[n(474)](Qp,{url:this[n(1646)],protocols:[this[n(592)+"ls"]],headers:this[n(889)][n(622)+n(806)+"s"][n(890)+"tpHeader"]},this[n(889)].ws),(this._isBrowser||this._isWorker)&&this[n(1601)]&&(this[n(1601)][n(990)+"pe"]=this[n(344)+"ype"]),this["_addWsLi"+n(723)](),this["_connect"+n(1490)+"utId"]=setTimeout(this[n(1786)+"ut"][n(598)](this),l)}catch(s){if(e.ADYkz!==n(1228))return this[n(1524)+"hMessageEvent"](_0x416a69),_0x2c71c0();throw this._connectLock=!1,s}}}[t(676)+t(422)](){let n=t;e[n(1759)](clearTimeout,this["_connect"+n(1490)+n(1534)]),this[n(1147)+n(1490)+n(1534)]=null}["_clearPi"+t(308)](){let n=t;e[n(570)](clearTimeout,this[n(1797)+n(1458)+"Id"]),e[n(391)](clearTimeout,this[n(637)+n(1356)+n(1074)]),this[n(1797)+"gTimeoutId"]=null,this[n(637)+n(1356)+n(1074)]=null}[t(718)](...n){let s=t,l={StLfW:e[s(1620)],rTobw:function(h,w,y,E){return e.pbQEr(h,w,y,E)},SkCwk:function(h,w,y,E){return e[s(369)](h,w,y,E)},EnXRu:e[s(411)],bEOTH:e[s(985)],MkqVT:e[s(1501)],exeNW:e[s(305)],jaXeq:function(h,w,y,E){return e[s(1208)](h,w,y,E)},ZYpNr:e[s(534)],rOthp:function(h,w,y,E){return e[s(969)](h,w,y,E)}};if(e[s(1128)](s(734),e[s(1497)])){let[h,w]=e.Ftwjj(_0x49fb8c,_0x1f3c30),y=e[s(647)](_0x2dca78,h),E=0;return _0x1c4b64[s(1686)](p=>{let R=s,T=(R(581)+"5|2|4|8|"+R(438))[R(1244)]("|"),N=0;for(;;){switch(T[N++]){case"0":_0x2ba7be[R(508)](ayghJi.StLfW,E);continue;case"1":E=ayghJi[R(792)](_0x29bfe1,y,E,p.service||0);continue;case"2":E=ayghJi[R(569)](_0x4c9fd8,w[p[R(632)+R(1271)]],y,E);continue;case"3":E=ayghJi[R(792)](_0x1fd4f1,0,y,E);continue;case"4":_0x49896e[R(508)](ayghJi[R(595)],E);continue;case"5":_0x1f5d3a[R(508)](ayghJi[R(485)],E);continue;case"6":_0xef7d59[R(508)](ayghJi[R(1104)],p,p[R(341)]);continue;case"7":_0x1f7920[R(508)](ayghJi[R(911)],E);continue;case"8":E=ayghJi[R(1081)](_0x1daafd,p[R(632)+R(1271)],y,E);continue;case"9":_0x2339d6.log(ayghJi[R(1410)],E);continue;case"10":E=ayghJi[R(1782)](_0xc4ff47,_0x3debec[R(435)+"er"](p.cursor||_0xfbc4a0),y,E);continue}break}}),{frameType:_0x251978,headers:[{key:s(1048)+s(1148),value:_0x4c2bd6}],payload:y}}else this[s(889)].debug&&console[s(508)].apply(console,[s(1598)+">",...n])}[t(1417)+t(1087)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:h,reconnectIntervalGrowFactor:w}=this[s(889)],y=l*Math[s(1762)](w,e[s(498)](n,1));return e[s(548)](y,h)?h:y}[t(1078)](){let n=t,s={LQNDa:function(l,h){return e[H(633)](l,h)},XmRao:function(l,h){return l<h},UuUxR:function(l,h){return l&h}};if(e[n(490)](e[n(1370)],e[n(584)])){if(this[n(1601)]&&this._ws[n(1467)+"te"]===this[n(1547)+"NG"])if(e.WYviK!=="ugeQZ"){this[n(395)+n(308)](),this._pingPongTimeoutId=e[n(765)](setTimeout,this[n(1078)].bind(this),this._options.pingInterval);return}else{let l=0,h=0,w;do w=tSFYwp[n(1210)](_0x2ccfd6,_0x4c22cb),tSFYwp[n(525)](l,32)&&(h|=tSFYwp[n(907)](127,w)<<l),l+=7;while(tSFYwp[n(907)](128,w));return h}if(!this._ws||e.flBks(this[n(1601)][n(1467)+"te"],this[n(320)]))return void this[n(1043)+n(1700)]();this[n(1601)]&&this[n(1601)][n(1398)]("hi"),this[n(637)+n(1356)+n(1074)]=e[n(737)](setTimeout,this[n(1043)+"econnectTimeout"][n(598)](this),this[n(889)][n(690)+n(1779)+"val"])}else this.on(_0x4d8f4f,_0x5f1fb5)}["_handleReconnect"+t(959)](){let n=t;if(e[n(1128)](n(1640),e[n(779)])){if(!this._ws)return;this[n(617)+n(851)+"t"](_0x5e39aa,_0x3814de,_0x36eb87)}else this[n(947)+n(250)]?.addCount(),this[n(1676)](e[n(257)],e[n(572)]),this[n(947)+n(250)]?.checkReachMaxCount()?this[n(1043)+n(1700)]():this._ping()}[t(931)+t(1484)](){let n=t;return e.wskHU(e[n(510)],e[n(1337)])?((this[n(1625)+"rs"][_0x4a5638]||(this[n(1625)+"rs"][_0xeee3a7]=[])).push({fn:_0x20e0ac,ctx:_0xf562ae||this}),this):this[n(1374)+"T"]||this[n(1445)+"X"]?this[n(1017)+"igatorOn"+n(1139)]:(this[n(444)+"er"]||this._isWorker)&&this[n(889)][n(1588)+n(1185)+n(733)]?navigator[n(574)]:!0}[t(1043)+t(1700)](){let n=t;!this[n(931)+n(1484)]()||this[n(432)+n(872)]||(this[n(448)+n(664)]?.[n(1603)+n(796)+"fig"](),this[n(947)+"sCounter"]?.["resetCou"+n(1084)](),this._ws?this["_disconn"+n(984)](1001,e[n(1183)],!0):this[n(1147)]())}[t(1308)+t(1798)+t(407)](){let n=t;this._isMiniTT?tt[n(1130)+n(1431)+n(1590)](({isConnected:s})=>{let l=n;this[l(1017)+l(1461)+l(1139)]=s,s?this[l(1206)+l(741)]():this[l(1206)+l(778)]()}):this._isMiniWX&&wx[n(1130)+n(1431)+n(1590)](({isConnected:s})=>{let l=n;this[l(1017)+l(1461)+"line"]=s,s?this._handleOnLine():this["_handleO"+l(778)]()})}[t(1330)](n){return new Promise(s=>{let l=H;e[l(1469)](setTimeout,s,this[l(1417)+l(1087)+"e"](n))})}[t(1168)+"ect"](n=1e3,s="",l=!1){let h=t;this._ws&&this[h(617)+"WebSocket"](n,s,l)}[t(1786)+"ut"](){let n=t,s=this[n(448)+n(664)]?.[n(580)+n(1137)+"nt"]();this[n(718)]("connect "+s+n(656)),this[n(1168)+n(984)](1001,e[n(1207)],!0)}[t(357)](n){let s=t,l=e.xswvC(Gt,n);this[s(1601)]&&e.qLRyJ(this[s(1601)][s(1467)+"te"],this[s(320)])&&(this[s(1601)]&&this[s(1601)][s(1398)](l),this[s(718)](e[s(1756)],n))}[t(480)+t(471)+"rs"](){let n=t;if(e[n(279)](e[n(728)],e[n(728)])){if(!this._ws)return;this._ws["removeEventListe"+n(783)](e.kicsY,this[n(901)]),this[n(1601)]["removeEv"+n(997)+n(783)](e[n(596)],this[n(494)]),this._ws[n(1032)+"entListe"+n(783)](e[n(1310)],this[n(1764)+"ge"]),this[n(1601)][n(1032)+n(997)+n(783)](n(1493),this[n(1496)])}else zaAFMi[n(1016)](_0x497d7e,_0x222871.error),zaAFMi[n(1544)](_0x130b70)}[t(419)+t(723)](){let n=t,s=(n(1775)+"1")[n(1244)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1601)][n(777)+n(903)](e[n(1616)],this[n(901)]);continue;case"1":this[n(1601)][n(777)+n(903)](n(1493),this[n(1496)]);continue;case"2":if(!this[n(1601)])return;continue;case"3":this[n(1601)][n(777)+n(903)](e[n(596)],this[n(494)]);continue;case"4":this[n(1601)]["addEvent"+n(903)](n(1533),this[n(1764)+"ge"]);continue}break}}_wsInstanceClose(n=1e3,s=""){let l=t;try{this[l(1601)]&&this[l(1601)][l(624)](n,s)}catch{}}[t(617)+t(851)+"t"](n=1e3,s="",l=!1){let h=t,w={ArVnS:function(y,E){return e[H(1405)](y,E)},WflKd:function(y,E){return e[H(433)](y,E)},gVOXX:function(y,E){return e[H(1451)](y,E)}};if(e[h(331)](e[h(627)],e[h(627)])){let y=_0x420684[h(372)],E=_0x229042[h(710)],p=_0x15aa5c.limit,R=NJcxHQ[h(1564)](E,_0x5c7522);if(NJcxHQ[h(1059)](R,y[h(1629)])){let T=new _0x494bd8(NJcxHQ.gVOXX(2,R));T.set(y),_0x1fbbbb[h(372)]=T}return _0x32259d[h(710)]=R,R>p&&(_0x5d9a5f[h(791)]=R),E}else{if(this["_clearPi"+h(308)](),this[h(676)+"mer"](),this[h(480)+h(471)+"rs"](),this[h(1793)+h(1164)](1e3,s),this[h(1147)+h(935)]=!1,l&&this[h(931)+h(1484)]()&&!this[h(432)+h(872)]){if(this["_endpoin"+h(664)]?.[h(912)+"chMaxTries"]()){let E=this[h(448)+h(664)]?.[h(580)+"ntEndpoint"]();this[h(1524)+h(1014)+"ent"](e[h(1687)](wt,e[h(596)],{code:1006,reason:h(957)+E+(h(656)+h(1491)+h(760)+h(878)),wasClean:!0}))}else{let E=this[h(889)][h(271)+h(463)+h(1393)](n,s);this[h(1524)+h(1014)+h(823)](e[h(1060)](wt,e.wrwSk,{code:n,reason:s,wasClean:!0,willReconnect:E})),E&&this[h(1147)]()}return}this["_navigat"+h(1484)]()||this[h(432)+h(872)]?this[h(1524)+h(1014)+h(823)](e[h(470)](wt,e[h(596)],{code:n,reason:e[h(590)]})):this[h(1524)+"hCloseEv"+h(823)](wt(e[h(596)],{code:1006,reason:e.yfHic})),this[h(1601)]=null,this[h(448)+"tManager"]?.[h(1603)+"pointConfig"](),this[h(947)+"sCounter"]?.[h(1615)+h(1084)]()}}[t(1524)+"hOpenEvent"](n){let s=t;this[s(1676)](s(1287),n),this.onopen&&this[s(932)](n)}[t(1524)+t(312)+t(1088)](n){let s=t;e[s(983)]===e[s(983)]?(this[s(1676)](e[s(1310)],n),this[s(638)+"e"]&&this[s(638)+"e"](n)):(e[s(473)](_0x2ee27b,_0x25d181,90),e[s(319)](_0x5b531d,_0xc79a62,_0x2599ac))}["_dispatc"+t(366)+"ageEvent"](n){let s=t;if(e[s(278)](e[s(322)],e[s(322)]))return this[s(1293)][s(870)+s(967)]();this[s(1676)](e[s(669)],n),this[s(1004)+s(621)]&&this["onReceiv"+s(621)](n)}[t(1524)+t(673)+t(823)](n){let s=t,l={ttccn:function(h,w,y){return e[H(328)](h,w,y)}};if(e[s(942)](e[s(532)],s(1499)))this[s(1676)](e[s(362)],n),this[s(441)]&&this[s(441)](n);else return _0x1879c2[s(372)][HdAGkB[s(1371)](_0x4ba792,_0xdc6b54,1)]}[t(1524)+t(1014)+t(823)](n){let s=t;this[s(1676)](e[s(596)],n),this.onclose&&this[s(1570)](n)}get[t(990)+"pe"](){let n=t;return this[n(1601)]?this[n(1601)][n(990)+"pe"]:this["_binaryT"+n(1472)]}set binaryType(n){let s=t;this[s(344)+s(1472)]=n,this[s(1601)]&&(this[s(1601)][s(990)+"pe"]=n)}get[t(843)+"nt"](){let n=t;return this[n(448)+n(664)]?.[n(580)+n(1137)+n(1651)+n(551)]()||0}get[t(1724)+t(1305)](){let n=t;if(e[n(1243)]!==e[n(1243)])return{frameType:_0x1c619e,headers:[{key:n(1048)+n(1148),value:e[n(899)]}],payload:void 0};{let s=this[n(1593)+n(1350)][n(294)]((l,h)=>(l+=h&&h[n(499)+"th"]||0,l),0);return e[n(1311)](s,this._ws?this[n(1601)][n(1724)+n(1305)]:0)}}get extensions(){let n=t;return this[n(1601)]?this._ws[n(945)+"ns"]:""}get protocol(){let n=t;return this[n(1601)]?this[n(1601)][n(976)]:""}get[t(1467)+"te"](){let n=t;return this[n(1601)]?this[n(1601)].readyState:this[n(889)][n(1500)+n(1709)]?this.CONNECTING:this[n(702)]}get url(){let n=t;return this._ws?this[n(1601)][n(599)]:this[n(1646)]}close(n=1e3,s){let l=t,h=(l(1265)+l(426))[l(1244)]("|"),w=0;for(;;){switch(h[w++]){case"0":this[l(395)+"ngTimer"]();continue;case"1":if(!this[l(1601)])return void this._debug(e[l(1242)]);continue;case"2":this[l(676)+l(422)]();continue;case"3":this[l(1606)+l(464)+l(903)]();continue;case"4":if(this._ws[l(1467)+"te"]===this[l(702)]||this._ws[l(1467)+"te"]===this[l(679)])return void this[l(718)](e[l(325)]);continue;case"5":this[l(914)+l(962)]?.[l(452)]();continue;case"6":this[l(617)+l(851)+"t"](n,s);continue;case"7":this[l(432)+l(872)]=!0;continue}break}}async[t(1398)](n,s){let l=t;if(e[l(1602)](e[l(264)],e.RecMJ)){let h=!!this[l(889)][l(1807)+"S"];if(!h)return{enabled:h,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let w=e[l(1713)](_0xf06b02,_0x159b9b.message[l(788)],l(262)+l(373),"2"),y=w&&_0x9cdf3(_0xc6d774[l(1533)].headers,l(262)+l(1796)+"ck","1"),E=w&&_0x1a870c(_0x5811de[l(1533)][l(788)],e[l(334)],"1"),p=E?e[l(313)](_0x397886,_0x557bd7[l(1533)].headers,l(262)+l(1521)+l(885))?.split(",").filter(_0x21911a)||[]:[];return{enabled:h,isQoSMessage:w,isQoSAck:y,isAckCleanupMessage:E,ackMsgIds:p}}else{if(e[l(1633)](null,n))throw new Error(e.LShPX);e[l(1633)](e[l(560)],typeof n)&&(n=JSON[l(920)+"y"](n)),e[l(1525)](e[l(1e3)],typeof n)&&!e[l(376)](n,ArrayBuffer)&&!(n[l(327)]&&e[l(479)](n.buffer,ArrayBuffer))&&(n=JSON[l(920)+"y"](n));let h=await e[l(1135)](kl,n),w=e[l(1667)](tg,n),{method:y=0,service:E=this[l(889)][l(341)],logID:p=this[l(889)]["logIDGen"+l(640)](),headers:R=this._options.headers,payloadEncoding:T=this[l(889)][l(1551)+l(1211)],payloadType:N=this[l(889)][l(1394)+l(1472)],logIDNew:G=this[l(889)][l(469)+l(1304)][l(930)+l(693)+l(360)+"ew"]?e[l(1424)](i,this[l(889)]["logIDNew"+l(1304)][l(685)]):""}=s||{};if(!E)throw new Error(e.BDBsv);let K={SeqID:xe[l(435)+"er"](this[l(1325)]++),LogID:xe[l(435)+"er"](p),service:E,method:y,headers:R,payloadEncoding:T instanceof Object?T[l(299)]?T[l(299)]:"":T,payloadType:e.xrQlo(N,Object)?N.type?N.type:w:N||w,payload:h,LogIDNew:G},fe=e[l(1342)](Gt,K);return this[l(1601)]&&e[l(1628)](this[l(1601)][l(1467)+"te"],this[l(320)])?(this[l(1601)]&&this[l(1601)][l(1398)](fe),this[l(718)]("sent",K)):e.xSRAq(this._messageQueue[l(1629)],this[l(889)]["maxMessa"+l(630)+l(415)])?(this["_message"+l(1350)].push(fe),this[l(718)](e[l(1169)],K)):(this["_message"+l(1350)][l(1751)](),this._messageQueue[l(1174)](fe)),{seqID:this[l(1325)],logID:p,logIDNew:G}}}async[t(271)+"t"](n){let s=t;if(e[s(1331)](e[s(1459)],e[s(713)]))return new _0x5e8468(e[s(809)](e[s(1473)](e[s(891)](_0x4f3ac8[4],24)|e[s(1406)](_0x55d52c[5],16),e[s(665)](_0x655783[6],8)),_0x11e3ea[7]),e.ESWmp(e[s(1730)](e[s(1390)](_0x59ae8d[0],24)|e[s(315)](_0x38e84e[1],16),_0x32e9f9[2]<<8),_0x397f3c[3]),_0x16d5f0);{let{url:l}=e[s(807)](n,{}),h=Array[s(635)](l)?l:e.arTBy(e.VIPji,typeof l)?[l]:[];n&&Object.assign(this[s(889)],n),h&&h.length?this[s(448)+s(664)]=new vl(h,this._options[s(900)+"es"]):this[s(448)+s(664)]?.[s(1603)+s(796)+s(803)](),this[s(947)+"sCounter"]?.["resetCou"+s(1084)](this[s(889)][s(1101)+s(1354)]),this[s(432)+s(872)]=!1,this._ws&&e[s(1301)](this._ws[s(1467)+"te"],this[s(702)])?this[s(1168)+"ect"](1e3,e[s(782)],!0):(this[s(1072)]=!0,this[s(1147)]())}}async[t(1177)](){let n=t;e[n(1546)](e[n(249)],e.AAfMp)?this[n(1676)](e.HsQLM,_0x5c7728(e[n(362)],{message:this["_formatErrorMess"+n(520)](_0x2cf6b2)})):!this[n(1147)+n(935)]&&(this[n(448)+n(664)]?.[n(1603)+n(796)+"fig"](),this[n(947)+n(250)]?.[n(1615)+n(1084)](),this[n(432)+n(872)]=!1,this._isInit=!0,this[n(1147)]())}["addEvent"+t(903)](n,s){this.on(n,s)}[t(1706)+t(1088)](n){let s=t,{type:l}=n;this[s(1676)](l,n)}[t(1032)+t(997)+t(783)](n,s){this.off(n,s)}[t(1644)](){let n=t,s={iULif:function(l,h){return e.wQXQc(l,h)},mryJV:e[n(1108)],FhJze:e[n(1444)],dOhBR:e[n(257)],tHgfZ:e[n(572)],HezeU:function(l,h){return e[n(1630)](l,h)}};return new Promise((l,h)=>{let w=n;if(s[w(1063)]("NVTjS",w(1758))){if(!this._ws)return;this._ws[w(777)+w(903)]("open",this[w(901)]),this[w(1601)]["addEvent"+w(903)]("close",this[w(494)]),this._ws["addEvent"+w(903)](w(1533),this[w(1764)+"ge"]),this[w(1601)]["addEvent"+w(903)](w(1493),this._onError)}else{this[w(395)+w(308)](),this[w(1797)+"gTimeoutId"]=setTimeout(this._ping[w(598)](this),this._options["pingInte"+w(1249)]);let y=()=>{let p=w;s.iULif(l,s[p(449)]),this[p(742)](s[p(573)],y),this[p(742)](s.dOhBR,E)},E=()=>{let p=w;h(s[p(275)]),this[p(742)](s[p(573)],y),this[p(742)](s.dOhBR,E)};this.on(s[w(573)],y),this.on(w(1580)+"e_timeout",E),this[w(1078)]()}})}}})(),ze[B(1495)+"oseEvent"]=Oe[B(1495)+B(1649)],ze[B(703)+B(516)]=Oe.CustomErrorEvent,ze[B(1703)+"e"]=Oe[B(1703)+"e"],ze[B(1088)]=Oe.Event,ze[B(1657)]=Oe[B(1657)],ze["Frontier"+B(1714)+B(954)]=Oe[B(1673)+"MessageE"+B(954)],ze[B(1714)+B(954)]=Oe[B(1714)+B(954)],ze[B(1725)+"t"]=Oe[B(1725)+"t"],ze[B(654)+B(1743)]=Oe.ReconnectEvent,ze[B(1172)+B(1649)]=Oe[B(1172)+B(1649)],ze[B(1481)+B(516)]=Oe[B(1481)+B(516)],ze.createMessageEvent=Oe[B(642)+B(1397)+"nt"],ze[B(1439)+B(293)]=Oe[B(1439)+B(293)],ze["createRe"+B(921)+B(954)]=Oe[B(477)+B(921)+B(954)],ze["decodedF"+B(1162)]=Oe.decodedFrame,ze["encodeFr"+B(1271)]=Oe[B(873)+B(1271)];for(ta in Oe)[B(1495)+"oseEvent",B(703)+"rorEvent","ErrorCode",B(1088),B(1657),"Frontier"+B(1714)+"vent",B(1714)+"vent","OpenEvent","Reconnec"+B(1743),B(1172)+B(1649),B(1481)+B(516),B(642)+"ssageEvent",B(1439)+B(293),B(477)+B(921)+"vent","decodedFrame",B(873)+B(1271)][B(1731)](ta)===-1&&(ze[ta]=Oe[ta]);var ta;Object[B(385)+"operty"](ze,B(1095)+"le",{value:!0})});import{existsSync as o1,openSync as a1}from"node:fs";import{mkdir as c1}from"node:fs/promises";import{dirname as d1}from"node:path";import{fileURLToPath as l1}from"node:url";function f1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function el(t=Z()){return o1(t.libEntry)?t.libEntry:l1(new URL("../index.ts",import.meta.url))}async function dp(t={}){let e=t.paths??Z(),r=t.entryOverride??el(e),i=f1(e,process.env.COZE_BRIDGE_LOG_MODE);await c1(d1(i),{recursive:!0});let o=a1(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=st(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[us]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return u1.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var u1,us,fa=rt(()=>{"use strict";Zt();ne();Re();u1=j("spawn-daemon"),us="COZE_BRIDGE_DAEMON"});import{spawn as cI}from"node:child_process";import{mkdir as dI,unlink as lI,writeFile as uI}from"node:fs/promises";import{dirname as fI,join as hI}from"node:path";function ei(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function xI(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${ei(r)}</key>
|
|
21
|
-
<string>${
|
|
20
|
+
`+n)}function sr(t,e,n,i,o,a){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,sr),t.emit("wsClientError",d,n,e)}else as(n,i,o,a)}});var Xx=ae(Me=>{"use strict";var N=$;(function(t,e){let n=$,i=t();for(;;)try{if(-parseInt(n(1466))/1*(-parseInt(n(403))/2)+-parseInt(n(1182))/3*(-parseInt(n(461))/4)+-parseInt(n(1163))/5+parseInt(n(513))/6*(parseInt(n(589))/7)+parseInt(n(509))/8*(-parseInt(n(371))/9)+-parseInt(n(856))/10*(-parseInt(n(821))/11)+parseInt(n(873))/12===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(aa,122381);var TS=Object[N(951)+N(980)],CS=Object[N(1832)+N(788)+N(1412)],$x=(t,e)=>function(){return t&&(e=(0,t[{HBNkm:function(o,a){return o(a)}}.HBNkm(CS,t)[0]])(t=0)),e},DS=(t,e)=>{let n=N,i={xAWMo:function(a,d,u,f){return a(d,u,f)}};for(var o in e)i[n(702)](TS,t,o,{get:e[o],enumerable:!0})};function RS(){return Gx||(Gx=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function PS(){let t=N;return Hx||(Hx=[IDBCursor[t(497)+"e"][t(504)],IDBCursor[t(497)+"e"][t(1080)],IDBCursor[t(497)+"e"][t(1080)+t(1554)+"ey"]])}function OS(t){let e=N,n={yWTCu:e(621),XrTtY:e(1503),BCjrv:function(o){return o()},wdPKQ:"error",dSZRu:function(o,a){return o(a)},mMcMp:function(o,a,d,u){return o(a,d,u)},ZoMRO:e(1296)},i=new Promise((o,a)=>{let d=e,u={EHSqB:d(1296),plfME:n[d(1207)],dBSPO:function(w,S){return n[d(480)](w,S)},YqnGm:function(w){return n[d(551)](w)},HOiXu:function(w,S,_,b){return n.mMcMp(w,S,_,b)}},f=()=>{let w=d;t["removeEv"+w(729)+w(1473)](u[w(1803)],x),t[w(1192)+w(729)+w(1473)](u[w(419)],g)},x=()=>{u[d(849)](o,Ut(t.result)),u.YqnGm(f)},g=()=>{let w=d;if(n.yWTCu===n[w(978)])throw _0xf7903f=_0x424c4c.length,u.HOiXu(_0x43a59d,_0x3b4f79,10,_0x904b5d[w(374)]);a(t[w(1532)]),n[w(551)](f)};t["addEvent"+d(496)](n[d(784)],x),t[d(1809)+d(496)](n.wdPKQ,g)});return i[e(1792)](o=>{let a=e;o instanceof IDBCursor&&Jd[a(1876)](o,t)})[e(936)](()=>{}),sa[e(1876)](i,t),i}function $(t,e){t=t-312;let n=aa(),i=n[t];if($.EOchYx===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",w="";for(let S=0,_,b,I=0;b=f.charAt(I++);~b&&(_=S%4?_*64+b:b,S++%4)?g+=String.fromCharCode(255&_>>(-2*S&6)):0)b=x.indexOf(b);for(let S=0,_=g.length;S<_;S++)w+="%"+("00"+g.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};$.nwDMWD=o,$.NQMudI={},$.EOchYx=!0}let a=n[0],d=t+a,u=$.NQMudI[d];return u?i=u:(i=$.nwDMWD(i),$.NQMudI[d]=i),i}function LS(t){let e=N,n={AgwpN:"mfoOu",HqvJY:function(o,a){return o(a)},eMpZV:e(1194)+"or",qQXEM:function(o){return o()},IDeBX:function(o,a){return o!==a},wbTzw:e(1432),TWeJH:e(1311),OTwpv:"abort"};if(ia[e(1660)](t))return;let i=new Promise((o,a)=>{let d=e,u={HvMkt:function(f){return f()}};if(n[d(317)](n[d(945)],n[d(945)]))return _0x1342d8[d(1071)]||_0x122d86.errNo?("message: "+(_0x497ce9.errMsg||"")+d(834)+(_0x2640ac.errNo||""))[d(429)]():_0xed06d[d(588)+"y"](_0xf2316a);{let f=()=>{let w=d;t[w(1192)+w(729)+"ner"](w(1311),x),t[w(1192)+"entListe"+w(1473)]("error",g),t[w(1192)+w(729)+w(1473)](w(1507),g)},x=()=>{let w=d;u[w(618)](o),u[w(618)](f)},g=()=>{let w=d;w(1499)===n[w(681)]?(n.HqvJY(a,t.error||new DOMException(n[w(1416)],n.eMpZV)),n.qQXEM(f)):this._listeners={}};t[d(1809)+"Listener"](n[d(1772)],x),t[d(1809)+d(496)](d(1532),g),t[d(1809)+d(496)](n[d(668)],g)}});ia[e(1876)](t,i)}function NS(t){oa={lyuHS:function(i,o){return i(o)}}[N(688)](t,oa)}function MS(t){let e=N,n={IaSAS:function(i,o){return i(o)},obcZU:function(i,o){return i(o)},TqAng:function(i,o){return i===o},vGgHH:function(i,o){return i in o},HcIgg:e(1638)+"oreNames",RuFSO:function(i){return i()}};return n[e(396)](t,IDBDatabase[e(497)+"e"][e(445)+e(1236)])&&!n[e(943)](n[e(1293)],IDBTransaction[e(497)+"e"])?function(i,...o){let a=e,d=t[a(1653)](n[a(375)](cs,this),i,...o);return Vd[a(1876)](d,i[a(1268)]?i.sort():[i]),Ut(d)}:n.RuFSO(PS)[e(409)](t)?function(...i){let o=e;return t.apply(cs(this),i),Ut(Jd[o(645)](this))}:function(...i){let o=e;return n.IaSAS(Ut,t[o(426)](n[o(1557)](cs,this),i))}}function BS(t){let e=N,n={gWfps:function(i,o){return i===o},HvreA:function(i,o){return i instanceof o},TFOTX:function(i){return i()}};return n[e(947)](typeof t,e(1264))?MS(t):(n[e(643)](t,IDBTransaction)&&LS(t),Vx(t,n[e(491)](RS))?new Proxy(t,oa):t)}function Ut(t){let e=N,n={JFRUZ:function(o,a){return o>>>a},lBaCU:function(o,a){return o>>>a},libcs:function(o,a){return o|a},FqssE:function(o,a){return o<<a},QiXHL:function(o,a){return o>>>a},gafxM:function(o,a){return o===a},Tkxeu:function(o,a){return o===a},Smjsq:function(o,a){return o<a},klrPc:function(o,a){return o<a},Gmzcy:function(o,a){return o<a},GbSik:function(o,a,d){return o(a,d)},IeGlq:function(o,a){return o+a},TcwDF:function(o,a){return o&a},RjquX:function(o,a){return o>>>a},MwwrZ:function(o,a){return o+a},AhaHK:function(o,a){return o!==a},WtMDE:function(o,a){return o&a},vhZKj:function(o,a){return o>>>a},YFiyL:function(o,a){return o+a},uCcvE:function(o,a){return o|a},ejIzz:function(o,a){return o&a},uTLJC:function(o,a){return o>>>a},IdVqn:function(o,a){return o&a},pKJcH:function(o,a){return o+a},CZhEL:function(o,a){return o|a},hHDki:function(o,a){return o&a},fZOfj:function(o,a){return o|a},DrcGG:function(o,a){return o&a},bQTPo:function(o,a){return o+a},Riyft:function(o,a){return o|a},ChBcf:function(o,a){return o&a},CkKzJ:function(o,a){return o|a},AhpkK:function(o,a){return o instanceof a},UHtDg:function(o,a){return o(a)},yTSpM:function(o,a){return o(a)},kffyO:function(o,a){return o!==a},cFHBA:function(o,a){return o===a},cwJMs:"nMgBU",FHaog:e(1458)};if(n[e(845)](t,IDBRequest))return n[e(657)](OS,t);if(na[e(1660)](t))return na[e(645)](t);let i=n[e(1091)](BS,t);if(n.kffyO(i,t))if(n[e(908)](n.cwJMs,n.FHaog)){let o=n[e(740)](_0x3778fa[e(1422)],0),a=n[e(1800)](n[e(1842)](n[e(740)](_0x6758e5.low,28),n[e(576)](_0x5a034a[e(407)],4)),0),d=n[e(1821)](_0x2f2d75[e(407)],24),u=n[e(663)](0,d)?n.Tkxeu(0,a)?n[e(1348)](o,16384)?n[e(1276)](o,128)?1:2:n[e(1146)](o,2097152)?3:4:n[e(1146)](a,16384)?a<128?5:6:n[e(1348)](a,2097152)?7:8:d<128?9:10,f=n[e(920)](_0x5f23d7,_0x52d5ed,u),x=_0x341527[e(1449)];switch(u){case 10:x[n.IeGlq(f,9)]=n[e(1157)](n[e(654)](d,7),1);case 9:x[n.MwwrZ(f,8)]=n[e(1687)](9,u)?128|d:n[e(1860)](127,d);case 8:x[f+7]=u!==8?n[e(1842)](n[e(1515)](a,21),128):n[e(1860)](a>>>21,127);case 7:x[n.YFiyL(f,6)]=u!==7?n[e(604)](n[e(1821)](a,14),128):n[e(1123)](n[e(654)](a,14),127);case 6:x[f+5]=n.AhaHK(6,u)?n.uCcvE(a>>>7,128):n[e(1768)](a,7)&127;case 5:x[n[e(674)](f,4)]=n.AhaHK(5,u)?128|a:n[e(776)](127,a);case 4:x[n[e(769)](f,3)]=n[e(1687)](4,u)?n[e(1419)](n.vhZKj(o,21),128):n[e(1790)](o>>>21,127);case 3:x[n[e(1698)](f,2)]=n[e(1687)](3,u)?n[e(1878)](n[e(654)](o,14),128):n[e(1534)](o>>>14,127);case 2:x[n[e(728)](f,1)]=n[e(1687)](2,u)?n[e(783)](n.lBaCU(o,7),128):n[e(609)](n[e(654)](o,7),127);case 1:x[f]=n[e(1687)](1,u)?n[e(1137)](128,o):127&o}}else na[e(1876)](t,i),sa.set(i,t);return i}var Vx,Gx,Hx,Jd,ia,Vd,na,sa,oa,cs,jx=$x({"node_modules/idb/build/wrap-idb-value.js"(){let t=N,e={IsIKm:t(1686),DqyJk:t(846),HVroU:t(515),UHxPS:"pageshow",MjUgZ:function(n,i){return n instanceof i},HKRpb:function(n,i){return n===i},oHxqI:t(1881),GgyCG:function(n,i){return n===i},SokmJ:t(1638)+t(1855),ClyVL:t(1125),aHOav:t(501),DlLDh:function(n,i){return n(i)},ZvLpP:function(n,i){return n||i},ndGSQ:function(n,i){return n!==i},znpDX:t(1037),IHIdR:function(n,i){return n===i},GTGVL:t(1312),cHCCN:function(n,i){return n===i},uEWam:function(n,i){return n in i}};Vx=(n,i)=>i[t(938)](o=>n instanceof o),Jd=new WeakMap,ia=new WeakMap,Vd=new WeakMap,na=new WeakMap,sa=new WeakMap,oa={get(n,i,o){let a=t,d={tLJJe:e.IsIKm,PjZtw:e[a(1550)],CTpTu:e.HVroU,xUmsx:e[a(857)]};if(e[a(818)](n,IDBTransaction))if(e[a(1731)](a(1881),e.oHxqI)){if(e[a(422)](i,a(1312)))return ia[a(645)](n);if(e[a(1731)](i,e.SokmJ))return n[a(1638)+"oreNames"]||Vd[a(645)](n);if(i===e[a(362)])return a(501)===e[a(627)]?o["objectSt"+a(1855)][1]?void 0:o["objectSt"+a(477)](o["objectSt"+a(1855)][0]):new _0x5f323e(_0x1560e3,{code:_0x139628,reason:_0x599a6d,wasClean:_0x2cc7a5,willReconnect:_0x51ca1})}else this[a(633)+"er"]&&_0x266b50["removeEventListe"+a(1473)](d[a(1691)],this[a(1598)+a(1073)]),this[a(633)+"er"]&&_0x281229[a(1192)+a(729)+a(1473)](d[a(1133)],this[a(1598)+a(334)]),this._isBrowser&&_0x421a69[a(1192)+"entListe"+a(1473)](d.CTpTu,this[a(1796)+"ageHide"]),this[a(633)+"er"]&&_0xebd161[a(1192)+a(729)+a(1473)](d[a(747)],this[a(1796)+"ageShow"]);return e.DlLDh(Ut,n[i])},set(n,i,o){let a=t;if(e[a(312)](e[a(531)],a(1037))){let d=this._qosDB[a(495)+a(1278)+"nc"](this[a(1302)]),u=_0x5c8dbf[a(1148)](e[a(659)](d,"{}"));return _0x56a08c[a(1712)](u)}else return n[i]=o,!0},has(n,i){let o=t;return e[o(818)](n,IDBTransaction)&&(e[o(573)](i,e[o(427)])||e[o(1324)](i,o(1125)))?!0:e[o(1160)](i,n)}},cs=n=>sa[t(645)](n)}}),Jx={};DS(Jx,{deleteDB:()=>zS,openDB:()=>FS,unwrap:()=>cs,wrap:()=>Ut});function aa(){let t=["Fdf8mhWY","BxLczNa","vuzYDxu","ENnuy3G","sxbpCxi","y29Kzq","CgzTqKm","DMHAs2O","CNzOCey","tePsD0G","C3rVCcbPBw0","AxnmB25N","sNDjv2y","x0vysvnu","CePTu0i","ywWGy3vYC28","ywXty29Wzq","uKvprfK","Chv0","B2rHvLG","x3DZ","txfdrhG","Aw50zwDLCIa","CM92AwrLihC","zxjYB3i","rwrQAvK","rhjJr0C","AevlCLu","BxnN","EMHozKC","DgvZDa","ze9TAgW","z2v0qwXS","C2v0q3vYC28","AeDWEK8","DMfTCwu","A2v0ignVBNm","uNvLuLm","CNnVCKzPBgu","CMvZzxrdB3u","ugXsruS","uvb6qvi","rhf5sMS","C3vIyxjYyxK","y3jLyxrLrxi","x3DZsw5ZDge","uhjPBwfYEuS","CvnVCfG","yxv0BW","B2jJwLu","twjPtNq","tu9izgK","tvDlB3G","A1zwy3i","BMv3vMvYC2K","CMvHzfvjBNq","y2H5BNK","wvLTuvG","yw1L","EgnWt0C","yxKSig5LDhC","CLztA0m","tKHvtwi","BgLZDgvUtMu","qLfsqNa","ANb1su4","CYbHBhjLywq","BuDJzw4","yM5KDgK","CvDRA3K","C0vPAK8","tu5Ar2O","uKfpwMC","Cgf5Bg9Hzfq","x29Uq2XVC2u","zv9ZDwnJzxm","zMLUza","vwfey1a","CMvHC29U","rLHYufu","AefJA01LC3m","tfrzqu4","zvjwt1u","tNf5Au4","ywrK","vxHcB0O","quTst3a","twrjrLC","zejgque","s3vMAgW","x2HHBMrSzu8","CLj1wwm","CKPhD3O","s3z2Cee","uMvHzcbWyxm","ELzjEgS","t2PJB0S","AenSB3nLrxy","qLjQyvC","y2uGBM90igK","sMzUA2u","wgjXq04","C3vZC20","qKvhzLG","Curdv3K","uefTD2e","vuvXwwW","yMLUza","tunUt2C","q29UzMLN","uLjpuG","tg9NsurozxC","q0Xpu0ve","yNrAvw4","rgTLt1K","x2HHBMrSzvi","zxn0qxm","wLbbyNK","AunUEhG","DgLxwxi","AxnszwfKEq","zgvJB2rLzey","qNvJzMy","q0vlqKK","s2TOvgu","AeD4z2y","Dgv4DfbHEwW","Bg9N","CNnVCL92ywW","B25szwnLAxy","B2jQzwn0u3q","D3jPDgu","BezSDxnO","yxjYyxLIDwy","Cgf5Bg9Hza","CwLAvNq","C2XPy2u","m3W0Fdb8mxW","sKThwLq","qw1VDw50","Durxs1y","vvbKDvG","y2vZC0HHBMq","wLP5rvq","m3WWFde","y2fSBa","y29UBMvJDa","tfLMC3u","DNjesxK","u0rbDNa","BwLSChm","zLfLwgu","AgfZ","rfPpCgq","v2LUzg93","t1fpvLi","CKfJt1a","uKrKvLy","su5tvefova","q3vZDg9Trxi","z2v0q3vYCMu","DwrAyvm","AMj4r1u","zxjFywnRx20","rffoC3K","uvv0uLm","Avztveu","ENPNyKi","suLZz0O","DxbNCMfKzw4","t3r0qxC","x29UugfNzu4","whvJCNy","C3vIC3rYAw4","DxjS","s3jcvxm","ugvmtuO","wMzsA0K","B25SAw5L","qwHHseS","Ef9MCM9UDgK","u3nPtvy","ChDuEM4","DeXksMu","BMnVzgLUzW","C3rLBMvYCW","DgLLCKPtt04","B25pCgvU","ExLQt3i","Agv1zgu","txD3CLO","zKLAz0u","DfvoA3e","ihrVihjLDhi","zxPmAg8","CvD1q3C","CxvqrKq","y3jLyxrLrwW","sxnms1G","Cgu6ia","lcbTyxGGCMu","BwLUAvbYB2C","x2n1CNnVCKy","v0jzrLK","DMfSDwvZ","zw5JB2rLrNi","ywLMEgi","BvjmquS","y1b2Efm","DgfjuwW","u0r0y1G","u3rYyxrLz3K","B25tDgfYDfi","z2v0q3vYC28","zMLSDgvY","t29rvLy","qK9muwS","rxn0z0W","B3vUDa","yvDrvNi","mxWW","rvjst1i","D2vsALC","seTsCgi","tK55A1O","vvrXtLO","y2XVC2veqG","zM9YrwfJAa","DgDfq3u","B3H0ywG","AvHVB2i","B21Luui","zwTtCfK","sxLSALm","uxLSu1i","txjxC3e","EfHysgW","CNzHBfzHBhu","uuruz0m","wwjZzwe","sKHLtg0","x2rPC3bHDgm","r1LJCLa","Dvndzvi","rxDlBMy","wunbD08","y2XVC2uSihC","tKv0BLK","EvjLy29UBMu","mxW1Fdb8nhW","zfDervm","DwHiy3q","z0DkCLq","AxnrB1nby2S","yNvMzMvY","yw5Nzq","rxjYB3jdB2q","reH1s1y","zgD2Ew8","x2rYB3bhBg8","DvrmsKm","BgLUzw5V","BMrWB2LUDfq","q0nJq1q","vfDLsKG","Bg9NsurozxC","BvbWtK0","D09sufC","Bwv0Ag9K","x2n1CNnVCK0","DMvyzNC","Cg9PBNrbBMq","Cg93","v1D6vNC","DeHUyLu","tgvkDva","uunPr0C","uLPTBu0","BeXqtLi","y1fryLC","rev5Bvu","CgfNzxnOB3C","AeHeA2K","BMzmCLa","DgHLBG","EuzXyLe","y1rnvgO","CMvHzhLtDge","x2HHBMrSzva","v2HmChq","zgvSzxrL","t2jQzwn0","BejHq1u","zgvS","CgL0txi","ruHtCui","wvbjAhG","yNL0zu9MzNm","Dg9cExrLC0i","y3vYCMvUDeK","ufvmB1u","ywrKrxzLBNq","EMn1y28","txjYqLm","Dw50","Aw5KzxG","DKHpzMy","ugHhtMS","CeDjBvq","swH3BwC","z2fWDvG","C3rYAw5N","DMjLywO","uwLyseW","zeTJDey","sMPYs0K","s2TmtKq","y3jLyxrLt2i","sxLTv1e","DhjPzxm","CMvQzwn0","yurXEKq","ysbTDxn0igi","y3bvs0q","z2v0t3DUuhi","x2rPC2nVBM4","EfjbAgG","rLjptLrjrvi","vuTYrgK","uMTmu0e","A21eCwq","wLjztum","v0rpCvq","z3fkEe4","BgLIy3m","DMzZuui","ywjIzhy","BerKqwy","ANreB0m","EwPdAfq","twj5y08","B3jRig9MzMW","rMzfsge","zfjfCvC","tLPvsxe","A0nLCNm","yKr5suO","B3jLtMfTzxm","ywDLu2HVDW","qxDtwhm","zeHHvNa","AwHWvve","v3rnreu","q3vZDg9Tq2W","wNHJtei","Dev2zw50","DvLrthG","yxbgqKe","zg1ovgS","DMvUDa","vuHQzeW","BwvKAwf0zwW","y291BNq","t1nQDuq","y29UBMvJDgK","AKLmzgW","zwvNtuC","yMn6zNu","C2v0","A2XQru0","zLPpzMO","zw5fDMvUDa","re5RyMK","vxzkAwS","zxj2AwnL","rLvnBKi","yKnwrNm","BMDLza","Duf5swS","t2H4zgS","uKTLB2W","DMvYC2LVBG","zwzqq3O","nhWXFdb8mNW","CMvUDevUzha","BMrhu1e","yKnwELu","zw5HyMXLvhi","A3r6AMC","zvLJu2W","surLqLG","CKL3q0u","vw5PBxbSzw0","u2zPzeS","y3r4","igzHAwWSig0","B2LKvNe","BNDeB20","zgLZywjSzue","y3ruAw1LB3u","yxGGCMv0CMK","AMHXyKm","CeL3C1y","wuLHuMK","y3zdC28","BM1hrgW","y1jushO","zMzmAw5L","BMCGzMfPBgu","C2vYDMLJzq","DgfIyxnL","ywXPzcb1CMW","BNDpqKu","C2v0sxrLBq","whzmtLO","BxnNsuq","AuDoqKi","r0DHAeC","AgfUz2u","r1rrs1e","BNrbBMrvCgq","r2npthK","Ec11C2uT","z2jot3C","t0jgugC","B25dBg9Zzq","EvnntxG","y29UBMvJDeu","DxbLCfO","DffJB24","rLPIvxK","r1L6sw8","zKjZs0K","Dgv4Dc9WBge","zw5KCg9PBNq","q2X5vKW","pxv0zI04","DNDVvfi","DhjPzxmGCMu","AK9Hq2S","vuPdEe4","x3bHDgHlzxK","x2XPC3rLBMu","Ae9cvu0","odu5mdy4AeTYtvvg","AePvC1K","yxbWzw5Kq2G","BgvUz3rO","swftqvm","x3jLywr5q2W","BM9iA3O","ugfksgK","shDzDLm","DvPyA3m","zhvyvee","teDjzgq","D1flwuC","D2LSBfjLy28","s3fcD3O","v1jQtwy","A1voDKy","Bhv4wuO","zxjFBxnNAwq","uu9Jz1C","vgLTzw91Da","AKfZy08","rxH2tMy","CMvJzxzPzwq","Eu1Qq1y","vhfbBMC","sejPEhy","BNruCMLLC0m","BKfereu","wK11v0S","r0Tlvem","x2LZsw5PDa","otCYq29vq3vO","CgvYC2LZDgu","DMDquM0","AxnbCNjHEq","AgLNAa","C3rsBNe","Aw5JBhvKzxm","A3zLA2y","Dxrjza","C2vYDMLJzs0","CLjXEgW","zwvKzwq","zujfCuC","y05kEMC","AMLbBMq","zxjFCw9Z","CgXMtuu","x3jLBw92zvC","tfr1q04","r2D5q0C","uxPPrvG","q0jYBK4","o2nOyxjZzxq","yxbWBhK","r1rhvKW","AvnUsuu","DhjPBq","AMvYEhy","B3zOzNu","nhWYFdz8nxW","rgvKAwnHDgu","zcWG","BwvY","BKnlB2C","wuzYzvu","zNjVBu51Bwi","CMvZB2X2zq","AhrJAwy","zwrPyxrLBhK","AwDHDg9Yt24","rvrIv0q","zxmGCMvHy2G","DhjHBNnHy3q","D3jPDgvvAw4","rvHhC0q","vMv1CMO","q2HJve4","vuXbENm","vNv5uLO","twvZC2fNzuu","vwf1vxa","EhjcBK4","Eurvyxa","z0vLyvm","A2PNy1K","zNjVBuHHC2G","x2LUAxrqCM8","t2zRq0u","mJiXmtqWvxjKzNzt","igXHCMDLCIa","C0z5sKS","qNjZzNq","Dhz3reK","tufyx1jfvfi","C2HPzNq","q0Xpu0LorW","vgfN","q3nLEK4","r3zsB08","Aw5N","yxrHlcbKyxq","vvDlwfm","zMLSzw5HBwu","twLwwhK","B3jL","mdaWma","BfLfBK0","zfnAuNu","B3bLBG","t3LHBLy","yvD3sxy","Cg9W","rezJAMW","C2fNzq","zgfcAgi","sKnMB2C","u2vXsuq","y3Dlt0K","vezpvfG","x2rItMfTzq","qwTlvuS","CMvJzwL2zwq","z2v0u3rVCMe","tgLZDgvUzxi","ChjVDg90Exa","BNrfBMrWB2K","t25SthO","CNz4r3O","uMjRyKG","AgP4tvu","v0fVywu","ywr2yw5Jzq","rLDt","t0zisKy","t3DItLG","rwvJzhK","og91s0v0DG","ENH2BNi","sxbuu2m","zM9Yy2u","mtG5otz5y2PgA0y","z3fIEKC","CgfNzwHPzgu","q1fUr3u","u25JDwC","zhneBMe","zKzTChe","sK55CNq","Cgf5Bg9Hzeu","DxrVuMvJB24","B3v0sw50zxi","zgLZCgf0y2G","CYbWyxjHBxm","Avf5zuy","BeLNrxG","C1vxA3m","BwLZzq","CMvWBgfJzq","EM5WrfG","quPPug4","BMCGDxjSoIa","Aw9Ul2PZB24","uw1MDMy","sMfrwxG","nhW1Fdj8m3W","y3vYC29Yx2y","wMP4BLK","AMHOC0m","CMLLC0nVDw4","B2nRzxq","rKLmrv9ot1q","zMLN","v0f4Chq","BMfTzq","ign1CNnVCIa","ywnRtxnNswq","Bxf1BgW","yLjrr0S","qKnQCNy","BhzWCM4","x29Ut3bLBG","Aw5Lza","qKPQuge","D2PiuwK","BwvZC2fNzv8","Ec1TC2CTy3u","rvHSD28","x194x21Zz18","BeHHBMrSzxi","DwP3ruy","AMH6EfG","y3vYC29YlNm","t3bLBKv2zw4","B3zpExK","zxH0zw5ZAw8","tgvTr2C","zNjVBunOyxi","BxDRv1m","Cg9PBNrdB24","v25My04","suHjzfi","yw51Ce1LC3m","wMDdq08","rNfZC0u","ywDLrxzLBNq","DgfYz2v0","Ae9Wzw5fDMu","x19LC01Vzhu","ww9Ot2q","ChrVCG","whjzrhi","EMvsEMS","BM5Ly3q","rgPyy1m","wuvosei","C3rYAw5NAwy","mZKYChzPsw9O","y3jLyxrLtwu","DeLK","t3jmA2G","y29UC3rYDwm","DKD1yKu","De1HBMfNzxi","BgPPuve","rLDrAfe","yMLUyxj5vhK","zxrxB3jRq2G","mNWXFdb8nhW","C2vYDMvYvgK","uNzOvgu","DxLhBhG","DunJDKu","rKfvAgq","DgPADhG","ChvZAa","DwHOuwS","q2Hcy2y","CIb0DhDjra","Du9SyKW","yxnJCMLWDa","qLbJDuq","BuHyDu4","C3bSAxq","uhPgy24","qNjPzgDL","shznA3q","ANblEve","x2LZv29YA2u","D3LcwNO","DeLUDgvYy2u","zM9yB24","z2v0qwXSs2u","C1bhv1i","x2n1CNnVCK4","yuHpyxy","t1bftG","x21LC3nHz2u","rw5WB0e","AgvKtwf4uMu","twLlA0W","x2LZqNjVD3m","sxfrt1i","ywXSq3vYC28","Dg9Y","zgvSzxrLrge","y09Wzw4","CLzHBhvLCW","CgLUz0XVC3m","uNLYCxe","x2LZtM9Kzq","shzYzue","DxrMofDYAxq","z2v0","rxD2whi","q05Tque","tK9wq0q","C1jftge","yw5eD2K","qM1uDuO","shjHBfq","A2v5CW","uMPXDvG","tLzqA0m","q2fhBvu","vuH0rgC","zvvYBa","wNzmCfa","zxq9DxrMltG","yw5ZzM9YBvq","lcbxzwjtB2m","z2fMEe0","yxv0B21HDgK","zMX1C2HfEha","tKfusvzfx0u","BxfgAfa","t1r3Chy","CwTvAMS","Dhr3Awq","ihn1y2nLC3m","u2vYDMLJzvC","tKHdDxK","wuzPEuW","CMfNzvn5BMm","sffbu1K","zfPnEei","AuLKrNm","BML0AwfSAxO","wfD1A3q","qwD3Ce4","v2fLAxe","wMvtBfC","D0nPyMS","sKP1zwy","rgnmthG","AKDWAhu","BhL1sfm","rLDzrMG","rhPtC2O","suPrCuq","y050Eu4","AK9oCgG","uwvPqNu","t1bftL9fuLi","ihrPBwvZ","q3b5EeC","tvHYs3a","C2vUza","sfziDxm","x2DLDeLUDgu","Eefxtw8","ywnRDxbfBMq","vuP5yMG","ve1pquq","CgLUz0LUDgu","rwrVyuW","Ew5nwKe","DujHze0","y2nyvxa","uwPgBKS","vfjpzgO","z2vtEw5J","B25nzxnZywC","C2PWC0C","Dg9oDw1Izxi","u0zPEvK","v0vVz3O","wxjcrhi","u29Swfq","CNzHBa","qMrLD3u","zw50","vvvoqM8","vxrUD2G","lcbOB3n0BMe","rNjVBNrPzxi","yLfuug8","zw50tgLZDgu","y25uu1G","EvruEMO","wLP3tMi","B25JBg9Zzq","x2TLEvbHDgG","Dg9mB3DLCKm","rxrdr2q","wwzTvKu","x3fVC0rc","rgXcv0C","sKzsvvO","CYbPBNn0yw4","vMXgEfi","tefdv24","Dg9iyxnO","zNjVBujPDhm","A21iq1y","EfvTC3G","z2v0sxrLBq","z2vY","weXqCfu","t3Luq04","Dg9cExrLC0W","AMj2AMS","CMvZzxrfBMq","Aw9UvgLTzw8","AxnFywnR","BwvZC2fNzq","AKTSEMW","uNDkDwC","AvrfALy","Be9hC0u","zwn0","shf3ywq","whHRwxC","ywzSD0K","CgjICdi","ywDL","zKjNEgS","CeTky0G","wwrJu0u","v0DHCeq","x3vYBa","yMr1Ee4","D3jkA1u","CgLUz1rPBwu","swrwCw4","sM5Xu2C","B2nRzxrtDwm","DgLezKO","y2HLy2Tszwe","ywnOzwq","EvjlAw8","uML5zNq","wM9nuK8","zcWGDw5RBM8","y0z5r0O","B2nRzxrgywK","B3bLCNr5tMe","zxjFCw9Zx2e","x3bPBMC","BMrLEa","r0TywLK","BwfW","A2v5","tgHrrxC","u3HSz2K","uML1weG","zNb4tLy","ywDLsgLKzq","ExbL","vvjwCw8","CMrQugW","B3nLza","uMvJB25Uzwm","zxjFDhrS","BuzOuMi","CMfTzq","qu9zufO","x25HDMLNyxq","zLDArMi","vMHKr1e","x2zVCM1HDeu","BMv4DcGPigm","BuPUuhq","vhz6tuS","AgvHzgvYCW","wfzACe0","twPvz1O","DKLbDLu","u2nOqNK","nJzqs1n5r20","qxzkB0u","zMTxAeS","zvncCe0","x3bPBMDmB3m","vwnYwNa","y3jLyxrLt3a","tKXcDLi","DMXnvNi","DuLMs1m","zfPXsgK","wKThrva","vLfLCfO","ignVzgu6ia","igzPzwXKoIa","sfjAtfu","txPpEMq","B0TwtNq","DhL4EwW","zfDMwxK","u2HHCMvKv28","tM16uMC","zNjHBwvuExa","yu5ms2K","qwHWA0S","B2zMBgLUzq","v1fXzeu","zhrTruW","zejtue8","zxjHDg9Y","AKnzrg0","wwPkuvy","rNP0wNe","CuvMEe0","B2XKvMvYC2K","ntqYmZbwBvPxDvq","vuH4ufm","uvLSteu","AxnrB1nnzxm","AxmGDw5Kzwy","yMXVy2TLza","DuPkBfK","EeL4Bfq","uLPTu0K","zenMEue","Bg9IywXty28","q1LUz0q","BNLpBeS","zwnVBM5Ly3q","Bff5zeq","B3zKrMG","sejbAfa","ndi1ntmYBKTWExrX","m3W0Fdf8mhW","BvP6ANu","txzkwgG","vhLOtuW","sMfuyMq","CM92AwrLigi","CMv0CNLdB3u","Ag5Ozxa","wvPoq0q","Bwf4twvZC2e","v29HEKO","yKfSAKm","zgv2AwnLx2K","x2nYzwf0zvm","CMTLCKDSB2i","x2jPBMfYEvq","DgvmB2Djre4","BNvTyMvY","vxjSyNm","CMvWBgfJzui","yKzQvKC","zNfTEuG","vKrLsNK","BgvY","Aw1LCYbPBIa","x3nLBMrby2S","t2Dzv0i","s0zcChK","yMLUyxj5","z2u6ia","BNrLCG","Axb0ug4","svDgt0i","Aw47y2HHCNm","y0ziqKe","DeXmtLq","vfvYEhe","z01Iv0W","u05LrwK","t3LZzgy","wNHcwKi","wNnguMK","rgfRq1u","BgTOy2S","rwLRrhi","y3fXt1O","r2jtAwS","C2vUDa","z1fVu0O","A1n0yxr1C0m","rMvet2e","zxDAA1i","thzsuwi","tg1bD1C","BNfKyNO","Dxrwvvq","Dg9cExrLCW","DLfAA0q","sMfgCLy","z2vjtu8","EKr1s3a","B3rkt2G","y2f0y2G","r0zbvNG","C29Tzq","tK1bCw0","suvtx0vsuK8","wef5Ce4","Evj6rva","DKDNseG","Cwndtfu","D2juENC","qNHJAhq","z1DMChm","x2rLC3rYB3K","CKP0sei","wNb4A1e","zgvMAw5Luhi","zw5XDwv1zq","B2zM","DgjfwK8","zMz3rMu","zKzLy0i","DvzUB0W","BvjNDMS","ywrKq291BNq","qwnHt00","qMLbzNm","rhjRwhG","tu5suwe","zKrZCgW","uw1ArxG","AgXgywK","B3jpBMXPBMu","wvv3yLa","u3jUBhu","DvrqBxi","zxDXDhe","y2XLyxi","CgLUz09Uy2u","z1rMqLe","BwfUDwfSihi","yM5Pv3q","ChjVy2vZCW","whjuDfK","EKTczLK","B3bLCNr5","D1rgEMK","t3PlEfa","wKzhwMG","x29UtwvZC2e","DeLYDhq","u251BuC","D3nZoI8V","zfDVCMTLCKC","C2v0u3rVCMe","txPbEe4","ywzL","zgHhCLa","z01fs3i","zNn0ANq","BgfcEfq","C2nYAxb0","CMvZzxruCMK","y0jjrMS","vfP3y1K","rvPuAva","tw1LBLu","DcbSAw1PDa","BgLUzq","v2vPEgLUsLm","zw1pq1u","ALnZDLG","zxjYtM8","C3fLD04","D0HyDuK","y2HnyxHdB3u","zv90Aw1LB3u","q1rWs0m","u1fctM0","x2fKzfDZtgK","ihzHBgLKigq","mNWZFdr8mxW","s050zLi","wuXZz2i","BMCGB3iGyw4","wezOtxa","qMXouK4","qKHTwfG","qvHny3C","BhrUzwS","wg5fy1C","ALLOD2K","DhLWzq","twLZC2LUzYa","uLfzENC","B3jRzxjhBg8","D1b5D2y","B25ozxr3B3i","BM9Uzv9UB24","u01gsLi","q09oveLovuu","yMj1uvq","y0TJC2q","x0rctMfTzq","rgnmvhe","AM9PBG","DMvY","Dfffy2y","t25jCe0","t0Hrufa","zgvIDwC","A25YveS","Dg9VigXHCMC","DwL2z2m","CMvKDwnL","t05lwNa","A0rnyLG","B2zMC2v0","FdL8n3W0Fdy","x3jLy29UBMu","qvfmA0m","zgf0yq","BxbPBKG","D2nfr0e","yxKSihrYEsa","s2PUA1a","yw1LoIa","CufXEuy","zuPnwhK","rxzLBNq","vMziAhi","s3n5zvC","zLbxzKy","wM96CNG","zuzXsw4","z1Dyvfa","zxjYtxnN","wefHs0K","BKXPBMu","aaaaaaaaaaa","B2fWzM4","x2LZtwLUAvC","BMH5sLC","DMfS","CwrPzMO","y29UDgLUDwu","wfnOrLe","z3zhENa","tLLYEue","x2LUAxrhBg8","C3riyuq","zw1PDa","CMvXDwLYzwq","C1DiD1a","Bwf4uMv0CMK","z2v0s2v5","EvrtCe0","t0f3tMK","z1rPBwvVDxq","yLDbshK","x29WDgLVBNm","rwHPA0O","BwzeqKO","CvHWDvi","ANbgsNC","BKnIB00","AxjLza","D1vQtMO","Aw5KzxHpzG","ywnRx2nVzgu","CgXLyxnLiha","rvnqBfa","tg9Nsuq","uhvSswu","zxzWBeq","qvnurue","t2PhCLC","x2rLyNvN","vvnlExe","yM9KEq","Bg1fq0y","x3nVy2TLDa","AgfZt3DUuhi","z2vrDwv1zuW","y29UBMvJDca","AwXK","uMfmBeK","rKfysLe","zwPjENO","BKTMtxa","C3rVCMu","B25tDg9Wsw0","AxPXyMS","tMP4ufq","ihrPBwvVDxq","uKnJsNy","CM92AwrLige","EfDdBvC","ugPADhC","AhzdEg0","AgnIu0O","vujVu1G","q2TlEKO","qMzkvhm","rMn0Dvi","tuvtu0fhrv8","y29SBM8","BgLTAxq","yKLQt20","yNzPrg8","t2njtM4","r216y3K","zgjNtey","CgfYC2u","y3vYDMfSDwu","zvrNy0K","ChjVDg9JB2W","q29Kzq","vhfPyw8","y2HLy2TdDxi","Cufwwxa","AvzUz1y","vgn3rey","thHtq0m","AMTZrvO","Duvxyw0","DgT6rvu","CwDiD2i","otaXntCWB21iC1nh","quvXuxa","ywX3yxLZ","EhrdwMu","D2Xuuei","BNjeqMi","zvLgrLG","q2vqswK","Cw9Zx18","Efrurw52","yxnL","ENPXyM8","qu1UAfm","yxrLq291BNq","twvOv2G","BfrPBwvVDxq","Axf3y0C","y3jLyxrLuMu","uvb4z0G","nNvKqLr4qq","x2LUAxq","CMfUzg9T","wfzotxm","yLvmtNe","yMP3ALG","wxbOqLK","AKvsBKS","q291BNq","zufJAW","CMvTB3zLrxy","BwvZC2fNztO","qwjVCNrfCNi","zxbqDLK","Afrmzxa","qwLJq3q","vxbKyxrLq28","BwLUzW","vMzLshe","qM5oAhm","x2nSzwfYugK","AwrI","t25mCNi","s0f2q1u","yxnZAwDU","D2rqs1e","x2vUzhbVAw4","tw9KDwXL","rxHXywe","rgjqy2S","r3rSrMG","t0fxteO","DgLTzw91Da","x3DHAxq","vKDzB2K","uLzxs3q","BML0EwO","B1jzvwW","zevcBNe","C3nHz2vfDMu","EezUru0","tKDFrvjst1i","A2TdtMu","Bwf4tg9ZC0m","y3jLyxrLq2W","zNjVBNrPzxi","txnRv2y","mxWWFdj8nhW","y2HHCKnVzgu","zu5IwKS","x29UvgLTzw8","Aw5PDcbrB1m","y3vYC29Yx24","BMvLzf9Hy2S","Aw9U","y3PzDhy","wLHUDe4","x21PBMLoyxy","sKfcwgG","q1Hbq2G","BgfLExG","q3niEM4","C0nVDw50zxi","C0jf","B3v3yLi","uenmseu","x2nSzwfYvgK","CMvTB3zLq2G","CunNA20","y29UDgv4Da","BMrWB2LUDca","C2vUzf9Hy2S","rvzpv0W","tg9JAW","wxHoy2G","zw5HyMXLuw8","wNrnreu","sKvNuwu","DvjID0W","ENDHvKS","uvrbEMO","l3DZl3yY","zNvUy3rPB24","DLfSEKO","B2fK","yNL0zuXLBMC","C29YDa","C0XPC3rLBMu","x2LUDgvYDMe","t1vSEvq","y3vZDg9Tshq","B25pwve","B3bLBKrc","tMfTzq","A2XYugm","wvvSEvq","z2vjBMzVu3K","ywnOzwqSihC","qKvmDxK","vNnbDNq","DgLTzw91DcW","Dgv4Dc9Qyxy","zNjVBuj5Dgu","qM9wD3i","ywXSzwqGBxu","B1DPAgq","tKP2Cgu","x3bPBMDqB24","D29iug8","z0fJEKm","vw53z3q","sgnjz2C","C0Xf","zK5hCMC","C3vJy2vZCW","zgjsEuy","vKDgtLy","uxvLDwu","yw5Hz2vY","wxPMr2i","x3bYzwzPEa","sfndBvi","C2DPza","sgvdzKq","wuDpEhO","vuL1ENq","r3fdwvq","BxDzq1y","zwrIBNa","y29TCgXLDgu","zg9Uzq","BMzmzKS","D1fgAMi","AKPbrfO","BMXIuMq","yKXcu1m","Be5iu3y","B1zgEeC","AwvYsMq","y2XVC2u","u0HuqNq","AMvJDfn0B3i","y0Hdq04","vKHJD2q","CeTxwvq","t3PJzwW","C2HmuLe","y29UBMvJDfm","r3fewLq","rxjbCfC","mdaWmdaWmda","B3bLBIa","D3rftxO","q01rrMm","BvPPAMe","D3m6lY8","DwXbDMO","C3rHCNq","t1Dyrge","zgrjrcWGzgu","uNvdsxK","y3fYEeG","wgjOAem","Dfrdu2W","AvnABeu","ywXSB2nvBNm","u21QC3e","BMnLq2XVC2u","reiGzMfPBgu","y29Uy2f0","twfsA1m","zw5JB2rPBMC","Bg9Nsurhzw4","t0vQrLC","x2nVBM5Ly3q","q0Pgvwi","CMvZDwX0","zxHWB3j0CW","v3PwANu","vLDkwNi","zhrzsLy","v3z5txq","sM5LsLO","C3bSAwnL","swfKDu4","sgv1CMe","CKT0vhy","sM9nyxO","Eejwt0m","CNjVCK1LC3m","Derlvfi","mtb8ohW5Fde","u1vJy1C","wK5UBuu","CMfTugfYyw0","B25TzxnZywC","z29PBMCGyxC","y3vYCMvUDeu","y05jq3u","DMDHCeG","B2LUDfjLywm","ELvzC2K","yM9hBvG","CvDYu0e","mxW0","AMv5te0","CePlENG","u29wr0m","Dg9tDhjPBMC","BM93","CMvJB25Uzwm","EfvZzuvUDG","ihrYEsbYzwm","q1P2AgG","sxfLzhy","q1Dfr2u","qw1TtK4","B25VCgvU","zhjyAee","DMPYB0q","shjjtg0","qNvMteO","EvfNENK","t25qCgC","yMPSr0q","B3nLrxzLBNq","AevYCM9Yrxy","x1fVu01HBMe","vhblqwK","DMfSDwu","BwvZ","teHnwfe","DgLUzYbZzxi","sxjlAe8","zu1WwLy","wuHrAfO","BMvJDa","q1POruW","BxzLuNa","zMPzwxy","Bg93","CMvHzg9UBhK","q3Hru3K","B25LCNjVCG","v2r4quy","CM9YrxzLBNq","yMfJA3vWigu","BevlzwK","vfPQEhC","q09otKvdveK","CxPjD3G","AwXLtMfTzq","Ec1TC2CTCw8","Eej2B1q","C2nSwgu","vfHTsve","sLnptLa","s3LjCLK","x2LZtwLUAvq","v2vIu29JA2u","u1rcqNy","x3nLCuLK","vfHps2e","AeHJuhO","sfLlBM0","AM9grxm","D2fZq2XLyw4","yNL0zxm","vevTsLC","CgnoBei","v2rWseG","CwzzuwK","zwLWzeW","CgDzCKS","Dw5KzwzPBMu","Dw5ZAwDUzwq","svPbAKy","DgHHBIbSB2m","yxn4seW","y2HnyxHuCMK","icSG","AfvvEha","AeLJqLO","zMDpswy","odD1uKrXv2m","rhzABfa","y09Yvem","ChbL","Dg5byuS","yw1Lu3bHy2u","tNbXtKK","BMvY","uwPZsMG","yMfSrxzLBNq","t0vYEM0","Avzyr2S","uMvWuu4","Aff2Ae8","Ae1LC3nHz2u","wurIuwC","yNvMzMvYzwq","u0XXshe","Bwu6ia","Dhj1y3rVCIa","yLLyBue","shLHzxi","CLLssNy","ELvNuLm","x29UrxjYB3i","DLHMyLG","Bw9Swhe","zMTjwum","CxjMqxy","BMDuAw1LCG","B2vJDxK","qujmEK0","CgLUz19VBMm","BwzVt3u","y2jct0i","x3bYB3rVy28","B2v0B0S","AfHTBgK","y3vYC29Y","EgTIr1G","D1zxzxK","ywjVCNq"];return aa=function(){return t},aa()}function FS(t,e,{blocked:n,upgrade:i,blocking:o,terminated:a}={}){let d=N,u={QylSR:function(g,w,S,_,b){return g(w,S,_,b)},JwIWf:function(g,w){return g(w)},Brsft:function(g,w){return g(w)},xrBnN:"close",qAqyF:"versionchange",Srnlu:function(g,w){return g(w)},fgOIf:"blocked"},f=indexedDB[d(481)](t,e),x=u[d(969)](Ut,f);return i&&f[d(1809)+"Listener"](d(1677)+d(414),g=>{let w=d;u[w(1742)](i,u[w(1520)](Ut,f[w(1358)]),g.oldVersion,g[w(1562)+"on"],u[w(464)](Ut,f[w(445)+w(1236)]))}),n&&f[d(1809)+d(496)](u[d(1465)],()=>n()),x[d(1792)](g=>{let w=d;a&&g[w(1809)+w(496)](u[w(454)],()=>a()),o&&g[w(1809)+w(496)](u[w(1062)],()=>o())}).catch(()=>{}),x}function zS(t,{blocked:e}={}){let n=N,i={KkhTe:function(a,d){return a(d)}},o=indexedDB[n(637)+n(337)](t);return e&&o[n(1809)+n(496)](n(861),()=>e()),i[n(1632)](Ut,o)[n(1792)](()=>{})}function Wx(t,e){let n=N,i={bFjVG:"readwrite",uhhQk:n(1423),yyjOr:function(f,x){return f instanceof x},zzqbo:function(f,x){return f in x},oidVq:function(f,x){return f===x},xFnEM:n(1819),rKtTv:function(f,x){return f!==x}};if(!(i[n(1696)](t,IDBDatabase)&&!i[n(1174)](e,t)&&i[n(323)](typeof e,i[n(1222)])))return;if(ra[n(645)](e))return ra[n(645)](e);let o=e[n(530)](/FromIndex$/,""),a=i[n(1368)](e,o),d=Zx[n(409)](o);if(!(o in(a?IDBIndex:IDBObjectStore)[n(497)+"e"])||!(d||Yx[n(409)](o)))return;let u=async function(f,...x){let g=n,w=this.transaction(f,d?i[g(894)]:i[g(608)]),S=w[g(1125)];return a&&(S=S[g(1813)](x[g(467)]())),(await Promise.all([S[o](...x),d&&w[g(1312)]]))[0]};return ra[n(1876)](e,u),u}var Yx,Zx,ra,US=$x({"node_modules/idb/build/index.js"(){let t=N,e={FVaGK:t(537)+t(1728),WhLpt:t(645),hvCxm:t(1540),mwYCV:t(1870),Tqiao:t(1526),CePIi:t(1592),dsDna:t(1798),YIaRi:t(972),LACWn:function(o){return o()}},n=e.FVaGK.split("|"),i=0;for(;;){switch(n[i++]){case"0":NS(o=>({...o,get:(a,d,u)=>Wx(a,d)||o[t(645)](a,d,u),has:(a,d)=>!!Wx(a,d)||o[t(1660)](a,d)}));continue;case"1":ra=new Map;continue;case"2":Yx=[e[t(1797)],t(1090),e[t(1134)],t(624)+"ys",e[t(1309)]];continue;case"3":Zx=[e[t(1153)],e[t(1170)],e[t(518)],e[t(330)]];continue;case"4":e[t(743)](jx);continue;case"5":jx();continue}break}}}),qS={idb:function(t){let e=N;t[e(1359)]=Promise[e(439)]().then(()=>(US(),Jx))[e(1792)](function(n){return n})}},Kx={};function zt(t){let e=N,n={LeJuP:function(a,d){return a!==d}};var i=Kx[t];if(n[e(1783)](void 0,i))return i[e(1359)];var o=Kx[t]={exports:{}};return qS[t](o,o[e(1359)],zt),o.exports}zt.d=(t,e)=>{let n=$;for(var i in e)zt.o(e,i)&&!zt.o(t,i)&&Object[n(951)+n(980)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=N;zt.o=(e,n)=>Object[t(497)+"e"][t(1117)+t(980)][t(1653)](e,n)})(),(()=>{let t=N,e={gAczC:t(1456)+"d",NHCuy:t(580)+"le"};zt.r=n=>{let i=t;e[i(1291)]!=typeof Symbol&&Symbol[i(1390)+i(469)]&&Object[i(951)+i(980)](n,Symbol[i(1390)+i(469)],{value:i(1209)}),Object[i(951)+"operty"](n,e[i(673)],{value:!0})}})();var Re={};(()=>{let t=N,e={yjChT:function(c,r,s){return c(r,s)},pitMr:function(c,r){return c!==r},iSZlE:t(864),bndti:function(c,r){return c(r)},rvxGz:function(c,r){return c+r},BoVwr:function(c,r){return c+r},XVNMs:function(c,r){return c*r},PhGNk:t(1753),PaJHi:function(c,r){return c(r)},iGNBB:function(c,r,s){return c(r,s)},lEKei:function(c,r){return c+r},tvwDI:function(c,r,s){return c(r,s)},XFhMp:function(c,r){return c+r},czREm:t(478),OnfLd:"ffff",dZMxB:function(c,r){return c(r)},MNRQa:function(c,r){return c(r)},dbgLF:t(1332)+t(1332)+"00000000"+t(1332),pGImT:function(c,r){return c|r},MzAxN:function(c,r){return c<<r},gMbWL:function(c,r){return c<<r},jerxv:function(c,r){return c|r},mfDBJ:function(c,r){return c|r},PeLMJ:function(c,r){return c<<r},LhQEw:function(c,r){return c<<r},sPGWR:function(c,r){return c>r},gqJxN:function(c,r){return c<r},dWDES:function(c,r){return c>r},mGcen:function(c,r){return c!==r},IqQOR:"Ryrqq",qAVYp:function(c,r){return c!==r},rRqxl:function(c,r){return c-r},ABLzM:function(c,r){return c<r},MOHdi:function(c,r){return c===r},lmECF:t(1817),YeiVm:"wjHQi",XbqCN:function(c,r,s){return c(r,s)},DFcjl:function(c,r,s){return c(r,s)},SLqHq:function(c,r,s){return c(r,s)},QziEX:function(c,r,s){return c(r,s)},WAoae:function(c,r){return c>>>r},DcLTq:function(c,r,s){return c(r,s)},yFqbQ:function(c,r){return c&r},EXGsD:t(1028)+t(1087)+" field: "+t(794),eNbZK:t(1028)+t(1087)+t(835)+t(1411),HrILm:function(c){return c()},JEgQe:function(c,r){return c(r)},XAaKI:function(c,r){return c||r},NYryA:function(c,r,s){return c(r,s)},cpUKD:function(c,r,s,l){return c(r,s,l)},ONKZp:function(c,r,s){return c(r,s)},YLsgb:function(c,r,s){return c(r,s)},TXOKa:function(c,r,s){return c(r,s)},fFmpq:function(c,r,s){return c(r,s)},btZUn:t(1335),BiAfs:function(c,r,s){return c(r,s)},LmAwW:function(c,r,s){return c(r,s)},hjxMU:function(c,r){return c===r},qWuCw:"bsQCz",daBhb:function(c,r,s){return c(r,s)},PzFcn:function(c,r){return c!==r},gWXTP:t(1043),xBvoT:function(c,r,s){return c(r,s)},kljEM:function(c,r){return c!==r},Xucrv:function(c,r,s){return c(r,s)},eSBpM:function(c,r,s){return c(r,s)},VfeHq:function(c,r){return c!==r},yTTzj:function(c,r){return c!==r},YFreU:function(c,r,s){return c(r,s)},Heura:function(c,r,s){return c(r,s)},wORPW:function(c,r,s){return c(r,s)},bbuQT:function(c,r,s){return c(r,s)},QOcgW:function(c,r,s){return c(r,s)},foXon:function(c,r){return c(r)},DkeOY:function(c,r){return c(r)},nhyJW:function(c,r){return c(r)},zKBfY:t(1532),XAypN:function(c,r,s){return c(r,s)},ZMuWK:function(c,r){return c>>>r},nrDBb:function(c,r){return c(r)},vgapH:t(763),QCiGG:function(c,r,s){return c(r,s)},BRjaW:function(c,r){return c(r)},KFBpy:function(c,r,s){return c(r,s)},UKtwm:function(c,r,s){return c(r,s)},UBoSX:function(c,r){return c(r)},cPvxS:function(c,r){return c(r)},Tqmxd:function(c,r,s){return c(r,s)},qWrSA:function(c,r){return c===r},NqyiN:"Missing "+t(1087)+t(835)+t(489),MiVXy:t(1028)+t(1087)+t(835)+"method",Bucff:function(c,r){return c(r)},sclXe:function(c,r){return c+r},QjFnK:t(449),Bxcht:t(1560),IJQqD:function(c,r){return c&r},hLpNz:t(319)+"ented ty"+t(1707),YphBY:function(c,r){return c>>r},QeiBu:t(600)+"3",QjsJh:t(1818),Ybsea:"Skip pas"+t(1002),QYlLE:t(774),OnlLz:function(c,r){return c>r},KxCaf:t(1602)+t(1002),IrKhO:function(c,r,s){return c(r,s)},YPIhx:function(c,r){return c+r},JCfog:function(c,r){return c!==r},OQOVR:"mjkCU",uIfKS:t(998),IymWQ:function(c,r,s){return c(r,s)},OyTCN:function(c,r){return c||r},JneJZ:function(c,r,s){return c(r,s)},NNykZ:function(c,r){return c<r},aDqzD:function(c,r){return c+r},czYtv:function(c,r){return c+r},CEKBI:function(c,r){return c&r},vwoTR:function(c,r){return c&r},FWQhQ:function(c,r){return c==r},VlFxR:function(c,r){return c>=r},yRKio:function(c,r){return c===r},kCers:t(1330),nCKog:function(c,r){return c+r},pgYrK:function(c,r){return c!==r},SchBy:function(c,r){return c&r},wCibk:function(c,r){return c<=r},hewwr:function(c,r){return c(r)},xWCmW:function(c,r){return c&r},TvzMK:function(c,r){return c>=r},evplD:function(c,r){return c+r},OXTKl:function(c,r){return c+r},RZmmM:function(c,r){return c+r},CQnGu:function(c,r){return c!==r},kkCNe:function(c,r){return c&r},TpKAi:function(c,r){return c|r},UUNBo:function(c,r){return c|r},DrkXx:function(c,r){return c<<r},UJybh:function(c,r){return c<<r},YHQhZ:function(c,r){return c>r},tLLNT:t(876),JABXh:function(c,r,s){return c(r,s)},fstjt:function(c,r){return c>>r},gqbzG:function(c,r){return c>=r},cqqOZ:function(c,r){return c<=r},IznXa:function(c,r){return c-r},jeyLM:function(c,r){return c+r},paYrQ:function(c,r){return c-r},ewqtq:function(c,r){return c<r},tTCSl:function(c,r){return c>>r},YxNch:function(c,r){return c|r},tbEZO:function(c,r){return c&r},FeDOa:function(c,r){return c<r},geIMO:function(c,r){return c+r},iCnxx:function(c,r){return c&r},JJuef:function(c,r,s,l){return c(r,s,l)},mHXuN:function(c,r){return c+r},KNaZH:t(1633),hIcBZ:"ftOso",OjGrW:function(c,r,s){return c(r,s)},uBadM:function(c,r){return c!==r},OcINn:t(1608),fNGrg:t(712),eRVOU:function(c,r){return c<r},yRzEP:function(c,r){return c<<r},VhdGQ:function(c,r){return c&r},YfmVE:function(c,r,s){return c(r,s)},sussm:t(1234)+t(1566),jbvjk:t(1456)+"d",KsyeW:function(c,r){return c(r)},wHXuI:function(c,r){return c&r},jILdl:function(c,r){return c(r)},GKKTC:function(c,r){return c<<r},RKeol:function(c,r){return c&r},Unwgt:function(c,r){return c<<r},jCYDm:function(c,r){return c&r},QUtRS:function(c,r){return c(r)},vgPRm:function(c,r){return c<<r},vwDcj:function(c,r){return c&r},HQASY:function(c,r){return c(r)},tQQLa:function(c,r){return c(r)},Urlbs:function(c,r){return c&r},rJtHB:function(c,r){return c===r},UxBoJ:t(1744),ErApW:"mJkMD",NLBvR:function(c,r){return c<<r},EtCGd:function(c,r){return c&r},ZXntN:function(c,r){return c(r)},bRQGK:function(c,r){return c===r},ZfRkI:function(c,r){return c&r},DjXcS:function(c,r){return c&r},boGmX:function(c,r){return c|r},SfidK:function(c,r){return c|r},FUdXS:function(c,r){return c<<r},XrYDr:function(c,r){return c>>>r},NpqNI:function(c,r){return c>>>r},jtDoC:function(c,r){return c===r},qiZVt:function(c,r){return c===r},iVSTE:function(c,r){return c<r},wPgMI:function(c,r){return c<r},fPWfF:function(c,r){return c<r},cbBOB:function(c,r){return c<r},KrBUs:function(c,r){return c<r},JaFrV:function(c,r){return c&r},GvRoO:function(c,r){return c>>>r},fjYYv:function(c,r){return c!==r},EwvXr:function(c,r){return c+r},Dtubt:function(c,r){return c>>>r},VsAvt:function(c,r){return c!==r},FUMnB:function(c,r){return c>>>r},yQgzy:function(c,r){return c&r},DcLLx:function(c,r){return c+r},vQZkD:function(c,r){return c!==r},vfsQB:function(c,r){return c>>>r},wcEGA:function(c,r){return c&r},jhzxX:function(c,r){return c>>>r},otJOh:function(c,r){return c&r},NHUMb:function(c,r){return c+r},gGJrT:function(c,r){return c!==r},wWlgg:function(c,r){return c>>>r},WDOqT:function(c,r){return c>>>r},YRyrh:function(c,r){return c!==r},UcrZp:function(c,r){return c!==r},RkLSA:function(c,r){return c&r},IpOqr:function(c,r){return c|r},cNJzg:"RFuOd",qWkky:function(c,r){return c(r)},bviDo:function(c,r){return c|r},gbNOw:function(c,r){return c===r},SMFJR:function(c,r){return c<<r},bkhsy:function(c,r){return c|r},tgECu:function(c,r){return c|r},tnAaK:function(c,r){return c<<r},ekSpY:function(c,r){return c<<r},nfLrP:function(c,r){return c|r},DHuKV:function(c,r){return c<<r},qCgkm:function(c,r){return c|r},KyIrY:function(c,r){return c|r},laeyx:function(c,r){return c<<r},HYKnm:function(c,r){return c<<r},jiAnd:function(c,r){return c|r},IZPdg:function(c,r){return c<<r},bjwjX:function(c,r){return c<<r},jhqbC:function(c,r){return c<<r},vQlzJ:function(c,r){return c===r},CxQSy:"nUWcH",BlNRN:function(c,r){return c&r},MaRkS:function(c,r){return c>>>r},xcpOG:function(c,r){return c&r},HTbRv:function(c,r){return c&r},YiLgM:function(c,r){return c>>>r},PJpPD:function(c,r){return c>>>r},qEfxM:function(c,r){return c>>>r},JKwTu:function(c,r){return c|r},Eecdy:function(c,r){return c<r},GAAyJ:function(c,r){return c>>r},ZeSlW:function(c,r){return c|r},jksEZ:function(c,r){return c&r},ihpUQ:function(c,r){return c>>r},kUNvF:function(c,r){return c|r},ZjxnY:function(c,r){return c&r},XvLNZ:function(c,r){return c>>r},hHcPz:function(c,r){return c|r},SFiyY:function(c,r){return c&r},uAyIk:function(c,r){return c(r)},CpyxG:function(c,r){return c!==r},taIQl:t(1334),JKGZT:t(905),fkWhK:function(c,r){return c(r)},Iqedv:function(c,r){return c===r},cOrTC:"pjgkf",dZqHi:t(1320),CCcCT:function(c,r){return c>=r},yRQoc:t(1397),RepQN:t(1179),RiuXH:function(c,r){return c>=r},fqmyH:function(c,r){return c|r},Ohxdk:function(c,r){return c%r},nqdbz:function(c,r){return c/r},RVWKt:t(1498)+t(1011)+"t",HBAhP:t(1214),nmGDl:"EEbPf",qgHwb:function(c,r){return c+r},XxkYw:function(c,r){return c*r},JCdmn:function(c,r){return c>>>r},pIwsV:function(c,r){return c+r},VHcwd:function(c,r){return c+r},lLPNR:function(c,r){return c>>>r},dREqW:function(c,r){return c+r},XnEcW:function(c,r){return c<<r},QmZEx:function(c,r){return c>>>r},KkLND:function(c,r){return c>>>r},qBFBn:function(c,r){return c===r},qcCLU:function(c,r){return c===r},eTgcI:function(c,r){return c+r},NjxPT:function(c,r){return c&r},FtALE:function(c,r){return c&r},Oysdf:function(c,r){return c>>>r},SHTBt:function(c,r){return c>>>r},dLFJg:function(c,r){return c&r},QDTgC:t(1645)+"5|2",bIjOm:t(466)+t(940)+"R",aWQVr:"MESSAGE_"+t(1729),mpinH:t(666)+"RROR",mBiRJ:t(1431)+t(1223),PNMxY:t(695)+"OR",UJCxN:function(c,r){return c&r},iVXGk:function(c,r){return c>>>r},dmNTk:function(c,r){return c>>>r},sRELa:function(c,r){return c===r},ovOyy:t(1491),bFccj:t(432)+t(1652),DbftW:t(1891)+"3",EdjiY:function(c,r){return c>=r},tiWYr:function(c,r){return c-r},BEGfX:function(c,r){return c<r},sjpsG:function(c,r){return c|r},CvaaA:function(c,r){return c&r},DbPck:function(c,r){return c|r},MoqoW:function(c,r){return c|r},ZiZRL:function(c,r){return c|r},hXsZW:function(c,r){return c&r},OttAw:function(c,r,s,l,h){return c(r,s,l,h)},jOaCk:function(c,r){return c(r)},dtmEL:function(c,r){return c===r},kvekf:t(431),laBxT:t(1380),EstgL:t(937),zxvnr:function(c,r){return c===r},uZXks:function(c,r){return c*r},XbhhC:t(1752),XkSLd:t(1787),ezLho:function(c,r){return c instanceof r},bYXmA:"Unhandled error.",KvvpA:function(c,r){return c+r},BELuy:function(c,r){return c===r},aifxb:function(c,r){return c<r},VGFNV:function(c,r){return c===r},eYFFX:function(c,r){return c===r},dtYJV:t(479),wTFzi:function(c,r){return c===r},odaVX:"GtPsm",wlTPB:function(c,r){return c-r},ARXeH:"QVVSQ",pfmBC:t(926),kmDqd:function(c,r,s){return c(r,s)},xIxlT:function(c,r,s){return c(r,s)},oKVNt:t(1321),qXpuR:function(c,r){return c!==r},aflwI:t(1686),DNkbi:t(846),hlFai:t(1442),dKctF:"open",WzVju:function(c,r,s){return c(r,s)},anDwi:t(802),Swxsm:t(1862),EdoaL:function(c,r,s){return c(r,s)},hQvhO:t(757),ktzjg:function(c,r,s){return c(r,s)},dEBnq:t(1715),dhGrP:function(c,r){return c+r},LJRwH:function(c,r){return c+r},eazvT:function(c,r,s){return c(r,s)},WdxAF:function(c,r){return c>>>r},Exqaa:"BGcnP",rVSkC:function(c,r){return c===r},nADDE:function(c,r){return c+r},fBsKI:t(379),omeQB:"VNokn",REODY:function(c,r){return c||r},AEqQp:function(c,r){return c||r},zwaVK:function(c,r){return c!=r},AXMcw:function(c,r){return c||r},kpKaU:function(c,r){return c<=r},ZRYMC:t(813)+t(1286)+"ltiple t"+t(898)+t(977),cFyGJ:function(c,r){return c===r},SDtcX:function(c,r){return c(r)},uTPmr:function(c,r){return c<r},iXoob:function(c,r){return c<r},Waeiq:function(c,r){return c<r},OwbNX:function(c,r){return c&r},wPywf:function(c,r){return c+r},oRYUl:function(c,r){return c-r},hRzZd:function(c,r){return c<=r},zKBKo:function(c,r){return c<r},CTpKC:function(c,r){return c<<r},dgvyo:function(c,r){return c&r},gQoSJ:function(c,r){return c>=r},MsLqX:function(c,r){return c<<r},adcXP:function(c,r){return c-r},vrDIy:function(c,r){return c|r},pwTzn:function(c,r){return c|r},jpFJw:function(c,r){return c&r},VDeJy:function(c,r){return c>>r},bLBSS:t(1186),Veurj:function(c,r){return c|r},MzOzd:function(c,r){return c&r},bCVFs:function(c,r){return c===r},cBjGy:function(c,r){return c&r},MehWh:function(c,r){return c===r},YZNCD:function(c,r){return c&r},BQRBp:function(c,r){return c>>r},WQqdE:function(c,r){return c+r},LzjsA:function(c,r){return c|r},SsiMV:function(c,r){return c>>r},TyhML:function(c,r){return c|r},yDUap:function(c,r){return c|r},WdpHH:t(1819),Bdewu:function(c,r){return c!=r},cRTHz:"application/json",xtCZe:t(360)+t(907)+t(660),RofCE:"boe",GRSZc:t(1469),TEmJW:function(c,r){return c!=r},chyny:t(318),HVUeF:function(c,r){return c<<r},jpuIN:function(c,r){return c&r},OHQPP:function(c,r){return c&r},YUwbP:function(c,r){return c<=r},uOlbL:function(c,r){return c===r},GTQKQ:t(1312),nityj:function(c,r){return c===r},XShFQ:function(c,r){return c===r},utVUT:t(1125),mRgvk:"unknown "+t(1586),HralT:t(1029),dcObR:t(996),uJJlY:function(c,r){return c+r},ndkiz:"http",VuyRZ:t(1203),pKWYT:function(c){return c()},noHkz:t(572),OfkCE:function(c,r,s){return c(r,s)},dqrPz:t(421),TZjxw:t(987),VQepZ:t(1139),nOpNY:t(1138),bWAHy:t(878),zzgbB:"ping_onc"+t(1583)+"s",EnpoA:"success",fkIYC:function(c,r){return c===r},lOGsE:"ChKFf",paSfB:t(1638)+t(1855),iQyeF:function(c,r){return c(r)},TZwcY:t(545),LxSCC:function(c,r){return c instanceof r},hGpzO:function(c,r){return c instanceof r},bAljC:"applicat"+t(534)+t(425)+t(363),ljiQQ:t(902),iIdFs:t(358),xxxHB:t(1277),oetoK:function(c,r){return c||r},OAWLJ:function(c,r){return c||r},HRZLU:t(1669),NADVq:t(619),NmzRg:function(c,r){return c===r},asxHL:"fTEgW",Utnwh:t(1539),DvZlP:t(1612),jAscO:function(c,r){return c||r},nwOBE:function(c,r){return c!=r},IWFOB:function(c,r,s){return c(r,s)},zfEDt:"qos",DzSsj:t(557)+"id",CaGmU:t(1545),zUgRS:function(c,r){return c===r},tDKTR:t(1065),sqewN:t(1820),UauUp:function(c,r){return c(r)},ouwbR:function(c,r,s,l){return c(r,s,l)},oecuy:t(1688)+t(418),ZZyET:t(1688)+"er_is_ack",uYQLx:function(c,r,s){return c(r,s)},AkKUK:function(c,r,s,l){return c(r,s,l)},GbIzI:t(756),PULoU:function(c,r){return c&&r},veXfw:function(c,r){return c||r},vGrVf:t(1104),IyljS:t(494),RaLlI:function(c,r){return c(r)},MrrBS:function(c,r){return c instanceof r},FfEHa:t(1033)+"e",VGYoi:function(c,r,s,l){return c(r,s,l)},KjnkP:function(c){return c()},vIAvU:function(c,r){return c<r},cvCso:function(c,r){return c(r)},AOYPZ:function(c,r){return c(r)},LHMXQ:function(c,r){return c||r},uhHct:function(c,r){return c>>>r},jDoex:"index out of ran"+t(903),uivgc:t(1462),rJGwz:" > ",oxtah:t(1530)+t(1047)+"e",efPCz:function(c,r,s,l){return c(r,s,l)},epPvY:function(c,r){return c+r},stHaD:function(c,r){return c+r},YzfGb:function(c,r,s,l){return c(r,s,l)},WBYFY:function(c,r){return c+r},HVHus:function(c,r){return c|r},zrQyB:function(c,r){return c|r},vamqe:function(c,r){return c|r},DIGEh:function(c,r){return c<<r},FAUhd:function(c,r){return c+r},gGBnx:function(c,r){return c+r},MwqDZ:function(c,r){return c+r},QPxgH:function(c,r){return c===r},uSCeR:t(1389),izqbk:t(1205),SUccW:function(c,r){return c+r},dWfYy:function(c,r){return c&r},vYmdv:function(c,r){return c>>>r},edbnp:function(c,r){return c+r},USKyq:function(c,r){return c+r},WWzVw:function(c,r){return c>>>r},ZtMDE:function(c,r){return c&r},PulIe:function(c,r){return c+r},jbxGU:function(c,r){return c&r},FtAdL:function(c,r){return c!==r},htcif:t(1388),AMnhS:function(c,r){return c+r},WGapD:function(c,r){return c+r},FZbUy:"RzQOj",xBVOC:"2|7|1|3|"+t(1373)+t(1757)+"6",eGcsi:function(c,r){return c|r},heude:function(c,r){return c>>>r},TUrxq:function(c,r){return c|r},lQydD:function(c,r){return c<<r},xRAhh:function(c,r){return c&r},gfnnQ:function(c,r){return c>r},EZTiP:function(c,r,s,l){return c(r,s,l)},cNtyN:function(c,r){return c&r},ffwFe:function(c,r){return c|r},vneqB:function(c,r){return c|r},BnNhs:function(c,r){return c|r},TXmIQ:function(c,r){return c<<r},OUlyT:function(c,r){return c<r},GcOLy:"LXNRe",gTfBQ:t(546),jKlzl:t(1149),PlREK:"header",wgSIl:"service",LemGg:function(c,r){return c(r)},tQcon:t(538)+"ile_name",nfLfK:function(c,r,s){return c(r,s)},IsLKX:function(c,r,s){return c(r,s)},RzQiY:function(c,r){return c+r},HMcwd:function(c,r,s){return c(r,s)},myBfp:t(543)+t(1521),sWuCq:t(635)+t(639),YrBDr:"ALL",sFyJK:t(1666),JnqSg:t(1035),rRuYc:t(1082),lgjra:t(1327),aWwIv:"setdb",ESPlP:"setcursor",NOVCD:t(806),CXACh:function(c,r){return c||r},qdifj:t(917),WEogz:t(1733),JVcvh:function(c,r){return c&r},upepZ:function(c,r){return c&r},nwDom:function(c,r){return c(r)},snFnx:function(c,r){return c&r},qrfAv:function(c,r,s,l){return c(r,s,l)},Qmfvf:t(1513),oVFxG:t(1688)+t(389),sEijO:t(558)+"rsor_name",UKrDi:function(c,r){return c(r)},tfVhE:t(558)+t(1636)+"ue",yTYfk:t(1243),VUArE:function(c,r){return c+r},Kufhl:function(c){return c()},OEjFW:function(c){return c()},wwwpQ:function(c,r,s){return c(r,s)},FztZq:"reconnect",MiKkL:function(c){return c()},ZKGEP:t(1814),onOYQ:function(c,r){return c===r},KqBwz:t(606),KafuD:t(916),ufuKo:function(c,r){return c(r)},HeCfD:function(c){return c()},WvyMt:function(c){return c()},VHeFJ:"YetvX",nKfMp:t(957),PgqTT:function(c,r){return c!==r},kjgcY:t(750),knrTK:t(705),UWKXS:function(c,r){return c===r},jGphu:function(c,r){return c===r},tIrtt:t(1556),OBFPg:function(c,r){return c&r},jtscb:function(c,r,s){return c(r,s)},RlJxp:"bye",zVIxk:function(c,r){return c!==r},lDdAf:t(766),drXhA:function(c,r){return c/r},UFruu:function(c,r){return c==r},OyanV:t(1105)+t(1531)+t(525)+t(662)+t(1544)+t(1485)+t(860)+t(554),mwkWS:function(c,r,s){return c(r,s)},sUWks:t(1518)+t(441)+" reconnect",gMEKr:t(515),OjcoK:t(1789),nlbRd:function(c,r){return c(r)},EhikJ:t(792),xkbGX:function(c,r){return c!==r},iMlZL:"x_fronti"+t(789)+"ck",MNZGj:t(1688)+t(1671)+t(1304),CsezN:function(c,r){return c!==r},IpTSc:t(964),yNBuA:function(c,r){return c==r},kVVcr:"https:",YGOxz:t(1337),AQLkC:"bd_did",mqFhP:t(670),wSJTH:function(c,r){return c||r},tiDfJ:t(1264),oWihd:function(c){return c()},ETbWD:function(c,r,s){return c(r,s)},fQeXe:"web",OAwNi:function(c,r){return c!==r},ZPAby:t(1254),bczfu:"lCgum",YDbQg:function(c,r,s){return c(r,s)},nnqNM:"umpxr",QrEar:function(c,r,s){return c(r,s)},MCnOg:t(1339),tHnbU:function(c,r,s){return c(r,s)},CZvhh:t(1595),OFHJF:t(372),aNLKi:t(1835)+">",lNHSv:function(c,r){return c*r},qjEld:function(c,r){return c-r},lxxfa:function(c,r){return c>r},WoazJ:function(c,r){return c!==r},RuCIy:t(602),mPpNM:function(c,r,s){return c(r,s)},SnumG:function(c,r,s){return c(r,s)},kDMbX:t(1511),RCcJv:"madLx",iVngV:t(1378)+t(1059)+t(1392)+t(1414)+t(1041),hEKrU:function(c,r,s){return c(r,s)},IbCwr:function(c,r,s){return c(r,s)},ZNnmE:function(c,r){return c!==r},stRnq:t(1308),vlMVr:function(c,r){return c!=r},NeZRv:t(313),LYfsu:function(c,r,s){return c(r,s)},tsdYO:function(c,r){return c>=r},iSnIE:function(c,r,s){return c(r,s)},hOBUM:function(c,r,s){return c(r,s)},mqull:t(1328),DItJe:t(1282)+t(1394)+"onnecting",pJmSB:"wNWaN",ULAzs:t(1383),dacQy:function(c,r){return c===r},SDAvp:t(1253),dHaVp:"2|4|1|0|3",GKLLu:function(c,r){return c===r},CJFUb:t(1594),joFEs:t(839),bniWt:t(1378)+t(1568)+t(1849)+"ine",UaDcP:"ack",kmHCV:function(c,r){return c+r},Zojgr:t(680),YFzrk:t(900),CJWgv:t(1754)+t(741)+t(1607)+t(679)+"ed",eSZvK:function(c,r){return c===r},NVPkC:t(1754)+t(1574)+"y closed",ZZwNb:t(1105)+"rovide a"+t(1015)+t(473)+t(1830)+"e a stri"+t(1019)+" arraybuffer",nCboM:t(891),URVqo:function(c,r){return c!=r},abbdv:function(c,r){return c instanceof r},ExvNf:function(c,r){return c instanceof r},FWYFh:function(c,r){return c(r)},tkzEU:function(c,r){return c instanceof r},NJvpe:function(c,r){return c(r)},wVWey:t(921),woHPo:function(c,r){return c<r},bduxN:function(c,r){return c||r},SrEiN:function(c,r){return c==r},YYmQX:function(c,r){return c!==r},AmmNN:t(975)+t(869)+t(472),eJMXy:function(c,r){return c!==r},DlBWG:t(1700),AicCt:"2|0|3|4|1",JoMaz:function(c,r){return c!==r},QPzAR:"dAATz",ccXUp:function(c,r){return c(r)},PCLHE:t(1074),hUUxp:function(c,r){return c*r},mLrCY:function(c,r){return c*r},AvJoE:function(c,r){return c!=r},fFecB:t(1662),wQKYG:function(c,r){return c===r},OnPpg:t(1799),ZxBZB:function(c,r){return c===r},UPduX:t(433)+t(988)+t(866)+"pe",oapfn:function(c,r){return c===r},kCqMp:function(c,r){return c==r},mJnPt:function(c,r){return c!=r},UIuzt:function(c,r){return c===r},tlDSI:t(841)+t(888)+t(1524),cTMTj:function(c,r){return c===r},BOLQk:t(672)+t(1030)+"balScope",zcuco:function(c,r){return c!=r},JHeLm:function(c,r){return c!=r}};zt.r(Re),zt.d(Re,{FWS:()=>Mg,CustomErrorEvent:()=>gl,createCloseEvent:()=>mt,ReconnectEvent:()=>pl,createErrorEvent:()=>ct,decodedFrame:()=>sn,createOpenEvent:()=>bl,CustomCloseEvent:()=>ml,createReconnectEvent:()=>Sa,FrontierMessageEvent:()=>_l,encodeFrame:()=>Gt,createMessageEvent:()=>El,OpenEvent:()=>yl,ErrorCode:()=>an,Event:()=>cr,MessageEvent:()=>wl});let n="";function i(c=""){let r=t;if(e[r(1802)](r(864),e[r(1346)])){let s=e.yjChT(_0xb531f2,_0x2dc640,1);_0x45afbf.bytes[s]=_0x584a9c}else{let l=""+Date.now(),h=n||(n=e[r(1576)](f,c)),m=Math[r(1184)]()[r(1390)](16)[r(1644)](-6);return e[r(500)](e.rvxGz(e[r(1285)]("02",l),h),m)}}function o(){let c=t;return e[c(500)](e[c(1185)](1e4,Date.now()),Math.floor(1e4*Math[c(1184)]()))}function a(c){let r=t;if(e[r(1815)]!==e[r(1815)])this["currentI"+r(791)]=0,this["currentE"+r(1770)+r(541)+"t"]=0;else return e.BoVwr(e[r(378)](Array,8)[r(1040)]("0"),e[r(343)](parseInt,c,10)[r(1390)](2))[r(1644)](-8)}function d(c){let r=t;return e[r(1429)](e[r(378)](Array,4)[r(1040)]("0"),e[r(465)](parseInt,c,2)[r(1390)](16)).slice(-4)}function u(c){let r=t,s=c.split(/\./)[r(793)](m=>a(m)),l=[];return l[0]=d(e[r(1429)](s[0],s[1])),l[1]=e[r(378)](d,e[r(1020)](s[2],s[3])),[e.czREm,r(478),e.czREm,r(478),e.czREm,e.OnfLd,l[0],l[1]][r(1040)]("")}function f(c){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(1538)](c),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]))/.test(c);return s?e.dZMxB(u,c):l?e[r(963)](x,c):e.dbgLF}function x(c){let r=t,s="",l=[],h=0,m=0,E=!0,v=e.czREm;if(e.sPGWR(c.indexOf("::"),-1)){let p=c[r(615)]("::");for(let O=0;e.gqJxN(O,p.length);O++){let F=p[O];if(e[r(1758)](F[r(1103)](":"),0)){if(e[r(1575)](e[r(634)],r(641)))return this[r(738)][r(972)]();{let j=F[r(615)](":");E&&(h=j[r(374)]),m+=j.length;for(let K=0;K<j[r(374)];K++)if(e.qAVYp(4,j[K][r(374)])){let V=v[r(1681)+"g"](0,4-j[K].length),We=V.concat(j[K]);l[r(607)](We)}else l[r(607)](j[K]);E=!1}}else{if(F[r(374)]!==4){let j=v.substring(0,e[r(413)](4,F.length)),K=j[r(1351)](F);l.push(K)}else l[r(607)](F);E&&(h+=1),m+=1,E=!1}}let C="";for(let O=0;e[r(1497)](O,e.rRqxl(8,m));O++)C=C[r(1351)](v);for(let O=0;O<l[r(374)];O++)e[r(1559)](O,h)&&(s=s.concat(C)),s=s[r(1351)](l[O]);return s}{let p=c[r(615)](":");for(let C=0;e[r(1497)](C,p[r(374)]);C++){if(e[r(1115)]!==e[r(1115)])return new _0x343268(e.pGImT(_0x1ebfe9[4]<<24|e[r(990)](_0x3aab89[5],16)|e.gMbWL(_0x448c33[6],8),_0x452ba0[7]),e[r(430)](e.pGImT(e[r(1097)](e[r(1684)](_0x5738eb[0],24),e[r(795)](_0x14f447[1],16)),_0x2c429c[2]<<8),_0x35ed58[3]),_0x110785);{let O=p[C];if(p[C][r(374)]!==4){let F=v[r(1681)+"g"](0,e[r(413)](4,p[C][r(374)])),j=F[r(1351)](O);s=s.concat(j)}else s=s[r(1351)](O)}}return s}}function g(c,r){let s=t,l={tQEcf:function(h,m){return e[$(963)](h,m)}};if(s(556)!==e.YeiVm)return function(...h){let m=s;return _0x5d797a[m(426)](QEcqdT[m(1042)](_0x4a0a55,this),h),QEcqdT[m(1042)](_0x216495,_0x3217aa[m(645)](this))};{let h=c[s(794)];h!==void 0&&(e[s(1609)](pe,r,10),e[s(485)](U,r,h));let m=c[s(1411)];e[s(1155)](void 0,m)&&(e[s(1483)](pe,r,18),e[s(423)](U,r,m))}}function w(c){let r=t,s={};e:for(;!J(c);){let l=e[r(677)](ue,c);switch(e[r(503)](l,3)){case 0:break e;case 1:s[r(794)]=e[r(1039)](R,c,e[r(677)](ue,c));break;case 2:s[r(1411)]=e[r(1039)](R,c,e[r(677)](ue,c));break;default:e[r(1483)](T,c,e[r(1793)](7,l))}}if(e[r(1559)](void 0,s[r(794)]))throw new Error(e[r(447)]);if(e[r(1559)](void 0,s[r(1411)]))throw new Error(e[r(1231)]);return s}function S(c){let r=t,s=e[r(1402)](D);return _(c,s),e[r(1259)](M,s)}function _(c,r){let s=t,l={CBrnN:function(dt,Be,wt){return e[$(1083)](dt,Be,wt)},BPcuD:function(dt,Be,wt,ur){return e.cpUKD(dt,Be,wt,ur)}},h=c.SeqID;e[s(1575)](void 0,h)&&(e[s(1050)](pe,r,8),e.YLsgb(gt,r,h));let m=c[s(1107)];e[s(1802)](void 0,m)&&(e[s(1444)](pe,r,16),e[s(519)](gt,r,m));let E=c[s(336)];if(e[s(1802)](void 0,E))if(e[s(1621)]==="CMQFc")e[s(1050)](pe,r,24),gt(r,e.MNRQa(P,E));else{let{offset:dt}=l[s(424)](_0x4dc500,_0x5a5cda,_0x47f22a);_0x30edce=dt;let Be={cursor_name:"",cursor:0,service:0},{value:wt,offset:ur}=l[s(424)](_0x5debb3,_0x8142ee,_0x489eff);Be[s(336)]=wt,_0x56dda4=ur;let{value:gs,offset:ci}=_0x1e3858(_0x2572d5,_0x49ebcf);_0x20f28a=ci,Be[s(1234)+"ame"]=l[s(613)](_0x55eba8,_0x4f9730,_0x2cbbf6,_0x125e24+gs),_0x557daf+=gs;let{value:Pa,offset:Ht}=_0x377ca1(_0x422d45,_0x13a9b3);Be[s(1504)]=Pa[s(716)](),_0x274c1d=Ht,_0x23a21e.push(Be)}let v=c.method;e[s(1575)](void 0,v)&&(e[s(961)](pe,r,32),e[s(927)](gt,r,e.JEgQe(P,v)));let p=c.headers;if(e.qAVYp(void 0,p))for(let dt of p)if(e[s(502)](e[s(1703)],e[s(1703)])){pe(r,42);let Be=D();e[s(519)](g,dt,Be),pe(r,Be[s(1142)]),e[s(487)](H,r,Be),L(Be)}else{let Be=this._qosDB["getStora"+s(713)](this[s(1302)]),wt=_0x47a2a3[s(1148)](e[s(1072)](Be,"{}"));return wt[_0x264b17||_0x23014a[this[s(368)]]]=_0x2facbb,this[s(738)][s(989)+s(713)](this[s(1302)],_0x1d94af[s(588)+"y"](wt)),_0x5e662c||_0x1b427c[this[s(368)]]}let C=c["payloadE"+s(1692)];if(e[s(616)](void 0,C)){if(e[s(1575)](e[s(1070)],e[s(1070)]))return e[s(1559)](0,this.high)&&e[s(1559)](0,this[s(1422)]);e[s(1435)](pe,r,50),e[s(1847)](U,r,C)}let O=c["payloadT"+s(800)];e[s(1877)](void 0,O)&&(e[s(465)](pe,r,58),U(r,O));let F=c[s(1642)];F!==void 0&&(e[s(1680)](pe,r,66),e[s(1444)](pe,r,F[s(374)]),e[s(824)](oe,r,F));let j=c[s(1619)];e[s(1200)](void 0,j)&&(e[s(1609)](pe,r,74),e.SLqHq(U,r,j));let K=c.serverTiming;e[s(731)](void 0,K)&&(e[s(437)](pe,r,82),e[s(1367)](U,r,K));let V=c[s(342)];V!==void 0&&(e.wORPW(pe,r,90),e[s(1036)](U,r,V));let We=c.frameType;We!==void 0&&(e[s(1039)](pe,r,96),e[s(390)](gt,r,e[s(623)](P,We)))}function b(c){let r=t;return e[r(1622)](I,e[r(1077)](B,c))}function I(c){let r=t,s={IIsgJ:e.zKBfY,pcNlB:function(h,m,E){return e[$(941)](h,m,E)}},l={};e:for(;!e[r(378)](J,c);){let h=ue(c);switch(e[r(400)](h,3)){case 0:break e;case 1:l[r(489)]=e.tvwDI(At,c,!0);break;case 2:l[r(1107)]=e[r(390)](At,c,!0);break;case 3:l[r(336)]=ue(c);break;case 4:l[r(1776)]=e[r(1168)](ue,c);break;case 5:if(e[r(502)](e[r(1381)],e.vgapH)){let m=A(c);(l[r(816)]||(l[r(816)]=[])).push(e[r(378)](w,c)),c[r(1142)]=m;break}else this.emit(s[r(1676)],s[r(1451)](_0x51f62f,r(1532),{message:this[r(812)+r(1371)+r(767)](_0x5c96cd)}));case 6:l[r(521)+r(1692)]=e[r(1784)](R,c,e[r(1606)](ue,c));break;case 7:l[r(1581)+"ype"]=e[r(901)](R,c,ue(c));break;case 8:l[r(1642)]=e.UKtwm(te,c,ue(c));break;case 9:l[r(1619)]=R(c,e[r(1136)](ue,c));break;case 10:l[r(601)+r(1199)]=e[r(1018)](R,c,e.cPvxS(ue,c));break;case 11:l[r(342)]=R(c,e.PaJHi(ue,c));break;case 12:l[r(843)+"e"]=ue(c);break;default:e.Tqmxd(T,c,e.yFqbQ(7,h))}}if(e[r(1385)](void 0,l[r(489)]))throw new Error(e[r(1591)]);if(e[r(1559)](void 0,l[r(1107)]))throw new Error(r(1028)+r(1087)+" field: "+r(1107));if(l.service===void 0)throw new Error(r(1028)+r(1087)+r(835)+r(336));if(e[r(502)](void 0,l.method))throw new Error(e[r(476)]);return l}function A(c){let r=t,s=e[r(1630)](ue,c),l=c.limit;return c[r(1142)]=e.sclXe(c.offset,s),l}function T(c,r){let s=t;if(e[s(711)]!==e[s(946)])switch(r){case 0:for(;e[s(691)](128,ne(c)););break;case 2:e[s(941)](Y,c,ue(c));break;case 5:e[s(1775)](Y,c,4);break;case 1:e[s(1018)](Y,c,8);break;default:throw new Error(e[s(1429)](e.hLpNz,r))}else _0x1e9d30+=e[s(963)](_0x504498,_0xbd2433),_0x53f87a+=2}function P(c){return c|=0,{low:c,high:e.YphBY(c,31),unsigned:c>=0}}let y=[];function D(){let c=t,r={hnhep:e[c(694)],JjrKI:function(h,m){return e[c(1802)](h,m)}};if(e[c(1474)]===e[c(1474)]){let h=y[c(484)]();return h?(h[c(1052)]=h.limit=0,h):{bytes:new Uint8Array(64),offset:0,limit:0}}else{let h=r[c(881)].split("|"),m=0;for(;;){switch(h[m++]){case"0":var s=_0x474dc6[_0x4576f8]={exports:{}};continue;case"1":if(qlXTcc[c(1823)](void 0,l))return l.exports;continue;case"2":var l=_0x35e0a0[_0x424f66];continue;case"3":return s[c(1359)];case"4":_0x3c3b98[_0x42700f](s,s.exports,_0x2a0dec);continue}break}}}function L(c){y[t(607)](c)}function B(c){return{bytes:c,offset:0,limit:c[t(374)]}}function M(c){let r=c.bytes,s=c.limit;return r.length===s?r:r.subarray(0,s)}function Y(c,r){let s=t;if(e[s(1429)](c[s(1052)],r)>c[s(1142)])throw new Error(e[s(1747)]);c[s(1052)]+=r}function J(c){let r=t;return c[r(1052)]>=c[r(1142)]}function ie(c,r){let s=t,l=c[s(1449)],h=c[s(1052)],m=c[s(1142)],E=e.BoVwr(h,r);if(E>l[s(374)])if(e[s(616)](e[s(858)],e[s(858)]))_0x44ef2f[s(1635)](_0x259085);else{let v=new Uint8Array(2*E);v[s(1876)](l),c[s(1449)]=v}return c[s(1052)]=E,E>m&&(c.limit=E),h}function Q(c,r){let s=t,l=c[s(1052)];if(e[s(499)](e[s(1285)](l,r),c[s(1142)]))throw new Error(e.KxCaf);return c[s(1052)]+=r,l}function te(c,r){let s=t,l=e[s(1415)](Q,c,r);return c.bytes.subarray(l,e[s(1804)](l,r))}function oe(c,r){let s=t;if(e.JCfog(e[s(1663)],e[s(830)])){let l=ie(c,r[s(374)]);c[s(1449)][s(1876)](r,l)}else return new _0x23c082(_0x51362a,{data:_0x2bfa0c,message:_0x1a2d0e})}function R(c,r){let s=t,l={MmenU:function(C,O){return e.OyTCN(C,O)}},h=e[s(1364)](Q,c,r),m=String["fromChar"+s(1152)],E=c[s(1449)],v="\uFFFD",p="";for(let C=0;e[s(1732)](C,r);C++){let O=E[C+h],F,j,K,V;if(e.IJQqD(128,O)===0)p+=e.DkeOY(m,O);else if(e[s(1559)](e[s(691)](224,O),192))e[s(1829)](C,1)>=r?p+=v:(F=E[e[s(1436)](e[s(1237)](C,h),1)],e[s(1631)](192,F)!==128?p+=v:(V=e.pGImT(e.IJQqD(31,O)<<6,e[s(364)](63,F)),e.NNykZ(V,128)?p+=v:(p+=m(V),C++)));else if(e[s(597)](e[s(691)](240,O),224))if(e.VlFxR(C+2,r))p+=v;else if(e.yRKio(e[s(1853)],e[s(1853)]))F=E[e[s(436)](C,h)+1],j=E[e[s(500)](C+h,2)],e[s(1455)](e.SchBy(e[s(1097)](F,j<<8),49344),32896)?p+=v:(V=e[s(1816)](e[s(820)](15,O)<<12,e.vwoTR(63,F)<<6)|63&j,e[s(1497)](V,2048)||V>=55296&&e[s(684)](V,57343)?p+=v:(p+=e.hewwr(m,V),C+=2));else{this[s(1202)+"ngTimer"](),this["_pingPon"+s(1093)+"Id"]=e.IymWQ(_0x2315ac,this[s(790)].bind(this),this._options.pingInterval);return}else if(e[s(1132)](248,O)==240)if(e[s(815)](C+3,r))p+=v;else if(F=E[e.evplD(e.OXTKl(C,h),1)],j=E[e[s(1785)](e[s(1237)](C,h),2)],K=E[e.czYtv(C+h,3)],e[s(516)](e.kkCNe(e[s(1410)](e.UUNBo(F,e.PeLMJ(j,8)),e[s(990)](K,16)),12632256),8421504))p+=v;else if(V=e[s(1816)](e[s(1410)](e[s(990)](7&O,18)|e.DrkXx(e[s(1132)](63,F),12),e[s(704)](e.vwoTR(63,j),6)),e[s(691)](63,K)),V<65536||e[s(1417)](V,1114111))p+=v;else if(e[s(1455)](e[s(909)],s(768)))V-=65536,p+=e[s(1240)](m,e.fstjt(V,10)+55296,e.nCKog(e[s(1631)](1023,V),56320)),C+=3;else{let We=this._qosDB.getItem(this[s(1302)]);return _0x5b7727.parse(l[s(1001)](We,"{}"))[_0x4cdf78]}else p+=v}return p}function U(c,r){let s=t,l=r[s(374)],h=0;for(let v=0;e[s(1841)](v,l);v++){let p=r.charCodeAt(v);e[s(514)](p,55296)&&e[s(919)](p,56319)&&e.ABLzM(e[s(1785)](v,1),l)&&(p=e.IznXa(e[s(1387)](p<<10,r[s(1230)+"At"](++v)),56613888)),h+=e[s(1841)](p,128)?1:p<2048?2:e[s(1732)](p,65536)?3:4}e[s(1036)](pe,c,h);let m=e[s(1364)](ie,c,h),E=c[s(1449)];for(let v=0;e[s(1497)](v,l);v++){let p=r[s(1230)+"At"](v);p>=55296&&e[s(919)](p,56319)&&e[s(1436)](v,1)<l&&(p=e.paYrQ((p<<10)+r.charCodeAt(++v),56613888)),e.ABLzM(p,128)?E[m++]=p:(e[s(1732)](p,2048)?E[m++]=e[s(1188)](p,6)&31|192:(e[s(971)](p,65536)?E[m++]=p>>12&15|224:(E[m++]=e[s(1631)](e[s(1188)](p,18),7)|240,E[m++]=e[s(724)](e[s(1631)](e[s(1345)](p,12),63),128)),E[m++]=e[s(1256)](e.vwoTR(e[s(1345)](p,6),63),128)),E[m++]=e[s(1097)](e[s(954)](63,p),128))}}function H(c,r){let s=t,l=e[s(1018)](ie,c,r[s(1142)]),h=c.bytes,m=r[s(1449)];for(let E=0,v=r.limit;e[s(924)](E,v);E++)h[e[s(933)](E,l)]=m[E]}function ne(c){let r=t;if(e.hjxMU(e.KNaZH,e[r(1464)])){let s=e[r(1626)](255,_0x272b2b);e[r(685)](_0x55363a,s,_0xfc86d2,e[r(614)](_0x22e075,_0x212724)),_0xf29cdd>>>=8,_0x15be73--}else return c[r(1449)][e[r(1111)](Q,c,1)]}function Je(c,r){let s=t;if(e[s(1145)]===e[s(1295)]){let l=_0x3a762d[s(794)];e[s(709)](void 0,l)&&(_0x41cfd8(_0x2cf5b7,10),e[s(1435)](_0x4c83d8,_0x21505b,l));let h=_0x416d57[s(1411)];e[s(1877)](void 0,h)&&(e[s(1483)](_0x38cf07,_0x2b3dd4,18),e[s(1826)](_0x59bc3a,_0x3922b8,h))}else{let l=e[s(1364)](ie,c,1);c[s(1449)][l]=r}}function ue(c){let r=t,s=0,l=0,h;do h=ne(c),e[r(1590)](s,32)&&(l|=e.yRzEP(e[r(811)](127,h),s)),s+=7;while(e[r(1626)](128,h));return l}function pe(c,r){let s=t;for(r>>>=0;e.VlFxR(r,128);)e[s(927)](Je,c,e[s(811)](127,r)|128),r>>>=7;e[s(737)](Je,c,r)}function At(c,r){let s=t,l={eipdL:function(p,C){return e[$(751)](p,C)},eBEqG:function(p,C){return p!=C},sWHwP:e[s(753)]},h=0,m=0,E=0,v;if(v=e[s(1066)](ne,c),h=e[s(1009)](127,v),e[s(691)](128,v)&&(v=e[s(1873)](ne,c),h|=e[s(401)](e.RKeol(127,v),7),e.yFqbQ(128,v)&&(v=e[s(963)](ne,c),h|=e[s(1292)](e.jCYDm(127,v),14),128&v&&(v=e[s(1673)](ne,c),h|=e[s(405)](e.vwDcj(127,v),21),128&v&&(v=e[s(676)](ne,c),m=127&v,e.IJQqD(128,v)&&(v=e.tQQLa(ne,c),m|=e[s(942)](e[s(851)](127,v),7),e[s(892)](128,v)))))))if(e[s(949)](e[s(1593)],e[s(1331)])){if(_0x456a89)return new _0x5988d9(_0xe0d515.url,_0x20b2ab.protocol);if(l[s(1454)](_0x20dc13,_0x18afa9))return new _0x585aee(_0x132747.url,_0x2ab4c9[s(1151)],_0x39ce36.headers);if(l.eipdL(_0x5b9da1,_0x5528f3)&&l[s(415)](l[s(1088)],typeof _0x288e45)&&_0x3b669c)return new _0x15d05f(_0x6e281c[s(1682)],_0x1673b1[s(1151)+"s"])}else v=e[s(378)](ne,c),m|=e[s(828)](e[s(736)](127,v),14),e[s(811)](128,v)&&(v=e[s(1238)](ne,c),m|=e[s(405)](e.wHXuI(127,v),21),e[s(1224)](128,v)&&(e[s(550)](s(759),"TUjaW")?(this[s(626)+"ameSpace"]=_0x318117,this[s(1710)+s(1433)]=_0x539607,this[s(629)+"Strategy"]=_0x2afff1,this[s(738)]=e[s(1018)](_0x557e16,this[s(626)+s(1471)],e[s(1610)])):(v=e.HQASY(ne,c),E=e[s(736)](127,v),e.ZfRkI(128,v)&&(v=ne(c),E|=e[s(586)](127,v)<<7))));return{low:e[s(1384)](h,m<<28),high:e.SfidK(e[s(503)](m,4),e.FUdXS(E,24)),unsigned:r}}function gt(c,r){let s=t,l=e[s(583)](r[s(1422)],0),h=e[s(1472)](e[s(320)](e[s(1472)](r[s(1422)],28),e[s(828)](r[s(407)],4)),0),m=e[s(583)](r[s(407)],24),E=e.jtDoC(0,m)?e[s(1643)](0,h)?l<16384?e[s(1590)](l,128)?1:2:e.iVSTE(l,2097152)?3:4:e.wPgMI(h,16384)?e[s(1067)](h,128)?5:6:e[s(1500)](h,2097152)?7:8:e[s(1683)](m,128)?9:10,v=ie(c,E),p=c[s(1449)];switch(E){case 10:p[e[s(1285)](v,9)]=e[s(932)](e[s(471)](m,7),1);case 9:p[e[s(500)](v,8)]=e[s(1421)](9,E)?128|m:127&m;case 8:p[e[s(646)](v,7)]=e[s(1155)](8,E)?e.mfDBJ(e.Dtubt(h,21),128):e.ZMuWK(h,21)&127;case 7:p[v+6]=e[s(1281)](7,E)?e[s(1816)](e[s(1883)](h,14),128):e[s(1404)](e.XrYDr(h,14),127);case 6:p[e[s(686)](v,5)]=e[s(931)](6,E)?e[s(1843)](h,7)|128:e[s(1058)](e[s(563)](h,7),127);case 5:p[v+4]=e.PzFcn(5,E)?e[s(1410)](128,h):e[s(935)](127,h);case 4:p[e[s(1570)](v,3)]=e[s(1760)](4,E)?e[s(430)](e.wWlgg(l,21),128):e.kkCNe(e[s(1840)](l,21),127);case 3:p[e[s(1387)](v,2)]=e.YRyrh(3,E)?e[s(724)](l>>>14,128):e[s(1843)](l,14)&127;case 2:p[v+1]=e[s(826)](2,E)?e[s(1097)](e[s(400)](l,7),128):e[s(1837)](e.wWlgg(l,7),127);case 1:p[v]=E!==1?e[s(1512)](128,l):e.EtCGd(127,l)}}function sn(c){let r=t;return e[r(1385)](e[r(416)],e[r(416)])?b(c):this[r(738)].isReady}function Gt(c){return e.qWkky(S,c)}let on=65536,si=e[t(1247)],_e=e[t(1463)](on,on),Ae=e.mLrCY(_e,_e),ar=e[t(928)](Ae,2),Oe=String[t(497)+"e"][t(1230)+"At"];class fe{constructor(r,s,l){let h=t;this[h(1519)]=!0,this[h(1422)]=e[h(1144)](0,r),this[h(407)]=e[h(1097)](0,s),this.unsigned=!!l}static[t(1519)](r){let s=t;return r&&e[s(350)](!0,r[s(1519)])}static[t(745)](r,s,l){return new fe(r,s,l)}static fromBytes(r,s,l){let h=t;return l?fe[h(1284)+h(1294)](r,s):fe[h(1284)+h(1245)](r,s)}static[t(1284)+t(1294)](r,s){let l=t;return new fe(e[l(1097)](e.IpOqr(r[0],e[l(1034)](r[1],8)),r[2]<<16)|e[l(911)](r[3],24),e[l(1144)](e.bkhsy(e[l(1736)](r[4],r[5]<<8),e[l(1470)](r[6],16)),e.ekSpY(r[7],24)),s)}static[t(1284)+"sBE"](r,s){let l=t;return new fe(e[l(1791)](e[l(1144)](e[l(962)](r[4],24),r[5]<<16)|e[l(1765)](r[6],8),r[7]),e[l(1250)](e[l(1439)](e.gMbWL(r[0],24)|e[l(1242)](r[1],16),e[l(1446)](r[2],8)),r[3]),s)}static[t(458)](r){let s=t;return e[s(1643)](r,si)?xl:new fe(e.ZMuWK(e[s(417)](e[s(1439)](Oe[s(1653)](r,0),e.IZPdg(Oe[s(1653)](r,1),8))|e[s(990)](Oe[s(1653)](r,2),16),Oe[s(1653)](r,3)<<24),0),e[s(1843)](e[s(1410)](e[s(1384)](e.TpKAi(Oe[s(1653)](r,4),e[s(1187)](Oe.call(r,5),8)),e[s(704)](Oe.call(r,6),16)),e[s(328)](Oe[s(1653)](r,7),24)),0),!0)}[t(744)](){let r=t;return e.vQlzJ(e[r(1424)],"nddlT")?new _0x3a8539(_0x4191fd,{message:_0x2a8e0c}):String[r(569)+r(1152)](e[r(1021)](255,this[r(1422)]),e.yFqbQ(e[r(1352)](this[r(1422)],8),255),e[r(1567)](e[r(471)](this[r(1422)],16),255),this[r(1422)]>>>24,e.EtCGd(255,this[r(407)]),e.HTbRv(e.YiLgM(this.high,8),255),e.PJpPD(this.high,16)&255,e[r(854)](this[r(407)],24))}static fromNumber(r,s=!0){let l=t,h={wQFjb:function(m,E){return e[$(1886)](m,E)},CHKAQ:function(m,E){return e[$(1740)](m,E)}};if(e[l(697)](e[l(1717)],e[l(1646)])){if(e[l(823)](isNaN,r))return s?Vp:xl;if(s){if(e[l(1396)](e[l(1468)],e[l(831)]))_0x95116d=DpVLPD[l(1314)](_0x3614f6,_0x5b2e7e),_0x3b7a3a|=DpVLPD.CHKAQ(127&_0x487384,7);else if(e[l(1771)](r,Ae))return Yp}else{if(e.yRQoc===e[l(1478)])return _0x55860f[l(1635)]("setdb",_0x4b0932,_0x25d89f,_0x5323a3),this._qosDB[l(1876)]({cursor_name:_0x298927,cursor:_0x14dc44,service:_0x2085f7});if(r<=-ar)return Zp;if(e[l(797)](r+1,ar))return Jp}return fe[l(745)](e[l(895)](e[l(1887)](r,_e),0),e[l(928)](r,_e)|0,s)}else e[l(1497)](_0x11cd1b,2048)?_0x444428[_0x598b3d++]=e.JKwTu(e.jCYDm(_0x183336>>6,31),192):(e[l(508)](_0x468400,65536)?_0x368247[_0x32b6af++]=e[l(1791)](e[l(1058)](e[l(1188)](_0x20bbd1,12),15),224):(_0x3a47d3[_0x4f2ac7++]=e.GAAyJ(_0x2926e2,18)&7|240,_0x3f0233[_0x184f09++]=e[l(683)](e[l(1159)](e[l(1859)](_0x284edf,12),63),128)),_0x562a83[_0x153584++]=e[l(387)](e.ZjxnY(e[l(341)](_0x30f5c5,6),63),128)),_0x17b1b4[_0x3433ef++]=e[l(1445)](e[l(717)](63,_0x539951),128)}[t(716)](){let r=t;if(e[r(488)](e[r(332)],e[r(332)]))this[r(825)+r(1244)]?.addCount(),this[r(1086)](e[r(1217)],e[r(872)]),this[r(825)+r(1244)]?.[r(780)+r(1010)+"nt"]()?this[r(1623)+"econnect"]():this[r(790)]();else return this[r(1457)]?e[r(1162)](e[r(503)](this.high,0)*_e,this[r(1422)]>>>0):e[r(1804)](e[r(764)](this[r(407)],_e),e.NpqNI(this[r(1422)],0))}isZero(){let r=t;return this[r(407)]===0&&e.bRQGK(0,this[r(1422)])}[t(1592)](r){let s=t;fe[s(1519)](r)||(r=fe[s(438)+"er"](r));let l=this[s(407)]>>>16,h=e[s(1631)](65535,this[s(407)]),m=e.JCdmn(this.low,16),E=e.vwoTR(65535,this[s(1422)]),v=r[s(407)]>>>16,p=65535&r[s(407)],C=r.low>>>16,O=e[s(1567)](65535,r[s(1422)]),F=0,j=0,K=0,V=0;return V+=e[s(329)](E,O),K+=e[s(400)](V,16),V&=65535,K+=e.VHcwd(m,C),j+=e[s(1786)](K,16),K&=65535,j+=e[s(1851)](h,p),F+=e[s(1840)](j,16),j&=65535,F+=e.dREqW(l,v),F&=65535,fe[s(745)](e[s(724)](K<<16,V),e[s(683)](e.XnEcW(F,16),j),this[s(1457)])}equals(r){let s=t;return fe[s(1519)](r)||(r=fe[s(438)+"er"](r)),this[s(1457)]!==r[s(1457)]&&e[s(965)](this[s(407)],31)===1&&e.KkLND(r[s(407)],31)===1?!1:e.qBFBn(this[s(407)],r.high)&&e[s(550)](this.low,r[s(1422)])}addOne(){let r=t;return e.yRKio(-1,this.low)&&e[r(1385)](-1,this.high)?fe[r(745)](0,0,this[r(1457)]):e[r(944)](-1,this[r(1422)])?fe[r(745)](0,e[r(1150)](this.high,1),this[r(1457)]):fe[r(745)](e[r(1325)](this[r(1422)],1),this.high,this[r(1457)])}[t(930)](r){let s=t;return r?this[s(752)+"E"]():this[s(1806)+"E"]()}toBytesLE(){let r=t,s=this.high,l=this.low;return[e[r(1128)](255,l),e[r(1404)](l>>>8,255),e.BlNRN(l>>>16,255),e[r(1824)](l,24),e[r(1159)](255,s),e.FtALE(e[r(583)](s,8),255),e[r(1888)](e[r(913)](s,16),255),e[r(1843)](s,24)]}[t(1806)+"E"](){let r=t,s=this.high,l=this.low;return[s>>>24,e[r(1021)](s>>>16,255),e[r(1322)](s,8)&255,e[r(1567)](255,s),e[r(965)](l,24),e[r(851)](e[r(1322)](l,16),255),e.dLFJg(e[r(1472)](l,8),255),255&l]}}let xl=new fe(0,0,!1),Vp=new fe(0,0,!0),Jp=fe.fromBits(-1,2147483647,!1),Yp=fe[t(745)](-1,-1,!0),Zp=fe[t(745)](0,-2147483648,!1);var an=(function(c){let r=t,s=e[r(1746)].split("|"),l=0;for(;;){switch(s[l++]){case"0":c[c[e.bIjOm]=5003]=e[r(1143)];continue;case"1":c[c[r(1140)+"ERROR"]=5004]=e[r(1727)];continue;case"2":return c;case"3":c[c[e.mpinH]=5001]=e[r(1057)];continue;case"4":c[c[e.mBiRJ]=5002]=e.mBiRJ;continue;case"5":c[c[e.PNMxY]=5005]=e.PNMxY;continue}break}})({});class cr{constructor(r){let s=t;this[s(1027)]=r,this[s(578)]=null}}class pl extends cr{constructor(r,s){let l=t;if(e.sRELa(l(1228),e[l(566)])){let h=this[l(407)],m=this[l(1422)];return[e.ZjxnY(255,m),e[l(1159)](m>>>8,255),e[l(954)](e.lLPNR(m,16),255),m>>>24,e[l(367)](255,h),e.VhdGQ(e[l(1477)](h,8),255),e[l(1224)](e[l(1866)](h,16),255),e.vfsQB(h,24)]}else super(r),this.message=s&&s[l(757)]||null}}class gl extends cr{constructor(r,s){let l=t,h=e.bFccj[l(615)]("|"),m=0;for(;;){switch(h[m++]){case"0":this[l(757)]=s&&s.message||"";continue;case"1":this[l(1513)]=s&&s[l(1513)]||5001;continue;case"2":this[l(1532)]=s&&s[l(1532)]||null;continue;case"3":this[l(1769)]=s&&s[l(1769)]||0;continue;case"4":super(r);continue;case"5":this.filename=s&&s[l(475)]||"";continue;case"6":this.colno=s&&s[l(1141)]||0;continue}break}}}class ml extends cr{constructor(r,s){let l=t,h=e.DbftW[l(615)]("|"),m=0;for(;;){switch(h[m++]){case"0":this[l(1586)]=s&&s[l(1586)]||"";continue;case"1":this[l(1513)]=s&&s[l(1513)]||0;continue;case"2":this[l(1448)]=s&&s[l(1448)]||!1;continue;case"3":this[l(384)+l(585)]=s&&s[l(384)+l(585)]||!1;continue;case"4":super(r);continue}break}}}class wl extends cr{constructor(r,s){let l=t,h={gXoFl:function(m,E){return e[$(1533)](m,E)},bjlGD:function(m,E){return e[$(1237)](m,E)},OErzm:function(m,E){return e[$(1627)](m,E)},OrLkh:function(m,E){return e[$(508)](m,E)},eFqIn:function(m,E){return e[$(1611)](m,E)},ynMZA:function(m,E){return e.sjpsG(m,E)},emOCU:function(m,E){return e.CvaaA(m,E)},DUnlb:function(m,E){return e.DbPck(m,E)},cnTSX:function(m,E){return e[$(994)](m,E)},BvqlV:function(m,E){return e[$(586)](m,E)},QPnPw:function(m,E){return e.MoqoW(m,E)},Iimeo:function(m,E){return m&E},BHmXX:function(m,E){return e[$(994)](m,E)},HBixv:function(m,E){return e.ZiZRL(m,E)},mHiKE:function(m,E){return e.hXsZW(m,E)}};if(l(651)===l(651))super(r),this[l(1056)]=s&&s[l(1056)]||null;else{let m=_0x310ac0[l(1230)+"At"](_0xbb39b6);OaMKdc.gXoFl(m,55296)&&m<=56319&&OaMKdc[l(1406)](_0x29209a,1)<_0x224eef&&(m=OaMKdc[l(1476)]((m<<10)+_0x9d8106[l(1230)+"At"](++_0x313689),56613888)),OaMKdc[l(592)](m,128)?_0x2048a3[_0x35bc21++]=m:(OaMKdc[l(1069)](m,2048)?_0x21e6a1[_0x5cbd74++]=OaMKdc[l(708)](OaMKdc[l(1005)](m>>6,31),192):(OaMKdc[l(1069)](m,65536)?_0xf6210a[_0x4acfbf++]=OaMKdc.DUnlb(OaMKdc[l(1005)](OaMKdc[l(730)](m,12),15),224):(_0x326461[_0x2cd2e0++]=OaMKdc.ynMZA(OaMKdc.emOCU(m>>18,7),240),_0x477c69[_0x1bc448++]=OaMKdc[l(708)](OaMKdc.BvqlV(m>>12,63),128)),_0x15748c[_0x349292++]=OaMKdc.QPnPw(OaMKdc.Iimeo(OaMKdc[l(1022)](m,6),63),128)),_0x17d6b7[_0x3d90a8++]=OaMKdc[l(397)](OaMKdc.mHiKE(63,m),128))}}}class _l extends wl{constructor(r,s){let l=t;super(r),this[l(1056)]=s&&s[l(1056)]||null,this[l(757)]=s&&s.message||null}}class yl extends cr{constructor(r,s){let l=t;super(r),this.data=s&&s[l(1056)]||null}}function ct(c,{message:r,code:s,error:l}){return new gl(c,{message:r,code:s,error:l})}function mt(c,{code:r,reason:s,wasClean:l,willReconnect:h}){return new ml(c,{code:r,reason:s,wasClean:l,willReconnect:h})}function El(c,{data:r,message:s}){return new _l(c,{data:r,message:s})}function bl(c,{data:r}){let s=t;if(e[s(848)](e[s(410)],e[s(995)]))oTbEFZ[s(1678)](_0x2915fb,oTbEFZ[s(366)](_0x35ff51,_0xaf9f8a.result),_0x3aab66[s(855)+"on"],_0x483c0d[s(1562)+"on"],_0x4c8352(_0x30b068[s(445)+s(1236)]));else return new yl(c,{data:r})}function Sa(c,{message:r}){return new pl(c,{message:r})}class vl{constructor(r,s){let l=t;this.endpoints=r,this[l(1089)+"es"]=s,this[l(1807)+l(791)]=0,this[l(1379)+l(1770)+l(541)+"t"]=0}[t(754)+t(571)+t(544)](){let r=t;this[r(1807)+r(791)]=0,this["currentEndpointT"+r(541)+"t"]=0}[t(997)+"es"](){let r=t;if(e[r(1396)](e[r(1725)],e[r(1725)]))this[r(1379)+r(1770)+r(541)+"t"]=0;else{if(this[r(1095)][r(325)+r(522)+r(1418)]||this[r(376)+r(803)])return;this[r(1623)+r(869)]()}}[t(1668)+"ntEndpoint"](){let r=t;return this[r(361)+"s"][this[r(1807)+"ndex"]]}[t(1668)+t(498)+"ntTriesCount"](){let r=t;return this[r(1379)+r(1770)+r(541)+"t"]}[t(780)+t(1461)+"es"](){let r=t;return!!(e[r(742)](this[r(1807)+r(791)],this[r(361)+"s"][r(374)])||e[r(944)](this.currentIndex,e[r(1627)](this[r(361)+"s"].length,1))&&e[r(510)](this[r(1379)+"ndpointT"+r(541)+"t"],this[r(1089)+"es"]))}[t(1154)+"rentEndp"+t(1382)+"hedMaxRetries"](){let r=t;return e[r(597)](this[r(1807)+r(791)],this[r(361)+"s"][r(374)])?!0:e[r(1417)](this[r(1379)+r(1770)+r(541)+"t"],this.maxRetries)}[t(893)+t(703)+t(1779)+t(1198)+t(1812)](){let r=t;if(e[r(1344)]!==e.XkSLd)return this[r(1379)+r(1770)+"riesCount"]=1,this[r(1807)+"ndex"]++,this[r(361)+"s"][this[r(1807)+r(791)]];{let s=new _0x3f384c(e[r(380)](2,_0x9f5a4f));s[r(1876)](_0x1be935),_0x4d6919[r(1449)]=s}}["getCurre"+t(498)+t(347)+t(1176)](){let r=t;return this["currentE"+r(1770)+r(541)+"t"]++,this[r(1668)+r(498)+"nt"]()}}let dr=(e.AvJoE("undefined",typeof globalThis)&&e.MehWh(e[t(956)],globalThis["construc"+t(636)][t(546)])||e[t(753)]!=typeof window&&e[t(383)](e[t(956)],window.constructor[t(546)]))&&typeof document<"u",Nn=e[t(339)](e[t(753)],typeof globalThis)&&(e.wQKYG(e.OnPpg,globalThis["construc"+t(636)].name)||e[t(914)](e.UPduX,globalThis[t(593)+t(636)][t(546)]))&&e[t(822)](e.jbvjk,typeof tt),oi=(e[t(753)]!=typeof globalThis&&e[t(1075)]("Object",globalThis[t(593)+t(636)][t(546)])||e.kCqMp(t(1456)+"d",typeof globalThis)||e[t(822)](e.jbvjk,typeof globalThis)&&!!globalThis[t(1004)+t(617)])&&e[t(814)](e[t(753)],typeof wx),ai=e[t(339)](e[t(753)],typeof globalThis)&&(e[t(687)](e[t(1649)],globalThis[t(593)+"tor"][t(546)])||e[t(1307)](e.tlDSI,globalThis[t(593)+t(636)][t(546)])||e.cTMTj(e[t(1724)],globalThis[t(593)+"tor"][t(546)]))&&e[t(1810)](e[t(753)],typeof self),Xp=e[t(753)]!=typeof globalThis&&e[t(1794)](e[t(1405)],globalThis["construc"+t(636)].name)&&t(1456)+"d"!=typeof global&&e[t(1181)](e[t(1405)],global[t(593)+t(636)][t(546)])&&e[t(1748)](e.jbvjk,typeof process)&&!!process[t(1889)];class Ia{constructor(){let r=t;this[r(369)+"rs"]={}}[t(1086)](r,...s){let l=t,h=this[l(369)+"rs"][r];if(h)h[l(1644)]().forEach(m=>m.fn[l(426)](m[l(321)],s));else if(e[l(979)]===r&&!this[l(1425)]){let m=s.length&&s[0];if(e.ezLho(m,Error))throw m;let E=new Error(e[l(329)](e[l(1486)],m?e[l(1601)](" (",m.message)+")":""));throw E[l(1251)]=m,m}return this}[t(953)](r,s){let l=t;if(e[l(1280)](void 0,r))this._listeners={};else if(e[l(1846)](void 0,s))this._listeners[r]=null;else{let h=this[l(369)+"rs"][r];if(h)for(let m=0;e[l(1714)](m,h[l(374)]);)e.VGFNV(h[m].fn,s)?h[l(1365)](m,1):++m}return this}on(r,s,l){let h=t;return e[h(1169)](h(479),e[h(1362)])?((this[h(369)+"rs"][r]||(this._listeners[r]=[]))[h(607)]({fn:s,ctx:l||this}),this):(_0x2f456d&&(_0x1f07c8=(0,_0x5942bb[oTbEFZ[h(1886)](_0x219cc1,_0xf0c512)[0]])(_0x2b6728=0)),_0x589250)}}class Qp extends Ia{[t(812)+t(1371)+t(767)](r){let s=t;if(e[s(981)](e[s(1527)],s(1024)))this[s(953)](_0x1ade05,_0xfe03e6);else return r[s(1071)]||r[s(1007)]?(s(1193)+" "+(r[s(1071)]||"")+s(834)+(r[s(1007)]||"")).trim():JSON[s(588)+"y"](r)}constructor(r,s,l){let h=t,m={RAOZg:function(E,v){return e.XxkYw(E,v)},mZija:function(E,v){return e[$(1167)](E,v)}};if(e[h(1280)]("jeDqV",e.ARXeH)){let{initReconnectInterval:E,maxReconnectInterval:v,reconnectIntervalGrowFactor:p}=this._options,C=m[h(1580)](E,_0x14f438.pow(p,m[h(1336)](_0x54bcb6,1)));return C>v?v:C}else super(),this[h(1116)]=null,oi&&wx["connectS"+h(542)]&&(this[h(1116)]=wx[h(1329)+h(542)]({url:r,protocols:s,header:l,fail:this["_createS"+h(787)+h(561)][h(1615)](this),success:this[h(887)+h(778)+"cessHandler"].bind(this)})),Nn&&tt["connectS"+h(542)]&&(this._socket=tt.connectSocket({url:r,protocols:s,header:l,fail:this[h(887)+"ocketFai"+h(561)][h(1615)](this),success:this[h(887)+h(778)+"cessHand"+h(897)][h(1615)](this)}))}[t(887)+t(778)+t(1650)+t(897)](){let r=t;if(r(1857)===e[r(1514)]){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(_0x5e3f00),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(1538)](_0x5f4a29);return s?_0x37f6c2(_0x4eacaf):l?e[r(1622)](_0x3ce2d9,_0x5d5936):e[r(1147)]}else Promise[r(439)]().then(()=>{let s=r;this[s(1014)+s(1693)]()})}[t(887)+"ocketFai"+t(561)](r){let s=t,l={fWZFb:function(h,m){return h!==m},molXq:function(h,m){return e[$(1098)](h,m)},RDdVV:e[s(765)],rkcrv:e[s(1880)]};e.hlFai===e[s(966)]?Promise.resolve()[s(1792)](()=>{let h=s,m=e[h(1838)](ct,e[h(979)],{message:this[h(812)+h(1371)+h(767)](r)});this[h(1086)](e[h(979)],m);let E=e[h(863)](mt,e.oKVNt,{reason:this[h(812)+"rrorMessage"](r)});this.emit(e[h(838)],E)}):_0x122d8a[s(404)+"d"]&&(this._navigatorOnline()&&(!this[s(1528)]||l[s(810)](this._ws[s(1795)+"te"],this[s(628)])||l[s(1492)](this[s(1528)].readyState,this[s(1431)+"NG"]))&&this[s(1598)+"nLine"](),this[s(633)+"er"]&&_0x5c8e40["addEvent"+s(496)](l[s(1665)],this["_handleO"+s(1073)]),this._isBrowser&&_0xa9b4a8[s(1809)+"Listener"](l.rkcrv,this[s(1598)+s(334)]))}_addWsListeners(){let r=t,s={yAYXG:e[r(838)],jERnK:function(l,h,m){return e[r(315)](l,h,m)}};this[r(1116)][r(1695)](l=>{let h=r;this[h(1086)](e[h(1822)],e[h(1360)](bl,e[h(1822)],{...l,data:l.errMsg||""}))}),this._socket[r(352)](l=>{let h=r;this[h(1086)](s.yAYXG,s[h(1189)](mt,h(1321),{...l}))}),this[r(1116)][r(714)+"e"](l=>{let h=r;e[h(949)](e[h(650)],e.Swxsm)?_0xf8f91b[h(1114)]["removeCh"+h(1120)](_0x195931):this[h(1086)](h(757),e[h(707)](El,e[h(1479)],{...l}))}),this[r(1116)].onError(l=>{let h=r;this[h(1086)](e.zKBfY,e[h(1364)](ct,e.zKBfY,{...l,message:l[h(1071)]||""}))})}[t(699)](r){let s=t,l={ZpxkQ:function(h,m,E){return h(m,E)}};if(e.ezLho(r,Uint8Array)){if(e[s(1220)]!==e[s(1220)])return this._qosDB["clearSto"+s(675)]();{let h=r[s(1762)][s(1644)](r[s(1805)+"et"],e[s(992)](r.byteLength,r[s(1805)+"et"]));this[s(1116)]&&this[s(1116)].send({data:h,fail:m=>{let E=s;this[E(1086)](e[E(979)],ct(e[E(979)],{message:this[E(812)+"rrorMessage"](m)}))}})}}else this[s(1116)]&&this[s(1116)][s(699)]({data:r,fail:h=>{let m=s;this[m(1086)](m(1532),l[m(950)](ct,m(1532),{message:this[m(812)+m(1371)+m(767)](h)}))}})}[t(1321)](r,s){let l=t,h={fIZgE:function(m,E){return e[$(1517)](m,E)},xZRne:function(m,E){return m<E},OWXDa:function(m,E,v){return e.eazvT(m,E,v)},vjroD:function(m,E){return e[$(1426)](m,E)},rvhpF:function(m,E){return e[$(828)](m,E)}};if(e.Exqaa===e[l(1210)])this[l(1116)]&&this[l(1116)][l(1321)]({code:r,reason:s});else{let m=0,E=_0x5f5621,v=h[l(1699)](_0x84c1f,4);for(;h.xZRne(E,v);){let{value:p,offset:C}=h[l(1340)](_0x42717f,_0x536a4e,E);E=C,m=h[l(1401)](h[l(1516)](m,8),0),m+=p}return{value:m,offset:v}}}["addEvent"+t(496)](r,s){this.on(r,s)}["removeEv"+t(729)+t(1473)](r,s){this[t(953)](r,s)}get[t(1795)+"te"](){let r=t;return this[r(1116)][r(1795)+"te"]}get[t(598)+"pe"](){let r=t;if(e.qBFBn(e[r(359)],e[r(1739)])){let s=this[r(369)+"rs"][_0x5262bc];if(s)s[r(1644)]()[r(1735)](l=>l.fn[r(426)](l[r(321)],_0x235637));else if(e[r(1569)](r(1532),_0x329296)&&!this.onerror){let l=_0x434866[r(374)]&&_0x41fd62[0];if(e[r(1702)](l,_0x43ab63))throw l;let h=new _0x27eac4(e[r(1325)](e[r(1486)],l?e[r(399)](" (",l.message)+")":""));throw h[r(1251)]=l,l}return this}else return this._socket[r(598)+"pe"]}set[t(598)+"pe"](r){}get[t(1682)](){let r=t;return this[r(1116)][r(1682)]}get[t(1151)](){return this[t(1116)].protocol}get[t(567)+"ns"](){let r=t;return this._socket[r(567)+"ns"]}get[t(1482)+t(1647)](){return 0}}function eg(c,r){let s=t;if(r)return new r(c.url,c[s(1151)]);if(e.REODY(oi,Nn))return new Qp(c[s(1682)],c.protocol,c[s(816)]);if(e[s(1164)](dr,ai)&&e[s(1261)](s(1456)+"d",typeof WebSocket)&&WebSocket)return new WebSocket(c.url,c[s(1151)+"s"])}function tg(c){let r=t,s=(r(1016)+"0").split("|"),l=0;for(;;){switch(s[l++]){case"0":return!1;case"1":if(e.AXMcw(dr,ai)&&e[r(753)]!=typeof WebSocket&&WebSocket)return!0;continue;case"2":if(c)return!0;continue;case"3":if(oi&&wx["connectS"+r(542)])return!0;continue;case"4":if(Nn&&tt[r(1329)+"ocket"])return!0;continue}break}}function Sl(c,r,s){let l=t,h={dCfyA:function(v,p){return e.kpKaU(v,p)},hcbSJ:e[l(1839)],LGIdd:function(v,p){return e[l(786)](v,p)},OJrfX:function(v,p){return e[l(992)](v,p)}},m=-1;async function E(v){let p=l;return h[p(865)](v,m)?Promise[p(1828)](new Error(h[p(1135)])):(m=v,h[p(382)](v,s[p(374)])?Promise[p(439)]():s[v][p(1615)](c)(r,E[p(1615)](null,h.OJrfX(v,1))))}e[l(1718)](E,0)}function Il(c){let r=t,s=0,l=0;for(let h=0;e.uTPmr(h,c[r(374)]);++h)l=c.charCodeAt(h),e[r(1738)](l,128)?s+=1:e[r(682)](l,2048)?s+=2:e.eYFFX(64512&l,55296)&&e[r(649)](e[r(507)](64512,c[r(1230)+"At"](e[r(1031)](h,1))),56320)?(++h,s+=4):s+=3;return s}function Al(c,r,s){let l=t;if(e[l(1219)](s,r)<1)return"";let h="";for(let m=r;e[l(1738)](m,s);){let E=c[m++];if(e.hRzZd(E,127))h+=String[l(569)+l(1152)](E);else if(e[l(1533)](E,192)&&e.zKBKo(E,224))h+=String[l(569)+l(1152)](e.ZiZRL(e[l(1012)](e[l(1766)](31,E),6),63&c[m++]));else if(e[l(922)](E,224)&&e.ABLzM(E,240))h+=String[l(569)+l(1152)](e[l(1816)](e[l(1211)](e.MsLqX(15&E,12),e[l(704)](63&c[m++],6)),63&c[m++]));else if(e[l(1533)](E,240)){let v=e.adcXP(e[l(1656)](e[l(1690)](e[l(1099)](7,E)<<18,e[l(1025)](e[l(935)](63,c[m++]),12)),e[l(1685)](63,c[m++])<<6)|63&c[m++],65536);h+=String["fromChar"+l(1152)](e.jeyLM(55296,e[l(896)](v,10))),h+=String[l(569)+l(1152)](56320+e[l(586)](1023,v))}}return h}function Aa(c,r,s){let l=t,h=s,m,E;for(let v=0;e[l(508)](v,c[l(374)]);++v)if(e[l(1265)](e[l(1317)],l(1186)))if(m=c[l(1230)+"At"](v),e[l(1067)](m,128))r[s++]=m;else if(m<2048)r[s++]=e[l(448)](e.YphBY(m,6),192),r[s++]=e[l(837)](63,m)|128;else if(e[l(1884)](e.cBjGy(64512,m),55296)&&e[l(1177)](e[l(1404)](64512,E=c[l(1230)+"At"](v+1)),56320)){let p=("3|0|5|2|"+l(1386))[l(615)]("|"),C=0;for(;;){switch(p[C++]){case"0":++v;continue;case"1":r[s++]=e[l(341)](m,6)&63|128;continue;case"2":r[s++]=e[l(882)](e[l(1572)](m,12),63)|128;continue;case"3":m=e[l(847)](e[l(1109)](65536,e[l(1025)](e[l(364)](1023,m),10)),1023&E);continue;case"4":r[s++]=e.LzjsA(63&m,128);continue;case"5":r[s++]=e.ZeSlW(e[l(1689)](m,18),240);continue}break}}else r[s++]=m>>12|224,r[s++]=e[l(877)](e[l(539)](m>>6,63),128),r[s++]=e[l(455)](e[l(837)](63,m),128);else this[l(1440)+"T"]||this[l(1076)+"X"]?this["_onPageN"+l(599)+l(1763)]():this[l(633)+"er"]&&this[l(1084)+l(1475)+l(496)]();return s-h}async function kl(c){let r=t;if(e[r(1452)]==typeof c){let s=new Uint8Array(e[r(1577)](Il,c));return Aa(c,s,0),s}return e[r(1702)](c,ArrayBuffer)?new Uint8Array(c):new Uint8Array(c[r(1762)],c[r(1805)+"et"],c[r(1267)+"th"])}function ng(c){let r=t;try{return e[r(1452)]!=typeof c&&(c instanceof ArrayBuffer||c[r(1762)]&&c[r(1762)]instanceof ArrayBuffer)||e[r(722)](e[r(1452)],typeof c)?"":(JSON[r(1148)](c),e[r(333)])}catch{return e.FWQhQ(e[r(1452)],typeof c)?e[r(1166)]:""}}let rg=(c,r)=>{let s=t;switch(c){case e.RofCE:case e.GRSZc:return{[s(349)+c]:1,"x-tt-env":r};default:return{}}};class ig{constructor(r){let s=t;this[s(1225)+s(1726)]=r,this[s(1870)]=0}addCount(){let r=t;this[r(1870)]++}[t(780)+t(1010)+"nt"](){let r=t;if(e[r(782)](e[r(1564)],e.chyny))return e[r(1771)](this[r(1870)],this[r(1225)+r(1726)]);try{return e[r(1261)](e.WdpHH,typeof _0x35a3cc)&&(e[r(1702)](_0x46ec95,_0x24cecf)||_0x2c6ce2.buffer&&e[r(1702)](_0x3b22ec[r(1762)],_0x5c9cb0))||e[r(1450)](e.WdpHH,typeof _0x528f70)?"":(_0x1fd87b[r(1148)](_0x241fba),e[r(333)])}catch{return e[r(1452)]==typeof _0x783ff8?e.xtCZe:""}}[t(1547)+"nter"](r=0){let s=t;e.pitMr(s(1852),s(1068))?(this[s(1225)+s(1726)]=r,this[s(1870)]=0):(_0x5fd0f4=e[s(715)](e.HVUeF(e[s(1573)](15,_0x46f534),12),e[s(1012)](e[s(1044)](63,_0x31e906),6))|e[s(1766)](63,_0xe06078),e[s(1497)](_0x2b7486,2048)||e[s(797)](_0xe77676,55296)&&e[s(968)](_0x4d8dd5,57343)?_0x172ac5+=_0xb6247a:(_0x16f2dc+=e[s(1606)](_0x4bb3a8,_0x21f79b),_0x3ef3a9+=2))}}async function sg(c){let r=t,s={ZFGZh:function(l,h){return e[$(611)](l,h)},mZzju:e[r(346)],kCejR:function(l,h){return e[r(1218)](l,h)},tYcse:function(l,h){return e[r(1081)](l,h)},MbycO:e[r(929)],zeRzk:function(l,h){return e[r(1873)](l,h)},jSsvX:e[r(958)],WRjMf:function(l,h){return e[r(709)](l,h)},jmFjN:e[r(652)],ujwEF:e.dcObR,reUBQ:function(l,h){return e[r(862)](l,h)},NEtnY:e.ndkiz,zDuKp:function(l,h){return e[r(1077)](l,h)}};return new Promise(l=>{let h=r,m={ljFeC:function(E,v){return s.zeRzk(E,v)},cYSwV:s[h(1006)]};if(s[h(386)](h(1029),s.jmFjN)){if(EwxPyE[h(983)](_0x1090ad,EwxPyE[h(875)]))return _0x3cf20b[h(645)](_0x4dd0b2);if(EwxPyE.kCejR(_0x17a452,h(1638)+h(1855)))return _0xcedc61["objectSt"+h(1855)]||_0xb5be0a.get(_0x44f02b);if(EwxPyE.tYcse(_0x42240b,EwxPyE[h(1848)]))return _0x4114a2["objectSt"+h(1855)][1]?void 0:_0x4a98d1["objectSt"+h(477)](_0xa05bc0[h(1638)+h(1855)][0])}else{if(!dr)return s[h(584)](l,s[h(1006)]);try{let E=document[h(1705)+"ement"](s[h(562)]);window["frontier"+h(1438)]=v=>{let p=h;document[p(1114)][p(1249)+"ild"](E),window[p(1227)+"JSONP"]=void 0,m.ljFeC(l,v&&v[p(1536)]||m.cYSwV)},E[h(1027)]=h(1283)+h(612),E.src=s.reUBQ(c[h(530)](/^ws/,s[h(1755)]),"&jscallback=fron"+h(1694)+"P");try{document.body[h(373)+h(1120)](E)}catch{document.body[h(1249)+"ild"](E)}}catch{window.frontierJSONP=void 0,s[h(934)](l,s[h(1006)])}}})}function cn(c,r,s){let l=t;return!!c?.[l(1584)](h=>h[l(794)]===r&&h[l(1411)]===s)}function lr(c,r){let s=t;return c?.[s(1584)](l=>l[s(794)]===r)?.[s(1411)]}let ka=null;async function og(){let c=t;return ka||(ka=Promise[c(439)]()[c(1792)](zt[c(1615)](zt,e[c(451)]))),ka}class ag extends Ia{constructor(r,s){let l=t;super(),this[l(492)]=r,this[l(734)]=s,this._qosDB=void 0,this[l(459)+"mise"]=null}async[t(1274)](){await this[t(1183)]()}async[t(1183)](){let r=t;if(!this[r(738)]){if(this[r(459)+"mise"])return this[r(459)+r(529)];try{let s=this[r(492)],l=this[r(734)];this._initPromise=(async()=>{let h=r,{openDB:m}=await e.pKWYT(og);this[h(738)]=await e[h(1831)](m,h(1227)+"_"+s,1,{upgrade(E){let v=h;E[v(1825)+v(1323)+"e"](s,{keyPath:l})}})})(),await this["_initPro"+r(529)]}catch(s){e[r(377)]!==e.noHkz?(this["maxLossC"+r(1726)]=_0x431f84,this[r(1870)]=0):console[r(1635)](s)}finally{this[r(459)+r(529)]=null}}}async get(r){let s=t;if(e.uOlbL(s(552),e.dqrPz))e[s(465)](_0x254f0f,_0x23f484,16),e.OfkCE(_0x3470f1,_0x2d238a,_0x5ce112);else try{return await this[s(1183)](),this._qosDB?.[s(645)](this[s(492)],r)}catch(l){console[s(1635)](l)}}async[t(1876)](r,s){let l=t;return await this[l(1183)](),this._qosDB?.[l(1526)](this[l(492)],r)}async[t(1801)](r){let s=t;try{return e[s(510)](e[s(833)],e[s(833)])?(await this[s(1183)](),this[s(738)]?.[s(1798)](this._dbName,r)):this[s(1528)]?this[s(1528)][s(567)+"ns"]:""}catch(l){e.nOpNY===e[s(1094)]?(_0x1ddb3a=e[s(1430)],_0x5021ca=_0x458f83[s(530)](/(^http)((?:[s]*:\/\/))/,""),_0x1cd946=/(^ws)((?:[s]*:\/\/))/[s(1538)](_0x47a3c4)?_0x266994:""+_0x4fd7e6+_0x255ce9):console.log(l)}}async[t(972)](){let r=t,s={pTRAZ:e.zzgbB,Ufmyg:e.EnpoA};if(e.fkIYC(r(1026),e[r(761)]))this[r(1202)+"ngTimer"](),this[r(1086)](s.pTRAZ,s.Ufmyg),this["_pingPon"+r(1093)+"Id"]=_0x2fd5aa(this[r(790)][r(1615)](this),_0x11e67c);else try{return await this._init(),this[r(738)]?.clear(this._dbName)}catch(l){console[r(1635)](l)}}async keys(){let r=t;return await this[r(1183)](),this._qosDB?.[r(624)+"ys"](this[r(492)])}async getAll(){let r=t;return await this._init(),this[r(738)]?.[r(1540)](this._dbName)}async[t(1734)](){let r=t;try{this[r(738)]?.[r(1321)](),this._qosDB=void 0}catch(s){console[r(1635)](s)}}get[t(1628)](){let r=t,s={jONph:e[r(346)],Wpiph:function(l,h){return e[r(1265)](l,h)},MXrKp:e.paSfB,TtnIl:function(l,h){return l===h},Sxlgi:r(1125),eegMG:function(l,h){return e[r(526)](l,h)}};try{if(e[r(981)](e[r(999)],"WAxpt"))return!!this[r(738)];if(_0x393e50 instanceof _0x52f924){if(_0x5c2704===bspomY[r(693)])return _0x479c01[r(645)](_0x3f7925);if(bspomY.Wpiph(_0x1c5615,bspomY[r(698)]))return _0x567aa0[r(1638)+r(1855)]||_0x436e3f[r(645)](_0x1252e8);if(bspomY.TtnIl(_0x197325,bspomY[r(796)]))return _0x2bc531[r(1638)+r(1855)][1]?void 0:_0x23830e[r(1638)+"ore"](_0x121a3c[r(1638)+r(1855)][0])}return bspomY[r(1874)](_0x325847,_0x135d54[_0x1d8cc5])}catch(l){return console.log(l),!1}}}class cg{constructor(r,s){let l=t;this[l(1038)]=r,this._pathKey=s,this._qosDB=localStorage}async openDB(){}get[t(1302)](){let r=t;if(e[r(611)](e[r(678)],e.xxxHB)){let s=e[r(1158)](this._options["payloadE"+r(1692)],_0x25ebc4)?{force:!!this[r(1095)][r(521)+r(1692)][r(512)],encoding:this[r(1095)]["payloadE"+r(1692)].encoding?this[r(1095)][r(521)+"ncoding"][r(1353)][r(530)](/\s/g,"")[r(735)+"ase"]():""}:{force:!1,encoding:this[r(1095)][r(521)+r(1692)]?this[r(1095)][r(521)+r(1692)].replace(/\s/g,"")[r(735)+"ase"]():""},l=_0x522e1f[r(521)+r(1692)]?_0x43131b[r(521)+"ncoding"][r(530)](/\s/g,"")[r(735)+r(1173)]():"",h=e.hGpzO(this[r(1095)].payloadType,_0x1f60d8)?{force:!!this[r(1095)][r(1581)+"ype"][r(512)],type:this._options[r(1581)+r(800)][r(1027)]?this[r(1095)]["payloadT"+r(800)][r(1027)].replace(/\s/g,"")[r(735)+r(1173)]():""}:{force:!1,type:this[r(1095)][r(1581)+r(800)]?this._options[r(1581)+r(800)][r(530)](/\s/g,"")["toLowerC"+r(1173)]():""},m=_0x2cc0ca.payloadType?_0x3d6a06[r(1581)+"ype"][r(530)](/\s/g,"")[r(735)+r(1173)]():"",E=h[r(512)]?h[r(1027)]:m||h[r(1027)],v=s[r(512)]?s[r(1353)]:l||s[r(1353)],p=[e[r(1166)],e.cRTHz,e[r(885)],e[r(1452)]],C=[r(1033)+"e",e[r(596)]];this[r(1095)][r(314)+r(661)+"extPayload"]&&p[r(409)](E)&&(!v||C[r(409)](v))?_0xd5caa0[r(1634)+r(1266)]=e[r(685)](_0x4b7b62,_0x2feab8.payload,0,_0x443be9.payload.byteLength):_0x4a4829[r(1634)+"oad"]=""}else return r(1227)+"_"+this._DBName}async[t(645)](r){let s=t,l=this[s(738)].getItem(this[s(1302)]);return JSON.parse(e.oetoK(l,"{}"))[r]}async set(r,s){let l=t,h=this._qosDB.getItem(this._prefix),m=JSON[l(1148)](e[l(1213)](h,"{}"));return m[s||r[this[l(368)]]]=r,this._qosDB[l(340)](this[l(1302)],JSON[l(588)+"y"](m)),s||r[this._pathKey]}async[t(1801)](r){let s=t,l=this[s(738)][s(748)](this[s(1302)]),h=JSON[s(1148)](l||"{}");return h[r]=void 0,this[s(738)][s(340)](this[s(1302)],JSON[s(588)+"y"](h))}async clear(){let r=t;return this[r(738)][r(972)]()}async[t(653)](){let r=t;if(e[r(510)](e[r(836)],e.NADVq))return _0x1c0bd2?.[r(1584)](s=>s[r(794)]===_0x22af27)?.[r(1411)];{let s=this[r(738)][r(748)](this._prefix),l=JSON[r(1148)](e[r(1213)](s,"{}"));return Object[r(653)](l)}}async[t(1540)](){let r=t,s=this[r(738)][r(748)](this[r(1302)]),l=JSON[r(1148)](e[r(1023)](s,"{}"));return Object[r(1712)](l)}[t(1734)](){return Promise[t(439)]()}get[t(1628)](){return!!this[t(738)]}}class dg{constructor(r,s){let l=t;this[l(1038)]=r,this[l(368)]=s,this._qosDB=Nn?tt:oi?wx:null}async[t(1274)](){}get[t(1302)](){let r=t;return r(1227)+"_"+this[r(1038)]}async[t(645)](r){let s=t,l=this[s(738)][s(495)+s(713)](this[s(1302)]);return JSON[s(1148)](e[s(1164)](l,"{}"))[r]}async set(r,s){let l=t;if(e[l(1460)]===e.asxHL){let h=this[l(738)][l(495)+l(713)](this[l(1302)]),m=JSON[l(1148)](e[l(1525)](h,"{}"));return m[s||r[this[l(368)]]]=r,this[l(738)][l(989)+l(713)](this[l(1302)],JSON.stringify(m)),s||r[this[l(368)]]}else return!!(e[l(514)](this[l(1807)+l(791)],this[l(361)+"s"][l(374)])||e[l(842)](this[l(1807)+"ndex"],this[l(361)+"s"].length-1)&&e[l(1569)](this.currentEndpointTriesCount,this.maxRetries))}async[t(1801)](r){let s=t,l=this._qosDB[s(495)+"geSync"](this[s(1302)]),h=JSON[s(1148)](l||"{}");return h[r]=void 0,this._qosDB[s(989)+s(713)](this[s(1302)],JSON[s(588)+"y"](h))}async[t(972)](){let r=t;return this[r(738)]["clearSto"+r(675)]()}async keys(){let r=t,s=this[r(738)].getStorageInfoSync(this[r(1302)]),l=JSON[r(1148)](s||"{}");return Object[r(653)](l)}async[t(1540)](){let r=t;if(e.YRyrh(e[r(725)],e[r(1467)])){let s=this._qosDB[r(495)+"geInfoSync"](this[r(1302)]),l=JSON[r(1148)](e[r(1502)](s,"{}"));return Object[r(1712)](l)}else this[r(402)]=!0,this[r(1356)]()}[t(1734)](){return Promise.resolve()}get[t(1628)](){return!!this[t(738)]}}function Tl(c,r){let s=t;if(Nn||Nn)return new dg(c,r);if(e[s(392)](dr,ai)&&e.jbvjk!=typeof indexedDB)return new ag(c,r);if((dr||ai)&&e[s(339)]("undefined",typeof localStorage))return new cg(c,r);throw new Error(s(1233)+s(1350)+"d")}class lg{constructor(){let r=t;this["_interva"+r(1178)+"Id"]=null,this[r(1270)+"l"]=36e5,this._qosDB=e[r(906)](Tl,e.zfEDt,e[r(690)])}async[t(1270)+t(1640)](){let r=t,s={dbRyF:e[r(838)]};if(e[r(1281)](e[r(656)],e[r(656)])){let l=this._options[r(1392)+r(622)+r(582)](_0x387cc4,_0x191550);this[r(1749)+r(1605)+r(723)](_0xafee(s[r(1297)],{code:_0x27b529,reason:_0x4678fe,wasClean:!0,willReconnect:l})),l&&this[r(1356)]()}else e[r(1259)](clearInterval,this[r(1270)+r(1178)+"Id"]),this[r(1270)+"lTimeoutId"]=setInterval(()=>{let l=r;this[l(665)+l(1101)]()},this._interval)}async openDB(){let r=t,s={eYcSl:function(l,h){return e[$(1489)](l,h)},dBFAA:e[r(1372)],japAm:e[r(1008)]};await this[r(738)][r(1274)]()[r(1792)](()=>{let l=r;if(s[l(316)](s[l(1596)],s.japAm))return new _0x269c25(_0x544c30);this["_interva"+l(1640)]()})}async["flushExp"+t(1101)](){let r=t,s={qkUjk:function(m,E,v){return m(E,v)},SQBNm:function(m,E,v){return m(E,v)},zhNfG:function(m,E){return m!==E},BhMnM:r(1854),EWXBD:"ToMVI"};(await this[r(738)]?.[r(1540)]()||[])[r(1722)](({timestamp:m})=>m<Date[r(1391)]())[r(1735)](m=>{let E=r;s[E(1537)](s.BhMnM,s.EWXBD)?this[E(738)]?.[E(1801)](m[E(557)+"id"]):(TEcSfw[E(669)](_0x240ef5,_0x54c081,74),TEcSfw[E(1013)](_0x3927ea,_0x26a1ca,_0x1b0191))})}async[t(1801)](r){let s=t;return this._qosDB?.[s(1801)](r)}async[t(1876)](r,s){let l=t;return this[l(738)]?.[l(1876)]({message_id:r,timestamp:s})}async[t(645)](r){return this[t(738)]?.get(r)}async[t(1734)](){let r=t;e[r(453)](clearInterval,this._intervalTimeoutId),await this[r(738)]?.[r(1734)]()}get[t(1628)](){return this._qosDB?.isReady}}function Ta(c){let r=t,s=!!this[r(1095)][r(1257)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[r(1246)](cn,c[r(757)][r(816)],e[r(1496)],"2"),h=l&&cn(c[r(757)][r(816)],r(1688)+r(789)+"ck","1"),m=l&&e.ouwbR(cn,c[r(757)].headers,e[r(1651)],"1"),E=m?e[r(1864)](lr,c.message[r(816)],r(1688)+r(1671)+"sgid")?.[r(615)](",")[r(1722)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:h,isAckCleanupMessage:m,ackMsgIds:E}}async function Cl(){let c=t;return this["_QoSMana"+c(749)]||(this["_QoSMana"+c(749)]=new lg),this["_QoSMana"+c(749)][c(1628)]||await this[c(1409)+"ger"].openDB(),this[c(1409)+c(749)]}async function ug(c,r){let s=t,{enableAutoAck:l}=this._options,h=cn(c[s(757)][s(816)],s(1235),"1"),m=e[s(493)](cn,c.message[s(816)],e.GbIzI,"1"),E=Ta[s(1653)](this,c);if(e[s(1808)](l,h)){let{SeqID:v,LogID:p,service:C,LogIDNew:O,method:F}=c[s(757)];this._sendAck({SeqID:v,LogID:p,LogIDNew:O,service:C,method:F,headers:[{key:e.GbIzI,value:"1"},{key:"ack_id",value:e[s(1778)](O,"")},{key:e.vGrVf,value:"0"}]})}m&&!E[s(1761)]&&this[s(1749)+s(1588)+"ageEvent"](c),r()}async function fg(c,r){let s=t;this[s(1112)](e.IyljS,c[s(757)]),r()}async function hg(c,r){let s=t,l=e[s(453)](sn,await e[s(1121)](kl,c[s(1056)]));try{if(s(1555)!==s(1555))this[s(953)](_0x78323e,_0x5d8ede);else if(e[s(1811)](l.payload,Uint8Array)){let h=e[s(1542)](this[s(1095)][s(521)+s(1692)],Object)?{force:!!this[s(1095)][s(521)+"ncoding"].force,encoding:this[s(1095)][s(521)+s(1692)][s(1353)]?this[s(1095)][s(521)+s(1692)][s(1353)].replace(/\s/g,"")[s(735)+s(1173)]():""}:{force:!1,encoding:this._options[s(521)+s(1692)]?this[s(1095)][s(521)+s(1692)].replace(/\s/g,"")["toLowerC"+s(1173)]():""},m=l[s(521)+s(1692)]?l["payloadE"+s(1692)][s(530)](/\s/g,"")[s(735)+s(1173)]():"",E=e[s(1542)](this[s(1095)]["payloadT"+s(800)],Object)?{force:!!this[s(1095)][s(1581)+s(800)][s(512)],type:this[s(1095)][s(1581)+s(800)][s(1027)]?this[s(1095)][s(1581)+s(800)][s(1027)][s(530)](/\s/g,"")[s(735)+s(1173)]():""}:{force:!1,type:this[s(1095)][s(1581)+"ype"]?this[s(1095)].payloadType[s(530)](/\s/g,"")[s(735)+s(1173)]():""},v=l[s(1581)+"ype"]?l[s(1581)+s(800)][s(530)](/\s/g,"")[s(735)+s(1173)]():"",p=E[s(512)]?E[s(1027)]:v||E.type,C=h.force?h[s(1353)]:m||h[s(1353)],O=[s(360)+"in;chars"+s(660),e[s(333)],e.bAljC,s(1819)],F=[e[s(1850)],"binary"];this[s(1095)]["enableTr"+s(661)+"extPayload"]&&O[s(409)](p)&&(!C||F.includes(C))?l["textPayl"+s(1266)]=e.VGYoi(Al,l[s(1642)],0,l[s(1642)][s(1267)+"th"]):l["textPayl"+s(1266)]=""}else l[s(1634)+s(1266)]=""}catch(h){l["textPayl"+s(1266)]="",console[s(1635)](h)}c[s(757)]=l,e[s(1060)](r)}function xg(c,r,s){let l=t,h={rlQty:function(C,O){return e[$(819)](C,O)},gWVuH:function(C,O){return e[$(331)](C,O)},JGWsq:function(C,O){return e[$(1758)](C,O)},ySMMx:function(C,O){return e[$(808)](C,O)},ewZkR:function(C,O){return e[$(1044)](C,O)},KNtfR:function(C,O){return e[$(1517)](C,O)}},m=e[l(1413)](s,8192),E=e[l(1759)](m,1),v=null,p=m;return function(C){let O=l;if(h.rlQty(C,1)||C>E)return h.gWVuH(c,C);h.JGWsq(p+C,m)&&(v=h[O(353)](c,m),p=0);let F=r[O(1653)](v,p,p+=C);return h[O(925)](7,p)&&(p=h[O(1017)](7|p,1)),F}}let pg=4294967295;function gg(c,r,s){let l=t;return e[l(1066)](RangeError,e[l(614)](e[l(686)](e.jDoex,c)+e[l(1048)]+e[l(1778)](r,1)+e[l(1600)],s))}function mg(c,r,s){let l=t;if(e[l(625)](s,pg))throw new Error(e[l(1737)]);let h=3;for(;e[l(742)](h,0);){let m=255&s;e[l(1890)](Da,m,c,e[l(1195)](r,h)),s>>>=8,h--}return e[l(1387)](r,4)}function wg(c,r){let s=t,l=0,h=r,m=e.aDqzD(r,4);for(;e.FeDOa(h,m);){let{value:E,offset:v}=e[s(1240)](Ca,c,h);h=v,l=e[s(471)](l<<8,0),l+=E}return{value:l,offset:m}}function _g(c,r,s){let l=t,h=(l(1229)+"3").split("|"),m=0;for(;;){switch(h[m++]){case"0":if(e[l(970)](c.length,40))return e[l(1085)](Aa(c,r,s),s);continue;case"1":if(!c)return s;continue;case"2":if(r[l(644)+"e"])return r[l(644)+"e"](c,s)+s;continue;case"3":return e[l(1301)](Aa,c,r,s)+s;case"4":if(r.write)return e[l(1711)](r[l(1639)](c,s),s);continue}break}}function yg(c,r){let s=t,l=new fe(e[s(700)](e.zrQyB(e[s(1543)](e[s(911)](c[e[s(1429)](r,4)],24),e.vgPRm(c[r+5],16)),e.DIGEh(c[e[s(646)](r,6)],8)),c[r+7]),e[s(320)](e[s(1384)](e.DIGEh(c[r+0],24),c[e[s(605)](r,1)]<<16)|c[e.gGBnx(r,2)]<<8,c[e[s(862)](r,3)]),!0);return r+=8,{value:l,offset:e.MwqDZ(r,8)}}function Eg(c,r,s){let l=t;if(e[l(1181)](e[l(1751)],e[l(1127)]))_0x187a4d["textPayl"+l(1266)]="",_0x29ea33[l(1635)](_0x4157d7);else{let h=c[l(1422)],m=c.high;return r[s]=e[l(854)](m,24),r[e[l(1374)](s,1)]=e[l(840)](e.vYmdv(m,16),255),r[e[l(1310)](s,2)]=m>>>8&255,r[e[l(605)](s,3)]=e.ZfRkI(255,m),r[e[l(1113)](s,4)]=h>>>24,r[s+5]=e.otJOh(e[l(1781)](h,16),255),r[e.nADDE(s,6)]=e[l(1258)](e.SHTBt(h,8),255),r[e[l(1108)](s,7)]=e[l(1670)](255,h),s+=8,s}}function Ca(c,r){let s=t;return e.FtAdL(s(1388),e[s(440)])?!!this[s(738)]:c[s(1563)+"8"]?{value:c.readUInt8(r),offset:e[s(1175)](r,1)}:{value:255&c[r],offset:e[s(399)](r,1)}}function Da(c,r,s){let l=t;return r.writeUint8?r[l(446)+"t8"](c,s):r[s]=e[l(840)](255,c),e[l(771)](s,1)}let bg=function(c){let r=t;return e.cFyGJ(e.FZbUy,e[r(357)])?new Uint8Array(c):this._socket[r(1682)]},vg=e[t(1261)](e[t(753)],typeof Buffer)?Buffer[t(1347)+t(991)]:e[t(519)](xg,bg,Uint8Array[t(497)+"e"][t(1551)]),Sg=16,Ra=32;function Ig(c){let r=t,s=0,l={};for(let h=0;e[r(1611)](h,c.length);h++)l[c[h].cursor_name]=e[r(1577)](Il,c[h][r(1234)+r(1566)]),s+=e[r(605)](14,l[c[h][r(1234)+r(1566)]]);return[s,l]}function Dl(c,r,s){let l=t,h={rYRJv:function(C,O){return e[$(1673)](C,O)},FXrPU:function(C,O){return C(O)},FAXJQ:l(536),XUEej:e[l(348)],quPFD:"8|10|3|5"+l(1053)+l(1508),cwKOI:function(C,O,F,j){return e.YzfGb(C,O,F,j)},YENHB:e[l(974)],OoQVV:e[l(758)],rAcOP:e[l(1548)],jhhsC:function(C,O,F,j){return e[l(1e3)](C,O,F,j)},EXlwo:function(C,O,F,j){return e[l(1216)](C,O,F,j)},luxYJ:l(564)+l(1882),AJiPn:e.wgSIl},[m,E]=e[l(568)](Ig,c),v=vg(m),p=0;return c[l(1735)](C=>{let O=l,F={cqrxH:function(j,K){return h[$(1488)](j,K)},SNeEi:function(j,K){return h[$(1587)](j,K)}};if(h[O(1122)]===h.XUEej)F[O(1343)](_0x10fa79,this["_pingPon"+O(1093)+"Id"]),F[O(912)](_0x264a16,this[O(1054)+O(326)+O(591)]),this[O(1289)+O(1093)+"Id"]=null,this[O(1054)+O(326)+"tId"]=null;else{let j=h[O(1704)].split("|"),K=0;for(;;){switch(j[K++]){case"0":p=h[O(490)](Eg,fe.fromNumber(C.cursor||r),v,p);continue;case"1":console[O(1635)](h[O(587)],p);continue;case"2":console[O(1635)](h[O(1723)],p);continue;case"3":console[O(1635)](h[O(1664)],p);continue;case"4":console[O(1635)](O(412)+O(546),p);continue;case"5":p=h[O(540)](mg,v,p,C[O(336)]||0);continue;case"6":p=h[O(559)](_g,C.cursor_name,v,p);continue;case"7":p=h[O(559)](Da,E[C["cursor_n"+O(1566)]],v,p);continue;case"8":console[O(1635)](h[O(388)],C,C[O(336)]);continue;case"9":console[O(1635)](h[O(532)],p);continue;case"10":p=Da(0,v,p);continue}break}}}),{frameType:Ra,headers:[{key:e[l(356)],value:s}],payload:v}}function Ag(c){let r=t,s=0,l=[];for(;e[r(1732)](s,c[r(1267)+"th"]);){let{offset:h}=e[r(1313)](Ca,c,s);s=h;let m={cursor_name:"",cursor:0,service:0},{value:E,offset:v}=wg(c,s);m[r(336)]=E,s=v;let{value:p,offset:C}=e[r(1706)](Ca,c,s);s=C,m[r(1234)+r(1566)]=e[r(1216)](Al,c,s,e.RzQiY(s,p)),s+=p;let{value:O,offset:F}=e.HMcwd(yg,c,s);m.cursor=O[r(716)](),s=F,l[r(607)](m)}return l}function kg(){let c=t;return{frameType:Ra,headers:[{key:e.tQcon,value:e[c(1509)]}],payload:void 0}}class Tg{constructor(r,s,l){let h=t;this[h(626)+h(1471)]=r,this[h(1710)+h(1433)]=s,this[h(629)+h(1719)]=l,this._qosDB=e[h(737)](Tl,this[h(626)+h(1471)],e.sussm)}async openDB(){let r=t;await this[r(738)][r(1274)]()}async[t(1721)+"rs"](){let r=t;if(!this[r(738)][r(1628)])return;let s=this[r(629)+"Strategy"],l=await this[r(738)][r(1540)]();switch(console[r(1635)](e.sWuCq,l),s){case e[r(719)]:return l&&l.length?Dl(l,0,this[r(1710)+"ileName"]):void 0;case e[r(463)]:return;case e[r(777)]:return l&&l[r(374)]?Dl(l,0,this[r(1710)+"ileName"]):e[r(1060)](kg)}}async[t(1876)](r,s,l){let h=t;if(e[h(1599)]!==e.lgjra)return console[h(1635)](e[h(483)],r,s,l),this[h(738)][h(1876)]({cursor_name:r,cursor:s,service:l});_0x47ae50.log(_0x229f47)}async[t(1541)+"rs"](r){let s=t,l=e[s(1886)](Ag,r);for(let h of l)console[s(1635)](e[s(1106)],l),await this[s(738)][s(1876)](h)}async[t(645)](r){let s=t;return(await this[s(738)][s(645)](r))?.[s(1504)]}async[t(1734)](){let r=t;await this[r(738)][r(1734)]()}["updateCu"+t(1546)+t(1275)](r){let s=t,l={YjJQV:function(h,m){return h>m},Sncug:function(h,m){return e[$(922)](h,m)},DQNsy:function(h,m){return h+m}};if(e[s(1396)](e[s(648)],s(806)))this[s(1710)+s(1433)]=r;else{if(zCOkPz[s(852)](_0x4fe7fb,_0x58ca02))throw new _0x48c32b(s(1530)+s(1047)+"e");let h=3;for(;zCOkPz[s(517)](h,0);){let m=255&_0x45f0e5;_0x4ca1c6(m,_0x824ff5,zCOkPz[s(1672)](_0xbe90a,h)),_0x2cf9c9>>>=8,h--}return _0x35b163+4}}get isReady(){let r=t;return this[r(738)][r(1628)]}}let Cg=t(560)+t(1171);async function Rl(c){let r=t;if(!this[r(1095)].enableQoS)return null;let{aID:s,fpID:l,messageStrategy:h}=this._options,m=e[r(1241)](c,Cg);try{return e[r(1079)]!==e[r(718)]?(this[r(1777)+r(1300)]?c&&this["_cursorM"+r(1300)]["updateCu"+r(1546)+"Name"](c):this["_cursorM"+r(1300)]=new Tg(l+"_"+s+"_"+m,m,h),this["_cursorM"+r(1300)].isReady||await this[r(1777)+r(1300)].openDB(),this[r(1777)+r(1300)]):{bytes:_0x111c42,offset:0,limit:_0x5f5de2[r(374)]}}catch{return null}}async function Dg(c,r){let s=t,l={ZsFRi:function(K,V){return e[$(870)](K,V)},Wzzoz:function(K,V){return e.JVcvh(K,V)},uyGlx:function(K,V){return e[$(717)](K,V)},LTYAN:function(K,V){return e[$(355)](K,V)},vGubE:function(K,V){return e[$(324)](K,V)},JNyrt:function(K,V){return e.snFnx(K,V)}},h=e[s(1494)](cn,c[s(757)][s(816)],e[s(535)],"-1"),m=e[s(493)](cn,c[s(757)].headers,e.GbIzI,"1"),E=lr(c[s(757)].headers,e[s(1319)]),v=e[s(1716)](Number,lr(c.message[s(816)],"x_fronti"+s(805)))||0,p=Ta[s(1653)](this,c),C=e.VGYoi(cn,c[s(757)][s(816)],s(1434)+"s","2"),O=e.OjGrW(lr,c[s(757)].headers,e[s(1578)]),F=e[s(1836)](Number,lr(c[s(757)].headers,e.tfVhE));if(p[s(1761)])return e[s(1402)](r);let j=p[s(859)+s(486)]?await Cl[s(1653)](this):null;if(e.dWDES(c[s(757)][s(336)],0)&&m&&!h||e[s(499)](c[s(757)][s(336)],0))if(e[s(697)](e.yTYfk,s(1361))){if(E&&p[s(859)+"sage"]&&j)return!!!await j[s(645)](E)&&(this[s(1749)+s(1480)+s(1064)](c),await j[s(1876)](E,e.VUArE(Date[s(1391)](),v))),e[s(1597)](r);if(C){let K=await Rl[s(1653)](this);if(!K)return this[s(1749)+s(1480)+s(1064)](c),r();let V=await K[s(645)](O)??-1;if(V<F)this["_dispatc"+s(1480)+s(1064)](c),K[s(1876)](O,F,c[s(757)][s(336)]);else throw new Error(s(394)+" message"+s(547)+F+(s(462)+s(1459)+s(1523)+"r ")+V);return e[s(1326)](r)}return this["_dispatchMessage"+s(1064)](c),e.HrILm(r)}else _0x221742=_0x531dcd(_0xccb004),_0x393d1a|=lnsIiy[s(915)](lnsIiy.Wzzoz(127,_0x184b38),14),128&_0x47ea09&&(_0x44c190=_0x204b11(_0x1dbf74),_0x16c190|=lnsIiy[s(915)](lnsIiy[s(603)](127,_0x56c58a),21),lnsIiy[s(603)](128,_0x4a6347)&&(_0x2402ce=_0x2cd1ed(_0x482d66),_0x4056f8=lnsIiy[s(1589)](127,_0x1fcb8e),128&_0x259802&&(_0x1744b5=lnsIiy[s(594)](_0x211386,_0x2305df),_0x520848|=lnsIiy[s(520)](127,_0x1f7d41)<<7)))}async function Rg(c,r){let s=t,l=Ta[s(1653)](this,c);if(!l[s(859)+s(486)])return e[s(1060)](r);let h=await Cl[s(1653)](this);if(l["isAckCle"+s(574)+s(767)]&&l[s(548)+"s"][s(374)])for(let m of l[s(548)+"s"])await h[s(1801)](m);e[s(1355)](r)}async function Pg(c,r){let s=t,l={AcaOM:"function",nyOlK:function(p,C){return e.ZXntN(p,C)},GtlFh:function(p){return e[$(1597)](p)},uDWKV:function(p,C,O){return e.wwwpQ(p,C,O)},UHjdL:e[s(853)]},h=e[s(1569)](c[s(757)].frameType,Sg),m=e.QPxgH(c.message[s(843)+"e"],Ra);if(e[s(1808)](!h,!m))return r();let E=lr(c[s(757)].headers,e.tQcon);if(!E)return e[s(1355)](r);let v=await Rl[s(1653)](this,E);if(!v)return e[s(632)](r);if(h)if(e[s(832)]===e.ZKGEP){let p=await v[s(1721)+"rs"](),C={frameType:p?.[s(843)+"e"],SeqID:fe[s(438)+"er"](this._seqId++),LogID:fe.fromNumber(this._options["logIDGen"+s(850)]()),service:9e3,method:5,headers:p?.[s(816)],payload:p?.[s(1642)]},O=S(C);this[s(1528)]&&this[s(1528)][s(1795)+"te"]&&this._ws[s(699)](O)}else return typeof _0xb5254e===OVbfGy[s(960)]?_0xa8d0d4(_0x42f064):(_0x4b291e instanceof _0x19b9d2&&OVbfGy[s(868)](_0x1c22cd,_0x3da7ea),_0x51352a(_0x47eb11,OVbfGy[s(1212)](_0x230a58))?new _0x558619(_0x57428c,_0x85d99a):_0x279124);if(m)if(e[s(1273)](e[s(385)],e.KafuD)){let p=l[s(1648)](_0x280ea4,l[s(1868)],{message:s(1339)});this[s(1720)+"econnect"]&&this[s(1720)+s(869)](p)}else{let p=c.message[s(1642)];p&&v.setCursors(p)}}let Og=async function(c,r){let s=t;this[s(402)]=!1,e.ufuKo(clearTimeout,this[s(1356)+"ionTimeo"+s(411)]),e[s(1305)](r)},Lg=async function(c,r){let s=t;if(!this._ws||this._ws[s(1795)+"te"]!==this[s(628)])return e[s(1363)](r);let{pingInterval:l}=this[s(1095)];this["_endpoin"+s(595)]?.["resetEnd"+s(571)+s(544)]();for(let m=0;m<this[s(629)+"Queue"][s(374)];m++){let E=this[s(629)+s(1299)][m];if(e.sRELa(this[s(1528)].readyState,this[s(628)])&&e[s(616)](null,E))this[s(1528)]&&this[s(1528)][s(699)](E),this[s(629)+s(1299)][m]=null;else break}this[s(629)+s(1299)]=this[s(629)+s(1299)][s(1722)](m=>!!m),this["_pingPon"+s(1093)+"Id"]=e[s(1036)](setTimeout,()=>this._ping(),l),this[s(1749)+s(579)+"nt"](c),this._isBrowser&&this[s(1528)]&&(this[s(1528)][s(598)+"pe"]=this[s(889)+s(800)]);let h=this[s(1208)+"tManager"]?.[s(1668)+s(498)+"nt"]();this._debug(s(1333)+h+s(671)),r()},Ng=async function(c,r){let s=t,l={XVZpM:function(h,m,E){return e.XbqCN(h,m,E)},eLhah:function(h,m){return h(m)}};if(e[s(488)](e.VHeFJ,e[s(1124)])){let h=this[s(1208)+s(595)]?.[s(1668)+s(498)+"nt"]();this[s(1112)](s(1333)+h),r()}else ITBPaA.XVZpM(_0xdb0da2,_0x29a1a3,96),ITBPaA[s(817)](_0x43f416,_0x4a9494,ITBPaA.eLhah(_0x481946,_0x457c2d))};class Mg extends Ia{constructor(r){let s=t,l={TUJdt:function(v,p,C,O){return v(p,C,O)},uRbwL:function(v,p,C){return v(p,C)},HSCmR:e[s(979)],VnKzB:function(v,p){return e[s(1836)](v,p)},BufLJ:function(v,p){return v===p},BJjPa:s(1253),JIAvt:function(v,p){return e[s(611)](v,p)},EikDr:s(344),jJADZ:function(v,p){return e[s(687)](v,p)},hTLep:e[s(985)],MbiNt:e.EnpoA,yMjCV:function(v,p){return v|p},ovdFh:function(v,p){return e[s(351)](v,p)},OSjuD:function(v,p){return e[s(507)](v,p)},Ojzrr:function(v,p){return e[s(896)](v,p)},ulAvj:function(v,p,C){return e[s(863)](v,p,C)},VGGJh:function(v,p,C){return e.jtscb(v,p,C)},DEymU:e[s(838)],CYngD:e.RlJxp,gEeaS:function(v,p){return e.vQZkD(v,p)},OzKxP:function(v,p){return e[s(1603)](v,p)}};super(),this[s(1239)+s(442)+s(1003)]=!0,this[s(633)+"er"]=dr,this[s(642)]=Xp,this[s(1440)+"T"]=Nn,this[s(1076)+"X"]=oi,this[s(620)+"r"]=ai,this[s(629)+s(1299)]=[],this[s(1208)+"tManager"]=null,this[s(376)+s(803)]=!1,this[s(889)+s(800)]=s(1641)+"fer",this["_connect"+s(1255)]=!1,this["_connect"+s(755)+"utId"]=null,this["_reconne"+s(326)+s(591)]=null,this["_pingPon"+s(1093)+"Id"]=null,this._seqId=0,this[s(402)]=!1,this[s(772)]="",this[s(1409)+"ger"]=null,this["_cursorM"+s(1300)]=null,this[s(825)+"sCounter"]=null,this._protocols=e[s(1845)],this.CLOSED=3,this.CONNECTING=0,this[s(628)]=1,this[s(468)]=2,this[s(553)]=v=>{let p=s;try{l.TUJdt(Sl,this,v,[Og,Lg,Ng])}catch(C){let O=l[p(1260)](ct,l[p(1303)],{message:C.message,code:an.OPEN_ERROR,error:C});this[p(1749)+"hErrorEv"+p(723)](O)}},this._onMessage=async v=>{let p=s;if(l.JIAvt(l[p(918)],l[p(918)])){let{pingInterval:C,pingFrequency:O}=this[p(1095)];if((l[p(1315)]("hi",v[p(1056)])&&l[p(1403)](p(1165),O)||l.JIAvt(l[p(1196)],O))&&(this[p(1202)+"ngTimer"](),this[p(1086)](p(1498)+"e_success",l[p(1558)]),this[p(1289)+p(1093)+"Id"]=l[p(1260)](setTimeout,this[p(790)][p(1615)](this),C)),l[p(1315)]("hi",v.data))return;try{Sl(this,v,[hg,ug,Rg,Pg,Dg,fg])}catch(F){let j=l[p(1260)](ct,l[p(1303)],{message:F[p(757)],code:an[p(1140)+p(1729)],error:F});this[p(1749)+"hErrorEv"+p(723)](j)}}else{let C=l.VnKzB(_0x198bb6,_0x32034e);this[p(1528)]&&l.BufLJ(this._ws[p(1795)+"te"],this[p(628)])&&(this._ws&&this._ws[p(699)](C),this[p(1112)](l[p(555)],_0x436dcd))}},this[s(1490)]=v=>{let p=s,C=this[p(1208)+p(595)]?.[p(780)+p(1461)+"es"](),O=this[p(1208)+p(595)]?.[p(1668)+"ntEndpoint"]();if(C&&!v.message)if(e.PgqTT(e[p(457)],e[p(1046)])){let F=p(1119)+O+(" fail, m"+p(327)+"es reached");this[p(1749)+p(1408)+p(723)](ct(e[p(979)],{message:F,code:an[p(466)+p(940)+"R"],error:v}));return}else _0x47634e.o=(F,j)=>_0x18baae.prototype[p(1117)+p(980)].call(F,j);this[p(1528)]&&e[p(474)](this[p(1528)].readyState,this.OPEN)&&this[p(1833)+p(762)](),this[p(1749)+p(1408)+p(723)](e[p(1050)](ct,e[p(979)],{message:v[p(757)],code:an[p(666)+p(1618)],error:v}))},this[s(1582)]=async v=>{let p=s;this[p(1248)+p(435)](),this[p(1202)+p(1495)](),this[p(420)+p(1269)+"rs"](),this[p(1528)]=null,this[p(1356)+p(1255)]=!1;let C=this[p(1208)+p(595)]?.[p(780)+p(1461)+"es"]();if(!C&&this["_navigat"+p(967)]()&&!this[p(376)+p(803)]){let O=this[p(1208)+p(595)]?.["getCurre"+p(498)+"nt"](),F=this[p(1095)][p(1392)+p(622)+p(582)](v.code,v[p(1586)]);this[p(1749)+p(1605)+p(723)](l[p(1338)](mt,p(1321),{code:1006,reason:v[p(1586)]||"connecti"+p(335)+p(785)+"wn reason, hostn"+p(1061)+O,willReconnect:F})),F&&this[p(1356)]();return}if(v[p(1513)]!==1e3&&this["_readyCl"+p(803)]){this[p(1749)+"hCloseEv"+p(723)](l.VGGJh(mt,l[p(1788)],{code:1e3,reason:l[p(867)]})),this[p(1208)+p(595)]?.[p(754)+p(571)+p(544)](),this[p(825)+p(1244)]?.["resetCou"+p(904)]();return}if(l[p(456)](1e3,v[p(1513)])&&C){let O=this[p(1208)+p(595)]?.[p(1668)+p(498)+"nt"](),F=v[p(1586)];F||(F=await sg(this._url)),F=p(1872)+"ng faile"+p(434)+F+(p(726)+p(1484))+O+(p(1708)+p(365)+p(781)),this[p(1749)+p(1605)+"ent"](mt(p(1321),{code:v[p(1513)],reason:F}));let j=p(1119)+O+(p(322)+p(327)+p(444)+"ed");this[p(1749)+"hErrorEv"+p(723)](ct(l[p(1303)],{message:j,code:an[p(466)+p(940)+"R"]})),this[p(1208)+p(595)]?.[p(754)+p(571)+p(544)](),this["_pingLos"+p(1244)]?.[p(1547)+p(904)]();return}if(l[p(982)](1e3,v[p(1513)])&&!v[p(1586)])if(p(1661)===p(1661)){let O=this[p(1208)+p(595)]?.["getCurre"+p(498)+"nt"]();this["_dispatc"+p(1605)+p(723)](mt(p(1321),{code:v[p(1513)],reason:p(1872)+"ng faile"+p(785)+"wn reason, hostn"+p(1061)+O})),this[p(1208)+p(595)]?.[p(754)+p(571)+"fig"](),this[p(825)+"sCounter"]?.["resetCou"+p(904)]();return}else _0x1c14ac[_0xb7dc18++]=foFKPa[p(395)](foFKPa[p(871)](_0x3ae940>>18,7),240),_0x3d055f[_0xc509dd++]=foFKPa[p(395)](foFKPa[p(1871)](foFKPa.Ojzrr(_0x45af2d,12),63),128);this[p(1749)+p(1605)+p(723)](v),this[p(1208)+p(595)]?.[p(754)+p(571)+"fig"](),this["_pingLos"+p(1244)]?.[p(1547)+p(904)]()},this.onclose=null,this[s(1425)]=null,this.onmessage=null,this[s(1399)]=null,this[s(1720)+s(869)]=null,this[s(1637)+s(1191)]=null,this["onStopIm"+s(1869)+s(1756)+"ct"]=null,this[s(1598)+"nLine"]=this._handleOnLine[s(1615)](this),this[s(1598)+"ffLine"]=this["_handleO"+s(334)][s(1615)](this),this["_handleP"+s(799)]=this._handlePageHide[s(1615)](this),this[s(1796)+"ageShow"]=this[s(1796)+"ageShow"][s(1615)](this),this[s(1095)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1400)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(985)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(777)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:m}=r,E=Array[s(406)](h)?h:e[s(1510)](e[s(1452)],typeof h)?[h]:[];if(!E||e[s(1218)](0,E[s(374)]))throw new Error(s(1105)+"rovide v"+s(338));if(!tg(m))throw new Error(e[s(482)]);Object[s(1206)](this[s(1095)],r),this[s(1208)+s(595)]=new vl(E,this[s(1095)].maxRetries),this[s(825)+"sCounter"]=new ig(this[s(1095)]["pingLoss"+s(1190)]),this[s(1095)][s(664)+s(638)]&&(this[s(402)]=!0,this[s(1356)]()),this[s(1095)][s(1571)+"tworkCha"+s(1885)]&&(this[s(1440)+"T"]||this[s(1076)+"X"]?this["_onPageN"+s(599)+s(1763)]():this[s(633)+"er"]&&this["_initGlo"+s(1475)+"Listener"]())}[t(1598)+t(1073)](){let r=t;this[r(1095)][r(325)+r(522)+"nect"]||this[r(376)+r(803)]||this[r(1623)+r(869)]()}["_handleO"+t(334)](){let r=t;this["_destroy"+r(1441)+"t"]();let s=e[r(570)](Sa,e[r(853)],{message:e[r(528)]});this[r(1126)+r(1869)+r(1756)+"ct"]&&this[r(1126)+"mediatelyReconnect"](s)}["_initGlo"+t(1475)+"Listener"](){let r=t;this[r(633)+"er"]&&window[r(1809)+r(496)](e[r(765)],this[r(1598)+r(1073)]),this._isBrowser&&window[r(1809)+r(496)](e.DNkbi,this[r(1598)+r(334)]),this[r(633)+"er"]&&window[r(1809)+r(496)](e[r(993)],this[r(1796)+r(799)]),this._isBrowser&&window["addEvent"+r(496)](e[r(1604)],this[r(1796)+"ageShow"])}[t(1767)+t(1475)+t(496)](){let r=t,s={SolXT:e[r(1217)],CNmAA:function(l,h){return e[r(1316)](l,h)},YdcSE:e[r(872)],GYcrP:e[r(1675)],MrWsq:function(l,h,m){return e[r(863)](l,h,m)}};if(e[r(1493)](e[r(1096)],e[r(1096)]))this[r(633)+"er"]&&window["removeEv"+r(729)+"ner"](e[r(765)],this[r(1598)+r(1073)]),this[r(633)+"er"]&&window["removeEventListe"+r(1473)](e.DNkbi,this[r(1598)+"ffLine"]),this[r(633)+"er"]&&window[r(1192)+r(729)+r(1473)](e[r(993)],this["_handleP"+r(799)]),this[r(633)+"er"]&&window[r(1192)+r(729)+r(1473)](e[r(1604)],this["_handleP"+r(1856)]);else{this["_clearPi"+r(1495)](),this["_pingPon"+r(1093)+"Id"]=s[r(1743)](_0x5d9f61,this[r(790)][r(1615)](this),this[r(1095)]["pingInte"+r(721)]);let l=()=>{let m=r;_0x2b1ed1("success"),this[m(953)](m(1498)+m(1583)+"s",l),this[m(953)](s.SolXT,h)},h=()=>{let m=r;s[m(647)](_0x5b1144,s[m(770)]),this[m(953)](s[m(1750)],l),this[m(953)](s[m(720)],h)};this.on(s.GYcrP,l),this.on(s[r(720)],h),this[r(790)]()}}_handlePageHide(r){let s=t;!r.persisted&&(this._isBrowser&&window["removeEv"+s(729)+s(1473)](e[s(993)],this[s(1796)+s(799)]),this[s(633)+"er"]&&window[s(1192)+s(729)+"ner"](e[s(1604)],this[s(1796)+s(1856)]),this.close()),this[s(633)+"er"]&&window["removeEventListe"+s(1473)](s(1686),this["_handleO"+s(1073)]),this._isBrowser&&window[s(1192)+s(729)+s(1473)](e[s(1880)],this["_handleO"+s(334)])}[t(1796)+t(1856)](r){let s=t;r.persisted&&(this[s(809)+s(967)]()&&(!this._ws||e[s(1505)](this._ws[s(1795)+"te"],this[s(628)])||e[s(1155)](this._ws[s(1795)+"te"],this[s(1431)+"NG"]))&&this[s(1598)+s(1073)](),this[s(633)+"er"]&&window[s(1809)+s(496)](e[s(765)],this[s(1598)+"nLine"]),this._isBrowser&&window[s(1809)+s(496)](e[s(1880)],this["_handleO"+s(334)]))}async _generateUrl(r){let s=t,{fpID:l,deviceID:h,bddID:m,ttwID:E,accessKey:v,aID:p,customParams:C={},enableAutoAck:O,enableQoS:F,QoSLevel:j,env:K}=this[s(1095)],V,We,dt;if(this._isBrowser||this[s(1076)+"X"]||this[s(1440)+"T"])if(e[s(470)](e.IpTSc,e[s(511)])){let Ht=!!this[s(1095)][s(1257)+"S"];if(!Ht)return{enabled:Ht,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let Mn=_0x4ae822(_0x247e3b.message[s(816)],"x_fronti"+s(418),"2"),Bg=Mn&&e.cpUKD(_0x1562f7,_0x525b86[s(757)][s(816)],e.iMlZL,"1"),Pl=Mn&&_0x32fe1c(_0xa1da8d[s(757)][s(816)],e[s(1651)],"1"),Fg=Pl?_0x5dfca2(_0x502ce0.message[s(816)],e[s(1579)])?.split(",")[s(1722)](_0x32e5b5)||[]:[];return{enabled:Ht,isQoSMessage:Mn,isQoSAck:Bg,isAckCleanupMessage:Pl,ackMsgIds:Fg}}else V=location&&e.yNBuA(e[s(1561)],location[s(1151)])?e[s(1430)]:e[s(1306)],We=r[s(530)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),dt=/^wss(.*:\/\/)/.test(r)?r:""+V+We;else V=s(987),We=r[s(530)](/(^http)((?:[s]*:\/\/))/,""),dt=/(^ws)((?:[s]*:\/\/))/[s(1538)](We)?We:""+V+We;let Be=m?e[s(1055)]:E?e[s(667)]:s(886)+"d",wt=m||E||h;if(e.wSJTH(!wt,!Be))throw new Error(s(1105)+s(879)+s(1341)+"viceID o"+s(610));let ur=e[s(779)]==typeof C?await e[s(1287)](C):C,gs=K?e[s(443)](rg,K[s(1393)],K[s(1172)]):{},ci=Object[s(1206)]({device_platform:e[s(1659)],version_code:"fws_1.0.0",access_key:v,fpid:l,aid:p,[Be]:wt,xsack:O?1:0,xaack:O?1:0,xsqos:F?1:0,qos_level:F?j:void 0,qos_sdk_version:2,...gs},ur),Pa=Object.keys(ci)[s(1049)]((Ht,Mn)=>ci[Mn]!==void 0?""+Ht+(Ht?"&":"?")+Mn+"="+ci[Mn]:Ht,"");return dt+s(1263)+Pa}async[t(1356)](){let r=t;if(!(this[r(1356)+r(1255)]||this[r(376)+r(803)])){this._connectLock=!0;try{let s=this[r(1208)+"tManager"]?.["checkCur"+r(1892)+"ointReac"+r(631)+r(1827)](),{timeoutInterval:l}=this[r(1095)];if(s){let m=this[r(1208)+"tManager"]?.[r(1668)+r(498)+"nt"](),E=this["_endpoin"+r(595)]?.[r(893)+r(703)+r(1779)+"UpdateCount"](),v=this[r(1208)+r(595)]?.["getCurre"+r(498)+r(398)+"ount"]();if(E)if(e[r(1092)](e[r(1625)],e[r(1875)])){let p=r(1119)+m+(" timeout"+r(1708)+"tries re"+r(1279)+"ill use "+r(1428)+r(1252))+E+(r(1701)+"y"),C=ct(e[r(979)],{message:p,code:an[r(466)+r(940)+"R"]});this[r(1112)](p),this["_dispatchErrorEv"+r(723)](C),this[r(772)]=await this["_generat"+r(658)](E),this._debug(r(1119)+E+" "+v+r(696)),this[r(420)+"sListeners"]()}else this[r(1112)](e[r(1741)],_0x5f1739.message),e[r(1305)](_0x506f3b);else{let p=r(1119)+m+(r(1129)+r(1708)+r(365)+r(781));this[r(1112)](p),this[r(1749)+r(1408)+r(723)](e[r(1481)](ct,e[r(979)],{message:p,code:an[r(466)+r(940)+"R"]}));return}}else{let m=this[r(1208)+r(595)]?.[r(1668)+"ntEndpoi"+r(347)+r(1176)](),E=this[r(1208)+r(595)]?.[r(1668)+r(498)+r(398)+r(1726)]();this._url=await this["_generat"+r(658)](m||""),this[r(1112)](r(1119)+m+" "+E+r(696)),this["_removeW"+r(1269)+"rs"]()}if(this[r(402)])this[r(402)]=!1;else{if(e.nnqNM!==e.nnqNM)return _0x3b8498||(_0x1581ba=_0x47480f[r(439)]()[r(1792)](_0x28c129.bind(_0x457ad0,r(1203)))),_0x2bdd17;{let m=e.QrEar(Sa,r(1392)+"t",{message:e[r(1616)]});this[r(1720)+r(869)]&&this[r(1720)+r(869)](m)}}let h=this[r(1208)+r(595)]?.[r(1668)+r(498)+"ntTriesCount"]()||0;e[r(625)](h,1)&&await this[r(1215)](e.adcXP(h,1)),this[r(1112)](r(1872)+r(533)+this[r(772)]+" protocols: "+this[r(1501)+"ls"]),this[r(1528)]=e[r(1782)](eg,{url:this[r(772)],protocols:[this._protocols],headers:this._options[r(1709)+r(1376)+"s"][r(1272)+"tpHeader"]},this[r(1095)].ws),(this._isBrowser||this._isWorker)&&this[r(1528)]&&(this[r(1528)][r(598)+"pe"]=this[r(889)+r(800)]),this._addWsListeners(),this[r(1356)+r(755)+r(411)]=setTimeout(this[r(1232)+"ut"][r(1615)](this),l)}catch(s){if(e[r(1395)]!==e[r(506)])throw this[r(1356)+r(1255)]=!1,s;this[r(1038)]=_0x57ceb2,this[r(368)]=_0x88018f,this[r(738)]=_0x325e84}}}["_clearTi"+t(435)](){let r=t;e.nwDom(clearTimeout,this[r(1356)+r(755)+r(411)]),this["_connect"+r(755)+"utId"]=null}[t(1202)+"ngTimer"](){let r=t;e[r(1077)](clearTimeout,this[r(1289)+r(1093)+"Id"]),e[r(1716)](clearTimeout,this[r(1054)+"ctTimeou"+r(591)]),this[r(1289)+r(1093)+"Id"]=null,this["_reconne"+r(326)+r(591)]=null}_debug(...r){let s=t;this._options[s(1045)]&&console[s(1635)][s(426)](console,[e[s(844)],...r])}[t(701)+t(1745)+"e"](r){let s=t,{initReconnectInterval:l,maxReconnectInterval:h,reconnectIntervalGrowFactor:m}=this[s(1095)],E=e[s(1318)](l,Math[s(1780)](m,e.qjEld(r,1)));return e.lxxfa(E,h)?h:E}_ping(){let r=t;if(this[r(1528)]&&e.vQlzJ(this[r(1528)].readyState,this.CONNECTING)){if(e[r(884)](e[r(1342)],"RvhTe"))return _0x2065d4[_0x4ea9f2]=_0x5bbde4,!0;this[r(1202)+r(1495)](),this[r(1289)+"gTimeoutId"]=e[r(1774)](setTimeout,this._ping.bind(this),this[r(1095)][r(706)+"rval"]);return}if(!this[r(1528)]||e.UcrZp(this[r(1528)][r(1795)+"te"],this[r(628)]))return void this[r(1623)+"econnect"]();this[r(1528)]&&this[r(1528)][r(699)]("hi"),this[r(1054)+"ctTimeou"+r(591)]=e[r(986)](setTimeout,this[r(1623)+r(869)+"Timeout"][r(1615)](this),this[r(1095)][r(775)+r(523)+r(1078)])}["_handleR"+t(869)+t(391)](){let r=t;if(e[r(931)](e[r(1051)],e[r(1130)]))this[r(825)+"sCounter"]?.[r(959)](),this[r(1086)](e[r(1217)],e[r(872)]),this["_pingLos"+r(1244)]?.checkReachMaxCount()?this._handleReconnect():this[r(790)]();else return r(1227)+"_"+this._DBName}[t(809)+t(967)](){let r=t;return this[r(1440)+"T"]||this[r(1076)+"X"]?this[r(1239)+r(442)+r(1003)]:(this._isBrowser||this[r(620)+"r"])&&this._options[r(1571)+"tworkCha"+r(1885)]?navigator.onLine:!0}["_handleR"+t(869)](){let r=t;!this[r(809)+r(967)]()||this["_readyCl"+r(803)]||(this._endpointManager?.[r(754)+"pointConfig"](),this[r(825)+r(1244)]?.[r(1547)+"nter"](),this[r(1528)]?this["_disconn"+r(762)](1001,e[r(1156)],!0):this[r(1356)]())}[t(1679)+t(599)+t(1763)](){let r=t,s={NMAqm:function(l,h,m){return e[$(1535)](l,h,m)},iTEjV:function(l,h,m){return e.IbCwr(l,h,m)}};if(e[r(1375)](e[r(408)],"GqCYT")){let l=0,h=[];for(;l<_0x508add[r(1267)+"th"];){let{offset:m}=YOApoc[r(939)](_0x53707d,_0x515521,l);l=m;let E={cursor_name:"",cursor:0,service:0},{value:v,offset:p}=YOApoc.NMAqm(_0x460283,_0x578d84,l);E[r(336)]=v,l=p;let{value:C,offset:O}=YOApoc[r(760)](_0x47a158,_0x13ed7b,l);l=O,E.cursor_name=_0x4ce287(_0x26b141,l,l+C),l+=C;let{value:F,offset:j}=_0x2cdcf7(_0x5af631,l);E.cursor=F.toNumber(),l=j,h.push(E)}return h}else this[r(1440)+"T"]?tt[r(1032)+r(923)+r(345)](({isConnected:l})=>{let h=r;this[h(1239)+h(442)+h(1003)]=l,l?this[h(1598)+h(1073)]():this["_handleO"+h(334)]()}):this[r(1076)+"X"]&&wx[r(1032)+r(923)+"hange"](({isConnected:l})=>{let h=r;this[h(1239)+h(442)+h(1003)]=l,l?this._handleOnLine():this[h(1598)+"ffLine"]()})}[t(1215)](r){let s=t,l={milps:s(1819),QTAzj:function(h,m){return e[s(1811)](h,m)},jEQil:function(h,m){return e[s(829)](h,m)},DDTgl:e[s(333)],weRjW:e.NeZRv,IaduN:s(581),OnLrr:function(h,m,E){return e[s(1655)](h,m,E)}};return new Promise(h=>{let m=s;if(l[m(1730)]===l[m(1366)])return LqhSEp.milps!=typeof _0x5a0868&&(LqhSEp[m(1262)](_0x5e6e64,_0x23876a)||_0x4c87a6[m(1762)]&&LqhSEp[m(1262)](_0x5924c2.buffer,_0xed2779))||LqhSEp.jEQil(LqhSEp[m(1658)],typeof _0x34e3e4)?"":(_0x166c4a[m(1148)](_0x318c7e),LqhSEp.DDTgl);l[m(1204)](setTimeout,h,this[m(701)+m(1745)+"e"](r))})}_disconnect(r=1e3,s="",l=!1){let h=t,m={fpxNV:function(E,v){return e.tsdYO(E,v)},UEqYl:function(E,v,p){return e[$(428)](E,v,p)},ASTEA:function(E,v){return E|v},ZgCCO:function(E,v){return e[$(507)](E,v)},udolX:function(E,v,p){return e[$(370)](E,v,p)}};if(e[h(1493)](e[h(549)],e[h(549)])){if(!this[h(1528)])return;this[h(948)+"WebSocket"](r,s,l)}else{for(_0x58258f>>>=0;QWKPZv[h(798)](_0x42633c,128);)QWKPZv[h(1614)](_0x49be06,_0x3c35d3,QWKPZv[h(1110)](QWKPZv[h(575)](127,_0x4b5473),128)),_0x10382a>>>=7;QWKPZv.udolX(_0x48c5d9,_0x30ef42,_0x53a478)}}[t(1232)+"ut"](){let r=t,s=this[r(1208)+r(595)]?.[r(1668)+r(498)+"nt"]();this._debug(r(1119)+s+r(1129)),this[r(1833)+"ect"](1001,e.DItJe,!0)}[t(899)](r){let s=t;if(e.qcCLU(e[s(1522)],e[s(450)]))return _0x41b59c.log(_0x3a22a5),!1;{let l=e.JEgQe(Gt,r);this[s(1528)]&&e.dacQy(this[s(1528)][s(1795)+"te"],this[s(628)])&&(this[s(1528)]&&this[s(1528)][s(699)](l),this[s(1112)](e[s(1657)],r))}}[t(420)+t(1269)+"rs"](){let r=t,s=(r(874)+"2").split("|"),l=0;for(;;){switch(s[l++]){case"0":this[r(1528)]["removeEv"+r(729)+"ner"](e[r(1479)],this[r(984)+"ge"]);continue;case"1":this[r(1528)][r(1192)+r(729)+r(1473)](e[r(838)],this[r(1582)]);continue;case"2":this[r(1528)][r(1192)+r(729)+r(1473)](e[r(979)],this._onError);continue;case"3":if(!this[r(1528)])return;continue;case"4":this._ws[r(1192)+r(729)+r(1473)](e[r(1822)],this._onOpen);continue}break}}[t(1014)+t(1693)](){let r=t,s=e[r(1858)].split("|"),l=0;for(;;){switch(s[l++]){case"0":this[r(1528)].addEventListener(r(757),this[r(984)+"ge"]);continue;case"1":this[r(1528)][r(1809)+r(496)](e[r(838)],this[r(1582)]);continue;case"2":if(!this[r(1528)])return;continue;case"3":this[r(1528)]["addEvent"+r(496)](e[r(979)],this._onError);continue;case"4":this[r(1528)][r(1809)+r(496)]("open",this._onOpen);continue}break}}[t(1553)+t(1349)](r=1e3,s=""){let l=t;if(e.GKLLu(e[l(1357)],e[l(1447)])){if(!this["_navigat"+l(967)]()||this[l(376)+l(803)])return;this._endpointManager?.[l(754)+"pointCon"+l(544)](),this._pingLossCounter?.resetCounter(),this[l(1528)]?this["_disconn"+l(762)](1001,e.iVngV,!0):this[l(1356)]()}else try{this._ws&&this[l(1528)][l(1321)](r,s)}catch{}}["_destroy"+t(1441)+"t"](r=1e3,s="",l=!1){let h=t;if(this[h(1202)+"ngTimer"](),this[h(1248)+h(435)](),this[h(420)+"sListeners"](),this[h(1553)+h(1349)](1e3,s),this[h(1356)+h(1255)]=!1,l&&this[h(809)+h(967)]()&&!this[h(376)+h(803)]){if(this[h(1208)+h(595)]?.["checkRea"+h(1461)+"es"]()){let E=this["_endpoin"+h(595)]?.[h(1668)+h(498)+"nt"]();this[h(1749)+"hCloseEvent"](e[h(370)](mt,e.oKVNt,{code:1006,reason:"connect "+E+(" timeout"+h(1708)+h(365)+h(781)),wasClean:!0}))}else if(h(1453)!==h(527)){let E=this[h(1095)][h(1392)+h(622)+h(582)](r,s);this[h(1749)+h(1605)+h(723)](e[h(1864)](mt,e[h(838)],{code:r,reason:s,wasClean:!0,willReconnect:E})),E&&this[h(1356)]()}else return e[h(862)](_0x52e8c9(4)[h(1040)]("0"),_0x2f3c3c(_0x41370f,2)[h(1390)](16)).slice(-4);return}this[h(809)+h(967)]()||this[h(376)+"osed"]?this[h(1749)+"hCloseEv"+h(723)](mt(e[h(838)],{code:r,reason:"bye"})):this["_dispatc"+h(1605)+h(723)](e[h(460)](mt,e[h(838)],{code:1006,reason:e[h(976)]})),this._ws=null,this[h(1208)+h(595)]?.[h(754)+"pointCon"+h(544)](),this[h(825)+h(1244)]?.["resetCou"+h(904)]()}[t(1749)+t(579)+"nt"](r){let s=t;this.emit(s(481),r),this.onopen&&this.onopen(r)}["_dispatchMessage"+t(1064)](r){let s=t;this[s(1086)](e[s(1479)],r),this[s(1377)+"e"]&&this[s(1377)+"e"](r)}[t(1749)+t(1588)+t(577)](r){let s=t;this[s(1086)](e[s(1585)],r),this[s(1637)+s(1191)]&&this[s(1637)+s(1191)](r)}["_dispatc"+t(1408)+t(723)](r){let s=t;this[s(1086)](e[s(979)],r),this[s(1425)]&&this[s(1425)](r)}["_dispatc"+t(1605)+t(723)](r){let s=t;this[s(1086)](e[s(838)],r),this[s(733)]&&this[s(733)](r)}get[t(598)+"pe"](){let r=t;return this[r(1528)]?this[r(1528)].binaryType:this[r(889)+r(800)]}set binaryType(r){let s=t;this[s(889)+s(800)]=r,this[s(1528)]&&(this._ws[s(598)+"pe"]=r)}get[t(880)+"nt"](){let r=t;return this[r(1208)+r(595)]?.[r(1668)+r(498)+r(398)+r(1726)]()||0}get[t(1482)+t(1647)](){let r=t,s=this[r(629)+r(1299)].reduce((l,h)=>(l+=h&&h[r(1267)+"th"]||0,l),0);return e[r(746)](s,this[r(1528)]?this._ws["buffered"+r(1647)]:0)}get[t(567)+"ns"](){return this[t(1528)]?this._ws.extensions:""}get[t(1151)](){let r=t;if(e[r(1575)](e.Zojgr,e.YFzrk))return this._ws?this._ws[r(1151)]:"";{let s=this[r(1208)+r(595)]?.[r(1668)+r(498)+"nt"]();this[r(1112)](r(1119)+s+r(1129)),this[r(1833)+r(762)](1001,r(1282)+" try reconnecting",!0)}}get[t(1795)+"te"](){let r=t;return this[r(1528)]?this[r(1528)].readyState:this[r(1095)][r(664)+r(638)]?this[r(1431)+"NG"]:this[r(1620)]}get url(){let r=t;return this[r(1528)]?this[r(1528)][r(1682)]:this[r(772)]}[t(1321)](r=1e3,s){let l=t;if(this[l(376)+l(803)]=!0,this[l(1248)+l(435)](),this[l(1202)+l(1495)](),this[l(1767)+l(1475)+"Listener"](),this["_QoSMana"+l(749)]?.[l(1734)](),!this[l(1528)])return void this[l(1112)](e.CJWgv);if(e.eSZvK(this._ws[l(1795)+"te"],this[l(1620)])||this[l(1528)][l(1795)+"te"]===this[l(468)])return void this[l(1112)](e[l(655)]);this[l(948)+"WebSocket"](r,s)}async send(r,s){let l=t;if(e[l(597)](null,r))throw new Error(e[l(732)]);e[l(1510)](e[l(1100)],typeof r)&&(r=JSON[l(588)+"y"](r)),e[l(801)](e[l(1452)],typeof r)&&!e[l(1844)](r,ArrayBuffer)&&!(r.buffer&&e[l(393)](r.buffer,ArrayBuffer))&&(r=JSON.stringify(r));let h=await e[l(1238)](kl,r),m=e.cPvxS(ng,r),{method:E=0,service:v=this[l(1095)][l(336)],logID:p=this._options[l(1354)+l(850)](),headers:C=this[l(1095)].headers,payloadEncoding:O=this[l(1095)]["payloadE"+l(1692)],payloadType:F=this[l(1095)].payloadType,logIDNew:j=this[l(1095)]["logIDNew"+l(1617)]["enableAutoGenera"+l(890)+"ew"]?e[l(689)](i,this[l(1095)][l(1773)+l(1617)].userIp):""}=s||{};if(!v)throw new Error(l(1105)+l(1131)+" valid service");let K={SeqID:fe[l(438)+"er"](this[l(1443)]++),LogID:fe[l(438)+"er"](p),service:v,method:E,headers:C,payloadEncoding:O instanceof Object?O.encoding?O[l(1353)]:"":O,payloadType:e[l(1161)](F,Object)?F[l(1027)]?F[l(1027)]:m:F||m,payload:h,LogIDNew:j},V=e[l(1288)](Gt,K);return this[l(1528)]&&e[l(1298)](this[l(1528)].readyState,this[l(628)])?(this[l(1528)]&&this._ws[l(699)](V),this[l(1112)](e[l(1506)],K)):e[l(1290)](this[l(629)+"Queue"][l(374)],this[l(1095)][l(883)+l(1118)+"ength"])?(this["_message"+l(1299)][l(607)](V),this._debug(l(952),K)):(this[l(629)+l(1299)][l(467)](),this["_message"+l(1299)][l(607)](V)),{seqID:this[l(1443)],logID:p,logIDNew:j}}async[t(1392)+"t"](r){let s=t,{url:l}=e[s(773)](r,{}),h=Array[s(406)](l)?l:e.SrEiN(e[s(1452)],typeof l)?[l]:[];r&&Object[s(1206)](this[s(1095)],r),h&&h[s(374)]?this._endpointManager=new vl(h,this[s(1095)].maxRetries):this["_endpoin"+s(595)]?.[s(754)+"pointCon"+s(544)](),this[s(825)+"sCounter"]?.["resetCou"+s(904)](this[s(1095)][s(640)+s(1190)]),this["_readyCl"+s(803)]=!1,this._ws&&e[s(1565)](this[s(1528)].readyState,this[s(1620)])?this[s(1833)+"ect"](1e3,e[s(1398)],!0):(this[s(402)]=!0,this._connect())}async[t(1654)](){let r=t;!this[r(1356)+r(1255)]&&(this._endpointManager?.[r(754)+r(571)+r(544)](),this["_pingLos"+r(1244)]?.["resetCou"+r(904)](),this[r(376)+"osed"]=!1,this._isInit=!0,this._connect())}[t(1809)+t(496)](r,s){this.on(r,s)}[t(524)+t(1064)](r){let s=t;if(e[s(1063)](s(1613),e[s(739)])){let{type:l}=r;this[s(1086)](l,r)}else{if(!this[s(1528)])return;this[s(948)+"WebSocket"](_0x362283,_0x433fb7,_0x5e6417)}}[t(1192)+t(729)+t(1473)](r,s){let l=t,h={wUjNj:e[l(1197)],Hyaer:"open",duXTA:e[l(838)]};if(e[l(1369)](e[l(1549)],l(1529)))this[l(953)](r,s);else{let m=h[l(1102)][l(615)]("|"),E=0;for(;;){switch(m[E++]){case"0":this[l(1528)][l(1809)+l(496)](qiDVCP[l(1487)],this[l(553)]);continue;case"1":this._ws.addEventListener(l(1532),this[l(1490)]);continue;case"2":if(!this[l(1528)])return;continue;case"3":this[l(1528)][l(1809)+l(496)](qiDVCP[l(381)],this._onClose);continue;case"4":this._ws[l(1809)+l(496)](l(757),this[l(984)+"ge"]);continue}break}}}[t(973)](){let r=t,s={estAs:function(l,h){return e[$(710)](l,h)},ZqSFI:e[r(630)],apFBA:e[r(1675)],mveRp:e[r(1217)]};return new Promise((l,h)=>{let m=r,E={DbNpa:e[m(872)],MvnNl:"ping_once_success"};this[m(1202)+m(1495)](),this[m(1289)+m(1093)+"Id"]=e[m(485)](setTimeout,this[m(790)][m(1615)](this),this[m(1095)]["pingInte"+m(721)]);let v=()=>{let C=m;s[C(1624)](l,s.ZqSFI),this[C(953)](s[C(1865)],v),this[C(953)](s[C(1420)],p)},p=()=>{let C=m;h(E.DbNpa),this[C(953)](E.MvnNl,v),this[C(953)](C(1498)+C(1011)+"t",p)};this.on(e[m(1675)],v),this.on(e[m(1217)],p),this[m(790)]()})}}})(),Me[N(1861)+N(1407)]=Re[N(1861)+N(1407)],Me[N(1667)+N(1427)]=Re[N(1667)+N(1427)],Me[N(1764)+"e"]=Re[N(1764)+"e"],Me[N(1064)]=Re.Event,Me[N(505)]=Re[N(505)],Me[N(727)+N(452)+N(1867)]=Re[N(727)+N(452)+N(1867)],Me[N(452)+N(1867)]=Re[N(452)+N(1867)],Me[N(565)+"t"]=Re.OpenEvent,Me[N(804)+"tEvent"]=Re["Reconnec"+N(1863)],Me[N(1226)+N(1407)]=Re[N(1226)+N(1407)],Me.createErrorEvent=Re[N(1552)+"rorEvent"],Me[N(590)+N(1221)+"nt"]=Re[N(590)+N(1221)+"nt"],Me["createOp"+N(1879)]=Re.createOpenEvent,Me["createRe"+N(354)+N(1867)]=Re[N(1180)+N(354)+N(1867)],Me[N(1629)+N(807)]=Re["decodedF"+N(807)],Me[N(1713)+"ame"]=Re[N(1713)+N(1566)];for(ta in Re)[N(1861)+"oseEvent",N(1667)+N(1427),N(1764)+"e","Event","FWS",N(727)+N(452)+N(1867),"MessageEvent","OpenEvent",N(804)+N(1863),N(1226)+N(1407),N(1552)+N(1427),N(590)+N(1221)+"nt",N(827)+N(1879),N(1180)+N(354)+N(1867),"decodedF"+N(807),N(1713)+N(1566)][N(1103)](ta)===-1&&(Me[ta]=Re[ta]);var ta;Object[N(951)+N(980)](Me,N(580)+"le",{value:!0})});import{existsSync as c1,openSync as d1}from"node:fs";import{mkdir as l1}from"node:fs/promises";import{dirname as u1}from"node:path";import{fileURLToPath as f1}from"node:url";function x1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function el(t=Z()){return c1(t.libEntry)?t.libEntry:f1(new URL("../index.ts",import.meta.url))}async function lp(t={}){let e=t.paths??Z(),n=t.entryOverride??el(e),i=x1(e,process.env.COZE_BRIDGE_LOG_MODE);await l1(u1(i),{recursive:!0});let o=d1(i,"a"),d=n.endsWith(".ts")?["--import","tsx/esm",n,"--daemon"]:[n,"--daemon"],u=rt(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[us]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return h1.info("daemon spawned",{pid:u.pid,entry:n}),{pid:u.pid,entry:n}}var h1,us,fa=et(()=>{"use strict";Zt();re();Te();h1=q("spawn-daemon"),us="COZE_BRIDGE_DAEMON"});import{spawn as l2}from"node:child_process";import{mkdir as u2,unlink as f2,writeFile as h2}from"node:fs/promises";import{dirname as x2,join as p2}from"node:path";function ri(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function g2(t){if(!t)return"";let e=Object.entries(t).map(([n,i])=>` <key>${ri(n)}</key>
|
|
21
|
+
<string>${ri(i)}</string>`).join(`
|
|
22
22
|
`);return e?`
|
|
23
23
|
<key>EnvironmentVariables</key>
|
|
24
24
|
<dict>
|
|
25
25
|
${e}
|
|
26
|
-
</dict>`:""}function
|
|
26
|
+
</dict>`:""}function m2(t,e){return new Promise((n,i)=>{let o=l2(t,e,{stdio:["ignore","pipe","pipe"]}),a="";o.stderr?.on("data",d=>{a+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${a.trim()}`))})})}var ni,xs,wa,ll,Pp=et(()=>{"use strict";re();ni=q("supervisor.launchd"),xs="ai.coze.bridge",wa=m2,ll={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>
|
|
@@ -31,8 +31,8 @@ ${e}
|
|
|
31
31
|
<string>${xs}</string>
|
|
32
32
|
<key>ProgramArguments</key>
|
|
33
33
|
<array>
|
|
34
|
-
<string>${
|
|
35
|
-
<string>${
|
|
34
|
+
<string>${ri(t.nodeBin)}</string>
|
|
35
|
+
<string>${ri(t.entry)}</string>
|
|
36
36
|
<string>--daemon</string>
|
|
37
37
|
</array>
|
|
38
38
|
<key>RunAtLoad</key>
|
|
@@ -42,13 +42,13 @@ ${e}
|
|
|
42
42
|
<key>ThrottleInterval</key>
|
|
43
43
|
<integer>10</integer>
|
|
44
44
|
<key>StandardOutPath</key>
|
|
45
|
-
<string>${
|
|
45
|
+
<string>${ri(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${
|
|
47
|
+
<string>${ri(t.logFile)}</string>${g2(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function
|
|
50
|
+
`},configPath(t){return p2(t.homeDir,"Library","LaunchAgents",`${xs}.plist`)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t);if(await u2(x2(i),{recursive:!0}),await h2(i,this.renderConfig(t),"utf8"),ni.info("plist written",{plistPath:i,activate:n}),!n)return;await wa("launchctl",["unload","-w",i]).catch(a=>ni.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(a)})),await wa("launchctl",["load","-w",i]),ni.info("launchd job loaded",{label:xs});let o=process.getuid?.()??0;await wa("launchctl",["kickstart","-k",`gui/${o}/${xs}`]),ni.info("launchd job kickstarted",{label:xs,uid:o})},async uninstall(t){let e=this.configPath(t);await wa("launchctl",["unload","-w",e]).catch(n=>ni.warn("launchctl unload failed (ignored)",{err:String(n)})),await f2(e).catch(n=>{if(n.code!=="ENOENT")throw n}),ni.info("launchd job removed",{plistPath:e})}}});import{spawn as w2}from"node:child_process";import{mkdir as _2,unlink as y2,writeFile as E2}from"node:fs/promises";import{dirname as b2,join as Op}from"node:path";function ya(t,e){return t.isRoot?e:["--user",...e]}function S2(t){return t?Object.entries(t).map(([e,n])=>{let i=n.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function Ea(t,e){return new Promise((n,i)=>{let o=w2(t,e,{stdio:["ignore","pipe","pipe"]}),a="";o.stderr?.on("data",d=>{a+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${a.trim()}`))})})}var _a,ii,v2,ul,Lp=et(()=>{"use strict";re();_a=q("supervisor.systemd"),ii="coze-bridge.service",v2="/etc/systemd/system";ul={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
|
+
${S2(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?
|
|
65
|
+
`},configPath(t){return t.isRoot?Op(v2,ii):Op(t.homeDir,".config","systemd","user",ii)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await _2(b2(i),{recursive:!0}),await E2(i,this.renderConfig(t),"utf8"),_a.info("systemd unit written",{unitPath:i,mode:o,activate:n}),await Ea("systemctl",ya(t,["daemon-reload"])),await Ea("systemctl",ya(t,n?["enable","--now",ii]:["enable",ii])),_a.info("systemd unit enabled",{unitName:ii,mode:o,activate:n})},async uninstall(t){let e=this.configPath(t);await Ea("systemctl",ya(t,["disable","--now",ii])).catch(n=>_a.warn("systemctl disable failed (ignored)",{err:String(n)})),await y2(e).catch(n=>{if(n.code!=="ENOENT")throw n}),await Ea("systemctl",ya(t,["daemon-reload"])).catch(()=>{}),_a.info("systemd unit removed",{unitPath:e})}}});import{spawn as I2}from"node:child_process";import{join as A2}from"node:path";function Np(t,e){return new Promise((n,i)=>{let o=I2(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),a="";o.stderr?.on("data",d=>{a+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${a.trim()}`))})})}var fl,ba,hl,Mp=et(()=>{"use strict";re();fl=q("supervisor.taskscheduler"),ba="CozeBridge",hl={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,52 +86,52 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return SI(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 Lp("schtasks",["/Create","/SC","ONLOGON","/TN",Ea,"/TR",r,"/RU",t.userName,"/F"]),fl.info("task scheduler entry created",{task:Ea,logFile:t.logFile})},async uninstall(t){await Lp("schtasks",["/Delete","/TN",Ea,"/F"]).catch(e=>fl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),fl.info("task scheduler entry removed",{task:Ea})}}});var Mp={};La(Mp,{buildContext:()=>RI,getSupervisor:()=>kI,launchdSupervisor:()=>ll,systemdSupervisor:()=>ul,taskSchedulerSupervisor:()=>hl});import{homedir as II,userInfo as AI}from"node:os";function kI(t=process.platform){switch(t){case"darwin":return ll;case"linux":return ul;case"win32":return hl;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function CI(){let t={};for(let e of TI){let r=process.env[e];r&&(t[e]=r)}return t}function RI(){let t=Z();return{nodeBin:process.execPath,entry:el(t),logFile:t.logFile,homeDir:II(),userName:AI().username,isRoot:process.getuid?.()===0,env:CI()}}var TI,Bp=rt(()=>{"use strict";Re();fa();Pp();Op();Np();TI=["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 jl=j("acp-installer-warmup"),dm=["claude-code","codex"];async function ql(t={}){let e=t.ensure??xr,i=(await Promise.allSettled(dm.map(async o=>{let c=await e(o);jl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&jl.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))})}xn();ne();import{readdir as Im}from"node:fs/promises";import{mkdir as Vl,readFile as vm,writeFile as Jl}from"node:fs/promises";import{join as Ha}from"node:path";var Sm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function pr(t,e,r){await Vl(t,{recursive:!0});let i=Sm[e],o=Ha(t,i);return await Jl(o,r??"","utf8"),o}async function Ga(t,e,r){let i=Ha(t,".claude");await Vl(i,{recursive:!0});let o=Ha(i,"settings.local.json"),c={};try{let u=await vm(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await Jl(o,JSON.stringify(c,null,2),"utf8"),o}var et=j("agent-detail-sync"),Am=6e4,km=5*6e4,ks=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Im(r)}catch(o){et.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}et.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Pe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){et.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){et.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),et.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){et.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){et.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Pe(e,this.opts.paths);if(!i){et.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){et.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),g=x?Math.min(x.currentDelay*2,km):Am;this.retryQueue.set(e,{dueAt:Date.now()+g,currentDelay:g});return}if(o.agentId&&o.agentId!==e){et.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"?(et.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&et.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){et.debug("detail sync: no diff",{agentId:e});return}await Ue(i,this.opts.paths),et.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}),et.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await pr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var ld=jt(Tu(),1);import{createHash as oy}from"node:crypto";import{lstat as rd,mkdir as id,readFile as bo,readdir as x0,rm as sd,stat as p0,writeFile as od}from"node:fs/promises";import{homedir as ay}from"node:os";import{dirname as cy,join as _e,normalize as dy,relative as dd,resolve as ad,sep as g0}from"node:path";import{Readable as m0}from"node:stream";import{pipeline as w0}from"node:stream/promises";import Jm from"events";import it from"fs";import{EventEmitter as Hc}from"node:events";import lf from"node:stream";import{StringDecoder as Zm}from"node:string_decoder";import hf from"node:path";import kr from"node:fs";import{dirname as dw,parse as lw}from"path";import{EventEmitter as ww}from"events";import Ec from"assert";import{Buffer as $n}from"buffer";import*as Ou from"zlib";import _w from"zlib";import{posix as yr}from"node:path";import{basename as Kw}from"node:path";import so from"fs";import Rt from"fs";import Uu from"path";import{win32 as r_}from"node:path";import $u from"path";import Tf from"node:fs";import y_ from"node:assert";import{randomBytes as Cf}from"node:crypto";import ie from"node:fs";import Fe from"node:path";import Rf from"fs";import po from"node:fs";import Pi from"node:path";import ct from"node:fs";import k_ from"node:fs/promises";import co from"node:path";import{join as Hf}from"node:path";import at from"node:fs";import qf from"node:path";var $m=Object.defineProperty,Vm=(t,e)=>{for(var r in e)$m(t,r,{get:e[r],enumerable:!0})},Cu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ym=t=>!!t&&typeof t=="object"&&(t instanceof Zn||t instanceof lf||Xm(t)||Qm(t)),Xm=t=>!!t&&typeof t=="object"&&t instanceof Hc&&typeof t.pipe=="function"&&t.pipe!==lf.Writable.prototype.pipe,Qm=t=>!!t&&typeof t=="object"&&t instanceof Hc&&typeof t.write=="function"&&typeof t.end=="function",qt=Symbol("EOF"),Wt=Symbol("maybeEmitEnd"),gn=Symbol("emittedEnd"),Ds=Symbol("emittingEnd"),xi=Symbol("emittedError"),Os=Symbol("closed"),Ru=Symbol("read"),Ls=Symbol("flush"),Pu=Symbol("flushChunk"),_t=Symbol("encoding"),_r=Symbol("decoder"),He=Symbol("flowing"),pi=Symbol("paused"),Sr=Symbol("resume"),Ge=Symbol("buffer"),nt=Symbol("pipes"),je=Symbol("bufferLength"),Va=Symbol("bufferPush"),Ns=Symbol("bufferShift"),Qe=Symbol("objectMode"),ke=Symbol("destroyed"),Ja=Symbol("error"),Za=Symbol("emitData"),Du=Symbol("emitEnd"),Ya=Symbol("emitEnd2"),kt=Symbol("async"),Xa=Symbol("abort"),Ms=Symbol("aborted"),gi=Symbol("signal"),Fn=Symbol("dataListeners"),ot=Symbol("discarded"),mi=t=>Promise.resolve().then(t),ew=t=>t(),tw=t=>t==="end"||t==="finish"||t==="prefinish",nw=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,rw=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),uf=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[Sr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},iw=class extends uf{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)}},sw=t=>!!t.objectMode,ow=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Zn=class extends Hc{[He]=!1;[pi]=!1;[nt]=[];[Ge]=[];[Qe];[_t];[kt];[_r];[qt]=!1;[gn]=!1;[Ds]=!1;[Os]=!1;[xi]=null;[je]=0;[ke]=!1;[gi];[Ms]=!1;[Fn]=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");sw(e)?(this[Qe]=!0,this[_t]=null):ow(e)?(this[_t]=e.encoding,this[Qe]=!1):(this[Qe]=!1,this[_t]=null),this[kt]=!!e.async,this[_r]=this[_t]?new Zm(this[_t]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Ge]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[nt]});let{signal:r}=e;r&&(this[gi]=r,r.aborted?this[Xa]():r.addEventListener("abort",()=>this[Xa]()))}get bufferLength(){return this[je]}get encoding(){return this[_t]}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[Qe]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[kt]}set async(t){this[kt]=this[kt]||!!t}[Xa](){this[Ms]=!0,this.emit("abort",this[gi]?.reason),this.destroy(this[gi]?.reason)}get aborted(){return this[Ms]}set aborted(t){}write(t,e,r){if(this[Ms])return!1;if(this[qt])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"&&(r=e,e="utf8"),e||(e="utf8");let i=this[kt]?mi:ew;if(!this[Qe]&&!Buffer.isBuffer(t)){if(rw(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(nw(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Qe]?(this[He]&&this[je]!==0&&this[Ls](!0),this[He]?this.emit("data",t):this[Va](t),this[je]!==0&&this.emit("readable"),r&&i(r),this[He]):t.length?(typeof t=="string"&&!(e===this[_t]&&!this[_r]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[_t]&&(t=this[_r].write(t)),this[He]&&this[je]!==0&&this[Ls](!0),this[He]?this.emit("data",t):this[Va](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[ke])return null;if(this[ot]=!1,this[je]===0||t===0||t&&t>this[je])return this[Wt](),null;this[Qe]&&(t=null),this[Ge].length>1&&!this[Qe]&&(this[Ge]=[this[_t]?this[Ge].join(""):Buffer.concat(this[Ge],this[je])]);let e=this[Ru](t||null,this[Ge][0]);return this[Wt](),e}[Ru](t,e){if(this[Qe])this[Ns]();else{let r=e;t===r.length||t===null?this[Ns]():typeof r=="string"?(this[Ge][0]=r.slice(t),e=r.slice(0,t),this[je]-=t):(this[Ge][0]=r.subarray(t),e=r.subarray(0,t),this[je]-=t)}return this.emit("data",e),!this[Ge].length&&!this[qt]&&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[qt]=!0,this.writable=!1,(this[He]||!this[pi])&&this[Wt](),this}[Sr](){this[ke]||(!this[Fn]&&!this[nt].length&&(this[ot]=!0),this[pi]=!1,this[He]=!0,this.emit("resume"),this[Ge].length?this[Ls]():this[qt]?this[Wt]():this.emit("drain"))}resume(){return this[Sr]()}pause(){this[He]=!1,this[pi]=!0,this[ot]=!1}get destroyed(){return this[ke]}get flowing(){return this[He]}get paused(){return this[pi]}[Va](t){this[Qe]?this[je]+=1:this[je]+=t.length,this[Ge].push(t)}[Ns](){return this[Qe]?this[je]-=1:this[je]-=this[Ge][0].length,this[Ge].shift()}[Ls](t=!1){do;while(this[Pu](this[Ns]())&&this[Ge].length);!t&&!this[Ge].length&&!this[qt]&&this.emit("drain")}[Pu](t){return this.emit("data",t),this[He]}pipe(t,e){if(this[ke])return t;this[ot]=!1;let r=this[gn];return e=e||{},t===Cu.stdout||t===Cu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[nt].push(e.proxyErrors?new iw(this,t,e):new uf(this,t,e)),this[kt]?mi(()=>this[Sr]()):this[Sr]()),t}unpipe(t){let e=this[nt].find(r=>r.dest===t);e&&(this[nt].length===1?(this[He]&&this[Fn]===0&&(this[He]=!1),this[nt]=[]):this[nt].splice(this[nt].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[ot]=!1,this[Fn]++,!this[nt].length&&!this[He]&&this[Sr]();else if(t==="readable"&&this[je]!==0)super.emit("readable");else if(tw(t)&&this[gn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[xi]){let i=e;this[kt]?mi(()=>i.call(this,this[xi])):i.call(this,this[xi])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Fn]=this.listeners("data").length,this[Fn]===0&&!this[ot]&&!this[nt].length&&(this[He]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Fn]=0,!this[ot]&&!this[nt].length&&(this[He]=!1)),e}get emittedEnd(){return this[gn]}[Wt](){!this[Ds]&&!this[gn]&&!this[ke]&&this[Ge].length===0&&this[qt]&&(this[Ds]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Os]&&this.emit("close"),this[Ds]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ke&&this[ke])return!1;if(t==="data")return!this[Qe]&&!r?!1:this[kt]?(mi(()=>this[Za](r)),!0):this[Za](r);if(t==="end")return this[Du]();if(t==="close"){if(this[Os]=!0,!this[gn]&&!this[ke])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[xi]=r,super.emit(Ja,r);let o=!this[gi]||this.listeners("error").length?super.emit("error",r):!1;return this[Wt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Wt](),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[Wt](),i}[Za](t){for(let r of this[nt])r.dest.write(t)===!1&&this.pause();let e=this[ot]?!1:super.emit("data",t);return this[Wt](),e}[Du](){return this[gn]?!1:(this[gn]=!0,this.readable=!1,this[kt]?(mi(()=>this[Ya]()),!0):this[Ya]())}[Ya](){if(this[_r]){let e=this[_r].end();if(e){for(let r of this[nt])r.dest.write(e);this[ot]||super.emit("data",e)}}for(let e of this[nt])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Qe]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Qe]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Qe])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[_t]?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",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[ot]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[qt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(ke,f),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(ke,f),this.pause(),i({value:x,done:!!this[qt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(ke,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((x,g)=>{o=g,i=x,this.once(ke,f),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ot]=!1;let t=!1,e=()=>(this.pause(),this.off(Ja,e),this.off(ke,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(Ja,e),this.once(ke,e),{next:r,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[Ge].length=0,this[je]=0;let e=this;return typeof e.close=="function"&&!this[Os]&&e.close(),t?this.emit("error",t):this.emit(ke),this}static get isStream(){return Ym}},aw=it.writev,An=Symbol("_autoClose"),vt=Symbol("_close"),wi=Symbol("_ended"),le=Symbol("_fd"),Qa=Symbol("_finished"),Jt=Symbol("_flags"),ec=Symbol("_flush"),yc=Symbol("_handleChunk"),bc=Symbol("_makeBuf"),Ci=Symbol("_mode"),Bs=Symbol("_needDrain"),Cr=Symbol("_onerror"),Rr=Symbol("_onopen"),tc=Symbol("_onread"),Ir=Symbol("_onwrite"),kn=Symbol("_open"),Et=Symbol("_path"),bn=Symbol("_pos"),Tt=Symbol("_queue"),Ar=Symbol("_read"),nc=Symbol("_readSize"),Vt=Symbol("_reading"),_i=Symbol("_remain"),rc=Symbol("_size"),$s=Symbol("_write"),zn=Symbol("_writing"),Vs=Symbol("_defaultFlag"),Kn=Symbol("_errored"),Gc=class extends Zn{[Kn]=!1;[le];[Et];[nc];[Vt]=!1;[rc];[_i];[An];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[Kn]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[Et]=t,this[nc]=e.readSize||16*1024*1024,this[Vt]=!1,this[rc]=typeof e.size=="number"?e.size:1/0,this[_i]=this[rc],this[An]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[Ar]():this[kn]()}get fd(){return this[le]}get path(){return this[Et]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[kn](){it.open(this[Et],"r",(t,e)=>this[Rr](t,e))}[Rr](t,e){t?this[Cr](t):(this[le]=e,this.emit("open",e),this[Ar]())}[bc](){return Buffer.allocUnsafe(Math.min(this[nc],this[_i]))}[Ar](){if(!this[Vt]){this[Vt]=!0;let t=this[bc]();if(t.length===0)return process.nextTick(()=>this[tc](null,0,t));it.read(this[le],t,0,t.length,null,(e,r,i)=>this[tc](e,r,i))}}[tc](t,e,r){this[Vt]=!1,t?this[Cr](t):this[yc](e,r)&&this[Ar]()}[vt](){if(this[An]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Cr](t){this[Vt]=!0,this[vt](),this.emit("error",t)}[yc](t,e){let r=!1;return this[_i]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[_i]<=0)&&(r=!1,this[vt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[Ar](),!1;case"error":return this[Kn]?!1:(this[Kn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},cw=class extends Gc{[kn](){let t=!0;try{this[Rr](null,it.openSync(this[Et],"r")),t=!1}finally{t&&this[vt]()}}[Ar](){let t=!0;try{if(!this[Vt]){this[Vt]=!0;do{let e=this[bc](),r=e.length===0?0:it.readSync(this[le],e,0,e.length,null);if(!this[yc](r,e))break}while(!0);this[Vt]=!1}t=!1}finally{t&&this[vt]()}}[vt](){if(this[An]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.closeSync(t),this.emit("close")}}},lo=class extends Jm{readable=!1;writable=!0;[Kn]=!1;[zn]=!1;[wi]=!1;[Tt]=[];[Bs]=!1;[Et];[Ci];[An];[le];[Vs];[Jt];[Qa]=!1;[bn];constructor(t,e){e=e||{},super(e),this[Et]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[Ci]=e.mode===void 0?438:e.mode,this[bn]=typeof e.start=="number"?e.start:void 0,this[An]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[bn]!==void 0?"r+":"w";this[Vs]=e.flags===void 0,this[Jt]=e.flags===void 0?r:e.flags,this[le]===void 0&&this[kn]()}emit(t,...e){if(t==="error"){if(this[Kn])return!1;this[Kn]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[Et]}[Cr](t){this[vt](),this[zn]=!0,this.emit("error",t)}[kn](){it.open(this[Et],this[Jt],this[Ci],(t,e)=>this[Rr](t,e))}[Rr](t,e){this[Vs]&&this[Jt]==="r+"&&t&&t.code==="ENOENT"?(this[Jt]="w",this[kn]()):t?this[Cr](t):(this[le]=e,this.emit("open",e),this[zn]||this[ec]())}end(t,e){return t&&this.write(t,e),this[wi]=!0,!this[zn]&&!this[Tt].length&&typeof this[le]=="number"&&this[Ir](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[wi]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[zn]||this[Tt].length?(this[Tt].push(t),this[Bs]=!0,!1):(this[zn]=!0,this[$s](t),!0)}[$s](t){it.write(this[le],t,0,t.length,this[bn],(e,r)=>this[Ir](e,r))}[Ir](t,e){t?this[Cr](t):(this[bn]!==void 0&&typeof e=="number"&&(this[bn]+=e),this[Tt].length?this[ec]():(this[zn]=!1,this[wi]&&!this[Qa]?(this[Qa]=!0,this[vt](),this.emit("finish")):this[Bs]&&(this[Bs]=!1,this.emit("drain"))))}[ec](){if(this[Tt].length===0)this[wi]&&this[Ir](null,0);else if(this[Tt].length===1)this[$s](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],aw(this[le],t,this[bn],(e,r)=>this[Ir](e,r))}}[vt](){if(this[An]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},ff=class extends lo{[kn](){let t;if(this[Vs]&&this[Jt]==="r+")try{t=it.openSync(this[Et],this[Jt],this[Ci])}catch(e){if(e?.code==="ENOENT")return this[Jt]="w",this[kn]();throw e}else t=it.openSync(this[Et],this[Jt],this[Ci]);this[Rr](null,t)}[vt](){if(this[An]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.closeSync(t),this.emit("close")}}[$s](t){let e=!0;try{this[Ir](null,it.writeSync(this[le],t,0,t.length,this[bn])),e=!1}finally{if(e)try{this[vt]()}catch{}}}},uw=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"]]),fw=t=>!!t.sync&&!!t.file,hw=t=>!t.sync&&!!t.file,xw=t=>!!t.sync&&!t.file,pw=t=>!t.sync&&!t.file,gw=t=>!!t.file,mw=t=>uw.get(t)||t,jc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=mw(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Fi=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=jc(c);if(o?.(f,d),fw(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if(hw(f)){let x=e(f,d);return u?x.then(()=>u(),u):x}else if(xw(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,d)}else if(pw(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),yw=_w.constants||{ZLIB_VERNUM:4736},Dt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},yw)),bw=$n.concat,Lu=Object.getOwnPropertyDescriptor($n,"concat"),Ew=t=>t,ic=Lu?.writable===!0||Lu?.set!==void 0?t=>{$n.concat=t?Ew:bw}:t=>{},Vn=Symbol("_superWrite"),Fs=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"}},sc=Symbol("flushFlag"),qc=class extends Zn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof Ou[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new Ou[e](t)}catch(r){throw new Fs(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 Fs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return Ec(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign($n.alloc(0),{[sc]: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}[Vn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=$n.from(t,e)),this.#e)return;Ec(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},ic(!0);let d;try{let f=typeof t[sc]=="number"?t[sc]:this.#r;d=this.#t._processChunk(t,f),ic(!1)}catch(f){ic(!1),this.#o(new Fs(f,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",f=>this.#o(new Fs(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[Vn]($n.from(f));for(let x=1;x<d.length;x++)u=this[Vn](d[x])}else u=this[Vn]($n.from(d));return r&&r(),u}},xf=class extends qc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Dt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Dt.Z_FINISH,t.fullFlushFlag=Dt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Dt.Z_SYNC_FLUSH),Ec(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)}}}},vw=class extends xf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Vn](t){return this.#e?(this.#e=!1,t[9]=255,super[Vn](t)):super[Vn](t)}},Sw=class extends xf{constructor(t){super(t,"Unzip")}},pf=class extends qc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Dt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Dt.BROTLI_OPERATION_FLUSH,super(t,e)}},Iw=class extends pf{constructor(t){super(t,"BrotliCompress")}},Aw=class extends pf{constructor(t){super(t,"BrotliDecompress")}},gf=class extends qc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Dt.ZSTD_e_end,t.fullFlushFlag=Dt.ZSTD_e_flush,super(t,e)}},kw=class extends gf{constructor(t){super(t,"ZstdCompress")}},Tw=class extends gf{constructor(t){super(t,"ZstdDecompress")}},Cw=(t,e)=>{if(Number.isSafeInteger(t))t<0?Pw(t,e):Rw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Rw=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Pw=(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]=mf(o):o===0?e[i-1]=0:(r=!0,e[i-1]=wf(o))}},Dw=t=>{let e=t[0],r=e===128?Lw(t.subarray(1,t.length)):e===255?Ow(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},Ow=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=mf(c):c===0?d=c:(i=!0,d=wf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Lw=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},mf=t=>(255^t)&255,wf=t=>(255^t)+1&255,Nw={};Vm(Nw,{code:()=>Wc,isCode:()=>Js,isName:()=>Mw,name:()=>uo});var Js=t=>uo.has(t),Mw=t=>Wc.has(t),uo=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"]]),Wc=new Map(Array.from(uo).map(t=>[t[1],t[0]])),Jn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");this.path=r?.path??Un(t,e,100),this.mode=r?.mode??i?.mode??En(t,e+100,8),this.uid=r?.uid??i?.uid??En(t,e+108,8),this.gid=r?.gid??i?.gid??En(t,e+116,8),this.size=r?.size??i?.size??En(t,e+124,12),this.mtime=r?.mtime??i?.mtime??oc(t,e+136,12),this.cksum=En(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Un(t,e+156,1);if(Js(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Un(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Un(t,e+265,32),this.gname=r?.gname??i?.gname??Un(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??En(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??En(t,e+337,8)??0,t[e+475]!==0){let d=Un(t,e+345,155);this.path=d+"/"+this.path}else{let d=Un(t,e+345,130);d&&(this.path=d+"/"+this.path),this.atime=r?.atime??i?.atime??oc(t,e+476,12),this.ctime=r?.ctime??i?.ctime??oc(t,e+488,12)}let c=256;for(let d=e;d<e+148;d++)c+=t[d];for(let d=e+156;d<e+512;d++)c+=t[d];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=Bw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Hn(t,e,100,o)||this.needPax,this.needPax=vn(t,e+100,8,this.mode)||this.needPax,this.needPax=vn(t,e+108,8,this.uid)||this.needPax,this.needPax=vn(t,e+116,8,this.gid)||this.needPax,this.needPax=vn(t,e+124,12,this.size)||this.needPax,this.needPax=ac(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Hn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Hn(t,e+265,32,this.uname)||this.needPax,this.needPax=Hn(t,e+297,32,this.gname)||this.needPax,this.needPax=vn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=vn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Hn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Hn(t,e+345,155,c)||this.needPax:(this.needPax=Hn(t,e+345,130,c)||this.needPax,this.needPax=ac(t,e+476,12,this.atime)||this.needPax,this.needPax=ac(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,vn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:uo.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Wc.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)}},Bw=(t,e)=>{let r=t,i="",o,c=yr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=yr.dirname(r),r=yr.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=yr.join(yr.basename(i),r),i=yr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Un=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),oc=(t,e,r)=>Fw(En(t,e,r)),Fw=t=>t===void 0?void 0:new Date(t*1e3),En=(t,e,r)=>Number(t[e])&128?Dw(t.subarray(e,e+r)):Uw(t,e,r),zw=t=>isNaN(t)?void 0:t,Uw=(t,e,r)=>zw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Hw={12:8589934591,8:2097151},vn=(t,e,r,i)=>i===void 0?!1:i>Hw[r]||i<0?(Cw(i,t.subarray(e,e+r)),!0):(Gw(t,e,r,i),!1),Gw=(t,e,r,i)=>t.write(jw(i,r),e,r,"ascii"),jw=(t,e)=>qw(Math.floor(t).toString(8),e),qw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",ac=(t,e,r,i)=>i===void 0?!1:vn(t,e,r,i.getTime()/1e3),Ww=new Array(156).join("\0"),Hn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Ww,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),io=class _f{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 Jn({path:("PaxHeader/"+Kw(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
|
-
`,
|
|
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("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Zw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Q=Zw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),yf=class extends Zn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=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))))}},fo=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},Yw=1024*1024,vc=Buffer.from([31,139]),Sc=Buffer.from([40,181,47,253]),Xw=Math.max(vc.length,Sc.length),ft=Symbol("state"),Gn=Symbol("writeEntry"),Kt=Symbol("readEntry"),cc=Symbol("nextEntry"),Nu=Symbol("processEntry"),Ct=Symbol("extendedHeader"),yi=Symbol("globalExtendedHeader"),mn=Symbol("meta"),Mu=Symbol("emitMeta"),we=Symbol("buffer"),$t=Symbol("queue"),wn=Symbol("ended"),dc=Symbol("emittedEnd"),jn=Symbol("emit"),De=Symbol("unzip"),zs=Symbol("consumeChunk"),Us=Symbol("consumeChunkSub"),lc=Symbol("consumeBody"),Bu=Symbol("consumeMeta"),Fu=Symbol("consumeHeader"),bi=Symbol("consuming"),uc=Symbol("bufferConcat"),Hs=Symbol("maybeEnd"),br=Symbol("writing"),_n=Symbol("aborted"),Gs=Symbol("onDone"),qn=Symbol("sawValidEntry"),js=Symbol("sawNullBlock"),qs=Symbol("sawEOF"),zu=Symbol("closeStream"),Qw=()=>!0,Bi=class extends ww{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[$t]=[];[we];[Kt];[Gn];[ft]="begin";[mn]="";[Ct];[yi];[wn]=!1;[De];[_n]=!1;[qn];[js]=!1;[qs]=!1;[br]=!1;[bi]=!1;[dc]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Gs,()=>{(this[ft]==="begin"||this[qn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Gs,t.ondone):this.on(Gs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Yw,this.filter=typeof t.filter=="function"?t.filter:Qw;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[zu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){fo(this,t,e,r)}[Fu](t,e){this[qn]===void 0&&(this[qn]=!1);let r;try{r=new Jn(t,e,this[Ct],this[yi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[js]?(this[qs]=!0,this[ft]==="begin"&&(this[ft]="header"),this[jn]("eof")):(this[js]=!0,this[jn]("nullBlock"));else if(this[js]=!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[Gn]=new yf(r,this[Ct],this[yi]);if(!this[qn])if(o.remain){let c=()=>{o.invalid||(this[qn]=!0)};o.on("end",c)}else this[qn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[jn]("ignoredEntry",o),this[ft]="ignore",o.resume()):o.size>0&&(this[mn]="",o.on("data",c=>this[mn]+=c),this[ft]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[jn]("ignoredEntry",o),this[ft]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ft]="body":(this[ft]="header",o.end()),this[Kt]?this[$t].push(o):(this[$t].push(o),this[cc]())))}}}[zu](){queueMicrotask(()=>this.emit("close"))}[Nu](t){let e=!0;if(!t)this[Kt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Kt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[cc]()),e=!1);return e}[cc](){do;while(this[Nu](this[$t].shift()));if(this[$t].length===0){let t=this[Kt];!t||t.flowing||t.size===t.remain?this[br]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[lc](t,e){let r=this[Gn];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[ft]="header",this[Gn]=void 0,r.end()),o.length}[Bu](t,e){let r=this[Gn],i=this[lc](t,e);return!this[Gn]&&r&&this[Mu](r),i}[jn](t,e,r){this[$t].length===0&&!this[Kt]?this.emit(t,e,r):this[$t].push([t,e,r])}[Mu](t){switch(this[jn]("meta",this[mn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=io.parse(this[mn],this[Ct],!1);break;case"GlobalExtendedHeader":this[yi]=io.parse(this[mn],this[yi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[mn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=e,e.linkpath=this[mn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[_n]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[_n])return r?.(),!1;if((this[De]===void 0||this.brotli===void 0&&this[De]===!1)&&t){if(this[we]&&(t=Buffer.concat([this[we],t]),this[we]=void 0),t.length<Xw)return this[we]=t,r?.(),!0;for(let d=0;this[De]===void 0&&d<vc.length;d++)t[d]!==vc[d]&&(this[De]=!1);let o=!1;if(this[De]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<Sc.length;d++)if(t[d]!==Sc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[De]===!1&&c)if(t.length<512)if(this[wn])this.brotli=!0;else return this[we]=t,r?.(),!0;else try{new Jn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[De]===void 0||this[De]===!1&&(this.brotli||o)){let d=this[wn];this[wn]=!1,this[De]=this[De]===void 0?new Sw({}):o?new Tw({}):new Aw({}),this[De].on("data",f=>this[zs](f)),this[De].on("error",f=>this.abort(f)),this[De].on("end",()=>{this[wn]=!0,this[zs]()}),this[br]=!0;let u=!!this[De][d?"end":"write"](t);return this[br]=!1,r?.(),u}}this[br]=!0,this[De]?this[De].write(t):this[zs](t),this[br]=!1;let i=this[$t].length>0?!1:this[Kt]?this[Kt].flowing:!0;return!i&&this[$t].length===0&&this[Kt]?.once("drain",()=>this.emit("drain")),r?.(),i}[uc](t){t&&!this[_n]&&(this[we]=this[we]?Buffer.concat([this[we],t]):t)}[Hs](){if(this[wn]&&!this[dc]&&!this[_n]&&!this[bi]){this[dc]=!0;let t=this[Gn];if(t&&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[jn](Gs)}}[zs](t){if(this[bi]&&t)this[uc](t);else if(!t&&!this[we])this[Hs]();else if(t){if(this[bi]=!0,this[we]){this[uc](t);let e=this[we];this[we]=void 0,this[Us](e)}else this[Us](t);for(;this[we]&&this[we]?.length>=512&&!this[_n]&&!this[qs];){let e=this[we];this[we]=void 0,this[Us](e)}this[bi]=!1}(!this[we]||this[wn])&&this[Hs]()}[Us](t){let e=0,r=t.length;for(;e+512<=r&&!this[_n]&&!this[qs];)switch(this[ft]){case"begin":case"header":this[Fu](t,e),e+=512;break;case"ignore":case"body":e+=this[lc](t,e);break;case"meta":e+=this[Bu](t,e);break;default:throw new Error("invalid state: "+this[ft])}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[_n]||(this[De]?(t&&this[De].write(t),this[De].end()):(this[wn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Hs]())),this}},Ri=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)},e_=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},bf=(t,e)=>{let r=new Map(e.map(c=>[Ri(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||lw(c).root||".",f;if(c===u)f=!1;else{let x=r.get(c);f=x!==void 0?x:o(dw(c),u)}return r.set(c,f),f};t.filter=i?(c,d)=>i(c,d)&&o(Ri(c)):c=>o(Ri(c))},t_=t=>{let e=new Bi(t),r=t.file,i;try{i=kr.openSync(r,"r");let o=kr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=kr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let f=kr.readSync(i,u,0,c,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{kr.closeSync(i)}catch{}}},n_=(t,e)=>{let r=new Bi(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),kr.stat(o,(u,f)=>{if(u)d(u);else{let x=new Gc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},Pr=Fi(t_,n_,t=>new Bi(t),t=>new Bi(t),(t,e)=>{e?.length&&bf(t,e),t.noResume||e_(t)}),Ef=(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:i_,parse:Hu}=r_,Kc=t=>{let e="",r=Hu(t);for(;i_(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Hu(t)}return[e,t]},ho=["|","<",">","?",":"],$c=ho.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),s_=new Map(ho.map((t,e)=>[t,$c[e]])),o_=new Map($c.map((t,e)=>[t,ho[e]])),Gu=t=>ho.reduce((e,r)=>e.split(r).join(s_.get(r)),t),a_=t=>$c.reduce((e,r)=>e.split(r).join(o_.get(r)),t),vf=(t,e)=>e?(t=Q(t).replace(/^\.(\/|$)/,""),Ri(e)+"/"+t):Q(t),c_=16*1024*1024,ju=Symbol("process"),qu=Symbol("file"),Wu=Symbol("directory"),Ic=Symbol("symlink"),Ku=Symbol("hardlink"),Ei=Symbol("header"),Zs=Symbol("read"),Ac=Symbol("lstat"),Ys=Symbol("onlstat"),kc=Symbol("onread"),Tc=Symbol("onreadlink"),Cc=Symbol("openfile"),Rc=Symbol("onopenfile"),Sn=Symbol("close"),oo=Symbol("mode"),Pc=Symbol("awaitDrain"),fc=Symbol("ondrain"),Pt=Symbol("prefix"),Sf=class extends Zn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=jc(e);super(),this.path=Q(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||c_,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]=Kc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=a_(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Q(r.absolute||Uu.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[Ys](o):this[Ac]()}warn(t,e,r={}){return fo(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[Ac](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ys](e)})}[Ys](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=u_(t),this.emit("stat",t),this[ju]()}[ju](){switch(this.type){case"File":return this[qu]();case"Directory":return this[Wu]();case"SymbolicLink":return this[Ic]();default:return this.end()}}[oo](t){return Ef(t,this.type==="Directory",this.portable)}[Pt](t){return vf(t,this.prefix)}[Ei](){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 Jn({path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,mode:this[oo](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 io({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)}[Wu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[Ei](),this.end()}[Ic](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Tc](e)})}[Tc](t){this.linkpath=Q(t),this[Ei](),this.end()}[Ku](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Q(Uu.relative(this.cwd,t)),this.stat.size=0,this[Ei](),this.end()}[qu](){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[Ku](e);this.linkCache.set(t,this.absolute)}if(this[Ei](),this.stat.size===0)return this.end();this[Cc]()}[Cc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Rc](e)})}[Rc](t){if(this.fd=t,this.#e)return this[Sn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Zs]()}[Zs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Rt.read(t,e,r,i,o,(c,d)=>{if(c)return this[Sn](()=>this.emit("error",c));this[kc](d)})}[Sn](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[kc](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[Sn](()=>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[Sn](()=>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[fc]():this[Pc](()=>this[fc]())}[Pc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[fc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[Sn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Zs]()}},d_=class extends Sf{sync=!0;[Ac](){this[Ys](Rt.lstatSync(this.absolute))}[Ic](){this[Tc](Rt.readlinkSync(this.absolute))}[Cc](){this[Rc](Rt.openSync(this.absolute,"r"))}[Zs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=Rt.readSync(e,r,i,o,c);this[kc](d),t=!1}finally{if(t)try{this[Sn](()=>{})}catch{}}}[Pc](t){t()}[Sn](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},l_=class extends Zn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return fo(this,t,e,r)}constructor(t,e={}){let r=jc(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[oo](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]=Kc(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 Jn({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 io({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 vf(t,this.prefix)}[oo](t){return Ef(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}},u_=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",f_=class Tr{tail;head;length=0;static create(e=[]){return new Tr(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++)x_(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)p_(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 Tr;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 Tr;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 Tr;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 Tr;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=h_(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 h_(t,e,r){let i=e,o=e?e.next:t.head,c=new Vc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function x_(t,e){t.tail=new Vc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function p_(t,e){t.head=new Vc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Vc=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}},Vu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Ju=Buffer.alloc(1024),Xs=Symbol("onStat"),vi=Symbol("ended"),yt=Symbol("queue"),Si=Symbol("queue"),yn=Symbol("current"),Wn=Symbol("process"),Ii=Symbol("processing"),Ws=Symbol("processJob"),bt=Symbol("jobs"),hc=Symbol("jobDone"),Qs=Symbol("addFSEntry"),Zu=Symbol("addTarEntry"),Dc=Symbol("stat"),Oc=Symbol("readdir"),eo=Symbol("onreaddir"),to=Symbol("pipe"),Yu=Symbol("entry"),xc=Symbol("entryOpt"),no=Symbol("writeEntryClass"),If=Symbol("write"),pc=Symbol("ondrain"),xo=class extends Zn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[no];onWriteEntry;[yt];[Si]=new Map;[bt]=0;[Ii]=!1;[vi]=!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[no]=Sf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new vw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Iw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new kw(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[pc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[pc]);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[yt]=new f_,this[bt]=0,this.jobs=Number(t.jobs)||4,this[Ii]=!1,this[vi]=!1}[If](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[vi]=!0,this[Wn](),r&&r(),this}write(t){if(this[vi])throw new Error("write after end");return t instanceof yf?this[Zu](t):this[Qs](t),this.flowing}[Zu](t){let e=Q($u.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Vu(t.path,e);r.entry=new l_(t,this[xc](r)),r.entry.on("end",()=>this[hc](r)),this[bt]+=1,this[yt].push(r)}this[Wn]()}[Qs](t){let e=Q($u.resolve(this.cwd,t));this[yt].push(new Vu(t,e)),this[Wn]()}[Dc](t){t.pending=!0,this[bt]+=1;let e=this.follow?"stat":"lstat";so[e](t.absolute,(r,i)=>{t.pending=!1,this[bt]-=1,r?this.emit("error",r):this[Xs](t,i)})}[Xs](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[yn])this[Ws](t);else{let r=`${e.dev}:${e.ino}`,i=this[Si].get(r);i?i.push(t):this[Si].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Wn]()}[Oc](t){t.pending=!0,this[bt]+=1,so.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[bt]-=1,e)return this.emit("error",e);this[eo](t,r)})}[eo](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Wn]()}[Wn](){if(!this[Ii]){this[Ii]=!0;for(let t=this[yt].head;t&&this[bt]<this.jobs;t=t.next)if(this[Ws](t.value),t.value.ignore){let e=t.next;this[yt].removeNode(t),t.next=e}this[Ii]=!1,this[vi]&&this[yt].length===0&&this[bt]===0&&(this.zip?this.zip.end(Ju):(super.write(Ju),super.end()))}}get[yn](){return this[yt]&&this[yt].head&&this[yt].head.value}[hc](t){this[yt].shift(),this[bt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[Si].get(r);if(i){this[Si].delete(r);for(let o of i)o.pending=!1,this[Ws](o)}}this[Wn]()}[Ws](t){if(t.pending&&t.pendingLink&&t===this[yn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[yn]&&!t.piped&&this[to](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Xs](t,e):this[Dc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[eo](t,e):this[Oc](t),!t.readdir)return}if(t.entry=this[Yu](t),!t.entry){t.ignore=!0;return}t===this[yn]&&!t.piped&&this[to](t)}}}[xc](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}}[Yu](t){this[bt]+=1;try{return new this[no](t.path,this[xc](t)).on("end",()=>this[hc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[pc](){this[yn]&&this[yn].entry&&this[yn].entry.resume()}[to](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Qs](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={}){fo(this,t,e,r)}},Jc=class extends xo{sync=!0;constructor(t){super(t),this[no]=d_}pause(){}resume(){}[Dc](t){let e=this.follow?"statSync":"lstatSync";this[Xs](t,so[e](t.absolute))}[Oc](t){this[eo](t,so.readdirSync(t.absolute))}[to](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Qs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[If](i)})}},g_=(t,e)=>{let r=new Jc(t),i=new ff(t.file,{mode:t.mode||438});r.pipe(i),Af(r,e)},m_=(t,e)=>{let r=new xo(t),i=new lo(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 kf(r,e).catch(c=>r.emit("error",c)),o},Af=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Pr({file:hf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},kf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Pr({file:hf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},w_=(t,e)=>{let r=new Jc(t);return Af(r,e),r},__=(t,e)=>{let r=new xo(t);return kf(r,e).catch(i=>r.emit("error",i)),r},fk=Fi(g_,m_,w_,__,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),b_=process.env.__FAKE_PLATFORM__||process.platform,Pf=b_==="win32",{O_CREAT:Df,O_NOFOLLOW:Xu,O_TRUNC:Of,O_WRONLY:Lf}=Rf.constants,Nf=Number(process.env.__FAKE_FS_O_FILENAME__)||Rf.constants.UV_FS_O_FILEMAP||0,E_=Pf&&!!Nf,v_=512*1024,S_=Nf|Of|Df|Lf,Qu=!Pf&&typeof Xu=="number"?Xu|Of|Df|Lf:null,Mf=Qu!==null?()=>Qu:E_?t=>t<v_?S_:"w":()=>"w",Lc=(t,e,r)=>{try{return po.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},ao=(t,e,r,i)=>{po.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},I_=(t,e,r,i,o)=>{if(e.isDirectory())Bf(Pi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=Pi.resolve(t,e.name);ao(d,r,i,o)});else{let c=Pi.resolve(t,e.name);ao(c,r,i,o)}},Bf=(t,e,r,i)=>{po.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 ao(t,e,r,i);let d=c.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--d===0)return ao(t,e,r,i)}};for(let x of c)I_(t,x,e,r,f)})},A_=(t,e,r,i)=>{e.isDirectory()&&Ff(Pi.resolve(t,e.name),r,i),Lc(Pi.resolve(t,e.name),r,i)},Ff=(t,e,r)=>{let i;try{i=po.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Lc(t,e,r);throw c}for(let o of i)A_(t,o,e,r);return Lc(t,e,r)},zf=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"}},go=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"}},T_=(t,e)=>{ct.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new zf(t,r?.code||"ENOTDIR")),e(r)})},C_=(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,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,g=e.unlink,m=Q(e.cwd),S=(v,I)=>{v?r(v):I&&f?Bf(I,d,u,A=>S(A)):c?ct.chmod(t,o,r):r()};if(t===m)return T_(t,S);if(x)return k_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let _=Q(co.relative(m,t)).split("/");Nc(m,_,o,g,m,void 0,S)},Nc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),f=Q(co.resolve(t+"/"+u));ct.mkdir(f,r,Uf(f,e,r,i,o,c,d))},Uf=(t,e,r,i,o,c,d)=>u=>{u?ct.lstat(t,(f,x)=>{if(f)f.path=f.path&&Q(f.path),d(f);else if(x.isDirectory())Nc(t,e,r,i,o,c,d);else if(i)ct.unlink(t,g=>{if(g)return d(g);ct.mkdir(t,r,Uf(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new go(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Nc(t,e,r,i,o,c,d))},R_=t=>{let e=!1,r;try{e=ct.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new zf(t,r??"ENOTDIR")}},P_=(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),f=e.preserve,x=e.unlink,g=Q(e.cwd),m=v=>{v&&u&&Ff(v,c,d),o&&ct.chmodSync(t,i)};if(t===g)return R_(g),m();if(f)return m(ct.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=Q(co.relative(g,t)).split("/"),_;for(let v=S.shift(),I=g;v&&(I+="/"+v);v=S.shift()){I=Q(co.resolve(I));try{ct.mkdirSync(I,i),_=_||I}catch{let A=ct.lstatSync(I);if(A.isDirectory())continue;if(x){ct.unlinkSync(I),ct.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new go(I,I+"/"+S.join("/"))}}return m(_)},gc=Object.create(null),ef=1e4,Er=new Set,D_=t=>{Er.has(t)?Er.delete(t):gc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Er.add(t);let e=gc[t],r=Er.size-ef;if(r>ef/10){for(let i of Er)if(Er.delete(i),delete gc[i],--r<=0)break}return e},O_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,L_=O_==="win32",N_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=Hf(i,r)),e.push(r||"/"),e},[]),M_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=L_?["win32 parallelization disabled"]:t.map(i=>Ri(Hf(D_(i))));let r=new Set(t.map(i=>N_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},B_=()=>process.umask(),tf=Symbol("onEntry"),Mc=Symbol("checkFs"),nf=Symbol("checkFs2"),Bc=Symbol("isReusable"),ht=Symbol("makeFs"),Fc=Symbol("file"),zc=Symbol("directory"),ro=Symbol("link"),rf=Symbol("symlink"),sf=Symbol("hardlink"),Ti=Symbol("ensureNoSymlink"),of=Symbol("unsupported"),af=Symbol("checkPath"),mc=Symbol("stripAbsolutePath"),In=Symbol("mkdir"),qe=Symbol("onError"),Ks=Symbol("pending"),cf=Symbol("pend"),vr=Symbol("unpend"),wc=Symbol("ended"),_c=Symbol("maybeClose"),Uc=Symbol("skip"),Di=Symbol("doChown"),Oi=Symbol("uid"),Li=Symbol("gid"),Ni=Symbol("checkedCwd"),F_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Mi=F_==="win32",z_=1024,U_=(t,e)=>{if(!Mi)return ie.unlink(t,e);let r=t+".DELETE."+Cf(16).toString("hex");ie.rename(t,r,i=>{if(i)return e(i);ie.unlink(r,e)})},H_=t=>{if(!Mi)return ie.unlinkSync(t);let e=t+".DELETE."+Cf(16).toString("hex");ie.renameSync(t,e),ie.unlinkSync(e)},df=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Zc=class extends Bi{[wc]=!1;[Ni]=!1;[Ks]=0;reservations=new M_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[wc]=!0,this[_c]()},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:z_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Mi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Q(Fe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:B_():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[tf](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[_c](){this[wc]&&this[Ks]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[mc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Kc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Mi&&/^[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=Fe.posix.dirname(t.path),f=Fe.posix.normalize(Fe.posix.join(u,d.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[af](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[mc](t,"path")||!this[mc](t,"linkpath"))return!1;if(t.absolute=Fe.isAbsolute(t.path)?Q(Fe.resolve(t.path)):Q(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: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}=Fe.win32.parse(String(t.absolute));t.absolute=i+Gu(String(t.absolute).slice(i.length));let{root:o}=Fe.win32.parse(t.path);t.path=o+Gu(t.path.slice(o.length))}return!0}[tf](t){if(!this[af](t))return t.resume();switch(y_.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[Mc](t);default:return this[of](t)}}[qe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[vr](),e.resume())}[In](t,e,r){C_(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)}[Di](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}[Oi](t){return df(this.uid,t.uid,this.processUid)}[Li](t){return df(this.gid,t.gid,this.processGid)}[Fc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new lo(String(t.absolute),{flags:Mf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&ie.close(i.fd,()=>{}),i.write=()=>!0,this[qe](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ie.close(i.fd,()=>{}),this[qe](u,t),e();return}--o===0&&i.fd!==void 0&&ie.close(i.fd,f=>{f?this[qe](f,t):this[vr](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,g=t.mtime;ie.futimes(f,x,g,m=>m?ie.utimes(u,x,g,S=>c(S&&m)):c())}if(typeof f=="number"&&this[Di](t)){o++;let x=this[Oi](t),g=this[Li](t);typeof x=="number"&&typeof g=="number"&&ie.fchown(f,x,g,m=>m?ie.chown(u,x,g,S=>c(S&&m)):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)}[zc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[In](String(t.absolute),r,i=>{if(i){this[qe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[vr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ie.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Di](t)&&(o++,ie.chown(String(t.absolute),Number(this[Oi](t)),Number(this[Li](t)),c)),c()})}[of](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[rf](t,e){let r=Q(Fe.relative(this.cwd,Fe.resolve(Fe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Ti](t,this.cwd,r,()=>this[ro](t,String(t.linkpath),"symlink",e),i=>{this[qe](i,t),e()})}[sf](t,e){let r=Q(Fe.resolve(this.cwd,String(t.linkpath))),i=Q(String(t.linkpath)).split("/");this[Ti](t,this.cwd,i,()=>this[ro](t,r,"link",e),o=>{this[qe](o,t),e()})}[Ti](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Fe.resolve(e,c);ie.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new go(d,Fe.resolve(d,r.join("/"))));this[Ti](t,d,r,i,o)})}[cf](){this[Ks]++}[vr](){this[Ks]--,this[_c]()}[Uc](t){this[vr](),t.resume()}[Bc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Mi}[Mc](t){this[cf]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[nf](t,r))}[nf](t,e){let r=d=>{e(d)},i=()=>{this[In](this.cwd,this.dmode,d=>{if(d){this[qe](d,t),r();return}this[Ni]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=Q(Fe.dirname(String(t.absolute)));if(d!==this.cwd)return this[In](d,this.dmode,u=>{if(u){this[qe](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[Uc](t),r();return}if(d||this[Bc](t,u))return this[ht](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=g=>this[ht](g??null,t,r);return f?ie.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return ie.rmdir(String(t.absolute),f=>this[ht](f??null,t,r))}if(t.absolute===this.cwd)return this[ht](null,t,r);U_(String(t.absolute),f=>this[ht](f??null,t,r))})};this[Ni]?o():i()}[ht](t,e,r){if(t){this[qe](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Fc](e,r);case"Link":return this[sf](e,r);case"SymbolicLink":return this[rf](e,r);case"Directory":case"GNUDumpDir":return this[zc](e,r)}}[ro](t,e,r,i){ie[r](e,String(t.absolute),o=>{o?this[qe](o,t):(this[vr](),t.resume()),i()})}},Ai=t=>{try{return[null,t()]}catch(e){return[e,null]}},Gf=class extends Zc{sync=!0;[ht](t,e){return super[ht](t,e,()=>{})}[Mc](t){if(!this[Ni]){let o=this[In](this.cwd,this.dmode);if(o)return this[qe](o,t);this[Ni]=!0}if(t.absolute!==this.cwd){let o=Q(Fe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[In](o,this.dmode);if(c)return this[qe](c,t)}}let[e,r]=Ai(()=>ie.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Uc](t);if(e||this[Bc](t,r))return this[ht](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?Ai(()=>{ie.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ht](d,t)}let[o]=Ai(()=>ie.rmdirSync(String(t.absolute)));this[ht](o,t)}let[i]=t.absolute===this.cwd?[]:Ai(()=>H_(String(t.absolute)));this[ht](i,t)}[Fc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{ie.closeSync(o)}catch(f){u=f}(d||u)&&this[qe](d||u,t),e()},o;try{o=ie.openSync(String(t.absolute),Mf(t.size),r)}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{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,f=t.mtime;try{ie.futimesSync(o,u,f)}catch(x){try{ie.utimesSync(String(t.absolute),u,f)}catch{d=x}}}if(this[Di](t)){let u=this[Oi](t),f=this[Li](t);try{ie.fchownSync(o,Number(u),Number(f))}catch(x){try{ie.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||x}}}i(d)})}[zc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[In](String(t.absolute),r);if(i){this[qe](i,t),e();return}if(t.mtime&&!this.noMtime)try{ie.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Di](t))try{ie.chownSync(String(t.absolute),Number(this[Oi](t)),Number(this[Li](t)))}catch{}e(),t.resume()}[In](t,e){try{return P_(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}}[Ti](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Fe.resolve(c,d);let[u,f]=Ai(()=>ie.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new go(c,Fe.resolve(e,r.join("/"))))}i()}[ro](t,e,r,i){let o=`${r}Sync`;try{ie[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[qe](c,t)}}},G_=t=>{let e=new Gf(t),r=t.file,i=Tf.statSync(r),o=t.maxReadSize||16*1024*1024;new cw(r,{readSize:o,size:i.size}).pipe(e)},j_=(t,e)=>{let r=new Zc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),Tf.stat(o,(u,f)=>{if(u)d(u);else{let x=new Gc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},jf=Fi(G_,j_,t=>new Gf(t),t=>new Zc(t),(t,e)=>{e?.length&&bf(t,e)}),q_=(t,e)=>{let r=new Jc(t),i=!0,o,c;try{try{o=at.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=at.openSync(t.file,"w+");else throw f}let d=at.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let g=0,m=0;g<512;g+=m){if(m=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(!m)break e}let f=new Jn(u);if(!f.cksumValid)break;let x=512*Math.ceil((f.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,W_(t,r,c,o,e)}finally{if(i)try{at.closeSync(o)}catch{}}},W_=(t,e,r,i,o)=>{let c=new ff(t.file,{fd:i,start:r});e.pipe(c),$_(e,o)},K_=(t,e)=>{e=Array.from(e);let r=new xo(t),i=(o,c,d)=>{let u=(S,_)=>{S?at.close(o,v=>d(S)):d(null,_)},f=0;if(c===0)return u(null,0);let x=0,g=Buffer.alloc(512),m=(S,_)=>{if(S||_===void 0)return u(S);if(x+=_,x<512&&_)return at.read(o,g,x,g.length-x,f+x,m);if(f===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let v=new Jn(g);if(!v.cksumValid)return u(null,f);let I=512*Math.ceil((v.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,at.read(o,g,0,512,f,m)};at.read(o,g,0,512,f,m)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(f,x)=>{if(f&&f.code==="ENOENT"&&d==="r+")return d="w+",at.open(t.file,d,u);if(f||!x)return c(f);at.fstat(x,(g,m)=>{if(g)return at.close(x,()=>c(g));i(x,m.size,(S,_)=>{if(S)return c(S);let v=new lo(t.file,{fd:x,start:_});r.pipe(v),v.on("error",c),v.on("close",o),V_(r,e)})})};at.open(t.file,d,u)})},$_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Pr({file:qf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},V_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Pr({file:qf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},ki=Fi(q_,K_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!gw(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")}),kk=Fi(ki.syncFile,ki.asyncFile,ki.syncNoFile,ki.asyncNoFile,(t,e=[])=>{ki.validate?.(t,e),J_(t)}),J_=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))};xn();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 mo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Wf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function wo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Kf(t){return t?.bizFreeScene?.trim()||void 0}function $f(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Vf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Yn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Zt();$e();ne();Re();$e();function Dr(t,e){if(mo(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function zi(t){return t.startsWith("http://")||t.startsWith("https://")}function Or(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as w2}from"node:fs";import{dirname as y2,join as b2}from"node:path";import{fileURLToPath as v2}from"node:url";var Ot="0.2.7-alpha.11";$e();ne();var _o="1008033",Xf="1289";var Qf="pbbp2",e0="https://www.coze.cn",t0="/api/coze_claw/resource/get_frontier_key",ry="https://www.coze.cn",iy="wss://frontier.coze.cn";function Lr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??ry}function n0(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??iy}function Tn(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 Hi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ui=j("handshake");async function Yc(t){let e=Lr(t.endpoint),r=t.timeoutMs??1e4,i=`${Or(e)}${t0}?aid=${encodeURIComponent(_o)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Tn(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Ui.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),f=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${v.slice(0,200)}`)}let g=await u.json();if(g.code!==void 0&&g.code!==0)throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${g.code} msg=${g.msg??"-"} logid=${f}`);let m=g.data??{},S=typeof m.access_key=="string"&&m.access_key||typeof m.accessKey=="string"&&m.accessKey||void 0,_=typeof m.device_id=="string"&&m.device_id||typeof m.deviceId=="string"&&m.deviceId||void 0;if(!S||!_){let v=JSON.stringify(g).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${v}`)}return Ui.info("handshake ok",{remoteDeviceId:_,logid:f,traceId:x}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof k)throw Ui.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ui.warn("handshake timeout",{base:e,timeoutMs:r}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Ui.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new k("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var Xc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Lt="auto",yo=15e4;function i0(t){return{model:Qc(t.model)??Lt,...t.modelToken?{modelToken:t.modelToken}:{}}}function s0(t){return!t||t===Lt}var sy=new Set(["auto","\u81EA\u52A8"]);function Qc(t){let e=t?.trim();if(e)return sy.has(e.toLowerCase())?Lt:e}function o0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Xc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Lt;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 s0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function a0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Lt}"`):s0(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Xc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??yo;e.push("-c",`model_context_window=${r}`)}return e}function c0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function ed(t,e,r){let{ttEnv:i,usePpe:o}=Hi(t),c={};return i&&(c["x-tt-env"]=i),o&&(c["x-use-ppe"]=o),e&&(c["x-mock-scenario"]=e),r&&(c["rpc-persist-biz-free-scene"]=r),c}function d0(t,e,r,i){if(!t.modelToken)return{};let o=ed(e,r,i);return Object.keys(o).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(o).map(([d,u])=>`${d}:${u}`).join(`
|
|
92
|
-
`)}}function td(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function nd(t){return t.model||Lt}function r0(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 l0(t,e,r,i,o){if(!t.modelToken)return null;let c=nd(t),d=ed(e,r,o),u=["text"];t.modelInfo?.capabilities?.image===!0&&u.push("image");let f=[r0(c,u,t.modelInfo?.contextWindow??yo)],x=new Set([c]);for(let m of i??[])!m||x.has(m)||(x.add(m),f.push(r0(m,["text"],yo)));let g={baseUrl:`${Xc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:c,name:c,reasoning:!1,input:u,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??yo,maxTokens:32e3,api:"openai-completions"}]};return Object.keys(d).length>0&&(g.headers=d),g}function u0(t,e,r,i){if(!t.modelToken)return[];let o=ed(e,r,i),c=[];for(let[d,u]of Object.entries(o))c.push("-c",`model_providers.coze.http_headers.${d}="${u}"`);return c}var ge=j("agent-handlers"),f0=5*1024*1024,ly=1,uy=6,fy=new Set(["node_modules",".git",".coze","dist","build",".next"]),hy=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,xy=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,py=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function gy(t){let e=t?.trim();return e?py.test(e)||xy.test(e)?e:(ge.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function my(t){return new Promise((e,r)=>{let i=st("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 Eo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let r=Yn(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ve(r).workspace,c=i?.skills??[],d=[],u=new Set;for(let f of c){let x=_e(o,f.relPath,"SKILL.md");await p0(x).then(m=>m.isFile()).catch(()=>!1)&&(d.push(vy(f)),u.add(f.relPath))}if(e.scanLocal){let f=i?.framework??"claude-code",x=await _y(r,o,f),g=await yy(r,f);for(let m of[...x,...g])u.has(m.relPath)||(u.add(m.relPath),d.push(m.skill))}return{skills:d}}async addSkills(e){e._meta;let r=Yn(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((f,x)=>[f.skillId,x])),u=[];for(let f of o){let x=await vo({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});So(c,d,x),u.push(f)}return await fi(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let r=Yn(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let f=_e(i.workspace,u.relPath);await sd(f,{recursive:!0,force:!0}),ge.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await fi(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let r=Yn(e._meta);if(!e.skillName)throw new k("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");ge.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??Ve(r).workspace,c=i?.framework??"claude-code",d=e.isGlobal??!1,u=_0(e.skillName),f=await wy(o,c,u,d);if(!f){let O=d?"global":"workspace";throw new k("SKILL_NOT_FOUND",`skill not found in ${O}: ${e.skillName} (${u})`)}let{absDir:x,relPath:g}=f,m=_e(x,"SKILL.md"),S=new ld.default;S.addLocalFolder(x,u);let _=S.toBuffer();if(_.length>h0)throw new k("SKILL_ZIP_TOO_LARGE",`skill zip ${_.length} bytes exceeds limit ${h0}`);let v=await bo(m,{encoding:"utf8"}).then(O=>E0(O).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:_,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:r,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):ge.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:r,skillName:e.skillName});let A=I.version??"v1.0",C=I.skillId??e.skillId??b0(r,g);if(i&&!d){let O=i.skills??[],b=O.find(P=>P.relPath===g);b?(b.version=A,b.skillId=C):O.push({skillId:C,skillName:e.skillName,relPath:g,version:A,installedAt:Date.now(),...v?{description:v}:{}}),await fi(r,O)}return ge.info("skill published",{agentId:r,skillName:e.skillName,relPath:g,zipBytes:_.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,ge.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=c.downstream;c.downstream=void 0,ge.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(r).catch(x=>ge.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 ge.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Pe(r);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return ge.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await pr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw ge.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ue(i),ge.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Pe(r))throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&zi(e.registry)&&o.push(`--registry=${e.registry}`);let c=gy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&hy.test(d)&&o.push("--env",d);let u=await my(o);return ge.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Pe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ue(i),ge.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}):(ge.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async deleteAgent(e){let r=e.agentId;if(!r)throw new k("IPC_BAD_REQUEST",`${xt.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=Ve(r);return c==="cloud"?await sd(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Ue(i)),ge.info("agent deleted",{agentId:r,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Dr(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Qc(e.model)??Lt,i=await Pe(e.agentId);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ue(i),ge.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return ge.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=>ge.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,f]of o.allSessionQueues())d.push(f.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),ge.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(Dr(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,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),ge.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 ui(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 Ue(r)}async repairAgent(e){if(Dr(e._meta,xt.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${xt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${xt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){ge.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,r,i){if(!this.opts.detailSyncer){ge.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){ge.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Dr(e._meta,"_agent/getFileTree");let r=e._meta,i=Yn(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await rd(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 li(d,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=Ny(e.depth);return u.isDirectory()?{tree:await Ly(o,d,c,f)}:{tree:[{name:My(c),path:A0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Dr(e._meta,"_agent/getFileContent");let r=Yn(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new k("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await rd(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 li(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>f0)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${f0})`);let d=await bo(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??Ve(e).workspace}safeJoin(e,r){let i=ad(e,r||"."),o=dd(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${g0}`))throw new k("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 k("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function _0(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 ud(t){return t==="claude-code"?_e(".claude","skills"):_e(".agents","skills")}function y0(t){let e=ay();return t==="claude-code"?[_e(e,".claude","skills")]:t==="codex"?[_e(e,".agents","skills"),_e(e,".codex","skills")]:[_e(e,".agents","skills"),_e(e,".openclaw","skills")]}async function wy(t,e,r,i){let o=async c=>p0(_e(c,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let c=_e(ud(e),r),d=_e(t,c);return await o(d)?{absDir:d,relPath:c}:null}for(let c of y0(e)){let d=_e(c,r);if(await o(d))return{absDir:d,relPath:d}}return null}function b0(t,e){return(oy("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function E0(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 v0(t,e,r,i){let o=await x0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let d of o){if(!d.isDirectory())continue;let u=d.name,f=_e(r,u),x=_e(e,u,"SKILL.md"),g=await bo(x,{encoding:"utf8"}).catch(()=>null);if(g===null)continue;let m=E0(g);c.push({relPath:f,skill:{skillId:b0(t,f),skillName:m.name||u,...m.description?{description:m.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function _y(t,e,r){let i=ud(r);return v0(t,_e(e,i),i,!1)}async function yy(t,e){let r=[],i=new Set;for(let o of y0(e)){let c=await v0(t,o,o,!0);for(let d of c)i.has(d.relPath)||(i.add(d.relPath),r.push(d))}return r}var by=3e4,Ey=50*1024*1024,h0=10*1024*1024,Nr=3e4;async function vo(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new k("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,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=_0(o.skillName),f=ud(i),x=_e(f,u),g=_e(r,x);if(await id(g,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Gi(S.length),await od(_e(g,"SKILL.md"),S,"utf8")}else{let S=await Iy(o.downloadUrl);ky(S)?await Py(S,g):Ty(S)?await Cy(S,g):await od(_e(g,"SKILL.md"),S.toString("utf8"),"utf8")}let m={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 ge.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),m}function So(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 vy(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 Sy(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 S0(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=Ot,o=r.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return r.skillsRefreshedForVersion=i,await Ue(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((g,m)=>[g.skillId,m])),u=c.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Ue(r,e),{status:"noop",count:0};let f=0,x=0;for(let g of u)try{await sd(_e(r.workspace,g.relPath),{recursive:!0,force:!0});let m=await vo({agentId:t,workspace:r.workspace,framework:r.framework,skill:Sy(g)});So(c,d,m),f+=1}catch(m){x+=1,ge.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(m)})}return r.skills=c,x===0&&(r.skillsRefreshedForVersion=i),await Ue(r,e),ge.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:f,failed:x}),{status:"refreshed",count:f}}async function Iy(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Gi(e);let r=Ay(t);return Gi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await bo(e);return Gi(r.length),r}if(zi(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),by);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 Gi(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new k("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Gi(t){if(t>Ey)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function Ay(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new k("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function ky(t){return t.length>=2&&t[0]===31&&t[1]===139}function Ty(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 cd(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function Cy(t,e){let r,i;try{r=new ld.default(t),i=r.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||cd(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(x=>x===".."))throw new k("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=d.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new k("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=Ry(i),c=ad(e);for(let d of i){if(cd(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=ad(e,u),x=dd(c,f);if(x.startsWith("..")||x==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await id(f,{recursive:!0});continue}await id(cy(f),{recursive:!0});let g;try{g=d.getData()}catch(m){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${m.message}`,{cause:m})}await od(f,g)}}function Ry(t){let e;for(let r of t){let i=r.entryName;if(!i||cd(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 Py(t,e){await Dy(t);let r=jf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Nr}ms)`))},Nr);try{await w0(m0.from(t),r)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Nr}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Dy(t){let e=[],r=Pr({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 k("IPC_BAD_REQUEST",`tar list timeout (${Nr}ms)`))},Nr);try{await w0(m0.from(t),r)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Nr}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 Oy=5e3;async function Ly(t,e,r,i){return I0(t,e,r,i,{count:0})}async function I0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await x0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(fy.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Oy){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=_e(e,u.name),x=dy(_e(r,u.name)),g=null;try{g=await rd(f)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let m={name:u.name,path:A0(dd(t,f)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(m.children=await I0(t,f,x,i-1,o)),d.push(m)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function Ny(t){return!t||t<=0?ly:Math.min(t,uy)}function My(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function A0(t){return t.split(g0).join("/")}ne();var Cn=j("agent-health-reporter"),By=1e4,Fy=3,ji=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??By,this.livenessFailureThreshold=e.livenessFailureThreshold??Fy}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()}),Cn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),Cn.info("heartbeat stopped"))}async tick(){if(this.inFlight){Cn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,Cn.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=zy(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),r.push(f)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Ot,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,Cn.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(Cn.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){Cn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){Cn.warn("onTickEnd hook failed",{err:String(r)})}}};function zy(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}xn();import{mkdir as yd,rm as Zb,stat as Yb}from"node:fs/promises";import{homedir as Xb}from"node:os";import{join as bd}from"node:path";dn();import{existsSync as Xy}from"node:fs";import{release as Qy}from"node:os";import{basename as eb,isAbsolute as tb}from"node:path";function qi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Mr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Br(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Rn(t,e){return{jsonrpc:"2.0",id:t,error:e}}$e();var Io=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)}},Y={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 k0(t){return"method"in t&&"id"in t&&t.id!==void 0}function T0(t){return"method"in t&&!("id"in t)}function Ao(t){return!("method"in t)&&"id"in t}var Uy={AGENT_NOT_FOUND:Y.AGENT_NOT_FOUND,AGENT_BUSY:Y.AGENT_BUSY,AGENT_DISCONNECTED:Y.AGENT_DISCONNECTED,AGENT_TIMEOUT:Y.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Y.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Y.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Y.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Y.INTERNAL_ERROR,BRIDGE_INTERNAL:Y.INTERNAL_ERROR,IPC_AUTH_FAILED:Y.INTERNAL_ERROR,IPC_BAD_REQUEST:Y.INVALID_REQUEST,METHOD_NOT_FOUND:Y.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:Y.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Y.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Y.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:Y.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:Y.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Y.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Y.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Y.FILE_TOO_LARGE,UNSUPPORTED_MIME:Y.UNSUPPORTED_MIME,UPLOAD_FAILED:Y.UPLOAD_FAILED,UPSTREAM_NOT_READY:Y.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Y.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Y.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Y.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Y.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:Y.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:Y.SKILL_ZIP_TOO_LARGE};function Hy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Wi(t.message)}:typeof t=="string"?Wi(t):typeof t=="object"?jy(t):t}var Gy=[[/\/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 Wi(t){let e=t;for(let[r,i]of Gy)e=e.replace(r,i);return e}function jy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Wi(i):e[r]=i;return e}function Ki(t){if(t instanceof k){let e=Hy(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:Uy[t.code]??Y.INTERNAL_ERROR,message:Wi(t.message),data:r}}return{code:Y.INTERNAL_ERROR,message:Wi(t instanceof Error?t.message:String(t))}}function C0(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 k(r,o,{retriable:e?.retriable??!1,cause:c})}function P0(t){return`${JSON.stringify(t)}
|
|
95
|
-
`}var R0=10*1024*1024,ko=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>R0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${R0} bytes`)}),[]}let
|
|
96
|
-
`);this.buffer=
|
|
97
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function F0(t,e){if(t.length===0)return;let r=e?.killFn??Ji,i=e?.isAliveFn??Vi,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Yy=[{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[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function z0(t,e){if(!e)return null;for(let r of Yy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function U0(t,e){return z0(t,e)}function H0(t,e){return z0(t,e)}function Ur(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function G0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,g=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Ur(g,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Ur(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Ur(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Ur(c,!1,e)}}var j0=Xe("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),nb=200,rb=40,ib=Xe("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),sb=Xe("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),ob=Xe("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),ab=Xe("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),cb=Xe("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),db=Xe("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),q0=500;function lb(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=q0?t:`${e.slice(0,q0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function ub(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function W0(t){try{return Xy(t)}catch{return}}function fb(t,e){return{platform:process.platform,osRelease:Qy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:tb(e.command)?W0(e.command):void 0,cwd:e.cwd,cwdExists:W0(e.cwd),envKeys:e.envKeys}}function hb(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${eb(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Nt=class{constructor(e){this.opts=e;this.log=j(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new ko({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Fr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=To(process.env,this.opts.agentEnvFile??Z().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=st(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,L0(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>nb&&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,N0(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=fb(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 k("AGENT_SPAWN_FAILED",hb(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:cb,phase2GateMs:ib,livenessWindowMs:sb,absoluteMaxMs:ob,approvalMaxMs:db,suspendThresholdMs:ab,...r};return this.call("session/prompt",e,j0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Mr("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(Br(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(Rn(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=j0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=qi(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let f=r.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,x)=>{let g={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let m=this.now(),S={cfg:o,startedAt:m,lastActivityAt:m,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:m,expectedIntervalMs:Ur(0,!1,o),sessionId:u};g.promptTimeout=S;let _=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},I=this.now(),A=G0(v,S.cfg,I),C=O=>{S.armedAt=I,S.expectedIntervalMs=O,g.timer=setTimeout(_,O)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),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 k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new k("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 k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,g);try{this.writeFrame(d)}catch(m){g.timer&&clearTimeout(g.timer),this.pending.delete(c),x(m)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(P0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(Ao(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new k("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:lb(e.result)}),r.resolve(e.result));return}if(T0(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(k0(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(Rn(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(Rn(e.id,Ki(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=C0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=H0(this.framework,ub(e));return i?new k(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new k("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(rb).join(`
|
|
98
|
-
`),o=
|
|
99
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):i.replace(/\\'/g,"'")}}return e.replace(/\s+#.*$/,"")}function
|
|
100
|
-
`)})}async stop(e){if(await super.stop(e),this.codexHomeDir&&this.cleanupCodexHomeDir)try{Eb(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};function zb(t){let e=t.update;if(e.sessionUpdate!=="current_mode_update"||typeof e.currentModeId!="string")return t;let r=J0(e.currentModeId);return!r||r===e.currentModeId?t:{...t,update:{...t.update,currentModeId:r}}}$e();var Ub=3e4,Gr=class extends Nt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ub))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};hn();$e();ne();Re();function wd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}dn();var Pn=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 Po=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 Pn,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)Zi(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 Zi(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"}Zt();ne();import{constants as Q0}from"node:fs";import{access as Hb}from"node:fs/promises";import{delimiter as Gb,join as jb}from"node:path";var St=j("framework-detector"),eh={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},qb=[".exe",".cmd",".bat",".ps1"],Xn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??st,access:e.access??Hb}}async detect(e){let r=eh[e],i=await this.which(r);if(!i)return St.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,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(eh).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(Gb).filter(Boolean),i=this.env.platform==="win32"?["",...qb]:[""];for(let o of r)for(let c of i){let d=jb(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?Q0.F_OK:Q0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return St.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return St.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return St.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return St.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(St.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(St.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return St.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return St.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||St.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let 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){St.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&&(Kb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=f=>{c||(c=!0,d&&clearTimeout(d),i(f))};try{let f=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",x=>{o+=x.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},Wb=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Kb(t){return t.replace(Wb,"")}import{homedir as nh}from"node:os";import{join as Oo}from"node:path";hn();Zt();lr();$e();ne();async function rh(){let t=Oo(nh(),".openclaw/openclaw.json");return ln(t)}async function ih(){return(await rh())?.gateway?.auth?.token??""}var Qn=j("openclaw.config"),$b=[0,5e3,5e3],Vb=Xe("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),th="models.providers.",Do="agents.defaults.models",Jb=["operator.admin","operator.read","operator.write","operator.approvals","operator.pairing"];function _d(t,e){if(!Array.isArray(t))return!1;let r=new Set(t);return e.every(i=>r.has(i))}var Lo=class{command;env;retryDelaysMs;cliTimeoutMs;openclawDir;queue=new Pn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??$b,this.cliTimeoutMs=e.cliTimeoutMs??Vb,this.openclawDir=e.openclawDir??Oo(nh(),".openclaw")}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,Qn.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((r,i)=>{let o=st(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=x=>{d||(d=!0,clearTimeout(f),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?r():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){Qn.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",`${th}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${th}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Do}[${e}]`,()=>this.runCli(["config","set",Do,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Do}[${e}]`,`${Do}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await rh())?.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"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}async ensureAcpDeviceScopes(){try{let e=Oo(this.openclawDir,"identity","device.json"),i=(await ln(e))?.deviceId?.trim();if(!i)return Qn.debug("openclaw device identity absent, skip acp scope ensure",{identityPath:e}),!1;let o=Oo(this.openclawDir,"devices","paired.json"),c=await ln(o),d=c?.[i];if(!c||!d)return Qn.debug("acp device not yet paired, skip scope ensure",{deviceId:i}),!1;let u=[...Jb],f=d.tokens?.operator;return _d(d.scopes,u)&&_d(d.approvedScopes,u)&&_d(f?.scopes,u)?(Qn.debug("acp device already has full operator scopes",{deviceId:i}),!1):(d.scopes=[...u],d.approvedScopes=[...u],f&&(f.scopes=[...u]),await fn(o,c,{mode:384}),Qn.info("acp device scopes upgraded to full operator set (bypass manual approval)",{deviceId:i,scopes:u}),!0)}catch(e){return Qn.warn("ensureAcpDeviceScopes failed (ignored, best-effort)",{err:String(e)}),!1}}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}};var ue=j("agent-manager"),vd="acceptEdits",ah="full-access",ch="read-only";function Qb(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var eE=(t,e,r,i,o,c,d,u,f,x,g,m)=>{switch(t){case"claude-code":{let S={...o?{...o0(o),...d0(o,d,u,m)}:{},...f??{},IS_SANDBOX:"1"};return new Co({cwd:r,env:S,agentId:i})}case"codex":{let S=o?[...a0(o),...u0(o,d,u,m)]:[],_=ah;x!==void 0&&(Mt("codex",x)?_=x:ue.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let v=[...S,...Qb(_)],I={...o?c0(o):{},...f??{}},A=!!o;return new Ro({cwd:r,agentId:i,...v.length>0?{extraArgs:v}:{},...Object.keys(I).length>0?{env:I}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0,...g?{codexHomeDir:g}:{}}:{}})}case"openclaw":return new Gr({command:e,cwd:r,agentId:i,...c?{sessionName:wd(c)}:{}})}};function Ed(t){return t==="claude-code"||t==="codex"}function tE(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(nE(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
89
|
+
`},configPath(t){return A2(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 Np("schtasks",["/Create","/SC","ONLOGON","/TN",ba,"/TR",n,"/RU",t.userName,"/F"]),fl.info("task scheduler entry created",{task:ba,logFile:t.logFile})},async uninstall(t){await Np("schtasks",["/Delete","/TN",ba,"/F"]).catch(e=>fl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),fl.info("task scheduler entry removed",{task:ba})}}});var Bp={};La(Bp,{buildContext:()=>P2,getSupervisor:()=>C2,launchdSupervisor:()=>ll,systemdSupervisor:()=>ul,taskSchedulerSupervisor:()=>hl});import{homedir as k2,userInfo as T2}from"node:os";function C2(t=process.platform){switch(t){case"darwin":return ll;case"linux":return ul;case"win32":return hl;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function R2(){let t={};for(let e of D2){let n=process.env[e];n&&(t[e]=n)}return t}function P2(){let t=Z();return{nodeBin:process.execPath,entry:el(t),logFile:t.logFile,homeDir:k2(),userName:T2().username,isRoot:process.getuid?.()===0,env:R2()}}var D2,Fp=et(()=>{"use strict";Te();fa();Pp();Lp();Mp();D2=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});re();dn();var jl=q("acp-installer-warmup"),um=["claude-code","codex"];async function Wl(t={}){let e=t.ensure??gr,i=(await Promise.allSettled(um.map(async o=>{let a=await e(o);jl.info("acp wrapper warmup ok",{framework:o,path:a})}))).filter(o=>o.status==="rejected");i.length>0&&jl.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))})}xn();re();import{readdir as km}from"node:fs/promises";import{mkdir as Jl,readFile as Im,writeFile as Yl}from"node:fs/promises";import{join as qa}from"node:path";var Am={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function mr(t,e,n){await Jl(t,{recursive:!0});let i=Am[e],o=qa(t,i);return await Yl(o,n??"","utf8"),o}async function Ga(t,e,n){let i=qa(t,".claude");await Jl(i,{recursive:!0});let o=qa(i,"settings.local.json"),a={};try{let u=await Im(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(a=f)}catch{}let d=typeof a.permissions=="object"&&a.permissions!==null&&!Array.isArray(a.permissions)?a.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",a.autoCompactWindow=15e4;else{if(!n)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=n)}return a.permissions=d,await Yl(o,JSON.stringify(a,null,2),"utf8"),o}var Xe=q("agent-detail-sync"),Tm=6e4,Cm=5*6e4,ks=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let n=this.opts.paths.agentsRoot,i;try{i=await km(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 a=await Ce(o,this.opts.paths).catch(()=>null);if(a){if(a.disconnectedAt){Xe.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,a)}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 Ce(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(f){Xe.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),g=x?Math.min(x.currentDelay*2,Cm):Tm;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 a=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,a=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,a=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,a=!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",a=!0,u=!0):o.deployType&&Xe.info("detail.deployType",{agentId:e,deployType:o.deployType}),!a){Xe.debug("detail sync: no diff",{agentId:e});return}await Fe(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 mr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var ld=jt(Cu(),1);import{createHash as cy}from"node:crypto";import{lstat as rd,mkdir as id,readFile as Eo,readdir as p0,rm as sd,stat as g0,writeFile as od}from"node:fs/promises";import{homedir as dy}from"node:os";import{dirname as ly,join as me,normalize as uy,relative as dd,resolve as ad,sep as m0}from"node:path";import{Readable as w0}from"node:stream";import{pipeline as _0}from"node:stream/promises";import Zm from"events";import nt from"fs";import{EventEmitter as qc}from"node:events";import uf from"node:stream";import{StringDecoder as Xm}from"node:string_decoder";import xf from"node:path";import Cr from"node:fs";import{dirname as uw,parse as fw}from"path";import{EventEmitter as yw}from"events";import bc from"assert";import{Buffer as Vn}from"buffer";import*as Lu from"zlib";import Ew from"zlib";import{posix as br}from"node:path";import{basename as Vw}from"node:path";import so from"fs";import Dt from"fs";import qu from"path";import{win32 as s_}from"node:path";import Vu from"path";import Cf from"node:fs";import b_ from"node:assert";import{randomBytes as Df}from"node:crypto";import se from"node:fs";import Ne from"node:path";import Rf from"fs";import po from"node:fs";import Pi from"node:path";import ot from"node:fs";import C_ from"node:fs/promises";import co from"node:path";import{join as Gf}from"node:path";import st from"node:fs";import Wf from"node:path";var Jm=Object.defineProperty,Ym=(t,e)=>{for(var n in e)Jm(t,n,{get:e[n],enumerable:!0})},Du=typeof process=="object"&&process?process:{stdout:null,stderr:null},Qm=t=>!!t&&typeof t=="object"&&(t instanceof Zn||t instanceof uf||ew(t)||tw(t)),ew=t=>!!t&&typeof t=="object"&&t instanceof qc&&typeof t.pipe=="function"&&t.pipe!==uf.Writable.prototype.pipe,tw=t=>!!t&&typeof t=="object"&&t instanceof qc&&typeof t.write=="function"&&typeof t.end=="function",Wt=Symbol("EOF"),Kt=Symbol("maybeEmitEnd"),gn=Symbol("emittedEnd"),Ps=Symbol("emittingEnd"),pi=Symbol("emittedError"),Os=Symbol("closed"),Ru=Symbol("read"),Ls=Symbol("flush"),Pu=Symbol("flushChunk"),_t=Symbol("encoding"),Er=Symbol("decoder"),ze=Symbol("flowing"),gi=Symbol("paused"),Ar=Symbol("resume"),Ue=Symbol("buffer"),Qe=Symbol("pipes"),qe=Symbol("bufferLength"),Va=Symbol("bufferPush"),Ns=Symbol("bufferShift"),Ze=Symbol("objectMode"),Ie=Symbol("destroyed"),Ja=Symbol("error"),Ya=Symbol("emitData"),Ou=Symbol("emitEnd"),Za=Symbol("emitEnd2"),kt=Symbol("async"),Xa=Symbol("abort"),Ms=Symbol("aborted"),mi=Symbol("signal"),zn=Symbol("dataListeners"),it=Symbol("discarded"),wi=t=>Promise.resolve().then(t),nw=t=>t(),rw=t=>t==="end"||t==="finish"||t==="prefinish",iw=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,sw=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),ff=class{src;dest;opts;ondrain;constructor(t,e,n){this.src=t,this.dest=e,this.opts=n,this.ondrain=()=>t[Ar](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ow=class extends ff{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)}},aw=t=>!!t.objectMode,cw=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Zn=class extends qc{[ze]=!1;[gi]=!1;[Qe]=[];[Ue]=[];[Ze];[_t];[kt];[Er];[Wt]=!1;[gn]=!1;[Ps]=!1;[Os]=!1;[pi]=null;[qe]=0;[Ie]=!1;[mi];[Ms]=!1;[zn]=0;[it]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");aw(e)?(this[Ze]=!0,this[_t]=null):cw(e)?(this[_t]=e.encoding,this[Ze]=!1):(this[Ze]=!1,this[_t]=null),this[kt]=!!e.async,this[Er]=this[_t]?new Xm(this[_t]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Ue]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Qe]});let{signal:n}=e;n&&(this[mi]=n,n.aborted?this[Xa]():n.addEventListener("abort",()=>this[Xa]()))}get bufferLength(){return this[qe]}get encoding(){return this[_t]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ze]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[kt]}set async(t){this[kt]=this[kt]||!!t}[Xa](){this[Ms]=!0,this.emit("abort",this[mi]?.reason),this.destroy(this[mi]?.reason)}get aborted(){return this[Ms]}set aborted(t){}write(t,e,n){if(this[Ms])return!1;if(this[Wt])throw new Error("write after end");if(this[Ie])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[kt]?wi:nw;if(!this[Ze]&&!Buffer.isBuffer(t)){if(sw(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(iw(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ze]?(this[ze]&&this[qe]!==0&&this[Ls](!0),this[ze]?this.emit("data",t):this[Va](t),this[qe]!==0&&this.emit("readable"),n&&i(n),this[ze]):t.length?(typeof t=="string"&&!(e===this[_t]&&!this[Er]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[_t]&&(t=this[Er].write(t)),this[ze]&&this[qe]!==0&&this[Ls](!0),this[ze]?this.emit("data",t):this[Va](t),this[qe]!==0&&this.emit("readable"),n&&i(n),this[ze]):(this[qe]!==0&&this.emit("readable"),n&&i(n),this[ze])}read(t){if(this[Ie])return null;if(this[it]=!1,this[qe]===0||t===0||t&&t>this[qe])return this[Kt](),null;this[Ze]&&(t=null),this[Ue].length>1&&!this[Ze]&&(this[Ue]=[this[_t]?this[Ue].join(""):Buffer.concat(this[Ue],this[qe])]);let e=this[Ru](t||null,this[Ue][0]);return this[Kt](),e}[Ru](t,e){if(this[Ze])this[Ns]();else{let n=e;t===n.length||t===null?this[Ns]():typeof n=="string"?(this[Ue][0]=n.slice(t),e=n.slice(0,t),this[qe]-=t):(this[Ue][0]=n.subarray(t),e=n.subarray(0,t),this[qe]-=t)}return this.emit("data",e),!this[Ue].length&&!this[Wt]&&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[Wt]=!0,this.writable=!1,(this[ze]||!this[gi])&&this[Kt](),this}[Ar](){this[Ie]||(!this[zn]&&!this[Qe].length&&(this[it]=!0),this[gi]=!1,this[ze]=!0,this.emit("resume"),this[Ue].length?this[Ls]():this[Wt]?this[Kt]():this.emit("drain"))}resume(){return this[Ar]()}pause(){this[ze]=!1,this[gi]=!0,this[it]=!1}get destroyed(){return this[Ie]}get flowing(){return this[ze]}get paused(){return this[gi]}[Va](t){this[Ze]?this[qe]+=1:this[qe]+=t.length,this[Ue].push(t)}[Ns](){return this[Ze]?this[qe]-=1:this[qe]-=this[Ue][0].length,this[Ue].shift()}[Ls](t=!1){do;while(this[Pu](this[Ns]())&&this[Ue].length);!t&&!this[Ue].length&&!this[Wt]&&this.emit("drain")}[Pu](t){return this.emit("data",t),this[ze]}pipe(t,e){if(this[Ie])return t;this[it]=!1;let n=this[gn];return e=e||{},t===Du.stdout||t===Du.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,n?e.end&&t.end():(this[Qe].push(e.proxyErrors?new ow(this,t,e):new ff(this,t,e)),this[kt]?wi(()=>this[Ar]()):this[Ar]()),t}unpipe(t){let e=this[Qe].find(n=>n.dest===t);e&&(this[Qe].length===1?(this[ze]&&this[zn]===0&&(this[ze]=!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[it]=!1,this[zn]++,!this[Qe].length&&!this[ze]&&this[Ar]();else if(t==="readable"&&this[qe]!==0)super.emit("readable");else if(rw(t)&&this[gn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[pi]){let i=e;this[kt]?wi(()=>i.call(this,this[pi])):i.call(this,this[pi])}return n}removeListener(t,e){return this.off(t,e)}off(t,e){let n=super.off(t,e);return t==="data"&&(this[zn]=this.listeners("data").length,this[zn]===0&&!this[it]&&!this[Qe].length&&(this[ze]=!1)),n}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[zn]=0,!this[it]&&!this[Qe].length&&(this[ze]=!1)),e}get emittedEnd(){return this[gn]}[Kt](){!this[Ps]&&!this[gn]&&!this[Ie]&&this[Ue].length===0&&this[Wt]&&(this[Ps]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Os]&&this.emit("close"),this[Ps]=!1)}emit(t,...e){let n=e[0];if(t!=="error"&&t!=="close"&&t!==Ie&&this[Ie])return!1;if(t==="data")return!this[Ze]&&!n?!1:this[kt]?(wi(()=>this[Ya](n)),!0):this[Ya](n);if(t==="end")return this[Ou]();if(t==="close"){if(this[Os]=!0,!this[gn]&&!this[Ie])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[pi]=n,super.emit(Ja,n);let o=!this[mi]||this.listeners("error").length?super.emit("error",n):!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}[Ya](t){for(let n of this[Qe])n.dest.write(t)===!1&&this.pause();let e=this[it]?!1:super.emit("data",t);return this[Kt](),e}[Ou](){return this[gn]?!1:(this[gn]=!0,this.readable=!1,this[kt]?(wi(()=>this[Za]()),!0):this[Za]())}[Za](){if(this[Er]){let e=this[Er].end();if(e){for(let n of this[Qe])n.dest.write(e);this[it]||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[Ze]||(t.dataLength=0);let e=this.promise();return this.on("data",n=>{t.push(n),this[Ze]||(t.dataLength+=n.length)}),await e,t}async concat(){if(this[Ze])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[_t]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ie,()=>e(new Error("stream destroyed"))),this.on("error",n=>e(n)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[it]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[Wt])return e();let i,o,a=x=>{this.off("data",d),this.off("end",u),this.off(Ie,f),e(),o(x)},d=x=>{this.off("error",a),this.off("end",u),this.off(Ie,f),this.pause(),i({value:x,done:!!this[Wt]})},u=()=>{this.off("error",a),this.off("data",d),this.off(Ie,f),e(),i({done:!0,value:void 0})},f=()=>a(new Error("stream destroyed"));return new Promise((x,g)=>{o=g,i=x,this.once(Ie,f),this.once("error",a),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[it]=!1;let t=!1,e=()=>(this.pause(),this.off(Ja,e),this.off(Ie,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(Ja,e),this.once(Ie,e),{next:n,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Ie])return t?this.emit("error",t):this.emit(Ie),this;this[Ie]=!0,this[it]=!0,this[Ue].length=0,this[qe]=0;let e=this;return typeof e.close=="function"&&!this[Os]&&e.close(),t?this.emit("error",t):this.emit(Ie),this}static get isStream(){return Qm}},dw=nt.writev,An=Symbol("_autoClose"),vt=Symbol("_close"),_i=Symbol("_ended"),de=Symbol("_fd"),Qa=Symbol("_finished"),Yt=Symbol("_flags"),ec=Symbol("_flush"),yc=Symbol("_handleChunk"),Ec=Symbol("_makeBuf"),Di=Symbol("_mode"),Bs=Symbol("_needDrain"),Rr=Symbol("_onerror"),Pr=Symbol("_onopen"),tc=Symbol("_onread"),kr=Symbol("_onwrite"),kn=Symbol("_open"),bt=Symbol("_path"),En=Symbol("_pos"),Tt=Symbol("_queue"),Tr=Symbol("_read"),nc=Symbol("_readSize"),Jt=Symbol("_reading"),yi=Symbol("_remain"),rc=Symbol("_size"),$s=Symbol("_write"),Un=Symbol("_writing"),Vs=Symbol("_defaultFlag"),$n=Symbol("_errored"),Gc=class extends Zn{[$n]=!1;[de];[bt];[nc];[Jt]=!1;[rc];[yi];[An];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[$n]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[bt]=t,this[nc]=e.readSize||16*1024*1024,this[Jt]=!1,this[rc]=typeof e.size=="number"?e.size:1/0,this[yi]=this[rc],this[An]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[Tr]():this[kn]()}get fd(){return this[de]}get path(){return this[bt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[kn](){nt.open(this[bt],"r",(t,e)=>this[Pr](t,e))}[Pr](t,e){t?this[Rr](t):(this[de]=e,this.emit("open",e),this[Tr]())}[Ec](){return Buffer.allocUnsafe(Math.min(this[nc],this[yi]))}[Tr](){if(!this[Jt]){this[Jt]=!0;let t=this[Ec]();if(t.length===0)return process.nextTick(()=>this[tc](null,0,t));nt.read(this[de],t,0,t.length,null,(e,n,i)=>this[tc](e,n,i))}}[tc](t,e,n){this[Jt]=!1,t?this[Rr](t):this[yc](e,n)&&this[Tr]()}[vt](){if(this[An]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Rr](t){this[Jt]=!0,this[vt](),this.emit("error",t)}[yc](t,e){let n=!1;return this[yi]-=t,t>0&&(n=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[yi]<=0)&&(n=!1,this[vt](),super.end()),n}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[Tr](),!1;case"error":return this[$n]?!1:(this[$n]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},lw=class extends Gc{[kn](){let t=!0;try{this[Pr](null,nt.openSync(this[bt],"r")),t=!1}finally{t&&this[vt]()}}[Tr](){let t=!0;try{if(!this[Jt]){this[Jt]=!0;do{let e=this[Ec](),n=e.length===0?0:nt.readSync(this[de],e,0,e.length,null);if(!this[yc](n,e))break}while(!0);this[Jt]=!1}t=!1}finally{t&&this[vt]()}}[vt](){if(this[An]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,nt.closeSync(t),this.emit("close")}}},lo=class extends Zm{readable=!1;writable=!0;[$n]=!1;[Un]=!1;[_i]=!1;[Tt]=[];[Bs]=!1;[bt];[Di];[An];[de];[Vs];[Yt];[Qa]=!1;[En];constructor(t,e){e=e||{},super(e),this[bt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[Di]=e.mode===void 0?438:e.mode,this[En]=typeof e.start=="number"?e.start:void 0,this[An]=typeof e.autoClose=="boolean"?e.autoClose:!0;let n=this[En]!==void 0?"r+":"w";this[Vs]=e.flags===void 0,this[Yt]=e.flags===void 0?n:e.flags,this[de]===void 0&&this[kn]()}emit(t,...e){if(t==="error"){if(this[$n])return!1;this[$n]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[bt]}[Rr](t){this[vt](),this[Un]=!0,this.emit("error",t)}[kn](){nt.open(this[bt],this[Yt],this[Di],(t,e)=>this[Pr](t,e))}[Pr](t,e){this[Vs]&&this[Yt]==="r+"&&t&&t.code==="ENOENT"?(this[Yt]="w",this[kn]()):t?this[Rr](t):(this[de]=e,this.emit("open",e),this[Un]||this[ec]())}end(t,e){return t&&this.write(t,e),this[_i]=!0,!this[Un]&&!this[Tt].length&&typeof this[de]=="number"&&this[kr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[_i]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[Un]||this[Tt].length?(this[Tt].push(t),this[Bs]=!0,!1):(this[Un]=!0,this[$s](t),!0)}[$s](t){nt.write(this[de],t,0,t.length,this[En],(e,n)=>this[kr](e,n))}[kr](t,e){t?this[Rr](t):(this[En]!==void 0&&typeof e=="number"&&(this[En]+=e),this[Tt].length?this[ec]():(this[Un]=!1,this[_i]&&!this[Qa]?(this[Qa]=!0,this[vt](),this.emit("finish")):this[Bs]&&(this[Bs]=!1,this.emit("drain"))))}[ec](){if(this[Tt].length===0)this[_i]&&this[kr](null,0);else if(this[Tt].length===1)this[$s](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],dw(this[de],t,this[En],(e,n)=>this[kr](e,n))}}[vt](){if(this[An]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},hf=class extends lo{[kn](){let t;if(this[Vs]&&this[Yt]==="r+")try{t=nt.openSync(this[bt],this[Yt],this[Di])}catch(e){if(e?.code==="ENOENT")return this[Yt]="w",this[kn]();throw e}else t=nt.openSync(this[bt],this[Yt],this[Di]);this[Pr](null,t)}[vt](){if(this[An]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,nt.closeSync(t),this.emit("close")}}[$s](t){let e=!0;try{this[kr](null,nt.writeSync(this[de],t,0,t.length,this[En])),e=!1}finally{if(e)try{this[vt]()}catch{}}}},hw=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"]]),xw=t=>!!t.sync&&!!t.file,pw=t=>!t.sync&&!!t.file,gw=t=>!!t.sync&&!t.file,mw=t=>!t.sync&&!t.file,ww=t=>!!t.file,_w=t=>hw.get(t)||t,Hc=(t={})=>{if(!t)return{};let e={};for(let[n,i]of Object.entries(t)){let o=_w(n);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},zi=(t,e,n,i,o)=>Object.assign((a=[],d,u)=>{Array.isArray(a)&&(d=a,a={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=Hc(a);if(o?.(f,d),xw(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if(pw(f)){let x=e(f,d);return u?x.then(()=>u(),u):x}else if(gw(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return n(f,d)}else if(mw(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:n,asyncNoFile:i,validate:o}),bw=Ew.constants||{ZLIB_VERNUM:4736},Pt=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},bw)),vw=Vn.concat,Nu=Object.getOwnPropertyDescriptor(Vn,"concat"),Sw=t=>t,ic=Nu?.writable===!0||Nu?.set!==void 0?t=>{Vn.concat=t?Sw:vw}:t=>{},Jn=Symbol("_superWrite"),Fs=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"}},sc=Symbol("flushFlag"),jc=class extends Zn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof Lu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new Lu[e](t)}catch(n){throw new Fs(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 Fs(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return bc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Vn.alloc(0),{[sc]: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}[Jn](t){return super.write(t)}write(t,e,n){if(typeof e=="function"&&(n=e,e="utf8"),typeof t=="string"&&(t=Vn.from(t,e)),this.#e)return;bc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let a=this.#t.close;this.#t.close=()=>{},ic(!0);let d;try{let f=typeof t[sc]=="number"?t[sc]:this.#r;d=this.#t._processChunk(t,f),ic(!1)}catch(f){ic(!1),this.#o(new Fs(f,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=a,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",f=>this.#o(new Fs(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[Jn](Vn.from(f));for(let x=1;x<d.length;x++)u=this[Jn](d[x])}else u=this[Jn](Vn.from(d));return n&&n(),u}},pf=class extends jc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Pt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Pt.Z_FINISH,t.fullFlushFlag=Pt.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(Pt.Z_SYNC_FLUSH),bc(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)}}}},Iw=class extends pf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Jn](t){return this.#e?(this.#e=!1,t[9]=255,super[Jn](t)):super[Jn](t)}},Aw=class extends pf{constructor(t){super(t,"Unzip")}},gf=class extends jc{constructor(t,e){t=t||{},t.flush=t.flush||Pt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Pt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Pt.BROTLI_OPERATION_FLUSH,super(t,e)}},kw=class extends gf{constructor(t){super(t,"BrotliCompress")}},Tw=class extends gf{constructor(t){super(t,"BrotliDecompress")}},mf=class extends jc{constructor(t,e){t=t||{},t.flush=t.flush||Pt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Pt.ZSTD_e_end,t.fullFlushFlag=Pt.ZSTD_e_flush,super(t,e)}},Cw=class extends mf{constructor(t){super(t,"ZstdCompress")}},Dw=class extends mf{constructor(t){super(t,"ZstdDecompress")}},Rw=(t,e)=>{if(Number.isSafeInteger(t))t<0?Ow(t,e):Pw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Pw=(t,e)=>{e[0]=128;for(var n=e.length;n>1;n--)e[n-1]=t&255,t=Math.floor(t/256)},Ow=(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]=wf(o):o===0?e[i-1]=0:(n=!0,e[i-1]=_f(o))}},Lw=t=>{let e=t[0],n=e===128?Mw(t.subarray(1,t.length)):e===255?Nw(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},Nw=t=>{for(var e=t.length,n=0,i=!1,o=e-1;o>-1;o--){var a=Number(t[o]),d;i?d=wf(a):a===0?d=a:(i=!0,d=_f(a)),d!==0&&(n-=d*Math.pow(256,e-o-1))}return n},Mw=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},wf=t=>(255^t)&255,_f=t=>(255^t)+1&255,Bw={};Ym(Bw,{code:()=>Wc,isCode:()=>Js,isName:()=>Fw,name:()=>uo});var Js=t=>uo.has(t),Fw=t=>Wc.has(t),uo=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"]]),Wc=new Map(Array.from(uo).map(t=>[t[1],t[0]])),Yn=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");this.path=n?.path??qn(t,e,100),this.mode=n?.mode??i?.mode??bn(t,e+100,8),this.uid=n?.uid??i?.uid??bn(t,e+108,8),this.gid=n?.gid??i?.gid??bn(t,e+116,8),this.size=n?.size??i?.size??bn(t,e+124,12),this.mtime=n?.mtime??i?.mtime??oc(t,e+136,12),this.cksum=bn(t,e+148,12),i&&this.#n(i,!0),n&&this.#n(n);let o=qn(t,e+156,1);if(Js(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=qn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=n?.uname??i?.uname??qn(t,e+265,32),this.gname=n?.gname??i?.gname??qn(t,e+297,32),this.devmaj=n?.devmaj??i?.devmaj??bn(t,e+329,8)??0,this.devmin=n?.devmin??i?.devmin??bn(t,e+337,8)??0,t[e+475]!==0){let d=qn(t,e+345,155);this.path=d+"/"+this.path}else{let d=qn(t,e+345,130);d&&(this.path=d+"/"+this.path),this.atime=n?.atime??i?.atime??oc(t,e+476,12),this.ctime=n?.ctime??i?.ctime??oc(t,e+488,12)}let a=256;for(let d=e;d<e+148;d++)a+=t[d];for(let d=e+156;d<e+512;d++)a+=t[d];this.cksumValid=a===this.cksum,this.cksum===void 0&&a===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=zw(this.path||"",n),o=i[0],a=i[1];this.needPax=!!i[2],this.needPax=Gn(t,e,100,o)||this.needPax,this.needPax=vn(t,e+100,8,this.mode)||this.needPax,this.needPax=vn(t,e+108,8,this.uid)||this.needPax,this.needPax=vn(t,e+116,8,this.gid)||this.needPax,this.needPax=vn(t,e+124,12,this.size)||this.needPax,this.needPax=ac(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Gn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Gn(t,e+265,32,this.uname)||this.needPax,this.needPax=Gn(t,e+297,32,this.gname)||this.needPax,this.needPax=vn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=vn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Gn(t,e+345,n,a)||this.needPax,t[e+475]!==0?this.needPax=Gn(t,e+345,155,a)||this.needPax:(this.needPax=Gn(t,e+345,130,a)||this.needPax,this.needPax=ac(t,e+476,12,this.atime)||this.needPax,this.needPax=ac(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,vn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:uo.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Wc.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)}},zw=(t,e)=>{let n=t,i="",o,a=br.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,i,!1];else{i=br.dirname(n),n=br.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=br.join(br.basename(i),n),i=br.dirname(i));while(i!==a&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},qn=(t,e,n)=>t.subarray(e,e+n).toString("utf8").replace(/\0.*/,""),oc=(t,e,n)=>Uw(bn(t,e,n)),Uw=t=>t===void 0?void 0:new Date(t*1e3),bn=(t,e,n)=>Number(t[e])&128?Lw(t.subarray(e,e+n)):Gw(t,e,n),qw=t=>isNaN(t)?void 0:t,Gw=(t,e,n)=>qw(parseInt(t.subarray(e,e+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),Hw={12:8589934591,8:2097151},vn=(t,e,n,i)=>i===void 0?!1:i>Hw[n]||i<0?(Rw(i,t.subarray(e,e+n)),!0):(jw(t,e,n,i),!1),jw=(t,e,n,i)=>t.write(Ww(i,n),e,n,"ascii"),Ww=(t,e)=>Kw(Math.floor(t).toString(8),e),Kw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",ac=(t,e,n,i)=>i===void 0?!1:vn(t,e,n,i.getTime()/1e3),$w=new Array(156).join("\0"),Gn=(t,e,n,i)=>i===void 0?!1:(t.write(i+$w,e,n,"utf8"),i.length!==Buffer.byteLength(i)||i.length>n),io=class yf{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 a=0;a<512;a++)o[a]=0;new Yn({path:("PaxHeader/"+Vw(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 a=n+512;a<o.length;a++)o[a]=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
|
+
`,a=Buffer.byteLength(o),d=Math.floor(Math.log(a)/Math.log(10))+1;return a+d>=Math.pow(10,d)&&(d+=1),d+a+o}static parse(e,n,i=!1){return new yf(Jw(Yw(e),n),i)}},Jw=(t,e)=>e?Object.assign({},e,t):t,Yw=t=>t.replace(/\n$/,"").split(`
|
|
91
|
+
`).reduce(Zw,Object.create(null)),Zw=(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 a=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[a]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(a)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,ee=Xw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Ef=class extends Zn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,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))))}},fo=(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,vc=Buffer.from([31,139]),Sc=Buffer.from([40,181,47,253]),e_=Math.max(vc.length,Sc.length),ut=Symbol("state"),Hn=Symbol("writeEntry"),$t=Symbol("readEntry"),cc=Symbol("nextEntry"),Mu=Symbol("processEntry"),Ct=Symbol("extendedHeader"),Ei=Symbol("globalExtendedHeader"),mn=Symbol("meta"),Bu=Symbol("emitMeta"),ge=Symbol("buffer"),Vt=Symbol("queue"),wn=Symbol("ended"),dc=Symbol("emittedEnd"),jn=Symbol("emit"),De=Symbol("unzip"),zs=Symbol("consumeChunk"),Us=Symbol("consumeChunkSub"),lc=Symbol("consumeBody"),Fu=Symbol("consumeMeta"),zu=Symbol("consumeHeader"),bi=Symbol("consuming"),uc=Symbol("bufferConcat"),qs=Symbol("maybeEnd"),vr=Symbol("writing"),_n=Symbol("aborted"),Gs=Symbol("onDone"),Wn=Symbol("sawValidEntry"),Hs=Symbol("sawNullBlock"),js=Symbol("sawEOF"),Uu=Symbol("closeStream"),t_=()=>!0,Fi=class extends yw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Vt]=[];[ge];[$t];[Hn];[ut]="begin";[mn]="";[Ct];[Ei];[wn]=!1;[De];[_n]=!1;[Wn];[Hs]=!1;[js]=!1;[vr]=!1;[bi]=!1;[dc]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Gs,()=>{(this[ut]==="begin"||this[Wn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Gs,t.ondone):this.on(Gs,()=>{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:t_;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[Uu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,n={}){fo(this,t,e,n)}[zu](t,e){this[Wn]===void 0&&(this[Wn]=!1);let n;try{n=new Yn(t,e,this[Ct],this[Ei])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(n.nullBlock)this[Hs]?(this[js]=!0,this[ut]==="begin"&&(this[ut]="header"),this[jn]("eof")):(this[Hs]=!0,this[jn]("nullBlock"));else if(this[Hs]=!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[Hn]=new Ef(n,this[Ct],this[Ei]);if(!this[Wn])if(o.remain){let a=()=>{o.invalid||(this[Wn]=!0)};o.on("end",a)}else this[Wn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[jn]("ignoredEntry",o),this[ut]="ignore",o.resume()):o.size>0&&(this[mn]="",o.on("data",a=>this[mn]+=a),this[ut]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[jn]("ignoredEntry",o),this[ut]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ut]="body":(this[ut]="header",o.end()),this[$t]?this[Vt].push(o):(this[Vt].push(o),this[cc]())))}}}[Uu](){queueMicrotask(()=>this.emit("close"))}[Mu](t){let e=!0;if(!t)this[$t]=void 0,e=!1;else if(Array.isArray(t)){let[n,...i]=t;this.emit(n,...i)}else this[$t]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[cc]()),e=!1);return e}[cc](){do;while(this[Mu](this[Vt].shift()));if(this[Vt].length===0){let t=this[$t];!t||t.flowing||t.size===t.remain?this[vr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[lc](t,e){let n=this[Hn];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[Hn]=void 0,n.end()),o.length}[Fu](t,e){let n=this[Hn],i=this[lc](t,e);return!this[Hn]&&n&&this[Bu](n),i}[jn](t,e,n){this[Vt].length===0&&!this[$t]?this.emit(t,e,n):this[Vt].push([t,e,n])}[Bu](t){switch(this[jn]("meta",this[mn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=io.parse(this[mn],this[Ct],!1);break;case"GlobalExtendedHeader":this[Ei]=io.parse(this[mn],this[Ei],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[mn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=e,e.linkpath=this[mn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[_n]=!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[_n])return n?.(),!1;if((this[De]===void 0||this.brotli===void 0&&this[De]===!1)&&t){if(this[ge]&&(t=Buffer.concat([this[ge],t]),this[ge]=void 0),t.length<e_)return this[ge]=t,n?.(),!0;for(let d=0;this[De]===void 0&&d<vc.length;d++)t[d]!==vc[d]&&(this[De]=!1);let o=!1;if(this[De]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<Sc.length;d++)if(t[d]!==Sc[d]){o=!1;break}}let a=this.brotli===void 0&&!o;if(this[De]===!1&&a)if(t.length<512)if(this[wn])this.brotli=!0;else return this[ge]=t,n?.(),!0;else try{new Yn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[De]===void 0||this[De]===!1&&(this.brotli||o)){let d=this[wn];this[wn]=!1,this[De]=this[De]===void 0?new Aw({}):o?new Dw({}):new Tw({}),this[De].on("data",f=>this[zs](f)),this[De].on("error",f=>this.abort(f)),this[De].on("end",()=>{this[wn]=!0,this[zs]()}),this[vr]=!0;let u=!!this[De][d?"end":"write"](t);return this[vr]=!1,n?.(),u}}this[vr]=!0,this[De]?this[De].write(t):this[zs](t),this[vr]=!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")),n?.(),i}[uc](t){t&&!this[_n]&&(this[ge]=this[ge]?Buffer.concat([this[ge],t]):t)}[qs](){if(this[wn]&&!this[dc]&&!this[_n]&&!this[bi]){this[dc]=!0;let t=this[Hn];if(t&&t.blockRemain){let e=this[ge]?this[ge].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ge]&&t.write(this[ge]),t.end()}this[jn](Gs)}}[zs](t){if(this[bi]&&t)this[uc](t);else if(!t&&!this[ge])this[qs]();else if(t){if(this[bi]=!0,this[ge]){this[uc](t);let e=this[ge];this[ge]=void 0,this[Us](e)}else this[Us](t);for(;this[ge]&&this[ge]?.length>=512&&!this[_n]&&!this[js];){let e=this[ge];this[ge]=void 0,this[Us](e)}this[bi]=!1}(!this[ge]||this[wn])&&this[qs]()}[Us](t){let e=0,n=t.length;for(;e+512<=n&&!this[_n]&&!this[js];)switch(this[ut]){case"begin":case"header":this[zu](t,e),e+=512;break;case"ignore":case"body":e+=this[lc](t,e);break;case"meta":e+=this[Fu](t,e);break;default:throw new Error("invalid state: "+this[ut])}e<n&&(this[ge]=this[ge]?Buffer.concat([t.subarray(e),this[ge]]):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[_n]||(this[De]?(t&&this[De].write(t),this[De].end()):(this[wn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[qs]())),this}},Ri=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)},n_=t=>{let e=t.onReadEntry;t.onReadEntry=e?n=>{e(n),n.resume()}:n=>n.resume()},bf=(t,e)=>{let n=new Map(e.map(a=>[Ri(a),!0])),i=t.filter,o=(a,d="")=>{let u=d||fw(a).root||".",f;if(a===u)f=!1;else{let x=n.get(a);f=x!==void 0?x:o(uw(a),u)}return n.set(a,f),f};t.filter=i?(a,d)=>i(a,d)&&o(Ri(a)):a=>o(Ri(a))},r_=t=>{let e=new Fi(t),n=t.file,i;try{i=Cr.openSync(n,"r");let o=Cr.fstatSync(i),a=t.maxReadSize||16*1024*1024;if(o.size<a){let d=Buffer.allocUnsafe(o.size),u=Cr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(a);for(;d<o.size;){let f=Cr.readSync(i,u,0,a,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{Cr.closeSync(i)}catch{}}},i_=(t,e)=>{let n=new Fi(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((a,d)=>{n.on("error",d),n.on("end",a),Cr.stat(o,(u,f)=>{if(u)d(u);else{let x=new Gc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(n)}})})},Or=zi(r_,i_,t=>new Fi(t),t=>new Fi(t),(t,e)=>{e?.length&&bf(t,e),t.noResume||n_(t)}),vf=(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:o_,parse:Gu}=s_,Kc=t=>{let e="",n=Gu(t);for(;o_(t)||n.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":n.root;t=t.slice(i.length),e+=i,n=Gu(t)}return[e,t]},ho=["|","<",">","?",":"],$c=ho.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),a_=new Map(ho.map((t,e)=>[t,$c[e]])),c_=new Map($c.map((t,e)=>[t,ho[e]])),Hu=t=>ho.reduce((e,n)=>e.split(n).join(a_.get(n)),t),d_=t=>$c.reduce((e,n)=>e.split(n).join(c_.get(n)),t),Sf=(t,e)=>e?(t=ee(t).replace(/^\.(\/|$)/,""),Ri(e)+"/"+t):ee(t),l_=16*1024*1024,ju=Symbol("process"),Wu=Symbol("file"),Ku=Symbol("directory"),Ic=Symbol("symlink"),$u=Symbol("hardlink"),vi=Symbol("header"),Ys=Symbol("read"),Ac=Symbol("lstat"),Zs=Symbol("onlstat"),kc=Symbol("onread"),Tc=Symbol("onreadlink"),Cc=Symbol("openfile"),Dc=Symbol("onopenfile"),Sn=Symbol("close"),oo=Symbol("mode"),Rc=Symbol("awaitDrain"),fc=Symbol("ondrain"),Rt=Symbol("prefix"),If=class extends Zn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let n=Hc(e);super(),this.path=ee(t),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||l_,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[a,d]=Kc(this.path);a&&typeof d=="string"&&(this.path=d,i=a)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=d_(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=ee(n.absolute||qu.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[Zs](o):this[Ac]()}warn(t,e,n={}){return fo(this,t,e,n)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[Ac](){Dt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Zs](e)})}[Zs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=h_(t),this.emit("stat",t),this[ju]()}[ju](){switch(this.type){case"File":return this[Wu]();case"Directory":return this[Ku]();case"SymbolicLink":return this[Ic]();default:return this.end()}}[oo](t){return vf(t,this.type==="Directory",this.portable)}[Rt](t){return Sf(t,this.prefix)}[vi](){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 Yn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[oo](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 io({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Ku](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[vi](),this.end()}[Ic](){Dt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Tc](e)})}[Tc](t){this.linkpath=ee(t),this[vi](),this.end()}[$u](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=ee(qu.relative(this.cwd,t)),this.stat.size=0,this[vi](),this.end()}[Wu](){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[$u](e);this.linkCache.set(t,this.absolute)}if(this[vi](),this.stat.size===0)return this.end();this[Cc]()}[Cc](){Dt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Dc](e)})}[Dc](t){if(this.fd=t,this.#e)return this[Sn]();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[Ys]()}[Ys](){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");Dt.read(t,e,n,i,o,(a,d)=>{if(a)return this[Sn](()=>this.emit("error",a));this[kc](d)})}[Sn](t=()=>{}){this.fd!==void 0&&Dt.close(this.fd,t)}[kc](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[Sn](()=>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[Sn](()=>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[fc]():this[Rc](()=>this[fc]())}[Rc](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)}[fc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[Sn](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[Ys]()}},u_=class extends If{sync=!0;[Ac](){this[Zs](Dt.lstatSync(this.absolute))}[Ic](){this[Tc](Dt.readlinkSync(this.absolute))}[Cc](){this[Dc](Dt.openSync(this.absolute,"r"))}[Ys](){let t=!0;try{let{fd:e,buf:n,offset:i,length:o,pos:a}=this;if(e===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let d=Dt.readSync(e,n,i,o,a);this[kc](d),t=!1}finally{if(t)try{this[Sn](()=>{})}catch{}}}[Rc](t){t()}[Sn](t=()=>{}){this.fd!==void 0&&Dt.closeSync(this.fd),t()}},f_=class extends Zn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,n={}){return fo(this,t,e,n)}constructor(t,e={}){let n=Hc(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[oo](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]=Kc(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 Yn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new io({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let a=this.header?.block;if(!a)throw new Error("failed to encode header");super.write(a),t.pipe(this)}[Rt](t){return Sf(t,this.prefix)}[oo](t){return vf(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}},h_=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",x_=class Dr{tail;head;length=0;static create(e=[]){return new Dr(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++)g_(this,e[n]);return this.length}unshift(...e){for(var n=0,i=e.length;n<i;n++)m_(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 Dr;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 Dr;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 a=0;o;a++)i=e(i,o.value,a),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 a=this.length-1;o;a--)i=e(i,o.value,a),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 Dr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.head,a=0;for(a=0;o&&a<e;a++)o=o.next;for(;o&&a<n;a++,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 Dr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.length,a=this.tail;for(;a&&o>n;o--)a=a.prev;for(;a&&o>e;o--,a=a.prev)i.push(a.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 a=[];for(let d=0;o&&d<n;d++)a.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=p_(this,o,d);return a}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 p_(t,e,n){let i=e,o=e?e.next:t.head,a=new Vc(n,i,o,t);return a.next===void 0&&(t.tail=a),a.prev===void 0&&(t.head=a),t.length++,a}function g_(t,e){t.tail=new Vc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function m_(t,e){t.head=new Vc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Vc=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}},Ju=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Yu=Buffer.alloc(1024),Xs=Symbol("onStat"),Si=Symbol("ended"),yt=Symbol("queue"),Ii=Symbol("queue"),yn=Symbol("current"),Kn=Symbol("process"),Ai=Symbol("processing"),Ws=Symbol("processJob"),Et=Symbol("jobs"),hc=Symbol("jobDone"),Qs=Symbol("addFSEntry"),Zu=Symbol("addTarEntry"),Pc=Symbol("stat"),Oc=Symbol("readdir"),eo=Symbol("onreaddir"),to=Symbol("pipe"),Xu=Symbol("entry"),xc=Symbol("entryOpt"),no=Symbol("writeEntryClass"),Af=Symbol("write"),pc=Symbol("ondrain"),xo=class extends Zn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[no];onWriteEntry;[yt];[Ii]=new Map;[Et]=0;[Ai]=!1;[Si]=!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[no]=If,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 Iw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new kw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Cw(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[pc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[pc]);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[yt]=new x_,this[Et]=0,this.jobs=Number(t.jobs)||4,this[Ai]=!1,this[Si]=!1}[Af](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[Si]=!0,this[Kn](),n&&n(),this}write(t){if(this[Si])throw new Error("write after end");return t instanceof Ef?this[Zu](t):this[Qs](t),this.flowing}[Zu](t){let e=ee(Vu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let n=new Ju(t.path,e);n.entry=new f_(t,this[xc](n)),n.entry.on("end",()=>this[hc](n)),this[Et]+=1,this[yt].push(n)}this[Kn]()}[Qs](t){let e=ee(Vu.resolve(this.cwd,t));this[yt].push(new Ju(t,e)),this[Kn]()}[Pc](t){t.pending=!0,this[Et]+=1;let e=this.follow?"stat":"lstat";so[e](t.absolute,(n,i)=>{t.pending=!1,this[Et]-=1,n?this.emit("error",n):this[Xs](t,i)})}[Xs](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[yn])this[Ws](t);else{let n=`${e.dev}:${e.ino}`,i=this[Ii].get(n);i?i.push(t):this[Ii].set(n,[t]),t.pendingLink=!0,t.pending=!0}this[Kn]()}[Oc](t){t.pending=!0,this[Et]+=1,so.readdir(t.absolute,(e,n)=>{if(t.pending=!1,this[Et]-=1,e)return this.emit("error",e);this[eo](t,n)})}[eo](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Kn]()}[Kn](){if(!this[Ai]){this[Ai]=!0;for(let t=this[yt].head;t&&this[Et]<this.jobs;t=t.next)if(this[Ws](t.value),t.value.ignore){let e=t.next;this[yt].removeNode(t),t.next=e}this[Ai]=!1,this[Si]&&this[yt].length===0&&this[Et]===0&&(this.zip?this.zip.end(Yu):(super.write(Yu),super.end()))}}get[yn](){return this[yt]&&this[yt].head&&this[yt].head.value}[hc](t){this[yt].shift(),this[Et]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let n=`${e.dev}:${e.ino}`,i=this[Ii].get(n);if(i){this[Ii].delete(n);for(let o of i)o.pending=!1,this[Ws](o)}}this[Kn]()}[Ws](t){if(t.pending&&t.pendingLink&&t===this[yn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[yn]&&!t.piped&&this[to](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Xs](t,e):this[Pc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[eo](t,e):this[Oc](t),!t.readdir)return}if(t.entry=this[Xu](t),!t.entry){t.ignore=!0;return}t===this[yn]&&!t.piped&&this[to](t)}}}[xc](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}}[Xu](t){this[Et]+=1;try{return new this[no](t.path,this[xc](t)).on("end",()=>this[hc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[pc](){this[yn]&&this[yn].entry&&this[yn].entry.resume()}[to](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,a=o==="./"?"":o.replace(/\/*$/,"/");this[Qs](a+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={}){fo(this,t,e,n)}},Jc=class extends xo{sync=!0;constructor(t){super(t),this[no]=u_}pause(){}resume(){}[Pc](t){let e=this.follow?"statSync":"lstatSync";this[Xs](t,so[e](t.absolute))}[Oc](t){this[eo](t,so.readdirSync(t.absolute))}[to](t){let e=t.entry,n=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,a=o==="./"?"":o.replace(/\/*$/,"/");this[Qs](a+i)}),!e)throw new Error("Cannot pipe without source");n?e.on("data",i=>{n.write(i)}):e.on("data",i=>{super[Af](i)})}},w_=(t,e)=>{let n=new Jc(t),i=new hf(t.file,{mode:t.mode||438});n.pipe(i),kf(n,e)},__=(t,e)=>{let n=new xo(t),i=new lo(t.file,{mode:t.mode||438});n.pipe(i);let o=new Promise((a,d)=>{i.on("error",d),i.on("close",a),n.on("error",d)});return Tf(n,e).catch(a=>n.emit("error",a)),o},kf=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Or({file:xf.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},Tf=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Or({file:xf.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(n);t.end()},y_=(t,e)=>{let n=new Jc(t);return kf(n,e),n},E_=(t,e)=>{let n=new xo(t);return Tf(n,e).catch(i=>n.emit("error",i)),n},xA=zi(w_,__,y_,E_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),v_=process.env.__FAKE_PLATFORM__||process.platform,Pf=v_==="win32",{O_CREAT:Of,O_NOFOLLOW:Qu,O_TRUNC:Lf,O_WRONLY:Nf}=Rf.constants,Mf=Number(process.env.__FAKE_FS_O_FILENAME__)||Rf.constants.UV_FS_O_FILEMAP||0,S_=Pf&&!!Mf,I_=512*1024,A_=Mf|Lf|Of|Nf,ef=!Pf&&typeof Qu=="number"?Qu|Lf|Of|Nf:null,Bf=ef!==null?()=>ef:S_?t=>t<I_?A_:"w":()=>"w",Lc=(t,e,n)=>{try{return po.lchownSync(t,e,n)}catch(i){if(i?.code!=="ENOENT")throw i}},ao=(t,e,n,i)=>{po.lchown(t,e,n,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},k_=(t,e,n,i,o)=>{if(e.isDirectory())Ff(Pi.resolve(t,e.name),n,i,a=>{if(a)return o(a);let d=Pi.resolve(t,e.name);ao(d,n,i,o)});else{let a=Pi.resolve(t,e.name);ao(a,n,i,o)}},Ff=(t,e,n,i)=>{po.readdir(t,{withFileTypes:!0},(o,a)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!a.length)return ao(t,e,n,i);let d=a.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--d===0)return ao(t,e,n,i)}};for(let x of a)k_(t,x,e,n,f)})},T_=(t,e,n,i)=>{e.isDirectory()&&zf(Pi.resolve(t,e.name),n,i),Lc(Pi.resolve(t,e.name),n,i)},zf=(t,e,n)=>{let i;try{i=po.readdirSync(t,{withFileTypes:!0})}catch(o){let a=o;if(a?.code==="ENOENT")return;if(a?.code==="ENOTDIR"||a?.code==="ENOTSUP")return Lc(t,e,n);throw a}for(let o of i)T_(t,o,e,n);return Lc(t,e,n)},Uf=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"}},go=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},D_=(t,e)=>{ot.stat(t,(n,i)=>{(n||!i.isDirectory())&&(n=new Uf(t,n?.code||"ENOTDIR")),e(n)})},R_=(t,e,n)=>{t=ee(t);let i=e.umask??18,o=e.mode|448,a=(o&i)!==0,d=e.uid,u=e.gid,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,g=e.unlink,w=ee(e.cwd),S=(b,I)=>{b?n(b):I&&f?Ff(I,d,u,A=>S(A)):a?ot.chmod(t,o,n):n()};if(t===w)return D_(t,S);if(x)return C_.mkdir(t,{mode:o,recursive:!0}).then(b=>S(null,b??void 0),S);let _=ee(co.relative(w,t)).split("/");Nc(w,_,o,g,w,void 0,S)},Nc=(t,e,n,i,o,a,d)=>{if(e.length===0)return d(null,a);let u=e.shift(),f=ee(co.resolve(t+"/"+u));ot.mkdir(f,n,qf(f,e,n,i,o,a,d))},qf=(t,e,n,i,o,a,d)=>u=>{u?ot.lstat(t,(f,x)=>{if(f)f.path=f.path&&ee(f.path),d(f);else if(x.isDirectory())Nc(t,e,n,i,o,a,d);else if(i)ot.unlink(t,g=>{if(g)return d(g);ot.mkdir(t,n,qf(t,e,n,i,o,a,d))});else{if(x.isSymbolicLink())return d(new go(t,t+"/"+e.join("/")));d(u)}}):(a=a||t,Nc(t,e,n,i,o,a,d))},P_=t=>{let e=!1,n;try{e=ot.statSync(t).isDirectory()}catch(i){n=i?.code}finally{if(!e)throw new Uf(t,n??"ENOTDIR")}},O_=(t,e)=>{t=ee(t);let n=e.umask??18,i=e.mode|448,o=(i&n)!==0,a=e.uid,d=e.gid,u=typeof a=="number"&&typeof d=="number"&&(a!==e.processUid||d!==e.processGid),f=e.preserve,x=e.unlink,g=ee(e.cwd),w=b=>{b&&u&&zf(b,a,d),o&&ot.chmodSync(t,i)};if(t===g)return P_(g),w();if(f)return w(ot.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=ee(co.relative(g,t)).split("/"),_;for(let b=S.shift(),I=g;b&&(I+="/"+b);b=S.shift()){I=ee(co.resolve(I));try{ot.mkdirSync(I,i),_=_||I}catch{let A=ot.lstatSync(I);if(A.isDirectory())continue;if(x){ot.unlinkSync(I),ot.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new go(I,I+"/"+S.join("/"))}}return w(_)},gc=Object.create(null),tf=1e4,Sr=new Set,L_=t=>{Sr.has(t)?Sr.delete(t):gc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Sr.add(t);let e=gc[t],n=Sr.size-tf;if(n>tf/10){for(let i of Sr)if(Sr.delete(i),delete gc[i],--n<=0)break}return e},N_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,M_=N_==="win32",B_=t=>t.split("/").slice(0,-1).reduce((e,n)=>{let i=e.at(-1);return i!==void 0&&(n=Gf(i,n)),e.push(n||"/"),e},[]),F_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=M_?["win32 parallelization disabled"]:t.map(i=>Ri(Gf(L_(i))));let n=new Set(t.map(i=>B_(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 a=o.at(-1);a instanceof Set?a.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 a of n){let d=this.#e.get(a);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(a);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let a of i){let d=this.#e.get(a),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(a);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(a=>this.#i(a)),!0}},z_=()=>process.umask(),nf=Symbol("onEntry"),Mc=Symbol("checkFs"),rf=Symbol("checkFs2"),Bc=Symbol("isReusable"),ft=Symbol("makeFs"),Fc=Symbol("file"),zc=Symbol("directory"),ro=Symbol("link"),sf=Symbol("symlink"),of=Symbol("hardlink"),Ci=Symbol("ensureNoSymlink"),af=Symbol("unsupported"),cf=Symbol("checkPath"),mc=Symbol("stripAbsolutePath"),In=Symbol("mkdir"),Ge=Symbol("onError"),Ks=Symbol("pending"),df=Symbol("pend"),Ir=Symbol("unpend"),wc=Symbol("ended"),_c=Symbol("maybeClose"),Uc=Symbol("skip"),Oi=Symbol("doChown"),Li=Symbol("uid"),Ni=Symbol("gid"),Mi=Symbol("checkedCwd"),U_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Bi=U_==="win32",q_=1024,G_=(t,e)=>{if(!Bi)return se.unlink(t,e);let n=t+".DELETE."+Df(16).toString("hex");se.rename(t,n,i=>{if(i)return e(i);se.unlink(n,e)})},H_=t=>{if(!Bi)return se.unlinkSync(t);let e=t+".DELETE."+Df(16).toString("hex");se.renameSync(t,e),se.unlinkSync(e)},lf=(t,e,n)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:n,Yc=class extends Fi{[wc]=!1;[Mi]=!1;[Ks]=0;reservations=new F_;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[wc]=!0,this[_c]()},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:q_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Bi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=ee(Ne.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:z_():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[nf](e))}warn(t,e,n={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(n.recoverable=!1),super.warn(t,e,n)}[_c](){this[wc]&&this[Ks]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[mc](t,e){let n=t[e],{type:i}=t;if(!n||this.preservePaths)return!0;let[o,a]=Kc(n),d=a.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Bi&&/^[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=Ne.posix.dirname(t.path),f=Ne.posix.normalize(Ne.posix.join(u,d.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:n}),!1}return o&&(t[e]=String(a),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:n})),!0}[cf](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[mc](t,"path")||!this[mc](t,"linkpath"))return!1;if(t.absolute=Ne.isAbsolute(t.path)?ee(Ne.resolve(t.path)):ee(Ne.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path: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}=Ne.win32.parse(String(t.absolute));t.absolute=i+Hu(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+Hu(t.path.slice(o.length))}return!0}[nf](t){if(!this[cf](t))return t.resume();switch(b_.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[Mc](t);default:return this[af](t)}}[Ge](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[Ir](),e.resume())}[In](t,e,n){R_(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)}[Oi](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}[Li](t){return lf(this.uid,t.uid,this.processUid)}[Ni](t){return lf(this.gid,t.gid,this.processGid)}[Fc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new lo(String(t.absolute),{flags:Bf(t.size),mode:n,autoClose:!1});i.on("error",u=>{i.fd&&se.close(i.fd,()=>{}),i.write=()=>!0,this[Ge](u,t),e()});let o=1,a=u=>{if(u){i.fd&&se.close(i.fd,()=>{}),this[Ge](u,t),e();return}--o===0&&i.fd!==void 0&&se.close(i.fd,f=>{f?this[Ge](f,t):this[Ir](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,g=t.mtime;se.futimes(f,x,g,w=>w?se.utimes(u,x,g,S=>a(S&&w)):a())}if(typeof f=="number"&&this[Oi](t)){o++;let x=this[Li](t),g=this[Ni](t);typeof x=="number"&&typeof g=="number"&&se.fchown(f,x,g,w=>w?se.chown(u,x,g,S=>a(S&&w)):a())}a()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[Ge](u,t),e()}),t.pipe(d)),d.pipe(i)}[zc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode;this[In](String(t.absolute),n,i=>{if(i){this[Ge](i,t),e();return}let o=1,a=()=>{--o===0&&(e(),this[Ir](),t.resume())};t.mtime&&!this.noMtime&&(o++,se.utimes(String(t.absolute),t.atime||new Date,t.mtime,a)),this[Oi](t)&&(o++,se.chown(String(t.absolute),Number(this[Li](t)),Number(this[Ni](t)),a)),a()})}[af](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[sf](t,e){let n=ee(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Ci](t,this.cwd,n,()=>this[ro](t,String(t.linkpath),"symlink",e),i=>{this[Ge](i,t),e()})}[of](t,e){let n=ee(Ne.resolve(this.cwd,String(t.linkpath))),i=ee(String(t.linkpath)).split("/");this[Ci](t,this.cwd,i,()=>this[ro](t,n,"link",e),o=>{this[Ge](o,t),e()})}[Ci](t,e,n,i,o){let a=n.shift();if(this.preservePaths||a===void 0)return i();let d=Ne.resolve(e,a);se.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new go(d,Ne.resolve(d,n.join("/"))));this[Ci](t,d,n,i,o)})}[df](){this[Ks]++}[Ir](){this[Ks]--,this[_c]()}[Uc](t){this[Ir](),t.resume()}[Bc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Bi}[Mc](t){this[df]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,n=>this[rf](t,n))}[rf](t,e){let n=d=>{e(d)},i=()=>{this[In](this.cwd,this.dmode,d=>{if(d){this[Ge](d,t),n();return}this[Mi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=ee(Ne.dirname(String(t.absolute)));if(d!==this.cwd)return this[In](d,this.dmode,u=>{if(u){this[Ge](u,t),n();return}a()})}a()},a=()=>{se.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Uc](t),n();return}if(d||this[Bc](t,u))return this[ft](null,t,n);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=g=>this[ft](g??null,t,n);return f?se.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return se.rmdir(String(t.absolute),f=>this[ft](f??null,t,n))}if(t.absolute===this.cwd)return this[ft](null,t,n);G_(String(t.absolute),f=>this[ft](f??null,t,n))})};this[Mi]?o():i()}[ft](t,e,n){if(t){this[Ge](t,e),n();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Fc](e,n);case"Link":return this[of](e,n);case"SymbolicLink":return this[sf](e,n);case"Directory":case"GNUDumpDir":return this[zc](e,n)}}[ro](t,e,n,i){se[n](e,String(t.absolute),o=>{o?this[Ge](o,t):(this[Ir](),t.resume()),i()})}},ki=t=>{try{return[null,t()]}catch(e){return[e,null]}},Hf=class extends Yc{sync=!0;[ft](t,e){return super[ft](t,e,()=>{})}[Mc](t){if(!this[Mi]){let o=this[In](this.cwd,this.dmode);if(o)return this[Ge](o,t);this[Mi]=!0}if(t.absolute!==this.cwd){let o=ee(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let a=this[In](o,this.dmode);if(a)return this[Ge](a,t)}}let[e,n]=ki(()=>se.lstatSync(String(t.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[Uc](t);if(e||this[Bc](t,n))return this[ft](null,t);if(n.isDirectory()){if(t.type==="Directory"){let a=this.chmod&&t.mode&&(n.mode&4095)!==t.mode,[d]=a?ki(()=>{se.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ft](d,t)}let[o]=ki(()=>se.rmdirSync(String(t.absolute)));this[ft](o,t)}let[i]=t.absolute===this.cwd?[]:ki(()=>H_(String(t.absolute)));this[ft](i,t)}[Fc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{se.closeSync(o)}catch(f){u=f}(d||u)&&this[Ge](d||u,t),e()},o;try{o=se.openSync(String(t.absolute),Bf(t.size),n)}catch(d){return i(d)}let a=this.transform&&this.transform(t)||t;a!==t&&(a.on("error",d=>this[Ge](d,t)),t.pipe(a)),a.on("data",d=>{try{se.writeSync(o,d,0,d.length)}catch(u){i(u)}}),a.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{se.futimesSync(o,u,f)}catch(x){try{se.utimesSync(String(t.absolute),u,f)}catch{d=x}}}if(this[Oi](t)){let u=this[Li](t),f=this[Ni](t);try{se.fchownSync(o,Number(u),Number(f))}catch(x){try{se.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||x}}}i(d)})}[zc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[In](String(t.absolute),n);if(i){this[Ge](i,t),e();return}if(t.mtime&&!this.noMtime)try{se.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Oi](t))try{se.chownSync(String(t.absolute),Number(this[Li](t)),Number(this[Ni](t)))}catch{}e(),t.resume()}[In](t,e){try{return O_(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}}[Ci](t,e,n,i,o){if(this.preservePaths||n.length===0)return i();let a=e;for(let d of n){a=Ne.resolve(a,d);let[u,f]=ki(()=>se.lstatSync(a));if(u)return i();if(f.isSymbolicLink())return o(new go(a,Ne.resolve(e,n.join("/"))))}i()}[ro](t,e,n,i){let o=`${n}Sync`;try{se[o](e,String(t.absolute)),i(),t.resume()}catch(a){return this[Ge](a,t)}}},j_=t=>{let e=new Hf(t),n=t.file,i=Cf.statSync(n),o=t.maxReadSize||16*1024*1024;new lw(n,{readSize:o,size:i.size}).pipe(e)},W_=(t,e)=>{let n=new Yc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((a,d)=>{n.on("error",d),n.on("close",a),Cf.stat(o,(u,f)=>{if(u)d(u);else{let x=new Gc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(n)}})})},jf=zi(j_,W_,t=>new Hf(t),t=>new Yc(t),(t,e)=>{e?.length&&bf(t,e)}),K_=(t,e)=>{let n=new Jc(t),i=!0,o,a;try{try{o=st.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=st.openSync(t.file,"w+");else throw f}let d=st.fstatSync(o),u=Buffer.alloc(512);e:for(a=0;a<d.size;a+=512){for(let g=0,w=0;g<512;g+=w){if(w=st.readSync(o,u,g,u.length-g,a+g),a===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let f=new Yn(u);if(!f.cksumValid)break;let x=512*Math.ceil((f.size||0)/512);if(a+x+512>d.size)break;a+=x,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,$_(t,n,a,o,e)}finally{if(i)try{st.closeSync(o)}catch{}}},$_=(t,e,n,i,o)=>{let a=new hf(t.file,{fd:i,start:n});e.pipe(a),J_(e,o)},V_=(t,e)=>{e=Array.from(e);let n=new xo(t),i=(o,a,d)=>{let u=(S,_)=>{S?st.close(o,b=>d(S)):d(null,_)},f=0;if(a===0)return u(null,0);let x=0,g=Buffer.alloc(512),w=(S,_)=>{if(S||_===void 0)return u(S);if(x+=_,x<512&&_)return st.read(o,g,x,g.length-x,f+x,w);if(f===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let b=new Yn(g);if(!b.cksumValid)return u(null,f);let I=512*Math.ceil((b.size??0)/512);if(f+I+512>a||(f+=I+512,f>=a))return u(null,f);t.mtimeCache&&b.mtime&&t.mtimeCache.set(String(b.path),b.mtime),x=0,st.read(o,g,0,512,f,w)};st.read(o,g,0,512,f,w)};return new Promise((o,a)=>{n.on("error",a);let d="r+",u=(f,x)=>{if(f&&f.code==="ENOENT"&&d==="r+")return d="w+",st.open(t.file,d,u);if(f||!x)return a(f);st.fstat(x,(g,w)=>{if(g)return st.close(x,()=>a(g));i(x,w.size,(S,_)=>{if(S)return a(S);let b=new lo(t.file,{fd:x,start:_});n.pipe(b),b.on("error",a),b.on("close",o),Y_(n,e)})})};st.open(t.file,d,u)})},J_=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Or({file:Wf.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},Y_=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Or({file:Wf.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n);t.end()},Ti=zi(K_,V_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!ww(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")}),CA=zi(Ti.syncFile,Ti.asyncFile,Ti.syncNoFile,Ti.asyncNoFile,(t,e=[])=>{Ti.validate?.(t,e),Z_(t)}),Z_=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))};xn();var ht={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 mo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Kf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function wo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function $f(t){let e=t?.requestScene?.trim();if(!(!e||e.length>64||!/^[A-Za-z0-9_.-]+$/.test(e)))return e}function Vf(t){let e=t?.permissionMode;if(typeof e!="string")return;let n=e.trim();return n===""?void 0:n}function Jf(t){let{_meta:e,...n}=t;return{stripped:n,meta:e}}function Xn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Zt();Ke();re();Te();Ke();function Lr(t,e){if(mo(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ui(t){return t.startsWith("http://")||t.startsWith("https://")}function Nr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as yk}from"node:fs";import{dirname as bk,join as vk}from"node:path";import{fileURLToPath as Ik}from"node:url";var Ot="0.2.7-alpha.12";Ke();re();var _o="1008033",Qf="1289";var e0="pbbp2",t0="https://www.coze.cn",n0="/api/coze_claw/resource/get_frontier_key",sy="https://www.coze.cn",oy="wss://frontier.coze.cn";function Mr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??sy}function r0(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??oy}function Tn(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 Gi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var qi=q("handshake");async function Zc(t){let e=Mr(t.endpoint),n=t.timeoutMs??1e4,i=`${Nr(e)}${n0}?aid=${encodeURIComponent(_o)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Tn(t.ppeOverride)},a=new AbortController,d=setTimeout(()=>a.abort(),n);qi.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:a.signal}),f=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let b=await u.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${b.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=${f}`);let w=g.data??{},S=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!S||!_){let b=JSON.stringify(g).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${b}`)}return qi.info("handshake ok",{remoteDeviceId:_,logid:f,traceId:x}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof k)throw qi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw qi.warn("handshake timeout",{base:e,timeoutMs:n}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${n}ms)`,{cause:u});let f=u.cause;throw qi.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new k("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var Xc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Lt="auto",yo=15e4;function s0(t){return{model:Qc(t.model)??Lt,...t.modelToken?{modelToken:t.modelToken}:{}}}function o0(t){return!t||t===Lt}var ay=new Set(["auto","\u81EA\u52A8"]);function Qc(t){let e=t?.trim();if(e)return ay.has(e.toLowerCase())?Lt:e}function a0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Xc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let n=t.model||Lt;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))}else o0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function c0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Lt}"`):o0(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Xc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let n=t.modelInfo?.contextWindow??yo;e.push("-c",`model_context_window=${n}`)}return e}function d0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function ed(t,e,n){let{ttEnv:i,usePpe:o}=Gi(t),a={};return i&&(a["x-tt-env"]=i),o&&(a["x-use-ppe"]=o),e&&(a["x-mock-scenario"]=e),n&&(a["x-coze-request-scene"]=n),a}function l0(t,e,n,i){if(!t.modelToken)return{};let o=ed(e,n,i);return Object.keys(o).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(o).map(([d,u])=>`${d}:${u}`).join(`
|
|
92
|
+
`)}}function td(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function nd(t){return t.model||Lt}function i0(t,e,n){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:n,maxTokens:8192,api:"openai-completions"}}function u0(t,e,n,i,o){if(!t.modelToken)return null;let a=nd(t),d=ed(e,n,o),u=["text"];t.modelInfo?.capabilities?.image===!0&&u.push("image");let f=[i0(a,u,t.modelInfo?.contextWindow??yo)],x=new Set([a]);for(let w of i??[])!w||x.has(w)||(x.add(w),f.push(i0(w,["text"],yo)));let g={baseUrl:`${Xc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:a,name:a,reasoning:!1,input:u,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??yo,maxTokens:32e3,api:"openai-completions"}]};return Object.keys(d).length>0&&(g.headers=d),g}function f0(t,e,n,i){if(!t.modelToken)return[];let o=ed(e,n,i),a=[];for(let[d,u]of Object.entries(o))a.push("-c",`model_providers.coze.http_headers.${d}="${u}"`);return a}var xe=q("agent-handlers"),h0=5*1024*1024,fy=1,hy=6,xy=new Set(["node_modules",".git",".coze","dist","build",".next"]),py=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,gy=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,my=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function wy(t){let e=t?.trim();return e?my.test(e)||gy.test(e)?e:(xe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function _y(t){return new Promise((e,n)=>{let i=rt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,a=d=>{o||(o=!0,d?n(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),a()}),i.once("error",d=>a(d))})}var bo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let n=Xn(e._meta),i=await this.loadAgentCfg(n),o=i?.workspace??$e(n).workspace,a=i?.skills??[],d=[],u=new Set;for(let f of a){let x=me(o,f.relPath,"SKILL.md");await g0(x).then(w=>w.isFile()).catch(()=>!1)&&(d.push(Iy(f)),u.add(f.relPath))}if(e.scanLocal){let f=i?.framework??"claude-code",x=await Ey(n,o,f),g=await by(n,f);for(let w of[...x,...g])u.has(w.relPath)||(u.add(w.relPath),d.push(w.skill))}return{skills:d}}async addSkills(e){e._meta;let n=Xn(e._meta),i=await this.requireAgentCfg(n),o=e.skills??[],a=[...i.skills??[]],d=new Map(a.map((f,x)=>[f.skillId,x])),u=[];for(let f of o){let x=await vo({agentId:n,workspace:i.workspace,framework:i.framework,skill:f});So(a,d,x),u.push(f)}return await hi(n,a),this.reloadAgentSessions(n,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let n=Xn(e._meta),i=await this.requireAgentCfg(n),o=new Set(e.skillIds??[]),a=i.skills??[],d=[];for(let u of a){if(!o.has(u.skillId)){d.push(u);continue}let f=me(i.workspace,u.relPath);await sd(f,{recursive:!0,force:!0}),xe.info("skill removed",{agentId:n,skillId:u.skillId,relPath:u.relPath})}return await hi(n,d),this.reloadAgentSessions(n,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let n=Xn(e._meta);if(!e.skillName)throw new k("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");xe.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??$e(n).workspace,a=i?.framework??"claude-code",d=e.isGlobal??!1,u=y0(e.skillName),f=await yy(o,a,u,d);if(!f){let P=d?"global":"workspace";throw new k("SKILL_NOT_FOUND",`skill not found in ${P}: ${e.skillName} (${u})`)}let{absDir:x,relPath:g}=f,w=me(x,"SKILL.md"),S=new ld.default;S.addLocalFolder(x,u);let _=S.toBuffer();if(_.length>x0)throw new k("SKILL_ZIP_TOO_LARGE",`skill zip ${_.length} bytes exceeds limit ${x0}`);let b=await Eo(w,{encoding:"utf8"}).then(P=>v0(P).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:_,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...b?{description:b}:{},agentId:n,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):xe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:n,skillName:e.skillName});let A=I.version??"v1.0",T=I.skillId??e.skillId??b0(n,g);if(i&&!d){let P=i.skills??[],y=P.find(D=>D.relPath===g);y?(y.version=A,y.skillId=T):P.push({skillId:T,skillName:e.skillName,relPath:g,version:A,installedAt:Date.now(),...b?{description:b}:{}}),await hi(n,P)}return xe.info("skill published",{agentId:n,skillName:e.skillName,relPath:g,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,a]of i.sessions){if(!a.downstream)continue;let d=a.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(a)){a.reloadAfterTurn=!0,xe.info("downstream busy, scheduling reload after turn",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=a.downstream;a.downstream=void 0,xe.info("killing downstream for workspace reload (idle)",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(n).catch(x=>xe.warn("downstream stop failed during reload (ignored)",{reason:n,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let n=this.opts.isRuntimePendingPermission;return!n||!e.downstream?!1:n(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return xe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let n=e.agentId,i=await Ce(n);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);if(i.cozeIdentity===e.cozeIdentity)return xe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:n}),{ok:!0};try{await mr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw xe.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 Fe(i),xe.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 Ce(n))throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);let o=["-y"];e.registry&&Ui(e.registry)&&o.push(`--registry=${e.registry}`);let a=wy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${a}`,"connect");let d=e._meta?.cozeEnv;d&&py.test(d)&&o.push("--env",d);let u=await _y(o);return xe.info("_agent/upgrade: spawned bridge upgrade process",{agentId:n,pid:u,targetVersion:a,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 Ce(n);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Fe(i),xe.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}):(xe.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",`${ht.DELETE}: missing agentId`);let i=await Ce(n),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,a=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(n,e.reason??"delete");let d=$e(n);return a==="cloud"?await sd(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Fe(i)),xe.info("agent deleted",{agentId:n,reason:e.reason??"",deployType:a,configFound:!!i}),{ok:!0}}async switchModel(e){if(Lr(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let n=Qc(e.model)??Lt,i=await Ce(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 Fe(i),xe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:n,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return xe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let a=o.model;o.model=n,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,a).catch(u=>xe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,f]of o.allSessionQueues())d.push(f.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${n}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(d),xe.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(Lr(e._meta,ht.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${ht.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ht.RESET),await this.runDetailSync(e.agentId,ht.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,n){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),xe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(n);for(let a of i.sessions.values())a.acpSessionId=void 0,a.replySeq=0,a.loadingSession=!1,a.spawnFailCount=void 0,a.spawnFailedAt=void 0;let o=new Map;for(let[a,d]of i.sessions)o.set(a,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await fi(e,o)}async clearPersistedAcpSessionIds(e){let n=await Ce(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 Fe(n)}async repairAgent(e){if(Lr(e._meta,ht.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${ht.REPAIR}: missing agentId`);let n=await this.loadAgentCfg(e.agentId);if(n&&n.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${ht.REPAIR} only allowed for openclaw, got ${n.framework}`);if(n&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,n.workspace)}catch(i){xe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ht.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,n,i){if(!this.opts.detailSyncer){xe.warn("detailSyncer not wired, skipping sync",{method:n,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){xe.warn("detail sync failed (ignored)",{method:n,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Lr(e._meta,"_agent/getFileTree");let n=e._meta,i=Xn(n),o=await this.resolveWorkspace(i),a=e.filePath??"",d=this.safeJoin(o,a),u=await rd(d).catch(()=>null);if(!u)throw new k("IPC_BAD_REQUEST",`path not found: ${a}`);if(u.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${a}`);if(!await ui(d,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${a}`);let f=By(e.depth);return u.isDirectory()?{tree:await My(o,d,a,f)}:{tree:[{name:Fy(a),path:k0(a||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Lr(e._meta,"_agent/getFileContent");let n=Xn(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),a=await rd(o).catch(()=>null);if(!a||!a.isFile())throw new k("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(a.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ui(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(a.size>h0)throw new k("IPC_BAD_REQUEST",`file too large: ${a.size} bytes (max ${h0})`);let d=await Eo(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:a.size}:{content:d.toString("utf8"),encoding:"utf-8",size:a.size}}async resolveWorkspace(e){let n=this.opts.agents.get(e);return n?n.workspace:(await Ce(e).catch(()=>null))?.workspace??$e(e).workspace}safeJoin(e,n){let i=ad(e,n||"."),o=dd(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${m0}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return i}loadAgentCfg(e){return Ce(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 y0(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 ud(t){return t==="claude-code"?me(".claude","skills"):me(".agents","skills")}function E0(t){let e=dy();return t==="claude-code"?[me(e,".claude","skills")]:t==="codex"?[me(e,".agents","skills"),me(e,".codex","skills")]:[me(e,".agents","skills"),me(e,".openclaw","skills")]}async function yy(t,e,n,i){let o=async a=>g0(me(a,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let a=me(ud(e),n),d=me(t,a);return await o(d)?{absDir:d,relPath:a}:null}for(let a of E0(e)){let d=me(a,n);if(await o(d))return{absDir:d,relPath:d}}return null}function b0(t,e){return(cy("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function v0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
93
|
+
---`,3);if(e<0)return{};let n=t.slice(3,e),i={};for(let o of n.split(`
|
|
94
|
+
`)){let a=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!a||!a[2])continue;let d=a[1],u=a[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function S0(t,e,n,i){let o=await p0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let a=[];for(let d of o){if(!d.isDirectory())continue;let u=d.name,f=me(n,u),x=me(e,u,"SKILL.md"),g=await Eo(x,{encoding:"utf8"}).catch(()=>null);if(g===null)continue;let w=v0(g);a.push({relPath:f,skill:{skillId:b0(t,f),skillName:w.name||u,...w.description?{description:w.description}:{},...i?{isGlobal:!0}:{}}})}return a}async function Ey(t,e,n){let i=ud(n);return S0(t,me(e,i),i,!1)}async function by(t,e){let n=[],i=new Set;for(let o of E0(e)){let a=await S0(t,o,o,!0);for(let d of a)i.has(d.relPath)||(i.add(d.relPath),n.push(d))}return n}var vy=3e4,Sy=50*1024*1024,x0=10*1024*1024,Br=3e4;async function vo(t){let{agentId:e,workspace:n,framework:i,skill:o}=t;if(!o.skillName)throw new k("IPC_BAD_REQUEST","skill missing skillName");let a=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!a&&!d)throw new k("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=y0(o.skillName),f=ud(i),x=me(f,u),g=me(n,x);if(await id(g,{recursive:!0}),a){let S=Buffer.from(o.content,"utf8");Hi(S.length),await od(me(g,"SKILL.md"),S,"utf8")}else{let S=await ky(o.downloadUrl);Cy(S)?await Oy(S,g):Dy(S)?await Ry(S,g):await od(me(g,"SKILL.md"),S.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return xe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:a?"content":"downloadUrl"}),w}function So(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 Iy(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 Ay(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function I0(t,e){let n=await Ce(t,e);if(!n)return{status:"skipped",count:0};if(n.disconnectedAt)return{status:"skipped",count:0};let i=Ot,o=n.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return n.skillsRefreshedForVersion=i,await Fe(n,e),{status:"seeded",count:0};let a=[...n.skills??[]],d=new Map(a.map((g,w)=>[g.skillId,w])),u=a.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return n.skillsRefreshedForVersion=i,await Fe(n,e),{status:"noop",count:0};let f=0,x=0;for(let g of u)try{await sd(me(n.workspace,g.relPath),{recursive:!0,force:!0});let w=await vo({agentId:t,workspace:n.workspace,framework:n.framework,skill:Ay(g)});So(a,d,w),f+=1}catch(w){x+=1,xe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(w)})}return n.skills=a,x===0&&(n.skillsRefreshedForVersion=i),await Fe(n,e),xe.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:f,failed:x}),{status:"refreshed",count:f}}async function ky(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Hi(e);let n=Ty(t);return Hi(n.length),n}if(t.startsWith("file:")){let e=new URL(t).pathname,n=await Eo(e);return Hi(n.length),n}if(Ui(t)){let e=new AbortController,n=setTimeout(()=>e.abort(),vy);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 Hi(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 Hi(t){if(t>Sy)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function Ty(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 Cy(t){return t.length>=2&&t[0]===31&&t[1]===139}function Dy(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 cd(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function Ry(t,e){let n,i;try{n=new ld.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||cd(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(x=>x===".."))throw new k("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=d.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new k("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=Py(i),a=ad(e);for(let d of i){if(cd(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=ad(e,u),x=dd(a,f);if(x.startsWith("..")||x==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await id(f,{recursive:!0});continue}await id(ly(f),{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 od(f,g)}}function Py(t){let e;for(let n of t){let i=n.entryName;if(!i||cd(i))continue;let o=i.indexOf("/");if(o<=0)return;let a=i.slice(0,o+1);if(e===void 0)e=a;else if(e!==a)return}return e}async function Oy(t,e){await Ly(t);let n=jf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Br}ms)`))},Br);try{await _0(w0.from(t),n)}catch(a){throw a instanceof k?a:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Br}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${a.message??String(a)}`,{cause:a})}finally{clearTimeout(o)}}async function Ly(t){let e=[],n=Or({onReadEntry:a=>{let d=a.path,u=a.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,n.destroy(new k("IPC_BAD_REQUEST",`tar list timeout (${Br}ms)`))},Br);try{await _0(w0.from(t),n)}catch(a){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Br}ms)`):new k("IPC_BAD_REQUEST",`tar list failed: ${a.message??String(a)}`,{cause:a})}finally{clearTimeout(o)}if(e.length>0)throw new k("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var Ny=5e3;async function My(t,e,n,i){return A0(t,e,n,i,{count:0})}async function A0(t,e,n,i,o){if(i<=0)return[];let a;try{a=await p0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of a){if(xy.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Ny){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=me(e,u.name),x=uy(me(n,u.name)),g=null;try{g=await rd(f)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let w={name:u.name,path:k0(dd(t,f)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(w.children=await A0(t,f,x,i-1,o)),d.push(w)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function By(t){return!t||t<=0?fy:Math.min(t,hy)}function Fy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function k0(t){return t.split(m0).join("/")}re();var Cn=q("agent-health-reporter"),zy=1e4,Uy=3,ji=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??zy,this.livenessFailureThreshold=e.livenessFailureThreshold??Uy}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()}),Cn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),Cn.info("heartbeat stopped"))}async tick(){if(this.inFlight){Cn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,Cn.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=qy(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),n.push(f)}if(n.length===0){this.consecutiveFailures=0;return}let i={agents:n,bridgeVersion:Ot,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,Cn.warn("heartbeat batch send failed",{count:n.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let a=o?.authFailures;if(a&&a.length>0&&(Cn.warn("heartbeat received authFailures from cloud",{count:a.length,agentIds:a.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(a)}catch(d){Cn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(n){Cn.warn("onTickEnd hook failed",{err:String(n)})}}};function qy(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}xn();import{mkdir as yd,rm as XE,stat as QE}from"node:fs/promises";import{homedir as eb}from"node:os";import{join as Ed}from"node:path";dn();import{existsSync as eE}from"node:fs";import{release as tE}from"node:os";import{basename as nE,isAbsolute as rE}from"node:path";function Wi(t,e,n){return n===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:n}}function Fr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function zr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Dn(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var Io=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 T0(t){return"method"in t&&"id"in t&&t.id!==void 0}function C0(t){return"method"in t&&!("id"in t)}function Ao(t){return!("method"in t)&&"id"in t}var Gy={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 Hy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ki(t.message)}:typeof t=="string"?Ki(t):typeof t=="object"?Wy(t):t}var jy=[[/\/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 Ki(t){let e=t;for(let[n,i]of jy)e=e.replace(n,i);return e}function Wy(t){let e={};for(let[n,i]of Object.entries(t))typeof i=="string"?e[n]=Ki(i):e[n]=i;return e}function $i(t){if(t instanceof k){let e=Hy(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:Gy[t.code]??X.INTERNAL_ERROR,message:Ki(t.message),data:n}}return{code:X.INTERNAL_ERROR,message:Ki(t instanceof Error?t.message:String(t))}}function D0(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,a=t.data;if(i&&e){let{message:d,...u}=e;a=u}return new k(n,o,{retriable:e?.retriable??!1,cause:a})}function P0(t){return`${JSON.stringify(t)}
|
|
95
|
+
`}var R0=10*1024*1024,ko=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>R0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${R0} bytes`)}),[]}let n=this.buffer.split(`
|
|
96
|
+
`);this.buffer=n.pop()??"";let i=[];for(let o of n){let a=o.replace(/\r$/,"").trim();if(a)try{i.push(JSON.parse(a))}catch(d){this.onError?.({line:a,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(n){return this.onError?.({line:e,error:n}),[]}}};var L0={"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"},lT=Object.fromEntries(Object.entries(L0).map(([t,e])=>[e,t])),Ky={"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:[]},Ur=class{seq=0;next(e,n){this.seq+=1;let i=L0[e]??$y(e),o=Ky[i]??[],a=[i,String(this.seq)];if(o.length>0){let d=o.map(f=>O0(n?.[f]??"")),u=Vy(d).join(":");u&&a.push(u)}else n&&Object.values(n).some(d=>d)&&a.push(Object.values(n).filter(Boolean).map(d=>O0(String(d))).join(":"));return a.join("_")}reset(){this.seq=0}};function $y(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function O0(t){return t.replace(/[:_\s]+/g,"-")}function Vy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}hn();import{readFileSync as Jy}from"node:fs";var Yy=384;async function fd(t,e=process.env){let n={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(n[i]=o);await fn(t.agentEnvFile,n,{mode:Yy})}function Vi(t){try{let e=JSON.parse(Jy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function To(t,e,n={},i=o=>o){return{...i({...t,...Vi(e)}),...n}}Zt();fr();Ke();re();Te();import{execFileSync as Zy,spawnSync as Xy}from"node:child_process";function Ji(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Yi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let n=["/PID",String(t),"/T"];e==="SIGKILL"&&n.push("/F"),Xy("taskkill",n,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var hd=new Set;function N0(t){typeof t=="number"&&t>0&&hd.add(t)}function M0(t){typeof t=="number"&&hd.delete(t)}function B0(){for(let t of hd)Yi(t,"SIGKILL")}var qr="coze-bridge-daemon";function F0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return Zy("pgrep",["-U",String(o),"-f",qr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),n;try{n=e()}catch{return[]}let i=process.pid;return n.split(`
|
|
97
|
+
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function z0(t,e){if(t.length===0)return;let n=e?.killFn??Yi,i=e?.isAliveFn??Ji,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),a=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)n(u,"SIGTERM");for(let u=0;u<a&&t.some(f=>i(f));u+=d)await o(Math.min(d,a-u));for(let u of t)i(u)&&n(u,"SIGKILL")}var Qy=[{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[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function U0(t,e){if(!e)return null;for(let n of Qy)if(!(n.frameworks&&!n.frameworks.includes(t))&&n.match.test(e))return{bridgeCode:n.bridgeCode,reason:n.reason,message:n.message};return null}function q0(t,e){return U0(t,e)}function G0(t,e){return U0(t,e)}function Gr(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 H0(t,e,n){let o=n-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,g=n-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Gr(g,t.firstFrameSeen,e)}}let a=n-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return a>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?a<e.phase2GateMs?{action:"continue",rearmMs:Gr(a,!0,e)}:n-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Gr(a,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&a>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Gr(a,!1,e)}}var j0=Ye("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),iE=200,sE=40,oE=Ye("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),aE=Ye("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),cE=Ye("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),dE=Ye("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),lE=Ye("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),uE=Ye("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),W0=500;function fE(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=W0?t:`${e.slice(0,W0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function hE(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 K0(t){try{return eE(t)}catch{return}}function xE(t,e){return{platform:process.platform,osRelease:tE(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:rE(e.command)?K0(e.command):void 0,cwd:e.cwd,cwdExists:K0(e.cwd),envKeys:e.envKeys}}function pE(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${nE(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Nt=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new ko({onError:n=>this.log.warn("decode line failed",{line:n.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Ur;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=To(process.env,this.opts.agentEnvFile??Z().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=rt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:n,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,N0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let a of this.decoder.push(o))this.dispatch(a)}catch(a){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(a)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let a=o.trimEnd();this.stderrRing.push(a),this.stderrRing.length>iE&&this.stderrRing.shift(),this.log.debug("stderr",{text:a})}),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,a)=>{this.stopped=!0,M0(i.pid),(o!==0||a!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:a,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,a));for(let u of this.exitHandlers)u(o,a)}),i.on("error",o=>{let a=o,d=xE(a,{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",pE(a,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(a=>n.once("exit",()=>a()));Yi(n.pid,"SIGTERM");let o=setTimeout(()=>{n.killed||Yi(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:lE,phase2GateMs:oE,livenessWindowMs:aE,absoluteMaxMs:cE,approvalMaxMs:uE,suspendThresholdMs:dE,...n};return this.call("session/prompt",e,j0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Fr("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(zr(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(Dn(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=j0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let a=this.idAllocator.next(e),d=Wi(a,e,n),u=(()=>{if(typeof n!="object"||n===null)return;let f=n.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,x)=>{let g={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Gr(0,!1,o),sessionId:u};g.promptTimeout=S;let _=()=>{let b={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=H0(b,S.cfg,I),T=P=>{S.armedAt=I,S.expectedIntervalMs=P,g.timer=setTimeout(_,P)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:a,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),T(A.rearmMs);return}if(A.action==="continue"){T(A.rearmMs);return}this.pending.delete(a),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:a,method:e,awaitingApproval:A.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(A.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new k("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:a,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(a),this.log.warn("downstream call timeout",{id:a,method:e,timeoutMs:i}),x(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(a,g);try{this.writeFrame(d)}catch(w){g.timer&&clearTimeout(g.timer),this.pending.delete(a),x(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(P0(e),n=>{n&&this.log.warn("stdin write callback err",{err:String(n)})})}dispatch(e){if(Ao(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:fE(e.result)}),n.resolve(e.result));return}if(C0(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(T0(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 a=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!a)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(a):u&&e.activeToolCalls.delete(a)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(Dn(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(Dn(e.id,$i(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let n=D0(e);if(n.code!=="AGENT_PROTOCOL_ERROR")return n;let i=G0(this.framework,hE(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(sE).join(`
|
|
98
|
+
`),o=q0(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 gE(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 Co=class extends Nt{framework="claude-code";constructor(e){let{command:n,args:i}=li("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 gE(e)}};dn();import{spawn as mE}from"node:child_process";import{closeSync as wE,existsSync as gd,mkdirSync as _E,mkdtempSync as yE,openSync as EE,readFileSync as Q0,readSync as bE,readdirSync as vE,rmSync as SE,statSync as IE}from"node:fs";import{homedir as AE,tmpdir as kE}from"node:os";import{join as Hr}from"node:path";var $0=["default","acceptEdits","plan","auto","bypassPermissions"],V0=["read-only","auto","full-access"];function Mt(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return $0.includes(e);case"codex":return V0.includes(e);case"openclaw":return!1}}function J0(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}function Y0(t){switch(t){case"read-only":return"read-only";case"agent":return"auto";case"agent-full-access":return"full-access";default:return}}function xd(t){switch(t){case"claude-code":return $0.join("/");case"codex":return V0.join("/");case"openclaw":return""}}Te();var md=9e4,TE=64*1024,CE=100;function DE(t){let e=typeof t=="number"?t:typeof t=="string"?Number.parseFloat(t):Number.NaN;return!Number.isFinite(e)||e<=0?md:Math.max(1,Math.floor(e*1e3))}function RE(t){let e=typeof t=="number"?t:typeof t=="string"?Number.parseFloat(t):Number.NaN;return!Number.isFinite(e)||e<=0?md:Math.max(1,Math.floor(e))}function PE(t){if(!t||typeof t!="object"||Array.isArray(t))return;let e={};for(let[n,i]of Object.entries(t))typeof i=="string"&&(e[n]=i);return Object.keys(e).length>0?e:void 0}function Z0(t){if(typeof t=="string"&&t.trim())return{command:t,timeoutMs:md};if(!t||typeof t!="object"||Array.isArray(t))return;let e=t;if(e.type&&e.type!=="command")return;let n=typeof e.command=="string"?e.command.trim():"";if(!n)return;let i=typeof e.working_directory=="string"&&e.working_directory.trim()?e.working_directory.trim():typeof e.cwd=="string"&&e.cwd.trim()?e.cwd.trim():void 0,o=PE(e.env);return{command:n,timeoutMs:e.timeout_ms===void 0?DE(e.timeout):RE(e.timeout_ms),...i?{cwd:i}:{},...o?{env:o}:{}}}function pd(t){if(Array.isArray(t))return t.flatMap(i=>pd(i));if(!t||typeof t!="object"){let i=Z0(t);return i?[i]:[]}let e=t;if(e.hooks)return pd(e.hooks);let n=Z0(e);return n?[n]:[]}function OE(t){let e=Hr(t,"hooks.json");if(!gd(e))return[];let n=JSON.parse(Q0(e,"utf8")),o=n.hooks&&typeof n.hooks=="object"?n.hooks:n;return pd(o.Stop??o.stop)}function LE(t,e){let n=Hr(t,"sessions");if(!gd(n))return;let i=[],o=a=>{let d;try{d=vE(a,{withFileTypes:!0})}catch{return}for(let u of d){let f=Hr(a,u.name);if(u.isDirectory())o(f);else if(u.isFile()&&u.name.endsWith(".jsonl"))try{i.push({path:f,mtimeMs:IE(f).mtimeMs})}catch{}}};o(n),i.sort((a,d)=>d.mtimeMs-a.mtimeMs);for(let a of i.slice(0,CE))if(NE(a.path,e))return a.path;return i[0]?.path}function NE(t,e){let n;try{n=EE(t,"r");let i=Buffer.alloc(TE),o=bE(n,i,0,i.length,0),a=i.subarray(0,o).toString("utf8");return a.includes(JSON.stringify(e))||a.includes(e)}catch{return!1}finally{if(n!==void 0)try{wE(n)}catch{}}}function ME(t){return Vi(t??Z().agentEnvFile)}function BE(t){let e=t.trim();if(e.length>=2){let n=e[0];if((n==='"'||n==="'")&&e.endsWith(n)){let i=e.slice(1,-1);return n==='"'?i.replace(/\\n/g,`
|
|
99
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):i.replace(/\\'/g,"'")}}return e.replace(/\s+#.*$/,"")}function FE(t){let e={};for(let n of t.split(/\r?\n/)){let i=n.trim();if(!i||i.startsWith("#"))continue;let o=i.startsWith("export ")?i.slice(7).trimStart():i,a=o.indexOf("=");if(a<=0)continue;let d=o.slice(0,a).trim();/^[A-Za-z_][A-Za-z0-9_]*$/.test(d)&&(e[d]=BE(o.slice(a+1)))}return e}function zE(t){let e=Hr(t,"cozeloop.env");return gd(e)?FE(Q0(e,"utf8")):{}}function X0(t){let e=t?.trim();return e||void 0}function UE(t){let e=ME(t.agentEnvFile),n=X0(t.env?.CODEX_HOME??e.CODEX_HOME??process.env.CODEX_HOME);if(n)return n;let i=X0(t.env?.HOME??e.HOME??process.env.HOME)??AE();return Hr(i,".codex")}var Do=class extends Nt{framework="codex";authMethodId;codexHomeDir;cleanupCodexHomeDir;constructor(e){let n=e.args??[],i=e.extraArgs?[...n,...e.extraArgs]:n,{command:o,args:a}=li("codex",e.command,i),d=e.isolateCodexHome?e.codexHomeDir??e.env?.CODEX_HOME??yE(Hr(kE(),"coze-bridge-codex-home-")):UE(e),u=!!e.isolateCodexHome&&!!d&&!e.codexHomeDir&&e.env?.CODEX_HOME!==d;e.isolateCodexHome&&d&&!u&&_E(d,{recursive:!0});let f=e.isolateCodexHome&&d?{...e.env??{},CODEX_HOME:d}:e.env,x={command:o,args:a,cwd:e.cwd,agentId:e.agentId,...e.agentEnvFile?{agentEnvFile:e.agentEnvFile}:{},...f?{env:f}:{}};super(x),this.authMethodId=e.authMethodId,this.codexHomeDir=d,this.cleanupCodexHomeDir=u}async initialize(e){let n=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),n}async sessionPrompt(e){let n=await super.sessionPrompt(e);return this.runStopHooksBestEffort(e.sessionId).catch(i=>{this.log.warn("codex stop hook unexpected failure",{err:String(i)})}),n}setSessionMode(e){let n=Mt("codex",e.modeId)?J0(e.modeId):e.modeId;return super.setSessionMode({...e,modeId:n})}onUpdate(e){super.onUpdate(n=>e(qE(n)))}async runStopHooksBestEffort(e){let n=this.codexHomeDir??this.opts.env?.CODEX_HOME;if(!n)return;let i;try{i=OE(n)}catch(d){this.log.warn("codex stop hook load failed",{codexHomeDir:n,err:String(d)});return}if(i.length===0)return;let o=LE(n,e),a=JSON.stringify({hook_event_name:"Stop",session_id:e,...o?{transcript_path:o}:{},trigger:"coze-bridge"});await Promise.all(i.map(async d=>{try{await this.runHookCommand(d,a)}catch(u){this.log.warn("codex stop hook failed",{codexHomeDir:n,command:d.command.slice(0,200),err:String(u)})}}))}runHookCommand(e,n){return new Promise((i,o)=>{let a=this.codexHomeDir??this.opts.env?.CODEX_HOME,d=a?zE(a):{},u=mE(e.command,{cwd:e.cwd??this.opts.cwd,env:To(process.env,this.opts.agentEnvFile??Z().agentEnvFile,{...this.opts.env??{},...d,...e.env??{}}),shell:!0,stdio:["pipe","ignore","pipe"]}),f="",x=setTimeout(()=>{u.kill("SIGTERM"),o(new Error(`hook timed out after ${e.timeoutMs}ms`))},e.timeoutMs);u.stderr?.setEncoding("utf8"),u.stderr?.on("data",g=>{f+=g,f.length>4e3&&(f=f.slice(-4e3))}),u.on("error",g=>{clearTimeout(x),o(g)}),u.on("close",(g,w)=>{if(clearTimeout(x),g===0){i();return}o(new Error(`hook exited code=${g} signal=${w} stderr=${f.slice(-1e3)}`))}),u.stdin.end(`${n}
|
|
100
|
+
`)})}async stop(e){if(await super.stop(e),this.codexHomeDir&&this.cleanupCodexHomeDir)try{SE(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};function qE(t){let e=t.update;if(e.sessionUpdate!=="current_mode_update"||typeof e.currentModeId!="string")return t;let n=Y0(e.currentModeId);return!n||n===e.currentModeId?t:{...t,update:{...t.update,currentModeId:n}}}Ke();var GE=3e4,jr=class extends Nt{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}`}]},GE))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};hn();Ke();re();Te();function wd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}dn();var Rn=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 Ro=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 Rn,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)Wr(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 Wr(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Xt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Zt();re();import{constants as eh}from"node:fs";import{access as HE}from"node:fs/promises";import{delimiter as jE,join as WE}from"node:path";var St=q("framework-detector"),th={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},KE=[".exe",".cmd",".bat",".ps1"],Qn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??rt,access:e.access??HE}}async detect(e){let n=th[e],i=await this.which(n);if(!i)return St.debug("framework binary not found",{framework:e,bin:n}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[a,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:a};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(th).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(jE).filter(Boolean),i=this.env.platform==="win32"?["",...KE]:[""];for(let o of n)for(let a of i){let d=WE(o,e+a);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let n=this.env.platform==="win32"?eh.F_OK:eh.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 St.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(n.code!==0)return St.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 St.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 St.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let a=o.find(d=>d?.isDefault===!0);return a?!a.id||!a.workspace?(St.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!a.id,hasWorkspace:!!a.workspace}),null):{id:a.id,workspace:a.workspace}:(St.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return St.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let n=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!n)return St.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=n.code===0;i||St.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)});let o={reachable:i},a=n.stdout.match(/\{[\s\S]*\}/);if(a)try{let d=JSON.parse(a[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){St.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&&(VE(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,n){return new Promise(i=>{let o="",a=!1,d,u=f=>{a||(a=!0,d&&clearTimeout(d),i(f))};try{let f=this.env.spawn(e,n,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",x=>{o+=x.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},$E=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function VE(t){return t.replace($E,"")}import{homedir as rh}from"node:os";import{join as Oo}from"node:path";hn();Zt();fr();Ke();re();async function ih(){let t=Oo(rh(),".openclaw/openclaw.json");return ln(t)}async function sh(){return(await ih())?.gateway?.auth?.token??""}var er=q("openclaw.config"),JE=[0,5e3,5e3],YE=Ye("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),nh="models.providers.",Po="agents.defaults.models",ZE=["operator.admin","operator.read","operator.write","operator.approvals","operator.pairing"];function _d(t,e){if(!Array.isArray(t))return!1;let n=new Set(t);return e.every(i=>n.has(i))}var Lo=class{command;env;retryDelaysMs;cliTimeoutMs;openclawDir;queue=new Rn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??JE,this.cliTimeoutMs=e.cliTimeoutMs??YE,this.openclawDir=e.openclawDir??Oo(rh(),".openclaw")}async withRetry(e,n){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let a=this.retryDelaysMs[o]??0;a>0&&await new Promise(d=>setTimeout(d,a));try{return await n()}catch(d){i=d,er.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=rt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),a="",d=!1,u=x=>{d||(d=!0,clearTimeout(f),x())};o.stderr?.on("data",x=>{a+=x.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?n():i(new Error(`exit ${x}: ${a.trim().slice(0,500)}`))}))})}async runCliTolerant(e,n){try{await this.runCli(e)}catch(i){let o=String(i);if(n.some(a=>o.includes(a)))return;throw i}}async bestEffortUnset(e,n){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",n])))}catch(i){er.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",`${nh}${e}`,JSON.stringify(n),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${nh}${e}`)}addModelToAllowlist(e,n){let i={[e]:n?{alias:n}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Po}[${e}]`,()=>this.runCli(["config","set",Po,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Po}[${e}]`,`${Po}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await ih())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,a=[];for(let d of Object.keys(i))d.startsWith(o)&&a.push(d.slice(o.length));return a}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"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}async ensureAcpDeviceScopes(){try{let e=Oo(this.openclawDir,"identity","device.json"),i=(await ln(e))?.deviceId?.trim();if(!i)return er.debug("openclaw device identity absent, skip acp scope ensure",{identityPath:e}),!1;let o=Oo(this.openclawDir,"devices","paired.json"),a=await ln(o),d=a?.[i];if(!a||!d)return er.debug("acp device not yet paired, skip scope ensure",{deviceId:i}),!1;let u=[...ZE],f=d.tokens?.operator;return _d(d.scopes,u)&&_d(d.approvedScopes,u)&&_d(f?.scopes,u)?(er.debug("acp device already has full operator scopes",{deviceId:i}),!1):(d.scopes=[...u],d.approvedScopes=[...u],f&&(f.scopes=[...u]),await fn(o,a,{mode:384}),er.info("acp device scopes upgraded to full operator set (bypass manual approval)",{deviceId:i,scopes:u}),!0)}catch(e){return er.warn("ensureAcpDeviceScopes failed (ignored, best-effort)",{err:String(e)}),!1}}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}};var le=q("agent-manager"),vd="acceptEdits",ch="full-access",dh="read-only";function tb(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var nb=(t,e,n,i,o,a,d,u,f,x,g,w)=>{switch(t){case"claude-code":{let S={...o?{...a0(o),...l0(o,d,u,w)}:{},...f??{},IS_SANDBOX:"1"};return new Co({cwd:n,env:S,agentId:i})}case"codex":{let S=o?[...c0(o),...f0(o,d,u,w)]:[],_=ch;x!==void 0&&(Mt("codex",x)?_=x:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let b=[...S,...tb(_)],I={...o?d0(o):{},...f??{}},A=!!o;return new Do({cwd:n,agentId:i,...b.length>0?{extraArgs:b}:{},...Object.keys(I).length>0?{env:I}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0,...g?{codexHomeDir:g}:{}}:{}})}case"openclaw":return new jr({command:e,cwd:n,agentId:i,...a?{sessionName:wd(a)}:{}})}};function bd(t){return t==="claude-code"||t==="codex"}function rb(t){let e=[],n=Object.keys(t).sort();for(let i of n){let o=t[i];o!==void 0&&(ib(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
101
101
|
`)}
|
|
102
|
-
`}function
|
|
103
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var rE={path:"",version:"cloud-deployed"},sh="openclaw_gateway_unavailable",iE="openclaw_default_agent_missing";function oh(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 sE={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},oE=6e4,No=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??eE,this.createTimeoutMs=e.createTimeoutMs??oE,this.detectorFactory=e.detectorFactory??(()=>new Xn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new Lo({command:r,openclawDir:this.openclawConfigDir})),this.openclawConfigDir=e.openclawConfigDir??bd(Xb(),".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=>{ue.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=bd(e,".env");if(await Yb(r).then(c=>c.isFile()).catch(()=>!1)){ue.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=tE({...process.env,...$i(this.paths.agentEnvFile)});await un(r,o,{mode:384}),ue.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),ue.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new 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=mo(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")ue.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(C=>ue.warn("dispose stale agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")ue.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(C=>ue.warn("dispose drifted agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){ue.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let C=await Pe(e.agentId,this.paths).catch(()=>null);C&&(C.patToken=e.patToken,await Ue(C,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){ue.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 Ue(C,this.paths))}return ue.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ve(e.agentId,this.paths),f=o?"cloud":"local",x=e.framework==="openclaw"&&f==="local",g;x&&!r?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let m=g??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??m??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&Ed(e.framework)&&await xr(e.framework,_.signal);let C=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await yd(u.root,{recursive:!0}),await yd(S,{recursive:!0}),await yd(u.logs,{recursive:!0}),C(),x||await pr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Ga(S,"cloud"):await Ga(S,"local",vd)),C();let O=i,b=i0({model:e.model??O?.model}),P=Wf(e._meta)??O?.accountId,L=e.patToken??O?.patToken,F=f==="cloud"?e.modelInfo??O?.modelInfo:void 0;if(I=new Po({agentId:e.agentId,framework:e.framework,workspace:S,model:b.model??Lt,deployType:f,...P?{accountId:P}:{},...L?{patToken:L}:{},...F?{modelInfo:F}:{}}),I.status="ok",O?.sessions){let V=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[X,se]of Object.entries(O.sessions)){let ae={acpSessionId:se.acpSessionId,modelToken:se.modelToken,tokenGeneratedAt:se.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?se.permissionMode===void 0?(ae.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",ue.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:X,framework:e.framework,fallback:ae.permissionMode})):Mt(e.framework,se.permissionMode)?ae.permissionMode=se.permissionMode:ue.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:X,framework:e.framework,value:se.permissionMode}):se.permissionMode!==void 0&&ue.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:X,framework:e.framework,deployType:f}),se.cozeGroupId&&(ae.cozeGroupId=se.cozeGroupId),I.sessions.set(X,ae)}let re=Object.keys(O.sessions).length;re>0&&ue.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:re})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:O?.createdAt??Date.now(),sessions:O?.sessions??{},model:b.model};f==="cloud"&&(M.deployType="cloud"),P&&(M.accountId=P),L&&(M.patToken=L),F&&(M.modelInfo=F),O?.skills&&(M.skills=O.skills),O?.agentName&&(M.agentName=O.agentName),O?.description&&(M.description=O.description),M.skillsRefreshedForVersion=O?.skillsRefreshedForVersion??Ot,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):ue.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let J=e.initialSkills??[];if(J.length>0){let V=[...M.skills??[]],re=new Map(V.map((ae,D)=>[ae.skillId,D])),X=await Promise.allSettled(J.map(ae=>vo({agentId:e.agentId,workspace:S,framework:e.framework,skill:ae}))),se=0;for(let[ae,D]of X.entries()){let U=J[ae];U&&(D.status==="fulfilled"?(So(V,re,D.value),se++):ue.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(D.reason)}))}se>0&&(M.skills=V,ue.info("initialSkills installed",{agentId:e.agentId,installed:se,requested:J.length}))}return await Ue(M,this.paths),ue.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(C){throw ue.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 Zb(u.root,{recursive:!0,force:!0}).catch(O=>ue.warn("rm agent dir failed (ignored)",{err:String(O)})),C instanceof k?C:new k("AGENT_SPAWN_FAILED",String(C),{cause:C})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c,d){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&Ed(e.framework))f=rE;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Ed(e.framework)&&!vs(e.framework)&&(ue.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await xr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,g;if(e.framework==="openclaw")g=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,bizFreeScene:d,command:f.path});else{let m=e.sessions.get(i),S=Yt(e)?m?.permissionMode??ah:"full-access";g=this.factory(e.framework,f.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),S,e.framework==="codex"&&e.deployType==="cloud"?bd(Ve(e.agentId,this.paths).root,"codex-home"):void 0,d)}try{return await g.start(),await g.initialize(sE),g}catch(m){let S=g instanceof Nt?g.getStderrTail():[];throw S.length>0&&ue.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof k?m.code:"unknown",recentStderr:S}),await g.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new k("AGENT_ENV_NOT_READY",oh(o),{cause:{reason:sh}})}catch(o){ue.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};ue.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return ue.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new 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:iE}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new k("AGENT_ENV_NOT_READY",oh(r),{cause:{reason:sh}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,bizFreeScene:u,command:f}=e,x=wd(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Gr({command:f,cwd:S.workspace,agentId:S.id,sessionName:x})}let g=await ih();try{await this.getOpenclawConfig().ensureAcpDeviceScopes()}catch(S){ue.warn("acp device scope ensure failed (ignored)",{err:String(S)})}let m;if(i?.modelToken){let S=td(o),_=nd(i),v=`${S}/${_}`;if(!this.ensuredProviders.has(v)){let I=this.getOpenclawConfig(),A=await I.getAllowlistModelsForProvider(S),C=l0(i,c,d,A,u);C&&(await I.ensureProvider(S,C),await I.addModelToAllowlist(v),this.ensuredProviders.add(v))}m=v}return new Gr({command:f,cwd:r.workspace,agentId:r.agentId,sessionName:x,...g?{gatewayToken:g}:{},...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=td(c),u=`${d}/${o}`,f=!0;try{await i.removeProvider(d)}catch(x){f=!1,ue.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){f=!1,ue.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}f&&this.ensuredProviders.delete(u)}}};import{randomUUID as hh}from"node:crypto";import{promises as hE}from"node:fs";import{basename as xh}from"node:path";$e();ne();import{promises as aE}from"node:fs";import{basename as cE}from"node:path";var dh=j("file-upload"),dE="/api/coze_claw/file/agent_upload",lE=6e4;async function lh(t,e={}){let i=`${Or(Lr(e.handshakeBase))}${dE}`,o=e.timeoutMs??lE,c=await aE.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",...Tn(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);dh.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),m=g.headers.get("x-tt-logid")??"";if(!g.ok){let v=await g.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${m}: ${v.slice(0,200)}`)}let S=await g.json();if(S.code!==void 0&&S.code!==0)throw new k("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${m}`);let _=S.data?.file?.file_url;if(!_)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${m}: ${JSON.stringify(S).slice(0,200)}`);return dh.info("file upload ok",{uri:_,logid:m}),{uri:_}}catch(g){throw g instanceof k?g:g.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${cE(t.path)}`):new k("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(x)}}$e();ne();import{extname as uE}from"node:path";var fE={".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 uh(t){let e=uE(t).toLowerCase();return fE[e]??"application/octet-stream"}Re();var Mo=j("agent-send"),fh=50*1024*1024;function ph(t,e,r){let i=t.get(e);if(!i)throw new k("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new k("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new k("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function gh(t,e,r,i,o,c){let u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,f<2&&(Mo.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(g=>setTimeout(g,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function mh(t,e){let{session:r,runtime:i}=ph(e.core,t.agentId,t.sessionId);if(!await li(t.path,r.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await hE.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>fh)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${fh}`);let c=await uh(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??xh(t.path),u;try{u=await lh({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 Mo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof k?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let f={sessionUpdate:"agent_file",messageId:hh(),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 gh(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Mo.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 wh(t,e){let{session:r,runtime:i}=ph(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??xh(t.path),c={sessionUpdate:"group_file",messageId:hh(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await gh(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),Mo.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 _h(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();Zt();ne();var Bt=j("coze-cli-installer"),yh="@coze/cli@latest",xE="coze",bh="0.1.8",pE=5e3,gE=5e3,mE=9e4,Eh=1e4,Yi=null,Bo=!1;async function Id(t,e={}){if(Bo)return;if(Yi)return Yi;let r=e.exec??Yf;return Yi=(async()=>{try{let i=await wE(xE,r),o=!1;if(i){let d=await _E(r);if(d===void 0)Bt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(_h(d,bh))Bt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:bh}),o=!0;else{Bt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),Bo=!0;return}}let c=o?"upgrade-only":"full";Bt.info("coze-cli install start",{package:yh,mode:c});try{await r("npm",["i","-g","--prefer-online",yh],{timeout:mE,maxBuffer:10*1024*1024}),Bt.info("coze-cli install ok")}catch(d){Bt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){Bo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:Eh}),Bt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Bt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:Eh}),Bt.info("coze auth login ok")}catch(d){Bt.warn("coze auth login failed",{err:String(d)});return}Bo=!0}finally{Yi=null}})(),Yi}async function wE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:pE});return Ua(i)}catch{return}}async function _E(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:gE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}hn();Re();var yE=10*6e4;function vh(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?yE:e}function Fo(t){return ln(t??Z().configFile)}function Xi(t,e){return fn(e??Z().configFile,t)}import{randomBytes as UE}from"node:crypto";lr();$e();ne();import{createReadStream as bE}from"node:fs";import{mkdir as EE,readFile as vE,realpath as SE,stat as IE,writeFile as AE}from"node:fs/promises";import{basename as kE,dirname as Ad,isAbsolute as TE,join as CE,relative as RE,resolve as Sh,sep as PE}from"node:path";import{createInterface as DE}from"node:readline";var Ah=j("fs-rpc"),Qi=Xe("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function kh(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Qi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Qi} bytes`);let i=await Ch(t.path,e);return await EE(Ad(i),{recursive:!0}),await AE(i,t.content,"utf8"),Ah.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Th(t,e){let r=await Ch(t.path,e),i=await IE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Qi&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Qi} bytes`);let c;if(o&&i.size>Qi)c=await OE(r,t.line??1,t.limit);else{let d=await vE(r,"utf8");if(o){let u=d.split(`
|
|
104
|
-
`),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;
|
|
105
|
-
`)}else
|
|
106
|
-
`)}async function Ch(t,e){if(typeof t!="string"||t.length===0)throw new k("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([Ih(Sh(e)),Ih(Sh(t))]),o=RE(r,i);if(LE(o,PE,TE(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function LE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function Ih(t){let e=[],r=t;for(;r!==Ad(r);)try{let i=await SE(r);return e.length?CE(i,...e.reverse()):i}catch{e.push(kE(r)),r=Ad(r)}return t}ne();var Rh=j("prompt-multimodal"),Ph=10*1024*1024,NE=15e3,ME=6;async function Dh(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 BE(d))}}let o=Array.from({length:Math.min(ME,t.length)},()=>i());return await Promise.all(o),e}function Oh(t){return t.some(e=>e.type==="image")}async function BE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!zi(e.uri))return t;try{let{buf:r,contentType:i}=await zE(e.uri),o=e.mimeType||FE(i)||"application/octet-stream";return Rh.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 Rh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function FE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function zE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),NE);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>Ph)throw new Error(`image too large: ${o.byteLength} bytes (max ${Ph})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}xn();$e();ne();var $=j("core"),HE=3e4,GE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,jE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",qE="\u5BA1\u6279\u5DF2\u8D85\u65F6",WE=3e4,zo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Fr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;bizFreeSceneBySession=new Map;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=vh(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}getBizFreeSceneForSession(e){return this.bizFreeSceneBySession.get(e)}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),$.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){$.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),$.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){$.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&$.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{$.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Zi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){$.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(Rn(o,{code:Y.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>$.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Y.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){$.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Y.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(Ao(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&&GE.test(i)?this.currentCozeEnv=i:i&&$.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});let o=e.params,c=Kf(o?._meta),d=o?.sessionId;c&&typeof d=="string"&&this.bizFreeSceneBySession.get(d)!==c&&(this.bizFreeSceneBySession.set(d,c),$.info("cached free_scene for session",{sessionId:d,bizFreeScene:c}));try{if(e.method.startsWith("_agent/")){let u=this.extensions[e.method];if(!u){r!==null?await this.sendError(r,Y.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):$.warn("drop notification: extension not registered",{method:e.method});return}let f=await u(e,this);r!==null&&await this.upstream.send(Br(r,f));return}if(e.method.startsWith("session/")){let u=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Br(r,u));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Br(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Y.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):$.warn("drop unknown notification",{method:e.method})}catch(u){$.error("handleFrame failed",{method:e.method,err:String(u)}),r!==null&&await this.upstream.send(Rn(r,Ki(u)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new k("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new k("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new k("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,g=wo(r._meta);return $.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,jE,x,g)}}let d=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,f}finally{$.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}=Vf(i);switch(r){case"session/new":{let c=KE();return $.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return $.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Yt(e)?$f(i._meta):void 0;if(u!==void 0&&!Mt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${xd(e.framework)}`);let f=await this.ensureRuntime(e,d);if(u!==void 0&&f.permissionMode===void 0&&(f.permissionMode=u,await this.persistSessionMapping(e)),f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&f.permissionMode!==void 0&&f.permissionMode!==u){let S=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(_){throw f.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(f.acpSessionId,x):e.activeTriggers.delete(f.acpSessionId);let g=wo(i._meta);if(g?e.activeGroupIds.set(f.acpSessionId,g):e.activeGroupIds.delete(f.acpSessionId),g&&f.cozeGroupId!==g&&(f.cozeGroupId=g,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Oh(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let m=await Dh(c.prompt);try{let S=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:m});return f.lastActiveAt=Date.now(),S}catch(S){if(S instanceof k&&S.code==="AGENT_APPROVAL_TIMEOUT"){let _=f.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),f.pendingPermission=void 0);let v=f.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=v?e.activeGroupIds.get(v):void 0;return $.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,qE,I,A)}throw S}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let S=f.downstream;S&&(f.downstream=void 0,$.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),S.stop("reload-after-turn").catch(_=>$.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let f=e.getSessionQueue(d);f.size>0&&($.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:f.size}),f.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,f=wo(i._meta);if(!d)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Yt(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(!Mt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${xd(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let g=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(m){throw x.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),m}else $.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: ${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 $.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};$.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,f=d.runtime.acpSessionId;u?.isAlive()&&f&&c.push({downstream:u,acpSessionId:f,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let f of o)f.runtime.permissionMode=f.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Yt(e)&&(c.permissionMode=e.framework==="claude-code"?vd:ch),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(xt.GEN_MODEL_TOKEN,i,WE);if(!o?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof k&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new k("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Zi(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 ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{let x=this.bizFreeSceneBySession.get(r);x&&$.info("spawn: injecting free_scene gateway header",{agentId:e.agentId,cloudId:r,bizFreeScene:x}),f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario,x)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&($.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),$.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){$.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let g=await f.sessionNew({cwd:e.workspace});i.acpSessionId=g.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await f.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw $.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),Yt(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){$.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(Zi(i),this.isRuntimeBusy(e,i)){$.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){$.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}$.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>$.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Mr("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(Mr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>$.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){$.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){$.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(JE(r)){$.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 g=d.currentModeId;Mt(e.framework,g)&&c.permissionMode!==g?(c.permissionMode=g,this.persistSessionMapping(e).catch(m=>$.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(m)}))):typeof g=="string"&&!Mt(e.framework,g)&&$.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:g})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Mr("session/update",{...r,sessionId:o,_meta:u})).catch(g=>$.warn("forward update failed",{agentId:e.agentId,err:String(g)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}$.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Y.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 kh(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await Th(c,o);r.respondAgentRequest(i.id,d)}}catch(o){$.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Ki(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,f=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};f&&(x.cozeTriggerMsgId=f);let g=u?e.activeGroupIds.get(u):void 0;g&&(x.cozeGroupId=g);let m=u?this.reverseSessionId(e,u):void 0,S=m?e.sessions.get(m):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...m?{sessionId:m}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:m}),$.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:m,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(qi(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),$.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:Y.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?($.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"&&$E(e.result,o),$.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new Io(e.error)):i.value.resolve(e.result);return}$.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),d=e.get(c);if(d)return $.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=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(qi(o,e,r)).catch(f=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(f)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Yt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ui(e.agentId,r,this.paths)}catch(r){$.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(Rn(e,{code:r,message:i,data:{bridgeVersion:Ot}}))}};function KE(){return UE(16).toString("hex")}function $E(t,e){if(!t||typeof t!="object"){$.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){$.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){$.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&$.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var VE=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function JE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let r=e.content;if(!r||typeof r!="object")return!1;let i=r;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return VE.some(c=>o.startsWith(c))}hn();ne();Re();import{randomBytes as ZE}from"node:crypto";import{createServer as YE}from"node:http";var XE=1e6,Lh=j("ipc"),Uo=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??Z()}async start(){this.token=ZE(32).toString("hex");let e=YE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),Lh.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 un(this.paths.portFile,String(this.port)),await un(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){es(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){es(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await QE(e)}catch(u){es(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);es(r,200,u??{ok:!0})}catch(u){Lh.error("IPC handler failed",{key:o,err:String(u)}),es(r,500,{error:u instanceof Error?u.message:String(u)})}}};function es(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function QE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>XE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var _S=jt(Rx(),1),yS=jt(Jo(),1),bS=jt(Wr(),1),ES=jt(Bd(),1),vS=jt(Ud(),1),SS=jt(Kd(),1),zx=jt(Qo(),1),IS=jt(Fx(),1);var Ux=zx.default;$e();ne();var{FWS:HS}=Yx(),Le=j("upstream.frontier"),Qx="application/json",ep="none",GS=15e3;function jS(t){class e extends Ux{constructor(i){super(i,Qf,{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(Ml("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let 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 ds=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:e0,...Tn(this.opts.ppeOverride)},r=jS(e),i=n0(this.opts.urlOverride),o={url:i,ws:r,fpID:Xf,aID:_o,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Qx,force:!0},payloadEncoding:{encoding:ep,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new HS(o),d=!1,u=null,f,x,g=new Promise((_,v)=>{f=_,x=v}),m=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?x(_):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Le.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&m();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(I=>Le.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,Le.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{Le.warn("frontier error",{code:_.code,msg:_.message}),m(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??GS;u=setTimeout(()=>{m(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await g}catch(_){try{c.close(1e3,"open failed")}catch(v){Le.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){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 k("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 k("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;tp(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:Qx,payloadEncoding:ep})}catch(u){throw Le.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new k("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Le.debug("drop non-adapter frontier frame",{service:r});return}let i=KS(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;tp(c)||Le.info("frontier frame in",{logid:WS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:qS(i)}),Promise.resolve(this.handler(o)).catch(d=>Le.warn("frontier frame handler threw",{err:String(d)}))}};function tp(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var np=2e3;function qS(t){return t.length<=np?t:`${t.slice(0,np)}...<truncated, total ${t.length} chars>`}function WS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function KS(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}}$e();ne();var Zd=j("skill-publish"),$S="/api/marketplace/product/skill/publish_with_assets",VS=15e4;async function rp(t,e={}){let i=`${Or(Lr(e.handshakeBase))}${$S}`,o=e.timeoutMs??VS,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",...Tn(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,f=setTimeout(()=>u.abort(),o);Zd.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}),g=x.headers.get("x-tt-logid")??"";if(!x.ok){let _=await x.text().catch(()=>"");throw new k("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${g}: ${_.slice(0,200)}`)}let m=await x.json();if(Zd.info("skill publish response",{logid:g,httpStatus:x.status,code:m.code,msg:m.msg,dataSkillId:m.data?.skill_id??"",dataVersion:m.data?.version??""}),m.code!==void 0&&m.code!==0)throw new k("UPLOAD_FAILED",`skill publish code=${m.code} msg=${m.msg??"-"} logid=${g}`);let S={};return m.data?.skill_id!==void 0&&m.data.skill_id!==""&&(S.skillId=String(m.data.skill_id)),m.data?.version&&(S.version=m.data.version),Zd.info("skill publish ok",{logid:g,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof k?x:x.name==="AbortError"?new k("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new k("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(f)}}ne();var Yd=j("upstream.switchable"),ca=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Yd.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 Yd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Yd.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 Xd=j("upstream"),Yr=class{handler=null;async start(){Xd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Xd.info("NoopUpstream stopped",{reason:e})}async send(e){Xd.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();ne();hn();ne();Re();import{promises as JS}from"node:fs";var ip=j("pat-token-store");async function da(t=Z()){try{let r=(await JS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(ip.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"&&ip.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function ls(t,e=Z()){if(!t)throw new Error("writePatToken: empty patToken");await un(e.patTokenFile,t,{mode:384})}Re();Re();import{promises as la}from"node:fs";import{join as ZS}from"node:path";function YS(t,e){return`#!/bin/sh
|
|
102
|
+
`}function ib(t){if(t.includes(`
|
|
103
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var sb={path:"",version:"cloud-deployed"},oh="openclaw_gateway_unavailable",ob="openclaw_default_agent_missing";function ah(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 ab={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},cb=6e4,No=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??nb,this.createTimeoutMs=e.createTimeoutMs??cb,this.detectorFactory=e.detectorFactory??(()=>new Qn),this.openclawConfigFactory=e.openclawConfigFactory??(n=>new Lo({command:n,openclawDir:this.openclawConfigDir})),this.openclawConfigDir=e.openclawConfigDir??Ed(eb(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,n=Ed(e,".env");if(await QE(n).then(a=>a.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:n});return}let o=rb({...process.env,...Vi(this.paths.agentEnvFile)});await un(n,o,{mode:384}),le.info("openclaw .env bootstrapped",{envFile:n,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.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 Ce(e.agentId,this.paths).catch(()=>null),o=mo(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let a=this.registry.get(e.agentId);if(a){if(a.framework!==e.framework)throw new k("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${a.framework})`);if(a.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await a.dispose("rebuild after error").catch(T=>le.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&a.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await a.dispose("rebuild after deployType drift").catch(T=>le.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==a.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),a.setPatToken(e.patToken);let T=await Ce(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Fe(T,this.paths))}if(a.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),a.setModelInfo(e.modelInfo);let T=await Ce(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Fe(T,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:a.agentId,workspace:a.workspace,framework:a.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=$e(e.agentId,this.paths),f=o?"cloud":"local",x=e.framework==="openclaw"&&f==="local",g;x&&!n?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=g??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,_=new AbortController,b=setTimeout(()=>_.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&bd(e.framework)&&await gr(e.framework,_.signal);let T=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await yd(u.root,{recursive:!0}),await yd(S,{recursive:!0}),await yd(u.logs,{recursive:!0}),T(),x||await mr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Ga(S,"cloud"):await Ga(S,"local",vd)),T();let P=i,y=s0({model:e.model??P?.model}),D=Kf(e._meta)??P?.accountId,L=e.patToken??P?.patToken,B=f==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(I=new Ro({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??Lt,deployType:f,...D?{accountId:D}:{},...L?{patToken:L}:{},...B?{modelInfo:B}:{}}),I.status="ok",P?.sessions){let J=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Q,te]of Object.entries(P.sessions)){let oe={acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};J?te.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Q,framework:e.framework,fallback:oe.permissionMode})):Mt(e.framework,te.permissionMode)?oe.permissionMode=te.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Q,framework:e.framework,value:te.permissionMode}):te.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Q,framework:e.framework,deployType:f}),te.cozeGroupId&&(oe.cozeGroupId=te.cozeGroupId),te.tokenGroupId&&(oe.tokenGroupId=te.tokenGroupId),te.requestScene&&(oe.requestScene=te.requestScene),I.sessions.set(Q,oe)}let ie=Object.keys(P.sessions).length;ie>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ie})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:y.model};f==="cloud"&&(M.deployType="cloud"),D&&(M.accountId=D),L&&(M.patToken=L),B&&(M.modelInfo=B),P?.skills&&(M.skills=P.skills),P?.agentName&&(M.agentName=P.agentName),P?.description&&(M.description=P.description),M.skillsRefreshedForVersion=P?.skillsRefreshedForVersion??Ot,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Y=e.initialSkills??[];if(Y.length>0){let J=[...M.skills??[]],ie=new Map(J.map((oe,R)=>[oe.skillId,R])),Q=await Promise.allSettled(Y.map(oe=>vo({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),te=0;for(let[oe,R]of Q.entries()){let U=Y[oe];U&&(R.status==="fulfilled"?(So(J,ie,R.value),te++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(R.reason)}))}te>0&&(M.skills=J,le.info("initialSkills installed",{agentId:e.agentId,installed:te,requested:Y.length}))}return await Fe(M,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(T){throw le.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 XE(u.root,{recursive:!0,force:!0}).catch(P=>le.warn("rm agent dir failed (ignored)",{err:String(P)})),T instanceof k?T:new k("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(b)}}async spawnSessionDownstream(e,n,i,o,a,d){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&bd(e.framework))f=sb;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);bd(e.framework)&&!vs(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await gr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:n,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,g;if(e.framework==="openclaw")g=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:a,requestScene:d,command:f.path});else{let w=e.sessions.get(i),S=Xt(e)?w?.permissionMode??ch:"full-access";g=this.factory(e.framework,f.path,e.workspace,e.agentId,x,i,o,a,this.buildBinShimPathEnv(),S,e.framework==="codex"&&e.deployType==="cloud"?Ed($e(e.agentId,this.paths).root,"codex-home"):void 0,d)}try{return await g.start(),await g.initialize(ab),g}catch(w){let S=g instanceof Nt?g.getStderrTail():[];throw S.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof k?w.code:"unknown",recentStderr:S}),await g.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,w)}}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",ah(o),{cause:{reason:oh}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof k?i:new k("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let n=await this.detectorFactory().detect("openclaw");if(n?.defaultAgent?.id&&n.defaultAgent.workspace)return le.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:ob}})}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",ah(n),{cause:{reason:oh}})}async buildOpenclawDownstream(e){let{session:n,modelConfig:i,cloudSessionId:o,cozeEnv:a,mockScenario:d,requestScene:u,command:f}=e,x=wd(o);if(n.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new jr({command:f,cwd:S.workspace,agentId:S.id,sessionName:x})}let g=await sh();try{await this.getOpenclawConfig().ensureAcpDeviceScopes()}catch(S){le.warn("acp device scope ensure failed (ignored)",{err:String(S)})}let w;if(i?.modelToken){let S=td(o),_=nd(i),b=`${S}/${_}`;if(!this.ensuredProviders.has(b)){let I=this.getOpenclawConfig(),A=await I.getAllowlistModelsForProvider(S),T=u0(i,a,d,A,u);T&&(await I.ensureProvider(S,T),await I.addModelToAllowlist(b),this.ensuredProviders.add(b))}w=b}return new jr({command:f,cwd:n.workspace,agentId:n.agentId,sessionName:x,...g?{gatewayToken:g}:{},...w?{slashModelOnStart:w}:{}})}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 a of e.sessions.keys()){let d=td(a),u=`${d}/${o}`,f=!0;try{await i.removeProvider(d)}catch(x){f=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){f=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}f&&this.ensuredProviders.delete(u)}}};import{randomUUID as xh}from"node:crypto";import{promises as pb}from"node:fs";import{basename as ph}from"node:path";Ke();re();import{promises as db}from"node:fs";import{basename as lb}from"node:path";var lh=q("file-upload"),ub="/api/coze_claw/file/agent_upload",fb=6e4;async function uh(t,e={}){let i=`${Nr(Mr(e.handshakeBase))}${ub}`,o=e.timeoutMs??fb,a=await db.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([a],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Tn(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);lh.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),w=g.headers.get("x-tt-logid")??"";if(!g.ok){let b=await g.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${w}: ${b.slice(0,200)}`)}let S=await g.json();if(S.code!==void 0&&S.code!==0)throw new k("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let _=S.data?.file?.file_url;if(!_)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return lh.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 ${lb(t.path)}`):new k("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(x)}}Ke();re();import{extname as hb}from"node:path";var xb={".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 fh(t){let e=hb(t).toLowerCase();return xb[e]??"application/octet-stream"}Te();var Mo=q("agent-send"),hh=50*1024*1024;function gh(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 mh(t,e,n,i,o,a){let u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,n,i,o);return}catch(x){u=x,f<2&&(Mo.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(g=>setTimeout(g,5e3)))}throw new k("UPSTREAM_NOT_READY",`${a} after 3 attempts: ${String(u)}`,{cause:u})}async function wh(t,e){let{session:n,runtime:i}=gh(e.core,t.agentId,t.sessionId);if(!await ui(t.path,n.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${n.workspace}`);let o=await pb.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>hh)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${hh}`);let a=await fh(t.path);if(t.kind==="image"&&!a.startsWith("image/"))throw new k("UNSUPPORTED_MIME",`kind=image but mime=${a}`);if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??ph(t.path),u;try{u=await uh({patToken:n.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:a,name:d,sizeBytes:o.size,...n.accountId?{accountId:n.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw Mo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:a,code:x instanceof k?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let f={sessionUpdate:"agent_file",messageId:xh(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:a,name:d,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await mh(e,n,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Mo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:a,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:a,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function _h(t,e){let{session:n,runtime:i}=gh(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??ph(t.path),a={sessionUpdate:"group_file",messageId:xh(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await mh(e,n,i,t.sessionId,a,"agent group file sendAgentFileUpdate failed"),Mo.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 yh(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(n.length,i.length);for(let a=0;a<o;a++){let d=n[a]??0,u=i[a]??0;if(d<u)return!0;if(d>u)return!1}return!1}dn();Zt();re();var Bt=q("coze-cli-installer"),Eh="@coze/cli@latest",gb="coze",bh="0.1.8",mb=5e3,wb=5e3,_b=9e4,vh=1e4,Zi=null,Bo=!1;async function Id(t,e={}){if(Bo)return;if(Zi)return Zi;let n=e.exec??Xf;return Zi=(async()=>{try{let i=await yb(gb,n),o=!1;if(i){let d=await Eb(n);if(d===void 0)Bt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(yh(d,bh))Bt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:bh}),o=!0;else{Bt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),Bo=!0;return}}let a=o?"upgrade-only":"full";Bt.info("coze-cli install start",{package:Eh,mode:a});try{await n("npm",["i","-g","--prefer-online",Eh],{timeout:_b,maxBuffer:10*1024*1024}),Bt.info("coze-cli install ok")}catch(d){Bt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){Bo=!0;return}if(t.env)try{await n("coze",["config","set","xTTEnv",t.env],{timeout:vh}),Bt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Bt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await n("coze",["auth","login","--token",t.patToken],{timeout:vh}),Bt.info("coze auth login ok")}catch(d){Bt.warn("coze auth login failed",{err:String(d)});return}Bo=!0}finally{Zi=null}})(),Zi}async function yb(t,e){let n=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(n,[t],{timeout:mb});return Ua(i)}catch{return}}async function Eb(t){try{let{stdout:e,stderr:n}=await t("coze",["--version"],{timeout:wb});return(e||n).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}hn();Te();var bb=10*6e4;function Sh(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?bb:e}function Fo(t){return ln(t??Z().configFile)}function Xi(t,e){return fn(e??Z().configFile,t)}import{randomBytes as Gb}from"node:crypto";fr();Ke();re();import{createReadStream as vb}from"node:fs";import{mkdir as Sb,readFile as Ib,realpath as Ab,stat as kb,writeFile as Tb}from"node:fs/promises";import{basename as Cb,dirname as Ad,isAbsolute as Db,join as Rb,relative as Pb,resolve as Ih,sep as Ob}from"node:path";import{createInterface as Lb}from"node:readline";var kh=q("fs-rpc"),Qi=Ye("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Th(t,e){let n=Buffer.byteLength(t.content,"utf8");if(n>Qi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${n} bytes > limit ${Qi} bytes`);let i=await Dh(t.path,e);return await Sb(Ad(i),{recursive:!0}),await Tb(i,t.content,"utf8"),kh.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Ch(t,e){let n=await Dh(t.path,e),i=await kb(n),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Qi&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Qi} bytes`);let a;if(o&&i.size>Qi)a=await Nb(n,t.line??1,t.limit);else{let d=await Ib(n,"utf8");if(o){let u=d.split(`
|
|
104
|
+
`),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;a=u.slice(f,x).join(`
|
|
105
|
+
`)}else a=d}return kh.info("fs/read_text_file ok",{path:n,size:a.length}),{content:a}}async function Nb(t,e,n){let i=Lb({input:vb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),a=typeof n=="number"?o+n:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let f of i)if(u>=o&&u<a&&d.push(f),u++,u>=a)break}finally{i.close()}return d.join(`
|
|
106
|
+
`)}async function Dh(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([Ah(Ih(e)),Ah(Ih(t))]),o=Pb(n,i);if(Mb(o,Ob,Db(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Mb(t,e,n){return t===""?!1:n?!0:t===".."||t.startsWith(`..${e}`)}async function Ah(t){let e=[],n=t;for(;n!==Ad(n);)try{let i=await Ab(n);return e.length?Rb(i,...e.reverse()):i}catch{e.push(Cb(n)),n=Ad(n)}return t}re();var Rh=q("prompt-multimodal"),Ph=10*1024*1024,Bb=15e3,Fb=6;async function Oh(t){let e=new Array(t.length),n=0;async function i(){for(;n<t.length;){let a=n++,d=t[a];d!==void 0&&(e[a]=await zb(d))}}let o=Array.from({length:Math.min(Fb,t.length)},()=>i());return await Promise.all(o),e}function Lh(t){return t.some(e=>e.type==="image")}async function zb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ui(e.uri))return t;try{let{buf:n,contentType:i}=await qb(e.uri),o=e.mimeType||Ub(i)||"application/octet-stream";return Rh.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 Rh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(n)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Ub(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function qb(t){let e=new AbortController,n=setTimeout(()=>e.abort(),Bb);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>Ph)throw new Error(`image too large: ${o.byteLength} bytes (max ${Ph})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(n)}}xn();Ke();re();var W=q("core"),Hb=3e4,jb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,Wb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",Kb="\u5BA1\u6279\u5DF2\u8D85\u65F6",$b=3e4,zo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Ur;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;requestSceneBySession=new Map;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=Sh(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}getRequestSceneForSession(e){return this.requestSceneBySession.get(e)}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),W.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){W.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(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),W.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let n of this.registerHandlers)try{n(e.agentId)}catch(i){W.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&W.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,n,i){let o=i.downstream;o&&(o.onUpdate(a=>{i.loadingSession||this.forwardUpdate(e,a)}),o.onAgentRequest(a=>{this.handleAgentRequest(e,o,a)}),o.onExit((a,d)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:n,code:a,signal:d}),Wr(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,a]of this.pendingUpstream)a.downstream===e&&i.push(o);if(i.length!==0){W.info("reject pendingUpstream entries (downstream gone)",{reason:n,count:i.length});for(let o of i){let a=this.pendingUpstream.get(o);if(a){this.pendingUpstream.delete(o),this.upstream.send(Dn(o,{code:X.INTERNAL_ERROR,message:`bridge downstream gone: ${n}`})).catch(d=>W.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{a.downstream.respondAgentRequestError(a.agentRequestId,{code:X.INTERNAL_ERROR,message:`bridge: ${n}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,n=this.pendingBridge.size;if(!(e===0&&n===0)){W.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(Ao(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&&jb.test(i)?this.currentCozeEnv=i:i&&W.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});let o=e.params,a=$f(o?._meta),d=o?.sessionId;if(e.method==="session/prompt"&&typeof d=="string"){let u=this.requestSceneBySession.get(d);a&&u!==a?(this.requestSceneBySession.set(d,a),W.info("cached request_scene for session",{sessionId:d,requestScene:a})):!a&&u!==void 0&&(this.requestSceneBySession.delete(d),W.info("cleared request_scene for session",{sessionId:d}))}try{if(e.method.startsWith("_agent/")){let u=this.extensions[e.method];if(!u){n!==null?await this.sendError(n,X.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):W.warn("drop notification: extension not registered",{method:e.method});return}let f=await u(e,this);n!==null&&await this.upstream.send(zr(n,f));return}if(e.method.startsWith("session/")){let u=await this.routeSessionMethod(e);n!==null&&await this.upstream.send(zr(n,u));return}if(e.method==="initialize"){n!==null&&await this.upstream.send(zr(n,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}n!==null?await this.sendError(n,X.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):W.warn("drop unknown notification",{method:e.method})}catch(u){W.error("handleFrame failed",{method:e.method,err:String(u)}),n!==null&&await this.upstream.send(Dn(n,$i(u)))}}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 a=typeof n.sessionId=="string"?n.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!a)return this.dispatchSessionCall(o,e.method,n);if(e.method==="session/prompt"){let f=o.sessions.get(a);if(f?.pendingPermission){let x=n._meta?.cozeTriggerMsgId,g=wo(n._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:a}),this.synthesizePromptReply(o,f,a,Wb,x,g)}}let d=Date.now(),u=!1;try{let f=await o.getSessionQueue(a).enqueue(()=>this.dispatchSessionCall(o,e.method,n));return u=!0,f}finally{W.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}=Jf(i);switch(n){case"session/new":{let a=Vb();return W.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:a}),{sessionId:a}}case"session/load":{let a=o;return W.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:a.sessionId}),{}}case"session/prompt":{let a=o,d=a.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Xt(e)?Vf(i._meta):void 0;if(u!==void 0&&!Mt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${xd(e.framework)}`);let f=wo(i._meta),x=this.requestSceneBySession.get(d),g=await this.ensureRuntime(e,d,f,x);if(u!==void 0&&g.permissionMode===void 0&&(g.permissionMode=u,await this.persistSessionMapping(e)),g.replySeq=0,await this.ensureDownstream(e,d,g),!g.downstream||!g.acpSessionId)throw new k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&g.permissionMode!==void 0&&g.permissionMode!==u){let _=g.permissionMode;g.permissionMode=u,await this.persistSessionMapping(e);try{await g.downstream.setSessionMode({sessionId:g.acpSessionId,modeId:u})}catch(b){throw g.permissionMode=_,await this.persistSessionMapping(e).catch(()=>{}),b}}let w=i._meta?.cozeTriggerMsgId;if(w?e.activeTriggers.set(g.acpSessionId,w):e.activeTriggers.delete(g.acpSessionId),f?e.activeGroupIds.set(g.acpSessionId,f):e.activeGroupIds.delete(g.acpSessionId),f&&g.cozeGroupId!==f&&(g.cozeGroupId=f,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Lh(a.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let S=await Oh(a.prompt);try{let _=await g.downstream.sessionPrompt({...a,sessionId:g.acpSessionId,prompt:S});return g.lastActiveAt=Date.now(),_}catch(_){if(_ instanceof k&&_.code==="AGENT_APPROVAL_TIMEOUT"){let b=g.pendingPermission;b&&(b.downstream.respondAgentRequest(b.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(b.upstreamId),g.pendingPermission=void 0);let I=g.acpSessionId,A=I?e.activeTriggers.get(I):void 0,T=I?e.activeGroupIds.get(I):void 0;return W.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,g,d,Kb,A,T)}throw _}finally{if(e.activeTriggers.delete(g.acpSessionId),e.activeGroupIds.delete(g.acpSessionId),g.pendingPermission=void 0,g.reloadAfterTurn){g.reloadAfterTurn=!1;let _=g.downstream;_&&(g.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:g.acpSessionId}),_.stop("reload-after-turn").catch(b=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(b)})))}else g.downstream?.isAlive()&&this.armIdleTimer(e,d,g)}}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 f=e.getSessionQueue(d);f.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:f.size}),f.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 a=o,d=a.sessionId,u=a.modeId,f=wo(i._meta);if(!d)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Xt(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(!Mt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${xd(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let g=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(w){throw x.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),w}else W.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 W.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i}),{};W.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 a=[];for(let d of o){let u=d.runtime.downstream,f=d.runtime.acpSessionId;u?.isAlive()&&f&&a.push({downstream:u,acpSessionId:f,oldMode:d.oldMode,runtime:d.runtime})}for(let d of a)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let f of o)f.runtime.permissionMode=f.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,n,i,o){let a=e.sessions.get(n);if(a){let f=e.deployType==="cloud"&&a.tokenGroupId!==i,x=a.requestScene!==o;if(f&&(a.modelToken=await this.requestSessionToken(e.agentId,n,i),a.tokenGeneratedAt=Date.now(),a.tokenGroupId=i),f||x){Wr(a);let g=a.downstream;a.downstream=void 0,g&&await g.stop("request-context-changed")}return a.cozeGroupId=i,a.requestScene=o,(f||x)&&await this.persistSessionMapping(e),a}let u={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,n,i):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0,...i?{cozeGroupId:i}:{},...i?{tokenGroupId:i}:{},...o?{requestScene:o}:{}};return Xt(e)&&(u.permissionMode=e.framework==="claude-code"?vd:dh),e.sessions.set(n,u),await this.persistSessionMapping(e),u}async requestSessionToken(e,n,i){let o={sessionId:n,_meta:{cozeAgentId:e,...i?{cozeGroupId:i}:{}}};try{let a=await this.sendRequest(ht.GEN_MODEL_TOKEN,o,$b);if(!a?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${n})`);return a.modelToken}catch(a){throw a instanceof k&&a.code==="MODEL_TOKEN_GEN_FAILED"?a:new k("MODEL_TOKEN_GEN_FAILED",a instanceof Error?a.message:String(a),{cause:a})}}async ensureDownstream(e,n,i){if(Wr(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,a=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<a)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((a-(Date.now()-u))/1e3)}s`);let f;try{let x=this.requestSceneBySession.get(n);x&&W.info("spawn: injecting request_scene gateway header",{agentId:e.agentId,cloudId:n,requestScene:x}),f=await this.sessionSpawner(e,i.modelToken,n,this.currentCozeEnv,this.currentMockScenario,x)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:n,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,n,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId})}catch(x){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let g=await f.sessionNew({cwd:e.workspace});i.acpSessionId=g.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await f.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw W.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),Xt(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){W.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:n,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,n,i){if(Wr(i),this.isRuntimeBusy(e,i)){W.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)){W.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:n}),this.armIdleTimer(e,n,i);return}W.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(a=>W.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:n,err:String(a)}))},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 a={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};if(n.acpSessionId){let d=e.activeTriggers.get(n.acpSessionId);d&&(a.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(n.acpSessionId);u&&(a.cozeGroupId=u)}await this.upstream.send(Fr("session/update",{sessionId:i,update:o,_meta:a}))}async synthesizePromptReply(e,n,i,o,a,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};return a&&(u.cozeTriggerMsgId=a),d&&(u.cozeGroupId=d),await this.upstream.send(Fr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>W.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,n){let i=n.sessionId,o=this.reverseSessionId(e,i);if(!o){W.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let a=e.sessions.get(o);if(!a){W.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(Zb(n)){W.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"&&Xt(e)){let g=d.currentModeId;Mt(e.framework,g)&&a.permissionMode!==g?(a.permissionMode=g,this.persistSessionMapping(e).catch(w=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof g=="string"&&!Mt(e.framework,g)&&W.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:++a.replySeq},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Fr("session/update",{...n,sessionId:o,_meta:u})).catch(g=>W.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}W.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 a=i.params??{},d=await Th(a,o);n.respondAgentRequest(i.id,d)}else{let a=i.params??{},d=await Ch(a,o);n.respondAgentRequest(i.id,d)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),n.respondAgentRequestError(i.id,$i(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"),a=i.params??{},u=a.sessionId,f=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};f&&(x.cozeTriggerMsgId=f);let g=u?e.activeGroupIds.get(u):void 0;g&&(x.cozeGroupId=g);let w=u?this.reverseSessionId(e,u):void 0,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:n,agentRequestId:i.id,upstreamId:o});let _={...a,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:n,method:i.method,cloudSessionId:w}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:a.toolCall?.toolCallId,options:a.options?.map(b=>({optionId:b.optionId,kind:b.kind,name:b.name}))}),this.upstream.send(Wi(o,"session/request_permission",_)).catch(b=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(b)}),n.respondAgentRequestError(i.id,{code:X.INTERNAL_ERROR,message:`upstream send failed: ${String(b)}`})})}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?(W.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&Jb(e.result,o),W.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new Io(e.error)):i.value.resolve(e.result);return}W.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 a=String(n),d=e.get(a);if(d)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:n,normalizedId:a}),{value:d,key:a}}}sendRequest(e,n,i=Hb){let o=this.upstreamIds.next(e);return new Promise((a,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:a,reject:d,timer:u}),this.upstream.send(Wi(o,e,n)).catch(f=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(f)})})}async persistSessionMapping(e){if(this.paths)try{let n=new Map;for(let[i,o]of e.sessions){let a={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(a.acpSessionId=o.acpSessionId),o.permissionMode&&Xt(e)&&(a.permissionMode=o.permissionMode),o.cozeGroupId&&(a.cozeGroupId=o.cozeGroupId),o.tokenGroupId&&(a.tokenGroupId=o.tokenGroupId),o.requestScene&&(a.requestScene=o.requestScene),n.set(i,a)}await fi(e.agentId,n,this.paths)}catch(n){W.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(Dn(e,{code:n,message:i,data:{bridgeVersion:Ot}}))}};function Vb(){return Gb(16).toString("hex")}function Jb(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let n=t;if("kind"in n&&!("outcome"in n)){W.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"){W.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let a=i.outcome;(typeof a!="string"||a!=="selected"&&a!=="cancelled")&&W.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:a,result:t})}var Yb=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function Zb(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{text:o}=i;return Yb.some(a=>o.startsWith(a))}hn();re();Te();import{randomBytes as Xb}from"node:crypto";import{createServer as Qb}from"node:http";var ev=1e6,Nh=q("ipc"),Uo=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??Z()}async start(){this.token=Xb(32).toString("hex");let e=Qb((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(),Nh.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 un(this.paths.portFile,String(this.port)),await un(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,n){if(e.headers.authorization!==`Bearer ${this.token}`){es(n,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,a=this.routes.get(o);if(!a){es(n,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await tv(e)}catch(u){es(n,400,{error:"invalid json",detail:String(u)});return}try{let u=await a.handler(d,e);es(n,200,u??{ok:!0})}catch(u){Nh.error("IPC handler failed",{key:o,err:String(u)}),es(n,500,{error:u instanceof Error?u.message:String(u)})}}};function es(t,e,n){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}async function tv(t){let e=[],n=0;for await(let o of t){let a=o;if(n+=a.length,n>ev)throw new Error("body too large");e.push(a)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var ES=jt(Rx(),1),bS=jt(Jo(),1),vS=jt(Vr(),1),SS=jt(Bd(),1),IS=jt(Ud(),1),AS=jt(Kd(),1),Ux=jt(Qo(),1),kS=jt(zx(),1);var qx=Ux.default;Ke();re();var{FWS:HS}=Xx(),Pe=q("upstream.frontier"),ep="application/json",tp="none",jS=15e3;function WS(t){class e extends qx{constructor(i){super(i,e0,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Pe.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(Bl("debug"))try{let a;typeof i=="string"?a=Buffer.from(i,"utf8"):i instanceof Buffer?a=i:i instanceof ArrayBuffer?a=new Uint8Array(i):ArrayBuffer.isView(i)?a=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):a=new Uint8Array(0);let d=Buffer.from(a.slice(0,128)).toString("hex");Pe.debug("WS raw frame out",{bytes:a.byteLength,headHex:d})}catch(a){Pe.warn("WS raw frame dump failed",{err:String(a)})}super.send(i,...o)}}return e}var ds=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){Pe.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:t0,...Tn(this.opts.ppeOverride)},n=WS(e),i=r0(this.opts.urlOverride),o={url:i,ws:n,fpID:Qf,aID:_o,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:ep,force:!0},payloadEncoding:{encoding:tp,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},a=new HS(o),d=!1,u=null,f,x,g=new Promise((_,b)=>{f=_,x=b}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?x(_):f())};a.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Pe.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let b of this.connectHandlers)Promise.resolve(b({initial:_})).catch(I=>Pe.warn("onConnect handler threw (ignored)",{err:String(I)}))},a.onclose=_=>{this.opened=!1,Pe.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},a.onerror=_=>{Pe.warn("frontier error",{code:_.code,msg:_.message}),w(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},a.onmessage=_=>this.handleMessage(_),this.fws=a;let S=this.opts.openTimeoutMs??jS;u=setTimeout(()=>{w(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await a.connect();try{await g}catch(_){try{a.close(1e3,"open failed")}catch(b){Pe.warn("fws close during start failure threw (ignored)",{err:String(b)})}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){Pe.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let n=this.fws,i=e.method;if(!n)throw Pe.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?(Pe.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),a=e;np(a)||Pe.info("frontier frame out",{method:a.method,jsonrpcId:a.id,size:o.length});try{await n.send(o,{service:33555712,method:1,payloadType:ep,payloadEncoding:tp})}catch(u){throw Pe.warn("frontier frame send failed",{method:a.method,jsonrpcId:a.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){Pe.debug("drop non-adapter frontier frame",{service:n});return}let i=VS(e);if(!i){Pe.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Pe.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Pe.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let a=o;np(a)||Pe.info("frontier frame in",{logid:$S(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:a.id,method:a.method,body:KS(i)}),Promise.resolve(this.handler(o)).catch(d=>Pe.warn("frontier frame handler threw",{err:String(d)}))}};function np(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var rp=2e3;function KS(t){return t.length<=rp?t:`${t.slice(0,rp)}...<truncated, total ${t.length} chars>`}function $S(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function VS(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}}Ke();re();var Yd=q("skill-publish"),JS="/api/marketplace/product/skill/publish_with_assets",YS=15e4;async function ip(t,e={}){let i=`${Nr(Mr(e.handshakeBase))}${JS}`,o=e.timeoutMs??YS,a=new FormData;a.append("skill_id",t.skillId??""),a.append("skill_name",t.skillName),a.append("skill_description",t.description??""),a.append("agent_id",t.agentId),a.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",...Tn(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,f=setTimeout(()=>u.abort(),o);Yd.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:a,signal:u.signal}),g=x.headers.get("x-tt-logid")??"";if(!x.ok){let _=await x.text().catch(()=>"");throw new k("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${g}: ${_.slice(0,200)}`)}let w=await x.json();if(Yd.info("skill publish response",{logid:g,httpStatus:x.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 S={};return w.data?.skill_id!==void 0&&w.data.skill_id!==""&&(S.skillId=String(w.data.skill_id)),w.data?.version&&(S.version=w.data.version),Yd.info("skill publish ok",{logid:g,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof k?x:x.name==="AbortError"?new k("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new k("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(f)}}re();var Zd=q("upstream.switchable"),ca=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,n){if(this.inner===e)return;Zd.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 Zd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(n??"swapped").catch(o=>Zd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};re();var Xd=q("upstream"),ei=class{handler=null;async start(){Xd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Xd.info("NoopUpstream stopped",{reason:e})}async send(e){Xd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();re();hn();re();Te();import{promises as ZS}from"node:fs";var sp=q("pat-token-store");async function da(t=Z()){try{let n=(await ZS.readFile(t.patTokenFile,"utf8")).trim();return n.length===0?(sp.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"&&sp.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:n,message:e.message}),null}}async function ls(t,e=Z()){if(!t)throw new Error("writePatToken: empty patToken");await un(e.patTokenFile,t,{mode:384})}Te();Te();import{promises as la}from"node:fs";import{join as XS}from"node:path";function QS(t,e){return`#!/bin/sh
|
|
107
107
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
108
|
-
`}function
|
|
108
|
+
`}function e1(t,e){return`@echo off\r
|
|
109
109
|
"${e}" "${t}" %*\r
|
|
110
|
-
`}async function
|
|
110
|
+
`}async function op(t,e=Z()){let n=e.binDir;await la.mkdir(n,{recursive:!0});let i=XS(n,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,a=process.platform==="win32"?e1(t,o):QS(t,o);return await la.readFile(i,"utf8").catch(()=>null)===a||(await la.writeFile(i,a,"utf8"),process.platform!=="win32"&&await la.chmod(i,493)),n}re();Te();import{execSync as ap}from"node:child_process";import{readFileSync as cp,unlinkSync as t1}from"node:fs";import{mkdir as n1,open as r1,readFile as dp,unlink as Qd,writeFile as i1}from"node:fs/promises";import{dirname as s1}from"node:path";var o1=q("single-instance"),a1=t=>new Promise(e=>setTimeout(e,t)),ua=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Z().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:n=>Ji(n),isDaemon:n=>this.matchesDaemonTitle(n)},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 n=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&&o1.warn("removing stale pid file",{stalePid:i}),await i1(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return n.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),n}async release(){if(this.acquired){try{(await dp(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Qd(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 n=await dp(e,"utf8"),i=Number.parseInt(n.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(n){if(n.code==="ENOENT")return null;throw n}}async withClaimLock(e){let n=`${this.pidFile}.lock`;await n1(s1(n),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await r1(n,"wx")}catch(a){if(a.code!=="EEXIST")throw a;let d=await this.readPidFrom(n);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await a1(this.claimLockIntervalMs);continue}await Qd(n).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Qd(n).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${n} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let n=cp(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(n.includes(qr)||n.includes("lib/index.js"))}catch{}try{let n=ap(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return n.trim()?n.includes(qr)||n.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=ap(`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{cp(this.pidFile,"utf8").trim()===String(this.selfPid)&&t1(this.pidFile)}catch{}})}};fa();re();var or=q("daemon.upstream-watchdog"),p1=12e4,g1=9e5,m1=3e4;function tl(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var ha=class{constructor(e){this.opts=e;this.softMs=e.softMs??tl("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",p1),this.hardMs=e.hardMs??tl("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",g1),this.intervalMs=e.intervalMs??tl("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",m1),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?.(),or.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&&or.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&&or.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,or.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let n=e-this.downSince;if(n>=this.hardMs){or.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:n,hardMs:this.hardMs}),this.opts.onFatal(n);return}n>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,or.warn("upstream watchdog: forcing reconnect",{downMs:n,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>or.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var G=q("daemon");async function fp(){let t=Z();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){Nl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:R=>$e(R,t).logs,listAgentIds:()=>Ss(t)});try{let{writeFileSync:R}=await import("node:fs");R(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
|
|
111
111
|
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
112
112
|
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
113
|
-
`)}catch{}}let e=new ua({processTitle:zr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Fo(),o=i??{};ys({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");let c=new ca(new Yr),d=null,u=new zo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(D,U,W,te,Ze,he)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(D,U,W,te,Ze,he)}}),f=new No({paths:t,config:o,registry:u});d=f;let x,g,m=null,S={},_,v=null,I=null,A=null,C=new Pn;function O(D,U){return C.enqueue(()=>P(D,U))}function b(){I||(I=new ha({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?O(A,{force:!0}):void 0,onFatal:D=>{if(process.env[us]==="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 P(D,U){let W=D,te=W?.privatecode;if(!te)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Ze=Hi(W.env),he=W.handshake_url,me=W.frontier_url,At=lp(W.env,he,me);if(A=W,!U?.force&&x===te&&g===At){let be=await g1(t);return u.agents.size===0&&be?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),pa(t,f).catch(Te=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Te)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let mt=!!x&&x!==te,rn=g!==void 0&&g!==At,Gt=mt||rn,sn=await Yc({privatecode:te,...he?{endpoint:he}:{},ppeOverride:Ze});if(Gt){q.warn("connect config switched, resetting agents",{pcChanged:mt,envChanged:rn,previousPc:x?xa(x):"",nextPc:xa(te)});for(let be of[...u.agents.values()])await be.dispose("connect config switch").catch(()=>{}),u.agents.delete(be.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 Yr,"connect switch").catch(()=>{})}m=sn.deviceId,ys({deviceId:m,pid:process.pid}),Id({patToken:te,env:W.env}).catch(be=>q.warn("coze-cli setup error (ignored)",{err:String(be)}));let ni=new ds({handshake:sn,privatecode:te,...me?{urlOverride:me}:{},ppeOverride:Ze,getPatTokenForAgent:be=>u.agents.get(be)?.patToken});return await c.swap(ni,"connect"),x=te,g=At,S=Ze,_=he,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),q.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new ji({core:u,getDeviceId:()=>m??"",onTickEnd:()=>M.retryPending().catch(be=>q.warn("detailSync.retryPending failed (ignored)",{err:String(be)})),onAuthFailures:J})),v.start(),b(),Gt&&pa(t,f).catch(be=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(be)})),ls(te,t).catch(be=>q.warn("writePatToken after /connect failed (ignored)",{err:String(be)})),q.info("/connect: WS established",{deviceId:m}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async D=>f.createAgent(D.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let L={},F=new Eo({agents:u.agents,publishSkillToMarketplace:async D=>{let U=u.agents.get(D.agentId)?.patToken??x;if(!U)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return rp({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:_,ppeOverride:S})},disposeAndMarkDisconnected:async(D,U)=>{let W=u.agents.get(D);if(W){await f.cleanupOpenclawSessionProviders(W).catch(Ze=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:D,err:String(Ze)}));let te=!0;try{await W.dispose(`disconnect: ${U}`)}catch(Ze){te=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:D,err:String(Ze)}),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 f.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(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(D)},cleanupOpenclawProviders:async(D,U)=>{await f.cleanupOpenclawSessionProviders(D,U)},openclawRepair:async(D,U)=>{await f.openclawRepair(D,U)},isRuntimePendingPermission:D=>u.hasPendingPermissionFor(D)});u.registerExtension("_agent/listSkills",D=>F.listSkills(D.params)),u.registerExtension("_agent/addSkills",D=>F.addSkills(D.params)),u.registerExtension("_agent/removeSkills",D=>F.removeSkills(D.params)),u.registerExtension("_agent/publishSkill",D=>F.publishSkill(D.params)),u.registerExtension("_agent/getFileTree",D=>F.getFileTree(D.params)),u.registerExtension("_agent/getFileContent",D=>F.getFileContent(D.params)),u.registerExtension("_agent/update",D=>F.updateAgent(D.params)),u.registerExtension("_agent/disconnect",D=>F.disconnectAgent(D.params)),u.registerExtension("_agent/switchModel",D=>F.switchModel(D.params)),u.registerExtension("_agent/reset",D=>F.resetAgent(D.params)),u.registerExtension("_agent/repair",D=>F.repairAgent(D.params)),u.registerExtension("_agent/delete",D=>F.deleteAgent(D.params)),u.registerExtension("_agent/upgrade",D=>F.upgradeBridge(D.params));let M=new ks({paths:t,handlers:F,agentManager:f,sendDetail:D=>u.sendRequest("_agent/detail",D)});L.ref=M;let J=async D=>{await Promise.allSettled(D.map(async U=>{try{await F.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}),M.syncAll(D?"initial-connect":"reconnect").catch(U=>q.warn("detail sync top-level error (ignored)",{err:String(U)}))});let V=new Uo({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[us]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:m??"",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 k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ze=Hi(U.env),he=U.handshake_url,me=U.frontier_url,At=lp(U.env,he,me),mt=!!x&&x!==W,rn=g!==void 0&&g!==At,Gt=mt||rn,sn=await Yc({privatecode:W,...he?{endpoint:he}:{},ppeOverride:Ze});if(Gt){q.warn("pair config switched, resetting agents",{pcChanged:mt,envChanged:rn,previousPc:x?xa(x):"",nextPc:xa(W),previousEnvKey:g??"",nextEnvKey:At});for(let Te of[...u.agents.values()])await Te.dispose("pair config switch").catch(()=>{}),u.agents.delete(Te.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 Yr,"pair switch").catch(()=>{})}m=sn.deviceId,ys({deviceId:m,pid:process.pid}),Id({patToken:W,env:U.env}).catch(Te=>q.warn("coze-cli setup error (ignored)",{err:String(Te)}));let ni=new ds({handshake:sn,privatecode:W,...me?{urlOverride:me}:{},ppeOverride:Ze,getPatTokenForAgent:Te=>u.agents.get(Te)?.patToken});await c.swap(ni,"pair");try{let Te=new Xn;o.frameworksCache=await Te.detectAll(),await Xi(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Te){q.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:te,patToken:W,frameworks:be,_meta:{cozeDeviceId:m}});q.info("_agent/pair ok",{pairResult:Te}),x=W,g=At,S=Ze,_=he,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),q.info("mock scenario set",{scenario:U.mock_scenario})),ls(W,t).catch(Ne=>q.warn("writePatToken after /pair failed (ignored)",{err:String(Ne)})),v||(v=new ji({core:u,getDeviceId:()=>m??"",onTickEnd:()=>M.retryPending().catch(Ne=>q.warn("detailSync.retryPending failed (ignored)",{err:String(Ne)})),onAuthFailures:J})),v.start(),b(),Gt&&pa(t,f).catch(Ne=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(Ne)}));let or;return U.agent_id&&(or=await w1(U.agent_id,t,f,Ne=>u.sendRequest("_agent/detail",Ne),W).catch(Ne=>(q.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(Ne)}),{ok:!1,agentId:U.agent_id??"",note:String(Ne)}))),{ok:!0,note:"paired with cloud",...or?{agent:or}:{}}}catch(Te){return q.error("_agent/pair failed",{err:String(Te)}),{ok:!1,note:`pair failed: ${String(Te)}`}}}},{method:"POST",path:"/connect",handler:D=>O(D)},{method:"POST",path:"/_agent/create",handler:async D=>{let U=D;return{ok:!0,result:await f.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async D=>{let U=D;if(!U?.agentId||!U?.sessionId||!U?.kind||!U?.path)throw new k("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=U;return await(W.groupFile?wh:mh)(W,{core:u,patToken:x,handshakeBase:_,ppeOverride:S})}catch(W){if(W instanceof k)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:X}=await V.start();try{await sp(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(),_1({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Xn().detectAll(),await Xi(o),o.frameworksCache)}).catch(D=>q.warn("startup warmup error (ignored)",{err:String(D)})),ql().then(async()=>{let{probeAcpVersion:D}=await Promise.resolve().then(()=>(dn(),Gl));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:X,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",()=>M0()),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}
|
|
114
|
-
`)}catch{}process.exit(1)}),
|
|
115
|
-
`)){let u=d.indexOf("=");u<=0||(
|
|
116
|
-
`;await hs(
|
|
117
|
-
`).filter(d=>d.length>0).filter(d=>
|
|
118
|
-
`)}async function
|
|
113
|
+
`)}catch{}}let e=new ua({processTitle:qr}),n=await e.acquire();if(n.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${n.pid})`);let i=await Fo(),o=i??{};ys({pid:process.pid}),G.info(i?"loaded bridge config":"initialized bridge config");let a=new ca(new ei),d=null,u=new zo({upstream:a,paths:t,bridgeConfig:o,sessionSpawner:async(R,U,H,ne,Je,ue)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(R,U,H,ne,Je,ue)}}),f=new No({paths:t,config:o,registry:u});d=f;let x,g,w=null,S={},_,b=null,I=null,A=null,T=new Rn;function P(R,U){return T.enqueue(()=>D(R,U))}function y(){I||(I=new ha({isConnected:()=>a.isConnected()&&!(b?.isLivenessLost()??!1),forceReconnect:()=>A?P(A,{force:!0}):void 0,onFatal:R=>{if(process.env[us]==="1"){G.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:R});return}G.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:R}),process.exit(1)}})),I.start()}async function D(R,U){let H=R,ne=H?.privatecode;if(!ne)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Je=Gi(H.env),ue=H.handshake_url,pe=H.frontier_url,At=up(H.env,ue,pe);if(A=H,!U?.force&&x===ne&&g===At){let _e=await w1(t);return u.agents.size===0&&_e?(G.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),pa(t,f).catch(Ae=>G.warn("connect-noop auto-revive error (ignored)",{err:String(Ae)}))):G.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let gt=!!x&&x!==ne,sn=g!==void 0&&g!==At,Gt=gt||sn,on=await Zc({privatecode:ne,...ue?{endpoint:ue}:{},ppeOverride:Je});if(Gt){G.warn("connect config switched, resetting agents",{pcChanged:gt,envChanged:sn,previousPc:x?xa(x):"",nextPc:xa(ne)});for(let _e of[...u.agents.values()])await _e.dispose("connect config switch").catch(()=>{}),u.agents.delete(_e.agentId);u.disconnectedAgents.size>0&&(G.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await a.swap(new ei,"connect switch").catch(()=>{})}w=on.deviceId,ys({deviceId:w,pid:process.pid}),Id({patToken:ne,env:H.env}).catch(_e=>G.warn("coze-cli setup error (ignored)",{err:String(_e)}));let si=new ds({handshake:on,privatecode:ne,...pe?{urlOverride:pe}:{},ppeOverride:Je,getPatTokenForAgent:_e=>u.agents.get(_e)?.patToken});return await a.swap(si,"connect"),x=ne,g=At,S=Je,_=ue,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),G.info("mock scenario set",{scenario:H.mock_scenario})),b||(b=new ji({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(_e=>G.warn("detailSync.retryPending failed (ignored)",{err:String(_e)})),onAuthFailures:Y})),b.start(),y(),Gt&&pa(t,f).catch(_e=>G.warn("post-connect-switch auto-revive error (ignored)",{err:String(_e)})),ls(ne,t).catch(_e=>G.warn("writePatToken after /connect failed (ignored)",{err:String(_e)})),G.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async R=>f.createAgent(R.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let L={},B=new bo({agents:u.agents,publishSkillToMarketplace:async R=>{let U=u.agents.get(R.agentId)?.patToken??x;if(!U)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return ip({patToken:U,zip:R.zip,...R.skillId?{skillId:R.skillId}:{},skillName:R.skillName,...R.description?{description:R.description}:{},agentId:R.agentId,...R.accountId?{accountId:R.accountId}:{}},{handshakeBase:_,ppeOverride:S})},disposeAndMarkDisconnected:async(R,U)=>{let H=u.agents.get(R);if(H){await f.cleanupOpenclawSessionProviders(H).catch(Je=>G.warn("cleanup openclaw providers failed (ignored)",{agentId:R,err:String(Je)}));let ne=!0;try{await H.dispose(`disconnect: ${U}`)}catch(Je){ne=!1,G.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:R,err:String(Je)}),H.status="error"}ne&&(H.status="disconnected",u.unregister(R),u.disconnectedAgents.add(R))}else u.disconnectedAgents.add(R)},disposeForDelete:async(R,U)=>{let H=u.agents.get(R);H&&(await f.cleanupOpenclawSessionProviders(H).catch(ne=>G.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:R,err:String(ne)})),await H.dispose(`delete: ${U}`).catch(ne=>G.warn("dispose during delete failed (ignored)",{agentId:R,err:String(ne)})),u.unregister(R)),u.disconnectedAgents.delete(R)},detailSyncer:async R=>{if(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(R)},cleanupOpenclawProviders:async(R,U)=>{await f.cleanupOpenclawSessionProviders(R,U)},openclawRepair:async(R,U)=>{await f.openclawRepair(R,U)},isRuntimePendingPermission:R=>u.hasPendingPermissionFor(R)});u.registerExtension("_agent/listSkills",R=>B.listSkills(R.params)),u.registerExtension("_agent/addSkills",R=>B.addSkills(R.params)),u.registerExtension("_agent/removeSkills",R=>B.removeSkills(R.params)),u.registerExtension("_agent/publishSkill",R=>B.publishSkill(R.params)),u.registerExtension("_agent/getFileTree",R=>B.getFileTree(R.params)),u.registerExtension("_agent/getFileContent",R=>B.getFileContent(R.params)),u.registerExtension("_agent/update",R=>B.updateAgent(R.params)),u.registerExtension("_agent/disconnect",R=>B.disconnectAgent(R.params)),u.registerExtension("_agent/switchModel",R=>B.switchModel(R.params)),u.registerExtension("_agent/reset",R=>B.resetAgent(R.params)),u.registerExtension("_agent/repair",R=>B.repairAgent(R.params)),u.registerExtension("_agent/delete",R=>B.deleteAgent(R.params)),u.registerExtension("_agent/upgrade",R=>B.upgradeBridge(R.params));let M=new ks({paths:t,handlers:B,agentManager:f,sendDetail:R=>u.sendRequest("_agent/detail",R)});L.ref=M;let Y=async R=>{await Promise.allSettled(R.map(async U=>{try{await B.disconnectAgent({agentId:U.agentId,reason:`auth_failure: code=${U.code} ${U.message}`}),G.info("agent disconnected due to auth failure from heartbeat response",{agentId:U.agentId,code:U.code,message:U.message})}catch(H){G.warn("disconnect during authFailure handling failed (ignored)",{agentId:U.agentId,err:String(H)})}}))};a.onConnect(({initial:R})=>{G.info("frontier upstream connected, triggering detail sync",{initial:R}),M.syncAll(R?"initial-connect":"reconnect").catch(U=>G.warn("detail sync top-level error (ignored)",{err:String(U)}))});let J=new Uo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let R=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[us]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...R?{mockScenario:R}:{}}}},{method:"POST",path:"/pair",handler:async R=>{let U=R,H=U?.privatecode,ne=U?.pairing_code;if(!H||!ne)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Je=Gi(U.env),ue=U.handshake_url,pe=U.frontier_url,At=up(U.env,ue,pe),gt=!!x&&x!==H,sn=g!==void 0&&g!==At,Gt=gt||sn,on=await Zc({privatecode:H,...ue?{endpoint:ue}:{},ppeOverride:Je});if(Gt){G.warn("pair config switched, resetting agents",{pcChanged:gt,envChanged:sn,previousPc:x?xa(x):"",nextPc:xa(H),previousEnvKey:g??"",nextEnvKey:At});for(let Ae of[...u.agents.values()])await Ae.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ae.agentId);u.disconnectedAgents.size>0&&(G.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await a.swap(new ei,"pair switch").catch(()=>{})}w=on.deviceId,ys({deviceId:w,pid:process.pid}),Id({patToken:H,env:U.env}).catch(Ae=>G.warn("coze-cli setup error (ignored)",{err:String(Ae)}));let si=new ds({handshake:on,privatecode:H,...pe?{urlOverride:pe}:{},ppeOverride:Je,getPatTokenForAgent:Ae=>u.agents.get(Ae)?.patToken});await a.swap(si,"pair");try{let Ae=new Qn;o.frameworksCache=await Ae.detectAll(),await Xi(o),G.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ae){G.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ae)})}let _e=Object.keys(o.frameworksCache??{});try{let Ae=await u.sendRequest("_agent/pair",{pairCode:ne,patToken:H,frameworks:_e,_meta:{cozeDeviceId:w}});G.info("_agent/pair ok",{pairResult:Ae}),x=H,g=At,S=Je,_=ue,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),G.info("mock scenario set",{scenario:U.mock_scenario})),ls(H,t).catch(Oe=>G.warn("writePatToken after /pair failed (ignored)",{err:String(Oe)})),b||(b=new ji({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Oe=>G.warn("detailSync.retryPending failed (ignored)",{err:String(Oe)})),onAuthFailures:Y})),b.start(),y(),Gt&&pa(t,f).catch(Oe=>G.warn("post-pair-switch auto-revive error (ignored)",{err:String(Oe)}));let ar;return U.agent_id&&(ar=await y1(U.agent_id,t,f,Oe=>u.sendRequest("_agent/detail",Oe),H).catch(Oe=>(G.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(Oe)}),{ok:!1,agentId:U.agent_id??"",note:String(Oe)}))),{ok:!0,note:"paired with cloud",...ar?{agent:ar}:{}}}catch(Ae){return G.error("_agent/pair failed",{err:String(Ae)}),{ok:!1,note:`pair failed: ${String(Ae)}`}}}},{method:"POST",path:"/connect",handler:R=>P(R)},{method:"POST",path:"/_agent/create",handler:async R=>{let U=R;return{ok:!0,result:await f.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async R=>{let U=R;if(!U?.agentId||!U?.sessionId||!U?.kind||!U?.path)throw new k("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let H=U;return await(H.groupFile?_h:wh)(H,{core:u,patToken:x,handshakeBase:_,ppeOverride:S})}catch(H){if(H instanceof k)return{ok:!1,code:H.code,message:H.message};throw H}}},{method:"POST",path:"/reload",handler:async R=>{let U=R?.agent_id,H=await u.reloadAgents(U);return G.info("IPC /reload: recycled agent subprocesses",{agentId:U??"(all)",recycled:H}),{ok:!0,recycled:H}}},{method:"POST",path:"/shutdown",handler:async()=>(G.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ie,token:Q}=await J.start();try{await op(t.libEntry,t)}catch(R){G.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(R)})}await u.start(),E1({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Qn().detectAll(),await Xi(o),o.frameworksCache)}).catch(R=>G.warn("startup warmup error (ignored)",{err:String(R)})),Wl().then(async()=>{let{probeAcpVersion:R}=await Promise.resolve().then(()=>(dn(),Hl));for(let U of["claude-code","codex"]){let H=await R(U);H&&G.info("acp wrapper version",{framework:U,version:H})}}).catch(R=>G.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(R)}));let te=null,oe={port:ie,token:Q,core:u,ipc:J,shutdown(R){return te||(G.info("daemon shutdown",{reason:R}),te=(async()=>{b?.stop(),I?.stop(),await u.stop(R),await J.stop(),await e.release()})(),te)}};for(let R of["SIGTERM","SIGINT"])process.on(R,()=>{oe.shutdown(R).then(()=>process.exit(0))});return process.on("exit",()=>B0()),process.on("unhandledRejection",R=>{G.error("unhandledRejection",{reason:R instanceof Error?R.message:String(R),stack:R instanceof Error?R.stack:void 0})}),process.on("uncaughtException",R=>{G.error("uncaughtException (will exit, supervisor will restart)",{message:R.message,stack:R.stack,name:R.name});try{process.stderr.write(`FATAL uncaughtException: ${R.stack??R.message}
|
|
114
|
+
`)}catch{}process.exit(1)}),G.info("daemon ready",{port:ie,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),v1({cliSpawned:process.env[us]==="1",readPatToken:()=>da(t),connect:P}).catch(R=>G.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(R)})),oe}async function w1(t){return Ss(t).length>0}function xa(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function up(t,e,n){return`${t??""}|${e??""}|${n??""}`}async function _1(t,e){let n=Ss(t);if(n.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(xn(),As));for(let a of n){await o(a,t).catch(d=>G.warn("enforceAgentConfigMode failed (ignored)",{agentId:a,err:String(d)}));try{let d=await i(a,t);d?.deletedAt?(e.disconnectedAgents.add(a),G.info("agent marked deleted on startup",{agentId:a,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(a),G.info("agent marked disconnected on startup",{agentId:a,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){G.warn("failed to load agent config on startup, skipping",{agentId:a,err:String(d)})}}}async function y1(t,e,n,i,o){let{loadAgentConfig:a}=await Promise.resolve().then(()=>(xn(),As)),d=await a(t,e);if(d){if(d.deletedAt)throw new k("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${d.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);G.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let g=hp(d),w={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...g?{_meta:g}:{}};return await n.createAgent(w),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}G.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new k("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let f={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await n.createAgent(f);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function E1(t){let e=t.logger??G;try{let n=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(n??{})})}catch(n){e.warn("framework detection failed (using cached)",{err:String(n)})}await _1(t.paths,t.core).catch(n=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(n)})),await pa(t.paths,t.agentManager).catch(n=>e.warn("auto-revive top-level error (ignored)",{err:String(n)})),await b1(t.paths).catch(n=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(n)}))}async function pa(t,e){let{readdir:n}=await import("node:fs/promises"),i;try{i=await n(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(()=>(xn(),As));G.info("auto-revive: scanning local agents on startup",{count:i.length});let a=0,d=0;for(let u of i){let f;try{f=await o(u,t)}catch(x){G.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),d+=1;continue}if(!f){d+=1;continue}if(f.deletedAt){G.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:f.deletedAt}),d+=1;continue}if(f.disconnectedAt){G.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),d+=1;continue}try{G.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let x=hp(f);await e.createAgent({agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...x?{_meta:x}:{}},{revive:!0}),a+=1}catch(x){G.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(x)}),d+=1}}return G.info("auto-revive: done",{revived:a,skipped:d,total:i.length}),{revived:a,skipped:d,total:i.length}}async function b1(t){let{readdir:e}=await import("node:fs/promises"),n;try{n=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(n.length===0)return{refreshed:0,total:0};let i=0;for(let o of n)try{(await I0(o,t)).status==="refreshed"&&(i+=1)}catch(a){G.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(a)})}return i>0&&G.info("builtin skills refresh on startup done",{refreshed:i,total:n.length}),{refreshed:i,total:n.length}}async function v1(t){let e=t.logger??G;if(t.cliSpawned)return"skipped-cli";let n=await t.readPatToken();return n?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:n}).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 hp(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}fa();Te();import{readFile as xp}from"node:fs/promises";var rn=class{paths;constructor(e){this.paths=e??Z()}async probe(e=1e3){let n=await ga(this.paths);if(!n)return{kind:"not-running"};try{let i=await this.fetch(n,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...n,body:i.body}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:I1(i)}}}async request(e){let n=await ga(this.paths);if(!n)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(n,e)}async fetch(e,n){let i=n.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let a=new AbortController,d=setTimeout(()=>a.abort(),n.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${n.path}`,{method:n.method,headers:o,body:i?JSON.stringify(n.body):void 0,signal:a.signal}),f=await u.text();return{status:u.status,body:S1(f)}}finally{clearTimeout(d)}}};async function ga(t){try{let[e,n]=await Promise.all([xp(t.portFile,"utf8"),xp(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=n.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 I1(t){return t instanceof Error?t.message:String(t)}Zt();re();fr();import{spawn as A1}from"node:child_process";import{userInfo as gp}from"node:os";var nl="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",k1=new Set(["bash","zsh","sh","dash","ksh"]),pp=Ye("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),T1=2e3;function C1(t,e=nl){let n=t.indexOf(e);if(n===-1)return null;let i=t.indexOf(e,n+e.length);if(i===-1)return null;let o=t.slice(n+e.length,i),a={};for(let d of o.split(`
|
|
115
|
+
`)){let u=d.indexOf("=");u<=0||(a[d.slice(0,u)]=d.slice(u+1))}return a}function D1(){let t=(process.env.SHELL??"").trim()||(gp().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return k1.has(e)?t:null}function R1(t){return new Promise(e=>{let n=`printf '%s' '${nl}'; env; printf '%s' '${nl}'`,i;try{i=A1(t,["-ilc",n],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??gp().homedir}})}catch{e(null);return}let o="",a=!1,d=g=>{try{i.pid&&process.kill(-i.pid,g)}catch{}},u=g=>{a||(a=!0,clearTimeout(f),clearTimeout(x),e(g))};i.stdout?.on("data",g=>{o+=g.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let f=setTimeout(()=>d("SIGTERM"),pp),x=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},pp+T1)})}async function rl(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let n=D1();if(!n)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??R1)(n);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=C1(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Te();function Ln(t,...e){let n=[],i;for(let o=0;o<t.length;o++){let a=t[o],d=!1;for(let u of e){if(a===u){i=t[o+1],o+=1,d=!0;break}if(a.startsWith(`${u}=`)){i=a.slice(u.length+1),d=!0;break}}d||n.push(a)}return{value:i,rest:n}}dn();import{chmod as P1,copyFile as mp,mkdir as _p,readFile as hs,rename as wp,rm as ol,stat as al,writeFile as O1}from"node:fs/promises";import{homedir as jP}from"node:os";import{dirname as L1,join as qt,resolve as cl,sep as fs}from"node:path";import{fileURLToPath as N1}from"node:url";Zt();re();Te();var ti=q("dist-install");function yp(){return{darwin:{arm64:"@zed-industries/codex-acp-darwin-arm64",x64:"@zed-industries/codex-acp-darwin-x64"},linux:{arm64:"@zed-industries/codex-acp-linux-arm64",x64:"@zed-industries/codex-acp-linux-x64"},win32:{arm64:"@zed-industries/codex-acp-win32-arm64",x64:"@zed-industries/codex-acp-win32-x64"}}[process.platform]?.[process.arch]}function M1(){return process.platform==="win32"?"codex-acp.exe":"codex-acp"}function B1(t){let e=N1(t),n=L1(e),i=`${fs}src${fs}`;if(n.includes(i)||n.endsWith(`${fs}src${fs}cli`))return null;let o=cl(n,"index.js"),a=cl(n,"..","package.json");return{dist:o,pkgJson:a}}async function dl(t={}){let e=t.paths??Z(),n=B1(import.meta.url),i=t.sourceDist??n?.dist,o=t.sourcePackageJson??n?.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 a,d;try{let b=JSON.parse(await hs(o,"utf8"));a=b.version??"unknown",d=b.dependencies??{}}catch(b){return ti.warn("cannot read source package.json,skip dist install",{err:String(b)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(b)}`}}let u=bs.map(b=>({name:b,spec:d[b]??"latest"})),f=u.map(({name:b,spec:I})=>`${b}@${I}`),x=await Fo(e.configFile)??{},g=x.libVersion,w=await hs(e.libEntry).then(()=>!0).catch(()=>!1),S=g===a,_=await Ep(e,u);if(S&&w&&_)return{kind:"already-current",libVersion:a};if(!S||!w){await _p(e.libDir,{recursive:!0}),await mp(i,e.libEntry),await mp(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let b=cl(e.libDir,"package.json"),I=`${JSON.stringify({type:"module"},null,2)}
|
|
116
|
+
`;await hs(b,"utf8").catch(()=>null)!==I&&await O1(b,I)}return _||(t.installWrappers?await t.installWrappers(e,f):await z1(e,f,u)),x.libVersion=a,await Xi(x,e.configFile),ti.info("dist installed",{libEntry:e.libEntry,fromVersion:g,toVersion:a}),S&&w?{kind:"already-current",libVersion:a}:g?{kind:"version-changed",fromVersion:g,toVersion:a,libEntry:e.libEntry}:{kind:"first-install",libVersion:a,libEntry:e.libEntry}}async function Ep(t,e){for(let n of e){let i=qt(t.libDir,"node_modules",...n.name.split("/"),"package.json"),o;try{o=JSON.parse(await hs(i,"utf8"))}catch(d){return ti.warn("wrapper not ready: package.json read failed",{package:n.name,expected:n.spec,pkgJson:i,err:String(d)}),!1}let a=o.version;if(!a)return ti.warn("wrapper not ready: package.json \u7F3A version",{package:n.name,expected:n.spec,pkgJson:i}),!1;if(!F1(a,n.spec))return ti.warn("wrapper not ready: installed version does not satisfy expected range",{package:n.name,installed:a,expected:n.spec}),!1}return!!await bp(qt(t.libDir,"node_modules"))}function F1(t,e){let n=il(t);if(!n)return!0;let i=e.trim();if(!i||i==="*"||i==="latest")return!0;if(i.startsWith("^")){let a=il(i.slice(1));if(!a)return!0;if(sl(n,a)<0)return!1;let d=a[0]>0?[a[0]+1,0,0]:a[1]>0?[0,a[1]+1,0]:[0,0,a[2]+1];return sl(n,d)<0}let o=il(i);return o?sl(n,o)===0:!0}function il(t){let e=t.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}function sl(t,e){for(let n=0;n<3;n++){let i=(t[n]??0)-(e[n]??0);if(i!==0)return i}return 0}async function z1(t,e,n){await G1(t.installLock,async()=>{if(await Ep(t,n))return;let i=Math.random().toString(36).slice(2,10),o=`${t.libDir}${fs}.staging-${process.pid}-${i}`,a=qt(o,"node_modules"),d=qt(t.libDir,"node_modules");try{await _p(o,{recursive:!0}),await U1(e,o),await q1(a);let u=`${d}.trash-${i}`;await wp(d,u).catch(()=>{}),await wp(a,d),await ol(u,{recursive:!0,force:!0}).catch(()=>{}),ti.info("wrapper closure installed",{liveNm:d,specs:e})}finally{await ol(o,{recursive:!0,force:!0}).catch(()=>{})}})}function U1(t,e){let n=["install",...t,"--prefix",e,"--omit=dev","--include=optional","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let a=rt("npm",n,{stdio:["ignore","pipe","pipe"]}),d="";a.stderr?.on("data",f=>{d.length<8192&&(d+=f.toString("utf8"))});let u=setTimeout(()=>a.kill("SIGKILL"),18e4);a.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),a.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${d.trim().slice(0,2e3)}`))})})}async function q1(t){for(let e of bs){let n=qt(t,...e.split("/")),i=JSON.parse(await hs(qt(n,"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 a=qt(t,".bin",o),d=await al(a);process.platform!=="win32"&&!(d.mode&73)&&await P1(a,d.mode|73).catch(()=>{})}if(!await bp(t)){let e=yp()??"<unsupported-platform>";throw new Error(`${e}: \u5F53\u524D\u5E73\u53F0 codex-acp binary \u7F3A\u5931`)}}async function bp(t){let e=yp();if(!e)return!0;let n=qt(t,...e.split("/")),i=qt(n,"package.json"),o=qt(n,"bin",M1()),[a,d]=await Promise.all([al(i).then(u=>u.isFile()).catch(()=>!1),al(o).then(u=>u.isFile()).catch(()=>!1)]);return a&&d}async function G1(t,e){let{open:n}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await n(t,"wx")).close(),i=!0}catch{await new Promise(a=>setTimeout(a,500))}try{return await e()}finally{i&&await ol(t,{force:!0}).catch(()=>{})}}Ma();re();Te();import{closeSync as Sp,fstatSync as Ip,openSync as Ap,readFileSync as H1,readSync as j1,readdirSync as W1,statSync as K1}from"node:fs";import{join as ma}from"node:path";var $1=new Set(["debug","info","warn","error"]);function kp(t){let e=t,n=Ln(e,"--agent-id");e=n.rest;let i=Ln(e,"--date");e=i.rest;let o=Ln(e,"-n","--lines");e=o.rest;let a=Ln(e,"--level");e=a.rest;let d=Ln(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),f=Number.isInteger(u)&&u>=0?u:200,x=a.value&&$1.has(a.value)?a.value:void 0,g={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return n.value&&(g.agentId=n.value),i.value&&(g.date=i.value),x&&(g.level=x),d.value&&(g.grep=d.value),g}function V1(t,e){return t.agentId?ma($e(t.agentId,e).logs,hr("agent",t.date)):ma(e.bridgeLogsDir,hr("bridge",t.date))}function J1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function Y1(t,e){let n;try{n=W1(t)}catch{return[]}let i=[];for(let o of n){let a=Na(o,e);if(!a)continue;let d=0;try{d=K1(ma(t,o)).size}catch{}i.push({file:ma(t,o),date:a,size:d})}return i.sort((o,a)=>a.date.localeCompare(o.date)),i}function Tp(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let n;try{n=JSON.parse(t).level}catch{return!0}if(typeof n=="string"&&!Fl(n,e.level))return!1}return!0}var vp={debug:"90",info:"36",warn:"33",error:"31"},Z1=new Set(["ts","level","module","msg"]);function X1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Cp(t,e){if(e.raw)return t;let n;try{n=JSON.parse(t)}catch{return t}let i=X1(n.ts),o=typeof n.level=="string"?n.level:"",a=o.toUpperCase().padEnd(5);e.color&&vp[o]&&(a=`\x1B[${vp[o]}m${a}\x1B[0m`);let d=typeof n.module=="string"?n.module:"",u=typeof n.msg=="string"?n.msg:"",f=Object.entries(n).filter(([x])=>!Z1.has(x)).map(([x,g])=>` ${x}=${typeof g=="string"?g:JSON.stringify(g)}`).join("");return`${i} ${a} ${d} ${u}${f}`}function Q1(t,e,n){let a=H1(t,"utf8").split(`
|
|
117
|
+
`).filter(d=>d.length>0).filter(d=>Tp(d,{level:e.level,grep:e.grep}));for(let d of J1(a,e.lines))process.stdout.write(`${Cp(d,{raw:e.raw,color:n})}
|
|
118
|
+
`)}async function Dp(t,e){let n=e.paths??Z(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?$e(t.agentId,n).logs:n.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=Y1(d,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
|
|
119
119
|
`),1;for(let x of f)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
|
|
120
|
-
`);return 0}let o=t.date??
|
|
120
|
+
`);return 0}let o=t.date??Bn(new Date),a=V1({agentId:t.agentId,date:o},n);try{Q1(a,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${a}
|
|
121
121
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
122
|
-
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${
|
|
123
|
-
`),1}return t.follow&&await
|
|
124
|
-
`);o=f.pop()??"";for(let x of f)x.length>0&&
|
|
125
|
-
`)}await new Promise(f=>setTimeout(f,
|
|
122
|
+
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${n.logFile})
|
|
123
|
+
`),1}return t.follow&&await n2(a,t,i),0}var e2=500;function t2(t){try{let e=Ap(t,"r");try{return Ip(e).size}finally{Sp(e)}}catch{return 0}}async function n2(t,e,n){let i=t2(t),o="",a=!1,d=()=>{a=!0};process.on("SIGINT",d);try{for(;!a;){let u="";try{let f=Ap(t,"r");try{let x=Ip(f).size;if(x>i){let g=Buffer.allocUnsafe(x-i),w=j1(f,g,0,g.length,i);u=g.subarray(0,w).toString("utf8"),i+=w}}finally{Sp(f)}}catch{}if(u){let f=(o+u).split(`
|
|
124
|
+
`);o=f.pop()??"";for(let x of f)x.length>0&&Tp(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Cp(x,{raw:e.raw,color:n})}
|
|
125
|
+
`)}await new Promise(f=>setTimeout(f,e2))}}finally{process.off("SIGINT",d)}}import{basename as r2,resolve as i2}from"node:path";Te();var s2=9e4,o2={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function a2(t){return o2[t]??1}async function Rp(t,e={}){let n=e.paths??Z();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>
|
|
126
126
|
`),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.
|
|
127
|
-
`),3;let i=await ga(
|
|
128
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
129
|
-
`),4}if(!
|
|
130
|
-
`),
|
|
131
|
-
`);else{let d=t.name??
|
|
132
|
-
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${
|
|
133
|
-
`)}return 0}async function
|
|
134
|
-
`)}function
|
|
127
|
+
`),3;let i=await ga(n).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${n.portFile} / ${n.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
|
|
128
|
+
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:i2(process.cwd(),t.path),...t.caption?{caption:t.caption}:{},...t.name?{name:t.name}:{},...t.groupFile?{groupFile:!0}:{},...t.mimeType?{mimeType:t.mimeType}:{}},a;try{a=await c2(i,"/agent/send",o,s2)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
|
|
129
|
+
`),4}if(!a.ok)return process.stderr.write(`Error: ${a.code}: ${a.message}
|
|
130
|
+
`),a2(a.code);if(t.json)process.stdout.write(`${JSON.stringify(a)}
|
|
131
|
+
`);else{let d=t.name??r2(o.path);if(t.groupFile){let u=a.uri.length>60?`${a.uri.slice(0,57)}...`:a.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
|
|
132
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${d2(a.bytes)})
|
|
133
|
+
`)}return 0}async function c2(t,e,n,i){let o=new AbortController,a=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(n),signal:o.signal}),u=await d.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(a)}}function d2(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var qp=q("cli");function je(t,e){let{value:n,rest:i}=Ln(t,e);return{value:n,rest:i}}function va(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
134
|
+
`)}function O2(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:P}=je(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 L2(e.slice(1));if(e[0]==="log")return{mode:"log",...kp(e.slice(1))};if(e[0]==="connect")return N2(e.slice(1));if(e.includes("--status"))return va("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return va("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return va("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return va("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let n=e,{value:i,rest:o}=je(n,"--pat-token");n=o;let{value:a,rest:d}=je(n,"--pair-code");n=d;let{value:u,rest:f}=je(n,"--env");n=f;let{value:x,rest:g}=je(n,"--handshake-url");n=g;let{value:w,rest:S}=je(n,"--frontier-url");n=S;let{value:_,rest:b}=je(n,"--mock-scenario");n=b;let{value:I}=je(n,"--agent-id"),A=n.includes("--skip-rebuild-env");if(!i||!a)return{mode:"help"};let T={mode:"pair",privatecode:i,pairingCode:a};return u&&(T.env=u),x&&(T.handshakeUrl=x),w&&(T.frontierUrl=w),_&&(T.mockScenario=_),I&&(T.agentId=I),A&&(T.skipRebuildEnv=!0),T}function L2(t){let e=t[0],n=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!n||n.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:a}=je(i,"--caption");i=a;let{value:d,rest:u}=je(i,"--name");i=u;let{value:f,rest:x}=je(i,"--agent-id");i=x;let{value:g,rest:w}=je(i,"--session-id");i=w;let{value:S,rest:_}=je(i,"--mime");i=_;let b=i.includes("--group-file");i=i.filter(T=>T!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:n,json:I};return o&&(A.caption=o),d&&(A.name=d),f&&(A.agentId=f),g&&(A.sessionId=g),b&&(A.groupFile=!0),S&&(A.mimeType=S),A}function N2(t){let e=t,{value:n,rest:i}=je(e,"--pat-token");e=i;let{value:o,rest:a}=je(e,"--env");e=a;let{value:d,rest:u}=je(e,"--handshake-url");e=u;let{value:f,rest:x}=je(e,"--frontier-url");e=x;let{value:g,rest:w}=je(e,"--mock-scenario");e=w;let S=e.includes("--skip-rebuild-env"),_={mode:"connect"};return n&&(_.privatecode=n),o&&(_.env=o),d&&(_.handshakeUrl=d),f&&(_.frontierUrl=f),g&&(_.mockScenario=g),S&&(_.skipRebuildEnv=!0),_}var M2=`
|
|
135
135
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
136
136
|
|
|
137
137
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -212,57 +212,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
212
212
|
|
|
213
213
|
Internal:
|
|
214
214
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
215
|
-
`.trimStart();async function
|
|
216
|
-
`),0;case"daemon":{try{await
|
|
217
|
-
`),1;if(i.kind==="stale")return await
|
|
218
|
-
`),1;let o=await
|
|
215
|
+
`.trimStart();async function Gp(t=process.argv,e={}){let n=O2(t);switch(n.mode){case"help":return process.stdout.write(M2),0;case"version":return process.stdout.write(`${Ot}
|
|
216
|
+
`),0;case"daemon":{try{await fp()}catch(i){return qp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return B2(e);case"stop":return jp(e);case"reload":return U2(n.agentId,e);case"log":return Dp(n,e);case"update":return F2(e);case"purge":return G2(e);case"service-install":return H2(e);case"service-uninstall":return j2(e);case"pair":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),W2(n.privatecode,n.pairingCode,e,i,n.agentId,n.skipRebuildEnv)}case"connect":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),K2(n.privatecode,e,i,n.skipRebuildEnv)}case"send":return Rp({kind:n.kind,path:n.path,...n.agentId?{agentId:n.agentId}:{},...n.sessionId?{sessionId:n.sessionId}:{},...n.caption?{caption:n.caption}:{},...n.name?{name:n.name}:{},...n.groupFile?{groupFile:!0}:{},...n.mimeType?{mimeType:n.mimeType}:{},json:n.json},e)}}async function Hp(t){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(t.pidFile).catch(()=>{}),e(t.portFile).catch(()=>{}),e(t.tokenFile).catch(()=>{})])}async function B2(t){let e=t.paths??Z(),n=new rn(e),i=await n.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
217
|
+
`),1;if(i.kind==="stale")return await Hp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
218
|
+
`),1;let o=await n.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
219
219
|
${JSON.stringify(o.body,null,2)}
|
|
220
|
-
`),0}async function jp(t){let e=t.paths??Z(),
|
|
221
|
-
`)}let u=await
|
|
220
|
+
`),0}async function jp(t){let e=t.paths??Z(),n=new rn(e),i=t.daemonSweep??(async()=>{let f=F0();return await z0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},a=await ps(t),d=!1;if(a)try{await a.uninstall(),d=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
|
|
221
|
+
`)}let u=await n.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
|
|
222
222
|
`:`coze-bridge: not running
|
|
223
|
-
`),0;if(u.kind==="stale")return await
|
|
224
|
-
`),0;try{return await
|
|
225
|
-
`),0}catch(f){return(await
|
|
223
|
+
`),0;if(u.kind==="stale")return await Hp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
224
|
+
`),0;try{return await n.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
225
|
+
`),0}catch(f){return(await n.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
|
|
226
226
|
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
|
|
227
|
-
`),1)}}async function
|
|
228
|
-
`),e(1)})})}async function
|
|
229
|
-
`),1;try{let o=await
|
|
230
|
-
`):process.stdout.write(`coze-bridge: reloaded ${
|
|
227
|
+
`),1)}}async function F2(t){return await jp(t),(t.spawnNpx??z2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function z2(t){return new Promise(e=>{let n=rt("npx",t,{stdio:"inherit"});n.on("exit",i=>e(i??1)),n.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
|
|
228
|
+
`),e(1)})})}async function U2(t,e){let n=new rn(e.paths);if((await n.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
229
|
+
`),1;try{let o=await n.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let a=o.body.recycled??[];return t&&a.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
|
|
230
|
+
`):process.stdout.write(`coze-bridge: reloaded ${a.length} agent(s): ${a.join(", ")||"(none)"}
|
|
231
231
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
232
232
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
233
|
-
`),1}}async function ps(t){if(t.supervisor){let
|
|
233
|
+
`),1}}async function ps(t){if(t.supervisor){let a=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:a.platform,install:u=>a.install(d,u),uninstall:()=>a.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:n}=await Promise.resolve().then(()=>(Fp(),Bp)),i=e(),o=n();return{platform:i.platform,install:a=>i.install(o,a),uninstall:()=>i.uninstall(o)}}async function Wp(t,e){let n=await e.probe(),i=t.waitTimeoutMs??15e3,o=t.sleep??$2,a=t.paths??Z();if(n.kind==="connected"){if(!q2(n.body))return n;lt(a.bridgeLogsDir,"warn","cli","daemon Node \u4E0E\u5F53\u524D CLI \u4E0D\u4E00\u81F4, \u91CD\u542F daemon",{currentNode:process.execPath,currentArch:process.arch,daemon:n.body}),await e.request({method:"POST",path:"/shutdown"}).catch(f=>lt(a.bridgeLogsDir,"warn","cli","restart for Node drift: shutdown failed",{err:String(f)})),await Up(a.pidFile,o)}let d=t.spawnDaemon??lp,u=await ps(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await zp(e,i,o);if(f.kind==="connected")return f;lt(a.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:i})}catch(f){lt(a.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}lt(a.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 Up(a.pidFile,o)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
|
|
234
234
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
235
|
-
`),await d({paths:t.paths}),
|
|
235
|
+
`),await d({paths:t.paths}),zp(e,i,o)}function q2(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 G2(t){let e=new rn(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
236
236
|
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
|
|
237
237
|
`)}await new Promise(d=>setTimeout(d,500))}let i=await ps(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
238
238
|
`)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
|
|
239
|
-
`)}let o=t.paths??Z(),{rm:
|
|
239
|
+
`)}let o=t.paths??Z(),{rm:a}=await import("node:fs/promises");try{await a(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
|
|
240
240
|
`)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
|
|
241
241
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
242
|
-
`),0}async function
|
|
242
|
+
`),0}async function H2(t){let e=await ps(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
243
243
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
244
|
-
`),0}catch(
|
|
245
|
-
`),1}}async function
|
|
246
|
-
`),0}catch(
|
|
247
|
-
`),1}}async function
|
|
248
|
-
`),
|
|
249
|
-
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):
|
|
250
|
-
`)}let x=await
|
|
251
|
-
`),1;let g={privatecode:t,pairing_code:e};i.env&&(g.env=i.env),i.handshakeUrl&&(g.handshake_url=i.handshakeUrl),i.frontierUrl&&(g.frontier_url=i.frontierUrl),i.mockScenario&&(g.mock_scenario=i.mockScenario),o&&(g.agent_id=o);try{let
|
|
244
|
+
`),0}catch(n){return process.stderr.write(`coze-bridge: service install failed: ${String(n)}
|
|
245
|
+
`),1}}async function j2(t){let e=await ps(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
246
|
+
`),0}catch(n){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(n)}
|
|
247
|
+
`),1}}async function Kp(t,e,n){if(e)return lt(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await n();return i.kind==="ok"?(lt(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(lt(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)
|
|
248
|
+
`),lt(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function W2(t,e,n,i={},o,a){let d=new rn(n.paths),u=n.paths??Z(),f=await Kp(u,a,n.reconstructEnv??rl);if(await fd(u,f).catch(w=>lt(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!n.skipDistInstall){let w=await dl({paths:n.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
|
|
249
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
|
|
250
|
+
`)}let x=await Wp(n,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
|
|
251
|
+
`),1;let g={privatecode:t,pairing_code:e};i.env&&(g.env=i.env),i.handshakeUrl&&(g.handshake_url=i.handshakeUrl),i.frontierUrl&&(g.frontier_url=i.frontierUrl),i.mockScenario&&(g.mock_scenario=i.mockScenario),o&&(g.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:g,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let S=w.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
|
|
252
252
|
`),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"
|
|
253
|
-
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(
|
|
254
|
-
`),1}catch(
|
|
255
|
-
`),1}}async function
|
|
253
|
+
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
|
|
254
|
+
`),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
|
|
255
|
+
`),1}}async function K2(t,e,n={},i){let o=e.paths??Z(),a=t??await da(o);if(!a)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 Kp(o,i,e.reconstructEnv??rl);if(await fd(o,u).catch(g=>lt(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(g)})),!e.skipDistInstall){let g=await dl({paths:e.paths});g.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${g.fromVersion} \u2192 ${g.toVersion}
|
|
256
256
|
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):g.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${g.libVersion}
|
|
257
|
-
`)}let f=await
|
|
258
|
-
`),1;let x={privatecode:
|
|
259
|
-
`),t!==void 0&&await ls(
|
|
257
|
+
`)}let f=await Wp(e,d);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
|
|
258
|
+
`),1;let x={privatecode:a};n.env&&(x.env=n.env),n.handshakeUrl&&(x.handshake_url=n.handshakeUrl),n.frontierUrl&&(x.frontier_url=n.frontierUrl),n.mockScenario&&(x.mock_scenario=n.mockScenario);try{let g=await d.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return g.status===200&&g.body?.ok?(process.stdout.write(`coze-bridge: connected (${g.body.note??"ok"})
|
|
259
|
+
`),t!==void 0&&await ls(a,o).catch(w=>qp.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(g.body)}
|
|
260
260
|
`),1)}catch(g){return process.stderr.write(`coze-bridge: connect failed: ${String(g)}
|
|
261
|
-
`),1}}async function
|
|
262
|
-
`),
|
|
261
|
+
`),1}}async function zp(t,e,n){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await n(200)}return t.probe(500)}async function Up(t,e,n=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let a=0;a<n;a++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!Ji(u))return;await e(i)}}function $2(t){return new Promise(e=>setTimeout(e,t))}re();function V2(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let n=Number(e[1]),i=Number(e[2]??0);return n<18||n===18&&i<4?"fatal":n<20?"warn":"ok"}function $p(t=process.versions.node,e=i=>{process.stderr.write(i)},n=i=>process.exit(i)){let i=V2(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
|
|
262
|
+
`),n(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
|
|
263
263
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
264
264
|
npx -y coze-bridge@latest stop
|
|
265
265
|
npx -y coze-bridge@latest connect
|
|
266
266
|
|
|
267
|
-
`)}
|
|
267
|
+
`)}$p();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&Ml("warn");Gp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
268
268
|
`),process.exit(1)});
|