coze-bridge 0.2.3-alpha.101 → 0.2.3-alpha.102
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 +79 -79
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,25 +5,25 @@ import { dirname as __coze_dirname } from 'node:path';
|
|
|
5
5
|
const require = __coze_createRequire(import.meta.url);
|
|
6
6
|
const __filename = __coze_fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __coze_dirname(__filename);
|
|
8
|
-
var
|
|
8
|
+
var Sg=Object.create;var Ea=Object.defineProperty;var Ig=Object.getOwnPropertyDescriptor;var Ag=Object.getOwnPropertyNames;var kg=Object.getPrototypeOf,Tg=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Xe=(t,e)=>()=>(t&&(e=t(t=0)),e);var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),va=(t,e)=>{for(var n in e)Ea(t,n,{get:e[n],enumerable:!0})},Cg=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ag(e))!Tg.call(t,o)&&o!==n&&Ea(t,o,{get:()=>e[o],enumerable:!(i=Ig(e,o))||i.enumerable});return t};var zt=(t,e,n)=>(n=t!=null?Sg(kg(t)):{},Cg(e||!t||!t.__esModule?Ea(n,"default",{value:t,enumerable:!0}):n,t));function Ke(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var ir=Xe(()=>{"use strict"});import{createWriteStream as Rg,mkdirSync as Pg,readdirSync as Dg,unlinkSync as Og}from"node:fs";import{join as yl}from"node:path";function Pn(t){let e=n=>String(n).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function sr(t,e){return`${t}-${e}.log`}function Sa(t,e){let n=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!n||n[1]!==e?null:n[2]??null}function Lg(t,e,n){let i=c=>{let[d,u,f]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>n}function as(t,e,n,i){let o;try{o=Dg(t)}catch{return}for(let c of o){let d=Sa(c,e);if(d&&Lg(d,n,i))try{Og(yl(t,c))}catch{}}}var Qr,Ia=Xe(()=>{"use strict";Qr=class{constructor(e,n,i){this.dir=e;this.prefix=n;this.opts=i;this.clock=i.clock??(()=>Pn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let n=this.clock();n!==this.currentDate&&this.rotate(n),this.stream?.write(e)}rotate(e){this.stream?.end();try{Pg(this.dir,{recursive:!0});let n=Rg(yl(this.dir,sr(this.prefix,e)),{flags:"a"});n.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
|
|
9
9
|
`)),this.stream=n}catch(n){process.stderr.write(`[log-sink] rotate failed: ${String(n)}
|
|
10
|
-
`),this.stream=void 0;return}this.currentDate!==void 0&&
|
|
11
|
-
`;
|
|
12
|
-
`;if(ds){let
|
|
13
|
-
`),{cause:o})}}async function
|
|
14
|
-
`,n)}var an=Qe(()=>{"use strict"});import{promises as Dd,readdirSync as rm}from"node:fs";import{homedir as im}from"node:os";import{sep as sm,join as Te,resolve as Od}from"node:path";function Q(t){let e=t??im(),n=Te(e,".coze"),i=Te(n,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:n,bridgeRoot:i,libDir:o,libEntry:Te(o,"index.js"),binDir:Te(i,"bin"),pidFile:Te(i,"bridge.pid"),portFile:Te(i,"bridge.port"),tokenFile:Te(i,"bridge.token"),patTokenFile:Te(i,"pat-token"),agentEnvFile:Te(i,"agent-env.json"),logFile:Te(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Te(c,"daemon-stdio.log"),installLock:Te(i,"install.lock"),configFile:Te(i,"config.json"),agentsRoot:Te(n,"agents")}}function Ve(t,e=Q()){let n=Te(e.agentsRoot,t);return{root:n,config:Te(n,"config.json"),workspace:Te(n,"workspace"),logs:Te(n,"logs")}}function xs(t=Q()){try{return rm(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ni(t,e){let n=await Dd.realpath(Od(t)).catch(()=>null);if(!n)return!1;let i=await Dd.realpath(Od(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?n.toLowerCase():n,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+sm)}var Oe=Qe(()=>{"use strict"});var gs={};va(gs,{AGENT_CONFIG_FILE_MODE:()=>ps,enforceAgentConfigMode:()=>cm,loadAgentConfig:()=>ke,persistAgentSessions:()=>ri,persistAgentSkills:()=>ii,saveAgentConfig:()=>Be});import{chmod as om,stat as am}from"node:fs/promises";function ke(t,e){return cr(Ve(t,e).config)}function Be(t,e){return lr(Ve(t.agentId,e).config,t,{mode:ps})}async function cm(t,e){if(process.platform==="win32")return;let n=Ve(t,e).config;try{let i=await am(n);if(!i.isFile())return;let o=i.mode&511;o!==ps&&(await om(n,ps),Ld.warn("agent config mode auto-corrected to 0600",{path:n,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Ld.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:n,err:String(i)})}}async function ri(t,e,n){let i=await ke(t,n);i&&(i.sessions=Object.fromEntries(e),await Be(i,n))}async function ii(t,e,n){let i=await ke(t,n);i&&(i.skills=e,await Be(i,n))}var Ld,ps,cn=Qe(()=>{"use strict";an();te();Oe();Ld=q("agent-config"),ps=384});var Da=ae((QA,Bd)=>{Bd.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 ws=ae(zd=>{var Fd={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 xm(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(n,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Fd))zd[t]=xm(Fd[t])});var jd=ae((t1,Hd)=>{var pm=ue("fs"),Le=ue("path"),Ud=Da(),gm=ws(),mm=typeof process=="object"&&process.platform==="win32",Gd=t=>typeof t=="object"&&t!==null,qd=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function ve(t){this.sep=Le.sep,this.fs=pm,Gd(t)&&Gd(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Hd.exports=ve;ve.prototype.makeDir=function(t){let e=this;function n(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw gm.FILE_IN_THE_WAY(`"${o}"`)}})}n(t)};ve.prototype.writeFileTo=function(t,e,n,i){let o=this;if(o.fs.existsSync(t)){if(!n)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Le.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};ve.prototype.writeFileToAsync=function(t,e,n,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!n)return o(!1);c.fs.stat(t,function(u,h){if(l&&h.isDirectory())return o(!1);var x=Le.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),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)})})})})})};ve.prototype.findFiles=function(t){let e=this;function n(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let h=Le.join(i,u),x=e.fs.statSync(h);(!o||o.test(h))&&l.push(Le.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(l=l.concat(n(h,o,c)))}),l}return n(t,void 0,!0)};ve.prototype.findFilesAsync=function(t,e){let n=this,i=[];n.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Le.join(t,u),n.fs.stat(u,function(h,x){if(h)return e(h);x&&(i.push(Le.normalize(u)+(x.isDirectory()?n.sep:"")),x.isDirectory()?n.findFilesAsync(u,function(m,w){if(m)return e(m);i=i.concat(w),--l||e(null,i)}):--l||e(null,i))})})})};ve.prototype.getAttributes=function(){};ve.prototype.setAttributes=function(){};ve.crc32update=function(t,e){return qd[(t^e)&255]^t>>>8};ve.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,n=-1;for(let i=0;i<e;)n=ve.crc32update(n,t[i++]);return~n>>>0};ve.methodToString=function(t){switch(t){case Ud.STORED:return"STORED ("+t+")";case Ud.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};ve.canonical=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};ve.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.posix.join(".",e)};ve.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let n=t.length>>>0;for(let i=n-1;i>=0;i--)if(e(t[i],i,t))return t[i]};ve.sanitize=function(t,e){t=Le.resolve(Le.normalize(t));for(var n=e.split("/"),i=0,o=n.length;i<o;i++){var c=Le.normalize(Le.join(t,n.slice(i,o).join(Le.sep)));if(c.indexOf(t)===0)return c}return Le.normalize(Le.join(t,Le.basename(e)))};ve.toBuffer=function(e,n){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?n(e):Buffer.alloc(0)};ve.readBigUInt64LE=function(t,e){let n=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+n};ve.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};ve.fromDate2DOS=function(t){let e=0,n=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),n=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|n};ve.isWin=mm;ve.crcTable=qd});var Kd=ae((n1,Wd)=>{var wm=ue("path");Wd.exports=function(t,{fs:e}){var n=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return n&&e.existsSync(n)?(o=e.statSync(n),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=wm.basename(n)[0]==="."):console.warn("Invalid path: "+n),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:n,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Vd=ae((r1,$d)=>{$d.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var fr=ae((i1,ur)=>{ur.exports=jd();ur.exports.Constants=Da();ur.exports.Errors=ws();ur.exports.FileAttr=Kd();ur.exports.decoder=Vd()});var Jd=ae((s1,Zd)=>{var ln=fr(),z=ln.Constants;Zd.exports=function(){var t=20,e=10,n=0,i=0,o=0,c=0,l=0,u=0,h=0,x=0,m=0,w=0,S=0,_=0,v=0;t|=ln.isWin?2560:768,n|=z.FLG_EFS;let I={extraLen:0},A=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,D=y=>Math.max(0,y)&255;return o=ln.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return n},set flags(y){n=y},get flags_efs(){return(n&z.FLG_EFS)>0},set flags_efs(y){y?n|=z.FLG_EFS:n&=~z.FLG_EFS},get flags_desc(){return(n&z.FLG_DESC)>0},set flags_desc(y){y?n|=z.FLG_DESC:n&=~z.FLG_DESC},get method(){return i},set method(y){switch(y){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=y},get time(){return ln.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=ln.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(y){c=A(y)},get compressedSize(){return l},set compressedSize(y){l=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 S},set inAttr(y){S=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(n&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 C=y.slice(v,v+z.LOCHDR);if(C.readUInt32LE(0)!==z.LOCSIG)throw ln.Errors.INVALID_LOC();I.version=C.readUInt16LE(z.LOCVER),I.flags=C.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=C.readUInt16LE(z.LOCHOW),I.time=C.readUInt32LE(z.LOCTIM),I.crc=C.readUInt32LE(z.LOCCRC),I.compressedSize=C.readUInt32LE(z.LOCSIZ),I.size=C.readUInt32LE(z.LOCLEN),I.fnameLen=C.readUInt16LE(z.LOCNAM),I.extraLen=C.readUInt16LE(z.LOCEXT);let O=v+z.LOCHDR+I.fnameLen,M=O+I.extraLen;return y.slice(O,M)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw ln.Errors.INVALID_CEN();t=y.readUInt16LE(z.CENVEM),e=y.readUInt16LE(z.CENVER),n=y.readUInt16LE(z.CENFLG),i=y.readUInt16LE(z.CENHOW),o=y.readUInt32LE(z.CENTIM),c=y.readUInt32LE(z.CENCRC),l=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),S=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(n,z.LOCFLG),y.writeUInt16LE(i,z.LOCHOW),y.writeUInt32LE(o,z.LOCTIM),y.writeUInt32LE(c,z.LOCCRC),y.writeUInt32LE(l,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(n,z.CENFLG),y.writeUInt16LE(i,z.CENHOW),y.writeUInt32LE(o,z.CENTIM),y.writeUInt32LE(c,z.CENCRC),y.writeUInt32LE(l,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(S,z.CENATT),y.writeUInt32LE(_,z.CENATX),y.writeUInt32LE(v,z.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:n,method:ln.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(u),fileNameLength:y(h),extraLength:y(x),commentLength:y(m),diskNumStart:w,inAttr:S,attr:_,offset:v,centralHeaderSize:y(z.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Xd=ae((o1,Yd)=>{var hr=fr(),ye=hr.Constants;Yd.exports=function(){var t=0,e=0,n=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return n},set size(c){n=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return ye.ENDHDR+o},loadFromBinary:function(c){if((c.length!==ye.ENDHDR||c.readUInt32LE(0)!==ye.ENDSIG)&&(c.length<ye.ZIP64HDR||c.readUInt32LE(0)!==ye.ZIP64SIG))throw hr.Errors.INVALID_END();c.readUInt32LE(0)===ye.ENDSIG?(t=c.readUInt16LE(ye.ENDSUB),e=c.readUInt16LE(ye.ENDTOT),n=c.readUInt32LE(ye.ENDSIZ),i=c.readUInt32LE(ye.ENDOFF),o=c.readUInt16LE(ye.ENDCOM)):(t=hr.readBigUInt64LE(c,ye.ZIP64SUB),e=hr.readBigUInt64LE(c,ye.ZIP64TOT),n=hr.readBigUInt64LE(c,ye.ZIP64SIZE),i=hr.readBigUInt64LE(c,ye.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(ye.ENDHDR+o);return c.writeUInt32LE(ye.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,ye.ENDSUB),c.writeUInt16LE(e,ye.ENDTOT),c.writeUInt32LE(n,ye.ENDSIZ),c.writeUInt32LE(i,ye.ENDOFF),c.writeUInt16LE(o,ye.ENDCOM),c.fill(" ",ye.ENDHDR),c},toJSON:function(){let c=function(l,u){let h=l.toString(16).toUpperCase();for(;h.length<u;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:n+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var La=ae(Oa=>{Oa.EntryHeader=Jd();Oa.MainHeader=Xd()});var eu=ae((c1,Qd)=>{Qd.exports=function(t){var e=ue("zlib"),n={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,n)},deflateAsync:function(i){var o=e.createDeflateRaw(n),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),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 nu=ae((l1,tu)=>{var _m=+(process.versions?process.versions.node:"").split(".")[0]||0;tu.exports=function(t,e){var n=ue("zlib");let i=_m>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return n.inflateRawSync(t,i)},inflateAsync:function(o){var c=n.createInflateRaw(i),l=[],u=0;c.on("data",function(h){l.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),x=0;h.fill(0);for(var m=0;m<l.length;m++){var w=l[m];w.copy(h,x),x+=w.length}o&&o(h)}),c.end(t)}}}});var au=ae((d1,ou)=>{"use strict";var{randomFillSync:ru}=ue("crypto"),ym=ws(),bm=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),su=(t,e)=>Math.imul(t,e)>>>0,iu=(t,e)=>bm[(t^e)&255]^t>>>8,si=()=>typeof ru=="function"?ru(Buffer.alloc(12)):si.node();si.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let n=0;n<e;n++)t[n]=Math.random()*256&255;return t};var _s={genSalt:si};function ys(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let n=0;n<e.length;n++)this.updateKeys(e[n])}ys.prototype.updateKeys=function(t){let e=this.keys;return e[0]=iu(e[0],t),e[1]+=e[0]&255,e[1]=su(e[1],134775813)+1,e[2]=iu(e[2],e[1]>>>24),t};ys.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return su(t,t^1)>>8&255};function Em(t){let e=new ys(t);return function(n){let i=Buffer.alloc(n.length),o=0;for(let c of n)i[o++]=e.updateKeys(c^e.next());return i}}function vm(t){let e=new ys(t);return function(n,i,o=0){i||(i=Buffer.alloc(n.length));for(let c of n){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function Sm(t,e,n){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Em(n),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw ym.WRONG_PASSWORD();return i(t.slice(12))}function Im(t){Buffer.isBuffer(t)&&t.length>=12?_s.genSalt=function(){return t.slice(0,12)}:t==="node"?_s.genSalt=si.node:_s.genSalt=si}function Am(t,e,n,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=vm(n),c=_s.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}ou.exports={decrypt:Sm,encrypt:Am,_salter:Im}});var cu=ae(bs=>{bs.Deflater=eu();bs.Inflater=nu();bs.ZipCrypto=au()});var Ma=ae((f1,lu)=>{var ce=fr(),Tm=La(),Se=ce.Constants,Na=cu();lu.exports=function(t,e){var n=new Tm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=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 S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=n.loadLocalHeaderFromBinary(e),e.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function _(y){if(!n.flags_desc&&!n.localHeader.flags_desc){if(ce.crc32(y)!==n.localHeader.crc)return!1}else{let C={},O=n.realDataOffset+n.compressedSize;if(e.readUInt32LE(O)==Se.LOCSIG||e.readUInt32LE(O)==Se.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==Se.EXTSIG)C.crc=e.readUInt32LE(O+Se.EXTCRC),C.compressedSize=e.readUInt32LE(O+Se.EXTSIZ),C.size=e.readUInt32LE(O+Se.EXTLEN);else if(e.readUInt16LE(O+12)===19280)C.crc=e.readUInt32LE(O+Se.EXTCRC-4),C.compressedSize=e.readUInt32LE(O+Se.EXTSIZ-4),C.size=e.readUInt32LE(O+Se.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==n.compressedSize||C.size!==n.size||C.crc!==n.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(y)!==C.crc)return!1}return!0}function v(y,C,O){if(typeof C>"u"&&typeof y=="string"&&(O=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var M=S();if(M.length===0)return y&&C&&C(M),M;if(n.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw ce.Errors.INVALID_PASS_PARAM();M=Na.ZipCrypto.decrypt(M,n,O)}var L=Buffer.alloc(n.size);switch(n.method){case ce.Constants.STORED:if(M.copy(L),_(L))return y&&C&&C(L),L;throw y&&C&&C(L,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var Z=new Na.Inflater(M,n.size);if(y)Z.inflateAsync(function(V){V.copy(V,0),C&&(_(V)?C(V):C(V,ce.Errors.BAD_CRC()))});else{if(Z.inflate(L).copy(L,0),!_(L))throw ce.Errors.BAD_CRC(`"${w.decode(i)}"`);return L}break;default:throw y&&C&&C(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&C&&C(S()),S();if(l.length&&!c){var O;switch(n.method){case ce.Constants.STORED:return n.compressedSize=n.size,O=Buffer.alloc(l.length),l.copy(O),y&&C&&C(O),O;default:case ce.Constants.DEFLATED:var M=new Na.Deflater(l);if(y)M.deflateAsync(function(Z){O=Buffer.alloc(Z.length),n.compressedSize=Z.length,Z.copy(O),C&&C(O)});else{var L=M.deflate();return n.compressedSize=L.length,L}M=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,C){return ce.readBigUInt64LE(y,C)}function R(y){try{for(var C=0,O,M,L;C+4<y.length;)O=y.readUInt16LE(C),C+=2,M=y.readUInt16LE(C),C+=2,L=y.slice(C,C+M),C+=M,Se.ID_ZIP64===O&&D(L)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(y){var C,O,M,L;y.length>=Se.EF_ZIP64_SCOMP&&(C=A(y,Se.EF_ZIP64_SUNCOMP),n.size===Se.EF_ZIP64_OR_32&&(n.size=C)),y.length>=Se.EF_ZIP64_RHO&&(O=A(y,Se.EF_ZIP64_SCOMP),n.compressedSize===Se.EF_ZIP64_OR_32&&(n.compressedSize=O)),y.length>=Se.EF_ZIP64_DSN&&(M=A(y,Se.EF_ZIP64_RHO),n.offset===Se.EF_ZIP64_OR_32&&(n.offset=M)),y.length>=Se.EF_ZIP64_DSN+4&&(L=y.readUInt32LE(Se.EF_ZIP64_DSN),n.diskNumStart===Se.EF_ZIP64_OR_16&&(n.diskNumStart=L))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=ce.toBuffer(y,w.encode);var C=i[i.length-1];c=C===47||C===92,n.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(y){u=y,n.extraLength=y.length,R(y)},get comment(){return w.decode(o)},set comment(y){if(o=ce.toBuffer(y,w.encode),n.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return 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){l=ce.toBuffer(y,ce.decoder.encode),!c&&l.length?(n.size=l.length,n.method=ce.Constants.DEFLATED,n.crc=ce.crc32(y),n.changed=!0):n.method=ce.Constants.STORED},getData:function(y){return n.changed?l:v(!1,null,y)},getDataAsync:function(y,C){n.changed?y(l):v(!0,y,C)},set attr(y){n.attr=y},get attr(){return n.attr},set header(y){n.loadFromBinary(y)},get header(){return n},packCentralHeader:function(){n.flags_efs=this.efs,n.extraLength=u.length;var y=n.centralHeaderToBinary(),C=ce.Constants.CENHDR;return i.copy(y,C),C+=i.length,u.copy(y,C),C+=n.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;n.flags_efs=this.efs,n.extraLocalLength=h.length;let C=n.localHeaderToBinary(),O=Buffer.alloc(C.length+i.length+n.extraLocalLength);return C.copy(O,y),y+=C.length,i.copy(O,y),y+=i.length,h.copy(O,y),y+=h.length,O},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:y(e),data:y(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var fu=ae((h1,uu)=>{var du=Ma(),km=La(),Ke=fr();uu.exports=function(t,e){var n=[],i={},o=Buffer.alloc(0),c=new km.MainHeader,l=!1,u=null;let h=new Set,x=e,{noSort:m,decoder:w}=x;t?v(x.readEntries):l=!0;function S(){let A=new Set;for(let R of Object.keys(i)){let D=R.split("/");if(D.pop(),!!D.length)for(let y=0;y<D.length;y++){let C=D.slice(0,y+1).join("/")+"/";A.add(C)}}for(let R of A)if(!(R in i)){let D=new du(x);D.entryName=R,D.attr=16,D.temporary=!0,n.push(D),i[D.entryName]=D,h.add(D)}}function _(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/Ke.Constants.CENHDR)throw Ke.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(c.diskEntries);for(var A=c.offset,R=0;R<n.length;R++){var D=A,y=new du(x,t);y.header=t.slice(D,D+=Ke.Constants.CENHDR),y.entryName=t.slice(D,D+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(D,D+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(D,D+y.header.commentLength)),A+=y.header.centralHeaderSize,n[R]=y,i[y.entryName]=y}h.clear(),S()}function v(A){var R=t.length-Ke.Constants.ENDHDR,D=Math.max(0,R-65535),y=D,C=t.length,O=-1,M=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(D=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===Ke.Constants.ENDSIG){O=R,M=R,C=R+Ke.Constants.ENDHDR,y=R-Ke.Constants.END64HDR;continue}if(t.readUInt32LE(R)===Ke.Constants.END64SIG){y=D;continue}if(t.readUInt32LE(R)===Ke.Constants.ZIP64SIG){O=R,C=R+Ke.readBigUInt64LE(t,R+Ke.Constants.ZIP64SIZE)+Ke.Constants.ZIP64LEAD;break}}if(O==-1)throw Ke.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,C)),c.commentLength&&(o=t.slice(M+Ke.Constants.ENDHDR)),A&&_()}function I(){n.length>1&&!m&&n.sort((A,R)=>A.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||_(),n.filter(A=>!h.has(A))},get comment(){return w.decode(o)},set comment(A){o=Ke.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return l?n.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return l||_(),i[A]||null},setEntry:function(A){l||_(),n.push(A),i[A.entryName]=A,c.totalEntries=n.length},deleteFile:function(A,R=!0){l||_();let D=i[A];this.getEntryChildren(D,R).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){l||_();let R=i[A],D=n.indexOf(R);D>=0&&(n.splice(D,1),delete i[A],c.totalEntries=n.length)},getEntryChildren:function(A,R=!0){if(l||_(),typeof A=="object")if(A.isDirectory&&R){let D=[],y=A.entryName;for(let C of n)C.entryName.startsWith(y)&&D.push(C);return D}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let R=this.getEntryChildren(A);return R.includes(A)?R.length-1:R.length}return 0},compressToBuffer:function(){l||_(),I();let A=[],R=[],D=0,y=0;c.size=0,c.offset=0;let C=0;for(let L of this.entries){let Z=L.getCompressedData();L.header.offset=y;let V=L.packLocalHeader(),ne=V.length+Z.length;y+=ne,A.push(V),A.push(Z);let Y=L.packCentralHeader();R.push(Y),c.size+=Y.length,D+=ne+Y.length,C++}D+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let O=Buffer.alloc(D);for(let L of A)L.copy(O,y),y+=L.length;for(let L of R)L.copy(O,y),y+=L.length;let M=c.toBinary();return o&&o.copy(M,Ke.Constants.ENDHDR),M.copy(O,y),t=O,l=!1,O},toAsyncBuffer:function(A,R,D,y){try{l||_(),I();let C=[],O=[],M=0,L=0,Z=0;c.size=0,c.offset=0;let V=function(ne){if(ne.length>0){let Y=ne.shift(),ie=Y.entryName+Y.extra.toString();D&&D(ie),Y.getCompressedDataAsync(function(oe){y&&y(ie),Y.header.offset=L;let P=Y.packLocalHeader(),U=P.length+oe.length;L+=U,C.push(P),C.push(oe);let j=Y.packCentralHeader();O.push(j),c.size+=j.length,M+=U+j.length,Z++,V(ne)})}else{M+=c.mainHeaderSize,c.offset=L,c.totalEntries=Z,L=0;let Y=Buffer.alloc(M);C.forEach(function(oe){oe.copy(Y,L),L+=oe.length}),O.forEach(function(oe){oe.copy(Y,L),L+=oe.length});let ie=c.toBinary();o&&o.copy(ie,Ke.Constants.ENDHDR),ie.copy(Y,L),t=Y,l=!1,A(Y)}};V(Array.from(this.entries))}catch(C){R(C)}}}}});var pu=ae((x1,xu)=>{var Ee=fr(),be=ue("path"),Rm=Ma(),Cm=fu(),Dn=(...t)=>Ee.findLast(t,e=>typeof e=="boolean"),hu=(...t)=>Ee.findLast(t,e=>typeof e=="string"),Pm=(...t)=>Ee.findLast(t,e=>typeof e=="function"),Dm={noSort:!1,readEntries:!1,method:Ee.Constants.NONE,fs:null};xu.exports=function(t,e){let n=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)&&(n=t,i.method=Ee.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Ee(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Ee.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Ee.Constants.FILE,i.filename=t,n=o.fs.readFileSync(t);else throw Ee.Errors.INVALID_FILENAME();let c=new Cm(n,i),{canonical:l,sanitize:u,zipnamefix:h}=Ee;function x(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(be.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}=be.posix;return v(be.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 S=(_,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",be.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(R,D){if(D){v(R,D);return}R&&R.length?v(R.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 R=be.win32.basename(be.win32.normalize(_));v+=I||R;let D=o.fs.statSync(_),y=D.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);D.isDirectory()&&(v+=o.sep),this.addFile(v,y,A,D)}else throw Ee.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let I=be.resolve(_.localPath),{comment:A}=_,{zipPath:R,zipName:D}=_,y=this;o.fs.stat(I,function(C,O){if(C)return v(C,!1);R=R?m(R):"";let M=be.win32.basename(be.win32.normalize(I));if(R+=D||M,O.isFile())o.fs.readFile(I,function(L,Z){return L?v(L,!1):(y.addFile(R,Z,A,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),A,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,I){if(I=w(I),v=v?m(v):"",_=be.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),R=this;if(A.length)for(let D of A){let y=be.join(v,S(_,D));I(y)&&R.addLocalFile(D,be.dirname(y))}}else throw Ee.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,I,A){A=w(A),I=I?m(I):"",_=be.normalize(_);var R=this;o.fs.open(_,"r",function(D){if(D&&D.code==="ENOENT")v(void 0,Ee.Errors.FILE_NOT_FOUND(_));else if(D)v(void 0,D);else{var y=o.findFiles(_),C=-1,O=function(){if(C+=1,C<y.length){var M=y[C],L=S(_,M).split("\\").join("/");L=L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(L)?o.fs.stat(M,function(Z,V){Z&&v(void 0,Z),V.isFile()?o.fs.readFile(M,function(ne,Y){ne?v(void 0,ne):(R.addFile(I+L,Y,"",V),O())}):(R.addFile(I+L+"/",Buffer.alloc(0),"",V),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(_,v){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=be.resolve(m(_.localPath));let{zipPath:A,filter:R,namefix:D}=_;R instanceof RegExp?R=(function(O){return function(M){return O.test(M)}})(R):typeof R!="function"&&(R=function(){return!0}),A=A?m(A):"",D=="latin1"&&(D=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=O=>O);let y=O=>be.join(A,D(S(localPath,O))),C=O=>be.win32.basename(be.win32.normalize(D(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,Ee.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(M,L){if(M)return v(M);L=L.filter(Z=>R(y(Z))),L.length||v(void 0,!1),setImmediate(L.reverse().reduce(function(Z,V){return function(ne,Y){if(ne||Y===!1)return setImmediate(Z,ne,!1);I.addLocalFileAsync({localPath:V,zipPath:be.dirname(y(V)),zipName:C(V)},Z)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(R,D)=>{R&&A(R),D&&I(this)})})},addFile:function(_,v,I,A){_=h(_);let R=x(_),D=R!=null;D||(R=new Rm(i),R.entryName=_),R.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(R.header.time=A.mtime);var C=R.isDirectory?16:0;let O=R.isDirectory?16384:32768;return y?O|=4095&A.mode:typeof A=="number"?O|=4095&A:O|=R.isDirectory?493:420,C=(C|O<<16)>>>0,R.attr=C,R.setData(v),D||c.setEntry(R),R},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,R,D){A=Dn(!1,A),R=Dn(!1,R),I=Dn(!0,I),D=hu(R,D);var y=x(_);if(!y)throw Ee.Errors.NO_ENTRY();var C=l(y.entryName),O=u(v,D&&!y.isDirectory?D:I?C:be.basename(C));if(y.isDirectory){var M=c.getEntryChildren(y);return M.forEach(function(V){if(V.isDirectory)return;var ne=V.getData();if(!ne)throw Ee.Errors.CANT_EXTRACT_FILE();var Y=l(V.entryName),ie=u(v,I?Y:be.basename(Y));let oe=R?V.header.fileAttr:void 0;o.writeFileTo(ie,ne,A,oe)}),!0}var L=y.getData(c.password);if(!L)throw Ee.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!A)throw Ee.Errors.CANT_OVERRIDE();let Z=R?_.header.fileAttr:void 0;return o.writeFileTo(O,L,A,Z),!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=Dn(!1,I),A=hu(I,A),v=Dn(!1,v),!c)throw Ee.Errors.NO_ZIP();c.entries.forEach(function(R){var D=u(_,l(R.entryName));if(R.isDirectory){o.makeDir(D);return}var y=R.getData(A);if(!y)throw Ee.Errors.CANT_EXTRACT_FILE();let C=I?R.header.fileAttr:void 0;o.writeFileTo(D,y,v,C);try{o.fs.utimesSync(D,R.header.time,R.header.time)}catch{throw Ee.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,I,A){if(A=Pm(v,I,A),I=Dn(!1,I),v=Dn(!1,v),!A)return new Promise((O,M)=>{this.extractAllToAsync(_,v,I,function(L){L?M(L):O(this)})});if(!c){A(Ee.Errors.NO_ZIP());return}_=be.resolve(_);let R=O=>u(_,be.normalize(l(O.entryName))),D=(O,M)=>new Error(O+': "'+M+'"'),y=[],C=[];c.entries.forEach(O=>{O.isDirectory?y.push(O):C.push(O)});for(let O of y){let M=R(O),L=I?O.header.fileAttr:void 0;try{o.makeDir(M),L&&o.fs.chmodSync(M,L),o.fs.utimesSync(M,O.header.time,O.header.time)}catch{A(D("Unable to create folder",M))}}C.reverse().reduce(function(O,M){return function(L){if(L)O(L);else{let Z=be.normalize(l(M.entryName)),V=u(_,Z);M.getDataAsync(function(ne,Y){if(Y)O(Y);else if(!ne)O(Ee.Errors.CANT_EXTRACT_FILE());else{let ie=I?M.header.fileAttr:void 0;o.writeFileToAsync(V,ne,v,ie,function(oe){oe||O(D("Unable to write file",V)),o.fs.utimes(V,M.header.time,M.header.time,function(P){P?O(D("Unable to set times",V)):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((R,D)=>{!_&&i.filename&&(_=i.filename),_||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=O=>O?R(O):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,A,C)},D)})},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 F_,spawn as z_,spawnSync as D2}from"node:child_process";import{promisify as U_}from"node:util";function q_(t){if(process.platform!=="win32")return!1;if(Nf.test(t))return!0;let n=(t.split(/[/\\]/).pop()??t).replace(Nf,"").toLowerCase();return G_.has(n)}function Mf(t,e){if(process.platform!=="win32")return e??{};let n={...e??{}};return q_(t)&&n.shell===void 0&&(n.shell=!0),n.windowsHide===void 0&&(n.windowsHide=!0),n}function nt(t,e=[],n={}){return z_(t,e,Mf(t,n))}function Bf(t,e=[],n={}){return H_(t,e,Mf(t,n))}var G_,Nf,H_,$t=Qe(()=>{"use strict";G_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Nf=/\.(cmd|bat|ps1)$/i;H_=U_(F_)});var Zt=ae((xC,bh)=>{"use strict";var _h=["nodebuffer","arraybuffer","fragments"],yh=typeof Blob<"u";yh&&_h.push("blob");bh.exports={BINARY_TYPES:_h,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:yh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ki=ae((pC,ko)=>{"use strict";var{EMPTY_BUFFER:bE}=Zt(),hl=Buffer[Symbol.species];function EE(t,e){if(t.length===0)return bE;if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];n.set(c,i),i+=c.length}return i<e?new hl(n.buffer,n.byteOffset,i):n}function Eh(t,e,n,i,o){for(let c=0;c<o;c++)n[i+c]=t[c]^e[c&3]}function vh(t,e){for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function vE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xl(t){if(xl.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new hl(t):ArrayBuffer.isView(t)?e=new hl(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xl.readOnly=!1),e}ko.exports={concat:EE,mask:Eh,toArrayBuffer:vE,toBuffer:xl,unmask:vh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");ko.exports.mask=function(e,n,i,o,c){c<48?Eh(e,n,i,o,c):t.mask(e,n,i,o,c)},ko.exports.unmask=function(e,n){e.length<32?vh(e,n):t.unmask(e,n)}}catch{}});var Ah=ae((gC,Ih)=>{"use strict";var Sh=Symbol("kDone"),pl=Symbol("kRun"),gl=class{constructor(e){this[Sh]=()=>{this.pending--,this[pl]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pl]()}[pl](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Sh])}}};Ih.exports=gl});var zr=ae((mC,Ch)=>{"use strict";var $i=ue("zlib"),Th=Ki(),SE=Ah(),{kStatusCode:kh}=Zt(),IE=Buffer[Symbol.species],AE=Buffer.from([0,0,255,255]),Co=Symbol("permessage-deflate"),Jt=Symbol("total-length"),Br=Symbol("callback"),Tn=Symbol("buffers"),Fr=Symbol("error"),Ro,ml=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,!Ro){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ro=new SE(n)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Br];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let n=this._options,i=e.find(o=>!(n.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(n.serverMaxWindowBits===!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>o.server_max_window_bits)||typeof n.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return n.serverNoContextTakeover&&(i.server_no_context_takeover=!0),n.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof n.serverMaxWindowBits=="number"&&(i.server_max_window_bits=n.serverMaxWindowBits),typeof n.clientMaxWindowBits=="number"?i.client_max_window_bits=n.clientMaxWindowBits:(i.client_max_window_bits===!0||n.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let n=e[0];if(this._options.clientNoContextTakeover===!1&&n.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!n.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(n.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&n.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return n}normalizeParams(e){return e.forEach(n=>{Object.keys(n).forEach(i=>{let o=n[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);n[i]=o})}),e}decompress(e,n,i){Ro.add(o=>{this._decompress(e,n,(c,l)=>{o(),i(c,l)})})}compress(e,n,i){Ro.add(o=>{this._compress(e,n,(c,l)=>{o(),i(c,l)})})}_decompress(e,n,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=$i.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Co]=this,this._inflate[Jt]=0,this._inflate[Tn]=[],this._inflate.on("error",kE),this._inflate.on("data",Rh)}this._inflate[Br]=i,this._inflate.write(e),n&&this._inflate.write(AE),this._inflate.flush(()=>{let c=this._inflate[Fr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=Th.concat(this._inflate[Tn],this._inflate[Jt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Jt]=0,this._inflate[Tn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,n,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=$i.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Jt]=0,this._deflate[Tn]=[],this._deflate.on("data",TE)}this._deflate[Br]=i,this._deflate.write(e),this._deflate.flush($i.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Th.concat(this._deflate[Tn],this._deflate[Jt]);n&&(c=new IE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Br]=null,this._deflate[Jt]=0,this._deflate[Tn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Ch.exports=ml;function TE(t){this[Tn].push(t),this[Jt]+=t.length}function Rh(t){if(this[Jt]+=t.length,this[Co]._maxPayload<1||this[Jt]<=this[Co]._maxPayload){this[Tn].push(t);return}this[Fr]=new RangeError("Max payload size exceeded"),this[Fr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Fr][kh]=1009,this.removeListener("data",Rh),this.reset()}function kE(t){if(this[Co]._inflate=null,this[Fr]){this[Br](this[Fr]);return}t[kh]=1007,this[Br](t)}});var Ur=ae((wC,Po)=>{"use strict";var{isUtf8:Ph}=ue("buffer"),{hasBlob:RE}=Zt(),CE=[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 PE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function wl(t){let e=t.length,n=0;for(;n<e;)if((t[n]&128)===0)n++;else if((t[n]&224)===192){if(n+1===e||(t[n+1]&192)!==128||(t[n]&254)===192)return!1;n+=2}else if((t[n]&240)===224){if(n+2>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||t[n]===224&&(t[n+1]&224)===128||t[n]===237&&(t[n+1]&224)===160)return!1;n+=3}else if((t[n]&248)===240){if(n+3>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||(t[n+3]&192)!==128||t[n]===240&&(t[n+1]&240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function DE(t){return RE&&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:DE,isValidStatusCode:PE,isValidUTF8:wl,tokenChars:CE};if(Ph)Po.exports.isValidUTF8=function(t){return t.length<24?wl(t):Ph(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?wl(e):t(e)}}catch{}});var vl=ae((_C,Fh)=>{"use strict";var{Writable:OE}=ue("stream"),Dh=zr(),{BINARY_TYPES:LE,EMPTY_BUFFER:Oh,kStatusCode:NE,kWebSocket:ME}=Zt(),{concat:_l,toArrayBuffer:BE,unmask:FE}=Ki(),{isValidStatusCode:zE,isValidUTF8:Lh}=Ur(),Do=Buffer[Symbol.species],ft=0,Nh=1,Mh=2,Bh=3,yl=4,bl=5,Oo=6,El=class extends OE{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[ME]=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=ft}_write(e,n,i){if(this._opcode===8&&this._state==ft)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 Do(i.buffer,i.byteOffset+e,i.length-e),new Do(i.buffer,i.byteOffset,e)}let n=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=n.length-e;e>=i.length?n.set(this._buffers.shift(),o):(n.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Do(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case ft:this.getInfo(e);break;case Nh:this.getPayloadLength16(e);break;case Mh:this.getPayloadLength64(e);break;case Bh:this.getMask();break;case yl:this.getData(e);break;case bl:case Oo:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let n=this.consume(2);if((n[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(n[0]&64)===64;if(i&&!this._extensions[Dh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(n[0]&128)===128,this._opcode=n[0]&15,this._payloadLength=n[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(n[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=Nh:this._payloadLength===127?this._state=Mh:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let n=this.consume(8),i=n.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+n.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(n);return}this._masked?this._state=Bh:this._state=yl}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=yl}getData(e){let n=Oh;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&FE(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._compressed){this._state=bl,this.decompress(n,e);return}if(n.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(n)}this.dataMessage(e)}decompress(e,n){this._extensions[Dh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return n(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");n(l);return}this._fragments.push(c)}this.dataMessage(n),this._state===ft&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=ft;return}let n=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=_l(i,n):this._binaryType==="arraybuffer"?o=BE(_l(i,n)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ft):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!0),this._state=ft,this.startLoop(e)}))}else{let o=_l(i,n);if(!this._skipUTF8Validation&&!Lh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===bl||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ft):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!1),this._state=ft,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Oh),this.end();else{let i=e.readUInt16BE(0);if(!zE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(c);return}let o=new Do(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Lh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ft;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ft):(this._state=Oo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ft,this.startLoop(n)}))}createError(e,n,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(l,this.createError),l.code=c,l[NE]=o,l}};Fh.exports=El});var Al=ae((bC,Gh)=>{"use strict";var{Duplex:yC}=ue("stream"),{randomFillSync:UE}=ue("crypto"),{types:{isUint8Array:GE}}=ue("util"),zh=zr(),{EMPTY_BUFFER:qE,kWebSocket:HE,NOOP:jE}=Zt(),{isBlob:Gr,isValidStatusCode:WE}=Ur(),{mask:Uh,toBuffer:Vn}=Ki(),ht=Symbol("kByteLength"),KE=Buffer.alloc(4),Lo=8*1024,Zn,qr=Lo,Et=0,$E=1,VE=2,Sl=class t{constructor(e,n,i){this._extensions=n||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=Et,this.onerror=jE,this[HE]=void 0}static frame(e,n){let i,o=!1,c=2,l=!1;n.mask&&(i=n.maskBuffer||KE,n.generateMask?n.generateMask(i):(qr===Lo&&(Zn===void 0&&(Zn=Buffer.alloc(Lo)),UE(Zn,0,Lo),qr=0),i[0]=Zn[qr++],i[1]=Zn[qr++],i[2]=Zn[qr++],i[3]=Zn[qr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!n.mask||l)&&n[ht]!==void 0?u=n[ht]:(e=Buffer.from(e),u=e.length):(u=e.length,o=n.mask&&n.readOnly&&!l);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]=n.fin?n.opcode|128:n.opcode,n.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)),n.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],l?[x,e]:o?(Uh(e,i,x,c,u),[x]):(Uh(e,i,e,0,u),[x,e])):[x,e]}close(e,n,i,o){let c;if(e===void 0)c=qE;else{if(typeof e!="number"||!WE(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(n);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof n=="string")c.write(n,2);else if(GE(n))c.set(n,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ht]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Et?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ht]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Gr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ht]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Gr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,n,i){let o=this._extensions[zh.extensionName],c=n.binary?2:1,l=n.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):Gr(e)?(u=e.size,h=!1):(e=Vn(e),u=e.length,h=Vn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),n.fin&&(this._firstFragment=!0);let x={[ht]:u,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:l};Gr(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,n,i,o){this._bufferedBytes+=i[ht],this._state=VE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Il,this,u,o);return}this._bufferedBytes-=i[ht];let l=Vn(c);n?this.dispatch(l,n,i,o):(this._state=Et,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(ZE,this,c,o)})}dispatch(e,n,i,o){if(!n){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[zh.extensionName];this._bufferedBytes+=i[ht],this._state=$E,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");Il(this,h,o);return}this._bufferedBytes-=i[ht],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][ht],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ht],this._queue.push(e)}sendFrame(e,n){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.write(e[0],n)}};Gh.exports=Sl;function Il(t,e,n){typeof n=="function"&&n(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function ZE(t,e,n){Il(t,e,n),t.onerror(e)}});var Jh=ae((EC,Zh)=>{"use strict";var{kForOnEventAttribute:Vi,kListener:Tl}=Zt(),qh=Symbol("kCode"),Hh=Symbol("kData"),jh=Symbol("kError"),Wh=Symbol("kMessage"),Kh=Symbol("kReason"),Hr=Symbol("kTarget"),$h=Symbol("kType"),Vh=Symbol("kWasClean"),Yt=class{constructor(e){this[Hr]=null,this[$h]=e}get target(){return this[Hr]}get type(){return this[$h]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Jn=class extends Yt{constructor(e,n={}){super(e),this[qh]=n.code===void 0?0:n.code,this[Kh]=n.reason===void 0?"":n.reason,this[Vh]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[qh]}get reason(){return this[Kh]}get wasClean(){return this[Vh]}};Object.defineProperty(Jn.prototype,"code",{enumerable:!0});Object.defineProperty(Jn.prototype,"reason",{enumerable:!0});Object.defineProperty(Jn.prototype,"wasClean",{enumerable:!0});var jr=class extends Yt{constructor(e,n={}){super(e),this[jh]=n.error===void 0?null:n.error,this[Wh]=n.message===void 0?"":n.message}get error(){return this[jh]}get message(){return this[Wh]}};Object.defineProperty(jr.prototype,"error",{enumerable:!0});Object.defineProperty(jr.prototype,"message",{enumerable:!0});var Zi=class extends Yt{constructor(e,n={}){super(e),this[Hh]=n.data===void 0?null:n.data}get data(){return this[Hh]}};Object.defineProperty(Zi.prototype,"data",{enumerable:!0});var JE={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[Vi]&&o[Tl]===e&&!o[Vi])return;let i;if(t==="message")i=function(c,l){let u=new Zi("message",{data:l?c:c.toString()});u[Hr]=this,No(e,this,u)};else if(t==="close")i=function(c,l){let u=new Jn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Hr]=this,No(e,this,u)};else if(t==="error")i=function(c){let l=new jr("error",{error:c,message:c.message});l[Hr]=this,No(e,this,l)};else if(t==="open")i=function(){let c=new Yt("open");c[Hr]=this,No(e,this,c)};else return;i[Vi]=!!n[Vi],i[Tl]=e,n.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[Tl]===e&&!n[Vi]){this.removeListener(t,n);break}}};Zh.exports={CloseEvent:Jn,ErrorEvent:jr,Event:Yt,EventTarget:JE,MessageEvent:Zi};function No(t,e,n){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var Mo=ae((vC,Yh)=>{"use strict";var{tokenChars:Ji}=Ur();function Nt(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}function YE(t){let e=Object.create(null),n=Object.create(null),i=!1,o=!1,c=!1,l,u,h=-1,x=-1,m=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),l===void 0)if(m===-1&&Ji[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?(Nt(e,_,n),n=Object.create(null)):l=_,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(m===-1&&Ji[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),Nt(n,t.slice(h,m),!0),x===44&&(Nt(e,l,n),n=Object.create(null),l=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(Ji[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);h===-1?h=w:i||(i=!0),o=!1}else if(c)if(Ji[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&&Ji[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),Nt(n,u,_),x===44&&(Nt(e,l,n),n=Object.create(null),l=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 S=t.slice(h,m);return l===void 0?Nt(e,S,n):(u===void 0?Nt(n,S,!0):i?Nt(n,u,S.replace(/\\/g,"")):Nt(n,u,S),Nt(e,l,n)),e}function XE(t){return Object.keys(t).map(e=>{let n=t[e];return Array.isArray(n)||(n=[n]),n.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Yh.exports={format:XE,parse:YE}});var Uo=ae((AC,lx)=>{"use strict";var QE=ue("events"),ev=ue("https"),tv=ue("http"),ex=ue("net"),nv=ue("tls"),{randomBytes:rv,createHash:iv}=ue("crypto"),{Duplex:SC,Readable:IC}=ue("stream"),{URL:kl}=ue("url"),kn=zr(),sv=vl(),ov=Al(),{isBlob:av}=Ur(),{BINARY_TYPES:Xh,CLOSE_TIMEOUT:cv,EMPTY_BUFFER:Bo,GUID:lv,kForOnEventAttribute:Rl,kListener:dv,kStatusCode:uv,kWebSocket:qe,NOOP:tx}=Zt(),{EventTarget:{addEventListener:fv,removeEventListener:hv}}=Jh(),{format:xv,parse:pv}=Mo(),{toBuffer:gv}=Ki(),nx=Symbol("kAborted"),Cl=[8,13],Xt=["CONNECTING","OPEN","CLOSING","CLOSED"],mv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,we=class t extends QE{constructor(e,n,i){super(),this._binaryType=Xh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Bo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,n===void 0?n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(i=n,n=[]):n=[n]),rx(this,e,n,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Xh.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,n,i){let o=new sv({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 ov(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[qe]=this,c[qe]=this,e[qe]=this,o.on("conclude",yv),o.on("drain",bv),o.on("error",Ev),o.on("message",vv),o.on("ping",Sv),o.on("pong",Iv),c.onerror=Av,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",ox),e.on("data",zo),e.on("end",ax),e.on("error",cx),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[kn.extensionName]&&this._extensions[kn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,n){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,n,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),sx(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||Bo,n,i)}pong(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.pong(e||Bo,n,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(i=n,n={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[kn.extensionName]||(o.compress=!1),this._sender.send(e||Bo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(we,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(we.prototype,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(we,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(we.prototype,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(we,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(we.prototype,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(we,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});Object.defineProperty(we.prototype,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(we.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(we.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Rl])return e[dv];return null},set(e){for(let n of this.listeners(t))if(n[Rl]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Rl]:!0})}})});we.prototype.addEventListener=fv;we.prototype.removeEventListener=hv;lx.exports=we;function rx(t,e,n,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:cv,protocolVersion:Cl[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,!Cl.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Cl.join(", ")})`);let c;if(e instanceof kl)c=e;else try{c=new kl(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",u=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!l&&!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;Fo(t,I);return}let x=l?443:80,m=rv(16).toString("base64"),w=l?ev.request:tv.request,S=new Set,_;if(o.createConnection=o.createConnection||(l?_v:wv),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 kn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=xv({[kn.extensionName]:_.offer()})),n.length){for(let I of n){if(typeof I!="string"||!mv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(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=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,R]of Object.entries(I))i.headers[A.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=w(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=w(o);o.timeout&&v.on("timeout",()=>{ot(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[nx]||(v=t._req=null,Fo(t,I))}),v.on("response",I=>{let A=I.headers.location,R=I.statusCode;if(A&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){ot(t,v,"Maximum redirects exceeded");return}v.abort();let D;try{D=new kl(A,e)}catch{let C=new SyntaxError(`Invalid URL: ${A}`);Fo(t,C);return}rx(t,D,n,i)}else t.emit("unexpected-response",v,I)||ot(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,R)=>{if(t.emit("upgrade",I),t.readyState!==we.CONNECTING)return;v=t._req=null;let D=I.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){ot(t,A,"Invalid Upgrade header");return}let y=iv("sha1").update(m+lv).digest("base64");if(I.headers["sec-websocket-accept"]!==y){ot(t,A,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],O;if(C!==void 0?S.size?S.has(C)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":S.size&&(O="Server sent no subprotocol"),O){ot(t,A,O);return}C&&(t._protocol=C);let M=I.headers["sec-websocket-extensions"];if(M!==void 0){if(!_){ot(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let L;try{L=pv(M)}catch{ot(t,A,"Invalid Sec-WebSocket-Extensions header");return}let Z=Object.keys(L);if(Z.length!==1||Z[0]!==kn.extensionName){ot(t,A,"Server indicated an extension that was not requested");return}try{_.accept(L[kn.extensionName])}catch{ot(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[kn.extensionName]=_}t.setSocket(A,R,{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 Fo(t,e){t._readyState=we.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function wv(t){return t.path=t.socketPath,ex.connect(t)}function _v(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=ex.isIP(t.host)?"":t.host),nv.connect(t)}function ot(t,e,n){t._readyState=we.CLOSING;let i=new Error(n);Error.captureStackTrace(i,ot),e.setHeader?(e[nx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Fo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pl(t,e,n){if(e){let i=av(e)?e.size:gv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(n){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Xt[t.readyState]})`);process.nextTick(n,i)}}function yv(t,e){let n=this[qe];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[qe]!==void 0&&(n._socket.removeListener("data",zo),process.nextTick(ix,n._socket),t===1005?n.close():n.close(t,e))}function bv(){let t=this[qe];t.isPaused||t._socket.resume()}function Ev(t){let e=this[qe];e._socket[qe]!==void 0&&(e._socket.removeListener("data",zo),process.nextTick(ix,e._socket),e.close(t[uv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Qh(){this[qe].emitClose()}function vv(t,e){this[qe].emit("message",t,e)}function Sv(t){let e=this[qe];e._autoPong&&e.pong(t,!this._isServer,tx),e.emit("ping",t)}function Iv(t){this[qe].emit("pong",t)}function ix(t){t.resume()}function Av(t){let e=this[qe];e.readyState!==we.CLOSED&&(e.readyState===we.OPEN&&(e._readyState=we.CLOSING,sx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function sx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function ox(){let t=this[qe];if(this.removeListener("close",ox),this.removeListener("data",zo),this.removeListener("end",ax),t._readyState=we.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[qe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Qh),t._receiver.on("finish",Qh))}function zo(t){this[qe]._receiver.write(t)||this.pause()}function ax(){let t=this[qe];t._readyState=we.CLOSING,t._receiver.end(),this.end()}function cx(){let t=this[qe];this.removeListener("error",cx),this.on("error",tx),t&&(t._readyState=we.CLOSING,this.destroy())}});var hx=ae((kC,fx)=>{"use strict";var TC=Uo(),{Duplex:Tv}=ue("stream");function dx(t){t.emit("close")}function kv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function ux(t){this.removeListener("error",ux),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Rv(t,e){let n=!0,i=new Tv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(n=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(dx,i);return}let l=!1;t.once("error",function(h){l=!0,c(h)}),t.once("close",function(){l||c(o),process.nextTick(dx,i)}),n&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",kv),i.on("error",ux),i}fx.exports=Rv});var Dl=ae((RC,xx)=>{"use strict";var{tokenChars:Cv}=Ur();function Pv(t){let e=new Set,n=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&Cv[l]===1)n===-1&&(n=o);else if(o!==0&&(l===32||l===9))i===-1&&n!==-1&&(i=o);else if(l===44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(n,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),n=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(n===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(n,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}xx.exports={parse:Pv}});var Ex=ae((PC,bx)=>{"use strict";var Dv=ue("events"),Go=ue("http"),{Duplex:CC}=ue("stream"),{createHash:Ov}=ue("crypto"),px=Mo(),Yn=zr(),Lv=Dl(),Nv=Uo(),{CLOSE_TIMEOUT:Mv,GUID:Bv,kWebSocket:Fv}=Zt(),zv=/^[+/0-9A-Za-z]{22}==$/,gx=0,mx=1,yx=2,Ol=class extends Dv{constructor(e,n){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Mv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Nv,...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=Go.createServer((i,o)=>{let c=Go.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,n)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Uv(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,l)=>{this.handleUpgrade(o,c,l,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=gx}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===yx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Yi,this);return}if(e&&this.once("close",e),this._state!==mx)if(this._state=mx,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(Yi,this):process.nextTick(Yi,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{Yi(this)})}}shouldHandle(e){if(this.options.path){let n=e.url.indexOf("?");if((n!==-1?e.url.slice(0,n):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,n,i,o){n.on("error",_x);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Xn(this,e,n,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Xn(this,e,n,400,"Invalid Upgrade header");return}if(c===void 0||!zv.test(c)){Xn(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Xn(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Xi(n,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=Lv.parse(h)}catch{Xn(this,e,n,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 Yn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=px.parse(m);_[Yn.extensionName]&&(S.accept(_[Yn.extensionName]),w[Yn.extensionName]=S)}catch{Xn(this,e,n,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,v,I,A)=>{if(!_)return Xi(n,v||401,I,A);this.completeUpgrade(w,c,x,e,n,i,o)});return}if(!this.options.verifyClient(S))return Xi(n,401)}this.completeUpgrade(w,c,x,e,n,i,o)}completeUpgrade(e,n,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[Fv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>gx)return Xi(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Ov("sha1").update(n+Bv).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[Yn.extensionName]){let w=e[Yn.extensionName].params,S=px.format({[Yn.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&as(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as Ng,mkdirSync as Mg}from"node:fs";import{join as Bg}from"node:path";function El(t){let e=t.retentionDays??Ug,n=t.clock??(()=>Pn(new Date));ds={bridgeSink:new Qr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:n}),agentSinks:new Map,makeAgentSink:o=>new Qr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:n})};let i=n();as(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])as(t.agentLogsDir(o),"agent",i,e)}function Gg(t,e){let n=t.agentSinks.get(e);return n||(n=t.makeAgentSink(e),t.agentSinks.set(e,n)),n}function vl(t){Aa=t}function Sl(t){return or[Aa]<=or[t]}function Il(t,e){let n=or[t];return n===void 0?!0:n>=or[e]}function ls(t){bl={...t}}function Al(t){let e=(u,f=2)=>String(u).padStart(f,"0"),n=-t.getTimezoneOffset(),i=n>=0?"+":"-",o=Math.abs(n),c=e(Math.floor(o/60)),d=e(o%60);return`${Pn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function at(t,e,n,i,o){try{let c=`${JSON.stringify({ts:Al(new Date),level:e,module:n,msg:i,...o})}
|
|
11
|
+
`;Mg(t,{recursive:!0}),Ng(Bg(t,sr("bridge",Pn(new Date))),c)}catch{}}function jg(t,e){if(t)return t;let n=e?.agentId;return typeof n=="string"&&n.length>0?n:void 0}function cs(t,e,n,i,o){if(or[t]<or[Aa])return;let c=`${JSON.stringify({ts:Al(new Date),level:t,module:e,msg:n,...bl,...i})}
|
|
12
|
+
`;if(ds){let d=jg(o,i),u=d?Gg(ds,d):ds.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?zg.write(c):Fg.write(c)}function G(t,e){return{debug:(n,i)=>cs("debug",t,n,i,e),info:(n,i)=>cs("info",t,n,i,e),warn:(n,i)=>cs("warn",t,n,i,e),error:(n,i)=>cs("error",t,n,i,e),child:n=>G(`${t}.${n}`,e),forAgent:n=>G(t,n)}}var or,Aa,Fg,zg,bl,Ug,ds,te=Xe(()=>{"use strict";ir();Ia();or={debug:10,info:20,warn:30,error:40},Aa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Fg=process.stdout,zg=process.stderr,bl={},Ug=Ke("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ds=null});var k,He=Xe(()=>{"use strict";k=class extends Error{code;retriable;cause;constructor(e,n,i){super(n),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Rl={};va(Rl,{ACP_WRAPPER_NPM_PACKAGES:()=>us,_resetAcpInstallerForTests:()=>Vg,_setBinaryPathCacheForTests:()=>Jg,buildAcpSpawn:()=>ti,ensureAcpInstalled:()=>ar,getAcpBinaryPath:()=>fs,pickWhichLine:()=>Ca,probeAcpVersion:()=>$g,resolveAcpCommand:()=>Cl});import{readFileSync as kl}from"node:fs";import{createRequire as qg}from"node:module";import{dirname as Hg,resolve as Wg}from"node:path";function Ca(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let n=i=>e.find(o=>o.toLowerCase().endsWith(i));return n(".cmd")??n(".exe")??n(".bat")??n(".ps1")??e[0]}function Kg(t){let e=Tl.resolve(`${t.npmPackage}/package.json`),n=Hg(e),i=JSON.parse(kl(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 Wg(n,o)}async function ar(t,e){let n=Ta[t];if(!n)throw new k("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ei.get(t);if(i)return i;try{let o=Kg(n);return ei.set(t,o),ka.info("acp wrapper resolved",{framework:t,binary:n.binary,path:o}),o}catch(o){throw ka.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:n.npmPackage,err:String(o)}),new k("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${n.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
|
|
13
|
+
`),{cause:o})}}async function $g(t){let e=Ta[t];if(e)try{let n=Tl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(kl(n,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(n){ka.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(n)});return}}function fs(t){return ei.get(t)}function Cl(t,e){if(e)return e;let n=fs(t);if(!n)throw new k("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return n}function ti(t,e,n){if(e)return{command:e,args:[...n]};let i=Cl(t);return{command:process.execPath,args:[i,...n]}}function Vg(){ei.clear()}function Jg(t,e){ei.set(t,e)}var ka,Ta,us,Tl,ei,sn=Xe(()=>{"use strict";He();te();ka=G("agents.acp-installer"),Ta={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},us=Object.values(Ta).filter(t=>t!==void 0).map(t=>t.npmPackage),Tl=qg(import.meta.url),ei=new Map});import{chmod as Zg,mkdir as Xg,readFile as Qg,rename as em,rm as tm,writeFile as nm}from"node:fs/promises";import{dirname as rm}from"node:path";async function cr(t){try{let e=await Qg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function on(t,e,n){await Xg(rm(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await nm(i,e,{encoding:"utf8",mode:n?.mode}),await em(i,t),n?.mode!==void 0&&await Zg(t,n.mode)}catch(o){throw await tm(i,{force:!0}).catch(()=>{}),o}}async function dr(t,e,n){await on(t,`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,n)}var an=Xe(()=>{"use strict"});import{promises as Ol,readdirSync as im}from"node:fs";import{homedir as sm}from"node:os";import{sep as om,join as Ae,resolve as Ll}from"node:path";function Q(t){let e=t??sm(),n=Ae(e,".coze"),i=Ae(n,"bridge"),o=Ae(i,"lib"),c=Ae(i,"logs");return{cozeRoot:n,bridgeRoot:i,libDir:o,libEntry:Ae(o,"index.js"),binDir:Ae(i,"bin"),pidFile:Ae(i,"bridge.pid"),portFile:Ae(i,"bridge.port"),tokenFile:Ae(i,"bridge.token"),patTokenFile:Ae(i,"pat-token"),agentEnvFile:Ae(i,"agent-env.json"),logFile:Ae(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ae(c,"daemon-stdio.log"),installLock:Ae(i,"install.lock"),configFile:Ae(i,"config.json"),agentsRoot:Ae(n,"agents")}}function $e(t,e=Q()){let n=Ae(e.agentsRoot,t);return{root:n,config:Ae(n,"config.json"),workspace:Ae(n,"workspace"),logs:Ae(n,"logs")}}function hs(t=Q()){try{return im(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ni(t,e){let n=await Ol.realpath(Ll(t)).catch(()=>null);if(!n)return!1;let i=await Ol.realpath(Ll(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?n.toLowerCase():n,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+om)}var De=Xe(()=>{"use strict"});var ps={};va(ps,{AGENT_CONFIG_FILE_MODE:()=>xs,enforceAgentConfigMode:()=>dm,loadAgentConfig:()=>ke,persistAgentSessions:()=>ri,persistAgentSkills:()=>ii,saveAgentConfig:()=>Me});import{chmod as am,stat as cm}from"node:fs/promises";function ke(t,e){return cr($e(t,e).config)}function Me(t,e){return dr($e(t.agentId,e).config,t,{mode:xs})}async function dm(t,e){if(process.platform==="win32")return;let n=$e(t,e).config;try{let i=await cm(n);if(!i.isFile())return;let o=i.mode&511;o!==xs&&(await am(n,xs),Nl.warn("agent config mode auto-corrected to 0600",{path:n,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Nl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:n,err:String(i)})}}async function ri(t,e,n){let i=await ke(t,n);i&&(i.sessions=Object.fromEntries(e),await Me(i,n))}async function ii(t,e,n){let i=await ke(t,n);i&&(i.skills=e,await Me(i,n))}var Nl,xs,cn=Xe(()=>{"use strict";an();te();De();Nl=G("agent-config"),xs=384});var Da=oe((eA,Fl)=>{Fl.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 ms=oe(Ul=>{var zl={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 pm(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(n,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(zl))Ul[t]=pm(zl[t])});var Wl=oe((nA,Hl)=>{var gm=le("fs"),Oe=le("path"),Gl=Da(),mm=ms(),wm=typeof process=="object"&&process.platform==="win32",jl=t=>typeof t=="object"&&t!==null,ql=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=gm,jl(t)&&jl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Hl.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function n(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw mm.FILE_IN_THE_WAY(`"${o}"`)}})}n(t)};Ee.prototype.writeFileTo=function(t,e,n,i){let o=this;if(o.fs.existsSync(t)){if(!n)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Oe.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,n,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!n)return o(!1);c.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var x=Oe.dirname(t);c.fs.exists(x,function(g){g||c.makeDir(x),c.fs.open(t,"w",438,function(w,S){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function n(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Oe.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&d.push(Oe.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(n(f,o,c)))}),d}return n(t,void 0,!0)};Ee.prototype.findFilesAsync=function(t,e){let n=this,i=[];n.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Oe.join(t,u),n.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Oe.normalize(u)+(x.isDirectory()?n.sep:"")),x.isDirectory()?n.findFilesAsync(u,function(g,w){if(g)return e(g);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return ql[(t^e)&255]^t>>>8};Ee.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,n=-1;for(let i=0;i<e;)n=Ee.crc32update(n,t[i++]);return~n>>>0};Ee.methodToString=function(t){switch(t){case Gl.STORED:return"STORED ("+t+")";case Gl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let n=t.length>>>0;for(let i=n-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var n=e.split("/"),i=0,o=n.length;i<o;i++){var c=Oe.normalize(Oe.join(t,n.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,n){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?n(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let n=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+n};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,n=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),n=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|n};Ee.isWin=wm;Ee.crcTable=ql});var $l=oe((rA,Kl)=>{var _m=le("path");Kl.exports=function(t,{fs:e}){var n=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return n&&e.existsSync(n)?(o=e.statSync(n),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=_m.basename(n)[0]==="."):console.warn("Invalid path: "+n),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:n,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Jl=oe((iA,Vl)=>{Vl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var fr=oe((sA,ur)=>{ur.exports=Wl();ur.exports.Constants=Da();ur.exports.Errors=ms();ur.exports.FileAttr=$l();ur.exports.decoder=Jl()});var Zl=oe((oA,Yl)=>{var dn=fr(),F=dn.Constants;Yl.exports=function(){var t=20,e=10,n=0,i=0,o=0,c=0,d=0,u=0,f=0,x=0,g=0,w=0,S=0,y=0,v=0;t|=dn.isWin?2560:768,n|=F.FLG_EFS;let I={extraLen:0},A=b=>Math.max(0,b)>>>0,T=b=>Math.max(0,b)&65535,P=b=>Math.max(0,b)&255;return o=dn.fromDate2DOS(new Date),{get made(){return t},set made(b){t=b},get version(){return e},set version(b){e=b},get flags(){return n},set flags(b){n=b},get flags_efs(){return(n&F.FLG_EFS)>0},set flags_efs(b){b?n|=F.FLG_EFS:n&=~F.FLG_EFS},get flags_desc(){return(n&F.FLG_DESC)>0},set flags_desc(b){b?n|=F.FLG_DESC:n&=~F.FLG_DESC},get method(){return i},set method(b){switch(b){case F.STORED:this.version=10;case F.DEFLATED:default:this.version=20}i=b},get time(){return dn.fromDOS2Date(this.timeval)},set time(b){b=new Date(b),this.timeval=dn.fromDate2DOS(b)},get timeval(){return o},set timeval(b){o=A(b)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(b){c=A(b)},get compressedSize(){return d},set compressedSize(b){d=A(b)},get size(){return u},set size(b){u=A(b)},get fileNameLength(){return f},set fileNameLength(b){f=b},get extraLength(){return x},set extraLength(b){x=b},get extraLocalLength(){return I.extraLen},set extraLocalLength(b){I.extraLen=b},get commentLength(){return g},set commentLength(b){g=b},get diskNumStart(){return w},set diskNumStart(b){w=A(b)},get inAttr(){return S},set inAttr(b){S=A(b)},get attr(){return y},set attr(b){y=A(b)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(b){v=A(b)},get encrypted(){return(n&F.FLG_ENC)===F.FLG_ENC},get centralHeaderSize(){return F.CENHDR+f+x+g},get realDataOffset(){return v+F.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(b){var C=b.slice(v,v+F.LOCHDR);if(C.readUInt32LE(0)!==F.LOCSIG)throw dn.Errors.INVALID_LOC();I.version=C.readUInt16LE(F.LOCVER),I.flags=C.readUInt16LE(F.LOCFLG),I.flags_desc=(I.flags&F.FLG_DESC)>0,I.method=C.readUInt16LE(F.LOCHOW),I.time=C.readUInt32LE(F.LOCTIM),I.crc=C.readUInt32LE(F.LOCCRC),I.compressedSize=C.readUInt32LE(F.LOCSIZ),I.size=C.readUInt32LE(F.LOCLEN),I.fnameLen=C.readUInt16LE(F.LOCNAM),I.extraLen=C.readUInt16LE(F.LOCEXT);let D=v+F.LOCHDR+I.fnameLen,B=D+I.extraLen;return b.slice(D,B)},loadFromBinary:function(b){if(b.length!==F.CENHDR||b.readUInt32LE(0)!==F.CENSIG)throw dn.Errors.INVALID_CEN();t=b.readUInt16LE(F.CENVEM),e=b.readUInt16LE(F.CENVER),n=b.readUInt16LE(F.CENFLG),i=b.readUInt16LE(F.CENHOW),o=b.readUInt32LE(F.CENTIM),c=b.readUInt32LE(F.CENCRC),d=b.readUInt32LE(F.CENSIZ),u=b.readUInt32LE(F.CENLEN),f=b.readUInt16LE(F.CENNAM),x=b.readUInt16LE(F.CENEXT),g=b.readUInt16LE(F.CENCOM),w=b.readUInt16LE(F.CENDSK),S=b.readUInt16LE(F.CENATT),y=b.readUInt32LE(F.CENATX),v=b.readUInt32LE(F.CENOFF)},localHeaderToBinary:function(){var b=Buffer.alloc(F.LOCHDR);return b.writeUInt32LE(F.LOCSIG,0),b.writeUInt16LE(e,F.LOCVER),b.writeUInt16LE(n,F.LOCFLG),b.writeUInt16LE(i,F.LOCHOW),b.writeUInt32LE(o,F.LOCTIM),b.writeUInt32LE(c,F.LOCCRC),b.writeUInt32LE(d,F.LOCSIZ),b.writeUInt32LE(u,F.LOCLEN),b.writeUInt16LE(f,F.LOCNAM),b.writeUInt16LE(I.extraLen,F.LOCEXT),b},centralHeaderToBinary:function(){var b=Buffer.alloc(F.CENHDR+f+x+g);return b.writeUInt32LE(F.CENSIG,0),b.writeUInt16LE(t,F.CENVEM),b.writeUInt16LE(e,F.CENVER),b.writeUInt16LE(n,F.CENFLG),b.writeUInt16LE(i,F.CENHOW),b.writeUInt32LE(o,F.CENTIM),b.writeUInt32LE(c,F.CENCRC),b.writeUInt32LE(d,F.CENSIZ),b.writeUInt32LE(u,F.CENLEN),b.writeUInt16LE(f,F.CENNAM),b.writeUInt16LE(x,F.CENEXT),b.writeUInt16LE(g,F.CENCOM),b.writeUInt16LE(w,F.CENDSK),b.writeUInt16LE(S,F.CENATT),b.writeUInt32LE(y,F.CENATX),b.writeUInt32LE(v,F.CENOFF),b},toJSON:function(){let b=function(C){return C+" bytes"};return{made:t,version:e,flags:n,method:dn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:b(d),size:b(u),fileNameLength:b(f),extraLength:b(x),commentLength:b(g),diskNumStart:w,inAttr:S,attr:y,offset:v,centralHeaderSize:b(F.CENHDR+f+x+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ql=oe((aA,Xl)=>{var hr=fr(),_e=hr.Constants;Xl.exports=function(){var t=0,e=0,n=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return n},set size(c){n=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return _e.ENDHDR+o},loadFromBinary:function(c){if((c.length!==_e.ENDHDR||c.readUInt32LE(0)!==_e.ENDSIG)&&(c.length<_e.ZIP64HDR||c.readUInt32LE(0)!==_e.ZIP64SIG))throw hr.Errors.INVALID_END();c.readUInt32LE(0)===_e.ENDSIG?(t=c.readUInt16LE(_e.ENDSUB),e=c.readUInt16LE(_e.ENDTOT),n=c.readUInt32LE(_e.ENDSIZ),i=c.readUInt32LE(_e.ENDOFF),o=c.readUInt16LE(_e.ENDCOM)):(t=hr.readBigUInt64LE(c,_e.ZIP64SUB),e=hr.readBigUInt64LE(c,_e.ZIP64TOT),n=hr.readBigUInt64LE(c,_e.ZIP64SIZE),i=hr.readBigUInt64LE(c,_e.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(_e.ENDHDR+o);return c.writeUInt32LE(_e.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,_e.ENDSUB),c.writeUInt16LE(e,_e.ENDTOT),c.writeUInt32LE(n,_e.ENDSIZ),c.writeUInt32LE(i,_e.ENDOFF),c.writeUInt16LE(o,_e.ENDCOM),c.fill(" ",_e.ENDHDR),c},toJSON:function(){let c=function(d,u){let f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:n+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var La=oe(Oa=>{Oa.EntryHeader=Zl();Oa.MainHeader=Ql()});var tu=oe((dA,eu)=>{eu.exports=function(t){var e=le("zlib"),n={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,n)},deflateAsync:function(i){var o=e.createDeflateRaw(n),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var x=0;x<c.length;x++){var g=c[x];g.copy(u,f),f+=g.length}i&&i(u)}),o.end(t)}}}});var ru=oe((lA,nu)=>{var ym=+(process.versions?process.versions.node:"").split(".")[0]||0;nu.exports=function(t,e){var n=le("zlib");let i=ym>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return n.inflateRawSync(t,i)},inflateAsync:function(o){var c=n.createInflateRaw(i),d=[],u=0;c.on("data",function(f){d.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var g=0;g<d.length;g++){var w=d[g];w.copy(f,x),x+=w.length}o&&o(f)}),c.end(t)}}}});var cu=oe((uA,au)=>{"use strict";var{randomFillSync:iu}=le("crypto"),bm=ms(),Em=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),ou=(t,e)=>Math.imul(t,e)>>>0,su=(t,e)=>Em[(t^e)&255]^t>>>8,si=()=>typeof iu=="function"?iu(Buffer.alloc(12)):si.node();si.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let n=0;n<e;n++)t[n]=Math.random()*256&255;return t};var ws={genSalt:si};function _s(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let n=0;n<e.length;n++)this.updateKeys(e[n])}_s.prototype.updateKeys=function(t){let e=this.keys;return e[0]=su(e[0],t),e[1]+=e[0]&255,e[1]=ou(e[1],134775813)+1,e[2]=su(e[2],e[1]>>>24),t};_s.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return ou(t,t^1)>>8&255};function vm(t){let e=new _s(t);return function(n){let i=Buffer.alloc(n.length),o=0;for(let c of n)i[o++]=e.updateKeys(c^e.next());return i}}function Sm(t){let e=new _s(t);return function(n,i,o=0){i||(i=Buffer.alloc(n.length));for(let c of n){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function Im(t,e,n){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=vm(n),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw bm.WRONG_PASSWORD();return i(t.slice(12))}function Am(t){Buffer.isBuffer(t)&&t.length>=12?ws.genSalt=function(){return t.slice(0,12)}:t==="node"?ws.genSalt=si.node:ws.genSalt=si}function km(t,e,n,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Sm(n),c=ws.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)}au.exports={decrypt:Im,encrypt:km,_salter:Am}});var du=oe(ys=>{ys.Deflater=tu();ys.Inflater=ru();ys.ZipCrypto=cu()});var Ma=oe((hA,lu)=>{var ae=fr(),Tm=La(),ve=ae.Constants,Na=du();lu.exports=function(t,e){var n=new Tm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let g=t,w=typeof g.decoder=="object"?g.decoder:ae.decoder;x=w.hasOwnProperty("efs")?w.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=n.loadLocalHeaderFromBinary(e),e.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function y(b){if(!n.flags_desc&&!n.localHeader.flags_desc){if(ae.crc32(b)!==n.localHeader.crc)return!1}else{let C={},D=n.realDataOffset+n.compressedSize;if(e.readUInt32LE(D)==ve.LOCSIG||e.readUInt32LE(D)==ve.CENSIG)throw ae.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(D)==ve.EXTSIG)C.crc=e.readUInt32LE(D+ve.EXTCRC),C.compressedSize=e.readUInt32LE(D+ve.EXTSIZ),C.size=e.readUInt32LE(D+ve.EXTLEN);else if(e.readUInt16LE(D+12)===19280)C.crc=e.readUInt32LE(D+ve.EXTCRC-4),C.compressedSize=e.readUInt32LE(D+ve.EXTSIZ-4),C.size=e.readUInt32LE(D+ve.EXTLEN-4);else throw ae.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==n.compressedSize||C.size!==n.size||C.crc!==n.crc)throw ae.Errors.DESCRIPTOR_FAULTY();if(ae.crc32(b)!==C.crc)return!1}return!0}function v(b,C,D){if(typeof C>"u"&&typeof b=="string"&&(D=b,b=void 0),c)return b&&C&&C(Buffer.alloc(0),ae.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=S();if(B.length===0)return b&&C&&C(B),B;if(n.encrypted){if(typeof D!="string"&&!Buffer.isBuffer(D))throw ae.Errors.INVALID_PASS_PARAM();B=Na.ZipCrypto.decrypt(B,n,D)}var M=Buffer.alloc(n.size);switch(n.method){case ae.Constants.STORED:if(B.copy(M),y(M))return b&&C&&C(M),M;throw b&&C&&C(M,ae.Errors.BAD_CRC()),ae.Errors.BAD_CRC();case ae.Constants.DEFLATED:var J=new Na.Inflater(B,n.size);if(b)J.inflateAsync(function($){$.copy($,0),C&&(y($)?C($):C($,ae.Errors.BAD_CRC()))});else{if(J.inflate(M).copy(M,0),!y(M))throw ae.Errors.BAD_CRC(`"${w.decode(i)}"`);return M}break;default:throw b&&C&&C(Buffer.alloc(0),ae.Errors.UNKNOWN_METHOD()),ae.Errors.UNKNOWN_METHOD()}}function I(b,C){if((!d||!d.length)&&Buffer.isBuffer(e))return b&&C&&C(S()),S();if(d.length&&!c){var D;switch(n.method){case ae.Constants.STORED:return n.compressedSize=n.size,D=Buffer.alloc(d.length),d.copy(D),b&&C&&C(D),D;default:case ae.Constants.DEFLATED:var B=new Na.Deflater(d);if(b)B.deflateAsync(function(J){D=Buffer.alloc(J.length),n.compressedSize=J.length,J.copy(D),C&&C(D)});else{var M=B.deflate();return n.compressedSize=M.length,M}B=null;break}}else if(b&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function A(b,C){return ae.readBigUInt64LE(b,C)}function T(b){try{for(var C=0,D,B,M;C+4<b.length;)D=b.readUInt16LE(C),C+=2,B=b.readUInt16LE(C),C+=2,M=b.slice(C,C+B),C+=B,ve.ID_ZIP64===D&&P(M)}catch{throw ae.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(b){var C,D,B,M;b.length>=ve.EF_ZIP64_SCOMP&&(C=A(b,ve.EF_ZIP64_SUNCOMP),n.size===ve.EF_ZIP64_OR_32&&(n.size=C)),b.length>=ve.EF_ZIP64_RHO&&(D=A(b,ve.EF_ZIP64_SCOMP),n.compressedSize===ve.EF_ZIP64_OR_32&&(n.compressedSize=D)),b.length>=ve.EF_ZIP64_DSN&&(B=A(b,ve.EF_ZIP64_RHO),n.offset===ve.EF_ZIP64_OR_32&&(n.offset=B)),b.length>=ve.EF_ZIP64_DSN+4&&(M=b.readUInt32LE(ve.EF_ZIP64_DSN),n.diskNumStart===ve.EF_ZIP64_OR_16&&(n.diskNumStart=M))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(b){i=ae.toBuffer(b,w.encode);var C=i[i.length-1];c=C===47||C===92,n.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(b){u=b,n.extraLength=b.length,T(b)},get comment(){return w.decode(o)},set comment(b){if(o=ae.toBuffer(b,w.encode),n.commentLength=o.length,o.length>65535)throw ae.Errors.COMMENT_TOO_LONG()},get name(){var b=w.decode(i);return c?b.substr(b.length-1).split("/").pop():b.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(b){I(!0,b)},setData:function(b){d=ae.toBuffer(b,ae.decoder.encode),!c&&d.length?(n.size=d.length,n.method=ae.Constants.DEFLATED,n.crc=ae.crc32(b),n.changed=!0):n.method=ae.Constants.STORED},getData:function(b){return n.changed?d:v(!1,null,b)},getDataAsync:function(b,C){n.changed?b(d):v(!0,b,C)},set attr(b){n.attr=b},get attr(){return n.attr},set header(b){n.loadFromBinary(b)},get header(){return n},packCentralHeader:function(){n.flags_efs=this.efs,n.extraLength=u.length;var b=n.centralHeaderToBinary(),C=ae.Constants.CENHDR;return i.copy(b,C),C+=i.length,u.copy(b,C),C+=n.extraLength,o.copy(b,C),b},packLocalHeader:function(){let b=0;n.flags_efs=this.efs,n.extraLocalLength=f.length;let C=n.localHeaderToBinary(),D=Buffer.alloc(C.length+i.length+n.extraLocalLength);return C.copy(D,b),b+=C.length,i.copy(D,b),b+=i.length,f.copy(D,b),b+=f.length,D},toJSON:function(){let b=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:b(e),data:b(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var hu=oe((xA,fu)=>{var uu=Ma(),Cm=La(),We=fr();fu.exports=function(t,e){var n=[],i={},o=Buffer.alloc(0),c=new Cm.MainHeader,d=!1,u=null;let f=new Set,x=e,{noSort:g,decoder:w}=x;t?v(x.readEntries):d=!0;function S(){let A=new Set;for(let T of Object.keys(i)){let P=T.split("/");if(P.pop(),!!P.length)for(let b=0;b<P.length;b++){let C=P.slice(0,b+1).join("/")+"/";A.add(C)}}for(let T of A)if(!(T in i)){let P=new uu(x);P.entryName=T,P.attr=16,P.temporary=!0,n.push(P),i[P.entryName]=P,f.add(P)}}function y(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/We.Constants.CENHDR)throw We.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(c.diskEntries);for(var A=c.offset,T=0;T<n.length;T++){var P=A,b=new uu(x,t);b.header=t.slice(P,P+=We.Constants.CENHDR),b.entryName=t.slice(P,P+=b.header.fileNameLength),b.header.extraLength&&(b.extra=t.slice(P,P+=b.header.extraLength)),b.header.commentLength&&(b.comment=t.slice(P,P+b.header.commentLength)),A+=b.header.centralHeaderSize,n[T]=b,i[b.entryName]=b}f.clear(),S()}function v(A){var T=t.length-We.Constants.ENDHDR,P=Math.max(0,T-65535),b=P,C=t.length,D=-1,B=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),T;T>=b;T--)if(t[T]===80){if(t.readUInt32LE(T)===We.Constants.ENDSIG){D=T,B=T,C=T+We.Constants.ENDHDR,b=T-We.Constants.END64HDR;continue}if(t.readUInt32LE(T)===We.Constants.END64SIG){b=P;continue}if(t.readUInt32LE(T)===We.Constants.ZIP64SIG){D=T,C=T+We.readBigUInt64LE(t,T+We.Constants.ZIP64SIZE)+We.Constants.ZIP64LEAD;break}}if(D==-1)throw We.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(D,C)),c.commentLength&&(o=t.slice(B+We.Constants.ENDHDR)),A&&y()}function I(){n.length>1&&!g&&n.sort((A,T)=>A.entryName.toLowerCase().localeCompare(T.entryName.toLowerCase()))}return{get entries(){return d||y(),n.filter(A=>!f.has(A))},get comment(){return w.decode(o)},set comment(A){o=We.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?n.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||y(),i[A]||null},setEntry:function(A){d||y(),n.push(A),i[A.entryName]=A,c.totalEntries=n.length},deleteFile:function(A,T=!0){d||y();let P=i[A];this.getEntryChildren(P,T).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||y();let T=i[A],P=n.indexOf(T);P>=0&&(n.splice(P,1),delete i[A],c.totalEntries=n.length)},getEntryChildren:function(A,T=!0){if(d||y(),typeof A=="object")if(A.isDirectory&&T){let P=[],b=A.entryName;for(let C of n)C.entryName.startsWith(b)&&P.push(C);return P}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let T=this.getEntryChildren(A);return T.includes(A)?T.length-1:T.length}return 0},compressToBuffer:function(){d||y(),I();let A=[],T=[],P=0,b=0;c.size=0,c.offset=0;let C=0;for(let M of this.entries){let J=M.getCompressedData();M.header.offset=b;let $=M.packLocalHeader(),ne=$.length+J.length;b+=ne,A.push($),A.push(J);let Z=M.packCentralHeader();T.push(Z),c.size+=Z.length,P+=ne+Z.length,C++}P+=c.mainHeaderSize,c.offset=b,c.totalEntries=C,b=0;let D=Buffer.alloc(P);for(let M of A)M.copy(D,b),b+=M.length;for(let M of T)M.copy(D,b),b+=M.length;let B=c.toBinary();return o&&o.copy(B,We.Constants.ENDHDR),B.copy(D,b),t=D,d=!1,D},toAsyncBuffer:function(A,T,P,b){try{d||y(),I();let C=[],D=[],B=0,M=0,J=0;c.size=0,c.offset=0;let $=function(ne){if(ne.length>0){let Z=ne.shift(),ie=Z.entryName+Z.extra.toString();P&&P(ie),Z.getCompressedDataAsync(function(se){b&&b(ie),Z.header.offset=M;let R=Z.packLocalHeader(),z=R.length+se.length;M+=z,C.push(R),C.push(se);let H=Z.packCentralHeader();D.push(H),c.size+=H.length,B+=z+H.length,J++,$(ne)})}else{B+=c.mainHeaderSize,c.offset=M,c.totalEntries=J,M=0;let Z=Buffer.alloc(B);C.forEach(function(se){se.copy(Z,M),M+=se.length}),D.forEach(function(se){se.copy(Z,M),M+=se.length});let ie=c.toBinary();o&&o.copy(ie,We.Constants.ENDHDR),ie.copy(Z,M),t=Z,d=!1,A(Z)}};$(Array.from(this.entries))}catch(C){T(C)}}}}});var gu=oe((pA,pu)=>{var be=fr(),ye=le("path"),Rm=Ma(),Pm=hu(),Dn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),xu=(...t)=>be.findLast(t,e=>typeof e=="string"),Dm=(...t)=>be.findLast(t,e=>typeof e=="function"),Om={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};pu.exports=function(t,e){let n=null,i=Object.assign(Object.create(null),Om);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(n=t,i.method=be.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new be(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=be.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=be.Constants.FILE,i.filename=t,n=o.fs.readFileSync(t);else throw be.Errors.INVALID_FILENAME();let c=new Pm(n,i),{canonical:d,sanitize:u,zipnamefix:f}=be;function x(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(ye.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(v=c.getEntry(y.entryName)),v)return v}return null}function g(y){let{join:v,normalize:I,sep:A}=ye.posix;return v(ye.isAbsolute(y)?"/":".",I(A+y.split("\\").join(A)+A))}function w(y){return y instanceof RegExp?(function(v){return function(I){return v.test(I)}})(y):typeof y!="function"?()=>!0:y}let S=(y,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",ye.relative(y,v)+I};return{readFile:function(y,v){var I=x(y);return I&&I.getData(v)||null},childCount:function(y){let v=x(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var I=x(y);I?I.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var I=x(y);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,I){var A=x(y);A?A.getDataAsync(function(T,P){if(P){v(T,P);return}T&&T.length?v(T.toString(I||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var I=x(y);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(y){var v=x(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var I=x(y);I&&(I.comment=v)},getZipEntryComment:function(y){var v=x(y);return v&&v.comment||""},updateFile:function(y,v){var I=x(y);I&&I.setData(v)},addLocalFile:function(y,v,I,A){if(o.fs.existsSync(y)){v=v?g(v):"";let T=ye.win32.basename(ye.win32.normalize(y));v+=I||T;let P=o.fs.statSync(y),b=P.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);P.isDirectory()&&(v+=o.sep),this.addFile(v,b,A,P)}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let I=ye.resolve(y.localPath),{comment:A}=y,{zipPath:T,zipName:P}=y,b=this;o.fs.stat(I,function(C,D){if(C)return v(C,!1);T=T?g(T):"";let B=ye.win32.basename(ye.win32.normalize(I));if(T+=P||B,D.isFile())o.fs.readFile(I,function(M,J){return M?v(M,!1):(b.addFile(T,J,A,D),setImmediate(v,void 0,!0))});else if(D.isDirectory())return T+=o.sep,b.addFile(T,Buffer.alloc(0),A,D),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,I){if(I=w(I),v=v?g(v):"",y=ye.normalize(y),o.fs.existsSync(y)){let A=o.findFiles(y),T=this;if(A.length)for(let P of A){let b=ye.join(v,S(y,P));I(b)&&T.addLocalFile(P,ye.dirname(b))}}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,I,A){A=w(A),I=I?g(I):"",y=ye.normalize(y);var T=this;o.fs.open(y,"r",function(P){if(P&&P.code==="ENOENT")v(void 0,be.Errors.FILE_NOT_FOUND(y));else if(P)v(void 0,P);else{var b=o.findFiles(y),C=-1,D=function(){if(C+=1,C<b.length){var B=b[C],M=S(y,B).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(B,function(J,$){J&&v(void 0,J),$.isFile()?o.fs.readFile(B,function(ne,Z){ne?v(void 0,ne):(T.addFile(I+M,Z,"",$),D())}):(T.addFile(I+M+"/",Buffer.alloc(0),"",$),D())}):process.nextTick(()=>{D()})}else v(!0,void 0)};D()}})},addLocalFolderAsync2:function(y,v){let I=this;y=typeof y=="object"?y:{localPath:y},localPath=ye.resolve(g(y.localPath));let{zipPath:A,filter:T,namefix:P}=y;T instanceof RegExp?T=(function(D){return function(B){return D.test(B)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?g(A):"",P=="latin1"&&(P=D=>D.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=D=>D);let b=D=>ye.join(A,P(S(localPath,D))),C=D=>ye.win32.basename(ye.win32.normalize(P(D)));o.fs.open(localPath,"r",function(D){D&&D.code==="ENOENT"?v(void 0,be.Errors.FILE_NOT_FOUND(localPath)):D?v(void 0,D):o.findFilesAsync(localPath,function(B,M){if(B)return v(B);M=M.filter(J=>T(b(J))),M.length||v(void 0,!1),setImmediate(M.reverse().reduce(function(J,$){return function(ne,Z){if(ne||Z===!1)return setImmediate(J,ne,!1);I.addLocalFileAsync({localPath:$,zipPath:ye.dirname(b($)),zipName:C($)},J)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(T,P)=>{T&&A(T),P&&I(this)})})},addFile:function(y,v,I,A){y=f(y);let T=x(y),P=T!=null;P||(T=new Rm(i),T.entryName=y),T.comment=I||"";let b=typeof A=="object"&&A instanceof o.fs.Stats;b&&(T.header.time=A.mtime);var C=T.isDirectory?16:0;let D=T.isDirectory?16384:32768;return b?D|=4095&A.mode:typeof A=="number"?D|=4095&A:D|=T.isDirectory?493:420,C=(C|D<<16)>>>0,T.attr=C,T.setData(v),P||c.setEntry(T),T},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return x(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,I,A,T,P){A=Dn(!1,A),T=Dn(!1,T),I=Dn(!0,I),P=xu(T,P);var b=x(y);if(!b)throw be.Errors.NO_ENTRY();var C=d(b.entryName),D=u(v,P&&!b.isDirectory?P:I?C:ye.basename(C));if(b.isDirectory){var B=c.getEntryChildren(b);return B.forEach(function($){if($.isDirectory)return;var ne=$.getData();if(!ne)throw be.Errors.CANT_EXTRACT_FILE();var Z=d($.entryName),ie=u(v,I?Z:ye.basename(Z));let se=T?$.header.fileAttr:void 0;o.writeFileTo(ie,ne,A,se)}),!0}var M=b.getData(c.password);if(!M)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(D)&&!A)throw be.Errors.CANT_OVERRIDE();let J=T?y.header.fileAttr:void 0;return o.writeFileTo(D,M,A,J),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(y);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(y,v,I,A){if(I=Dn(!1,I),A=xu(I,A),v=Dn(!1,v),!c)throw be.Errors.NO_ZIP();c.entries.forEach(function(T){var P=u(y,d(T.entryName));if(T.isDirectory){o.makeDir(P);return}var b=T.getData(A);if(!b)throw be.Errors.CANT_EXTRACT_FILE();let C=I?T.header.fileAttr:void 0;o.writeFileTo(P,b,v,C);try{o.fs.utimesSync(P,T.header.time,T.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,I,A){if(A=Dm(v,I,A),I=Dn(!1,I),v=Dn(!1,v),!A)return new Promise((D,B)=>{this.extractAllToAsync(y,v,I,function(M){M?B(M):D(this)})});if(!c){A(be.Errors.NO_ZIP());return}y=ye.resolve(y);let T=D=>u(y,ye.normalize(d(D.entryName))),P=(D,B)=>new Error(D+': "'+B+'"'),b=[],C=[];c.entries.forEach(D=>{D.isDirectory?b.push(D):C.push(D)});for(let D of b){let B=T(D),M=I?D.header.fileAttr:void 0;try{o.makeDir(B),M&&o.fs.chmodSync(B,M),o.fs.utimesSync(B,D.header.time,D.header.time)}catch{A(P("Unable to create folder",B))}}C.reverse().reduce(function(D,B){return function(M){if(M)D(M);else{let J=ye.normalize(d(B.entryName)),$=u(y,J);B.getDataAsync(function(ne,Z){if(Z)D(Z);else if(!ne)D(be.Errors.CANT_EXTRACT_FILE());else{let ie=I?B.header.fileAttr:void 0;o.writeFileToAsync($,ne,v,ie,function(se){se||D(P("Unable to write file",$)),o.fs.utimes($,B.header.time,B.header.time,function(R){R?D(P("Unable to set times",$)):D()})})}})}}},A)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(y,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((T,P)=>{!y&&i.filename&&(y=i.filename),y||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(b=>{let C=D=>D?T(D):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,b,I,A,C)},P)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,I,A){return typeof y=="function"?(c.toAsyncBuffer(y,v,I,A),null):c.compressToBuffer()}}}});import{execFile as z_,spawn as U_,spawnSync as Ok}from"node:child_process";import{promisify as G_}from"node:util";function q_(t){if(process.platform!=="win32")return!1;if(Mf.test(t))return!0;let n=(t.split(/[/\\]/).pop()??t).replace(Mf,"").toLowerCase();return j_.has(n)}function Bf(t,e){if(process.platform!=="win32")return e??{};let n={...e??{}};return q_(t)&&n.shell===void 0&&(n.shell=!0),n.windowsHide===void 0&&(n.windowsHide=!0),n}function et(t,e=[],n={}){return U_(t,e,Bf(t,n))}function Ff(t,e=[],n={}){return H_(t,e,Bf(t,n))}var j_,Mf,H_,Kt=Xe(()=>{"use strict";j_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Mf=/\.(cmd|bat|ps1)$/i;H_=G_(z_)});var Vt=oe((pR,Eh)=>{"use strict";var yh=["nodebuffer","arraybuffer","fragments"],bh=typeof Blob<"u";bh&&yh.push("blob");Eh.exports={BINARY_TYPES:yh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:bh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ki=oe((gR,ko)=>{"use strict";var{EMPTY_BUFFER:EE}=Vt(),hd=Buffer[Symbol.species];function vE(t,e){if(t.length===0)return EE;if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];n.set(c,i),i+=c.length}return i<e?new hd(n.buffer,n.byteOffset,i):n}function vh(t,e,n,i,o){for(let c=0;c<o;c++)n[i+c]=t[c]^e[c&3]}function Sh(t,e){for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function SE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xd(t){if(xd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new hd(t):ArrayBuffer.isView(t)?e=new hd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xd.readOnly=!1),e}ko.exports={concat:vE,mask:vh,toArrayBuffer:SE,toBuffer:xd,unmask:Sh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=le("bufferutil");ko.exports.mask=function(e,n,i,o,c){c<48?vh(e,n,i,o,c):t.mask(e,n,i,o,c)},ko.exports.unmask=function(e,n){e.length<32?Sh(e,n):t.unmask(e,n)}}catch{}});var kh=oe((mR,Ah)=>{"use strict";var Ih=Symbol("kDone"),pd=Symbol("kRun"),gd=class{constructor(e){this[Ih]=()=>{this.pending--,this[pd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pd]()}[pd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ih])}}};Ah.exports=gd});var zr=oe((wR,Ph)=>{"use strict";var $i=le("zlib"),Th=Ki(),IE=kh(),{kStatusCode:Ch}=Vt(),AE=Buffer[Symbol.species],kE=Buffer.from([0,0,255,255]),Co=Symbol("permessage-deflate"),Jt=Symbol("total-length"),Br=Symbol("callback"),kn=Symbol("buffers"),Fr=Symbol("error"),To,md=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,!To){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;To=new IE(n)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Br];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let n=this._options,i=e.find(o=>!(n.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(n.serverMaxWindowBits===!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>o.server_max_window_bits)||typeof n.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return n.serverNoContextTakeover&&(i.server_no_context_takeover=!0),n.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof n.serverMaxWindowBits=="number"&&(i.server_max_window_bits=n.serverMaxWindowBits),typeof n.clientMaxWindowBits=="number"?i.client_max_window_bits=n.clientMaxWindowBits:(i.client_max_window_bits===!0||n.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let n=e[0];if(this._options.clientNoContextTakeover===!1&&n.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!n.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(n.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&n.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return n}normalizeParams(e){return e.forEach(n=>{Object.keys(n).forEach(i=>{let o=n[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);n[i]=o})}),e}decompress(e,n,i){To.add(o=>{this._decompress(e,n,(c,d)=>{o(),i(c,d)})})}compress(e,n,i){To.add(o=>{this._compress(e,n,(c,d)=>{o(),i(c,d)})})}_decompress(e,n,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=$i.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Co]=this,this._inflate[Jt]=0,this._inflate[kn]=[],this._inflate.on("error",CE),this._inflate.on("data",Rh)}this._inflate[Br]=i,this._inflate.write(e),n&&this._inflate.write(kE),this._inflate.flush(()=>{let c=this._inflate[Fr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=Th.concat(this._inflate[kn],this._inflate[Jt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Jt]=0,this._inflate[kn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,n,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=$i.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Jt]=0,this._deflate[kn]=[],this._deflate.on("data",TE)}this._deflate[Br]=i,this._deflate.write(e),this._deflate.flush($i.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Th.concat(this._deflate[kn],this._deflate[Jt]);n&&(c=new AE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Br]=null,this._deflate[Jt]=0,this._deflate[kn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Ph.exports=md;function TE(t){this[kn].push(t),this[Jt]+=t.length}function Rh(t){if(this[Jt]+=t.length,this[Co]._maxPayload<1||this[Jt]<=this[Co]._maxPayload){this[kn].push(t);return}this[Fr]=new RangeError("Max payload size exceeded"),this[Fr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Fr][Ch]=1009,this.removeListener("data",Rh),this.reset()}function CE(t){if(this[Co]._inflate=null,this[Fr]){this[Br](this[Fr]);return}t[Ch]=1007,this[Br](t)}});var Ur=oe((_R,Ro)=>{"use strict";var{isUtf8:Dh}=le("buffer"),{hasBlob:RE}=Vt(),PE=[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 DE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function wd(t){let e=t.length,n=0;for(;n<e;)if((t[n]&128)===0)n++;else if((t[n]&224)===192){if(n+1===e||(t[n+1]&192)!==128||(t[n]&254)===192)return!1;n+=2}else if((t[n]&240)===224){if(n+2>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||t[n]===224&&(t[n+1]&224)===128||t[n]===237&&(t[n+1]&224)===160)return!1;n+=3}else if((t[n]&248)===240){if(n+3>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||(t[n+3]&192)!==128||t[n]===240&&(t[n+1]&240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function OE(t){return RE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Ro.exports={isBlob:OE,isValidStatusCode:DE,isValidUTF8:wd,tokenChars:PE};if(Dh)Ro.exports.isValidUTF8=function(t){return t.length<24?wd(t):Dh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=le("utf-8-validate");Ro.exports.isValidUTF8=function(e){return e.length<32?wd(e):t(e)}}catch{}});var vd=oe((yR,zh)=>{"use strict";var{Writable:LE}=le("stream"),Oh=zr(),{BINARY_TYPES:NE,EMPTY_BUFFER:Lh,kStatusCode:ME,kWebSocket:BE}=Vt(),{concat:_d,toArrayBuffer:FE,unmask:zE}=Ki(),{isValidStatusCode:UE,isValidUTF8:Nh}=Ur(),Po=Buffer[Symbol.species],ut=0,Mh=1,Bh=2,Fh=3,yd=4,bd=5,Do=6,Ed=class extends LE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||NE[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[BE]=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=ut}_write(e,n,i){if(this._opcode===8&&this._state==ut)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 Po(i.buffer,i.byteOffset+e,i.length-e),new Po(i.buffer,i.byteOffset,e)}let n=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=n.length-e;e>=i.length?n.set(this._buffers.shift(),o):(n.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Po(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case ut:this.getInfo(e);break;case Mh:this.getPayloadLength16(e);break;case Bh:this.getPayloadLength64(e);break;case Fh:this.getMask();break;case yd:this.getData(e);break;case bd:case Do:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let n=this.consume(2);if((n[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(n[0]&64)===64;if(i&&!this._extensions[Oh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(n[0]&128)===128,this._opcode=n[0]&15,this._payloadLength=n[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(n[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=Mh:this._payloadLength===127?this._state=Bh:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let n=this.consume(8),i=n.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+n.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(n);return}this._masked?this._state=Fh:this._state=yd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=yd}getData(e){let n=Lh;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&zE(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._compressed){this._state=bd,this.decompress(n,e);return}if(n.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(n)}this.dataMessage(e)}decompress(e,n){this._extensions[Oh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return n(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(d);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let d=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");n(d);return}this._fragments.push(c)}this.dataMessage(n),this._state===ut&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=ut;return}let n=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=_d(i,n):this._binaryType==="arraybuffer"?o=FE(_d(i,n)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ut):(this._state=Do,setImmediate(()=>{this.emit("message",o,!0),this._state=ut,this.startLoop(e)}))}else{let o=_d(i,n);if(!this._skipUTF8Validation&&!Nh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===bd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ut):(this._state=Do,setImmediate(()=>{this.emit("message",o,!1),this._state=ut,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Lh),this.end();else{let i=e.readUInt16BE(0);if(!UE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(c);return}let o=new Po(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Nh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ut;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ut):(this._state=Do,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ut,this.startLoop(n)}))}createError(e,n,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(d,this.createError),d.code=c,d[ME]=o,d}};zh.exports=Ed});var Ad=oe((ER,jh)=>{"use strict";var{Duplex:bR}=le("stream"),{randomFillSync:GE}=le("crypto"),{types:{isUint8Array:jE}}=le("util"),Uh=zr(),{EMPTY_BUFFER:qE,kWebSocket:HE,NOOP:WE}=Vt(),{isBlob:Gr,isValidStatusCode:KE}=Ur(),{mask:Gh,toBuffer:Vn}=Ki(),ft=Symbol("kByteLength"),$E=Buffer.alloc(4),Oo=8*1024,Jn,jr=Oo,Et=0,VE=1,JE=2,Sd=class t{constructor(e,n,i){this._extensions=n||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=Et,this.onerror=WE,this[HE]=void 0}static frame(e,n){let i,o=!1,c=2,d=!1;n.mask&&(i=n.maskBuffer||$E,n.generateMask?n.generateMask(i):(jr===Oo&&(Jn===void 0&&(Jn=Buffer.alloc(Oo)),GE(Jn,0,Oo),jr=0),i[0]=Jn[jr++],i[1]=Jn[jr++],i[2]=Jn[jr++],i[3]=Jn[jr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!n.mask||d)&&n[ft]!==void 0?u=n[ft]:(e=Buffer.from(e),u=e.length):(u=e.length,o=n.mask&&n.readOnly&&!d);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=n.fin?n.opcode|128:n.opcode,n.rsv1&&(x[0]|=64),x[1]=f,f===126?x.writeUInt16BE(u,2):f===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),n.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(Gh(e,i,x,c,u),[x]):(Gh(e,i,e,0,u),[x,e])):[x,e]}close(e,n,i,o){let c;if(e===void 0)c=qE;else{if(typeof e!="number"||!KE(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(n);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof n=="string")c.write(n,2);else if(jE(n))c.set(n,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[ft]: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,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[ft]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Gr(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,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Gr(e)?(o=e.size,c=!1):(e=Vn(e),o=e.length,c=Vn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[ft]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Gr(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,n,i){let o=this._extensions[Uh.extensionName],c=n.binary?2:1,d=n.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Gr(e)?(u=e.size,f=!1):(e=Vn(e),u=e.length,f=Vn.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=u>=o._threshold),this._compress=d):(d=!1,c=0),n.fin&&(this._firstFragment=!0);let x={[ft]:u,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:d};Gr(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,n,i,o){this._bufferedBytes+=i[ft],this._state=JE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Id,this,u,o);return}this._bufferedBytes-=i[ft];let d=Vn(c);n?this.dispatch(d,n,i,o):(this._state=Et,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(YE,this,c,o)})}dispatch(e,n,i,o){if(!n){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Uh.extensionName];this._bufferedBytes+=i[ft],this._state=VE,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");Id(this,f,o);return}this._bufferedBytes-=i[ft],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][ft],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ft],this._queue.push(e)}sendFrame(e,n){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.write(e[0],n)}};jh.exports=Sd;function Id(t,e,n){typeof n=="function"&&n(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function YE(t,e,n){Id(t,e,n),t.onerror(e)}});var Zh=oe((vR,Yh)=>{"use strict";var{kForOnEventAttribute:Vi,kListener:kd}=Vt(),qh=Symbol("kCode"),Hh=Symbol("kData"),Wh=Symbol("kError"),Kh=Symbol("kMessage"),$h=Symbol("kReason"),qr=Symbol("kTarget"),Vh=Symbol("kType"),Jh=Symbol("kWasClean"),Yt=class{constructor(e){this[qr]=null,this[Vh]=e}get target(){return this[qr]}get type(){return this[Vh]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Yn=class extends Yt{constructor(e,n={}){super(e),this[qh]=n.code===void 0?0:n.code,this[$h]=n.reason===void 0?"":n.reason,this[Jh]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[qh]}get reason(){return this[$h]}get wasClean(){return this[Jh]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var Hr=class extends Yt{constructor(e,n={}){super(e),this[Wh]=n.error===void 0?null:n.error,this[Kh]=n.message===void 0?"":n.message}get error(){return this[Wh]}get message(){return this[Kh]}};Object.defineProperty(Hr.prototype,"error",{enumerable:!0});Object.defineProperty(Hr.prototype,"message",{enumerable:!0});var Ji=class extends Yt{constructor(e,n={}){super(e),this[Hh]=n.data===void 0?null:n.data}get data(){return this[Hh]}};Object.defineProperty(Ji.prototype,"data",{enumerable:!0});var ZE={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[Vi]&&o[kd]===e&&!o[Vi])return;let i;if(t==="message")i=function(c,d){let u=new Ji("message",{data:d?c:c.toString()});u[qr]=this,Lo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Yn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[qr]=this,Lo(e,this,u)};else if(t==="error")i=function(c){let d=new Hr("error",{error:c,message:c.message});d[qr]=this,Lo(e,this,d)};else if(t==="open")i=function(){let c=new Yt("open");c[qr]=this,Lo(e,this,c)};else return;i[Vi]=!!n[Vi],i[kd]=e,n.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[kd]===e&&!n[Vi]){this.removeListener(t,n);break}}};Yh.exports={CloseEvent:Yn,ErrorEvent:Hr,Event:Yt,EventTarget:ZE,MessageEvent:Ji};function Lo(t,e,n){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var No=oe((SR,Xh)=>{"use strict";var{tokenChars:Yi}=Ur();function Lt(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}function XE(t){let e=Object.create(null),n=Object.create(null),i=!1,o=!1,c=!1,d,u,f=-1,x=-1,g=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),d===void 0)if(g===-1&&Yi[x]===1)f===-1&&(f=w);else if(w!==0&&(x===32||x===9))g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let y=t.slice(f,g);x===44?(Lt(e,y,n),n=Object.create(null)):d=y,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(g===-1&&Yi[x]===1)f===-1&&(f=w);else if(x===32||x===9)g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w),Lt(n,t.slice(f,g),!0),x===44&&(Lt(e,d,n),n=Object.create(null),d=void 0),f=g=-1}else if(x===61&&f!==-1&&g===-1)u=t.slice(f,w),f=g=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Yi[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);f===-1?f=w:i||(i=!0),o=!1}else if(c)if(Yi[x]===1)f===-1&&(f=w);else if(x===34&&f!==-1)c=!1,g=w;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(x===34&&t.charCodeAt(w-1)===61)c=!0;else if(g===-1&&Yi[x]===1)f===-1&&(f=w);else if(f!==-1&&(x===32||x===9))g===-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let y=t.slice(f,g);i&&(y=y.replace(/\\/g,""),i=!1),Lt(n,u,y),x===44&&(Lt(e,d,n),n=Object.create(null),d=void 0),u=void 0,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(f===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=w);let S=t.slice(f,g);return d===void 0?Lt(e,S,n):(u===void 0?Lt(n,S,!0):i?Lt(n,u,S.replace(/\\/g,"")):Lt(n,u,S),Lt(e,d,n)),e}function QE(t){return Object.keys(t).map(e=>{let n=t[e];return Array.isArray(n)||(n=[n]),n.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Xh.exports={format:QE,parse:XE}});var zo=oe((kR,lx)=>{"use strict";var ev=le("events"),tv=le("https"),nv=le("http"),tx=le("net"),rv=le("tls"),{randomBytes:iv,createHash:sv}=le("crypto"),{Duplex:IR,Readable:AR}=le("stream"),{URL:Td}=le("url"),Tn=zr(),ov=vd(),av=Ad(),{isBlob:cv}=Ur(),{BINARY_TYPES:Qh,CLOSE_TIMEOUT:dv,EMPTY_BUFFER:Mo,GUID:lv,kForOnEventAttribute:Cd,kListener:uv,kStatusCode:fv,kWebSocket:Ge,NOOP:nx}=Vt(),{EventTarget:{addEventListener:hv,removeEventListener:xv}}=Zh(),{format:pv,parse:gv}=No(),{toBuffer:mv}=Ki(),rx=Symbol("kAborted"),Rd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],wv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,me=class t extends ev{constructor(e,n,i){super(),this._binaryType=Qh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Mo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,n===void 0?n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(i=n,n=[]):n=[n]),ix(this,e,n,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Qh.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,n,i){let o=new ov({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 av(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",bv),o.on("drain",Ev),o.on("error",vv),o.on("message",Sv),o.on("ping",Iv),o.on("pong",Av),c.onerror=kv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",ax),e.on("data",Fo),e.on("end",cx),e.on("error",dx),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,n){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,n,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),ox(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||Mo,n,i)}pong(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.pong(e||Mo,n,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(i=n,n={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[Tn.extensionName]||(o.compress=!1),this._sender.send(e||Mo,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(me,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(me.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(me,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(me.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(me,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(me.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(me,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(me.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(me.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(me.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Cd])return e[uv];return null},set(e){for(let n of this.listeners(t))if(n[Cd]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Cd]:!0})}})});me.prototype.addEventListener=hv;me.prototype.removeEventListener=xv;lx.exports=me;function ix(t,e,n,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:dv,protocolVersion:Rd[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,!Rd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Rd.join(", ")})`);let c;if(e instanceof Td)c=e;else try{c=new Td(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",f;if(c.protocol!=="ws:"&&!d&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;Bo(t,I);return}let x=d?443:80,g=iv(16).toString("base64"),w=d?tv.request:nv.request,S=new Set,y;if(o.createConnection=o.createConnection||(d?yv:_v),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Tn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=pv({[Tn.extensionName]:y.offer()})),n.length){for(let I of n){if(typeof I!="string"||!wv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(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",()=>{st(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[rx]||(v=t._req=null,Bo(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){st(t,v,"Maximum redirects exceeded");return}v.abort();let P;try{P=new Td(A,e)}catch{let C=new SyntaxError(`Invalid URL: ${A}`);Bo(t,C);return}ix(t,P,n,i)}else t.emit("unexpected-response",v,I)||st(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,T)=>{if(t.emit("upgrade",I),t.readyState!==me.CONNECTING)return;v=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){st(t,A,"Invalid Upgrade header");return}let b=sv("sha1").update(g+lv).digest("base64");if(I.headers["sec-websocket-accept"]!==b){st(t,A,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],D;if(C!==void 0?S.size?S.has(C)||(D="Server sent an invalid subprotocol"):D="Server sent a subprotocol but none was requested":S.size&&(D="Server sent no subprotocol"),D){st(t,A,D);return}C&&(t._protocol=C);let B=I.headers["sec-websocket-extensions"];if(B!==void 0){if(!y){st(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=gv(B)}catch{st(t,A,"Invalid Sec-WebSocket-Extensions header");return}let J=Object.keys(M);if(J.length!==1||J[0]!==Tn.extensionName){st(t,A,"Server indicated an extension that was not requested");return}try{y.accept(M[Tn.extensionName])}catch{st(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Tn.extensionName]=y}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 Bo(t,e){t._readyState=me.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function _v(t){return t.path=t.socketPath,tx.connect(t)}function yv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=tx.isIP(t.host)?"":t.host),rv.connect(t)}function st(t,e,n){t._readyState=me.CLOSING;let i=new Error(n);Error.captureStackTrace(i,st),e.setHeader?(e[rx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Bo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pd(t,e,n){if(e){let i=cv(e)?e.size:mv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(n){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(n,i)}}function bv(t,e){let n=this[Ge];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[Ge]!==void 0&&(n._socket.removeListener("data",Fo),process.nextTick(sx,n._socket),t===1005?n.close():n.close(t,e))}function Ev(){let t=this[Ge];t.isPaused||t._socket.resume()}function vv(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",Fo),process.nextTick(sx,e._socket),e.close(t[fv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function ex(){this[Ge].emitClose()}function Sv(t,e){this[Ge].emit("message",t,e)}function Iv(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,nx),e.emit("ping",t)}function Av(t){this[Ge].emit("pong",t)}function sx(t){t.resume()}function kv(t){let e=this[Ge];e.readyState!==me.CLOSED&&(e.readyState===me.OPEN&&(e._readyState=me.CLOSING,ox(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function ox(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function ax(){let t=this[Ge];if(this.removeListener("close",ax),this.removeListener("data",Fo),this.removeListener("end",cx),t._readyState=me.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",ex),t._receiver.on("finish",ex))}function Fo(t){this[Ge]._receiver.write(t)||this.pause()}function cx(){let t=this[Ge];t._readyState=me.CLOSING,t._receiver.end(),this.end()}function dx(){let t=this[Ge];this.removeListener("error",dx),this.on("error",nx),t&&(t._readyState=me.CLOSING,this.destroy())}});var xx=oe((CR,hx)=>{"use strict";var TR=zo(),{Duplex:Tv}=le("stream");function ux(t){t.emit("close")}function Cv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function fx(t){this.removeListener("error",fx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Rv(t,e){let n=!0,i=new Tv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(n=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(ux,i);return}let d=!1;t.once("error",function(f){d=!0,c(f)}),t.once("close",function(){d||c(o),process.nextTick(ux,i)}),n&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",Cv),i.on("error",fx),i}hx.exports=Rv});var Dd=oe((RR,px)=>{"use strict";var{tokenChars:Pv}=Ur();function Dv(t){let e=new Set,n=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&Pv[d]===1)n===-1&&(n=o);else if(o!==0&&(d===32||d===9))i===-1&&n!==-1&&(i=o);else if(d===44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(n,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),n=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(n===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(n,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}px.exports={parse:Dv}});var vx=oe((DR,Ex)=>{"use strict";var Ov=le("events"),Uo=le("http"),{Duplex:PR}=le("stream"),{createHash:Lv}=le("crypto"),gx=No(),Zn=zr(),Nv=Dd(),Mv=zo(),{CLOSE_TIMEOUT:Bv,GUID:Fv,kWebSocket:zv}=Vt(),Uv=/^[+/0-9A-Za-z]{22}==$/,mx=0,_x=1,bx=2,Od=class extends Ov{constructor(e,n){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Bv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Mv,...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=Uo.createServer((i,o)=>{let c=Uo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,n)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=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=mx}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===bx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Zi,this);return}if(e&&this.once("close",e),this._state!==_x)if(this._state=_x,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(Zi,this):process.nextTick(Zi,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{Zi(this)})}}shouldHandle(e){if(this.options.path){let n=e.url.indexOf("?");if((n!==-1?e.url.slice(0,n):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,n,i,o){n.on("error",yx);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Xn(this,e,n,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){Xn(this,e,n,400,"Invalid Upgrade header");return}if(c===void 0||!Uv.test(c)){Xn(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Xn(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Xi(n,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=Nv.parse(f)}catch{Xn(this,e,n,400,"Invalid Sec-WebSocket-Protocol header");return}let g=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&g!==void 0){let S=new Zn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=gx.parse(g);y[Zn.extensionName]&&(S.accept(y[Zn.extensionName]),w[Zn.extensionName]=S)}catch{Xn(this,e,n,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(y,v,I,A)=>{if(!y)return Xi(n,v||401,I,A);this.completeUpgrade(w,c,x,e,n,i,o)});return}if(!this.options.verifyClient(S))return Xi(n,401)}this.completeUpgrade(w,c,x,e,n,i,o)}completeUpgrade(e,n,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[zv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>mx)return Xi(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Lv("sha1").update(n+Fv).digest("base64")}`],g=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(x.push(`Sec-WebSocket-Protocol: ${w}`),g._protocol=w)}if(e[Zn.extensionName]){let w=e[Zn.extensionName].params,S=gx.format({[Zn.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${S}`),g._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),c.removeListener("error",
|
|
16
|
+
`)),c.removeListener("error",yx),g.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(g),g.on("close",()=>{this.clients.delete(g),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Zi,this)})),u(g,o)}};Ex.exports=Od;function Gv(t,e){for(let n of Object.keys(e))t.on(n,e[n]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function Zi(t){t._state=bx,t.emit("close")}function yx(){this.destroy()}function Xi(t,e,n,i){n=n||Uo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Uo.STATUS_CODES[e]}\r
|
|
17
17
|
`+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
|
|
18
18
|
`)+`\r
|
|
19
19
|
\r
|
|
20
|
-
`+n)}function Xn(t,e,n,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Xn),t.emit("wsClientError",l,n,e)}else Xi(n,i,o,c)}});var Nx=ae(Me=>{"use strict";var G=F;(function(t,e){let n=F,i=t();for(;;)try{if(parseInt(n(490))/1*(-parseInt(n(1355))/2)+-parseInt(n(1107))/3+parseInt(n(1598))/4*(-parseInt(n(1193))/5)+-parseInt(n(1726))/6+parseInt(n(1737))/7+parseInt(n(518))/8*(-parseInt(n(977))/9)+-parseInt(n(1850))/10*(-parseInt(n(567))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Vo,446675);var Vv=Object.defineProperty,Zv=Object.getOwnPropertyNames,Cx=(t,e)=>function(){return t&&(e=(0,t[{dfjFp:function(c,l){return c(l)}}[F(1253)](Zv,t)[0]])(t=0)),e},Jv=(t,e)=>{for(var n in e)Vv(t,n,{get:e[n],enumerable:!0})};function F(t,e){t=t-479;let n=Vo(),i=n[t];if(F.wAPQQk===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",w="";for(let S=0,_,v,I=0;v=h.charAt(I++);~v&&(_=S%4?_*64+v:v,S++%4)?m+=String.fromCharCode(255&_>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,_=m.length;S<_;S++)w+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};F.ieqiMJ=o,F.uOxGSW={},F.wAPQQk=!0}let c=n[0],l=t+c,u=F.uOxGSW[l];return u?i=u:(i=F.ieqiMJ(i),F.uOxGSW[l]=i),i}function Yv(){return Ix||(Ix=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Xv(){let t=F;return Ax||(Ax=[IDBCursor[t(1800)+"e"][t(1854)],IDBCursor[t(1800)+"e"][t(1657)],IDBCursor[t(1800)+"e"]["continue"+t(1038)+"ey"]])}function Qv(t){let e=F,n={UBZoU:function(o,c){return o(c)},SebSy:function(o){return o()},gYzCF:function(o,c){return o!==c},iVpWb:e(1380),RKoNX:function(o){return o()},rfgbt:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={YnMpk:function(w,S){return n[F(578)](w,S)},isOUV:n[l(817)],JlBwb:function(w){return n.RKoNX(w)}},h=()=>{let w=l;t[w(715)+w(1625)+"ner"](w(1922),x),t[w(715)+"entListe"+w(1420)](w(1069),m)},x=()=>{let w=l;o(n[w(1365)](Bt,t[w(1842)])),n[w(1452)](h)},m=()=>{let w=l;u[w(1479)](u[w(1391)],u[w(1391)])?(this[w(1702)]&&this[w(1702)][w(1633)](_0x16bc3c),this[w(1472)+"Queue"][_0x327ac0]=null):(c(t[w(1069)]),u.JlBwb(h))};t.addEventListener("success",x),t[l(1205)+"Listener"]("error",m)});return i.then(o=>{let c=e;n[c(1379)](o,IDBCursor)&&Nl[c(962)](o,t)})[e(1605)](()=>{}),Ko.set(i,t),i}function eS(t){let e=F,n={ACdcI:function(o){return o()},kZfQn:function(o){return o()},pmrJQ:"complete",POClb:e(1070),EyiAm:function(o){return o()},OrWbn:e(1069)};if(Wo.has(t))return;let i=new Promise((o,c)=>{let l=e,u={wYvVt:n[l(839)],rHyOW:l(1069),yqsLB:n[l(1378)],gjhhH:function(w){return n[l(1098)](w)}},h=()=>{let w=l;t[w(715)+w(1625)+w(1420)](u.wYvVt,x),t[w(715)+w(1625)+w(1420)](u[w(907)],m),t[w(715)+w(1625)+w(1420)](u[w(1569)],m)},x=()=>{n[l(1916)](o),n.kZfQn(h)},m=()=>{let w=l;c(t.error||new DOMException(w(1154)+"or",w(1154)+"or")),u[w(1808)](h)};t[l(1205)+"Listener"]("complete",x),t[l(1205)+l(1462)](n[l(1544)],m),t[l(1205)+l(1462)](n[l(1378)],m)});Wo[e(962)](t,i)}function tS(t){$o=t($o)}function nS(t){let e=F,n={cuZyI:function(i,o){return i(o)},QauqE:function(i,o){return i(o)},jeRGw:e(957),oLATR:"sCjRa",jtCCf:function(i,o){return i(o)},mXzbA:function(i,o){return i in o},aqfAX:e(1414)+e(1765),pQsrH:e(1528),ESRQB:function(i){return i()}};if(t===IDBDatabase[e(1800)+"e"]["transact"+e(1836)]&&!n.mXzbA(n[e(1724)],IDBTransaction.prototype))if(n[e(752)]==="UrBhQ")try{this[e(1702)]&&this._ws[e(793)](_0x44eabf,_0x57525d)}catch{}else return function(i,...o){let c=e,l=t[c(596)](n[c(498)](Qi,this),i,...o);return Ll[c(962)](l,i.sort?i[c(661)]():[i]),n[c(750)](Bt,l)};return n[e(1644)](Xv)[e(1486)](t)?function(...i){return t.apply(Qi(this),i),Bt(Nl.get(this))}:function(...i){let o=e;return n[o(1549)]!==n.oLATR?n[o(750)](Bt,t[o(1058)](n.jtCCf(Qi,this),i)):this[o(1937)][o(1554)]()}}function rS(t){let e=F,n={xFVry:e(778),vqUpn:function(i,o){return i(o)},ltmqK:function(i,o){return i instanceof o},HdXKi:function(i){return i()}};return typeof t===n[e(1397)]?n[e(1260)](nS,t):(n.ltmqK(t,IDBTransaction)&&n.vqUpn(eS,t),Px(t,n[e(1261)](Yv))?new Proxy(t,$o):t)}function Bt(t){let e=F,n={BYQds:function(o,c){return o instanceof c},hZSJy:function(o,c){return o(c)}};if(n[e(1371)](t,IDBRequest))return n.hZSJy(Qv,t);if(Ho[e(1890)](t))return Ho[e(835)](t);let i=rS(t);return i!==t&&(Ho[e(962)](t,i),Ko[e(962)](i,t)),i}var Px,Ix,Ax,Nl,Wo,Ll,Ho,Ko,$o,Qi,Tx=Cx({"node_modules/idb/build/wrap-idb-value.js"(){let t=F,e={lEjZy:function(n,i){return n instanceof i},yJjvD:function(n,i){return n!==i},TPFvB:t(792),lKJbx:t(1543),JmxZo:function(n,i){return n===i},ULvEi:t(1414)+t(1765),EsebK:function(n,i){return n===i},VIOCA:"store",GuVXf:function(n,i){return n(i)},PxGZs:function(n,i){return n===i},uRTma:function(n,i){return n in i}};Px=(n,i)=>i[t(959)](o=>n instanceof o),Nl=new WeakMap,Wo=new WeakMap,Ll=new WeakMap,Ho=new WeakMap,Ko=new WeakMap,$o={get(n,i,o){let c=t;if(e[c(544)](n,IDBTransaction))if(e[c(719)](e[c(663)],c(1536))){if(i===e[c(1823)])return Wo.get(n);if(e[c(1867)](i,e[c(1715)]))return n[c(1414)+c(1765)]||Ll[c(835)](n);if(e[c(789)](i,e[c(1350)]))return o["objectSt"+c(1765)][1]?void 0:o["objectSt"+c(1856)](o[c(1414)+c(1765)][0])}else this[c(948)+c(1508)]();return e[c(487)](Bt,n[i])},set(n,i,o){return n[i]=o,!0},has(n,i){let o=t;return e[o(544)](n,IDBTransaction)&&(e[o(789)](i,e.lKJbx)||e.PxGZs(i,e.VIOCA))?!0:e[o(1729)](i,n)}},Qi=n=>Ko[t(835)](n)}}),Dx={};function Vo(){let t=["s2XMBue","qvDQuLq","wevuBeq","s1DQteu","vwjoyxG","u2vXsuq","B25TzxnZywC","Dez6vwi","C2fdvhe","quHLC2e","vMrjv3e","zg9Uzq","t3jxyM4","x2LZtwLUAvC","ihn1y2nLC3m","AhHIv3G","BMv4DcGPigm","AMvsr3C","aaaaaaaaaaa","B3v0sw50zxi","rwXqtMK","FdeXFdD8mhW","y2XLyxi","BhrPCgXLihq","Aw5L","u1nIrMG","D2zrEwe","yNLL","BwHOwNe","BMLzz1q","y3jLyxrLt3a","Ce5HD1G","DMHyB0K","Cw9NDeq","C2vYDMvYvgK","vwTht28","vvvrv0O","ExfZtei","B2zMBgLUzq","zgfSDgG","x29Uq2XVC2u","Cgf5Bg9Hzeu","x3nLBMrby2S","B25VCgvU","x3bHDgHlzxK","r2n6ANO","rKDou2C","yw1L","BhjcBNy","CMvUDevUzha","y3jLyxrLrxi","C3jJ","tuLJzNe","CLv2vwG","D0H5Eu0","BMCGDxjSoIa","DgfIyxnL","B3nLrxzLBNq","ve1iCNq","mNW1","z3P3C2q","A0fmDu8","x2HHBMrSzva","y3jLyxrLt2i","svDpB0m","DgLTzw91DcW","nJiXmdyWuMjPA2Dr","s3vTANC","C3bSAxq","s3jAAvy","t1bftL9fuLi","Ehjyz3K","Bvznvvm","y2f0y2G","DK1AA3O","BgLUzq","DhDcrNK","CKznrK0","wLfRwLi","zxjFDhrS","x2rLyNvN","ug5JExK","wvr2tuq","whz6y04","wfnfy3i","C01pDwu","DMv2rey","vu9ZyMC","D3jPDgvvAw4","Exn3rwu","r25duuS","vuf3Axa","Ag5pqum","zw50tgLZDgu","y29UBMvJDeu","z2vY","werJtLu","x3bPBMC","uhLxrMm","Dw5ZAwDUzwq","A1bowKS","C2vUza","ywX3yxLZ","uM9iww0","Aw9UvgLTzw8","ugztqvu","v2LUzg93","rgvKAwnHDgu","yNL0zxm","ExL6y04","yvjwD0q","wuzlzKO","rvnsuui","x2LZsw5PDa","AM1kBKS","te9TDu0","r3LjAuC","zfPty2i","yxrLq291BNq","zgvSzxrLrge","EvPmB0O","CMfNzvn5BMm","zxjFCw9Zx2e","pxv0zI04","v2vPEgLUsLm","y29UDgLUDwu","rLjprK4","vu5SEeO","yxv0B21HDgK","AgzUz3G","DhjPzxmGCMu","CMvcBNu","yKTPBgW","Ee9UEe8","D3jPDgu","B1LNtha","wKzlv1q","zfPowKu","AfPUtMS","zMLSzw5HBwu","B2DqBwy","BNrLCG","y29UBMvJDa","AvrcvKe","Aw50zwDLCIa","zeXpvui","ihjLy29UBMu","BM5Ly3q","z2v0q3vYCMu","CM92AwrLigi","Agf1CeG","x2nSzwfYugK","sxLgvMy","C3rLBMvYCW","tK5mt0K","yMLUyxj5","shDMwwG","EwDste4","tujKyxq","Eu1erfG","uMvOsxm","vff0vxq","seT6ENe","vu1Xuwy","r2zoANK","yM9KEq","B25JBg9Zzq","vLzQB0y","yxKSig5LDhC","zw5HyMXLvhi","x3DZ","CLzHBhvLCW","zw9Uv3i","t3bLBKv2zw4","qu1SEhC","Dhj1y3rVCIa","EwPlr0G","ALjcC3O","x2LZqNjVD3m","uhbiwwq","CvPlq0i","zxf1ywXZ","tg1lBg0","vuX2rwK","Bhvcqxu","tKz1DNC","BhDWqwO","zLDHCMO","BKryCwW","B25LCNjVCG","qMfrwxy","D0nQCem","yxfMqvG","ENztCuq","mZuWndK0ognyzvbXAG","z3LQCgW","Dw50","DvjuBwe","tKPLrMy","qKf6wve","EgjPELy","t0H5zLC","x2LUAxq","y2z6zxu","DxbxtNm","mtG3otG5owD5Ehv4rG","tunUBKu","wLjiufm","z0nTC2G","ihrPBwvVDxq","zeDJEuW","zxzMsfO","DMvYC2LVBG","ALbAv1e","zw5fqMS","CNnVCL92ywW","sgjoALu","BMrWB2LUDfq","rM9vBwm","v09hufa","Aw5PDcbrB1m","ueLlEva","zwrPyxrLBhK","BuHTDfy","tg9xr24","CMvHzfvjBNq","quXm","CNH0t20","CufvsgS","CejKBfG","CMvZB2X2zq","u3b4Buq","rxfurei","B3jLtMfTzxm","zw5JB2rPBMC","Dgv4Dc9Qyxy","CMvHzg9UBhK","t0PHq3K","Dg9oDw1Izxi","Aw5KzxHpzG","A0jovgi","C09WEuu","rvvAsNi","DKPbquy","mxWZFdb8nhW","Cu15AK0","Ahr0Chm6","yMfSrxzLBNq","C3bSAwnL","wKruu0i","C3rVCMu","yxbWzw5Kq2G","EvjLy29UBMu","z05Zr2S","tfvby0m","C0Lfq0i","D2vI","Dg9cExrLC0i","nhWWFdj8m3W","x3nLCuLK","x2jPBMfYEvq","sufYAxy","C0XPC3rLBMu","yxjYyxLIDwy","rLjptLrjrvi","uK9uBeG","BhvzDLq","A2XIuhu","ChjVDg90Exa","CNzHBfzHBhu","whzHv3e","rxzLBNq","rLP0Dfq","A2v0ignVBNm","DKftrwS","yNvbzNu","z2POAeG","r1PVBwq","qMnZDwW","tfHxu2y","CNPZvg8","x2HHBMrSzvi","qLH1we0","EKv2CeS","wLboqvy","AenSB3nLrxy","t1nusu8","AePXCuS","ihrPBwvZ","mdaWma","zLHMsxi","BeTkyNG","BKXPBMu","wNvXzuW","yw9Nufi","r2fQExC","C3vcwve","rKzftwK","ihzHBgLKihm","zv9ZDwnJzxm","AezzsLO","x19LC01Vzhu","DcbSAw1PDa","BMXysee","Aw9U","Cvnfuvu","CMv0CNLdB3u","y09JALu","tg9Nsuq","AKvTDuC","CMvZDwX0","A05gq0S","zxmGCMvHy2G","Cw9Zx18","u0fmAgG","y3DNtLq","zxzVCge","CMTLCKDSB2i","mJaYodi1nZbNrLvbDxq","vKXKs1O","rMrUy2q","zxjFCw9Z","ywr2yw5Jzq","qMTOvfu","B3jL","C1r5txq","wvHXqxy","uurhD0y","DgvmB2Djre4","AwXK","y3PTuee","wejSteS","C2fNzq","AeLrDfq","su5cEMu","sM14wM8","BeLbBKC","tNLrBNG","q3nAt20","yNL0zu9MzNm","CMvZzxruCMK","qKf4ENK","D2jnC3q","swfwBxm","Efrurw52","zuLyuK0","Dg9hzw5LCMe","sLDswu4","vvzICui","BfLWDLi","B2HoA0C","DgLLCKPtt04","AMjprLe","sMXqAxq","v0H2quW","yxKSihrYEsa","zw5fDMvUDa","vM12Che","AgfZ","q291BNq","ywXty29Wzq","A3v0vxO","sMDsufu","D1buwMS","Dg9tDhjPBMC","shnhs3G","igzHAwWSig0","DxrVuMvJB24","BwXgzhu","sMXOyKO","rezyCfm","t3niruO","CwHxrLC","B2rIz3e","CfvoEhy","CgfHD00","A0nIr3C","mxW0Fdn8mhW","zgLZCgf0y2G","Bwf4tg9ZC0m","wejPrMq","y3vYC29YlNm","DMPUyNi","rvnwthq","qunKy0K","vuXpu1C","vwTJEwq","B2nRzxrtDwm","CMvZzxrdB3u","txPjDeG","C3vJy2vZCW","DvHWt0i","yMrFzgLK","B3jRig9MzMW","s0DmyLG","D3PsDfa","tevouLi","ALLLEhi","y2uGBM90igK","CMvWBgfJzui","ywnOzwq","t3Dnu3m","qvrPzwq","BvbIwuS","AgfUz2u","x3fVC0rc","yKT0CfO","x2DLBMvYyxq","v2jTB2e","CKP5u0W","x21PBMLoyxy","C1zKvvO","wLnzCNu","z1Dtrfi","DxjS","wKjst3e","DxrMofDYAxq","rvjst1i","y2HnyxHuCMK","ChPsy3y","rwHYyxu","Efzozw8","uKvQv1a","ENjoDvq","Dgv4Dc9WBge","vLj3Dgm","Cxjbtvq","x2LZtM9Kzq","sxrSu0e","r3vwwgy","zsbHihn0CMK","Cvzwr28","mtCYodvuAujnz3e","uMvJB25Uzwm","Cu5YCgS","EujdEg4","y2HLy2TdDxi","B2nRzxrgywK","zgvIDwC","BuHWu2u","y3vAEuK","x29UrxjYB3i","BMrLEa","Bwf4uMv0CMK","DKvPAfO","AxnbCNjHEq","C2vUDa","BMDLza","sgvxtKK","s3Hct1G","D0DouvC","ywfbyu8","zLnIu3i","zxrxB3jRq2G","CLPqtvy","rMPrEfu","zwD3yuu","tuXuEhO","CuXRC2u","zfnpDfq","ndHws1znthG","BwLUAvbYB2C","tMTfDfe","BfHutuO","CMvWBgfJzq","q3vZDg9Tq2W","tg9NsurozxC","rKrcv3K","ChfXz2S","yxbWBgLJyxq","zNjVBuHHC2G","vgDqsxm","zMP6Cu8","ve1fuhq","Exbwv3e","q2fZrhK","uLjpuG","zgvMAw5Luhi","wwfmseW","Bwv0Ag9K","z2vtEw5J","vwfcBxq","tKzysvC","x2nYzwf0zvm","D24GCMvHC28","Dxrjza","BevQwNK","yM1Oywe","z2vjBMzVu3K","ze1nr0K","y0jrugq","zfneEwS","C0jvtgG","vNHoAfO","zNjVBujPDhm","t2jQzwn0","yNDOt1a","Aw47y2HHCNm","CgLUz09Uy2u","DePdCue","BxnNsuq","EeHrAgu","v2vIu29JA2u","thDqtNq","z2v0qwXSs2u","y2vZC0HHBMq","BwLUzW","zMzAB3u","B2v4ufa","mtftvgjcsum","q09otKvdveK","CgfNzwHPzgu","D2j5Evy","AxvpsuC","ywDLsgLKzq","BgvY","CvL1rMm","twvZC2fNzuu","m3W0Fdb8mxW","zevfu2m","z1L6q0y","z2v0u3rVCMe","ChrJzfa","qMrXs2C","vfHACMC","x2nSzwfYvgK","B2zM","u0nSCKi","Ec1TC2CTCw8","B25SAw5L","suvtx0vsuK8","AgLSywe","qvnzEKW","yLvRsee","y2XVC2uSihC","tuHvv2y","A2v5CW","vKvUyxi","y2fSBa","zxj2AwnL","AMjmAwC","zNjVBNrPzxi","txv6z0m","u2vYDMLJzvC","ug9et2G","uvLQAwK","wK5ADLe","CgDSwvG","vejuzvi","DwfxExa","rvbMqvy","B2nRzxq","CYbPBNn0yw4","C2v0sxrLBq","q29Kzq","CNzHBa","su5tvefova","AwDHDg9Yt24","qMXyDuO","uLrcELi","su1Ovvu","Cu5JwNi","AKDVD1y","sMjiAhG","CgXLyxnLiha","x3nVy2TLDa","Cgf5Bg9Hza","vujIC0W","vgrtExi","BNzcrfm","y3jLyxrLtwu","AgvHzgvY","Dg9cExrLC0W","zNDZxZeUmc4","y3b0Cwi","q09oveLovuu","wNPzr1C","shHuzLe","uLzYq2y","ihrVihjLDhi","CgjICdi","C3rYAw5N","CMvQzwn0","BgLTAxq","z2u6ia","yMLUza","BeHRuNm","BezSDxnO","rwjtD1i","ALjgtLe","yw1LoIa","D1Pftuq","CLnLANy","ELj1q1e","yw5Nzq","uKnTBeS","CMvZzxrfBMq","yw5ZzM9YBvq","zw5NDgG","DeLK","ugXNr1K","q0Xpu0ve","x29Ut3bLBG","C29YDa","yw1Lu3bHy2u","vfbgDKi","vfz1DM0","sgPtu1K","y1nNqwO","DgD5uhi","u0P6EMe","C3DnDhy","zgLZywjSzue","thbIyxi","C3v3vLa","ugz4B2O","A0PuwfK","zw50","vgLqy0u","BvbACKO","v3nnCM8","rgTxwNO","EfvWwvq","mxW0","BMCGB3iGyw4","q0fXzLO","s2nOu1O","q1jqvgG","BvHgwLe","q3vZDg9Trxi","qKvwu1a","B0HeEue","C2v0zgi","qM5Htfa","BxDSCMW","vgLlsvi","tKfusvzfx0u","CMfTugfYyw0","q2vktxi","y29UDgv4Da","DMTzy2e","BNHOrw0","twPtuuy","C1HUDgm","zef3Cu0","BvvLwvK","BwfW","wLfbu1G","wxjHuhK","t3vZuw8","vLDADKi","tLDbz0S","t0n2D08","Bvvmq2K","CLDrr0m","BgvUz3rO","s01JvNG","CMvTB3zLrxy","zu9SAfu","Aw5KzxGGB3u","ExLlyLi","EuPQDKq","quPYufK","tufyx1jfvfi","C2Doqxi","Avj3Dvi","u0viyNO","B3bLBIa","sg9AsLO","BMvxzxC","ugP1sg8","refHq3G","u0TqzvO","z2v0sxrLBq","D3m6lY8","vKPct1q","qMrSvue","z1rPBwvVDxq","jMPZy2fSBgi","ywnRx2LK","uMfRrw0","C2X5uLi","A1H3DwO","z2XQqKO","EhPYA0G","zvzhCNy","vK5QqLK","AvHJr1u","zw1ADuC","A2v5","uhbODwu","uMvHzcbWyxm","uwf1Cuu","CMfUzg9T","CffZCKG","yM9L","thn5y1K","thnyq0W","lcbOB3n0BMe","Dg9cExrLCW","tMfTzq","AxnFywnR","B25tDg9Wsw0","x0rctMfTzq","C3rYAw5NAwy","DwXJruu","CNjVCK1LC3m","BuHTr1y","tgPkCeC","y3vYC29Y","rNjVBNrPzxi","qxrcsw4","yNvMzMvYzwq","ufj6uKO","svjLrLy","CgLUz19VBMm","BMCGzMfPBgu","A2TiBLm","Bwj4u2m","D2TUrvC","zNvUy3rPB24","AevYCM9Yrxy","v3DnBgy","q2Tbu0W","CNnVCL9Uyw0","ENzlAwW","CLHrsey","r0z2rhm","BgLZDgvUtMu","Du5JvKy","ExfNBLu","rxnLyKS","y29Kzq","uNDmyLi","t0L3r04","y2XVC2u","yxL6swG","De1HBMfNzxi","BML0AwfSAxO","CMvHzhDYAxq","AKDvqMS","s1DeDu8","DMvUDa","CK1otuK","DxPXCLK","BgLUzw5V","ywnRpwzYB24","zvz1C2C","wg5vDKq","rKLmrv9ot1q","t3LdDfm","x29UtwvZC2e","tKXZy1e","BwvZC2fNztO","yuPey2K","qvz6Eem","ChbL","ELLuuhq","DKfLzvq","AvzWv2i","zvHWz2O","zxHMwu4","C2HPzNq","y3vLz0m","qKjSq1G","BwnQrK0","nxWWFdj8m3W","CLvuBfG","C3nHz2vfDMu","vufXuM8","vNrQAuO","AgfZt3DUuhi","CM92AwrLihy","yxnL","Cgf5Bg9Hzfq","D2TdvgS","vwX2t3G","z2v0","ihzHBgLKigq","DMvY","x2DLDeLUDgu","Cg1YsLe","uwjtqLC","DMfSDwvZ","Ec1TC2CTy3u","t2vwruK","vhPsAfa","tMDtrMW","ENbrqLe","zNjVBuj5Dgu","CML4tuK","v0TNDvm","vvDyEhq","AwrI","zMLN","yxnZAwDU","BwvKAwf0zwW","A3nct3m","s1HcrK0","u3rYyxrLz3K","Bg9N","AMPrBuK","DvvNwwW","q1Dutvm","y3vYC29Yx24","x2rPC2nVBM4","z29PBMCGyxC","ywzL","ruHUrw4","C2v0y3vYC28","AgjrBNO","qKjPCwW","yw5Hz2vY","swrfEvq","thn2qKS","x2n1CNnVCK0","uLzfDvq","rvbiufi","twrNwMq","yw51Ce1LC3m","ENvzsg8","zufJAW","CfnvrfG","D1fKAxK","zgf0yq","Chv0","zNHQCxG","AhDzzLi","zw5KCg9PBNq","vfvwzNK","yLLsqxK","twLHuxG","su1bzwi","mNWZFdz8nW","tvzzCLq","AgvqCgy","Axr1wu8","q1fZrhy","r1HXBgy","tKDFrvjst1i","DhjPzxm","v01YCLi","CwDAA04","Dg9mB3DLCKm","B25fCNjVCG","B1jdtNG","sfzdBxC","AxmGDw5Kzwy","B25szwnLAxy","CKH5t1C","B25pCgvU","ChjVDg9JB2W","B2Trz3G","zMnYC2K","Eeflwwy","uKz0qu8","rM1oAM4","yvrAuMS","v2Xyu2G","BgDxDwe","v21kA3q","x2zVCM1HDeu","txzszeu","zv90Aw1LB3u","s050zNa","EsbJBg9Zzwq","AgLNAa","suHXrgS","s1nKDeW","rKDLtNm","Ae9Wzw5fDMu","AMLHA1a","t1bftG","u2HHCMvKv28","Ef9MCM9UDgK","CMvTB3zLq2G","rLDt","Bu9gDgy","tKH6zeC","y29UBMvJDfm","sfnOuKe","zgD0txC","x29WDgLVBNm","zw5JB2rLrNi","yMLUyxj5vhK","Dg9iyxnO","wNrktgK","x3jLywr5q2W","x3bPBMDqB24","lcbTyxGGCMu","zMX1C2HfEha","q2XYzg0","r3jMyvK","x0vysvnu","zM9Yy2u","C2v0q3vYC28","AfzfCe4","DhLWzq","wNnPtLi","yLPNzMu","sNrvA1e","C29Tzq","uK11De0","EhnWD1m","C2v0","CM5gwwC","yLzvww0","BeTPCgG","zMzLCG","AwXSihvZzsa","y2XLyxjtDg8","tKXjuvm","thLLyKW","vNbHtfy","BM93","zNjVBunOyxi","zMzmAw5L","whzLtey","C2fNq0q","ntm4mJyZvuHovg9n","t2nJtfm","twLZC2LUzYa","EuXfuMi","DMDkyu4","q3D3wwG","CuHYq2i","x2rYB3bhBg8","qu1rCMK","C3vIyxjYyxK","zu9VBhe","yMXVy2TLza","Aw5Lza","t1PWzg4","C2vYDMLJzq","rwrVBhO","zvnLB28","rvnltge","igXHCMDLCIa","y3ruAw1LB3u","yxGGCMv0CMK","vw5Oyw5KBgu","x3DZsw5ZDge","zgrMqMO","CgvYC2LZDgu","y2XVC2veqG","swn5A3y","ANnluNq","B3ncDKu","C0jf","y29SBM8","r1zxzKG","Aw1LCYbPBIa","rgHLDem","BMfTzq","B1PJq0K","uufdqxe","vhndAgq","Dev2zw50","CNLdtKC","Dgzlrxu","AgvHzgvYCW","qvzfuvq","rxjYB3jdB2q","x2LZv29YA2u","EfnRqKq","zhHKuue","C1P5uvC","uxfqAKS","DMfSDwu","CMLLC0nVDw4","uhvACue","DMvYC2LVBMm","DvPwrfC","tNrczxC","ELjLuxC","AgH1BNC","uKnPu0e","wffSswm","DvbnqMm","r1bjwgu","uhjPBwfYEuS","zMXVB3i","DwfWCw8","yuzNww8","tNrywva","DgvZDa","AhbHBey","Cg9PBNrbBMq","qw9Jv3u","EwLOrgu","rKnWDK4","v2TWA1m","yMfSu2nVCgu","zMLUza","Ae1LC3nHz2u","mdaWmdaWmda","BKXVt3G","icSG","DMn2EMO","DxbKyxrLq3u","yxbWBhK","zwnVBM5Ly3q","x2rLC3rYB3K","AxnrB1nnzxm","x25HDMLNyxq","tgnzANO","tLHLyMO","v2LiEge","CKTlBNy","Ae5ntuq","ywP1wey","zxjYB3i","ywjVCNq","r2PpD00","DxzcrKS","B25tDgfYDfi","C3rVCcbPBw0","x2n1CNnVCK4","wvvusgK","zxjFAxnFywm","rNzbuMS","BNruCMLLC0m","EuXJC1q","zfL6CNq","x3DHAxq","ywXS","BwLZzq","EKnuu1K","ywrK","Exrrwgm","ohW5Fdz8mxW","B1PVtMy","y0n4AMu","v2n1zMK","ywrKq291BNq","AefJA01LC3m","BhjlENK","tfzqsKS","yLfHsMS","DMLJzuLeig8","rxLPqw0","DgnXzLy","yLDpC2u","Ewfkt1m","rfPSrKG","qwT2Aum","y3vYC29Yx2y","vhbAvgi","Dg9Y","ota3mZKYrKzkwKHA","zMzMzG","sLnHseC","vK9rtg8","CuHntuS","EKHds0u","uwzQDxe","zNjHBwvuExa","Du9bsKm","z0Letxm","AMvJDfn0B3i","zKHTre4","swzVvem","tgDqBhG","BwvY","tNzoB3q","AMfWDNu","x3bYB3rVy28","sLnptLa","A1n0yxr1C0m","Bwu6ia","t0fcu1C","l3DZl3yY","zg5lvvi","yxv0BW","y09Wzw4","zLbfu2i","zMvY","s0DiEgK","CMvXDwLYzwq","CM92AwrLige","qNjPzgDL","DeLUDgvYy2u","C0TcB0y","uM9yEeW","D2HZsgC","Dw5KzwzPBMu","ywnRx2nVzgu","Dg9VigXHCMC","B2fK","s0jWs2W","q0zmq1K","x2LZtwLUAvq","vvncrgG","Ec11C2uT","CgfNzxnOB3C","y29Uy2f0","qwjVCNrfCNi","wuPSs3K","BMnVzgLUzW","nxWXFdb8nhW","BMv3vMvYC2K","wuvVyKW","zw5XDwv1zq","wMTSwuG","swPfEMe","re55B0i","sKH4Exu","rNjQqNe","u1vxqKm","CvbSuLi","y2vby1m","vw5PBxbSzw0","CfHiv2e","txjpt2q","t1jHugW","thfltgG","y2HnyxHdB3u","r0zurue","B2zMC2v0","rgr1qMO","ywnOzwqSihC","D3rdvMC","ign1CNnVCIa","wenTELu","BxrOBKm","DgHHBIbSB2m","tvPdwKK","z1vzqw8","DhjHBNnHy3q","rgXdyNq","zxnPvKC","vg9XwKK","Aw5N","ugr4z3e","Bxf2t2e","nu1ltgjiqq","t1bYDxa","DxnLCKLW","x3jLBw92zvC","z1zMCK4","zw5HyMXLuw8","yNL0zuXLBMC","tM1hD0S","Ae9SEKG","BMDuAw1LCG","yuHqwfa","BNrbBMrvCgq","ywrKrxzLBNq","uLf4BLK","DhjPBq","x1fVu01HBMe","rLvqwhG","zxjYtM8","EhzosNC","u2nyqu0","sefXrxC","x29UvgLTzw8","t3zRsuC","wxLOyLu","AfLOBKi","x3vYBa","AejUExC","zLLMqNC","AxnrB1nby2S","Dvz2ALC","BNvNuNa","BhLoDwW","wfvLt3y","y29UC3rYDwm","x2LUAxrqCM8","zw1PDa","BMnLq2XVC2u","ywDL","s3LeC0u","sgrTsuG","AxnmB25N","vxbKyxrLq28","C0vmCNa","y3vYCMvUDeK","r0nSsve","vgfN","qw1VDw50","AfLbrhK","y29UBMvJDgK","CuPLCMi","tgzqBfa","DKzzDuG","svzKteW","t1fvswW","ChrVCG","DhbizwfKzxi","zxjYtxnN","x2rItMfTzq","nxWY","Dgv4DfbHEwW","zgzQrNa","zvvYBa","Aff0u1K","CgfYC2u","C3vIC3rYAw4","vMD5suG","y0vfDKy","DNfvCg4","sgrys2K","DNblrM0","Du9Atxm","wgL3twK","ue1crLq","ELnNtuS","ANj4tMq","DLP6wve","C2XPy2u","thrgu2i","zxH0ugf5Bg8","DgfYz2v0","r2P6qKK","B3bLBKrc","rLjyC3a","ugnLEee","zfvmzwC","D2LSBfjLy28","u1nsCMW","tLntt2C","v0zuAKy","Ee5NCvC","x3bPBMDmB3m","CMvJB25Uzwm","ELfZwhC","t0ncqxu","qw5mD2O","DenTr3e","DMfS","y3vYCMvUDeu","tfLJAgO","B3bLBG","zxjHDg9Y","ysbTDxn0igi","DMzVDLa","y3jLyxrLq2W","CMvKDwnL","x2n1CNnVCKy","AwXLx25HBwu","tg91zhK","igzPzwXKoIa","yMfJA3vWigu","zxHWB3j0CW","B3jpBMXPBMu","AKDeD0y","zNjVBu51Bwi","uKr4qK4","zMLSDgvY","AgrQCwe","tMnJu0q","x3jLy29UBMu","Bg9IywXty28","CgLUz0XVC3m","wwzvCMO","zKP5zMG","ywDLu2HVDW","yLvnr3O","vKferKq","s2jNwM0","zfDVCMTLCKC","BLfRreC","B3fdqxC","ywXSq3vYC28","EK5erhi","z2v0qwXS","Cg9PBNrdB24","x2rPC3bHDgm","y29UBMvJDca","qMPXD2W","zw1LBNq","qvPSBKG","ze15Axm","vfHruvK","q2LpDum","Cw9Z","q2HbCM4","x2nVBM5Ly3q","BNrfBMrWB2K","Be1bDfe","zw50zwqGDhK","y2HLy2Tszwe","CNHrzKW","DM5MChO","CM92AwrLihC","zcbLCNjVCI4","vLjeAKm","tfbvqMu","s3PrtMS","qM1NwM0","vKLpq0e","z29ruxy","mhW0Fdf8mNW","CurquLK","CMfTzq","ntjZt3Dvs1i","C0nVDw50zxi","zM9YrwfJAa","uu1twKq","s3z6vMu","qwHYu1K","tg9JAW","q0rxvKK","tunWt1u","Cg9W","vujAB1u","yxrHlcbKyxq","ywnR","wM9tq3m","AwXLtMfTzq","tuvtu0fhrv8","qLLrzhm","vvP1y3e","zM9Ts2m","AwThEK0","vNPSC28","igfYCMf5yNu","zfffCwS","ue9dBgi","CMzNyNq","D2vrAeK","rhvZtw8","zLDpCgi","DfjHzeG","vgLTzw91Da","vNH2vhe","wufbA3u","ChvZAa","EeXVzhi","z3HABxK","zNbuzhi","Axnpvvy","CgLUz1rPBwu","rhLuAhO","zxH0zw5ZAw8","CMvJzwL2zwq","EMj6t1a","EezwCNK","rLDeuha","BfHuuu8","CMvHC29U","AwTezfy","wKzAu0q","vefiALu","yxHhAwO","ALrlC0W","ignVzgu6ia","sgP5Bhi","zK9KBva","y052zhu","Afrqu0K","z2v0q3vYC28","EvPbz20","r1bQzeK","B2jQzwn0u3q","u0nbrg4","vLDXCva","x2XPC3rLBMu","AM9PBG","z2v0s2v5","BMvY","quTqt1q","x29UugfNzu4","AgvKtwf4uMu","ihbYB3rVy28","B29oEMi","vK5czgy","zxq9DxrMltG","vuvewNK","B3nLza","z2X5uu0","ExbL","DMPuBMK","y291BNq","Bg9Nsurhzw4","q09PsMK","vLrOqKS","EKrIBxe","z3ngDvu","s2zkyKK","yxnJCMLWDa","swvoBMu","vujfrhG","AxnszwfKEq","zLDItNq","Dw5RBM93BIa","AMrjyxy","zwn0","x2HHBMrSzu8","AMr1rei","D0nJtMy","sNjuyMy","u2vIu3K","zgvS","vxbWs2q","CM9YrxzLBNq","Bhm6ia","B2LUDfjLywm","y2HHCKnVzgu","zLHjv3q","DKvwDKe","zNjdBwq","tgLZDgvUzxi","zuzcz0q","ENfRDxq","x2vUzhbVAw4","ExzQrxC","s1rzqLy","uxvLDwu","wu9jtwu","B3vUDa","EKzjyK8","x21LC3nHz2u","ANvAExi","Bg93","CNnVCKzPBgu","uwnjvM8","DgHLBG","DwTTC0i","ww5nCgS","ywDLrxzLBNq","CgLUz0LUDgu","yNvMzMvY","m3WWFdj8nhW","ywnRDxbfBMq","zKDmwum","Aw5JBhvKzxm","D0jnzMW","x2TLEvbHDgG","BeHHBMrSzxi","BxnN","zgvSzxrL","ywnRtxnNswq","Ae5KDwW","D3nZoI8V","AgrtCuO","sLbkzNi","CMvHzhLtDge","zu9euxa","BfrPBwvVDxq","qxj5zeO","BM9Uzv9UB24","BwvZC2fNzv8","vMDfEhi","C2v0u3rVCMe","Aw9Ul2PZB24","vgrQEMe","qvnfuwW","AxjLza","BwvZC2fNzq","q0Xpu0LorW","qwHHDvi","x2fKzfDZtgK","zgvJB2rLzey","B3bLCNr5","x2LUDgvYDMe","o2nOyxjZzxq","t1Dxwvq","vxLdwMO","BMnsqKq","AeHovfC","wujryuG","z2vrDwv1zuW","y3jLyxrLuMu","q21bsNa","x3bYzwzPEa","AMX3vwC","B25ozxr3B3i","D2Lnu1y","qwHwB2y","DwXotLi","Bg9rDLO"];return Vo=function(){return t},Vo()}Jv(Dx,{deleteDB:()=>sS,openDB:()=>iS,unwrap:()=>Qi,wrap:()=>Bt});function iS(t,e,{blocked:n,upgrade:i,blocking:o,terminated:c}={}){let l=F,u={Hjylr:function(m,w,S,_,v){return m(w,S,_,v)},YEgVH:function(m,w){return m(w)},hQtSY:l(793),wkCTk:l(1029)+l(1936),rJySL:function(m,w){return m(w)},mHmGV:"upgradeneeded",hFYJZ:l(988)},h=indexedDB[l(1292)](t,e),x=u[l(1941)](Bt,h);return i&&h.addEventListener(u[l(765)],m=>{let w=l;u[w(1407)](i,Bt(h.result),m.oldVersion,m[w(1158)+"on"],u.YEgVH(Bt,h[w(1186)+w(1836)]))}),n&&h["addEvent"+l(1462)](u[l(1832)],()=>n()),x.then(m=>{let w=l;c&&m["addEvent"+w(1462)](u[w(1255)],()=>c()),o&&m[w(1205)+w(1462)](u[w(833)],()=>o())}).catch(()=>{}),x}function sS(t,{blocked:e}={}){let n=F,i={nfxfm:"blocked",xrXgy:function(c,l){return c(l)}},o=indexedDB[n(1651)+n(1588)](t);return e&&o[n(1205)+n(1462)](i.nfxfm,()=>e()),i[n(1603)](Bt,o)[n(1477)](()=>{})}function kx(t,e){let n=F,i={zSgMK:"send_ack",AYwIg:function(h,x){return h!==x},QqPjK:n(726),VWZvB:"LkyrA",TsChd:n(797)+"e",qogtD:n(1768),jPZWQ:function(h,x){return h instanceof x},vJAAF:function(h,x){return h in x},vhXoI:function(h,x){return h===x},CasDy:n(639),LqKLh:n(607),qHrCb:function(h,x){return h!==x}};if(!(i[n(1745)](t,IDBDatabase)&&!i.vJAAF(e,t)&&i[n(1564)](typeof e,i[n(533)]))){if(i[n(1173)]===i[n(1173)])return;_0x40d597.d=(h,x)=>{let m=n;for(var w in x)_0x398524.o(x,w)&&!_0x37b7ab.o(h,w)&&_0x210ace[m(535)+m(1514)](h,w,{enumerable:!0,get:x[w]})}}if(jo.get(e))return jo[n(835)](e);let o=e[n(522)](/FromIndex$/,""),c=i[n(983)](e,o),l=Lx.includes(o);if(!i[n(1775)](o,(c?IDBIndex:IDBObjectStore).prototype)||!(l||Ox[n(1486)](o)))return;let u=async function(h,...x){let m=n;if(i.AYwIg(i[m(1025)],i[m(708)])){let w=this[m(1186)+m(1836)](h,l?i[m(1014)]:i[m(1565)]),S=w[m(1782)];return c&&(S=S.index(x[m(820)]())),(await Promise[m(1083)]([S[o](...x),l&&w.done]))[0]}else{let w=_0xa6b9e7(_0x19f5f5);this[m(1702)]&&this[m(1702)][m(1497)+"te"]===this[m(930)]&&(this[m(1702)]&&this[m(1702)][m(1633)](w),this[m(1612)](i[m(1266)],_0x21abf5))}};return jo.set(e,u),u}var Ox,Lx,jo,oS=Cx({"node_modules/idb/build/index.js"(){let t=F,e={NtXYP:function(n){return n()},UlvOx:t(835),iMqmC:t(1419),CeJMr:t(1325),yaJOS:t(562)+"ys",fpTdr:"count",ikDdV:"put",xHQhe:"add",xbizV:function(n,i){return n(i)}};e.NtXYP(Tx),e[t(1042)](Tx),Ox=[e[t(834)],e.iMqmC,e[t(696)],e[t(1101)],e[t(1390)]],Lx=[e[t(1401)],e[t(559)],"delete",t(1554)],jo=new Map,e[t(1732)](tS,n=>({...n,get:(i,o,c)=>kx(i,o)||n[t(835)](i,o,c),has:(i,o)=>!!kx(i,o)||n[t(1890)](i,o)}))}}),aS={idb:function(t){let e=F;t[e(1303)]=Promise[e(1762)]()[e(1477)](()=>(oS(),Dx)).then(function(n){return n})}},Rx={};function Mt(t){let e=F,n={meuWX:function(c,l){return c!==l}};var i=Rx[t];if(n.meuWX(void 0,i))return i[e(1303)];var o=Rx[t]={exports:{}};return aS[t](o,o[e(1303)],Mt),o[e(1303)]}Mt.d=(t,e)=>{let n=F;for(var i in e)Mt.o(e,i)&&!Mt.o(t,i)&&Object[n(535)+n(1514)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=F;Mt.o=(e,n)=>Object[t(1800)+"e"]["hasOwnPr"+t(1514)][t(596)](e,n)})(),(()=>{let t={Fdncd:function(e,n){return e!=n},sHkOu:"undefined",NJeFf:"Module",NStQR:"__esModule"};Mt.r=e=>{let n=F;t[n(1852)](t.sHkOu,typeof Symbol)&&Symbol["toString"+n(1238)]&&Object[n(535)+"operty"](e,Symbol[n(1896)+n(1238)],{value:t[n(1730)]}),Object[n(535)+n(1514)](e,t.NStQR,{value:!0})}})();var Ce={};(()=>{let t=F,e={nlXHA:function(a,r){return a(r)},UBbsL:function(a,r){return a+r},SSbFh:function(a,r){return a+r},kPNZK:function(a,r){return a|r},JbHhx:function(a,r){return a<<r},dMyis:function(a,r){return a|r},NWAgK:function(a,r){return a|r},fjzqO:function(a,r){return a!==r},avqeQ:"qQDvt",MvRdE:t(740),OPrup:function(a,r){return a+r},BoQra:function(a,r){return a*r},FKjjU:function(a,r){return a*r},REjWP:function(a,r){return a(r)},egwaE:function(a,r,s){return a(r,s)},QDGwF:function(a,r,s){return a(r,s)},DNyoB:t(1821),YbJuX:t(1108),GPIXe:function(a,r){return a(r)},zYTPt:function(a,r,s,d){return a(r,s,d)},lwpAj:function(a,r){return a>r},TVuvm:function(a,r){return a<r},YAAku:function(a,r){return a!==r},ToqZI:function(a,r){return a-r},UEDZy:"PyyRc",wtCVg:function(a,r){return a!==r},NgSFl:function(a,r){return a===r},EUZJr:t(1048),oZcCI:function(a,r){return a<r},Bjqwl:function(a,r){return a<r},OvkIG:function(a,r){return a===r},BAzYQ:function(a,r){return a===r},zDbmq:function(a,r){return a>>>r},MCnnE:function(a,r){return a|r},WOGPP:t(1022),MdgZd:function(a,r){return a!==r},uOZMs:function(a,r,s){return a(r,s)},sagCD:t(860),zpQBQ:t(1270),WsMro:function(a,r,s){return a(r,s)},CwwYh:function(a,r){return a(r)},odbgq:function(a,r,s){return a(r,s)},IeNne:function(a,r,s){return a(r,s)},BXuXM:function(a,r){return a(r)},wZEMD:function(a,r){return a&r},rSejv:function(a,r){return a===r},pglYX:"Missing "+t(1136)+t(1301)+t(747),cCxje:function(a,r){return a===r},JmROu:t(979)+t(1136)+t(1301)+t(1026),KcgYi:function(a){return a()},TzRhP:function(a,r){return a<<r},IMhUU:function(a,r){return a(r)},dxdQA:function(a,r){return a&r},eIXRM:function(a,r){return a!==r},KfJbI:function(a,r,s){return a(r,s)},YTvMD:function(a,r){return a!==r},exfYN:function(a,r,s){return a(r,s)},PfSAU:function(a,r,s){return a(r,s)},sgNAr:function(a,r){return a(r)},XiwMi:function(a,r){return a!==r},WkpkS:function(a,r){return a!==r},GfNjy:function(a){return a()},swMtv:function(a,r,s){return a(r,s)},BdqKg:function(a,r,s){return a(r,s)},nSKPT:function(a,r,s){return a(r,s)},luYvT:function(a,r){return a!==r},CAqfZ:function(a,r,s){return a(r,s)},upWNs:function(a,r,s){return a(r,s)},QvnUq:function(a,r,s){return a(r,s)},NSSOg:function(a,r,s){return a(r,s)},aDiZl:function(a,r){return a===r},YEobL:t(1846),RQxnY:t(1185),jTKsL:function(a,r,s){return a(r,s)},jbLig:function(a,r){return a(r)},XvzcN:function(a,r){return a(r)},SSRrl:function(a,r){return a>>>r},eVGrv:function(a,r,s){return a(r,s)},hOlzH:function(a,r,s){return a(r,s)},vASEk:function(a,r){return a(r)},FoUmc:function(a,r,s){return a(r,s)},GjzBI:function(a,r,s){return a(r,s)},hVEpN:function(a,r){return a(r)},MzItH:function(a,r,s){return a(r,s)},XnUvD:function(a,r){return a(r)},xySDE:function(a,r){return a(r)},AMlxw:function(a,r){return a(r)},AMQri:function(a,r,s){return a(r,s)},FGeNs:function(a,r){return a&r},GnCQK:"Missing "+t(1136)+t(1301)+t(1840),mlFdu:function(a,r){return a===r},bKtpZ:t(979)+"required field: "+t(537),bmhaa:"frVMv",FFEMi:function(a,r,s){return a(r,s)},UOsbg:function(a,r){return a(r)},JWFSE:function(a,r,s){return a(r,s)},dSDyk:t(1169)+t(1340)+"pe: ",xzrkH:function(a,r){return a>>r},Wbmoa:function(a,r){return a>=r},AWjRT:"timeout",RDxBN:t(903),mHpSe:function(a,r){return a===r},FRXsp:function(a,r){return a>r},sTyMt:function(a,r){return a+r},ywtuq:t(749)+t(1834),ZoSCs:function(a,r){return a+r},vEVvA:function(a,r,s){return a(r,s)},DFXpS:"HeMaB",chCMh:function(a,r,s){return a(r,s)},EPfAV:function(a,r){return a===r},AhrSY:function(a,r){return a&r},wCcNf:function(a,r){return a+r},HsGKx:function(a,r){return a+r},ZNZvQ:function(a,r){return a|r},tcqfV:function(a,r){return a<<r},CdGtn:function(a,r){return a&r},nApWj:function(a,r){return a==r},dZNZE:function(a,r){return a===r},EgLfz:t(1040),EHnEn:function(a,r){return a!==r},Mbfrn:function(a,r){return a&r},IdEyT:function(a,r){return a<<r},MVYrT:function(a,r){return a<r},juZyr:function(a,r){return a>=r},gyjpl:function(a,r){return a<=r},DSwFX:function(a,r){return a==r},ncRBD:function(a,r){return a&r},BnaLP:function(a,r){return a>=r},RFtAO:function(a,r){return a+r},bKill:function(a,r){return a+r},OCBAu:function(a,r){return a&r},buAfu:function(a,r){return a|r},hJqqK:function(a,r){return a<<r},aHPXP:function(a,r){return a|r},bWOse:function(a,r){return a<<r},YraPy:function(a,r){return a&r},yswEe:function(a,r){return a&r},zReQw:function(a,r,s){return a(r,s)},AHesa:function(a,r){return a>>r},QACAq:function(a,r){return a&r},KWDuO:function(a,r){return a-r},zqkut:"wmaUF",MLTxz:function(a,r){return a<=r},bwhOP:function(a,r){return a-r},DlCbt:function(a,r){return a+r},sBULh:function(a,r){return a<<r},JWRYN:function(a,r){return a<r},IMAeb:function(a,r,s){return a(r,s)},ZsiNR:function(a,r){return a>=r},EqTDB:function(a,r){return a<r},jdIav:function(a,r){return a|r},AkviC:function(a,r){return a>>r},JgRPU:function(a,r){return a|r},NFXIW:function(a,r){return a&r},COiJi:function(a,r){return a|r},sVdUZ:function(a,r){return a+r},uNcVF:function(a,r){return a<r},xNgqW:function(a,r){return a&r},GQRcz:t(590),AtBIn:function(a,r,s){return a(r,s)},loQvZ:function(a,r){return a|r},uPMBc:function(a,r){return a&r},rXQHF:function(a,r,s){return a(r,s)},VEnar:t(814),ROTlH:function(a,r){return a&r},WmJkt:function(a,r){return a&r},jEmuG:function(a,r){return a(r)},yqgnU:function(a,r){return a&r},CmAJp:"Hdfxm",ZEjUe:function(a,r){return a(r)},OABSW:function(a,r){return a(r)},OQUIl:t(1115),RoXxL:t(1507),MrOOd:function(a,r){return a<<r},kAhdT:t(589),pNawX:t(1643),CDWVI:function(a,r){return a&r},dEESc:t(1534),kNFCK:function(a,r){return a&r},gzwsd:function(a,r){return a&r},XUeOv:function(a,r){return a!==r},NmGwK:t(1568),iuOIG:function(a,r){return a<<r},RakEm:function(a,r){return a|r},hnOAC:function(a,r){return a>>>r},niYgT:function(a,r){return a>>>r},KXBFM:function(a,r){return a|r},GVWfH:function(a,r){return a>>>r},BAxzy:function(a,r){return a<r},GjOwM:function(a,r){return a<r},SGqXD:function(a,r){return a<r},oHDyA:function(a,r,s){return a(r,s)},tRadH:function(a,r){return a+r},qPlRR:function(a,r){return a|r},AJrPY:function(a,r){return a&r},SpxmD:function(a,r){return a!==r},IWOoC:function(a,r){return a&r},iRwuR:function(a,r){return a>>>r},fmWOT:function(a,r){return a&r},hhunw:function(a,r){return a&r},Gajyw:function(a,r){return a&r},NXebj:function(a,r){return a>>>r},IReFV:function(a,r){return a!==r},UVbqB:t(1690),DusMo:t(1160),Edolz:"LiErI",DoslG:"fKTWY",HKzzq:function(a,r){return a|r},dQEqk:function(a,r){return a|r},mULCi:function(a,r){return a===r},vZzYQ:function(a,r){return a instanceof r},PkKUo:function(a,r){return a(r)},UWXxt:"anPbo",qZKCB:function(a,r){return a|r},eFBgD:function(a,r){return a<<r},IfoTC:function(a,r){return a<<r},wBMfl:function(a,r){return a|r},LsvBK:function(a,r){return a>>>r},RMutM:function(a,r){return a|r},qNcZr:function(a,r){return a<<r},xmouJ:function(a,r){return a|r},dnKUR:function(a,r){return a<<r},USBDh:function(a,r){return a!==r},YJlKy:"JrSrU",TXZrg:function(a,r){return a&r},pBdlX:function(a,r){return a>>>r},KisAh:function(a,r){return a&r},fWarj:function(a,r,s,d){return a(r,s,d)},DkWZz:function(a,r){return a(r)},ceAcS:function(a,r){return a>=r},FUSJN:"Sdhpl",Qfjuq:function(a,r){return a+r},yZLoJ:function(a,r){return a%r},Lpbar:function(a,r){return a/r},FZttT:function(a,r){return a>>>r},OJaCy:function(a,r){return a===r},cuegC:function(a,r){return a|r},uzqrY:function(a,r){return a|r},fxjqx:function(a,r){return a|r},zFIbO:function(a,r){return a+r},FmNjn:function(a,r){return a+r},rzsTo:function(a,r){return a|r},mVMUS:function(a,r){return a+r},QMSZD:function(a,r){return a<<r},emZuG:function(a,r){return a+r},UKvIx:function(a,r){return a+r},mcjFM:function(a,r){return a+r},rUTlX:t(1593),EbSwR:t(1693),ayzIh:function(a,r){return a>>>r},jRFNQ:function(a,r){return a&r},IDcpK:function(a,r){return a>>>r},XvaWq:function(a,r){return a&r},ptcdP:function(a,r){return a+r},ukmsB:function(a,r){return a>>>r},zQsXw:function(a,r){return a|r},ESKLa:function(a,r){return a!==r},AZlnH:function(a,r){return a===r},UAwip:function(a,r){return a===r},DAaCx:function(a,r){return a===r},DiTTM:function(a,r,s,d,f){return a(r,s,d,f)},CRPTh:function(a,r){return a(r)},KWvHO:t(728),AhauR:t(813),PpHYd:function(a,r){return a===r},tfKEu:function(a,r){return a+r},ccstZ:function(a,r){return a&r},OeVEI:function(a,r){return a>>>r},FDBWy:function(a,r){return a&r},KiqLi:function(a,r){return a>>>r},neWew:function(a,r){return a>>>r},TgPIs:function(a,r){return a>>>r},vpKFm:function(a,r){return a&r},wiLYv:function(a,r){return a&r},HxTfQ:function(a,r){return a>>>r},HAqEw:function(a,r){return a&r},JtUkQ:t(1776)+t(1591),FjQxU:t(721)+t(588)+"R",yLERb:t(694)+"RROR",YaLHL:t(1602)+"OR",UZucq:"CONNECTI"+t(897),HwfYh:t(1370)+t(1949),LYchj:t(576)+"2",tJCqA:t(1509),zvSqD:function(a,r){return a!==r},NLscQ:t(1822),kJTXY:t(1346),Ukcyd:t(1535),cZIxG:function(a,r){return a===r},xspwS:function(a,r){return a==r},AWTOi:function(a,r){return a===r},xVNeo:"error",nugRp:function(a,r){return a instanceof r},aJDci:t(998)+t(1345),VNjBY:function(a,r){return a+r},cptqb:t(1787),LOmuM:function(a,r){return a===r},RoHYm:function(a,r,s){return a(r,s)},iZFYc:function(a,r,s){return a(r,s)},hwYfR:t(1451),aTZRk:t(1292),fJyfh:"XSLcm",CGMwL:t(1116),ygRLN:function(a,r,s){return a(r,s)},yjKGH:function(a,r){return a==r},LoWGn:t(639),RTBzR:t(1570),MCpOU:t(1152),RMIZe:t(565),PMBFT:"KkAJG",zEvpK:function(a,r){return a||r},DyThz:function(a,r){return a===r},WDXBR:t(1521),esiVG:t(1005),OsHEJ:function(a,r){return a||r},dZScb:function(a,r){return a!=r},BmgZm:t(1143)+"d",slyRR:"0|2|1|3|4",gCmsh:function(a,r){return a!=r},paawM:t(1548)+"alled mu"+t(1555)+t(1009)+"process",OWWYT:function(a,r){return a!==r},yihDe:t(1240),kCbGw:t(874),VWqqP:function(a,r){return a<r},Wcufi:function(a,r){return a&r},ZDTSB:function(a,r){return a===r},nLoOx:t(510),cXmBJ:function(a,r){return a<=r},SalTQ:function(a,r){return a<r},zbzOP:function(a,r){return a&r},Bchza:function(a,r){return a&r},KbgZm:function(a,r){return a<<r},vFYuH:function(a,r){return a&r},IaVms:function(a,r){return a&r},oqCAw:function(a,r){return a|r},suBYQ:function(a,r){return a|r},mbxSc:function(a,r){return a<<r},yLcsT:function(a,r){return a<<r},xAKYf:function(a,r){return a&r},IAriv:function(a,r){return a&r},ATied:function(a,r){return a+r},luBAu:function(a,r){return a<r},WwMlf:function(a,r){return a<r},KTYBV:function(a,r){return a|r},mHmtV:function(a,r){return a|r},FiMSJ:t(1909)+t(1251),ohNkG:function(a,r){return a>>r},BaQYv:function(a,r){return a|r},UppKd:function(a,r){return a|r},ituYO:function(a,r){return a&r},sMOue:function(a,r){return a|r},ulcEE:function(a,r){return a&r},NFuvw:function(a,r){return a-r},vnfpz:function(a,r){return a==r},ZFZSD:function(a,r){return a(r)},Ehrau:function(a,r){return a!=r},qJerb:function(a,r){return a instanceof r},IjEza:t(527)+t(1505),whsHg:function(a,r){return a==r},ULOSW:t(482)+t(555)+t(1427),hCXdb:t(753),TNzDF:function(a,r){return a>=r},vcvzj:function(a,r){return a+r},hbQnz:function(a,r){return a|r},rKKnv:t(702),JptGJ:t(949),WiHxa:t(1677),ryCNG:t(1445)+t(1400),TdSyr:t(1767)+t(1440),evfHZ:"http",sZyQW:function(a,r){return a!==r},XBlLK:function(a,r){return a===r},BlXuJ:function(a,r){return a===r},YXqAv:t(1584),zxXyQ:function(a,r){return a<<r},xUpYT:function(a,r){return a&r},MuzgC:function(a,r){return a===r},gWSDR:"wgGCl",HdmIH:function(a,r){return a|r},qtZiJ:function(a,r){return a&r},rixMI:function(a,r){return a|r},GPjdI:function(a,r){return a!==r},rnFYg:"CJhvL",tFzUb:t(851),jlwUg:"YQyQW",yyKbR:t(1217),Pdxgq:function(a,r){return a===r},vXjcV:t(855),mbSds:t(1618),zdyoX:t(1245),KvzVe:t(1309),fomKc:t(1668),vEihZ:function(a,r){return a||r},rwCQm:function(a,r){return a===r},XSEcr:t(1031),rWQGC:function(a,r){return a!==r},cFgEx:t(1123),dYzrt:t(925),ZBROq:function(a,r){return a===r},fRzwi:t(785),EPHPR:function(a,r){return a||r},YOIMe:function(a,r){return a||r},nxhEm:function(a,r,s){return a(r,s)},AVEQT:t(1164),ZJyvU:"biljV",XCmzU:t(1752)+"DB failed",OCvwO:t(1318),iJAdp:t(1335),AnLwj:t(1687),zHCKE:"kQBLG",ORaPl:function(a,r){return a(r)},ChArn:function(a,r,s){return a(r,s)},hePpf:"send_ack",swXIZ:t(911),zJlEJ:function(a,r){return a(r)},PIKyP:function(a,r,s,d){return a(r,s,d)},mOFtf:t(932)+t(1853),pzRcv:t(932)+t(1654)+"ck",qNrpk:function(a,r,s,d){return a(r,s,d)},KxBOX:t(932)+t(1077)+"k",GQLXp:t(932)+"er_ack_msgid",lYpvR:function(a,r,s,d){return a(r,s,d)},OusQo:"is_ack",DSFNk:t(737),xOnxO:t(1144),SCADn:function(a,r){return a<r},fGLYC:function(a,r){return a>r},hdSqJ:function(a,r){return a>r},vMZkz:function(a,r){return a+r},UNlxJ:function(a,r){return a&r},NyQnx:function(a,r){return a|r},jmJnK:function(a,r){return a===r},CsZOm:t(539),eOlhU:t(527)+t(1505)+t(1516)+"=utf-8",tCmGq:t(1501)+"e",lHkRs:function(a,r,s,d){return a(r,s,d)},XBiFd:"IbTfu",hTPSI:t(698),lKiph:function(a){return a()},gljBJ:function(a,r){return a+r},iTBVA:function(a,r){return a|r},PoDOh:function(a,r){return a(r)},TMEPt:function(a,r){return a+r},ESVLt:function(a,r){return a+r},oYgLp:function(a,r){return a+r},WHvAL:function(a,r){return a+r},AKPOT:t(717)+"t of ran"+t(642),WMrrR:t(1055),VRwtc:" > ",VThBK:t(1676)+t(1145)+"e",BrBoK:function(a,r){return a>=r},fuJnV:function(a,r){return a<r},pvpBv:function(a,r){return a>>>r},APyyG:function(a,r){return a+r},QbSBW:function(a,r){return a+r},bVUYm:function(a,r){return a+r},eXpgj:function(a,r){return a+r},QWFLE:function(a,r){return a+r},kitfJ:function(a,r){return a|r},wfQya:function(a,r){return a<<r},KlfmA:function(a,r){return a+r},RLCIQ:function(a,r){return a&r},ZtJLi:function(a,r){return a+r},Vmvpq:function(a,r){return a+r},bYRAy:function(a,r){return a+r},SYeLZ:function(a,r){return a&r},uZVDW:function(a,r){return a+r},EqoIU:function(a,r){return a>>>r},mqvOa:function(a,r){return a&r},BdlUA:t(1088)+"10|5|4|3"+t(1553)+"2",CWTMS:function(a,r,s,d){return a(r,s,d)},fXIWt:function(a,r){return a|r},wQdiy:function(a,r){return a|r},LXWSf:function(a,r){return a>>>r},SClrB:function(a,r){return a>>>r},mOHGh:function(a,r){return a<<r},RCmlK:function(a,r){return a>>>r},mUeYY:function(a,r){return a&r},zCTSY:function(a,r){return a|r},fYfBw:function(a,r){return a|r},lMAtQ:function(a,r){return a<<r},fOdmP:function(a,r){return a&r},qHMMK:function(a,r){return a|r},ucWGv:function(a,r){return a&r},NmkTQ:function(a,r){return a<r},OyCtS:function(a,r){return a<r},ypVWq:function(a,r){return a|r},ZuqeL:function(a,r){return a&r},FWDPp:t(824)+t(681),jduDB:function(a,r){return a+r},jiakP:function(a,r){return a|r},ZzYGW:"pagehide",KWWzr:t(493),mthnC:t(978),jGowV:function(a,r){return a<r},xLodr:function(a,r){return a===r},uXpOB:t(1310),hpalF:function(a,r){return a+r},HIaxC:t(676),JlPit:t(629),qMyjM:function(a,r,s,d){return a(r,s,d)},CgbHv:t(991),UBEDx:function(a,r,s,d){return a(r,s,d)},TCqAV:t(1011),pSUDX:"curvalue",saCTq:function(a,r){return a(r)},CQsDv:t(1104)+t(1299),KchSZ:function(a,r,s){return a(r,s)},okQgx:function(a,r){return a+r},ZRHPS:function(a,r){return a<r},eODQp:function(a,r){return a!==r},NvNot:t(1404),qFywb:t(1237),lyNul:function(a,r,s){return a(r,s)},LfPlP:function(a,r){return a+r},wzRtP:function(a,r,s){return a(r,s)},KrZiV:t(807)+t(951),jrxNd:t(862)+t(1579),suwVP:t(1323)+t(1703),aScHt:t(1758),LwPNt:t(614),KSdtL:t(633),LmKlm:function(a){return a()},VdIWq:function(a,r){return a!==r},RXbxg:t(827),qrAMT:t(1444),Pfxoj:function(a,r){return a(r)},OHyfW:t(867)+"r",GyIiG:t(1035),ooNzb:"fEYSr",qAUHk:t(790),DZlFH:function(a,r,s,d){return a(r,s,d)},XveLF:t(932)+"er_msgid",wbyyV:function(a,r,s){return a(r,s)},ZSYru:t(932)+t(1611),OZpdn:function(a,r,s,d){return a(r,s,d)},yvjEw:function(a,r){return a(r)},VJBOT:function(a,r,s){return a(r,s)},cEEvF:t(842)+t(1747)+"ue",ZPNAV:function(a,r){return a<r},KBpKl:function(a){return a()},ElPNi:function(a){return a()},ogPmf:function(a,r){return a<r},yMDDX:function(a,r){return a-r},zrNuT:function(a,r){return a===r},mjNhc:function(a,r){return a&&r},MGZeN:function(a){return a()},cSgAj:function(a){return a()},haupH:t(1529),joyIV:function(a,r){return a!==r},cNvdu:t(1135),qhWFW:function(a,r,s){return a(r,s)},Pncyy:t(520),rZPMV:function(a,r,s,d){return a(r,s,d)},GrfaY:function(a,r,s){return a(r,s)},KMcVx:function(a,r,s){return a(r,s)},LENRR:function(a,r){return a===r},TMHrt:t(1634),LOFIU:t(1131),BEVSP:t(773)+t(1831)+"s",jGUBk:t(1922),Kjaoh:"MydRL",FGNSg:function(a,r,s){return a(r,s)},hfngx:"close",zNDDr:function(a,r){return a(r)},bQaJk:t(1795)+t(1134),kBNTb:function(a,r){return a/r},OpPQt:function(a,r){return a===r},fHmDN:"please p"+t(830)+"alid url",bUMGz:t(622)+t(1344)+"s params, WebSoc"+t(1805)+t(1707)+t(905)+t(989),kkHnS:function(a,r){return a!==r},viyZf:t(1209),qVVGo:t(1284)+"t",wbMst:"stop imm"+t(1754)+t(1678)+"ct",cwgNT:t(587),aRVwD:function(a,r){return a!==r},UMqQf:t(1494),BPicT:t(732),Bcsul:t(1924),vAeeT:"device_id",Loudy:function(a,r){return a||r},hxbWx:"function",lXTMJ:function(a){return a()},Vzlso:t(1788),gxZmy:function(a,r,s){return a(r,s)},biAdt:function(a,r){return a>r},sEgie:function(a,r){return a-r},LsycY:function(a,r){return a|r},SEHbz:function(a,r){return a&r},ajdTj:function(a,r){return a&r},ulNNR:function(a,r){return a(r)},hZnNk:t(791),bUkHA:t(1796)+">",fWOpb:function(a,r){return a*r},eOolq:function(a,r){return a>r},nQtbh:function(a,r){return a(r)},tgyPr:function(a,r){return a!==r},xTuFG:t(981),hHNTW:function(a,r){return a===r},XgFUb:function(a,r,s){return a(r,s)},EcZnV:function(a,r,s){return a(r,s)},wHyyM:t(773)+t(921)+"t",aFgYo:t(864)+t(1887)+t(1284)+"ting ser"+t(837),SeYfn:t(1597)+" try reconnecting",FROFN:t(1559),TpKSn:t(864)+t(1700)+t(1925)+t(1556),mPZrJ:t(1704),Vxkqy:t(1334),ddfBj:function(a,r){return a(r)},zVeBj:function(a,r){return a!==r},lgWua:t(1929),jRBsz:t(1367),DduBj:t(1072),UdgMj:t(916),zRuCQ:function(a,r){return a!==r},iXcGU:t(1094),ItlSA:function(a,r){return a+r},Pphue:t(1157)+t(891),qDPRY:t(592)+t(610)+t(1930)+t(796)+"ed",uVvjW:function(a,r){return a===r},lMZWI:t(592)+"s alread"+t(923),JPJfr:"number",INBze:function(a,r){return a(r)},KyDsE:t(622)+"rovide a"+t(1830)+t(597),wPTZk:function(a,r){return a instanceof r},rUvUh:function(a,r){return a instanceof r},dMMGI:function(a,r){return a(r)},wGNQW:t(504),zuYHo:function(a,r){return a||r},YfUrj:function(a,r){return a!==r},zhdDi:"manual r"+t(1059)+t(1190),PuZqA:t(1790)+"1",rEBcU:function(a,r){return a(r)},mYKgC:t(1235),NHmMY:"gWmZT",dgtMw:t(1550),sOpyE:function(a,r){return a*r},Icykv:function(a,r){return a*r},zlpDY:function(a,r){return a/r},LVPJK:t(1638),oexPP:function(a,r){return a!=r},cBQPd:t(553),DtOjB:function(a,r){return a!=r},NNLOI:function(a,r){return a===r},GZomd:t(1639)+"dWorkerG"+t(1312)+"pe",HjSSY:function(a,r){return a===r},hIQtT:t(931)+t(1849)+t(1892),ScXAM:function(a,r){return a===r},VgExr:t(601)+"orkerGlo"+t(1050),lIAnG:function(a,r){return a!=r},AjkGW:function(a,r){return a!=r},rxtOm:function(a,r){return a!=r},jbOFQ:function(a,r,s){return a(r,s)}};Mt.r(Ce),Mt.d(Ce,{FWS:()=>_g,CustomErrorEvent:()=>nd,createCloseEvent:()=>pt,ReconnectEvent:()=>td,createErrorEvent:()=>at,decodedFrame:()=>en,createOpenEvent:()=>cd,CustomCloseEvent:()=>rd,createReconnectEvent:()=>ua,FrontierMessageEvent:()=>sd,encodeFrame:()=>zt,createMessageEvent:()=>ad,OpenEvent:()=>od,ErrorCode:()=>nn,Event:()=>tr,MessageEvent:()=>id});let n="";function i(a=""){let r=t,s="02",d=""+Date[r(972)](),f=n||(n=e[r(1835)](h,a)),p=Math[r(751)]()[r(1896)](16)[r(1269)](-6);return e[r(625)](e[r(1557)](s,d)+f,p)}function o(){let a=t,r={MHUWf:function(s,d){return s|d},dULeg:function(s,d){return e.kPNZK(s,d)},KMRYM:function(s,d){return e[F(621)](s,d)},YUTHi:function(s,d){return e[F(1332)](s,d)},eHNXB:function(s,d){return e[F(709)](s,d)},TUVfy:function(s,d){return s<<d}};return e[a(530)](e.avqeQ,e[a(920)])?e[a(1194)](e.BoQra(1e4,Date[a(972)]()),Math[a(1039)](e.FKjjU(1e4,Math[a(751)]()))):new _0x5e1ff3(r[a(593)](r[a(1277)](r[a(593)](r.KMRYM(_0x4bdc08[4],24),_0x16ff3d[5]<<16),_0x564467[6]<<8),_0x29864d[7]),r[a(1076)](r.eHNXB(r[a(887)](_0x1535bf[0],24),_0x1161cb[1]<<16)|_0x466b0e[2]<<8,_0x177625[3]),_0x29fb8b)}function c(a){let r=t;return(e.REjWP(Array,8)[r(1418)]("0")+e[r(514)](parseInt,a,10)[r(1896)](2))[r(1269)](-8)}function l(a){let r=t;return e.OPrup(Array(4)[r(1418)]("0"),e.QDGwF(parseInt,a,2)[r(1896)](16))[r(1269)](-4)}function u(a){let r=t,s=a[r(1600)](/\./)[r(704)](p=>c(p)),d=[];return d[0]=l(e[r(1557)](s[0],s[1])),d[1]=e.REjWP(l,s[2]+s[3]),["0000",r(1821),e[r(1163)],r(1821),e[r(1163)],e.YbJuX,d[0],d[1]][r(1418)]("")}function h(a){let r=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[r(1043)](a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[r(1043)](a);return s?e.nlXHA(u,a):d?e[r(1037)](x,a):r(1053)+"00000000"+r(1053)+"00000000"}function x(a){let r=t,s={dalth:function(N,B,W,$){return e[F(815)](N,B,W,$)}},d="",f=[],p=0,E=0,b=!0,g=e[r(1163)];if(e[r(1718)](a[r(1771)]("::"),-1)){let N=a[r(1600)]("::");for(let W=0;e[r(664)](W,N[r(713)]);W++){let $=N[W];if($.indexOf(":")>0){let se=$.split(":");b&&(p=se[r(713)]),E+=se[r(713)];for(let je=0;e[r(664)](je,se[r(713)]);je++)if(e[r(1386)](4,se[je][r(713)])){let St=g[r(1257)+"g"](0,e.ToqZI(4,se[je][r(713)])),as=St[r(1153)](se[je]);f[r(1387)](as)}else f[r(1387)](se[je]);b=!1}else if(e[r(1428)]===r(1120))for(var k in _0x11d2ff)dDhcJp[r(1571)](_0x50ab75,_0xd7e0b0,k,{get:_0x41f5ee[k],enumerable:!0});else{if(e.wtCVg(4,$[r(713)]))if(e[r(845)](e[r(1774)],e[r(1774)])){let se=g.substring(0,e[r(1189)](4,$[r(713)])),je=se[r(1153)]($);f[r(1387)](je)}else _0x3bbf3f[r(1387)](_0x175470);else f[r(1387)]($);b&&(p+=1),E+=1,b=!1}}let B="";for(let W=0;e.oZcCI(W,e[r(1189)](8,E));W++)B=B[r(1153)](g);for(let W=0;e[r(1329)](W,f[r(713)]);W++)e.OvkIG(W,p)&&(d=d[r(1153)](B)),d=d[r(1153)](f[W]);return d}{let N=a[r(1600)](":");for(let B=0;e[r(1012)](B,N[r(713)]);B++){let W=N[B];if(N[B][r(713)]!==4){let $=g[r(1257)+"g"](0,e[r(1189)](4,N[B][r(713)])),se=$[r(1153)](W);d=d[r(1153)](se)}else d=d[r(1153)](W)}return d}}function m(a,r){let s=t,d={ptmUD:function(f,p){return e[F(1731)](f,p)},vfovP:function(f,p){return e.zDbmq(f,p)},fGKBF:function(f,p){return e[F(1632)](f,p)},TpZTb:function(f,p){return e[F(1738)](f,p)},mPbYK:function(f,p){return e[F(621)](f,p)},cZsks:function(f,p){return e[F(621)](f,p)},kutUz:function(f,p){return e.JbHhx(f,p)},rxQfL:function(f,p){return e.MCnnE(f,p)}};if(e[s(1751)]===s(1281))return e[s(1037)](_0x97bdf5,_0x1b1511(_0x173126));{let f=a[s(747)];e[s(876)](void 0,f)&&(e.uOZMs(pe,r,10),e[s(1263)](U,r,f));let p=a[s(1026)];if(p!==void 0)if(e[s(976)]!==e[s(846)])e[s(678)](pe,r,18),e[s(1859)](U,r,p);else return d.ptmUD(_0x3eca5c,_0x3b6812)?_0x3ce9f6:new _0x3c5268(d[s(1295)](d.fGKBF(d[s(1105)](_0x5602eb.call(_0x4854b7,0)|d[s(1935)](_0x5c643e[s(596)](_0x2b6bbc,1),8),d.cZsks(_0x4fd02d.call(_0x780ef3,2),16)),d[s(1893)](_0xc9f449[s(596)](_0x4f4060,3),24)),0),d[s(1105)](d[s(1342)](_0x56e91d[s(596)](_0x2ebe0f,4),_0x2ae741[s(596)](_0x9f056f,5)<<8)|d.cZsks(_0x279de2[s(596)](_0x42730f,6),16),_0x4237fa.call(_0x405cb0,7)<<24)>>>0,!0)}}function w(a){let r=t,s={};e:for(;!e[r(982)](V,a);){let d=xe(a);switch(e[r(1437)](d,3)){case 0:break e;case 1:s[r(747)]=e[r(1905)](P,a,e.CwwYh(xe,a));break;case 2:s[r(1026)]=e[r(1441)](P,a,e.BXuXM(xe,a));break;default:R(a,e[r(649)](7,d))}}if(e[r(650)](void 0,s.key))throw new Error(e[r(605)]);if(e[r(1090)](void 0,s[r(1026)]))throw new Error(e.JmROu);return s}function S(a){let r=t,s=e.KcgYi(C);return e[r(1441)](_,a,s),L(s)}function _(a,r){let s=t,d=a[s(1537)];e[s(1877)](void 0,d)&&(e[s(1439)](pe,r,8),e[s(1441)](xt,r,d));let f=a[s(1840)];e[s(1614)](void 0,f)&&(e[s(819)](pe,r,16),e[s(1637)](xt,r,f));let p=a.service;e[s(1614)](void 0,p)&&(e[s(678)](pe,r,24),xt(r,e[s(722)](D,p)));let E=a.method;e[s(1264)](void 0,E)&&(pe(r,32),xt(r,e[s(618)](D,E)));let b=a[s(1018)];if(e[s(1049)](void 0,b))for(let je of b){e[s(1637)](pe,r,42);let St=e.GfNjy(C);e[s(1637)](m,je,St),pe(r,St[s(641)]),e.swMtv(j,r,St),e[s(618)](O,St)}let g=a[s(1573)+s(1156)];g!==void 0&&(e[s(581)](pe,r,50),e[s(819)](U,r,g));let k=a[s(832)+s(1431)];e[s(1049)](void 0,k)&&(e[s(819)](pe,r,58),e.nSKPT(U,r,k));let N=a[s(624)];e[s(1877)](void 0,N)&&(e.exfYN(pe,r,66),e.IeNne(pe,r,N[s(713)]),e[s(1263)](oe,r,N));let B=a[s(524)];e.luYvT(void 0,B)&&(e.CAqfZ(pe,r,74),e[s(1736)](U,r,B));let W=a[s(1566)+"ming"];e[s(1877)](void 0,W)&&(e.QvnUq(pe,r,82),e.CAqfZ(U,r,W));let $=a[s(558)];e.wtCVg(void 0,$)&&(e[s(1280)](pe,r,90),e[s(1263)](U,r,$));let se=a.frameType;se!==void 0&&(e.aDiZl(e[s(1159)],e[s(1206)])?(_0x44c2c4=e[s(480)](_0x368da8,_0x4a1ada),_0x4c4fa7|=e.TzRhP(e[s(649)](127,_0x4ab0b7),21),128&_0x2de081&&(_0x27ff07=e[s(618)](_0x176823,_0x101c08),_0x8ef999=127&_0x13769d,128&_0x1bc70f&&(_0x18fb03=_0x1a3065(_0x250a4c),_0x301328|=e[s(621)](e[s(1023)](127,_0x1b4290),7)))):(e[s(1405)](pe,r,96),xt(r,e[s(598)](D,se))))}function v(a){let r=t;return e[r(1037)](I,e[r(1615)](M,a))}function I(a){let r=t,s={};e:for(;!V(a);){let d=e[r(1615)](xe,a);switch(e[r(1279)](d,3)){case 0:break e;case 1:s[r(1537)]=e[r(743)](vt,a,!0);break;case 2:s.LogID=e[r(1201)](vt,a,!0);break;case 3:s.service=e[r(1806)](xe,a);break;case 4:s[r(537)]=e.sgNAr(xe,a);break;case 5:{let f=A(a);(s[r(1018)]||(s[r(1018)]=[]))[r(1387)](e.IMhUU(w,a)),a.limit=f;break}case 6:s.payloadEncoding=e.FoUmc(P,a,e[r(1814)](xe,a));break;case 7:s["payloadT"+r(1431)]=e[r(1273)](P,a,xe(a));break;case 8:s[r(624)]=ie(a,e[r(954)](xe,a));break;case 9:s[r(524)]=e.MzItH(P,a,e[r(806)](xe,a));break;case 10:s[r(1566)+r(564)]=e[r(1441)](P,a,e.xySDE(xe,a));break;case 11:s[r(558)]=e.PfSAU(P,a,e[r(1037)](xe,a));break;case 12:s[r(1114)+"e"]=e[r(1706)](xe,a);break;default:e[r(985)](R,a,e[r(927)](7,d))}}if(e.BAzYQ(void 0,s.SeqID))throw new Error("Missing "+r(1136)+r(1301)+r(1537));if(e.rSejv(void 0,s[r(1840)]))throw new Error(e[r(1622)]);if(e[r(1900)](void 0,s[r(991)]))throw new Error(r(979)+r(1136)+" field: "+r(991));if(e.NgSFl(void 0,s[r(537)]))throw new Error(e[r(1938)]);return s}function A(a){let r=t,s=xe(a),d=a[r(641)];return a[r(641)]=a[r(1176)]+s,d}function R(a,r){let s=t,d={wknEW:function(f,p){return e[F(1023)](f,p)},SKPeZ:function(f,p){return e[F(1279)](f,p)},VxvTq:function(f,p){return f&p},aaAaO:function(f,p){return e.FGeNs(f,p)}};if(e.mlFdu(e[s(545)],e[s(545)]))switch(r){case 0:for(;e.wZEMD(128,e.nlXHA(ee,a)););break;case 2:e[s(1829)](Z,a,e[s(1619)](xe,a));break;case 5:e.JWFSE(Z,a,4);break;case 1:Z(a,8);break;default:throw new Error(e[s(1557)](e[s(549)],r))}else{let f=this.high,p=this.low;return[f>>>24,d[s(777)](d[s(730)](f,16),255),d[s(777)](f>>>8,255),d[s(777)](255,f),d.SKPeZ(p,24),d[s(1385)](d[s(730)](p,16),255),d.aaAaO(d[s(730)](p,8),255),d[s(509)](255,p)]}}function D(a){let r=t;return a|=0,{low:a,high:e[r(742)](a,31),unsigned:e[r(1940)](a,0)}}let y=[];function C(){let a=t,r={zxAhk:e.AWjRT};if(a(1170)!==e[a(1307)]){let s=y.pop();return s?(s[a(1176)]=s.limit=0,s):{bytes:new Uint8Array(64),offset:0,limit:0}}else this[a(1283)+a(1356)]?.[a(1092)](),this[a(1228)]("ping_once_timeout",r.zxAhk),this[a(1283)+a(1356)]?.[a(1341)+a(1174)+"nt"]()?this[a(1813)+a(1059)]():this[a(1629)]()}function O(a){y.push(a)}function M(a){return{bytes:a,offset:0,limit:a.length}}function L(a){let r=t,s=a.bytes,d=a[r(641)];return e[r(497)](s.length,d)?s:s[r(986)](0,d)}function Z(a,r){let s=t;if(e.OPrup(a[s(1176)],r)>a[s(641)])throw new Error("Skip pas"+s(1834));a[s(1176)]+=r}function V(a){let r=t;return e[r(1940)](a.offset,a[r(641)])}function ne(a,r){let s=t,d=a.bytes,f=a[s(1176)],p=a[s(641)],E=f+r;if(e[s(1275)](E,d[s(713)])){let b=new Uint8Array(2*E);b[s(962)](d),a[s(1640)]=b}return a[s(1176)]=E,e[s(1275)](E,p)&&(a[s(641)]=E),f}function Y(a,r){let s=t,d=a.offset;if(e[s(1857)](d,r)>a[s(641)])throw new Error(e.ywtuq);return a[s(1176)]+=r,d}function ie(a,r){let s=t,d=e.odbgq(Y,a,r);return a[s(1640)][s(986)](d,e[s(1368)](d,r))}function oe(a,r){let s=t,d=e.vEVvA(ne,a,r.length);a[s(1640)][s(962)](r,d)}function P(a,r){let s=t;if(e[s(1731)](e[s(1902)],e[s(1902)])){let d=e.chCMh(Y,a,r),f=String[s(973)+s(612)],p=a[s(1640)],E="\uFFFD",b="";for(let g=0;e[s(1329)](g,r);g++){let k=p[g+d],N,B,W,$;e.EPfAV(e.AhrSY(128,k),0)?b+=e[s(598)](f,k):e.OvkIG(224&k,192)?g+1>=r?b+=E:(N=p[e.wCcNf(e[s(1897)](g,d),1)],e[s(1179)](192&N,128)?b+=E:($=e[s(604)](e[s(1099)](e[s(649)](31,k),6),e.CdGtn(63,N)),e[s(664)]($,128)?b+=E:(b+=f($),g++))):e.nApWj(e[s(927)](240,k),224)?g+2>=r?b+=E:e.dZNZE(e.EgLfz,s(828))?this.on(_0x25d783,_0x12f39f):(N=p[g+d+1],B=p[e.HsGKx(g,d)+2],e.EHnEn(e.Mbfrn(e[s(1332)](N,e[s(871)](B,8)),49344),32896)?b+=E:($=e[s(1332)](e.MCnnE(e[s(649)](15,k)<<12,e.CdGtn(63,N)<<6),e[s(649)](63,B)),e[s(892)]($,2048)||e[s(1473)]($,55296)&&e[s(1727)]($,57343)?b+=E:(b+=f($),g+=2))):e.DSwFX(e[s(1519)](248,k),240)?e.BnaLP(e[s(1450)](g,3),r)?b+=E:(N=p[e.RFtAO(e[s(1664)](g,d),1)],B=p[g+d+2],W=p[e.bKill(g+d,3)],e[s(1286)](e[s(1738)](e[s(1807)](N,e[s(1819)](B,8)),e[s(871)](W,16)),12632256)!==8421504?b+=E:($=e[s(1738)](e[s(1203)](e[s(1332)](e.JbHhx(e[s(1519)](7,k),18),e.bWOse(e.YraPy(63,N),12)),e[s(649)](63,B)<<6),e[s(1621)](63,W)),e.MVYrT($,65536)||$>1114111?b+=E:($-=65536,b+=e[s(1032)](f,e.HsGKx(e[s(1541)]($,10),55296),e.UBbsL(e[s(1013)](1023,$),56320)),g+=3))):b+=E}return b}else this[s(1645)]=!0,this[s(1337)]()}function U(a,r){let s=t,d={WKguS:function(g,k){return e[F(799)](g,k)}},f=r.length,p=0;for(let g=0;g<f;g++)if(e[s(1464)]!==s(1630)){let k=r.charCodeAt(g);e.Wbmoa(k,55296)&&e.MLTxz(k,56319)&&e[s(1012)](g+1,f)&&(k=e[s(554)](e[s(1187)](e[s(550)](k,10),r[s(1458)+"At"](++g)),56613888)),p+=e[s(1879)](k,128)?1:k<2048?2:e.Bjqwl(k,65536)?3:4}else return _0x4ffe6a?.find(k=>k[s(747)]===_0x277dc3)?.[s(1026)];e[s(1460)](pe,a,p);let E=e.IMAeb(ne,a,p),b=a[s(1640)];for(let g=0;g<f;g++){let k=r.charCodeAt(g);if(e[s(956)](k,55296)&&k<=56319&&e[s(1329)](e[s(1664)](g,1),f)&&(k=e.ToqZI(e[s(1187)](e[s(1100)](k,10),r[s(1458)+"At"](++g)),56613888)),e[s(1764)](k,128))b[E++]=k;else if(e[s(1386)](s(1926),s(1628)))k<2048?b[E++]=e[s(1446)](e[s(1360)](e[s(742)](k,6),31),192):(k<65536?b[E++]=e[s(1621)](e[s(1103)](k,12),15)|224:(b[E++]=e.JgRPU(e[s(1286)](e.AkviC(k,18),7),240),b[E++]=e[s(1203)](e[s(1013)](e[s(1103)](k,12),63),128)),b[E++]=e[s(540)](e.AHesa(k,6),63)|128),b[E++]=e.COiJi(63&k,128);else{let N=_0x24eb06.substring(0,etNgHA[s(849)](4,_0x41de6e[_0x51955d][s(713)])),B=N[s(1153)](_0x26dde1[_0x1f7e0b]);_0x5a2a46[s(1387)](B)}}}function j(a,r){let s=t,d=e[s(890)](ne,a,r.limit),f=a.bytes,p=r[s(1640)];for(let E=0,b=r[s(641)];E<b;E++)f[e[s(1943)](E,d)]=p[E]}function ee(a){return a[t(1640)][Y(a,1)]}function Xe(a,r){let s=t,d=e.vEVvA(ne,a,1);a[s(1640)][d]=r}function xe(a){let r=t,s=0,d=0,f;do f=ee(a),e.uNcVF(s,32)&&(d|=e[r(550)](e[r(1282)](127,f),s)),s+=7;while(e.ncRBD(128,f));return d}function pe(a,r){let s=t;for(r>>>=0;r>=128;){if(e.GQRcz!==s(590))return;e[s(769)](Xe,a,e[s(1531)](e[s(1036)](127,r),128)),r>>>=7}e[s(784)](Xe,a,r)}function vt(a,r){let s=t,d={ZQASX:"boe",tDOoj:e[s(595)]},f=0,p=0,E=0,b;if(b=ee(a),f=e.ROTlH(127,b),e[s(918)](128,b)&&(b=e[s(1841)](ee,a),f|=e[s(1099)](e[s(788)](127,b),7),128&b)){if(e.OvkIG(s(1351),e[s(1524)]))switch(_0x109e5a){case d[s(705)]:case d.tDOoj:return{["x-use-"+_0x50492e]:1,"x-tt-env":_0x32b110};default:return{}}else if(b=e[s(1835)](ee,a),f|=e.ncRBD(127,b)<<14,128&b&&(b=e.ZEjUe(ee,a),f|=e[s(649)](127,b)<<21,e[s(788)](128,b)&&(b=e[s(1128)](ee,a),p=e[s(1360)](127,b),e.yqgnU(128,b))))if(e[s(866)](e[s(1246)],e[s(1141)])){if(b=e[s(1814)](ee,a),p|=e[s(1171)](127&b,7),128&b&&(b=e[s(982)](ee,a),p|=e[s(844)](e[s(706)](127,b),14),128&b))if(e[s(530)](e.kAhdT,e[s(1563)])){if(b=e[s(1706)](ee,a),p|=e[s(1171)](e.CDWVI(127,b),21),e[s(1797)](128,b)){if(e[s(577)]!==e.dEESc)this[s(1327)+"hMessageEvent"](_0x3ffab9),_0x4d70da[s(962)](_0x50010b,_0xbb091e,_0x5bfcdf[s(1509)][s(991)]);else if(b=ee(a),E=e[s(1843)](127,b),e[s(1592)](128,b))if(e[s(1225)](s(1175),e[s(1200)]))b=ee(a),E|=(127&b)<<7;else{let g=(s(1483)+"1")[s(1600)]("|"),k=0;for(;;){switch(g[k++]){case"0":this[s(1283)+"sCounter"]?.[s(1920)+s(1673)]();continue;case"1":this[s(1337)]();continue;case"2":this["_readyCl"+s(1429)]=!1;continue;case"3":this[s(1465)+s(795)]?.[s(654)+s(1326)+s(852)]();continue;case"4":this[s(1645)]=!0;continue}break}}}}else return this._socket[s(909)]}else e.JWFSE(_0x2a5fd2,_0x5e1350,66),e[s(819)](_0x5b691c,_0x4fd8f1,_0x50a925.length),e[s(1750)](_0x164bab,_0x292cda,_0x5c6b0f)}return{low:e.COiJi(f,e.iuOIG(p,28)),high:e[s(738)](e[s(1279)](p,4),E<<24),unsigned:r}}function xt(a,r){let s=t,d=e[s(1624)](r.low,0),f=e[s(1561)](e.KXBFM(e[s(1437)](r[s(1474)],28),e[s(1171)](r[s(924)],4)),0),p=e[s(1008)](r[s(924)],24),E=e[s(845)](0,p)?f===0?d<16384?e[s(892)](d,128)?1:2:e[s(1873)](d,2097152)?3:4:e[s(1071)](f,16384)?e.TVuvm(f,128)?5:6:e.SGqXD(f,2097152)?7:8:p<128?9:10,b=e[s(689)](ne,a,E),g=a[s(1640)];switch(E){case 10:g[e[s(1383)](b,9)]=e.YraPy(e[s(1561)](p,7),1);case 9:g[e[s(625)](b,8)]=E!==9?e[s(1167)](128,p):e[s(720)](127,p);case 8:g[e[s(913)](b,7)]=e[s(1763)](8,E)?e.jdIav(e.zDbmq(f,21),128):e[s(1596)](e.SSRrl(f,21),127);case 7:g[b+6]=E!==7?f>>>14|128:e[s(1013)](f>>>14,127);case 6:g[b+5]=e[s(1798)](6,E)?e[s(723)](f,7)|128:e.fmWOT(e[s(1561)](f,7),127);case 5:g[e[s(1187)](b,4)]=e[s(866)](5,E)?e[s(1435)](128,f):e[s(1596)](127,f);case 4:g[e.bKill(b,3)]=E!==4?e[s(1894)](e[s(1624)](d,21),128):e[s(1033)](e[s(1279)](d,21),127);case 3:g[e[s(1450)](b,2)]=e[s(1614)](3,E)?d>>>14|128:e.Gajyw(e[s(1437)](d,14),127);case 2:g[b+1]=E!==2?e[s(1624)](d,7)|128:e[s(1797)](e.NXebj(d,7),127);case 1:g[b]=e.IReFV(1,E)?e[s(856)](128,d):e.OCBAu(127,d)}}function en(a){let r=t;return e[r(1669)](e[r(1880)],e[r(1880)])?v(a):this[r(1937)]["clearSto"+r(1653)]()}function zt(a){return e[t(1706)](S,a)}let tn=65536,Jr=e[t(939)],_e=e[t(1773)](tn,tn),Ae=e[t(1003)](_e,_e),er=e.zlpDY(Ae,2),De=String[t(1800)+"e"][t(1458)+"At"];class fe{constructor(r,s,d){let f=t;e.mlFdu(e[f(992)],e.DoslG)?(this[f(1472)+f(1468)].push(_0x516958),this[f(1612)](e.DusMo,_0x1296e1)):(this[f(1233)]=!0,this[f(1474)]=e[f(1694)](0,r),this.high=e.dQEqk(0,s),this[f(1631)]=!!d)}static[t(1233)](r){let s=t;return r&&e[s(711)](!0,r[s(1233)])}static[t(552)](r,s,d){return new fe(r,s,d)}static fromBytes(r,s,d){let f=t;if(e.fjzqO(e[f(850)],e.UWXxt)){if(TaOVjN[f(1268)](_0x50826a,_0x1ec67b))return TaOVjN.PkKUo(_0x552db1,_0x1d42df);if(_0x4a6dc7[f(1890)](_0x3ddee7))return _0x4361b7[f(835)](_0xfb7ff8);let p=_0x4bd671(_0x23f1df);return p!==_0x1728ea&&(_0x4d4941.set(_0x4274af,p),_0x1cb264[f(962)](p,_0xcdc9fb)),p}else return d?fe[f(847)+"sLE"](r,s):fe[f(847)+f(1006)](r,s)}static[t(847)+"sLE"](r,s){let d=t;return new fe(r[0]|r[1]<<8|r[2]<<16|e[d(871)](r[3],24),e[d(738)](r[4]|e[d(571)](r[5],8)|e.iuOIG(r[6],16),e[d(1171)](r[7],24)),s)}static[t(847)+"sBE"](r,s){let d=t;return new fe(e[d(1203)](e[d(1712)](e[d(1463)](r[4],24),e.IfoTC(r[5],16))|e[d(621)](r[6],8),r[7]),e[d(1531)](e[d(1487)](e[d(1446)](r[0]<<24,r[1]<<16),r[2]<<8),r[3]),s)}static[t(528)](r){let s=t;return e[s(608)](r,Jr)?ed:new fe(e[s(872)](e[s(960)](De.call(r,0)|e[s(550)](De.call(r,1),8),De[s(596)](r,2)<<16)|e[s(619)](De[s(596)](r,3),24),0),e.xmouJ(e[s(1632)](De[s(596)](r,4),e[s(844)](De[s(596)](r,5),8))|e[s(1099)](De[s(596)](r,6),16),e[s(1130)](De[s(596)](r,7),24))>>>0,!0)}[t(943)](){let r=t,s={iSJRU:function(d,f){return d===f}};if(e[r(1150)]("UqZff",e[r(1155)]))return String[r(973)+r(612)](e[r(1827)](255,this[r(1474)]),this.low>>>8&255,e.yqgnU(e[r(1279)](this[r(1474)],16),255),this[r(1474)]>>>24,e[r(582)](255,this[r(924)]),e[r(1761)](this.high,8)&255,e.KisAh(e[r(1561)](this[r(924)],16),255),this.high>>>24);{let d=this[r(1417)+"rs"][_0x2cf137];if(d)for(let f=0;f<d[r(713)];)s.iSJRU(d[f].fn,_0x238092)?d[r(1780)](f,1):++f}}static fromNumber(r,s=!0){let d=t;if(e[d(679)](isNaN,r))return s?Pp:ed;if(s){if(e.ceAcS(r,Ae))return Op}else if(e[d(1049)](d(1004),e.FUSJN)){if(e[d(515)](r,-er))return Lp;if(e.Qfjuq(r,1)>=er)return Dp}else throw _0x1ce93a=_0x571e20[d(713)],e[d(1719)](_0x5258a5,_0x3382f4,10,_0x43dfe3.length);return fe[d(552)](e.ZNZvQ(e[d(1652)](r,_e),0),e[d(738)](e[d(671)](r,_e),0),s)}toNumber(){let r=t;return this[r(1631)]?e.DlCbt((this.high>>>0)*_e,this[r(1474)]>>>0):e.ZoSCs(this[r(924)]*_e,e[r(1804)](this.low,0))}isZero(){return e[t(1769)](0,this.high)&&this.low===0}[t(1086)](r){let s=t;if(e.cCxje(e[s(825)],e[s(646)])){let d=new _0x54417a(e[s(821)](e[s(802)](e[s(884)](e[s(1819)](_0x43d7b5[_0x52125c+4],24),e[s(550)](_0x271de2[e[s(1471)](_0x10c9a9,5)],16)),e[s(1099)](_0xa276c4[_0x20929d+6],8)),_0xeea26d[e[s(914)](_0x213e4c,7)]),e[s(1377)](e.rzsTo(e[s(1694)](_0xb88382[e[s(1604)](_0x399ba9,0)]<<24,e[s(1358)](_0x90b276[e[s(746)](_0x23bd71,1)],16)),_0x1fe4a7[e.UKvIx(_0x399f1d,2)]<<8),_0x44b107[e[s(823)](_0x2c0b31,3)]),!0);return _0x3a3a07+=8,{value:d,offset:_0x4123f5+8}}else{fe[s(1233)](r)||(r=fe[s(1306)+"er"](r));let d=e[s(1761)](this[s(924)],16),f=e[s(540)](65535,this[s(924)]),p=e[s(794)](this[s(1474)],16),E=e[s(647)](65535,this[s(1474)]),b=e.IDcpK(r[s(924)],16),g=e[s(1360)](65535,r[s(924)]),k=e[s(1437)](r[s(1474)],16),N=e[s(1802)](65535,r[s(1474)]),B=0,W=0,$=0,se=0;return se+=e.sVdUZ(E,N),$+=e[s(1008)](se,16),se&=65535,$+=e[s(823)](p,k),W+=$>>>16,$&=65535,W+=e[s(580)](f,g),B+=e[s(1478)](W,16),W&=65535,B+=e[s(580)](d,b),B&=65535,fe[s(552)](e[s(1130)]($,16)|se,e[s(1285)](e[s(1100)](B,16),W),this.unsigned)}}[t(1713)](r){let s=t;return fe.isLong(r)||(r=fe[s(1306)+"er"](r)),e[s(994)](this.unsigned,r.unsigned)&&e[s(1331)](e[s(1437)](this[s(924)],31),1)&&e[s(1064)](r[s(924)],31)===1?!1:e[s(1623)](this[s(924)],r[s(924)])&&e[s(729)](this[s(1474)],r[s(1474)])}addOne(){let r=t,s={LPUBe:function(d,f,p,E,b){return e.DiTTM(d,f,p,E,b)},RytIN:function(d,f){return e[F(685)](d,f)}};if(e[r(1049)](e.KWvHO,e[r(1511)]))return e.UAwip(-1,this[r(1474)])&&e[r(1215)](-1,this.high)?fe.fromBits(0,0,this[r(1631)]):e[r(1711)](-1,this[r(1474)])?fe[r(552)](0,this[r(924)]+1,this.unsigned):fe[r(552)](e[r(1017)](this[r(1474)],1),this[r(924)],this[r(1631)]);gDBNry[r(1347)](_0x3a1d87,_0x47b026(_0x36e666[r(1842)]),_0x4c4444.oldVersion,_0x215272[r(1158)+"on"],gDBNry.RytIN(_0x40a1b9,_0x301212["transact"+r(1836)]))}[t(757)](r){let s=t;return r?this[s(630)+"E"]():this[s(1789)+"E"]()}[t(630)+"E"](){let r=t,s=this[r(924)],d=this[r(1474)];return[e.ccstZ(255,d),e[r(843)](d,8)&255,d>>>16&255,e[r(1064)](d,24),e[r(540)](255,s),e[r(525)](e.KiqLi(s,8),255),e[r(649)](e.SSRrl(s,16),255),e[r(794)](s,24)]}toBytesBE(){let r=t,s=this.high,d=this[r(1474)];return[e.neWew(s,24),e[r(1064)](s,16)&255,e[r(1033)](e[r(529)](s,8),255),e[r(1262)](255,s),e[r(727)](d,24),e.wiLYv(e.HxTfQ(d,16),255),d>>>8&255,e[r(1213)](255,d)]}}let ed=new fe(0,0,!1),Pp=new fe(0,0,!0),Dp=fe[t(552)](-1,2147483647,!1),Op=fe[t(552)](-1,-1,!0),Lp=fe[t(552)](0,-2147483648,!1);var nn=(function(a){let r=t,s=e[r(958)][r(1600)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[r(513)]]=5003]=e.FjQxU;continue;case"1":a[a[r(694)+r(534)]=5001]=e[r(980)];continue;case"2":a[a[e[r(536)]]=5005]=e[r(536)];continue;case"3":a[a[e[r(1372)]]=5002]=e[r(1372)];continue;case"4":a[a[e[r(1688)]]=5004]=e[r(1688)];continue;case"5":return a}break}})({});class tr{constructor(r){let s=t;this[s(955)]=r,this[s(1272)]=null}}class td extends tr{constructor(r,s){let d=t;super(r),this[d(1509)]=s&&s[d(1509)]||null}}class nd extends tr{constructor(r,s){let d=t;super(r),this[d(1069)]=s&&s.error||null,this.colno=s&&s[d(1007)]||0,this[d(1671)]=s&&s[d(1671)]||"",this[d(803)]=s&&s[d(803)]||0,this[d(1509)]=s&&s[d(1509)]||"",this.code=s&&s[d(790)]||5001}}class rd extends tr{constructor(r,s){let d=t,f=e[d(1291)][d(1600)]("|"),p=0;for(;;){switch(f[p++]){case"0":this[d(1400)]=s&&s[d(1400)]||"";continue;case"1":this.wasClean=s&&s.wasClean||!1;continue;case"2":this[d(1278)+d(1679)]=s&&s["willReco"+d(1679)]||!1;continue;case"3":super(r);continue;case"4":this[d(790)]=s&&s.code||0;continue}break}}}class id extends tr{constructor(r,s){let d=t;super(r),this[d(882)]=s&&s[d(882)]||null}}class sd extends id{constructor(r,s){let d=t,f={enEBk:e[d(557)]};e[d(1725)](e[d(810)],e[d(674)])?(super(r),this.data=s&&s[d(882)]||null,this[d(1509)]=s&&s[d(1509)]||null):(this[d(1228)](f[d(1746)],_0x3f5091),this[d(1538)+"e"]&&this[d(1538)+"e"](_0x5b6abd))}}class od extends tr{constructor(r,s){let d=t;super(r),this[d(882)]=s&&s[d(882)]||null}}function at(a,{message:r,code:s,error:d}){return new nd(a,{message:r,code:s,error:d})}function pt(a,{code:r,reason:s,wasClean:d,willReconnect:f}){return new rd(a,{code:r,reason:s,wasClean:d,willReconnect:f})}function ad(a,{data:r,message:s}){return new sd(a,{data:r,message:s})}function cd(a,{data:r}){let s=t,d={TBTeR:function(f,p,E){return f(p,E)}};if(e[s(1331)](e[s(1918)],s(1535)))return new od(a,{data:r});d[s(606)](_0x5e51f4,_0x41cf87,this[s(838)+s(1801)+"e"](_0x2efe7b))}function ua(a,{message:r}){return new td(a,{message:r})}class ld{constructor(r,s){let d=t;this[d(886)+"s"]=r,this[d(501)+"es"]=s,this["currentI"+d(500)]=0,this["currentE"+d(1749)+"riesCount"]=0}[t(654)+t(1326)+t(852)](){let r=t;this[r(1236)+r(500)]=0,this["currentE"+r(1749)+r(1027)+"t"]=0}[t(1872)+"es"](){let r=t;this[r(1290)+r(1749)+r(1027)+"t"]=0}[t(1680)+t(1338)+"nt"](){let r=t;return this.endpoints[this[r(1236)+r(500)]]}[t(1680)+"ntEndpointTriesC"+t(1470)](){let r=t;return this[r(1290)+r(1749)+r(1027)+"t"]}[t(1341)+t(1950)+"es"](){let r=t;return!!(e[r(1473)](this.currentIndex,this[r(886)+"s"].length)||e.cZIxG(this[r(1236)+"ndex"],e.bwhOP(this[r(886)+"s"][r(713)],1))&&this[r(1290)+r(1749)+r(1027)+"t"]===this[r(501)+"es"])}["checkCur"+t(1581)+t(1457)+t(1423)+t(898)](){let r=t;return e[r(961)](this[r(1236)+r(500)],this.endpoints[r(713)])?!0:this["currentE"+r(1749)+r(1027)+"t"]>this.maxRetries}[t(1931)+t(1484)+"pointAnd"+t(1234)+t(1728)](){let r=t;return this[r(1290)+r(1749)+"riesCount"]=1,this["currentI"+r(500)]++,this[r(886)+"s"][this[r(1236)+"ndex"]]}[t(1680)+t(1338)+t(1204)+t(1650)](){let r=t;return this[r(1290)+r(1749)+r(1027)+"t"]++,this[r(1680)+r(1338)+"nt"]()}}let nr=(e[t(1952)](e[t(1349)],typeof globalThis)&&e[t(1863)](t(1638),globalThis[t(1226)+t(1106)].name)||e[t(1349)]!=typeof window&&e[t(1095)]===window[t(1226)+t(1106)][t(1011)])&&e[t(566)](t(1143)+"d",typeof document),Cn=e.oexPP(t(1143)+"d",typeof globalThis)&&(e[t(548)]===globalThis[t(1226)+"tor"][t(1011)]||t(1639)+t(1320)+t(1312)+"pe"===globalThis[t(1226)+"tor"][t(1011)])&&e[t(1349)]!=typeof tt,Yr=(e.DtOjB(e[t(1349)],typeof globalThis)&&e[t(548)]===globalThis[t(1226)+t(1106)].name||e[t(1708)](e[t(1349)],typeof globalThis)||e[t(1649)](e[t(1349)],typeof globalThis)&&!!globalThis[t(1656)+t(1138)])&&e[t(566)](e[t(1349)],typeof wx),Xr=e[t(1349)]!=typeof globalThis&&(e[t(1686)](e[t(1809)],globalThis[t(1226)+t(1106)][t(1011)])||e[t(665)](e[t(1865)],globalThis[t(1226)+t(1106)].name)||e[t(1212)](e[t(1503)],globalThis["construc"+t(1106)].name))&&e[t(566)](e[t(1349)],typeof self),Np=e[t(1868)](e[t(1349)],typeof globalThis)&&e[t(548)]===globalThis[t(1226)+t(1106)].name&&e.AjkGW(e.BmgZm,typeof global)&&e[t(548)]===global["construc"+t(1106)][t(1011)]&&t(1143)+"d"!=typeof process&&!!process[t(1744)];class fa{constructor(){let r=t;this[r(1417)+"rs"]={}}[t(1228)](r,...s){let d=t,f=this._listeners[r];if(f)f[d(1269)]()[d(1357)](p=>p.fn.apply(p.ctx,s));else if(e.AWTOi(e[d(479)],r)&&!this.onerror){let p=s.length&&s[0];if(e[d(1223)](p,Error))throw p;let E=new Error(e.tRadH(e[d(812)],p?e[d(744)](" ("+p[d(1509)],")"):""));throw E[d(697)]=p,p}return this}[t(584)](r,s){let d=t;if(e[d(632)]!==e[d(632)])return _0x44e23c[d(1176)]>=_0x1197eb[d(641)];if(r===void 0)this[d(1417)+"rs"]={};else if(e[d(650)](void 0,s))this[d(1417)+"rs"][r]=null;else{let f=this[d(1417)+"rs"][r];if(f)for(let p=0;p<f[d(713)];)e[d(1647)](f[p].fn,s)?f[d(1780)](p,1):++p}return this}on(r,s,d){let f=t;return(this[f(1417)+"rs"][r]||(this[f(1417)+"rs"][r]=[]))[f(1387)]({fn:s,ctx:d||this}),this}}class Mp extends fa{[t(919)+"rrorMess"+t(1230)](r){let s=t;return r[s(1249)]||r.errNo?(s(811)+" "+(r.errMsg||"")+s(1406)+(r[s(1210)]||""))[s(1207)]():JSON[s(762)+"y"](r)}constructor(r,s,d){let f=t;super(),this._socket=null,Yr&&wx[f(937)+f(609)]&&(this[f(623)]=wx[f(937)+f(609)]({url:r,protocols:s,header:d,fail:this[f(541)+f(495)+"lHandler"][f(643)](this),success:this[f(541)+f(1919)+f(563)+f(573)].bind(this)})),Cn&&tt[f(937)+f(609)]&&(this._socket=tt[f(937)+f(609)]({url:r,protocols:s,header:d,fail:this[f(541)+f(495)+f(1489)][f(643)](this),success:this[f(541)+f(1919)+f(563)+f(573)][f(643)](this)}))}[t(541)+t(1919)+"cessHand"+t(573)](){let r=t;Promise[r(1762)]()[r(1477)](()=>{this[r(1512)+"steners"]()})}[t(541)+"ocketFailHandler"](r){let s=t;if(e[s(1725)](e[s(885)],e[s(885)]))return this[s(886)+"s"][this.currentIndex];Promise.resolve()[s(1477)](()=>{let d=s,f=e[d(1635)](at,"error",{message:this[d(919)+"rrorMess"+d(1230)](r)});this[d(1228)](e[d(479)],f);let p=e.iZFYc(pt,d(793),{reason:this[d(919)+d(764)+"age"](r)});this[d(1228)](d(793),p)})}[t(1512)+t(1685)](){let r=t,s={pqqgk:"close",zGWZw:function(d,f,p){return e[F(1637)](d,f,p)},qYuFc:r(1509),lrBnv:"error",VLdKZ:function(d,f,p){return e[r(683)](d,f,p)}};this[r(623)][r(908)](d=>{let f=r;this.emit(e[f(915)],e[f(1405)](cd,e.aTZRk,{...d,data:d.errMsg||""}))}),this[r(623)].onClose(d=>{let f=r;this[f(1228)](s[f(526)],s.zGWZw(pt,s[f(526)],{...d}))}),this[r(623)].onMessage(d=>{let f=r;this[f(1228)](s[f(574)],ad(s[f(574)],{...d}))}),this[r(623)][r(902)](d=>{let f=r;this[f(1228)](s.lrBnv,s[f(1851)](at,s[f(1580)],{...d,message:d[f(1249)]||""}))})}send(r){let s=t,d={yyzcN:e[s(479)],mwlrl:function(f,p,E){return e[s(1689)](f,p,E)},wCjpC:function(f,p){return f||p},BtOpN:function(f,p){return e[s(1708)](f,p)},LcYjz:e[s(1756)],QGjmR:function(f,p){return e[s(1763)](f,p)}};if(e[s(1223)](r,Uint8Array)){let f=r[s(1482)][s(1269)](r[s(1871)+"et"],r[s(1199)+"th"]+r[s(1871)+"et"]);this[s(623)]&&this._socket[s(1633)]({data:f,fail:p=>{let E=s;this.emit(d[E(1641)],d[E(692)](at,d[E(1641)],{message:this["_formatE"+E(764)+E(1230)](p)}))}})}else this._socket&&this[s(623)][s(1633)]({data:r,fail:f=>{let p=s;if(e[p(1315)]!==e.CGMwL)this.emit(p(1069),e.nSKPT(at,p(1069),{message:this["_formatE"+p(764)+p(1230)](f)}));else{let{url:E}=d[p(1723)](_0x1f3845,{}),b=_0x5866ce[p(503)](E)?E:d.BtOpN(d[p(1063)],typeof E)?[E]:[];_0xbce2e7&&_0x597441[p(853)](this[p(940)],_0x3de68f),b&&b[p(713)]?this[p(1465)+p(795)]=new _0x1fc265(b,this[p(940)][p(501)+"es"]):this[p(1465)+p(795)]?.[p(654)+p(1326)+p(852)](),this[p(1283)+p(1356)]?.[p(1920)+"nter"](this[p(940)][p(1313)+"Count"]),this[p(945)+p(1429)]=!1,this[p(1702)]&&d.QGjmR(this[p(1702)][p(1497)+"te"],this[p(659)])?this[p(863)+p(1447)](1e3,"manual r"+p(1059)+p(1190),!0):(this[p(1645)]=!0,this[p(1337)]())}}})}[t(793)](r,s){let d=t;this[d(623)]&&this._socket[d(793)]({code:r,reason:s})}[t(1205)+t(1462)](r,s){this.on(r,s)}["removeEv"+t(1625)+t(1420)](r,s){this[t(584)](r,s)}get[t(1497)+"te"](){let r=t;return this[r(623)][r(1497)+"te"]}get[t(942)+"pe"](){let r=t;if(e.RMIZe!==e[r(1265)])return this._socket[r(942)+"pe"];this[r(1710)+"er"]&&_0x49b5fc["addEvent"+r(1462)](r(587),this[r(1448)+r(1824)]),this[r(1710)+"er"]&&_0x269c62[r(1205)+r(1462)](e[r(617)],this[r(1448)+r(974)]),this._isBrowser&&_0x5e7221[r(1205)+"Listener"](r(569),this[r(1594)+r(572)]),this[r(1710)+"er"]&&_0xcfa7d8["addEvent"+r(1462)](e[r(1363)],this[r(1594)+"ageShow"])}set[t(942)+"pe"](r){}get[t(1946)](){return this[t(623)].url}get[t(909)](){return this[t(623)].protocol}get[t(1394)+"ns"](){let r=t,s={qSEQU:function(d,f){return e.zEvpK(d,f)}};if(e[r(1393)](e.WDXBR,e[r(1188)])){let d=this[r(1937)].getItem(this[r(1525)]),f=_0x2984f0[r(1256)](s[r(1837)](d,"{}"));return _0x34bf53.keys(f)}else return this[r(623)][r(1394)+"ns"]}get[t(770)+t(1239)](){return 0}}function Bp(a,r){let s=t;if(r)return new r(a[s(1946)],a[s(909)]);if(e[s(1903)](Yr,Cn))return new Mp(a[s(1946)],a[s(909)],a[s(1018)]);if((nr||Xr)&&e[s(1649)](e[s(1349)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(1946)],a[s(909)+"s"])}function Fp(a){let r=t,s=e[r(739)].split("|"),d=0;for(;;){switch(s[d++]){case"0":if(a)return!0;continue;case"1":if(Cn&&tt[r(937)+r(609)])return!0;continue;case"2":if(Yr&&wx[r(937)+r(609)])return!0;continue;case"3":if((nr||Xr)&&e[r(1740)](e[r(1349)],typeof WebSocket)&&WebSocket)return!0;continue;case"4":return!1}break}}function dd(a,r,s){let d=t,f={CkASL:function(p,E){return e[F(1727)](p,E)},IyFVf:e[d(1907)],KNtfp:function(p,E){return p===E},vJedP:function(p,E){return e.HsGKx(p,E)}};if(e.OWWYT(e[d(1047)],e[d(1908)])){let p=-1;async function E(b){let g=d;return f[g(781)](b,p)?Promise[g(640)](new Error(f[g(1684)])):(p=b,f[g(922)](b,s[g(713)])?Promise.resolve():s[b][g(643)](a)(r,E[g(643)](null,f.vJedP(b,1))))}e[d(480)](E,0)}else return this[d(1236)+d(500)]==this[d(886)+"s"][d(713)]?!0:e[d(1718)](this["currentE"+d(1749)+d(1027)+"t"],this[d(501)+"es"])}function ud(a){let r=t,s=0,d=0;for(let f=0;f<a.length;++f)d=a[r(1458)+"At"](f),d<128?s+=1:e[r(1416)](d,2048)?s+=2:e[r(1393)](e[r(1091)](64512,d),55296)&&e[r(1781)](e[r(1213)](64512,a[r(1458)+"At"](e[r(625)](f,1))),56320)?(++f,s+=4):s+=3;return s}function fd(a,r,s){let d=t;if(d(510)!==e[d(1054)])return this[d(623)][d(942)+"pe"];{if(e[d(1189)](s,r)<1)return"";let f="";for(let p=r;p<s;){let E=a[p++];if(e.cXmBJ(E,127))f+=String[d(973)+d(612)](E);else if(e.ceAcS(E,192)&&e.SalTQ(E,224))f+=String[d(973)+d(612)](e[d(821)](e[d(571)](e[d(1396)](31,E),6),63&a[p++]));else if(e[d(691)](E,224)&&e[d(1329)](E,240))f+=String[d(973)+d(612)](e[d(1377)](e[d(1812)](e[d(1100)](e.Bchza(15,E),12),e[d(1319)](e[d(1244)](63,a[p++]),6)),e.IaVms(63,a[p++])));else if(E>=240){let b=e[d(1322)](e[d(1828)](e[d(776)](e[d(927)](7,E),18)|e.KbgZm(e.CdGtn(63,a[p++]),12),e[d(1080)](e[d(912)](63,a[p++]),6)),e[d(1793)](63,a[p++]))-65536;f+=String[d(973)+d(612)](55296+(b>>10)),f+=String[d(973)+d(612)](e[d(1934)](56320,1023&b))}}return f}}function ha(a,r,s){let d=t,f=s,p,E;for(let b=0;e[d(787)](b,a[d(713)]);++b)if(p=a[d(1458)+"At"](b),e[d(1716)](p,128))r[s++]=p;else if(e[d(780)](p,2048))r[s++]=e.KTYBV(e[d(1103)](p,6),192),r[s++]=e[d(1755)](e.zbzOP(63,p),128);else if((64512&p)===55296&&e[d(608)](64512&(E=a.charCodeAt(e[d(1557)](b,1))),56320)){let g=e.FiMSJ[d(1600)]("|"),k=0;for(;;){switch(g[k++]){case"0":r[s++]=e[d(1882)](p,12)&63|128;continue;case"1":p=65536+(e[d(1875)](1023,p)<<10)+e[d(1036)](1023,E);continue;case"2":r[s++]=e.kPNZK(e[d(1843)](63,p),128);continue;case"3":r[s++]=e[d(1722)](p>>18,240);continue;case"4":++b;continue;case"5":r[s++]=e.UppKd(e[d(894)](p>>6,63),128);continue}break}}else r[s++]=e[d(1617)](e[d(1103)](p,12),224),r[s++]=e[d(763)](e[d(1541)](p,6),63)|128,r[s++]=e.aHPXP(e[d(582)](63,p),128);return e.NFuvw(s,f)}async function hd(a){let r=t;if(e[r(1343)](r(639),typeof a)){let s=new Uint8Array(e[r(1402)](ud,a));return ha(a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[r(1482)],a[r(1871)+"et"],a[r(1199)+"th"])}function zp(a){let r=t;try{return e[r(1952)](e.LoWGn,typeof a)&&(a instanceof ArrayBuffer||a[r(1482)]&&e[r(1242)](a[r(1482)],ArrayBuffer))||e[r(1756)]!=typeof a?"":(JSON[r(1256)](a),e[r(1162)])}catch{return e[r(1142)](e[r(1756)],typeof a)?e[r(1917)]:""}}let Up=(a,r)=>{let s=t;switch(a){case e.hCXdb:case e[s(595)]:return{[s(1151)+a]:1,"x-tt-env":r};default:return{}}};class Gp{constructor(r){let s=t,d={vjTni:function(f,p){return f>=p},cMyqE:function(f,p){return f<=p},qrLuL:function(f,p){return e.TNzDF(f,p)},VxNhZ:function(f,p){return e[F(1056)](f,p)},LUAcC:function(f,p){return e[F(868)](f,p)},uVKsU:function(f,p){return e[F(1652)](f,p)},dSOtT:function(f,p){return e[F(1807)](f,p)}};if(e[s(1066)]===e.JptGJ){if(_0x582509(_0x23cd86))return _0x1a12c9?_0x349daf:_0x37cfb9;if(_0xe9896){if(TGWypU[s(1432)](_0x23c308,_0x395e19))return _0xf74643}else{if(TGWypU.cMyqE(_0x1dd979,-_0x525325))return _0x5c8218;if(TGWypU.qrLuL(TGWypU[s(551)](_0x5850a2,1),_0x16933e))return _0x320efa}return _0xe95bb5[s(552)](TGWypU[s(1786)](TGWypU.uVKsU(_0xacfa05,_0x517fe7),0),TGWypU[s(517)](_0x52c8b6/_0x1ca65c,0),_0x4e5aaf)}else this["maxLossC"+s(1470)]=r,this[s(1433)]=0}[t(1092)](){let r=t,s={mXFZQ:function(d,f,p){return d(f,p)}};e[r(1215)](r(1677),e[r(1065)])?this[r(1433)]++:(_0x58e90d(_0xd02e3c,96),zWDVxG[r(686)](_0xc51ed3,_0x1393cc,_0x3b464b(_0x58e09f)))}[t(1341)+t(1174)+"nt"](){let r=t;return this.count>=this[r(1911)+"ount"]}["resetCou"+t(1673)](r=0){let s=t;this[s(1911)+"ount"]=r,this[s(1433)]=0}}async function qp(a){let r=t,s={sXntc:function(d,f){return e[F(1706)](d,f)},ytQXc:e[r(1016)],MKqHe:e[r(626)],PRzRJ:e[r(1743)],eVusg:function(d,f){return e.GPIXe(d,f)},zmHQZ:function(d,f){return e[r(1024)](d,f)},zIpHq:function(d,f){return d===f},IYmCw:function(d,f){return d>>>f},qLkse:function(d,f){return e.cCxje(d,f)},GXqlf:function(d,f){return e[r(1863)](d,f)}};return e.BlXuJ(e.YXqAv,e[r(1858)])?new Promise(d=>{let f=r,p={aogPR:function(E,b){return s[F(701)](E,b)},QcIVo:s[f(1087)]};if(!nr)return s[f(701)](d,s[f(1087)]);try{let E=document["createEl"+f(1330)]("script");window[f(599)+"JSONP"]=b=>{let g=f;document[g(1697)][g(933)+g(1861)](E),window["frontier"+g(1125)]=void 0,p[g(1826)](d,b&&b[g(1490)]||p[g(1476)])},E[f(955)]=s.MKqHe,E[f(1583)]=a[f(522)](/^ws/,s[f(771)])+(f(736)+f(804)+f(1883)+"P");try{document[f(1697)][f(1783)+f(1861)](E)}catch{document[f(1697)][f(933)+f(1861)](E)}}catch{window[f(599)+f(1125)]=void 0,s[f(805)](d,s[f(1087)])}}):(_0x33560d.isLong(_0x271f31)||(_0x346da2=_0x12d7fc[r(1306)+"er"](_0x1f0926)),AYEbwg.zmHQZ(this[r(1631)],_0xfca259[r(1631)])&&AYEbwg.zIpHq(AYEbwg.IYmCw(this[r(924)],31),1)&&AYEbwg[r(516)](AYEbwg.IYmCw(_0x40ab26.high,31),1)?!1:AYEbwg[r(896)](this.high,_0x345bf8[r(924)])&&AYEbwg.GXqlf(this[r(1474)],_0x4a02c0.low))}function rn(a,r,s){let d=t;return!!a?.[d(1051)](f=>f[d(747)]===r&&f.value===s)}function rr(a,r){let s=t,d={sUCXZ:function(f,p){return f>>>p},NHzdG:function(f,p){return e[F(892)](f,p)},BkhTU:function(f,p){return e[F(635)](f,p)},ZklYH:function(f,p){return e.zxXyQ(f,p)},gVfrN:function(f,p){return e[F(680)](f,p)},MZCZI:function(f,p){return e.suBYQ(f,p)},LjJpG:function(f,p){return f&p},AbzXt:function(f,p){return f<<p}};if(e[s(600)](s(1109),e[s(1945)])){let f={ssrqp:function(E,b){return d.sUCXZ(E,b)},DhetC:function(E,b){return d[s(936)](E,b)},fPESb:function(E,b){return d[s(1855)](E,b)},eSeoo:function(E,b){return d[s(1161)](E,b)},NLIQS:function(E,b){return d[s(1197)](E,b)},BBlCX:function(E,b){return d[s(1184)](E,b)},jjQmI:function(E,b){return d[s(1855)](E,b)},cOcjU:function(E,b){return d[s(1184)](E,b)},cfzeu:function(E,b){return d[s(766)](E,b)},klbPu:function(E,b){return d[s(1855)](E,b)},hNdul:function(E,b){return d.AbzXt(E,b)},czmPA:function(E,b){return d[s(1184)](E,b)},VgyIH:function(E,b){return d[s(1184)](E,b)},FvARk:function(E,b){return E&b},QYjii:function(E,b){return E>b}},p=4294967295;return function(E,b,g=!0){let k=s;if(p=f.ssrqp(127&E[b],0),f.DhetC(E[b++],128))return{value:g?p:0|p,offset:b};if(p=f[k(1133)](p|f[k(993)](f[k(969)](127,E[b]),7),0),f[k(1010)](E[b++],128))return{value:g?p:f.BBlCX(0,p),offset:b};if(p=f[k(859)](f[k(1839)](p,f[k(1735)](127,E[b])<<14),0),E[b++]<128)return{value:g?p:f[k(1839)](0,p),offset:b};if(p=f[k(1799)](f[k(822)](p,f[k(1493)](127&E[b],21)),0),E[b++]<128)return{value:g?p:f[k(1862)](0,p),offset:b};if(p=f[k(1799)](f[k(1258)](p,f[k(1078)](15,E[b])<<28),0),E[b++]<128)return{value:g?p:f[k(1839)](0,p),offset:b};if(f[k(603)](b+=5,E.length))throw b=E[k(713)],_0x143950(b,10,E[k(713)]);return{value:g?p:f[k(1839)](0,p),offset:b}}}else return a?.[s(1051)](f=>f[s(747)]===r)?.[s(1026)]}let xa=null;async function Hp(){let a=t;if(e[a(1413)](a(1412),e[a(963)]))return xa||(xa=Promise[a(1762)]()[a(1477)](Mt[a(643)](Mt,e[a(1539)]))),xa;_0xad8a1b[_0x1d4e17++]=e[a(1467)](e.xzrkH(_0xa0649c,12),224),_0x1ea3e5[_0x222582++]=e[a(1232)](e.qtZiJ(e[a(742)](_0x42a2ff,6),63),128),_0x45f10f[_0x566d56++]=e[a(848)](63&_0x40b018,128)}class jp extends fa{constructor(r,s){let d=t;super(),this[d(1250)]=r,this[d(1488)]=s,this._qosDB=void 0,this[d(1227)+"mise"]=null}async[t(1274)](){let r=t;if(e[r(1526)]!==e[r(718)])await this[r(1734)]();else{if(_0x3f479d)return new _0x5db87b(_0x5bd5c5.url,_0x4d1d09.protocol);if(_0x5bf9b9||_0x308572)return new _0x20b7be(_0x2d33ca[r(1946)],_0x1f001f[r(909)],_0x891f48[r(1018)]);if((_0x2eeb75||_0x259ecf)&&e.dZScb(e[r(1349)],typeof _0x2722b8)&&_0x2bd8d6)return new _0x26710b(_0x553015[r(1946)],_0x212aa1[r(909)+"s"])}}async _init(){let r=t;if(!this[r(1937)]){if(this["_initPro"+r(1084)])return this[r(1227)+r(1084)];try{let s=this[r(1250)],d=this[r(1488)];this[r(1227)+r(1084)]=(async()=>{let f=r,{openDB:p}=await e.KcgYi(Hp);this[f(1937)]=await p(f(599)+"_"+s,1,{upgrade(E){let b=f;E[b(1595)+b(1117)+"e"](s,{keyPath:d})}})})(),await this._initPromise}catch(s){console.log(s)}finally{this[r(1227)+r(1084)]=null}}}async get(r){let s=t;try{return await this._init(),this[s(1937)]?.[s(835)](this._dbName,r)}catch(d){console[s(858)](d)}}async[t(962)](r,s){let d=t;return await this._init(),this[d(1937)]?.[d(883)](this[d(1250)],r)}async[t(1453)](r){let s=t;if(e[s(1191)](e.vXjcV,"ICRRj"))this[s(1149)+"T"]?_0x4b208a[s(1527)+s(1126)+s(1936)](({isConnected:d})=>{let f=s;this[f(1942)+"igatorOn"+f(1607)]=d,d?this[f(1448)+f(1824)]():this[f(1448)+f(974)]()}):this[s(1545)+"X"]&&_0x44c9a2[s(1527)+s(1126)+s(1936)](({isConnected:d})=>{let f=s;this[f(1942)+"igatorOn"+f(1607)]=d,d?this["_handleO"+f(1824)]():this[f(1448)+"ffLine"]()});else try{return await this[s(1734)](),this[s(1937)]?.[s(1491)](this[s(1250)],r)}catch(d){console[s(858)](d)}}async[t(1554)](){let r=t;try{return await this[r(1734)](),this[r(1937)]?.[r(1554)](this[r(1250)])}catch(s){console[r(858)](s)}}async keys(){let r=t;return await this[r(1734)](),this[r(1937)]?.[r(562)+"ys"](this[r(1250)])}async[t(1325)](){let r=t;return e.mbSds===e.zdyoX?this._socket[r(1946)]:(await this[r(1734)](),this[r(1937)]?.[r(1325)](this[r(1250)]))}async[t(1002)](){let r=t;try{this[r(1937)]?.[r(793)](),this[r(1937)]=void 0}catch(s){console[r(858)](s)}}get[t(1443)](){let r=t,s={PcexA:function(d,f){return d(f)},MYMaW:function(d,f){return e[F(1843)](d,f)},cjwvc:function(d,f){return d&f}};try{return!!this[r(1937)]}catch(d){if(e.aDiZl(e[r(1359)],e[r(1373)]))_0x209011=tGoZXy[r(1276)](_0x3f33a9,_0x78f8ef),_0x2f1747=tGoZXy.MYMaW(127,_0x151423),tGoZXy.cjwvc(128,_0x56bf3e)&&(_0x50dbbe=tGoZXy[r(1276)](_0x2dbd22,_0x38a988),_0x4033c8|=tGoZXy.cjwvc(127,_0x428e71)<<7);else return console[r(858)](d),!1}}}class Wp{constructor(r,s){let d=t;this._DBName=r,this[d(1576)]=s,this._qosDB=localStorage}async[t(1274)](){}get _prefix(){let r=t;return r(599)+"_"+this[r(761)]}async[t(835)](r){let s=t,d=this[s(1937)].getItem(this[s(1525)]);return JSON[s(1256)](d||"{}")[r]}async set(r,s){let d=t,f=this[d(1937)].getItem(this._prefix),p=JSON[d(1256)](e[d(502)](f,"{}"));return p[s||r[this[d(1576)]]]=r,this[d(1937)][d(611)](this[d(1525)],JSON[d(762)+"y"](p)),s||r[this[d(1576)]]}async[t(1453)](r){let s=t,d=this[s(1937)][s(731)](this[s(1525)]),f=JSON[s(1256)](e[s(502)](d,"{}"));return f[r]=void 0,this[s(1937)].setItem(this[s(1525)],JSON.stringify(f))}async[t(1554)](){let r=t;return this[r(1937)][r(1554)]()}async keys(){let r=t,s=this[r(1937)][r(731)](this[r(1525)]),d=JSON.parse(e[r(502)](s,"{}"));return Object[r(594)](d)}async getAll(){let r=t,s=this[r(1937)][r(731)](this._prefix),d=JSON.parse(s||"{}");return Object[r(841)](d)}[t(1002)](){return Promise[t(1762)]()}get[t(1443)](){let r=t,s={Jtbon:function(d,f){return e[F(1806)](d,f)},ArydJ:function(d){return e[F(1696)](d)}};if(e.rwCQm("NtBew",e[r(1616)]))return!!this[r(1937)];VRPZsO.Jtbon(_0x572af2,_0x36597a[r(1069)]),VRPZsO[r(1500)](_0x5de91c)}}class Kp{constructor(r,s){let d=t;if(e[d(712)](e.cFgEx,e[d(1081)]))this[d(761)]=r,this[d(1576)]=s,this[d(1937)]=Cn?tt:Yr?wx:null;else return}async[t(1274)](){}get[t(1525)](){let r=t;return r(599)+"_"+this[r(761)]}async[t(835)](r){let s=t,d={KgnTC:e[s(1756)],frILa:e[s(1917)]};if(e[s(1947)](e.fRzwi,s(785))){let f=this[s(1937)]["getStora"+s(538)](this[s(1525)]);return JSON[s(1256)](e[s(875)](f,"{}"))[r]}else return ajjvkl.KgnTC==typeof _0x1afbd8?ajjvkl.frILa:""}async[t(962)](r,s){let d=t,f=this[d(1937)][d(579)+"geSync"](this._prefix),p=JSON[d(1256)](e[d(1469)](f,"{}"));return p[s||r[this._pathKey]]=r,this._qosDB["setStora"+d(538)](this[d(1525)],JSON[d(762)+"y"](p)),s||r[this[d(1576)]]}async del(r){let s=t,d=this[s(1937)][s(579)+"geSync"](this._prefix),f=JSON.parse(e[s(1903)](d,"{}"));return f[r]=void 0,this[s(1937)].setStorageSync(this[s(1525)],JSON[s(762)+"y"](f))}async clear(){let r=t;return this[r(1937)][r(968)+r(1653)]()}async[t(594)](){let r=t,s=this[r(1937)].getStorageInfoSync(this._prefix),d=JSON[r(1256)](e.OsHEJ(s,"{}"));return Object[r(594)](d)}async[t(1325)](){let r=t;if(e[r(616)](e[r(1019)],e.ZJyvU))e[r(1441)](_0x2f036b,_0x40d05a,18),e[r(699)](_0x487b78,_0x9948e2,_0x454b58);else{let s=this[r(1937)][r(579)+r(546)+"nc"](this[r(1525)]),d=JSON[r(1256)](s||"{}");return Object[r(841)](d)}}[t(1002)](){return Promise[t(1762)]()}get isReady(){return!!this[t(1937)]}}function xd(a,r){let s=t;if(e[s(875)](Cn,Cn))return new Kp(a,r);if(e[s(1815)](nr,Xr)&&e[s(1649)]("undefined",typeof indexedDB))return new jp(a,r);if(e[s(502)](nr,Xr)&&e.dZScb(e[s(1349)],typeof localStorage))return new Wp(a,r);throw new Error(e[s(1181)])}class $p{constructor(){let r=t;if(e[r(1711)](e[r(710)],"USXgt"))return new _0x2fced7(_0x10180f,{data:_0x496197});this[r(1515)+r(1499)+"Id"]=null,this._interval=36e5,this[r(1937)]=e[r(1905)](xd,e.iJAdp,"message_id")}async[t(1515)+t(645)](){let r=t,s={hNMMD:function(d,f){return e[F(1223)](d,f)},OwMSs:e.ULOSW,LOeuE:e.IjEza,iGdjn:e.LoWGn,UkGOo:e[r(1287)],AocWu:function(d,f,p,E){return e[r(1719)](d,f,p,E)},HbNjU:e[r(1112)]};e[r(1172)](clearInterval,this["_interva"+r(1499)+"Id"]),this[r(1515)+r(1499)+"Id"]=e[r(1336)](setInterval,()=>{let d=r;if(s[d(1748)]!==s.HbNjU){let f=this._options["payloadE"+d(1156)]instanceof _0x4afadc?{force:!!this[d(940)]["payloadE"+d(1156)][d(952)],encoding:this._options[d(1573)+"ncoding"][d(1766)]?this[d(940)][d(1573)+"ncoding"][d(1766)][d(522)](/\s/g,"")[d(901)+d(831)]():""}:{force:!1,encoding:this[d(940)]["payloadE"+d(1156)]?this[d(940)][d(1573)+d(1156)][d(522)](/\s/g,"")[d(901)+d(831)]():""},p=_0x37ac70[d(1573)+"ncoding"]?_0x277b88[d(1573)+d(1156)].replace(/\s/g,"")[d(901)+d(831)]():"",E=s[d(1067)](this._options[d(832)+d(1431)],_0x1be868)?{force:!!this[d(940)].payloadType[d(952)],type:this[d(940)][d(832)+d(1431)][d(955)]?this[d(940)].payloadType[d(955)][d(522)](/\s/g,"")[d(901)+d(831)]():""}:{force:!1,type:this[d(940)]["payloadT"+d(1431)]?this._options[d(832)+d(1431)][d(522)](/\s/g,"")[d(901)+d(831)]():""},b=_0x45d4d4[d(832)+d(1431)]?_0x5c342e[d(832)+d(1431)][d(522)](/\s/g,"")[d(901)+d(831)]():"",g=E[d(952)]?E.type:b||E[d(955)],k=f.force?f[d(1766)]:p||f[d(1766)],N=[s[d(1933)],s.LOeuE,d(527)+d(1505)+d(1516)+d(1655),s.iGdjn],B=[d(1501)+"e",s[d(1567)]];this._options["enableTr"+d(655)+"extPayload"]&&N[d(1486)](g)&&(!k||B[d(1486)](k))?_0x29125a["textPayl"+d(1146)]=s[d(1046)](_0x191cdf,_0xac68f7.payload,0,_0x52db37[d(624)][d(1199)+"th"]):_0x1b77bf[d(1252)+d(1146)]=""}else this[d(948)+d(1508)]()},this[r(1515)+"l"])}async[t(1274)](){await this._qosDB.openDB().then(()=>{let r=F;this[r(1515)+r(645)]()})}async["flushExp"+t(1508)](){let r=t;(await this[r(1937)]?.[r(1325)]()||[])[r(1308)](({timestamp:f})=>f<Date.now())[r(1357)](f=>{let p=r;this._qosDB?.[p(1453)](f[p(1502)+"id"])})}async[t(1453)](r){let s=t;return this[s(1937)]?.[s(1453)](r)}async set(r,s){return this[t(1937)]?.set({message_id:r,timestamp:s})}async[t(835)](r){let s=t;return this[s(1937)]?.[s(835)](r)}async[t(1002)](){let r=t;e.swXIZ!==r(971)?(e.zJlEJ(clearInterval,this[r(1515)+"lTimeoutId"]),await this[r(1937)]?.[r(1002)]()):(this[r(1702)]&&this[r(1702)][r(1633)](_0x363e57),this[r(1612)](e[r(893)],_0x2fb62b))}get[t(1443)](){return this[t(1937)]?.isReady}}function pa(a){let r=t,s=!!this._options.enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[r(1753)](rn,a[r(1509)][r(1018)],e[r(935)],"2"),f=d&&rn(a[r(1509)][r(1018)],e[r(1951)],"1"),p=d&&e[r(492)](rn,a[r(1509)][r(1018)],e[r(507)],"1"),E=p?rr(a[r(1509)][r(1018)],e.GQLXp)?.split(",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:p,ackMsgIds:E}}async function pd(){let a=t;return this[a(1208)+a(1627)]||(this[a(1208)+a(1627)]=new $p),this[a(1208)+a(1627)][a(1443)]||await this[a(1208)+a(1627)][a(1274)](),this[a(1208)+a(1627)]}async function Vp(a,r){let s=t,{enableAutoAck:d}=this._options,f=e[s(1881)](rn,a[s(1509)][s(1018)],"need_ack","1"),p=e[s(1881)](rn,a[s(1509)][s(1018)],e[s(707)],"1"),E=pa[s(596)](this,a);if(d&&f){let{SeqID:b,LogID:g,service:k,LogIDNew:N,method:B}=a[s(1509)];this[s(1574)]({SeqID:b,LogID:g,LogIDNew:N,service:k,method:B,headers:[{key:s(759),value:"1"},{key:e.DSFNk,value:N||""},{key:e[s(1665)],value:"0"}]})}p&&!E[s(1221)]&&this[s(1327)+s(1093)+s(1480)](a),e.KcgYi(r)}async function Zp(a,r){let s=t;this._debug(s(1395),a[s(1509)]),e[s(1696)](r)}async function Jp(a,r){let s=t,d=e[s(722)](en,await e[s(480)](hd,a[s(882)]));try{if(e[s(1646)](e[s(1870)],e[s(1870)]))if(d[s(624)]instanceof Uint8Array){let f=e[s(1242)](this[s(940)][s(1573)+s(1156)],Object)?{force:!!this[s(940)]["payloadE"+s(1156)][s(952)],encoding:this._options[s(1573)+"ncoding"].encoding?this[s(940)][s(1573)+s(1156)].encoding[s(522)](/\s/g,"")[s(901)+s(831)]():""}:{force:!1,encoding:this._options["payloadE"+s(1156)]?this[s(940)][s(1573)+"ncoding"][s(522)](/\s/g,"")[s(901)+s(831)]():""},p=d[s(1573)+s(1156)]?d[s(1573)+s(1156)][s(522)](/\s/g,"")[s(901)+s(831)]():"",E=e.qJerb(this[s(940)][s(832)+s(1431)],Object)?{force:!!this[s(940)][s(832)+s(1431)][s(952)],type:this[s(940)][s(832)+s(1431)][s(955)]?this[s(940)]["payloadT"+s(1431)][s(955)][s(522)](/\s/g,"")[s(901)+s(831)]():""}:{force:!1,type:this[s(940)][s(832)+s(1431)]?this[s(940)][s(832)+s(1431)][s(522)](/\s/g,"")[s(901)+s(831)]():""},b=d[s(832)+"ype"]?d[s(832)+s(1431)].replace(/\s/g,"")[s(901)+"ase"]():"",g=E[s(952)]?E[s(955)]:b||E[s(955)],k=f[s(952)]?f[s(1766)]:p||f[s(1766)],N=[e[s(1917)],e.IjEza,e[s(716)],e[s(1756)]],B=[e[s(1288)],e[s(1287)]];this[s(940)][s(1701)+s(655)+s(1271)+"ad"]&&N.includes(g)&&(!k||B[s(1486)](k))?d[s(1252)+"oad"]=e[s(644)](fd,d[s(624)],0,d[s(624)][s(1199)+"th"]):d["textPayl"+s(1146)]=""}else d[s(1252)+s(1146)]="";else{let f=_0x48d79f[s(1364)]();return f?(f.offset=f[s(641)]=0,f):{bytes:new _0x1fadfd(64),offset:0,limit:0}}}catch(f){if(e[s(1215)](e[s(1912)],e[s(1410)])){if(e[s(1415)](_0x12f3e5,1)||e[s(1485)](_0x33dca2,_0x3dd943))return e[s(480)](_0x129008,_0x3ea52f);e[s(1495)](e[s(1606)](_0x535a53,_0x4e8745),_0x14e31d)&&(_0x3ed387=e.OABSW(_0x52bd78,_0xae8d49),_0x1f3eb4=0);let p=_0x194fbe.call(_0x3dbaa2,_0x506e24,_0x30fc53+=_0x514972);return e[s(1659)](7,_0x213e8b)&&(_0x2cefe8=e[s(914)](e[s(1869)](7,_0x143363),1)),p}else d[s(1252)+s(1146)]="",console.log(f)}a[s(1509)]=d,e[s(965)](r)}function Yp(a,r,s){let d={rMNMI:function(g,k){return e[F(787)](g,k)},reBnu:function(g,k){return g(k)},glyQM:function(g,k){return e[F(1495)](g,k)},hBnyw:function(g,k){return e[F(1037)](g,k)},nDXql:function(g,k){return e[F(582)](g,k)},pTgwi:function(g,k){return e[F(741)](g,k)},VOQLo:function(g,k){return e[F(1675)](g,k)}},f=s||8192,p=f>>>1,E=null,b=f;return function(g){let k=F;if(d[k(801)](g,1)||g>p)return d[k(1663)](a,g);d[k(1430)](b+g,f)&&(E=d[k(1219)](a,f),b=0);let N=r[k(596)](E,b,b+=g);return d[k(1720)](7,b)&&(b=d.pTgwi(d[k(1110)](7,b),1)),N}}let Xp=4294967295;function Qp(a,r,s){let d=t;return e[d(602)](RangeError,e[d(531)](e[d(1915)](e[d(1113)](e[d(1667)](e[d(1886)](e[d(1421)],a),e[d(899)]),e[d(1469)](r,1)),e[d(483)]),s))}function eg(a,r,s){let d=t;if(e[d(1485)](s,Xp))throw new Error(e[d(1436)]);let f=3;for(;e.BrBoK(f,0);){let p=255&s;e[d(815)](ma,p,a,r+f),s>>>=8,f--}return e[d(1857)](r,4)}function tg(a,r){let s=0,d=r,f=r+4;for(;e.fuJnV(d,f);){let{value:p,offset:E}=ga(a,d);d=E,s=e.pvpBv(s<<8,0),s+=p}return{value:s,offset:f}}function ng(a,r,s){let d=t;return a?e[d(664)](a[d(713)],40)?e.APyyG(e[d(492)](ha,a,r,s),s):r.utf8Write?e[d(840)](r[d(1948)+"e"](a,s),s):r[d(1666)]?e[d(964)](r[d(1666)](a,s),s):e.eXpgj(ha(a,r,s),s):s}function rg(a,r){let s=t,d=new fe(e[s(1332)](e.KTYBV(e.eFBgD(a[e.QWFLE(r,4)],24),e.zxXyQ(a[r+5],16)),e.JbHhx(a[r+6],8))|a[r+7],e.kitfJ(e.kPNZK(e[s(738)](e[s(1558)](a[r+0],24),e[s(1119)](a[e[s(964)](r,1)],16)),e[s(621)](a[e[s(1113)](r,2)],8)),a[r+3]),!0);return r+=8,{value:d,offset:e[s(1532)](r,8)}}function ig(a,r,s){let d=t,f=a[d(1474)],p=a.high;return r[s]=e[d(635)](p,24),r[e[d(744)](s,1)]=e.RLCIQ(p>>>16,255),r[e[d(944)](s,2)]=e[d(1761)](p,8)&255,r[e[d(1889)](s,3)]=e[d(1875)](255,p),r[e[d(888)](s,4)]=e.NXebj(f,24),r[s+5]=e.SYeLZ(e[d(1804)](f,16),255),r[e[d(1030)](s,6)]=e.EqoIU(f,8)&255,r[e[d(1450)](s,7)]=e[d(680)](255,f),s+=8,s}function ga(a,r){let s=t;return a[s(1757)+"8"]?{value:a.readUInt8(r),offset:e[s(1667)](r,1)}:{value:e[s(1262)](255,a[r]),offset:e[s(818)](r,1)}}function ma(a,r,s){let d=t;return r[d(1620)+"t8"]?r[d(1620)+"t8"](a,s):r[s]=e[d(1192)](255,a),s+1}let sg=function(a){return new Uint8Array(a)},og=e[t(1759)](e.BmgZm,typeof Buffer)?Buffer["allocUns"+t(865)]:e[t(1884)](Yp,sg,Uint8Array.prototype[t(986)]),ag=16,wa=32;function cg(a){let r=t,s={VRqta:function(d,f){return e.NmkTQ(d,f)},eCxBz:function(d,f){return e[F(808)](d,f)},KzQNk:function(d,f){return e[F(532)](d,f)},UyCZj:function(d,f){return e.AkviC(d,f)},LsXCL:function(d,f){return e[F(1362)](d,f)},mhhZq:function(d,f){return d===f},RCiSA:function(d,f){return e[F(1825)](d,f)},twBFy:function(d,f){return d+f},qgZkN:e[r(1398)],sKBoF:function(d,f){return d|f},OSTIO:function(d,f){return e[r(1449)](d,f)},oZoNf:function(d,f){return e[r(929)](d,f)},Tdjza:function(d,f){return e[r(912)](d,f)},TXQQY:function(d,f){return d&f},Gczjz:e[r(617)],nvBDS:e.ZzYGW,evopa:e[r(1363)]};if(e.KWWzr===e[r(1182)])if(_0x3bd9d2=_0x10db74[r(1458)+"At"](_0xc6f09d),ezTOXR.VRqta(_0x44554b,128))_0x2f63a8[_0x31701f++]=_0x4cab01;else if(ezTOXR.eCxBz(_0x27a192,2048))_0x461d9f[_0x2d0e57++]=ezTOXR.KzQNk(ezTOXR[r(1518)](_0x27e19a,6),192),_0x17cee3[_0x4204d5++]=ezTOXR[r(755)](63,_0x24e066)|128;else if(ezTOXR[r(1560)](64512&_0x1fd2c2,55296)&&ezTOXR.mhhZq(ezTOXR[r(1034)](64512,_0x5c351a=_0x3f6de4[r(1458)+"At"](ezTOXR[r(1608)](_0x55e624,1))),56320)){let d=ezTOXR[r(900)].split("|"),f=0;for(;;){switch(d[f++]){case"0":++_0x5efc26;continue;case"1":_0x4f4fb0[_0x2622b2++]=ezTOXR[r(1348)](ezTOXR[r(1518)](_0x5b32af,6)&63,128);continue;case"2":_0x2077a6[_0xdcd41b++]=ezTOXR.UyCZj(_0x2a314b,18)|240;continue;case"3":_0x15e901[_0x1b4ad1++]=ezTOXR.KzQNk(ezTOXR.LsXCL(ezTOXR.UyCZj(_0x114133,12),63),128);continue;case"4":_0x462807[_0x3c4817++]=ezTOXR[r(1140)](ezTOXR[r(755)](63,_0x5b9341),128);continue;case"5":_0x347d60=ezTOXR[r(1818)](ezTOXR[r(1818)](65536,ezTOXR.LsXCL(1023,_0x4cf681)<<10),ezTOXR[r(755)](1023,_0x3c9134));continue}break}}else _0x46a0bf[_0x376671++]=ezTOXR[r(1089)](_0x1adad4>>12,224),_0x5ac325[_0x3b88b5++]=ezTOXR[r(1506)](_0x45c1c7>>6,63)|128,_0x4079fe[_0x6be7bf++]=ezTOXR[r(1089)](ezTOXR[r(1333)](63,_0x688b),128);else{let d=0,f={};for(let p=0;e[r(620)](p,a[r(713)]);p++)e[r(1388)](e.uXpOB,e[r(1923)])?(f[a[p][r(862)+r(1579)]]=ud(a[p][r(862)+r(1579)]),d+=e[r(1044)](14,f[a[p][r(862)+r(1579)]])):(this[r(1710)+"er"]&&_0xc29229[r(715)+r(1625)+r(1420)]("online",this[r(1448)+r(1824)]),this[r(1710)+"er"]&&_0x3c6843[r(715)+r(1625)+r(1420)](s[r(1577)],this[r(1448)+r(974)]),this._isBrowser&&_0x2083a5[r(715)+r(1625)+r(1420)](s[r(627)],this[r(1594)+r(572)]),this._isBrowser&&_0xecf991["removeEv"+r(1625)+"ner"](s[r(1848)],this["_handleP"+r(1316)]));return[d,f]}}function gd(a,r,s){let d=t,[f,p]=e[d(602)](cg,a),E=e[d(1540)](og,f),b=0;return a.forEach(g=>{let k=d,N={TiKIR:function(B,W){return e[F(625)](B,W)},PuPtJ:k(998)+"d error.",RehIs:function(B,W){return B+W}};if(e[k(608)](e.HIaxC,e.HIaxC))console[k(858)](k(1913)+k(597),g,g[k(991)]),b=ma(0,E,b),console.log(e[k(1885)],b),b=e[k(1777)](eg,E,b,g.service||0),console[k(858)](e.CgbHv,b),b=e[k(1777)](ma,p[g["cursor_n"+k(1579)]],E,b),console.log("service-name",b),b=e[k(1442)](ng,g[k(862)+"ame"],E,b),console[k(858)](e.TCqAV,b),b=e[k(815)](ig,fe[k(1306)+"er"](g[k(767)]||r),E,b),console.log(e[k(880)],b);else{let B=_0x2f11ce[k(713)]&&_0x2806a8[0];if(B instanceof _0x419128)throw B;let W=new _0x59d7f0(MAqVPr[k(693)](MAqVPr.PuPtJ,B?MAqVPr[k(1692)](MAqVPr[k(693)](" (",B.message),")"):""));throw W.context=B,B}}),{frameType:wa,headers:[{key:e[d(895)],value:s}],payload:E}}function lg(a){let r=t,s=0,d=[];for(;e[r(1739)](s,a[r(1199)+"th"]);)if(e[r(1498)](e[r(1122)],e.qFywb)){let{offset:f}=e[r(1224)](ga,a,s);s=f;let p={cursor_name:"",cursor:0,service:0},{value:E,offset:b}=e[r(1921)](tg,a,s);p[r(991)]=E,s=b;let{value:g,offset:k}=e[r(1405)](ga,a,s);s=k,p[r(862)+"ame"]=e.lYpvR(fd,a,s,e[r(1243)](s,g)),s+=g;let{value:N,offset:B}=e[r(1927)](rg,a,s);p.cursor=N[r(1770)](),s=B,d[r(1387)](p)}else{let{offset:f}=e[r(684)](_0x204a4d,_0x31db83,_0x213c39);_0x434d88=f;let p={cursor_name:"",cursor:0,service:0},{value:E,offset:b}=e[r(689)](_0x19914e,_0x559538,_0x1fc3ce);p[r(991)]=E,_0x2fc6db=b;let{value:g,offset:k}=_0x1b11d5(_0x3c3e41,_0x45b73c);_0x151d68=k,p[r(862)+"ame"]=_0x581fcb(_0x3c9b61,_0x27e236,e[r(910)](_0x542a36,g)),_0x31043a+=g;let{value:N,offset:B}=e[r(1750)](_0x1c9a4c,_0x9bd8d5,_0x4cbe90);p[r(767)]=N[r(1770)](),_0x2e5b7a=B,_0x2b75a8[r(1387)](p)}return d}function dg(){let a=t;return{frameType:wa,headers:[{key:e[a(895)],value:e[a(1601)]}],payload:void 0}}class ug{constructor(r,s,d){let f=t;this._cursorNameSpace=r,this["_cursorF"+f(1369)]=s,this[f(1472)+f(857)]=d,this[f(1937)]=e[f(1405)](xd,this[f(1075)+f(662)],e[f(1267)])}async[t(1274)](){let r=t;await this[r(1937)][r(1274)]()}async[t(1411)+"rs"](){let r=t;if(!this[r(1937)].isReady)return;let s=this[r(1472)+r(857)],d=await this._qosDB[r(1325)]();switch(console[r(858)](e[r(672)],d),s){case e.aScHt:return d&&d[r(713)]?gd(d,0,this[r(1298)+r(1369)]):void 0;case e[r(561)]:return;case e[r(926)]:return d&&d[r(713)]?e[r(1881)](gd,d,0,this[r(1298)+r(1369)]):e[r(1714)](dg)}}async[t(962)](r,s,d){let f=t,p={RVrCf:function(E,b,g,k){return e[F(644)](E,b,g,k)}};if(e[f(1542)](e.RXbxg,e[f(484)]))return console[f(858)](f(690),r,s,d),this._qosDB[f(962)]({cursor_name:r,cursor:s,service:d});{let E=new _0x156646(_0x15c521(_0x5a936a));return GvAERw[f(636)](_0x13126b,_0x2daeb5,E,0),E}}async[t(953)+"rs"](r){let s=t,d=e[s(673)](lg,r);for(let f of d)console[s(858)](e[s(1733)],d),await this[s(1937)].set(f)}async[t(835)](r){let s=t;return(await this._qosDB.get(r))?.[s(767)]}async[t(1002)](){let r=t;await this[r(1937)][r(1002)]()}[t(1057)+t(1475)+t(758)](r){let s=t;this[s(1298)+"ileName"]=r}get[t(1443)](){let r=t;return this[r(1937)][r(1443)]}}let fg="__x_msg_"+t(1845);async function md(a){let r=t;if(!this._options[r(1198)+"S"])return null;let{aID:s,fpID:d,messageStrategy:f}=this[r(940)],p=a||fg;try{return e[r(1648)]===r(889)?_0x22accf[r(1414)+r(1765)]||_0x3793a9[r(835)](_0x3545e):(this[r(873)+"anager"]?a&&this[r(873)+r(870)][r(1057)+r(1475)+r(758)](a):this[r(873)+r(870)]=new ug(d+"_"+s+"_"+p,p,f),this[r(873)+r(870)][r(1443)]||await this[r(873)+r(870)][r(1274)](),this[r(873)+r(870)])}catch{return null}}async function hg(a,r){let s=t;if(e[s(600)](e.ooNzb,e[s(1425)])){let d=e[s(815)](rn,a[s(1509)].headers,e[s(1760)],"-1"),f=e[s(1102)](rn,a[s(1509)][s(1018)],e.OusQo,"1"),p=e[s(669)](rr,a[s(1509)][s(1018)],e[s(975)]),E=e[s(954)](Number,e[s(570)](rr,a[s(1509)][s(1018)],e[s(1944)]))||0,b=pa[s(596)](this,a),g=e[s(990)](rn,a.message.headers,s(586)+"s","2"),k=rr(a.message[s(1018)],s(842)+s(782)+"e"),N=e[s(1466)](Number,e[s(733)](rr,a.message[s(1018)],e[s(1259)]));if(b.isQoSAck)return r();let B=b[s(1061)+s(1864)]?await pd[s(596)](this):null;if(a[s(1509)][s(991)]>0&&f&&!d||a[s(1509)][s(991)]>0){if(p&&b[s(1061)+"sage"]&&B)return!!!await B[s(835)](p)&&(this["_dispatc"+s(1052)+s(1803)](a),await B[s(962)](p,e[s(1044)](Date.now(),E))),r();if(g){let W=await md[s(596)](this);if(!W)return this[s(1327)+"hMessage"+s(1803)](a),r();let $=await W[s(835)](k)??-1;if(e[s(1816)]($,N))this[s(1327)+s(1052)+s(1803)](a),W.set(k,N,a[s(1509)][s(991)]);else throw new Error("recevied message"+s(1180)+N+(s(995)+s(1183)+"al cursor ")+$);return e[s(1147)](r)}return this[s(1327)+s(1052)+s(1803)](a),e[s(1552)](r)}}else return _0x1b1e88+=_0x43d481&&_0x4b3825.byteLength||0,_0x2fb14d}async function xg(a,r){let s=t,d=pa[s(596)](this,a);if(!d[s(1061)+s(1864)])return e[s(1714)](r);let f=await pd[s(596)](this);if(d["isAckCle"+s(877)+s(1230)]&&d.ackMsgIds.length)for(let p of d[s(1492)+"s"])await f[s(1453)](p);e[s(1714)](r)}async function pg(a,r){let s=t,d={SUWBC:function(g,k){return e[F(1672)](g,k)},HVCmw:function(g,k){return e[F(1225)](g,k)},kLnkK:function(g,k){return e[F(1691)](g,k)}},f=e[s(481)](a[s(1509)].frameType,ag),p=e[s(1388)](a[s(1509)].frameType,wa);if(e.mjNhc(!f,!p))return r();let E=rr(a[s(1509)][s(1018)],e[s(895)]);if(!E)return e.MGZeN(r);let b=await md[s(596)](this,E);if(!b)return e[s(666)](r);if(f){let g=await b.getCursors(),k={frameType:g?.[s(1114)+"e"],SeqID:fe.fromNumber(this[s(1791)]++),LogID:fe.fromNumber(this[s(940)][s(1434)+"erator"]()),service:9e3,method:5,headers:g?.headers,payload:g?.[s(624)]},N=S(k);this[s(1702)]&&this[s(1702)][s(1497)+"te"]&&this._ws[s(1633)](N)}if(p)if(e[s(1763)](e[s(1682)],"AhVof")){let g=_0x4b2b8e[s(1600)](":");_0x27862f&&(_0x416aff=g[s(713)]),_0x3684a1+=g[s(713)];for(let k=0;fLyoqo[s(1166)](k,g[s(713)]);k++)if(fLyoqo[s(904)](4,g[k][s(713)])){let N=_0x5178bf.substring(0,fLyoqo.kLnkK(4,g[k][s(713)])),B=N[s(1153)](g[k]);_0xf53a91.push(B)}else _0x5c0ea6[s(1387)](g[k]);_0x25654c=!1}else{let g=a[s(1509)][s(624)];g&&b[s(953)+"rs"](g)}}let gg=async function(a,r){let s=t;this[s(1645)]=!1,clearTimeout(this[s(1337)+s(1636)+s(543)]),e.GfNjy(r)},mg=async function(a,r){let s=t,d={jGDwF:function(f,p){return e.vEihZ(f,p)}};if(e.joyIV(e[s(1409)],e[s(1409)])){let f=this[s(1937)][s(579)+s(538)](this[s(1525)]),p=_0x13ebba.parse(yBOlcE[s(1305)](f,"{}"));return p[_0x1949f2]=void 0,this[s(1937)][s(1504)+s(538)](this[s(1525)],_0x223341.stringify(p))}else{if(!this[s(1702)]||e[s(772)](this[s(1702)][s(1497)+"te"],this[s(930)]))return r();let{pingInterval:f}=this[s(940)];this[s(1465)+"tManager"]?.["resetEnd"+s(1326)+s(852)]();for(let E=0;E<this["_message"+s(1468)][s(713)];E++){let b=this["_message"+s(1468)][E];if(this[s(1702)][s(1497)+"te"]===this[s(930)]&&e[s(1517)](null,b))this[s(1702)]&&this[s(1702)][s(1633)](b),this["_message"+s(1468)][E]=null;else break}this["_message"+s(1468)]=this[s(1472)+s(1468)].filter(E=>!!E),this[s(946)+"gTimeoutId"]=e[s(1904)](setTimeout,()=>this._ping(),f),this[s(1327)+s(928)+"nt"](a),this[s(1710)+"er"]&&this[s(1702)]&&(this[s(1702)][s(942)+"pe"]=this[s(1792)+"ype"]);let p=this[s(1465)+s(795)]?.["getCurre"+s(1338)+"nt"]();this._debug(s(725)+p+s(1546)),r()}},wg=async function(a,r){let s=t,d=this[s(1465)+s(795)]?.[s(1680)+s(1338)+"nt"]();this[s(1612)]("open "+d),e.GfNjy(r)};class _g extends fa{constructor(r){let s=t,d={wVMLr:function(b,g){return e[F(1928)](b,g)},Kumjw:function(b,g){return b===g},BsbJc:e[s(1590)],HShRA:e.LOFIU,ZQkZR:e.BEVSP,gsFuU:e[s(798)],JlhbJ:function(b,g,k){return e.QvnUq(b,g,k)},lXTQO:function(b,g){return e[s(1623)](b,g)},VVjoF:e.Kjaoh,nQkDG:e[s(479)],WUkKe:function(b,g,k){return e.FGNSg(b,g,k)},DemuH:function(b,g){return b!==g},vjnbr:e.hfngx,HeWNI:s(1559),NoJGt:function(b,g){return e[s(1324)](b,g)},NVZmh:function(b,g,k){return e[s(1032)](b,g,k)}};super(),this[s(1942)+s(615)+"line"]=!0,this[s(1710)+"er"]=nr,this[s(485)]=Np,this[s(1149)+"T"]=Cn,this._isMiniWX=Yr,this._isWorker=Xr,this["_message"+s(1468)]=[],this[s(1465)+s(795)]=null,this["_readyCl"+s(1429)]=!1,this["_binaryT"+s(1431)]=e[s(1096)],this[s(1337)+s(1361)]=!1,this[s(1337)+"ionTimeo"+s(543)]=null,this[s(1311)+s(996)+"tId"]=null,this[s(946)+s(735)+"Id"]=null,this[s(1791)]=0,this[s(1645)]=!1,this[s(1218)]="",this[s(1208)+"ger"]=null,this[s(873)+"anager"]=null,this[s(1283)+s(1356)]=null,this._protocols=s(638),this[s(659)]=3,this[s(568)+"NG"]=0,this.OPEN=1,this[s(1510)]=2,this[s(660)]=b=>{let g=s,k={gNsGk:e[g(707)],SJzza:e.DSFNk,ajuXF:e[g(1665)]};if(e[g(1613)]!==e.Pncyy){let{SeqID:N,LogID:B,service:W,LogIDNew:$,method:se}=_0x3ad50e[g(1509)];this[g(1574)]({SeqID:N,LogID:B,LogIDNew:$,service:W,method:se,headers:[{key:nULIRf[g(1785)],value:"1"},{key:nULIRf[g(668)],value:$||""},{key:nULIRf[g(1068)],value:"0"}]})}else try{e[g(512)](dd,this,b,[gg,mg,wg])}catch(N){let B=e[g(950)](at,e[g(479)],{message:N[g(1509)],code:nn.OPEN_ERROR,error:N});this[g(1327)+g(779)+g(675)](B)}},this[s(809)+"ge"]=async b=>{let g=s,{pingInterval:k,pingFrequency:N}=this[g(940)];if((d.wVMLr("hi",b.data)&&d[g(1599)](d.BsbJc,N)||d[g(938)]===N)&&(this[g(1683)+g(1202)](),this[g(1228)](d[g(1610)],d[g(1438)]),this[g(946)+g(735)+"Id"]=d[g(1901)](setTimeout,this._ping[g(643)](this),k)),!d.Kumjw("hi",b.data))try{dd(this,b,[Jp,Vp,xg,pg,hg,Zp])}catch(B){if(d[g(1399)](d[g(1699)],g(970)))_0x5e50f2.o=(W,$)=>_0x446f98.prototype[g(829)+g(1514)][g(596)](W,$);else{let W=at(d[g(1321)],{message:B[g(1509)],code:nn[g(1370)+g(1949)],error:B});this["_dispatc"+g(779)+"ent"](W)}}},this[s(499)]=b=>{let g=s,k=this[g(1465)+g(795)]?.[g(1341)+g(1950)+"es"](),N=this["_endpoin"+g(795)]?.[g(1680)+g(1338)+"nt"]();if(k&&!b[g(1509)]){let B=g(1328)+N+(g(1898)+g(997)+g(1844)+"ed");this["_dispatc"+g(779)+"ent"](at(e[g(479)],{message:B,code:nn[g(721)+g(588)+"R"],error:b}));return}this[g(1702)]&&e[g(1090)](this[g(1702)][g(1497)+"te"],this[g(930)])&&this[g(863)+"ect"](),this[g(1327)+g(779)+g(675)](e[g(714)](at,e[g(479)],{message:b.message,code:nn[g(694)+g(534)],error:b}))},this[s(1572)]=async b=>{let g=s;this[g(583)+g(1121)](),this[g(1683)+g(1202)](),this[g(1196)+g(1794)+"rs"](),this[g(1702)]=null,this[g(1337)+g(1361)]=!1;let k=this[g(1465)+g(795)]?.[g(1341)+"chMaxTries"]();if(!k&&this["_navigat"+g(1304)]()&&!this["_readyCl"+g(1429)]){let N=this["_endpoin"+g(795)]?.[g(1680)+"ntEndpoint"](),B=this[g(940)][g(1284)+g(1139)+g(1247)](b[g(790)],b[g(1400)]);this["_dispatchCloseEv"+g(675)](d.WUkKe(pt,g(793),{code:1006,reason:b[g(1400)]||g(1241)+g(774)+"d, unkno"+g(542)+"n, hostn"+g(648)+N,willReconnect:B})),B&&this[g(1337)]();return}if(d.DemuH(1e3,b.code)&&this["_readyCl"+g(1429)]){this[g(1327)+g(1817)+g(675)](pt(d[g(1914)],{code:1e3,reason:d[g(506)]})),this[g(1465)+g(795)]?.[g(654)+g(1326)+g(852)](),this[g(1283)+"sCounter"]?.["resetCou"+g(1673)]();return}if(d.DemuH(1e3,b.code)&&k){let N=this[g(1465)+g(795)]?.["getCurre"+g(1338)+"nt"](),B=b[g(1400)];B||(B=await d.NoJGt(qp,this[g(1218)])),B="connecti"+g(774)+"d, "+B+(g(756)+g(1127))+N+(g(947)+"tries re"+g(1932)),this[g(1327)+g(1817)+"ent"](d[g(1901)](pt,d[g(1914)],{code:b[g(790)],reason:B}));let W="connect "+N+(g(1898)+g(997)+g(1844)+"ed");this["_dispatc"+g(779)+g(675)](at(d.nQkDG,{message:W,code:nn[g(721)+g(588)+"R"]})),this[g(1465)+"tManager"]?.[g(654)+g(1326)+g(852)](),this[g(1283)+"sCounter"]?.[g(1920)+"nter"]();return}if(d.DemuH(1e3,b[g(790)])&&!b.reason){let N=this[g(1465)+"tManager"]?.getCurrentEndpoint();this[g(1327)+g(1817)+g(675)](d.NVZmh(pt,d[g(1914)],{code:b[g(790)],reason:g(1241)+g(774)+"d, unkno"+g(542)+"n, hostn"+g(648)+N})),this[g(1465)+g(795)]?.[g(654)+g(1326)+g(852)](),this[g(1283)+"sCounter"]?.["resetCou"+g(1673)]();return}this[g(1327)+"hCloseEv"+g(675)](b),this["_endpoin"+g(795)]?.[g(654)+g(1326)+g(852)](),this[g(1283)+g(1356)]?.[g(1920)+g(1673)]()},this[s(1698)]=null,this[s(1721)]=null,this.onmessage=null,this.onopen=null,this[s(1073)+"econnect"]=null,this["onReceiv"+s(879)]=null,this[s(760)+s(854)+s(1784)+"ct"]=null,this[s(1448)+s(1824)]=this[s(1448)+s(1824)][s(643)](this),this[s(1448)+s(974)]=this._handleOffLine[s(643)](this),this[s(1594)+s(572)]=this._handlePageHide[s(643)](this),this[s(1594)+"ageShow"]=this[s(1594)+s(1316)][s(643)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1772)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(1131),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(926)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:p}=r,E=Array.isArray(f)?f:e[s(1756)]==typeof f?[f]:[];if(!E||e.OpPQt(0,E[s(713)]))throw new Error(e[s(1118)]);if(!Fp(p))throw new Error(e[s(1317)]);if(Object[s(853)](this[s(940)],r),this[s(1465)+s(795)]=new ld(E,this[s(940)][s(501)+"es"]),this[s(1283)+s(1356)]=new Gp(this[s(940)]["pingLoss"+s(1891)]),this._options["automati"+s(1132)]){if(e[s(775)](e.viyZf,s(1209)))return!!(e[s(1168)](this["currentI"+s(500)],this.endpoints.length)||this.currentIndex===e[s(1717)](this[s(886)+"s"][s(713)],1)&&this[s(1290)+s(1749)+s(1027)+"t"]===this[s(501)+"es"]);this[s(1645)]=!0,this[s(1337)]()}this[s(940)][s(786)+"tworkCha"+s(505)]&&(this[s(1149)+"T"]||this[s(1545)+"X"]?this[s(1422)+s(511)+s(652)]():this[s(1710)+"er"]&&this["_initGlobalEvent"+s(1462)]())}[t(1448)+t(1824)](){let r=t;this[r(940)][r(670)+r(1899)+"nect"]||this[r(945)+"osed"]||this[r(1813)+r(1059)]()}[t(1448)+t(974)](){let r=t;this["_destroy"+r(560)+"t"]();let s=e[r(1578)](ua,e[r(489)],{message:e[r(1874)]});this[r(760)+r(854)+r(1784)+"ct"]&&this[r(760)+r(854)+r(1784)+"ct"](s)}["_initGlo"+t(1779)+t(1462)](){let r=t;this._isBrowser&&window[r(1205)+"Listener"](e.cwgNT,this[r(1448)+"nLine"]),this._isBrowser&&window[r(1205)+r(1462)](e.RTBzR,this[r(1448)+r(974)]),this[r(1710)+"er"]&&window["addEvent"+r(1462)](e[r(634)],this[r(1594)+r(572)]),this._isBrowser&&window["addEvent"+r(1462)](e[r(1363)],this[r(1594)+r(1316)])}["_dropGlo"+t(1779)+t(1462)](){let r=t;this[r(1710)+"er"]&&window["removeEventListe"+r(1420)](e[r(1847)],this["_handleO"+r(1824)]),this[r(1710)+"er"]&&window[r(715)+r(1625)+r(1420)](e[r(617)],this[r(1448)+r(974)]),this._isBrowser&&window["removeEv"+r(1625)+r(1420)]("pagehide",this["_handleP"+r(572)]),this[r(1710)+"er"]&&window.removeEventListener("pageshow",this[r(1594)+r(1316)])}[t(1594)+t(572)](r){let s=t;!r[s(1001)+"d"]&&(this[s(1710)+"er"]&&window[s(715)+"entListe"+s(1420)](e.ZzYGW,this[s(1594)+s(572)]),this[s(1710)+"er"]&&window[s(715)+s(1625)+s(1420)](e[s(1363)],this["_handleP"+s(1316)]),this[s(793)]()),this[s(1710)+"er"]&&window[s(715)+s(1625)+s(1420)](e.cwgNT,this[s(1448)+"nLine"]),this[s(1710)+"er"]&&window["removeEventListe"+s(1420)](e[s(617)],this["_handleO"+s(974)])}[t(1594)+t(1316)](r){let s=t;r[s(1001)+"d"]&&(this[s(1062)+s(1304)]()&&(!this._ws||e[s(1413)](this[s(1702)][s(1497)+"te"],this[s(930)])||e[s(1642)](this[s(1702)][s(1497)+"te"],this[s(568)+"NG"]))&&this[s(1448)+"nLine"](),this[s(1710)+"er"]&&window["addEvent"+s(1462)](e[s(1847)],this[s(1448)+s(1824)]),this[s(1710)+"er"]&&window[s(1205)+s(1462)](e.RTBzR,this[s(1448)+"ffLine"]))}async[t(1939)+t(1254)](r){let s=t,{fpID:d,deviceID:f,bddID:p,ttwID:E,accessKey:b,aID:g,customParams:k={},enableAutoAck:N,enableQoS:B,QoSLevel:W,env:$}=this[s(940)],se,je,St;this[s(1710)+"er"]||this[s(1545)+"X"]||this[s(1149)+"T"]?(se=location&&s(1778)==location[s(909)]?e[s(1695)]:e.BPicT,je=r[s(522)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),St=/^wss(.*:\/\/)/.test(r)?r:""+se+je):(se="wss://",je=r.replace(/(^http)((?:[s]*:\/\/))/,""),St=/(^ws)((?:[s]*:\/\/))/[s(1043)](je)?je:""+se+je);let as=p?e[s(1810)]:E?"ttwid":e[s(816)],wd=p||E||f;if(e[s(1300)](!wd,!as))throw new Error(s(622)+s(1681)+"ddID, de"+s(1097)+"r ttwID");let yg=e[s(1708)](e[s(1547)],typeof k)?await e[s(521)](k):k,bg=$?e[s(1405)](Up,$.xUseEnv,$[s(1876)]):{},_a=Object[s(853)]({device_platform:e[s(1375)],version_code:s(631)+"0",access_key:b,fpid:d,aid:g,[as]:wd,xsack:N?1:0,xaack:N?1:0,xsqos:B?1:0,qos_level:B?W:void 0,qos_sdk_version:2,...bg},yg),Eg=Object.keys(_a)[s(1297)]((ya,ba)=>_a[ba]!==void 0?""+ya+(ya?"&":"?")+ba+"="+_a[ba]:ya,"");return St+s(1129)+Eg}async[t(1337)](){let r=t;if(!(this[r(1337)+"Lock"]||this[r(945)+r(1429)])){this[r(1337)+r(1361)]=!0;try{let s=this[r(1465)+"tManager"]?.[r(494)+r(1581)+"ointReachedMaxRe"+r(898)](),{timeoutInterval:d}=this[r(940)];if(s){let p=this[r(1465)+r(795)]?.[r(1680)+"ntEndpoint"](),E=this[r(1465)+"tManager"]?.[r(1931)+r(1484)+r(1045)+r(1234)+"unt"](),b=this[r(1465)+r(795)]?.[r(1680)+"ntEndpointTriesC"+r(1470)]();if(E){let g=r(1328)+p+(r(1741)+r(947)+"tries re"+r(1178)+r(967)+r(1302)+"ndpoint ")+E+(r(637)+"y"),k=e.JWFSE(at,e[r(479)],{message:g,code:nn.MAX_RETRIES_ERROR});this[r(1612)](g),this[r(1327)+r(779)+"ent"](k),this[r(1218)]=await this[r(1939)+r(1254)](E),this[r(1612)](r(1328)+E+" "+b+r(1820)),this[r(1196)+r(1794)+"rs"]()}else{let g=r(1328)+p+(" timeout"+r(947)+r(1662)+r(1932));this[r(1612)](g),this["_dispatc"+r(779)+"ent"](e[r(1389)](at,e[r(479)],{message:g,code:nn[r(721)+r(588)+"R"]}));return}}else{let p=this[r(1465)+"tManager"]?.["getCurrentEndpoi"+r(1204)+r(1650)](),E=this[r(1465)+"tManager"]?.[r(1680)+"ntEndpoi"+r(1079)+r(1470)]();this[r(1218)]=await this[r(1939)+"eUrl"](p||""),this[r(1612)]("connect "+p+" "+E+r(1820)),this[r(1196)+r(1794)+"rs"]()}if(this[r(1645)])this[r(1645)]=!1;else{let p=e[r(1921)](ua,r(1284)+"t",{message:"start"});this["onStartR"+r(1059)]&&this[r(1073)+r(1059)](p)}let f=this[r(1465)+r(795)]?.[r(1680)+r(1338)+r(1079)+r(1470)]()||0;e.biAdt(f,1)&&await this._wait(e.sEgie(f,1)),this[r(1612)](r(1241)+r(1587)+this[r(1218)]+(r(1424)+r(1456))+this[r(1124)+"ls"]),this[r(1702)]=Bp({url:this[r(1218)],protocols:[this._protocols],headers:this._options[r(519)+r(695)+"s"]["customHt"+r(1248)]},this[r(940)].ws),(this[r(1710)+"er"]||this[r(1021)+"r"])&&this[r(1702)]&&(this[r(1702)][r(942)+"pe"]=this._binaryType),this[r(1512)+r(1685)](),this[r(1337)+r(1636)+r(543)]=e[r(1439)](setTimeout,this[r(1214)+"ut"][r(643)](this),d)}catch(s){throw this[r(1337)+r(1361)]=!1,s}}}_clearTimer(){let r=t;clearTimeout(this[r(1337)+r(1636)+r(543)]),this._connectionTimeoutId=null}["_clearPi"+t(1202)](){let r=t;e[r(608)](e[r(1670)],r(1211))?(_0x3d83c4=e[r(754)](e[r(724)](31,_0x43662d)<<6,e.ajdTj(63,_0x5a84dc)),e.MVYrT(_0x397494,128)?_0x46b603+=_0x1f42e1:(_0x531970+=e[r(1530)](_0x37cdf1,_0xc3263e),_0x25eb11++)):(e[r(1172)](clearTimeout,this["_pingPon"+r(735)+"Id"]),clearTimeout(this[r(1311)+r(996)+r(657)]),this[r(946)+r(735)+"Id"]=null,this["_reconne"+r(996)+r(657)]=null)}_debug(...r){let s=t;this[s(940)][s(496)]&&console[s(858)][s(1058)](console,[e[s(591)],...r])}[t(838)+t(1801)+"e"](r){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:p}=this[s(940)],E=e[s(1382)](d,Math.pow(p,e[s(1189)](r,1)));return e[s(987)](E,f)?f:E}[t(1629)](){let r=t,s={FrjBq:function(d,f){return e.nQtbh(d,f)}};if(e[r(667)](e.xTuFG,"vgJaN"))return _0x2c5466[r(1058)](NIgbWN[r(1165)](_0x1d0b82,this),_0xd2fbbd),NIgbWN.FrjBq(_0x1bb70e,_0x5e84c3[r(835)](this));if(this[r(1702)]&&e[r(1520)](this[r(1702)][r(1497)+"te"],this[r(568)+"NG"])){this[r(1683)+"ngTimer"](),this["_pingPon"+r(735)+"Id"]=e.XgFUb(setTimeout,this[r(1629)].bind(this),this[r(940)][r(1481)+r(613)]);return}if(!this[r(1702)]||this._ws[r(1497)+"te"]!==this[r(930)])return void this[r(1813)+"econnect"]();this[r(1702)]&&this[r(1702)][r(1633)]("hi"),this["_reconne"+r(996)+"tId"]=e.EcZnV(setTimeout,this[r(1813)+r(1059)+"Timeout"][r(643)](this),this[r(940)][r(1392)+r(1551)+r(1289)])}[t(1813)+"econnect"+t(1384)](){let r=t;this[r(1283)+r(1356)]?.[r(1092)](),this[r(1228)](e[r(1586)],e[r(1533)]),this[r(1283)+r(1356)]?.[r(1341)+"chMaxCount"]()?this[r(1813)+"econnect"]():this._ping()}[t(1062)+t(1304)](){let r=t;return this._isMiniTT||this[r(1545)+"X"]?this[r(1942)+"igatorOn"+r(1607)]:(this[r(1710)+"er"]||this[r(1021)+"r"])&&this[r(940)][r(786)+"tworkCha"+r(505)]?navigator.onLine:!0}[t(1813)+t(1059)](){let r=t;!this[r(1062)+r(1304)]()||this[r(945)+r(1429)]||(this[r(1465)+r(795)]?.[r(654)+r(1326)+"fig"](),this[r(1283)+r(1356)]?.[r(1920)+r(1673)](),this._ws?this[r(863)+"ect"](1001,e[r(1041)],!0):this[r(1337)]())}[t(1422)+t(511)+t(652)](){let r=t;this[r(1149)+"T"]?tt[r(1527)+r(1126)+r(1936)](({isConnected:s})=>{let d=r;this[d(1942)+d(615)+d(1607)]=s,s?this[d(1448)+"nLine"]():this[d(1448)+"ffLine"]()}):this._isMiniWX&&wx[r(1527)+r(1126)+r(1936)](({isConnected:s})=>{let d=r;this[d(1942)+"igatorOn"+d(1607)]=s,s?this[d(1448)+d(1824)]():this["_handleO"+d(974)]()})}[t(1082)](r){let s={VNBdf:function(d,f,p){return d(f,p)}};return new Promise(d=>{let f=F;s[f(1426)](setTimeout,d,this[f(838)+f(1801)+"e"](r))})}[t(863)+"ect"](r=1e3,s="",d=!1){let f=t;this._ws&&this[f(1060)+"WebSocket"](r,s,d)}[t(1214)+"ut"](){let r=t,s=this[r(1465)+r(795)]?.[r(1680)+r(1338)+"nt"]();this[r(1612)](r(1328)+s+" timeout"),this["_disconn"+r(1447)](1001,e.SeYfn,!0)}[t(1574)](r){let s=t,d=zt(r);this._ws&&e[s(845)](this[s(1702)][s(1497)+"te"],this[s(930)])&&(this[s(1702)]&&this[s(1702)][s(1633)](d),this[s(1612)](e.hePpf,r))}[t(1196)+t(1794)+"rs"](){let r=t,s="4|2|1|0|3".split("|"),d=0;for(;;){switch(s[d++]){case"0":this[r(1702)][r(715)+r(1625)+"ner"](e[r(557)],this[r(809)+"ge"]);continue;case"1":this[r(1702)][r(715)+r(1625)+r(1420)](e[r(1661)],this[r(1572)]);continue;case"2":this._ws[r(715)+r(1625)+r(1420)]("open",this[r(660)]);continue;case"3":this[r(1702)][r(715)+r(1625)+"ner"](e[r(479)],this._onError);continue;case"4":if(!this[r(1702)])return;continue}break}}["_addWsLi"+t(1685)](){let r=t,s=(r(1352)+"3")[r(1600)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(!this[r(1702)])return;continue;case"1":this._ws["addEvent"+r(1462)](e[r(1661)],this[r(1572)]);continue;case"2":this._ws[r(1205)+r(1462)](e.tJCqA,this._onMessage);continue;case"3":this[r(1702)][r(1205)+"Listener"](e[r(479)],this[r(499)]);continue;case"4":this._ws.addEventListener(r(1292),this[r(660)]);continue}break}}[t(999)+t(1229)](r=1e3,s=""){let d=t;try{this[d(1702)]&&this._ws[d(793)](r,s)}catch{}}["_destroy"+t(560)+"t"](r=1e3,s="",d=!1){let f=t;if(this["_clearPi"+f(1202)](),this[f(583)+f(1121)](),this[f(1196)+f(1794)+"rs"](),this[f(999)+f(1229)](1e3,s),this["_connect"+f(1361)]=!1,d&&this[f(1062)+f(1304)]()&&!this[f(945)+f(1429)]){if(this[f(1465)+f(795)]?.[f(1341)+f(1950)+"es"]()){let E=this[f(1465)+f(795)]?.["getCurre"+f(1338)+"nt"]();this[f(1327)+f(1817)+f(675)](e[f(1905)](pt,e[f(1661)],{code:1006,reason:f(1328)+E+(f(1741)+f(947)+f(1662)+f(1932)),wasClean:!0}))}else{let E=this[f(940)][f(1284)+f(1139)+f(1247)](r,s);this["_dispatchCloseEv"+f(675)](e[f(1635)](pt,e.hfngx,{code:r,reason:s,wasClean:!0,willReconnect:E})),E&&this._connect()}return}this["_navigat"+f(1304)]()||this[f(945)+f(1429)]?this[f(1327)+f(1817)+"ent"](e[f(1578)](pt,e[f(1661)],{code:r,reason:e[f(1658)]})):this[f(1327)+"hCloseEv"+f(675)](e[f(1689)](pt,e[f(1661)],{code:1006,reason:e.TpKSn})),this[f(1702)]=null,this[f(1465)+f(795)]?.[f(654)+f(1326)+f(852)](),this["_pingLos"+f(1356)]?.["resetCou"+f(1673)]()}[t(1327)+t(928)+"nt"](r){let s=t;e[s(1388)](e[s(677)],e.Vxkqy)?(this[s(1228)](e[s(1661)],_0x34e5dd),this.onclose&&this[s(1698)](_0x3aad80)):(this.emit(e.aTZRk,r),this[s(1575)]&&this[s(1575)](r))}[t(1327)+t(1052)+"Event"](r){let s=t,d={aUHyi:function(f,p){return e[F(1e3)](f,p)}};if(e.zVeBj(e[s(917)],"ymCxg"))this.emit(e[s(557)],r),this.onmessage&&this.onmessage(r);else return _0xda3cf0(_0x3bf4de[s(1058)](aQNxxK.aUHyi(_0x42ef8d,this),_0x4d6137))}[t(1327)+t(1093)+t(1480)](r){let s=t;this[s(1228)](e[s(1709)],r),this[s(906)+"eAck"]&&this[s(906)+s(879)](r)}["_dispatc"+t(779)+t(675)](r){let s=t;this[s(1228)]("error",r),this[s(1721)]&&this[s(1721)](r)}[t(1327)+"hCloseEv"+t(675)](r){let s=t;e.ESKLa(s(1461),s(1216))?(this[s(1228)](e[s(1661)],r),this[s(1698)]&&this.onclose(r)):(this.emit(s(1292),_0x308284),this[s(1575)]&&this[s(1575)](_0x56440d))}get[t(942)+"pe"](){let r=t;return this._ws?this[r(1702)][r(942)+"pe"]:this[r(1792)+r(1431)]}set[t(942)+"pe"](r){let s=t,d={TAHjU:function(f,p){return e[F(1242)](f,p)},etUZN:function(f,p){return f===p},pUNxv:function(f,p){return f===p},GZmec:s(1414)+s(1765),ikGzM:function(f,p){return e[s(845)](f,p)},rFMFM:s(1782)};if(e.kkHnS(e[s(1177)],e.UdgMj))this[s(1792)+s(1431)]=r,this[s(1702)]&&(this[s(1702)][s(942)+"pe"]=r);else{if(ZdkJrd[s(1403)](_0x1b2f7b,_0x53503a)){if(ZdkJrd.etUZN(_0x7f97cd,s(1543)))return _0x4c7786[s(835)](_0x5e1080);if(ZdkJrd[s(1906)](_0x38fdcb,ZdkJrd.GZmec))return _0x30f087["objectSt"+s(1765)]||_0xf7c2f0[s(835)](_0x45f23c);if(ZdkJrd[s(1374)](_0x4d93aa,ZdkJrd[s(1609)]))return _0x3f69b3[s(1414)+s(1765)][1]?void 0:_0x328a8e[s(1414)+s(1856)](_0x109621[s(1414)+"oreNames"][0])}return _0x3ff646(_0x95516c[_0x5c909b])}}get[t(1838)+"nt"](){let r=t,s={dGcyL:function(d,f){return e[F(1615)](d,f)},zvKil:function(d,f,p){return d(f,p)}};if(e[r(651)](e[r(745)],e.iXcGU))mwgRqM[r(1742)](_0x1520e9,this["_interva"+r(1499)+"Id"]),this[r(1515)+r(1499)+"Id"]=mwgRqM[r(783)](_0x2d51ac,()=>{this[r(948)+"ired"]()},this[r(1515)+"l"]);else return this[r(1465)+r(795)]?.[r(1680)+r(1338)+r(1079)+"ount"]()||0}get[t(770)+t(1239)](){let r=t,s=this[r(1472)+r(1468)].reduce((d,f)=>(d+=f&&f[r(1199)+"th"]||0,d),0);return e[r(486)](s,this[r(1702)]?this._ws[r(770)+r(1239)]:0)}get[t(1394)+"ns"](){let r=t;return this._ws?this[r(1702)][r(1394)+"ns"]:""}get[t(909)](){let r=t;return this._ws?this[r(1702)][r(909)]:""}get[t(1497)+"te"](){let r=t;return this[r(1702)]?this[r(1702)][r(1497)+"te"]:this[r(940)][r(1660)+r(1132)]?this[r(568)+"NG"]:this[r(659)]}get[t(1946)](){let r=t;return this._ws?this[r(1702)].url:this._url}[t(793)](r=1e3,s){let d=t,f=e[d(748)][d(1600)]("|"),p=0;for(;;){switch(f[p++]){case"0":this[d(1683)+d(1202)]();continue;case"1":this[d(583)+d(1121)]();continue;case"2":this[d(1208)+"ger"]?.closeDB();continue;case"3":if(!this[d(1702)])return void this[d(1612)](e[d(1353)]);continue;case"4":this[d(984)+d(1779)+d(1462)]();continue;case"5":this[d(945)+d(1429)]=!0;continue;case"6":if(e[d(1222)](this[d(1702)][d(1497)+"te"],this.CLOSED)||e.PpHYd(this[d(1702)].readyState,this[d(1510)]))return void this._debug(e.lMZWI);continue;case"7":this[d(1060)+"WebSocket"](r,s);continue}break}}async send(r,s){let d=t;if(e.nApWj(null,r))throw new Error(d(622)+d(1137)+d(836)+d(1366)+d(1294)+d(488)+d(682)+d(1376)+d(966));e[d(1496)]==typeof r&&(r=JSON.stringify(r)),e[d(1952)](e[d(1756)],typeof r)&&!(r instanceof ArrayBuffer)&&!(r.buffer&&e[d(1242)](r[d(1482)],ArrayBuffer))&&(r=JSON[d(762)+"y"](r));let f=await e.Pfxoj(hd,r),p=zp(r),{method:E=0,service:b=this[d(940)][d(991)],logID:g=this[d(940)]["logIDGen"+d(1293)](),headers:k=this[d(940)][d(1018)],payloadEncoding:N=this[d(940)][d(1573)+d(1156)],payloadType:B=this[d(940)][d(832)+"ype"],logIDNew:W=this._options.logIDNewConfig["enableAu"+d(1878)+d(1860)+"ew"]?e[d(1866)](i,this[d(940)].logIDNewConfig[d(1195)]):""}=s||{};if(!b)throw new Error(e[d(1231)]);let $={SeqID:fe[d(1306)+"er"](this._seqId++),LogID:fe[d(1306)+"er"](g),service:b,method:E,headers:k,payloadEncoding:e[d(1895)](N,Object)?N[d(1766)]?N[d(1766)]:"":N,payloadType:e[d(1585)](B,Object)?B.type?B[d(955)]:p:B||p,payload:f,LogIDNew:W},se=e[d(547)](zt,$);return this[d(1702)]&&this[d(1702)][d(1497)+"te"]===this[d(930)]?(this[d(1702)]&&this[d(1702)][d(1633)](se),this[d(1612)](e[d(508)],$)):this["_message"+d(1468)].length<this[d(940)]["maxMessa"+d(1522)+d(656)]?(this[d(1472)+d(1468)][d(1387)](se),this._debug(e[d(1381)],$)):(this[d(1472)+d(1468)].shift(),this[d(1472)+d(1468)][d(1387)](se)),{seqID:this[d(1791)],logID:g,logIDNew:W}}async[t(1284)+"t"](r){let s=t,{url:d}=e[s(878)](r,{}),f=Array[s(503)](d)?d:e[s(1142)](e.LoWGn,typeof d)?[d]:[];r&&Object.assign(this[s(940)],r),f&&f.length?this["_endpoin"+s(795)]=new ld(f,this._options[s(501)+"es"]):this[s(1465)+"tManager"]?.[s(654)+s(1326)+s(852)](),this[s(1283)+"sCounter"]?.[s(1920)+s(1673)](this[s(940)]["pingLoss"+s(1891)]),this[s(945)+s(1429)]=!1,this._ws&&e[s(1314)](this[s(1702)][s(1497)+"te"],this[s(659)])?this["_disconn"+s(1447)](1e3,e.zhdDi,!0):(this[s(1645)]=!0,this[s(1337)]())}async[t(1674)](){let r=t;if(!this[r(1337)+r(1361)]){let s=e[r(1028)][r(1600)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[r(1283)+r(1356)]?.["resetCou"+r(1673)]();continue;case"1":this[r(1337)]();continue;case"2":this[r(945)+r(1429)]=!1;continue;case"3":this[r(1645)]=!0;continue;case"4":this[r(1465)+r(795)]?.[r(654)+r(1326)+r(852)]();continue}break}}}[t(1205)+t(1462)](r,s){this.on(r,s)}[t(1910)+"Event"](r){let s=t,{type:d}=r;this[s(1228)](d,r)}[t(715)+"entListener"](r,s){this.off(r,s)}[t(556)](){let r={BBiql:function(s,d,f){return e[F(1405)](s,d,f)}};return new Promise((s,d)=>{let f=F,p={PlgGY:function(E,b){return e.rEBcU(E,b)},MjSQF:"ping_once_timeout",ORPZu:e[f(1533)],CFLCY:"ping_once_success"};if(e[f(608)](e.mYKgC,e.NHmMY)){this[f(1060)+f(560)+"t"]();let E=vmEHPu[f(869)](_0x45530c,"reconnect",{message:f(1074)+f(1754)+f(1678)+"ct"});this[f(760)+f(854)+f(1784)+"ct"]&&this[f(760)+f(854)+f(1784)+"ct"](E)}else{this[f(1683)+f(1202)](),this._pingPongTimeoutId=e[f(950)](setTimeout,this._ping.bind(this),this[f(940)][f(1481)+f(613)]);let E=()=>{let g=f;p[g(658)](s,g(1922)),this[g(584)](g(773)+"e_success",E),this[g(584)](p.MjSQF,b)},b=()=>{let g=f;p[g(658)](d,p.ORPZu),this[g(584)](p[g(1148)],E),this[g(584)](p[g(700)],b)};this.on(e[f(688)],E),this.on(e[f(1586)],b),this[f(1629)]()}})}}})(),Me[G(523)+G(1589)]=Ce[G(523)+G(1589)],Me[G(687)+G(1455)]=Ce["CustomEr"+G(1455)],Me[G(1020)+"e"]=Ce[G(1020)+"e"],Me[G(1803)]=Ce[G(1803)],Me.FWS=Ce[G(934)],Me["Frontier"+G(575)+G(800)]=Ce["Frontier"+G(575)+"vent"],Me[G(575)+G(800)]=Ce[G(575)+G(800)],Me[G(1705)+"t"]=Ce[G(1705)+"t"],Me[G(491)+G(1015)]=Ce[G(491)+G(1015)],Me["createCl"+G(1589)]=Ce[G(1296)+G(1589)],Me[G(1582)+G(1455)]=Ce[G(1582)+"rorEvent"],Me[G(628)+G(826)+"nt"]=Ce["createMe"+G(826)+"nt"],Me.createOpenEvent=Ce.createOpenEvent,Me["createRe"+G(1626)+G(800)]=Ce[G(1523)+G(1626)+G(800)],Me.decodedFrame=Ce[G(1513)+"rame"],Me[G(941)+"ame"]=Ce[G(941)+G(1579)];for(qo in Ce)[G(523)+G(1589),"CustomEr"+G(1455),G(1020)+"e",G(1803),G(934),G(768)+"MessageEvent",G(575)+G(800),G(1705)+"t",G(491)+"tEvent",G(1296)+"oseEvent",G(1582)+"rorEvent",G(628)+G(826)+"nt",G(1562)+G(1888),G(1523)+"connectE"+G(800),"decodedF"+G(1354),G(941)+"ame"].indexOf(qo)===-1&&(Me[qo]=Ce[qo]);var qo;Object[G(535)+G(1514)](Me,G(1833)+"le",{value:!0})});import{existsSync as kS,openSync as RS}from"node:fs";import{mkdir as CS}from"node:fs/promises";import{dirname as PS}from"node:path";import{fileURLToPath as DS}from"node:url";function LS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ul(t=Q()){return kS(t.libEntry)?t.libEntry:DS(new URL("../index.ts",import.meta.url))}async function $x(t={}){let e=t.paths??Q(),n=t.entryOverride??Ul(e),i=LS(e,process.env.COZE_BRIDGE_LOG_MODE);await CS(PS(i),{recursive:!0});let o=RS(i,"a"),l=n.endsWith(".ts")?["--import","tsx/esm",n,"--daemon"]:[n,"--daemon"],u=nt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[ns]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return OS.info("daemon spawned",{pid:u.pid,entry:n}),{pid:u.pid,entry:n}}var OS,ns,Qo=Qe(()=>{"use strict";$t();te();Oe();OS=q("spawn-daemon"),ns="COZE_BRIDGE_DAEMON"});import{spawn as CI}from"node:child_process";import{mkdir as PI,unlink as DI,writeFile as OI}from"node:fs/promises";import{dirname as LI,join as NI}from"node:path";function Vr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function MI(t){if(!t)return"";let e=Object.entries(t).map(([n,i])=>` <key>${Vr(n)}</key>
|
|
20
|
+
`+n)}function Xn(t,e,n,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,Xn),t.emit("wsClientError",d,n,e)}else Xi(n,i,o,c)}});var Mx=oe(Ne=>{"use strict";var L=U;(function(t,e){let n=U,i=t();for(;;)try{if(-parseInt(n(1419))/1*(-parseInt(n(471))/2)+parseInt(n(1855))/3*(parseInt(n(1483))/4)+parseInt(n(932))/5*(-parseInt(n(981))/6)+parseInt(n(1735))/7*(-parseInt(n(1315))/8)+parseInt(n(1163))/9+-parseInt(n(1842))/10*(-parseInt(n(1214))/11)+-parseInt(n(382))/12*(parseInt(n(1831))/13)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Ho,830739);var Jv=Object[L(628)+L(1012)],Yv=Object[L(503)+L(886)+L(457)],Px=(t,e)=>function(){return t&&(e=(0,t[{sMFRU:function(o,c){return o(c)}}.sMFRU(Yv,t)[0]])(t=0)),e},Zv=(t,e)=>{let n=L,i={Sukzn:function(c,d,u,f){return c(d,u,f)}};for(var o in e)i[n(780)](Jv,t,o,{get:e[o],enumerable:!0})};function Xv(){return Ax||(Ax=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Qv(){let t=L;return kx||(kx=[IDBCursor[t(708)+"e"][t(1862)],IDBCursor[t(708)+"e"][t(828)],IDBCursor[t(708)+"e"][t(828)+t(1628)+"ey"]])}function eS(t){let e=L,n={NqLWK:function(o,c){return o(c)},anGrp:function(o,c){return o(c)},hPgRR:function(o){return o()},vjbIk:function(o){return o()},rGtIw:e(449),vdKNs:function(o){return o()},iTgEU:function(o,c,d){return o(c,d)},EqYyt:function(o,c){return o&c},IMomf:function(o,c){return o>>>c},DAItE:function(o,c){return o>>>c},qsUSk:function(o,c){return o>>>c},INvHR:e(504),DyBOn:function(o,c){return o instanceof c},YfuHY:function(o,c){return o===c},QdWCx:e(850),leezb:e(1438)},i=new Promise((o,c)=>{let d=e,u=()=>{let g=U;t[g(1118)+g(854)+g(1516)](g(449),f),t["removeEv"+g(854)+"ner"](g(1441),x)},f=()=>{let g=U;n[g(909)](o,n[g(620)](Mt,t[g(1201)])),n[g(1887)](u)},x=()=>{c(t[U(1441)]),n.vjbIk(u)};t[d(1886)+"Listener"](n.rGtIw,f),t[d(1886)+d(1434)](d(1441),x)});return i[e(887)](o=>{let c=e,d={wCNyA:function(u,f){return n[U(1532)](u,f)},PppSa:function(u,f){return u>>>f},KTfif:function(u,f){return n.IMomf(u,f)},ixGbw:function(u,f){return n[U(1532)](u,f)},PlgZK:function(u,f){return u&f},FAbeA:function(u,f){return n[U(1471)](u,f)},DyywC:function(u,f){return n[U(1532)](u,f)},cEczn:function(u,f){return n[U(1396)](u,f)},nijzM:function(u,f){return n[U(1815)](u,f)}};if(n.INvHR!==c(1127)){if(n[c(980)](o,IDBCursor)){if(n[c(789)](n[c(1454)],n[c(1168)]))return _0x69fd30[c(1859)+c(1662)](255&this[c(1617)],d[c(1232)](d[c(1141)](this[c(1617)],8),255),d[c(1884)](this[c(1617)],16)&255,this[c(1617)]>>>24,d[c(1415)](255,this[c(1509)]),d[c(1182)](d[c(1588)](this[c(1509)],8),255),d[c(1700)](d[c(1672)](this[c(1509)],16),255),d[c(1843)](this.high,24));Nd[c(1762)](o,t)}}else{let u=n[c(1823)](_0x361f38);return n[c(1720)](_0x5680a3,_0x2d160a,u),n.anGrp(_0x3072a6,u)}})[e(664)](()=>{}),Ko.set(i,t),i}function tS(t){let e=L,n={dwEwt:function(o,c){return o!==c},IPJAz:"complete",qZLiA:e(1441),ywuda:function(o,c){return o(c)},ujbZV:e(1276)+"or",QYLVP:function(o){return o()}};if(Wo[e(1367)](t))return;let i=new Promise((o,c)=>{let d=e,u={RJgsV:function(w,S){return n[U(1293)](w,S)},OwByN:d(384),drHeT:n.IPJAz,kfDVH:n[d(1754)],xYiVR:function(w){return w()},JnbCp:function(w,S){return n[d(1334)](w,S)},ivcNL:n[d(494)],Yhgvm:function(w){return n[d(1878)](w)}},f=()=>{let w=d;if(u[w(1850)](u[w(965)],u[w(965)]))return this._socket[w(1730)+"te"];t[w(1118)+w(854)+w(1516)](u[w(1505)],x),t[w(1118)+w(854)+w(1516)](u[w(1642)],g),t[w(1118)+w(854)+"ner"](w(570),g)},x=()=>{u.xYiVR(o),f()},g=()=>{let w=d;u[w(924)](c,t[w(1441)]||new DOMException(u.ivcNL,u[w(1511)])),u[w(636)](f)};t[d(1886)+d(1434)](n[d(1530)],x),t[d(1886)+"Listener"]("error",g),t[d(1886)+"Listener"]("abort",g)});Wo[e(1762)](t,i)}function Ho(){let t=["mZqYofrVz2jXsa","BxnNsuq","zgvSzxrLrge","y3rMENq","te5qCu8","whPgyKu","CgjICdi","Aw47y2HHCNm","BwLZzq","uvLgChK","ze1qvKq","vhjvs1e","igzPzwXKoIa","BufQzM8","B3jL","sLPXrue","lcbTyxGGCMu","BwPrtM8","z2vY","BKfZuMu","yxnZAwDU","v2vPEgLUsLm","zhjizvq","CNzHBfzHBhu","CMvKDwnL","CuPHsMy","AgLNAa","rvjst1i","AxzJtKW","B25Uzwn0Aw4","tg9NsurozxC","CKHqrLq","uLH3whO","BMvY","zeD0ELq","wgHQtvy","zxjYtM8","B25fCNjVCG","AenSB3nLrxy","zev3rfa","vuDZCM4","CMvHC29U","zujVyKi","BML0AwfSAxO","t3PXAei","teXbExa","DgvZDa","svbkqxO","rwX0yxi","rxfzExq","EhrZugu","wxjMr0q","wwD0u0e","yw51Ce1LC3m","vLzkqLm","ENHkCMi","y2HLy2Tszwe","rvbzywu","CgLUz0LUDgu","x0rctMfTzq","AwXLtMfTzq","ywnOzwq","tuvtu0fhrv8","x2fKzfDZtgK","ohW5Fdb8nhW","Ag91Awy","x2LZv29YA2u","x3bPBMDmB3m","BMCGB3iGyw4","uvHXzwO","yNfWv3q","Ee9csNK","Cgu6ia","ywnRpwzYB24","wMr3Bu0","tKfusvzfx0u","swrKvfK","DK5uBxi","CMvZzxrdB3u","s1fyCee","C3Hcq0W","BuPHuu8","BMvLzf9Hy2S","quniDKi","zg50CKG","AxmGDw5Kzwy","suvtx0vsuK8","CKfJz0e","twvZC2fNzuu","DMnczfm","zw5JB2rPBMC","uMvHzcbWyxm","yw1L","twPWqNe","x2DLDeLUDgu","BLbnwxC","Efrbtee","CK1Yuhm","nxW2Fdr8mhW","suPgzNK","y29UBMvJDeu","DeXmExm","sfjKs1O","vLjdEwW","B25tDgfYDfi","rKfIzue","CgfNzxnOB3C","B29erwW","sMLpAhm","B1D5B2y","ohWXFdeXFde","Be90tuS","u1zREwC","lcbxzwjtB2m","uMLUzK4","qM93A1a","zLbTuMe","vwnbEw0","CuvvqM0","A2v0ignVBNm","vuDsB20","uKf6zvu","s0XZuMW","mNW0Fdn8mhW","x29UugfNzu4","AgfUz2u","x29UrxjYB3i","CNzHBa","Dg9VigXHCMC","twHfrKq","teTxEfy","q0PsvNa","q09otKvdveK","sxv3vgK","Bg93","D0Lkz1m","AxPcD28","CMvUDevUzha","mhW3FdL8m3W","D1zxvgy","thPsCve","yxv0BW","Ae9bsfK","C3vVteS","Axnby2TdBgu","uhjPBwfYEuS","A1vIuNi","yMzkqwm","y3vYC29Yx2y","zgvJB2rLzey","Agforwi","AxnrB1nby2S","nxW2Fdn8mNW","x2n1CNnVCK0","s295Dem","v2fcALG","qvrTueS","BuTRv28","DMLJzuLeig8","A2zevKG","t2vcu20","nhWYFdb8mxW","yxrHlcbKyxq","qMjpDgu","CNzdsLy","zfrys2m","DhLWzq","CvDJAwq","q2LoB3a","x21LC3nHz2u","y3jLyxrLrxi","yNL0zuXLBMC","z29QwuK","z2vtEw5J","D3nZoI8V","BgnWEuC","tw5wEeO","r3b4A2W","Afzbu28","q29Kzq","u0fhswC","rvLvugG","l3DZl3yY","r2DRALy","v3Lxt0m","wuTJEK0","EgzysLG","r3jLEvm","vLL2se8","y0vJEM4","BhbpqMm","x2nVBM5Ly3q","uKL6rgi","ALPNBgO","u1DgAxG","x2vUzhbVAw4","s2T3Bwi","z05twfq","ihrPBwvVDxq","Dw5ZAwDUzwq","rw1jDKy","CvzRs0y","y3PNtgO","zg1WCNq","CLPQDhu","B3bLBIa","EvfqEuS","B2nRzxq","vfjoreq","B25VCgvU","x3bHDgHlzxK","x3DZ","werwwg8","ChbL","se1gqxe","y3jLyxrLq2W","zxjFCw9Z","rhL5D0m","EvfNCLq","zwrPyxrLBhK","zxHWB3j0CW","sxbcEeW","DM9SzMW","sen3wvy","DLbfrxa","zu9Arxu","ignVzgu6ia","BMv4DcGPigm","y2HnyxHuCMK","AwT6su8","Bujttxy","Aw9UvgLTzw8","q0XRDuK","yM9L","x2nYzwf0zvm","qMPKqvO","ihrYEsbYzwm","AvrNrvu","CMvWBgfJzq","u2TPCcbWyxm","x2XPC3rLBMu","EvjLy29UBMu","rKnpDve","y3jLyxrLt3a","ww1nBxi","vg5fwNO","u2PTtLy","CMvHzhLtDge","Dfveu3C","qMf6tgS","y2PZtLK","sxLNA0C","mZC1ndHxrLDXyMS","zMLUza","qKzcugS","Aw50zwDLCIa","DhjPBq","AgvHzgvYCW","ywrKt25L","s3LMqMW","z3nnEg8","yMLUyxj5vhK","zvLVrxC","AxnbCNjHEq","tgrpAwu","t3vWyLy","Dw5KzwzPBMu","C2vUDa","zxH0zw5ZAw8","C3rHCNq","vgLTzw91Da","CvPmAue","BwfUufq","yNL0zxm","vNrJy3K","sgDfC0O","C3rLBMvYCW","EfPYwKC","y1nnC0y","C2v0","z1vWv2S","z2v0qwXSs2u","Cg1qs0y","BNLeExm","yvndAgu","AM9PBG","ywXSB2nvBNm","reiGzMfPBgu","x3jLy29UBMu","v3fJwhq","zMnzweG","id4G","wfLRwwO","CMvHzfvjBNq","ChvZAa","ywXPzcb1CMW","CMv0CNLdB3u","A2Xlqwi","BeHHBMrSzxi","BwvKAwf0zwW","t0T5yKC","t2vYsw4","ChjVDg9JB2W","EfvZzuvUDG","DKnSwKS","yNvMzMvYzwq","vMXdzKi","CNDJwg4","ExHirKC","uKrOz1q","vxbKyxrLq28","ChrMzLi","zK93rxq","Euz1qNG","uMfSzvK","tgPWwNm","t2joA1i","yxKSihrYEsa","B2TPv2W","Dxrjza","yMLUza","AM1rvhG","z0vTwhu","EfHyu1y","x25HDMLNyxq","zffpEuS","u0nAC2K","ww1sse4","yw1LoIa","ywHRqKK","CeTWwuC","zwzzEgm","Cxnvu2S","Bhm6ia","ywWGy3vYC28","s0LovwC","wvbmwvC","t3rbCxy","CNjpvwO","suPTruC","DMrltNm","y29UBMvJDa","BMCGzMfPBgu","vfDOu1u","vxzLyvi","wvfqDwi","Cgf5Bg9Hzeu","qxLft2O","nJC2rLbQEhz1","zNjVBNrPzxi","C2vYDMvYvgK","AwHJAuG","BgLZDgvUtMu","BMvJDa","BMv3vMvYC2K","zuTJBgu","Efrurw52","BLjWCfO","mdaWma","mtm3nJC3mtbrDgvOsKS","BMLQEK0","r2DvD0O","tNnkvg8","u0vOv3O","yKzztuy","yK1MBvK","s0THy1q","uKPNC1y","shfVvNG","wgvVDfm","CevKrwu","A1n0yxr1C0m","nde3ENflqMny","uLLLDLO","Dg9cExrLC0i","C2vYDMLJzs0","zNjVBunOyxi","C2vAtMK","BKTkt1G","ywr2yw5Jzq","thrltNm","B3LbDKK","zMLN","DMfSDwu","u3f1r3O","DwPZuNO","vgfN","uuPKv28","Cu1LqLG","DNndBKG","Ae5AsM4","wKPMtKS","x194x21Zz18","tu5Nq0q","BwHJA20","uvLmvLa","rejsrxK","tMnwtuK","tw9KDwXL","t3bLBKv2zw4","zMvY","s1rMAwy","D0jAzKC","ywrKrxzLBNq","AfbNuLi","v1DSu1m","zxjHDg9Y","DK9TAK0","D1nzrLG","Bg9Nsurhzw4","BNrLCG","ywzL","q2LeqKC","u3rYyxrLz3K","CvD5B20","C0XzAxq","mNWZFdr8nxW","C3rVCMu","zxH0ugf5Bg8","C0Xf","BvjZyw8","txrNs2S","ndq1ntCYt3PQuw1y","C3L2r0u","wgPxs0W","wMX2EgG","C2XPy2u","zLHmwNG","wNLmt0y","sNPrzKy","BgLUzw5V","wgX3y1K","B2zMBgLUzq","r0H1wui","DLffBgS","u3bHBwm","CgLUz0XVC3m","y29Kzq","zMzmAw5L","C2v0q3vYC28","Cun6AuS","DxrMofDYAxq","DM93weG","ALjXD0C","zM1cv2u","BM93","s1jiEee","rLbLwNC","ALfHsuu","q1PXy3i","z0rxve4","x2LZqNjVD3m","u1PAq3K","qwTPr1u","r3rOyxi","sLDksg0","ig1LC3nHz2u","mhW2Fdq","uxbysha","rxn3wfa","sMvprKi","z2v0qwXS","tNbfqMC","B25LCNjVCG","zcbLCNjVCI4","v3PkDwC","s1zVwwe","zNjHBwvuExa","ufHOs0m","senTBNO","AgfZt3DUuhi","wxLNwve","sKrtCLi","q3jiqu4","r1bZzLG","zvvYBa","DxbKyxrLq3u","CM9YrxzLBNq","C2vYDMLJzq","Dw5RBM93BIa","zfbTuhy","ALPmDxm","B2zM","BMrWB2LUDfq","zMLHCgS","BeL5C0i","r3rqAg8","CgLUz19VBMm","rxzLBNq","C3vJy2vZCW","ufPzB1O","A09Iu3e","uvn4zLC","tgfcwuG","yMrFzgLK","y3vYCMvUDeu","q0Xpu0LorW","BwvZ","ExjKvNG","A2rRD3C","rLD4sLK","ww5jDuS","Eu5Otvu","x2rPC2nVBM4","y3jLyxrLrwW","BgLUzq","C0XPC3rLBMu","ChzIs2q","x3bYzwzPEa","x2LZtwLUAvC","Dev2zw50","mLbdsvv4AG","thvuDgy","BwrfEhO","Dgv4Dc9Qyxy","DxnLCKLW","AfL4sMu","zw5LEem","zNjVBuj5Dgu","zwvnBeq","B2nRzxrtDwm","Aw5KzxHpzG","y291BNq","uuz6D3e","x2nSzwfYugK","DxbNCMfKzw4","mxWWFdr8nNW","yNL0zu9MzNm","weLWqMi","ugHYrKe","zLD2Afy","vwLeDve","AgvKtwf4uMu","Ae5hEMG","DwPIwLy","x3fVC0rc","Euv1yxe","CeXJAvi","wez1Cxa","Ahr0Chm6","uhrLC3O","Dwfvt3u","D01ir1O","z2v0t3DUuhi","rLH1rMG","x2LUAxrhBg8","B1zJwgy","ruXvvwu","Chzjqwi","CMTMDKy","tLL1v0u","Aw5N","z29PBMCGyxC","x2LZsw5PDa","CM92AwrLigi","BMDuAw1LCG","AMvrCeC","EKrmz0u","Avrpq2K","tevSuxu","tvbvCKq","DhjPzxm","uxzXDxa","uxvLDwu","rLPwAgu","BMfTzq","C2fNzq","tufyx1jfvfi","x3jLBw92zvC","Dg9mB3DLCKm","vxfVsLa","DgLUzYbZzxi","Aw5PDcbrB1m","C3rYAw5N","EfLSzuW","v3LQrw4","wLnrqvK","re1zv2S","tujirg0","y29UC3rYDwm","A2DxC1G","y3vYC29Yx24","Ee9yu0i","zw50","DhjHBNnHy3q","DNfRzuG","u1vPBMG","ChjVy2vZCW","DwnOqNC","rLDt","sKjou28","x2DLBMvYyxq","wvHsv0i","v0rzy3e","CufevKe","uwT4vKy","y0rRCeC","rfbuAhC","CMvHzg9UBhK","uMHZqLC","CMP5txe","q1jVtfO","qwPoCwO","A2v5","yxv0B21HDgK","qLHpDhi","y2vZC0HHBMq","Dgv4Dc9WBge","tKnIrhq","x2n1CNnVCKy","ywjVCNq","wgH4Dfi","Ag5QrKi","DKTXC1m","y2XVC2uSihC","v2vIu29JA2u","rgzlzwe","CevKt0e","zMD1t2K","EuPQCui","tuTYB1u","zxLZvwq","zhPzy3K","ywzhEKS","zgrjwhu","z2v0","uLLZBhu","uvjVDuy","CvbdD1O","C2noqK8","BKPvvKe","Aw5Lza","B3nLrxzLBNq","ueP1BNG","BM9Uzv9UB24","Dg9hzw5LCMe","rfHrzwS","BhLdwMi","zKnrCem","mxWZFdj8nhW","zxrYvgu","x2rYB3bhBg8","C3bSAwnL","uereC3K","A0vyAvy","BMnLq2XVC2u","t0XXuxq","z2rOA2e","r0jWy3a","CgDksuS","yw5Nzq","AevYCM9Yrxy","su1RsMm","y3nuwgi","y3jLyxrLt2i","x2LUAxq","yxbWBgLJyxq","y3ruAw1LB3u","sgzcv0W","DwPpyvi","yw5hCNa","rhHeCxu","servvu8","A2TQDxC","sevAEe0","z2LjExK","EefwDwi","uNfUB3e","zgvMAw5Luhi","Cgf5Bg9Hzfq","zgf0yq","tw56zwi","uLHev3K","zgvSzxrL","Ae9Wzw5fDMu","AfLrrwe","wwHNDM0","y09os3a","r3jKCNu","q3PtuxG","yMfSrxzLBNq","zv90Aw1LB3u","z2v0u3rVCMe","Cg9PBNrdB24","DeLK","AKnLvM0","B2zMC2v0","tLzKDhu","AwXK","u2vXsuq","C3rVCcbPBw0","yw5ZzM9YBvq","ExDpvNm","C0vmCfK","B2nyzLm","Aw1LCYbPBIa","C1bIuMO","y3vYC29YlNm","C1f4z0e","BwvZC2fNztO","Bg9NsurozxC","rfjXrxK","rwzkENu","BNnuDKG","y2f0y2G","B2jQzwn0u3q","vwT5BKq","BwLUAvbYB2C","y3jQBhi","x2rPC3bHDgm","zw5NDgG","Exz6EuW","vw5Oyw5KBgu","qwX6qxy","y2XLyxi","zezxu08","B3zYz0q","Cu5RCfe","C29Tzq","tuXVy00","B2LUDfjLywm","z0vgv1q","tgHxCM8","z0rWDLK","zM9YrwfJAa","yKH1rwu","x2LZtwLUAvq","AMvJDfn0B3i","Aw5KzxG","DLDSAuK","q1LZBfm","qNvlwLq","t2TxCgK","tK1rA2W","uuLotuu","vw9rAei","zgvIDwC","zxjYtxnN","Ahr0Ca","yxrLq291BNq","qK9zsMe","tgPNr20","DgLTzw91Da","BgLTAxq","DMvUDa","DMfSDwvZ","y3jLyxrLtwu","DxnnswO","ChjVDg90Exa","CgLUz1rPBwu","y3vYDMfSDwu","zcWG","CMTLCKDSB2i","A0Tdug8","Ew5Oue0","qNfeA2q","B2X3BMW","D0LTwxa","CK9MrK0","C29YDa","DgLTzw91DcW","vujVr2q","AwTdDxy","BhrPCgXLihq","B2XKvMvYC2K","y2uGBM90igK","CgfNzwHPzgu","ue9bwKm","qLjwsxu","s1rIr0y","BMrLEa","BwvY","uefnBuq","CLPrseW","BMnVzgLUzW","u2HHCMvKv28","C3nHz2vfDMu","tgvOwfO","yw1Lu3bHy2u","B25szwnLAxy","DuDPCgC","AgjksMW","x2rItMfTzq","DhbizwfKzxi","wxPrrvu","o2nOyxjZzxq","ru9rt1O","t21xDe0","uuLMu2W","v29yqMm","yw5Hz2vY","BNrbBMrvCgq","ywDLrxzLBNq","D24GCMvHC28","tNrZCuS","D0HozeK","yMPgz3G","BMLpuxK","y29UBMvJDgK","vNfSsLi","AwDHDg9Yt24","z2u6ia","ENfktxO","DMvYC2LVBG","rKXzExa","CLDfrfC","tMz1zwm","wxrjwwW","EKvJq0K","wK5MsNa","u0X3sxK","C05XyvG","sgjdu2m","CM92AwrLige","BM5Ly3q","sxbivfO","Bwf4twvZC2e","tgXnrKe","D3m6lY8","B25JBg9Zzq","u3vREM4","yuzst2y","Ef9MCM9UDgK","BMDLza","v2LUzg93","EuDVCu8","ihzHBgLKihm","D2LSBfjLy28","x29Ut3bLBG","wwz1sfK","AgvHzgvY","Cg9PBNrbBMq","uhb5qwi","x3DHAxq","BKT0ugi","t0j4zu4","zxjFDhrS","B25TzxnZywC","C3bSAxq","DKDeuKq","yLjStMG","y2HnyxHdB3u","y0XjyNq","CMvZB2X2zq","C2v0sxrLBq","zeP6EvK","Aw9Ul2PZB24","C3jJ","u2vYDMLJzvC","vKXRuvm","rwfsAMu","DcbSAw1PDa","DgLLCKPtt04","AxnrB1nnzxm","tLLpu0u","A0XSve4","D1zHtgu","rLnSuKS","sw5Zr0i","CM5hD0y","EenVu1O","B3nLza","zwvKzwq","q0L0uum","tLr2rgO","CMvXDwLYzwq","Bwu6ia","tg9Nsuq","y29UDgLUDwu","wMfOrM8","ywrKq291BNq","qujQzhu","s1LXDMO","CgXLyxnLiha","CwLAthG","BgDJswS","qNnnDvi","DhLuwhO","vM50t1q","AxnszwfKEq","Dg9Y","z2vrDwv1zuW","x2LUDgvYDMe","r1L2A2K","BxnN","AhjRveS","mdaWmdaWmda","t2jxvxi","q09oveLovuu","yxnL","uhzAwKi","ywX3yxLZ","mxWW","yMLUyxj5","zw50tgLZDgu","zeHcDuO","uunIz2u","zKroD2W","m3WWFdj8nxW","BwvZC2fNzv8","vhHZwM4","AKjbAva","ChrVCG","y3vYCMvUDeK","rfrSveG","rxrVD1K","ELvowei","z0vbuM4","DLfKzwC","ywXSq3vYC28","wLvxq2G","AefJA01LC3m","q0HKzee","ywDLsgLKzq","Cw9Z","u09AyMy","zNjVBu51Bwi","DMP0ANK","BLPvvgG","t0vbq0G","zwnVBM5Ly3q","BIWGAg9ZDg4","wgXJqwy","D25cveC","CeTxuva","sxvqqwO","B3bLCNr5tMe","DgHLBG","A0LICxa","Chz4q3a","Aev2CLa","vwDpt1a","EM1Hsvy","nxWWFdn8mxW","yMrYBvy","x3vYBa","rhPsDvO","Avr5vhC","CeztCwy","Dg5svuy","thPUzhG","DhDVCMTdAge","BwfW","wfLmB2u","D3PcDxK","x19LC01Vzhu","x2LUAxrqCM8","te1Uru8","C0nVDw50zxi","tNfmv0S","Cgf5Bg9Hza","BKzOzwG","zxq9DxrMltG","rxD0vhC","CYbWyxjHBxm","C2v0u3rVCMe","qLfnEhq","y2HLy2TdDxi","igzHAwWSig0","BfrPBwvVDxq","ANPizgy","wffODxu","BgrZEfC","sgDNtw4","sM5Iq3a","t2TSvKK","z2v0q3vYC28","ue1MBK4","zKrcyMO","t2HZv0K","rgT3Cha","vwzxDwi","mZi4ndbKsuvxBfa","tuzhDhi","tvP2wNq","rfz2tgq","yNHKqLi","qKf0Afy","rfrSuuS","B25SAw5L","EsbJBg9Zzwq","su5tvefova","s3zUzKm","CMvJB25Uzwm","x3DZsw5ZDge","lcbOB3n0BMe","q2D5tuu","tMfTzq","D1PmDNm","sMfYvuy","uvbIEhu","B1zUtvC","ywDL","Ae1LC3nHz2u","qMP6Ewy","x1fVu01HBMe","x2TLEvbHDgG","txroExy","zw5XDwv1zq","qKfTBgO","DgfIyxnL","BNrfBMrWB2K","zwfyEeS","DNDfquS","DNzHy2S","t3DcEu4","CM92AwrLihy","vxDvCKm","tKDFrvjst1i","rLfODNy","zwn0","D3jPDgvvAw4","Awz4yva","whjZtuK","A21OB0W","y29UBMvJDca","thrRv2G","uxzjDeW","CIb0DhDjra","t1bftL9fuLi","rhLct24","ote4wu1Ks3Pj","igfYCMf5yNu","r0PkrKe","z1rPBwvVDxq","yw1Uz3i","qLf2tgy","yLj1Bxu","CKjHBgm","r05wEMm","zM9Yy2u","z29dC3i","B2X5rMi","B25nzxnZywC","svjqEwm","y29SBM8","zgvS","BLvABKG","AMHyAMW","uu1vrLO","z1LfsKK","zw1LBNq","Ae1zwK4","reDkueu","DeLUDgvYy2u","x2zVCM1HDeu","zeLeAfK","BLL1vMW","ChHeExK","CYbHBhjLywq","y2PtrLK","AMPkELK","B3bLCNr5","uxneA0W","tNzSswG","CMLLC0nVDw4","B3vUDa","uNv4v0y","uwvYB3e","uu1csei","x3bYB3rVy28","t0D5wKO","s3fkA2C","ENj1uMK","z0PPzuq","aaaaaaaaaaa","vLLVDM8","s2DxBwq","tNj1v0e","uLjpuG","twLZC2LUzYa","C0vktey","q0vnqxq","ywL3rLK","tu9iCem","x3jLywr5q2W","yMrTz20","quXm","uwrnt1q","tfvuD1G","BwLUzW","ENDkExm","zNjVBujPDhm","Bg9N","CMvTB3zLq2G","zKzdyxa","vKX2Ege","rgX2Ehe","DwTws3u","t0PiEgC","wxH6CLC","ExbL","CuDSvMS","C0LpwKi","zgnkCw0","tfrJzfu","s1vPqMW","v0XysMu","zsbHihn0CMK","B2fK","Chv0","q0fPBKi","Aw9U","C1zusNq","qw1VDw50","AxjLza","zvLSyLm","Dg9tDhjPBMC","CMnVDgm","C2v0y3vYC28","B25dBg9Zzq","CMvWBgfJzui","B3LHu3u","zenUwue","y2HHCKnVzgu","vgndCfi","zg9Uzq","AwXLx25HBwu","BgvUz3rO","B1nTy2y","x2HHBMrSzva","qxbwAw4","vePivLK","C1PHswy","D3vWzgW","DMvY","AuvtCw4","t2r3uwO","zNLZy0S","yK9kAhO","svzXvgW","y3vquxi","u3PYrxa","DMfS","v25TA1C","ihzHBgLKigq","Cg9W","t1Dhz0S","vMHHrKq","zMLSDgvY","BLrSrKO","q0XpwKu","A0D6y0e","B3bLBKrc","Ec1TC2CTCw8","z2DYqxO","uwz4tuy","sKHWrxK","r1vlruu","rNvmsNu","vgfnA08","t1bftG","x2HHBMrSzu8","CND5r0m","EvvYsxy","zhn2tvC","zfDVCMTLCKC","uxHQAMG","CMvTB3zLrxy","EgzoBgq","AKLLuMK","Duv6seq","CMvJzwL2zwq","zKLSzLC","vwzWseq","CMfUzg9T","rMX0zLy","CKD0q1m","ENfozeC","ugzyA2O","zxrxB3jRq2G","CMfTzq","CMfNzvn5BMm","vK9tAu0","sM91AwO","ANHLquS","DvvwwNe","vLHHy2q","sLfSuLO","C3rYAw5NAwy","yMz1v2K","uhbWu2e","vxjyyu4","v0v0whi","DhHHrNe","Ec11C2uT","A2rpDfi","tezdsgK","AKfuDw8","C2vUza","q3vZDg9Tq2W","AeDRz2y","uLL5sNG","ywXSzwqGBxu","q0P3Cg0","yxbWzw5Kq2G","BNruCMLLC0m","mNW0","CuLjB2G","z2v0q3vYCMu","t3Hotge","AM5Ku20","r0HbtgW","mtmZnJmYntruA2nKuhO","BezJsvq","DxjS","sLnptLa","x3nVy2TLDa","BgvLEMi","qvLguLG","vgL5DNC","vLbdyNm","uLjkuvG","CMvHzhDYAxq","z2nKz0G","x2rLC3rYB3K","m3WYFdf8nhW","AxnmB25N","B25ozxr3B3i","zw5KCg9PBNq","B3jRzxjhBg8","C0PzuuC","ugXNwKS","vfjzA3q","z2v0sxrLBq","ihn1y2nLC3m","qujJCLe","C2nYAxb0","zefzAuS","C09bA0K","whLuz0q","zw1PDa","EuPduMm","CxHpvuC","zMX1C2HfEha","x3nLCuLK","v3LNEfe","txPPyMu","r2jZwuW","zufJAW","twzsA1G","CMvZDwX0","yuXYrK0","CgfYC2u","DfDOy0G","v2zIug4","v2zTBLy","BezSDxnO","BLHzDgO","Evjby3G","zMzMzG","q29UzMLN","Eeftrfm","rw9ZwNy","mtfhDMXktMO","x29Uq2XVC2u","CxnVwNe","zvflsgK","x29UvgLTzw8","wgf2Dxy","B2nRzxrgywK","x2jPBMfYEvq","yMrxAKW","AxnFywnR","zuzLBva","y2fSBa","x2LZtM9Kzq","zMLSzw5HBwu","ihjLy29UBMu","C1PczNe","AvHsuuK","AxnAzxjV","D0noEue","ChzxzxG","zMXVB3i","qNjPzgDL","ywDLu2HVDW","Cg93","AMnuvKK","CNnVCL92ywW","ugLhv3C","nxWZFdf8mNW","icSG","zhvjvvC","tMzJuwO","C3PqqvC","CLzuCgi","yxbWBhK","A3LnvfC","sgzKD3K","CK1WDwy","t2jQzwn0","x29UtwvZC2e","D2PuzeC","CMDbCxO","EhHeDNu","Bwf4tg9ZC0m","ywnRx2LK","AwrI","u21Xtgi","D01gwMS","zxmGCMvHy2G","qxrPuNu","Cu1cAMu","Durrzw4","yMfJA3vWigu","DgvmB2Djre4","BfrIqxi","yvnqCwq","BK1bEKy","DMjnyM0","Dg9iyxnO","DxrVuMvJB24","yKzju3q","quDqvwS","vgTNr0q","qwjVCNrfCNi","wMDzvMe","DgfYz2v0","CMvZzxrfBMq","ENHMBg0","BKXPBMu","zNjVBuHHC2G","De1HBMfNzxi","EuzNwgi","sK92tfe","x2nSzwfYvgK","EgPdExK","vvbMAwG","CgrtvNO","z2vjBMzVu3K","C3vIC3rYAw4","zhbrCfG","zhDfD3q","z0H4v1O","vwHItLG","ze9gD28","y2XVC2veqG","zxbiD3O","yMXVy2TLza","x2n1CNnVCK4","tg5YrKy","Dw50","zK1Vyu4","zxP1t0q","sLvkuvm","ELjpvKO","zefpqwW","tg5rExu","ANHOzei","CNnbDw0","rgrUCu4","Dgv4DfbHEwW","ANzTq3a","AurvtMm","mtiWoeLyrfHAtG","v0Tewve","jMPZy2fSBgi","zcWGDw5RBM8","DwrWEgy","uvbYtwi","vg9Wt0O","y29UBMvJDfm","y2XVC2u","q01iuxK","zxjFBxnNAwq","zMzLCG","svLuCNa","zNvUy3rPB24","ywnOzwqSihC","uMvJB25Uzwm","x29WDgLVBNm","x3nLBMrby2S","CMvZzxruCMK","ExD1zge","qLPytgG","yxnJCMLWDa","B3bLBG","Awjmv0m","B3jpBMXPBMu","ru5WrwS","yxGGCMv0CMK","u3LIBxm","Aw5JBhvKzxm","wuLpqK0","CNjVCK1LC3m","q0Xpu0ve","v21ywvC","C3vIyxjYyxK","ugXHvvu","Bwv0Ag9K","s0npBKq","wefpyK8","rMPrwuy","sMrRvNm","y29UDgv4Da","uMXMwey","C2HPzNq","zgPIz3m","q1zuy20","CYbPBNn0yw4","ALjjwfi","zMjNtuW","x21PBMLoyxy","DhjPzxmGCMu","zxH4vgO","tg9JAW","AgfZ","q3vZDg9Trxi","igXHCMDLCIa","zxDsB1u","tgXoqK8","wuXvCNe","ELDQvfi","r1bctLK","AwvTuwy","sKX6sNi","EfzMywO","zw5fDMvUDa","y052rg0","CM92AwrLihC","z0njreK","B3jLtMfTzxm","r3DNyLO","tKnQsNe","zLHwruW","C0jf","EeXxB0K","CKzZAhO","DvfuzM4","ywnRx2nVzgu","CezcENe","s0DXq3u","u2HRr0C","v25ksLa","CgLUz09Uy2u","refjDeu","seXgt0G","nhWX","CLPRB24","q1rVwue","rNjVBNrPzxi","rw5TteW","r0DABLC","r3DLsK4","r1PZANi","q0L1BNG","ywnRtxnNswq","zv9ZDwnJzxm","D2LvCKW","rKHzvLi","y3r4","CgvYC2LZDgu","y3vYC29Y","x2rLyNvN","AxHhyNC","zxj2AwnL","z01LzvK","vhPNv2K","mtu5ntCXouz0qM5tzq","wMjJwwK","BNvXAe8","vKnuq3q","x2HHBMrSzvi","Cejorwy","m3WWFdj8mxW","BwvZC2fNzq","CKfhANO","BgvY","yvfVu0C","wNDOq2G","Eg50t1K","CNnVCKzPBgu","rLjptLrjrvi","tgLZDgvUzxi","A2v5CW","x3bPBMDqB24","sfvNtwu","CK1yEg4","qLfqvwq","CgvNBKy","zxjYB3i","yNLL","D3jPDgu","vwL4r3O","rMPvtwq","rvHjrMe","B25tDg9Wsw0","Cgj6Bhi","qKvLA3u","AKz3s1G","s1jZtLO","vgfvDxu","yNvMzMvY","uwrxq3G","zw5JB2rLrNi","Bwf4uMv0CMK","BvHuweW","AufVwxu","D0rnrxC","rezvthu","CxPHz3q","y3jLyxrLuMu","x3bPBMC","BLvnv00","zKDHwNG","qxH3t1a","EM15sg8","Bg9IywXty28","yM9KEq","AuLlz2m","su1VBwy","BhvVwMW","rxjYB3jdB2q","vuHMBgy","y29Uy2f0","DfbOCKC","C0PABxu","zMPPC3i","y3vZDg9Tshq","BuLXtue","zw16r28","t2LZz3m"];return Ho=function(){return t},Ho()}function nS(t){$o={ikCuv:function(i,o){return i(o)}}[L(722)](t,$o)}function rS(t){let e=L,n={bFYMF:function(i,o){return i(o)},HUgMe:"error",UoQhB:function(i,o){return i(o)},Gthar:function(i,o){return i(o)},fDBbj:function(i,o){return i===o},wZLvs:function(i,o){return i in o},QPrMb:"objectSt"+e(1382),mKkWo:function(i){return i()}};return n[e(928)](t,IDBDatabase[e(708)+"e"].transaction)&&!n[e(948)](n[e(1320)],IDBTransaction[e(708)+"e"])?function(i,...o){let c=e,d=t[c(1225)](Qi(this),i,...o);return Ld[c(1762)](d,i[c(719)]?i[c(719)]():[i]),n[c(1847)](Mt,d)}:n[e(1640)](Qv).includes(t)?function(...i){let o=e;if(o(467)!=="tuDar")return t[o(1247)](n[o(695)](Qi,this),i),n[o(414)](Mt,Nd[o(585)](this));this[o(1191)](n[o(1437)],_0x117051(n[o(1437)],{..._0x5b459b,message:_0x11efa9.errMsg||""}))}:function(...i){let o=e;return Mt(t[o(1247)](n[o(695)](Qi,this),i))}}function iS(t){let e=L,n={zruRi:function(i,o){return i===o},HLFOH:"function",FWxJY:function(i,o){return i(o)},CaxVl:function(i,o){return i instanceof o},kswQj:function(i,o){return i(o)},dTXKc:function(i){return i()}};return n[e(1023)](typeof t,n[e(1397)])?n[e(460)](rS,t):(n.CaxVl(t,IDBTransaction)&&n.kswQj(tS,t),Dx(t,n[e(1648)](Xv))?new Proxy(t,$o):t)}function Mt(t){let e=L,n={wDMEw:function(o,c){return o(c)},NzBBe:function(o,c){return o(c)},uDQen:function(o,c){return o!==c}};if(t instanceof IDBRequest)return n[e(1459)](eS,t);if(jo[e(1367)](t))return jo.get(t);let i=n.NzBBe(iS,t);return n[e(1264)](i,t)&&(jo.set(t,i),Ko[e(1762)](i,t)),i}function U(t,e){t=t-367;let n=Ho(),i=n[t];if(U.AHrdoK===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",w="";for(let S=0,y,v,I=0;v=f.charAt(I++);~v&&(y=S%4?y*64+v:v,S++%4)?g+=String.fromCharCode(255&y>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,y=g.length;S<y;S++)w+="%"+("00"+g.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};U.TGhBLf=o,U.ztAmLe={},U.AHrdoK=!0}let c=n[0],d=t+c,u=U.ztAmLe[d];return u?i=u:(i=U.TGhBLf(i),U.ztAmLe[d]=i),i}var Dx,Ax,kx,Nd,Wo,Ld,jo,Ko,$o,Qi,Tx=Px({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={CItQC:function(n,i){return n instanceof i},YrfGD:"objectSt"+t(1382),pKWQP:"store",fGaZx:function(n,i){return n(i)},OBFSX:function(n,i){return n instanceof i},GHALl:function(n,i){return n===i},DVvLd:t(1076),wVWTf:function(n,i){return n===i}};Dx=(n,i)=>i[t(678)](o=>n instanceof o),Nd=new WeakMap,Wo=new WeakMap,Ld=new WeakMap,jo=new WeakMap,Ko=new WeakMap,$o={get(n,i,o){let c=t;if(e[c(823)](n,IDBTransaction)){if(i===c(1076))return Wo[c(585)](n);if(i===e[c(1534)])return n[c(665)+"oreNames"]||Ld.get(n);if(i===e[c(884)])return o[c(665)+c(1382)][1]?void 0:o[c(665)+c(1497)](o[c(665)+c(1382)][0])}return e[c(1465)](Mt,n[i])},set(n,i,o){return n[i]=o,!0},has(n,i){let o=t;return e.OBFSX(n,IDBTransaction)&&(e[o(1162)](i,e[o(935)])||e[o(1622)](i,o(377)))?!0:i in n}},Qi=n=>Ko.get(n)}}),Ox={};Zv(Ox,{deleteDB:()=>oS,openDB:()=>sS,unwrap:()=>Qi,wrap:()=>Mt});function sS(t,e,{blocked:n,upgrade:i,blocking:o,terminated:c}={}){let d=L,u={KVoYa:function(g,w){return g!==w},dZCUM:d(1482),EosZv:function(g,w,S,y,v){return g(w,S,y,v)},fXVEL:function(g,w){return g(w)},cSMsF:function(g,w){return g===w},czgLj:function(g,w){return g===w},zUNXB:d(890),Eltar:d(1323),LcWHM:"versionc"+d(1608),SGQsP:function(g,w){return g(w)},fbgML:d(485)+d(822),sEJLF:d(1299)},f=indexedDB.open(t,e),x=u.SGQsP(Mt,f);return i&&f.addEventListener(u[d(1362)],g=>{let w=d,S={qdJKb:w(541)+w(1575)};u[w(426)](w(1075),u.dZCUM)?u[w(1213)](i,u[w(1385)](Mt,f[w(1201)]),g[w(724)+"on"],g[w(1837)+"on"],u[w(1385)](Mt,f[w(544)+w(1062)])):(this[w(1300)+w(738)]=_0x231c15,this[w(569)+"ileName"]=_0x527f20,this[w(1652)+w(373)]=_0x3c84c2,this[w(495)]=_0x268cc0(this[w(1300)+w(738)],S.qdJKb))}),n&&f[d(1886)+d(1434)](u[d(1031)],()=>n()),x[d(887)](g=>{let w=d;if(u[w(426)](u[w(866)],w(890)))return u[w(1761)](0,this[w(1509)])&&u[w(1685)](0,this[w(1617)]);c&&g[w(1886)+w(1434)](u[w(1531)],()=>c()),o&&g[w(1886)+w(1434)](u.LcWHM,()=>o())}).catch(()=>{}),x}function oS(t,{blocked:e}={}){let n=L,i={sPbRj:"blocked"},o=indexedDB[n(1485)+n(960)](t);return e&&o[n(1886)+"Listener"](i[n(656)],()=>e()),Mt(o)[n(887)](()=>{})}function Cx(t,e){let n=L,i={QvItL:n(447)+"e_timeout",yFgXb:function(f,x){return f+x},jCeVm:function(f,x){return f|x},Ptesz:function(f,x){return f|x},DnKAF:function(f,x){return f<<x},GPBNY:function(f,x){return f<<x},hwxWx:function(f,x){return f>x},pvIAb:function(f,x,g){return f(x,g)},HgEsJ:function(f,x){return f===x},gDWTN:n(1399),MZvZt:"kOPjs",gRrmH:n(1173)+"e",QRouF:n(558),JDSrR:function(f,x){return f instanceof x},QINME:function(f,x){return f in x},pEdEe:function(f,x){return f===x},qEUBm:function(f,x){return f!==x},NMGot:n(1794)};if(!(i[n(432)](t,IDBDatabase)&&!i[n(694)](e,t)&&i[n(1853)](typeof e,n(533))))return;if(qo[n(585)](e))return qo[n(585)](e);let o=e.replace(/FromIndex$/,""),c=i[n(1601)](e,o),d=Nx[n(1343)](o);if(!i[n(694)](o,(c?IDBIndex:IDBObjectStore)[n(708)+"e"])||!(d||Lx.includes(o))){if(i[n(1601)](n(728),i.NMGot))return;this[n(1550)+n(908)]?.[n(830)](),this.emit(i[n(977)],n(702)),this[n(1550)+"sCounter"]?.[n(1539)+n(801)+"nt"]()?this[n(1423)+n(880)]():this[n(1463)]()}let u=async function(f,...x){let g=n,w={ApVin:function(S,y){return S+y},SWFix:function(S,y){return S+y},nAsRe:function(S,y){return i.yFgXb(S,y)},bFISt:function(S,y){return i[U(645)](S,y)},YIOBM:function(S,y){return i[U(645)](S,y)},BQvLf:function(S,y){return S<<y},wyACR:function(S,y){return i[U(500)](S,y)},pbzlr:function(S,y){return i[U(645)](S,y)},ShkGG:function(S,y){return i.DnKAF(S,y)},rMrPs:function(S,y){return S&y},EYUPh:function(S,y){return i[U(1374)](S,y)},edTcm:function(S,y){return i.hwxWx(S,y)},NCbDt:function(S,y,v){return i[U(508)](S,y,v)},rwcXn:function(S,y){return S>>y},qUEYE:function(S,y){return i[U(1284)](S,y)}};if(i[g(1758)](i[g(410)],i[g(934)]))_0x25ab65=_0x19d162[w.ApVin(w[g(1677)](_0x18e393,_0x2f628d),1)],_0x534eaf=_0x55fb7b[w[g(1081)](w[g(1502)](_0x54c443,_0x328b59),2)],_0x2e6241=_0x424688[_0x3ef24b+_0x57cad5+3],(w[g(1273)](w[g(1344)](_0x128695,w.BQvLf(_0x5d5a49,8)),w[g(986)](_0x291c8b,16))&12632256)!==8421504?_0x43e066+=_0x53533a:(_0x13a60e=w.wyACR(w[g(1344)](w[g(1448)](w[g(1393)](7&_0x5a8d22,18),w[g(1393)](w.rMrPs(63,_0x46be20),12)),w[g(1664)](63&_0x4bc816,6)),w[g(1580)](63,_0x3b25eb)),_0x4fe790<65536||w.edTcm(_0x20bf96,1114111)?_0xf214c6+=_0x5484ef:(_0x220dba-=65536,_0x404aed+=w[g(568)](_0xce7539,w[g(1677)](w[g(1790)](_0x37e4ff,10),55296),w.qUEYE(1023&_0x105f4f,56320)),_0x28908f+=3));else{let S=this["transact"+g(1062)](f,d?i.gRrmH:i[g(587)]),y=S[g(377)];return c&&(y=y[g(688)](x[g(1357)]())),(await Promise.all([y[o](...x),d&&S[g(1076)]]))[0]}};return qo[n(1762)](e,u),u}var Lx,Nx,qo,aS=Px({"node_modules/idb/build/index.js"(){let t=L,e={yrdVx:t(376)+t(852),lOtMK:function(o,c){return o(c)},JMOGQ:function(o){return o()},HwNWp:t(585),WfbPn:"getKey",xIdpL:t(482),lyCZb:t(1060),VCTCt:"add",WZfII:t(674)},n=e[t(458)].split("|"),i=0;for(;;){switch(n[i++]){case"0":e[t(1594)](nS,o=>({...o,get:(c,d,u)=>Cx(c,d)||o[t(585)](c,d,u),has:(c,d)=>!!Cx(c,d)||o.has(c,d)}));continue;case"1":qo=new Map;continue;case"2":Tx();continue;case"3":e.JMOGQ(Tx);continue;case"4":Lx=[e.HwNWp,e[t(1205)],t(421),t(1764)+"ys",e.xIdpL];continue;case"5":Nx=[e[t(597)],e[t(1422)],t(633),e.WZfII];continue}break}}}),cS={idb:function(t){let e=L;t[e(1703)]=Promise[e(803)]()[e(887)](()=>(aS(),Ox)).then(function(n){return n})}},Rx={};function Nt(t){let e=L,n={YPLYW:function(u,f){return u!==f}},i=(e(599)+"0")[e(798)]("|"),o=0;for(;;){switch(i[o++]){case"0":return d[e(1703)];case"1":var c=Rx[t];continue;case"2":var d=Rx[t]={exports:{}};continue;case"3":if(n[e(1819)](void 0,c))return c[e(1703)];continue;case"4":cS[t](d,d.exports,Nt);continue}break}}Nt.d=(t,e)=>{let n=U;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[n(628)+n(1012)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Nt.o=(e,n)=>Object.prototype[t(430)+t(1012)].call(e,n)})(),(()=>{let t=L,e={kGzcA:function(n,i){return n!=i},LTcdU:t(1881)};Nt.r=n=>{let i=t;e[i(1102)](i(1749)+"d",typeof Symbol)&&Symbol[i(1067)+"Tag"]&&Object[i(628)+i(1012)](n,Symbol[i(1067)+i(1869)],{value:e[i(1055)]}),Object.defineProperty(n,i(905)+"le",{value:!0})}})();var Ce={};(()=>{let t=L,e={HRdKZ:function(a,r){return a(r)},xYleL:function(a,r){return a+r},SEhWz:function(a,r){return a*r},zqNdG:function(a,r){return a+r},Grdru:function(a,r){return a!==r},oVnMW:t(1170),CrHAN:function(a,r){return a+r},fmBWe:t(1841),HfBWL:t(1210),vOmjM:"00000000"+t(846)+"00000000"+t(846),QYFpy:function(a,r){return a>r},hMYZN:function(a,r){return a<r},CIunx:function(a,r){return a===r},szPAW:"SNhnZ",yJjqB:function(a,r){return a-r},RinfN:function(a,r){return a!==r},OxNLa:function(a,r){return a-r},ldsxW:function(a,r){return a===r},zKFQM:t(1592),dpQpX:function(a,r){return a!==r},KYqvj:function(a,r,s){return a(r,s)},gCIDI:function(a,r){return a!==r},qVkKF:t(395),SBhyz:t(1197),EfJzu:function(a,r,s){return a(r,s)},JdkVs:function(a,r,s){return a(r,s)},rjyMq:t(474)+t(1336),jQaIE:t(698),MNgCD:function(a,r){return a!==r},YtIYl:t(1452),EtowY:function(a,r){return a(r)},PAMmD:function(a,r){return a>>>r},OUDZg:function(a,r){return a(r)},BAthV:function(a,r,s){return a(r,s)},ujOaR:t(1030)+"required field: "+t(563),UHflf:function(a,r){return a===r},wHNdI:t(1030)+t(825)+t(1495)+t(1866),LehXZ:function(a){return a()},YKczM:function(a,r){return a(r)},XAObO:function(a,r){return a!==r},KKacT:function(a,r,s){return a(r,s)},VOSiM:function(a,r,s){return a(r,s)},goCsr:function(a,r){return a===r},eYlbS:t(483),OdwQj:"KJRNS",giIyy:function(a,r,s){return a(r,s)},Lzndx:function(a,r,s){return a(r,s)},nsTvH:function(a,r,s){return a(r,s)},jZglj:function(a,r){return a(r)},sVTJt:function(a,r){return a!==r},VYvHO:function(a){return a()},ZgYVa:function(a,r,s){return a(r,s)},qMBje:function(a,r){return a!==r},pxDyy:function(a,r,s){return a(r,s)},dFWSO:function(a,r,s){return a(r,s)},vQElk:function(a,r,s){return a(r,s)},iIKgc:function(a,r,s){return a(r,s)},CJRVp:function(a,r){return a!==r},MBHDm:"PYtxG",aLrFM:function(a,r,s){return a(r,s)},nFheh:function(a,r){return a!==r},SquGz:function(a,r,s){return a(r,s)},GGZnW:function(a,r){return a!==r},LnQyu:function(a,r,s){return a(r,s)},ibLWC:function(a,r,s){return a(r,s)},AGPUk:function(a,r,s){return a(r,s)},XhxtR:function(a,r){return a(r)},GPsfX:function(a,r){return a===r},IkQxJ:t(406),yQgrT:t(1026),bhAvr:"YnIuK",RIzDb:function(a,r){return a(r)},dsvMW:function(a,r){return a(r)},WmXYW:function(a,r){return a>>>r},XIpBb:function(a,r,s){return a(r,s)},MOHpC:function(a,r){return a(r)},zWjTR:function(a,r){return a(r)},bqpWt:function(a,r,s){return a(r,s)},sJZmu:function(a,r,s){return a(r,s)},LnrFF:function(a,r){return a(r)},dIDhY:function(a,r){return a(r)},LdOie:function(a,r){return a(r)},oDKSi:function(a,r,s){return a(r,s)},UiDuQ:function(a,r){return a(r)},IygkG:t(1030)+"required"+t(1495)+t(827),QXqej:t(1030)+t(825)+t(1495)+t(438),GwgbZ:t(1030)+"required"+t(1495)+t(1350),KRsNZ:function(a,r){return a(r)},ELUUe:function(a,r){return a&r},WWlSS:function(a,r,s){return a(r,s)},SmqLb:function(a,r){return a(r)},WzJug:function(a,r){return a+r},urPfz:"Unimplemented ty"+t(1555),aYFwn:function(a,r){return a>>r},TRYkt:function(a,r){return a>=r},CiNop:function(a,r){return a===r},zxJrb:function(a,r){return a>r},lIysB:function(a,r){return a+r},tLLys:t(1722)+t(811),vcBdS:function(a,r){return a===r},MFdsq:t(1304),fEnNC:t(1359),Gakus:function(a,r){return a*r},MbeIn:function(a,r){return a>r},usMIj:t(1337),DGJPE:function(a,r){return a+r},aFROf:function(a,r){return a+r},uaUOu:function(a,r){return a|r},mJaQO:function(a,r){return a<<r},kmhoL:function(a,r){return a|r},XDVXo:function(a,r){return a<<r},XhjMV:function(a,r){return a&r},yNhMU:function(a,r){return a&r},XrsMI:function(a,r){return a&r},olyFb:function(a,r){return a<=r},qShbh:function(a,r){return a(r)},jRqwG:t(1089),nUZnH:t(1027),nuqhO:"RcUSb",bfJAc:function(a,r){return a(r)},KUiBl:function(a,r){return a>=r},TJHVY:function(a,r){return a+r},GbsYL:function(a,r){return a<<r},AkiGU:function(a,r){return a&r},FSlRK:function(a,r){return a!==r},IRPyc:t(1704),ejTuR:function(a,r){return a==r},XYLoe:function(a,r){return a>=r},pvWex:function(a,r){return a+r},QfQsC:function(a,r){return a+r},jIeRi:function(a,r){return a!==r},NSEPU:function(a,r){return a<r},YxzrW:function(a,r){return a==r},DxDqu:function(a,r){return a+r},KLsRl:function(a,r){return a+r},PpyAb:function(a,r){return a+r},FQhvv:function(a,r){return a!==r},hrkTK:function(a,r){return a<<r},wupdl:function(a,r){return a|r},jhXjl:function(a,r){return a&r},OhsWI:function(a,r){return a<r},jxhdB:function(a,r){return a>>r},jxeAK:function(a,r){return a>=r},PJunx:function(a,r){return a<=r},kgWsX:function(a,r){return a<r},RDhgT:function(a,r){return a<r},VhaFD:function(a,r,s){return a(r,s)},jndSm:function(a,r){return a<r},nXYtj:function(a,r){return a>=r},JCRfU:function(a,r){return a<r},afGzK:function(a,r){return a-r},WEtXr:function(a,r){return a>>r},MjpBq:function(a,r){return a===r},SzrEp:t(1222),XeotS:function(a,r){return a|r},sNqaX:function(a,r){return a>>r},fiapk:function(a,r){return a&r},VLvxa:function(a,r){return a>>r},NTeZK:function(a,r,s){return a(r,s)},CLOZE:function(a,r,s){return a(r,s)},vWliI:t(1727),yxHFG:function(a,r){return a<<r},kLlTN:function(a,r){return a===r},PZYoZ:t(1558)+"RROR",FPeZw:t(979)+"OR",LjpZs:t(1545)+t(1510),WyjEn:t(537),GHuYB:function(a,r){return a>=r},BQMxt:function(a,r){return a&r},JBNSo:function(a,r){return a<=r},xLWoI:function(a,r){return a|r},rZjtu:function(a,r){return a/r},YygYQ:function(a,r){return a&r},jvmCp:function(a,r){return a&r},UBoGd:function(a,r){return a(r)},ooDEl:function(a,r){return a&r},iTOCi:function(a,r){return a(r)},ufDvU:function(a,r){return a!==r},manPT:t(1319),RuxWF:function(a,r){return a<<r},ywOVs:function(a,r){return a&r},etrTe:function(a,r){return a&r},WnmkW:function(a,r){return a&r},ewRoU:function(a,r){return a&r},klKAb:function(a,r){return a&r},OOJgi:function(a,r){return a(r)},xTALA:function(a,r){return a&r},QpXHp:function(a,r){return a&r},HMFAq:function(a,r){return a|r},UGRom:function(a,r){return a<<r},bjFgx:function(a,r){return a>>>r},FLYyp:function(a,r){return a>>>r},volfl:function(a,r){return a|r},BOYJa:function(a,r){return a>>>r},jATuo:function(a,r){return a===r},OGyZJ:function(a,r){return a===r},pKpYG:function(a,r){return a<r},VlCfB:function(a,r){return a<r},QJdWo:function(a,r){return a<r},hOAHY:function(a,r){return a<r},CLkuI:function(a,r){return a<r},rHPFT:function(a,r,s){return a(r,s)},CYslS:function(a,r){return a+r},InsGB:function(a,r){return a>>>r},UViMp:function(a,r){return a|r},dAOAl:function(a,r){return a+r},FltfV:function(a,r){return a!==r},XYkYj:function(a,r){return a>>>r},hYxJe:function(a,r){return a&r},UqoJP:function(a,r){return a>>>r},Qvqup:function(a,r){return a|r},lTbAr:function(a,r){return a>>>r},OWGgK:function(a,r){return a&r},MtgKk:function(a,r){return a!==r},exxTj:function(a,r){return a+r},qNkpQ:function(a,r){return a+r},nTlKg:function(a,r){return a|r},TxsZn:function(a,r){return a&r},GZMLk:function(a,r){return a+r},dEwDP:function(a,r){return a|r},OLqQt:function(a,r){return a(r)},PXhKC:function(a,r){return a(r)},rOfFM:function(a,r){return a|r},vvack:function(a,r){return a|r},iESqn:t(542),Vtccy:function(a,r){return a<<r},NcVMI:function(a,r){return a|r},OEACH:function(a,r){return a|r},gUpWk:function(a,r){return a|r},sELpY:function(a,r){return a<<r},yCOeE:function(a,r){return a===r},rAcgA:function(a,r){return a>>>r},OerIn:function(a,r){return a<<r},TkgGD:function(a,r){return a<<r},SziAw:function(a,r){return a>>>r},pBNEf:function(a,r){return a<<r},EaRje:function(a,r){return a>>>r},nMAzF:function(a,r){return a&r},crjlr:function(a,r){return a>>>r},gHxWZ:function(a,r){return a&r},CEMAt:function(a,r){return a&r},PfiaG:function(a,r){return a>>>r},bRlNh:function(a,r,s,l){return a(r,s,l)},zxflm:t(1257),LzRqQ:function(a,r){return a||r},vClZK:t(1390),sIOZB:function(a){return a()},OBxeN:function(a,r){return a(r)},HCmnz:function(a,r){return a===r},rFshz:"cPrgT",FKlBX:t(1206),cuPQr:function(a,r){return a|r},XlcAf:function(a,r){return a%r},gNSXT:function(a,r){return a/r},vEDJo:function(a,r){return a+r},IhIKP:function(a,r){return a*r},dOFwo:function(a,r){return a>>>r},IuwTi:function(a,r){return a>>>r},wMHGZ:function(a,r){return a&r},DdnqN:function(a,r){return a>>>r},lpOBc:function(a,r){return a&r},wImYp:function(a,r){return a>>>r},Nfuec:function(a,r){return a>>>r},ihciH:function(a,r){return a===r},JwDoR:function(a,r){return a===r},mdExz:function(a,r){return a===r},rkfvF:function(a,r){return a===r},TrUKQ:function(a,r,s){return a(r,s)},jcTVI:"close",WKDYQ:function(a,r){return a!==r},FZVhe:t(1260),efYxc:t(548),UPfih:function(a,r){return a&r},tnRUF:function(a,r){return a>>>r},XFuqp:function(a,r){return a&r},WaBjX:function(a,r){return a>>>r},ATsrH:function(a,r){return a&r},BZXLh:function(a,r){return a&r},VqlJR:function(a,r){return a>>>r},bHuEe:function(a,r){return a>>>r},OeBSm:function(a,r){return a>>>r},rvCJV:function(a,r){return a&r},TopOJ:t(893)+t(1157),SOZbf:"CONNECTI"+t(968),nPMYw:t(527)+t(1569)+"R",ovrgD:t(1241)+t(417),vbMbm:function(a,r){return a===r},LlNBO:"RPlnt",ctfzt:function(a,r){return a>=r},rVTpb:function(a,r){return a===r},NYOSE:function(a,r){return a==r},JQlRZ:function(a,r){return a>r},pPsUG:"HTnmH",xCoSZ:function(a,r){return a===r},HCwYV:t(1441),rWEDW:function(a,r){return a instanceof r},rcotc:function(a,r){return a+r},PlaUU:t(672)+t(424),YQPub:function(a,r){return a===r},UkynD:function(a,r){return a<r},LKWxV:"bVULv",ynhPM:function(a,r){return a!==r},luoZl:t(861),eOZEu:t(1716),iemQf:t(1696),tYLsL:t(1305),RhsBW:t(1376),PfXkj:t(1426),cLIbt:function(a,r,s){return a(r,s)},rKJtX:function(a,r){return a>=r},viLrM:t(1844),IVqTl:function(a,r){return a instanceof r},ZbcYi:t(1028),suoLK:t(1885),pgJIK:function(a,r){return a||r},EOQOZ:function(a,r){return a!=r},vGDRD:t(1749)+"d",jFwKX:t(770),fyscK:"KOedr",GYvki:function(a,r){return a||r},ZyEXY:function(a,r){return a<=r},Luxgw:t(1710)+t(1153)+t(723)+t(655)+t(547),kIbqp:"TXAVL",OKybG:function(a,r){return a===r},ATmPK:function(a,r){return a&r},GZsjr:function(a,r){return a>=r},hbJJl:function(a,r){return a|r},iAoYu:function(a,r){return a<<r},RYevZ:function(a,r){return a|r},cNvDm:function(a,r){return a<<r},yUrIv:function(a,r){return a&r},LtHKI:function(a,r){return a|r},QPbxu:function(a,r){return a<<r},dcJqm:function(a,r){return a&r},gEFWT:function(a,r){return a&r},EwtTw:function(a,r){return a<r},YzQEU:function(a,r){return a<r},gFhOj:function(a,r){return a>>r},aSChe:function(a,r){return a|r},CZqcr:function(a,r){return a&r},zROVJ:function(a,r){return a===r},qouVV:function(a,r){return a+r},GUKEE:function(a,r){return a<<r},XqcNa:function(a,r){return a&r},eKcle:function(a,r){return a&r},YXRWB:function(a,r){return a|r},gJieD:function(a,r){return a&r},rSUxn:function(a,r){return a>>r},JOvLQ:function(a,r){return a&r},pmPKF:function(a,r){return a>>r},UwUrC:function(a,r){return a==r},yQPyK:t(533),fCQpC:t(1593)+t(1621)+t(1581)+"2",ZyLOF:function(a,r,s,l){return a(r,s,l)},GgkjV:function(a,r){return a<r},qxOUG:function(a,r){return a|r},UfWub:function(a,r){return a<<r},ocXfS:function(a,r){return a<r},gmLQK:function(a,r){return a|r},jZLus:function(a,r){return a<<r},hnjFB:t(1600),MFGtr:function(a,r){return a===r},pLciR:"nlgZk",KqJkg:function(a,r){return a instanceof r},wSYFX:t(616)+"ion/json",jjJzY:t(567)+t(1490)+"et=utf-8",BqDkd:t(1117),vowXH:t(578),rZQHL:t(857),fWvhV:function(a,r){return a>=r},vNTmr:t(1669),AxwOP:t(439)+t(1524),xfNld:function(a,r){return a===r},KTbGF:function(a,r){return a<r},oVcXf:function(a,r){return a+r},eeMlD:t(1317)+"ack=fron"+t(812)+"P",vnxJv:t(1864),hVASo:t(1258),AtiRu:function(a,r){return a-r},wiUrL:function(a,r){return a|r},ifxaP:function(a,r){return a<<r},AFPPl:function(a,r){return a>>r},XlwcY:function(a,r){return a+r},KoytC:t(1567),DRqEy:t(907),ABjdu:t(637),nTlFJ:t(905)+"le",UGsrn:t(1230),RRJQX:t(1476),VRCyl:t(896),oaXCO:function(a,r){return a!==r},NpEBg:t(624),vjtjy:function(a,r,s,l,h){return a(r,s,l,h)},JngJg:t(1498),YmRHN:"AAgjX",WqcXt:function(a,r){return a||r},MzvcL:function(a,r){return a+r},jRIXR:function(a,r){return a!==r},TWhSU:function(a,r){return a|r},pgVgQ:function(a,r){return a!==r},VQaUk:t(1314),DXQek:function(a,r){return a||r},YgtSA:t(1137),emzGo:function(a,r){return a||r},jdOPI:function(a,r){return a!==r},ZwhCh:t(647),hEwZi:t(1554),twIhk:function(a,r){return a||r},ujsRz:function(a,r,s){return a(r,s)},rsAum:t(772),TnEZz:function(a,r){return a!=r},aSPqd:function(a,r){return a!==r},LtKNs:t(1718),MPUrD:function(a,r){return a||r},EnmLL:function(a,r){return a||r},kObSq:function(a,r){return a!=r},AyEOj:t(532)+t(1770)+"d",GtPho:t(874),syvGE:t(859)+"id",xASDS:t(493),QsDkL:function(a,r){return a(r)},yRAcx:function(a,r){return a!==r},OupbV:"YehWa",xXXSV:t(1110),kEXiV:function(a,r,s,l){return a(r,s,l)},cjSFY:t(782)+"er_qos_ack",oSmcf:function(a,r,s,l){return a(r,s,l)},kkjuw:t(782)+"er_ack_msgid",RaleY:function(a,r,s,l){return a(r,s,l)},DTlQK:t(1565),AlytF:function(a,r,s,l){return a(r,s,l)},IMkJc:function(a,r){return a&&r},KBZTR:"DSahj",zEcCI:"Tijly",RAzeU:t(1223),iTyTw:function(a){return a()},pdSVz:t(1122),RXDWy:function(a,r,s){return a(r,s)},bdrmV:function(a,r){return a(r)},ENpEk:function(a,r){return a instanceof r},djbgs:function(a,r){return a===r},hPYKy:t(1480),wRirA:t(594)+"e",BowkP:t(853),AdyIE:function(a,r){return a(r)},fcYXH:function(a,r){return a&r},wjTdG:function(a,r){return a+r},lgcIk:function(a,r){return a>>>r},bRNCF:function(a,r){return a+r},SAGIg:function(a,r){return a+r},ZahFo:t(1242),JzQfF:t(1774),UhbNX:function(a,r){return a&r},bRumu:function(a,r){return a+r},CiDBG:t(1606)+"1",nYuVl:function(a,r){return a+r},gcdgH:function(a,r){return a<<r},HFsgP:function(a,r){return a<<r},xtsPe:function(a,r){return a+r},UrXaN:function(a,r){return a|r},SUinh:function(a,r){return a|r},hcFQm:function(a,r){return a<<r},pFBzq:function(a,r){return a+r},fnvXS:function(a,r){return a<<r},xntOY:function(a,r){return a+r},oHWYe:function(a,r){return a+r},nJUVA:function(a,r){return a+r},EXIFa:function(a,r){return a&r},UXdce:function(a,r){return a+r},OJHxg:function(a,r){return a&r},Bjzyf:function(a,r){return a+r},LFCHi:function(a,r){return a+r},RYyJx:function(a,r){return a+r},mAjfo:function(a,r){return a>>>r},xVfaj:function(a,r){return a instanceof r},aiwFY:t(627),PMfnN:function(a,r){return a+r},OklVI:function(a,r){return a|r},CqRLf:function(a,r){return a&r},ZUWCh:t(1629),bfuWi:"tcOrg",olwnl:function(a,r){return a|r},fXLZx:function(a,r){return a|r},BFBPk:function(a,r){return a|r},vQdeg:function(a,r){return a|r},CHddA:function(a,r){return a&r},wZUoT:t(657)+t(1416),vKqsS:t(438),PhrFA:t(1858)+t(525),yGoqO:function(a,r,s,l){return a(r,s,l)},BwxjC:t(710),sLYit:t(453),LLAyp:"mgVeT",epHwz:t(1631)+t(1077),qMeBX:function(a,r){return a<r},jeQpG:function(a,r,s){return a(r,s)},OkWpi:function(a,r,s,l){return a(r,s,l)},tyTXz:"FILE_NOT_EXIST",uSwPb:function(a,r){return a(r)},CJwpm:function(a,r){return a(r)},WoXBc:t(1353),CToYA:function(a,r,s){return a(r,s)},GJJFA:"cursor_name",UveaR:t(1037),KoHVs:t(941),sxBCL:t(848),WyWOC:function(a){return a()},pyqnZ:"setdb",kKCPo:function(a,r){return a(r)},HUXNo:function(a,r){return a||r},JCQUk:function(a,r){return a===r},lxbCF:t(834),gEARn:t(1872),JeOFB:"code",SVkyg:function(a,r,s,l){return a(r,s,l)},AYFRX:t(782)+t(1325),IYTrp:t(782)+t(796),eysUd:t(1104)+"s",Kkwmb:"x-msg-cursor_name",VLkQS:function(a,r){return a(r)},xBleG:"x-msg-cu"+t(1239)+"ue",zmaIV:function(a,r){return a>r},QZweR:function(a){return a()},MnVxJ:function(a){return a()},QMUFZ:function(a){return a()},HggMn:function(a,r){return a&&r},scNBO:function(a){return a()},PiGWw:t(720)+t(1719)+t(1512)+"g",slIRW:t(794),qmoSu:function(a,r){return a===r},LhWro:t(1204),WDYcq:t(727),ZSQAY:"mqWOB",XQhuu:function(a){return a()},VPCbs:t(851),rBalc:t(447)+t(1408)+"s",uGipg:t(449),MHrCF:function(a,r){return a===r},LUTwX:t(856),bMfmY:function(a,r,s){return a(r,s)},mBSMv:function(a,r,s,l){return a(r,s,l)},LuTtf:function(a,r,s){return a(r,s)},DsDOP:function(a,r){return a&r},RlfXF:function(a,r){return a!==r},nRppZ:t(1442),eYoEw:function(a,r,s){return a(r,s)},nJzgh:function(a,r,s){return a(r,s)},EmIvF:"arraybuf"+t(1883),QfxMF:function(a,r){return a==r},nZUTh:t(833)+t(966)+t(1778),sQxgA:t(833)+t(1380)+t(914)+t(1596)+t(1602)+"tructor "+t(1568)+t(591),zDLgE:function(a,r,s){return a(r,s)},TRNDD:t(943)+"t",RYslu:t(650)+t(1702)+t(1228)+"ct",QDrlx:function(a,r){return a!==r},gdhka:t(1136),Hfdwy:t(757),QIfSl:t(939),eBobB:t(726),NtsqK:t(1589),jmQTx:function(a,r){return a===r},AlzAv:t(440),fMoaN:"offline",NsJTo:function(a,r){return a!==r},hGkgf:function(a,r){return a!==r},MfRkX:function(a,r){return a(r)},qWyom:t(447)+t(641)+"t",NKTYL:function(a,r){return a+r},pjFbe:function(a,r){return a===r},vqkeH:t(946),NPNWC:t(499),vPEEp:t(1657),FCOuQ:"qFNji",houif:t(454),Sybms:"ttwid",MFydx:"device_id",ahkBI:"please p"+t(514)+"ddID, de"+t(1641)+t(978),tUDSw:t(1328),ABcrQ:"web",mrSWP:"fws_1.0.0",AUJfs:"3|2|1|4|0",mXTXL:function(a,r){return a!==r},xdLFc:t(1196),DPThw:function(a,r,s){return a(r,s)},yvzyL:function(a,r,s){return a(r,s)},rwyGC:t(1752),XFUpF:function(a,r){return a>r},wVaLe:function(a,r,s){return a(r,s)},lcpyG:function(a,r){return a(r)},BAmlj:function(a,r){return a(r)},MKroU:"FRONTIER>",nKJOX:function(a,r){return a*r},BsMuR:function(a,r){return a>r},zqJMz:function(a,r){return a===r},MhEFD:function(a,r){return a!==r},rnGwF:t(702),dMPVD:function(a,r){return a*r},wnBTG:t(1109),eaXxK:function(a,r,s){return a(r,s)},HqoVx:function(a,r){return a(r)},nUMWM:"send_ack",qGlVk:t(1425)+"4",cwihP:function(a,r){return a>=r},qJaJf:function(a,r){return a<r},qIIoh:function(a,r){return a<r},DBREy:"IddTY",PSArI:"CwIhD",gMeeY:function(a,r,s){return a(r,s)},OmWtM:t(512)+"ay, network offline",sZaIf:function(a,r,s){return a(r,s)},amngr:t(1873),NMQkl:t(1818),NYuWE:t(855),okiWl:t(989),RTEoO:"SzizB",SCZsi:function(a,r){return a!==r},rMpuf:t(1537),fjisr:t(486)+"5|3|7|2",qADVA:t(574)+t(1360)+t(725)+t(1526)+"ed",ACHvB:t(574)+t(1009)+t(940),UixGz:function(a,r){return a==r},Qeroq:"please provide a"+t(1095)+t(1645)+"a must b"+t(1058)+t(1551)+t(982)+t(1326),ObWUr:function(a,r){return a==r},GreyS:"number",LNPqO:function(a,r){return a instanceof r},OtAqv:function(a,r){return a(r)},IpHTZ:function(a,r){return a(r)},rrDOx:"please p"+t(773)+t(786)+t(1416),PpBrL:t(1750),KQXpA:t(958),vcEaw:function(a,r){return a||r},YFaYp:function(a,r){return a==r},IHUcW:function(a,r){return a!==r},pvxCp:"manual r"+t(880)+t(511),XrYtu:function(a,r,s){return a(r,s)},VBTCZ:function(a,r){return a===r},gojYI:t(1019),Mnzeb:t(898),iMBzP:function(a,r){return a*r},Gpxkl:function(a,r){return a*r},CvCKs:function(a,r){return a/r},RXwXz:function(a,r){return a!=r},jzHdf:function(a,r){return a===r},jvVIm:t(784),rrOUj:t(1251),KGqCu:"Dedicate"+t(1116)+t(1468)+"pe",OzqhB:function(a,r){return a!=r},VntOT:function(a,r){return a===r},AichC:function(a,r){return a==r},LtkWh:function(a,r){return a!=r},WLXJe:function(a,r){return a!=r},qzagt:function(a,r){return a===r},dGtzT:t(735)+t(712)+"alScope",kXZnz:t(808)+t(1180)+"balScope",kdkww:function(a,r){return a!=r},IJFfy:function(a,r){return a!=r},tVcMG:function(a,r){return a!=r},bxdBR:function(a,r){return a!=r},KyfBl:t(1875)+"qos__"};Nt.r(Ce),Nt.d(Ce,{FWS:()=>yg,CustomErrorEvent:()=>nl,createCloseEvent:()=>xt,ReconnectEvent:()=>tl,createErrorEvent:()=>ot,decodedFrame:()=>Qt,createOpenEvent:()=>cl,CustomCloseEvent:()=>rl,createReconnectEvent:()=>la,FrontierMessageEvent:()=>sl,encodeFrame:()=>Ft,createMessageEvent:()=>al,OpenEvent:()=>ol,ErrorCode:()=>tn,Event:()=>tr,MessageEvent:()=>il});let n="";function i(a=""){let r=t,s="02",l=""+Date[r(405)](),h=n||(n=e[r(1585)](f,a)),p=Math[r(1125)]()[r(1067)](16)[r(386)](-6);return e[r(534)](e.xYleL(s+l,h),p)}function o(){let a=t;return e[a(534)](e[a(1846)](1e4,Date[a(405)]()),Math[a(1234)](1e4*Math[a(1125)]()))}function c(a){let r=t;return e[r(1128)](e.HRdKZ(Array,8)[r(1768)]("0"),parseInt(a,10).toString(2))[r(386)](-8)}function d(a){let r=t;return e[r(638)](e.oVnMW,e[r(951)])?(_0x2b4228[r(1043)](_0x5c8f7),!1):(Array(4)[r(1768)]("0")+parseInt(a,2)[r(1067)](16))[r(386)](-4)}function u(a){let r=t,s=a.split(/\./)[r(902)](p=>c(p)),l=[];return l[0]=d(s[0]+s[1]),l[1]=e[r(1585)](d,e[r(433)](s[2],s[3])),[r(1841),e[r(404)],e[r(404)],e.fmBWe,e[r(404)],e[r(618)],l[0],l[1]].join("")}function f(a){let r=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[r(1529)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[r(1529)](a);return s?u(a):l?x(a):e[r(367)]}function x(a){let r=t,s="",l=[],h=0,p=0,_=!0,E=e[r(404)];if(e[r(1492)](a[r(481)]("::"),-1)){let m=a[r(798)]("::");for(let N=0;e[r(1002)](N,m[r(1078)]);N++){let q=m[N];if(q.indexOf(":")>0)if(e[r(1406)](r(963),e[r(1245)]))this[r(1256)+r(1016)]=_0xcd4b4e,this.count=0;else{let W=q[r(798)](":");_&&(h=W[r(1078)]),p+=W.length;for(let V=0;e.hMYZN(V,W[r(1078)]);V++)if(e[r(638)](4,W[V][r(1078)])){let qe=E.substring(0,e[r(579)](4,W[V].length)),rn=qe[r(1475)](W[V]);l[r(1777)](rn)}else l[r(1777)](W[V]);_=!1}else{if(e[r(1597)](4,q[r(1078)])){let W=E[r(1291)+"g"](0,e[r(1160)](4,q[r(1078)])),V=W[r(1475)](q);l.push(V)}else l[r(1777)](q);_&&(h+=1),p+=1,_=!1}}let O="";for(let N=0;N<e[r(1160)](8,p);N++)O=O[r(1475)](E);for(let N=0;e[r(1002)](N,l[r(1078)]);N++)e[r(1406)](N,h)?(s=s.concat(O),s=s.concat(l[N])):s=s[r(1475)](l[N]);return s}if(e[r(922)](e.zKFQM,e.zKFQM)){let m=a[r(798)](":");for(let O=0;e[r(1002)](O,m.length);O++){let N=m[O];if(e[r(1292)](4,m[O][r(1078)])){let q=E[r(1291)+"g"](0,e[r(1160)](4,m[O][r(1078)])),W=q[r(1475)](N);s=s[r(1475)](W)}else s=s.concat(N)}return s}else return this[r(1167)][r(1785)]}function g(a,r){let s=t,l=a[s(563)];e[s(638)](void 0,l)&&(e[s(832)](xe,r,10),e[s(832)](z,r,l));let h=a[s(1866)];if(h!==void 0)if(e[s(1381)](e[s(1684)],e.SBhyz))e.EfJzu(xe,r,18),e[s(1354)](z,r,h);else return new _0x314814(_0x583a5d,{data:_0x3c130c})}function w(a){let r=t,s={wIJgS:r(439)+r(1524),tMGeH:e[r(560)],QdMOT:function(l,h){return e[r(433)](l,h)},XzFbE:e[r(408)],aqeJT:r(1317)+r(1556)+r(812)+"P"};if(e[r(1876)](e[r(767)],e.YtIYl)){let l={atSwY:function(p,_){return p(_)},yFuBx:s[r(1618)]},h=_0x3510fc[r(464)+r(1001)]("script");_0x31595a[r(1832)+r(1166)]=p=>{let _=r;_0x3c6a0b[_(1469)]["removeCh"+_(648)](h),_0x5340bb["frontier"+_(1166)]=void 0,l.atSwY(_0x331842,p&&p[_(844)]||l[_(1796)])},h[r(1649)]=s.tMGeH,h[r(807)]=s[r(1038)](_0x2f74d5.replace(/^ws/,s[r(1488)]),s.aqeJT);try{_0xc7d199[r(1469)][r(1155)+r(648)](h)}catch{_0x419b87.body.removeChild(h)}}else{let l={};e:for(;!$(a);){let h=e.EtowY(he,a);switch(e.PAMmD(h,3)){case 0:break e;case 1:l.key=R(a,e.OUDZg(he,a));break;case 2:l.value=e[r(937)](R,a,he(a));break;default:T(a,7&h)}}if(e[r(1406)](void 0,l[r(563)]))throw new Error(e[r(619)]);if(e.UHflf(void 0,l[r(1866)]))throw new Error(e[r(755)]);return l}}function S(a){let r=t,s=e[r(737)](C);return e[r(1354)](y,a,s),e[r(1668)](M,s)}function y(a,r){let s=t,l=a[s(649)];e[s(1352)](void 0,l)&&(e[s(1849)](xe,r,8),e[s(1133)](ht,r,l));let h=a[s(827)];h!==void 0&&(xe(r,16),e[s(832)](ht,r,h));let p=a[s(438)];if(e[s(1381)](void 0,p)){if(e[s(991)](e[s(1066)],e[s(1087)]))return _0x600dfb?_0x22f554[s(478)+"sLE"](_0x288da4,_0x13f6ed):_0x202c7e[s(478)+"sBE"](_0xa15b5,_0x1ca1a1);e.KKacT(xe,r,24),e[s(625)](ht,r,e.OUDZg(P,p))}let _=a[s(1350)];_!==void 0&&(e.Lzndx(xe,r,32),e[s(663)](ht,r,e[s(1676)](P,_)));let E=a[s(1740)];if(e[s(1063)](void 0,E))for(let rn of E){e.giIyy(xe,r,42);let pt=e[s(1671)](C);e[s(1277)](g,rn,pt),e.KYqvj(xe,r,pt[s(703)]),e[s(625)](H,r,pt),e[s(865)](D,pt)}let m=a[s(1829)+s(734)];e[s(1263)](void 0,m)&&(e[s(832)](xe,r,50),e[s(1008)](z,r,m));let O=a[s(629)+"ype"];O!==void 0&&(e[s(675)](xe,r,58),e[s(394)](z,r,O));let N=a[s(910)];N!==void 0&&(e[s(1470)](xe,r,66),e[s(1133)](xe,r,N.length),e[s(394)](se,r,N));let q=a[s(1513)];e[s(1614)](void 0,q)&&(e[s(538)]!==s(576)?(xe(r,74),e[s(1202)](z,r,q)):this[s(906)+s(1491)]=null);let W=a[s(1833)+s(1040)];e[s(911)](void 0,W)&&(xe(r,82),e.SquGz(z,r,W));let V=a[s(1484)];e.GGZnW(void 0,V)&&(e[s(1308)](xe,r,90),e[s(1338)](z,r,V));let qe=a[s(427)+"e"];qe!==void 0&&(e[s(1274)](xe,r,96),ht(r,P(qe)))}function v(a){let r=t;if(e.GPsfX(e.IkQxJ,e[r(1701)]))_0x208d41=e[r(571)](_0x44910a,_0x351fff),_0x32263d=0;else return I(e.OUDZg(B,a))}function I(a){let r=t;if(e.GPsfX(e.bhAvr,r(461))){let s={};e:for(;!e.RIzDb($,a);){let l=e[r(1115)](he,a);switch(e[r(1347)](l,3)){case 0:break e;case 1:s.SeqID=e[r(488)](vt,a,!0);break;case 2:s[r(827)]=e[r(1308)](vt,a,!0);break;case 3:s.service=e[r(1034)](he,a);break;case 4:s[r(1350)]=e.zWjTR(he,a);break;case 5:{let h=A(a);(s.headers||(s[r(1740)]=[]))[r(1777)](w(a)),a.limit=h;break}case 6:s[r(1829)+r(734)]=e[r(1553)](R,a,e.HRdKZ(he,a));break;case 7:s["payloadT"+r(1051)]=e[r(1477)](R,a,e[r(1373)](he,a));break;case 8:s[r(910)]=ie(a,e[r(1301)](he,a));break;case 9:s[r(1513)]=e[r(1867)](R,a,e[r(1006)](he,a));break;case 10:s[r(1833)+r(1040)]=e[r(662)](R,a,e[r(1747)](he,a));break;case 11:s[r(1484)]=e.oDKSi(R,a,he(a));break;case 12:s[r(427)+"e"]=e[r(491)](he,a);break;default:T(a,7&l)}}if(s[r(649)]===void 0)throw new Error(r(1030)+r(825)+r(1495)+r(649));if(e.GPsfX(void 0,s[r(827)]))throw new Error(e[r(1734)]);if(e[r(991)](void 0,s.service))throw new Error(e[r(1552)]);if(e.CIunx(void 0,s[r(1350)]))throw new Error(e[r(1383)]);return s}else _0x5f2fa8[_0x4eb26f[_0x12f9c9]["cursor_n"+r(1575)]]=_0x31fafe(_0x308d2f[_0x1d7139][r(541)+"ame"]),_0x2d511a+=e.xYleL(14,_0x316586[_0x4fbd97[_0xe21d7e][r(541)+"ame"]])}function A(a){let r=t,s=e[r(1451)](he,a),l=a[r(703)];return a.limit=e[r(1128)](a[r(646)],s),l}function T(a,r){let s=t;switch(r){case 0:for(;e[s(507)](128,ee(a)););break;case 2:e.WWlSS(J,a,e[s(1259)](he,a));break;case 5:J(a,4);break;case 1:e[s(1888)](J,a,8);break;default:throw new Error(e[s(425)](e.urPfz,r))}}function P(a){return a|=0,{low:a,high:e.aYFwn(a,31),unsigned:e.TRYkt(a,0)}}let b=[];function C(){let a=t,r=b[a(1096)]();return r?(r[a(646)]=r.limit=0,r):{bytes:new Uint8Array(64),offset:0,limit:0}}function D(a){b[t(1777)](a)}function B(a){return{bytes:a,offset:0,limit:a.length}}function M(a){let r=t,s=a[r(1756)],l=a[r(703)];return e[r(1651)](s[r(1078)],l)?s:s[r(1348)](0,l)}function J(a,r){let s=t;if(e[s(1538)](e[s(445)](a[s(646)],r),a.limit))throw new Error(e[s(1584)]);a[s(646)]+=r}function $(a){let r=t,s={fmSEH:function(l){return e.VYvHO(l)}};if(e[r(1572)](e.MFdsq,e.fEnNC)){let l=this[r(1678)+r(1283)]?.[r(1159)+r(961)+"nt"]();this[r(1414)](r(1688)+l),s.fmSEH(_0x24b658)}else return e[r(1183)](a[r(646)],a[r(703)])}function ne(a,r){let s=t,l=a[s(1756)],h=a[s(646)],p=a[s(703)],_=e[s(534)](h,r);if(e[s(1492)](_,l[s(1078)])){let E=new Uint8Array(e.Gakus(2,_));E[s(1762)](l),a[s(1756)]=E}return a.offset=_,e[s(1538)](_,p)&&(a[s(703)]=_),h}function Z(a,r){let s=t,l=a[s(646)];if(e.MbeIn(l+r,a[s(703)]))throw new Error(s(1574)+"t limit");return a[s(646)]+=r,l}function ie(a,r){let s=t,l=e.ZgYVa(Z,a,r);return a.bytes[s(1348)](l,e[s(1128)](l,r))}function se(a,r){let s=e.vQElk(ne,a,r.length);a.bytes.set(r,s)}function R(a,r){let s=t;if(e[s(403)]!==e[s(997)]){let l=Z(a,r),h=String[s(1859)+s(1662)],p=a.bytes,_="\uFFFD",E="";for(let m=0;e.hMYZN(m,r);m++)if(e[s(1421)]!==e[s(1421)])this.emit(e[s(707)],e[s(832)](_0x5c2ae4,s(1337),{..._0x3dcdd9,data:_0x3dd354.errMsg||""}));else{let O=p[e[s(445)](m,l)],N,q,W,V;e[s(1406)](e[s(973)](128,O),0)?E+=e[s(1630)](h,O):e[s(973)](224,O)===192?e[s(1056)](e[s(781)](m,1),r)?E+=_:(N=p[e[s(425)](e[s(1082)](m,l),1)],(192&N)!==128?E+=_:(V=e.GbsYL(e.AkiGU(31,O),6)|e[s(973)](63,N),V<128?E+=_:e[s(817)]("VNSWQ",e[s(994)])?(E+=h(V),m++):(_0x2d0c1b=_0x3cc289[e[s(1003)](_0x3c5dff+_0x5666f7,1)],_0x475151=_0x515c9e[e[s(781)](e[s(534)](_0x4e8928,_0xb34cc9),2)],(e[s(501)](_0x11ae3a,e[s(1564)](_0x5c8062,8))&49344)!==32896?_0x52f8e5+=_0xc1a4da:(_0x392c50=e[s(501)](e[s(974)](e[s(1695)](e[s(1518)](15,_0x373cf2),12),e[s(1564)](e.yNhMU(63,_0x2939cf),6)),e[s(973)](63,_0x4d8778)),e[s(1002)](_0xc6c001,2048)||e[s(1183)](_0x5315d5,55296)&&e.olyFb(_0x219163,57343)?_0x28f5e1+=_0x545fc1:(_0x5706d0+=e.qShbh(_0x12e1cc,_0x33a132),_0xa2c66e+=2))))):e.ejTuR(e[s(1518)](240,O),224)?e[s(903)](e[s(433)](m,2),r)?E+=_:(N=p[e.pvWex(m,l)+1],q=p[e.QfQsC(m+l,2)],e[s(1120)](e.XrsMI(e.kmhoL(N,q<<8),49344),32896)?E+=_:(V=e[s(974)](e.mJaQO(15&O,12),e.mJaQO(e.XhjMV(63,N),6))|e.yNhMU(63,q),e.NSEPU(V,2048)||V>=55296&&e[s(992)](V,57343)?E+=_:(E+=h(V),m+=2))):e[s(1050)](e[s(1518)](248,O),240)?e[s(1183)](e.DxDqu(m,3),r)?E+=_:(N=p[e[s(1605)](e[s(781)](m,l),1)],q=p[e[s(1082)](e[s(792)](m,l),2)],W=p[e[s(792)](e[s(1128)](m,l),3)],e[s(969)]((e[s(974)](N,e[s(845)](q,8))|W<<16)&12632256,8421504)?E+=_:(V=e[s(1084)](e[s(974)]((7&O)<<18,e.XDVXo(e.AkiGU(63,N),12))|e.jhXjl(63,q)<<6,e[s(973)](63,W)),e[s(929)](V,65536)||V>1114111?E+=_:(V-=65536,E+=e[s(1470)](h,e.TJHVY(e[s(1309)](V,10),55296),e[s(621)](e[s(1518)](1023,V),56320)),m+=3))):E+=_}return E}else return new _0x4dcd20(_0x5c72af)}function z(a,r){let s=t,l=r.length,h=0;for(let E=0;e[s(1002)](E,l);E++){let m=r[s(1074)+"At"](E);e[s(1135)](m,55296)&&e[s(593)](m,56319)&&e.kgWsX(E+1,l)&&(m=e[s(1198)](m,10)+r[s(1074)+"At"](++E)-56613888),h+=e[s(1792)](m,128)?1:m<2048?2:m<65536?3:4}e[s(1098)](xe,a,h);let p=ne(a,h),_=a.bytes;for(let E=0;e.jndSm(E,l);E++){let m=r[s(1074)+"At"](E);if(e[s(1208)](m,55296)&&m<=56319&&e.JCRfU(e[s(1128)](E,1),l)&&(m=e[s(583)](e[s(534)](e[s(1198)](m,10),r[s(1074)+"At"](++E)),56613888)),m<128)_[p++]=m;else{if(e[s(929)](m,2048))_[p++]=e[s(1143)](m,6)&31|192;else{if(e.kgWsX(m,65536))_[p++]=e[s(1309)](m,12)&15|224;else if(e[s(1576)](s(1222),e[s(1092)]))_[p++]=e[s(974)](m>>18&7,240),_[p++]=e[s(1852)](e.sNqaX(m,12)&63,128);else return _0xc1c3f6||(_0x5721b4=[_0x53c54b,_0x1cfb6f,_0x27278b,_0x2f2a3b,_0x12b27d]);_[p++]=e[s(444)](e[s(1046)](m,6),63)|128}_[p++]=e.wupdl(e[s(413)](63,m),128)}}}function H(a,r){let s=t,l=e.NTeZK(ne,a,r[s(703)]),h=a[s(1756)],p=r[s(1756)];for(let _=0,E=r[s(703)];e[s(929)](_,E);_++)h[e.aFROf(_,l)]=p[_]}function ee(a){let r=t;return a[r(1756)][e[r(1101)](Z,a,1)]}function Ze(a,r){let s=t;if(!e[s(1651)](e[s(689)],s(1e3))){let l=e[s(900)](ne,a,1);a[s(1756)][l]=r}}function he(a){let r=t,s={mRsao:function(_,E){return _|E},JarUF:function(_,E){return _<<E},PWTfz:function(_,E){return e[U(501)](_,E)},ZNfJp:function(_,E){return e.uaUOu(_,E)},dCnYA:function(_,E){return e[U(1791)](_,E)}},l=0,h=0,p;do{if(e[r(815)](r(496),r(415)))return new _0x1bf6a2(s[r(380)](s[r(380)](s.mRsao(_0x4bc33a[0],s[r(949)](_0x7ed1e1[1],8)),_0x39ce0c[2]<<16),_0x3c8b48[3]<<24),s.PWTfz(s[r(769)](_0x1e18c1[4],s[r(1073)](_0x3aa092[5],8))|_0x13983f[6]<<16,_0xf706d4[7]<<24),_0x3d7933);p=e.RIzDb(ee,a),e[r(1792)](l,32)&&(h|=(127&p)<<l),l+=7}while(e[r(462)](128,p));return h}function xe(a,r){let s=t,l={BazLk:s(1615)+s(968),enexC:"MAX_RETRIES_ERROR",ddIXu:e[s(450)],qCziK:e[s(407)],rgAqz:e[s(1798)]};if(e[s(991)](s(1795),e[s(535)])){let h=(s(858)+s(1398))[s(798)]("|"),p=0;for(;;){switch(h[p++]){case"0":_0x1172b1[_0x589bc7[l.BazLk]=5002]=l[s(1732)];continue;case"1":return _0xd59bb5;case"2":_0x307024[_0x5af4f5[l[s(477)]]=5003]=l[s(477)];continue;case"3":_0x93e966[_0x585c6b[l[s(584)]]=5001]=l[s(584)];continue;case"4":_0xe7626d[_0xdcbe83[l.qCziK]=5005]=l[s(400)];continue;case"5":_0x33ac9c[_0x1dc7a5[l[s(1254)]]=5004]=l.rgAqz;continue}break}}else{for(r>>>=0;e[s(393)](r,128);)e[s(1101)](Ze,a,e[s(974)](e[s(916)](127,r),128)),r>>>=7;Ze(a,r)}}function vt(a,r){let s=t,l=0,h=0,p=0,_;if(_=ee(a),l=e[s(431)](127,_),e[s(1313)](128,_)&&(_=e[s(721)](ee,a),l|=e[s(1791)](127&_,7),e[s(1590)](128,_)&&(_=e[s(518)](ee,a),l|=e[s(845)](e.jvmCp(127,_),14),e.ELUUe(128,_))))if(e.ufDvU(e[s(1755)],s(1319))){if(_0x2d20c0(_0x1821ba))return _0x460d10?_0x2dc886:_0x38268b;if(_0x59f65e){if(_0x4b0415>=_0x52380c)return _0x133f42}else{if(e[s(550)](_0x458a37,-_0x105a07))return _0x5c5d4d;if(e[s(1135)](_0x3a0bde+1,_0x330b07))return _0x255e55}return _0x2010b0[s(1042)](e.kmhoL(_0x330fe1%_0x6a92e9,0),e.xLWoI(e[s(1687)](_0x4af470,_0x4ffb5a),0),_0xd353e8)}else _=e[s(1006)](ee,a),l|=e[s(1017)](e.ywOVs(127,_),21),e[s(600)](128,_)&&(_=ee(a),h=e[s(1094)](127,_),e[s(916)](128,_)&&(_=e[s(1373)](ee,a),h|=(127&_)<<7,e[s(1370)](128,_)&&(_=e[s(1747)](ee,a),h|=e.mJaQO(e[s(1780)](127,_),14),128&_&&(_=e[s(1675)](ee,a),h|=e[s(1198)](e[s(916)](127,_),21),128&_&&(_=e.OOJgi(ee,a),p=e[s(1579)](127,_),e[s(418)](128,_)&&(_=e.dIDhY(ee,a),p|=e[s(600)](127,_)<<7))))));return{low:e[s(1697)](l,e[s(1695)](h,28)),high:e.PAMmD(h,4)|e.UGRom(p,24),unsigned:r}}function ht(a,r){let s=t,l=e[s(756)](r[s(1617)],0),h=e[s(764)](e[s(1705)](e[s(700)](r.low,28),r[s(1509)]<<4),0),p=e[s(756)](r.high,24),_=e[s(1148)](0,p)?e[s(1021)](0,h)?e[s(1813)](l,16384)?e[s(1789)](l,128)?1:2:e[s(1870)](l,2097152)?3:4:e[s(1789)](h,16384)?h<128?5:6:e[s(1625)](h,2097152)?7:8:e[s(1715)](p,128)?9:10,E=e[s(1514)](ne,a,_),m=a[s(1756)];switch(_){case 10:m[e[s(690)](E,9)]=e[s(818)](p,7)&1;case 9:m[e[s(1003)](E,8)]=e[s(1263)](9,_)?e.UViMp(128,p):e[s(1579)](127,p);case 8:m[e[s(1307)](E,7)]=e[s(1126)](8,_)?h>>>21|128:e[s(1775)](h,21)&127;case 7:m[e[s(1003)](E,6)]=e.CJRVp(7,_)?e[s(1705)](h>>>14,128):e[s(476)](e[s(530)](h,14),127);case 6:m[E+5]=_!==6?e[s(522)](e[s(1267)](h,7),128):e.OWGgK(e[s(732)](h,7),127);case 5:m[e[s(1082)](E,4)]=e[s(381)](5,_)?e[s(1697)](128,h):e[s(507)](127,h);case 4:m[e[s(1365)](E,3)]=_!==4?e[s(1387)](l>>>21,128):e[s(756)](l,21)&127;case 3:m[e[s(677)](E,2)]=_!==3?e.nTlKg(e[s(1775)](l,14),128):e[s(860)](l>>>14,127);case 2:m[e.GZMLk(E,1)]=_!==2?l>>>7|128:e[s(1097)](e[s(530)](l,7),127);case 1:m[E]=e[s(1403)](1,_)?e.dEwDP(128,l):127&l}}function Qt(a){return e[t(606)](v,a)}function Ft(a){return e[t(428)](S,a)}let en=65536,Yr=t(1025),we=e.iMBzP(en,en),Ie=e[t(1660)](we,we),er=e.CvCKs(Ie,2),Pe=String[t(708)+"e"][t(1074)+"At"];class ue{constructor(r,s,l){let h=t;this[h(1177)]=!0,this[h(1617)]=e[h(718)](0,r),this[h(1509)]=e[h(964)](0,s),this[h(1682)]=!!l}static[t(1177)](r){let s=t;return r&&e[s(991)](!0,r[s(1177)])}static fromBits(r,s,l){let h=t;return e[h(1086)]==="oqxoh"?e[h(903)](this[h(482)],this[h(1256)+h(1016)]):new ue(r,s,l)}static[t(478)+"s"](r,s,l){let h=t;return l?ue[h(478)+h(379)](r,s):ue["fromByte"+h(1386)](r,s)}static["fromByte"+t(379)](r,s){let l=t;return new ue(r[0]|r[1]<<8|e.yxHFG(r[2],16)|e[l(1791)](r[3],24),e[l(1522)](e.XeotS(r[4],e[l(1564)](r[5],8))|e[l(1791)](r[6],16),e[l(1757)](r[7],24)),s)}static[t(478)+"sBE"](r,s){let l=t;return new ue(e.dEwDP(e[l(501)](e.NcVMI(e[l(1603)](r[4],24),e[l(1017)](r[5],16)),e[l(1791)](r[6],8)),r[7]),e[l(879)](e[l(1387)](e[l(1763)](e.sELpY(r[0],24),r[1]<<16),r[2]<<8),r[3]),s)}static[t(1282)](r){let s=t;return e.yCOeE(r,Yr)?el:new ue(e[s(1570)](e[s(1522)](e[s(501)](e[s(1084)](Pe[s(1225)](r,0),e[s(1784)](Pe[s(1225)](r,1),8)),Pe[s(1225)](r,2)<<16),e[s(1275)](Pe.call(r,3),24)),0),e.SziAw(e[s(1697)](Pe[s(1225)](r,4),e[s(1424)](Pe[s(1225)](r,5),8))|e.sELpY(Pe[s(1225)](r,6),16)|e[s(653)](Pe[s(1225)](r,7),24),0),!0)}[t(1271)](){let r=t;return String[r(1859)+r(1662)](e.OWGgK(255,this[r(1617)]),e[r(810)](this.low,8)&255,e[r(1269)](e.crjlr(this[r(1617)],16),255),this[r(1617)]>>>24,e[r(1294)](255,this[r(1509)]),e[r(418)](e[r(764)](this[r(1509)],8),255),e[r(1032)](e.PfiaG(this.high,16),255),e[r(810)](this[r(1509)],24))}static[t(876)+"er"](r,s=!0){let l=t,h={ILFhF:function(p,_,E,m){return e[U(800)](p,_,E,m)},yJCRc:l(1223),CAinB:e[l(1280)],oyaSu:function(p,_){return e[l(1623)](p,_)},NTvDj:e.vClZK,QkOTH:function(p){return e.sIOZB(p)}};if(e[l(795)](isNaN,r))return s?Dp:el;if(s){if(r>=Ie)return Lp}else if(e.HCmnz(e[l(1388)],e.FKlBX)){let{enableAutoAck:p}=this._options,_=h.ILFhF(_0x4edf33,_0x370470[l(1426)].headers,"need_ack","1"),E=_0xb306b3(_0x37f120[l(1426)][l(1740)],h[l(1192)],"1"),m=_0x2d70c9[l(1225)](this,_0x49b91b);if(p&&_){let{SeqID:O,LogID:N,service:q,LogIDNew:W,method:V}=_0x133965[l(1426)];this[l(1332)]({SeqID:O,LogID:N,LogIDNew:W,service:q,method:V,headers:[{key:"is_ack",value:"1"},{key:h[l(1061)],value:h[l(1072)](W,"")},{key:h[l(824)],value:"0"}]})}E&&!m.isQoSAck&&this["_dispatc"+l(871)+l(752)](_0x554ae9),h.QkOTH(_0x1d0fe9)}else{if(e[l(593)](r,-er))return Np;if(r+1>=er)return Op}return ue[l(1042)](e[l(1091)](e[l(882)](r,we),0),e[l(501)](e.gNSXT(r,we),0),s)}toNumber(){let r=t;return this[r(1682)]?e.vEDJo(e.IhIKP(e[r(756)](this[r(1509)],0),we),e[r(1296)](this[r(1617)],0)):this[r(1509)]*we+e[r(732)](this.low,0)}[t(1231)](){let r=t;return e[r(922)](0,this[r(1509)])&&e[r(1572)](0,this[r(1617)])}add(r){let s=t;ue[s(1177)](r)||(r=ue[s(876)+"er"](r));let l=e[s(1616)](this[s(1509)],16),h=e[s(502)](65535,this[s(1509)]),p=e[s(1311)](this[s(1617)],16),_=e[s(1590)](65535,this[s(1617)]),E=r.high>>>16,m=e.lpOBc(65535,r.high),O=e[s(717)](r.low,16),N=e[s(860)](65535,r[s(1617)]),q=0,W=0,V=0,qe=0;return qe+=e.lIysB(_,N),V+=e[s(766)](qe,16),qe&=65535,V+=e[s(781)](p,O),W+=V>>>16,V&=65535,W+=h+m,q+=W>>>16,W&=65535,q+=l+E,q&=65535,ue[s(1042)](e[s(1880)](e[s(1275)](V,16),qe),e[s(1198)](q,16)|W,this[s(1682)])}equals(r){let s=t;return ue[s(1177)](r)||(r=ue[s(876)+"er"](r)),this.unsigned!==r.unsigned&&this[s(1509)]>>>31===1&&e[s(1834)](r[s(1509)]>>>31,1)?!1:e.JwDoR(this.high,r[s(1509)])&&e[s(473)](this[s(1617)],r[s(1617)])}[t(1741)](){let r=t;return e[r(1651)](-1,this[r(1617)])&&e.kLlTN(-1,this[r(1509)])?ue[r(1042)](0,0,this.unsigned):e[r(509)](-1,this[r(1617)])?ue.fromBits(0,e.GZMLk(this.high,1),this[r(1682)]):ue[r(1042)](e.vEDJo(this.low,1),this[r(1509)],this[r(1682)])}toBytes(r){return r?this.toBytesLE():this[t(1857)+"E"]()}toBytesLE(){let r=t;if(e.WKDYQ(e[r(524)],e[r(1814)])){let s=this.high,l=this[r(1617)];return[e[r(1288)](255,l),e[r(1370)](e[r(899)](l,8),255),e[r(498)](e[r(1638)](l,16),255),l>>>24,e.ATsrH(255,s),e[r(1335)](e[r(759)](s,8),255),e[r(998)](e[r(685)](s,16),255),e.InsGB(s,24)]}else{let s=this._options[r(943)+"tInterce"+r(862)](_0x5debe5,_0x1c6457);this[r(669)+r(1521)+r(543)](e[r(1494)](_0x58d41a,e.jcTVI,{code:_0x5e2956,reason:_0x70de7d,wasClean:!0,willReconnect:s})),s&&this[r(1674)]()}}[t(1857)+"E"](){let r=t,s=this.high,l=this.low;return[s>>>24,e[r(1643)](s,16)&255,e.ewRoU(s>>>8,255),e[r(1673)](255,s),e[r(530)](l,24),e[r(507)](e.PfiaG(l,16),255),e[r(1647)](l>>>8,255),e.jhXjl(255,l)]}}let el=new ue(0,0,!1),Dp=new ue(0,0,!0),Op=ue[t(1042)](-1,2147483647,!1),Lp=ue[t(1042)](-1,-1,!0),Np=ue[t(1042)](0,-2147483648,!1);var tn=(function(a){let r=t,s=e[r(1321)][r(798)]("|"),l=0;for(;;){switch(s[l++]){case"0":a[a[e.SOZbf]=5002]=e[r(875)];continue;case"1":a[a[e[r(1798)]]=5004]=r(1545)+r(1510);continue;case"2":a[a[r(979)+"OR"]=5005]=e[r(407)];continue;case"3":a[a[e[r(1578)]]=5003]=e[r(1578)];continue;case"4":return a;case"5":a[a[e.PZYoZ]=5001]=e[r(450)];continue}break}})({});class tr{constructor(r){let s=t;this.type=r,this[s(1278)]=null}}class tl extends tr{constructor(r,s){let l=t;super(r),this[l(1426)]=s&&s.message||null}}class nl extends tr{constructor(r,s){let l=t,h=e[l(676)][l(798)]("|"),p=0;for(;;){switch(h[p++]){case"0":this[l(390)]=s&&s.lineno||0;continue;case"1":this.colno=s&&s[l(995)]||0;continue;case"2":this[l(1227)]=s&&s[l(1227)]||"";continue;case"3":this.error=s&&s[l(1441)]||null;continue;case"4":this.code=s&&s.code||5001;continue;case"5":super(r);continue;case"6":this[l(1426)]=s&&s.message||"";continue}break}}}class rl extends tr{constructor(r,s){let l=t;super(r),this[l(397)]=s&&s[l(397)]||0,this[l(1524)]=s&&s[l(1524)]||"",this.wasClean=s&&s.wasClean||!1,this[l(787)+l(774)]=s&&s[l(787)+l(774)]||!1}}class il extends tr{constructor(r,s){let l=t;super(r),this[l(630)]=s&&s[l(630)]||null}}class sl extends il{constructor(r,s){let l=t;e[l(1270)](l(805),e[l(1371)])?(e[l(1668)](_0x49793d,this[l(1674)+l(1714)+l(1802)]),this[l(1674)+"ionTimeo"+l(1802)]=null):(super(r),this[l(630)]=s&&s[l(630)]||null,this.message=s&&s.message||null)}}class ol extends tr{constructor(r,s){let l=t;super(r),this[l(630)]=s&&s[l(630)]||null}}function ot(a,{message:r,code:s,error:l}){return new nl(a,{message:r,code:s,error:l})}function xt(a,{code:r,reason:s,wasClean:l,willReconnect:h}){return new rl(a,{code:r,reason:s,wasClean:l,willReconnect:h})}function al(a,{data:r,message:s}){return new sl(a,{data:r,message:s})}function cl(a,{data:r}){return new ol(a,{data:r})}function la(a,{message:r}){return new tl(a,{message:r})}class dl{constructor(r,s){let l=t;this[l(1179)+"s"]=r,this[l(1456)+"es"]=s,this.currentIndex=0,this.currentEndpointTriesCount=0}[t(1279)+t(643)+t(1865)](){let r=t;this[r(863)+"ndex"]=0,this[r(455)+r(443)+r(1015)+"t"]=0}[t(1333)+"es"](){let r=t;this["currentE"+r(443)+r(1015)+"t"]=0}["getCurre"+t(961)+"nt"](){let r=t;return this[r(1179)+"s"][this["currentI"+r(730)]]}["getCurre"+t(961)+t(1156)+t(1016)](){return this[t(455)+"ndpointTriesCount"]}[t(1539)+t(1711)+"es"](){let r=t;return!!(e.ctfzt(this[r(863)+r(730)],this.endpoints[r(1078)])||e[r(1246)](this["currentI"+r(730)],e[r(583)](this[r(1179)+"s"][r(1078)],1))&&e[r(1148)](this[r(455)+r(443)+r(1015)+"t"],this[r(1456)+"es"]))}[t(917)+t(1620)+"ointReac"+t(492)+t(521)](){let r=t;return e[r(814)](this[r(863)+r(730)],this[r(1179)+"s"][r(1078)])?!0:e[r(1138)](this["currentE"+r(443)+"riesCount"],this[r(1456)+"es"])}[t(1071)+"ackupEnd"+t(791)+t(1793)+t(1302)](){let r=t;return this[r(455)+r(443)+r(1015)+"t"]=1,this.currentIndex++,this[r(1179)+"s"][this[r(863)+r(730)]]}[t(1159)+"ntEndpoi"+t(751)+t(699)](){let r=t;return this[r(455)+"ndpointT"+r(1015)+"t"]++,this[r(1159)+r(961)+"nt"]()}}let nr=(e[t(1515)](e.vGDRD,typeof globalThis)&&e[t(920)](t(784),globalThis[t(539)+t(840)][t(525)])||t(1749)+"d"!=typeof window&&e.MHrCF(e.jvVIm,window[t(539)+t(840)][t(525)]))&&e[t(1515)]("undefined",typeof document),Rn=e.kObSq(e[t(799)],typeof globalThis)&&(e.rkfvF(e[t(1821)],globalThis[t(539)+t(840)][t(525)])||e[t(1119)](e[t(1392)],globalThis[t(539)+t(840)][t(525)]))&&e[t(1527)](e[t(799)],typeof tt),Zr=(e[t(799)]!=typeof globalThis&&e[t(838)](e[t(1821)],globalThis[t(539)+"tor"].name)||e.AichC(e[t(799)],typeof globalThis)||e[t(976)](e[t(799)],typeof globalThis)&&!!globalThis[t(1504)+t(1235)])&&e[t(976)](e[t(799)],typeof wx),Xr=e[t(1057)](e[t(799)],typeof globalThis)&&(e[t(1461)](e[t(1392)],globalThis[t(539)+t(840)].name)||e[t(1246)](e[t(1517)],globalThis[t(539)+"tor"].name)||e.xfNld(e.kXZnz,globalThis["construc"+t(840)][t(525)]))&&e[t(459)](e.vGDRD,typeof self),Mp=e[t(1582)](t(1749)+"d",typeof globalThis)&&t(1251)===globalThis[t(539)+t(840)][t(525)]&&e.tVcMG(t(1749)+"d",typeof global)&&e.rrOUj===global.constructor[t(525)]&&e[t(799)]!=typeof process&&!!process[t(763)];class ua{constructor(){let r=t;this[r(1723)+"rs"]={}}emit(r,...s){let l=t,h={Dkwpp:function(p,_){return p<_}};if(e[l(1292)](e.pPsUG,l(1760))){let p=this._listeners[r];if(p)p.slice().forEach(_=>_.fn[l(1247)](_[l(1411)],s));else if(e[l(820)](e[l(1706)],r)&&!this[l(423)]){let _=s[l(1078)]&&s[0];if(e[l(765)](_,Error))throw _;let E=new Error(e[l(1068)](e[l(1349)],_?e[l(1128)](e[l(445)](" (",_[l(1426)]),")"):""));throw E[l(1355)]=_,_}return this}else{let p=_0x6ab3c8[l(798)](":");for(let _=0;zMgiOT[l(930)](_,p[l(1078)]);_++){let E=p[_];if(p[_][l(1078)]!==4){let m=_0x194a3c.substring(0,4-p[_][l(1078)]),O=m.concat(E);_0x11e021=_0x58bb2a[l(1475)](O)}else _0x4a14c9=_0x42c31c[l(1475)](E)}return _0x5eb50c}}[t(442)](r,s){let l=t;if(e[l(1828)](void 0,r))this._listeners={};else if(e.kLlTN(void 0,s))this[l(1723)+"rs"][r]=null;else{let h=this[l(1723)+"rs"][r];if(h)for(let p=0;e[l(666)](p,h[l(1078)]);)e.vbMbm(h[p].fn,s)?h[l(602)](p,1):++p}return this}on(r,s,l){let h=t;return e[h(1474)](h(691),e[h(1613)])?((this._listeners[_0x3ce81e]||(this[h(1723)+"rs"][_0x35f36f]=[]))[h(1777)]({fn:_0x8176fd,ctx:_0x1b8230||this}),this):((this._listeners[r]||(this[h(1723)+"rs"][r]=[])).push({fn:s,ctx:l||this}),this)}}class Bp extends ua{[t(1005)+"rrorMess"+t(952)](r){let s=t;return r.errMsg||r[s(1519)]?(s(659)+" "+(r[s(697)]||"")+s(1709)+(r[s(1519)]||""))[s(1739)]():JSON[s(1139)+"y"](r)}constructor(r,s,l){let h=t;e[h(714)](h(861),e[h(1472)])?this[h(1331)][h(696)]&&_0x11c7fc[h(1043)][h(1247)](_0x38feeb,[h(1433)+">",..._0x1b3c1f]):(super(),this[h(1167)]=null,Zr&&wx[h(1322)+"ocket"]&&(this._socket=wx[h(1322)+h(1690)]({url:r,protocols:s,header:l,fail:this["_createSocketFai"+h(1781)][h(1803)](this),success:this[h(1717)+"ocketSuc"+h(566)+h(1428)][h(1803)](this)})),Rn&&tt[h(1322)+"ocket"]&&(this[h(1167)]=tt["connectS"+h(1690)]({url:r,protocols:s,header:l,fail:this["_createS"+h(1220)+h(1781)][h(1803)](this),success:this["_createS"+h(480)+"cessHandler"].bind(this)})))}[t(1717)+t(480)+"cessHand"+t(1428)](){let r=t;Promise[r(803)]().then(()=>{let s=r;this[s(1546)+s(1759)]()})}[t(1717)+t(1220)+"lHandler"](r){let s=t,l={seZNi:function(h,p,_){return e[U(1101)](h,p,_)},Alkib:e[s(1706)],FjUMd:e[s(1238)]};Promise.resolve().then(()=>{let h=s,p=l[h(1860)](ot,h(1441),{message:this[h(1005)+h(1345)+"age"](r)});this[h(1191)](l.Alkib,p);let _=xt(l[h(1445)],{reason:this[h(1005)+h(1345)+h(952)](r)});this[h(1191)]("close",_)})}[t(1546)+t(1759)](){let r=t,s={dzYcy:e.jcTVI,enNky:function(l,h,p){return e[U(1470)](l,h,p)}};this[r(1167)].onOpen(l=>{let h=r;this[h(1191)](h(1337),cl(e[h(707)],{...l,data:l[h(697)]||""}))}),this[r(1167)][r(1070)](l=>{let h=r;this.emit(s[h(582)],s.enNky(xt,h(1323),{...l}))}),this[r(1167)][r(993)+"e"](l=>{let h=r,p={Dgnyj:e[h(1708)],bdHdw:e[h(1375)]};if(e.tYLsL!==e[h(559)])this[h(1191)](e[h(1129)],al(e[h(1129)],{...l}));else switch(_0x14a1e6){case p.Dgnyj:case p.bdHdw:return{["x-use-"+_0x1b4230]:1,"x-tt-env":_0x5894a9};default:return{}}}),this[r(1167)][r(1520)](l=>{let h=r;this[h(1191)](h(1441),e[h(802)](ot,h(1441),{...l,message:l[h(697)]||""}))})}[t(1149)](r){let s=t;if(e.viLrM==="GgUwJ")if(e[s(1090)](r,Uint8Array)){let l=r[s(1453)][s(386)](r[s(487)+"et"],r[s(1654)+"th"]+r[s(487)+"et"]);this[s(1167)]&&this[s(1167)][s(1149)]({data:l,fail:h=>{let p=s;this[p(1191)](e.HCwYV,e.WWlSS(ot,e[p(1706)],{message:this[p(1005)+p(1345)+p(952)](h)}))}})}else this[s(1167)]&&this[s(1167)][s(1149)]({data:r,fail:l=>{let h=s;this.emit(e[h(1706)],ot(e[h(1706)],{message:this["_formatE"+h(1345)+h(952)](l)}))}});else{for(_0x3526de>>>=0;e.rKJtX(_0x292c7b,128);)_0x28a2b0(_0x5ab30a,e[s(1522)](127&_0x588b78,128)),_0x974b3>>>=7;e[s(1888)](_0x89944e,_0x151009,_0x471a3c)}}close(r,s){let l=t;this[l(1167)]&&this[l(1167)][l(1323)]({code:r,reason:s})}[t(1886)+t(1434)](r,s){let l=t;if(e[l(434)](l(1181),e[l(1420)]))return new _0x14c858(_0x21bf3c,{data:_0x55da54,message:_0x1d6dce});this.on(r,s)}[t(1118)+"entListener"](r,s){this[t(442)](r,s)}get[t(1730)+"te"](){let r=t;return this[r(1167)][r(1730)+"te"]}get[t(1744)+"pe"](){let r=t;return this[r(1167)][r(1744)+"pe"]}set[t(1744)+"pe"](r){}get[t(1165)](){return this[t(1167)].url}get[t(1785)](){let r=t;return this._socket[r(1785)]}get[t(1751)+"ns"](){let r=t;return this[r(1167)][r(1751)+"ns"]}get[t(1788)+t(1064)](){return 0}}function Fp(a,r){let s=t;if(e[s(1474)](s(1686),e[s(1626)])){let l=new _0x8d291(2*_0x595cb0);l[s(1762)](_0x2ed501),_0x788c4c[s(1756)]=l}else{if(r)return new r(a[s(1165)],a[s(1785)]);if(e[s(609)](Zr,Rn))return new Bp(a[s(1165)],a[s(1785)],a[s(1740)]);if(e[s(1623)](nr,Xr)&&e[s(746)](e[s(799)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(1165)],a[s(1785)+"s"])}}function zp(a){let r=t;if(e[r(1450)]!==e[r(1088)]){let s=(r(1176)+"0")[r(798)]("|"),l=0;for(;;){switch(s[l++]){case"0":return!1;case"1":if(Rn&&tt[r(1322)+"ocket"])return!0;continue;case"2":if(Zr&&wx[r(1322)+"ocket"])return!0;continue;case"3":if(a)return!0;continue;case"4":if(e[r(843)](nr,Xr)&&typeof WebSocket<"u"&&WebSocket)return!0;continue}break}}else return(e[r(1034)](_0x487266,4).join("0")+_0x12b7fe(_0x420d99,2)[r(1067)](16))[r(386)](-4)}function ll(a,r,s){let l=t;if(e[l(888)]!==e[l(888)])return this[l(495)]?.[l(996)](_0x1e3dc3);{let h=-1;async function p(_){let E=l;return e.ZyEXY(_,h)?Promise.reject(new Error(e.Luxgw)):(h=_,e[E(815)](_,s.length)?Promise[E(803)]():s[_].bind(a)(r,p[E(1803)](null,_+1)))}e[l(606)](p,0)}}function ul(a){let r=t,s=0,l=0;for(let h=0;e.JCRfU(h,a[r(1078)]);++h)l=a[r(1074)+"At"](h),e[r(1792)](l,128)?s+=1:l<2048?s+=2:e[r(1783)](e[r(1639)](64512,l),55296)&&e[r(1834)](e[r(652)](64512,a.charCodeAt(h+1)),56320)?(++h,s+=4):s+=3;return s}function fl(a,r,s){let l=t;if(s-r<1)return"";let h="";for(let p=r;e.kgWsX(p,s);){let _=a[p++];if(_<=127)h+=String["fromChar"+l(1662)](_);else if(e[l(1405)](_,192)&&e.hMYZN(_,224))h+=String[l(1859)+l(1662)](e[l(741)](e[l(1458)](e.nMAzF(31,_),6),e[l(1647)](63,a[p++])));else if(_>=224&&e[l(1161)](_,240))h+=String[l(1859)+"Code"](e[l(1856)](e[l(1084)](e[l(1379)](e[l(1313)](15,_),12),e[l(1458)](e[l(502)](63,a[p++]),6)),e[l(1114)](63,a[p++])));else if(e[l(1486)](_,240)){let E=e.OxNLa(e.LtHKI(e[l(1091)](e[l(1275)](e[l(413)](7,_),18),e[l(1094)](63,a[p++])<<12)|e[l(950)](63&a[p++],6),e[l(1054)](63,a[p++])),65536);h+=String[l(1859)+l(1662)](e[l(1233)](55296,e[l(1309)](E,10))),h+=String[l(1859)+l(1662)](56320+e[l(681)](1023,E))}}return h}function fa(a,r,s){let l=t,h=s,p,_;for(let E=0;E<a.length;++E)p=a[l(1074)+"At"](E),e[l(913)](p,128)?r[s++]=p:e[l(744)](p,2048)?(r[s++]=e.gFhOj(p,6)|192,r[s++]=e[l(1767)](63&p,128)):e[l(1270)](e[l(409)](64512,p),55296)&&e[l(1306)](e[l(860)](64512,_=a.charCodeAt(e.qouVV(E,1))),56320)?(p=e[l(1003)](65536,e[l(1108)](e.XqcNa(1023,p),10))+e[l(1838)](1023,_),++E,r[s++]=e[l(1522)](e[l(1046)](p,18),240),r[s++]=e[l(552)](e[l(1024)](e.rSUxn(p,12),63),128),r[s++]=e[l(501)](p>>6&63,128),r[s++]=e[l(1285)](63,p)|128):(r[s++]=e[l(741)](e[l(1765)](p,12),224),r[s++]=e[l(964)](e[l(998)](p>>6,63),128),r[s++]=63&p|128);return e[l(583)](s,h)}async function hl(a){let r=t;if(e[r(967)](e[r(1689)],typeof a)){let s=new Uint8Array(e[r(518)](ul,a));return e.bRlNh(fa,a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[r(1453)],a[r(487)+"et"],a[r(1654)+"th"])}function Up(a){let r=t;if(e[r(1474)](e[r(572)],e[r(572)]))try{if(e.MFGtr(e[r(497)],"KdlPv"))KkQdIh[r(1671)](_0x2e7cc9),KkQdIh[r(1053)](_0x70dec5);else return e[r(1689)]!=typeof a&&(a instanceof ArrayBuffer||a[r(1453)]&&e.KqJkg(a[r(1453)],ArrayBuffer))||e[r(746)](r(533),typeof a)?"":(JSON.parse(a),e[r(368)])}catch{return e.YxzrW(r(533),typeof a)?e[r(1011)]:""}else{let s={ZJfNK:e[r(598)],nrZEy:function(h,p){return e[r(1138)](h,p)},eHoBr:function(h,p,_,E){return e[r(388)](h,p,_,E)},ikzIO:function(h,p){return e[r(1666)](h,p)},UfpHD:function(h,p){return e[r(1193)](h,p)},AjNqj:function(h,p){return h>>>p},duIUW:function(h,p){return e.iAoYu(h,p)},DduLa:function(h,p){return e[r(1370)](h,p)},fFCap:function(h,p){return h<p},KvnfC:function(h,p){return e[r(1002)](h,p)},WnJJP:function(h,p){return h|p},qsoZq:function(h,p){return e[r(413)](h,p)},CMHQy:function(h,p){return e[r(1570)](h,p)},eCXEa:function(h,p){return e[r(931)](h,p)},EPYae:function(h,p){return e[r(1590)](h,p)},ukVKu:function(h,p){return e.klKAb(h,p)},tHfWK:function(h,p){return e[r(654)](h,p)},IuPAj:function(h,p){return e[r(732)](h,p)},KCOnD:function(h,p){return e.gmLQK(h,p)},aQoSG:function(h,p){return e[r(441)](h,p)}},l=4294967295;return function(h,p,_=!0){let E=r,m=s[E(1874)][E(798)]("|"),O=0;for(;;){switch(m[O++]){case"0":if(s.nrZEy(p+=5,h[E(1078)]))throw p=h.length,s.eHoBr(_0x5b5e5c,p,10,h[E(1078)]);continue;case"1":if(s[E(1712)](h[p++],128))return{value:_?l:0|l,offset:p};continue;case"2":return{value:_?l:s[E(1124)](0,l),offset:p};case"3":l=s.AjNqj(s.UfpHD(l,s[E(1243)](s.DduLa(127,h[p]),21)),0);continue;case"4":if(s[E(1045)](h[p++],128))return{value:_?l:0|l,offset:p};continue;case"5":if(s[E(942)](h[p++],128))return{value:_?l:0|l,offset:p};continue;case"6":l=s[E(1394)](l,s[E(1216)](15,h[p])<<28)>>>0;continue;case"7":l=s[E(1324)](l|s.eCXEa(s[E(1540)](127,h[p]),14),0);continue;case"8":l=s[E(562)](s[E(1048)](127,h[p]),0);continue;case"9":if(s.tHfWK(h[p++],128))return{value:_?l:0|l,offset:p};continue;case"10":if(s.ikzIO(h[p++],128))return{value:_?l:s[E(1394)](0,l),offset:p};continue;case"11":l=s[E(885)](s[E(1351)](l,s[E(1429)](127&h[p],7)),0);continue}break}}}}let Gp=(a,r)=>{let s=t;if(e[s(715)]!==e[s(402)])switch(a){case e[s(1708)]:case e[s(1375)]:return{[s(1145)+a]:1,"x-tt-env":r};default:return{}}};class jp{constructor(r){let s=t;this[s(1256)+s(1016)]=r,this[s(482)]=0}addCount(){this.count++}[t(1539)+t(801)+"nt"](){let r=t;return e[r(733)]==="JvuoZ"?this[r(495)][r(839)]:e[r(490)](this[r(482)],this[r(1256)+r(1016)])}[t(1561)+t(370)](r=0){let s=t;this[s(1256)+s(1016)]=r,this.count=0}}async function qp(a){let r=t,s={xxDvu:function(l,h){return e[U(1316)](l,h)},HDUUO:e[r(1560)],xjCyy:function(l,h){return e[r(721)](l,h)},JiOhs:e[r(1466)],dAYiK:function(l,h){return e.xfNld(l,h)},izBwo:function(l,h){return e[r(509)](l,h)},zmyHo:function(l,h){return e[r(729)](l,h)},fPmRa:e[r(560)],SjmNV:function(l,h){return e[r(506)](l,h)},cjsNY:e[r(479)],SZZCy:e.vnxJv};return new Promise(l=>{let h=r,p={GICTo:function(_,E){return s.dAYiK(_,E)},hGjwW:function(_,E){return s[U(1619)](_,E)},hixPa:function(_,E){return s[U(1467)](_,E)},YLUrq:function(_,E){return s[U(1188)](_,E)}};if(!nr)return s.xjCyy(l,s[h(1591)]);try{let _=document[h(464)+"ement"](h(1187));window["frontier"+h(1166)]=E=>{let m=h;s[m(1255)](s[m(622)],m(1669))?this["_addWsLi"+m(1759)]():(document[m(1469)][m(1044)+m(648)](_),window[m(1832)+m(1166)]=void 0,s[m(1287)](l,E&&E.msg||s[m(1591)]))},_[h(1649)]=s[h(1599)],_[h(807)]=s[h(1729)](a[h(1721)](/^ws/,h(698)),s[h(1733)]);try{document.body[h(1155)+"ild"](_)}catch{document[h(1469)][h(1044)+"ild"](_)}}catch{if(s[h(1188)](s[h(412)],h(1864)))window["frontier"+h(1166)]=void 0,s.xjCyy(l,s[h(1591)]);else{if(OlzjYy.GICTo(void 0,_0x2eb920))this[h(1723)+"rs"]={};else if(OlzjYy.hGjwW(void 0,_0x4d051f))this._listeners[_0x556916]=null;else{let _=this[h(1723)+"rs"][_0x1eabb6];if(_)for(let E=0;OlzjYy.hixPa(E,_[h(1078)]);)OlzjYy[h(1372)](_[E].fn,_0x59e9be)?_[h(602)](E,1):++E}return this}}})}function nn(a,r,s){let l=t;return!!a?.[l(1736)](h=>h[l(563)]===r&&h[l(1866)]===s)}function rr(a,r){let s=t;return a?.[s(1736)](l=>l[s(563)]===r)?.value}let ha=null;async function Hp(){let a=t;return ha||(ha=Promise.resolve()[a(887)](Nt[a(1803)](Nt,e[a(1661)]))),ha}class Wp extends ua{constructor(r,s){let l=t,h={zwJys:function(p,_){return e[U(1262)](p,_)},sZBfq:function(p,_){return e[U(552)](p,_)},JzVkB:function(p,_){return e.wiUrL(p,_)},lFcIT:function(p,_){return e[U(972)](p,_)},BXOtr:function(p,_){return e.XhjMV(p,_)},kdOtR:function(p,_){return p<<_},pEdOA:function(p,_){return e[U(1307)](p,_)},hzujV:function(p,_){return e.AFPPl(p,_)},haNEb:function(p,_){return e[U(391)](p,_)},vFbKo:function(p,_){return e[U(1097)](p,_)}};if(e[l(969)](e[l(1637)],e[l(661)]))super(),this[l(742)]=r,this[l(956)]=s,this[l(495)]=void 0,this[l(906)+"mise"]=null;else{let p=jFjemo[l(1041)](jFjemo[l(1229)](jFjemo.JzVkB(jFjemo.sZBfq(jFjemo[l(1164)](jFjemo[l(565)](7,_0x211121),18),jFjemo[l(1146)](jFjemo[l(565)](63,_0x403b44[_0x4bc4d4++]),12)),jFjemo[l(565)](63,_0x19c325[_0x5dd44c++])<<6),jFjemo[l(565)](63,_0x48f42a[_0x5e3ead++])),65536);_0x5990e9+=_0x2f100b[l(1859)+l(1662)](jFjemo[l(577)](55296,jFjemo.hzujV(p,10))),_0x507eda+=_0x3fd963[l(1859)+l(1662)](jFjemo[l(1633)](56320,jFjemo.vFbKo(1023,p)))}}async openDB(){await this[t(615)]()}async[t(615)](){let r=t;if(!this[r(495)]){if(this[r(906)+r(1491)])return this["_initPro"+r(1491)];try{let s=this._dbName,l=this._keyPath;this["_initPro"+r(1491)]=(async()=>{let h=r,{openDB:p}=await e.LehXZ(Hp);this[h(495)]=await p("frontier_"+s,1,{upgrade(_){let E=h;_[E(614)+E(687)+"e"](s,{keyPath:l})}})})(),await this[r(906)+r(1491)]}catch(s){console[r(1043)](s)}finally{e[r(831)]==="QVuTe"?_0x293d46[r(1043)](_0x3f50c8):this["_initPro"+r(1491)]=null}}}async[t(585)](r){let s=t;try{return await this[s(615)](),this[s(495)]?.[s(585)](this[s(742)],r)}catch(l){console[s(1043)](l)}}async[t(1762)](r,s){let l=t;return await this[l(615)](),this[l(495)]?.[l(1060)](this[l(742)],r)}async[t(996)](r){let s=t;if(e[s(1523)]===e.UGsrn)try{return await this[s(615)](),this[s(495)]?.delete(this[s(742)],r)}catch(l){console.log(l)}else{let l={PYDVL:function(h,p){return h!=p},sOAkI:KkQdIh[s(799)],EswXP:s(1881),MLocM:KkQdIh[s(1100)]};_0x343de7.r=h=>{let p=s;l.PYDVL(l[p(1189)],typeof _0x2dd8f7)&&_0x26af4f[p(1067)+p(1869)]&&_0x115aff["definePr"+p(1012)](h,_0x4d339b[p(1067)+p(1869)],{value:l[p(419)]}),_0xbdcc6e[p(628)+"operty"](h,l[p(679)],{value:!0})}}}async[t(674)](){let r=t;try{return await this._init(),this[r(495)]?.clear(this._dbName)}catch(s){console[r(1043)](s)}}async[t(1435)](){let r=t;if(e.ufDvU(e[r(1172)],e[r(1586)]))return await this[r(615)](),this[r(495)]?.[r(1764)+"ys"](this[r(742)]);this[r(1694)]&&this._ws.close(_0x5e9053,_0x3985a7)}async[t(421)](){let r=t;return await this[r(615)](),this._qosDB?.[r(421)](this[r(742)])}async[t(1297)](){let r=t,s={QSxfW:e.hVASo};if(e.oaXCO(r(624),e[r(422)]))return _0x17e8bc||(_0x572543=_0x539eb8.resolve()[r(887)](_0x1d37b1.bind(_0x5c0cf1,bkZbQM[r(452)]))),_0x1beae6;try{this[r(495)]?.[r(1323)](),this[r(495)]=void 0}catch(l){console[r(1043)](l)}}get[t(839)](){let r=t;try{return!!this[r(495)]}catch(s){return console[r(1043)](s),!1}}}class Kp{constructor(r,s){let l=t;this[l(1542)]=r,this[l(1693)]=s,this._qosDB=localStorage}async[t(1103)](){}get _prefix(){let r=t;if(e.JngJg===e[r(1810)])KkQdIh[r(877)](_0x4db0b7,KkQdIh[r(1668)](_0x47d81f,_0x40de98[r(1201)]),_0x399cb2[r(724)+"on"],_0x2927bb.newVersion,KkQdIh.RIzDb(_0x5a6377,_0x1d8c3c.transaction));else return r(1832)+"_"+this._DBName}async[t(585)](r){let s=t,l=this[s(495)][s(1184)](this[s(468)]);return JSON[s(1203)](e.pgJIK(l,"{}"))[r]}async[t(1762)](r,s){let l=t,h=this[l(495)][l(1184)](this._prefix),p=JSON.parse(e[l(1772)](h,"{}"));return p[s||r[this[l(1693)]]]=r,this[l(495)][l(804)](this[l(468)],JSON[l(1139)+"y"](p)),s||r[this[l(1693)]]}async[t(996)](r){let s=t,l={ZdwmM:function(h,p){return e.MzvcL(h,p)},hYQEa:function(h,p){return e[U(1361)](h,p)},eXkJv:function(h,p){return e[U(431)](h,p)},TzgWi:function(h,p){return e[U(1826)](h,p)},GBpcp:function(h,p){return h<<p},DTlTH:function(h,p){return h<p}};if(e.pgVgQ(e.VQaUk,s(603))){let h=this._qosDB[s(1184)](this[s(468)]),p=JSON[s(1203)](e[s(596)](h,"{}"));return p[r]=void 0,this[s(495)][s(804)](this._prefix,JSON[s(1139)+"y"](p))}else _0x34f822=_0x2a9bda[updKHt[s(1557)](updKHt.ZdwmM(_0x568ab8,_0x12cd50),1)],updKHt[s(635)](updKHt.eXkJv(192,_0x4e7879),128)?_0x402a11+=_0x1c9b34:(_0x3d86c7=updKHt[s(1418)](updKHt[s(608)](31&_0x1c6bb8,6),63&_0x3d5fb7),updKHt[s(864)](_0x319de0,128)?_0x4076b3+=_0x549104:(_0x31ce4d+=_0x1cd862(_0x4b3243),_0x1a8eb7++))}async clear(){let r=t;return e[r(1021)](e[r(1535)],e[r(1535)])?this[r(495)][r(674)]():this[r(1678)+"tManager"]?.[r(1159)+"ntEndpoi"+r(1156)+"ount"]()||0}async[t(1435)](){let r=t,s=this._qosDB[r(1184)](this._prefix),l=JSON[r(1203)](e.emzGo(s,"{}"));return Object[r(1435)](l)}async[t(421)](){let r=t,s=this._qosDB.getItem(this._prefix),l=JSON[r(1203)](s||"{}");return Object[r(705)](l)}[t(1297)](){return Promise[t(803)]()}get[t(839)](){return!!this[t(495)]}}class $p{constructor(r,s){let l=t;this[l(1542)]=r,this._pathKey=s,this._qosDB=Rn?tt:Zr?wx:null}async[t(1103)](){}get _prefix(){return"frontier_"+this[t(1542)]}async get(r){let s=t,l=this._qosDB["getStora"+s(1656)](this._prefix);return JSON[s(1203)](e.WqcXt(l,"{}"))[r]}async[t(1762)](r,s){let l=t;if(e.jdOPI(e[l(1430)],e.hEwZi)){let h=this._qosDB[l(642)+"geSync"](this[l(468)]),p=JSON[l(1203)](e.twIhk(h,"{}"));return p[s||r[this[l(1693)]]]=r,this[l(495)]["setStora"+l(1656)](this[l(468)],JSON[l(1139)+"y"](p)),s||r[this[l(1693)]]}else _0x2ebce7[l(1777)](_0x3336ae)}async del(r){let s=t,l=this[s(495)][s(642)+s(1656)](this._prefix),h=JSON.parse(e[s(596)](l,"{}"));return h[r]=void 0,this._qosDB[s(915)+"geSync"](this[s(468)],JSON[s(1139)+"y"](h))}async[t(674)](){let r=t;return this[r(495)]["clearSto"+r(1132)]()}async[t(1435)](){let r=t,s=this[r(495)][r(642)+r(1290)+"nc"](this[r(468)]),l=JSON[r(1203)](s||"{}");return Object[r(1435)](l)}async[t(421)](){let r=t,s=this._qosDB[r(642)+r(1290)+"nc"](this[r(468)]),l=JSON[r(1203)](e.emzGo(s,"{}"));return Object[r(705)](l)}closeDB(){let r=t;if(e[r(1310)]==="RUkhk")e[r(1868)](_0x2f8340,_0x4bdea4,50),e[r(900)](_0x226c82,_0x544791,_0x2aba8e);else return Promise.resolve()}get[t(839)](){return!!this[t(495)]}}function xl(a,r){let s=t;if(e[s(1268)](e[s(1863)],e[s(1863)])){if(_0x5328ce)return new _0x3566c4(_0x5d7aeb[s(1165)],_0x238d9c.protocol);if(_0x4e865c||_0x15bb75)return new _0x563ef2(_0x872382[s(1165)],_0x5c3481.protocol,_0x2343c1.headers);if(e[s(843)](_0x561eb6,_0x3fbdaf)&&e[s(1728)](e[s(799)],typeof _0x5171d7)&&_0x507109)return new _0x3a6674(_0x34b68d[s(1165)],_0x116bfb.protocols)}else{if(e[s(520)](Rn,Rn))return new $p(a,r);if(e[s(1402)](nr,Xr)&&e[s(746)](e[s(799)],typeof indexedDB))return new Wp(a,r);if(e.WqcXt(nr,Xr)&&e[s(451)](s(1749)+"d",typeof localStorage))return new Kp(a,r);throw new Error(e[s(1830)])}}class Vp{constructor(){let r=t;this[r(842)+r(919)+"Id"]=null,this[r(842)+"l"]=36e5,this[r(495)]=e[r(1133)](xl,e[r(446)],e[r(383)])}async[t(842)+t(1207)](){let r=t;e.EtowY(clearInterval,this[r(842)+r(919)+"Id"]),this["_interva"+r(919)+"Id"]=e.SquGz(setInterval,()=>{let s=r;this[s(1194)+s(1065)]()},this[r(842)+"l"])}async openDB(){let r=t;await this._qosDB[r(1103)]()[r(887)](()=>{let s=r;this[s(842)+s(1207)]()})}async[t(1194)+t(1065)](){let r=t,s={XyTgD:function(p,_){return p!==_},BbOte:e[r(1212)]};(await this[r(495)]?.[r(421)]()||[])[r(1099)](({timestamp:p})=>p<Date[r(405)]())[r(684)](p=>{let _=r;if(s[_(1190)](s[_(1646)],s[_(1646)]))return _0x21fca8(_0x7649fc);this[_(495)]?.[_(996)](p[_(859)+"id"])})}async[t(996)](r){return this[t(495)]?.del(r)}async set(r,s){let l=t;return this[l(495)]?.[l(1762)]({message_id:r,timestamp:s})}async[t(585)](r){return this._qosDB?.get(r)}async[t(1297)](){let r=t;e[r(1013)](clearInterval,this[r(842)+r(919)+"Id"]),await this._qosDB?.[r(1297)]()}get[t(839)](){return this[t(495)]?.isReady}}function xa(a){let r=t;if(e[r(1209)](e[r(1748)],e[r(1806)])){let s=!!this[r(1331)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e.kEXiV(nn,a[r(1426)][r(1740)],r(782)+r(1699),"2"),h=l&&nn(a.message.headers,e[r(1010)],"1"),p=l&&e[r(1079)](nn,a[r(1426)].headers,r(782)+"er_is_ack","1"),_=p?e[r(662)](rr,a[r(1426)][r(1740)],e[r(623)])?.[r(798)](",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:h,isAckCleanupMessage:p,ackMsgIds:_}}else _0x4e9130(_0x287c7d,32),_0x352406(_0x4684da,e[r(1747)](_0x50be6c,_0x2bbdd5))}async function pl(){let a=t;return this[a(955)+a(1501)]||(this[a(955)+a(1501)]=new Vp),this["_QoSMana"+a(1501)].isReady||await this[a(955)+a(1501)][a(1103)](),this[a(955)+a(1501)]}async function Jp(a,r){let s=t,{enableAutoAck:l}=this[s(1331)],h=e[s(1797)](nn,a.message[s(1740)],e[s(938)],"1"),p=e.AlytF(nn,a.message[s(1740)],s(1223),"1"),_=xa[s(1225)](this,a);if(e[s(612)](l,h))if(e[s(817)](e.KBZTR,e[s(768)])){let{SeqID:E,LogID:m,service:O,LogIDNew:N,method:q}=a.message;this[s(1332)]({SeqID:E,LogID:m,LogIDNew:N,service:O,method:q,headers:[{key:e.RAzeU,value:"1"},{key:e[s(1280)],value:e[s(609)](N,"")},{key:e[s(1787)],value:"0"}]})}else return this._isMiniTT||this._isMiniWX?this[s(1363)+s(760)+s(465)]:(this[s(411)+"er"]||this[s(1549)+"r"])&&this[s(1331)][s(1835)+"tworkCha"+s(783)]?_0x383409.onLine:!0;p&&!_.isQoSAck&&this[s(669)+s(871)+"ageEvent"](a),e[s(897)](r)}async function Yp(a,r){let s=t;this[s(1414)](e[s(1289)],a.message),r()}async function Zp(a,r){let s=t,l=e[s(1006)](Qt,await e[s(894)](hl,a.data));try{if(e.ENpEk(l.payload,Uint8Array))if(e[s(1358)](e.hPYKy,s(957))){this[s(484)+s(515)](),this["_pingPon"+s(984)+"Id"]=e[s(632)](_0xcdca3d,this._ping[s(1803)](this),this[s(1331)][s(1541)+s(1610)]);return}else{let h=e[s(1090)](this._options[s(1829)+s(734)],Object)?{force:!!this._options[s(1829)+s(734)].force,encoding:this[s(1331)][s(1829)+"ncoding"][s(1573)]?this[s(1331)][s(1829)+s(734)][s(1573)][s(1721)](/\s/g,"")[s(529)+s(849)]():""}:{force:!1,encoding:this._options[s(1829)+s(734)]?this[s(1331)][s(1829)+s(734)][s(1721)](/\s/g,"")[s(529)+s(849)]():""},p=l[s(1829)+s(734)]?l[s(1829)+s(734)][s(1721)](/\s/g,"")["toLowerC"+s(849)]():"",_=e[s(1340)](this._options[s(629)+s(1051)],Object)?{force:!!this[s(1331)][s(629)+s(1051)][s(990)],type:this._options["payloadT"+s(1051)][s(1649)]?this[s(1331)][s(629)+s(1051)][s(1649)].replace(/\s/g,"")[s(529)+s(849)]():""}:{force:!1,type:this._options.payloadType?this._options[s(629)+s(1051)][s(1721)](/\s/g,"")[s(529)+s(849)]():""},E=l[s(629)+s(1051)]?l[s(629)+s(1051)].replace(/\s/g,"")[s(529)+"ase"]():"",m=_[s(990)]?_[s(1649)]:E||_[s(1649)],O=h.force?h[s(1573)]:p||h[s(1573)],N=[s(567)+s(1490)+s(912),e[s(368)],"applicat"+s(806)+s(745)+"=utf-8",e.yQPyK],q=[e.wRirA,e[s(1598)]];this[s(1331)]["enableTr"+s(651)+s(378)+"ad"]&&N[s(1343)](m)&&(!O||q[s(1343)](O))?l[s(1312)+s(1059)]=e.bRlNh(fl,l[s(910)],0,l.payload[s(1654)+"th"]):l[s(1312)+s(1059)]=""}else l[s(1312)+s(1059)]=""}catch(h){l[s(1312)+"oad"]="",console[s(1043)](h)}a[s(1426)]=l,r()}function Xp(a,r,s){let l=t,h=s||8192,p=e[l(835)](h,1),_=null,E=h;return function(m){let O=l;if(m<1||m>p)return e.AdyIE(a,m);E+m>h&&(_=e[O(1630)](a,h),E=0);let N=r[O(1225)](_,E,E+=m);return e[O(1773)](7,E)&&(E=e[O(1253)](e[O(1767)](7,E),1)),N}}let Qp=4294967295;function eg(a,r,s){let l=t;return e[l(1630)](RangeError,e.bRNCF(e[l(433)](e.MzvcL(e[l(1663)]("index out of ran"+l(761),a)+e[l(829)],e.LzRqQ(r,1)),e[l(389)]),s))}function tg(a,r,s){let l=t;if(s>Qp)throw new Error(l(1738)+l(1611)+"e");let h=3;for(;h>=0;){let p=e[l(1295)](255,s);e[l(604)](ga,p,a,e[l(987)](r,h)),s>>>=8,h--}return e.DGJPE(r,4)}function ng(a,r){let s=t,l=0,h=r,p=r+4;for(;e[s(1625)](h,p);){let{value:_,offset:E}=pa(a,h);h=E,l=e[s(1296)](l<<8,0),l+=_}return{value:l,offset:p}}function rg(a,r,s){let l=t,h=e[l(372)][l(798)]("|"),p=0;for(;;){switch(h[p++]){case"0":if(r[l(1443)])return e[l(1605)](r.write(a,s),s);continue;case"1":return e.AlytF(fa,a,r,s)+s;case"2":if(!a)return s;continue;case"3":if(r.utf8Write)return e[l(1007)](r[l(401)+"e"](a,s),s);continue;case"4":if(e[l(654)](a.length,40))return e[l(677)](e[l(1079)](fa,a,r,s),s);continue}break}}function ig(a,r){let s=t,l=new ue(e[s(741)](e[s(1409)](e[s(1174)](a[e[s(677)](r,4)],24),e.HFsgP(a[e[s(1533)](r,5)],16)),a[r+6]<<8)|a[r+7],e[s(1142)](e[s(546)](e.hcFQm(a[e[s(1391)](r,0)],24)|e.fnvXS(a[e[s(1391)](r,1)],16),e.hrkTK(a[e[s(534)](r,2)],8)),a[e[s(1431)](r,3)]),!0);return r+=8,{value:l,offset:e.oHWYe(r,8)}}function sg(a,r,s){let l=t,h=a[l(1617)],p=a.high;return r[s]=p>>>24,r[e[l(792)](s,1)]=e.dcJqm(p>>>16,255),r[e[l(590)](s,2)]=e[l(1446)](p>>>8,255),r[e.UXdce(s,3)]=e[l(1049)](255,p),r[e[l(954)](s,4)]=e[l(668)](h,24),r[e[l(1147)](s,5)]=e.xTALA(h>>>16,255),r[e[l(1152)](s,6)]=e[l(1496)](h,8)&255,r[e[l(1431)](s,7)]=e[l(1114)](255,h),s+=8,s}function pa(a,r){let s=t;if(s(627)!==e[s(1033)])KkQdIh[s(1377)](_0x800ad1,_0x354e3b)&&_0x301fbf[s(1762)](_0x59ffc1,_0xd0d8de);else return a[s(1776)+"8"]?{value:a[s(1776)+"8"](r),offset:r+1}:{value:255&a[r],offset:e[s(927)](r,1)}}function ga(a,r,s){let l=t;return r.writeUint8?r[l(971)+"t8"](a,s):r[s]=255&a,e[l(506)](s,1)}let og=function(a){let r=t;if(e[r(870)]===e[r(1140)])_0x42034f[_0x3f7273++]=e[r(925)](_0x2838e1>>12,224),_0x3e2e5b[_0x2784e3++]=e.kmhoL(e[r(771)](_0x36df1f,6)&63,128),_0x488a8e[_0x3b7f25++]=e.CqRLf(63,_0x39baea)|128;else return new Uint8Array(a)},ag=e[t(936)](t(1749)+"d",typeof Buffer)?Buffer[t(1769)+t(371)]:Xp(og,Uint8Array.prototype.subarray),cg=16,ma=32;function dg(a){let r=t,s=0,l={};for(let h=0;h<a[r(1078)];h++)l[a[h][r(541)+r(1575)]]=e[r(491)](ul,a[h][r(541)+r(1575)]),s+=e[r(445)](14,l[a[h].cursor_name]);return[s,l]}function gl(a,r,s){let l=t,h={OvFSX:e.wZUoT,qPCwZ:function(p,_,E,m){return e.oSmcf(p,_,E,m)},BdvgN:e[l(573)],OkgYt:e[l(489)],Dlvxq:function(p,_,E,m){return e[l(785)](p,_,E,m)},kyMTW:l(525),gEmXu:e.BwxjC};if(e[l(375)]!==e[l(1528)]){let[p,_]=dg(a),E=e[l(491)](ag,p),m=0;return a.forEach(O=>{let N=l;console[N(1043)](h.OvFSX,O,O[N(438)]),m=h[N(588)](ga,0,E,m),console[N(1043)](N(790),m),m=h[N(588)](tg,E,m,O[N(438)]||0),console[N(1043)](h.BdvgN,m),m=ga(_[O[N(541)+N(1575)]],E,m),console.log(h.OkgYt,m),m=h[N(1047)](rg,O.cursor_name,E,m),console[N(1043)](h[N(1248)],m),m=sg(ue[N(876)+"er"](O[N(1413)]||r),E,m),console[N(1043)](h[N(1805)],m)}),{frameType:ma,headers:[{key:e[l(1298)],value:s}],payload:E}}else this[l(1542)]=_0xf8b700,this[l(1693)]=_0x4291fc,this._qosDB=_0x4f0b03}function lg(a){let r=t,s=0,l=[];for(;e[r(1871)](s,a.byteLength);){let{offset:h}=pa(a,s);s=h;let p={cursor_name:"",cursor:0,service:0},{value:_,offset:E}=e[r(1477)](ng,a,s);p[r(438)]=_,s=E;let{value:m,offset:O}=e[r(516)](pa,a,s);s=O,p[r(541)+r(1575)]=e[r(692)](fl,a,s,e[r(590)](s,m)),s+=m;let{value:N,offset:q}=e[r(1477)](ig,a,s);p[r(1413)]=N.toNumber(),s=q,l.push(p)}return l}function ug(){let a=t;return{frameType:ma,headers:[{key:a(1631)+a(1077),value:e[a(837)]}],payload:void 0}}class fg{constructor(r,s,l){let h=t,p={BEeku:function(_,E){return e.uSwPb(_,E)},NvlIh:function(_,E){return e[U(1154)](_,E)}};if(e[h(749)]===e.WoXBc)this[h(1300)+h(738)]=r,this[h(569)+h(1543)]=s,this["_message"+h(373)]=l,this._qosDB=e.CToYA(xl,this[h(1300)+h(738)],e[h(983)]);else return function(_,...E){let m=h,O=_0x3d0067[m(1225)](eMSydG[m(1449)](_0x2d84d2,this),_,...E);return _0x4dd8c0[m(1762)](O,_[m(719)]?_[m(719)]():[_]),eMSydG[m(1014)](_0x57248d,O)}}async[t(1103)](){let r=t;await this[r(495)][r(1103)]()}async getCursors(){let r=t;if(!this[r(495)][r(839)])return;let s=this[r(1652)+"Strategy"],l=await this._qosDB[r(421)]();switch(console[r(1043)](r(869)+"rValues",l),s){case e[r(1827)]:return l&&l[r(1078)]?e.OkWpi(gl,l,0,this[r(569)+"ileName"]):void 0;case e.KoHVs:return;case e[r(1563)]:return l&&l[r(1078)]?gl(l,0,this[r(569)+r(1543)]):e[r(1667)](ug)}}async set(r,s,l){let h=t;return console[h(1043)](e.pyqnZ,r,s,l),this[h(495)][h(1762)]({cursor_name:r,cursor:s,service:l})}async[t(399)+"rs"](r){let s=t,l=e[s(713)](lg,r);for(let h of l)console[s(1043)](s(1069)+"r",l),await this[s(495)][s(1762)](h)}async[t(585)](r){let s=t;return(await this[s(495)].get(r))?.[s(1413)]}async closeDB(){await this._qosDB.closeDB()}[t(436)+t(1432)+t(947)](r){let s=t;this[s(569)+s(1543)]=r}get[t(839)](){let r=t;return this[r(495)][r(839)]}}let hg=e[t(1742)];async function ml(a){let r=t;if(!this._options.enableQoS)return null;let{aID:s,fpID:l,messageStrategy:h}=this._options,p=e.HUXNo(a,hg);try{return this[r(1636)+"anager"]?a&&this[r(1636)+r(750)][r(436)+"rsorFile"+r(947)](a):this[r(1636)+r(750)]=new fg(l+"_"+s+"_"+p,p,h),this[r(1636)+r(750)][r(839)]||await this["_cursorM"+r(750)].openDB(),this["_cursorM"+r(750)]}catch{if(e.JCQUk(e.lxbCF,e[r(867)]))this[r(842)+r(1207)]();else return null}}async function xg(a,r){let s=t,l=e.RaleY(nn,a[s(1426)].headers,e[s(420)],"-1"),h=e[s(1595)](nn,a.message[s(1740)],e[s(1604)],"1"),p=e.dFWSO(rr,a[s(1426)][s(1740)],e[s(1169)]),_=Number(e[s(1494)](rr,a[s(1426)][s(1740)],e[s(1327)]))||0,E=xa[s(1225)](this,a),m=nn(a[s(1426)][s(1740)],e[s(581)],"2"),O=e[s(1868)](rr,a.message[s(1740)],e[s(1679)]),N=e[s(809)](Number,rr(a.message.headers,e.xBleG));if(E[s(1634)])return e[s(1053)](r);let q=E[s(813)+"sage"]?await pl[s(1225)](this):null;if(e[s(892)](a[s(1426)][s(438)],0)&&h&&!l||e[s(1138)](a[s(1426)][s(438)],0)){if(p&&E["isQoSMes"+s(526)]&&q)return!!!await q[s(585)](p)&&(this[s(669)+s(953)+s(448)](a),await q[s(1762)](p,e[s(1365)](Date[s(405)](),_))),r();if(m){let W=await ml[s(1225)](this);if(!W)return this[s(669)+"hMessage"+s(448)](a),e.QZweR(r);let V=await W[s(585)](O)??-1;if(V<N)this["_dispatc"+s(953)+s(448)](a),W[s(1762)](O,N,a.message[s(438)]);else throw new Error("recevied"+s(416)+" cursor "+N+(s(1369)+"than loc"+s(1817)+"r ")+V);return e[s(1659)](r)}return this[s(669)+s(953)+s(448)](a),e[s(999)](r)}}async function pg(a,r){let s=t,l=xa[s(1225)](this,a);if(!l.isQoSMessage)return e[s(999)](r);let h=await pl[s(1225)](this);if(l[s(1627)+s(1536)+"age"]&&l[s(1407)+"s"][s(1078)])for(let p of l.ackMsgIds)await h.del(p);r()}async function gg(a,r){let s=t,l=e[s(1783)](a.message[s(427)+"e"],cg),h=a.message.frameType===ma;if(e[s(923)](!l,!h))return e[s(1667)](r);let p=rr(a[s(1426)][s(1740)],e.epHwz);if(!p)return r();let _=await ml[s(1225)](this,p);if(!_)return e[s(589)](r);if(l){let E=await _[s(926)+"rs"](),m={frameType:E?.[s(427)+"e"],SeqID:ue[s(876)+"er"](this._seqId++),LogID:ue.fromNumber(this._options["logIDGen"+s(1889)]()),service:9e3,method:5,headers:E?.headers,payload:E?.[s(910)]},O=e[s(1006)](S,m);this._ws&&this[s(1694)][s(1730)+"te"]&&this[s(1694)][s(1149)](O)}if(h){let E=a[s(1426)][s(910)];E&&_[s(399)+"rs"](E)}}let mg=async function(a,r){let s=t;this[s(513)]=!1,clearTimeout(this[s(1674)+s(1714)+s(1802)]),r()},wg=async function(a,r){let s=t,l={JHpEy:e[s(1240)],uQTfn:function(h,p){return e[s(579)](h,p)}};if(e.slIRW!==s(794)){let h=this[s(1678)+s(1283)]?.[s(1159)+s(961)+"nt"]();this._debug("connect "+h+s(1681)),this[s(463)+s(970)](1001,l[s(1107)],!0)}else{if(!this[s(1694)]||e.jRIXR(this[s(1694)][s(1730)+"te"],this.OPEN))return r();let{pingInterval:h}=this._options;this[s(1678)+"tManager"]?.[s(1279)+"pointCon"+s(1865)]();for(let _=0;e.JCRfU(_,this[s(1652)+s(523)].length);_++)if(e.qmoSu(e.LhWro,e[s(682)])){let E=this[s(1652)+s(523)][_];if(e[s(1572)](this._ws[s(1730)+"te"],this[s(1111)])&&e[s(1126)](null,E))if(e.yRAcx(e[s(553)],e[s(536)]))this[s(1694)]&&this._ws.send(E),this["_message"+s(523)][_]=null;else{let m=_0x2da365[s(1291)+"g"](0,DVmxcl[s(1389)](4,_0x16d12d[_0x3a9190][s(1078)])),O=m[s(1475)](_0x108280);_0x162fe9=_0x193040[s(1475)](O)}else break}else return this._ws?this[s(1694)].protocol:"";this[s(1652)+s(523)]=this["_message"+s(523)][s(1099)](_=>!!_),this[s(1436)+s(984)+"Id"]=e[s(1008)](setTimeout,()=>this[s(1463)](),h),this[s(669)+s(634)+"nt"](a),this[s(411)+"er"]&&this._ws&&(this[s(1694)].binaryType=this[s(1221)+s(1051)]);let p=this[s(1678)+"tManager"]?.[s(1159)+s(961)+"nt"]();this[s(1414)](s(1688)+p+s(1185)),e[s(921)](r)}},_g=async function(a,r){let s=t,l=this["_endpoin"+s(1283)]?.[s(1159)+s(961)+"nt"]();this._debug(s(1688)+l),r()};class yg extends ua{constructor(r){let s=t,l={mhckm:function(E,m,O,N){return e[U(1713)](E,m,O,N)},ObNkR:function(E,m,O){return e[U(472)](E,m,O)},LElQu:e[s(1706)],fIlfW:function(E,m){return e.KRsNZ(E,m)},CRoLZ:function(E,m){return e.DsDOP(E,m)},UgOOP:function(E,m,O){return E(m,O)},GweJN:"close",eQKHi:function(E,m){return e[s(1356)](E,m)},xAVub:function(E,m){return e[s(1021)](E,m)},JDqtr:function(E,m,O){return e[s(516)](E,m,O)},pegnF:e.nRppZ,vOaru:function(E,m){return E!==m},zbxxR:function(E,m){return E(m)},cDkpG:function(E,m,O){return e[s(1745)](E,m,O)},NIMOH:function(E,m,O){return e.nJzgh(E,m,O)}};super(),this[s(1363)+s(760)+s(465)]=!0,this[s(411)+"er"]=nr,this[s(1226)]=Mp,this[s(686)+"T"]=Rn,this[s(469)+"X"]=Zr,this[s(1549)+"r"]=Xr,this[s(1652)+s(523)]=[],this[s(1678)+s(1283)]=null,this[s(1035)+s(821)]=!1,this._binaryType=e[s(1683)],this[s(1674)+s(1366)]=!1,this["_connect"+s(1714)+s(1802)]=null,this["_reconne"+s(617)+"tId"]=null,this[s(1436)+s(984)+"Id"]=null,this._seqId=0,this._isInit=!1,this[s(895)]="",this[s(955)+s(1501)]=null,this[s(1636)+s(750)]=null,this["_pingLos"+s(908)]=null,this[s(1020)+"ls"]=s(1489),this[s(1346)]=3,this[s(1615)+"NG"]=0,this[s(1111)]=1,this[s(456)]=2,this[s(788)]=E=>{let m=s;try{l[m(1877)](ll,this,E,[mg,wg,_g])}catch(O){let N=l[m(1799)](ot,l[m(519)],{message:O[m(1426)],code:tn[m(979)+"OR"],error:O});this[m(669)+m(611)+"ent"](N)}},this[s(1252)+"ge"]=async E=>{let m=s,{pingInterval:O,pingFrequency:N}=this[m(1331)];if((e.djbgs("hi",E[m(630)])&&e[m(815)](e[m(1171)],N)||e.ihciH("auto",N))&&(this[m(484)+m(515)](),this[m(1191)](e.rBalc,e[m(740)]),this["_pingPon"+m(984)+"Id"]=setTimeout(this[m(1463)].bind(this),O)),!e.MHrCF("hi",E.data))try{e[m(800)](ll,this,E,[Zp,Jp,pg,gg,xg,Yp])}catch(q){if(e[m(1039)]===e[m(1039)]){let W=ot(m(1441),{message:q[m(1426)],code:tn["MESSAGE_"+m(1510)],error:q});this[m(669)+m(611)+m(543)](W)}else return this[m(1694)]?this[m(1694)][m(1165)]:this._url}},this._onError=E=>{let m=s,O=this[m(1678)+m(1283)]?.[m(1539)+m(1711)+"es"](),N=this[m(1678)+m(1283)]?.[m(1159)+m(961)+"nt"]();if(O&&!E.message){let q="connect "+N+(" fail, m"+m(1341)+"es reached");this[m(669)+m(611)+m(543)](e[m(1848)](ot,e[m(1706)],{message:q,code:tn[m(527)+m(1569)+"R"],error:E}));return}this._ws&&this[m(1694)].readyState===this[m(1111)]&&this[m(463)+m(970)](),this["_dispatc"+m(611)+"ent"](e[m(1400)](ot,m(1441),{message:E.message,code:tn[m(1558)+m(1029)],error:E}))},this[s(1215)]=async E=>{let m=s,O={jWQuL:function(q,W){return l[U(1123)](q,W)},Zlvxh:function(q,W){return l[U(561)](q,W)}};this[m(1286)+m(731)](),this[m(484)+"ngTimer"](),this[m(528)+m(466)+"rs"](),this[m(1694)]=null,this[m(1674)+m(1366)]=!1;let N=this[m(1678)+m(1283)]?.[m(1539)+m(1711)+"es"]();if(!N&&this[m(1807)+m(1339)]()&&!this[m(1035)+m(821)]){let q=this["_endpoin"+m(1283)]?.["getCurre"+m(961)+"nt"](),W=this[m(1331)]["reconnec"+m(1004)+m(862)](E[m(397)],E.reason);this[m(669)+"hCloseEv"+m(543)](l[m(891)](xt,l[m(1404)],{code:1006,reason:E[m(1524)]||m(758)+m(1825)+m(1318)+m(753)+m(881)+m(1811)+q,willReconnect:W})),W&&this[m(1674)]();return}if(l[m(1217)](1e3,E[m(397)])&&this[m(1035)+m(821)])if(l[m(626)](m(639),m(701)))_0x580504=IuGGTy.jWQuL(_0x35984c,_0x1f28c2),_0x26e631|=IuGGTy[m(385)](127,_0x536597)<<7;else{this[m(669)+m(1521)+"ent"](l.JDqtr(xt,l.GweJN,{code:1e3,reason:l[m(1440)]})),this[m(1678)+m(1283)]?.[m(1279)+m(643)+m(1865)](),this[m(1550)+m(908)]?.[m(1561)+"nter"]();return}if(l.vOaru(1e3,E[m(397)])&&N){let q=this[m(1678)+m(1283)]?.["getCurre"+m(961)+"nt"](),W=E[m(1524)];W||(W=await l.zbxxR(qp,this[m(895)])),W=m(758)+m(1825)+m(711)+W+(m(945)+m(826))+q+(m(1499)+m(1364)+m(1544)),this[m(669)+m(1521)+"ent"](l[m(556)](xt,l[m(1404)],{code:E[m(397)],reason:W}));let V=m(975)+q+(m(918)+m(1341)+m(1261)+"ed");this[m(669)+m(611)+"ent"](ot(l[m(519)],{message:V,code:tn[m(527)+m(1569)+"R"]})),this[m(1678)+"tManager"]?.[m(1279)+m(643)+m(1865)](),this[m(1550)+"sCounter"]?.[m(1561)+m(370)]();return}if(E[m(397)]!==1e3&&!E[m(1524)]){let q=this["_endpoin"+m(1283)]?.[m(1159)+"ntEndpoint"]();this[m(669)+"hCloseEv"+m(543)](l.NIMOH(xt,"close",{code:E[m(397)],reason:"connecti"+m(1825)+m(1318)+"wn reaso"+m(881)+m(1811)+q})),this["_endpoin"+m(1283)]?.["resetEndpointCon"+m(1865)](),this[m(1550)+m(908)]?.[m(1561)+m(370)]();return}this[m(669)+m(1521)+m(543)](E),this[m(1678)+m(1283)]?.["resetEnd"+m(643)+m(1865)](),this[m(1550)+m(908)]?.[m(1561)+"nter"]()},this.onclose=null,this.onerror=null,this[s(797)+"e"]=null,this.onopen=null,this[s(1587)+"econnect"]=null,this[s(739)+s(1199)]=null,this[s(1447)+"mediatel"+s(1724)+"ct"]=null,this[s(1112)+s(1281)]=this[s(1112)+s(1281)][s(1803)](this),this[s(1112)+s(398)]=this[s(1112)+s(398)][s(1803)](this),this["_handleP"+s(873)]=this[s(1080)+s(873)][s(1803)](this),this[s(1080)+s(1236)]=this[s(1080)+s(1236)][s(1803)](this),this[s(1331)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1680)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(1624),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1563)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:p}=r,_=Array[s(1746)](h)?h:e.QfxMF(s(533),typeof h)?[h]:[];if(!_||_[s(1078)]===0)throw new Error(e[s(878)]);if(!e[s(428)](zp,p))throw new Error(e[s(658)]);Object.assign(this[s(1331)],r),this[s(1678)+s(1283)]=new dl(_,this[s(1331)].maxRetries),this[s(1550)+s(908)]=new jp(this._options[s(396)+"Count"]),this[s(1331)].automaticOpen&&(this[s(513)]=!0,this._connect()),this[s(1331)]["listenNe"+s(901)+s(783)]&&(this[s(686)+"T"]||this._isMiniWX?this[s(1607)+s(1130)+"ange"]():this[s(411)+"er"]&&this[s(505)+"balEvent"+s(1434)]())}["_handleO"+t(1281)](){let r=t;this[r(1331)]["disableA"+r(1272)+r(1836)]||this["_readyCl"+r(821)]||this[r(1423)+r(880)]()}[t(1112)+"ffLine"](){let r=t;this["_destroy"+r(575)+"t"]();let s=e[r(517)](la,e[r(1691)],{message:e[r(586)]});this[r(1447)+"mediatel"+r(1724)+"ct"]&&this[r(1447)+r(1782)+r(1724)+"ct"](s)}["_initGlo"+t(640)+t(1434)](){let r=t,s={UEfco:e.jcTVI};e.QDrlx(e[r(607)],e[r(1249)])?(this[r(411)+"er"]&&window["addEvent"+r(1434)](e[r(748)],this[r(1112)+r(1281)]),this[r(411)+"er"]&&window[r(1886)+r(1434)](r(392),this[r(1112)+r(398)]),this[r(411)+"er"]&&window[r(1886)+r(1434)](e[r(1525)],this[r(1080)+r(873)]),this[r(411)+"er"]&&window[r(1886)+"Listener"](r(1589),this[r(1080)+"ageShow"])):(this[r(1191)](s.UEfco,_0x1ed31d),this[r(779)]&&this[r(779)](_0x24fc01))}[t(601)+t(640)+t(1434)](){let r=t;this._isBrowser&&window["removeEv"+r(854)+r(1516)](e.QIfSl,this._handleOnLine),this[r(411)+"er"]&&window[r(1118)+r(854)+"ner"]("offline",this[r(1112)+"ffLine"]),this[r(411)+"er"]&&window[r(1118)+"entListe"+r(1516)](e[r(1525)],this[r(1080)+r(873)]),this._isBrowser&&window[r(1118)+r(854)+r(1516)](e[r(754)],this[r(1080)+r(1236)])}[t(1080)+t(873)](r){let s=t;if(!r.persisted)if(e[s(1804)](e[s(673)],e[s(673)]))this._isBrowser&&window[s(1118)+"entListe"+s(1516)](s(726),this[s(1080)+s(873)]),this._isBrowser&&window[s(1118)+s(854)+s(1516)](e[s(754)],this["_handleP"+s(1236)]),this[s(1323)]();else return _0x4df5ad[s(803)]();this[s(411)+"er"]&&window["removeEventListe"+s(1516)](e[s(748)],this[s(1112)+s(1281)]),this._isBrowser&&window[s(1118)+s(854)+s(1516)](e[s(1303)],this[s(1112)+s(398)])}[t(1080)+t(1236)](r){let s=t;r[s(1412)+"d"]&&(this["_navigat"+s(1339)]()&&(!this._ws||e[s(1845)](this._ws.readyState,this.OPEN)||e[s(1151)](this[s(1694)][s(1730)+"te"],this[s(1615)+"NG"]))&&this[s(1112)+"nLine"](),this[s(411)+"er"]&&window[s(1886)+s(1434)](e.QIfSl,this["_handleO"+s(1281)]),this[s(411)+"er"]&&window["addEvent"+s(1434)](s(392),this[s(1112)+s(398)]))}async _generateUrl(r){let s=t,l={gsMxo:function(h,p){return e.NKTYL(h,p)},LCAxp:function(h,p){return e[U(1097)](h,p)}};if(e.pjFbe(e[s(545)],s(1410)))return _0x50596e[s(1776)+"8"]?{value:_0x24cde2[s(1776)+"8"](_0x5acc9f),offset:nVibbI[s(1743)](_0x44ae7d,1)}:{value:nVibbI.LCAxp(255,_0x5826b2[_0x4ad077]),offset:nVibbI[s(1743)](_0x2fdf16,1)};{let{fpID:h,deviceID:p,bddID:_,ttwID:E,accessKey:m,aID:O,customParams:N={},enableAutoAck:q,enableQoS:W,QoSLevel:V,env:qe}=this[s(1331)],rn,pt,wa;this[s(411)+"er"]||this[s(469)+"X"]||this[s(686)+"T"]?(rn=location&&e.QfxMF(e.NPNWC,location[s(1785)])?e[s(1707)]:s(778),pt=r[s(1721)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),wa=/^wss(.*:\/\/)/[s(1529)](r)?r:""+rn+pt):e[s(1725)]!==e[s(1725)]?(e[s(1200)](_0x36ba4a,e.uGipg),this[s(442)](e[s(988)],_0x21a470),this[s(442)](e[s(374)],_0x1aaf67)):(rn=e[s(1707)],pt=r[s(1721)](/(^http)((?:[s]*:\/\/))/,""),wa=/(^ws)((?:[s]*:\/\/))/[s(1529)](pt)?pt:""+rn+pt);let wl=_?e[s(1548)]:E?e[s(1342)]:e.MFydx,_l=_||E||p;if(!_l||!wl)throw new Error(e[s(1812)]);let bg=e[s(1106)](e[s(1731)],typeof N)?await N():N,Eg=qe?e[s(675)](Gp,qe[s(1786)],qe[s(1839)]):{},_a=Object[s(1503)]({device_platform:e[s(1186)],version_code:e.mrSWP,access_key:m,fpid:h,aid:O,[wl]:_l,xsack:q?1:0,xaack:q?1:0,xsqos:W?1:0,qos_level:W?V:void 0,qos_sdk_version:2,...Eg},bg),vg=Object.keys(_a).reduce((ya,ba)=>_a[ba]!==void 0?""+ya+(ya?"&":"?")+ba+"="+_a[ba]:ya,"");return wa+s(1665)+vg}}async _connect(){let r=t;if(!(this[r(1674)+"Lock"]||this[r(1035)+"osed"])){this[r(1674)+r(1366)]=!0;try{let s=this[r(1678)+r(1283)]?.[r(917)+r(1620)+r(680)+r(492)+"tries"](),{timeoutInterval:l}=this._options;if(s){let p=this[r(1678)+r(1283)]?.["getCurre"+r(961)+"nt"](),_=this[r(1678)+r(1283)]?.[r(1071)+"ackupEnd"+r(791)+r(1793)+r(1302)](),E=this[r(1678)+r(1283)]?.[r(1159)+r(961)+"ntTriesC"+r(1016)]();if(_){let m=r(975)+p+(" timeout, max re"+r(1364)+r(1329)+"ill use "+r(1265)+"ndpoint ")+_+" to retry",O=e[r(802)](ot,e[r(1706)],{message:m,code:tn["MAX_RETR"+r(1569)+"R"]});this[r(1414)](m),this[r(669)+r(611)+r(543)](O),this[r(895)]=await this[r(551)+r(435)](_),this._debug(r(975)+_+" "+E+" times"),this[r(528)+r(466)+"rs"]()}else if(e[r(1457)](e.xdLFc,r(1196))){if(!this[r(1674)+r(1366)]){let m=e.AUJfs[r(798)]("|"),O=0;for(;;){switch(m[O++]){case"0":this[r(1674)]();continue;case"1":this[r(1035)+r(821)]=!1;continue;case"2":this[r(1550)+r(908)]?.resetCounter();continue;case"3":this["_endpoin"+r(1283)]?.[r(1279)+"pointConfig"]();continue;case"4":this._isInit=!0;continue}break}}}else{let m=r(975)+p+(r(1681)+r(1499)+"tries reached");this[r(1414)](m),this[r(669)+r(611)+r(543)](e[r(557)](ot,e[r(1706)],{message:m,code:tn[r(527)+r(1569)+"R"]}));return}}else{let p=this[r(1678)+r(1283)]?.["getCurre"+r(961)+r(751)+r(699)](),_=this[r(1678)+r(1283)]?.[r(1159)+r(961)+r(1156)+r(1016)]();this[r(895)]=await this["_generat"+r(435)](e[r(596)](p,"")),this._debug("connect "+p+" "+_+" times"),this[r(528)+r(466)+"rs"]()}if(this[r(513)])this._isInit=!1;else{let p=e[r(671)](la,e[r(1691)],{message:e[r(1113)]});this[r(1587)+r(880)]&&this["onStartR"+r(880)](p)}let h=this[r(1678)+r(1283)]?.[r(1159)+"ntEndpointTriesCount"]()||0;e.XFUpF(h,1)&&await this[r(793)](h-1),this[r(1414)]("connecting url: "+this._url+(" protoco"+r(1816))+this[r(1020)+"ls"]),this[r(1694)]=e[r(937)](Fp,{url:this[r(895)],protocols:[this[r(1020)+"ls"]],headers:this[r(1331)][r(667)+"ramParams"][r(1479)+r(743)]},this._options.ws),(this._isBrowser||this[r(1549)+"r"])&&this[r(1694)]&&(this[r(1694)].binaryType=this[r(1221)+r(1051)]),this[r(1546)+r(1759)](),this[r(1674)+r(1714)+"utId"]=e[r(816)](setTimeout,this._onTimeout[r(1803)](this),l)}catch(s){throw this[r(1674)+r(1366)]=!1,s}}}[t(1286)+t(731)](){let r=t;e[r(1658)](clearTimeout,this[r(1674)+r(1714)+r(1802)]),this["_connect"+r(1714)+r(1802)]=null}[t(484)+t(515)](){let r=t;e[r(959)](clearTimeout,this[r(1436)+r(984)+"Id"]),clearTimeout(this["_reconne"+r(617)+r(644)]),this[r(1436)+r(984)+"Id"]=null,this["_reconnectTimeou"+r(644)]=null}_debug(...r){let s=t;this[s(1331)][s(696)]&&console[s(1043)].apply(console,[e[s(580)],...r])}[t(1577)+t(1506)+"e"](r){let s=t,{initReconnectInterval:l,maxReconnectInterval:h,reconnectIntervalGrowFactor:p}=this[s(1331)],_=e[s(1861)](l,Math[s(1237)](p,e[s(1262)](r,1)));return e[s(836)](_,h)?h:_}[t(1463)](){let r=t;if(this[r(1694)]&&e[r(762)](this[r(1694)].readyState,this.CONNECTING)){this[r(484)+r(515)](),this[r(1436)+r(984)+"Id"]=setTimeout(this[r(1463)][r(1803)](this),this._options.pingInterval);return}if(!this[r(1694)]||e[r(1612)](this[r(1694)][r(1730)+"te"],this[r(1111)]))return void this["_handleR"+r(880)]();this[r(1694)]&&this[r(1694)].send("hi"),this[r(1771)+"ctTimeou"+r(644)]=e[r(675)](setTimeout,this[r(1423)+r(880)+r(1753)][r(1803)](this),this[r(1331)][r(709)+"outInter"+r(1093)])}[t(1423)+t(880)+t(1753)](){let r=t;this[r(1550)+"sCounter"]?.[r(830)](),this.emit(r(447)+"e_timeout",e[r(819)]),this[r(1550)+"sCounter"]?.[r(1539)+"chMaxCount"]()?this[r(1423)+r(880)]():this[r(1463)]()}_navigatorOnline(){let r=t;return this[r(686)+"T"]||this[r(469)+"X"]?this[r(1363)+"igatorOn"+r(465)]:(this._isBrowser||this[r(1549)+"r"])&&this[r(1331)][r(1835)+r(901)+r(783)]?navigator.onLine:!0}[t(1423)+t(880)](){let r=t;!this[r(1807)+r(1339)]()||this[r(1035)+r(821)]||(this[r(1678)+r(1283)]?.[r(1279)+r(643)+r(1865)](),this["_pingLos"+r(908)]?.["resetCou"+r(370)](),this[r(1694)]?this[r(463)+"ect"](1001,r(512)+r(1800)+"reconnec"+r(531)+r(1085),!0):this[r(1674)]())}[t(1607)+t(1130)+t(610)](){let r=t;this[r(686)+"T"]?tt[r(1178)+r(1854)+r(1608)](({isConnected:s})=>{let l=r;this[l(1363)+l(760)+l(465)]=s,s?this[l(1112)+l(1281)]():this["_handleO"+l(398)]()}):this[r(469)+"X"]&&wx[r(1178)+r(1854)+r(1608)](({isConnected:s})=>{let l=r;this[l(1363)+l(760)+l(465)]=s,s?this[l(1112)+l(1281)]():this[l(1112)+l(398)]()})}[t(793)](r){return new Promise(s=>{let l=U,h={NfcQj:function(p,_){return e[U(1493)](p,_)},mjQNo:function(p,_){return e.OxNLa(p,_)}};if(e[l(1457)](e[l(883)],l(555)))e[l(962)](setTimeout,s,this[l(1577)+l(1506)+"e"](r));else{let{initReconnectInterval:p,maxReconnectInterval:_,reconnectIntervalGrowFactor:E}=this[l(1331)],m=cglyhh[l(1244)](p,_0x51885f[l(1237)](E,cglyhh[l(1500)](_0x2940e7,1)));return m>_?_:m}})}[t(463)+t(970)](r=1e3,s="",l=!1){let h=t;this[h(1694)]&&this[h(1175)+"WebSocket"](r,s,l)}[t(1218)+"ut"](){let r=t,s=this["_endpoin"+r(1283)]?.[r(1159)+"ntEndpoint"]();this[r(1414)](r(975)+s+r(1681)),this["_disconn"+r(970)](1001,r(720)+" try rec"+r(1512)+"g",!0)}[t(1332)](r){let s=t,l=e[s(1851)](Ft,r);this._ws&&e[s(434)](this[s(1694)][s(1730)+"te"],this[s(1111)])&&(this._ws&&this[s(1694)][s(1149)](l),this[s(1414)](e[s(1464)],r))}[t(528)+"sListeners"](){let r=t,s=e[r(1052)][r(798)]("|"),l=0;for(;;){switch(s[l++]){case"0":this._ws["removeEventListe"+r(1516)](e[r(707)],this[r(788)]);continue;case"1":this[r(1694)][r(1118)+r(854)+r(1516)]("message",this[r(1252)+"ge"]);continue;case"2":this[r(1694)][r(1118)+r(854)+r(1516)](e.jcTVI,this._onClose);continue;case"3":if(!this[r(1694)])return;continue;case"4":this[r(1694)][r(1118)+"entListe"+r(1516)](e[r(1706)],this[r(1609)]);continue}break}}["_addWsLi"+t(1759)](){let r=t,s={sVOMk:function(l,h){return e.cwihP(l,h)},LlMFA:function(l,h){return l<=h},wzBuy:function(l,h){return e.wjTdG(l,h)},HdShE:function(l,h){return l<<h},csTXb:function(l,h){return e[U(1508)](l,h)},YTNMI:function(l,h){return e[U(1158)](l,h)}};if(e[r(1879)]===r(1559)){if(!this[r(1694)])return;this[r(1694)][r(1886)+r(1434)](e[r(707)],this[r(788)]),this[r(1694)][r(1886)+"Listener"](e[r(1238)],this._onClose),this[r(1694)][r(1886)+r(1434)](e.PfXkj,this[r(1252)+"ge"]),this[r(1694)]["addEvent"+r(1434)](e[r(1706)],this[r(1609)])}else{let l=_0x28bae2[r(1074)+"At"](_0xa83ffa);tzTuEZ.sVOMk(l,55296)&&tzTuEZ[r(777)](l,56319)&&tzTuEZ.wzBuy(_0x1732ca,1)<_0x1fc406&&(l=tzTuEZ[r(904)](tzTuEZ.HdShE(l,10),_0x2ba7e5[r(1074)+"At"](++_0x2b6c5e))-56613888),_0x4302d7+=tzTuEZ[r(613)](l,128)?1:tzTuEZ.csTXb(l,2048)?2:tzTuEZ.YTNMI(l,65536)?3:4}}[t(944)+t(605)](r=1e3,s=""){let l=t;try{this[l(1694)]&&this._ws[l(1323)](r,s)}catch{}}[t(1175)+"WebSocket"](r=1e3,s="",l=!1){let h=t;if(this[h(484)+"ngTimer"](),this["_clearTi"+h(731)](),this._removeWsListeners(),this[h(944)+h(605)](1e3,s),this[h(1674)+"Lock"]=!1,l&&this[h(1807)+"orOnline"]()&&!this["_readyCl"+h(821)]){if(this[h(1678)+h(1283)]?.["checkRea"+h(1711)+"es"]()){let _=this[h(1678)+h(1283)]?.[h(1159)+"ntEndpoint"]();this["_dispatchCloseEv"+h(543)](e[h(1849)](xt,h(1323),{code:1006,reason:"connect "+_+(" timeout, max re"+h(1364)+h(1544)),wasClean:!0}))}else if(e.PSArI==="CwIhD"){let _=this[h(1331)][h(943)+h(1004)+"ptor"](r,s);this["_dispatc"+h(1521)+h(543)](e[h(1417)](xt,"close",{code:r,reason:s,wasClean:!0,willReconnect:_})),_&&this[h(1674)]()}else this[h(1363)+h(760)+h(465)]=_0x3dcaef,_0x43d886?this[h(1112)+h(1281)]():this[h(1112)+h(398)]();return}this["_navigat"+h(1339)]()||this[h(1035)+h(821)]?this[h(669)+h(1521)+h(543)](e.dFWSO(xt,e[h(1238)],{code:r,reason:e[h(1840)]})):this[h(669)+h(1521)+h(543)](xt(e[h(1238)],{code:1006,reason:e[h(747)]})),this._ws=null,this["_endpoin"+h(1283)]?.[h(1279)+"pointCon"+h(1865)](),this["_pingLos"+h(908)]?.[h(1561)+h(370)]()}[t(669)+t(634)+"nt"](r){let s=t;this[s(1191)](e[s(707)],r),this[s(1692)]&&this[s(1692)](r)}["_dispatc"+t(953)+"Event"](r){let s=t;e[s(985)]===e[s(693)]?(e[s(1083)](_0x58a059,_0x517695,82),e.sJZmu(_0x4ed807,_0xdf19c0,_0x32ee84)):(this[s(1191)](e[s(1129)],r),this[s(797)+"e"]&&this[s(797)+"e"](r))}[t(669)+t(871)+t(752)](r){let s=t;this[s(1191)]("ack",r),this[s(739)+"eAck"]&&this[s(739)+s(1199)](r)}[t(669)+t(611)+t(543)](r){let s=t;this[s(1191)](e[s(1706)],r),this[s(423)]&&this[s(423)](r)}[t(669)+t(1521)+"ent"](r){let s=t;this.emit(e[s(1238)],r),this[s(779)]&&this[s(779)](r)}get[t(1744)+"pe"](){let r=t;return this._ws?this._ws[r(1744)+"pe"]:this[r(1221)+"ype"]}set[t(1744)+"pe"](r){let s=t;if(e[s(429)](e[s(510)],e.NYuWE))this[s(1221)+s(1051)]=r,this._ws&&(this[s(1694)][s(1744)+"pe"]=r);else return{bytes:_0x443736,offset:0,limit:_0x44055b[s(1078)]}}get[t(1779)+"nt"](){let r=t;return this[r(1678)+r(1283)]?.[r(1159)+r(961)+r(1156)+r(1016)]()||0}get[t(1788)+t(1064)](){let r=t,s={VySZp:e[r(1801)],dQOyK:e.RTEoO},l=this[r(1652)+r(523)][r(1507)]((h,p)=>{let _=r;return s.VySZp!==s[_(1808)]?(h+=p&&p[_(1654)+"th"]||0,h):this[_(863)+_(730)]==this[_(1179)+"s"][_(1078)]?!0:this[_(455)+_(443)+_(1015)+"t"]>this[_(1456)+"es"]},0);return e[r(1147)](l,this[r(1694)]?this[r(1694)][r(1788)+r(1064)]:0)}get[t(1751)+"ns"](){let r=t;return this[r(1694)]?this[r(1694)][r(1751)+"ns"]:""}get[t(1785)](){let r=t;return this[r(1694)]?this._ws[r(1785)]:""}get readyState(){let r=t;return this[r(1694)]?this[r(1694)].readyState:this[r(1331)][r(564)+"cOpen"]?this[r(1615)+"NG"]:this.CLOSED}get[t(1165)](){let r=t;if(e[r(1809)](r(1460),e[r(1250)]))return this[r(1694)]?this[r(1694)][r(1165)]:this._url;try{this[r(495)]?.[r(1323)](),this._qosDB=void 0}catch(s){_0x152ba0[r(1043)](s)}}[t(1323)](r=1e3,s){let l=t,h=e[l(1478)].split("|"),p=0;for(;;){switch(h[p++]){case"0":this["_clearTi"+l(731)]();continue;case"1":this["_readyCl"+l(821)]=!0;continue;case"2":this[l(1175)+l(575)+"t"](r,s);continue;case"3":if(!this[l(1694)])return void this[l(1414)](e[l(554)]);continue;case"4":this[l(484)+l(515)]();continue;case"5":this["_QoSMana"+l(1501)]?.closeDB();continue;case"6":this[l(601)+l(640)+l(1434)]();continue;case"7":if(e[l(933)](this[l(1694)][l(1730)+"te"],this.CLOSED)||e.vcBdS(this._ws[l(1730)+"te"],this[l(456)]))return void this[l(1414)](e[l(1566)]);continue}break}}async[t(1149)](r,s){let l=t;if(e[l(1444)](null,r))throw new Error(e[l(1018)]);e[l(847)](e[l(1670)],typeof r)&&(r=JSON[l(1139)+"y"](r)),e[l(1689)]!=typeof r&&!e[l(1487)](r,ArrayBuffer)&&!(r.buffer&&e[l(1022)](r[l(1453)],ArrayBuffer))&&(r=JSON.stringify(r));let h=await e[l(1820)](hl,r),p=Up(r),{method:_=0,service:E=this[l(1331)][l(438)],logID:m=this[l(1331)][l(369)+l(1889)](),headers:O=this[l(1331)].headers,payloadEncoding:N=this[l(1331)][l(1829)+l(734)],payloadType:q=this[l(1331)][l(629)+l(1051)],logIDNew:W=this[l(1331)][l(660)+l(1211)]["enableAu"+l(595)+l(1266)+"ew"]?e[l(775)](i,this[l(1331)][l(660)+"Config"][l(475)]):""}=e[l(1481)](s,{});if(!E)throw new Error(e.rrDOx);let V={SeqID:ue.fromNumber(this._seqId++),LogID:ue[l(876)+"er"](m),service:E,method:_,headers:O,payloadEncoding:e[l(1377)](N,Object)?N[l(1573)]?N[l(1573)]:"":N,payloadType:e.KqJkg(q,Object)?q[l(1649)]?q.type:p:q||p,payload:h,LogIDNew:W},qe=e.MfRkX(Ft,V);return this[l(1694)]&&this[l(1694)].readyState===this.OPEN?(this[l(1694)]&&this[l(1694)][l(1149)](qe),this[l(1414)](e.PpBrL,V)):e.VlCfB(this[l(1652)+l(523)].length,this[l(1331)][l(776)+l(841)+l(670)])?(this._messageQueue[l(1777)](qe),this[l(1414)](e[l(1562)],V)):(this[l(1652)+l(523)][l(1357)](),this["_message"+l(523)][l(1777)](qe)),{seqID:this[l(1195)],logID:m,logIDNew:W}}async[t(943)+"t"](r){let s=t,{url:l}=e.vcEaw(r,{}),h=Array[s(1746)](l)?l:e.YFaYp(e[s(1689)],typeof l)?[l]:[];r&&Object[s(1503)](this[s(1331)],r),h&&h[s(1078)]?this[s(1678)+"tManager"]=new dl(h,this[s(1331)][s(1456)+"es"]):this["_endpoin"+s(1283)]?.[s(1279)+s(643)+"fig"](),this[s(1550)+s(908)]?.["resetCou"+s(370)](this[s(1331)][s(396)+"Count"]),this[s(1035)+s(821)]=!1,this[s(1694)]&&e.IHUcW(this._ws.readyState,this[s(1346)])?this["_disconn"+s(970)](1e3,e[s(889)],!0):(this[s(513)]=!0,this[s(1674)]())}async[t(1824)](){let r=t;if(!this["_connect"+r(1366)]){let s=(r(1644)+"3")[r(798)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[r(1035)+r(821)]=!1;continue;case"1":this[r(513)]=!0;continue;case"2":this["_pingLos"+r(908)]?.[r(1561)+"nter"]();continue;case"3":this[r(1674)]();continue;case"4":this[r(1678)+r(1283)]?.[r(1279)+r(643)+r(1865)]();continue}break}}}[t(1886)+t(1434)](r,s){this.on(r,s)}dispatchEvent(r){let{type:s}=r;this.emit(s,r)}[t(1118)+t(854)+t(1516)](r,s){this[t(442)](r,s)}[t(1395)](){let r=t,s={OPwVF:e.yQPyK,bdmgm:function(l,h,p,_){return l(h,p,_)},CSOkd:function(l,h){return e[U(1658)](l,h)},eFemP:e[r(819)],Xavuv:e[r(988)],lNXQU:e[r(374)]};if(e.VBTCZ(e[r(1655)],e[r(631)])){if(KZJhdh.OPwVF==typeof _0xd5b6b2){let l=new _0x30b832(_0x353b01(_0x450442));return KZJhdh[r(1036)](_0x52f8d8,_0x43d150,l,0),l}return _0x57ddf3 instanceof _0x44d843?new _0x4290c2(_0x483530):new _0x2bd7e7(_0x4a382b[r(1453)],_0x18b39f.byteOffset,_0x531b23[r(1654)+"th"])}else return new Promise((l,h)=>{let p=r,_={IJmEG:function(O,N){return e.HqoVx(O,N)},TKGsP:e[p(988)],qWcid:e[p(374)]};this[p(484)+p(515)](),this._pingPongTimeoutId=e.XrYtu(setTimeout,this[p(1463)][p(1803)](this),this[p(1331)][p(1541)+p(1610)]);let E=()=>{let O=p;_[O(1822)](l,O(449)),this[O(442)](_.TKGsP,E),this.off(_[O(1650)],m)},m=()=>{let O=p;s.CSOkd(h,s[O(1224)]),this[O(442)](s[O(1219)],E),this[O(442)](s.lNXQU,m)};this.on(p(447)+p(1408)+"s",E),this.on(e[p(374)],m),this[p(1463)]()})}}})(),Ne[L(1150)+L(592)]=Ce[L(1150)+L(592)],Ne[L(1368)+"rorEvent"]=Ce.CustomErrorEvent,Ne[L(1473)+"e"]=Ce.ErrorCode,Ne[L(448)]=Ce[L(448)],Ne[L(549)]=Ce.FWS,Ne[L(1401)+L(1571)+L(704)]=Ce["Frontier"+L(1571)+L(704)],Ne["MessageE"+L(704)]=Ce[L(1571)+L(704)],Ne[L(1882)+"t"]=Ce[L(1882)+"t"],Ne[L(1330)+"tEvent"]=Ce[L(1330)+L(470)],Ne[L(1698)+L(592)]=Ce[L(1698)+L(592)],Ne[L(1653)+L(437)]=Ce[L(1653)+L(437)],Ne[L(706)+L(736)+"nt"]=Ce[L(706)+"ssageEvent"],Ne[L(1726)+L(1378)]=Ce[L(1726)+L(1378)],Ne[L(1462)+L(1583)+"vent"]=Ce[L(1462)+"connectE"+L(704)],Ne[L(1632)+L(1131)]=Ce[L(1632)+"rame"],Ne[L(1455)+L(1575)]=Ce[L(1455)+L(1575)];for(Go in Ce)[L(1150)+L(592),"CustomEr"+L(437),L(1473)+"e","Event",L(549),"Frontier"+L(1571)+"vent",L(1571)+"vent",L(1882)+"t",L(1330)+L(470),L(1698)+L(592),L(1653)+L(437),L(706)+L(736)+"nt",L(1726)+L(1378),L(1462)+L(1583)+"vent",L(1632)+L(1131),"encodeFrame"][L(481)](Go)===-1&&(Ne[Go]=Ce[Go]);var Go;Object[L(628)+L(1012)](Ne,L(905)+"le",{value:!0})});import{existsSync as CS,openSync as RS}from"node:fs";import{mkdir as PS}from"node:fs/promises";import{dirname as DS}from"node:path";import{fileURLToPath as OS}from"node:url";function NS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ud(t=Q()){return CS(t.libEntry)?t.libEntry:OS(new URL("../index.ts",import.meta.url))}async function Vx(t={}){let e=t.paths??Q(),n=t.entryOverride??Ud(e),i=NS(e,process.env.COZE_BRIDGE_LOG_MODE);await PS(DS(i),{recursive:!0});let o=RS(i,"a"),d=n.endsWith(".ts")?["--import","tsx/esm",n,"--daemon"]:[n,"--daemon"],u=et(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[ns]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return LS.info("daemon spawned",{pid:u.pid,entry:n}),{pid:u.pid,entry:n}}var LS,ns,Xo=Xe(()=>{"use strict";Kt();te();De();LS=G("spawn-daemon"),ns="COZE_BRIDGE_DAEMON"});import{spawn as P1}from"node:child_process";import{mkdir as D1,unlink as O1,writeFile as L1}from"node:fs/promises";import{dirname as N1,join as M1}from"node:path";function Vr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function B1(t){if(!t)return"";let e=Object.entries(t).map(([n,i])=>` <key>${Vr(n)}</key>
|
|
21
21
|
<string>${Vr(i)}</string>`).join(`
|
|
22
22
|
`);return e?`
|
|
23
23
|
<key>EnvironmentVariables</key>
|
|
24
24
|
<dict>
|
|
25
25
|
${e}
|
|
26
|
-
</dict>`:""}function
|
|
26
|
+
</dict>`:""}function F1(t,e){return new Promise((n,i)=>{let o=P1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var $r,ss,ia,Yd,gp=Xe(()=>{"use strict";te();$r=G("supervisor.launchd"),ss="ai.coze.bridge",ia=F1,Yd={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>
|
|
@@ -44,11 +44,11 @@ ${e}
|
|
|
44
44
|
<key>StandardOutPath</key>
|
|
45
45
|
<string>${Vr(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${Vr(t.logFile)}</string>${
|
|
47
|
+
<string>${Vr(t.logFile)}</string>${B1(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function
|
|
50
|
+
`},configPath(t){return M1(t.homeDir,"Library","LaunchAgents",`${ss}.plist`)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t);if(await D1(N1(i),{recursive:!0}),await L1(i,this.renderConfig(t),"utf8"),$r.info("plist written",{plistPath:i,activate:n}),!n)return;await ia("launchctl",["unload","-w",i]).catch(c=>$r.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ia("launchctl",["load","-w",i]),$r.info("launchd job loaded",{label:ss});let o=process.getuid?.()??0;await ia("launchctl",["kickstart","-k",`gui/${o}/${ss}`]),$r.info("launchd job kickstarted",{label:ss,uid:o})},async uninstall(t){let e=this.configPath(t);await ia("launchctl",["unload","-w",e]).catch(n=>$r.warn("launchctl unload failed (ignored)",{err:String(n)})),await O1(e).catch(n=>{if(n.code!=="ENOENT")throw n}),$r.info("launchd job removed",{plistPath:e})}}});import{spawn as z1}from"node:child_process";import{mkdir as U1,unlink as G1,writeFile as j1}from"node:fs/promises";import{dirname as q1,join as mp}from"node:path";function oa(t,e){return t.isRoot?e:["--user",...e]}function W1(t){return t?Object.entries(t).map(([e,n])=>{let i=n.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function aa(t,e){return new Promise((n,i)=>{let o=z1(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?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var sa,Jr,H1,Zd,wp=Xe(()=>{"use strict";te();sa=G("supervisor.systemd"),Jr="coze-bridge.service",H1="/etc/systemd/system";Zd={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
|
+
${W1(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?
|
|
65
|
+
`},configPath(t){return t.isRoot?mp(H1,Jr):mp(t.homeDir,".config","systemd","user",Jr)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await U1(q1(i),{recursive:!0}),await j1(i,this.renderConfig(t),"utf8"),sa.info("systemd unit written",{unitPath:i,mode:o,activate:n}),await aa("systemctl",oa(t,["daemon-reload"])),await aa("systemctl",oa(t,n?["enable","--now",Jr]:["enable",Jr])),sa.info("systemd unit enabled",{unitName:Jr,mode:o,activate:n})},async uninstall(t){let e=this.configPath(t);await aa("systemctl",oa(t,["disable","--now",Jr])).catch(n=>sa.warn("systemctl disable failed (ignored)",{err:String(n)})),await G1(e).catch(n=>{if(n.code!=="ENOENT")throw n}),await aa("systemctl",oa(t,["daemon-reload"])).catch(()=>{}),sa.info("systemd unit removed",{unitPath:e})}}});import{spawn as K1}from"node:child_process";import{join as $1}from"node:path";function _p(t,e){return new Promise((n,i)=>{let o=K1(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?n():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Xd,ca,Qd,yp=Xe(()=>{"use strict";te();Xd=G("supervisor.taskscheduler"),ca="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,50 +86,50 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return KI(t.homeDir,".coze","bridge","task.xml")},async install(t){let n=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await wp("schtasks",["/Create","/SC","ONLOGON","/TN",la,"/TR",n,"/RU",t.userName,"/F"]),Xl.info("task scheduler entry created",{task:la,logFile:t.logFile})},async uninstall(t){await wp("schtasks",["/Delete","/TN",la,"/F"]).catch(e=>Xl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Xl.info("task scheduler entry removed",{task:la})}}});var yp={};va(yp,{buildContext:()=>XI,getSupervisor:()=>ZI,launchdSupervisor:()=>Jl,systemdSupervisor:()=>Yl,taskSchedulerSupervisor:()=>Ql});import{homedir as $I,userInfo as VI}from"node:os";function ZI(t=process.platform){switch(t){case"darwin":return Jl;case"linux":return Yl;case"win32":return Ql;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function YI(){let t={};for(let e of JI){let n=process.env[e];n&&(t[e]=n)}return t}function XI(){let t=Q();return{nodeBin:process.execPath,entry:Ul(t),logFile:t.logFile,homeDir:$I(),userName:VI().username,isRoot:process.getuid?.()===0,env:YI()}}var JI,bp=Qe(()=>{"use strict";Oe();Qo();pp();mp();_p();JI=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();sn();var Cd=q("acp-installer-warmup"),Zg=["claude-code","codex"];async function Pd(t={}){let e=t.ensure??ar,i=(await Promise.allSettled(Zg.map(async o=>{let c=await e(o);Cd.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Cd.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}cn();te();import{readdir as um}from"node:fs/promises";import{mkdir as Nd,readFile as lm,writeFile as Md}from"node:fs/promises";import{join as Ca}from"node:path";var dm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function dr(t,e,n){await Nd(t,{recursive:!0});let i=dm[e],o=Ca(t,i);return await Md(o,n??"","utf8"),o}async function Pa(t,e,n){let i=Ca(t,".claude");await Nd(i,{recursive:!0});let o=Ca(i,"settings.local.json"),c={};try{let u=await lm(o,"utf8"),h=JSON.parse(u);typeof h=="object"&&h!==null&&!Array.isArray(h)&&(c=h)}catch{}let l=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")l.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!n)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=n)}return c.permissions=l,await Md(o,JSON.stringify(c,null,2),"utf8"),o}var Je=q("agent-detail-sync"),fm=6e4,hm=5*6e4,ms=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let n=this.opts.paths.agentsRoot,i;try{i=await um(n)}catch(o){Je.info("agents dir not found, skip detail sync",{root:n,err:String(o)});return}Je.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await ke(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Je.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Je.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Je.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),n=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&n.push(i);if(n.length!==0){Je.info("retrying pending detail syncs",{count:n.length});for(let i of n)try{await this.syncOne(i)}catch(o){Je.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,n){let i=n??await ke(e,this.opts.paths);if(!i){Je.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(h){Je.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,hm):fm;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Je.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Je.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Je.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Je.debug("detail sync: no diff",{agentId:e});return}await Be(i,this.opts.paths),Je.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Je.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await dr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var el=Ut(pu(),1);import{createHash as $_}from"node:crypto";import{lstat as $c,mkdir as Vc,readFile as lo,readdir as t0,rm as Zc,stat as n0,writeFile as Jc}from"node:fs/promises";import{homedir as V_}from"node:os";import{dirname as Z_,join as me,normalize as J_,relative as Qc,resolve as Yc,sep as r0}from"node:path";import{Readable as i0}from"node:stream";import{pipeline as s0}from"node:stream/promises";import Nm from"events";import et from"fs";import{EventEmitter as Cc}from"node:events";import Ju from"node:stream";import{StringDecoder as Mm}from"node:string_decoder";import Qu from"node:path";import Er from"node:fs";import{dirname as Zm,parse as Jm}from"path";import{EventEmitter as iw}from"events";import uc from"assert";import{Buffer as qn}from"buffer";import*as yu from"zlib";import sw from"zlib";import{posix as pr}from"node:path";import{basename as Dw}from"node:path";import Zs from"fs";import kt from"fs";import Tu from"path";import{win32 as jw}from"node:path";import Lu from"path";import pf from"node:fs";import a_ from"node:assert";import{randomBytes as gf}from"node:crypto";import re from"node:fs";import Ne from"node:path";import mf from"fs";import io from"node:fs";import vi from"node:path";import st from"node:fs";import x_ from"node:fs/promises";import Xs from"node:path";import{join as kf}from"node:path";import it from"node:fs";import Pf from"node:path";var Om=Object.defineProperty,Lm=(t,e)=>{for(var n in e)Om(t,n,{get:e[n],enumerable:!0})},gu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Bm=t=>!!t&&typeof t=="object"&&(t instanceof Wn||t instanceof Ju||Fm(t)||zm(t)),Fm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.pipe=="function"&&t.pipe!==Ju.Writable.prototype.pipe,zm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.write=="function"&&typeof t.end=="function",Gt=Symbol("EOF"),qt=Symbol("maybeEmitEnd"),dn=Symbol("emittedEnd"),Es=Symbol("emittingEnd"),oi=Symbol("emittedError"),vs=Symbol("closed"),mu=Symbol("read"),Ss=Symbol("flush"),wu=Symbol("flushChunk"),gt=Symbol("encoding"),xr=Symbol("decoder"),Fe=Symbol("flowing"),ai=Symbol("paused"),_r=Symbol("resume"),ze=Symbol("buffer"),Ye=Symbol("pipes"),Ue=Symbol("bufferLength"),Ba=Symbol("bufferPush"),Is=Symbol("bufferShift"),Ze=Symbol("objectMode"),Ie=Symbol("destroyed"),Fa=Symbol("error"),za=Symbol("emitData"),_u=Symbol("emitEnd"),Ua=Symbol("emitEnd2"),It=Symbol("async"),Ga=Symbol("abort"),As=Symbol("aborted"),ci=Symbol("signal"),On=Symbol("dataListeners"),rt=Symbol("discarded"),li=t=>Promise.resolve().then(t),Um=t=>t(),Gm=t=>t==="end"||t==="finish"||t==="prefinish",qm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Hm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Yu=class{src;dest;opts;ondrain;constructor(t,e,n){this.src=t,this.dest=e,this.opts=n,this.ondrain=()=>t[_r](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},jm=class extends Yu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,n){super(t,e,n),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Wm=t=>!!t.objectMode,Km=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Wn=class extends Cc{[Fe]=!1;[ai]=!1;[Ye]=[];[ze]=[];[Ze];[gt];[It];[xr];[Gt]=!1;[dn]=!1;[Es]=!1;[vs]=!1;[oi]=null;[Ue]=0;[Ie]=!1;[ci];[As]=!1;[On]=0;[rt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Wm(e)?(this[Ze]=!0,this[gt]=null):Km(e)?(this[gt]=e.encoding,this[Ze]=!1):(this[Ze]=!1,this[gt]=null),this[It]=!!e.async,this[xr]=this[gt]?new Mm(this[gt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[ze]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ye]});let{signal:n}=e;n&&(this[ci]=n,n.aborted?this[Ga]():n.addEventListener("abort",()=>this[Ga]()))}get bufferLength(){return this[Ue]}get encoding(){return this[gt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ze]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ga](){this[As]=!0,this.emit("abort",this[ci]?.reason),this.destroy(this[ci]?.reason)}get aborted(){return this[As]}set aborted(t){}write(t,e,n){if(this[As])return!1;if(this[Gt])throw new Error("write after end");if(this[Ie])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(n=e,e="utf8"),e||(e="utf8");let i=this[It]?li:Um;if(!this[Ze]&&!Buffer.isBuffer(t)){if(Hm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(qm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ze]?(this[Fe]&&this[Ue]!==0&&this[Ss](!0),this[Fe]?this.emit("data",t):this[Ba](t),this[Ue]!==0&&this.emit("readable"),n&&i(n),this[Fe]):t.length?(typeof t=="string"&&!(e===this[gt]&&!this[xr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[gt]&&(t=this[xr].write(t)),this[Fe]&&this[Ue]!==0&&this[Ss](!0),this[Fe]?this.emit("data",t):this[Ba](t),this[Ue]!==0&&this.emit("readable"),n&&i(n),this[Fe]):(this[Ue]!==0&&this.emit("readable"),n&&i(n),this[Fe])}read(t){if(this[Ie])return null;if(this[rt]=!1,this[Ue]===0||t===0||t&&t>this[Ue])return this[qt](),null;this[Ze]&&(t=null),this[ze].length>1&&!this[Ze]&&(this[ze]=[this[gt]?this[ze].join(""):Buffer.concat(this[ze],this[Ue])]);let e=this[mu](t||null,this[ze][0]);return this[qt](),e}[mu](t,e){if(this[Ze])this[Is]();else{let n=e;t===n.length||t===null?this[Is]():typeof n=="string"?(this[ze][0]=n.slice(t),e=n.slice(0,t),this[Ue]-=t):(this[ze][0]=n.subarray(t),e=n.subarray(0,t),this[Ue]-=t)}return this.emit("data",e),!this[ze].length&&!this[Gt]&&this.emit("drain"),e}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e="utf8"),t!==void 0&&this.write(t,e),n&&this.once("end",n),this[Gt]=!0,this.writable=!1,(this[Fe]||!this[ai])&&this[qt](),this}[_r](){this[Ie]||(!this[On]&&!this[Ye].length&&(this[rt]=!0),this[ai]=!1,this[Fe]=!0,this.emit("resume"),this[ze].length?this[Ss]():this[Gt]?this[qt]():this.emit("drain"))}resume(){return this[_r]()}pause(){this[Fe]=!1,this[ai]=!0,this[rt]=!1}get destroyed(){return this[Ie]}get flowing(){return this[Fe]}get paused(){return this[ai]}[Ba](t){this[Ze]?this[Ue]+=1:this[Ue]+=t.length,this[ze].push(t)}[Is](){return this[Ze]?this[Ue]-=1:this[Ue]-=this[ze][0].length,this[ze].shift()}[Ss](t=!1){do;while(this[wu](this[Is]())&&this[ze].length);!t&&!this[ze].length&&!this[Gt]&&this.emit("drain")}[wu](t){return this.emit("data",t),this[Fe]}pipe(t,e){if(this[Ie])return t;this[rt]=!1;let n=this[dn];return e=e||{},t===gu.stdout||t===gu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,n?e.end&&t.end():(this[Ye].push(e.proxyErrors?new jm(this,t,e):new Yu(this,t,e)),this[It]?li(()=>this[_r]()):this[_r]()),t}unpipe(t){let e=this[Ye].find(n=>n.dest===t);e&&(this[Ye].length===1?(this[Fe]&&this[On]===0&&(this[Fe]=!1),this[Ye]=[]):this[Ye].splice(this[Ye].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let n=super.on(t,e);if(t==="data")this[rt]=!1,this[On]++,!this[Ye].length&&!this[Fe]&&this[_r]();else if(t==="readable"&&this[Ue]!==0)super.emit("readable");else if(Gm(t)&&this[dn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[oi]){let i=e;this[It]?li(()=>i.call(this,this[oi])):i.call(this,this[oi])}return n}removeListener(t,e){return this.off(t,e)}off(t,e){let n=super.off(t,e);return t==="data"&&(this[On]=this.listeners("data").length,this[On]===0&&!this[rt]&&!this[Ye].length&&(this[Fe]=!1)),n}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[On]=0,!this[rt]&&!this[Ye].length&&(this[Fe]=!1)),e}get emittedEnd(){return this[dn]}[qt](){!this[Es]&&!this[dn]&&!this[Ie]&&this[ze].length===0&&this[Gt]&&(this[Es]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[vs]&&this.emit("close"),this[Es]=!1)}emit(t,...e){let n=e[0];if(t!=="error"&&t!=="close"&&t!==Ie&&this[Ie])return!1;if(t==="data")return!this[Ze]&&!n?!1:this[It]?(li(()=>this[za](n)),!0):this[za](n);if(t==="end")return this[_u]();if(t==="close"){if(this[vs]=!0,!this[dn]&&!this[Ie])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[oi]=n,super.emit(Fa,n);let o=!this[ci]||this.listeners("error").length?super.emit("error",n):!1;return this[qt](),o}else if(t==="resume"){let o=super.emit("resume");return this[qt](),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[qt](),i}[za](t){for(let n of this[Ye])n.dest.write(t)===!1&&this.pause();let e=this[rt]?!1:super.emit("data",t);return this[qt](),e}[_u](){return this[dn]?!1:(this[dn]=!0,this.readable=!1,this[It]?(li(()=>this[Ua]()),!0):this[Ua]())}[Ua](){if(this[xr]){let e=this[xr].end();if(e){for(let n of this[Ye])n.dest.write(e);this[rt]||super.emit("data",e)}}for(let e of this[Ye])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ze]||(t.dataLength=0);let e=this.promise();return this.on("data",n=>{t.push(n),this[Ze]||(t.dataLength+=n.length)}),await e,t}async concat(){if(this[Ze])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[gt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ie,()=>e(new Error("stream destroyed"))),this.on("error",n=>e(n)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[rt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[Gt])return e();let i,o,c=x=>{this.off("data",l),this.off("end",u),this.off(Ie,h),e(),o(x)},l=x=>{this.off("error",c),this.off("end",u),this.off(Ie,h),this.pause(),i({value:x,done:!!this[Gt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Ie,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(Ie,h),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[rt]=!1;let t=!1,e=()=>(this.pause(),this.off(Fa,e),this.off(Ie,e),this.off("end",e),t=!0,{done:!0,value:void 0}),n=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Fa,e),this.once(Ie,e),{next:n,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Ie])return t?this.emit("error",t):this.emit(Ie),this;this[Ie]=!0,this[rt]=!0,this[ze].length=0,this[Ue]=0;let e=this;return typeof e.close=="function"&&!this[vs]&&e.close(),t?this.emit("error",t):this.emit(Ie),this}static get isStream(){return Bm}},$m=et.writev,yn=Symbol("_autoClose"),yt=Symbol("_close"),di=Symbol("_ended"),le=Symbol("_fd"),qa=Symbol("_finished"),Kt=Symbol("_flags"),Ha=Symbol("_flush"),lc=Symbol("_handleChunk"),dc=Symbol("_makeBuf"),bi=Symbol("_mode"),Ts=Symbol("_needDrain"),Sr=Symbol("_onerror"),Ir=Symbol("_onopen"),ja=Symbol("_onread"),yr=Symbol("_onwrite"),bn=Symbol("_open"),_t=Symbol("_path"),pn=Symbol("_pos"),At=Symbol("_queue"),br=Symbol("_read"),Wa=Symbol("_readSize"),Wt=Symbol("_reading"),ui=Symbol("_remain"),Ka=Symbol("_size"),Bs=Symbol("_write"),Ln=Symbol("_writing"),Fs=Symbol("_defaultFlag"),Gn=Symbol("_errored"),Pc=class extends Wn{[Gn]=!1;[le];[_t];[Wa];[Wt]=!1;[Ka];[ui];[yn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Gn]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[_t]=t,this[Wa]=e.readSize||16*1024*1024,this[Wt]=!1,this[Ka]=typeof e.size=="number"?e.size:1/0,this[ui]=this[Ka],this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[br]():this[bn]()}get fd(){return this[le]}get path(){return this[_t]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[bn](){et.open(this[_t],"r",(t,e)=>this[Ir](t,e))}[Ir](t,e){t?this[Sr](t):(this[le]=e,this.emit("open",e),this[br]())}[dc](){return Buffer.allocUnsafe(Math.min(this[Wa],this[ui]))}[br](){if(!this[Wt]){this[Wt]=!0;let t=this[dc]();if(t.length===0)return process.nextTick(()=>this[ja](null,0,t));et.read(this[le],t,0,t.length,null,(e,n,i)=>this[ja](e,n,i))}}[ja](t,e,n){this[Wt]=!1,t?this[Sr](t):this[lc](e,n)&&this[br]()}[yt](){if(this[yn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Sr](t){this[Wt]=!0,this[yt](),this.emit("error",t)}[lc](t,e){let n=!1;return this[ui]-=t,t>0&&(n=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ui]<=0)&&(n=!1,this[yt](),super.end()),n}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[br](),!1;case"error":return this[Gn]?!1:(this[Gn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Vm=class extends Pc{[bn](){let t=!0;try{this[Ir](null,et.openSync(this[_t],"r")),t=!1}finally{t&&this[yt]()}}[br](){let t=!0;try{if(!this[Wt]){this[Wt]=!0;do{let e=this[dc](),n=e.length===0?0:et.readSync(this[le],e,0,e.length,null);if(!this[lc](n,e))break}while(!0);this[Wt]=!1}t=!1}finally{t&&this[yt]()}}[yt](){if(this[yn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.closeSync(t),this.emit("close")}}},Qs=class extends Nm{readable=!1;writable=!0;[Gn]=!1;[Ln]=!1;[di]=!1;[At]=[];[Ts]=!1;[_t];[bi];[yn];[le];[Fs];[Kt];[qa]=!1;[pn];constructor(t,e){e=e||{},super(e),this[_t]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[bi]=e.mode===void 0?438:e.mode,this[pn]=typeof e.start=="number"?e.start:void 0,this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let n=this[pn]!==void 0?"r+":"w";this[Fs]=e.flags===void 0,this[Kt]=e.flags===void 0?n:e.flags,this[le]===void 0&&this[bn]()}emit(t,...e){if(t==="error"){if(this[Gn])return!1;this[Gn]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[_t]}[Sr](t){this[yt](),this[Ln]=!0,this.emit("error",t)}[bn](){et.open(this[_t],this[Kt],this[bi],(t,e)=>this[Ir](t,e))}[Ir](t,e){this[Fs]&&this[Kt]==="r+"&&t&&t.code==="ENOENT"?(this[Kt]="w",this[bn]()):t?this[Sr](t):(this[le]=e,this.emit("open",e),this[Ln]||this[Ha]())}end(t,e){return t&&this.write(t,e),this[di]=!0,!this[Ln]&&!this[At].length&&typeof this[le]=="number"&&this[yr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[di]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[Ln]||this[At].length?(this[At].push(t),this[Ts]=!0,!1):(this[Ln]=!0,this[Bs](t),!0)}[Bs](t){et.write(this[le],t,0,t.length,this[pn],(e,n)=>this[yr](e,n))}[yr](t,e){t?this[Sr](t):(this[pn]!==void 0&&typeof e=="number"&&(this[pn]+=e),this[At].length?this[Ha]():(this[Ln]=!1,this[di]&&!this[qa]?(this[qa]=!0,this[yt](),this.emit("finish")):this[Ts]&&(this[Ts]=!1,this.emit("drain"))))}[Ha](){if(this[At].length===0)this[di]&&this[yr](null,0);else if(this[At].length===1)this[Bs](this[At].pop());else{let t=this[At];this[At]=[],$m(this[le],t,this[pn],(e,n)=>this[yr](e,n))}}[yt](){if(this[yn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Xu=class extends Qs{[bn](){let t;if(this[Fs]&&this[Kt]==="r+")try{t=et.openSync(this[_t],this[Kt],this[bi])}catch(e){if(e?.code==="ENOENT")return this[Kt]="w",this[bn]();throw e}else t=et.openSync(this[_t],this[Kt],this[bi]);this[Ir](null,t)}[yt](){if(this[yn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,et.closeSync(t),this.emit("close")}}[Bs](t){let e=!0;try{this[yr](null,et.writeSync(this[le],t,0,t.length,this[pn])),e=!1}finally{if(e)try{this[yt]()}catch{}}}},Ym=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"]]),Xm=t=>!!t.sync&&!!t.file,Qm=t=>!t.sync&&!!t.file,ew=t=>!!t.sync&&!t.file,tw=t=>!t.sync&&!t.file,nw=t=>!!t.file,rw=t=>Ym.get(t)||t,Dc=(t={})=>{if(!t)return{};let e={};for(let[n,i]of Object.entries(t)){let o=rw(n);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ci=(t,e,n,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let h=Dc(c);if(o?.(h,l),Xm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,l)}else if(Qm(h)){let x=e(h,l);return u?x.then(()=>u(),u):x}else if(ew(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return n(h,l)}else if(tw(h)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(h,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:n,asyncNoFile:i,validate:o}),ow=sw.constants||{ZLIB_VERNUM:4736},Ct=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},ow)),aw=qn.concat,bu=Object.getOwnPropertyDescriptor(qn,"concat"),cw=t=>t,$a=bu?.writable===!0||bu?.set!==void 0?t=>{qn.concat=t?cw:aw}:t=>{},Hn=Symbol("_superWrite"),ks=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"}},Va=Symbol("flushFlag"),Oc=class extends Wn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof yu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new yu[e](t)}catch(n){throw new ks(n,this.constructor)}this.#o=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#o(new ks(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return uc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(qn.alloc(0),{[Va]:t})))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(n)}get ended(){return this.#n}[Hn](t){return super.write(t)}write(t,e,n){if(typeof e=="function"&&(n=e,e="utf8"),typeof t=="string"&&(t=qn.from(t,e)),this.#e)return;uc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let l;try{let h=typeof t[Va]=="number"?t[Va]:this.#r;l=this.#t._processChunk(t,h),$a(!1)}catch(h){$a(!1),this.#o(new ks(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 ks(h,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let h=l[0];u=this[Hn](qn.from(h));for(let x=1;x<l.length;x++)u=this[Hn](l[x])}else u=this[Hn](qn.from(l));return n&&n(),u}},ef=class extends Oc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Ct.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Ct.Z_FINISH,t.fullFlushFlag=Ct.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(Ct.Z_SYNC_FLUSH),uc(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=n}this.handle&&(this.#e=t,this.#n=e)}}}},lw=class extends ef{#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)}},dw=class extends ef{constructor(t){super(t,"Unzip")}},tf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Ct.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Ct.BROTLI_OPERATION_FLUSH,super(t,e)}},uw=class extends tf{constructor(t){super(t,"BrotliCompress")}},fw=class extends tf{constructor(t){super(t,"BrotliDecompress")}},nf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.ZSTD_e_continue,t.finishFlush=t.finishFlush||Ct.ZSTD_e_end,t.fullFlushFlag=Ct.ZSTD_e_flush,super(t,e)}},hw=class extends nf{constructor(t){super(t,"ZstdCompress")}},xw=class extends nf{constructor(t){super(t,"ZstdDecompress")}},pw=(t,e)=>{if(Number.isSafeInteger(t))t<0?mw(t,e):gw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},gw=(t,e)=>{e[0]=128;for(var n=e.length;n>1;n--)e[n-1]=t&255,t=Math.floor(t/256)},mw=(t,e)=>{e[0]=255;var n=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),n?e[i-1]=rf(o):o===0?e[i-1]=0:(n=!0,e[i-1]=sf(o))}},ww=t=>{let e=t[0],n=e===128?yw(t.subarray(1,t.length)):e===255?_w(t):null;if(n===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(n))throw Error("parsed number outside of javascript safe integer range");return n},_w=t=>{for(var e=t.length,n=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=rf(c):c===0?l=c:(i=!0,l=sf(c)),l!==0&&(n-=l*Math.pow(256,e-o-1))}return n},yw=t=>{for(var e=t.length,n=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(n+=o*Math.pow(256,e-i-1))}return n},rf=t=>(255^t)&255,sf=t=>(255^t)+1&255,bw={};Lm(bw,{code:()=>Lc,isCode:()=>zs,isName:()=>Ew,name:()=>eo,normalFsTypes:()=>of});var zs=t=>eo.has(t),Ew=t=>Lc.has(t),of=new Set(["0","","1","2","3","4","5","6","7","D"]),eo=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"]]),Lc=new Map(Array.from(eo).map(t=>[t[1],t[0]])),jn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,n,i){Buffer.isBuffer(t)?this.decode(t,e||0,n,i):t&&this.#n(t)}decode(t,e,n,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Nn(t,e+156,1),c=of.has(o),l=c?n:void 0,u=c?i:void 0;if(this.path=l?.path??Nn(t,e,100),this.mode=l?.mode??u?.mode??gn(t,e+100,8),this.uid=l?.uid??u?.uid??gn(t,e+108,8),this.gid=l?.gid??u?.gid??gn(t,e+116,8),this.size=l?.size??u?.size??gn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??Za(t,e+136,12),this.cksum=gn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),zs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Nn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Nn(t,e+265,32),this.gname=l?.gname??u?.gname??Nn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??gn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??gn(t,e+337,8)??0,t[e+475]!==0){let x=Nn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Nn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=n?.atime??i?.atime??Za(t,e+476,12),this.ctime=n?.ctime??i?.ctime??Za(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(([n,i])=>!(i==null||n==="path"&&e||n==="linkpath"&&e||n==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,i=vw(this.path||"",n),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Mn(t,e,100,o)||this.needPax,this.needPax=mn(t,e+100,8,this.mode)||this.needPax,this.needPax=mn(t,e+108,8,this.uid)||this.needPax,this.needPax=mn(t,e+116,8,this.gid)||this.needPax,this.needPax=mn(t,e+124,12,this.size)||this.needPax,this.needPax=Ja(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Mn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Mn(t,e+265,32,this.uname)||this.needPax,this.needPax=Mn(t,e+297,32,this.gname)||this.needPax,this.needPax=mn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=mn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Mn(t,e+345,n,c)||this.needPax,t[e+475]!==0?this.needPax=Mn(t,e+345,155,c)||this.needPax:(this.needPax=Mn(t,e+345,130,c)||this.needPax,this.needPax=Ja(t,e+476,12,this.atime)||this.needPax,this.needPax=Ja(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,mn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:eo.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Lc.get(t));if(zs(e)||e==="Unsupported")this.#e=e;else if(zs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},vw=(t,e)=>{let n=t,i="",o,c=pr.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,i,!1];else{i=pr.dirname(n),n=pr.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(i)<=e?o=[n,i,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(i)<=e?o=[n.slice(0,99),i,!0]:(n=pr.join(pr.basename(i),n),i=pr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Nn=(t,e,n)=>t.subarray(e,e+n).toString("utf8").replace(/\0.*/,""),Za=(t,e,n)=>Sw(gn(t,e,n)),Sw=t=>t===void 0?void 0:new Date(t*1e3),gn=(t,e,n)=>Number(t[e])&128?ww(t.subarray(e,e+n)):Aw(t,e,n),Iw=t=>isNaN(t)?void 0:t,Aw=(t,e,n)=>Iw(parseInt(t.subarray(e,e+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),Tw={12:8589934591,8:2097151},mn=(t,e,n,i)=>i===void 0?!1:i>Tw[n]||i<0?(pw(i,t.subarray(e,e+n)),!0):(kw(t,e,n,i),!1),kw=(t,e,n,i)=>t.write(Rw(i,n),e,n,"ascii"),Rw=(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",Ja=(t,e,n,i)=>i===void 0?!1:mn(t,e,n,i.getTime()/1e3),Pw=new Array(156).join("\0"),Mn=(t,e,n,i)=>i===void 0?!1:(t.write(i+Pw,e,n,"utf8"),i.length!==Buffer.byteLength(i)||i.length>n),Vs=class af{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,n=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=n,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let n=Buffer.byteLength(e),i=512*Math.ceil(1+n/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new jn({path:("PaxHeader/"+Dw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:n,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,n,"utf8");for(let c=n+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let n=this[e],i=n instanceof Date?n.getTime()/1e3:n,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
-
`,c=Buffer.byteLength(o),
|
|
91
|
-
`).reduce(Nw,Object.create(null)),Nw=(t,e)=>{let n=parseInt(e,10);if(n!==Buffer.byteLength(e)+1)return t;e=e.slice((n+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},Mw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=Mw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Bw=class extends Wn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,n){switch(super({}),this.pause(),this.extended=e,this.globalExtended=n,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=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),n&&this.#e(n,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,i=this.blockRemain;return this.remain=Math.max(0,n-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:n>=e?super.write(t):super.write(t.subarray(0,n))}#e(t,e=!1){t.path&&(t.path=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e))))}},to=(t,e,n,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=n instanceof Error&&n.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(n instanceof Error&&(i=Object.assign(n,i),n=n.message),t.emit("warn",e,n,i)):n instanceof Error?t.emit("error",Object.assign(n,i)):t.emit("error",Object.assign(new Error(`${e}: ${n}`),i))},Fw=1024*1024,fc=Buffer.from([31,139]),hc=Buffer.from([40,181,47,253]),zw=Math.max(fc.length,hc.length),lt=Symbol("state"),Bn=Symbol("writeEntry"),Ht=Symbol("readEntry"),Ya=Symbol("nextEntry"),Eu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),fi=Symbol("globalExtendedHeader"),un=Symbol("meta"),vu=Symbol("emitMeta"),ge=Symbol("buffer"),jt=Symbol("queue"),fn=Symbol("ended"),Xa=Symbol("emittedEnd"),Fn=Symbol("emit"),Re=Symbol("unzip"),Rs=Symbol("consumeChunk"),Cs=Symbol("consumeChunkSub"),Qa=Symbol("consumeBody"),Su=Symbol("consumeMeta"),Iu=Symbol("consumeHeader"),hi=Symbol("consuming"),ec=Symbol("bufferConcat"),Ps=Symbol("maybeEnd"),gr=Symbol("writing"),hn=Symbol("aborted"),Ds=Symbol("onDone"),zn=Symbol("sawValidEntry"),Os=Symbol("sawNullBlock"),Ls=Symbol("sawEOF"),Au=Symbol("closeStream"),Uw=()=>!0,Ri=class extends iw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[jt]=[];[ge];[Ht];[Bn];[lt]="begin";[un]="";[Tt];[fi];[fn]=!1;[Re];[hn]=!1;[zn];[Os]=!1;[Ls]=!1;[gr]=!1;[hi]=!1;[Xa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ds,()=>{(this[lt]==="begin"||this[zn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ds,t.ondone):this.on(Ds,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Fw,this.filter=typeof t.filter=="function"?t.filter:Uw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let n=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:n?!0:void 0,this.on("end",()=>this[Au]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,n={}){to(this,t,e,n)}[Iu](t,e){this[zn]===void 0&&(this[zn]=!1);let n;try{n=new jn(t,e,this[Tt],this[fi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(n.nullBlock)this[Os]?(this[Ls]=!0,this[lt]==="begin"&&(this[lt]="header"),this[Fn]("eof")):(this[Os]=!0,this[Fn]("nullBlock"));else if(this[Os]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let i=n.type;if(/^(Symbolic)?Link$/.test(i)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let o=this[Bn]=new Bw(n,this[Tt],this[fi]);if(!this[zn])if(o.remain){let c=()=>{o.invalid||(this[zn]=!0)};o.on("end",c)}else this[zn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Fn]("ignoredEntry",o),this[lt]="ignore",o.resume()):o.size>0&&(this[un]="",o.on("data",c=>this[un]+=c),this[lt]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Fn]("ignoredEntry",o),this[lt]=o.remain?"ignore":"header",o.resume()):(o.remain?this[lt]="body":(this[lt]="header",o.end()),this[Ht]?this[jt].push(o):(this[jt].push(o),this[Ya]())))}}}[Au](){queueMicrotask(()=>this.emit("close"))}[Eu](t){let e=!0;if(!t)this[Ht]=void 0,e=!1;else if(Array.isArray(t)){let[n,...i]=t;this.emit(n,...i)}else this[Ht]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ya]()),e=!1);return e}[Ya](){do;while(this[Eu](this[jt].shift()));if(this[jt].length===0){let t=this[Ht];!t||t.flowing||t.size===t.remain?this[gr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Qa](t,e){let n=this[Bn];if(!n)throw new Error("attempt to consume body without entry??");let i=n.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return n.write(o),n.blockRemain||(this[lt]="header",this[Bn]=void 0,n.end()),o.length}[Su](t,e){let n=this[Bn],i=this[Qa](t,e);return!this[Bn]&&n&&this[vu](n),i}[Fn](t,e,n){this[jt].length===0&&!this[Ht]?this.emit(t,e,n):this[jt].push([t,e,n])}[vu](t){switch(this[Fn]("meta",this[un]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Vs.parse(this[un],this[Tt],!1);break;case"GlobalExtendedHeader":this[fi]=Vs.parse(this[un],this[fi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[un].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[un].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[hn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[hn])return n?.(),!1;if((this[Re]===void 0||this.brotli===void 0&&this[Re]===!1)&&t){if(this[ge]&&(t=Buffer.concat([this[ge],t]),this[ge]=void 0),t.length<zw)return this[ge]=t,n?.(),!0;for(let l=0;this[Re]===void 0&&l<fc.length;l++)t[l]!==fc[l]&&(this[Re]=!1);let o=!1;if(this[Re]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<hc.length;l++)if(t[l]!==hc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Re]===!1&&c)if(t.length<512)if(this[fn])this.brotli=!0;else return this[ge]=t,n?.(),!0;else try{new jn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Re]===void 0||this[Re]===!1&&(this.brotli||o)){let l=this[fn];this[fn]=!1,this[Re]=this[Re]===void 0?new dw({}):o?new xw({}):new fw({}),this[Re].on("data",h=>this[Rs](h)),this[Re].on("error",h=>this.abort(h)),this[Re].on("end",()=>{this[fn]=!0,this[Rs]()}),this[gr]=!0;let u=!!this[Re][l?"end":"write"](t);return this[gr]=!1,n?.(),u}}this[gr]=!0,this[Re]?this[Re].write(t):this[Rs](t),this[gr]=!1;let i=this[jt].length>0?!1:this[Ht]?this[Ht].flowing:!0;return!i&&this[jt].length===0&&this[Ht]?.once("drain",()=>this.emit("drain")),n?.(),i}[ec](t){t&&!this[hn]&&(this[ge]=this[ge]?Buffer.concat([this[ge],t]):t)}[Ps](){if(this[fn]&&!this[Xa]&&!this[hn]&&!this[hi]){this[Xa]=!0;let t=this[Bn];if(t&&t.blockRemain){let e=this[ge]?this[ge].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ge]&&t.write(this[ge]),t.end()}this[Fn](Ds)}}[Rs](t){if(this[hi]&&t)this[ec](t);else if(!t&&!this[ge])this[Ps]();else if(t){if(this[hi]=!0,this[ge]){this[ec](t);let e=this[ge];this[ge]=void 0,this[Cs](e)}else this[Cs](t);for(;this[ge]&&this[ge]?.length>=512&&!this[hn]&&!this[Ls];){let e=this[ge];this[ge]=void 0,this[Cs](e)}this[hi]=!1}(!this[ge]||this[fn])&&this[Ps]()}[Cs](t){let e=0,n=t.length;for(;e+512<=n&&!this[hn]&&!this[Ls];)switch(this[lt]){case"begin":case"header":this[Iu](t,e),e+=512;break;case"ignore":case"body":e+=this[Qa](t,e);break;case"meta":e+=this[Su](t,e);break;default:throw new Error("invalid state: "+this[lt])}e<n&&(this[ge]=this[ge]?Buffer.concat([t.subarray(e),this[ge]]):t.subarray(e))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),n&&this.once("finish",n),this[hn]||(this[Re]?(t&&this[Re].write(t),this[Re].end()):(this[fn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ps]())),this}},Ei=t=>{let e=t.length-1,n=-1;for(;e>-1&&t.charAt(e)==="/";)n=e,e--;return n===-1?t:t.slice(0,n)},Gw=t=>{let e=t.onReadEntry;t.onReadEntry=e?n=>{e(n),n.resume()}:n=>n.resume()},cf=(t,e)=>{let n=new Map(e.map(c=>[Ei(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Jm(c).root||".",h;if(c===u)h=!1;else{let x=n.get(c);h=x!==void 0?x:o(Zm(c),u)}return n.set(c,h),h};t.filter=i?(c,l)=>i(c,l)&&o(Ei(c)):c=>o(Ei(c))},qw=t=>{let e=new Ri(t),n=t.file,i;try{i=Er.openSync(n,"r");let o=Er.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=Er.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let h=Er.readSync(i,u,0,c,l);if(h===0)break;l+=h,e.write(u.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{Er.closeSync(i)}catch{}}},Hw=(t,e)=>{let n=new Ri(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{n.on("error",l),n.on("end",c),Er.stat(o,(u,h)=>{if(u)l(u);else{let x=new Pc(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(n)}})})},Ar=Ci(qw,Hw,t=>new Ri(t),t=>new Ri(t),(t,e)=>{e?.length&&cf(t,e),t.noResume||Gw(t)}),lf=(t,e,n)=>(t&=4095,n&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Ww,parse:ku}=jw,Nc=t=>{let e="",n=ku(t);for(;Ww(t)||n.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":n.root;t=t.slice(i.length),e+=i,n=ku(t)}return[e,t]},no=["|","<",">","?",":"],Mc=no.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Kw=new Map(no.map((t,e)=>[t,Mc[e]])),$w=new Map(Mc.map((t,e)=>[t,no[e]])),Ru=t=>no.reduce((e,n)=>e.split(n).join(Kw.get(n)),t),Vw=t=>Mc.reduce((e,n)=>e.split(n).join($w.get(n)),t),df=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),Ei(e)+"/"+t):X(t),Zw=16*1024*1024,Cu=Symbol("process"),Pu=Symbol("file"),Du=Symbol("directory"),xc=Symbol("symlink"),Ou=Symbol("hardlink"),xi=Symbol("header"),Us=Symbol("read"),pc=Symbol("lstat"),Gs=Symbol("onlstat"),gc=Symbol("onread"),mc=Symbol("onreadlink"),wc=Symbol("openfile"),_c=Symbol("onopenfile"),wn=Symbol("close"),Js=Symbol("mode"),yc=Symbol("awaitDrain"),tc=Symbol("ondrain"),Rt=Symbol("prefix"),uf=class extends Wn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let n=Dc(e);super(),this.path=X(t),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||Zw,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=X(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?X(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Nc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=Vw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(n.absolute||Tu.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[Gs](o):this[pc]()}warn(t,e,n={}){return to(this,t,e,n)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[pc](){kt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Gs](e)})}[Gs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Xw(t),this.emit("stat",t),this[Cu]()}[Cu](){switch(this.type){case"File":return this[Pu]();case"Directory":return this[Du]();case"SymbolicLink":return this[xc]();default:return this.end()}}[Js](t){return lf(t,this.type==="Directory",this.portable)}[Rt](t){return df(t,this.prefix)}[xi](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new jn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Js](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 Vs({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)}[Du](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[xi](),this.end()}[xc](){kt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){this.linkpath=X(t),this[xi](),this.end()}[Ou](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(Tu.relative(this.cwd,t)),this.stat.size=0,this[xi](),this.end()}[Pu](){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[Ou](e);this.linkCache.set(t,this.absolute)}if(this[xi](),this.stat.size===0)return this.end();this[wc]()}[wc](){kt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){if(this.fd=t,this.#e)return this[wn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Us]()}[Us](){let{fd:t,buf:e,offset:n,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");kt.read(t,e,n,i,o,(c,l)=>{if(c)return this[wn](()=>this.emit("error",c));this[gc](l)})}[wn](t=()=>{}){this.fd!==void 0&&kt.close(this.fd,t)}[gc](t){if(t<=0&&this.remain>0){let n=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[wn](()=>this.emit("error",n))}if(t>this.remain){let n=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[wn](()=>this.emit("error",n))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let n=t;n<this.length&&t<this.blockRemain;n++)this.buf[n+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[tc]():this[yc](()=>this[tc]())}[yc](t){this.once("drain",t)}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,n)}[tc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[wn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Us]()}},Jw=class extends uf{sync=!0;[pc](){this[Gs](kt.lstatSync(this.absolute))}[xc](){this[mc](kt.readlinkSync(this.absolute))}[wc](){this[_c](kt.openSync(this.absolute,"r"))}[Us](){let t=!0;try{let{fd:e,buf:n,offset:i,length:o,pos:c}=this;if(e===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let l=kt.readSync(e,n,i,o,c);this[gc](l),t=!1}finally{if(t)try{this[wn](()=>{})}catch{}}}[yc](t){t()}[wn](t=()=>{}){this.fd!==void 0&&kt.closeSync(this.fd),t()}},Yw=class extends Wn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,n={}){return to(this,t,e,n)}constructor(t,e={}){let n=Dc(e);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=X(t.path),this.mode=t.mode!==void 0?this[Js](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:n.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Nc(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new jn({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 Vs({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 df(t,this.prefix)}[Js](t){return lf(t,this.type==="Directory",this.portable)}write(t,e,n){typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,n)}end(t,e,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),n&&this.once("finish",n),t?super.end(t,n):super.end(n),this}},Xw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Qw=class vr{tail;head;length=0;static create(e=[]){return new vr(e)}constructor(e=[]){for(let n of e)this.push(n)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let n=e.next,i=e.prev;return n&&(n.prev=i),i&&(i.next=n),e===this.head&&(this.head=n),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,n}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let n=this.head;e.list=this,e.next=n,n&&(n.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let n=this.tail;e.list=this,e.prev=n,n&&(n.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let n=0,i=e.length;n<i;n++)t_(this,e[n]);return this.length}unshift(...e){for(var n=0,i=e.length;n<i;n++)n_(this,e[n]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,n=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,n.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,n=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,n.list=void 0,this.length--,e}forEach(e,n){n=n||this;for(let i=this.head,o=0;i;o++)e.call(n,i.value,o,this),i=i.next}forEachReverse(e,n){n=n||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(n,i.value,o,this),i=i.prev}get(e){let n=0,i=this.head;for(;i&&n<e;n++)i=i.next;if(n===e&&i)return i.value}getReverse(e){let n=0,i=this.tail;for(;i&&n<e;n++)i=i.prev;if(n===e&&i)return i.value}map(e,n){n=n||this;let i=new vr;for(let o=this.head;o;)i.push(e.call(n,o.value,this)),o=o.next;return i}mapReverse(e,n){n=n||this;var i=new vr;for(let o=this.tail;o;)i.push(e.call(n,o.value,this)),o=o.prev;return i}reduce(e,n){let i,o=this.head;if(arguments.length>1)i=n;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,n){let i,o=this.tail;if(arguments.length>1)i=n;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let n=0,i=this.head;i;n++)e[n]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let n=0,i=this.tail;i;n++)e[n]=i.value,i=i.prev;return e}slice(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new vr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<n;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new vr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.length,c=this.tail;for(;c&&o>n;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,n=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<n;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=e_(this,o,l);return c}reverse(){let e=this.head,n=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=n,this.tail=e,this}};function e_(t,e,n){let i=e,o=e?e.next:t.head,c=new Bc(n,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function t_(t,e){t.tail=new Bc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function n_(t,e){t.head=new Bc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Bc=class{list;next;prev;value;constructor(t,e,n,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Nu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Mu=Buffer.alloc(1024),qs=Symbol("onStat"),pi=Symbol("ended"),mt=Symbol("queue"),gi=Symbol("pendingLinks"),xn=Symbol("current"),Un=Symbol("process"),mi=Symbol("processing"),Ns=Symbol("processJob"),wt=Symbol("jobs"),nc=Symbol("jobDone"),Hs=Symbol("addFSEntry"),Bu=Symbol("addTarEntry"),bc=Symbol("stat"),Ec=Symbol("readdir"),js=Symbol("onreaddir"),Ws=Symbol("pipe"),Fu=Symbol("entry"),rc=Symbol("entryOpt"),Ks=Symbol("writeEntryClass"),ff=Symbol("write"),ic=Symbol("ondrain"),ro=class extends Wn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ks];onWriteEntry;[mt];[gi]=new Map;[wt]=0;[mi]=!1;[pi]=!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[Ks]=uf,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 lw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new uw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new hw(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",n=>super.write(n)),e.on("end",()=>super.end()),e.on("drain",()=>this[ic]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ic]);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[mt]=new Qw,this[wt]=0,this.jobs=Number(t.jobs)||4,this[mi]=!1,this[pi]=!1}[ff](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&this.add(t),this[pi]=!0,this[Un](),n&&n(),this}write(t){if(this[pi])throw new Error("write after end");return typeof t=="string"?this[Hs](t):this[Bu](t),this.flowing}[Bu](t){let e=X(Lu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let n=new Nu(t.path,e);n.entry=new Yw(t,this[rc](n)),n.entry.on("end",()=>this[nc](n)),this[wt]+=1,this[mt].push(n)}this[Un]()}[Hs](t){let e=X(Lu.resolve(this.cwd,t));this[mt].push(new Nu(t,e)),this[Un]()}[bc](t){t.pending=!0,this[wt]+=1;let e=this.follow?"stat":"lstat";Zs[e](t.absolute,(n,i)=>{t.pending=!1,this[wt]-=1,n?this.emit("error",n):this[qs](t,i)})}[qs](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[Ns](t);else{let n=`${e.dev}:${e.ino}`,i=this[gi].get(n);i?i.push(t):this[gi].set(n,[t]),t.pendingLink=!0,t.pending=!0}this[Un]()}[Ec](t){t.pending=!0,this[wt]+=1,Zs.readdir(t.absolute,(e,n)=>{if(t.pending=!1,this[wt]-=1,e)return this.emit("error",e);this[js](t,n)})}[js](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Un]()}[Un](){if(!this[mi]){this[mi]=!0;for(let t=this[mt].head;t&&this[wt]<this.jobs;t=t.next)if(this[Ns](t.value),t.value.ignore){let e=t.next;this[mt].removeNode(t),t.next=e}this[mi]=!1,this[pi]&&this[mt].length===0&&this[wt]===0&&(this.zip?this.zip.end(Mu):(super.write(Mu),super.end()))}}get[xn](){return this[mt]&&this[mt].head&&this[mt].head.value}[nc](t){this[mt].shift(),this[wt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let n=`${e.dev}:${e.ino}`,i=this[gi].get(n);if(i){this[gi].delete(n);for(let o of i)o.pending=!1,this[Ns](o)}}this[Un]()}[Ns](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[Ws](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[qs](t,e):this[bc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[js](t,e):this[Ec](t),!t.readdir)return}if(t.entry=this[Fu](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[Ws](t)}}}[rc](t){return{onwarn:(e,n,i)=>this.warn(e,n,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Fu](t){this[wt]+=1;try{return new this[Ks](t.path,this[rc](t)).on("end",()=>this[nc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ic](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[Ws](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Hs](c+i)});let e=t.entry,n=this.zip;if(!e)throw new Error("cannot pipe without source");n?e.on("data",i=>{n.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,n={}){to(this,t,e,n)}},Fc=class extends ro{sync=!0;constructor(t){super(t),this[Ks]=Jw}pause(){}resume(){}[bc](t){let e=this.follow?"statSync":"lstatSync";this[qs](t,Zs[e](t.absolute))}[Ec](t){this[js](t,Zs.readdirSync(t.absolute))}[Ws](t){let e=t.entry,n=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Hs](c+i)}),!e)throw new Error("Cannot pipe without source");n?e.on("data",i=>{n.write(i)}):e.on("data",i=>{super[ff](i)})}},r_=(t,e)=>{let n=new Fc(t),i=new Xu(t.file,{mode:t.mode||438});n.pipe(i),hf(n,e)},i_=(t,e)=>{let n=new ro(t),i=new Qs(t.file,{mode:t.mode||438});n.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),n.on("error",l)});return xf(n,e).catch(c=>n.emit("error",c)),o},hf=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Ar({file:Qu.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},xf=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Ar({file:Qu.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(n);t.end()},s_=(t,e)=>{let n=new Fc(t);return hf(n,e),n},o_=(t,e)=>{let n=new ro(t);return xf(n,e).catch(i=>n.emit("error",i)),n},L1=Ci(r_,i_,s_,o_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),c_=process.env.__FAKE_PLATFORM__||process.platform,wf=c_==="win32",{O_CREAT:_f,O_NOFOLLOW:zu,O_TRUNC:yf,O_WRONLY:bf}=mf.constants,Ef=Number(process.env.__FAKE_FS_O_FILENAME__)||mf.constants.UV_FS_O_FILEMAP||0,l_=wf&&!!Ef,d_=512*1024,u_=Ef|yf|_f|bf,Uu=!wf&&typeof zu=="number"?zu|yf|_f|bf:null,vf=Uu!==null?()=>Uu:l_?t=>t<d_?u_:"w":()=>"w",vc=(t,e,n)=>{try{return io.lchownSync(t,e,n)}catch(i){if(i?.code!=="ENOENT")throw i}},Ys=(t,e,n,i)=>{io.lchown(t,e,n,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},f_=(t,e,n,i,o)=>{if(e.isDirectory())Sf(vi.resolve(t,e.name),n,i,c=>{if(c)return o(c);let l=vi.resolve(t,e.name);Ys(l,n,i,o)});else{let c=vi.resolve(t,e.name);Ys(c,n,i,o)}},Sf=(t,e,n,i)=>{io.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 Ys(t,e,n,i);let l=c.length,u=null,h=x=>{if(!u){if(x)return i(u=x);if(--l===0)return Ys(t,e,n,i)}};for(let x of c)f_(t,x,e,n,h)})},h_=(t,e,n,i)=>{e.isDirectory()&&If(vi.resolve(t,e.name),n,i),vc(vi.resolve(t,e.name),n,i)},If=(t,e,n)=>{let i;try{i=io.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return vc(t,e,n);throw c}for(let o of i)h_(t,o,e,n);return vc(t,e,n)},Af=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"}},so=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"}},p_=(t,e)=>{st.stat(t,(n,i)=>{(n||!i.isDirectory())&&(n=new Af(t,n?.code||"ENOTDIR")),e(n)})},g_=(t,e,n)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,h=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),x=e.preserve,m=e.unlink,w=X(e.cwd),S=(v,I)=>{v?n(v):I&&h?Sf(I,l,u,A=>S(A)):c?st.chmod(t,o,n):n()};if(t===w)return p_(t,S);if(x)return x_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let _=X(Xs.relative(w,t)).split("/");Sc(w,_,o,m,w,void 0,S)},Sc=(t,e,n,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),h=X(Xs.resolve(t+"/"+u));st.mkdir(h,n,Tf(h,e,n,i,o,c,l))},Tf=(t,e,n,i,o,c,l)=>u=>{u?st.lstat(t,(h,x)=>{if(h)h.path=h.path&&X(h.path),l(h);else if(x.isDirectory())Sc(t,e,n,i,o,c,l);else if(i)st.unlink(t,m=>{if(m)return l(m);st.mkdir(t,n,Tf(t,e,n,i,o,c,l))});else{if(x.isSymbolicLink())return l(new so(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,Sc(t,e,n,i,o,c,l))},m_=t=>{let e=!1,n;try{e=st.statSync(t).isDirectory()}catch(i){n=i?.code}finally{if(!e)throw new Af(t,n??"ENOTDIR")}},w_=(t,e)=>{t=X(t);let n=e.umask??18,i=e.mode|448,o=(i&n)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),h=e.preserve,x=e.unlink,m=X(e.cwd),w=v=>{v&&u&&If(v,c,l),o&&st.chmodSync(t,i)};if(t===m)return m_(m),w();if(h)return w(st.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X(Xs.relative(m,t)).split("/"),_;for(let v=S.shift(),I=m;v&&(I+="/"+v);v=S.shift()){I=X(Xs.resolve(I));try{st.mkdirSync(I,i),_=_||I}catch{let A=st.lstatSync(I);if(A.isDirectory())continue;if(x){st.unlinkSync(I),st.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new so(I,I+"/"+S.join("/"))}}return w(_)},sc=Object.create(null),Gu=1e4,mr=new Set,__=t=>{mr.has(t)?mr.delete(t):sc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),mr.add(t);let e=sc[t],n=mr.size-Gu;if(n>Gu/10){for(let i of mr)if(mr.delete(i),delete sc[i],--n<=0)break}return e},y_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,b_=y_==="win32",E_=t=>t.split("/").slice(0,-1).reduce((e,n)=>{let i=e.at(-1);return i!==void 0&&(n=kf(i,n)),e.push(n||"/"),e},[]),v_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=b_?["win32 parallelization disabled"]:t.map(i=>Ei(kf(__(i))));let n=new Set(t.map(i=>E_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:n,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of n){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(n=>this.#e.get(n)),dirs:[...e.dirs].map(n=>this.#e.get(n))}}check(t){let{paths:e,dirs:n}=this.#s(t);return e.every(i=>i&&i[0]===t)&&n.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:n,dirs:i}=e,o=new Set;for(let c of n){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let h=l[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},S_=()=>process.umask(),qu=Symbol("onEntry"),Ic=Symbol("checkFs"),Hu=Symbol("checkFs2"),Ac=Symbol("isReusable"),dt=Symbol("makeFs"),Tc=Symbol("file"),kc=Symbol("directory"),$s=Symbol("link"),ju=Symbol("symlink"),Wu=Symbol("hardlink"),yi=Symbol("ensureNoSymlink"),Ku=Symbol("unsupported"),$u=Symbol("checkPath"),oc=Symbol("stripAbsolutePath"),_n=Symbol("mkdir"),Ge=Symbol("onError"),Ms=Symbol("pending"),Vu=Symbol("pend"),wr=Symbol("unpend"),ac=Symbol("ended"),cc=Symbol("maybeClose"),Rc=Symbol("skip"),Si=Symbol("doChown"),Ii=Symbol("uid"),Ai=Symbol("gid"),Ti=Symbol("checkedCwd"),I_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,ki=I_==="win32",A_=1024,T_=(t,e)=>{if(!ki)return re.unlink(t,e);let n=t+".DELETE."+gf(16).toString("hex");re.rename(t,n,i=>{if(i)return e(i);re.unlink(n,e)})},k_=t=>{if(!ki)return re.unlinkSync(t);let e=t+".DELETE."+gf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Zu=(t,e,n)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:n,zc=class extends Ri{[ac]=!1;[Ti]=!1;[Ms]=0;reservations=new v_;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[ac]=!0,this[cc]()},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:A_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||ki,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:S_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[qu](e))}warn(t,e,n={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(n.recoverable=!1),super.warn(t,e,n)}[cc](){this[ac]&&this[Ms]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[oc](t,e){let n=t[e],{type:i}=t;if(!n||this.preservePaths)return!0;let[o,c]=Nc(n),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||ki&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:n}),!1;let u=Ne.posix.dirname(t.path),h=Ne.posix.normalize(Ne.posix.join(u,l.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:n}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:n})),!0}[$u](t){let e=X(t.path),n=e.split("/");if(this.strip){if(n.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}n.splice(0,this.strip),t.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this[oc](t,"path")||!this[oc](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+Ru(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+Ru(t.path.slice(o.length))}return!0}[qu](t){if(!this[$u](t))return t.resume();switch(a_.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[Ic](t);default:return this[Ku](t)}}[Ge](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[wr](),e.resume())}[_n](t,e,n){g_(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},n)}[Si](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}[Ii](t){return Zu(this.uid,t.uid,this.processUid)}[Ai](t){return Zu(this.gid,t.gid,this.processGid)}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Qs(String(t.absolute),{flags:vf(t.size),mode:n,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ge](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ge](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[Ge](h,t):this[wr](),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,S=>c(S&&w)):c())}if(typeof h=="number"&&this[Si](t)){o++;let x=this[Ii](t),m=this[Ai](t);typeof x=="number"&&typeof m=="number"&&re.fchown(h,x,m,w=>w?re.chown(u,x,m,S=>c(S&&w)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[Ge](u,t),e()}),t.pipe(l)),l.pipe(i)}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode;this[_n](String(t.absolute),n,i=>{if(i){this[Ge](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[wr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Si](t)&&(o++,re.chown(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)),c)),c()})}[Ku](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[ju](t,e){let n=X(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[yi](t,this.cwd,n,()=>this[$s](t,String(t.linkpath),"symlink",e),i=>{this[Ge](i,t),e()})}[Wu](t,e){let n=X(Ne.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[yi](t,this.cwd,i,()=>this[$s](t,n,"link",e),o=>{this[Ge](o,t),e()})}[yi](t,e,n,i,o){let c=n.shift();if(this.preservePaths||c===void 0)return i();let l=Ne.resolve(e,c);re.lstat(l,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new so(l,Ne.resolve(l,n.join("/"))));this[yi](t,l,n,i,o)})}[Vu](){this[Ms]++}[wr](){this[Ms]--,this[cc]()}[Rc](t){this[wr](),t.resume()}[Ac](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!ki}[Ic](t){this[Vu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,n=>this[Hu](t,n))}[Hu](t,e){let n=l=>{e(l)},i=()=>{this[_n](this.cwd,this.dmode,l=>{if(l){this[Ge](l,t),n();return}this[Ti]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=X(Ne.dirname(String(t.absolute)));if(l!==this.cwd)return this[_n](l,this.dmode,u=>{if(u){this[Ge](u,t),n();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Rc](t),n();return}if(l||this[Ac](t,u))return this[dt](null,t,n);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=m=>this[dt](m??null,t,n);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[dt](h??null,t,n))}if(t.absolute===this.cwd)return this[dt](null,t,n);T_(String(t.absolute),h=>this[dt](h??null,t,n))})};this[Ti]?o():i()}[dt](t,e,n){if(t){this[Ge](t,e),n();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Tc](e,n);case"Link":return this[Wu](e,n);case"SymbolicLink":return this[ju](e,n);case"Directory":case"GNUDumpDir":return this[kc](e,n)}}[$s](t,e,n,i){re[n](e,String(t.absolute),o=>{o?this[Ge](o,t):(this[wr](),t.resume()),i()})}},wi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Rf=class extends zc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[Ic](t){if(!this[Ti]){let o=this[_n](this.cwd,this.dmode);if(o)return this[Ge](o,t);this[Ti]=!0}if(t.absolute!==this.cwd){let o=X(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[_n](o,this.dmode);if(c)return this[Ge](c,t)}}let[e,n]=wi(()=>re.lstatSync(String(t.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[Rc](t);if(e||this[Ac](t,n))return this[dt](null,t);if(n.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(n.mode&4095)!==t.mode,[l]=c?wi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](l,t)}let[o]=wi(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:wi(()=>k_(String(t.absolute)));this[dt](i,t)}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{re.closeSync(o)}catch(h){u=h}(l||u)&&this[Ge](l||u,t),e()},o;try{o=re.openSync(String(t.absolute),vf(t.size),n)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[Ge](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,h=t.mtime;try{re.futimesSync(o,u,h)}catch(x){try{re.utimesSync(String(t.absolute),u,h)}catch{l=x}}}if(this[Si](t)){let u=this[Ii](t),h=this[Ai](t);try{re.fchownSync(o,Number(u),Number(h))}catch(x){try{re.chownSync(String(t.absolute),Number(u),Number(h))}catch{l=l||x}}}i(l)})}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[_n](String(t.absolute),n);if(i){this[Ge](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Si](t))try{re.chownSync(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)))}catch{}e(),t.resume()}[_n](t,e){try{return 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})}catch(n){return n}}[yi](t,e,n,i,o){if(this.preservePaths||n.length===0)return i();let c=e;for(let l of n){c=Ne.resolve(c,l);let[u,h]=wi(()=>re.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new so(c,Ne.resolve(e,n.join("/"))))}i()}[$s](t,e,n,i){let o=`${n}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ge](c,t)}}},R_=t=>{let e=new Rf(t),n=t.file,i=pf.statSync(n),o=t.maxReadSize||16*1024*1024;new Vm(n,{readSize:o,size:i.size}).pipe(e)},C_=(t,e)=>{let n=new zc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{n.on("error",l),n.on("close",c),pf.stat(o,(u,h)=>{if(u)l(u);else{let x=new Pc(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(n)}})})},Cf=Ci(R_,C_,t=>new Rf(t),t=>new zc(t),(t,e)=>{e?.length&&cf(t,e)}),P_=(t,e)=>{let n=new Fc(t),i=!0,o,c;try{try{o=it.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=it.openSync(t.file,"w+");else throw h}let l=it.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let m=0,w=0;m<512;m+=w){if(w=it.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let h=new jn(u);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>l.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,D_(t,n,c,o,e)}finally{if(i)try{it.closeSync(o)}catch{}}},D_=(t,e,n,i,o)=>{let c=new Xu(t.file,{fd:i,start:n});e.pipe(c),L_(e,o)},O_=(t,e)=>{e=Array.from(e);let n=new ro(t),i=(o,c,l)=>{let u=(S,_)=>{S?it.close(o,v=>l(S)):l(null,_)},h=0;if(c===0)return u(null,0);let x=0,m=Buffer.alloc(512),w=(S,_)=>{if(S||_===void 0)return u(S);if(x+=_,x<512&&_)return it.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 jn(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,it.read(o,m,0,512,h,w)};it.read(o,m,0,512,h,w)};return new Promise((o,c)=>{n.on("error",c);let l="r+",u=(h,x)=>{if(h&&h.code==="ENOENT"&&l==="r+")return l="w+",it.open(t.file,l,u);if(h||!x)return c(h);it.fstat(x,(m,w)=>{if(m)return it.close(x,()=>c(m));i(x,w.size,(S,_)=>{if(S)return c(S);let v=new Qs(t.file,{fd:x,start:_});n.pipe(v),v.on("error",c),v.on("close",o),N_(n,e)})})};it.open(t.file,l,u)})},L_=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Ar({file:Pf.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},N_=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Ar({file:Pf.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n);t.end()},_i=Ci(P_,O_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!nw(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")}),Z1=Ci(_i.syncFile,_i.asyncFile,_i.syncNoFile,_i.asyncNoFile,(t,e=[])=>{_i.validate?.(t,e),M_(t)}),M_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(n,i)=>e(n,i)&&!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0)):(n,i)=>!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0))};cn();var ut={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete",PUBLISH_SKILL:"_agent/publishSkill"};function oo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Df(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function ao(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Of(t){let e=t?.permissionMode;if(typeof e!="string")return;let n=e.trim();return n===""?void 0:n}function Lf(t){let{_meta:e,...n}=t;return{stripped:n,meta:e}}function Kn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}$t();We();te();Oe();We();function Tr(t,e){if(oo(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Pi(t){return t.startsWith("http://")||t.startsWith("https://")}function kr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as U2}from"node:fs";import{dirname as q2,join as H2}from"node:path";import{fileURLToPath as W2}from"node:url";var Pt="0.2.3-alpha.101";We();te();var co="1008033",Ff="1289";var zf="pbbp2",Uf="https://www.coze.cn",Gf="/api/coze_claw/resource/get_frontier_key",j_="https://www.coze.cn",W_="wss://frontier.coze.cn";function Rr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??j_}function qf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??W_}function En(t){let e={},n=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return n&&(e["x-tt-env"]=n),i&&(e["x-use-ppe"]=i),e}function Oi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Di=q("handshake");async function Uc(t){let e=Rr(t.endpoint),n=t.timeoutMs??1e4,i=`${kr(e)}${Gf}?aid=${encodeURIComponent(co)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...En(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),n);Di.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let 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 T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Di.info("handshake ok",{remoteDeviceId:_,logid:h,traceId:x}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof T)throw Di.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Di.warn("handshake timeout",{base:e,timeoutMs:n}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${n}ms)`,{cause:u});let h=u.cause;throw Di.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var qc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Dt="auto",Gc=15e4,Hf=8192;function Wf(t){return{model:Hc(t.model)??Dt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Kf(t){return!t||t===Dt}var K_=new Set(["auto","\u81EA\u52A8"]);function Hc(t){let e=t?.trim();if(e)return K_.has(e.toLowerCase())?Dt:e}function $f(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=qc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let n=t.model||Dt;e.ANTHROPIC_MODEL=n,e.ANTHROPIC_SMALL_FAST_MODEL=n,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=n,e.ANTHROPIC_DEFAULT_OPUS_MODEL=n,e.ANTHROPIC_DEFAULT_SONNET_MODEL=n,e.CLAUDE_CODE_SUBAGENT_MODEL=n,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow)),t.modelInfo?.maxOutput&&(e.CLAUDE_CODE_MAX_OUTPUT_TOKENS=String(t.modelInfo.maxOutput))}else Kf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Vf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Dt}"`):Kf(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="${qc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let n=t.modelInfo?.contextWindow??Gc;e.push("-c",`model_context_window=${n}`)}return e}function Zf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function jc(t,e){let{ttEnv:n,usePpe:i}=Oi(t),o={};return n&&(o["x-tt-env"]=n),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Jf(t,e,n){if(!t.modelToken)return{};let i=jc(e,n);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
|
|
92
|
-
`)}}function Wc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Kc(t){return t.model||Dt}function jf(t,e,n,i){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:n,maxTokens:i,api:"openai-completions"}}function Yf(t,e,n,i){if(!t.modelToken)return null;let o=Kc(t),c=jc(e,n),l=["text"];t.modelInfo?.capabilities?.image===!0&&l.push("image");let u=[jf(o,l,t.modelInfo?.contextWindow??Gc,t.modelInfo?.maxOutput??Hf)],h=new Set([o]);for(let m of i??[])!m||h.has(m)||(h.add(m),u.push(jf(m,["text"],Gc,Hf)));let x={baseUrl:`${qc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:u};return Object.keys(c).length>0&&(x.headers=c),x}function Xf(t,e,n){if(!t.modelToken)return[];let i=jc(e,n),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var he=q("agent-handlers"),Qf=5*1024*1024,Y_=1,X_=6,Q_=new Set(["node_modules",".git",".coze","dist","build",".next"]),ey=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,ty=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,ny=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function ry(t){let e=t?.trim();return e?ny.test(e)||ty.test(e)?e:(he.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function iy(t){return new Promise((e,n)=>{let i=nt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=l=>{o||(o=!0,l?n(l):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",l=>c(l))})}var uo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let n=Kn(e._meta),i=await this.loadAgentCfg(n),o=i?.workspace??Ve(n).workspace,c=i?.skills??[],l=[],u=new Set;for(let h of c){let x=me(o,h.relPath,"SKILL.md");await n0(x).then(w=>w.isFile()).catch(()=>!1)&&(l.push(dy(h)),u.add(h.relPath))}if(e.scanLocal){let h=i?.framework??"claude-code",x=await oy(n,o,h),m=await ay(n,h);for(let w of[...x,...m])u.has(w.relPath)||(u.add(w.relPath),l.push(w.skill))}return{skills:l}}async addSkills(e){e._meta;let n=Kn(e._meta),i=await this.requireAgentCfg(n),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((h,x)=>[h.skillId,x])),u=[];for(let h of o){let x=await fo({agentId:n,workspace:i.workspace,framework:i.framework,skill:h});ho(c,l,x),u.push(h)}return await ii(n,c),this.reloadAgentSessions(n,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let n=Kn(e._meta),i=await this.requireAgentCfg(n),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let h=me(i.workspace,u.relPath);await Zc(h,{recursive:!0,force:!0}),he.info("skill removed",{agentId:n,skillId:u.skillId,relPath:u.relPath})}return await ii(n,l),this.reloadAgentSessions(n,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let n=Kn(e._meta);if(!e.skillName)throw new T("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");he.info("_agent/publishSkill start",{agentId:n,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(n),o=i?.workspace??Ve(n).workspace,c=i?.framework??"claude-code",l=e.isGlobal??!1,u=o0(e.skillName),h=await sy(o,c,u,l);if(!h){let D=l?"global":"workspace";throw new T("SKILL_NOT_FOUND",`skill not found in ${D}: ${e.skillName} (${u})`)}let{absDir:x,relPath:m}=h,w=me(x,"SKILL.md"),S=new el.default;S.addLocalFolder(x,u);let _=S.toBuffer();if(_.length>e0)throw new T("SKILL_ZIP_TOO_LARGE",`skill zip ${_.length} bytes exceeds limit ${e0}`);let v=await lo(w,{encoding:"utf8"}).then(D=>l0(D).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:_,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:n,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):he.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:n,skillName:e.skillName});let A=I.version??"v1.0",R=I.skillId??e.skillId??c0(n,m);if(i&&!l){let D=i.skills??[],y=D.find(C=>C.relPath===m);y?(y.version=A,y.skillId=R):D.push({skillId:R,skillName:e.skillName,relPath:m,version:A,installedAt:Date.now(),...v?{description:v}:{}}),await ii(n,D)}return he.info("skill published",{agentId:n,skillName:e.skillName,relPath:m,zipBytes:_.length,skillId:R,version:A}),{ok:!0,skillId:R,version:A}}reloadAgentSessionsPublic(e,n){this.reloadAgentSessions(e,n)}reloadAgentSessions(e,n){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,he.info("downstream busy, scheduling reload after turn",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let h=c.downstream;c.downstream=void 0,he.info("killing downstream for workspace reload (idle)",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:l}),h.stop(n).catch(x=>he.warn("downstream stop failed during reload (ignored)",{reason:n,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let n=this.opts.isRuntimePendingPermission;return!n||!e.downstream?!1:n(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return he.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let n=e.agentId,i=await ke(n);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${n}`);if(i.cozeIdentity===e.cozeIdentity)return he.info("_agent/update: cozeIdentity unchanged, noop",{agentId:n}),{ok:!0};try{await dr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw he.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:n,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${n}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Be(i),he.info("_agent/update: cozeIdentity rewritten",{agentId:n,framework:i.framework}),this.reloadAgentSessions(n,"identity-changed"),{ok:!0}}async upgradeBridge(e){let n=e.agentId||e._meta?.cozeAgentId;if(!n)throw new T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await ke(n))throw new T("AGENT_NOT_FOUND",`agent not found: ${n}`);let o=["-y"];e.registry&&Pi(e.registry)&&o.push(`--registry=${e.registry}`);let c=ry(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&ey.test(l)&&o.push("--env",l);let u=await iy(o);return he.info("_agent/upgrade: spawned bridge upgrade process",{agentId:n,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let n=e.agentId;if(!n)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await ke(n);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Be(i),he.info("agent disconnected",{agentId:n,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(n,e.reason??"disconnect"),{ok:!0}):(he.warn("_agent/disconnect: agent not found, ignoring",{agentId:n}),{ok:!0})}async deleteAgent(e){let n=e.agentId;if(!n)throw new T("IPC_BAD_REQUEST",`${ut.DELETE}: missing agentId`);let i=await ke(n),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(n,e.reason??"delete");let l=Ve(n);return c==="cloud"?await Zc(l.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Be(i)),he.info("agent deleted",{agentId:n,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Tr(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let n=Hc(e.model)??Dt,i=await ke(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=n,e.modelInfo&&(i.modelInfo=e.modelInfo),await Be(i),he.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:n,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return he.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=n,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>he.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let l=[];for(let[u,h]of o.allSessionQueues())l.push(h.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${n}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(l),he.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:n,cloudSessions:l.length}),{ok:!0}}async resetAgent(e){if(Tr(e._meta,ut.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ut.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ut.RESET),await this.runDetailSync(e.agentId,ut.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,n){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),he.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(n);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await ri(e,o)}async clearPersistedAcpSessionIds(e){let n=await ke(e).catch(()=>null);if(!n?.sessions)return;let i=!1;for(let o of Object.values(n.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Be(n)}async repairAgent(e){if(Tr(e._meta,ut.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ut.REPAIR}: missing agentId`);let n=await this.loadAgentCfg(e.agentId);if(n&&n.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${ut.REPAIR} only allowed for openclaw, got ${n.framework}`);if(n&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,n.workspace)}catch(i){he.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ut.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,n,i){if(!this.opts.detailSyncer){he.warn("detailSyncer not wired, skipping sync",{method:n,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){he.warn("detail sync failed (ignored)",{method:n,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Tr(e._meta,"_agent/getFileTree");let n=e._meta,i=Kn(n),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await $c(l).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ni(l,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=Ey(e.depth);return u.isDirectory()?{tree:await by(o,l,c,h)}:{tree:[{name:vy(c),path:h0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Tr(e._meta,"_agent/getFileContent");let n=Kn(e._meta),i=await this.resolveWorkspace(n);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await $c(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ni(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Qf)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Qf})`);let l=await lo(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let n=this.opts.agents.get(e);return n?n.workspace:(await ke(e).catch(()=>null))?.workspace??Ve(e).workspace}safeJoin(e,n){let i=Yc(e,n||"."),o=Qc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${r0}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return i}loadAgentCfg(e){return ke(e)}async requireAgentCfg(e){let n=await this.loadAgentCfg(e);if(!n)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return n}};function o0(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function tl(t){return t==="claude-code"?me(".claude","skills"):me(".agents","skills")}function a0(t){let e=V_();return t==="claude-code"?[me(e,".claude","skills")]:t==="codex"?[me(e,".agents","skills"),me(e,".codex","skills")]:[me(e,".agents","skills"),me(e,".openclaw","skills")]}async function sy(t,e,n,i){let o=async c=>n0(me(c,"SKILL.md")).then(l=>l.isFile()).catch(()=>!1);if(!i){let c=me(tl(e),n),l=me(t,c);return await o(l)?{absDir:l,relPath:c}:null}for(let c of a0(e)){let l=me(c,n);if(await o(l))return{absDir:l,relPath:l}}return null}function c0(t,e){return($_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function l0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
89
|
+
`},configPath(t){return $1(t.homeDir,".coze","bridge","task.xml")},async install(t){let n=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await _p("schtasks",["/Create","/SC","ONLOGON","/TN",ca,"/TR",n,"/RU",t.userName,"/F"]),Xd.info("task scheduler entry created",{task:ca,logFile:t.logFile})},async uninstall(t){await _p("schtasks",["/Delete","/TN",ca,"/F"]).catch(e=>Xd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Xd.info("task scheduler entry removed",{task:ca})}}});var bp={};va(bp,{buildContext:()=>Q1,getSupervisor:()=>Y1,launchdSupervisor:()=>Yd,systemdSupervisor:()=>Zd,taskSchedulerSupervisor:()=>Qd});import{homedir as V1,userInfo as J1}from"node:os";function Y1(t=process.platform){switch(t){case"darwin":return Yd;case"linux":return Zd;case"win32":return Qd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function X1(){let t={};for(let e of Z1){let n=process.env[e];n&&(t[e]=n)}return t}function Q1(){let t=Q();return{nodeBin:process.execPath,entry:Ud(t),logFile:t.logFile,homeDir:V1(),userName:J1().username,isRoot:process.getuid?.()===0,env:X1()}}var Z1,Ep=Xe(()=>{"use strict";De();Xo();gp();wp();yp();Z1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();sn();var Pl=G("acp-installer-warmup"),Yg=["claude-code","codex"];async function Dl(t={}){let e=t.ensure??ar,i=(await Promise.allSettled(Yg.map(async o=>{let c=await e(o);Pl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Pl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}cn();te();import{readdir as fm}from"node:fs/promises";import{mkdir as Ml,readFile as lm,writeFile as Bl}from"node:fs/promises";import{join as Ra}from"node:path";var um={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function lr(t,e,n){await Ml(t,{recursive:!0});let i=um[e],o=Ra(t,i);return await Bl(o,n??"","utf8"),o}async function Pa(t,e,n){let i=Ra(t,".claude");await Ml(i,{recursive:!0});let o=Ra(i,"settings.local.json"),c={};try{let u=await lm(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!n)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=n)}return c.permissions=d,await Bl(o,JSON.stringify(c,null,2),"utf8"),o}var Je=G("agent-detail-sync"),hm=6e4,xm=5*6e4,gs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let n=this.opts.paths.agentsRoot,i;try{i=await fm(n)}catch(o){Je.info("agents dir not found, skip detail sync",{root:n,err:String(o)});return}Je.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await ke(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Je.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Je.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Je.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),n=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&n.push(i);if(n.length!==0){Je.info("retrying pending detail syncs",{count:n.length});for(let i of n)try{await this.syncOne(i)}catch(o){Je.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,n){let i=n??await ke(e,this.opts.paths);if(!i){Je.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){Je.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),g=x?Math.min(x.currentDelay*2,xm):hm;this.retryQueue.set(e,{dueAt:Date.now()+g,currentDelay:g});return}if(o.agentId&&o.agentId!==e){Je.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Je.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Je.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Je.debug("detail sync: no diff",{agentId:e});return}await Me(i,this.opts.paths),Je.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Je.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await lr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var ed=zt(gu(),1);import{createHash as V_}from"node:crypto";import{lstat as $c,mkdir as Vc,readFile as co,readdir as n0,rm as Jc,stat as r0,writeFile as Yc}from"node:fs/promises";import{homedir as J_}from"node:os";import{dirname as Y_,join as ge,normalize as Z_,relative as Qc,resolve as Zc,sep as i0}from"node:path";import{Readable as s0}from"node:stream";import{pipeline as o0}from"node:stream/promises";import Mm from"events";import Qe from"fs";import{EventEmitter as Rc}from"node:events";import Zu from"node:stream";import{StringDecoder as Bm}from"node:string_decoder";import ef from"node:path";import Er from"node:fs";import{dirname as Ym,parse as Zm}from"path";import{EventEmitter as sw}from"events";import uc from"assert";import{Buffer as jn}from"buffer";import*as bu from"zlib";import ow from"zlib";import{posix as pr}from"node:path";import{basename as Ow}from"node:path";import Vs from"fs";import kt from"fs";import Tu from"path";import{win32 as Ww}from"node:path";import Nu from"path";import gf from"node:fs";import c_ from"node:assert";import{randomBytes as mf}from"node:crypto";import re from"node:fs";import Le from"node:path";import wf from"fs";import ro from"node:fs";import vi from"node:path";import it from"node:fs";import p_ from"node:fs/promises";import Zs from"node:path";import{join as Cf}from"node:path";import rt from"node:fs";import Df from"node:path";var Lm=Object.defineProperty,Nm=(t,e)=>{for(var n in e)Lm(t,n,{get:e[n],enumerable:!0})},mu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Fm=t=>!!t&&typeof t=="object"&&(t instanceof Wn||t instanceof Zu||zm(t)||Um(t)),zm=t=>!!t&&typeof t=="object"&&t instanceof Rc&&typeof t.pipe=="function"&&t.pipe!==Zu.Writable.prototype.pipe,Um=t=>!!t&&typeof t=="object"&&t instanceof Rc&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),ln=Symbol("emittedEnd"),bs=Symbol("emittingEnd"),oi=Symbol("emittedError"),Es=Symbol("closed"),wu=Symbol("read"),vs=Symbol("flush"),_u=Symbol("flushChunk"),gt=Symbol("encoding"),xr=Symbol("decoder"),Be=Symbol("flowing"),ai=Symbol("paused"),_r=Symbol("resume"),Fe=Symbol("buffer"),Ye=Symbol("pipes"),ze=Symbol("bufferLength"),Ba=Symbol("bufferPush"),Ss=Symbol("bufferShift"),Ve=Symbol("objectMode"),Se=Symbol("destroyed"),Fa=Symbol("error"),za=Symbol("emitData"),yu=Symbol("emitEnd"),Ua=Symbol("emitEnd2"),St=Symbol("async"),Ga=Symbol("abort"),Is=Symbol("aborted"),ci=Symbol("signal"),On=Symbol("dataListeners"),nt=Symbol("discarded"),di=t=>Promise.resolve().then(t),Gm=t=>t(),jm=t=>t==="end"||t==="finish"||t==="prefinish",qm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Hm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Xu=class{src;dest;opts;ondrain;constructor(t,e,n){this.src=t,this.dest=e,this.opts=n,this.ondrain=()=>t[_r](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Wm=class extends Xu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,n){super(t,e,n),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Km=t=>!!t.objectMode,$m=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Wn=class extends Rc{[Be]=!1;[ai]=!1;[Ye]=[];[Fe]=[];[Ve];[gt];[St];[xr];[Ut]=!1;[ln]=!1;[bs]=!1;[Es]=!1;[oi]=null;[ze]=0;[Se]=!1;[ci];[Is]=!1;[On]=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");Km(e)?(this[Ve]=!0,this[gt]=null):$m(e)?(this[gt]=e.encoding,this[Ve]=!1):(this[Ve]=!1,this[gt]=null),this[St]=!!e.async,this[xr]=this[gt]?new Bm(this[gt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Fe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ye]});let{signal:n}=e;n&&(this[ci]=n,n.aborted?this[Ga]():n.addEventListener("abort",()=>this[Ga]()))}get bufferLength(){return this[ze]}get encoding(){return this[gt]}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[Ve]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[St]}set async(t){this[St]=this[St]||!!t}[Ga](){this[Is]=!0,this.emit("abort",this[ci]?.reason),this.destroy(this[ci]?.reason)}get aborted(){return this[Is]}set aborted(t){}write(t,e,n){if(this[Is])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"&&(n=e,e="utf8"),e||(e="utf8");let i=this[St]?di:Gm;if(!this[Ve]&&!Buffer.isBuffer(t)){if(Hm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(qm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ve]?(this[Be]&&this[ze]!==0&&this[vs](!0),this[Be]?this.emit("data",t):this[Ba](t),this[ze]!==0&&this.emit("readable"),n&&i(n),this[Be]):t.length?(typeof t=="string"&&!(e===this[gt]&&!this[xr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[gt]&&(t=this[xr].write(t)),this[Be]&&this[ze]!==0&&this[vs](!0),this[Be]?this.emit("data",t):this[Ba](t),this[ze]!==0&&this.emit("readable"),n&&i(n),this[Be]):(this[ze]!==0&&this.emit("readable"),n&&i(n),this[Be])}read(t){if(this[Se])return null;if(this[nt]=!1,this[ze]===0||t===0||t&&t>this[ze])return this[Gt](),null;this[Ve]&&(t=null),this[Fe].length>1&&!this[Ve]&&(this[Fe]=[this[gt]?this[Fe].join(""):Buffer.concat(this[Fe],this[ze])]);let e=this[wu](t||null,this[Fe][0]);return this[Gt](),e}[wu](t,e){if(this[Ve])this[Ss]();else{let n=e;t===n.length||t===null?this[Ss]():typeof n=="string"?(this[Fe][0]=n.slice(t),e=n.slice(0,t),this[ze]-=t):(this[Fe][0]=n.subarray(t),e=n.subarray(0,t),this[ze]-=t)}return this.emit("data",e),!this[Fe].length&&!this[Ut]&&this.emit("drain"),e}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e="utf8"),t!==void 0&&this.write(t,e),n&&this.once("end",n),this[Ut]=!0,this.writable=!1,(this[Be]||!this[ai])&&this[Gt](),this}[_r](){this[Se]||(!this[On]&&!this[Ye].length&&(this[nt]=!0),this[ai]=!1,this[Be]=!0,this.emit("resume"),this[Fe].length?this[vs]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[_r]()}pause(){this[Be]=!1,this[ai]=!0,this[nt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[ai]}[Ba](t){this[Ve]?this[ze]+=1:this[ze]+=t.length,this[Fe].push(t)}[Ss](){return this[Ve]?this[ze]-=1:this[ze]-=this[Fe][0].length,this[Fe].shift()}[vs](t=!1){do;while(this[_u](this[Ss]())&&this[Fe].length);!t&&!this[Fe].length&&!this[Ut]&&this.emit("drain")}[_u](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[nt]=!1;let n=this[ln];return e=e||{},t===mu.stdout||t===mu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,n?e.end&&t.end():(this[Ye].push(e.proxyErrors?new Wm(this,t,e):new Xu(this,t,e)),this[St]?di(()=>this[_r]()):this[_r]()),t}unpipe(t){let e=this[Ye].find(n=>n.dest===t);e&&(this[Ye].length===1?(this[Be]&&this[On]===0&&(this[Be]=!1),this[Ye]=[]):this[Ye].splice(this[Ye].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let n=super.on(t,e);if(t==="data")this[nt]=!1,this[On]++,!this[Ye].length&&!this[Be]&&this[_r]();else if(t==="readable"&&this[ze]!==0)super.emit("readable");else if(jm(t)&&this[ln])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[oi]){let i=e;this[St]?di(()=>i.call(this,this[oi])):i.call(this,this[oi])}return n}removeListener(t,e){return this.off(t,e)}off(t,e){let n=super.off(t,e);return t==="data"&&(this[On]=this.listeners("data").length,this[On]===0&&!this[nt]&&!this[Ye].length&&(this[Be]=!1)),n}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[On]=0,!this[nt]&&!this[Ye].length&&(this[Be]=!1)),e}get emittedEnd(){return this[ln]}[Gt](){!this[bs]&&!this[ln]&&!this[Se]&&this[Fe].length===0&&this[Ut]&&(this[bs]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Es]&&this.emit("close"),this[bs]=!1)}emit(t,...e){let n=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ve]&&!n?!1:this[St]?(di(()=>this[za](n)),!0):this[za](n);if(t==="end")return this[yu]();if(t==="close"){if(this[Es]=!0,!this[ln]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[oi]=n,super.emit(Fa,n);let o=!this[ci]||this.listeners("error").length?super.emit("error",n):!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}[za](t){for(let n of this[Ye])n.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[Gt](),e}[yu](){return this[ln]?!1:(this[ln]=!0,this.readable=!1,this[St]?(di(()=>this[Ua]()),!0):this[Ua]())}[Ua](){if(this[xr]){let e=this[xr].end();if(e){for(let n of this[Ye])n.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[Ye])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ve]||(t.dataLength=0);let e=this.promise();return this.on("data",n=>{t.push(n),this[Ve]||(t.dataLength+=n.length)}),await e,t}async concat(){if(this[Ve])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[gt]?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",n=>e(n)),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 n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[Ut])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(Se,f),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(Se,f),this.pause(),i({value:x,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Se,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((x,g)=>{o=g,i=x,this.once(Se,f),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(Fa,e),this.off(Se,e),this.off("end",e),t=!0,{done:!0,value:void 0}),n=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Fa,e),this.once(Se,e),{next:n,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[nt]=!0,this[Fe].length=0,this[ze]=0;let e=this;return typeof e.close=="function"&&!this[Es]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return Fm}},Vm=Qe.writev,yn=Symbol("_autoClose"),yt=Symbol("_close"),li=Symbol("_ended"),ce=Symbol("_fd"),ja=Symbol("_finished"),Wt=Symbol("_flags"),qa=Symbol("_flush"),dc=Symbol("_handleChunk"),lc=Symbol("_makeBuf"),bi=Symbol("_mode"),As=Symbol("_needDrain"),Sr=Symbol("_onerror"),Ir=Symbol("_onopen"),Ha=Symbol("_onread"),yr=Symbol("_onwrite"),bn=Symbol("_open"),_t=Symbol("_path"),pn=Symbol("_pos"),It=Symbol("_queue"),br=Symbol("_read"),Wa=Symbol("_readSize"),Ht=Symbol("_reading"),ui=Symbol("_remain"),Ka=Symbol("_size"),Ms=Symbol("_write"),Ln=Symbol("_writing"),Bs=Symbol("_defaultFlag"),Gn=Symbol("_errored"),Pc=class extends Wn{[Gn]=!1;[ce];[_t];[Wa];[Ht]=!1;[Ka];[ui];[yn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Gn]=!1,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[_t]=t,this[Wa]=e.readSize||16*1024*1024,this[Ht]=!1,this[Ka]=typeof e.size=="number"?e.size:1/0,this[ui]=this[Ka],this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ce]=="number"?this[br]():this[bn]()}get fd(){return this[ce]}get path(){return this[_t]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[bn](){Qe.open(this[_t],"r",(t,e)=>this[Ir](t,e))}[Ir](t,e){t?this[Sr](t):(this[ce]=e,this.emit("open",e),this[br]())}[lc](){return Buffer.allocUnsafe(Math.min(this[Wa],this[ui]))}[br](){if(!this[Ht]){this[Ht]=!0;let t=this[lc]();if(t.length===0)return process.nextTick(()=>this[Ha](null,0,t));Qe.read(this[ce],t,0,t.length,null,(e,n,i)=>this[Ha](e,n,i))}}[Ha](t,e,n){this[Ht]=!1,t?this[Sr](t):this[dc](e,n)&&this[br]()}[yt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Sr](t){this[Ht]=!0,this[yt](),this.emit("error",t)}[dc](t,e){let n=!1;return this[ui]-=t,t>0&&(n=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ui]<=0)&&(n=!1,this[yt](),super.end()),n}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ce]=="number"&&this[br](),!1;case"error":return this[Gn]?!1:(this[Gn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Jm=class extends Pc{[bn](){let t=!0;try{this[Ir](null,Qe.openSync(this[_t],"r")),t=!1}finally{t&&this[yt]()}}[br](){let t=!0;try{if(!this[Ht]){this[Ht]=!0;do{let e=this[lc](),n=e.length===0?0:Qe.readSync(this[ce],e,0,e.length,null);if(!this[dc](n,e))break}while(!0);this[Ht]=!1}t=!1}finally{t&&this[yt]()}}[yt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,Qe.closeSync(t),this.emit("close")}}},Xs=class extends Mm{readable=!1;writable=!0;[Gn]=!1;[Ln]=!1;[li]=!1;[It]=[];[As]=!1;[_t];[bi];[yn];[ce];[Bs];[Wt];[ja]=!1;[pn];constructor(t,e){e=e||{},super(e),this[_t]=t,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[bi]=e.mode===void 0?438:e.mode,this[pn]=typeof e.start=="number"?e.start:void 0,this[yn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let n=this[pn]!==void 0?"r+":"w";this[Bs]=e.flags===void 0,this[Wt]=e.flags===void 0?n:e.flags,this[ce]===void 0&&this[bn]()}emit(t,...e){if(t==="error"){if(this[Gn])return!1;this[Gn]=!0}return super.emit(t,...e)}get fd(){return this[ce]}get path(){return this[_t]}[Sr](t){this[yt](),this[Ln]=!0,this.emit("error",t)}[bn](){Qe.open(this[_t],this[Wt],this[bi],(t,e)=>this[Ir](t,e))}[Ir](t,e){this[Bs]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[bn]()):t?this[Sr](t):(this[ce]=e,this.emit("open",e),this[Ln]||this[qa]())}end(t,e){return t&&this.write(t,e),this[li]=!0,!this[Ln]&&!this[It].length&&typeof this[ce]=="number"&&this[yr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[li]?(this.emit("error",new Error("write() after end()")),!1):this[ce]===void 0||this[Ln]||this[It].length?(this[It].push(t),this[As]=!0,!1):(this[Ln]=!0,this[Ms](t),!0)}[Ms](t){Qe.write(this[ce],t,0,t.length,this[pn],(e,n)=>this[yr](e,n))}[yr](t,e){t?this[Sr](t):(this[pn]!==void 0&&typeof e=="number"&&(this[pn]+=e),this[It].length?this[qa]():(this[Ln]=!1,this[li]&&!this[ja]?(this[ja]=!0,this[yt](),this.emit("finish")):this[As]&&(this[As]=!1,this.emit("drain"))))}[qa](){if(this[It].length===0)this[li]&&this[yr](null,0);else if(this[It].length===1)this[Ms](this[It].pop());else{let t=this[It];this[It]=[],Vm(this[ce],t,this[pn],(e,n)=>this[yr](e,n))}}[yt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Qu=class extends Xs{[bn](){let t;if(this[Bs]&&this[Wt]==="r+")try{t=Qe.openSync(this[_t],this[Wt],this[bi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[bn]();throw e}else t=Qe.openSync(this[_t],this[Wt],this[bi]);this[Ir](null,t)}[yt](){if(this[yn]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,Qe.closeSync(t),this.emit("close")}}[Ms](t){let e=!0;try{this[yr](null,Qe.writeSync(this[ce],t,0,t.length,this[pn])),e=!1}finally{if(e)try{this[yt]()}catch{}}}},Xm=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"]]),Qm=t=>!!t.sync&&!!t.file,ew=t=>!t.sync&&!!t.file,tw=t=>!!t.sync&&!t.file,nw=t=>!t.sync&&!t.file,rw=t=>!!t.file,iw=t=>Xm.get(t)||t,Dc=(t={})=>{if(!t)return{};let e={};for(let[n,i]of Object.entries(t)){let o=iw(n);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ri=(t,e,n,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=Dc(c);if(o?.(f,d),Qm(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if(ew(f)){let x=e(f,d);return u?x.then(()=>u(),u):x}else if(tw(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return n(f,d)}else if(nw(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:n,asyncNoFile:i,validate:o}),aw=ow.constants||{ZLIB_VERNUM:4736},Ct=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},aw)),cw=jn.concat,Eu=Object.getOwnPropertyDescriptor(jn,"concat"),dw=t=>t,$a=Eu?.writable===!0||Eu?.set!==void 0?t=>{jn.concat=t?dw:cw}:t=>{},qn=Symbol("_superWrite"),ks=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"}},Va=Symbol("flushFlag"),Oc=class extends Wn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof bu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new bu[e](t)}catch(n){throw new ks(n,this.constructor)}this.#o=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#o(new ks(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return uc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(jn.alloc(0),{[Va]:t})))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(n)}get ended(){return this.#n}[qn](t){return super.write(t)}write(t,e,n){if(typeof e=="function"&&(n=e,e="utf8"),typeof t=="string"&&(t=jn.from(t,e)),this.#e)return;uc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let d;try{let f=typeof t[Va]=="number"?t[Va]:this.#r;d=this.#t._processChunk(t,f),$a(!1)}catch(f){$a(!1),this.#o(new ks(f,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",f=>this.#o(new ks(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[qn](jn.from(f));for(let x=1;x<d.length;x++)u=this[qn](d[x])}else u=this[qn](jn.from(d));return n&&n(),u}},tf=class extends Oc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Ct.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Ct.Z_FINISH,t.fullFlushFlag=Ct.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(Ct.Z_SYNC_FLUSH),uc(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=n}this.handle&&(this.#e=t,this.#n=e)}}}},lw=class extends tf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[qn](t){return this.#e?(this.#e=!1,t[9]=255,super[qn](t)):super[qn](t)}},uw=class extends tf{constructor(t){super(t,"Unzip")}},nf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Ct.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Ct.BROTLI_OPERATION_FLUSH,super(t,e)}},fw=class extends nf{constructor(t){super(t,"BrotliCompress")}},hw=class extends nf{constructor(t){super(t,"BrotliDecompress")}},rf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.ZSTD_e_continue,t.finishFlush=t.finishFlush||Ct.ZSTD_e_end,t.fullFlushFlag=Ct.ZSTD_e_flush,super(t,e)}},xw=class extends rf{constructor(t){super(t,"ZstdCompress")}},pw=class extends rf{constructor(t){super(t,"ZstdDecompress")}},gw=(t,e)=>{if(Number.isSafeInteger(t))t<0?ww(t,e):mw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},mw=(t,e)=>{e[0]=128;for(var n=e.length;n>1;n--)e[n-1]=t&255,t=Math.floor(t/256)},ww=(t,e)=>{e[0]=255;var n=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),n?e[i-1]=sf(o):o===0?e[i-1]=0:(n=!0,e[i-1]=of(o))}},_w=t=>{let e=t[0],n=e===128?bw(t.subarray(1,t.length)):e===255?yw(t):null;if(n===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(n))throw Error("parsed number outside of javascript safe integer range");return n},yw=t=>{for(var e=t.length,n=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=sf(c):c===0?d=c:(i=!0,d=of(c)),d!==0&&(n-=d*Math.pow(256,e-o-1))}return n},bw=t=>{for(var e=t.length,n=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(n+=o*Math.pow(256,e-i-1))}return n},sf=t=>(255^t)&255,of=t=>(255^t)+1&255,Ew={};Nm(Ew,{code:()=>Lc,isCode:()=>Fs,isName:()=>vw,name:()=>Qs,normalFsTypes:()=>af});var Fs=t=>Qs.has(t),vw=t=>Lc.has(t),af=new Set(["0","","1","2","3","4","5","6","7","D"]),Qs=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"]]),Lc=new Map(Array.from(Qs).map(t=>[t[1],t[0]])),Hn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,n,i){Buffer.isBuffer(t)?this.decode(t,e||0,n,i):t&&this.#n(t)}decode(t,e,n,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Nn(t,e+156,1),c=af.has(o),d=c?n:void 0,u=c?i:void 0;if(this.path=d?.path??Nn(t,e,100),this.mode=d?.mode??u?.mode??gn(t,e+100,8),this.uid=d?.uid??u?.uid??gn(t,e+108,8),this.gid=d?.gid??u?.gid??gn(t,e+116,8),this.size=d?.size??u?.size??gn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Ja(t,e+136,12),this.cksum=gn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Fs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Nn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Nn(t,e+265,32),this.gname=d?.gname??u?.gname??Nn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??gn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??gn(t,e+337,8)??0,t[e+475]!==0){let x=Nn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Nn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=n?.atime??i?.atime??Ja(t,e+476,12),this.ctime=n?.ctime??i?.ctime??Ja(t,e+488,12)}let f=256;for(let x=e;x<e+148;x++)f+=t[x];for(let x=e+156;x<e+512;x++)f+=t[x];this.cksumValid=f===this.cksum,this.cksum===void 0&&f===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e||n==="linkpath"&&e||n==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,i=Sw(this.path||"",n),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Mn(t,e,100,o)||this.needPax,this.needPax=mn(t,e+100,8,this.mode)||this.needPax,this.needPax=mn(t,e+108,8,this.uid)||this.needPax,this.needPax=mn(t,e+116,8,this.gid)||this.needPax,this.needPax=mn(t,e+124,12,this.size)||this.needPax,this.needPax=Ya(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Mn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Mn(t,e+265,32,this.uname)||this.needPax,this.needPax=Mn(t,e+297,32,this.gname)||this.needPax,this.needPax=mn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=mn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Mn(t,e+345,n,c)||this.needPax,t[e+475]!==0?this.needPax=Mn(t,e+345,155,c)||this.needPax:(this.needPax=Mn(t,e+345,130,c)||this.needPax,this.needPax=Ya(t,e+476,12,this.atime)||this.needPax,this.needPax=Ya(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,mn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Qs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Lc.get(t));if(Fs(e)||e==="Unsupported")this.#e=e;else if(Fs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Sw=(t,e)=>{let n=t,i="",o,c=pr.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,i,!1];else{i=pr.dirname(n),n=pr.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(i)<=e?o=[n,i,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(i)<=e?o=[n.slice(0,99),i,!0]:(n=pr.join(pr.basename(i),n),i=pr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Nn=(t,e,n)=>t.subarray(e,e+n).toString("utf8").replace(/\0.*/,""),Ja=(t,e,n)=>Iw(gn(t,e,n)),Iw=t=>t===void 0?void 0:new Date(t*1e3),gn=(t,e,n)=>Number(t[e])&128?_w(t.subarray(e,e+n)):kw(t,e,n),Aw=t=>isNaN(t)?void 0:t,kw=(t,e,n)=>Aw(parseInt(t.subarray(e,e+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),Tw={12:8589934591,8:2097151},mn=(t,e,n,i)=>i===void 0?!1:i>Tw[n]||i<0?(gw(i,t.subarray(e,e+n)),!0):(Cw(t,e,n,i),!1),Cw=(t,e,n,i)=>t.write(Rw(i,n),e,n,"ascii"),Rw=(t,e)=>Pw(Math.floor(t).toString(8),e),Pw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ya=(t,e,n,i)=>i===void 0?!1:mn(t,e,n,i.getTime()/1e3),Dw=new Array(156).join("\0"),Mn=(t,e,n,i)=>i===void 0?!1:(t.write(i+Dw,e,n,"utf8"),i.length!==Buffer.byteLength(i)||i.length>n),$s=class cf{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,n=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=n,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let n=Buffer.byteLength(e),i=512*Math.ceil(1+n/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Hn({path:("PaxHeader/"+Ow(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:n,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,n,"utf8");for(let c=n+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let n=this[e],i=n instanceof Date?n.getTime()/1e3:n,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
+
`,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,n,i=!1){return new cf(Lw(Nw(e),n),i)}},Lw=(t,e)=>e?Object.assign({},e,t):t,Nw=t=>t.replace(/\n$/,"").split(`
|
|
91
|
+
`).reduce(Mw,Object.create(null)),Mw=(t,e)=>{let n=parseInt(e,10);if(n!==Buffer.byteLength(e)+1)return t;e=e.slice((n+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Bw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=Bw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Fw=class extends Wn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,n){switch(super({}),this.pause(),this.extended=e,this.globalExtended=n,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=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),n&&this.#e(n,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,i=this.blockRemain;return this.remain=Math.max(0,n-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:n>=e?super.write(t):super.write(t.subarray(0,n))}#e(t,e=!1){t.path&&(t.path=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e))))}},eo=(t,e,n,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=n instanceof Error&&n.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(n instanceof Error&&(i=Object.assign(n,i),n=n.message),t.emit("warn",e,n,i)):n instanceof Error?t.emit("error",Object.assign(n,i)):t.emit("error",Object.assign(new Error(`${e}: ${n}`),i))},zw=1024*1024,fc=Buffer.from([31,139]),hc=Buffer.from([40,181,47,253]),Uw=Math.max(fc.length,hc.length),ct=Symbol("state"),Bn=Symbol("writeEntry"),jt=Symbol("readEntry"),Za=Symbol("nextEntry"),vu=Symbol("processEntry"),At=Symbol("extendedHeader"),fi=Symbol("globalExtendedHeader"),un=Symbol("meta"),Su=Symbol("emitMeta"),pe=Symbol("buffer"),qt=Symbol("queue"),fn=Symbol("ended"),Xa=Symbol("emittedEnd"),Fn=Symbol("emit"),Te=Symbol("unzip"),Ts=Symbol("consumeChunk"),Cs=Symbol("consumeChunkSub"),Qa=Symbol("consumeBody"),Iu=Symbol("consumeMeta"),Au=Symbol("consumeHeader"),hi=Symbol("consuming"),ec=Symbol("bufferConcat"),Rs=Symbol("maybeEnd"),gr=Symbol("writing"),hn=Symbol("aborted"),Ps=Symbol("onDone"),zn=Symbol("sawValidEntry"),Ds=Symbol("sawNullBlock"),Os=Symbol("sawEOF"),ku=Symbol("closeStream"),Gw=()=>!0,Ci=class extends sw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[qt]=[];[pe];[jt];[Bn];[ct]="begin";[un]="";[At];[fi];[fn]=!1;[Te];[hn]=!1;[zn];[Ds]=!1;[Os]=!1;[gr]=!1;[hi]=!1;[Xa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ps,()=>{(this[ct]==="begin"||this[zn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ps,t.ondone):this.on(Ps,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||zw,this.filter=typeof t.filter=="function"?t.filter:Gw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let n=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:n?!0:void 0,this.on("end",()=>this[ku]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,n={}){eo(this,t,e,n)}[Au](t,e){this[zn]===void 0&&(this[zn]=!1);let n;try{n=new Hn(t,e,this[At],this[fi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(n.nullBlock)this[Ds]?(this[Os]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Fn]("eof")):(this[Ds]=!0,this[Fn]("nullBlock"));else if(this[Ds]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let i=n.type;if(/^(Symbolic)?Link$/.test(i)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let o=this[Bn]=new Fw(n,this[At],this[fi]);if(!this[zn])if(o.remain){let c=()=>{o.invalid||(this[zn]=!0)};o.on("end",c)}else this[zn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Fn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[un]="",o.on("data",c=>this[un]+=c),this[ct]="meta"):(this[At]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Fn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[jt]?this[qt].push(o):(this[qt].push(o),this[Za]())))}}}[ku](){queueMicrotask(()=>this.emit("close"))}[vu](t){let e=!0;if(!t)this[jt]=void 0,e=!1;else if(Array.isArray(t)){let[n,...i]=t;this.emit(n,...i)}else this[jt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Za]()),e=!1);return e}[Za](){do;while(this[vu](this[qt].shift()));if(this[qt].length===0){let t=this[jt];!t||t.flowing||t.size===t.remain?this[gr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Qa](t,e){let n=this[Bn];if(!n)throw new Error("attempt to consume body without entry??");let i=n.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return n.write(o),n.blockRemain||(this[ct]="header",this[Bn]=void 0,n.end()),o.length}[Iu](t,e){let n=this[Bn],i=this[Qa](t,e);return!this[Bn]&&n&&this[Su](n),i}[Fn](t,e,n){this[qt].length===0&&!this[jt]?this.emit(t,e,n):this[qt].push([t,e,n])}[Su](t){switch(this[Fn]("meta",this[un]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[At]=$s.parse(this[un],this[At],!1);break;case"GlobalExtendedHeader":this[fi]=$s.parse(this[un],this[fi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[At]??Object.create(null);this[At]=e,e.path=this[un].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[At]||Object.create(null);this[At]=e,e.linkpath=this[un].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[hn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[hn])return n?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<Uw)return this[pe]=t,n?.(),!0;for(let d=0;this[Te]===void 0&&d<fc.length;d++)t[d]!==fc[d]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<hc.length;d++)if(t[d]!==hc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[fn])this.brotli=!0;else return this[pe]=t,n?.(),!0;else try{new Hn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let d=this[fn];this[fn]=!1,this[Te]=this[Te]===void 0?new uw({}):o?new pw({}):new hw({}),this[Te].on("data",f=>this[Ts](f)),this[Te].on("error",f=>this.abort(f)),this[Te].on("end",()=>{this[fn]=!0,this[Ts]()}),this[gr]=!0;let u=!!this[Te][d?"end":"write"](t);return this[gr]=!1,n?.(),u}}this[gr]=!0,this[Te]?this[Te].write(t):this[Ts](t),this[gr]=!1;let i=this[qt].length>0?!1:this[jt]?this[jt].flowing:!0;return!i&&this[qt].length===0&&this[jt]?.once("drain",()=>this.emit("drain")),n?.(),i}[ec](t){t&&!this[hn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Rs](){if(this[fn]&&!this[Xa]&&!this[hn]&&!this[hi]){this[Xa]=!0;let t=this[Bn];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[Fn](Ps)}}[Ts](t){if(this[hi]&&t)this[ec](t);else if(!t&&!this[pe])this[Rs]();else if(t){if(this[hi]=!0,this[pe]){this[ec](t);let e=this[pe];this[pe]=void 0,this[Cs](e)}else this[Cs](t);for(;this[pe]&&this[pe]?.length>=512&&!this[hn]&&!this[Os];){let e=this[pe];this[pe]=void 0,this[Cs](e)}this[hi]=!1}(!this[pe]||this[fn])&&this[Rs]()}[Cs](t){let e=0,n=t.length;for(;e+512<=n&&!this[hn]&&!this[Os];)switch(this[ct]){case"begin":case"header":this[Au](t,e),e+=512;break;case"ignore":case"body":e+=this[Qa](t,e);break;case"meta":e+=this[Iu](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<n&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):t.subarray(e))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),n&&this.once("finish",n),this[hn]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[fn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Rs]())),this}},Ei=t=>{let e=t.length-1,n=-1;for(;e>-1&&t.charAt(e)==="/";)n=e,e--;return n===-1?t:t.slice(0,n)},jw=t=>{let e=t.onReadEntry;t.onReadEntry=e?n=>{e(n),n.resume()}:n=>n.resume()},df=(t,e)=>{let n=new Map(e.map(c=>[Ei(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||Zm(c).root||".",f;if(c===u)f=!1;else{let x=n.get(c);f=x!==void 0?x:o(Ym(c),u)}return n.set(c,f),f};t.filter=i?(c,d)=>i(c,d)&&o(Ei(c)):c=>o(Ei(c))},qw=t=>{let e=new Ci(t),n=t.file,i;try{i=Er.openSync(n,"r");let o=Er.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Er.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let f=Er.readSync(i,u,0,c,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{Er.closeSync(i)}catch{}}},Hw=(t,e)=>{let n=new Ci(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{n.on("error",d),n.on("end",c),Er.stat(o,(u,f)=>{if(u)d(u);else{let x=new Pc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(n)}})})},Ar=Ri(qw,Hw,t=>new Ci(t),t=>new Ci(t),(t,e)=>{e?.length&&df(t,e),t.noResume||jw(t)}),lf=(t,e,n)=>(t&=4095,n&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Kw,parse:Cu}=Ww,Nc=t=>{let e="",n=Cu(t);for(;Kw(t)||n.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":n.root;t=t.slice(i.length),e+=i,n=Cu(t)}return[e,t]},to=["|","<",">","?",":"],Mc=to.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),$w=new Map(to.map((t,e)=>[t,Mc[e]])),Vw=new Map(Mc.map((t,e)=>[t,to[e]])),Ru=t=>to.reduce((e,n)=>e.split(n).join($w.get(n)),t),Jw=t=>Mc.reduce((e,n)=>e.split(n).join(Vw.get(n)),t),uf=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),Ei(e)+"/"+t):X(t),Yw=16*1024*1024,Pu=Symbol("process"),Du=Symbol("file"),Ou=Symbol("directory"),xc=Symbol("symlink"),Lu=Symbol("hardlink"),xi=Symbol("header"),zs=Symbol("read"),pc=Symbol("lstat"),Us=Symbol("onlstat"),gc=Symbol("onread"),mc=Symbol("onreadlink"),wc=Symbol("openfile"),_c=Symbol("onopenfile"),wn=Symbol("close"),Js=Symbol("mode"),yc=Symbol("awaitDrain"),tc=Symbol("ondrain"),Tt=Symbol("prefix"),ff=class extends Wn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let n=Dc(e);super(),this.path=X(t),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||Yw,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=X(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?X(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Nc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=Jw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(n.absolute||Tu.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[Us](o):this[pc]()}warn(t,e,n={}){return eo(this,t,e,n)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[pc](){kt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Us](e)})}[Us](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Qw(t),this.emit("stat",t),this[Pu]()}[Pu](){switch(this.type){case"File":return this[Du]();case"Directory":return this[Ou]();case"SymbolicLink":return this[xc]();default:return this.end()}}[Js](t){return lf(t,this.type==="Directory",this.portable)}[Tt](t){return uf(t,this.prefix)}[xi](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Hn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,mode:this[Js](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new $s({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](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)}[Ou](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[xi](),this.end()}[xc](){kt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){this.linkpath=X(t),this[xi](),this.end()}[Lu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(Tu.relative(this.cwd,t)),this.stat.size=0,this[xi](),this.end()}[Du](){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[Lu](e);this.linkCache.set(t,this.absolute)}if(this[xi](),this.stat.size===0)return this.end();this[wc]()}[wc](){kt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){if(this.fd=t,this.#e)return this[wn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[zs]()}[zs](){let{fd:t,buf:e,offset:n,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");kt.read(t,e,n,i,o,(c,d)=>{if(c)return this[wn](()=>this.emit("error",c));this[gc](d)})}[wn](t=()=>{}){this.fd!==void 0&&kt.close(this.fd,t)}[gc](t){if(t<=0&&this.remain>0){let n=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[wn](()=>this.emit("error",n))}if(t>this.remain){let n=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[wn](()=>this.emit("error",n))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let n=t;n<this.length&&t<this.blockRemain;n++)this.buf[n+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[tc]():this[yc](()=>this[tc]())}[yc](t){this.once("drain",t)}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,n)}[tc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[wn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[zs]()}},Zw=class extends ff{sync=!0;[pc](){this[Us](kt.lstatSync(this.absolute))}[xc](){this[mc](kt.readlinkSync(this.absolute))}[wc](){this[_c](kt.openSync(this.absolute,"r"))}[zs](){let t=!0;try{let{fd:e,buf:n,offset:i,length:o,pos:c}=this;if(e===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let d=kt.readSync(e,n,i,o,c);this[gc](d),t=!1}finally{if(t)try{this[wn](()=>{})}catch{}}}[yc](t){t()}[wn](t=()=>{}){this.fd!==void 0&&kt.closeSync(this.fd),t()}},Xw=class extends Wn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,n={}){return eo(this,t,e,n)}constructor(t,e={}){let n=Dc(e);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=X(t.path),this.mode=t.mode!==void 0?this[Js](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:n.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Nc(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 Hn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new $s({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](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)}[Tt](t){return uf(t,this.prefix)}[Js](t){return lf(t,this.type==="Directory",this.portable)}write(t,e,n){typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,n)}end(t,e,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),n&&this.once("finish",n),t?super.end(t,n):super.end(n),this}},Qw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",e_=class vr{tail;head;length=0;static create(e=[]){return new vr(e)}constructor(e=[]){for(let n of e)this.push(n)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let n=e.next,i=e.prev;return n&&(n.prev=i),i&&(i.next=n),e===this.head&&(this.head=n),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,n}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let n=this.head;e.list=this,e.next=n,n&&(n.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let n=this.tail;e.list=this,e.prev=n,n&&(n.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let n=0,i=e.length;n<i;n++)n_(this,e[n]);return this.length}unshift(...e){for(var n=0,i=e.length;n<i;n++)r_(this,e[n]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,n=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,n.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,n=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,n.list=void 0,this.length--,e}forEach(e,n){n=n||this;for(let i=this.head,o=0;i;o++)e.call(n,i.value,o,this),i=i.next}forEachReverse(e,n){n=n||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(n,i.value,o,this),i=i.prev}get(e){let n=0,i=this.head;for(;i&&n<e;n++)i=i.next;if(n===e&&i)return i.value}getReverse(e){let n=0,i=this.tail;for(;i&&n<e;n++)i=i.prev;if(n===e&&i)return i.value}map(e,n){n=n||this;let i=new vr;for(let o=this.head;o;)i.push(e.call(n,o.value,this)),o=o.next;return i}mapReverse(e,n){n=n||this;var i=new vr;for(let o=this.tail;o;)i.push(e.call(n,o.value,this)),o=o.prev;return i}reduce(e,n){let i,o=this.head;if(arguments.length>1)i=n;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,n){let i,o=this.tail;if(arguments.length>1)i=n;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let n=0,i=this.head;i;n++)e[n]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let n=0,i=this.tail;i;n++)e[n]=i.value,i=i.prev;return e}slice(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new vr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<n;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new vr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.length,c=this.tail;for(;c&&o>n;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,n=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<n;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=t_(this,o,d);return c}reverse(){let e=this.head,n=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=n,this.tail=e,this}};function t_(t,e,n){let i=e,o=e?e.next:t.head,c=new Bc(n,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function n_(t,e){t.tail=new Bc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function r_(t,e){t.head=new Bc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Bc=class{list;next;prev;value;constructor(t,e,n,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Mu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Bu=Buffer.alloc(1024),Gs=Symbol("onStat"),pi=Symbol("ended"),mt=Symbol("queue"),gi=Symbol("pendingLinks"),xn=Symbol("current"),Un=Symbol("process"),mi=Symbol("processing"),Ls=Symbol("processJob"),wt=Symbol("jobs"),nc=Symbol("jobDone"),js=Symbol("addFSEntry"),Fu=Symbol("addTarEntry"),bc=Symbol("stat"),Ec=Symbol("readdir"),qs=Symbol("onreaddir"),Hs=Symbol("pipe"),zu=Symbol("entry"),rc=Symbol("entryOpt"),Ws=Symbol("writeEntryClass"),hf=Symbol("write"),ic=Symbol("ondrain"),no=class extends Wn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ws];onWriteEntry;[mt];[gi]=new Map;[wt]=0;[mi]=!1;[pi]=!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[Ws]=ff,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 lw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new fw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new xw(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",n=>super.write(n)),e.on("end",()=>super.end()),e.on("drain",()=>this[ic]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ic]);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[mt]=new e_,this[wt]=0,this.jobs=Number(t.jobs)||4,this[mi]=!1,this[pi]=!1}[hf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&this.add(t),this[pi]=!0,this[Un](),n&&n(),this}write(t){if(this[pi])throw new Error("write after end");return typeof t=="string"?this[js](t):this[Fu](t),this.flowing}[Fu](t){let e=X(Nu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let n=new Mu(t.path,e);n.entry=new Xw(t,this[rc](n)),n.entry.on("end",()=>this[nc](n)),this[wt]+=1,this[mt].push(n)}this[Un]()}[js](t){let e=X(Nu.resolve(this.cwd,t));this[mt].push(new Mu(t,e)),this[Un]()}[bc](t){t.pending=!0,this[wt]+=1;let e=this.follow?"stat":"lstat";Vs[e](t.absolute,(n,i)=>{t.pending=!1,this[wt]-=1,n?this.emit("error",n):this[Gs](t,i)})}[Gs](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[Ls](t);else{let n=`${e.dev}:${e.ino}`,i=this[gi].get(n);i?i.push(t):this[gi].set(n,[t]),t.pendingLink=!0,t.pending=!0}this[Un]()}[Ec](t){t.pending=!0,this[wt]+=1,Vs.readdir(t.absolute,(e,n)=>{if(t.pending=!1,this[wt]-=1,e)return this.emit("error",e);this[qs](t,n)})}[qs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Un]()}[Un](){if(!this[mi]){this[mi]=!0;for(let t=this[mt].head;t&&this[wt]<this.jobs;t=t.next)if(this[Ls](t.value),t.value.ignore){let e=t.next;this[mt].removeNode(t),t.next=e}this[mi]=!1,this[pi]&&this[mt].length===0&&this[wt]===0&&(this.zip?this.zip.end(Bu):(super.write(Bu),super.end()))}}get[xn](){return this[mt]&&this[mt].head&&this[mt].head.value}[nc](t){this[mt].shift(),this[wt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let n=`${e.dev}:${e.ino}`,i=this[gi].get(n);if(i){this[gi].delete(n);for(let o of i)o.pending=!1,this[Ls](o)}}this[Un]()}[Ls](t){if(t.pending&&t.pendingLink&&t===this[xn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[xn]&&!t.piped&&this[Hs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Gs](t,e):this[bc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[qs](t,e):this[Ec](t),!t.readdir)return}if(t.entry=this[zu](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[Hs](t)}}}[rc](t){return{onwarn:(e,n,i)=>this.warn(e,n,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[zu](t){this[wt]+=1;try{return new this[Ws](t.path,this[rc](t)).on("end",()=>this[nc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ic](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[Hs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[js](c+i)});let e=t.entry,n=this.zip;if(!e)throw new Error("cannot pipe without source");n?e.on("data",i=>{n.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,n={}){eo(this,t,e,n)}},Fc=class extends no{sync=!0;constructor(t){super(t),this[Ws]=Zw}pause(){}resume(){}[bc](t){let e=this.follow?"statSync":"lstatSync";this[Gs](t,Vs[e](t.absolute))}[Ec](t){this[qs](t,Vs.readdirSync(t.absolute))}[Hs](t){let e=t.entry,n=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[js](c+i)}),!e)throw new Error("Cannot pipe without source");n?e.on("data",i=>{n.write(i)}):e.on("data",i=>{super[hf](i)})}},i_=(t,e)=>{let n=new Fc(t),i=new Qu(t.file,{mode:t.mode||438});n.pipe(i),xf(n,e)},s_=(t,e)=>{let n=new no(t),i=new Xs(t.file,{mode:t.mode||438});n.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),n.on("error",d)});return pf(n,e).catch(c=>n.emit("error",c)),o},xf=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Ar({file:ef.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},pf=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Ar({file:ef.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(n);t.end()},o_=(t,e)=>{let n=new Fc(t);return xf(n,e),n},a_=(t,e)=>{let n=new no(t);return pf(n,e).catch(i=>n.emit("error",i)),n},NA=Ri(i_,s_,o_,a_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),d_=process.env.__FAKE_PLATFORM__||process.platform,_f=d_==="win32",{O_CREAT:yf,O_NOFOLLOW:Uu,O_TRUNC:bf,O_WRONLY:Ef}=wf.constants,vf=Number(process.env.__FAKE_FS_O_FILENAME__)||wf.constants.UV_FS_O_FILEMAP||0,l_=_f&&!!vf,u_=512*1024,f_=vf|bf|yf|Ef,Gu=!_f&&typeof Uu=="number"?Uu|bf|yf|Ef:null,Sf=Gu!==null?()=>Gu:l_?t=>t<u_?f_:"w":()=>"w",vc=(t,e,n)=>{try{return ro.lchownSync(t,e,n)}catch(i){if(i?.code!=="ENOENT")throw i}},Ys=(t,e,n,i)=>{ro.lchown(t,e,n,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},h_=(t,e,n,i,o)=>{if(e.isDirectory())If(vi.resolve(t,e.name),n,i,c=>{if(c)return o(c);let d=vi.resolve(t,e.name);Ys(d,n,i,o)});else{let c=vi.resolve(t,e.name);Ys(c,n,i,o)}},If=(t,e,n,i)=>{ro.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 Ys(t,e,n,i);let d=c.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--d===0)return Ys(t,e,n,i)}};for(let x of c)h_(t,x,e,n,f)})},x_=(t,e,n,i)=>{e.isDirectory()&&Af(vi.resolve(t,e.name),n,i),vc(vi.resolve(t,e.name),n,i)},Af=(t,e,n)=>{let i;try{i=ro.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return vc(t,e,n);throw c}for(let o of i)x_(t,o,e,n);return vc(t,e,n)},kf=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"}},io=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"}},g_=(t,e)=>{it.stat(t,(n,i)=>{(n||!i.isDirectory())&&(n=new kf(t,n?.code||"ENOTDIR")),e(n)})},m_=(t,e,n)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,g=e.unlink,w=X(e.cwd),S=(v,I)=>{v?n(v):I&&f?If(I,d,u,A=>S(A)):c?it.chmod(t,o,n):n()};if(t===w)return g_(t,S);if(x)return p_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=X(Zs.relative(w,t)).split("/");Sc(w,y,o,g,w,void 0,S)},Sc=(t,e,n,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),f=X(Zs.resolve(t+"/"+u));it.mkdir(f,n,Tf(f,e,n,i,o,c,d))},Tf=(t,e,n,i,o,c,d)=>u=>{u?it.lstat(t,(f,x)=>{if(f)f.path=f.path&&X(f.path),d(f);else if(x.isDirectory())Sc(t,e,n,i,o,c,d);else if(i)it.unlink(t,g=>{if(g)return d(g);it.mkdir(t,n,Tf(t,e,n,i,o,c,d))});else{if(x.isSymbolicLink())return d(new io(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Sc(t,e,n,i,o,c,d))},w_=t=>{let e=!1,n;try{e=it.statSync(t).isDirectory()}catch(i){n=i?.code}finally{if(!e)throw new kf(t,n??"ENOTDIR")}},__=(t,e)=>{t=X(t);let n=e.umask??18,i=e.mode|448,o=(i&n)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),f=e.preserve,x=e.unlink,g=X(e.cwd),w=v=>{v&&u&&Af(v,c,d),o&&it.chmodSync(t,i)};if(t===g)return w_(g),w();if(f)return w(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X(Zs.relative(g,t)).split("/"),y;for(let v=S.shift(),I=g;v&&(I+="/"+v);v=S.shift()){I=X(Zs.resolve(I));try{it.mkdirSync(I,i),y=y||I}catch{let A=it.lstatSync(I);if(A.isDirectory())continue;if(x){it.unlinkSync(I),it.mkdirSync(I,i),y=y||I;continue}else if(A.isSymbolicLink())return new io(I,I+"/"+S.join("/"))}}return w(y)},sc=Object.create(null),ju=1e4,mr=new Set,y_=t=>{mr.has(t)?mr.delete(t):sc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),mr.add(t);let e=sc[t],n=mr.size-ju;if(n>ju/10){for(let i of mr)if(mr.delete(i),delete sc[i],--n<=0)break}return e},b_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,E_=b_==="win32",v_=t=>t.split("/").slice(0,-1).reduce((e,n)=>{let i=e.at(-1);return i!==void 0&&(n=Cf(i,n)),e.push(n||"/"),e},[]),S_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=E_?["win32 parallelization disabled"]:t.map(i=>Ei(Cf(y_(i))));let n=new Set(t.map(i=>v_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:n,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of n){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(n=>this.#e.get(n)),dirs:[...e.dirs].map(n=>this.#e.get(n))}}check(t){let{paths:e,dirs:n}=this.#s(t);return e.every(i=>i&&i[0]===t)&&n.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:n,dirs:i}=e,o=new Set;for(let c of n){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},I_=()=>process.umask(),qu=Symbol("onEntry"),Ic=Symbol("checkFs"),Hu=Symbol("checkFs2"),Ac=Symbol("isReusable"),dt=Symbol("makeFs"),kc=Symbol("file"),Tc=Symbol("directory"),Ks=Symbol("link"),Wu=Symbol("symlink"),Ku=Symbol("hardlink"),yi=Symbol("ensureNoSymlink"),$u=Symbol("unsupported"),Vu=Symbol("checkPath"),oc=Symbol("stripAbsolutePath"),_n=Symbol("mkdir"),Ue=Symbol("onError"),Ns=Symbol("pending"),Ju=Symbol("pend"),wr=Symbol("unpend"),ac=Symbol("ended"),cc=Symbol("maybeClose"),Cc=Symbol("skip"),Si=Symbol("doChown"),Ii=Symbol("uid"),Ai=Symbol("gid"),ki=Symbol("checkedCwd"),A_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ti=A_==="win32",k_=1024,T_=(t,e)=>{if(!Ti)return re.unlink(t,e);let n=t+".DELETE."+mf(16).toString("hex");re.rename(t,n,i=>{if(i)return e(i);re.unlink(n,e)})},C_=t=>{if(!Ti)return re.unlinkSync(t);let e=t+".DELETE."+mf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Yu=(t,e,n)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:n,zc=class extends Ci{[ac]=!1;[ki]=!1;[Ns]=0;reservations=new S_;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[ac]=!0,this[cc]()},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:k_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ti,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:I_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[qu](e))}warn(t,e,n={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(n.recoverable=!1),super.warn(t,e,n)}[cc](){this[ac]&&this[Ns]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[oc](t,e){let n=t[e],{type:i}=t;if(!n||this.preservePaths)return!0;let[o,c]=Nc(n),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ti&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:n}),!1;let u=Le.posix.dirname(t.path),f=Le.posix.normalize(Le.posix.join(u,d.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:n}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:n})),!0}[Vu](t){let e=X(t.path),n=e.split("/");if(this.strip){if(n.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}n.splice(0,this.strip),t.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this[oc](t,"path")||!this[oc](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?X(Le.resolve(t.path)):X(Le.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:X(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Le.win32.parse(String(t.absolute));t.absolute=i+Ru(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+Ru(t.path.slice(o.length))}return!0}[qu](t){if(!this[Vu](t))return t.resume();switch(c_.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[Ic](t);default:return this[$u](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[wr](),e.resume())}[_n](t,e,n){m_(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},n)}[Si](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}[Ii](t){return Yu(this.uid,t.uid,this.processUid)}[Ai](t){return Yu(this.gid,t.gid,this.processGid)}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Xs(String(t.absolute),{flags:Sf(t.size),mode:n,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,f=>{f?this[Ue](f,t):this[wr](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,g=t.mtime;re.futimes(f,x,g,w=>w?re.utimes(u,x,g,S=>c(S&&w)):c())}if(typeof f=="number"&&this[Si](t)){o++;let x=this[Ii](t),g=this[Ai](t);typeof x=="number"&&typeof g=="number"&&re.fchown(f,x,g,w=>w?re.chown(u,x,g,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)}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode;this[_n](String(t.absolute),n,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[wr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Si](t)&&(o++,re.chown(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)),c)),c()})}[$u](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Wu](t,e){let n=X(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[yi](t,this.cwd,n,()=>this[Ks](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[Ku](t,e){let n=X(Le.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[yi](t,this.cwd,i,()=>this[Ks](t,n,"link",e),o=>{this[Ue](o,t),e()})}[yi](t,e,n,i,o){let c=n.shift();if(this.preservePaths||c===void 0)return i();let d=Le.resolve(e,c);re.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new io(d,Le.resolve(d,n.join("/"))));this[yi](t,d,n,i,o)})}[Ju](){this[Ns]++}[wr](){this[Ns]--,this[cc]()}[Cc](t){this[wr](),t.resume()}[Ac](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ti}[Ic](t){this[Ju]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,n=>this[Hu](t,n))}[Hu](t,e){let n=d=>{e(d)},i=()=>{this[_n](this.cwd,this.dmode,d=>{if(d){this[Ue](d,t),n();return}this[ki]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=X(Le.dirname(String(t.absolute)));if(d!==this.cwd)return this[_n](d,this.dmode,u=>{if(u){this[Ue](u,t),n();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Cc](t),n();return}if(d||this[Ac](t,u))return this[dt](null,t,n);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=g=>this[dt](g??null,t,n);return f?re.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),f=>this[dt](f??null,t,n))}if(t.absolute===this.cwd)return this[dt](null,t,n);T_(String(t.absolute),f=>this[dt](f??null,t,n))})};this[ki]?o():i()}[dt](t,e,n){if(t){this[Ue](t,e),n();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[kc](e,n);case"Link":return this[Ku](e,n);case"SymbolicLink":return this[Wu](e,n);case"Directory":case"GNUDumpDir":return this[Tc](e,n)}}[Ks](t,e,n,i){re[n](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[wr](),t.resume()),i()})}},wi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Rf=class extends zc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[Ic](t){if(!this[ki]){let o=this[_n](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[ki]=!0}if(t.absolute!==this.cwd){let o=X(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[_n](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,n]=wi(()=>re.lstatSync(String(t.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[Cc](t);if(e||this[Ac](t,n))return this[dt](null,t);if(n.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(n.mode&4095)!==t.mode,[d]=c?wi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](d,t)}let[o]=wi(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:wi(()=>C_(String(t.absolute)));this[dt](i,t)}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{re.closeSync(o)}catch(f){u=f}(d||u)&&this[Ue](d||u,t),e()},o;try{o=re.openSync(String(t.absolute),Sf(t.size),n)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[Ue](d,t)),t.pipe(c)),c.on("data",d=>{try{re.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{re.futimesSync(o,u,f)}catch(x){try{re.utimesSync(String(t.absolute),u,f)}catch{d=x}}}if(this[Si](t)){let u=this[Ii](t),f=this[Ai](t);try{re.fchownSync(o,Number(u),Number(f))}catch(x){try{re.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||x}}}i(d)})}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[_n](String(t.absolute),n);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[Si](t))try{re.chownSync(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)))}catch{}e(),t.resume()}[_n](t,e){try{return __(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(n){return n}}[yi](t,e,n,i,o){if(this.preservePaths||n.length===0)return i();let c=e;for(let d of n){c=Le.resolve(c,d);let[u,f]=wi(()=>re.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new io(c,Le.resolve(e,n.join("/"))))}i()}[Ks](t,e,n,i){let o=`${n}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},R_=t=>{let e=new Rf(t),n=t.file,i=gf.statSync(n),o=t.maxReadSize||16*1024*1024;new Jm(n,{readSize:o,size:i.size}).pipe(e)},P_=(t,e)=>{let n=new zc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{n.on("error",d),n.on("close",c),gf.stat(o,(u,f)=>{if(u)d(u);else{let x=new Pc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(n)}})})},Pf=Ri(R_,P_,t=>new Rf(t),t=>new zc(t),(t,e)=>{e?.length&&df(t,e)}),D_=(t,e)=>{let n=new Fc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw f}let d=rt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let g=0,w=0;g<512;g+=w){if(w=rt.readSync(o,u,g,u.length-g,c+g),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let f=new Hn(u);if(!f.cksumValid)break;let x=512*Math.ceil((f.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,O_(t,n,c,o,e)}finally{if(i)try{rt.closeSync(o)}catch{}}},O_=(t,e,n,i,o)=>{let c=new Qu(t.file,{fd:i,start:n});e.pipe(c),N_(e,o)},L_=(t,e)=>{e=Array.from(e);let n=new no(t),i=(o,c,d)=>{let u=(S,y)=>{S?rt.close(o,v=>d(S)):d(null,y)},f=0;if(c===0)return u(null,0);let x=0,g=Buffer.alloc(512),w=(S,y)=>{if(S||y===void 0)return u(S);if(x+=y,x<512&&y)return rt.read(o,g,x,g.length-x,f+x,w);if(f===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let v=new Hn(g);if(!v.cksumValid)return u(null,f);let I=512*Math.ceil((v.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,rt.read(o,g,0,512,f,w)};rt.read(o,g,0,512,f,w)};return new Promise((o,c)=>{n.on("error",c);let d="r+",u=(f,x)=>{if(f&&f.code==="ENOENT"&&d==="r+")return d="w+",rt.open(t.file,d,u);if(f||!x)return c(f);rt.fstat(x,(g,w)=>{if(g)return rt.close(x,()=>c(g));i(x,w.size,(S,y)=>{if(S)return c(S);let v=new Xs(t.file,{fd:x,start:y});n.pipe(v),v.on("error",c),v.on("close",o),M_(n,e)})})};rt.open(t.file,d,u)})},N_=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Ar({file:Df.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},M_=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Ar({file:Df.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n);t.end()},_i=Ri(D_,L_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!rw(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=Ri(_i.syncFile,_i.asyncFile,_i.syncNoFile,_i.asyncNoFile,(t,e=[])=>{_i.validate?.(t,e),B_(t)}),B_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(n,i)=>e(n,i)&&!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0)):(n,i)=>!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0))};cn();var lt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete",PUBLISH_SKILL:"_agent/publishSkill"};function so(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Of(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function oo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Lf(t){let e=t?.permissionMode;if(typeof e!="string")return;let n=e.trim();return n===""?void 0:n}function Nf(t){let{_meta:e,...n}=t;return{stripped:n,meta:e}}function Kn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();He();te();De();He();function kr(t,e){if(so(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Pi(t){return t.startsWith("http://")||t.startsWith("https://")}function Tr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as Gk}from"node:fs";import{dirname as qk,join as Hk}from"node:path";import{fileURLToPath as Kk}from"node:url";var Rt="0.2.3-alpha.102";He();te();var ao="1008033",zf="1289";var Uf="pbbp2",Gf="https://www.coze.cn",jf="/api/coze_claw/resource/get_frontier_key",W_="https://www.coze.cn",K_="wss://frontier.coze.cn";function Cr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??W_}function qf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??K_}function En(t){let e={},n=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return n&&(e["x-tt-env"]=n),i&&(e["x-use-ppe"]=i),e}function Oi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Di=G("handshake");async function Uc(t){let e=Cr(t.endpoint),n=t.timeoutMs??1e4,i=`${Tr(e)}${jf}?aid=${encodeURIComponent(ao)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...En(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),n);Di.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),f=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${v.slice(0,200)}`)}let g=await u.json();if(g.code!==void 0&&g.code!==0)throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${g.code} msg=${g.msg??"-"} logid=${f}`);let w=g.data??{},S=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,y=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!S||!y){let v=JSON.stringify(g).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${v}`)}return Di.info("handshake ok",{remoteDeviceId:y,logid:f,traceId:x}),{accessKey:S,deviceId:y}}catch(u){if(u instanceof k)throw Di.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Di.warn("handshake timeout",{base:e,timeoutMs:n}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${n}ms)`,{cause:u});let f=u.cause;throw Di.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new k("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var jc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Pt="auto",Gc=15e4,Hf=8192;function Kf(t){return{model:qc(t.model)??Pt,...t.modelToken?{modelToken:t.modelToken}:{}}}function $f(t){return!t||t===Pt}var $_=new Set(["auto","\u81EA\u52A8"]);function qc(t){let e=t?.trim();if(e)return $_.has(e.toLowerCase())?Pt:e}function Vf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=jc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let n=t.model||Pt;e.ANTHROPIC_MODEL=n,e.ANTHROPIC_SMALL_FAST_MODEL=n,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=n,e.ANTHROPIC_DEFAULT_OPUS_MODEL=n,e.ANTHROPIC_DEFAULT_SONNET_MODEL=n,e.CLAUDE_CODE_SUBAGENT_MODEL=n,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow)),t.modelInfo?.maxOutput&&(e.CLAUDE_CODE_MAX_OUTPUT_TOKENS=String(t.modelInfo.maxOutput))}else $f(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Jf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Pt}"`):$f(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="${jc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let n=t.modelInfo?.contextWindow??Gc;e.push("-c",`model_context_window=${n}`)}return e}function Yf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Hc(t,e){let{ttEnv:n,usePpe:i}=Oi(t),o={};return n&&(o["x-tt-env"]=n),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Zf(t,e,n){if(!t.modelToken)return{};let i=Hc(e,n);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
+
`)}}function Wc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Kc(t){return t.model||Pt}function Wf(t,e,n,i){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:n,maxTokens:i,api:"openai-completions"}}function Xf(t,e,n,i){if(!t.modelToken)return null;let o=Kc(t),c=Hc(e,n),d=["text"];t.modelInfo?.capabilities?.image===!0&&d.push("image");let u=[Wf(o,d,t.modelInfo?.contextWindow??Gc,t.modelInfo?.maxOutput??Hf)],f=new Set([o]);for(let g of i??[])!g||f.has(g)||(f.add(g),u.push(Wf(g,["text"],Gc,Hf)));let x={baseUrl:`${jc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:u};return Object.keys(c).length>0&&(x.headers=c),x}function Qf(t,e,n){if(!t.modelToken)return[];let i=Hc(e,n),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var fe=G("agent-handlers"),e0=5*1024*1024,X_=1,Q_=6,ey=new Set(["node_modules",".git",".coze","dist","build",".next"]),ty=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,ny=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,ry=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function iy(t){let e=t?.trim();return e?ry.test(e)||ny.test(e)?e:(fe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function sy(t){return new Promise((e,n)=>{let i=et("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=d=>{o||(o=!0,d?n(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",d=>c(d))})}var lo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let n=Kn(e._meta),i=await this.loadAgentCfg(n),o=i?.workspace??$e(n).workspace,c=i?.skills??[],d=[],u=new Set;for(let f of c){let x=ge(o,f.relPath,"SKILL.md");await r0(x).then(w=>w.isFile()).catch(()=>!1)&&(d.push(uy(f)),u.add(f.relPath))}if(e.scanLocal){let f=i?.framework??"claude-code",x=await ay(n,o,f),g=await cy(n,f);for(let w of[...x,...g])u.has(w.relPath)||(u.add(w.relPath),d.push(w.skill))}return{skills:d}}async addSkills(e){e._meta;let n=Kn(e._meta),i=await this.requireAgentCfg(n),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((f,x)=>[f.skillId,x])),u=[];for(let f of o){let x=await uo({agentId:n,workspace:i.workspace,framework:i.framework,skill:f});fo(c,d,x),u.push(f)}return await ii(n,c),this.reloadAgentSessions(n,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let n=Kn(e._meta),i=await this.requireAgentCfg(n),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let f=ge(i.workspace,u.relPath);await Jc(f,{recursive:!0,force:!0}),fe.info("skill removed",{agentId:n,skillId:u.skillId,relPath:u.relPath})}return await ii(n,d),this.reloadAgentSessions(n,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let n=Kn(e._meta);if(!e.skillName)throw new k("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");fe.info("_agent/publishSkill start",{agentId:n,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(n),o=i?.workspace??$e(n).workspace,c=i?.framework??"claude-code",d=e.isGlobal??!1,u=a0(e.skillName),f=await oy(o,c,u,d);if(!f){let P=d?"global":"workspace";throw new k("SKILL_NOT_FOUND",`skill not found in ${P}: ${e.skillName} (${u})`)}let{absDir:x,relPath:g}=f,w=ge(x,"SKILL.md"),S=new ed.default;S.addLocalFolder(x,u);let y=S.toBuffer();if(y.length>t0)throw new k("SKILL_ZIP_TOO_LARGE",`skill zip ${y.length} bytes exceeds limit ${t0}`);let v=await co(w,{encoding:"utf8"}).then(P=>l0(P).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:y,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:n,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):fe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:n,skillName:e.skillName});let A=I.version??"v1.0",T=I.skillId??e.skillId??d0(n,g);if(i&&!d){let P=i.skills??[],b=P.find(C=>C.relPath===g);b?(b.version=A,b.skillId=T):P.push({skillId:T,skillName:e.skillName,relPath:g,version:A,installedAt:Date.now(),...v?{description:v}:{}}),await ii(n,P)}return fe.info("skill published",{agentId:n,skillName:e.skillName,relPath:g,zipBytes:y.length,skillId:T,version:A}),{ok:!0,skillId:T,version:A}}reloadAgentSessionsPublic(e,n){this.reloadAgentSessions(e,n)}reloadAgentSessions(e,n){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,fe.info("downstream busy, scheduling reload after turn",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=c.downstream;c.downstream=void 0,fe.info("killing downstream for workspace reload (idle)",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(n).catch(x=>fe.warn("downstream stop failed during reload (ignored)",{reason:n,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let n=this.opts.isRuntimePendingPermission;return!n||!e.downstream?!1:n(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return fe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let n=e.agentId,i=await ke(n);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);if(i.cozeIdentity===e.cozeIdentity)return fe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:n}),{ok:!0};try{await lr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw fe.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:n,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${n}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Me(i),fe.info("_agent/update: cozeIdentity rewritten",{agentId:n,framework:i.framework}),this.reloadAgentSessions(n,"identity-changed"),{ok:!0}}async upgradeBridge(e){let n=e.agentId||e._meta?.cozeAgentId;if(!n)throw new k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await ke(n))throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);let o=["-y"];e.registry&&Pi(e.registry)&&o.push(`--registry=${e.registry}`);let c=iy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&ty.test(d)&&o.push("--env",d);let u=await sy(o);return fe.info("_agent/upgrade: spawned bridge upgrade process",{agentId:n,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let n=e.agentId;if(!n)throw new k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await ke(n);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Me(i),fe.info("agent disconnected",{agentId:n,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(n,e.reason??"disconnect"),{ok:!0}):(fe.warn("_agent/disconnect: agent not found, ignoring",{agentId:n}),{ok:!0})}async deleteAgent(e){let n=e.agentId;if(!n)throw new k("IPC_BAD_REQUEST",`${lt.DELETE}: missing agentId`);let i=await ke(n),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(n,e.reason??"delete");let d=$e(n);return c==="cloud"?await Jc(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Me(i)),fe.info("agent deleted",{agentId:n,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(kr(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let n=qc(e.model)??Pt,i=await ke(e.agentId);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=n,e.modelInfo&&(i.modelInfo=e.modelInfo),await Me(i),fe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:n,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return fe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=n,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>fe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,f]of o.allSessionQueues())d.push(f.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${n}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(d),fe.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:n,cloudSessions:d.length}),{ok:!0}}async resetAgent(e){if(kr(e._meta,lt.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${lt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,lt.RESET),await this.runDetailSync(e.agentId,lt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,n){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),fe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(n);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await ri(e,o)}async clearPersistedAcpSessionIds(e){let n=await ke(e).catch(()=>null);if(!n?.sessions)return;let i=!1;for(let o of Object.values(n.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Me(n)}async repairAgent(e){if(kr(e._meta,lt.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${lt.REPAIR}: missing agentId`);let n=await this.loadAgentCfg(e.agentId);if(n&&n.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${lt.REPAIR} only allowed for openclaw, got ${n.framework}`);if(n&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,n.workspace)}catch(i){fe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,lt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,n,i){if(!this.opts.detailSyncer){fe.warn("detailSyncer not wired, skipping sync",{method:n,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){fe.warn("detail sync failed (ignored)",{method:n,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){kr(e._meta,"_agent/getFileTree");let n=e._meta,i=Kn(n),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await $c(d).catch(()=>null);if(!u)throw new k("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ni(d,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=vy(e.depth);return u.isDirectory()?{tree:await Ey(o,d,c,f)}:{tree:[{name:Sy(c),path:x0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){kr(e._meta,"_agent/getFileContent");let n=Kn(e._meta),i=await this.resolveWorkspace(n);if(!e.filePath)throw new k("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await $c(o).catch(()=>null);if(!c||!c.isFile())throw new k("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ni(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>e0)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${e0})`);let d=await co(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let n=this.opts.agents.get(e);return n?n.workspace:(await ke(e).catch(()=>null))?.workspace??$e(e).workspace}safeJoin(e,n){let i=Zc(e,n||"."),o=Qc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${i0}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return i}loadAgentCfg(e){return ke(e)}async requireAgentCfg(e){let n=await this.loadAgentCfg(e);if(!n)throw new k("AGENT_NOT_FOUND",`no config for agent: ${e}`);return n}};function a0(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new k("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new k("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function td(t){return t==="claude-code"?ge(".claude","skills"):ge(".agents","skills")}function c0(t){let e=J_();return t==="claude-code"?[ge(e,".claude","skills")]:t==="codex"?[ge(e,".agents","skills"),ge(e,".codex","skills")]:[ge(e,".agents","skills"),ge(e,".openclaw","skills")]}async function oy(t,e,n,i){let o=async c=>r0(ge(c,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let c=ge(td(e),n),d=ge(t,c);return await o(d)?{absDir:d,relPath:c}:null}for(let c of c0(e)){let d=ge(c,n);if(await o(d))return{absDir:d,relPath:d}}return null}function d0(t,e){return(V_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function l0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
93
93
|
---`,3);if(e<0)return{};let n=t.slice(3,e),i={};for(let o of n.split(`
|
|
94
|
-
`)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let l=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[l]=u)}return i}async function d0(t,e,n,i){let o=await t0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let l of o){if(!l.isDirectory())continue;let u=l.name,h=me(n,u),x=me(e,u,"SKILL.md"),m=await lo(x,{encoding:"utf8"}).catch(()=>null);if(m===null)continue;let w=l0(m);c.push({relPath:h,skill:{skillId:c0(t,h),skillName:w.name||u,...w.description?{description:w.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function oy(t,e,n){let i=tl(n);return d0(t,me(e,i),i,!1)}async function ay(t,e){let n=[],i=new Set;for(let o of a0(e)){let c=await d0(t,o,o,!0);for(let l of c)i.has(l.relPath)||(i.add(l.relPath),n.push(l))}return n}var cy=3e4,ly=50*1024*1024,e0=10*1024*1024,Cr=3e4;async function fo(t){let{agentId:e,workspace:n,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=o0(o.skillName),h=tl(i),x=me(h,u),m=me(n,x);if(await Vc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Li(S.length),await Jc(me(m,"SKILL.md"),S,"utf8")}else{let S=await fy(o.downloadUrl);xy(S)?await wy(S,m):py(S)?await gy(S,m):await Jc(me(m,"SKILL.md"),S.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return he.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),w}function ho(t,e,n){let i=e.get(n.skillId);if(i!==void 0){t[i]=n;return}e.set(n.skillId,t.length),t.push(n)}function dy(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function uy(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function u0(t,e){let n=await ke(t,e);if(!n)return{status:"skipped",count:0};if(n.disconnectedAt)return{status:"skipped",count:0};let i=Pt,o=n.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return n.skillsRefreshedForVersion=i,await Be(n,e),{status:"seeded",count:0};let c=[...n.skills??[]],l=new Map(c.map((m,w)=>[m.skillId,w])),u=c.filter(m=>m.builtin===!0&&!!m.downloadUrl);if(u.length===0)return n.skillsRefreshedForVersion=i,await Be(n,e),{status:"noop",count:0};let h=0,x=0;for(let m of u)try{await Zc(me(n.workspace,m.relPath),{recursive:!0,force:!0});let w=await fo({agentId:t,workspace:n.workspace,framework:n.framework,skill:uy(m)});ho(c,l,w),h+=1}catch(w){x+=1,he.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:m.skillId,skillName:m.skillName,err:String(w)})}return n.skills=c,x===0&&(n.skillsRefreshedForVersion=i),await Be(n,e),he.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:h,failed:x}),{status:"refreshed",count:h}}async function fy(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Li(e);let n=hy(t);return Li(n.length),n}if(t.startsWith("file:")){let e=new URL(t).pathname,n=await lo(e);return Li(n.length),n}if(Pi(t)){let e=new AbortController,n=setTimeout(()=>e.abort(),cy);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Li(o.byteLength),Buffer.from(o)}finally{clearTimeout(n)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Li(t){if(t>ly)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function hy(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let n=!!e[2],i=e[3]??"";return n?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function xy(t){return t.length>=2&&t[0]===31&&t[1]===139}function py(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],n=t[3];return e===3&&n===4||e===5&&n===6}function Xc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function gy(t,e){let n,i;try{n=new el.default(t),i=n.getEntries()}catch(l){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Xc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=l.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=my(i),c=Yc(e);for(let l of i){if(Xc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=Yc(e,u),x=Qc(c,h);if(x.startsWith("..")||x==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Vc(h,{recursive:!0});continue}await Vc(Z_(h),{recursive:!0});let m;try{m=l.getData()}catch(w){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${w.message}`,{cause:w})}await Jc(h,m)}}function my(t){let e;for(let n of t){let i=n.entryName;if(!i||Xc(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 wy(t,e){await _y(t);let n=Cf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${Cr}ms)`))},Cr);try{await s0(i0.from(t),n)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${Cr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function _y(t){let e=[],n=Ar({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${Cr}ms)`))},Cr);try{await s0(i0.from(t),n)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${Cr}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var yy=5e3;async function by(t,e,n,i){return f0(t,e,n,i,{count:0})}async function f0(t,e,n,i,o){if(i<=0)return[];let c;try{c=await t0(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(Q_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=yy){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=me(e,u.name),x=J_(me(n,u.name)),m=null;try{m=await $c(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let w={name:u.name,path:h0(Qc(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(w.children=await f0(t,h,x,i-1,o)),l.push(w)}return l.sort((u,h)=>u.isDir!==h.isDir?u.isDir?-1:1:u.name.localeCompare(h.name)),l}function Ey(t){return!t||t<=0?Y_:Math.min(t,X_)}function vy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function h0(t){return t.split(r0).join("/")}te();var vn=q("agent-health-reporter"),Sy=1e4,Iy=3,Ni=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Sy,this.livenessFailureThreshold=e.livenessFailureThreshold??Iy}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),vn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),vn.info("heartbeat stopped"))}async tick(){if(this.inFlight){vn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,vn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let n=[];for(let l of this.opts.core.agents.values()){let u=Ay(l);if(!u)continue;let h={agentId:l.agentId,status:u};l.patToken&&(h.patToken=l.patToken),l.accountId&&(h.accountId=l.accountId),n.push(h)}if(n.length===0){this.consecutiveFailures=0;return}let i={agents:n,bridgeVersion:Pt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(l){this.consecutiveFailures+=1,vn.warn("heartbeat batch send failed",{count:n.length,consecutiveFailures:this.consecutiveFailures,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(vn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){vn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(n){vn.warn("onTickEnd hook failed",{err:String(n)})}}};function Ay(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}cn();import{mkdir as al,rm as mb,stat as wb}from"node:fs/promises";import{homedir as _b}from"node:os";import{join as q0}from"node:path";sn();import{existsSync as zy}from"node:fs";import{release as Uy}from"node:os";import{basename as Gy,isAbsolute as qy}from"node:path";function Mi(t,e,n){return n===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:n}}function Pr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Dr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Sn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var xo=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},J={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function x0(t){return"method"in t&&"id"in t&&t.id!==void 0}function p0(t){return"method"in t&&!("id"in t)}function po(t){return!("method"in t)&&"id"in t}var Ty={AGENT_NOT_FOUND:J.AGENT_NOT_FOUND,AGENT_BUSY:J.AGENT_BUSY,AGENT_DISCONNECTED:J.AGENT_DISCONNECTED,AGENT_TIMEOUT:J.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:J.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:J.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:J.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:J.INTERNAL_ERROR,BRIDGE_INTERNAL:J.INTERNAL_ERROR,IPC_AUTH_FAILED:J.INTERNAL_ERROR,IPC_BAD_REQUEST:J.INVALID_REQUEST,METHOD_NOT_FOUND:J.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:J.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:J.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:J.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:J.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:J.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:J.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:J.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:J.FILE_TOO_LARGE,UNSUPPORTED_MIME:J.UNSUPPORTED_MIME,UPLOAD_FAILED:J.UPLOAD_FAILED,UPSTREAM_NOT_READY:J.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:J.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:J.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:J.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:J.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:J.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:J.SKILL_ZIP_TOO_LARGE};function ky(t){if(t!=null)return t instanceof Error?{name:t.name,message:Bi(t.message)}:typeof t=="string"?Bi(t):typeof t=="object"?Cy(t):t}var Ry=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Bi(t){let e=t;for(let[n,i]of Ry)e=e.replace(n,i);return e}function Cy(t){let e={};for(let[n,i]of Object.entries(t))typeof i=="string"?e[n]=Bi(i):e[n]=i;return e}function Fi(t){if(t instanceof T){let e=ky(t.cause),n={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(n.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(n.reason=e.reason),{code:Ty[t.code]??J.INTERNAL_ERROR,message:Bi(t.message),data:n}}return{code:J.INTERNAL_ERROR,message:Bi(t instanceof Error?t.message:String(t))}}function g0(t){let e=t.data,n=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new T(n,o,{retriable:e?.retriable??!1,cause:c})}function w0(t){return`${JSON.stringify(t)}
|
|
95
|
-
`}var
|
|
96
|
-
`);this.buffer=n.pop()??"";let i=[];for(let o of n){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(
|
|
97
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function A0(t,e){if(t.length===0)return;let n=e?.killFn??Ui,i=e?.isAliveFn??zi,o=e?.sleepFn??(u=>new Promise(h=>setTimeout(h,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)n(u,"SIGTERM");for(let u=0;u<c&&t.some(h=>i(h));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&n(u,"SIGKILL")}var Fy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function T0(t,e){if(!e)return null;for(let n of Fy)if(!(n.frameworks&&!n.frameworks.includes(t))&&n.match.test(e))return{bridgeCode:n.bridgeCode,reason:n.reason,message:n.message};return null}function k0(t,e){return T0(t,e)}function R0(t,e){return T0(t,e)}function Nr(t,e,n){return!e&&n.firstUpdateMs>0&&t<n.firstUpdateMs?Math.max(1,n.firstUpdateMs-t):t<n.phase2GateMs?Math.max(1,n.phase2GateMs-t):Math.max(1,n.livenessWindowMs)}function C0(t,e,n){let o=n-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,m=n-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Nr(m,t.firstFrameSeen,e)}}let c=n-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Nr(c,!0,e)}:n-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Nr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Nr(c,!1,e)}}var P0=$e("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Hy=200,jy=40,Wy=$e("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Ky=$e("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),$y=$e("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Vy=$e("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Zy=$e("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Jy=$e("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),D0=500;function Yy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=D0?t:`${e.slice(0,D0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Xy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:n}=t;if(typeof n=="string")e.push(n);else if(n&&typeof n=="object")try{e.push(JSON.stringify(n))}catch{}return e.join(" ")}function O0(t){try{return zy(t)}catch{return}}function Qy(t,e){return{platform:process.platform,osRelease:Uy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:qy(e.command)?O0(e.command):void 0,cwd:e.cwd,cwdExists:O0(e.cwd),envKeys:e.envKeys}}function eb(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=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new go({onError:n=>this.log.warn("decode line failed",{line:n.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Or;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",n=b0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:n,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,E0(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>Hy&&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,v0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=Qy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(n).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new T("AGENT_SPAWN_FAILED",eb(c,l),{cause:l}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let n=this.child,i=new Promise(c=>n.once("exit",()=>c()));Ui(n.pid,"SIGTERM");let o=setTimeout(()=>{n.killed||Ui(n.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,n){let i={firstUpdateMs:Zy,phase2GateMs:Wy,livenessWindowMs:Ky,absoluteMaxMs:$y,approvalMaxMs:Jy,suspendThresholdMs:Vy,...n};return this.call("session/prompt",e,P0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Pr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Dr(e,n))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Sn(e,n))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,n,i=P0,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Mi(c,e,n),u=(()=>{if(typeof n!="object"||n===null)return;let h=n.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(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Nr(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},I=this.now(),A=C0(v,S.cfg,I),R=D=>{S.armedAt=I,S.expectedIntervalMs=D,m.timer=setTimeout(_,D)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),R(A.rearmMs);return}if(A.action==="continue"){R(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(A.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(l)}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 T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(w0(e),n=>{n&&this.log.warn("stdin write callback err",{err:String(n)})})}dispatch(e){if(po(e)){let n=e.id!==null?this.pending.get(e.id):void 0;if(!n){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),n.timer&&clearTimeout(n.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:n.method,code:e.error.code,message:e.error.message,data:e.error.data}),n.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:n.method}),n.reject(new T("AGENT_PROTOCOL_ERROR",`${n.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:n.method,result:Yy(e.result)}),n.resolve(e.result));return}if(p0(e)){if(e.method==="session/update"){let n=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,n))}for(let i of this.updateHandlers)try{Promise.resolve(i(n)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(x0(e)){let n=e;try{this.handleAgentRequest(n).catch(i=>this.log.error("agent request handler failed (async)",{method:n.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:n.method,err:String(i)})}}}trackToolCall(e,n){let i=n.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(Sn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let n of this.agentRequestHandlers)try{await n(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(Sn(e.id,Fi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let n=g0(e);if(n.code!=="AGENT_PROTOCOL_ERROR")return n;let i=R0(this.framework,Xy(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):n}buildExitError(e,n){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(jy).join(`
|
|
98
|
-
`),o=k0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:n,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${n})`,{cause:{code:e,signal:n,stderrTail:i}})}failAllPending(e){for(let n of this.pending.values())n.timer&&clearTimeout(n.timer),n.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function tb(t){let e={};for(let[n,i]of Object.entries(t))i!==void 0&&(n.startsWith("CLAUDE")||n==="AI_AGENT"||n==="BAGGAGE"||(e[n]=i));return e}var mo=class extends Ot{framework="claude-code";constructor(e){let{command:n,args:i}=ti("claude-code",e.command,e.args??[]),o={command:n,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return tb(e)}};sn();import{mkdtempSync as nb,rmSync as rb}from"node:fs";import{tmpdir as ib}from"node:os";import{join as sb}from"node:path";var wo=class extends Ot{framework="codex";authMethodId;codexHomeDir;constructor(e){let n=e.args??[],i=e.extraArgs?[...n,...e.extraArgs]:n,{command:o,args:c}=ti("codex",e.command,i),l=e.isolateCodexHome?nb(sb(ib(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let n=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),n}async stop(e){if(await super.stop(e),this.codexHomeDir)try{rb(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};We();var ob=3e4,Mr=class extends Ot{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let n=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${n}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=n,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},ob))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var L0=["default","acceptEdits","plan","auto","bypassPermissions"],N0=["read-only","auto","full-access"];function In(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return L0.includes(e);case"codex":return N0.includes(e);case"openclaw":return!1}}function sl(t){switch(t){case"claude-code":return L0.join("/");case"codex":return N0.join("/");case"openclaw":return""}}an();We();te();Oe();function ol(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}sn();var An=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((n,i)=>{this.slots.push({task:e,resolve:n,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let n=await e.task();e.resolve(n)}catch(n){e.reject(n)}}}finally{this.running=!1}}}};var _o=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let n=this.sessionQueues.get(e);return(!n||n.isDisposed)&&(n=new An,this.sessionQueues.set(e,n)),n}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let n=this.sessionQueues.get(e);return!!n&&!n.isDisposed}async dispose(e){this.status="stopped";let n=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(n);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let n=[];for(let[,i]of this.sessions)Gi(i),i.downstream&&(n.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(n),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Gi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Vt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}$t();te();import{constants as M0}from"node:fs";import{access as ab}from"node:fs/promises";import{delimiter as cb,join as lb}from"node:path";var bt=q("framework-detector"),B0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},db=[".exe",".cmd",".bat",".ps1"],$n=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??ab}}async detect(e){let n=B0[e],i=await this.which(n);if(!i)return bt.debug("framework binary not found",{framework:e,bin:n}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(B0).map(async i=>[i,await this.detect(i)])),n={};for(let[i,o]of e)o&&(n[i]=o);return n}async which(e){let n=this.env.pathEnv.split(cb).filter(Boolean),i=this.env.platform==="win32"?["",...db]:[""];for(let o of n)for(let c of i){let l=lb(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let n=this.env.platform==="win32"?M0.F_OK:M0.X_OK;return await this.env.access(e,n),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let n=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!n)return bt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(n.code!==0)return bt.warn("openclaw default agent probe: non-zero exit",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)}),null;let i=n.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return bt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:n.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return bt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(bt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(bt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return bt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let n=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!n)return bt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=n.code===0;i||bt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)});let o={reachable:i},c=n.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){bt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,n=[]){let i=await this.runProbe(e,[...n,"--version"]);return i&&(fb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,n){return new Promise(i=>{let o="",c=!1,l,u=h=>{c||(c=!0,l&&clearTimeout(l),i(h))};try{let h=this.env.spawn(e,n,{stdio:["ignore","pipe","pipe"]});l=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)}})}},ub=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function fb(t){return t.replace(ub,"")}import{homedir as hb}from"node:os";import{join as xb}from"node:path";an();$t();ir();We();te();async function U0(){let t=xb(hb(),".openclaw/openclaw.json");return cr(t)}async function G0(){return(await U0())?.gateway?.auth?.token??""}var F0=q("openclaw.config"),pb=[0,5e3,5e3],gb=$e("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),z0="models.providers.",yo="agents.defaults.models",bo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new An;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??pb,this.cliTimeoutMs=e.cliTimeoutMs??gb}async withRetry(e,n){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await n()}catch(l){i=l,F0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((n,i)=>{let o=nt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=x=>{l||(l=!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?n():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,n){try{await this.runCli(e)}catch(i){let o=String(i);if(n.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,n){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",n])))}catch(i){F0.warn(`${e} failed (best-effort)`,{configPath:n,err:String(i)})}}ensureProvider(e,n){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${z0}${e}`,JSON.stringify(n),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${z0}${e}`)}addModelToAllowlist(e,n){let i={[e]:n?{alias:n}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${yo}[${e}]`,()=>this.runCli(["config","set",yo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${yo}[${e}]`,`${yo}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await U0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let l of Object.keys(i))l.startsWith(o)&&c.push(l.slice(o.length));return c}ensureAgent(e,n,i){let o=["agents","add",e,"--workspace",n,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var de=q("agent-manager"),ll="acceptEdits",W0="full-access",K0="read-only";function yb(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 bb=(t,e,n,i,o,c,l,u,h,x)=>{switch(t){case"claude-code":{let m={...o?{...$f(o),...Jf(o,l,u)}:{},...h??{},IS_SANDBOX:"1"};return new mo({cwd:n,env:m,agentId:i})}case"codex":{let m=o?[...Vf(o),...Xf(o,l,u)]:[],w=W0;x!==void 0&&(In("codex",x)?w=x:de.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let S=[...m,...yb(w)],_={...o?Zf(o):{},...h??{}},v=!!o;return new wo({cwd:n,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(_).length>0?{env:_}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Mr({command:e,cwd:n,agentId:i,...c?{sessionName:ol(c)}:{}})}};function cl(t){return t==="claude-code"||t==="codex"}function Eb(t){let e=[],n=Object.keys(t).sort();for(let i of n){let o=t[i];o!==void 0&&(vb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
94
|
+
`)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function u0(t,e,n,i){let o=await n0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let d of o){if(!d.isDirectory())continue;let u=d.name,f=ge(n,u),x=ge(e,u,"SKILL.md"),g=await co(x,{encoding:"utf8"}).catch(()=>null);if(g===null)continue;let w=l0(g);c.push({relPath:f,skill:{skillId:d0(t,f),skillName:w.name||u,...w.description?{description:w.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function ay(t,e,n){let i=td(n);return u0(t,ge(e,i),i,!1)}async function cy(t,e){let n=[],i=new Set;for(let o of c0(e)){let c=await u0(t,o,o,!0);for(let d of c)i.has(d.relPath)||(i.add(d.relPath),n.push(d))}return n}var dy=3e4,ly=50*1024*1024,t0=10*1024*1024,Rr=3e4;async function uo(t){let{agentId:e,workspace:n,framework:i,skill:o}=t;if(!o.skillName)throw new k("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new k("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=a0(o.skillName),f=td(i),x=ge(f,u),g=ge(n,x);if(await Vc(g,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Li(S.length),await Yc(ge(g,"SKILL.md"),S,"utf8")}else{let S=await hy(o.downloadUrl);py(S)?await _y(S,g):gy(S)?await my(S,g):await Yc(ge(g,"SKILL.md"),S.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return fe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),w}function fo(t,e,n){let i=e.get(n.skillId);if(i!==void 0){t[i]=n;return}e.set(n.skillId,t.length),t.push(n)}function uy(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function fy(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function f0(t,e){let n=await ke(t,e);if(!n)return{status:"skipped",count:0};if(n.disconnectedAt)return{status:"skipped",count:0};let i=Rt,o=n.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return n.skillsRefreshedForVersion=i,await Me(n,e),{status:"seeded",count:0};let c=[...n.skills??[]],d=new Map(c.map((g,w)=>[g.skillId,w])),u=c.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return n.skillsRefreshedForVersion=i,await Me(n,e),{status:"noop",count:0};let f=0,x=0;for(let g of u)try{await Jc(ge(n.workspace,g.relPath),{recursive:!0,force:!0});let w=await uo({agentId:t,workspace:n.workspace,framework:n.framework,skill:fy(g)});fo(c,d,w),f+=1}catch(w){x+=1,fe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(w)})}return n.skills=c,x===0&&(n.skillsRefreshedForVersion=i),await Me(n,e),fe.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:f,failed:x}),{status:"refreshed",count:f}}async function hy(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Li(e);let n=xy(t);return Li(n.length),n}if(t.startsWith("file:")){let e=new URL(t).pathname,n=await co(e);return Li(n.length),n}if(Pi(t)){let e=new AbortController,n=setTimeout(()=>e.abort(),dy);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new k("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Li(o.byteLength),Buffer.from(o)}finally{clearTimeout(n)}}throw new k("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Li(t){if(t>ly)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function xy(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new k("IPC_BAD_REQUEST","bad data URL");let n=!!e[2],i=e[3]??"";return n?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function py(t){return t.length>=2&&t[0]===31&&t[1]===139}function gy(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],n=t[3];return e===3&&n===4||e===5&&n===6}function Xc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function my(t,e){let n,i;try{n=new ed.default(t),i=n.getEntries()}catch(d){throw new k("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||Xc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new k("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new k("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=d.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new k("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=wy(i),c=Zc(e);for(let d of i){if(Xc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=Zc(e,u),x=Qc(c,f);if(x.startsWith("..")||x==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Vc(f,{recursive:!0});continue}await Vc(Y_(f),{recursive:!0});let g;try{g=d.getData()}catch(w){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await Yc(f,g)}}function wy(t){let e;for(let n of t){let i=n.entryName;if(!i||Xc(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 _y(t,e){await yy(t);let n=Pf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Rr}ms)`))},Rr);try{await o0(s0.from(t),n)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Rr}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function yy(t){let e=[],n=Ar({onReadEntry:c=>{let d=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new k("IPC_BAD_REQUEST",`tar list timeout (${Rr}ms)`))},Rr);try{await o0(s0.from(t),n)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Rr}ms)`):new k("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new k("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var by=5e3;async function Ey(t,e,n,i){return h0(t,e,n,i,{count:0})}async function h0(t,e,n,i,o){if(i<=0)return[];let c;try{c=await n0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(ey.has(u.name)||u.isSymbolicLink())continue;if(o.count>=by){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=ge(e,u.name),x=Z_(ge(n,u.name)),g=null;try{g=await $c(f)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let w={name:u.name,path:x0(Qc(t,f)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(w.children=await h0(t,f,x,i-1,o)),d.push(w)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function vy(t){return!t||t<=0?X_:Math.min(t,Q_)}function Sy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function x0(t){return t.split(i0).join("/")}te();var vn=G("agent-health-reporter"),Iy=1e4,Ay=3,Ni=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Iy,this.livenessFailureThreshold=e.livenessFailureThreshold??Ay}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),vn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),vn.info("heartbeat stopped"))}async tick(){if(this.inFlight){vn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,vn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let n=[];for(let d of this.opts.core.agents.values()){let u=ky(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),n.push(f)}if(n.length===0){this.consecutiveFailures=0;return}let i={agents:n,bridgeVersion:Rt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,vn.warn("heartbeat batch send failed",{count:n.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(vn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){vn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(n){vn.warn("onTickEnd hook failed",{err:String(n)})}}};function ky(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}cn();import{mkdir as ad,rm as wb,stat as _b}from"node:fs/promises";import{homedir as yb}from"node:os";import{join as q0}from"node:path";sn();import{existsSync as Uy}from"node:fs";import{release as Gy}from"node:os";import{basename as jy,isAbsolute as qy}from"node:path";function Mi(t,e,n){return n===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:n}}function Pr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Dr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Sn(t,e){return{jsonrpc:"2.0",id:t,error:e}}He();var ho=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},Y={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function p0(t){return"method"in t&&"id"in t&&t.id!==void 0}function g0(t){return"method"in t&&!("id"in t)}function xo(t){return!("method"in t)&&"id"in t}var Ty={AGENT_NOT_FOUND:Y.AGENT_NOT_FOUND,AGENT_BUSY:Y.AGENT_BUSY,AGENT_DISCONNECTED:Y.AGENT_DISCONNECTED,AGENT_TIMEOUT:Y.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Y.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Y.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Y.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Y.INTERNAL_ERROR,BRIDGE_INTERNAL:Y.INTERNAL_ERROR,IPC_AUTH_FAILED:Y.INTERNAL_ERROR,IPC_BAD_REQUEST:Y.INVALID_REQUEST,METHOD_NOT_FOUND:Y.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:Y.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Y.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Y.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:Y.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:Y.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Y.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Y.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Y.FILE_TOO_LARGE,UNSUPPORTED_MIME:Y.UNSUPPORTED_MIME,UPLOAD_FAILED:Y.UPLOAD_FAILED,UPSTREAM_NOT_READY:Y.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Y.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Y.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Y.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Y.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:Y.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:Y.SKILL_ZIP_TOO_LARGE};function Cy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Bi(t.message)}:typeof t=="string"?Bi(t):typeof t=="object"?Py(t):t}var Ry=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Bi(t){let e=t;for(let[n,i]of Ry)e=e.replace(n,i);return e}function Py(t){let e={};for(let[n,i]of Object.entries(t))typeof i=="string"?e[n]=Bi(i):e[n]=i;return e}function Fi(t){if(t instanceof k){let e=Cy(t.cause),n={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(n.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(n.reason=e.reason),{code:Ty[t.code]??Y.INTERNAL_ERROR,message:Bi(t.message),data:n}}return{code:Y.INTERNAL_ERROR,message:Bi(t instanceof Error?t.message:String(t))}}function m0(t){let e=t.data,n=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...u}=e;c=u}return new k(n,o,{retriable:e?.retriable??!1,cause:c})}function _0(t){return`${JSON.stringify(t)}
|
|
95
|
+
`}var w0=10*1024*1024,po=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>w0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${w0} bytes`)}),[]}let n=this.buffer.split(`
|
|
96
|
+
`);this.buffer=n.pop()??"";let i=[];for(let o of n){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(n){return this.onError?.({line:e,error:n}),[]}}};var b0={"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"},P2=Object.fromEntries(Object.entries(b0).map(([t,e])=>[e,t])),Dy={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Or=class{seq=0;next(e,n){this.seq+=1;let i=b0[e]??Oy(e),o=Dy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(f=>y0(n?.[f]??"")),u=Ly(d).join(":");u&&c.push(u)}else n&&Object.values(n).some(d=>d)&&c.push(Object.values(n).filter(Boolean).map(d=>y0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Oy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function y0(t){return t.replace(/[:_\s]+/g,"-")}function Ly(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}an();import{readFileSync as Ny}from"node:fs";var My=384;async function nd(t,e=process.env){let n={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(n[i]=o);await dr(t.agentEnvFile,n,{mode:My})}function rd(t){try{let e=JSON.parse(Ny(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function E0(t,e,n={},i=o=>o){return{...i({...t,...rd(e)}),...n}}Kt();ir();He();te();De();import{execFileSync as By,spawnSync as Fy}from"node:child_process";function zi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Ui(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let n=["/PID",String(t),"/T"];e==="SIGKILL"&&n.push("/F"),Fy("taskkill",n,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var id=new Set;function v0(t){typeof t=="number"&&t>0&&id.add(t)}function S0(t){typeof t=="number"&&id.delete(t)}function I0(){for(let t of id)Ui(t,"SIGKILL")}var Lr="coze-bridge-daemon";function A0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return By("pgrep",["-U",String(o),"-f",Lr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),n;try{n=e()}catch{return[]}let i=process.pid;return n.split(`
|
|
97
|
+
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function k0(t,e){if(t.length===0)return;let n=e?.killFn??Ui,i=e?.isAliveFn??zi,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)n(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&n(u,"SIGKILL")}var zy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function T0(t,e){if(!e)return null;for(let n of zy)if(!(n.frameworks&&!n.frameworks.includes(t))&&n.match.test(e))return{bridgeCode:n.bridgeCode,reason:n.reason,message:n.message};return null}function C0(t,e){return T0(t,e)}function R0(t,e){return T0(t,e)}function Nr(t,e,n){return!e&&n.firstUpdateMs>0&&t<n.firstUpdateMs?Math.max(1,n.firstUpdateMs-t):t<n.phase2GateMs?Math.max(1,n.phase2GateMs-t):Math.max(1,n.livenessWindowMs)}function P0(t,e,n){let o=n-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,g=n-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Nr(g,t.firstFrameSeen,e)}}let c=n-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Nr(c,!0,e)}:n-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Nr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Nr(c,!1,e)}}var D0=Ke("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Hy=200,Wy=40,Ky=Ke("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),$y=Ke("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Vy=Ke("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Jy=Ke("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Yy=Ke("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Zy=Ke("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),O0=500;function Xy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=O0?t:`${e.slice(0,O0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Qy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:n}=t;if(typeof n=="string")e.push(n);else if(n&&typeof n=="object")try{e.push(JSON.stringify(n))}catch{}return e.join(" ")}function L0(t){try{return Uy(t)}catch{return}}function eb(t,e){return{platform:process.platform,osRelease:Gy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:qy(e.command)?L0(e.command):void 0,cwd:e.cwd,cwdExists:L0(e.cwd),envKeys:e.envKeys}}function tb(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${jy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Dt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new po({onError:n=>this.log.warn("decode line failed",{line:n.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Or;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",n=E0(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:n,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,v0(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>Hy&&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,S0(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=eb(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(n).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new k("AGENT_SPAWN_FAILED",tb(c,d),{cause:d}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let n=this.child,i=new Promise(c=>n.once("exit",()=>c()));Ui(n.pid,"SIGTERM");let o=setTimeout(()=>{n.killed||Ui(n.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,n){let i={firstUpdateMs:Yy,phase2GateMs:Ky,livenessWindowMs:$y,absoluteMaxMs:Vy,approvalMaxMs:Zy,suspendThresholdMs:Jy,...n};return this.call("session/prompt",e,D0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Pr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Dr(e,n))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Sn(e,n))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,n,i=D0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Mi(c,e,n),u=(()=>{if(typeof n!="object"||n===null)return;let f=n.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,x)=>{let g={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Nr(0,!1,o),sessionId:u};g.promptTimeout=S;let y=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},I=this.now(),A=P0(v,S.cfg,I),T=P=>{S.armedAt=I,S.expectedIntervalMs=P,g.timer=setTimeout(y,P)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),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,...S.sessionId?{sessionId:S.sessionId}:{}}),x(A.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new k("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(y,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,g);try{this.writeFrame(d)}catch(w){g.timer&&clearTimeout(g.timer),this.pending.delete(c),x(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(_0(e),n=>{n&&this.log.warn("stdin write callback err",{err:String(n)})})}dispatch(e){if(xo(e)){let n=e.id!==null?this.pending.get(e.id):void 0;if(!n){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),n.timer&&clearTimeout(n.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:n.method,code:e.error.code,message:e.error.message,data:e.error.data}),n.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:n.method}),n.reject(new k("AGENT_PROTOCOL_ERROR",`${n.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:n.method,result:Xy(e.result)}),n.resolve(e.result));return}if(g0(e)){if(e.method==="session/update"){let n=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,n))}for(let i of this.updateHandlers)try{Promise.resolve(i(n)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(p0(e)){let n=e;try{this.handleAgentRequest(n).catch(i=>this.log.error("agent request handler failed (async)",{method:n.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:n.method,err:String(i)})}}}trackToolCall(e,n){let i=n.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(Sn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let n of this.agentRequestHandlers)try{await n(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(Sn(e.id,Fi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let n=m0(e);if(n.code!=="AGENT_PROTOCOL_ERROR")return n;let i=R0(this.framework,Qy(e));return i?new k(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):n}buildExitError(e,n){if(this.stopReason!==void 0)return new k("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Wy).join(`
|
|
98
|
+
`),o=C0(this.framework,i);return o?new k(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:n,stderrTail:i}}):new k("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${n})`,{cause:{code:e,signal:n,stderrTail:i}})}failAllPending(e){for(let n of this.pending.values())n.timer&&clearTimeout(n.timer),n.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function nb(t){let e={};for(let[n,i]of Object.entries(t))i!==void 0&&(n.startsWith("CLAUDE")||n==="AI_AGENT"||n==="BAGGAGE"||(e[n]=i));return e}var go=class extends Dt{framework="claude-code";constructor(e){let{command:n,args:i}=ti("claude-code",e.command,e.args??[]),o={command:n,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return nb(e)}};sn();import{mkdtempSync as rb,rmSync as ib}from"node:fs";import{tmpdir as sb}from"node:os";import{join as ob}from"node:path";var mo=class extends Dt{framework="codex";authMethodId;codexHomeDir;constructor(e){let n=e.args??[],i=e.extraArgs?[...n,...e.extraArgs]:n,{command:o,args:c}=ti("codex",e.command,i),d=e.isolateCodexHome?rb(ob(sb(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let n=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),n}async stop(e){if(await super.stop(e),this.codexHomeDir)try{ib(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};He();var ab=3e4,Mr=class extends Dt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let n=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${n}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=n,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},ab))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var N0=["default","acceptEdits","plan","auto","bypassPermissions"],M0=["read-only","auto","full-access"];function In(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return N0.includes(e);case"codex":return M0.includes(e);case"openclaw":return!1}}function sd(t){switch(t){case"claude-code":return N0.join("/");case"codex":return M0.join("/");case"openclaw":return""}}an();He();te();De();function od(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}sn();var An=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((n,i)=>{this.slots.push({task:e,resolve:n,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let n=await e.task();e.resolve(n)}catch(n){e.reject(n)}}}finally{this.running=!1}}}};var wo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let n=this.sessionQueues.get(e);return(!n||n.isDisposed)&&(n=new An,this.sessionQueues.set(e,n)),n}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let n=this.sessionQueues.get(e);return!!n&&!n.isDisposed}async dispose(e){this.status="stopped";let n=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(n);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let n=[];for(let[,i]of this.sessions)Gi(i),i.downstream&&(n.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(n),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Gi(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();te();import{constants as B0}from"node:fs";import{access as cb}from"node:fs/promises";import{delimiter as db,join as lb}from"node:path";var bt=G("framework-detector"),F0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},ub=[".exe",".cmd",".bat",".ps1"],$n=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??et,access:e.access??cb}}async detect(e){let n=F0[e],i=await this.which(n);if(!i)return bt.debug("framework binary not found",{framework:e,bin:n}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(F0).map(async i=>[i,await this.detect(i)])),n={};for(let[i,o]of e)o&&(n[i]=o);return n}async which(e){let n=this.env.pathEnv.split(db).filter(Boolean),i=this.env.platform==="win32"?["",...ub]:[""];for(let o of n)for(let c of i){let d=lb(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let n=this.env.platform==="win32"?B0.F_OK:B0.X_OK;return await this.env.access(e,n),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let n=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!n)return bt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(n.code!==0)return bt.warn("openclaw default agent probe: non-zero exit",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)}),null;let i=n.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return bt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:n.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return bt.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?(bt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(bt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return bt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let n=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!n)return bt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=n.code===0;i||bt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)});let o={reachable:i},c=n.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){bt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,n=[]){let i=await this.runProbe(e,[...n,"--version"]);return i&&(hb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,n){return new Promise(i=>{let o="",c=!1,d,u=f=>{c||(c=!0,d&&clearTimeout(d),i(f))};try{let f=this.env.spawn(e,n,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",x=>{o+=x.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},fb=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function hb(t){return t.replace(fb,"")}import{homedir as xb}from"node:os";import{join as pb}from"node:path";an();Kt();ir();He();te();async function G0(){let t=pb(xb(),".openclaw/openclaw.json");return cr(t)}async function j0(){return(await G0())?.gateway?.auth?.token??""}var z0=G("openclaw.config"),gb=[0,5e3,5e3],mb=Ke("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),U0="models.providers.",_o="agents.defaults.models",yo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new An;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??gb,this.cliTimeoutMs=e.cliTimeoutMs??mb}async withRetry(e,n){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await n()}catch(d){i=d,z0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new k("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((n,i)=>{let o=et(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=x=>{d||(d=!0,clearTimeout(f),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?n():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,n){try{await this.runCli(e)}catch(i){let o=String(i);if(n.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,n){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCliTolerant(["config","unset",n],["Config path not found","Nothing was changed"])))}catch(i){z0.warn(`${e} failed (best-effort)`,{configPath:n,err:String(i)})}}ensureProvider(e,n){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${U0}${e}`,JSON.stringify(n),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${U0}${e}`)}addModelToAllowlist(e,n){let i={[e]:n?{alias:n}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${_o}[${e}]`,()=>this.runCli(["config","set",_o,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${_o}[${e}]`,`${_o}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await G0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let d of Object.keys(i))d.startsWith(o)&&c.push(d.slice(o.length));return c}ensureAgent(e,n,i){let o=["agents","add",e,"--workspace",n,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var de=G("agent-manager"),dd="acceptEdits",K0="full-access",$0="read-only";function bb(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 Eb=(t,e,n,i,o,c,d,u,f,x)=>{switch(t){case"claude-code":{let g={...o?{...Vf(o),...Zf(o,d,u)}:{},...f??{},IS_SANDBOX:"1"};return new go({cwd:n,env:g,agentId:i})}case"codex":{let g=o?[...Jf(o),...Qf(o,d,u)]:[],w=K0;x!==void 0&&(In("codex",x)?w=x:de.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let S=[...g,...bb(w)],y={...o?Yf(o):{},...f??{}},v=!!o;return new mo({cwd:n,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(y).length>0?{env:y}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Mr({command:e,cwd:n,agentId:i,...c?{sessionName:od(c)}:{}})}};function cd(t){return t==="claude-code"||t==="codex"}function vb(t){let e=[],n=Object.keys(t).sort();for(let i of n){let o=t[i];o!==void 0&&(Sb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
99
99
|
`)}
|
|
100
|
-
`}function
|
|
101
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Sb={path:"",version:"cloud-deployed"},H0="openclaw_gateway_unavailable",Ib="openclaw_default_agent_missing";function j0(t){let e=[t.port!==void 0?`port=${t.port}`:"",t.runtime?`runtime=${t.runtime}`:"",t.detail??""].filter(Boolean).join(", ");return`openclaw gateway \u672A\u8FD0\u884C/\u4E0D\u53EF\u8FBE${e?` (${e})`:""}; \u8BF7\u542F\u52A8 openclaw gateway`}var Ab={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Tb=6e4,Eo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??bb,this.createTimeoutMs=e.createTimeoutMs??Tb,this.detectorFactory=e.detectorFactory??(()=>new $n),this.openclawConfigFactory=e.openclawConfigFactory??(n=>new bo({command:n})),this.openclawConfigDir=e.openclawConfigDir??q0(_b(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{de.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,n=q0(e,".env");if(await wb(n).then(c=>c.isFile()).catch(()=>!1)){de.debug("openclaw .env exists, skip bootstrap",{envFile:n});return}let o=Eb({...process.env,...rl(this.paths.agentEnvFile)});await on(n,o,{mode:384}),de.info("openclaw .env bootstrapped",{envFile:n,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),de.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,n){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await ke(e.agentId,this.paths).catch(()=>null),o=oo(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")de.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>de.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")de.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>de.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){de.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await ke(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Be(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){de.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await ke(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Be(R,this.paths))}return de.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ve(e.agentId,this.paths),h=o?"cloud":"local",x=e.framework==="openclaw"&&h==="local",m;x&&!n?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=m??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&cl(e.framework)&&await ar(e.framework,_.signal);let R=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await al(u.root,{recursive:!0}),await al(S,{recursive:!0}),await al(u.logs,{recursive:!0}),R(),x||await dr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(h==="cloud"?await Pa(S,"cloud"):await Pa(S,"local",ll)),R();let D=i,y=Wf({model:e.model??D?.model}),C=Df(e._meta)??D?.accountId,O=e.patToken??D?.patToken,M=h==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(I=new _o({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??Dt,deployType:h,...C?{accountId:C}:{},...O?{patToken:O}:{},...M?{modelInfo:M}:{}}),I.status="ok",D?.sessions){let V=h==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Y,ie]of Object.entries(D.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",de.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Y,framework:e.framework,fallback:oe.permissionMode})):In(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:de.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Y,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&de.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Y,framework:e.framework,deployType:h}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),I.sessions.set(Y,oe)}let ne=Object.keys(D.sessions).length;ne>0&&de.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(I),A=!0;let L={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:y.model};h==="cloud"&&(L.deployType="cloud"),C&&(L.accountId=C),O&&(L.patToken=O),M&&(L.modelInfo=M),D?.skills&&(L.skills=D.skills),D?.agentName&&(L.agentName=D.agentName),D?.description&&(L.description=D.description),L.skillsRefreshedForVersion=D?.skillsRefreshedForVersion??Pt,e.framework==="openclaw"&&h==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):de.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Z=e.initialSkills??[];if(Z.length>0){let V=[...L.skills??[]],ne=new Map(V.map((oe,P)=>[oe.skillId,P])),Y=await Promise.allSettled(Z.map(oe=>fo({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),ie=0;for(let[oe,P]of Y.entries()){let U=Z[oe];U&&(P.status==="fulfilled"?(ho(V,ne,P.value),ie++):de.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(P.reason)}))}ie>0&&(L.skills=V,de.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Z.length}))}return await Be(L,this.paths),de.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:h}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(R){throw de.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await mb(u.root,{recursive:!0,force:!0}).catch(D=>de.warn("rm agent dir failed (ignored)",{err:String(D)})),R instanceof T?R:new T("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,n,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&cl(e.framework))u=Sb;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);cl(e.framework)&&!hs(e.framework)&&(de.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await ar(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:n,...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=Vt(e)?m?.permissionMode??W0:"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(Ab),x}catch(m){let w=x instanceof Ot?x.getStderrTail():[];throw w.length>0&&de.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:w}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,n,i){if(e.framework==="openclaw"&&e.deployType==="local"&&n)try{let o=await this.detectorFactory().probeOpenclawGateway(n);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",j0(o),{cause:{reason:H0}})}catch(o){de.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};de.warn("openclaw default agent stale or missing, attempting lazy re-detect");let n=await this.detectorFactory().detect("openclaw");if(n?.defaultAgent?.id&&n.defaultAgent.workspace)return de.info("openclaw lazy re-detect success",{agentId:n.defaultAgent.id,workspace:n.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=n,{id:n.defaultAgent.id,workspace:n.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:Ib}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let n=await this.detectorFactory().probeOpenclawGateway(e);if(!n.reachable)throw new T("AGENT_ENV_NOT_READY",j0(n),{cause:{reason:H0}})}async buildOpenclawDownstream(e){let{session:n,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,h=ol(o);if(n.deployType==="local"){let w=await this.ensureOpenclawDefaultAgent();return new Mr({command:u,cwd:w.workspace,agentId:w.id,sessionName:h})}let x=await G0(),m;if(i?.modelToken){let w=Wc(o),S=Kc(i),_=`${w}/${S}`;if(!this.ensuredProviders.has(_)){let v=this.getOpenclawConfig(),I=await v.getAllowlistModelsForProvider(w),A=Yf(i,c,l,I);A&&(await v.ensureProvider(w,A),await v.addModelToAllowlist(_),this.ensuredProviders.add(_))}m=_}return new Mr({command:u,cwd:n.workspace,agentId:n.agentId,sessionName:h,...x?{gatewayToken:x}:{},...m?{slashModelOnStart:m}:{}})}async openclawRepair(e,n){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,n)}async cleanupOpenclawSessionProviders(e,n){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=n??e.model;for(let c of e.sessions.keys()){let l=Wc(c),u=`${l}/${o}`,h=!0;try{await i.removeProvider(l)}catch(x){h=!1,de.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:l,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){h=!1,de.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}h&&this.ensuredProviders.delete(u)}}};import{randomUUID as Y0}from"node:crypto";import{promises as Lb}from"node:fs";import{basename as X0}from"node:path";We();te();import{promises as kb}from"node:fs";import{basename as Rb}from"node:path";var $0=q("file-upload"),Cb="/api/coze_claw/file/agent_upload",Pb=6e4;async function V0(t,e={}){let i=`${kr(Rr(e.handshakeBase))}${Cb}`,o=e.timeoutMs??Pb,c=await kb.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);$0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:u,body:l,signal:h.signal}),w=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${w}: ${v.slice(0,200)}`)}let S=await m.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let _=S.data?.file?.file_url;if(!_)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return $0.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Rb(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}We();te();import{extname as Db}from"node:path";var Ob={".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 Z0(t){let e=Db(t).toLowerCase();return Ob[e]??"application/octet-stream"}Oe();var vo=q("agent-send"),J0=50*1024*1024;function Q0(t,e,n){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(n);if(!o)throw new T("AGENT_NOT_FOUND",`session=${n} not active in agent=${e}`);return{session:i,runtime:o}}async function eh(t,e,n,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,n,i,o);return}catch(x){u=x,h<2&&(vo.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function th(t,e){let{session:n,runtime:i}=Q0(e.core,t.agentId,t.sessionId);if(!await ni(t.path,n.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${n.workspace}`);let o=await Lb.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>J0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${J0}`);let c=await Z0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??X0(t.path),u;try{u=await V0({patToken:n.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...n.accountId?{accountId:n.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw vo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof T?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:Y0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:l,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await eh(e,n,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),vo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function nh(t,e){let{session:n,runtime:i}=Q0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??X0(t.path),c={sessionUpdate:"group_file",messageId:Y0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await eh(e,n,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),vo.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 rh(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(n.length,i.length);for(let c=0;c<o;c++){let l=n[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}sn();$t();te();var Lt=q("coze-cli-installer"),ih="@coze/cli@latest",Nb="coze",sh="0.1.8",Mb=5e3,Bb=5e3,Fb=9e4,oh=1e4,qi=null,So=!1;async function ul(t,e={}){if(So)return;if(qi)return qi;let n=e.exec??Bf;return qi=(async()=>{try{let i=await zb(Nb,n),o=!1;if(i){let l=await Ub(n);if(l===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(rh(l,sh))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:sh}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),So=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:ih,mode:c});try{await n("npm",["i","-g","--prefer-online",ih],{timeout:Fb,maxBuffer:10*1024*1024}),Lt.info("coze-cli install ok")}catch(l){Lt.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){So=!0;return}if(t.env)try{await n("coze",["config","set","xTTEnv",t.env],{timeout:oh}),Lt.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Lt.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await n("coze",["auth","login","--token",t.patToken],{timeout:oh}),Lt.info("coze auth login ok")}catch(l){Lt.warn("coze auth login failed",{err:String(l)});return}So=!0}finally{qi=null}})(),qi}async function zb(t,e){let n=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(n,[t],{timeout:Mb});return Ra(i)}catch{return}}async function Ub(t){try{let{stdout:e,stderr:n}=await t("coze",["--version"],{timeout:Bb});return(e||n).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}an();Oe();var Gb=10*6e4;function ah(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Gb:e}function Io(t){return cr(t??Q().configFile)}function Hi(t,e){return lr(e??Q().configFile,t)}import{randomBytes as aE}from"node:crypto";ir();We();te();import{createReadStream as qb}from"node:fs";import{mkdir as Hb,readFile as jb,realpath as Wb,stat as Kb,writeFile as $b}from"node:fs/promises";import{basename as Vb,dirname as fl,isAbsolute as Zb,join as Jb,relative as Yb,resolve as ch,sep as Xb}from"node:path";import{createInterface as Qb}from"node:readline";var dh=q("fs-rpc"),ji=$e("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function uh(t,e){let n=Buffer.byteLength(t.content,"utf8");if(n>ji)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${n} bytes > limit ${ji} bytes`);let i=await hh(t.path,e);return await Hb(fl(i),{recursive:!0}),await $b(i,t.content,"utf8"),dh.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function fh(t,e){let n=await hh(t.path,e),i=await Kb(n),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>ji&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${ji} bytes`);let c;if(o&&i.size>ji)c=await eE(n,t.line??1,t.limit);else{let l=await jb(n,"utf8");if(o){let u=l.split(`
|
|
102
|
-
`),
|
|
103
|
-
`)}else c=
|
|
104
|
-
`)}async function hh(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[n,i]=await Promise.all([lh(ch(e)),lh(ch(t))]),o=Yb(n,i);if(tE(o,Xb,Zb(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function tE(t,e,n){return t===""?!1:n?!0:t===".."||t.startsWith(`..${e}`)}async function lh(t){let e=[],n=t;for(;n!==fl(n);)try{let i=await Wb(n);return e.length?Jb(i,...e.reverse()):i}catch{e.push(Vb(n)),n=fl(n)}return t}te();var xh=q("prompt-multimodal"),ph=10*1024*1024,nE=15e3,rE=6;async function gh(t){let e=new Array(t.length),n=0;async function i(){for(;n<t.length;){let c=n++,l=t[c];l!==void 0&&(e[c]=await iE(l))}}let o=Array.from({length:Math.min(rE,t.length)},()=>i());return await Promise.all(o),e}function mh(t){return t.some(e=>e.type==="image")}async function iE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Pi(e.uri))return t;try{let{buf:n,contentType:i}=await oE(e.uri),o=e.mimeType||sE(i)||"application/octet-stream";return xh.info("image uri fetched and inlined",{uri:e.uri,bytes:n.length,mimeType:o}),{type:"image",data:n.toString("base64"),mimeType:o}}catch(n){return xh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(n)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function sE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function oE(t){let e=new AbortController,n=setTimeout(()=>e.abort(),nE);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new Error(`HTTP ${i.status} ${i.statusText}`);let o=await i.arrayBuffer();if(o.byteLength>ph)throw new Error(`image too large: ${o.byteLength} bytes (max ${ph})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(n)}}cn();We();te();var K=q("core"),cE=3e4,lE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,dE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",uE="\u5BA1\u6279\u5DF2\u8D85\u65F6",fE=3e4,Ao=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Or;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=ah(e.bridgeConfig)}registerExtension(e,n){this.extensions[e]=n}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(n=>n.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let n=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of n)await this.agents.get(i)?.killAllRuntimes("reload");return n}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let n of this.registerHandlers)try{n(e.agentId)}catch(i){K.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&K.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,n,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:n,code:c,signal:l}),Gi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let n of this.pendingUpstream.values())if(n.downstream===e)return!0;return!1}rejectPendingForDownstream(e,n){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){K.info("reject pendingUpstream entries (downstream gone)",{reason:n,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(Sn(o,{code:J.INTERNAL_ERROR,message:`bridge downstream gone: ${n}`})).catch(l=>K.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:J.INTERNAL_ERROR,message:`bridge: ${n}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,n=this.pendingBridge.size;if(!(e===0&&n===0)){K.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:n});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:J.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(po(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let n="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&lE.test(i)?this.currentCozeEnv=i:i&&K.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){n!==null?await this.sendError(n,J.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);n!==null&&await this.upstream.send(Dr(n,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);n!==null&&await this.upstream.send(Dr(n,o));return}if(e.method==="initialize"){n!==null&&await this.upstream.send(Dr(n,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}n!==null?await this.sendError(n,J.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),n!==null&&await this.upstream.send(Sn(n,Fi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let n=e.params,i=n._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof n.sessionId=="string"?n.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,n);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=n._meta?.cozeTriggerMsgId,m=ao(n._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,dE,x,m)}}let l=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,n));return u=!0,h}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,n,i){e.lastActiveAt=Date.now();let{stripped:o}=Lf(i);switch(n){case"session/new":{let c=hE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Vt(e)?Of(i._meta):void 0;if(u!==void 0&&!In(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${sl(e.framework)}`);let h=await this.ensureRuntime(e,l);if(u!==void 0&&h.permissionMode===void 0&&(h.permissionMode=u,await this.persistSessionMapping(e)),h.replySeq=0,await this.ensureDownstream(e,l,h),!h.downstream||!h.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&h.permissionMode!==void 0&&h.permissionMode!==u){let S=h.permissionMode;h.permissionMode=u,await this.persistSessionMapping(e);try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(_){throw h.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(h.acpSessionId,x):e.activeTriggers.delete(h.acpSessionId);let m=ao(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&&mh(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await gh(c.prompt);try{let S=await h.downstream.sessionPrompt({...c,sessionId:h.acpSessionId,prompt:w});return h.lastActiveAt=Date.now(),S}catch(S){if(S instanceof T&&S.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 K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,h,l,uE,I,A)}throw S}finally{if(e.activeTriggers.delete(h.acpSessionId),e.activeGroupIds.delete(h.acpSessionId),h.pendingPermission=void 0,h.reloadAfterTurn){h.reloadAfterTurn=!1;let S=h.downstream;S&&(h.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:h.acpSessionId}),S.stop("reload-after-turn").catch(_=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(_)})))}else h.downstream?.isAlive()&&this.armIdleTimer(e,l,h)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let h=e.getSessionQueue(l);h.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:h.size}),h.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,h=ao(i._meta);if(!l)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Vt(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!In(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${sl(e.framework)}`);if(h)return await this.handleGroupSetMode(e,h,u);let x=e.sessions.get(l)??await this.ensureRuntime(e,l);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 K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:l,modeId:u});return{}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${n}`)}}async handleGroupSetMode(e,n,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===n&&u.permissionMode!==i&&o.push({cloudId:l,runtime:u,oldMode:u.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i,targets:o.length});for(let l of o)l.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let l of o){let u=l.runtime.downstream,h=l.runtime.acpSessionId;u?.isAlive()&&h&&c.push({downstream:u,acpSessionId:h,oldMode:l.oldMode,runtime:l.runtime})}for(let l of c)try{await l.downstream.setSessionMode({sessionId:l.acpSessionId,modeId:i})}catch(u){for(let h of o)h.runtime.permissionMode=h.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,n){let i=e.sessions.get(n);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,n):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Vt(e)&&(c.permissionMode=e.framework==="claude-code"?ll:K0),e.sessions.set(n,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,n){let i={sessionId:n,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(ut.GEN_MODEL_TOKEN,i,fE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${n})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,n,i){if(Gi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${n} spawn failed ${l} 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,n,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:n,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,n,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId})}catch(x){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:n,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),Vt(e)&&i.acpSessionId&&i.permissionMode)try{await h.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){K.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:n,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,n,i){if(Gi(i),this.isRuntimeBusy(e,i)){K.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:n});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:n}),this.armIdleTimer(e,n,i);return}K.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:n});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>K.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:n,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,n){if(n.acpSessionId&&e.activeTriggers.has(n.acpSessionId))return!0;let i=n.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,n,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};if(n.acpSessionId){let l=e.activeTriggers.get(n.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(n.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Pr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,n,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Pr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,n){let i=n.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(gE(n)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=n.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&Vt(e)){let m=l.currentModeId;In(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(w=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof m=="string"&&!In(e.framework,m)&&K.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},h=e.activeTriggers.get(i);h&&(u.cozeTriggerMsgId=h);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Pr("session/update",{...n,sessionId:o,_meta:u})).catch(m=>K.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,n,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,n,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,n,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),n.respondAgentRequestError(i.id,{code:J.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,n,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await uh(c,o);n.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await fh(c,o);n.respondAgentRequest(i.id,l)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),n.respondAgentRequestError(i.id,Fi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let n=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);n&&(n.pendingPermission=void 0)}forwardPermissionRequest(e,n,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,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,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:n,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:n,method:i.method,cloudSessionId:w}),K.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(Mi(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),n.respondAgentRequestError(i.id,{code:J.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let n=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(n){this.pendingUpstream.delete(n.key);let o=n.value;this.clearPendingPermissionFor(o),e.error?(K.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&xE(e.result,o),K.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new xo(e.error)):i.value.resolve(e.result);return}K.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,n,i){let o=e.get(n);if(o)return{value:o,key:n};if(typeof n=="number"){let c=String(n),l=e.get(c);if(l)return K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:n,normalizedId:c}),{value:l,key:c}}}sendRequest(e,n,i=cE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(Mi(o,e,n)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),l(h)})})}async persistSessionMapping(e){if(this.paths)try{let n=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Vt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),n.set(i,c)}await ri(e.agentId,n,this.paths)}catch(n){K.warn("persist session mapping failed",{agentId:e.agentId,err:String(n)})}}reverseSessionId(e,n){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===n)return i}sendError(e,n,i){return this.upstream.send(Sn(e,{code:n,message:i,data:{bridgeVersion:Pt}}))}};function hE(){return aE(16).toString("hex")}function xE(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let n=t;if("kind"in n&&!("outcome"in n)){K.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=n.outcome;if(!i||typeof i!="object"){K.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var pE=["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 gE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let n=e.content;if(!n||typeof n!="object")return!1;let i=n;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return pE.some(c=>o.startsWith(c))}an();te();Oe();import{randomBytes as mE}from"node:crypto";import{createServer as wE}from"node:http";var _E=1e6,wh=q("ipc"),To=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(n=>[`${n.method} ${n.path}`,n])),this.paths=e.paths??Q()}async start(){this.token=mE(32).toString("hex");let e=wE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let n=e.address();if(!n||typeof n!="object")throw new Error("failed to obtain IPC port");return this.port=n.port,await this.persistAuthFiles(),wh.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((n,i)=>{e.close(o=>o?i(o):n())}),this.server=null)}async persistAuthFiles(){await on(this.paths.portFile,String(this.port)),await on(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,n){if(e.headers.authorization!==`Bearer ${this.token}`){Wi(n,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Wi(n,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await yE(e)}catch(u){Wi(n,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Wi(n,200,u??{ok:!0})}catch(u){wh.error("IPC handler failed",{key:o,err:String(u)}),Wi(n,500,{error:u instanceof Error?u.message:String(u)})}}};function Wi(t,e,n){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}async function yE(t){let e=[],n=0;for await(let o of t){let c=o;if(n+=c.length,n>_E)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 Gv=Ut(hx(),1),qv=Ut(Mo(),1),Hv=Ut(zr(),1),jv=Ut(vl(),1),Wv=Ut(Al(),1),Kv=Ut(Dl(),1),vx=Ut(Uo(),1),$v=Ut(Ex(),1);var Sx=vx.default;We();te();var{FWS:lS}=Nx(),Pe=q("upstream.frontier"),Bx="application/json",Fx="none",dS=15e3;function uS(t){class e extends Sx{constructor(i){super(i,zf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Pe.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(vd("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Pe.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Pe.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var es=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Pe.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Uf,...En(this.opts.ppeOverride)},n=uS(e),i=qf(this.opts.urlOverride),o={url:i,ws:n,fpID:Ff,aID:co,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Bx,force:!0},payloadEncoding:{encoding:Fx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new lS(o),l=!1,u=null,h,x,m=new Promise((_,v)=>{h=_,x=v}),w=_=>{l||(l=!0,u&&(clearTimeout(u),u=null),_?x(_):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Pe.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(I=>Pe.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,Pe.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{Pe.warn("frontier error",{code:_.code,msg:_.message}),w(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??dS;u=setTimeout(()=>{w(new T("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){Pe.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let n=this.fws;if(n){this.fws=null,this.opened=!1;try{n.close(1e3,e??"bridge shutdown")}catch(i){Pe.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let n=this.fws,i=e.method;if(!n)throw Pe.warn("frontier send refused: upstream not started",{method:i}),new T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Pe.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:n.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${n.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;zx(c)||Pe.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await n.send(o,{service:33555712,method:1,payloadType:Bx,payloadEncoding:Fx})}catch(u){throw Pe.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let n=this.opts.getPatTokenForAgent;if(!n)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=n(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let n=e.message?.service;if(n!==33555712){Pe.debug("drop non-adapter frontier frame",{service:n});return}let i=xS(e);if(!i){Pe.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Pe.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Pe.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;zx(c)||Pe.info("frontier frame in",{logid:hS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:fS(i)}),Promise.resolve(this.handler(o)).catch(l=>Pe.warn("frontier frame handler threw",{err:String(l)}))}};function zx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Ux=2e3;function fS(t){return t.length<=Ux?t:`${t.slice(0,Ux)}...<truncated, total ${t.length} chars>`}function hS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function xS(t){let e=t.message;if(e?.textPayload)return e.textPayload;let n=e?.payload;if(!n)return null;try{return Buffer.from(n).toString("utf8")}catch{return null}}We();te();var Ml=q("skill-publish"),pS="/api/marketplace/product/skill/publish_with_assets",gS=15e4;async function Gx(t,e={}){let i=`${kr(Rr(e.handshakeBase))}${pS}`,o=e.timeoutMs??gS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let l={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,h=setTimeout(()=>u.abort(),o);Ml.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...l,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let x=await fetch(i,{method:"POST",headers:l,body:c,signal:u.signal}),m=x.headers.get("x-tt-logid")??"";if(!x.ok){let _=await x.text().catch(()=>"");throw new T("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${m}: ${_.slice(0,200)}`)}let w=await x.json();if(Ml.info("skill publish response",{logid:m,httpStatus:x.status,code:w.code,msg:w.msg,dataSkillId:w.data?.skill_id??"",dataVersion:w.data?.version??""}),w.code!==void 0&&w.code!==0)throw new T("UPLOAD_FAILED",`skill publish code=${w.code} msg=${w.msg??"-"} logid=${m}`);let S={};return w.data?.skill_id!==void 0&&w.data.skill_id!==""&&(S.skillId=String(w.data.skill_id)),w.data?.version&&(S.version=w.data.version),Ml.info("skill publish ok",{logid:m,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof T?x:x.name==="AbortError"?new T("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new T("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(h)}}te();var Bl=q("upstream.switchable"),Zo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,n){if(this.inner===e)return;Bl.info("swap upstream",{reason:n});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw Bl.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(n??"swapped").catch(o=>Bl.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};te();var Fl=q("upstream"),Wr=class{handler=null;async start(){Fl.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Fl.info("NoopUpstream stopped",{reason:e})}async send(e){Fl.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};We();te();an();te();Oe();import{promises as mS}from"node:fs";var qx=q("pat-token-store");async function Jo(t=Q()){try{let n=(await mS.readFile(t.patTokenFile,"utf8")).trim();return n.length===0?(qx.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):n}catch(e){let n=e?.code;return n!=="ENOENT"&&qx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:n,message:e.message}),null}}async function ts(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await on(e.patTokenFile,t,{mode:384})}Oe();Oe();import{promises as Yo}from"node:fs";import{join as wS}from"node:path";function _S(t,e){return`#!/bin/sh
|
|
100
|
+
`}function Sb(t){if(t.includes(`
|
|
101
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Ib={path:"",version:"cloud-deployed"},H0="openclaw_gateway_unavailable",Ab="openclaw_default_agent_missing";function W0(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 kb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Tb=6e4,bo=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??Eb,this.createTimeoutMs=e.createTimeoutMs??Tb,this.detectorFactory=e.detectorFactory??(()=>new $n),this.openclawConfigFactory=e.openclawConfigFactory??(n=>new yo({command:n})),this.openclawConfigDir=e.openclawConfigDir??q0(yb(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{de.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,n=q0(e,".env");if(await _b(n).then(c=>c.isFile()).catch(()=>!1)){de.debug("openclaw .env exists, skip bootstrap",{envFile:n});return}let o=vb({...process.env,...rd(this.paths.agentEnvFile)});await on(n,o,{mode:384}),de.info("openclaw .env bootstrapped",{envFile:n,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),de.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,n){if(!e.agentId)throw new k("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new k("IPC_BAD_REQUEST","framework required");let i=await ke(e.agentId,this.paths).catch(()=>null),o=so(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new k("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")de.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(T=>de.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")de.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(T=>de.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){de.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let T=await ke(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Me(T,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){de.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let T=await ke(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Me(T,this.paths))}return de.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=$e(e.agentId,this.paths),f=o?"cloud":"local",x=e.framework==="openclaw"&&f==="local",g;x&&!n?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=g??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&cd(e.framework)&&await ar(e.framework,y.signal);let T=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await ad(u.root,{recursive:!0}),await ad(S,{recursive:!0}),await ad(u.logs,{recursive:!0}),T(),x||await lr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Pa(S,"cloud"):await Pa(S,"local",dd)),T();let P=i,b=Kf({model:e.model??P?.model}),C=Of(e._meta)??P?.accountId,D=e.patToken??P?.patToken,B=f==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(I=new wo({agentId:e.agentId,framework:e.framework,workspace:S,model:b.model??Pt,deployType:f,...C?{accountId:C}:{},...D?{patToken:D}:{},...B?{modelInfo:B}:{}}),I.status="ok",P?.sessions){let $=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(P.sessions)){let se={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?ie.permissionMode===void 0?(se.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",de.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:se.permissionMode})):In(e.framework,ie.permissionMode)?se.permissionMode=ie.permissionMode:de.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&de.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:f}),ie.cozeGroupId&&(se.cozeGroupId=ie.cozeGroupId),I.sessions.set(Z,se)}let ne=Object.keys(P.sessions).length;ne>0&&de.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:b.model};f==="cloud"&&(M.deployType="cloud"),C&&(M.accountId=C),D&&(M.patToken=D),B&&(M.modelInfo=B),P?.skills&&(M.skills=P.skills),P?.agentName&&(M.agentName=P.agentName),P?.description&&(M.description=P.description),M.skillsRefreshedForVersion=P?.skillsRefreshedForVersion??Rt,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):de.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let J=e.initialSkills??[];if(J.length>0){let $=[...M.skills??[]],ne=new Map($.map((se,R)=>[se.skillId,R])),Z=await Promise.allSettled(J.map(se=>uo({agentId:e.agentId,workspace:S,framework:e.framework,skill:se}))),ie=0;for(let[se,R]of Z.entries()){let z=J[se];z&&(R.status==="fulfilled"?(fo($,ne,R.value),ie++):de.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:z.skillId,skillName:z.skillName,err:String(R.reason)}))}ie>0&&(M.skills=$,de.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:J.length}))}return await Me(M,this.paths),de.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(T){throw de.error("agent create failed, rolling back",{agentId:e.agentId,err:String(T)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await wb(u.root,{recursive:!0,force:!0}).catch(P=>de.warn("rm agent dir failed (ignored)",{err:String(P)})),T instanceof k?T:new k("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,n,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&cd(e.framework))u=Ib;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);cd(e.framework)&&!fs(e.framework)&&(de.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await ar(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:n,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let g=e.sessions.get(i),w=$t(e)?g?.permissionMode??K0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv(),w)}try{return await x.start(),await x.initialize(kb),x}catch(g){let w=x instanceof Dt?x.getStderrTail():[];throw w.length>0&&de.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:g instanceof k?g.code:"unknown",recentStderr:w}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,g)}}async resolveSpawnFailure(e,n,i){if(e.framework==="openclaw"&&e.deployType==="local"&&n)try{let o=await this.detectorFactory().probeOpenclawGateway(n);if(!o.reachable)return new k("AGENT_ENV_NOT_READY",W0(o),{cause:{reason:H0}})}catch(o){de.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof k?i:new k("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};de.warn("openclaw default agent stale or missing, attempting lazy re-detect");let n=await this.detectorFactory().detect("openclaw");if(n?.defaultAgent?.id&&n.defaultAgent.workspace)return de.info("openclaw lazy re-detect success",{agentId:n.defaultAgent.id,workspace:n.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=n,{id:n.defaultAgent.id,workspace:n.defaultAgent.workspace};throw new k("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:Ab}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let n=await this.detectorFactory().probeOpenclawGateway(e);if(!n.reachable)throw new k("AGENT_ENV_NOT_READY",W0(n),{cause:{reason:H0}})}async buildOpenclawDownstream(e){let{session:n,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,f=od(o);if(n.deployType==="local"){let w=await this.ensureOpenclawDefaultAgent();return new Mr({command:u,cwd:w.workspace,agentId:w.id,sessionName:f})}let x=await j0(),g;if(i?.modelToken){let w=Wc(o),S=Kc(i),y=`${w}/${S}`;if(!this.ensuredProviders.has(y)){let v=this.getOpenclawConfig(),I=await v.getAllowlistModelsForProvider(w),A=Xf(i,c,d,I);A&&(await v.ensureProvider(w,A),await v.addModelToAllowlist(y),this.ensuredProviders.add(y))}g=y}return new Mr({command:u,cwd:n.workspace,agentId:n.agentId,sessionName:f,...x?{gatewayToken:x}:{},...g?{slashModelOnStart:g}:{}})}async openclawRepair(e,n){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,n)}async cleanupOpenclawSessionProviders(e,n){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=n??e.model;for(let c of e.sessions.keys()){let d=Wc(c),u=`${d}/${o}`,f=!0;try{await i.removeProvider(d)}catch(x){f=!1,de.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){f=!1,de.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}f&&this.ensuredProviders.delete(u)}}};import{randomUUID as X0}from"node:crypto";import{promises as Nb}from"node:fs";import{basename as Q0}from"node:path";He();te();import{promises as Cb}from"node:fs";import{basename as Rb}from"node:path";var V0=G("file-upload"),Pb="/api/coze_claw/file/agent_upload",Db=6e4;async function J0(t,e={}){let i=`${Tr(Cr(e.handshakeBase))}${Pb}`,o=e.timeoutMs??Db,c=await Cb.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);V0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),w=g.headers.get("x-tt-logid")??"";if(!g.ok){let v=await g.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${w}: ${v.slice(0,200)}`)}let S=await g.json();if(S.code!==void 0&&S.code!==0)throw new k("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let y=S.data?.file?.file_url;if(!y)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return V0.info("file upload ok",{uri:y,logid:w}),{uri:y}}catch(g){throw g instanceof k?g:g.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Rb(t.path)}`):new k("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(x)}}He();te();import{extname as Ob}from"node:path";var Lb={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function Y0(t){let e=Ob(t).toLowerCase();return Lb[e]??"application/octet-stream"}De();var Eo=G("agent-send"),Z0=50*1024*1024;function eh(t,e,n){let i=t.get(e);if(!i)throw new k("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new k("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(n);if(!o)throw new k("AGENT_NOT_FOUND",`session=${n} not active in agent=${e}`);return{session:i,runtime:o}}async function th(t,e,n,i,o,c){let u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,n,i,o);return}catch(x){u=x,f<2&&(Eo.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(g=>setTimeout(g,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function nh(t,e){let{session:n,runtime:i}=eh(e.core,t.agentId,t.sessionId);if(!await ni(t.path,n.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${n.workspace}`);let o=await Nb.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new k("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>Z0)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${Z0}`);let c=await Y0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new k("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??Q0(t.path),u;try{u=await J0({patToken:n.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...n.accountId?{accountId:n.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw Eo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof k?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let f={sessionUpdate:"agent_file",messageId:X0(),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 th(e,n,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Eo.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 rh(t,e){let{session:n,runtime:i}=eh(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new k("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??Q0(t.path),c={sessionUpdate:"group_file",messageId:X0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await th(e,n,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),Eo.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 ih(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(n.length,i.length);for(let c=0;c<o;c++){let d=n[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}sn();Kt();te();var Ot=G("coze-cli-installer"),sh="@coze/cli@latest",Mb="coze",oh="0.1.8",Bb=5e3,Fb=5e3,zb=9e4,ah=1e4,ji=null,vo=!1;async function ud(t,e={}){if(vo)return;if(ji)return ji;let n=e.exec??Ff;return ji=(async()=>{try{let i=await Ub(Mb,n),o=!1;if(i){let d=await Gb(n);if(d===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(ih(d,oh))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:oh}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),vo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:sh,mode:c});try{await n("npm",["i","-g","--prefer-online",sh],{timeout:zb,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){vo=!0;return}if(t.env)try{await n("coze",["config","set","xTTEnv",t.env],{timeout:ah}),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 n("coze",["auth","login","--token",t.patToken],{timeout:ah}),Ot.info("coze auth login ok")}catch(d){Ot.warn("coze auth login failed",{err:String(d)});return}vo=!0}finally{ji=null}})(),ji}async function Ub(t,e){let n=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(n,[t],{timeout:Bb});return Ca(i)}catch{return}}async function Gb(t){try{let{stdout:e,stderr:n}=await t("coze",["--version"],{timeout:Fb});return(e||n).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}an();De();var jb=10*6e4;function ch(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?jb:e}function So(t){return cr(t??Q().configFile)}function qi(t,e){return dr(e??Q().configFile,t)}import{randomBytes as cE}from"node:crypto";ir();He();te();import{createReadStream as qb}from"node:fs";import{mkdir as Hb,readFile as Wb,realpath as Kb,stat as $b,writeFile as Vb}from"node:fs/promises";import{basename as Jb,dirname as fd,isAbsolute as Yb,join as Zb,relative as Xb,resolve as dh,sep as Qb}from"node:path";import{createInterface as eE}from"node:readline";var uh=G("fs-rpc"),Hi=Ke("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function fh(t,e){let n=Buffer.byteLength(t.content,"utf8");if(n>Hi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${n} bytes > limit ${Hi} bytes`);let i=await xh(t.path,e);return await Hb(fd(i),{recursive:!0}),await Vb(i,t.content,"utf8"),uh.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function hh(t,e){let n=await xh(t.path,e),i=await $b(n),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Hi&&!o)throw new k("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 tE(n,t.line??1,t.limit);else{let d=await Wb(n,"utf8");if(o){let u=d.split(`
|
|
102
|
+
`),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;c=u.slice(f,x).join(`
|
|
103
|
+
`)}else c=d}return uh.info("fs/read_text_file ok",{path:n,size:c.length}),{content:c}}async function tE(t,e,n){let i=eE({input:qb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof n=="number"?o+n:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let f of i)if(u>=o&&u<c&&d.push(f),u++,u>=c)break}finally{i.close()}return d.join(`
|
|
104
|
+
`)}async function xh(t,e){if(typeof t!="string"||t.length===0)throw new k("IPC_BAD_REQUEST","path must be a non-empty string");let[n,i]=await Promise.all([lh(dh(e)),lh(dh(t))]),o=Xb(n,i);if(nE(o,Qb,Yb(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function nE(t,e,n){return t===""?!1:n?!0:t===".."||t.startsWith(`..${e}`)}async function lh(t){let e=[],n=t;for(;n!==fd(n);)try{let i=await Kb(n);return e.length?Zb(i,...e.reverse()):i}catch{e.push(Jb(n)),n=fd(n)}return t}te();var ph=G("prompt-multimodal"),gh=10*1024*1024,rE=15e3,iE=6;async function mh(t){let e=new Array(t.length),n=0;async function i(){for(;n<t.length;){let c=n++,d=t[c];d!==void 0&&(e[c]=await sE(d))}}let o=Array.from({length:Math.min(iE,t.length)},()=>i());return await Promise.all(o),e}function wh(t){return t.some(e=>e.type==="image")}async function sE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Pi(e.uri))return t;try{let{buf:n,contentType:i}=await aE(e.uri),o=e.mimeType||oE(i)||"application/octet-stream";return ph.info("image uri fetched and inlined",{uri:e.uri,bytes:n.length,mimeType:o}),{type:"image",data:n.toString("base64"),mimeType:o}}catch(n){return ph.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(n)}),{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 aE(t){let e=new AbortController,n=setTimeout(()=>e.abort(),rE);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>gh)throw new Error(`image too large: ${o.byteLength} bytes (max ${gh})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(n)}}cn();He();te();var K=G("core"),dE=3e4,lE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,uE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",fE="\u5BA1\u6279\u5DF2\u8D85\u65F6",hE=3e4,Io=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Or;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=ch(e.bridgeConfig)}registerExtension(e,n){this.extensions[e]=n}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(n=>n.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let n=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of n)await this.agents.get(i)?.killAllRuntimes("reload");return n}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let n of this.registerHandlers)try{n(e.agentId)}catch(i){K.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&K.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,n,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:n,code:c,signal:d}),Gi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let n of this.pendingUpstream.values())if(n.downstream===e)return!0;return!1}rejectPendingForDownstream(e,n){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){K.info("reject pendingUpstream entries (downstream gone)",{reason:n,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(Sn(o,{code:Y.INTERNAL_ERROR,message:`bridge downstream gone: ${n}`})).catch(d=>K.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Y.INTERNAL_ERROR,message:`bridge: ${n}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,n=this.pendingBridge.size;if(!(e===0&&n===0)){K.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:n});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Y.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new k("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(xo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let n="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&lE.test(i)?this.currentCozeEnv=i:i&&K.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){n!==null?await this.sendError(n,Y.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);n!==null&&await this.upstream.send(Dr(n,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);n!==null&&await this.upstream.send(Dr(n,o));return}if(e.method==="initialize"){n!==null&&await this.upstream.send(Dr(n,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}n!==null?await this.sendError(n,Y.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),n!==null&&await this.upstream.send(Sn(n,Fi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let n=e.params,i=n._meta?.cozeAgentId;if(!i)throw new k("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new k("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new k("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof n.sessionId=="string"?n.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,n);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let x=n._meta?.cozeTriggerMsgId,g=oo(n._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,uE,x,g)}}let d=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,n));return u=!0,f}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,n,i){e.lastActiveAt=Date.now();let{stripped:o}=Nf(i);switch(n){case"session/new":{let c=xE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=$t(e)?Lf(i._meta):void 0;if(u!==void 0&&!In(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${sd(e.framework)}`);let f=await this.ensureRuntime(e,d);if(u!==void 0&&f.permissionMode===void 0&&(f.permissionMode=u,await this.persistSessionMapping(e)),f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&f.permissionMode!==void 0&&f.permissionMode!==u){let S=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(y){throw f.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(f.acpSessionId,x):e.activeTriggers.delete(f.acpSessionId);let g=oo(i._meta);if(g?e.activeGroupIds.set(f.acpSessionId,g):e.activeGroupIds.delete(f.acpSessionId),g&&f.cozeGroupId!==g&&(f.cozeGroupId=g,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&wh(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await mh(c.prompt);try{let S=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:w});return f.lastActiveAt=Date.now(),S}catch(S){if(S instanceof k&&S.code==="AGENT_APPROVAL_TIMEOUT"){let y=f.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),f.pendingPermission=void 0);let v=f.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=v?e.activeGroupIds.get(v):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,fE,I,A)}throw S}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let S=f.downstream;S&&(f.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),S.stop("reload-after-turn").catch(y=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(y)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let f=e.getSessionQueue(d);f.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:f.size}),f.dispose(new k("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,f=oo(i._meta);if(!d)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!$t(e))throw e.framework==="openclaw"?new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new k("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!In(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${sd(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let g=x.permissionMode;if(x.permissionMode=u,await this.persistSessionMapping(e),x.downstream?.isAlive()&&x.acpSessionId)try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(w){throw x.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),w}else K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new k("IPC_BAD_REQUEST",`session method not supported: ${n}`)}}async handleGroupSetMode(e,n,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===n&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,f=d.runtime.acpSessionId;u?.isAlive()&&f&&c.push({downstream:u,acpSessionId:f,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let f of o)f.runtime.permissionMode=f.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,n){let i=e.sessions.get(n);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,n):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return $t(e)&&(c.permissionMode=e.framework==="claude-code"?dd:$0),e.sessions.set(n,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,n){let i={sessionId:n,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(lt.GEN_MODEL_TOKEN,i,hE);if(!o?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${n})`);return o.modelToken}catch(o){throw o instanceof k&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new k("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,n,i){if(Gi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new k("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new k("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${n} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{f=await this.sessionSpawner(e,i.modelToken,n,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:n,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,n,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId})}catch(x){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let g=await f.sessionNew({cwd:e.workspace});i.acpSessionId=g.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await f.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),$t(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){K.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:n,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,n,i){if(Gi(i),this.isRuntimeBusy(e,i)){K.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:n});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:n}),this.armIdleTimer(e,n,i);return}K.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:n});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>K.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:n,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,n){if(n.acpSessionId&&e.activeTriggers.has(n.acpSessionId))return!0;let i=n.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,n,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};if(n.acpSessionId){let d=e.activeTriggers.get(n.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(n.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Pr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,n,i,o,c,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};return c&&(u.cozeTriggerMsgId=c),d&&(u.cozeGroupId=d),await this.upstream.send(Pr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,n){let i=n.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(mE(n)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=n.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&$t(e)){let g=d.currentModeId;In(e.framework,g)&&c.permissionMode!==g?(c.permissionMode=g,this.persistSessionMapping(e).catch(w=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof g=="string"&&!In(e.framework,g)&&K.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:g})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Pr("session/update",{...n,sessionId:o,_meta:u})).catch(g=>K.warn("forward update failed",{agentId:e.agentId,err:String(g)}))}handleAgentRequest(e,n,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,n,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,n,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),n.respondAgentRequestError(i.id,{code:Y.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,n,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await fh(c,o);n.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await hh(c,o);n.respondAgentRequest(i.id,d)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),n.respondAgentRequestError(i.id,Fi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let n=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);n&&(n.pendingPermission=void 0)}forwardPermissionRequest(e,n,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,f=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};f&&(x.cozeTriggerMsgId=f);let g=u?e.activeGroupIds.get(u):void 0;g&&(x.cozeGroupId=g);let w=u?this.reverseSessionId(e,u):void 0,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:n,agentRequestId:i.id,upstreamId:o});let y={...c,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:n,method:i.method,cloudSessionId:w}),K.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(Mi(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),n.respondAgentRequestError(i.id,{code:Y.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let n=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(n){this.pendingUpstream.delete(n.key);let o=n.value;this.clearPendingPermissionFor(o),e.error?(K.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&pE(e.result,o),K.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new ho(e.error)):i.value.resolve(e.result);return}K.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,n,i){let o=e.get(n);if(o)return{value:o,key:n};if(typeof n=="number"){let c=String(n),d=e.get(c);if(d)return K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:n,normalizedId:c}),{value:d,key:c}}}sendRequest(e,n,i=dE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Mi(o,e,n)).catch(f=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(f)})})}async persistSessionMapping(e){if(this.paths)try{let n=new Map;for(let[i,o]of e.sessions){let 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),n.set(i,c)}await ri(e.agentId,n,this.paths)}catch(n){K.warn("persist session mapping failed",{agentId:e.agentId,err:String(n)})}}reverseSessionId(e,n){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===n)return i}sendError(e,n,i){return this.upstream.send(Sn(e,{code:n,message:i,data:{bridgeVersion:Rt}}))}};function xE(){return cE(16).toString("hex")}function pE(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let n=t;if("kind"in n&&!("outcome"in n)){K.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=n.outcome;if(!i||typeof i!="object"){K.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var gE=["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 mE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let n=e.content;if(!n||typeof n!="object")return!1;let i=n;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return gE.some(c=>o.startsWith(c))}an();te();De();import{randomBytes as wE}from"node:crypto";import{createServer as _E}from"node:http";var yE=1e6,_h=G("ipc"),Ao=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(n=>[`${n.method} ${n.path}`,n])),this.paths=e.paths??Q()}async start(){this.token=wE(32).toString("hex");let e=_E((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let n=e.address();if(!n||typeof n!="object")throw new Error("failed to obtain IPC port");return this.port=n.port,await this.persistAuthFiles(),_h.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((n,i)=>{e.close(o=>o?i(o):n())}),this.server=null)}async persistAuthFiles(){await on(this.paths.portFile,String(this.port)),await on(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,n){if(e.headers.authorization!==`Bearer ${this.token}`){Wi(n,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Wi(n,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await bE(e)}catch(u){Wi(n,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Wi(n,200,u??{ok:!0})}catch(u){_h.error("IPC handler failed",{key:o,err:String(u)}),Wi(n,500,{error:u instanceof Error?u.message:String(u)})}}};function Wi(t,e,n){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}async function bE(t){let e=[],n=0;for await(let o of t){let c=o;if(n+=c.length,n>yE)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 jv=zt(xx(),1),qv=zt(No(),1),Hv=zt(zr(),1),Wv=zt(vd(),1),Kv=zt(Ad(),1),$v=zt(Dd(),1),Sx=zt(zo(),1),Vv=zt(vx(),1);var Ix=Sx.default;He();te();var{FWS:lS}=Mx(),Re=G("upstream.frontier"),Fx="application/json",zx="none",uS=15e3;function fS(t){class e extends Ix{constructor(i){super(i,Uf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Re.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(Sl("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");Re.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Re.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var es=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Gf,...En(this.opts.ppeOverride)},n=fS(e),i=qf(this.opts.urlOverride),o={url:i,ws:n,fpID:zf,aID:ao,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Fx,force:!0},payloadEncoding:{encoding:zx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new lS(o),d=!1,u=null,f,x,g=new Promise((y,v)=>{f=y,x=v}),w=y=>{d||(d=!0,u&&(clearTimeout(u),u=null),y?x(y):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Re.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&w();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(I=>Re.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=y=>{this.opened=!1,Re.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Re.warn("frontier error",{code:y.code,msg:y.message}),w(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let S=this.opts.openTimeoutMs??uS;u=setTimeout(()=>{w(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await g}catch(y){try{c.close(1e3,"open failed")}catch(v){Re.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let n=this.fws;if(n){this.fws=null,this.opened=!1;try{n.close(1e3,e??"bridge shutdown")}catch(i){Re.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let n=this.fws,i=e.method;if(!n)throw Re.warn("frontier send refused: upstream not started",{method:i}),new k("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Re.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:n.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new k("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${n.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Ux(c)||Re.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await n.send(o,{service:33555712,method:1,payloadType:Fx,payloadEncoding:zx})}catch(u){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new k("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let n=this.opts.getPatTokenForAgent;if(!n)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=n(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let n=e.message?.service;if(n!==33555712){Re.debug("drop non-adapter frontier frame",{service:n});return}let i=pS(e);if(!i){Re.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Re.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Re.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Ux(c)||Re.info("frontier frame in",{logid:xS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:hS(i)}),Promise.resolve(this.handler(o)).catch(d=>Re.warn("frontier frame handler threw",{err:String(d)}))}};function Ux(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Gx=2e3;function hS(t){return t.length<=Gx?t:`${t.slice(0,Gx)}...<truncated, total ${t.length} chars>`}function xS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function pS(t){let e=t.message;if(e?.textPayload)return e.textPayload;let n=e?.payload;if(!n)return null;try{return Buffer.from(n).toString("utf8")}catch{return null}}He();te();var Md=G("skill-publish"),gS="/api/marketplace/product/skill/publish_with_assets",mS=15e4;async function jx(t,e={}){let i=`${Tr(Cr(e.handshakeBase))}${gS}`,o=e.timeoutMs??mS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,f=setTimeout(()=>u.abort(),o);Md.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...d,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let x=await fetch(i,{method:"POST",headers:d,body:c,signal:u.signal}),g=x.headers.get("x-tt-logid")??"";if(!x.ok){let y=await x.text().catch(()=>"");throw new k("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${g}: ${y.slice(0,200)}`)}let w=await x.json();if(Md.info("skill publish response",{logid:g,httpStatus:x.status,code:w.code,msg:w.msg,dataSkillId:w.data?.skill_id??"",dataVersion:w.data?.version??""}),w.code!==void 0&&w.code!==0)throw new k("UPLOAD_FAILED",`skill publish code=${w.code} msg=${w.msg??"-"} logid=${g}`);let S={};return w.data?.skill_id!==void 0&&w.data.skill_id!==""&&(S.skillId=String(w.data.skill_id)),w.data?.version&&(S.version=w.data.version),Md.info("skill publish ok",{logid:g,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof k?x:x.name==="AbortError"?new k("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new k("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(f)}}te();var Bd=G("upstream.switchable"),Vo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,n){if(this.inner===e)return;Bd.info("swap upstream",{reason:n});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw Bd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(n??"swapped").catch(o=>Bd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};te();var Fd=G("upstream"),Wr=class{handler=null;async start(){Fd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Fd.info("NoopUpstream stopped",{reason:e})}async send(e){Fd.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)}};He();te();an();te();De();import{promises as wS}from"node:fs";var qx=G("pat-token-store");async function Jo(t=Q()){try{let n=(await wS.readFile(t.patTokenFile,"utf8")).trim();return n.length===0?(qx.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):n}catch(e){let n=e?.code;return n!=="ENOENT"&&qx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:n,message:e.message}),null}}async function ts(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await on(e.patTokenFile,t,{mode:384})}De();De();import{promises as Yo}from"node:fs";import{join as _S}from"node:path";function yS(t,e){return`#!/bin/sh
|
|
105
105
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
106
|
-
`}function
|
|
106
|
+
`}function bS(t,e){return`@echo off\r
|
|
107
107
|
"${e}" "${t}" %*\r
|
|
108
|
-
`}async function Hx(t,e=Q()){let n=e.binDir;await Yo.mkdir(n,{recursive:!0});let i=
|
|
108
|
+
`}async function Hx(t,e=Q()){let n=e.binDir;await Yo.mkdir(n,{recursive:!0});let i=_S(n,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?bS(t,o):yS(t,o);return await Yo.readFile(i,"utf8").catch(()=>null)===c||(await Yo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Yo.chmod(i,493)),n}te();De();import{execSync as Wx}from"node:child_process";import{readFileSync as Kx,unlinkSync as ES}from"node:fs";import{mkdir as vS,open as SS,readFile as $x,unlink as zd,writeFile as IS}from"node:fs/promises";import{dirname as AS}from"node:path";var kS=G("single-instance"),TS=t=>new Promise(e=>setTimeout(e,t)),Zo=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:n=>zi(n),isDaemon:n=>this.matchesDaemonTitle(n)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let n=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&kS.warn("removing stale pid file",{stalePid:i}),await IS(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return n.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),n}async release(){if(this.acquired){try{(await $x(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await zd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let n=await $x(e,"utf8"),i=Number.parseInt(n.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(n){if(n.code==="ENOENT")return null;throw n}}async withClaimLock(e){let n=`${this.pidFile}.lock`;await vS(AS(n),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await SS(n,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let d=await this.readPidFrom(n);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await TS(this.claimLockIntervalMs);continue}await zd(n).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await zd(n).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${n} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let n=Kx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(n.includes(Lr)||n.includes("lib/index.js"))}catch{}try{let n=Wx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return n.trim()?n.includes(Lr)||n.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Wx(`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{Kx(this.pidFile,"utf8").trim()===String(this.selfPid)&&ES(this.pidFile)}catch{}})}};Xo();te();var Qn=G("daemon.upstream-watchdog"),MS=12e4,BS=9e5,FS=3e4;function Gd(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var Qo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Gd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",MS),this.hardMs=e.hardMs??Gd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",BS),this.intervalMs=e.intervalMs??Gd("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?.(),Qn.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&Qn.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&Qn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Qn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let n=e-this.downSince;if(n>=this.hardMs){Qn.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:n,hardMs:this.hardMs}),this.opts.onFatal(n);return}n>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,Qn.warn("upstream watchdog: forcing reconnect",{downMs:n,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Qn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var j=G("daemon");async function Yx(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){El({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:R=>$e(R,t).logs,listAgentIds:()=>hs(t)});try{let{writeFileSync:R}=await import("node:fs");R(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
|
|
109
109
|
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
110
110
|
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
111
|
-
`)}catch{}}let e=new Xo({processTitle:Lr}),n=await e.acquire();if(n.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${n.pid})`);let i=await Io(),o=i??{};us({pid:process.pid}),H.info(i?"loaded bridge config":"initialized bridge config");let c=new Zo(new Wr),l=null,u=new Ao({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(P,U,j,ee)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(P,U,j,ee)}}),h=new Eo({paths:t,config:o,registry:u});l=h;let x,m,w=null,S={},_,v=null,I=null,A=null,R=new An;function D(P,U){return R.enqueue(()=>C(P,U))}function y(){I||(I=new ea({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?D(A,{force:!0}):void 0,onFatal:P=>{if(process.env[ns]==="1"){H.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:P});return}H.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:P}),process.exit(1)}})),I.start()}async function C(P,U){let j=P,ee=j?.privatecode;if(!ee)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let Xe=Oi(j.env),xe=j.handshake_url,pe=j.frontier_url,vt=Vx(j.env,xe,pe);if(A=j,!U?.force&&x===ee&&m===vt){let _e=await FS(t);return u.agents.size===0&&_e?(H.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),na(t,h).catch(Ae=>H.warn("connect-noop auto-revive error (ignored)",{err:String(Ae)}))):H.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let xt=!!x&&x!==ee,en=m!==void 0&&m!==vt,zt=xt||en,tn=await Uc({privatecode:ee,...xe?{endpoint:xe}:{},ppeOverride:Xe});if(zt){H.warn("connect config switched, resetting agents",{pcChanged:xt,envChanged:en,previousPc:x?ta(x):"",nextPc:ta(ee)});for(let _e of[...u.agents.values()])await _e.dispose("connect config switch").catch(()=>{}),u.agents.delete(_e.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"connect switch").catch(()=>{})}w=tn.deviceId,us({deviceId:w,pid:process.pid}),ul({patToken:ee,env:j.env}).catch(_e=>H.warn("coze-cli setup error (ignored)",{err:String(_e)}));let Jr=new es({handshake:tn,privatecode:ee,...pe?{urlOverride:pe}:{},ppeOverride:Xe,getPatTokenForAgent:_e=>u.agents.get(_e)?.patToken});return await c.swap(Jr,"connect"),x=ee,m=vt,S=Xe,_=xe,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),H.info("mock scenario set",{scenario:j.mock_scenario})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>L.retryPending().catch(_e=>H.warn("detailSync.retryPending failed (ignored)",{err:String(_e)})),onAuthFailures:Z})),v.start(),y(),zt&&na(t,h).catch(_e=>H.warn("post-connect-switch auto-revive error (ignored)",{err:String(_e)})),ts(ee,t).catch(_e=>H.warn("writePatToken after /connect failed (ignored)",{err:String(_e)})),H.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async P=>h.createAgent(P.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},M=new uo({agents:u.agents,publishSkillToMarketplace:async P=>{let U=u.agents.get(P.agentId)?.patToken??x;if(!U)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Gx({patToken:U,zip:P.zip,...P.skillId?{skillId:P.skillId}:{},skillName:P.skillName,...P.description?{description:P.description}:{},agentId:P.agentId,...P.accountId?{accountId:P.accountId}:{}},{handshakeBase:_,ppeOverride:S})},disposeAndMarkDisconnected:async(P,U)=>{let j=u.agents.get(P);if(j){await h.cleanupOpenclawSessionProviders(j).catch(Xe=>H.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(Xe)}));let ee=!0;try{await j.dispose(`disconnect: ${U}`)}catch(Xe){ee=!1,H.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:P,err:String(Xe)}),j.status="error"}ee&&(j.status="disconnected",u.unregister(P),u.disconnectedAgents.add(P))}else u.disconnectedAgents.add(P)},disposeForDelete:async(P,U)=>{let j=u.agents.get(P);j&&(await h.cleanupOpenclawSessionProviders(j).catch(ee=>H.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:P,err:String(ee)})),await j.dispose(`delete: ${U}`).catch(ee=>H.warn("dispose during delete failed (ignored)",{agentId:P,err:String(ee)})),u.unregister(P)),u.disconnectedAgents.delete(P)},detailSyncer:async P=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(P)},cleanupOpenclawProviders:async(P,U)=>{await h.cleanupOpenclawSessionProviders(P,U)},openclawRepair:async(P,U)=>{await h.openclawRepair(P,U)},isRuntimePendingPermission:P=>u.hasPendingPermissionFor(P)});u.registerExtension("_agent/listSkills",P=>M.listSkills(P.params)),u.registerExtension("_agent/addSkills",P=>M.addSkills(P.params)),u.registerExtension("_agent/removeSkills",P=>M.removeSkills(P.params)),u.registerExtension("_agent/publishSkill",P=>M.publishSkill(P.params)),u.registerExtension("_agent/getFileTree",P=>M.getFileTree(P.params)),u.registerExtension("_agent/getFileContent",P=>M.getFileContent(P.params)),u.registerExtension("_agent/update",P=>M.updateAgent(P.params)),u.registerExtension("_agent/disconnect",P=>M.disconnectAgent(P.params)),u.registerExtension("_agent/switchModel",P=>M.switchModel(P.params)),u.registerExtension("_agent/reset",P=>M.resetAgent(P.params)),u.registerExtension("_agent/repair",P=>M.repairAgent(P.params)),u.registerExtension("_agent/delete",P=>M.deleteAgent(P.params)),u.registerExtension("_agent/upgrade",P=>M.upgradeBridge(P.params));let L=new ms({paths:t,handlers:M,agentManager:h,sendDetail:P=>u.sendRequest("_agent/detail",P)});O.ref=L;let Z=async P=>{await Promise.allSettled(P.map(async U=>{try{await M.disconnectAgent({agentId:U.agentId,reason:`auth_failure: code=${U.code} ${U.message}`}),H.info("agent disconnected due to auth failure from heartbeat response",{agentId:U.agentId,code:U.code,message:U.message})}catch(j){H.warn("disconnect during authFailure handling failed (ignored)",{agentId:U.agentId,err:String(j)})}}))};c.onConnect(({initial:P})=>{H.info("frontier upstream connected, triggering detail sync",{initial:P}),L.syncAll(P?"initial-connect":"reconnect").catch(U=>H.warn("detail sync top-level error (ignored)",{err:String(U)}))});let V=new To({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let P=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[ns]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...P?{mockScenario:P}:{}}}},{method:"POST",path:"/pair",handler:async P=>{let U=P,j=U?.privatecode,ee=U?.pairing_code;if(!j||!ee)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Xe=Oi(U.env),xe=U.handshake_url,pe=U.frontier_url,vt=Vx(U.env,xe,pe),xt=!!x&&x!==j,en=m!==void 0&&m!==vt,zt=xt||en,tn=await Uc({privatecode:j,...xe?{endpoint:xe}:{},ppeOverride:Xe});if(zt){H.warn("pair config switched, resetting agents",{pcChanged:xt,envChanged:en,previousPc:x?ta(x):"",nextPc:ta(j),previousEnvKey:m??"",nextEnvKey:vt});for(let Ae of[...u.agents.values()])await Ae.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ae.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"pair switch").catch(()=>{})}w=tn.deviceId,us({deviceId:w,pid:process.pid}),ul({patToken:j,env:U.env}).catch(Ae=>H.warn("coze-cli setup error (ignored)",{err:String(Ae)}));let Jr=new es({handshake:tn,privatecode:j,...pe?{urlOverride:pe}:{},ppeOverride:Xe,getPatTokenForAgent:Ae=>u.agents.get(Ae)?.patToken});await c.swap(Jr,"pair");try{let Ae=new $n;o.frameworksCache=await Ae.detectAll(),await Hi(o),H.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ae){H.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ae)})}let _e=Object.keys(o.frameworksCache??{});try{let Ae=await u.sendRequest("_agent/pair",{pairCode:ee,patToken:j,frameworks:_e,_meta:{cozeDeviceId:w}});H.info("_agent/pair ok",{pairResult:Ae}),x=j,m=vt,S=Xe,_=xe,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),H.info("mock scenario set",{scenario:U.mock_scenario})),ts(j,t).catch(De=>H.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>L.retryPending().catch(De=>H.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:Z})),v.start(),y(),zt&&na(t,h).catch(De=>H.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let er;return U.agent_id&&(er=await US(U.agent_id,t,h,De=>u.sendRequest("_agent/detail",De),j).catch(De=>(H.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(De)}),{ok:!1,agentId:U.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...er?{agent:er}:{}}}catch(Ae){return H.error("_agent/pair failed",{err:String(Ae)}),{ok:!1,note:`pair failed: ${String(Ae)}`}}}},{method:"POST",path:"/connect",handler:P=>D(P)},{method:"POST",path:"/_agent/create",handler:async P=>{let U=P;return{ok:!0,result:await h.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async P=>{let U=P;if(!U?.agentId||!U?.sessionId||!U?.kind||!U?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let j=U;return await(j.groupFile?nh:th)(j,{core:u,patToken:x,handshakeBase:_,ppeOverride:S})}catch(j){if(j instanceof T)return{ok:!1,code:j.code,message:j.message};throw j}}},{method:"POST",path:"/reload",handler:async P=>{let U=P?.agent_id,j=await u.reloadAgents(U);return H.info("IPC /reload: recycled agent subprocesses",{agentId:U??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(H.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:Y}=await V.start();try{await Hx(t.libEntry,t)}catch(P){H.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(P)})}await u.start(),GS({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new $n().detectAll(),await Hi(o),o.frameworksCache)}).catch(P=>H.warn("startup warmup error (ignored)",{err:String(P)})),Pd().then(async()=>{let{probeAcpVersion:P}=await Promise.resolve().then(()=>(sn(),Rd));for(let U of["claude-code","codex"]){let j=await P(U);j&&H.info("acp wrapper version",{framework:U,version:j})}}).catch(P=>H.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(P)}));let ie=null,oe={port:ne,token:Y,core:u,ipc:V,shutdown(P){return ie||(H.info("daemon shutdown",{reason:P}),ie=(async()=>{v?.stop(),I?.stop(),await u.stop(P),await V.stop(),await e.release()})(),ie)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{oe.shutdown(P).then(()=>process.exit(0))});return process.on("exit",()=>S0()),process.on("unhandledRejection",P=>{H.error("unhandledRejection",{reason:P instanceof Error?P.message:String(P),stack:P instanceof Error?P.stack:void 0})}),process.on("uncaughtException",P=>{H.error("uncaughtException (will exit, supervisor will restart)",{message:P.message,stack:P.stack,name:P.name});try{process.stderr.write(`FATAL uncaughtException: ${P.stack??P.message}
|
|
112
|
-
`)}catch{}process.exit(1)}),
|
|
113
|
-
`)){let u=
|
|
114
|
-
`;await is(v,"utf8").catch(()=>null)!==I&&await
|
|
115
|
-
`).filter(
|
|
116
|
-
`)}async function
|
|
117
|
-
`),1;for(let x of
|
|
118
|
-
`);return 0}let o=t.date??Pn(new Date),c=
|
|
111
|
+
`)}catch{}}let e=new Zo({processTitle:Lr}),n=await e.acquire();if(n.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${n.pid})`);let i=await So(),o=i??{};ls({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new Vo(new Wr),d=null,u=new Io({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(R,z,H,ee)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(R,z,H,ee)}}),f=new bo({paths:t,config:o,registry:u});d=f;let x,g,w=null,S={},y,v=null,I=null,A=null,T=new An;function P(R,z){return T.enqueue(()=>C(R,z))}function b(){I||(I=new Qo({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?P(A,{force:!0}):void 0,onFatal:R=>{if(process.env[ns]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:R});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:R}),process.exit(1)}})),I.start()}async function C(R,z){let H=R,ee=H?.privatecode;if(!ee)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Ze=Oi(H.env),he=H.handshake_url,xe=H.frontier_url,vt=Jx(H.env,he,xe);if(A=H,!z?.force&&x===ee&&g===vt){let we=await zS(t);return u.agents.size===0&&we?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ta(t,f).catch(Ie=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ht=!!x&&x!==ee,Qt=g!==void 0&&g!==vt,Ft=ht||Qt,en=await Uc({privatecode:ee,...he?{endpoint:he}:{},ppeOverride:Ze});if(Ft){j.warn("connect config switched, resetting agents",{pcChanged:ht,envChanged:Qt,previousPc:x?ea(x):"",nextPc:ea(ee)});for(let we of[...u.agents.values()])await we.dispose("connect config switch").catch(()=>{}),u.agents.delete(we.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"connect switch").catch(()=>{})}w=en.deviceId,ls({deviceId:w,pid:process.pid}),ud({patToken:ee,env:H.env}).catch(we=>j.warn("coze-cli setup error (ignored)",{err:String(we)}));let Yr=new es({handshake:en,privatecode:ee,...xe?{urlOverride:xe}:{},ppeOverride:Ze,getPatTokenForAgent:we=>u.agents.get(we)?.patToken});return await c.swap(Yr,"connect"),x=ee,g=vt,S=Ze,y=he,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),j.info("mock scenario set",{scenario:H.mock_scenario})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(we=>j.warn("detailSync.retryPending failed (ignored)",{err:String(we)})),onAuthFailures:J})),v.start(),b(),Ft&&ta(t,f).catch(we=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(we)})),ts(ee,t).catch(we=>j.warn("writePatToken after /connect failed (ignored)",{err:String(we)})),j.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async R=>f.createAgent(R.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let D={},B=new lo({agents:u.agents,publishSkillToMarketplace:async R=>{let z=u.agents.get(R.agentId)?.patToken??x;if(!z)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return jx({patToken:z,zip:R.zip,...R.skillId?{skillId:R.skillId}:{},skillName:R.skillName,...R.description?{description:R.description}:{},agentId:R.agentId,...R.accountId?{accountId:R.accountId}:{}},{handshakeBase:y,ppeOverride:S})},disposeAndMarkDisconnected:async(R,z)=>{let H=u.agents.get(R);if(H){await f.cleanupOpenclawSessionProviders(H).catch(Ze=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:R,err:String(Ze)}));let ee=!0;try{await H.dispose(`disconnect: ${z}`)}catch(Ze){ee=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:R,err:String(Ze)}),H.status="error"}ee&&(H.status="disconnected",u.unregister(R),u.disconnectedAgents.add(R))}else u.disconnectedAgents.add(R)},disposeForDelete:async(R,z)=>{let H=u.agents.get(R);H&&(await f.cleanupOpenclawSessionProviders(H).catch(ee=>j.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:R,err:String(ee)})),await H.dispose(`delete: ${z}`).catch(ee=>j.warn("dispose during delete failed (ignored)",{agentId:R,err:String(ee)})),u.unregister(R)),u.disconnectedAgents.delete(R)},detailSyncer:async R=>{if(!D.ref)throw new Error("agent-detail-sync not initialized yet");await D.ref.syncOne(R)},cleanupOpenclawProviders:async(R,z)=>{await f.cleanupOpenclawSessionProviders(R,z)},openclawRepair:async(R,z)=>{await f.openclawRepair(R,z)},isRuntimePendingPermission:R=>u.hasPendingPermissionFor(R)});u.registerExtension("_agent/listSkills",R=>B.listSkills(R.params)),u.registerExtension("_agent/addSkills",R=>B.addSkills(R.params)),u.registerExtension("_agent/removeSkills",R=>B.removeSkills(R.params)),u.registerExtension("_agent/publishSkill",R=>B.publishSkill(R.params)),u.registerExtension("_agent/getFileTree",R=>B.getFileTree(R.params)),u.registerExtension("_agent/getFileContent",R=>B.getFileContent(R.params)),u.registerExtension("_agent/update",R=>B.updateAgent(R.params)),u.registerExtension("_agent/disconnect",R=>B.disconnectAgent(R.params)),u.registerExtension("_agent/switchModel",R=>B.switchModel(R.params)),u.registerExtension("_agent/reset",R=>B.resetAgent(R.params)),u.registerExtension("_agent/repair",R=>B.repairAgent(R.params)),u.registerExtension("_agent/delete",R=>B.deleteAgent(R.params)),u.registerExtension("_agent/upgrade",R=>B.upgradeBridge(R.params));let M=new gs({paths:t,handlers:B,agentManager:f,sendDetail:R=>u.sendRequest("_agent/detail",R)});D.ref=M;let J=async R=>{await Promise.allSettled(R.map(async z=>{try{await B.disconnectAgent({agentId:z.agentId,reason:`auth_failure: code=${z.code} ${z.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:z.agentId,code:z.code,message:z.message})}catch(H){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:z.agentId,err:String(H)})}}))};c.onConnect(({initial:R})=>{j.info("frontier upstream connected, triggering detail sync",{initial:R}),M.syncAll(R?"initial-connect":"reconnect").catch(z=>j.warn("detail sync top-level error (ignored)",{err:String(z)}))});let $=new Ao({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let R=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[ns]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...R?{mockScenario:R}:{}}}},{method:"POST",path:"/pair",handler:async R=>{let z=R,H=z?.privatecode,ee=z?.pairing_code;if(!H||!ee)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ze=Oi(z.env),he=z.handshake_url,xe=z.frontier_url,vt=Jx(z.env,he,xe),ht=!!x&&x!==H,Qt=g!==void 0&&g!==vt,Ft=ht||Qt,en=await Uc({privatecode:H,...he?{endpoint:he}:{},ppeOverride:Ze});if(Ft){j.warn("pair config switched, resetting agents",{pcChanged:ht,envChanged:Qt,previousPc:x?ea(x):"",nextPc:ea(H),previousEnvKey:g??"",nextEnvKey:vt});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Wr,"pair switch").catch(()=>{})}w=en.deviceId,ls({deviceId:w,pid:process.pid}),ud({patToken:H,env:z.env}).catch(Ie=>j.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Yr=new es({handshake:en,privatecode:H,...xe?{urlOverride:xe}:{},ppeOverride:Ze,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Yr,"pair");try{let Ie=new $n;o.frameworksCache=await Ie.detectAll(),await qi(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let we=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:ee,patToken:H,frameworks:we,_meta:{cozeDeviceId:w}});j.info("_agent/pair ok",{pairResult:Ie}),x=H,g=vt,S=Ze,y=he,z.mock_scenario!==void 0&&(u.setMockScenario(z.mock_scenario),j.info("mock scenario set",{scenario:z.mock_scenario})),ts(H,t).catch(Pe=>j.warn("writePatToken after /pair failed (ignored)",{err:String(Pe)})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Pe=>j.warn("detailSync.retryPending failed (ignored)",{err:String(Pe)})),onAuthFailures:J})),v.start(),b(),Ft&&ta(t,f).catch(Pe=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(Pe)}));let er;return z.agent_id&&(er=await GS(z.agent_id,t,f,Pe=>u.sendRequest("_agent/detail",Pe),H).catch(Pe=>(j.error("--agent-id ensureAgent failed",{agentId:z.agent_id,err:String(Pe)}),{ok:!1,agentId:z.agent_id??"",note:String(Pe)}))),{ok:!0,note:"paired with cloud",...er?{agent:er}:{}}}catch(Ie){return j.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:R=>P(R)},{method:"POST",path:"/_agent/create",handler:async R=>{let z=R;return{ok:!0,result:await f.createAgent(z)}}},{method:"POST",path:"/agent/send",handler:async R=>{let z=R;if(!z?.agentId||!z?.sessionId||!z?.kind||!z?.path)throw new k("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let H=z;return await(H.groupFile?rh:nh)(H,{core:u,patToken:x,handshakeBase:y,ppeOverride:S})}catch(H){if(H instanceof k)return{ok:!1,code:H.code,message:H.message};throw H}}},{method:"POST",path:"/reload",handler:async R=>{let z=R?.agent_id,H=await u.reloadAgents(z);return j.info("IPC /reload: recycled agent subprocesses",{agentId:z??"(all)",recycled:H}),{ok:!0,recycled:H}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{se.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:Z}=await $.start();try{await Hx(t.libEntry,t)}catch(R){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(R)})}await u.start(),jS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new $n().detectAll(),await qi(o),o.frameworksCache)}).catch(R=>j.warn("startup warmup error (ignored)",{err:String(R)})),Dl().then(async()=>{let{probeAcpVersion:R}=await Promise.resolve().then(()=>(sn(),Rl));for(let z of["claude-code","codex"]){let H=await R(z);H&&j.info("acp wrapper version",{framework:z,version:H})}}).catch(R=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(R)}));let ie=null,se={port:ne,token:Z,core:u,ipc:$,shutdown(R){return ie||(j.info("daemon shutdown",{reason:R}),ie=(async()=>{v?.stop(),I?.stop(),await u.stop(R),await $.stop(),await e.release()})(),ie)}};for(let R of["SIGTERM","SIGINT"])process.on(R,()=>{se.shutdown(R).then(()=>process.exit(0))});return process.on("exit",()=>I0()),process.on("unhandledRejection",R=>{j.error("unhandledRejection",{reason:R instanceof Error?R.message:String(R),stack:R instanceof Error?R.stack:void 0})}),process.on("uncaughtException",R=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:R.message,stack:R.stack,name:R.name});try{process.stderr.write(`FATAL uncaughtException: ${R.stack??R.message}
|
|
112
|
+
`)}catch{}process.exit(1)}),j.info("daemon ready",{port:ne,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),HS({cliSpawned:process.env[ns]==="1",readPatToken:()=>Jo(t),connect:P}).catch(R=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(R)})),se}async function zS(t){return hs(t).length>0}function ea(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Jx(t,e,n){return`${t??""}|${e??""}|${n??""}`}async function US(t,e){let n=hs(t);if(n.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(cn(),ps));for(let c of n){await o(c,t).catch(d=>j.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.deletedAt?(e.disconnectedAgents.add(c),j.info("agent marked deleted on startup",{agentId:c,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(c),j.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){j.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function GS(t,e,n,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(cn(),ps)),d=await c(t,e);if(d){if(d.deletedAt)throw new k("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${d.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let g=Zx(d),w={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...g?{_meta:g}:{}};return await n.createAgent(w),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}j.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new k("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let f={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await n.createAgent(f);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function jS(t){let e=t.logger??j;try{let n=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(n??{})})}catch(n){e.warn("framework detection failed (using cached)",{err:String(n)})}await US(t.paths,t.core).catch(n=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(n)})),await ta(t.paths,t.agentManager).catch(n=>e.warn("auto-revive top-level error (ignored)",{err:String(n)})),await qS(t.paths).catch(n=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(n)}))}async function ta(t,e){let{readdir:n}=await import("node:fs/promises"),i;try{i=await n(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(cn(),ps));j.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let f;try{f=await o(u,t)}catch(x){j.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),d+=1;continue}if(!f){d+=1;continue}if(f.deletedAt){j.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:f.deletedAt}),d+=1;continue}if(f.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),d+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let x=Zx(f);await e.createAgent({agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){j.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(x)}),d+=1}}return j.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function qS(t){let{readdir:e}=await import("node:fs/promises"),n;try{n=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(n.length===0)return{refreshed:0,total:0};let i=0;for(let o of n)try{(await f0(o,t)).status==="refreshed"&&(i+=1)}catch(c){j.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&j.info("builtin skills refresh on startup done",{refreshed:i,total:n.length}),{refreshed:i,total:n.length}}async function HS(t){let e=t.logger??j;if(t.cliSpawned)return"skipped-cli";let n=await t.readPatToken();return n?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:n}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Zx(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Xo();De();import{readFile as Xx}from"node:fs/promises";var Xt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let n=await na(this.paths);if(!n)return{kind:"not-running"};try{let i=await this.fetch(n,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...n,body:i.body}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:KS(i)}}}async request(e){let n=await na(this.paths);if(!n)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(n,e)}async fetch(e,n){let i=n.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),n.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${n.path}`,{method:n.method,headers:o,body:i?JSON.stringify(n.body):void 0,signal:c.signal}),f=await u.text();return{status:u.status,body:WS(f)}}finally{clearTimeout(d)}}};async function na(t){try{let[e,n]=await Promise.all([Xx(t.portFile,"utf8"),Xx(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=n.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function WS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function KS(t){return t instanceof Error?t.message:String(t)}Kt();te();ir();import{spawn as $S}from"node:child_process";import{userInfo as ep}from"node:os";var jd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",VS=new Set(["bash","zsh","sh","dash","ksh"]),Qx=Ke("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),JS=2e3;function YS(t,e=jd){let n=t.indexOf(e);if(n===-1)return null;let i=t.indexOf(e,n+e.length);if(i===-1)return null;let o=t.slice(n+e.length,i),c={};for(let d of o.split(`
|
|
113
|
+
`)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function ZS(){let t=(process.env.SHELL??"").trim()||(ep().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return VS.has(e)?t:null}function XS(t){return new Promise(e=>{let n=`printf '%s' '${jd}'; env; printf '%s' '${jd}'`,i;try{i=$S(t,["-ilc",n],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??ep().homedir}})}catch{e(null);return}let o="",c=!1,d=g=>{try{i.pid&&process.kill(-i.pid,g)}catch{}},u=g=>{c||(c=!0,clearTimeout(f),clearTimeout(x),e(g))};i.stdout?.on("data",g=>{o+=g.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let f=setTimeout(()=>d("SIGTERM"),Qx),x=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},Qx+JS)})}async function qd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let n=ZS();if(!n)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??XS)(n);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=YS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}De();function Cn(t,...e){let n=[],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||n.push(c)}return{value:i,rest:n}}sn();import{chmod as QS,copyFile as tp,mkdir as rp,readFile as is,rename as np,rm as Kd,stat as $d,writeFile as e1}from"node:fs/promises";import{homedir as aD}from"node:os";import{dirname as t1,join as Bt,resolve as Vd,sep as rs}from"node:path";import{fileURLToPath as n1}from"node:url";Kt();te();De();var Kr=G("dist-install");function ip(){return{darwin:{arm64:"@zed-industries/codex-acp-darwin-arm64",x64:"@zed-industries/codex-acp-darwin-x64"},linux:{arm64:"@zed-industries/codex-acp-linux-arm64",x64:"@zed-industries/codex-acp-linux-x64"},win32:{arm64:"@zed-industries/codex-acp-win32-arm64",x64:"@zed-industries/codex-acp-win32-x64"}}[process.platform]?.[process.arch]}function r1(){return process.platform==="win32"?"codex-acp.exe":"codex-acp"}function i1(t){let e=n1(t),n=t1(e),i=`${rs}src${rs}`;if(n.includes(i)||n.endsWith(`${rs}src${rs}cli`))return null;let o=Vd(n,"index.js"),c=Vd(n,"..","package.json");return{dist:o,pkgJson:c}}async function Jd(t={}){let e=t.paths??Q(),n=i1(import.meta.url),i=t.sourceDist??n?.dist,o=t.sourcePackageJson??n?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let v=JSON.parse(await is(o,"utf8"));c=v.version??"unknown",d=v.dependencies??{}}catch(v){return Kr.warn("cannot read source package.json,skip dist install",{err:String(v)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(v)}`}}let u=us.map(v=>({name:v,spec:d[v]??"latest"})),f=u.map(({name:v,spec:I})=>`${v}@${I}`),x=await So(e.configFile)??{},g=x.libVersion,w=await is(e.libEntry).then(()=>!0).catch(()=>!1),S=g===c,y=await sp(e,u);if(S&&w&&y)return{kind:"already-current",libVersion:c};if(!S||!w){await rp(e.libDir,{recursive:!0}),await tp(i,e.libEntry),await tp(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let v=Vd(e.libDir,"package.json"),I=`${JSON.stringify({type:"module"},null,2)}
|
|
114
|
+
`;await is(v,"utf8").catch(()=>null)!==I&&await e1(v,I)}return y||(t.installWrappers?await t.installWrappers(e,f):await o1(e,f,u)),x.libVersion=c,await qi(x,e.configFile),Kr.info("dist installed",{libEntry:e.libEntry,fromVersion:g,toVersion:c}),S&&w?{kind:"already-current",libVersion:c}:g?{kind:"version-changed",fromVersion:g,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function sp(t,e){for(let n of e){let i=Bt(t.libDir,"node_modules",...n.name.split("/"),"package.json"),o;try{o=JSON.parse(await is(i,"utf8"))}catch(d){return Kr.warn("wrapper not ready: package.json read failed",{package:n.name,expected:n.spec,pkgJson:i,err:String(d)}),!1}let c=o.version;if(!c)return Kr.warn("wrapper not ready: package.json \u7F3A version",{package:n.name,expected:n.spec,pkgJson:i}),!1;if(!s1(c,n.spec))return Kr.warn("wrapper not ready: installed version does not satisfy expected range",{package:n.name,installed:c,expected:n.spec}),!1}return!!await op(Bt(t.libDir,"node_modules"))}function s1(t,e){let n=Hd(t);if(!n)return!0;let i=e.trim();if(!i||i==="*"||i==="latest")return!0;if(i.startsWith("^")){let c=Hd(i.slice(1));if(!c)return!0;if(Wd(n,c)<0)return!1;let d=c[0]>0?[c[0]+1,0,0]:c[1]>0?[0,c[1]+1,0]:[0,0,c[2]+1];return Wd(n,d)<0}let o=Hd(i);return o?Wd(n,o)===0:!0}function Hd(t){let e=t.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}function Wd(t,e){for(let n=0;n<3;n++){let i=(t[n]??0)-(e[n]??0);if(i!==0)return i}return 0}async function o1(t,e,n){await d1(t.installLock,async()=>{if(await sp(t,n))return;let i=Math.random().toString(36).slice(2,10),o=`${t.libDir}${rs}.staging-${process.pid}-${i}`,c=Bt(o,"node_modules"),d=Bt(t.libDir,"node_modules");try{await rp(o,{recursive:!0}),await a1(e,o),await c1(c);let u=`${d}.trash-${i}`;await np(d,u).catch(()=>{}),await np(c,d),await Kd(u,{recursive:!0,force:!0}).catch(()=>{}),Kr.info("wrapper closure installed",{liveNm:d,specs:e})}finally{await Kd(o,{recursive:!0,force:!0}).catch(()=>{})}})}function a1(t,e){let n=["install",...t,"--prefix",e,"--omit=dev","--include=optional","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=et("npm",n,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",f=>{d.length<8192&&(d+=f.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),c.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${d.trim().slice(0,2e3)}`))})})}async function c1(t){for(let e of us){let n=Bt(t,...e.split("/")),i=JSON.parse(await is(Bt(n,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Bt(t,".bin",o),d=await $d(c);process.platform!=="win32"&&!(d.mode&73)&&await QS(c,d.mode|73).catch(()=>{})}if(!await op(t)){let e=ip()??"<unsupported-platform>";throw new Error(`${e}: \u5F53\u524D\u5E73\u53F0 codex-acp binary \u7F3A\u5931`)}}async function op(t){let e=ip();if(!e)return!0;let n=Bt(t,...e.split("/")),i=Bt(n,"package.json"),o=Bt(n,"bin",r1()),[c,d]=await Promise.all([$d(i).then(u=>u.isFile()).catch(()=>!1),$d(o).then(u=>u.isFile()).catch(()=>!1)]);return c&&d}async function d1(t,e){let{open:n}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await n(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Kd(t,{force:!0}).catch(()=>{})}}Ia();te();De();import{closeSync as cp,fstatSync as dp,openSync as lp,readFileSync as l1,readSync as u1,readdirSync as f1,statSync as h1}from"node:fs";import{join as ra}from"node:path";var x1=new Set(["debug","info","warn","error"]);function up(t){let e=t,n=Cn(e,"--agent-id");e=n.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),f=Number.isInteger(u)&&u>=0?u:200,x=c.value&&x1.has(c.value)?c.value:void 0,g={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return n.value&&(g.agentId=n.value),i.value&&(g.date=i.value),x&&(g.level=x),d.value&&(g.grep=d.value),g}function p1(t,e){return t.agentId?ra($e(t.agentId,e).logs,sr("agent",t.date)):ra(e.bridgeLogsDir,sr("bridge",t.date))}function g1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function m1(t,e){let n;try{n=f1(t)}catch{return[]}let i=[];for(let o of n){let c=Sa(o,e);if(!c)continue;let d=0;try{d=h1(ra(t,o)).size}catch{}i.push({file:ra(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function fp(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let n;try{n=JSON.parse(t).level}catch{return!0}if(typeof n=="string"&&!Il(n,e.level))return!1}return!0}var ap={debug:"90",info:"36",warn:"33",error:"31"},w1=new Set(["ts","level","module","msg"]);function _1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function hp(t,e){if(e.raw)return t;let n;try{n=JSON.parse(t)}catch{return t}let i=_1(n.ts),o=typeof n.level=="string"?n.level:"",c=o.toUpperCase().padEnd(5);e.color&&ap[o]&&(c=`\x1B[${ap[o]}m${c}\x1B[0m`);let d=typeof n.module=="string"?n.module:"",u=typeof n.msg=="string"?n.msg:"",f=Object.entries(n).filter(([x])=>!w1.has(x)).map(([x,g])=>` ${x}=${typeof g=="string"?g:JSON.stringify(g)}`).join("");return`${i} ${c} ${d} ${u}${f}`}function y1(t,e,n){let c=l1(t,"utf8").split(`
|
|
115
|
+
`).filter(d=>d.length>0).filter(d=>fp(d,{level:e.level,grep:e.grep}));for(let d of g1(c,e.lines))process.stdout.write(`${hp(d,{raw:e.raw,color:n})}
|
|
116
|
+
`)}async function xp(t,e){let n=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?$e(t.agentId,n).logs:n.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=m1(d,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
|
|
117
|
+
`),1;for(let x of f)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
|
|
118
|
+
`);return 0}let o=t.date??Pn(new Date),c=p1({agentId:t.agentId,date:o},n);try{y1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
|
|
119
119
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
120
120
|
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${n.logFile})
|
|
121
|
-
`),1}return t.follow&&await
|
|
122
|
-
`);o=
|
|
123
|
-
`)}await new Promise(
|
|
121
|
+
`),1}return t.follow&&await v1(c,t,i),0}var b1=500;function E1(t){try{let e=lp(t,"r");try{return dp(e).size}finally{cp(e)}}catch{return 0}}async function v1(t,e,n){let i=E1(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let f=lp(t,"r");try{let x=dp(f).size;if(x>i){let g=Buffer.allocUnsafe(x-i),w=u1(f,g,0,g.length,i);u=g.subarray(0,w).toString("utf8"),i+=w}}finally{cp(f)}}catch{}if(u){let f=(o+u).split(`
|
|
122
|
+
`);o=f.pop()??"";for(let x of f)x.length>0&&fp(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${hp(x,{raw:e.raw,color:n})}
|
|
123
|
+
`)}await new Promise(f=>setTimeout(f,b1))}}finally{process.off("SIGINT",d)}}import{basename as S1,resolve as I1}from"node:path";De();var A1=9e4,k1={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function T1(t){return k1[t]??1}async function pp(t,e={}){let n=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>
|
|
124
124
|
`),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
|
|
125
|
-
`),3;let i=await
|
|
126
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
125
|
+
`),3;let i=await na(n).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${n.portFile} / ${n.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
|
|
126
|
+
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:I1(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 C1(i,"/agent/send",o,A1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
|
|
127
127
|
`),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
|
|
128
|
-
`),
|
|
129
|
-
`);else{let
|
|
130
|
-
`)}else process.stdout.write(`Sent ${t.kind} ${
|
|
131
|
-
`)}return 0}async function
|
|
132
|
-
`)}function
|
|
128
|
+
`),T1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
|
|
129
|
+
`);else{let d=t.name??S1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
|
|
130
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${R1(c.bytes)})
|
|
131
|
+
`)}return 0}async function C1(t,e,n,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(n),signal:o.signal}),u=await d.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function R1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Ip=G("cli");function je(t,e){let{value:n,rest:i}=Cn(t,e);return{value:n,rest:i}}function da(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
132
|
+
`)}function eI(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:P}=je(e.slice(1),"--agent-id");return P?{mode:"reload",agentId:P}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return tI(e.slice(1));if(e[0]==="log")return{mode:"log",...up(e.slice(1))};if(e[0]==="connect")return nI(e.slice(1));if(e.includes("--status"))return da("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return da("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return da("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return da("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let n=e,{value:i,rest:o}=je(n,"--pat-token");n=o;let{value:c,rest:d}=je(n,"--pair-code");n=d;let{value:u,rest:f}=je(n,"--env");n=f;let{value:x,rest:g}=je(n,"--handshake-url");n=g;let{value:w,rest:S}=je(n,"--frontier-url");n=S;let{value:y,rest:v}=je(n,"--mock-scenario");n=v;let{value:I}=je(n,"--agent-id"),A=n.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let T={mode:"pair",privatecode:i,pairingCode:c};return u&&(T.env=u),x&&(T.handshakeUrl=x),w&&(T.frontierUrl=w),y&&(T.mockScenario=y),I&&(T.agentId=I),A&&(T.skipRebuildEnv=!0),T}function tI(t){let e=t[0],n=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!n||n.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=je(i,"--caption");i=c;let{value:d,rest:u}=je(i,"--name");i=u;let{value:f,rest:x}=je(i,"--agent-id");i=x;let{value:g,rest:w}=je(i,"--session-id");i=w;let{value:S,rest:y}=je(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(T=>T!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:n,json:I};return o&&(A.caption=o),d&&(A.name=d),f&&(A.agentId=f),g&&(A.sessionId=g),v&&(A.groupFile=!0),S&&(A.mimeType=S),A}function nI(t){let e=t,{value:n,rest:i}=je(e,"--pat-token");e=i;let{value:o,rest:c}=je(e,"--env");e=c;let{value:d,rest:u}=je(e,"--handshake-url");e=u;let{value:f,rest:x}=je(e,"--frontier-url");e=x;let{value:g,rest:w}=je(e,"--mock-scenario");e=w;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return n&&(y.privatecode=n),o&&(y.env=o),d&&(y.handshakeUrl=d),f&&(y.frontierUrl=f),g&&(y.mockScenario=g),S&&(y.skipRebuildEnv=!0),y}var rI=`
|
|
133
133
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
134
134
|
|
|
135
135
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -210,57 +210,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
210
210
|
|
|
211
211
|
Internal:
|
|
212
212
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
213
|
-
`.trimStart();async function
|
|
214
|
-
`),0;case"daemon":{try{await
|
|
215
|
-
`),1;if(i.kind==="stale")return await
|
|
213
|
+
`.trimStart();async function Ap(t=process.argv,e={}){let n=eI(t);switch(n.mode){case"help":return process.stdout.write(rI),0;case"version":return process.stdout.write(`${Rt}
|
|
214
|
+
`),0;case"daemon":{try{await Yx()}catch(i){return Ip.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return iI(e);case"stop":return Tp(e);case"reload":return aI(n.agentId,e);case"log":return xp(n,e);case"update":return sI(e);case"purge":return dI(e);case"service-install":return lI(e);case"service-uninstall":return uI(e);case"pair":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),fI(n.privatecode,n.pairingCode,e,i,n.agentId,n.skipRebuildEnv)}case"connect":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),hI(n.privatecode,e,i,n.skipRebuildEnv)}case"send":return pp({kind:n.kind,path:n.path,...n.agentId?{agentId:n.agentId}:{},...n.sessionId?{sessionId:n.sessionId}:{},...n.caption?{caption:n.caption}:{},...n.name?{name:n.name}:{},...n.groupFile?{groupFile:!0}:{},...n.mimeType?{mimeType:n.mimeType}:{},json:n.json},e)}}async function kp(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 iI(t){let e=t.paths??Q(),n=new Xt(e),i=await n.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
215
|
+
`),1;if(i.kind==="stale")return await kp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
216
216
|
`),1;let o=await n.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
217
217
|
${JSON.stringify(o.body,null,2)}
|
|
218
|
-
`),0}async function Tp(t){let e=t.paths??Q(),n=new
|
|
219
|
-
`)}let u=await n.probe();if(u.kind==="not-running")return await o(),process.stdout.write(
|
|
218
|
+
`),0}async function Tp(t){let e=t.paths??Q(),n=new Xt(e),i=t.daemonSweep??(async()=>{let f=A0();return await k0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},c=await os(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
|
|
219
|
+
`)}let u=await n.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
|
|
220
220
|
`:`coze-bridge: not running
|
|
221
|
-
`),0;if(u.kind==="stale")return await
|
|
221
|
+
`),0;if(u.kind==="stale")return await kp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
222
222
|
`),0;try{return await n.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
223
|
-
`),0}catch(
|
|
224
|
-
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(
|
|
225
|
-
`),1)}}async function
|
|
226
|
-
`),e(1)})})}async function
|
|
223
|
+
`),0}catch(f){return(await n.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
|
|
224
|
+
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
|
|
225
|
+
`),1)}}async function sI(t){return await Tp(t),(t.spawnNpx??oI)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function oI(t){return new Promise(e=>{let n=et("npx",t,{stdio:"inherit"});n.on("exit",i=>e(i??1)),n.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
|
|
226
|
+
`),e(1)})})}async function aI(t,e){let n=new Xt(e.paths);if((await n.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
227
227
|
`),1;try{let o=await n.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
|
|
228
228
|
`):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
|
|
229
229
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
230
230
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
231
|
-
`),1}}async function os(t){if(t.supervisor){let c=t.supervisor,
|
|
231
|
+
`),1}}async function os(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(d,u),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:n}=await Promise.resolve().then(()=>(Ep(),bp)),i=e(),o=n();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Cp(t,e){let n=await e.probe(),i=t.waitTimeoutMs??15e3,o=t.sleep??xI,c=t.paths??Q();if(n.kind==="connected"){if(!cI(n.body))return n;at(c.bridgeLogsDir,"warn","cli","daemon Node \u4E0E\u5F53\u524D CLI \u4E0D\u4E00\u81F4, \u91CD\u542F daemon",{currentNode:process.execPath,currentArch:process.arch,daemon:n.body}),await e.request({method:"POST",path:"/shutdown"}).catch(f=>at(c.bridgeLogsDir,"warn","cli","restart for Node drift: shutdown failed",{err:String(f)})),await Sp(c.pidFile,o)}let d=t.spawnDaemon??Vx,u=await os(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await vp(e,i,o);if(f.kind==="connected")return f;at(c.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:i})}catch(f){at(c.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}at(c.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await Sp(c.pidFile,o)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
|
|
232
232
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
233
|
-
`),await
|
|
234
|
-
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(
|
|
235
|
-
`)}await new Promise(
|
|
236
|
-
`)}catch(
|
|
233
|
+
`),await d({paths:t.paths}),vp(e,i,o)}function cI(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.nodeExecPath!="string"||typeof e.nodeArch!="string"?!1:e.nodeExecPath!==process.execPath||e.nodeArch!==process.arch}async function dI(t){let e=new Xt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
234
|
+
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
|
|
235
|
+
`)}await new Promise(d=>setTimeout(d,500))}let i=await os(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
236
|
+
`)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
|
|
237
237
|
`)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
|
|
238
|
-
`)}catch(
|
|
238
|
+
`)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
|
|
239
239
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
240
|
-
`),0}async function
|
|
240
|
+
`),0}async function lI(t){let e=await os(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
241
241
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
242
242
|
`),0}catch(n){return process.stderr.write(`coze-bridge: service install failed: ${String(n)}
|
|
243
|
-
`),1}}async function
|
|
243
|
+
`),1}}async function uI(t){let e=await os(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
244
244
|
`),0}catch(n){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(n)}
|
|
245
|
-
`),1}}async function Rp(t,e,n){if(e)return
|
|
246
|
-
`),
|
|
247
|
-
`),(await
|
|
248
|
-
`)}let x=await
|
|
249
|
-
`),1;let
|
|
245
|
+
`),1}}async function Rp(t,e,n){if(e)return at(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await n();return i.kind==="ok"?(at(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(at(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
|
|
246
|
+
`),at(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function fI(t,e,n,i={},o,c){let d=new Xt(n.paths),u=n.paths??Q(),f=await Rp(u,c,n.reconstructEnv??qd);if(await nd(u,f).catch(w=>at(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!n.skipDistInstall){let w=await Jd({paths:n.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
|
|
247
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
|
|
248
|
+
`)}let x=await Cp(n,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
|
|
249
|
+
`),1;let g={privatecode:t,pairing_code:e};i.env&&(g.env=i.env),i.handshakeUrl&&(g.handshake_url=i.handshakeUrl),i.frontierUrl&&(g.frontier_url=i.frontierUrl),i.mockScenario&&(g.mock_scenario=i.mockScenario),o&&(g.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:g,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let S=w.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
|
|
250
250
|
`),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
|
|
251
251
|
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
|
|
252
252
|
`),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
|
|
253
|
-
`),1}}async function
|
|
254
|
-
`),(await
|
|
255
|
-
`)}let
|
|
256
|
-
`),1;let x={privatecode:c};n.env&&(x.env=n.env),n.handshakeUrl&&(x.handshake_url=n.handshakeUrl),n.frontierUrl&&(x.frontier_url=n.frontierUrl),n.mockScenario&&(x.mock_scenario=n.mockScenario);try{let
|
|
257
|
-
`),t!==void 0&&await ts(c,o).catch(w=>
|
|
258
|
-
`),1)}catch(
|
|
259
|
-
`),1}}async function
|
|
253
|
+
`),1}}async function hI(t,e,n={},i){let o=e.paths??Q(),c=t??await Jo(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 Rp(o,i,e.reconstructEnv??qd);if(await nd(o,u).catch(g=>at(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(g)})),!e.skipDistInstall){let g=await Jd({paths:e.paths});g.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${g.fromVersion} \u2192 ${g.toVersion}
|
|
254
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):g.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${g.libVersion}
|
|
255
|
+
`)}let f=await Cp(e,d);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
|
|
256
|
+
`),1;let x={privatecode:c};n.env&&(x.env=n.env),n.handshakeUrl&&(x.handshake_url=n.handshakeUrl),n.frontierUrl&&(x.frontier_url=n.frontierUrl),n.mockScenario&&(x.mock_scenario=n.mockScenario);try{let g=await d.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return g.status===200&&g.body?.ok?(process.stdout.write(`coze-bridge: connected (${g.body.note??"ok"})
|
|
257
|
+
`),t!==void 0&&await ts(c,o).catch(w=>Ip.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(g.body)}
|
|
258
|
+
`),1)}catch(g){return process.stderr.write(`coze-bridge: connect failed: ${String(g)}
|
|
259
|
+
`),1}}async function vp(t,e,n){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await n(200)}return t.probe(500)}async function Sp(t,e,n=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<n;c++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!zi(u))return;await e(i)}}function xI(t){return new Promise(e=>setTimeout(e,t))}te();function pI(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let n=Number(e[1]),i=Number(e[2]??0);return n<18||n===18&&i<4?"fatal":n<20?"warn":"ok"}function Pp(t=process.versions.node,e=i=>{process.stderr.write(i)},n=i=>process.exit(i)){let i=pI(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
|
|
260
260
|
`),n(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
|
|
261
261
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
262
262
|
npx -y coze-bridge@latest stop
|
|
263
263
|
npx -y coze-bridge@latest connect
|
|
264
264
|
|
|
265
|
-
`)}
|
|
265
|
+
`)}Pp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&vl("warn");Ap(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
266
266
|
`),process.exit(1)});
|