coze-bridge 0.1.104-beta.0 → 0.2.0-alpha.0
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 +86 -84
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
|
|
|
5
5
|
const require = __coze_createRequire(import.meta.url);
|
|
6
6
|
const __filename = __coze_fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __coze_dirname(__filename);
|
|
8
|
-
var
|
|
8
|
+
var mg=Object.create;var ba=Object.defineProperty;var wg=Object.getOwnPropertyDescriptor;var _g=Object.getOwnPropertyNames;var yg=Object.getPrototypeOf,bg=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Qe=(t,e)=>()=>(t&&(e=t(t=0)),e);var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ea=(t,e)=>{for(var r in e)ba(t,r,{get:e[r],enumerable:!0})},Eg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _g(e))!bg.call(t,o)&&o!==r&&ba(t,o,{get:()=>e[o],enumerable:!(i=wg(e,o))||i.enumerable});return t};var Ut=(t,e,r)=>(r=t!=null?mg(yg(t)):{},Eg(e||!t||!t.__esModule?ba(r,"default",{value:t,enumerable:!0}):r,t));function Ke(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var ir=Qe(()=>{"use strict"});import{createWriteStream as vg,mkdirSync as Sg,readdirSync as Ig,unlinkSync as Ag}from"node:fs";import{join as gl}from"node:path";function Pn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function sr(t,e){return`${t}-${e}.log`}function va(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function kg(t,e,r){let i=c=>{let[d,u,f]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>r}function as(t,e,r,i){let o;try{o=Ig(t)}catch{return}for(let c of o){let d=va(c,e);if(d&&kg(d,r,i))try{Ag(gl(t,c))}catch{}}}var Qr,Sa=Qe(()=>{"use strict";Qr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Pn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{Sg(this.dir,{recursive:!0});let r=vg(gl(this.dir,sr(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
|
|
9
9
|
`)),this.stream=r}catch(r){process.stderr.write(`[log-sink] rotate failed: ${String(r)}
|
|
10
|
-
`),this.stream=void 0;return}this.currentDate!==void 0&&
|
|
11
|
-
`;
|
|
12
|
-
`;if(
|
|
13
|
-
`),{cause:o})}}async function
|
|
14
|
-
`,r)}var on=Ye(()=>{"use strict"});import{promises as vl,readdirSync as Lg}from"node:fs";import{homedir as Ng}from"node:os";import{sep as Mg,join as Re,resolve as Sl}from"node:path";function ee(t){let e=t??Ng(),r=Re(e,".coze"),i=Re(r,"bridge"),o=Re(i,"lib"),c=Re(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Re(o,"index.js"),binDir:Re(i,"bin"),pidFile:Re(i,"bridge.pid"),portFile:Re(i,"bridge.port"),tokenFile:Re(i,"bridge.token"),patTokenFile:Re(i,"pat-token"),agentEnvFile:Re(i,"agent-env.json"),logFile:Re(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Re(c,"daemon-stdio.log"),installLock:Re(i,"install.lock"),configFile:Re(i,"config.json"),agentsRoot:Re(r,"agents")}}function Xe(t,e=ee()){let r=Re(e.agentsRoot,t);return{root:r,config:Re(r,"config.json"),workspace:Re(r,"workspace"),logs:Re(r,"logs")}}function us(t=ee()){try{return Lg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ti(t,e){let r=await vl.realpath(Sl(t)).catch(()=>null);if(!r)return!1;let i=await vl.realpath(Sl(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+Mg)}var Le=Ye(()=>{"use strict"});var hs={};Ea(hs,{AGENT_CONFIG_FILE_MODE:()=>fs,enforceAgentConfigMode:()=>zg,loadAgentConfig:()=>Be,persistAgentSessions:()=>ni,persistAgentSkills:()=>xs,saveAgentConfig:()=>Qe});import{chmod as Bg,stat as Fg}from"node:fs/promises";function Be(t,e){return or(Xe(t,e).config)}function Qe(t,e){return ar(Xe(t.agentId,e).config,t,{mode:fs})}async function zg(t,e){if(process.platform==="win32")return;let r=Xe(t,e).config;try{let i=await Fg(r);if(!i.isFile())return;let o=i.mode&511;o!==fs&&(await Bg(r,fs),Il.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Il.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ni(t,e,r){let i=await Be(t,r);i&&(i.sessions=Object.fromEntries(e),await Qe(i,r))}async function xs(t,e,r){let i=await Be(t,r);i&&(i.skills=e,await Qe(i,r))}var Il,fs,an=Ye(()=>{"use strict";on();re();Le();Il=q("agent-config"),fs=384});var ka=ce((S2,Cl)=>{Cl.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 gs=ce(kl=>{var Rl={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 Wg(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(Rl))kl[t]=Wg(Rl[t])});var Nl=ce((A2,Ll)=>{var Kg=fe("fs"),Ne=fe("path"),Dl=ka(),$g=gs(),Vg=typeof process=="object"&&process.platform==="win32",Pl=t=>typeof t=="object"&&t!==null,Ol=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 ve(t){this.sep=Ne.sep,this.fs=Kg,Pl(t)&&Pl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ll.exports=ve;ve.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw $g.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};ve.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Ne.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};ve.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,x){if(l&&x.isDirectory())return o(!1);var p=Ne.dirname(t);c.fs.exists(p,function(w){w||c.makeDir(p),c.fs.open(t,"w",438,function(_,I){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,S){c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):I?c.fs.write(I,e,0,e.length,0,function(){c.fs.close(I,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};ve.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let x=Ne.join(i,u),p=e.fs.statSync(x);(!o||o.test(x))&&l.push(Ne.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(x,o,c)))}),l}return r(t,void 0,!0)};ve.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Ne.join(t,u),r.fs.stat(u,function(x,p){if(x)return e(x);p&&(i.push(Ne.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(w,_){if(w)return e(w);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};ve.prototype.getAttributes=function(){};ve.prototype.setAttributes=function(){};ve.crc32update=function(t,e){return Ol[(t^e)&255]^t>>>8};ve.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=ve.crc32update(r,t[i++]);return~r>>>0};ve.methodToString=function(t){switch(t){case Dl.STORED:return"STORED ("+t+")";case Dl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};ve.canonical=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.join(".",e)};ve.zipnamefix=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.posix.join(".",e)};ve.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]};ve.sanitize=function(t,e){t=Ne.resolve(Ne.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Ne.normalize(Ne.join(t,r.slice(i,o).join(Ne.sep)));if(c.indexOf(t)===0)return c}return Ne.normalize(Ne.join(t,Ne.basename(e)))};ve.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};ve.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};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,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};ve.isWin=Vg;ve.crcTable=Ol});var Bl=ce((T2,Ml)=>{var Jg=fe("path");Ml.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=Jg.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 zl=ce((C2,Fl)=>{Fl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var lr=ce((R2,dr)=>{dr.exports=Nl();dr.exports.Constants=ka();dr.exports.Errors=gs();dr.exports.FileAttr=Bl();dr.exports.decoder=zl()});var ql=ce((k2,Ul)=>{var cn=lr(),z=cn.Constants;Ul.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,x=0,p=0,w=0,_=0,I=0,y=0,S=0;t|=cn.isWin?2560:768,r|=z.FLG_EFS;let A={extraLen:0},T=E=>Math.max(0,E)>>>0,R=E=>Math.max(0,E)&65535,P=E=>Math.max(0,E)&255;return o=cn.fromDate2DOS(new Date),{get made(){return t},set made(E){t=E},get version(){return e},set version(E){e=E},get flags(){return r},set flags(E){r=E},get flags_efs(){return(r&z.FLG_EFS)>0},set flags_efs(E){E?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(E){E?r|=z.FLG_DESC:r&=~z.FLG_DESC},get method(){return i},set method(E){switch(E){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=E},get time(){return cn.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=cn.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=T(E)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(E){c=T(E)},get compressedSize(){return l},set compressedSize(E){l=T(E)},get size(){return u},set size(E){u=T(E)},get fileNameLength(){return x},set fileNameLength(E){x=E},get extraLength(){return p},set extraLength(E){p=E},get extraLocalLength(){return A.extraLen},set extraLocalLength(E){A.extraLen=E},get commentLength(){return w},set commentLength(E){w=E},get diskNumStart(){return _},set diskNumStart(E){_=T(E)},get inAttr(){return I},set inAttr(E){I=T(E)},get attr(){return y},set attr(E){y=T(E)},get fileAttr(){return(y||0)>>16&4095},get offset(){return S},set offset(E){S=T(E)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+x+p+w},get realDataOffset(){return S+z.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(E){var k=E.slice(S,S+z.LOCHDR);if(k.readUInt32LE(0)!==z.LOCSIG)throw cn.Errors.INVALID_LOC();A.version=k.readUInt16LE(z.LOCVER),A.flags=k.readUInt16LE(z.LOCFLG),A.flags_desc=(A.flags&z.FLG_DESC)>0,A.method=k.readUInt16LE(z.LOCHOW),A.time=k.readUInt32LE(z.LOCTIM),A.crc=k.readUInt32LE(z.LOCCRC),A.compressedSize=k.readUInt32LE(z.LOCSIZ),A.size=k.readUInt32LE(z.LOCLEN),A.fnameLen=k.readUInt16LE(z.LOCNAM),A.extraLen=k.readUInt16LE(z.LOCEXT);let O=S+z.LOCHDR+A.fnameLen,F=O+A.extraLen;return E.slice(O,F)},loadFromBinary:function(E){if(E.length!==z.CENHDR||E.readUInt32LE(0)!==z.CENSIG)throw cn.Errors.INVALID_CEN();t=E.readUInt16LE(z.CENVEM),e=E.readUInt16LE(z.CENVER),r=E.readUInt16LE(z.CENFLG),i=E.readUInt16LE(z.CENHOW),o=E.readUInt32LE(z.CENTIM),c=E.readUInt32LE(z.CENCRC),l=E.readUInt32LE(z.CENSIZ),u=E.readUInt32LE(z.CENLEN),x=E.readUInt16LE(z.CENNAM),p=E.readUInt16LE(z.CENEXT),w=E.readUInt16LE(z.CENCOM),_=E.readUInt16LE(z.CENDSK),I=E.readUInt16LE(z.CENATT),y=E.readUInt32LE(z.CENATX),S=E.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(z.LOCHDR);return E.writeUInt32LE(z.LOCSIG,0),E.writeUInt16LE(e,z.LOCVER),E.writeUInt16LE(r,z.LOCFLG),E.writeUInt16LE(i,z.LOCHOW),E.writeUInt32LE(o,z.LOCTIM),E.writeUInt32LE(c,z.LOCCRC),E.writeUInt32LE(l,z.LOCSIZ),E.writeUInt32LE(u,z.LOCLEN),E.writeUInt16LE(x,z.LOCNAM),E.writeUInt16LE(A.extraLen,z.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(z.CENHDR+x+p+w);return E.writeUInt32LE(z.CENSIG,0),E.writeUInt16LE(t,z.CENVEM),E.writeUInt16LE(e,z.CENVER),E.writeUInt16LE(r,z.CENFLG),E.writeUInt16LE(i,z.CENHOW),E.writeUInt32LE(o,z.CENTIM),E.writeUInt32LE(c,z.CENCRC),E.writeUInt32LE(l,z.CENSIZ),E.writeUInt32LE(u,z.CENLEN),E.writeUInt16LE(x,z.CENNAM),E.writeUInt16LE(p,z.CENEXT),E.writeUInt16LE(w,z.CENCOM),E.writeUInt16LE(_,z.CENDSK),E.writeUInt16LE(I,z.CENATT),E.writeUInt32LE(y,z.CENATX),E.writeUInt32LE(S,z.CENOFF),E},toJSON:function(){let E=function(k){return k+" bytes"};return{made:t,version:e,flags:r,method:cn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(l),size:E(u),fileNameLength:E(x),extraLength:E(p),commentLength:E(w),diskNumStart:_,inAttr:I,attr:y,offset:S,centralHeaderSize:E(z.CENHDR+x+p+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Hl=ce((D2,Gl)=>{var ur=lr(),ye=ur.Constants;Gl.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 ye.ENDHDR+o},loadFromBinary:function(c){if((c.length!==ye.ENDHDR||c.readUInt32LE(0)!==ye.ENDSIG)&&(c.length<ye.ZIP64HDR||c.readUInt32LE(0)!==ye.ZIP64SIG))throw ur.Errors.INVALID_END();c.readUInt32LE(0)===ye.ENDSIG?(t=c.readUInt16LE(ye.ENDSUB),e=c.readUInt16LE(ye.ENDTOT),r=c.readUInt32LE(ye.ENDSIZ),i=c.readUInt32LE(ye.ENDOFF),o=c.readUInt16LE(ye.ENDCOM)):(t=ur.readBigUInt64LE(c,ye.ZIP64SUB),e=ur.readBigUInt64LE(c,ye.ZIP64TOT),r=ur.readBigUInt64LE(c,ye.ZIP64SIZE),i=ur.readBigUInt64LE(c,ye.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(ye.ENDHDR+o);return c.writeUInt32LE(ye.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,ye.ENDSUB),c.writeUInt16LE(e,ye.ENDTOT),c.writeUInt32LE(r,ye.ENDSIZ),c.writeUInt32LE(i,ye.ENDOFF),c.writeUInt16LE(o,ye.ENDCOM),c.fill(" ",ye.ENDHDR),c},toJSON:function(){let c=function(l,u){let x=l.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Pa=ce(Da=>{Da.EntryHeader=ql();Da.MainHeader=Hl()});var Wl=ce((O2,jl)=>{jl.exports=function(t){var e=fe("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),x=0;u.fill(0);for(var p=0;p<c.length;p++){var w=c[p];w.copy(u,x),x+=w.length}i&&i(u)}),o.end(t)}}}});var $l=ce((L2,Kl)=>{var Zg=+(process.versions?process.versions.node:"").split(".")[0]||0;Kl.exports=function(t,e){var r=fe("zlib");let i=Zg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(x){l.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),p=0;x.fill(0);for(var w=0;w<l.length;w++){var _=l[w];_.copy(x,p),p+=_.length}o&&o(x)}),c.end(t)}}}});var Xl=ce((N2,Yl)=>{"use strict";var{randomFillSync:Vl}=fe("crypto"),Yg=gs(),Xg=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}),Zl=(t,e)=>Math.imul(t,e)>>>0,Jl=(t,e)=>Xg[(t^e)&255]^t>>>8,ri=()=>typeof Vl=="function"?Vl(Buffer.alloc(12)):ri.node();ri.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 ms={genSalt:ri};function ws(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])}ws.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Jl(e[0],t),e[1]+=e[0]&255,e[1]=Zl(e[1],134775813)+1,e[2]=Jl(e[2],e[1]>>>24),t};ws.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Zl(t,t^1)>>8&255};function Qg(t){let e=new ws(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 em(t){let e=new ws(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function tm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Qg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Yg.WRONG_PASSWORD();return i(t.slice(12))}function nm(t){Buffer.isBuffer(t)&&t.length>=12?ms.genSalt=function(){return t.slice(0,12)}:t==="node"?ms.genSalt=ri.node:ms.genSalt=ri}function rm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=em(r),c=ms.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}Yl.exports={decrypt:tm,encrypt:rm,_salter:nm}});var Ql=ce(_s=>{_s.Deflater=Wl();_s.Inflater=$l();_s.ZipCrypto=Xl()});var La=ce((B2,eu)=>{var de=lr(),im=Pa(),Se=de.Constants,Oa=Ql();eu.exports=function(t,e){var r=new im.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let w=t,_=typeof w.decoder=="object"?w.decoder:de.decoder;p=_.hasOwnProperty("efs")?_.efs:!1;function I(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function y(E){if(!r.flags_desc&&!r.localHeader.flags_desc){if(de.crc32(E)!==r.localHeader.crc)return!1}else{let k={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==Se.LOCSIG||e.readUInt32LE(O)==Se.CENSIG)throw de.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==Se.EXTSIG)k.crc=e.readUInt32LE(O+Se.EXTCRC),k.compressedSize=e.readUInt32LE(O+Se.EXTSIZ),k.size=e.readUInt32LE(O+Se.EXTLEN);else if(e.readUInt16LE(O+12)===19280)k.crc=e.readUInt32LE(O+Se.EXTCRC-4),k.compressedSize=e.readUInt32LE(O+Se.EXTSIZ-4),k.size=e.readUInt32LE(O+Se.EXTLEN-4);else throw de.Errors.DESCRIPTOR_UNKNOWN();if(k.compressedSize!==r.compressedSize||k.size!==r.size||k.crc!==r.crc)throw de.Errors.DESCRIPTOR_FAULTY();if(de.crc32(E)!==k.crc)return!1}return!0}function S(E,k,O){if(typeof k>"u"&&typeof E=="string"&&(O=E,E=void 0),c)return E&&k&&k(Buffer.alloc(0),de.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=I();if(F.length===0)return E&&k&&k(F),F;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw de.Errors.INVALID_PASS_PARAM();F=Oa.ZipCrypto.decrypt(F,r,O)}var B=Buffer.alloc(r.size);switch(r.method){case de.Constants.STORED:if(F.copy(B),y(B))return E&&k&&k(B),B;throw E&&k&&k(B,de.Errors.BAD_CRC()),de.Errors.BAD_CRC();case de.Constants.DEFLATED:var V=new Oa.Inflater(F,r.size);if(E)V.inflateAsync(function($){$.copy($,0),k&&(y($)?k($):k($,de.Errors.BAD_CRC()))});else{if(V.inflate(B).copy(B,0),!y(B))throw de.Errors.BAD_CRC(`"${_.decode(i)}"`);return B}break;default:throw E&&k&&k(Buffer.alloc(0),de.Errors.UNKNOWN_METHOD()),de.Errors.UNKNOWN_METHOD()}}function A(E,k){if((!l||!l.length)&&Buffer.isBuffer(e))return E&&k&&k(I()),I();if(l.length&&!c){var O;switch(r.method){case de.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(l.length),l.copy(O),E&&k&&k(O),O;default:case de.Constants.DEFLATED:var F=new Oa.Deflater(l);if(E)F.deflateAsync(function(V){O=Buffer.alloc(V.length),r.compressedSize=V.length,V.copy(O),k&&k(O)});else{var B=F.deflate();return r.compressedSize=B.length,B}F=null;break}}else if(E&&k)k(Buffer.alloc(0));else return Buffer.alloc(0)}function T(E,k){return de.readBigUInt64LE(E,k)}function R(E){try{for(var k=0,O,F,B;k+4<E.length;)O=E.readUInt16LE(k),k+=2,F=E.readUInt16LE(k),k+=2,B=E.slice(k,k+F),k+=F,Se.ID_ZIP64===O&&P(B)}catch{throw de.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(E){var k,O,F,B;E.length>=Se.EF_ZIP64_SCOMP&&(k=T(E,Se.EF_ZIP64_SUNCOMP),r.size===Se.EF_ZIP64_OR_32&&(r.size=k)),E.length>=Se.EF_ZIP64_RHO&&(O=T(E,Se.EF_ZIP64_SCOMP),r.compressedSize===Se.EF_ZIP64_OR_32&&(r.compressedSize=O)),E.length>=Se.EF_ZIP64_DSN&&(F=T(E,Se.EF_ZIP64_RHO),r.offset===Se.EF_ZIP64_OR_32&&(r.offset=F)),E.length>=Se.EF_ZIP64_DSN+4&&(B=E.readUInt32LE(Se.EF_ZIP64_DSN),r.diskNumStart===Se.EF_ZIP64_OR_16&&(r.diskNumStart=B))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(E){i=de.toBuffer(E,_.encode);var k=i[i.length-1];c=k===47||k===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return u},set extra(E){u=E,r.extraLength=E.length,R(E)},get comment(){return _.decode(o)},set comment(E){if(o=de.toBuffer(E,_.encode),r.commentLength=o.length,o.length>65535)throw de.Errors.COMMENT_TOO_LONG()},get name(){var E=_.decode(i);return c?E.substr(E.length-1).split("/").pop():E.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(E){A(!0,E)},setData:function(E){l=de.toBuffer(E,de.decoder.encode),!c&&l.length?(r.size=l.length,r.method=de.Constants.DEFLATED,r.crc=de.crc32(E),r.changed=!0):r.method=de.Constants.STORED},getData:function(E){return r.changed?l:S(!1,null,E)},getDataAsync:function(E,k){r.changed?E(l):S(!0,E,k)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var E=r.centralHeaderToBinary(),k=de.Constants.CENHDR;return i.copy(E,k),k+=i.length,u.copy(E,k),k+=r.extraLength,o.copy(E,k),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let k=r.localHeaderToBinary(),O=Buffer.alloc(k.length+i.length+r.extraLocalLength);return k.copy(O,E),E+=k.length,i.copy(O,E),E+=i.length,x.copy(O,E),E+=x.length,O},toJSON:function(){let E=function(k){return"<"+(k&&k.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:E(e),data:E(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ru=ce((F2,nu)=>{var tu=La(),sm=Pa(),je=lr();nu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new sm.MainHeader,l=!1,u=null;let x=new Set,p=e,{noSort:w,decoder:_}=p;t?S(p.readEntries):l=!0;function I(){let T=new Set;for(let R of Object.keys(i)){let P=R.split("/");if(P.pop(),!!P.length)for(let E=0;E<P.length;E++){let k=P.slice(0,E+1).join("/")+"/";T.add(k)}}for(let R of T)if(!(R in i)){let P=new tu(p);P.entryName=R,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,x.add(P)}}function y(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var T=c.offset,R=0;R<r.length;R++){var P=T,E=new tu(p,t);E.header=t.slice(P,P+=je.Constants.CENHDR),E.entryName=t.slice(P,P+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(P,P+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(P,P+E.header.commentLength)),T+=E.header.centralHeaderSize,r[R]=E,i[E.entryName]=E}x.clear(),I()}function S(T){var R=t.length-je.Constants.ENDHDR,P=Math.max(0,R-65535),E=P,k=t.length,O=-1,F=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(P=0),R;R>=E;R--)if(t[R]===80){if(t.readUInt32LE(R)===je.Constants.ENDSIG){O=R,F=R,k=R+je.Constants.ENDHDR,E=R-je.Constants.END64HDR;continue}if(t.readUInt32LE(R)===je.Constants.END64SIG){E=P;continue}if(t.readUInt32LE(R)===je.Constants.ZIP64SIG){O=R,k=R+je.readBigUInt64LE(t,R+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(O==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,k)),c.commentLength&&(o=t.slice(F+je.Constants.ENDHDR)),T&&y()}function A(){r.length>1&&!w&&r.sort((T,R)=>T.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||y(),r.filter(T=>!x.has(T))},get comment(){return _.decode(o)},set comment(T){o=je.toBuffer(T,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(T){this.entries.forEach(T)},getEntry:function(T){return l||y(),i[T]||null},setEntry:function(T){l||y(),r.push(T),i[T.entryName]=T,c.totalEntries=r.length},deleteFile:function(T,R=!0){l||y();let P=i[T];this.getEntryChildren(P,R).map(k=>k.entryName).forEach(this.deleteEntry)},deleteEntry:function(T){l||y();let R=i[T],P=r.indexOf(R);P>=0&&(r.splice(P,1),delete i[T],c.totalEntries=r.length)},getEntryChildren:function(T,R=!0){if(l||y(),typeof T=="object")if(T.isDirectory&&R){let P=[],E=T.entryName;for(let k of r)k.entryName.startsWith(E)&&P.push(k);return P}else return[T];return[]},getChildCount:function(T){if(T&&T.isDirectory){let R=this.getEntryChildren(T);return R.includes(T)?R.length-1:R.length}return 0},compressToBuffer:function(){l||y(),A();let T=[],R=[],P=0,E=0;c.size=0,c.offset=0;let k=0;for(let B of this.entries){let V=B.getCompressedData();B.header.offset=E;let $=B.packLocalHeader(),ne=$.length+V.length;E+=ne,T.push($),T.push(V);let Z=B.packCentralHeader();R.push(Z),c.size+=Z.length,P+=ne+Z.length,k++}P+=c.mainHeaderSize,c.offset=E,c.totalEntries=k,E=0;let O=Buffer.alloc(P);for(let B of T)B.copy(O,E),E+=B.length;for(let B of R)B.copy(O,E),E+=B.length;let F=c.toBinary();return o&&o.copy(F,je.Constants.ENDHDR),F.copy(O,E),t=O,l=!1,O},toAsyncBuffer:function(T,R,P,E){try{l||y(),A();let k=[],O=[],F=0,B=0,V=0;c.size=0,c.offset=0;let $=function(ne){if(ne.length>0){let Z=ne.shift(),se=Z.entryName+Z.extra.toString();P&&P(se),Z.getCompressedDataAsync(function(ae){E&&E(se),Z.header.offset=B;let L=Z.packLocalHeader(),G=L.length+ae.length;B+=G,k.push(L),k.push(ae);let K=Z.packCentralHeader();O.push(K),c.size+=K.length,F+=G+K.length,V++,$(ne)})}else{F+=c.mainHeaderSize,c.offset=B,c.totalEntries=V,B=0;let Z=Buffer.alloc(F);k.forEach(function(ae){ae.copy(Z,B),B+=ae.length}),O.forEach(function(ae){ae.copy(Z,B),B+=ae.length});let se=c.toBinary();o&&o.copy(se,je.Constants.ENDHDR),se.copy(Z,B),t=Z,l=!1,T(Z)}};$(Array.from(this.entries))}catch(k){R(k)}}}}});var ou=ce((z2,su)=>{var be=lr(),Ee=fe("path"),om=La(),am=ru(),Dn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),iu=(...t)=>be.findLast(t,e=>typeof e=="string"),cm=(...t)=>be.findLast(t,e=>typeof e=="function"),dm={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};su.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),dm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=be.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new be(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=be.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=be.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw be.Errors.INVALID_FILENAME();let c=new am(r,i),{canonical:l,sanitize:u,zipnamefix:x}=be;function p(y){if(y&&c){var S;if(typeof y=="string"&&(S=c.getEntry(Ee.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(S=c.getEntry(y.entryName)),S)return S}return null}function w(y){let{join:S,normalize:A,sep:T}=Ee.posix;return S(Ee.isAbsolute(y)?"/":".",A(T+y.split("\\").join(T)+T))}function _(y){return y instanceof RegExp?(function(S){return function(A){return S.test(A)}})(y):typeof y!="function"?()=>!0:y}let I=(y,S)=>{let A=S.slice(-1);return A=A===o.sep?o.sep:"",Ee.relative(y,S)+A};return{readFile:function(y,S){var A=p(y);return A&&A.getData(S)||null},childCount:function(y){let S=p(y);if(S)return c.getChildCount(S)},readFileAsync:function(y,S){var A=p(y);A?A.getDataAsync(S):S(null,"getEntry failed for:"+y)},readAsText:function(y,S){var A=p(y);if(A){var T=A.getData();if(T&&T.length)return T.toString(S||"utf8")}return""},readAsTextAsync:function(y,S,A){var T=p(y);T?T.getDataAsync(function(R,P){if(P){S(R,P);return}R&&R.length?S(R.toString(A||"utf8")):S("")}):S("")},deleteFile:function(y,S=!0){var A=p(y);A&&c.deleteFile(A.entryName,S)},deleteEntry:function(y){var S=p(y);S&&c.deleteEntry(S.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,S){var A=p(y);A&&(A.comment=S)},getZipEntryComment:function(y){var S=p(y);return S&&S.comment||""},updateFile:function(y,S){var A=p(y);A&&A.setData(S)},addLocalFile:function(y,S,A,T){if(o.fs.existsSync(y)){S=S?w(S):"";let R=Ee.win32.basename(Ee.win32.normalize(y));S+=A||R;let P=o.fs.statSync(y),E=P.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);P.isDirectory()&&(S+=o.sep),this.addFile(S,E,T,P)}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,S){y=typeof y=="object"?y:{localPath:y};let A=Ee.resolve(y.localPath),{comment:T}=y,{zipPath:R,zipName:P}=y,E=this;o.fs.stat(A,function(k,O){if(k)return S(k,!1);R=R?w(R):"";let F=Ee.win32.basename(Ee.win32.normalize(A));if(R+=P||F,O.isFile())o.fs.readFile(A,function(B,V){return B?S(B,!1):(E.addFile(R,V,T,O),setImmediate(S,void 0,!0))});else if(O.isDirectory())return R+=o.sep,E.addFile(R,Buffer.alloc(0),T,O),setImmediate(S,void 0,!0)})},addLocalFolder:function(y,S,A){if(A=_(A),S=S?w(S):"",y=Ee.normalize(y),o.fs.existsSync(y)){let T=o.findFiles(y),R=this;if(T.length)for(let P of T){let E=Ee.join(S,I(y,P));A(E)&&R.addLocalFile(P,Ee.dirname(E))}}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,S,A,T){T=_(T),A=A?w(A):"",y=Ee.normalize(y);var R=this;o.fs.open(y,"r",function(P){if(P&&P.code==="ENOENT")S(void 0,be.Errors.FILE_NOT_FOUND(y));else if(P)S(void 0,P);else{var E=o.findFiles(y),k=-1,O=function(){if(k+=1,k<E.length){var F=E[k],B=I(y,F).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),T(B)?o.fs.stat(F,function(V,$){V&&S(void 0,V),$.isFile()?o.fs.readFile(F,function(ne,Z){ne?S(void 0,ne):(R.addFile(A+B,Z,"",$),O())}):(R.addFile(A+B+"/",Buffer.alloc(0),"",$),O())}):process.nextTick(()=>{O()})}else S(!0,void 0)};O()}})},addLocalFolderAsync2:function(y,S){let A=this;y=typeof y=="object"?y:{localPath:y},localPath=Ee.resolve(w(y.localPath));let{zipPath:T,filter:R,namefix:P}=y;R instanceof RegExp?R=(function(O){return function(F){return O.test(F)}})(R):typeof R!="function"&&(R=function(){return!0}),T=T?w(T):"",P=="latin1"&&(P=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=O=>O);let E=O=>Ee.join(T,P(I(localPath,O))),k=O=>Ee.win32.basename(Ee.win32.normalize(P(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?S(void 0,be.Errors.FILE_NOT_FOUND(localPath)):O?S(void 0,O):o.findFilesAsync(localPath,function(F,B){if(F)return S(F);B=B.filter(V=>R(E(V))),B.length||S(void 0,!1),setImmediate(B.reverse().reduce(function(V,$){return function(ne,Z){if(ne||Z===!1)return setImmediate(V,ne,!1);A.addLocalFileAsync({localPath:$,zipPath:Ee.dirname(E($)),zipName:k($)},V)}},S))})})},addLocalFolderPromise:function(y,S){return new Promise((A,T)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},S),(R,P)=>{R&&T(R),P&&A(this)})})},addFile:function(y,S,A,T){y=x(y);let R=p(y),P=R!=null;P||(R=new om(i),R.entryName=y),R.comment=A||"";let E=typeof T=="object"&&T instanceof o.fs.Stats;E&&(R.header.time=T.mtime);var k=R.isDirectory?16:0;let O=R.isDirectory?16384:32768;return E?O|=4095&T.mode:typeof T=="number"?O|=4095&T:O|=R.isDirectory?493:420,k=(k|O<<16)>>>0,R.attr=k,R.setData(S),P||c.setEntry(R),R},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return p(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,S,A,T,R,P){T=Dn(!1,T),R=Dn(!1,R),A=Dn(!0,A),P=iu(R,P);var E=p(y);if(!E)throw be.Errors.NO_ENTRY();var k=l(E.entryName),O=u(S,P&&!E.isDirectory?P:A?k:Ee.basename(k));if(E.isDirectory){var F=c.getEntryChildren(E);return F.forEach(function($){if($.isDirectory)return;var ne=$.getData();if(!ne)throw be.Errors.CANT_EXTRACT_FILE();var Z=l($.entryName),se=u(S,A?Z:Ee.basename(Z));let ae=R?$.header.fileAttr:void 0;o.writeFileTo(se,ne,T,ae)}),!0}var B=E.getData(c.password);if(!B)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!T)throw be.Errors.CANT_OVERRIDE();let V=R?y.header.fileAttr:void 0;return o.writeFileTo(O,B,T,V),!0},test:function(y){if(!c)return!1;for(var S in c.entries)try{if(S.isDirectory)continue;var A=c.entries[S].getData(y);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(y,S,A,T){if(A=Dn(!1,A),T=iu(A,T),S=Dn(!1,S),!c)throw be.Errors.NO_ZIP();c.entries.forEach(function(R){var P=u(y,l(R.entryName));if(R.isDirectory){o.makeDir(P);return}var E=R.getData(T);if(!E)throw be.Errors.CANT_EXTRACT_FILE();let k=A?R.header.fileAttr:void 0;o.writeFileTo(P,E,S,k);try{o.fs.utimesSync(P,R.header.time,R.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,S,A,T){if(T=cm(S,A,T),A=Dn(!1,A),S=Dn(!1,S),!T)return new Promise((O,F)=>{this.extractAllToAsync(y,S,A,function(B){B?F(B):O(this)})});if(!c){T(be.Errors.NO_ZIP());return}y=Ee.resolve(y);let R=O=>u(y,Ee.normalize(l(O.entryName))),P=(O,F)=>new Error(O+': "'+F+'"'),E=[],k=[];c.entries.forEach(O=>{O.isDirectory?E.push(O):k.push(O)});for(let O of E){let F=R(O),B=A?O.header.fileAttr:void 0;try{o.makeDir(F),B&&o.fs.chmodSync(F,B),o.fs.utimesSync(F,O.header.time,O.header.time)}catch{T(P("Unable to create folder",F))}}k.reverse().reduce(function(O,F){return function(B){if(B)O(B);else{let V=Ee.normalize(l(F.entryName)),$=u(y,V);F.getDataAsync(function(ne,Z){if(Z)O(Z);else if(!ne)O(be.Errors.CANT_EXTRACT_FILE());else{let se=A?F.header.fileAttr:void 0;o.writeFileToAsync($,ne,S,se,function(ae){ae||O(P("Unable to write file",$)),o.fs.utimes($,F.header.time,F.header.time,function(L){L?O(P("Unable to set times",$)):O()})})}})}}},T)()},writeZip:function(y,S){if(arguments.length===1&&typeof y=="function"&&(S=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var A=c.compressToBuffer();if(A){var T=o.writeFileTo(y,A,!0);typeof S=="function"&&S(T?null:new Error("failed"),"")}}},writeZipPromise:function(y,S){let{overwrite:A,perm:T}=Object.assign({overwrite:!0},S);return new Promise((R,P)=>{!y&&i.filename&&(y=i.filename),y||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let k=O=>O?R(O):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,E,A,T,k)},P)})},toBufferPromise:function(){return new Promise((y,S)=>{c.toAsyncBuffer(y,S)})},toBuffer:function(y,S,A,T){return typeof y=="function"?(c.toAsyncBuffer(y,S,A,T),null):c.compressToBuffer()}}}});import{execFile as p_,spawn as g_,spawnSync as rA}from"node:child_process";import{promisify as m_}from"node:util";function __(t){if(process.platform!=="win32")return!1;if(Af.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Af,"").toLowerCase();return w_.has(r)}function Tf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return __(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function nt(t,e=[],r={}){return g_(t,e,Tf(t,r))}function Cf(t,e=[],r={}){return y_(t,e,Tf(t,r))}var w_,Af,y_,Wt=Ye(()=>{"use strict";w_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Af=/\.(cmd|bat|ps1)$/i;y_=m_(p_)});var $t=ce((LR,rx)=>{"use strict";var tx=["nodebuffer","arraybuffer","fragments"],nx=typeof Blob<"u";nx&&tx.push("blob");rx.exports={BINARY_TYPES:tx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:nx,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ji=ce((NR,Io)=>{"use strict";var{EMPTY_BUFFER:Y1}=$t(),ad=Buffer[Symbol.species];function X1(t,e){if(t.length===0)return Y1;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new ad(r.buffer,r.byteOffset,i):r}function ix(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function sx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function Q1(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function cd(t){if(cd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ad(t):ArrayBuffer.isView(t)?e=new ad(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),cd.readOnly=!1),e}Io.exports={concat:X1,mask:ix,toArrayBuffer:Q1,toBuffer:cd,unmask:sx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=fe("bufferutil");Io.exports.mask=function(e,r,i,o,c){c<48?ix(e,r,i,o,c):t.mask(e,r,i,o,c)},Io.exports.unmask=function(e,r){e.length<32?sx(e,r):t.unmask(e,r)}}catch{}});var cx=ce((MR,ax)=>{"use strict";var ox=Symbol("kDone"),dd=Symbol("kRun"),ld=class{constructor(e){this[ox]=()=>{this.pending--,this[dd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[dd]()}[dd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[ox])}}};ax.exports=ld});var Br=ce((BR,fx)=>{"use strict";var Wi=fe("zlib"),dx=ji(),eE=cx(),{kStatusCode:lx}=$t(),tE=Buffer[Symbol.species],nE=Buffer.from([0,0,255,255]),To=Symbol("permessage-deflate"),Vt=Symbol("total-length"),Nr=Symbol("callback"),An=Symbol("buffers"),Mr=Symbol("error"),Ao,ud=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!Ao){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ao=new eE(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[Nr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Ao.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Ao.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Wi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[To]=this,this._inflate[Vt]=0,this._inflate[An]=[],this._inflate.on("error",iE),this._inflate.on("data",ux)}this._inflate[Nr]=i,this._inflate.write(e),r&&this._inflate.write(nE),this._inflate.flush(()=>{let c=this._inflate[Mr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=dx.concat(this._inflate[An],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[An]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Wi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[An]=[],this._deflate.on("data",rE)}this._deflate[Nr]=i,this._deflate.write(e),this._deflate.flush(Wi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=dx.concat(this._deflate[An],this._deflate[Vt]);r&&(c=new tE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Nr]=null,this._deflate[Vt]=0,this._deflate[An]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};fx.exports=ud;function rE(t){this[An].push(t),this[Vt]+=t.length}function ux(t){if(this[Vt]+=t.length,this[To]._maxPayload<1||this[Vt]<=this[To]._maxPayload){this[An].push(t);return}this[Mr]=new RangeError("Max payload size exceeded"),this[Mr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Mr][lx]=1009,this.removeListener("data",ux),this.reset()}function iE(t){if(this[To]._inflate=null,this[Mr]){this[Nr](this[Mr]);return}t[lx]=1007,this[Nr](t)}});var Fr=ce((FR,Co)=>{"use strict";var{isUtf8:xx}=fe("buffer"),{hasBlob:sE}=$t(),oE=[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 aE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function fd(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function cE(t){return sE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Co.exports={isBlob:cE,isValidStatusCode:aE,isValidUTF8:fd,tokenChars:oE};if(xx)Co.exports.isValidUTF8=function(t){return t.length<24?fd(t):xx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=fe("utf-8-validate");Co.exports.isValidUTF8=function(e){return e.length<32?fd(e):t(e)}}catch{}});var md=ce((zR,Ex)=>{"use strict";var{Writable:dE}=fe("stream"),hx=Br(),{BINARY_TYPES:lE,EMPTY_BUFFER:px,kStatusCode:uE,kWebSocket:fE}=$t(),{concat:xd,toArrayBuffer:xE,unmask:hE}=ji(),{isValidStatusCode:pE,isValidUTF8:gx}=Fr(),Ro=Buffer[Symbol.species],lt=0,mx=1,_x=2,yx=3,hd=4,pd=5,ko=6,gd=class extends dE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||lE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[fE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=lt}_write(e,r,i){if(this._opcode===8&&this._state==lt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Ro(i.buffer,i.byteOffset+e,i.length-e),new Ro(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 Ro(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case lt:this.getInfo(e);break;case mx:this.getPayloadLength16(e);break;case _x:this.getPayloadLength64(e);break;case yx:this.getMask();break;case hd:this.getData(e);break;case pd: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[hx.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=mx:this._payloadLength===127?this._state=_x: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=yx:this._state=hd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=hd}getData(e){let r=px;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&hE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=pd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[hx.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===lt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=lt;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=xd(i,r):this._binaryType==="arraybuffer"?o=xE(xd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=xd(i,r);if(!this._skipUTF8Validation&&!gx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===pd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit("message",o,!1),this._state=lt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,px),this.end();else{let i=e.readUInt16BE(0);if(!pE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Ro(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!gx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=lt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=lt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[uE]=o,l}};Ex.exports=gd});var yd=ce((qR,Sx)=>{"use strict";var{Duplex:UR}=fe("stream"),{randomFillSync:gE}=fe("crypto"),{types:{isUint8Array:mE}}=fe("util"),bx=Br(),{EMPTY_BUFFER:wE,kWebSocket:_E,NOOP:yE}=$t(),{isBlob:zr,isValidStatusCode:EE}=Fr(),{mask:vx,toBuffer:Kn}=ji(),ut=Symbol("kByteLength"),bE=Buffer.alloc(4),Do=8*1024,$n,Ur=Do,bt=0,vE=1,SE=2,wd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=bt,this.onerror=yE,this[_E]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||bE,r.generateMask?r.generateMask(i):(Ur===Do&&($n===void 0&&($n=Buffer.alloc(Do)),gE($n,0,Do),Ur=0),i[0]=$n[Ur++],i[1]=$n[Ur++],i[2]=$n[Ur++],i[3]=$n[Ur++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?u=r[ut]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let p=Buffer.allocUnsafe(o?u+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=x,x===126?p.writeUInt16BE(u,2):x===127&&(p[2]=p[3]=0,p.writeUIntBE(u,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],l?[p,e]:o?(vx(e,i,p,c,u),[p]):(vx(e,i,e,0,u),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=wE;else{if(typeof e!="number"||!EE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(mE(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ut]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==bt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):zr(e)?(o=e.size,c=!1):(e=Kn(e),o=e.length,c=Kn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};zr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):zr(e)?(o=e.size,c=!1):(e=Kn(e),o=e.length,c=Kn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};zr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[bx.extensionName],c=r.binary?2:1,l=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):zr(e)?(u=e.size,x=!1):(e=Kn(e),u=e.length,x=Kn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[ut]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};zr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==bt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ut],this._state=SE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(_d,this,u,o);return}this._bufferedBytes-=i[ut];let l=Kn(c);r?this.dispatch(l,r,i,o):(this._state=bt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(IE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[bx.extensionName];this._bufferedBytes+=i[ut],this._state=vE,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");_d(this,x,o);return}this._bufferedBytes-=i[ut],this._state=bt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===bt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ut],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ut],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Sx.exports=wd;function _d(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function IE(t,e,r){_d(t,e,r),t.onerror(e)}});var Ox=ce((GR,Px)=>{"use strict";var{kForOnEventAttribute:Ki,kListener:Ed}=$t(),Ix=Symbol("kCode"),Ax=Symbol("kData"),Tx=Symbol("kError"),Cx=Symbol("kMessage"),Rx=Symbol("kReason"),qr=Symbol("kTarget"),kx=Symbol("kType"),Dx=Symbol("kWasClean"),Jt=class{constructor(e){this[qr]=null,this[kx]=e}get target(){return this[qr]}get type(){return this[kx]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var Vn=class extends Jt{constructor(e,r={}){super(e),this[Ix]=r.code===void 0?0:r.code,this[Rx]=r.reason===void 0?"":r.reason,this[Dx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Ix]}get reason(){return this[Rx]}get wasClean(){return this[Dx]}};Object.defineProperty(Vn.prototype,"code",{enumerable:!0});Object.defineProperty(Vn.prototype,"reason",{enumerable:!0});Object.defineProperty(Vn.prototype,"wasClean",{enumerable:!0});var Gr=class extends Jt{constructor(e,r={}){super(e),this[Tx]=r.error===void 0?null:r.error,this[Cx]=r.message===void 0?"":r.message}get error(){return this[Tx]}get message(){return this[Cx]}};Object.defineProperty(Gr.prototype,"error",{enumerable:!0});Object.defineProperty(Gr.prototype,"message",{enumerable:!0});var $i=class extends Jt{constructor(e,r={}){super(e),this[Ax]=r.data===void 0?null:r.data}get data(){return this[Ax]}};Object.defineProperty($i.prototype,"data",{enumerable:!0});var AE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ki]&&o[Ed]===e&&!o[Ki])return;let i;if(t==="message")i=function(c,l){let u=new $i("message",{data:l?c:c.toString()});u[qr]=this,Po(e,this,u)};else if(t==="close")i=function(c,l){let u=new Vn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[qr]=this,Po(e,this,u)};else if(t==="error")i=function(c){let l=new Gr("error",{error:c,message:c.message});l[qr]=this,Po(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[qr]=this,Po(e,this,c)};else return;i[Ki]=!!r[Ki],i[Ed]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ed]===e&&!r[Ki]){this.removeListener(t,r);break}}};Px.exports={CloseEvent:Vn,ErrorEvent:Gr,Event:Jt,EventTarget:AE,MessageEvent:$i};function Po(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Oo=ce((HR,Lx)=>{"use strict";var{tokenChars:Vi}=Fr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function TE(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,x=-1,p=-1,w=-1,_=0;for(;_<t.length;_++)if(p=t.charCodeAt(_),l===void 0)if(w===-1&&Vi[p]===1)x===-1&&(x=_);else if(_!==0&&(p===32||p===9))w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let y=t.slice(x,w);p===44?(Lt(e,y,r),r=Object.create(null)):l=y,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(w===-1&&Vi[p]===1)x===-1&&(x=_);else if(p===32||p===9)w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_),Lt(r,t.slice(x,w),!0),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),x=w=-1}else if(p===61&&x!==-1&&w===-1)u=t.slice(x,_),x=w=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(Vi[p]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if(Vi[p]===1)x===-1&&(x=_);else if(p===34&&x!==-1)c=!1,w=_;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(p===34&&t.charCodeAt(_-1)===61)c=!0;else if(w===-1&&Vi[p]===1)x===-1&&(x=_);else if(x!==-1&&(p===32||p===9))w===-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let y=t.slice(x,w);i&&(y=y.replace(/\\/g,""),i=!1),Lt(r,u,y),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),u=void 0,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(x===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");w===-1&&(w=_);let I=t.slice(x,w);return l===void 0?Lt(e,I,r):(u===void 0?Lt(r,I,!0):i?Lt(r,u,I.replace(/\\/g,"")):Lt(r,u,I),Lt(e,l,r)),e}function CE(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Lx.exports={format:CE,parse:TE}});var Bo=ce((KR,Kx)=>{"use strict";var RE=fe("events"),kE=fe("https"),DE=fe("http"),Bx=fe("net"),PE=fe("tls"),{randomBytes:OE,createHash:LE}=fe("crypto"),{Duplex:jR,Readable:WR}=fe("stream"),{URL:bd}=fe("url"),Tn=Br(),NE=md(),ME=yd(),{isBlob:BE}=Fr(),{BINARY_TYPES:Nx,CLOSE_TIMEOUT:FE,EMPTY_BUFFER:Lo,GUID:zE,kForOnEventAttribute:vd,kListener:UE,kStatusCode:qE,kWebSocket:Ge,NOOP:Fx}=$t(),{EventTarget:{addEventListener:GE,removeEventListener:HE}}=Ox(),{format:jE,parse:WE}=Oo(),{toBuffer:KE}=ji(),zx=Symbol("kAborted"),Sd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],$E=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,we=class t extends RE{constructor(e,r,i){super(),this._binaryType=Nx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Lo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Ux(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Nx.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 NE({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new ME(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ge]=this,c[Ge]=this,e[Ge]=this,o.on("conclude",ZE),o.on("drain",YE),o.on("error",XE),o.on("message",QE),o.on("ping",eb),o.on("pong",tb),c.onerror=nb,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Hx),e.on("data",Mo),e.on("end",jx),e.on("error",Wx),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[Tn.extensionName]&&this._extensions[Tn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Gx(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){Id(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Lo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Id(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Lo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Id(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Tn.extensionName]||(o.compress=!1),this._sender.send(e||Lo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(we,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(we.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(we,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(we.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(we,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(we.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(we,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(we.prototype,"CLOSED",{enumerable:!0,value:Zt.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[vd])return e[UE];return null},set(e){for(let r of this.listeners(t))if(r[vd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[vd]:!0})}})});we.prototype.addEventListener=GE;we.prototype.removeEventListener=HE;Kx.exports=we;function Ux(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:FE,protocolVersion:Sd[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Sd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Sd.join(", ")})`);let c;if(e instanceof bd)c=e;else try{c=new bd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!l&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let A=new SyntaxError(x);if(t._redirects===0)throw A;No(t,A);return}let p=l?443:80,w=OE(16).toString("base64"),_=l?kE.request:DE.request,I=new Set,y;if(o.createConnection=o.createConnection||(l?JE:VE),o.defaultPort=o.defaultPort||p,o.port=c.port||p,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":w,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Tn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=jE({[Tn.extensionName]:y.offer()})),r.length){for(let A of r){if(typeof A!="string"||!$E.test(A)||I.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");I.add(A)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let S;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[T,R]of Object.entries(A))i.headers[T.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),S=t._req=_(o),t._redirects&&t.emit("redirect",t.url,S)}else S=t._req=_(o);o.timeout&&S.on("timeout",()=>{ot(t,S,"Opening handshake has timed out")}),S.on("error",A=>{S===null||S[zx]||(S=t._req=null,No(t,A))}),S.on("response",A=>{let T=A.headers.location,R=A.statusCode;if(T&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){ot(t,S,"Maximum redirects exceeded");return}S.abort();let P;try{P=new bd(T,e)}catch{let k=new SyntaxError(`Invalid URL: ${T}`);No(t,k);return}Ux(t,P,r,i)}else t.emit("unexpected-response",S,A)||ot(t,S,`Unexpected server response: ${A.statusCode}`)}),S.on("upgrade",(A,T,R)=>{if(t.emit("upgrade",A),t.readyState!==we.CONNECTING)return;S=t._req=null;let P=A.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){ot(t,T,"Invalid Upgrade header");return}let E=LE("sha1").update(w+zE).digest("base64");if(A.headers["sec-websocket-accept"]!==E){ot(t,T,"Invalid Sec-WebSocket-Accept header");return}let k=A.headers["sec-websocket-protocol"],O;if(k!==void 0?I.size?I.has(k)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":I.size&&(O="Server sent no subprotocol"),O){ot(t,T,O);return}k&&(t._protocol=k);let F=A.headers["sec-websocket-extensions"];if(F!==void 0){if(!y){ot(t,T,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=WE(F)}catch{ot(t,T,"Invalid Sec-WebSocket-Extensions header");return}let V=Object.keys(B);if(V.length!==1||V[0]!==Tn.extensionName){ot(t,T,"Server indicated an extension that was not requested");return}try{y.accept(B[Tn.extensionName])}catch{ot(t,T,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Tn.extensionName]=y}t.setSocket(T,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(S,t):S.end()}function No(t,e){t._readyState=we.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function VE(t){return t.path=t.socketPath,Bx.connect(t)}function JE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Bx.isIP(t.host)?"":t.host),PE.connect(t)}function ot(t,e,r){t._readyState=we.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ot),e.setHeader?(e[zx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(No,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Id(t,e,r){if(e){let i=BE(e)?e.size:KE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(r,i)}}function ZE(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",Mo),process.nextTick(qx,r._socket),t===1005?r.close():r.close(t,e))}function YE(){let t=this[Ge];t.isPaused||t._socket.resume()}function XE(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",Mo),process.nextTick(qx,e._socket),e.close(t[qE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Mx(){this[Ge].emitClose()}function QE(t,e){this[Ge].emit("message",t,e)}function eb(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Fx),e.emit("ping",t)}function tb(t){this[Ge].emit("pong",t)}function qx(t){t.resume()}function nb(t){let e=this[Ge];e.readyState!==we.CLOSED&&(e.readyState===we.OPEN&&(e._readyState=we.CLOSING,Gx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Gx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Hx(){let t=this[Ge];if(this.removeListener("close",Hx),this.removeListener("data",Mo),this.removeListener("end",jx),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[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Mx),t._receiver.on("finish",Mx))}function Mo(t){this[Ge]._receiver.write(t)||this.pause()}function jx(){let t=this[Ge];t._readyState=we.CLOSING,t._receiver.end(),this.end()}function Wx(){let t=this[Ge];this.removeListener("error",Wx),this.on("error",Fx),t&&(t._readyState=we.CLOSING,this.destroy())}});var Zx=ce((VR,Jx)=>{"use strict";var $R=Bo(),{Duplex:rb}=fe("stream");function $x(t){t.emit("close")}function ib(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Vx(t){this.removeListener("error",Vx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function sb(t,e){let r=!0,i=new rb({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick($x,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick($x,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",ib),i.on("error",Vx),i}Jx.exports=sb});var Ad=ce((JR,Yx)=>{"use strict";var{tokenChars:ob}=Fr();function ab(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&ob[l]===1)r===-1&&(r=o);else if(o!==0&&(l===32||l===9))i===-1&&r!==-1&&(i=o);else if(l===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Yx.exports={parse:ab}});var ih=ce((YR,rh)=>{"use strict";var cb=fe("events"),Fo=fe("http"),{Duplex:ZR}=fe("stream"),{createHash:db}=fe("crypto"),Xx=Oo(),Jn=Br(),lb=Ad(),ub=Bo(),{CLOSE_TIMEOUT:fb,GUID:xb,kWebSocket:hb}=$t(),pb=/^[+/0-9A-Za-z]{22}==$/,Qx=0,eh=1,nh=2,Td=class extends cb{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:fb,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:ub,...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=Fo.createServer((i,o)=>{let c=Fo.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=gb(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,l)=>{this.handleUpgrade(o,c,l,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Qx}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===nh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Ji,this);return}if(e&&this.once("close",e),this._state!==eh)if(this._state=eh,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(Ji,this):process.nextTick(Ji,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Ji(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",th);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Zn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Zn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!pb.test(c)){Zn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Zn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Zi(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=lb.parse(x)}catch{Zn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let w=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&w!==void 0){let I=new Jn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=Xx.parse(w);y[Jn.extensionName]&&(I.accept(y[Jn.extensionName]),_[Jn.extensionName]=I)}catch{Zn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let I={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(I,(y,S,A,T)=>{if(!y)return Zi(r,S||401,A,T);this.completeUpgrade(_,c,p,e,r,i,o)});return}if(!this.options.verifyClient(I))return Zi(r,401)}this.completeUpgrade(_,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[hb])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Qx)return Zi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${db("sha1").update(r+xb).digest("base64")}`],w=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(p.push(`Sec-WebSocket-Protocol: ${_}`),w._protocol=_)}if(e[Jn.extensionName]){let _=e[Jn.extensionName].params,I=Xx.format({[Jn.extensionName]:[_]});p.push(`Sec-WebSocket-Extensions: ${I}`),w._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&as(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as Tg,mkdirSync as Rg}from"node:fs";import{join as Cg}from"node:path";function wl(t){let e=t.retentionDays??Og,r=t.clock??(()=>Pn(new Date));ds={bridgeSink:new Qr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Qr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();as(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])as(t.agentLogsDir(o),"agent",i,e)}function Lg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function _l(t){Ia=t}function yl(t){return or[Ia]<=or[t]}function bl(t,e){let r=or[t];return r===void 0?!0:r>=or[e]}function ls(t){ml={...t}}function El(t){let e=(u,f=2)=>String(u).padStart(f,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Pn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function At(t,e,r,i,o){try{let c=`${JSON.stringify({ts:El(new Date),level:e,module:r,msg:i,...o})}
|
|
11
|
+
`;Rg(t,{recursive:!0}),Tg(Cg(t,sr("bridge",Pn(new Date))),c)}catch{}}function Ng(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function cs(t,e,r,i,o){if(or[t]<or[Ia])return;let c=`${JSON.stringify({ts:El(new Date),level:t,module:e,msg:r,...ml,...i})}
|
|
12
|
+
`;if(ds){let d=Ng(o,i),u=d?Lg(ds,d):ds.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Dg.write(c):Pg.write(c)}function G(t,e){return{debug:(r,i)=>cs("debug",t,r,i,e),info:(r,i)=>cs("info",t,r,i,e),warn:(r,i)=>cs("warn",t,r,i,e),error:(r,i)=>cs("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var or,Ia,Pg,Dg,ml,Og,ds,te=Qe(()=>{"use strict";ir();Sa();or={debug:10,info:20,warn:30,error:40},Ia=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Pg=process.stdout,Dg=process.stderr,ml={},Og=Ke("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ds=null});var k,qe=Qe(()=>{"use strict";k=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Al={};Ea(Al,{ACP_WRAPPER_NPM_PACKAGES:()=>ti,_resetAcpInstallerForTests:()=>Gg,_setBinaryPathCacheForTests:()=>Hg,buildAcpSpawn:()=>ni,ensureAcpInstalled:()=>ar,getAcpBinaryPath:()=>us,pickWhichLine:()=>Ta,probeAcpVersion:()=>Ug,resolveAcpCommand:()=>Il});import{readFileSync as vl}from"node:fs";import{createRequire as Mg}from"node:module";import{dirname as Bg,resolve as Fg}from"node:path";function Ta(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function zg(t){let e=Sl.resolve(`${t.npmPackage}/package.json`),r=Bg(e),i=JSON.parse(vl(e,"utf8")),o=typeof i.bin=="string"?i.bin:i.bin?.[t.binary];if(!o)throw new Error(`${t.npmPackage} package.json \u7F3A bin[${t.binary}]`);return Fg(r,o)}async function ar(t,e){let r=ka[t];if(!r)throw new k("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ei.get(t);if(i)return i;try{let o=zg(r);return ei.set(t,o),Aa.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw Aa.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new k("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
|
|
13
|
+
`),{cause:o})}}async function Ug(t){let e=ka[t];if(e)try{let r=Sl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(vl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){Aa.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function us(t){return ei.get(t)}function Il(t,e){if(e)return e;let r=us(t);if(!r)throw new k("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function ni(t,e,r){if(e)return{command:e,args:[...r]};let i=Il(t);return{command:process.execPath,args:[i,...r]}}function Gg(){ei.clear()}function Hg(t,e){ei.set(t,e)}var Aa,ka,ti,Sl,ei,sn=Qe(()=>{"use strict";qe();te();Aa=G("agents.acp-installer"),ka={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},ti=Object.values(ka).filter(t=>t!==void 0).map(t=>t.npmPackage),Sl=Mg(import.meta.url),ei=new Map});import{chmod as jg,mkdir as Wg,readFile as $g,rename as Kg,rm as Vg,writeFile as Zg}from"node:fs/promises";import{dirname as Jg}from"node:path";async function cr(t){try{let e=await $g(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function on(t,e,r){await Wg(Jg(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Zg(i,e,{encoding:"utf8",mode:r?.mode}),await Kg(i,t),r?.mode!==void 0&&await jg(t,r.mode)}catch(o){throw await Vg(i,{force:!0}).catch(()=>{}),o}}async function dr(t,e,r){await on(t,`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,r)}var an=Qe(()=>{"use strict"});import{promises as Rl,readdirSync as Yg}from"node:fs";import{homedir as Xg}from"node:os";import{sep as Qg,join as Ae,resolve as Cl}from"node:path";function Q(t){let e=t??Xg(),r=Ae(e,".coze"),i=Ae(r,"bridge"),o=Ae(i,"lib"),c=Ae(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ae(o,"index.js"),binDir:Ae(i,"bin"),pidFile:Ae(i,"bridge.pid"),portFile:Ae(i,"bridge.port"),tokenFile:Ae(i,"bridge.token"),patTokenFile:Ae(i,"pat-token"),agentEnvFile:Ae(i,"agent-env.json"),logFile:Ae(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ae(c,"daemon-stdio.log"),installLock:Ae(i,"install.lock"),configFile:Ae(i,"config.json"),agentsRoot:Ae(r,"agents")}}function Ve(t,e=Q()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function fs(t=Q()){try{return Yg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ri(t,e){let r=await Rl.realpath(Cl(t)).catch(()=>null);if(!r)return!1;let i=await Rl.realpath(Cl(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?r.toLowerCase():r,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+Qg)}var De=Qe(()=>{"use strict"});var xs={};Ea(xs,{AGENT_CONFIG_FILE_MODE:()=>hs,enforceAgentConfigMode:()=>nm,loadAgentConfig:()=>ke,persistAgentSessions:()=>ii,persistAgentSkills:()=>si,saveAgentConfig:()=>Me});import{chmod as em,stat as tm}from"node:fs/promises";function ke(t,e){return cr(Ve(t,e).config)}function Me(t,e){return dr(Ve(t.agentId,e).config,t,{mode:hs})}async function nm(t,e){if(process.platform==="win32")return;let r=Ve(t,e).config;try{let i=await tm(r);if(!i.isFile())return;let o=i.mode&511;o!==hs&&(await em(r,hs),Pl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Pl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ii(t,e,r){let i=await ke(t,r);i&&(i.sessions=Object.fromEntries(e),await Me(i,r))}async function si(t,e,r){let i=await ke(t,r);i&&(i.skills=e,await Me(i,r))}var Pl,hs,cn=Qe(()=>{"use strict";an();te();De();Pl=G("agent-config"),hs=384});var Pa=oe(($I,Ll)=>{Ll.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 gs=oe(Ml=>{var Nl={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function cm(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Nl))Ml[t]=cm(Nl[t])});var Gl=oe((VI,Ul)=>{var dm=le("fs"),Oe=le("path"),Bl=Pa(),lm=gs(),um=typeof process=="object"&&process.platform==="win32",Fl=t=>typeof t=="object"&&t!==null,zl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=dm,Fl(t)&&Fl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ul.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw lm.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ee.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Oe.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var x=Oe.dirname(t);c.fs.exists(x,function(p){p||c.makeDir(x),c.fs.open(t,"w",438,function(_,v){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(w,E){c.fs.write(E,e,0,e.length,0,function(){c.fs.close(E,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):v?c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Oe.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&d.push(Oe.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(f,o,c)))}),d}return r(t,void 0,!0)};Ee.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Oe.join(t,u),r.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Oe.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(p,_){if(p)return e(p);i=i.concat(_),--d||e(null,i)}):--d||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return zl[(t^e)&255]^t>>>8};Ee.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ee.crc32update(r,t[i++]);return~r>>>0};Ee.methodToString=function(t){switch(t){case Bl.STORED:return"STORED ("+t+")";case Bl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Oe.normalize(Oe.join(t,r.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=um;Ee.crcTable=zl});var ql=oe((ZI,Hl)=>{var fm=le("path");Hl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=fm.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wl=oe((JI,jl)=>{jl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var fr=oe((YI,ur)=>{ur.exports=Gl();ur.exports.Constants=Pa();ur.exports.Errors=gs();ur.exports.FileAttr=ql();ur.exports.decoder=Wl()});var Kl=oe((XI,$l)=>{var dn=fr(),z=dn.Constants;$l.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,f=0,x=0,p=0,_=0,v=0,w=0,E=0;t|=dn.isWin?2560:768,r|=z.FLG_EFS;let I={extraLen:0},A=y=>Math.max(0,y)>>>0,T=y=>Math.max(0,y)&65535,D=y=>Math.max(0,y)&255;return o=dn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&z.FLG_EFS)>0},set flags_efs(y){y?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(y){y?r|=z.FLG_DESC:r&=~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 dn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=dn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(y){c=A(y)},get compressedSize(){return d},set compressedSize(y){d=A(y)},get size(){return u},set size(y){u=A(y)},get fileNameLength(){return f},set fileNameLength(y){f=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return p},set commentLength(y){p=y},get diskNumStart(){return _},set diskNumStart(y){_=A(y)},get inAttr(){return v},set inAttr(y){v=A(y)},get attr(){return w},set attr(y){w=A(y)},get fileAttr(){return(w||0)>>16&4095},get offset(){return E},set offset(y){E=A(y)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+f+x+p},get realDataOffset(){return E+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(E,E+z.LOCHDR);if(C.readUInt32LE(0)!==z.LOCSIG)throw dn.Errors.INVALID_LOC();I.version=C.readUInt16LE(z.LOCVER),I.flags=C.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=C.readUInt16LE(z.LOCHOW),I.time=C.readUInt32LE(z.LOCTIM),I.crc=C.readUInt32LE(z.LOCCRC),I.compressedSize=C.readUInt32LE(z.LOCSIZ),I.size=C.readUInt32LE(z.LOCLEN),I.fnameLen=C.readUInt16LE(z.LOCNAM),I.extraLen=C.readUInt16LE(z.LOCEXT);let O=E+z.LOCHDR+I.fnameLen,M=O+I.extraLen;return y.slice(O,M)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw dn.Errors.INVALID_CEN();t=y.readUInt16LE(z.CENVEM),e=y.readUInt16LE(z.CENVER),r=y.readUInt16LE(z.CENFLG),i=y.readUInt16LE(z.CENHOW),o=y.readUInt32LE(z.CENTIM),c=y.readUInt32LE(z.CENCRC),d=y.readUInt32LE(z.CENSIZ),u=y.readUInt32LE(z.CENLEN),f=y.readUInt16LE(z.CENNAM),x=y.readUInt16LE(z.CENEXT),p=y.readUInt16LE(z.CENCOM),_=y.readUInt16LE(z.CENDSK),v=y.readUInt16LE(z.CENATT),w=y.readUInt32LE(z.CENATX),E=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(r,z.LOCFLG),y.writeUInt16LE(i,z.LOCHOW),y.writeUInt32LE(o,z.LOCTIM),y.writeUInt32LE(c,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+p);return y.writeUInt32LE(z.CENSIG,0),y.writeUInt16LE(t,z.CENVEM),y.writeUInt16LE(e,z.CENVER),y.writeUInt16LE(r,z.CENFLG),y.writeUInt16LE(i,z.CENHOW),y.writeUInt32LE(o,z.CENTIM),y.writeUInt32LE(c,z.CENCRC),y.writeUInt32LE(d,z.CENSIZ),y.writeUInt32LE(u,z.CENLEN),y.writeUInt16LE(f,z.CENNAM),y.writeUInt16LE(x,z.CENEXT),y.writeUInt16LE(p,z.CENCOM),y.writeUInt16LE(_,z.CENDSK),y.writeUInt16LE(v,z.CENATT),y.writeUInt32LE(w,z.CENATX),y.writeUInt32LE(E,z.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:dn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(f),extraLength:y(x),commentLength:y(p),diskNumStart:_,inAttr:v,attr:w,offset:E,centralHeaderSize:y(z.CENHDR+f+x+p)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Zl=oe((QI,Vl)=>{var hr=fr(),_e=hr.Constants;Vl.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return _e.ENDHDR+o},loadFromBinary:function(c){if((c.length!==_e.ENDHDR||c.readUInt32LE(0)!==_e.ENDSIG)&&(c.length<_e.ZIP64HDR||c.readUInt32LE(0)!==_e.ZIP64SIG))throw hr.Errors.INVALID_END();c.readUInt32LE(0)===_e.ENDSIG?(t=c.readUInt16LE(_e.ENDSUB),e=c.readUInt16LE(_e.ENDTOT),r=c.readUInt32LE(_e.ENDSIZ),i=c.readUInt32LE(_e.ENDOFF),o=c.readUInt16LE(_e.ENDCOM)):(t=hr.readBigUInt64LE(c,_e.ZIP64SUB),e=hr.readBigUInt64LE(c,_e.ZIP64TOT),r=hr.readBigUInt64LE(c,_e.ZIP64SIZE),i=hr.readBigUInt64LE(c,_e.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(_e.ENDHDR+o);return c.writeUInt32LE(_e.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,_e.ENDSUB),c.writeUInt16LE(e,_e.ENDTOT),c.writeUInt32LE(r,_e.ENDSIZ),c.writeUInt32LE(i,_e.ENDOFF),c.writeUInt16LE(o,_e.ENDCOM),c.fill(" ",_e.ENDHDR),c},toJSON:function(){let c=function(d,u){let f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Oa=oe(Da=>{Da.EntryHeader=Kl();Da.MainHeader=Zl()});var Yl=oe((tA,Jl)=>{Jl.exports=function(t){var e=le("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var x=0;x<c.length;x++){var p=c[x];p.copy(u,f),f+=p.length}i&&i(u)}),o.end(t)}}}});var Ql=oe((nA,Xl)=>{var hm=+(process.versions?process.versions.node:"").split(".")[0]||0;Xl.exports=function(t,e){var r=le("zlib");let i=hm>=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 p=0;p<d.length;p++){var _=d[p];_.copy(f,x),x+=_.length}o&&o(f)}),c.end(t)}}}});var iu=oe((rA,ru)=>{"use strict";var{randomFillSync:eu}=le("crypto"),xm=gs(),pm=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),nu=(t,e)=>Math.imul(t,e)>>>0,tu=(t,e)=>pm[(t^e)&255]^t>>>8,oi=()=>typeof eu=="function"?eu(Buffer.alloc(12)):oi.node();oi.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 ms={genSalt:oi};function ws(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])}ws.prototype.updateKeys=function(t){let e=this.keys;return e[0]=tu(e[0],t),e[1]+=e[0]&255,e[1]=nu(e[1],134775813)+1,e[2]=tu(e[2],e[1]>>>24),t};ws.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return nu(t,t^1)>>8&255};function gm(t){let e=new ws(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function mm(t){let e=new ws(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function wm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=gm(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw xm.WRONG_PASSWORD();return i(t.slice(12))}function _m(t){Buffer.isBuffer(t)&&t.length>=12?ms.genSalt=function(){return t.slice(0,12)}:t==="node"?ms.genSalt=oi.node:ms.genSalt=oi}function ym(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=mm(r),c=ms.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)}ru.exports={decrypt:wm,encrypt:ym,_salter:_m}});var su=oe(_s=>{_s.Deflater=Yl();_s.Inflater=Ql();_s.ZipCrypto=iu()});var Na=oe((sA,ou)=>{var ae=fr(),bm=Oa(),ve=ae.Constants,La=su();ou.exports=function(t,e){var r=new bm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let p=t,_=typeof p.decoder=="object"?p.decoder:ae.decoder;x=_.hasOwnProperty("efs")?_.efs:!1;function v(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function w(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ae.crc32(y)!==r.localHeader.crc)return!1}else{let C={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==ve.LOCSIG||e.readUInt32LE(O)==ve.CENSIG)throw ae.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==ve.EXTSIG)C.crc=e.readUInt32LE(O+ve.EXTCRC),C.compressedSize=e.readUInt32LE(O+ve.EXTSIZ),C.size=e.readUInt32LE(O+ve.EXTLEN);else if(e.readUInt16LE(O+12)===19280)C.crc=e.readUInt32LE(O+ve.EXTCRC-4),C.compressedSize=e.readUInt32LE(O+ve.EXTSIZ-4),C.size=e.readUInt32LE(O+ve.EXTLEN-4);else throw ae.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw ae.Errors.DESCRIPTOR_FAULTY();if(ae.crc32(y)!==C.crc)return!1}return!0}function E(y,C,O){if(typeof C>"u"&&typeof y=="string"&&(O=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),ae.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var M=v();if(M.length===0)return y&&C&&C(M),M;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw ae.Errors.INVALID_PASS_PARAM();M=La.ZipCrypto.decrypt(M,r,O)}var N=Buffer.alloc(r.size);switch(r.method){case ae.Constants.STORED:if(M.copy(N),w(N))return y&&C&&C(N),N;throw y&&C&&C(N,ae.Errors.BAD_CRC()),ae.Errors.BAD_CRC();case ae.Constants.DEFLATED:var Z=new La.Inflater(M,r.size);if(y)Z.inflateAsync(function(K){K.copy(K,0),C&&(w(K)?C(K):C(K,ae.Errors.BAD_CRC()))});else{if(Z.inflate(N).copy(N,0),!w(N))throw ae.Errors.BAD_CRC(`"${_.decode(i)}"`);return N}break;default:throw y&&C&&C(Buffer.alloc(0),ae.Errors.UNKNOWN_METHOD()),ae.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(v()),v();if(d.length&&!c){var O;switch(r.method){case ae.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(d.length),d.copy(O),y&&C&&C(O),O;default:case ae.Constants.DEFLATED:var M=new La.Deflater(d);if(y)M.deflateAsync(function(Z){O=Buffer.alloc(Z.length),r.compressedSize=Z.length,Z.copy(O),C&&C(O)});else{var N=M.deflate();return r.compressedSize=N.length,N}M=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,C){return ae.readBigUInt64LE(y,C)}function T(y){try{for(var C=0,O,M,N;C+4<y.length;)O=y.readUInt16LE(C),C+=2,M=y.readUInt16LE(C),C+=2,N=y.slice(C,C+M),C+=M,ve.ID_ZIP64===O&&D(N)}catch{throw ae.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(y){var C,O,M,N;y.length>=ve.EF_ZIP64_SCOMP&&(C=A(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=C)),y.length>=ve.EF_ZIP64_RHO&&(O=A(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=O)),y.length>=ve.EF_ZIP64_DSN&&(M=A(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=M)),y.length>=ve.EF_ZIP64_DSN+4&&(N=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=N))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(y){i=ae.toBuffer(y,_.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,T(y)},get comment(){return _.decode(o)},set comment(y){if(o=ae.toBuffer(y,_.encode),r.commentLength=o.length,o.length>65535)throw ae.Errors.COMMENT_TOO_LONG()},get name(){var y=_.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=ae.toBuffer(y,ae.decoder.encode),!c&&d.length?(r.size=d.length,r.method=ae.Constants.DEFLATED,r.crc=ae.crc32(y),r.changed=!0):r.method=ae.Constants.STORED},getData:function(y){return r.changed?d:E(!1,null,y)},getDataAsync:function(y,C){r.changed?y(d):E(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var y=r.centralHeaderToBinary(),C=ae.Constants.CENHDR;return i.copy(y,C),C+=i.length,u.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let C=r.localHeaderToBinary(),O=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(O,y),y+=C.length,i.copy(O,y),y+=i.length,f.copy(O,y),y+=f.length,O},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var du=oe((oA,cu)=>{var au=Na(),Em=Oa(),je=fr();cu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Em.MainHeader,d=!1,u=null;let f=new Set,x=e,{noSort:p,decoder:_}=x;t?E(x.readEntries):d=!0;function v(){let A=new Set;for(let T of Object.keys(i)){let D=T.split("/");if(D.pop(),!!D.length)for(let y=0;y<D.length;y++){let C=D.slice(0,y+1).join("/")+"/";A.add(C)}}for(let T of A)if(!(T in i)){let D=new au(x);D.entryName=T,D.attr=16,D.temporary=!0,r.push(D),i[D.entryName]=D,f.add(D)}}function w(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var A=c.offset,T=0;T<r.length;T++){var D=A,y=new au(x,t);y.header=t.slice(D,D+=je.Constants.CENHDR),y.entryName=t.slice(D,D+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(D,D+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(D,D+y.header.commentLength)),A+=y.header.centralHeaderSize,r[T]=y,i[y.entryName]=y}f.clear(),v()}function E(A){var T=t.length-je.Constants.ENDHDR,D=Math.max(0,T-65535),y=D,C=t.length,O=-1,M=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(D=0),T;T>=y;T--)if(t[T]===80){if(t.readUInt32LE(T)===je.Constants.ENDSIG){O=T,M=T,C=T+je.Constants.ENDHDR,y=T-je.Constants.END64HDR;continue}if(t.readUInt32LE(T)===je.Constants.END64SIG){y=D;continue}if(t.readUInt32LE(T)===je.Constants.ZIP64SIG){O=T,C=T+je.readBigUInt64LE(t,T+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(O==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,C)),c.commentLength&&(o=t.slice(M+je.Constants.ENDHDR)),A&&w()}function I(){r.length>1&&!p&&r.sort((A,T)=>A.entryName.toLowerCase().localeCompare(T.entryName.toLowerCase()))}return{get entries(){return d||w(),r.filter(A=>!f.has(A))},get comment(){return _.decode(o)},set comment(A){o=je.toBuffer(A,_.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||w(),i[A]||null},setEntry:function(A){d||w(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,T=!0){d||w();let D=i[A];this.getEntryChildren(D,T).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||w();let T=i[A],D=r.indexOf(T);D>=0&&(r.splice(D,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,T=!0){if(d||w(),typeof A=="object")if(A.isDirectory&&T){let D=[],y=A.entryName;for(let C of r)C.entryName.startsWith(y)&&D.push(C);return D}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||w(),I();let A=[],T=[],D=0,y=0;c.size=0,c.offset=0;let C=0;for(let N of this.entries){let Z=N.getCompressedData();N.header.offset=y;let K=N.packLocalHeader(),ne=K.length+Z.length;y+=ne,A.push(K),A.push(Z);let Y=N.packCentralHeader();T.push(Y),c.size+=Y.length,D+=ne+Y.length,C++}D+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let O=Buffer.alloc(D);for(let N of A)N.copy(O,y),y+=N.length;for(let N of T)N.copy(O,y),y+=N.length;let M=c.toBinary();return o&&o.copy(M,je.Constants.ENDHDR),M.copy(O,y),t=O,d=!1,O},toAsyncBuffer:function(A,T,D,y){try{d||w(),I();let C=[],O=[],M=0,N=0,Z=0;c.size=0,c.offset=0;let K=function(ne){if(ne.length>0){let Y=ne.shift(),ie=Y.entryName+Y.extra.toString();D&&D(ie),Y.getCompressedDataAsync(function(se){y&&y(ie),Y.header.offset=N;let P=Y.packLocalHeader(),U=P.length+se.length;N+=U,C.push(P),C.push(se);let j=Y.packCentralHeader();O.push(j),c.size+=j.length,M+=U+j.length,Z++,K(ne)})}else{M+=c.mainHeaderSize,c.offset=N,c.totalEntries=Z,N=0;let Y=Buffer.alloc(M);C.forEach(function(se){se.copy(Y,N),N+=se.length}),O.forEach(function(se){se.copy(Y,N),N+=se.length});let ie=c.toBinary();o&&o.copy(ie,je.Constants.ENDHDR),ie.copy(Y,N),t=Y,d=!1,A(Y)}};K(Array.from(this.entries))}catch(C){T(C)}}}}});var fu=oe((aA,uu)=>{var be=fr(),ye=le("path"),vm=Na(),Sm=du(),Dn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),lu=(...t)=>be.findLast(t,e=>typeof e=="string"),Im=(...t)=>be.findLast(t,e=>typeof e=="function"),Am={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};uu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Am);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=be.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new be(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=be.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=be.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw be.Errors.INVALID_FILENAME();let c=new Sm(r,i),{canonical:d,sanitize:u,zipnamefix:f}=be;function x(w){if(w&&c){var E;if(typeof w=="string"&&(E=c.getEntry(ye.posix.normalize(w))),typeof w=="object"&&typeof w.entryName<"u"&&typeof w.header<"u"&&(E=c.getEntry(w.entryName)),E)return E}return null}function p(w){let{join:E,normalize:I,sep:A}=ye.posix;return E(ye.isAbsolute(w)?"/":".",I(A+w.split("\\").join(A)+A))}function _(w){return w instanceof RegExp?(function(E){return function(I){return E.test(I)}})(w):typeof w!="function"?()=>!0:w}let v=(w,E)=>{let I=E.slice(-1);return I=I===o.sep?o.sep:"",ye.relative(w,E)+I};return{readFile:function(w,E){var I=x(w);return I&&I.getData(E)||null},childCount:function(w){let E=x(w);if(E)return c.getChildCount(E)},readFileAsync:function(w,E){var I=x(w);I?I.getDataAsync(E):E(null,"getEntry failed for:"+w)},readAsText:function(w,E){var I=x(w);if(I){var A=I.getData();if(A&&A.length)return A.toString(E||"utf8")}return""},readAsTextAsync:function(w,E,I){var A=x(w);A?A.getDataAsync(function(T,D){if(D){E(T,D);return}T&&T.length?E(T.toString(I||"utf8")):E("")}):E("")},deleteFile:function(w,E=!0){var I=x(w);I&&c.deleteFile(I.entryName,E)},deleteEntry:function(w){var E=x(w);E&&c.deleteEntry(E.entryName)},addZipComment:function(w){c.comment=w},getZipComment:function(){return c.comment||""},addZipEntryComment:function(w,E){var I=x(w);I&&(I.comment=E)},getZipEntryComment:function(w){var E=x(w);return E&&E.comment||""},updateFile:function(w,E){var I=x(w);I&&I.setData(E)},addLocalFile:function(w,E,I,A){if(o.fs.existsSync(w)){E=E?p(E):"";let T=ye.win32.basename(ye.win32.normalize(w));E+=I||T;let D=o.fs.statSync(w),y=D.isFile()?o.fs.readFileSync(w):Buffer.alloc(0);D.isDirectory()&&(E+=o.sep),this.addFile(E,y,A,D)}else throw be.Errors.FILE_NOT_FOUND(w)},addLocalFileAsync:function(w,E){w=typeof w=="object"?w:{localPath:w};let I=ye.resolve(w.localPath),{comment:A}=w,{zipPath:T,zipName:D}=w,y=this;o.fs.stat(I,function(C,O){if(C)return E(C,!1);T=T?p(T):"";let M=ye.win32.basename(ye.win32.normalize(I));if(T+=D||M,O.isFile())o.fs.readFile(I,function(N,Z){return N?E(N,!1):(y.addFile(T,Z,A,O),setImmediate(E,void 0,!0))});else if(O.isDirectory())return T+=o.sep,y.addFile(T,Buffer.alloc(0),A,O),setImmediate(E,void 0,!0)})},addLocalFolder:function(w,E,I){if(I=_(I),E=E?p(E):"",w=ye.normalize(w),o.fs.existsSync(w)){let A=o.findFiles(w),T=this;if(A.length)for(let D of A){let y=ye.join(E,v(w,D));I(y)&&T.addLocalFile(D,ye.dirname(y))}}else throw be.Errors.FILE_NOT_FOUND(w)},addLocalFolderAsync:function(w,E,I,A){A=_(A),I=I?p(I):"",w=ye.normalize(w);var T=this;o.fs.open(w,"r",function(D){if(D&&D.code==="ENOENT")E(void 0,be.Errors.FILE_NOT_FOUND(w));else if(D)E(void 0,D);else{var y=o.findFiles(w),C=-1,O=function(){if(C+=1,C<y.length){var M=y[C],N=v(w,M).split("\\").join("/");N=N.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(N)?o.fs.stat(M,function(Z,K){Z&&E(void 0,Z),K.isFile()?o.fs.readFile(M,function(ne,Y){ne?E(void 0,ne):(T.addFile(I+N,Y,"",K),O())}):(T.addFile(I+N+"/",Buffer.alloc(0),"",K),O())}):process.nextTick(()=>{O()})}else E(!0,void 0)};O()}})},addLocalFolderAsync2:function(w,E){let I=this;w=typeof w=="object"?w:{localPath:w},localPath=ye.resolve(p(w.localPath));let{zipPath:A,filter:T,namefix:D}=w;T instanceof RegExp?T=(function(O){return function(M){return O.test(M)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?p(A):"",D=="latin1"&&(D=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=O=>O);let y=O=>ye.join(A,D(v(localPath,O))),C=O=>ye.win32.basename(ye.win32.normalize(D(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?E(void 0,be.Errors.FILE_NOT_FOUND(localPath)):O?E(void 0,O):o.findFilesAsync(localPath,function(M,N){if(M)return E(M);N=N.filter(Z=>T(y(Z))),N.length||E(void 0,!1),setImmediate(N.reverse().reduce(function(Z,K){return function(ne,Y){if(ne||Y===!1)return setImmediate(Z,ne,!1);I.addLocalFileAsync({localPath:K,zipPath:ye.dirname(y(K)),zipName:C(K)},Z)}},E))})})},addLocalFolderPromise:function(w,E){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:w},E),(T,D)=>{T&&A(T),D&&I(this)})})},addFile:function(w,E,I,A){w=f(w);let T=x(w),D=T!=null;D||(T=new vm(i),T.entryName=w),T.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(T.header.time=A.mtime);var C=T.isDirectory?16:0;let O=T.isDirectory?16384:32768;return y?O|=4095&A.mode:typeof A=="number"?O|=4095&A:O|=T.isDirectory?493:420,C=(C|O<<16)>>>0,T.attr=C,T.setData(E),D||c.setEntry(T),T},getEntries:function(w){return c.password=w,c?c.entries:[]},getEntry:function(w){return x(w)},getEntryCount:function(){return c.getEntryCount()},forEach:function(w){return c.forEach(w)},extractEntryTo:function(w,E,I,A,T,D){A=Dn(!1,A),T=Dn(!1,T),I=Dn(!0,I),D=lu(T,D);var y=x(w);if(!y)throw be.Errors.NO_ENTRY();var C=d(y.entryName),O=u(E,D&&!y.isDirectory?D:I?C:ye.basename(C));if(y.isDirectory){var M=c.getEntryChildren(y);return M.forEach(function(K){if(K.isDirectory)return;var ne=K.getData();if(!ne)throw be.Errors.CANT_EXTRACT_FILE();var Y=d(K.entryName),ie=u(E,I?Y:ye.basename(Y));let se=T?K.header.fileAttr:void 0;o.writeFileTo(ie,ne,A,se)}),!0}var N=y.getData(c.password);if(!N)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!A)throw be.Errors.CANT_OVERRIDE();let Z=T?w.header.fileAttr:void 0;return o.writeFileTo(O,N,A,Z),!0},test:function(w){if(!c)return!1;for(var E in c.entries)try{if(E.isDirectory)continue;var I=c.entries[E].getData(w);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(w,E,I,A){if(I=Dn(!1,I),A=lu(I,A),E=Dn(!1,E),!c)throw be.Errors.NO_ZIP();c.entries.forEach(function(T){var D=u(w,d(T.entryName));if(T.isDirectory){o.makeDir(D);return}var y=T.getData(A);if(!y)throw be.Errors.CANT_EXTRACT_FILE();let C=I?T.header.fileAttr:void 0;o.writeFileTo(D,y,E,C);try{o.fs.utimesSync(D,T.header.time,T.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(w,E,I,A){if(A=Im(E,I,A),I=Dn(!1,I),E=Dn(!1,E),!A)return new Promise((O,M)=>{this.extractAllToAsync(w,E,I,function(N){N?M(N):O(this)})});if(!c){A(be.Errors.NO_ZIP());return}w=ye.resolve(w);let T=O=>u(w,ye.normalize(d(O.entryName))),D=(O,M)=>new Error(O+': "'+M+'"'),y=[],C=[];c.entries.forEach(O=>{O.isDirectory?y.push(O):C.push(O)});for(let O of y){let M=T(O),N=I?O.header.fileAttr:void 0;try{o.makeDir(M),N&&o.fs.chmodSync(M,N),o.fs.utimesSync(M,O.header.time,O.header.time)}catch{A(D("Unable to create folder",M))}}C.reverse().reduce(function(O,M){return function(N){if(N)O(N);else{let Z=ye.normalize(d(M.entryName)),K=u(w,Z);M.getDataAsync(function(ne,Y){if(Y)O(Y);else if(!ne)O(be.Errors.CANT_EXTRACT_FILE());else{let ie=I?M.header.fileAttr:void 0;o.writeFileToAsync(K,ne,E,ie,function(se){se||O(D("Unable to write file",K)),o.fs.utimes(K,M.header.time,M.header.time,function(P){P?O(D("Unable to set times",K)):O()})})}})}}},A)()},writeZip:function(w,E){if(arguments.length===1&&typeof w=="function"&&(E=w,w=""),!w&&i.filename&&(w=i.filename),!!w){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(w,I,!0);typeof E=="function"&&E(A?null:new Error("failed"),"")}}},writeZipPromise:function(w,E){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},E);return new Promise((T,D)=>{!w&&i.filename&&(w=i.filename),w||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=O=>O?T(O):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(w,y,I,A,C)},D)})},toBufferPromise:function(){return new Promise((w,E)=>{c.toAsyncBuffer(w,E)})},toBuffer:function(w,E,I,A){return typeof w=="function"?(c.toAsyncBuffer(w,E,I,A),null):c.compressToBuffer()}}}});import{execFile as D_,spawn as O_,spawnSync as I2}from"node:child_process";import{promisify as L_}from"node:util";function M_(t){if(process.platform!=="win32")return!1;if(Df.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Df,"").toLowerCase();return N_.has(r)}function Of(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return M_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function nt(t,e=[],r={}){return O_(t,e,Of(t,r))}function Lf(t,e=[],r={}){return B_(t,e,Of(t,r))}var N_,Df,B_,Kt=Qe(()=>{"use strict";N_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Df=/\.(cmd|bat|ps1)$/i;B_=L_(D_)});var Zt=oe((fC,wh)=>{"use strict";var gh=["nodebuffer","arraybuffer","fragments"],mh=typeof Blob<"u";mh&&gh.push("blob");wh.exports={BINARY_TYPES:gh,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 Ki=oe((hC,Ao)=>{"use strict";var{EMPTY_BUFFER:gE}=Zt(),ud=Buffer[Symbol.species];function mE(t,e){if(t.length===0)return gE;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 ud(r.buffer,r.byteOffset,i):r}function _h(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function yh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function wE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function fd(t){if(fd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ud(t):ArrayBuffer.isView(t)?e=new ud(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),fd.readOnly=!1),e}Ao.exports={concat:mE,mask:_h,toArrayBuffer:wE,toBuffer:fd,unmask:yh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=le("bufferutil");Ao.exports.mask=function(e,r,i,o,c){c<48?_h(e,r,i,o,c):t.mask(e,r,i,o,c)},Ao.exports.unmask=function(e,r){e.length<32?yh(e,r):t.unmask(e,r)}}catch{}});var vh=oe((xC,Eh)=>{"use strict";var bh=Symbol("kDone"),hd=Symbol("kRun"),xd=class{constructor(e){this[bh]=()=>{this.pending--,this[hd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[hd]()}[hd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[bh])}}};Eh.exports=xd});var zr=oe((pC,kh)=>{"use strict";var Vi=le("zlib"),Sh=Ki(),_E=vh(),{kStatusCode:Ih}=Zt(),yE=Buffer[Symbol.species],bE=Buffer.from([0,0,255,255]),To=Symbol("permessage-deflate"),Jt=Symbol("total-length"),Br=Symbol("callback"),kn=Symbol("buffers"),Fr=Symbol("error"),ko,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,!ko){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ko=new _E(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[Br];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){ko.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){ko.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"?Vi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Vi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[To]=this,this._inflate[Jt]=0,this._inflate[kn]=[],this._inflate.on("error",vE),this._inflate.on("data",Ah)}this._inflate[Br]=i,this._inflate.write(e),r&&this._inflate.write(bE),this._inflate.flush(()=>{let c=this._inflate[Fr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=Sh.concat(this._inflate[kn],this._inflate[Jt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Jt]=0,this._inflate[kn]=[],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"?Vi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Vi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Jt]=0,this._deflate[kn]=[],this._deflate.on("data",EE)}this._deflate[Br]=i,this._deflate.write(e),this._deflate.flush(Vi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Sh.concat(this._deflate[kn],this._deflate[Jt]);r&&(c=new yE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Br]=null,this._deflate[Jt]=0,this._deflate[kn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};kh.exports=pd;function EE(t){this[kn].push(t),this[Jt]+=t.length}function Ah(t){if(this[Jt]+=t.length,this[To]._maxPayload<1||this[Jt]<=this[To]._maxPayload){this[kn].push(t);return}this[Fr]=new RangeError("Max payload size exceeded"),this[Fr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Fr][Ih]=1009,this.removeListener("data",Ah),this.reset()}function vE(t){if(this[To]._inflate=null,this[Fr]){this[Br](this[Fr]);return}t[Ih]=1007,this[Br](t)}});var Ur=oe((gC,Ro)=>{"use strict";var{isUtf8:Th}=le("buffer"),{hasBlob:SE}=Zt(),IE=[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 AE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function gd(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 kE(t){return SE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Ro.exports={isBlob:kE,isValidStatusCode:AE,isValidUTF8:gd,tokenChars:IE};if(Th)Ro.exports.isValidUTF8=function(t){return t.length<24?gd(t):Th(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=le("utf-8-validate");Ro.exports.isValidUTF8=function(e){return e.length<32?gd(e):t(e)}}catch{}});var bd=oe((mC,Nh)=>{"use strict";var{Writable:TE}=le("stream"),Rh=zr(),{BINARY_TYPES:RE,EMPTY_BUFFER:Ch,kStatusCode:CE,kWebSocket:PE}=Zt(),{concat:md,toArrayBuffer:DE,unmask:OE}=Ki(),{isValidStatusCode:LE,isValidUTF8:Ph}=Ur(),Co=Buffer[Symbol.species],ht=0,Dh=1,Oh=2,Lh=3,wd=4,_d=5,Po=6,yd=class extends TE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||RE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[PE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=ht}_write(e,r,i){if(this._opcode===8&&this._state==ht)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Co(i.buffer,i.byteOffset+e,i.length-e),new Co(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Co(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case ht:this.getInfo(e);break;case Dh:this.getPayloadLength16(e);break;case Oh:this.getPayloadLength64(e);break;case Lh:this.getMask();break;case wd:this.getData(e);break;case _d:case Po:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[Rh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=Dh:this._payloadLength===127?this._state=Oh: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=Lh:this._state=wd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=wd}getData(e){let r=Ch;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&&OE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=_d,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[Rh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let d=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===ht&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ht;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=md(i,r):this._binaryType==="arraybuffer"?o=DE(md(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ht):(this._state=Po,setImmediate(()=>{this.emit("message",o,!0),this._state=ht,this.startLoop(e)}))}else{let o=md(i,r);if(!this._skipUTF8Validation&&!Ph(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===_d||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ht):(this._state=Po,setImmediate(()=>{this.emit("message",o,!1),this._state=ht,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Ch),this.end();else{let i=e.readUInt16BE(0);if(!LE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Co(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Ph(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=ht;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ht):(this._state=Po,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ht,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[CE]=o,d}};Nh.exports=yd});var Sd=oe((_C,Fh)=>{"use strict";var{Duplex:wC}=le("stream"),{randomFillSync:NE}=le("crypto"),{types:{isUint8Array:ME}}=le("util"),Mh=zr(),{EMPTY_BUFFER:BE,kWebSocket:FE,NOOP:zE}=Zt(),{isBlob:Gr,isValidStatusCode:UE}=Ur(),{mask:Bh,toBuffer:Vn}=Ki(),xt=Symbol("kByteLength"),GE=Buffer.alloc(4),Do=8*1024,Zn,Hr=Do,St=0,HE=1,qE=2,Ed=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=St,this.onerror=zE,this[FE]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||GE,r.generateMask?r.generateMask(i):(Hr===Do&&(Zn===void 0&&(Zn=Buffer.alloc(Do)),NE(Zn,0,Do),Hr=0),i[0]=Zn[Hr++],i[1]=Zn[Hr++],i[2]=Zn[Hr++],i[3]=Zn[Hr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[xt]!==void 0?u=r[xt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let 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?(Bh(e,i,x,c,u),[x]):(Bh(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=BE;else{if(typeof e!="number"||!UE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(ME(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[xt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==St?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):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[xt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Gr(e)?this._state!==St?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==St?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[xt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Gr(e)?this._state!==St?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==St?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[Mh.extensionName],c=r.binary?2:1,d=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Gr(e)?(u=e.size,f=!1):(e=Vn(e),u=e.length,f=Vn.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={[xt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:d};Gr(e)?this._state!==St?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==St?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[xt],this._state=qE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(vd,this,u,o);return}this._bufferedBytes-=i[xt];let d=Vn(c);r?this.dispatch(d,r,i,o):(this._state=St,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(jE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Mh.extensionName];this._bufferedBytes+=i[xt],this._state=HE,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");vd(this,f,o);return}this._bufferedBytes-=i[xt],this._state=St,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===St&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][xt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][xt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Fh.exports=Ed;function vd(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 jE(t,e,r){vd(t,e,r),t.onerror(e)}});var Kh=oe((yC,$h)=>{"use strict";var{kForOnEventAttribute:Zi,kListener:Id}=Zt(),zh=Symbol("kCode"),Uh=Symbol("kData"),Gh=Symbol("kError"),Hh=Symbol("kMessage"),qh=Symbol("kReason"),qr=Symbol("kTarget"),jh=Symbol("kType"),Wh=Symbol("kWasClean"),Yt=class{constructor(e){this[qr]=null,this[jh]=e}get target(){return this[qr]}get type(){return this[jh]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Jn=class extends Yt{constructor(e,r={}){super(e),this[zh]=r.code===void 0?0:r.code,this[qh]=r.reason===void 0?"":r.reason,this[Wh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[zh]}get reason(){return this[qh]}get wasClean(){return this[Wh]}};Object.defineProperty(Jn.prototype,"code",{enumerable:!0});Object.defineProperty(Jn.prototype,"reason",{enumerable:!0});Object.defineProperty(Jn.prototype,"wasClean",{enumerable:!0});var jr=class extends Yt{constructor(e,r={}){super(e),this[Gh]=r.error===void 0?null:r.error,this[Hh]=r.message===void 0?"":r.message}get error(){return this[Gh]}get message(){return this[Hh]}};Object.defineProperty(jr.prototype,"error",{enumerable:!0});Object.defineProperty(jr.prototype,"message",{enumerable:!0});var Ji=class extends Yt{constructor(e,r={}){super(e),this[Uh]=r.data===void 0?null:r.data}get data(){return this[Uh]}};Object.defineProperty(Ji.prototype,"data",{enumerable:!0});var WE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Zi]&&o[Id]===e&&!o[Zi])return;let i;if(t==="message")i=function(c,d){let u=new Ji("message",{data:d?c:c.toString()});u[qr]=this,Oo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Jn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[qr]=this,Oo(e,this,u)};else if(t==="error")i=function(c){let d=new jr("error",{error:c,message:c.message});d[qr]=this,Oo(e,this,d)};else if(t==="open")i=function(){let c=new Yt("open");c[qr]=this,Oo(e,this,c)};else return;i[Zi]=!!r[Zi],i[Id]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Id]===e&&!r[Zi]){this.removeListener(t,r);break}}};$h.exports={CloseEvent:Jn,ErrorEvent:jr,Event:Yt,EventTarget:WE,MessageEvent:Ji};function Oo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Lo=oe((bC,Vh)=>{"use strict";var{tokenChars:Yi}=Ur();function Mt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function $E(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,f=-1,x=-1,p=-1,_=0;for(;_<t.length;_++)if(x=t.charCodeAt(_),d===void 0)if(p===-1&&Yi[x]===1)f===-1&&(f=_);else if(_!==0&&(x===32||x===9))p===-1&&f!==-1&&(p=_);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_);let w=t.slice(f,p);x===44?(Mt(e,w,r),r=Object.create(null)):d=w,f=p=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(p===-1&&Yi[x]===1)f===-1&&(f=_);else if(x===32||x===9)p===-1&&f!==-1&&(p=_);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_),Mt(r,t.slice(f,p),!0),x===44&&(Mt(e,d,r),r=Object.create(null),d=void 0),f=p=-1}else if(x===61&&f!==-1&&p===-1)u=t.slice(f,_),f=p=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(Yi[x]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);f===-1?f=_:i||(i=!0),o=!1}else if(c)if(Yi[x]===1)f===-1&&(f=_);else if(x===34&&f!==-1)c=!1,p=_;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(x===34&&t.charCodeAt(_-1)===61)c=!0;else if(p===-1&&Yi[x]===1)f===-1&&(f=_);else if(f!==-1&&(x===32||x===9))p===-1&&(p=_);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_);let w=t.slice(f,p);i&&(w=w.replace(/\\/g,""),i=!1),Mt(r,u,w),x===44&&(Mt(e,d,r),r=Object.create(null),d=void 0),u=void 0,f=p=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(f===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");p===-1&&(p=_);let v=t.slice(f,p);return d===void 0?Mt(e,v,r):(u===void 0?Mt(r,v,!0):i?Mt(r,u,v.replace(/\\/g,"")):Mt(r,u,v),Mt(e,d,r)),e}function KE(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(", ")}Vh.exports={format:KE,parse:$E}});var Fo=oe((SC,ox)=>{"use strict";var VE=le("events"),ZE=le("https"),JE=le("http"),Yh=le("net"),YE=le("tls"),{randomBytes:XE,createHash:QE}=le("crypto"),{Duplex:EC,Readable:vC}=le("stream"),{URL:Ad}=le("url"),Tn=zr(),ev=bd(),tv=Sd(),{isBlob:nv}=Ur(),{BINARY_TYPES:Zh,CLOSE_TIMEOUT:rv,EMPTY_BUFFER:No,GUID:iv,kForOnEventAttribute:kd,kListener:sv,kStatusCode:ov,kWebSocket:Ge,NOOP:Xh}=Zt(),{EventTarget:{addEventListener:av,removeEventListener:cv}}=Kh(),{format:dv,parse:lv}=Lo(),{toBuffer:uv}=Ki(),Qh=Symbol("kAborted"),Td=[8,13],Xt=["CONNECTING","OPEN","CLOSING","CLOSED"],fv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,me=class t extends VE{constructor(e,r,i){super(),this._binaryType=Zh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=No,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]),ex(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Zh.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let o=new ev({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new tv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ge]=this,c[Ge]=this,e[Ge]=this,o.on("conclude",pv),o.on("drain",gv),o.on("error",mv),o.on("message",wv),o.on("ping",_v),o.on("pong",yv),c.onerror=bv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",rx),e.on("data",Bo),e.on("end",ix),e.on("error",sx),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[Tn.extensionName]&&this._extensions[Tn.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){ct(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())}),nx(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){Rd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||No,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){Rd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||No,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){Rd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Tn.extensionName]||(o.compress=!1),this._sender.send(e||No,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ct(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(me,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(me.prototype,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(me,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(me.prototype,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(me,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(me.prototype,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(me,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});Object.defineProperty(me.prototype,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(me.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(me.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[kd])return e[sv];return null},set(e){for(let r of this.listeners(t))if(r[kd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[kd]:!0})}})});me.prototype.addEventListener=av;me.prototype.removeEventListener=cv;ox.exports=me;function ex(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:rv,protocolVersion:Td[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Td.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Td.join(", ")})`);let c;if(e instanceof Ad)c=e;else try{c=new Ad(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let 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;Mo(t,I);return}let x=d?443:80,p=XE(16).toString("base64"),_=d?ZE.request:JE.request,v=new Set,w;if(o.createConnection=o.createConnection||(d?xv:hv),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":p,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(w=new Tn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=dv({[Tn.extensionName]:w.offer()})),r.length){for(let I of r){if(typeof I!="string"||!fv.test(I)||v.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");v.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 E;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,T]of Object.entries(I))i.headers[A.toLowerCase()]=T}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),E=t._req=_(o),t._redirects&&t.emit("redirect",t.url,E)}else E=t._req=_(o);o.timeout&&E.on("timeout",()=>{ct(t,E,"Opening handshake has timed out")}),E.on("error",I=>{E===null||E[Qh]||(E=t._req=null,Mo(t,I))}),E.on("response",I=>{let A=I.headers.location,T=I.statusCode;if(A&&o.followRedirects&&T>=300&&T<400){if(++t._redirects>o.maxRedirects){ct(t,E,"Maximum redirects exceeded");return}E.abort();let D;try{D=new Ad(A,e)}catch{let C=new SyntaxError(`Invalid URL: ${A}`);Mo(t,C);return}ex(t,D,r,i)}else t.emit("unexpected-response",E,I)||ct(t,E,`Unexpected server response: ${I.statusCode}`)}),E.on("upgrade",(I,A,T)=>{if(t.emit("upgrade",I),t.readyState!==me.CONNECTING)return;E=t._req=null;let D=I.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){ct(t,A,"Invalid Upgrade header");return}let y=QE("sha1").update(p+iv).digest("base64");if(I.headers["sec-websocket-accept"]!==y){ct(t,A,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],O;if(C!==void 0?v.size?v.has(C)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":v.size&&(O="Server sent no subprotocol"),O){ct(t,A,O);return}C&&(t._protocol=C);let M=I.headers["sec-websocket-extensions"];if(M!==void 0){if(!w){ct(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let N;try{N=lv(M)}catch{ct(t,A,"Invalid Sec-WebSocket-Extensions header");return}let Z=Object.keys(N);if(Z.length!==1||Z[0]!==Tn.extensionName){ct(t,A,"Server indicated an extension that was not requested");return}try{w.accept(N[Tn.extensionName])}catch{ct(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Tn.extensionName]=w}t.setSocket(A,T,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(E,t):E.end()}function Mo(t,e){t._readyState=me.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function hv(t){return t.path=t.socketPath,Yh.connect(t)}function xv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Yh.isIP(t.host)?"":t.host),YE.connect(t)}function ct(t,e,r){t._readyState=me.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ct),e.setHeader?(e[Qh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Mo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Rd(t,e,r){if(e){let i=nv(e)?e.size:uv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Xt[t.readyState]})`);process.nextTick(r,i)}}function pv(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",Bo),process.nextTick(tx,r._socket),t===1005?r.close():r.close(t,e))}function gv(){let t=this[Ge];t.isPaused||t._socket.resume()}function mv(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",Bo),process.nextTick(tx,e._socket),e.close(t[ov])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Jh(){this[Ge].emitClose()}function wv(t,e){this[Ge].emit("message",t,e)}function _v(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Xh),e.emit("ping",t)}function yv(t){this[Ge].emit("pong",t)}function tx(t){t.resume()}function bv(t){let e=this[Ge];e.readyState!==me.CLOSED&&(e.readyState===me.OPEN&&(e._readyState=me.CLOSING,nx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function nx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function rx(){let t=this[Ge];if(this.removeListener("close",rx),this.removeListener("data",Bo),this.removeListener("end",ix),t._readyState=me.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Jh),t._receiver.on("finish",Jh))}function Bo(t){this[Ge]._receiver.write(t)||this.pause()}function ix(){let t=this[Ge];t._readyState=me.CLOSING,t._receiver.end(),this.end()}function sx(){let t=this[Ge];this.removeListener("error",sx),this.on("error",Xh),t&&(t._readyState=me.CLOSING,this.destroy())}});var lx=oe((AC,dx)=>{"use strict";var IC=Fo(),{Duplex:Ev}=le("stream");function ax(t){t.emit("close")}function vv(){!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 Sv(t,e){let r=!0,i=new Ev({...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(ax,i);return}let d=!1;t.once("error",function(f){d=!0,c(f)}),t.once("close",function(){d||c(o),process.nextTick(ax,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",vv),i.on("error",cx),i}dx.exports=Sv});var Cd=oe((kC,ux)=>{"use strict";var{tokenChars:Iv}=Ur();function Av(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&Iv[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}ux.exports={parse:Av}});var _x=oe((RC,mx)=>{"use strict";var kv=le("events"),zo=le("http"),{Duplex:TC}=le("stream"),{createHash:Tv}=le("crypto"),fx=Lo(),Yn=zr(),Rv=Cd(),Cv=Fo(),{CLOSE_TIMEOUT:Pv,GUID:Dv,kWebSocket:Ov}=Zt(),Lv=/^[+/0-9A-Za-z]{22}==$/,hx=0,xx=1,gx=2,Pd=class extends kv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Pv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Cv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=zo.createServer((i,o)=>{let c=zo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Nv(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=hx}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===gx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Xi,this);return}if(e&&this.once("close",e),this._state!==xx)if(this._state=xx,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(Xi,this):process.nextTick(Xi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Xi(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",px);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Xn(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){Xn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!Lv.test(c)){Xn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Xn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Qi(r,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=Rv.parse(f)}catch{Xn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let p=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&p!==void 0){let v=new Yn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let w=fx.parse(p);w[Yn.extensionName]&&(v.accept(w[Yn.extensionName]),_[Yn.extensionName]=v)}catch{Xn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let v={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(v,(w,E,I,A)=>{if(!w)return Qi(r,E||401,I,A);this.completeUpgrade(_,c,x,e,r,i,o)});return}if(!this.options.verifyClient(v))return Qi(r,401)}this.completeUpgrade(_,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[Ov])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>hx)return Qi(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Tv("sha1").update(r+Dv).digest("base64")}`],p=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(x.push(`Sec-WebSocket-Protocol: ${_}`),p._protocol=_)}if(e[Yn.extensionName]){let _=e[Yn.extensionName].params,v=fx.format({[Yn.extensionName]:[_]});x.push(`Sec-WebSocket-Extensions: ${v}`),p._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),c.removeListener("error",
|
|
16
|
+
`)),c.removeListener("error",px),p.setSocket(c,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(p),p.on("close",()=>{this.clients.delete(p),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Xi,this)})),u(p,o)}};mx.exports=Pd;function Nv(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function Xi(t){t._state=gx,t.emit("close")}function px(){this.destroy()}function Qi(t,e,r,i){r=r||zo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${zo.STATUS_CODES[e]}\r
|
|
17
17
|
`+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
|
|
18
18
|
`)+`\r
|
|
19
19
|
\r
|
|
20
|
-
`+r)}function Zn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Zn),t.emit("wsClientError",l,r,e)}else Zi(r,i,o,c)}});var mh=ce(Te=>{"use strict";var M=U;function U(t,e){t=t-260;let r=Wo(),i=r[t];if(U.kgmvAg===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",_="";for(let I=0,y,S,A=0;S=x.charAt(A++);~S&&(y=I%4?y*64+S:S,I++%4)?w+=String.fromCharCode(255&y>>(-2*I&6)):0)S=p.indexOf(S);for(let I=0,y=w.length;I<y;I++)_+="%"+("00"+w.charCodeAt(I).toString(16)).slice(-2);return decodeURIComponent(_)};U.PXmQyz=o,U.fAUtys={},U.kgmvAg=!0}let c=r[0],l=t+c,u=U.fAUtys[l];return u?i=u:(i=U.PXmQyz(i),U.fAUtys[l]=i),i}(function(t,e){let r=U,i=t();for(;;)try{if(parseInt(r(1637))/1+-parseInt(r(994))/2+-parseInt(r(1699))/3*(parseInt(r(688))/4)+parseInt(r(1620))/5*(parseInt(r(1167))/6)+-parseInt(r(520))/7*(parseInt(r(1807))/8)+parseInt(r(826))/9*(parseInt(r(1072))/10)+parseInt(r(1475))/11*(parseInt(r(695))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Wo,747792);var Sb=Object[M(640)+"operty"],Ib=Object[M(742)+"opertyNames"],fh=(t,e)=>function(){return t&&(e=(0,t[{ZidkW:function(c,l){return c(l)}}[M(530)](Ib,t)[0]])(t=0)),e},Ab=(t,e)=>{let r=M,i={ziwLo:function(c,l,u,x){return c(l,u,x)}};for(var o in e)i[r(1581)](Sb,t,o,{get:e[o],enumerable:!0})};function Tb(){return ah||(ah=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Cb(){let t=M;return ch||(ch=[IDBCursor.prototype[t(734)],IDBCursor.prototype[t(1764)],IDBCursor[t(1587)+"e"][t(1764)+t(739)+"ey"]])}function Rb(t){let e=M,r={tvyPE:e(379),LPPlO:e(1786),GImsy:function(o,c){return o(c)},taerK:function(o,c){return o+c},BMsVk:function(o,c){return o===c},vdAfc:"pQNiu",XvxUC:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={eZpWN:r[l(1319)],IclYK:function(_){return _()}},x=()=>{let _=l;t["removeEv"+_(518)+"ner"](u.eZpWN,p),t[_(1785)+_(518)+_(663)]("error",w)},p=()=>{o(Mt(t[l(1367)])),x()},w=()=>{let _=l;c(t[_(1786)]),u[_(514)](x)};t[l(469)+l(286)](l(379),p),t[l(469)+l(286)](r[l(1449)],w)});return i[e(313)](o=>{let c=e;if(r[c(879)](r[c(581)],c(1307))){let u=""+_0x586a24[c(795)](),x=_0x21e144||(_0x1d15f2=r[c(1619)](_0x534f10,_0x3dc3e6)),p=_0x25f6ca[c(1546)]()[c(589)](16).slice(-6);return r[c(506)](r[c(506)](r.taerK("02",u),x),p)}else r[c(747)](o,IDBCursor)&&Rd[c(1462)](o,t)})[e(1765)](()=>{}),Ho[e(1462)](i,t),i}function kb(t){let e=M,r={NbtAV:function(o,c){return o===c},yOhhw:e(1803),kKaKZ:e(1020),ywlLX:"error",GPJqC:"abort"};if(Go[e(1614)](t))return;let i=new Promise((o,c)=>{let l=e,u={RNaDT:function(_,I){return r[U(883)](_,I)},YIKAA:r.yOhhw,GXmmg:l(1786),oMrkp:"abort",lWoZN:function(_){return _()},TRYnE:l(347)+"or"},x=()=>{let _=l;u.RNaDT(u[_(1348)],_(1803))?(t[_(1785)+"entListe"+_(663)](_(1020),p),t[_(1785)+_(518)+_(663)](u[_(487)],w),t[_(1785)+_(518)+_(663)](u[_(1801)],w)):(this[_(736)+"igatorOn"+_(1187)]=_0x3af49a,_0x17b096?this[_(1480)+"nLine"]():this[_(1480)+_(919)]())},p=()=>{let _=l;u.lWoZN(o),u[_(1397)](x)},w=()=>{let _=l;c(t.error||new DOMException(u.TRYnE,u[_(584)])),x()};t[l(469)+"Listener"](r[l(454)],p),t[l(469)+l(286)](r[l(1200)],w),t[l(469)+l(286)](r[l(1400)],w)});Go.set(t,i)}function Db(t){jo={Altwz:function(i,o){return i(o)}}[M(546)](t,jo)}function Pb(t){let e=M,r={mKoIQ:function(i,o){return i(o)},xTkNs:function(i,o){return i(o)},iHLjy:function(i,o){return i(o)},YLSJO:"objectSt"+e(1224),MKIDc:function(i){return i()}};return t===IDBDatabase.prototype["transact"+e(1234)]&&!(r[e(1819)]in IDBTransaction.prototype)?function(i,...o){let c=e,l=t[c(307)](r[c(1703)](Yi,this),i,...o);return Cd[c(1462)](l,i[c(1326)]?i.sort():[i]),r[c(1703)](Mt,l)}:r[e(269)](Cb).includes(t)?function(...i){let o=e;return t[o(1259)](r[o(1340)](Yi,this),i),r[o(1703)](Mt,Rd[o(495)](this))}:function(...i){let o=e;return Mt(t[o(1259)](r[o(1163)](Yi,this),i))}}function Ob(t){let e=M,r={MhXAj:function(i,o){return i===o},NNPuh:"function",dKZZV:function(i,o){return i(o)},frqKd:function(i,o,c){return i(o,c)}};return r[e(1051)](typeof t,r[e(1272)])?r.dKZZV(Pb,t):(t instanceof IDBTransaction&&kb(t),r[e(791)](xh,t,Tb())?new Proxy(t,jo):t)}function Mt(t){let e=M,r={NXfJm:function(o,c){return o instanceof c},cYUnm:function(o,c){return o(c)},awwdE:function(o,c){return o!==c},tbuDI:e(486)};if(r.NXfJm(t,IDBRequest))return Rb(t);if(Uo[e(1614)](t))return Uo[e(495)](t);let i=r[e(732)](Ob,t);if(r.awwdE(i,t))if(e(613)!==r[e(1256)])Uo[e(1462)](t,i),Ho[e(1462)](i,t);else return this[e(393)]?.[e(1462)]({message_id:_0x265bc5,timestamp:_0x4fa8e4});return i}var xh,ah,ch,Rd,Go,Cd,Uo,Ho,jo,Yi,dh=fh({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={ILGEn:function(r,i){return r===i},tyswK:"done",Zrmao:function(r,i){return r===i},PcHjj:t(1173)+t(1224),Yspat:function(r,i){return r instanceof i},IWSOd:function(r,i){return r===i},iWahb:t(1075),lXNLK:function(r,i){return r in i}};xh=(r,i)=>i[t(1839)](o=>r instanceof o),Rd=new WeakMap,Go=new WeakMap,Cd=new WeakMap,Uo=new WeakMap,Ho=new WeakMap,jo={get(r,i,o){let c=t;if(r instanceof IDBTransaction){if(e.ILGEn(i,e[c(1091)]))return Go.get(r);if(e[c(1598)](i,e[c(1552)]))return r[c(1173)+"oreNames"]||Cd.get(r);if(e[c(1112)](i,c(1075)))return o[c(1173)+c(1224)][1]?void 0:o[c(1173)+c(860)](o[c(1173)+"oreNames"][0])}return Mt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(877)](r,IDBTransaction)&&(e[o(757)](i,e[o(1091)])||i===e[o(1695)])?!0:e[o(907)](i,r)}},Yi=r=>Ho[t(495)](r)}}),hh={};Ab(hh,{deleteDB:()=>Nb,openDB:()=>Lb,unwrap:()=>Yi,wrap:()=>Mt});function Lb(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=M,u={vTruz:function(w,_,I,y,S){return w(_,I,y,S)},ShbvR:function(w,_){return w(_)},FEcCk:function(w,_){return w(_)},vlUBj:l(1811),xbVbD:l(1361)+l(807),SbdSO:function(w,_){return w(_)},CaUtI:"upgraden"+l(1464)},x=indexedDB[l(477)](t,e),p=u[l(1426)](Mt,x);return i&&x[l(469)+l(286)](u[l(1343)],w=>{let _=l;u[_(344)](i,u.ShbvR(Mt,x.result),w[_(390)+"on"],w[_(802)+"on"],u[_(809)](Mt,x[_(381)+_(1234)]))}),r&&x[l(469)+"Listener"](l(1412),()=>r()),p[l(313)](w=>{let _=l;c&&w[_(469)+_(286)](u[_(1641)],()=>c()),o&&w[_(469)+_(286)](u[_(318)],()=>o())})[l(1765)](()=>{}),p}function Nb(t,{blocked:e}={}){let r=M,i={HiIzu:function(c,l){return c(l)}},o=indexedDB[r(1746)+r(1427)](t);return e&&o[r(469)+r(286)](r(1412),()=>e()),i.HiIzu(Mt,o)[r(313)](()=>{})}function lh(t,e){let r=M,i={tKwOc:function(x,p){return x+p},nJVUW:r(781)+"e",FTxsO:r(272),KaJpU:function(x,p){return x instanceof p},EgTNW:function(x,p){return x in p},IUsqP:"string",aAfFy:"AChpz",RHvud:function(x,p){return x!==p}};if(!(i[r(1611)](t,IDBDatabase)&&!i[r(1417)](e,t)&&typeof e===i[r(645)]))return i[r(792)]!==i[r(792)]?_0x529497[r(1491)+"8"]?{value:_0x5b7329[r(1491)+"8"](_0x5d5901),offset:i[r(1022)](_0x554e66,1)}:{value:255&_0x3932b5[_0x53037b],offset:_0xa9beee+1}:void 0;if(qo[r(495)](e))return qo[r(495)](e);let o=e[r(1299)](/FromIndex$/,""),c=i[r(1317)](e,o),l=gh[r(1037)](o);if(!(o in(c?IDBIndex:IDBObjectStore).prototype)||!(l||ph[r(1037)](o)))return;let u=async function(x,...p){let w=r,_=this.transaction(x,l?i[w(938)]:i.FTxsO),I=_[w(1075)];return c&&(I=I.index(p[w(1252)]())),(await Promise.all([I[o](...p),l&&_[w(1715)]]))[0]};return qo[r(1462)](e,u),u}var ph,gh,qo,Mb=fh({"node_modules/idb/build/index.js"(){let t=M,e={kcADM:t(495),PVjkx:"getKey",zwMMG:"getAll",peKfh:t(590),WhBct:function(o){return o()},fdjBI:function(o){return o()},FdaRb:t(1543),OvUCi:t(1375),DyQUr:function(o,c){return o(c)}},r=(t(1292)+t(779))[t(485)]("|"),i=0;for(;;){switch(r[i++]){case"0":ph=[e.kcADM,e.PVjkx,e.zwMMG,t(1787)+"ys",e[t(1243)]];continue;case"1":qo=new Map;continue;case"2":e[t(1313)](dh);continue;case"3":e.fdjBI(dh);continue;case"4":gh=[e[t(1288)],e[t(1610)],t(1289),t(724)];continue;case"5":e.DyQUr(Db,o=>({...o,get:(c,l,u)=>lh(c,l)||o[t(495)](c,l,u),has:(c,l)=>!!lh(c,l)||o[t(1614)](c,l)}));continue}break}}}),Bb={idb:function(t){let e=M;t[e(1518)]=Promise[e(1380)]()[e(313)](()=>(Mb(),hh))[e(313)](function(r){return r})}},uh={};function Nt(t){let e=M,r=(e(1768)+"4")[e(485)]("|"),i=0;for(;;){switch(r[i++]){case"0":var o=uh[t];continue;case"1":Bb[t](c,c[e(1518)],Nt);continue;case"2":if(o!==void 0)return o[e(1518)];continue;case"3":var c=uh[t]={exports:{}};continue;case"4":return c[e(1518)]}break}}Nt.d=(t,e)=>{let r=U;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(640)+"operty"](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;Nt.o=(e,r)=>Object.prototype[t(778)+t(1418)][t(307)](e,r)})(),(()=>{let t=M,e={NXncX:function(r,i){return r!=i},TNREe:"undefined",XKQiK:"Module",ZSupc:t(1350)+"le"};Nt.r=r=>{let i=t;e.NXncX(e[i(671)],typeof Symbol)&&Symbol[i(589)+i(1477)]&&Object[i(640)+i(1418)](r,Symbol[i(589)+"Tag"],{value:e[i(1080)]}),Object[i(640)+"operty"](r,e[i(1798)],{value:!0})}})();var De={};(()=>{let t=M,e={HqhCK:function(a,n){return a+n},pNTzN:function(a,n,s){return a(n,s)},twbKD:function(a,n){return a!==n},GmZmf:t(453),ECNVC:function(a,n){return a+n},rdgeD:function(a,n,s){return a(n,s)},bWOWY:function(a,n){return a>>>n},Ayynb:function(a,n){return a<<n},Lhpxo:function(a,n){return a===n},alduN:t(513),QMELo:function(a,n){return a(n)},dItbP:function(a,n){return a+n},DazdF:function(a,n){return a(n)},WBQQr:t(1648),xBktF:t(1177),HPsCR:function(a,n){return a(n)},iGmVh:function(a,n){return a(n)},qfxsz:"00000000"+t(1718)+t(1718)+t(1718),arNWu:"received",jIWVK:function(a){return a()},RmxVy:function(a,n){return a>n},SRNot:function(a,n){return a<n},uSymE:function(a,n){return a!==n},rVenx:t(1226),xraOu:t(996),DIgHd:function(a,n){return a!==n},LZndK:function(a,n){return a-n},zSaID:t(1459),aZFqj:function(a,n){return a-n},Kzcev:function(a,n){return a<n},CqIiE:function(a,n){return a<n},MfwGN:function(a,n){return a!==n},YehPM:function(a,n){return a!==n},xmKyJ:function(a,n,s){return a(n,s)},sQcZz:function(a,n,s){return a(n,s)},gxBbr:function(a,n){return a(n)},BhkPH:function(a,n){return a(n)},BnYxn:function(a,n){return a(n)},YRBOk:function(a,n,s){return a(n,s)},ltfMC:t(933)+t(1458)+t(958)+t(740),VTZmq:function(a,n,s){return a(n,s)},GmUFg:function(a,n){return a+n},UGTVR:function(a,n){return a>n},rKqZJ:function(a,n){return a*n},rjPpJ:function(a,n){return a>n},WlTbG:t(831),XLHmu:function(a,n){return a!==n},bCFHv:t(1492),HFEYt:function(a,n,s){return a(n,s)},bdiWn:function(a,n,s){return a(n,s)},IlUWA:function(a,n){return a!==n},BlzqT:function(a,n,s){return a(n,s)},FZusK:function(a,n){return a(n)},yFEzt:function(a,n){return a(n)},ISeRs:function(a,n){return a!==n},BuIQL:"USjSV",mRCoL:t(1063),PgAlz:function(a){return a()},niXwV:function(a,n,s){return a(n,s)},uiVIh:function(a,n){return a(n)},bwJqw:function(a,n,s){return a(n,s)},hqXkm:function(a,n){return a!==n},agylE:function(a,n){return a===n},LpLzt:t(471),lAzvy:function(a,n,s){return a(n,s)},mRixc:function(a,n,s){return a(n,s)},wcCNf:function(a,n){return a!==n},VTMOG:function(a,n,s){return a(n,s)},pFYEO:function(a,n,s){return a(n,s)},xRDFU:function(a,n){return a!==n},VSRYp:function(a,n,s){return a(n,s)},JAKpO:function(a,n,s){return a(n,s)},RqfCJ:function(a,n){return a(n)},EIlnW:function(a,n){return a|n},hBcKU:function(a,n){return a<<n},ABqVE:function(a,n){return a<<n},maKUa:function(a,n){return a<<n},yLqBN:function(a,n){return a|n},kwNHo:t(1606),yGweM:function(a,n){return a(n)},jNYAs:function(a,n){return a(n)},bYhJm:function(a,n){return a(n)},ZEDNX:function(a,n){return a(n)},ljmph:function(a,n,s){return a(n,s)},tjMyl:t(933)+t(1458)+t(958)+t(1248),QvQiS:function(a,n){return a===n},qWKPg:t(933)+t(1458)+t(958)+t(315),DWDwH:t(933)+t(1458)+t(958)+t(965),kutmg:function(a,n){return a(n)},ahOxE:t(646),bnFLI:function(a,n){return a&n},pCiqs:function(a,n,s){return a(n,s)},BxyXZ:t(422)+t(1709)+"pe: ",yHClv:function(a,n){return a>>n},ZoQHI:function(a,n){return a>=n},HNSTt:t(475)+"t limit",NiSwa:function(a,n){return a+n},VUYex:function(a,n){return a>n},YjPaW:function(a,n){return a*n},BIXfF:function(a,n){return a>n},xbZKY:t(1586)+t(1108),WzQzy:function(a,n){return a&n},oiUdr:function(a,n){return a&n},zWOjt:function(a,n){return a&n},PTwgo:"knElf",FAgPE:function(a,n,s){return a(n,s)},YINJH:function(a,n){return a>>>n},aVvyR:t(1154)+t(467),eSUyu:function(a,n){return a+n},Qlnem:function(a,n){return a&n},EHVMg:function(a,n){return a===n},yoKFz:function(a,n){return a>>n},ARLUN:function(a,n){return a&n},NVPHa:function(a,n){return a&n},SHCRj:function(a,n){return a|n},XYbXD:function(a,n){return a>>n},jWbbT:function(a,n){return a|n},rVUAE:function(a,n){return a|n},xdkXd:function(a,n){return a+n},DJtfD:function(a,n){return a===n},piOmp:function(a,n){return a&n},mAGbB:function(a,n){return a(n)},ScQdv:function(a,n){return a+n},Kgnki:t(1444),vzIUF:function(a,n){return a|n},klGgM:function(a,n){return a<<n},GNyDT:function(a,n){return a&n},VsmTi:function(a,n){return a<n},AfbRl:t(903),iUNeq:function(a,n){return a==n},usdmp:function(a,n){return a&n},eJJWB:function(a,n){return a+n},aSYjR:"XJcef",EFHhC:t(1066),JGNiW:function(a,n){return a+n},zuwZq:function(a,n){return a<<n},ttOMv:function(a,n){return a<<n},KrUMF:function(a,n){return a>=n},kSkOg:function(a,n){return a<=n},JVcxu:function(a,n){return a&n},iPMIH:function(a,n){return a+n},pclbd:function(a,n){return a+n},IJHUn:function(a,n){return a+n},vcaWk:function(a,n){return a+n},yuMPo:function(a,n){return a!==n},rXBbM:function(a,n){return a&n},wdewy:function(a,n){return a<<n},wsGly:function(a,n){return a&n},VtMbp:function(a,n){return a<<n},CSeXx:function(a,n){return a&n},utYDx:function(a,n){return a<n},Ifvov:function(a,n){return a+n},RyPKq:t(763),duUKJ:function(a,n){return a<=n},cqbRZ:function(a,n){return a-n},FSuYs:function(a,n){return a<n},JfsgA:function(a,n){return a<n},wbxnD:function(a,n,s){return a(n,s)},cqPZw:function(a,n,s){return a(n,s)},ngTIG:function(a,n){return a>=n},sxEia:function(a,n){return a<=n},iVQHe:function(a,n){return a<<n},rdBrH:function(a,n){return a|n},UjQqV:function(a,n){return a&n},iqsqy:function(a,n){return a>>n},FvoHI:function(a,n){return a<n},TvfeO:function(a,n){return a&n},VFKaD:function(a,n){return a>>n},NQHHB:function(a,n){return a|n},YKdHh:function(a,n,s){return a(n,s)},IfZpk:"gvCYQ",atNdM:function(a,n,s){return a(n,s)},zqhHX:function(a,n){return a<<n},GtFPV:function(a,n){return a&n},FAgqv:t(1436),ZSmsG:function(a,n){return a|n},ZwOLd:function(a,n,s){return a(n,s)},dbmMd:function(a,n){return a||n},PfLwo:t(856)+t(798)+t(716)+t(1221)+t(963),XzuLi:function(a,n){return a&n},qOMtN:function(a,n){return a(n)},ruzXs:function(a,n){return a&n},RdgLy:function(a,n){return a(n)},spBtQ:function(a,n){return a===n},RsdeJ:"tdQny",KNuyQ:function(a,n){return a(n)},yTOJt:function(a,n){return a&n},ihxmG:function(a,n){return a&n},WKRCh:function(a,n){return a&n},jKlDo:function(a,n){return a&n},DhISS:function(a,n){return a&n},EbMOt:function(a,n){return a&n},UjSLl:t(1215),TJkcr:function(a,n){return a&n},qdsxt:function(a,n){return a&n},oCCaD:function(a,n){return a|n},kxrrL:function(a,n){return a<<n},uetJf:function(a,n){return a<<n},hijMo:function(a,n){return a|n},jHUuD:function(a,n){return a>>>n},RlULf:function(a,n){return a<<n},MwFHA:function(a,n){return a===n},IZnXu:function(a,n){return a<n},jVfDQ:function(a,n){return a<n},ORLlN:function(a,n){return a<n},Xqzdl:function(a,n){return a&n},FrJeU:function(a,n){return a|n},DQMHt:function(a,n){return a>>>n},GRYqX:function(a,n){return a&n},GgUiY:function(a,n){return a>>>n},Sdprb:function(a,n){return a+n},lSFqw:function(a,n){return a|n},LiJZr:function(a,n){return a&n},UOxnZ:function(a,n){return a|n},Krols:function(a,n){return a&n},urjKQ:function(a,n){return a|n},ohICC:function(a,n){return a&n},XEGDs:function(a,n){return a+n},RiXaE:function(a,n){return a|n},ssQui:function(a,n){return a|n},bkBje:function(a,n){return a>>>n},mZhyq:function(a,n){return a(n)},JPmIz:function(a,n){return a-n},uWVBM:t(1374),vXpFe:function(a,n){return a===n},bZekB:"kiMSI",wpGmo:"jFEay",benIp:function(a,n){return a===n},KFywX:t(1735)+"2|7|3|0|5|10|4",Jkkiw:t(746)+t(1651),eeapY:t(315),zSIju:t(1413)+"name",vCyng:t(1212),roqIX:t(1689),XUGGJ:function(a,n){return a(n)},NhANO:t(1771)+"ile_name",ydwAn:function(a,n){return a===n},BcxbL:t(1682),uhBuU:function(a,n){return a|n},VUkVX:function(a,n){return a<<n},gUwZg:function(a,n){return a<<n},Ycjsx:function(a,n){return a|n},CNFwr:function(a,n){return a<<n},mnaTY:function(a,n){return a|n},HqArt:function(a,n){return a|n},eiWWc:function(a,n){return a<<n},JqJNz:function(a,n){return a|n},zrSXe:function(a,n){return a===n},ifFgS:function(a,n){return a>>>n},TLfFT:function(a,n){return a|n},MttfT:function(a,n){return a<<n},TJQKt:function(a,n){return a<<n},mGAGf:function(a,n){return a>>>n},UZpZS:function(a,n){return a<<n},JEnXU:function(a,n){return a<<n},zuSul:function(a,n){return a>>>n},SBAAo:function(a,n){return a>>>n},XkCzq:function(a,n){return a&n},INtWZ:function(a,n){return a>>>n},bVJMK:function(a,n){return a&n},gkcdS:function(a,n){return a>>>n},ioRbN:function(a,n){return a(n)},qGSne:function(a,n){return a>=n},LKhyk:function(a,n){return a>=n},HnGnM:function(a,n){return a+n},KNoAK:function(a,n){return a%n},MfNRa:function(a,n){return a|n},RxnWN:function(a,n){return a+n},NbjTL:function(a,n){return a>>>n},clbnk:function(a,n){return a*n},dKiRI:function(a,n){return a>>>n},oKyja:function(a,n){return a&n},Mrxpq:function(a,n){return a>>>n},HCpMf:function(a,n){return a>>>n},TvsHg:function(a,n){return a|n},uTCtC:function(a,n){return a|n},gZJaO:function(a,n){return a<<n},AxOZf:function(a,n){return a===n},KndFb:function(a,n){return a>>>n},PfTvl:function(a,n){return a===n},gVRFy:"JnaVQ",oTJLF:function(a,n){return a===n},ibzmn:function(a,n){return a===n},UmAyS:function(a,n){return a===n},ntKHY:function(a,n){return a&n},YfHvv:function(a,n){return a&n},ZGvbq:t(526)+t(349)+"R",loKir:t(1053)+"OR",iBhMJ:"CONNECTI"+t(1018),NNwog:t(503)+t(1448),ZASHC:t(1392)+t(642),OnRJu:function(a,n){return a!==n},UXJUw:t(480),zReMl:"ynegh",LIFJf:function(a,n){return a|n},RfDOt:function(a,n){return a<<n},BnLuN:function(a,n){return a&n},sVLfK:function(a,n){return a>>n},XSLnS:function(a,n){return a+n},JwLvL:t(446),VyUkk:t(904),DifwT:"wxYuW",zuoMJ:t(749),cShbc:t(1209),BIcSZ:function(a,n){return a|n},bwkUL:function(a,n){return a|n},gEttg:function(a,n){return a===n},Sczcw:"vPddU",soSBV:function(a,n){return a===n},pBoae:t(271),AEoxA:t(1312),FjQjn:function(a,n){return a+n},WQyzm:function(a,n){return a+n},kLzoq:function(a,n){return a===n},ZUTgE:function(a,n){return a===n},EhCEs:function(a,n){return a<n},qLOJb:function(a,n){return a!==n},aTcfE:t(643),fbioT:t(1786),zVqPJ:t(1811),XhfBm:t(477),wWyYe:t(560),Iunlr:"aymKe",eafgm:"NJqtc",fXCGX:function(a,n){return a instanceof n},dbDgl:t(1594)+t(1455)+"|0|10|9|1",xrFVB:function(a,n){return a&n},qONAL:function(a,n){return a<n},ykgpW:function(a,n){return a|n},eyMtV:function(a,n){return a|n},WdHpj:t(370),zGiCm:function(a,n){return a(n)},BjZNV:t(713),vdHDd:" > ",wNKpX:t(1623)+"d",cWcRs:function(a,n){return a||n},HhfIZ:function(a,n){return a<=n},CFDxm:t(427)+t(1760)+t(1193)+t(1834)+t(1318),WjdUq:function(a,n){return a(n)},UyRBH:function(a,n){return a<n},DlTHL:function(a,n){return a<n},pqZqH:function(a,n){return a&n},FwjtW:function(a,n){return a&n},wqRQb:function(a,n){return a+n},IEQqY:function(a,n){return a|n},ZoyPM:function(a,n){return a|n},rxnEG:function(a,n){return a|n},cmfHv:function(a,n){return a|n},tQNlw:function(a,n){return a<<n},LdPnk:function(a,n){return a<<n},vQJtC:function(a,n){return a===n},YFCRS:"wECvc",BjYXE:"MBuDW",UtGeW:function(a,n){return a<n},ozUAI:function(a,n){return a|n},DMWMt:function(a,n){return a|n},YnTSY:function(a,n){return a+n},nfQjL:function(a,n){return a>>n},IwclK:function(a,n){return a&n},AWjIL:function(a,n){return a<n},uphEZ:function(a,n){return a|n},WSAcR:function(a,n){return a|n},LGwHa:function(a,n){return a===n},treEL:function(a,n){return a+n},sQLct:t(774)+t(1372),PgMEs:function(a,n){return a>>n},PuEqQ:function(a,n){return a&n},xLwdN:function(a,n){return a|n},kiFVx:function(a,n){return a|n},TYSOg:function(a,n){return a&n},FaMlV:function(a,n){return a>>n},hUNLs:function(a,n){return a+n},LVxAV:function(a,n){return a|n},dhjev:function(a,n){return a|n},tvUvt:function(a,n){return a&n},UXELW:function(a,n){return a==n},upusf:t(1572),PkPAh:function(a,n,s,d){return a(n,s,d)},aYowp:function(a,n){return a!==n},lzESh:t(372),GCpty:function(a,n){return a!=n},SeXOt:function(a,n){return a instanceof n},SbYRP:function(a,n){return a instanceof n},rJPGQ:t(696)+t(1393),ouVXJ:"text/pla"+t(1460)+"et=utf-8",AqDLc:function(a,n){return a===n},OMNuI:t(447),uoPqP:t(1065),xUNui:"ppe",NWfUy:function(a,n){return a>=n},bYkAX:t(1038)+"reason",cXOgR:t(1321)+t(1179),RYpKk:function(a,n){return a+n},ykjCk:t(588),Koqfi:"&jscallb"+t(821)+t(1439)+"P",PVcvp:t(1741),jCtVp:t(512),gxuzE:function(a,n){return a(n)},WUKpI:function(a,n){return a&n},nJGUd:function(a,n){return a|n},ILWuP:function(a,n){return a&n},ovnMb:function(a,n){return a(n)},IdqGY:"ckMGr",segEz:function(a,n){return a!==n},YkBcJ:t(788),KfOca:t(696)+t(1393)+t(329)+t(1117),isMan:t(1496)+"e",LtPtM:t(629),pzPNq:function(a,n,s,d){return a(n,s,d)},JpkfQ:function(a,n){return a!==n},fWWsd:t(979),rFivy:t(400),zzxrg:function(a,n){return a<=n},iCsor:function(a){return a()},gWKww:t(1308),Dmbed:function(a,n){return a|n},liBBw:function(a,n){return a&n},jyblR:function(a,n){return a&n},aefYh:function(a,n){return a&n},wtPmA:function(a,n){return a>=n},qmyxD:function(a,n){return a(n)},EIUug:"frngF",nTFiL:function(a,n,s){return a(n,s)},MCvuy:function(a,n){return a===n},obreH:"RkTCZ",EioFO:"CLmdG",yZNRG:"cursor_n"+t(981),rXIfy:function(a,n){return a!==n},VOtdw:t(1101),jVlvK:function(a,n){return a&n},QcwzC:function(a,n){return a!==n},mOFSU:t(320),gBzCH:function(a,n,s,d){return a(n,s,d)},SlSUO:function(a,n){return a===n},NdRRk:"ULkHs",dXIEt:function(a,n){return a||n},hJjeW:function(a,n){return a||n},QvrXr:function(a,n){return a===n},zyzjQ:t(633),eiEsY:"Adgid",XfOof:function(a,n){return a===n},jdwJQ:t(456),JzzAm:function(a,n){return a||n},VcvIl:function(a,n,s){return a(n,s)},hfoPN:function(a,n){return a!==n},WtbSq:"XtbsM",HLfxe:t(482),LgwWB:function(a,n){return a>n},fTCFL:t(984),IeYJq:t(999),gboas:function(a,n){return a!=n},IHXxU:"init QoS"+t(350)+"d",wKMVA:t(1599)+"id",dZqhb:t(408),abdsC:t(1686),ECOdJ:t(1355)+t(404)+"e",owmJU:t(857),msrkt:"paJKB",RgJen:function(a,n){return a!==n},Qtpro:"ZYVId",rLHNl:function(a,n){return a(n)},qwLLD:t(899)+t(1432),aWIlp:t(899)+"er_qos_ack",DqyPG:function(a,n,s,d){return a(n,s,d)},TxIQg:t(899)+t(955)+t(601),jXzAx:function(a,n,s){return a(n,s)},CFvAT:function(a,n){return a&&n},DRNRs:t(794),vSXvi:"is_ack",BvqAW:t(851),jtyec:t(1244),KYjLC:"qhVUZ",eqHqN:function(a){return a()},NyNET:function(a,n){return a===n},LiZPQ:t(1823),dxXKk:function(a,n){return a instanceof n},ZOeCp:function(a,n){return a instanceof n},xOgfI:function(a,n){return a<n},cDLGK:function(a,n){return a>n},rpyLr:function(a,n){return a&n},ygqjY:function(a,n){return a+n},oDSxK:function(a,n){return a|n},gEORo:function(a,n){return a(n)},ysvwE:function(a,n){return a+n},TBWDR:function(a,n){return a+n},aMxHH:function(a,n){return a+n},SYeQY:function(a,n){return a+n},tPaYu:function(a,n){return a>>>n},TRXUS:function(a,n){return a<<n},iEqVJ:t(828),JShGh:function(a,n){return a|n},vddCy:function(a,n){return a|n},McxnJ:function(a,n){return a<<n},DWmyR:function(a,n){return a<<n},dkyVL:function(a,n){return a+n},aHWyU:function(a,n){return a<<n},zDzqh:function(a,n){return a+n},XSTdz:function(a,n){return a|n},SfSbf:function(a,n){return a<<n},PLfJb:function(a,n){return a<<n},rSDSk:function(a,n){return a+n},MhUsr:function(a,n){return a+n},wgEJk:function(a,n){return a+n},hsyMa:function(a,n){return a>>>n},lYEcM:function(a,n){return a+n},CBrEK:function(a,n){return a&n},jwwKo:function(a,n){return a+n},HyIjo:function(a,n){return a&n},sQzKa:function(a,n){return a+n},BRLmA:function(a,n){return a&n},FpyNN:function(a,n){return a&n},pvVQL:function(a,n){return a>>>n},lDQMZ:function(a,n){return a<n},RCLqc:function(a,n){return a>n},bzKRr:function(a,n,s,d){return a(n,s,d)},pplPc:function(a,n){return a(n)},DUXyJ:t(744)+t(326)+"|1|6|4",HgMzu:t(962),JTDcM:t(991),xlWgz:function(a,n){return a<n},FIpBx:function(a,n,s){return a(n,s)},ZpfDW:function(a,n){return a+n},ifRcx:t(769)+t(1067),kIPvs:function(a,n){return a!==n},zORBo:"ALL",whlzG:t(598),AKoKi:t(997),GfEut:function(a,n,s,d){return a(n,s,d)},fYfbG:function(a,n){return a(n)},lbqEc:function(a,n){return a+n},YWggt:function(a,n){return a!==n},bQcjm:"npxjd",AcDOS:t(1780),SxkbL:function(a,n){return a(n)},CfScp:t(347)+"or",rqcZJ:function(a,n){return a===n},koSVv:t(1601),AtkpG:t(1129),NhTLV:function(a,n){return a===n},Qosbv:t(1097),QHSgI:function(a,n,s,d){return a(n,s,d)},XhOLy:t(363),aPUHZ:function(a,n,s,d){return a(n,s,d)},oCpKX:"x_fronti"+t(1149),sQfLb:t(1647)+"s",EeOwv:t(1188)+t(714)+"e",yazJs:function(a,n,s){return a(n,s)},wUZMb:t(1188)+t(361)+"ue",SnDgG:function(a,n){return a>n},kxShZ:function(a,n){return a+n},lhpXZ:function(a){return a()},KQMGS:function(a,n){return a<n},rYcjq:function(a){return a()},nORXP:function(a){return a()},SQwFK:function(a,n){return a===n},pNxoT:function(a){return a()},jqqwe:function(a){return a()},jTYdk:function(a){return a()},vmiOZ:function(a,n){return a(n)},FiqGa:function(a,n){return a(n)},PWTmK:function(a){return a()},opqWe:function(a){return a()},mlKnI:function(a,n){return a<n},arIpJ:function(a,n,s){return a(n,s)},xASTx:function(a){return a()},bGljO:"always",RNNil:"auto",IvogE:"ping_onc"+t(748)+"s",ctgqj:t(379),kNwYZ:function(a,n){return a===n},jiuhK:function(a,n,s,d){return a(n,s,d)},TgFNz:function(a,n,s){return a(n,s)},jekJt:t(790),IhaQo:t(1303),tmKmy:function(a,n){return a===n},RkIXf:function(a,n,s){return a(n,s)},EIzXk:"complete",LMyqm:"abort",OHuVe:t(888),imtFM:function(a,n,s){return a(n,s)},UvprQ:function(a,n){return a!==n},fIavF:function(a,n){return a(n)},XGlbG:function(a,n,s){return a(n,s)},HqNNr:t(765),GRXGv:function(a,n,s){return a(n,s)},uImMV:function(a,n){return a!==n},pRKpV:t(1482),MhRGt:function(a,n){return a/n},jmWrY:function(a,n){return a==n},cryhN:function(a,n){return a(n)},YdJgJ:t(875)+t(1563)+t(1742)+t(599)+"ket cons"+t(1385)+"is undef"+t(1624),hSojn:function(a,n){return a===n},pozHg:t(1213),hOlbn:t(415),dcOgi:t(346),Cugeh:t(716)+"t",Xgskg:t(1204)+t(1041)+" reconnect",vskjF:"nbZCL",JSeeh:t(693),uZExn:t(1162),sGNCW:"pagehide",ZIKBk:t(1011),wpxRY:function(a,n){return a===n},rwjgi:t(1230),aHJOH:function(a,n){return a(n)},idmCj:function(a,n){return a!==n},SaIWC:t(1377),RyOaW:t(1087),VVWig:t(319),hUdVA:t(1137),rkvqx:t(432),IeEPV:t(1116),VKtNB:"device_id",UeVfK:"please p"+t(1157)+t(1489)+t(1830)+t(1106),IkOBp:t(1454),TcnCk:t(448),MRZVj:t(574)+"0",cEJti:function(a,n,s){return a(n,s)},dDdQx:function(a,n,s){return a(n,s)},TlfYY:t(1452),ndOMo:t(489),KkKbP:function(a,n){return a||n},rkNqM:function(a,n,s){return a(n,s)},kvsIm:t(1774),xrdqt:function(a,n,s){return a(n,s)},kQRWh:function(a,n,s){return a(n,s)},XaRjI:t(1391)+t(1692)+"t",UnBAL:function(a,n){return a===n},APYfR:t(1379),uSgQj:t(1653),XMPiq:function(a,n){return a(n)},jvVrX:function(a,n){return a(n)},ugLgx:function(a,n){return a(n)},xcTnI:function(a,n){return a===n},sziKk:t(439),BqOko:t(1784),gZbMu:function(a,n){return a*n},vyRGo:function(a,n){return a-n},vuLRc:function(a,n){return a>n},RfoWP:function(a,n){return a===n},tVRpt:function(a,n){return a!==n},SSQZC:function(a,n,s){return a(n,s)},IwgbL:t(887),sOipo:function(a,n){return a===n},eLKiI:"zmlHd",JdZeH:"rLuiG",XmKvV:"timeout,"+t(1560)+t(912)+"g",qHXtm:t(1568),TLZnU:t(1350)+"le",GHgjV:t(1009),ixjHC:t(1676),TmaIj:t(920)+"0",XVKEC:"0|2|1|4|3",pHprs:t(856)+t(1390)+t(1532)+t(666),Mdueg:t(552),YXlNF:t(881)+"eeded",kqgEY:function(a,n,s,d,f){return a(n,s,d,f)},LdtxM:t(568),zUrIO:t(1551),cznJI:t(957),infsl:t(517)+"s instan"+t(710)+t(355)+"ed",oUoWP:function(a,n){return a===n},pZFZe:function(a,n){return a===n},cMvUp:t(517)+t(1337)+t(1781),oNkap:function(a,n){return a===n},LvfoO:"pyDwV",TCviy:t(875)+t(1369)+t(1138)+t(1636)+t(1579)+t(337)+"ng or an"+t(451)+t(906),PNuuc:t(262),QgjrN:function(a,n){return a(n)},yGXja:"please p"+t(1369)+t(884)+t(1651),qbYXN:function(a,n){return a instanceof n},AUDWB:function(a,n){return a(n)},yRNVV:"sent",tgIrD:function(a,n){return a<n},BWCZP:function(a,n){return a||n},DbnPo:function(a,n){return a!==n},dzlbR:t(1031)+"econnect"+t(498),tDMLB:t(586),xcTnD:t(1019)+"2",GwuWk:t(761),BVzjQ:"PNibt",RWgJG:t(1126),bUVaD:t(970),pntvF:"vLvmZ",IfpyK:function(a,n){return a(n)},esbEv:t(1580),iGmxr:function(a,n){return a!==n},AfYcr:function(a,n,s){return a(n,s)},ufhQr:t(1407),NdXtS:function(a,n){return a!=n},Acruh:t(1098),GOfww:function(a,n){return a!=n},SLXRC:"Object",yfBqU:t(431)+t(767)+t(441)+"pe",pMoHO:function(a,n){return a!=n},Iopuj:function(a,n){return a==n},BmATj:function(a,n){return a===n},tNOGp:function(a,n){return a!=n},yRCGe:function(a,n){return a!=n},TYBDJ:t(1793)+"qos__"};Nt.r(De),Nt.d(De,{FWS:()=>Yp,CustomErrorEvent:()=>Vd,createCloseEvent:()=>xt,ReconnectEvent:()=>$d,createErrorEvent:()=>at,decodedFrame:()=>Xt,createOpenEvent:()=>el,CustomCloseEvent:()=>Jd,createReconnectEvent:()=>da,FrontierMessageEvent:()=>Yd,encodeFrame:()=>Bt,createMessageEvent:()=>Qd,OpenEvent:()=>Xd,ErrorCode:()=>en,Event:()=>Qn,MessageEvent:()=>Zd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(795)](),f=r||(r=x(a)),h=Math[n(1546)]().toString(16).slice(-6);return e[n(1818)](s+d+f,h)}function o(){let a=t;if(e[a(1376)](a(453),e[a(1205)])){let n=e[a(535)](_0x4b3e09,_0x2488ac,_0x4da21e.length);_0x550d92[a(1122)][a(1462)](_0x5b9483,n)}else return e[a(1820)](1e4*Date[a(795)](),Math[a(873)](1e4*Math.random()))}function c(a){let n=t;if(e[n(362)](n(394),e[n(789)])){let{value:s,offset:d}=e[n(1713)](_0x2d3210,_0x202735,_0x5c157f);_0x11ffff=d,_0x534631=e[n(657)](e[n(1270)](_0x4418ca,8),0),_0x1df8e2+=s}else return e.ECNVC(e[n(1631)](Array,8)[n(939)]("0"),parseInt(a,10)[n(589)](2))[n(264)](-8)}function l(a){let n=t;return e[n(571)](e[n(1631)](Array,4)[n(939)]("0"),e[n(535)](parseInt,a,2)[n(589)](16)).slice(-4)}function u(a){let n=t,s=a[n(485)](/\./).map(h=>c(h)),d=[];return d[0]=e.QMELo(l,s[0]+s[1]),d[1]=e[n(1762)](l,s[2]+s[3]),[n(1648),e[n(1450)],e.WBQQr,n(1648),e[n(1450)],e[n(580)],d[0],d[1]][n(939)]("")}function x(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(521)](a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(521)](a);return s?e[n(457)](u,a):d?e.iGmVh(p,a):e[n(1012)]}function p(a){let n=t,s="",d=[],f=0,h=0,m=!0,b=e.WBQQr;if(e[n(1536)](a[n(822)]("::"),-1)){let g=a[n(485)]("::");for(let D=0;e[n(931)](D,g[n(1524)]);D++){let N=g[D];if(e[n(1536)](N.indexOf(":"),0))if(e[n(927)](e.rVenx,e.xraOu)){let H=N[n(485)](":");m&&(f=H[n(1524)]),h+=H[n(1524)];for(let J=0;e.SRNot(J,H[n(1524)]);J++)if(e[n(1387)](4,H[J].length)){let X=b.substring(0,e[n(1142)](4,H[J][n(1524)])),Q=X.concat(H[J]);d[n(354)](Q)}else d.push(H[J]);m=!1}else this._debug(e[n(1831)],_0x1acfbd.message),e[n(722)](_0x225dd2);else{if(e[n(1387)](4,N[n(1524)])){if(e.DIgHd(e[n(1544)],e[n(1544)]))return _0x536843+=_0x37cf44&&_0x28a0af.byteLength||0,_0x5f4812;{let H=b[n(292)+"g"](0,e.LZndK(4,N.length)),J=H[n(576)](N);d[n(354)](J)}}else d.push(N);m&&(f+=1),h+=1,m=!1}}let v="";for(let D=0;e.SRNot(D,e.aZFqj(8,h));D++)v=v.concat(b);for(let D=0;e[n(1443)](D,d[n(1524)]);D++)e[n(362)](D,f)?(s=s[n(576)](v),s=s[n(576)](d[D])):s=s.concat(d[D]);return s}{let g=a[n(485)](":");for(let v=0;e.CqIiE(v,g[n(1524)]);v++){let D=g[v];if(e.MfwGN(4,g[v][n(1524)])){let N=b[n(292)+"g"](0,e[n(392)](4,g[v][n(1524)])),H=N[n(576)](D);s=s.concat(H)}else s=s.concat(D)}return s}}function w(a,n){let s=t,d=a.key;d!==void 0&&(e[s(535)](pe,n,10),e[s(1713)](G,n,d));let f=a.value;e[s(754)](void 0,f)&&(e[s(1656)](pe,n,18),e[s(729)](G,n,f))}function _(a){let n=t,s={};e:for(;!e[n(1217)]($,a);){let d=e[n(855)](he,a);switch(e[n(657)](d,3)){case 0:break e;case 1:s[n(740)]=e[n(729)](L,a,e.BnYxn(he,a));break;case 2:s.value=e[n(1713)](L,a,he(a));break;default:e[n(1310)](R,a,7&d)}}if(s[n(740)]===void 0)throw new Error(e[n(1238)]);if(e[n(362)](void 0,s[n(1045)]))throw new Error("Missing required"+n(958)+n(1045));return s}function I(a){let n=t,s=e[n(722)](k);return e.VTZmq(y,a,s),e[n(1631)](B,s)}function y(a,n){let s=t;if(e[s(362)](e[s(1332)],"VCYKq"))_0x166459&&this[s(1258)+s(1127)][s(745)+"rsorFile"+s(1203)](_0x599175);else{let d=a[s(301)];e[s(1025)](void 0,d)&&(e[s(1376)](s(1255),e[s(1567)])?(e[s(1333)](pe,n,8),e[s(753)](ft,n,d)):this[s(896)+"T"]?_0x201b3b["onNetwor"+s(917)+s(807)](({isConnected:Q})=>{let ge=s;this[ge(736)+"igatorOn"+ge(1187)]=Q,Q?this[ge(1480)+ge(1331)]():this[ge(1480)+"ffLine"]()}):this._isMiniWX&&_0x5aaed2[s(1105)+"kStatusC"+s(807)](({isConnected:Q})=>{let ge=s;this[ge(736)+"igatorOn"+ge(1187)]=Q,Q?this["_handleO"+ge(1331)]():this[ge(1480)+ge(919)]()}));let f=a[s(1248)];e[s(1376)](void 0,f)&&(pe(n,16),e.YRBOk(ft,n,f));let h=a[s(315)];e.IlUWA(void 0,h)&&(pe(n,24),e[s(1245)](ft,n,e[s(1778)](P,h)));let m=a[s(965)];m!==void 0&&(pe(n,32),ft(n,e[s(1704)](P,m)));let b=a[s(296)];if(e.ISeRs(void 0,b))for(let Q of b){if(e[s(362)](e[s(1751)],e[s(815)]))return new _0x179886(_0x53aa64,_0x50e3af,_0x501800);{e[s(1713)](pe,n,42);let ge=e[s(1717)](k);e.xmKyJ(w,Q,ge),e.niXwV(pe,n,ge[s(523)]),e.sQcZz(K,n,ge),e.uiVIh(O,ge)}}let g=a[s(1239)+"ncoding"];g!==void 0&&(e[s(900)](pe,n,50),e[s(729)](G,n,g));let v=a[s(1001)+s(874)];if(e[s(536)](void 0,v))if(e[s(1082)](e[s(1816)],e.LpLzt))e[s(1437)](pe,n,58),e[s(1245)](G,n,v);else{let Q=_0x5c632d[s(1122)],ge=_0x198d26[s(1528)],is=_0x3d216e[s(523)],nn=e[s(1694)](ge,_0x202398);if(e.UGTVR(nn,Q[s(1524)])){let ss=new _0x3168f5(e.rKqZJ(2,nn));ss[s(1462)](Q),_0x449d30[s(1122)]=ss}return _0x2026ad[s(1528)]=nn,e[s(1470)](nn,is)&&(_0x2ade9f[s(523)]=nn),ge}let D=a[s(756)];e[s(754)](void 0,D)&&(e[s(1245)](pe,n,66),pe(n,D[s(1524)]),e[s(1310)](ae,n,D));let N=a.LogIDNew;N!==void 0&&(e[s(1333)](pe,n,74),e[s(1354)](G,n,N));let H=a["serverTi"+s(908)];e[s(1387)](void 0,H)&&(e[s(1310)](pe,n,82),G(n,H));let J=a[s(290)];e[s(737)](void 0,J)&&(e[s(1269)](pe,n,90),e[s(305)](G,n,J));let X=a[s(1145)+"e"];e[s(1673)](void 0,X)&&(e[s(617)](pe,n,96),e[s(735)](ft,n,e[s(1704)](P,X)))}}function S(a){let n=t;return e[n(1023)](A,e[n(1631)](F,a))}function A(a){let n=t;if(e.kwNHo===n(971))return new _0x29e8dc(e.EIlnW(e[n(426)](_0x24e250[4],24),e[n(654)](_0x155e20[5],16))|e.maKUa(_0xa2c4dc[6],8)|_0x4e952b[7],e[n(684)](e.yLqBN(e[n(1270)](_0x58d480[0],24),e[n(426)](_0x39a77c[1],16)),e[n(426)](_0x50acf1[2],8))|_0x4c69b5[3],_0x1d0201);{let s={};e:for(;!e.yGweM($,a);){let d=e[n(1704)](he,a);switch(e[n(657)](d,3)){case 0:break e;case 1:s.SeqID=e.BlzqT(vt,a,!0);break;case 2:s.LogID=vt(a,!0);break;case 3:s[n(315)]=e[n(1800)](he,a);break;case 4:s[n(965)]=e[n(457)](he,a);break;case 5:{let f=e[n(662)](T,a);(s.headers||(s[n(296)]=[]))[n(354)](_(a)),a[n(523)]=f;break}case 6:s.payloadEncoding=e[n(1333)](L,a,he(a));break;case 7:s[n(1001)+n(874)]=e[n(1656)](L,a,e[n(855)](he,a));break;case 8:s[n(756)]=e[n(535)](se,a,e[n(1748)](he,a));break;case 9:s[n(1658)]=e[n(305)](L,a,e.ZEDNX(he,a));break;case 10:s.serverTiming=e[n(1629)](L,a,e[n(1062)](he,a));break;case 11:s.msgID=e[n(1437)](L,a,he(a));break;case 12:s[n(1145)+"e"]=e[n(1062)](he,a);break;default:R(a,7&d)}}if(e.Lhpxo(void 0,s.SeqID))throw new Error(n(933)+n(1458)+n(958)+n(301));if(s.LogID===void 0)throw new Error(e[n(1431)]);if(e.QvQiS(void 0,s.service))throw new Error(e[n(1328)]);if(e[n(1278)](void 0,s[n(965)]))throw new Error(e[n(694)]);return s}}function T(a){let n=t,s=e.kutmg(he,a),d=a[n(523)];return a[n(523)]=e[n(1820)](a[n(1528)],s),d}function R(a,n){let s=t;if(e[s(1082)](e[s(1516)],s(1513)))this[s(1632)+"s"]=_0x283f6b,this[s(1542)+"es"]=_0x2bc986,this[s(924)+"ndex"]=0,this["currentEndpointT"+s(911)+"t"]=0;else switch(n){case 0:for(;e[s(1657)](128,e[s(1762)](oe,a)););break;case 2:e.pCiqs(V,a,e.jNYAs(he,a));break;case 5:e[s(1713)](V,a,4);break;case 1:V(a,8);break;default:throw new Error(e[s(843)]+n)}}function P(a){let n=t;return a|=0,{low:a,high:e[n(1446)](a,31),unsigned:e[n(359)](a,0)}}let E=[];function k(){let a=t,n=E[a(316)]();return n?(n[a(1528)]=n[a(523)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){E[t(354)](a)}function F(a){return{bytes:a,offset:0,limit:a[t(1524)]}}function B(a){let n=t,s=a.bytes,d=a.limit;return e[n(1082)](s[n(1524)],d)?s:s.subarray(0,d)}function V(a,n){let s=t;if(e[s(1820)](a[s(1528)],n)>a[s(523)])throw new Error(e[s(423)]);a[s(1528)]+=n}function $(a){let n=t;return a.offset>=a[n(523)]}function ne(a,n){let s=t,d=a[s(1122)],f=a[s(1528)],h=a.limit,m=e[s(967)](f,n);if(e[s(1577)](m,d.length)){let b=new Uint8Array(e[s(416)](2,m));b[s(1462)](d),a[s(1122)]=b}return a.offset=m,e[s(1536)](m,h)&&(a[s(523)]=m),f}function Z(a,n){let s=t,d={FGuwY:function(f,h){return f+h},OkCvU:function(f,h){return e[U(1665)](f,h)},dRLli:function(f,h,m){return e[U(1354)](f,h,m)}};if(e[s(1278)](s(1770),s(1770))){let f=a[s(1528)];if(e.BIXfF(e.GmUFg(f,n),a[s(523)]))throw new Error(e[s(725)]);return a[s(1528)]+=n,f}else return cCgmrk[s(1073)](cCgmrk[s(631)](_0x5c0050,4).join("0"),cCgmrk[s(1401)](_0x10061c,_0x18a527,2).toString(16))[s(264)](-4)}function se(a,n){let s=t,d=e[s(1656)](Z,a,n);return a[s(1122)][s(647)](d,e[s(967)](d,n))}function ae(a,n){let s=t,d={VrDOu:function(f,h){return f(h)},vTffs:function(f,h){return e[U(1210)](f,h)},UHXjg:function(f,h){return f<<h},hTSjF:function(f,h){return f&h},HLUNJ:function(f,h){return e[U(770)](f,h)},gPZzK:function(f,h){return e[U(570)](f,h)},vpaTr:function(f,h){return e[U(1210)](f,h)}};if(e.PTwgo===e[s(1840)]){let f=e[s(436)](ne,a,n.length);a.bytes[s(1462)](n,f)}else _0x2b12dd=d.VrDOu(_0xe5eab3,_0x399c21),_0x44edf2|=d.vTffs(127,_0x1e9a0c)<<14,d[s(1202)](128,_0x620a5e)&&(_0x49d57e=_0x2f47b9(_0x3551d1),_0x58ca25|=d[s(1797)](d[s(1371)](127,_0x412d65),21),d[s(1597)](128,_0x53a0c4)&&(_0x107575=d[s(402)](_0x12d545,_0x573919),_0x504e33=d.gPZzK(127,_0x27ea77),d[s(1584)](128,_0x1e7901)&&(_0x1ad23f=d[s(402)](_0x564d48,_0x12537a),_0x11f1b3|=d[s(1584)](127,_0x2eaa65)<<7)))}function L(a,n){let s=t,d={iighS:function(v,D){return e[U(684)](v,D)},srZth:function(v,D){return e.QvQiS(v,D)},okjNy:function(v,D){return e.Qlnem(v,D)},jsXWB:function(v,D){return e[U(1024)](v,D)},mVxLS:function(v,D){return v&D},TXRjN:function(v,D){return e[U(967)](v,D)},Hmqap:function(v,D){return e[U(967)](v,D)},cYKCT:function(v,D){return e[U(936)](v,D)},qeOkJ:function(v,D){return e[U(770)](v,D)},NIkuf:function(v,D){return v>>D},nSxlM:function(v,D){return e[U(1424)](v,D)},AyWac:function(v,D){return e[U(1505)](v,D)},VfNme:function(v,D){return e[U(1115)](v,D)},RaHZc:function(v,D){return e.XYbXD(v,D)},rLUua:function(v,D){return e[U(1773)](v,D)},FPdIU:function(v,D){return e[U(936)](v,D)},pkKHS:function(v,D){return e[U(1276)](v,D)}},f=Z(a,n),h=String[s(1507)+"Code"],m=a[s(1122)],b="\uFFFD",g="";for(let v=0;e[s(931)](v,n);v++)if(s(1233)===s(1233)){let D=m[e.xdkXd(v,f)],N,H,J,X;if(e[s(1294)](e[s(974)](128,D),0))g+=e.mAGbB(h,D);else if((224&D)===192)if(e[s(1113)](v,1)>=n)g+=b;else if(N=m[e[s(1113)](e[s(1558)](v,f),1)],e.xRDFU(192&N,128))g+=b;else if(e.Kgnki===s(1444))X=e[s(1565)](e[s(283)](31&D,6),e[s(1109)](63,N)),e[s(1071)](X,128)?g+=b:e[s(927)](s(903),e[s(420)])?(_0x11f54e=_0x483b95[s(1649)+"At"](_0x5afb8e),_0x30c194<128?_0x18dd1f[_0x466374++]=_0x354072:_0x9dcb4e<2048?(_0x1d548b[_0x3183f5++]=d.iighS(_0x3c8b0a>>6,192),_0x21967e[_0x4437f9++]=63&_0x2fbc59|128):d[s(1166)](d.okjNy(64512,_0x120c63),55296)&&d[s(1172)](d.mVxLS(64512,_0x154b6c=_0x7d8351[s(1649)+"At"](d[s(1554)](_0x3f65ff,1))),56320)?(_0x177b4=d[s(805)](d[s(1554)](65536,(1023&_0x2ab50e)<<10),d[s(1548)](1023,_0x526b95)),++_0x59080c,_0x4c6b34[_0x283379++]=d[s(1671)](_0x3b14df,18)|240,_0x339928[_0x36a891++]=d[s(606)](d[s(1285)](d.NIkuf(_0x3b0ad5,12),63),128),_0x269212[_0x174169++]=d[s(403)](d.NIkuf(_0x2bad1c,6),63)|128,_0x1ce2c1[_0x3c874c++]=d[s(1483)](63,_0xa46bf2)|128):(_0x4a660f[_0xc34ff0++]=d.VfNme(d[s(776)](_0x351d39,12),224),_0xf2b969[_0x113207++]=d[s(545)](d.AyWac(d.FPdIU(_0x58053e,6),63),128),_0x481381[_0x28f1ba++]=d.pkKHS(d[s(1483)](63,_0x564819),128))):(g+=h(X),v++);else return _0xabffe[_0x27fd50]=_0x2d2280,!0;else if(e[s(622)](e[s(915)](240,D),224))if(e.eJJWB(v,2)>=n)g+=b;else if(e[s(1025)](e[s(384)],e.EFHhC))N=m[e.GmUFg(v,f)+1],H=m[e.eJJWB(e.JGNiW(v,f),2)],e[s(1025)](e[s(1109)](e[s(1276)](N,e[s(1201)](H,8)),49344),32896)?g+=b:(X=e[s(1773)](e[s(540)](e.piOmp(15,D),12)|e[s(1210)](63,N)<<6,e[s(1657)](63,H)),X<2048||e[s(819)](X,55296)&&e[s(709)](X,57343)?g+=b:(g+=e[s(1631)](h,X),v+=2));else return _0x5313bd[s(1817)](_0x7e6f5d)||(_0x592974=_0x562585[s(297)+"er"](_0x56ad2c)),e[s(927)](this[s(1722)],_0x5c3775[s(1722)])&&e[s(657)](this[s(388)],31)===1&&e[s(1525)](_0x50f7e9[s(388)],31)===1?!1:e[s(362)](this[s(388)],_0x3ccbdc.high)&&e.agylE(this[s(1453)],_0x3eb1a3.low);else e.JVcxu(248,D)==240?e[s(571)](v,3)>=n?g+=b:(N=m[e.iPMIH(e.pclbd(v,f),1)],H=m[e[s(1335)](e.vcaWk(v,f),2)],J=m[e.NiSwa(e[s(1352)](v,f),3)],e.yuMPo(e[s(644)](N|e.wdewy(H,8)|e[s(426)](J,16),12632256),8421504)?g+=b:(X=e[s(637)](e[s(1456)](7,D)<<18,e[s(1210)](63,N)<<12)|e[s(1207)](63&H,6)|e[s(721)](63,J),e[s(944)](X,65536)||X>1114111?g+=b:(X-=65536,g+=e[s(535)](h,(X>>10)+55296,e.Ifvov(1023&X,56320)),v+=3))):g+=b}else{let D=_0x5ad564[s(1524)]&&_0x3e5e11[0];if(D instanceof _0x4ed775)throw D;let N=new _0x14ed1f(e[s(1694)](e[s(323)],D?e[s(1113)](" ("+D.message,")"):""));throw N.context=D,D}return g}function G(a,n){let s=t;if(e[s(1278)](e[s(322)],"XbYRE")){let d=_0x28a51a.bytes,f=_0x2172d9[s(523)];return d[s(1524)]===f?d:d.subarray(0,f)}else{let d=n[s(1524)],f=0;for(let b=0;e[s(931)](b,d);b++){let g=n[s(1649)+"At"](b);e[s(819)](g,55296)&&e[s(1158)](g,56319)&&e.CqIiE(e.ScQdv(b,1),d)&&(g=e[s(1330)](e.IJHUn(e[s(540)](g,10),n[s(1649)+"At"](++b)),56613888)),f+=g<128?1:e[s(274)](g,2048)?2:e.JfsgA(g,65536)?3:4}e[s(1079)](pe,a,f);let h=e.cqPZw(ne,a,f),m=a.bytes;for(let b=0;e[s(641)](b,d);b++){let g=n.charCodeAt(b);e[s(1171)](g,55296)&&e[s(1498)](g,56319)&&b+1<d&&(g=e.iVQHe(g,10)+n[s(1649)+"At"](++b)-56613888),g<128?m[h++]=g:(g<2048?m[h++]=e.rdBrH(e[s(830)](e[s(1810)](g,6),31),192):(e[s(1253)](g,65536)?m[h++]=e[s(930)](e.TvfeO(e[s(936)](g,12),15),224):(m[h++]=e[s(1565)](e[s(1540)](e.XYbXD(g,18),7),240),m[h++]=e[s(1565)](e.XYbXD(g,12)&63,128)),m[h++]=e.piOmp(e[s(1211)](g,6),63)|128),m[h++]=e[s(889)](63&g,128))}}}function K(a,n){let s=t,d=e[s(1777)](ne,a,n[s(523)]),f=a.bytes,h=n[s(1122)];for(let m=0,b=n[s(523)];e[s(838)](m,b);m++)f[m+d]=h[m]}function oe(a){let n=t;if(e[n(1278)](e[n(1485)],e[n(1485)]))return a.bytes[e.atNdM(Z,a,1)];this[n(845)](n(1811),_0x4b8501),this[n(1254)]&&this[n(1254)](_0x50bc75)}function Ze(a,n){let s=t,d=e.cqPZw(ne,a,1);a[s(1122)][d]=n}function he(a){let n=t,s=0,d=0,f;do f=e[n(1762)](oe,a),s<32&&(d|=e[n(854)](e.GtFPV(127,f),s)),s+=7;while(128&f);return d}function pe(a,n){let s=t;if(e[s(387)]!==e[s(387)])return this._ws?this._ws[s(497)]:this._url;for(n>>>=0;n>=128;)e[s(1488)](Ze,a,e[s(1364)](e[s(770)](127,n),128)),n>>>=7;e[s(1021)](Ze,a,n)}function vt(a,n){let s=t,d={zjkCz:e.PfLwo},f=0,h=0,m=0,b;if(b=e[s(1748)](oe,a),f=e[s(558)](127,b),e.TvfeO(128,b)&&(b=e[s(685)](oe,a),f|=e.VtMbp(127&b,7),e[s(1008)](128,b)&&(b=e[s(1316)](oe,a),f|=e[s(1505)](127,b)<<14,e[s(1008)](128,b))))if(e.spBtQ(e[s(960)],e[s(960)])){if(b=e[s(1687)](oe,a),f|=e.GNyDT(127,b)<<21,e[s(892)](128,b)&&(b=e[s(1631)](oe,a),h=e[s(799)](127,b),e.WKRCh(128,b)&&(b=e[s(457)](oe,a),h|=e[s(1358)](127,b)<<7,e[s(850)](128,b)))){if(s(1549)!=="XQqXc"){if(!this[s(1602)+s(1042)]()||this["_readyCl"+s(988)])return;this["_endpoin"+s(976)]?.[s(1730)+s(621)+s(334)](),this[s(270)+s(579)]?.[s(683)+"nter"](),this[s(528)]?this[s(1291)+"ect"](1001,d.zjkCz,!0):this[s(424)]()}else if(b=e[s(685)](oe,a),h|=e[s(1237)](e[s(733)](127,b),14),128&b)if(e.xRDFU(e[s(1794)],e.UjSLl)){let g=this[s(393)][s(950)+s(1341)+"nc"](this[s(263)]),v=_0x48c5ac[s(869)](e[s(1521)](g,"{}"));return _0xcfbdfc[s(627)](v)}else b=e.jNYAs(oe,a),h|=e.ttOMv(e.GtFPV(127,b),21),e[s(644)](128,b)&&(b=e.jNYAs(oe,a),m=127&b,e[s(872)](128,b)&&(b=e[s(1316)](oe,a),m|=e[s(651)](127,b)<<7))}}else return _0x4e4fc3[s(1173)+s(1224)]||_0x3fadbd[s(495)](_0x29aa74);return{low:e[s(1799)](f,e[s(1143)](h,28)),high:e.rVUAE(h>>>4,e.uetJf(m,24)),unsigned:n}}function ft(a,n){let s=t,d=n[s(1453)]>>>0,f=e.bWOWY(e.hijMo(e[s(947)](n[s(1453)],28),e[s(1706)](n[s(388)],4)),0),h=n[s(388)]>>>24,m=e.EHVMg(0,h)?e[s(483)](0,f)?e[s(1071)](d,16384)?e.IZnXu(d,128)?1:2:d<2097152?3:4:f<16384?e[s(775)](f,128)?5:6:e.VsmTi(f,2097152)?7:8:e[s(983)](h,128)?9:10,b=ne(a,m),g=a.bytes;switch(m){case 10:g[e[s(940)](b,9)]=e[s(1835)](h>>>7,1);case 9:g[e[s(808)](b,8)]=e[s(754)](9,m)?e[s(1799)](128,h):e.oiUdr(127,h);case 8:g[b+7]=e[s(1673)](8,m)?e[s(1728)](e[s(905)](f,21),128):e.GRYqX(e[s(1595)](f,21),127);case 7:g[e[s(1829)](b,6)]=m!==7?e[s(1103)](e[s(1525)](f,14),128):e[s(1754)](f>>>14,127);case 6:g[e.pclbd(b,5)]=e[s(975)](6,m)?e[s(1084)](f>>>7,128):e[s(995)](f>>>7,127);case 5:g[e.GmUFg(b,4)]=e.twbKD(5,m)?e[s(325)](128,f):e[s(1028)](127,f);case 4:g[e[s(1359)](b,3)]=m!==4?e[s(930)](e[s(905)](d,21),128):e[s(850)](e.GgUiY(d,21),127);case 3:g[e[s(1352)](b,2)]=m!==3?e[s(865)](d>>>14,128):e[s(905)](d,14)&127;case 2:g[e.pclbd(b,1)]=e[s(927)](2,m)?e[s(1409)](e[s(657)](d,7),128):e[s(1447)](d,7)&127;case 1:g[b]=e[s(975)](1,m)?128|d:127&d}}function Xt(a){return e[t(342)](S,a)}function Bt(a){return e[t(1665)](I,a)}let Qt=65536,Vr=e.ufhQr,_e=e.clbnk(Qt,Qt),Ce=_e*_e,Xn=Ce/2,Oe=String[t(1587)+"e"][t(1649)+"At"];class xe{constructor(n,s,d){let f=t;if(e[f(1095)]!==e.uWVBM){let h=_0x2d9264[_0x4e7287];if(e[f(927)](4,_0x10c363[_0x1711ce][f(1524)])){let m=_0x2fae1d.substring(0,e.JPmIz(4,_0xc89d0[_0x11132d][f(1524)])),b=m[f(576)](h);_0x1257a2=_0x385afd.concat(b)}else _0x30a221=_0x5aea4c[f(576)](h)}else this.isLong=!0,this[f(1453)]=0|n,this.high=e[f(1276)](0,s),this[f(1722)]=!!d}static[t(1817)](n){let s=t;return e[s(1e3)](e[s(324)],e[s(852)])?this[s(1632)+"s"][this[s(924)+s(273)]]:n&&e[s(1016)](!0,n[s(1817)])}static[t(1758)](n,s,d){let f=t;if(e[f(909)](e[f(1085)],e[f(1085)]))return new xe(n,s,d);{let h={kXUBs:e[f(295)],ahlAc:function(D,N,H,J){return D(N,H,J)},RLeqL:e.Jkkiw,JBQke:e.eeapY,Wfrhp:e[f(1144)],GASvM:e[f(1222)],AYDfn:e.roqIX},[m,b]=_0x2ab55a(_0x5debb0),g=e[f(681)](_0x1989ab,m),v=0;return _0x3fe3a0[f(1300)](D=>{let N=f,H=h[N(784)][N(485)]("|"),J=0;for(;;){switch(H[J++]){case"0":v=h.ahlAc(_0x4a01ca,D["cursor_n"+N(981)],g,v);continue;case"1":_0x27a6f1.log(h.RLeqL,D,D.service);continue;case"2":_0x2fb733[N(1688)](h[N(1634)],v);continue;case"3":_0xfd6c61[N(1688)](h[N(1574)],v);continue;case"4":_0xc7e9f1[N(1688)](h.GASvM,v);continue;case"5":_0x113d19.log("name",v);continue;case"6":_0x558c15[N(1688)](h[N(1347)],v);continue;case"7":v=h[N(1061)](_0xe1d010,b[D[N(1302)+"ame"]],g,v);continue;case"8":v=_0x4b9023(0,g,v);continue;case"9":v=h.ahlAc(_0x1b1519,g,v,D[N(315)]||0);continue;case"10":v=_0x2c4f79(_0x4f5428.fromNumber(D.cursor||_0x1a37a9),g,v);continue}break}}),{frameType:_0x420e3b,headers:[{key:e[f(1005)],value:_0x2f9871}],payload:g}}}static[t(1373)+"s"](n,s,d){let f=t;return d?xe[f(1373)+f(1090)](n,s):xe["fromByte"+f(878)](n,s)}static[t(1373)+"sLE"](n,s){let d=t;return new xe(e[d(889)](e[d(276)](n[0],e.VUkVX(n[1],8))|e[d(612)](n[2],16),n[3]<<24),e.Ycjsx(n[4]|e[d(1270)](n[5],8)|e[d(1270)](n[6],16),e[d(689)](n[7],24)),s)}static[t(1373)+t(878)](n,s){let d=t;return new xe(e.mnaTY(e[d(1661)](n[4]<<24,n[5]<<16),e.eiWWc(n[6],8))|n[7],e[d(1276)](e[d(1236)](e.VUkVX(n[0],24)|e.maKUa(n[1],16),n[2]<<8),n[3]),s)}static[t(1621)](n){let s=t;return e.zrSXe(n,Vr)?Kd:new xe(e[s(1078)](e.TLfFT(e[s(637)](Oe[s(307)](n,0),e.MttfT(Oe[s(307)](n,1),8))|e[s(728)](Oe.call(n,2),16),e[s(582)](Oe[s(307)](n,3),24)),0),e[s(557)](e[s(865)](e[s(1615)](Oe.call(n,4),e[s(1625)](Oe[s(307)](n,5),8)),e[s(564)](Oe[s(307)](n,6),16))|e[s(426)](Oe.call(n,7),24),0),!0)}[t(455)](){let n=t;return String["fromChar"+n(507)](255&this.low,e[n(338)](this[n(1453)],8)&255,this[n(1453)]>>>16&255,e[n(783)](this[n(1453)],24),e[n(1505)](255,this[n(388)]),e[n(876)](e[n(771)](this.high,8),255),e[n(1526)](e[n(1734)](this[n(388)],16),255),this.high>>>24)}static[t(297)+"er"](n,s=!0){let d=t;if(e[d(1428)](isNaN,n))return s?dp:Kd;if(s){if(e.qGSne(n,Ce))return up}else{if(n<=-Xn)return fp;if(e[d(1539)](e[d(336)](n,1),Xn))return lp}return xe[d(1758)](e[d(1084)](e[d(1523)](n,_e),0),e[d(484)](n/_e,0),s)}toNumber(){let n=t;return this.unsigned?e[n(1329)](e[n(1315)](e.NbjTL(this[n(388)],0),_e),e[n(1525)](this[n(1453)],0)):e[n(967)](e[n(1531)](this[n(388)],_e),e[n(961)](this[n(1453)],0))}[t(901)](){let n=t;return e[n(483)](0,this[n(388)])&&this.low===0}[t(1375)](n){let s=t;xe[s(1817)](n)||(n=xe[s(297)+"er"](n));let d=e[s(1043)](this[s(388)],16),f=e[s(1679)](65535,this[s(388)]),h=this.low>>>16,m=e.ihxmG(65535,this[s(1453)]),b=n.high>>>16,g=e[s(770)](65535,n[s(388)]),v=e[s(1595)](n[s(1453)],16),D=e[s(1526)](65535,n.low),N=0,H=0,J=0,X=0;return X+=e[s(808)](m,D),J+=X>>>16,X&=65535,J+=h+v,H+=e.Mrxpq(J,16),J&=65535,H+=e[s(1113)](f,g),N+=e[s(1752)](H,16),H&=65535,N+=e[s(834)](d,b),N&=65535,xe[s(1758)](e.TvsHg(e[s(564)](J,16),X),e.uTCtC(e.gZJaO(N,16),H),this[s(1722)])}[t(332)](n){let s=t;return xe[s(1817)](n)||(n=xe[s(297)+"er"](n)),e[s(1025)](this.unsigned,n[s(1722)])&&e[s(783)](this[s(388)],31)===1&&e[s(1559)](e[s(1107)](n[s(388)],31),1)?!1:e.spBtQ(this[s(388)],n[s(388)])&&e[s(785)](this[s(1453)],n[s(1453)])}[t(1590)](){let n=t;if(e.AxOZf(e.gVRFy,e[n(1199)]))return e[n(1756)](-1,this.low)&&e[n(1690)](-1,this[n(388)])?xe[n(1758)](0,0,this[n(1722)]):e[n(1670)](-1,this.low)?xe[n(1758)](0,e[n(1820)](this.high,1),this.unsigned):xe[n(1758)](this[n(1453)]+1,this[n(388)],this.unsigned);for(var s in _0x44465f)_0x4ab454.o(_0x3d98aa,s)&&!_0x24a294.o(_0x3d2bda,s)&&_0x4acabb[n(640)+n(1418)](_0x183087,s,{enumerable:!0,get:_0x1d728c[s]})}[t(556)](n){return n?this[t(1365)+"E"]():this.toBytesBE()}[t(1365)+"E"](){let n=t,s=this[n(388)],d=this.low;return[e[n(733)](255,d),e[n(1752)](d,8)&255,e[n(657)](d,16)&255,d>>>24,255&s,e[n(1659)](e[n(783)](s,8),255),e[n(1210)](e[n(1107)](s,16),255),s>>>24]}[t(1592)+"E"](){let n=t,s=this[n(388)],d=this[n(1453)];return[s>>>24,e.WzQzy(s>>>16,255),e[n(1505)](e[n(338)](s,8),255),255&s,d>>>24,e.DhISS(d>>>16,255),e.YfHvv(e[n(1107)](d,8),255),255&d]}}let Kd=new xe(0,0,!1),dp=new xe(0,0,!0),lp=xe[t(1758)](-1,2147483647,!1),up=xe[t(1758)](-1,-1,!0),fp=xe[t(1758)](0,-2147483648,!1);var en=(function(a){let n=t,s=(n(1292)+n(779))[n(485)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[n(1121)]]=5003]=n(526)+n(349)+"R";continue;case"1":a[a[e[n(532)]]=5005]=e[n(532)];continue;case"2":a[a[e[n(864)]]=5002]=e[n(864)];continue;case"3":a[a[e[n(314)]]=5001]=n(503)+n(1448);continue;case"4":a[a[e[n(1125)]]=5004]=e[n(1125)];continue;case"5":return a}break}})({});class Qn{constructor(n){let s=t;this[s(519)]=n,this[s(1183)]=null}}class $d extends Qn{constructor(n,s){let d=t;super(n),this[d(560)]=s&&s.message||null}}class Vd extends Qn{constructor(n,s){let d=t;if(e.OnRJu(e[d(285)],e[d(1396)])){let f=(d(1324)+d(511))[d(485)]("|"),h=0;for(;;){switch(f[h++]){case"0":this[d(267)]=s&&s[d(267)]||0;continue;case"1":super(n);continue;case"2":this[d(1786)]=s&&s[d(1786)]||null;continue;case"3":this[d(635)]=s&&s[d(635)]||0;continue;case"4":this[d(560)]=s&&s[d(560)]||"";continue;case"5":this[d(345)]=s&&s.filename||"";continue;case"6":this[d(363)]=s&&s[d(363)]||5001;continue}break}}else throw this[d(424)+d(395)]=!1,_0x59ee87}}class Jd extends Qn{constructor(n,s){let d=t,f={nvwix:function(h,m){return e.LIFJf(h,m)},WUOkG:function(h,m){return h<<m},jixTk:function(h,m){return e[U(1540)](h,m)},grdBE:function(h,m){return h&m},jALhB:function(h,m){return e.RfDOt(h,m)},WUljC:function(h,m){return e[U(1832)](h,m)},ZGbUy:function(h,m){return e[U(1792)](h,m)},ckjWv:function(h,m){return e[U(969)](h,m)}};if(e[d(1082)](d(1644),e[d(922)])){let h=f.nvwix(f[d(1353)](f.WUOkG(f[d(464)](7,_0x56c665),18)|f[d(1691)](63,_0x410f91[_0x4cc9c2++])<<12,f[d(1338)](f[d(464)](63,_0x4ae254[_0x407c46++]),6)),f[d(1229)](63,_0xc0c0c9[_0x4355e7++]))-65536;_0x511025+=_0x412978[d(1507)+"Code"](55296+f[d(1541)](h,10)),_0x5b6364+=_0x483ec9[d(1507)+"Code"](f[d(566)](56320,1023&h))}else{let h=(d(615)+"2").split("|"),m=0;for(;;){switch(h[m++]){case"0":super(n);continue;case"1":this[d(481)]=s&&s[d(481)]||"";continue;case"2":this[d(493)+d(1223)]=s&&s.willReconnect||!1;continue;case"3":this[d(551)]=s&&s[d(551)]||!1;continue;case"4":this[d(363)]=s&&s[d(363)]||0;continue}break}}}}class Zd extends Qn{constructor(n,s){let d=t;super(n),this[d(1283)]=s&&s[d(1283)]||null}}class Yd extends Zd{constructor(n,s){let d=t;super(n),this[d(1283)]=s&&s[d(1283)]||null,this[d(560)]=s&&s[d(560)]||null}}class Xd extends Qn{constructor(n,s){let d=t;super(n),this[d(1283)]=s&&s.data||null}}function at(a,{message:n,code:s,error:d}){return new Vd(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:f}){return new Jd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function Qd(a,{data:n,message:s}){let d=t,f={eHVtT:"online",qUXuh:e[d(1769)]};if(e.DifwT===e[d(1044)])this[d(353)+"er"]&&_0x3ebce2[d(1785)+"entListener"](f[d(782)],this[d(1480)+d(1331)]),this[d(353)+"er"]&&_0x39c3aa[d(1785)+d(518)+d(663)](f[d(1729)],this["_handleO"+d(919)]),this._isBrowser&&_0x3a19af[d(1785)+d(518)+"ner"](d(1745),this[d(1423)+"ageHide"]),this[d(353)+"er"]&&_0x436187[d(1785)+"entListe"+d(663)](d(1011),this[d(1423)+d(1007)]);else return new Yd(a,{data:n,message:s})}function el(a,{data:n}){return new Xd(a,{data:n})}function da(a,{message:n}){return new $d(a,{message:n})}class tl{constructor(n,s){let d=t;e[d(1481)](e[d(1054)],"omfGO")?_0x516f37[d(1843)]["appendCh"+d(450)](_0x34d735):(this[d(1632)+"s"]=n,this[d(1542)+"es"]=s,this.currentIndex=0,this["currentEndpointT"+d(911)+"t"]=0)}[t(1730)+"pointCon"+t(334)](){let n=t;this[n(924)+n(273)]=0,this[n(918)+n(925)+"riesCount"]=0}[t(1838)+"es"](){let n=t;this[n(918)+n(925)+"riesCount"]=0}[t(638)+t(1643)+"nt"](){let n=t,s={hJBqY:function(d,f){return e[U(1486)](d,f)},ddAGL:function(d,f){return d<<f},NnZrO:function(d,f){return e[U(1728)](d,f)},mnord:function(d,f){return e[U(998)](d,f)},QaANo:function(d,f){return e[U(1409)](d,f)}};return e.gEttg(n(632),e[n(1414)])?new _0x4eb65e(iNojpS[n(711)](_0x58ad63[0]|_0x3ff864[1]<<8,iNojpS[n(1530)](_0x13dbdb[2],16))|iNojpS.ddAGL(_0x278982[3],24),iNojpS[n(1501)](iNojpS[n(1617)](iNojpS[n(510)](_0xa49fb9[4],_0x2945b9[5]<<8),iNojpS[n(1530)](_0x37d095[6],16)),_0x2ff847[7]<<24),_0x5adf8c):this[n(1632)+"s"][this[n(924)+n(273)]]}["getCurre"+t(1643)+t(1014)+"ount"](){let n=t;return this[n(918)+n(925)+"riesCount"]}["checkRea"+t(266)+"es"](){let n=t;return!!(e[n(359)](this["currentI"+n(273)],this.endpoints[n(1524)])||this[n(924)+n(273)]===e.cqbRZ(this.endpoints[n(1524)],1)&&e[n(1294)](this[n(918)+"ndpointT"+n(911)+"t"],this.maxRetries))}[t(720)+t(1635)+t(460)+t(268)+t(810)](){let n=t;return e[n(622)](this[n(924)+"ndex"],this[n(1632)+"s"][n(1524)])?!0:e[n(1470)](this[n(918)+n(925)+n(911)+"t"],this[n(1542)+"es"])}["replaceB"+t(800)+t(1716)+"UpdateCo"+t(543)](){let n=t;return this[n(918)+"ndpointT"+n(911)+"t"]=1,this[n(924)+n(273)]++,this.endpoints[this[n(924)+n(273)]]}[t(638)+t(1643)+t(777)+"ateCount"](){let n=t;return this[n(918)+n(925)+"riesCount"]++,this["getCurre"+n(1643)+"nt"]()}}let er=(e[t(435)](e[t(977)],typeof globalThis)&&e.SlSUO("Window",globalThis[t(1747)+t(610)][t(962)])||e.NdXtS(e[t(977)],typeof window)&&e[t(1089)](e[t(820)],window[t(1747)+"tor"].name))&&e[t(751)](e[t(977)],typeof document),Rn=e[t(399)](e[t(977)],typeof globalThis)&&(e[t(494)]===globalThis["construc"+t(610)][t(962)]||e[t(928)]===globalThis[t(1747)+"tor"][t(962)])&&e[t(977)]!=typeof tt,Jr=(e[t(300)](t(1623)+"d",typeof globalThis)&&t(1573)===globalThis[t(1747)+t(610)][t(962)]||e.Iopuj("undefined",typeof globalThis)||e[t(435)](e[t(977)],typeof globalThis)&&!!globalThis[t(1591)+t(1070)])&&e[t(399)](e[t(977)],typeof wx),Zr=typeof globalThis<"u"&&(e.gEttg(e[t(928)],globalThis["construc"+t(610)][t(962)])||e[t(1327)](t(1120)+"rkerGlobalScope",globalThis["construc"+t(610)][t(962)])||e[t(1294)](t(1263)+t(458)+"balScope",globalThis.constructor.name))&&t(1623)+"d"!=typeof self,xp=e[t(914)]("undefined",typeof globalThis)&&e.vQJtC(t(1573),globalThis[t(1747)+t(610)][t(962)])&&e.yRCGe(t(1623)+"d",typeof global)&&e[t(1082)](e[t(494)],global[t(1747)+t(610)][t(962)])&&e.GOfww(e[t(977)],typeof process)&&!!process[t(608)];class la{constructor(){let n=t;this[n(672)+"rs"]={}}[t(845)](n,...s){let d=t,f=this[d(672)+"rs"][n];if(f)f[d(264)]()[d(1300)](h=>h.fn[d(1259)](h[d(1195)],s));else if(e[d(1559)](d(1786),n)&&!this[d(1088)]){if(e.soSBV(e[d(547)],e[d(948)]))return _0x367caa||(_0x37af92=[_0x5b654e[d(1587)+"e"][d(734)],_0x56f8af[d(1587)+"e"][d(1764)],_0x4e8795[d(1587)+"e"].continuePrimaryKey]);{let h=s.length&&s[0];if(h instanceof Error)throw h;let m=new Error(e.FjQjn(e[d(323)],h?e[d(289)](e[d(289)](" (",h.message),")"):""));throw m[d(1533)]=h,h}}return this}[t(284)](n,s){let d=t;if(e.kLzoq(void 0,n))this[d(672)+"rs"]={};else if(e.ZUTgE(void 0,s))this._listeners[n]=null;else{let f=this[d(672)+"rs"][n];if(f)for(let h=0;e[d(1701)](h,f[d(1524)]);)e[d(1690)](f[h].fn,s)?f.splice(h,1):++h}return this}on(n,s,d){let f=t;return(this[f(672)+"rs"][n]||(this._listeners[n]=[]))[f(354)]({fn:s,ctx:d||this}),this}}class hp extends la{_formatErrorMessage(n){let s=t;return n[s(1389)]||n[s(508)]?(s(1561)+" "+(n[s(1389)]||"")+s(1737)+(n[s(508)]||""))[s(405)]():JSON[s(1789)+"y"](n)}constructor(n,s,d){let f=t;super(),this[f(548)]=null,Jr&&wx[f(708)+f(1520)]&&(this[f(548)]=wx[f(708)+f(1520)]({url:n,protocols:s,header:d,fail:this[f(697)+f(1821)+f(1744)][f(636)](this),success:this[f(697)+f(755)+f(1578)+f(1465)][f(636)](this)})),Rn&&tt[f(708)+f(1520)]&&(this[f(548)]=tt[f(708)+"ocket"]({url:n,protocols:s,header:d,fail:this[f(697)+f(1821)+"lHandler"].bind(this),success:this[f(697)+f(755)+f(1578)+"ler"][f(636)](this)}))}[t(697)+"ocketSuc"+t(1578)+t(1465)](){let n=t;e[n(1257)](e.aTcfE,e[n(812)])?(_0x1a34e2[n(1462)](_0x55518a,_0x587ea6),_0x3d2541.set(_0x568106,_0x377c3e)):Promise[n(1380)]()[n(313)](()=>{let s=n;this[s(358)+s(1841)]()})}[t(697)+"ocketFai"+t(1744)](n){let s=t;Promise[s(1380)]()[s(313)](()=>{let d=s,f=at(e[d(1806)],{message:this[d(1467)+d(433)+d(1654)](n)});this[d(845)](e[d(1806)],f);let h=e[d(1434)](xt,e.zVqPJ,{reason:this["_formatErrorMess"+d(1654)](n)});this[d(845)](d(1811),h)})}[t(358)+t(1841)](){let n=t,s={RlNQL:e[n(1306)],pISnF:e[n(1666)],ArTxk:function(d,f,h){return e[n(1629)](d,f,h)},nJQeR:e.fbioT};this[n(548)][n(839)](d=>{let f=n;this.emit(s.RlNQL,el(f(477),{...d,data:d[f(1389)]||""}))}),this._socket[n(442)](d=>{let f=n;this[f(845)](e[f(1249)],e.ZwOLd(xt,e[f(1249)],{...d}))}),this._socket[n(577)+"e"](d=>{let f=n;this[f(845)](s[f(1720)],s[f(1123)](Qd,s[f(1720)],{...d}))}),this[n(548)].onError(d=>{let f=n;this.emit(f(1786),at(s[f(1280)],{...d,message:d.errMsg||""}))})}[t(1118)](n){let s=t,d={wCXbg:function(f,h,m){return f(h,m)},oolME:e[s(1806)],ibMSd:function(f,h){return f(h)}};if(e[s(445)](n,Uint8Array)){let f=n[s(1612)][s(264)](n[s(569)+"et"],n.byteLength+n.byteOffset);this[s(548)]&&this[s(548)][s(1118)]({data:f,fail:h=>{let m=s;this.emit(m(1786),d[m(1408)](at,d.oolME,{message:this[m(1467)+m(433)+"age"](h)}))}})}else this._socket&&this[s(548)][s(1118)]({data:n,fail:f=>{let h=s;e[h(1262)]===e[h(1004)]?(_0x3c11ef=d[h(280)](_0xc13d47,_0x1c3102),_0x249a1d=0):this[h(845)](e[h(1806)],at(e[h(1806)],{message:this[h(1467)+h(433)+"age"](f)}))}})}[t(1811)](n,s){let d=t;this[d(548)]&&this[d(548)][d(1811)]({code:n,reason:s})}[t(469)+t(286)](n,s){this.on(n,s)}[t(1785)+t(518)+t(663)](n,s){this[t(284)](n,s)}get[t(398)+"te"](){return this[t(548)].readyState}get[t(1370)+"pe"](){let n=t;return this[n(548)][n(1370)+"pe"]}set binaryType(n){}get[t(497)](){let n=t;return this[n(548)][n(497)]}get[t(956)](){let n=t,s={Eemqe:e[n(340)],BZWNd:function(d,f){return e.mGAGf(d,f)},uLDvh:function(d,f){return e[n(684)](d,f)},BmidF:function(d,f){return e[n(934)](d,f)},xyQNx:function(d,f){return d<<f},NOgBX:function(d,f){return e[n(1835)](d,f)},DkhiT:function(d,f){return e.qONAL(d,f)},BfPbS:function(d,f){return e.uTCtC(d,f)},VPddI:function(d,f){return e.Mrxpq(d,f)},dwajS:function(d,f){return d<f},RJRGv:function(d,f,h,m){return d(f,h,m)},yxXot:function(d,f){return e[n(604)](d,f)},WRLPZ:function(d,f){return e[n(341)](d,f)}};if(e[n(308)]==="lVwbC"){let d=4294967295;return function(f,h,m=!0){let b=n,g=s.Eemqe.split("|"),v=0;for(;;){switch(g[v++]){case"0":d=s[b(1588)](s[b(853)](d,s[b(559)](15,f[h])<<28),0);continue;case"1":return{value:m?d:0|d,offset:h};case"2":if(f[h++]<128)return{value:m?d:s[b(853)](0,d),offset:h};continue;case"3":d=s.uLDvh(d,s[b(1040)](s.BmidF(127,f[h]),14))>>>0;continue;case"4":d=(d|s[b(559)](127,f[h])<<21)>>>0;continue;case"5":d=s[b(1705)](127,f[h])>>>0;continue;case"6":if(s[b(1055)](f[h++],128))return{value:m?d:s[b(504)](0,d),offset:h};continue;case"7":d=s[b(1357)](d|s.xyQNx(s.NOgBX(127,f[h]),7),0);continue;case"8":if(s[b(726)](f[h++],128))return{value:m?d:0|d,offset:h};continue;case"9":if((h+=5)>f[b(1524)])throw h=f[b(1524)],s.RJRGv(_0x106d41,h,10,f[b(1524)]);continue;case"10":if(s.dwajS(f[h++],128))return{value:m?d:s.yxXot(0,d),offset:h};continue;case"11":if(s.DkhiT(f[h++],128))return{value:m?d:s[b(531)](0,d),offset:h};continue}break}}}else return this[n(548)].protocol}get[t(649)+"ns"](){let n=t,s={ndfBl:function(d,f){return e[U(335)](d,f)},QcIgH:function(d,f){return d+f},dWiJc:e[n(553)],Avveq:function(d,f){return d||f},PVARI:e[n(1228)]};return n(1503)!=="NkAwm"?this[n(548)][n(649)+"ns"]:s[n(1519)](_0x2f2e8e,s[n(1036)](s[n(1036)](s[n(1036)](s[n(1036)](n(1583)+n(275)+"ge: ",_0x224008),s.dWiJc),s[n(1176)](_0x4b9a02,1)),s[n(1284)])+_0x213694)}get[t(554)+t(1445)](){return 0}}function pp(a,n){let s=t;if(n)return new n(a[s(497)],a.protocol);if(Jr||Rn)return new hp(a[s(497)],a.protocol,a[s(296)]);if((er||Zr)&&e.wNKpX!=typeof WebSocket&&WebSocket)return new WebSocket(a.url,a[s(956)+"s"])}function gp(a){let n=t,s="4|3|1|0|2"[n(485)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(e[n(304)](er,Zr)&&e[n(977)]!=typeof WebSocket&&WebSocket)return!0;continue;case"1":if(Rn&&tt[n(708)+"ocket"])return!0;continue;case"2":return!1;case"3":if(Jr&&wx[n(708)+n(1520)])return!0;continue;case"4":if(a)return!0;continue}break}}function nl(a,n,s){let d=-1;async function f(h){let m=U;return e[m(397)](h,d)?Promise[m(1273)](new Error(e[m(1074)])):(d=h,e[m(1024)](h,s.length)?Promise[m(1380)]():s[h][m(636)](a)(n,f[m(636)](null,h+1)))}e.WjdUq(f,0)}function rl(a){let n=t,s=0,d=0;for(let f=0;e[n(1253)](f,a.length);++f)d=a[n(1649)+"At"](f),e[n(650)](d,128)?s+=1:e[n(376)](d,2048)?s+=2:e[n(703)](e[n(890)](64512,d),55296)&&e[n(265)](64512,a[n(1649)+"At"](e[n(1440)](f,1)))===56320?(++f,s+=4):s+=3;return s}function il(a,n,s){let d=t,f={RKaEm:function(h,m){return e[U(764)](h,m)},fNaYf:function(h,m){return e.ZoyPM(h,m)},bnVsq:function(h,m){return e[U(1329)](h,m)},uBcXK:function(h,m){return h+m},pIfGu:function(h,m){return h|m},pOxwR:function(h,m){return e[U(1181)](h,m)},zfmlW:function(h,m){return e[U(1214)](h,m)},uAhos:function(h,m){return e[U(1457)](h,m)},utKhl:function(h,m){return e.LdPnk(h,m)},tNxOj:function(h,m){return h<<m},nDRKZ:function(h,m){return e[U(1440)](h,m)}};if(e[d(639)](e[d(648)],e[d(773)])){let h=new _0x20877e(f[d(1159)](f[d(1287)](f[d(1159)](_0x5d2648[f.bnVsq(_0x64e025,4)]<<24,_0x26826f[f[d(291)](_0x4b2fdb,5)]<<16),_0x3bd309[_0x1a3169+6]<<8),_0x4a6117[_0xed2bd2+7]),f[d(1650)](f[d(1184)](f.zfmlW(f.uAhos(_0x54ba39[f[d(1208)](_0x32edd5,0)],24),f[d(437)](_0x33ce41[f.uBcXK(_0x2e4217,1)],16)),f[d(1494)](_0x12a1dd[f[d(1508)](_0x4c5ef0,2)],8)),_0x3e7255[f[d(291)](_0xddeb86,3)]),!0);return _0x5d7ff7+=8,{value:h,offset:f[d(1208)](_0x1831cf,8)}}else{if(e[d(392)](s,n)<1)return"";let h="";for(let m=n;e.JfsgA(m,s);){let b=a[m++];if(b<=127)h+=String[d(1507)+d(507)](b);else if(b>=192&&e[d(1153)](b,224))h+=String.fromCharCode(e[d(449)](e[d(1267)](e.GNyDT(31,b),6),63&a[m++]));else if(e[d(1171)](b,224)&&e[d(931)](b,240))h+=String[d(1507)+d(507)](e.oCCaD(e[d(1364)](e[d(1109)](15,b)<<12,e.bnFLI(63,a[m++])<<6),63&a[m++]));else if(e[d(359)](b,240)){let g=e[d(392)](e[d(1364)](e[d(341)](e[d(1622)](e.kxrrL(7&b,18),e[d(1216)](e[d(651)](63,a[m++]),12)),e[d(564)](63&a[m++],6)),e.FwjtW(63,a[m++])),65536);h+=String[d(1507)+d(507)](e[d(605)](55296,e[d(538)](g,10))),h+=String[d(1507)+d(507)](56320+e[d(1264)](1023,g))}}return h}}function ua(a,n,s){let d=t,f=s,h,m;for(let b=0;b<a[d(1524)];++b)if(h=a[d(1649)+"At"](b),h<128)n[s++]=h;else if(e.AWjIL(h,2048))n[s++]=e[d(1827)](h>>6,192),n[s++]=e[d(616)](e[d(265)](63,h),128);else if(e[d(1690)](e.DhISS(64512,h),55296)&&e[d(417)](e[d(1659)](64512,m=a.charCodeAt(e[d(1271)](b,1))),56320)){let g=e[d(561)][d(485)]("|"),v=0;for(;;){switch(g[v++]){case"0":n[s++]=e.yLqBN(e[d(567)](h,18),240);continue;case"1":n[s++]=e[d(1083)](e[d(1545)](63,h),128);continue;case"2":++b;continue;case"3":n[s++]=e[d(1804)](e[d(567)](h,6)&63,128);continue;case"4":n[s++]=e[d(369)](e.TYSOg(e[d(1119)](h,12),63),128);continue;case"5":h=e[d(1708)](65536+(e.ARLUN(1023,h)<<10),e[d(1832)](1023,m));continue}break}}else n[s++]=e[d(407)](h>>12,224),n[s++]=e[d(1103)](e.usdmp(h>>6,63),128),n[s++]=e[d(1039)](e.tvUvt(63,h),128);return e[d(1330)](s,f)}async function sl(a){let n=t;if(e[n(1788)](e[n(1557)],typeof a)){let s=new Uint8Array(e[n(1748)](rl,a));return e.PkPAh(ua,a,s,0),s}return e[n(445)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1612)],a[n(569)+"et"],a.byteLength)}function mp(a){let n=t;if(e[n(550)](e[n(1311)],e.lzESh))return null;try{return e[n(399)](e[n(1557)],typeof a)&&(e[n(669)](a,ArrayBuffer)||a[n(1612)]&&e[n(1060)](a[n(1612)],ArrayBuffer))||e[n(1557)]!=typeof a?"":(JSON[n(869)](a),e[n(1422)])}catch{return typeof a=="string"?e[n(1791)]:""}}let wp=(a,n)=>{let s=t;if(e[s(1304)](e.OMNuI,e[s(607)]))switch(a){case e[s(653)]:case e[s(1779)]:return{[s(1721)+a]:1,"x-tt-env":n};default:return{}}else Te[s(926)+"ount"]=_0x2e9759,Te[s(590)]=0};class _p{constructor(n){let s=t;this[s(926)+s(389)]=n,this[s(590)]=0}[t(814)](){let n=t;this[n(590)]++}["checkRea"+t(1566)+"nt"](){let n=t;return e[n(1700)](this[n(590)],this[n(926)+n(389)])}["resetCou"+t(659)](n=0){let s=t;this[s(926)+"ount"]=n,this[s(590)]=0}}async function yp(a){let n=t;if(e[n(1305)]===n(1646))return new Promise(s=>{let d=n,f={hsCDE:function(h,m){return h(m)},HEtTi:e[d(985)]};if(!er)return s(e.bYkAX);try{let h=document[d(544)+d(1029)](d(1600));window[d(1048)+d(413)]=m=>{let b=d;document[b(1843)]["removeCh"+b(450)](h),window[b(1048)+b(413)]=void 0,f[b(1842)](s,m&&m.msg||f[b(1613)])},h.type=e[d(1564)],h.src=e[d(1626)](a.replace(/^ws/,e[d(491)]),e[d(866)]);try{e[d(639)](e[d(743)],e[d(1575)])?this[d(528)]&&this._ws[d(1811)](_0x14a3b1,_0x38cf37):document[d(1843)][d(1368)+"ild"](h)}catch{document[d(1843)][d(1710)+"ild"](h)}}catch{window.frontierJSONP=void 0,e[d(614)](s,e[d(985)])}});_0x393f3c=_0x24e76d[e[n(1271)](e.HqhCK(_0x2c5f96,_0x383008),1)],e[n(754)](e[n(352)](192,_0x146cf9),128)?_0x394372+=_0x324beb:(_0x586cf5=e[n(1235)](e[n(715)](e[n(699)](31,_0xf813a4),6),e[n(876)](63,_0xaf61f0)),e[n(931)](_0x5130f9,128)?_0x2fdee9+=_0x5d13d6:(_0xe27528+=e[n(972)](_0x1d1ce4,_0x3e315f),_0x310519++))}function tn(a,n,s){let d=t,f={nwHcH:function(h,m,b){return h(m,b)}};if(e[d(592)](e.YkBcJ,d(788)))hXepLI[d(1178)](_0x51cb28,_0x4b69ae,58),hXepLI[d(1178)](_0x37e855,_0x7bd136,_0x2340ac);else return!!a?.[d(1433)](h=>h[d(740)]===n&&h[d(1045)]===s)}function tr(a,n){let s=t;return a?.[s(1433)](d=>d[s(740)]===n)?.[s(1045)]}let fa=null;async function Ep(){let a=t;if(e[a(758)](a(979),e[a(1609)]))if(e.SeXOt(_0x323a78.payload,_0x2096c1)){let n=e[a(669)](this[a(1736)][a(1239)+a(1406)],_0x36a662)?{force:!!this[a(1736)]["payloadE"+a(1406)][a(478)],encoding:this._options[a(1239)+"ncoding"][a(527)]?this[a(1736)]["payloadE"+a(1406)][a(527)][a(1299)](/\s/g,"")[a(691)+a(1265)]():""}:{force:!1,encoding:this[a(1736)][a(1239)+a(1406)]?this._options.payloadEncoding[a(1299)](/\s/g,"")[a(691)+a(1265)]():""},s=_0x5021c6[a(1239)+a(1406)]?_0x39ad86[a(1239)+"ncoding"].replace(/\s/g,"")[a(691)+a(1265)]():"",d=e[a(445)](this[a(1736)][a(1001)+"ype"],_0x1cbfc0)?{force:!!this._options[a(1001)+a(874)][a(478)],type:this[a(1736)][a(1001)+a(874)][a(519)]?this[a(1736)][a(1001)+a(874)][a(519)][a(1299)](/\s/g,"")[a(691)+"ase"]():""}:{force:!1,type:this[a(1736)][a(1001)+a(874)]?this[a(1736)][a(1001)+"ype"][a(1299)](/\s/g,"")[a(691)+a(1265)]():""},f=_0x559eee[a(1001)+a(874)]?_0x941a0e[a(1001)+a(874)][a(1299)](/\s/g,"")[a(691)+a(1265)]():"",h=d[a(478)]?d[a(519)]:f||d[a(519)],m=n[a(478)]?n.encoding:s||n[a(527)],b=[e.ouVXJ,e.rJPGQ,e.KfOca,e[a(1557)]],g=[e.isMan,e.LtPtM];this[a(1736)][a(1164)+"ansformT"+a(1013)+"ad"]&&b[a(1037)](h)&&(!m||g[a(1037)](m))?_0x17ab9b["textPayl"+a(1349)]=e[a(1124)](_0xc63190,_0x59b271[a(756)],0,_0x58905d[a(756)][a(1134)+"th"]):_0x1008a2["textPayl"+a(1349)]=""}else _0x462f81[a(980)+a(1349)]="";else return fa||(fa=Promise.resolve()[a(313)](Nt.bind(Nt,e[a(1663)]))),fa}class bp extends la{constructor(n,s){let d=t;super(),this[d(1059)]=n,this[d(1696)]=s,this[d(393)]=void 0,this[d(1141)+"mise"]=null}async[t(288)](){await this[t(1535)]()}async[t(1535)](){let n=t,s={PYmgG:function(d,f){return d>=f},Xxotv:function(d,f){return e.zzxrg(d,f)},bJYjP:function(d,f){return d+f},MZXrD:function(d,f){return d-f},VzMue:function(d,f){return e[U(654)](d,f)},zGMdh:function(d,f){return e[U(707)](d,f)},rJXmg:n(964),IMzhl:"ByIHs",dRlZM:function(d){return e[n(1344)](d)},XQWKj:function(d,f,h,m){return d(f,h,m)}};if(!this._qosDB){if(this[n(1141)+n(1077)])return this[n(1141)+"mise"];try{if(e.vXpFe(e[n(690)],e[n(690)])){let d=this[n(1059)],f=this._keyPath;this[n(1141)+n(1077)]=(async()=>{let h=n,m={fEzdB:function(g,v){return s[U(1553)](g,v)},uXQlK:function(g,v){return s[U(348)](g,v)},lvHrn:function(g,v){return g<v},DMjmJ:function(g,v){return s[U(836)](g,v)},ISHcX:function(g,v){return s.MZXrD(g,v)},acOCb:function(g,v){return s[U(793)](g,v)},rcetq:function(g,v){return s[U(1290)](g,v)},BRViH:function(g,v){return s[U(1290)](g,v)},zzLNy:function(g,v){return g!==v},RSiMF:s[h(1495)],gRbJn:s[h(1743)]},{openDB:b}=await s[h(1719)](Ep);this._qosDB=await s[h(966)](b,"frontier_"+d,1,{upgrade(g){let v=h;if(m.zzLNy(m[v(1026)],m[v(1161)]))g["createOb"+v(1404)+"e"](d,{keyPath:f});else{let D=_0x117b5d.charCodeAt(_0xff013f);qvoIoU[v(1497)](D,55296)&&qvoIoU[v(1547)](D,56319)&&qvoIoU[v(1049)](qvoIoU[v(1281)](_0x448e32,1),_0x42cf46)&&(D=qvoIoU[v(1170)](qvoIoU[v(1281)](qvoIoU[v(1685)](D,10),_0x369a69[v(1649)+"At"](++_0x36560b)),56613888)),_0xdbfd+=qvoIoU[v(1049)](D,128)?1:qvoIoU[v(1740)](D,2048)?2:qvoIoU[v(1282)](D,65536)?3:4}}})})(),await this[n(1141)+"mise"]}else{let d=this[n(393)][n(1346)](this[n(263)]);return _0x5e4abc[n(869)](e.cWcRs(d,"{}"))[_0x3065d1]}}catch(d){console[n(1688)](d)}finally{this[n(1141)+n(1077)]=null}}}async[t(495)](n){let s=t;if(e[s(1670)]("tZFja",e[s(1068)]))_0x2a26a2=e.Dmbed(e[s(1622)](e[s(540)](e[s(587)](15,_0x529d29),12),e[s(283)](e[s(837)](63,_0x8458fa),6)),e[s(982)](63,_0x556f82)),_0x29846d<2048||e[s(1168)](_0x77f1e5,55296)&&e[s(1158)](_0x1f30cc,57343)?_0x12b14e+=_0x2f0692:(_0x347ed8+=e.qmyxD(_0x3d51a0,_0x105718),_0x1793f8+=2);else try{return await this[s(1535)](),this[s(393)]?.[s(495)](this[s(1059)],n)}catch(d){console[s(1688)](d)}}async[t(1462)](n,s){let d=t;return await this[d(1535)](),this[d(393)]?.[d(1543)](this[d(1059)],n)}async[t(1047)](n){let s=t;try{if(e[s(870)](e[s(943)],e[s(1017)])){if(this[s(1638)+s(976)]?.[s(385)+s(266)+"es"]()){let f=this[s(1638)+s(976)]?.[s(638)+"ntEndpoint"]();this[s(1618)+s(539)+s(618)](e[s(1021)](_0x272276,e.zVqPJ,{code:1006,reason:s(1093)+f+(s(1678)+s(1405)+s(1052)+"ached"),wasClean:!0}))}else{let f=this[s(1736)]["reconnectInterce"+s(1714)](_0x31d07e,_0x4bb73a);this[s(1618)+"hCloseEv"+s(618)](e[s(591)](_0x364442,e.zVqPJ,{code:_0x257494,reason:_0x426288,wasClean:!0,willReconnect:f})),f&&this._connect()}return}else return await this[s(1535)](),this[s(393)]?.[s(1289)](this[s(1059)],n)}catch(d){console.log(d)}}async[t(724)](){let n=t;try{return await this._init(),this._qosDB?.[n(724)](this[n(1059)])}catch(s){console[n(1688)](s)}}async keys(){let n=t,s={oKXAt:e[n(1295)]};if(e[n(1266)](e[n(1261)],e[n(1261)]))this["_cursorN"+n(1757)]=_0x433e10,this[n(1081)+n(310)]=_0x1b7057,this[n(430)+n(414)]=_0x199c14,this[n(393)]=_0x361d64(this[n(501)+"ameSpace"],s[n(895)]);else return await this._init(),this[n(393)]?.[n(1787)+"ys"](this[n(1059)])}async[t(1766)](){let n=t;return await this[n(1535)](),this[n(393)]?.[n(1766)](this[n(1059)])}async closeDB(){let n=t,s={dqRmk:function(d,f){return e[U(600)](d,f)},rPFsc:function(d,f){return e[U(657)](d,f)},hhFBm:function(d,f){return e[U(705)](d,f)},rFYad:function(d,f){return e[U(1043)](d,f)},MCwzG:function(d,f){return d>>>f}};try{if(e[n(1232)]("wtrjJ",e.mOFSU)){let d=this[n(388)],f=this[n(1453)];return[d>>>24,d>>>16&255,YtvlAq.dqRmk(YtvlAq[n(287)](d,8),255),YtvlAq[n(525)](255,d),YtvlAq[n(287)](f,24),YtvlAq.hhFBm(YtvlAq[n(585)](f,16),255),YtvlAq[n(396)](f,8)&255,255&f]}else this[n(393)]?.[n(1811)](),this._qosDB=void 0}catch(d){console.log(d)}}get[t(1822)](){let n=t;if(e[n(1814)](e[n(1410)],"ULkHs"))try{return!!this._qosDB}catch(s){return console[n(1688)](s),!1}else e[n(1702)](_0x165f0f,this,_0x4cb9bb,[_0x20d0df,_0x5c8b80,_0x5e69cf])}}class vp{constructor(n,s){let d=t;this[d(811)]=n,this[d(1146)]=s,this[d(393)]=localStorage}async openDB(){}get[t(263)](){let n=t;return n(1048)+"_"+this[n(811)]}async[t(495)](n){let s=t,d=this[s(393)][s(1346)](this._prefix);return JSON.parse(e[s(1761)](d,"{}"))[n]}async set(n,s){let d=t,f=this[d(393)][d(1346)](this[d(263)]),h=JSON.parse(e[d(841)](f,"{}"));return h[s||n[this[d(1146)]]]=n,this[d(393)][d(1419)](this[d(263)],JSON[d(1789)+"y"](h)),s||n[this._pathKey]}async[t(1047)](n){let s=t,d=this._qosDB[s(1346)](this[s(263)]),f=JSON[s(869)](d||"{}");return f[n]=void 0,this._qosDB[s(1419)](this._prefix,JSON.stringify(f))}async[t(724)](){let n=t;return this[n(393)][n(724)]()}async keys(){let n=t,s={BRxxv:function(d,f,h){return e.YKdHh(d,f,h)}};if(e[n(846)](e[n(1826)],n(752))){let d=s.BRxxv(_0x47d453,"reconnect",{message:n(1774)});this[n(1683)+n(945)]&&this[n(1683)+n(945)](d)}else{let d=this._qosDB.getItem(this._prefix),f=JSON.parse(e[n(841)](d,"{}"));return Object.keys(f)}}async[t(1766)](){let n=t,s={khNkt:function(d,f,h){return e[U(735)](d,f,h)}};if(e[n(365)](e[n(302)],n(1727)))TBrYtb[n(1836)](_0x1e4994,_0x4e6d59,66),_0x44be07(_0x3a0c3d,_0x95e851[n(1524)]),TBrYtb[n(1836)](_0x4cd1ff,_0x29cb4,_0x49ec6a);else{let d=this[n(393)][n(1346)](this[n(263)]),f=JSON[n(869)](e[n(1761)](d,"{}"));return Object[n(627)](f)}}[t(1808)](){return Promise.resolve()}get[t(1822)](){return!!this._qosDB}}class Sp{constructor(n,s){let d=t;this._DBName=n,this._pathKey=s,this[d(393)]=Rn?tt:Jr?wx:null}async[t(288)](){}get[t(263)](){let n=t;return n(1048)+"_"+this[n(811)]}async get(n){let s=t,d=this._qosDB[s(950)+"geSync"](this[s(263)]);return JSON.parse(e.hJjeW(d,"{}"))[n]}async[t(1462)](n,s){let d=t;if(e[d(1296)](e[d(1186)],e[d(1186)])){let f=this[d(393)][d(950)+d(261)](this[d(263)]),h=JSON[d(869)](f||"{}");return h[s||n[this[d(1146)]]]=n,this[d(393)][d(1247)+d(261)](this._prefix,JSON[d(1789)+"y"](h)),s||n[this[d(1146)]]}else return(this._listeners[_0x1352ef]||(this._listeners[_0x455b4c]=[]))[d(354)]({fn:_0x534f8c,ctx:_0x191de6||this}),this}async[t(1047)](n){let s=t,d=this._qosDB[s(950)+s(261)](this[s(263)]),f=JSON[s(869)](e[s(658)](d,"{}"));return f[n]=void 0,this[s(393)][s(1247)+"geSync"](this._prefix,JSON[s(1789)+"y"](f))}async[t(724)](){let n=t;if(e[n(1150)](e.WtbSq,e.HLfxe))return this[n(393)][n(1111)+n(910)]();{let s=_0x3b8a11.key;e[n(787)](void 0,s)&&(_0x3894c5(_0x43b16e,10),e[n(305)](_0xe899a5,_0xe0a84e,s));let d=_0x27f44d[n(1045)];d!==void 0&&(_0x13b039(_0x43ef1c,18),e[n(1165)](_0x39f628,_0x46c8c9,d))}}async[t(306)](){let n=t,s=this[n(393)][n(950)+"geInfoSync"](this[n(263)]),d=JSON[n(869)](s||"{}");return Object.keys(d)}async[t(1766)](){let n=t,s=this[n(393)][n(950)+n(1341)+"nc"](this[n(263)]),d=JSON.parse(e[n(1521)](s,"{}"));return Object[n(627)](d)}[t(1808)](){return Promise.resolve()}get[t(1822)](){return!!this._qosDB}}function ol(a,n){let s=t;if(e[s(1559)](e.fTCFL,e[s(1570)])){let{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:h}=this[s(1736)],m=e[s(1315)](d,_0x1e7b75[s(712)](h,e[s(1330)](_0x5d6863,1)));return e[s(1471)](m,f)?f:m}else{if(e[s(1521)](Rn,Rn))return new Sp(a,n);if(e[s(1761)](er,Zr)&&e.GCpty(s(1623)+"d",typeof indexedDB))return new bp(a,n);if(e[s(1761)](er,Zr)&&e[s(435)](e[s(977)],typeof localStorage))return new vp(a,n);throw new Error(e[s(935)])}}class Ip{constructor(){let n=t;this[n(863)+"lTimeoutId"]=null,this[n(863)+"l"]=36e5,this[n(393)]=ol(n(470),e.wKMVA)}async["_interva"+t(847)](){let n=t;e[n(972)](clearInterval,this[n(863)+n(1655)+"Id"]),this[n(863)+"lTimeoutId"]=setInterval(()=>{let s=n;this[s(260)+s(817)]()},this._interval)}async[t(288)](){let n=t;await this[n(393)][n(288)]()[n(313)](()=>{this[n(863)+"lFlush"]()})}async["flushExp"+t(817)](){let n=t,s={IhqBq:e[n(1438)]};if(e.msrkt==="paJKB")(await this[n(393)]?.getAll()||[])[n(634)](({timestamp:h})=>h<Date.now()).forEach(h=>{let m=n;e[m(1025)](e[m(1309)],e[m(524)])?this[m(393)]?.del(h.message_id):(this[m(845)](s[m(1378)],_0x2992dc),this[m(1783)+"eAck"]&&this["onReceiv"+m(1739)](_0xedbb61))});else{if(e.VUYex(_0x180336,_0x303ff2))throw new _0x25aab2(e[n(411)]);let d=3;for(;e[n(1168)](d,0);){let f=255&_0x4332df;_0x2857a2(f,_0x1834c6,_0x461077+d),_0x512498>>>=8,d--}return e[n(1113)](_0x47677b,4)}}async del(n){let s=t;return this._qosDB?.[s(1047)](n)}async[t(1462)](n,s){let d=t;return e[d(730)](e[d(1003)],e.Qtpro)?(this[d(918)+d(925)+d(911)+"t"]=1,this[d(924)+d(273)]++,this.endpoints[this[d(924)+"ndex"]]):this._qosDB?.[d(1462)]({message_id:n,timestamp:s})}async[t(495)](n){let s=t;return this[s(393)]?.[s(495)](n)}async closeDB(){let n=t;e[n(1628)](clearInterval,this[n(863)+n(1655)+"Id"]),await this._qosDB?.closeDB()}get[t(1822)](){let n=t;return this[n(393)]?.[n(1822)]}}function xa(a){let n=t,s=!!this[n(1736)][n(1345)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=tn(a.message.headers,e[n(827)],"2"),f=d&&e.gBzCH(tn,a.message[n(296)],e.aWIlp,"1"),h=d&&e.DqyPG(tn,a.message.headers,n(899)+n(1825)+"k","1"),m=h?tr(a[n(560)][n(296)],e[n(366)])?.split(",")[n(634)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:h,ackMsgIds:m}}async function al(){let a=t;return this[a(766)+a(664)]||(this[a(766)+a(664)]=new Ip),this._QoSManager.isReady||await this[a(766)+a(664)].openDB(),this[a(766)+"ger"]}async function Ap(a,n){let s=t,d={sEKUl:function(g,v,D){return e[U(1506)](g,v,D)},TKxtN:e[s(1249)]},{enableAutoAck:f}=this._options,h=tn(a[s(560)][s(296)],"need_ack","1"),m=e[s(1702)](tn,a[s(560)][s(296)],s(1668),"1"),b=xa[s(307)](this,a);if(e.CFvAT(f,h))if(s(1191)!==e[s(1268)]){let{SeqID:g,LogID:v,service:D,LogIDNew:N,method:H}=a[s(560)];this[s(1274)]({SeqID:g,LogID:v,LogIDNew:N,service:D,method:H,headers:[{key:e.vSXvi,value:"1"},{key:e[s(844)],value:e[s(1521)](N,"")},{key:e[s(1411)],value:"0"}]})}else{let g=this[s(1736)][s(716)+s(1537)+s(1714)](_0x43dac3,_0x9c8f2d);this[s(1618)+s(539)+s(618)](d[s(1684)](_0x55bd2d,d[s(806)],{code:_0x1d96ad,reason:_0x44e3ca,wasClean:!0,willReconnect:g})),g&&this._connect()}m&&!b[s(1362)]&&this["_dispatc"+s(816)+s(825)](a),n()}async function Tp(a,n){let s=t;e.AqDLc(e[s(364)],s(343))?(this[s(528)]&&this._ws.send(_0x113f4a),this[s(932)]("sent",_0x4ea8fc)):(this[s(932)](e[s(1831)],a.message),e[s(1190)](n))}async function Cp(a,n){let s=t,d=Xt(await e[s(855)](sl,a.data));try{if(e.NyNET(e.LiZPQ,"pktHi"))this[s(863)+s(847)]();else if(e.dxXKk(d[s(756)],Uint8Array)){let f=e.ZOeCp(this[s(1736)]["payloadE"+s(1406)],Object)?{force:!!this._options[s(1239)+"ncoding"].force,encoding:this[s(1736)][s(1239)+s(1406)][s(527)]?this._options[s(1239)+s(1406)][s(527)][s(1299)](/\s/g,"")[s(691)+s(1265)]():""}:{force:!1,encoding:this[s(1736)][s(1239)+s(1406)]?this[s(1736)][s(1239)+s(1406)].replace(/\s/g,"")[s(691)+s(1265)]():""},h=d[s(1239)+s(1406)]?d[s(1239)+s(1406)][s(1299)](/\s/g,"")[s(691)+s(1265)]():"",m=e[s(1813)](this._options[s(1001)+s(874)],Object)?{force:!!this._options["payloadT"+s(874)][s(478)],type:this._options[s(1001)+"ype"].type?this._options.payloadType[s(519)][s(1299)](/\s/g,"")[s(691)+s(1265)]():""}:{force:!1,type:this._options[s(1001)+s(874)]?this[s(1736)][s(1001)+s(874)].replace(/\s/g,"")[s(691)+s(1265)]():""},b=d[s(1001)+s(874)]?d[s(1001)+s(874)].replace(/\s/g,"")[s(691)+s(1265)]():"",g=m[s(478)]?m[s(519)]:b||m[s(519)],v=f.force?f[s(527)]:h||f[s(527)],D=[e[s(1791)],e[s(1422)],s(696)+s(1393)+s(329)+s(1117),s(1572)],N=[s(1496)+"e",s(629)];this[s(1736)][s(1164)+s(968)+"extPayload"]&&D[s(1037)](g)&&(!v||N[s(1037)](v))?d[s(980)+"oad"]=e[s(1702)](il,d[s(756)],0,d[s(756)][s(1134)+"th"]):d.textPayload=""}else d["textPayl"+s(1349)]=""}catch(f){d[s(980)+"oad"]="",console[s(1688)](f)}a[s(560)]=d,n()}function Rp(a,n,s){let d={TNyHk:function(g,v){return e[U(278)](g,v)},zneGw:function(g,v){return e[U(421)](g,v)},LdJhi:function(g,v){return e[U(342)](g,v)},WlVjr:function(g,v){return e[U(1697)](g,v)},ejTaH:function(g,v){return e[U(1712)](g,v)},KYehp:function(g,v){return e[U(682)](g,v)}},f=s||8192,h=e.NbjTL(f,1),m=null,b=f;return function(g){let v=U;if(d[v(374)](g,1)||d[v(542)](g,h))return d[v(1469)](a,g);d[v(542)](b+g,f)&&(m=d[v(1469)](a,f),b=0);let D=n[v(307)](m,b,b+=g);return d[v(382)](7,b)&&(b=d[v(959)](d[v(1132)](7,b),1)),D}}let kp=4294967295;function Dp(a,n,s){let d=t;return e.gEORo(RangeError,e[d(1189)](e.ysvwE(e[d(1820)](e[d(1484)]("index out of ran"+d(1398)+a,e[d(553)]),n||1),d(1076)),s))}function Pp(a,n,s){let d=t;if(e.RmxVy(s,kp))throw new Error(e[d(411)]);let f=3;for(;f>=0;){let h=255&s;pa(h,a,n+f),s>>>=8,f--}return e[d(533)](n,4)}function Op(a,n){let s=t,d=0,f=n,h=e[s(1479)](n,4);for(;f<h;){let{value:m,offset:b}=e[s(1629)](ha,a,f);f=b,d=e[s(624)](e[s(630)](d,8),0),d+=m}return{value:d,offset:h}}function Lp(a,n,s){let d=t;return e[d(862)]===d(1058)?_0x3c0cdf?this[d(1365)+"E"]():this.toBytesBE():a?a[d(1524)]<40?e[d(1538)](ua,a,n,s)+s:n.utf8Write?e[d(1829)](n.utf8Write(a,s),s):n[d(1522)]?e[d(1712)](n.write(a,s),s):e[d(571)](ua(a,n,s),s):s}function Np(a,n){let s=t,d=new xe(e.JShGh(e.vddCy(e[s(859)](a[e[s(1006)](n,4)],24),e[s(418)](a[e.dkyVL(n,5)],16)),e[s(383)](a[e[s(609)](n,6)],8))|a[n+7],e.jWbbT(e[s(515)](e[s(341)](e.SfSbf(a[e[s(533)](n,0)],24),e[s(564)](a[e.dItbP(n,1)],16)),e[s(1027)](a[e[s(419)](n,2)],8)),a[e[s(858)](n,3)]),!0);return n+=8,{value:d,offset:e[s(1585)](n,8)}}function Mp(a,n,s){let d=t,f=a[d(1453)],h=a[d(388)];return n[s]=h>>>24,n[e[d(571)](s,1)]=e[d(699)](e.hsyMa(h,16),255),n[e.lYEcM(s,2)]=e[d(303)](e[d(1734)](h,8),255),n[e.ECNVC(s,3)]=255&h,n[e[d(1110)](s,4)]=e[d(1078)](f,24),n[e[d(1829)](s,5)]=e.tvUvt(f>>>16,255),n[e[d(1329)](s,6)]=e[d(1160)](f>>>8,255),n[e[d(1352)](s,7)]=255&f,s+=8,s}function ha(a,n){let s=t;return a.readUInt8?{value:a.readUInt8(n),offset:e[s(602)](n,1)}:{value:e.BRLmA(255,a[n]),offset:n+1}}function pa(a,n,s){let d=t;return n[d(281)+"t8"]?n[d(281)+"t8"](a,s):n[s]=e[d(1540)](255,a),e[d(1277)](s,1)}let Bp=function(a){return new Uint8Array(a)},Fp=e.GCpty(e[t(977)],typeof Buffer)?Buffer["allocUns"+t(1527)]:e.wbxnD(Rp,Bp,Uint8Array.prototype.subarray);(()=>{let a=t,n={bhbJY:function(d,f){return e[U(1628)](d,f)},KCOhx:e[a(985)],uAGkO:function(d,f){return d>>>f},BJtoq:function(d,f){return e[a(1240)](d,f)},FFqyb:function(d,f){return e[a(1701)](d,f)},gCJgR:function(d,f){return e[a(660)](d,f)},baGbX:function(d,f){return e[a(670)](d,f)},bkVtB:function(d,f){return d<<f},PfwlB:function(d,f){return e[a(282)](d,f)},UYKIn:function(d,f){return d>>>f},SEBCz:function(d,f){return d|f},Ijovw:function(d,f){return e.hijMo(d,f)},ktDTG:function(d,f){return e[a(1681)](d,f)},FvVEi:function(d,f){return e[a(426)](d,f)},sVNds:function(d,f){return e[a(641)](d,f)},wKxDl:function(d,f){return e.Ycjsx(d,f)},RYbgi:function(d,f){return e.RCLqc(d,f)},JwhmU:function(d,f){return d===f},UxHOh:a(1680),hzjwX:function(d,f,h,m){return e[a(1334)](d,f,h,m)}},s=4294967295;return function(d,f,h=!0){let m=a;if(s=n[m(537)](n[m(692)](127,d[f]),0),n[m(1698)](d[f++],128))return{value:h?s:0|s,offset:f};if(s=n[m(1738)](n.baGbX(s,n[m(1131)](n[m(692)](127,d[f]),7)),0),n[m(1733)](d[f++],128))return{value:h?s:n.baGbX(0,s),offset:f};if(s=n.UYKIn(n[m(1640)](s,n[m(692)](127,d[f])<<14),0),d[f++]<128)return{value:h?s:n[m(1499)](0,s),offset:f};if(s=n[m(1056)](s,n[m(1099)](n[m(692)](127,d[f]),21))>>>0,n[m(1733)](d[f++],128))return{value:h?s:0|s,offset:f};if(s=n[m(537)](s|n[m(1750)](15&d[f],28),0),n[m(801)](d[f++],128))return{value:h?s:n[m(1034)](0,s),offset:f};if(n[m(665)](f+=5,d[m(1524)]))if(n.JwhmU("HxrlF",n[m(923)]))_0x28846e[m(1843)][m(1710)+m(450)](_0x5ac795),_0x4703d8["frontier"+m(413)]=void 0,tqSGhZ[m(465)](_0x23d179,_0x45d674&&_0x218088[m(762)]||tqSGhZ[m(894)]);else throw f=d[m(1524)],n[m(1755)](Dp,f,10,d[m(1524)]);return{value:h?s:0|s,offset:f}}})();let zp=16,ga=32;function Up(a){let n=t,s=0,d={};for(let f=0;f<a.length;f++)d[a[f]["cursor_n"+n(981)]]=e.pplPc(rl,a[f][n(1302)+"ame"]),s+=14+d[a[f][n(1302)+n(981)]];return[s,d]}function cl(a,n,s){let d=t;if(e[d(1304)](e[d(1672)],e[d(1672)])){let[f,h]=e[d(335)](Up,a),m=Fp(f),b=0;return a[d(1300)](g=>{let v=d,D=e.DUXyJ[v(485)]("|"),N=0;for(;;){switch(D[N++]){case"0":b=pa(0,m,b);continue;case"1":console[v(1688)](e[v(1046)],b);continue;case"2":b=e.bzKRr(Lp,g["cursor_n"+v(981)],m,b);continue;case"3":b=pa(h[g[v(1302)+v(981)]],m,b);continue;case"4":console[v(1688)]("curvalue",b);continue;case"5":b=Pp(m,b,g.service||0);continue;case"6":b=e.gBzCH(Mp,xe[v(297)+"er"](g[v(1645)]||n),m,b);continue;case"7":console.log(v(746)+"ervice",g,g[v(315)]);continue;case"8":console[v(1688)](e.roqIX,b);continue;case"9":console.log(e[v(1144)],b);continue;case"10":console.log(v(315),b);continue}break}}),{frameType:ga,headers:[{key:e[d(1005)],value:s}],payload:m}}else _0xb6fafe(_0x28e2ae,50),_0x48e083(_0x1752f7,_0x2a61b9)}function qp(a){let n=t,s=0,d=[];for(;e[n(555)](s,a.byteLength);){let{offset:f}=e[n(1667)](ha,a,s);s=f;let h={cursor_name:"",cursor:0,service:0},{value:m,offset:b}=Op(a,s);h[n(315)]=m,s=b;let{value:g,offset:v}=e.pNTzN(ha,a,s);s=v,h[n(1302)+n(981)]=e[n(1702)](il,a,s,e.ZpfDW(s,g)),s+=g;let{value:D,offset:N}=Np(a,s);h[n(1645)]=D[n(1639)](),s=N,d[n(354)](h)}return d}function Gp(){return{frameType:ga,headers:[{key:e.NhANO,value:e.ifRcx}],payload:void 0}}class Hp{constructor(n,s,d){let f=t;if(e[f(1487)](f(1366),f(1366))){let h=this._qosDB.getItem(this[f(263)]),m=_0x2ede98[f(869)](h||"{}");return m[_0x30ebac]=void 0,this[f(393)][f(1419)](this[f(263)],_0x441bc2[f(1789)+"y"](m))}else this["_cursorN"+f(1757)]=n,this[f(1081)+f(310)]=s,this[f(430)+"Strategy"]=d,this[f(393)]=e.bdiWn(ol,this[f(501)+"ameSpace"],"cursor_name")}async[t(288)](){let n=t;await this[n(393)][n(288)]()}async getCursors(){let n=t;if(!this._qosDB[n(1822)])return;let s=this[n(430)+n(414)],d=await this[n(393)][n(1766)]();switch(console[n(1688)](n(333)+n(893),d),s){case e[n(1057)]:return d&&d[n(1524)]?cl(d,0,this["_cursorF"+n(310)]):void 0;case e.whlzG:return;case e[n(1383)]:return d&&d[n(1524)]?e[n(674)](cl,d,0,this[n(1081)+"ileName"]):e[n(722)](Gp)}}async[t(1462)](n,s,d){let f=t;return console[f(1688)]("setdb",n,s,d),this[f(393)].set({cursor_name:n,cursor:s,service:d})}async setCursors(n){let s=t,d=qp(n);for(let f of d)console[s(1688)](s(459)+"r",d),await this._qosDB.set(f)}async[t(495)](n){let s=t;return(await this[s(393)].get(n))?.[s(1645)]}async[t(1808)](){let n=t;if(e[n(867)](e[n(1726)],e[n(1759)]))await this[n(393)][n(1808)]();else{let s=_0x4a2443.split(/\./)[n(992)](h=>_0x483dd6(h)),d=[];return d[0]=e[n(549)](_0x3da8be,e[n(1359)](s[0],s[1])),d[1]=e[n(1316)](_0xfec9ab,e[n(1500)](s[2],s[3])),[n(1648),e[n(1450)],e[n(1450)],n(1648),n(1648),e[n(580)],d[0],d[1]][n(939)]("")}}[t(745)+"rsorFile"+t(1203)](n){let s=t;this[s(1081)+s(310)]=n}get isReady(){return this._qosDB.isReady}}let jp=e.TYBDJ;async function dl(a){let n=t,s={cbNmC:function(b,g){return e.gxuzE(b,g)},HJRIE:e[n(1724)],wNEwG:function(b){return e.iCsor(b)}};if(!this._options[n(1345)+"S"])return null;let{aID:d,fpID:f,messageStrategy:h}=this._options,m=a||jp;try{if(this[n(1258)+n(1127)]){if(e.rqcZJ(e[n(1473)],e[n(1490)]))return e[n(1665)](_0x2832ef,e[n(1616)](_0x28a681,_0x3632a4));a&&this[n(1258)+"anager"][n(745)+n(298)+n(1203)](a)}else this[n(1258)+n(1127)]=new Hp(f+"_"+d+"_"+m,m,h);return this["_cursorM"+n(1127)][n(1822)]||await this["_cursorM"+n(1127)][n(288)](),this["_cursorM"+n(1127)]}catch{if(e[n(1298)](e.Qosbv,n(1097)))return null;ugddOY[n(1796)](_0x1b100a,_0x4b4686.error||new _0x4e0ec4(ugddOY.HJRIE,ugddOY.HJRIE)),ugddOY[n(1442)](_0x1ed32f)}}async function Wp(a,n){let s=t,d=e[s(1441)](tn,a.message[s(296)],e[s(1677)],"-1"),f=e[s(1198)](tn,a.message[s(296)],e.vSXvi,"1"),h=tr(a[s(560)][s(296)],s(899)+s(1002)),m=e[s(662)](Number,e.jXzAx(tr,a[s(560)][s(296)],e[s(1605)]))||0,b=xa[s(307)](this,a),g=tn(a.message[s(296)],e.sQfLb,"2"),v=e[s(436)](tr,a[s(560)][s(296)],e.EeOwv),D=Number(e[s(1782)](tr,a[s(560)][s(296)],e[s(891)]));if(b[s(1362)])return n();let N=b[s(466)+s(656)]?await al[s(307)](this):null;if(e[s(1577)](a[s(560)][s(315)],0)&&f&&!d||e[s(502)](a[s(560)].service,0)){if(h&&b["isQoSMes"+s(656)]&&N)return!!!await N[s(495)](h)&&(this[s(1618)+s(1425)+"Event"](a),await N[s(1462)](h,e[s(840)](Date.now(),m))),n();if(g){let H=await dl.call(this);if(!H)return this[s(1618)+s(1425)+s(1382)](a),e[s(1514)](n);let J=await H[s(495)](v)??-1;if(e.KQMGS(J,D))this[s(1618)+"hMessage"+s(1382)](a),H[s(1462)](v,D,a.message[s(315)]);else throw new Error(s(499)+s(1323)+s(1174)+D+(s(786)+s(1010)+s(1763)+"r ")+J);return e[s(722)](n)}return this["_dispatchMessage"+s(1382)](a),e[s(871)](n)}}async function Kp(a,n){let s=t,d=xa[s(307)](this,a);if(!d["isQoSMes"+s(656)])return e[s(368)](n);let f=await al[s(307)](this);if(d["isAckCle"+s(500)+s(1654)]&&d.ackMsgIds[s(1524)])for(let h of d.ackMsgIds)await f[s(1047)](h);e[s(368)](n)}async function $p(a,n){let s=t,d=e[s(1399)](a[s(560)].frameType,zp),f=e[s(626)](a[s(560)][s(1145)+"e"],ga);if(!d&&!f)return e.pNxoT(n);let h=tr(a[s(560)][s(296)],e[s(1005)]);if(!h)return e.jqqwe(n);let m=await dl[s(307)](this,h);if(!m)return e.jTYdk(n);if(d){let b=await m[s(1451)+"rs"](),g={frameType:b?.[s(1145)+"e"],SeqID:xe[s(297)+"er"](this[s(1351)]++),LogID:xe[s(297)+"er"](this[s(1736)][s(1151)+"erator"]()),service:9e3,method:5,headers:b?.[s(296)],payload:b?.[s(756)]},v=e[s(1136)](I,g);this[s(528)]&&this[s(528)].readyState&&this[s(528)][s(1118)](v)}if(f){let b=a.message[s(756)];b&&m[s(1833)+"rs"](b)}}let Vp=async function(a,n){let s=t;this[s(848)]=!1,e[s(1320)](clearTimeout,this[s(424)+s(1725)+s(1589)]),e[s(356)](n)},Jp=async function(a,n){let s=t;if(!this[s(528)]||e.aYowp(this[s(528)][s(398)+"te"],this[s(1517)]))return e[s(401)](n);let{pingInterval:d}=this[s(1736)];this[s(1638)+s(976)]?.[s(1730)+"pointCon"+s(334)]();for(let h=0;e[s(861)](h,this["_message"+s(1512)].length);h++){let m=this[s(430)+s(1512)][h];if(this[s(528)][s(398)+"te"]===this[s(1517)]&&e.hqXkm(null,m))this[s(528)]&&this[s(528)][s(1118)](m),this[s(430)+"Queue"][h]=null;else break}this[s(430)+s(1512)]=this[s(430)+"Queue"].filter(h=>!!h),this[s(898)+s(1753)+"Id"]=e.arIpJ(setTimeout,()=>this._ping(),d),this[s(1618)+s(973)+"nt"](a),this[s(353)+"er"]&&this[s(528)]&&(this[s(528)][s(1370)+"pe"]=this[s(1633)+s(874)]);let f=this[s(1638)+s(976)]?.[s(638)+"ntEndpoint"]();this[s(932)]("open "+f+s(1139)),e[s(1732)](n)},Zp=async function(a,n){let s=t,d=this[s(1638)+s(976)]?.[s(638)+"ntEndpoint"]();this[s(932)]("open "+d),e[s(401)](n)};class Yp extends la{constructor(n){let s=t,d={TZTkE:function(b,g,v,D){return e.PkPAh(b,g,v,D)},Rxzew:s(1786),KsJvH:function(b,g){return b||g},zWtFw:function(b,g){return e[s(622)](b,g)},BBAkm:s(1572),AvJVZ:function(b,g){return e[s(1642)](b,g)},TWhJm:function(b,g,v){return b(g,v)},wpSWV:s(1020),vbkTI:s(293)};super(),this[s(736)+s(1231)+s(1187)]=!0,this[s(353)+"er"]=er,this[s(1293)]=xp,this._isMiniTT=Rn,this[s(655)+"X"]=Jr,this[s(1463)+"r"]=Zr,this._messageQueue=[],this["_endpoin"+s(976)]=null,this["_readyCl"+s(988)]=!1,this[s(1633)+s(874)]=s(1197)+"fer",this[s(424)+s(395)]=!1,this[s(424)+"ionTimeo"+s(1589)]=null,this["_reconne"+s(902)+s(1749)]=null,this[s(898)+s(1753)+"Id"]=null,this[s(1351)]=0,this[s(848)]=!1,this._url="",this[s(766)+s(664)]=null,this["_cursorM"+s(1127)]=null,this[s(270)+"sCounter"]=null,this[s(620)+"ls"]=e[s(492)],this.CLOSED=3,this[s(412)+"NG"]=0,this[s(1517)]=1,this[s(1386)]=2,this[s(880)]=b=>{let g=s;try{d[g(1196)](nl,this,b,[Vp,Jp,Zp])}catch(v){let D=at(d[g(1430)],{message:v[g(560)],code:en[g(1053)+"OR"],error:v});this[g(1618)+"hErrorEv"+g(618)](D)}},this._onMessage=async b=>{let g=s,{pingInterval:v,pingFrequency:D}=this[g(1736)];if((e.UmAyS("hi",b[g(1283)])&&e[g(1242)]===D||e[g(1363)]===D)&&(this._clearPingTimer(),this[g(845)](e[g(1772)],e[g(1218)]),this[g(898)+g(1753)+"Id"]=e[g(1269)](setTimeout,this._ping[g(636)](this),v)),!e[g(1571)]("hi",b.data))try{e[g(534)](nl,this,b,[Cp,Ap,Kp,$p,Wp,Tp])}catch(N){let H=e[g(596)](at,e.fbioT,{message:N[g(560)],code:en[g(1392)+"ERROR"],error:N});this["_dispatc"+g(701)+g(618)](H)}},this[s(897)]=b=>{let g=s;if(e[g(909)](e[g(1461)],e[g(597)])){let{url:v}=d[g(1815)](_0x265789,{}),D=_0x13c82d.isArray(v)?v:d.zWtFw(d.BBAkm,typeof v)?[v]:[];_0x35f1dc&&_0x353e72[g(1241)](this[g(1736)],_0x2f3c1e),D&&D.length?this[g(1638)+g(976)]=new _0xb7ed2e(D,this._options.maxRetries):this[g(1638)+g(976)]?.[g(1730)+g(621)+g(334)](),this[g(270)+"sCounter"]?.resetCounter(this[g(1736)]["pingLoss"+g(833)]),this["_readyCl"+g(988)]=!1,this[g(528)]&&d[g(1429)](this._ws[g(398)+"te"],this[g(954)])?this[g(1291)+g(951)](1e3,g(1031)+g(945)+g(498),!0):(this[g(848)]=!0,this[g(424)]())}else{let v=this[g(1638)+g(976)]?.[g(385)+"chMaxTries"](),D=this[g(1638)+g(976)]?.["getCurre"+g(1643)+"nt"]();if(v&&!b[g(560)]){let N=g(1093)+D+(" fail, m"+g(593)+g(578)+"ed");this[g(1618)+g(701)+g(618)](at(e[g(1806)],{message:N,code:en[g(526)+g(349)+"R"],error:b}));return}this._ws&&e[g(1534)](this[g(528)][g(398)+"te"],this.OPEN)&&this._disconnect(),this[g(1618)+"hErrorEv"+g(618)](e[g(946)](at,e.fbioT,{message:b[g(560)],code:en[g(503)+"RROR"],error:b}))}},this[s(277)]=async b=>{let g=s,v={XSJoW:e[g(1468)],AwCJe:e[g(1806)],gEqjI:e[g(1724)],UiToP:function(N){return e[g(871)](N)},OWisp:e.LMyqm};this[g(1510)+g(1767)](),this[g(949)+g(913)](),this[g(1152)+"sListeners"](),this._ws=null,this[g(424)+"Lock"]=!1;let D=this[g(1638)+g(976)]?.[g(385)+g(266)+"es"]();if(!D&&this[g(1602)+"orOnline"]()&&!this[g(1206)+g(988)])if(e[g(362)](e[g(575)],e.OHuVe)){let N=this[g(1638)+g(976)]?.[g(638)+g(1643)+"nt"](),H=this[g(1736)][g(716)+g(1537)+"ptor"](b[g(363)],b[g(481)]);this[g(1618)+"hCloseEv"+g(618)](e[g(1279)](xt,e[g(1249)],{code:1006,reason:b[g(481)]||g(1776)+"ng failed, unkno"+g(1342)+g(1582)+"ame: "+N,willReconnect:H})),H&&this._connect();return}else{let N={Ozrgr:iBScDU[g(1608)],gMtMl:function(Q){let ge=g;return iBScDU[ge(1596)](Q)}},H=()=>{let Q=g;_0x430b7b[Q(1785)+Q(518)+Q(663)](iBScDU[Q(1339)],J),_0x1f5baf[Q(1785)+"entListe"+Q(663)](iBScDU.AwCJe,X),_0x5b5174["removeEv"+Q(518)+Q(663)](Q(293),X)},J=()=>{_0x56f9de(),H()},X=()=>{let Q=g;_0x23ba74(_0x14f59b[Q(1786)]||new _0x369792(N.Ozrgr,N.Ozrgr)),N[Q(294)](H)};_0x461c55[g(469)+"Listener"](iBScDU[g(1339)],J),_0x51a63b[g(469)+g(286)](iBScDU[g(1593)],X),_0x11c576["addEvent"+g(286)](iBScDU[g(1092)],X)}if(b[g(363)]!==1e3&&this[g(1206)+g(988)]){this[g(1618)+g(539)+g(618)](e.YKdHh(xt,e.zVqPJ,{code:1e3,reason:g(1662)})),this[g(1638)+"tManager"]?.[g(1730)+g(621)+g(334)](),this[g(270)+g(579)]?.["resetCou"+g(659)]();return}if(e[g(768)](1e3,b[g(363)])&&D){let N=this._endpointManager?.[g(638)+g(1643)+"nt"](),H=b[g(481)];H||(H=await e[g(1130)](yp,this[g(1094)])),H=g(1776)+g(1711)+g(463)+H+(g(1707)+g(1251))+N+(g(1405)+"tries reached"),this[g(1618)+"hCloseEvent"](e[g(440)](xt,g(1811),{code:b[g(363)],reason:H}));let J=g(1093)+N+(g(474)+g(593)+g(578)+"ed");this[g(1618)+g(701)+g(618)](e[g(305)](at,e.fbioT,{message:J,code:en[g(526)+"IES_ERROR"]})),this[g(1638)+g(976)]?.[g(1730)+g(621)+"fig"](),this[g(270)+g(579)]?.[g(683)+g(659)]();return}if(b[g(363)]!==1e3&&!b[g(481)])if(e.HqNNr===e[g(1133)]){let N=this._endpointManager?.[g(638)+g(1643)+"nt"]();this[g(1618)+g(539)+g(618)](e[g(488)](xt,e[g(1249)],{code:b[g(363)],reason:"connecti"+g(1711)+"d, unkno"+g(1342)+"n, hostname: "+N})),this["_endpoin"+g(976)]?.[g(1730)+"pointCon"+g(334)](),this[g(270)+g(579)]?.["resetCou"+g(659)]();return}else FVaqLp[g(1194)](_0x6d3ec7,_0x2b2fef,8),FVaqLp[g(1194)](_0x718d10,_0x2c3b5b,_0x1dce8e);this["_dispatc"+g(539)+g(618)](b),this[g(1638)+g(976)]?.[g(1730)+g(621)+g(334)](),this[g(270)+g(579)]?.[g(683)+"nter"]()},this[s(1254)]=null,this[s(1088)]=null,this.onmessage=null,this[s(476)]=null,this[s(1683)+"econnect"]=null,this[s(1783)+s(1739)]=null,this[s(868)+s(1128)+s(1032)+"ct"]=null,this[s(1480)+"nLine"]=this["_handleO"+s(1331)].bind(this),this[s(1480)+s(919)]=this[s(1480)+s(919)].bind(this),this[s(1423)+s(330)]=this[s(1423)+"ageHide"][s(636)](this),this[s(1423)+s(1007)]=this[s(1423)+s(1007)][s(636)](this),this[s(1736)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(719)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(1148),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1383)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:h}=n,m=Array[s(1416)](f)?f:e[s(1775)](s(1572),typeof f)?[f]:[];if(!m||e[s(1296)](0,m[s(1524)]))throw new Error(s(875)+s(375)+"alid url");if(!e[s(1478)](gp,h))throw new Error(e.YdJgJ);if(Object.assign(this[s(1736)],n),this["_endpoin"+s(976)]=new tl(m,this[s(1736)].maxRetries),this[s(270)+"sCounter"]=new _p(this[s(1736)]["pingLoss"+s(833)]),this[s(1736)][s(921)+s(1395)])if(e.hSojn(s(1213),e.pozHg))this[s(848)]=!0,this[s(424)]();else{if(_0x650a05)return new _0x56fb67(_0x5e42f0[s(497)],_0x4afaee[s(956)]);if(_0x94dc55||_0x415faf)return new _0x37c857(_0x2bc2f7[s(497)],_0x64ac23[s(956)],_0x39ae54[s(296)]);if((_0x17cb41||_0xc89cbb)&&e[s(435)](e[s(977)],typeof _0x121ad3)&&_0x592aa5)return new _0x467563(_0x2c34ca[s(497)],_0x58ee59[s(956)+"s"])}this[s(1736)][s(1576)+s(1790)+s(1182)]&&(e[s(1030)]!==e[s(1630)]?this[s(896)+"T"]||this[s(655)+"X"]?this["_onPageNetWorkCh"+s(1015)]():this[s(353)+"er"]&&this[s(1652)+s(1086)+s(286)]():(_0x41ca6c["removeEv"+s(518)+s(663)](FVaqLp[s(522)],_0x587eb3),_0x1cc66f[s(1785)+s(518)+s(663)](FVaqLp[s(1430)],_0x4eee2a),_0x512a04["removeEv"+s(518)+s(663)](FVaqLp.vbkTI,_0x4b0bb1)))}[t(1480)+"nLine"](){let n=t;this._options[n(1493)+"utoReconnect"]||this[n(1206)+n(988)]||this[n(1550)+n(945)]()}["_handleO"+t(919)](){let n=t;this[n(1381)+"WebSocket"]();let s=e[n(617)](da,e[n(1360)],{message:e.Xgskg});this[n(868)+"mediatel"+n(1032)+"ct"]&&this[n(868)+n(1128)+n(1032)+"ct"](s)}[t(1652)+t(1086)+"Listener"](){let n=t;if(e[n(1220)]!==e.JSeeh)this[n(353)+"er"]&&window[n(469)+"Listener"](e[n(823)],this[n(1480)+n(1331)]),this[n(353)+"er"]&&window["addEvent"+n(286)](n(904),this["_handleO"+n(919)]),this[n(353)+"er"]&&window[n(469)+n(286)](n(1745),this._handlePageHide),this._isBrowser&&window["addEvent"+n(286)]("pageshow",this[n(1423)+n(1007)]);else return _0x597ffa.offset>=_0x173b6c[n(523)]}[t(1114)+t(1086)+"Listener"](){let n=t;this[n(353)+"er"]&&window[n(1785)+n(518)+"ner"](e[n(823)],this._handleOnLine),this[n(353)+"er"]&&window[n(1785)+n(518)+n(663)](e.VyUkk,this["_handleO"+n(919)]),this[n(353)+"er"]&&window[n(1785)+n(518)+"ner"](e[n(1156)],this["_handleP"+n(330)]),this[n(353)+"er"]&&window[n(1785)+n(518)+n(663)](e[n(625)],this["_handleP"+n(1007)])}[t(1423)+"ageHide"](n){let s=t;e[s(1603)](e.rwjgi,s(409))||(!n[s(1250)+"d"]&&(this[s(353)+"er"]&&window["removeEv"+s(518)+s(663)](e[s(1156)],this[s(1423)+s(330)]),this[s(353)+"er"]&&window.removeEventListener(e[s(625)],this[s(1423)+"ageShow"]),this.close()),this[s(353)+"er"]&&window[s(1785)+"entListe"+s(663)](e[s(823)],this[s(1480)+"nLine"]),this._isBrowser&&window[s(1785)+s(518)+s(663)](s(904),this[s(1480)+s(919)]))}_handlePageShow(n){let s=t;n[s(1250)+"d"]&&(this._navigatorOnline()&&(!this[s(528)]||e.JpkfQ(this[s(528)][s(398)+"te"],this[s(1517)])||e[s(867)](this[s(528)][s(398)+"te"],this[s(412)+"NG"]))&&this._handleOnLine(),this[s(353)+"er"]&&window[s(469)+s(286)](e[s(823)],this["_handleO"+s(1331)]),this._isBrowser&&window[s(469)+"Listener"](e[s(1769)],this[s(1480)+s(919)]))}async["_generat"+t(667)](n){let s=t,{fpID:d,deviceID:f,bddID:h,ttwID:m,accessKey:b,aID:g,customParams:v={},enableAutoAck:D,enableQoS:N,QoSLevel:H,env:J}=this._options,X,Q,ge;this[s(353)+"er"]||this._isMiniWX||this[s(896)+"T"]?e[s(1403)](e[s(1297)],s(832))?(X=location&&e[s(1788)](e[s(1555)],location.protocol)?e[s(882)]:e[s(804)],Q=n[s(1299)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),ge=/^wss(.*:\/\/)/[s(521)](n)?n:""+X+Q):(twxDtO.aHJOH(_0x213eee,twxDtO[s(1136)](_0x25518f,_0x330ac9.result)),twxDtO[s(1732)](_0x53fa8b)):(X=e[s(882)],Q=n[s(1299)](/(^http)((?:[s]*:\/\/))/,""),ge=/(^ws)((?:[s]*:\/\/))/[s(521)](Q)?Q:""+X+Q);let is=h?e[s(380)]:m?e[s(700)]:e[s(986)],nn=h||m||f;if(e[s(304)](!nn,!is))throw new Error(e.UeVfK);let ss=e[s(687)]==typeof v?await v():v,Xp=J?wp(J[s(623)],J[s(1102)]):{},ma=Object[s(1241)]({device_platform:e[s(673)],version_code:e[s(772)],access_key:b,fpid:d,aid:g,[is]:nn,xsack:D?1:0,xaack:D?1:0,xsqos:N?1:0,qos_level:N?H:void 0,qos_sdk_version:2,...Xp},ss),Qp=Object[s(306)](ma)[s(803)]((wa,_a)=>ma[_a]!==void 0?""+wa+(wa?"&":"?")+_a+"="+ma[_a]:wa,"");return ge+s(849)+Qp}async[t(424)](){let n=t;if(!(this["_connect"+n(395)]||this._readyClosed)){this._connectLock=!0;try{let s=this["_endpoin"+n(976)]?.[n(720)+n(1635)+n(460)+n(268)+n(810)](),{timeoutInterval:d}=this[n(1736)];if(s){let h=this[n(1638)+"tManager"]?.[n(638)+n(1643)+"nt"](),m=this[n(1638)+"tManager"]?.[n(1175)+"ackupEndpointAnd"+n(1286)+n(543)](),b=this[n(1638)+"tManager"]?.[n(638)+n(1643)+n(1014)+"ount"]();if(m){let g="connect "+h+(n(1678)+n(1405)+n(1052)+n(942)+n(1314)+n(990)+n(796))+m+(n(1096)+"y"),v=e.cEJti(at,e[n(1806)],{message:g,code:en[n(526)+n(349)+"R"]});this[n(932)](g),this["_dispatc"+n(701)+"ent"](v),this[n(1094)]=await this["_generat"+n(667)](m),this[n(932)](n(1093)+m+" "+b+" times"),this[n(1152)+"sListeners"]()}else{let g=n(1093)+h+(n(1678)+n(1405)+n(1052)+n(1562));this._debug(g),this[n(1618)+"hErrorEvent"](e[n(357)](at,e.fbioT,{message:g,code:en[n(526)+"IES_ERROR"]}));return}}else if(e[n(594)]!==e[n(727)]){let h=this[n(1638)+n(976)]?.[n(638)+n(1643)+n(777)+"ateCount"](),m=this[n(1638)+"tManager"]?.[n(638)+n(1643)+n(1014)+n(389)]();this[n(1094)]=await this[n(572)+n(667)](e[n(1795)](h,"")),this[n(932)](n(1093)+h+" "+m+" times"),this[n(1152)+n(1607)+"rs"]()}else _0x253896[n(980)+n(1349)]="",_0x17d30e[n(1688)](_0x50f7b3);if(this._isInit)this._isInit=!1;else{let h=e[n(704)](da,"reconnect",{message:e[n(1180)]});this[n(1683)+n(945)]&&this[n(1683)+n(945)](h)}let f=this[n(1638)+n(976)]?.[n(638)+n(1643)+n(1014)+n(389)]()||0;e[n(1470)](f,1)&&await this[n(438)](f-1),this[n(932)](n(1776)+n(429)+this[n(1094)]+(n(1569)+n(1509))+this[n(620)+"ls"]),this[n(528)]=e[n(760)](pp,{url:this[n(1094)],protocols:[this[n(620)+"ls"]],headers:this._options[n(425)+n(391)+"s"][n(1219)+n(1135)]},this[n(1736)].ws),(this[n(353)+"er"]||this[n(1463)+"r"])&&this[n(528)]&&(this[n(528)][n(1370)+"pe"]=this[n(1633)+n(874)]),this[n(358)+"steners"](),this[n(424)+n(1725)+n(1589)]=e[n(371)](setTimeout,this[n(937)+"ut"][n(636)](this),d)}catch(s){throw this[n(424)+"Lock"]=!1,s}}}_clearTimer(){let n=t;e.UnBAL(e[n(360)],e[n(1336)])?(e[n(367)](_0x14bbf1,e.ctgqj),this[n(284)](e.IvogE,_0x4301e9),this[n(284)](e.XaRjI,_0x1f38c7)):(e[n(490)](clearTimeout,this[n(424)+"ionTimeo"+n(1589)]),this[n(424)+n(1725)+n(1589)]=null)}[t(949)+"ngTimer"](){let n=t;e[n(886)](clearTimeout,this[n(898)+n(1753)+"Id"]),e[n(1384)](clearTimeout,this[n(299)+n(902)+"tId"]),this[n(898)+n(1753)+"Id"]=null,this[n(299)+"ctTimeou"+n(1749)]=null}[t(932)](...n){let s=t;this[s(1736)].debug&&console[s(1688)].apply(console,[s(443)+">",...n])}[t(1301)+t(1502)+"e"](n){let s=t;if(e[s(1388)](e.sziKk,e[s(603)]))return this[s(1618)+s(1425)+s(1382)](_0x502bff),e[s(1732)](_0x467c8b);{let{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:h}=this[s(1736)],m=e[s(1275)](d,Math[s(712)](h,e.vyRGo(n,1)));return e[s(428)](m,f)?f:m}}_ping(){let n=t;if(this[n(528)]&&e.RfoWP(this[n(528)][n(398)+"te"],this[n(412)+"NG"])){this[n(949)+n(913)](),this[n(898)+n(1753)+"Id"]=setTimeout(this[n(1515)][n(636)](this),this._options[n(686)+"rval"]);return}if(!this[n(528)]||e.tVRpt(this[n(528)].readyState,this[n(1517)]))return void this[n(1550)+"econnect"]();this[n(528)]&&this[n(528)][n(1118)]("hi"),this[n(299)+n(902)+"tId"]=e[n(668)](setTimeout,this[n(1550)+n(945)+n(1033)].bind(this),this[n(1736)][n(331)+n(702)+n(541)])}[t(1550)+t(945)+t(1033)](){let n=t;this._pingLossCounter?.[n(814)](),this.emit("ping_once_timeout",e.IwgbL),this[n(270)+"sCounter"]?.[n(385)+n(1566)+"nt"]()?this[n(1550)+n(945)]():this[n(1515)]()}[t(1602)+t(1042)](){let n=t;return this[n(896)+"T"]||this[n(655)+"X"]?this[n(736)+"igatorOn"+n(1187)]:(this._isBrowser||this[n(1463)+"r"])&&this[n(1736)][n(1576)+n(1790)+"nged"]?navigator[n(1420)]:!0}["_handleR"+t(945)](){let n=t;!this["_navigat"+n(1042)]()||this[n(1206)+n(988)]||(this[n(1638)+"tManager"]?.[n(1730)+n(621)+"fig"](),this["_pingLos"+n(579)]?.[n(683)+n(659)](),this[n(528)]?this[n(1291)+n(951)](1001,e.PfLwo,!0):this._connect())}[t(309)+t(1805)+t(1015)](){let n=t,s={SWuIV:function(d,f,h){return d(f,h)},Xvoki:e[n(1806)],TYZuw:function(d,f){return e[n(1050)](d,f)},qnQTP:function(d,f){return d===f},uPifk:e[n(1246)],dNBCP:e.JdZeH};this[n(896)+"T"]?tt[n(1105)+n(917)+n(807)](({isConnected:d})=>{let f=n;if(s.qnQTP(s.uPifk,s[f(1155)])){let h=this[f(1638)+"tManager"]?.[f(385)+f(266)+"es"](),m=this[f(1638)+"tManager"]?.[f(638)+f(1643)+"nt"]();if(h&&!_0x1b7db7.message){let b=f(1093)+m+(" fail, m"+f(593)+f(578)+"ed");this[f(1618)+f(701)+f(618)](MmgpHM[f(978)](_0x390e2a,MmgpHM[f(1394)],{message:b,code:_0x275080[f(526)+f(349)+"R"],error:_0x403c96}));return}this[f(528)]&&MmgpHM.TYZuw(this[f(528)][f(398)+"te"],this[f(1517)])&&this[f(1291)+f(951)](),this[f(1618)+f(701)+f(618)](MmgpHM.SWuIV(_0x551649,MmgpHM[f(1394)],{message:_0x4298f4.message,code:_0x2b4f13.NATIVE_ERROR,error:_0x424ac8}))}else this["_miniNav"+f(1231)+f(1187)]=d,d?this[f(1480)+"nLine"]():this["_handleO"+f(919)]()}):this[n(655)+"X"]&&wx[n(1105)+"kStatusC"+n(807)](({isConnected:d})=>{let f=n;this["_miniNav"+f(1231)+"line"]=d,d?this[f(1480)+f(1331)]():this._handleOffLine()})}[t(438)](n){let s=t,d={oMTlZ:function(f,h,m){return f(h,m)},yCVkL:e[s(1306)]};if(e[s(417)](s(628),s(628)))return new Promise(f=>{let h=s;d[h(468)](setTimeout,f,this[h(1301)+h(1502)+"e"](n))});this[s(845)](d[s(327)],_0x1affb5),this[s(476)]&&this[s(476)](_0x6a1c59)}[t(1291)+t(951)](n=1e3,s="",d=!1){let f=t;this[f(528)]&&this["_destroy"+f(941)+"t"](n,s,d)}[t(937)+"ut"](){let n=t,s=this["_endpoin"+n(976)]?.[n(638)+n(1643)+"nt"]();this[n(932)](n(1093)+s+n(1678)),this["_disconn"+n(951)](1001,e[n(462)],!0)}[t(1274)](n){let s=t,d=e[s(1628)](Bt,n);if(this[s(528)]&&e[s(1278)](this[s(528)][s(398)+"te"],this.OPEN))if(e[s(1674)]===e[s(1674)])this[s(528)]&&this._ws[s(1118)](d),this[s(932)](e.ixjHC,n);else{let f={MyxWc:function(h,m){return h!=m},IFvUZ:twxDtO[s(977)],oqCMf:twxDtO[s(516)],NTEJB:twxDtO[s(680)]};_0xcfa9f1.r=h=>{let m=s;f[m(505)](f[m(1064)],typeof _0x2cd921)&&_0x311698[m(589)+m(1477)]&&_0x280568[m(640)+m(1418)](h,_0x11d6c0[m(589)+m(1477)],{value:f[m(595)]}),_0x1fc2e7[m(640)+"operty"](h,f.NTEJB,{value:!0})}}}[t(1152)+t(1607)+"rs"](){let n=t,s=e[n(717)][n(485)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(528)][n(1785)+n(518)+n(663)]("error",this._onError);continue;case"1":this[n(528)][n(1785)+n(518)+n(663)](e[n(1666)],this._onMessage);continue;case"2":this[n(528)]["removeEv"+n(518)+n(663)](n(1811),this[n(277)]);continue;case"3":this._ws[n(1785)+n(518)+n(663)](n(477),this._onOpen);continue;case"4":if(!this[n(528)])return;continue}break}}[t(358)+t(1841)](){let n=t,s=e[n(1035)][n(485)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(!this[n(528)])return;continue;case"1":this[n(528)][n(469)+n(286)](e.zVqPJ,this[n(277)]);continue;case"2":this[n(528)][n(469)+n(286)](e[n(1306)],this._onOpen);continue;case"3":this[n(528)][n(469)+n(286)](e[n(1806)],this[n(897)]);continue;case"4":this._ws["addEvent"+n(286)](e[n(1666)],this._onMessage);continue}break}}[t(1824)+t(479)](n=1e3,s=""){let d=t;try{this[d(528)]&&this[d(528)][d(1811)](n,s)}catch{}}[t(1381)+t(941)+"t"](n=1e3,s="",d=!1){let f=t;if(this[f(949)+f(913)](),this[f(1510)+"mer"](),this[f(1152)+f(1607)+"rs"](),this[f(1824)+f(479)](1e3,s),this[f(424)+f(395)]=!1,d&&this[f(1602)+"orOnline"]()&&!this[f(1206)+"osed"]){if(this[f(1638)+f(976)]?.[f(385)+f(266)+"es"]()){let m=this[f(1638)+"tManager"]?.["getCurre"+f(1643)+"nt"]();this[f(1618)+f(539)+"ent"](xt("close",{code:1006,reason:f(1093)+m+(" timeout"+f(1405)+"tries re"+f(1562)),wasClean:!0}))}else{let m=this[f(1736)][f(716)+f(1537)+f(1714)](n,s);this[f(1618)+"hCloseEv"+f(618)](e[f(591)](xt,f(1811),{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[f(424)]()}return}this._navigatorOnline()||this[f(1206)+f(988)]?this["_dispatchCloseEv"+f(618)](e.lAzvy(xt,e[f(1249)],{code:n,reason:f(1662)})):this["_dispatc"+f(539)+f(618)](e[f(753)](xt,f(1811),{code:1006,reason:e.pHprs})),this._ws=null,this._endpointManager?.[f(1730)+f(621)+f(334)](),this["_pingLos"+f(579)]?.[f(683)+f(659)]()}["_dispatc"+t(973)+"nt"](n){let s=t;this.emit("open",n),this[s(476)]&&this[s(476)](n)}[t(1618)+t(1425)+t(1382)](n){let s=t;this[s(845)](s(560),n),this.onmessage&&this[s(1837)+"e"](n)}[t(1618)+t(816)+t(825)](n){let s=t;this[s(845)](e[s(1438)],n),this["onReceiv"+s(1739)]&&this[s(1783)+s(1739)](n)}["_dispatc"+t(701)+t(618)](n){let s=t;this[s(845)](e.fbioT,n),this[s(1088)]&&this.onerror(n)}[t(1618)+t(539)+t(618)](n){let s=t;this[s(845)](e[s(1249)],n),this[s(1254)]&&this[s(1254)](n)}get[t(1370)+"pe"](){let n=t;return this[n(528)]?this[n(528)][n(1370)+"pe"]:this[n(1633)+"ype"]}set binaryType(n){let s=t,d={mCAFu:function(f,h){return f===h},HvohI:function(f,h){return f===h},BDYoq:function(f,h){return f+h},qNQBo:function(f,h){return e[U(1329)](f,h)}};if(e.Mdueg===e[s(1147)])this[s(1633)+s(874)]=n,this[s(528)]&&(this._ws[s(1370)+"pe"]=n);else return ZUDeVf[s(1472)](-1,this.low)&&ZUDeVf[s(1472)](-1,this.high)?_0x5365a2[s(1758)](0,0,this[s(1722)]):ZUDeVf[s(611)](-1,this.low)?_0x24d5ba[s(1758)](0,ZUDeVf[s(1802)](this[s(388)],1),this[s(1722)]):_0x5538fd.fromBits(ZUDeVf[s(679)](this.low,1),this[s(388)],this.unsigned)}get[t(312)+"nt"](){let n=t;return this[n(1638)+n(976)]?.[n(638)+n(1643)+n(1014)+"ount"]()||0}get[t(554)+"Amount"](){let n=t,s={Vrhzj:function(d,f,h,m,b){return e[U(813)](d,f,h,m,b)},mlFQL:function(d,f){return e[U(662)](d,f)}};if(e.ibzmn(e[n(993)],e.zUrIO))_0x57bb87[n(469)+n(286)](twxDtO[n(929)],d=>{let f=n;vlJAjc[f(1660)](_0x845cc5,vlJAjc.mlFQL(_0x1a89a8,_0x4fd43a[f(1367)]),d[f(390)+"on"],d.newVersion,vlJAjc[f(444)](_0x30540a,_0x20fa61[f(381)+f(1234)]))});else{let d=this[n(430)+n(1512)][n(803)]((f,h)=>(f+=h&&h.byteLength||0,f),0);return e[n(1352)](d,this[n(528)]?this[n(528)][n(554)+"Amount"]:0)}}get[t(649)+"ns"](){let n=t;return this[n(528)]?this[n(528)][n(649)+"ns"]:""}get[t(956)](){let n=t;return this[n(528)]?this[n(528)][n(956)]:""}get readyState(){let n=t;return e[n(473)]!==n(957)?this[n(528)]?this._ws[n(1370)+"pe"]:this[n(1633)+n(874)]:this[n(528)]?this[n(528)][n(398)+"te"]:this._options["automati"+n(1395)]?this[n(412)+"NG"]:this.CLOSED}get[t(497)](){let n=t;return this._ws?this[n(528)][n(497)]:this[n(1094)]}[t(1811)](n=1e3,s){let d=t;if(this[d(1206)+d(988)]=!0,this[d(1510)+d(1767)](),this[d(949)+d(913)](),this["_dropGlo"+d(1086)+d(286)](),this[d(766)+d(664)]?.[d(1808)](),!this[d(528)])return void this._debug(e[d(675)]);if(e.oUoWP(this[d(528)][d(398)+"te"],this[d(954)])||e.pZFZe(this[d(528)][d(398)+"te"],this[d(1386)]))return void this._debug(e[d(562)]);this[d(1381)+d(941)+"t"](n,s)}async[t(1118)](n,s){let d=t,f={KWwKx:function(h,m){return h|m}};if(e[d(1529)](e[d(1421)],e[d(1421)])){if(n==null)throw new Error(e.TCviy);e[d(622)](e[d(509)],typeof n)&&(n=JSON[d(1789)+"y"](n)),d(1572)!=typeof n&&!(n instanceof ArrayBuffer)&&!(n[d(1612)]&&e[d(1060)](n.buffer,ArrayBuffer))&&(n=JSON[d(1789)+"y"](n));let h=await e[d(529)](sl,n),m=e[d(335)](mp,n),{method:b=0,service:g=this[d(1736)][d(315)],logID:v=this[d(1736)][d(1151)+"erator"](),headers:D=this[d(1736)][d(296)],payloadEncoding:N=this[d(1736)][d(1239)+d(1406)],payloadType:H=this[d(1736)][d(1001)+d(874)],logIDNew:J=this[d(1736)][d(1225)+d(1504)][d(311)+d(952)+"teLogIDNew"]?e.pplPc(i,this[d(1736)][d(1225)+"Config"][d(835)]):""}=s||{};if(!g)throw new Error(e[d(818)]);let X={SeqID:xe[d(297)+"er"](this._seqId++),LogID:xe.fromNumber(v),service:g,method:b,headers:D,payloadEncoding:e[d(1474)](N,Object)?N[d(527)]?N[d(527)]:"":N,payloadType:e[d(1813)](H,Object)?H[d(519)]?H[d(519)]:m:H||m,payload:h,LogIDNew:J},Q=e.AUDWB(Bt,X);return this._ws&&this[d(528)].readyState===this[d(1517)]?(this._ws&&this[d(528)].send(Q),this[d(932)](e[d(738)],X)):e[d(731)](this[d(430)+d(1512)][d(1524)],this[d(1736)]["maxMessa"+d(780)+d(1693)])?(this[d(430)+"Queue"].push(Q),this._debug(d(1731),X)):(this[d(430)+"Queue"].shift(),this[d(430)+d(1512)][d(354)](Q)),{seqID:this._seqId,logID:v,logIDNew:J}}else this.isLong=!0,this[d(1453)]=YENXPE[d(377)](0,_0x8a5397),this.high=0|_0x52b0e6,this[d(1722)]=!!_0x3dbf27}async reconnect(n){let s=t,{url:d}=e[s(953)](n,{}),f=Array.isArray(d)?d:e[s(1788)](e[s(1557)],typeof d)?[d]:[];if(n&&Object[s(1241)](this[s(1736)],n),f&&f[s(1524)]?this[s(1638)+"tManager"]=new tl(f,this._options[s(1542)+"es"]):this[s(1638)+s(976)]?.["resetEnd"+s(621)+s(334)](),this[s(270)+s(579)]?.[s(683)+s(659)](this[s(1736)][s(410)+s(833)]),this._readyClosed=!1,this[s(528)]&&e[s(386)](this[s(528)].readyState,this[s(954)]))this[s(1291)+s(951)](1e3,e.dzlbR,!0);else if(s(1604)!==e[s(1828)])this[s(848)]=!0,this[s(424)]();else return _0x35a887[_0x515f4f[e[s(314)]]=5001]=e[s(314)],_0x2e6a90[_0x33d267[s(412)+"NG_ERROR"]=5002]="CONNECTI"+s(1018),_0x1d16ff[_0x529904[e[s(1121)]]=5003]=e.ZGvbq,_0x579430[_0x5c77b2[e.ZASHC]=5004]=s(1392)+s(642),_0x483d83[_0x2c4967[s(1053)+"OR"]=5005]=e.loKir,_0x62be7}async connect(){let n=t;if(!this[n(424)+"Lock"]){let s=e[n(452)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this._isInit=!0;continue;case"1":this[n(1206)+n(988)]=!1;continue;case"2":this[n(424)]();continue;case"3":this[n(270)+n(579)]?.[n(683)+n(659)]();continue;case"4":this[n(1638)+n(976)]?.[n(1730)+n(621)+n(334)]();continue}break}}}[t(469)+"Listener"](n,s){let d=t,f={gaXyA:function(h,m,b){return e.VSRYp(h,m,b)}};if(e.yuMPo(e[d(563)],e[d(1556)]))this.on(n,s);else{let h={xwUzQ:e.fbioT};if(e[d(1474)](_0xd7ca29,_0x3ce837)){let m=_0x28a336[d(1612)][d(264)](_0xa191f3[d(569)+"et"],e[d(1694)](_0x25e0a1.byteLength,_0x479823[d(569)+"et"]));this[d(548)]&&this._socket.send({data:m,fail:b=>{let g=d;this[g(845)](h[g(723)],_0x375616(h[g(723)],{message:this[g(1467)+g(433)+g(1654)](b)}))}})}else this[d(548)]&&this._socket[d(1118)]({data:_0x311c47,fail:m=>{let b=d;this[b(845)](b(1786),WgAYmY[b(565)](_0x54cbd1,"error",{message:this["_formatErrorMess"+b(1654)](m)}))}})}}[t(1675)+t(1382)](n){let s=t,{type:d}=n;this[s(845)](d,n)}[t(1785)+t(518)+"ner"](n,s){let d=t,f={pkgfO:function(h,m){return e[U(1069)](h,m)},nlomc:function(h,m,b){return h(m,b)}};e[d(1642)](e[d(1227)],e.RWgJG)?(yKiZbH.pkgfO(_0x459c1d,this[d(863)+d(1655)+"Id"]),this[d(863)+d(1655)+"Id"]=yKiZbH[d(829)](_0x96e2a,()=>{let h=d;this[h(260)+h(817)]()},this[d(863)+"l"])):this[d(284)](n,s)}[t(328)](){let n=t,s={pBQcI:function(d,f){return d!==f},ujsUE:e[n(1812)],mOMvq:e[n(759)],jfPbt:function(d,f){return e[n(1169)](d,f)},YJRnN:n(379),HleFS:n(1391)+n(748)+"s",uaLAm:function(d,f,h){return e[n(704)](d,f,h)},NhgDe:e[n(1809)],Hyxtd:n(887),OoGQx:e[n(1806)],DxnzX:function(d,f){return e.iGmxr(d,f)},shQpS:n(750),nHCqy:function(d,f,h){return e.AfYcr(d,f,h)},VRasU:e[n(676)]};return new Promise((d,f)=>{let h=n,m={uOhut:function(b,g,v){return s[U(1476)](b,g,v)},mwSBN:function(b,g,v){return b(g,v)},ddcQi:function(b,g){return b(g)},lnNGq:function(b,g){return b!==g},FLNpW:s[h(1664)],EZNUI:function(b,g){return b(g)},yntTf:s[h(1100)],CBEFy:s.HleFS,CapTr:h(1391)+h(1692)+"t",HGdjs:s.OoGQx};if(s[h(1140)](h(706),s[h(885)])){this[h(949)+h(913)](),this[h(898)+h(1753)+"Id"]=s[h(842)](setTimeout,this[h(1515)][h(636)](this),this[h(1736)][h(686)+h(378)]);let b=()=>{let v=h;s[v(351)](s[v(1192)],s[v(1185)])?(s[v(583)](d,s[v(1260)]),this[v(284)](s[v(989)],b),this[v(284)](v(1391)+"e_timeout",g)):(EeMIWF[v(661)](_0x1e62ee,_0x1a23b9,96),EeMIWF[v(339)](_0x5739cd,_0x581499,EeMIWF[v(1104)](_0x294a91,_0xaa3c00)))},g=()=>{let v=h,D={UoRHY:function(N,H,J){return N(H,J)}};if(m[v(1322)](m[v(678)],m[v(678)])){this[v(949)+v(913)](),this[v(898)+v(1753)+"Id"]=SPAiTw[v(1627)](_0x435c65,this[v(1515)][v(636)](this),this[v(1736)][v(686)+v(378)]);return}else m[v(317)](f,m[v(1325)]),this.off(m[v(741)],b),this[v(284)](m[v(619)],g)};this.on(s.HleFS,b),this.on(s[h(677)],g),this[h(1515)]()}else{let b=EeMIWF[h(661)](_0x1fe38c,EeMIWF[h(279)],{message:_0x3bc43d[h(560)],code:_0x266b21[h(1392)+h(642)],error:_0x563611});this[h(1618)+h(701)+h(618)](b)}})}}})(),Te[M(434)+M(373)]=De[M(434)+"oseEvent"],Te[M(1402)+"rorEvent"]=De["CustomEr"+M(916)],Te.ErrorCode=De[M(698)+"e"],Te[M(1382)]=De[M(1382)],Te[M(1723)]=De[M(1723)],Te[M(321)+M(1356)+M(1435)]=De[M(321)+M(1356)+M(1435)],Te[M(1356)+M(1435)]=De[M(1356)+"vent"],Te[M(718)+"t"]=De[M(718)+"t"],Te["Reconnec"+M(824)]=De[M(987)+"tEvent"],Te[M(496)+M(373)]=De["createCl"+M(373)],Te[M(1466)+M(916)]=De[M(1466)+M(916)],Te["createMe"+M(1669)+"nt"]=De[M(472)+"ssageEvent"],Te[M(406)+M(797)]=De[M(406)+M(797)],Te["createRe"+M(1511)+M(1435)]=De[M(461)+M(1511)+"vent"],Te[M(1415)+M(573)]=De[M(1415)+M(573)],Te[M(652)+M(981)]=De[M(652)+M(981)];for(zo in De)[M(434)+M(373),M(1402)+M(916),"ErrorCode","Event",M(1723),M(321)+M(1356)+M(1435),M(1356)+M(1435),"OpenEvent",M(987)+M(824),"createCl"+M(373),M(1466)+M(916),M(472)+M(1669)+"nt","createOp"+M(797),M(461)+M(1511)+M(1435),M(1415)+M(573),"encodeFr"+M(981)][M(822)](zo)===-1&&(Te[zo]=De[zo]);var zo;function Wo(){let t=["A21gtfa","Bg93","zNvUy3rPB24","m3W2Fdr8mte","D3nhBhK","DffoBhC","CMvXDwLYzwq","qM9kB1m","Aw47y2HHCNm","AMvRsNq","C2v0","x2LZv29YA2u","zwvKzwq","BgvY","y3jLyxrLrxi","x2zVCM1HDeu","ruL6wgS","tgrkAgK","CMPqCeO","tgD3v0i","BunbrNu","A29tvNy","Cwjzwe4","mtK4vNHRrer3","Dwfmqw0","vgfN","y3j5Ae4","u1LLuvK","x2HHBMrSzu8","twz3r04","CgjICdi","qxLxywm","vejxrfi","swzACgS","qKLJu1O","A0LqDNm","BMLyD1y","zgrjrcWGzgu","qxrRCeC","CMvHzfvjBNq","v0TozwS","zgLZywjSzue","De54t2O","CKPyBwC","BM9Uzv9UB24","zKv6zei","C3HfAwe","u0vcq3O","BgjXrwm","tM5ACK8","CNzHBfzHBhu","AurIyNC","q29UzMLN","tLzqsge","ALH6qxG","zNjVBunOyxi","BKrss1O","Bhm6ia","x2nSzwfYvgK","y29UBMvJDeu","uxvLDwu","y0jctK0","BgHWwfO","x3bPBMC","ywHpEeu","t1bftG","zxHWB3j0CW","BMrMqMW","B2nRzxq","zgjTtwq","D3jPDgu","s05VquS","BgvUz3rO","wuLosKG","yLzktuS","ywzL","B2zMC2v0","B05Ryxa","zgrbr0W","y2XIBMS","B3jRig9MzMW","y29UDgv4Da","Dg1lBxK","x2LUAxq","uM14vNK","DeLUDgvYy2u","rhf5ueC","teTOEwS","sLzJEhu","wKDIvxK","Bwf4uMv0CMK","Chv0","ELnHsuq","uhvfCve","CMfUzg9T","DvHrBeS","Bvz4tfm","wffXwgm","x2HHBMrSzvi","zMLArKK","ugniAMO","ufLTz0C","vfHsAK4","uNLpyvC","qLz6ALe","Dxb1C2y","u2nrzhy","qxHpwMy","ihrYEsbYzwm","BwvZC2fNztO","ywnOzwq","CM92AwrLihC","y1Hpz1i","DNPjvuy","y2HnyxHdB3u","yKngshy","tw9KDwXL","ihbYB3rVy28","swvzsNe","A053wvO","C3rYAw5N","t2jQzwn0","v2zYAha","AKn0vNa","BgLZDgvUtMu","vLvzzxG","y2vZC0HHBMq","ysbTDxn0igi","t1juDMS","EML3tg8","BIWGAg9ZDg4","Aw5KzxGGB3u","DNbHvhi","D2DfsMS","uMvHzcbWyxm","ChjVDg90Exa","qLPxtMq","Dxrjza","ywrKt25L","v2vPEgLUsLm","Dg9cExrLC0i","qxDdsMu","nxW4FdD8mNW","r2DvAvK","vwLuB1a","seXvtKO","wNjTyw8","BwvZC2fNzv8","C2nYAxb0","vxvdy1i","x25HDMLNyxq","D3b4uLK","vM5Aq2C","B0nWs1G","qwTwANa","C0XPC3rLBMu","z0vXAKK","zLDxC2q","t3zvq2K","s2fkCfu","yNvMzMvY","sev0vgK","AgfZ","Bw5HvfK","u3HRyKW","Bw5VCMq","x2rPC3bHDgm","r0LTC3K","mty3ntqZnwXsuwnPqq","zNjVBuHHC2G","re1xtxq","Dw5KzwzPBMu","Aw5Lza","vvPWwLm","uLLWs2S","vw9ssfK","CKXitMW","BgPTCgG","zgnpz2K","uu1ftg8","zw5KCg9PBNq","x2jPBMfYEvq","sKjrA2u","CMvUDevUzha","yxrHlcbKyxq","mte4ndK0n0LkBMD6za","x2vUzhbVAw4","Dg9oDw1Izxi","yMfhyLG","DMXvqMO","DuLTtvy","BNrfBMrWB2K","DNnoEhG","y3vYC29Y","y2Tnr3i","Ec1TC2CTCw8","mdaWma","y2HHCKnVzgu","CeLMr3u","zxj2AwnL","x2LUAxrhBg8","D0PpuM4","ywDL","BfrPBwvVDxq","Eg1lEuO","yM5gteK","tg9NsurozxC","BNrlsfK","vNjOEMO","shfbCNq","yNLL","CKzPDNK","tMHNrgu","DwLwswG","D1D5wwu","rKLWqNG","AxnFywnR","C3nHz2vfDMu","vw1bEvm","y1Llq1q","sLrey00","EfjerLu","r0HNALy","zgLZCgf0y2G","C2vUzf9Hy2S","wgHpthK","ihrPBwvVDxq","B0T5AMe","Du9utwy","vLvRvLG","uNzoyLu","B25tDgfYDfi","C0vlvwW","ywnpq2i","EMzttvO","s051Eve","Bg9N","AgvHzgvY","Awj6Bw4","z3jKqKu","zv90Aw1LB3u","zw5NDgG","r21vrMC","AvDHAgi","x2TLEvbHDgG","CNb5thi","rKzXEwi","mZm0mJK5yu1jqNfH","tLDMvxK","rwHdrxm","z0j6q0G","BuTVsve","EuzfENq","tK9NqLG","uMXvtgy","lcbOB3n0BMe","Afvothm","zw50zwqGDhK","CMvTB3zLq2G","BMCGzMfPBgu","EwDXALK","CMrNzuq","ChrVCG","zg9Uzq","Cg9PBNrbBMq","ugDbBhO","mdaWmdaWmda","zfjSwK0","CeLtBKy","Ec11C2uT","Dw5ZAwDUzwq","rLDt","q2zty3a","Aw9UvgLTzw8","yLfJAM0","rMf1A2m","rNjkzvu","CvvyDwG","CMvZzxrfBMq","zw5XDwv1zq","EeftvhG","ugz3Bei","z2TJzfm","mxW4Fdz8oxW","x29WDgLVBNm","ignVzgu6ia","z0nkz1i","zufJAW","CMnLDhe","sMP4tM8","CYbWyxjHBxm","su16AgW","BeHHBMrSzxi","CgfNzwHPzgu","zgvSzxrLrge","y29UC3rYDwm","qM5zEg4","DeLK","rNzwrwK","qNvjuuW","senWtwy","z1rPBwvVDxq","tgLkwNi","AhPQD1G","B1rktey","yw1Lu3bHy2u","zNjVBujPDhm","qwnet1m","ywXSzwqGBxu","zfHjrxq","rgf6zey","ywWGy3vYC28","y29UDgLUDwu","y2f0y2G","z2v0qwXS","BwvY","mhWYFdn8mxW","vNLvA2S","tuPxuMe","y3vYC29Yx2y","sxzVz0u","ALDIyLq","C3rHCNq","AM1xCLK","y29UBMvJDgK","wuTKsgG","rLP1C0S","EfvoDwK","u1v2vgC","EsbJBg9Zzwq","Ewf6sNm","B25szwnLAxy","yMrQCMW","CMvTB3zLrxy","zxjYB3i","z2v0qwXSs2u","vvHftfC","C3rYAw5NAwy","DhDVCMTdAge","B3vwweO","C1zmzKS","x194x21Zz18","vwPttgW","s2TlyLa","y2joBum","vuHyAMC","wLn1Cgm","B0ndyuq","AK5zqxm","B01YA3a","qKrzB3e","qKPwC3K","EeX3ze4","zxrxB3jRq2G","zMjPB1q","mtC5ndC3nNvkA3P5Cq","y2XVC2veqG","zxnIrxy","AxfZCxK","y2XVC2u","yLvwyuq","zhHys2S","u2Xtvu8","s3nkDKG","thbmENq","AxnmB25N","shfOq0S","wuXtsK8","runovKm","B2nRzxrgywK","AxnszwfKEq","t0jAq2q","x3DZsw5ZDge","zxjFAxnFywm","ENL6ALe","DxbOrvO","Derntei","u2rWCMi","DMLJzuLeig8","yxjov3u","qM5mDu4","C2v0q3vYC28","Aw1LCYbPBIa","whf6zgW","A2HoA3q","B25TzxnZywC","CMvZzxruCMK","C29Tzq","ufr3z28","C3rLBMvYCW","Ahndreu","yM9KEq","zMX1C2HfEha","z2vtEw5J","BNvTyMvY","x3bYzwzPEa","C2XPy2u","rNDQDfC","y2HnyxHuCMK","y29SBM8","AgvKtwf4uMu","tuTjrgm","x3bPBMDmB3m","qMnHwwO","CMvHzg9UBhK","BMrLEa","rLn1wxm","DcbVzIbYyw4","DwHcDvu","x29Uq2XVC2u","Ee9NzKK","seDKANm","Awjnu2q","D3jPDgvvAw4","BerrtvO","A2Xhz00","B2zM","vvHkvxC","tgLZDgvUzxi","CLbgC2m","B3bLBKrc","v1f5EM0","BxnNsuq","DujJweS","C3vIC3rYAw4","ywjVCNq","z010twW","s0z5D1G","AgvHzgvYCW","zNjVBu51Bwi","CNnVCKzPBgu","x3jLy29UBMu","Ce1Vse8","u2vXsuq","zwLfC1K","q0jYruS","y1DJuNm","Cezzru8","A2v5CW","y2fSBa","v2riCgO","x29UugfNzu4","AwXLtMfTzq","zw5HyMXLqxu","CMv0CNLdB3u","DgHLBG","tK53B2C","C2vYDMLJzq","Cg9W","rvPovuK","EgjwyKq","D3nZoI8V","D3rYAKO","rNjVBNrPzxi","uNLqs3e","yvz2Evi","yLPLA0i","DxjQs1e","mtb8m3W5Fdi","EunwA0W","CgLUz09Uy2u","o2nOyxjZzxq","ywDLsgLKzq","CgLUz1rPBwu","zxf1ywXZ","ywXSq3vYC28","zMLN","EKDPq20","sg5hBK0","zsbHihn0CMK","ENvtDwW","BxDtqK4","zgjez2W","zxLnDfy","BvPOExe","tvvZv2u","DLrYDxO","zMLSzw5HBwu","t2X3DeK","qwjVCNrfCNi","whHVDhy","suvtx0vsuK8","reiGzMfPBgu","Cejry0K","v1vlCeK","x2LZqNjVD3m","ChvZAa","BML0AwfSAxO","ufDuBuS","zerKuxG","x2fKzfDZtgK","wM9rseK","qvbzzLi","CNnVCL92ywW","tgHWEg8","y29Kzq","s1LQtem","z0v0DgC","vhHjuwC","A3v0BwC","BK9swfa","A2LgvNG","uNf3C3K","A1fsv2G","A3Lfqu0","B3nLrxzLBNq","ve55sgS","CM92AwrLihy","rgXuseW","s1D3s3G","CNzHBa","C3vJy2vZCW","CMT2CxG","DhjHBNnHy3q","v2XwANi","yuHxEvu","yvnzALi","y2HLy2Tszwe","rgjUug8","rKfNCxy","AgLNAa","B3vUDa","B2XKvMvYC2K","CMfTugfYyw0","yvPgCwO","x3fVC0rc","BwPhywe","tg9JAW","tun3EKC","sgHMsvO","CMvHzhLtDge","r0nWDhK","AwrI","B3bXv2u","vNjet3u","BLn4Be0","Dg9VigXHCMC","DhjPBq","y3jLyxrLt3a","tfz4qvy","yufjC2u","B3nHExu","CgLUz0XVC3m","runpzeO","q09otKvdveK","sLnptLa","u3rYyxrLz3K","u1f3BK0","wwPqyvC","teD3sge","rfDTEvi","CLneu2S","qwzIuMW","y0rmr0S","vw5PBxbSzw0","se5tvhq","x2nVBM5Ly3q","BwLUAvbYB2C","AejJs1u","BMv4DcGPigm","DNvmuMm","BMCGDxjSoIa","x21LC3nHz2u","rgvKAwnHDgu","yMrFzgLK","CNjVCK1LC3m","q3vZDg9Tq2W","z2jVyxm","rKfNueu","DxrlAgW","x3DHAxq","rgPttNm","weDSyKC","Bg9IywXty28","B25dBg9Zzq","rLjptLrjrvi","BwXguuW","zLHdr1G","vefzBuO","DxP4zKS","D2vI","B3PvquK","AwXK","igfYCMf5yNu","EgnuBKq","rwjeteq","A0THs1O","Dg9iyxnO","ELLAAui","sfbZq1i","B3jRzxjhBg8","C2v0y3vYC28","B2LUDfjLywm","y3jLyxrLuMu","wg1lDLy","zcWG","AML4vgS","yMHIsLK","AxnrB1nnzxm","zcbLCNjVCI4","B01uBfO","ywrKrxzLBNq","Cw9Z","Cw9Oreq","y3jLyxrLtwu","y3PUsKK","igzHAwWSig0","u2TPCcbWyxm","B25VCgvU","B3bLBG","zM9Yy2u","BMnLq2XVC2u","B2XqtuW","CMvHC29U","v1DSwwC","txDgsee","twzouMe","C3bSAxq","v3jTtgu","r1HTBwC","r1jyr3y","qM13u0q","we1qAxe","EwTQq2S","CfjlCfy","D2LSBfjLy28","u0XyuKm","z2v0","y3jLyxrLq2W","DxjS","Aw5N","CMvJzxzPzwq","yw51Ce1LC3m","x2n1CNnVCK4","u25ez0C","tKfusvzfx0u","qMzqyLm","txL4v2m","DgfLCKS","q29Kzq","zxjYtM8","ue51Dwm","uwfbtM8","m3W0Fdy","wLjyBuu","ufvwu3O","swnSwuS","wfnuzhO","CuHyDg0","y2XVC2uSihC","zw50tgLZDgu","DhLWzq","mZvjDxbvuwO","DgvZDa","D3btv1y","BgLTAxq","ywjKC0m","zhfsBwS","tufyx1jfvfi","zw5JB2rPBMC","x3DZ","uwDQCK4","wMLKA1C","v1jmufO","Bg9lAxi","yu14seG","AML1AeS","Ce5uEK4","AhfyA20","DufhA08","BMzrAKW","AenSB3nLrxy","Dhrptxy","DMfS","EM5Lr3C","Dw50","y3jLyxrLrwW","CKXvDwe","qwX0D3O","CejVywu","x3nVy2TLDa","zLLMyKC","yvLVD3a","D2fZq2XLyw4","v3HHvNy","qMPAtLy","yNvMzMvYzwq","EgXxz3O","Dg9cExrLCW","BuDbr2y","whP1tgK","qM1Pzey","BwvZC2fNzq","C1fmy3q","y012vxa","r3D1v2S","sKvUwfu","z2fyEue","y2TQv3y","ugDnrxm","ANvNzuC","yNL0zu9MzNm","ELDpANq","zeL0yLa","x2DLBMvYyxq","CMfTzq","zNDZxZeUmc4","t0H1vMu","y29Uy2f0","B25nzxnZywC","zxmGCMvHy2G","C0nVDw50zxi","EejRDey","DMrbzMm","vePrs3q","AMzqyNq","vfjzBKu","CKzzywq","ELfNuwK","BgLcqNC","Ahr0Ca","Dg9tDhjPBMC","y291BNq","BLrgAuW","C2vNrxO","yxGGCMv0CMK","vgXMwvK","B3fdtwy","vgDgtNO","swHHuw8","su5tvefova","lcbxzwjtB2m","ALzSDKS","C2DPza","C1f6s2e","qNfpA28","EwTNCfC","ww5uu1K","AwLNAfm","t01oDuK","DMvYC2LVBG","EKr6CwG","Dg9Y","shzVAeK","z1v3wMC","ue9Rs0G","z3H1EKu","mhW0Fdf8m3W","v1nby1i","vLnswxa","zw50","q2fWvhi","x3bYB3rVy28","Cg9PBNrdB24","Avvozxe","EfvZzuvUDG","DfbHwxu","wKLlqMS","u1f3rKS","DMfSDwvZ","rePkvvG","yMLUyxj5","vfjyvvm","t2TdDLu","vgXKyxq","AerXEeq","zMLSDgvY","BgLUzw5V","yMLUza","ruLSBLC","z2v0q3vYCMu","DLfkDem","zgvMAw5Luhi","q3fjAuu","rvjst1i","sK1Mq0e","CLHcyK0","svvZCva","t0j6Cwi","C3vIyxjYyxK","wuzduLm","zxH0zw5ZAw8","vxLsqKG","CwrZEhq","zw5JB2rLrNi","Dw9qCva","qujXvKu","x2LZtwLUAvC","C2fNzq","yLDpv1K","sNP6qw0","BNrLCG","ChzwuuW","Du9ODxq","yLLOsM0","BMvY","z2vY","uLLIz2K","Aw5L","zvvYBa","u1nrwKm","u2vyt3q","AgLQtw8","ve5srwu","x2XPC3rLBMu","vgnUq2S","r2zfDxq","Aw5MC2W","wgfsAKK","vLjHC1u","rKXoCfC","Cu5rqM8","veXABLu","wfvhr0O","B0rtEeS","CMvZzxrdB3u","EuXXqK4","Cu9nDe4","CgLUz0LUDgu","swTpqNa","nfjRzvPIuW","q05gD3i","z1DlD3C","Dg9mB3DLCKm","qKP0B3e","Dff2Bem","rfDeD0G","mJu4nti4rLr6Cg1w","yxbWBgLJyxq","x2nYzwf0zvm","rxjYB3jdB2q","suXxDva","swvfufy","AevYCM9Yrxy","B3v0sw50zxi","C29tqLy","CMToCu0","wwziDNy","A0f2uLO","svPUwhu","y29UBMvJDfm","A1nRt2C","y2uGBM90igK","AePcCvK","Cg93","icSG","CNnVCL9Uyw0","zwLxv2m","CMvJB25Uzwm","vg1HswO","t3bLBKv2zw4","twHsr3q","y2HLy2TdDxi","q1nLwhG","AKLxvKS","EhDvELe","y2XLyxi","EgjAs1K","zhDHALm","BMrptw8","Dwv0sMy","C1fJwNO","uMDkzw4","DgDjCKq","y1LvBM0","rwjnt3q","ywr2yw5Jzq","sKflCe8","x21PBMLoyxy","D2ndtMy","EvjovLy","uhjPBwfYEuS","A2v5","q0jfrNK","z2v0t3DUuhi","ufzJDNa","n3WWFdH8nxW","DxbKyxrLq3u","y3vYC29YlNm","whz4vum","zv9ZDwnJzxm","y1bsyKG","vhbPEKi","r09MD3C","wvnquum","yMrPv24","wwvOue0","B2nRzxrtDwm","Cgf5Bg9Hza","svDtt2q","sNbRzLe","Cg50DKy","EhjKCxq","z3jVC3K","BxnN","qMPjuKG","suvrCvK","rLLbwNu","x1fVu01HBMe","zfDVCMTLCKC","vxzWCLe","rKLmrv9ot1q","B2Lvzhi","su50v1O","tvjAvMO","qMPzweu","nxWYFdb8nhW","ALzMrfe","uMfiwMm","BNrbBMrvCgq","AgfZt3DUuhi","mxW1","z2vrDwv1zuW","CMvHzhDYAxq","zuHwDfq","u0jbqw8","A1HvqNm","ugzuDMW","igXHCMDLCIa","t25ssNu","BMXUrNq","ywXKDu4","EM1ozfe","zNjXs2q","yufMrNK","vNPnDwu","s2LdDNy","BM93","BMrWB2LUDca","zw5fDMvUDa","yxKSihrYEsa","AwH4BuC","ywnRDxbfBMq","C1zozhm","BMv3vMvYC2K","CMvKDwnL","AfvKvKe","sg1Xyxa","veT4De4","AgfUz2u","swz2B3y","rKvJq2S","DhjPzxm","x0rctMfTzq","yvrJzKu","A3fNrvK","ywrKq291BNq","BvjdB0W","AefJA01LC3m","AxjLza","EuDyAMe","s3jvtuy","qwnYDwG","ywnRpwzYB24","Aw5KzxHpzG","DvPfEg4","Dev2zw50","ywDLrxzLBNq","ownMEMDgra","CxDmteq","CfjeAMK","BMXVBwm","vwPrCvy","quvYBhi","rg1ZBuK","q291BNq","DMnHv2S","DxnLCKLW","yKPzALa","ANLIBfi","sMzZz0e","B25pCgvU","A3HtAfO","AePQzvC","BKHdCxK","qNH5wfO","qNzXqvC","zw1PDa","uxzYwhi","BezSDxnO","x2LZsw5PDa","l3DZl3yY","rgHju1m","ywnRx2LK","D3bhBw8","DuXeDMG","ENfOsfG","qMHRueG","z29PBMCGyxC","ywnR","twHvC3i","twn4BKO","B3jL","BwXlBKK","AuvXvKO","x2LUDgvYDMe","AujOtuO","uMLyyuu","s29XzMK","wvDNz3q","B25tDg9Wsw0","CgfYC2u","tun2DxK","CLLJANe","vePRy3i","zMXVB3i","ExbL","CgXLyxnLiha","wgTdENe","wxnWyxq","C0jf","qK1ZvMS","x29Ut3bLBG","DxbNCMfKzw4","vLzxAwC","tMj0qvy","ihzHBgLKihm","C2HrCfm","ANzwCLG","DgLTzw91Da","rMPbufm","tLfisei","ChfACuG","D1vAtwi","EvrpsNq","CLzHBhvLCW","s0npAhG","B0Tyqxq","x2LZtwLUAvq","x29UrxjYB3i","x3bPBMDqB24","Ef9MCM9UDgK","yNDkCxC","AxnAzxjV","y3ruAw1LB3u","zwrtv2S","B2zMBgLUzq","rffnshq","zMzLCG","BfHoteS","BwLUzW","Ewr3qw4","CMfNzvn5BMm","CMLLC0nVDw4","B25Uzwn0Aw4","BMDuAw1LCG","De5pr3a","DxnKBxa","CM9YrxzLBNq","A1n0yxr1C0m","y3vYCMvUDeu","zMzmAw5L","nhWZFdj8mxW","yxv0B21HDgK","sNDmDKW","vxHit2G","y3vYCMvUDeK","BMrWB2LUDfq","Bwf4tg9ZC0m","Dvn5Buu","EwzcCvu","wvHStKy","CMrcCKG","u1joB3q","x2rLyNvN","twLZC2LUzYa","EhjgvKi","suHyEfu","Ew9lrNO","x29UvgLTzw8","BKPwvvC","AM9PBG","CgnSyMq","v2vIu29JA2u","ywnOzwqSihC","B2jYzuG","DxrzrhG","zwnVBM5Ly3q","uMTjwgy","AKHvDuq","quvVEee","x2nSzwfYugK","z2v0u3rVCMe","zwn0","Dg9hzw5LCMe","qLDdwLa","q0Xpu0ve","zxjFywnRx20","ChjVDg9JB2W","ug9Mq1C","igzPzwXKoIa","zwPuyuG","uNnKzuO","zeTPuKK","BMfTzq","DMvY","yw9nugO","Bwv0Ag9K","wffxs2O","tMLtD2e","yw5ZzM9YBvq","wfnmBLm","D2P2rKG","shbwD1m","B3zUtwi","Ae9Wzw5fDMu","CgLpBxa","swXvv0e","De1HBMfNzxi","D05lCfG","u1D1svy","Dhv0s1u","Dgv4DfbHEwW","yw1L","ywvMwwG","t1jmBe4","rK9ABfq","yLLRqvG","vKT0tKi","uMvJB25Uzwm","B3nLza","sgXLrLm","yMfJA3vWigu","sM9wDw4","BwfW","tgr0Ee0","mZeYotm4vxn1sunN","s3jVBhm","sLnJwuu","q09oveLovuu","yNDRvuW","u0vqALi","DLHWrMu","Cgf5Bg9Hzfq","zxjFBxnNAwq","uxrWCM8","zwfMz20","tMHbtK8","EgrRwgq","ywDLu2HVDW","CNv6whm","uKr2uxi","DgHHBIbSB2m","CgfNzxnOB3C","Cwz4C3O","zxH0ugf5Bg8","BNruCMLLC0m","yw5Nzq","yMvUsxa","rwLVrK8","tKDFrvjst1i","nhWZFdf8mhW","y29TCgXLDgu","wNDptgq","DeT3t2m","uNfMq0O","ruHwtwC","weXiBxu","uLnPtuy","ueXMsMi","B2Hjq0m","zw1LBNq","Ae9SyM4","BwfUDwfSihi","EvjLy29UBMu","vgLTzw91Da","D0T4rgW","wfzlrum","uwnjz0G","Aw5JBhvKzxm","Dw5RBM93BIa","zgHQzxy","EhLrtNG","zwrPyxrLBhK","B3jpBMXPBMu","tMjQveW","ENvVtuO","DMfSDwu","sgDnENu","zgvS","zNjVBNrPzxi","BhziCM4","C09PCg8","twHyqwO","DhjPzxmGCMu","t1bftL9fuLi","y1nOyMm","rgTOAvq","swPVDNC","EK9sqM8","sKzNvxi","x2rItMfTzq","u2jzuLa","ywHSqwm","EuD3zu0","EKXbqNy","suz2vvO","yM9L","ywDgq0C","x0vysvnu","ruLvDwC","ChbSugm","qNjPzgDL","vNnTvgK","mJi5nJaZmfjKrfbtzG","rKD1D1K","q0zeEg0","C3rVCMu","id4G","BwLZzq","Awzgz1m","D2j4BKq","weTrAuS","x2n1CNnVCKy","ywD5Beu","wwnQC3G","vu94BLO","qMn4yKW","yMfSrxzLBNq","Ahr0Chm6","B25LCNjVCG","uMzVv1a","C0Xf","DhLZD0S","t1DPC3a","y29UBMvJDca","x3vYBa","DvDwqK0","ihrVihjLDhi","tMX3Cue","v2LUzg93","A3reveC","shL4Dgq","r0nLDhi","Efrurw52","BfngCxC","zgrJuwK","B25ozxr3B3i","CIb0DhDjra","s25KrMi","DcbSAw1PDa","r055rfq","AND3s28","y2XLyxjtDg8","suXhrw4","zvnvExu","x2rYB3bhBg8","u0HduMO","Dhr3Awq","pxv0zI04","C2vUza","rMfnBfy","u2HHCMvKv28","wKD2yNe","yNL0zxm","qxjuEgS","ChPqtNe","wKftsem","DKLNvgO","yw5Hz2vY","BwvKAwf0zwW","D2TPyLO","zKLHDKy","yMTwDei","s1LLAha","shfotNi","yNL0zuXLBMC","DhbizwfKzxi","DM1Pt1O","D3m6lY8","ihzHBgLKigq","ihn1y2nLC3m","rhHUELG","x2LUAxrqCM8","tfPUzeS","A3HYCKW","ELnjANu","zNjHBwvuExa","x3bHDgHlzxK","twr1zwC","yxv0BW","zxjFDhrS","AgzVue4","Bg9Nsurhzw4","x3jLBw92zvC","vxrhzvC","vw5Oyw5KBgu","ze5cq1a","C0Doq1C","CM92AwrLigi","zhvvs0O","uKTHrw0","shLjAM8","z1jIsM4","B25SAw5L","AuHmANK","zw5HyMXLvhi","vMn2swW","C3jADgG","nKnXvenbuG","D3rqBue","swzWEuS","svniy1G","BMDusuC","ANnyv0i","B2jQzwn0u3q","ign1CNnVCIa","CMvWBgfJzui","qxz2zxe","zMzMzG","BNDiy0G","yxnJCMLWDa","A3zZsw0","CNHUruC","BMDLza","DgfYz2v0","Ce94D1i","Bu9nDNe","AMr3sLe","BgLUzq","Ec1TC2CTy3u","rMPrAM4","zxfiCu4","svb0uMS","DwPZvuu","BhrPCgXLihq","vfDOsM0","y3r4","vfPuA0u","yxjYyxLIDwy","yvbvsfO","z1zsrNK","ExDStfG","ENv3wNe","DLrMzNm","tMfTzq","C3rVCcbPBw0","r21ABwy","x3jLywr5q2W","vNrnyNa","yM5wC3e","B21Mr08","v3PrENK","vKzlyuq","y3vYDMfSDwu","AhbzEfm","y21Mshy","AeXvs1i","D2rLD3K","z3HcyNi","y3rNCwO","y3vZDg9Tshq","DNnRAKy","DgLUzYbZzxi","DKn5BMC","BM5Ly3q","B3jLtMfTzxm","Bg9NsurozxC","A3HjyK8","uLDNsKC","DMrirgq","v1vSAKm","CKf1quq","AwDHDg9Yt24","uwn3EKm","zKTusxO","Aw9U","BKPhvwq","sNfktNO","Avzrsgu","BhrMtum","Cgf5Bg9Hzeu","rNb5tK4","yxnZAwDU","yKDSAK8","CgvlzMG","ywnRx2nVzgu","qMX6Cvq","zuXlAuK","C2v0u3rVCMe","tg9Nsuq","ELzXueO","CgvYC2LZDgu","Bwu6ia","C2HPzNq","rNzVseK","B25JBg9Zzq","ve9nuhG","Dgj1reK","CuXpsMi","x2n1CNnVCK0","yxbWBhK","wuPsBK4","vK90zhC","sxvUBhi","u2vYDMLJzvC","sxDJBeS","yxnL","CLHjzNK","uMzet3q","rfjouNm","vLrnt0C","qxL5BMi","DhjLruW","tK5qDwG","CMvQzwn0","x3nLBMrby2S","z1PItxu","CLzvquu","zuPkv0i","uxzrAvm","Aw10rK0","BKPrzvi","re1QBuO","qLjwAuG","zgf0yq","ufzbuKK","CwvpA0O","vxbKyxrLq28","zK5Hwwy","rMrHuMi","zgvSzxrL","EKDnzgG","x2rPC2nVBM4","m3WYFdb8nhW","x2LZtM9Kzq","reP0zKq","EvPouKC","wgzpB2y","u2fjv0m","tMHutfy","CMvWBgfJzq","zM9YrwfJAa","x2DLDeLUDgu","y3vYC29Yx24","shfdwfO","qxfetgm","swrXr1K","wgHMqM0","r2P1Ag8","t3rMDNy","zfPXAgi","wvjct2S","BhPfu2G","u0DmExK","v2Hcy3q","AwXSihvZzsa","CKTXwKO","uMrNthK","uKH2Dwq","ChjVy2vZCW","Dhz5ueu","rMLXr2e","Dgv4Dc9Qyxy","Bg5or3e","ig1LC3nHz2u","mxWYFdb8nxW","Ew50vgy","C29YDa","qM1bvgO","CvDlugC","uNHUv04","y3fIuLO","BKXPBMu","v2XuyKC","sezfwxq","yNPluNi","suPivw4","DvnNuwO","CYbHBhjLywq","AKfmAei","wfnkB1C","EfrRtNm","z2vjBMzVu3K","D24GCMvHC28","q2fvDeK","AunZB3i","zw5HyMXLuw8","z2v0sxrLBq","qvLezM4","wuLlque","B2fK","x19LC01Vzhu","x3nLCuLK","sKDoAvC","BNz3AxG","BvjPEgm","Aw50zwDLCIa","twvZC2fNzuu","vLbKzeK","AKTSrg8","wevhrhm","q3vNzwG","DMvYC2LVBMm","AxnrB1nby2S","uK5oAwW","wLnTC0C","Dg9cExrLC0W","yvbvy0K","CMvZDwX0","yxbWzw5Kq2G","CM92AwrLige","yMLUyxj5vhK","AfrtAKy","m3WX","zNjVBuj5Dgu","AevQBeC","ywrK","DhDIs0q","ufDzAKe","swHXqNe","r3zQqNu","CMvZB2X2zq","x2rLC3rYB3K","rxzLBNq","quTVs2K","DwDmz3G","Dhj1y3rVCIa","q0Xpu0LorW","reLNsgq","EgnuBKK","zxjYtxnN","yxKSig5LDhC","CgLUz19VBMm","tuvtu0fhrv8","Aw9Ul2PZB24","whzVA2K","y09Wzw4","ELjLtwW","BfDVwK4","z2u6ia","ENjtwgu","r1bkCum","zfjmBgK","q3vZDg9Trxi","AwrTq2O","AMvJDfn0B3i","lcbTyxGGCMu","BMnVzgLUzW","aaaaaaaaaaa","D0nyyMC","C3nrDwK","tMrsuMS","ANr5zwm","yMXVy2TLza","C2vYDMLJzs0","u2n6y3C","zgvJB2rLzey","AxnbCNjHEq","rwDutLC","B3bLCNr5","C2v0sxrLBq","B25mAw5L","thzMB08","CKPqr1e","x2HHBMrSzva","qvjmvu4","Ae1LC3nHz2u","u2jKu08","DgfIyxnL","Aw9syK4","qxzkvLO","uNH6zxC","DgPnEwW","zxjFCw9Z","zMLUza","vLrABxe","DMvUDa","z3PyvNi","Bef6DNK","B3DTsLu","DgLLCKPtt04","D3fsuwi","uuHtz0K","D05fD0C","s3PJzxy","r1zXA08","qw1VDw50","EuHdBhy","yMTcAMu","uLjpuG","tfbqBe8","v0jruxi","z2v0q3vYC28"];return Wo=function(){return t},Wo()}Object["definePr"+M(1418)](Te,M(1350)+"le",{value:!0})});import{existsSync as nv,openSync as rv}from"node:fs";import{mkdir as iv}from"node:fs/promises";import{dirname as sv}from"node:path";import{fileURLToPath as ov}from"node:url";function cv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Od(t=ee()){return nv(t.libEntry)?t.libEntry:ov(new URL("../index.ts",import.meta.url))}async function Ch(t={}){let e=t.paths??ee(),r=t.entryOverride??Od(e),i=cv(e,process.env.COZE_BRIDGE_LOG_MODE);await iv(sv(i),{recursive:!0});let o=rv(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=nt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[es]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return av.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var av,es,Zo=Ye(()=>{"use strict";Wt();re();Le();av=q("spawn-daemon"),es="COZE_BRIDGE_DAEMON"});import{spawn as tS}from"node:child_process";import{mkdir as nS,unlink as rS,writeFile as iS}from"node:fs/promises";import{dirname as sS,join as oS}from"node:path";function Kr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function aS(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Kr(r)}</key>
|
|
21
|
-
<string>${
|
|
20
|
+
`+r)}function Xn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,Xn),t.emit("wsClientError",d,r,e)}else Qi(r,i,o,c)}});var Dx=oe(Ne=>{"use strict";var L=q;(function(t,e){let r=q,i=t();for(;;)try{if(-parseInt(r(1385))/1*(parseInt(r(1557))/2)+-parseInt(r(1308))/3*(parseInt(r(661))/4)+-parseInt(r(1421))/5+parseInt(r(1161))/6*(parseInt(r(330))/7)+parseInt(r(473))/8*(parseInt(r(1493))/9)+parseInt(r(752))/10+-parseInt(r(1170))/11*(-parseInt(r(1014))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})($o,380090);var qv=Object[L(408)+L(851)],jv=Object[L(1271)+"opertyNa"+L(449)],kx=(t,e)=>function(){return t&&(e=(0,t[{HDPRg:function(c,d){return c(d)}}[L(1722)](jv,t)[0]])(t=0)),e},Wv=(t,e)=>{let r=L,i={mBpGE:function(c,d,u,f){return c(d,u,f)}};for(var o in e)i[r(708)](qv,t,o,{get:e[o],enumerable:!0})};function $v(){return Ex||(Ex=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Kv(){let t=L;return vx||(vx=[IDBCursor[t(1443)+"e"].advance,IDBCursor[t(1443)+"e"][t(1143)],IDBCursor[t(1443)+"e"]["continue"+t(442)+"ey"]])}function Vv(t){let e=L,r={orxsW:e(514),WSChh:e(870),mvFvg:function(o){return o()},Sabcf:e(835),kwoGR:function(o,c){return o instanceof c},KdSJd:function(o,c){return o===c},MQVsI:e(1198)},i=new Promise((o,c)=>{let d=e,u={IikLY:function(x,p){return x!==p},oMCuH:d(1697),KMwRh:r[d(1361)],GZhUn:r[d(699)],tfXMz:function(x){return r[d(1118)](x)}};if(r[d(663)]==="qavKi")for(var f in _0x5b03cd)_0x43f579.o(_0x3536cd,f)&&!_0x2529f0.o(_0x424c48,f)&&_0x335fcc[d(408)+d(851)](_0x43491f,f,{enumerable:!0,get:_0x566979[f]});else{let x=()=>{let v=d;u[v(958)](u[v(1411)],u[v(1411)])?_0x493cff.log(_0x5ba4d3):(t[v(1183)+"entListener"](u.KMwRh,p),t[v(1183)+v(1467)+v(1714)](u[v(1286)],_))},p=()=>{let v=d;o(Ft(t[v(489)])),u[v(862)](x)},_=()=>{c(t[d(870)]),u.tfXMz(x)};t[d(1395)+d(1020)](d(514),p),t[d(1395)+d(1020)](d(870),_)}});return i[e(577)](o=>{let c=e;if(r[c(1238)](o,IDBCursor)){if(r[c(1158)](c(968),r[c(804)]))return new _0x4bc5a0(_0x1a20b1,{data:_0x1399df});Od[c(1744)](o,t)}})[e(1321)](()=>{}),jo[e(1744)](i,t),i}function Zv(t){let e=L,r={eUtKO:e(676),MGqFW:e(1479)+"2",rTVNT:function(o,c){return o!==c},CdnWI:e(575),PynEf:function(o,c){return o>>c},oAOcv:function(o,c){return o&c},tUanA:function(o,c){return o|c},Ttivo:function(o,c){return o(c)},oxLBi:"AbortError",XUNTw:function(o){return o()},eRzLb:"cmtlD",FsbPE:e(870),dNbiM:e(389)};if(qo.has(t))return;let i=new Promise((o,c)=>{let d=e,u={njsdg:function(p,_){return p||_},YaVRa:function(p,_){return p===_},YDMbG:r.CdnWI,mKNHw:function(p,_){return r[q(678)](p,_)},dBtqM:function(p,_){return r[q(825)](p,_)},oAoCT:function(p,_){return r[q(360)](p,_)},VecKH:function(p,_){return r[q(678)](p,_)},Idnxm:d(632),lthhj:function(p,_){return r[d(1702)](p,_)},kwAVR:r[d(868)],NIaXD:function(p){return r[d(1043)](p)}};if(r[d(886)]===r[d(886)]){let p=()=>{let w=d;t[w(1183)+w(1467)+w(1714)](r[w(1559)],_),t[w(1183)+w(1467)+w(1714)](w(870),v),t[w(1183)+w(1467)+"ner"](w(389),v)},_=()=>{let w=d;if(u[w(1211)](u.YDMbG,"pGtff")){let E=this[w(1038)][w(1244)+w(812)](this._prefix);return _0x2d149a[w(1601)](u[w(878)](E,"{}"))[_0x2c2357]}else o(),p()},v=()=>{let w=d,E={mQnSW:function(I,A){return I|A},IDexN:function(I,A){return I&A},IZBoP:function(I,A){return u[q(1547)](I,A)},gkRPQ:function(I,A){return u[q(1615)](I,A)},SVgMr:function(I,A){return u[q(1547)](I,A)},uDfhZ:function(I,A){return u[q(936)](I,A)},neWCk:function(I,A){return u[q(638)](I,A)},SBdfE:function(I,A){return u[q(936)](I,A)},rMdck:function(I,A){return u[q(1615)](I,A)},Ioyml:function(I,A){return u.mKNHw(I,A)}};u[w(1211)]("yTQMc",u[w(349)])?(_0x18192f<65536?_0x1687c[_0x92712++]=E[w(504)](E[w(1618)](E[w(1055)](_0x188dcf,12),15),224):(_0x50df9f[_0x2873e4++]=E[w(504)](E[w(938)](E[w(406)](_0x3bd328,18),7),240),_0x4c8b32[_0x9c2461++]=E[w(1276)](E.IDexN(E[w(308)](_0x360f16,12),63),128)),_0x172bd5[_0x2f66ce++]=E[w(654)](E.rMdck(E.Ioyml(_0x192aa,6),63),128)):(u[w(605)](c,t[w(870)]||new DOMException(w(333)+"or",u[w(1575)])),u[w(876)](p))};t[d(1395)+d(1020)](r.eUtKO,_),t[d(1395)+d(1020)](r[d(616)],v),t[d(1395)+d(1020)](r.dNbiM,v)}else{let p=r[d(1091)][d(732)]("|"),_=0;for(;;){switch(p[_++]){case"0":if(r[d(1232)](void 0,x))return x[d(450)];continue;case"1":var f=_0x485e01[_0xf239e8]={exports:{}};continue;case"2":return f[d(450)];case"3":var x=_0x1ebd9c[_0xfc56b9];continue;case"4":_0xcd1d93[_0x345886](f,f[d(450)],_0x12e9eb);continue}break}}});qo[e(1744)](t,i)}function Jv(t){Wo={rYnZN:function(r,i){return r(i)}}.rYnZN(t,Wo)}function Yv(t){let e=L,r={tylrs:function(i,o){return i(o)},EEugk:function(i,o){return i>o},yeImD:function(i,o){return i+o},dboiP:function(i,o){return i(o)},rOnkB:function(i,o){return i===o},pZGrZ:e(783),SiljU:e(818)};if(r.rOnkB(t,IDBDatabase.prototype[e(691)+e(983)])&&!("objectSt"+e(1416)in IDBTransaction[e(1443)+"e"]))return function(i,...o){let c=e,d=t[c(493)](es(this),i,...o);return Dd[c(1744)](d,i[c(1763)]?i[c(1763)]():[i]),Ft(d)};if(Kv().includes(t)){if(r.pZGrZ!==r[e(1397)])return function(...i){return t[e(427)](r.tylrs(es,this),i),Ft(Od.get(this))};{let i=_0x2dfdd1[e(690)];if(r[e(764)](r[e(1201)](i,_0x549f30),_0x11fd03.limit))throw new _0x13a295(e(1144)+"t limit");return _0x719467[e(690)]+=_0x30f821,i}}return function(...i){let o=e;return r[o(998)](Ft,t[o(427)](r[o(811)](es,this),i))}}function Xv(t){let e=L,r={iZhFM:function(i,o){return i===o},UkNQV:e(1352),EYroe:function(i,o){return i(o)},bxyNO:function(i,o){return i instanceof o},BDgyg:function(i,o,c){return i(o,c)}};return r[e(845)](typeof t,r[e(512)])?r[e(966)](Yv,t):(r[e(703)](t,IDBTransaction)&&r[e(966)](Zv,t),r[e(1264)](Tx,t,$v())?new Proxy(t,Wo):t)}function Ft(t){let e=L,r={XbRVm:function(o,c){return o(c)},sHUUk:function(o,c){return o!==c}};if(t instanceof IDBRequest)return r.XbRVm(Vv,t);if(Go[e(750)](t))return Go[e(915)](t);let i=r[e(1202)](Xv,t);return r[e(1309)](i,t)&&(Go[e(1744)](t,i),jo.set(i,t)),i}var Tx,Ex,vx,Od,qo,Dd,Go,jo,Wo,es,Sx=kx({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={SWJdQ:function(r,i){return r instanceof i},kLqqv:function(r,i){return r===i},CBdhO:t(1377),kbYLa:"store",fdNzu:function(r,i){return r===i},eQSNa:function(r,i){return r===i},xOWLs:function(r,i){return r in i}};Tx=(r,i)=>i[t(1021)](o=>r instanceof o),Od=new WeakMap,qo=new WeakMap,Dd=new WeakMap,Go=new WeakMap,jo=new WeakMap,Wo={get(r,i,o){let c=t;if(e.SWJdQ(r,IDBTransaction)){if(e.kLqqv(i,e.CBdhO))return qo[c(915)](r);if(e.kLqqv(i,c(1423)+c(1416)))return r[c(1423)+"oreNames"]||Dd[c(915)](r);if(e[c(1564)](i,e[c(1662)]))return o["objectSt"+c(1416)][1]?void 0:o[c(1423)+"ore"](o[c(1423)+c(1416)][0])}return Ft(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return r instanceof IDBTransaction&&(e[o(682)](i,o(1377))||e[o(1694)](i,e[o(1662)]))?!0:e.xOWLs(i,r)}},es=r=>jo[t(915)](r)}}),Rx={};function $o(){let t=["B3jLtMfTzxm","Ae92yNa","wwj3vLO","mxWZFdD8nhW","zNjVBuj5Dgu","mJyXotCZnwvsDwTADa","Cg9PBNrdB24","B2jQzwn0u3q","y3vYC29Y","Cw5ZBM8","x29UvgLTzw8","BM1Qsw0","Bg9Nsurhzw4","qKHtuLu","CfLcAwC","CMv0CNLdB3u","rgL6zxy","C2v0u3rVCMe","rhLMs2O","zw5JB2rLrNi","se9MCha","v2vIu29JA2u","DgTvyKy","ywXSzwqGBxu","wM5rzei","CMvZzxrdB3u","vgX4ENi","ChjVDg90Exa","Dgv4DfbHEwW","se95seS","CNnVCL9Uyw0","wKrtsfq","EMj6A3y","x3bPBMDqB24","ywrKq291BNq","AxnFywnR","zNjwBg8","DhjWDMO","ig1LC3nHz2u","Cwvxrei","CMvTB3zLq2G","vwjWu3i","A2v5","C05zvfq","BwfUDwfSihi","wM5eAvC","vxvWBuO","CKnnuhm","EvjLy29UBMu","zMrHz1C","AKLMqNy","zw50tgLZDgu","sfHiyvG","zgTcwLK","y2HnyxHdB3u","zgLcsfC","wvn1y3e","BMnLq2XVC2u","CePjqve","q3vZDg9Trxi","ENnRu0W","D1beDMu","x2n1CNnVCK4","m3WWFdf8nhW","Ae1IyNm","ywnOzwq","BNrfBMrWB2K","n3WWFdH8oxW","aaaaaaaaaaa","lcbTyxGGCMu","uw5IDMu","ywDL","BNruugS","ywnRtxnNswq","tu9mv1u","rgT6twW","BKvjwhm","mZi4mdmXmwjZCM1UCq","BNrbBMrvCgq","u0TeCMq","zxjFAxnFywm","zxq9DxrMltG","D2LSBfjLy28","rxDWsu4","x194x21Zz18","yM9L","rgrXu1i","tNnWsgi","r2LJBgm","CNzHBfzHBhu","wfrLshG","CMvWBgfJzui","zgv2AwnLx2K","y3r2AgO","twfIu3e","uNHhyNi","ywXty29Wzq","r2rfEgK","wNLjqwK","t3jdyw0","ELfhDui","z2vrDwv1zuW","yKfNr3a","Dhzev3e","y2HLy2Tszwe","uwDHuKm","wePIALK","EwnjvKK","t05TqNm","BKndB0S","zw1LBNq","CM92AwrLigi","BMCGB3iGyw4","tePYvw0","z29PBMCGyxC","Fdj8nhWX","D0Tby2K","y3jLyxrLtwu","AfbkEfu","AefJA01LC3m","DMfSDwu","wKXIuLe","Awz0CgS","B3jL","C3rYAw5N","C1bPyuS","BLfOwNe","BKPPtKS","BenNsKW","Cgf5Bg9Hzfq","B3jRig9MzMW","BuToshC","ANfwANe","veXYtLm","uvvsAe8","C2v4r0G","DgfIyxnL","AxDWEKO","swH5y1O","B25ozxr3B3i","twjuvMO","mtGWohPZzeDerq","yMLUyxj5vhK","zvv0s08","swDsvuu","uNfstKW","rKLmrv9ot1q","mNWXFdv8nNW","A0XXCxy","tfbYCwC","zuz4Dgm","u0XHBhG","whHxvLu","vwDQwNq","yvbOsem","AenSB3nLrxy","whHqEKy","z1vlA0C","rLjptLrjrvi","A3DbvLi","r29rAwu","BIWGAg9ZDg4","x2zVCM1HDeu","D2DhqMu","rxzLBNq","B25dBg9Zzq","B3bLBG","v2jlwg8","x2HHBMrSzva","rer1yKG","shDZEK0","CgfNzwHPzgu","BNf1zfu","Ec1TC2CTy3u","ywnOzwqSihC","AevYCM9Yrxy","z2zJuM0","yNjmyNa","BwvZC2fNzv8","quzOtMq","zLbVCha","Aw5KzxGGB3u","AxLZtMm","Dw5RBM93BIa","EgvKBeW","CgfYC2u","BevJrM4","AKXPr2G","y3rmq3G","tfnIEKe","AxjLza","B25TzxnZywC","C2DPza","twLwD28","B25szwnLAxy","z2TItM4","x2LUAxrhBg8","DK1nvuC","DxrVuMvJB24","zej0Cu0","yxrHlcbKyxq","refuvwe","surLEe4","Bw5zq0y","C0TmEu4","DLv1tgS","x2LUAxrqCM8","CMvWBgfJzq","CwrtCfC","zxH0zw5ZAw8","z2u6ia","B3jRzxjhBg8","zw5HyMXLqxu","vgjPrNC","zw5fDMvUDa","C0jf","y29UDgv4Da","vxPgvLu","vLv1uNu","rwnxwNm","x25HDMLNyxq","A2v0ignVBNm","CfLkB1y","Efrurw52","z1royui","zMX1C2HfEha","zw5KCg9PBNq","vNHJBui","CMvXDwLYzwq","B1HzzKq","qw1VDw50","DgXkzNi","ChfXrLi","v29PwuC","BM13B0m","z0XAAeG","x2n1CNnVCKy","DhLWzq","BenbEMu","qLzeDMW","sNvlCNy","CLjxv0i","yMXVy2TLza","A1PhAue","Chj0q1u","x2fKzfDZtgK","A2jztge","shvks0u","yw1L","wLnWyMe","CMvHzhLtDge","BwvKAwf0zwW","su5tvefova","x29WDgLVBNm","rLjQEK4","y3jLyxrLrxi","CwDfq2y","r3Lov3O","s2DmyKe","zMTbv2y","BgHyCva","CMvHC29U","z0nOChu","D2vZshi","wfzAzu0","Au5twha","vfbHC0W","CezOBMW","vfPVCe8","y3rAugy","A0XOCfK","r0rwz1i","BM5XBxO","q3Lqvwy","CM92AwrLihy","qMvLs08","rMzvA0q","AM90sLq","zvfttMe","ChrVCG","Aw1LCYbPBIa","v0vZC3y","vxzxEe8","CMvQzwn0","EsbJBg9Zzwq","t3H3ruW","vhrPDM8","sNLMC24","rvjst1i","DffJv1C","DwLIExi","tuvtu0fhrv8","EfvZzuvUDG","DLL3DLC","zKDYrfi","Dg9cExrLC0i","A3rTr0K","igzHAwWSig0","BMvY","D25wBhe","CNnVCL92ywW","r25csg4","zw1PDa","BwvZC2fNztO","Dg9cExrLC0W","BgLUzw5V","serquMC","y3jLyxrLrwW","r0DrBNG","tKfusvzfx0u","C2v0y3vYC28","twLZC2LUzYa","y29UC3rYDwm","rxjYB3jdB2q","x29Ut3bLBG","ihzHBgLKihm","q0Xpu0LorW","Aw9UvgLTzw8","ywXPzcb1CMW","BMDLza","rxfkCeO","zNjVBuHHC2G","C1HxDLG","y2XVC2u","qxbmA3q","zNDZxZeUmc4","uxbRD0W","zxjYtxnN","C2v0","y29UBMvJDa","Dg9VigXHCMC","x21PBMLoyxy","thf0A1i","q1vUAu0","yLDuv1O","x2LUDgvYDMe","Aw5L","CLL5Cfe","zgvSzxrLrge","y29SBM8","z2v0q3vYC28","rwXyywW","Dw1NtfC","yw1Lu3bHy2u","B0HqyM0","CMvHzg9UBhK","C1zRthu","C29YDa","BMvxq2S","rNDSB0C","y3vYC29YlNm","quPesgm","vNPzzee","rxvmDgO","B3fZExG","vhHrzfO","ELLruwy","BgLTAxq","CKXXtxy","zxbAz3m","CuHcEfa","CeX4A0i","v0H1uhu","zufJAW","yMfSu2nVCgu","tvHHDNu","C0Xf","wxrmuNa","sejKC3a","Dev2zw50","n05twMzSuW","rwvOt1K","DhjPBq","qwjVCNrfCNi","uvjhsg8","x3DHAxq","Dw5KzwzPBMu","Cg1ICuy","CLnhywm","CgvYC2LZDgu","A3LZAfe","t3PjEKK","ywWGy3vYC28","tLrkAeG","wLnHqLq","t25zA0e","z2f5Dg0","AgHivha","yMLUy2y","swrUEg0","uefNsgO","DuvhuhK","ihn1y2nLC3m","Bu1ltei","BfrPBwvVDxq","B3Dmv3G","DKv2ELm","y2HlB2u","t0Dstge","B2jyy3O","DfvHBKe","CIb0DhDjra","DgvmB2Djre4","AwDHDg9Yt24","C2vYDMLJzs0","DNvpAw4","BM12zwO","AefNAhK","A1jXs1u","rwrzAw4","vhL4CwO","vwDptvy","AgfUz2u","x2rPC3bHDgm","Beritfi","yNvMzMvYzwq","ysbTDxn0igi","ywXSq3vYC28","y2LSDKS","BMCGDxjSoIa","sgPyr0e","x3jLy29UBMu","Aw5Lza","x2rLC3rYB3K","BgvY","mhW3Fdj8mhW","Ag5Nzw4","zwnQrw0","qujWseW","ywjVCNq","su5Wq3q","DMvY","v3nAuNq","B3L6EKi","u2HHCMvKv28","A2LtANq","BgzgB0i","x21LC3nHz2u","Bg9ryKC","AfHKyNa","AxnmEwG","DKrsBM0","wK9TtwW","B0vewgO","q2j0ALG","sevpvvK","u1zNtxi","CNjVCK1LC3m","zgvMAw5Luhi","wMjzuK8","ywDLu2HVDW","ywPtAve","BwLUAvbYB2C","ign1CNnVCIa","tfHrr0S","v0nzwee","tg9JAW","DhjPzxmGCMu","y2rlvvG","vxjoExq","uw1kExK","ywrKt25L","x3nLCuLK","yKvuuhG","yxnZAwDU","nNW1Fdj8ma","x2DLDeLUDgu","yxbWBhK","x29Uq2XVC2u","lcbOB3n0BMe","Cw9Z","y3HQvLO","q3Pnwgu","zeLZC3K","EMnfCMm","wgvvtha","uundq1m","y3DHCfK","Cxryseq","BM9Uzv9UB24","wfLmBem","CKnmvhO","uhjPBwfYEuS","B3nLrxzLBNq","zgf0yq","z2v0qwXS","uxrsv2y","BhrPCgXLihq","x2n1CNnVCK0","BwvZ","zxHWB3j0CW","r21Mu2u","DuTtqNm","m3W0Fda","yMfSrxzLBNq","ywrKzMq","AKvAt04","zMXVB3i","C3vIC3rYAw4","BgLUzq","BgvUz3rO","ue1xsKO","yNL0zu9MzNm","q29UzMLN","BwvZC2fNzq","BuzhEKG","q09otKvdveK","mxWZFdj8nhW","sLrrqvi","EwXcDMq","vM9Jsgi","vLLOExO","DLP1v3C","mtzPvuTHs1C","EMTuAuW","Dhj1y3rVCIa","zK5zsuK","zKP0B0O","yNbhz1a","x19LC01Vzhu","r2zTwum","zwXQthi","vgT2Bwm","EfL1wKu","DxHLuMO","x2nVBM5Ly3q","EMnMugS","x0vysvnu","zgvSzxrL","CMvZDwX0","ze94yK8","x2LZqNjVD3m","q1fLvgC","y2fSBa","B2zMBgLUzq","wML0vu8","y2XLyxi","z2vjBMzVu3K","rwHsv2C","qxbnANC","r0vntg8","uevUsxy","AevfvLq","EwDtyvm","BvfUu1C","zgvS","whfHqKG","DgLLCKPtt04","igzPzwXKoIa","yM9KEq","Bwfztvu","B3jpBMXPBMu","vwTouvy","z2vY","C3vJy2vZCW","zMjmtgC","tfnhs1G","Eejfwwq","zxjHDg9Y","D24GCMvHC28","Ewf1Awu","z1LNAhm","q0HyrhO","t1z1y24","zsbHihn0CMK","D3Pmsue","CMvHzfvjBNq","B2n1sfe","AwjlyMe","Cu5vuue","D3jPDgvvAw4","zwrPyxrLBhK","q0Xpu0ve","AvjjweW","u0HvsNa","x2HHBMrSzu8","uxnAwNK","DhDVCMTdAge","rwXMBvu","zwnVBM5Ly3q","sfLxC3e","shHJDLm","x2vUzhbVAw4","t0LcCMS","tMzrCha","AML6Dhm","rhrIB0W","yNbeqM8","EMLOwuG","zMXxvMu","yw5Hz2vY","yw1LoIa","Dg9Iwei","yKXABMK","C2vYDMLJzq","yNLL","icSG","B25Uzwn0Aw4","yK5SwKG","z0jPq2O","C3b3zK0","yKjWBNO","suvtx0vsuK8","CMfNzvn5BMm","C2v0zgi","ug5YCNG","yKXvDwW","CYbPBNn0yw4","sfPqvwu","yvn6r0G","qMjfEKO","CMLXEwu","z0v3rg0","ALHeuxG","s1PdCfi","zxnmtLK","zMPcBLq","DgHLBG","CxHgAxi","v2vPEgLUsLm","C2nYAxb0","zK9wAfO","qxbIBK0","zhzYwLu","Dg9oDw1Izxi","zMLN","zMLUza","yxjiEKC","B2nRzxrtDwm","ren3s0m","CK92yvi","x2nSzwfYvgK","mxW0Fdn8mNW","vKHltfm","r3HHBxu","yNvMzMvY","B3vUDa","sMzWqKK","tfveqM8","uKr5BhG","reTTwfO","B0Lsvue","x2nSzwfYugK","DgvZDa","x2LZsw5PDa","BhrOAgO","x29UrxjYB3i","BeHHBMrSzxi","BerXt1m","yxnL","Cgf5Bg9Hza","sLnLsfi","C3bSAwnL","x3bYzwzPEa","AgvKtwf4uMu","uMvJB25Uzwm","rNnIueu","r0jSDxe","ihrPBwvZ","rhnIqwi","shDgvuS","y0HpreS","DxbKyxrLq3u","sw5TBKS","EwfetM4","Aw5PDcbrB1m","x3nLBMrby2S","Dxv6Exm","Ae1LC3nHz2u","CMvHzhDYAxq","uxfxtKW","tfrdu0C","rMnevNe","CMfUzg9T","quPwwwy","BvvbEfq","DhbizwfKzxi","Cw96zfe","vMvJs0G","CgfNzxnOB3C","yNL0zxm","ywDLrxzLBNq","yujhwfu","u3rzwhu","D1fQzhO","tK9csfi","s2jqExa","rxbKChe","y2XVC2veqG","CMPsyLy","AhffzLi","DunUvKG","tMPdDKm","Bhb3vei","u0jKzKu","wNHmDwC","BfPmufe","u0DTqLy","A2Twr2S","x2nYzwf0zvm","weDSwhG","ndqXmda0ALzIC1zo","B2nRzxq","u2fIy2y","B3nLza","CKrnvw0","q291BNq","D2rqquS","Dfrzue0","u1HfuNu","Dw50","y3ruAw1LB3u","uhPoz3G","ywzL","zMzMzG","DunVDg0","y29TCgXLDgu","CNvdsMW","uhLUrwy","vhDVALu","sNHQCNO","yLnpy3y","zMroENu","wLnhzuC","zMvY","vfbREvO","zu1VAKW","rwPbAeK","AwXK","Ahv3s0S","B2zMC2v0","DhjHBNnHy3q","u0PKru4","BvD3BLC","ENr6y1q","tMfAqKW","tuXHuKy","BNruCMLLC0m","uLjpuG","v1ndAgG","Aw5Ky0e","rNjVBNrPzxi","C3rLBMvYCW","yNH5tK8","zw5HyMXLvhi","AMnfq3K","DfDiwuW","CYbWyxjHBxm","BujWr0u","zNjVBunOyxi","C3rYAw5NAwy","A3n5vxq","Ahr0Chm6","t3PeqxG","vxrtze4","Eg9gqKW","ugvurxa","q29WtgO","mxWWFdj8nhW","ywnR","DM5Ozei","vuvqrvO","we5qzwy","DhrbvMW","ExnRBNe","yxLst0G","y2vZC0HHBMq","thPKu3a","BMrWB2LUDfq","ywXSB2nvBNm","wxr5A2i","BMfTzq","C3bSAxq","Aw5N","D0HhAKK","suXyww4","zMLSDgvY","x2DLBMvYyxq","rg9Oq0y","AxnbCNjHEq","A1zdBKe","zMzmAw5L","o2nOyxjZzxq","zfj0vge","Cg93","tw9KDwXL","y2Lzt2u","zv9ZDwnJzxm","Ae9Wzw5fDMu","Cgu6ia","AgfZ","t1bftG","mZK4mJK2mhffEwLgqW","uNvNCgK","CMTLCKDSB2i","yxjYyxLIDwy","y2XLyxjtDg8","rxzovge","rLPPrxy","v0rMzNq","CMjPueW","C2v0sxrLBq","CwjcvNm","tLLhzMG","ruv1z2S","qMTZuLy","B25SAw5L","zhnPCg0","BM93","y2HnyxHuCMK","q09ZveW","y3r4","B3bLBIa","yxjttMi","y2XVC2uSihC","x2XPC3rLBMu","x3nVy2TLDa","CMvZB2X2zq","ExndEwe","AMH2thC","CKzOrxe","yw9JyMC","x2rYB3bhBg8","BxfOteK","DxH1wKW","u1LIyNK","ywDLsgLKzq","uwrTshK","wuL4B2C","B2nRzxrgywK","Dhn4t3O","x3jLywr5q2W","swPiAvm","nxWZFdz8mta","zMPjyvO","tuD1DfC","zfDVCMTLCKC","vKLVwhu","ywnRDxbfBMq","Bwf4uMv0CMK","u2vXsuq","DMvYC2LVBMm","l3DZl3yY","wwLbvK4","tvfwC0K","Bwf4tg9ZC0m","CM1Nzg0","A2v5CW","DMfS","y29UBMvJDca","qMDowKW","zgjVAva","z2vtEw5J","Dg9iyxnO","tg9Nsuq","BKXPBMu","D2fZq2XLyw4","zxjYtM8","BgHMwhq","quvREvK","DKz5AM8","vuTws1u","DhjPzxm","B25nzxnZywC","sfb3y1m","B0fpy3y","ExPNvLm","C0jAqLe","uKLZrfe","A1Dts00","v0rgrM4","u25iv1q","rvbfA0O","surKrLK","zfbnCLu","tNLuB1C","lcbxzwjtB2m","DMvUDa","uxvLDwu","ruffv1C","Dhvrv3i","BwfW","BuvxsNi","zMLSzw5HBwu","rwnnywG","AvPOrK0","qLPlA3y","BMrLEa","rfDMwKe","CM9YrxzLBNq","Ef9MCM9UDgK","B3bLCNr5","CgLUz0LUDgu","A2HvwwG","B25fCNjVCG","BMvLzf9Hy2S","wxnxz0q","CNnVCKzPBgu","thvmELq","svH1vhK","C2vYDMvYvgK","tKDFrvjst1i","DgzytxO","wfvzzvm","AwXLx25HBwu","C3rHCNq","jMPZy2fSBgi","sMn2zvK","B3HmqMK","tLLZs2G","zxjYB3i","uwPwv0i","wvfXwNm","DeLUDgvYy2u","Bg9IywXty28","AervAxG","tKLHweq","x2LZtM9Kzq","BMPZzgC","De1HBMfNzxi","DxrMofDYAxq","DMLJzuLeig8","y29Kzq","AxnmB25N","tg9NsurozxC","A1nOugW","zvj6tgi","zM9Yy2u","DenTEhq","wvzfA2G","vgLTzw91Da","rLDt","rxnRvu0","whH3DMC","sM5xDgG","t2jQzwn0","uurpt3i","shb2sMq","zxH0ugf5Bg8","yw5Nzq","ywrK","C2XPy2u","DgLUzYbZzxi","zgvIDwC","Dhr3Awq","we5PAgi","yxGGCMv0CMK","ywX3yxLZ","zv90Aw1LB3u","wxnur2W","DM1LAvy","DeLK","AwrI","DgLTzw91Da","D2vI","z2v0","twvZC2fNzuu","tK5tzhC","rKHyCgW","yvrZvgS","wLj4r2y","Aw9Ul2PZB24","DxjS","t1r2BxC","zwn0","B25JBg9Zzq","B2fK","sMPOv20","tMfTzq","y0zrEM0","z2vhAMS","vgf2q0e","y291BNq","x29UtwvZC2e","Evbxyxm","zgjJzuO","B0fVq1q","AgrRy1e","z2Tsufe","C09Luei","AwfTB2y","z0Ddsvm","x1fVu01HBMe","yMfJA3vWigu","Cev1ufy","x3bPBMDmB3m","sLnptLa","BwHNANq","tuHqyva","x3vYBa","BMCGzMfPBgu","zcWG","BMnVzgLUzW","zM9YrwfJAa","r3r2vgG","B2XQsg8","zxj2AwnL","x3bPBMC","swLRtfK","DLLurKm","Cgf5Bg9Hzeu","z3LXq2K","EvHnEeW","Dw5ZAwDUzwq","ExLPzKu","CNvRD3m","rvLYB2u","Aw5JBhvKzxm","re5uzLu","CuHSwhy","y3jLyxrLt3a","AM9MAwS","ALbPDwK","B2XKvMvYC2K","q2vQr3q","C0LPtfy","wMnsB0u","ywLJwgC","CMvZzxrfBMq","Aw5KzxG","r0zLB3O","zMzqEwu","CeDkue0","Aw9U","u2TPCcbWyxm","z2PRBg0","zhvqA0u","rvvNtgK","A2jrsfC","C3rVCMu","yLbsqNm","Aw50zwDLCIa","x2LZtwLUAvC","CfnptKe","CeflD1y","B2zM","x2HHBMrSzvi","sffMu0O","DhLSCNm","CfHfEgO","AeHjv2u","quXwzKm","mdaWmdaWmda","ExPQwgW","CgLUz19VBMm","Eg9KsxG","we1fCLO","rxbKAMy","x2jPBMfYEvq","CvLzzMu","CM92AwrLige","z25cyuq","CMvUDevUzha","AM9PBG","mJi0mdrhqK1ODfC","shLHweW","wwTKrxq","ChvZAa","u0PpCwO","ChjVDg9JB2W","tgLZDgvUzxi","C29Tzq","ugvmCvi","yMLUza","DLLWyu0","ELvgD1G","x3bYB3rVy28","Aen2rva","CYbHBhjLywq","CKDVwwC","AxnszwfKEq","CMrNBei","CMXJA28","x3DZ","BMfkD2y","y01jweS","BvnXzMu","sMP0ELe","x3fVC0rc","BM5Ly3q","ufvQqNe","zvfvsNy","ruTSzNm","wfvovhC","vMDcq3y","vgfN","y2HHCKnVzgu","DMfSDwvZ","yLLbAxa","qNf1EhO","x2LZv29YA2u","EMHnBLu","sgveDfO","C3rVCcbPBw0","mhWYFdr8m3W","svPcB1a","vxbKyxrLq28","x2rPC2nVBM4","q2f4yve","BwLUzW","zgvJB2rLzey","A1n0yxr1C0m","BgLZDgvUtMu","yMT1BgO","BMrWB2LUDca","swXPsw8","C3vIyxjYyxK","x3jLBw92zvC","EKrZwMi","Axnby2TdBgu","ohW0Fdv8oxW","r3rMvMy","vNDmDNe","zvPNyNK","z3rsswC","vhfjww8","t1rkEKm","CMLLC0nVDw4","rujUrKK","zwDuuw8","ExPOtwO","r1D2z2e","ywHyz2u","vhnQugC","tfD6EeC","AxnJtKW","x2rItMfTzq","EKvIC1G","AujQCva","uLvsBwy","BvDHDxm","tuDXrLC","zNjVBNrPzxi","Ec11C2uT","yxnJCMLWDa","y09Wzw4","Dxrjza","tgDhv1G","D3nZoI8V","BwvY","tu9jrgm","EfrwuwK","yNnlDNa","EhvcA2i","BML0AwfSAxO","BMDuAw1LCG","BwLZzq","CLbTAMu","Cg9W","vwDHy3C","sLLyy3m","uMXcvwi","r21kBeG","AMfbwMm","CNzHBa","ihjLy29UBMu","zgDKq1y","ExbL","BxzgDMC","wwTYDKm","Ag5fugS","u3rYyxrLz3K","qvjuBuS","CK5OreG","CMfTzq","DMvYC2LVBG","v1Lxug8","CgXLyxnLiha","x29UugfNzu4","DfLjyw4","rKfUtwK","y3vZDg9Tshq","ExH2r0i","ugDks0e","DhzhExi","q29Kzq","sM55uhm","yMfTyLe","ihzHBgLKigq","zhfZzKK","EuXsDfa","wu95vxy","shbdqui","y29UDgLUDwu","uMvHzcbWyxm","zw5HyMXLuw8","yKTJCNG","A053yxy","yxrLq291BNq","C2fNzq","CMfTugfYyw0","BhvUzuq","DcbVzIbYyw4","y29Uy2f0","AuHxsxi","BLbHAwm","A3Hjufy","zvvYBa","s2rtsMq","u3nduKG","B3v0sw50zxi","mZCWmJqZoffqs0PyDG","DvfkBLq","BxnN","Bg9N","mxWWFdn8mNW","Bg5NAgG","rgvKAwnHDgu","Dgv4Dc9WBge","zcWGDw5RBM8","mtCZoeLVwwHoqG","tennBNe","BwfRCgy","rg9Ozxa","venRvve","yxbWBgLJyxq","yuHmv2K","z2v0qwXSs2u","x2rLyNvN","zwvKzwq","BezSDxnO","zxmGCMvHy2G","zw5JB2rPBMC","CMvTB3zLrxy","zNjVBu51Bwi","B25LCNjVCG","BNrLCG","CNLqEhy","CgLUz09Uy2u","y3jLyxrLq2W","v01TswS","z2jnr3G","zunnse4","B25VCgvU","teLzzLC","EMDIrhm","tfbYBNK","qMPXzeq","Euj1sLC","B25tDgfYDfi","vw5Oyw5KBgu","EwvjBuq","wgjsvM0","BMv3vMvYC2K","CgLUz0XVC3m","sxfPwhG","AxnrB1nby2S","CgjICdi","B25pCgvU","y29UBMvJDgK","q09oveLovuu","wwfwuMe","A2rNAK4","Bw5TCvu","nxW0Fdj8mhW","uvj3CKG","qvnTB1i","uu5qsw0","EK9Wz3y","AwXSihvZzsa","DuHtCxu","y3PMzuW","ufjptgy","Chv0","qvDgvMS","yw5ZzM9YBvq","y2HLy2TdDxi","C3H4Afi","EfPhquS","B2LUDfjLywm","Eev4r2i","AMvJDfn0B3i","CLrwtLq","ywXS","tgz3t1K","vxrmt2u","s2vTCw8","ihrVihjLDhi","A3DVr1i","zw5XDwv1zq","wgHKCgq","vKXLEw4","y0X3BNy","D2Xry2u","z2v0u3rVCMe","CMH0Cgq","BxnNsuq","vMLdBeS","A1PyDLm","CMvJzxzPzwq","y3vYCMvUDeK","s1LTvMu","rg9sALO","y3vYC29Yx24","zgLZywjSzue","CMvKDwnL","y3vYDMfSDwu","CMTUDMe","Cg9PBNrbBMq","qNjPzgDL","x3DZsw5ZDge","tMTfA2m","seHnrgi","AMrkExu","qKrNEwC","D3jdrfy","C2v0q3vYC28","quTzDKO","yMLUyxj5","De9Rrui","C0nVDw50zxi","z2v0t3DUuhi","AxPgEKe","y3futeW","EKv4Dfm","Dg9tDhjPBMC","DurMAfO","wvDTyLG","Aw47y2HHCNm","vNfwCvK","z2v0sxrLBq","t1bftL9fuLi","re9Ry0q","D0Dcs00","y29UBMvJDfm","D3P4z2y","r1POvw4","BefhyxC","uvb5BgS","rwPSB2y","Dw96yxK","q3vUAxe","AgvHzgvYCW","EgTtu2i","CufmrNa","AMnhBNa","ve9MAM0","wKP2uvq","x3bHDgHlzxK","vengq3G","veXtuuC","teLzzgW","zKnUthe","rfvtrwi","runPDeG","B3nttva","D3HzCK0","CMvJB25Uzwm","mtjov0DyrMG","C0HvvwS","wfDUrfC","vhPQwgS","sw5kuxG","u3ffrKq","zxjFBxnNAwq","BKXAANq","C3nHz2vfDMu","yLP3wfO","tgnyr2C","tufyx1jfvfi","B25tDg9Wsw0","y2f0y2G","vfrerM4","C3DLB3y","Bg93","zNjHBwvuExa","sND2BKm","tMXjzKe","uLDWBwi","Dg9hzw5LCMe","Dg9mB3DLCKm","zgf5q0W","yu5su3y","q3vZDg9Tq2W","BK9wBeW","AgLNAa","x0rctMfTzq","zgLZCgf0y2G","yNL0zuXLBMC","DNbxy00","r0D1vgi","wffuwvq","zw50","u052CfK","ExroCeu","y29UBMvJDeu","y3nTuM4","BezmtMK","B3bLBKrc","uKrnuK8","AwXLtMfTzq","vujYwKm","zNvUy3rPB24","x2LUAxq","Aw5KzxHpzG","z1rPBwvVDxq","zxrxB3jRq2G","vKvOse0","DxnLCKLW","wgL0D08","AMnVB1O","B3j4C1C","Cer3q2y","B3LpD3e","yurvrNy","t2PfugC","ChbL","BwntDw0","y3vYCMvUDeu","swnAAvm","mNWWFdn8nhW","ihrPBwvVDxq","C09Ws04","yxjvC1O","rfbqwK8","DNfZEwG","CMvJzwL2zwq","zg9Uzq","y2j5DgK","ihrYEsbYzwm","D3jPDgu","zgrjrcWGzgu","uKftANy","C2vUza","x2LZtwLUAvq","nZy4rxjoEw1j","u2rjCwu","C0XPC3rLBMu","zNjVBujPDhm","CLDpvgy","Ahr0Ca","y3vYC29Yx2y","tw9sqLO","z2v0q3vYCMu","we5Zu3u","ywrKrxzLBNq","D3m6lY8","u2LSALu","y1jdzuS","tM1srMK","AhH2rfy","vfLvvem","A2X5zvC","t3PWweC","AhHcv2W","Dg9Y","z0vvEvm","sKjhCg4","ruvJsw0","r0f0tLy","AwjOyum","B01dDuG","DcbSAw1PDa","BNrfsgq","Bwv0Ag9K","y3jLyxrLuMu"];return $o=function(){return t},$o()}Wv(Rx,{deleteDB:()=>eS,openDB:()=>Qv,unwrap:()=>es,wrap:()=>Ft});function Qv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=L,u={uCotm:function(p,_,v,w,E){return p(_,v,w,E)},ztzcT:function(p,_){return p(_)},hCvEP:function(p,_){return p(_)},ffPye:d(1739),hhHTp:d(801)+d(372),lfFoB:"upgraden"+d(1179),ruCJl:d(1658)},f=indexedDB[d(1582)](t,e),x=u[d(694)](Ft,f);return i&&f[d(1395)+"Listener"](u[d(396)],p=>{let _=d;u[_(675)](i,u[_(694)](Ft,f[_(489)]),p[_(973)+"on"],p[_(1203)+"on"],u[_(1027)](Ft,f["transact"+_(983)]))}),r&&f["addEvent"+d(1020)](u[d(677)],()=>r()),x[d(577)](p=>{let _=d;c&&p[_(1395)+_(1020)](u[_(981)],()=>c()),o&&p[_(1395)+_(1020)](u[_(347)],()=>o())})[d(1321)](()=>{}),x}function eS(t,{blocked:e}={}){let r=L,i={LaoDm:"blocked"},o=indexedDB[r(1754)+r(1552)](t);return e&&o["addEvent"+r(1020)](i.LaoDm,()=>e()),Ft(o)[r(577)](()=>{})}function Ix(t,e){let r=L,i={HOyHK:r(629)+"e",YsWgD:r(1761),UtLOe:function(f,x){return f in x},HtpTp:function(f,x){return f===x},ASmoR:r(1540),jotJT:function(f,x){return f!==x}};if(!(t instanceof IDBDatabase&&!i[r(1235)](e,t)&&i.HtpTp(typeof e,i[r(1216)])))return;if(Ho.get(e))return Ho[r(915)](e);let o=e[r(1623)](/FromIndex$/,""),c=i[r(1693)](e,o),d=Px[r(967)](o);if(!(o in(c?IDBIndex:IDBObjectStore).prototype)||!(d||Cx[r(967)](o)))return;let u=async function(f,...x){let p=r,_=this[p(691)+p(983)](f,d?i[p(1445)]:i[p(856)]),v=_.store;return c&&(v=v[p(979)](x.shift())),(await Promise[p(1233)]([v[o](...x),d&&_[p(1377)]]))[0]};return Ho[r(1744)](e,u),u}var Cx,Px,Ho,tS=kx({"node_modules/idb/build/index.js"(){let t=L,e={WYWPo:"4|3|5|1|0|2",bSOcv:t(1223),INpCt:t(900),wgGBe:function(o,c){return o(c)},HwszM:function(o){return o()},xZGAK:function(o){return o()},DKmXZ:"getKey",arHzG:t(445),IEaAF:t(1177)+"ys",HBYTu:t(932)},r=e[t(1126)][t(732)]("|"),i=0;for(;;){switch(r[i++]){case"0":Ho=new Map;continue;case"1":Px=[e[t(681)],e[t(390)],t(488),"clear"];continue;case"2":e[t(1579)](Jv,o=>({...o,get:(c,d,u)=>Ix(c,d)||o.get(c,d,u),has:(c,d)=>!!Ix(c,d)||o.has(c,d)}));continue;case"3":e[t(1586)](Sx);continue;case"4":e[t(1228)](Sx);continue;case"5":Cx=[t(915),e[t(600)],e[t(587)],e.IEaAF,e.HBYTu];continue}break}}}),nS={idb:function(t){let e=L;t.exports=Promise.resolve()[e(577)](()=>(tS(),Rx))[e(577)](function(r){return r})}},Ax={};function q(t,e){t=t-308;let r=$o(),i=r[t];if(q.MrbiJX===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",p="",_="";for(let v=0,w,E,I=0;E=f.charAt(I++);~E&&(w=v%4?w*64+E:E,v++%4)?p+=String.fromCharCode(255&w>>(-2*v&6)):0)E=x.indexOf(E);for(let v=0,w=p.length;v<w;v++)_+="%"+("00"+p.charCodeAt(v).toString(16)).slice(-2);return decodeURIComponent(_)};q.swiWFE=o,q.nYaWbU={},q.MrbiJX=!0}let c=r[0],d=t+c,u=q.nYaWbU[d];return u?i=u:(i=q.swiWFE(i),q.nYaWbU[d]=i),i}function Bt(t){let e=L,r={eFxtc:e(592)+"0"},i=r[e(1566)][e(732)]("|"),o=0;for(;;){switch(i[o++]){case"0":return d[e(450)];case"1":var c=Ax[t];continue;case"2":nS[t](d,d[e(450)],Bt);continue;case"3":var d=Ax[t]={exports:{}};continue;case"4":if(c!==void 0)return c[e(450)];continue}break}}(()=>{let t=L,e={cmRyB:function(r,i){return r>>i},huwKK:function(r,i){return r|i},CejGt:function(r,i){return r!==i},mnYCF:t(929)};Bt.d=(r,i)=>{let o=t,c={UzFVU:function(u,f){return e.cmRyB(u,f)},bxGWO:function(u,f){return e[q(689)](u,f)}};if(e[o(974)](o(929),e[o(1619)]))_0x55fa95[_0x341380++]=c[o(1633)](_0x5f3941,6)|192,_0x5750cb[_0x348bd5++]=c.bxGWO(63&_0x56c084,128);else for(var d in i)Bt.o(i,d)&&!Bt.o(r,d)&&Object[o(408)+o(851)](r,d,{enumerable:!0,get:i[d]})}})(),(()=>{let t=L;Bt.o=(e,r)=>Object.prototype["hasOwnPr"+t(851)][t(493)](e,r)})(),(()=>{let t=L,e={jaAZc:function(r,i){return r!=i},QBhze:t(745),ZcRoE:t(479)+"le"};Bt.r=r=>{let i=t;e[i(1113)]("undefined",typeof Symbol)&&Symbol[i(1275)+i(1045)]&&Object[i(408)+i(851)](r,Symbol[i(1275)+"Tag"],{value:e.QBhze}),Object[i(408)+i(851)](r,e[i(976)],{value:!0})}})();var Re={};(()=>{let t=L,e={qxFir:function(a,n){return a(n)},LzdSp:function(a,n){return a+n},rPmje:function(a,n){return a+n},iHWIr:function(a,n){return a*n},LCMnq:function(a,n){return a*n},NkEkc:function(a,n){return a(n)},InmnK:function(a,n){return a+n},dqsfI:function(a,n,s){return a(n,s)},tsxOz:function(a,n){return a(n)},qeWDB:function(a,n){return a+n},yyifE:"0000",LTCSG:t(674),nCCoK:function(a,n){return a(n)},EwpIN:function(a,n){return a(n)},LSbzA:"00000000"+t(1002)+t(1002)+"00000000",YtLRp:"error",vckyb:function(a,n){return a>n},COsTL:function(a,n){return a!==n},qHlXv:t(480),iBjqP:t(1267),kdgjN:function(a,n){return a>n},Tkvmc:function(a,n){return a===n},UEPEZ:"SmJEh",YsTGl:function(a,n){return a<n},TOfjm:"oOoZh",IDdFY:function(a,n){return a-n},ZSpba:function(a,n){return a<n},riqye:function(a,n){return a-n},UtSdN:t(1401),cooCn:"ebGVk",Yhaal:function(a,n){return a!==n},GnBHn:function(a,n,s){return a(n,s)},aDUFv:function(a,n){return a(n)},ZbYRO:function(a,n){return a(n)},qHBxP:function(a,n){return a>>>n},kiSjt:function(a,n,s){return a(n,s)},RURmf:function(a,n){return a&n},InJQx:function(a,n){return a===n},sOePB:t(1727)+t(1644)+t(508)+"key",ZJvQT:function(a){return a()},lDHLR:t(430),LJrUm:t(1594)+"id",kWSKM:function(a,n){return a!==n},BksRV:function(a,n,s){return a(n,s)},HHMDb:function(a,n,s){return a(n,s)},LfwOY:function(a,n){return a!==n},PPmXn:function(a,n,s){return a(n,s)},AFhNd:function(a,n){return a(n)},cwapY:function(a,n,s){return a(n,s)},tYIan:function(a,n){return a(n)},aPhHC:function(a,n){return a!==n},LWzxG:function(a){return a()},IhycZ:function(a,n,s){return a(n,s)},XWnDW:function(a,n,s){return a(n,s)},zQGuB:function(a,n,s){return a(n,s)},uCnVH:t(683),ciYOe:t(1291),oEDXj:function(a,n,s){return a(n,s)},SnHWT:function(a,n,s){return a(n,s)},qgECf:t(1518),lAGaw:function(a,n,s){return a(n,s)},OxwEL:function(a,n){return a!==n},pLxkB:t(1583),NTJhH:"jvZmT",Kemqo:function(a,n,s){return a(n,s)},QmJyy:function(a,n){return a(n)},EcMah:function(a,n){return a(n)},Dizev:function(a,n){return a(n)},DWfZA:function(a,n,s){return a(n,s)},NjCvC:function(a,n){return a(n)},TbiFw:function(a,n,s){return a(n,s)},lsKny:function(a,n){return a(n)},ypapY:function(a,n){return a(n)},sNYTT:function(a,n,s){return a(n,s)},pFhnl:function(a,n){return a(n)},zhMnU:function(a,n,s){return a(n,s)},gaytm:function(a,n){return a&n},yzhMj:function(a,n){return a===n},bZwXZ:function(a,n){return a===n},JcveY:t(1727)+t(1644)+t(508)+t(814),jLiGh:t(1727)+t(1644)+t(508)+"service",XGlXx:"Missing required"+t(508)+t(1414),yzgVS:function(a,n){return a(n)},ysknq:function(a,n,s){return a(n,s)},tlJfr:function(a,n){return a(n)},xuBkb:function(a,n){return a>>n},XxWVU:function(a,n){return a>=n},cdKUX:function(a,n,s,l){return a(n,s,l)},YKYSt:t(1511),VWfIS:"Byggq",dRtTa:t(1130),EskUM:function(a,n){return a+n},QURhO:function(a,n){return a>n},YbwVZ:t(1144)+t(1412),ApMjw:function(a,n){return a+n},LUDBo:function(a,n){return a<n},GBluq:function(a,n){return a===n},EdYin:function(a,n){return a+n},EqJpJ:function(a,n){return a!==n},klyeW:function(a,n){return a<<n},LqtkR:function(a,n){return a&n},Tlxzr:function(a,n){return a==n},gnBaD:function(a,n){return a&n},iNSXp:function(a,n){return a>=n},SXERu:t(781),lpwTB:function(a,n){return a+n},vmeiV:function(a,n){return a+n},ZOmMl:function(a,n){return a+n},YOyUv:function(a,n){return a&n},YkrvC:function(a,n){return a|n},rGoYg:function(a,n){return a|n},rbiPL:function(a,n){return a<<n},NspHb:function(a,n){return a>=n},QNPIm:function(a,n){return a==n},RlBUb:function(a,n){return a&n},TwojU:function(a,n){return a>=n},TzjXk:function(a,n){return a+n},zihYH:function(a,n){return a+n},eljLr:function(a,n){return a+n},GtfVf:function(a,n){return a&n},HpCAB:function(a,n){return a<<n},FRjzN:function(a,n){return a|n},fjIaZ:function(a,n){return a|n},RIsDQ:function(a,n){return a&n},OzIzI:function(a,n){return a&n},SHUJp:function(a,n){return a<n},IXuTy:function(a,n){return a>n},jhvLw:function(a,n){return a+n},vFyjo:function(a,n){return a&n},hHIWe:function(a,n){return a<=n},hqEfR:function(a,n){return a<n},uuzys:function(a,n){return a<<n},mhgjt:function(a,n){return a<n},EUgLi:function(a,n){return a<n},eZgby:function(a,n,s){return a(n,s)},dOxbO:function(a,n){return a<n},IgRUE:function(a,n){return a-n},OrCam:function(a,n){return a<<n},bzwVu:function(a,n){return a<n},YiAVN:function(a,n){return a&n},vYwvW:function(a,n){return a===n},BRYOA:function(a,n){return a<n},GoQie:function(a,n){return a|n},vuOin:function(a,n){return a>>n},vZuWw:function(a,n){return a&n},Ugacw:function(a,n){return a|n},wxYrM:function(a,n){return a&n},jEZON:function(a,n){return a|n},dIssy:function(a,n,s){return a(n,s)},JjhWm:function(a,n,s){return a(n,s)},eQEtn:function(a,n,s){return a(n,s)},kxIPV:t(1075),dPMrU:function(a,n){return a(n)},LPrqg:function(a,n,s){return a(n,s)},vMMUG:function(a,n){return a|n},zExtS:t(719),QCCCS:function(a,n){return a&n},rknva:function(a,n){return a&n},vDRnm:function(a,n){return a&n},TTDFn:"QqdoY",wPDve:function(a,n){return a&n},VzYdA:function(a,n){return a&n},QtRWf:t(1417),yPWas:t(711),qNUQA:function(a,n){return a(n)},VTPJw:t(311),GWvga:function(a,n){return a&n},DDGmA:function(a,n){return a&n},Xhdpd:function(a,n){return a<<n},chKoe:function(a,n){return a(n)},SqEFD:function(a,n){return a&n},NmRFi:function(a,n){return a&n},EhRWg:function(a,n){return a<<n},pAKwV:function(a,n){return a<<n},DDubH:function(a,n){return a>>>n},NfQpp:function(a,n){return a===n},gyqCi:function(a,n){return a===n},YIxog:function(a,n){return a<n},wesHr:function(a,n){return a<n},BeeKO:function(a,n){return a+n},jofik:function(a,n){return a+n},loQbG:function(a,n){return a|n},nnqmz:function(a,n){return a>>>n},DoRjZ:function(a,n){return a|n},HXHaX:function(a,n){return a&n},izFzA:function(a,n){return a>>>n},wrCDV:function(a,n){return a!==n},gEwDm:function(a,n){return a&n},EBnFI:function(a,n){return a|n},jcooZ:function(a,n){return a&n},tTYPM:function(a,n){return a|n},QRGHo:function(a,n){return a!==n},ktmGI:function(a,n){return a|n},brLbp:function(a,n){return a&n},egTQo:function(a,n){return a&n},Giclc:function(a,n){return a|n},RWpmb:function(a,n){return a<<n},buuXq:function(a,n){return a|n},RDylx:function(a,n){return a|n},rDMUm:function(a,n){return a<<n},eQUJv:function(a,n){return a|n},tvDWq:"ViClK",SsCRH:function(a,n){return a===n},HjXGA:function(a,n){return a|n},Tyxqj:function(a,n){return a<<n},VHKLS:function(a,n){return a>>>n},HKPyU:function(a,n){return a<<n},UgOMV:function(a,n){return a<<n},QsZZy:function(a,n){return a>>>n},ibKba:function(a,n){return a&n},SLalx:function(a,n){return a&n},lFLNi:function(a,n){return a>>>n},pEuPV:"kcris",DkzMl:function(a,n){return a(n)},zcErc:function(a,n){return a===n},geGjk:t(720),arSNb:function(a,n){return a<=n},wzLIA:function(a,n){return a>=n},vpWcM:function(a,n){return a+n},bPRBs:function(a,n){return a%n},XUYeS:function(a,n){return a|n},indcA:function(a,n){return a/n},LIYdl:function(a,n){return a*n},pGJPM:function(a,n){return a>>>n},FHXpl:function(a,n){return a>>>n},sexGH:function(a,n){return a*n},OTvmw:function(a,n){return a===n},oljHo:function(a,n){return a===n},SGmBV:function(a,n){return a>>>n},oyOwq:function(a,n){return a>>>n},ygSaS:function(a,n){return a>>>n},tkUbF:function(a,n){return a&n},kbQHW:function(a,n){return a>>>n},zDsZb:function(a,n){return a>>>n},JTQAR:function(a,n){return a|n},SNvpY:function(a,n){return a|n},wdPAK:function(a,n){return a<<n},oyzzB:function(a,n){return a>>>n},fkAWf:function(a,n){return a===n},tOkEB:function(a,n){return a+n},IcZiS:function(a,n){return a&n},iamof:function(a,n){return a>>>n},MGutW:function(a,n){return a&n},qbBVs:function(a,n){return a>>>n},fGrDR:function(a,n){return a&n},rNhDH:function(a,n){return a&n},TLSQG:function(a,n){return a>>>n},PROLf:function(a,n){return a>>>n},nOVlL:function(a,n){return a&n},QgaRC:t(1214)+"3|1",BVDvl:t(1707)+t(1704),JBGpn:t(1281)+"OR",XQTYT:t(466)+t(861),yLRtP:t(1725)+t(698),xkSSb:t(1563)+t(453),kNwav:t(1370)+"1",JfpBI:t(1739),xoFBL:function(a,n){return a!==n},jIfBv:"UfYFH",Ytykb:function(a,n,s){return a(n,s)},uJFOS:"LUkJN",BgNZL:function(a,n){return a===n},hngen:function(a,n){return a===n},wQjdz:function(a,n){return a instanceof n},ibhaC:t(1200)+"d error.",ZyIAi:function(a,n){return a+n},YnIsR:function(a,n){return a>n},cilvK:function(a,n){return a*n},addfd:function(a,n){return a+n},bBpnz:function(a,n){return a===n},gjklm:t(541),nEIXs:function(a,n){return a===n},jPiui:function(a,n){return a!==n},pmbqF:t(1365),LPIyk:function(a,n){return a<n},wHGjI:function(a,n){return a===n},XitwO:t(1582),cxjVZ:function(a,n,s){return a(n,s)},TCkUQ:function(a,n,s){return a(n,s)},rukws:"message",TWMhQ:t(850)+"er_qos",LPrny:t(850)+"er_qos_ack",pDwCf:t(850)+t(1496)+"k",khUYh:function(a,n,s){return a(n,s)},gLZhH:"x_frontier_ack_m"+t(1608),fjBnT:function(a,n){return a===n},HuJKE:t(1425),zUFwX:t(642),IjHiS:"cEIGt",sPiaK:function(a,n){return a!==n},jdJyu:"ZbFkN",PeLqR:"SXBDL",LSGKX:function(a,n){return a||n},ALVfC:function(a,n){return a||n},HBdsp:function(a,n){return a!=n},EcWZs:"undefined",mFGzH:function(a,n){return a>>>n},HZPUe:function(a,n){return a+n},iwpzJ:function(a,n){return a!==n},YSucq:t(1176),QpkwL:t(467)+"0",EjAhI:function(a,n){return a||n},gYghs:"next() c"+t(1439)+t(447)+t(1696)+"process",lpZIk:function(a,n){return a===n},hMbbs:function(a,n){return a+n},LIYfW:function(a,n){return a<n},ARTmK:function(a,n){return a&n},TavCA:t(1375),SJOqj:function(a,n){return a<n},HYWsq:function(a,n){return a&n},fJtoJ:function(a,n){return a<n},fbLLg:function(a,n){return a|n},hEEVT:function(a,n){return a<<n},Jyfsn:function(a,n){return a&n},pSONA:function(a,n){return a-n},VEhHM:function(a,n){return a|n},ElfmU:function(a,n){return a|n},Bquxz:"ylBvd",dgdCV:function(a,n){return a|n},aSzGH:function(a,n){return a===n},AWFVk:function(a,n){return a+n},rhtpd:function(a,n){return a&n},naJwf:function(a,n){return a>>n},GAtNV:function(a,n){return a&n},UgjZt:function(a,n){return a|n},gTNaB:function(a,n){return a&n},NYGfh:function(a,n){return a>>n},eBrMc:function(a,n){return a|n},ApbnM:t(1540),zskSL:function(a,n,s,l){return a(n,s,l)},ZRxGf:function(a,n){return a instanceof n},BHSRU:function(a,n){return a!=n},dvrZU:t(1251),UBrZC:t(1168)+"in;chars"+t(1497),Rugpi:t(1366),ggVCV:function(a,n){return a===n},LuLzT:t(1600),QPylk:function(a,n,s){return a(n,s)},QRwrH:function(a,n){return a!==n},bETPx:function(a,n){return a>=n},CUniM:t(1599)+t(1677),SYbby:"text/jav"+t(1094),jcGnp:function(a,n){return a+n},isLyh:t(1390),ctLCx:t(866)+"ack=fron"+t(507)+"P",mvBrL:function(a,n){return a===n},hXdbp:t(611),xYuZE:function(a,n){return a(n)},rCMPs:t(1072),lEcFn:function(a,n,s){return a(n,s)},CyKjc:function(a,n){return a!==n},qleMW:t(608),rrLwJ:t(912),GtvTh:function(a,n){return a<n},byVnG:function(a,n){return a>n},oqsyx:function(a,n){return a&n},yxvGB:function(a,n){return a>>>n},kVCnA:function(a,n){return a!==n},QDOOr:t(1076),aNRSv:function(a){return a()},sDUwk:"zgbDs",nqudU:t(832),xTVQi:function(a,n){return a+n},jSZyb:"iNgDC",ZDSHT:"EeauO",jizts:function(a,n){return a&n},owDNv:function(a,n){return a>>>n},KgLbA:function(a,n){return a>>>n},DOkcD:function(a,n){return a!==n},bUpBN:t(1110),pYJoV:function(a,n){return a||n},oIRUA:function(a,n){return a===n},bLUul:"ZdysI",FfUkD:function(a,n){return a||n},YkdEt:function(a,n){return a!=n},Gxamu:t(745),luneD:"__esModule",cMIXK:function(a,n){return a===n},tkiJV:t(501),xExGb:function(a,n){return a!=n},ryPxv:t(625)+"DB failed",JjtzQ:function(a,n,s){return a(n,s)},Fhwzv:function(a,n){return a<=n},GEMLo:function(a,n){return a|n},EpQMX:function(a,n){return a&n},sxxhR:function(a,n){return a&n},kShPl:function(a,n){return a|n},uQJnT:function(a,n){return a&n},zcfPk:function(a,n){return a&n},cbyti:function(a,n){return a===n},DsbAb:t(1242),arUsZ:t(784),mMKLB:function(a,n){return a instanceof n},EehOY:t(1175)+t(921),qYYfe:t(1175)+t(921)+t(742)+"=utf-8",jXDQx:t(439)+"e",UJXFT:t(1268),OzDAx:function(a,n,s,l){return a(n,s,l)},WMmIk:"tbAPl",MHPaP:function(a,n,s,l){return a(n,s,l)},juXRq:function(a,n,s){return a(n,s)},fOVhZ:t(344),GyNWz:function(a,n,s,l){return a(n,s,l)},sBZBQ:t(1451),yIuvo:function(a,n){return a&&n},hqxEX:"ack_id",hnEPk:"ack_code",yauie:function(a){return a()},pXExj:t(1376),yzjXl:function(a,n,s){return a(n,s)},qtXHD:function(a,n){return a(n)},ukFhh:t(1524),KZCpR:t(1506),vEvzS:function(a,n){return a instanceof n},wGBKM:function(a,n){return a instanceof n},qALFp:t(840),XNPef:function(a,n){return a<n},wnVlq:function(a,n){return a(n)},kZXvS:function(a,n){return a>n},MmsoQ:function(a,n){return a&n},CopLj:function(a,n){return a|n},DBrYO:function(a,n){return a(n)},WHuPu:function(a,n){return a+n},FXUan:function(a,n){return a+n},yAOzo:t(1597)+t(1152)+t(1626),CbtjX:t(556),DdqSR:" > ",RDMRO:function(a,n){return a===n},dsipm:t(1682),jQajC:function(a,n){return a>n},DtboL:t(991)+t(1746)+"e",bpGgP:function(a,n){return a<n},uibyr:function(a,n,s){return a(n,s)},ntEHd:function(a,n){return a<<n},OnYkA:"0|2|1|4|3",aTyYp:function(a,n){return a!==n},bNlZH:t(589),XJbjY:function(a,n){return a<<n},czfeL:function(a,n){return a+n},YWmbX:function(a,n){return a|n},bambQ:function(a,n){return a|n},flWVe:function(a,n){return a<<n},PAgHj:function(a,n){return a+n},cqTLL:function(a,n){return a<<n},OGRLa:function(a,n){return a+n},NNSdw:function(a,n){return a+n},HrAyM:function(a,n){return a+n},NOBHR:function(a,n){return a>>>n},HQfSJ:function(a,n){return a+n},MoRBZ:function(a,n){return a+n},rztcT:function(a,n){return a>>>n},bpDBo:function(a,n){return a+n},EpWGx:function(a,n){return a|n},fCnLq:function(a,n){return a&n},ajSiQ:function(a,n){return a>>>n},ElXal:function(a,n){return a&n},BxfBx:function(a,n){return a|n},TCFCx:function(a,n){return a<<n},HyaXL:function(a,n){return a&n},HOfpp:function(a,n){return a|n},SKDrd:function(a,n){return a|n},TsjPg:function(a,n){return a&n},rRtoh:function(a,n){return a<<n},LcXGg:function(a,n){return a===n},FzZwe:t(780),duPkE:function(a,n,s,l){return a(n,s,l)},ntTPk:t(1256),zkTiL:"name",UvWxO:function(a,n,s,l){return a(n,s,l)},gbMGx:"service",yqzZC:t(364)+t(731),hxBWl:t(310)+t(956),jpaCz:"header",WCYXA:function(a,n){return a-n},mEWJr:function(a,n){return a<n},tWHYL:function(a,n){return a!==n},HfTfB:t(1687),mLLxI:"cursor_name",rCLTz:t(377)+"rValues",gWTzc:"ALL",ZitUO:t(1668),mWwnW:function(a,n,s,l){return a(n,s,l)},Ljqix:function(a,n){return a(n)},RqRNL:t(1726)+"r",deTMD:"MQYbm",MiVwo:function(a,n,s,l){return a(n,s,l)},IqiXx:t(882),QjVWB:function(a,n,s){return a(n,s)},hDUix:t(850)+t(1314),ysCya:function(a,n){return a(n)},wzxgf:t(850)+"er_ttl",cRCeK:function(a){return a()},pOjSC:function(a,n){return a>n},Fguop:function(a,n){return a!==n},bYAip:t(897),uozay:t(1650),CzMXe:function(a,n){return a+n},kmulL:function(a){return a()},VUuRu:function(a,n){return a<n},OIBrk:function(a){return a()},MbTVj:function(a){return a()},vYTFC:function(a,n){return a===n},OVucn:function(a,n,s){return a(n,s)},YuwPD:"XqaBH",iRIXL:function(a){return a()},ZLbRQ:function(a,n){return a!==n},hAghy:function(a,n){return a===n},PUjBq:"wCQvh",LgGWX:function(a,n,s){return a(n,s)},uWEhi:function(a){return a()},VLeyn:t(907),rmgdm:function(a,n){return a===n},mnmqU:"auto",ayROH:"ping_onc"+t(747)+"s",ODfMA:"success",OSUEB:function(a,n){return a===n},rjRbV:t(1367),VIrPT:function(a,n,s,l){return a(n,s,l)},sKLyN:function(a,n){return a===n},rWOTf:function(a,n,s){return a(n,s)},kRqKU:t(1534),Dohep:function(a,n){return a!==n},ecjEm:t(686),TZopO:function(a,n,s){return a(n,s)},rlcko:function(a,n,s){return a(n,s)},aTsTk:t(555),woCfI:function(a,n,s){return a(n,s)},VyoXa:function(a,n,s){return a(n,s)},lCgJL:t(755)+t(684),SJdEN:"CONTINUE",uKSBs:function(a,n){return a==n},PKOCt:function(a,n){return a(n)},GGuTb:t(1127)+"rovide w"+t(707)+t(836)+t(1637)+t(475)+"is undef"+t(382),ytNpE:"done",tCmxt:function(a,n){return a in n},GdExi:function(a,n){return a===n},VUSDA:t(1762),GGQnx:function(a,n,s){return a(n,s)},jqVjq:"reconnect",NYsKh:t(1053)+t(531)+t(1115)+"ct",DBzXS:"online",uxeRj:t(494),CQeTg:t(1587),WoiYG:t(639),QiNxQ:function(a,n){return a==n},DATUa:t(712),gkbNn:t(1098),uHSqu:"bd_did",DUSEb:t(904),IliIo:function(a,n){return a==n},hdkcQ:function(a){return a()},QqWNL:t(1741)+"0",vHViS:function(a,n){return a>=n},Xxwvg:function(a,n,s){return a(n,s)},ECitH:t(313),nJiNK:function(a,n,s){return a(n,s)},iftpk:function(a,n,s){return a(n,s)},uaivB:function(a,n,s){return a(n,s)},Ejlof:function(a,n){return a(n)},VqVqY:function(a,n){return a(n)},rYypQ:function(a,n){return a===n},bKcrx:t(590),RKBDS:t(680),MLaRF:t(1574)+">",HPwcS:function(a,n){return a-n},NHGjO:function(a,n){return a>n},oRNdi:function(a,n){return a===n},EvNTa:function(a,n,s){return a(n,s)},VIoXu:t(1004)+t(908)+"t",SdIqe:t(913),sXWvX:t(1530)+"ay, try reconnec"+t(902)+t(391),gEUyS:function(a,n,s){return a(n,s)},NMKyK:"timeout,"+t(1379)+t(557)+"g",epZgs:function(a,n){return a(n)},csmRn:function(a,n){return a===n},wUPXp:t(340),GmJlH:t(1659),iLUQn:function(a,n,s){return a(n,s)},MOLWU:function(a,n,s){return a(n,s)},lKzOu:function(a,n,s){return a(n,s)},zEbsX:t(1530)+"ay, netw"+t(1546)+t(1752),KDgPO:function(a,n){return a===n},QdmHy:"ZnQdB",PMWJJ:t(1134),CHXDz:t(348),ABpHL:function(a,n){return a!==n},qozdQ:t(316),PubxL:t(1419)+t(425),HEOUY:"close, w"+t(1028)+t(1700),XLWsP:t(774)+t(567)+"ce not i"+t(1104)+"ed",lnghh:t(1127)+t(1010)+t(1138)+t(1616)+t(376)+t(524)+t(1528)+" arraybuffer",diBHW:function(a,n){return a instanceof n},iscNL:function(a,n){return a(n)},UsZjk:function(a,n){return a||n},trpvj:t(1127)+t(1010)+t(1731)+t(956),rLqMv:function(a,n){return a instanceof n},KjCwm:function(a,n){return a instanceof n},cqihC:t(1239),nEZOA:function(a,n){return a!==n},sIiLV:t(735),rRWWB:function(a,n){return a(n)},PsHgU:function(a,n){return a!==n},CyPUf:function(a,n){return a===n},PvOhO:t(419),MOIDc:function(a,n){return a!==n},FwloG:"rSGac",iysNc:t(718)+"3",CaxaQ:function(a,n){return a>>>n},KbPyp:function(a,n){return a<n},NaZBL:function(a,n){return a|n},nLZjt:function(a,n){return a<n},IGbQU:function(a,n,s,l){return a(n,s,l)},DohCF:function(a,n){return a|n},YQqZs:t(527),pvINi:t(1549),hxvDV:t(1082),nmvej:t(510),LXQGK:t(1484),wlQce:function(a,n){return a*n},UbpSr:function(a,n){return a===n},zbzkv:"Window",owLWx:function(a,n){return a===n},vUuLk:"DedicatedWorkerG"+t(874)+"pe",kkVGk:function(a,n){return a!=n},spwfM:function(a,n){return a===n},TxQdZ:function(a,n){return a!=n},osSMP:function(a,n){return a===n},RKZNr:function(a,n){return a===n},fPopp:t(394)+t(754)+t(1512),SGlmJ:function(a,n){return a===n},eEurm:function(a,n){return a===n},AEkyY:function(a,n){return a===n},PeTEp:"Object",HwFUK:function(a,n,s){return a(n,s)},makpf:t(1500)+"qos__"};Bt.r(Re),Bt.d(Re,{FWS:()=>hg,CustomErrorEvent:()=>Qd,createCloseEvent:()=>gt,ReconnectEvent:()=>Xd,createErrorEvent:()=>dt,decodedFrame:()=>en,createOpenEvent:()=>sl,CustomCloseEvent:()=>el,createReconnectEvent:()=>la,FrontierMessageEvent:()=>nl,encodeFrame:()=>zt,createMessageEvent:()=>il,OpenEvent:()=>rl,ErrorCode:()=>nn,Event:()=>tr,MessageEvent:()=>tl});let r="";function i(a=""){let n=t,s="02",l=""+Date.now(),h=r||(r=e[n(578)](f,a)),g=Math[n(633)]().toString(16)[n(901)](-6);return e[n(727)](e[n(1107)](e[n(727)](s,l),h),g)}function o(){let a=t;return e[a(727)](e[a(1154)](1e4,Date[a(768)]()),Math[a(457)](e[a(1171)](1e4,Math.random())))}function c(a){let n=t;return(e[n(1261)](Array,8)[n(1013)]("0")+parseInt(a,10)[n(1275)](2)).slice(-8)}function d(a){let n=t;return e[n(623)](e[n(578)](Array,4)[n(1013)]("0"),e[n(1139)](parseInt,a,2)[n(1275)](16))[n(901)](-4)}function u(a){let n=t,s=a.split(/\./)[n(841)](g=>c(g)),l=[];return l[0]=e.tsxOz(d,e[n(623)](s[0],s[1])),l[1]=e.tsxOz(d,e[n(1455)](s[2],s[3])),[e[n(964)],e[n(964)],e[n(964)],e[n(964)],e.yyifE,e[n(631)],l[0],l[1]].join("")}function f(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(a),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(a);return s?e[n(1525)](u,a):l?e[n(1499)](x,a):e[n(1605)]}function x(a){let n=t,s={tobXB:function(l,h){return e.vckyb(l,h)},GFeoz:function(l,h){return e.rPmje(l,h)}};if(e.COsTL(e[n(969)],e[n(1088)])){let l="",h=[],g=0,S=0,b=!0,m=e[n(964)];if(e[n(1212)](a[n(1354)]("::"),-1))if(e[n(482)](e[n(721)],e[n(721)])){let R=a[n(732)]("::");for(let F=0;e[n(909)](F,R[n(460)]);F++)if(e.Tkvmc("vzyRN",e[n(1296)])){let V=e[n(1139)](_0x2518d0,e[n(327)],{message:_0x4bd495.message,code:_0xc35eb3[n(1281)+"OR"],error:_0x1f698c});this[n(373)+n(1591)+n(1342)](V)}else{let V=R[F];if(V.indexOf(":")>0){let $=V.split(":");b&&(g=$[n(460)]),S+=$.length;for(let pe=0;e[n(909)](pe,$[n(460)]);pe++)if(e[n(770)](4,$[pe][n(460)])){let rt=m[n(458)+"g"](0,e[n(833)](4,$[pe][n(460)])),$e=rt.concat($[pe]);h[n(1017)]($e)}else h[n(1017)]($[pe]);b=!1}else{if(V[n(460)]!==4){let $=m[n(458)+"g"](0,4-V.length),pe=$[n(1153)](V);h[n(1017)](pe)}else h[n(1017)](V);b&&(g+=1),S+=1,b=!1}}let B="";for(let F=0;e[n(1665)](F,e[n(571)](8,S));F++)B=B[n(1153)](m);for(let F=0;e.YsTGl(F,h[n(460)]);F++)e[n(482)](F,g)?(l=l[n(1153)](B),l=l[n(1153)](h[F])):l=l.concat(h[F]);return l}else try{return!!this[n(1038)]}catch(R){return _0x4fd47a[n(1164)](R),!1}{let R=a.split(":");for(let B=0;e[n(909)](B,R.length);B++){let F=R[B];if(e[n(770)](4,R[B][n(460)]))if(e[n(770)](e[n(714)],e.cooCn)){let V=m[n(458)+"g"](0,e[n(571)](4,R[B][n(460)])),$=V[n(1153)](F);l=l[n(1153)]($)}else return;else l=l[n(1153)](F)}return l}}else{if(s[n(552)](s[n(980)](_0x3a2f9d.offset,_0x130e89),_0x1cfcda[n(317)]))throw new _0x4e8f02(n(984)+n(1412));_0x29cdd6[n(690)]+=_0x1a818e}}function p(a,n){let s=t,l=a.key;e.Yhaal(void 0,l)&&(xe(n,10),e[s(1139)](U,n,l));let h=a[s(1536)];e[s(770)](void 0,h)&&(e[s(1139)](xe,n,18),e[s(1717)](U,n,h))}function _(a){let n=t,s={};e:for(;!e[n(1364)](K,a);){let l=e[n(409)](he,a);switch(e[n(320)](l,3)){case 0:break e;case 1:s[n(1458)]=e.dqsfI(P,a,e[n(1499)](he,a));break;case 2:s[n(1536)]=P(a,e.ZbYRO(he,a));break;default:e[n(395)](T,a,e[n(1089)](7,l))}}if(e[n(1312)](void 0,s[n(1458)]))throw new Error(e[n(939)]);if(e[n(482)](void 0,s.value))throw new Error("Missing "+n(1644)+n(508)+n(1536));return s}function v(a){let n=t,s=e[n(1297)](C);return e.GnBHn(w,a,s),e.qxFir(N,s)}function w(a,n){let s=t,l={TlITS:function($e,it){return $e-it},XNsSu:function($e,it){return $e*it}},h=a.SeqID;e[s(829)](void 0,h)&&(e.BksRV(xe,n,8),e.kiSjt(pt,n,h));let g=a[s(814)];g!==void 0&&(e[s(395)](xe,n,16),e[s(1262)](pt,n,g));let S=a.service;e[s(1234)](void 0,S)&&(e.dqsfI(xe,n,24),e.PPmXn(pt,n,e.AFhNd(D,S)));let b=a[s(1414)];e[s(770)](void 0,b)&&(e[s(395)](xe,n,32),e[s(437)](pt,n,e[s(1129)](D,b)));let m=a.headers;if(e[s(1570)](void 0,m))for(let $e of m){e[s(1139)](xe,n,42);let it=e[s(1084)](C);e[s(1554)](p,$e,it),e.XWnDW(xe,n,it[s(317)]),e[s(1516)](j,n,it),O(it)}let R=a["payloadE"+s(952)];if(R!==void 0)if(e[s(1312)](e[s(651)],e[s(746)])){if(_0x594ae1[s(460)]!==4){let $e=_0x35f03e[s(458)+"g"](0,YIMmMI.TlITS(4,_0x449c22[s(460)])),it=$e.concat(_0x556b66);_0x583eda[s(1017)](it)}else _0xcd7ab4[s(1017)](_0x62dac9);_0x41b201&&(_0xf66efb+=1),_0x2157af+=1,_0x159952=!1}else e[s(1310)](xe,n,50),e[s(403)](U,n,R);let B=a[s(1545)+"ype"];e[s(829)](void 0,B)&&(xe(n,58),e[s(831)](U,n,B));let F=a[s(610)];if(F!==void 0)if(e[s(1312)](e[s(1672)],e[s(1672)]))e[s(1287)](xe,n,66),e[s(1516)](xe,n,F[s(460)]),se(n,F);else{let $e=new _0x1c5aa5(l[s(1394)](2,_0x13fc64));$e[s(1744)](_0x56c2cb),_0x269e93[s(640)]=$e}let V=a[s(884)];e[s(1701)](void 0,V)&&(e[s(482)](e[s(321)],e[s(343)])?(this[s(1751)+s(354)+"Id"]=null,this._interval=36e5,this._qosDB=e[s(1139)](_0x2cb56c,e[s(374)],e.LJrUm)):(e[s(1236)](xe,n,74),e[s(765)](U,n,V)));let $=a["serverTi"+s(1059)];e[s(1570)](void 0,$)&&(e.dqsfI(xe,n,82),e[s(831)](U,n,$));let pe=a[s(1246)];pe!==void 0&&(e[s(1287)](xe,n,90),U(n,pe));let rt=a[s(1325)+"e"];e.OxwEL(void 0,rt)&&(e[s(437)](xe,n,96),e[s(403)](pt,n,e.EwpIN(D,rt)))}function E(a){return I(e.nCCoK(M,a))}function I(a){let n=t,s={};e:for(;!K(a);){let l=e[n(1364)](he,a);switch(e[n(320)](l,3)){case 0:break e;case 1:s[n(800)]=It(a,!0);break;case 2:s[n(814)]=e[n(1310)](It,a,!0);break;case 3:s[n(554)]=e[n(420)](he,a);break;case 4:s[n(1414)]=e[n(409)](he,a);break;case 5:{let h=e[n(844)](A,a);(s.headers||(s[n(1292)]=[]))[n(1017)](e[n(1432)](_,a)),a.limit=h;break}case 6:s["payloadE"+n(952)]=e[n(1717)](P,a,e[n(790)](he,a));break;case 7:s[n(1545)+n(1117)]=e[n(848)](P,a,e[n(652)](he,a));break;case 8:s[n(610)]=e[n(1629)](ie,a,e[n(1364)](he,a));break;case 9:s[n(884)]=e[n(1717)](P,a,e.lsKny(he,a));break;case 10:s[n(860)+n(1059)]=e[n(848)](P,a,e.ypapY(he,a));break;case 11:s.msgID=e[n(1459)](P,a,e.tsxOz(he,a));break;case 12:s.frameType=e[n(1683)](he,a);break;default:e[n(1051)](T,a,e[n(346)](7,l))}}if(e[n(1080)](void 0,s[n(800)]))throw new Error(n(1727)+"required"+n(508)+n(800));if(e[n(1317)](void 0,s[n(814)]))throw new Error(e[n(867)]);if(e[n(1080)](void 0,s[n(554)]))throw new Error(e[n(1603)]);if(e.bZwXZ(void 0,s[n(1414)]))throw new Error(e[n(660)]);return s}function A(a){let n=t,s=e[n(578)](he,a),l=a[n(317)];return a[n(317)]=e.rPmje(a.offset,s),l}function T(a,n){let s=t;switch(n){case 0:for(;e[s(346)](128,e[s(826)](ee,a)););break;case 2:e[s(724)](Z,a,e[s(1647)](he,a));break;case 5:e[s(765)](Z,a,4);break;case 1:e[s(1262)](Z,a,8);break;default:throw new Error(e[s(727)]("Unimplemented ty"+s(749),n))}}function D(a){let n=t;return a|=0,{low:a,high:e[n(1103)](a,31),unsigned:e[n(1568)](a,0)}}let y=[];function C(){let a=t,n=y[a(1108)]();return n?(n[a(690)]=n[a(317)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){y[t(1017)](a)}function M(a){return{bytes:a,offset:0,limit:a.length}}function N(a){let n=t,s=a[n(640)],l=a[n(317)];return s[n(460)]===l?s:s[n(1066)](0,l)}function Z(a,n){let s=t,l={nQhZq:function(h,g,S,b){return e[q(418)](h,g,S,b)},dmIEk:"error"};if(e.yzhMj(e.YKYSt,e.VWfIS))try{l[s(1542)](_0xc4a26b,this,_0xd61d70,[_0x52c122,_0x354596,_0x5f1db0])}catch(h){let g=_0x3c7927(l.dmIEk,{message:h[s(464)],code:_0x1b36c4.OPEN_ERROR,error:h});this["_dispatc"+s(1591)+s(1342)](g)}else{if(e.kdgjN(a[s(690)]+n,a[s(317)]))throw new Error(s(984)+s(1412));a.offset+=n}}function K(a){let n=t;return a[n(690)]>=a[n(317)]}function ne(a,n){let s=t;if(e[s(743)]!==e[s(743)])return this._socket.readyState;{let l=a[s(640)],h=a[s(690)],g=a.limit,S=e[s(892)](h,n);if(e[s(1212)](S,l[s(460)])){let b=new Uint8Array(e[s(1171)](2,S));b[s(1744)](l),a.bytes=b}return a.offset=S,e[s(1550)](S,g)&&(a.limit=S),h}}function Y(a,n){let s=t,l=a[s(690)];if(e[s(1212)](e[s(1455)](l,n),a[s(317)]))throw new Error(e[s(1418)]);return a[s(690)]+=n,l}function ie(a,n){let s=t,l=e[s(1717)](Y,a,n);return a.bytes[s(1066)](l,e[s(499)](l,n))}function se(a,n){let s=t,l=ne(a,n[s(460)]);a[s(640)].set(n,l)}function P(a,n){let s=t,l=e[s(1629)](Y,a,n),h=String["fromChar"+s(1135)],g=a[s(640)],S="\uFFFD",b="";for(let m=0;e[s(598)](m,n);m++){let R=g[m+l],B,F,V,$;if(e[s(617)](128&R,0))b+=e[s(1595)](h,R);else if(e[s(1089)](224,R)===192)e[s(1568)](e[s(623)](m,1),n)?b+=S:(B=g[e[s(1455)](e[s(369)](m,l),1)],e[s(1736)](192&B,128)?b+=S:($=e[s(1402)](e.LqtkR(31,R),6)|e.RURmf(63,B),e[s(909)]($,128)?b+=S:(b+=h($),m++)));else if(e[s(1442)](e.gnBaD(240,R),224))if(e[s(1681)](m+2,n))b+=S;else{if(e[s(617)](e[s(669)],s(1645)))return this._ws?this[s(1033)][s(1019)]:"";B=g[e[s(653)](m,l)+1],F=g[e[s(910)](e[s(402)](m,l),2)],e[s(1141)](e[s(1119)](B,F<<8),49344)!==32896?b+=S:($=e[s(1029)](e[s(1029)]((15&R)<<12,e[s(760)](e[s(1748)](63,B),6)),e[s(1141)](63,F)),e[s(598)]($,2048)||e[s(1503)]($,55296)&&$<=57343?b+=S:(b+=e[s(1261)](h,$),m+=2))}else e[s(1217)](e.RlBUb(248,R),240)?e[s(679)](e[s(1311)](m,3),n)?b+=S:(B=g[e[s(402)](m,l)+1],F=g[e[s(548)](m+l,2)],V=g[e[s(481)](e[s(727)](m,l),3)],e.Yhaal(e[s(1071)](e[s(1029)](B|e[s(1402)](F,8),e.HpCAB(V,16)),12632256),8421504)?b+=S:($=e[s(1119)](e[s(1670)](e[s(794)](e[s(1111)](7,R)<<18,e[s(828)](63,B)<<12),e[s(1142)](63&F,6)),e[s(341)](63,V)),e[s(534)]($,65536)||e[s(859)]($,1114111)?b+=S:($-=65536,b+=e.HHMDb(h,e[s(727)](e[s(1103)]($,10),55296),e[s(779)](e.vFyjo(1023,$),56320)),m+=3))):b+=S}return b}function U(a,n){let s=t,l=n[s(460)],h=0;for(let b=0;b<l;b++){let m=n[s(1046)+"At"](b);e[s(1503)](m,55296)&&e[s(1e3)](m,56319)&&e[s(650)](e[s(727)](b,1),l)&&(m=e[s(833)](e[s(369)](e[s(627)](m,10),n[s(1046)+"At"](++b)),56613888)),h+=e.hqEfR(m,128)?1:e[s(947)](m,2048)?2:e[s(987)](m,65536)?3:4}e[s(1073)](xe,a,h);let g=e[s(1717)](ne,a,h),S=a[s(640)];for(let b=0;b<l;b++){let m=n[s(1046)+"At"](b);e.XxWVU(m,55296)&&m<=56319&&e[s(490)](e.jhvLw(b,1),l)&&(m=e[s(1560)](e[s(1515)](m,10)+n[s(1046)+"At"](++b),56613888)),e.bzwVu(m,128)?S[g++]=m:(e[s(534)](m,2048)?S[g++]=e[s(803)](e[s(1103)](m,6),31)|192:e[s(1709)](s(962),"yXMxL")?(e.BRYOA(m,65536)?S[g++]=e[s(1576)](e[s(365)](m,12)&15,224):(S[g++]=e.FRjzN(e[s(472)](e[s(1103)](m,18),7),240),S[g++]=e[s(1109)](e[s(1306)](e.xuBkb(m,12),63),128)),S[g++]=e[s(1029)](e[s(365)](m,6)&63,128)):!this[s(485)+"Lock"]&&(this[s(542)+s(879)]?.[s(978)+"pointCon"+s(585)](),this[s(945)+s(1270)]?.["resetCou"+s(1186)](),this[s(791)+"osed"]=!1,this[s(604)]=!0,this[s(485)]()),S[g++]=e[s(456)](e[s(341)](63,m),128))}}function j(a,n){let s=t,l=e[s(433)](ne,a,n[s(317)]),h=a.bytes,g=n[s(640)];for(let S=0,b=n[s(317)];e.LUDBo(S,b);S++)h[S+l]=g[S]}function ee(a){return a[t(640)][Y(a,1)]}function Xe(a,n){let s=t,l=e[s(437)](ne,a,1);a[s(640)][l]=n}function he(a){let n=t,s=0,l=0,h;do n(1075)!==e[n(1156)]?(e[n(927)](_0x88785d,_0x2a5514,50),e.eQEtn(_0x18e20e,_0x2f651a,_0xd01713)):(h=e[n(834)](ee,a),s<32&&(l|=(127&h)<<s),s+=7);while(e[n(346)](128,h));return l}function xe(a,n){let s=t;for(n>>>=0;e[s(1681)](n,128);)e[s(1565)](Xe,a,e[s(1613)](e[s(346)](127,n),128)),n>>>=7;e[s(1139)](Xe,a,n)}function It(a,n){let s=t,l={dkBZY:e[s(1274)],ctvhj:function(m,R){return e[s(436)](m,R)},zOpgv:function(m,R){return m&R},MXavu:function(m,R){return m>>>R},FZiEv:function(m,R){return e[s(1257)](m,R)},XYLlC:function(m,R){return e[s(320)](m,R)}},h=0,g=0,S=0,b;if(b=e[s(420)](ee,a),h=e[s(401)](127,b),128&b){if(e[s(1322)]!==e.TTDFn)this.emit(l[s(1469)],_0x352f50),this[s(1610)+"eAck"]&&this["onReceiv"+s(323)](_0x55e47b);else if(b=e[s(1499)](ee,a),h|=e[s(1142)](e[s(1477)](127,b),7),e.VzYdA(128,b))if(e[s(1317)](e[s(446)],e[s(934)])){let m=this[s(1335)],R=this[s(1324)];return[255&R,l[s(1509)](R>>>8,255),l[s(1218)](l.MXavu(R,16),255),l[s(325)](R,24),l[s(758)](255,m),l[s(1218)](l.XYLlC(m,8),255),l[s(440)](m,16)&255,m>>>24]}else b=e[s(409)](ee,a),h|=e[s(760)](127&b,14),e[s(1748)](128,b)&&(b=e[s(529)](ee,a),h|=e.HpCAB(e[s(1306)](127,b),21),e.vDRnm(128,b)&&(s(311)===e.VTPJw?(b=e[s(420)](ee,a),g=127&b,e[s(1477)](128,b)&&(b=ee(a),g|=e[s(1081)](127,b)<<7,e.DDGmA(128,b)&&(b=ee(a),g|=e[s(1240)](e[s(1141)](127,b),14),e.YiAVN(128,b)&&(b=e[s(357)](ee,a),g|=e[s(341)](127,b)<<21,e.YiAVN(128,b)&&(b=ee(a),S=e[s(1313)](127,b),e[s(1399)](128,b)&&(b=ee(a),S|=(127&b)<<7)))))):this[s(776)]&&this[s(776)].close({code:_0x34d4fd,reason:_0x56944e})))}return{low:e[s(1613)](h,e[s(498)](g,28)),high:e[s(1029)](e[s(320)](g,4),S<<24),unsigned:n}}function pt(a,n){let s=t,l=e.qHBxP(n[s(1324)],0),h=e[s(1670)](e[s(320)](n[s(1324)],28),e[s(994)](n[s(1335)],4))>>>0,g=e[s(1585)](n[s(1335)],24),S=e[s(544)](0,g)?e[s(961)](0,h)?l<16384?l<128?1:2:e.EUgLi(l,2097152)?3:4:e[s(788)](h,16384)?e[s(1679)](h,128)?5:6:e[s(1679)](h,2097152)?7:8:e[s(490)](g,128)?9:10,b=ne(a,S),m=a[s(640)];switch(S){case 10:m[e.InmnK(b,9)]=e[s(828)](e[s(1585)](g,7),1);case 9:m[e[s(1691)](b,8)]=e[s(829)](9,S)?e[s(456)](128,g):127&g;case 8:m[e[s(971)](b,7)]=e[s(829)](8,S)?e.loQbG(e[s(1688)](h,21),128):h>>>21&127;case 7:m[e[s(779)](b,6)]=S!==7?e[s(1252)](e.DDubH(h,14),128):e[s(1468)](e.izFzA(h,14),127);case 6:m[e[s(481)](b,5)]=e[s(1701)](6,S)?e[s(1670)](h>>>7,128):e[s(1468)](h>>>7,127);case 5:m[b+4]=e.wrCDV(5,S)?128|h:e.gEwDm(127,h);case 4:m[b+3]=S!==4?e[s(1078)](e[s(320)](l,21),128):e[s(1360)](e.nnqmz(l,21),127);case 3:m[b+2]=e.COsTL(3,S)?e[s(668)](e[s(1585)](l,14),128):e[s(820)](l>>>14,127);case 2:m[e[s(779)](b,1)]=e[s(334)](2,S)?e[s(1712)](l>>>7,128):e[s(1593)](e[s(1272)](l,7),127);case 1:m[b]=e.OxwEL(1,S)?e[s(668)](128,l):e[s(1079)](127,l)}}function en(a){return E(a)}function zt(a){return v(a)}let tn=65536,Jr=e[t(414)],we=e[t(1171)](tn,tn),Ie=e[t(1243)](we,we),er=e[t(700)](Ie,2),Pe=String.prototype[t(1046)+"At"];class ue{constructor(n,s,l){let h=t;this[h(883)]=!0,this[h(1324)]=0|n,this[h(1335)]=0|s,this[h(963)]=!!l}static isLong(n){let s=t;return n&&e[s(617)](!0,n[s(883)])}static[t(1388)](n,s,l){return new ue(n,s,l)}static[t(1420)+"s"](n,s,l){let h=t;return l?ue[h(1420)+h(326)](n,s):ue[h(1420)+h(1631)](n,s)}static[t(1420)+t(326)](n,s){let l=t;return new ue(e[l(1504)](n[0]|e[l(1328)](n[1],8)|e.rbiPL(n[2],16),e[l(760)](n[3],24)),e[l(398)](e.Giclc(n[4],n[5]<<8),n[6]<<16)|e[l(1142)](n[7],24),s)}static[t(1420)+t(1631)](n,s){let l=t;return new ue(e.buuXq(e[l(599)](e[l(665)](n[4],24),e[l(1515)](n[5],16))|n[6]<<8,n[7]),e[l(1576)](e[l(1041)](e[l(1328)](n[0],24),e[l(498)](n[1],16)),n[2]<<8)|n[3],s)}static[t(1737)](n){let s=t;if(e[s(1519)]===s(1247))return e[s(1159)](n,Jr)?Yd:new ue(e.DDubH(e[s(380)](e[s(1109)](e.ktmGI(Pe[s(493)](n,0),Pe.call(n,1)<<8),e[s(370)](Pe[s(493)](n,2),16)),Pe.call(n,3)<<24),0),e[s(593)](e.Ugacw(e.FRjzN(Pe[s(493)](n,4),e.HKPyU(Pe[s(493)](n,5),8)),e[s(371)](Pe[s(493)](n,6),16))|Pe[s(493)](n,7)<<24,0),!0);try{this[s(1033)]&&this[s(1033)][s(1739)](_0x55650a,_0x4a7f16)}catch{}}[t(813)](){let n=t;return String["fromChar"+n(1135)](e[n(1011)](255,this[n(1324)]),e.QsZZy(this.low,8)&255,e[n(528)](e[n(536)](this[n(1324)],16),255),e[n(1688)](this[n(1324)],24),e.HXHaX(255,this[n(1335)]),e[n(1272)](this[n(1335)],8)&255,e[n(1567)](e[n(1347)](this[n(1335)],16),255),e[n(1347)](this[n(1335)],24))}static[t(1184)+"er"](n,s=!0){let l=t;if(e[l(1317)](l(476),e[l(944)]))this._DBName=_0x13bace,this[l(1298)]=_0x405739,this[l(1038)]=_0x54f9c0?_0x254473:_0x2e67ed?_0x5dcc31:null;else{if(e[l(1491)](isNaN,n))return s?Ip:Yd;if(s){if(e.XxWVU(n,Ie))return kp}else if(e[l(434)](e[l(930)],l(1680)))_0x176527=e[l(834)](_0x574fa2,_0x4d74dd),_0x28a9f2|=e[l(1402)](e.egTQo(127,_0x59204a),7);else{if(e.arSNb(n,-er))return Tp;if(e[l(525)](e[l(1339)](n,1),er))return Ap}return ue[l(1388)](e[l(990)](n,we)|0,e.XUYeS(e[l(700)](n,we),0),s)}}[t(584)](){let n=t;return this[n(963)]?e.eljLr(e[n(1301)](e[n(982)](this[n(1335)],0),we),e[n(918)](this.low,0)):e[n(1551)](this[n(1335)],we)+e[n(1347)](this[n(1324)],0)}isZero(){let n=t;return e[n(923)](0,this[n(1335)])&&e.oljHo(0,this.low)}add(n){let s=t;ue[s(883)](n)||(n=ue[s(1184)+"er"](n));let l=e[s(982)](this[s(1335)],16),h=e[s(1141)](65535,this.high),g=e[s(657)](this.low,16),S=65535&this[s(1324)],b=e[s(1363)](n[s(1335)],16),m=65535&n[s(1335)],R=e[s(503)](n.low,16),B=e[s(1438)](65535,n[s(1324)]),F=0,V=0,$=0,pe=0;return pe+=e[s(402)](S,B),$+=e[s(988)](pe,16),pe&=65535,$+=e[s(779)](g,R),V+=e[s(536)]($,16),$&=65535,V+=h+m,F+=e[s(1068)](V,16),V&=65535,F+=e.vmeiV(l,b),F&=65535,ue[s(1388)](e[s(468)]($<<16,pe),e[s(1343)](e[s(667)](F,16),V),this.unsigned)}equals(n){let s=t;return ue.isLong(n)||(n=ue[s(1184)+"er"](n)),e[s(829)](this[s(963)],n[s(963)])&&e[s(544)](this.high>>>31,1)&&e[s(1709)](e[s(393)](n[s(1335)],31),1)?!1:this[s(1335)]===n.high&&e[s(544)](this[s(1324)],n.low)}[t(421)](){let n=t;return this[n(1324)]===-1&&e[n(1317)](-1,this[n(1335)])?ue[n(1388)](0,0,this[n(963)]):e[n(1675)](-1,this[n(1324)])?ue.fromBits(0,e[n(1269)](this[n(1335)],1),this[n(963)]):ue[n(1388)](this[n(1324)]+1,this.high,this[n(963)])}toBytes(n){let s=t;return n?this[s(1720)+"E"]():this[s(1711)+"E"]()}toBytesLE(){let n=t,s=this[n(1335)],l=this[n(1324)];return[e[n(1369)](255,l),e.VzYdA(e[n(940)](l,8),255),e[n(795)](e[n(762)](l,16),255),e[n(1363)](l,24),e[n(1313)](255,s),e[n(1710)](e[n(1347)](s,8),255),e[n(1123)](e.pGJPM(s,16),255),s>>>24]}[t(1711)+"E"](){let n=t,s=this[n(1335)],l=this[n(1324)];return[e[n(1300)](s,24),e.gaytm(s>>>16,255),e[n(1222)](s,8)&255,e[n(1334)](255,s),e[n(762)](l,24),e[n(988)](l,16)&255,e[n(1011)](e[n(320)](l,8),255),e[n(1011)](255,l)]}}let Yd=new ue(0,0,!1),Ip=new ue(0,0,!0),Ap=ue[t(1388)](-1,2147483647,!1),kp=ue[t(1388)](-1,-1,!0),Tp=ue.fromBits(0,-2147483648,!1);var nn=(function(a){let n=t,s=e[n(1521)].split("|"),l=0;for(;;){switch(s[l++]){case"0":a[a[e[n(1655)]]=5004]="MESSAGE_ERROR";continue;case"1":return a;case"2":a[a["MAX_RETR"+n(562)+"R"]=5003]=n(1319)+n(562)+"R";continue;case"3":a[a[e[n(1407)]]=5005]=e[n(1407)];continue;case"4":a[a[e[n(1341)]]=5002]=e[n(1341)];continue;case"5":a[a[e[n(1140)]]=5001]=e[n(1140)];continue}break}})({});class tr{constructor(n){let s=t;this[s(1653)]=n,this.target=null}}class Xd extends tr{constructor(n,s){let l=t;super(n),this[l(464)]=s&&s.message||null}}class Qd extends tr{constructor(n,s){let l=t,h=e[l(1293)].split("|"),g=0;for(;;){switch(h[g++]){case"0":this[l(882)]=s&&s[l(882)]||5001;continue;case"1":this.error=s&&s[l(870)]||null;continue;case"2":super(n);continue;case"3":this[l(1721)]=s&&s.lineno||0;continue;case"4":this.message=s&&s.message||"";continue;case"5":this[l(1755)]=s&&s[l(1755)]||0;continue;case"6":this.filename=s&&s[l(843)]||"";continue}break}}}class el extends tr{constructor(n,s){let l=t,h=e[l(1147)][l(732)]("|"),g=0;for(;;){switch(h[g++]){case"0":this.code=s&&s[l(882)]||0;continue;case"1":this[l(1498)+l(1039)]=s&&s[l(1498)+l(1039)]||!1;continue;case"2":super(n);continue;case"3":this[l(1677)]=s&&s[l(1677)]||"";continue;case"4":this[l(816)]=s&&s[l(816)]||!1;continue}break}}}class tl extends tr{constructor(n,s){super(n),this.data=s&&s.data||null}}class nl extends tl{constructor(n,s){let l=t;super(n),this[l(444)]=s&&s[l(444)]||null,this.message=s&&s.message||null}}class rl extends tr{constructor(n,s){let l=t;super(n),this[l(444)]=s&&s[l(444)]||null}}function dt(a,{message:n,code:s,error:l}){return new Qd(a,{message:n,code:s,error:l})}function gt(a,{code:n,reason:s,wasClean:l,willReconnect:h}){return new el(a,{code:n,reason:s,wasClean:l,willReconnect:h})}function il(a,{data:n,message:s}){return new nl(a,{data:n,message:s})}function sl(a,{data:n}){return new rl(a,{data:n})}function la(a,{message:n}){let s=t,l={ulWRU:e[s(597)],VocHb:e.YtLRp};if(e.xoFBL(s(565),e[s(1466)]))return new Xd(a,{message:n});{let h=(s(1165)+"4")[s(732)]("|"),g=0;for(;;){switch(h[g++]){case"0":this[s(1033)][s(1183)+s(1467)+s(1714)](s(1582),this[s(1730)]);continue;case"1":if(!this._ws)return;continue;case"2":this[s(1033)][s(1183)+s(1467)+s(1714)]("message",this[s(933)+"ge"]);continue;case"3":this[s(1033)][s(1183)+s(1467)+s(1714)](l.ulWRU,this[s(428)]);continue;case"4":this._ws["removeEv"+s(1467)+s(1714)](l[s(470)],this._onError);continue}break}}}class ol{constructor(n,s){let l=t;this[l(1642)+"s"]=n,this[l(799)+"es"]=s,this[l(1250)+l(847)]=0,this[l(1368)+l(728)+l(1077)+"t"]=0}[t(978)+t(1422)+t(585)](){let n=t;this[n(1250)+n(847)]=0,this[n(1368)+n(728)+n(1077)+"t"]=0}resetTries(){let n=t;this[n(1368)+"ndpointT"+n(1077)+"t"]=0}[t(1393)+t(1482)+"nt"](){let n=t;if(e[n(617)](e.uJFOS,e.uJFOS))return this[n(1642)+"s"][this[n(1250)+n(847)]];_0x538165(_0xd50170,8),e.Ytykb(_0x11f30a,_0x3e09ed,_0x49626a)}[t(1393)+"ntEndpoi"+t(697)+t(596)](){return this["currentEndpointT"+t(1077)+"t"]}["checkRea"+t(769)+"es"](){let n=t;return!!(this[n(1250)+n(847)]>=this[n(1642)+"s"][n(460)]||e[n(810)](this.currentIndex,this.endpoints[n(460)]-1)&&e[n(386)](this[n(1368)+n(728)+n(1077)+"t"],this[n(799)+"es"]))}[t(1226)+t(1012)+t(1229)+t(614)+"tries"](){let n=t;return e[n(1217)](this[n(1250)+n(847)],this[n(1642)+"s"][n(460)])?!0:this[n(1368)+n(728)+n(1077)+"t"]>this[n(799)+"es"]}[t(1507)+t(798)+t(1258)+t(1056)+t(670)](){let n=t;return this[n(1368)+n(728)+"riesCount"]=1,this[n(1250)+n(847)]++,this[n(1642)+"s"][this[n(1250)+n(847)]]}["getCurre"+t(1482)+t(1494)+t(1148)](){let n=t;return this[n(1368)+n(728)+"riesCount"]++,this[n(1393)+n(1482)+"nt"]()}}let nr=(e.BHSRU(e[t(1635)],typeof globalThis)&&e[t(1457)](e[t(1448)],globalThis[t(1728)+t(1405)].name)||t(336)+"d"!=typeof window&&window[t(1728)+t(1405)][t(731)]==="Window")&&e.xExGb(t(336)+"d",typeof document),Cn=e[t(328)](e[t(1635)],typeof globalThis)&&(e[t(1349)]("Object",globalThis[t(1728)+t(1405)][t(731)])||e[t(355)](e[t(1621)],globalThis[t(1728)+t(1405)][t(731)]))&&e.BHSRU(t(336)+"d",typeof tt),Yr=(e.kkVGk(e[t(1635)],typeof globalThis)&&e[t(560)](t(895),globalThis[t(1728)+t(1405)].name)||e[t(1065)](e[t(1635)],typeof globalThis)||e[t(315)]("undefined",typeof globalThis)&&!!globalThis[t(579)+t(1259)])&&t(336)+"d"!=typeof wx,Xr=e[t(658)](e[t(1635)],typeof globalThis)&&(e[t(1305)](t(1167)+t(796)+t(874)+"pe",globalThis[t(1728)+"tor"][t(731)])||e.RKZNr(e[t(1596)],globalThis[t(1728)+"tor"].name)||e.SGlmJ("ServiceW"+t(1627)+t(324),globalThis[t(1728)+t(1405)][t(731)]))&&e[t(315)](t(336)+"d",typeof self),Rp=e[t(1429)](e.EcWZs,typeof globalThis)&&e.eEurm(t(895),globalThis[t(1728)+t(1405)][t(731)])&&e[t(1635)]!=typeof global&&e[t(819)](e[t(716)],global[t(1728)+"tor"][t(731)])&&e[t(1635)]!=typeof process&&!!process[t(1125)];class ua{constructor(){let n=t;this[n(775)+"rs"]={}}[t(1718)](n,...s){let l=t,h=this[l(775)+"rs"][n];if(h)h[l(901)]()[l(953)](g=>g.fn.apply(g[l(771)],s));else if(e[l(544)](e[l(327)],n)&&!this[l(1185)]){let g=s[l(460)]&&s[0];if(e[l(644)](g,Error))throw g;let S=new Error(e.qeWDB(e[l(1410)],g?e.InmnK(" ("+g[l(464)],")"):""));throw S.context=g,g}return this}off(n,s){let l=t;if(e[l(561)](e[l(985)],e[l(985)])){if(e.nEIXs(void 0,n))this[l(775)+"rs"]={};else if(s===void 0)this[l(775)+"rs"][n]=null;else if(e.jPiui(e[l(337)],l(634))){let h=this[l(775)+"rs"][n];if(h)for(let g=0;e.LPIyk(g,h[l(460)]);)e[l(734)](h[g].fn,s)?h[l(612)](g,1):++g}else{let h=_0x1eb09b[l(640)],g=_0x409f47[l(690)],S=_0x3ede0f.limit,b=e[l(1514)](g,_0x6b022d);if(e.YnIsR(b,h[l(460)])){let m=new _0x21006d(e[l(378)](2,b));m[l(1744)](h),_0x27de89[l(640)]=m}return _0x4b8622[l(690)]=b,b>S&&(_0x3cf44d[l(317)]=b),g}return this}else{let h=this[l(775)+"rs"][_0xaf39ae];if(h)h[l(901)]()[l(953)](g=>g.fn[l(427)](g.ctx,_0x7a5641));else if(e[l(386)](e.YtLRp,_0x3b54fc)&&!this[l(1185)]){let g=_0x317fe1.length&&_0x3d6877[0];if(e.wQjdz(g,_0x473d3c))throw g;let S=new _0x71461a(e.ibhaC+(g?e[l(455)](" (",g[l(464)])+")":""));throw S[l(1632)]=g,g}return this}}on(n,s,l){let h=t;return(this[h(775)+"rs"][n]||(this._listeners[n]=[]))[h(1017)]({fn:s,ctx:l||this}),this}}class Cp extends ua{["_formatE"+t(407)+t(1487)](n){let s=t;return n[s(1743)]||n[s(817)]?(s(1719)+" "+(n[s(1743)]||"")+" code: "+(n[s(817)]||""))[s(332)]():JSON[s(710)+"y"](n)}constructor(n,s,l){let h=t;super(),this[h(776)]=null,Yr&&wx["connectS"+h(662)]&&(this._socket=wx.connectSocket({url:n,protocols:s,header:l,fail:this[h(659)+"ocketFai"+h(607)][h(1023)](this),success:this[h(659)+"ocketSuccessHand"+h(384)][h(1023)](this)})),Cn&&tt["connectS"+h(662)]&&(this[h(776)]=tt.connectSocket({url:n,protocols:s,header:l,fail:this["_createS"+h(789)+"lHandler"][h(1023)](this),success:this[h(659)+h(588)+"cessHand"+h(384)][h(1023)](this)}))}["_createS"+t(588)+t(726)+t(384)](){let n=t;Promise[n(777)]()[n(577)](()=>{let s=n;this[s(1661)+s(702)]()})}[t(659)+"ocketFai"+t(607)](n){let s=t;Promise[s(777)]().then(()=>{let l=s,h=e[l(1310)](dt,l(870),{message:this[l(1578)+l(407)+"age"](n)});this.emit(e[l(327)],h);let g=e[l(395)](gt,e[l(597)],{reason:this["_formatE"+l(407)+"age"](n)});this[l(1718)](e[l(597)],g)})}[t(1661)+t(702)](){let n=t,s={Qnbve:function(l,h,g){return e[q(433)](l,h,g)},VxcmB:e.rukws};this[n(776)][n(1208)](l=>{let h=n;this[h(1718)](e[h(1359)],e[h(431)](sl,e[h(1359)],{...l,data:l.errMsg||""}))}),this._socket[n(1581)](l=>{let h=n;this[h(1718)](h(1739),s[h(1486)](gt,h(1739),{...l}))}),this[n(776)][n(823)+"e"](l=>{let h=n;this[h(1718)](s[h(1643)],il(s[h(1643)],{...l}))}),this._socket[n(854)](l=>{let h=n;this.emit(e[h(327)],e[h(1174)](dt,h(870),{...l,message:l[h(1743)]||""}))})}[t(1383)](n){let s=t,l={PzNgx:s(870)};if(n instanceof Uint8Array){let h=n.buffer.slice(n[s(462)+"et"],n[s(1338)+"th"]+n.byteOffset);this[s(776)]&&this[s(776)][s(1383)]({data:h,fail:g=>{let S=s;this.emit(e[S(327)],dt(e.YtLRp,{message:this["_formatE"+S(407)+"age"](g)}))}})}else this._socket&&this._socket[s(1383)]({data:n,fail:h=>{let g=s;this[g(1718)](l.PzNgx,dt(l[g(672)],{message:this[g(1578)+g(407)+g(1487)](h)}))}})}[t(1739)](n,s){let l=t;this[l(776)]&&this[l(776)][l(1739)]({code:n,reason:s})}[t(1395)+t(1020)](n,s){this.on(n,s)}[t(1183)+t(1467)+t(1714)](n,s){let l=t;if(e[l(576)](e[l(1663)],l(1425)))this[l(995)](n,s);else{let h=!!this[l(1669)][l(1145)+"S"];if(!h)return{enabled:h,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let g=e[l(418)](_0x2baf25,_0x44a179[l(464)][l(1292)],e.TWMhQ,"2"),S=g&&_0x2067d3(_0x46c1df[l(464)][l(1292)],e[l(1196)],"1"),b=g&&e[l(418)](_0xc81b15,_0x449371[l(464)].headers,e[l(1362)],"1"),m=b?e[l(853)](_0x25e812,_0x30e8a5[l(464)].headers,e[l(1651)])?.[l(732)](",").filter(_0x3478ca)||[]:[];return{enabled:h,isQoSMessage:g,isQoSAck:S,isAckCleanupMessage:b,ackMsgIds:m}}}get[t(1666)+"te"](){let n=t;return this[n(776)][n(1666)+"te"]}get binaryType(){let n=t;return this[n(776)][n(1558)+"pe"]}set[t(1558)+"pe"](n){}get[t(922)](){let n=t,s={mSqfe:function(l,h,g){return e.lAGaw(l,h,g)}};return e[n(482)](e[n(1025)],e[n(792)])?new _0xf25697(l=>{let h=n;s[h(1036)](_0x28f19a,l,this[h(426)+h(1505)+"e"](_0x3d59ca))}):this._socket.url}get[t(1019)](){return this._socket.protocol}get[t(1625)+"ns"](){let n=t;return this[n(776)][n(1625)+"ns"]}get[t(375)+"Amount"](){let n=t;return e[n(1541)](e[n(1263)],e[n(1022)])?0:(this[n(1368)+n(728)+n(1077)+"t"]++,this["getCurre"+n(1482)+"nt"]())}}function Pp(a,n){let s=t;if(n)return new n(a.url,a.protocol);if(e.LSGKX(Yr,Cn))return new Cp(a.url,a[s(1019)],a[s(1292)]);if(e.ALVfC(nr,Xr)&&e[s(328)](e.EcWZs,typeof WebSocket)&&WebSocket)return new WebSocket(a[s(922)],a[s(1019)+"s"])}function Dp(a){let n=t,s={WsZRt:function(l,h){return e[q(465)](l,h)},jcECy:function(l,h){return l&h},qdSpW:function(l,h){return e[q(568)](l,h)},mUAxT:function(l,h){return l+h}};if(e[n(1553)](e[n(1472)],"aHLWi")){let l=_0xd61201.low,h=_0xea0c6[n(1335)];return _0x340e94[_0x59a3c1]=s[n(392)](h,24),_0x173bff[_0xe86b5c+1]=s[n(705)](s[n(392)](h,16),255),_0x35f7fc[_0x395eaa+2]=s[n(705)](h>>>8,255),_0x21ff8f[s.qdSpW(_0x34b2e1,3)]=s[n(705)](255,h),_0x24c599[_0x3ee531+4]=s[n(392)](l,24),_0x522c76[s[n(1624)](_0x99820f,5)]=l>>>16&255,_0x5726ee[_0x4dddc4+6]=s.jcECy(l>>>8,255),_0x2129ab[s[n(635)](_0x81d2e3,7)]=s[n(705)](255,l),_0x43deb2+=8,_0x5f48e4}else{let l=e[n(1742)][n(732)]("|"),h=0;for(;;){switch(l[h++]){case"0":return!1;case"1":if(a)return!0;continue;case"2":if(Cn&&tt["connectS"+n(662)])return!0;continue;case"3":if(Yr&&wx[n(1284)+n(662)])return!0;continue;case"4":if(e.EjAhI(nr,Xr)&&typeof WebSocket<"u"&&WebSocket)return!0;continue}break}}}function al(a,n,s){let l=t,h={TRiaK:function(b,m){return e.hHIWe(b,m)},WDFFn:e[l(521)],ffeWu:function(b,m){return e.lpZIk(b,m)},BbEzJ:function(b,m){return e[l(1480)](b,m)}},g=-1;async function S(b){let m=l;return h.TRiaK(b,g)?Promise[m(1699)](new Error(h[m(830)])):(g=b,h.ffeWu(b,s.length)?Promise[m(777)]():s[b][m(1023)](a)(n,S.bind(null,h[m(570)](b,1))))}e[l(1129)](S,0)}function cl(a){let n=t,s=0,l=0;for(let h=0;e[n(909)](h,a[n(460)]);++h)l=a.charCodeAt(h),e.LIYfW(l,128)?s+=1:l<2048?s+=2:e[n(1122)](64512,l)===55296&&e.nEIXs(64512&a[n(1046)+"At"](h+1),56320)?e[n(576)](e.TavCA,e[n(931)])?(++h,s+=4):_0x55a671[n(1164)](_0x472ba9):s+=3;return s}function dl(a,n,s){let l=t;if(e[l(1018)](e[l(571)](s,n),1))return"";let h="";for(let g=n;e[l(650)](g,s);){let S=a[g++];if(e[l(773)](S,127))h+=String[l(709)+l(1135)](S);else if(e[l(525)](S,192)&&e.EUgLi(S,224))h+=String[l(709)+"Code"](e[l(1240)](31&S,6)|e[l(540)](63,a[g++]));else if(S>=224&&e[l(477)](S,240))h+=String[l(709)+l(1135)](e.buuXq(e[l(515)](e[l(502)](e[l(1567)](15,S),12),e[l(667)](63&a[g++],6)),e[l(1703)](63,a[g++])));else if(S>=240){let b=e[l(993)](e[l(1357)](e[l(538)](e[l(1142)](e.ARTmK(7,S),18)|e.hEEVT(e[l(312)](63,a[g++]),12),e[l(667)](e.tkUbF(63,a[g++]),6)),63&a[g++]),65536);h+=String["fromChar"+l(1135)](55296+(b>>10)),h+=String[l(709)+l(1135)](56320+e[l(1122)](1023,b))}}return h}function fa(a,n,s){let l=t;if(e[l(955)](l(469),e[l(1049)])){let h=s,g,S;for(let b=0;e[l(490)](b,a[l(460)]);++b)g=a[l(1046)+"At"](b),e[l(788)](g,128)?n[s++]=g:e[l(788)](g,2048)?(n[s++]=e[l(1116)](e[l(1103)](g,6),192),n[s++]=e[l(1670)](e[l(1399)](63,g),128)):e[l(569)](e[l(1477)](64512,g),55296)&&e[l(434)](e[l(1468)](64512,S=a[l(1046)+"At"](b+1)),56320)?(g=e[l(369)](e[l(1224)](65536,e[l(667)](e.rhtpd(1023,g),10)),e.vZuWw(1023,S)),++b,n[s++]=e[l(1103)](g,18)|240,n[s++]=e[l(1078)](e[l(540)](e[l(1034)](g,12),63),128),n[s++]=e[l(1409)](e[l(1103)](g,6),63)|128,n[s++]=e[l(1569)](e[l(1640)](63,g),128)):(n[s++]=e[l(863)](e[l(763)](g,12),224),n[s++]=e[l(365)](g,6)&63|128,n[s++]=e.eBrMc(e.gTNaB(63,g),128));return s-h}else this["currentI"+l(847)]=0,this[l(1368)+l(728)+l(1077)+"t"]=0}async function ll(a){let n=t;if(e[n(1442)](e[n(582)],typeof a)){let s=new Uint8Array(cl(a));return e[n(1476)](fa,a,s,0),s}return e[n(920)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(595)],a.byteOffset,a[n(1338)+"th"])}function Op(a){let n=t;try{return e[n(328)](n(1540),typeof a)&&(a instanceof ArrayBuffer||a[n(595)]&&e[n(920)](a[n(595)],ArrayBuffer))||e.BHSRU(n(1540),typeof a)?"":(JSON.parse(a),n(1175)+n(921))}catch{return e[n(583)]!==e[n(583)]?n(1092)+"_"+this._DBName:typeof a=="string"?e[n(1351)]:""}}let Lp=(a,n)=>{let s=t;switch(a){case s(1501):case e[s(753)]:return{[s(1093)+a]:1,"x-tt-env":n};default:return{}}};class Np{constructor(n){let s=t;if(e.ggVCV(e[s(858)],"TLDvj"))return null;this.maxLossCount=n,this.count=0}addCount(){this.count++}[t(1520)+t(1470)+"nt"](){let n=t,s={sOpKN:function(l,h,g){return e[q(1288)](l,h,g)},rdglB:function(l,h){return e[q(1736)](l,h)},Epdpq:function(l,h,g){return l(h,g)}};if(e[n(1215)](n(1573),"gdWhp"))return e[n(423)](this[n(932)],this[n(805)+"ount"]);if(this[n(1033)]&&this[n(1033)][n(1666)+"te"]===this[n(466)+"NG"]){this[n(602)+n(1105)](),this[n(1449)+n(1355)+"Id"]=s[n(1372)](_0x3129f1,this._ping[n(1023)](this),this._options[n(852)+n(1114)]);return}if(!this[n(1033)]||s[n(1031)](this._ws[n(1666)+"te"],this[n(751)]))return void this[n(996)+n(539)]();this._ws&&this._ws.send("hi"),this[n(381)+n(671)+n(911)]=s[n(647)](_0x2a45ff,this[n(996)+n(539)+n(890)][n(1023)](this),this[n(1669)]["pingTime"+n(1160)+n(808)])}[t(1441)+t(1186)](n=0){let s=t;this[s(805)+s(596)]=n,this[s(932)]=0}}async function Mp(a){let n=t,s={ZxLug:function(l,h){return e.pFhnl(l,h)},EKlfs:e[n(1749)]};if(e[n(1492)](e[n(1463)],n(1072)))return new Promise(l=>{let h=n;if(!nr)return e.pFhnl(l,e[h(1749)]);try{let g=document[h(1723)+h(1526)](h(580));window[h(1092)+h(946)]=S=>{let b=h;document.body[b(1456)+b(688)](g),window[b(1092)+b(946)]=void 0,s[b(655)](l,S&&S[b(1163)]||s[b(1042)])},g[h(1653)]=e[h(785)],g.src=e[h(1295)](a[h(1623)](/^ws/,e[h(400)]),e[h(1604)]);try{if(e.mvBrL(e[h(399)],h(559)))return this[h(1038)][h(1030)];document[h(509)]["appendCh"+h(688)](g)}catch{document[h(509)][h(1456)+h(688)](g)}}catch{window[h(1092)+h(946)]=void 0,e.pFhnl(l,"unknown "+h(1677))}});e.xYuZE(_0x1875c0,this[n(485)+n(1733)+n(1096)]),this[n(485)+n(1733)+n(1096)]=null}function rn(a,n,s){let l=t,h={prtCU:function(g,S,b){return e[q(1602)](g,S,b)},XMErZ:e[l(327)]};if(e.CyKjc(e.qleMW,l(608))){let g=l(809)+_0x1ef1e8+(l(1371)+", max re"+l(417)+l(1481));this[l(1178)](g),this["_dispatc"+l(1591)+"ent"](h[l(1660)](_0x899c63,h[l(1006)],{message:g,code:_0x269f74[l(1319)+l(562)+"R"]}));return}else return!!a?.[l(586)](g=>g[l(1458)]===n&&g[l(1536)]===s)}function rr(a,n){let s=t;return a?.find(l=>l[s(1458)]===n)?.[s(1536)]}let ha=null;async function Bp(){let a=t;return ha||(ha=Promise.resolve()[a(577)](Bt.bind(Bt,e.rrLwJ))),ha}class Fp extends ua{constructor(n,s){let l=t;super(),this[l(1086)]=n,this._keyPath=s,this[l(1038)]=void 0,this[l(1622)+l(1106)]=null}async[t(1348)](){await this._init()}async[t(1353)](){let n=t,s={lhXqP:function(l,h){return l!==h},gfcRm:e.sDUwk};if(!this[n(1038)]){if(this[n(1622)+"mise"])return this[n(1622)+n(1106)];try{let l=this[n(1086)],h=this._keyPath;this[n(1622)+n(1106)]=(async()=>{let g=n,S={umgLW:function(b,m){return e[q(954)](b,m)},eCMHN:function(b,m){return e.byVnG(b,m)},EEcIm:function(b,m){return e[q(409)](b,m)},XeULp:function(b,m){return e[q(314)](b,m)},kLhpY:function(b,m){return e[q(1252)](b,m)},tQcWW:function(b,m){return b||m},cHODK:function(b,m){return e[q(1132)](b,m)}};if(e[g(740)](e[g(896)],"BHuFN")){let{openDB:b}=await e[g(1332)](Bp);this[g(1038)]=await e[g(1476)](b,g(1092)+"_"+l,1,{upgrade(m){let R=g;if(s[R(1676)](R(1195),s[R(1592)]))return this[R(776)][R(1558)+"pe"];m["createOb"+R(1231)+"e"](l,{keyPath:h})}})}else{let b=S[g(1705)](_0xec5fde,8192),m=S[g(621)](b,1),R=null,B=b;return function(F){let V=g;if(S[V(1758)](F,1)||S[V(1192)](F,m))return _0x33345a(F);S[V(1192)](B+F,b)&&(R=S[V(1408)](_0xa7600b,b),B=0);let $=_0x24c1d2[V(493)](R,B,B+=F);return S[V(435)](7,B)&&(B=S[V(1686)](7,B)+1),$}}})(),await this["_initPro"+n(1106)]}catch(l){console[n(1164)](l)}finally{this._initPromise=null}}}async[t(915)](n){let s=t;try{return await this[s(1353)](),this[s(1038)]?.[s(915)](this[s(1086)],n)}catch(l){console[s(1164)](l)}}async set(n,s){let l=t;if(e[l(1588)]!==e[l(1588)])_0x51ecaa(_0x482e04,74),_0x5e6961(_0x508852,_0x2c4c32);else return await this[l(1353)](),this[l(1038)]?.[l(1223)](this[l(1086)],n)}async[t(505)](n){let s=t,l={hQxuQ:function(h,g){return e[q(1101)](h,g)}};try{return await this[s(1353)](),this._qosDB?.[s(488)](this[s(1086)],n)}catch(h){e[s(1265)](s(846),e.jSZyb)?console[s(1164)](h):(_0x5c6619[_0x490465[_0x695474].cursor_name]=_0x4703a7(_0x2ce0e0[_0x39be8a][s(1253)+"ame"]),_0x57f9b0+=l.hQxuQ(14,_0x347a96[_0x141d69[_0x14c2f8][s(1253)+s(1664)]]))}}async[t(496)](){let n=t;try{return await this[n(1353)](),this[n(1038)]?.[n(496)](this[n(1086)])}catch(s){console[n(1164)](s)}}async keys(){let n=t;return await this[n(1353)](),this._qosDB?.[n(1177)+"ys"](this._dbName)}async[t(445)](){let n=t;return await this[n(1353)](),this._qosDB?.[n(445)](this._dbName)}async closeDB(){let n=t;try{this._qosDB?.[n(1739)](),this[n(1038)]=void 0}catch(s){console[n(1164)](s)}}get[t(1030)](){let n=t;try{return!!this[n(1038)]}catch(s){return console[n(1164)](s),!1}}}class zp{constructor(n,s){let l=t;this[l(1336)]=n,this[l(1298)]=s,this[l(1038)]=localStorage}async[t(1348)](){}get[t(613)](){let n=t;return n(1092)+"_"+this[n(1336)]}async[t(915)](n){let s=t;if(e[s(1447)]===e.ZDSHT){let l=this[s(1038)][s(1280)](this[s(613)]);return JSON[s(1601)](l||"{}")[n]}else return{bytes:_0xec1fb4,offset:0,limit:_0x22bbbf[s(460)]}}async[t(1744)](n,s){let l=t,h={VYhyz:function(g,S){return e[q(545)](g,S)},ULWIs:function(g,S){return g&S},yaDNn:function(g,S){return e.owDNv(g,S)},DyfKj:function(g,S){return g&S},MabSq:function(g,S){return e[q(1674)](g,S)},VmoSd:function(g,S){return e.rhtpd(g,S)},WDfft:function(g,S){return g>>>S}};if(e[l(1282)](e.bUpBN,l(1024))){let g=this[l(1038)].getItem(this[l(613)]),S=JSON[l(1601)](e[l(1638)](g,"{}"));return S[s||n[this[l(1298)]]]=n,this[l(1038)][l(761)](this[l(613)],JSON[l(710)+"y"](S)),s||n[this._pathKey]}else{let g=this[l(1335)],S=this[l(1324)];return[g>>>24,TAjTnB[l(471)](g>>>16,255),TAjTnB.ULWIs(TAjTnB[l(624)](g,8),255),TAjTnB[l(1434)](255,g),TAjTnB[l(624)](S,24),TAjTnB[l(471)](TAjTnB[l(1510)](S,16),255),TAjTnB.VmoSd(TAjTnB[l(759)](S,8),255),TAjTnB.VmoSd(255,S)]}}async del(n){let s=t,l=this[s(1038)][s(1280)](this[s(613)]),h=JSON[s(1601)](e.ALVfC(l,"{}"));return h[n]=void 0,this[s(1038)].setItem(this[s(613)],JSON[s(710)+"y"](h))}async[t(496)](){let n=t;return this[n(1038)][n(496)]()}async[t(807)](){let n=t,s=this._qosDB[n(1280)](this[n(613)]),l=JSON[n(1601)](e[n(516)](s,"{}"));return Object[n(807)](l)}async[t(445)](){let n=t,s=this[n(1038)][n(1280)](this._prefix),l=JSON[n(1601)](s||"{}");return Object.values(l)}[t(648)](){return Promise[t(777)]()}get[t(1030)](){return!!this._qosDB}}class Up{constructor(n,s){let l=t;e[l(601)](e[l(566)],e[l(566)])?(this[l(1336)]=n,this[l(1298)]=s,this[l(1038)]=Cn?tt:Yr?wx:null):_0x1f23c9&&this[l(448)+"anager"][l(622)+"rsorFile"+l(928)](_0x4872c8)}async[t(1348)](){}get[t(613)](){let n=t;return n(1092)+"_"+this[n(1336)]}async get(n){let s=t,l=this._qosDB[s(1244)+s(812)](this[s(613)]);return JSON[s(1601)](e.FfUkD(l,"{}"))[n]}async[t(1744)](n,s){let l=t,h=this[l(1038)][l(1244)+l(812)](this[l(613)]),g=JSON.parse(e[l(1001)](h,"{}"));return g[s||n[this._pathKey]]=n,this[l(1038)]["setStora"+l(812)](this._prefix,JSON.stringify(g)),s||n[this[l(1298)]]}async[t(505)](n){let s=t,l=this[s(1038)][s(1244)+s(812)](this._prefix),h=JSON.parse(l||"{}");return h[n]=void 0,this[s(1038)][s(1433)+"geSync"](this[s(613)],JSON[s(710)+"y"](h))}async[t(496)](){let n=t;return this._qosDB[n(756)+n(563)]()}async[t(807)](){let n=t,s=this._qosDB[n(1244)+"geInfoSync"](this[n(613)]),l=JSON[n(1601)](e[n(687)](s,"{}"));return Object[n(807)](l)}async[t(445)](){let n=t,s=this[n(1038)][n(1244)+n(497)+"nc"](this[n(613)]),l=JSON.parse(s||"{}");return Object[n(1047)](l)}[t(648)](){return Promise[t(777)]()}get[t(1030)](){let n=t;if(e[n(1035)](n(1452),e.tkiJV)){let s={XxPzF:function(l,h){return beIKsU.YkdEt(l,h)},lCAze:beIKsU[n(1635)],eSaJa:beIKsU[n(594)],NlIfA:beIKsU[n(1151)]};_0x548705.r=l=>{let h=n;s[h(1572)](s[h(1654)],typeof _0x3ff30a)&&_0x3c1dce[h(1275)+h(1045)]&&_0x2362dc[h(408)+h(851)](l,_0x124288[h(1275)+h(1045)],{value:s.eSaJa}),_0x2b93b6["definePr"+h(851)](l,s[h(1327)],{value:!0})}}else return!!this[n(1038)]}}function ul(a,n){let s=t;if(Cn||Cn)return new Up(a,n);if((nr||Xr)&&e[s(1016)](e[s(1635)],typeof indexedDB))return new Fp(a,n);if(e[s(1692)](nr,Xr)&&e[s(1230)](s(336)+"d",typeof localStorage))return new zp(a,n);throw new Error(e[s(1187)])}class Gp{constructor(){let n=t;this[n(1751)+n(354)+"Id"]=null,this[n(1751)+"l"]=36e5,this[n(1038)]=e[n(724)](ul,e[n(374)],e[n(1529)])}async["_interva"+t(1180)](){let n=t;e.pFhnl(clearInterval,this["_interva"+n(354)+"Id"]),this[n(1751)+n(354)+"Id"]=e[n(1037)](setInterval,()=>{let s=n;this[s(1641)+s(1606)]()},this._interval)}async[t(1348)](){let n=t;await this._qosDB[n(1348)]()[n(577)](()=>{let s=n;this[s(1751)+s(1180)]()})}async[t(1641)+"ired"](){let n=t,s={RASjv:function(l,h){return e.Fhwzv(l,h)},pJIAQ:function(l,h){return e[q(500)](l,h)},EAEWW:function(l,h){return l<<h},XNihb:function(l,h){return e.EpQMX(l,h)},kzxgp:function(l,h){return e[q(1399)](l,h)},pYBig:function(l,h){return l>=h},TPkyZ:function(l,h){return l<h},BjqdD:function(l,h){return l&h},DPPZO:function(l,h){return e[q(1227)](l,h)},guJPJ:function(l,h){return l-h},gGCIS:function(l,h){return e[q(885)](l,h)},GmfSe:function(l,h){return e[q(538)](l,h)},xBEYd:function(l,h){return l<<h},sweov:function(l,h){return e[q(1162)](l,h)},hNXpw:function(l,h){return e[q(486)](l,h)}};if(e[n(1378)](e[n(619)],e[n(1373)])){let l=_0x21ed1e[_0x6a69fc++];if(zqWfxU[n(1382)](l,127))_0x4ed908+=_0x283abc[n(709)+n(1135)](l);else if(l>=192&&l<224)_0x268d54+=_0x1ab6e9[n(709)+n(1135)](zqWfxU[n(1474)](zqWfxU.EAEWW(zqWfxU[n(905)](31,l),6),zqWfxU.kzxgp(63,_0x21b27c[_0x1acd79++])));else if(zqWfxU[n(1430)](l,224)&&zqWfxU[n(685)](l,240))_0x3a96bb+=_0x26f4db[n(709)+n(1135)](zqWfxU[n(1474)](zqWfxU[n(905)](15,l)<<12,zqWfxU[n(839)](zqWfxU[n(1197)](63,_0x332d79[_0xc66c76++]),6))|zqWfxU[n(1374)](63,_0x1220bf[_0x15ecae++]));else if(l>=240){let h=zqWfxU.guJPJ(zqWfxU[n(941)](zqWfxU[n(451)](zqWfxU[n(1374)](7,l)<<18,zqWfxU[n(839)](63&_0x2e57f3[_0x4203f1++],12)),zqWfxU[n(517)](zqWfxU[n(905)](63,_0x3ac290[_0x40f586++]),6))|zqWfxU[n(1323)](63,_0x5bcb4b[_0x5d915a++]),65536);_0x372266+=_0x43cfa1["fromChar"+n(1135)](55296+(h>>10)),_0x37ae0c+=_0x4be857[n(709)+n(1135)](56320+zqWfxU.hNXpw(1023,h))}}else(await this[n(1038)]?.[n(445)]()||[])[n(736)](({timestamp:g})=>g<Date.now())[n(953)](g=>{let S=n;this[S(1038)]?.[S(505)](g[S(1594)+"id"])})}async[t(505)](n){let s=t;return this[s(1038)]?.[s(505)](n)}async[t(1744)](n,s){let l=t;return this[l(1038)]?.[l(1744)]({message_id:n,timestamp:s})}async[t(915)](n){return this[t(1038)]?.get(n)}async[t(648)](){let n=t;clearInterval(this[n(1751)+"lTimeoutId"]),await this[n(1038)]?.closeDB()}get[t(1030)](){let n=t;if(e[n(1190)]===e.WMmIk)return this._qosDB?.[n(1030)];if(_0x45f251.payload instanceof _0x1a4039){let s=this[n(1669)][n(960)+"ncoding"]instanceof _0x3dd91a?{force:!!this[n(1669)][n(960)+n(952)][n(887)],encoding:this[n(1669)][n(960)+n(952)][n(1182)]?this._options[n(960)+n(952)][n(1182)][n(1623)](/\s/g,"")["toLowerC"+n(609)]():""}:{force:!1,encoding:this[n(1669)][n(960)+"ncoding"]?this[n(1669)].payloadEncoding[n(1623)](/\s/g,"")[n(1330)+n(609)]():""},l=_0x156e73["payloadE"+n(952)]?_0x5254a2[n(960)+n(952)][n(1623)](/\s/g,"")["toLowerC"+n(609)]():"",h=e.mMKLB(this[n(1669)][n(1545)+n(1117)],_0x29762e)?{force:!!this[n(1669)][n(1545)+n(1117)][n(887)],type:this._options["payloadT"+n(1117)].type?this[n(1669)][n(1545)+n(1117)][n(1653)][n(1623)](/\s/g,"")[n(1330)+n(609)]():""}:{force:!1,type:this[n(1669)]["payloadT"+n(1117)]?this[n(1669)][n(1545)+n(1117)].replace(/\s/g,"")[n(1330)+n(609)]():""},g=_0x30e126[n(1545)+n(1117)]?_0x1d6333[n(1545)+n(1117)][n(1623)](/\s/g,"")[n(1330)+n(609)]():"",S=h.force?h[n(1653)]:g||h.type,b=s[n(887)]?s.encoding:l||s[n(1182)],m=["text/pla"+n(1278)+n(1497),e[n(331)],e[n(1009)],e.ApbnM],R=[e.jXDQx,e.UJXFT];this._options[n(704)+"ansformT"+n(898)+"ad"]&&m[n(967)](S)&&(!b||R[n(967)](b))?_0x2359c4[n(1444)+n(926)]=e[n(713)](_0x4d9499,_0x1172dd[n(610)],0,_0x243de6[n(610)][n(1338)+"th"]):_0x535afa[n(1444)+n(926)]=""}else _0x1a0eea[n(1444)+n(926)]=""}}function xa(a){let n=t,s=!!this[n(1669)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=rn(a[n(464)][n(1292)],e.TWMhQ,"2"),h=l&&rn(a[n(464)].headers,e.LPrny,"1"),g=l&&e.MHPaP(rn,a[n(464)][n(1292)],n(850)+n(1496)+"k","1"),S=g?e.juXRq(rr,a.message[n(1292)],e[n(1651)])?.[n(732)](",")[n(736)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:h,isAckCleanupMessage:g,ackMsgIds:S}}async function fl(){let a=t;return this["_QoSMana"+a(513)]||(this[a(942)+a(513)]=new Gp),this[a(942)+a(513)][a(1030)]||await this[a(942)+"ger"][a(1348)](),this[a(942)+a(513)]}async function Hp(a,n){let s=t;if(e[s(581)]==="rsGOY")this[s(604)]=!0,this._connect();else{let{enableAutoAck:l}=this[s(1669)],h=e[s(1673)](rn,a.message[s(1292)],s(855),"1"),g=rn(a[s(464)].headers,e[s(827)],"1"),S=xa.call(this,a);if(e.yIuvo(l,h)){let{SeqID:b,LogID:m,service:R,LogIDNew:B,method:F}=a[s(464)];this._sendAck({SeqID:b,LogID:m,LogIDNew:B,service:R,method:F,headers:[{key:e.sBZBQ,value:"1"},{key:e.hqxEX,value:B||""},{key:e[s(1120)],value:"0"}]})}g&&!S[s(1206)]&&this[s(373)+s(1535)+"ageEvent"](a),e[s(520)](n)}}async function qp(a,n){let s=t;this[s(1178)](e[s(999)],a[s(464)]),n()}async function jp(a,n){let s=t,l=e[s(438)](en,await ll(a.data));try{if(e[s(644)](l.payload,Uint8Array))if(e[s(972)](e.ukFhh,e[s(574)])){let h=e[s(356)](this._options[s(960)+s(952)],Object)?{force:!!this._options[s(960)+"ncoding"].force,encoding:this[s(1669)][s(960)+"ncoding"][s(1182)]?this[s(1669)][s(960)+s(952)][s(1182)].replace(/\s/g,"")["toLowerC"+s(609)]():""}:{force:!1,encoding:this[s(1669)]["payloadE"+s(952)]?this[s(1669)]["payloadE"+s(952)][s(1623)](/\s/g,"")[s(1330)+s(609)]():""},g=l[s(960)+"ncoding"]?l[s(960)+s(952)].replace(/\s/g,"")[s(1330)+"ase"]():"",S=e[s(1283)](this[s(1669)][s(1545)+"ype"],Object)?{force:!!this._options["payloadT"+s(1117)][s(887)],type:this[s(1669)][s(1545)+s(1117)][s(1653)]?this[s(1669)][s(1545)+"ype"][s(1653)][s(1623)](/\s/g,"")[s(1330)+s(609)]():""}:{force:!1,type:this._options.payloadType?this[s(1669)][s(1545)+s(1117)][s(1623)](/\s/g,"")[s(1330)+s(609)]():""},b=l[s(1545)+s(1117)]?l["payloadT"+s(1117)][s(1623)](/\s/g,"")["toLowerC"+s(609)]():"",m=S[s(887)]?S[s(1653)]:b||S.type,R=h[s(887)]?h.encoding:g||h[s(1182)],B=[e[s(1351)],e.EehOY,s(1175)+s(921)+s(742)+"=utf-8",e[s(582)]],F=[e[s(573)],e.UJXFT];this._options[s(704)+s(1225)+s(898)+"ad"]&&B.includes(m)&&(!R||F[s(967)](R))?l[s(1444)+"oad"]=dl(l[s(610)],0,l[s(610)][s(1338)+"th"]):l[s(1444)+s(926)]=""}else this[s(932)]++;else l[s(1444)+"oad"]=""}catch(h){if(e[s(1294)]!=="tuQWr"){for(_0x3618c2>>>=0;_0x2e9037>=128;)e[s(927)](_0x5205f6,_0x1ad2d4,e[s(794)](e.gnBaD(127,_0x60fd67),128)),_0x2aad15>>>=7;e[s(1003)](_0x1007c6,_0x2c8d8b,_0x34c566)}else l[s(1444)+s(926)]="",console.log(h)}a[s(464)]=l,e[s(1297)](n)}function Wp(a,n,s){let l=t,h=s||8192,g=e[l(982)](h,1),S=null,b=h;return function(m){let R=l;if(e[R(722)](m,1)||m>g)return e[R(1715)](a,m);e[R(1248)](b+m,h)&&(S=a(h),b=0);let B=n[R(493)](S,b,b+=m);return e.MmsoQ(7,b)&&(b=e[R(717)](7,b)+1),B}}let $p=4294967295;function Kp(a,n,s){let l=t;return e.DBrYO(RangeError,e[l(322)](e.BeeKO(e.rPmje(e[l(1101)](e.FXUan(e.yAOzo,a),e[l(404)]),e[l(1638)](n,1)),e[l(1502)]),s))}function Vp(a,n,s){let l=t;if(e.RDMRO(e[l(767)],l(1682))){if(e.jQajC(s,$p))throw new Error(e[l(546)]);let h=3;for(;h>=0;){let g=e[l(1703)](255,s);ga(g,a,e[l(1269)](n,h)),s>>>=8,h--}return n+4}else return 0}function Zp(a,n){let s=t,l=0,h=n,g=e[s(779)](n,4);for(;e[s(478)](h,g);){let{value:S,offset:b}=e[s(1706)](pa,a,h);h=b,l=e[s(1413)](l,8)>>>0,l+=S}return{value:l,offset:g}}function Jp(a,n,s){let l=t,h=e[l(345)].split("|"),g=0;for(;;){switch(h[g++]){case"0":if(!a)return s;continue;case"1":if(n[l(880)+"e"])return e[l(322)](n[l(880)+"e"](a,s),s);continue;case"2":if(e[l(1665)](a[l(460)],40))return e[l(1673)](fa,a,n,s)+s;continue;case"3":return e.EskUM(e[l(1673)](fa,a,n,s),s);case"4":if(n.write)return n[l(1380)](a,s)+s;continue}break}}function Yp(a,n){let s=t;if(e.aTyYp(e[s(558)],e[s(558)]))return this[s(776)].extensions;{let l=new ue(e[s(1078)](a[e.ZyIAi(n,4)]<<24|e[s(1522)](a[e[s(1221)](n,5)],16),e[s(1522)](a[n+6],8))|a[e[s(1101)](n,7)],e[s(1277)](e[s(1137)](e[s(1670)](e[s(549)](a[e.eljLr(n,0)],24),e[s(1515)](a[e[s(350)](n,1)],16)),e[s(1273)](a[e[s(358)](n,2)],8)),a[e[s(917)](n,3)]),!0);return n+=8,{value:l,offset:e.HrAyM(n,8)}}}function Xp(a,n,s){let l=t,h=a[l(1324)],g=a[l(1335)];return n[s]=g>>>24,n[s+1]=e.QCCCS(e[l(593)](g,16),255),n[e[l(1224)](s,2)]=e[l(645)](g,8)&255,n[e[l(997)](s,3)]=e[l(1640)](255,g),n[e[l(1392)](s,4)]=h>>>24,n[s+5]=e.rztcT(h,16)&255,n[e[l(1101)](s,6)]=e[l(1438)](e.QsZZy(h,8),255),n[s+7]=e[l(1313)](255,h),s+=8,s}function pa(a,n){let s=t;return a[s(526)+"8"]?{value:a[s(526)+"8"](n),offset:e.NNSdw(n,1)}:{value:e[s(1593)](255,a[n]),offset:e[s(547)](n,1)}}function ga(a,n,s){let l=t;return n[l(530)+"t8"]?n[l(530)+"t8"](a,s):n[s]=255&a,e[l(568)](s,1)}let Qp=function(a){return new Uint8Array(a)},eg=e.EcWZs!=typeof Buffer?Buffer[t(729)+t(673)]:e[t(620)](Wp,Qp,Uint8Array.prototype[t(1066)]);(()=>{let a=t;if(e[a(1318)](e.FzZwe,e.FzZwe)){let n=4294967295;return function(s,l,h=!0){let g=a,S=("1|11|3|1"+g(385)+g(1070)+"6")[g(732)]("|"),b=0;for(;;){switch(S[b++]){case"0":n=e.lFLNi(e.EpWGx(n,e[g(1302)](127,s[l])<<21),0);continue;case"1":n=e[g(411)](e[g(1757)](127,s[l]),0);continue;case"2":if(s[l++]<128)return{value:h?n:0|n,offset:l};continue;case"3":n=e.BxfBx(n,e[g(1273)](e[g(572)](127,s[l]),7))>>>0;continue;case"4":n=e[g(536)](n|e[g(1299)](e[g(1015)](15,s[l]),28),0);continue;case"5":if(s[l++]<128)return{value:h?n:e[g(1436)](0,n),offset:l};continue;case"6":return{value:h?n:e.vMMUG(0,n),offset:l};case"7":n=e[g(536)](e[g(1504)](n,e[g(1328)](127&s[l],14)),0);continue;case"8":if(e[g(954)](s[l++],128))return{value:h?n:0|n,offset:l};continue;case"9":if((l+=5)>s[g(460)])throw l=s[g(460)],Kp(l,10,s.length);continue;case"10":if(s[l++]<128)return{value:h?n:e[g(1495)](0,n),offset:l};continue;case"11":if(e[g(1194)](s[l++],128))return{value:h?n:0|n,offset:l};continue}break}}}else _0xc9f495=_0x1105d8(_0x225276),_0x1005bf=e.YiAVN(127,_0x12799a),e[a(1083)](128,_0x3c7810)&&(_0x205cd5=e[a(483)](_0x30ee6a,_0x32b73c),_0x393f22|=e.rRtoh(e[a(1162)](127,_0x3e9fbe),7))})();let tg=16,ma=32;function ng(a){let n=t,s=0,l={};for(let h=0;e[n(788)](h,a[n(460)]);h++)l[a[h][n(1253)+n(1664)]]=cl(a[h][n(1253)+n(1664)]),s+=14+l[a[h][n(1253)+n(1664)]];return[s,l]}function hl(a,n,s){let l=t,[h,g]=e[l(1499)](ng,a),S=e[l(529)](eg,h),b=0;return a[l(953)](m=>{let R=l,B=(R(1483)+R(793)+R(1531))[R(732)]("|"),F=0;for(;;){switch(B[F++]){case"0":b=e[R(986)](ga,0,S,b);continue;case"1":console[R(1164)](e[R(1488)],b);continue;case"2":console[R(1164)](e[R(474)],b);continue;case"3":b=e[R(948)](ga,g[m[R(1253)+R(1664)]],S,b);continue;case"4":b=e.UvWxO(Xp,ue[R(1184)+"er"](m[R(1424)]||n),S,b);continue;case"5":console[R(1164)](e[R(1191)],b);continue;case"6":console.log(e.yqzZC,b);continue;case"7":console[R(1164)](e[R(1404)],m,m[R(554)]);continue;case"8":console[R(1164)](e.jpaCz,b);continue;case"9":b=Vp(S,b,m.service||0);continue;case"10":b=e[R(1673)](Jp,m[R(1253)+R(1664)],S,b);continue}break}}),{frameType:ma,headers:[{key:l(1391)+"ile_name",value:s}],payload:S}}function rg(a){let n=t,s=0,l=[];for(;e[n(842)](s,a[n(1338)+"th"]);)if(e.tWHYL(n(1687),e.HfTfB)){let h=_0x3f5544.substring(0,e.WCYXA(4,_0x31feaa[_0x3968f5][n(460)])),g=h[n(1153)](_0x636101[_0x1c37a2]);_0x552a44.push(g)}else{let{offset:h}=pa(a,s);s=h;let g={cursor_name:"",cursor:0,service:0},{value:S,offset:b}=e[n(730)](Zp,a,s);g[n(554)]=S,s=b;let{value:m,offset:R}=pa(a,s);s=R,g["cursor_n"+n(1664)]=e[n(418)](dl,a,s,e[n(548)](s,m)),s+=m;let{value:B,offset:F}=Yp(a,s);g.cursor=B.toNumber(),s=F,l[n(1017)](g)}return l}function ig(){let a=t;return{frameType:ma,headers:[{key:a(1391)+"ile_name",value:a(1562)+a(487)}],payload:void 0}}class sg{constructor(n,s,l){let h=t;this[h(1478)+h(1759)]=n,this._cursorFileName=s,this[h(397)+"Strategy"]=l,this[h(1038)]=e[h(1003)](ul,this[h(1478)+"ameSpace"],e.mLLxI)}async[t(1348)](){let n=t;await this[n(1038)][n(1348)]()}async[t(1756)+"rs"](){let n=t;if(!this._qosDB[n(1030)])return;let s=this[n(397)+n(1121)],l=await this[n(1038)][n(445)]();switch(console.log(e[n(441)],l),s){case e.gWTzc:return l&&l[n(460)]?e.duPkE(hl,l,0,this["_cursorF"+n(1350)]):void 0;case e[n(495)]:return;case n(1210):return l&&l[n(460)]?e[n(693)](hl,l,0,this[n(1652)+n(1350)]):e[n(1332)](ig)}}async[t(1744)](n,s,l){let h=t;return console[h(1164)](h(564),n,s,l),this._qosDB.set({cursor_name:n,cursor:s,service:l})}async[t(1266)+"rs"](n){let s=t,l=e.Ljqix(rg,n);for(let h of l)console.log(e[s(1561)],l),await this[s(1038)][s(1744)](h)}async[t(915)](n){let s=t,l={zkqaC:function(h,g,S){return e[q(1037)](h,g,S)},OzpXG:s(1739)};if(e[s(770)](e.deTMD,s(935)))return(await this._qosDB[s(915)](n))?.[s(1424)];{let h=this[s(542)+s(879)]?.[s(1393)+"ntEndpoint"]();this[s(373)+s(1571)+"ent"](l.zkqaC(_0x5e5c1f,l[s(1403)],{code:_0x29392f[s(882)],reason:s(1209)+"ng faile"+s(1169)+s(519)+s(1577)+s(551)+h})),this[s(542)+s(879)]?.["resetEnd"+s(1422)+s(585)](),this[s(945)+s(1270)]?.resetCounter();return}}async[t(648)](){let n=t;await this._qosDB[n(648)]()}[t(622)+t(857)+t(928)](n){let s=t;this[s(1652)+"ileName"]=n}get[t(1030)](){let n=t;return this._qosDB[n(1030)]}}let og=e[t(1172)];async function xl(a){let n=t;if(!this[n(1669)][n(1145)+"S"])return null;let{aID:s,fpID:l,messageStrategy:h}=this[n(1669)],g=a||og;try{return this[n(448)+"anager"]?a&&this[n(448)+n(550)][n(622)+n(857)+n(928)](a):this[n(448)+"anager"]=new sg(l+"_"+s+"_"+g,g,h),this[n(448)+"anager"][n(1030)]||await this[n(448)+n(550)][n(1348)](),this[n(448)+n(550)]}catch{return null}}async function ag(a,n){let s=t,l=e[s(1609)](rn,a.message[s(1292)],e[s(1205)],"-1"),h=rn(a[s(464)].headers,e.sBZBQ,"1"),g=e[s(871)](rr,a[s(464)][s(1292)],e[s(875)]),S=e[s(778)](Number,rr(a[s(464)][s(1292)],e[s(1285)]))||0,b=xa.call(this,a),m=e[s(1698)](rn,a[s(464)][s(1292)],"x-msg-qos","2"),R=rr(a[s(464)][s(1292)],s(1589)+s(1446)+"e"),B=e[s(790)](Number,rr(a[s(464)][s(1292)],s(1589)+s(1716)+"ue"));if(b.isQoSAck)return e[s(1398)](n);let F=b["isQoSMes"+s(1149)]?await fl[s(493)](this):null;if(e.pOjSC(a[s(464)][s(554)],0)&&h&&!l||a[s(464)][s(554)]>0){if(g&&b["isQoSMes"+s(1149)]&&F)if(e.Fguop(s(897),e[s(1048)]))this.on(_0x2f1b31,_0x10a443);else return!!!await F[s(915)](g)&&(e[s(1290)]!==s(1760)?(this[s(373)+s(628)+s(1580)](a),await F[s(1744)](g,e[s(432)](Date[s(768)](),S))):_0x42264a[s(1164)](_0x5d548f)),e[s(520)](n);if(m){let V=await xl[s(493)](this);if(!V)return this[s(373)+"hMessage"+s(1580)](a),e.kmulL(n);let $=await V[s(915)](R)??-1;if(e[s(1634)]($,B))this[s(373)+s(628)+s(1580)](a),V[s(1744)](R,B,a.message.service);else throw new Error(s(1249)+s(1454)+s(413)+B+(" larger than loc"+s(342)+"r ")+$);return n()}return this[s(373)+s(628)+s(1580)](a),e[s(543)](n)}}async function cg(a,n){let s=t,l=xa.call(this,a);if(!l["isQoSMes"+s(1149)])return e[s(1556)](n);let h=await fl[s(493)](this);if(l[s(1069)+"anupMess"+s(1487)]&&l[s(1489)+"s"][s(460)])for(let g of l[s(1489)+"s"])await h.del(g);e[s(520)](n)}async function dg(a,n){let s=t,l=a[s(464)][s(1325)+"e"]===tg,h=e[s(959)](a[s(464)][s(1325)+"e"],ma);if(!l&&!h)return e[s(1084)](n);let g=rr(a[s(464)][s(1292)],"cursor_f"+s(864));if(!g)return n();let S=await xl[s(493)](this,g);if(!S)return n();if(l){let b=await S.getCursors(),m={frameType:b?.[s(1325)+"e"],SeqID:ue[s(1184)+"er"](this._seqId++),LogID:ue.fromNumber(this[s(1669)][s(1428)+s(518)]()),service:9e3,method:5,headers:b?.headers,payload:b?.[s(610)]},R=e[s(483)](v,m);this[s(1033)]&&this[s(1033)][s(1666)+"te"]&&this._ws.send(R)}if(h){let b=a[s(464)][s(610)];b&&S.setCursors(b)}}let lg=async function(a,n){let s=t;if(e[s(576)](s(506),e.YuwPD))this[s(604)]=!1,clearTimeout(this[s(485)+s(1733)+s(1096)]),e[s(533)](n);else{let l=e[s(523)](_0x2f5197,e[s(327)],{message:_0x153a04[s(464)],code:_0x38d81c[s(1707)+s(1704)],error:_0x855efa});this[s(373)+s(1591)+s(1342)](l)}},ug=async function(a,n){let s=t,l={mWaus:function(S,b,m){return S(b,m)},HeDtZ:e[s(597)]};if(!this[s(1033)]||e[s(1537)](this._ws[s(1666)+"te"],this[s(751)]))return e[s(1556)](n);let{pingInterval:h}=this[s(1669)];this[s(542)+s(879)]?.[s(978)+s(1422)+s(585)]();for(let S=0;S<this[s(397)+"Queue"][s(460)];S++){let b=this[s(397)+s(838)][S];if(e[s(367)](this[s(1033)][s(1666)+"te"],this[s(751)])&&e.aPhHC(null,b))if(e[s(1040)]!=="NYNra")this[s(1033)]&&this._ws[s(1383)](b),this[s(397)+"Queue"][S]=null;else{let m=this[s(1669)][s(1307)+"tInterce"+s(1695)](_0xb2d5b3,_0x143f24);this[s(373)+"hCloseEv"+s(1342)](l[s(1090)](_0x37f6b8,l[s(1052)],{code:_0x2c077c,reason:_0x4845a5,wasClean:!0,willReconnect:m})),m&&this[s(485)]()}else break}this[s(397)+s(838)]=this[s(397)+"Queue"][s(736)](S=>!!S),this[s(1449)+"gTimeoutId"]=e[s(1097)](setTimeout,()=>this[s(957)](),h),this[s(373)+s(748)+"nt"](a),this[s(491)+"er"]&&this._ws&&(this[s(1033)].binaryType=this[s(1008)+s(1117)]);let g=this["_endpoin"+s(879)]?.["getCurre"+s(1482)+"nt"]();this[s(1178)](s(772)+g+s(352)),e.uWEhi(n)},fg=async function(a,n){let s=t,l=this[s(542)+s(879)]?.[s(1393)+s(1482)+"nt"]();this[s(1178)](s(772)+l),e.cRCeK(n)};class hg extends ua{constructor(n){let s=t,l={JwvnC:function(b,m,R,B){return b(m,R,B)},uEGPy:function(b,m,R){return e.VyoXa(b,m,R)},ZqfuE:e[s(327)],FUqDJ:function(b,m){return e.jEZON(b,m)}};super(),this[s(1747)+s(363)+s(459)]=!0,this[s(491)+"er"]=nr,this[s(877)]=Rp,this._isMiniTT=Cn,this[s(992)+"X"]=Yr,this[s(1050)+"r"]=Xr,this["_message"+s(838)]=[],this[s(542)+"tManager"]=null,this[s(791)+s(664)]=!1,this[s(1008)+s(1117)]=e[s(1544)],this[s(485)+s(416)]=!1,this[s(485)+s(1733)+s(1096)]=null,this[s(381)+s(671)+s(911)]=null,this[s(1449)+"gTimeoutId"]=null,this._seqId=0,this[s(604)]=!1,this[s(949)]="",this[s(942)+s(513)]=null,this[s(448)+s(550)]=null,this[s(945)+s(1270)]=null,this._protocols=s(1207),this[s(532)]=3,this[s(466)+"NG"]=0,this[s(751)]=1,this.CLOSING=2,this[s(1730)]=b=>{let m=s;try{l[m(1326)](al,this,b,[lg,ug,fg])}catch(R){let B=l.uEGPy(dt,l.ZqfuE,{message:R[m(464)],code:nn[m(1281)+"OR"],error:R});this["_dispatc"+m(1591)+m(1342)](B)}},this[s(933)+"ge"]=async b=>{let m=s,{pingInterval:R,pingFrequency:B}=this._options;if((e.SsCRH("hi",b[m(444)])&&e[m(1241)]===B||e[m(806)](e[m(1213)],B))&&(this[m(602)+"ngTimer"](),this[m(1718)](e[m(725)],e.ODfMA),this._pingPongTimeoutId=e[m(1174)](setTimeout,this[m(957)][m(1023)](this),R)),!e.OSUEB("hi",b[m(444)]))try{e[m(706)](e[m(649)],"mcSum")?(eQczxH[m(351)](_0x4b67a3,_0x230005,82),eQczxH[m(351)](_0x567181,_0x2d5196,_0x1fac48)):e.VIrPT(al,this,b,[jp,Hp,cg,dg,ag,qp])}catch(F){let V=dt(e[m(327)],{message:F[m(464)],code:nn[m(1707)+m(1704)],error:F});this[m(373)+m(1591)+m(1342)](V)}},this._onError=b=>{let m=s,R=this[m(542)+"tManager"]?.[m(1520)+"chMaxTries"](),B=this[m(542)+"tManager"]?.["getCurre"+m(1482)+"nt"]();if(R&&!b[m(464)]){let F=m(809)+B+(" fail, m"+m(906)+m(1181)+"ed");this[m(373)+m(1591)+m(1342)](e.LgGWX(dt,e[m(327)],{message:F,code:nn[m(1319)+"IES_ERROR"],error:b}));return}this[m(1033)]&&e[m(1620)](this[m(1033)][m(1666)+"te"],this[m(751)])&&this[m(1057)+m(924)](),this[m(373)+m(1591)+m(1342)](e.rWOTf(dt,"error",{message:b.message,code:nn[m(1725)+"RROR"],error:b}))},this._onClose=async b=>{let m=s;if(e[m(961)](e[m(368)],m(1074))){let R=_0x1ca256[m(464)].payload;R&&_0xe84c45[m(1266)+"rs"](R)}else{this[m(591)+m(1099)](),this[m(602)+m(1105)](),this[m(1067)+m(1387)+"rs"](),this[m(1033)]=null,this[m(485)+m(416)]=!1;let R=this._endpointManager?.[m(1520)+"chMaxTries"]();if(!R&&this[m(1636)+m(511)]()&&!this[m(791)+m(664)])if(e[m(1173)](e[m(387)],e[m(387)]))eQczxH[m(351)](_0x100f57,_0x1b6991,eQczxH.FUqDJ(127&_0x9d12f,128)),_0x469657>>>=7;else{let B=this[m(542)+m(879)]?.[m(1393)+"ntEndpoint"](),F=this._options[m(1307)+m(873)+m(1695)](b.code,b[m(1677)]);this["_dispatc"+m(1571)+m(1342)](e[m(1684)](gt,e[m(597)],{code:1006,reason:b[m(1677)]||m(1209)+m(950)+m(1169)+m(519)+m(1577)+"ame: "+B,willReconnect:F})),F&&this[m(485)]();return}if(b[m(882)]!==1e3&&this._readyClosed){this[m(373)+m(1571)+m(1342)](e[m(1032)](gt,e[m(597)],{code:1e3,reason:e[m(919)]})),this[m(542)+"tManager"]?.[m(978)+"pointConfig"](),this[m(945)+m(1270)]?.["resetCou"+m(1186)]();return}if(e[m(770)](1e3,b[m(882)])&&R){let B=this[m(542)+m(879)]?.["getCurre"+m(1482)+"nt"](),F=b[m(1677)];F||(F=await e[m(529)](Mp,this[m(949)])),F=m(1209)+"ng faile"+m(951)+F+(m(429)+"me: ")+B+(", max retries re"+m(1481)),this["_dispatchCloseEv"+m(1342)](e[m(1389)](gt,e[m(597)],{code:b[m(882)],reason:F}));let V=m(809)+B+(m(1713)+m(906)+m(1181)+"ed");this[m(373)+m(1591)+m(1342)](e.woCfI(dt,m(870),{message:V,code:nn[m(1319)+m(562)+"R"]})),this[m(542)+m(879)]?.[m(978)+m(1422)+"fig"](),this[m(945)+m(1270)]?.["resetCou"+m(1186)]();return}if(b[m(882)]!==1e3&&!b.reason){let B=this[m(542)+m(879)]?.[m(1393)+m(1482)+"nt"]();this[m(373)+"hCloseEv"+m(1342)](e.khUYh(gt,e.JfpBI,{code:b.code,reason:"connecti"+m(950)+"d, unkno"+m(519)+m(1577)+"ame: "+B})),this[m(542)+m(879)]?.[m(978)+m(1422)+"fig"](),this[m(945)+m(1270)]?.resetCounter();return}this[m(373)+m(1571)+m(1342)](b),this._endpointManager?.["resetEnd"+m(1422)+m(585)](),this[m(945)+"sCounter"]?.["resetCou"+m(1186)]()}},this[s(925)]=null,this[s(1185)]=null,this.onmessage=null,this[s(1193)]=null,this[s(1199)+s(539)]=null,this["onReceiv"+s(323)]=null,this[s(1320)+"mediatel"+s(1464)+"ct"]=null,this[s(535)+s(815)]=this._handleOnLine[s(1023)](this),this[s(535)+s(741)]=this[s(535)+s(741)][s(1023)](this),this[s(1584)+s(786)]=this._handlePageHide[s(1023)](this),this[s(1584)+s(410)]=this._handlePageShow[s(1023)](this),this[s(1669)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(700)](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(1213)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(692)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:g}=n,S=Array[s(739)](h)?h:e.uKSBs(e[s(582)],typeof h)?[h]:[];if(!S||e[s(1080)](0,S[s(460)]))throw new Error(s(1127)+s(1690)+s(1734));if(!e.PKOCt(Dp,g))throw new Error(e[s(1340)]);Object[s(424)](this[s(1669)],n),this["_endpoin"+s(879)]=new ol(S,this[s(1669)][s(799)+"es"]),this[s(945)+"sCounter"]=new Np(this[s(1669)][s(1204)+s(666)]),this[s(1669)].automaticOpen&&(this[s(604)]=!0,this._connect()),this[s(1669)][s(1062)+s(537)+"nged"]&&(this[s(1384)+"T"]||this[s(992)+"X"]?this[s(1128)+s(1356)+"ange"]():this[s(491)+"er"]&&this[s(1612)+"balEvent"+s(1020)]())}["_handleO"+t(815)](){let n=t;if(e[n(1513)]("sVkLu",e.VUSDA)){if(this[n(1669)][n(1254)+n(1614)+"nect"]||this[n(791)+n(664)])return;this[n(996)+n(539)]()}else return _0x4882c4 instanceof _0x38dc95&&(beIKsU.lpZIk(_0x5be302,beIKsU[n(1344)])||_0x38daaf===n(989))?!0:beIKsU[n(888)](_0x5182f8,_0x157ba1)}["_handleO"+t(741)](){let n=t;this[n(383)+n(1437)+"t"]();let s=e[n(1724)](la,e[n(1548)],{message:e[n(869)]});this[n(1320)+n(1667)+"yReconnect"]&&this[n(1320)+n(1667)+n(1464)+"ct"](s)}["_initGlo"+t(454)+t(1020)](){let n=t;this[n(491)+"er"]&&window[n(1395)+n(1020)](e.DBzXS,this["_handleO"+n(815)]),this[n(491)+"er"]&&window[n(1395)+n(1020)](e.uxeRj,this[n(535)+n(741)]),this[n(491)+"er"]&&window[n(1395)+n(1020)](e[n(492)],this[n(1584)+"ageHide"]),this._isBrowser&&window[n(1395)+n(1020)](n(639),this[n(1584)+n(410)])}[t(782)+"balEventListener"](){let n=t;this._isBrowser&&window[n(1183)+n(1467)+"ner"](e.DBzXS,this[n(535)+n(815)]),this[n(491)+"er"]&&window[n(1183)+"entListener"](e[n(484)],this["_handleO"+n(741)]),this[n(491)+"er"]&&window[n(1183)+"entListe"+n(1714)](e[n(492)],this[n(1584)+"ageHide"]),this[n(491)+"er"]&&window[n(1183)+"entListe"+n(1714)](e.WoiYG,this["_handleP"+n(410)])}["_handleP"+t(786)](n){let s=t;!n[s(339)+"d"]&&(this[s(491)+"er"]&&window[s(1183)+s(1467)+s(1714)](e[s(492)],this[s(1584)+s(786)]),this[s(491)+"er"]&&window[s(1183)+s(1467)+s(1714)](e[s(1649)],this[s(1584)+"ageShow"]),this[s(1739)]()),this[s(491)+"er"]&&window[s(1183)+"entListe"+s(1714)](s(766),this[s(535)+s(815)]),this[s(491)+"er"]&&window[s(1183)+"entListener"](e[s(484)],this[s(535)+s(741)])}[t(1584)+"ageShow"](n){let s=t;n[s(339)+"d"]&&(this["_navigat"+s(511)]()&&(!this[s(1033)]||this._ws[s(1666)+"te"]!==this[s(751)]||e[s(1265)](this._ws[s(1666)+"te"],this.CONNECTING))&&this[s(535)+"nLine"](),this[s(491)+"er"]&&window[s(1395)+s(1020)](s(766),this[s(535)+"nLine"]),this[s(491)+"er"]&&window[s(1395)+s(1020)](e[s(484)],this._handleOffLine))}async[t(737)+t(1157)](n){let s=t,{fpID:l,deviceID:h,bddID:g,ttwID:S,accessKey:b,aID:m,customParams:R={},enableAutoAck:B,enableQoS:F,QoSLevel:V,env:$}=this[s(1669)],pe,rt,$e;this[s(491)+"er"]||this[s(992)+"X"]||this[s(1384)+"T"]?(pe=location&&e.QiNxQ(e[s(1617)],location[s(1019)])?e.gkbNn:s(1396),rt=n[s(1623)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),$e=/^wss(.*:\/\/)/[s(603)](n)?n:""+pe+rt):(pe=e[s(1611)],rt=n[s(1623)](/(^http)((?:[s]*:\/\/))/,""),$e=/(^ws)((?:[s]*:\/\/))/.test(rt)?rt:""+pe+rt);let it=g?e[s(1220)]:S?e[s(1303)]:s(1508)+"d",pl=g||S||h;if(!pl||!it)throw new Error(s(1127)+s(1527)+s(1381)+s(881)+s(361));let xg=e[s(1065)]("function",typeof R)?await e[s(937)](R):R,pg=$?Lp($[s(1708)],$[s(1639)]):{},wa=Object.assign({device_platform:s(914),version_code:e[s(630)],access_key:b,fpid:l,aid:m,[it]:pl,xsack:B?1:0,xaack:B?1:0,xsqos:F?1:0,qos_level:F?V:void 0,qos_sdk_version:2,...pg},xg),gg=Object[s(807)](wa)[s(1255)]((_a,ya)=>wa[ya]!==void 0?""+_a+(_a?"&":"?")+ya+"="+wa[ya]:_a,"");return $e+s(802)+gg}async[t(485)](){let n=t,s={sHzSA:function(l,h){return l<=h},wKAci:function(l,h){return e.vHViS(l,h)},gChpu:function(l,h){return l+h}};if(!(this[n(485)+n(416)]||this[n(791)+n(664)])){this[n(485)+n(416)]=!0;try{let l=this[n(542)+n(879)]?.[n(1226)+n(1012)+n(1229)+n(614)+n(822)](),{timeoutInterval:h}=this[n(1669)];if(l){let S=this["_endpoin"+n(879)]?.[n(1393)+n(1482)+"nt"](),b=this[n(542)+n(879)]?.["replaceB"+n(798)+"pointAndUpdateCount"](),m=this[n(542)+n(879)]?.[n(1393)+n(1482)+n(697)+"ount"]();if(b){let R=n(809)+S+(n(1371)+n(1485)+n(417)+n(1590)+n(1219)+n(943)+n(1064))+b+(n(1237)+"y"),B=e[n(893)](dt,"error",{message:R,code:nn[n(1319)+n(562)+"R"]});this[n(1178)](R),this[n(373)+n(1591)+n(1342)](B),this[n(949)]=await this[n(737)+n(1157)](b),this._debug(n(809)+b+" "+m+n(618)),this[n(1067)+n(1387)+"rs"]()}else{let R=n(809)+S+(n(1371)+", max re"+n(417)+n(1481));this._debug(R),this[n(373)+"hErrorEvent"](dt(n(870),{message:R,code:nn[n(1319)+"IES_ERROR"]}));return}}else{let S=this["_endpoin"+n(879)]?.[n(1393)+n(1482)+n(1494)+n(1148)](),b=this[n(542)+n(879)]?.[n(1393)+n(1482)+n(697)+n(596)]();this[n(949)]=await this[n(737)+n(1157)](S||""),this[n(1178)](n(809)+S+" "+b+n(618)),this[n(1067)+n(1387)+"rs"]()}if(this._isInit)this._isInit=!1;else if(e[n(1304)]!=="hieGt"){let S=e[n(1543)](la,n(1307)+"t",{message:n(865)});this[n(1199)+"econnect"]&&this[n(1199)+n(539)](S)}else{if(FyAknx.sHzSA(_0x1c7567,-_0x2d580a))return _0x552b4b;if(FyAknx[n(1532)](FyAknx[n(1678)](_0x88b4fb,1),_0xec017))return _0x56dd66}let g=this[n(542)+n(879)]?.["getCurre"+n(1482)+n(697)+"ount"]()||0;e[n(1248)](g,1)&&await this[n(335)](e[n(415)](g,1)),this[n(1178)](n(1209)+n(379)+this[n(949)]+" protocols: "+this[n(1026)+"ls"]),this[n(1033)]=e[n(1538)](Pp,{url:this._url,protocols:[this[n(1026)+"ls"]],headers:this[n(1669)][n(412)+n(1150)+"s"][n(1131)+n(636)]},this[n(1669)].ws),(this[n(491)+"er"]||this[n(1050)+"r"])&&this[n(1033)]&&(this[n(1033)][n(1558)+"pe"]=this[n(1008)+n(1117)]),this[n(1661)+n(702)](),this[n(485)+n(1733)+"utId"]=e.uaivB(setTimeout,this[n(1426)+"ut"][n(1023)](this),h)}catch(l){throw this["_connect"+n(416)]=!1,l}}}["_clearTi"+t(1099)](){let n=t;e[n(1289)](clearTimeout,this[n(485)+"ionTimeoutId"]),this[n(485)+n(1733)+n(1096)]=null}[t(602)+t(1105)](){let n=t;clearTimeout(this._pingPongTimeoutId),e[n(1279)](clearTimeout,this[n(381)+n(671)+"tId"]),this[n(1449)+n(1355)+"Id"]=null,this[n(381)+n(671)+n(911)]=null}[t(1178)](...n){let s=t,l={Epdjf:e[s(1341)],ctZPf:e.BVDvl,ycIVI:"MAX_RETR"+s(562)+"R",VgBCv:e.JBGpn};if(e[s(1753)](e[s(1146)],e.RKBDS)){let h=(s(1054)+"5|1")[s(732)]("|"),g=0;for(;;){switch(h[g++]){case"0":_0x26d07c[_0x50e0e0[s(1725)+s(698)]=5001]=s(1725)+s(698);continue;case"1":return _0x3682dc;case"2":_0x523f0d[_0x3fa8e3[AObZvo[s(1007)]]=5002]=AObZvo[s(1007)];continue;case"3":_0x39cc90[_0x40f2c6[AObZvo.ctZPf]=5004]=AObZvo[s(1685)];continue;case"4":_0x4e042e[_0x38733b[AObZvo[s(1523)]]=5003]=AObZvo.ycIVI;continue;case"5":_0x1f6229[_0x4aac27.OPEN_ERROR=5005]=AObZvo[s(1044)];continue}break}}else this[s(1669)][s(903)]&&console[s(1164)][s(427)](console,[e[s(696)],...n])}["_getInte"+t(1505)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:h,reconnectIntervalGrowFactor:g}=this[s(1669)],S=l*Math[s(744)](g,e[s(824)](n,1));return e.NHGjO(S,h)?h:S}[t(957)](){let n=t;if(this[n(1033)]&&e.oRNdi(this._ws[n(1666)+"te"],this[n(466)+"NG"])){this["_clearPi"+n(1105)](),this[n(1449)+"gTimeoutId"]=setTimeout(this[n(957)].bind(this),this[n(1669)][n(852)+n(1114)]);return}if(!this[n(1033)]||e.Fguop(this[n(1033)].readyState,this[n(751)]))return void this[n(996)+"econnect"]();this._ws&&this[n(1033)][n(1383)]("hi"),this["_reconne"+n(671)+"tId"]=e[n(757)](setTimeout,this[n(996)+n(539)+n(890)].bind(this),this[n(1669)]["pingTime"+n(1160)+"val"])}[t(996)+t(539)+"Timeout"](){let n=t;this._pingLossCounter?.[n(1450)](),this[n(1718)](e[n(797)],e[n(1386)]),this["_pingLos"+n(1270)]?.["checkRea"+n(1470)+"nt"]()?this[n(996)+n(539)]():this[n(957)]()}[t(1636)+t(511)](){let n=t;return this[n(1384)+"T"]||this._isMiniWX?this["_miniNav"+n(363)+"line"]:(this[n(491)+"er"]||this[n(1050)+"r"])&&this._options[n(1062)+"tworkCha"+n(1735)]?navigator.onLine:!0}[t(996)+t(539)](){let n=t;!this[n(1636)+"orOnline"]()||this[n(791)+n(664)]||(this[n(542)+"tManager"]?.[n(978)+n(1422)+"fig"](),this[n(945)+"sCounter"]?.["resetCou"+n(1186)](),this[n(1033)]?this["_disconn"+n(924)](1001,e[n(1738)],!0):this[n(485)]())}[t(1128)+"etWorkCh"+t(899)](){let n=t;this[n(1384)+"T"]?tt[n(1555)+n(1061)+n(372)](({isConnected:s})=>{let l=n;this["_miniNav"+l(363)+l(459)]=s,s?this["_handleO"+l(815)]():this[l(535)+l(741)]()}):this._isMiniWX&&wx[n(1555)+n(1061)+n(372)](({isConnected:s})=>{let l=n;this["_miniNav"+l(363)+"line"]=s,s?this[l(535)+"nLine"]():this[l(535)+l(741)]()})}_wait(n){let s={UKVKU:function(l,h,g){return e[q(1406)](l,h,g)}};return new Promise(l=>{let h=q;s[h(821)](setTimeout,l,this[h(426)+h(1505)+"e"](n))})}[t(1057)+t(924)](n=1e3,s="",l=!1){let h=t;this[h(1033)]&&this[h(383)+"WebSocket"](n,s,l)}[t(1426)+"ut"](){let n=t,s=this[n(542)+n(879)]?.[n(1393)+"ntEndpoint"]();this[n(1178)](n(809)+s+n(1371)),this[n(1057)+n(924)](1001,e.NMKyK,!0)}[t(626)](n){let s=t,l=e[s(319)](zt,n);this[s(1033)]&&e[s(1346)](this._ws[s(1666)+"te"],this[s(751)])&&(this[s(1033)]&&this[s(1033)][s(1383)](l),this[s(1178)]("send_ack",n))}["_removeW"+t(1387)+"rs"](){let n=t;this[n(1033)]&&(this[n(1033)][n(1183)+n(1467)+"ner"](e[n(1359)],this._onOpen),this[n(1033)][n(1183)+n(1467)+n(1714)](e[n(597)],this[n(428)]),this[n(1033)][n(1183)+"entListe"+n(1714)](e[n(965)],this[n(933)+"ge"]),this[n(1033)][n(1183)+n(1467)+"ner"](e[n(327)],this[n(606)]))}["_addWsLi"+t(702)](){let n=t;this[n(1033)]&&(this[n(1033)][n(1395)+n(1020)](n(1582),this[n(1730)]),this._ws[n(1395)+n(1020)](e[n(597)],this[n(428)]),this[n(1033)][n(1395)+n(1020)](e[n(965)],this[n(933)+"ge"]),this._ws[n(1395)+n(1020)](e[n(327)],this._onError))}[t(1260)+t(1473)](n=1e3,s=""){let l=t;try{e.wUPXp===e[l(1112)]?beIKsU[l(353)](_0x1a0ae3,_0x527bc2)&&_0x254a59.set(_0x18b8e9,_0x540902):this[l(1033)]&&this._ws[l(1739)](n,s)}catch{}}["_destroy"+t(1437)+"t"](n=1e3,s="",l=!1){let h=t;if(this["_clearPi"+h(1105)](),this[h(591)+h(1099)](),this[h(1067)+"sListeners"](),this["_wsInsta"+h(1473)](1e3,s),this["_connect"+h(416)]=!1,l&&this["_navigat"+h(511)]()&&!this[h(791)+h(664)]){if(this[h(542)+"tManager"]?.[h(1520)+"chMaxTries"]()){let S=this[h(542)+h(879)]?.[h(1393)+"ntEndpoint"]();this[h(373)+"hCloseEv"+h(1342)](e.iLUQn(gt,e[h(597)],{code:1006,reason:h(809)+S+(h(1371)+", max retries re"+h(1481)),wasClean:!0}))}else{let S=this[h(1669)][h(1307)+h(873)+h(1695)](n,s);this[h(373)+h(1571)+h(1342)](e[h(1490)](gt,e[h(597)],{code:n,reason:s,wasClean:!0,willReconnect:S})),S&&this[h(485)]()}return}this[h(1636)+h(511)]()||this[h(791)+h(664)]?this[h(373)+h(1571)+h(1342)](e[h(1389)](gt,h(1739),{code:n,reason:e[h(919)]})):this[h(373)+h(1571)+"ent"](e.lKzOu(gt,h(1739),{code:1006,reason:e[h(1087)]})),this[h(1033)]=null,this[h(542)+"tManager"]?.[h(978)+h(1422)+"fig"](),this[h(945)+h(1270)]?.[h(1441)+h(1186)]()}[t(373)+"hOpenEvent"](n){let s=t;this.emit(e[s(1359)],n),this[s(1193)]&&this.onopen(n)}[t(373)+t(628)+t(1580)](n){let s=t;this[s(1718)](e[s(965)],n),this[s(1607)+"e"]&&this[s(1607)+"e"](n)}[t(373)+t(1535)+t(641)](n){let s=t;this[s(1718)](e[s(1274)],n),this[s(1610)+s(323)]&&this[s(1610)+s(323)](n)}[t(373)+"hErrorEv"+t(1342)](n){let s=t;this[s(1718)](e[s(327)],n),this[s(1185)]&&this[s(1185)](n)}[t(373)+t(1571)+"ent"](n){let s=t;this[s(1718)](e[s(597)],n),this.onclose&&this[s(925)](n)}get[t(1558)+"pe"](){let n=t;return this._ws?this[n(1033)][n(1558)+"pe"]:this[n(1008)+n(1117)]}set binaryType(n){let s=t;if(e.KDgPO(s(1440),e[s(787)]))this[s(1008)+s(1117)]=n,this[s(1033)]&&(this[s(1033)][s(1558)+"pe"]=n);else return new _0x1d1baa(_0x47d2fb,{data:_0x2135ea,message:_0x321968})}get[t(1431)+"nt"](){let n=t;return this._endpointManager?.["getCurrentEndpoi"+n(697)+"ount"]()||0}get[t(375)+t(1646)](){let n=t;return this[n(397)+n(838)].reduce((l,h)=>{let g=n;return e[g(461)]!==g(1134)?this[g(1642)+"s"][this[g(1250)+g(847)]]:(l+=h&&h[g(1338)+"th"]||0,l)},0)+(this[n(1033)]?this[n(1033)][n(375)+n(1646)]:0)}get[t(1625)+"ns"](){let n=t;return this[n(1033)]?this[n(1033)].extensions:""}get[t(1019)](){let n=t;return this[n(1033)]?this[n(1033)][n(1019)]:""}get readyState(){let n=t;if(e[n(522)]===n(348))return this[n(1033)]?this[n(1033)][n(1666)+"te"]:this[n(1669)]["automati"+n(1095)]?this[n(466)+"NG"]:this.CLOSED;this[n(1661)+n(702)]()}get[t(922)](){let n=t;return this[n(1033)]?this[n(1033)][n(922)]:this._url}[t(1739)](n=1e3,s){let l=t;if(e[l(388)](e[l(637)],l(1461))){let h=e.PubxL[l(732)]("|"),g=0;for(;;){switch(h[g++]){case"0":this[l(383)+l(1437)+"t"](n,s);continue;case"1":this[l(791)+"osed"]=!0;continue;case"2":if(e.yzhMj(this[l(1033)][l(1666)+"te"],this.CLOSED)||this[l(1033)][l(1666)+"te"]===this[l(1732)])return void this[l(1178)](e[l(405)]);continue;case"3":this[l(591)+"mer"]();continue;case"4":this[l(782)+"balEvent"+l(1020)]();continue;case"5":if(!this._ws)return void this._debug(e.XLWsP);continue;case"6":this[l(942)+"ger"]?.[l(648)]();continue;case"7":this[l(602)+l(1105)]();continue}break}}else this[l(1718)](e[l(1359)],_0x3187e6),this[l(1193)]&&this[l(1193)](_0x130195)}async[t(1383)](n,s){let l=t;if(n==null)throw new Error(e[l(1166)]);e.IliIo("number",typeof n)&&(n=JSON[l(710)+"y"](n)),e[l(582)]!=typeof n&&!e[l(1283)](n,ArrayBuffer)&&!(n[l(595)]&&e[l(1471)](n[l(595)],ArrayBuffer))&&(n=JSON[l(710)+"y"](n));let h=await e[l(357)](ll,n),g=e.wnVlq(Op,n),{method:S=0,service:b=this[l(1669)][l(554)],logID:m=this._options[l(1428)+l(518)](),headers:R=this[l(1669)][l(1292)],payloadEncoding:B=this[l(1669)][l(960)+l(952)],payloadType:F=this._options[l(1545)+l(1117)],logIDNew:V=this[l(1669)]["logIDNew"+l(463)][l(1628)+l(1329)+l(362)+"ew"]?e[l(1085)](i,this[l(1669)]["logIDNew"+l(463)][l(1358)]):""}=e.UsZjk(s,{});if(!b)throw new Error(e[l(1453)]);let $={SeqID:ue[l(1184)+"er"](this[l(422)]++),LogID:ue.fromNumber(m),service:b,method:S,headers:R,payloadEncoding:e[l(318)](B,Object)?B[l(1182)]?B[l(1182)]:"":B,payloadType:e.KjCwm(F,Object)?F[l(1653)]?F[l(1653)]:g:F||g,payload:h,LogIDNew:V},pe=e.NkEkc(zt,$);if(this._ws&&e[l(601)](this[l(1033)][l(1666)+"te"],this[l(751)]))this._ws&&this._ws[l(1383)](pe),this[l(1178)]("sent",$);else if(e[l(1634)](this[l(397)+l(838)].length,this[l(1669)]["maxMessa"+l(1517)+"ength"]))this[l(397)+l(838)][l(1017)](pe),this[l(1178)](e.cqihC,$);else if(e.nEZOA(e[l(975)],e[l(975)])){let rt=_0xd6edc9(_0x3f4fb6,_0x24b756[l(460)]);_0x49ba49[l(640)][l(1744)](_0x1dc8d6,rt)}else this[l(397)+l(838)].shift(),this[l(397)+l(838)].push(pe);return{seqID:this[l(422)],logID:m,logIDNew:V}}async[t(1307)+"t"](n){let s=t,l={JnyPs:function(S,b){return e[q(1657)](S,b)},bLZni:e.SdIqe,UupmJ:s(1004)+"e_success",ttAVl:e[s(797)]},{url:h}=e[s(1001)](n,{}),g=Array[s(739)](h)?h:e[s(452)](e[s(582)],typeof h)?[h]:[];n&&Object[s(424)](this[s(1669)],n),g&&g.length?this[s(542)+"tManager"]=new ol(g,this._options.maxRetries):this["_endpoin"+s(879)]?.["resetEnd"+s(1422)+s(585)](),this[s(945)+s(1270)]?.[s(1441)+"nter"](this[s(1669)][s(1204)+s(666)]),this[s(791)+s(664)]=!1,this[s(1033)]&&e.PsHgU(this._ws[s(1666)+"te"],this[s(532)])?this[s(1057)+"ect"](1e3,s(1460)+"econnect"+s(733),!0):e[s(1689)](e.PvOhO,e.PvOhO)?(this[s(604)]=!0,this[s(485)]()):(l[s(1136)](_0x233ceb,l[s(553)]),this[s(995)](l[s(1462)],_0x4800bd),this[s(995)](l[s(723)],_0x243573))}async[t(1745)](){let n=t;if(!this[n(485)+n(416)]){if(e[n(1100)](e[n(309)],n(338)))return _0x40accb["objectSt"+n(1416)][1]?void 0:_0x2e8087[n(1423)+n(1539)](_0x37b87a[n(1423)+n(1416)][0]);{let s=e[n(1598)].split("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(945)+"sCounter"]?.[n(1441)+"nter"]();continue;case"1":this[n(542)+n(879)]?.[n(978)+n(1422)+"fig"]();continue;case"2":this["_readyCl"+n(664)]=!1;continue;case"3":this[n(485)]();continue;case"4":this[n(604)]=!0;continue}break}}}}[t(1395)+t(1020)](n,s){let l=t,h={wcnLG:function(g,S){return e[q(1058)](g,S)},fdagW:function(g,S){return g&S},YVEkh:function(g,S){return e[q(646)](g,S)},dayCL:function(g,S){return e[q(695)](g,S)},JuKrv:function(g,S){return e[q(1363)](g,S)},xodIx:function(g,S){return e[q(1245)](g,S)},lZLPQ:function(g,S){return e[q(1315)](g,S)},PgJKA:function(g,S){return e.eQUJv(g,S)},StYXu:function(g,S){return e[q(1363)](g,S)},nPaic:function(g,S){return e[q(1413)](g,S)},ApLkt:function(g,S){return e[q(398)](g,S)},mlyaV:function(g,S,b,m){return e.IGbQU(g,S,b,m)},aicXg:function(g,S){return e[q(738)](g,S)}};if(e[l(715)](e[l(872)],e.pvINi))this.on(n,s);else{if(_0x2d2cbe=pZJacm.wcnLG(pZJacm[l(1465)](127,_0x38c55e[_0x23f7ba]),0),pZJacm[l(889)](_0x230a1b[_0xca5688++],128))return{value:_0x245f20?_0x373b45:pZJacm[l(1331)](0,_0x1072a4),offset:_0x28b99d};if(_0x3c5239=pZJacm[l(1656)](pZJacm.dayCL(_0x5b3b2a,pZJacm.xodIx(127,_0xfdf4c3[_0x448285])<<7),0),pZJacm.lZLPQ(_0xef4f3d[_0x3dac30++],128))return{value:_0x11bd6c?_0x34906e:pZJacm.PgJKA(0,_0xda3898),offset:_0x119a7b};if(_0x235994=pZJacm[l(643)](pZJacm[l(1331)](_0x30e6cd,pZJacm[l(1155)](pZJacm[l(1005)](127,_0x5c7c4e[_0x39cb11]),14)),0),_0x559d7c[_0x2e6a30++]<128)return{value:_0x17983e?_0x66473c:pZJacm[l(1133)](0,_0x77bf65),offset:_0x3f3775};if(_0x314163=pZJacm[l(1656)](pZJacm[l(1331)](_0x461301,pZJacm[l(1155)](pZJacm.xodIx(127,_0x143fa3[_0x13d145]),21)),0),pZJacm[l(656)](_0x521204[_0x48f4c2++],128))return{value:_0xd94009?_0x31eea8:pZJacm[l(1740)](0,_0xaf5a28),offset:_0x56c67c};if(_0x17011e=pZJacm.JuKrv(pZJacm.PgJKA(_0x163427,pZJacm[l(1465)](15,_0x4be34b[_0x13ae7d])<<28),0),pZJacm.YVEkh(_0x36092d[_0xaa1f76++],128))return{value:_0x5e92d5?_0x459a4b:pZJacm[l(1331)](0,_0x177dbb),offset:_0x52b1b4};if((_0x1d9d78+=5)>_0x56094c[l(460)])throw _0x461496=_0xa09d7d[l(460)],pZJacm.mlyaV(_0x455562,_0x1e0133,10,_0x198655[l(460)]);return{value:_0x250f39?_0x209bdb:pZJacm[l(977)](0,_0x308e1a),offset:_0x140392}}}[t(1337)+"Event"](n){let s=t,{type:l}=n;this[s(1718)](l,n)}[t(1183)+t(1467)+t(1714)](n,s){this.off(n,s)}[t(1188)](){let n=t,s={bsKvp:function(l,h){return l(h)},vmqCT:n(1004)+n(747)+"s",JnWth:function(l,h,g){return l(h,g)},bWTWZ:e[n(797)]};return e[n(961)](e[n(1400)],e[n(366)])?new _0x1fc363(_0x4499f0,_0x264adc,_0x11e15f):new Promise((l,h)=>{let g=n,S={bkulj:function(R,B){return s[q(1102)](R,B)},nmjIm:s.vmqCT,obXcz:g(1004)+g(908)+"t",pqqFR:function(R,B){return s[g(1102)](R,B)}};this[g(602)+g(1105)](),this[g(1449)+"gTimeoutId"]=s[g(894)](setTimeout,this[g(957)][g(1023)](this),this[g(1669)][g(852)+g(1114)]);let b=()=>{let R=g;S[R(1063)](l,R(514)),this[R(995)](S.nmjIm,b),this[R(995)](S[R(359)],m)},m=()=>{let R=g;S[R(1648)](h,"timeout"),this[R(995)](S[R(1427)],b),this[R(995)](S.obXcz,m)};this.on(g(1004)+g(747)+"s",b),this.on(s[g(1750)],m),this[g(957)]()})}}})(),Ne["CustomCl"+L(443)]=Re[L(1333)+"oseEvent"],Ne[L(1475)+L(849)]=Re.CustomErrorEvent,Ne[L(1729)+"e"]=Re[L(1729)+"e"],Ne.Event=Re[L(1580)],Ne[L(891)]=Re[L(891)],Ne[L(701)+L(916)+L(837)]=Re[L(701)+L(916)+L(837)],Ne[L(916)+L(837)]=Re[L(916)+"vent"],Ne.OpenEvent=Re.OpenEvent,Ne[L(615)+L(329)]=Re[L(615)+L(329)],Ne["createCl"+L(443)]=Re[L(1189)+L(443)],Ne[L(1671)+L(849)]=Re[L(1671)+L(849)],Ne[L(1533)+"ssageEvent"]=Re["createMe"+L(1316)+"nt"],Ne.createOpenEvent=Re["createOp"+L(1630)],Ne[L(1415)+L(1345)+L(837)]=Re[L(1415)+L(1345)+L(837)],Ne[L(1060)+L(1124)]=Re["decodedF"+L(1124)],Ne[L(1435)+L(1664)]=Re[L(1435)+L(1664)];for(Uo in Re)["CustomCl"+L(443),L(1475)+"rorEvent",L(1729)+"e",L(1580),"FWS",L(701)+L(916)+L(837),L(916)+L(837),"OpenEvent",L(615)+L(329),L(1189)+L(443),L(1671)+L(849),L(1533)+L(1316)+"nt",L(970)+L(1630),"createRe"+L(1345)+"vent",L(1060)+L(1124),L(1435)+L(1664)][L(1354)](Uo)===-1&&(Ne[Uo]=Re[Uo]);var Uo;Object[L(408)+L(851)](Ne,"__esModule",{value:!0})});import{existsSync as vS,openSync as SS}from"node:fs";import{mkdir as IS}from"node:fs/promises";import{dirname as AS}from"node:path";import{fileURLToPath as kS}from"node:url";function RS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Fd(t=Q()){return vS(t.libEntry)?t.libEntry:kS(new URL("../index.ts",import.meta.url))}async function jx(t={}){let e=t.paths??Q(),r=t.entryOverride??Fd(e),i=RS(e,process.env.COZE_BRIDGE_LOG_MODE);await IS(AS(i),{recursive:!0});let o=SS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=nt(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[rs]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return TS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var TS,rs,Yo=Qe(()=>{"use strict";Kt();te();De();TS=G("spawn-daemon"),rs="COZE_BRIDGE_DAEMON"});import{spawn as v1}from"node:child_process";import{mkdir as S1,unlink as I1,writeFile as A1}from"node:fs/promises";import{dirname as k1,join as T1}from"node:path";function Vr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function R1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Vr(r)}</key>
|
|
21
|
+
<string>${Vr(i)}</string>`).join(`
|
|
22
22
|
`);return e?`
|
|
23
23
|
<key>EnvironmentVariables</key>
|
|
24
24
|
<dict>
|
|
25
25
|
${e}
|
|
26
|
-
</dict>`:""}function
|
|
26
|
+
</dict>`:""}function C1(t,e){return new Promise((r,i)=>{let o=v1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Kr,ss,ia,Kd,lp=Qe(()=>{"use strict";te();Kr=G("supervisor.launchd"),ss="ai.coze.bridge",ia=C1,Kd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
27
27
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
28
28
|
<plist version="1.0">
|
|
29
29
|
<dict>
|
|
30
30
|
<key>Label</key>
|
|
31
|
-
<string>${
|
|
31
|
+
<string>${ss}</string>
|
|
32
32
|
<key>ProgramArguments</key>
|
|
33
33
|
<array>
|
|
34
|
-
<string>${
|
|
35
|
-
<string>${
|
|
34
|
+
<string>${Vr(t.nodeBin)}</string>
|
|
35
|
+
<string>${Vr(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>${Vr(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${
|
|
47
|
+
<string>${Vr(t.logFile)}</string>${R1(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function
|
|
50
|
+
`},configPath(t){return T1(t.homeDir,"Library","LaunchAgents",`${ss}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await S1(k1(i),{recursive:!0}),await A1(i,this.renderConfig(t),"utf8"),Kr.info("plist written",{plistPath:i,activate:r}),!r)return;await ia("launchctl",["unload","-w",i]).catch(c=>Kr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ia("launchctl",["load","-w",i]),Kr.info("launchd job loaded",{label:ss});let o=process.getuid?.()??0;await ia("launchctl",["kickstart","-k",`gui/${o}/${ss}`]),Kr.info("launchd job kickstarted",{label:ss,uid:o})},async uninstall(t){let e=this.configPath(t);await ia("launchctl",["unload","-w",e]).catch(r=>Kr.warn("launchctl unload failed (ignored)",{err:String(r)})),await I1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Kr.info("launchd job removed",{plistPath:e})}}});import{spawn as P1}from"node:child_process";import{mkdir as D1,unlink as O1,writeFile as L1}from"node:fs/promises";import{dirname as N1,join as up}from"node:path";function oa(t,e){return t.isRoot?e:["--user",...e]}function B1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function aa(t,e){return new Promise((r,i)=>{let o=P1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var sa,Zr,M1,Vd,fp=Qe(()=>{"use strict";te();sa=G("supervisor.systemd"),Zr="coze-bridge.service",M1="/etc/systemd/system";Vd={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
|
+
${B1(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?
|
|
65
|
+
`},configPath(t){return t.isRoot?up(M1,Zr):up(t.homeDir,".config","systemd","user",Zr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await D1(N1(i),{recursive:!0}),await L1(i,this.renderConfig(t),"utf8"),sa.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await aa("systemctl",oa(t,["daemon-reload"])),await aa("systemctl",oa(t,r?["enable","--now",Zr]:["enable",Zr])),sa.info("systemd unit enabled",{unitName:Zr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await aa("systemctl",oa(t,["disable","--now",Zr])).catch(r=>sa.warn("systemctl disable failed (ignored)",{err:String(r)})),await O1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await aa("systemctl",oa(t,["daemon-reload"])).catch(()=>{}),sa.info("systemd unit removed",{unitPath:e})}}});import{spawn as F1}from"node:child_process";import{join as z1}from"node:path";function hp(t,e){return new Promise((r,i)=>{let o=F1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Zd,ca,Jd,xp=Qe(()=>{"use strict";te();Zd=G("supervisor.taskscheduler"),ca="CozeBridge",Jd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
|
|
66
66
|
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
67
67
|
<RegistrationInfo>
|
|
68
68
|
<Description>Coze Bridge daemon</Description>
|
|
@@ -86,48 +86,50 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return mS(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 Yh("schtasks",["/Create","/SC","ONLOGON","/TN",aa,"/TR",r,"/RU",t.userName,"/F"]),jd.info("task scheduler entry created",{task:aa,logFile:t.logFile})},async uninstall(t){await Yh("schtasks",["/Delete","/TN",aa,"/F"]).catch(e=>jd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),jd.info("task scheduler entry removed",{task:aa})}}});var Qh={};Ea(Qh,{buildContext:()=>vS,getSupervisor:()=>yS,launchdSupervisor:()=>Gd,systemdSupervisor:()=>Hd,taskSchedulerSupervisor:()=>Wd});import{homedir as wS,userInfo as _S}from"node:os";function yS(t=process.platform){switch(t){case"darwin":return Gd;case"linux":return Hd;case"win32":return Wd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function bS(){let t={};for(let e of ES){let r=process.env[e];r&&(t[e]=r)}return t}function vS(){let t=ee();return{nodeBin:process.execPath,entry:Od(t),logFile:t.logFile,homeDir:wS(),userName:_S().username,isRoot:process.getuid?.()===0,env:bS()}}var ES,ep=Ye(()=>{"use strict";Le();Zo();Vh();Zh();Xh();ES=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});re();rn();var El=q("acp-installer-warmup"),Ag=["claude-code","codex"];async function bl(t={}){let e=t.ensure??sr,i=(await Promise.allSettled(Ag.map(async o=>{let c=await e(o);El.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&El.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}an();re();import{readdir as Gg}from"node:fs/promises";import{mkdir as Al,readFile as Ug,writeFile as Tl}from"node:fs/promises";import{join as Ca}from"node:path";var qg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function cr(t,e,r){await Al(t,{recursive:!0});let i=qg[e],o=Ca(t,i);return await Tl(o,r??"","utf8"),o}async function Ra(t,e,r){let i=Ca(t,".claude");await Al(i,{recursive:!0});let o=Ca(i,"settings.local.json"),c={};try{let u=await Ug(o,"utf8"),x=JSON.parse(u);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}catch{}let l=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")l.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=r)}return c.permissions=l,await Tl(o,JSON.stringify(c,null,2),"utf8"),o}var Ve=q("agent-detail-sync"),Hg=6e4,jg=5*6e4,ps=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Gg(r)}catch(o){Ve.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ve.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Be(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ve.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Ve.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Ve.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){Ve.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ve.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Be(e,this.opts.paths);if(!i){Ve.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(x){Ve.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let p=this.retryQueue.get(e),w=p?Math.min(p.currentDelay*2,jg):Hg;this.retryQueue.set(e,{dueAt:Date.now()+w,currentDelay:w});return}if(o.agentId&&o.agentId!==e){Ve.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Ve.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ve.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ve.debug("detail sync: no diff",{agentId:e});return}await Qe(i,this.opts.paths),Ve.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Ve.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await cr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Vf=Ft(ou(),1);import{lstat as Hc,mkdir as jc,readFile as jf,readdir as S_,rm as I_,stat as A_,writeFile as Wc}from"node:fs/promises";import{dirname as T_,join as Dt,normalize as C_,relative as Vc,resolve as Kc,sep as Wf}from"node:path";import{Readable as Kf}from"node:stream";import{pipeline as $f}from"node:stream/promises";import fm from"events";import et from"fs";import{EventEmitter as Cc}from"node:events";import qu from"node:stream";import{StringDecoder as xm}from"node:string_decoder";import ju from"node:path";import yr from"node:fs";import{dirname as Am,parse as Tm}from"path";import{EventEmitter as Nm}from"events";import dc from"assert";import{Buffer as qn}from"buffer";import*as uu from"zlib";import Mm from"zlib";import{posix as xr}from"node:path";import{basename as dw}from"node:path";import $s from"fs";import Ct from"fs";import wu from"path";import{win32 as Ew}from"node:path";import Iu from"path";import of from"node:fs";import Fw from"node:assert";import{randomBytes as af}from"node:crypto";import ie from"node:fs";import Me from"node:path";import cf from"fs";import no from"node:fs";import Ei from"node:path";import st from"node:fs";import Ww from"node:fs/promises";import Zs from"node:path";import{join as _f}from"node:path";import it from"node:fs";import bf from"node:path";var lm=Object.defineProperty,um=(t,e)=>{for(var r in e)lm(t,r,{get:e[r],enumerable:!0})},au=typeof process=="object"&&process?process:{stdout:null,stderr:null},hm=t=>!!t&&typeof t=="object"&&(t instanceof jn||t instanceof qu||pm(t)||gm(t)),pm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.pipe=="function"&&t.pipe!==qu.Writable.prototype.pipe,gm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.write=="function"&&typeof t.end=="function",zt=Symbol("EOF"),Ut=Symbol("maybeEmitEnd"),dn=Symbol("emittedEnd"),ys=Symbol("emittingEnd"),ii=Symbol("emittedError"),Es=Symbol("closed"),cu=Symbol("read"),bs=Symbol("flush"),du=Symbol("flushChunk"),ht=Symbol("encoding"),fr=Symbol("decoder"),Fe=Symbol("flowing"),si=Symbol("paused"),mr=Symbol("resume"),ze=Symbol("buffer"),Je=Symbol("pipes"),Ue=Symbol("bufferLength"),Na=Symbol("bufferPush"),vs=Symbol("bufferShift"),$e=Symbol("objectMode"),Ie=Symbol("destroyed"),Ma=Symbol("error"),Ba=Symbol("emitData"),lu=Symbol("emitEnd"),Fa=Symbol("emitEnd2"),It=Symbol("async"),za=Symbol("abort"),Ss=Symbol("aborted"),oi=Symbol("signal"),Pn=Symbol("dataListeners"),rt=Symbol("discarded"),ai=t=>Promise.resolve().then(t),mm=t=>t(),wm=t=>t==="end"||t==="finish"||t==="prefinish",_m=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,ym=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Gu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[mr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Em=class extends Gu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},bm=t=>!!t.objectMode,vm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",jn=class extends Cc{[Fe]=!1;[si]=!1;[Je]=[];[ze]=[];[$e];[ht];[It];[fr];[zt]=!1;[dn]=!1;[ys]=!1;[Es]=!1;[ii]=null;[Ue]=0;[Ie]=!1;[oi];[Ss]=!1;[Pn]=0;[rt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");bm(e)?(this[$e]=!0,this[ht]=null):vm(e)?(this[ht]=e.encoding,this[$e]=!1):(this[$e]=!1,this[ht]=null),this[It]=!!e.async,this[fr]=this[ht]?new xm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[ze]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Je]});let{signal:r}=e;r&&(this[oi]=r,r.aborted?this[za]():r.addEventListener("abort",()=>this[za]()))}get bufferLength(){return this[Ue]}get encoding(){return this[ht]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[$e]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[za](){this[Ss]=!0,this.emit("abort",this[oi]?.reason),this.destroy(this[oi]?.reason)}get aborted(){return this[Ss]}set aborted(t){}write(t,e,r){if(this[Ss])return!1;if(this[zt])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"&&(r=e,e="utf8"),e||(e="utf8");let i=this[It]?ai:mm;if(!this[$e]&&!Buffer.isBuffer(t)){if(ym(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(_m(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[$e]?(this[Fe]&&this[Ue]!==0&&this[bs](!0),this[Fe]?this.emit("data",t):this[Na](t),this[Ue]!==0&&this.emit("readable"),r&&i(r),this[Fe]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[fr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[fr].write(t)),this[Fe]&&this[Ue]!==0&&this[bs](!0),this[Fe]?this.emit("data",t):this[Na](t),this[Ue]!==0&&this.emit("readable"),r&&i(r),this[Fe]):(this[Ue]!==0&&this.emit("readable"),r&&i(r),this[Fe])}read(t){if(this[Ie])return null;if(this[rt]=!1,this[Ue]===0||t===0||t&&t>this[Ue])return this[Ut](),null;this[$e]&&(t=null),this[ze].length>1&&!this[$e]&&(this[ze]=[this[ht]?this[ze].join(""):Buffer.concat(this[ze],this[Ue])]);let e=this[cu](t||null,this[ze][0]);return this[Ut](),e}[cu](t,e){if(this[$e])this[vs]();else{let r=e;t===r.length||t===null?this[vs]():typeof r=="string"?(this[ze][0]=r.slice(t),e=r.slice(0,t),this[Ue]-=t):(this[ze][0]=r.subarray(t),e=r.subarray(0,t),this[Ue]-=t)}return this.emit("data",e),!this[ze].length&&!this[zt]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[zt]=!0,this.writable=!1,(this[Fe]||!this[si])&&this[Ut](),this}[mr](){this[Ie]||(!this[Pn]&&!this[Je].length&&(this[rt]=!0),this[si]=!1,this[Fe]=!0,this.emit("resume"),this[ze].length?this[bs]():this[zt]?this[Ut]():this.emit("drain"))}resume(){return this[mr]()}pause(){this[Fe]=!1,this[si]=!0,this[rt]=!1}get destroyed(){return this[Ie]}get flowing(){return this[Fe]}get paused(){return this[si]}[Na](t){this[$e]?this[Ue]+=1:this[Ue]+=t.length,this[ze].push(t)}[vs](){return this[$e]?this[Ue]-=1:this[Ue]-=this[ze][0].length,this[ze].shift()}[bs](t=!1){do;while(this[du](this[vs]())&&this[ze].length);!t&&!this[ze].length&&!this[zt]&&this.emit("drain")}[du](t){return this.emit("data",t),this[Fe]}pipe(t,e){if(this[Ie])return t;this[rt]=!1;let r=this[dn];return e=e||{},t===au.stdout||t===au.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Je].push(e.proxyErrors?new Em(this,t,e):new Gu(this,t,e)),this[It]?ai(()=>this[mr]()):this[mr]()),t}unpipe(t){let e=this[Je].find(r=>r.dest===t);e&&(this[Je].length===1?(this[Fe]&&this[Pn]===0&&(this[Fe]=!1),this[Je]=[]):this[Je].splice(this[Je].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[rt]=!1,this[Pn]++,!this[Je].length&&!this[Fe]&&this[mr]();else if(t==="readable"&&this[Ue]!==0)super.emit("readable");else if(wm(t)&&this[dn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ii]){let i=e;this[It]?ai(()=>i.call(this,this[ii])):i.call(this,this[ii])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Pn]=this.listeners("data").length,this[Pn]===0&&!this[rt]&&!this[Je].length&&(this[Fe]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Pn]=0,!this[rt]&&!this[Je].length&&(this[Fe]=!1)),e}get emittedEnd(){return this[dn]}[Ut](){!this[ys]&&!this[dn]&&!this[Ie]&&this[ze].length===0&&this[zt]&&(this[ys]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Es]&&this.emit("close"),this[ys]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Ie&&this[Ie])return!1;if(t==="data")return!this[$e]&&!r?!1:this[It]?(ai(()=>this[Ba](r)),!0):this[Ba](r);if(t==="end")return this[lu]();if(t==="close"){if(this[Es]=!0,!this[dn]&&!this[Ie])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ii]=r,super.emit(Ma,r);let o=!this[oi]||this.listeners("error").length?super.emit("error",r):!1;return this[Ut](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ut](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Ut](),i}[Ba](t){for(let r of this[Je])r.dest.write(t)===!1&&this.pause();let e=this[rt]?!1:super.emit("data",t);return this[Ut](),e}[lu](){return this[dn]?!1:(this[dn]=!0,this.readable=!1,this[It]?(ai(()=>this[Fa]()),!0):this[Fa]())}[Fa](){if(this[fr]){let e=this[fr].end();if(e){for(let r of this[Je])r.dest.write(e);this[rt]||super.emit("data",e)}}for(let e of this[Je])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[$e]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[$e]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[$e])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ht]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ie,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[rt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[zt])return e();let i,o,c=p=>{this.off("data",l),this.off("end",u),this.off(Ie,x),e(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(Ie,x),this.pause(),i({value:p,done:!!this[zt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Ie,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((p,w)=>{o=w,i=p,this.once(Ie,x),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[rt]=!1;let t=!1,e=()=>(this.pause(),this.off(Ma,e),this.off(Ie,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Ma,e),this.once(Ie,e),{next:r,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[rt]=!0,this[ze].length=0,this[Ue]=0;let e=this;return typeof e.close=="function"&&!this[Es]&&e.close(),t?this.emit("error",t):this.emit(Ie),this}static get isStream(){return hm}},Sm=et.writev,_n=Symbol("_autoClose"),wt=Symbol("_close"),ci=Symbol("_ended"),le=Symbol("_fd"),Ua=Symbol("_finished"),jt=Symbol("_flags"),qa=Symbol("_flush"),ac=Symbol("_handleChunk"),cc=Symbol("_makeBuf"),_i=Symbol("_mode"),Is=Symbol("_needDrain"),br=Symbol("_onerror"),vr=Symbol("_onopen"),Ga=Symbol("_onread"),wr=Symbol("_onwrite"),yn=Symbol("_open"),mt=Symbol("_path"),hn=Symbol("_pos"),At=Symbol("_queue"),_r=Symbol("_read"),Ha=Symbol("_readSize"),Ht=Symbol("_reading"),di=Symbol("_remain"),ja=Symbol("_size"),Ns=Symbol("_write"),On=Symbol("_writing"),Ms=Symbol("_defaultFlag"),Un=Symbol("_errored"),Rc=class extends jn{[Un]=!1;[le];[mt];[Ha];[Ht]=!1;[ja];[di];[_n];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Un]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ha]=e.readSize||16*1024*1024,this[Ht]=!1,this[ja]=typeof e.size=="number"?e.size:1/0,this[di]=this[ja],this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[_r]():this[yn]()}get fd(){return this[le]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[yn](){et.open(this[mt],"r",(t,e)=>this[vr](t,e))}[vr](t,e){t?this[br](t):(this[le]=e,this.emit("open",e),this[_r]())}[cc](){return Buffer.allocUnsafe(Math.min(this[Ha],this[di]))}[_r](){if(!this[Ht]){this[Ht]=!0;let t=this[cc]();if(t.length===0)return process.nextTick(()=>this[Ga](null,0,t));et.read(this[le],t,0,t.length,null,(e,r,i)=>this[Ga](e,r,i))}}[Ga](t,e,r){this[Ht]=!1,t?this[br](t):this[ac](e,r)&&this[_r]()}[wt](){if(this[_n]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[br](t){this[Ht]=!0,this[wt](),this.emit("error",t)}[ac](t,e){let r=!1;return this[di]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[di]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[_r](),!1;case"error":return this[Un]?!1:(this[Un]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Im=class extends Rc{[yn](){let t=!0;try{this[vr](null,et.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[_r](){let t=!0;try{if(!this[Ht]){this[Ht]=!0;do{let e=this[cc](),r=e.length===0?0:et.readSync(this[le],e,0,e.length,null);if(!this[ac](r,e))break}while(!0);this[Ht]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[_n]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.closeSync(t),this.emit("close")}}},Ys=class extends fm{readable=!1;writable=!0;[Un]=!1;[On]=!1;[ci]=!1;[At]=[];[Is]=!1;[mt];[_i];[_n];[le];[Ms];[jt];[Ua]=!1;[hn];constructor(t,e){e=e||{},super(e),this[mt]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[_i]=e.mode===void 0?438:e.mode,this[hn]=typeof e.start=="number"?e.start:void 0,this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[hn]!==void 0?"r+":"w";this[Ms]=e.flags===void 0,this[jt]=e.flags===void 0?r:e.flags,this[le]===void 0&&this[yn]()}emit(t,...e){if(t==="error"){if(this[Un])return!1;this[Un]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[mt]}[br](t){this[wt](),this[On]=!0,this.emit("error",t)}[yn](){et.open(this[mt],this[jt],this[_i],(t,e)=>this[vr](t,e))}[vr](t,e){this[Ms]&&this[jt]==="r+"&&t&&t.code==="ENOENT"?(this[jt]="w",this[yn]()):t?this[br](t):(this[le]=e,this.emit("open",e),this[On]||this[qa]())}end(t,e){return t&&this.write(t,e),this[ci]=!0,!this[On]&&!this[At].length&&typeof this[le]=="number"&&this[wr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ci]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[On]||this[At].length?(this[At].push(t),this[Is]=!0,!1):(this[On]=!0,this[Ns](t),!0)}[Ns](t){et.write(this[le],t,0,t.length,this[hn],(e,r)=>this[wr](e,r))}[wr](t,e){t?this[br](t):(this[hn]!==void 0&&typeof e=="number"&&(this[hn]+=e),this[At].length?this[qa]():(this[On]=!1,this[ci]&&!this[Ua]?(this[Ua]=!0,this[wt](),this.emit("finish")):this[Is]&&(this[Is]=!1,this.emit("drain"))))}[qa](){if(this[At].length===0)this[ci]&&this[wr](null,0);else if(this[At].length===1)this[Ns](this[At].pop());else{let t=this[At];this[At]=[],Sm(this[le],t,this[hn],(e,r)=>this[wr](e,r))}}[wt](){if(this[_n]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Hu=class extends Ys{[yn](){let t;if(this[Ms]&&this[jt]==="r+")try{t=et.openSync(this[mt],this[jt],this[_i])}catch(e){if(e?.code==="ENOENT")return this[jt]="w",this[yn]();throw e}else t=et.openSync(this[mt],this[jt],this[_i]);this[vr](null,t)}[wt](){if(this[_n]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.closeSync(t),this.emit("close")}}[Ns](t){let e=!0;try{this[wr](null,et.writeSync(this[le],t,0,t.length,this[hn])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},Cm=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"]]),Rm=t=>!!t.sync&&!!t.file,km=t=>!t.sync&&!!t.file,Dm=t=>!!t.sync&&!t.file,Pm=t=>!t.sync&&!t.file,Om=t=>!!t.file,Lm=t=>Cm.get(t)||t,kc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Lm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ci=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let x=kc(c);if(o?.(x,l),Rm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(km(x)){let p=e(x,l);return u?p.then(()=>u(),u):p}else if(Dm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(Pm(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Bm=Mm.constants||{ZLIB_VERNUM:4736},kt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Bm)),Fm=qn.concat,fu=Object.getOwnPropertyDescriptor(qn,"concat"),zm=t=>t,Wa=fu?.writable===!0||fu?.set!==void 0?t=>{qn.concat=t?zm:Fm}:t=>{},Gn=Symbol("_superWrite"),As=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Ka=Symbol("flushFlag"),Dc=class extends jn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof uu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new uu[e](t)}catch(r){throw new As(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 As(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return dc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(qn.alloc(0),{[Ka]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Gn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=qn.from(t,e)),this.#e)return;dc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Wa(!0);let l;try{let x=typeof t[Ka]=="number"?t[Ka]:this.#r;l=this.#t._processChunk(t,x),Wa(!1)}catch(x){Wa(!1),this.#o(new As(x,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",x=>this.#o(new As(x,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];u=this[Gn](qn.from(x));for(let p=1;p<l.length;p++)u=this[Gn](l[p])}else u=this[Gn](qn.from(l));return r&&r(),u}},Wu=class extends Dc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||kt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||kt.Z_FINISH,t.fullFlushFlag=kt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(kt.Z_SYNC_FLUSH),dc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},Um=class extends Wu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Gn](t){return this.#e?(this.#e=!1,t[9]=255,super[Gn](t)):super[Gn](t)}},qm=class extends Wu{constructor(t){super(t,"Unzip")}},Ku=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||kt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||kt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=kt.BROTLI_OPERATION_FLUSH,super(t,e)}},Gm=class extends Ku{constructor(t){super(t,"BrotliCompress")}},Hm=class extends Ku{constructor(t){super(t,"BrotliDecompress")}},$u=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||kt.ZSTD_e_continue,t.finishFlush=t.finishFlush||kt.ZSTD_e_end,t.fullFlushFlag=kt.ZSTD_e_flush,super(t,e)}},jm=class extends $u{constructor(t){super(t,"ZstdCompress")}},Wm=class extends $u{constructor(t){super(t,"ZstdDecompress")}},Km=(t,e)=>{if(Number.isSafeInteger(t))t<0?Vm(t,e):$m(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},$m=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Vm=(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]=Vu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Ju(o))}},Jm=t=>{let e=t[0],r=e===128?Ym(t.subarray(1,t.length)):e===255?Zm(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},Zm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Vu(c):c===0?l=c:(i=!0,l=Ju(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Ym=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},Vu=t=>(255^t)&255,Ju=t=>(255^t)+1&255,Xm={};um(Xm,{code:()=>Pc,isCode:()=>Bs,isName:()=>Qm,name:()=>Xs,normalFsTypes:()=>Zu});var Bs=t=>Xs.has(t),Qm=t=>Pc.has(t),Zu=new Set(["0","","1","2","3","4","5","6","7","D"]),Xs=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Pc=new Map(Array.from(Xs).map(t=>[t[1],t[0]])),Hn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Ln(t,e+156,1),c=Zu.has(o),l=c?r:void 0,u=c?i:void 0;if(this.path=l?.path??Ln(t,e,100),this.mode=l?.mode??u?.mode??pn(t,e+100,8),this.uid=l?.uid??u?.uid??pn(t,e+108,8),this.gid=l?.gid??u?.gid??pn(t,e+116,8),this.size=l?.size??u?.size??pn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??$a(t,e+136,12),this.cksum=pn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Bs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ln(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Ln(t,e+265,32),this.gname=l?.gname??u?.gname??Ln(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??pn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??pn(t,e+337,8)??0,t[e+475]!==0){let p=Ln(t,e+345,155);this.path=p+"/"+this.path}else{let p=Ln(t,e+345,130);p&&(this.path=p+"/"+this.path),this.atime=r?.atime??i?.atime??$a(t,e+476,12),this.ctime=r?.ctime??i?.ctime??$a(t,e+488,12)}let x=256;for(let p=e;p<e+148;p++)x+=t[p];for(let p=e+156;p<e+512;p++)x+=t[p];this.cksumValid=x===this.cksum,this.cksum===void 0&&x===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=ew(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Nn(t,e,100,o)||this.needPax,this.needPax=gn(t,e+100,8,this.mode)||this.needPax,this.needPax=gn(t,e+108,8,this.uid)||this.needPax,this.needPax=gn(t,e+116,8,this.gid)||this.needPax,this.needPax=gn(t,e+124,12,this.size)||this.needPax,this.needPax=Va(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Nn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Nn(t,e+265,32,this.uname)||this.needPax,this.needPax=Nn(t,e+297,32,this.gname)||this.needPax,this.needPax=gn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=gn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Nn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Nn(t,e+345,155,c)||this.needPax:(this.needPax=Nn(t,e+345,130,c)||this.needPax,this.needPax=Va(t,e+476,12,this.atime)||this.needPax,this.needPax=Va(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,gn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Xs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Pc.get(t));if(Bs(e)||e==="Unsupported")this.#e=e;else if(Bs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},ew=(t,e)=>{let r=t,i="",o,c=xr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=xr.dirname(r),r=xr.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=xr.join(xr.basename(i),r),i=xr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Ln=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),$a=(t,e,r)=>tw(pn(t,e,r)),tw=t=>t===void 0?void 0:new Date(t*1e3),pn=(t,e,r)=>Number(t[e])&128?Jm(t.subarray(e,e+r)):rw(t,e,r),nw=t=>isNaN(t)?void 0:t,rw=(t,e,r)=>nw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),iw={12:8589934591,8:2097151},gn=(t,e,r,i)=>i===void 0?!1:i>iw[r]||i<0?(Km(i,t.subarray(e,e+r)),!0):(sw(t,e,r,i),!1),sw=(t,e,r,i)=>t.write(ow(i,r),e,r,"ascii"),ow=(t,e)=>aw(Math.floor(t).toString(8),e),aw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Va=(t,e,r,i)=>i===void 0?!1:gn(t,e,r,i.getTime()/1e3),cw=new Array(156).join("\0"),Nn=(t,e,r,i)=>i===void 0?!1:(t.write(i+cw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Ks=class Yu{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 Hn({path:("PaxHeader/"+dw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
-
`,c=Buffer.byteLength(o),
|
|
91
|
-
`).reduce(fw,Object.create(null)),fw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Y=xw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),hw=class extends jn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=Y(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?Y(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=Y(t.path)),t.linkpath&&(t.linkpath=Y(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Qs=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},pw=1024*1024,lc=Buffer.from([31,139]),uc=Buffer.from([40,181,47,253]),gw=Math.max(lc.length,uc.length),ct=Symbol("state"),Mn=Symbol("writeEntry"),qt=Symbol("readEntry"),Ja=Symbol("nextEntry"),xu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),li=Symbol("globalExtendedHeader"),ln=Symbol("meta"),hu=Symbol("emitMeta"),me=Symbol("buffer"),Gt=Symbol("queue"),un=Symbol("ended"),Za=Symbol("emittedEnd"),Bn=Symbol("emit"),ke=Symbol("unzip"),Ts=Symbol("consumeChunk"),Cs=Symbol("consumeChunkSub"),Ya=Symbol("consumeBody"),pu=Symbol("consumeMeta"),gu=Symbol("consumeHeader"),ui=Symbol("consuming"),Xa=Symbol("bufferConcat"),Rs=Symbol("maybeEnd"),hr=Symbol("writing"),fn=Symbol("aborted"),ks=Symbol("onDone"),Fn=Symbol("sawValidEntry"),Ds=Symbol("sawNullBlock"),Ps=Symbol("sawEOF"),mu=Symbol("closeStream"),mw=()=>!0,Ti=class extends Nm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Gt]=[];[me];[qt];[Mn];[ct]="begin";[ln]="";[Tt];[li];[un]=!1;[ke];[fn]=!1;[Fn];[Ds]=!1;[Ps]=!1;[hr]=!1;[ui]=!1;[Za]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(ks,()=>{(this[ct]==="begin"||this[Fn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(ks,t.ondone):this.on(ks,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||pw,this.filter=typeof t.filter=="function"?t.filter:mw;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[mu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Qs(this,t,e,r)}[gu](t,e){this[Fn]===void 0&&(this[Fn]=!1);let r;try{r=new Hn(t,e,this[Tt],this[li])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ds]?(this[Ps]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Bn]("eof")):(this[Ds]=!0,this[Bn]("nullBlock"));else if(this[Ds]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Mn]=new hw(r,this[Tt],this[li]);if(!this[Fn])if(o.remain){let c=()=>{o.invalid||(this[Fn]=!0)};o.on("end",c)}else this[Fn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Bn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[ln]="",o.on("data",c=>this[ln]+=c),this[ct]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Bn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[qt]?this[Gt].push(o):(this[Gt].push(o),this[Ja]())))}}}[mu](){queueMicrotask(()=>this.emit("close"))}[xu](t){let e=!0;if(!t)this[qt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[qt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ja]()),e=!1);return e}[Ja](){do;while(this[xu](this[Gt].shift()));if(this[Gt].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[hr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ya](t,e){let r=this[Mn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[ct]="header",this[Mn]=void 0,r.end()),o.length}[pu](t,e){let r=this[Mn],i=this[Ya](t,e);return!this[Mn]&&r&&this[hu](r),i}[Bn](t,e,r){this[Gt].length===0&&!this[qt]?this.emit(t,e,r):this[Gt].push([t,e,r])}[hu](t){switch(this[Bn]("meta",this[ln]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Ks.parse(this[ln],this[Tt],!1);break;case"GlobalExtendedHeader":this[li]=Ks.parse(this[ln],this[li],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[ln].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[ln].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[fn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[fn])return r?.(),!1;if((this[ke]===void 0||this.brotli===void 0&&this[ke]===!1)&&t){if(this[me]&&(t=Buffer.concat([this[me],t]),this[me]=void 0),t.length<gw)return this[me]=t,r?.(),!0;for(let l=0;this[ke]===void 0&&l<lc.length;l++)t[l]!==lc[l]&&(this[ke]=!1);let o=!1;if(this[ke]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<uc.length;l++)if(t[l]!==uc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[ke]===!1&&c)if(t.length<512)if(this[un])this.brotli=!0;else return this[me]=t,r?.(),!0;else try{new Hn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[ke]===void 0||this[ke]===!1&&(this.brotli||o)){let l=this[un];this[un]=!1,this[ke]=this[ke]===void 0?new qm({}):o?new Wm({}):new Hm({}),this[ke].on("data",x=>this[Ts](x)),this[ke].on("error",x=>this.abort(x)),this[ke].on("end",()=>{this[un]=!0,this[Ts]()}),this[hr]=!0;let u=!!this[ke][l?"end":"write"](t);return this[hr]=!1,r?.(),u}}this[hr]=!0,this[ke]?this[ke].write(t):this[Ts](t),this[hr]=!1;let i=this[Gt].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[Gt].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Xa](t){t&&!this[fn]&&(this[me]=this[me]?Buffer.concat([this[me],t]):t)}[Rs](){if(this[un]&&!this[Za]&&!this[fn]&&!this[ui]){this[Za]=!0;let t=this[Mn];if(t&&t.blockRemain){let e=this[me]?this[me].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[me]&&t.write(this[me]),t.end()}this[Bn](ks)}}[Ts](t){if(this[ui]&&t)this[Xa](t);else if(!t&&!this[me])this[Rs]();else if(t){if(this[ui]=!0,this[me]){this[Xa](t);let e=this[me];this[me]=void 0,this[Cs](e)}else this[Cs](t);for(;this[me]&&this[me]?.length>=512&&!this[fn]&&!this[Ps];){let e=this[me];this[me]=void 0,this[Cs](e)}this[ui]=!1}(!this[me]||this[un])&&this[Rs]()}[Cs](t){let e=0,r=t.length;for(;e+512<=r&&!this[fn]&&!this[Ps];)switch(this[ct]){case"begin":case"header":this[gu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ya](t,e);break;case"meta":e+=this[pu](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<r&&(this[me]=this[me]?Buffer.concat([t.subarray(e),this[me]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[fn]||(this[ke]?(t&&this[ke].write(t),this[ke].end()):(this[un]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Rs]())),this}},yi=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)},ww=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},Xu=(t,e)=>{let r=new Map(e.map(c=>[yi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Tm(c).root||".",x;if(c===u)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(Am(c),u)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(yi(c)):c=>o(yi(c))},_w=t=>{let e=new Ti(t),r=t.file,i;try{i=yr.openSync(r,"r");let o=yr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=yr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let x=yr.readSync(i,u,0,c,l);if(x===0)break;l+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{yr.closeSync(i)}catch{}}},yw=(t,e)=>{let r=new Ti(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),yr.stat(o,(u,x)=>{if(u)l(u);else{let p=new Rc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},Sr=Ci(_w,yw,t=>new Ti(t),t=>new Ti(t),(t,e)=>{e?.length&&Xu(t,e),t.noResume||ww(t)}),Qu=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:bw,parse:_u}=Ew,Oc=t=>{let e="",r=_u(t);for(;bw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=_u(t)}return[e,t]},eo=["|","<",">","?",":"],Lc=eo.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),vw=new Map(eo.map((t,e)=>[t,Lc[e]])),Sw=new Map(Lc.map((t,e)=>[t,eo[e]])),yu=t=>eo.reduce((e,r)=>e.split(r).join(vw.get(r)),t),Iw=t=>Lc.reduce((e,r)=>e.split(r).join(Sw.get(r)),t),ef=(t,e)=>e?(t=Y(t).replace(/^\.(\/|$)/,""),yi(e)+"/"+t):Y(t),Aw=16*1024*1024,Eu=Symbol("process"),bu=Symbol("file"),vu=Symbol("directory"),fc=Symbol("symlink"),Su=Symbol("hardlink"),fi=Symbol("header"),Fs=Symbol("read"),xc=Symbol("lstat"),zs=Symbol("onlstat"),hc=Symbol("onread"),pc=Symbol("onreadlink"),gc=Symbol("openfile"),mc=Symbol("onopenfile"),mn=Symbol("close"),Vs=Symbol("mode"),wc=Symbol("awaitDrain"),Qa=Symbol("ondrain"),Rt=Symbol("prefix"),tf=class extends jn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=kc(e);super(),this.path=Y(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Aw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Y(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Y(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Oc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Iw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Y(r.absolute||wu.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[xc]()}warn(t,e,r={}){return Qs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[xc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[zs](e)})}[zs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Rw(t),this.emit("stat",t),this[Eu]()}[Eu](){switch(this.type){case"File":return this[bu]();case"Directory":return this[vu]();case"SymbolicLink":return this[fc]();default:return this.end()}}[Vs](t){return Qu(t,this.type==="Directory",this.portable)}[Rt](t){return ef(t,this.prefix)}[fi](){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 Hn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Vs](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 Ks({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)}[vu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[fi](),this.end()}[fc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){this.linkpath=Y(t),this[fi](),this.end()}[Su](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Y(wu.relative(this.cwd,t)),this.stat.size=0,this[fi](),this.end()}[bu](){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[Su](e);this.linkCache.set(t,this.absolute)}if(this[fi](),this.stat.size===0)return this.end();this[gc]()}[gc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){if(this.fd=t,this.#e)return this[mn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Fs]()}[Fs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Ct.read(t,e,r,i,o,(c,l)=>{if(c)return this[mn](()=>this.emit("error",c));this[hc](l)})}[mn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[hc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[mn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[mn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Qa]():this[wc](()=>this[Qa]())}[wc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Qa](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[mn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Fs]()}},Tw=class extends tf{sync=!0;[xc](){this[zs](Ct.lstatSync(this.absolute))}[fc](){this[pc](Ct.readlinkSync(this.absolute))}[gc](){this[mc](Ct.openSync(this.absolute,"r"))}[Fs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let l=Ct.readSync(e,r,i,o,c);this[hc](l),t=!1}finally{if(t)try{this[mn](()=>{})}catch{}}}[wc](t){t()}[mn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},Cw=class extends jn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Qs(this,t,e,r)}constructor(t,e={}){let r=kc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=Y(t.path),this.mode=t.mode!==void 0?this[Vs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?Y(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Oc(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Hn({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 Ks({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Rt](t){return ef(t,this.prefix)}[Vs](t){return Qu(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}},Rw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",kw=class Er{tail;head;length=0;static create(e=[]){return new Er(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++)Pw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Ow(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 Er;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 Er;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 Er;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 Er;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<r;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=Dw(this,o,l);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function Dw(t,e,r){let i=e,o=e?e.next:t.head,c=new Nc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Pw(t,e){t.tail=new Nc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Ow(t,e){t.head=new Nc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Nc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Au=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Tu=Buffer.alloc(1024),Us=Symbol("onStat"),xi=Symbol("ended"),pt=Symbol("queue"),hi=Symbol("pendingLinks"),xn=Symbol("current"),zn=Symbol("process"),pi=Symbol("processing"),Os=Symbol("processJob"),gt=Symbol("jobs"),ec=Symbol("jobDone"),qs=Symbol("addFSEntry"),Cu=Symbol("addTarEntry"),_c=Symbol("stat"),yc=Symbol("readdir"),Gs=Symbol("onreaddir"),Hs=Symbol("pipe"),Ru=Symbol("entry"),tc=Symbol("entryOpt"),js=Symbol("writeEntryClass"),nf=Symbol("write"),nc=Symbol("ondrain"),to=class extends jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[js];onWriteEntry;[pt];[hi]=new Map;[gt]=0;[pi]=!1;[xi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Y(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[js]=tf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new Um(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new jm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[nc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[nc]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[pt]=new kw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[pi]=!1,this[xi]=!1}[nf](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[xi]=!0,this[zn](),r&&r(),this}write(t){if(this[xi])throw new Error("write after end");return typeof t=="string"?this[qs](t):this[Cu](t),this.flowing}[Cu](t){let e=Y(Iu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Au(t.path,e);r.entry=new Cw(t,this[tc](r)),r.entry.on("end",()=>this[ec](r)),this[gt]+=1,this[pt].push(r)}this[zn]()}[qs](t){let e=Y(Iu.resolve(this.cwd,t));this[pt].push(new Au(t,e)),this[zn]()}[_c](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";$s[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Us](t,i)})}[Us](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[xn])this[Os](t);else{let r=`${e.dev}:${e.ino}`,i=this[hi].get(r);i?i.push(t):this[hi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[zn]()}[yc](t){t.pending=!0,this[gt]+=1,$s.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[Gs](t,r)})}[Gs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[zn]()}[zn](){if(!this[pi]){this[pi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Os](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[pi]=!1,this[xi]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(Tu):(super.write(Tu),super.end()))}}get[xn](){return this[pt]&&this[pt].head&&this[pt].head.value}[ec](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[hi].get(r);if(i){this[hi].delete(r);for(let o of i)o.pending=!1,this[Os](o)}}this[zn]()}[Os](t){if(t.pending&&t.pendingLink&&t===this[xn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[xn]&&!t.piped&&this[Hs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Us](t,e):this[_c](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Gs](t,e):this[yc](t),!t.readdir)return}if(t.entry=this[Ru](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[Hs](t)}}}[tc](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Ru](t){this[gt]+=1;try{return new this[js](t.path,this[tc](t)).on("end",()=>this[ec](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[nc](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[Hs](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={}){Qs(this,t,e,r)}},Mc=class extends to{sync=!0;constructor(t){super(t),this[js]=Tw}pause(){}resume(){}[_c](t){let e=this.follow?"statSync":"lstatSync";this[Us](t,$s[e](t.absolute))}[yc](t){this[Gs](t,$s.readdirSync(t.absolute))}[Hs](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[nf](i)})}},Lw=(t,e)=>{let r=new Mc(t),i=new Hu(t.file,{mode:t.mode||438});r.pipe(i),rf(r,e)},Nw=(t,e)=>{let r=new to(t),i=new Ys(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),r.on("error",l)});return sf(r,e).catch(c=>r.emit("error",c)),o},rf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:ju.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},sf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Sr({file:ju.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Mw=(t,e)=>{let r=new Mc(t);return rf(r,e),r},Bw=(t,e)=>{let r=new to(t);return sf(r,e).catch(i=>r.emit("error",i)),r},sI=Ci(Lw,Nw,Mw,Bw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),zw=process.env.__FAKE_PLATFORM__||process.platform,df=zw==="win32",{O_CREAT:lf,O_NOFOLLOW:ku,O_TRUNC:uf,O_WRONLY:ff}=cf.constants,xf=Number(process.env.__FAKE_FS_O_FILENAME__)||cf.constants.UV_FS_O_FILEMAP||0,Uw=df&&!!xf,qw=512*1024,Gw=xf|uf|lf|ff,Du=!df&&typeof ku=="number"?ku|uf|lf|ff:null,hf=Du!==null?()=>Du:Uw?t=>t<qw?Gw:"w":()=>"w",Ec=(t,e,r)=>{try{return no.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Js=(t,e,r,i)=>{no.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Hw=(t,e,r,i,o)=>{if(e.isDirectory())pf(Ei.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=Ei.resolve(t,e.name);Js(l,r,i,o)});else{let c=Ei.resolve(t,e.name);Js(c,r,i,o)}},pf=(t,e,r,i)=>{no.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 Js(t,e,r,i);let l=c.length,u=null,x=p=>{if(!u){if(p)return i(u=p);if(--l===0)return Js(t,e,r,i)}};for(let p of c)Hw(t,p,e,r,x)})},jw=(t,e,r,i)=>{e.isDirectory()&&gf(Ei.resolve(t,e.name),r,i),Ec(Ei.resolve(t,e.name),r,i)},gf=(t,e,r)=>{let i;try{i=no.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Ec(t,e,r);throw c}for(let o of i)jw(t,o,e,r);return Ec(t,e,r)},mf=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"}},ro=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"}},Kw=(t,e)=>{st.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new mf(t,r?.code||"ENOTDIR")),e(r)})},$w=(t,e,r)=>{t=Y(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,x=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),p=e.preserve,w=e.unlink,_=Y(e.cwd),I=(S,A)=>{S?r(S):A&&x?pf(A,l,u,T=>I(T)):c?st.chmod(t,o,r):r()};if(t===_)return Kw(t,I);if(p)return Ww.mkdir(t,{mode:o,recursive:!0}).then(S=>I(null,S??void 0),I);let y=Y(Zs.relative(_,t)).split("/");bc(_,y,o,w,_,void 0,I)},bc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),x=Y(Zs.resolve(t+"/"+u));st.mkdir(x,r,wf(x,e,r,i,o,c,l))},wf=(t,e,r,i,o,c,l)=>u=>{u?st.lstat(t,(x,p)=>{if(x)x.path=x.path&&Y(x.path),l(x);else if(p.isDirectory())bc(t,e,r,i,o,c,l);else if(i)st.unlink(t,w=>{if(w)return l(w);st.mkdir(t,r,wf(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new ro(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,bc(t,e,r,i,o,c,l))},Vw=t=>{let e=!1,r;try{e=st.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new mf(t,r??"ENOTDIR")}},Jw=(t,e)=>{t=Y(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),x=e.preserve,p=e.unlink,w=Y(e.cwd),_=S=>{S&&u&&gf(S,c,l),o&&st.chmodSync(t,i)};if(t===w)return Vw(w),_();if(x)return _(st.mkdirSync(t,{mode:i,recursive:!0})??void 0);let I=Y(Zs.relative(w,t)).split("/"),y;for(let S=I.shift(),A=w;S&&(A+="/"+S);S=I.shift()){A=Y(Zs.resolve(A));try{st.mkdirSync(A,i),y=y||A}catch{let T=st.lstatSync(A);if(T.isDirectory())continue;if(p){st.unlinkSync(A),st.mkdirSync(A,i),y=y||A;continue}else if(T.isSymbolicLink())return new ro(A,A+"/"+I.join("/"))}}return _(y)},rc=Object.create(null),Pu=1e4,pr=new Set,Zw=t=>{pr.has(t)?pr.delete(t):rc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),pr.add(t);let e=rc[t],r=pr.size-Pu;if(r>Pu/10){for(let i of pr)if(pr.delete(i),delete rc[i],--r<=0)break}return e},Yw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Xw=Yw==="win32",Qw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=_f(i,r)),e.push(r||"/"),e},[]),e_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Xw?["win32 parallelization disabled"]:t.map(i=>yi(_f(Zw(i))));let r=new Set(t.map(i=>Qw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let x of u)o.add(x)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let x=l[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},t_=()=>process.umask(),Ou=Symbol("onEntry"),vc=Symbol("checkFs"),Lu=Symbol("checkFs2"),Sc=Symbol("isReusable"),dt=Symbol("makeFs"),Ic=Symbol("file"),Ac=Symbol("directory"),Ws=Symbol("link"),Nu=Symbol("symlink"),Mu=Symbol("hardlink"),wi=Symbol("ensureNoSymlink"),Bu=Symbol("unsupported"),Fu=Symbol("checkPath"),ic=Symbol("stripAbsolutePath"),wn=Symbol("mkdir"),qe=Symbol("onError"),Ls=Symbol("pending"),zu=Symbol("pend"),gr=Symbol("unpend"),sc=Symbol("ended"),oc=Symbol("maybeClose"),Tc=Symbol("skip"),bi=Symbol("doChown"),vi=Symbol("uid"),Si=Symbol("gid"),Ii=Symbol("checkedCwd"),n_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ai=n_==="win32",r_=1024,i_=(t,e)=>{if(!Ai)return ie.unlink(t,e);let r=t+".DELETE."+af(16).toString("hex");ie.rename(t,r,i=>{if(i)return e(i);ie.unlink(r,e)})},s_=t=>{if(!Ai)return ie.unlinkSync(t);let e=t+".DELETE."+af(16).toString("hex");ie.renameSync(t,e),ie.unlinkSync(e)},Uu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Bc=class extends Ti{[sc]=!1;[Ii]=!1;[Ls]=0;reservations=new e_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[sc]=!0,this[oc]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:r_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ai,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Y(Me.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:t_():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[Ou](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[oc](){this[sc]&&this[Ls]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[ic](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Oc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Ai&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Me.posix.dirname(t.path),x=Me.posix.normalize(Me.posix.join(u,l.join("/")));if(x.startsWith("../")||x==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Fu](t){let e=Y(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Y(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[ic](t,"path")||!this[ic](t,"linkpath"))return!1;if(t.absolute=Me.isAbsolute(t.path)?Y(Me.resolve(t.path)):Y(Me.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Y(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Me.win32.parse(String(t.absolute));t.absolute=i+yu(String(t.absolute).slice(i.length));let{root:o}=Me.win32.parse(t.path);t.path=o+yu(t.path.slice(o.length))}return!0}[Ou](t){if(!this[Fu](t))return t.resume();switch(Fw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[vc](t);default:return this[Bu](t)}}[qe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[gr](),e.resume())}[wn](t,e,r){$w(Y(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[bi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[vi](t){return Uu(this.uid,t.uid,this.processUid)}[Si](t){return Uu(this.gid,t.gid,this.processGid)}[Ic](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Ys(String(t.absolute),{flags:hf(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,x=>{x?this[qe](x,t):this[gr](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,w=t.mtime;ie.futimes(x,p,w,_=>_?ie.utimes(u,p,w,I=>c(I&&_)):c())}if(typeof x=="number"&&this[bi](t)){o++;let p=this[vi](t),w=this[Si](t);typeof p=="number"&&typeof w=="number"&&ie.fchown(x,p,w,_=>_?ie.chown(u,p,w,I=>c(I&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[qe](u,t),e()}),t.pipe(l)),l.pipe(i)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[wn](String(t.absolute),r,i=>{if(i){this[qe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[gr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ie.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[bi](t)&&(o++,ie.chown(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)),c)),c()})}[Bu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Nu](t,e){let r=Y(Me.relative(this.cwd,Me.resolve(Me.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[wi](t,this.cwd,r,()=>this[Ws](t,String(t.linkpath),"symlink",e),i=>{this[qe](i,t),e()})}[Mu](t,e){let r=Y(Me.resolve(this.cwd,String(t.linkpath))),i=Y(String(t.linkpath)).split("/");this[wi](t,this.cwd,i,()=>this[Ws](t,r,"link",e),o=>{this[qe](o,t),e()})}[wi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Me.resolve(e,c);ie.lstat(l,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new ro(l,Me.resolve(l,r.join("/"))));this[wi](t,l,r,i,o)})}[zu](){this[Ls]++}[gr](){this[Ls]--,this[oc]()}[Tc](t){this[gr](),t.resume()}[Sc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ai}[vc](t){this[zu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Lu](t,r))}[Lu](t,e){let r=l=>{e(l)},i=()=>{this[wn](this.cwd,this.dmode,l=>{if(l){this[qe](l,t),r();return}this[Ii]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Y(Me.dirname(String(t.absolute)));if(l!==this.cwd)return this[wn](l,this.dmode,u=>{if(u){this[qe](u,t),r();return}c()})}c()},c=()=>{ie.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Tc](t),r();return}if(l||this[Sc](t,u))return this[dt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=w=>this[dt](w??null,t,r);return x?ie.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return ie.rmdir(String(t.absolute),x=>this[dt](x??null,t,r))}if(t.absolute===this.cwd)return this[dt](null,t,r);i_(String(t.absolute),x=>this[dt](x??null,t,r))})};this[Ii]?o():i()}[dt](t,e,r){if(t){this[qe](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Ic](e,r);case"Link":return this[Mu](e,r);case"SymbolicLink":return this[Nu](e,r);case"Directory":case"GNUDumpDir":return this[Ac](e,r)}}[Ws](t,e,r,i){ie[r](e,String(t.absolute),o=>{o?this[qe](o,t):(this[gr](),t.resume()),i()})}},gi=t=>{try{return[null,t()]}catch(e){return[e,null]}},yf=class extends Bc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[vc](t){if(!this[Ii]){let o=this[wn](this.cwd,this.dmode);if(o)return this[qe](o,t);this[Ii]=!0}if(t.absolute!==this.cwd){let o=Y(Me.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[wn](o,this.dmode);if(c)return this[qe](c,t)}}let[e,r]=gi(()=>ie.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Tc](t);if(e||this[Sc](t,r))return this[dt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?gi(()=>{ie.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](l,t)}let[o]=gi(()=>ie.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:gi(()=>s_(String(t.absolute)));this[dt](i,t)}[Ic](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{ie.closeSync(o)}catch(x){u=x}(l||u)&&this[qe](l||u,t),e()},o;try{o=ie.openSync(String(t.absolute),hf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[qe](l,t)),t.pipe(c)),c.on("data",l=>{try{ie.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{ie.futimesSync(o,u,x)}catch(p){try{ie.utimesSync(String(t.absolute),u,x)}catch{l=p}}}if(this[bi](t)){let u=this[vi](t),x=this[Si](t);try{ie.fchownSync(o,Number(u),Number(x))}catch(p){try{ie.chownSync(String(t.absolute),Number(u),Number(x))}catch{l=l||p}}}i(l)})}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[wn](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[bi](t))try{ie.chownSync(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)))}catch{}e(),t.resume()}[wn](t,e){try{return Jw(Y(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[wi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Me.resolve(c,l);let[u,x]=gi(()=>ie.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new ro(c,Me.resolve(e,r.join("/"))))}i()}[Ws](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)}}},o_=t=>{let e=new yf(t),r=t.file,i=of.statSync(r),o=t.maxReadSize||16*1024*1024;new Im(r,{readSize:o,size:i.size}).pipe(e)},a_=(t,e)=>{let r=new Bc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),of.stat(o,(u,x)=>{if(u)l(u);else{let p=new Rc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},Ef=Ci(o_,a_,t=>new yf(t),t=>new Bc(t),(t,e)=>{e?.length&&Xu(t,e)}),c_=(t,e)=>{let r=new Mc(t),i=!0,o,c;try{try{o=it.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=it.openSync(t.file,"w+");else throw x}let l=it.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let w=0,_=0;w<512;w+=_){if(_=it.readSync(o,u,w,u.length-w,c+w),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let x=new Hn(u);if(!x.cksumValid)break;let p=512*Math.ceil((x.size||0)/512);if(c+p+512>l.size)break;c+=p,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,d_(t,r,c,o,e)}finally{if(i)try{it.closeSync(o)}catch{}}},d_=(t,e,r,i,o)=>{let c=new Hu(t.file,{fd:i,start:r});e.pipe(c),u_(e,o)},l_=(t,e)=>{e=Array.from(e);let r=new to(t),i=(o,c,l)=>{let u=(I,y)=>{I?it.close(o,S=>l(I)):l(null,y)},x=0;if(c===0)return u(null,0);let p=0,w=Buffer.alloc(512),_=(I,y)=>{if(I||y===void 0)return u(I);if(p+=y,p<512&&y)return it.read(o,w,p,w.length-p,x+p,_);if(x===0&&w[0]===31&&w[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,x);let S=new Hn(w);if(!S.cksumValid)return u(null,x);let A=512*Math.ceil((S.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&S.mtime&&t.mtimeCache.set(String(S.path),S.mtime),p=0,it.read(o,w,0,512,x,_)};it.read(o,w,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(x,p)=>{if(x&&x.code==="ENOENT"&&l==="r+")return l="w+",it.open(t.file,l,u);if(x||!p)return c(x);it.fstat(p,(w,_)=>{if(w)return it.close(p,()=>c(w));i(p,_.size,(I,y)=>{if(I)return c(I);let S=new Ys(t.file,{fd:p,start:y});r.pipe(S),S.on("error",c),S.on("close",o),f_(r,e)})})};it.open(t.file,l,u)})},u_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:bf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},f_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Sr({file:bf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},mi=Ci(c_,l_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Om(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")}),yI=Ci(mi.syncFile,mi.asyncFile,mi.syncNoFile,mi.asyncNoFile,(t,e=[])=>{mi.validate?.(t,e),x_(t)}),x_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};an();var _t={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function io(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function vf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function so(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Sf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function If(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Ir(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Wt();Ke();re();Le();Ke();function En(t,e){if(io(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ri(t){return t.startsWith("http://")||t.startsWith("https://")}function oo(t){return t.endsWith("/")?t.slice(0,-1):t}Ke();re();var ao="1008033",Rf="1289";var kf="pbbp2",Df="https://www.coze.cn",Pf="/api/coze_claw/resource/get_frontier_key",E_="https://www.coze.cn",b_="wss://frontier.coze.cn";function co(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??E_}function Of(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??b_}function Ar(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 Di(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var ki=q("handshake");async function Fc(t){let e=co(t.endpoint),r=t.timeoutMs??1e4,i=`${oo(e)}${Pf}?aid=${encodeURIComponent(ao)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Ar(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);ki.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=u.headers.get("x-tt-logid")??"",p=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let S=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${S.slice(0,200)}`)}let w=await u.json();if(w.code!==void 0&&w.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${w.code} msg=${w.msg??"-"} logid=${x}`);let _=w.data??{},I=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,y=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!I||!y){let S=JSON.stringify(w).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${S}`)}return ki.info("handshake ok",{remoteDeviceId:y,logid:x,traceId:p}),{accessKey:I,deviceId:y}}catch(u){if(u instanceof C)throw ki.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw ki.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw ki.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:x?.code,syscall:x?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var zc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Lf=15e4;function Nf(t){return{model:Uc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Mf(t){return!t||t===yt}var v_=new Set(["auto","\u81EA\u52A8"]);function Uc(t){let e=t?.trim();if(e)return v_.has(e.toLowerCase())?yt:e}function Bf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=zc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Mf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Ff(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):Mf(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${zc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??Lf;e.push("-c",`model_context_window=${r}`)}return e}function zf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function qc(t,e){let{ttEnv:r,usePpe:i}=Di(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Uf(t,e,r){if(!t.modelToken)return{};let i=qc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
|
|
92
|
-
`)}}function Gc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function qf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=qc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${zc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Lf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Gf(t,e,r){if(!t.modelToken)return[];let i=qc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ae=q("agent-handlers"),Hf=5*1024*1024,R_=1,k_=6,D_=new Set(["node_modules",".git",".coze","dist","build",".next"]),P_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,O_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,L_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function N_(t){let e=t?.trim();return e?L_.test(e)||O_.test(e)?e:(Ae.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function M_(t){return new Promise((e,r)=>{let i=nt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=l=>{o||(o=!0,l?r(l):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",l=>c(l))})}var lo=class{constructor(e){this.opts=e}opts;async listSkills(e){En(e._meta,"_agent/listSkills");let r=Ir(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.skills??[],l=[];for(let u of c){let x=Dt(o,u.relPath,"SKILL.md");await A_(x).then(w=>w.isFile()).catch(()=>!1)&&l.push(q_(u))}return{skills:l}}async addSkills(e){let r=Ir(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((x,p)=>[x.skillId,p])),u=[];for(let x of o){let p=await Jc({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Zc(c,l,p),u.push(x)}return await xs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){En(e._meta,"_agent/removeSkills");let r=Ir(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let x=Dt(i.workspace,u.relPath);await I_(x,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await xs(r,l),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Ae.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let x=c.downstream;c.downstream=void 0,Ae.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(p=>Ae.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(p)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Ae.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Be(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ae.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await cr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ae.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new C("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Qe(i),Ae.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Be(r))throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ri(e.registry)&&o.push(`--registry=${e.registry}`);let c=N_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&P_.test(l)&&o.push("--env",l);let u=await M_(o);return Ae.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Be(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Qe(i),Ae.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Ae.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(En(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Uc(e.model)??yt,i=await Be(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Qe(i),Ae.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ae.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Ae.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let x=o.sessions.get(l);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(c),Ae.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(En(e._meta,_t.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ae.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await ni(e,o)}async clearPersistedAcpSessionIds(e){let r=await Be(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Qe(r)}async repairAgent(e){if(En(e._meta,_t.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ae.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ae.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ae.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){En(e._meta,"_agent/getFileTree");let r=e._meta,i=Ir(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Hc(l).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ti(l,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=X_(e.depth);return u.isDirectory()?{tree:await Y_(o,l,c,x)}:{tree:[{name:Q_(c),path:Zf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){En(e._meta,"_agent/getFileContent");let r=Ir(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Hc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ti(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Hf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Hf})`);let l=await jf(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await Be(e).catch(()=>null))?.workspace??Xe(e).workspace}safeJoin(e,r){let i=Kc(e,r||"."),o=Vc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Wf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Be(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function B_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function F_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var z_=3e4,U_=50*1024*1024,Tr=3e4;async function Jc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new C("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=B_(o.skillName),x=F_(i),p=Dt(x,u),w=Dt(r,p);if(await jc(w,{recursive:!0}),c){let I=Buffer.from(o.content,"utf8");Pi(I.length),await Wc(Dt(w,"SKILL.md"),I,"utf8")}else{let I=await G_(o.downloadUrl);j_(I)?await V_(I,w):W_(I)?await K_(I,w):await Wc(Dt(w,"SKILL.md"),I.toString("utf8"),"utf8")}let _={skillId:o.skillId,skillName:o.skillName,relPath:p,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Ae.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),_}function Zc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function q_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function G_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Pi(e);let r=H_(t);return Pi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await jf(e);return Pi(r.length),r}if(Ri(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),z_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Pi(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Pi(t){if(t>U_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function H_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function j_(t){return t.length>=2&&t[0]===31&&t[1]===139}function W_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function $c(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function K_(t,e){let r,i;try{r=new Vf.default(t),i=r.getEntries()}catch(l){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||$c(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(p=>p===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=l.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=$_(i),c=Kc(e);for(let l of i){if($c(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=Kc(e,u),p=Vc(c,x);if(p.startsWith("..")||p==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await jc(x,{recursive:!0});continue}await jc(T_(x),{recursive:!0});let w;try{w=l.getData()}catch(_){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await Wc(x,w)}}function $_(t){let e;for(let r of t){let i=r.entryName;if(!i||$c(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function V_(t,e){await J_(t);let r=Ef({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${Tr}ms)`))},Tr);try{await $f(Kf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${Tr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function J_(t){let e=[],r=Sr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${Tr}ms)`))},Tr);try{await $f(Kf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${Tr}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var Z_=5e3;async function Y_(t,e,r,i){return Jf(t,e,r,i,{count:0})}async function Jf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await S_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(D_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Z_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Dt(e,u.name),p=C_(Dt(r,u.name)),w=null;try{w=await Hc(x)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let _={name:u.name,path:Zf(Vc(t,x)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(_.children=await Jf(t,x,p,i-1,o)),l.push(_)}return l.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),l}function X_(t){return!t||t<=0?R_:Math.min(t,k_)}function Q_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Zf(t){return t.split(Wf).join("/")}re();import{readFileSync as NA}from"node:fs";import{dirname as BA,join as FA}from"node:path";import{fileURLToPath as UA}from"node:url";var Cr="0.1.104-beta.0";var bn=q("agent-health-reporter"),ey=1e4,Oi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??ey}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),bn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),bn.info("heartbeat stopped"))}async tick(){if(this.inFlight){bn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){bn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let u=ty(l);if(!u)continue;let x={agentId:l.agentId,status:u};l.patToken&&(x.patToken=l.patToken),l.accountId&&(x.accountId=l.accountId),r.push(x)}if(r.length===0)return;let i={agents:r,bridgeVersion:Cr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){bn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(bn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){bn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){bn.warn("onTickEnd hook failed",{err:String(r)})}}};function ty(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}an();import{mkdir as nd,rm as Ky,stat as $y}from"node:fs/promises";import{homedir as Vy}from"node:os";import{join as S0}from"node:path";rn();import{existsSync as hy}from"node:fs";import{release as py}from"node:os";import{basename as gy,isAbsolute as my}from"node:path";function Li(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Rr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function kr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function vn(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var uo=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)}},te={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function Yf(t){return"method"in t&&"id"in t&&t.id!==void 0}function Xf(t){return"method"in t&&!("id"in t)}function fo(t){return!("method"in t)&&"id"in t}var ny={AGENT_NOT_FOUND:te.AGENT_NOT_FOUND,AGENT_BUSY:te.AGENT_BUSY,AGENT_DISCONNECTED:te.AGENT_DISCONNECTED,AGENT_TIMEOUT:te.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:te.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:te.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:te.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:te.INTERNAL_ERROR,BRIDGE_INTERNAL:te.INTERNAL_ERROR,IPC_AUTH_FAILED:te.INTERNAL_ERROR,IPC_BAD_REQUEST:te.INVALID_REQUEST,METHOD_NOT_FOUND:te.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:te.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:te.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:te.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:te.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:te.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:te.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:te.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:te.FILE_TOO_LARGE,UNSUPPORTED_MIME:te.UNSUPPORTED_MIME,UPLOAD_FAILED:te.UPLOAD_FAILED,UPSTREAM_NOT_READY:te.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:te.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:te.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:te.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:te.AGENT_ENV_NOT_READY};function ry(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ni(t.message)}:typeof t=="string"?Ni(t):typeof t=="object"?sy(t):t}var iy=[[/\/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 Ni(t){let e=t;for(let[r,i]of iy)e=e.replace(r,i);return e}function sy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ni(i):e[r]=i;return e}function Mi(t){if(t instanceof C){let e=ry(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:ny[t.code]??te.INTERNAL_ERROR,message:Ni(t.message),data:r}}return{code:te.INTERNAL_ERROR,message:Ni(t instanceof Error?t.message:String(t))}}function Qf(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function t0(t){return`${JSON.stringify(t)}
|
|
93
|
-
|
|
94
|
-
`);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(l){this.onError?.({line:c,error:l})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var r0={"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"},YA=Object.fromEntries(Object.entries(r0).map(([t,e])=>[e,t])),oy={"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:[]},Dr=class{seq=0;next(e,r){this.seq+=1;let i=r0[e]??ay(e),o=oy[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>n0(r?.[x]??"")),u=cy(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>n0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function ay(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function n0(t){return t.replace(/[:_\s]+/g,"-")}function cy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}on();import{readFileSync as dy}from"node:fs";var ly=384;async function Yc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await ar(t.agentEnvFile,r,{mode:ly})}function Xc(t){try{let e=JSON.parse(dy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function i0(t,e,r={},i=o=>o){return{...i({...t,...Xc(e)}),...r}}Wt();nr();Ke();re();Le();import{execFileSync as uy,spawnSync as fy}from"node:child_process";function Bi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Fi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),fy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Qc=new Set;function s0(t){typeof t=="number"&&t>0&&Qc.add(t)}function o0(t){typeof t=="number"&&Qc.delete(t)}function a0(){for(let t of Qc)Fi(t,"SIGKILL")}var Pr="coze-bridge-daemon";function c0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return uy("pgrep",["-U",String(o),"-f",Pr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
|
|
95
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function d0(t,e){if(t.length===0)return;let r=e?.killFn??Fi,i=e?.isAliveFn??Bi,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(x=>i(x));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var xy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @(zed-industries|agentclientprotocol)\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function l0(t,e){if(!e)return null;for(let r of xy)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 l0(t,e)}function f0(t,e){return l0(t,e)}function Or(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 x0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,w=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Or(w,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Or(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Or(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Or(c,!1,e)}}var h0=We("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),wy=200,_y=40,yy=We("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Ey=We("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),by=We("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),vy=We("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Sy=We("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Iy=We("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),p0=500;function Ay(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=p0?t:`${e.slice(0,p0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Ty(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 g0(t){try{return hy(t)}catch{return}}function Cy(t,e){return{platform:process.platform,osRelease:py(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:my(e.command)?g0(e.command):void 0,cwd:e.cwd,cwdExists:g0(e.cwd),envKeys:e.envKeys}}function Ry(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${gy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new xo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Dr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=i0(process.env,this.opts.agentEnvFile??ee().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,s0(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>wy&&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,o0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=Cy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new C("AGENT_SPAWN_FAILED",Ry(c,l),{cause:l}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Fi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Fi(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:Sy,phase2GateMs:yy,livenessWindowMs:Ey,absoluteMaxMs:by,approvalMaxMs:Iy,suspendThresholdMs:vy,...r};return this.call("session/prompt",e,h0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Rr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(kr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(vn(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=h0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Li(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let x=r.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,p)=>{let w={resolve:x,reject:p,timer:null,method:e,promptTimeout:null};if(o){let _=this.now(),I={cfg:o,startedAt:_,lastActivityAt:_,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:_,expectedIntervalMs:Or(0,!1,o),sessionId:u};w.promptTimeout=I;let y=()=>{let S={startedAt:I.startedAt,lastActivityAt:I.lastActivityAt,firstFrameSeen:I.firstFrameSeen,hasActiveTool:I.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:I.suspendedMs,armedAt:I.armedAt,expectedIntervalMs:I.expectedIntervalMs},A=this.now(),T=x0(S,I.cfg,A),R=P=>{I.armedAt=A,I.expectedIntervalMs=P,w.timer=setTimeout(y,P)};if(T.action==="suspend"){I.suspendedMs+=T.suspendedDeltaMs,I.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:T.suspendedDeltaMs,suspendedMs:I.suspendedMs,...I.sessionId?{sessionId:I.sessionId}:{}}),R(T.rearmMs);return}if(T.action==="continue"){R(T.rearmMs);return}this.pending.delete(c),T.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:T.awaitingApproval,...I.sessionId?{sessionId:I.sessionId}:{}}),p(T.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${I.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${I.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...I.sessionId?{sessionId:I.sessionId}:{}}),p(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${I.cfg.livenessWindowMs}ms`)))};w.timer=setTimeout(y,I.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(w.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),p(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,w);try{this.writeFrame(l)}catch(_){w.timer&&clearTimeout(w.timer),this.pending.delete(c),p(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(t0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(fo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Ay(e.result)}),r.resolve(e.result));return}if(Xf(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(Yf(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(vn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(vn(e.id,Mi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Qf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=f0(this.framework,Ty(e));return i?new C(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new C("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(_y).join(`
|
|
96
|
-
`),o=u0(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function ky(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var ho=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=ei("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return ky(e)}};rn();import{mkdtempSync as Dy,rmSync as Py}from"node:fs";import{tmpdir as Oy}from"node:os";import{join as Ly}from"node:path";var po=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ei("codex",e.command,i),l=e.isolateCodexHome?Dy(Ly(Oy(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(x),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Py(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Ke();var Ny=3e4,Lr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ny))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var m0=["default","acceptEdits","plan","auto","bypassPermissions"],w0=["read-only","auto","full-access"];function Sn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return m0.includes(e);case"codex":return w0.includes(e);case"openclaw":return!1}}function ed(t){switch(t){case"claude-code":return m0.join("/");case"codex":return w0.join("/");case"openclaw":return""}}on();Ke();re();Le();function td(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();var In=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var go=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new In,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)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 Kt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Wt();re();import{constants as _0}from"node:fs";import{access as My}from"node:fs/promises";import{delimiter as By,join as Fy}from"node:path";var Et=q("framework-detector"),y0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},zy=[".exe",".cmd",".bat",".ps1"],Wn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??My}}async detect(e){let r=y0[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(y0).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(By).filter(Boolean),i=this.env.platform==="win32"?["",...zy]:[""];for(let o of r)for(let c of i){let l=Fy(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?_0.F_OK:_0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(qy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=x=>{c||(c=!0,l&&clearTimeout(l),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{x.kill("SIGKILL"),u(null)},15e3),x.stdout?.on("data",p=>{o+=p.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",p=>u({code:p,stdout:o}))}catch{u(null)}})}},Uy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function qy(t){return t.replace(Uy,"")}import{homedir as Gy}from"node:os";import{join as Hy}from"node:path";on();Wt();nr();Ke();re();async function v0(){let t=Hy(Gy(),".openclaw/openclaw.json");return(await or(t))?.gateway?.auth?.token??""}var E0=q("openclaw.config"),jy=[0,5e3,5e3],Wy=We("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),b0="models.providers.",mo="agents.defaults.models",wo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new In;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??jy,this.cliTimeoutMs=e.cliTimeoutMs??Wy}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await r()}catch(l){i=l,E0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=nt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=p=>{l||(l=!0,clearTimeout(x),p())};o.stderr?.on("data",p=>{c+=p.toString("utf8")});let x=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);x.unref(),o.on("error",p=>u(()=>i(p))),o.on("close",p=>u(()=>{p===0?r():i(new Error(`exit ${p}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){E0.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",`${b0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${b0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${mo}[${e}]`,()=>this.runCli(["config","set",mo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${mo}[${e}]`,`${mo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var ue=q("agent-manager"),id="bypassPermissions",T0="full-access",C0="full-access";function Jy(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var Zy=(t,e,r,i,o,c,l,u,x,p)=>{switch(t){case"claude-code":{let w={...o?{...Bf(o),...Uf(o,l,u)}:{},...x??{},IS_SANDBOX:"1"};return new ho({cwd:r,env:w,agentId:i})}case"codex":{let w=o?[...Ff(o),...Gf(o,l,u)]:[],_=T0;p!==void 0&&(Sn("codex",p)?_=p:ue.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:p}));let I=[...w,...Jy(_)],y={...o?zf(o):{},...x??{}},S=!!o;return new po({cwd:r,agentId:i,...I.length>0?{extraArgs:I}:{},...Object.keys(y).length>0?{env:y}:{},...S?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Lr({command:e,cwd:r,agentId:i,...c?{sessionName:td(c)}:{}})}};function rd(t){return t==="claude-code"||t==="codex"}function Yy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Xy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
89
|
+
`},configPath(t){return z1(t.homeDir,".coze","bridge","task.xml")},async install(t){let r=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await hp("schtasks",["/Create","/SC","ONLOGON","/TN",ca,"/TR",r,"/RU",t.userName,"/F"]),Zd.info("task scheduler entry created",{task:ca,logFile:t.logFile})},async uninstall(t){await hp("schtasks",["/Delete","/TN",ca,"/F"]).catch(e=>Zd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Zd.info("task scheduler entry removed",{task:ca})}}});var pp={};Ea(pp,{buildContext:()=>W1,getSupervisor:()=>H1,launchdSupervisor:()=>Kd,systemdSupervisor:()=>Vd,taskSchedulerSupervisor:()=>Jd});import{homedir as U1,userInfo as G1}from"node:os";function H1(t=process.platform){switch(t){case"darwin":return Kd;case"linux":return Vd;case"win32":return Jd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function j1(){let t={};for(let e of q1){let r=process.env[e];r&&(t[e]=r)}return t}function W1(){let t=Q();return{nodeBin:process.execPath,entry:Fd(t),logFile:t.logFile,homeDir:U1(),userName:G1().username,isRoot:process.getuid?.()===0,env:j1()}}var q1,gp=Qe(()=>{"use strict";De();Yo();lp();fp();xp();q1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();sn();var kl=G("acp-installer-warmup"),qg=["claude-code","codex"];async function Tl(t={}){let e=t.ensure??ar,i=(await Promise.allSettled(qg.map(async o=>{let c=await e(o);kl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&kl.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))})}cn();te();import{readdir as sm}from"node:fs/promises";import{mkdir as Dl,readFile as rm,writeFile as Ol}from"node:fs/promises";import{join as Ra}from"node:path";var im={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function lr(t,e,r){await Dl(t,{recursive:!0});let i=im[e],o=Ra(t,i);return await Ol(o,r??"","utf8"),o}async function Ca(t,e,r){let i=Ra(t,".claude");await Dl(i,{recursive:!0});let o=Ra(i,"settings.local.json"),c={};try{let u=await rm(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await Ol(o,JSON.stringify(c,null,2),"utf8"),o}var Je=G("agent-detail-sync"),om=6e4,am=5*6e4,ps=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await sm(r)}catch(o){Je.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Je.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await ke(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Je.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Je.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Je.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){Je.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Je.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await ke(e,this.opts.paths);if(!i){Je.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){Je.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),p=x?Math.min(x.currentDelay*2,am):om;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});return}if(o.agentId&&o.agentId!==e){Je.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Je.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Je.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Je.debug("detail sync: no diff",{agentId:e});return}await Me(i,this.opts.paths),Je.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Je.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await lr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Yc=Ut(fu(),1);import{createHash as H_}from"node:crypto";import{lstat as jc,mkdir as Wc,readFile as ao,readdir as Jf,rm as $c,stat as Kf,writeFile as Kc}from"node:fs/promises";import{dirname as q_,join as We,normalize as j_,relative as Jc,resolve as Vc,sep as Yf}from"node:path";import{Readable as Xf}from"node:stream";import{pipeline as Qf}from"node:stream/promises";import Rm from"events";import et from"fs";import{EventEmitter as Rc}from"node:events";import Ku from"node:stream";import{StringDecoder as Cm}from"node:string_decoder";import Ju from"node:path";import Er from"node:fs";import{dirname as qm,parse as jm}from"path";import{EventEmitter as Xm}from"events";import lc from"assert";import{Buffer as Hn}from"buffer";import*as mu from"zlib";import Qm from"zlib";import{posix as pr}from"node:path";import{basename as Aw}from"node:path";import Ks from"fs";import Ct from"fs";import Su from"path";import{win32 as Fw}from"node:path";import Pu from"path";import ff from"node:fs";import t_ from"node:assert";import{randomBytes as hf}from"node:crypto";import re from"node:fs";import Le from"node:path";import xf from"fs";import no from"node:fs";import Si from"node:path";import at from"node:fs";import c_ from"node:fs/promises";import Js from"node:path";import{join as If}from"node:path";import ot from"node:fs";import Tf from"node:path";var km=Object.defineProperty,Tm=(t,e)=>{for(var r in e)km(t,r,{get:e[r],enumerable:!0})},hu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Pm=t=>!!t&&typeof t=="object"&&(t instanceof Wn||t instanceof Ku||Dm(t)||Om(t)),Dm=t=>!!t&&typeof t=="object"&&t instanceof Rc&&typeof t.pipe=="function"&&t.pipe!==Ku.Writable.prototype.pipe,Om=t=>!!t&&typeof t=="object"&&t instanceof Rc&&typeof t.write=="function"&&typeof t.end=="function",Gt=Symbol("EOF"),Ht=Symbol("maybeEmitEnd"),ln=Symbol("emittedEnd"),ys=Symbol("emittingEnd"),ai=Symbol("emittedError"),bs=Symbol("closed"),xu=Symbol("read"),Es=Symbol("flush"),pu=Symbol("flushChunk"),mt=Symbol("encoding"),xr=Symbol("decoder"),Be=Symbol("flowing"),ci=Symbol("paused"),_r=Symbol("resume"),Fe=Symbol("buffer"),Ye=Symbol("pipes"),ze=Symbol("bufferLength"),Ma=Symbol("bufferPush"),vs=Symbol("bufferShift"),Ze=Symbol("objectMode"),Se=Symbol("destroyed"),Ba=Symbol("error"),Fa=Symbol("emitData"),gu=Symbol("emitEnd"),za=Symbol("emitEnd2"),kt=Symbol("async"),Ua=Symbol("abort"),Ss=Symbol("aborted"),di=Symbol("signal"),On=Symbol("dataListeners"),st=Symbol("discarded"),li=t=>Promise.resolve().then(t),Lm=t=>t(),Nm=t=>t==="end"||t==="finish"||t==="prefinish",Mm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Bm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Vu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[_r](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Fm=class extends Vu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},zm=t=>!!t.objectMode,Um=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Wn=class extends Rc{[Be]=!1;[ci]=!1;[Ye]=[];[Fe]=[];[Ze];[mt];[kt];[xr];[Gt]=!1;[ln]=!1;[ys]=!1;[bs]=!1;[ai]=null;[ze]=0;[Se]=!1;[di];[Ss]=!1;[On]=0;[st]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");zm(e)?(this[Ze]=!0,this[mt]=null):Um(e)?(this[mt]=e.encoding,this[Ze]=!1):(this[Ze]=!1,this[mt]=null),this[kt]=!!e.async,this[xr]=this[mt]?new Cm(this[mt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Fe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ye]});let{signal:r}=e;r&&(this[di]=r,r.aborted?this[Ua]():r.addEventListener("abort",()=>this[Ua]()))}get bufferLength(){return this[ze]}get encoding(){return this[mt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[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}[Ua](){this[Ss]=!0,this.emit("abort",this[di]?.reason),this.destroy(this[di]?.reason)}get aborted(){return this[Ss]}set aborted(t){}write(t,e,r){if(this[Ss])return!1;if(this[Gt])throw new Error("write after end");if(this[Se])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[kt]?li:Lm;if(!this[Ze]&&!Buffer.isBuffer(t)){if(Bm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Mm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ze]?(this[Be]&&this[ze]!==0&&this[Es](!0),this[Be]?this.emit("data",t):this[Ma](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[mt]&&!this[xr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[mt]&&(t=this[xr].write(t)),this[Be]&&this[ze]!==0&&this[Es](!0),this[Be]?this.emit("data",t):this[Ma](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Se])return null;if(this[st]=!1,this[ze]===0||t===0||t&&t>this[ze])return this[Ht](),null;this[Ze]&&(t=null),this[Fe].length>1&&!this[Ze]&&(this[Fe]=[this[mt]?this[Fe].join(""):Buffer.concat(this[Fe],this[ze])]);let e=this[xu](t||null,this[Fe][0]);return this[Ht](),e}[xu](t,e){if(this[Ze])this[vs]();else{let r=e;t===r.length||t===null?this[vs]():typeof r=="string"?(this[Fe][0]=r.slice(t),e=r.slice(0,t),this[ze]-=t):(this[Fe][0]=r.subarray(t),e=r.subarray(0,t),this[ze]-=t)}return this.emit("data",e),!this[Fe].length&&!this[Gt]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Gt]=!0,this.writable=!1,(this[Be]||!this[ci])&&this[Ht](),this}[_r](){this[Se]||(!this[On]&&!this[Ye].length&&(this[st]=!0),this[ci]=!1,this[Be]=!0,this.emit("resume"),this[Fe].length?this[Es]():this[Gt]?this[Ht]():this.emit("drain"))}resume(){return this[_r]()}pause(){this[Be]=!1,this[ci]=!0,this[st]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[ci]}[Ma](t){this[Ze]?this[ze]+=1:this[ze]+=t.length,this[Fe].push(t)}[vs](){return this[Ze]?this[ze]-=1:this[ze]-=this[Fe][0].length,this[Fe].shift()}[Es](t=!1){do;while(this[pu](this[vs]())&&this[Fe].length);!t&&!this[Fe].length&&!this[Gt]&&this.emit("drain")}[pu](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[st]=!1;let r=this[ln];return e=e||{},t===hu.stdout||t===hu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ye].push(e.proxyErrors?new Fm(this,t,e):new Vu(this,t,e)),this[kt]?li(()=>this[_r]()):this[_r]()),t}unpipe(t){let e=this[Ye].find(r=>r.dest===t);e&&(this[Ye].length===1?(this[Be]&&this[On]===0&&(this[Be]=!1),this[Ye]=[]):this[Ye].splice(this[Ye].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[st]=!1,this[On]++,!this[Ye].length&&!this[Be]&&this[_r]();else if(t==="readable"&&this[ze]!==0)super.emit("readable");else if(Nm(t)&&this[ln])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ai]){let i=e;this[kt]?li(()=>i.call(this,this[ai])):i.call(this,this[ai])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[On]=this.listeners("data").length,this[On]===0&&!this[st]&&!this[Ye].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[On]=0,!this[st]&&!this[Ye].length&&(this[Be]=!1)),e}get emittedEnd(){return this[ln]}[Ht](){!this[ys]&&!this[ln]&&!this[Se]&&this[Fe].length===0&&this[Gt]&&(this[ys]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[bs]&&this.emit("close"),this[ys]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ze]&&!r?!1:this[kt]?(li(()=>this[Fa](r)),!0):this[Fa](r);if(t==="end")return this[gu]();if(t==="close"){if(this[bs]=!0,!this[ln]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ai]=r,super.emit(Ba,r);let o=!this[di]||this.listeners("error").length?super.emit("error",r):!1;return this[Ht](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ht](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Ht](),i}[Fa](t){for(let r of this[Ye])r.dest.write(t)===!1&&this.pause();let e=this[st]?!1:super.emit("data",t);return this[Ht](),e}[gu](){return this[ln]?!1:(this[ln]=!0,this.readable=!1,this[kt]?(li(()=>this[za]()),!0):this[za]())}[za](){if(this[xr]){let e=this[xr].end();if(e){for(let r of this[Ye])r.dest.write(e);this[st]||super.emit("data",e)}}for(let e of this[Ye])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ze]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ze]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ze])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[mt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[st]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Gt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(Se,f),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(Se,f),this.pause(),i({value:x,done:!!this[Gt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Se,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((x,p)=>{o=p,i=x,this.once(Se,f),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[st]=!1;let t=!1,e=()=>(this.pause(),this.off(Ba,e),this.off(Se,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Ba,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[st]=!0,this[Fe].length=0,this[ze]=0;let e=this;return typeof e.close=="function"&&!this[bs]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return Pm}},Gm=et.writev,yn=Symbol("_autoClose"),bt=Symbol("_close"),ui=Symbol("_ended"),ce=Symbol("_fd"),Ga=Symbol("_finished"),$t=Symbol("_flags"),Ha=Symbol("_flush"),cc=Symbol("_handleChunk"),dc=Symbol("_makeBuf"),Ei=Symbol("_mode"),Is=Symbol("_needDrain"),Sr=Symbol("_onerror"),Ir=Symbol("_onopen"),qa=Symbol("_onread"),yr=Symbol("_onwrite"),bn=Symbol("_open"),yt=Symbol("_path"),pn=Symbol("_pos"),Tt=Symbol("_queue"),br=Symbol("_read"),ja=Symbol("_readSize"),Wt=Symbol("_reading"),fi=Symbol("_remain"),Wa=Symbol("_size"),Ns=Symbol("_write"),Ln=Symbol("_writing"),Ms=Symbol("_defaultFlag"),Gn=Symbol("_errored"),Cc=class extends Wn{[Gn]=!1;[ce];[yt];[ja];[Wt]=!1;[Wa];[fi];[yn];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[Gn]=!1,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[yt]=t,this[ja]=e.readSize||16*1024*1024,this[Wt]=!1,this[Wa]=typeof e.size=="number"?e.size:1/0,this[fi]=this[Wa],this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ce]=="number"?this[br]():this[bn]()}get fd(){return this[ce]}get path(){return this[yt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[bn](){et.open(this[yt],"r",(t,e)=>this[Ir](t,e))}[Ir](t,e){t?this[Sr](t):(this[ce]=e,this.emit("open",e),this[br]())}[dc](){return Buffer.allocUnsafe(Math.min(this[ja],this[fi]))}[br](){if(!this[Wt]){this[Wt]=!0;let t=this[dc]();if(t.length===0)return process.nextTick(()=>this[qa](null,0,t));et.read(this[ce],t,0,t.length,null,(e,r,i)=>this[qa](e,r,i))}}[qa](t,e,r){this[Wt]=!1,t?this[Sr](t):this[cc](e,r)&&this[br]()}[bt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Sr](t){this[Wt]=!0,this[bt](),this.emit("error",t)}[cc](t,e){let r=!1;return this[fi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[fi]<=0)&&(r=!1,this[bt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ce]=="number"&&this[br](),!1;case"error":return this[Gn]?!1:(this[Gn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Hm=class extends Cc{[bn](){let t=!0;try{this[Ir](null,et.openSync(this[yt],"r")),t=!1}finally{t&&this[bt]()}}[br](){let t=!0;try{if(!this[Wt]){this[Wt]=!0;do{let e=this[dc](),r=e.length===0?0:et.readSync(this[ce],e,0,e.length,null);if(!this[cc](r,e))break}while(!0);this[Wt]=!1}t=!1}finally{t&&this[bt]()}}[bt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,et.closeSync(t),this.emit("close")}}},Ys=class extends Rm{readable=!1;writable=!0;[Gn]=!1;[Ln]=!1;[ui]=!1;[Tt]=[];[Is]=!1;[yt];[Ei];[yn];[ce];[Ms];[$t];[Ga]=!1;[pn];constructor(t,e){e=e||{},super(e),this[yt]=t,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[Ei]=e.mode===void 0?438:e.mode,this[pn]=typeof e.start=="number"?e.start:void 0,this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[pn]!==void 0?"r+":"w";this[Ms]=e.flags===void 0,this[$t]=e.flags===void 0?r:e.flags,this[ce]===void 0&&this[bn]()}emit(t,...e){if(t==="error"){if(this[Gn])return!1;this[Gn]=!0}return super.emit(t,...e)}get fd(){return this[ce]}get path(){return this[yt]}[Sr](t){this[bt](),this[Ln]=!0,this.emit("error",t)}[bn](){et.open(this[yt],this[$t],this[Ei],(t,e)=>this[Ir](t,e))}[Ir](t,e){this[Ms]&&this[$t]==="r+"&&t&&t.code==="ENOENT"?(this[$t]="w",this[bn]()):t?this[Sr](t):(this[ce]=e,this.emit("open",e),this[Ln]||this[Ha]())}end(t,e){return t&&this.write(t,e),this[ui]=!0,!this[Ln]&&!this[Tt].length&&typeof this[ce]=="number"&&this[yr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ui]?(this.emit("error",new Error("write() after end()")),!1):this[ce]===void 0||this[Ln]||this[Tt].length?(this[Tt].push(t),this[Is]=!0,!1):(this[Ln]=!0,this[Ns](t),!0)}[Ns](t){et.write(this[ce],t,0,t.length,this[pn],(e,r)=>this[yr](e,r))}[yr](t,e){t?this[Sr](t):(this[pn]!==void 0&&typeof e=="number"&&(this[pn]+=e),this[Tt].length?this[Ha]():(this[Ln]=!1,this[ui]&&!this[Ga]?(this[Ga]=!0,this[bt](),this.emit("finish")):this[Is]&&(this[Is]=!1,this.emit("drain"))))}[Ha](){if(this[Tt].length===0)this[ui]&&this[yr](null,0);else if(this[Tt].length===1)this[Ns](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],Gm(this[ce],t,this[pn],(e,r)=>this[yr](e,r))}}[bt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Zu=class extends Ys{[bn](){let t;if(this[Ms]&&this[$t]==="r+")try{t=et.openSync(this[yt],this[$t],this[Ei])}catch(e){if(e?.code==="ENOENT")return this[$t]="w",this[bn]();throw e}else t=et.openSync(this[yt],this[$t],this[Ei]);this[Ir](null,t)}[bt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,et.closeSync(t),this.emit("close")}}[Ns](t){let e=!0;try{this[yr](null,et.writeSync(this[ce],t,0,t.length,this[pn])),e=!1}finally{if(e)try{this[bt]()}catch{}}}},Wm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),$m=t=>!!t.sync&&!!t.file,Km=t=>!t.sync&&!!t.file,Vm=t=>!!t.sync&&!t.file,Zm=t=>!t.sync&&!t.file,Jm=t=>!!t.file,Ym=t=>Wm.get(t)||t,Pc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Ym(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Pi=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=Pc(c);if(o?.(f,d),$m(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if(Km(f)){let x=e(f,d);return u?x.then(()=>u(),u):x}else if(Vm(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,d)}else if(Zm(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),ew=Qm.constants||{ZLIB_VERNUM:4736},Dt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},ew)),tw=Hn.concat,wu=Object.getOwnPropertyDescriptor(Hn,"concat"),nw=t=>t,$a=wu?.writable===!0||wu?.set!==void 0?t=>{Hn.concat=t?nw:tw}:t=>{},qn=Symbol("_superWrite"),As=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Ka=Symbol("flushFlag"),Dc=class extends Wn{#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 mu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new mu[e](t)}catch(r){throw new As(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 As(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return lc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Hn.alloc(0),{[Ka]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[qn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Hn.from(t,e)),this.#e)return;lc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let d;try{let f=typeof t[Ka]=="number"?t[Ka]:this.#r;d=this.#t._processChunk(t,f),$a(!1)}catch(f){$a(!1),this.#o(new As(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 As(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[qn](Hn.from(f));for(let x=1;x<d.length;x++)u=this[qn](d[x])}else u=this[qn](Hn.from(d));return r&&r(),u}},Yu=class extends Dc{#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),lc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},rw=class extends Yu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[qn](t){return this.#e?(this.#e=!1,t[9]=255,super[qn](t)):super[qn](t)}},iw=class extends Yu{constructor(t){super(t,"Unzip")}},Xu=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Dt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Dt.BROTLI_OPERATION_FLUSH,super(t,e)}},sw=class extends Xu{constructor(t){super(t,"BrotliCompress")}},ow=class extends Xu{constructor(t){super(t,"BrotliDecompress")}},Qu=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Dt.ZSTD_e_end,t.fullFlushFlag=Dt.ZSTD_e_flush,super(t,e)}},aw=class extends Qu{constructor(t){super(t,"ZstdCompress")}},cw=class extends Qu{constructor(t){super(t,"ZstdDecompress")}},dw=(t,e)=>{if(Number.isSafeInteger(t))t<0?uw(t,e):lw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},lw=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},uw=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=ef(o):o===0?e[i-1]=0:(r=!0,e[i-1]=tf(o))}},fw=t=>{let e=t[0],r=e===128?xw(t.subarray(1,t.length)):e===255?hw(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},hw=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=ef(c):c===0?d=c:(i=!0,d=tf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},xw=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},ef=t=>(255^t)&255,tf=t=>(255^t)+1&255,pw={};Tm(pw,{code:()=>Oc,isCode:()=>Bs,isName:()=>gw,name:()=>Xs,normalFsTypes:()=>nf});var Bs=t=>Xs.has(t),gw=t=>Oc.has(t),nf=new Set(["0","","1","2","3","4","5","6","7","D"]),Xs=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"]]),Oc=new Map(Array.from(Xs).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");let o=Nn(t,e+156,1),c=nf.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??Nn(t,e,100),this.mode=d?.mode??u?.mode??gn(t,e+100,8),this.uid=d?.uid??u?.uid??gn(t,e+108,8),this.gid=d?.gid??u?.gid??gn(t,e+116,8),this.size=d?.size??u?.size??gn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Va(t,e+136,12),this.cksum=gn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Bs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Nn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Nn(t,e+265,32),this.gname=d?.gname??u?.gname??Nn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??gn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??gn(t,e+337,8)??0,t[e+475]!==0){let x=Nn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Nn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=r?.atime??i?.atime??Va(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Va(t,e+488,12)}let f=256;for(let x=e;x<e+148;x++)f+=t[x];for(let x=e+156;x<e+512;x++)f+=t[x];this.cksumValid=f===this.cksum,this.cksum===void 0&&f===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=mw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Mn(t,e,100,o)||this.needPax,this.needPax=mn(t,e+100,8,this.mode)||this.needPax,this.needPax=mn(t,e+108,8,this.uid)||this.needPax,this.needPax=mn(t,e+116,8,this.gid)||this.needPax,this.needPax=mn(t,e+124,12,this.size)||this.needPax,this.needPax=Za(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Mn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Mn(t,e+265,32,this.uname)||this.needPax,this.needPax=Mn(t,e+297,32,this.gname)||this.needPax,this.needPax=mn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=mn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Mn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Mn(t,e+345,155,c)||this.needPax:(this.needPax=Mn(t,e+345,130,c)||this.needPax,this.needPax=Za(t,e+476,12,this.atime)||this.needPax,this.needPax=Za(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,mn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Xs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Oc.get(t));if(Bs(e)||e==="Unsupported")this.#e=e;else if(Bs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},mw=(t,e)=>{let r=t,i="",o,c=pr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=pr.dirname(r),r=pr.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=pr.join(pr.basename(i),r),i=pr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Nn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Va=(t,e,r)=>ww(gn(t,e,r)),ww=t=>t===void 0?void 0:new Date(t*1e3),gn=(t,e,r)=>Number(t[e])&128?fw(t.subarray(e,e+r)):yw(t,e,r),_w=t=>isNaN(t)?void 0:t,yw=(t,e,r)=>_w(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),bw={12:8589934591,8:2097151},mn=(t,e,r,i)=>i===void 0?!1:i>bw[r]||i<0?(dw(i,t.subarray(e,e+r)),!0):(Ew(t,e,r,i),!1),Ew=(t,e,r,i)=>t.write(vw(i,r),e,r,"ascii"),vw=(t,e)=>Sw(Math.floor(t).toString(8),e),Sw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Za=(t,e,r,i)=>i===void 0?!1:mn(t,e,r,i.getTime()/1e3),Iw=new Array(156).join("\0"),Mn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Iw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),$s=class rf{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/"+Aw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
+
`,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,r,i=!1){return new rf(kw(Tw(e),r),i)}},kw=(t,e)=>e?Object.assign({},e,t):t,Tw=t=>t.replace(/\n$/,"").split(`
|
|
91
|
+
`).reduce(Rw,Object.create(null)),Rw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Cw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=Cw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Pw=class extends Wn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=X(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?X(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Qs=(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))},Dw=1024*1024,uc=Buffer.from([31,139]),fc=Buffer.from([40,181,47,253]),Ow=Math.max(uc.length,fc.length),lt=Symbol("state"),Bn=Symbol("writeEntry"),qt=Symbol("readEntry"),Ja=Symbol("nextEntry"),_u=Symbol("processEntry"),Rt=Symbol("extendedHeader"),hi=Symbol("globalExtendedHeader"),un=Symbol("meta"),yu=Symbol("emitMeta"),ge=Symbol("buffer"),jt=Symbol("queue"),fn=Symbol("ended"),Ya=Symbol("emittedEnd"),Fn=Symbol("emit"),Te=Symbol("unzip"),ks=Symbol("consumeChunk"),Ts=Symbol("consumeChunkSub"),Xa=Symbol("consumeBody"),bu=Symbol("consumeMeta"),Eu=Symbol("consumeHeader"),xi=Symbol("consuming"),Qa=Symbol("bufferConcat"),Rs=Symbol("maybeEnd"),gr=Symbol("writing"),hn=Symbol("aborted"),Cs=Symbol("onDone"),zn=Symbol("sawValidEntry"),Ps=Symbol("sawNullBlock"),Ds=Symbol("sawEOF"),vu=Symbol("closeStream"),Lw=()=>!0,Ci=class extends Xm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[jt]=[];[ge];[qt];[Bn];[lt]="begin";[un]="";[Rt];[hi];[fn]=!1;[Te];[hn]=!1;[zn];[Ps]=!1;[Ds]=!1;[gr]=!1;[xi]=!1;[Ya]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Cs,()=>{(this[lt]==="begin"||this[zn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Cs,t.ondone):this.on(Cs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Dw,this.filter=typeof t.filter=="function"?t.filter:Lw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[vu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Qs(this,t,e,r)}[Eu](t,e){this[zn]===void 0&&(this[zn]=!1);let r;try{r=new jn(t,e,this[Rt],this[hi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ps]?(this[Ds]=!0,this[lt]==="begin"&&(this[lt]="header"),this[Fn]("eof")):(this[Ps]=!0,this[Fn]("nullBlock"));else if(this[Ps]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Bn]=new Pw(r,this[Rt],this[hi]);if(!this[zn])if(o.remain){let c=()=>{o.invalid||(this[zn]=!0)};o.on("end",c)}else this[zn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Fn]("ignoredEntry",o),this[lt]="ignore",o.resume()):o.size>0&&(this[un]="",o.on("data",c=>this[un]+=c),this[lt]="meta"):(this[Rt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Fn]("ignoredEntry",o),this[lt]=o.remain?"ignore":"header",o.resume()):(o.remain?this[lt]="body":(this[lt]="header",o.end()),this[qt]?this[jt].push(o):(this[jt].push(o),this[Ja]())))}}}[vu](){queueMicrotask(()=>this.emit("close"))}[_u](t){let e=!0;if(!t)this[qt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[qt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ja]()),e=!1);return e}[Ja](){do;while(this[_u](this[jt].shift()));if(this[jt].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[gr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Xa](t,e){let r=this[Bn];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[lt]="header",this[Bn]=void 0,r.end()),o.length}[bu](t,e){let r=this[Bn],i=this[Xa](t,e);return!this[Bn]&&r&&this[yu](r),i}[Fn](t,e,r){this[jt].length===0&&!this[qt]?this.emit(t,e,r):this[jt].push([t,e,r])}[yu](t){switch(this[Fn]("meta",this[un]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Rt]=$s.parse(this[un],this[Rt],!1);break;case"GlobalExtendedHeader":this[hi]=$s.parse(this[un],this[hi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Rt]??Object.create(null);this[Rt]=e,e.path=this[un].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Rt]||Object.create(null);this[Rt]=e,e.linkpath=this[un].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[hn]=!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[hn])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[ge]&&(t=Buffer.concat([this[ge],t]),this[ge]=void 0),t.length<Ow)return this[ge]=t,r?.(),!0;for(let d=0;this[Te]===void 0&&d<uc.length;d++)t[d]!==uc[d]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<fc.length;d++)if(t[d]!==fc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[fn])this.brotli=!0;else return this[ge]=t,r?.(),!0;else try{new jn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let d=this[fn];this[fn]=!1,this[Te]=this[Te]===void 0?new iw({}):o?new cw({}):new ow({}),this[Te].on("data",f=>this[ks](f)),this[Te].on("error",f=>this.abort(f)),this[Te].on("end",()=>{this[fn]=!0,this[ks]()}),this[gr]=!0;let u=!!this[Te][d?"end":"write"](t);return this[gr]=!1,r?.(),u}}this[gr]=!0,this[Te]?this[Te].write(t):this[ks](t),this[gr]=!1;let i=this[jt].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[jt].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Qa](t){t&&!this[hn]&&(this[ge]=this[ge]?Buffer.concat([this[ge],t]):t)}[Rs](){if(this[fn]&&!this[Ya]&&!this[hn]&&!this[xi]){this[Ya]=!0;let t=this[Bn];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[Fn](Cs)}}[ks](t){if(this[xi]&&t)this[Qa](t);else if(!t&&!this[ge])this[Rs]();else if(t){if(this[xi]=!0,this[ge]){this[Qa](t);let e=this[ge];this[ge]=void 0,this[Ts](e)}else this[Ts](t);for(;this[ge]&&this[ge]?.length>=512&&!this[hn]&&!this[Ds];){let e=this[ge];this[ge]=void 0,this[Ts](e)}this[xi]=!1}(!this[ge]||this[fn])&&this[Rs]()}[Ts](t){let e=0,r=t.length;for(;e+512<=r&&!this[hn]&&!this[Ds];)switch(this[lt]){case"begin":case"header":this[Eu](t,e),e+=512;break;case"ignore":case"body":e+=this[Xa](t,e);break;case"meta":e+=this[bu](t,e);break;default:throw new Error("invalid state: "+this[lt])}e<r&&(this[ge]=this[ge]?Buffer.concat([t.subarray(e),this[ge]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[hn]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[fn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Rs]())),this}},vi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},Nw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},sf=(t,e)=>{let r=new Map(e.map(c=>[vi(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||jm(c).root||".",f;if(c===u)f=!1;else{let x=r.get(c);f=x!==void 0?x:o(qm(c),u)}return r.set(c,f),f};t.filter=i?(c,d)=>i(c,d)&&o(vi(c)):c=>o(vi(c))},Mw=t=>{let e=new Ci(t),r=t.file,i;try{i=Er.openSync(r,"r");let o=Er.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Er.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let f=Er.readSync(i,u,0,c,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{Er.closeSync(i)}catch{}}},Bw=(t,e)=>{let r=new Ci(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),Er.stat(o,(u,f)=>{if(u)d(u);else{let x=new Cc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},Ar=Pi(Mw,Bw,t=>new Ci(t),t=>new Ci(t),(t,e)=>{e?.length&&sf(t,e),t.noResume||Nw(t)}),of=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:zw,parse:Iu}=Fw,Lc=t=>{let e="",r=Iu(t);for(;zw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Iu(t)}return[e,t]},eo=["|","<",">","?",":"],Nc=eo.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Uw=new Map(eo.map((t,e)=>[t,Nc[e]])),Gw=new Map(Nc.map((t,e)=>[t,eo[e]])),Au=t=>eo.reduce((e,r)=>e.split(r).join(Uw.get(r)),t),Hw=t=>Nc.reduce((e,r)=>e.split(r).join(Gw.get(r)),t),af=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),vi(e)+"/"+t):X(t),qw=16*1024*1024,ku=Symbol("process"),Tu=Symbol("file"),Ru=Symbol("directory"),hc=Symbol("symlink"),Cu=Symbol("hardlink"),pi=Symbol("header"),Fs=Symbol("read"),xc=Symbol("lstat"),zs=Symbol("onlstat"),pc=Symbol("onread"),gc=Symbol("onreadlink"),mc=Symbol("openfile"),wc=Symbol("onopenfile"),wn=Symbol("close"),Vs=Symbol("mode"),_c=Symbol("awaitDrain"),ec=Symbol("ondrain"),Pt=Symbol("prefix"),cf=class extends Wn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Pc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||qw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Lc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Hw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(r.absolute||Su.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[xc]()}warn(t,e,r={}){return Qs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[xc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[zs](e)})}[zs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=$w(t),this.emit("stat",t),this[ku]()}[ku](){switch(this.type){case"File":return this[Tu]();case"Directory":return this[Ru]();case"SymbolicLink":return this[hc]();default:return this.end()}}[Vs](t){return of(t,this.type==="Directory",this.portable)}[Pt](t){return af(t,this.prefix)}[pi](){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[Vs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new $s({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[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)}[Ru](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[pi](),this.end()}[hc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[gc](e)})}[gc](t){this.linkpath=X(t),this[pi](),this.end()}[Cu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(Su.relative(this.cwd,t)),this.stat.size=0,this[pi](),this.end()}[Tu](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[Cu](e);this.linkCache.set(t,this.absolute)}if(this[pi](),this.stat.size===0)return this.end();this[mc]()}[mc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[wc](e)})}[wc](t){if(this.fd=t,this.#e)return this[wn]();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[Fs]()}[Fs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Ct.read(t,e,r,i,o,(c,d)=>{if(c)return this[wn](()=>this.emit("error",c));this[pc](d)})}[wn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[pc](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[wn](()=>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[wn](()=>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[ec]():this[_c](()=>this[ec]())}[_c](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)}[ec](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[wn](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[Fs]()}},jw=class extends cf{sync=!0;[xc](){this[zs](Ct.lstatSync(this.absolute))}[hc](){this[gc](Ct.readlinkSync(this.absolute))}[mc](){this[wc](Ct.openSync(this.absolute,"r"))}[Fs](){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=Ct.readSync(e,r,i,o,c);this[pc](d),t=!1}finally{if(t)try{this[wn](()=>{})}catch{}}}[_c](t){t()}[wn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},Ww=class extends Wn{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 Qs(this,t,e,r)}constructor(t,e={}){let r=Pc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=X(t.path),this.mode=t.mode!==void 0?this[Vs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Lc(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 $s({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[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 af(t,this.prefix)}[Vs](t){return of(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}},$w=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Kw=class vr{tail;head;length=0;static create(e=[]){return new vr(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++)Zw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Jw(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 vr;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 vr;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 vr;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 vr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=Vw(this,o,d);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function Vw(t,e,r){let i=e,o=e?e.next:t.head,c=new Mc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Zw(t,e){t.tail=new Mc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Jw(t,e){t.head=new Mc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Mc=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}},Du=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Ou=Buffer.alloc(1024),Us=Symbol("onStat"),gi=Symbol("ended"),wt=Symbol("queue"),mi=Symbol("pendingLinks"),xn=Symbol("current"),Un=Symbol("process"),wi=Symbol("processing"),Os=Symbol("processJob"),_t=Symbol("jobs"),tc=Symbol("jobDone"),Gs=Symbol("addFSEntry"),Lu=Symbol("addTarEntry"),yc=Symbol("stat"),bc=Symbol("readdir"),Hs=Symbol("onreaddir"),qs=Symbol("pipe"),Nu=Symbol("entry"),nc=Symbol("entryOpt"),js=Symbol("writeEntryClass"),df=Symbol("write"),rc=Symbol("ondrain"),to=class extends Wn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[js];onWriteEntry;[wt];[mi]=new Map;[_t]=0;[wi]=!1;[gi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=X(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[js]=cf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new rw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new sw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new aw(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[rc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[rc]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[wt]=new Kw,this[_t]=0,this.jobs=Number(t.jobs)||4,this[wi]=!1,this[gi]=!1}[df](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[gi]=!0,this[Un](),r&&r(),this}write(t){if(this[gi])throw new Error("write after end");return typeof t=="string"?this[Gs](t):this[Lu](t),this.flowing}[Lu](t){let e=X(Pu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Du(t.path,e);r.entry=new Ww(t,this[nc](r)),r.entry.on("end",()=>this[tc](r)),this[_t]+=1,this[wt].push(r)}this[Un]()}[Gs](t){let e=X(Pu.resolve(this.cwd,t));this[wt].push(new Du(t,e)),this[Un]()}[yc](t){t.pending=!0,this[_t]+=1;let e=this.follow?"stat":"lstat";Ks[e](t.absolute,(r,i)=>{t.pending=!1,this[_t]-=1,r?this.emit("error",r):this[Us](t,i)})}[Us](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[xn])this[Os](t);else{let r=`${e.dev}:${e.ino}`,i=this[mi].get(r);i?i.push(t):this[mi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Un]()}[bc](t){t.pending=!0,this[_t]+=1,Ks.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[_t]-=1,e)return this.emit("error",e);this[Hs](t,r)})}[Hs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Un]()}[Un](){if(!this[wi]){this[wi]=!0;for(let t=this[wt].head;t&&this[_t]<this.jobs;t=t.next)if(this[Os](t.value),t.value.ignore){let e=t.next;this[wt].removeNode(t),t.next=e}this[wi]=!1,this[gi]&&this[wt].length===0&&this[_t]===0&&(this.zip?this.zip.end(Ou):(super.write(Ou),super.end()))}}get[xn](){return this[wt]&&this[wt].head&&this[wt].head.value}[tc](t){this[wt].shift(),this[_t]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[mi].get(r);if(i){this[mi].delete(r);for(let o of i)o.pending=!1,this[Os](o)}}this[Un]()}[Os](t){if(t.pending&&t.pendingLink&&t===this[xn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[xn]&&!t.piped&&this[qs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Us](t,e):this[yc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Hs](t,e):this[bc](t),!t.readdir)return}if(t.entry=this[Nu](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[qs](t)}}}[nc](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}}[Nu](t){this[_t]+=1;try{return new this[js](t.path,this[nc](t)).on("end",()=>this[tc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[rc](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[qs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Gs](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={}){Qs(this,t,e,r)}},Bc=class extends to{sync=!0;constructor(t){super(t),this[js]=jw}pause(){}resume(){}[yc](t){let e=this.follow?"statSync":"lstatSync";this[Us](t,Ks[e](t.absolute))}[bc](t){this[Hs](t,Ks.readdirSync(t.absolute))}[qs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Gs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[df](i)})}},Yw=(t,e)=>{let r=new Bc(t),i=new Zu(t.file,{mode:t.mode||438});r.pipe(i),lf(r,e)},Xw=(t,e)=>{let r=new to(t),i=new Ys(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 uf(r,e).catch(c=>r.emit("error",c)),o},lf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Ar({file:Ju.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},uf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Ar({file:Ju.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Qw=(t,e)=>{let r=new Bc(t);return lf(r,e),r},e_=(t,e)=>{let r=new to(t);return uf(r,e).catch(i=>r.emit("error",i)),r},kA=Pi(Yw,Xw,Qw,e_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),n_=process.env.__FAKE_PLATFORM__||process.platform,pf=n_==="win32",{O_CREAT:gf,O_NOFOLLOW:Mu,O_TRUNC:mf,O_WRONLY:wf}=xf.constants,_f=Number(process.env.__FAKE_FS_O_FILENAME__)||xf.constants.UV_FS_O_FILEMAP||0,r_=pf&&!!_f,i_=512*1024,s_=_f|mf|gf|wf,Bu=!pf&&typeof Mu=="number"?Mu|mf|gf|wf:null,yf=Bu!==null?()=>Bu:r_?t=>t<i_?s_:"w":()=>"w",Ec=(t,e,r)=>{try{return no.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Zs=(t,e,r,i)=>{no.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},o_=(t,e,r,i,o)=>{if(e.isDirectory())bf(Si.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=Si.resolve(t,e.name);Zs(d,r,i,o)});else{let c=Si.resolve(t,e.name);Zs(c,r,i,o)}},bf=(t,e,r,i)=>{no.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return Zs(t,e,r,i);let d=c.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--d===0)return Zs(t,e,r,i)}};for(let x of c)o_(t,x,e,r,f)})},a_=(t,e,r,i)=>{e.isDirectory()&&Ef(Si.resolve(t,e.name),r,i),Ec(Si.resolve(t,e.name),r,i)},Ef=(t,e,r)=>{let i;try{i=no.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Ec(t,e,r);throw c}for(let o of i)a_(t,o,e,r);return Ec(t,e,r)},vf=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"}},ro=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)=>{at.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new vf(t,r?.code||"ENOTDIR")),e(r)})},l_=(t,e,r)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,p=e.unlink,_=X(e.cwd),v=(E,I)=>{E?r(E):I&&f?bf(I,d,u,A=>v(A)):c?at.chmod(t,o,r):r()};if(t===_)return d_(t,v);if(x)return c_.mkdir(t,{mode:o,recursive:!0}).then(E=>v(null,E??void 0),v);let w=X(Js.relative(_,t)).split("/");vc(_,w,o,p,_,void 0,v)},vc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),f=X(Js.resolve(t+"/"+u));at.mkdir(f,r,Sf(f,e,r,i,o,c,d))},Sf=(t,e,r,i,o,c,d)=>u=>{u?at.lstat(t,(f,x)=>{if(f)f.path=f.path&&X(f.path),d(f);else if(x.isDirectory())vc(t,e,r,i,o,c,d);else if(i)at.unlink(t,p=>{if(p)return d(p);at.mkdir(t,r,Sf(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new ro(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,vc(t,e,r,i,o,c,d))},u_=t=>{let e=!1,r;try{e=at.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new vf(t,r??"ENOTDIR")}},f_=(t,e)=>{t=X(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),f=e.preserve,x=e.unlink,p=X(e.cwd),_=E=>{E&&u&&Ef(E,c,d),o&&at.chmodSync(t,i)};if(t===p)return u_(p),_();if(f)return _(at.mkdirSync(t,{mode:i,recursive:!0})??void 0);let v=X(Js.relative(p,t)).split("/"),w;for(let E=v.shift(),I=p;E&&(I+="/"+E);E=v.shift()){I=X(Js.resolve(I));try{at.mkdirSync(I,i),w=w||I}catch{let A=at.lstatSync(I);if(A.isDirectory())continue;if(x){at.unlinkSync(I),at.mkdirSync(I,i),w=w||I;continue}else if(A.isSymbolicLink())return new ro(I,I+"/"+v.join("/"))}}return _(w)},ic=Object.create(null),Fu=1e4,mr=new Set,h_=t=>{mr.has(t)?mr.delete(t):ic[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),mr.add(t);let e=ic[t],r=mr.size-Fu;if(r>Fu/10){for(let i of mr)if(mr.delete(i),delete ic[i],--r<=0)break}return e},x_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,p_=x_==="win32",g_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=If(i,r)),e.push(r||"/"),e},[]),m_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=p_?["win32 parallelization disabled"]:t.map(i=>vi(If(h_(i))));let r=new Set(t.map(i=>g_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},w_=()=>process.umask(),zu=Symbol("onEntry"),Sc=Symbol("checkFs"),Uu=Symbol("checkFs2"),Ic=Symbol("isReusable"),ut=Symbol("makeFs"),Ac=Symbol("file"),kc=Symbol("directory"),Ws=Symbol("link"),Gu=Symbol("symlink"),Hu=Symbol("hardlink"),bi=Symbol("ensureNoSymlink"),qu=Symbol("unsupported"),ju=Symbol("checkPath"),sc=Symbol("stripAbsolutePath"),_n=Symbol("mkdir"),Ue=Symbol("onError"),Ls=Symbol("pending"),Wu=Symbol("pend"),wr=Symbol("unpend"),oc=Symbol("ended"),ac=Symbol("maybeClose"),Tc=Symbol("skip"),Ii=Symbol("doChown"),Ai=Symbol("uid"),ki=Symbol("gid"),Ti=Symbol("checkedCwd"),__=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ri=__==="win32",y_=1024,b_=(t,e)=>{if(!Ri)return re.unlink(t,e);let r=t+".DELETE."+hf(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},E_=t=>{if(!Ri)return re.unlinkSync(t);let e=t+".DELETE."+hf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},$u=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Fc=class extends Ci{[oc]=!1;[Ti]=!1;[Ls]=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[oc]=!0,this[ac]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:y_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ri,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:w_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[zu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[ac](){this[oc]&&this[Ls]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[sc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Lc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ri&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Le.posix.dirname(t.path),f=Le.posix.normalize(Le.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}[ju](t){let e=X(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=X(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[sc](t,"path")||!this[sc](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?X(Le.resolve(t.path)):X(Le.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:X(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Le.win32.parse(String(t.absolute));t.absolute=i+Au(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+Au(t.path.slice(o.length))}return!0}[zu](t){if(!this[ju](t))return t.resume();switch(t_.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Sc](t);default:return this[qu](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[wr](),e.resume())}[_n](t,e,r){l_(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[Ii](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}[Ai](t){return $u(this.uid,t.uid,this.processUid)}[ki](t){return $u(this.gid,t.gid,this.processGid)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Ys(String(t.absolute),{flags:yf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,f=>{f?this[Ue](f,t):this[wr](),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,p=t.mtime;re.futimes(f,x,p,_=>_?re.utimes(u,x,p,v=>c(v&&_)):c())}if(typeof f=="number"&&this[Ii](t)){o++;let x=this[Ai](t),p=this[ki](t);typeof x=="number"&&typeof p=="number"&&re.fchown(f,x,p,_=>_?re.chown(u,x,p,v=>c(v&&_)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[Ue](u,t),e()}),t.pipe(d)),d.pipe(i)}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[_n](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[wr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ii](t)&&(o++,re.chown(String(t.absolute),Number(this[Ai](t)),Number(this[ki](t)),c)),c()})}[qu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Gu](t,e){let r=X(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[bi](t,this.cwd,r,()=>this[Ws](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[Hu](t,e){let r=X(Le.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[bi](t,this.cwd,i,()=>this[Ws](t,r,"link",e),o=>{this[Ue](o,t),e()})}[bi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Le.resolve(e,c);re.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new ro(d,Le.resolve(d,r.join("/"))));this[bi](t,d,r,i,o)})}[Wu](){this[Ls]++}[wr](){this[Ls]--,this[ac]()}[Tc](t){this[wr](),t.resume()}[Ic](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ri}[Sc](t){this[Wu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Uu](t,r))}[Uu](t,e){let r=d=>{e(d)},i=()=>{this[_n](this.cwd,this.dmode,d=>{if(d){this[Ue](d,t),r();return}this[Ti]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=X(Le.dirname(String(t.absolute)));if(d!==this.cwd)return this[_n](d,this.dmode,u=>{if(u){this[Ue](u,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Tc](t),r();return}if(d||this[Ic](t,u))return this[ut](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=p=>this[ut](p??null,t,r);return f?re.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),f=>this[ut](f??null,t,r))}if(t.absolute===this.cwd)return this[ut](null,t,r);b_(String(t.absolute),f=>this[ut](f??null,t,r))})};this[Ti]?o():i()}[ut](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Ac](e,r);case"Link":return this[Hu](e,r);case"SymbolicLink":return this[Gu](e,r);case"Directory":case"GNUDumpDir":return this[kc](e,r)}}[Ws](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[wr](),t.resume()),i()})}},_i=t=>{try{return[null,t()]}catch(e){return[e,null]}},Af=class extends Fc{sync=!0;[ut](t,e){return super[ut](t,e,()=>{})}[Sc](t){if(!this[Ti]){let o=this[_n](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[Ti]=!0}if(t.absolute!==this.cwd){let o=X(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[_n](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=_i(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Tc](t);if(e||this[Ic](t,r))return this[ut](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?_i(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ut](d,t)}let[o]=_i(()=>re.rmdirSync(String(t.absolute)));this[ut](o,t)}let[i]=t.absolute===this.cwd?[]:_i(()=>E_(String(t.absolute)));this[ut](i,t)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{re.closeSync(o)}catch(f){u=f}(d||u)&&this[Ue](d||u,t),e()},o;try{o=re.openSync(String(t.absolute),yf(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[Ue](d,t)),t.pipe(c)),c.on("data",d=>{try{re.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{re.futimesSync(o,u,f)}catch(x){try{re.utimesSync(String(t.absolute),u,f)}catch{d=x}}}if(this[Ii](t)){let u=this[Ai](t),f=this[ki](t);try{re.fchownSync(o,Number(u),Number(f))}catch(x){try{re.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||x}}}i(d)})}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[_n](String(t.absolute),r);if(i){this[Ue](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ii](t))try{re.chownSync(String(t.absolute),Number(this[Ai](t)),Number(this[ki](t)))}catch{}e(),t.resume()}[_n](t,e){try{return f_(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[bi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Le.resolve(c,d);let[u,f]=_i(()=>re.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new ro(c,Le.resolve(e,r.join("/"))))}i()}[Ws](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},v_=t=>{let e=new Af(t),r=t.file,i=ff.statSync(r),o=t.maxReadSize||16*1024*1024;new Hm(r,{readSize:o,size:i.size}).pipe(e)},S_=(t,e)=>{let r=new Fc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),ff.stat(o,(u,f)=>{if(u)d(u);else{let x=new Cc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},kf=Pi(v_,S_,t=>new Af(t),t=>new Fc(t),(t,e)=>{e?.length&&sf(t,e)}),I_=(t,e)=>{let r=new Bc(t),i=!0,o,c;try{try{o=ot.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=ot.openSync(t.file,"w+");else throw f}let d=ot.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let p=0,_=0;p<512;p+=_){if(_=ot.readSync(o,u,p,u.length-p,c+p),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)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,A_(t,r,c,o,e)}finally{if(i)try{ot.closeSync(o)}catch{}}},A_=(t,e,r,i,o)=>{let c=new Zu(t.file,{fd:i,start:r});e.pipe(c),T_(e,o)},k_=(t,e)=>{e=Array.from(e);let r=new to(t),i=(o,c,d)=>{let u=(v,w)=>{v?ot.close(o,E=>d(v)):d(null,w)},f=0;if(c===0)return u(null,0);let x=0,p=Buffer.alloc(512),_=(v,w)=>{if(v||w===void 0)return u(v);if(x+=w,x<512&&w)return ot.read(o,p,x,p.length-x,f+x,_);if(f===0&&p[0]===31&&p[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let E=new jn(p);if(!E.cksumValid)return u(null,f);let I=512*Math.ceil((E.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&E.mtime&&t.mtimeCache.set(String(E.path),E.mtime),x=0,ot.read(o,p,0,512,f,_)};ot.read(o,p,0,512,f,_)};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+",ot.open(t.file,d,u);if(f||!x)return c(f);ot.fstat(x,(p,_)=>{if(p)return ot.close(x,()=>c(p));i(x,_.size,(v,w)=>{if(v)return c(v);let E=new Ys(t.file,{fd:x,start:w});r.pipe(E),E.on("error",c),E.on("close",o),R_(r,e)})})};ot.open(t.file,d,u)})},T_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Ar({file:Tf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},R_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Ar({file:Tf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},yi=Pi(I_,k_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Jm(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")}),HA=Pi(yi.syncFile,yi.asyncFile,yi.syncNoFile,yi.asyncNoFile,(t,e=[])=>{yi.validate?.(t,e),C_(t)}),C_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};cn();var ft={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 io(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Rf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function so(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Cf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Pf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function $n(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();qe();te();De();qe();function kr(t,e){if(io(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Di(t){return t.startsWith("http://")||t.startsWith("https://")}function Tr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as O2}from"node:fs";import{dirname as N2,join as M2}from"node:path";import{fileURLToPath as F2}from"node:url";var Ot="0.2.0-alpha.0";qe();te();var oo="1008033",Nf="1289";var Mf="pbbp2",Bf="https://www.coze.cn",Ff="/api/coze_claw/resource/get_frontier_key",F_="https://www.coze.cn",z_="wss://frontier.coze.cn";function Rr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??F_}function zf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??z_}function En(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Li(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Oi=G("handshake");async function zc(t){let e=Rr(t.endpoint),r=t.timeoutMs??1e4,i=`${Tr(e)}${Ff}?aid=${encodeURIComponent(oo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...En(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Oi.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 E=await u.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${E.slice(0,200)}`)}let p=await u.json();if(p.code!==void 0&&p.code!==0)throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${p.code} msg=${p.msg??"-"} logid=${f}`);let _=p.data??{},v=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,w=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!v||!w){let E=JSON.stringify(p).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${E}`)}return Oi.info("handshake ok",{remoteDeviceId:w,logid:f,traceId:x}),{accessKey:v,deviceId:w}}catch(u){if(u instanceof k)throw Oi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Oi.warn("handshake timeout",{base:e,timeoutMs:r}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Oi.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 Uc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Et="auto",Uf=15e4;function Gf(t){return{model:Gc(t.model)??Et,...t.modelToken?{modelToken:t.modelToken}:{}}}function U_(t){return!t||t===Et}var G_=new Set(["auto","\u81EA\u52A8"]);function Gc(t){let e=t?.trim();if(e)return G_.has(e.toLowerCase())?Et:e}function Hf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Uc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Et;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else U_(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function qf(t,e,r){return t.modelToken?{baseUrl:`${Uc}/v1`,providerName:"coze",headers:{Authorization:`Bearer ${t.modelToken}`,...Hc(e,r)}}:null}function jf(t){if(!t.modelToken)return{};let e={model:t.model||Et,model_context_window:t.modelInfo?.contextWindow??Uf};return{CODEX_CONFIG:JSON.stringify(e)}}function Hc(t,e){let{ttEnv:r,usePpe:i}=Li(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Wf(t,e,r){if(!t.modelToken)return{};let i=Hc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
+
`)}}function qc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function $f(t,e,r){if(!t.modelToken)return null;let i=t.model||Et,o=Hc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Uc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Uf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}var fe=G("agent-handlers"),Vf=5*1024*1024,W_=1,$_=6,K_=new Set(["node_modules",".git",".coze","dist","build",".next"]),V_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,Z_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,J_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function Y_(t){let e=t?.trim();return e?J_.test(e)||Z_.test(e)?e:(fe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function X_(t){return new Promise((e,r)=>{let i=nt("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 co=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let r=$n(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=We(o,f.relPath,"SKILL.md");await Kf(x).then(_=>_.isFile()).catch(()=>!1)&&(d.push(ny(f)),u.add(f.relPath))}if(e.scanLocal){let f=i?.framework??"claude-code",x=await Q_(r,o,f);for(let p of x)u.has(p.relPath)||(u.add(p.relPath),d.push(p.skill))}return{skills:d}}async addSkills(e){e._meta;let r=$n(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 lo({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});uo(c,d,x),u.push(f)}return await si(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let r=$n(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=We(i.workspace,u.relPath);await $c(f,{recursive:!0,force:!0}),fe.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await si(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let r=$n(e._meta);if(!e.skillName)throw new k("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");fe.info("_agent/publishSkill start",{agentId:r,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(r),o=i?.workspace??Ve(r).workspace,c=i?.framework??"claude-code",d=e0(e.skillName),u=We(Xc(c),d),f=We(o,u),x=We(f,"SKILL.md");if(!await Kf(x).then(T=>T.isFile()).catch(()=>!1))throw new k("SKILL_NOT_FOUND",`skill not found locally: ${e.skillName} (${u})`);let _=new Yc.default;_.addLocalFolder(f,d);let v=_.toBuffer();if(v.length>Zf)throw new k("SKILL_ZIP_TOO_LARGE",`skill zip ${v.length} bytes exceeds limit ${Zf}`);let w=await ao(x,{encoding:"utf8"}).then(T=>n0(T).description).catch(()=>{}),E={};this.opts.publishSkillToMarketplace?E=await this.opts.publishSkillToMarketplace({zip:v,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...w?{description:w}:{},agentId:r,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):fe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:r,skillName:e.skillName});let I=E.version??"v1.0",A=E.skillId??e.skillId??t0(r,u);if(i){let T=i.skills??[],D=T.find(y=>y.relPath===u);D?(D.version=I,D.skillId=A):T.push({skillId:A,skillName:e.skillName,relPath:u,version:I,installedAt:Date.now(),...w?{description:w}:{}}),await si(r,T)}return fe.info("skill published",{agentId:r,skillName:e.skillName,relPath:u,zipBytes:v.length,skillId:A,version:I}),{ok:!0,skillId:A,version:I}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,fe.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=c.downstream;c.downstream=void 0,fe.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(r).catch(x=>fe.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 fe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await ke(r);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return fe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await lr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw fe.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Me(i),fe.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await ke(r))throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Di(e.registry)&&o.push(`--registry=${e.registry}`);let c=Y_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&V_.test(d)&&o.push("--env",d);let u=await X_(o);return fe.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await ke(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Me(i),fe.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(fe.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async deleteAgent(e){let r=e.agentId;if(!r)throw new k("IPC_BAD_REQUEST",`${ft.DELETE}: missing agentId`);let i=await ke(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 $c(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Me(i)),fe.info("agent deleted",{agentId:r,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(kr(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Gc(e.model)??Et,i=await ke(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 Me(i),fe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return fe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(d=>fe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(d)}));let c=[];for(let[d,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let f=o.sessions.get(d);f?.downstream&&(await f.downstream.stop(`switchModel: ${r}`).catch(()=>{}),f.downstream=void 0)}));return await Promise.all(c),fe.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(kr(e._meta,ft.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${ft.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ft.RESET),await this.runDetailSync(e.agentId,ft.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),fe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await ii(e,o)}async clearPersistedAcpSessionIds(e){let r=await ke(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 Me(r)}async repairAgent(e){if(kr(e._meta,ft.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${ft.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${ft.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){fe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ft.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){fe.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){fe.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){kr(e._meta,"_agent/getFileTree");let r=e._meta,i=$n(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await jc(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 ri(d,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=xy(e.depth);return u.isDirectory()?{tree:await hy(o,d,c,f)}:{tree:[{name:py(c),path:s0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){kr(e._meta,"_agent/getFileContent");let r=$n(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 jc(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 ri(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Vf)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Vf})`);let d=await ao(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 ke(e).catch(()=>null))?.workspace??Ve(e).workspace}safeJoin(e,r){let i=Vc(e,r||"."),o=Jc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Yf}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return ke(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 e0(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 Xc(t){return t==="claude-code"?We(".claude","skills"):We(".agents","skills")}function t0(t,e){return(H_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function n0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
93
|
+
---`,3);if(e<0)return{};let r=t.slice(3,e),i={};for(let o of r.split(`
|
|
94
|
+
`)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function Q_(t,e,r){let i=Xc(r),o=We(e,i),c=await Jf(o,{withFileTypes:!0}).catch(()=>null);if(!c)return[];let d=[];for(let u of c){if(!u.isDirectory())continue;let f=u.name,x=We(i,f),p=We(o,f,"SKILL.md"),_=await ao(p,{encoding:"utf8"}).catch(()=>null);if(_===null)continue;let v=n0(_);d.push({relPath:x,skill:{skillId:t0(t,x),skillName:v.name||f,...v.description?{description:v.description}:{}}})}return d}var ey=3e4,ty=50*1024*1024,Zf=10*1024*1024,Cr=3e4;async function lo(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=e0(o.skillName),f=Xc(i),x=We(f,u),p=We(r,x);if(await Wc(p,{recursive:!0}),c){let v=Buffer.from(o.content,"utf8");Ni(v.length),await Kc(We(p,"SKILL.md"),v,"utf8")}else{let v=await iy(o.downloadUrl);oy(v)?await ly(v,p):ay(v)?await cy(v,p):await Kc(We(p,"SKILL.md"),v.toString("utf8"),"utf8")}let _={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return fe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),_}function uo(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function ny(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function ry(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function r0(t,e){let r=await ke(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 Me(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((p,_)=>[p.skillId,_])),u=c.filter(p=>p.builtin===!0&&!!p.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Me(r,e),{status:"noop",count:0};let f=0,x=0;for(let p of u)try{await $c(We(r.workspace,p.relPath),{recursive:!0,force:!0});let _=await lo({agentId:t,workspace:r.workspace,framework:r.framework,skill:ry(p)});uo(c,d,_),f+=1}catch(_){x+=1,fe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:p.skillId,skillName:p.skillName,err:String(_)})}return r.skills=c,x===0&&(r.skillsRefreshedForVersion=i),await Me(r,e),fe.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);Ni(e);let r=sy(t);return Ni(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await ao(e);return Ni(r.length),r}if(Di(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),ey);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new k("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ni(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 Ni(t){if(t>ty)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function sy(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 oy(t){return t.length>=2&&t[0]===31&&t[1]===139}function ay(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Zc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function cy(t,e){let r,i;try{r=new Yc.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||Zc(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=dy(i),c=Vc(e);for(let d of i){if(Zc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=Vc(e,u),x=Jc(c,f);if(x.startsWith("..")||x==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Wc(f,{recursive:!0});continue}await Wc(q_(f),{recursive:!0});let p;try{p=d.getData()}catch(_){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${_.message}`,{cause:_})}await Kc(f,p)}}function dy(t){let e;for(let r of t){let i=r.entryName;if(!i||Zc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function ly(t,e){await uy(t);let r=kf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Cr}ms)`))},Cr);try{await Qf(Xf.from(t),r)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Cr}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function uy(t){let e=[],r=Ar({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 (${Cr}ms)`))},Cr);try{await Qf(Xf.from(t),r)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Cr}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 fy=5e3;async function hy(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 Jf(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(K_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=fy){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=We(e,u.name),x=j_(We(r,u.name)),p=null;try{p=await jc(f)}catch{continue}if(p.isSymbolicLink())continue;o.count++;let _={name:u.name,path:s0(Jc(t,f)),isDir:p.isDirectory(),size:p.size,modifiedAt:Math.floor(p.mtimeMs)};p.isDirectory()&&i>1&&(_.children=await i0(t,f,x,i-1,o)),d.push(_)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function xy(t){return!t||t<=0?W_:Math.min(t,$_)}function py(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function s0(t){return t.split(Yf).join("/")}te();var vn=G("agent-health-reporter"),gy=1e4,my=3,Mi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??gy,this.livenessFailureThreshold=e.livenessFailureThreshold??my}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),vn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),vn.info("heartbeat stopped"))}async tick(){if(this.inFlight){vn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,vn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let u=wy(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),r.push(f)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Ot,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,vn.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(vn.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){vn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){vn.warn("onTickEnd hook failed",{err:String(r)})}}};function wy(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}cn();import{mkdir as id,rm as fb,stat as hb}from"node:fs/promises";import{homedir as xb}from"node:os";import{join as od}from"node:path";sn();import{existsSync as Py}from"node:fs";import{release as Dy}from"node:os";import{basename as Oy,isAbsolute as Ly}from"node:path";function Bi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Pr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Dr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Sn(t,e){return{jsonrpc:"2.0",id:t,error:e}}qe();var fo=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)}},J={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 o0(t){return"method"in t&&"id"in t&&t.id!==void 0}function a0(t){return"method"in t&&!("id"in t)}function ho(t){return!("method"in t)&&"id"in t}var _y={AGENT_NOT_FOUND:J.AGENT_NOT_FOUND,AGENT_BUSY:J.AGENT_BUSY,AGENT_DISCONNECTED:J.AGENT_DISCONNECTED,AGENT_TIMEOUT:J.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:J.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:J.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:J.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:J.INTERNAL_ERROR,BRIDGE_INTERNAL:J.INTERNAL_ERROR,IPC_AUTH_FAILED:J.INTERNAL_ERROR,IPC_BAD_REQUEST:J.INVALID_REQUEST,METHOD_NOT_FOUND:J.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:J.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:J.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:J.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:J.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:J.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:J.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:J.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:J.FILE_TOO_LARGE,UNSUPPORTED_MIME:J.UNSUPPORTED_MIME,UPLOAD_FAILED:J.UPLOAD_FAILED,UPSTREAM_NOT_READY:J.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:J.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:J.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:J.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:J.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:J.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:J.SKILL_ZIP_TOO_LARGE};function yy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Fi(t.message)}:typeof t=="string"?Fi(t):typeof t=="object"?Ey(t):t}var by=[[/\/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 Fi(t){let e=t;for(let[r,i]of by)e=e.replace(r,i);return e}function Ey(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Fi(i):e[r]=i;return e}function zi(t){if(t instanceof k){let e=yy(t.cause),r={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(r.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(r.reason=e.reason),{code:_y[t.code]??J.INTERNAL_ERROR,message:Fi(t.message),data:r}}return{code:J.INTERNAL_ERROR,message:Fi(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 l0(t){return`${JSON.stringify(t)}
|
|
95
|
+
`}var d0=10*1024*1024,xo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>d0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${d0} bytes`)}),[]}let r=this.buffer.split(`
|
|
96
|
+
`);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var f0={"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"},Ek=Object.fromEntries(Object.entries(f0).map(([t,e])=>[e,t])),vy={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Or=class{seq=0;next(e,r){this.seq+=1;let i=f0[e]??Sy(e),o=vy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(f=>u0(r?.[f]??"")),u=Iy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>u0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Sy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function u0(t){return t.replace(/[:_\s]+/g,"-")}function Iy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}an();import{readFileSync as Ay}from"node:fs";var ky=384;async function Qc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await dr(t.agentEnvFile,r,{mode:ky})}function ed(t){try{let e=JSON.parse(Ay(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function h0(t,e,r={},i=o=>o){return{...i({...t,...ed(e)}),...r}}Kt();ir();qe();te();De();import{execFileSync as Ty,spawnSync as Ry}from"node:child_process";function Ui(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Gi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Ry("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var td=new Set;function x0(t){typeof t=="number"&&t>0&&td.add(t)}function p0(t){typeof t=="number"&&td.delete(t)}function g0(){for(let t of td)Gi(t,"SIGKILL")}var Lr="coze-bridge-daemon";function m0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return Ty("pgrep",["-U",String(o),"-f",Lr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
|
|
97
|
+
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function w0(t,e){if(t.length===0)return;let r=e?.killFn??Gi,i=e?.isAliveFn??Ui,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Cy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @(zed-industries|agentclientprotocol)\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function _0(t,e){if(!e)return null;for(let r of Cy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function y0(t,e){return _0(t,e)}function b0(t,e){return _0(t,e)}function Nr(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 E0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,p=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Nr(p,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:Nr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Nr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Nr(c,!1,e)}}var v0=Ke("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Ny=200,My=40,By=Ke("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Fy=Ke("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),zy=Ke("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Uy=Ke("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Gy=Ke("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Hy=Ke("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),S0=500;function qy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=S0?t:`${e.slice(0,S0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function jy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function I0(t){try{return Py(t)}catch{return}}function Wy(t,e){return{platform:process.platform,osRelease:Dy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:Ly(e.command)?I0(e.command):void 0,cwd:e.cwd,cwdExists:I0(e.cwd),envKeys:e.envKeys}}function $y(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Oy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Lt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new xo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Or;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;spawnEnv={};sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=h0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o));this.spawnEnv=r;let i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,x0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>Ny&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,p0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=Wy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new k("AGENT_SPAWN_FAILED",$y(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()));Gi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Gi(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,r){let i={firstUpdateMs:Gy,phase2GateMs:By,livenessWindowMs:Fy,absoluteMaxMs:zy,approvalMaxMs:Hy,suspendThresholdMs:Uy,...r};return this.call("session/prompt",e,v0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Pr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Dr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Sn(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=v0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Bi(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 p={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let _=this.now(),v={cfg:o,startedAt:_,lastActivityAt:_,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:_,expectedIntervalMs:Nr(0,!1,o),sessionId:u};p.promptTimeout=v;let w=()=>{let E={startedAt:v.startedAt,lastActivityAt:v.lastActivityAt,firstFrameSeen:v.firstFrameSeen,hasActiveTool:v.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:v.suspendedMs,armedAt:v.armedAt,expectedIntervalMs:v.expectedIntervalMs},I=this.now(),A=E0(E,v.cfg,I),T=D=>{v.armedAt=I,v.expectedIntervalMs=D,p.timer=setTimeout(w,D)};if(A.action==="suspend"){v.suspendedMs+=A.suspendedDeltaMs,v.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:v.suspendedMs,...v.sessionId?{sessionId:v.sessionId}:{}}),T(A.rearmMs);return}if(A.action==="continue"){T(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...v.sessionId?{sessionId:v.sessionId}:{}}),x(A.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${v.cfg.approvalMaxMs}ms`):new k("AGENT_TIMEOUT",`${e} timed out after ${v.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...v.sessionId?{sessionId:v.sessionId}:{}}),x(new k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${v.cfg.livenessWindowMs}ms`)))};p.timer=setTimeout(w,v.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(p.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,p);try{this.writeFrame(d)}catch(_){p.timer&&clearTimeout(p.timer),this.pending.delete(c),x(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(l0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(ho(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new 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:qy(e.result)}),r.resolve(e.result));return}if(a0(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(o0(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(Sn(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(Sn(e.id,zi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=c0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=b0(this.framework,jy(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(My).join(`
|
|
98
|
+
`),o=y0(this.framework,i);return o?new k(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new k("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function Ky(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var po=class extends Lt{framework="claude-code";constructor(e){let{command:r,args:i}=ni("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return Ky(e)}};sn();import{mkdtempSync as Yy,rmSync as Xy}from"node:fs";import{tmpdir as Qy}from"node:os";import{join as eb}from"node:path";import{readFileSync as k0}from"node:fs";import{homedir as Vy}from"node:os";import{join as A0}from"node:path";function T0(t){let e=t.CODEX_HOME?.trim()||A0(t.HOME?.trim()||Vy(),".codex");return A0(e,"config.toml")}function Zy(t){let e=null;for(let r=0;r<t.length;r++){let i=t[r];if(e)i===e&&(e=null);else if(i==='"'||i==="'")e=i;else if(i==="#")return t.slice(0,r)}return t}function Jy(t){let e=t.trim();if(e.length>=2){let r=e[0];if((r==='"'||r==="'")&&e[e.length-1]===r)return e.slice(1,-1)}return e}function R0(t){let e={},r={},i=e;for(let o of t.split(/\r?\n/)){let c=Zy(o).trim();if(!c)continue;let d=/^\[([^\]]+)\]$/.exec(c);if(d){let x=(d[1]??"").trim(),p=r[x]??{};r[x]=p,i=p;continue}let u=c.indexOf("=");if(u<=0)continue;let f=c.slice(0,u).trim();f&&(i[f]=Jy(c.slice(u+1)))}return{root:e,tables:r}}function C0(t){let e=t.root.model_provider;if(!e||e==="openai")return null;let r=t.tables[`model_providers.${e}`];return r?{providerId:e,baseUrl:r.base_url,envKey:r.env_key,bearerToken:r.experimental_bearer_token}:null}function P0(t){let e;try{e=k0(T0(t),"utf8")}catch{return null}return C0(R0(e))?.providerId??null}function D0(t){let e;try{e=k0(T0(t),"utf8")}catch{return null}let r=C0(R0(e));if(!r?.baseUrl)return null;let i=r.bearerToken||(r.envKey?t[r.envKey]?.trim():void 0);return i?{baseUrl:r.baseUrl,providerName:r.providerId,headers:{Authorization:`Bearer ${i}`}}:null}var go=class t extends Lt{framework="codex";authRequest;resolveLocalGatewayAuth;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ni("codex",e.command,i),d=e.isolateCodexHome?Yy(eb(Qy(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authRequest=e.authRequest,this.resolveLocalGatewayAuth=e.resolveLocalGatewayAuth??!1,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e),i=this.authRequest??this.localGatewayAuthRequest();return i&&await this.call("authenticate",i),r}localGatewayAuthRequest(){if(!this.resolveLocalGatewayAuth)return null;let e=D0(this.spawnEnv);return e?(this.log.info("codex local: \u7528 config.toml custom provider \u8D70 gateway \u8BA4\u8BC1",{providerName:e.providerName,baseUrl:e.baseUrl}),{methodId:"gateway",_meta:{gateway:e}}):null}static MODE_ID_MAP={"read-only":"read-only",auto:"agent","full-access":"agent-full-access"};setSessionMode(e){let r=t.MODE_ID_MAP[e.modeId]??e.modeId;return super.setSessionMode({...e,modeId:r})}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Xy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};qe();var tb=3e4,Mr=class extends Lt{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}`}]},tb))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var O0=["default","acceptEdits","plan","auto","bypassPermissions"],L0=["read-only","auto","full-access"];function In(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return O0.includes(e);case"codex":return L0.includes(e);case"openclaw":return!1}}function nd(t){switch(t){case"claude-code":return O0.join("/");case"codex":return L0.join("/");case"openclaw":return""}}an();qe();te();De();function rd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}sn();var An=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 mo=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 An,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)Hi(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 Hi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Vt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Kt();te();import{constants as N0}from"node:fs";import{access as nb}from"node:fs/promises";import{delimiter as rb,join as ib}from"node:path";var vt=G("framework-detector"),M0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},sb=[".exe",".cmd",".bat",".ps1"],Kn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??nb}}async detect(e){let r=M0[e],i=await this.which(r);if(!i)return vt.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(M0).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(rb).filter(Boolean),i=this.env.platform==="win32"?["",...sb]:[""];for(let o of r)for(let c of i){let d=ib(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?N0.F_OK:N0.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 vt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return vt.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 vt.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 vt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(vt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(vt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return vt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return vt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||vt.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){vt.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&&(ab(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)}})}},ob=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function ab(t){return t.replace(ob,"")}import{homedir as cb}from"node:os";import{join as db}from"node:path";an();Kt();ir();qe();te();async function z0(){let t=db(cb(),".openclaw/openclaw.json");return(await cr(t))?.gateway?.auth?.token??""}var B0=G("openclaw.config"),lb=[0,5e3,5e3],ub=Ke("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),F0="models.providers.",wo="agents.defaults.models",_o=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new An;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??lb,this.cliTimeoutMs=e.cliTimeoutMs??ub}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,B0.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=nt(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){B0.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",`${F0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${F0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${wo}[${e}]`,()=>this.runCli(["config","set",wo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${wo}[${e}]`,`${wo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var de=G("agent-manager"),ad="bypassPermissions",H0="full-access",q0="full-access";function pb(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}var gb=(t,e,r,i,o,c,d,u,f,x)=>{switch(t){case"claude-code":{let p={...o?{...Hf(o),...Wf(o,d,u)}:{},...f??{},IS_SANDBOX:"1"};return new po({cwd:r,env:p,agentId:i})}case"codex":{let p=H0;x!==void 0&&(In("codex",x)?p=x:de.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let _=o?null:P0(process.env),v={...o?jf(o):{},INITIAL_AGENT_MODE:pb(p),...process.env.COZE_BRIDGE_CODEX_APP_SERVER_LOGS==="1"?{APP_SERVER_LOGS:od(r,"..","logs","codex-app-server")}:{},..._?{MODEL_PROVIDER:_}:{},...f??{}},w=o?qf(o,d,u):null,E=w?{methodId:"gateway",_meta:{gateway:w}}:void 0,I=!!o,A=!I&&process.env.COZE_BRIDGE_CODEX_LOCAL_GATEWAY_AUTH==="1";return new go({cwd:r,agentId:i,...Object.keys(v).length>0?{env:v}:{},...E?{authRequest:E}:{},...I?{isolateCodexHome:!0}:{},...A?{resolveLocalGatewayAuth:!0}:{}})}case"openclaw":return new Mr({command:e,cwd:r,agentId:i,...c?{sessionName:rd(c)}:{}})}};function sd(t){return t==="claude-code"||t==="codex"}function mb(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(wb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
97
99
|
`)}
|
|
98
|
-
`}function
|
|
99
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Qy={path:"",version:"cloud-deployed"},I0="openclaw_gateway_unavailable",e1="openclaw_default_agent_missing";function A0(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 t1={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},n1=6e4,_o=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Zy,this.createTimeoutMs=e.createTimeoutMs??n1,this.detectorFactory=e.detectorFactory??(()=>new Wn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new wo({command:r})),this.openclawConfigDir=e.openclawConfigDir??S0(Vy(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{ue.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=S0(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){ue.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=Yy({...process.env,...Xc(this.paths.agentEnvFile)});await sn(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 C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=await Be(e.agentId,this.paths).catch(()=>null),o=io(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")ue.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>ue.warn("dispose stale agent failed (ignored)",{err:String(R)})),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(R=>ue.warn("dispose drifted agent failed (ignored)",{err:String(R)})),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 R=await Be(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Qe(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){ue.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Be(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Qe(R,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 C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Xe(e.agentId,this.paths),x=o?"cloud":"local",p=e.framework==="openclaw"&&x==="local",w;p&&!r?.revive&&(w=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=w??(p?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),I=e.workspace??_??u.workspace,y=new AbortController,S=setTimeout(()=>y.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,T=!1;try{o&&rd(e.framework)&&await sr(e.framework,y.signal);let R=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await nd(u.root,{recursive:!0}),await nd(I,{recursive:!0}),await nd(u.logs,{recursive:!0}),R(),p||await cr(I,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ra(I,"cloud"):await Ra(I,"local",id)),R();let P=i,E=Nf({model:e.model??P?.model}),k=vf(e._meta)??P?.accountId,O=e.patToken??P?.patToken,F=x==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(A=new go({agentId:e.agentId,framework:e.framework,workspace:I,model:E.model??yt,deployType:x,...k?{accountId:k}:{},...O?{patToken:O}:{},...F?{modelInfo:F}:{}}),A.status="ok",P?.sessions){let $=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,se]of Object.entries(P.sessions)){let ae={acpSessionId:se.acpSessionId,modelToken:se.modelToken,tokenGeneratedAt:se.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?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:Z,framework:e.framework,fallback:ae.permissionMode})):Sn(e.framework,se.permissionMode)?ae.permissionMode=se.permissionMode:ue.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:se.permissionMode}):se.permissionMode!==void 0&&ue.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:x}),se.cozeGroupId&&(ae.cozeGroupId=se.cozeGroupId),A.sessions.set(Z,ae)}let ne=Object.keys(P.sessions).length;ne>0&&ue.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(A),T=!0;let B={agentId:e.agentId,framework:e.framework,workspace:I,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:E.model};x==="cloud"&&(B.deployType="cloud"),k&&(B.accountId=k),O&&(B.patToken=O),F&&(B.modelInfo=F),P?.skills&&(B.skills=P.skills),P?.agentName&&(B.agentName=P.agentName),P?.description&&(B.description=P.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,I)):ue.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let V=e.initialSkills??[];if(V.length>0){let $=[...B.skills??[]],ne=new Map($.map((ae,L)=>[ae.skillId,L])),Z=await Promise.allSettled(V.map(ae=>Jc({agentId:e.agentId,workspace:I,framework:e.framework,skill:ae}))),se=0;for(let[ae,L]of Z.entries()){let G=V[ae];G&&(L.status==="fulfilled"?(Zc($,ne,L.value),se++):ue.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:G.skillId,skillName:G.skillName,err:String(L.reason)}))}se>0&&(B.skills=$,ue.info("initialSkills installed",{agentId:e.agentId,installed:se,requested:V.length}))}return await Qe(B,this.paths),ue.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:I,framework:e.framework}}catch(R){throw ue.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),T&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(u.root,{recursive:!0,force:!0}).catch(P=>ue.warn("rm agent dir failed (ignored)",{err:String(P)})),R instanceof C?R:new C("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(S)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&rd(e.framework))u=Qy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);rd(e.framework)&&!ls(e.framework)&&(ue.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await sr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;if(e.framework==="openclaw")p=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let w=e.sessions.get(i),_=Kt(e)?w?.permissionMode??T0:"full-access";p=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),_)}try{return await p.start(),await p.initialize(t1),p}catch(w){let _=p instanceof Pt?p.getStderrTail():[];throw _.length>0&&ue.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof C?w.code:"unknown",recentStderr:_}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,w)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",A0(o),{cause:{reason:I0}})}catch(o){ue.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?i:new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};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 C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:e1}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",A0(r),{cause:{reason:I0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,x=td(o);if(r.deployType==="local"){let I=await this.ensureOpenclawDefaultAgent();return new Lr({command:u,cwd:I.workspace,agentId:I.id,sessionName:x})}let p=await v0(),w=i?qf(i,c,l):null,_;if(w){let I=Gc(o),S=w.models[0]?.id??yt,A=`${I}/${S}`;if(!this.ensuredProviders.has(A)){let T=this.getOpenclawConfig();await T.ensureProvider(I,w),await T.addModelToAllowlist(A),this.ensuredProviders.add(A)}_=A}return new Lr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...p?{gatewayToken:p}:{},..._?{slashModelOnStart:_}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Gc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,ue.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,ue.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as O0}from"node:crypto";import{promises as l1}from"node:fs";import{basename as L0}from"node:path";Ke();re();import{promises as i1}from"node:fs";import{basename as s1}from"node:path";var R0=q("file-upload"),o1="/api/coze_claw/file/agent_upload",a1=6e4;async function k0(t,e={}){let i=`${oo(co(e.handshakeBase))}${o1}`,o=e.timeoutMs??a1,c=await i1.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Ar(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);R0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let w=await fetch(i,{method:"POST",headers:u,body:l,signal:x.signal}),_=w.headers.get("x-tt-logid")??"";if(!w.ok){let S=await w.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${_}: ${S.slice(0,200)}`)}let I=await w.json();if(I.code!==void 0&&I.code!==0)throw new C("UPLOAD_FAILED",`upload code=${I.code} msg=${I.msg??"-"} logid=${_}`);let y=I.data?.file?.file_url;if(!y)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(I).slice(0,200)}`);return R0.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(w){throw w instanceof C?w:w.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${s1(t.path)}`):new C("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(p)}}Ke();re();import{extname as c1}from"node:path";var d1={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function D0(t){let e=c1(t).toLowerCase();return d1[e]??"application/octet-stream"}Le();var yo=q("agent-send"),P0=50*1024*1024;function N0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function M0(t,e,r,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){u=p,x<2&&(yo.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(w=>setTimeout(w,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function B0(t,e){let{session:r,runtime:i}=N0(e.core,t.agentId,t.sessionId);if(!await ti(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await l1.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>P0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${P0}`);let c=await D0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??L0(t.path),u;try{u=await k0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(p){throw yo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof C?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let x={sessionUpdate:"agent_file",messageId:O0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:l,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await M0(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),yo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function F0(t,e){let{session:r,runtime:i}=N0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??L0(t.path),c={sessionUpdate:"group_file",messageId:O0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await M0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),yo.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 z0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}rn();Wt();re();var Ot=q("coze-cli-installer"),U0="@coze/cli@latest",u1="coze",q0="0.1.8",f1=5e3,x1=5e3,h1=9e4,G0=1e4,Ui=null,Eo=!1;async function sd(t,e={}){if(Eo)return;if(Ui)return Ui;let r=e.exec??Cf;return Ui=(async()=>{try{let i=await p1(u1,r),o=!1;if(i){let l=await g1(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(z0(l,q0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:q0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),Eo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:U0,mode:c});try{await r("npm",["i","-g","--prefer-online",U0],{timeout:h1,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(l){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){Eo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:G0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Ot.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:G0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}Eo=!0}finally{Ui=null}})(),Ui}async function p1(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:f1});return Ta(i)}catch{return}}async function g1(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:x1});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}on();Le();var m1=10*6e4;function H0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?m1:e}function bo(t){return or(t??ee().configFile)}function qi(t,e){return ar(e??ee().configFile,t)}import{randomBytes as B1}from"node:crypto";nr();Ke();re();import{createReadStream as w1}from"node:fs";import{mkdir as _1,readFile as y1,realpath as E1,stat as b1,writeFile as v1}from"node:fs/promises";import{basename as S1,dirname as od,isAbsolute as I1,join as A1,relative as T1,resolve as j0,sep as C1}from"node:path";import{createInterface as R1}from"node:readline";var K0=q("fs-rpc"),Gi=We("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function $0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Gi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Gi} bytes`);let i=await J0(t.path,e);return await _1(od(i),{recursive:!0}),await v1(i,t.content,"utf8"),K0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function V0(t,e){let r=await J0(t.path,e),i=await b1(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Gi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Gi} bytes`);let c;if(o&&i.size>Gi)c=await k1(r,t.line??1,t.limit);else{let l=await y1(r,"utf8");if(o){let u=l.split(`
|
|
100
|
-
`),
|
|
101
|
-
`)}else c=
|
|
102
|
-
`)}async function J0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([W0(j0(e)),W0(j0(t))]),o=T1(r,i);if(D1(o,C1,I1(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function D1(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function W0(t){let e=[],r=t;for(;r!==od(r);)try{let i=await E1(r);return e.length?A1(i,...e.reverse()):i}catch{e.push(S1(r)),r=od(r)}return t}re();var Z0=q("prompt-multimodal"),Y0=10*1024*1024,P1=15e3,O1=6;async function X0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,l=t[c];l!==void 0&&(e[c]=await L1(l))}}let o=Array.from({length:Math.min(O1,t.length)},()=>i());return await Promise.all(o),e}function Q0(t){return t.some(e=>e.type==="image")}async function L1(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ri(e.uri))return t;try{let{buf:r,contentType:i}=await M1(e.uri),o=e.mimeType||N1(i)||"application/octet-stream";return Z0.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 Z0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function N1(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function M1(t){let e=new AbortController,r=setTimeout(()=>e.abort(),P1);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>Y0)throw new Error(`image too large: ${o.byteLength} bytes (max ${Y0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}an();Ke();re();var W=q("core"),F1=3e4,z1=/^(boe|ppe)_[A-Za-z0-9_-]+$/,U1="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",q1="\u5BA1\u6279\u5DF2\u8D85\u65F6",G1=3e4,vo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Dr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=H0(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),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(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),W.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(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,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),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){W.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(vn(o,{code:te.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>W.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:te.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){W.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:te.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(fo(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&&z1.test(i)?this.currentCozeEnv=i:i&&W.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,te.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):W.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(kr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(kr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(kr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,te.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):W.warn("drop unknown notification",{method:e.method})}catch(o){W.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(vn(r,Mi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new C("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new C("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let x=o.sessions.get(c);if(x?.pendingPermission){let p=r._meta?.cozeTriggerMsgId,w=so(r._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,U1,p,w)}}let l=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,x}finally{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=If(i);switch(r){case"session/new":{let c=H1();return W.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return W.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Kt(e)?Sf(i._meta):void 0;if(u!==void 0&&!Sn(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${ed(e.framework)}`);let x=await this.ensureRuntime(e,l);if(u!==void 0&&x.permissionMode===void 0&&(x.permissionMode=u,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,l,x),!x.downstream||!x.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let I=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(y){throw x.permissionMode=I,await this.persistSessionMapping(e).catch(()=>{}),y}}let p=i._meta?.cozeTriggerMsgId;p?e.activeTriggers.set(x.acpSessionId,p):e.activeTriggers.delete(x.acpSessionId);let w=so(i._meta);if(w?e.activeGroupIds.set(x.acpSessionId,w):e.activeGroupIds.delete(x.acpSessionId),w&&x.cozeGroupId!==w&&(x.cozeGroupId=w,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Q0(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await X0(c.prompt);try{let I=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:_});return x.lastActiveAt=Date.now(),I}catch(I){if(I instanceof C&&I.code==="AGENT_APPROVAL_TIMEOUT"){let y=x.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),x.pendingPermission=void 0);let S=x.acpSessionId,A=S?e.activeTriggers.get(S):void 0,T=S?e.activeGroupIds.get(S):void 0;return W.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,x,l,q1,A,T)}throw I}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let I=x.downstream;I&&(x.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:x.acpSessionId}),I.stop("reload-after-turn").catch(y=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(y)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,l,x)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let x=e.getSessionQueue(l);x.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:x.size}),x.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,x=so(i._meta);if(!l)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Kt(e))throw e.framework==="openclaw"?new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new C("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Sn(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${ed(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,u);let p=e.sessions.get(l)??await this.ensureRuntime(e,l);if(p.permissionMode===u)return{};let w=p.permissionMode;if(p.permissionMode=u,await this.persistSessionMapping(e),p.downstream?.isAlive()&&p.acpSessionId)try{await p.downstream.setSessionMode({sessionId:p.acpSessionId,modeId:u})}catch(_){throw p.permissionMode=w,await this.persistSessionMapping(e).catch(()=>{}),_}else W.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:l,modeId:u});return{}}default:throw new C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:l,runtime:u,oldMode:u.permissionMode});if(o.length===0)return W.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};W.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let l of o)l.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let l of o){let u=l.runtime.downstream,x=l.runtime.acpSessionId;u?.isAlive()&&x&&c.push({downstream:u,acpSessionId:x,oldMode:l.oldMode,runtime:l.runtime})}for(let l of c)try{await l.downstream.setSessionMode({sessionId:l.acpSessionId,modeId:i})}catch(u){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Kt(e)&&(c.permissionMode=e.framework==="claude-code"?id:C0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(_t.GEN_MODEL_TOKEN,i,G1);if(!o?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof C&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new C("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(zi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let x;try{x=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=x,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await x.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let w=await x.sessionNew({cwd:e.workspace});i.acpSessionId=w.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let p=await x.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}}catch(p){throw W.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),await x.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,p}if(x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId),Kt(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(p){W.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:r,mode:i.permissionMode,err:String(p)})}}armIdleTimer(e,r,i){if(zi(i),this.isRuntimeBusy(e,i)){W.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)){W.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}W.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=>W.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let l=e.activeTriggers.get(r.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Rr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Rr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>W.warn("synthesizePromptReply update send failed (ignored)",{err:String(x)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){W.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){W.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(K1(r)){W.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=r.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&Kt(e)){let w=l.currentModeId;Sn(e.framework,w)&&c.permissionMode!==w?(c.permissionMode=w,this.persistSessionMapping(e).catch(_=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof w=="string"&&!Sn(e.framework,w)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:w})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(u.cozeTriggerMsgId=x);let p=e.activeGroupIds.get(i);p&&(u.cozeGroupId=p),this.upstream.send(Rr("session/update",{...r,sessionId:o,_meta:u})).catch(w=>W.warn("forward update failed",{agentId:e.agentId,err:String(w)}))}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}W.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:te.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await $0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await V0(c,o);r.respondAgentRequest(i.id,l)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Mi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,p={cozeAgentId:e.agentId};x&&(p.cozeTriggerMsgId=x);let w=u?e.activeGroupIds.get(u):void 0;w&&(p.cozeGroupId=w);let _=u?this.reverseSessionId(e,u):void 0,I=_?e.sessions.get(_):void 0;I&&(I.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,..._?{sessionId:_}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(S=>({optionId:S.optionId,kind:S.kind,name:S.name}))}),this.upstream.send(Li(o,"session/request_permission",y)).catch(S=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(S)}),r.respondAgentRequestError(i.id,{code:te.INTERNAL_ERROR,message:`upstream send failed: ${String(S)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(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"&&j1(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 uo(e.error)):i.value.resolve(e.result);return}W.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),l=e.get(c);if(l)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=F1){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(Li(o,e,r)).catch(x=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),l(x)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Kt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ni(e.agentId,r,this.paths)}catch(r){W.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(vn(e,{code:r,message:i,data:{bridgeVersion:Cr}}))}};function H1(){return B1(16).toString("hex")}function j1(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){W.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"){W.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")&&W.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var W1=["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 K1(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 W1.some(c=>o.startsWith(c))}on();re();Le();import{randomBytes as $1}from"node:crypto";import{createServer as V1}from"node:http";var J1=1e6,ex=q("ipc"),So=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??ee()}async start(){this.token=$1(32).toString("hex");let e=V1((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(),ex.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await sn(this.paths.portFile,String(this.port)),await sn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Hi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Hi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await Z1(e)}catch(u){Hi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Hi(r,200,u??{ok:!0})}catch(u){ex.error("IPC handler failed",{key:o,err:String(u)}),Hi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Hi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function Z1(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>J1)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 mb=Ft(Zx(),1),wb=Ft(Oo(),1),_b=Ft(Br(),1),yb=Ft(md(),1),Eb=Ft(yd(),1),bb=Ft(Ad(),1),sh=Ft(Bo(),1),vb=Ft(ih(),1);var oh=sh.default;Ke();re();var{FWS:zb}=mh(),Pe=q("upstream.frontier"),_h="application/json",yh="none",Ub=15e3;function qb(t){class e extends oh{constructor(i){super(i,kf,{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(hl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Pe.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Pe.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Xi=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:Df,...Ar(this.opts.ppeOverride)},r=qb(e),i=Of(this.opts.urlOverride),o={url:i,ws:r,fpID:Rf,aID:ao,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:_h,force:!0},payloadEncoding:{encoding:yh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new zb(o),l=!1,u=null,x,p,w=new Promise((y,S)=>{x=y,p=S}),_=y=>{l||(l=!0,u&&(clearTimeout(u),u=null),y?p(y):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Pe.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&_();for(let S of this.connectHandlers)Promise.resolve(S({initial:y})).catch(A=>Pe.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=y=>{this.opened=!1,Pe.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Pe.warn("frontier error",{code:y.code,msg:y.message}),_(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let I=this.opts.openTimeoutMs??Ub;u=setTimeout(()=>{_(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${I}ms (handshake or upgrade slow)`))},I),await c.connect();try{await w}catch(y){try{c.close(1e3,"open failed")}catch(S){Pe.warn("fws close during start failure threw (ignored)",{err:String(S)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Pe.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Pe.warn("frontier send refused: upstream not started",{method:i}),new C("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Pe.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new C("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Eh(c)||Pe.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:_h,payloadEncoding:yh})}catch(u){throw Pe.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Pe.debug("drop non-adapter frontier frame",{service:r});return}let i=jb(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(l){Pe.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;Eh(c)||Pe.info("frontier frame in",{logid:Hb(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Gb(i)}),Promise.resolve(this.handler(o)).catch(l=>Pe.warn("frontier frame handler threw",{err:String(l)}))}};function Eh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var bh=2e3;function Gb(t){return t.length<=bh?t:`${t.slice(0,bh)}...<truncated, total ${t.length} chars>`}function Hb(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function jb(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}re();var kd=q("upstream.switchable"),Ko=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;kd.info("swap upstream",{reason:r});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw kd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>kd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};re();var Dd=q("upstream"),Hr=class{handler=null;async start(){Dd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Dd.info("NoopUpstream stopped",{reason:e})}async send(e){Dd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();re();on();re();Le();import{promises as Wb}from"node:fs";var vh=q("pat-token-store");async function $o(t=ee()){try{let r=(await Wb.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(vh.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"&&vh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Qi(t,e=ee()){if(!t)throw new Error("writePatToken: empty patToken");await sn(e.patTokenFile,t,{mode:384})}Le();Le();import{promises as Vo}from"node:fs";import{join as Kb}from"node:path";function $b(t,e){return`#!/bin/sh
|
|
100
|
+
`}function wb(t){if(t.includes(`
|
|
101
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var _b={path:"",version:"cloud-deployed"},U0="openclaw_gateway_unavailable",yb="openclaw_default_agent_missing";function G0(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 bb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Eb=6e4,yo=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??gb,this.createTimeoutMs=e.createTimeoutMs??Eb,this.detectorFactory=e.detectorFactory??(()=>new Kn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new _o({command:r})),this.openclawConfigDir=e.openclawConfigDir??od(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=>{de.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=od(e,".env");if(await hb(r).then(c=>c.isFile()).catch(()=>!1)){de.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=mb({...process.env,...ed(this.paths.agentEnvFile)});await on(r,o,{mode:384}),de.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),de.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new k("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new k("IPC_BAD_REQUEST","framework required");let i=await ke(e.agentId,this.paths).catch(()=>null),o=io(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")de.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(T=>de.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")de.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(T=>de.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){de.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let T=await ke(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Me(T,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){de.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let T=await ke(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Me(T,this.paths))}return de.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new 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",p;x&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=p??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),v=e.workspace??_??u.workspace,w=new AbortController,E=setTimeout(()=>w.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&sd(e.framework)&&await ar(e.framework,w.signal);let T=()=>{if(w.signal.aborted)throw w.signal.reason instanceof Error?w.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await id(u.root,{recursive:!0}),await id(v,{recursive:!0}),await id(u.logs,{recursive:!0}),T(),x||await lr(v,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Ca(v,"cloud"):await Ca(v,"local",ad)),T();let D=i,y=Gf({model:e.model??D?.model}),C=Rf(e._meta)??D?.accountId,O=e.patToken??D?.patToken,M=f==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(I=new mo({agentId:e.agentId,framework:e.framework,workspace:v,model:y.model??Et,deployType:f,...C?{accountId:C}:{},...O?{patToken:O}:{},...M?{modelInfo:M}:{}}),I.status="ok",D?.sessions){let K=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Y,ie]of Object.entries(D.sessions)){let se={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};K?ie.permissionMode===void 0?(se.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",de.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Y,framework:e.framework,fallback:se.permissionMode})):In(e.framework,ie.permissionMode)?se.permissionMode=ie.permissionMode:de.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Y,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&de.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Y,framework:e.framework,deployType:f}),ie.cozeGroupId&&(se.cozeGroupId=ie.cozeGroupId),I.sessions.set(Y,se)}let ne=Object.keys(D.sessions).length;ne>0&&de.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(I),A=!0;let N={agentId:e.agentId,framework:e.framework,workspace:v,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:y.model};f==="cloud"&&(N.deployType="cloud"),C&&(N.accountId=C),O&&(N.patToken=O),M&&(N.modelInfo=M),D?.skills&&(N.skills=D.skills),D?.agentName&&(N.agentName=D.agentName),D?.description&&(N.description=D.description),N.skillsRefreshedForVersion=D?.skillsRefreshedForVersion??Ot,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,v)):de.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Z=e.initialSkills??[];if(Z.length>0){let K=[...N.skills??[]],ne=new Map(K.map((se,P)=>[se.skillId,P])),Y=await Promise.allSettled(Z.map(se=>lo({agentId:e.agentId,workspace:v,framework:e.framework,skill:se}))),ie=0;for(let[se,P]of Y.entries()){let U=Z[se];U&&(P.status==="fulfilled"?(uo(K,ne,P.value),ie++):de.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(P.reason)}))}ie>0&&(N.skills=K,de.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Z.length}))}return await Me(N,this.paths),de.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:v,framework:e.framework}}catch(T){throw de.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 fb(u.root,{recursive:!0,force:!0}).catch(D=>de.warn("rm agent dir failed (ignored)",{err:String(D)})),T instanceof k?T:new k("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(E)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&sd(e.framework))u=_b;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);sd(e.framework)&&!us(e.framework)&&(de.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await ar(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let p=e.sessions.get(i),_=Vt(e)?p?.permissionMode??H0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv(),_)}try{return await x.start(),await x.initialize(bb),x}catch(p){let _=x instanceof Lt?x.getStderrTail():[];throw _.length>0&&de.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:p instanceof k?p.code:"unknown",recentStderr:_}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,p)}}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",G0(o),{cause:{reason:U0}})}catch(o){de.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};de.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return de.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new 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:yb}})}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",G0(r),{cause:{reason:U0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,f=rd(o);if(r.deployType==="local"){let v=await this.ensureOpenclawDefaultAgent();return new Mr({command:u,cwd:v.workspace,agentId:v.id,sessionName:f})}let x=await z0(),p=i?$f(i,c,d):null,_;if(p){let v=qc(o),E=p.models[0]?.id??Et,I=`${v}/${E}`;if(!this.ensuredProviders.has(I)){let A=this.getOpenclawConfig();await A.ensureProvider(v,p),await A.addModelToAllowlist(I),this.ensuredProviders.add(I)}_=I}return new Mr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:f,...x?{gatewayToken:x}:{},..._?{slashModelOnStart:_}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=qc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(u){d=!1,de.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){d=!1,de.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as V0}from"node:crypto";import{promises as Rb}from"node:fs";import{basename as Z0}from"node:path";qe();te();import{promises as vb}from"node:fs";import{basename as Sb}from"node:path";var j0=G("file-upload"),Ib="/api/coze_claw/file/agent_upload",Ab=6e4;async function W0(t,e={}){let i=`${Tr(Rr(e.handshakeBase))}${Ib}`,o=e.timeoutMs??Ab,c=await vb.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);j0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let p=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),_=p.headers.get("x-tt-logid")??"";if(!p.ok){let E=await p.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${p.status} logid=${_}: ${E.slice(0,200)}`)}let v=await p.json();if(v.code!==void 0&&v.code!==0)throw new k("UPLOAD_FAILED",`upload code=${v.code} msg=${v.msg??"-"} logid=${_}`);let w=v.data?.file?.file_url;if(!w)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(v).slice(0,200)}`);return j0.info("file upload ok",{uri:w,logid:_}),{uri:w}}catch(p){throw p instanceof k?p:p.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Sb(t.path)}`):new k("UPLOAD_FAILED",String(p),{cause:p})}finally{clearTimeout(x)}}qe();te();import{extname as kb}from"node:path";var Tb={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function $0(t){let e=kb(t).toLowerCase();return Tb[e]??"application/octet-stream"}De();var bo=G("agent-send"),K0=50*1024*1024;function J0(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 Y0(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&&(bo.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(p=>setTimeout(p,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function X0(t,e){let{session:r,runtime:i}=J0(e.core,t.agentId,t.sessionId);if(!await ri(t.path,r.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Rb.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>K0)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${K0}`);let c=await $0(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??Z0(t.path),u;try{u=await W0({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 bo.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:V0(),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 Y0(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),bo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function Q0(t,e){let{session:r,runtime:i}=J0(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??Z0(t.path),c={sessionUpdate:"group_file",messageId:V0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await Y0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),bo.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function eh(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}sn();Kt();te();var Nt=G("coze-cli-installer"),th="@coze/cli@latest",Cb="coze",nh="0.1.8",Pb=5e3,Db=5e3,Ob=9e4,rh=1e4,qi=null,Eo=!1;async function dd(t,e={}){if(Eo)return;if(qi)return qi;let r=e.exec??Lf;return qi=(async()=>{try{let i=await Lb(Cb,r),o=!1;if(i){let d=await Nb(r);if(d===void 0)Nt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(eh(d,nh))Nt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:nh}),o=!0;else{Nt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),Eo=!0;return}}let c=o?"upgrade-only":"full";Nt.info("coze-cli install start",{package:th,mode:c});try{await r("npm",["i","-g","--prefer-online",th],{timeout:Ob,maxBuffer:10*1024*1024}),Nt.info("coze-cli install ok")}catch(d){Nt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){Eo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:rh}),Nt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Nt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:rh}),Nt.info("coze auth login ok")}catch(d){Nt.warn("coze auth login failed",{err:String(d)});return}Eo=!0}finally{qi=null}})(),qi}async function Lb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Pb});return Ta(i)}catch{return}}async function Nb(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Db});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}an();De();var Mb=10*6e4;function ih(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Mb:e}function vo(t){return cr(t??Q().configFile)}function ji(t,e){return dr(e??Q().configFile,t)}import{randomBytes as nE}from"node:crypto";ir();qe();te();import{createReadStream as Bb}from"node:fs";import{mkdir as Fb,readFile as zb,realpath as Ub,stat as Gb,writeFile as Hb}from"node:fs/promises";import{basename as qb,dirname as ld,isAbsolute as jb,join as Wb,relative as $b,resolve as sh,sep as Kb}from"node:path";import{createInterface as Vb}from"node:readline";var ah=G("fs-rpc"),Wi=Ke("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function ch(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Wi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Wi} bytes`);let i=await lh(t.path,e);return await Fb(ld(i),{recursive:!0}),await Hb(i,t.content,"utf8"),ah.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function dh(t,e){let r=await lh(t.path,e),i=await Gb(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Wi&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Wi} bytes`);let c;if(o&&i.size>Wi)c=await Zb(r,t.line??1,t.limit);else{let d=await zb(r,"utf8");if(o){let u=d.split(`
|
|
102
|
+
`),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;c=u.slice(f,x).join(`
|
|
103
|
+
`)}else c=d}return ah.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Zb(t,e,r){let i=Vb({input:Bb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let f of i)if(u>=o&&u<c&&d.push(f),u++,u>=c)break}finally{i.close()}return d.join(`
|
|
104
|
+
`)}async function lh(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([oh(sh(e)),oh(sh(t))]),o=$b(r,i);if(Jb(o,Kb,jb(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Jb(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function oh(t){let e=[],r=t;for(;r!==ld(r);)try{let i=await Ub(r);return e.length?Wb(i,...e.reverse()):i}catch{e.push(qb(r)),r=ld(r)}return t}te();var uh=G("prompt-multimodal"),fh=10*1024*1024,Yb=15e3,Xb=6;async function hh(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 Qb(d))}}let o=Array.from({length:Math.min(Xb,t.length)},()=>i());return await Promise.all(o),e}function xh(t){return t.some(e=>e.type==="image")}async function Qb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Di(e.uri))return t;try{let{buf:r,contentType:i}=await tE(e.uri),o=e.mimeType||eE(i)||"application/octet-stream";return uh.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 uh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function eE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function tE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Yb);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>fh)throw new Error(`image too large: ${o.byteLength} bytes (max ${fh})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}cn();qe();te();var W=G("core"),rE=3e4,iE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,sE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",oE="\u5BA1\u6279\u5DF2\u8D85\u65F6",aE=3e4,So=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Or;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=ih(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),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(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),W.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(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,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)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Hi(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){W.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(Sn(o,{code:J.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>W.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:J.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){W.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:J.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(ho(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&iE.test(i)?this.currentCozeEnv=i:i&&W.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,J.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):W.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Dr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Dr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Dr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,J.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):W.warn("drop unknown notification",{method:e.method})}catch(o){W.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(Sn(r,zi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new k("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new k("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new k("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,p=so(r._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,sE,x,p)}}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{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Pf(i);switch(r){case"session/new":{let c=cE();return W.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return W.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=Vt(e)?Cf(i._meta):void 0;if(u!==void 0&&!In(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${nd(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 v=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(w){throw f.permissionMode=v,await this.persistSessionMapping(e).catch(()=>{}),w}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(f.acpSessionId,x):e.activeTriggers.delete(f.acpSessionId);let p=so(i._meta);if(p?e.activeGroupIds.set(f.acpSessionId,p):e.activeGroupIds.delete(f.acpSessionId),p&&f.cozeGroupId!==p&&(f.cozeGroupId=p,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&xh(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await hh(c.prompt);try{let v=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:_});return f.lastActiveAt=Date.now(),v}catch(v){if(v instanceof k&&v.code==="AGENT_APPROVAL_TIMEOUT"){let w=f.pendingPermission;w&&(w.downstream.respondAgentRequest(w.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(w.upstreamId),f.pendingPermission=void 0);let E=f.acpSessionId,I=E?e.activeTriggers.get(E):void 0,A=E?e.activeGroupIds.get(E):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,f,d,oE,I,A)}throw v}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let v=f.downstream;v&&(f.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),v.stop("reload-after-turn").catch(w=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(w)})))}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&&(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 c=o,d=c.sessionId,u=c.modeId,f=so(i._meta);if(!d)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Vt(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(!In(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${nd(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 p=x.permissionMode;if(x.permissionMode=u,await this.persistSessionMapping(e),x.downstream?.isAlive()&&x.acpSessionId)try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(_){throw x.permissionMode=p,await this.persistSessionMapping(e).catch(()=>{}),_}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: ${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 W.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};W.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 Vt(e)&&(c.permissionMode=e.framework==="claude-code"?ad:q0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(ft.GEN_MODEL_TOKEN,i,aE);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(Hi(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{f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.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}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let p=await f.sessionNew({cwd:e.workspace});i.acpSessionId=p.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: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),Vt(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:r,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,r,i){if(Hi(i),this.isRuntimeBusy(e,i)){W.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)){W.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}W.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=>W.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(Pr("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(Pr("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,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){W.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){W.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(uE(r)){W.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"&&Vt(e)){let p=d.currentModeId;In(e.framework,p)&&c.permissionMode!==p?(c.permissionMode=p,this.persistSessionMapping(e).catch(_=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof p=="string"&&!In(e.framework,p)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:p})}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(Pr("session/update",{...r,sessionId:o,_meta:u})).catch(p=>W.warn("forward update failed",{agentId:e.agentId,err:String(p)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}W.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:J.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 ch(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await dh(c,o);r.respondAgentRequest(i.id,d)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,zi(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 p=u?e.activeGroupIds.get(u):void 0;p&&(x.cozeGroupId=p);let _=u?this.reverseSessionId(e,u):void 0,v=_?e.sessions.get(_):void 0;v&&(v.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let w={...c,..._?{sessionId:_}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(E=>({optionId:E.optionId,kind:E.kind,name:E.name}))}),this.upstream.send(Bi(o,"session/request_permission",w)).catch(E=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(E)}),r.respondAgentRequestError(i.id,{code:J.INTERNAL_ERROR,message:`upstream send failed: ${String(E)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(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"&&dE(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 fo(e.error)):i.value.resolve(e.result);return}W.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 W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=rE){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(Bi(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&&Vt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ii(e.agentId,r,this.paths)}catch(r){W.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(Sn(e,{code:r,message:i,data:{bridgeVersion:Ot}}))}};function cE(){return nE(16).toString("hex")}function dE(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){W.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"){W.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")&&W.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var lE=["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 uE(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 lE.some(c=>o.startsWith(c))}an();te();De();import{randomBytes as fE}from"node:crypto";import{createServer as hE}from"node:http";var xE=1e6,ph=G("ipc"),Io=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Q()}async start(){this.token=fE(32).toString("hex");let e=hE((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(),ph.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 on(this.paths.portFile,String(this.port)),await on(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){$i(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){$i(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await pE(e)}catch(u){$i(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);$i(r,200,u??{ok:!0})}catch(u){ph.error("IPC handler failed",{key:o,err:String(u)}),$i(r,500,{error:u instanceof Error?u.message:String(u)})}}};function $i(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function pE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>xE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var Mv=Ut(lx(),1),Bv=Ut(Lo(),1),Fv=Ut(zr(),1),zv=Ut(bd(),1),Uv=Ut(Sd(),1),Gv=Ut(Cd(),1),yx=Ut(Fo(),1),Hv=Ut(_x(),1);var bx=yx.default;qe();te();var{FWS:iS}=Dx(),Ce=G("upstream.frontier"),Lx="application/json",Nx="none",sS=15e3;function oS(t){class e extends bx{constructor(i){super(i,Mf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Ce.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(yl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Ce.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Ce.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var ts=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Ce.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Bf,...En(this.opts.ppeOverride)},r=oS(e),i=zf(this.opts.urlOverride),o={url:i,ws:r,fpID:Nf,aID:oo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Lx,force:!0},payloadEncoding:{encoding:Nx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new iS(o),d=!1,u=null,f,x,p=new Promise((w,E)=>{f=w,x=E}),_=w=>{d||(d=!0,u&&(clearTimeout(u),u=null),w?x(w):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let w=this.openCount===1;Ce.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:w,openCount:this.openCount}),w&&_();for(let E of this.connectHandlers)Promise.resolve(E({initial:w})).catch(I=>Ce.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=w=>{this.opened=!1,Ce.info("frontier closed",{code:w.code,reason:w.reason,willReconnect:w.willReconnect})},c.onerror=w=>{Ce.warn("frontier error",{code:w.code,msg:w.message}),_(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${w.code} msg=${w.message??""}`))},c.onmessage=w=>this.handleMessage(w),this.fws=c;let v=this.opts.openTimeoutMs??sS;u=setTimeout(()=>{_(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${v}ms (handshake or upgrade slow)`))},v),await c.connect();try{await p}catch(w){try{c.close(1e3,"open failed")}catch(E){Ce.warn("fws close during start failure threw (ignored)",{err:String(E)})}throw this.fws=null,this.opened=!1,w}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Ce.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Ce.warn("frontier send refused: upstream not started",{method:i}),new k("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Ce.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=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;Mx(c)||Ce.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Lx,payloadEncoding:Nx})}catch(u){throw Ce.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){Ce.debug("drop non-adapter frontier frame",{service:r});return}let i=dS(e);if(!i){Ce.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Ce.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Ce.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Mx(c)||Ce.info("frontier frame in",{logid:cS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:aS(i)}),Promise.resolve(this.handler(o)).catch(d=>Ce.warn("frontier frame handler threw",{err:String(d)}))}};function Mx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Bx=2e3;function aS(t){return t.length<=Bx?t:`${t.slice(0,Bx)}...<truncated, total ${t.length} chars>`}function cS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function dS(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}qe();te();var Ld=G("skill-publish"),lS="/api/marketplace/product/skill/publish_with_assets",uS=15e4;async function Fx(t,e={}){let i=`${Tr(Rr(e.handshakeBase))}${lS}`,o=e.timeoutMs??uS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,f=setTimeout(()=>u.abort(),o);Ld.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}),p=x.headers.get("x-tt-logid")??"";if(!x.ok){let w=await x.text().catch(()=>"");throw new k("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${p}: ${w.slice(0,200)}`)}let _=await x.json();if(Ld.info("skill publish response",{logid:p,httpStatus:x.status,code:_.code,msg:_.msg,dataSkillId:_.data?.skill_id??"",dataVersion:_.data?.version??""}),_.code!==void 0&&_.code!==0)throw new k("UPLOAD_FAILED",`skill publish code=${_.code} msg=${_.msg??"-"} logid=${p}`);let v={};return _.data?.skill_id!==void 0&&_.data.skill_id!==""&&(v.skillId=String(_.data.skill_id)),_.data?.version&&(v.version=_.data.version),Ld.info("skill publish ok",{logid:p,skillId:v.skillId??"",version:v.version??""}),v}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)}}te();var Nd=G("upstream.switchable"),Ko=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Nd.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 Nd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Nd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};te();var Md=G("upstream"),Wr=class{handler=null;async start(){Md.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Md.info("NoopUpstream stopped",{reason:e})}async send(e){Md.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};qe();te();an();te();De();import{promises as fS}from"node:fs";var zx=G("pat-token-store");async function Vo(t=Q()){try{let r=(await fS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(zx.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):r}catch(e){let r=e?.code;return r!=="ENOENT"&&zx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function ns(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await on(e.patTokenFile,t,{mode:384})}De();De();import{promises as Zo}from"node:fs";import{join as hS}from"node:path";function xS(t,e){return`#!/bin/sh
|
|
103
105
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
104
|
-
`}function
|
|
106
|
+
`}function pS(t,e){return`@echo off\r
|
|
105
107
|
"${e}" "${t}" %*\r
|
|
106
|
-
`}async function
|
|
108
|
+
`}async function Ux(t,e=Q()){let r=e.binDir;await Zo.mkdir(r,{recursive:!0});let i=hS(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?pS(t,o):xS(t,o);return await Zo.readFile(i,"utf8").catch(()=>null)===c||(await Zo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Zo.chmod(i,493)),r}te();De();import{execSync as Gx}from"node:child_process";import{readFileSync as Hx,unlinkSync as gS}from"node:fs";import{mkdir as mS,open as wS,readFile as qx,unlink as Bd,writeFile as _S}from"node:fs/promises";import{dirname as yS}from"node:path";var bS=G("single-instance"),ES=t=>new Promise(e=>setTimeout(e,t)),Jo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Ui(r),isDaemon:r=>this.matchesDaemonTitle(r)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let r=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&bS.warn("removing stale pid file",{stalePid:i}),await _S(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return r.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),r}async release(){if(this.acquired){try{(await qx(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Bd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await qx(e,"utf8"),i=Number.parseInt(r.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(r){if(r.code==="ENOENT")return null;throw r}}async withClaimLock(e){let r=`${this.pidFile}.lock`;await mS(yS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await wS(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let d=await this.readPidFrom(r);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await ES(this.claimLockIntervalMs);continue}await Bd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Bd(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=Hx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Lr)||r.includes("lib/index.js"))}catch{}try{let r=Gx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Lr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Gx(`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{Hx(this.pidFile,"utf8").trim()===String(this.selfPid)&&gS(this.pidFile)}catch{}})}};Yo();te();var Qn=G("daemon.upstream-watchdog"),CS=12e4,PS=9e5,DS=3e4;function zd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Xo=class{constructor(e){this.opts=e;this.softMs=e.softMs??zd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",CS),this.hardMs=e.hardMs??zd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",PS),this.intervalMs=e.intervalMs??zd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",DS),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?.(),Qn.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&&Qn.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&&Qn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Qn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Qn.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,Qn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Qn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var H=G("daemon");async function $x(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){wl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:P=>Ve(P,t).logs,listAgentIds:()=>fs(t)});try{let{writeFileSync:P}=await import("node:fs");P(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
|
|
107
109
|
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
108
110
|
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
109
|
-
`)}catch{}}let e=new Jo({processTitle:Pr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await bo(),o=i??{};ds({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new Ko(new Hr),l=null,u=new vo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(L,G,K,oe)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(L,G,K,oe)}}),x=new _o({paths:t,config:o,registry:u});l=x;let p,w,_=null,I={},y,S=null,A=null,T=null,R=new In;function P(L,G){return R.enqueue(()=>k(L,G))}function E(){A||(A=new Yo({isConnected:()=>c.isConnected(),forceReconnect:()=>T?P(T,{force:!0}):void 0,onFatal:L=>{if(process.env[es]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:L});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:L}),process.exit(1)}})),A.start()}async function k(L,G){let K=L,oe=K?.privatecode;if(!oe)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Ze=Di(K.env),he=K.handshake_url,pe=K.frontier_url,vt=Rh(K.env,he,pe);if(T=K,!G?.force&&p===oe&&w===vt){let _e=await fv(t);return u.agents.size===0&&_e?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Qo(t,x).catch(Ce=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Ce)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!p&&p!==oe,Xt=w!==void 0&&w!==vt,Bt=ft||Xt,Qt=await Fc({privatecode:oe,...he?{endpoint:he}:{},ppeOverride:Ze});if(Bt){j.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Xo(p):"",nextPc:Xo(oe)});for(let _e of[...u.agents.values()])await _e.dispose("connect config switch").catch(()=>{}),u.agents.delete(_e.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Hr,"connect switch").catch(()=>{})}_=Qt.deviceId,ds({deviceId:_,pid:process.pid}),sd({patToken:oe,env:K.env}).catch(_e=>j.warn("coze-cli setup error (ignored)",{err:String(_e)}));let Vr=new Xi({handshake:Qt,privatecode:oe,...pe?{urlOverride:pe}:{},ppeOverride:Ze,getPatTokenForAgent:_e=>u.agents.get(_e)?.patToken});return await c.swap(Vr,"connect"),p=oe,w=vt,I=Ze,y=he,K.mock_scenario!==void 0&&(u.setMockScenario(K.mock_scenario),j.info("mock scenario set",{scenario:K.mock_scenario})),S||(S=new Oi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(_e=>j.warn("detailSync.retryPending failed (ignored)",{err:String(_e)})),onAuthFailures:V})),S.start(),E(),Bt&&Qo(t,x).catch(_e=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(_e)})),Qi(oe,t).catch(_e=>j.warn("writePatToken after /connect failed (ignored)",{err:String(_e)})),j.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async L=>x.createAgent(L.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},F=new lo({agents:u.agents,disposeAndMarkDisconnected:async(L,G)=>{let K=u.agents.get(L);if(K){await x.cleanupOpenclawSessionProviders(K).catch(Ze=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:L,err:String(Ze)}));let oe=!0;try{await K.dispose(`disconnect: ${G}`)}catch(Ze){oe=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:L,err:String(Ze)}),K.status="error"}oe&&(K.status="disconnected",u.unregister(L),u.disconnectedAgents.add(L))}else u.disconnectedAgents.add(L)},detailSyncer:async L=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(L)},cleanupOpenclawProviders:async L=>{await x.cleanupOpenclawSessionProviders(L)},openclawRepair:async(L,G)=>{await x.openclawRepair(L,G)},isRuntimePendingPermission:L=>u.hasPendingPermissionFor(L)});u.registerExtension("_agent/listSkills",L=>F.listSkills(L.params)),u.registerExtension("_agent/addSkills",L=>F.addSkills(L.params)),u.registerExtension("_agent/removeSkills",L=>F.removeSkills(L.params)),u.registerExtension("_agent/getFileTree",L=>F.getFileTree(L.params)),u.registerExtension("_agent/getFileContent",L=>F.getFileContent(L.params)),u.registerExtension("_agent/update",L=>F.updateAgent(L.params)),u.registerExtension("_agent/disconnect",L=>F.disconnectAgent(L.params)),u.registerExtension("_agent/switchModel",L=>F.switchModel(L.params)),u.registerExtension("_agent/reset",L=>F.resetAgent(L.params)),u.registerExtension("_agent/repair",L=>F.repairAgent(L.params)),u.registerExtension("_agent/upgrade",L=>F.upgradeBridge(L.params));let B=new ps({paths:t,handlers:F,agentManager:x,sendDetail:L=>u.sendRequest("_agent/detail",L)});O.ref=B;let V=async L=>{await Promise.allSettled(L.map(async G=>{try{await F.disconnectAgent({agentId:G.agentId,reason:`auth_failure: code=${G.code} ${G.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:G.agentId,code:G.code,message:G.message})}catch(K){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:G.agentId,err:String(K)})}}))};c.onConnect(({initial:L})=>{j.info("frontier upstream connected, triggering detail sync",{initial:L}),B.syncAll(L?"initial-connect":"reconnect").catch(G=>j.warn("detail sync top-level error (ignored)",{err:String(G)}))});let $=new So({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let L=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[es]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...L?{mockScenario:L}:{}}}},{method:"POST",path:"/pair",handler:async L=>{let G=L,K=G?.privatecode,oe=G?.pairing_code;if(!K||!oe)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ze=Di(G.env),he=G.handshake_url,pe=G.frontier_url,vt=Rh(G.env,he,pe),ft=!!p&&p!==K,Xt=w!==void 0&&w!==vt,Bt=ft||Xt,Qt=await Fc({privatecode:K,...he?{endpoint:he}:{},ppeOverride:Ze});if(Bt){j.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Xo(p):"",nextPc:Xo(K),previousEnvKey:w??"",nextEnvKey:vt});for(let Ce of[...u.agents.values()])await Ce.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ce.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Hr,"pair switch").catch(()=>{})}_=Qt.deviceId,ds({deviceId:_,pid:process.pid}),sd({patToken:K,env:G.env}).catch(Ce=>j.warn("coze-cli setup error (ignored)",{err:String(Ce)}));let Vr=new Xi({handshake:Qt,privatecode:K,...pe?{urlOverride:pe}:{},ppeOverride:Ze,getPatTokenForAgent:Ce=>u.agents.get(Ce)?.patToken});await c.swap(Vr,"pair");try{let Ce=new Wn;o.frameworksCache=await Ce.detectAll(),await qi(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ce){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ce)})}let _e=Object.keys(o.frameworksCache??{});try{let Ce=await u.sendRequest("_agent/pair",{pairCode:oe,patToken:K,frameworks:_e,_meta:{cozeDeviceId:_}});j.info("_agent/pair ok",{pairResult:Ce}),p=K,w=vt,I=Ze,y=he,G.mock_scenario!==void 0&&(u.setMockScenario(G.mock_scenario),j.info("mock scenario set",{scenario:G.mock_scenario})),Qi(K,t).catch(Oe=>j.warn("writePatToken after /pair failed (ignored)",{err:String(Oe)})),S||(S=new Oi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(Oe=>j.warn("detailSync.retryPending failed (ignored)",{err:String(Oe)})),onAuthFailures:V})),S.start(),E(),Bt&&Qo(t,x).catch(Oe=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(Oe)}));let Xn;return G.agent_id&&(Xn=await hv(G.agent_id,t,x,Oe=>u.sendRequest("_agent/detail",Oe),K).catch(Oe=>(j.error("--agent-id ensureAgent failed",{agentId:G.agent_id,err:String(Oe)}),{ok:!1,agentId:G.agent_id??"",note:String(Oe)}))),{ok:!0,note:"paired with cloud",...Xn?{agent:Xn}:{}}}catch(Ce){return j.error("_agent/pair failed",{err:String(Ce)}),{ok:!1,note:`pair failed: ${String(Ce)}`}}}},{method:"POST",path:"/connect",handler:L=>P(L)},{method:"POST",path:"/_agent/create",handler:async L=>{let G=L;return{ok:!0,result:await x.createAgent(G)}}},{method:"POST",path:"/agent/send",handler:async L=>{let G=L;if(!G?.agentId||!G?.sessionId||!G?.kind||!G?.path)throw new C("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let K=G;return await(K.groupFile?F0:B0)(K,{core:u,patToken:p,handshakeBase:y,ppeOverride:I})}catch(K){if(K instanceof C)return{ok:!1,code:K.code,message:K.message};throw K}}},{method:"POST",path:"/reload",handler:async L=>{let G=L?.agent_id,K=await u.reloadAgents(G);return j.info("IPC /reload: recycled agent subprocesses",{agentId:G??"(all)",recycled:K}),{ok:!0,recycled:K}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{ae.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:Z}=await $.start();try{await Sh(t.libEntry,t)}catch(L){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(L)})}await u.start(),pv({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Wn().detectAll(),await qi(o),o.frameworksCache)}).catch(L=>j.warn("startup warmup error (ignored)",{err:String(L)})),bl().then(async()=>{let{probeAcpVersion:L}=await Promise.resolve().then(()=>(rn(),yl));for(let G of["claude-code","codex"]){let K=await L(G);K&&j.info("acp wrapper version",{framework:G,version:K})}}).catch(L=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(L)}));let se=null,ae={port:ne,token:Z,core:u,ipc:$,shutdown(L){return se||(j.info("daemon shutdown",{reason:L}),se=(async()=>{S?.stop(),A?.stop(),await u.stop(L),await $.stop(),await e.release()})(),se)}};for(let L of["SIGTERM","SIGINT"])process.on(L,()=>{ae.shutdown(L).then(()=>process.exit(0))});return process.on("exit",()=>a0()),process.on("unhandledRejection",L=>{j.error("unhandledRejection",{reason:L instanceof Error?L.message:String(L),stack:L instanceof Error?L.stack:void 0})}),process.on("uncaughtException",L=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:L.message,stack:L.stack,name:L.name});try{process.stderr.write(`FATAL uncaughtException: ${L.stack??L.message}
|
|
110
|
-
`)}catch{}process.exit(1)}),
|
|
111
|
-
`)){let u=
|
|
112
|
-
`;await
|
|
113
|
-
`).filter(
|
|
114
|
-
`)}async function
|
|
115
|
-
`),1;for(let
|
|
116
|
-
`);return 0}let o=t.date??
|
|
111
|
+
`)}catch{}}let e=new Jo({processTitle:Lr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await vo(),o=i??{};ls({pid:process.pid}),H.info(i?"loaded bridge config":"initialized bridge config");let c=new Ko(new Wr),d=null,u=new So({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(P,U,j,ee)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(P,U,j,ee)}}),f=new yo({paths:t,config:o,registry:u});d=f;let x,p,_=null,v={},w,E=null,I=null,A=null,T=new An;function D(P,U){return T.enqueue(()=>C(P,U))}function y(){I||(I=new Xo({isConnected:()=>c.isConnected()&&!(E?.isLivenessLost()??!1),forceReconnect:()=>A?D(A,{force:!0}):void 0,onFatal:P=>{if(process.env[rs]==="1"){H.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:P});return}H.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:P}),process.exit(1)}})),I.start()}async function C(P,U){let j=P,ee=j?.privatecode;if(!ee)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Xe=Li(j.env),he=j.handshake_url,xe=j.frontier_url,It=Wx(j.env,he,xe);if(A=j,!U?.force&&x===ee&&p===It){let we=await OS(t);return u.agents.size===0&&we?(H.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ea(t,f).catch(Ie=>H.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):H.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let pt=!!x&&x!==ee,en=p!==void 0&&p!==It,zt=pt||en,tn=await zc({privatecode:ee,...he?{endpoint:he}:{},ppeOverride:Xe});if(zt){H.warn("connect config switched, resetting agents",{pcChanged:pt,envChanged:en,previousPc:x?Qo(x):"",nextPc:Qo(ee)});for(let we of[...u.agents.values()])await we.dispose("connect config switch").catch(()=>{}),u.agents.delete(we.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"connect switch").catch(()=>{})}_=tn.deviceId,ls({deviceId:_,pid:process.pid}),dd({patToken:ee,env:j.env}).catch(we=>H.warn("coze-cli setup error (ignored)",{err:String(we)}));let Jr=new ts({handshake:tn,privatecode:ee,...xe?{urlOverride:xe}:{},ppeOverride:Xe,getPatTokenForAgent:we=>u.agents.get(we)?.patToken});return await c.swap(Jr,"connect"),x=ee,p=It,v=Xe,w=he,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),H.info("mock scenario set",{scenario:j.mock_scenario})),E||(E=new Mi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>N.retryPending().catch(we=>H.warn("detailSync.retryPending failed (ignored)",{err:String(we)})),onAuthFailures:Z})),E.start(),y(),zt&&ea(t,f).catch(we=>H.warn("post-connect-switch auto-revive error (ignored)",{err:String(we)})),ns(ee,t).catch(we=>H.warn("writePatToken after /connect failed (ignored)",{err:String(we)})),H.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async P=>f.createAgent(P.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},M=new co({agents:u.agents,publishSkillToMarketplace:async P=>{let U=u.agents.get(P.agentId)?.patToken??x;if(!U)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Fx({patToken:U,zip:P.zip,...P.skillId?{skillId:P.skillId}:{},skillName:P.skillName,...P.description?{description:P.description}:{},agentId:P.agentId,...P.accountId?{accountId:P.accountId}:{}},{handshakeBase:w,ppeOverride:v})},disposeAndMarkDisconnected:async(P,U)=>{let j=u.agents.get(P);if(j){await f.cleanupOpenclawSessionProviders(j).catch(Xe=>H.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(Xe)}));let ee=!0;try{await j.dispose(`disconnect: ${U}`)}catch(Xe){ee=!1,H.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:P,err:String(Xe)}),j.status="error"}ee&&(j.status="disconnected",u.unregister(P),u.disconnectedAgents.add(P))}else u.disconnectedAgents.add(P)},disposeForDelete:async(P,U)=>{let j=u.agents.get(P);j&&(await f.cleanupOpenclawSessionProviders(j).catch(ee=>H.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:P,err:String(ee)})),await j.dispose(`delete: ${U}`).catch(ee=>H.warn("dispose during delete failed (ignored)",{agentId:P,err:String(ee)})),u.unregister(P)),u.disconnectedAgents.delete(P)},detailSyncer:async P=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(P)},cleanupOpenclawProviders:async P=>{await f.cleanupOpenclawSessionProviders(P)},openclawRepair:async(P,U)=>{await f.openclawRepair(P,U)},isRuntimePendingPermission:P=>u.hasPendingPermissionFor(P)});u.registerExtension("_agent/listSkills",P=>M.listSkills(P.params)),u.registerExtension("_agent/addSkills",P=>M.addSkills(P.params)),u.registerExtension("_agent/removeSkills",P=>M.removeSkills(P.params)),u.registerExtension("_agent/publishSkill",P=>M.publishSkill(P.params)),u.registerExtension("_agent/getFileTree",P=>M.getFileTree(P.params)),u.registerExtension("_agent/getFileContent",P=>M.getFileContent(P.params)),u.registerExtension("_agent/update",P=>M.updateAgent(P.params)),u.registerExtension("_agent/disconnect",P=>M.disconnectAgent(P.params)),u.registerExtension("_agent/switchModel",P=>M.switchModel(P.params)),u.registerExtension("_agent/reset",P=>M.resetAgent(P.params)),u.registerExtension("_agent/repair",P=>M.repairAgent(P.params)),u.registerExtension("_agent/delete",P=>M.deleteAgent(P.params)),u.registerExtension("_agent/upgrade",P=>M.upgradeBridge(P.params));let N=new ps({paths:t,handlers:M,agentManager:f,sendDetail:P=>u.sendRequest("_agent/detail",P)});O.ref=N;let Z=async P=>{await Promise.allSettled(P.map(async U=>{try{await M.disconnectAgent({agentId:U.agentId,reason:`auth_failure: code=${U.code} ${U.message}`}),H.info("agent disconnected due to auth failure from heartbeat response",{agentId:U.agentId,code:U.code,message:U.message})}catch(j){H.warn("disconnect during authFailure handling failed (ignored)",{agentId:U.agentId,err:String(j)})}}))};c.onConnect(({initial:P})=>{H.info("frontier upstream connected, triggering detail sync",{initial:P}),N.syncAll(P?"initial-connect":"reconnect").catch(U=>H.warn("detail sync top-level error (ignored)",{err:String(U)}))});let K=new Io({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let P=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[rs]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...P?{mockScenario:P}:{}}}},{method:"POST",path:"/pair",handler:async P=>{let U=P,j=U?.privatecode,ee=U?.pairing_code;if(!j||!ee)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Xe=Li(U.env),he=U.handshake_url,xe=U.frontier_url,It=Wx(U.env,he,xe),pt=!!x&&x!==j,en=p!==void 0&&p!==It,zt=pt||en,tn=await zc({privatecode:j,...he?{endpoint:he}:{},ppeOverride:Xe});if(zt){H.warn("pair config switched, resetting agents",{pcChanged:pt,envChanged:en,previousPc:x?Qo(x):"",nextPc:Qo(j),previousEnvKey:p??"",nextEnvKey:It});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"pair switch").catch(()=>{})}_=tn.deviceId,ls({deviceId:_,pid:process.pid}),dd({patToken:j,env:U.env}).catch(Ie=>H.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Jr=new ts({handshake:tn,privatecode:j,...xe?{urlOverride:xe}:{},ppeOverride:Xe,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Jr,"pair");try{let Ie=new Kn;o.frameworksCache=await Ie.detectAll(),await ji(o),H.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){H.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let we=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:ee,patToken:j,frameworks:we,_meta:{cozeDeviceId:_}});H.info("_agent/pair ok",{pairResult:Ie}),x=j,p=It,v=Xe,w=he,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),H.info("mock scenario set",{scenario:U.mock_scenario})),ns(j,t).catch(Pe=>H.warn("writePatToken after /pair failed (ignored)",{err:String(Pe)})),E||(E=new Mi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>N.retryPending().catch(Pe=>H.warn("detailSync.retryPending failed (ignored)",{err:String(Pe)})),onAuthFailures:Z})),E.start(),y(),zt&&ea(t,f).catch(Pe=>H.warn("post-pair-switch auto-revive error (ignored)",{err:String(Pe)}));let er;return U.agent_id&&(er=await NS(U.agent_id,t,f,Pe=>u.sendRequest("_agent/detail",Pe),j).catch(Pe=>(H.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(Pe)}),{ok:!1,agentId:U.agent_id??"",note:String(Pe)}))),{ok:!0,note:"paired with cloud",...er?{agent:er}:{}}}catch(Ie){return H.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:P=>D(P)},{method:"POST",path:"/_agent/create",handler:async P=>{let U=P;return{ok:!0,result:await f.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async P=>{let U=P;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 j=U;return await(j.groupFile?Q0:X0)(j,{core:u,patToken:x,handshakeBase:w,ppeOverride:v})}catch(j){if(j instanceof k)return{ok:!1,code:j.code,message:j.message};throw j}}},{method:"POST",path:"/reload",handler:async P=>{let U=P?.agent_id,j=await u.reloadAgents(U);return H.info("IPC /reload: recycled agent subprocesses",{agentId:U??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(H.info("IPC /shutdown received"),setImmediate(()=>{se.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:Y}=await K.start();try{await Ux(t.libEntry,t)}catch(P){H.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(P)})}await u.start(),MS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Kn().detectAll(),await ji(o),o.frameworksCache)}).catch(P=>H.warn("startup warmup error (ignored)",{err:String(P)})),Tl().then(async()=>{let{probeAcpVersion:P}=await Promise.resolve().then(()=>(sn(),Al));for(let U of["claude-code","codex"]){let j=await P(U);j&&H.info("acp wrapper version",{framework:U,version:j})}}).catch(P=>H.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(P)}));let ie=null,se={port:ne,token:Y,core:u,ipc:K,shutdown(P){return ie||(H.info("daemon shutdown",{reason:P}),ie=(async()=>{E?.stop(),I?.stop(),await u.stop(P),await K.stop(),await e.release()})(),ie)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{se.shutdown(P).then(()=>process.exit(0))});return process.on("exit",()=>g0()),process.on("unhandledRejection",P=>{H.error("unhandledRejection",{reason:P instanceof Error?P.message:String(P),stack:P instanceof Error?P.stack:void 0})}),process.on("uncaughtException",P=>{H.error("uncaughtException (will exit, supervisor will restart)",{message:P.message,stack:P.stack,name:P.name});try{process.stderr.write(`FATAL uncaughtException: ${P.stack??P.message}
|
|
112
|
+
`)}catch{}process.exit(1)}),H.info("daemon ready",{port:ne,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),FS({cliSpawned:process.env[rs]==="1",readPatToken:()=>Vo(t),connect:D}).catch(P=>H.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(P)})),se}async function OS(t){return fs(t).length>0}function Qo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Wx(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function LS(t,e){let r=fs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(cn(),xs));for(let c of r){await o(c,t).catch(d=>H.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.deletedAt?(e.disconnectedAgents.add(c),H.info("agent marked deleted on startup",{agentId:c,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(c),H.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){H.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function NS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(cn(),xs)),d=await c(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`);H.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let p=Kx(d),_={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...p?{_meta:p}:{}};return await r.createAgent(_),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}H.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new 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 r.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 MS(t){let e=t.logger??H;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await LS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await ea(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)})),await BS(t.paths).catch(r=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(r)}))}async function ea(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(cn(),xs));H.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let f;try{f=await o(u,t)}catch(x){H.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),d+=1;continue}if(!f){d+=1;continue}if(f.deletedAt){H.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:f.deletedAt}),d+=1;continue}if(f.disconnectedAt){H.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),d+=1;continue}try{H.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let x=Kx(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}),c+=1}catch(x){H.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(x)}),d+=1}}return H.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function BS(t){let{readdir:e}=await import("node:fs/promises"),r;try{r=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(r.length===0)return{refreshed:0,total:0};let i=0;for(let o of r)try{(await r0(o,t)).status==="refreshed"&&(i+=1)}catch(c){H.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&H.info("builtin skills refresh on startup done",{refreshed:i,total:r.length}),{refreshed:i,total:r.length}}async function FS(t){let e=t.logger??H;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Kx(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Yo();De();import{readFile as Vx}from"node:fs/promises";var Qt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await ta(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:US(i)}}}async request(e){let r=await ta(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),f=await u.text();return{status:u.status,body:zS(f)}}finally{clearTimeout(d)}}};async function ta(t){try{let[e,r]=await Promise.all([Vx(t.portFile,"utf8"),Vx(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=r.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function zS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function US(t){return t instanceof Error?t.message:String(t)}Kt();te();ir();import{spawn as GS}from"node:child_process";import{userInfo as Jx}from"node:os";var Ud="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",HS=new Set(["bash","zsh","sh","dash","ksh"]),Zx=Ke("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),qS=2e3;function jS(t,e=Ud){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let d of o.split(`
|
|
113
|
+
`)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function WS(){let t=(process.env.SHELL??"").trim()||(Jx().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return HS.has(e)?t:null}function $S(t){return new Promise(e=>{let r=`printf '%s' '${Ud}'; env; printf '%s' '${Ud}'`,i;try{i=GS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Jx().homedir}})}catch{e(null);return}let o="",c=!1,d=p=>{try{i.pid&&process.kill(-i.pid,p)}catch{}},u=p=>{c||(c=!0,clearTimeout(f),clearTimeout(x),e(p))};i.stdout?.on("data",p=>{o+=p.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let f=setTimeout(()=>d("SIGTERM"),Zx),x=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},Zx+qS)})}async function Gd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=WS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??$S)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=jS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}De();function Rn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}sn();import{chmod as KS,copyFile as Yx,mkdir as Qx,readFile as na,rename as Xx,rm as Hd,stat as ep,writeFile as VS}from"node:fs/promises";import{homedir as iD}from"node:os";import{dirname as ZS,join as $r,resolve as qd,sep as is}from"node:path";import{fileURLToPath as JS}from"node:url";Kt();te();De();var jd=G("dist-install");function YS(t){let e=JS(t),r=ZS(e),i=`${is}src${is}`;if(r.includes(i)||r.endsWith(`${is}src${is}cli`))return null;let o=qd(r,"index.js"),c=qd(r,"..","package.json");return{dist:o,pkgJson:c}}async function $d(t={}){let e=t.paths??Q(),r=YS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let v=JSON.parse(await na(o,"utf8"));c=v.version??"unknown",d=v.dependencies??{}}catch(v){return jd.warn("cannot read source package.json,skip dist install",{err:String(v)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(v)}`}}let u=ti.map(v=>`${v}@${d[v]??"latest"}`),f=await vo(e.configFile)??{},x=f.libVersion,p=await na(e.libEntry).then(()=>!0).catch(()=>!1),_=x===c;if(_&&p&&await Wd(e))return{kind:"already-current",libVersion:c};if(!_||!p){await Qx(e.libDir,{recursive:!0}),await Yx(i,e.libEntry),await Yx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let v=qd(e.libDir,"package.json"),w=`${JSON.stringify({type:"module"},null,2)}
|
|
114
|
+
`;await na(v,"utf8").catch(()=>null)!==w&&await VS(v,w)}return(!_||!await Wd(e))&&await(t.installWrappers??XS)(e,u),f.libVersion=c,await ji(f,e.configFile),jd.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),_&&p?{kind:"already-current",libVersion:c}:x?{kind:"version-changed",fromVersion:x,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Wd(t){for(let e of ti){let r=$r(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await ep(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function XS(t,e){await t1(t.installLock,async()=>{if(await Wd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${is}.staging-${process.pid}-${r}`,o=$r(i,"node_modules"),c=$r(t.libDir,"node_modules");try{await Qx(i,{recursive:!0}),await QS(e,i),await e1(o);let d=`${c}.trash-${r}`;await Xx(c,d).catch(()=>{}),await Xx(o,c),await Hd(d,{recursive:!0,force:!0}).catch(()=>{}),jd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Hd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function QS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=nt("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",f=>{d.length<8192&&(d+=f.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),c.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${d.trim().slice(0,2e3)}`))})})}async function e1(t){for(let e of ti){let r=$r(t,...e.split("/")),i=JSON.parse(await na($r(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=$r(t,".bin",o),d=await ep(c);process.platform!=="win32"&&!(d.mode&73)&&await KS(c,d.mode|73).catch(()=>{})}}async function t1(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Hd(t,{force:!0}).catch(()=>{})}}Sa();te();De();import{closeSync as np,fstatSync as rp,openSync as ip,readFileSync as n1,readSync as r1,readdirSync as i1,statSync as s1}from"node:fs";import{join as ra}from"node:path";var o1=new Set(["debug","info","warn","error"]);function sp(t){let e=t,r=Rn(e,"--agent-id");e=r.rest;let i=Rn(e,"--date");e=i.rest;let o=Rn(e,"-n","--lines");e=o.rest;let c=Rn(e,"--level");e=c.rest;let d=Rn(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),f=Number.isInteger(u)&&u>=0?u:200,x=c.value&&o1.has(c.value)?c.value:void 0,p={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(p.agentId=r.value),i.value&&(p.date=i.value),x&&(p.level=x),d.value&&(p.grep=d.value),p}function a1(t,e){return t.agentId?ra(Ve(t.agentId,e).logs,sr("agent",t.date)):ra(e.bridgeLogsDir,sr("bridge",t.date))}function c1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function d1(t,e){let r;try{r=i1(t)}catch{return[]}let i=[];for(let o of r){let c=va(o,e);if(!c)continue;let d=0;try{d=s1(ra(t,o)).size}catch{}i.push({file:ra(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function op(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let r;try{r=JSON.parse(t).level}catch{return!0}if(typeof r=="string"&&!bl(r,e.level))return!1}return!0}var tp={debug:"90",info:"36",warn:"33",error:"31"},l1=new Set(["ts","level","module","msg"]);function u1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function ap(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=u1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&tp[o]&&(c=`\x1B[${tp[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",f=Object.entries(r).filter(([x])=>!l1.has(x)).map(([x,p])=>` ${x}=${typeof p=="string"?p:JSON.stringify(p)}`).join("");return`${i} ${c} ${d} ${u}${f}`}function f1(t,e,r){let c=n1(t,"utf8").split(`
|
|
115
|
+
`).filter(d=>d.length>0).filter(d=>op(d,{level:e.level,grep:e.grep}));for(let d of c1(c,e.lines))process.stdout.write(`${ap(d,{raw:e.raw,color:r})}
|
|
116
|
+
`)}async function cp(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ve(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=d1(d,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
|
|
117
|
+
`),1;for(let x of f)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
|
|
118
|
+
`);return 0}let o=t.date??Pn(new Date),c=a1({agentId:t.agentId,date:o},r);try{f1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
|
|
117
119
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
118
120
|
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
|
|
119
|
-
`),1}return t.follow&&await
|
|
120
|
-
`);o=
|
|
121
|
-
`)}await new Promise(
|
|
121
|
+
`),1}return t.follow&&await p1(c,t,i),0}var h1=500;function x1(t){try{let e=ip(t,"r");try{return rp(e).size}finally{np(e)}}catch{return 0}}async function p1(t,e,r){let i=x1(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let f=ip(t,"r");try{let x=rp(f).size;if(x>i){let p=Buffer.allocUnsafe(x-i),_=r1(f,p,0,p.length,i);u=p.subarray(0,_).toString("utf8"),i+=_}}finally{np(f)}}catch{}if(u){let f=(o+u).split(`
|
|
122
|
+
`);o=f.pop()??"";for(let x of f)x.length>0&&op(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${ap(x,{raw:e.raw,color:r})}
|
|
123
|
+
`)}await new Promise(f=>setTimeout(f,h1))}}finally{process.off("SIGINT",d)}}import{basename as g1,resolve as m1}from"node:path";De();var w1=9e4,_1={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function y1(t){return _1[t]??1}async function dp(t,e={}){let r=e.paths??Q();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
|
|
122
124
|
`),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
|
|
123
|
-
`),3;let i=await
|
|
124
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
125
|
+
`),3;let i=await ta(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
|
|
126
|
+
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:m1(process.cwd(),t.path),...t.caption?{caption:t.caption}:{},...t.name?{name:t.name}:{},...t.groupFile?{groupFile:!0}:{},...t.mimeType?{mimeType:t.mimeType}:{}},c;try{c=await b1(i,"/agent/send",o,w1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
|
|
125
127
|
`),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
|
|
126
|
-
`),
|
|
127
|
-
`);else{let
|
|
128
|
-
`)}else process.stdout.write(`Sent ${t.kind} ${
|
|
129
|
-
`)}return 0}async function
|
|
130
|
-
`)}function
|
|
128
|
+
`),y1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
|
|
129
|
+
`);else{let d=t.name??g1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
|
|
130
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${E1(c.bytes)})
|
|
131
|
+
`)}return 0}async function b1(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await d.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function E1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var wp=G("cli");function He(t,e){let{value:r,rest:i}=Rn(t,e);return{value:r,rest:i}}function da(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
132
|
+
`)}function $1(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:D}=He(e.slice(1),"--agent-id");return D?{mode:"reload",agentId:D}:{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 K1(e.slice(1));if(e[0]==="log")return{mode:"log",...sp(e.slice(1))};if(e[0]==="connect")return V1(e.slice(1));if(e.includes("--status"))return da("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return da("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return da("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return da("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=He(r,"--pat-token");r=o;let{value:c,rest:d}=He(r,"--pair-code");r=d;let{value:u,rest:f}=He(r,"--env");r=f;let{value:x,rest:p}=He(r,"--handshake-url");r=p;let{value:_,rest:v}=He(r,"--frontier-url");r=v;let{value:w,rest:E}=He(r,"--mock-scenario");r=E;let{value:I}=He(r,"--agent-id"),A=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let T={mode:"pair",privatecode:i,pairingCode:c};return u&&(T.env=u),x&&(T.handshakeUrl=x),_&&(T.frontierUrl=_),w&&(T.mockScenario=w),I&&(T.agentId=I),A&&(T.skipRebuildEnv=!0),T}function K1(t){let e=t[0],r=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!r||r.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=He(i,"--caption");i=c;let{value:d,rest:u}=He(i,"--name");i=u;let{value:f,rest:x}=He(i,"--agent-id");i=x;let{value:p,rest:_}=He(i,"--session-id");i=_;let{value:v,rest:w}=He(i,"--mime");i=w;let E=i.includes("--group-file");i=i.filter(T=>T!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:r,json:I};return o&&(A.caption=o),d&&(A.name=d),f&&(A.agentId=f),p&&(A.sessionId=p),E&&(A.groupFile=!0),v&&(A.mimeType=v),A}function V1(t){let e=t,{value:r,rest:i}=He(e,"--pat-token");e=i;let{value:o,rest:c}=He(e,"--env");e=c;let{value:d,rest:u}=He(e,"--handshake-url");e=u;let{value:f,rest:x}=He(e,"--frontier-url");e=x;let{value:p,rest:_}=He(e,"--mock-scenario");e=_;let v=e.includes("--skip-rebuild-env"),w={mode:"connect"};return r&&(w.privatecode=r),o&&(w.env=o),d&&(w.handshakeUrl=d),f&&(w.frontierUrl=f),p&&(w.mockScenario=p),v&&(w.skipRebuildEnv=!0),w}var Z1=`
|
|
131
133
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
132
134
|
|
|
133
135
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -208,57 +210,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
208
210
|
|
|
209
211
|
Internal:
|
|
210
212
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
211
|
-
`.trimStart();async function
|
|
212
|
-
`),0;case"daemon":{try{await
|
|
213
|
-
`),1;if(i.kind==="stale")return await
|
|
213
|
+
`.trimStart();async function _p(t=process.argv,e={}){let r=$1(t);switch(r.mode){case"help":return process.stdout.write(Z1),0;case"version":return process.stdout.write(`${Ot}
|
|
214
|
+
`),0;case"daemon":{try{await $x()}catch(i){return wp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return J1(e);case"stop":return bp(e);case"reload":return Q1(r.agentId,e);case"log":return cp(r,e);case"update":return Y1(e);case"purge":return eI(e);case"service-install":return tI(e);case"service-uninstall":return nI(e);case"pair":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),rI(r.privatecode,r.pairingCode,e,i,r.agentId,r.skipRebuildEnv)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),iI(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return dp({kind:r.kind,path:r.path,...r.agentId?{agentId:r.agentId}:{},...r.sessionId?{sessionId:r.sessionId}:{},...r.caption?{caption:r.caption}:{},...r.name?{name:r.name}:{},...r.groupFile?{groupFile:!0}:{},...r.mimeType?{mimeType:r.mimeType}:{},json:r.json},e)}}async function yp(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 J1(t){let e=t.paths??Q(),r=new Qt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
215
|
+
`),1;if(i.kind==="stale")return await yp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
214
216
|
`),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
215
217
|
${JSON.stringify(o.body,null,2)}
|
|
216
|
-
`),0}async function
|
|
217
|
-
`)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(
|
|
218
|
+
`),0}async function bp(t){let e=t.paths??Q(),r=new Qt(e),i=t.daemonSweep??(async()=>{let f=m0();return await w0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},c=await os(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
|
|
219
|
+
`)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
|
|
218
220
|
`:`coze-bridge: not running
|
|
219
|
-
`),0;if(u.kind==="stale")return await
|
|
221
|
+
`),0;if(u.kind==="stale")return await yp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
220
222
|
`),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
221
|
-
`),0}catch(
|
|
222
|
-
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(
|
|
223
|
-
`),1)}}async function
|
|
224
|
-
`),e(1)})})}async function
|
|
223
|
+
`),0}catch(f){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
|
|
224
|
+
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
|
|
225
|
+
`),1)}}async function Y1(t){return await bp(t),(t.spawnNpx??X1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function X1(t){return new Promise(e=>{let r=nt("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
|
|
226
|
+
`),e(1)})})}async function Q1(t,e){let r=new Qt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
225
227
|
`),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
|
|
226
228
|
`):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
|
|
227
229
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
228
230
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
229
|
-
`),1}}async function
|
|
231
|
+
`),1}}async function os(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(d,u),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(gp(),pp)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Ep(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??jx,o=t.waitTimeoutMs??15e3,c=t.sleep??oI,d=t.paths??Q(),u=await os(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await mp(e,o,c);if(f.kind==="connected")return f;At(d.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(f){At(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}At(d.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await sI(d.pidFile,c)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
|
|
230
232
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
231
|
-
`),await i({paths:t.paths}),
|
|
232
|
-
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(
|
|
233
|
-
`)}await new Promise(
|
|
234
|
-
`)}catch(
|
|
235
|
-
`)}let o=t.paths??
|
|
236
|
-
`)}catch(
|
|
233
|
+
`),await i({paths:t.paths}),mp(e,o,c)}async function eI(t){let e=new Qt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
234
|
+
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
|
|
235
|
+
`)}await new Promise(d=>setTimeout(d,500))}let i=await os(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
236
|
+
`)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
|
|
237
|
+
`)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
|
|
238
|
+
`)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
|
|
237
239
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
238
|
-
`),0}async function
|
|
240
|
+
`),0}async function tI(t){let e=await os(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
239
241
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
240
242
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
|
|
241
|
-
`),1}}async function
|
|
243
|
+
`),1}}async function nI(t){let e=await os(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
242
244
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
|
|
243
|
-
`),1}}async function
|
|
244
|
-
`),
|
|
245
|
-
`),(await
|
|
246
|
-
`)}let
|
|
247
|
-
`),1;let
|
|
245
|
+
`),1}}async function vp(t,e,r){if(e)return At(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(At(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(At(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
|
|
246
|
+
`),At(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function rI(t,e,r,i={},o,c){let d=new Qt(r.paths),u=r.paths??Q(),f=await vp(u,c,r.reconstructEnv??Gd);if(await Qc(u,f).catch(_=>At(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await $d({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
|
|
247
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(w=>setTimeout(w,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
|
|
248
|
+
`)}let x=await Ep(r,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
|
|
249
|
+
`),1;let p={privatecode:t,pairing_code:e};i.env&&(p.env=i.env),i.handshakeUrl&&(p.handshake_url=i.handshakeUrl),i.frontierUrl&&(p.frontier_url=i.frontierUrl),i.mockScenario&&(p.mock_scenario=i.mockScenario),o&&(p.agent_id=o);try{let _=await d.request({method:"POST",path:"/pair",body:p,timeoutMs:35e3});if(_.status===200&&_.body?.ok){let v=_.body.agent;return v&&!v.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${v.agentId}): ${v.note}
|
|
248
250
|
`),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
|
|
249
251
|
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
|
|
250
252
|
`),1}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
|
|
251
|
-
`),1}}async function
|
|
252
|
-
`),(await
|
|
253
|
-
`)}let
|
|
254
|
-
`),1;let
|
|
255
|
-
`),t!==void 0&&await
|
|
256
|
-
`),1)}catch(
|
|
257
|
-
`),1}}async function
|
|
253
|
+
`),1}}async function iI(t,e,r={},i){let o=e.paths??Q(),c=t??await Vo(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let d=new Qt(e.paths),u=await vp(o,i,e.reconstructEnv??Gd);if(await Qc(o,u).catch(p=>At(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(p)})),!e.skipDistInstall){let p=await $d({paths:e.paths});p.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${p.fromVersion} \u2192 ${p.toVersion}
|
|
254
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(v=>setTimeout(v,500)))):p.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${p.libVersion}
|
|
255
|
+
`)}let f=await Ep(e,d);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
|
|
256
|
+
`),1;let x={privatecode:c};r.env&&(x.env=r.env),r.handshakeUrl&&(x.handshake_url=r.handshakeUrl),r.frontierUrl&&(x.frontier_url=r.frontierUrl),r.mockScenario&&(x.mock_scenario=r.mockScenario);try{let p=await d.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return p.status===200&&p.body?.ok?(process.stdout.write(`coze-bridge: connected (${p.body.note??"ok"})
|
|
257
|
+
`),t!==void 0&&await ns(c,o).catch(_=>wp.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(p.body)}
|
|
258
|
+
`),1)}catch(p){return process.stderr.write(`coze-bridge: connect failed: ${String(p)}
|
|
259
|
+
`),1}}async function mp(t,e,r){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await r(200)}return t.probe(500)}async function sI(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!Ui(u))return;await e(i)}}function oI(t){return new Promise(e=>setTimeout(e,t))}te();function aI(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let r=Number(e[1]),i=Number(e[2]??0);return r<18||r===18&&i<4?"fatal":r<20?"warn":"ok"}function Sp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=aI(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
|
|
258
260
|
`),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
|
|
259
261
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
260
262
|
npx -y coze-bridge@latest stop
|
|
261
263
|
npx -y coze-bridge@latest connect
|
|
262
264
|
|
|
263
|
-
`)}
|
|
265
|
+
`)}Sp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&_l("warn");_p(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
264
266
|
`),process.exit(1)});
|