coze-bridge 0.1.103-alpha.2 → 0.1.103-alpha.5
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 +80 -77
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
|
|
|
5
5
|
const require = __coze_createRequire(import.meta.url);
|
|
6
6
|
const __filename = __coze_fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __coze_dirname(__filename);
|
|
8
|
-
var
|
|
8
|
+
var eg=Object.create;var wa=Object.defineProperty;var tg=Object.getOwnPropertyDescriptor;var ng=Object.getOwnPropertyNames;var rg=Object.getPrototypeOf,ig=Object.prototype.hasOwnProperty;var ue=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ye=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_a=(t,e)=>{for(var r in e)wa(t,r,{get:e[r],enumerable:!0})},sg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ng(e))!ig.call(t,o)&&o!==r&&wa(t,o,{get:()=>e[o],enumerable:!(i=tg(e,o))||i.enumerable});return t};var Ft=(t,e,r)=>(r=t!=null?eg(rg(t)):{},sg(e||!t||!t.__esModule?wa(r,"default",{value:t,enumerable:!0}):r,t));function je(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var nr=Ye(()=>{"use strict"});import{createWriteStream as og,mkdirSync as ag,readdirSync as cg,unlinkSync as dg}from"node:fs";import{join as dl}from"node:path";function Rn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function rr(t,e){return`${t}-${e}.log`}function ya(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function lg(t,e,r){let i=c=>{let[d,u,x]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function is(t,e,r,i){let o;try{o=cg(t)}catch{return}for(let c of o){let d=ya(c,e);if(d&&lg(d,r,i))try{dg(dl(t,c))}catch{}}}var Zr,ba=Ye(()=>{"use strict";Zr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Rn(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{ag(this.dir,{recursive:!0});let r=og(dl(this.dir,rr(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
|
-
`,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await Il(o,i,{encoding:"utf8",mode:r.mode}):await Il(o,i,"utf8"),await Sl(o,t),r?.mode!==void 0&&await Dg(t,r.mode)}catch(c){await Sl(o,o).catch(()=>{});let{rm:d}=await import("node:fs/promises");throw await d(o,{force:!0}).catch(()=>{}),c}}var Xr=Je(()=>{"use strict"});import{promises as Al,readdirSync as Ng}from"node:fs";import{homedir as Mg}from"node:os";import{sep as Bg,join as Ie,resolve as Tl}from"node:path";function Y(t){let e=t??Mg(),r=Ie(e,".coze"),i=Ie(r,"bridge"),o=Ie(i,"lib"),c=Ie(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ie(o,"index.js"),binDir:Ie(i,"bin"),pidFile:Ie(i,"bridge.pid"),portFile:Ie(i,"bridge.port"),tokenFile:Ie(i,"bridge.token"),patTokenFile:Ie(i,"pat-token"),agentEnvFile:Ie(i,"agent-env.json"),logFile:Ie(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ie(c,"daemon-stdio.log"),installLock:Ie(i,"install.lock"),configFile:Ie(i,"config.json"),agentsRoot:Ie(r,"agents")}}function Ze(t,e=Y()){let r=Ie(e.agentsRoot,t);return{root:r,config:Ie(r,"config.json"),workspace:Ie(r,"workspace"),logs:Ie(r,"logs")}}function os(t=Y()){try{return Ng(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Qr(t,e){let r=await Al.realpath(Tl(t)).catch(()=>null);if(!r)return!1;let i=await Al.realpath(Tl(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?r.toLowerCase():r,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+Bg)}var ke=Je(()=>{"use strict"});var ds={};_a(ds,{AGENT_CONFIG_FILE_MODE:()=>as,enforceAgentConfigMode:()=>Ug,loadAgentConfig:()=>Ge,persistAgentSessions:()=>ei,persistAgentSkills:()=>cs,saveAgentConfig:()=>Ye});import{chmod as Fg,stat as zg}from"node:fs/promises";function Ge(t,e){return rr(Ze(t,e).config)}function Ye(t,e){return ir(Ze(t.agentId,e).config,t,{mode:as})}async function Ug(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await zg(r);if(!i.isFile())return;let o=i.mode&511;o!==as&&(await Fg(r,as),Cl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Cl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ei(t,e,r){let i=await Ge(t,r);i&&(i.sessions=Object.fromEntries(e),await Ye(i,r))}async function cs(t,e,r){let i=await Ge(t,r);i&&(i.skills=e,await Ye(i,r))}var Cl,as,rn=Je(()=>{"use strict";Xr();ne();ke();Cl=U("agent-config"),as=384});var Ca=ae((II,Dl)=>{Dl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var us=ae(Ol=>{var Pl={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function Kg(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Pl))Ol[t]=Kg(Pl[t])});var Fl=ae((TI,Bl)=>{var $g=ue("fs"),De=ue("path"),Ll=Ca(),Vg=us(),Jg=typeof process=="object"&&process.platform==="win32",Nl=t=>typeof t=="object"&&t!==null,Ml=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=De.sep,this.fs=$g,Nl(t)&&Nl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Bl.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var 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 Vg.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=De.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,h){if(d&&h.isDirectory())return o(!1);var x=De.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),c.fs.open(t,"w",438,function(w,b){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):b?c.fs.write(b,e,0,e.length,0,function(){c.fs.close(b,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 h=De.join(i,u),x=e.fs.statSync(h);(!o||o.test(h))&&d.push(De.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(h,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=De.join(t,u),r.fs.stat(u,function(h,x){if(h)return e(h);x&&(i.push(De.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(m,w){if(m)return e(m);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Ml[(t^e)&255]^t>>>8};Ee.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ee.crc32update(r,t[i++]);return~r>>>0};Ee.methodToString=function(t){switch(t){case Ll.STORED:return"STORED ("+t+")";case Ll.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=De.posix.normalize("/"+t.split("\\").join("/"));return De.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=De.posix.normalize("/"+t.split("\\").join("/"));return De.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=De.resolve(De.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=De.normalize(De.join(t,r.slice(i,o).join(De.sep)));if(c.indexOf(t)===0)return c}return De.normalize(De.join(t,De.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=Jg;Ee.crcTable=Ml});var Ul=ae((CI,zl)=>{var Zg=ue("path");zl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=Zg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ql=ae((RI,Gl)=>{Gl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var ar=ae((kI,or)=>{or.exports=Fl();or.exports.Constants=Ca();or.exports.Errors=us();or.exports.FileAttr=Ul();or.exports.decoder=ql()});var jl=ae((DI,Hl)=>{var sn=ar(),z=sn.Constants;Hl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,h=0,x=0,m=0,w=0,b=0,_=0,v=0;t|=sn.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,R=y=>Math.max(0,y)&255;return o=sn.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 sn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=sn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return R(o>>>8)},get crc(){return c},set crc(y){c=A(y)},get compressedSize(){return d},set compressedSize(y){d=A(y)},get size(){return u},set size(y){u=A(y)},get fileNameLength(){return h},set fileNameLength(y){h=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return m},set commentLength(y){m=y},get diskNumStart(){return w},set diskNumStart(y){w=A(y)},get inAttr(){return b},set inAttr(y){b=A(y)},get attr(){return _},set attr(y){_=A(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return v},set offset(y){v=A(y)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+h+x+m},get realDataOffset(){return v+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var D=y.slice(v,v+z.LOCHDR);if(D.readUInt32LE(0)!==z.LOCSIG)throw sn.Errors.INVALID_LOC();I.version=D.readUInt16LE(z.LOCVER),I.flags=D.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=D.readUInt16LE(z.LOCHOW),I.time=D.readUInt32LE(z.LOCTIM),I.crc=D.readUInt32LE(z.LOCCRC),I.compressedSize=D.readUInt32LE(z.LOCSIZ),I.size=D.readUInt32LE(z.LOCLEN),I.fnameLen=D.readUInt16LE(z.LOCNAM),I.extraLen=D.readUInt16LE(z.LOCEXT);let O=v+z.LOCHDR+I.fnameLen,B=O+I.extraLen;return y.slice(O,B)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw sn.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),h=y.readUInt16LE(z.CENNAM),x=y.readUInt16LE(z.CENEXT),m=y.readUInt16LE(z.CENCOM),w=y.readUInt16LE(z.CENDSK),b=y.readUInt16LE(z.CENATT),_=y.readUInt32LE(z.CENATX),v=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(h,z.LOCNAM),y.writeUInt16LE(I.extraLen,z.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(z.CENHDR+h+x+m);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(h,z.CENNAM),y.writeUInt16LE(x,z.CENEXT),y.writeUInt16LE(m,z.CENCOM),y.writeUInt16LE(w,z.CENDSK),y.writeUInt16LE(b,z.CENATT),y.writeUInt32LE(_,z.CENATX),y.writeUInt32LE(v,z.CENOFF),y},toJSON:function(){let y=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:sn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(h),extraLength:y(x),commentLength:y(m),diskNumStart:w,inAttr:b,attr:_,offset:v,centralHeaderSize:y(z.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Kl=ae((PI,Wl)=>{var cr=ar(),we=cr.Constants;Wl.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw cr.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=cr.readBigUInt64LE(c,we.ZIP64SUB),e=cr.readBigUInt64LE(c,we.ZIP64TOT),r=cr.readBigUInt64LE(c,we.ZIP64SIZE),i=cr.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(d,u){let h=d.toString(16).toUpperCase();for(;h.length<u;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ka=ae(Ra=>{Ra.EntryHeader=jl();Ra.MainHeader=Kl()});var Vl=ae((LI,$l)=>{$l.exports=function(t){var e=ue("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),h=0;u.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(u,h),h+=m.length}i&&i(u)}),o.end(t)}}}});var Zl=ae((NI,Jl)=>{var Yg=+(process.versions?process.versions.node:"").split(".")[0]||0;Jl.exports=function(t,e){var r=ue("zlib");let i=Yg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],u=0;c.on("data",function(h){d.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),x=0;h.fill(0);for(var m=0;m<d.length;m++){var w=d[m];w.copy(h,x),x+=w.length}o&&o(h)}),c.end(t)}}}});var tu=ae((MI,eu)=>{"use strict";var{randomFillSync:Yl}=ue("crypto"),Xg=us(),Qg=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),Ql=(t,e)=>Math.imul(t,e)>>>0,Xl=(t,e)=>Qg[(t^e)&255]^t>>>8,ti=()=>typeof Yl=="function"?Yl(Buffer.alloc(12)):ti.node();ti.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var fs={genSalt:ti};function hs(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])}hs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Xl(e[0],t),e[1]+=e[0]&255,e[1]=Ql(e[1],134775813)+1,e[2]=Xl(e[2],e[1]>>>24),t};hs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Ql(t,t^1)>>8&255};function em(t){let e=new hs(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 tm(t){let e=new hs(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 nm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=em(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Xg.WRONG_PASSWORD();return i(t.slice(12))}function rm(t){Buffer.isBuffer(t)&&t.length>=12?fs.genSalt=function(){return t.slice(0,12)}:t==="node"?fs.genSalt=ti.node:fs.genSalt=ti}function im(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=tm(r),c=fs.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)}eu.exports={decrypt:nm,encrypt:im,_salter:rm}});var nu=ae(xs=>{xs.Deflater=Vl();xs.Inflater=Zl();xs.ZipCrypto=tu()});var Pa=ae((FI,ru)=>{var ce=ar(),sm=ka(),ve=ce.Constants,Da=nu();ru.exports=function(t,e){var r=new sm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let m=t,w=typeof m.decoder=="object"?m.decoder:ce.decoder;x=w.hasOwnProperty("efs")?w.efs:!1;function b(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(y)!==r.localHeader.crc)return!1}else{let D={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==ve.LOCSIG||e.readUInt32LE(O)==ve.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==ve.EXTSIG)D.crc=e.readUInt32LE(O+ve.EXTCRC),D.compressedSize=e.readUInt32LE(O+ve.EXTSIZ),D.size=e.readUInt32LE(O+ve.EXTLEN);else if(e.readUInt16LE(O+12)===19280)D.crc=e.readUInt32LE(O+ve.EXTCRC-4),D.compressedSize=e.readUInt32LE(O+ve.EXTSIZ-4),D.size=e.readUInt32LE(O+ve.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(y)!==D.crc)return!1}return!0}function v(y,D,O){if(typeof D>"u"&&typeof y=="string"&&(O=y,y=void 0),c)return y&&D&&D(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=b();if(B.length===0)return y&&D&&D(B),B;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw ce.Errors.INVALID_PASS_PARAM();B=Da.ZipCrypto.decrypt(B,r,O)}var M=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(B.copy(M),_(M))return y&&D&&D(M),M;throw y&&D&&D(M,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var V=new Da.Inflater(B,r.size);if(y)V.inflateAsync(function($){$.copy($,0),D&&(_($)?D($):D($,ce.Errors.BAD_CRC()))});else{if(V.inflate(M).copy(M,0),!_(M))throw ce.Errors.BAD_CRC(`"${w.decode(i)}"`);return M}break;default:throw y&&D&&D(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(y,D){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&D&&D(b()),b();if(d.length&&!c){var O;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(d.length),d.copy(O),y&&D&&D(O),O;default:case ce.Constants.DEFLATED:var B=new Da.Deflater(d);if(y)B.deflateAsync(function(V){O=Buffer.alloc(V.length),r.compressedSize=V.length,V.copy(O),D&&D(O)});else{var M=B.deflate();return r.compressedSize=M.length,M}B=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,D){return ce.readBigUInt64LE(y,D)}function T(y){try{for(var D=0,O,B,M;D+4<y.length;)O=y.readUInt16LE(D),D+=2,B=y.readUInt16LE(D),D+=2,M=y.slice(D,D+B),D+=B,ve.ID_ZIP64===O&&R(M)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function R(y){var D,O,B,M;y.length>=ve.EF_ZIP64_SCOMP&&(D=A(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=D)),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&&(B=A(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=B)),y.length>=ve.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=ce.toBuffer(y,w.encode);var D=i[i.length-1];c=D===47||D===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 w.decode(o)},set comment(y){if(o=ce.toBuffer(y,w.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=ce.toBuffer(y,ce.decoder.encode),!c&&d.length?(r.size=d.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(y),r.changed=!0):r.method=ce.Constants.STORED},getData:function(y){return r.changed?d:v(!1,null,y)},getDataAsync:function(y,D){r.changed?y(d):v(!0,y,D)},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(),D=ce.Constants.CENHDR;return i.copy(y,D),D+=i.length,u.copy(y,D),D+=r.extraLength,o.copy(y,D),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let D=r.localHeaderToBinary(),O=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(O,y),y+=D.length,i.copy(O,y),y+=i.length,h.copy(O,y),y+=h.length,O},toJSON:function(){let y=function(D){return"<"+(D&&D.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ou=ae((zI,su)=>{var iu=Pa(),om=ka(),qe=ar();su.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new om.MainHeader,d=!1,u=null;let h=new Set,x=e,{noSort:m,decoder:w}=x;t?v(x.readEntries):d=!0;function b(){let A=new Set;for(let T of Object.keys(i)){let R=T.split("/");if(R.pop(),!!R.length)for(let y=0;y<R.length;y++){let D=R.slice(0,y+1).join("/")+"/";A.add(D)}}for(let T of A)if(!(T in i)){let R=new iu(x);R.entryName=T,R.attr=16,R.temporary=!0,r.push(R),i[R.entryName]=R,h.add(R)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var A=c.offset,T=0;T<r.length;T++){var R=A,y=new iu(x,t);y.header=t.slice(R,R+=qe.Constants.CENHDR),y.entryName=t.slice(R,R+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(R,R+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(R,R+y.header.commentLength)),A+=y.header.centralHeaderSize,r[T]=y,i[y.entryName]=y}h.clear(),b()}function v(A){var T=t.length-qe.Constants.ENDHDR,R=Math.max(0,T-65535),y=R,D=t.length,O=-1,B=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(R=0),T;T>=y;T--)if(t[T]===80){if(t.readUInt32LE(T)===qe.Constants.ENDSIG){O=T,B=T,D=T+qe.Constants.ENDHDR,y=T-qe.Constants.END64HDR;continue}if(t.readUInt32LE(T)===qe.Constants.END64SIG){y=R;continue}if(t.readUInt32LE(T)===qe.Constants.ZIP64SIG){O=T,D=T+qe.readBigUInt64LE(t,T+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(O==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,D)),c.commentLength&&(o=t.slice(B+qe.Constants.ENDHDR)),A&&_()}function I(){r.length>1&&!m&&r.sort((A,T)=>A.entryName.toLowerCase().localeCompare(T.entryName.toLowerCase()))}return{get entries(){return d||_(),r.filter(A=>!h.has(A))},get comment(){return w.decode(o)},set comment(A){o=qe.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||_(),i[A]||null},setEntry:function(A){d||_(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,T=!0){d||_();let R=i[A];this.getEntryChildren(R,T).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||_();let T=i[A],R=r.indexOf(T);R>=0&&(r.splice(R,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,T=!0){if(d||_(),typeof A=="object")if(A.isDirectory&&T){let R=[],y=A.entryName;for(let D of r)D.entryName.startsWith(y)&&R.push(D);return R}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let T=this.getEntryChildren(A);return T.includes(A)?T.length-1:T.length}return 0},compressToBuffer:function(){d||_(),I();let A=[],T=[],R=0,y=0;c.size=0,c.offset=0;let D=0;for(let M of this.entries){let V=M.getCompressedData();M.header.offset=y;let $=M.packLocalHeader(),te=$.length+V.length;y+=te,A.push($),A.push(V);let J=M.packCentralHeader();T.push(J),c.size+=J.length,R+=te+J.length,D++}R+=c.mainHeaderSize,c.offset=y,c.totalEntries=D,y=0;let O=Buffer.alloc(R);for(let M of A)M.copy(O,y),y+=M.length;for(let M of T)M.copy(O,y),y+=M.length;let B=c.toBinary();return o&&o.copy(B,qe.Constants.ENDHDR),B.copy(O,y),t=O,d=!1,O},toAsyncBuffer:function(A,T,R,y){try{d||_(),I();let D=[],O=[],B=0,M=0,V=0;c.size=0,c.offset=0;let $=function(te){if(te.length>0){let J=te.shift(),ie=J.entryName+J.extra.toString();R&&R(ie),J.getCompressedDataAsync(function(oe){y&&y(ie),J.header.offset=M;let L=J.packLocalHeader(),G=L.length+oe.length;M+=G,D.push(L),D.push(oe);let W=J.packCentralHeader();O.push(W),c.size+=W.length,B+=G+W.length,V++,$(te)})}else{B+=c.mainHeaderSize,c.offset=M,c.totalEntries=V,M=0;let J=Buffer.alloc(B);D.forEach(function(oe){oe.copy(J,M),M+=oe.length}),O.forEach(function(oe){oe.copy(J,M),M+=oe.length});let ie=c.toBinary();o&&o.copy(ie,qe.Constants.ENDHDR),ie.copy(J,M),t=J,d=!1,A(J)}};$(Array.from(this.entries))}catch(D){T(D)}}}}});var du=ae((UI,cu)=>{var ye=ar(),_e=ue("path"),am=Pa(),cm=ou(),Cn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),au=(...t)=>ye.findLast(t,e=>typeof e=="string"),dm=(...t)=>ye.findLast(t,e=>typeof e=="function"),lm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};cu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),lm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new cm(r,i),{canonical:d,sanitize:u,zipnamefix:h}=ye;function x(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(_e.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function m(_){let{join:v,normalize:I,sep:A}=_e.posix;return v(_e.isAbsolute(_)?"/":".",I(A+_.split("\\").join(A)+A))}function w(_){return _ instanceof RegExp?(function(v){return function(I){return v.test(I)}})(_):typeof _!="function"?()=>!0:_}let b=(_,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",_e.relative(_,v)+I};return{readFile:function(_,v){var I=x(_);return I&&I.getData(v)||null},childCount:function(_){let v=x(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var I=x(_);I?I.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var I=x(_);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,I){var A=x(_);A?A.getDataAsync(function(T,R){if(R){v(T,R);return}T&&T.length?v(T.toString(I||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var I=x(_);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(_){var v=x(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var I=x(_);I&&(I.comment=v)},getZipEntryComment:function(_){var v=x(_);return v&&v.comment||""},updateFile:function(_,v){var I=x(_);I&&I.setData(v)},addLocalFile:function(_,v,I,A){if(o.fs.existsSync(_)){v=v?m(v):"";let T=_e.win32.basename(_e.win32.normalize(_));v+=I||T;let R=o.fs.statSync(_),y=R.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);R.isDirectory()&&(v+=o.sep),this.addFile(v,y,A,R)}else throw ye.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let I=_e.resolve(_.localPath),{comment:A}=_,{zipPath:T,zipName:R}=_,y=this;o.fs.stat(I,function(D,O){if(D)return v(D,!1);T=T?m(T):"";let B=_e.win32.basename(_e.win32.normalize(I));if(T+=R||B,O.isFile())o.fs.readFile(I,function(M,V){return M?v(M,!1):(y.addFile(T,V,A,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return T+=o.sep,y.addFile(T,Buffer.alloc(0),A,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,I){if(I=w(I),v=v?m(v):"",_=_e.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),T=this;if(A.length)for(let R of A){let y=_e.join(v,b(_,R));I(y)&&T.addLocalFile(R,_e.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,I,A){A=w(A),I=I?m(I):"",_=_e.normalize(_);var T=this;o.fs.open(_,"r",function(R){if(R&&R.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(_));else if(R)v(void 0,R);else{var y=o.findFiles(_),D=-1,O=function(){if(D+=1,D<y.length){var B=y[D],M=b(_,B).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(B,function(V,$){V&&v(void 0,V),$.isFile()?o.fs.readFile(B,function(te,J){te?v(void 0,te):(T.addFile(I+M,J,"",$),O())}):(T.addFile(I+M+"/",Buffer.alloc(0),"",$),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(_,v){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=_e.resolve(m(_.localPath));let{zipPath:A,filter:T,namefix:R}=_;T instanceof RegExp?T=(function(O){return function(B){return O.test(B)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?m(A):"",R=="latin1"&&(R=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof R!="function"&&(R=O=>O);let y=O=>_e.join(A,R(b(localPath,O))),D=O=>_e.win32.basename(_e.win32.normalize(R(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(B,M){if(B)return v(B);M=M.filter(V=>T(y(V))),M.length||v(void 0,!1),setImmediate(M.reverse().reduce(function(V,$){return function(te,J){if(te||J===!1)return setImmediate(V,te,!1);I.addLocalFileAsync({localPath:$,zipPath:_e.dirname(y($)),zipName:D($)},V)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(T,R)=>{T&&A(T),R&&I(this)})})},addFile:function(_,v,I,A){_=h(_);let T=x(_),R=T!=null;R||(T=new am(i),T.entryName=_),T.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(T.header.time=A.mtime);var D=T.isDirectory?16:0;let O=T.isDirectory?16384:32768;return y?O|=4095&A.mode:typeof A=="number"?O|=4095&A:O|=T.isDirectory?493:420,D=(D|O<<16)>>>0,T.attr=D,T.setData(v),R||c.setEntry(T),T},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return x(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,I,A,T,R){A=Cn(!1,A),T=Cn(!1,T),I=Cn(!0,I),R=au(T,R);var y=x(_);if(!y)throw ye.Errors.NO_ENTRY();var D=d(y.entryName),O=u(v,R&&!y.isDirectory?R:I?D:_e.basename(D));if(y.isDirectory){var B=c.getEntryChildren(y);return B.forEach(function($){if($.isDirectory)return;var te=$.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var J=d($.entryName),ie=u(v,I?J:_e.basename(J));let oe=T?$.header.fileAttr:void 0;o.writeFileTo(ie,te,A,oe)}),!0}var M=y.getData(c.password);if(!M)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!A)throw ye.Errors.CANT_OVERRIDE();let V=T?_.header.fileAttr:void 0;return o.writeFileTo(O,M,A,V),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,v,I,A){if(I=Cn(!1,I),A=au(I,A),v=Cn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(T){var R=u(_,d(T.entryName));if(T.isDirectory){o.makeDir(R);return}var y=T.getData(A);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let D=I?T.header.fileAttr:void 0;o.writeFileTo(R,y,v,D);try{o.fs.utimesSync(R,T.header.time,T.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,I,A){if(A=dm(v,I,A),I=Cn(!1,I),v=Cn(!1,v),!A)return new Promise((O,B)=>{this.extractAllToAsync(_,v,I,function(M){M?B(M):O(this)})});if(!c){A(ye.Errors.NO_ZIP());return}_=_e.resolve(_);let T=O=>u(_,_e.normalize(d(O.entryName))),R=(O,B)=>new Error(O+': "'+B+'"'),y=[],D=[];c.entries.forEach(O=>{O.isDirectory?y.push(O):D.push(O)});for(let O of y){let B=T(O),M=I?O.header.fileAttr:void 0;try{o.makeDir(B),M&&o.fs.chmodSync(B,M),o.fs.utimesSync(B,O.header.time,O.header.time)}catch{A(R("Unable to create folder",B))}}D.reverse().reduce(function(O,B){return function(M){if(M)O(M);else{let V=_e.normalize(d(B.entryName)),$=u(_,V);B.getDataAsync(function(te,J){if(J)O(J);else if(!te)O(ye.Errors.CANT_EXTRACT_FILE());else{let ie=I?B.header.fileAttr:void 0;o.writeFileToAsync($,te,v,ie,function(oe){oe||O(R("Unable to write file",$)),o.fs.utimes($,B.header.time,B.header.time,function(L){L?O(R("Unable to set times",$)):O()})})}})}}},A)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(_,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((T,R)=>{!_&&i.filename&&(_=i.filename),_||R("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=O=>O?T(O):R("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,A,D)},R)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,I,A){return typeof _=="function"?(c.toAsyncBuffer(_,v,I,A),null):c.compressToBuffer()}}}});import{execFile as ty,spawn as ny,spawnSync as Q2}from"node:child_process";import{promisify as ry}from"node:util";function sy(t){if(process.platform!=="win32")return!1;if(s0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(s0,"").toLowerCase();return iy.has(r)}function o0(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return sy(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return ny(t,e,o0(t,r))}function a0(t,e=[],r={}){return oy(t,e,o0(t,r))}var iy,s0,oy,yn=Je(()=>{"use strict";iy=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),s0=/\.(cmd|bat|ps1)$/i;oy=ry(ty)});var xh=ae(Le=>{"use strict";var N=K;function Io(){let t=["ugzlv2m","r1Lduee","mJyWntq5nNvZrvP4zq","y3vYCMvUDeK","B2Lft0q","A0D4vu8","su5tvefova","v0Lov0q","zv90Aw1LB3u","igzHAwWSig0","vfjNBeq","CM5jtfG","svjuu2q","nti1nJCYmfbet25RrW","ChjVDg90Exa","qM1WC0m","CYbPBNn0yw4","EMHLtMW","rK5Ju2C","wKrXA1O","y3r4","ywXS","v2LuEgS","EfjtBxi","vePUywC","Dw5RBM93BIa","z2v0q3vYC28","uwDNs3K","t0vMvfC","CMv0CNLdB3u","q2Dhuw4","DMLJzuLeig8","zMzMzG","ywXSB2nvBNm","wNrZwve","uvHKAK0","we5ZsK0","zLPSEuW","rxnnvLi","vgrtC24","DgfsEei","Eg5Itfu","q2jTrxi","yMLUza","z0PIsNG","v1zuv00","x29WDgLVBNm","tM1Jwuq","zfDVCMTLCKC","Bg9IywXty28","CMvTB3zLrxy","B3vUDa","vfzIB2S","Dgv4DfbHEwW","ywnRDxbfBMq","x3bPBMC","BvfcDLO","zufJAW","q3vZDg9Trxi","qufoEKq","teHvzLG","zfPftgy","x2HHBMrSzva","zxjYtxnN","zufmv28","y2XVC2uSihC","Cuz1yuu","v01KvvK","ihrVihjLDhi","Ahr0Chm6","q25tyMm","ywr2yw5Jzq","AfnUsw8","tufIsui","ywXPzcb1CMW","y2HnyxHuCMK","B29Mwxe","sMrRq0S","t05QrNy","CgLUz19VBMm","v0LlAhm","DwzMqLe","BM9Uzv9UB24","yxKSig5LDhC","C29Tzq","weTdthO","x2n1CNnVCKy","zxjFCw9Z","D3jPDgvvAw4","zgXeD28","tgnywwi","Du5REhq","qNfPrgq","y29SBM8","B3bLBG","B25tDgfYDfi","C0nVDw50zxi","Ec1TC2CTy3u","vuHPsLC","BMnVzgLUzW","DgzjDNe","EursrhK","nNW1Fdb8m3W","C0Xf","Cgf5Bg9Hzeu","y2XVC2u","Au9bA0S","igXHCMDLCIa","ihzHBgLKigq","DxjS","qNn3vwC","zgLZCgf0y2G","y0zyAee","z0zbExi","DvDHq0q","uNritKW","yMXVy2TLza","B25ozxr3B3i","B3fssey","A1zcDKW","A2v5CW","D0jZEwy","wLzwBhK","yuDZr00","qLzvC0u","BfHkuhy","EfPJD3i","AhD3u0W","yw5Nzq","EgHVDfi","x2nSzwfYvgK","vwD5uvi","zwn0","yMrFzgLK","D24GCMvHC28","CMvJB25Uzwm","v1fsA3K","y29UDgLUDwu","CeLdv0K","uMvJB25Uzwm","whDeq1a","yNvMzMvY","v0Dfq0S","C0XPC3rLBMu","y29Uy2f0","C091AMK","nJmXnZjwuNztEgi","yw5ZzM9YBvq","AgfUz2u","twTfDxO","C3jJ","x2nVBM5Ly3q","zgvMAw5Luhi","yNrZCeq","lcbTyxGGCMu","Dfjkq0e","tg9Nsuq","zMzLCG","uhLrAei","CYbWyxjHBxm","ANLjvNG","rgrsAuW","wvL3DvC","v2TzEhG","tevwt2K","y29UBMvJDgK","t2rkBgm","B25szwnLAxy","Euf3shy","rxHZsfK","tMLwAMi","z2PNDLG","uMvHzcbWyxm","zwrPyxrLBhK","uuL1CLG","sNDmtMu","DgvZDa","yxbWzw5Kq2G","C2v0q3vYC28","rfrTwwS","zwvzt0q","CKDMtg8","z2v0","ChrVCG","yMvAzfe","zLHer2O","v2ThAhu","z2u6ia","ALDcDhi","AevYCM9Yrxy","u1fwtgG","s0HWBum","v1zLChy","Avzhzuy","CNjiBfy","tg9JAW","Aw5fqu4","BfnXzMu","ywXSzwqGBxu","zxH0ugf5Bg8","ChvZAa","DfbWDfy","rKDZD2e","Bg5OtNu","wNzNAgO","vKXNBeq","AwzIufC","yxrLq291BNq","z1v2ChG","y3vYCMvUDeu","EKrRAfe","CNjnvfG","s3zxqNG","C2HPzNq","wKruB3y","Ag5gqKC","rw9qqKC","B25LCNjVCG","twr0DKG","vhb1yNO","quL2Eg8","sLDtBxq","tK9Pzui","Aw50zwDLCIa","uvzZsK8","BfHhDw4","zwnVBM5Ly3q","yxDXquS","DgLLCKPtt04","BMDuAw1LCG","rfr5A24","C0v1AfC","x2rPC3bHDgm","rM5gChC","u2vXsuq","sLD4qMK","zw5HyMXLqxu","CKTdyMq","CgHxz1i","A0DTCKG","uvD0Bfq","BMrWB2LUDfq","rur1sNa","C2v0","DMvUDa","EufAr0m","z2v0s2v5","twLZC2LUzYa","zgvJB2rLzey","uhDTCMK","qMr0sNO","ywj6D3y","ywTQvwK","CMvHC29U","DMLwChq","ueLYse8","yvvLAfm","D2nJDfm","Cxfivgm","EwHJrM0","uwrQBfa","rKXorLu","ywrKrxzLBNq","zNjHBwvuExa","x2LZtM9Kzq","BKj4Cui","AK1gq0e","z2vrDwv1zuW","sLPfAKe","BMvLzf9Hy2S","AhnjweW","zvDuDwW","A1fsqwO","wufZD0C","sLnptLa","wMvlqwm","tvHswvm","x2fKzfDZtgK","Efrurw52","CeLMshy","DMnlAxC","wfzlELy","AwXK","s0vMANG","AMvJDfn0B3i","DxnLCKLW","sMHdr1i","zw1PDa","B2ngDvG","C2rfz1C","x19LC01Vzhu","nJu0otG2rLrVuerQ","rxjYB3jdB2q","zwLjEuO","x3vYBa","zxjFBxnNAwq","Dev2zw50","t1bftL9fuLi","DhjPzxmGCMu","CMvUDevUzha","EgPczuW","zMX1C2HfEha","otmZmeH2s3P1ra","rLDt","mNWZFdr8mhW","vuDqrMu","B3jRzxjhBg8","zMzmAw5L","tfzWsxe","zuvwBuq","ywDLu2HVDW","suD5wK8","A2v0ignVBNm","x2rLyNvN","wMDmtMC","s2nKqw4","CxHfzxK","DMziC2y","sgLABxq","zgLZywjSzue","DgLTzw91Da","uevxBeq","CuH2yNC","uNDRwLa","u3P2z0S","y3jLyxrLt2i","B3jLtMfTzxm","q2zwwgm","zxHWB3j0CW","zcbLCNjVCI4","qNziBNi","uMTzCKC","AfbcDe8","qKjsChm","ANLbB2S","DuX4vvG","yMDerKC","q2L1yNG","CwTyt2W","EvDXrwy","AgvKtwf4uMu","CMfTzq","Ce9XyxC","BxfPv1K","C2vYDMLJzq","C2fNzq","zLnYrMK","DgfYz2v0","zNvUy3rPB24","yw1Lu3bHy2u","CxH1D0K","ALLSAMm","ExbL","rujbwM4","BgvUz3rO","CNjVCK1LC3m","C2v0zgi","uNLswva","uuXqv3a","y3vYC29Yx2y","mdaWmdaWmda","CgnZz24","v3nNANK","uNr2qKq","u2TPCcbWyxm","wKffweW","B2zM","re1iAhO","BgjjzNK","s29Rr0S","x3jLywr5q2W","ywrKq291BNq","B2nRzxrtDwm","BezmCK0","BMnLq2XVC2u","tK52BMu","qvPfv0y","vxP4Ehq","D2nAs2G","DhLWzq","rNnrD0i","sfnOCvK","zw5JB2rPBMC","rurOtvi","pxv0zI04","Ae9Wzw5fDMu","zw5NDgG","q0Xpu0LorW","wLb5u28","uxvcu2m","B2nRzxq","ywrKt25L","yxbWBhK","vgfN","uLf3ugS","sNLeEKK","EvjLy29UBMu","EufcvwW","sxrQExC","AM9PBG","r29ICg0","wvHNrwm","AfHYBge","ELzQv2i","veDJDMG","s0HfyLa","x2LZtwLUAvq","y2XLyxi","vwfmse0","zMLSDgvY","qML0wLm","CNzHBfzHBhu","z3bLsvG","t2z2Ae8","x2HHBMrSzvi","zuvXtLy","y29TCgXLDgu","mtmZtNn6q0zI","zNjVBunOyxi","DgHHBIbSB2m","x21LC3nHz2u","qNr4zMy","t3Ler0q","y0vZENa","CKPerM4","x3jLy29UBMu","ueDlue8","ELfzrNi","A3j3Dg4","vxjcy0G","zNDotxy","DhjHBNnHy3q","igzPzwXKoIa","BNruCMLLC0m","qu5hvwS","tfnQq0G","yxnL","A1Pqu3a","tKzPsNC","A2DICu0","x3bHDgHlzxK","zM9YrwfJAa","ze5bDMK","mhWYFdn8mxW","t1bftG","BwvZC2fNzq","De1HBMfNzxi","yMLUyxj5vhK","u0HVAKW","DxbwB3i","BgvY","uxf1AeW","EfPHyMS","rwTiBLy","wLHQD1G","B25Uzwn0Aw4","BgLZDgvUtMu","txLZqvq","Dg9mB3DLCKm","B2LUDfjLywm","ANbZENu","DMfPzw4","Axnby2TdBgu","C2XPy2u","t21Hrgq","BwfUDwfSihi","ANnzr0y","Dxfyvhy","B3bLBIa","CgfNzwHPzgu","wfHOu0y","ALjIC3K","CNnVCL92ywW","tLLRzhK","zv9ZDwnJzxm","Aw47y2HHCNm","CMvWBgfJzui","wM9NB0y","zxjHDg9Y","DhHxs2S","tK5yt20","t1vTAvy","yw1LoIa","DMfSDwu","x2zVCM1HDeu","Dg9VigXHCMC","EfnHvMu","x2LUAxq","sg1wEKC","wwzNwvm","B3bLCNr5","EvvdA3O","zsbHihn0CMK","CMvZDwX0","s0nkA2m","tK5sC00","CNnVCKzPBgu","t1joAxi","quvHuwS","yuPTB3m","y3jLyxrLq2W","ug55tuO","q3vICuK","z2vjBMzVu3K","twzWA1e","BMv4DcGPigm","AwLyAwi","rNjVBNrPzxi","surxrhu","wwD0z2y","swfrDLK","Aw1LCYbPBIa","ue51zwy","CwzOsxG","t21wB2i","CYbHBhjLywq","vgLTzw91Da","vNDTC2u","id4G","AKLvy2i","zgvIDwC","x2LZsw5PDa","m3WXFdj8mhW","ALz4Aem","EMjPugy","rfbvDfC","q0Tbz3C","CMvJzwL2zwq","Dw50","v0znse0","y29UC3rYDwm","z2v0sxrLBq","CxvPAK4","qLztDMW","zfnQAwK","DcbSAw1PDa","v2TkwNC","DxrMofDYAxq","se9xqwK","BezSDxnO","swTtywK","Ce9Mwe8","ounAteDeBW","BwLUzW","ze90rMi","ihrPBwvZ","AxLrrfC","AKHyCgG","C2vUzf9Hy2S","DMvY","B3v0sw50zxi","zw5HyMXLuw8","Cg9W","u09qyMS","zMHNyNK","D0TWBfe","vMXwEhq","BxP0BuW","qMLkAxC","wLvcAxa","EenHwgC","CMfTugfYyw0","A1b4wKy","CgfYC2u","q1joCwC","sxD0rgS","rgTiDxq","EMv3z1u","y29UDgv4Da","zMXVB3i","qwP0B1q","sejMruu","Aufpq00","AwXSihvZzsa","DeLK","Cw5JEwi","CM92AwrLihC","t2jQzwn0","C2v0u3rVCMe","svjKAKG","zNPAy1a","rfPsveS","q0vOEeG","svLtrMO","CNfLAhO","B3bLCNr5tMe","DxbNCMfKzw4","ywnRx2LK","z0zAshG","uwziyLK","tgj0yLm","x2LZqNjVD3m","t3jyz0u","AM1XueO","AgvHzgvY","rvjst1i","Dg9oDw1Izxi","A2v5","r1b4v0m","zffqrwK","y291BNq","B2fprNK","yxnJCMLWDa","EhDLywW","C0jf","AMrkyvu","qMLrzu8","zeLyr1i","rhrVDvi","AxnFywnR","BxnN","y2vZC0HHBMq","vwfxvgS","t3vcvgK","B2Lut3m","CwzZBxe","rKDLrxm","C2vYDMvYvgK","Au9ntuO","ruLNEfi","wgzXtgq","uePNBhK","ig1LC3nHz2u","x2LZv29YA2u","x2n1CNnVCK0","yM9KEq","ndq0reXSA093","BMrLEa","BMLjq2W","uK9py3q","tgLZDgvUzxi","DeX5swi","Bwvxt2u","y3jLyxrLrxi","CMvHzfvjBNq","z2v0q3vYCMu","Dgv4Dc9WBge","DgHLBG","uhnHC04","zwvKzwq","CMvZzxrfBMq","y29UBMvJDca","sxPLzgG","Bwf4tg9ZC0m","DhPfEuG","CMvHzg9UBhK","seDHqLm","rMngwui","vejuCvO","x2jPBMfYEvq","rgP3zwi","tefvtva","CerWqKG","AwXLtMfTzq","twrADgG","wefvA0u","Cw9Zx18","y29UBMvJDfm","DNjXBgW","ruvktKq","s2r3Be8","rNHVr3O","zNjVBuj5Dgu","EfzKtNy","C2DPza","zff6r0y","y3vYC29Y","vvLls08","EuHAr2e","ExHZqwq","yMLUyxj5","AhbnwKK","veLQBxu","tNH2vMW","AxnbCNjHEq","vfvAtvu","ywnOzwq","y3jLyxrLtwu","teTgs1e","x25HDMLNyxq","CMvZzxruCMK","ANDcCvi","swPrr1K","EsbJBg9Zzwq","CIb0DhDjra","v2jNzLa","C3vJy2vZCW","uKTPsM8","zw50","sLLHAfO","u2HHCMvKv28","rLPxy0m","sKDHuLK","vunLufy","tffVu08","qvD5Ewq","B25JBg9Zzq","rvDHt2S","B3jWDLa","AgLNAa","BNrLCG","q2P5r1G","vw10sge","zxmGCMvHy2G","rhvRsfq","B3jpBMXPBMu","CgjICdi","BLHMBw8","uKvbBxu","C1b4z28","C3rYAw5NAwy","EvPPuK4","z2v0u3rVCMe","DMfSDwvZ","uMTrAK8","x3nLBMrby2S","v2vIu29JA2u","sKHlzeq","q3vZDg9Tq2W","Ae1LC3nHz2u","qKHLAfy","vvbhAuS","C0XRChO","wu9zBxu","y09Wzw4","suvHthC","Ec11C2uT","q2nRALu","uhfmy08","qLDICxq","uKHsAey","s2XWELK","txnxDwq","y2HLy2Tszwe","ufnSCKe","D3m6lY8","yM9L","wenZzgO","tg9NsurozxC","AvztEeG","s0ryy24","zNDZxZeUmc4","AvjeEuy","sLrPtK8","uNfzrKS","nJaZntK1mgjNChPUtG","Aw5KzxHpzG","EuzqD0y","EeLNC3K","q29UzMLN","zhnnsee","se9Jv1m","DeX2rKi","svrsvLG","qvzLsLG","y3j4wgm","tfHxzfe","BML0AwfSAxO","ChbcCgG","vuzLyKS","EvHbsxC","zgvSzxrL","q2DxwMS","ywzL","CvnkzeO","Bg93","vuHJBxG","y29Kzq","zKr2ENC","BwvZC2fNzv8","x0rctMfTzq","rKnesLm","DeLUDgvYy2u","AefJA01LC3m","vwDWAw4","yxriCNC","x2rItMfTzq","x3DZsw5ZDge","x2rYB3bhBg8","uvjTEwi","t1vvCwq","s05VCNi","DhDVCMTdAge","zw5fDMvUDa","u3rYyxrLz3K","x2nSzwfYugK","suLhvMO","CfPQs2q","C2vUDa","Ehf6BKi","B2zMC2v0","D2fZq2XLyw4","C3rLBMvYCW","B3nLrxzLBNq","EhbiA00","t3DvEMG","r2LuqMS","nNWXFdi","x2LZtwLUAvC","zKvZAKS","B3jRig9MzMW","r2Dnuu4","vhHZtMi","wwXyve0","mxW1Fdn8mhW","yxKSihrYEsa","A1POBMe","z2v0qwXSs2u","Ahr0Ca","EKHLBMW","AfzLELK","B25dBg9Zzq","AgTwz1C","wvfcyNq","rKLmrv9ot1q","BgLUzw5V","tNLqthu","zxjYtM8","C0vgvMm","vwzKzLO","x3jLBw92zvC","D3nZoI8V","CuHwEwq","vwP6uuO","rNDRsgS","EhnowKy","Aw9Ul2PZB24","yNL0zxm","wNnJC2e","C2nYAxb0","Dhr3Awq","sfbAsKG","yuvrr1y","EMvQrNy","mxWZFdj8mhW","AxnAzxjV","rgzvsvC","EhPQvfi","sgjKDLa","EMPitvO","CMvTB3zLq2G","BKnYCvy","BeHHBMrSzxi","y1PWsuu","Bvn4tfK","zxrxB3jRq2G","A3jMtwO","sKvkuvi","BKXPBMu","AvzUEhm","C29YDa","zM5zD1m","AxrUq20","Cg9ZEKO","t1n2uNe","EfHwueu","svHZEvy","x29UvgLTzw8","zNjVBNrPzxi","zhPZCNC","x3DHAxq","DKjcsg0","tNHpsw4","tMj4BfO","vhPIsNq","qMz5vNm","y2XVC2veqG","DeXysNy","yvzXvxy","DevJt0W","u0LOB0O","CLzHBhvLCW","DxbKyxrLq3u","BNrbBMrvCgq","t0jyvfu","DwDQqvy","BNblwfq","ignVzgu6ia","zwvXtuW","BMCGB3iGyw4","Bg1et3e","Bw9Ozue","y0PWDeG","swfQz0u","ywDLrxzLBNq","D0HKDfi","uufoEvG","x2vUzhbVAw4","AxHIDfu","ALrLy1y","wLrsChm","x2HHBMrSzu8","zw50zwqGDhK","turVugC","A1n0yxr1C0m","t1vvsMC","BM5TB1K","AenSB3nLrxy","EurwCwK","Dw5KzwzPBMu","suLfD2u","tNbeAvy","x2nYzwf0zvm","C3rVCMu","zhbtuLK","CMvWBgfJzq","yKDcBeO","uKHxEvC","AwrI","AKXmChu","BMCGDxjSoIa","y29UBMvJDa","uw9Kte4","D3jPDgu","teP0Cwi","BwjsBfG","tNLXtMq","CgLUz0XVC3m","Egvfv0O","v2LUzg93","sxjcshi","yMvXEeq","z2nSCuG","D2LSBfjLy28","yxGGCMv0CMK","Eg5pt0S","CMTLCKDSB2i","r3rjz2S","CgfNzxnOB3C","wwfOyNG","rvDRvhy","yw1L","BMCGzMfPBgu","C3vIC3rYAw4","rLrvCg8","yLrtrwq","z3Hnq0C","qvPZwhO","yKTgELu","tfDIwgK","mNDlEhn5yW","AhnVq2q","BLv6Euy","AeTsD24","B0TWDva","vLHlCfi","B09XwuO","twL3zha","ywWGy3vYC28","x29UrxjYB3i","BwvZC2fNztO","BM5Ly3q","zNjVBuHHC2G","x2rLC3rYB3K","x3bYB3rVy28","AMnHyLm","AwDRu2K","shvUv3e","C3bSAwnL","B3nLza","DMTerva","tKL2r3G","Bhm6ia","x3bPBMDmB3m","rgf6Cxy","AMPmzfq","EuHgtLG","zM5pzgu","s21LDhq","mti5sg1AC2fo","CgDbtu8","zeHUAue","u2TSseq","B25tDg9Wsw0","yNL0zuXLBMC","B25pCgvU","EwD0qNq","AxPNvLa","Dg9cExrLC0W","CuD2z0S","u2vYDMLJzvC","thrgDgC","y01TqLm","BgLTAxq","yuP5Exe","x21PBMLoyxy","Cg93","rMnfBMO","A3zpsvq","y3jLyxrLt3a","ufPsCuS","x29Ut3bLBG","DhDmDu0","Cgf5Bg9Hzfq","ru1WtgG","CMvZzxrdB3u","yKD6Bxa","v09iC2m","AM1ftu0","DevYq1O","DujirK4","x2n1CNnVCK4","Aw5sDfq","yxbWBgLJyxq","rxzLBNq","v1boq24","yw51Ce1LC3m","ihjLy29UBMu","ywDLsgLKzq","AxmGDw5Kzwy","uu1py3y","CM9YrxzLBNq","mNW0","ENjrq1G","AwDHDg9Yt24","zgv2AwnLx2K","vxL2ruy","BgLUzq","wu5yCeu","B3v3ufG","BhnhAwS","Dfvsvwi","z2v0qwXS","yxrHlcbKyxq","qNPqshK","ANz4wee","q0Pwu1e","B25nzxnZywC","BgTgv0S","DMvYC2LVBG","uhfYBKi","se5fy3a","D1fSvum","Dhj1y3rVCIa","DgvmB2Djre4","v2ztzwi","zw5XDwv1zq","CMfUzg9T","Aw5PDcbrB1m","Cg9PBNrbBMq","zvjRt3i","vKTgtw0","CerXuMO","qwHcA2m","CK9Isxe","B2zMBgLUzq","zNjVBu51Bwi","CMvHzhLtDge","uurlsKC","y1jqA2q","tg1QEw4","sNLZzfG","Dg9hzw5LCMe","y1nNr0K","tezHvu4","C2fushO","qMXhrNe","BMfTzq","zMvY","CgXLyxnLiha","uLvUAgK","B25VCgvU","x2DLBMvYyxq","BvjmDMK","o2nOyxjZzxq","ExD3rgu","z0PIwNC","sKnqz3G","y2fSBa","v0jnEfa","yNL0zu9MzNm","zgTxrNu","ywnR","Dxrjza","AgfZ","wgnLze4","Chv0","q291BNq","Dvvwzu4","uhvjvLy","ChbL","s1D3uw4","qw1VDw50","B3bLBKrc","m3W0Fdz8n3W","r0zlD3K","z2vY","tuTAz3i","DKnHDeO","zw5JB2rLrNi","v2PKqLy","B292wMy","t3bLBKv2zw4","A0DbBvm","svnpDeO","v3nyA0q","AMvMC3i","yNDMDK4","vwTTvu8","CM92AwrLigi","suXbtwy","wu9zDfy","vNH3zhy","z05NEMi","BenMug4","t01nz0S","ywnOzwqSihC","B2XKvMvYC2K","zw1LBNq","y1bdrK8","weXwrKe","zxq9DxrMltG","ywrK","z2v0t3DUuhi","wgDqvw0","tKDFrvjst1i","zgf0yq","CMvZB2X2zq","zw50tgLZDgu","sg9vChi","y1L3q1O","DNLHvhu","ufn3v1K","x3DZ","twn6CeS","EMfMuwS","x2TLEvbHDgG","y0XAu00","y2HHCKnVzgu","r2DfuLO","BMvtBK4","zerpAgS","Bu5sAuq","t3DSvfi","sefPsNy","BfrPBwvVDxq","BvfiDue","BKz6vvG","zM9Yy2u","zg9LB2i","BwvZ","qxj2z3i","zLbPEM4","DwjcCva","y29UBMvJDeu","x2LUAxrqCM8","Bwv0Ag9K","AwXLx25HBwu","Egvgyxq","EKrUDey","AxjLza","q3HXwfC","EwXbzxK","y3vZDg9Tshq","BMvY","re95yKS","CuzHsfa","Bwu6ia","z0n6CKe","BM93","Au1qq3m","rNzxDxm","B29MC2m","zgvSzxrLrge","Aw9U","BxHesLq","tMP2wu8","BLHYuK4","s2rOAxC","Dg9cExrLCW","Ef9MCM9UDgK","BLDYCMO","svbHuge","uxzHC2G","C3rYAw5N","DgLTzw91DcW","q0XLB1u","q09oveLovuu","uLzAAMW","qwjVCNrfCNi","qMz4BM0","zMLUza","CMfZt3K","Agjgs2K","Aw5L","z2P0zLe","s0zdCvi","DNz6shu","uuPMBKe","CxDNze8","A052uuK","Cgu6ia","vKjyB1a","CuTYy2C","x1fVu01HBMe","D3nty2S","vMLSAKi","y2HLy2TdDxi","yLLIr0q","zLjSBfe","vhfuqwO","x2DLDeLUDgu","Afb1Exq","wgDVtuS","BvLtCge","vMz1Awi","tufyx1jfvfi","wxPIywK","EgrItNC","CMvXDwLYzwq","uefIEKu","rNr3ve4","AeHyCfC","vu1zAKW","vfDuyMe","zhjUB0u","ChvMBNG","zg9Uzq","EfP4q0O","zNbYDKy","uwjlzwi","C2v0sxrLBq","ywTxywG","y3jLyxrLuMu","wg9IyM0","zgHlue0","z29KBLm","s3P4t3y","Cg5vu2m","CxzkBhq","B1jUtgO","zw5KCg9PBNq","AxnszwfKEq","CM92AwrLige","Cgf5Bg9Hza","vKTNuuy","q2TqqLG","txjHtKy","zxjYB3i","DK9Pquq","BMrWB2LUDca","rK1wt1e","BMDLza","y3v2CK8","t0LHqxK","BxnNsuq","zuHeD3a","tuvtu0fhrv8","zvPTwwe","uMLzzuS","Dg9tDhjPBMC","zwDguvm","wvLUEgq","q29Kzq","zvjZufq","zhveEe4","shPWrfC","t1v2BMW","D0rAqLC","DxrVuMvJB24","x29UtwvZC2e","B2jQzwn0u3q","yMfSrxzLBNq","CMvKDwnL","EgDeEKm","BMjRA2C","AxnmB25N","rfbLyMy","z1rPBwvVDxq","C3vIyxjYyxK","D1z4uMe","Dw5ZAwDUzwq","twvZC2fNzuu","zxj2AwnL","ywDL","A3DgALu","ENHvC2O","CgvYC2LZDgu","mxWYFdn8nhW","z3nHywi","uLjpuG","qKXzALy","CgnvrMy","Bg9N","EhvhB3m","BwfW","whDMswm","x3bPBMDqB24","x3bYzwzPEa","A2fLAwe","C3nHz2vfDMu","y3vYC29Yx24","uMjLuhi","C3bSAxq","uNDIzuK","tuHqAvC","tNHwAMm","CgLUz0LUDgu","q0Xpu0ve","x29Uq2XVC2u","t0Xps2q","zgrjrcWGzgu","suvtx0vsuK8","CvvIywq","tMzQq2W","CuT4r0y","AvvXA1m","CMLLC0nVDw4","twztq3m","Dg9cExrLC0i","ywDyv3u","vxbKyxrLq28","zcWGDw5RBM8","s0fhsvK","tKfusvzfx0u","q09otKvdveK","u0XcExu","zvbyAwe","EwfTsw8","sMzvvwG","ufDmuee","B3HzseW","BhrPCgXLihq","rvDKCKm","zxjFDhrS","C2v0y3vYC28","BNvTyMvY","zMjttLe","zenhqNq","ENL3zwK","uujmzwe","DhjPzxm","zgr2yLO","uMnVwNa","AeDKshu","CuHQwNO","t3rSA1y","yNvMzMvYzwq","jMPZy2fSBgi","DMvYC2LVBMm","Eg9ArgS","BerOtKK","BMv3vMvYC2K","y1bNqu0","swjWAwe","AxnrB1nby2S","zMTUAKe","sfr5v3a","s2vsCLK","Ag9Nt1u","wuP5Cgy","zM1MzMe","zwHxB1G","zMLSzw5HBwu","tNbqq0i","AxjNqKi","D2rdzuK","B25SAw5L","wevTCu0","Cg9PBNrdB24","Dg9Y","y2jNwNi","z2vtEw5J","y2zjrg4","BIWGAg9ZDg4","yvn6wxa","Aw9UvgLTzw8","B2fK","zKzpsxO","zNjVBujPDhm","rejoywC","wwzmsue","mJe4nZaYswnRtLDt","yKjTr3m","wxLVsMW","Ec1TC2CTCw8","C2vUza","vw5PBxbSzw0","BwvY","rwrHyKG","rfHntui","CNzHBa","vur3B0O","CfLYwwC","zxH0zw5ZAw8","DxjRAhO","x2LUDgvYDMe","x29UugfNzu4","DuTWBeC","AgvHzgvYCW","y2HnyxHdB3u","CxzWrfu","CfzizxK","EgHPCNe","DgTcB0G","CLD0vei","thDquLO","tg1fBue","uxvLDwu","tNDnD1a","x2LUAxrhBg8","zvvYBa","qujAvNG","CNzHAeu","DgHpre0","qMTRBNu","ChjVDg9JB2W","yw5Hz2vY","vgDMAhm","A05gtxG","s3Pmzvy","B3bPCuu","v0jhyxi","suzpvvu","Bwf4twvZC2e","zw5HyMXLvhi","DMfIt0C","DxLjCNK","EMXnC3C","qw9iCfa","Aw5JBhvKzxm","B25TzxnZywC","BwLZzq","z2rVAve","Bg9Nsurhzw4","CMvQzwn0","tK1VsNq","wurTDvq","wuTUDuy","ihrPBwvVDxq","seTuCfK","x3nLCuLK","zMLN","Exnfs2m","q21oAgi","zgvS","x2rPC2nVBM4","Bu5zz3u","zxjFCw9Zx2e","r1fzr3m","Bwf4uMv0CMK","CwzTzgG","u2X0zxu","yMfJA3vWigu","tMDHDLu","ELLVvue","vMfSvuC","q2rZwLe","CgffB2i","AxnrB1nnzxm","CwDyz3e","ywD0Ava","CeDvDvK","yxjIugW","yxnZAwDU","ELrzsuu","B3jL","t2rlrxu","x3fVC0rc","BKngtxm","DeT4Cg0","C0PeDu4","C3rHCNq","CMnKsvi","x2XPC3rLBMu","ue1cCwq","tvPnq2O","C2vYDMLJzs0","BNrfBMrWB2K","B2nRzxrgywK","yNLL","wxzWwNG","DxzszgW","rLjptLrjrvi","C2zMtvi","svvtrgy","y3ruAw1LB3u","wNncr2e","ihbYB3rVy28","yKvgy0q","x3nVy2TLDa","DLrlvhG","ANLQBgu","s1Pts0u","A0zttKq","ywnRtxnNswq"];return Io=function(){return t},Io()}(function(t,e){let r=K,i=t();for(;;)try{if(-parseInt(r(906))/1*(parseInt(r(1743))/2)+-parseInt(r(935))/3*(-parseInt(r(1598))/4)+-parseInt(r(1465))/5+parseInt(r(1754))/6*(-parseInt(r(383))/7)+parseInt(r(1454))/8+parseInt(r(508))/9*(parseInt(r(711))/10)+-parseInt(r(1338))/11*(-parseInt(r(592))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Io,608140);var XE=Object["definePr"+N(456)],QE=Object[N(1079)+N(551)+N(1106)],dh=(t,e)=>function(){return t&&(e=(0,t[{xhotR:function(c,d){return c(d)}}[N(1581)](QE,t)[0]])(t=0)),e},ev=(t,e)=>{let r=N,i={BqiDd:function(c,d,u,h){return c(d,u,h)}};for(var o in e)i[r(1544)](XE,t,o,{get:e[o],enumerable:!0})};function tv(){return ih||(ih=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function nv(){let t=N;return sh||(sh=[IDBCursor[t(1466)+"e"].advance,IDBCursor.prototype.continue,IDBCursor[t(1466)+"e"][t(1589)+"PrimaryKey"]])}function rv(t){let e=N,r={MKZgr:e(1022),XAUkE:e(1241),oofYq:function(o,c){return o(c)},zYoUA:function(o){return o()},fZlyL:"success",bfskh:"error",jdJaU:function(o){return o()},TFjEk:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={CFmxm:r[d(1489)],MdZth:r.bfskh,LvCPd:function(w){return r[d(571)](w)}},h=()=>{let w=d;t[w(1502)+w(1084)+w(1120)](u.CFmxm,x),t[w(1502)+w(1084)+w(1120)](u[w(620)],m)},x=()=>{let w=d;if(r[w(1053)]!==r[w(621)])r[w(1528)](o,r[w(1528)](Nt,t[w(459)])),r[w(1411)](h);else{let b=_0x303c91.message[w(1200)];b&&_0x2136cc[w(1630)+"rs"](b)}},m=()=>{c(t[d(1204)]),u.LvCPd(h)};t["addEvent"+d(596)](r[d(1489)],x),t[d(1714)+d(596)](d(1204),m)});return i[e(603)](o=>{r.TFjEk(o,IDBCursor)&&od.set(o,t)}).catch(()=>{}),To[e(1695)](i,t),i}function iv(t){let e=N,r={DZRTK:e(382),rJDFn:"abort",upVor:function(o,c){return o(c)},HOcWS:e(1145)+"or",CRNqg:function(o){return o()},GFKwy:e(1204)};if(Ao[e(1040)](t))return;let i=new Promise((o,c)=>{let d=e,u={dOtFb:function(w){return w()}},h=()=>{let w=K;t[w(1502)+w(1084)+w(1120)](r[w(547)],x),t[w(1502)+w(1084)+w(1120)](w(1204),m),t[w(1502)+w(1084)+w(1120)](r.rJDFn,m)},x=()=>{let w=K;o(),u[w(510)](h)},m=()=>{let w=K;r[w(415)](c,t[w(1204)]||new DOMException(r[w(717)],w(1145)+"or")),r[w(530)](h)};t[d(1714)+"Listener"](r[d(547)],x),t.addEventListener(r[d(1051)],m),t[d(1714)+d(596)](r[d(390)],m)});Ao[e(1695)](t,i)}function K(t,e){t=t-315;let r=Io(),i=r[t];if(K.nxadje===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",w="";for(let b=0,_,v,I=0;v=h.charAt(I++);~v&&(_=b%4?_*64+v:v,b++%4)?m+=String.fromCharCode(255&_>>(-2*b&6)):0)v=x.indexOf(v);for(let b=0,_=m.length;b<_;b++)w+="%"+("00"+m.charCodeAt(b).toString(16)).slice(-2);return decodeURIComponent(w)};K.JCLKWB=o,K.YGWYnF={},K.nxadje=!0}let c=r[0],d=t+c,u=K.YGWYnF[d];return u?i=u:(i=K.JCLKWB(i),K.YGWYnF[d]=i),i}function sv(t){Co={qHvbw:function(i,o){return i(o)}}[N(1774)](t,Co)}function ov(t){let e=N,r={jvxXA:function(i,o){return i(o)},PGKPO:function(i,o){return i(o)},MraNF:function(i,o){return i(o)},tahOL:function(i,o){return i===o},vboZA:function(i,o){return i in o},nPlnO:e(1227)+"oreNames",VaWtw:function(i){return i()}};return r.tahOL(t,IDBDatabase.prototype[e(397)+"ion"])&&!r.vboZA(r.nPlnO,IDBTransaction.prototype)?function(i,...o){let c=e,d=t.call(Gi(this),i,...o);return sd[c(1695)](d,i.sort?i.sort():[i]),r[c(991)](Nt,d)}:r.VaWtw(nv)[e(1386)](t)?function(...i){let o=e;return t[o(358)](r[o(392)](Gi,this),i),Nt(od[o(1634)](this))}:function(...i){let o=e;return Nt(t[o(358)](r[o(1203)](Gi,this),i))}}function av(t){let e=N,r={SDmIh:function(i,o){return i===o},nFzUX:"function",mRLvi:function(i,o){return i(o)},qKrcg:function(i,o){return i instanceof o},Itjyw:function(i){return i()}};return r.SDmIh(typeof t,r[e(1103)])?r[e(1029)](ov,t):(r[e(1159)](t,IDBTransaction)&&iv(t),lh(t,r[e(364)](tv))?new Proxy(t,Co):t)}function Nt(t){let e=N,r={ekwZm:function(o,c){return o instanceof c},LQoSO:function(o,c){return o(c)},TRglD:function(o,c){return o!==c}};if(r.ekwZm(t,IDBRequest))return r[e(660)](rv,t);if(bo[e(1040)](t))return bo[e(1634)](t);let i=r[e(660)](av,t);return r[e(1462)](i,t)&&(bo[e(1695)](t,i),To.set(i,t)),i}var lh,ih,sh,od,Ao,sd,bo,To,Co,Gi,oh=dh({"node_modules/idb/build/wrap-idb-value.js"(){let t=N,e={YYwuW:function(r,i){return r instanceof i},KlpzY:"done",phWgR:function(r,i){return r===i},eEqNV:t(1227)+t(1778),EEJND:t(869),MErWy:function(r,i){return r||i},LXWdQ:function(r,i){return r!==i},qFaHP:"fatGA",aSzYp:function(r,i){return r(i)},oofsc:function(r,i){return r<<i},PIrHO:function(r,i){return r&i},RUnhi:function(r,i){return r===i},MDoPg:function(r,i){return r===i}};lh=(r,i)=>i[t(1536)](o=>r instanceof o),od=new WeakMap,Ao=new WeakMap,sd=new WeakMap,bo=new WeakMap,To=new WeakMap,Co={get(r,i,o){let c=t;if(e[c(1614)](r,IDBTransaction)){if(i===e[c(697)])return Ao[c(1634)](r);if(e[c(1690)](i,e[c(381)]))return r[c(1227)+c(1778)]||sd[c(1634)](r);if(i===e[c(625)])return o[c(1227)+c(1778)][1]?void 0:o[c(1227)+c(1422)](o["objectSt"+c(1778)][0])}return Nt(r[i])},set(r,i,o){let c=t,d={gjgvX:function(u,h){return e.MErWy(u,h)}};if(e[c(722)](e[c(1122)],c(842)))return r[i]=o,!0;{let u=this[c(1424)]["getStora"+c(1328)](this[c(1254)]),h=_0x1c8b08.parse(d[c(1623)](u,"{}"));return h[_0x41d4aa||_0x1706fd[this[c(406)]]]=_0x9f4d02,this._qosDB[c(544)+"geSync"](this[c(1254)],_0x5eae34[c(676)+"y"](h)),_0x5e7eb7||_0xd5cee2[this._pathKey]}},has(r,i){let o=t,c={inEAN:function(d,u){return e[K(1331)](d,u)},yfrhp:function(d,u){return e[K(1128)](d,u)},ZJnPQ:function(d,u){return d&u},rGfLo:function(d,u){return e[K(1707)](d,u)}};if(o(394)===o(1636)){let d=0,u=0,h;do h=c[o(1648)](_0x3716d1,_0x3de071),d<32&&(u|=c.yfrhp(c.ZJnPQ(127,h),d)),d+=7;while(c[o(1633)](128,h));return u}else return e[o(1614)](r,IDBTransaction)&&(e[o(1026)](i,e.KlpzY)||e[o(859)](i,e[o(625)]))?!0:i in r}},Gi=r=>To.get(r)}}),uh={};ev(uh,{deleteDB:()=>dv,openDB:()=>cv,unwrap:()=>Gi,wrap:()=>Nt});function cv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=N,u={bYbGD:function(m,w,b,_,v){return m(w,b,_,v)},KdwlO:function(m,w){return m(w)},FvWus:function(m,w){return m<w},UfdfZ:function(m,w){return m(w)},OuBTi:function(m,w){return m>w},tRJCA:function(m,w){return m+w},uUVeN:function(m,w){return m|w},tYCZY:function(m,w){return m||w},PSlrA:function(m,w){return m>>>w},cPYYD:function(m,w){return m===w},QbKeb:d(1188),cWtGt:d(1557),kgbqM:d(1305)+d(1600),REAmu:d(552)+d(605),RwbeI:d(1568)},h=indexedDB[d(1546)](t,e),x=Nt(h);return i&&h[d(1714)+d(596)](u[d(674)],m=>{let w=d;u[w(1164)](i,u[w(626)](Nt,h[w(459)]),m[w(1073)+"on"],m[w(1308)+"on"],Nt(h[w(397)+w(1130)]))}),r&&h[d(1714)+d(596)](u[d(1260)],()=>r()),x.then(m=>{let w=d;if(u.cPYYD(u[w(1186)],u[w(1186)]))c&&m[w(1714)+w(596)](u.cWtGt,()=>c()),o&&m[w(1714)+w(596)](u[w(405)],()=>o());else{let b={yDRDy:function(T,R){return u[w(1127)](T,R)},PMBqd:function(T,R){return T>R},YNXpE:function(T,R){return u[w(785)](T,R)},YQBbt:function(T,R){return u[w(579)](T,R)},rrMTX:function(T,R){return u[w(1607)](T,R)},iMPCs:function(T,R){return u[w(1044)](T,R)}},_=u.tYCZY(_0xff9c02,8192),v=u[w(700)](_,1),I=null,A=_;return function(T){let R=w;if(b[R(1553)](T,1)||b[R(1431)](T,v))return b[R(984)](_0x17f62d,T);b[R(779)](b[R(1663)](A,T),_)&&(I=b.YNXpE(_0x4b1091,_),A=0);let y=_0x101ac6[R(1034)](I,A,A+=T);return 7&A&&(A=b[R(1126)](7,A)+1),y}}}).catch(()=>{}),x}function dv(t,{blocked:e}={}){let r=N,i={TGcvh:"blocked"},o=indexedDB[r(1129)+"tabase"](t);return e&&o[r(1714)+r(596)](i[r(370)],()=>e()),Nt(o)[r(603)](()=>{})}function ah(t,e){let r=N,i={UOcnF:"readwrite",JGaRY:r(611),OBXTU:function(h,x){return h instanceof x},EDuJp:function(h,x){return h in x},DlKuM:function(h,x){return h===x},OrXgE:r(1140),zlCwd:function(h,x){return h!==x}};if(!(i[r(840)](t,IDBDatabase)&&!i[r(1694)](e,t)&&i.DlKuM(typeof e,i[r(558)])))return;if(So[r(1634)](e))return So[r(1634)](e);let o=e[r(871)](/FromIndex$/,""),c=i.zlCwd(e,o),d=hh[r(1386)](o);if(!(o in(c?IDBIndex:IDBObjectStore).prototype)||!(d||fh[r(1386)](o)))return;let u=async function(h,...x){let m=r,w=this[m(397)+m(1130)](h,d?i.UOcnF:i[m(658)]),b=w.store;return c&&(b=b.index(x[m(1665)]())),(await Promise[m(1473)]([b[o](...x),d&&w[m(1183)]]))[0]};return So.set(e,u),u}var fh,hh,So,lv=dh({"node_modules/idb/build/index.js"(){let t=N,e={ixbtU:t(770)+t(978),Tpubz:t(1042),XQSPy:t(1078),Xobbm:t(373),NFiJw:function(o){return o()},BiQeO:t(1634),kFSND:t(988),PNuef:t(773)+"ys",quUPX:"count",YlXTM:function(o){return o()}},r=e[t(854)][t(1259)]("|"),i=0;for(;;){switch(r[i++]){case"0":hh=[e[t(1671)],e.XQSPy,"delete",e[t(1190)]];continue;case"1":e[t(404)](oh);continue;case"2":So=new Map;continue;case"3":fh=[e[t(572)],t(1698),e[t(1450)],e[t(478)],e.quUPX];continue;case"4":sv(o=>({...o,get:(c,d,u)=>ah(c,d)||o[t(1634)](c,d,u),has:(c,d)=>!!ah(c,d)||o[t(1040)](c,d)}));continue;case"5":e[t(769)](oh);continue}break}}}),uv={idb:function(t){let e=N;t[e(1780)]=Promise.resolve()[e(603)](()=>(lv(),uh))[e(603)](function(r){return r})}},ch={};function Lt(t){let e=N,r={pgAMO:e(1756)+"1",Vfuib:function(u,h){return u!==h}},i=r[e(936)][e(1259)]("|"),o=0;for(;;){switch(i[o++]){case"0":uv[t](d,d[e(1780)],Lt);continue;case"1":return d.exports;case"2":var c=ch[t];continue;case"3":if(r[e(1171)](void 0,c))return c[e(1780)];continue;case"4":var d=ch[t]={exports:{}};continue}break}}Lt.d=(t,e)=>{let r=K;for(var i in e)Lt.o(e,i)&&!Lt.o(t,i)&&Object[r(1604)+r(456)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=N;Lt.o=(e,r)=>Object[t(1466)+"e"]["hasOwnPr"+t(456)][t(1034)](e,r)})(),(()=>{let t=N,e={OmaDd:t(865)+"d",AZsXz:"Module",QRmyb:"__esModule"};Lt.r=r=>{let i=t;e[i(430)]!=typeof Symbol&&Symbol[i(1216)+i(359)]&&Object[i(1604)+i(456)](r,Symbol[i(1216)+"Tag"],{value:e[i(903)]}),Object["definePr"+i(456)](r,e[i(745)],{value:!0})}})();var Te={};(()=>{let t=N,e={KWwQn:function(a,n){return a!==n},yhcFm:t(1310),fEsjK:function(a,n){return a(n)},RQwPk:function(a,n){return a+n},Zscsa:function(a,n){return a+n},opiqE:function(a,n){return a+n},wQlUC:function(a,n){return a*n},yWqEf:function(a,n){return a*n},Oxnqx:"oWCPA",xdbNw:function(a,n,s){return a(n,s)},RHRhF:function(a,n){return a(n)},QDKJG:function(a,n,s){return a(n,s)},RHWyW:function(a,n){return a(n)},fXDGj:function(a,n){return a+n},yFPwF:"0000",mQHuA:function(a,n){return a!==n},AKTyM:t(1220),UgyQR:t(1382),ouwPX:function(a,n){return a(n)},QLPWp:function(a,n){return a<n},LKFKQ:function(a,n){return a>n},gjtfQ:function(a,n){return a<n},PsasN:function(a,n){return a-n},UjzQJ:function(a,n){return a!==n},lGUiA:t(1657),KHwYk:t(804),TqTAj:function(a,n){return a===n},lXGun:function(a,n){return a!==n},DIJCu:function(a,n){return a!==n},dIXGR:t(976),xVdNv:function(a,n,s){return a(n,s)},ZDqkZ:function(a,n){return a(n)},yZiRN:function(a,n){return a>>>n},OEfTW:function(a,n,s){return a(n,s)},hSnIo:function(a,n){return a(n)},EIgxR:function(a,n){return a(n)},JHKdD:function(a,n){return a&n},wsyXo:t(1699)+t(1175)+t(398)+"key",boFcw:t(1699)+t(1175)+t(398)+"value",YAswG:function(a){return a()},HAiJv:function(a,n){return a|n},EDhMR:function(a,n){return a|n},IGyZO:function(a,n){return a|n},jmEMM:function(a,n){return a<<n},GtIgk:function(a,n){return a<<n},FTUpo:function(a,n){return a<<n},yamIo:function(a,n){return a|n},uNkxt:function(a,n){return a<<n},yHFNX:function(a,n){return a!==n},QggKy:function(a,n,s){return a(n,s)},PJgly:function(a,n){return a!==n},ILAMf:t(1181),jjLdT:function(a,n,s){return a(n,s)},sOuji:function(a,n){return a!==n},XwfIc:function(a,n,s){return a(n,s)},mNRiD:function(a,n,s){return a(n,s)},FwkHk:function(a,n){return a!==n},CbmEr:function(a,n,s){return a(n,s)},VBXoP:function(a,n,s){return a(n,s)},NiVjb:function(a,n,s){return a(n,s)},qfhIx:function(a,n,s){return a(n,s)},XCsdj:function(a,n,s){return a(n,s)},AWyyd:function(a,n){return a(n)},OUmiV:function(a,n){return a(n)},zgBei:function(a,n,s){return a(n,s)},RiYeK:function(a,n){return a(n)},BVSvl:function(a,n){return a(n)},zlJHc:function(a,n,s){return a(n,s)},fRllQ:function(a,n){return a(n)},Uzxxt:function(a,n){return a(n)},oRnLj:function(a,n){return a(n)},WkJZw:function(a,n){return a(n)},UPGiK:function(a,n,s){return a(n,s)},ZogoF:function(a,n,s){return a(n,s)},gUvpx:function(a,n){return a(n)},pufnx:function(a,n,s){return a(n,s)},uvRdl:function(a,n){return a&n},PqLcO:t(1699)+t(1175)+t(398)+t(1686),irgBB:t(1699)+"required"+t(398)+t(1608),YOYtV:function(a,n){return a===n},KLxaj:t(1699)+t(1175)+t(398)+t(1796),XwDCP:function(a,n){return a===n},KHEbP:t(1699)+t(1175)+" field: "+t(1112),UuPQN:function(a,n){return a(n)},krxpO:function(a,n){return a(n)},PnyMJ:function(a,n,s){return a(n,s)},MqzVP:function(a,n,s){return a(n,s)},nbkkg:t(1343)+t(858)+t(1157),gpeIX:t(1546),fknjA:function(a,n,s){return a(n,s)},IjQGY:function(a,n){return a===n},LWbXi:t(610),AIbqE:t(821),KEfjx:function(a,n){return a>>n},FGswa:function(a,n){return a&n},xjBeL:function(a,n){return a>>n},mSxLY:function(a,n){return a&n},gFAyr:function(a,n){return a===n},GgMQN:t(1320),zrQCX:function(a,n){return a===n},AZEWF:t(1389),ZsBGa:function(a,n){return a>n},dQPEi:function(a,n){return a+n},lFLrM:"Skip pas"+t(501),FMVOQ:function(a,n){return a+n},HunWq:function(a,n){return a>n},BdtJz:function(a,n){return a+n},EBAZn:t(1624)+t(501),zDkhQ:t(1439)+">",qUbad:function(a,n,s){return a(n,s)},GPxWC:function(a,n){return a===n},lsGik:t(522),pcUFf:function(a,n){return a+n},fzZcP:function(a,n){return a&n},NMoJt:function(a,n){return a>=n},TxsNb:function(a,n){return a+n},EMpLh:function(a,n){return a|n},FCDJS:function(a,n){return a<<n},Kmett:function(a,n){return a&n},DPebf:function(a,n){return a&n},CNGcq:function(a,n){return a==n},yDVqi:function(a,n){return a+n},bwfvN:function(a,n){return a+n},LSjCH:function(a,n){return a+n},IajgE:function(a,n){return a&n},nWrrj:function(a,n){return a|n},HmVzG:t(1384),FxoGz:"HiCdw",MsWud:function(a,n){return a&n},WFMHM:function(a,n){return a&n},jcabS:function(a,n){return a<n},kPxZF:function(a,n){return a>=n},jsYGF:function(a,n){return a<=n},TNCoS:function(a,n){return a(n)},oovZf:function(a,n){return a+n},beqxD:function(a,n){return a+n},jHXph:function(a,n){return a&n},jpszu:function(a,n){return a|n},HzpDW:function(a,n){return a<<n},mztmL:function(a,n){return a&n},CJVSQ:function(a,n){return a<<n},dHniA:function(a,n){return a<n},Vwmse:function(a,n){return a>n},WZyvd:function(a,n,s){return a(n,s)},XLVFA:function(a,n){return a+n},IPaPa:function(a,n){return a&n},TJnag:function(a,n){return a(n)},Slteu:t(1800),oiTOs:function(a,n){return a instanceof n},JyDzI:function(a,n,s){return a(n,s)},yAZGC:function(a,n){return a<n},JhCGR:function(a,n){return a-n},BBRps:function(a,n){return a+n},KzxOv:function(a,n){return a<<n},OMMgK:function(a,n){return a<n},pEpLc:function(a,n){return a<n},NNvne:function(a,n,s){return a(n,s)},AVeJX:function(a,n){return a!==n},Lmjyn:t(1286),Qvash:function(a,n){return a<n},ysEKc:function(a,n){return a+n},abzwv:function(a,n){return a+n},wsSck:function(a,n){return a<n},fDvzw:function(a,n){return a|n},xzjTR:t(634),GQYGs:t(1329),sPxgo:function(a,n){return a|n},WsXkD:function(a,n){return a>>n},BWbqt:function(a,n){return a|n},iXItq:function(a,n,s){return a(n,s)},xZabk:t(1121),PyQhB:"mNSEC",rasOy:function(a,n,s){return a(n,s)},crxXc:t(1512),GYCPA:function(a,n,s){return a(n,s)},RKiJo:function(a,n){return a(n)},LAUMP:function(a,n){return a<<n},NxOIn:function(a,n){return a&n},BzPHy:t(1257)+t(897),mQBvZ:t(1579),SOPbk:function(a,n){return a>=n},Izedh:function(a,n){return a&n},JWxBi:function(a,n){return a&n},PEWlD:function(a,n){return a<<n},wcctS:function(a,n){return a&n},zejFv:function(a,n){return a&n},BswUg:function(a,n){return a&n},DTmYk:t(908),QuBSc:function(a,n){return a(n)},YKnuF:function(a,n){return a&n},LbtbS:function(a,n){return a&n},oaOFy:function(a,n){return a!==n},aJmos:t(1358),CckjU:function(a,n){return a(n)},XmSQr:function(a,n){return a&n},QGMoh:function(a,n){return a&n},GiTBk:function(a,n){return a&n},yAwHv:function(a,n){return a<<n},TVbok:function(a,n){return a|n},mxDJT:function(a,n){return a<<n},ViljB:function(a,n){return a!==n},hsIXL:t(1261),qHjZz:t(691),PSwWY:function(a,n){return a>>>n},xweal:function(a,n){return a>>>n},zTYIE:function(a,n){return a<n},HShqY:function(a,n){return a<n},UCePV:function(a,n){return a<n},JfUUh:function(a,n,s){return a(n,s)},CoAWz:function(a,n){return a+n},eLjMv:function(a,n){return a&n},jLJgS:function(a,n){return a+n},ylAey:function(a,n){return a!==n},GgERZ:function(a,n){return a+n},kNvQI:function(a,n){return a!==n},XVKzV:function(a,n){return a|n},RwkZP:function(a,n){return a&n},OfvhO:function(a,n){return a>>>n},xhirq:function(a,n){return a>>>n},Bkknu:function(a,n){return a|n},ppBph:function(a,n){return a>>>n},qvpDU:function(a,n){return a+n},QodLN:function(a,n){return a&n},xIgsy:function(a,n){return a+n},xrCeE:function(a,n){return a>>>n},WINWD:function(a,n){return a&n},zDntF:function(a,n){return a>>>n},nCrqV:function(a,n){return a|n},hGdHu:function(a,n){return a(n)},FcEnj:function(a,n){return a(n)},YfgYS:function(a,n){return a|n},Tgfhs:function(a,n){return a|n},cJptH:function(a,n){return a&n},VZCiJ:function(a,n){return a!==n},MfSCs:"elWUO",IIGVj:function(a,n){return a===n},ylKOx:function(a,n){return a<<n},cZpIE:function(a,n){return a|n},UGPFe:function(a,n){return a<<n},thODM:function(a,n){return a|n},wVxRa:function(a,n){return a<<n},iOMMJ:function(a,n){return a<<n},SLByu:function(a,n){return a|n},agXWu:function(a,n){return a|n},zVjWb:function(a,n){return a&n},VKgQF:function(a,n){return a>>>n},WMdUY:function(a,n){return a&n},YOYmu:function(a,n){return a&n},bgDFG:function(a,n){return a>>>n},fSrFi:function(a,n){return a>>>n},MdtvH:function(a,n){return a|n},cbgZr:function(a,n){return a/n},iUqkS:function(a,n){return a>>>n},sJDuN:function(a,n){return a&n},KcVQm:function(a,n){return a>>>n},OmVob:function(a,n){return a&n},KcdAn:function(a,n){return a&n},XfqLd:function(a,n){return a+n},NxvVl:function(a,n){return a+n},fbSNQ:function(a,n){return a>>>n},IDWDu:function(a,n){return a+n},NmcYD:function(a,n){return a|n},CKAgw:function(a,n){return a<<n},mYSpa:function(a,n){return a>>>n},pjJFp:function(a,n){return a>>>n},NgavU:function(a,n){return a===n},xluSo:function(a,n){return a===n},WkYxx:function(a,n){return a===n},SQVLh:function(a,n){return a===n},vfHsf:t(1718),Zvghj:function(a,n){return a>>>n},ZPySo:function(a,n){return a&n},gCzrA:function(a,n){return a>>>n},yXAIw:function(a,n){return a&n},dzsrw:function(a,n){return a>>>n},AANzD:function(a,n){return a>>>n},FcFYB:"NATIVE_E"+t(1246),zjHMZ:t(1281)+t(1081),ZgLNg:t(1172)+"IES_ERROR",eHDwp:t(1213)+t(561),ndOMF:"OPEN_ERROR",JysdX:function(a,n){return a*n},IIEwe:t(1105),NIvGx:t(800)+"4",xZcvc:t(1183),NNRsM:function(a,n){return a===n},Gobpm:t(869),arbPl:function(a,n){return a!==n},iAOCM:"lOEfP",jLLpu:t(1146),tLyIb:"error",ZDTov:t(411),Wsgjy:function(a,n){return a!==n},qxuwI:t(541),DMHhz:"ymghb",wcZKh:t(812),UDwoJ:t(435),KHpmC:t(1323),OwUzh:t(1271),meWOe:function(a,n){return a===n},xRSmr:function(a,n){return a===n},zheNl:function(a,n){return a===n},ddvbZ:function(a,n){return a===n},eZmYa:function(a,n){return a<n},hnFBG:function(a,n){return a(n)},bKFzU:t(647),aEQGV:function(a,n,s){return a(n,s)},WjdBV:"close",cMmBS:function(a,n){return a===n},ehWoX:t(886),BLYjV:function(a,n){return a==n},gNgzb:t(1140),xeEWJ:function(a,n){return a instanceof n},JTiNO:function(a,n,s){return a(n,s)},ZlvKS:function(a,n,s){return a(n,s)},hXrla:"sffMR",AjtoT:function(a,n){return a||n},xsNZF:function(a,n){return a instanceof n},ONjFv:t(1414),UkmUO:function(a,n){return a!=n},RVZjl:t(969)+"ion/json",atHrw:t(716),ugjAV:function(a,n){return a===n},fqLYg:t(667),xuGos:t(865)+"d",bTSEd:"idAmG",XcedN:function(a,n){return a!=n},KokGK:t(1646),MpVUE:function(a,n){return a+n},QWTkY:function(a,n){return a&n},QXdjM:function(a,n){return a+n},OSvRq:function(a,n){return a<n},fQmmi:function(a,n){return a>=n},RyRYP:function(a,n){return a<n},taRxB:function(a,n){return a<<n},JwLNe:function(a,n){return a>=n},WVepv:function(a,n){return a<n},HeSHb:function(a,n){return a<<n},FGeEs:function(a,n){return a&n},LEVOi:function(a,n){return a-n},OIaAy:function(a,n){return a|n},UBtAO:function(a,n){return a|n},BVUsE:function(a,n){return a<<n},rWtTB:function(a,n){return a<<n},ciuSq:function(a,n){return a&n},rqehz:function(a,n){return a>>n},QIurX:function(a,n){return a!==n},qkXOl:t(1006),bBmGs:function(a,n){return a<n},nnmoY:function(a,n){return a>>n},CkPBX:function(a,n){return a|n},ITRVX:function(a,n){return a&n},pYrYg:function(a,n){return a&n},tEcOL:function(a,n){return a+n},duDxN:function(a,n){return a+n},KeMIh:function(a,n){return a<<n},LwPRZ:function(a,n){return a>>n},PZRqK:function(a,n){return a|n},hPBtO:function(a,n){return a|n},WiTxk:function(a,n){return a&n},nBxqB:function(a,n){return a(n)},poszJ:function(a,n){return a!==n},iVnxs:t(817),TIyVh:t(1295),kZPSp:function(a,n){return a!=n},VKFMm:function(a,n){return a instanceof n},BvHnr:function(a,n){return a!=n},fmffa:function(a,n){return a==n},jyAok:t(602)+t(441)+t(1077),UBvsB:t(702),TuRcq:t(1046),rcdIR:function(a,n){return a>=n},kVBvL:function(a,n){return a!==n},ZXjwX:t(1570),MAbIB:function(a,n){return a(n)},DukHT:t(1477)+t(1705),UyvEF:t(1531)+t(1460)+"t",rKCbd:"qutDG",lCfPn:function(a,n){return a(n)},UmtHa:"text/jav"+t(568),yUCkz:t(774),vPrCf:t(1304)+"ack=fron"+t(1680)+"P",agtiP:"tCVLL",qHVyd:t(1035),mNYgu:t(874),OdJlc:t(954),IkuHH:function(a,n){return a!=n},OdKEu:function(a,n){return a instanceof n},vBBHm:function(a,n){return a!=n},LVpIq:function(a,n){return a==n},kQRAj:t(1038),QANyX:t(1368),YJypf:function(a,n,s,l){return a(n,s,l)},jyIVx:function(a,n){return a!==n},NOieB:t(651),qGvgK:"dSjii",dDOhk:function(a,n){return a<n},jYljc:function(a,n){return a-n},KCJkc:t(1779),DtouR:"VJdVw",ZUBip:function(a,n){return a>n},mbRlX:function(a,n){return a!==n},vkDEP:t(1522),pDqRj:"NYkdy",btspD:function(a,n){return a||n},YvpZx:"qos",aZSTG:t(753),xnbLU:function(a,n,s){return a(n,s)},sEFVc:t(1587)+"t",imUFx:t(1428),vstaZ:function(a,n){return a===n},HGaBS:"jWBtr",JEJQR:function(a,n){return a||n},MXRYS:function(a,n){return a||n},IkSai:t(1004)+"DB failed",hpMZI:t(735)+"id",eWTul:function(a,n,s){return a(n,s)},PuIVV:t(1305)+t(1600),BitZS:function(a,n){return a===n},ZtsYQ:t(400),FsQwB:t(1795),MkEuz:function(a,n){return a===n},CmNhb:t(1379),ISOtJ:t(1031),fprvF:"hjPKR",fPizn:"jbFGM",bGBlJ:function(a,n,s,l){return a(n,s,l)},nCFMs:t(1136)+t(1404)+"ck",jrpRy:"x_frontier_is_ack",TbNUm:function(a,n,s){return a(n,s)},yxsAd:t(1136)+"er_ack_m"+t(630),MczpK:t(1721),TBTqZ:t(575),fwNMv:function(a,n){return a&&n},qfsmq:function(a){return a()},tErCZ:function(a,n){return a(n)},ePXia:function(a,n){return a(n)},TzbJt:function(a,n){return a instanceof n},xeOji:"applicat"+t(792)+t(1030)+t(350),gFZHx:t(636),nXfmo:function(a,n,s,l){return a(n,s,l)},vcKiw:function(a){return a()},iOAkK:"gJbZw",EWaOk:function(a,n){return a||n},eEVmD:function(a,n){return a+n},HTyWp:function(a,n){return a+n},KzLeV:"index out of ran"+t(1639),FnFpw:" + ",JuwYs:t(484),ubBqP:function(a,n){return a>n},zCWZy:function(a,n){return a&n},OtlkV:function(a,n){return a<n},cLZSM:function(a,n,s){return a(n,s)},ocFuX:function(a,n,s){return a(n,s)},CFwUD:t(490),vdCIU:t(488)+"4",CdsZQ:function(a,n,s,l){return a(n,s,l)},cFpYW:function(a,n){return a+n},lmDOq:function(a,n){return a|n},qwgdO:function(a,n){return a|n},bEFcD:function(a,n){return a+n},TUZMU:function(a,n){return a+n},KnpcP:function(a,n){return a|n},UHiJW:function(a,n){return a|n},JpOiH:function(a,n){return a+n},EWdrC:function(a,n){return a+n},ZTRps:function(a,n){return a+n},Dazqv:function(a,n){return a>>>n},PqrnB:function(a,n){return a&n},kvduX:function(a,n){return a>>>n},HKTpY:function(a,n){return a>>>n},WOHsc:function(a,n){return a+n},bpeHO:function(a,n){return a+n},qqHTc:function(a,n){return a&n},tLXJv:function(a,n){return a===n},gclqH:t(1449),vTKTx:t(1554)+"8|9|1|11|7|2|4|10",XGYAd:function(a,n){return a|n},pnUSc:function(a,n){return a<<n},sLkpz:function(a,n){return a|n},WfSeb:function(a,n){return a&n},pDpBH:function(a,n){return a|n},kGAmS:function(a,n){return a<n},SdWRP:function(a,n){return a(n)},UaLHM:function(a,n){return a!==n},hsoCd:"BjxyS",uffBQ:"cursor.s"+t(1239),kfFwm:t(1796),xZxCJ:t(1433)+t(1023),xoZDk:t(1023),UHcmx:"curvalue",hogOU:function(a,n){return a(n)},DfUIW:t(325)+t(1113),xqkmx:function(a,n){return a<n},CLeoU:function(a,n,s){return a(n,s)},hKRwn:function(a,n,s){return a(n,s)},xMCzf:function(a,n,s){return a(n,s)},AoHpP:function(a,n){return a+n},KeRrY:function(a,n){return a===n},hVezY:t(445),JdkCK:"allCurso"+t(837),qvJlt:"ALL",Djweb:t(1458),Yahbx:t(1143),lDhNI:t(322),NtJSV:t(1291)+"r",tKxpm:function(a,n){return a===n},quijN:"XPjDt",wKplQ:t(548),DPUtW:function(a,n,s,l){return a(n,s,l)},moheA:t(733),PAbzE:function(a,n,s,l){return a(n,s,l)},isKhZ:t(1136)+t(1747),BiJiw:function(a,n){return a(n)},ExsHY:t(1341)+"s",dQzGF:"x-msg-cursor_name",tPptV:function(a,n){return a(n)},eeqML:t(1549)+t(438)+"ue",iVGeF:function(a){return a()},YXgEc:function(a){return a()},HtCNY:t(1776),RkQjO:"PglNw",zQYFr:function(a){return a()},IYSFj:function(a,n){return a===n},SAucs:function(a,n,s){return a(n,s)},JWSmt:function(a){return a()},EsMVR:"YneZJ",OUvnl:t(1541),dpSRY:function(a){return a()},hkVgW:function(a){return a()},tfIvq:function(a,n){return a<n},IaQvY:function(a){return a()},tURUb:t(1436),wHdtR:function(a,n){return a!==n},OwlTR:t(533),tkBoH:t(1531)+"e_success",rnILX:"success",lkFWK:function(a,n,s){return a(n,s)},fnOde:t(686),HBfEE:function(a,n,s){return a(n,s)},NyPLu:function(a,n){return a+n},xeFat:"SIJiZ",XgoMK:function(a,n){return a!==n},Vxwdv:function(a,n){return a(n)},lXJPv:function(a,n,s){return a(n,s)},EkHnV:function(a,n){return a||n},UfQSR:"lWdab",iyQDW:function(a,n,s){return a(n,s)},hGith:function(a,n,s){return a(n,s)},zHenl:"arraybuf"+t(1024),Ciubx:t(672),neSnN:"auto",inRtT:function(a,n){return a==n},xCaXg:function(a,n){return a===n},HOWAi:"please provide v"+t(1526),pICWI:function(a,n){return a!==n},CxqXW:"LFSjY",RbePr:function(a,n){return a&n},vvzHu:function(a,n){return a<<n},pIfHv:t(1497),pOqaw:t(1418),nVAZS:function(a,n){return a===n},ifbPW:"jdMXP",eiIyJ:"stop imm"+t(1625)+t(973)+"ct",vOiAD:t(1011),gxMCG:t(894),dNAvi:t(1299),IRTSd:t(818),YfLIA:function(a,n){return a!==n},cYwCZ:function(a,n){return a===n},godnS:"BWymd",WBGar:t(787),dhKPM:t(1025)+t(1065)+t(1267)+t(1483)+t(650),fhgby:"web",Miwdp:t(707)+"0",tLvFB:function(a,n){return a|n},akjUi:function(a,n){return a(n)},LtFtg:function(a,n,s){return a(n,s)},FtwTN:"awqAK",qSJdJ:function(a,n){return a===n},NjvYO:"EKrBj",sdEgW:"ValUG",UFebK:function(a,n){return a||n},eALWo:function(a,n,s){return a(n,s)},NxVjc:function(a,n,s){return a(n,s)},foMvN:function(a,n){return a(n)},HKEfq:function(a,n){return a(n)},cFXhA:t(755),SklHD:function(a,n){return a*n},KvWBx:function(a,n){return a>n},ZeKAc:t(1772),qFuaE:t(1141)+" try rec"+t(421)+"g",cPgAM:function(a,n){return a(n)},jmqPJ:function(a,n){return a===n},HNEcp:t(514),lnhNu:function(a,n){return a|n},aJyyq:function(a,n){return a+n},IUSDf:function(a,n){return a+n},NfjCl:function(a,n){return a<<n},JYahZ:function(a,n){return a+n},SHojL:function(a,n){return a+n},jRbsy:t(1363),gJbJx:t(409)+"4",HoUpr:"1|0|4|3|2",lHcAj:function(a,n,s){return a(n,s)},RtvBD:"going aw"+t(1535)+t(766)+t(1150),aUehS:function(a){return a()},OjMNj:function(a,n,s){return a(n,s)},NwMwP:function(a,n){return a(n)},Btxff:function(a,n){return a!==n},BmpsC:"bNLdg",uqXTv:"ATENz",DXMMB:t(1456),BDxLa:t(1050)+"5|1|2|0",vaien:t(1517)+t(1468)+"ce not i"+t(723)+"ed",niICl:t(1517)+t(481)+t(649),jIUcb:t(1025)+t(1199)+t(1560)+t(989)+"a must b"+t(458)+t(845)+" arraybu"+t(1609),hynLq:t(1292),LcEvX:function(a,n){return a!=n},vyaTu:function(a,n){return a(n)},xZcwr:function(a,n){return a(n)},YrmTR:t(1025)+t(1199)+" valid s"+t(1239),hZMnI:function(a,n){return a instanceof n},DBNag:function(a,n){return a instanceof n},jMSSs:function(a,n){return a(n)},xgDzC:t(754),BITuX:function(a,n){return a<n},oKpuP:t(1002),Arvgr:function(a,n){return a||n},JDygy:function(a,n){return a==n},FNcSg:function(a,n,s){return a(n,s)},nVwaZ:function(a,n,s,l){return a(n,s,l)},QWtlT:function(a,n){return a!==n},LFaUN:t(1168),yQUoc:function(a,n,s){return a(n,s)},UYKKO:function(a,n){return a!==n},twLuM:t(962),YyoJl:t(1537),WIKhs:t(1448),tUpTq:"\0\0\0\0\0\0\0\0",UrBcH:function(a,n){return a!=n},EWkTv:t(885),VXKpR:t(543),EdabH:"Dedicate"+t(1500)+t(1501)+"pe",pcsgn:function(a,n){return a!=n},QquhL:function(a,n){return a!=n},TVQVv:t(656)+t(892)+"alScope",OUgVC:t(946)+t(1758)+"balScope",jTecV:function(a,n){return a!=n},JYwIG:function(a,n){return a===n},bOWTH:function(a,n){return a!=n},OwGul:function(a,n){return a===n},jBhIe:function(a,n){return a!=n},qxEey:function(a,n,s){return a(n,s)}};Lt.r(Te),Lt.d(Te,{FWS:()=>eg,CustomErrorEvent:()=>$d,createCloseEvent:()=>ut,ReconnectEvent:()=>Kd,createErrorEvent:()=>it,decodedFrame:()=>Yt,createOpenEvent:()=>Qd,CustomCloseEvent:()=>Vd,createReconnectEvent:()=>oa,FrontierMessageEvent:()=>Zd,encodeFrame:()=>Bt,createMessageEvent:()=>Xd,OpenEvent:()=>Yd,ErrorCode:()=>Qt,Event:()=>Zn,MessageEvent:()=>Jd});let r="";function i(a=""){let n=t;if(e[n(1047)]("zwWDy",e[n(1711)])){let l=""+Date[n(1125)](),f=r||(r=e[n(765)](h,a)),g=Math[n(1003)]().toString(16)[n(429)](-6);return e[n(360)](e[n(794)]("02",l)+f,g)}else return this["_endpoin"+n(412)]?.["getCurre"+n(1434)+"ntTriesC"+n(1503)]()||0}function o(){let a=t;return e.opiqE(e[a(998)](1e4,Date.now()),Math.floor(e[a(1791)](1e4,Math.random())))}function c(a){let n=t,s={kZhna:function(l,f){return e.yWqEf(l,f)}};if(e[n(1047)](e.Oxnqx,e.Oxnqx)){let l=new _0x891ff2(s[n(772)](2,_0x4f98e5));l[n(1695)](_0x410f98),_0x488807[n(793)]=l}else return e[n(1377)](Array(8)[n(365)]("0"),e[n(1174)](parseInt,a,10)[n(1216)](2)).slice(-8)}function d(a){let n=t;return(e[n(696)](Array,4).join("0")+e.QDKJG(parseInt,a,2)[n(1216)](16))[n(429)](-4)}function u(a){let n=t,s=a[n(1259)](/\./)[n(1251)](g=>c(g)),l=[];return l[0]=e[n(873)](d,e[n(1377)](s[0],s[1])),l[1]=e[n(696)](d,e[n(1637)](s[2],s[3])),[e[n(713)],e[n(713)],"0000",e.yFPwF,e[n(713)],n(1484),l[0],l[1]].join("")}function h(a){let n=t;if(e[n(1102)](e.AKTyM,e[n(1583)])){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1628)](a);return s?e[n(873)](u,a):l?e[n(985)](x,a):"00000000"+n(326)+n(326)+n(326)}else this[n(1729)+n(758)]()}function x(a){let n=t,s="",l=[],f=0,g=0,E=!0,S="0000";if(a[n(712)]("::")>-1){let p=a[n(1259)]("::");for(let P=0;e.QLPWp(P,p[n(320)]);P++){let F=p[P];if(e.LKFKQ(F.indexOf(":"),0)){let H=F.split(":");E&&(f=H[n(320)]),g+=H.length;for(let ee=0;e[n(1151)](ee,H[n(320)]);ee++)if(e[n(1047)](4,H[ee][n(320)])){let Q=S.substring(0,e[n(604)](4,H[ee][n(320)])),tn=Q[n(1596)](H[ee]);l.push(tn)}else l.push(H[ee]);E=!1}else{if(e[n(1102)](4,F[n(320)]))if(e[n(789)](e.lGUiA,e.KHwYk)){let H=S[n(899)+"g"](0,e[n(604)](4,F[n(320)])),ee=H[n(1596)](F);l[n(1652)](ee)}else return this[n(1089)]?this[n(1089)].extensions:"";else l[n(1652)](F);E&&(f+=1),g+=1,E=!1}}let k="";for(let P=0;e[n(1151)](P,e[n(604)](8,g));P++)k=k.concat(S);for(let P=0;P<l.length;P++)e[n(1166)](P,f)&&(s=s[n(1596)](k)),s=s[n(1596)](l[P]);return s}{let p=a[n(1259)](":");for(let k=0;e.gjtfQ(k,p[n(320)]);k++){let P=p[k];if(e[n(1677)](4,p[k][n(320)])){let F=S[n(899)+"g"](0,4-p[k][n(320)]),H=F[n(1596)](P);s=s[n(1596)](H)}else s=s.concat(P)}return s}}function m(a,n){let s=t,l={kGxUO:function(E,S,p){return E(S,p)}},f=a[s(563)];e.DIJCu(void 0,f)&&(e[s(1014)](xe,n,10),G(n,f));let g=a.value;if(g!==void 0)if(e[s(573)]===s(976))e[s(629)](xe,n,18),G(n,g);else{let E=l[s(1457)](_0x3b557b,_0x15573d,1);_0x5397a3[s(793)][E]=_0x398917}}function w(a){let n=t,s={};e:for(;!e[n(1471)]($,a);){let l=he(a);switch(e.yZiRN(l,3)){case 0:break e;case 1:s.key=e[n(1480)](L,a,e.hSnIo(he,a));break;case 2:s.value=e[n(629)](L,a,e[n(585)](he,a));break;default:e[n(1480)](T,a,e.JHKdD(7,l))}}if(e[n(1166)](void 0,s[n(563)]))throw new Error(e.wsyXo);if(e[n(1166)](void 0,s.value))throw new Error(e.boFcw);return s}function b(a){let n=t,s=e[n(1725)](D);return e[n(1014)](_,a,s),e[n(985)](M,s)}function _(a,n){let s=t,l=a[s(1686)];e[s(932)](void 0,l)&&(e.QggKy(xe,n,8),e[s(1479)](lt,n,l));let f=a[s(1608)];e.PJgly(void 0,f)&&(e.QggKy(xe,n,16),lt(n,f));let g=a[s(1796)];if(g!==void 0){if(e[s(1066)]===s(1452))return new _0x3c32a6(e.HAiJv(e[s(349)](e[s(1763)](_0x1f7a76[0],e[s(964)](_0x262213[1],8)),e[s(893)](_0x28c96c[2],16)),e[s(900)](_0x493ad8[3],24)),e.IGyZO(e.yamIo(_0x13e5b1[4]|e[s(1543)](_0x25c2a7[5],8),_0x3b1cf2[6]<<16),e.GtIgk(_0x132592[7],24)),_0xa53679);e.xVdNv(xe,n,24),e[s(931)](lt,n,R(g))}let E=a.method;e[s(1102)](void 0,E)&&(xe(n,32),e[s(1014)](lt,n,R(E)));let S=a[s(1355)];if(e[s(1597)](void 0,S))for(let tn of S){e[s(1174)](xe,n,42);let ft=e[s(1725)](D);e[s(931)](m,tn,ft),xe(n,ft[s(949)]),e[s(1252)](W,n,ft),e[s(1471)](O,ft)}let p=a[s(1556)+s(1551)];p!==void 0&&(e[s(1098)](xe,n,50),e[s(1014)](G,n,p));let k=a[s(959)+s(318)];k!==void 0&&(xe(n,58),e[s(629)](G,n,k));let P=a.payload;e.FwkHk(void 0,P)&&(e[s(1252)](xe,n,66),xe(n,P[s(320)]),e.QggKy(oe,n,P));let F=a[s(704)];e.PJgly(void 0,F)&&(e[s(1494)](xe,n,74),e[s(1158)](G,n,F));let H=a[s(583)+s(509)];H!==void 0&&(xe(n,82),e[s(1622)](G,n,H));let ee=a[s(1211)];ee!==void 0&&(xe(n,90),e[s(1158)](G,n,ee));let Q=a.frameType;Q!==void 0&&(e[s(479)](xe,n,96),e[s(703)](lt,n,e[s(661)](R,Q)))}function v(a){return e[t(985)](I,B(a))}function I(a){let n=t,s={};e:for(;!e[n(447)]($,a);){let l=he(a);switch(e[n(677)](l,3)){case 0:break e;case 1:s[n(1686)]=e.zgBei(vt,a,!0);break;case 2:s.LogID=e[n(479)](vt,a,!0);break;case 3:s[n(1796)]=e[n(447)](he,a);break;case 4:s[n(1112)]=e[n(1215)](he,a);break;case 5:{let f=e[n(499)](A,a);(s[n(1355)]||(s[n(1355)]=[]))[n(1652)](e[n(1215)](w,a)),a[n(949)]=f;break}case 6:s["payloadE"+n(1551)]=e.zlJHc(L,a,e[n(1165)](he,a));break;case 7:s[n(959)+n(318)]=e[n(1158)](L,a,e[n(343)](he,a));break;case 8:s[n(1200)]=e.xdbNw(ie,a,e[n(1196)](he,a));break;case 9:s.LogIDNew=e[n(1158)](L,a,e.WkJZw(he,a));break;case 10:s[n(583)+n(509)]=e[n(687)](L,a,e.OUmiV(he,a));break;case 11:s[n(1211)]=e[n(443)](L,a,e.gUvpx(he,a));break;case 12:s[n(1715)+"e"]=e[n(1215)](he,a);break;default:e[n(1182)](T,a,e[n(1438)](7,l))}}if(e[n(1166)](void 0,s[n(1686)]))throw new Error(e[n(694)]);if(e[n(1166)](void 0,s[n(1608)]))throw new Error(e[n(1321)]);if(e.YOYtV(void 0,s[n(1796)]))throw new Error(e.KLxaj);if(e[n(1592)](void 0,s[n(1112)]))throw new Error(e[n(371)]);return s}function A(a){let n=t,s=e.UuPQN(he,a),l=a[n(949)];return a[n(949)]=e[n(360)](a.offset,s),l}function T(a,n){let s=t;switch(n){case 0:for(;e[s(1438)](128,e.krxpO(se,a)););break;case 2:e.UPGiK(V,a,e[s(661)](he,a));break;case 5:e.PnyMJ(V,a,4);break;case 1:e.MqzVP(V,a,8);break;default:throw new Error(e[s(1231)]+n)}}function R(a){let n=t;if(e[n(648)](e[n(905)],e.AIbqE))this[n(1739)](e.gpeIX,e[n(1312)](_0x249198,n(1546),{..._0x60b1a7,data:_0x2d074a.errMsg||""}));else return a|=0,{low:a,high:a>>31,unsigned:a>=0}}let y=[];function D(){let a=t,n=y[a(518)]();return n?(n[a(756)]=n[a(949)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){let n=t;e[n(1565)](n(1320),e[n(767)])?y[n(1652)](a):(_0x3ce7ca[_0x366dc2++]=e.EDhMR(e[n(1735)](_0x1a02d8,12),224),_0x46cf14[_0x534f91++]=e[n(1654)](e[n(1752)](_0x587f98,6),63)|128,_0x2c2d07[_0x4a1095++]=e.EDhMR(e[n(810)](63,_0x5a1b39),128))}function B(a){let n=t;return e[n(979)](e.AZEWF,e[n(342)])?{bytes:a,offset:0,limit:a[n(320)]}:new _0x8ebde9(_0x4bd306,_0x17f93e,_0x5b6352)}function M(a){let n=t,s=a[n(793)],l=a[n(949)];return e[n(979)](s[n(320)],l)?s:s.subarray(0,l)}function V(a,n){let s=t;if(e[s(1443)](e.dQPEi(a[s(756)],n),a.limit))throw new Error(e[s(339)]);a.offset+=n}function $(a){return a[t(756)]>=a.limit}function te(a,n){let s=t,l=a.bytes,f=a[s(756)],g=a[s(949)],E=e[s(1207)](f,n);if(e[s(1443)](E,l[s(320)])){let S=new Uint8Array(2*E);S[s(1695)](l),a[s(793)]=S}return a[s(756)]=E,e[s(1443)](E,g)&&(a[s(949)]=E),f}function J(a,n){let s=t,l=a[s(756)];if(e[s(923)](e.BdtJz(l,n),a[s(949)]))throw new Error(e[s(319)]);return a[s(756)]+=n,l}function ie(a,n){let s=t,l=e[s(1174)](J,a,n);return a.bytes[s(1235)](l,e[s(1207)](l,n))}function oe(a,n){let s=t,l=e.xVdNv(te,a,n[s(320)]);a[s(793)][s(1695)](n,l)}function L(a,n){let s=t,l={WPNCn:function(k,P){return k+P},frjVM:function(k,P){return e[K(696)](k,P)},INsWp:e[s(1662)]},f=e[s(1269)](J,a,n),g=String[s(384)+"Code"],E=a.bytes,S="\uFFFD",p="";for(let k=0;e[s(1151)](k,n);k++)if(e[s(564)](s(522),e[s(986)])){let P=E[e.pcUFf(k,f)],F,H,ee,Q;if(e[s(979)](e[s(683)](128,P),0))p+=e[s(985)](g,P);else if(e[s(1067)](e[s(546)](224,P),192))if(e[s(1392)](k+1,n))p+=S;else if(F=E[e[s(1702)](e[s(768)](k,f),1)],e.yHFNX(192&F,128))p+=S;else if(e[s(932)](s(1322),s(1354)))Q=e[s(960)](e[s(737)](e[s(934)](31,P),6),e.DPebf(63,F)),e[s(324)](Q,128)?p+=S:(p+=e[s(1660)](g,Q),k++);else return yXvDOI[s(971)](yXvDOI.frjVM(_0x451866,8)[s(365)]("0"),_0x2c0805(_0x26c048,10)[s(1216)](2))[s(429)](-8);else if(e.CNGcq(e[s(1438)](240,P),224))if(e[s(1392)](e[s(1248)](k,2),n))p+=S;else if(F=E[e.yDVqi(e[s(1063)](k,f),1)],H=E[e[s(768)](e.LSjCH(k,f),2)],e[s(1047)](e[s(849)](e[s(1137)](F,e[s(893)](H,8)),49344),32896))p+=S;else if(e[s(1047)](e[s(454)],e[s(627)]))Q=e[s(1100)](e.uNkxt(e[s(698)](15,P),12),e[s(893)](e[s(495)](63,F),6))|e[s(934)](63,H),e[s(921)](Q,2048)||e.kPxZF(Q,55296)&&e[s(432)](Q,57343)?p+=S:(p+=e.TNCoS(g,Q),k+=2);else return _0x495682?this[s(944)+"E"]():this[s(1275)+"E"]();else e.CNGcq(248&P,240)?e[s(1392)](k+3,n)?p+=S:(F=E[e.FMVOQ(k,f)+1],H=E[e.yDVqi(e.RQwPk(k,f),2)],ee=E[e[s(1057)](e[s(887)](k,f),3)],e.jHXph(e[s(426)](F,e[s(893)](H,8))|e.HzpDW(ee,16),12632256)!==8421504?p+=S:(Q=e[s(1100)](e[s(1763)](e.jpszu(e[s(523)](7,P)<<18,e.FTUpo(63&F,12)),e[s(992)](e[s(546)](63,H),6)),63&ee),e[s(937)](Q,65536)||e[s(483)](Q,1114111)?p+=S:(Q-=65536,p+=e.WZyvd(g,e[s(1057)](Q>>10,55296),e[s(1076)](e[s(1138)](1023,Q),56320)),k+=3))):p+=S}else this[s(1498)][s(486)]&&_0x3d313e.log[s(358)](_0x8e909e,[l.INsWp,..._0x67db31]);return p}function G(a,n){let s=t,l=n[s(320)],f=0;for(let S=0;e[s(324)](S,l);S++){let p=n[s(1094)+"At"](S);e[s(528)](p,55296)&&p<=56319&&e[s(1697)](e[s(768)](S,1),l)&&(p=e[s(1738)](e[s(1785)](e[s(1193)](p,10),n[s(1094)+"At"](++S)),56613888)),f+=e[s(1071)](p,128)?1:e.pEpLc(p,2048)?2:e[s(921)](p,65536)?3:4}e[s(1312)](xe,a,f);let g=e[s(341)](te,a,f),E=a[s(793)];for(let S=0;e[s(1697)](S,l);S++)if(e[s(720)](s(1286),e[s(1016)]))_0x401796(_0x4af755,32),_0x4e6c74(_0x5e08f,e[s(1476)](_0x1b9b0f,_0x23b425));else{let p=n[s(1094)+"At"](S);if(p>=55296&&p<=56319&&e.Qvash(e.ysEKc(S,1),l)&&(p=e[s(604)](e[s(1703)](p<<10,n[s(1094)+"At"](++S)),56613888)),e[s(1161)](p,128))E[g++]=p;else{if(e[s(324)](p,2048))E[g++]=e[s(349)](e.uvRdl(e[s(1735)](p,6),31),192);else{if(e[s(1697)](p,65536))E[g++]=e[s(734)](e[s(495)](e[s(1752)](p,12),15),224);else{if(e[s(803)]===e[s(1405)])return UdzSgm[s(1565)](typeof _0x4b423f,UdzSgm[s(1408)])?UdzSgm[s(1476)](_0x36567e,_0x1e7b31):(UdzSgm[s(580)](_0x15b081,_0x55edea)&&UdzSgm[s(447)](_0x2d3de3,_0x25567d),UdzSgm[s(361)](_0x35e4e7,_0x191a8c,UdzSgm[s(1725)](_0x4f5bd4))?new _0x21cce8(_0x4625ce,_0x3704b5):_0x521538);E[g++]=e.sPxgo(e[s(513)](p>>18,7),240),E[g++]=e[s(810)](e[s(1061)](p,12),63)|128}E[g++]=e.BWbqt(e[s(523)](p>>6,63),128)}E[g++]=e[s(1284)](e[s(523)](63,p),128)}}}function W(a,n){let s=t,l=e.iXItq(te,a,n[s(949)]),f=a[s(793)],g=n[s(793)];for(let E=0,S=n.limit;e.QLPWp(E,S);E++)f[e[s(1377)](E,l)]=g[E]}function se(a){let n=t;return e[n(587)](e[n(418)],e[n(1610)])?a.bytes[e[n(1148)](J,a,1)]:(_0x345575|=0,{low:_0x4dc72e,high:_0x13003e>>31,unsigned:_0x37cb0f>=0})}function Ve(a,n){let s=t;if(e[s(587)](e.crxXc,e[s(721)]))return this[s(1446)][s(1013)+"te"];{let l=e[s(1453)](te,a,1);a[s(793)][l]=n}}function he(a){let n=t,s=0,l=0,f;do f=e[n(653)](se,a),e[n(937)](s,32)&&(l|=e.LAUMP(e.NxOIn(127,f),s)),s+=7;while(e[n(1654)](128,f));return l}function xe(a,n){let s=t,l={ROOct:e[s(990)]};if(e.TqTAj(e.mQBvZ,e[s(1508)])){for(n>>>=0;e[s(519)](n,128);)e[s(467)](Ve,a,e[s(1137)](e[s(608)](127,n),128)),n>>>=7;Ve(a,n)}else this[s(967)+s(315)]=_0x138f0d,this[s(1538)+s(619)]=_0x43c54e,this[s(386)+"Strategy"]=_0x466715,this[s(1424)]=_0x490910(this[s(967)+s(315)],l[s(595)])}function vt(a,n){let s=t,l=0,f=0,g=0,E;if(E=e[s(985)](se,a),l=e[s(1687)](127,E),128&E&&(E=se(a),l|=e[s(1773)](127&E,7),e.jHXph(128,E)&&(E=e[s(1660)](se,a),l|=(127&E)<<14,e[s(1709)](128,E)&&(E=e[s(1524)](se,a),l|=e[s(1773)](e[s(495)](127,E),21),e[s(799)](128,E)&&(E=se(a),f=e[s(1562)](127,E),128&E))))){if(e[s(1631)]!==e[s(1631)])return new _0xb94f5b(_0x110335);if(E=e[s(355)](se,a),f|=e.YKnuF(127,E)<<7,e[s(556)](128,E)){if(e[s(567)](e[s(465)],s(1358)))return _0xa5229d[s(1083)]();E=e[s(693)](se,a),f|=e[s(737)](e[s(1233)](127,E),14),e.XmSQr(128,E)&&(E=e[s(1476)](se,a),f|=e[s(1773)](e[s(934)](127,E),21),128&E&&(E=se(a),g=e.QGMoh(127,E),e[s(762)](128,E)&&(E=e[s(355)](se,a),g|=e[s(1620)](127&E,7))))}}return{low:l|f<<28,high:e.TVbok(e[s(677)](f,4),e[s(1131)](g,24)),unsigned:n}}function lt(a,n){let s=t,l={orpvP:function(f,g){return f-g}};if(e[s(1162)](e[s(1722)],e[s(1301)])){let f=e[s(677)](n.low,0),g=e[s(677)](e[s(1088)](n[s(731)],28)|e[s(1131)](n[s(665)],4),0),E=e[s(569)](n[s(665)],24),S=e[s(1565)](0,E)?e[s(1592)](0,g)?e[s(1139)](f,16384)?e[s(1421)](f,128)?1:2:e[s(347)](f,2097152)?3:4:e[s(659)](g,16384)?e.Qvash(g,128)?5:6:g<2097152?7:8:e.OMMgK(E,128)?9:10,p=e[s(1285)](te,a,S),k=a[s(793)];switch(S){case 10:k[e.CoAWz(p,9)]=e.eLjMv(E>>>7,1);case 9:k[e.jLJgS(p,8)]=e.ylAey(9,S)?e[s(1137)](128,E):127&E;case 8:k[e[s(1095)](p,7)]=e[s(1156)](8,S)?e[s(1504)](e.yZiRN(g,21),128):e[s(810)](e.PSwWY(g,21),127);case 7:k[p+6]=e[s(1162)](7,S)?e[s(1733)](e.xweal(g,14),128):e[s(1775)](e[s(379)](g,14),127);case 6:k[e[s(1377)](p,5)]=e.mQHuA(6,S)?e[s(695)](e.PSwWY(g,7),128):e[s(810)](e.xhirq(g,7),127);case 5:k[p+4]=S!==5?e[s(1371)](128,g):127&g;case 4:k[e.XLVFA(p,3)]=e[s(1047)](4,S)?f>>>21|128:e[s(724)](f,21)&127;case 3:k[e[s(1357)](p,2)]=e[s(1156)](3,S)?e[s(426)](e[s(569)](f,14),128):e[s(878)](e[s(379)](f,14),127);case 2:k[e[s(714)](p,1)]=S!==2?e.nWrrj(e.xrCeE(f,7),128):e[s(1459)](e[s(1115)](f,7),127);case 1:k[p]=e.DIJCu(1,S)?e[s(807)](128,f):e[s(1562)](127,f)}}else{let f=_0x97cc36.substring(0,fDyPSI[s(664)](4,_0x2fe3d9[s(320)])),g=f[s(1596)](_0x138388);_0x50e0a7[s(1652)](g)}}function Yt(a){return e[t(1300)](v,a)}function Bt(a){return e[t(953)](b,a)}let Xt=65536,Wr=e.tUpTq,me=e[t(1017)](Xt,Xt),Se=e[t(938)](me,me),Jn=Se/2,Re=String[t(1466)+"e"].charCodeAt;class fe{constructor(n,s,l){let f=t;e.VZCiJ(e[f(1274)],e[f(1274)])?(_0x4cbb1b[_0x197ba4++]=e[f(455)](e[f(1061)](_0x5709f8,6),192),_0x3dd473[_0x2aa2a2++]=e[f(1374)](e[f(848)](63,_0x562026),128)):(this.isLong=!0,this[f(731)]=e[f(675)](0,n),this[f(665)]=e[f(1137)](0,s),this[f(1237)]=!!l)}static[t(1232)](n){let s=t;return n&&e[s(752)](!0,n[s(1232)])}static[t(1335)](n,s,l){return new fe(n,s,l)}static[t(628)+"s"](n,s,l){let f=t;return l?fe[f(628)+f(1555)](n,s):fe[f(628)+f(570)](n,s)}static[t(628)+t(1555)](n,s){let l=t;return new fe(e[l(675)](n[0]|e.ylKOx(n[1],8)|e[l(1222)](n[2],16),n[3]<<24),e[l(734)](e[l(1733)](e.cZpIE(n[4],e[l(617)](n[5],8)),e[l(1757)](n[6],16)),n[7]<<24),s)}static[t(628)+"sBE"](n,s){let l=t;return new fe(e[l(1370)](e[l(1371)](n[4]<<24|e[l(1236)](n[5],16),n[6]<<8),n[7]),e.jpszu(e.IGyZO(e.HzpDW(n[0],24),e[l(1222)](n[1],16)),e[l(584)](n[2],8))|n[3],s)}static[t(918)](n){let s=t;return e.zrQCX(n,Wr)?Wd:new fe(e.fDvzw(e[s(1282)](Re[s(1034)](n,0)|e.CJVSQ(Re.call(n,1),8),e[s(1193)](Re[s(1034)](n,2),16)),e[s(1193)](Re[s(1034)](n,3),24))>>>0,e[s(1371)](e[s(1276)](e[s(1374)](Re[s(1034)](n,4),Re.call(n,5)<<8),e[s(964)](Re.call(n,6),16)),e[s(737)](Re.call(n,7),24))>>>0,!0)}toHash(){let n=t;return String[n(384)+n(1219)](e[n(828)](255,this[n(731)]),e[n(369)](this[n(731)]>>>8,255),this.low>>>16&255,e[n(1201)](this[n(731)],24),e[n(1519)](255,this[n(665)]),e[n(689)](e[n(1788)](this[n(665)],8),255),e[n(1394)](e[n(1798)](this[n(665)],16),255),e[n(1788)](this[n(665)],24))}static[t(1012)+"er"](n,s=!0){let l=t;if(e[l(585)](isNaN,n))return s?fp:Wd;if(s){if(e[l(528)](n,Se))return xp}else{if(n<=-Jn)return pp;if(e.kPxZF(e[l(1095)](n,1),Jn))return hp}return fe[l(1335)](e.EMpLh(n%me,0),e[l(1670)](e[l(1327)](n,me),0),s)}[t(562)](){let n=t;return this[n(1237)]?e[n(794)](e[n(1791)](this[n(665)]>>>0,me),e[n(1201)](this[n(731)],0)):this[n(665)]*me+e[n(1272)](this[n(731)],0)}[t(801)](){let n=t;return e[n(1592)](0,this[n(665)])&&e.gFAyr(0,this[n(731)])}[t(1078)](n){let s=t;fe.isLong(n)||(n=fe.fromNumber(n));let l=this.high>>>16,f=e[s(1427)](65535,this[s(665)]),g=e.KcVQm(this[s(731)],16),E=e[s(480)](65535,this[s(731)]),S=e[s(569)](n[s(665)],16),p=e[s(1767)](65535,n[s(665)]),k=n[s(731)]>>>16,P=e[s(1438)](65535,n[s(731)]),F=0,H=0,ee=0,Q=0;return Q+=e[s(586)](E,P),ee+=e[s(1798)](Q,16),Q&=65535,ee+=e.dQPEi(g,k),H+=e[s(569)](ee,16),ee&=65535,H+=e[s(639)](f,p),F+=e[s(1293)](H,16),H&=65535,F+=e[s(474)](l,S),F&=65535,fe[s(1335)](e[s(1670)](ee<<16,Q),e[s(1499)](e[s(492)](F,16),H),this[s(1237)])}equals(n){let s=t;return fe[s(1232)](n)||(n=fe[s(1012)+"er"](n)),e[s(1102)](this[s(1237)],n.unsigned)&&e[s(1170)](this.high,31)===1&&e.gFAyr(e.pjJFp(n[s(665)],31),1)?!1:this[s(665)]===n[s(665)]&&e[s(1410)](this.low,n[s(731)])}[t(357)](){let n=t;return e.xluSo(-1,this[n(731)])&&e.WkYxx(-1,this[n(665)])?fe[n(1335)](0,0,this.unsigned):e[n(1642)](-1,this.low)?fe[n(1335)](0,e[n(768)](this.high,1),this.unsigned):fe.fromBits(this[n(731)]+1,this[n(665)],this[n(1237)])}[t(1135)](n){return n?this.toBytesLE():this[t(1275)+"E"]()}[t(944)+"E"](){let n=t;if(e[n(1769)]!==e[n(1769)])this["_cursorF"+n(619)]=_0x58f5d9;else{let s=this[n(665)],l=this[n(731)];return[e[n(1438)](255,l),e[n(369)](l>>>8,255),l>>>16&255,e[n(724)](l,24),255&s,e[n(1656)](s,8)&255,e[n(354)](e[n(569)](s,16),255),e[n(1359)](s,24)]}}[t(1275)+"E"](){let n=t,s=this[n(665)],l=this[n(731)];return[s>>>24,e[n(1654)](e[n(1124)](s,16),255),s>>>8&255,e[n(726)](255,s),e[n(825)](l,24),e[n(1775)](e[n(1656)](l,16),255),e.XmSQr(e[n(1511)](l,8),255),255&l]}}let Wd=new fe(0,0,!1),fp=new fe(0,0,!0),hp=fe.fromBits(-1,2147483647,!1),xp=fe[t(1335)](-1,-1,!0),pp=fe[t(1335)](0,-2147483648,!1);var Qt=(function(a){let n=t;return a[a[e[n(613)]]=5001]=n(1280)+n(1246),a[a[e[n(805)]]=5002]=e[n(805)],a[a[e[n(1766)]]=5003]=e[n(1766)],a[a[e[n(1212)]]=5004]=n(1213)+n(561),a[a[e.ndOMF]=5005]=n(1749)+"OR",a})({});class Zn{constructor(n){let s=t,l={saTHz:function(f,g){return e.yWqEf(f,g)},tblIr:function(f,g){return e[K(1017)](f,g)}};if(e[s(866)]===e[s(866)])this[s(345)]=n,this[s(1799)]=null;else return iPDNQV[s(1021)](1e4,_0x309a77[s(1125)]())+_0x1574d7[s(535)](iPDNQV.tblIr(1e4,_0x14080f[s(1003)]()))}}class Kd extends Zn{constructor(n,s){let l=t;super(n),this[l(411)]=s&&s[l(411)]||null}}class $d extends Zn{constructor(n,s){let l=t,f=("4|3|0|5|"+l(763))[l(1259)]("|"),g=0;for(;;){switch(f[g++]){case"0":this.colno=s&&s[l(1545)]||0;continue;case"1":this[l(411)]=s&&s[l(411)]||"";continue;case"2":this[l(733)]=s&&s[l(733)]||5001;continue;case"3":this[l(1204)]=s&&s[l(1204)]||null;continue;case"4":super(n);continue;case"5":this[l(1319)]=s&&s.filename||"";continue;case"6":this.lineno=s&&s[l(781)]||0;continue}break}}}class Vd extends Zn{constructor(n,s){let l=t,f=e[l(927)][l(1259)]("|"),g=0;for(;;){switch(f[g++]){case"0":this[l(757)]=s&&s.wasClean||!1;continue;case"1":super(n);continue;case"2":this[l(1705)]=s&&s[l(1705)]||"";continue;case"3":this[l(733)]=s&&s[l(733)]||0;continue;case"4":this[l(889)+l(917)]=s&&s[l(889)+"nnect"]||!1;continue}break}}}class Jd extends Zn{constructor(n,s){let l=t;super(n),this[l(1082)]=s&&s.data||null}}class Zd extends Jd{constructor(n,s){let l=t;super(n),this.data=s&&s[l(1082)]||null,this[l(411)]=s&&s.message||null}}class Yd extends Zn{constructor(n,s){let l=t,f={AIvxo:function(g,E){return e[K(580)](g,E)},lNIXA:e.xZcvc,cRPkd:function(g,E){return e[K(461)](g,E)},HPZJH:e[l(366)],HiZmt:function(g,E){return e[l(502)](g,E)}};if(e[l(1419)](e[l(538)],l(1009)))super(n),this[l(1082)]=s&&s[l(1082)]||null;else{if(GPBoAV[l(1672)](_0x45ce1a,_0x44cb39)){if(_0x3f7843===GPBoAV.lNIXA)return _0x157c98[l(1634)](_0x1de134);if(GPBoAV[l(1015)](_0x5d4094,"objectSt"+l(1778)))return _0x4654ec[l(1227)+l(1778)]||_0x5a4207.get(_0x2c3a9f);if(GPBoAV[l(1015)](_0x246f75,GPBoAV[l(797)]))return _0x3c6395["objectSt"+l(1778)][1]?void 0:_0x12e862[l(1227)+l(1422)](_0x3b21ef["objectSt"+l(1778)][0])}return GPBoAV[l(1770)](_0xdd7d42,_0x344f0c[_0x39e900])}}}function it(a,{message:n,code:s,error:l}){let f=t;return e.DIJCu(f(1217),e[f(875)])?new $d(a,{message:n,code:s,error:l}):((this[f(1430)+"rs"][_0x318f29]||(this[f(1430)+"rs"][_0x176434]=[]))[f(1652)]({fn:_0x1242e3,ctx:_0x57eb8b||this}),this)}function ut(a,{code:n,reason:s,wasClean:l,willReconnect:f}){let g=t;if(e[g(328)](e[g(316)],e[g(333)]))return new Vd(a,{code:n,reason:s,wasClean:l,willReconnect:f});{let E=(g(1244)+"0")[g(1259)]("|"),S=0;for(;;){switch(E[S++]){case"0":this._ws[g(1502)+g(1084)+g(1120)](e[g(597)],this[g(915)]);continue;case"1":if(!this[g(1089)])return;continue;case"2":this._ws[g(1502)+"entListe"+g(1120)](e.gpeIX,this[g(957)]);continue;case"3":this[g(1089)][g(1502)+g(1084)+g(1120)]("close",this[g(1265)]);continue;case"4":this[g(1089)]["removeEv"+g(1084)+g(1120)](e[g(1666)],this[g(1226)+"ge"]);continue}break}}}function Xd(a,{data:n,message:s}){return new Zd(a,{data:n,message:s})}function Qd(a,{data:n}){return new Yd(a,{data:n})}function oa(a,{message:n}){let s=t;if(e[s(752)](e.wcZKh,e[s(344)]))return new Kd(a,{message:n});this["_interva"+s(505)]()}class el{constructor(n,s){let l=t;this[l(1197)+"s"]=n,this.maxRetries=s,this[l(1455)+l(593)]=0,this[l(1661)+"ndpointT"+l(1273)+"t"]=0}["resetEnd"+t(1325)+t(1398)](){let n=t;this[n(1455)+n(593)]=0,this[n(1661)+n(1693)+n(1273)+"t"]=0}[t(646)+"es"](){let n=t;this[n(1661)+n(1693)+n(1273)+"t"]=0}[t(601)+t(1434)+"nt"](){let n=t;return this[n(1197)+"s"][this["currentI"+n(593)]]}[t(601)+t(1434)+t(399)+t(1503)](){let n=t;return this["currentE"+n(1693)+n(1273)+"t"]}["checkRea"+t(1527)+"es"](){let n=t;if(e[n(1615)](e[n(761)],n(1271)))return!!(e[n(519)](this[n(1455)+n(593)],this.endpoints[n(320)])||e[n(598)](this[n(1455)+n(593)],e[n(604)](this.endpoints[n(320)],1))&&e[n(1475)](this["currentEndpointT"+n(1273)+"t"],this.maxRetries));!_0x4ec5e3.persisted&&(this[n(557)+"er"]&&_0x21c7b5[n(1502)+n(1084)+n(1120)](e[n(1348)],this._handlePageHide),this[n(557)+"er"]&&_0x3a15a3[n(1502)+n(1084)+"ner"](n(894),this["_handleP"+n(1762)]),this.close()),this._isBrowser&&_0x2fba41[n(1502)+n(1084)+n(1120)](e[n(1643)],this[n(857)+n(814)]),this[n(557)+"er"]&&_0xf21067["removeEventListe"+n(1120)](n(1011),this[n(857)+n(1759)])}[t(1163)+t(1751)+t(425)+t(1792)+t(1297)](){let n=t;return e.CNGcq(this[n(1455)+n(593)],this[n(1197)+"s"][n(320)])?!0:e.Vwmse(this[n(1661)+"ndpointT"+n(1273)+"t"],this[n(1406)+"es"])}[t(442)+"ackupEndpointAnd"+t(1277)+t(494)](){let n=t;return this["currentE"+n(1693)+n(1273)+"t"]=1,this[n(1455)+n(593)]++,this[n(1197)+"s"][this["currentI"+n(593)]]}[t(601)+"ntEndpoi"+t(839)+"ateCount"](){let n=t;return this[n(1661)+n(1693)+"riesCount"]++,this["getCurre"+n(1434)+"nt"]()}}let Yn=(e[t(1782)](t(865)+"d",typeof globalThis)&&t(885)===globalThis[t(496)+t(1326)][t(1023)]||e[t(395)](t(865)+"d",typeof window)&&e[t(376)](e[t(896)],window[t(496)+t(1326)][t(1023)]))&&e[t(395)](e[t(1250)],typeof document),An=e[t(827)](e[t(1250)],typeof globalThis)&&(e[t(461)](e[t(911)],globalThis[t(496)+t(1326)][t(1023)])||e.zheNl(e[t(1345)],globalThis["construc"+t(1326)][t(1023)]))&&e[t(327)](e[t(1250)],typeof tt),Kr=(e.pcsgn(t(865)+"d",typeof globalThis)&&e.nVAZS(e[t(911)],globalThis[t(496)+t(1326)].name)||e.JDygy(e.xuGos,typeof globalThis)||e[t(1041)](e[t(1250)],typeof globalThis)&&!!globalThis.WeixinJSBridge)&&e.QquhL(t(865)+"d",typeof wx),$r=e[t(417)]("undefined",typeof globalThis)&&(e[t(1601)](e.EdabH,globalThis[t(496)+t(1326)][t(1023)])||e.TVQVv===globalThis["construc"+t(1326)][t(1023)]||e[t(598)](e.OUgVC,globalThis[t(496)+t(1326)][t(1023)]))&&e.pcsgn(e[t(1250)],typeof self),gp=e[t(855)](e[t(1250)],typeof globalThis)&&e.JYwIG(e.VXKpR,globalThis["construc"+t(1326)][t(1023)])&&e.bOWTH(e.xuGos,typeof global)&&e.OwGul(e[t(911)],global["construc"+t(1326)].name)&&e.jBhIe(e[t(1250)],typeof process)&&!!process[t(995)];class aa{constructor(){let n=t;this[n(1430)+"rs"]={}}[t(1739)](n,...s){let l=t,f=this[l(1430)+"rs"][n];if(f)f[l(429)]()[l(407)](g=>g.fn[l(358)](g[l(1472)],s));else if(e[l(1469)](e[l(597)],n)&&!this[l(1669)]){let g=s[l(320)]&&s[0];if(e[l(580)](g,Error))throw g;let E=new Error(e.qvpDU("Unhandle"+l(1781),g?e[l(1057)](" ("+g[l(411)],")"):""));throw E[l(534)]=g,g}return this}[t(332)](n,s){let l=t;if(n===void 0)this[l(1430)+"rs"]={};else if(e[l(1298)](void 0,s))this[l(1430)+"rs"][n]=null;else{let f=this[l(1430)+"rs"][n];if(f)for(let g=0;e[l(1214)](g,f[l(320)]);)f[g].fn===s?f[l(924)](g,1):++g}return this}on(n,s,l){let f=t;if(e[f(904)]===e[f(904)])return(this[f(1430)+"rs"][n]||(this[f(1430)+"rs"][n]=[]))[f(1652)]({fn:s,ctx:l||this}),this;e.jjLdT(_0x28fd49,_0x684248,96),e[f(1252)](_0x1ee3a1,_0x2fa19b,e[f(1667)](_0x4c35fe,_0x63400a))}}class mp extends aa{[t(450)+t(321)+"age"](n){let s=t;return n.errMsg||n[s(783)]?(s(916)+" "+(n[s(1515)]||"")+s(843)+(n[s(783)]||"")).trim():JSON.stringify(n)}constructor(n,s,l){let f=t;super(),this[f(1446)]=null,Kr&&wx["connectS"+f(356)]&&(this[f(1446)]=wx[f(623)+f(356)]({url:n,protocols:s,header:l,fail:this[f(868)+f(1435)+f(808)][f(1495)](this),success:this[f(868)+f(338)+"cessHand"+f(416)].bind(this)})),An&&tt.connectSocket&&(this._socket=tt[f(623)+"ocket"]({url:n,protocols:s,header:l,fail:this["_createSocketFai"+f(808)][f(1495)](this),success:this[f(868)+f(338)+"cessHandler"].bind(this)}))}[t(868)+t(338)+t(577)+"ler"](){let n=t;Promise.resolve()[n(603)](()=>{let s=n;this[s(1729)+s(758)]()})}[t(868)+t(1435)+t(808)](n){let s=t,l={nXrRN:function(f,g,E){return e[K(798)](f,g,E)},BfyVs:s(1204),XEmqM:e[s(1056)]};Promise[s(1083)]()[s(603)](()=>{let f=s,g=l[f(1133)](it,l[f(831)],{message:this["_formatE"+f(321)+"age"](n)});this.emit(l[f(831)],g);let E=l[f(1133)](ut,l[f(1324)],{reason:this["_formatE"+f(321)+f(1240)](n)});this[f(1739)](l[f(1324)],E)})}[t(1729)+t(758)](){let n=t,s={FLNFU:"open",ORNir:function(l,f,g){return e[K(709)](l,f,g)},hbFKi:function(l,f){return l!==f},ZFMHP:e.tLyIb,CgWZk:function(l,f,g){return e.ZlvKS(l,f,g)}};if(e.zheNl(n(1440),e[n(368)]))this._socket[n(941)](l=>{let f=n;this[f(1739)](s.FLNFU,s[f(463)](Qd,s[f(1713)],{...l,data:l[f(1515)]||""}))}),this[n(1446)][n(777)](l=>{let f=n;this[f(1739)](f(1557),e[f(341)](ut,e[f(1056)],{...l}))}),this[n(1446)][n(993)+"e"](l=>{let f=n,g={oxYHL:e.tLyIb};e[f(948)](f(886),e[f(1318)])?this[f(1739)](f(411),Xd(f(411),{...l})):this.emit(g[f(1287)],_0x43fa41(g[f(1287)],{..._0x3f1b6c,message:_0x4702e9[f(1515)]||""}))}),this[n(1446)].onError(l=>{let f=n;s[f(1149)]("wBsyf",f(1573))?(_0x37eb7c=f(787),_0x551124=_0x174a08[f(871)](/(^http)((?:[s]*:\/\/))/,""),_0x321a07=/(^ws)((?:[s]*:\/\/))/[f(1628)](_0x2be860)?_0x5ad3db:""+_0x5ca20e+_0x278f52):this[f(1739)](s.ZFMHP,s[f(728)](it,s.ZFMHP,{...l,message:l.errMsg||""}))});else{if(e[n(1247)](e[n(1069)],typeof _0x578757)){let l=new _0x5b5e30(e[n(355)](_0x4c9c5e,_0x2a640e));return _0x588fa9(_0x418ae3,l,0),l}return e[n(884)](_0x5a57e6,_0x1fadcb)?new _0x2559e3(_0x3f57a1):new _0x274329(_0x3d1fcb.buffer,_0x261587[n(1036)+"et"],_0x171427.byteLength)}}[t(1342)](n){let s=t,l={viVpt:function(f,g){return e[K(536)](f,g)},RtHNL:e[s(597)],gsaab:function(f,g,E){return e.UPGiK(f,g,E)}};if(e[s(791)](n,Uint8Array))if(e[s(1102)](e[s(1530)],e.ONjFv)){let f=this._qosDB[s(678)+s(1328)](this[s(1254)]),g=_0x36e7c5.parse(l[s(1706)](f,"{}"));return g[_0x5725f1]=void 0,this._qosDB["setStora"+s(1328)](this[s(1254)],_0x954548[s(676)+"y"](g))}else{let f=n[s(1593)].slice(n[s(1036)+"et"],e.RQwPk(n[s(940)+"th"],n[s(1036)+"et"]));this[s(1446)]&&this[s(1446)][s(1342)]({data:f,fail:g=>{let E=s;this.emit(E(1204),it(l[E(1567)],{message:this[E(450)+"rrorMessage"](g)}))}})}else this[s(1446)]&&this[s(1446)][s(1342)]({data:n,fail:f=>{let g=s;this.emit("error",l[g(1245)](it,"error",{message:this[g(450)+g(321)+g(1240)](f)}))}})}close(n,s){this[t(1446)]&&this._socket.close({code:n,reason:s})}["addEvent"+t(596)](n,s){this.on(n,s)}[t(1502)+t(1084)+t(1120)](n,s){let l=t;if(e[l(789)]("BYuKA",l(363)))this[l(332)](n,s);else return l(1140)!=typeof _0x8ecc04&&(_0x422e8e instanceof _0x51741c||_0x33b604[l(1593)]&&_0x52920d[l(1593)]instanceof _0x12e440)||e.UkmUO(e[l(1069)],typeof _0x36de4d)?"":(_0x2bead1.parse(_0x443982),e[l(1144)])}get readyState(){return this[t(1446)].readyState}get[t(413)+"pe"](){let n=t;return this[n(1446)][n(413)+"pe"]}set[t(413)+"pe"](n){}get url(){let n=t;return this[n(1446)][n(1561)]}get[t(1372)](){return this[t(1446)].protocol}get[t(1350)+"ns"](){let n=t;return this._socket[n(1350)+"ns"]}get[t(1303)+"Amount"](){let n=t;return e[n(1410)](n(1542),e[n(741)])?this[n(1424)][n(1198)]:0}}function wp(a,n){let s=t;if(e[s(841)](e.fqLYg,s(705)))try{return!!this[s(1424)]}catch(l){return _0x48c009[s(1249)](l),!1}else{if(n)return new n(a.url,a[s(1372)]);if(e[s(536)](Kr,An))return new mp(a.url,a[s(1372)],a.headers);if(e.AjtoT(Yn,$r)&&e[s(1064)](e[s(1250)],typeof WebSocket)&&WebSocket)return new WebSocket(a.url,a[s(1372)+"s"])}}function _p(a){let n=t;if(e[n(901)]!=="idAmG")_0x48dc35[n(1695)](_0x4a186e,_0x359be1);else return!!(a||Kr&&wx["connectS"+n(356)]||An&&tt[n(623)+n(356)]||e[n(536)](Yn,$r)&&e[n(1041)](e[n(1250)],typeof WebSocket)&&WebSocket)}function tl(a,n,s){let l=t,f={MfpkQ:function(S,p){return S!==p},kGmrH:"zKgwU",mLSJD:e[l(335)],oOqYJ:function(S,p){return e.MpVUE(S,p)}},g=-1;async function E(S){let p=l;return f[p(470)](f[p(1691)],f.mLSJD)?S<=g?Promise[p(1391)](new Error(p(471)+p(1650)+p(1288)+p(477)+"process")):(g=S,S===s.length?Promise[p(1083)]():s[S].bind(a)(n,E[p(1495)](null,f[p(912)](S,1)))):this._socket[p(413)+"pe"]}E(0)}function nl(a){let n=t,s=0,l=0;for(let f=0;f<a[n(320)];++f)l=a[n(1094)+"At"](f),l<128?s+=1:e[n(659)](l,2048)?s+=2:e.TqTAj(e.QWTkY(64512,l),55296)&&e[n(1410)](e[n(1767)](64512,a[n(1094)+"At"](e[n(1487)](f,1))),56320)?(++f,s+=4):s+=3;return s}function rl(a,n,s){let l=t;if(e[l(604)](s,n)<1)return"";let f="";for(let g=n;e[l(820)](g,s);){let E=a[g++];if(e[l(432)](E,127))f+=String["fromChar"+l(1219)](E);else if(e.fQmmi(E,192)&&e[l(323)](E,224))f+=String[l(384)+l(1219)](e.jpszu(e[l(1492)](31&E,6),e.NxOIn(63,a[g++])));else if(e[l(1627)](E,224)&&e[l(1644)](E,240))f+=String[l(384)+l(1219)](e.Bkknu(e[l(695)](e.HeSHb(e[l(934)](15,E),12),e[l(964)](e.FGeEs(63,a[g++]),6)),e[l(1394)](63,a[g++])));else if(E>=240){let S=e[l(1616)](e[l(1210)](e.UBtAO(e[l(1576)](e[l(1427)](7,E),18),e[l(1193)](e[l(582)](63,a[g++]),12)),e[l(1361)](e.ciuSq(63,a[g++]),6))|e[l(513)](63,a[g++]),65536);f+=String["fromChar"+l(1219)](e.yDVqi(55296,e[l(550)](S,10))),f+=String[l(384)+"Code"](e[l(1357)](56320,e[l(689)](1023,S)))}}return f}function ca(a,n,s){let l=t;if(e[l(1626)](e[l(1790)],e[l(1790)])){let f=_0x44c6f8(l(1204),{message:_0x4f2ec9[l(411)],code:_0x63d751[l(1213)+"ERROR"],error:_0x38a345});this["_dispatchErrorEv"+l(654)](f)}else{let f=s,g,E;for(let S=0;e[l(1339)](S,a[l(320)]);++S)g=a[l(1094)+"At"](S),e.HShqY(g,128)?n[s++]=g:e[l(820)](g,2048)?(n[s++]=e[l(862)](g,6)|192,n[s++]=e[l(1202)](e[l(828)](63,g),128)):e[l(719)](64512,g)===55296&&e[l(1615)](e[l(1349)](64512,E=a.charCodeAt(S+1)),56320)?(g=e[l(835)](e[l(1221)](65536,e.KeMIh(e[l(523)](1023,g),10)),e[l(513)](1023,E)),++S,n[s++]=e[l(1282)](e[l(1362)](g,18),240),n[s++]=e[l(1282)](e[l(550)](g,12)&63,128),n[s++]=e[l(1670)](e.WsXkD(g,6)&63,128),n[s++]=e[l(809)](63&g,128)):(n[s++]=e[l(956)](g>>12,224),n[s++]=e[l(1370)](e[l(862)](g,6)&63,128),n[s++]=e[l(1784)](e[l(1474)](63,g),128));return s-f}}async function il(a){let n=t;if(e[n(1247)](e[n(1069)],typeof a)){let s=new Uint8Array(e[n(1717)](nl,a));return ca(a,s,0),s}return e[n(791)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1593)],a[n(1036)+"et"],a.byteLength)}function yp(a){let n=t;if(e[n(819)](e[n(815)],e.TIyVh))try{return e[n(403)]("string",typeof a)&&(e[n(1007)](a,ArrayBuffer)||a[n(1593)]&&e[n(1007)](a[n(1593)],ArrayBuffer))||e.BvHnr(e[n(1069)],typeof a)?"":(JSON.parse(a),n(969)+n(792))}catch{return e[n(1317)](e.gNgzb,typeof a)?e[n(1786)]:""}else++_0x54f240,_0x255f63+=4}let Ep=(a,n)=>{let s=t;switch(a){case e.UBvsB:case e.TuRcq:return{[s(692)+a]:1,"x-tt-env":n};default:return{}}};class vp{constructor(n){let s=t;this[s(609)+s(1503)]=n,this[s(566)]=0}[t(337)](){let n=t;this[n(566)]++}[t(699)+t(1356)+"nt"](){let n=t;return e[n(1429)](this.count,this[n(609)+n(1503)])}[t(961)+t(666)](n=0){let s=t;e.kVBvL(e[s(420)],e.ZXjwX)?this.on(_0x2b1564,_0x5acbe9):(this[s(609)+s(1503)]=n,this[s(566)]=0)}}async function bp(a){let n=t,s={XXhSF:n(1075),aGsGM:function(l,f){return e[n(1525)](l,f)},WGECK:e[n(670)],DkHut:e.UyvEF,hHXpW:function(l,f){return l===f},NbxlZ:e[n(1689)],IXsyV:function(l,f){return e[n(1070)](l,f)},izgVP:n(795),TdSsn:e[n(668)],ZAEXL:e[n(457)],xpHkM:e.vPrCf};return new Promise(l=>{let f=n,g={MysAT:function(E,S){return E==S},GnVbc:"string",djfCB:function(E,S){return E===S},QdjlP:s[f(436)],wDZBW:function(E,S){return s[f(1575)](E,S)},RkYrG:s[f(1594)],TIjmu:f(1531)+f(440)+"s",vrqll:s[f(532)]};if(s[f(1178)](s.NbxlZ,s[f(829)])){if(!Yn)return s[f(822)](l,s.WGECK);try{let E=document["createEl"+f(1074)](s[f(943)]);window[f(824)+f(1726)]=S=>{let p=f;if(g.djfCB(g.QdjlP,g[p(1712)]))document[p(591)]["removeCh"+p(1734)](E),window["frontier"+p(1726)]=void 0,g[p(1224)](l,S&&S[p(576)]||g[p(1783)]);else return DgespZ[p(423)](DgespZ.GnVbc,typeof _0x3ff95f)?p(602)+"in;chars"+p(1077):""},E.type=s[f(1491)],E[f(1602)]=a[f(871)](/^ws/,s[f(331)])+s[f(760)];try{document.body[f(1629)+f(1734)](E)}catch{document[f(591)][f(806)+f(1734)](E)}}catch{window[f(824)+f(1726)]=void 0,s[f(1575)](l,s.WGECK)}}else _0x15a259(f(652)),this[f(332)](g[f(638)],_0x47c6d9),this.off(g[f(624)],_0x652da3)})}function en(a,n,s){let l=t;return!!a?.[l(1147)](f=>f[l(563)]===n&&f.value===s)}function Xn(a,n){let s=t;if(e[s(790)](e[s(1417)],e[s(788)]))return a?.[s(1147)](l=>l[s(563)]===n)?.value;this[s(609)+s(1503)]=_0x1587ae,this[s(566)]=0}let da=null;async function Sp(){let a=t;return da||(da=Promise.resolve()[a(603)](Lt[a(1495)](Lt,e[a(1403)]))),da}class Ip extends aa{constructor(n,s){let l=t;if(e[l(567)](e[l(1618)],e[l(1618)]))return _0x49b882||(_0x5378a2=[_0x25bb88[l(1466)+"e"][l(1523)],_0x4aea9f[l(1466)+"e"][l(1589)],_0x236117.prototype[l(1589)+"PrimaryKey"]]);super(),this[l(742)]=n,this[l(1092)]=s,this[l(1424)]=void 0,this["_initPro"+l(1388)]=null}async[t(1049)](){await this[t(453)]()}async _init(){let n=t,s={dZELf:e[n(1724)],xnOOK:e[n(852)],OwCYA:function(l){return e[n(1725)](l)},rObIq:function(l,f,g,E){return e.YJypf(l,f,g,E)}};if(e[n(1612)](e[n(1674)],e[n(1674)]))try{return e.IkuHH(e[n(1069)],typeof _0x4ae950)&&(e[n(1423)](_0x225b4f,_0x17834e)||_0x171d9f[n(1593)]&&e[n(884)](_0x3b7919[n(1593)],_0x208380))||e.vBBHm(n(1140),typeof _0x5b4148)?"":(_0x2a2253[n(529)](_0x4c4f13),e[n(1144)])}catch{return e[n(1760)](e[n(1069)],typeof _0x15643c)?e[n(1786)]:""}else{if(this[n(1424)])return;if(this._initPromise)return this[n(1111)+n(1388)];try{let l=this[n(742)],f=this._keyPath;this["_initPro"+n(1388)]=(async()=>{let g=n,E={KNorr:s[g(1513)],KFCqR:s[g(891)]},{openDB:S}=await s.OwCYA(Sp);this[g(1424)]=await s[g(1010)](S,g(824)+"_"+l,1,{upgrade(p){let k=g,P={Pwmri:E[k(747)]};E[k(1152)]===E[k(1152)]?p[k(1777)+k(1736)+"e"](l,{keyPath:f}):(this[k(1739)](P[k(1701)],_0x5b395a),this[k(1619)+"eAck"]&&this[k(1619)+k(1509)](_0x37f53e))}})})(),await this["_initPro"+n(1388)]}catch(l){console[n(1249)](l)}finally{this[n(1111)+n(1388)]=null}}}async get(n){let s=t;try{return await this[s(453)](),this[s(1424)]?.[s(1634)](this._dbName,n)}catch(l){console[s(1249)](l)}}async[t(1695)](n,s){let l=t;return await this[l(453)](),this._qosDB?.[l(1042)](this._dbName,n)}async del(n){let s=t;try{return await this[s(453)](),this[s(1424)]?.[s(727)](this[s(742)],n)}catch(l){e[s(945)]===s(500)?console.log(l):(e[s(687)](_0x176731,_0x2580b9,24),e[s(1480)](_0xbab657,_0x420dfb,e[s(1300)](_0x35d552,_0x4c1896)))}}async clear(){let n=t;try{if(e[n(1615)](e[n(460)],e[n(460)]))return await this[n(453)](),this[n(1424)]?.clear(this[n(742)]);{let s=this[n(386)+n(1364)][n(1229)]((l,f)=>(l+=f&&f.byteLength||0,l),0);return e[n(1095)](s,this[n(1089)]?this[n(1089)].bufferedAmount:0)}}catch(s){if(e[n(1156)](e[n(574)],e.DtouR)){let l=_0x345eba[n(1259)](":");_0x5e1d7c&&(_0xe3ba2b=l[n(320)]),_0xd2902c+=l[n(320)];for(let f=0;e[n(1097)](f,l[n(320)]);f++)if(l[f].length!==4){let g=_0x86d80e[n(899)+"g"](0,e[n(317)](4,l[f].length)),E=g[n(1596)](l[f]);_0x3f7c3a[n(1652)](E)}else _0x3132d3[n(1652)](l[f]);_0x14ba63=!1}else console.log(s)}}async[t(1572)](){let n=t;return await this._init(),this[n(1424)]?.[n(773)+"ys"](this[n(742)])}async[t(988)](){let n=t;return await this._init(),this[n(1424)]?.getAll(this[n(742)])}async[t(832)](){let n=t;try{this[n(1424)]?.[n(1557)](),this[n(1424)]=void 0}catch(s){console[n(1249)](s)}}get[t(1198)](){let n=t;try{return!!this[n(1424)]}catch(s){return console[n(1249)](s),!1}}}class Ap{constructor(n,s){let l=t;if(e[l(881)](l(1632),e[l(926)]))this[l(736)]=n,this[l(406)]=s,this[l(1424)]=localStorage;else{let{initReconnectInterval:f,maxReconnectInterval:g,reconnectIntervalGrowFactor:E}=this[l(1498)],S=e[l(1017)](f,_0x345f2c[l(952)](E,_0x2e0f4e-1));return e[l(525)](S,g)?g:S}}async[t(1049)](){}get[t(1254)](){let n=t;return e.xluSo(n(439),e[n(1008)])?n(824)+"_"+this[n(736)]:UdzSgm.QuBSc(_0xb540f2,_0x57ae12[n(358)](UdzSgm.fRllQ(_0x316a85,this),_0x4e05b8))}async[t(1634)](n){let s=t,l=this[s(1424)][s(497)](this[s(1254)]);return JSON.parse(e[s(1605)](l,"{}"))[n]}async set(n,s){let l=t,f=this._qosDB[l(497)](this[l(1254)]),g=JSON[l(529)](f||"{}");return g[s||n[this[l(406)]]]=n,this[l(1424)][l(1187)](this[l(1254)],JSON.stringify(g)),s||n[this[l(406)]]}async[t(1401)](n){let s=t,l=this._qosDB.getItem(this[s(1254)]),f=JSON[s(529)](l||"{}");return f[n]=void 0,this[s(1424)][s(1187)](this[s(1254)],JSON[s(676)+"y"](f))}async clear(){let n=t;if(n(1588)===e.aZSTG)this["_interva"+n(1101)+"Id"]=null,this[n(1352)+"l"]=36e5,this[n(1424)]=_0x4f9436(e[n(1437)],n(735)+"id");else return this[n(1424)].clear()}async keys(){let n=t,s=this[n(1424)].getItem(this[n(1254)]),l=JSON[n(529)](s||"{}");return Object[n(1572)](l)}async getAll(){let n=t,s=this._qosDB[n(497)](this._prefix),l=JSON[n(529)](e[n(536)](s,"{}"));return Object[n(679)](l)}[t(832)](){return Promise[t(1083)]()}get[t(1198)](){return!!this._qosDB}}class Tp{constructor(n,s){let l=t;this[l(736)]=n,this[l(406)]=s,this[l(1424)]=An?tt:Kr?wx:null}async[t(1049)](){}get[t(1254)](){let n=t;return n(824)+"_"+this[n(736)]}async[t(1634)](n){let s=t,l=this[s(1424)][s(678)+s(1328)](this[s(1254)]);return JSON[s(529)](e[s(536)](l,"{}"))[n]}async[t(1695)](n,s){let l=t;if(e.vstaZ(l(1640),e[l(612)])){let f=this[l(1424)]["getStora"+l(1328)](this[l(1254)]),g=JSON[l(529)](f||"{}");return g[s||n[this[l(406)]]]=n,this[l(1424)][l(544)+"geSync"](this[l(1254)],JSON[l(676)+"y"](g)),s||n[this[l(406)]]}else{let f=e[l(1493)](_0x3a7ece,e[l(784)],{message:e.imUFx});this[l(1547)+"econnect"]&&this[l(1547)+l(1678)](f)}}async[t(1401)](n){let s=t,l=this[s(1424)]["getStora"+s(1328)](this[s(1254)]),f=JSON.parse(e[s(1605)](l,"{}"));return f[n]=void 0,this[s(1424)][s(544)+s(1328)](this[s(1254)],JSON[s(676)+"y"](f))}async[t(373)](){return this[t(1424)].clearStorageSync()}async keys(){let n=t,s=this[n(1424)][n(678)+n(469)+"nc"](this[n(1254)]),l=JSON[n(529)](e[n(1605)](s,"{}"));return Object[n(1572)](l)}async[t(988)](){let n=t,s=this[n(1424)][n(678)+"geInfoSync"](this[n(1254)]),l=JSON[n(529)](e[n(1605)](s,"{}"));return Object[n(679)](l)}[t(832)](){return Promise[t(1083)]()}get[t(1198)](){return!!this[t(1424)]}}function sl(a,n){let s=t;if(e[s(813)](An,An))return new Tp(a,n);if(e[s(1728)](Yn,$r)&&e[s(1064)](e[s(1250)],typeof indexedDB))return new Ip(a,n);if((Yn||$r)&&e[s(1782)](e[s(1250)],typeof localStorage))return new Ap(a,n);throw new Error(e[s(506)])}class Cp{constructor(){let n=t;this[n(1352)+n(1101)+"Id"]=null,this[n(1352)+"l"]=36e5,this[n(1424)]=sl(e.YvpZx,e[n(637)])}async[t(1352)+t(505)](){let n=t;clearInterval(this[n(1352)+n(1101)+"Id"]),this["_interva"+n(1101)+"Id"]=e[n(1723)](setInterval,()=>{let s=n;this[s(1753)+s(1116)]()},this[n(1352)+"l"])}async[t(1049)](){let n=t,s={KmCXf:e[n(1056)],DTykn:e[n(1045)]};e[n(376)](e[n(1486)],e[n(1486)])?await this[n(1424)][n(1049)]()[n(603)](()=>{let l=n;this[l(1352)+l(505)]()}):(_0x5ea61f&&_0x47c5f7["addEvent"+n(596)](PVeufs.KmCXf,()=>_0x5cfb60()),_0x5b718a&&_0x20f86b[n(1714)+"Listener"](PVeufs[n(1682)],()=>_0x39b9af()))}async[t(1753)+"ired"](){let n=t;(await this[n(1424)]?.getAll()||[])[n(375)](({timestamp:f})=>f<Date[n(1125)]())[n(407)](f=>{let g=n;this[g(1424)]?.[g(1401)](f[g(735)+"id"])})}async[t(1401)](n){let s=t;if(e[s(346)]!==e[s(346)])_0x3a40eb.d=(l,f)=>{let g=s;for(var E in f)_0x32ce52.o(f,E)&&!_0x35cabb.o(l,E)&&_0x1c7e43[g(1604)+"operty"](l,E,{enumerable:!0,get:f[E]})};else return this._qosDB?.[s(1401)](n)}async[t(1695)](n,s){let l=t;if(e[l(1601)](e[l(1400)],e[l(1060)]))this._DBName=_0x3fc8f4,this._pathKey=_0x39cf3d,this[l(1424)]=_0x4f0f7c;else return this._qosDB?.[l(1695)]({message_id:n,timestamp:s})}async[t(1634)](n){let s=t;return this._qosDB?.[s(1634)](n)}async[t(832)](){let n=t;clearInterval(this[n(1352)+n(1101)+"Id"]),await this._qosDB?.closeDB()}get[t(1198)](){let n=t;if(e[n(1597)](e[n(1185)],e[n(1108)]))return this[n(1424)]?.[n(1198)];this[n(487)]=!0,this._connect()}}function la(a){let n=t,s=!!this[n(1498)][n(517)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e.YJypf(en,a[n(411)][n(1355)],"x_fronti"+n(1539),"2"),f=l&&e[n(872)](en,a.message[n(1355)],e[n(1425)],"1"),g=l&&e[n(1316)](en,a[n(411)][n(1355)],e.jrpRy,"1"),E=g?e.TbNUm(Xn,a[n(411)][n(1355)],e[n(635)])?.split(",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:g,ackMsgIds:E}}async function ol(){let a=t;return this[a(1160)+"ger"]||(this[a(1160)+a(1052)]=new Cp),this[a(1160)+a(1052)][a(1198)]||await this[a(1160)+a(1052)][a(1049)](),this[a(1160)+a(1052)]}async function Rp(a,n){let s=t,{enableAutoAck:l}=this[s(1498)],f=e.YJypf(en,a[s(411)][s(1355)],e[s(1090)],"1"),g=e[s(872)](en,a[s(411)][s(1355)],e[s(614)],"1"),E=la[s(1034)](this,a);if(e[s(396)](l,f)){let{SeqID:S,LogID:p,service:k,LogIDNew:P,method:F}=a[s(411)];this[s(681)]({SeqID:S,LogID:p,LogIDNew:P,service:k,method:F,headers:[{key:e[s(614)],value:"1"},{key:s(553),value:P||""},{key:"ack_code",value:"0"}]})}g&&!E.isQoSAck&&this[s(1684)+s(739)+s(850)](a),e[s(581)](n)}async function kp(a,n){let s=t;this[s(1765)](s(493),a[s(411)]),e.YAswG(n)}async function Dp(a,n){let s=t,l=e[s(965)](Yt,await e[s(1283)](il,a[s(1082)]));try{if(l.payload instanceof Uint8Array){let f=this[s(1498)][s(1556)+"ncoding"]instanceof Object?{force:!!this[s(1498)][s(1556)+s(1551)][s(1104)],encoding:this[s(1498)][s(1556)+"ncoding"][s(348)]?this[s(1498)]["payloadE"+s(1551)][s(348)][s(871)](/\s/g,"")["toLowerC"+s(402)]():""}:{force:!1,encoding:this[s(1498)][s(1556)+s(1551)]?this._options["payloadE"+s(1551)].replace(/\s/g,"")["toLowerC"+s(402)]():""},g=l[s(1556)+"ncoding"]?l["payloadE"+s(1551)].replace(/\s/g,"")[s(424)+s(402)]():"",E=e[s(830)](this._options["payloadT"+s(318)],Object)?{force:!!this._options[s(959)+s(318)][s(1104)],type:this._options[s(959)+s(318)][s(345)]?this[s(1498)]["payloadT"+s(318)].type[s(871)](/\s/g,"")[s(424)+s(402)]():""}:{force:!1,type:this[s(1498)]["payloadT"+s(318)]?this[s(1498)][s(959)+s(318)][s(871)](/\s/g,"").toLowerCase():""},S=l[s(959)+s(318)]?l[s(959)+s(318)][s(871)](/\s/g,"")[s(424)+s(402)]():"",p=E[s(1104)]?E.type:S||E[s(345)],k=f[s(1104)]?f.encoding:g||f[s(348)],P=[e.jyAok,s(969)+s(792),e.xeOji,"string"],F=[s(1534)+"e",e[s(554)]];this[s(1498)][s(1381)+s(1599)+s(1651)+"ad"]&&P[s(1386)](p)&&(!k||F[s(1386)](k))?l[s(1505)+"oad"]=e[s(673)](rl,l.payload,0,l[s(1200)][s(940)+"th"]):l.textPayload=""}else l[s(1505)+s(1333)]=""}catch(f){l[s(1505)+s(1333)]="",console[s(1249)](f)}a[s(411)]=l,e[s(1732)](n)}function Pp(a,n,s){let l=t,f={Dljeg:function(k,P){return e[K(1349)](k,P)},EoPBG:function(k,P){return e[K(1221)](k,P)},CubqI:function(k,P){return k>P},uLxUX:function(k,P){return e[K(1475)](k,P)},iRDyF:e[l(1558)],TWTba:function(k,P){return e[l(355)](k,P)},cSgGI:function(k,P){return k&P},NyqNd:function(k,P){return e[l(455)](k,P)}},g=e[l(663)](s,8192),E=e.bgDFG(g,1),S=null,p=g;return function(k){let P=l;if(k<1||f[P(468)](k,E))return a(k);if(f.CubqI(f.EoPBG(p,k),g))if(f[P(1787)](f[P(708)],P(1032)))S=f[P(1180)](a,g),p=0;else return _0x531e91.readUInt8?{value:_0x368a22[P(600)+"8"](_0x23c367),offset:_0x2ef6a4+1}:{value:f.Dljeg(255,_0x1383ac[_0x4b2062]),offset:f[P(1668)](_0x410af5,1)};let F=n.call(S,p,p+=k);return f[P(1019)](7,p)&&(p=f[P(882)](7,p)+1),F}}let Op=4294967295;function Lp(a,n,s){let l=t;return e.TNCoS(RangeError,e[l(1761)](e[l(835)](e[l(1313)](e[l(1076)](e[l(1376)]+a,e[l(1685)]),n||1),e.JuwYs),s))}function Np(a,n,s){let l=t;if(e[l(1109)](s,Op))throw new Error(l(1675)+l(451)+"e");let f=3;for(;e.SOPbk(f,0);){let g=e.zCWZy(255,s);e[l(1316)](fa,g,a,e[l(401)](n,f)),s>>>=8,f--}return n+4}function Mp(a,n){let s=t,l=0,f=n,g=e.beqxD(n,4);for(;e[s(1302)](f,g);){let{value:E,offset:S}=e[s(1093)](ua,a,f);f=S,l=e[s(1656)](e[s(1193)](l,8),0),l+=E}return{value:l,offset:g}}function Bp(a,n,s){let l=t,f={IMUTi:e[l(597)],uyIry:function(g,E,S){return e[l(1740)](g,E,S)}};if(l(966)!==e.CFwUD){let g=e.vdCIU.split("|"),E=0;for(;;){switch(g[E++]){case"0":if(n[l(879)])return e[l(565)](n[l(879)](a,s),s);continue;case"1":if(a[l(320)]<40)return e.QXdjM(e[l(1413)](ca,a,n,s),s);continue;case"2":if(n[l(503)+"e"])return e[l(887)](n[l(503)+"e"](a,s),s);continue;case"3":if(!a)return s;continue;case"4":return e.cFpYW(e[l(1413)](ca,a,n,s),s)}break}}else this.emit(DNiBTT.IMUTi,DNiBTT[l(1383)](_0x4af42f,l(1204),{message:this[l(450)+l(321)+l(1240)](_0x14923c)}))}function Fp(a,n){let s=t,l=new fe(e[s(846)](e[s(1155)](e.nWrrj(a[e[s(1761)](n,4)]<<24,a[e[s(1445)](n,5)]<<16),e[s(1131)](a[e[s(1703)](n,6)],8)),a[e[s(641)](n,7)]),e[s(1371)](e.KnpcP(e[s(1550)](a[e.eEVmD(n,0)]<<24,e.jmEMM(a[e.JpOiH(n,1)],16)),e[s(617)](a[e[s(1289)](n,2)],8)),a[e[s(856)](n,3)]),!0);return n+=8,{value:l,offset:n+8}}function zp(a,n,s){let l=t;if(e[l(1118)]("flbvR",l(861))){let f=a.low,g=a[l(665)];return n[s]=e[l(930)](g,24),n[e[l(1313)](s,1)]=e[l(1201)](g,16)&255,n[e[l(1057)](s,2)]=e[l(996)](e.kvduX(g,8),255),n[e[l(1703)](s,3)]=e[l(513)](255,g),n[e.bwfvN(s,4)]=e[l(930)](f,24),n[s+5]=e[l(556)](e[l(1396)](f,16),255),n[e[l(1377)](s,6)]=e[l(523)](f>>>8,255),n[e[l(963)](s,7)]=e[l(1709)](255,f),s+=8,s}else return _0x94e8a5?.[l(1147)](f=>f.key===_0x4be029)?.value}function ua(a,n){let s=t;return a[s(600)+"8"]?{value:a[s(600)+"8"](n),offset:e.bpeHO(n,1)}:{value:e[s(1710)](255,a[n]),offset:n+1}}function fa(a,n,s){let l=t;return n[l(1540)+"t8"]?n[l(1540)+"t8"](a,s):n[s]=255&a,e.TxsNb(s,1)}let Up=function(a){let n=t;return e[n(833)](n(657),e[n(888)])?new _0x5e517f(_0x10072a,{message:_0x15af26,code:_0x38f604,error:_0x37a662}):new Uint8Array(a)},Gp=e.LcEvX(t(865)+"d",typeof Buffer)?Buffer[t(1485)+t(729)]:e[t(1768)](Pp,Up,Uint8Array[t(1466)+"e"][t(1235)]);(()=>{let a=t,n={qgXgq:e[a(1447)],eaIbi:function(l,f){return e[a(1511)](l,f)},iiXib:function(l,f){return e.XGYAd(l,f)},SIhoJ:function(l,f){return e[a(1194)](l,f)},XNsJM:function(l,f){return e.IajgE(l,f)},KDXcn:function(l,f){return e[a(1201)](l,f)},lSqfe:function(l,f){return e[a(688)](l,f)},JfCfd:function(l,f){return e[a(1001)](l,f)},aWSel:function(l,f){return e[a(618)](l,f)},CgGQn:function(l,f){return e[a(937)](l,f)},QfHbY:function(l,f){return e.ZUBip(l,f)},zxUsj:function(l,f,g,E){return e.YJypf(l,f,g,E)},zafQk:function(l,f){return e.eZmYa(l,f)},lbIfy:function(l,f){return e[a(618)](l,f)},dgtuO:function(l,f){return e.xweal(l,f)},QBLea:function(l,f){return e[a(349)](l,f)}},s=4294967295;return function(l,f,g=!0){let E=a,S=n[E(1416)][E(1259)]("|"),p=0;for(;;){switch(S[p++]){case"0":s=n.eaIbi(n[E(472)](s,n[E(836)](n.XNsJM(127,l[f]),7)),0);continue;case"1":s=n[E(706)](n[E(1649)](s,n.JfCfd(127,l[f])<<21),0);continue;case"2":if(l[f++]<128)return{value:g?s:n.aWSel(0,s),offset:f};continue;case"3":if(n[E(1482)](l[f++],128))return{value:g?s:0|s,offset:f};continue;case"4":if(n[E(555)](f+=5,l.length))throw f=l[E(320)],n[E(1242)](Lp,f,10,l[E(320)]);continue;case"5":if(n[E(1091)](l[f++],128))return{value:g?s:n[E(472)](0,s),offset:f};continue;case"6":s=n.KDXcn(n[E(1488)](127,l[f]),0);continue;case"7":s=n[E(334)](s,n[E(836)](15&l[f],28))>>>0;continue;case"8":s=n.dgtuO(n.iiXib(s,(127&l[f])<<14),0);continue;case"9":if(n[E(1091)](l[f++],128))return{value:g?s:n[E(1296)](0,s),offset:f};continue;case"10":return{value:g?s:0|s,offset:f};case"11":if(n[E(1482)](l[f++],128))return{value:g?s:0|s,offset:f};continue}break}}})();let qp=16,ha=32;function Hp(a){let n=t,s=0,l={};for(let f=0;e[n(1059)](f,a[n(320)]);f++)l[a[f][n(1257)+"ame"]]=e.SdWRP(nl,a[f]["cursor_n"+n(897)]),s+=14+l[a[f][n(1257)+n(897)]];return[s,l]}function al(a,n,s){let l=t,f={JZEjA:function(k,P){return e[K(1399)](k,P)},pOfXO:l(330)+l(501)},[g,E]=e[l(1315)](Hp,a),S=Gp(g),p=0;return a.forEach(k=>{let P=l;if(e[P(374)](e[P(907)],P(452)))console[P(1249)](e[P(1533)],k,k[P(1796)]),p=fa(0,S,p),console.log(P(560),p),p=Np(S,p,k[P(1796)]||0),console[P(1249)](e.kfFwm,p),p=e[P(673)](fa,E[k[P(1257)+P(897)]],S,p),console.log(e[P(1184)],p),p=e.YJypf(Bp,k["cursor_n"+P(897)],S,p),console[P(1249)](e[P(1306)],p),p=zp(fe[P(1012)+"er"](k[P(632)]||n),S,p),console[P(1249)](e[P(732)],p);else{if(mCBvHw[P(1720)](_0x1196d2.offset,_0x226dd4)>_0x58c833[P(949)])throw new _0x40744f(mCBvHw[P(507)]);_0xe1cef4[P(756)]+=_0x3f5756}}),{frameType:ha,headers:[{key:e[l(802)],value:s}],payload:S}}function jp(a){let n=t,s=0,l=[];for(;e.xqkmx(s,a[n(940)+"th"]);){let{offset:f}=e[n(1142)](ua,a,s);s=f;let g={cursor_name:"",cursor:0,service:0},{value:E,offset:S}=e[n(909)](Mp,a,s);g[n(1796)]=E,s=S;let{value:p,offset:k}=e.xMCzf(ua,a,s);s=k,g[n(1257)+n(897)]=e.bGBlJ(rl,a,s,e[n(1385)](s,p)),s+=p;let{value:P,offset:F}=Fp(a,s);g[n(632)]=P[n(562)](),s=F,l.push(g)}return l}function Wp(){let a=t;return{frameType:ha,headers:[{key:e[a(802)],value:a(780)+"_EXIST"}],payload:void 0}}class Kp{constructor(n,s,l){let f=t;if(e[f(1314)](e[f(776)],e[f(776)]))this[f(967)+"ameSpace"]=n,this[f(1538)+f(619)]=s,this[f(386)+f(750)]=l,this[f(1424)]=sl(this["_cursorN"+f(315)],f(1257)+"ame");else return new _0x292606(_0xbbe4d1,{message:_0x86c2de})}async openDB(){let n=t;await this[n(1424)][n(1049)]()}async getCursors(){let n=t;if(!this[n(1424)].isReady)return;let s=this[n(386)+n(750)],l=await this._qosDB[n(988)]();switch(console[n(1249)](e[n(1529)],l),s){case e[n(1195)]:return l&&l[n(320)]?e.YJypf(al,l,0,this[n(1538)+"ileName"]):void 0;case e[n(616)]:return;case e[n(895)]:return l&&l.length?e.YJypf(al,l,0,this._cursorFileName):e[n(1732)](Wp)}}async[t(1695)](n,s,l){let f=t;return console.log(e[f(1307)],n,s,l),this._qosDB[f(1695)]({cursor_name:n,cursor:s,service:l})}async[t(1630)+"rs"](n){let s=t,l=jp(n);for(let f of l)console[s(1249)](e.NtJSV,l),await this[s(1424)][s(1695)](f)}async[t(1634)](n){let s=t;return(await this[s(1424)].get(n))?.[s(632)]}async closeDB(){await this[t(1424)].closeDB()}[t(838)+t(462)+"Name"](n){let s=t;this[s(1538)+s(619)]=n}get isReady(){let n=t;if(e[n(1426)](e[n(498)],n(922)))_0x137187(_0x2f06ba[n(1204)]),_0x5e4e02();else return this[n(1424)][n(1198)]}}let $p="__x_msg_"+t(622);async function cl(a){let n=t;if(!this[n(1498)][n(517)+"S"])return null;let{aID:s,fpID:l,messageStrategy:f}=this[n(1498)],g=a||$p;try{if(e[n(461)]("HTWWg",e[n(521)])){let E=this[n(1424)][n(497)](this[n(1254)]),S=_0x2ecf21[n(529)](e.MXRYS(E,"{}"));return S[_0xce5e3d||_0x39fe63[this._pathKey]]=_0x4599e3,this._qosDB[n(1187)](this[n(1254)],_0xd7591a.stringify(S)),_0x1d1ec0||_0x35efdc[this[n(406)]]}else return this[n(590)+"anager"]?a&&this["_cursorM"+n(1373)][n(838)+n(462)+"Name"](a):this[n(590)+n(1373)]=new Kp(l+"_"+s+"_"+g,g,f),this[n(590)+n(1373)][n(1198)]||await this["_cursorM"+n(1373)][n(1049)](),this[n(590)+"anager"]}catch{return null}}async function Vp(a,n){let s=t,l=e[s(491)](en,a[s(411)][s(1355)],e[s(847)],"-1"),f=e[s(1176)](en,a[s(411)].headers,e[s(614)],"1"),g=e[s(1148)](Xn,a[s(411)][s(1355)],e.isKhZ),E=e[s(524)](Number,e.ocFuX(Xn,a[s(411)][s(1355)],"x_fronti"+s(1290)))||0,S=la[s(1034)](this,a),p=en(a[s(411)][s(1355)],e[s(1621)],"2"),k=e[s(1285)](Xn,a[s(411)][s(1355)],e[s(631)]),P=e[s(1653)](Number,Xn(a[s(411)][s(1355)],e[s(844)]));if(S[s(1311)])return e[s(1645)](n);let F=S[s(1415)+s(1797)]?await ol.call(this):null;if(a[s(411)][s(1796)]>0&&f&&!l||e[s(483)](a[s(411)][s(1796)],0)){if(g&&S[s(1415)+s(1797)]&&F)return!!!await F[s(1634)](g)&&(this[s(1684)+s(685)+s(970)](a),await F[s(1695)](g,e[s(864)](Date.now(),E))),e[s(367)](n);if(p){let H=await cl[s(1034)](this);if(!H)return this[s(1684)+s(685)+s(970)](a),e[s(1725)](n);let ee=await H[s(1634)](k)??-1;if(e[s(820)](ee,P))this[s(1684)+s(685)+s(970)](a),H[s(1695)](k,P,a[s(411)][s(1796)]);else throw new Error("recevied"+s(588)+" cursor "+P+(s(1559)+s(385)+s(914)+"r ")+ee);return n()}return this[s(1684)+"hMessageEvent"](a),e[s(367)](n)}}async function Jp(a,n){let s=t,l={lChfr:function(f,g,E){return e[K(1494)](f,g,E)}};if(e[s(1047)](e.HtCNY,e[s(680)])){let f=la.call(this,a);if(!f[s(1415)+s(1797)])return e.zQYFr(n);let g=await ol[s(1034)](this);if(f[s(428)+s(972)+s(1240)]&&f.ackMsgIds.length)for(let E of f[s(1451)+"s"])await g.del(E);e[s(393)](n)}else{let f=l.lChfr(_0x3815fb,s(1204),{message:_0x570aed[s(411)],code:_0x14634e[s(1749)+"OR"],error:_0xc3e8d1});this["_dispatc"+s(1641)+s(654)](f)}}async function Zp(a,n){let s=t,l=e[s(1166)](a[s(411)][s(1715)+"e"],qp),f=e[s(549)](a[s(411)].frameType,ha);if(!l&&!f)return n();let g=e.SAucs(Xn,a[s(411)][s(1355)],e.DfUIW);if(!g)return e[s(1673)](n);let E=await cl[s(1034)](this,g);if(!E)return e[s(367)](n);if(l){if(e[s(1490)]===e[s(1223)])return!!_0x59b63b?.find(S=>S[s(563)]===_0x41d021&&S[s(449)]===_0x356b2f);{let S=await E[s(1478)+"rs"](),p={frameType:S?.[s(1715)+"e"],SeqID:fe[s(1012)+"er"](this[s(1397)]++),LogID:fe[s(1012)+"er"](this._options[s(1390)+s(444)]()),service:9e3,method:5,headers:S?.[s(1355)],payload:S?.[s(1200)]},k=e[s(1476)](b,p);this[s(1089)]&&this[s(1089)].readyState&&this[s(1089)][s(1342)](k)}}if(f){let S=a[s(411)].payload;S&&E[s(1630)+"rs"](S)}}let Yp=async function(a,n){let s=t;this[s(487)]=!1,clearTimeout(this[s(1603)+s(1332)+"utId"]),e[s(870)](n)},Xp=async function(a,n){let s=t;if(!this[s(1089)]||e[s(881)](this[s(1089)][s(1013)+"te"],this[s(410)]))return e[s(778)](n);let{pingInterval:l}=this[s(1498)];this[s(853)+s(412)]?.[s(606)+"pointCon"+s(1398)]();for(let g=0;e[s(1552)](g,this._messageQueue.length);g++){let E=this["_message"+s(1364)][g];if(this._ws[s(1013)+"te"]===this[s(410)]&&E!==null)this[s(1089)]&&this._ws[s(1342)](E),this[s(386)+s(1364)][g]=null;else break}this[s(386)+s(1364)]=this[s(386)+"Queue"][s(375)](g=>!!g),this[s(1253)+s(1234)+"Id"]=e[s(1098)](setTimeout,()=>this._ping(),l),this[s(1684)+s(351)+"nt"](a),this[s(557)+"er"]&&this[s(1089)]&&(this[s(1089)][s(413)+"pe"]=this["_binaryT"+s(318)]);let f=this[s(853)+s(412)]?.["getCurre"+s(1434)+"nt"]();this[s(1765)]("open "+f+" success"),e[s(778)](n)},Qp=async function(a,n){let s=t,l=this[s(853)+s(412)]?.[s(601)+s(1434)+"nt"]();this[s(1765)](s(434)+l),e[s(476)](n)};class eg extends aa{constructor(n){let s=t,l={Kdhiw:function(S,p){return e[K(419)](S,p)},NpDiV:function(S,p,k,P){return e.YJypf(S,p,k,P)},lqBQy:function(S,p){return e[K(1102)](S,p)},ZVVly:e.UfQSR,uWaCD:function(S,p,k){return e[K(512)](S,p,k)},kNFMx:e.WjdBV,vgLiT:s(1204),rvahE:function(S,p){return S===p},Ugpin:function(S,p,k){return e.hGith(S,p,k)},AEaQk:function(S,p){return S<p}};super(),this[s(951)+s(980)+s(983)]=!0,this[s(557)+"er"]=Yn,this[s(1716)]=gp,this[s(372)+"T"]=An,this[s(764)+"X"]=Kr,this[s(589)+"r"]=$r,this[s(386)+s(1364)]=[],this[s(853)+s(412)]=null,this[s(336)+s(925)]=!1,this[s(615)+"ype"]=e[s(775)],this[s(1603)+s(1647)]=!1,this[s(1603)+s(1332)+s(1039)]=null,this["_reconne"+s(1442)+"tId"]=null,this[s(1253)+"gTimeoutId"]=null,this._seqId=0,this[s(487)]=!1,this[s(1746)]="",this[s(1160)+s(1052)]=null,this[s(590)+s(1373)]=null,this["_pingLos"+s(1548)]=null,this[s(920)+"ls"]=e[s(1789)],this[s(1264)]=3,this[s(1281)+"NG"]=0,this.OPEN=1,this[s(353)]=2,this[s(957)]=S=>{let p=s;try{l[p(867)](tl,this,S,[Yp,Xp,Qp])}catch(k){if(l.lqBQy(l[p(1574)],l[p(1574)])){let P=this[p(1424)][p(497)](this._prefix);return _0x31b408[p(529)](XhGycw[p(1134)](P,"{}"))[_0x561e5f]}else{let P=l[p(1566)](it,"error",{message:k[p(411)],code:Qt[p(1749)+"OR"],error:k});this[p(1684)+p(1641)+p(654)](P)}}},this[s(1226)+"ge"]=async S=>{let p=s,k={urkhz:e.tURUb},{pingInterval:P,pingFrequency:F}=this[p(1498)];if(e.IYSFj("hi",S[p(1082)])&&F==="always"||e[p(1642)]("auto",F))if(e[p(851)](e[p(1099)],p(475)))this["_clearPi"+p(1681)](),this[p(1739)](e[p(1360)],e[p(1463)]),this[p(1253)+p(1234)+"Id"]=e[p(994)](setTimeout,this[p(1507)][p(1495)](this),P);else{this[p(1684)+p(863)+p(654)](_0x514bbe(p(1557),{code:1e3,reason:k[p(1351)]})),this[p(853)+"tManager"]?.["resetEnd"+p(1325)+p(1398)](),this[p(929)+p(1548)]?.[p(961)+"nter"]();return}if(S.data!=="hi")try{tl(this,S,[Dp,Rp,Jp,Zp,Vp,kp])}catch(H){if(e.ViljB(e.fnOde,e[p(933)])){if(this[p(853)+p(412)]?.[p(699)+p(1527)+"es"]()){let Q=this[p(853)+p(412)]?.[p(601)+p(1434)+"nt"]();this[p(1684)+"hCloseEv"+p(654)](l.uWaCD(_0x2c29ef,l[p(1375)],{code:1006,reason:p(607)+Q+(p(1395)+p(1606)+p(1750)+p(642)),wasClean:!0}))}else{let Q=this[p(1498)][p(1587)+"tInterce"+p(1635)](_0x435305,_0x3899eb);this["_dispatc"+p(863)+"ent"](l[p(1566)](_0x29478f,p(1557),{code:_0x5d2073,reason:_0x244e76,wasClean:!0,willReconnect:Q})),Q&&this[p(1603)]()}return}else{let ee=e[p(537)](it,e[p(597)],{message:H[p(411)],code:Qt.MESSAGE_ERROR,error:H});this[p(1684)+p(1641)+"ent"](ee)}}},this[s(915)]=S=>{let p=s,k=this["_endpoin"+p(412)]?.[p(699)+p(1527)+"es"](),P=this[p(853)+"tManager"]?.[p(601)+"ntEndpoint"]();if(k&&!S[p(411)]){let F=p(607)+P+(p(1461)+p(890)+p(669)+"ed");this["_dispatc"+p(1641)+p(654)](l[p(1566)](it,l.vgLiT,{message:F,code:Qt[p(1172)+"IES_ERROR"],error:S}));return}this[p(1089)]&&l[p(1369)](this._ws.readyState,this[p(410)])&&this[p(1402)+p(1584)](),this[p(1684)+p(1641)+p(654)](l[p(740)](it,l.vgLiT,{message:S[p(411)],code:Qt[p(1280)+p(1246)],error:S}))},this[s(1265)]=async S=>{let p=s,k={dCGBt:function(P,F,H){return e[K(1312)](P,F,H)},QVsJO:function(P,F){return e[K(1487)](P,F)},MZMCj:function(P,F){return e[K(782)](P,F)},YYnxd:function(P,F){return e[K(689)](P,F)}};if(e[p(1571)](e[p(1114)],p(1080))){this._clearTimer(),this[p(751)+p(1681)](),this[p(786)+p(1595)+"rs"](),this._ws=null,this[p(1603)+p(1647)]=!1;let P=this[p(853)+"tManager"]?.[p(699)+p(1527)+"es"]();if(!P&&this[p(645)+p(671)]()&&!this[p(336)+p(925)]){let F=this[p(853)+p(412)]?.[p(601)+p(1434)+"nt"](),H=this[p(1498)][p(1587)+p(738)+p(1635)](S[p(733)],S.reason);this[p(1684)+p(863)+p(654)](e[p(703)](ut,e[p(1056)],{code:1006,reason:S[p(1705)]||p(1617)+p(898)+p(1278)+"wn reaso"+p(1330)+"ame: "+F,willReconnect:H})),H&&this[p(1603)]();return}if(e[p(1169)](1e3,S[p(733)])&&this[p(336)+p(925)]){this["_dispatc"+p(863)+"ent"](ut(e[p(1056)],{code:1e3,reason:e[p(987)]})),this[p(853)+"tManager"]?.["resetEnd"+p(1325)+p(1398)](),this[p(929)+p(1548)]?.[p(961)+"nter"]();return}if(S[p(733)]!==1e3&&P){let F=this[p(853)+p(412)]?.["getCurre"+p(1434)+"nt"](),H=S.reason;H||(H=await e[p(1068)](bp,this[p(1746)])),H=p(1617)+p(898)+"d, "+H+(", hostna"+p(1123))+F+(", max re"+p(1750)+p(642)),this[p(1684)+p(863)+p(654)](e[p(1577)](ut,e[p(1056)],{code:S[p(733)],reason:H}));let ee=p(607)+F+(p(1461)+"ax retri"+p(669)+"ed");this[p(1684)+p(1641)+"ent"](e[p(1480)](it,e.tLyIb,{message:ee,code:Qt[p(1172)+"IES_ERROR"]})),this["_endpoin"+p(412)]?.[p(606)+p(1325)+"fig"](),this[p(929)+p(1548)]?.[p(961)+"nter"]();return}if(S.code!==1e3&&!S[p(1705)]){let F=this["_endpoin"+p(412)]?.[p(601)+"ntEndpoint"]();this[p(1684)+"hCloseEv"+p(654)](ut(e[p(1056)],{code:S[p(733)],reason:p(1617)+"ng failed, unkno"+p(1586)+p(1330)+p(448)+F})),this[p(853)+"tManager"]?.[p(606)+p(1325)+p(1398)](),this["_pingLos"+p(1548)]?.[p(961)+p(666)]();return}this[p(1684)+"hCloseEvent"](S),this["_endpoin"+p(412)]?.[p(606)+p(1325)+"fig"](),this["_pingLos"+p(1548)]?.[p(961)+p(666)]()}else _0x20a0b0-=65536,_0x214c9e+=BFhnbJ[p(1294)](_0x1e8814,BFhnbJ[p(1676)](_0x4414f5>>10,55296),BFhnbJ[p(1432)](BFhnbJ[p(1218)](1023,_0x49991e),56320)),_0x4ca433+=3},this.onclose=null,this.onerror=null,this[s(1387)+"e"]=null,this[s(1027)]=null,this[s(1547)+"econnect"]=null,this[s(1619)+s(1509)]=null,this[s(939)+"mediatel"+s(362)+"ct"]=null,this[s(857)+s(814)]=this[s(857)+s(814)][s(1495)](this),this[s(857)+"ffLine"]=this["_handleO"+s(1759)][s(1495)](this),this[s(1514)+s(974)]=this[s(1514)+"ageHide"][s(1495)](this),this[s(1514)+s(1762)]=this[s(1514)+"ageShow"].bind(this),this[s(1498)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e.cbgZr(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(1096)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:s(1143),env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=n,E=Array.isArray(f)?f:e[s(968)](e.gNgzb,typeof f)?[f]:[];if(!E||e[s(526)](0,E[s(320)]))throw new Error(e[s(504)]);if(!e[s(965)](_p,g))throw new Error(s(1025)+s(542)+s(1611)+", WebSoc"+s(1764)+s(999)+s(975)+"ined");if(Object[s(1420)](this[s(1498)],n),this[s(853)+"tManager"]=new el(E,this[s(1498)][s(1406)+"es"]),this["_pingLos"+s(1548)]=new vp(this[s(1498)][s(883)+s(1043)]),this._options["automati"+s(690)]&&(this[s(487)]=!0,this[s(1603)]()),this[s(1498)][s(422)+s(748)+"nged"])if(e[s(1590)]("LFSjY",e[s(1117)])){if(_0x59fbf9===void 0)this[s(1430)+"rs"]={};else if(XhGycw[s(1369)](void 0,_0x416fce))this._listeners[_0x5ad555]=null;else{let S=this[s(1430)+"rs"][_0x48cbae];if(S)for(let p=0;XhGycw[s(464)](p,S[s(320)]);)S[p].fn===_0x1cfc42?S.splice(p,1):++p}return this}else this[s(372)+"T"]||this[s(764)+"X"]?this[s(1353)+s(811)+s(1580)]():this[s(557)+"er"]&&this[s(1366)+s(1228)+"Listener"]()}[t(857)+"nLine"](){let n=t,s={ijKdd:function(l,f){return e[K(499)](l,f)},UMYjL:function(l,f){return e[K(1258)](l,f)},RqYFK:function(l,f){return l(f)},IwtDk:function(l,f){return e[K(1153)](l,f)}};if(e[n(790)](e[n(1731)],e[n(1794)])){if(this[n(1498)][n(1771)+n(1225)+"nect"]||this[n(336)+n(925)])return;this["_handleR"+n(1678)]()}else _0x479406=RMsiMK.ijKdd(_0x272ed6,_0xe27760),_0x371369=127&_0x74a3ac,RMsiMK[n(1179)](128,_0x2583e9)&&(_0x1e9f91=RMsiMK[n(710)](_0x4e87b0,_0x346ccc),_0x39f661|=RMsiMK[n(531)](127&_0x31e7ec,7))}[t(857)+t(1759)](){let n=t;if(e.nVAZS(e[n(1658)],e[n(1658)])){this[n(919)+n(682)+"t"]();let s=e[n(1312)](oa,e[n(784)],{message:e[n(1745)]});this["onStopImmediatel"+n(362)+"ct"]&&this[n(939)+"mediatel"+n(362)+"ct"](s)}else try{this[n(1089)]&&this[n(1089)][n(1557)](_0x1dc6c3,_0x3e683b)}catch{}}["_initGlo"+t(1228)+t(596)](){let n=t;this[n(557)+"er"]&&window[n(1714)+"Listener"]("online",this[n(857)+n(814)]),this[n(557)+"er"]&&window["addEvent"+n(596)](e[n(1205)],this["_handleO"+n(1759)]),this[n(557)+"er"]&&window[n(1714)+n(596)](n(435),this[n(1514)+n(974)]),this[n(557)+"er"]&&window[n(1714)+n(596)](e[n(902)],this[n(1514)+n(1762)])}[t(744)+t(1228)+t(596)](){let n=t;if(e[n(1169)](e[n(408)],e[n(1464)]))this[n(557)+"er"]&&window[n(1502)+n(1084)+n(1120)](e[n(1643)],this["_handleO"+n(814)]),this[n(557)+"er"]&&window[n(1502)+n(1084)+n(1120)](e[n(1205)],this[n(857)+n(1759)]),this[n(557)+"er"]&&window[n(1502)+n(1084)+"ner"](n(435),this["_handleP"+n(974)]),this[n(557)+"er"]&&window[n(1502)+n(1084)+"ner"](e.gxMCG,this[n(1514)+n(1762)]);else{let s=n(607)+_0x75440+(n(1395)+", max re"+n(1750)+n(642));this._debug(s),this["_dispatchErrorEv"+n(654)](_0xfe7c44(e[n(597)],{message:s,code:_0x37ef4e[n(1172)+n(1268)+"R"]}));return}}["_handleP"+t(974)](n){let s=t;!n[s(1243)+"d"]&&(this._isBrowser&&window["removeEv"+s(1084)+s(1120)](e[s(1348)],this[s(1514)+s(974)]),this[s(557)+"er"]&&window[s(1502)+s(1084)+s(1120)](s(894),this[s(1514)+s(1762)]),this[s(1557)]()),this[s(557)+"er"]&&window["removeEv"+s(1084)+s(1120)](e[s(1643)],this._handleOnLine),this[s(557)+"er"]&&window[s(1502)+s(1084)+s(1120)](e[s(1205)],this[s(857)+s(1759)])}[t(1514)+"ageShow"](n){let s=t;n[s(1243)+"d"]&&(this["_navigat"+s(671)]()&&(!this[s(1089)]||this[s(1089)][s(1013)+"te"]!==this[s(410)]||e[s(1337)](this[s(1089)][s(1013)+"te"],this[s(1281)+"NG"]))&&this[s(857)+s(814)](),this[s(557)+"er"]&&window[s(1714)+s(596)](e.KHpmC,this[s(857)+s(814)]),this[s(557)+"er"]&&window["addEvent"+s(596)](e[s(1205)],this._handleOffLine))}async[t(1028)+t(1367)](n){let s=t,l={OUUqd:s(493),YDmuT:function(f){return f()}};if(e[s(1086)](e.godnS,e[s(1192)])){let{fpID:f,deviceID:g,bddID:E,ttwID:S,accessKey:p,aID:k,customParams:P={},enableAutoAck:F,enableQoS:H,QoSLevel:ee,env:Q}=this._options,tn,ft,xa;this._isBrowser||this[s(764)+"X"]||this[s(372)+"T"]?(tn=location&&s(1521)==location[s(1372)]?s(787):s(701),ft=n.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),xa=/^wss(.*:\/\/)/[s(1628)](n)?n:""+tn+ft):(tn=e[s(1378)],ft=n[s(871)](/(^http)((?:[s]*:\/\/))/,""),xa=/(^ws)((?:[s]*:\/\/))/[s(1628)](ft)?ft:""+tn+ft);let dl=E?s(1585):S?s(796):s(981)+"d",ll=E||S||g;if(e[s(419)](!ll,!dl))throw new Error(e[s(1191)]);let tg=e[s(1317)]("function",typeof P)?await P():P,ng=Q?e[s(1723)](Ep,Q.xUseEnv,Q[s(1730)]):{},pa=Object.assign({device_platform:e[s(520)],version_code:e[s(913)],access_key:p,fpid:f,aid:k,[dl]:ll,xsack:F?1:0,xaack:F?1:0,xsqos:H?1:0,qos_level:H?ee:void 0,qos_sdk_version:2,...ng},tg),rg=Object[s(1572)](pa)[s(1229)]((ga,ma)=>pa[ma]!==void 0?""+ga+(ga?"&":"?")+ma+"="+pa[ma]:ga,"");return xa+"/ws/v2"+rg}else this[s(1765)](qqKLTw[s(746)],_0x17954f[s(411)]),qqKLTw[s(1393)](_0x110cfd)}async[t(1603)](){let n=t;if(!(this._connectLock||this[n(336)+"osed"])){this[n(1603)+"Lock"]=!0;try{if(e[n(841)](n(1679),e[n(1177)])){let s=this[n(853)+"tManager"]?.[n(1163)+n(1751)+n(425)+"hedMaxRe"+n(1297)](),{timeoutInterval:l}=this[n(1498)];if(s)if(e[n(730)](e[n(1132)],e[n(1132)])){let g=this[n(853)+n(412)]?.[n(601)+n(1434)+"nt"](),E=this[n(853)+"tManager"]?.[n(442)+n(1506)+n(1005)+n(1277)+n(494)](),S=this["_endpoin"+n(412)]?.[n(601)+n(1434)+n(399)+n(1503)]();if(E){let p="connect "+g+(n(1395)+", max re"+n(1750)+n(1072)+n(539)+n(1409)+n(1206))+E+(n(1520)+"y"),k=it(e[n(597)],{message:p,code:Qt[n(1172)+n(1268)+"R"]});this[n(1765)](p),this[n(1684)+n(1641)+n(654)](k),this[n(1746)]=await this[n(1028)+n(1367)](E),this._debug(n(607)+E+" "+S+n(511)),this[n(786)+n(1595)+"rs"]()}else{let p=n(607)+g+(n(1395)+", max re"+n(1750)+n(642));this._debug(p),this["_dispatc"+n(1641)+n(654)](it(e[n(597)],{message:p,code:Qt[n(1172)+n(1268)+"R"]}));return}}else this[n(1232)]=!0,this[n(731)]=e[n(718)](0,_0x1840ff),this.high=e.tLvFB(0,_0x3968ae),this[n(1237)]=!!_0x5181fa;else if(e.kVBvL(e[n(1741)],n(1412))){let g=_0x2d64ff.call(UdzSgm[n(1653)](_0x28ad8a,this),_0x217517,..._0x1c590d);return _0x1311b6.set(g,_0x4d6421.sort?_0x20a31d[n(816)]():[_0x1e4118]),UdzSgm[n(1704)](_0x35b892,g)}else{let g=this[n(853)+n(412)]?.[n(601)+n(1434)+n(839)+n(1659)](),E=this[n(853)+n(412)]?.[n(601)+n(1434)+"ntTriesC"+n(1503)]();this[n(1746)]=await this[n(1028)+n(1367)](e[n(725)](g,"")),this[n(1765)](n(607)+g+" "+E+" times"),this["_removeW"+n(1595)+"rs"]()}if(this[n(487)])this[n(487)]=!1;else{let g=e[n(1516)](oa,e.sEFVc,{message:e.imUFx});this[n(1547)+"econnect"]&&this["onStartR"+n(1678)](g)}let f=this[n(853)+n(412)]?.[n(601)+n(1434)+"ntTriesC"+n(1503)]()||0;e[n(644)](f,1)&&await this[n(826)](e.PsasN(f,1)),this[n(1765)]("connecti"+n(876)+this[n(1746)]+(n(1444)+n(928))+this[n(920)+"ls"]),this._ws=e.aEQGV(wp,{url:this[n(1746)],protocols:[this[n(920)+"ls"]],headers:this._options["miniProg"+n(527)+"s"][n(1119)+"tpHeader"]},this[n(1498)].ws),(this[n(557)+"er"]||this[n(589)+"r"])&&this[n(1089)]&&(this[n(1089)][n(413)+"pe"]=this[n(615)+"ype"]),this["_addWsLi"+n(758)](),this[n(1603)+n(1332)+n(1039)]=e[n(1262)](setTimeout,this[n(823)+"ut"][n(1495)](this),l)}else e[n(1453)](_0x541440,_0x1a4ec9,8),e[n(947)](_0x1ae75,_0x1c9d07,_0x462749)}catch(s){throw this[n(1603)+"Lock"]=!1,s}}}[t(1582)+"mer"](){let n=t;e.foMvN(clearTimeout,this[n(1603)+n(1332)+n(1039)]),this["_connect"+n(1332)+n(1039)]=null}[t(751)+"ngTimer"](){let n=t;e[n(1704)](clearTimeout,this[n(1253)+n(1234)+"Id"]),e.HKEfq(clearTimeout,this[n(391)+n(1442)+n(540)]),this[n(1253)+n(1234)+"Id"]=null,this["_reconne"+n(1442)+"tId"]=null}[t(1765)](...n){let s=t;if(s(755)!==e[s(1564)])return this[s(1089)]?this._ws[s(413)+"pe"]:this[s(615)+s(318)];this[s(1498)].debug&&console[s(1249)][s(358)](console,[e[s(1662)],...n])}["_getInte"+t(377)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(1498)],E=e[s(938)](l,Math[s(952)](g,n-1));return e[s(1664)](E,f)?f:E}[t(1507)](){let n=t;if(this[n(1089)]&&e[n(1565)](this[n(1089)].readyState,this.CONNECTING)){this[n(751)+n(1681)](),this[n(1253)+n(1234)+"Id"]=setTimeout(this[n(1507)][n(1495)](this),this[n(1498)]["pingInte"+n(1347)]);return}if(!this[n(1089)]||e[n(1677)](this[n(1089)].readyState,this[n(410)]))return void this[n(380)+n(1678)]();this._ws&&this[n(1089)].send("hi"),this["_reconnectTimeou"+n(540)]=e.xdbNw(setTimeout,this[n(380)+n(1678)+n(482)][n(1495)](this),this[n(1498)]["pingTime"+n(516)+"val"])}[t(380)+t(1678)+t(482)](){let n=t;this[n(929)+n(1548)]?.addCount(),this[n(1739)](e[n(982)],e[n(1727)]),this[n(929)+n(1548)]?.["checkRea"+n(1356)+"nt"]()?this[n(380)+"econnect"]():this[n(1507)]()}["_navigat"+t(671)](){let n=t;return this[n(372)+"T"]||this[n(764)+"X"]?this[n(951)+n(980)+n(983)]:(this[n(557)+"er"]||this[n(589)+"r"])&&this._options["listenNe"+n(748)+n(1208)]?navigator.onLine:!0}[t(380)+t(1678)](){let n=t;!this[n(645)+n(671)]()||this["_readyCl"+n(925)]||(this[n(853)+n(412)]?.["resetEndpointCon"+n(1398)](),this[n(929)+n(1548)]?.["resetCou"+n(666)](),this[n(1089)]?this[n(1402)+n(1584)](1001,"going aw"+n(771)+n(1587)+"ting ser"+n(515),!0):this._connect())}_onPageNetWorkChange(){let n=t;this._isMiniTT?tt[n(1569)+n(860)+"hange"](({isConnected:s})=>{let l=n;this[l(951)+l(980)+l(983)]=s,s?this[l(857)+l(814)]():this["_handleO"+l(1759)]()}):this[n(764)+"X"]&&wx[n(1569)+n(860)+"hange"](({isConnected:s})=>{let l=n;this[l(951)+l(980)+l(983)]=s,s?this._handleOnLine():this["_handleO"+l(1759)]()})}[t(826)](n){let s={LJtqb:function(l,f,g){return l(f,g)}};return new Promise(l=>{let f=K;s[f(880)](setTimeout,l,this[f(1167)+f(377)+"e"](n))})}[t(1402)+t(1584)](n=1e3,s="",l=!1){let f=t;this._ws&&this[f(919)+"WebSocket"](n,s,l)}[t(823)+"ut"](){let n=t,s=this["_endpoin"+n(412)]?.["getCurre"+n(1434)+"nt"]();this[n(1765)](n(607)+s+n(1395)),this[n(1402)+n(1584)](1001,e[n(1518)],!0)}[t(681)](n){let s=t,l=e[s(1309)](Bt,n);this[s(1089)]&&e[s(559)](this[s(1089)].readyState,this[s(410)])&&(this._ws&&this[s(1089)][s(1342)](l),this._debug(e[s(997)],n))}[t(786)+t(1595)+"rs"](){let n=t,s={KAGIY:function(l,f){return e[K(1655)](l,f)},jVxhC:function(l,f){return l|f},Yzbai:function(l,f){return l+f},WkGhu:function(l,f){return e.KeMIh(l,f)},cEszp:function(l,f){return e[K(950)](l,f)},OLOKd:function(l,f){return e[K(688)](l,f)},cBDDP:function(l,f){return e[K(1441)](l,f)},cuvrO:function(l,f){return e[K(1270)](l,f)},AXzdK:function(l,f){return e[K(655)](l,f)},ygtBt:function(l,f){return e[K(1095)](l,f)},PTjfV:function(l,f){return e[K(414)](l,f)}};if(e[n(437)]!==n(1033)){let l=e[n(1496)][n(1259)]("|"),f=0;for(;;){switch(l[f++]){case"0":if(!this._ws)return;continue;case"1":this[n(1089)][n(1502)+n(1084)+n(1120)](e.ZDTov,this._onMessage);continue;case"2":this[n(1089)]["removeEventListe"+n(1120)](e[n(378)],this[n(957)]);continue;case"3":this[n(1089)][n(1502)+n(1084)+n(1120)](e.WjdBV,this[n(1265)]);continue;case"4":this._ws[n(1502)+"entListe"+n(1120)](e[n(597)],this[n(915)]);continue}break}}else{let l=new _0x3e8622(GqSMdO[n(1279)](GqSMdO[n(489)](_0x457f30[GqSMdO[n(1173)](_0x5381c9,4)]<<24,GqSMdO[n(1638)](_0x23295a[GqSMdO[n(1173)](_0x2212f8,5)],16))|GqSMdO.WkGhu(_0xc05c42[GqSMdO[n(389)](_0x377923,6)],8),_0x232283[_0x4d90c6+7]),GqSMdO[n(1266)](_0x526e9d[GqSMdO.cBDDP(_0x1ddfdd,0)]<<24,GqSMdO[n(1638)](_0x44d208[_0x72fc76+1],16))|GqSMdO[n(1209)](_0x3c70ae[GqSMdO.AXzdK(_0xe14e05,2)],8)|_0x5b79a9[GqSMdO[n(942)](_0x139cdd,3)],!0);return _0x317da8+=8,{value:l,offset:GqSMdO.PTjfV(_0x98b5fe,8)}}}["_addWsLi"+t(758)](){let n=t,s=e[n(1085)][n(1259)]("|"),l=0;for(;;){switch(s[l++]){case"0":this._ws.addEventListener(e[n(378)],this._onOpen);continue;case"1":if(!this[n(1089)])return;continue;case"2":this[n(1089)][n(1714)+n(596)](e.tLyIb,this._onError);continue;case"3":this[n(1089)]["addEvent"+n(596)](e.ZDTov,this[n(1226)+"ge"]);continue;case"4":this._ws[n(1714)+n(596)](n(1557),this[n(1265)]);continue}break}}[t(743)+t(340)](n=1e3,s=""){let l=t;try{this._ws&&this[l(1089)][l(1557)](n,s)}catch{}}[t(919)+t(682)+"t"](n=1e3,s="",l=!1){let f=t;if(this[f(751)+f(1681)](),this[f(1582)+f(1344)](),this._removeWsListeners(),this[f(743)+f(340)](1e3,s),this[f(1603)+f(1647)]=!1,l&&this[f(645)+"orOnline"]()&&!this[f(336)+f(925)]){if(this["_endpoin"+f(412)]?.[f(699)+f(1527)+"es"]()){let E=this[f(853)+f(412)]?.[f(601)+f(1434)+"nt"]();this[f(1684)+"hCloseEv"+f(654)](e[f(1453)](ut,e[f(1056)],{code:1006,reason:f(607)+E+(" timeout, max re"+f(1750)+f(642)),wasClean:!0}))}else{let E=this[f(1498)]["reconnectInterce"+f(1635)](n,s);this[f(1684)+"hCloseEvent"](e[f(1182)](ut,e[f(1056)],{code:n,reason:s,wasClean:!0,willReconnect:E})),E&&this._connect()}return}this[f(645)+"orOnline"]()||this[f(336)+f(925)]?this[f(1684)+f(863)+f(654)](ut(f(1557),{code:n,reason:e[f(987)]})):this[f(1684)+f(863)+f(654)](e.lHcAj(ut,e.WjdBV,{code:1006,reason:e[f(329)]})),this[f(1089)]=null,this[f(853)+f(412)]?.[f(606)+f(1325)+f(1398)](),this[f(929)+f(1548)]?.["resetCou"+f(666)]()}[t(1684)+t(351)+"nt"](n){let s=t,l={UaWTk:function(f){return e[K(1708)](f)},kaeia:function(f,g,E){return e.OjMNj(f,g,E)},aVqUv:function(f,g){return e[K(1365)](f,g)}};if(e[s(387)](e[s(1467)],e[s(1467)])){let f=rSkfsy[s(578)](_0x2ead11);return rSkfsy[s(1255)](_0x1a3219,_0x50136b,f),rSkfsy[s(834)](_0x27b824,f)}else this[s(1739)](e[s(378)],n),this[s(1027)]&&this[s(1027)](n)}[t(1684)+t(685)+t(970)](n){let s=t;this[s(1739)](s(411),n),this[s(1387)+"e"]&&this[s(1387)+"e"](n)}[t(1684)+t(739)+t(850)](n){let s=t;this[s(1739)](e[s(1724)],n),this[s(1619)+s(1509)]&&this[s(1619)+s(1509)](n)}[t(1684)+t(1641)+t(654)](n){let s=t;this[s(1739)](e.tLyIb,n),this.onerror&&this[s(1669)](n)}["_dispatchCloseEv"+t(654)](n){let s=t;this[s(1739)](e[s(1056)],n),this[s(662)]&&this[s(662)](n)}get binaryType(){let n=t;return e[n(549)](e[n(433)],e[n(1346)])?(_0x30624e[n(1249)](_0x1c2d0f),!1):this[n(1089)]?this[n(1089)].binaryType:this["_binaryT"+n(318)]}set[t(413)+"pe"](n){let s=t;this[s(615)+s(318)]=n,this._ws&&(this._ws[s(413)+"pe"]=n)}get[t(1481)+"nt"](){let n=t;return this["_endpoin"+n(412)]?.[n(601)+n(1434)+n(399)+n(1503)]()||0}get["buffered"+t(1048)](){let n=t,s=this["_message"+n(1364)][n(1229)]((l,f)=>(l+=f&&f.byteLength||0,l),0);return e[n(950)](s,this[n(1089)]?this[n(1089)][n(1303)+n(1048)]:0)}get[t(1350)+"ns"](){let n=t;return this[n(1089)]?this[n(1089)].extensions:""}get[t(1372)](){let n=t;return this[n(1089)]?this[n(1089)][n(1372)]:""}get readyState(){let n=t;return this._ws?this[n(1089)][n(1013)+"te"]:this[n(1498)]["automati"+n(690)]?this[n(1281)+"NG"]:this[n(1264)]}get url(){let n=t;return this[n(1089)]?this._ws[n(1561)]:this[n(1746)]}[t(1557)](n=1e3,s){let l=t,f=e.BDxLa.split("|"),g=0;for(;;){switch(f[g++]){case"0":this[l(919)+l(682)+"t"](n,s);continue;case"1":if(!this._ws)return void this[l(1765)](e[l(427)]);continue;case"2":if(this[l(1089)][l(1013)+"te"]===this.CLOSED||e[l(1086)](this[l(1089)][l(1013)+"te"],this[l(353)]))return void this[l(1765)](e[l(594)]);continue;case"3":this[l(336)+l(925)]=!0;continue;case"4":this[l(1582)+l(1344)]();continue;case"5":this[l(1160)+"ger"]?.[l(832)]();continue;case"6":this[l(751)+"ngTimer"]();continue;case"7":this["_dropGlo"+l(1228)+l(596)]();continue}break}}async send(n,s){let l=t;if(n==null)throw new Error(e[l(485)]);e.hynLq==typeof n&&(n=JSON[l(676)+"y"](n)),e.LcEvX(e[l(1069)],typeof n)&&!e[l(791)](n,ArrayBuffer)&&!(n[l(1593)]&&e.OdKEu(n[l(1593)],ArrayBuffer))&&(n=JSON[l(676)+"y"](n));let f=await e[l(1087)](il,n),g=e[l(1578)](yp,n),{method:E=0,service:S=this[l(1498)][l(1796)],logID:p=this[l(1498)][l(1390)+l(444)](),headers:k=this[l(1498)][l(1355)],payloadEncoding:P=this._options[l(1556)+l(1551)],payloadType:F=this[l(1498)]["payloadT"+l(318)],logIDNew:H=this._options["logIDNew"+l(715)][l(1688)+l(1018)+l(1e3)+"ew"]?e[l(1524)](i,this[l(1498)]["logIDNew"+l(715)][l(1737)]):""}=e[l(813)](s,{});if(!S)throw new Error(e.YrmTR);let ee={SeqID:fe[l(1012)+"er"](this[l(1397)]++),LogID:fe[l(1012)+"er"](p),service:S,method:E,headers:k,payloadEncoding:e.hZMnI(P,Object)?P[l(348)]?P[l(348)]:"":P,payloadType:e[l(1336)](F,Object)?F[l(345)]?F.type:g:F||g,payload:f,LogIDNew:H},Q=e.jMSSs(Bt,ee);return this[l(1089)]&&this._ws.readyState===this[l(410)]?(this[l(1089)]&&this[l(1089)][l(1342)](Q),this[l(1765)](e[l(1230)],ee)):e.BITuX(this[l(386)+l(1364)][l(320)],this._options[l(1380)+l(1719)+l(352)])?(this[l(386)+l(1364)].push(Q),this[l(1765)](e[l(910)],ee)):(this[l(386)+l(1364)][l(1665)](),this[l(386)+"Queue"][l(1652)](Q)),{seqID:this._seqId,logID:p,logIDNew:H}}async[t(1587)+"t"](n){let s=t,{url:l}=e[s(1107)](n,{}),f=Array[s(640)](l)?l:e.JDygy(e[s(1069)],typeof l)?[l]:[];n&&Object.assign(this[s(1498)],n),f&&f.length?this[s(853)+"tManager"]=new el(f,this[s(1498)].maxRetries):this[s(853)+s(412)]?.[s(606)+s(1325)+s(1398)](),this[s(929)+s(1548)]?.[s(961)+s(666)](this[s(1498)][s(883)+"Count"]),this[s(336)+s(925)]=!1,this[s(1089)]&&this[s(1089)][s(1013)+"te"]!==this[s(1264)]?this[s(1402)+"ect"](1e3,s(431)+"econnecting",!0):(this[s(487)]=!0,this._connect())}async[t(877)](){let n=t;!this[n(1603)+n(1647)]&&(this[n(853)+"tManager"]?.[n(606)+"pointCon"+n(1398)](),this[n(929)+n(1548)]?.["resetCou"+n(666)](),this[n(336)+n(925)]=!1,this[n(487)]=!0,this[n(1603)]())}[t(1714)+t(596)](n,s){this.on(n,s)}[t(1563)+t(970)](n){let{type:s}=n;this.emit(s,n)}[t(1502)+t(1084)+t(1120)](n,s){this.off(n,s)}pingOnce(){let n=t,s={fFOIz:function(l,f){return e[K(1339)](l,f)},vCatJ:function(l,f){return l(f)},qfmdh:function(l,f){return l+f},IRdjH:e.rnILX,OyDGD:e[n(1360)],QJfnA:e[n(982)],DdRiL:function(l,f){return e[n(633)](l,f)},NNXOm:e[n(958)],dkWFu:n(1772)};if(e[n(1340)]===e[n(1532)]){let l=0,f={};for(let g=0;jIDybg[n(1334)](g,_0x59c7ea[n(320)]);g++)f[_0x1fd162[g][n(1257)+n(897)]]=jIDybg[n(1054)](_0x691996,_0x8870b3[g][n(1257)+"ame"]),l+=jIDybg[n(1407)](14,f[_0xf2187f[g][n(1257)+n(897)]]);return[l,f]}else return new Promise((l,f)=>{let g=n,E={jefsr:function(S,p,k){return e[K(1470)](S,p,k)},kIxNK:"close",sEuhW:function(S,p,k,P){return e.nVwaZ(S,p,k,P)}};if(e[g(1692)](e[g(1020)],e[g(1020)])){let S=this[g(853)+g(412)]?.[g(601)+g(1434)+"nt"]();this["_dispatc"+g(863)+g(654)](WhZbaV[g(1062)](_0x1d00c9,WhZbaV.kIxNK,{code:_0x2ab4eb.code,reason:"connecti"+g(898)+g(1278)+"wn reaso"+g(1330)+g(448)+S})),this[g(853)+"tManager"]?.[g(606)+"pointCon"+g(1398)](),this["_pingLos"+g(1548)]?.[g(961)+g(666)]();return}else{this[g(751)+"ngTimer"](),this[g(1253)+g(1234)+"Id"]=e.yQUoc(setTimeout,this._ping.bind(this),this[g(1498)][g(1263)+"rval"]);let S=()=>{let k=g;s[k(1054)](l,s[k(545)]),this.off(s[k(388)],S),this[k(332)](s[k(1154)],p)},p=()=>{let k=g;s[k(1613)](s[k(446)],k(962))?WhZbaV[k(1683)](_0x25d1de,this,_0x2bf4a3,[_0x4822c4,_0x3b70bb,_0x9eab5a,_0x4f5d37,_0x1a5f8f,_0x1b35c7]):(s[k(1054)](f,s[k(1037)]),this.off(k(1531)+k(440)+"s",S),this[k(332)](s[k(1154)],p))};this.on(e[g(1360)],S),this.on(e.UyvEF,p),this[g(1507)]()}})}}})(),Le[N(684)+N(759)]=Te[N(684)+"oseEvent"],Le[N(1510)+N(977)]=Te[N(1510)+N(977)],Le[N(1744)+"e"]=Te.ErrorCode,Le[N(970)]=Te[N(970)],Le[N(1755)]=Te[N(1755)],Le[N(473)+N(1238)+"vent"]=Te[N(473)+N(1238)+N(1696)],Le[N(1238)+N(1696)]=Te[N(1238)+N(1696)],Le[N(1058)+"t"]=Te[N(1058)+"t"],Le[N(1591)+"tEvent"]=Te[N(1591)+N(1748)],Le[N(466)+N(759)]=Te[N(466)+N(759)],Le[N(599)+N(977)]=Te.createErrorEvent,Le["createMe"+N(1256)+"nt"]=Te[N(643)+"ssageEvent"],Le["createOp"+N(749)]=Te["createOp"+N(749)],Le[N(1189)+"connectE"+N(1696)]=Te[N(1189)+N(1110)+N(1696)],Le[N(1700)+N(1793)]=Te[N(1700)+N(1793)],Le[N(1055)+N(897)]=Te[N(1055)+N(897)];for(vo in Te)[N(684)+N(759),N(1510)+N(977),"ErrorCode","Event",N(1755),"Frontier"+N(1238)+N(1696),N(1238)+N(1696),N(1058)+"t","ReconnectEvent",N(466)+N(759),N(599)+N(977),"createMe"+N(1256)+"nt",N(955)+N(749),N(1189)+N(1110)+N(1696),N(1700)+N(1793),N(1055)+N(897)][N(712)](vo)===-1&&(Le[vo]=Te[vo]);var vo;Object[N(1604)+"operty"](Le,N(1742)+"le",{value:!0})});var Kt=ae((NR,mh)=>{"use strict";var ph=["nodebuffer","arraybuffer","fragments"],gh=typeof Blob<"u";gh&&ph.push("blob");mh.exports={BINARY_TYPES:ph,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:gh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var qi=ae((MR,Ro)=>{"use strict";var{EMPTY_BUFFER:fv}=Kt(),ad=Buffer[Symbol.species];function hv(t,e){if(t.length===0)return fv;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 wh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function _h(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function xv(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}Ro.exports={concat:hv,mask:wh,toArrayBuffer:xv,toBuffer:cd,unmask:_h};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");Ro.exports.mask=function(e,r,i,o,c){c<48?wh(e,r,i,o,c):t.mask(e,r,i,o,c)},Ro.exports.unmask=function(e,r){e.length<32?_h(e,r):t.unmask(e,r)}}catch{}});var vh=ae((BR,Eh)=>{"use strict";var yh=Symbol("kDone"),dd=Symbol("kRun"),ld=class{constructor(e){this[yh]=()=>{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[yh])}}};Eh.exports=ld});var Lr=ae((FR,Ah)=>{"use strict";var Hi=ue("zlib"),bh=qi(),pv=vh(),{kStatusCode:Sh}=Kt(),gv=Buffer[Symbol.species],mv=Buffer.from([0,0,255,255]),Do=Symbol("permessage-deflate"),$t=Symbol("total-length"),Pr=Symbol("callback"),bn=Symbol("buffers"),Or=Symbol("error"),ko,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,!ko){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ko=new pv(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Pr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){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"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Hi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Do]=this,this._inflate[$t]=0,this._inflate[bn]=[],this._inflate.on("error",_v),this._inflate.on("data",Ih)}this._inflate[Pr]=i,this._inflate.write(e),r&&this._inflate.write(mv),this._inflate.flush(()=>{let c=this._inflate[Or];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=bh.concat(this._inflate[bn],this._inflate[$t]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[$t]=0,this._inflate[bn]=[],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"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Hi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[$t]=0,this._deflate[bn]=[],this._deflate.on("data",wv)}this._deflate[Pr]=i,this._deflate.write(e),this._deflate.flush(Hi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=bh.concat(this._deflate[bn],this._deflate[$t]);r&&(c=new gv(c.buffer,c.byteOffset,c.length-4)),this._deflate[Pr]=null,this._deflate[$t]=0,this._deflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Ah.exports=ud;function wv(t){this[bn].push(t),this[$t]+=t.length}function Ih(t){if(this[$t]+=t.length,this[Do]._maxPayload<1||this[$t]<=this[Do]._maxPayload){this[bn].push(t);return}this[Or]=new RangeError("Max payload size exceeded"),this[Or].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Or][Sh]=1009,this.removeListener("data",Ih),this.reset()}function _v(t){if(this[Do]._inflate=null,this[Or]){this[Pr](this[Or]);return}t[Sh]=1007,this[Pr](t)}});var Nr=ae((zR,Po)=>{"use strict";var{isUtf8:Th}=ue("buffer"),{hasBlob:yv}=Kt(),Ev=[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 vv(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 bv(t){return yv&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Po.exports={isBlob:bv,isValidStatusCode:vv,isValidUTF8:fd,tokenChars:Ev};if(Th)Po.exports.isValidUTF8=function(t){return t.length<24?fd(t):Th(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");Po.exports.isValidUTF8=function(e){return e.length<32?fd(e):t(e)}}catch{}});var md=ae((UR,Lh)=>{"use strict";var{Writable:Sv}=ue("stream"),Ch=Lr(),{BINARY_TYPES:Iv,EMPTY_BUFFER:Rh,kStatusCode:Av,kWebSocket:Tv}=Kt(),{concat:hd,toArrayBuffer:Cv,unmask:Rv}=qi(),{isValidStatusCode:kv,isValidUTF8:kh}=Nr(),Oo=Buffer[Symbol.species],ct=0,Dh=1,Ph=2,Oh=3,xd=4,pd=5,Lo=6,gd=class extends Sv{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Iv[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[Tv]=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=ct}_write(e,r,i){if(this._opcode===8&&this._state==ct)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 Oo(i.buffer,i.byteOffset+e,i.length-e),new Oo(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 Oo(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 ct:this.getInfo(e);break;case Dh:this.getPayloadLength16(e);break;case Ph:this.getPayloadLength64(e);break;case Oh:this.getMask();break;case xd:this.getData(e);break;case pd:case Lo: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[Ch.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=Ph: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=Oh:this._state=xd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xd}getData(e){let r=Rh;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&&Rv(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[Ch.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===ct&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ct;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=hd(i,r):this._binaryType==="arraybuffer"?o=Cv(hd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ct):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!0),this._state=ct,this.startLoop(e)}))}else{let o=hd(i,r);if(!this._skipUTF8Validation&&!kh(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=ct):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!1),this._state=ct,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Rh),this.end();else{let i=e.readUInt16BE(0);if(!kv(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Oo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!kh(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=ct;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ct):(this._state=Lo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ct,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[Av]=o,d}};Lh.exports=gd});var yd=ae((qR,Bh)=>{"use strict";var{Duplex:GR}=ue("stream"),{randomFillSync:Dv}=ue("crypto"),{types:{isUint8Array:Pv}}=ue("util"),Nh=Lr(),{EMPTY_BUFFER:Ov,kWebSocket:Lv,NOOP:Nv}=Kt(),{isBlob:Mr,isValidStatusCode:Mv}=Nr(),{mask:Mh,toBuffer:Hn}=qi(),dt=Symbol("kByteLength"),Bv=Buffer.alloc(4),No=8*1024,jn,Br=No,Et=0,Fv=1,zv=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=Et,this.onerror=Nv,this[Lv]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||Bv,r.generateMask?r.generateMask(i):(Br===No&&(jn===void 0&&(jn=Buffer.alloc(No)),Dv(jn,0,No),Br=0),i[0]=jn[Br++],i[1]=jn[Br++],i[2]=jn[Br++],i[3]=jn[Br++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[dt]!==void 0?u=r[dt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let h=u;u>=65536?(c+=8,h=127):u>125&&(c+=2,h=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=h,h===126?x.writeUInt16BE(u,2):h===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(Mh(e,i,x,c,u),[x]):(Mh(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=Ov;else{if(typeof e!="number"||!Mv(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(Pv(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[dt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Et?this.enqueue([this.dispatch,c,!1,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):Mr(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Mr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==Et?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):Mr(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Mr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[Nh.extensionName],c=r.binary?2:1,d=r.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):Mr(e)?(u=e.size,h=!1):(e=Hn(e),u=e.length,h=Hn.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={[dt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:d};Mr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==Et?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[dt],this._state=zv,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[dt];let d=Hn(c);r?this.dispatch(d,r,i,o):(this._state=Et,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(Uv,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Nh.extensionName];this._bufferedBytes+=i[dt],this._state=Fv,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");_d(this,h,o);return}this._bufferedBytes-=i[dt],this._state=Et,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===Et&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][dt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][dt],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)}};Bh.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 Uv(t,e,r){_d(t,e,r),t.onerror(e)}});var Kh=ae((HR,Wh)=>{"use strict";var{kForOnEventAttribute:ji,kListener:Ed}=Kt(),Fh=Symbol("kCode"),zh=Symbol("kData"),Uh=Symbol("kError"),Gh=Symbol("kMessage"),qh=Symbol("kReason"),Fr=Symbol("kTarget"),Hh=Symbol("kType"),jh=Symbol("kWasClean"),Vt=class{constructor(e){this[Fr]=null,this[Hh]=e}get target(){return this[Fr]}get type(){return this[Hh]}};Object.defineProperty(Vt.prototype,"target",{enumerable:!0});Object.defineProperty(Vt.prototype,"type",{enumerable:!0});var Wn=class extends Vt{constructor(e,r={}){super(e),this[Fh]=r.code===void 0?0:r.code,this[qh]=r.reason===void 0?"":r.reason,this[jh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Fh]}get reason(){return this[qh]}get wasClean(){return this[jh]}};Object.defineProperty(Wn.prototype,"code",{enumerable:!0});Object.defineProperty(Wn.prototype,"reason",{enumerable:!0});Object.defineProperty(Wn.prototype,"wasClean",{enumerable:!0});var zr=class extends Vt{constructor(e,r={}){super(e),this[Uh]=r.error===void 0?null:r.error,this[Gh]=r.message===void 0?"":r.message}get error(){return this[Uh]}get message(){return this[Gh]}};Object.defineProperty(zr.prototype,"error",{enumerable:!0});Object.defineProperty(zr.prototype,"message",{enumerable:!0});var Wi=class extends Vt{constructor(e,r={}){super(e),this[zh]=r.data===void 0?null:r.data}get data(){return this[zh]}};Object.defineProperty(Wi.prototype,"data",{enumerable:!0});var Gv={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[ji]&&o[Ed]===e&&!o[ji])return;let i;if(t==="message")i=function(c,d){let u=new Wi("message",{data:d?c:c.toString()});u[Fr]=this,Mo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Wn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Fr]=this,Mo(e,this,u)};else if(t==="error")i=function(c){let d=new zr("error",{error:c,message:c.message});d[Fr]=this,Mo(e,this,d)};else if(t==="open")i=function(){let c=new Vt("open");c[Fr]=this,Mo(e,this,c)};else return;i[ji]=!!r[ji],i[Ed]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ed]===e&&!r[ji]){this.removeListener(t,r);break}}};Wh.exports={CloseEvent:Wn,ErrorEvent:zr,Event:Vt,EventTarget:Gv,MessageEvent:Wi};function Mo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Bo=ae((jR,$h)=>{"use strict";var{tokenChars:Ki}=Nr();function Mt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function qv(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,h=-1,x=-1,m=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),d===void 0)if(m===-1&&Ki[x]===1)h===-1&&(h=w);else if(w!==0&&(x===32||x===9))m===-1&&h!==-1&&(m=w);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let _=t.slice(h,m);x===44?(Mt(e,_,r),r=Object.create(null)):d=_,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(m===-1&&Ki[x]===1)h===-1&&(h=w);else if(x===32||x===9)m===-1&&h!==-1&&(m=w);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w),Mt(r,t.slice(h,m),!0),x===44&&(Mt(e,d,r),r=Object.create(null),d=void 0),h=m=-1}else if(x===61&&h!==-1&&m===-1)u=t.slice(h,w),h=m=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Ki[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);h===-1?h=w:i||(i=!0),o=!1}else if(c)if(Ki[x]===1)h===-1&&(h=w);else if(x===34&&h!==-1)c=!1,m=w;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(x===34&&t.charCodeAt(w-1)===61)c=!0;else if(m===-1&&Ki[x]===1)h===-1&&(h=w);else if(h!==-1&&(x===32||x===9))m===-1&&(m=w);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let _=t.slice(h,m);i&&(_=_.replace(/\\/g,""),i=!1),Mt(r,u,_),x===44&&(Mt(e,d,r),r=Object.create(null),d=void 0),u=void 0,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=w);let b=t.slice(h,m);return d===void 0?Mt(e,b,r):(u===void 0?Mt(r,b,!0):i?Mt(r,u,b.replace(/\\/g,"")):Mt(r,u,b),Mt(e,d,r)),e}function Hv(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}$h.exports={format:Hv,parse:qv}});var Go=ae(($R,sx)=>{"use strict";var jv=ue("events"),Wv=ue("https"),Kv=ue("http"),Zh=ue("net"),$v=ue("tls"),{randomBytes:Vv,createHash:Jv}=ue("crypto"),{Duplex:WR,Readable:KR}=ue("stream"),{URL:vd}=ue("url"),Sn=Lr(),Zv=md(),Yv=yd(),{isBlob:Xv}=Nr(),{BINARY_TYPES:Vh,CLOSE_TIMEOUT:Qv,EMPTY_BUFFER:Fo,GUID:eb,kForOnEventAttribute:bd,kListener:tb,kStatusCode:nb,kWebSocket:ze,NOOP:Yh}=Kt(),{EventTarget:{addEventListener:rb,removeEventListener:ib}}=Kh(),{format:sb,parse:ob}=Bo(),{toBuffer:ab}=qi(),Xh=Symbol("kAborted"),Sd=[8,13],Jt=["CONNECTING","OPEN","CLOSING","CLOSED"],cb=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends jv{constructor(e,r,i){super(),this._binaryType=Vh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Fo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Qh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Vh.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 Zv({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 Yv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[ze]=this,c[ze]=this,e[ze]=this,o.on("conclude",ub),o.on("drain",fb),o.on("error",hb),o.on("message",xb),o.on("ping",pb),o.on("pong",gb),c.onerror=mb,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",nx),e.on("data",Uo),e.on("end",rx),e.on("error",ix),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[Sn.extensionName]&&this._extensions[Sn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){rt(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())}),tx(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||Fo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Id(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Fo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Id(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Sn.extensionName]||(o.compress=!1),this._sender.send(e||Fo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){rt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[bd])return e[tb];return null},set(e){for(let r of this.listeners(t))if(r[bd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[bd]:!0})}})});ge.prototype.addEventListener=rb;ge.prototype.removeEventListener=ib;sx.exports=ge;function Qh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Qv,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 vd)c=e;else try{c=new vd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!d&&!u?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;zo(t,I);return}let x=d?443:80,m=Vv(16).toString("base64"),w=d?Wv.request:Kv.request,b=new Set,_;if(o.createConnection=o.createConnection||(d?lb:db),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new Sn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=sb({[Sn.extensionName]:_.offer()})),r.length){for(let I of r){if(typeof I!="string"||!cb.test(I)||b.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");b.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,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")),v=t._req=w(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=w(o);o.timeout&&v.on("timeout",()=>{rt(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[Xh]||(v=t._req=null,zo(t,I))}),v.on("response",I=>{let A=I.headers.location,T=I.statusCode;if(A&&o.followRedirects&&T>=300&&T<400){if(++t._redirects>o.maxRedirects){rt(t,v,"Maximum redirects exceeded");return}v.abort();let R;try{R=new vd(A,e)}catch{let D=new SyntaxError(`Invalid URL: ${A}`);zo(t,D);return}Qh(t,R,r,i)}else t.emit("unexpected-response",v,I)||rt(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,T)=>{if(t.emit("upgrade",I),t.readyState!==ge.CONNECTING)return;v=t._req=null;let R=I.headers.upgrade;if(R===void 0||R.toLowerCase()!=="websocket"){rt(t,A,"Invalid Upgrade header");return}let y=Jv("sha1").update(m+eb).digest("base64");if(I.headers["sec-websocket-accept"]!==y){rt(t,A,"Invalid Sec-WebSocket-Accept header");return}let D=I.headers["sec-websocket-protocol"],O;if(D!==void 0?b.size?b.has(D)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":b.size&&(O="Server sent no subprotocol"),O){rt(t,A,O);return}D&&(t._protocol=D);let B=I.headers["sec-websocket-extensions"];if(B!==void 0){if(!_){rt(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=ob(B)}catch{rt(t,A,"Invalid Sec-WebSocket-Extensions header");return}let V=Object.keys(M);if(V.length!==1||V[0]!==Sn.extensionName){rt(t,A,"Server indicated an extension that was not requested");return}try{_.accept(M[Sn.extensionName])}catch{rt(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Sn.extensionName]=_}t.setSocket(A,T,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function zo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function db(t){return t.path=t.socketPath,Zh.connect(t)}function lb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Zh.isIP(t.host)?"":t.host),$v.connect(t)}function rt(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,rt),e.setHeader?(e[Xh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(zo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Id(t,e,r){if(e){let i=Xv(e)?e.size:ab(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Jt[t.readyState]})`);process.nextTick(r,i)}}function ub(t,e){let r=this[ze];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[ze]!==void 0&&(r._socket.removeListener("data",Uo),process.nextTick(ex,r._socket),t===1005?r.close():r.close(t,e))}function fb(){let t=this[ze];t.isPaused||t._socket.resume()}function hb(t){let e=this[ze];e._socket[ze]!==void 0&&(e._socket.removeListener("data",Uo),process.nextTick(ex,e._socket),e.close(t[nb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Jh(){this[ze].emitClose()}function xb(t,e){this[ze].emit("message",t,e)}function pb(t){let e=this[ze];e._autoPong&&e.pong(t,!this._isServer,Yh),e.emit("ping",t)}function gb(t){this[ze].emit("pong",t)}function ex(t){t.resume()}function mb(t){let e=this[ze];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,tx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function tx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function nx(){let t=this[ze];if(this.removeListener("close",nx),this.removeListener("data",Uo),this.removeListener("end",rx),t._readyState=ge.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[ze]=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 Uo(t){this[ze]._receiver.write(t)||this.pause()}function rx(){let t=this[ze];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function ix(){let t=this[ze];this.removeListener("error",ix),this.on("error",Yh),t&&(t._readyState=ge.CLOSING,this.destroy())}});var dx=ae((JR,cx)=>{"use strict";var VR=Go(),{Duplex:wb}=ue("stream");function ox(t){t.emit("close")}function _b(){!this.destroyed&&this._writableState.finished&&this.destroy()}function ax(t){this.removeListener("error",ax),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function yb(t,e){let r=!0,i=new wb({...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(ox,i);return}let d=!1;t.once("error",function(h){d=!0,c(h)}),t.once("close",function(){d||c(o),process.nextTick(ox,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",_b),i.on("error",ax),i}cx.exports=yb});var Ad=ae((ZR,lx)=>{"use strict";var{tokenChars:Eb}=Nr();function vb(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&&Eb[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}lx.exports={parse:vb}});var mx=ae((XR,gx)=>{"use strict";var bb=ue("events"),qo=ue("http"),{Duplex:YR}=ue("stream"),{createHash:Sb}=ue("crypto"),ux=Bo(),Kn=Lr(),Ib=Ad(),Ab=Go(),{CLOSE_TIMEOUT:Tb,GUID:Cb,kWebSocket:Rb}=Kt(),kb=/^[+/0-9A-Za-z]{22}==$/,fx=0,hx=1,px=2,Td=class extends bb{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:Tb,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Ab,...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=qo.createServer((i,o)=>{let c=qo.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=Db(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=fx}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===px){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick($i,this);return}if(e&&this.once("close",e),this._state!==hx)if(this._state=hx,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick($i,this):process.nextTick($i,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{$i(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",xx);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){$n(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){$n(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!kb.test(c)){$n(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){$n(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Vi(r,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=Ib.parse(h)}catch{$n(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&m!==void 0){let b=new Kn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=ux.parse(m);_[Kn.extensionName]&&(b.accept(_[Kn.extensionName]),w[Kn.extensionName]=b)}catch{$n(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let b={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(b,(_,v,I,A)=>{if(!_)return Vi(r,v||401,I,A);this.completeUpgrade(w,c,x,e,r,i,o)});return}if(!this.options.verifyClient(b))return Vi(r,401)}this.completeUpgrade(w,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[Rb])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>fx)return Vi(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Sb("sha1").update(r+Cb).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(x.push(`Sec-WebSocket-Protocol: ${w}`),m._protocol=w)}if(e[Kn.extensionName]){let w=e[Kn.extensionName].params,b=ux.format({[Kn.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${b}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&is(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 ug,mkdirSync as fg}from"node:fs";import{join as xg}from"node:path";function ul(t){let e=t.retentionDays??gg,r=t.clock??(()=>Rn(new Date));os={bridgeSink:new Zr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Zr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();is(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])is(t.agentLogsDir(o),"agent",i,e)}function mg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function fl(t){Ea=t}function xl(t){return ir[Ea]<=ir[t]}function hl(t,e){let r=ir[t];return r===void 0?!0:r>=ir[e]}function as(t){ll={...t}}function pl(t){let e=(u,x=2)=>String(u).padStart(x,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Rn(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:pl(new Date),level:e,module:r,msg:i,...o})}
|
|
11
|
+
`;fg(t,{recursive:!0}),ug(xg(t,rr("bridge",Rn(new Date))),c)}catch{}}function wg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function ss(t,e,r,i,o){if(ir[t]<ir[Ea])return;let c=`${JSON.stringify({ts:pl(new Date),level:t,module:e,msg:r,...ll,...i})}
|
|
12
|
+
`;if(os){let d=wg(o,i),u=d?mg(os,d):os.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?pg.write(c):hg.write(c)}function H(t,e){return{debug:(r,i)=>ss("debug",t,r,i,e),info:(r,i)=>ss("info",t,r,i,e),warn:(r,i)=>ss("warn",t,r,i,e),error:(r,i)=>ss("error",t,r,i,e),child:r=>H(`${t}.${r}`,e),forAgent:r=>H(t,r)}}var ir,Ea,hg,pg,ll,gg,os,ne=Ye(()=>{"use strict";nr();ba();ir={debug:10,info:20,warn:30,error:40},Ea=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),hg=process.stdout,pg=process.stderr,ll={},gg=je("COZE_BRIDGE_LOG_RETENTION_DAYS",30),os=null});var C,We=Ye(()=>{"use strict";C=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 _l={};_a(_l,{ACP_WRAPPER_NPM_PACKAGES:()=>Qr,_resetAcpInstallerForTests:()=>Sg,_setBinaryPathCacheForTests:()=>Ag,buildAcpSpawn:()=>ei,ensureAcpInstalled:()=>sr,getAcpBinaryPath:()=>cs,pickWhichLine:()=>Aa,probeAcpVersion:()=>vg,resolveAcpCommand:()=>wl});import{readFileSync as gl}from"node:fs";import{createRequire as _g}from"node:module";import{dirname as yg,resolve as bg}from"node:path";function Aa(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 Eg(t){let e=ml.resolve(`${t.npmPackage}/package.json`),r=yg(e),i=JSON.parse(gl(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 bg(r,o)}async function sr(t,e){let r=Sa[t];if(!r)throw new C("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Xr.get(t);if(i)return i;try{let o=Eg(r);return Xr.set(t,o),va.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw va.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new C("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 vg(t){let e=Sa[t];if(e)try{let r=ml.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(gl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){va.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function cs(t){return Xr.get(t)}function wl(t,e){if(e)return e;let r=cs(t);if(!r)throw new C("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function ei(t,e,r){if(e)return{command:e,args:[...r]};let i=wl(t);return{command:process.execPath,args:[i,...r]}}function Sg(){Xr.clear()}function Ag(t,e){Xr.set(t,e)}var va,Sa,Qr,ml,Xr,rn=Ye(()=>{"use strict";We();ne();va=H("agents.acp-installer"),Sa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},Qr=Object.values(Sa).filter(t=>t!==void 0).map(t=>t.npmPackage),ml=_g(import.meta.url),Xr=new Map});import{chmod as Tg,mkdir as Cg,readFile as Dg,rename as Rg,rm as kg,writeFile as Pg}from"node:fs/promises";import{dirname as Og}from"node:path";async function or(t){try{let e=await Dg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function sn(t,e,r){await Cg(Og(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Pg(i,e,{encoding:"utf8",mode:r?.mode}),await Rg(i,t),r?.mode!==void 0&&await Tg(t,r.mode)}catch(o){throw await kg(i,{force:!0}).catch(()=>{}),o}}async function ar(t,e,r){await sn(t,`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,r)}var on=Ye(()=>{"use strict"});import{promises as El,readdirSync as Lg}from"node:fs";import{homedir as Ng}from"node:os";import{sep as Mg,join as Ce,resolve as vl}from"node:path";function Q(t){let e=t??Ng(),r=Ce(e,".coze"),i=Ce(r,"bridge"),o=Ce(i,"lib"),c=Ce(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ce(o,"index.js"),binDir:Ce(i,"bin"),pidFile:Ce(i,"bridge.pid"),portFile:Ce(i,"bridge.port"),tokenFile:Ce(i,"bridge.token"),patTokenFile:Ce(i,"pat-token"),agentEnvFile:Ce(i,"agent-env.json"),logFile:Ce(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ce(c,"daemon-stdio.log"),installLock:Ce(i,"install.lock"),configFile:Ce(i,"config.json"),agentsRoot:Ce(r,"agents")}}function Ze(t,e=Q()){let r=Ce(e.agentsRoot,t);return{root:r,config:Ce(r,"config.json"),workspace:Ce(r,"workspace"),logs:Ce(r,"logs")}}function ds(t=Q()){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 El.realpath(vl(t)).catch(()=>null);if(!r)return!1;let i=await El.realpath(vl(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 Oe=Ye(()=>{"use strict"});var fs={};_a(fs,{AGENT_CONFIG_FILE_MODE:()=>ls,enforceAgentConfigMode:()=>Fg,loadAgentConfig:()=>Me,persistAgentSessions:()=>ni,persistAgentSkills:()=>us,saveAgentConfig:()=>Xe});import{chmod as Bg,stat as zg}from"node:fs/promises";function Me(t,e){return or(Ze(t,e).config)}function Xe(t,e){return ar(Ze(t.agentId,e).config,t,{mode:ls})}async function Fg(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await zg(r);if(!i.isFile())return;let o=i.mode&511;o!==ls&&(await Bg(r,ls),Sl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Sl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ni(t,e,r){let i=await Me(t,r);i&&(i.sessions=Object.fromEntries(e),await Xe(i,r))}async function us(t,e,r){let i=await Me(t,r);i&&(i.skills=e,await Xe(i,r))}var Sl,ls,an=Ye(()=>{"use strict";on();ne();Oe();Sl=H("agent-config"),ls=384});var Ca=ae((S2,Tl)=>{Tl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var hs=ae(Dl=>{var Cl={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(Cl))Dl[t]=Wg(Cl[t])});var Ll=ae((I2,Ol)=>{var Kg=ue("fs"),Le=ue("path"),Rl=Ca(),$g=hs(),Vg=typeof process=="object"&&process.platform==="win32",kl=t=>typeof t=="object"&&t!==null,Pl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function be(t){this.sep=Le.sep,this.fs=Kg,kl(t)&&kl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ol.exports=be;be.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw $g.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};be.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Le.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};be.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,x){if(d&&x.isDirectory())return o(!1);var p=Le.dirname(t);c.fs.exists(p,function(m){m||c.makeDir(p),c.fs.open(t,"w",438,function(w,S){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};be.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let x=Le.join(i,u),p=e.fs.statSync(x);(!o||o.test(x))&&d.push(Le.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(d=d.concat(r(x,o,c)))}),d}return r(t,void 0,!0)};be.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Le.join(t,u),r.fs.stat(u,function(x,p){if(x)return e(x);p&&(i.push(Le.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(m,w){if(m)return e(m);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Pl[(t^e)&255]^t>>>8};be.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=be.crc32update(r,t[i++]);return~r>>>0};be.methodToString=function(t){switch(t){case Rl.STORED:return"STORED ("+t+")";case Rl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.posix.join(".",e)};be.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};be.sanitize=function(t,e){t=Le.resolve(Le.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Le.normalize(Le.join(t,r.slice(i,o).join(Le.sep)));if(c.indexOf(t)===0)return c}return Le.normalize(Le.join(t,Le.basename(e)))};be.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};be.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};be.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};be.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};be.isWin=Vg;be.crcTable=Pl});var Ml=ae((T2,Nl)=>{var Jg=ue("path");Nl.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=ae((C2,Bl)=>{Bl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var lr=ae((D2,dr)=>{dr.exports=Ll();dr.exports.Constants=Ca();dr.exports.Errors=hs();dr.exports.FileAttr=Ml();dr.exports.decoder=zl()});var Ul=ae((R2,Fl)=>{var cn=lr(),U=cn.Constants;Fl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,x=0,p=0,m=0,w=0,S=0,_=0,v=0;t|=cn.isWin?2560:768,r|=U.FLG_EFS;let A={extraLen:0},T=y=>Math.max(0,y)>>>0,D=y=>Math.max(0,y)&65535,k=y=>Math.max(0,y)&255;return o=cn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&U.FLG_EFS)>0},set flags_efs(y){y?r|=U.FLG_EFS:r&=~U.FLG_EFS},get flags_desc(){return(r&U.FLG_DESC)>0},set flags_desc(y){y?r|=U.FLG_DESC:r&=~U.FLG_DESC},get method(){return i},set method(y){switch(y){case U.STORED:this.version=10;case U.DEFLATED:default:this.version=20}i=y},get time(){return cn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=cn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=T(y)},get timeHighByte(){return k(o>>>8)},get crc(){return c},set crc(y){c=T(y)},get compressedSize(){return d},set compressedSize(y){d=T(y)},get size(){return u},set size(y){u=T(y)},get fileNameLength(){return x},set fileNameLength(y){x=y},get extraLength(){return p},set extraLength(y){p=y},get extraLocalLength(){return A.extraLen},set extraLocalLength(y){A.extraLen=y},get commentLength(){return m},set commentLength(y){m=y},get diskNumStart(){return w},set diskNumStart(y){w=T(y)},get inAttr(){return S},set inAttr(y){S=T(y)},get attr(){return _},set attr(y){_=T(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return v},set offset(y){v=T(y)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+x+p+m},get realDataOffset(){return v+U.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(y){var R=y.slice(v,v+U.LOCHDR);if(R.readUInt32LE(0)!==U.LOCSIG)throw cn.Errors.INVALID_LOC();A.version=R.readUInt16LE(U.LOCVER),A.flags=R.readUInt16LE(U.LOCFLG),A.flags_desc=(A.flags&U.FLG_DESC)>0,A.method=R.readUInt16LE(U.LOCHOW),A.time=R.readUInt32LE(U.LOCTIM),A.crc=R.readUInt32LE(U.LOCCRC),A.compressedSize=R.readUInt32LE(U.LOCSIZ),A.size=R.readUInt32LE(U.LOCLEN),A.fnameLen=R.readUInt16LE(U.LOCNAM),A.extraLen=R.readUInt16LE(U.LOCEXT);let P=v+U.LOCHDR+A.fnameLen,B=P+A.extraLen;return y.slice(P,B)},loadFromBinary:function(y){if(y.length!==U.CENHDR||y.readUInt32LE(0)!==U.CENSIG)throw cn.Errors.INVALID_CEN();t=y.readUInt16LE(U.CENVEM),e=y.readUInt16LE(U.CENVER),r=y.readUInt16LE(U.CENFLG),i=y.readUInt16LE(U.CENHOW),o=y.readUInt32LE(U.CENTIM),c=y.readUInt32LE(U.CENCRC),d=y.readUInt32LE(U.CENSIZ),u=y.readUInt32LE(U.CENLEN),x=y.readUInt16LE(U.CENNAM),p=y.readUInt16LE(U.CENEXT),m=y.readUInt16LE(U.CENCOM),w=y.readUInt16LE(U.CENDSK),S=y.readUInt16LE(U.CENATT),_=y.readUInt32LE(U.CENATX),v=y.readUInt32LE(U.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(U.LOCHDR);return y.writeUInt32LE(U.LOCSIG,0),y.writeUInt16LE(e,U.LOCVER),y.writeUInt16LE(r,U.LOCFLG),y.writeUInt16LE(i,U.LOCHOW),y.writeUInt32LE(o,U.LOCTIM),y.writeUInt32LE(c,U.LOCCRC),y.writeUInt32LE(d,U.LOCSIZ),y.writeUInt32LE(u,U.LOCLEN),y.writeUInt16LE(x,U.LOCNAM),y.writeUInt16LE(A.extraLen,U.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(U.CENHDR+x+p+m);return y.writeUInt32LE(U.CENSIG,0),y.writeUInt16LE(t,U.CENVEM),y.writeUInt16LE(e,U.CENVER),y.writeUInt16LE(r,U.CENFLG),y.writeUInt16LE(i,U.CENHOW),y.writeUInt32LE(o,U.CENTIM),y.writeUInt32LE(c,U.CENCRC),y.writeUInt32LE(d,U.CENSIZ),y.writeUInt32LE(u,U.CENLEN),y.writeUInt16LE(x,U.CENNAM),y.writeUInt16LE(p,U.CENEXT),y.writeUInt16LE(m,U.CENCOM),y.writeUInt16LE(w,U.CENDSK),y.writeUInt16LE(S,U.CENATT),y.writeUInt32LE(_,U.CENATX),y.writeUInt32LE(v,U.CENOFF),y},toJSON:function(){let y=function(R){return R+" bytes"};return{made:t,version:e,flags:r,method:cn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(x),extraLength:y(p),commentLength:y(m),diskNumStart:w,inAttr:S,attr:_,offset:v,centralHeaderSize:y(U.CENHDR+x+p+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Hl=ae((k2,Gl)=>{var ur=lr(),we=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 we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw ur.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=ur.readBigUInt64LE(c,we.ZIP64SUB),e=ur.readBigUInt64LE(c,we.ZIP64TOT),r=ur.readBigUInt64LE(c,we.ZIP64SIZE),i=ur.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(d,u){let x=d.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ra=ae(Da=>{Da.EntryHeader=Ul();Da.MainHeader=Hl()});var jl=ae((O2,ql)=>{ql.exports=function(t){var e=ue("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),x=0;u.fill(0);for(var p=0;p<c.length;p++){var m=c[p];m.copy(u,x),x+=m.length}i&&i(u)}),o.end(t)}}}});var Kl=ae((L2,Wl)=>{var Yg=+(process.versions?process.versions.node:"").split(".")[0]||0;Wl.exports=function(t,e){var r=ue("zlib");let i=Yg>=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(x){d.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),p=0;x.fill(0);for(var m=0;m<d.length;m++){var w=d[m];w.copy(x,p),p+=w.length}o&&o(x)}),c.end(t)}}}});var Zl=ae((N2,Yl)=>{"use strict";var{randomFillSync:$l}=ue("crypto"),Zg=hs(),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}),Jl=(t,e)=>Math.imul(t,e)>>>0,Vl=(t,e)=>Xg[(t^e)&255]^t>>>8,ri=()=>typeof $l=="function"?$l(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 ps={genSalt:ri};function gs(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let r=0;r<e.length;r++)this.updateKeys(e[r])}gs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Vl(e[0],t),e[1]+=e[0]&255,e[1]=Jl(e[1],134775813)+1,e[2]=Vl(e[2],e[1]>>>24),t};gs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Jl(t,t^1)>>8&255};function Qg(t){let e=new gs(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function em(t){let e=new gs(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 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 Zg.WRONG_PASSWORD();return i(t.slice(12))}function nm(t){Buffer.isBuffer(t)&&t.length>=12?ps.genSalt=function(){return t.slice(0,12)}:t==="node"?ps.genSalt=ri.node:ps.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=ps.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)}Yl.exports={decrypt:tm,encrypt:rm,_salter:nm}});var Xl=ae(ms=>{ms.Deflater=jl();ms.Inflater=Kl();ms.ZipCrypto=Zl()});var Pa=ae((B2,Ql)=>{var ce=lr(),im=Ra(),Ee=ce.Constants,ka=Xl();Ql.exports=function(t,e){var r=new im.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let m=t,w=typeof m.decoder=="object"?m.decoder:ce.decoder;p=w.hasOwnProperty("efs")?w.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(y)!==r.localHeader.crc)return!1}else{let R={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==Ee.LOCSIG||e.readUInt32LE(P)==Ee.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==Ee.EXTSIG)R.crc=e.readUInt32LE(P+Ee.EXTCRC),R.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ),R.size=e.readUInt32LE(P+Ee.EXTLEN);else if(e.readUInt16LE(P+12)===19280)R.crc=e.readUInt32LE(P+Ee.EXTCRC-4),R.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ-4),R.size=e.readUInt32LE(P+Ee.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(R.compressedSize!==r.compressedSize||R.size!==r.size||R.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(y)!==R.crc)return!1}return!0}function v(y,R,P){if(typeof R>"u"&&typeof y=="string"&&(P=y,y=void 0),c)return y&&R&&R(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=S();if(B.length===0)return y&&R&&R(B),B;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw ce.Errors.INVALID_PASS_PARAM();B=ka.ZipCrypto.decrypt(B,r,P)}var N=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(B.copy(N),_(N))return y&&R&&R(N),N;throw y&&R&&R(N,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var Y=new ka.Inflater(B,r.size);if(y)Y.inflateAsync(function(J){J.copy(J,0),R&&(_(J)?R(J):R(J,ce.Errors.BAD_CRC()))});else{if(Y.inflate(N).copy(N,0),!_(N))throw ce.Errors.BAD_CRC(`"${w.decode(i)}"`);return N}break;default:throw y&&R&&R(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function A(y,R){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&R&&R(S()),S();if(d.length&&!c){var P;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(d.length),d.copy(P),y&&R&&R(P),P;default:case ce.Constants.DEFLATED:var B=new ka.Deflater(d);if(y)B.deflateAsync(function(Y){P=Buffer.alloc(Y.length),r.compressedSize=Y.length,Y.copy(P),R&&R(P)});else{var N=B.deflate();return r.compressedSize=N.length,N}B=null;break}}else if(y&&R)R(Buffer.alloc(0));else return Buffer.alloc(0)}function T(y,R){return ce.readBigUInt64LE(y,R)}function D(y){try{for(var R=0,P,B,N;R+4<y.length;)P=y.readUInt16LE(R),R+=2,B=y.readUInt16LE(R),R+=2,N=y.slice(R,R+B),R+=B,Ee.ID_ZIP64===P&&k(N)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function k(y){var R,P,B,N;y.length>=Ee.EF_ZIP64_SCOMP&&(R=T(y,Ee.EF_ZIP64_SUNCOMP),r.size===Ee.EF_ZIP64_OR_32&&(r.size=R)),y.length>=Ee.EF_ZIP64_RHO&&(P=T(y,Ee.EF_ZIP64_SCOMP),r.compressedSize===Ee.EF_ZIP64_OR_32&&(r.compressedSize=P)),y.length>=Ee.EF_ZIP64_DSN&&(B=T(y,Ee.EF_ZIP64_RHO),r.offset===Ee.EF_ZIP64_OR_32&&(r.offset=B)),y.length>=Ee.EF_ZIP64_DSN+4&&(N=y.readUInt32LE(Ee.EF_ZIP64_DSN),r.diskNumStart===Ee.EF_ZIP64_OR_16&&(r.diskNumStart=N))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=ce.toBuffer(y,w.encode);var R=i[i.length-1];c=R===47||R===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,D(y)},get comment(){return w.decode(o)},set comment(y){if(o=ce.toBuffer(y,w.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(y){A(!0,y)},setData:function(y){d=ce.toBuffer(y,ce.decoder.encode),!c&&d.length?(r.size=d.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(y),r.changed=!0):r.method=ce.Constants.STORED},getData:function(y){return r.changed?d:v(!1,null,y)},getDataAsync:function(y,R){r.changed?y(d):v(!0,y,R)},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(),R=ce.Constants.CENHDR;return i.copy(y,R),R+=i.length,u.copy(y,R),R+=r.extraLength,o.copy(y,R),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let R=r.localHeaderToBinary(),P=Buffer.alloc(R.length+i.length+r.extraLocalLength);return R.copy(P,y),y+=R.length,i.copy(P,y),y+=i.length,x.copy(P,y),y+=x.length,P},toJSON:function(){let y=function(R){return"<"+(R&&R.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var nu=ae((z2,tu)=>{var eu=Pa(),sm=Ra(),qe=lr();tu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new sm.MainHeader,d=!1,u=null;let x=new Set,p=e,{noSort:m,decoder:w}=p;t?v(p.readEntries):d=!0;function S(){let T=new Set;for(let D of Object.keys(i)){let k=D.split("/");if(k.pop(),!!k.length)for(let y=0;y<k.length;y++){let R=k.slice(0,y+1).join("/")+"/";T.add(R)}}for(let D of T)if(!(D in i)){let k=new eu(p);k.entryName=D,k.attr=16,k.temporary=!0,r.push(k),i[k.entryName]=k,x.add(k)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var T=c.offset,D=0;D<r.length;D++){var k=T,y=new eu(p,t);y.header=t.slice(k,k+=qe.Constants.CENHDR),y.entryName=t.slice(k,k+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(k,k+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(k,k+y.header.commentLength)),T+=y.header.centralHeaderSize,r[D]=y,i[y.entryName]=y}x.clear(),S()}function v(T){var D=t.length-qe.Constants.ENDHDR,k=Math.max(0,D-65535),y=k,R=t.length,P=-1,B=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(k=0),D;D>=y;D--)if(t[D]===80){if(t.readUInt32LE(D)===qe.Constants.ENDSIG){P=D,B=D,R=D+qe.Constants.ENDHDR,y=D-qe.Constants.END64HDR;continue}if(t.readUInt32LE(D)===qe.Constants.END64SIG){y=k;continue}if(t.readUInt32LE(D)===qe.Constants.ZIP64SIG){P=D,R=D+qe.readBigUInt64LE(t,D+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(P==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,R)),c.commentLength&&(o=t.slice(B+qe.Constants.ENDHDR)),T&&_()}function A(){r.length>1&&!m&&r.sort((T,D)=>T.entryName.toLowerCase().localeCompare(D.entryName.toLowerCase()))}return{get entries(){return d||_(),r.filter(T=>!x.has(T))},get comment(){return w.decode(o)},set comment(T){o=qe.toBuffer(T,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(T){this.entries.forEach(T)},getEntry:function(T){return d||_(),i[T]||null},setEntry:function(T){d||_(),r.push(T),i[T.entryName]=T,c.totalEntries=r.length},deleteFile:function(T,D=!0){d||_();let k=i[T];this.getEntryChildren(k,D).map(R=>R.entryName).forEach(this.deleteEntry)},deleteEntry:function(T){d||_();let D=i[T],k=r.indexOf(D);k>=0&&(r.splice(k,1),delete i[T],c.totalEntries=r.length)},getEntryChildren:function(T,D=!0){if(d||_(),typeof T=="object")if(T.isDirectory&&D){let k=[],y=T.entryName;for(let R of r)R.entryName.startsWith(y)&&k.push(R);return k}else return[T];return[]},getChildCount:function(T){if(T&&T.isDirectory){let D=this.getEntryChildren(T);return D.includes(T)?D.length-1:D.length}return 0},compressToBuffer:function(){d||_(),A();let T=[],D=[],k=0,y=0;c.size=0,c.offset=0;let R=0;for(let N of this.entries){let Y=N.getCompressedData();N.header.offset=y;let J=N.packLocalHeader(),te=J.length+Y.length;y+=te,T.push(J),T.push(Y);let Z=N.packCentralHeader();D.push(Z),c.size+=Z.length,k+=te+Z.length,R++}k+=c.mainHeaderSize,c.offset=y,c.totalEntries=R,y=0;let P=Buffer.alloc(k);for(let N of T)N.copy(P,y),y+=N.length;for(let N of D)N.copy(P,y),y+=N.length;let B=c.toBinary();return o&&o.copy(B,qe.Constants.ENDHDR),B.copy(P,y),t=P,d=!1,P},toAsyncBuffer:function(T,D,k,y){try{d||_(),A();let R=[],P=[],B=0,N=0,Y=0;c.size=0,c.offset=0;let J=function(te){if(te.length>0){let Z=te.shift(),ie=Z.entryName+Z.extra.toString();k&&k(ie),Z.getCompressedDataAsync(function(oe){y&&y(ie),Z.header.offset=N;let O=Z.packLocalHeader(),q=O.length+oe.length;N+=q,R.push(O),R.push(oe);let V=Z.packCentralHeader();P.push(V),c.size+=V.length,B+=q+V.length,Y++,J(te)})}else{B+=c.mainHeaderSize,c.offset=N,c.totalEntries=Y,N=0;let Z=Buffer.alloc(B);R.forEach(function(oe){oe.copy(Z,N),N+=oe.length}),P.forEach(function(oe){oe.copy(Z,N),N+=oe.length});let ie=c.toBinary();o&&o.copy(ie,qe.Constants.ENDHDR),ie.copy(Z,N),t=Z,d=!1,T(Z)}};J(Array.from(this.entries))}catch(R){D(R)}}}}});var su=ae((F2,iu)=>{var ye=lr(),_e=ue("path"),om=Pa(),am=nu(),kn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),ru=(...t)=>ye.findLast(t,e=>typeof e=="string"),cm=(...t)=>ye.findLast(t,e=>typeof e=="function"),dm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};iu.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=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new am(r,i),{canonical:d,sanitize:u,zipnamefix:x}=ye;function p(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(_e.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function m(_){let{join:v,normalize:A,sep:T}=_e.posix;return v(_e.isAbsolute(_)?"/":".",A(T+_.split("\\").join(T)+T))}function w(_){return _ instanceof RegExp?(function(v){return function(A){return v.test(A)}})(_):typeof _!="function"?()=>!0:_}let S=(_,v)=>{let A=v.slice(-1);return A=A===o.sep?o.sep:"",_e.relative(_,v)+A};return{readFile:function(_,v){var A=p(_);return A&&A.getData(v)||null},childCount:function(_){let v=p(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var A=p(_);A?A.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var A=p(_);if(A){var T=A.getData();if(T&&T.length)return T.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,A){var T=p(_);T?T.getDataAsync(function(D,k){if(k){v(D,k);return}D&&D.length?v(D.toString(A||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var A=p(_);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(_){var v=p(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var A=p(_);A&&(A.comment=v)},getZipEntryComment:function(_){var v=p(_);return v&&v.comment||""},updateFile:function(_,v){var A=p(_);A&&A.setData(v)},addLocalFile:function(_,v,A,T){if(o.fs.existsSync(_)){v=v?m(v):"";let D=_e.win32.basename(_e.win32.normalize(_));v+=A||D;let k=o.fs.statSync(_),y=k.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);k.isDirectory()&&(v+=o.sep),this.addFile(v,y,T,k)}else throw ye.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let A=_e.resolve(_.localPath),{comment:T}=_,{zipPath:D,zipName:k}=_,y=this;o.fs.stat(A,function(R,P){if(R)return v(R,!1);D=D?m(D):"";let B=_e.win32.basename(_e.win32.normalize(A));if(D+=k||B,P.isFile())o.fs.readFile(A,function(N,Y){return N?v(N,!1):(y.addFile(D,Y,T,P),setImmediate(v,void 0,!0))});else if(P.isDirectory())return D+=o.sep,y.addFile(D,Buffer.alloc(0),T,P),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,A){if(A=w(A),v=v?m(v):"",_=_e.normalize(_),o.fs.existsSync(_)){let T=o.findFiles(_),D=this;if(T.length)for(let k of T){let y=_e.join(v,S(_,k));A(y)&&D.addLocalFile(k,_e.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,A,T){T=w(T),A=A?m(A):"",_=_e.normalize(_);var D=this;o.fs.open(_,"r",function(k){if(k&&k.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(_));else if(k)v(void 0,k);else{var y=o.findFiles(_),R=-1,P=function(){if(R+=1,R<y.length){var B=y[R],N=S(_,B).split("\\").join("/");N=N.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),T(N)?o.fs.stat(B,function(Y,J){Y&&v(void 0,Y),J.isFile()?o.fs.readFile(B,function(te,Z){te?v(void 0,te):(D.addFile(A+N,Z,"",J),P())}):(D.addFile(A+N+"/",Buffer.alloc(0),"",J),P())}):process.nextTick(()=>{P()})}else v(!0,void 0)};P()}})},addLocalFolderAsync2:function(_,v){let A=this;_=typeof _=="object"?_:{localPath:_},localPath=_e.resolve(m(_.localPath));let{zipPath:T,filter:D,namefix:k}=_;D instanceof RegExp?D=(function(P){return function(B){return P.test(B)}})(D):typeof D!="function"&&(D=function(){return!0}),T=T?m(T):"",k=="latin1"&&(k=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof k!="function"&&(k=P=>P);let y=P=>_e.join(T,k(S(localPath,P))),R=P=>_e.win32.basename(_e.win32.normalize(k(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?v(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):P?v(void 0,P):o.findFilesAsync(localPath,function(B,N){if(B)return v(B);N=N.filter(Y=>D(y(Y))),N.length||v(void 0,!1),setImmediate(N.reverse().reduce(function(Y,J){return function(te,Z){if(te||Z===!1)return setImmediate(Y,te,!1);A.addLocalFileAsync({localPath:J,zipPath:_e.dirname(y(J)),zipName:R(J)},Y)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((A,T)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(D,k)=>{D&&T(D),k&&A(this)})})},addFile:function(_,v,A,T){_=x(_);let D=p(_),k=D!=null;k||(D=new om(i),D.entryName=_),D.comment=A||"";let y=typeof T=="object"&&T instanceof o.fs.Stats;y&&(D.header.time=T.mtime);var R=D.isDirectory?16:0;let P=D.isDirectory?16384:32768;return y?P|=4095&T.mode:typeof T=="number"?P|=4095&T:P|=D.isDirectory?493:420,R=(R|P<<16)>>>0,D.attr=R,D.setData(v),k||c.setEntry(D),D},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return p(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,A,T,D,k){T=kn(!1,T),D=kn(!1,D),A=kn(!0,A),k=ru(D,k);var y=p(_);if(!y)throw ye.Errors.NO_ENTRY();var R=d(y.entryName),P=u(v,k&&!y.isDirectory?k:A?R:_e.basename(R));if(y.isDirectory){var B=c.getEntryChildren(y);return B.forEach(function(J){if(J.isDirectory)return;var te=J.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var Z=d(J.entryName),ie=u(v,A?Z:_e.basename(Z));let oe=D?J.header.fileAttr:void 0;o.writeFileTo(ie,te,T,oe)}),!0}var N=y.getData(c.password);if(!N)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!T)throw ye.Errors.CANT_OVERRIDE();let Y=D?_.header.fileAttr:void 0;return o.writeFileTo(P,N,T,Y),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var A=c.entries[v].getData(_);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(_,v,A,T){if(A=kn(!1,A),T=ru(A,T),v=kn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(D){var k=u(_,d(D.entryName));if(D.isDirectory){o.makeDir(k);return}var y=D.getData(T);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let R=A?D.header.fileAttr:void 0;o.writeFileTo(k,y,v,R);try{o.fs.utimesSync(k,D.header.time,D.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,A,T){if(T=cm(v,A,T),A=kn(!1,A),v=kn(!1,v),!T)return new Promise((P,B)=>{this.extractAllToAsync(_,v,A,function(N){N?B(N):P(this)})});if(!c){T(ye.Errors.NO_ZIP());return}_=_e.resolve(_);let D=P=>u(_,_e.normalize(d(P.entryName))),k=(P,B)=>new Error(P+': "'+B+'"'),y=[],R=[];c.entries.forEach(P=>{P.isDirectory?y.push(P):R.push(P)});for(let P of y){let B=D(P),N=A?P.header.fileAttr:void 0;try{o.makeDir(B),N&&o.fs.chmodSync(B,N),o.fs.utimesSync(B,P.header.time,P.header.time)}catch{T(k("Unable to create folder",B))}}R.reverse().reduce(function(P,B){return function(N){if(N)P(N);else{let Y=_e.normalize(d(B.entryName)),J=u(_,Y);B.getDataAsync(function(te,Z){if(Z)P(Z);else if(!te)P(ye.Errors.CANT_EXTRACT_FILE());else{let ie=A?B.header.fileAttr:void 0;o.writeFileToAsync(J,te,v,ie,function(oe){oe||P(k("Unable to write file",J)),o.fs.utimes(J,B.header.time,B.header.time,function(O){O?P(k("Unable to set times",J)):P()})})}})}}},T)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var A=c.compressToBuffer();if(A){var T=o.writeFileTo(_,A,!0);typeof v=="function"&&v(T?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:A,perm:T}=Object.assign({overwrite:!0},v);return new Promise((D,k)=>{!_&&i.filename&&(_=i.filename),_||k("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let R=P=>P?D(P):k("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,A,T,R)},k)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,A,T){return typeof _=="function"?(c.toAsyncBuffer(_,v,A,T),null):c.compressToBuffer()}}}});import{execFile as p_,spawn as g_,spawnSync as rI}from"node:child_process";import{promisify as m_}from"node:util";function __(t){if(process.platform!=="win32")return!1;if(S0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(S0,"").toLowerCase();return w_.has(r)}function A0(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 et(t,e=[],r={}){return g_(t,e,A0(t,r))}function I0(t,e=[],r={}){return y_(t,e,A0(t,r))}var w_,S0,y_,Kt=Ye(()=>{"use strict";w_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),S0=/\.(cmd|bat|ps1)$/i;y_=m_(p_)});var Vt=ae((L3,nx)=>{"use strict";var ex=["nodebuffer","arraybuffer","fragments"],tx=typeof Blob<"u";tx&&ex.push("blob");nx.exports={BINARY_TYPES:ex,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:tx,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ji=ae((N3,vo)=>{"use strict";var{EMPTY_BUFFER:Zb}=Vt(),sd=Buffer[Symbol.species];function Xb(t,e){if(t.length===0)return Zb;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new sd(r.buffer,r.byteOffset,i):r}function rx(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function ix(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function Qb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function od(t){if(od.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new sd(t):ArrayBuffer.isView(t)?e=new sd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),od.readOnly=!1),e}vo.exports={concat:Xb,mask:rx,toArrayBuffer:Qb,toBuffer:od,unmask:ix};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");vo.exports.mask=function(e,r,i,o,c){c<48?rx(e,r,i,o,c):t.mask(e,r,i,o,c)},vo.exports.unmask=function(e,r){e.length<32?ix(e,r):t.unmask(e,r)}}catch{}});var ax=ae((M3,ox)=>{"use strict";var sx=Symbol("kDone"),ad=Symbol("kRun"),cd=class{constructor(e){this[sx]=()=>{this.pending--,this[ad]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[ad]()}[ad](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[sx])}}};ox.exports=cd});var Br=ae((B3,ux)=>{"use strict";var Wi=ue("zlib"),cx=ji(),eE=ax(),{kStatusCode:dx}=Vt(),tE=Buffer[Symbol.species],nE=Buffer.from([0,0,255,255]),Ao=Symbol("permessage-deflate"),Jt=Symbol("total-length"),Nr=Symbol("callback"),In=Symbol("buffers"),Mr=Symbol("error"),So,dd=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!So){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;So=new 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){So.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){So.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"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Wi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Ao]=this,this._inflate[Jt]=0,this._inflate[In]=[],this._inflate.on("error",iE),this._inflate.on("data",lx)}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 d=cx.concat(this._inflate[In],this._inflate[Jt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Jt]=0,this._inflate[In]=[],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"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Wi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Jt]=0,this._deflate[In]=[],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=cx.concat(this._deflate[In],this._deflate[Jt]);r&&(c=new tE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Nr]=null,this._deflate[Jt]=0,this._deflate[In]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};ux.exports=dd;function rE(t){this[In].push(t),this[Jt]+=t.length}function lx(t){if(this[Jt]+=t.length,this[Ao]._maxPayload<1||this[Jt]<=this[Ao]._maxPayload){this[In].push(t);return}this[Mr]=new RangeError("Max payload size exceeded"),this[Mr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Mr][dx]=1009,this.removeListener("data",lx),this.reset()}function iE(t){if(this[Ao]._inflate=null,this[Mr]){this[Nr](this[Mr]);return}t[dx]=1007,this[Nr](t)}});var zr=ae((z3,Io)=>{"use strict";var{isUtf8:fx}=ue("buffer"),{hasBlob:sE}=Vt(),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 ld(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function 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")}Io.exports={isBlob:cE,isValidStatusCode:aE,isValidUTF8:ld,tokenChars:oE};if(fx)Io.exports.isValidUTF8=function(t){return t.length<24?ld(t):fx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");Io.exports.isValidUTF8=function(e){return e.length<32?ld(e):t(e)}}catch{}});var pd=ae((F3,yx)=>{"use strict";var{Writable:dE}=ue("stream"),xx=Br(),{BINARY_TYPES:lE,EMPTY_BUFFER:hx,kStatusCode:uE,kWebSocket:fE}=Vt(),{concat:ud,toArrayBuffer:xE,unmask:hE}=ji(),{isValidStatusCode:pE,isValidUTF8:px}=zr(),To=Buffer[Symbol.species],dt=0,gx=1,mx=2,_x=3,fd=4,xd=5,Co=6,hd=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=dt}_write(e,r,i){if(this._opcode===8&&this._state==dt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new To(i.buffer,i.byteOffset+e,i.length-e),new To(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new To(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case dt:this.getInfo(e);break;case gx:this.getPayloadLength16(e);break;case mx:this.getPayloadLength64(e);break;case _x:this.getMask();break;case fd:this.getData(e);break;case xd:case Co: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[xx.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=gx:this._payloadLength===127?this._state=mx: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=_x:this._state=fd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=fd}getData(e){let r=hx;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=xd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[xx.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===dt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=dt;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=ud(i,r):this._binaryType==="arraybuffer"?o=xE(ud(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=dt):(this._state=Co,setImmediate(()=>{this.emit("message",o,!0),this._state=dt,this.startLoop(e)}))}else{let o=ud(i,r);if(!this._skipUTF8Validation&&!px(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===xd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=dt):(this._state=Co,setImmediate(()=>{this.emit("message",o,!1),this._state=dt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,hx),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 To(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!px(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=dt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=dt):(this._state=Co,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=dt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(d,this.createError),d.code=c,d[uE]=o,d}};yx.exports=hd});var wd=ae((G3,vx)=>{"use strict";var{Duplex:U3}=ue("stream"),{randomFillSync:gE}=ue("crypto"),{types:{isUint8Array:mE}}=ue("util"),bx=Br(),{EMPTY_BUFFER:wE,kWebSocket:_E,NOOP:yE}=Vt(),{isBlob:Fr,isValidStatusCode:bE}=zr(),{mask:Ex,toBuffer:Kn}=ji(),lt=Symbol("kByteLength"),EE=Buffer.alloc(4),Do=8*1024,$n,Ur=Do,vt=0,vE=1,SE=2,gd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=vt,this.onerror=yE,this[_E]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||EE,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++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[lt]!==void 0?u=r[lt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);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],d?[p,e]:o?(Ex(e,i,p,c,u),[p]):(Ex(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"||!bE(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={[lt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==vt?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Fr(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 d={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Fr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Fr(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 d={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Fr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[bx.extensionName],c=r.binary?2:1,d=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Fr(e)?(u=e.size,x=!1):(e=Kn(e),u=e.length,x=Kn.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 p={[lt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:d};Fr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==vt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[lt],this._state=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(md,this,u,o);return}this._bufferedBytes-=i[lt];let d=Kn(c);r?this.dispatch(d,r,i,o):(this._state=vt,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(AE,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[lt],this._state=vE,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");md(this,x,o);return}this._bufferedBytes-=i[lt],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][lt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][lt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};vx.exports=gd;function md(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function AE(t,e,r){md(t,e,r),t.onerror(e)}});var Px=ae((H3,kx)=>{"use strict";var{kForOnEventAttribute:Ki,kListener:_d}=Vt(),Sx=Symbol("kCode"),Ax=Symbol("kData"),Ix=Symbol("kError"),Tx=Symbol("kMessage"),Cx=Symbol("kReason"),Gr=Symbol("kTarget"),Dx=Symbol("kType"),Rx=Symbol("kWasClean"),Yt=class{constructor(e){this[Gr]=null,this[Dx]=e}get target(){return this[Gr]}get type(){return this[Dx]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Vn=class extends Yt{constructor(e,r={}){super(e),this[Sx]=r.code===void 0?0:r.code,this[Cx]=r.reason===void 0?"":r.reason,this[Rx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Sx]}get reason(){return this[Cx]}get wasClean(){return this[Rx]}};Object.defineProperty(Vn.prototype,"code",{enumerable:!0});Object.defineProperty(Vn.prototype,"reason",{enumerable:!0});Object.defineProperty(Vn.prototype,"wasClean",{enumerable:!0});var Hr=class extends Yt{constructor(e,r={}){super(e),this[Ix]=r.error===void 0?null:r.error,this[Tx]=r.message===void 0?"":r.message}get error(){return this[Ix]}get message(){return this[Tx]}};Object.defineProperty(Hr.prototype,"error",{enumerable:!0});Object.defineProperty(Hr.prototype,"message",{enumerable:!0});var $i=class extends Yt{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 IE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ki]&&o[_d]===e&&!o[Ki])return;let i;if(t==="message")i=function(c,d){let u=new $i("message",{data:d?c:c.toString()});u[Gr]=this,Ro(e,this,u)};else if(t==="close")i=function(c,d){let u=new Vn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Gr]=this,Ro(e,this,u)};else if(t==="error")i=function(c){let d=new Hr("error",{error:c,message:c.message});d[Gr]=this,Ro(e,this,d)};else if(t==="open")i=function(){let c=new Yt("open");c[Gr]=this,Ro(e,this,c)};else return;i[Ki]=!!r[Ki],i[_d]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[_d]===e&&!r[Ki]){this.removeListener(t,r);break}}};kx.exports={CloseEvent:Vn,ErrorEvent:Hr,Event:Yt,EventTarget:IE,MessageEvent:$i};function Ro(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var ko=ae((q3,Ox)=>{"use strict";var{tokenChars:Vi}=zr();function Nt(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,d,u,x=-1,p=-1,m=-1,w=0;for(;w<t.length;w++)if(p=t.charCodeAt(w),d===void 0)if(m===-1&&Vi[p]===1)x===-1&&(x=w);else if(w!==0&&(p===32||p===9))m===-1&&x!==-1&&(m=w);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let _=t.slice(x,m);p===44?(Nt(e,_,r),r=Object.create(null)):d=_,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(m===-1&&Vi[p]===1)x===-1&&(x=w);else if(p===32||p===9)m===-1&&x!==-1&&(m=w);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w),Nt(r,t.slice(x,m),!0),p===44&&(Nt(e,d,r),r=Object.create(null),d=void 0),x=m=-1}else if(p===61&&x!==-1&&m===-1)u=t.slice(x,w),x=m=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Vi[p]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);x===-1?x=w:i||(i=!0),o=!1}else if(c)if(Vi[p]===1)x===-1&&(x=w);else if(p===34&&x!==-1)c=!1,m=w;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(p===34&&t.charCodeAt(w-1)===61)c=!0;else if(m===-1&&Vi[p]===1)x===-1&&(x=w);else if(x!==-1&&(p===32||p===9))m===-1&&(m=w);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let _=t.slice(x,m);i&&(_=_.replace(/\\/g,""),i=!1),Nt(r,u,_),p===44&&(Nt(e,d,r),r=Object.create(null),d=void 0),u=void 0,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(x===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=w);let S=t.slice(x,m);return d===void 0?Nt(e,S,r):(u===void 0?Nt(r,S,!0):i?Nt(r,u,S.replace(/\\/g,"")):Nt(r,u,S),Nt(e,d,r)),e}function 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(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Ox.exports={format:CE,parse:TE}});var No=ae((K3,Wx)=>{"use strict";var DE=ue("events"),RE=ue("https"),kE=ue("http"),Mx=ue("net"),PE=ue("tls"),{randomBytes:OE,createHash:LE}=ue("crypto"),{Duplex:j3,Readable:W3}=ue("stream"),{URL:yd}=ue("url"),Tn=Br(),NE=pd(),ME=wd(),{isBlob:BE}=zr(),{BINARY_TYPES:Lx,CLOSE_TIMEOUT:zE,EMPTY_BUFFER:Po,GUID:FE,kForOnEventAttribute:bd,kListener:UE,kStatusCode:GE,kWebSocket:Ge,NOOP:Bx}=Vt(),{EventTarget:{addEventListener:HE,removeEventListener:qE}}=Px(),{format:jE,parse:WE}=ko(),{toBuffer:KE}=ji(),zx=Symbol("kAborted"),Ed=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],$E=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends DE{constructor(e,r,i){super(),this._binaryType=Lx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Po,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Fx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Lx.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",YE),o.on("drain",ZE),o.on("error",XE),o.on("message",QE),o.on("ping",ev),o.on("pong",tv),c.onerror=nv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Hx),e.on("data",Lo),e.on("end",qx),e.on("error",jx),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){st(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),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){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Po,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Po,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Tn.extensionName]||(o.compress=!1),this._sender.send(e||Po,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[bd])return e[UE];return null},set(e){for(let r of this.listeners(t))if(r[bd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[bd]:!0})}})});ge.prototype.addEventListener=HE;ge.prototype.removeEventListener=qE;Wx.exports=ge;function Fx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:zE,protocolVersion:Ed[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Ed.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Ed.join(", ")})`);let c;if(e instanceof yd)c=e;else try{c=new yd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!d&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let A=new SyntaxError(x);if(t._redirects===0)throw A;Oo(t,A);return}let p=d?443:80,m=OE(16).toString("base64"),w=d?RE.request:kE.request,S=new Set,_;if(o.createConnection=o.createConnection||(d?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":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new Tn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=jE({[Tn.extensionName]:_.offer()})),r.length){for(let A of r){if(typeof A!="string"||!$E.test(A)||S.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(A)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[T,D]of Object.entries(A))i.headers[T.toLowerCase()]=D}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=w(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=w(o);o.timeout&&v.on("timeout",()=>{st(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[zx]||(v=t._req=null,Oo(t,A))}),v.on("response",A=>{let T=A.headers.location,D=A.statusCode;if(T&&o.followRedirects&&D>=300&&D<400){if(++t._redirects>o.maxRedirects){st(t,v,"Maximum redirects exceeded");return}v.abort();let k;try{k=new yd(T,e)}catch{let R=new SyntaxError(`Invalid URL: ${T}`);Oo(t,R);return}Fx(t,k,r,i)}else t.emit("unexpected-response",v,A)||st(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,T,D)=>{if(t.emit("upgrade",A),t.readyState!==ge.CONNECTING)return;v=t._req=null;let k=A.headers.upgrade;if(k===void 0||k.toLowerCase()!=="websocket"){st(t,T,"Invalid Upgrade header");return}let y=LE("sha1").update(m+FE).digest("base64");if(A.headers["sec-websocket-accept"]!==y){st(t,T,"Invalid Sec-WebSocket-Accept header");return}let R=A.headers["sec-websocket-protocol"],P;if(R!==void 0?S.size?S.has(R)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":S.size&&(P="Server sent no subprotocol"),P){st(t,T,P);return}R&&(t._protocol=R);let B=A.headers["sec-websocket-extensions"];if(B!==void 0){if(!_){st(t,T,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let N;try{N=WE(B)}catch{st(t,T,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(N);if(Y.length!==1||Y[0]!==Tn.extensionName){st(t,T,"Server indicated an extension that was not requested");return}try{_.accept(N[Tn.extensionName])}catch{st(t,T,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Tn.extensionName]=_}t.setSocket(T,D,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Oo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function VE(t){return t.path=t.socketPath,Mx.connect(t)}function JE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Mx.isIP(t.host)?"":t.host),PE.connect(t)}function st(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,st),e.setHeader?(e[zx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Oo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function vd(t,e,r){if(e){let i=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 YE(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",Lo),process.nextTick(Ux,r._socket),t===1005?r.close():r.close(t,e))}function ZE(){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",Lo),process.nextTick(Ux,e._socket),e.close(t[GE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Nx(){this[Ge].emitClose()}function QE(t,e){this[Ge].emit("message",t,e)}function ev(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Bx),e.emit("ping",t)}function tv(t){this[Ge].emit("pong",t)}function Ux(t){t.resume()}function nv(t){let e=this[Ge];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.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",Lo),this.removeListener("end",qx),t._readyState=ge.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Nx),t._receiver.on("finish",Nx))}function Lo(t){this[Ge]._receiver.write(t)||this.pause()}function qx(){let t=this[Ge];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function jx(){let t=this[Ge];this.removeListener("error",jx),this.on("error",Bx),t&&(t._readyState=ge.CLOSING,this.destroy())}});var Jx=ae((V3,Vx)=>{"use strict";var $3=No(),{Duplex:rv}=ue("stream");function Kx(t){t.emit("close")}function iv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function $x(t){this.removeListener("error",$x),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function sv(t,e){let r=!0,i=new rv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Kx,i);return}let d=!1;t.once("error",function(x){d=!0,c(x)}),t.once("close",function(){d||c(o),process.nextTick(Kx,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",iv),i.on("error",$x),i}Vx.exports=sv});var Sd=ae((J3,Yx)=>{"use strict";var{tokenChars:ov}=zr();function av(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&ov[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}Yx.exports={parse:av}});var rh=ae((Z3,nh)=>{"use strict";var cv=ue("events"),Mo=ue("http"),{Duplex:Y3}=ue("stream"),{createHash:dv}=ue("crypto"),Zx=ko(),Jn=Br(),lv=Sd(),uv=No(),{CLOSE_TIMEOUT:fv,GUID:xv,kWebSocket:hv}=Vt(),pv=/^[+/0-9A-Za-z]{22}==$/,Xx=0,Qx=1,th=2,Ad=class extends cv{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:fv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:uv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Mo.createServer((i,o)=>{let c=Mo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=gv(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=Xx}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===th){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!==Qx)if(this._state=Qx,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",eh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Yn(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){Yn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!pv.test(c)){Yn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Yn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Yi(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=lv.parse(x)}catch{Yn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&m!==void 0){let S=new Jn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=Zx.parse(m);_[Jn.extensionName]&&(S.accept(_[Jn.extensionName]),w[Jn.extensionName]=S)}catch{Yn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,v,A,T)=>{if(!_)return Yi(r,v||401,A,T);this.completeUpgrade(w,c,p,e,r,i,o)});return}if(!this.options.verifyClient(S))return Yi(r,401)}this.completeUpgrade(w,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[hv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Xx)return Yi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${dv("sha1").update(r+xv).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(p.push(`Sec-WebSocket-Protocol: ${w}`),m._protocol=w)}if(e[Jn.extensionName]){let w=e[Jn.extensionName].params,S=Zx.format({[Jn.extensionName]:[w]});p.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),c.removeListener("error",
|
|
16
|
+
`)),c.removeListener("error",eh),m.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(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Ji,this)})),u(m,o)}};nh.exports=Ad;function gv(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function Ji(t){t._state=th,t.emit("close")}function eh(){this.destroy()}function Yi(t,e,r,i){r=r||Mo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Mo.STATUS_CODES[e]}\r
|
|
17
17
|
`+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
|
|
18
18
|
`)+`\r
|
|
19
19
|
\r
|
|
20
|
-
`+r)}function $n(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,$n),t.emit("wsClientError",d,r,e)}else Vi(r,i,o,c)}});import{existsSync as rS,openSync as iS}from"node:fs";import{mkdir as sS}from"node:fs/promises";import{dirname as oS}from"node:path";import{fileURLToPath as aS}from"node:url";function dS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Pd(t=Y()){return rS(t.libEntry)?t.libEntry:aS(new URL("../index.ts",import.meta.url))}async function Dx(t={}){let e=t.paths??Y(),r=t.entryOverride??Pd(e),i=dS(e,process.env.COZE_BRIDGE_LOG_MODE);await sS(oS(i),{recursive:!0});let o=iS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=at(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Yi]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return cS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var cS,Yi,$o=Je(()=>{"use strict";yn();ne();ke();cS=U("spawn-daemon"),Yi="COZE_BRIDGE_DAEMON"});import{spawn as n1}from"node:child_process";import{mkdir as r1,unlink as i1,writeFile as s1}from"node:fs/promises";import{dirname as o1,join as a1}from"node:path";function Hr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function c1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Hr(r)}</key>
|
|
21
|
-
<string>${
|
|
20
|
+
`+r)}function Yn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,Yn),t.emit("wsClientError",d,r,e)}else Yi(r,i,o,c)}});var gh=ae(Ie=>{"use strict";var L=G;(function(t,e){let r=G,i=t();for(;;)try{if(-parseInt(r(1824))/1+-parseInt(r(1590))/2*(-parseInt(r(556))/3)+parseInt(r(1279))/4*(parseInt(r(1703))/5)+-parseInt(r(680))/6*(parseInt(r(727))/7)+parseInt(r(1008))/8*(-parseInt(r(1047))/9)+parseInt(r(1303))/10+parseInt(r(747))/11===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(qo,143067);var Sv=Object[L(408)+L(1395)],Av=Object[L(1591)+L(942)+L(1447)],uh=(t,e)=>function(){return t&&(e=(0,t[{Paqfc:function(c,d){return c(d)}}[L(1014)](Av,t)[0]])(t=0)),e},Iv=(t,e)=>{for(var r in e)Sv(t,r,{get:e[r],enumerable:!0})};function Tv(){return oh||(oh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Cv(){let t=L;return ah||(ah=[IDBCursor[t(765)+"e"][t(1753)],IDBCursor[t(765)+"e"].continue,IDBCursor[t(765)+"e"][t(1610)+t(1115)+"ey"]])}function Dv(t){let e=L,r={aPKdy:function(o,c){return o(c)},qSVVl:function(o,c){return o!==c},nqRmW:function(o,c){return o===c},iwTyI:e(800),kdvgU:e(1506),eVRtw:e(1430),hCUtg:function(o){return o()},dgvcK:function(o,c){return o-c},SbBDD:function(o,c){return o!==c},GgIZE:e(1532),hcJqG:e(1146),CXVby:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={BoTip:function(x,p){return x instanceof p},XhTXk:function(x,p){return x(p)},bxvhT:function(x,p){return r[G(606)](x,p)},ugGbX:function(x,p){return r[G(1257)](x,p)},nZgwd:r[d(1666)],EFuAi:r[d(1570)],PARNY:r.eVRtw,VrqRo:function(x){return r[d(1380)](x)},DBFGd:function(x,p){return x>=p},idCfO:function(x,p){return r[d(1455)](x,p)}};if(r[d(435)](r.GgIZE,r[d(988)])){let x=()=>{let w=d;if(u.ugGbX(u[w(1913)],w(800)))t[w(686)+w(1522)+w(768)](u[w(749)],p),t[w(686)+w(1522)+w(768)](u.PARNY,m);else{if(u[w(1343)](_0x3dfaff,_0x5dc362))return u[w(491)](_0x43ace3,_0xf5da7f);if(_0xceb340[w(1541)](_0xdea501))return _0x3e04c4.get(_0x9e5f44);let S=_0x121dfe(_0x5f0570);return u[w(547)](S,_0x27e8b3)&&(_0x32c5d2[w(1434)](_0x425747,S),_0x478179[w(1434)](S,_0x5a0680)),S}},p=()=>{let w=d;u.XhTXk(o,Bt(t[w(2023)])),u.VrqRo(x)},m=()=>{let w=d;r[w(1452)](c,t[w(1430)]),x()};t["addEvent"+d(1301)](d(1506),p),t[d(1051)+"Listener"](r[d(390)],m)}else return!!(u.DBFGd(this[d(1277)+d(1729)],this.endpoints.length)||u[d(1539)](this.currentIndex,u.idCfO(this[d(1113)+"s"][d(1053)],1))&&u[d(1539)](this[d(1921)+d(456)+d(501)+"t"],this[d(1862)+"es"]))});return i[e(1327)](o=>{let c=e;r[c(1832)](o,IDBCursor)&&Td[c(1434)](o,t)})[e(632)](()=>{}),Go[e(1434)](i,t),i}function Rv(t){let e=L,r={LvCVB:function(o){return o()},csodU:function(o){return o()},dHScf:e(1847),Phnyn:e(1430),kvias:function(o,c){return o(c)},gIxCx:e(1996)+"or"};if(Uo[e(1541)](t))return;let i=new Promise((o,c)=>{let d=e,u={cWoQw:r[d(970)],vLXSV:r[d(637)],lOQaV:"abort",jmHan:function(w,S){return r[d(906)](w,S)},eqGLn:r[d(1742)],bupgZ:function(w){return r[d(415)](w)}},x=()=>{let w=d;t[w(686)+"entListe"+w(768)](u[w(1782)],p),t["removeEv"+w(1522)+"ner"](u[w(572)],m),t[w(686)+w(1522)+w(768)](u.lOQaV,m)},p=()=>{r[d(415)](o),r.csodU(x)},m=()=>{let w=d;u.jmHan(c,t[w(1430)]||new DOMException(u[w(1589)],u[w(1589)])),u[w(779)](x)};t[d(1051)+d(1301)]("complete",p),t[d(1051)+d(1301)](r.Phnyn,m),t[d(1051)+d(1301)](d(1553),m)});Uo.set(t,i)}function kv(t){Ho=t(Ho)}function Pv(t){let e=L,r={dBVzn:function(i,o){return i*o},qpnSx:function(i,o){return i>o},jvQyg:function(i,o){return i(o)},fnudK:function(i,o){return i(o)},gRHkZ:function(i,o,c){return i(o,c)},LHiQy:e(2008),kCVhE:e(508)+e(1901)+e(1205)+e(1417),mdNGM:function(i,o){return i!==o},vptiy:e(1111),ROXas:function(i,o){return i(o)},nBeIX:function(i,o){return i in o},auciP:e(636)};if(t===IDBDatabase[e(765)+"e"][e(1615)+e(1563)]&&!r[e(1681)](e(1560)+e(589),IDBTransaction.prototype))if(r[e(1804)](r[e(1924)],r[e(1924)])){let{initReconnectInterval:i,maxReconnectInterval:o,reconnectIntervalGrowFactor:c}=this[e(738)],d=r[e(1305)](i,_0x63901b.pow(c,_0x27871f-1));return r.qpnSx(d,o)?o:d}else return function(i,...o){let c=e,d=t.call(r[c(912)](Zi,this),i,...o);return Id[c(1434)](d,i.sort?i[c(1490)]():[i]),r.fnudK(Bt,d)};if(Cv().includes(t))if(r[e(1804)]("WXXHK",e(549))){if(this._clearPingTimer(),this["_clearTi"+e(872)](),this[e(1392)+e(1813)+"rs"](),this[e(1206)+e(1945)](1e3,_0x286e79),this[e(527)+"Lock"]=!1,_0x5c1dbf&&this[e(1754)+e(875)]()&&!this[e(450)+e(1228)]){if(this[e(1117)+e(978)]?.[e(1245)+e(958)+"es"]()){let o=this[e(1117)+e(978)]?.getCurrentEndpoint();this["_dispatc"+e(1157)+"ent"](r.gRHkZ(_0xaeb56e,r[e(1224)],{code:1006,reason:e(1494)+o+(e(1756)+e(449)+e(775)+"ached"),wasClean:!0}))}else{let o=this._options[e(868)+e(1549)+e(1833)](_0x27affb,_0x3dc58a);this[e(607)+e(1157)+e(597)](_0x3ef586("close",{code:_0x2bd0ce,reason:_0x3416fd,wasClean:!0,willReconnect:o})),o&&this[e(527)]()}return}this._navigatorOnline()||this._readyClosed?this["_dispatc"+e(1157)+e(597)](_0x24fee5(r[e(1224)],{code:_0x3a49dd,reason:e(432)})):this[e(607)+e(1157)+"ent"](_0x3f8bd0(e(2008),{code:1006,reason:r[e(835)]})),this[e(1852)]=null,this[e(1117)+e(978)]?.[e(1381)+e(1619)+e(1851)](),this[e(2037)+e(561)]?.[e(416)+"nter"]()}else return function(...i){let o=e;return t[o(567)](r.jvQyg(Zi,this),i),Bt(Td[o(1278)](this))};return function(...i){let o=e;if(r[o(1804)](r.vptiy,o(1147)))return r[o(1606)](Bt,t[o(567)](Zi(this),i));this[o(1733)](o(2027),r.gRHkZ(_0x52072c,"message",{..._0x13bbb4}))}}function Ov(t){let e=L,r={EZjDJ:function(i,o){return i===o},KgWhY:"function",XDtvH:function(i,o){return i(o)},ffnxz:function(i,o){return i instanceof o},TthUd:function(i,o){return i(o)},ucgdy:function(i,o,c){return i(o,c)},zHdyQ:function(i){return i()}};return r[e(1411)](typeof t,r[e(2009)])?r[e(1897)](Pv,t):(r[e(1369)](t,IDBTransaction)&&r[e(599)](Rv,t),r[e(541)](fh,t,r[e(1424)](Tv))?new Proxy(t,Ho):t)}function Bt(t){let e=L,r={TFbAC:function(o,c){return o instanceof c},ztGqH:function(o,c){return o(c)},TwaWp:function(o,c){return o!==c},Rmpyg:function(o,c){return o!==c},FxWlY:"aBiNE",Aprjx:e(806)};if(r[e(1517)](t,IDBRequest))return r[e(856)](Dv,t);if(zo[e(1541)](t))return zo[e(1278)](t);let i=Ov(t);return r[e(1622)](i,t)&&(r[e(919)](r[e(622)],r[e(859)])?(zo[e(1434)](t,i),Go[e(1434)](i,t)):(_0x18e12b(this[e(527)+e(1152)+e(1287)]),this[e(527)+e(1152)+e(1287)]=null)),i}var fh,oh,ah,Td,Uo,Id,zo,Go,Ho,Zi,ch=uh({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={IEMFS:function(r,i){return r instanceof i},teQaR:function(r,i){return r===i},gVneR:function(r,i){return r===i},wKnLl:t(1560)+t(589),DxOta:t(1172),SRhWU:function(r,i){return r<<i},gOdAJ:function(r,i){return r+i},PaAjB:function(r,i){return r|i},XiOWa:function(r,i){return r<<i},yaxkt:t(1078),oBIFW:function(r,i){return r===i},ONVXB:t(922)};fh=(r,i)=>i[t(913)](o=>r instanceof o),Td=new WeakMap,Uo=new WeakMap,Id=new WeakMap,zo=new WeakMap,Go=new WeakMap,Ho={get(r,i,o){let c=t;if(e[c(1170)](r,IDBTransaction)){if(e[c(889)](i,c(922)))return Uo[c(1278)](r);if(e[c(1099)](i,e[c(1274)]))return r[c(1560)+c(589)]||Id[c(1278)](r);if(i===e.DxOta)return o[c(1560)+c(589)][1]?void 0:o[c(1560)+"ore"](o[c(1560)+c(589)][0])}return Bt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t,c={QTLGv:function(d,u){return d|u},fxhYL:function(d,u){return e.SRhWU(d,u)},gMAQM:function(d,u){return e.gOdAJ(d,u)},kTtsz:function(d,u){return e[G(1822)](d,u)},XrtMc:function(d,u){return d<<u},WJvqE:function(d,u){return e[G(625)](d,u)},KGOTw:function(d,u){return d+u},gSDfg:function(d,u){return d+u}};if(e[o(1099)](o(1213),e.yaxkt)){let d=new _0xb04e68(c[o(1720)](c.fxhYL(_0x2fa404[c[o(1367)](_0x3c0431,4)],24),_0x315b18[c.gMAQM(_0x36cab5,5)]<<16)|c[o(710)](_0x448e28[c[o(1367)](_0x465b37,6)],8)|_0x4d77cc[c[o(1367)](_0x3807c1,7)],c.QTLGv(c[o(750)](c[o(750)](c.XrtMc(_0x517de5[_0x5b0ffa+0],24),c.WJvqE(_0x1b2f2c[c.gMAQM(_0x508579,1)],16)),_0x2eb709[c.KGOTw(_0x81d792,2)]<<8),_0x200dfa[c.gMAQM(_0x180a05,3)]),!0);return _0x4b12f3+=8,{value:d,offset:c.gSDfg(_0x55f2c7,8)}}else return e[o(1170)](r,IDBTransaction)&&(e[o(1106)](i,e[o(1102)])||e[o(1099)](i,"store"))?!0:i in r}},Zi=r=>Go[t(1278)](r)}}),xh={};Iv(xh,{deleteDB:()=>Nv,openDB:()=>Lv,unwrap:()=>Zi,wrap:()=>Bt});function Lv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=L,u={CALuy:function(m,w){return m!==w},dDUqp:d(1940),uWApg:function(m,w,S,_,v){return m(w,S,_,v)},NQSUX:function(m,w){return m(w)},mHsFF:d(2008),JBZPa:d(697)+d(841),NgsEP:d(886)+d(1585),OHHCU:d(695)},x=indexedDB[d(1980)](t,e),p=u[d(457)](Bt,x);return i&&x[d(1051)+"Listener"](u[d(1642)],m=>{let w=d;u.CALuy(w(1940),u[w(696)])?(this["_message"+w(531)][w(1292)](),this[w(1005)+"Queue"][w(1582)](_0x2171a6)):u[w(1569)](i,u[w(457)](Bt,x[w(2023)]),m[w(828)+"on"],m[w(962)+"on"],Bt(x["transact"+w(1563)]))}),r&&x["addEvent"+d(1301)](u[d(1890)],()=>r()),p.then(m=>{let w=d;c&&m["addEvent"+w(1301)](u[w(1288)],()=>c()),o&&m[w(1051)+"Listener"](u.JBZPa,()=>o())})[d(632)](()=>{}),p}function Nv(t,{blocked:e}={}){let r=L,i={RDzJm:r(695),Bzqvk:function(c,d){return c(d)}},o=indexedDB[r(1421)+r(477)](t);return e&&o[r(1051)+r(1301)](i[r(1149)],()=>e()),i[r(1597)](Bt,o)[r(1327)](()=>{})}function qo(){let t=["tMDZrva","CLnWExa","zNvUy3rPB24","B25LCNjVCG","t3DXt0W","q1LcC1y","A1vNtvO","vLnnv1O","vvPHsfK","vvniswy","y0XqAfm","BgLUzq","s0nrD3i","zKr2DgW","Dg9cExrLC0W","Bw1bEee","t3rItxi","t0vVvwe","BLzethG","y2HHCKnVzgu","tvncseW","t1fvr24","qMXbA2q","AwrI","AxDuEuK","D1L4yNK","ve1ktLi","tNPcEwe","zhPtBui","zKHYA1C","DgvmB2Djre4","zgfPCfq","D2j4z0e","D3z4B3u","zxjFywnRx20","wvf4qMi","D3jPDgu","oxW2Fdv8mxW","AKDsrgu","BKjLsvG","r3n0zLe","v0XvB2G","yMzzwhm","u1rjv2C","AxPutfK","ywnRx2nVzgu","AgXSDwK","v0X5sgG","suLYsuS","z2v0qwXS","zNjVBunOyxi","y0nREMW","z2v0q3vYC28","yNL0zxm","qwDJwLa","Exb1D1G","yMzxuNC","qKjZEgS","Chv0","qNDQB3q","ywvVC1u","mZbVBe1xug4","nxWWFdn8nNW","Bg9NsurozxC","ENPXBM8","q09otKvdveK","CMfNzvn5BMm","zxjYtM8","ruHOEfq","CfDYB20","u2nOAKm","mNWXmhW4Fdm","zMLSDgvY","ywDL","y2HLy2TdDxi","CMvHzhLtDge","B2LUDfjLywm","EhDUyxu","uvrmr3y","qKDvv2q","mxWY","zuv4Dhm","B0nVExe","x19LC01Vzhu","uMvHzcbWyxm","zKPns3a","x2jPBMfYEvq","BMrLEa","x29UvgLTzw8","CfbABK4","ENPsEwW","zw1PDa","vwHeCgu","rhj3Avq","sLbAvvm","y2XLyxjtDg8","C3nWAu8","zLv6q0G","y3jLyxrLt2i","sKPovuq","z0L4q3G","D3jPDgvvAw4","vgLjzNy","DwnNyMq","uvflB3a","Bhm6ia","ENflsM0","AuPlCMi","ru1ptM4","C3vIC3rYAw4","vxHtDLG","ywr2yw5Jzq","x25HDMLNyxq","tKfusvzfx0u","ihrPBwvVDxq","yxjYyxLIDwy","yK1jrwm","zhP5Eue","CIb0DhDjra","BLfNru4","ugfQyNu","twTiz3O","A3DvAKG","twLZC2LUzYa","CMvHzhDYAxq","yxnL","y3zvug8","zxjFCw9Z","x1fVu01HBMe","y29UBMvJDgK","sgr0v0C","yxnZAwDU","DMvUDa","y3L1BeW","DvLAzhK","rhzbC1a","DMfSDwvZ","C3jJ","B1nyEwK","v25lEfu","y1DVuxC","uKjorgK","AK1rEvm","x2zVCM1HDeu","vgfKtxy","C2DPza","wuTmse8","wNPuuKK","DM9lu0S","zw15tuq","EvjLy29UBMu","ihrYEsbYzwm","CMvWBgfJzq","CM9YrxzLBNq","y1jMr2u","Cw9Z","uMvJB25Uzwm","tg9JAW","svDUq2q","zufJAW","vvDMt2i","BM5Ly3q","Bwror00","ugTTyKq","CgLUz19VBMm","EhboDu4","nhWWFdj8m3W","z25sEvy","wgnIAhm","CgPqBfO","yK9Tr1e","C0XPC3rLBMu","zxHWB3j0CW","Ae5hDeC","AgPzCvi","CwrrswS","runKuxa","q0jsrha","C0L0rMu","ywDLrxzLBNq","ugfbAKi","zvzYAMu","mtuXmta1t01rC1jj","A1HHAKq","DNzeDLe","z2u6ia","q1zpA2y","EMPHAK0","ueTqu1m","Ef9MCM9UDgK","q1HwyNK","ChrVCG","y1rItve","zxjFCw9Zx2e","tuvtu0fhrv8","zfHYzw4","vxbKue0","D1HlENm","A2HLCgO","DNzXyxK","BNruCMLLC0m","yMLUyxj5vhK","Fdb8nhW3Fdu","tfn3AuS","z0fPAg8","y29TCgXLDgu","z1jWBvy","Dgf2CNq","BhbYBuW","zMLN","x3DZ","vffMzgm","qw9ozeC","zw5JB2rPBMC","q1HIuhm","y2vkrhu","rgfrAvK","qw1VDw50","uLvdBKi","BeLsqMG","Bwf4uMv0CMK","vM9wtwq","y3vYDMfSDwu","uuv3zwK","C2fNzq","x2LZqNjVD3m","B2zMBgLUzq","zxjYtxnN","r3nxqLy","BfrPBwvVDxq","tvP1ywC","B3v0sw50zxi","AxjZsfu","z2vrDwv1zuW","u2H1s1G","yLDmqwe","zgvSzxrL","ywnRDxbfBMq","yxbWBgLJyxq","BMCGDxjSoIa","rhPVENm","BwLZzq","BMvJDa","yMPjzwm","Eendy1K","vLvRtLu","sfz0ufy","z2jmy2y","t0Hiq1u","weH4s3G","zw5fDMvUDa","z1rPBwvVDxq","thP4BM0","x21PBMLoyxy","Dg9tDhjPBMC","wer0DKG","EfvhqwG","DwnHteC","t0PQBKy","yxKSig5LDhC","svzsEe8","BwLUzW","rMf1C0K","Cw1tC0K","EhjkExu","AKfcExG","BezSDxnO","u09UuwC","Bg9Nsurhzw4","ign1CNnVCIa","B1bPBe4","BLPND2q","wKXuzum","u1jkrvu","ufrRuhe","DhjcCgS","qKnqtMi","vgXuDMi","y29UC3rYDwm","y3vYCMvUDeu","tMPhuwy","EwLzweq","yxvJAva","Bg9IywXty28","yxzABxq","ExzYrhq","v2LUvwC","CKHZzgi","B25mAw5L","CNnVCL9Uyw0","wuvsq08","yLf4Bxa","uMDVD0W","wfPZv3m","t3bzu2S","tgDLEgm","tKTKC3m","AhrQq1u","qvrhwfu","z015sgO","zxrxB3jRq2G","A2v5CW","Avbdz3C","BMnLq2XVC2u","rfnLtKK","x2nYzwf0zvm","q2XkCMy","Dhn5z1i","m3W0","uxDAuNO","uhLhuw8","qujwrMO","BwrHugG","qKvuuu4","vw9oDKO","CMfTzq","ysbTDxn0igi","yxv0B21HDgK","Euf4uhO","vgH2A2S","CMv0CNLdB3u","mdaWmdaWmda","uw1sEvC","rNvnA2i","AgHSDeq","wgzxy0u","qMreC3m","DgnyyKG","q0DKzui","DgLTzw91DcW","CNPprgC","EhHgC2u","y3zVve4","DNzoBfG","ihjLy29UBMu","y3jLyxrLq2W","zxH0zw5ZAw8","Ag9TzMC","B3bLBG","zw5NDgG","y3DZBeG","x2HHBMrSzu8","vfv0yMG","Ae1jt1e","veDxDgW","q1rOqui","C2vYDMLJzq","EMPNrwS","A09owui","DxjS","B25Uzwn0Aw4","weDwsMS","B25JBg9Zzq","B3Dfy2G","qwjVCNrfCNi","D25uruq","t0n3te0","DNrYD00","B2nRzxrgywK","weDkv0O","u2HHCMvKv28","zhHeuMO","x0vysvnu","Dg9VigXHCMC","C2vUzf9Hy2S","AxbVqxi","y2XVC2u","s2DxAfK","B25SAw5L","zMzMzG","DwzWqM0","tNrjufm","x2LZtwLUAvq","sefRrKe","ww1qCvO","C2vUza","s0n2wfG","AgvHzgvYCW","D0PiBe4","rLDt","AxnFywnR","CMvZDwX0","thz0EKG","Dgzzz2u","AM9PBG","BwvZC2fNzq","mNWXFdq","CgfNzwHPzgu","wKz0BKm","Du5KwNG","zufHBxi","rLjptLrjrvi","zMHPAKq","z2v0sxrLBq","wvHPt1m","x3bPBMDmB3m","Cg9PBNrbBMq","D2LSBfjLy28","ze1PEhK","tNjqDfC","vMjLz08","CMvHzg9UBhK","wurLtxC","zMLUza","q05Lv0e","Du1VCxu","zcWG","zvzsDhC","zgvS","CNnVCL92ywW","sw9dy08","A0HJAK0","BwfW","vwj4B2y","y3ruAw1LB3u","BM93","yLfQD1e","v3HwEuK","t1Hdquu","CMvKDwnL","x2LUAxq","x0rctMfTzq","BwLUAvbYB2C","Ew5gqwO","aaaaaaaaaaa","zgvMAw5Luhi","DxHjA00","v3rSBMW","y2zxvxm","shrpv3e","Efrurw52","rxb1vM8","thzdvKi","CMvZzxrdB3u","AfL2uLq","A29gvKi","AwXSihvZzsa","Cvfgy2q","A2rPsuC","z2P6we0","ihrVihjLDhi","ueLIy1e","z2v0qwXSs2u","C2v0sxrLBq","EvLVuui","sLfZBfe","zK55EMy","q0Xpu0ve","shLhy1a","yNLL","tufyx1jfvfi","u05QBfe","u2jcreq","rK5Uqxm","ywrKq291BNq","vgHZCu4","x2LZv29YA2u","BuTkuMq","zNrkreO","zNzQuNO","q3vZDg9Tq2W","sNnVwvu","ELbgvwu","BxnN","EMD0Auq","uxnUCMS","lcbTyxGGCMu","x3jLywr5q2W","CujOvNe","te1Yv3G","EenXt1O","rffAqvm","C3rHCNq","BMrWB2LUDfq","tLftvvG","rvHwrfK","zxjHDg9Y","m3WY","AM9LteC","DMzPyvy","tKPPzuW","uMz5EKC","yKDxAue","B0fWy2y","BLvlC0y","yNH3vNy","Exf0EK0","yMfJA3vWigu","CunswKW","AxmGDw5Kzwy","zcWGDw5RBM8","Bhz0Axi","x3bYzwzPEa","EM9prxy","DgfIyxnL","zu5qufi","rw5JCvi","AgfZt3DUuhi","q3vZDg9Trxi","u1H6u0K","twvZC2fNzuu","z2vtEw5J","whbTD2m","r1n0Cw4","AwfKu2G","BMvLzf9Hy2S","C2zMt1m","suDsENa","wgHuwgS","CMvHC29U","y3vYC29Y","re1tCue","x3bPBMDqB24","BKXPBMu","tM5zBeq","Aw1LCYbPBIa","yuvyvfa","BgLTAxq","CMLLC0nVDw4","qNfHtgC","AxnmB25N","r1n6Bu0","wLHMrLC","vKf2z2S","x3bHDgHlzxK","z29PBMCGyxC","B25ozxr3B3i","zuf1y0e","z3bVugG","u0HWs2W","BwvKAwf0zwW","teHpz1a","u2vXsuq","CK9ftxG","EgH0DKW","z0TzDgO","AxvXveO","wvnAzhm","vwHKCe8","CM5UB1i","DhDVCMTdAge","qufdqKq","y0Xzwhm","l3DZl3yY","x2nVBM5Ly3q","A29WzxO","q0Xpu0LorW","Du5IEgC","uxvLDwu","zfDVCMTLCKC","Au9Sr3G","rMTNrKi","C2nYAxb0","sK1hzK4","x2n1CNnVCKy","qvLkqMK","B2nKEeG","q095tLi","DwnNzhK","vuXUtum","AhzkwKq","DxbKyxrLq3u","yufeC1q","swLoBNy","yNH2Afq","B25szwnLAxy","v1HyseS","tLP2AwO","y2XVC2veqG","CM92AwrLihC","C0zgzvu","yM9L","v1bHsgO","mJu0ne5LEhLoAa","zMXVB3i","Aw50zwDLCIa","u3LgvwS","wfHNv3i","C0nVDw50zxi","z0n4AwC","Ew11AKi","CgLUz0XVC3m","Cw9Zx18","vw5PBxbSzw0","yxbWBhK","q1nlzLe","zgvJB2rLzey","x29UtwvZC2e","qM9zvgm","DKXyu1y","uhjxqLG","yujiuxe","Cujlu0m","u1HvuhO","CgfYC2u","uNHKqNm","sgTcsxO","C3vIyxjYyxK","x2DLDeLUDgu","AuHHAxO","rxjkzLO","tffNBNa","qw5HCg0","y3vZDg9Tshq","sLnptLa","zvvYBa","B3jLtMfTzxm","ug1oy3u","x2DLBMvYyxq","qNfnCMW","mNWXFdb8nhW","B29hzvK","r25Rq3m","zK1yww4","zw50","AxDowKS","vhrOvwq","BML0AwfSAxO","ue9Ss00","y3jLyxrLtwu","qvbbz1C","rKLmrv9ot1q","ueTjz0q","CvnwvMW","x2rPC3bHDgm","zNjVBuHHC2G","rwrOvfG","Efj1tLu","z3f3vwO","zLPZrfa","zvrdvLC","z3PmAuq","sev6rgS","EgLdueS","A2PRu3y","D2HtDKC","qxvcwMG","tKDFrvjst1i","u1bPALC","rNHxBfK","yxHQuvy","Aer1DfC","wgLpv2e","rwvcEMG","ignVzgu6ia","yw5Hz2vY","CgXLyxnLiha","BMX4yKO","rM1HyM8","y2f0y2G","yMTvshe","zhv5Ehu","ze1wr1a","EvvWC04","ugHUEw4","Aw47y2HHCNm","D1DVzLe","zMX1C2HfEha","Euv6ELC","Dwf4u0i","y3jLyxrLt3a","zMjRvuW","mhWXFdz8oxW","D24GCMvHC28","vgzUsha","Aw5JBhvKzxm","B0n1C0O","tw9KDwXL","tfD0DKq","x2n1CNnVCK4","EwTjteW","rerJu2m","x2LUDgvYDMe","vhDSDfy","lcbxzwjtB2m","Aw5N","AgvKtwf4uMu","Euj4yuq","uePvC2i","zM9Yy2u","t1bftL9fuLi","DgXyy0W","B3vUDa","y05SDMm","rff1Cg8","B3Lvy3C","v2LUzg93","A1PsyMm","D2nQy08","vfb4Dg8","twXpCMC","qLzrC2O","m3WYFdf8mhW","uu1Qzhq","shDpte0","ywDLsgLKzq","x3vYBa","odCZmfH6vg5IDG","A01jC0m","CMvXDwLYzwq","ihrPBwvZ","CMvTB3zLq2G","teDWsMq","CMvTB3zLrxy","AgvHzgvY","DLLWCMC","Bwv0Ag9K","u3rYyxrLz3K","BwHitLy","Aw5Lza","zKP3EKy","vKPUtue","yMXVy2TLza","zervCxa","DMvYC2LVBMm","DxjVq0q","CuDuyM0","B25TzxnZywC","D3nlBgi","yNL0zu9MzNm","A3PTEM8","sK9MC3u","CMPjq0i","x2rPC2nVBM4","A1n0yxr1C0m","DM9LqLG","Ae1LC3nHz2u","zNHOwuW","shH5AuS","svb6DwW","BgPAvwq","DwDltMG","vLboCMS","svLqDvi","AxnrB1nby2S","x29UrxjYB3i","BhrPCgXLihq","uLjwDfa","ENzdu2e","zgv2AwnLx2K","tfr2CeW","x3nLBMrby2S","ugfYuKO","u3HNwLa","mti2tvDXDxbi","zcbLCNjVCI4","q0Psvxu","DurfthC","B25pCgvU","Dg9cExrLC0i","Dev2zw50","DxnLCKLW","Dg9oDw1Izxi","rxnkB1q","x2nSzwfYvgK","x29WDgLVBNm","q291BNq","B25tDg9Wsw0","zxfTrKe","ywnRx2LK","vM5Xrxe","Ahv4yKi","AevYCM9Yrxy","reDwv3a","mteYnJuXmef3Cg1cAq","z0rhuvi","ruz1qwK","A1r0C3O","C0jf","t3vOB0y","ru5NyKK","t2rmuvi","s1LzwNi","C3rLBMvYCW","AxnszwfKEq","Cu5Vt2q","CMvUDevUzha","vuXWAhe","q01NwNi","AeTLt2S","ywnOzwq","C3nTzfq","ChjVDg90Exa","vLvWDKy","EMzgBxC","BMvY","x2LZtwLUAvC","DgLUzYbZzxi","DMPVDgK","ihbYB3rVy28","A2LoC1O","rvjst1i","DhjPzxmGCMu","zhLOyLi","u3jNqvG","uKLivuO","yNvWz1O","EhzRzee","y29UBMvJDfm","s2zevwS","z2v0s2v5","ChbL","C3bSAwnL","svLfrMm","Cgf5Bg9Hza","qNPru0K","vNLYyuO","rwvKt3O","u0HAuKK","zxH0ugf5Bg8","AxPQz3q","icSG","Awvnt3m","u3LvCfG","tK1TBvm","qvD1uMW","A0D4D2u","AvPesM0","qvjPA2O","yNvMzMvYzwq","u2LPDeq","AxnAzxjV","DenqyK8","terdq2S","BMnVzgLUzW","A0TMAgW","CgLUz0LUDgu","x2LUAxrhBg8","t1vvCum","B3nLrxzLBNq","ChjuEve","y2HnyxHdB3u","zv9ZDwnJzxm","v2vIu29JA2u","qwHfDuK","Aw5KzxG","zNvpre4","EKzxte4","C2v0u3rVCMe","uhrJB3e","D1HhEfa","s2L6Aeq","t1bftG","DMLJzuLeig8","su9byLi","B2XKvMvYC2K","rgvKAwnHDgu","BgLZDgvUtMu","uhDyAvO","C2v0q3vYC28","C0Xf","C1nYrwu","A0nwAeu","zNjVBNrPzxi","Axnby2TdBgu","BMDLza","ANrkuha","u2TPCcbWyxm","AgfUz2u","B25dBg9Zzq","r05jruC","qK5qwfu","DcbSAw1PDa","qMDnEuu","Dg9cExrLCW","BgHjBvm","BuHLCMe","jMPZy2fSBgi","t1fNs2O","wfbsDuO","yvrmv0u","ywzL","ExbL","ENrhCuG","Cu1eDMS","yxrLq291BNq","qxbYANG","ywXPzcb1CMW","qKnOyxq","Dgv4Dc9Qyxy","CfzRD3i","ChjVDg9JB2W","B0L4Bfi","B1L3rK0","y3jLyxrLuMu","CMvJB25Uzwm","AvLuAxa","ihzHBgLKigq","CMvQzwn0","BwvY","z2jOy0C","uvHLtvG","B3jpBMXPBMu","Cg9W","t0rAC0K","yNL0zuXLBMC","r2jdDwS","DLfkBui","zfbZDwS","x2rLyNvN","DML0DLq","CNbgDNC","thDOsxu","DxbNCMfKzw4","CKPiwwi","s01zAe0","Dgvryvi","DgLLCKPtt04","CgLUz1rPBwu","sKHXrwW","y29Uy2f0","seH6Dgy","ueLcvgK","rfHlz00","sgr4vfG","weTvEfu","ywnAB0u","y0Lbt3i","u2vYDMLJzvC","y214zLi","y2DYve0","qu5Nzxm","ze54uuy","A3zPyxm","v0H4Dwm","zMvY","CfL0A3G","zw5JB2rLrNi","vwDVAKW","ANzrEwC","C29Tzq","CYbPBNn0yw4","uKfJv3m","sKflAKK","wg5myM0","y1z1tgK","uM1WEwC","u1vfEfi","D0jwwNa","zg9Uzq","y2fSBa","wu5dreK","uxbot3C","tfr6wvG","DhLWzq","sgjjBMK","rNLKDgC","wMrNBNK","Dhr3Awq","DvfTvfy","DujkDLa","tfjJtvi","tKfwB0m","ANfItLu","B3bLBKrc","BeHHBMrSzxi","BM13Eg0","CYbHBhjLywq","A0HnEuG","B3bLCNr5tMe","wgXAtgy","s1nyq3C","qNnVDxi","Aw9Ul2PZB24","tw5lD2q","AMXzCxm","nhWWFdv8m3W","C2XPy2u","C1vrruq","D3bHsLK","x2LZtM9Kzq","igfYCMf5yNu","y2uGBM90igK","uMfmzKi","zw5XDwv1zq","y2HnyxHuCMK","yMLUza","vePPqvG","CKfWC00","BMv3vMvYC2K","Ec11C2uT","q29Kzq","Aw5KzxGGB3u","zgjTzvO","swnpzNe","yvvTDum","A0rLqMO","zeHty2y","Cg93","qvHzEMG","z3bfyMO","zgLZCgf0y2G","Bxn4s3q","zxjFDhrS","y2XLyxi","De1HBMfNzxi","CKvJqMq","zwPntNq","q0TiALO","A2Hose0","zMHfv0C","qunQrgK","sfjPBKy","q1DVEMW","yM9KEq","AgnkCuC","BNrfBMrWB2K","rgj0BLi","yw1L","D3P0y0C","BxfPsge","yu93AvO","vvDtBhy","su5tvefova","s2fJBgO","y3jLyxrLrwW","Bg93","AuDqEKu","x3nLCuLK","s2XHruS","yuj6vwy","u3LiyKe","x21LC3nHz2u","AeTzAKK","tMDnyNu","odG0oteYvefOtg9o","qMjLC3G","x2rItMfTzq","x2rYB3bhBg8","tKzPt0O","x29Uq2XVC2u","ugfXzMm","CxzuEeC","vw16yLu","q1jSEeC","uKzTBvy","mdaWma","ywnR","Aw5euw4","vMT4CM0","CMfTugfYyw0","y29UBMvJDeu","AxjLza","yLbLrg0","vw1Svee","ugz6De8","BejoA20","s0jZvgi","CgvYC2LZDgu","t1rZqMm","DMvYC2LVBG","sxb3EKq","y29UDgv4Da","EufHC3i","zw5HyMXLuw8","sM9qsvK","suTvwwW","yKf0v0q","BuPMt2K","Fdz8mxW5","CMTLCKDSB2i","y291BNq","Cg5hC2e","B0fcu1a","mtH5sg5rt3G","z1zLs0W","DhbizwfKzxi","EMrAwfi","ywrKrxzLBNq","Dfb6zhi","BgvUz3rO","AhHSDwe","Ahr0Chm6","CwrtCKi","C3fbBxK","DxrMofDYAxq","m3WXmxW4Fdq","C3rYAw5NAwy","Cg1ZAhO","EKfWBwC","D2TxwLa","DfvXDNm","Ae9Wzw5fDMu","zujmvLe","zeDKzwe","CxjPz2y","zfnhvvu","C3rVCcbPBw0","yuzNy1e","C2v0y3vYC28","Bwf4tg9ZC0m","DNvoy2C","wMzbveW","BwfUDwfSihi","ruHqDgm","DhbjCLK","CgjICdi","zfnfwwe","vwD1zNi","DvngDNK","qw5Utfa","u25yt1q","Fdb8mNWXmhW","tNPlr0u","y25fyva","AeXIqNK","tfPTCeK","rM1RD1O","yw1LoIa","yMfSu2nVCgu","t3jyvxO","EwzzCKu","uhbMB24","uwvQCxO","sxDpvvy","z2vY","z1zUzvi","uwDiExK","yNbZwfG","t05wwei","BNrLCG","Dw5RBM93BIa","sMHzqNq","B0jjrLC","Dgv4DfbHEwW","EhLKCMK","AefJA01LC3m","o2nOyxjZzxq","sgLXsNe","ChjVy2vZCW","zw5KCg9PBNq","sKzJEKS","uhjPBwfYEuS","quz6u3C","x2vUzhbVAw4","BgvY","EuvdCuu","tK1zEwO","BNrbBMrvCgq","EKHWwxO","EfHgzKK","svb4rwu","u0LTs08","yMTuCMW","rNjVBNrPzxi","yMHcswe","zNjVBuj5Dgu","t294uum","CNjVCK1LC3m","wwPcDha","zw50zwqGDhK","Ec1TC2CTCw8","zfzLtxi","CNnVCKzPBgu","zNLXBve","DgvZDa","zxf1ywXZ","BIWGAg9ZDg4","Curjr1u","Dw5KzwzPBMu","ywWGy3vYC28","B3bLBIa","D2z0zeO","wg1Qq0K","qKnoBwi","ChLnvuW","uKr6sM0","DMfS","CNzHBa","Aw9UvgLTzw8","BhDovwG","ywXty29Wzq","z1vSDwS","pxv0zI04","AenSB3nLrxy","quXm","uLjpuG","qxbMB3e","Aw5KzxHpzG","ELzJsfC","yxKSihrYEsa","ywnOzwqSihC","zvDXuNa","wwfwvMq","ihzHBgLKihm","EKfzCfy","DNDPvve","suvnrLm","uNnUy2i","C3rVCMu","BNruq1K","rMv4sLG","zw9wru4","Evzdzge","q09oveLovuu","weLjwuO","CgfNzxnOB3C","zMLSzw5HBwu","C2zzswC","AeXsuK4","Cgf5Bg9Hzeu","C3rnCM0","q1DcuuO","z29AB28","B25nzxnZywC","vxfNsgm","C2vYDMLJzs0","veLvyxe","uMfUvKy","qwDhuhO","DwH0C0K","qxPlr1q","DxrVuMvJB24","DNrit08","Bg9N","De5RCwK","Bxvtv1C","zw91ALu","zM9YrwfJAa","BhjfEfG","uensthy","rLDUqMe","B3jRig9MzMW","x3DZsw5ZDge","vvD1C3K","BwvZC2fNzv8","s3Lnwxa","igXHCMDLCIa","qvDbC04","C2fWA0O","tfPJz2K","vMHPyuC","A0Hpr0e","BK1qz0e","v2nuzue","BxnNsuq","z3rQC0i","s0XrweW","yLjxyuG","CMvJzxzPzwq","v1jWvhe","teHPuxK","y3jLyxrLrxi","tfnVzMO","C2jOueO","B3nLza","qLjItgq","z2Lst28","C2vUDa","B2zMC2v0","A09TA3y","x2XPC3rLBMu","x29UugfNzu4","r1nLsKK","mNW1FdD8ohW","CgLUz09Uy2u","A1LOyMW","C3rYAw5N","uezhwg4","y0PZzKi","x3jLy29UBMu","vxblAfC","y2HLy2Tszwe","sNPLzLC","BLfquMG","vgLzv3e","zLHNDvm","Bvzfq0S","wLbTzg8","CM92AwrLige","txLLyvO","wwTiz00","rg55yM0","s1HqwgW","BNfsBvC","vgLTzw91Da","yLznvhC","DgfYz2v0","zuTdu3y","ww5qvfy","yKzpug0","Dw50","A2fkDhK","z2DPsuC","z0PyswK","wMLirwS","zufXwuy","s2X3vLO","zxLHsK8","ig1LC3nHz2u","zgf0yq","D0TUtgW","uuzhs3i","sMzfCgS","y3vYCMvUDeK","z2v0","mtaWmZu2A2ThufP1","veLVzKC","tNPyy2S","DxntAhu","uu5rsgK","AwXK","zLvTAw4","B2fK","Dxrjza","BuHZrKy","mxW0Fdv8mhW","x2LZsw5PDa","uvPcAgy","C2HPzNq","Ahr0Ca","rxjYB3jdB2q","y3fZsMq","Ce9YwK8","CfDtqxa","EvLovhG","qvbqwge","ywXSq3vYC28","tgLZDgvUzxi","tgvIsNm","mtCYndCWmgLpBKzJBa","zKHYsem","zejwEM4","r1vkChO","Dhj1y3rVCIa","mxW0Fdb8mNW","ENvlC2W","BNrNv3G","DePpqMi","uKLeAfO","yMfSrxzLBNq","v1vkCw4","Cu1SAMC","y3vYC29Yx24","B3jRzxjhBg8","BNvTyMvY","tMHOzMe","z2vjBMzVu3K","y2vZC0HHBMq","AgLNAa","B2nRzxrtDwm","x3bYB3rVy28","B25VCgvU","tg9NsurozxC","DgHLBG","x3nVy2TLDa","uuDjzfy","Dg9mB3DLCKm","CMfUzg9T","y2Lvtg0","Dxvfs0q","CNzHBfzHBhu","ENnyqxm","C3bSAxq","tLHfvgK","ywrQvNG","D2HzDLy","u0nzDuq","qNjPzgDL","y21hBgW","qM9uAxa","DhD6wMe","A1nnCMG","BNjZDvq","uxjzBva","y2XVC2uSihC","Ec1TC2CTy3u","x29Ut3bLBG","qNPczwu","sfn0Bvu","uNPVA3y","CfP4yuu","B21eAxm","vNnUEgC","Dxv1C2K","qMLjy04","z2v0q3vYCMu","AMrzAg8","ywjizuK","v1bVEeC","swHwuLe","BwDbzK8","BMCGzMfPBgu","DefqtK0","z01buu0","m3WWFdj8mxW","zMzUEhO","Ew1Qre4","yLrktgO","v3DguuO","x2HHBMrSzvi","vMD2vwS","C3nHz2vfDMu","DxbXr0S","EMXrvwK","ywrK","BMCGB3iGyw4","AenvDgC","CMvZzxrfBMq","DcbVzIbYyw4","zNjVBujPDhm","BMDuAw1LCG","zLDHCgi","yxbWzw5Kq2G","z2fNugu","D0LZEuq","svv5BuC","y0zxBei","tg9Nsuq","x3jLBw92zvC","DujIze0","wwrbDum","B3bLCNr5","zNHABhe","thfsuMW","BgLUzw5V","s2DKre0","yw5ZzM9YBvq","zMHUBwC","CMvHzfvjBNq","AefPr1i","y29SBM8","vxbKyxrLq28","y2XzwuC","AwDHDg9Yt24","B2zM","uxfUANq","s0nTA0u","rvPQreO","z2v3rKq","CMvZB2X2zq","uMXJEfq","CYbWyxjHBxm","q3jPwMy","Aw5L","B25tDgfYDfi","Ae5YDuW","zv90Aw1LB3u","zgvSzxrLrge","AgvSteW","Cer0rha","EKHKEve","CMvZzxruCMK","ww5WtKi","ugjfzvC","r2zJzxi","rxn3CfK","zxjYB3i","BgzvBhK","zw5HyMXLqxu","qLP3quO","C2v0","z1n4qwy","z0HTEKG","Dgv4Dc9WBge","t05JDMG","D2fZq2XLyw4","vgfN","B2nRzxq","zhvpEey","Aw5fAuO","tMfTzq","CMf5tuK","igzHAwWSig0","BwvZ","EuDOrue","Cgjbwhe","AKLKAKq","rvHnAuC","yvblzhK","u1Dwr2K","EMzYzgS","zgD2y0S","ywnRtxnNswq","x2rLC3rYB3K","x2nSzwfYugK","Cg1cwNC","z0Dps2O","vNv1vMi","s2X3r0u","ywDLu2HVDW","DMnsshy","vuXmAfi","uuTgrxC","rhzYzwK","ve1czLO","Dg9Y","txHVuxe","tef5A3O","zw1LBNq","DeLK","BxP0AwG","qvvZzK0","z3LdEKW","DxHTyKO","zw5HyMXLvhi","DgLTzw91Da","Dw5ZAwDUzwq","wgzlz24","BMfTzq","rxzLBNq","tgftz3C","Cen1z3i","zKnHAxe","y3r4","yK5qyuC","zxjFAxnFywm","C29YDa","x2LUAxrqCM8","vw5Oyw5KBgu","yxrHlcbKyxq","y29UBMvJDca","zw1fB3C","BM1TruO","m3WWFdj8nhW","yMLUyxj5","AxbiBeG","CLDnDvu","sMnoDgq","zhz3CgC","r09Luhq","zxj2AwnL","BNDhtK8","C3vJy2vZCW","igzPzwXKoIa","C2vYDMvYvgK","zg9TywC","t2jQzwn0","z1jhEMG","y2jQzgy","zffbthG","Ce1ABKe","CwzcDMC","BfH3seC","vezIqum","wgDPseW","rMnpBvK","AwXLtMfTzq","x2n1CNnVCK0","zw50tgLZDgu","Aw16s1i","DwLRvvG","Dg5yzhG","yxbwuM0","x3DHAxq","t3bLBKv2zw4","yw1Lu3bHy2u","A2v0ignVBNm","tKzKDwS","CKr6tfm","ELDVqve","vMjYrMK","ExzJt24","tK5Lzem","v2H4Cee","zNjHBwvuExa","DwDhyLG","tuXOse0","AgfZ","s1rhBfC","zNjVBu51Bwi","EfrutLC","yMrFzgLK","zxjFBxnNAwq","zLntz3G","AxjOtem","DeLUDgvYy2u","yNvMzMvY","ChbiBhC","Cgf5Bg9Hzfq","ywjVCNq","y3jiq1e","u3z5swS","suvtx0vsuK8","q29UzMLN","z2v0u3rVCMe","A3PmDeO","B2jQzwn0u3q","uwfuB2e","zwnVBM5Ly3q","Aw9U","B25fCNjVCG","CgXisKq","B2nRuha","ywXS","q2Dbu2e","DvDbCgC","A2r2z1u","CNvWtfu","uvrhCgG","mNWXFdb8nxW","zwrPyxrLBhK","B0njALm","C09btxK","wMrXBgK","shnxzgq","z0P6CfK","zMzmAw5L","yxGGCMv0CMK","ChvZAa","z1rpuum","Bwf4twvZC2e","zwvKzwq","DxzWuLK","zwn0","yLbXy2u","zxfhtg4","mJC0wgnrr1nM","z2v0t3DUuhi","uLnHAK0","x2HHBMrSzva","BffXsKu","v3jHruK","Bgjvtuq","qNPXDMS","s29zvLC","DhjPzxm","y29Kzq","Dg9iyxnO","uwXLzKK","DhjPBq","y0ntCfy","uNPrBMu","uK9yyxm","y09Wzw4","AxnbCNjHEq","yLD4uvG","y29UDgLUDwu","DMfSDwu","B3DhC00","y3vYC29YlNm","zxmGCMvHy2G","DhjHBNnHy3q","BMv4DcGPigm","sxbHt0y","C1DJDuy","Cg9PBNrdB24","x3bPBMC","tNvhz0m","vhDHv3a","x2fKzfDZtgK","qLfNDKO","A2v5","qwXzD3u","mNWWFdr8m3W","EeHzsLi","AxnrB1nnzxm","u2T0rg4","DKT0uuq","twTOEhi","AfrICw8","tM9Lrfm","q2f5rhO","qNPOAhC","CgvvuKC","BMPwt2m","x3fVC0rc","v0ngseK","qK5NEeW"];return qo=function(){return t},qo()}function G(t,e){t=t-382;let r=qo(),i=r[t];if(G.jRGcmx===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",w="";for(let S=0,_,v,A=0;v=x.charAt(A++);~v&&(_=S%4?_*64+v:v,S++%4)?m+=String.fromCharCode(255&_>>(-2*S&6)):0)v=p.indexOf(v);for(let S=0,_=m.length;S<_;S++)w+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};G.uGrHKf=o,G.saTIQW={},G.jRGcmx=!0}let c=r[0],d=t+c,u=G.saTIQW[d];return u?i=u:(i=G.uGrHKf(i),G.saTIQW[d]=i),i}function dh(t,e){let r=L,i={IwOUV:r(1766)+"e",JzefW:r(384),HHztf:function(x,p){return x instanceof p},kHMyH:function(x,p){return x===p},NjGQf:r(1240),KGwvx:function(x,p){return x===p},inEiJ:r(1462),eExts:function(x,p){return x!==p}};if(!(i[r(894)](t,IDBDatabase)&&!(e in t)&&i[r(941)](typeof e,i[r(1922)]))){if(i.KGwvx(i[r(1443)],i[r(1443)]))return;{let x=this[r(1639)].getItem(this[r(475)]),p=_0x2b4e47[r(577)](x||"{}");return p[_0x1dc914||_0x5e01a0[this[r(507)]]]=_0x59253e,this[r(1639)][r(426)](this[r(475)],_0x47f479[r(1060)+"y"](p)),_0x42da5f||_0x416026[this[r(507)]]}}if(Fo[r(1278)](e))return Fo[r(1278)](e);let o=e[r(1794)](/FromIndex$/,""),c=i[r(1723)](e,o),d=ph.includes(o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(765)+"e"])||!(d||hh[r(648)](o)))return;let u=async function(x,...p){let m=r,w=this[m(1615)+m(1563)](x,d?i[m(1097)]:i[m(1246)]),S=w[m(1172)];return c&&(S=S[m(818)](p[m(1292)]())),(await Promise[m(1567)]([S[o](...p),d&&w.done]))[0]};return Fo.set(e,u),u}var hh,ph,Fo,Mv=uh({"node_modules/idb/build/index.js"(){let t=L,e={eNPPR:t(949)+t(1722),RzQne:function(o){return o()},tAPNM:function(o,c){return o(c)},qrigf:t(1378),dSGUU:t(1878),cJoHB:t(977),YnPTV:function(o){return o()},WfgAB:t(783),cYwXN:"getAll",SiitD:t(425)+"ys",ZdkjD:t(1044)},r=e[t(478)].split("|"),i=0;for(;;){switch(r[i++]){case"0":e[t(1605)](ch);continue;case"1":Fo=new Map;continue;case"2":e[t(1366)](kv,o=>({...o,get:(c,d,u)=>dh(c,d)||o[t(1278)](c,d,u),has:(c,d)=>!!dh(c,d)||o[t(1541)](c,d)}));continue;case"3":ph=[t(1700),e[t(1068)],e[t(1069)],e.cJoHB];continue;case"4":e[t(1262)](ch);continue;case"5":hh=[t(1278),e.WfgAB,e.cYwXN,e[t(803)],e.ZdkjD];continue}break}}}),Bv={idb:function(t){let e=L;t[e(1814)]=Promise[e(1413)]()[e(1327)](()=>(Mv(),xh))[e(1327)](function(r){return r})}},lh={};function Mt(t){let e=L,r={FausI:e(1627)+"1",IBWpc:function(u,x){return u!==x}},i=r[e(1904)][e(1336)]("|"),o=0;for(;;){switch(i[o++]){case"0":if(r.IBWpc(void 0,c))return c[e(1814)];continue;case"1":return d[e(1814)];case"2":var c=lh[t];continue;case"3":Bv[t](d,d[e(1814)],Mt);continue;case"4":var d=lh[t]={exports:{}};continue}break}}Mt.d=(t,e)=>{let r=G;for(var i in e)Mt.o(e,i)&&!Mt.o(t,i)&&Object[r(408)+r(1395)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Mt.o=(e,r)=>Object[t(765)+"e"][t(480)+t(1395)][t(923)](e,r)})(),(()=>{let t=L,e={TMBfZ:function(r,i,o){return r(i,o)},emEow:"error",JHqEl:function(r,i){return r!==i},eZevN:t(1346),zoOEv:function(r,i){return r!=i},nMPgA:t(1142)+"d",SyHbA:t(650),LTEUV:t(1725)+"le"};Mt.r=r=>{let i=t;if(e[i(892)](e.eZevN,e.eZevN)){let o=i(1494)+_0x2d4675+(i(1756)+i(449)+i(775)+i(763));Ie[i(882)](o),Ie[i(607)+"hErrorEv"+i(597)](e[i(1468)](_0x4201ed,e[i(1495)],{message:o,code:_0x2488ef[i(433)+i(1556)+"R"]}));return}else e[i(476)](e[i(1216)],typeof Symbol)&&Symbol[i(1896)+i(1440)]&&Object[i(408)+i(1395)](r,Symbol["toString"+i(1440)],{value:e[i(1004)]}),Object[i(408)+i(1395)](r,e.LTEUV,{value:!0})}})();var Re={};(()=>{let t=L,e={vvNlX:function(a,n){return a(n)},GnkCs:function(a,n){return a+n},IYPuR:function(a,n){return a+n},AhEuI:function(a,n){return a*n},oIxlR:function(a,n,s){return a(n,s)},IhVRQ:function(a,n){return a+n},eVrje:function(a,n,s){return a(n,s)},XgiHL:function(a,n){return a(n)},GUJpz:t(1019),qmSsI:t(2011),LGpJd:function(a,n){return a!==n},tLEqt:t(553),OdLQR:function(a,n){return a(n)},yGhEA:t(1963)+"00000000"+t(1963)+t(1963),jIdjD:function(a,n){return a===n},pPZnN:function(a,n){return a+n},EEcaX:t(1104)+t(492),JsoYU:function(a,n){return a===n},fXguS:"huCvF",Zdqli:function(a,n){return a<n},gDGQR:"GlPUa",lXwHG:t(1203),yGlld:function(a,n){return a<n},PwXiZ:function(a,n){return a!==n},rJHYb:function(a,n){return a-n},pnGsa:function(a,n){return a-n},ipoAr:function(a,n){return a-n},gJXIi:function(a,n){return a<n},irKbL:"rApsM",BqMrl:function(a,n){return a<n},XfKgn:function(a,n,s){return a(n,s)},tfYge:function(a,n,s){return a(n,s)},FWnBa:function(a,n,s){return a(n,s)},Kaclj:function(a,n,s){return a(n,s)},cmGll:function(a,n){return a&n},sItFe:function(a,n){return a(n)},lprmL:function(a,n){return a<<n},gzLiD:function(a,n){return a&n},dbmeZ:"yhQTF",kboPx:t(1347),aBHQq:function(a,n){return a(n)},KXPXl:function(a,n,s){return a(n,s)},KBsTb:function(a,n){return a===n},Qclmu:t(1765)+t(682)+t(1507)+t(1625),EedOz:function(a,n){return a===n},xwnau:function(a){return a()},homfg:function(a,n){return a!==n},TiYWq:"ituEe",vvqay:function(a,n,s){return a(n,s)},cLPhS:function(a,n){return a(n)},kXajD:function(a,n){return a!==n},sdDAU:function(a,n,s){return a(n,s)},GSeJI:function(a,n,s){return a(n,s)},sqAmy:function(a,n,s){return a(n,s)},FcOmY:function(a,n){return a!==n},vjoti:function(a,n,s){return a(n,s)},NMmmS:function(a,n){return a!==n},CayDz:function(a,n,s){return a(n,s)},dNxQF:function(a,n,s){return a(n,s)},Bwjot:function(a,n){return a!==n},lrExX:"eDDWu",ANges:function(a,n,s){return a(n,s)},yiYXD:function(a,n){return a!==n},JAKjI:function(a,n,s){return a(n,s)},Lgexc:function(a,n,s){return a(n,s)},duyxu:function(a,n,s){return a(n,s)},TJiAX:function(a,n){return a(n)},BiIcN:function(a,n){return a(n)},IUymG:function(a,n){return a(n)},vcRHv:function(a,n,s){return a(n,s)},sWcuF:function(a,n){return a(n)},IpwzD:function(a,n){return a(n)},WcTeA:function(a,n){return a(n)},gpoPh:function(a,n,s){return a(n,s)},pVkwr:function(a,n,s){return a(n,s)},dxDRj:function(a,n,s){return a(n,s)},WCFHI:function(a,n,s){return a(n,s)},hxlua:t(1765)+t(682)+" field: SeqID",AgGPz:t(1765)+t(682)+t(1507)+t(1391),OpYSk:function(a,n){return a===n},dzSmB:"Missing required field: "+t(689),KCvXX:function(a,n,s,l){return a(n,s,l)},rjICB:t(1547),lgqYO:t(1969),zzqno:function(a,n,s){return a(n,s)},IYEFc:function(a,n){return a(n)},oABSP:function(a,n,s){return a(n,s)},Dzozs:t(566)+t(1133)+"pe: ",zHpYz:function(a,n){return a>>n},zuKsl:function(a,n){return a>=n},upqGK:function(a,n){return a>n},wJHlN:function(a,n){return a+n},Dnybm:t(840)+t(845),ROYHD:function(a,n){return a(n)},YkHgM:function(a,n){return a!==n},XZsWs:"CIdvD",imzKR:t(1985),XMbSj:t(1449),uuusi:function(a,n){return a*n},kOmkv:t(1726)+t(845),CKHjZ:function(a,n){return a+n},fZsDP:function(a,n,s){return a(n,s)},DXKgM:function(a,n){return a&n},SUExR:function(a,n){return a>>>n},dMVGP:function(a,n){return a&n},fxZlq:function(a,n){return a>>>n},TPxto:function(a,n){return a>>>n},MxoQq:function(a,n){return a<n},EmonK:t(1786),cFWlB:function(a,n){return a+n},KgdDM:function(a,n){return a===n},nmwxm:function(a,n){return a+n},wztcG:function(a,n){return a!==n},IWnCd:function(a,n){return a&n},lfUly:function(a,n){return a<<n},XnLbm:function(a,n){return a&n},PIBTi:function(a,n){return a<n},vpRLl:function(a,n){return a(n)},xHYJR:function(a,n){return a==n},hAiGR:function(a,n){return a+n},FuMkb:function(a,n){return a<<n},ooGeY:function(a,n){return a|n},jdYho:function(a,n){return a<<n},pCugr:function(a,n){return a&n},BRbLd:function(a,n){return a&n},VbegO:function(a,n){return a<=n},aOwiZ:function(a,n){return a+n},yvrDt:function(a,n){return a+n},BlAkd:function(a,n){return a&n},NNedC:function(a,n){return a|n},yqtzM:function(a,n){return a<<n},ARikj:function(a,n){return a<<n},HbIni:function(a,n){return a|n},aeosU:function(a,n){return a<<n},LebJs:function(a,n){return a&n},wpaJY:function(a,n){return a<<n},SHZRI:function(a,n){return a&n},SxgZP:function(a,n){return a<n},TwltV:function(a,n){return a>n},ynFAj:function(a,n){return a+n},gRpmV:function(a,n){return a<<n},Rzokv:function(a,n){return a&n},sfYIg:function(a,n){return a&n},bMIEc:function(a,n){return a(n)},oApcf:function(a,n){return a&n},kzmzo:function(a,n){return a<n},fyqmQ:function(a,n){return a+n},PfztO:function(a,n){return a<n},CriZf:function(a,n,s){return a(n,s)},qvTxG:function(a,n){return a<n},TlTvb:function(a,n){return a<=n},UpdPM:function(a,n){return a+n},CxHsF:function(a,n){return a-n},QXeMX:function(a,n){return a+n},RIDhZ:function(a,n){return a<<n},XHxKx:t(1311),kjkSv:t(1693),zjgEk:function(a,n){return a|n},ockPp:function(a,n){return a&n},uvpRY:t(1698),xhtvL:t(888),WPaHj:function(a,n){return a|n},VUpvF:function(a,n){return a|n},mJfOi:function(a,n){return a|n},OQUGn:function(a,n){return a&n},LHbUN:function(a,n){return a<n},ntTCY:function(a,n,s){return a(n,s)},bpsXX:function(a,n){return a>>>n},YdAuC:function(a,n){return a&n},JMGfN:function(a,n){return a>>>n},Ubxof:function(a,n){return a+n},ZLTeC:function(a,n){return a|n},OXCAE:t(1713)+t(1844)+t(1042),XGJWJ:t(1482),cyulL:t(1189)+t(1482),FmkwZ:t(687),EHPtc:t(1864),ptrJk:function(a,n){return a!==n},yECqE:t(499),kvicz:t(1524),eyaJO:function(a,n){return a===n},BoYTc:t(1126),zsXAs:t(522),pjPlZ:function(a,n){return a(n)},dvwpg:function(a,n){return a&n},LWtvD:function(a,n){return a&n},JjCit:function(a,n,s){return a(n,s)},ULLhR:function(a,n){return a|n},ipeUr:function(a,n){return a&n},HEUfQ:t(1696),gpEbj:"wDbdM",YaVVd:function(a,n){return a(n)},sffOS:function(a,n){return a&n},SPijW:function(a,n){return a(n)},Thvkk:function(a,n){return a&n},NuGgC:function(a,n){return a===n},SuubE:t(1551),WhxpA:function(a,n){return a(n)},qQFcd:function(a,n){return a&n},LwhIu:function(a,n){return a<<n},hNruL:function(a,n){return a&n},xvxph:function(a,n){return a(n)},ThsqN:function(a,n){return a&n},NnYlD:function(a,n){return a<<n},SNjlQ:function(a,n){return a&n},qdSrB:function(a,n){return a|n},izTLY:function(a,n){return a>>>n},nmmEJ:function(a,n){return a|n},UpKhW:function(a,n){return a>>>n},jGRDe:function(a,n){return a>>>n},jMQyS:function(a,n){return a===n},oeCkc:function(a,n){return a<n},WinUg:function(a,n){return a<n},whSvG:function(a,n){return a<n},IcOfq:function(a,n){return a!==n},zdZXR:function(a,n){return a&n},ypuwX:function(a,n){return a>>>n},PKPSS:function(a,n){return a>>>n},uMoqu:function(a,n){return a>>>n},HRinF:function(a,n){return a+n},QaToa:function(a,n){return a+n},iadSh:function(a,n){return a>>>n},tRcOX:function(a,n){return a>>>n},pmshz:function(a,n){return a&n},cLYXs:function(a,n){return a>>>n},oSXyi:function(a,n){return a|n},lTbcs:t(1096),wYxby:function(a,n){return a(n)},xxFse:t(619),koFVB:function(a,n){return a(n)},emyMD:function(a,n){return a|n},NFiOJ:t(1308)+"3",VnqEq:function(a,n){return a===n},GNIEG:t(664),BMDsQ:function(a,n){return a<<n},pZxaE:function(a,n){return a<<n},UhDpe:function(a,n){return a<<n},GstfQ:function(a,n){return a<<n},LMrWx:function(a,n){return a<<n},JoPIY:function(a,n){return a|n},iOlGx:function(a,n){return a<<n},AXYzh:function(a,n){return a|n},UyeHk:function(a,n){return a===n},xrJyu:function(a,n){return a>>>n},HdxTX:function(a,n){return a|n},fDvtl:function(a,n){return a|n},mGCzf:function(a,n){return a|n},vtrwM:function(a,n){return a<<n},Mkhxr:function(a,n){return a<<n},qdQIk:function(a,n){return a<<n},NZvij:function(a,n){return a<<n},QNQHi:function(a,n){return a<<n},lQqJE:function(a,n){return a|n},PhrLE:function(a,n){return a|n},AYJBi:function(a,n){return a|n},NAVoC:function(a,n){return a<<n},Tnbxo:function(a,n){return a|n},SchjC:function(a,n){return a|n},eAqYF:t(715),qBhVq:function(a,n){return a&n},lBNkm:function(a,n){return a>>>n},vQJmB:function(a,n){return a&n},iGPzE:function(a,n){return a>>>n},qGTbm:function(a,n){return a&n},FkgFB:function(a,n){return a&n},kHOGA:function(a,n){return a>>>n},tnXdx:function(a,n){return a>>>n},UWusy:function(a,n){return a>>>n},nuFRi:function(a,n){return a(n)},cgrTM:function(a,n){return a|n},NFduk:function(a,n){return a%n},RSajM:function(a,n){return a/n},vwiUQ:function(a,n){return a*n},eAucA:function(a,n){return a>>>n},VSMWZ:function(a,n){return a*n},acZoE:function(a,n){return a===n},HVtPV:function(a,n){return a>>>n},VoVMd:function(a,n){return a>>>n},oBnEV:function(a,n){return a&n},RIHUJ:function(a,n){return a>>>n},YOtNV:function(a,n){return a+n},YnpNB:function(a,n){return a+n},voeBX:function(a,n){return a<<n},jHnHk:function(a,n){return a<<n},hjYqR:function(a,n){return a>>>n},lhImS:function(a,n){return a===n},LQgnp:function(a,n){return a===n},MZuag:function(a,n){return a===n},lIRBh:function(a,n){return a===n},gUluk:function(a,n){return a+n},lcPcX:function(a,n){return a&n},sspiO:function(a,n){return a&n},inDQn:function(a,n){return a&n},bRWaH:function(a,n){return a>>>n},eoujU:function(a,n){return a>>>n},WxVyI:function(a,n){return a&n},Zdgny:function(a,n){return a&n},ciULm:function(a,n){return a&n},ljZUd:t(1059)+t(1085)+t(1679)+"7",UqgHc:function(a,n){return a>>>n},CXbPs:function(a,n){return a<<n},VUkNU:function(a,n){return a&n},BCPNb:function(a,n){return a>>>n},dVeMr:function(a,n){return a&n},Fydtg:function(a,n){return a<n},lbUMD:function(a,n){return a>>>n},xCCcY:function(a,n){return a<<n},LTzYX:function(a,n){return a&n},zqKJm:function(a,n){return a|n},cCSpV:function(a,n){return a|n},VJnMA:function(a,n){return a|n},hhltD:function(a,n){return a|n},VAvgk:t(1998),hYvRT:t(1289)+t(460),JOfsu:t(1836)+t(774),UZaHY:"NATIVE_E"+t(1159),bGWiA:"OPEN_ERROR",KCQwr:t(1707)+t(620),gVeKL:t(433)+t(1556)+"R",fUmin:"rZxoG",XXgWr:function(a,n){return a instanceof n},pMZnA:"none_none",BAbOP:t(1498),dXren:t(1006),GSzmM:t(993),BgMyE:function(a,n,s,l,f){return a(n,s,l,f)},jeJZQ:t(486),duOxF:function(a,n){return a<n},Bsour:function(a,n){return a(n)},XIIYJ:function(a,n){return a>=n},zPFUe:function(a,n){return a-n},HdtWG:function(a,n,s){return a(n,s)},NzKGE:function(a,n){return a===n},tUqvs:function(a,n){return a==n},yEzzW:"cursor_file_name",yYoQB:t(604)+t(2004),PrWBX:"KcGrB",AVPCw:function(a,n){return a===n},CBRDp:t(1430),IoCcO:function(a,n){return a+n},gTOQC:function(a,n){return a>=n},vuNcg:function(a,n){return a<n},MyeaZ:function(a,n){return a-n},xUGAh:function(a,n){return a+n},AFzSw:function(a,n){return a<n},LRcMR:function(a,n){return a|n},EXMiG:function(a,n){return a>>n},gSxAf:function(a,n){return a|n},Bbesx:function(a,n){return a&n},stMrm:function(a,n){return a>>n},XMtAr:function(a,n){return a>>n},zFWLN:function(a,n){return a===n},wkWZP:t(1637),LAykz:function(a,n){return a===n},DGVWp:"x_fronti"+t(1835)+"ck",RxdBs:function(a,n,s,l){return a(n,s,l)},fJwzF:function(a,n,s){return a(n,s)},wWofQ:"x_fronti"+t(1676)+t(1787),YmPqZ:function(a,n){return a===n},eWqRp:t(1828),egjxK:t(1214),YQxBb:function(a,n){return a&n},vRRGf:function(a,n){return a|n},gRGzh:function(a,n){return a!==n},UhdpO:t(1393),sUQED:function(a,n){return a===n},cehWJ:t(1595),KCmkE:t(2008),kaJty:function(a,n,s){return a(n,s)},Zypff:"dVWTy",fWapb:t(2027),KYDZu:function(a,n){return a!==n},ymjDN:t(530),BZwAJ:function(a,n,s){return a(n,s)},loDdH:function(a,n){return a===n},pOrZO:"kKIdV",xpNuN:t(559),hNGtG:function(a,n){return a+n},fMXYn:function(a,n){return a===n},ENgbI:t(1130),Pajbu:function(a,n){return a(n)},RaLfB:t(653),Gfcer:t(1162),BQgvJ:"VBkYD",qDIGU:function(a,n){return a||n},AoNdG:function(a,n){return a!=n},AzKGT:function(a,n){return a!=n},DDcSc:t(1240),mVECK:function(a,n,s,l){return a(n,s,l)},rHsdb:t(1616)+"alled mu"+t(719)+t(498)+t(1112),Qsnrk:function(a,n){return a!==n},BqaLg:t(1270),fDfyX:function(a,n){return a(n)},sapkJ:function(a,n){return a<n},kopez:function(a,n){return a<n},uxmbJ:function(a,n){return a===n},dyhbR:function(a,n){return a&n},rzODg:function(a,n){return a>=n},gjzXM:function(a,n){return a|n},bOmGQ:function(a,n){return a<<n},prTyQ:function(a,n){return a|n},PFGXn:function(a,n){return a<<n},uaxSB:function(a,n){return a&n},SHpKl:function(a,n){return a<<n},voKSK:function(a,n){return a&n},mHera:function(a,n){return a&n},TiIfv:function(a,n){return a+n},cwslH:function(a,n){return a+n},bTJLj:function(a,n){return a|n},CSKfQ:function(a,n){return a===n},UgojL:function(a,n){return a===n},wbxgA:function(a,n){return a&n},hKeOk:function(a,n){return a>>n},gHmzH:function(a,n){return a&n},LzFXM:function(a,n){return a>>n},jqbNU:function(a,n){return a&n},dKZQV:function(a,n){return a>>n},SRJEU:function(a,n){return a-n},QlefI:function(a,n){return a>>n},Suejw:function(a,n){return a+n},fQcBC:function(a,n){return a&n},DSeNI:function(a,n){return a==n},mdaPh:function(a,n){return a(n)},BChat:"offline",QFGKr:function(a,n){return a<n},iwNZK:function(a,n){return a!==n},helLL:t(1036),hvJZD:t(414),cJsfB:function(a,n){return a instanceof n},Xcbhs:function(a,n){return a instanceof n},Fmabo:function(a,n){return a!=n},BzBee:"applicat"+t(946),uDELw:t(1636),gMyHj:t(1437)+t(638)+"et=utf-8",ftJDJ:t(554),BETQN:t(784),LaSgw:function(a,n){return a&&n},IVRxO:t(2022),gJzpY:t(742),dMixy:function(a,n){return a||n},nVDLx:function(a){return a()},MnKwd:function(a,n){return a!==n},NoeDS:t(535),QpNOw:t(862)+"ascript",PTVRc:function(a,n){return a+n},CWozl:t(1293),pmBZw:t(850)+"ack=fron"+t(890)+"P",plHJD:function(a,n){return a(n)},fhEWG:t(1665),NxHmY:"kkilS",EncqR:t(711),xiCPK:function(a,n){return a>>>n},hdMGq:function(a,n){return a>>>n},ZTHTG:function(a,n){return a&n},GsWBV:function(a,n){return a>>>n},JQslQ:function(a,n){return a&n},rupLU:function(a,n){return a!==n},ODZsI:t(1412),CYBsV:t(1788),KizhD:"irEXf",aADsT:function(a,n){return a!==n},JPZUS:"OtbMr",YDeMw:function(a,n,s){return a(n,s)},BgQZA:t(1840),NrPtW:function(a,n,s){return a(n,s)},HkBIz:t(1633),gElyx:function(a,n){return a!==n},WnKxU:t(1858),uSFvy:function(a,n){return a||n},JfEpk:function(a,n){return a||n},wftdJ:function(a){return a()},WUJqn:function(a,n){return a===n},wqlrI:t(873),fhijD:function(a,n){return a||n},ZiHEk:function(a,n,s){return a(n,s)},eAamr:function(a,n){return a===n},MlOrg:t(453),RAcWs:"aHrjH",fhnmg:function(a,n){return a===n},bAtWD:t(1453),jAByx:function(a,n){return a||n},Qqnjt:t(1142)+"d",jLLnu:function(a,n){return a||n},rEcBd:function(a,n){return a!=n},QEwei:"init QoSDB failed",SCYuD:function(a,n,s){return a(n,s)},JrIRa:t(1797),eBLVQ:t(1208)+"id",AACBD:function(a,n){return a(n)},QTGph:function(a,n,s){return a(n,s)},oPilN:t(866),XBZRG:function(a,n){return a===n},fHrkW:t(1002),aTLWE:t(1423),jlYqs:function(a,n){return a(n)},bkUHq:function(a,n,s,l){return a(n,s,l)},BzQSI:t(1831)+t(1769),sSrEe:function(a,n,s,l){return a(n,s,l)},gyCzL:t(1831)+"er_is_ack",jgyVc:t(1533),iYTip:t(488),oCIjS:function(a,n){return a&&n},nUKsF:function(a,n){return a===n},UmzbU:t(1193),TGWtl:t(1845),wnTED:function(a){return a()},ABVFj:"received",zzRyl:function(a,n){return a(n)},njVOc:function(a,n){return a instanceof n},NgMbu:function(a,n){return a instanceof n},uqbsU:"applicat"+t(946)+t(1110)+t(1156),KfDUk:function(a,n,s,l){return a(n,s,l)},qCRZL:function(a){return a()},pWrom:function(a,n){return a&n},aFgcQ:function(a,n){return a+n},jtJPp:function(a,n){return a(n)},bTtAn:function(a,n){return a+n},DrwiT:function(a,n){return a+n},QMjdt:function(a,n){return a||n},gnRyV:" > ",QoGmo:function(a,n){return a>n},ggiIG:function(a,n){return a+n},JJNUD:function(a,n){return a<n},fvjRz:function(a,n){return a<<n},HAkFA:"FRONTIER>",XPRuJ:t(767),ATMwc:function(a,n){return a|n},sOAMy:function(a,n){return a+n},DvAsP:function(a,n){return a+n},WHxuc:function(a,n){return a|n},YXiOS:function(a,n){return a|n},bIGiT:function(a,n){return a<<n},irsHU:function(a,n){return a+n},aUmuC:function(a,n){return a+n},CGdeB:function(a,n){return a<<n},ACjDi:function(a,n){return a>>>n},AFQYB:function(a,n){return a>>>n},fNyzf:function(a,n){return a+n},CJRUu:function(a,n){return a>>>n},LZmpI:function(a,n){return a&n},oyUcw:function(a,n){return a>>>n},bFOPm:function(a,n){return a+n},mhHNV:function(a,n){return a+n},domag:function(a,n){return a&n},zxifn:function(a,n){return a+n},rpFvw:function(a,n){return a&n},DMSqA:function(a,n){return a&n},wIsyD:t(798),ucaLG:t(1199),kSMrh:function(a,n){return a<n},cvoTN:function(a,n){return a|n},gKYtj:function(a,n){return a>>>n},nwGNO:function(a,n){return a<<n},NzBya:function(a,n){return a|n},sbhPJ:function(a,n){return a>n},PkmbD:function(a,n){return a>>>n},VuuVb:function(a,n){return a<<n},wXGxP:function(a,n){return a&n},Dyavj:function(a,n){return a|n},ULphq:function(a,n){return a<n},OUUqC:function(a,n){return a<n},Nhhfa:function(a,n){return a<n},KoYVW:"cursor.s"+t(1504),QGIdV:function(a,n,s,l){return a(n,s,l)},KSXCw:function(a,n,s,l){return a(n,s,l)},cvUPo:function(a,n,s){return a(n,s)},RMnrm:function(a,n,s,l){return a(n,s,l)},owGsM:function(a,n){return a+n},EHhxT:function(a,n){return a!==n},AUsfM:t(1802),NzXck:function(a,n,s){return a(n,s)},SmQJa:t(1300)+"rValues",jldDA:t(1158),nlxbJ:t(996),PbEeW:t(1177),MkHgz:function(a,n){return a===n},RanVF:t(1190),mLvre:t(1072)+"r",Xpmwc:function(a,n){return a<n},NtIPS:function(a,n){return a>>n},dGdea:function(a,n){return a|n},abHeI:function(a,n){return a+n},ALQPX:t(675)+"5|4",adjVx:function(a,n){return a&n},SrgAX:function(a,n){return a+n},TUtbh:function(a,n){return a+n},IPzul:function(a,n){return a&n},GpYVE:function(a,n){return a&n},irhLC:function(a,n){return a&n},Apfoq:function(a,n){return a|n},ipHlH:function(a,n){return a>>n},uxIkM:function(a,n){return a&n},huxbB:function(a,n){return a===n},bWxQX:t(1032),CWBQJ:t(671),bNPaG:function(a,n){return a||n},zlQUi:function(a,n){return a&n},cbjdf:"x_fronti"+t(1546),clYYG:t(1831)+t(976),RRVtP:function(a,n,s){return a(n,s)},pWSAp:t(1349)+t(1931)+"e",uNdZx:t(1349)+t(392)+"ue",gGOKj:function(a,n){return a>n},jygXt:function(a,n){return a>n},yYNTx:t(805),axjQV:function(a,n){return a===n},COyNR:t(462),rSpyp:function(a,n){return a<n},ocdxH:function(a){return a()},MjNrY:function(a){return a()},iJKrb:function(a,n){return a|n},MLhHM:t(1282),zgtiD:function(a,n){return a===n},IiNnv:function(a,n){return a===n},YERCO:function(a,n){return a&&n},NJieL:function(a){return a()},fCaiq:function(a,n,s){return a(n,s)},Lzxnm:"PagtT",vitvT:t(1094),nQPRh:function(a,n){return a(n)},hLRRN:function(a,n){return a>>>n},dQALx:function(a,n){return a===n},gbLcf:function(a,n){return a>>>n},HdnzW:function(a,n){return a!==n},gtjsB:function(a,n){return a!==n},ZXfFW:function(a,n){return a<n},JFczK:function(a,n,s){return a(n,s)},JhYBt:function(a,n){return a!==n},hllui:t(1088),RlcxT:function(a){return a()},EswpY:"IZHlc",AWAsN:function(a,n){return a===n},SXzSI:"always",ZPmdo:"auto",pyMUL:"ping_onc"+t(815)+"s",SnXOT:"success",Rsncb:function(a,n,s){return a(n,s)},VoLtF:t(1916),CDMDa:t(516),KyMYp:function(a,n){return a===n},fHrHC:t(1454),uroCD:function(a,n){return a>=n},WGOmf:function(a,n){return a<=n},QwZRz:function(a,n){return a<<n},pYtkx:function(a,n){return a&n},Vsnxg:function(a,n){return a-n},CMfvF:function(a,n){return a<<n},fJMKp:function(a,n,s){return a(n,s)},khNHM:t(432),HtOWq:function(a,n){return a!==n},fUzCH:"ZNTaV",OrXUz:t(1497)+"1",KTGlW:t(1980),tNkqi:t(1079),KVZwm:"please provide v"+t(860),zApmg:t(629)+t(552)+t(1415)+t(657)+t(1530)+t(1307)+t(472)+t(692),AlYwu:function(a,n){return a===n},RgowL:"XODZx",cqsJd:"cebOh",vabGh:function(a){return a()},kNCAL:"complete",IGRzp:t(1553),cNwhp:function(a,n){return a(n)},LCbhn:t(1996)+"or",LFhuG:function(a,n){return a!==n},kdiIG:t(1967),NldzU:"reconnect",YNCDI:t(1070)+t(1574)+t(1976)+"ct",xydri:"DvLqn",kDeBj:t(2010),Vkxrm:t(2029),qBKSC:t(1179),VgvUk:t(736),BVQsj:function(a,n){return a===n},XDHoh:function(a,n){return a!==n},wBVZp:function(a,n){return a==n},ssmdT:t(1055),QKFEw:"wss://",Ugufr:t(1545),APAgW:t(629)+"rovide bddID, de"+t(826)+t(1760),uuEKD:function(a,n){return a==n},yAxPz:function(a,n,s){return a(n,s)},XGVJk:function(a,n,s){return a(n,s)},qfBvg:function(a,n){return a!==n},cfWUs:t(1364),DDtYE:"lDlkr",bfYXs:function(a,n,s){return a(n,s)},Ptcoq:function(a,n,s){return a(n,s)},PyGQo:t(455),EXVDY:function(a,n){return a-n},zjajM:function(a,n){return a>n},tavrt:function(a,n){return a===n},WLUoh:function(a,n){return a!==n},EMONn:t(1806)+"e_timeout",ZfATL:t(1479),kzLtJ:t(508)+t(1163)+t(868)+t(770)+"ver",npdrb:function(a,n){return a!==n},Peime:"OdRsw",ePJlH:t(1971)+t(1793)+t(1992)+"g",OUyrE:t(2006),nFLMX:t(758),WPoxG:function(a,n,s){return a(n,s)},QQKop:t(508)+t(1901)+t(1205)+t(1417),oCoyq:function(a,n){return a|n},IPxEe:function(a,n){return a|n},IOAbR:function(a,n){return a&n},uYZdy:function(a,n){return a<<n},vvDvQ:function(a,n){return a&n},gAiho:function(a,n){return a<<n},rMUZU:function(a,n){return a&n},ErJfZ:function(a,n){return a&n},JcFzJ:function(a,n){return a+n},vYprg:function(a,n){return a!==n},GOePt:function(a,n){return a!==n},mgSms:t(1467),oCusJ:"AEaLJ",tYrPK:t(1020),fuODN:t(609),ESRFL:"aWoMW",tsygR:function(a,n){return a===n},iOWUh:t(514),zvCSa:t(1673),OJjnF:function(a,n){return a+n},whYvV:t(1348)+t(914)+t(955)+t(600)+"ed",Ppfon:function(a,n){return a===n},dPsuk:function(a,n){return a||n},ULnMC:function(a,n){return a>=n},AnnLP:t(1764),YSZds:t(629)+"rovide a"+t(870)+t(1493)+t(1958)+"e a stri"+t(1379)+t(954)+"ffer",bPeDm:t(1318),HCLIx:"please p"+t(1252)+t(1167)+t(1504),bQxmp:function(a,n){return a instanceof n},bWLAa:function(a,n){return a(n)},CgASa:function(a,n){return a===n},RFmmV:t(1231),joeLG:function(a,n){return a<n},RfyzG:t(666),lwNUh:t(957),kKfhl:function(a,n){return a(n)},EbCYf:t(980),tjqIC:t(1076)+"econnect"+t(658),PKIgD:t(1668),tPzdr:function(a,n){return a!==n},FNnAs:t(900),mKJRd:t(1397),eoVEN:"YnUQp",iHaiz:function(a,n){return a>=n},bVMTw:t(677),ugKNh:"AyVeg",owEch:t(407),giROo:function(a,n){return a*n},ieMOs:function(a,n){return a===n},cVuLi:function(a,n){return a!=n},XKZht:function(a,n){return a===n},HsWdd:t(669),POlKM:function(a,n){return a!=n},BdDss:t(1510),WwFQJ:t(829)+t(532)+t(1925)+"pe",vUoCP:function(a,n){return a!=n},HEzDk:function(a,n){return a!=n},FexJX:function(a,n){return a===n},wAKRg:t(2002)+t(1043)+t(1154),THwsB:function(a,n){return a!=n},HLHiD:function(a,n){return a===n},kHcjM:function(a,n){return a!=n},dSEYa:function(a,n){return a!=n},wXKzs:"__x_msg_"+t(565)};Mt.r(Re),Mt.d(Re,{FWS:()=>Yp,CustomErrorEvent:()=>Kd,createCloseEvent:()=>ft,ReconnectEvent:()=>Wd,createErrorEvent:()=>ot,decodedFrame:()=>Qt,createOpenEvent:()=>Xd,CustomCloseEvent:()=>$d,createReconnectEvent:()=>aa,FrontierMessageEvent:()=>Jd,encodeFrame:()=>zt,createMessageEvent:()=>Zd,OpenEvent:()=>Yd,ErrorCode:()=>tn,Event:()=>Qn,MessageEvent:()=>Vd});let r="";function i(a=""){let n=t,s="02",l=""+Date.now(),f=r||(r=e[n(1975)](x,a)),h=Math[n(1331)]()[n(1896)](16)[n(950)](-6);return e.GnkCs(e[n(716)](s,l),f)+h}function o(){let a=t;return e[a(716)](1e4*Date[a(398)](),Math.floor(e[a(817)](1e4,Math[a(1331)]())))}function c(a){let n=t;return(e[n(1975)](Array,8)[n(2026)]("0")+e[n(865)](parseInt,a,10)[n(1896)](2)).slice(-8)}function d(a){let n=t;return e[n(1363)](e[n(1975)](Array,4)[n(2026)]("0"),e[n(1823)](parseInt,a,2)[n(1896)](16))[n(950)](-4)}function u(a){let n=t,s=a[n(1336)](/\./)[n(395)](h=>c(h)),l=[];return l[0]=e[n(1518)](d,e[n(716)](s[0],s[1])),l[1]=e.XgiHL(d,e.GnkCs(s[2],s[3])),[e[n(1306)],e[n(1306)],e[n(1306)],e[n(1306)],e.GUJpz,e[n(1905)],l[0],l[1]][n(2026)]("")}function x(a){let n=t;if(e[n(685)](e.tLEqt,n(857))){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1138)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1138)](a);return s?u(a):l?e[n(754)](p,a):e[n(1448)]}else _0x34f416[n(1197)](_0x16d5b0)}function p(a){let n=t,s={xXFfI:function(l,f){return e[G(754)](l,f)},trBpk:e.EEcaX};if(e[n(444)](e[n(1249)],"huCvF")){let l="",f=[],h=0,b=0,E=!0,g=e[n(1306)];if(a.indexOf("::")>-1){let I=a[n(1336)]("::");for(let z=0;e[n(1577)](z,I[n(1053)]);z++)if(e.LGpJd(e[n(748)],e[n(1516)])){let j=I[z];if(j.indexOf(":")>0){let F=j[n(1336)](":");E&&(h=F.length),b+=F[n(1053)];for(let W=0;e.yGlld(W,F[n(1053)]);W++)if(e[n(831)](4,F[W].length)){let ve=g[n(1751)+"g"](0,e[n(887)](4,F[W][n(1053)])),xt=ve.concat(F[W]);f[n(1582)](xt)}else f[n(1582)](F[W]);E=!1}else{if(e[n(831)](4,j[n(1053)])){let F=g.substring(0,e.pnGsa(4,j[n(1053)])),W=F[n(893)](j);f[n(1582)](W)}else f[n(1582)](j);E&&(h+=1),b+=1,E=!1}}else{if(this[n(1852)]&&e.jIdjD(this[n(1852)].readyState,this[n(1707)+"NG"])){this[n(1458)+"ngTimer"](),this["_pingPon"+n(1893)+"Id"]=e[n(865)](_0x3dcc7c,this[n(1620)].bind(this),this._options[n(809)+"rval"]);return}if(!this[n(1852)]||this[n(1852)][n(1717)+"te"]!==this[n(825)])return void this[n(1373)+n(1562)]();this._ws&&this._ws[n(2017)]("hi"),this[n(1243)+n(397)+n(1473)]=_0x25e705(this[n(1373)+n(1562)+"Timeout"][n(959)](this),this._options[n(891)+"outInter"+n(1150)])}let M="";for(let z=0;e[n(1577)](z,e[n(2007)](8,b));z++)M=M[n(893)](g);for(let z=0;e[n(1267)](z,f[n(1053)]);z++)e[n(1450)](z,h)&&(l=l.concat(M)),l=l[n(893)](f[z]);return l}{if(e.irKbL!==n(961))return e[n(1731)](1e4*_0x553fda.now(),_0x1b8693[n(557)](1e4*_0x346349.random()));{let I=a[n(1336)](":");for(let M=0;e.BqMrl(M,I[n(1053)]);M++){let z=I[M];if(e[n(831)](4,I[M][n(1053)])){let j=g[n(1751)+"g"](0,4-I[M][n(1053)]),F=j[n(893)](z);l=l[n(893)](F)}else l=l[n(893)](z)}return l}}}else _0x518c2e[n(836)+n(587)]=void 0,s[n(1123)](_0x381400,s[n(1917)])}function m(a,n){let s=t,l=a[s(1625)];e[s(831)](void 0,l)&&(e.XfKgn(he,n,10),e[s(2025)](q,n,l));let f=a[s(1611)];f!==void 0&&(e.FWnBa(he,n,18),e[s(997)](q,n,f))}function w(a){let n=t;if(e[n(966)]===e.kboPx)_0x1d6721=e[n(1518)](_0x506dd0,_0x1ea170),_0x5ed86c=127&_0x304dc8,e[n(1342)](128,_0x254db9)&&(_0xad81b5=e[n(1820)](_0x29fb4d,_0x5134be),_0x3c3f54|=e[n(1850)](e.gzLiD(127,_0x270777),7));else{let s={};e:for(;!J(a);){let l=e[n(574)](xe,a);switch(l>>>3){case 0:break e;case 1:s.key=O(a,xe(a));break;case 2:s[n(1611)]=e[n(1256)](O,a,e[n(1975)](xe,a));break;default:e.FWnBa(D,a,e[n(1342)](7,l))}}if(e[n(1030)](void 0,s[n(1625)]))throw new Error(e.Qclmu);if(e[n(790)](void 0,s.value))throw new Error(n(1765)+n(682)+n(1507)+n(1611));return s}}function S(a){let n=t,s=e[n(1719)](R);return _(a,s),e[n(574)](N,s)}function _(a,n){let s=t,l={PIbcQ:function(xt,ht){return e.ipoAr(xt,ht)}},f=a.SeqID;e[s(1979)](void 0,f)&&(e.PwXiZ(e[s(1248)],s(1239))?(e[s(1481)](he,n,8),e[s(2025)](ut,n,f)):(this[s(1073)+"ount"]=_0x22fd69,this[s(1044)]=0));let h=a[s(1391)];e[s(685)](void 0,h)&&(e[s(1481)](he,n,16),e[s(997)](ut,n,h));let b=a[s(1988)];b!==void 0&&(e[s(1841)](he,n,24),e.Kaclj(ut,n,e[s(1652)](k,b)));let E=a[s(689)];e.kXajD(void 0,E)&&(e[s(865)](he,n,32),e.sdDAU(ut,n,e[s(1820)](k,E)));let g=a.headers;if(e[s(1979)](void 0,g))for(let xt of g){he(n,42);let ht=e[s(1719)](R);e[s(1256)](m,xt,ht),e[s(1236)](he,n,ht[s(500)]),e[s(1057)](V,n,ht),e[s(1975)](P,ht)}let I=a[s(1183)+s(807)];e[s(1519)](void 0,I)&&(e[s(1057)](he,n,50),q(n,I));let M=a[s(1552)+s(855)];e[s(1825)](void 0,M)&&(e[s(771)](he,n,58),e.KXPXl(q,n,M));let z=a[s(787)];e[s(797)](void 0,z)&&(e.CayDz(he,n,66),e.dNxQF(he,n,z.length),oe(n,z));let j=a[s(1326)];if(e[s(1701)](void 0,j))if(e[s(797)](s(990),e[s(1202)]))he(n,74),e.ANges(q,n,j);else{let xt=_0x4e516a[s(1751)+"g"](0,KgwyPK[s(424)](4,_0x279b8a[_0xd3123][s(1053)])),ht=xt[s(893)](_0x4bcfe1[_0x9cce77]);_0x3c35df[s(1582)](ht)}let F=a[s(1508)+"ming"];e[s(1923)](void 0,F)&&(e[s(1841)](he,n,82),q(n,F));let W=a[s(1218)];e[s(1923)](void 0,W)&&(he(n,90),e[s(916)](q,n,W));let ve=a[s(1538)+"e"];ve!==void 0&&(e[s(1937)](he,n,96),e[s(634)](ut,n,e[s(1652)](k,ve)))}function v(a){let n=t;return e[n(960)](A,e[n(1358)](B,a))}function A(a){let n=t,s={};e:for(;!e[n(1389)](J,a);){let l=e[n(754)](xe,a);switch(l>>>3){case 0:break e;case 1:s.SeqID=e[n(1464)](St,a,!0);break;case 2:s[n(1391)]=e[n(2025)](St,a,!0);break;case 3:s[n(1988)]=e.sWcuF(xe,a);break;case 4:s.method=e[n(1034)](xe,a);break;case 5:{let f=e[n(1217)](T,a);(s[n(2019)]||(s[n(2019)]=[]))[n(1582)](e.TJiAX(w,a)),a[n(500)]=f;break}case 6:s[n(1183)+n(807)]=e.FWnBa(O,a,xe(a));break;case 7:s["payloadT"+n(855)]=O(a,xe(a));break;case 8:s[n(787)]=e[n(511)](ie,a,xe(a));break;case 9:s[n(1326)]=e[n(863)](O,a,e[n(754)](xe,a));break;case 10:s[n(1508)+n(1903)]=e.dxDRj(O,a,e[n(1217)](xe,a));break;case 11:s[n(1218)]=e[n(1640)](O,a,e[n(1820)](xe,a));break;case 12:s[n(1538)+"e"]=xe(a);break;default:D(a,7&l)}}if(s[n(515)]===void 0)throw new Error(e[n(1054)]);if(s[n(1391)]===void 0)throw new Error(e[n(1192)]);if(s.service===void 0)throw new Error(n(1765)+n(682)+n(1507)+n(1988));if(e[n(1936)](void 0,s.method))throw new Error(e[n(1670)]);return s}function T(a){let n=t;if(e[n(705)]!==e.lgqYO){let s=xe(a),l=a[n(500)];return a[n(500)]=e[n(716)](a[n(1232)],s),l}else e[n(2018)](_0x307315,this,_0xab0f1c,[_0x419f61,_0x5cf53d,_0x5ecb80])}function D(a,n){let s=t;switch(n){case 0:for(;e[s(1342)](128,se(a)););break;case 2:e[s(1706)](Y,a,e.IYEFc(xe,a));break;case 5:Y(a,4);break;case 1:e[s(1046)](Y,a,8);break;default:throw new Error(e.GnkCs(e[s(1882)],n))}}function k(a){let n=t;return a|=0,{low:a,high:e[n(1122)](a,31),unsigned:e[n(1309)](a,0)}}let y=[];function R(){let a=t,n=y[a(876)]();return n?(n[a(1232)]=n[a(500)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){y[t(1582)](a)}function B(a){return{bytes:a,offset:0,limit:a[t(1053)]}}function N(a){let n=t,s=a[n(1695)],l=a.limit;return s.length===l?s:s[n(580)](0,l)}function Y(a,n){let s=t;if(e.upqGK(e[s(2020)](a[s(1232)],n),a[s(500)]))throw new Error(e[s(1255)]);a.offset+=n}function J(a){let n=t;return e[n(1254)](e[n(1935)],"fELwE")?e[n(1309)](a.offset,a[n(500)]):e.ROYHD(_0x50129e,_0x15ec4a)}function te(a,n){let s=t;if(e.JsoYU(e[s(1523)],e.XMbSj))_0x4f9ccc&&this["_cursorM"+s(628)][s(544)+s(1136)+s(1444)](_0x1295e0);else{let l=a[s(1695)],f=a.offset,h=a[s(500)],b=f+n;if(e[s(1376)](b,l[s(1053)])){let E=new Uint8Array(e[s(1357)](2,b));E.set(l),a[s(1695)]=E}return a[s(1232)]=b,b>h&&(a[s(500)]=b),f}}function Z(a,n){let s=t,l=a[s(1232)];if(l+n>a[s(500)])throw new Error(e[s(1233)]);return a[s(1232)]+=n,l}function ie(a,n){let s=t,l=Z(a,n);return a.bytes[s(580)](l,e[s(981)](l,n))}function oe(a,n){let s=t,l=e[s(612)](te,a,n[s(1053)]);a[s(1695)][s(1434)](n,l)}function O(a,n){let s=t,l=Z(a,n),f=String[s(1692)+s(964)],h=a[s(1695)],b="\uFFFD",E="";for(let g=0;e[s(1470)](g,n);g++)if(e.EmonK!==s(1786)){let I=this[s(1322)],M=this[s(999)];return[e.cmGll(255,M),e[s(896)](e[s(920)](M,8),255),e[s(896)](e.SUExR(M,16),255),M>>>24,e[s(635)](255,I),e[s(1342)](I>>>8,255),e.fxZlq(I,16)&255,e[s(672)](I,24)]}else{let I=h[e[s(1390)](g,l)],M,z,j,F;e[s(1399)](128&I,0)?E+=f(I):e.KgdDM(224&I,192)?e[s(716)](g,1)>=n?E+=b:(M=h[e[s(939)](e[s(1390)](g,l),1)],e[s(992)](e[s(1800)](192,M),128)?E+=b:(F=e[s(1431)](e[s(917)](31,I),6)|63&M,e[s(895)](F,128)?E+=b:(E+=e.vpRLl(f,F),g++))):e[s(1628)](240&I,224)?e[s(1309)](e[s(2020)](g,2),n)?E+=b:(M=h[g+l+1],z=h[e[s(1403)](g+l,2)],((M|e.FuMkb(z,8))&49344)!==32896?E+=b:(F=e[s(594)](e[s(1360)](e.pCugr(15,I),12),e.lfUly(e.BRbLd(63,M),6))|e[s(635)](63,z),e[s(1577)](F,2048)||e[s(1309)](F,55296)&&e[s(383)](F,57343)?E+=b:(E+=e[s(1618)](f,F),g+=2))):e[s(635)](248,I)==240?g+3>=n?E+=b:(M=h[e[s(994)](g+l,1)],z=h[e.pPZnN(e[s(1927)](g,l),2)],j=h[e[s(1731)](e[s(994)](g,l),3)],e[s(1701)](e[s(1664)](e[s(1536)](e[s(594)](M,e[s(469)](z,8)),e.ARikj(j,16)),12632256),8421504)?E+=b:(F=e[s(1536)](e[s(1536)](e[s(928)](e[s(1702)](e[s(1302)](7,I),18),e[s(952)](63&M,12)),e[s(1850)](e.SHZRI(63,z),6)),e[s(614)](63,j)),e[s(726)](F,65536)||e.TwltV(F,1114111)?E+=b:(F-=65536,E+=f(e[s(406)](e[s(1122)](F,10),55296),e[s(1302)](1023,F)+56320),g+=3))):E+=b}return E}function q(a,n){let s=t,l={NMYyj:function(g,I){return e[G(1848)](g,I)},IKUYl:function(g,I){return e[G(1353)](g,I)},eKCSv:function(g,I){return e[G(1181)](g,I)},lKhcx:function(g,I){return e[G(1758)](g,I)},twzZa:function(g,I){return e[G(1302)](g,I)},goZoo:function(g,I){return e[G(466)](g,I)}},f=n[s(1053)],h=0;for(let g=0;e.kzmzo(g,f);g++){let I=n.charCodeAt(g);e[s(1309)](I,55296)&&e[s(383)](I,56319)&&g+1<f&&(I=e[s(1045)](e[s(1137)](e[s(1848)](I,10),n[s(1661)+"At"](++g)),56613888)),h+=e[s(1028)](I,128)?1:e[s(1470)](I,2048)?2:I<65536?3:4}e[s(1416)](he,a,h);let b=te(a,h),E=a[s(1695)];for(let g=0;e.qvTxG(g,f);g++){let I=n[s(1661)+"At"](g);I>=55296&&e[s(1919)](I,56319)&&e[s(703)](e[s(1838)](g,1),f)&&(I=e.CxHsF(e[s(874)](e[s(1312)](I,10),n[s(1661)+"At"](++g)),56613888)),e[s(726)](I,128)?E[b++]=I:e[s(1891)]===e[s(617)]?this[s(640)+s(1025)]():(I<2048?E[b++]=e.zjgEk(e[s(1566)](I>>6,31),192):e[s(685)](e[s(1586)],e[s(517)])?(e.qvTxG(I,65536)?E[b++]=e.WPaHj(I>>12&15,224):(E[b++]=e.HbIni(e[s(1122)](I,18)&7,240),E[b++]=e[s(766)](e[s(614)](e[s(1122)](I,12),63),128)),E[b++]=e[s(1041)](e[s(1663)](e[s(1122)](I,6),63),128)):(_0x932adc=_0x121873(_0x75009a),_0x2836e6|=l[s(1120)](l[s(1039)](127,_0x2c5d09),21),l[s(1261)](128,_0x41bc4c)&&(_0x56d766=l.lKhcx(_0x34e202,_0xb85317),_0x2dc4a4=l[s(1344)](127,_0x1c0bb5),l[s(1186)](128,_0x4aa890)&&(_0x148b40=l.lKhcx(_0x40a033,_0x4bc5c6),_0xc37853|=l[s(1120)](l[s(1039)](127,_0x7dcacc),7)))),E[b++]=e[s(1041)](e.dMVGP(63,I),128))}}function V(a,n){let s=t,l=e[s(1635)](te,a,n[s(500)]),f=a[s(1695)],h=n.bytes;for(let b=0,E=n.limit;e.LHbUN(b,E);b++)f[b+l]=h[b]}function se(a){return a.bytes[e.XfKgn(Z,a,1)]}function Je(a,n){let s=t,l=e[s(1173)](te,a,1);a.bytes[l]=n}function xe(a){let n=t,s={ZzTRI:e[n(401)],UGNrL:n(1988),ogNet:n(1613)+n(1504),UmlTA:function(l,f,h,b){return l(f,h,b)},zAYpV:e[n(2001)],YzKuK:e[n(1775)],gagPe:e[n(1090)],wsKlb:e[n(1077)]};if(e.ptrJk(e[n(1119)],e.kvicz)){let l=0,f=0,h;do if(e.eyaJO(e[n(571)],e[n(1335)])){let b=s[n(1789)][n(1336)]("|"),E=0;for(;;){switch(b[E++]){case"0":_0x3236e2[n(1197)](s.UGNrL,_0x26440a);continue;case"1":_0x524b58=_0x15417c(_0x39a0fb[n(1543)+"er"](_0x1766e7[n(493)]||_0x2335de),_0x3dc821,_0x92a677);continue;case"2":_0x5d758a[n(1197)](s.ogNet,_0x56e2ff,_0x5a7a5f[n(1988)]);continue;case"3":_0x446e68=_0x94fdc(_0x25a64f,_0x194aad,_0x443f38.service||0);continue;case"4":_0x375659=s.UmlTA(_0x7bd9da,_0x3fff77[_0x52e354[n(1316)+"ame"]],_0x109d3d,_0x305141);continue;case"5":_0x149a14=s.UmlTA(_0x375e2a,_0x28993d[n(1316)+n(991)],_0x1e32ed,_0x28105d);continue;case"6":_0x814947[n(1197)](s[n(1168)],_0x137925);continue;case"7":_0x21af16.log(s.YzKuK,_0x2f8658);continue;case"8":_0x6c557f.log(s[n(1387)],_0x53d854);continue;case"9":_0x231992.log(s[n(701)],_0x4939f2);continue;case"10":_0x16555d=s[n(1027)](_0x521305,0,_0x51f7fb,_0x3dd32b);continue}break}}else h=e.pjPlZ(se,a),e[n(1015)](l,32)&&(f|=e[n(1502)](127,h)<<l),l+=7;while(e[n(651)](128,h));return f}else{_0x15b115[n(503)](_0x446ffb)||(_0x3959a8=_0x2870c3[n(1543)+"er"](_0x15852d));let l=e[n(1101)](this.high,16),f=e.YdAuC(65535,this[n(1322)]),h=e[n(536)](this.low,16),b=e[n(1394)](65535,this[n(999)]),E=e.TPxto(_0x114ac1[n(1322)],16),g=e[n(1485)](65535,_0x707527[n(1322)]),I=e[n(1396)](_0x56dbab[n(999)],16),M=e.OQUGn(65535,_0x503742[n(999)]),z=0,j=0,F=0,W=0;return W+=b+M,F+=e[n(672)](W,16),W&=65535,F+=e.Ubxof(h,I),j+=F>>>16,F&=65535,j+=f+g,z+=e[n(536)](j,16),j&=65535,z+=e.pPZnN(l,E),z&=65535,_0x4023f1[n(1383)](e[n(1914)](e.lfUly(F,16),W),e[n(1914)](z<<16,j),this[n(1480)])}}function he(a,n){let s=t;for(n>>>=0;e[s(1309)](n,128);)e.JjCit(Je,a,e[s(1465)](e.ipeUr(127,n),128)),n>>>=7;e[s(905)](Je,a,n)}function St(a,n){let s=t;if(e.HEUfQ===e[s(973)])return this.endpoints[this[s(1277)+s(1729)]];{let l=0,f=0,h=0,b;if(b=e[s(1652)](se,a),l=e[s(1342)](127,b),e[s(1800)](128,b)&&(b=e[s(1166)](se,a),l|=e.RIDhZ(e[s(1663)](127,b),7),e[s(489)](128,b)&&(b=e[s(621)](se,a),l|=e.ARikj(e[s(1961)](127,b),14),128&b)))if(e[s(1621)]("ppHlw",e.SuubE))b=e[s(1537)](se,a),l|=e[s(801)](127&b,21),e.LWtvD(128,b)&&(b=e[s(1217)](se,a),f=e.cmGll(127,b),e[s(1485)](128,b)&&(b=e.WhxpA(se,a),f|=e.FuMkb(127&b,7),e[s(420)](128,b)&&(b=e.OdLQR(se,a),f|=e[s(635)](127,b)<<14,e[s(791)](128,b)&&(b=se(a),f|=e[s(885)](127&b,21),e[s(1419)](128,b)&&(b=e.xvxph(se,a),h=e[s(438)](127,b),e[s(1342)](128,b)&&(b=se(a),h|=e[s(497)](e[s(434)](127,b),7)))))));else return _0x2ab3d1?this.toBytesLE():this[s(732)+"E"]();return{low:e[s(1056)](l,f<<28),high:e[s(1686)](f,4)|e[s(1431)](h,24),unsigned:n}}}function ut(a,n){let s=t,l=n[s(999)]>>>0,f=e[s(1101)](e[s(1496)](e[s(1244)](n[s(999)],28),n[s(1322)]<<4),0),h=e.jGRDe(n[s(1322)],24),b=e[s(1621)](0,h)?e[s(1784)](0,f)?l<16384?e.oeCkc(l,128)?1:2:e[s(1928)](l,2097152)?3:4:e.Zdqli(f,16384)?f<128?5:6:e.Zdqli(f,2097152)?7:8:e[s(618)](h,128)?9:10,E=e[s(1464)](te,a,b),g=a[s(1695)];switch(b){case 10:g[e[s(1390)](E,9)]=e[s(614)](h>>>7,1);case 9:g[e[s(396)](E,8)]=e.IcOfq(9,b)?128|h:e.DXKgM(127,h);case 8:g[e[s(874)](E,7)]=b!==8?e[s(1056)](e.fxZlq(f,21),128):e[s(1050)](e[s(1697)](f,21),127);case 7:g[E+6]=b!==7?e.jGRDe(f,14)|128:e[s(1302)](e[s(1830)](f,14),127);case 6:g[e[s(1137)](E,5)]=e[s(1519)](6,b)?e[s(1244)](f,7)|128:e[s(388)](f,7)&127;case 5:g[e[s(985)](E,4)]=e[s(1825)](5,b)?e[s(1989)](128,f):e[s(1342)](127,f);case 4:g[e.QXeMX(E,3)]=b!==4?e[s(1041)](l>>>21,128):e[s(1419)](e[s(1680)](l,21),127);case 3:g[e[s(1561)](E,2)]=e[s(1825)](3,b)?e[s(1680)](l,14)|128:e[s(917)](e[s(487)](l,14),127);case 2:g[e[s(2020)](E,1)]=e[s(1979)](2,b)?e[s(1536)](e.tRcOX(l,7),128):e[s(1061)](e[s(525)](l,7),127);case 1:g[E]=b!==1?e[s(1780)](128,l):e[s(1229)](127,l)}}function Qt(a){let n=t;return e[n(1254)](e.lTbcs,n(1096))?this._socket[n(864)]:e[n(1667)](v,a)}function zt(a){let n=t,s={ucgbd:function(l,f,h){return l(f,h)}};if(e[n(1973)]===e[n(1973)])return e[n(418)](S,a);{let l=bTpdmR[n(1745)](_0x2a3c84,_0x38d564,_0x20524c[n(1053)]);_0x440a54[n(1695)][n(1434)](_0x12cf5f,l)}}let en=65536,Vr=e[t(1995)],me=en*en,Te=e[t(1230)](me,me),Xn=e[t(1592)](Te,2),Pe=String.prototype[t(1661)+"At"];class fe{constructor(n,s,l){let f=t;this.isLong=!0,this[f(999)]=e[f(1791)](0,n),this[f(1322)]=e[f(1056)](0,s),this[f(1480)]=!!l}static isLong(n){return n&&n.isLong===!0}static[t(1383)](n,s,l){return new fe(n,s,l)}static[t(1129)+"s"](n,s,l){let f=t,h={ijkzV:e[f(1012)]};if(e[f(743)](e[f(843)],e[f(843)]))return l?fe[f(1129)+f(833)](n,s):fe[f(1129)+f(751)](n,s);{let b=h.ijkzV[f(1336)]("|"),E=0;for(;;){switch(b[E++]){case"0":this[f(450)+f(1228)]=!1;continue;case"1":this[f(1117)+"tManager"]?.[f(1381)+f(1619)+f(1851)]();continue;case"2":this[f(1290)]=!0;continue;case"3":this[f(527)]();continue;case"4":this[f(2037)+"sCounter"]?.[f(416)+f(1103)]();continue}break}}}static[t(1129)+t(833)](n,s){let l=t;return new fe(e[l(1791)](e[l(1989)](n[0],e.BMDsQ(n[1],8))|e[l(1354)](n[2],16),e.pZxaE(n[3],24)),e[l(1465)](e[l(1914)](n[4]|e[l(1734)](n[5],8),e[l(1682)](n[6],16)),e[l(452)](n[7],24)),s)}static[t(1129)+"sBE"](n,s){let l=t;return new fe(e[l(1041)](e[l(1038)](n[4]<<24,n[5]<<16),e[l(533)](n[6],8))|n[7],e[l(1038)](e[l(972)](e.NNedC(e[l(533)](n[0],24),n[1]<<16),e.LwhIu(n[2],8)),n[3]),s)}static[t(608)](n){let s=t;return e.UyeHk(n,Vr)?jd:new fe(e[s(1906)](e[s(897)](e[s(1655)](e.mGCzf(Pe[s(923)](n,0),e[s(1850)](Pe[s(923)](n,1),8)),e[s(1999)](Pe[s(923)](n,2),16)),e[s(1632)](Pe.call(n,3),24)),0),e.cLYXs(Pe[s(923)](n,4)|e[s(1817)](Pe[s(923)](n,5),8)|e[s(550)](Pe[s(923)](n,6),16)|e[s(1283)](Pe[s(923)](n,7),24),0),!0)}[t(1601)](){let n=t;return e[n(1269)]!=="VPNrk"?new _0x2eb7e6(e[n(1594)](e.PhrLE(e.AYJBi(_0x10f090[0],e[n(935)](_0xeefe0b[1],8)),_0x34122[2]<<16),e[n(1682)](_0x29b7a7[3],24)),e.Tnbxo(e[n(594)](e.SchjC(_0x15aeaa[4],e[n(1965)](_0x53ba8e[5],8)),e[n(1734)](_0x2b4f83[6],16)),e[n(885)](_0x4bc580[7],24)),_0x232d26):String["fromChar"+n(964)](255&this[n(999)],e[n(451)](e[n(1029)](this.low,8),255),e[n(880)](this[n(999)]>>>16,255),e[n(1e3)](this[n(999)],24),e[n(699)](255,this[n(1322)]),e[n(534)](e[n(1215)](this[n(1322)],8),255),e[n(917)](e[n(1525)](this.high,16),255),e.UWusy(this[n(1322)],24))}static[t(1543)+"er"](n,s=!0){let l=t;if(e.nuFRi(isNaN,n))return s?cp:jd;if(s){if(e[l(1309)](n,Te))return lp}else{if(n<=-Xn)return up;if(e.ynFAj(n,1)>=Xn)return dp}return fe[l(1383)](e[l(903)](e[l(1531)](n,me),0),e[l(903)](e[l(1592)](n,me),0),s)}toNumber(){let n=t;return this[n(1480)]?e[n(985)](e[n(1169)](this.high>>>0,me),e[n(510)](this[n(999)],0)):e[n(939)](e[n(1649)](this[n(1322)],me),e.tRcOX(this[n(999)],0))}[t(804)](){let n=t;return e[n(790)](0,this.high)&&e[n(899)](0,this[n(999)])}[t(1378)](n){let s=t;fe.isLong(n)||(n=fe[s(1543)+"er"](n));let l=e[s(1888)](this[s(1322)],16),f=e.SHZRI(65535,this[s(1322)]),h=e[s(1863)](this.low,16),b=e.oBnEV(65535,this[s(999)]),E=e[s(778)](n[s(1322)],16),g=e[s(896)](65535,n[s(1322)]),I=n[s(999)]>>>16,M=e.pmshz(65535,n[s(999)]),z=0,j=0,F=0,W=0;return W+=e.YOtNV(b,M),F+=e[s(1029)](W,16),W&=65535,F+=e[s(1426)](h,I),j+=F>>>16,F&=65535,j+=e[s(406)](f,g),z+=e[s(1207)](j,16),j&=65535,z+=e[s(1561)](l,E),z&=65535,fe[s(1383)](e[s(708)](F,16)|W,e[s(1791)](e.jHnHk(z,16),j),this.unsigned)}[t(1139)](n){let s=t;return fe[s(503)](n)||(n=fe[s(1543)+"er"](n)),this[s(1480)]!==n[s(1480)]&&e[s(536)](this[s(1322)],31)===1&&e[s(1816)](n[s(1322)],31)===1?!1:e[s(848)](this[s(1322)],n[s(1322)])&&e[s(584)](this.low,n[s(999)])}addOne(){let n=t;return e.MZuag(-1,this[n(999)])&&this.high===-1?fe[n(1383)](0,0,this.unsigned):e[n(1861)](-1,this[n(999)])?fe[n(1383)](0,this[n(1322)]+1,this[n(1480)]):fe[n(1383)](e[n(1155)](this[n(999)],1),this[n(1322)],this[n(1480)])}[t(847)](n){let s=t;return n?this[s(1656)+"E"]():this[s(732)+"E"]()}[t(1656)+"E"](){let n=t,s=this.high,l=this[n(999)];return[e.lcPcX(255,l),e[n(1738)](l>>>8,255),e.IWnCd(l>>>16,255),l>>>24,e[n(1021)](255,s),e[n(1e3)](s,8)&255,e[n(1221)](s,16)&255,s>>>24]}[t(732)+"E"](){let n=t,s=this[n(1322)],l=this.low;return[s>>>24,e[n(1200)](s,16)&255,e.WxVyI(s>>>8,255),e[n(930)](255,s),e[n(525)](l,24),l>>>16&255,e[n(1332)](l>>>8,255),e[n(1353)](255,l)]}}let jd=new fe(0,0,!1),cp=new fe(0,0,!0),dp=fe.fromBits(-1,2147483647,!1),lp=fe[t(1383)](-1,-1,!0),up=fe[t(1383)](0,-2147483648,!1);var tn=(function(a){let n=t;if(e[n(967)](n(563),e[n(506)])){let s=e[n(417)][n(1336)]("|"),l=0;for(;;){switch(s[l++]){case"0":a[a.MESSAGE_ERROR=5004]=e[n(704)];continue;case"1":a[a[e[n(1650)]]=5001]=e.UZaHY;continue;case"2":return a;case"3":a[a[n(663)+"OR"]=5005]=e[n(465)];continue;case"4":a[a[e[n(1654)]]=5002]=n(1707)+"NG_ERROR";continue;case"5":a[a[e[n(1048)]]=5003]=e[n(1048)];continue}break}}else{let s=e[n(713)][n(1336)]("|"),l=0;for(;;){switch(s[l++]){case"0":_0x55cf26=e[n(1188)](e[n(1038)](_0x22faa7,e[n(1856)](e[n(1887)](127,_0x45eb41[_0x47c576]),14)),0);continue;case"1":if((_0x2039d6+=5)>_0x137585[n(1053)])throw _0x487e1d=_0x308764[n(1053)],_0x426244(_0x41de71,10,_0x16cdd0.length);continue;case"2":if(_0x56ce48[_0x61c82d++]<128)return{value:_0x2a03b3?_0xaced35:e[n(1712)](0,_0x5a5809),offset:_0x4675fe};continue;case"3":_0x5a3db7=e[n(1918)](e[n(1135)](127,_0x2fdce1[_0x4b151a]),0);continue;case"4":if(_0x5e6ebb[_0x1a2d08++]<128)return{value:_0x4d51d6?_0x4aa7b7:0|_0xc02f37,offset:_0x2334c7};continue;case"5":if(e[n(929)](_0x2d78b9[_0x1c02cc++],128))return{value:_0x2502cb?_0x54d3a6:e[n(538)](0,_0x5c50dd),offset:_0x5583fc};continue;case"6":_0x5d4e1e=e[n(1596)](_0x5cfd5b|e[n(1886)](e[n(926)](15,_0x10c072[_0x1da5bf]),28),0);continue;case"7":return{value:_0x198eab?_0x3e1487:0|_0x548c92,offset:_0x4867fb};case"8":_0x947965=e[n(1748)](_0x19e663,(127&_0x333b82[_0x3eb092])<<7)>>>0;continue;case"9":if(e[n(726)](_0x50afff[_0x4cd9a3++],128))return{value:_0xdcbc0e?_0xa861c6:e.cCSpV(0,_0x57e72a),offset:_0x3f9252};continue;case"10":_0x198920=e.xrJyu(e[n(694)](_0x14a357,e[n(420)](127,_0x2874be[_0x4b449c])<<21),0);continue;case"11":if(_0x577735[_0x237db4++]<128)return{value:_0x4bcb80?_0x4b5665:e[n(1966)](0,_0xa6f23),offset:_0x1693d8};continue}break}}})({});class Qn{constructor(n){let s=t;this.type=n,this[s(1260)]=null}}class Wd extends Qn{constructor(n,s){let l=t;super(n),this[l(2027)]=s&&s[l(2027)]||null}}class Kd extends Qn{constructor(n,s){let l=t;if(e[l(1979)](e[l(1285)],e[l(1285)]))this.on(_0x287dfb,_0x43eede);else{let f=(l(1704)+l(2028))[l(1336)]("|"),h=0;for(;;){switch(f[h++]){case"0":this[l(1430)]=s&&s[l(1430)]||null;continue;case"1":this[l(2027)]=s&&s.message||"";continue;case"2":this[l(1398)]=s&&s.lineno||0;continue;case"3":this[l(1404)]=s&&s[l(1404)]||0;continue;case"4":this.code=s&&s[l(1600)]||5001;continue;case"5":super(n);continue;case"6":this[l(1180)]=s&&s[l(1180)]||"";continue}break}}}}class $d extends Qn{constructor(n,s){let l=t,f=(l(1808)+"1")[l(1336)]("|"),h=0;for(;;){switch(f[h++]){case"0":this[l(1600)]=s&&s.code||0;continue;case"1":this[l(2039)+l(1803)]=s&&s[l(2039)+l(1803)]||!1;continue;case"2":this[l(492)]=s&&s[l(492)]||"";continue;case"3":this.wasClean=s&&s[l(1439)]||!1;continue;case"4":super(n);continue}break}}}class Vd extends Qn{constructor(n,s){let l=t;super(n),this.data=s&&s[l(1273)]||null}}class Jd extends Vd{constructor(n,s){let l=t;super(n),this[l(1273)]=s&&s[l(1273)]||null,this.message=s&&s.message||null}}class Yd extends Qn{constructor(n,s){let l=t;super(n),this[l(1273)]=s&&s.data||null}}function ot(a,{message:n,code:s,error:l}){return new Kd(a,{message:n,code:s,error:l})}function ft(a,{code:n,reason:s,wasClean:l,willReconnect:f}){let h=t,b={NEnFV:function(E,g){return e.XXgWr(E,g)},STIWg:function(E,g){return e[G(560)](E,g)},BNgxL:h(1880)+h(946),NKdss:"applicat"+h(946)+h(1110)+h(1156),abefw:h(1240),IpaOF:e[h(1514)],PJqtU:e.BAbOP,piXzi:function(E,g,I,M){return e[h(2018)](E,g,I,M)}};if(e[h(992)](e[h(1837)],e[h(504)]))return new $d(a,{code:n,reason:s,wasClean:l,willReconnect:f});{let E=b.NEnFV(this._options[h(1183)+h(807)],_0x55ab1d)?{force:!!this._options[h(1183)+h(807)].force,encoding:this[h(738)]["payloadE"+h(807)][h(1855)]?this[h(738)][h(1183)+h(807)][h(1855)][h(1794)](/\s/g,"")[h(1330)+h(1767)]():""}:{force:!1,encoding:this[h(738)][h(1183)+h(807)]?this[h(738)][h(1183)+"ncoding"].replace(/\s/g,"")[h(1330)+"ase"]():""},g=_0x45164f["payloadE"+h(807)]?_0x2c05d9[h(1183)+"ncoding"][h(1794)](/\s/g,"")[h(1330)+"ase"]():"",I=b[h(1685)](this[h(738)][h(1552)+h(855)],_0x15348a)?{force:!!this[h(738)][h(1552)+h(855)][h(662)],type:this[h(738)]["payloadT"+h(855)][h(927)]?this[h(738)][h(1552)+h(855)].type[h(1794)](/\s/g,"")[h(1330)+h(1767)]():""}:{force:!1,type:this[h(738)][h(1552)+h(855)]?this._options[h(1552)+h(855)][h(1794)](/\s/g,"")[h(1330)+h(1767)]():""},M=_0x31b71e[h(1552)+"ype"]?_0x3b4738[h(1552)+"ype"][h(1794)](/\s/g,"")[h(1330)+h(1767)]():"",z=I[h(662)]?I[h(927)]:M||I[h(927)],j=E.force?E[h(1855)]:g||E.encoding,F=[h(1437)+h(638)+"et=utf-8",b[h(1641)],b[h(1938)],b.abefw],W=[b[h(1617)],b.PJqtU];this[h(738)][h(1478)+h(1400)+h(792)+"ad"]&&F[h(648)](z)&&(!j||W[h(648)](j))?_0x5eee9c[h(1107)+h(1286)]=b.piXzi(_0x2a3e28,_0x213cb6[h(787)],0,_0x4fad2e.payload[h(878)+"th"]):_0x5e52d4[h(1107)+h(1286)]=""}}function Zd(a,{data:n,message:s}){let l=t;if(e[l(1923)](l(1659),e.jeJZQ))return new Jd(a,{data:n,message:s});lJxThV[l(846)](_0x20f129,lJxThV[l(1811)](_0x486a4d,_0x3de9b4.result),_0x23ecbf[l(828)+"on"],_0x4f805d[l(962)+"on"],lJxThV[l(1034)](_0x3228fa,_0x2705fa[l(1615)+"ion"]))}function Xd(a,{data:n}){return new Yd(a,{data:n})}function aa(a,{message:n}){return new Wd(a,{message:n})}class Qd{constructor(n,s){let l=t;this.endpoints=n,this[l(1862)+"es"]=s,this[l(1277)+"ndex"]=0,this[l(1921)+l(456)+l(501)+"t"]=0}["resetEndpointCon"+t(1851)](){let n=t;this[n(1277)+"ndex"]=0,this.currentEndpointTriesCount=0}[t(1425)+"es"](){let n=t;this["currentE"+n(456)+n(501)+"t"]=0}[t(1359)+t(989)+"nt"](){let n=t;return this[n(1113)+"s"][this[n(1277)+"ndex"]]}[t(1359)+"ntEndpoi"+t(1842)+"ount"](){let n=t;return this["currentE"+n(456)+n(501)+"t"]}[t(1245)+t(958)+"es"](){let n=t,s={BNPXU:function(l,f){return e[G(1442)](l,f)},mmAxA:function(l,f){return e[G(656)](l,f)},QNDiD:function(l,f){return e[G(945)](l,f)},CMgZr:function(l,f){return e[G(1738)](l,f)},VrFLz:function(l,f){return l+f}};if(n(1535)!==n(1535)){if(s[n(844)](_0x18b3de,1)||_0x42654f>_0x272aa7)return _0x2e3106(_0x3c1774);s[n(1657)](_0x413067+_0x5de99d,_0x417b88)&&(_0x5287f0=s.QNDiD(_0x375a15,_0x47b0de),_0x4e29d7=0);let l=_0x303a9b[n(923)](_0x1824f4,_0x2c1090,_0x162f4b+=_0x478923);return s[n(761)](7,_0x35f866)&&(_0x315ebd=s.VrFLz(7|_0x5cc060,1)),l}else return!!(e[n(1178)](this[n(1277)+n(1729)],this.endpoints[n(1053)])||e.lhImS(this[n(1277)+n(1729)],e.zPFUe(this[n(1113)+"s"][n(1053)],1))&&e[n(1271)](this[n(1921)+"ndpointT"+n(501)+"t"],this[n(1862)+"es"]))}["checkCurrentEndp"+t(1718)+t(659)+t(1599)](){let n=t;if(e[n(1086)](n(1860),n(431)))this[n(1733)](n(1980),e[n(1772)](_0x3fcdea,n(1980),{..._0x25959b,data:_0x32bfeb.errMsg||""}));else return e[n(1064)](this[n(1277)+n(1729)],this[n(1113)+"s"][n(1053)])?!0:e[n(656)](this[n(1921)+n(456)+n(501)+"t"],this[n(1862)+"es"])}["replaceB"+t(1879)+t(2038)+"UpdateCount"](){let n=t;return this[n(1921)+n(456)+"riesCount"]=1,this[n(1277)+n(1729)]++,this.endpoints[this[n(1277)+n(1729)]]}[t(1359)+t(989)+"ntAndUpdateCount"](){let n=t,s={ufpBm:e[n(641)],cRfGe:e[n(427)]};return e[n(1936)](e[n(573)],e[n(573)])?(this[n(1921)+n(456)+n(501)+"t"]++,this[n(1359)+"ntEndpoint"]()):{frameType:_0x416e20,headers:[{key:s[n(2012)],value:s[n(1796)]}],payload:void 0}}}let er=(e[t(631)]("undefined",typeof globalThis)&&e[t(795)]("Window",globalThis[t(1920)+t(1469)][t(1482)])||e[t(918)](t(1142)+"d",typeof window)&&e.XKZht(e[t(1578)],window[t(1920)+t(1469)][t(1482)]))&&e[t(601)](e[t(1409)],typeof document),Dn=e[t(631)](e.Qqnjt,typeof globalThis)&&(e[t(1968)]===globalThis[t(1920)+t(1469)].name||e[t(2032)](e[t(1372)],globalThis["construc"+t(1469)][t(1482)]))&&e[t(601)](e.Qqnjt,typeof tt),Jr=(e.vUoCP(e[t(1409)],typeof globalThis)&&e.VnqEq(e[t(1968)],globalThis[t(1920)+t(1469)].name)||e[t(1628)](e.Qqnjt,typeof globalThis)||t(1142)+"d"!=typeof globalThis&&!!globalThis["WeixinJS"+t(1341)])&&e.Qqnjt!=typeof wx,Yr=e[t(615)](e[t(1409)],typeof globalThis)&&(e.WwFQJ===globalThis[t(1920)+t(1469)][t(1482)]||e[t(1174)](e.wAKRg,globalThis[t(1920)+t(1469)][t(1482)])||e[t(1872)](t(901)+t(1317)+t(1092),globalThis.constructor.name))&&e.vUoCP(e[t(1409)],typeof self),fp=e[t(615)](e[t(1409)],typeof globalThis)&&t(1510)===globalThis[t(1920)+t(1469)].name&&e.THwsB(e[t(1409)],typeof global)&&e.HLHiD(e.BdDss,global["construc"+t(1469)][t(1482)])&&e[t(394)]("undefined",typeof process)&&!!process[t(1033)];class ca{constructor(){let n=t;this[n(1234)+"rs"]={}}[t(1733)](n,...s){let l=t,f=this[l(1234)+"rs"][n];if(f)f[l(950)]()[l(1201)](h=>h.fn[l(567)](h[l(1487)],s));else if(e.AVPCw(e[l(1819)],n)&&!this[l(1645)]){let h=s[l(1053)]&&s[0];if(h instanceof Error)throw h;let b=new Error(e[l(595)](l(1492)+l(728),h?e[l(393)](e[l(595)](" (",h[l(2027)]),")"):""));throw b[l(1035)]=h,h}return this}off(n,s){let l=t;if(e.zFWLN(void 0,n))this[l(1234)+"rs"]={};else if(e[l(790)](void 0,s))this._listeners[n]=null;else if(e.wkWZP!==e[l(1063)]){let f=_0x28c8e2[l(1661)+"At"](_0x1b7c93);e[l(1583)](f,55296)&&f<=56319&&e[l(1074)](e.YnpNB(_0x1b4e00,1),_0x2267f5)&&(f=e[l(1253)](e[l(1898)](f<<10,_0x2188ce[l(1661)+"At"](++_0x4bbf51)),56613888)),e.yGlld(f,128)?_0x2482c0[_0x554b3c++]=f:(e[l(1116)](f,2048)?_0x2c6fc9[_0xd08be4++]=e[l(934)](e[l(1451)](f,6)&31,192):(e[l(592)](f,65536)?_0x4ad224[_0x74bd27++]=e[l(1451)](f,12)&15|224:(_0x3ccd73[_0x332b80++]=e[l(1435)](e[l(1009)](e.zHpYz(f,18),7),240),_0x57f201[_0xb4ff83++]=e.FkgFB(e[l(1184)](f,12),63)|128),_0xbd003c[_0x54d4da++]=e.XMtAr(f,6)&63|128),_0x4b966b[_0x26157b++]=e[l(880)](63,f)|128)}else{let f=this[l(1234)+"rs"][n];if(f)for(let h=0;e[l(1074)](h,f.length);)e[l(1471)](f[h].fn,s)?f[l(785)](h,1):++h}return this}on(n,s,l){let f=t,h={iuqTJ:function(b,E,g,I){return b(E,g,I)},eqmFA:e[f(746)],TfnHp:function(b,E,g,I){return e.RxdBs(b,E,g,I)},QmRyW:function(b,E,g){return e.fJwzF(b,E,g)},QQIMx:e.wWofQ};if(e[f(2016)](e[f(1165)],e.egjxK)){let b=!!this[f(738)][f(1037)+"S"];if(!b)return{enabled:b,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let E=h[f(519)](_0x374f56,_0x1cd748[f(2027)][f(2019)],"x_fronti"+f(1769),"2"),g=E&&h[f(519)](_0x22c9a3,_0xd404fb[f(2027)][f(2019)],h[f(741)],"1"),I=E&&h[f(647)](_0x29f6a2,_0xa5c12f[f(2027)][f(2019)],"x_fronti"+f(1489)+"k","1"),M=I?h[f(1964)](_0x2df1aa,_0x2f78e2.message[f(2019)],h.QQIMx)?.[f(1336)](",")[f(1714)](_0x3eec1f)||[]:[];return{enabled:b,isQoSMessage:E,isQoSAck:g,isAckCleanupMessage:I,ackMsgIds:M}}else return(this[f(1234)+"rs"][n]||(this._listeners[n]=[]))[f(1582)]({fn:s,ctx:l||this}),this}}class xp extends ca{["_formatE"+t(1131)+t(1715)](n){let s=t,l={UiSbd:function(f,h){return e[G(1155)](f,h)},SktDn:function(f,h){return f+h},bQjwQ:function(f,h){return f!==h},xTTNW:function(f,h){return e[G(1677)](f,h)},avZmt:function(f,h){return e.vRRGf(f,h)},Kjmge:function(f,h){return f<<h},HStmU:function(f,h){return f&h},SXUPz:function(f,h){return e[G(1267)](f,h)}};if(e[s(1511)](e[s(521)],e[s(521)]))_0x2af2c0=_0xc291a3[vPVSQT.UiSbd(vPVSQT[s(1630)](_0x1a1468,_0xcf4b9),1)],vPVSQT[s(399)](vPVSQT[s(1544)](192,_0x211a0c),128)?_0x2f54bd+=_0x568bd1:(_0x13802a=vPVSQT[s(1926)](vPVSQT.Kjmge(31&_0x47b40a,6),vPVSQT[s(1352)](63,_0x2d7d90)),vPVSQT[s(576)](_0x22267e,128)?_0x287b0b+=_0x4fdf94:(_0x236efd+=_0x56eb9f(_0x278c97),_0x513e73++));else return n[s(1869)]||n[s(1709)]?("message: "+(n[s(1869)]||"")+s(627)+(n[s(1709)]||""))[s(1603)]():JSON[s(1060)+"y"](n)}constructor(n,s,l){let f=t;if(e[f(951)](e.cehWJ,f(1595)))super(),this[f(1328)]=null,Jr&&wx["connectS"+f(1441)]&&(this._socket=wx["connectS"+f(1441)]({url:n,protocols:s,header:l,fail:this[f(1947)+"ocketFai"+f(938)][f(959)](this),success:this[f(1947)+f(1323)+f(1321)+f(1118)][f(959)](this)})),Dn&&tt.connectSocket&&(this[f(1328)]=tt[f(781)+f(1441)]({url:n,protocols:s,header:l,fail:this["_createS"+f(2e3)+f(938)][f(959)](this),success:this[f(1947)+"ocketSuccessHand"+f(1118)][f(959)](this)}));else return _0x265fda[f(1197)](_0x24c833),!1}[t(1947)+t(1323)+t(1321)+t(1118)](){let n=t;Promise[n(1413)]()[n(1327)](()=>{this[n(1623)+"steners"]()})}["_createSocketFai"+t(938)](n){let s=t;Promise[s(1413)]().then(()=>{let l=s,f=e[l(1046)](ot,e[l(1819)],{message:this[l(1785)+l(1131)+"age"](n)});this[l(1733)](e[l(1819)],f);let h=e[l(634)](ft,e[l(1410)],{reason:this[l(1785)+l(1131)+l(1715)](n)});this[l(1733)](l(2008),h)})}[t(1623)+t(756)](){let n=t,s={Vllyg:e.Zypff,kZRbc:n(1980),Qlpzu:function(l,f,h){return e[n(865)](l,f,h)},OuhoF:e[n(1385)],nQgEN:e[n(1819)]};this[n(1328)][n(731)](l=>{let f=n;if(s.Vllyg==="GrVpn")return this[f(1639)]?.[f(1278)](_0x183891);this[f(1733)](s[f(670)],s.Qlpzu(Xd,f(1980),{...l,data:l[f(1869)]||""}))}),this[n(1328)][n(842)](l=>{let f=n;this.emit(e[f(1410)],e[f(1265)](ft,f(2008),{...l}))}),this[n(1328)][n(1187)+"e"](l=>{let f=n;this[f(1733)](s[f(752)],s.Qlpzu(Zd,s[f(752)],{...l}))}),this._socket[n(1564)](l=>{let f=n;this[f(1733)](f(1430),ot(s[f(1761)],{...l,message:l.errMsg||""}))})}send(n){let s=t,l={qkSok:e[s(1819)]};if(e.loDdH(e[s(1296)],e[s(1807)])){let f=_0x275443[s(1695)],h=_0x44ba60[s(1232)],b=_0x440591[s(500)],E=h+_0x1b5225;if(e[s(1376)](E,f[s(1053)])){let g=new _0x3d94b0(e[s(817)](2,E));g[s(1434)](f),_0x2f0435.bytes=g}return _0x52de82[s(1232)]=E,e[s(656)](E,b)&&(_0xf5a384[s(500)]=E),h}else if(n instanceof Uint8Array){let f=n[s(1550)][s(950)](n[s(702)+"et"],e[s(1815)](n[s(878)+"th"],n[s(702)+"et"]));this[s(1328)]&&this[s(1328)][s(2017)]({data:f,fail:h=>{let b=s;this.emit(b(1430),ot(l.qkSok,{message:this[b(1785)+b(1131)+b(1715)](h)}))}})}else this[s(1328)]&&this[s(1328)][s(2017)]({data:n,fail:f=>{let h=s,b={QZBhf:"open"};e.KYDZu(e[h(1370)],e[h(1370)])?(this.emit(b[h(1291)],_0x40bd3b),this[h(1325)]&&this[h(1325)](_0x5183f6)):this[h(1733)](e[h(1819)],e.BZwAJ(ot,e[h(1819)],{message:this["_formatE"+h(1131)+h(1715)](f)}))}})}close(n,s){let l=t;if(e.fMXYn(e[l(753)],e.ENgbI))this[l(1328)]&&this._socket[l(2008)]({code:n,reason:s});else throw this[l(527)+"Lock"]=!1,_0x26fb58}addEventListener(n,s){this.on(n,s)}[t(686)+t(1522)+t(768)](n,s){this[t(1408)](n,s)}get readyState(){let n=t;if(e[n(596)](e[n(956)],e[n(1428)])){let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(_0x755e3),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(_0x2ecfa5);return s?e[n(1975)](_0x518a2d,_0x55145b):l?e[n(1762)](_0x3d1381,_0x517da6):n(1963)+"0000000000000000"+n(1963)}else return this._socket[n(1717)+"te"]}get[t(1843)+"pe"](){let n=t;return this[n(1328)][n(1843)+"pe"]}set[t(1843)+"pe"](n){}get[t(1991)](){let n=t;return this[n(1328)][n(1991)]}get[t(864)](){let n=t;return e[n(1624)]!==e[n(1624)]?new _0x2be050(_0x2891e4,{data:_0x2edecc}):this[n(1328)][n(864)]}get extensions(){let n=t;return this[n(1328)][n(1978)+"ns"]}get[t(802)+t(1859)](){return 0}}function hp(a,n){let s=t;if(n)return new n(a[s(1991)],a.protocol);if(e.qDIGU(Jr,Dn))return new xp(a[s(1991)],a[s(864)],a[s(2019)]);if((er||Yr)&&e.AoNdG("undefined",typeof WebSocket)&&WebSocket)return new WebSocket(a[s(1991)],a[s(864)+"s"])}function pp(a){let n=t;return!!(a||Jr&&wx[n(781)+n(1441)]||Dn&&tt[n(781)+n(1441)]||(er||Yr)&&e[n(1194)](n(1142)+"d",typeof WebSocket)&&WebSocket)}function el(a,n,s){let l=t;if(e[l(448)]("KlwVZ",e[l(502)])){if(e[l(1628)](e[l(654)],typeof _0x5a7852)){let f=new _0x1479cb(_0x109b60(_0x5daf2c));return e[l(1250)](_0x48a3de,_0x48aaea,f,0),f}return e.XXgWr(_0x57c51d,_0x44de58)?new _0x1c53a2(_0x2d5775):new _0x3b29a8(_0x118d6b[l(1550)],_0x2e7b63[l(702)+"et"],_0x14dcb8[l(878)+"th"])}else{let f=-1;async function h(b){let E=l;return e[E(1919)](b,f)?Promise[E(871)](new Error(e[E(1929)])):(f=b,b===s[E(1053)]?Promise.resolve():s[b][E(959)](a)(n,h[E(959)](null,e.QaToa(b,1))))}e.fDfyX(h,0)}}function tl(a){let n=t,s=0,l=0;for(let f=0;e[n(1212)](f,a[n(1053)]);++f)l=a[n(1661)+"At"](f),e[n(528)](l,128)?s+=1:e[n(703)](l,2048)?s+=2:e[n(1477)](e[n(776)](64512,l),55296)&&e.YmPqZ(64512&a[n(1661)+"At"](e[n(1815)](f,1)),56320)?(++f,s+=4):s+=3;return s}function nl(a,n,s){let l=t;if(e[l(1212)](s-n,1))return"";let f="";for(let h=n;h<s;){let b=a[h++];if(e[l(383)](b,127))f+=String[l(1692)+l(964)](b);else if(e[l(1972)](b,192)&&b<224)f+=String[l(1692)+l(964)](e.JoPIY(e[l(1360)](e[l(635)](31,b),6),63&a[h++]));else if(b>=224&&e.Fydtg(b,240))f+=String[l(1692)+"Code"](e[l(422)](e[l(1812)](15&b,12)|(63&a[h++])<<6,e.Zdgny(63,a[h++])));else if(e[l(1972)](b,240)){let E=e[l(1045)](e[l(813)](e[l(538)](e[l(1241)](e[l(642)](7,b),18),e.BRbLd(63,a[h++])<<12)|e[l(512)](e[l(1790)](63,a[h++]),6),e[l(849)](63,a[h++])),65536);f+=String[l(1692)+l(964)](e[l(1744)](55296,e[l(1184)](E,10))),f+=String[l(1692)+"Code"](e[l(1982)](56320,1023&E))}}return f}function da(a,n,s){let l=t,f=s,h,b;for(let E=0;e[l(929)](E,a[l(1053)]);++E)if(h=a.charCodeAt(E),e[l(1442)](h,128))n[s++]=h;else if(e[l(895)](h,2048))n[s++]=e[l(1604)](h>>6,192),n[s++]=e[l(1371)](63&h,128);else if(e[l(568)](e[l(438)](64512,h),55296)&&e[l(911)](e[l(1674)](64512,b=a[l(1661)+"At"](e[l(595)](E,1))),56320)){let g=(l(1573)+l(1950))[l(1336)]("|"),I=0;for(;;){switch(g[I++]){case"0":n[s++]=e[l(1056)](e.hKeOk(h,18),240);continue;case"1":++E;continue;case"2":h=65536+((1023&h)<<10)+e[l(1436)](1023,b);continue;case"3":n[s++]=e[l(1332)](e.LzFXM(h,6),63)|128;continue;case"4":n[s++]=e.oBnEV(63,h)|128;continue;case"5":n[s++]=e[l(936)](h>>12,63)|128;continue}break}}else n[s++]=e[l(813)](e.dKZQV(h,12),224),n[s++]=e[l(1041)](e[l(466)](h>>6,63),128),n[s++]=e[l(1435)](e[l(1502)](63,h),128);return e[l(1915)](s,f)}async function rl(a){let n=t;if(e[n(1946)](n(1240),typeof a))if(n(644)!==n(644))_0x5bb930-=65536,_0x484a30+=e[n(1416)](_0x268893,e[n(1363)](e[n(1602)](_0x290a43,10),55296),e.Suejw(e.fQcBC(1023,_0x2694bc),56320)),_0x397fb4+=3;else{let s=new Uint8Array(e[n(1954)](tl,a));return e[n(578)](da,a,s,0),s}return e[n(560)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1550)],a.byteOffset,a[n(878)+"th"])}function gp(a){let n=t,s={XlvNa:e.BChat,gSceZ:n(2029),lZljM:n(1179),VdwvG:function(l,f){return e[n(1275)](l,f)},QoPSb:function(l,f){return e[n(598)](l,f)},zZodu:function(l,f){return l-f}};if(e[n(820)](e[n(1422)],e[n(543)]))this._isBrowser&&_0x51c120[n(1051)+"Listener"](n(2010),this[n(1983)+n(496)]),this._isBrowser&&_0x250c6d[n(1051)+"Listener"](s.XlvNa,this["_handleO"+n(1580)]),this._isBrowser&&_0x1af620[n(1051)+n(1301)](s.gSceZ,this[n(1593)+n(678)]),this._isBrowser&&_0xf65fa2[n(1051)+n(1301)](s.lZljM,this[n(1593)+n(1463)]);else try{return e[n(1194)](e[n(654)],typeof a)&&(e[n(1242)](a,ArrayBuffer)||a[n(1550)]&&e[n(1810)](a[n(1550)],ArrayBuffer))||e.Fmabo(e.DDcSc,typeof a)?"":(JSON[n(577)](a),e[n(1351)])}catch{if(e[n(584)](e.uDELw,e[n(730)]))return e[n(654)]==typeof a?e[n(1941)]:"";{let l=_0x3244ba[n(1336)](":");for(let f=0;xoPBKk.VdwvG(f,l.length);f++){let h=l[f];if(xoPBKk.QoPSb(4,l[f][n(1053)])){let b=_0x435f83[n(1751)+"g"](0,xoPBKk.zZodu(4,l[f][n(1053)])),E=b[n(893)](h);_0x16dd23=_0x4819f2.concat(E)}else _0x51f91e=_0x4ed2d3[n(893)](h)}return _0x4559e8}}}let mp=(a,n)=>{let s=t;switch(a){case e[s(441)]:case e[s(1955)]:return{["x-use-"+a]:1,"x-tt-env":n};default:return{}}};class wp{constructor(n){let s=t;this[s(1073)+s(665)]=n,this.count=0}[t(437)](){let n=t;this[n(1044)]++}[t(1245)+t(814)+"nt"](){let n=t;return e[n(1972)](this[n(1044)],this[n(1073)+n(665)])}[t(416)+"nter"](n=0){let s=t,l={qMljg:function(f,h,b,E){return f(h,b,E)},wvxou:"need_ack",SImKO:function(f,h){return e[G(1484)](f,h)},CNeWA:e[s(1902)],RBNDi:e[s(1579)],NZmmA:function(f,h){return e[s(2040)](f,h)},WRpTq:s(1687),EeBzh:function(f){return e[s(1660)](f)}};if(e[s(947)](s(898),s(1987)))this["maxLossC"+s(665)]=n,this[s(1044)]=0;else{let{enableAutoAck:f}=this[s(738)],h=l[s(1315)](_0x1b30fc,_0x3e0814[s(2027)][s(2019)],l[s(1675)],"1"),b=_0x3f78a1(_0xc68237[s(2027)][s(2019)],s(2022),"1"),E=_0x4c4410[s(923)](this,_0xd63ef6);if(l[s(1125)](f,h)){let{SeqID:g,LogID:I,service:M,LogIDNew:z,method:j}=_0x1d4a6c.message;this[s(724)]({SeqID:g,LogID:I,LogIDNew:z,service:M,method:j,headers:[{key:l[s(387)],value:"1"},{key:l[s(1783)],value:l.NZmmA(z,"")},{key:l[s(1223)],value:"0"}]})}b&&!E[s(717)]&&this["_dispatc"+s(1109)+s(1821)](_0x571637),l[s(626)](_0x5ce98a)}}}async function _p(a){let n=t,s={EUfxl:function(l,f){return e[G(1565)](l,f)},YdAWT:n(1104)+n(492)};return new Promise(l=>{let f=n;if(!er)return l(f(1104)+f(492));try{let h=document[f(998)+f(1472)](e[f(1634)]);window[f(836)+"JSONP"]=b=>{let E=f;document[E(987)][E(684)+"ild"](h),window.frontierJSONP=void 0,s.EUfxl(l,b&&b[E(446)]||s.YdAWT)},h.type=e[f(925)],h[f(1779)]=e.PTVRc(a[f(1794)](/^ws/,e[f(986)]),e[f(1459)]);try{document[f(987)][f(1386)+f(1284)](h)}catch{document[f(987)][f(684)+f(1284)](h)}}catch{window["frontier"+f(587)]=void 0,e[f(1954)](l,e.EEcaX)}})}function nn(a,n,s){let l=t;return!!a?.find(f=>f[l(1625)]===n&&f.value===s)}function tr(a,n){let s=t;return a?.[s(386)](l=>l[s(1625)]===n)?.value}let la=null;async function yp(){let a=t;return la||(la=Promise[a(1413)]()[a(1327)](Mt.bind(Mt,e[a(983)]))),la}class bp extends ca{constructor(n,s){let l=t;super(),this[l(1010)]=n,this._keyPath=s,this[l(1639)]=void 0,this[l(1491)+"mise"]=null}async[t(937)](){await this._init()}async[t(403)](){let n=t,s={KLQXL:function(l,f){return e.wztcG(l,f)},kMIsC:e.NxHmY,ECdQp:e[n(479)],OwqOL:function(l,f,h,b){return e[n(2018)](l,f,h,b)}};if(!this[n(1639)]){if(this[n(1491)+n(1883)])return this[n(1491)+n(1883)];try{let l=this[n(1010)],f=this._keyPath;this["_initPro"+n(1883)]=(async()=>{let h=n;if(s[h(1220)](s[h(681)],s[h(1818)])){let{openDB:b}=await yp();this[h(1639)]=await s[h(1646)](b,h(836)+"_"+l,1,{upgrade(E){E[h(1740)+"jectStore"](l,{keyPath:f})}})}else{let b=this[h(1639)][h(1558)+h(484)](this[h(475)]),E=_0x4f3275[h(577)](b||"{}");return E[_0xc0c5a9||_0x5be86a[this[h(507)]]]=_0x3a43bb,this[h(1639)][h(821)+h(484)](this._prefix,_0x58e1db.stringify(E)),_0x5a7545||_0x13994a[this[h(507)]]}})(),await this[n(1491)+"mise"]}catch(l){console.log(l)}finally{this[n(1491)+n(1883)]=null}}}async[t(1278)](n){let s=t;try{return e[s(1571)](e[s(877)],e[s(1647)])?(await this[s(403)](),this[s(1639)]?.[s(1278)](this._dbName,n)):_0x396ad6["fromChar"+s(964)](e.LTzYX(255,this[s(999)]),e[s(896)](e[s(1816)](this[s(999)],8),255),e.wbxgA(e[s(616)](this.low,16),255),e.hdMGq(this[s(999)],24),e.ZTHTG(255,this[s(1322)]),e[s(1870)](this.high,8)&255,e[s(428)](e[s(1888)](this[s(1322)],16),255),this.high>>>24)}catch(l){console.log(l)}}async[t(1434)](n,s){let l=t;return await this[l(403)](),this[l(1639)]?.[l(1700)](this[l(1010)],n)}async del(n){let s=t;try{return await this[s(403)](),this[s(1639)]?.delete(this._dbName,n)}catch(l){console[s(1197)](l)}}async clear(){let n=t;try{return await this[n(403)](),this[n(1639)]?.clear(this[n(1010)])}catch(s){console[n(1197)](s)}}async keys(){let n=t;if(e[n(824)]!==e[n(824)])this["currentI"+n(1729)]=0,this[n(1921)+n(456)+n(501)+"t"]=0;else return await this[n(403)](),this[n(1639)]?.[n(425)+"ys"](this[n(1010)])}async[t(1691)](){let n=t;return await this[n(403)](),this[n(1639)]?.[n(1691)](this[n(1010)])}async[t(551)](){let n=t;if(e[n(545)](n(1658),e[n(1736)]))return this[n(1277)+n(1729)]==this.endpoints[n(1053)]?!0:this[n(1921)+n(456)+n(501)+"t"]>this[n(1862)+"es"];try{this[n(1639)]?.[n(2008)](),this[n(1639)]=void 0}catch(s){console.log(s)}}get[t(757)](){let n=t,s={ceJDu:function(l,f,h){return e[G(385)](l,f,h)}};if(e.iwNZK(e.BgQZA,n(1196)))try{return!!this[n(1639)]}catch(l){return console[n(1197)](l),!1}else{let l=this[n(1117)+n(978)]?.[n(1359)+n(989)+"nt"]();this[n(607)+n(1157)+"ent"](s[n(1857)](_0x3902a2,n(2008),{code:_0x4a32ff[n(1600)],reason:n(1771)+n(1365)+"d, unkno"+n(646)+n(1140)+"ame: "+l})),this["_endpoin"+n(978)]?.[n(1381)+"pointConfig"](),this[n(2037)+n(561)]?.resetCounter();return}}}class Ep{constructor(n,s){let l=t;e[l(790)](e[l(579)],e.HkBIz)?(this[l(404)]=n,this[l(507)]=s,this._qosDB=localStorage):(this[l(655)+l(1871)+"Id"]=null,this[l(655)+"l"]=36e5,this._qosDB=e[l(382)](_0x3edc62,l(1797),"message_id"))}async[t(937)](){}get[t(475)](){return"frontier_"+this._DBName}async[t(1278)](n){let s=t,l=this[s(1639)][s(2035)](this[s(475)]);return JSON[s(577)](e.dMixy(l,"{}"))[n]}async set(n,s){let l=t,f=this[l(1639)][l(2035)](this[l(475)]),h=JSON[l(577)](e[l(1141)](f,"{}"));return h[s||n[this[l(507)]]]=n,this[l(1639)][l(426)](this._prefix,JSON[l(1060)+"y"](h)),s||n[this[l(507)]]}async[t(391)](n){let s=t,l=this[s(1639)][s(2035)](this[s(475)]),f=JSON.parse(e[s(2040)](l,"{}"));return f[n]=void 0,this[s(1639)][s(426)](this._prefix,JSON[s(1060)+"y"](f))}async[t(977)](){let n=t;return this._qosDB[n(977)]()}async[t(1943)](){let n=t;if(e.gElyx(e[n(1781)],n(1721))){let s=this[n(1639)].getItem(this[n(475)]),l=JSON.parse(e.uSFvy(s,"{}"));return Object[n(1943)](l)}else return this[n(1852)]?this._ws.readyState:this[n(738)][n(1959)+n(1607)]?this[n(1707)+"NG"]:this[n(430)]}async[t(1691)](){let n=t,s=this[n(1639)][n(2035)](this[n(475)]),l=JSON[n(577)](e[n(1276)](s,"{}"));return Object[n(1778)](l)}[t(551)](){return Promise[t(1413)]()}get[t(757)](){return!!this[t(1639)]}}class vp{constructor(n,s){let l=t;this[l(404)]=n,this[l(507)]=s,this[l(1639)]=Dn?tt:Jr?wx:null}async openDB(){}get[t(475)](){return t(836)+"_"+this._DBName}async[t(1278)](n){let s=t;if(e[s(1314)](e.wqlrI,"YatSA"))_0x4c99b5(_0x568082[s(1430)]),lJxThV[s(1145)](_0x20812a);else{let l=this._qosDB[s(1558)+s(484)](this[s(475)]);return JSON[s(577)](e.JfEpk(l,"{}"))[n]}}async[t(1434)](n,s){let l=t,f=this[l(1639)][l(1558)+l(484)](this[l(475)]),h=JSON[l(577)](e[l(2034)](f,"{}"));return h[s||n[this._pathKey]]=n,this._qosDB[l(821)+l(484)](this[l(475)],JSON[l(1060)+"y"](h)),s||n[this[l(507)]]}async[t(391)](n){let s=t,l=this[s(1639)][s(1558)+s(484)](this[s(475)]),f=JSON[s(577)](l||"{}");return f[n]=void 0,this[s(1639)][s(821)+"geSync"](this._prefix,JSON[s(1060)+"y"](f))}async[t(977)](){let n=t;return this._qosDB[n(1737)+n(1708)]()}async[t(1943)](){let n=t,s=this[n(1639)].getStorageInfoSync(this[n(475)]),l=JSON[n(577)](e.JfEpk(s,"{}"));return Object[n(1943)](l)}async getAll(){let n=t,s=this[n(1639)][n(1558)+n(1320)+"nc"](this[n(475)]),l=JSON[n(577)](s||"{}");return Object.values(l)}[t(551)](){return Promise[t(1413)]()}get[t(757)](){let n=t,s={xvkdA:function(l,f,h){return e[G(1268)](l,f,h)}};return e[n(2032)](e[n(673)],e[n(915)])?_0x3e22ee[n(1695)][UeoMoN[n(780)](_0x4a6d3b,_0x50ce68,1)]:!!this[n(1639)]}}function il(a,n){let s=t,l={LeSuE:s(2008)};if(e[s(1401)](e[s(1040)],e.bAtWD)){if(e[s(2034)](Dn,Dn))return new vp(a,n);if(e[s(1907)](er,Yr)&&e[s(1854)](e[s(1409)],typeof indexedDB))return new bp(a,n);if(e.jLLnu(er,Yr)&&e[s(979)](e[s(1409)],typeof localStorage))return new Ep(a,n);throw new Error(e[s(1865)])}else this.emit(l.LeSuE,_0x5f06e5),this.onclose&&this[s(1994)](_0xaee10c)}class Sp{constructor(){let n=t;this[n(655)+"lTimeoutId"]=null,this[n(655)+"l"]=36e5,this[n(1639)]=e[n(1340)](il,e.JrIRa,e[n(1066)])}async[t(655)+t(1908)](){let n=t;e.AACBD(clearInterval,this[n(655)+"lTimeoutId"]),this[n(655)+n(1871)+"Id"]=e[n(1572)](setInterval,()=>{let s=n;this[s(640)+s(1025)]()},this[n(655)+"l"])}async[t(937)](){let n=t;await this[n(1639)][n(937)]()[n(1327)](()=>{let s=n;this[s(655)+s(1908)]()})}async["flushExp"+t(1025)](){let n=t,s={PmNcu:function(l,f){return e[G(631)](l,f)},APPXa:e[n(1409)]};e[n(1912)]!=="oYwFM"?(XCEzQy[n(590)](XCEzQy[n(1299)],typeof _0x3d1994)&&_0x536696[n(1896)+n(1440)]&&_0x10482c[n(408)+n(1395)](_0x1462c8,_0x2f6f24[n(1896)+n(1440)],{value:n(650)}),_0x3fa5fb.defineProperty(_0x56fd8e,n(1725)+"le",{value:!0})):(await this[n(1639)]?.[n(1691)]()||[])[n(1714)](({timestamp:h})=>h<Date[n(398)]())[n(1201)](h=>{let b=n;this[b(1639)]?.[b(391)](h.message_id)})}async[t(391)](n){return this[t(1639)]?.del(n)}async[t(1434)](n,s){let l=t;return this._qosDB?.[l(1434)]({message_id:n,timestamp:s})}async[t(1278)](n){return this[t(1639)]?.get(n)}async[t(551)](){let n=t;if(e.XBZRG(e[n(1671)],e[n(853)])){let s=this[n(1117)+n(978)]?.[n(1359)+n(989)+"nt"]();this[n(882)]("connect "+s+n(1756)),this[n(706)+n(1587)](1001,"timeout,"+n(1793)+"onnecting",!0)}else e[n(948)](clearInterval,this[n(655)+n(1871)+"Id"]),await this[n(1639)]?.[n(551)]()}get[t(757)](){let n=t;return this[n(1639)]?.[n(757)]}}function ua(a){let n=t,s=!!this[n(738)][n(1037)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[n(633)](nn,a.message[n(2019)],e[n(788)],"2"),f=l&&nn(a[n(2027)][n(2019)],e[n(746)],"1"),h=l&&e[n(834)](nn,a[n(2027)].headers,e[n(1476)],"1"),b=h?e[n(916)](tr,a[n(2027)].headers,e[n(639)])?.[n(1336)](",")[n(1714)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:h,ackMsgIds:b}}async function sl(){let a=t;return e.jgyVc!==a(1533)?this[a(2014)+"T"]||this._isMiniWX?this[a(1895)+a(1407)+a(1653)]:(this._isBrowser||this[a(439)+"r"])&&this._options["listenNe"+a(523)+a(838)]?_0x4e86e2.onLine:!0:(this[a(1770)+a(1098)]||(this["_QoSMana"+a(1098)]=new Sp),this[a(1770)+a(1098)][a(757)]||await this[a(1770)+a(1098)][a(937)](),this[a(1770)+a(1098)])}async function Ap(a,n){let s=t,{enableAutoAck:l}=this._options,f=nn(a.message[s(2019)],e[s(869)],"1"),h=nn(a.message[s(2019)],e[s(1902)],"1"),b=ua[s(923)](this,a);if(e[s(1575)](l,f)){if(e[s(467)](e[s(1016)],e[s(1986)]))return this._qosDB[s(757)];{let{SeqID:E,LogID:g,service:I,LogIDNew:M,method:z}=a[s(2027)];this[s(724)]({SeqID:E,LogID:g,LogIDNew:M,service:I,method:z,headers:[{key:e[s(1902)],value:"1"},{key:e[s(1579)],value:e[s(1907)](M,"")},{key:"ack_code",value:"0"}]})}}h&&!b[s(717)]&&this[s(607)+"hAckMess"+s(1821)](a),e[s(1997)](n)}async function Ip(a,n){let s=t;this[s(882)](e[s(1953)],a[s(2027)]),n()}async function Tp(a,n){let s=t,l=e[s(1762)](Qt,await e[s(1732)](rl,a[s(1273)]));try{if(e[s(1638)](l[s(787)],Uint8Array)){let f=this[s(738)][s(1183)+s(807)]instanceof Object?{force:!!this[s(738)][s(1183)+s(807)][s(662)],encoding:this._options[s(1183)+s(807)][s(1855)]?this[s(738)][s(1183)+s(807)][s(1855)][s(1794)](/\s/g,"")["toLowerC"+s(1767)]():""}:{force:!1,encoding:this._options[s(1183)+s(807)]?this[s(738)][s(1183)+s(807)][s(1794)](/\s/g,"")["toLowerC"+s(1767)]():""},h=l[s(1183)+s(807)]?l[s(1183)+s(807)][s(1794)](/\s/g,"")[s(1330)+"ase"]():"",b=e[s(1007)](this[s(738)][s(1552)+s(855)],Object)?{force:!!this[s(738)][s(1552)+"ype"][s(662)],type:this[s(738)][s(1552)+s(855)][s(927)]?this._options[s(1552)+s(855)][s(927)][s(1794)](/\s/g,"")[s(1330)+"ase"]():""}:{force:!1,type:this[s(738)][s(1552)+s(855)]?this[s(738)][s(1552)+s(855)][s(1794)](/\s/g,"")[s(1330)+s(1767)]():""},E=l["payloadT"+s(855)]?l["payloadT"+s(855)][s(1794)](/\s/g,"")[s(1330)+s(1767)]():"",g=b[s(662)]?b[s(927)]:E||b.type,I=f.force?f[s(1855)]:h||f.encoding,M=[e.gMyHj,e.BzBee,e.uqbsU,s(1240)],z=[e.pMZnA,e.BAbOP];this[s(738)][s(1478)+"ansformTextPayload"]&&M.includes(g)&&(!I||z[s(648)](I))?l[s(1107)+s(1286)]=e.KfDUk(nl,l.payload,0,l[s(787)][s(878)+"th"]):l["textPayl"+s(1286)]=""}else l[s(1107)+"oad"]=""}catch(f){l[s(1107)+s(1286)]="",console[s(1197)](f)}a[s(2027)]=l,e.qCRZL(n)}function Cp(a,n,s){let l={PJUsb:function(g,I){return e[G(1275)](g,I)},mztih:function(g,I){return e.upqGK(g,I)},NXETi:function(g,I){return e[G(786)](g,I)},ClJrf:function(g,I){return e[G(1898)](g,I)},QgHyy:function(g,I){return e[G(524)](g,I)},GbCuk:function(g,I){return e[G(1711)](g,I)},crHCQ:function(g,I){return e[G(1071)](g,I)},ZFtnC:function(g,I){return e[G(934)](g,I)}},f=e.qDIGU(s,8192),h=f>>>1,b=null,E=f;return function(g){let I=G;if(l[I(661)](g,1)||l[I(1474)](g,h))return l[I(1337)](a,g);l[I(1474)](l[I(1948)](E,g),f)&&(b=l[I(1100)](a,f),E=0);let M=n[I(923)](b,E,E+=g);return l[I(879)](7,E)&&(E=l[I(1554)](l[I(2030)](7,E),1)),M}}let Dp=4294967295;function Rp(a,n,s){let l=t;return e[l(839)](RangeError,e.bTtAn(e[l(1731)](e.DrwiT(e[l(1426)](l(965)+l(1382)+l(1827),a),l(794))+e[l(676)](n,1),e[l(1809)]),s))}function kp(a,n,s){let l=t;if(e.QoGmo(s,Dp))throw new Error(l(558)+l(2005)+"e");let f=3;for(;e[l(1178)](f,0);){let h=255&s;e[l(782)](xa,h,a,e[l(1266)](n,f)),s>>>=8,f--}return e[l(1363)](n,4)}function Pp(a,n){let s=t,l=0,f=n,h=n+4;for(;e[s(1741)](f,h);){let{value:b,offset:E}=e[s(1464)](fa,a,f);f=E,l=e[s(442)](l,8)>>>0,l+=b}return{value:l,offset:h}}function Op(a,n,s){let l=t;if(e[l(852)]!==e.XPRuJ)this[l(738)].debug&&_0x52bd29[l(1197)][l(567)](_0x3a4c5b,[e[l(2015)],..._0x21244b]);else return a?e.PfztO(a.length,40)?e[l(1155)](e.KCvXX(da,a,n,s),s):n[l(1058)+"e"]?e[l(595)](n[l(1058)+"e"](a,s),s):n.write?n[l(1678)](a,s)+s:e.Suejw(da(a,n,s),s):s}function Lp(a,n){let s=t,l=new fe(e.ATMwc(e[s(766)](e[s(952)](a[e[s(939)](n,4)],24),a[e[s(1576)](n,5)]<<16),e[s(1850)](a[e[s(1777)](n,6)],8))|a[e.fyqmQ(n,7)],e[s(907)](e[s(555)](e[s(2036)](e.bIGiT(a[e[s(1874)](n,0)],24),a[e[s(968)](n,1)]<<16),e[s(1970)](a[e[s(1777)](n,2)],8)),a[e[s(1266)](n,3)]),!0);return n+=8,{value:l,offset:n+8}}function Np(a,n,s){let l=t,f=a[l(999)],h=a.high;return n[s]=e[l(984)](h,24),n[s+1]=e.pCugr(e.AFQYB(h,16),255),n[e[l(429)](s,2)]=e.Thvkk(e[l(729)](h,8),255),n[s+3]=e[l(400)](255,h),n[e[l(1898)](s,4)]=e.bRWaH(f,24),n[s+5]=e[l(1089)](e[l(668)](f,16),255),n[e[l(1263)](s,6)]=e[l(434)](e.PKPSS(f,8),255),n[e[l(691)](s,7)]=e[l(1509)](255,f),s+=8,s}function fa(a,n){let s=t;return a[s(1402)+"8"]?{value:a[s(1402)+"8"](n),offset:e.zxifn(n,1)}:{value:e[s(884)](255,a[n]),offset:n+1}}function xa(a,n,s){let l=t;return n[l(1743)+"t8"]?n[l(1743)+"t8"](a,s):n[s]=e[l(494)](255,a),e[l(968)](s,1)}let Mp=function(a){let n=t;return e[n(1936)](e[n(1388)],e[n(1899)])?e.DDcSc==typeof _0x57ec6d?n(1437)+n(638)+"et=utf-8":"":new Uint8Array(a)},Bp=e[t(1080)](e[t(1409)],typeof Buffer)?Buffer["allocUns"+t(854)]:e[t(634)](Cp,Mp,Uint8Array.prototype.subarray),zp=16,ha=32;function Fp(a){let n=t,s=0,l={};for(let f=0;e[n(1319)](f,a[n(1053)]);f++)l[a[f][n(1316)+n(991)]]=e[n(945)](tl,a[f][n(1316)+"ame"]),s+=e[n(1576)](14,l[a[f].cursor_name]);return[s,l]}function ol(a,n,s){let l=t,[f,h]=e[l(574)](Fp,a),b=Bp(f),E=0;return a[l(1201)](g=>{let I=l;console[I(1197)](e[I(1598)],g,g.service),E=e.sSrEe(xa,0,b,E),console.log(I(687),E),E=e[I(1250)](kp,b,E,g[I(1988)]||0),console[I(1197)](I(1988),E),E=e[I(1329)](xa,h[g[I(1316)+I(991)]],b,E),console[I(1197)](I(1189)+"name",E),E=Op(g[I(1316)+"ame"],b,E),console[I(1197)](e[I(2001)],E),E=e.KSXCw(Np,fe[I(1543)+"er"](g.cursor||n),b,E),console[I(1197)](e.EHPtc,E)}),{frameType:ha,headers:[{key:e.yEzzW,value:s}],payload:b}}function Up(a){let n=t,s=0,l=[];for(;e.kSMrh(s,a[n(878)+"th"]);){let{offset:f}=fa(a,s);s=f;let h={cursor_name:"",cursor:0,service:0},{value:b,offset:E}=e[n(1768)](Pp,a,s);h[n(1988)]=b,s=E;let{value:g,offset:I}=e[n(1433)](fa,a,s);s=I,h["cursor_n"+n(991)]=e.RMnrm(nl,a,s,e[n(1612)](s,g)),s+=g;let{value:M,offset:z}=e[n(1057)](Lp,a,s);h[n(493)]=M[n(735)](),s=z,l[n(1582)](h)}return l}function Gp(){let a=t;return{frameType:ha,headers:[{key:e.yEzzW,value:a(604)+"_EXIST"}],payload:void 0}}class Hp{constructor(n,s,l){let f=t;if(e[f(1710)](e[f(1475)],e[f(1475)])){let h=new _0x1e9e98(2*_0x1db3dc);h[f(1434)](_0x129277),_0x11aeb2[f(1695)]=h}else this["_cursorN"+f(1529)]=n,this[f(537)+f(1520)]=s,this["_message"+f(690)]=l,this[f(1639)]=e[f(1281)](il,this[f(652)+f(1529)],f(1316)+f(991))}async openDB(){let n=t;await this[n(1639)][n(937)]()}async[t(1694)+"rs"](){let n=t;if(!this[n(1639)][n(757)])return;let s=this[n(1005)+n(690)],l=await this[n(1639)][n(1691)]();switch(console[n(1197)](e.SmQJa,l),s){case e.jldDA:return l&&l[n(1053)]?ol(l,0,this[n(537)+n(1520)]):void 0;case e[n(630)]:return;case e[n(1427)]:return l&&l[n(1053)]?ol(l,0,this[n(537)+n(1520)]):e.xwnau(Gp)}}async[t(1434)](n,s,l){let f=t;return console[f(1197)]("setdb",n,s,l),this._qosDB[f(1434)]({cursor_name:n,cursor:s,service:l})}async[t(832)+"rs"](n){let s=t,l=Up(n);for(let f of l)e[s(1763)](e[s(1191)],e.RanVF)?(console[s(1197)](e.mLvre,l),await this[s(1639)][s(1434)](f)):this[s(2014)+"T"]?_0x581aaf[s(509)+s(707)+s(841)](({isConnected:h})=>{let b=s;this["_miniNav"+b(1407)+b(1653)]=h,h?this["_handleO"+b(496)]():this[b(1983)+"ffLine"]()}):this[s(769)+"X"]&&_0x547e34[s(509)+s(707)+s(841)](({isConnected:h})=>{let b=s;this["_miniNav"+b(1407)+b(1653)]=h,h?this[b(1983)+b(496)]():this[b(1983)+b(1580)]()})}async[t(1278)](n){let s=t;if(e.huxbB(e[s(1609)],e[s(1185)]))if(_0x5a6eb8=_0xfa61e8.charCodeAt(_0x2c9853),e[s(485)](_0x196a02,128))_0x5a0b43[_0x3eaafb++]=_0xe83501;else if(e.PIBTi(_0x2220b2,2048))_0x490ad3[_0x43daa5++]=e[s(1465)](e[s(2013)](_0x25367b,6),192),_0x52a906[_0x5a1bfd++]=e[s(1067)](e[s(1009)](63,_0x19cbe2),128);else if((64512&_0x1a425e)===55296&&(64512&(_0x10413a=_0x11318a[s(1661)+"At"](e[s(1361)](_0x1003bb,1))))===56320){let l=e.ALQPX[s(1336)]("|"),f=0;for(;;){switch(l[f++]){case"0":_0xab0de9[_0x1dd167++]=e.HdxTX(e[s(1338)](e.LzFXM(_0x2ba8cf,12),63),128);continue;case"1":_0x192194[_0x335305++]=e[s(762)](_0x1a8606,18)|240;continue;case"2":++_0x58581d;continue;case"3":_0x31799c=e[s(777)](e[s(1984)](65536,e[s(801)](e[s(712)](1023,_0x185817),10)),e.GpYVE(1023,_0x16969));continue;case"4":_0x53f40f[_0x2da843++]=e.ooGeY(e.BRbLd(63,_0x5df406),128);continue;case"5":_0x43f609[_0x4a4ccf++]=e.WHxuc(e[s(1548)](_0x33ce5c>>6,63),128);continue}break}}else _0xbf957b[_0x42be04++]=e[s(1914)](_0x4ccd7e>>12,224),_0x3784f3[_0x239a8c++]=e[s(1160)](e[s(1338)](e[s(1499)](_0x5a0ee8,6),63),128),_0x3f1bcc[_0x2dd6a3++]=e[s(409)](63,_0x33e666)|128;else return(await this._qosDB[s(1278)](n))?.[s(493)]}async closeDB(){await this[t(1639)].closeDB()}[t(544)+t(1136)+t(1444)](n){let s=t;this[s(537)+s(1520)]=n}get[t(757)](){let n=t;return this[n(1639)][n(757)]}}let qp=e[t(1839)];async function al(a){let n=t;if(!this[n(738)][n(1037)+"S"])return null;let{aID:s,fpID:l,messageStrategy:f}=this._options,h=e[n(1488)](a,qp);try{return this[n(1521)+n(628)]?a&&this[n(1521)+n(628)][n(544)+n(1136)+n(1444)](a):this[n(1521)+n(628)]=new Hp(l+"_"+s+"_"+h,h,f),this["_cursorM"+n(628)][n(757)]||await this[n(1521)+n(628)][n(937)](),this[n(1521)+n(628)]}catch{return null}}async function jp(a,n){let s=t,l={gCxig:function(F,W){return F(W)},omDis:function(F,W){return e[G(533)](F,W)},DQZAS:function(F,W){return F&W},bPqce:function(F,W){return e[G(1377)](F,W)},jvqjV:function(F,W){return e[G(776)](F,W)},OHJPz:function(F,W){return F&W}},f=nn(a.message[s(2019)],s(1600),"-1"),h=e[s(1250)](nn,a[s(2027)][s(2019)],e[s(1902)],"1"),b=e.WCFHI(tr,a.message.headers,e[s(1512)]),E=Number(tr(a[s(2027)][s(2019)],e[s(1406)]))||0,g=ua.call(this,a),I=e[s(944)](nn,a[s(2027)].headers,s(1134)+"s","2"),M=e[s(720)](tr,a[s(2027)][s(2019)],e[s(1297)]),z=e[s(1732)](Number,tr(a.message[s(2019)],e[s(2031)]));if(g[s(717)])return n();let j=g[s(1629)+s(1866)]?await sl.call(this):null;if(e[s(1460)](a[s(2027)][s(1988)],0)&&h&&!f||e.jygXt(a[s(2027)][s(1988)],0)){if(b&&g[s(1629)+s(1866)]&&j)return!!!await j[s(1278)](b)&&(e.yYNTx!==e[s(1298)]?(_0x9ad99c=ysgklT.gCxig(_0x4ce46f,_0x3b92d0),_0x30015c|=ysgklT[s(1355)](127&_0x28ae8d,14),ysgklT[s(454)](128,_0x7ad342)&&(_0x5a2f8e=ysgklT.gCxig(_0x382762,_0x538c0c),_0x58b1a0|=ysgklT[s(1588)](127,_0x3b167c)<<21,ysgklT[s(1588)](128,_0x31733a)&&(_0x1a1a16=ysgklT.gCxig(_0x122939,_0x5dc63b),_0x3c2e1b=ysgklT.jvqjV(127,_0x408f61),ysgklT[s(1588)](128,_0xac6513)&&(_0xeb7eab=ysgklT[s(562)](_0x5e7f32,_0x59bb87),_0x3807ee|=ysgklT.OHJPz(127,_0x4c19d2)<<7)))):(this[s(607)+s(709)+"Event"](a),await j[s(1434)](b,e[s(1735)](Date[s(398)](),E)))),e[s(1719)](n);if(I){let F=await al.call(this);if(!F)return e[s(623)](e.COyNR,e[s(540)])?(this[s(607)+s(709)+s(1483)](a),e[s(1660)](n)):0;let W=await F.get(M)??-1;if(e[s(1643)](W,z))this["_dispatc"+s(709)+s(1483)](a),F[s(1434)](M,z,a[s(2027)].service);else throw new Error(s(1222)+s(1272)+s(1911)+z+(s(1210)+"than loc"+s(1143)+"r ")+W);return e[s(539)](n)}return this[s(607)+s(709)+s(1483)](a),e.MjNrY(n)}}async function Wp(a,n){let s=t,l=ua[s(923)](this,a);if(!l[s(1629)+s(1866)])return e[s(1997)](n);let f=await sl.call(this);if(l[s(837)+"anupMess"+s(1715)]&&l.ackMsgIds[s(1053)])for(let h of l[s(1456)+"s"])await f.del(h);e[s(1719)](n)}async function Kp(a,n){let s=t,l={USHIf:function(f,h){return f>>>h},OQgKj:function(f,h){return e[G(1302)](f,h)},ParRJ:function(f,h){return e[G(1972)](f,h)},SOnQg:function(f,h,b){return f(h,b)},KYYZr:function(f,h){return e[G(1749)](f,h)}};if(s(1132)===e[s(1540)]){let f=this[s(1322)],h=this.low;return[MNYzeA[s(1651)](f,24),MNYzeA[s(851)](MNYzeA[s(1651)](f,16),255),MNYzeA[s(851)](f>>>8,255),MNYzeA[s(851)](255,f),MNYzeA.USHIf(h,24),h>>>16&255,MNYzeA.OQgKj(MNYzeA[s(1651)](h,8),255),255&h]}else{let f=e[s(447)](a[s(2027)][s(1538)+"e"],zp),h=e[s(546)](a[s(2027)][s(1538)+"e"],ha);if(e[s(1932)](!f,!h))return e.NJieL(n);let b=e[s(1486)](tr,a[s(2027)][s(2019)],e[s(641)]);if(!b)return e[s(471)](n);let E=await al[s(923)](this,b);if(!E)return e[s(539)](n);if(f)if(e[s(1936)](e[s(1894)],e[s(883)])){for(_0x27dba7>>>=0;MNYzeA[s(725)](_0x39e1b6,128);)MNYzeA[s(1909)](_0x6ff6d,_0x5b5395,MNYzeA[s(755)](127&_0x5d31c3,128)),_0x3bd411>>>=7;MNYzeA[s(1909)](_0x34532c,_0x7bd789,_0x2f3621)}else{let g=await E[s(1694)+"rs"](),I={frameType:g?.[s(1538)+"e"],SeqID:fe[s(1543)+"er"](this._seqId++),LogID:fe[s(1543)+"er"](this[s(738)][s(1910)+s(459)]()),service:9e3,method:5,headers:g?.[s(2019)],payload:g?.[s(787)]},M=e[s(1247)](S,I);this[s(1852)]&&this._ws[s(1717)+"te"]&&this[s(1852)].send(M)}if(h){let g=a[s(2027)][s(787)];g&&E.setCursors(g)}}}let $p=async function(a,n){let s=t,l={lvtir:function(f,h){return e[G(545)](f,h)},vKtQD:function(f,h){return f===h},msxKt:function(f,h){return e[G(1182)](f,h)},kiNsZ:function(f,h){return e[G(1513)](f,h)},bjIec:function(f,h){return e[G(1889)](f,h)}};if(e.HdnzW(s(932),s(932)))return _0x2cfc50[s(503)](_0x4d07a1)||(_0x2a016f=_0x2c515d[s(1543)+"er"](_0x10cb9a)),yYXdwX[s(474)](this[s(1480)],_0x1a75e5.unsigned)&&yYXdwX[s(1631)](yYXdwX[s(975)](this[s(1322)],31),1)&&yYXdwX[s(773)](yYXdwX[s(1885)](_0x37ce39.high,31),1)?!1:this[s(1322)]===_0x45e222[s(1322)]&&yYXdwX[s(1631)](this.low,_0x4a04d8[s(999)]);this._isInit=!1,clearTimeout(this[s(527)+s(1152)+s(1287)]),e.wftdJ(n)},Vp=async function(a,n){let s=t;if(!this[s(1852)]||e.gtjsB(this[s(1852)][s(1717)+"te"],this[s(825)]))return e.MjNrY(n);let{pingInterval:l}=this._options;this[s(1117)+"tManager"]?.[s(1381)+s(1619)+"fig"]();for(let h=0;e[s(505)](h,this["_message"+s(531)][s(1053)]);h++){let b=this["_message"+s(531)][h];if(e[s(744)](this[s(1852)].readyState,this.OPEN)&&b!==null)this._ws&&this[s(1852)][s(2017)](b),this[s(1005)+s(531)][h]=null;else break}this[s(1005)+s(531)]=this["_message"+s(531)][s(1714)](h=>!!h),this[s(495)+s(1893)+"Id"]=e[s(1114)](setTimeout,()=>this[s(1620)](),l),this["_dispatc"+s(1065)+"nt"](a),this[s(1867)+"er"]&&this[s(1852)]&&(this[s(1852)][s(1843)+"pe"]=this["_binaryT"+s(855)]);let f=this["_endpoin"+s(978)]?.[s(1359)+"ntEndpoint"]();this[s(882)]("open "+f+" success"),e.wftdJ(n)},Jp=async function(a,n){let s=t;if(e[s(1105)](e[s(1688)],e[s(1688)]))_0x440ff5[s(1197)](_0xe487e0);else{let l=this["_endpoin"+s(978)]?.[s(1359)+"ntEndpoint"]();this._debug(s(1144)+l),e[s(1414)](n)}};class Yp extends ca{constructor(n){let s=t,l={XlZLf:function(E,g){return e[G(698)](E,g)},htjCU:function(E,g){return e.dMixy(E,g)},yBxaD:function(E,g){return e.MxoQq(E,g)},SyUpX:function(E,g){return e[G(445)](E,g)},TQfdc:function(E,g){return e.WGOmf(E,g)},kUgMZ:function(E,g){return e.ULLhR(E,g)},CRlxG:function(E,g){return e[G(1970)](E,g)},UoNvJ:function(E,g){return E&g},rWMuU:function(E,g){return E|g},uBJvP:function(E,g){return e[G(1536)](E,g)},BBsxk:function(E,g){return e[G(1951)](E,g)},Wtlnl:function(E,g){return e[G(909)](E,g)},bhBIa:function(E,g){return e[G(1356)](E,g)},xRuNU:function(E,g){return e[G(884)](E,g)},fXSBb:function(E,g){return e.CMfvF(E,g)},dzyyA:function(E,g){return e[G(420)](E,g)},gqwUj:e.KCmkE,ShuKX:function(E,g,I){return e[G(1727)](E,g,I)},aBzUf:e[s(982)],JcNtd:function(E,g){return e[s(412)](E,g)},izjgt:e.CBRDp,cmxfR:s(1690),cTbMQ:e[s(1739)],DQupo:e[s(1093)],apVRm:e[s(1542)],LSofj:e[s(1385)]};super(),this[s(1895)+s(1407)+"line"]=!0,this[s(1867)+"er"]=er,this[s(953)]=fp,this[s(2014)+"T"]=Dn,this[s(769)+"X"]=Jr,this[s(439)+"r"]=Yr,this[s(1005)+s(531)]=[],this["_endpoin"+s(978)]=null,this[s(450)+"osed"]=!1,this[s(1728)+s(855)]=s(1757)+s(908),this[s(527)+s(1799)]=!1,this[s(527)+s(1152)+s(1287)]=null,this["_reconne"+s(397)+"tId"]=null,this[s(495)+s(1893)+"Id"]=null,this._seqId=0,this[s(1290)]=!1,this[s(679)]="",this[s(1770)+s(1098)]=null,this[s(1521)+"anager"]=null,this[s(2037)+s(561)]=null,this[s(1324)+"ls"]=e[s(1198)],this[s(430)]=3,this[s(1707)+"NG"]=0,this[s(825)]=1,this[s(529)]=2,this[s(1350)]=E=>{let g=s;try{if(e[g(1271)](e[g(1429)],e[g(1429)]))el(this,E,[$p,Vp,Jp]);else return _0x4b9141|=0,{low:_0x377f2c,high:_0x24f6d9>>31,unsigned:dtxvhK[g(943)](_0xf09e91,0)}}catch(I){let M=e[g(385)](ot,e[g(1819)],{message:I.message,code:tn.OPEN_ERROR,error:I});this[g(607)+g(745)+g(597)](M)}},this._onMessage=async E=>{let g=s,{pingInterval:I,pingFrequency:M}=this[g(738)];if((e[g(1784)]("hi",E[g(1273)])&&e[g(1211)](e[g(482)],M)||e.zgtiD(e.ZPmdo,M))&&(this[g(1458)+"ngTimer"](),this.emit(e[g(1148)],e[g(1084)]),this[g(495)+g(1893)+"Id"]=e[g(1171)](setTimeout,this._ping[g(959)](this),I)),!e.JsoYU("hi",E.data))try{if(e.VoLtF===e.CDMDa){let z=this._qosDB.getStorageSync(this[g(475)]),j=_0x479c01[g(577)](dtxvhK[g(1939)](z,"{}"));return j[_0x29a6a8]=void 0,this[g(1639)][g(821)+"geSync"](this._prefix,_0x5e40f3[g(1060)+"y"](j))}else e[g(633)](el,this,E,[Tp,Ap,Wp,Kp,jp,Ip])}catch(z){if(e[g(1209)](e[g(1304)],g(1454))){let j=ot(e.CBRDp,{message:z.message,code:tn[g(1836)+g(774)],error:z});this[g(607)+g(745)+g(597)](j)}else{if(dtxvhK[g(660)](dtxvhK[g(796)](_0xe81994,_0x4c317d),1))return"";let j="";for(let F=_0x26673a;F<_0x46fd31;){let W=_0x364422[F++];if(dtxvhK[g(1853)](W,127))j+=_0x252ecd[g(1692)+g(964)](W);else if(dtxvhK[g(943)](W,192)&&dtxvhK[g(660)](W,224))j+=_0x3f3acd.fromCharCode(dtxvhK[g(1648)](dtxvhK[g(1017)](dtxvhK[g(1956)](31,W),6),dtxvhK.UoNvJ(63,_0x52cad6[F++])));else if(dtxvhK.XlZLf(W,224)&&dtxvhK[g(660)](W,240))j+=_0x27310b[g(1692)+"Code"](dtxvhK[g(1500)](dtxvhK[g(933)](dtxvhK.BBsxk(dtxvhK[g(410)](15,W),12),dtxvhK.CRlxG(dtxvhK[g(410)](63,_0x3d52ce[F++]),6)),63&_0x1040a5[F++]));else if(dtxvhK[g(943)](W,240)){let ve=dtxvhK[g(1128)](dtxvhK[g(933)](dtxvhK[g(1648)](dtxvhK[g(933)](dtxvhK[g(1017)](dtxvhK[g(610)](7,W),18),dtxvhK.fXSBb(dtxvhK[g(410)](63,_0xf90ae0[F++]),12)),dtxvhK[g(1699)](dtxvhK[g(410)](63,_0xd4137d[F++]),6)),63&_0x13e322[F++]),65536);j+=_0x3bfeb5[g(1692)+g(964)](55296+(ve>>10)),j+=_0x170821["fromChar"+g(964)](56320+dtxvhK[g(1759)](1023,ve))}}return j}}},this[s(718)]=E=>{let g=s,I=this[g(1117)+g(978)]?.[g(1245)+g(958)+"es"](),M=this[g(1117)+g(978)]?.["getCurre"+g(989)+"nt"]();if(I&&!E[g(2027)]){let z=g(1494)+M+(g(1446)+g(1581)+g(1614)+"ed");this["_dispatc"+g(745)+g(597)](e[g(693)](ot,e.CBRDp,{message:z,code:tn.MAX_RETRIES_ERROR,error:E}));return}this[g(1852)]&&this[g(1852)].readyState===this[g(825)]&&this[g(706)+"ect"](),this["_dispatchErrorEv"+g(597)](e[g(904)](ot,e[g(1819)],{message:E[g(2027)],code:tn[g(1755)+g(1159)],error:E}))},this[s(1013)]=async E=>{let g=s;this[g(737)+g(872)](),this[g(1458)+g(1384)](),this[g(1392)+g(1813)+"rs"](),this[g(1852)]=null,this[g(527)+g(1799)]=!1;let I=this[g(1117)+g(978)]?.["checkRea"+g(958)+"es"]();if(!I&&this[g(1754)+g(875)]()&&!this[g(450)+g(1228)]){let M=this[g(1117)+g(978)]?.[g(1359)+"ntEndpoint"](),z=this[g(738)][g(868)+g(1549)+g(1833)](E[g(1600)],E[g(492)]);this[g(607)+g(1157)+"ent"](ft(l[g(611)],{code:1006,reason:E[g(492)]||g(1771)+g(1365)+"d, unknown reaso"+g(1140)+g(1091)+M,willReconnect:z})),z&&this._connect();return}if(E[g(1600)]!==1e3&&this[g(450)+g(1228)]){this[g(607)+g(1157)+g(597)](l.ShuKX(ft,l.gqwUj,{code:1e3,reason:l[g(1003)]})),this[g(1117)+"tManager"]?.[g(1381)+g(1619)+g(1851)](),this[g(2037)+"sCounter"]?.[g(416)+g(1103)]();return}if(l.JcNtd(1e3,E[g(1600)])&&I){let M=this[g(1117)+"tManager"]?.[g(1359)+g(989)+"nt"](),z=E.reason;z||(z=await _p(this._url)),z=g(1771)+g(1365)+g(389)+z+", hostname: "+M+(g(449)+g(775)+g(763)),this[g(607)+g(1157)+"ent"](ft(l[g(611)],{code:E[g(1600)],reason:z}));let j=g(1494)+M+(" fail, m"+g(1581)+g(1614)+"ed");this[g(607)+"hErrorEvent"](l[g(1876)](ot,l.izjgt,{message:j,code:tn[g(433)+g(1556)+"R"]})),this[g(1117)+g(978)]?.[g(1381)+g(1619)+g(1851)](),this[g(2037)+g(561)]?.[g(416)+g(1103)]();return}if(l[g(1501)](1e3,E[g(1600)])&&!E[g(492)])if(l[g(902)]===l[g(1834)])this[g(607)+g(709)+g(1483)](_0x44db9b),_0x1e0d1b[g(1434)](_0x336169,_0x20995e,_0x39231b.message.service);else{let M=this[g(1117)+"tManager"]?.[g(1359)+g(989)+"nt"]();this[g(607)+g(1157)+g(597)](ft(g(2008),{code:E[g(1600)],reason:g(1771)+g(1365)+g(473)+"wn reaso"+g(1140)+g(1091)+M})),this["_endpoin"+g(978)]?.[g(1381)+g(1619)+g(1851)](),this[g(2037)+g(561)]?.[g(416)+g(1103)]();return}this[g(607)+g(1157)+g(597)](E),this[g(1117)+g(978)]?.["resetEnd"+g(1619)+"fig"](),this[g(2037)+g(561)]?.[g(416)+g(1103)]()},this[s(1994)]=null,this[s(1645)]=null,this[s(700)+"e"]=null,this[s(1325)]=null,this[s(1418)+s(1562)]=null,this[s(548)+s(1801)]=null,this[s(740)+"mediatel"+s(1792)+"ct"]=null,this[s(1983)+s(496)]=this[s(1983)+s(496)].bind(this),this[s(1983)+s(1580)]=this[s(1983)+s(1580)][s(959)](this),this[s(1593)+s(678)]=this["_handleP"+s(678)][s(959)](this),this[s(1593)+s(1463)]=this["_handleP"+s(1463)][s(959)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:1/0,service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(1251)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.PbEeW,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:h}=n,b=Array[s(1608)](f)?f:e[s(654)]==typeof f?[f]:[];if(!b||e[s(447)](0,b[s(1053)]))throw new Error(e.KVZwm);if(!e[s(1565)](pp,h))throw new Error(e[s(1062)]);if(Object[s(1773)](this[s(738)],n),this[s(1117)+s(978)]=new Qd(b,this[s(738)][s(1862)+"es"]),this["_pingLos"+s(561)]=new wp(this[s(738)][s(564)+s(739)]),this._options[s(1959)+s(1607)]&&(this._isInit=!0,this._connect()),this[s(738)][s(830)+s(523)+s(838)])if(e[s(1626)](e[s(1934)],e[s(1295)])){let E=l[s(667)][s(1336)]("|"),g=0;for(;;){switch(E[g++]){case"0":this[s(1852)][s(1051)+s(1301)](l[s(1526)],this[s(1350)]);continue;case"1":this[s(1852)][s(1051)+"Listener"](l[s(793)],this[s(718)]);continue;case"2":this[s(1852)][s(1051)+"Listener"](s(2008),this[s(1013)]);continue;case"3":if(!this[s(1852)])return;continue;case"4":this[s(1852)][s(1051)+"Listener"](l[s(1226)],this[s(570)+"ge"]);continue}break}}else this[s(2014)+"T"]||this[s(769)+"X"]?this[s(1235)+s(1942)+"ange"]():this[s(1867)+"er"]&&this[s(810)+s(1313)+s(1301)]()}[t(1983)+"nLine"](){let n=t,s={UxSvX:e.CBRDp,VbrFi:e[n(490)],EUHaS:function(l,f){return e.cNwhp(l,f)},iPCgw:e.LCbhn};if(e.LFhuG("SJOoj",e[n(421)])){if(this[n(738)]["disableA"+n(1195)+n(1884)]||this[n(450)+n(1228)])return;this[n(1373)+n(1562)]()}else{let l={MSBHL:function(E){return lJxThV.vabGh(E)}},f=()=>{let E=n;_0x2ea70d[E(686)+E(1522)+E(768)]("complete",h),_0x3a16f3[E(686)+E(1522)+"ner"](ZoXRrY[E(1752)],b),_0x1acc64["removeEv"+E(1522)+"ner"](ZoXRrY[E(1534)],b)},h=()=>{let E=n;l[E(1662)](_0x17aa7e),l[E(1662)](f)},b=()=>{let E=n;ZoXRrY.EUHaS(_0x12900c,_0x55377c[E(1430)]||new _0x2525e6(ZoXRrY[E(1944)],E(1996)+"or")),f()};_0x55f133["addEvent"+n(1301)](lJxThV.kNCAL,h),_0x368852[n(1051)+n(1301)](lJxThV[n(1819)],b),_0x1a560e[n(1051)+n(1301)](lJxThV[n(490)],b)}}["_handleO"+t(1580)](){let n=t;this[n(1457)+n(816)+"t"]();let s=aa(e.NldzU,{message:e[n(924)]});this["onStopIm"+n(513)+n(1792)+"ct"]&&this[n(740)+"mediatelyReconnect"](s)}[t(810)+t(1313)+t(1301)](){let n=t;if(e[n(1108)]===e[n(1108)])this[n(1867)+"er"]&&window["addEvent"+n(1301)](e[n(969)],this[n(1983)+"nLine"]),this[n(1867)+"er"]&&window[n(1051)+"Listener"](e.BChat,this["_handleO"+n(1580)]),this[n(1867)+"er"]&&window.addEventListener(e[n(1022)],this[n(1593)+n(678)]),this[n(1867)+"er"]&&window[n(1051)+n(1301)](e[n(575)],this[n(1593)+"ageShow"]);else return _0x3a0d1f?.[n(386)](s=>s[n(1625)]===_0x1b4e83)?.[n(1611)]}[t(1011)+"balEvent"+t(1301)](){let n=t;this[n(1867)+"er"]&&window[n(686)+n(1522)+n(768)](e[n(969)],this["_handleO"+n(496)]),this._isBrowser&&window[n(686)+n(1522)+n(768)](e[n(861)],this[n(1983)+n(1580)]),this[n(1867)+"er"]&&window[n(686)+"entListe"+n(768)](e[n(1022)],this["_handleP"+n(678)]),this[n(1867)+"er"]&&window[n(686)+n(1522)+"ner"](e[n(575)],this[n(1593)+n(1463)])}[t(1593)+t(678)](n){let s=t;if(s(736)!==e[s(1374)]){let l=_0x2407ae.substring(0,e[s(1045)](4,_0x349cca[s(1053)])),f=l[s(893)](_0xbf1414);_0x43498b[s(1582)](f)}else{if(!n[s(1031)+"d"]){if(e[s(674)](s(2024),s(1445)))return _0x3907d8[s(1232)]>=_0x394051[s(500)];this._isBrowser&&window[s(686)+s(1522)+s(768)](s(2029),this[s(1593)+s(678)]),this[s(1867)+"er"]&&window[s(686)+s(1522)+s(768)](e[s(575)],this[s(1593)+s(1463)]),this[s(2008)]()}this[s(1867)+"er"]&&window[s(686)+s(1522)+"ner"](s(2010),this[s(1983)+"nLine"]),this[s(1867)+"er"]&&window[s(686)+s(1522)+"ner"](e[s(861)],this[s(1983)+s(1580)])}}[t(1593)+t(1463)](n){let s=t;n.persisted&&(this[s(1754)+s(875)]()&&(!this._ws||e.XDHoh(this[s(1852)].readyState,this[s(825)])||this[s(1852)].readyState!==this.CONNECTING)&&this[s(1983)+s(496)](),this[s(1867)+"er"]&&window[s(1051)+s(1301)](e[s(969)],this[s(1983)+s(496)]),this[s(1867)+"er"]&&window[s(1051)+"Listener"](s(1868),this[s(1983)+s(1580)]))}async["_generat"+t(588)](n){let s=t,{fpID:l,deviceID:f,bddID:h,ttwID:b,accessKey:E,aID:g,customParams:I={},enableAutoAck:M,enableQoS:z,QoSLevel:j,env:F}=this[s(738)],W,ve,xt;this._isBrowser||this[s(769)+"X"]||this._isMiniTT?(W=location&&e[s(921)](e[s(764)],location.protocol)?e.QKFEw:"ws://",ve=n[s(1794)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),xt=/^wss(.*:\/\/)/[s(1138)](n)?n:""+W+ve):(W=e[s(1466)],ve=n[s(1794)](/(^http)((?:[s]*:\/\/))/,""),xt=/(^ws)((?:[s]*:\/\/))/[s(1138)](ve)?ve:""+W+ve);let ht=h?e[s(1081)]:b?s(931):s(722)+"d",cl=h||b||f;if(e[s(1488)](!cl,!ht))throw new Error(e[s(603)]);let Zp=e[s(1333)](s(1644),typeof I)?await e[s(463)](I):I,Xp=F?e[s(1960)](mp,F.xUseEnv,F[s(413)]):{},pa=Object[s(1773)]({device_platform:"web",version_code:"fws_1.0.0",access_key:E,fpid:l,aid:g,[ht]:cl,xsack:M?1:0,xaack:M?1:0,xsqos:z?1:0,qos_level:z?j:void 0,qos_sdk_version:2,...Xp},Zp),Qp=Object[s(1943)](pa)[s(402)]((ga,ma)=>pa[ma]!==void 0?""+ga+(ga?"&":"?")+ma+"="+pa[ma]:ga,"");return xt+s(526)+Qp}async _connect(){let n=t;if(!(this["_connect"+n(1799)]||this[n(450)+"osed"])){this[n(527)+"Lock"]=!0;try{if(e[n(1515)](e[n(411)],e.DDtYE)){let s=this[n(1117)+n(978)]?.[n(1716)+n(759)+"ointReac"+n(659)+n(1599)](),{timeoutInterval:l}=this[n(738)];if(s){let h=this[n(1117)+"tManager"]?.[n(1359)+"ntEndpoint"](),b=this[n(1117)+"tManager"]?.["replaceB"+n(1879)+n(2038)+n(1405)+n(1264)](),E=this[n(1117)+n(978)]?.["getCurre"+n(989)+n(1842)+n(665)]();if(b){let g=n(1494)+h+(n(1756)+n(449)+n(775)+n(1164)+n(419)+n(470)+"ndpoint ")+b+(n(423)+"y"),I=e[n(1684)](ot,e[n(1819)],{message:g,code:tn[n(433)+"IES_ERROR"]});this[n(882)](g),this[n(607)+n(745)+n(597)](I),this._url=await this[n(591)+n(588)](b),this[n(882)](n(1494)+b+" "+E+n(683)),this[n(1392)+n(1813)+"rs"]()}else{let g="connect "+h+(n(1756)+n(449)+"tries reached");this[n(882)](g),this[n(607)+n(745)+n(597)](e[n(822)](ot,e[n(1819)],{message:g,code:tn[n(433)+n(1556)+"R"]}));return}}else{let h=this[n(1117)+n(978)]?.[n(1359)+n(989)+n(1121)+n(858)](),b=this[n(1117)+"tManager"]?.[n(1359)+"ntEndpoi"+n(1842)+"ount"]();this[n(679)]=await this._generateUrl(e[n(1907)](h,"")),this._debug("connect "+h+" "+b+" times"),this[n(1392)+"sListeners"]()}if(this[n(1290)])this[n(1290)]=!1;else{let h=aa(n(868)+"t",{message:e[n(1952)]});this[n(1418)+n(1562)]&&this[n(1418)+"econnect"](h)}let f=this[n(1117)+n(978)]?.[n(1359)+n(989)+n(1842)+"ount"]()||0;f>1&&await this[n(1527)](f-1),this[n(882)]("connecti"+n(1881)+this[n(679)]+(n(772)+n(1747))+this[n(1324)+"ls"]),this._ws=e[n(1416)](hp,{url:this[n(679)],protocols:[this[n(1324)+"ls"]],headers:this[n(738)][n(405)+n(1023)+"s"][n(586)+n(1049)]},this._options.ws),(this._isBrowser||this[n(439)+"r"])&&this[n(1852)]&&(this._ws[n(1843)+"pe"]=this[n(1728)+"ype"]),this["_addWsLi"+n(756)](),this["_connectionTimeo"+n(1287)]=e[n(1204)](setTimeout,this[n(1730)+"ut"][n(959)](this),l)}else _0x4ff505(_0x2571d2,66),e[n(1993)](_0x35bbff,_0x4a824d,_0x35aec8[n(1053)]),e[n(863)](_0x44779e,_0x2c6951,_0x174594)}catch(s){throw this["_connect"+n(1799)]=!1,s}}}[t(737)+t(872)](){let n=t;clearTimeout(this[n(527)+n(1152)+n(1287)]),this[n(527)+n(1152)+n(1287)]=null}[t(1458)+t(1384)](){let n=t;clearTimeout(this[n(495)+"gTimeoutId"]),e[n(1820)](clearTimeout,this._reconnectTimeoutId),this[n(495)+n(1893)+"Id"]=null,this[n(1243)+n(397)+n(1473)]=null}[t(882)](...n){let s=t;this[s(738)].debug&&console[s(1197)][s(567)](console,[s(2033)+">",...n])}["_getInte"+t(1334)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:f,reconnectIntervalGrowFactor:h}=this[s(738)],b=e[s(817)](l,Math[s(971)](h,e[s(458)](n,1)));return e[s(1829)](b,f)?f:b}_ping(){let n=t;if(this[n(1852)]&&e[n(1849)](this[n(1852)][n(1717)+"te"],this[n(1707)+"NG"])){this[n(1458)+n(1384)](),this["_pingPon"+n(1893)+"Id"]=e.dNxQF(setTimeout,this[n(1620)][n(959)](this),this[n(738)]["pingInte"+n(1151)]);return}if(!this[n(1852)]||e[n(1683)](this[n(1852)][n(1717)+"te"],this.OPEN))return void this[n(1373)+n(1562)]();this[n(1852)]&&this[n(1852)].send("hi"),this[n(1243)+n(397)+"tId"]=e.Lgexc(setTimeout,this[n(1373)+n(1562)+n(1258)].bind(this),this._options[n(891)+n(1873)+n(1150)])}[t(1373)+t(1562)+t(1258)](){let n=t;this[n(2037)+n(561)]?.addCount(),this.emit(e.EMONn,e[n(1075)]),this[n(2037)+"sCounter"]?.[n(1245)+n(814)+"nt"]()?this["_handleR"+n(1562)]():this[n(1620)]()}[t(1754)+t(875)](){let n=t;return this._isMiniTT||this[n(769)+"X"]?this[n(1895)+"igatorOn"+n(1653)]:(this._isBrowser||this._isWorker)&&this[n(738)]["listenNe"+n(523)+"nged"]?navigator[n(1930)]:!0}_handleReconnect(){let n=t;!this[n(1754)+n(875)]()||this[n(450)+"osed"]||(this[n(1117)+n(978)]?.[n(1381)+n(1619)+n(1851)](),this[n(2037)+n(561)]?.["resetCou"+n(1103)](),this[n(1852)]?this[n(706)+n(1587)](1001,e[n(1559)],!0):this[n(527)]())}[t(1235)+t(1942)+"ange"](){let n=t,s={VyraJ:e.ftJDJ,eTCVW:"ppe",ddiql:function(l,f){return e.npdrb(l,f)}};this._isMiniTT?tt[n(509)+n(707)+n(841)](({isConnected:l})=>{let f=n;if(s.ddiql(f(723),"Elspn"))this[f(1895)+f(1407)+f(1653)]=l,l?this["_handleO"+f(496)]():this[f(1983)+f(1580)]();else switch(_0x513b44){case GvlSMy[f(789)]:case GvlSMy[f(613)]:return{[f(963)+_0x14dcac]:1,"x-tt-env":_0x4872b9};default:return{}}}):this[n(769)+"X"]&&wx[n(509)+"kStatusC"+n(841)](({isConnected:l})=>{let f=n;this["_miniNavigatorOn"+f(1653)]=l,l?this[f(1983)+f(496)]():this._handleOffLine()})}[t(1527)](n){return new Promise(s=>{let l=G;e[l(1727)](setTimeout,s,this[l(581)+l(1334)+"e"](n))})}[t(706)+"ect"](n=1e3,s="",l=!1){let f=t;this[f(1852)]&&this[f(1457)+f(816)+"t"](n,s,l)}[t(1730)+"ut"](){let n=t;if(e.Peime!=="OCoHF"){let s=this["_endpoin"+n(978)]?.[n(1359)+n(989)+"nt"]();this[n(882)](n(1494)+s+n(1756)),this[n(706)+"ect"](1001,e.ePJlH,!0)}else return new _0x5d7774(_0x3b3b08,{message:_0x24b4f2,code:_0x36f09c,error:_0x5de85c})}[t(724)](n){let s=t,l=e[s(1762)](zt,n);this[s(1852)]&&this[s(1852)][s(1717)+"te"]===this[s(825)]&&(this[s(1852)]&&this._ws.send(l),this[s(882)](e.OUyrE,n))}[t(1392)+t(1813)+"rs"](){let n=t,s=(n(593)+"3")[n(1336)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1852)][n(686)+n(1522)+"ner"](e[n(1410)],this[n(1013)]);continue;case"1":this._ws[n(686)+n(1522)+n(768)]("open",this[n(1350)]);continue;case"2":if(!this[n(1852)])return;continue;case"3":this._ws[n(686)+n(1522)+n(768)]("error",this[n(718)]);continue;case"4":this[n(1852)][n(686)+n(1522)+n(768)]("message",this[n(570)+"ge"]);continue}break}}[t(1623)+"steners"](){let n=t;this[n(1852)]&&(this[n(1852)]["addEvent"+n(1301)]("open",this[n(1350)]),this[n(1852)][n(1051)+n(1301)](e[n(1410)],this._onClose),this._ws["addEvent"+n(1301)]("message",this[n(570)+"ge"]),this._ws[n(1051)+n(1301)](e[n(1819)],this._onError))}[t(1206)+"nceClose"](n=1e3,s=""){let l=t;if(e.nFLMX!==l(468))try{this[l(1852)]&&this[l(1852)][l(2008)](n,s)}catch{}else _0x494cd4[l(1434)](_0x579cbb,_0x57a312),_0x159caa[l(1434)](_0x4180f8,_0x1603c6)}[t(1457)+t(816)+"t"](n=1e3,s="",l=!1){let f=t;if(this[f(1458)+f(1384)](),this["_clearTi"+f(872)](),this[f(1392)+f(1813)+"rs"](),this[f(1206)+f(1945)](1e3,s),this[f(527)+f(1799)]=!1,l&&this["_navigat"+f(875)]()&&!this[f(450)+f(1228)]){if(this[f(1117)+f(978)]?.["checkRea"+f(958)+"es"]()){let b=this[f(1117)+f(978)]?.[f(1359)+"ntEndpoint"]();this[f(607)+f(1157)+f(597)](e[f(1362)](ft,e[f(1410)],{code:1006,reason:f(1494)+b+(" timeout"+f(449)+f(775)+"ached"),wasClean:!0}))}else{let b=this[f(738)]["reconnec"+f(1549)+f(1833)](n,s);this[f(607)+"hCloseEvent"](e[f(1433)](ft,e[f(1410)],{code:n,reason:s,wasClean:!0,willReconnect:b})),b&&this._connect()}return}this[f(1754)+"orOnline"]()||this[f(450)+f(1228)]?this[f(607)+f(1157)+"ent"](e[f(1256)](ft,e[f(1410)],{code:n,reason:e.khNHM})):this[f(607)+"hCloseEv"+f(597)](e[f(1486)](ft,e[f(1410)],{code:1006,reason:e[f(1746)]})),this[f(1852)]=null,this[f(1117)+f(978)]?.[f(1381)+f(1619)+f(1851)](),this[f(2037)+f(561)]?.[f(416)+f(1103)]()}[t(607)+t(1065)+"nt"](n){let s=t;if(e[s(688)](s(585),s(995)))this[s(1733)](e.KTGlW,n),this.onopen&&this[s(1325)](n);else{let l=e[s(1724)](e[s(1124)](e.CXbPs(e[s(827)](7,_0x171ca8),18)|e[s(1776)](e[s(1826)](63,_0x15d29d[_0x28fe2a++]),12),e[s(1846)](e.rMUZU(63,_0x2b71c6[_0x42e28c++]),6)),e[s(583)](63,_0x34e092[_0x300cbb++]))-65536;_0x3ce1a9+=_0x3994ab[s(1692)+s(964)](e.IoCcO(55296,e[s(762)](l,10))),_0xd7ecf1+=_0x79f236[s(1692)+"Code"](e.JcFzJ(56320,1023&l))}}[t(607)+t(709)+t(1483)](n){let s=t;this[s(1733)](e[s(1385)],n),this[s(700)+"e"]&&this[s(700)+"e"](n)}[t(607)+t(1109)+t(1821)](n){let s=t,l={ONcvh:function(f,h){return e[G(1082)](f,h)}};if(e[s(1503)](e.mgSms,e[s(649)]))this[s(1733)](e.tYrPK,n),this[s(548)+s(1801)]&&this[s(548)+s(1801)](n);else{let f=this[s(1639)][s(1558)+"geInfoSync"](this._prefix),h=_0x2aca99[s(577)](isnOEQ[s(1438)](f,"{}"));return _0x277580[s(1778)](h)}}[t(607)+t(745)+t(597)](n){let s=t;this[s(1733)](e[s(1819)],n),this[s(1645)]&&this[s(1645)](n)}["_dispatchCloseEv"+t(597)](n){let s=t;this.emit(e[s(1410)],n),this[s(1994)]&&this.onclose(n)}get binaryType(){let n=t;return e[n(674)](e[n(819)],e.ESRFL)?this._qosDB?.[n(757)]:this[n(1852)]?this._ws[n(1843)+"pe"]:this[n(1728)+n(855)]}set binaryType(n){let s=t;this[s(1728)+s(855)]=n,this[s(1852)]&&(this._ws[s(1843)+"pe"]=n)}get[t(1962)+"nt"](){let n=t;return e[n(1949)](e.iOWUh,e[n(721)])?(_0x41b479&&(_0x22e7ce=(0,_0x2aa37c[_0x5ce991(_0x51c5d7)[0]])(_0x4b9aa6=0)),_0x4c06e6):this[n(1117)+"tManager"]?.[n(1359)+n(989)+"ntTriesC"+n(665)]()||0}get[t(802)+t(1859)](){let n=t,s=this[n(1005)+n(531)].reduce((l,f)=>(l+=f&&f[n(878)+"th"]||0,l),0);return e[n(1900)](s,this[n(1852)]?this._ws[n(802)+n(1859)]:0)}get[t(1978)+"ns"](){let n=t;return this._ws?this[n(1852)][n(1978)+"ns"]:""}get[t(864)](){let n=t;return this[n(1852)]?this[n(1852)][n(864)]:""}get readyState(){let n=t;return this[n(1852)]?this[n(1852)][n(1717)+"te"]:this[n(738)][n(1959)+"cOpen"]?this[n(1707)+"NG"]:this[n(430)]}get[t(1991)](){let n=t;return this[n(1852)]?this[n(1852)][n(1991)]:this._url}close(n=1e3,s){let l=t;if(this._readyClosed=!0,this[l(737)+l(872)](),this["_clearPi"+l(1384)](),this["_dropGlo"+l(1313)+"Listener"](),this[l(1770)+l(1098)]?.[l(551)](),!this[l(1852)])return void this[l(882)](e[l(1339)]);if(e[l(951)](this[l(1852)][l(1717)+"te"],this.CLOSED)||e[l(1095)](this[l(1852)].readyState,this[l(529)]))return void this[l(882)](l(1348)+l(940)+"y closed");this[l(1457)+l(816)+"t"](n,s)}async[t(2017)](n,s){let l=t,f={kONYB:function(h,b){return e[G(542)](h,b)}};if(l(799)===e[l(1083)]){let h=this[l(1639)][l(1558)+"geInfoSync"](this[l(475)]),b=_0x1af480[l(577)](e[l(881)](h,"{}"));return _0x19578e[l(1943)](b)}else{if(e.tUqvs(null,n))throw new Error(e[l(520)]);e.DSeNI(e[l(1026)],typeof n)&&(n=JSON[l(1060)+"y"](n)),e[l(1194)](e.DDcSc,typeof n)&&!(n instanceof ArrayBuffer)&&!(n[l(1550)]&&e[l(560)](n.buffer,ArrayBuffer))&&(n=JSON[l(1060)+"y"](n));let h=await e[l(754)](rl,n),b=gp(n),{method:E=0,service:g=this._options.service,logID:I=this._options[l(1910)+l(459)](),headers:M=this._options[l(2019)],payloadEncoding:z=this._options["payloadE"+l(807)],payloadType:j=this[l(738)][l(1552)+l(855)],logIDNew:F=this._options[l(1705)+l(1557)][l(1432)+"toGenera"+l(1672)+"ew"]?e.YaVVd(i,this._options[l(1705)+"Config"][l(734)]):""}=s||{};if(!g)throw new Error(e.HCLIx);let W={SeqID:fe[l(1543)+"er"](this[l(1001)]++),LogID:fe.fromNumber(I),service:g,method:E,headers:M,payloadEncoding:e[l(1933)](z,Object)?z.encoding?z[l(1855)]:"":z,payloadType:e.NgMbu(j,Object)?j[l(927)]?j[l(927)]:b:j||b,payload:h,LogIDNew:F},ve=e[l(1877)](zt,W);if(this._ws&&e[l(1568)](this[l(1852)].readyState,this.OPEN))this._ws&&this._ws.send(ve),this[l(882)](e[l(1018)],W);else if(e[l(461)](this[l(1005)+l(531)][l(1053)],this._options[l(1584)+l(1875)+l(1981)])){if(e[l(623)](l(624),e[l(464)]))return KqpliV[l(1990)](this[l(1044)],this[l(1073)+l(665)]);this._messageQueue[l(1582)](ve),this._debug(e[l(1153)],W)}else this[l(1005)+l(531)][l(1292)](),this[l(1005)+l(531)][l(1582)](ve);return{seqID:this._seqId,logID:I,logIDNew:F}}}async[t(868)+"t"](n){let s=t,l={cnEaP:function(f,h){return f>=h},UtmPX:function(f,h){return e[G(1426)](f,h)},ntgWx:function(f,h){return e[G(808)](f,h)}};if(e[s(1219)]("ejMNt",e.EbCYf)){if(_0x10f71d<=-_0x3f0bf1)return _0x2ab2d4;if(ylirAA[s(1087)](ylirAA.UtmPX(_0x519e03,1),_0x1fbc45))return _0x1823f3}else{let{url:f}=e[s(1276)](n,{}),h=Array[s(1608)](f)?f:e.DSeNI(e.DDcSc,typeof f)?[f]:[];n&&Object.assign(this[s(738)],n),h&&h[s(1053)]?this["_endpoin"+s(978)]=new Qd(h,this._options[s(1862)+"es"]):this[s(1117)+s(978)]?.[s(1381)+s(1619)+s(1851)](),this[s(2037)+s(561)]?.[s(416)+s(1103)](this[s(738)]["pingLoss"+s(739)]),this[s(450)+s(1228)]=!1,this[s(1852)]&&e[s(598)](this._ws.readyState,this[s(430)])?this[s(706)+s(1587)](1e3,e.tjqIC,!0):e[s(605)]===e[s(605)]?(this[s(1290)]=!0,this._connect()):(_0x2810ad+=ylirAA[s(1310)](_0x1ba137,_0x2ee5b4),_0x4c6e59+=2)}}async connect(){let n=t;if(e[n(1052)](e[n(436)],n(900)))this.on(_0x1975a0,_0x486287);else if(!this["_connect"+n(1799)]){let s=(n(1368)+"4")[n(1336)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(2037)+n(561)]?.[n(416)+n(1103)]();continue;case"1":this._isInit=!0;continue;case"2":this[n(450)+n(1228)]=!1;continue;case"3":this[n(1117)+n(978)]?.[n(1381)+n(1619)+"fig"]();continue;case"4":this[n(527)]();continue}break}}}[t(1051)+t(1301)](n,s){this.on(n,s)}[t(974)+"Event"](n){let{type:s}=n;this.emit(s,n)}["removeEv"+t(1522)+"ner"](n,s){this.off(n,s)}[t(1238)](){let n=t,s={SvyIk:function(l,f){return e[G(1820)](l,f)},WLyHh:e.SnXOT};if(e[n(1219)](e[n(1259)],e[n(714)]))return new Promise((l,f)=>{let h=n,b={EKoaM:e[h(1075)],yVCda:e.pyMUL,TIofG:e[h(1750)]};if(e[h(1784)](e[h(440)],e[h(1175)])){let E=_0x59aead[h(1695)],g=_0x2fe656[h(500)];return E[h(1053)]===g?E:E[h(580)](0,g)}else{this[h(1458)+h(1384)](),this[h(495)+h(1893)+"Id"]=e[h(2003)](setTimeout,this[h(1620)][h(959)](this),this[h(738)][h(809)+h(1151)]);let E=()=>{let I=h;s[I(1555)](l,s[I(1689)]),this.off(I(1806)+I(815)+"s",E),this[I(1408)]("ping_onc"+I(1420)+"t",g)},g=()=>{let I=h;f(b.EKoaM),this[I(1408)](b[I(1176)],E),this.off(b[I(1280)],g)};this.on("ping_once_success",E),this.on("ping_onc"+h(1420)+"t",g),this[h(1620)]()}});if(e[n(582)](_0x35bdd5,_0x399a54))return _0x3cc37a}}})(),Ie[L(443)+L(812)]=Re.CustomCloseEvent,Ie[L(481)+L(1795)]=Re[L(481)+L(1795)],Ie[L(1294)+"e"]=Re[L(1294)+"e"],Ie[L(1483)]=Re[L(1483)],Ie.FWS=Re.FWS,Ie[L(1127)+L(483)+L(1774)]=Re[L(1127)+"MessageE"+L(1774)],Ie["MessageE"+L(1774)]=Re["MessageE"+L(1774)],Ie[L(1528)+"t"]=Re[L(1528)+"t"],Ie[L(1798)+L(733)]=Re[L(1798)+L(733)],Ie[L(1977)+"oseEvent"]=Re[L(1977)+"oseEvent"],Ie[L(1225)+L(1795)]=Re[L(1225)+L(1795)],Ie[L(602)+"ssageEvent"]=Re[L(602)+L(1375)+"nt"],Ie["createOp"+L(1892)]=Re[L(643)+"enEvent"],Ie[L(867)+L(1024)+L(1774)]=Re[L(867)+L(1024)+"vent"],Ie[L(569)+"rame"]=Re[L(569)+L(1957)],Ie[L(910)+"ame"]=Re[L(910)+L(991)];for(Bo in Re)["CustomCloseEvent","CustomErrorEvent","ErrorCode","Event",L(2021),L(1127)+L(483)+L(1774),L(483)+"vent",L(1528)+"t","ReconnectEvent",L(1977)+L(812),L(1225)+L(1795),"createMe"+L(1375)+"nt",L(643)+L(1892),L(867)+L(1024)+L(1774),L(569)+L(1957),L(910)+"ame"][L(1161)](Bo)===-1&&(Ie[Bo]=Re[Bo]);var Bo;Object[L(408)+L(1395)](Ie,"__esModule",{value:!0})});import{existsSync as nS,openSync as rS}from"node:fs";import{mkdir as iS}from"node:fs/promises";import{dirname as sS}from"node:path";import{fileURLToPath as oS}from"node:url";function cS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function kd(t=Q()){return nS(t.libEntry)?t.libEntry:oS(new URL("../index.ts",import.meta.url))}async function Th(t={}){let e=t.paths??Q(),r=t.entryOverride??kd(e),i=cS(e,process.env.COZE_BRIDGE_LOG_MODE);await iS(sS(i),{recursive:!0});let o=rS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=et(process.execPath,d,{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 aS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var aS,es,Vo=Ye(()=>{"use strict";Kt();ne();Oe();aS=H("spawn-daemon"),es="COZE_BRIDGE_DAEMON"});import{spawn as t1}from"node:child_process";import{mkdir as n1,unlink as r1,writeFile as i1}from"node:fs/promises";import{dirname as s1,join as o1}from"node:path";function Kr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function a1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Kr(r)}</key>
|
|
21
|
+
<string>${Kr(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=t1(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 Wr,ns,ta,Ud,$h=Ye(()=>{"use strict";ne();Wr=H("supervisor.launchd"),ns="ai.coze.bridge",ta=c1,Ud={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>${ns}</string>
|
|
32
32
|
<key>ProgramArguments</key>
|
|
33
33
|
<array>
|
|
34
|
-
<string>${
|
|
35
|
-
<string>${
|
|
34
|
+
<string>${Kr(t.nodeBin)}</string>
|
|
35
|
+
<string>${Kr(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>${Kr(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${
|
|
47
|
+
<string>${Kr(t.logFile)}</string>${a1(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function
|
|
50
|
+
`},configPath(t){return o1(t.homeDir,"Library","LaunchAgents",`${ns}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await n1(s1(i),{recursive:!0}),await i1(i,this.renderConfig(t),"utf8"),Wr.info("plist written",{plistPath:i,activate:r}),!r)return;await ta("launchctl",["unload","-w",i]).catch(c=>Wr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ta("launchctl",["load","-w",i]),Wr.info("launchd job loaded",{label:ns});let o=process.getuid?.()??0;await ta("launchctl",["kickstart","-k",`gui/${o}/${ns}`]),Wr.info("launchd job kickstarted",{label:ns,uid:o})},async uninstall(t){let e=this.configPath(t);await ta("launchctl",["unload","-w",e]).catch(r=>Wr.warn("launchctl unload failed (ignored)",{err:String(r)})),await r1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Wr.info("launchd job removed",{plistPath:e})}}});import{spawn as d1}from"node:child_process";import{mkdir as l1,unlink as u1,writeFile as f1}from"node:fs/promises";import{dirname as x1,join as Vh}from"node:path";function ra(t,e){return t.isRoot?e:["--user",...e]}function p1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function ia(t,e){return new Promise((r,i)=>{let o=d1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var na,$r,h1,Gd,Jh=Ye(()=>{"use strict";ne();na=H("supervisor.systemd"),$r="coze-bridge.service",h1="/etc/systemd/system";Gd={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
|
+
${p1(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?
|
|
65
|
+
`},configPath(t){return t.isRoot?Vh(h1,$r):Vh(t.homeDir,".config","systemd","user",$r)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await l1(x1(i),{recursive:!0}),await f1(i,this.renderConfig(t),"utf8"),na.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ia("systemctl",ra(t,["daemon-reload"])),await ia("systemctl",ra(t,r?["enable","--now",$r]:["enable",$r])),na.info("systemd unit enabled",{unitName:$r,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ia("systemctl",ra(t,["disable","--now",$r])).catch(r=>na.warn("systemctl disable failed (ignored)",{err:String(r)})),await u1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ia("systemctl",ra(t,["daemon-reload"])).catch(()=>{}),na.info("systemd unit removed",{unitPath:e})}}});import{spawn as g1}from"node:child_process";import{join as m1}from"node:path";function Yh(t,e){return new Promise((r,i)=>{let o=g1(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 Hd,sa,qd,Zh=Ye(()=>{"use strict";ne();Hd=H("supervisor.taskscheduler"),sa="CozeBridge",qd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
|
|
66
66
|
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
67
67
|
<RegistrationInfo>
|
|
68
68
|
<Description>Coze Bridge daemon</Description>
|
|
@@ -86,45 +86,48 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return w1(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 ep("schtasks",["/Create","/SC","ONLOGON","/TN",ia,"/TR",r,"/RU",t.userName,"/F"]),Hd.info("task scheduler entry created",{task:ia,logFile:t.logFile})},async uninstall(t){await ep("schtasks",["/Delete","/TN",ia,"/F"]).catch(e=>Hd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Hd.info("task scheduler entry removed",{task:ia})}}});var np={};_a(np,{buildContext:()=>S1,getSupervisor:()=>E1,launchdSupervisor:()=>Gd,systemdSupervisor:()=>qd,taskSchedulerSupervisor:()=>jd});import{homedir as _1,userInfo as y1}from"node:os";function E1(t=process.platform){switch(t){case"darwin":return Gd;case"linux":return qd;case"win32":return jd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function b1(){let t={};for(let e of v1){let r=process.env[e];r&&(t[e]=r)}return t}function S1(){let t=Y();return{nodeBin:process.execPath,entry:Pd(t),logFile:t.logFile,homeDir:_1(),userName:y1().username,isRoot:process.getuid?.()===0,env:b1()}}var v1,rp=Je(()=>{"use strict";ke();$o();Yx();Qx();tp();v1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();nn();var vl=U("acp-installer-warmup"),kg=["claude-code","codex"];async function bl(t={}){let e=t.ensure??nr,i=(await Promise.allSettled(kg.map(async o=>{let c=await e(o);vl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&vl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}rn();ne();import{readdir as Hg}from"node:fs/promises";import{mkdir as Rl,readFile as Gg,writeFile as kl}from"node:fs/promises";import{join as Aa}from"node:path";var qg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function sr(t,e,r){await Rl(t,{recursive:!0});let i=qg[e],o=Aa(t,i);return await kl(o,r??"","utf8"),o}async function Ta(t,e,r){let i=Aa(t,".claude");await Rl(i,{recursive:!0});let o=Aa(i,"settings.local.json"),c={};try{let u=await Gg(o,"utf8"),h=JSON.parse(u);typeof h=="object"&&h!==null&&!Array.isArray(h)&&(c=h)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await kl(o,JSON.stringify(c,null,2),"utf8"),o}var Ke=U("agent-detail-sync"),jg=6e4,Wg=5*6e4,ls=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Hg(r)}catch(o){Ke.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ke.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Ge(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ke.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Ke.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Ke.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){Ke.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ke.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Ge(e,this.opts.paths);if(!i){Ke.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(h){Ke.warn("detail RPC failed, using local data",{agentId:e,err:String(h)});let x=this.retryQueue.get(e),m=x?Math.min(x.currentDelay*2,Wg):jg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Ke.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"?(Ke.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ke.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ke.debug("detail sync: no diff",{agentId:e});return}await Ye(i,this.opts.paths),Ke.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}),Ke.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await sr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Vf=bt(du(),1);import{lstat as Gc,mkdir as qc,readFile as jf,readdir as __,rm as y_,stat as E_,writeFile as Hc}from"node:fs/promises";import{dirname as v_,join as Dt,normalize as b_,relative as Kc,resolve as jc,sep as Wf}from"node:path";import{Readable as Kf}from"node:stream";import{pipeline as $f}from"node:stream/promises";import hm from"events";import Xe from"fs";import{EventEmitter as Ac}from"node:events";import ju from"node:stream";import{StringDecoder as xm}from"node:string_decoder";import $u from"node:path";import mr from"node:fs";import{dirname as Tm,parse as Cm}from"path";import{EventEmitter as Mm}from"events";import ac from"assert";import{Buffer as Fn}from"buffer";import*as xu from"zlib";import Bm from"zlib";import{posix as lr}from"node:path";import{basename as lw}from"node:path";import qs from"fs";import Ct from"fs";import Eu from"path";import{win32 as vw}from"node:path";import Cu from"path";import df from"node:fs";import zw from"node:assert";import{randomBytes as lf}from"node:crypto";import re from"node:fs";import Pe from"node:path";import uf from"fs";import Ys from"node:fs";import _i from"node:path";import nt from"node:fs";import Kw from"node:fs/promises";import Ws from"node:path";import{join as vf}from"node:path";import et from"node:fs";import If from"node:path";var um=Object.defineProperty,fm=(t,e)=>{for(var r in e)um(t,r,{get:e[r],enumerable:!0})},lu=typeof process=="object"&&process?process:{stdout:null,stderr:null},pm=t=>!!t&&typeof t=="object"&&(t instanceof Gn||t instanceof ju||gm(t)||mm(t)),gm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,mm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.write=="function"&&typeof t.end=="function",Ft=Symbol("EOF"),zt=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),ps=Symbol("emittingEnd"),ni=Symbol("emittedError"),gs=Symbol("closed"),uu=Symbol("read"),ms=Symbol("flush"),fu=Symbol("flushChunk"),ht=Symbol("encoding"),dr=Symbol("decoder"),Ne=Symbol("flowing"),ri=Symbol("paused"),xr=Symbol("resume"),Me=Symbol("buffer"),$e=Symbol("pipes"),Be=Symbol("bufferLength"),Oa=Symbol("bufferPush"),ws=Symbol("bufferShift"),We=Symbol("objectMode"),be=Symbol("destroyed"),La=Symbol("error"),Na=Symbol("emitData"),hu=Symbol("emitEnd"),Ma=Symbol("emitEnd2"),It=Symbol("async"),Ba=Symbol("abort"),_s=Symbol("aborted"),ii=Symbol("signal"),Rn=Symbol("dataListeners"),Qe=Symbol("discarded"),si=t=>Promise.resolve().then(t),wm=t=>t(),_m=t=>t==="end"||t==="finish"||t==="prefinish",ym=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Em=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Wu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[xr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},vm=class extends Wu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},bm=t=>!!t.objectMode,Sm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Gn=class extends Ac{[Ne]=!1;[ri]=!1;[$e]=[];[Me]=[];[We];[ht];[It];[dr];[Ft]=!1;[on]=!1;[ps]=!1;[gs]=!1;[ni]=null;[Be]=0;[be]=!1;[ii];[_s]=!1;[Rn]=0;[Qe]=!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[We]=!0,this[ht]=null):Sm(e)?(this[ht]=e.encoding,this[We]=!1):(this[We]=!1,this[ht]=null),this[It]=!!e.async,this[dr]=this[ht]?new xm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[$e]});let{signal:r}=e;r&&(this[ii]=r,r.aborted?this[Ba]():r.addEventListener("abort",()=>this[Ba]()))}get bufferLength(){return this[Be]}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[We]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ba](){this[_s]=!0,this.emit("abort",this[ii]?.reason),this.destroy(this[ii]?.reason)}get aborted(){return this[_s]}set aborted(t){}write(t,e,r){if(this[_s])return!1;if(this[Ft])throw new Error("write after end");if(this[be])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]?si:wm;if(!this[We]&&!Buffer.isBuffer(t)){if(Em(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(ym(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[We]?(this[Ne]&&this[Be]!==0&&this[ms](!0),this[Ne]?this.emit("data",t):this[Oa](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[dr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[dr].write(t)),this[Ne]&&this[Be]!==0&&this[ms](!0),this[Ne]?this.emit("data",t):this[Oa](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne])}read(t){if(this[be])return null;if(this[Qe]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[zt](),null;this[We]&&(t=null),this[Me].length>1&&!this[We]&&(this[Me]=[this[ht]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[uu](t||null,this[Me][0]);return this[zt](),e}[uu](t,e){if(this[We])this[ws]();else{let r=e;t===r.length||t===null?this[ws]():typeof r=="string"?(this[Me][0]=r.slice(t),e=r.slice(0,t),this[Be]-=t):(this[Me][0]=r.subarray(t),e=r.subarray(0,t),this[Be]-=t)}return this.emit("data",e),!this[Me].length&&!this[Ft]&&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[Ft]=!0,this.writable=!1,(this[Ne]||!this[ri])&&this[zt](),this}[xr](){this[be]||(!this[Rn]&&!this[$e].length&&(this[Qe]=!0),this[ri]=!1,this[Ne]=!0,this.emit("resume"),this[Me].length?this[ms]():this[Ft]?this[zt]():this.emit("drain"))}resume(){return this[xr]()}pause(){this[Ne]=!1,this[ri]=!0,this[Qe]=!1}get destroyed(){return this[be]}get flowing(){return this[Ne]}get paused(){return this[ri]}[Oa](t){this[We]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[ws](){return this[We]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[ms](t=!1){do;while(this[fu](this[ws]())&&this[Me].length);!t&&!this[Me].length&&!this[Ft]&&this.emit("drain")}[fu](t){return this.emit("data",t),this[Ne]}pipe(t,e){if(this[be])return t;this[Qe]=!1;let r=this[on];return e=e||{},t===lu.stdout||t===lu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[$e].push(e.proxyErrors?new vm(this,t,e):new Wu(this,t,e)),this[It]?si(()=>this[xr]()):this[xr]()),t}unpipe(t){let e=this[$e].find(r=>r.dest===t);e&&(this[$e].length===1?(this[Ne]&&this[Rn]===0&&(this[Ne]=!1),this[$e]=[]):this[$e].splice(this[$e].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[Qe]=!1,this[Rn]++,!this[$e].length&&!this[Ne]&&this[xr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(_m(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ni]){let i=e;this[It]?si(()=>i.call(this,this[ni])):i.call(this,this[ni])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Rn]=this.listeners("data").length,this[Rn]===0&&!this[Qe]&&!this[$e].length&&(this[Ne]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Rn]=0,!this[Qe]&&!this[$e].length&&(this[Ne]=!1)),e}get emittedEnd(){return this[on]}[zt](){!this[ps]&&!this[on]&&!this[be]&&this[Me].length===0&&this[Ft]&&(this[ps]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[gs]&&this.emit("close"),this[ps]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==be&&this[be])return!1;if(t==="data")return!this[We]&&!r?!1:this[It]?(si(()=>this[Na](r)),!0):this[Na](r);if(t==="end")return this[hu]();if(t==="close"){if(this[gs]=!0,!this[on]&&!this[be])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ni]=r,super.emit(La,r);let o=!this[ii]||this.listeners("error").length?super.emit("error",r):!1;return this[zt](),o}else if(t==="resume"){let o=super.emit("resume");return this[zt](),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[zt](),i}[Na](t){for(let r of this[$e])r.dest.write(t)===!1&&this.pause();let e=this[Qe]?!1:super.emit("data",t);return this[zt](),e}[hu](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[It]?(si(()=>this[Ma]()),!0):this[Ma]())}[Ma](){if(this[dr]){let e=this[dr].end();if(e){for(let r of this[$e])r.dest.write(e);this[Qe]||super.emit("data",e)}}for(let e of this[$e])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[We]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[We]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[We])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(be,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[Qe]=!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[Ft])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(be,h),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(be,h),this.pause(),i({value:x,done:!!this[Ft]})},u=()=>{this.off("error",c),this.off("data",d),this.off(be,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(be,h),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Qe]=!1;let t=!1,e=()=>(this.pause(),this.off(La,e),this.off(be,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(La,e),this.once(be,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[be])return t?this.emit("error",t):this.emit(be),this;this[be]=!0,this[Qe]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[gs]&&e.close(),t?this.emit("error",t):this.emit(be),this}static get isStream(){return pm}},Im=Xe.writev,gn=Symbol("_autoClose"),mt=Symbol("_close"),oi=Symbol("_ended"),de=Symbol("_fd"),Fa=Symbol("_finished"),Ht=Symbol("_flags"),za=Symbol("_flush"),sc=Symbol("_handleChunk"),oc=Symbol("_makeBuf"),mi=Symbol("_mode"),ys=Symbol("_needDrain"),_r=Symbol("_onerror"),yr=Symbol("_onopen"),Ua=Symbol("_onread"),pr=Symbol("_onwrite"),mn=Symbol("_open"),gt=Symbol("_path"),un=Symbol("_pos"),At=Symbol("_queue"),gr=Symbol("_read"),Ga=Symbol("_readSize"),qt=Symbol("_reading"),ai=Symbol("_remain"),qa=Symbol("_size"),ks=Symbol("_write"),kn=Symbol("_writing"),Ds=Symbol("_defaultFlag"),Bn=Symbol("_errored"),Tc=class extends Gn{[Bn]=!1;[de];[gt];[Ga];[qt]=!1;[qa];[ai];[gn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Bn]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[gt]=t,this[Ga]=e.readSize||16*1024*1024,this[qt]=!1,this[qa]=typeof e.size=="number"?e.size:1/0,this[ai]=this[qa],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[gr]():this[mn]()}get fd(){return this[de]}get path(){return this[gt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[mn](){Xe.open(this[gt],"r",(t,e)=>this[yr](t,e))}[yr](t,e){t?this[_r](t):(this[de]=e,this.emit("open",e),this[gr]())}[oc](){return Buffer.allocUnsafe(Math.min(this[Ga],this[ai]))}[gr](){if(!this[qt]){this[qt]=!0;let t=this[oc]();if(t.length===0)return process.nextTick(()=>this[Ua](null,0,t));Xe.read(this[de],t,0,t.length,null,(e,r,i)=>this[Ua](e,r,i))}}[Ua](t,e,r){this[qt]=!1,t?this[_r](t):this[sc](e,r)&&this[gr]()}[mt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[_r](t){this[qt]=!0,this[mt](),this.emit("error",t)}[sc](t,e){let r=!1;return this[ai]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ai]<=0)&&(r=!1,this[mt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[gr](),!1;case"error":return this[Bn]?!1:(this[Bn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Am=class extends Tc{[mn](){let t=!0;try{this[yr](null,Xe.openSync(this[gt],"r")),t=!1}finally{t&&this[mt]()}}[gr](){let t=!0;try{if(!this[qt]){this[qt]=!0;do{let e=this[oc](),r=e.length===0?0:Xe.readSync(this[de],e,0,e.length,null);if(!this[sc](r,e))break}while(!0);this[qt]=!1}t=!1}finally{t&&this[mt]()}}[mt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Xe.closeSync(t),this.emit("close")}}},Ks=class extends hm{readable=!1;writable=!0;[Bn]=!1;[kn]=!1;[oi]=!1;[At]=[];[ys]=!1;[gt];[mi];[gn];[de];[Ds];[Ht];[Fa]=!1;[un];constructor(t,e){e=e||{},super(e),this[gt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mi]=e.mode===void 0?438:e.mode,this[un]=typeof e.start=="number"?e.start:void 0,this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[un]!==void 0?"r+":"w";this[Ds]=e.flags===void 0,this[Ht]=e.flags===void 0?r:e.flags,this[de]===void 0&&this[mn]()}emit(t,...e){if(t==="error"){if(this[Bn])return!1;this[Bn]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[gt]}[_r](t){this[mt](),this[kn]=!0,this.emit("error",t)}[mn](){Xe.open(this[gt],this[Ht],this[mi],(t,e)=>this[yr](t,e))}[yr](t,e){this[Ds]&&this[Ht]==="r+"&&t&&t.code==="ENOENT"?(this[Ht]="w",this[mn]()):t?this[_r](t):(this[de]=e,this.emit("open",e),this[kn]||this[za]())}end(t,e){return t&&this.write(t,e),this[oi]=!0,!this[kn]&&!this[At].length&&typeof this[de]=="number"&&this[pr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[oi]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[kn]||this[At].length?(this[At].push(t),this[ys]=!0,!1):(this[kn]=!0,this[ks](t),!0)}[ks](t){Xe.write(this[de],t,0,t.length,this[un],(e,r)=>this[pr](e,r))}[pr](t,e){t?this[_r](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[At].length?this[za]():(this[kn]=!1,this[oi]&&!this[Fa]?(this[Fa]=!0,this[mt](),this.emit("finish")):this[ys]&&(this[ys]=!1,this.emit("drain"))))}[za](){if(this[At].length===0)this[oi]&&this[pr](null,0);else if(this[At].length===1)this[ks](this[At].pop());else{let t=this[At];this[At]=[],Im(this[de],t,this[un],(e,r)=>this[pr](e,r))}}[mt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Ku=class extends Ks{[mn](){let t;if(this[Ds]&&this[Ht]==="r+")try{t=Xe.openSync(this[gt],this[Ht],this[mi])}catch(e){if(e?.code==="ENOENT")return this[Ht]="w",this[mn]();throw e}else t=Xe.openSync(this[gt],this[Ht],this[mi]);this[yr](null,t)}[mt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Xe.closeSync(t),this.emit("close")}}[ks](t){let e=!0;try{this[pr](null,Xe.writeSync(this[de],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[mt]()}catch{}}}},Rm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),km=t=>!!t.sync&&!!t.file,Dm=t=>!t.sync&&!!t.file,Pm=t=>!!t.sync&&!t.file,Om=t=>!t.sync&&!t.file,Lm=t=>!!t.file,Nm=t=>Rm.get(t)||t,Cc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Nm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ai=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let h=Cc(c);if(o?.(h,d),km(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,d)}else if(Dm(h)){let x=e(h,d);return u?x.then(()=>u(),u):x}else if(Pm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,d)}else if(Om(h)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(h,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Fm=Bm.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},Fm)),zm=Fn.concat,pu=Object.getOwnPropertyDescriptor(Fn,"concat"),Um=t=>t,Ha=pu?.writable===!0||pu?.set!==void 0?t=>{Fn.concat=t?Um:zm}:t=>{},zn=Symbol("_superWrite"),Es=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"}},ja=Symbol("flushFlag"),Rc=class extends Gn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof xu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new xu[e](t)}catch(r){throw new Es(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 Es(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ac(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Fn.alloc(0),{[ja]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[zn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Fn.from(t,e)),this.#e)return;ac(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Ha(!0);let d;try{let h=typeof t[ja]=="number"?t[ja]:this.#r;d=this.#t._processChunk(t,h),Ha(!1)}catch(h){Ha(!1),this.#o(new Es(h,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Es(h,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let h=d[0];u=this[zn](Fn.from(h));for(let x=1;x<d.length;x++)u=this[zn](d[x])}else u=this[zn](Fn.from(d));return r&&r(),u}},Vu=class extends Rc{#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),ac(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},Gm=class extends Vu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[zn](t){return this.#e?(this.#e=!1,t[9]=255,super[zn](t)):super[zn](t)}},qm=class extends Vu{constructor(t){super(t,"Unzip")}},Ju=class extends Rc{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)}},Hm=class extends Ju{constructor(t){super(t,"BrotliCompress")}},jm=class extends Ju{constructor(t){super(t,"BrotliDecompress")}},Zu=class extends Rc{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)}},Wm=class extends Zu{constructor(t){super(t,"ZstdCompress")}},Km=class extends Zu{constructor(t){super(t,"ZstdDecompress")}},$m=(t,e)=>{if(Number.isSafeInteger(t))t<0?Jm(t,e):Vm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Vm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Jm=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Yu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Xu(o))}},Zm=t=>{let e=t[0],r=e===128?Xm(t.subarray(1,t.length)):e===255?Ym(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},Ym=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=Yu(c):c===0?d=c:(i=!0,d=Xu(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Xm=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},Yu=t=>(255^t)&255,Xu=t=>(255^t)+1&255,Qm={};fm(Qm,{code:()=>kc,isCode:()=>Ps,isName:()=>ew,name:()=>$s,normalFsTypes:()=>Qu});var Ps=t=>$s.has(t),ew=t=>kc.has(t),Qu=new Set(["0","","1","2","3","4","5","6","7","D"]),$s=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"]]),kc=new Map(Array.from($s).map(t=>[t[1],t[0]])),Un=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Dn(t,e+156,1),c=Qu.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??Dn(t,e,100),this.mode=d?.mode??u?.mode??fn(t,e+100,8),this.uid=d?.uid??u?.uid??fn(t,e+108,8),this.gid=d?.gid??u?.gid??fn(t,e+116,8),this.size=d?.size??u?.size??fn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Wa(t,e+136,12),this.cksum=fn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Ps(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Dn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Dn(t,e+265,32),this.gname=d?.gname??u?.gname??Dn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??fn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let x=Dn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Dn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=r?.atime??i?.atime??Wa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Wa(t,e+488,12)}let h=256;for(let x=e;x<e+148;x++)h+=t[x];for(let x=e+156;x<e+512;x++)h+=t[x];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="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=tw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Pn(t,e,100,o)||this.needPax,this.needPax=hn(t,e+100,8,this.mode)||this.needPax,this.needPax=hn(t,e+108,8,this.uid)||this.needPax,this.needPax=hn(t,e+116,8,this.gid)||this.needPax,this.needPax=hn(t,e+124,12,this.size)||this.needPax,this.needPax=Ka(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Pn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Pn(t,e+265,32,this.uname)||this.needPax,this.needPax=Pn(t,e+297,32,this.gname)||this.needPax,this.needPax=hn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=hn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Pn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Pn(t,e+345,155,c)||this.needPax:(this.needPax=Pn(t,e+345,130,c)||this.needPax,this.needPax=Ka(t,e+476,12,this.atime)||this.needPax,this.needPax=Ka(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,hn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:$s.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(kc.get(t));if(Ps(e)||e==="Unsupported")this.#e=e;else if(Ps(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},tw=(t,e)=>{let r=t,i="",o,c=lr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=lr.dirname(r),r=lr.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=lr.join(lr.basename(i),r),i=lr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Dn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Wa=(t,e,r)=>nw(fn(t,e,r)),nw=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?Zm(t.subarray(e,e+r)):iw(t,e,r),rw=t=>isNaN(t)?void 0:t,iw=(t,e,r)=>rw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),sw={12:8589934591,8:2097151},hn=(t,e,r,i)=>i===void 0?!1:i>sw[r]||i<0?($m(i,t.subarray(e,e+r)),!0):(ow(t,e,r,i),!1),ow=(t,e,r,i)=>t.write(aw(i,r),e,r,"ascii"),aw=(t,e)=>cw(Math.floor(t).toString(8),e),cw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ka=(t,e,r,i)=>i===void 0?!1:hn(t,e,r,i.getTime()/1e3),dw=new Array(156).join("\0"),Pn=(t,e,r,i)=>i===void 0?!1:(t.write(i+dw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Gs=class ef{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Un({path:("PaxHeader/"+lw(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
|
|
91
|
-
`).reduce(hw,Object.create(null)),hw=(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},xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Z=xw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),pw=class extends Gn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=Z(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?Z(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=Z(t.path)),t.linkpath&&(t.linkpath=Z(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Vs=(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))},gw=1024*1024,cc=Buffer.from([31,139]),dc=Buffer.from([40,181,47,253]),mw=Math.max(cc.length,dc.length),st=Symbol("state"),On=Symbol("writeEntry"),Ut=Symbol("readEntry"),$a=Symbol("nextEntry"),gu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),ci=Symbol("globalExtendedHeader"),an=Symbol("meta"),mu=Symbol("emitMeta"),pe=Symbol("buffer"),Gt=Symbol("queue"),cn=Symbol("ended"),Va=Symbol("emittedEnd"),Ln=Symbol("emit"),Ae=Symbol("unzip"),vs=Symbol("consumeChunk"),bs=Symbol("consumeChunkSub"),Ja=Symbol("consumeBody"),wu=Symbol("consumeMeta"),_u=Symbol("consumeHeader"),di=Symbol("consuming"),Za=Symbol("bufferConcat"),Ss=Symbol("maybeEnd"),ur=Symbol("writing"),dn=Symbol("aborted"),Is=Symbol("onDone"),Nn=Symbol("sawValidEntry"),As=Symbol("sawNullBlock"),Ts=Symbol("sawEOF"),yu=Symbol("closeStream"),ww=()=>!0,Ii=class extends Mm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Gt]=[];[pe];[Ut];[On];[st]="begin";[an]="";[Tt];[ci];[cn]=!1;[Ae];[dn]=!1;[Nn];[As]=!1;[Ts]=!1;[ur]=!1;[di]=!1;[Va]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Is,()=>{(this[st]==="begin"||this[Nn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Is,t.ondone):this.on(Is,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||gw,this.filter=typeof t.filter=="function"?t.filter:ww;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[yu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Vs(this,t,e,r)}[_u](t,e){this[Nn]===void 0&&(this[Nn]=!1);let r;try{r=new Un(t,e,this[Tt],this[ci])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[As]?(this[Ts]=!0,this[st]==="begin"&&(this[st]="header"),this[Ln]("eof")):(this[As]=!0,this[Ln]("nullBlock"));else if(this[As]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[On]=new pw(r,this[Tt],this[ci]);if(!this[Nn])if(o.remain){let c=()=>{o.invalid||(this[Nn]=!0)};o.on("end",c)}else this[Nn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Ln]("ignoredEntry",o),this[st]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[st]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Ln]("ignoredEntry",o),this[st]=o.remain?"ignore":"header",o.resume()):(o.remain?this[st]="body":(this[st]="header",o.end()),this[Ut]?this[Gt].push(o):(this[Gt].push(o),this[$a]())))}}}[yu](){queueMicrotask(()=>this.emit("close"))}[gu](t){let e=!0;if(!t)this[Ut]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ut]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[$a]()),e=!1);return e}[$a](){do;while(this[gu](this[Gt].shift()));if(this[Gt].length===0){let t=this[Ut];!t||t.flowing||t.size===t.remain?this[ur]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ja](t,e){let r=this[On];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[st]="header",this[On]=void 0,r.end()),o.length}[wu](t,e){let r=this[On],i=this[Ja](t,e);return!this[On]&&r&&this[mu](r),i}[Ln](t,e,r){this[Gt].length===0&&!this[Ut]?this.emit(t,e,r):this[Gt].push([t,e,r])}[mu](t){switch(this[Ln]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Gs.parse(this[an],this[Tt],!1);break;case"GlobalExtendedHeader":this[ci]=Gs.parse(this[an],this[ci],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[an].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[an].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[dn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[dn])return r?.(),!1;if((this[Ae]===void 0||this.brotli===void 0&&this[Ae]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<mw)return this[pe]=t,r?.(),!0;for(let d=0;this[Ae]===void 0&&d<cc.length;d++)t[d]!==cc[d]&&(this[Ae]=!1);let o=!1;if(this[Ae]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<dc.length;d++)if(t[d]!==dc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ae]===!1&&c)if(t.length<512)if(this[cn])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new Un(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ae]===void 0||this[Ae]===!1&&(this.brotli||o)){let d=this[cn];this[cn]=!1,this[Ae]=this[Ae]===void 0?new qm({}):o?new Km({}):new jm({}),this[Ae].on("data",h=>this[vs](h)),this[Ae].on("error",h=>this.abort(h)),this[Ae].on("end",()=>{this[cn]=!0,this[vs]()}),this[ur]=!0;let u=!!this[Ae][d?"end":"write"](t);return this[ur]=!1,r?.(),u}}this[ur]=!0,this[Ae]?this[Ae].write(t):this[vs](t),this[ur]=!1;let i=this[Gt].length>0?!1:this[Ut]?this[Ut].flowing:!0;return!i&&this[Gt].length===0&&this[Ut]?.once("drain",()=>this.emit("drain")),r?.(),i}[Za](t){t&&!this[dn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Ss](){if(this[cn]&&!this[Va]&&!this[dn]&&!this[di]){this[Va]=!0;let t=this[On];if(t&&t.blockRemain){let e=this[pe]?this[pe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[pe]&&t.write(this[pe]),t.end()}this[Ln](Is)}}[vs](t){if(this[di]&&t)this[Za](t);else if(!t&&!this[pe])this[Ss]();else if(t){if(this[di]=!0,this[pe]){this[Za](t);let e=this[pe];this[pe]=void 0,this[bs](e)}else this[bs](t);for(;this[pe]&&this[pe]?.length>=512&&!this[dn]&&!this[Ts];){let e=this[pe];this[pe]=void 0,this[bs](e)}this[di]=!1}(!this[pe]||this[cn])&&this[Ss]()}[bs](t){let e=0,r=t.length;for(;e+512<=r&&!this[dn]&&!this[Ts];)switch(this[st]){case"begin":case"header":this[_u](t,e),e+=512;break;case"ignore":case"body":e+=this[Ja](t,e);break;case"meta":e+=this[wu](t,e);break;default:throw new Error("invalid state: "+this[st])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[dn]||(this[Ae]?(t&&this[Ae].write(t),this[Ae].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ss]())),this}},wi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},_w=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},tf=(t,e)=>{let r=new Map(e.map(c=>[wi(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||Cm(c).root||".",h;if(c===u)h=!1;else{let x=r.get(c);h=x!==void 0?x:o(Tm(c),u)}return r.set(c,h),h};t.filter=i?(c,d)=>i(c,d)&&o(wi(c)):c=>o(wi(c))},yw=t=>{let e=new Ii(t),r=t.file,i;try{i=mr.openSync(r,"r");let o=mr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=mr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let h=mr.readSync(i,u,0,c,d);if(h===0)break;d+=h,e.write(u.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{mr.closeSync(i)}catch{}}},Ew=(t,e)=>{let r=new Ii(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),mr.stat(o,(u,h)=>{if(u)d(u);else{let x=new Tc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},Er=Ai(yw,Ew,t=>new Ii(t),t=>new Ii(t),(t,e)=>{e?.length&&tf(t,e),t.noResume||_w(t)}),nf=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:bw,parse:vu}=vw,Dc=t=>{let e="",r=vu(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=vu(t)}return[e,t]},Js=["|","<",">","?",":"],Pc=Js.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Sw=new Map(Js.map((t,e)=>[t,Pc[e]])),Iw=new Map(Pc.map((t,e)=>[t,Js[e]])),bu=t=>Js.reduce((e,r)=>e.split(r).join(Sw.get(r)),t),Aw=t=>Pc.reduce((e,r)=>e.split(r).join(Iw.get(r)),t),rf=(t,e)=>e?(t=Z(t).replace(/^\.(\/|$)/,""),wi(e)+"/"+t):Z(t),Tw=16*1024*1024,Su=Symbol("process"),Iu=Symbol("file"),Au=Symbol("directory"),lc=Symbol("symlink"),Tu=Symbol("hardlink"),li=Symbol("header"),Os=Symbol("read"),uc=Symbol("lstat"),Ls=Symbol("onlstat"),fc=Symbol("onread"),hc=Symbol("onreadlink"),xc=Symbol("openfile"),pc=Symbol("onopenfile"),xn=Symbol("close"),Hs=Symbol("mode"),gc=Symbol("awaitDrain"),Ya=Symbol("ondrain"),Rt=Symbol("prefix"),sf=class extends Gn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Cc(e);super(),this.path=Z(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Tw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Z(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Z(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]=Dc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Aw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Z(r.absolute||Eu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Ls](o):this[uc]()}warn(t,e,r={}){return Vs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[uc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ls](e)})}[Ls](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=kw(t),this.emit("stat",t),this[Su]()}[Su](){switch(this.type){case"File":return this[Iu]();case"Directory":return this[Au]();case"SymbolicLink":return this[lc]();default:return this.end()}}[Hs](t){return nf(t,this.type==="Directory",this.portable)}[Rt](t){return rf(t,this.prefix)}[li](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Un({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Hs](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 Gs({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)}[Au](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[li](),this.end()}[lc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[hc](e)})}[hc](t){this.linkpath=Z(t),this[li](),this.end()}[Tu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Z(Eu.relative(this.cwd,t)),this.stat.size=0,this[li](),this.end()}[Iu](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[Tu](e);this.linkCache.set(t,this.absolute)}if(this[li](),this.stat.size===0)return this.end();this[xc]()}[xc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){if(this.fd=t,this.#e)return this[xn]();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[Os]()}[Os](){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[xn](()=>this.emit("error",c));this[fc](d)})}[xn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[fc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[xn](()=>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[xn](()=>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[Ya]():this[gc](()=>this[Ya]())}[gc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Ya](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[xn](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[Os]()}},Cw=class extends sf{sync=!0;[uc](){this[Ls](Ct.lstatSync(this.absolute))}[lc](){this[hc](Ct.readlinkSync(this.absolute))}[xc](){this[pc](Ct.openSync(this.absolute,"r"))}[Os](){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[fc](d),t=!1}finally{if(t)try{this[xn](()=>{})}catch{}}}[gc](t){t()}[xn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},Rw=class extends Gn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Vs(this,t,e,r)}constructor(t,e={}){let r=Cc(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=Z(t.path),this.mode=t.mode!==void 0?this[Hs](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?Z(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Dc(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 Un({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new Gs({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Rt](t){return rf(t,this.prefix)}[Hs](t){return nf(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},kw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Dw=class wr{tail;head;length=0;static create(e=[]){return new wr(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)Ow(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Lw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new wr;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new wr;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new wr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new wr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let 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=Pw(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 Pw(t,e,r){let i=e,o=e?e.next:t.head,c=new Oc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Ow(t,e){t.tail=new Oc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Lw(t,e){t.head=new Oc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Oc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Ru=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},ku=Buffer.alloc(1024),Ns=Symbol("onStat"),ui=Symbol("ended"),xt=Symbol("queue"),fi=Symbol("pendingLinks"),ln=Symbol("current"),Mn=Symbol("process"),hi=Symbol("processing"),Cs=Symbol("processJob"),pt=Symbol("jobs"),Xa=Symbol("jobDone"),Ms=Symbol("addFSEntry"),Du=Symbol("addTarEntry"),mc=Symbol("stat"),wc=Symbol("readdir"),Bs=Symbol("onreaddir"),Fs=Symbol("pipe"),Pu=Symbol("entry"),Qa=Symbol("entryOpt"),zs=Symbol("writeEntryClass"),of=Symbol("write"),ec=Symbol("ondrain"),Zs=class extends Gn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[zs];onWriteEntry;[xt];[fi]=new Map;[pt]=0;[hi]=!1;[ui]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Z(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[zs]=sf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new Gm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Hm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Wm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[ec]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ec]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[xt]=new Dw,this[pt]=0,this.jobs=Number(t.jobs)||4,this[hi]=!1,this[ui]=!1}[of](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[ui]=!0,this[Mn](),r&&r(),this}write(t){if(this[ui])throw new Error("write after end");return typeof t=="string"?this[Ms](t):this[Du](t),this.flowing}[Du](t){let e=Z(Cu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ru(t.path,e);r.entry=new Rw(t,this[Qa](r)),r.entry.on("end",()=>this[Xa](r)),this[pt]+=1,this[xt].push(r)}this[Mn]()}[Ms](t){let e=Z(Cu.resolve(this.cwd,t));this[xt].push(new Ru(t,e)),this[Mn]()}[mc](t){t.pending=!0,this[pt]+=1;let e=this.follow?"stat":"lstat";qs[e](t.absolute,(r,i)=>{t.pending=!1,this[pt]-=1,r?this.emit("error",r):this[Ns](t,i)})}[Ns](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[ln])this[Cs](t);else{let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);i?i.push(t):this[fi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Mn]()}[wc](t){t.pending=!0,this[pt]+=1,qs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[pt]-=1,e)return this.emit("error",e);this[Bs](t,r)})}[Bs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Mn]()}[Mn](){if(!this[hi]){this[hi]=!0;for(let t=this[xt].head;t&&this[pt]<this.jobs;t=t.next)if(this[Cs](t.value),t.value.ignore){let e=t.next;this[xt].removeNode(t),t.next=e}this[hi]=!1,this[ui]&&this[xt].length===0&&this[pt]===0&&(this.zip?this.zip.end(ku):(super.write(ku),super.end()))}}get[ln](){return this[xt]&&this[xt].head&&this[xt].head.value}[Xa](t){this[xt].shift(),this[pt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);if(i){this[fi].delete(r);for(let o of i)o.pending=!1,this[Cs](o)}}this[Mn]()}[Cs](t){if(t.pending&&t.pendingLink&&t===this[ln]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[ln]&&!t.piped&&this[Fs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ns](t,e):this[mc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Bs](t,e):this[wc](t),!t.readdir)return}if(t.entry=this[Pu](t),!t.entry){t.ignore=!0;return}t===this[ln]&&!t.piped&&this[Fs](t)}}}[Qa](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Pu](t){this[pt]+=1;try{return new this[zs](t.path,this[Qa](t)).on("end",()=>this[Xa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ec](){this[ln]&&this[ln].entry&&this[ln].entry.resume()}[Fs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ms](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={}){Vs(this,t,e,r)}},Lc=class extends Zs{sync=!0;constructor(t){super(t),this[zs]=Cw}pause(){}resume(){}[mc](t){let e=this.follow?"statSync":"lstatSync";this[Ns](t,qs[e](t.absolute))}[wc](t){this[Bs](t,qs.readdirSync(t.absolute))}[Fs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ms](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[of](i)})}},Nw=(t,e)=>{let r=new Lc(t),i=new Ku(t.file,{mode:t.mode||438});r.pipe(i),af(r,e)},Mw=(t,e)=>{let r=new Zs(t),i=new Ks(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 cf(r,e).catch(c=>r.emit("error",c)),o},af=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({file:$u.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},cf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Er({file:$u.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Bw=(t,e)=>{let r=new Lc(t);return af(r,e),r},Fw=(t,e)=>{let r=new Zs(t);return cf(r,e).catch(i=>r.emit("error",i)),r},oA=Ai(Nw,Mw,Bw,Fw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Uw=process.env.__FAKE_PLATFORM__||process.platform,ff=Uw==="win32",{O_CREAT:hf,O_NOFOLLOW:Ou,O_TRUNC:xf,O_WRONLY:pf}=uf.constants,gf=Number(process.env.__FAKE_FS_O_FILENAME__)||uf.constants.UV_FS_O_FILEMAP||0,Gw=ff&&!!gf,qw=512*1024,Hw=gf|xf|hf|pf,Lu=!ff&&typeof Ou=="number"?Ou|xf|hf|pf:null,mf=Lu!==null?()=>Lu:Gw?t=>t<qw?Hw:"w":()=>"w",_c=(t,e,r)=>{try{return Ys.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},js=(t,e,r,i)=>{Ys.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},jw=(t,e,r,i,o)=>{if(e.isDirectory())wf(_i.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=_i.resolve(t,e.name);js(d,r,i,o)});else{let c=_i.resolve(t,e.name);js(c,r,i,o)}},wf=(t,e,r,i)=>{Ys.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 d=c.length,u=null,h=x=>{if(!u){if(x)return i(u=x);if(--d===0)return js(t,e,r,i)}};for(let x of c)jw(t,x,e,r,h)})},Ww=(t,e,r,i)=>{e.isDirectory()&&_f(_i.resolve(t,e.name),r,i),_c(_i.resolve(t,e.name),r,i)},_f=(t,e,r)=>{let i;try{i=Ys.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return _c(t,e,r);throw c}for(let o of i)Ww(t,o,e,r);return _c(t,e,r)},yf=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},Xs=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"}},$w=(t,e)=>{nt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new yf(t,r?.code||"ENOTDIR")),e(r)})},Vw=(t,e,r)=>{t=Z(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,h=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,m=e.unlink,w=Z(e.cwd),b=(v,I)=>{v?r(v):I&&h?wf(I,d,u,A=>b(A)):c?nt.chmod(t,o,r):r()};if(t===w)return $w(t,b);if(x)return Kw.mkdir(t,{mode:o,recursive:!0}).then(v=>b(null,v??void 0),b);let _=Z(Ws.relative(w,t)).split("/");yc(w,_,o,m,w,void 0,b)},yc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),h=Z(Ws.resolve(t+"/"+u));nt.mkdir(h,r,Ef(h,e,r,i,o,c,d))},Ef=(t,e,r,i,o,c,d)=>u=>{u?nt.lstat(t,(h,x)=>{if(h)h.path=h.path&&Z(h.path),d(h);else if(x.isDirectory())yc(t,e,r,i,o,c,d);else if(i)nt.unlink(t,m=>{if(m)return d(m);nt.mkdir(t,r,Ef(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new Xs(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,yc(t,e,r,i,o,c,d))},Jw=t=>{let e=!1,r;try{e=nt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new yf(t,r??"ENOTDIR")}},Zw=(t,e)=>{t=Z(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),h=e.preserve,x=e.unlink,m=Z(e.cwd),w=v=>{v&&u&&_f(v,c,d),o&&nt.chmodSync(t,i)};if(t===m)return Jw(m),w();if(h)return w(nt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let b=Z(Ws.relative(m,t)).split("/"),_;for(let v=b.shift(),I=m;v&&(I+="/"+v);v=b.shift()){I=Z(Ws.resolve(I));try{nt.mkdirSync(I,i),_=_||I}catch{let A=nt.lstatSync(I);if(A.isDirectory())continue;if(x){nt.unlinkSync(I),nt.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new Xs(I,I+"/"+b.join("/"))}}return w(_)},tc=Object.create(null),Nu=1e4,fr=new Set,Yw=t=>{fr.has(t)?fr.delete(t):tc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),fr.add(t);let e=tc[t],r=fr.size-Nu;if(r>Nu/10){for(let i of fr)if(fr.delete(i),delete tc[i],--r<=0)break}return e},Xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Qw=Xw==="win32",e_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=vf(i,r)),e.push(r||"/"),e},[]),t_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Qw?["win32 parallelization disabled"]:t.map(i=>wi(vf(Yw(i))));let r=new Set(t.map(i=>e_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let h=d[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},n_=()=>process.umask(),Mu=Symbol("onEntry"),Ec=Symbol("checkFs"),Bu=Symbol("checkFs2"),vc=Symbol("isReusable"),ot=Symbol("makeFs"),bc=Symbol("file"),Sc=Symbol("directory"),Us=Symbol("link"),Fu=Symbol("symlink"),zu=Symbol("hardlink"),gi=Symbol("ensureNoSymlink"),Uu=Symbol("unsupported"),Gu=Symbol("checkPath"),nc=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),Fe=Symbol("onError"),Rs=Symbol("pending"),qu=Symbol("pend"),hr=Symbol("unpend"),rc=Symbol("ended"),ic=Symbol("maybeClose"),Ic=Symbol("skip"),yi=Symbol("doChown"),Ei=Symbol("uid"),vi=Symbol("gid"),bi=Symbol("checkedCwd"),r_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Si=r_==="win32",i_=1024,s_=(t,e)=>{if(!Si)return re.unlink(t,e);let r=t+".DELETE."+lf(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},o_=t=>{if(!Si)return re.unlinkSync(t);let e=t+".DELETE."+lf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Hu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Nc=class extends Ii{[rc]=!1;[bi]=!1;[Rs]=0;reservations=new t_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[rc]=!0,this[ic]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:i_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Si,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Z(Pe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:n_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[Mu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[ic](){this[rc]&&this[Rs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[nc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Dc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Si&&/^[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=Pe.posix.dirname(t.path),h=Pe.posix.normalize(Pe.posix.join(u,d.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Gu](t){let e=Z(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Z(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[nc](t,"path")||!this[nc](t,"linkpath"))return!1;if(t.absolute=Pe.isAbsolute(t.path)?Z(Pe.resolve(t.path)):Z(Pe.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:Z(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}=Pe.win32.parse(String(t.absolute));t.absolute=i+bu(String(t.absolute).slice(i.length));let{root:o}=Pe.win32.parse(t.path);t.path=o+bu(t.path.slice(o.length))}return!0}[Mu](t){if(!this[Gu](t))return t.resume();switch(zw.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[Ec](t);default:return this[Uu](t)}}[Fe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[hr](),e.resume())}[pn](t,e,r){Vw(Z(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[yi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Ei](t){return Hu(this.uid,t.uid,this.processUid)}[vi](t){return Hu(this.gid,t.gid,this.processGid)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Ks(String(t.absolute),{flags:mf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Fe](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Fe](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[Fe](h,t):this[hr](),e()})};i.on("finish",()=>{let u=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;re.futimes(h,x,m,w=>w?re.utimes(u,x,m,b=>c(b&&w)):c())}if(typeof h=="number"&&this[yi](t)){o++;let x=this[Ei](t),m=this[vi](t);typeof x=="number"&&typeof m=="number"&&re.fchown(h,x,m,w=>w?re.chown(u,x,m,b=>c(b&&w)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[Fe](u,t),e()}),t.pipe(d)),d.pipe(i)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[pn](String(t.absolute),r,i=>{if(i){this[Fe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[hr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[yi](t)&&(o++,re.chown(String(t.absolute),Number(this[Ei](t)),Number(this[vi](t)),c)),c()})}[Uu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Fu](t,e){let r=Z(Pe.relative(this.cwd,Pe.resolve(Pe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[gi](t,this.cwd,r,()=>this[Us](t,String(t.linkpath),"symlink",e),i=>{this[Fe](i,t),e()})}[zu](t,e){let r=Z(Pe.resolve(this.cwd,String(t.linkpath))),i=Z(String(t.linkpath)).split("/");this[gi](t,this.cwd,i,()=>this[Us](t,r,"link",e),o=>{this[Fe](o,t),e()})}[gi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Pe.resolve(e,c);re.lstat(d,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new Xs(d,Pe.resolve(d,r.join("/"))));this[gi](t,d,r,i,o)})}[qu](){this[Rs]++}[hr](){this[Rs]--,this[ic]()}[Ic](t){this[hr](),t.resume()}[vc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Si}[Ec](t){this[qu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Bu](t,r))}[Bu](t,e){let r=d=>{e(d)},i=()=>{this[pn](this.cwd,this.dmode,d=>{if(d){this[Fe](d,t),r();return}this[bi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=Z(Pe.dirname(String(t.absolute)));if(d!==this.cwd)return this[pn](d,this.dmode,u=>{if(u){this[Fe](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[Ic](t),r();return}if(d||this[vc](t,u))return this[ot](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=m=>this[ot](m??null,t,r);return h?re.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),h=>this[ot](h??null,t,r))}if(t.absolute===this.cwd)return this[ot](null,t,r);s_(String(t.absolute),h=>this[ot](h??null,t,r))})};this[bi]?o():i()}[ot](t,e,r){if(t){this[Fe](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[bc](e,r);case"Link":return this[zu](e,r);case"SymbolicLink":return this[Fu](e,r);case"Directory":case"GNUDumpDir":return this[Sc](e,r)}}[Us](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Fe](o,t):(this[hr](),t.resume()),i()})}},xi=t=>{try{return[null,t()]}catch(e){return[e,null]}},bf=class extends Nc{sync=!0;[ot](t,e){return super[ot](t,e,()=>{})}[Ec](t){if(!this[bi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[Fe](o,t);this[bi]=!0}if(t.absolute!==this.cwd){let o=Z(Pe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[pn](o,this.dmode);if(c)return this[Fe](c,t)}}let[e,r]=xi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Ic](t);if(e||this[vc](t,r))return this[ot](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?xi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ot](d,t)}let[o]=xi(()=>re.rmdirSync(String(t.absolute)));this[ot](o,t)}let[i]=t.absolute===this.cwd?[]:xi(()=>o_(String(t.absolute)));this[ot](i,t)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{re.closeSync(o)}catch(h){u=h}(d||u)&&this[Fe](d||u,t),e()},o;try{o=re.openSync(String(t.absolute),mf(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[Fe](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,h=t.mtime;try{re.futimesSync(o,u,h)}catch(x){try{re.utimesSync(String(t.absolute),u,h)}catch{d=x}}}if(this[yi](t)){let u=this[Ei](t),h=this[vi](t);try{re.fchownSync(o,Number(u),Number(h))}catch(x){try{re.chownSync(String(t.absolute),Number(u),Number(h))}catch{d=d||x}}}i(d)})}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[pn](String(t.absolute),r);if(i){this[Fe](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[yi](t))try{re.chownSync(String(t.absolute),Number(this[Ei](t)),Number(this[vi](t)))}catch{}e(),t.resume()}[pn](t,e){try{return Zw(Z(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[gi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Pe.resolve(c,d);let[u,h]=xi(()=>re.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new Xs(c,Pe.resolve(e,r.join("/"))))}i()}[Us](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Fe](c,t)}}},a_=t=>{let e=new bf(t),r=t.file,i=df.statSync(r),o=t.maxReadSize||16*1024*1024;new Am(r,{readSize:o,size:i.size}).pipe(e)},c_=(t,e)=>{let r=new Nc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),df.stat(o,(u,h)=>{if(u)d(u);else{let x=new Tc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},Sf=Ai(a_,c_,t=>new bf(t),t=>new Nc(t),(t,e)=>{e?.length&&tf(t,e)}),d_=(t,e)=>{let r=new Lc(t),i=!0,o,c;try{try{o=et.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=et.openSync(t.file,"w+");else throw h}let d=et.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let m=0,w=0;m<512;m+=w){if(w=et.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let h=new Un(u);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,l_(t,r,c,o,e)}finally{if(i)try{et.closeSync(o)}catch{}}},l_=(t,e,r,i,o)=>{let c=new Ku(t.file,{fd:i,start:r});e.pipe(c),f_(e,o)},u_=(t,e)=>{e=Array.from(e);let r=new Zs(t),i=(o,c,d)=>{let u=(b,_)=>{b?et.close(o,v=>d(b)):d(null,_)},h=0;if(c===0)return u(null,0);let x=0,m=Buffer.alloc(512),w=(b,_)=>{if(b||_===void 0)return u(b);if(x+=_,x<512&&_)return et.read(o,m,x,m.length-x,h+x,w);if(h===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,h);let v=new Un(m);if(!v.cksumValid)return u(null,h);let I=512*Math.ceil((v.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return u(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,et.read(o,m,0,512,h,w)};et.read(o,m,0,512,h,w)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(h,x)=>{if(h&&h.code==="ENOENT"&&d==="r+")return d="w+",et.open(t.file,d,u);if(h||!x)return c(h);et.fstat(x,(m,w)=>{if(m)return et.close(x,()=>c(m));i(x,w.size,(b,_)=>{if(b)return c(b);let v=new Ks(t.file,{fd:x,start:_});r.pipe(v),v.on("error",c),v.on("close",o),h_(r,e)})})};et.open(t.file,d,u)})},f_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({file:If.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},h_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Er({file:If.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},pi=Ai(d_,u_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Lm(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")}),EA=Ai(pi.syncFile,pi.asyncFile,pi.syncNoFile,pi.asyncNoFile,(t,e=[])=>{pi.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))};rn();var wt={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",DELETE:"_agent/delete"};function Qs(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Af(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function eo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Tf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Cf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function vr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}je();ne();ke();je();function jt(t,e){if(Qs(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function to(t){return t.startsWith("http://")||t.startsWith("https://")}function no(t){return t.endsWith("/")?t.slice(0,-1):t}je();ne();var ro="1008033",Rf="1289";var kf="pbbp2",Df="https://www.coze.cn",Pf="/api/coze_claw/resource/get_frontier_key",g_="https://www.coze.cn",m_="wss://frontier.coze.cn";function io(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??g_}function Of(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??m_}function br(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 Ci(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ti=U("handshake");async function Mc(t){let e=io(t.endpoint),r=t.timeoutMs??1e4,i=`${no(e)}${Pf}?aid=${encodeURIComponent(ro)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...br(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Ti.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let w=m.data??{},b=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!b||!_){let v=JSON.stringify(m).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Ti.info("handshake ok",{remoteDeviceId:_,logid:h,traceId:x}),{accessKey:b,deviceId:_}}catch(u){if(u instanceof C)throw Ti.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ti.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let h=u.cause;throw Ti.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var Bc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",_t="auto",Lf=15e4;function Nf(t){return{model:Fc(t.model)??_t,...t.modelToken?{modelToken:t.modelToken}:{}}}function Mf(t){return!t||t===_t}var w_=new Set(["auto","\u81EA\u52A8"]);function Fc(t){let e=t?.trim();if(e)return w_.has(e.toLowerCase())?_t:e}function Bf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Bc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||_t;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||_t}"`):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="${Bc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??Lf;e.push("-c",`model_context_window=${r}`)}return e}function zf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function zc(t,e){let{ttEnv:r,usePpe:i}=Ci(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=zc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
-
`)}}function Uc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Gf(t,e,r){if(!t.modelToken)return null;let i=t.model||_t,o=zc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Bc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Lf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}function qf(t,e,r){if(!t.modelToken)return[];let i=zc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var Oe=U("agent-handlers"),Hf=5*1024*1024,S_=1,I_=6,A_=new Set(["node_modules",".git",".coze","dist","build",".next"]),so=class{constructor(e){this.opts=e}opts;async listSkills(e){jt(e._meta,"_agent/listSkills");let r=vr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],d=[];for(let u of c){let h=Dt(o,u.relPath,"SKILL.md");await E_(h).then(m=>m.isFile()).catch(()=>!1)&&d.push(D_(u))}return{skills:d}}async addSkills(e){jt(e._meta,"_agent/addSkills");let r=vr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((h,x)=>[h.skillId,x])),u=[];for(let h of o){let x=await $c({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});Vc(c,d,x),u.push(h)}return await cs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){jt(e._meta,"_agent/removeSkills");let r=vr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let h=Dt(i.workspace,u.relPath);await y_(h,{recursive:!0,force:!0}),Oe.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await cs(r,d),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 d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Oe.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let h=c.downstream;c.downstream=void 0,Oe.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),h.stop(r).catch(x=>Oe.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 Oe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Ge(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Oe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await sr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Oe.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 Ye(i),Oe.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Ge(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ye(i),Oe.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}):(Oe.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(jt(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Fc(e.model)??_t,i=await Ge(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 Ye(i),Oe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Oe.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=>Oe.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 h=o.sessions.get(d);h?.downstream&&(await h.downstream.stop(`switchModel: ${r}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(c),Oe.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(jt(e._meta,wt.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${wt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,wt.RESET),await this.runDetailSync(e.agentId,wt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Oe.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 ei(e,o)}async clearPersistedAcpSessionIds(e){let r=await Ge(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 Ye(r)}async repairAgent(e){if(jt(e._meta,wt.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${wt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${wt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Oe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,wt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Oe.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Oe.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){jt(e._meta,"_agent/getFileTree");let r=e._meta,i=vr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await Gc(d).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Qr(d,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=q_(e.depth);return u.isDirectory()?{tree:await G_(o,d,c,h)}:{tree:[{name:H_(c),path:Zf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){jt(e._meta,"_agent/getFileContent");let r=vr(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 Gc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Qr(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Hf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Hf})`);let d=await jf(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 Ge(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=jc(e,r||"."),o=Kc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Wf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Ge(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 T_(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 C_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var R_=3e4,k_=50*1024*1024,Sr=3e4;async function $c(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,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=T_(o.skillName),h=C_(i),x=Dt(h,u),m=Dt(r,x);if(await qc(m,{recursive:!0}),c){let b=Buffer.from(o.content,"utf8");Ri(b.length),await Hc(Dt(m,"SKILL.md"),b,"utf8")}else{let b=await P_(o.downloadUrl);L_(b)?await F_(b,m):N_(b)?await M_(b,m):await Hc(Dt(m,"SKILL.md"),b.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Oe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),w}function Vc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function D_(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 P_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ri(e);let r=O_(t);return Ri(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await jf(e);return Ri(r.length),r}if(to(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),R_);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 Ri(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 Ri(t){if(t>k_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function O_(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 L_(t){return t.length>=2&&t[0]===31&&t[1]===139}function N_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Wc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function M_(t,e){let r,i;try{r=new Vf.default(t),i=r.getEntries()}catch(d){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||Wc(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(x=>x===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=d.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=B_(i),c=jc(e);for(let d of i){if(Wc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=jc(e,u),x=Kc(c,h);if(x.startsWith("..")||x==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await qc(h,{recursive:!0});continue}await qc(v_(h),{recursive:!0});let m;try{m=d.getData()}catch(w){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await Hc(h,m)}}function B_(t){let e;for(let r of t){let i=r.entryName;if(!i||Wc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function F_(t,e){await z_(t);let r=Sf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${Sr}ms)`))},Sr);try{await $f(Kf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${Sr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function z_(t){let e=[],r=Er({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 C("IPC_BAD_REQUEST",`tar list timeout (${Sr}ms)`))},Sr);try{await $f(Kf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${Sr}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var U_=5e3;async function G_(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 __(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(A_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=U_){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=Dt(e,u.name),x=b_(Dt(r,u.name)),m=null;try{m=await Gc(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let w={name:u.name,path:Zf(Kc(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(w.children=await Jf(t,h,x,i-1,o)),d.push(w)}return d.sort((u,h)=>u.isDir!==h.isDir?u.isDir?-1:1:u.name.localeCompare(h.name)),d}function q_(t){return!t||t<=0?S_:Math.min(t,I_)}function H_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Zf(t){return t.split(Wf).join("/")}ne();import{readFileSync as D2}from"node:fs";import{dirname as O2,join as L2}from"node:path";import{fileURLToPath as M2}from"node:url";var Ir="0.1.103-alpha.2";var wn=U("agent-health-reporter"),j_=1e4,ki=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??j_}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()}),wn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),wn.info("heartbeat stopped"))}async tick(){if(this.inFlight){wn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){wn.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=W_(d);if(!u)continue;let h={agentId:d.agentId,status:u};d.patToken&&(h.patToken=d.patToken),d.accountId&&(h.accountId=d.accountId),r.push(h)}if(r.length===0)return;let i={agents:r,bridgeVersion:Ir,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(d){wn.warn("heartbeat batch send failed",{count:r.length,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(wn.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){wn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){wn.warn("onTickEnd hook failed",{err:String(r)})}}};function W_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as qy,mkdir as po,rm as Hy,stat as jy,writeFile as Wy}from"node:fs/promises";import{homedir as Ky}from"node:os";import{join as T0}from"node:path";nn();import{existsSync as ly}from"node:fs";import{release as uy}from"node:os";import{basename as fy,isAbsolute as hy}from"node:path";function Di(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Ar(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Tr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function _n(t,e){return{jsonrpc:"2.0",id:t,error:e}}je();var oo=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},X={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,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 ao(t){return!("method"in t)&&"id"in t}var K_={AGENT_NOT_FOUND:X.AGENT_NOT_FOUND,AGENT_BUSY:X.AGENT_BUSY,AGENT_DISCONNECTED:X.AGENT_DISCONNECTED,AGENT_TIMEOUT:X.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:X.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:X.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:X.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:X.INTERNAL_ERROR,BRIDGE_INTERNAL:X.INTERNAL_ERROR,IPC_AUTH_FAILED:X.INTERNAL_ERROR,IPC_BAD_REQUEST:X.INVALID_REQUEST,METHOD_NOT_FOUND:X.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:X.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:X.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:X.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:X.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:X.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:X.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:X.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:X.FILE_TOO_LARGE,UNSUPPORTED_MIME:X.UNSUPPORTED_MIME,UPLOAD_FAILED:X.UPLOAD_FAILED,UPSTREAM_NOT_READY:X.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:X.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:X.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:X.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:X.AGENT_ENV_NOT_READY};function $_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Pi(t.message)}:typeof t=="string"?Pi(t):typeof t=="object"?J_(t):t}var V_=[[/\/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 Pi(t){let e=t;for(let[r,i]of V_)e=e.replace(r,i);return e}function J_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Pi(i):e[r]=i;return e}function Oi(t){if(t instanceof C){let e=$_(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:K_[t.code]??X.INTERNAL_ERROR,message:Pi(t.message),data:r}}return{code:X.INTERNAL_ERROR,message:Pi(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:d,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function t0(t){return`${JSON.stringify(t)}
|
|
93
|
-
`}var
|
|
94
|
-
`);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(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
|
|
95
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function f0(t,e){if(t.length===0)return;let r=e?.killFn??Ni,i=e?.isAliveFn??Li,o=e?.sleepFn??(u=>new Promise(h=>setTimeout(h,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(h=>i(h));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var dy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function h0(t,e){if(!e)return null;for(let r of dy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function x0(t,e){return h0(t,e)}function p0(t,e){return h0(t,e)}function kr(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function g0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,m=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:kr(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:kr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:kr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:kr(c,!1,e)}}var m0=He("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),xy=200,py=40,gy=He("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),my=He("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),wy=He("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),_y=He("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),yy=He("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Ey=He("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),w0=500;function vy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=w0?t:`${e.slice(0,w0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function by(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function _0(t){try{return ly(t)}catch{return}}function Sy(t,e){return{platform:process.platform,osRelease:uy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:hy(e.command)?_0(e.command):void 0,cwd:e.cwd,cwdExists:_0(e.cwd),envKeys:e.envKeys}}function Iy(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${fy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=U(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new co({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Cr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=i0(process.env,this.opts.agentEnvFile??Y().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=at(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,c0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>xy&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,d0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=Sy(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 C("AGENT_SPAWN_FAILED",Iy(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()));Ni(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Ni(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:yy,phase2GateMs:gy,livenessWindowMs:my,absoluteMaxMs:wy,approvalMaxMs:Ey,suspendThresholdMs:_y,...r};return this.call("session/prompt",e,m0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Ar("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Tr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(_n(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=m0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Di(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let h=r.sessionId;return typeof h=="string"?h:void 0})();return new Promise((h,x)=>{let m={resolve:h,reject:x,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),b={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:kr(0,!1,o),sessionId:u};m.promptTimeout=b;let _=()=>{let v={startedAt:b.startedAt,lastActivityAt:b.lastActivityAt,firstFrameSeen:b.firstFrameSeen,hasActiveTool:b.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:b.suspendedMs,armedAt:b.armedAt,expectedIntervalMs:b.expectedIntervalMs},I=this.now(),A=g0(v,b.cfg,I),T=R=>{b.armedAt=I,b.expectedIntervalMs=R,m.timer=setTimeout(_,R)};if(A.action==="suspend"){b.suspendedMs+=A.suspendedDeltaMs,b.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:b.suspendedMs,...b.sessionId?{sessionId:b.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,...b.sessionId?{sessionId:b.sessionId}:{}}),x(A.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${b.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${b.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...b.sessionId?{sessionId:b.sessionId}:{}}),x(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${b.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(_,b.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(d)}catch(w){m.timer&&clearTimeout(m.timer),this.pending.delete(c),x(w)}})}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(ao(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new 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:vy(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 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(_n(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(_n(e.id,Oi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Qf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=p0(this.framework,by(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(py).join(`
|
|
96
|
-
`),o=x0(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 Ay(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 lo=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Yr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return Ay(e)}};nn();import{mkdtempSync as Ty,rmSync as Cy}from"node:fs";import{tmpdir as Ry}from"node:os";import{join as ky}from"node:path";var uo=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Yr("codex",e.command,i),d=e.isolateCodexHome?Ty(ky(Ry(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Cy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};je();var Dy=3e4,Dr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Dy))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var y0=["default","acceptEdits","plan","auto","bypassPermissions"],E0=["read-only","auto","full-access"];function En(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return y0.includes(e);case"codex":return E0.includes(e);case"openclaw":return!1}}function Xc(t){switch(t){case"claude-code":return y0.join("/");case"codex":return E0.join("/");case"openclaw":return""}}je();ne();ke();function Qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}nn();var vn=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var fo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new vn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Mi(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 Mi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Wt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}yn();ne();import{constants as v0}from"node:fs";import{access as Py}from"node:fs/promises";import{delimiter as Oy,join as Ly}from"node:path";var yt=U("framework-detector"),b0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Ny=[".exe",".cmd",".bat",".ps1"],qn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??at,access:e.access??Py}}async detect(e){let r=b0[e],i=await this.which(r);if(!i)return yt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(b0).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(Oy).filter(Boolean),i=this.env.platform==="win32"?["",...Ny]:[""];for(let o of r)for(let c of i){let d=Ly(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?v0.F_OK:v0.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 yt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return yt.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 yt.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 yt.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?(yt.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}:(yt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return yt.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 yt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||yt.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){yt.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&&(By(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=h=>{c||(c=!0,d&&clearTimeout(d),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{h.kill("SIGKILL"),u(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>u(null)),h.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},My=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function By(t){return t.replace(My,"")}import{homedir as Fy}from"node:os";import{join as zy}from"node:path";yn();Qn();je();Xr();ne();async function A0(){let t=zy(Fy(),".openclaw/openclaw.json");return(await rr(t))?.gateway?.auth?.token??""}var S0=U("openclaw.config"),Uy=[0,5e3,5e3],Gy=He("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),I0="models.providers.",ho="agents.defaults.models",xo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new vn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Uy,this.cliTimeoutMs=e.cliTimeoutMs??Gy}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,S0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}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=at(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=x=>{d||(d=!0,clearTimeout(h),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let h=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);h.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?r():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){S0.warn(`${e} failed (best-effort)`,{configPath:r,err:String(i)})}}ensureProvider(e,r){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${I0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${I0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${ho}[${e}]`,()=>this.runCli(["config","set",ho,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${ho}[${e}]`,`${ho}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=U("agent-manager"),td="acceptEdits",k0="full-access",D0="read-only";function $y(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 Vy=(t,e,r,i,o,c,d,u,h,x)=>{switch(t){case"claude-code":{let m={...o?{...Bf(o),...Uf(o,d,u)}:{},...h??{},IS_SANDBOX:"1"};return new lo({cwd:r,env:m,agentId:i})}case"codex":{let m=o?[...Ff(o),...qf(o,d,u)]:[],w=k0;x!==void 0&&(En("codex",x)?w=x:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let b=[...m,...$y(w)],_={...o?zf(o):{},...h??{}},v=!!o;return new uo({cwd:r,agentId:i,...b.length>0?{extraArgs:b}:{},...Object.keys(_).length>0?{env:_}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Dr({command:e,cwd:r,agentId:i,...c?{sessionName:Qc(c)}:{}})}};function ed(t){return t==="claude-code"||t==="codex"}function Jy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Zy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
89
|
+
`},configPath(t){return m1(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",sa,"/TR",r,"/RU",t.userName,"/F"]),Hd.info("task scheduler entry created",{task:sa,logFile:t.logFile})},async uninstall(t){await Yh("schtasks",["/Delete","/TN",sa,"/F"]).catch(e=>Hd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Hd.info("task scheduler entry removed",{task:sa})}}});var Xh={};_a(Xh,{buildContext:()=>v1,getSupervisor:()=>y1,launchdSupervisor:()=>Ud,systemdSupervisor:()=>Gd,taskSchedulerSupervisor:()=>qd});import{homedir as w1,userInfo as _1}from"node:os";function y1(t=process.platform){switch(t){case"darwin":return Ud;case"linux":return Gd;case"win32":return qd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function E1(){let t={};for(let e of b1){let r=process.env[e];r&&(t[e]=r)}return t}function v1(){let t=Q();return{nodeBin:process.execPath,entry:kd(t),logFile:t.logFile,homeDir:w1(),userName:_1().username,isRoot:process.getuid?.()===0,env:E1()}}var b1,Qh=Ye(()=>{"use strict";Oe();Vo();$h();Jh();Zh();b1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();rn();var yl=H("acp-installer-warmup"),Ig=["claude-code","codex"];async function bl(t={}){let e=t.ensure??sr,i=(await Promise.allSettled(Ig.map(async o=>{let c=await e(o);yl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&yl.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();ne();import{readdir as Hg}from"node:fs/promises";import{mkdir as Al,readFile as Ug,writeFile as Il}from"node:fs/promises";import{join as Ia}from"node:path";var Gg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function cr(t,e,r){await Al(t,{recursive:!0});let i=Gg[e],o=Ia(t,i);return await Il(o,r??"","utf8"),o}async function Ta(t,e,r){let i=Ia(t,".claude");await Al(i,{recursive:!0});let o=Ia(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 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 Il(o,JSON.stringify(c,null,2),"utf8"),o}var $e=H("agent-detail-sync"),qg=6e4,jg=5*6e4,xs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Hg(r)}catch(o){$e.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}$e.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Me(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){$e.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){$e.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),$e.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){$e.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){$e.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Me(e,this.opts.paths);if(!i){$e.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(x){$e.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let p=this.retryQueue.get(e),m=p?Math.min(p.currentDelay*2,jg):qg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){$e.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,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"?($e.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&$e.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){$e.debug("detail sync: no diff",{agentId:e});return}await Xe(i,this.opts.paths),$e.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),$e.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await cr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var K0=Ft(su(),1);import{lstat as Gc,mkdir as Hc,readFile as H0,readdir as S_,rm as A_,stat as I_,writeFile as qc}from"node:fs/promises";import{dirname as T_,join as Pt,normalize as C_,relative as Kc,resolve as jc,sep as q0}from"node:path";import{Readable as j0}from"node:stream";import{pipeline as W0}from"node:stream/promises";import fm from"events";import Qe from"fs";import{EventEmitter as Ic}from"node:events";import Uu from"node:stream";import{StringDecoder as xm}from"node:string_decoder";import qu from"node:path";import yr from"node:fs";import{dirname as Im,parse as Tm}from"path";import{EventEmitter as Nm}from"events";import ac from"assert";import{Buffer as Gn}from"buffer";import*as lu from"zlib";import Mm from"zlib";import{posix as xr}from"node:path";import{basename as dw}from"node:path";import Ws from"fs";import Dt from"fs";import mu from"path";import{win32 as bw}from"node:path";import Su from"path";import i0 from"node:fs";import zw from"node:assert";import{randomBytes as s0}from"node:crypto";import re from"node:fs";import Ne from"node:path";import o0 from"fs";import eo from"node:fs";import bi from"node:path";import it from"node:fs";import Ww from"node:fs/promises";import Vs from"node:path";import{join as m0}from"node:path";import rt from"node:fs";import y0 from"node:path";var lm=Object.defineProperty,um=(t,e)=>{for(var r in e)lm(t,r,{get:e[r],enumerable:!0})},ou=typeof process=="object"&&process?process:{stdout:null,stderr:null},hm=t=>!!t&&typeof t=="object"&&(t instanceof jn||t instanceof Uu||pm(t)||gm(t)),pm=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.pipe=="function"&&t.pipe!==Uu.Writable.prototype.pipe,gm=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),dn=Symbol("emittedEnd"),ws=Symbol("emittingEnd"),ii=Symbol("emittedError"),_s=Symbol("closed"),au=Symbol("read"),ys=Symbol("flush"),cu=Symbol("flushChunk"),pt=Symbol("encoding"),fr=Symbol("decoder"),Be=Symbol("flowing"),si=Symbol("paused"),mr=Symbol("resume"),ze=Symbol("buffer"),Ve=Symbol("pipes"),Fe=Symbol("bufferLength"),Oa=Symbol("bufferPush"),bs=Symbol("bufferShift"),Ke=Symbol("objectMode"),Se=Symbol("destroyed"),La=Symbol("error"),Na=Symbol("emitData"),du=Symbol("emitEnd"),Ma=Symbol("emitEnd2"),It=Symbol("async"),Ba=Symbol("abort"),Es=Symbol("aborted"),oi=Symbol("signal"),Pn=Symbol("dataListeners"),nt=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()}},bm=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)}},Em=t=>!!t.objectMode,vm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",jn=class extends Ic{[Be]=!1;[si]=!1;[Ve]=[];[ze]=[];[Ke];[pt];[It];[fr];[Ut]=!1;[dn]=!1;[ws]=!1;[_s]=!1;[ii]=null;[Fe]=0;[Se]=!1;[oi];[Es]=!1;[Pn]=0;[nt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Em(e)?(this[Ke]=!0,this[pt]=null):vm(e)?(this[pt]=e.encoding,this[Ke]=!1):(this[Ke]=!1,this[pt]=null),this[It]=!!e.async,this[fr]=this[pt]?new xm(this[pt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[ze]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ve]});let{signal:r}=e;r&&(this[oi]=r,r.aborted?this[Ba]():r.addEventListener("abort",()=>this[Ba]()))}get bufferLength(){return this[Fe]}get encoding(){return this[pt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ke]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ba](){this[Es]=!0,this.emit("abort",this[oi]?.reason),this.destroy(this[oi]?.reason)}get aborted(){return this[Es]}set aborted(t){}write(t,e,r){if(this[Es])return!1;if(this[Ut])throw new Error("write after end");if(this[Se])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[It]?ai:mm;if(!this[Ke]&&!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[Ke]?(this[Be]&&this[Fe]!==0&&this[ys](!0),this[Be]?this.emit("data",t):this[Oa](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[pt]&&!this[fr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[pt]&&(t=this[fr].write(t)),this[Be]&&this[Fe]!==0&&this[ys](!0),this[Be]?this.emit("data",t):this[Oa](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Se])return null;if(this[nt]=!1,this[Fe]===0||t===0||t&&t>this[Fe])return this[Gt](),null;this[Ke]&&(t=null),this[ze].length>1&&!this[Ke]&&(this[ze]=[this[pt]?this[ze].join(""):Buffer.concat(this[ze],this[Fe])]);let e=this[au](t||null,this[ze][0]);return this[Gt](),e}[au](t,e){if(this[Ke])this[bs]();else{let r=e;t===r.length||t===null?this[bs]():typeof r=="string"?(this[ze][0]=r.slice(t),e=r.slice(0,t),this[Fe]-=t):(this[ze][0]=r.subarray(t),e=r.subarray(0,t),this[Fe]-=t)}return this.emit("data",e),!this[ze].length&&!this[Ut]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Ut]=!0,this.writable=!1,(this[Be]||!this[si])&&this[Gt](),this}[mr](){this[Se]||(!this[Pn]&&!this[Ve].length&&(this[nt]=!0),this[si]=!1,this[Be]=!0,this.emit("resume"),this[ze].length?this[ys]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[mr]()}pause(){this[Be]=!1,this[si]=!0,this[nt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[si]}[Oa](t){this[Ke]?this[Fe]+=1:this[Fe]+=t.length,this[ze].push(t)}[bs](){return this[Ke]?this[Fe]-=1:this[Fe]-=this[ze][0].length,this[ze].shift()}[ys](t=!1){do;while(this[cu](this[bs]())&&this[ze].length);!t&&!this[ze].length&&!this[Ut]&&this.emit("drain")}[cu](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[nt]=!1;let r=this[dn];return e=e||{},t===ou.stdout||t===ou.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ve].push(e.proxyErrors?new bm(this,t,e):new Gu(this,t,e)),this[It]?ai(()=>this[mr]()):this[mr]()),t}unpipe(t){let e=this[Ve].find(r=>r.dest===t);e&&(this[Ve].length===1?(this[Be]&&this[Pn]===0&&(this[Be]=!1),this[Ve]=[]):this[Ve].splice(this[Ve].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[nt]=!1,this[Pn]++,!this[Ve].length&&!this[Be]&&this[mr]();else if(t==="readable"&&this[Fe]!==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[nt]&&!this[Ve].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Pn]=0,!this[nt]&&!this[Ve].length&&(this[Be]=!1)),e}get emittedEnd(){return this[dn]}[Gt](){!this[ws]&&!this[dn]&&!this[Se]&&this[ze].length===0&&this[Ut]&&(this[ws]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[_s]&&this.emit("close"),this[ws]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ke]&&!r?!1:this[It]?(ai(()=>this[Na](r)),!0):this[Na](r);if(t==="end")return this[du]();if(t==="close"){if(this[_s]=!0,!this[dn]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ii]=r,super.emit(La,r);let o=!this[oi]||this.listeners("error").length?super.emit("error",r):!1;return this[Gt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Gt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Gt](),i}[Na](t){for(let r of this[Ve])r.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[Gt](),e}[du](){return this[dn]?!1:(this[dn]=!0,this.readable=!1,this[It]?(ai(()=>this[Ma]()),!0):this[Ma]())}[Ma](){if(this[fr]){let e=this[fr].end();if(e){for(let r of this[Ve])r.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[Ve])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ke]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ke]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ke])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[pt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[nt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Ut])return e();let i,o,c=p=>{this.off("data",d),this.off("end",u),this.off(Se,x),e(),o(p)},d=p=>{this.off("error",c),this.off("end",u),this.off(Se,x),this.pause(),i({value:p,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Se,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((p,m)=>{o=m,i=p,this.once(Se,x),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(La,e),this.off(Se,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(La,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[nt]=!0,this[ze].length=0,this[Fe]=0;let e=this;return typeof e.close=="function"&&!this[_s]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return hm}},Sm=Qe.writev,_n=Symbol("_autoClose"),_t=Symbol("_close"),ci=Symbol("_ended"),de=Symbol("_fd"),za=Symbol("_finished"),Wt=Symbol("_flags"),Fa=Symbol("_flush"),sc=Symbol("_handleChunk"),oc=Symbol("_makeBuf"),_i=Symbol("_mode"),vs=Symbol("_needDrain"),Er=Symbol("_onerror"),vr=Symbol("_onopen"),Ua=Symbol("_onread"),wr=Symbol("_onwrite"),yn=Symbol("_open"),wt=Symbol("_path"),hn=Symbol("_pos"),Tt=Symbol("_queue"),_r=Symbol("_read"),Ga=Symbol("_readSize"),jt=Symbol("_reading"),di=Symbol("_remain"),Ha=Symbol("_size"),Os=Symbol("_write"),On=Symbol("_writing"),Ls=Symbol("_defaultFlag"),Un=Symbol("_errored"),Tc=class extends jn{[Un]=!1;[de];[wt];[Ga];[jt]=!1;[Ha];[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[de]=typeof e.fd=="number"?e.fd:void 0,this[wt]=t,this[Ga]=e.readSize||16*1024*1024,this[jt]=!1,this[Ha]=typeof e.size=="number"?e.size:1/0,this[di]=this[Ha],this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[_r]():this[yn]()}get fd(){return this[de]}get path(){return this[wt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[yn](){Qe.open(this[wt],"r",(t,e)=>this[vr](t,e))}[vr](t,e){t?this[Er](t):(this[de]=e,this.emit("open",e),this[_r]())}[oc](){return Buffer.allocUnsafe(Math.min(this[Ga],this[di]))}[_r](){if(!this[jt]){this[jt]=!0;let t=this[oc]();if(t.length===0)return process.nextTick(()=>this[Ua](null,0,t));Qe.read(this[de],t,0,t.length,null,(e,r,i)=>this[Ua](e,r,i))}}[Ua](t,e,r){this[jt]=!1,t?this[Er](t):this[sc](e,r)&&this[_r]()}[_t](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Er](t){this[jt]=!0,this[_t](),this.emit("error",t)}[sc](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[_t](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[_r](),!1;case"error":return this[Un]?!1:(this[Un]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Am=class extends Tc{[yn](){let t=!0;try{this[vr](null,Qe.openSync(this[wt],"r")),t=!1}finally{t&&this[_t]()}}[_r](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[oc](),r=e.length===0?0:Qe.readSync(this[de],e,0,e.length,null);if(!this[sc](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[_t]()}}[_t](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.closeSync(t),this.emit("close")}}},Js=class extends fm{readable=!1;writable=!0;[Un]=!1;[On]=!1;[ci]=!1;[Tt]=[];[vs]=!1;[wt];[_i];[_n];[de];[Ls];[Wt];[za]=!1;[hn];constructor(t,e){e=e||{},super(e),this[wt]=t,this[de]=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[Ls]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[de]===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[de]}get path(){return this[wt]}[Er](t){this[_t](),this[On]=!0,this.emit("error",t)}[yn](){Qe.open(this[wt],this[Wt],this[_i],(t,e)=>this[vr](t,e))}[vr](t,e){this[Ls]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[yn]()):t?this[Er](t):(this[de]=e,this.emit("open",e),this[On]||this[Fa]())}end(t,e){return t&&this.write(t,e),this[ci]=!0,!this[On]&&!this[Tt].length&&typeof this[de]=="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[de]===void 0||this[On]||this[Tt].length?(this[Tt].push(t),this[vs]=!0,!1):(this[On]=!0,this[Os](t),!0)}[Os](t){Qe.write(this[de],t,0,t.length,this[hn],(e,r)=>this[wr](e,r))}[wr](t,e){t?this[Er](t):(this[hn]!==void 0&&typeof e=="number"&&(this[hn]+=e),this[Tt].length?this[Fa]():(this[On]=!1,this[ci]&&!this[za]?(this[za]=!0,this[_t](),this.emit("finish")):this[vs]&&(this[vs]=!1,this.emit("drain"))))}[Fa](){if(this[Tt].length===0)this[ci]&&this[wr](null,0);else if(this[Tt].length===1)this[Os](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],Sm(this[de],t,this[hn],(e,r)=>this[wr](e,r))}}[_t](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Hu=class extends Js{[yn](){let t;if(this[Ls]&&this[Wt]==="r+")try{t=Qe.openSync(this[wt],this[Wt],this[_i])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[yn]();throw e}else t=Qe.openSync(this[wt],this[Wt],this[_i]);this[vr](null,t)}[_t](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.closeSync(t),this.emit("close")}}[Os](t){let e=!0;try{this[wr](null,Qe.writeSync(this[de],t,0,t.length,this[hn])),e=!1}finally{if(e)try{this[_t]()}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"]]),Dm=t=>!!t.sync&&!!t.file,Rm=t=>!t.sync&&!!t.file,km=t=>!!t.sync&&!t.file,Pm=t=>!t.sync&&!t.file,Om=t=>!!t.file,Lm=t=>Cm.get(t)||t,Cc=(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=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let x=Cc(c);if(o?.(x,d),Dm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,d)}else if(Rm(x)){let p=e(x,d);return u?p.then(()=>u(),u):p}else if(km(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,d)}else if(Pm(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile: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)),zm=Gn.concat,uu=Object.getOwnPropertyDescriptor(Gn,"concat"),Fm=t=>t,qa=uu?.writable===!0||uu?.set!==void 0?t=>{Gn.concat=t?Fm:zm}:t=>{},Hn=Symbol("_superWrite"),Ss=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},ja=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 lu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new lu[e](t)}catch(r){throw new Ss(r,this.constructor)}this.#o=r=>{this.#e||(this.#e=!0,this.close(),this.emit("error",r))},this.#t?.on("error",r=>this.#o(new Ss(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ac(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Gn.alloc(0),{[ja]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Hn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Gn.from(t,e)),this.#e)return;ac(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},qa(!0);let d;try{let x=typeof t[ja]=="number"?t[ja]:this.#r;d=this.#t._processChunk(t,x),qa(!1)}catch(x){qa(!1),this.#o(new Ss(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 Ss(x,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let x=d[0];u=this[Hn](Gn.from(x));for(let p=1;p<d.length;p++)u=this[Hn](d[p])}else u=this[Hn](Gn.from(d));return r&&r(),u}},ju=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),ac(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},Um=class extends ju{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Hn](t){return this.#e?(this.#e=!1,t[9]=255,super[Hn](t)):super[Hn](t)}},Gm=class extends ju{constructor(t){super(t,"Unzip")}},Wu=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)}},Hm=class extends Wu{constructor(t){super(t,"BrotliCompress")}},qm=class extends Wu{constructor(t){super(t,"BrotliDecompress")}},Ku=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 Ku{constructor(t){super(t,"ZstdCompress")}},Wm=class extends Ku{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]=$u(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Vu(o))}},Jm=t=>{let e=t[0],r=e===128?Zm(t.subarray(1,t.length)):e===255?Ym(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},Ym=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=$u(c):c===0?d=c:(i=!0,d=Vu(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Zm=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},$u=t=>(255^t)&255,Vu=t=>(255^t)+1&255,Xm={};um(Xm,{code:()=>Rc,isCode:()=>Ns,isName:()=>Qm,name:()=>Ys,normalFsTypes:()=>Ju});var Ns=t=>Ys.has(t),Qm=t=>Rc.has(t),Ju=new Set(["0","","1","2","3","4","5","6","7","D"]),Ys=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Rc=new Map(Array.from(Ys).map(t=>[t[1],t[0]])),qn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Ln(t,e+156,1),c=Ju.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??Ln(t,e,100),this.mode=d?.mode??u?.mode??pn(t,e+100,8),this.uid=d?.uid??u?.uid??pn(t,e+108,8),this.gid=d?.gid??u?.gid??pn(t,e+116,8),this.size=d?.size??u?.size??pn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Wa(t,e+136,12),this.cksum=pn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Ns(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ln(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Ln(t,e+265,32),this.gname=d?.gname??u?.gname??Ln(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??pn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??pn(t,e+337,8)??0,t[e+475]!==0){let 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??Wa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Wa(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=Ka(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=Ka(t,e+476,12,this.atime)||this.needPax,this.needPax=Ka(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,gn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Ys.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Rc.get(t));if(Ns(e)||e==="Unsupported")this.#e=e;else if(Ns(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},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.*/,""),Wa=(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",Ka=(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),js=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 qn({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),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 Yu(lw(uw(e),r),i)}},lw=(t,e)=>e?Object.assign({},e,t):t,uw=t=>t.replace(/\n$/,"").split(`
|
|
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"),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},xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=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=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))))}},Zs=(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,cc=Buffer.from([31,139]),dc=Buffer.from([40,181,47,253]),gw=Math.max(cc.length,dc.length),at=Symbol("state"),Mn=Symbol("writeEntry"),Ht=Symbol("readEntry"),$a=Symbol("nextEntry"),fu=Symbol("processEntry"),Ct=Symbol("extendedHeader"),li=Symbol("globalExtendedHeader"),ln=Symbol("meta"),xu=Symbol("emitMeta"),pe=Symbol("buffer"),qt=Symbol("queue"),un=Symbol("ended"),Va=Symbol("emittedEnd"),Bn=Symbol("emit"),De=Symbol("unzip"),As=Symbol("consumeChunk"),Is=Symbol("consumeChunkSub"),Ja=Symbol("consumeBody"),hu=Symbol("consumeMeta"),pu=Symbol("consumeHeader"),ui=Symbol("consuming"),Ya=Symbol("bufferConcat"),Ts=Symbol("maybeEnd"),hr=Symbol("writing"),fn=Symbol("aborted"),Cs=Symbol("onDone"),zn=Symbol("sawValidEntry"),Ds=Symbol("sawNullBlock"),Rs=Symbol("sawEOF"),gu=Symbol("closeStream"),mw=()=>!0,Ti=class extends Nm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[qt]=[];[pe];[Ht];[Mn];[at]="begin";[ln]="";[Ct];[li];[un]=!1;[De];[fn]=!1;[zn];[Ds]=!1;[Rs]=!1;[hr]=!1;[ui]=!1;[Va]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Cs,()=>{(this[at]==="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||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[gu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Zs(this,t,e,r)}[pu](t,e){this[zn]===void 0&&(this[zn]=!1);let r;try{r=new qn(t,e,this[Ct],this[li])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ds]?(this[Rs]=!0,this[at]==="begin"&&(this[at]="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[Ct],this[li]);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[Bn]("ignoredEntry",o),this[at]="ignore",o.resume()):o.size>0&&(this[ln]="",o.on("data",c=>this[ln]+=c),this[at]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Bn]("ignoredEntry",o),this[at]=o.remain?"ignore":"header",o.resume()):(o.remain?this[at]="body":(this[at]="header",o.end()),this[Ht]?this[qt].push(o):(this[qt].push(o),this[$a]())))}}}[gu](){queueMicrotask(()=>this.emit("close"))}[fu](t){let e=!0;if(!t)this[Ht]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ht]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[$a]()),e=!1);return e}[$a](){do;while(this[fu](this[qt].shift()));if(this[qt].length===0){let t=this[Ht];!t||t.flowing||t.size===t.remain?this[hr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ja](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[at]="header",this[Mn]=void 0,r.end()),o.length}[hu](t,e){let r=this[Mn],i=this[Ja](t,e);return!this[Mn]&&r&&this[xu](r),i}[Bn](t,e,r){this[qt].length===0&&!this[Ht]?this.emit(t,e,r):this[qt].push([t,e,r])}[xu](t){switch(this[Bn]("meta",this[ln]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=js.parse(this[ln],this[Ct],!1);break;case"GlobalExtendedHeader":this[li]=js.parse(this[ln],this[li],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[ln].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=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[De]===void 0||this.brotli===void 0&&this[De]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<gw)return this[pe]=t,r?.(),!0;for(let d=0;this[De]===void 0&&d<cc.length;d++)t[d]!==cc[d]&&(this[De]=!1);let o=!1;if(this[De]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<dc.length;d++)if(t[d]!==dc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[De]===!1&&c)if(t.length<512)if(this[un])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new qn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[De]===void 0||this[De]===!1&&(this.brotli||o)){let d=this[un];this[un]=!1,this[De]=this[De]===void 0?new Gm({}):o?new Wm({}):new qm({}),this[De].on("data",x=>this[As](x)),this[De].on("error",x=>this.abort(x)),this[De].on("end",()=>{this[un]=!0,this[As]()}),this[hr]=!0;let u=!!this[De][d?"end":"write"](t);return this[hr]=!1,r?.(),u}}this[hr]=!0,this[De]?this[De].write(t):this[As](t),this[hr]=!1;let i=this[qt].length>0?!1:this[Ht]?this[Ht].flowing:!0;return!i&&this[qt].length===0&&this[Ht]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ya](t){t&&!this[fn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Ts](){if(this[un]&&!this[Va]&&!this[fn]&&!this[ui]){this[Va]=!0;let t=this[Mn];if(t&&t.blockRemain){let e=this[pe]?this[pe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[pe]&&t.write(this[pe]),t.end()}this[Bn](Cs)}}[As](t){if(this[ui]&&t)this[Ya](t);else if(!t&&!this[pe])this[Ts]();else if(t){if(this[ui]=!0,this[pe]){this[Ya](t);let e=this[pe];this[pe]=void 0,this[Is](e)}else this[Is](t);for(;this[pe]&&this[pe]?.length>=512&&!this[fn]&&!this[Rs];){let e=this[pe];this[pe]=void 0,this[Is](e)}this[ui]=!1}(!this[pe]||this[un])&&this[Ts]()}[Is](t){let e=0,r=t.length;for(;e+512<=r&&!this[fn]&&!this[Rs];)switch(this[at]){case"begin":case"header":this[pu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ja](t,e);break;case"meta":e+=this[hu](t,e);break;default:throw new Error("invalid state: "+this[at])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[fn]||(this[De]?(t&&this[De].write(t),this[De].end()):(this[un]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ts]())),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()},Zu=(t,e)=>{let r=new Map(e.map(c=>[yi(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||Tm(c).root||".",x;if(c===u)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(Im(c),u)}return r.set(c,x),x};t.filter=i?(c,d)=>i(c,d)&&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 d=Buffer.allocUnsafe(o.size),u=yr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let x=yr.readSync(i,u,0,c,d);if(x===0)break;d+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{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,d)=>{r.on("error",d),r.on("end",c),yr.stat(o,(u,x)=>{if(u)d(u);else{let p=new Tc(o,{readSize:i,size:x.size});p.on("error",d),p.pipe(r)}})})},Sr=Ci(_w,yw,t=>new Ti(t),t=>new Ti(t),(t,e)=>{e?.length&&Zu(t,e),t.noResume||ww(t)}),Xu=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Ew,parse:wu}=bw,kc=t=>{let e="",r=wu(t);for(;Ew(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=wu(t)}return[e,t]},Xs=["|","<",">","?",":"],Pc=Xs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),vw=new Map(Xs.map((t,e)=>[t,Pc[e]])),Sw=new Map(Pc.map((t,e)=>[t,Xs[e]])),_u=t=>Xs.reduce((e,r)=>e.split(r).join(vw.get(r)),t),Aw=t=>Pc.reduce((e,r)=>e.split(r).join(Sw.get(r)),t),Qu=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),yi(e)+"/"+t):X(t),Iw=16*1024*1024,yu=Symbol("process"),bu=Symbol("file"),Eu=Symbol("directory"),lc=Symbol("symlink"),vu=Symbol("hardlink"),fi=Symbol("header"),Ms=Symbol("read"),uc=Symbol("lstat"),Bs=Symbol("onlstat"),fc=Symbol("onread"),xc=Symbol("onreadlink"),hc=Symbol("openfile"),pc=Symbol("onopenfile"),mn=Symbol("close"),Ks=Symbol("mode"),gc=Symbol("awaitDrain"),Za=Symbol("ondrain"),Rt=Symbol("prefix"),e0=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=Cc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Iw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=kc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Aw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(r.absolute||mu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Bs](o):this[uc]()}warn(t,e,r={}){return Zs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[uc](){Dt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Bs](e)})}[Bs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Dw(t),this.emit("stat",t),this[yu]()}[yu](){switch(this.type){case"File":return this[bu]();case"Directory":return this[Eu]();case"SymbolicLink":return this[lc]();default:return this.end()}}[Ks](t){return Xu(t,this.type==="Directory",this.portable)}[Rt](t){return Qu(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 qn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Ks](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new js({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Eu](){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()}[lc](){Dt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[xc](e)})}[xc](t){this.linkpath=X(t),this[fi](),this.end()}[vu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(mu.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[vu](e);this.linkCache.set(t,this.absolute)}if(this[fi](),this.stat.size===0)return this.end();this[hc]()}[hc](){Dt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){if(this.fd=t,this.#e)return this[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[Ms]()}[Ms](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Dt.read(t,e,r,i,o,(c,d)=>{if(c)return this[mn](()=>this.emit("error",c));this[fc](d)})}[mn](t=()=>{}){this.fd!==void 0&&Dt.close(this.fd,t)}[fc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[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[Za]():this[gc](()=>this[Za]())}[gc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Za](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[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[Ms]()}},Tw=class extends e0{sync=!0;[uc](){this[Bs](Dt.lstatSync(this.absolute))}[lc](){this[xc](Dt.readlinkSync(this.absolute))}[hc](){this[pc](Dt.openSync(this.absolute,"r"))}[Ms](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=Dt.readSync(e,r,i,o,c);this[fc](d),t=!1}finally{if(t)try{this[mn](()=>{})}catch{}}}[gc](t){t()}[mn](t=()=>{}){this.fd!==void 0&&Dt.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 Zs(this,t,e,r)}constructor(t,e={}){let r=Cc(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[Ks](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=kc(this.path);d&&typeof u=="string"&&(this.path=u,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new qn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new js({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Rt](t){return Qu(t,this.prefix)}[Ks](t){return Xu(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}},Dw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Rw=class br{tail;head;length=0;static create(e=[]){return new br(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)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 br;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new br;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new br;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new br;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=kw(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 kw(t,e,r){let i=e,o=e?e.next:t.head,c=new Oc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Pw(t,e){t.tail=new Oc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Ow(t,e){t.head=new Oc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Oc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Au=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Iu=Buffer.alloc(1024),zs=Symbol("onStat"),xi=Symbol("ended"),gt=Symbol("queue"),hi=Symbol("pendingLinks"),xn=Symbol("current"),Fn=Symbol("process"),pi=Symbol("processing"),ks=Symbol("processJob"),mt=Symbol("jobs"),Xa=Symbol("jobDone"),Fs=Symbol("addFSEntry"),Tu=Symbol("addTarEntry"),mc=Symbol("stat"),wc=Symbol("readdir"),Us=Symbol("onreaddir"),Gs=Symbol("pipe"),Cu=Symbol("entry"),Qa=Symbol("entryOpt"),Hs=Symbol("writeEntryClass"),t0=Symbol("write"),ec=Symbol("ondrain"),Qs=class extends jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Hs];onWriteEntry;[gt];[hi]=new Map;[mt]=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=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[Hs]=e0,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 Hm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new jm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[ec]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ec]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[gt]=new Rw,this[mt]=0,this.jobs=Number(t.jobs)||4,this[pi]=!1,this[xi]=!1}[t0](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[Fn](),r&&r(),this}write(t){if(this[xi])throw new Error("write after end");return typeof t=="string"?this[Fs](t):this[Tu](t),this.flowing}[Tu](t){let e=X(Su.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[Qa](r)),r.entry.on("end",()=>this[Xa](r)),this[mt]+=1,this[gt].push(r)}this[Fn]()}[Fs](t){let e=X(Su.resolve(this.cwd,t));this[gt].push(new Au(t,e)),this[Fn]()}[mc](t){t.pending=!0,this[mt]+=1;let e=this.follow?"stat":"lstat";Ws[e](t.absolute,(r,i)=>{t.pending=!1,this[mt]-=1,r?this.emit("error",r):this[zs](t,i)})}[zs](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[ks](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[Fn]()}[wc](t){t.pending=!0,this[mt]+=1,Ws.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[mt]-=1,e)return this.emit("error",e);this[Us](t,r)})}[Us](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Fn]()}[Fn](){if(!this[pi]){this[pi]=!0;for(let t=this[gt].head;t&&this[mt]<this.jobs;t=t.next)if(this[ks](t.value),t.value.ignore){let e=t.next;this[gt].removeNode(t),t.next=e}this[pi]=!1,this[xi]&&this[gt].length===0&&this[mt]===0&&(this.zip?this.zip.end(Iu):(super.write(Iu),super.end()))}}get[xn](){return this[gt]&&this[gt].head&&this[gt].head.value}[Xa](t){this[gt].shift(),this[mt]-=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[ks](o)}}this[Fn]()}[ks](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[Gs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[zs](t,e):this[mc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Us](t,e):this[wc](t),!t.readdir)return}if(t.entry=this[Cu](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[Gs](t)}}}[Qa](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Cu](t){this[mt]+=1;try{return new this[Hs](t.path,this[Qa](t)).on("end",()=>this[Xa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ec](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[Gs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Fs](c+i)});let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",i=>{r.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){Zs(this,t,e,r)}},Lc=class extends Qs{sync=!0;constructor(t){super(t),this[Hs]=Tw}pause(){}resume(){}[mc](t){let e=this.follow?"statSync":"lstatSync";this[zs](t,Ws[e](t.absolute))}[wc](t){this[Us](t,Ws.readdirSync(t.absolute))}[Gs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Fs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[t0](i)})}},Lw=(t,e)=>{let r=new Lc(t),i=new Hu(t.file,{mode:t.mode||438});r.pipe(i),n0(r,e)},Nw=(t,e)=>{let r=new Qs(t),i=new Js(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 r0(r,e).catch(c=>r.emit("error",c)),o},n0=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:qu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},r0=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Sr({file:qu.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 Lc(t);return n0(r,e),r},Bw=(t,e)=>{let r=new Qs(t);return r0(r,e).catch(i=>r.emit("error",i)),r},sA=Ci(Lw,Nw,Mw,Bw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Fw=process.env.__FAKE_PLATFORM__||process.platform,a0=Fw==="win32",{O_CREAT:c0,O_NOFOLLOW:Du,O_TRUNC:d0,O_WRONLY:l0}=o0.constants,u0=Number(process.env.__FAKE_FS_O_FILENAME__)||o0.constants.UV_FS_O_FILEMAP||0,Uw=a0&&!!u0,Gw=512*1024,Hw=u0|d0|c0|l0,Ru=!a0&&typeof Du=="number"?Du|d0|c0|l0:null,f0=Ru!==null?()=>Ru:Uw?t=>t<Gw?Hw:"w":()=>"w",_c=(t,e,r)=>{try{return eo.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},$s=(t,e,r,i)=>{eo.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},qw=(t,e,r,i,o)=>{if(e.isDirectory())x0(bi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=bi.resolve(t,e.name);$s(d,r,i,o)});else{let c=bi.resolve(t,e.name);$s(c,r,i,o)}},x0=(t,e,r,i)=>{eo.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return $s(t,e,r,i);let d=c.length,u=null,x=p=>{if(!u){if(p)return i(u=p);if(--d===0)return $s(t,e,r,i)}};for(let p of c)qw(t,p,e,r,x)})},jw=(t,e,r,i)=>{e.isDirectory()&&h0(bi.resolve(t,e.name),r,i),_c(bi.resolve(t,e.name),r,i)},h0=(t,e,r)=>{let i;try{i=eo.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return _c(t,e,r);throw c}for(let o of i)jw(t,o,e,r);return _c(t,e,r)},p0=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},to=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},Kw=(t,e)=>{it.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new p0(t,r?.code||"ENOTDIR")),e(r)})},$w=(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,x=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),p=e.preserve,m=e.unlink,w=X(e.cwd),S=(v,A)=>{v?r(v):A&&x?x0(A,d,u,T=>S(T)):c?it.chmod(t,o,r):r()};if(t===w)return Kw(t,S);if(p)return Ww.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let _=X(Vs.relative(w,t)).split("/");yc(w,_,o,m,w,void 0,S)},yc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),x=X(Vs.resolve(t+"/"+u));it.mkdir(x,r,g0(x,e,r,i,o,c,d))},g0=(t,e,r,i,o,c,d)=>u=>{u?it.lstat(t,(x,p)=>{if(x)x.path=x.path&&X(x.path),d(x);else if(p.isDirectory())yc(t,e,r,i,o,c,d);else if(i)it.unlink(t,m=>{if(m)return d(m);it.mkdir(t,r,g0(t,e,r,i,o,c,d))});else{if(p.isSymbolicLink())return d(new to(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,yc(t,e,r,i,o,c,d))},Vw=t=>{let e=!1,r;try{e=it.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new p0(t,r??"ENOTDIR")}},Jw=(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),x=e.preserve,p=e.unlink,m=X(e.cwd),w=v=>{v&&u&&h0(v,c,d),o&&it.chmodSync(t,i)};if(t===m)return Vw(m),w();if(x)return w(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X(Vs.relative(m,t)).split("/"),_;for(let v=S.shift(),A=m;v&&(A+="/"+v);v=S.shift()){A=X(Vs.resolve(A));try{it.mkdirSync(A,i),_=_||A}catch{let T=it.lstatSync(A);if(T.isDirectory())continue;if(p){it.unlinkSync(A),it.mkdirSync(A,i),_=_||A;continue}else if(T.isSymbolicLink())return new to(A,A+"/"+S.join("/"))}}return w(_)},tc=Object.create(null),ku=1e4,pr=new Set,Yw=t=>{pr.has(t)?pr.delete(t):tc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),pr.add(t);let e=tc[t],r=pr.size-ku;if(r>ku/10){for(let i of pr)if(pr.delete(i),delete tc[i],--r<=0)break}return e},Zw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Xw=Zw==="win32",Qw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=m0(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(m0(Yw(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 d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let x of u)o.add(x)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let x=d[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},t_=()=>process.umask(),Pu=Symbol("onEntry"),bc=Symbol("checkFs"),Ou=Symbol("checkFs2"),Ec=Symbol("isReusable"),ct=Symbol("makeFs"),vc=Symbol("file"),Sc=Symbol("directory"),qs=Symbol("link"),Lu=Symbol("symlink"),Nu=Symbol("hardlink"),wi=Symbol("ensureNoSymlink"),Mu=Symbol("unsupported"),Bu=Symbol("checkPath"),nc=Symbol("stripAbsolutePath"),wn=Symbol("mkdir"),Ue=Symbol("onError"),Ps=Symbol("pending"),zu=Symbol("pend"),gr=Symbol("unpend"),rc=Symbol("ended"),ic=Symbol("maybeClose"),Ac=Symbol("skip"),Ei=Symbol("doChown"),vi=Symbol("uid"),Si=Symbol("gid"),Ai=Symbol("checkedCwd"),n_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ii=n_==="win32",r_=1024,i_=(t,e)=>{if(!Ii)return re.unlink(t,e);let r=t+".DELETE."+s0(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},s_=t=>{if(!Ii)return re.unlinkSync(t);let e=t+".DELETE."+s0(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Fu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Nc=class extends Ti{[rc]=!1;[Ai]=!1;[Ps]=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[rc]=!0,this[ic]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:r_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ii,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Ne.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[Pu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[ic](){this[rc]&&this[Ps]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[nc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=kc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ii&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Ne.posix.dirname(t.path),x=Ne.posix.normalize(Ne.posix.join(u,d.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}[Bu](t){let e=X(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=X(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[nc](t,"path")||!this[nc](t,"linkpath"))return!1;if(t.absolute=Ne.isAbsolute(t.path)?X(Ne.resolve(t.path)):X(Ne.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:X(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Ne.win32.parse(String(t.absolute));t.absolute=i+_u(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+_u(t.path.slice(o.length))}return!0}[Pu](t){if(!this[Bu](t))return t.resume();switch(zw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[bc](t);default:return this[Mu](t)}}[Ue](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(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)}[Ei](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 Fu(this.uid,t.uid,this.processUid)}[Si](t){return Fu(this.gid,t.gid,this.processGid)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Js(String(t.absolute),{flags:f0(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[Ue](x,t):this[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,m=t.mtime;re.futimes(x,p,m,w=>w?re.utimes(u,p,m,S=>c(S&&w)):c())}if(typeof x=="number"&&this[Ei](t)){o++;let p=this[vi](t),m=this[Si](t);typeof p=="number"&&typeof m=="number"&&re.fchown(x,p,m,w=>w?re.chown(u,p,m,S=>c(S&&w)):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)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[wn](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[gr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ei](t)&&(o++,re.chown(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)),c)),c()})}[Mu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Lu](t,e){let r=X(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[wi](t,this.cwd,r,()=>this[qs](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[Nu](t,e){let r=X(Ne.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[wi](t,this.cwd,i,()=>this[qs](t,r,"link",e),o=>{this[Ue](o,t),e()})}[wi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Ne.resolve(e,c);re.lstat(d,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new to(d,Ne.resolve(d,r.join("/"))));this[wi](t,d,r,i,o)})}[zu](){this[Ps]++}[gr](){this[Ps]--,this[ic]()}[Ac](t){this[gr](),t.resume()}[Ec](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ii}[bc](t){this[zu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Ou](t,r))}[Ou](t,e){let r=d=>{e(d)},i=()=>{this[wn](this.cwd,this.dmode,d=>{if(d){this[Ue](d,t),r();return}this[Ai]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=X(Ne.dirname(String(t.absolute)));if(d!==this.cwd)return this[wn](d,this.dmode,u=>{if(u){this[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[Ac](t),r();return}if(d||this[Ec](t,u))return this[ct](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=m=>this[ct](m??null,t,r);return x?re.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),x=>this[ct](x??null,t,r))}if(t.absolute===this.cwd)return this[ct](null,t,r);i_(String(t.absolute),x=>this[ct](x??null,t,r))})};this[Ai]?o():i()}[ct](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[vc](e,r);case"Link":return this[Nu](e,r);case"SymbolicLink":return this[Lu](e,r);case"Directory":case"GNUDumpDir":return this[Sc](e,r)}}[qs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[gr](),t.resume()),i()})}},gi=t=>{try{return[null,t()]}catch(e){return[e,null]}},w0=class extends Nc{sync=!0;[ct](t,e){return super[ct](t,e,()=>{})}[bc](t){if(!this[Ai]){let o=this[wn](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[Ai]=!0}if(t.absolute!==this.cwd){let o=X(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[wn](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=gi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Ac](t);if(e||this[Ec](t,r))return this[ct](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?gi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ct](d,t)}let[o]=gi(()=>re.rmdirSync(String(t.absolute)));this[ct](o,t)}let[i]=t.absolute===this.cwd?[]:gi(()=>s_(String(t.absolute)));this[ct](i,t)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{re.closeSync(o)}catch(x){u=x}(d||u)&&this[Ue](d||u,t),e()},o;try{o=re.openSync(String(t.absolute),f0(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,x=t.mtime;try{re.futimesSync(o,u,x)}catch(p){try{re.utimesSync(String(t.absolute),u,x)}catch{d=p}}}if(this[Ei](t)){let u=this[vi](t),x=this[Si](t);try{re.fchownSync(o,Number(u),Number(x))}catch(p){try{re.chownSync(String(t.absolute),Number(u),Number(x))}catch{d=d||p}}}i(d)})}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[wn](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[Ei](t))try{re.chownSync(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)))}catch{}e(),t.resume()}[wn](t,e){try{return Jw(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}}[wi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Ne.resolve(c,d);let[u,x]=gi(()=>re.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new to(c,Ne.resolve(e,r.join("/"))))}i()}[qs](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)}}},o_=t=>{let e=new w0(t),r=t.file,i=i0.statSync(r),o=t.maxReadSize||16*1024*1024;new Am(r,{readSize:o,size:i.size}).pipe(e)},a_=(t,e)=>{let r=new Nc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),i0.stat(o,(u,x)=>{if(u)d(u);else{let p=new Tc(o,{readSize:i,size:x.size});p.on("error",d),p.pipe(r)}})})},_0=Ci(o_,a_,t=>new w0(t),t=>new Nc(t),(t,e)=>{e?.length&&Zu(t,e)}),c_=(t,e)=>{let r=new Lc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw x}let d=rt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let m=0,w=0;m<512;m+=w){if(w=rt.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let x=new qn(u);if(!x.cksumValid)break;let p=512*Math.ceil((x.size||0)/512);if(c+p+512>d.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{rt.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 Qs(t),i=(o,c,d)=>{let u=(S,_)=>{S?rt.close(o,v=>d(S)):d(null,_)},x=0;if(c===0)return u(null,0);let p=0,m=Buffer.alloc(512),w=(S,_)=>{if(S||_===void 0)return u(S);if(p+=_,p<512&&_)return rt.read(o,m,p,m.length-p,x+p,w);if(x===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,x);let v=new qn(m);if(!v.cksumValid)return u(null,x);let A=512*Math.ceil((v.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,rt.read(o,m,0,512,x,w)};rt.read(o,m,0,512,x,w)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(x,p)=>{if(x&&x.code==="ENOENT"&&d==="r+")return d="w+",rt.open(t.file,d,u);if(x||!p)return c(x);rt.fstat(p,(m,w)=>{if(m)return rt.close(p,()=>c(m));i(p,w.size,(S,_)=>{if(S)return c(S);let v=new Js(t.file,{fd:p,start:_});r.pipe(v),v.on("error",c),v.on("close",o),f_(r,e)})})};rt.open(t.file,d,u)})},u_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:y0.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:y0.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")}),yA=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 yt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function no(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function b0(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function ro(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function E0(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function v0(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Ar(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();We();ne();Oe();We();function bn(t,e){if(no(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Di(t){return t.startsWith("http://")||t.startsWith("https://")}function io(t){return t.endsWith("/")?t.slice(0,-1):t}We();ne();var so="1008033",T0="1289";var C0="pbbp2",D0="https://www.coze.cn",R0="/api/coze_claw/resource/get_frontier_key",b_="https://www.coze.cn",E_="wss://frontier.coze.cn";function oo(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??b_}function k0(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??E_}function Ir(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 ki(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ri=H("handshake");async function Mc(t){let e=oo(t.endpoint),r=t.timeoutMs??1e4,i=`${io(e)}${R0}?aid=${encodeURIComponent(so)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Ir(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Ri.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 v=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${x}`);let w=m.data??{},S=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!S||!_){let v=JSON.stringify(m).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return Ri.info("handshake ok",{remoteDeviceId:_,logid:x,traceId:p}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof C)throw Ri.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ri.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Ri.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(d)}}var Bc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",bt="auto",P0=15e4;function O0(t){return{model:zc(t.model)??bt,...t.modelToken?{modelToken:t.modelToken}:{}}}function L0(t){return!t||t===bt}var v_=new Set(["auto","\u81EA\u52A8"]);function zc(t){let e=t?.trim();if(e)return v_.has(e.toLowerCase())?bt:e}function N0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Bc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||bt;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 L0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function M0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||bt}"`):L0(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Bc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??P0;e.push("-c",`model_context_window=${r}`)}return e}function B0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Fc(t,e){let{ttEnv:r,usePpe:i}=ki(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function z0(t,e,r){if(!t.modelToken)return{};let i=Fc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
+
`)}}function Uc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function F0(t,e,r){if(!t.modelToken)return null;let i=t.model||bt,o=Fc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Bc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??P0,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}function U0(t,e,r){if(!t.modelToken)return[];let i=Fc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var Ae=H("agent-handlers"),G0=5*1024*1024,D_=1,R_=6,k_=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=et("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 ao=class{constructor(e){this.opts=e}opts;async listSkills(e){bn(e._meta,"_agent/listSkills");let r=Ar(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],d=[];for(let u of c){let x=Pt(o,u.relPath,"SKILL.md");await I_(x).then(m=>m.isFile()).catch(()=>!1)&&d.push(G_(u))}return{skills:d}}async addSkills(e){let r=Ar(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((x,p)=>[x.skillId,p])),u=[];for(let x of o){let p=await $c({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Vc(c,d,p),u.push(x)}return await us(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){bn(e._meta,"_agent/removeSkills");let r=Ar(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 x=Pt(i.workspace,u.relPath);await A_(x,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await us(r,d),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 d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Ae.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});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:d}),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 Me(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ae.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await 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 Xe(i),Ae.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Me(r))throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Di(e.registry)&&o.push(`--registry=${e.registry}`);let c=N_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&P_.test(d)&&o.push("--env",d);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 Me(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Xe(i),Ae.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Ae.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(bn(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=zc(e.model)??bt,i=await Me(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Xe(i),Ae.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ae.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(d=>Ae.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 x=o.sessions.get(d);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(bn(e._meta,yt.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${yt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,yt.RESET),await this.runDetailSync(e.agentId,yt.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,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await ni(e,o)}async clearPersistedAcpSessionIds(e){let r=await Me(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Xe(r)}async repairAgent(e){if(bn(e._meta,yt.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${yt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${yt.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,yt.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){bn(e._meta,"_agent/getFileTree");let r=e._meta,i=Ar(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await Gc(d).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(d,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=X_(e.depth);return u.isDirectory()?{tree:await Z_(o,d,c,x)}:{tree:[{name:Q_(c),path:V0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){bn(e._meta,"_agent/getFileContent");let r=Ar(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 Gc(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>G0)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${G0})`);let d=await H0(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 Me(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=jc(e,r||"."),o=Kc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${q0}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Me(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function 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 z_(t){return t==="claude-code"?Pt(".claude","skills"):Pt(".agents","skills")}var F_=3e4,U_=50*1024*1024,Tr=3e4;async function $c(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,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=B_(o.skillName),x=z_(i),p=Pt(x,u),m=Pt(r,p);if(await Hc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Pi(S.length),await qc(Pt(m,"SKILL.md"),S,"utf8")}else{let S=await H_(o.downloadUrl);j_(S)?await V_(S,m):W_(S)?await K_(S,m):await qc(Pt(m,"SKILL.md"),S.toString("utf8"),"utf8")}let w={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"}),w}function Vc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function G_(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 H_(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=q_(t);return Pi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await H0(e);return Pi(r.length),r}if(Di(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),F_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return 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 q_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function 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 Wc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function K_(t,e){let r,i;try{r=new K0.default(t),i=r.getEntries()}catch(d){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||Wc(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=d.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=jc(e);for(let d of i){if(Wc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=jc(e,u),p=Kc(c,x);if(p.startsWith("..")||p==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Hc(x,{recursive:!0});continue}await Hc(T_(x),{recursive:!0});let m;try{m=d.getData()}catch(w){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await qc(x,m)}}function $_(t){let e;for(let r of t){let i=r.entryName;if(!i||Wc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function V_(t,e){await J_(t);let r=_0({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 W0(j0.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 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(p=>p==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${Tr}ms)`))},Tr);try{await W0(j0.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 Y_=5e3;async function Z_(t,e,r,i){return $0(t,e,r,i,{count:0})}async function $0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await S_(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(k_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Y_){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Pt(e,u.name),p=C_(Pt(r,u.name)),m=null;try{m=await Gc(x)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let w={name:u.name,path:V0(Kc(t,x)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(w.children=await $0(t,x,p,i-1,o)),d.push(w)}return d.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),d}function X_(t){return!t||t<=0?D_:Math.min(t,R_)}function Q_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function V0(t){return t.split(q0).join("/")}ne();import{readFileSync as NI}from"node:fs";import{dirname as BI,join as zI}from"node:path";import{fileURLToPath as UI}from"node:url";var Cr="0.1.103-alpha.5";var En=H("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()}),En.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),En.info("heartbeat stopped"))}async tick(){if(this.inFlight){En.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){En.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=ty(d);if(!u)continue;let x={agentId:d.agentId,status:u};d.patToken&&(x.patToken=d.patToken),d.accountId&&(x.accountId=d.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(d){En.warn("heartbeat batch send failed",{count:r.length,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(En.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){En.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){En.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 ed,rm as Ky,stat as $y}from"node:fs/promises";import{homedir as Vy}from"node:os";import{join as vf}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 Dr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Rr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function vn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var co=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},ee={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function J0(t){return"method"in t&&"id"in t&&t.id!==void 0}function Y0(t){return"method"in t&&!("id"in t)}function lo(t){return!("method"in t)&&"id"in t}var ny={AGENT_NOT_FOUND:ee.AGENT_NOT_FOUND,AGENT_BUSY:ee.AGENT_BUSY,AGENT_DISCONNECTED:ee.AGENT_DISCONNECTED,AGENT_TIMEOUT:ee.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:ee.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:ee.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:ee.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:ee.INTERNAL_ERROR,BRIDGE_INTERNAL:ee.INTERNAL_ERROR,IPC_AUTH_FAILED:ee.INTERNAL_ERROR,IPC_BAD_REQUEST:ee.INVALID_REQUEST,METHOD_NOT_FOUND:ee.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:ee.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:ee.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:ee.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:ee.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:ee.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:ee.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:ee.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:ee.FILE_TOO_LARGE,UNSUPPORTED_MIME:ee.UNSUPPORTED_MIME,UPLOAD_FAILED:ee.UPLOAD_FAILED,UPSTREAM_NOT_READY:ee.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:ee.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:ee.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:ee.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:ee.AGENT_ENV_NOT_READY};function 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]??ee.INTERNAL_ERROR,message:Ni(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Ni(t instanceof Error?t.message:String(t))}}function Z0(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 C(r,o,{retriable:e?.retriable??!1,cause:c})}function Q0(t){return`${JSON.stringify(t)}
|
|
93
|
+
`}var X0=10*1024*1024,uo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>X0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${X0} bytes`)}),[]}let r=this.buffer.split(`
|
|
94
|
+
`);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(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 tf={"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"},ZI=Object.fromEntries(Object.entries(tf).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:[]},kr=class{seq=0;next(e,r){this.seq+=1;let i=tf[e]??ay(e),o=oy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(x=>ef(r?.[x]??"")),u=cy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>ef(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function ay(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function ef(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 Jc(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 Yc(t){try{let e=JSON.parse(dy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function nf(t,e,r={},i=o=>o){return{...i({...t,...Yc(e)}),...r}}Kt();nr();We();ne();Oe();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 zi(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 Zc=new Set;function rf(t){typeof t=="number"&&t>0&&Zc.add(t)}function sf(t){typeof t=="number"&&Zc.delete(t)}function of(){for(let t of Zc)zi(t,"SIGKILL")}var Pr="coze-bridge-daemon";function af(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 cf(t,e){if(t.length===0)return;let r=e?.killFn??zi,i=e?.isAliveFn??Bi,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,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(x=>i(x));u+=d)await o(Math.min(d,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 df(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 lf(t,e){return df(t,e)}function uf(t,e){return df(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 ff(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,m=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Or(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs: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 xf=je("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),wy=200,_y=40,yy=je("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),by=je("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Ey=je("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),vy=je("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Sy=je("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Ay=je("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),hf=500;function Iy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=hf?t:`${e.slice(0,hf)}...<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 pf(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)?pf(e.command):void 0,cwd:e.cwd,cwdExists:pf(e.cwd),envKeys:e.envKeys}}function Dy(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 Ot=class{constructor(e){this.opts=e;this.log=H(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new uo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new kr;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=nf(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=et(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,rf(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,sf(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=Cy(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 C("AGENT_SPAWN_FAILED",Dy(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()));zi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||zi(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:by,absoluteMaxMs:Ey,approvalMaxMs:Ay,suspendThresholdMs:vy,...r};return this.call("session/prompt",e,xf,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Dr("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(Rr(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=xf,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=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 m={resolve:x,reject:p,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Or(0,!1,o),sessionId:u};m.promptTimeout=S;let _=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},A=this.now(),T=ff(v,S.cfg,A),D=k=>{S.armedAt=A,S.expectedIntervalMs=k,m.timer=setTimeout(_,k)};if(T.action==="suspend"){S.suspendedMs+=T.suspendedDeltaMs,S.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:T.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),D(T.rearmMs);return}if(T.action==="continue"){D(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,...S.sessionId?{sessionId:S.sessionId}:{}}),p(T.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),p(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),p(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(d)}catch(w){m.timer&&clearTimeout(m.timer),this.pending.delete(c),p(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Q0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(lo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Iy(e.result)}),r.resolve(e.result));return}if(Y0(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(J0(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(vn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(vn(e.id,Mi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Z0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=uf(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=lf(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function Ry(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var fo=class extends Ot{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 Ry(e)}};rn();import{mkdtempSync as ky,rmSync as Py}from"node:fs";import{tmpdir as Oy}from"node:os";import{join as Ly}from"node:path";var xo=class extends Ot{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),d=e.isolateCodexHome?ky(Ly(Oy(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(x),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let 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{}}};We();var Ny=3e4,Lr=class extends Ot{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ny))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var gf=["default","acceptEdits","plan","auto","bypassPermissions"],mf=["read-only","auto","full-access"];function Sn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return gf.includes(e);case"codex":return mf.includes(e);case"openclaw":return!1}}function Xc(t){switch(t){case"claude-code":return gf.join("/");case"codex":return mf.join("/");case"openclaw":return""}}on();We();ne();Oe();function Qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();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 ho=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new 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)Fi(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Fi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function $t(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Kt();ne();import{constants as wf}from"node:fs";import{access as My}from"node:fs/promises";import{delimiter as By,join as zy}from"node:path";var Et=H("framework-detector"),_f={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Fy=[".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??et,access:e.access??My}}async detect(e){let r=_f[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,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(_f).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"?["",...Fy]:[""];for(let o of r)for(let c of i){let d=zy(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?wf.F_OK:wf.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(d=>d?.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 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){Et.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&&(Gy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=x=>{c||(c=!0,d&&clearTimeout(d),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=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 Gy(t){return t.replace(Uy,"")}import{homedir as Hy}from"node:os";import{join as qy}from"node:path";on();Kt();nr();We();ne();async function Ef(){let t=qy(Hy(),".openclaw/openclaw.json");return(await or(t))?.gateway?.auth?.token??""}var yf=H("openclaw.config"),jy=[0,5e3,5e3],Wy=je("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),bf="models.providers.",po="agents.defaults.models",go=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new An;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(d=>setTimeout(d,c));try{return await r()}catch(d){i=d,yf.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=et(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=p=>{d||(d=!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){yf.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",`${bf}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${bf}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${po}[${e}]`,()=>this.runCli(["config","set",po,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${po}[${e}]`,`${po}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=H("agent-manager"),nd="bypassPermissions",If="full-access",Tf="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 Yy=(t,e,r,i,o,c,d,u,x,p)=>{switch(t){case"claude-code":{let m={...o?{...N0(o),...z0(o,d,u)}:{},...x??{},IS_SANDBOX:"1"};return new fo({cwd:r,env:m,agentId:i})}case"codex":{let m=o?[...M0(o),...U0(o,d,u)]:[],w=If;p!==void 0&&(Sn("codex",p)?w=p:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:p}));let S=[...m,...Jy(w)],_={...o?B0(o):{},...x??{}},v=!!o;return new xo({cwd:r,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(_).length>0?{env:_}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Lr({command:e,cwd:r,agentId:i,...c?{sessionName:Qc(c)}:{}})}};function td(t){return t==="claude-code"||t==="codex"}function Zy(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(`
|
|
97
97
|
`)}
|
|
98
|
-
`}function
|
|
99
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Yy={path:"",version:"cloud-deployed"},C0="openclaw_gateway_unavailable",Xy="openclaw_default_agent_missing";function R0(t){let e=[t.port!==void 0?`port=${t.port}`:"",t.runtime?`runtime=${t.runtime}`:"",t.detail??""].filter(Boolean).join(", ");return`openclaw gateway \u672A\u8FD0\u884C/\u4E0D\u53EF\u8FBE${e?` (${e})`:""}; \u8BF7\u542F\u52A8 openclaw gateway`}var Qy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},eE=6e4,go=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??Vy,this.createTimeoutMs=e.createTimeoutMs??eE,this.detectorFactory=e.detectorFactory??(()=>new qn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new xo({command:r})),this.openclawConfigDir=e.openclawConfigDir??T0(Ky(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=T0(e,".env");if(await jy(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await po(e,{recursive:!0});let o=Jy({...process.env,...Zc(this.paths.agentEnvFile)});if(await Wy(r,o,"utf8"),process.platform!=="win32")try{await qy(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=await Ge(e.agentId,this.paths).catch(()=>null),o=Qs(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(T=>le.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(T=>le.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let T=await Ge(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Ye(T,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let T=await Ge(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Ye(T,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ze(e.agentId,this.paths),h=o?"cloud":"local",x=e.framework==="openclaw"&&h==="local",m;x&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=m??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),b=e.workspace??w??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&ed(e.framework)&&await nr(e.framework,_.signal);let T=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await po(u.root,{recursive:!0}),await po(b,{recursive:!0}),await po(u.logs,{recursive:!0}),T(),x||await sr(b,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(h==="cloud"?await Ta(b,"cloud"):await Ta(b,"local",td)),T();let R=i,y=Nf({model:e.model??R?.model}),D=Af(e._meta)??R?.accountId,O=e.patToken??R?.patToken,B=h==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(I=new fo({agentId:e.agentId,framework:e.framework,workspace:b,model:y.model??_t,deployType:h,...D?{accountId:D}:{},...O?{patToken:O}:{},...B?{modelInfo:B}:{}}),I.status="ok",R?.sessions){let $=h==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[J,ie]of Object.entries(R.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:J,framework:e.framework,fallback:oe.permissionMode})):En(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:J,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:J,framework:e.framework,deployType:h}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),I.sessions.set(J,oe)}let te=Object.keys(R.sessions).length;te>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:te})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:b,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:y.model};h==="cloud"&&(M.deployType="cloud"),D&&(M.accountId=D),O&&(M.patToken=O),B&&(M.modelInfo=B),R?.skills&&(M.skills=R.skills),R?.agentName&&(M.agentName=R.agentName),R?.description&&(M.description=R.description),e.framework==="openclaw"&&h==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,b)):le.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 $=[...M.skills??[]],te=new Map($.map((oe,L)=>[oe.skillId,L])),J=await Promise.allSettled(V.map(oe=>$c({agentId:e.agentId,workspace:b,framework:e.framework,skill:oe}))),ie=0;for(let[oe,L]of J.entries()){let G=V[oe];G&&(L.status==="fulfilled"?(Vc($,te,L.value),ie++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:G.skillId,skillName:G.skillName,err:String(L.reason)}))}ie>0&&(M.skills=$,le.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:V.length}))}return await Ye(M,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:h}),{ok:!0,agentId:e.agentId,workspace:b,framework:e.framework}}catch(T){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(T)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Hy(u.root,{recursive:!0,force:!0}).catch(R=>le.warn("rm agent dir failed (ignored)",{err:String(R)})),T instanceof C?T:new C("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&ed(e.framework))u=Yy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);ed(e.framework)&&!ss(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await nr(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let m=e.sessions.get(i),w=Wt(e)?m?.permissionMode??k0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv(),w)}try{return await x.start(),await x.initialize(Qy),x}catch(m){let w=x instanceof Pt?x.getStderrTail():[];throw w.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof C?m.code:"unknown",recentStderr:w}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",R0(o),{cause:{reason:C0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?i:new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:Xy}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",R0(r),{cause:{reason:C0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,h=Qc(o);if(r.deployType==="local"){let b=await this.ensureOpenclawDefaultAgent();return new Dr({command:u,cwd:b.workspace,agentId:b.id,sessionName:h})}let x=await A0(),m=i?Gf(i,c,d):null,w;if(m){let b=Uc(o),v=m.models[0]?.id??_t,I=`${b}/${v}`;if(!this.ensuredProviders.has(I)){let A=this.getOpenclawConfig();await A.ensureProvider(b,m),await A.addModelToAllowlist(I),this.ensuredProviders.add(I)}w=I}return new Dr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:h,...x?{gatewayToken:x}:{},...w?{slashModelOnStart:w}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Uc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(u){d=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){d=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as M0}from"node:crypto";import{promises as cE}from"node:fs";import{basename as B0}from"node:path";je();ne();import{promises as nE}from"node:fs";import{basename as rE}from"node:path";var P0=U("file-upload"),iE="/api/coze_claw/file/agent_upload",sE=6e4;async function O0(t,e={}){let i=`${no(io(e.handshakeBase))}${iE}`,o=e.timeoutMs??sE,c=await nE.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",...br(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);P0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:u,body:d,signal:h.signal}),w=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${w}: ${v.slice(0,200)}`)}let b=await m.json();if(b.code!==void 0&&b.code!==0)throw new C("UPLOAD_FAILED",`upload code=${b.code} msg=${b.msg??"-"} logid=${w}`);let _=b.data?.file?.file_url;if(!_)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(b).slice(0,200)}`);return P0.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(m){throw m instanceof C?m:m.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${rE(t.path)}`):new C("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}je();ne();import{extname as oE}from"node:path";var aE={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function L0(t){let e=oE(t).toLowerCase();return aE[e]??"application/octet-stream"}ke();var mo=U("agent-send"),N0=50*1024*1024;function F0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function z0(t,e,r,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,h<2&&(mo.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function U0(t,e){let{session:r,runtime:i}=F0(e.core,t.agentId,t.sessionId);if(!await Qr(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await cE.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>N0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${N0}`);let c=await L0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??B0(t.path),u;try{u=await O0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw mo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof C?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:M0(),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 z0(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),mo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function G0(t,e){let{session:r,runtime:i}=F0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??B0(t.path),c={sessionUpdate:"group_file",messageId:M0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await z0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),mo.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function q0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}nn();yn();ne();var Ot=U("coze-cli-installer"),H0="@coze/cli@latest",dE="coze",j0="0.1.8",lE=5e3,uE=5e3,fE=9e4,W0=1e4,Bi=null,wo=!1;async function nd(t,e={}){if(wo)return;if(Bi)return Bi;let r=e.exec??a0;return Bi=(async()=>{try{let i=await hE(dE,r),o=!1;if(i){let d=await xE(r);if(d===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(q0(d,j0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:j0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),wo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:H0,mode:c});try{await r("npm",["i","-g","--prefer-online",H0],{timeout:fE,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(d){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){wo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:W0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Ot.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:W0}),Ot.info("coze auth login ok")}catch(d){Ot.warn("coze auth login failed",{err:String(d)});return}wo=!0}finally{Bi=null}})(),Bi}async function hE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:lE});return Ia(i)}catch{return}}async function xE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:uE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Xr();ke();var pE=10*6e4;function K0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?pE:e}function _o(t){return rr(t??Y().configFile)}function Fi(t,e){return ir(e??Y().configFile,t)}import{randomBytes as NE}from"node:crypto";Qn();je();ne();import{createReadStream as gE}from"node:fs";import{mkdir as mE,readFile as wE,realpath as _E,stat as yE,writeFile as EE}from"node:fs/promises";import{basename as vE,dirname as rd,isAbsolute as bE,join as SE,relative as IE,resolve as $0,sep as AE}from"node:path";import{createInterface as TE}from"node:readline";var J0=U("fs-rpc"),zi=He("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Z0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>zi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${zi} bytes`);let i=await X0(t.path,e);return await mE(rd(i),{recursive:!0}),await EE(i,t.content,"utf8"),J0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Y0(t,e){let r=await X0(t.path,e),i=await yE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>zi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${zi} bytes`);let c;if(o&&i.size>zi)c=await CE(r,t.line??1,t.limit);else{let d=await wE(r,"utf8");if(o){let u=d.split(`
|
|
100
|
-
`),
|
|
101
|
-
`)}else c=d}return
|
|
102
|
-
`)}async function X0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([V0($0(e)),V0($0(t))]),o=IE(r,i);if(RE(o,AE,bE(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function RE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function V0(t){let e=[],r=t;for(;r!==rd(r);)try{let i=await _E(r);return e.length?SE(i,...e.reverse()):i}catch{e.push(vE(r)),r=rd(r)}return t}ne();var Q0=U("prompt-multimodal"),eh=10*1024*1024,kE=15e3,DE=6;async function th(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 PE(d))}}let o=Array.from({length:Math.min(DE,t.length)},()=>i());return await Promise.all(o),e}function nh(t){return t.some(e=>e.type==="image")}async function PE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!to(e.uri))return t;try{let{buf:r,contentType:i}=await LE(e.uri),o=e.mimeType||OE(i)||"application/octet-stream";return Q0.info("image uri fetched and inlined",{uri:e.uri,bytes:r.length,mimeType:o}),{type:"image",data:r.toString("base64"),mimeType:o}}catch(r){return Q0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function OE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function LE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),kE);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new Error(`HTTP ${i.status} ${i.statusText}`);let o=await i.arrayBuffer();if(o.byteLength>eh)throw new Error(`image too large: ${o.byteLength} bytes (max ${eh})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();je();ne();var j=U("core"),ME=3e4,BE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,FE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",zE="\u5BA1\u6279\u5DF2\u8D85\u65F6",UE=3e4,yo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Cr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=K0(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),j.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){j.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(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),j.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){j.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&j.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,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)=>{j.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Mi(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){j.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(_n(o,{code:X.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>j.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:X.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){j.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:X.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(ao(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&BE.test(i)?this.currentCozeEnv=i:i&&j.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,X.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):j.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Tr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Tr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Tr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,X.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):j.warn("drop unknown notification",{method:e.method})}catch(o){j.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(_n(r,Oi(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 h=o.sessions.get(c);if(h?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,m=eo(r._meta);return j.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,FE,x,m)}}let d=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,h}finally{j.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}=Cf(i);switch(r){case"session/new":{let c=GE();return j.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return j.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Wt(e)?Tf(i._meta):void 0;if(u!==void 0&&!En(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${Xc(e.framework)}`);let h=await this.ensureRuntime(e,d);if(u!==void 0&&h.permissionMode===void 0&&(h.permissionMode=u,await this.persistSessionMapping(e)),h.replySeq=0,await this.ensureDownstream(e,d,h),!h.downstream||!h.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&h.permissionMode!==void 0&&h.permissionMode!==u){let b=h.permissionMode;h.permissionMode=u,await this.persistSessionMapping(e);try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(_){throw h.permissionMode=b,await this.persistSessionMapping(e).catch(()=>{}),_}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(h.acpSessionId,x):e.activeTriggers.delete(h.acpSessionId);let m=eo(i._meta);if(m?e.activeGroupIds.set(h.acpSessionId,m):e.activeGroupIds.delete(h.acpSessionId),m&&h.cozeGroupId!==m&&(h.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&nh(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await th(c.prompt);try{let b=await h.downstream.sessionPrompt({...c,sessionId:h.acpSessionId,prompt:w});return h.lastActiveAt=Date.now(),b}catch(b){if(b instanceof C&&b.code==="AGENT_APPROVAL_TIMEOUT"){let _=h.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),h.pendingPermission=void 0);let v=h.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=v?e.activeGroupIds.get(v):void 0;return j.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,h,d,zE,I,A)}throw b}finally{if(e.activeTriggers.delete(h.acpSessionId),e.activeGroupIds.delete(h.acpSessionId),h.pendingPermission=void 0,h.reloadAfterTurn){h.reloadAfterTurn=!1;let b=h.downstream;b&&(h.downstream=void 0,j.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:h.acpSessionId}),b.stop("reload-after-turn").catch(_=>j.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else h.downstream?.isAlive()&&this.armIdleTimer(e,d,h)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let h=e.getSessionQueue(d);h.size>0&&(j.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:h.size}),h.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,h=eo(i._meta);if(!d)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Wt(e))throw e.framework==="openclaw"?new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new C("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!En(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${Xc(e.framework)}`);if(h)return await this.handleGroupSetMode(e,h,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let m=x.permissionMode;if(x.permissionMode=u,await this.persistSessionMapping(e),x.downstream?.isAlive()&&x.acpSessionId)try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(w){throw x.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),w}else j.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new C("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 j.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};j.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,h=d.runtime.acpSessionId;u?.isAlive()&&h&&c.push({downstream:u,acpSessionId:h,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let h of o)h.runtime.permissionMode=h.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Wt(e)&&(c.permissionMode=e.framework==="claude-code"?td:D0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(wt.GEN_MODEL_TOKEN,i,UE);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(Mi(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,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(j.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),j.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){j.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw j.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),await h.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId),Wt(e)&&i.acpSessionId&&i.permissionMode)try{await h.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){j.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(Mi(i),this.isRuntimeBusy(e,i)){j.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)){j.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}j.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=>j.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(Ar("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(Ar("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>j.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){j.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){j.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(jE(r)){j.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"&&Wt(e)){let m=d.currentModeId;En(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(w=>j.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof m=="string"&&!En(e.framework,m)&&j.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},h=e.activeTriggers.get(i);h&&(u.cozeTriggerMsgId=h);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Ar("session/update",{...r,sessionId:o,_meta:u})).catch(m=>j.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}j.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:X.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await Z0(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await Y0(c,o);r.respondAgentRequest(i.id,d)}}catch(o){j.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Oi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,h=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let m=u?e.activeGroupIds.get(u):void 0;m&&(x.cozeGroupId=m);let w=u?this.reverseSessionId(e,u):void 0,b=w?e.sessions.get(w):void 0;b&&(b.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:w}),j.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Di(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),j.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:X.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(j.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&qE(e.result,o),j.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new oo(e.error)):i.value.resolve(e.result);return}j.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 j.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=ME){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Di(o,e,r)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(h)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Wt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ei(e.agentId,r,this.paths)}catch(r){j.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(_n(e,{code:r,message:i,data:{bridgeVersion:Ir}}))}};function GE(){return NE(16).toString("hex")}function qE(t,e){if(!t||typeof t!="object"){j.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){j.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"){j.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&j.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var HE=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function jE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let r=e.content;if(!r||typeof r!="object")return!1;let i=r;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return HE.some(c=>o.startsWith(c))}ne();ke();import{randomBytes as WE}from"node:crypto";import{chmod as KE,mkdir as $E,writeFile as rh}from"node:fs/promises";import{createServer as VE}from"node:http";import{dirname as JE}from"node:path";var ZE=1e6,id=U("ipc"),Eo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Y()}async start(){this.token=WE(32).toString("hex");let e=VE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),id.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await $E(JE(this.paths.portFile),{recursive:!0}),await rh(this.paths.portFile,String(this.port),"utf8"),await rh(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await KE(this.paths.tokenFile,384)}catch(e){id.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Ui(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Ui(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await YE(e)}catch(u){Ui(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Ui(r,200,u??{ok:!0})}catch(u){id.error("IPC handler failed",{key:o,err:String(u)}),Ui(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Ui(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function YE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>ZE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var Ax=bt(xh(),1);var Pb=bt(dx(),1),Ob=bt(Bo(),1),Lb=bt(Lr(),1),Nb=bt(md(),1),Mb=bt(yd(),1),Bb=bt(Ad(),1),_x=bt(Go(),1),Fb=bt(mx(),1);var yx=_x.default;je();ne();var Ce=U("upstream.frontier"),vx="application/json",bx="none",Ub=15e3;function Gb(t){class e extends yx{constructor(i){super(i,kf,{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(pl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let 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 Ji=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:Df,...br(this.opts.ppeOverride)},r=Gb(e),i=Of(this.opts.urlOverride),o={url:i,ws:r,fpID:Rf,aID:ro,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:vx,force:!0},payloadEncoding:{encoding:bx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Ax.FWS(o),d=!1,u=null,h,x,m=new Promise((_,v)=>{h=_,x=v}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?x(_):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Ce.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(I=>Ce.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,Ce.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{Ce.warn("frontier error",{code:_.code,msg:_.message}),w(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let b=this.opts.openTimeoutMs??Ub;u=setTimeout(()=>{w(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${b}ms (handshake or upgrade slow)`))},b),await c.connect();try{await m}catch(_){try{c.close(1e3,"open failed")}catch(v){Ce.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){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 C("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 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;Sx(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:vx,payloadEncoding:bx})}catch(u){throw Ce.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){Ce.debug("drop non-adapter frontier frame",{service:r});return}let i=jb(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;Sx(c)||Ce.info("frontier frame in",{logid:Hb(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:qb(i)}),Promise.resolve(this.handler(o)).catch(d=>Ce.warn("frontier frame handler threw",{err:String(d)}))}};function Sx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Ix=2e3;function qb(t){return t.length<=Ix?t:`${t.slice(0,Ix)}...<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}}ne();var Cd=U("upstream.switchable"),Ho=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Cd.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 Cd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Cd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var Rd=U("upstream"),Ur=class{handler=null;async start(){Rd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Rd.info("NoopUpstream stopped",{reason:e})}async send(e){Rd.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)}};je();ne();ne();ke();import{promises as kd}from"node:fs";import{dirname as Wb}from"node:path";var Kb=U("pat-token-store");async function jo(t=Y()){try{let r=(await kd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Kb.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Zi(t,e=Y()){if(!t)throw new Error("writePatToken: empty patToken");await kd.mkdir(Wb(e.patTokenFile),{recursive:!0}),await kd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as Wo}from"node:fs";import{join as $b}from"node:path";function Vb(t,e){return`#!/bin/sh
|
|
98
|
+
`}function Xy(t){if(t.includes(`
|
|
99
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Qy={path:"",version:"cloud-deployed"},Sf="openclaw_gateway_unavailable",eb="openclaw_default_agent_missing";function Af(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 tb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},nb=6e4,mo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Yy,this.createTimeoutMs=e.createTimeoutMs??nb,this.detectorFactory=e.detectorFactory??(()=>new Wn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new go({command:r})),this.openclawConfigDir=e.openclawConfigDir??vf(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=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=vf(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=Zy({...process.env,...Yc(this.paths.agentEnvFile)});await sn(r,o,{mode:384}),le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=await Me(e.agentId,this.paths).catch(()=>null),o=no(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(D=>le.warn("dispose stale agent failed (ignored)",{err:String(D)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(D=>le.warn("dispose drifted agent failed (ignored)",{err:String(D)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let D=await Me(e.agentId,this.paths).catch(()=>null);D&&(D.patToken=e.patToken,await Xe(D,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let D=await Me(e.agentId,this.paths).catch(()=>null);D&&(D.modelInfo=e.modelInfo,await Xe(D,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ze(e.agentId,this.paths),x=o?"cloud":"local",p=e.framework==="openclaw"&&x==="local",m;p&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=m??(p?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,T=!1;try{o&&td(e.framework)&&await sr(e.framework,_.signal);let D=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await ed(u.root,{recursive:!0}),await ed(S,{recursive:!0}),await ed(u.logs,{recursive:!0}),D(),p||await cr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ta(S,"cloud"):await Ta(S,"local",nd)),D();let k=i,y=O0({model:e.model??k?.model}),R=b0(e._meta)??k?.accountId,P=e.patToken??k?.patToken,B=x==="cloud"?e.modelInfo??k?.modelInfo:void 0;if(A=new ho({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??bt,deployType:x,...R?{accountId:R}:{},...P?{patToken:P}:{},...B?{modelInfo:B}:{}}),A.status="ok",k?.sessions){let J=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(k.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};J?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:oe.permissionMode})):Sn(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:x}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),A.sessions.set(Z,oe)}let te=Object.keys(k.sessions).length;te>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:te})}this.registry.register(A),T=!0;let N={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:k?.createdAt??Date.now(),sessions:k?.sessions??{},model:y.model};x==="cloud"&&(N.deployType="cloud"),R&&(N.accountId=R),P&&(N.patToken=P),B&&(N.modelInfo=B),k?.skills&&(N.skills=k.skills),k?.agentName&&(N.agentName=k.agentName),k?.description&&(N.description=k.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Y=e.initialSkills??[];if(Y.length>0){let J=[...N.skills??[]],te=new Map(J.map((oe,O)=>[oe.skillId,O])),Z=await Promise.allSettled(Y.map(oe=>$c({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),ie=0;for(let[oe,O]of Z.entries()){let q=Y[oe];q&&(O.status==="fulfilled"?(Vc(J,te,O.value),ie++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:q.skillId,skillName:q.skillName,err:String(O.reason)}))}ie>0&&(N.skills=J,le.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Y.length}))}return await Xe(N,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(D){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(D)}),T&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(u.root,{recursive:!0,force:!0}).catch(k=>le.warn("rm agent dir failed (ignored)",{err:String(k)})),D instanceof C?D:new C("AGENT_SPAWN_FAILED",String(D),{cause:D})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&td(e.framework))u=Qy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);td(e.framework)&&!cs(e.framework)&&(le.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 m=e.sessions.get(i),w=$t(e)?m?.permissionMode??If:"full-access";p=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),w)}try{return await p.start(),await p.initialize(tb),p}catch(m){let w=p instanceof Ot?p.getStderrTail():[];throw w.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof C?m.code:"unknown",recentStderr:w}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",Af(o),{cause:{reason:Sf}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?i:new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:eb}})}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",Af(r),{cause:{reason:Sf}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,x=Qc(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Lr({command:u,cwd:S.workspace,agentId:S.id,sessionName:x})}let p=await Ef(),m=i?F0(i,c,d):null,w;if(m){let S=Uc(o),v=m.models[0]?.id??bt,A=`${S}/${v}`;if(!this.ensuredProviders.has(A)){let T=this.getOpenclawConfig();await T.ensureProvider(S,m),await T.addModelToAllowlist(A),this.ensuredProviders.add(A)}w=A}return new Lr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...p?{gatewayToken:p}:{},...w?{slashModelOnStart:w}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Uc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(u){d=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){d=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as Pf}from"node:crypto";import{promises as lb}from"node:fs";import{basename as Of}from"node:path";We();ne();import{promises as ib}from"node:fs";import{basename as sb}from"node:path";var Cf=H("file-upload"),ob="/api/coze_claw/file/agent_upload",ab=6e4;async function Df(t,e={}){let i=`${io(oo(e.handshakeBase))}${ob}`,o=e.timeoutMs??ab,c=await ib.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",...Ir(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);Cf.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:u,body:d,signal:x.signal}),w=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${w}: ${v.slice(0,200)}`)}let S=await m.json();if(S.code!==void 0&&S.code!==0)throw new C("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let _=S.data?.file?.file_url;if(!_)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return Cf.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(m){throw m instanceof C?m:m.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${sb(t.path)}`):new C("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(p)}}We();ne();import{extname as cb}from"node:path";var db={".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 Rf(t){let e=cb(t).toLowerCase();return db[e]??"application/octet-stream"}Oe();var wo=H("agent-send"),kf=50*1024*1024;function Lf(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 Nf(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&&(wo.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(m=>setTimeout(m,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function Mf(t,e){let{session:r,runtime:i}=Lf(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 lb.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>kf)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${kf}`);let c=await Rf(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 d=t.name??Of(t.path),u;try{u=await Df({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(p){throw wo.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:Pf(),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 Nf(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),wo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name: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 Bf(t,e){let{session:r,runtime:i}=Lf(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??Of(t.path),c={sessionUpdate:"group_file",messageId:Pf(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await Nf(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),wo.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function zf(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}rn();Kt();ne();var Lt=H("coze-cli-installer"),Ff="@coze/cli@latest",ub="coze",Uf="0.1.8",fb=5e3,xb=5e3,hb=9e4,Gf=1e4,Ui=null,_o=!1;async function rd(t,e={}){if(_o)return;if(Ui)return Ui;let r=e.exec??I0;return Ui=(async()=>{try{let i=await pb(ub,r),o=!1;if(i){let d=await gb(r);if(d===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(zf(d,Uf))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:Uf}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),_o=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:Ff,mode:c});try{await r("npm",["i","-g","--prefer-online",Ff],{timeout:hb,maxBuffer:10*1024*1024}),Lt.info("coze-cli install ok")}catch(d){Lt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){_o=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:Gf}),Lt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Lt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:Gf}),Lt.info("coze auth login ok")}catch(d){Lt.warn("coze auth login failed",{err:String(d)});return}_o=!0}finally{Ui=null}})(),Ui}async function pb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:fb});return Aa(i)}catch{return}}async function gb(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:xb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}on();Oe();var mb=10*6e4;function Hf(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?mb:e}function yo(t){return or(t??Q().configFile)}function Gi(t,e){return ar(e??Q().configFile,t)}import{randomBytes as Bb}from"node:crypto";nr();We();ne();import{createReadStream as wb}from"node:fs";import{mkdir as _b,readFile as yb,realpath as bb,stat as Eb,writeFile as vb}from"node:fs/promises";import{basename as Sb,dirname as id,isAbsolute as Ab,join as Ib,relative as Tb,resolve as qf,sep as Cb}from"node:path";import{createInterface as Db}from"node:readline";var Wf=H("fs-rpc"),Hi=je("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Kf(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Hi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Hi} bytes`);let i=await Vf(t.path,e);return await _b(id(i),{recursive:!0}),await vb(i,t.content,"utf8"),Wf.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function $f(t,e){let r=await Vf(t.path,e),i=await Eb(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Hi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Hi} bytes`);let c;if(o&&i.size>Hi)c=await Rb(r,t.line??1,t.limit);else{let d=await yb(r,"utf8");if(o){let u=d.split(`
|
|
100
|
+
`),x=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?x+t.limit:void 0;c=u.slice(x,p).join(`
|
|
101
|
+
`)}else c=d}return Wf.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Rb(t,e,r){let i=Db({input:wb(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 x of i)if(u>=o&&u<c&&d.push(x),u++,u>=c)break}finally{i.close()}return d.join(`
|
|
102
|
+
`)}async function Vf(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([jf(qf(e)),jf(qf(t))]),o=Tb(r,i);if(kb(o,Cb,Ab(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function kb(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function jf(t){let e=[],r=t;for(;r!==id(r);)try{let i=await bb(r);return e.length?Ib(i,...e.reverse()):i}catch{e.push(Sb(r)),r=id(r)}return t}ne();var Jf=H("prompt-multimodal"),Yf=10*1024*1024,Pb=15e3,Ob=6;async function Zf(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 Lb(d))}}let o=Array.from({length:Math.min(Ob,t.length)},()=>i());return await Promise.all(o),e}function Xf(t){return t.some(e=>e.type==="image")}async function Lb(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 Mb(e.uri),o=e.mimeType||Nb(i)||"application/octet-stream";return Jf.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 Jf.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Nb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function Mb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Pb);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>Yf)throw new Error(`image too large: ${o.byteLength} bytes (max ${Yf})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}an();We();ne();var $=H("core"),zb=3e4,Fb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,Ub="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",Gb="\u5BA1\u6279\u5DF2\u8D85\u65F6",Hb=3e4,bo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new kr;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=Hf(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(),$.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){$.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),$.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){$.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&$.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{$.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Fi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){$.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:ee.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>$.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:ee.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){$.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:ee.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(lo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&Fb.test(i)?this.currentCozeEnv=i:i&&$.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):$.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Rr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Rr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Rr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):$.warn("drop unknown notification",{method:e.method})}catch(o){$.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,m=ro(r._meta);return $.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,Ub,p,m)}}let d=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,x}finally{$.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=v0(i);switch(r){case"session/new":{let c=qb();return $.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return $.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=$t(e)?E0(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: ${Xc(e.framework)}`);let x=await this.ensureRuntime(e,d);if(u!==void 0&&x.permissionMode===void 0&&(x.permissionMode=u,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,d,x),!x.downstream||!x.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let S=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(_){throw x.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let p=i._meta?.cozeTriggerMsgId;p?e.activeTriggers.set(x.acpSessionId,p):e.activeTriggers.delete(x.acpSessionId);let m=ro(i._meta);if(m?e.activeGroupIds.set(x.acpSessionId,m):e.activeGroupIds.delete(x.acpSessionId),m&&x.cozeGroupId!==m&&(x.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Xf(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await Zf(c.prompt);try{let S=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:w});return x.lastActiveAt=Date.now(),S}catch(S){if(S instanceof C&&S.code==="AGENT_APPROVAL_TIMEOUT"){let _=x.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),x.pendingPermission=void 0);let v=x.acpSessionId,A=v?e.activeTriggers.get(v):void 0,T=v?e.activeGroupIds.get(v):void 0;return $.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,x,d,Gb,A,T)}throw S}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let S=x.downstream;S&&(x.downstream=void 0,$.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:x.acpSessionId}),S.stop("reload-after-turn").catch(_=>$.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,d,x)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let x=e.getSessionQueue(d);x.size>0&&($.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:x.size}),x.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,x=ro(i._meta);if(!d)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!$t(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: ${Xc(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,u);let p=e.sessions.get(d)??await this.ensureRuntime(e,d);if(p.permissionMode===u)return{};let m=p.permissionMode;if(p.permissionMode=u,await this.persistSessionMapping(e),p.downstream?.isAlive()&&p.acpSessionId)try{await p.downstream.setSessionMode({sessionId:p.acpSessionId,modeId:u})}catch(w){throw p.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),w}else $.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.permissionMode});if(o.length===0)return $.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};$.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,x=d.runtime.acpSessionId;u?.isAlive()&&x&&c.push({downstream:u,acpSessionId:x,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return $t(e)&&(c.permissionMode=e.framework==="claude-code"?nd:Tf),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(yt.GEN_MODEL_TOKEN,i,Hb);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(Fi(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,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new C("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 x;try{x=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&($.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),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}),$.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){$.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let m=await x.sessionNew({cwd:e.workspace});i.acpSessionId=m.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 $.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),$t(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(p){$.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(Fi(i),this.isRuntimeBusy(e,i)){$.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){$.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}$.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>$.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Dr("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(Dr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>$.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){$.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){$.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(Kb(r)){$.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=r.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&$t(e)){let m=d.currentModeId;Sn(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(w=>$.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof m=="string"&&!Sn(e.framework,m)&&$.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(u.cozeTriggerMsgId=x);let p=e.activeGroupIds.get(i);p&&(u.cozeGroupId=p),this.upstream.send(Dr("session/update",{...r,sessionId:o,_meta:u})).catch(m=>$.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}$.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:ee.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await Kf(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await $f(c,o);r.respondAgentRequest(i.id,d)}}catch(o){$.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,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 m=u?e.activeGroupIds.get(u):void 0;m&&(p.cozeGroupId=m);let w=u?this.reverseSessionId(e,u):void 0,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta: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:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Li(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),$.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?($.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&jb(e.result,o),$.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new co(e.error)):i.value.resolve(e.result);return}$.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),d=e.get(c);if(d)return $.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=zb){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,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)),d(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&&$t(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ni(e.agentId,r,this.paths)}catch(r){$.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(vn(e,{code:r,message:i,data:{bridgeVersion:Cr}}))}};function qb(){return Bb(16).toString("hex")}function jb(t,e){if(!t||typeof t!="object"){$.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){$.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){$.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&$.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var Wb=["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 Kb(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 Wb.some(c=>o.startsWith(c))}on();ne();Oe();import{randomBytes as $b}from"node:crypto";import{createServer as Vb}from"node:http";var Jb=1e6,Qf=H("ipc"),Eo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Q()}async start(){this.token=$b(32).toString("hex");let e=Vb((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(),Qf.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}`){qi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){qi(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await Yb(e)}catch(u){qi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);qi(r,200,u??{ok:!0})}catch(u){Qf.error("IPC handler failed",{key:o,err:String(u)}),qi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function qi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function Yb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>Jb)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=Ft(Jx(),1),wv=Ft(ko(),1),_v=Ft(Br(),1),yv=Ft(pd(),1),bv=Ft(wd(),1),Ev=Ft(Sd(),1),ih=Ft(No(),1),vv=Ft(rh(),1);var sh=ih.default;We();ne();var{FWS:Fv}=gh(),ke=H("upstream.frontier"),wh="application/json",_h="none",Uv=15e3;function Gv(t){class e extends sh{constructor(i){super(i,C0,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>ke.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(xl("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");ke.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){ke.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){ke.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:D0,...Ir(this.opts.ppeOverride)},r=Gv(e),i=k0(this.opts.urlOverride),o={url:i,ws:r,fpID:T0,aID:so,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:wh,force:!0},payloadEncoding:{encoding:_h,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Fv(o),d=!1,u=null,x,p,m=new Promise((_,v)=>{x=_,p=v}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?p(_):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;ke.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(A=>ke.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=_=>{this.opened=!1,ke.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{ke.warn("frontier error",{code:_.code,msg:_.message}),w(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??Uv;u=setTimeout(()=>{w(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await m}catch(_){try{c.close(1e3,"open failed")}catch(v){ke.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){ke.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw ke.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?(ke.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;yh(c)||ke.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:wh,payloadEncoding:_h})}catch(u){throw ke.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){ke.debug("drop non-adapter frontier frame",{service:r});return}let i=jv(e);if(!i){ke.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){ke.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){ke.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;yh(c)||ke.info("frontier frame in",{logid:qv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Hv(i)}),Promise.resolve(this.handler(o)).catch(d=>ke.warn("frontier frame handler threw",{err:String(d)}))}};function yh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var bh=2e3;function Hv(t){return t.length<=bh?t:`${t.slice(0,bh)}...<truncated, total ${t.length} chars>`}function qv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function jv(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ne();var Cd=H("upstream.switchable"),jo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Cd.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 Cd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Cd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var Dd=H("upstream"),qr=class{handler=null;async start(){Dd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Dd.info("NoopUpstream stopped",{reason:e})}async send(e){Dd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};We();ne();on();ne();Oe();import{promises as Wv}from"node:fs";var Eh=H("pat-token-store");async function Wo(t=Q()){try{let r=(await Wv.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Eh.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"&&Eh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Qi(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await sn(e.patTokenFile,t,{mode:384})}Oe();Oe();import{promises as Ko}from"node:fs";import{join as Kv}from"node:path";function $v(t,e){return`#!/bin/sh
|
|
103
103
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
104
|
-
`}function
|
|
104
|
+
`}function Vv(t,e){return`@echo off\r
|
|
105
105
|
"${e}" "${t}" %*\r
|
|
106
|
-
`}async function Tx(t,e=Y()){let r=e.binDir;await Wo.mkdir(r,{recursive:!0});let i=$b(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Jb(t,o):Vb(t,o);return await Wo.readFile(i,"utf8").catch(()=>null)===c||(await Wo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Wo.chmod(i,493)),r}ne();ke();import{execSync as Cx}from"node:child_process";import{readFileSync as Rx,unlinkSync as Zb}from"node:fs";import{mkdir as Yb,open as Xb,readFile as kx,unlink as Dd,writeFile as Qb}from"node:fs/promises";import{dirname as eS}from"node:path";var tS=U("single-instance"),nS=t=>new Promise(e=>setTimeout(e,t)),Ko=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Y().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Li(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&&tS.warn("removing stale pid file",{stalePid:i}),await Qb(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 kx(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Dd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await kx(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 Yb(eS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await Xb(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 nS(this.claimLockIntervalMs);continue}await Dd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Dd(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=Rx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Rr)||r.includes("lib/index.js"))}catch{}try{let r=Cx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Rr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Cx(`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{Rx(this.pidFile,"utf8").trim()===String(this.selfPid)&&Zb(this.pidFile)}catch{}})}};$o();ne();var Vn=U("daemon.upstream-watchdog"),lS=12e4,uS=9e5,fS=3e4;function Od(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Vo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",lS),this.hardMs=e.hardMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",uS),this.intervalMs=e.intervalMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",fS),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?.(),Vn.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&&Vn.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&&Vn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Vn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Vn.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,Vn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Vn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var q=U("daemon");async function Ox(){let t=Y();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&hl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:L=>Ze(L,t).logs,listAgentIds:()=>os(t)});let e=new Ko({processTitle:Rr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await _o(),o=i??{};is({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");let c=new Ho(new Ur),d=null,u=new yo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(L,G,W,se)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(L,G,W,se)}}),h=new go({paths:t,config:o,registry:u});d=h;let x,m,w=null,b={},_,v=null,I=null,A=null,T=new vn;function R(L,G){return T.enqueue(()=>D(L,G))}function y(){I||(I=new Vo({isConnected:()=>c.isConnected(),forceReconnect:()=>A?R(A,{force:!0}):void 0,onFatal:L=>{if(process.env[Yi]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:L});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:L}),process.exit(1)}})),I.start()}async function D(L,G){let W=L,se=W?.privatecode;if(!se)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Ve=Ci(W.env),he=W.handshake_url,xe=W.frontier_url,vt=Px(W.env,he,xe);if(A=W,!G?.force&&x===se&&m===vt){let me=await hS(t);return u.agents.size===0&&me?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Zo(t,h).catch(Se=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Se)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let lt=!!x&&x!==se,Yt=m!==void 0&&m!==vt,Bt=lt||Yt,Xt=await Mc({privatecode:se,...he?{endpoint:he}:{},ppeOverride:Ve});if(Bt){q.warn("connect config switched, resetting agents",{pcChanged:lt,envChanged:Yt,previousPc:x?Jo(x):"",nextPc:Jo(se)});for(let me of[...u.agents.values()])await me.dispose("connect config switch").catch(()=>{}),u.agents.delete(me.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Ur,"connect switch").catch(()=>{})}w=Xt.deviceId,is({deviceId:w,pid:process.pid}),nd({patToken:se,env:W.env}).catch(me=>q.warn("coze-cli setup error (ignored)",{err:String(me)}));let Wr=new Ji({handshake:Xt,privatecode:se,...xe?{urlOverride:xe}:{},ppeOverride:Ve,getPatTokenForAgent:me=>u.agents.get(me)?.patToken});return await c.swap(Wr,"connect"),x=se,m=vt,b=Ve,_=he,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),q.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new ki({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(me=>q.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:V})),v.start(),y(),Bt&&Zo(t,h).catch(me=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Zi(se,t).catch(me=>q.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),q.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async L=>h.createAgent(L.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},B=new so({agents:u.agents,disposeAndMarkDisconnected:async(L,G)=>{let W=u.agents.get(L);if(W){await h.cleanupOpenclawSessionProviders(W).catch(Ve=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:L,err:String(Ve)}));let se=!0;try{await W.dispose(`disconnect: ${G}`)}catch(Ve){se=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:L,err:String(Ve)}),W.status="error"}se&&(W.status="disconnected",u.unregister(L),u.disconnectedAgents.add(L))}else u.disconnectedAgents.add(L)},detailSyncer:async L=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(L)},cleanupOpenclawProviders:async L=>{await h.cleanupOpenclawSessionProviders(L)},openclawRepair:async(L,G)=>{await h.openclawRepair(L,G)},isRuntimePendingPermission:L=>u.hasPendingPermissionFor(L)});u.registerExtension("_agent/listSkills",L=>B.listSkills(L.params)),u.registerExtension("_agent/addSkills",L=>B.addSkills(L.params)),u.registerExtension("_agent/removeSkills",L=>B.removeSkills(L.params)),u.registerExtension("_agent/getFileTree",L=>B.getFileTree(L.params)),u.registerExtension("_agent/getFileContent",L=>B.getFileContent(L.params)),u.registerExtension("_agent/update",L=>B.updateAgent(L.params)),u.registerExtension("_agent/disconnect",L=>B.disconnectAgent(L.params)),u.registerExtension("_agent/switchModel",L=>B.switchModel(L.params)),u.registerExtension("_agent/reset",L=>B.resetAgent(L.params)),u.registerExtension("_agent/repair",L=>B.repairAgent(L.params));let M=new ls({paths:t,handlers:B,agentManager:h,sendDetail:L=>u.sendRequest("_agent/detail",L)});O.ref=M;let V=async L=>{await Promise.allSettled(L.map(async G=>{try{await B.disconnectAgent({agentId:G.agentId,reason:`auth_failure: code=${G.code} ${G.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:G.agentId,code:G.code,message:G.message})}catch(W){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:G.agentId,err:String(W)})}}))};c.onConnect(({initial:L})=>{q.info("frontier upstream connected, triggering detail sync",{initial:L}),M.syncAll(L?"initial-connect":"reconnect").catch(G=>q.warn("detail sync top-level error (ignored)",{err:String(G)}))});let $=new Eo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let L=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Yi]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...L?{mockScenario:L}:{}}}},{method:"POST",path:"/pair",handler:async L=>{let G=L,W=G?.privatecode,se=G?.pairing_code;if(!W||!se)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ve=Ci(G.env),he=G.handshake_url,xe=G.frontier_url,vt=Px(G.env,he,xe),lt=!!x&&x!==W,Yt=m!==void 0&&m!==vt,Bt=lt||Yt,Xt=await Mc({privatecode:W,...he?{endpoint:he}:{},ppeOverride:Ve});if(Bt){q.warn("pair config switched, resetting agents",{pcChanged:lt,envChanged:Yt,previousPc:x?Jo(x):"",nextPc:Jo(W),previousEnvKey:m??"",nextEnvKey:vt});for(let Se of[...u.agents.values()])await Se.dispose("pair config switch").catch(()=>{}),u.agents.delete(Se.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Ur,"pair switch").catch(()=>{})}w=Xt.deviceId,is({deviceId:w,pid:process.pid}),nd({patToken:W,env:G.env}).catch(Se=>q.warn("coze-cli setup error (ignored)",{err:String(Se)}));let Wr=new Ji({handshake:Xt,privatecode:W,...xe?{urlOverride:xe}:{},ppeOverride:Ve,getPatTokenForAgent:Se=>u.agents.get(Se)?.patToken});await c.swap(Wr,"pair");try{let Se=new qn;o.frameworksCache=await Se.detectAll(),await Fi(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Se){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Se)})}let me=Object.keys(o.frameworksCache??{});try{let Se=await u.sendRequest("_agent/pair",{pairCode:se,patToken:W,frameworks:me,_meta:{cozeDeviceId:w}});q.info("_agent/pair ok",{pairResult:Se}),x=W,m=vt,b=Ve,_=he,G.mock_scenario!==void 0&&(u.setMockScenario(G.mock_scenario),q.info("mock scenario set",{scenario:G.mock_scenario})),Zi(W,t).catch(Re=>q.warn("writePatToken after /pair failed (ignored)",{err:String(Re)})),v||(v=new ki({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Re=>q.warn("detailSync.retryPending failed (ignored)",{err:String(Re)})),onAuthFailures:V})),v.start(),y(),Bt&&Zo(t,h).catch(Re=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(Re)}));let Jn;return G.agent_id&&(Jn=await pS(G.agent_id,t,h,Re=>u.sendRequest("_agent/detail",Re),W).catch(Re=>(q.error("--agent-id ensureAgent failed",{agentId:G.agent_id,err:String(Re)}),{ok:!1,agentId:G.agent_id??"",note:String(Re)}))),{ok:!0,note:"paired with cloud",...Jn?{agent:Jn}:{}}}catch(Se){return q.error("_agent/pair failed",{err:String(Se)}),{ok:!1,note:`pair failed: ${String(Se)}`}}}},{method:"POST",path:"/connect",handler:L=>R(L)},{method:"POST",path:"/_agent/create",handler:async L=>{let G=L;return{ok:!0,result:await h.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(!x)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=G;return await(W.groupFile?G0:U0)(W,{core:u,patToken:x,handshakeBase:_,ppeOverride:b})}catch(W){if(W instanceof C)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async L=>{let G=L?.agent_id,W=await u.reloadAgents(G);return q.info("IPC /reload: recycled agent subprocesses",{agentId:G??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:J}=await $.start();try{await Tx(t.libEntry,t)}catch(L){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(L)})}await u.start(),gS({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new qn().detectAll(),await Fi(o),o.frameworksCache)}).catch(L=>q.warn("startup warmup error (ignored)",{err:String(L)})),bl().then(async()=>{let{probeAcpVersion:L}=await Promise.resolve().then(()=>(nn(),El));for(let G of["claude-code","codex"]){let W=await L(G);W&&q.info("acp wrapper version",{framework:G,version:W})}}).catch(L=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(L)}));let ie=null,oe={port:te,token:J,core:u,ipc:$,shutdown(L){return ie||(q.info("daemon shutdown",{reason:L}),ie=(async()=>{v?.stop(),I?.stop(),await u.stop(L),await $.stop(),await e.release()})(),ie)}};for(let L of["SIGTERM","SIGINT"])process.on(L,()=>{oe.shutdown(L).then(()=>process.exit(0))});return process.on("exit",()=>l0()),process.on("unhandledRejection",L=>{q.error("unhandledRejection",{reason:L instanceof Error?L.message:String(L),stack:L instanceof Error?L.stack:void 0})}),process.on("uncaughtException",L=>{q.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}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
`;await Xo(b,"utf8").catch(()=>null)!==_&&await TS(b,_)}return(!w||!await zd(e))&&await(t.installWrappers??DS)(e,u),h.libVersion=c,await Fi(h,e.configFile),Fd.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),w&&m?{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 zd(t){for(let e of Zr){let r=Gr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Gx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function DS(t,e){await LS(t.installLock,async()=>{if(await zd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Xi}.staging-${process.pid}-${r}`,o=Gr(i,"node_modules"),c=Gr(t.libDir,"node_modules");try{await Ux(i,{recursive:!0}),await PS(e,i),await OS(o);let d=`${c}.trash-${r}`;await zx(c,d).catch(()=>{}),await zx(o,c),await Md(d,{recursive:!0,force:!0}).catch(()=>{}),Fd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Md(i,{recursive:!0,force:!0}).catch(()=>{})}})}function PS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=at("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",h=>{d.length<8192&&(d+=h.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(u),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${d.trim().slice(0,2e3)}`))})})}async function OS(t){for(let e of Zr){let r=Gr(t,...e.split("/")),i=JSON.parse(await Xo(Gr(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=Gr(t,".bin",o),d=await Gx(c);process.platform!=="win32"&&!(d.mode&73)&&await AS(c,d.mode|73).catch(()=>{})}}async function LS(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Md(t,{force:!0}).catch(()=>{})}}Ea();ne();ke();import{closeSync as Hx,fstatSync as jx,openSync as Wx,readFileSync as NS,readSync as MS,readdirSync as BS,statSync as FS}from"node:fs";import{join as Qo}from"node:path";var zS=new Set(["debug","info","warn","error"]);function Kx(t){let e=t,r=In(e,"--agent-id");e=r.rest;let i=In(e,"--date");e=i.rest;let o=In(e,"-n","--lines");e=o.rest;let c=In(e,"--level");e=c.rest;let d=In(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),h=Number.isInteger(u)&&u>=0?u:200,x=c.value&&zS.has(c.value)?c.value:void 0,m={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),x&&(m.level=x),d.value&&(m.grep=d.value),m}function US(t,e){return t.agentId?Qo(Ze(t.agentId,e).logs,er("agent",t.date)):Qo(e.bridgeLogsDir,er("bridge",t.date))}function GS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function qS(t,e){let r;try{r=BS(t)}catch{return[]}let i=[];for(let o of r){let c=ya(o,e);if(!c)continue;let d=0;try{d=FS(Qo(t,o)).size}catch{}i.push({file:Qo(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function $x(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"&&!gl(r,e.level))return!1}return!0}var qx={debug:"90",info:"36",warn:"33",error:"31"},HS=new Set(["ts","level","module","msg"]);function jS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Vx(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=jS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&qx[o]&&(c=`\x1B[${qx[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([x])=>!HS.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${d} ${u}${h}`}function WS(t,e,r){let c=NS(t,"utf8").split(`
|
|
110
|
-
`).
|
|
111
|
-
`)}
|
|
112
|
-
|
|
113
|
-
`)
|
|
106
|
+
`}async function vh(t,e=Q()){let r=e.binDir;await Ko.mkdir(r,{recursive:!0});let i=Kv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Vv(t,o):$v(t,o);return await Ko.readFile(i,"utf8").catch(()=>null)===c||(await Ko.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Ko.chmod(i,493)),r}ne();Oe();import{execSync as Sh}from"node:child_process";import{readFileSync as Ah,unlinkSync as Jv}from"node:fs";import{mkdir as Yv,open as Zv,readFile as Ih,unlink as Rd,writeFile as Xv}from"node:fs/promises";import{dirname as Qv}from"node:path";var eS=H("single-instance"),tS=t=>new Promise(e=>setTimeout(e,t)),$o=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Bi(r),isDaemon:r=>this.matchesDaemonTitle(r)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let r=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&eS.warn("removing stale pid file",{stalePid:i}),await Xv(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 Ih(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Rd(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 Ih(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 Yv(Qv(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await Zv(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 tS(this.claimLockIntervalMs);continue}await Rd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Rd(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=Ah(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Pr)||r.includes("lib/index.js"))}catch{}try{let r=Sh(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Pr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Sh(`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{Ah(this.pidFile,"utf8").trim()===String(this.selfPid)&&Jv(this.pidFile)}catch{}})}};Vo();ne();var Zn=H("daemon.upstream-watchdog"),dS=12e4,lS=9e5,uS=3e4;function Pd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Pd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",dS),this.hardMs=e.hardMs??Pd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",lS),this.intervalMs=e.intervalMs??Pd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",uS),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?.(),Zn.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&&Zn.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&&Zn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Zn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Zn.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,Zn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Zn.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 K=H("daemon");async function Dh(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){ul({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Ze(O,t).logs,listAgentIds:()=>ds(t)});try{let{writeFileSync:O}=await import("node:fs");O(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
|
+
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
108
|
+
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
109
|
+
`)}catch{}}let e=new $o({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 yo(),o=i??{};as({pid:process.pid}),K.info(i?"loaded bridge config":"initialized bridge config");let c=new jo(new qr),d=null,u=new bo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,q,V,se)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(O,q,V,se)}}),x=new mo({paths:t,config:o,registry:u});d=x;let p,m,w=null,S={},_,v=null,A=null,T=null,D=new An;function k(O,q){return D.enqueue(()=>R(O,q))}function y(){A||(A=new Jo({isConnected:()=>c.isConnected(),forceReconnect:()=>T?k(T,{force:!0}):void 0,onFatal:O=>{if(process.env[es]==="1"){K.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}K.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),A.start()}async function R(O,q){let V=O,se=V?.privatecode;if(!se)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Je=ki(V.env),xe=V.handshake_url,he=V.frontier_url,St=Ch(V.env,xe,he);if(T=V,!q?.force&&p===se&&m===St){let me=await fS(t);return u.agents.size===0&&me?(K.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Zo(t,x).catch(Te=>K.warn("connect-noop auto-revive error (ignored)",{err:String(Te)}))):K.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ut=!!p&&p!==se,Qt=m!==void 0&&m!==St,zt=ut||Qt,en=await Mc({privatecode:se,...xe?{endpoint:xe}:{},ppeOverride:Je});if(zt){K.warn("connect config switched, resetting agents",{pcChanged:ut,envChanged:Qt,previousPc:p?Yo(p):"",nextPc:Yo(se)});for(let me of[...u.agents.values()])await me.dispose("connect config switch").catch(()=>{}),u.agents.delete(me.agentId);u.disconnectedAgents.size>0&&(K.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new qr,"connect switch").catch(()=>{})}w=en.deviceId,as({deviceId:w,pid:process.pid}),rd({patToken:se,env:V.env}).catch(me=>K.warn("coze-cli setup error (ignored)",{err:String(me)}));let Vr=new Xi({handshake:en,privatecode:se,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:me=>u.agents.get(me)?.patToken});return await c.swap(Vr,"connect"),p=se,m=St,S=Je,_=xe,V.mock_scenario!==void 0&&(u.setMockScenario(V.mock_scenario),K.info("mock scenario set",{scenario:V.mock_scenario})),v||(v=new Oi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>N.retryPending().catch(me=>K.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:Y})),v.start(),y(),zt&&Zo(t,x).catch(me=>K.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Qi(se,t).catch(me=>K.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),K.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>x.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let P={},B=new ao({agents:u.agents,disposeAndMarkDisconnected:async(O,q)=>{let V=u.agents.get(O);if(V){await x.cleanupOpenclawSessionProviders(V).catch(Je=>K.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Je)}));let se=!0;try{await V.dispose(`disconnect: ${q}`)}catch(Je){se=!1,K.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Je)}),V.status="error"}se&&(V.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await x.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,q)=>{await x.openclawRepair(O,q)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>B.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>B.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>B.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>B.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>B.getFileContent(O.params)),u.registerExtension("_agent/update",O=>B.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>B.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>B.switchModel(O.params)),u.registerExtension("_agent/reset",O=>B.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>B.repairAgent(O.params)),u.registerExtension("_agent/upgrade",O=>B.upgradeBridge(O.params));let N=new xs({paths:t,handlers:B,agentManager:x,sendDetail:O=>u.sendRequest("_agent/detail",O)});P.ref=N;let Y=async O=>{await Promise.allSettled(O.map(async q=>{try{await B.disconnectAgent({agentId:q.agentId,reason:`auth_failure: code=${q.code} ${q.message}`}),K.info("agent disconnected due to auth failure from heartbeat response",{agentId:q.agentId,code:q.code,message:q.message})}catch(V){K.warn("disconnect during authFailure handling failed (ignored)",{agentId:q.agentId,err:String(V)})}}))};c.onConnect(({initial:O})=>{K.info("frontier upstream connected, triggering detail sync",{initial:O}),N.syncAll(O?"initial-connect":"reconnect").catch(q=>K.warn("detail sync top-level error (ignored)",{err:String(q)}))});let J=new Eo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[es]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let q=O,V=q?.privatecode,se=q?.pairing_code;if(!V||!se)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Je=ki(q.env),xe=q.handshake_url,he=q.frontier_url,St=Ch(q.env,xe,he),ut=!!p&&p!==V,Qt=m!==void 0&&m!==St,zt=ut||Qt,en=await Mc({privatecode:V,...xe?{endpoint:xe}:{},ppeOverride:Je});if(zt){K.warn("pair config switched, resetting agents",{pcChanged:ut,envChanged:Qt,previousPc:p?Yo(p):"",nextPc:Yo(V),previousEnvKey:m??"",nextEnvKey:St});for(let Te of[...u.agents.values()])await Te.dispose("pair config switch").catch(()=>{}),u.agents.delete(Te.agentId);u.disconnectedAgents.size>0&&(K.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new qr,"pair switch").catch(()=>{})}w=en.deviceId,as({deviceId:w,pid:process.pid}),rd({patToken:V,env:q.env}).catch(Te=>K.warn("coze-cli setup error (ignored)",{err:String(Te)}));let Vr=new Xi({handshake:en,privatecode:V,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:Te=>u.agents.get(Te)?.patToken});await c.swap(Vr,"pair");try{let Te=new Wn;o.frameworksCache=await Te.detectAll(),await Gi(o),K.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Te){K.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Te)})}let me=Object.keys(o.frameworksCache??{});try{let Te=await u.sendRequest("_agent/pair",{pairCode:se,patToken:V,frameworks:me,_meta:{cozeDeviceId:w}});K.info("_agent/pair ok",{pairResult:Te}),p=V,m=St,S=Je,_=xe,q.mock_scenario!==void 0&&(u.setMockScenario(q.mock_scenario),K.info("mock scenario set",{scenario:q.mock_scenario})),Qi(V,t).catch(Pe=>K.warn("writePatToken after /pair failed (ignored)",{err:String(Pe)})),v||(v=new Oi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>N.retryPending().catch(Pe=>K.warn("detailSync.retryPending failed (ignored)",{err:String(Pe)})),onAuthFailures:Y})),v.start(),y(),zt&&Zo(t,x).catch(Pe=>K.warn("post-pair-switch auto-revive error (ignored)",{err:String(Pe)}));let Xn;return q.agent_id&&(Xn=await hS(q.agent_id,t,x,Pe=>u.sendRequest("_agent/detail",Pe),V).catch(Pe=>(K.error("--agent-id ensureAgent failed",{agentId:q.agent_id,err:String(Pe)}),{ok:!1,agentId:q.agent_id??"",note:String(Pe)}))),{ok:!0,note:"paired with cloud",...Xn?{agent:Xn}:{}}}catch(Te){return K.error("_agent/pair failed",{err:String(Te)}),{ok:!1,note:`pair failed: ${String(Te)}`}}}},{method:"POST",path:"/connect",handler:O=>k(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let q=O;return{ok:!0,result:await x.createAgent(q)}}},{method:"POST",path:"/agent/send",handler:async O=>{let q=O;if(!q?.agentId||!q?.sessionId||!q?.kind||!q?.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 V=q;return await(V.groupFile?Bf:Mf)(V,{core:u,patToken:p,handshakeBase:_,ppeOverride:S})}catch(V){if(V instanceof C)return{ok:!1,code:V.code,message:V.message};throw V}}},{method:"POST",path:"/reload",handler:async O=>{let q=O?.agent_id,V=await u.reloadAgents(q);return K.info("IPC /reload: recycled agent subprocesses",{agentId:q??"(all)",recycled:V}),{ok:!0,recycled:V}}},{method:"POST",path:"/shutdown",handler:async()=>(K.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Z}=await J.start();try{await vh(t.libEntry,t)}catch(O){K.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),pS({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Wn().detectAll(),await Gi(o),o.frameworksCache)}).catch(O=>K.warn("startup warmup error (ignored)",{err:String(O)})),bl().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(rn(),_l));for(let q of["claude-code","codex"]){let V=await O(q);V&&K.info("acp wrapper version",{framework:q,version:V})}}).catch(O=>K.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let ie=null,oe={port:te,token:Z,core:u,ipc:J,shutdown(O){return ie||(K.info("daemon shutdown",{reason:O}),ie=(async()=>{v?.stop(),A?.stop(),await u.stop(O),await J.stop(),await e.release()})(),ie)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{oe.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>of()),process.on("unhandledRejection",O=>{K.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{K.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
|
|
110
|
+
`)}catch{}process.exit(1)}),K.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),gS({cliSpawned:process.env[es]==="1",readPatToken:()=>Wo(t),connect:k}).catch(O=>K.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),oe}async function fS(t){return ds(t).length>0}function Yo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Ch(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function xS(t,e){let r=ds(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(an(),fs));for(let c of r){await o(c,t).catch(d=>K.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.disconnectedAt&&(e.disconnectedAgents.add(c),K.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){K.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function hS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(an(),fs)),d=await c(t,e);if(d){K.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let m=Rh(d),w={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}K.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 C("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let x={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(x);let p=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function pS(t){let e=t.logger??K;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 xS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Zo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Zo(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(an(),fs));K.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let x;try{x=await o(u,t)}catch(p){K.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(p)}),d+=1;continue}if(!x){d+=1;continue}if(x.disconnectedAt){K.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),d+=1;continue}try{K.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let p=Rh(x);await e.createAgent({agentId:x.agentId,framework:x.framework,...x.cozeIdentity?{cozeIdentity:x.cozeIdentity}:{},...x.model?{model:x.model}:{},...p?{_meta:p}:{}},{revive:!0}),c+=1}catch(p){K.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(p)}),d+=1}}return K.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function gS(t){let e=t.logger??K;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 Rh(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Vo();Oe();import{readFile as kh}from"node:fs/promises";var Xt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await Xo(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:wS(i)}}}async request(e){let r=await Xo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,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}),x=await u.text();return{status:u.status,body:mS(x)}}finally{clearTimeout(d)}}};async function Xo(t){try{let[e,r]=await Promise.all([kh(t.portFile,"utf8"),kh(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 mS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function wS(t){return t instanceof Error?t.message:String(t)}Kt();ne();nr();import{spawn as _S}from"node:child_process";import{userInfo as Oh}from"node:os";var Od="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",yS=new Set(["bash","zsh","sh","dash","ksh"]),Ph=je("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),bS=2e3;function ES(t,e=Od){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(`
|
|
111
|
+
`)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function vS(){let t=(process.env.SHELL??"").trim()||(Oh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return yS.has(e)?t:null}function SS(t){return new Promise(e=>{let r=`printf '%s' '${Od}'; env; printf '%s' '${Od}'`,i;try{i=_S(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Oh().homedir}})}catch{e(null);return}let o="",c=!1,d=m=>{try{i.pid&&process.kill(-i.pid,m)}catch{}},u=m=>{c||(c=!0,clearTimeout(x),clearTimeout(p),e(m))};i.stdout?.on("data",m=>{o+=m.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let x=setTimeout(()=>d("SIGTERM"),Ph),p=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},Ph+bS)})}async function Ld(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=vS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??SS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=ES(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Oe();function Cn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}rn();import{chmod as AS,copyFile as Lh,mkdir as Mh,readFile as Qo,rename as Nh,rm as Nd,stat as Bh,writeFile as IS}from"node:fs/promises";import{homedir as yR}from"node:os";import{dirname as TS,join as jr,resolve as Md,sep as ts}from"node:path";import{fileURLToPath as CS}from"node:url";Kt();ne();Oe();var Bd=H("dist-install");function DS(t){let e=CS(t),r=TS(e),i=`${ts}src${ts}`;if(r.includes(i)||r.endsWith(`${ts}src${ts}cli`))return null;let o=Md(r,"index.js"),c=Md(r,"..","package.json");return{dist:o,pkgJson:c}}async function Fd(t={}){let e=t.paths??Q(),r=DS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let S=JSON.parse(await Qo(o,"utf8"));c=S.version??"unknown",d=S.dependencies??{}}catch(S){return Bd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=Qr.map(S=>`${S}@${d[S]??"latest"}`),x=await yo(e.configFile)??{},p=x.libVersion,m=await Qo(e.libEntry).then(()=>!0).catch(()=>!1),w=p===c;if(w&&m&&await zd(e))return{kind:"already-current",libVersion:c};if(!w||!m){await Mh(e.libDir,{recursive:!0}),await Lh(i,e.libEntry),await Lh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Md(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
|
|
112
|
+
`;await Qo(S,"utf8").catch(()=>null)!==_&&await IS(S,_)}return(!w||!await zd(e))&&await(t.installWrappers??RS)(e,u),x.libVersion=c,await Gi(x,e.configFile),Bd.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),w&&m?{kind:"already-current",libVersion:c}:p?{kind:"version-changed",fromVersion:p,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function zd(t){for(let e of Qr){let r=jr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Bh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function RS(t,e){await OS(t.installLock,async()=>{if(await zd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${ts}.staging-${process.pid}-${r}`,o=jr(i,"node_modules"),c=jr(t.libDir,"node_modules");try{await Mh(i,{recursive:!0}),await kS(e,i),await PS(o);let d=`${c}.trash-${r}`;await Nh(c,d).catch(()=>{}),await Nh(o,c),await Nd(d,{recursive:!0,force:!0}).catch(()=>{}),Bd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Nd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function kS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=et("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",x=>{d.length<8192&&(d+=x.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(u),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${d.trim().slice(0,2e3)}`))})})}async function PS(t){for(let e of Qr){let r=jr(t,...e.split("/")),i=JSON.parse(await Qo(jr(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=jr(t,".bin",o),d=await Bh(c);process.platform!=="win32"&&!(d.mode&73)&&await AS(c,d.mode|73).catch(()=>{})}}async function OS(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 Nd(t,{force:!0}).catch(()=>{})}}ba();ne();Oe();import{closeSync as Fh,fstatSync as Uh,openSync as Gh,readFileSync as LS,readSync as NS,readdirSync as MS,statSync as BS}from"node:fs";import{join as ea}from"node:path";var zS=new Set(["debug","info","warn","error"]);function Hh(t){let e=t,r=Cn(e,"--agent-id");e=r.rest;let i=Cn(e,"--date");e=i.rest;let o=Cn(e,"-n","--lines");e=o.rest;let c=Cn(e,"--level");e=c.rest;let d=Cn(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),x=Number.isInteger(u)&&u>=0?u:200,p=c.value&&zS.has(c.value)?c.value:void 0,m={lines:x,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),p&&(m.level=p),d.value&&(m.grep=d.value),m}function FS(t,e){return t.agentId?ea(Ze(t.agentId,e).logs,rr("agent",t.date)):ea(e.bridgeLogsDir,rr("bridge",t.date))}function US(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function GS(t,e){let r;try{r=MS(t)}catch{return[]}let i=[];for(let o of r){let c=ya(o,e);if(!c)continue;let d=0;try{d=BS(ea(t,o)).size}catch{}i.push({file:ea(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function qh(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"&&!hl(r,e.level))return!1}return!0}var zh={debug:"90",info:"36",warn:"33",error:"31"},HS=new Set(["ts","level","module","msg"]);function qS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function jh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=qS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&zh[o]&&(c=`\x1B[${zh[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([p])=>!HS.has(p)).map(([p,m])=>` ${p}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${d} ${u}${x}`}function jS(t,e,r){let c=LS(t,"utf8").split(`
|
|
113
|
+
`).filter(d=>d.length>0).filter(d=>qh(d,{level:e.level,grep:e.grep}));for(let d of US(c,e.lines))process.stdout.write(`${jh(d,{raw:e.raw,color:r})}
|
|
114
|
+
`)}async function Wh(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=GS(d,u);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
|
|
115
|
+
`),1;for(let p of x)process.stdout.write(`${p.date} ${(p.size/1024).toFixed(1)}KB ${p.file}
|
|
116
|
+
`);return 0}let o=t.date??Rn(new Date),c=FS({agentId:t.agentId,date:o},r);try{jS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
|
|
114
117
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
115
118
|
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
|
|
116
|
-
`),1}return t.follow&&await
|
|
117
|
-
`);o=
|
|
118
|
-
`)}await new Promise(
|
|
119
|
+
`),1}return t.follow&&await $S(c,t,i),0}var WS=500;function KS(t){try{let e=Gh(t,"r");try{return Uh(e).size}finally{Fh(e)}}catch{return 0}}async function $S(t,e,r){let i=KS(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let x=Gh(t,"r");try{let p=Uh(x).size;if(p>i){let m=Buffer.allocUnsafe(p-i),w=NS(x,m,0,m.length,i);u=m.subarray(0,w).toString("utf8"),i+=w}}finally{Fh(x)}}catch{}if(u){let x=(o+u).split(`
|
|
120
|
+
`);o=x.pop()??"";for(let p of x)p.length>0&&qh(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${jh(p,{raw:e.raw,color:r})}
|
|
121
|
+
`)}await new Promise(x=>setTimeout(x,WS))}}finally{process.off("SIGINT",d)}}import{basename as VS,resolve as JS}from"node:path";Oe();var YS=9e4,ZS={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function XS(t){return ZS[t]??1}async function Kh(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>
|
|
119
122
|
`),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
|
|
120
|
-
`),3;let i=await
|
|
121
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
123
|
+
`),3;let i=await Xo(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
|
|
124
|
+
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:JS(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 QS(i,"/agent/send",o,YS)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
|
|
122
125
|
`),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
|
|
123
|
-
`),
|
|
124
|
-
`);else{let d=t.name??
|
|
125
|
-
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${
|
|
126
|
-
`)}return 0}async function
|
|
127
|
-
`)}function
|
|
126
|
+
`),XS(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
|
|
127
|
+
`);else{let d=t.name??VS(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})
|
|
128
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${e1(c.bytes)})
|
|
129
|
+
`)}return 0}async function QS(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(),x=u?JSON.parse(u):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${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 tp=H("cli");function He(t,e){let{value:r,rest:i}=Cn(t,e);return{value:r,rest:i}}function oa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
130
|
+
`)}function S1(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:k}=He(e.slice(1),"--agent-id");return k?{mode:"reload",agentId:k}:{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 A1(e.slice(1));if(e[0]==="log")return{mode:"log",...Hh(e.slice(1))};if(e[0]==="connect")return I1(e.slice(1));if(e.includes("--status"))return oa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return oa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return oa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return oa("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=He(r,"--pat-token");r=o;let{value:c,rest:d}=He(r,"--pair-code");r=d;let{value:u,rest:x}=He(r,"--env");r=x;let{value:p,rest:m}=He(r,"--handshake-url");r=m;let{value:w,rest:S}=He(r,"--frontier-url");r=S;let{value:_,rest:v}=He(r,"--mock-scenario");r=v;let{value:A}=He(r,"--agent-id"),T=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let D={mode:"pair",privatecode:i,pairingCode:c};return u&&(D.env=u),p&&(D.handshakeUrl=p),w&&(D.frontierUrl=w),_&&(D.mockScenario=_),A&&(D.agentId=A),T&&(D.skipRebuildEnv=!0),D}function A1(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:x,rest:p}=He(i,"--agent-id");i=p;let{value:m,rest:w}=He(i,"--session-id");i=w;let{value:S,rest:_}=He(i,"--mime");i=_;let v=i.includes("--group-file");i=i.filter(D=>D!=="--group-file");let A=i.includes("--json"),T={mode:"send",kind:e,path:r,json:A};return o&&(T.caption=o),d&&(T.name=d),x&&(T.agentId=x),m&&(T.sessionId=m),v&&(T.groupFile=!0),S&&(T.mimeType=S),T}function I1(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:x,rest:p}=He(e,"--frontier-url");e=p;let{value:m,rest:w}=He(e,"--mock-scenario");e=w;let S=e.includes("--skip-rebuild-env"),_={mode:"connect"};return r&&(_.privatecode=r),o&&(_.env=o),d&&(_.handshakeUrl=d),x&&(_.frontierUrl=x),m&&(_.mockScenario=m),S&&(_.skipRebuildEnv=!0),_}var T1=`
|
|
128
131
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
129
132
|
|
|
130
133
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -205,57 +208,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
205
208
|
|
|
206
209
|
Internal:
|
|
207
210
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
208
|
-
`.trimStart();async function
|
|
209
|
-
`),0;case"daemon":{try{await
|
|
210
|
-
`),1;if(i.kind==="stale")return await
|
|
211
|
+
`.trimStart();async function np(t=process.argv,e={}){let r=S1(t);switch(r.mode){case"help":return process.stdout.write(T1),0;case"version":return process.stdout.write(`${Cr}
|
|
212
|
+
`),0;case"daemon":{try{await Dh()}catch(i){return tp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return C1(e);case"stop":return ip(e);case"reload":return k1(r.agentId,e);case"log":return Wh(r,e);case"update":return D1(e);case"purge":return P1(e);case"service-install":return O1(e);case"service-uninstall":return L1(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),N1(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),M1(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Kh({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 rp(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 C1(t){let e=t.paths??Q(),r=new Xt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
213
|
+
`),1;if(i.kind==="stale")return await rp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
211
214
|
`),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
212
215
|
${JSON.stringify(o.body,null,2)}
|
|
213
|
-
`),0}async function
|
|
216
|
+
`),0}async function ip(t){let e=t.paths??Q(),r=new Xt(e),i=t.daemonSweep??(async()=>{let x=af();return await cf(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await rs(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
|
|
214
217
|
`)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
|
|
215
218
|
`:`coze-bridge: not running
|
|
216
|
-
`),0;if(u.kind==="stale")return await
|
|
219
|
+
`),0;if(u.kind==="stale")return await rp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
217
220
|
`),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
218
|
-
`),0}catch(
|
|
219
|
-
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(
|
|
220
|
-
`),1)}}async function
|
|
221
|
-
`),e(1)})})}async function
|
|
221
|
+
`),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
|
|
222
|
+
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(x)}
|
|
223
|
+
`),1)}}async function D1(t){return await ip(t),(t.spawnNpx??R1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function R1(t){return new Promise(e=>{let r=et("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
|
|
224
|
+
`),e(1)})})}async function k1(t,e){let r=new Xt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
222
225
|
`),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
|
|
223
226
|
`):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
|
|
224
227
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
225
228
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
226
|
-
`),1}}async function
|
|
229
|
+
`),1}}async function rs(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(()=>(Qh(),Xh)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function sp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Th,o=t.waitTimeoutMs??15e3,c=t.sleep??z1,d=t.paths??Q(),u=await rs(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await ep(e,o,c);if(x.kind==="connected")return x;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(x){At(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}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 B1(d.pidFile,c)}else u&&await u.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
|
|
227
230
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
228
|
-
`),await i({paths:t.paths}),
|
|
231
|
+
`),await i({paths:t.paths}),ep(e,o,c)}async function P1(t){let e=new Xt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
229
232
|
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
|
|
230
|
-
`)}await new Promise(d=>setTimeout(d,500))}let i=await
|
|
233
|
+
`)}await new Promise(d=>setTimeout(d,500))}let i=await rs(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
231
234
|
`)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
|
|
232
|
-
`)}let o=t.paths??
|
|
235
|
+
`)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
|
|
233
236
|
`)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
|
|
234
237
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
235
|
-
`),0}async function
|
|
238
|
+
`),0}async function O1(t){let e=await rs(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
236
239
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
237
240
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
|
|
238
|
-
`),1}}async function
|
|
241
|
+
`),1}}async function L1(t){let e=await rs(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
239
242
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
|
|
240
|
-
`),1}}async function
|
|
241
|
-
`),
|
|
243
|
+
`),1}}async function op(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)
|
|
244
|
+
`),At(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function N1(t,e,r,i={},o,c){let d=new Xt(r.paths),u=r.paths??Q(),x=await op(u,c,r.reconstructEnv??Ld);if(await Jc(u,x).catch(w=>At(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!r.skipDistInstall){let w=await Fd({paths:r.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
|
|
242
245
|
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
|
|
243
|
-
`)}let
|
|
244
|
-
`),1;let m={privatecode:t,pairing_code:e};i.env&&(m.env=i.env),i.handshakeUrl&&(m.handshake_url=i.handshakeUrl),i.frontierUrl&&(m.frontier_url=i.frontierUrl),i.mockScenario&&(m.mock_scenario=i.mockScenario),o&&(m.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let
|
|
246
|
+
`)}let p=await sp(r,d);if(p.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${p.kind}
|
|
247
|
+
`),1;let m={privatecode:t,pairing_code:e};i.env&&(m.env=i.env),i.handshakeUrl&&(m.handshake_url=i.handshakeUrl),i.frontierUrl&&(m.frontier_url=i.frontierUrl),i.mockScenario&&(m.mock_scenario=i.mockScenario),o&&(m.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let S=w.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
|
|
245
248
|
`),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
|
|
246
249
|
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
|
|
247
250
|
`),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
|
|
248
|
-
`),1}}async function
|
|
249
|
-
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(
|
|
250
|
-
`)}let
|
|
251
|
-
`),1;let
|
|
252
|
-
`),await
|
|
251
|
+
`),1}}async function M1(t,e,r={},i){let o=e.paths??Q(),c=t??await Wo(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let d=new Xt(e.paths),u=await op(o,i,e.reconstructEnv??Ld);if(await Jc(o,u).catch(m=>At(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await Fd({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
|
|
252
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
|
|
253
|
+
`)}let x=await sp(e,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
|
|
254
|
+
`),1;let p={privatecode:c};r.env&&(p.env=r.env),r.handshakeUrl&&(p.handshake_url=r.handshakeUrl),r.frontierUrl&&(p.frontier_url=r.frontierUrl),r.mockScenario&&(p.mock_scenario=r.mockScenario);try{let m=await d.request({method:"POST",path:"/connect",body:p,timeoutMs:35e3});return m.status===200&&m.body?.ok?(process.stdout.write(`coze-bridge: connected (${m.body.note??"ok"})
|
|
255
|
+
`),t!==void 0&&await Qi(c,o).catch(w=>tp.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
|
|
253
256
|
`),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
|
|
254
|
-
`),1}}async function
|
|
257
|
+
`),1}}async function ep(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 B1(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||!Bi(u))return;await e(i)}}function z1(t){return new Promise(e=>setTimeout(e,t))}ne();function F1(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 ap(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=F1(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
|
|
255
258
|
`),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
|
|
256
259
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
257
260
|
npx -y coze-bridge@latest stop
|
|
258
261
|
npx -y coze-bridge@latest connect
|
|
259
262
|
|
|
260
|
-
`)}
|
|
263
|
+
`)}ap();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&fl("warn");np(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
261
264
|
`),process.exit(1)});
|