@wengine-ai/claude-code-router-shared 2.3.2430 → 2.3.2432
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 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
`+u,p=d.join(s);m=`[
|
|
13
13
|
`+u+p+`,
|
|
14
14
|
`+D+"]"}return i.pop(),u=D,m}}});var Kn=J((va,yi)=>{var rs=gi(),is=Ai(),us={parse:rs,stringify:is};yi.exports=us});var Jn=J((_a,hi)=>{hi.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 $t=J(vi=>{var Fi={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 os(e){return function(...t){return t.length&&(e=e.replace(/\{(\d)\}/g,(n,r)=>t[r]||"")),new Error("ADM-ZIP: "+e)}}for(let e of Object.keys(Fi))vi[e]=os(Fi[e])});var wi=J((Pa,Ii)=>{var ss=require("fs"),Y=require("path"),_i=Jn(),as=$t(),cs=typeof process=="object"&&process.platform==="win32",Si=e=>typeof e=="object"&&e!==null,Pi=new Uint32Array(256).map((e,t)=>{for(let n=0;n<8;n++)(t&1)!==0?t=3988292384^t>>>1:t>>>=1;return t>>>0});function Z(e){this.sep=Y.sep,this.fs=ss,Si(e)&&Si(e.fs)&&typeof e.fs.statSync=="function"&&(this.fs=e.fs)}Ii.exports=Z;Z.prototype.makeDir=function(e){let t=this;function n(r){let i=r.split(t.sep)[0];r.split(t.sep).forEach(function(u){if(!(!u||u.substr(-1,1)===":")){i+=t.sep+u;var o;try{o=t.fs.statSync(i)}catch{t.fs.mkdirSync(i)}if(o&&o.isFile())throw as.FILE_IN_THE_WAY(`"${i}"`)}})}n(e)};Z.prototype.writeFileTo=function(e,t,n,r){let i=this;if(i.fs.existsSync(e)){if(!n)return!1;var u=i.fs.statSync(e);if(u.isDirectory())return!1}var o=Y.dirname(e);i.fs.existsSync(o)||i.makeDir(o);var a;try{a=i.fs.openSync(e,"w",438)}catch{i.fs.chmodSync(e,438),a=i.fs.openSync(e,"w",438)}if(a)try{i.fs.writeSync(a,t,0,t.length,0)}finally{i.fs.closeSync(a)}return i.fs.chmodSync(e,r||438),!0};Z.prototype.writeFileToAsync=function(e,t,n,r,i){typeof r=="function"&&(i=r,r=void 0);let u=this;u.fs.exists(e,function(o){if(o&&!n)return i(!1);u.fs.stat(e,function(a,c){if(o&&c.isDirectory())return i(!1);var E=Y.dirname(e);u.fs.exists(E,function(h){h||u.makeDir(E),u.fs.open(e,"w",438,function(w,I){w?u.fs.chmod(e,438,function(){u.fs.open(e,"w",438,function(f,C){u.fs.write(C,t,0,t.length,0,function(){u.fs.close(C,function(){u.fs.chmod(e,r||438,function(){i(!0)})})})})}):I?u.fs.write(I,t,0,t.length,0,function(){u.fs.close(I,function(){u.fs.chmod(e,r||438,function(){i(!0)})})}):u.fs.chmod(e,r||438,function(){i(!0)})})})})})};Z.prototype.findFiles=function(e){let t=this;function n(r,i,u){typeof i=="boolean"&&(u=i,i=void 0);let o=[];return t.fs.readdirSync(r).forEach(function(a){let c=Y.join(r,a),E=t.fs.statSync(c);(!i||i.test(c))&&o.push(Y.normalize(c)+(E.isDirectory()?t.sep:"")),E.isDirectory()&&u&&(o=o.concat(n(c,i,u)))}),o}return n(e,void 0,!0)};Z.prototype.findFilesAsync=function(e,t){let n=this,r=[];n.fs.readdir(e,function(i,u){if(i)return t(i);let o=u.length;if(!o)return t(null,r);u.forEach(function(a){a=Y.join(e,a),n.fs.stat(a,function(c,E){if(c)return t(c);E&&(r.push(Y.normalize(a)+(E.isDirectory()?n.sep:"")),E.isDirectory()?n.findFilesAsync(a,function(h,w){if(h)return t(h);r=r.concat(w),--o||t(null,r)}):--o||t(null,r))})})})};Z.prototype.getAttributes=function(){};Z.prototype.setAttributes=function(){};Z.crc32update=function(e,t){return Pi[(e^t)&255]^e>>>8};Z.crc32=function(e){typeof e=="string"&&(e=Buffer.from(e,"utf8"));let t=e.length,n=-1;for(let r=0;r<t;)n=Z.crc32update(n,e[r++]);return~n>>>0};Z.methodToString=function(e){switch(e){case _i.STORED:return"STORED ("+e+")";case _i.DEFLATED:return"DEFLATED ("+e+")";default:return"UNSUPPORTED ("+e+")"}};Z.canonical=function(e){if(!e)return"";let t=Y.posix.normalize("/"+e.split("\\").join("/"));return Y.join(".",t)};Z.zipnamefix=function(e){if(!e)return"";let t=Y.posix.normalize("/"+e.split("\\").join("/"));return Y.posix.join(".",t)};Z.findLast=function(e,t){if(!Array.isArray(e))throw new TypeError("arr is not array");let n=e.length>>>0;for(let r=n-1;r>=0;r--)if(t(e[r],r,e))return e[r]};Z.sanitize=function(e,t){e=Y.resolve(Y.normalize(e));for(var n=t.split("/"),r=0,i=n.length;r<i;r++){var u=Y.normalize(Y.join(e,n.slice(r,i).join(Y.sep)));if(u.indexOf(e)===0)return u}return Y.normalize(Y.join(e,Y.basename(t)))};Z.toBuffer=function(t,n){return Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t):typeof t=="string"?n(t):Buffer.alloc(0)};Z.readBigUInt64LE=function(e,t){var n=Buffer.from(e.slice(t,t+8));return n.swap64(),parseInt(`0x${n.toString("hex")}`)};Z.fromDOS2Date=function(e){return new Date((e>>25&127)+1980,Math.max((e>>21&15)-1,0),Math.max(e>>16&31,1),e>>11&31,e>>5&63,(e&31)<<1)};Z.fromDate2DOS=function(e){let t=0,n=0;return e.getFullYear()>1979&&(t=(e.getFullYear()-1980&127)<<9|e.getMonth()+1<<5|e.getDate(),n=e.getHours()<<11|e.getMinutes()<<5|e.getSeconds()>>1),t<<16|n};Z.isWin=cs;Z.crcTable=Pi});var xi=J((Ia,Ri)=>{var fs=require("path");Ri.exports=function(e,{fs:t}){var n=e||"",r=u(),i=null;function u(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return n&&t.existsSync(n)?(i=t.statSync(n),r.directory=i.isDirectory(),r.mtime=i.mtime,r.atime=i.atime,r.executable=(73&i.mode)!==0,r.readonly=(128&i.mode)===0,r.hidden=fs.basename(n)[0]==="."):console.warn("Invalid path: "+n),{get directory(){return r.directory},get readOnly(){return r.readonly},get hidden(){return r.hidden},get mtime(){return r.mtime},get atime(){return r.atime},get executable(){return r.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:n,isDirectory:r.directory,isReadOnly:r.readonly,isHidden:r.hidden,isExecutable:r.executable,mTime:r.mtime,aTime:r.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Bi=J((wa,Oi)=>{Oi.exports={efs:!0,encode:e=>Buffer.from(e,"utf8"),decode:e=>e.toString("utf8")}});var Ve=J((Ra,ze)=>{ze.exports=wi();ze.exports.Constants=Jn();ze.exports.Errors=$t();ze.exports.FileAttr=xi();ze.exports.decoder=Bi()});var bi=J((xa,Ni)=>{var we=Ve(),y=we.Constants;Ni.exports=function(){var e=20,t=10,n=0,r=0,i=0,u=0,o=0,a=0,c=0,E=0,h=0,w=0,I=0,f=0,C=0;e|=we.isWin?2560:768,n|=y.FLG_EFS;let l={extraLen:0},D=s=>Math.max(0,s)>>>0,d=s=>Math.max(0,s)&65535,m=s=>Math.max(0,s)&255;return i=we.fromDate2DOS(new Date),{get made(){return e},set made(s){e=s},get version(){return t},set version(s){t=s},get flags(){return n},set flags(s){n=s},get flags_efs(){return(n&y.FLG_EFS)>0},set flags_efs(s){s?n|=y.FLG_EFS:n&=~y.FLG_EFS},get flags_desc(){return(n&y.FLG_DESC)>0},set flags_desc(s){s?n|=y.FLG_DESC:n&=~y.FLG_DESC},get method(){return r},set method(s){switch(s){case y.STORED:this.version=10;case y.DEFLATED:default:this.version=20}r=s},get time(){return we.fromDOS2Date(this.timeval)},set time(s){this.timeval=we.fromDate2DOS(s)},get timeval(){return i},set timeval(s){i=D(s)},get timeHighByte(){return m(i>>>8)},get crc(){return u},set crc(s){u=D(s)},get compressedSize(){return o},set compressedSize(s){o=D(s)},get size(){return a},set size(s){a=D(s)},get fileNameLength(){return c},set fileNameLength(s){c=s},get extraLength(){return E},set extraLength(s){E=s},get extraLocalLength(){return l.extraLen},set extraLocalLength(s){l.extraLen=s},get commentLength(){return h},set commentLength(s){h=s},get diskNumStart(){return w},set diskNumStart(s){w=D(s)},get inAttr(){return I},set inAttr(s){I=D(s)},get attr(){return f},set attr(s){f=D(s)},get fileAttr(){return(f||0)>>16&4095},get offset(){return C},set offset(s){C=D(s)},get encrypted(){return(n&y.FLG_ENC)===y.FLG_ENC},get centralHeaderSize(){return y.CENHDR+c+E+h},get realDataOffset(){return C+y.LOCHDR+l.fnameLen+l.extraLen},get localHeader(){return l},loadLocalHeaderFromBinary:function(s){var p=s.slice(C,C+y.LOCHDR);if(p.readUInt32LE(0)!==y.LOCSIG)throw we.Errors.INVALID_LOC();l.version=p.readUInt16LE(y.LOCVER),l.flags=p.readUInt16LE(y.LOCFLG),l.method=p.readUInt16LE(y.LOCHOW),l.time=p.readUInt32LE(y.LOCTIM),l.crc=p.readUInt32LE(y.LOCCRC),l.compressedSize=p.readUInt32LE(y.LOCSIZ),l.size=p.readUInt32LE(y.LOCLEN),l.fnameLen=p.readUInt16LE(y.LOCNAM),l.extraLen=p.readUInt16LE(y.LOCEXT);let g=C+y.LOCHDR+l.fnameLen,v=g+l.extraLen;return s.slice(g,v)},loadFromBinary:function(s){if(s.length!==y.CENHDR||s.readUInt32LE(0)!==y.CENSIG)throw we.Errors.INVALID_CEN();e=s.readUInt16LE(y.CENVEM),t=s.readUInt16LE(y.CENVER),n=s.readUInt16LE(y.CENFLG),r=s.readUInt16LE(y.CENHOW),i=s.readUInt32LE(y.CENTIM),u=s.readUInt32LE(y.CENCRC),o=s.readUInt32LE(y.CENSIZ),a=s.readUInt32LE(y.CENLEN),c=s.readUInt16LE(y.CENNAM),E=s.readUInt16LE(y.CENEXT),h=s.readUInt16LE(y.CENCOM),w=s.readUInt16LE(y.CENDSK),I=s.readUInt16LE(y.CENATT),f=s.readUInt32LE(y.CENATX),C=s.readUInt32LE(y.CENOFF)},localHeaderToBinary:function(){var s=Buffer.alloc(y.LOCHDR);return s.writeUInt32LE(y.LOCSIG,0),s.writeUInt16LE(t,y.LOCVER),s.writeUInt16LE(n,y.LOCFLG),s.writeUInt16LE(r,y.LOCHOW),s.writeUInt32LE(i,y.LOCTIM),s.writeUInt32LE(u,y.LOCCRC),s.writeUInt32LE(o,y.LOCSIZ),s.writeUInt32LE(a,y.LOCLEN),s.writeUInt16LE(c,y.LOCNAM),s.writeUInt16LE(l.extraLen,y.LOCEXT),s},centralHeaderToBinary:function(){var s=Buffer.alloc(y.CENHDR+c+E+h);return s.writeUInt32LE(y.CENSIG,0),s.writeUInt16LE(e,y.CENVEM),s.writeUInt16LE(t,y.CENVER),s.writeUInt16LE(n,y.CENFLG),s.writeUInt16LE(r,y.CENHOW),s.writeUInt32LE(i,y.CENTIM),s.writeUInt32LE(u,y.CENCRC),s.writeUInt32LE(o,y.CENSIZ),s.writeUInt32LE(a,y.CENLEN),s.writeUInt16LE(c,y.CENNAM),s.writeUInt16LE(E,y.CENEXT),s.writeUInt16LE(h,y.CENCOM),s.writeUInt16LE(w,y.CENDSK),s.writeUInt16LE(I,y.CENATT),s.writeUInt32LE(f,y.CENATX),s.writeUInt32LE(C,y.CENOFF),s},toJSON:function(){let s=function(p){return p+" bytes"};return{made:e,version:t,flags:n,method:we.methodToString(r),time:this.time,crc:"0x"+u.toString(16).toUpperCase(),compressedSize:s(o),size:s(a),fileNameLength:s(c),extraLength:s(E),commentLength:s(h),diskNumStart:w,inAttr:I,attr:f,offset:C,centralHeaderSize:s(y.CENHDR+c+E+h)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Li=J((Oa,Ti)=>{var qe=Ve(),z=qe.Constants;Ti.exports=function(){var e=0,t=0,n=0,r=0,i=0;return{get diskEntries(){return e},set diskEntries(u){e=t=u},get totalEntries(){return t},set totalEntries(u){t=e=u},get size(){return n},set size(u){n=u},get offset(){return r},set offset(u){r=u},get commentLength(){return i},set commentLength(u){i=u},get mainHeaderSize(){return z.ENDHDR+i},loadFromBinary:function(u){if((u.length!==z.ENDHDR||u.readUInt32LE(0)!==z.ENDSIG)&&(u.length<z.ZIP64HDR||u.readUInt32LE(0)!==z.ZIP64SIG))throw qe.Errors.INVALID_END();u.readUInt32LE(0)===z.ENDSIG?(e=u.readUInt16LE(z.ENDSUB),t=u.readUInt16LE(z.ENDTOT),n=u.readUInt32LE(z.ENDSIZ),r=u.readUInt32LE(z.ENDOFF),i=u.readUInt16LE(z.ENDCOM)):(e=qe.readBigUInt64LE(u,z.ZIP64SUB),t=qe.readBigUInt64LE(u,z.ZIP64TOT),n=qe.readBigUInt64LE(u,z.ZIP64SIZE),r=qe.readBigUInt64LE(u,z.ZIP64OFF),i=0)},toBinary:function(){var u=Buffer.alloc(z.ENDHDR+i);return u.writeUInt32LE(z.ENDSIG,0),u.writeUInt32LE(0,4),u.writeUInt16LE(e,z.ENDSUB),u.writeUInt16LE(t,z.ENDTOT),u.writeUInt32LE(n,z.ENDSIZ),u.writeUInt32LE(r,z.ENDOFF),u.writeUInt16LE(i,z.ENDCOM),u.fill(" ",z.ENDHDR),u},toJSON:function(){let u=function(o,a){let c=o.toString(16).toUpperCase();for(;c.length<a;)c="0"+c;return"0x"+c};return{diskEntries:e,totalEntries:t,size:n+" bytes",offset:u(r,4),commentLength:i}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Yn=J(Xn=>{Xn.EntryHeader=bi();Xn.MainHeader=Li()});var ki=J((Na,Mi)=>{Mi.exports=function(e){var t=require("zlib"),n={chunkSize:(parseInt(e.length/1024)+1)*1024};return{deflate:function(){return t.deflateRawSync(e,n)},deflateAsync:function(r){var i=t.createDeflateRaw(n),u=[],o=0;i.on("data",function(a){u.push(a),o+=a.length}),i.on("end",function(){var a=Buffer.alloc(o),c=0;a.fill(0);for(var E=0;E<u.length;E++){var h=u[E];h.copy(a,c),c+=h.length}r&&r(a)}),i.end(e)}}}});var ji=J((ba,Ui)=>{var ls=+(process.versions?process.versions.node:"").split(".")[0]||0;Ui.exports=function(e,t){var n=require("zlib");let r=ls>=15&&t>0?{maxOutputLength:t}:{};return{inflate:function(){return n.inflateRawSync(e,r)},inflateAsync:function(i){var u=n.createInflateRaw(r),o=[],a=0;u.on("data",function(c){o.push(c),a+=c.length}),u.on("end",function(){var c=Buffer.alloc(a),E=0;c.fill(0);for(var h=0;h<o.length;h++){var w=o[h];w.copy(c,E),E+=w.length}i&&i(c)}),u.end(e)}}}});var qi=J((Ta,Vi)=>{"use strict";var{randomFillSync:$i}=require("crypto"),ds=$t(),Ds=new Uint32Array(256).map((e,t)=>{for(let n=0;n<8;n++)(t&1)!==0?t=t>>>1^3988292384:t>>>=1;return t>>>0}),zi=(e,t)=>Math.imul(e,t)>>>0,Hi=(e,t)=>Ds[(e^t)&255]^e>>>8,ut=()=>typeof $i=="function"?$i(Buffer.alloc(12)):ut.node();ut.node=()=>{let e=Buffer.alloc(12),t=e.length;for(let n=0;n<t;n++)e[n]=Math.random()*256&255;return e};var Ht={genSalt:ut};function zt(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let n=0;n<t.length;n++)this.updateKeys(t[n])}zt.prototype.updateKeys=function(e){let t=this.keys;return t[0]=Hi(t[0],e),t[1]+=t[0]&255,t[1]=zi(t[1],134775813)+1,t[2]=Hi(t[2],t[1]>>>24),e};zt.prototype.next=function(){let e=(this.keys[2]|2)>>>0;return zi(e,e^1)>>8&255};function ps(e){let t=new zt(e);return function(n){let r=Buffer.alloc(n.length),i=0;for(let u of n)r[i++]=t.updateKeys(u^t.next());return r}}function Cs(e){let t=new zt(e);return function(n,r,i=0){r||(r=Buffer.alloc(n.length));for(let u of n){let o=t.next();r[i++]=u^o,t.updateKeys(u)}return r}}function Es(e,t,n){if(!e||!Buffer.isBuffer(e)||e.length<12)return Buffer.alloc(0);let r=ps(n),i=r(e.slice(0,12)),u=(t.flags&8)===8?t.timeHighByte:t.crc>>>24;if(i[11]!==u)throw ds.WRONG_PASSWORD();return r(e.slice(12))}function gs(e){Buffer.isBuffer(e)&&e.length>=12?Ht.genSalt=function(){return e.slice(0,12)}:e==="node"?Ht.genSalt=ut.node:Ht.genSalt=ut}function ms(e,t,n,r=!1){e==null&&(e=Buffer.alloc(0)),Buffer.isBuffer(e)||(e=Buffer.from(e.toString()));let i=Cs(n),u=Ht.genSalt();u[11]=t.crc>>>24&255,r&&(u[10]=t.crc>>>16&255);let o=Buffer.alloc(e.length+12);return i(u,o),i(e,o,12)}Vi.exports={decrypt:Es,encrypt:ms,_salter:gs}});var Zi=J(Vt=>{Vt.Deflater=ki();Vt.Inflater=ji();Vt.ZipCrypto=qi()});var er=J((Ma,Wi)=>{var M=Ve(),As=Yn(),W=M.Constants,Qn=Zi();Wi.exports=function(e,t){var n=new As.EntryHeader,r=Buffer.alloc(0),i=Buffer.alloc(0),u=!1,o=null,a=Buffer.alloc(0),c=Buffer.alloc(0),E=!0;let h=e,w=typeof h.decoder=="object"?h.decoder:M.decoder;E=w.hasOwnProperty("efs")?w.efs:!1;function I(){return!t||!(t instanceof Uint8Array)?Buffer.alloc(0):(c=n.loadLocalHeaderFromBinary(t),t.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function f(s){if(n.flags_desc){let p={},g=n.realDataOffset+n.compressedSize;if(t.readUInt32LE(g)==W.LOCSIG||t.readUInt32LE(g)==W.CENSIG)throw M.Errors.DESCRIPTOR_NOT_EXIST();if(t.readUInt32LE(g)==W.EXTSIG)p.crc=t.readUInt32LE(g+W.EXTCRC),p.compressedSize=t.readUInt32LE(g+W.EXTSIZ),p.size=t.readUInt32LE(g+W.EXTLEN);else if(t.readUInt16LE(g+12)===19280)p.crc=t.readUInt32LE(g+W.EXTCRC-4),p.compressedSize=t.readUInt32LE(g+W.EXTSIZ-4),p.size=t.readUInt32LE(g+W.EXTLEN-4);else throw M.Errors.DESCRIPTOR_UNKNOWN();if(p.compressedSize!==n.compressedSize||p.size!==n.size||p.crc!==n.crc)throw M.Errors.DESCRIPTOR_FAULTY();if(M.crc32(s)!==p.crc)return!1}else if(M.crc32(s)!==n.localHeader.crc)return!1;return!0}function C(s,p,g){if(typeof p>"u"&&typeof s=="string"&&(g=s,s=void 0),u)return s&&p&&p(Buffer.alloc(0),M.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var v=I();if(v.length===0)return s&&p&&p(v),v;if(n.encrypted){if(typeof g!="string"&&!Buffer.isBuffer(g))throw M.Errors.INVALID_PASS_PARAM();v=Qn.ZipCrypto.decrypt(v,n,g)}var F=Buffer.alloc(n.size);switch(n.method){case M.Constants.STORED:if(v.copy(F),f(F))return s&&p&&p(F),F;throw s&&p&&p(F,M.Errors.BAD_CRC()),M.Errors.BAD_CRC();case M.Constants.DEFLATED:var T=new Qn.Inflater(v,n.size);if(s)T.inflateAsync(function(L){L.copy(L,0),p&&(f(L)?p(L):p(L,M.Errors.BAD_CRC()))});else{if(T.inflate(F).copy(F,0),!f(F))throw M.Errors.BAD_CRC(`"${w.decode(r)}"`);return F}break;default:throw s&&p&&p(Buffer.alloc(0),M.Errors.UNKNOWN_METHOD()),M.Errors.UNKNOWN_METHOD()}}function l(s,p){if((!o||!o.length)&&Buffer.isBuffer(t))return s&&p&&p(I()),I();if(o.length&&!u){var g;switch(n.method){case M.Constants.STORED:return n.compressedSize=n.size,g=Buffer.alloc(o.length),o.copy(g),s&&p&&p(g),g;default:case M.Constants.DEFLATED:var v=new Qn.Deflater(o);if(s)v.deflateAsync(function(T){g=Buffer.alloc(T.length),n.compressedSize=T.length,T.copy(g),p&&p(g)});else{var F=v.deflate();return n.compressedSize=F.length,F}v=null;break}}else if(s&&p)p(Buffer.alloc(0));else return Buffer.alloc(0)}function D(s,p){return(s.readUInt32LE(p+4)<<4)+s.readUInt32LE(p)}function d(s){try{for(var p=0,g,v,F;p+4<s.length;)g=s.readUInt16LE(p),p+=2,v=s.readUInt16LE(p),p+=2,F=s.slice(p,p+v),p+=v,W.ID_ZIP64===g&&m(F)}catch{throw M.Errors.EXTRA_FIELD_PARSE_ERROR()}}function m(s){var p,g,v,F;s.length>=W.EF_ZIP64_SCOMP&&(p=D(s,W.EF_ZIP64_SUNCOMP),n.size===W.EF_ZIP64_OR_32&&(n.size=p)),s.length>=W.EF_ZIP64_RHO&&(g=D(s,W.EF_ZIP64_SCOMP),n.compressedSize===W.EF_ZIP64_OR_32&&(n.compressedSize=g)),s.length>=W.EF_ZIP64_DSN&&(v=D(s,W.EF_ZIP64_RHO),n.offset===W.EF_ZIP64_OR_32&&(n.offset=v)),s.length>=W.EF_ZIP64_DSN+4&&(F=s.readUInt32LE(W.EF_ZIP64_DSN),n.diskNumStart===W.EF_ZIP64_OR_16&&(n.diskNumStart=F))}return{get entryName(){return w.decode(r)},get rawEntryName(){return r},set entryName(s){r=M.toBuffer(s,w.encode);var p=r[r.length-1];u=p===47||p===92,n.fileNameLength=r.length},get efs(){return typeof E=="function"?E(this.entryName):E},get extra(){return a},set extra(s){a=s,n.extraLength=s.length,d(s)},get comment(){return w.decode(i)},set comment(s){if(i=M.toBuffer(s,w.encode),n.commentLength=i.length,i.length>65535)throw M.Errors.COMMENT_TOO_LONG()},get name(){var s=w.decode(r);return u?s.substr(s.length-1).split("/").pop():s.split("/").pop()},get isDirectory(){return u},getCompressedData:function(){return l(!1,null)},getCompressedDataAsync:function(s){l(!0,s)},setData:function(s){o=M.toBuffer(s,M.decoder.encode),!u&&o.length?(n.size=o.length,n.method=M.Constants.DEFLATED,n.crc=M.crc32(s),n.changed=!0):n.method=M.Constants.STORED},getData:function(s){return n.changed?o:C(!1,null,s)},getDataAsync:function(s,p){n.changed?s(o):C(!0,s,p)},set attr(s){n.attr=s},get attr(){return n.attr},set header(s){n.loadFromBinary(s)},get header(){return n},packCentralHeader:function(){n.flags_efs=this.efs,n.extraLength=a.length;var s=n.centralHeaderToBinary(),p=M.Constants.CENHDR;return r.copy(s,p),p+=r.length,a.copy(s,p),p+=n.extraLength,i.copy(s,p),s},packLocalHeader:function(){let s=0;n.flags_efs=this.efs,n.extraLocalLength=c.length;let p=n.localHeaderToBinary(),g=Buffer.alloc(p.length+r.length+n.extraLocalLength);return p.copy(g,s),s+=p.length,r.copy(g,s),s+=r.length,c.copy(g,s),s+=c.length,g},toJSON:function(){let s=function(p){return"<"+(p&&p.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:s(t),data:s(o)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ji=J((ka,Ki)=>{var Gi=er(),ys=Yn(),ie=Ve();Ki.exports=function(e,t){var n=[],r={},i=Buffer.alloc(0),u=new ys.MainHeader,o=!1,a=null;let c=new Set,E=t,{noSort:h,decoder:w}=E;e?C(E.readEntries):o=!0;function I(){let D=new Set;for(let d of Object.keys(r)){let m=d.split("/");if(m.pop(),!!m.length)for(let s=0;s<m.length;s++){let p=m.slice(0,s+1).join("/")+"/";D.add(p)}}for(let d of D)if(!(d in r)){let m=new Gi(E);m.entryName=d,m.attr=16,m.temporary=!0,n.push(m),r[m.entryName]=m,c.add(m)}}function f(){if(o=!0,r={},u.diskEntries>(e.length-u.offset)/ie.Constants.CENHDR)throw ie.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(u.diskEntries);for(var D=u.offset,d=0;d<n.length;d++){var m=D,s=new Gi(E,e);s.header=e.slice(m,m+=ie.Constants.CENHDR),s.entryName=e.slice(m,m+=s.header.fileNameLength),s.header.extraLength&&(s.extra=e.slice(m,m+=s.header.extraLength)),s.header.commentLength&&(s.comment=e.slice(m,m+s.header.commentLength)),D+=s.header.centralHeaderSize,n[d]=s,r[s.entryName]=s}c.clear(),I()}function C(D){var d=e.length-ie.Constants.ENDHDR,m=Math.max(0,d-65535),s=m,p=e.length,g=-1,v=0;for((typeof E.trailingSpace=="boolean"?E.trailingSpace:!1)&&(m=0),d;d>=s;d--)if(e[d]===80){if(e.readUInt32LE(d)===ie.Constants.ENDSIG){g=d,v=d,p=d+ie.Constants.ENDHDR,s=d-ie.Constants.END64HDR;continue}if(e.readUInt32LE(d)===ie.Constants.END64SIG){s=m;continue}if(e.readUInt32LE(d)===ie.Constants.ZIP64SIG){g=d,p=d+ie.readBigUInt64LE(e,d+ie.Constants.ZIP64SIZE)+ie.Constants.ZIP64LEAD;break}}if(g==-1)throw ie.Errors.INVALID_FORMAT();u.loadFromBinary(e.slice(g,p)),u.commentLength&&(i=e.slice(v+ie.Constants.ENDHDR)),D&&f()}function l(){n.length>1&&!h&&n.sort((D,d)=>D.entryName.toLowerCase().localeCompare(d.entryName.toLowerCase()))}return{get entries(){return o||f(),n.filter(D=>!c.has(D))},get comment(){return w.decode(i)},set comment(D){i=ie.toBuffer(D,w.encode),u.commentLength=i.length},getEntryCount:function(){return o?n.length:u.diskEntries},forEach:function(D){this.entries.forEach(D)},getEntry:function(D){return o||f(),r[D]||null},setEntry:function(D){o||f(),n.push(D),r[D.entryName]=D,u.totalEntries=n.length},deleteFile:function(D,d=!0){o||f();let m=r[D];this.getEntryChildren(m,d).map(p=>p.entryName).forEach(this.deleteEntry)},deleteEntry:function(D){o||f();let d=r[D],m=n.indexOf(d);m>=0&&(n.splice(m,1),delete r[D],u.totalEntries=n.length)},getEntryChildren:function(D,d=!0){if(o||f(),typeof D=="object")if(D.isDirectory&&d){let m=[],s=D.entryName;for(let p of n)p.entryName.startsWith(s)&&m.push(p);return m}else return[D];return[]},getChildCount:function(D){if(D&&D.isDirectory){let d=this.getEntryChildren(D);return d.includes(D)?d.length-1:d.length}return 0},compressToBuffer:function(){o||f(),l();let D=[],d=[],m=0,s=0;u.size=0,u.offset=0;let p=0;for(let F of this.entries){let T=F.getCompressedData();F.header.offset=s;let L=F.packLocalHeader(),K=L.length+T.length;s+=K,D.push(L),D.push(T);let k=F.packCentralHeader();d.push(k),u.size+=k.length,m+=K+k.length,p++}m+=u.mainHeaderSize,u.offset=s,u.totalEntries=p,s=0;let g=Buffer.alloc(m);for(let F of D)F.copy(g,s),s+=F.length;for(let F of d)F.copy(g,s),s+=F.length;let v=u.toBinary();return i&&i.copy(v,ie.Constants.ENDHDR),v.copy(g,s),e=g,o=!1,g},toAsyncBuffer:function(D,d,m,s){try{o||f(),l();let p=[],g=[],v=0,F=0,T=0;u.size=0,u.offset=0;let L=function(K){if(K.length>0){let k=K.shift(),ae=k.entryName+k.extra.toString();m&&m(ae),k.getCompressedDataAsync(function(oe){s&&s(ae),k.header.offset=F;let be=k.packLocalHeader(),st=be.length+oe.length;F+=st,p.push(be),p.push(oe);let Zt=k.packCentralHeader();g.push(Zt),u.size+=Zt.length,v+=st+Zt.length,T++,L(K)})}else{v+=u.mainHeaderSize,u.offset=F,u.totalEntries=T,F=0;let k=Buffer.alloc(v);p.forEach(function(oe){oe.copy(k,F),F+=oe.length}),g.forEach(function(oe){oe.copy(k,F),F+=oe.length});let ae=u.toBinary();i&&i.copy(ae,ie.Constants.ENDHDR),ae.copy(k,F),e=k,o=!1,D(k)}};L(Array.from(this.entries))}catch(p){d(p)}}}}});var Qi=J((Ua,Yi)=>{var V=Ve(),G=require("path"),hs=er(),Fs=Ji(),Ne=(...e)=>V.findLast(e,t=>typeof t=="boolean"),Xi=(...e)=>V.findLast(e,t=>typeof t=="string"),vs=(...e)=>V.findLast(e,t=>typeof t=="function"),_s={noSort:!1,readEntries:!1,method:V.Constants.NONE,fs:null};Yi.exports=function(e,t){let n=null,r=Object.assign(Object.create(null),_s);e&&typeof e=="object"&&(e instanceof Uint8Array||(Object.assign(r,e),e=r.input?r.input:void 0,r.input&&delete r.input),Buffer.isBuffer(e)&&(n=e,r.method=V.Constants.BUFFER,e=void 0)),Object.assign(r,t);let i=new V(r);if((typeof r.decoder!="object"||typeof r.decoder.encode!="function"||typeof r.decoder.decode!="function")&&(r.decoder=V.decoder),e&&typeof e=="string")if(i.fs.existsSync(e))r.method=V.Constants.FILE,r.filename=e,n=i.fs.readFileSync(e);else throw V.Errors.INVALID_FILENAME();let u=new Fs(n,r),{canonical:o,sanitize:a,zipnamefix:c}=V;function E(f){if(f&&u){var C;if(typeof f=="string"&&(C=u.getEntry(G.posix.normalize(f))),typeof f=="object"&&typeof f.entryName<"u"&&typeof f.header<"u"&&(C=u.getEntry(f.entryName)),C)return C}return null}function h(f){let{join:C,normalize:l,sep:D}=G.posix;return C(".",l(D+f.split("\\").join(D)+D))}function w(f){return f instanceof RegExp?(function(C){return function(l){return C.test(l)}})(f):typeof f!="function"?()=>!0:f}let I=(f,C)=>{let l=C.slice(-1);return l=l===i.sep?i.sep:"",G.relative(f,C)+l};return{readFile:function(f,C){var l=E(f);return l&&l.getData(C)||null},childCount:function(f){let C=E(f);if(C)return u.getChildCount(C)},readFileAsync:function(f,C){var l=E(f);l?l.getDataAsync(C):C(null,"getEntry failed for:"+f)},readAsText:function(f,C){var l=E(f);if(l){var D=l.getData();if(D&&D.length)return D.toString(C||"utf8")}return""},readAsTextAsync:function(f,C,l){var D=E(f);D?D.getDataAsync(function(d,m){if(m){C(d,m);return}d&&d.length?C(d.toString(l||"utf8")):C("")}):C("")},deleteFile:function(f,C=!0){var l=E(f);l&&u.deleteFile(l.entryName,C)},deleteEntry:function(f){var C=E(f);C&&u.deleteEntry(C.entryName)},addZipComment:function(f){u.comment=f},getZipComment:function(){return u.comment||""},addZipEntryComment:function(f,C){var l=E(f);l&&(l.comment=C)},getZipEntryComment:function(f){var C=E(f);return C&&C.comment||""},updateFile:function(f,C){var l=E(f);l&&l.setData(C)},addLocalFile:function(f,C,l,D){if(i.fs.existsSync(f)){C=C?h(C):"";let d=G.win32.basename(G.win32.normalize(f));C+=l||d;let m=i.fs.statSync(f),s=m.isFile()?i.fs.readFileSync(f):Buffer.alloc(0);m.isDirectory()&&(C+=i.sep),this.addFile(C,s,D,m)}else throw V.Errors.FILE_NOT_FOUND(f)},addLocalFileAsync:function(f,C){f=typeof f=="object"?f:{localPath:f};let l=G.resolve(f.localPath),{comment:D}=f,{zipPath:d,zipName:m}=f,s=this;i.fs.stat(l,function(p,g){if(p)return C(p,!1);d=d?h(d):"";let v=G.win32.basename(G.win32.normalize(l));if(d+=m||v,g.isFile())i.fs.readFile(l,function(F,T){return F?C(F,!1):(s.addFile(d,T,D,g),setImmediate(C,void 0,!0))});else if(g.isDirectory())return d+=i.sep,s.addFile(d,Buffer.alloc(0),D,g),setImmediate(C,void 0,!0)})},addLocalFolder:function(f,C,l){if(l=w(l),C=C?h(C):"",f=G.normalize(f),i.fs.existsSync(f)){let D=i.findFiles(f),d=this;if(D.length)for(let m of D){let s=G.join(C,I(f,m));l(s)&&d.addLocalFile(m,G.dirname(s))}}else throw V.Errors.FILE_NOT_FOUND(f)},addLocalFolderAsync:function(f,C,l,D){D=w(D),l=l?h(l):"",f=G.normalize(f);var d=this;i.fs.open(f,"r",function(m){if(m&&m.code==="ENOENT")C(void 0,V.Errors.FILE_NOT_FOUND(f));else if(m)C(void 0,m);else{var s=i.findFiles(f),p=-1,g=function(){if(p+=1,p<s.length){var v=s[p],F=I(f,v).split("\\").join("/");F=F.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),D(F)?i.fs.stat(v,function(T,L){T&&C(void 0,T),L.isFile()?i.fs.readFile(v,function(K,k){K?C(void 0,K):(d.addFile(l+F,k,"",L),g())}):(d.addFile(l+F+"/",Buffer.alloc(0),"",L),g())}):process.nextTick(()=>{g()})}else C(!0,void 0)};g()}})},addLocalFolderAsync2:function(f,C){let l=this;f=typeof f=="object"?f:{localPath:f},localPath=G.resolve(h(f.localPath));let{zipPath:D,filter:d,namefix:m}=f;d instanceof RegExp?d=(function(g){return function(v){return g.test(v)}})(d):typeof d!="function"&&(d=function(){return!0}),D=D?h(D):"",m=="latin1"&&(m=g=>g.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof m!="function"&&(m=g=>g);let s=g=>G.join(D,m(I(localPath,g))),p=g=>G.win32.basename(G.win32.normalize(m(g)));i.fs.open(localPath,"r",function(g){g&&g.code==="ENOENT"?C(void 0,V.Errors.FILE_NOT_FOUND(localPath)):g?C(void 0,g):i.findFilesAsync(localPath,function(v,F){if(v)return C(v);F=F.filter(T=>d(s(T))),F.length||C(void 0,!1),setImmediate(F.reverse().reduce(function(T,L){return function(K,k){if(K||k===!1)return setImmediate(T,K,!1);l.addLocalFileAsync({localPath:L,zipPath:G.dirname(s(L)),zipName:p(L)},T)}},C))})})},addLocalFolderPromise:function(f,C){return new Promise((l,D)=>{this.addLocalFolderAsync2(Object.assign({localPath:f},C),(d,m)=>{d&&D(d),m&&l(this)})})},addFile:function(f,C,l,D){f=c(f);let d=E(f),m=d!=null;m||(d=new hs(r),d.entryName=f),d.comment=l||"";let s=typeof D=="object"&&D instanceof i.fs.Stats;s&&(d.header.time=D.mtime);var p=d.isDirectory?16:0;let g=d.isDirectory?16384:32768;return s?g|=4095&D.mode:typeof D=="number"?g|=4095&D:g|=d.isDirectory?493:420,p=(p|g<<16)>>>0,d.attr=p,d.setData(C),m||u.setEntry(d),d},getEntries:function(f){return u.password=f,u?u.entries:[]},getEntry:function(f){return E(f)},getEntryCount:function(){return u.getEntryCount()},forEach:function(f){return u.forEach(f)},extractEntryTo:function(f,C,l,D,d,m){D=Ne(!1,D),d=Ne(!1,d),l=Ne(!0,l),m=Xi(d,m);var s=E(f);if(!s)throw V.Errors.NO_ENTRY();var p=o(s.entryName),g=a(C,m&&!s.isDirectory?m:l?p:G.basename(p));if(s.isDirectory){var v=u.getEntryChildren(s);return v.forEach(function(L){if(L.isDirectory)return;var K=L.getData();if(!K)throw V.Errors.CANT_EXTRACT_FILE();var k=o(L.entryName),ae=a(C,l?k:G.basename(k));let oe=d?L.header.fileAttr:void 0;i.writeFileTo(ae,K,D,oe)}),!0}var F=s.getData(u.password);if(!F)throw V.Errors.CANT_EXTRACT_FILE();if(i.fs.existsSync(g)&&!D)throw V.Errors.CANT_OVERRIDE();let T=d?f.header.fileAttr:void 0;return i.writeFileTo(g,F,D,T),!0},test:function(f){if(!u)return!1;for(var C in u.entries)try{if(C.isDirectory)continue;var l=u.entries[C].getData(f);if(!l)return!1}catch{return!1}return!0},extractAllTo:function(f,C,l,D){if(l=Ne(!1,l),D=Xi(l,D),C=Ne(!1,C),!u)throw V.Errors.NO_ZIP();u.entries.forEach(function(d){var m=a(f,o(d.entryName));if(d.isDirectory){i.makeDir(m);return}var s=d.getData(D);if(!s)throw V.Errors.CANT_EXTRACT_FILE();let p=l?d.header.fileAttr:void 0;i.writeFileTo(m,s,C,p);try{i.fs.utimesSync(m,d.header.time,d.header.time)}catch{throw V.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(f,C,l,D){if(D=vs(C,l,D),l=Ne(!1,l),C=Ne(!1,C),!D)return new Promise((g,v)=>{this.extractAllToAsync(f,C,l,function(F){F?v(F):g(this)})});if(!u){D(V.Errors.NO_ZIP());return}f=G.resolve(f);let d=g=>a(f,G.normalize(o(g.entryName))),m=(g,v)=>new Error(g+': "'+v+'"'),s=[],p=[];u.entries.forEach(g=>{g.isDirectory?s.push(g):p.push(g)});for(let g of s){let v=d(g),F=l?g.header.fileAttr:void 0;try{i.makeDir(v),F&&i.fs.chmodSync(v,F),i.fs.utimesSync(v,g.header.time,g.header.time)}catch{D(m("Unable to create folder",v))}}p.reverse().reduce(function(g,v){return function(F){if(F)g(F);else{let T=G.normalize(o(v.entryName)),L=a(f,T);v.getDataAsync(function(K,k){if(k)g(k);else if(!K)g(V.Errors.CANT_EXTRACT_FILE());else{let ae=l?v.header.fileAttr:void 0;i.writeFileToAsync(L,K,C,ae,function(oe){oe||g(m("Unable to write file",L)),i.fs.utimes(L,v.header.time,v.header.time,function(be){be?g(m("Unable to set times",L)):g()})})}})}}},D)()},writeZip:function(f,C){if(arguments.length===1&&typeof f=="function"&&(C=f,f=""),!f&&r.filename&&(f=r.filename),!!f){var l=u.compressToBuffer();if(l){var D=i.writeFileTo(f,l,!0);typeof C=="function"&&C(D?null:new Error("failed"),"")}}},writeZipPromise:function(f,C){let{overwrite:l,perm:D}=Object.assign({overwrite:!0},C);return new Promise((d,m)=>{!f&&r.filename&&(f=r.filename),f||m("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(s=>{let p=g=>g?d(g):m("ADM-ZIP: Wasn't able to write zip file");i.writeFileToAsync(f,s,l,D,p)},m)})},toBufferPromise:function(){return new Promise((f,C)=>{u.toAsyncBuffer(f,C)})},toBuffer:function(f,C,l,D){return typeof f=="function"?(u.toAsyncBuffer(f,C,l,D),null):u.compressToBuffer()}}}});var Ys={};gu(Ys,{CCR_DEFAULT_PORT:()=>Gt,CCR_PROJECT_HEADER:()=>Kt,CCR_SELF_PROVIDER_DELETED_FLAG:()=>Ln,CCR_SELF_PROVIDER_NAME:()=>Lt,CLAUDE_PROJECTS_DIR:()=>vu,CLIENT_IDS:()=>ke,CLIENT_STATE_FILE:()=>Jt,CONFIG_FILE:()=>Au,DEFAULT_CONFIG:()=>_u,DEFAULT_CONTEXT_WINDOW:()=>dn,HOME_DIR:()=>X,InputType:()=>Mn,MergeStrategy:()=>kn,NPM_SPEC_PATTERN:()=>dr,PID_FILE:()=>hu,PLUGINS_DIR:()=>yu,PLUGIN_ARCHIVE_MAX_BYTES:()=>de,PLUGIN_ARCHIVE_MAX_FILES:()=>Ke,PLUGIN_CORE_API:()=>dt,PLUGIN_ENTRY_FILE:()=>Re,PLUGIN_MANIFEST_FILE:()=>me,PLUGIN_NAME_PATTERN:()=>Xt,PLUGIN_NPM_PACK_TIMEOUT_MS:()=>Dr,PLUGIN_RECORDS_FILE:()=>lr,PRESETS_DIR:()=>Wt,PROJECT_TAKEOVER_CLIENT_IDS:()=>He,PluginInstallError:()=>P,REFERENCE_COUNT_FILE:()=>Fu,TOKEN_SPEED_TEMP_SUBDIRECTORY:()=>Mu,applyCcrProjectTakeover:()=>St,applyClientSelection:()=>No,applyConfigMappings:()=>tu,applyOpencodeProjectTakeover:()=>xt,applyPiProjectTakeover:()=>Pt,applyQwenProjectTakeover:()=>wt,applyUserInputs:()=>nu,applyZcodeProjectTakeover:()=>wn,assertArchiveWithinCaps:()=>yr,assertNoSymlinks:()=>rn,assertRecordsWritable:()=>gr,assertSafeNpmSpec:()=>en,buildDependencyGraph:()=>ru,createManifest:()=>Zs,deleteProjectConfig:()=>Mo,disableClient:()=>Nn,disableConfiguredClients:()=>To,downloadPresetToTemp:()=>Us,enableClient:()=>Bn,enableConfiguredClients:()=>bo,ensureCcrSelfProvider:()=>Ho,evaluateCondition:()=>tr,evaluateConditions:()=>ur,exportPreset:()=>Ws,extractMetadata:()=>Hs,extractPluginArchive:()=>Fr,extractPreset:()=>Ls,fillSensitiveInputs:()=>Zo,findMarketPresetByName:()=>Xs,generateEnvVarName:()=>ci,getAffectedFields:()=>Bs,getCcrTakeoverStatus:()=>ii,getClaudeProjectId:()=>Ge,getClaudeSettingsLocalPath:()=>bt,getClientConfig:()=>ee,getContextWindow:()=>et,getDefaultClientsConfig:()=>Yu,getDefaultValue:()=>xs,getDynamicOptions:()=>eu,getMarketPresets:()=>lu,getPiProjectProviderName:()=>nt,getPresetDir:()=>Ze,getProjectConfigDir:()=>Ee,getProjectConfigPath:()=>ft,getProjectTakeoverClients:()=>oi,getTempDir:()=>ou,getValueByPath:()=>Ss,installPluginFromArchive:()=>Pr,installPluginFromNpm:()=>Lu,isCcrProjectTakeoverActive:()=>tt,isCcrSelfProvider:()=>ai,isClientEnabled:()=>pn,isClientId:()=>Mr,isOpencodeProjectTakeoverActive:()=>Ot,isPiProjectTakeoverActive:()=>It,isPresetInstalled:()=>Vs,isProjectTakeoverClient:()=>Oo,isQwenProjectTakeoverActive:()=>Rt,isZcodeProjectTakeoverActive:()=>xn,listClientStatuses:()=>Bt,listPresets:()=>qs,listProjectConfigs:()=>ri,loadConfigFromManifest:()=>or,loadPreset:()=>js,manifestToPresetFile:()=>sr,mergeConfig:()=>Xo,npmPackPlugin:()=>vr,openSqliteDatabase:()=>Hu,openSqliteDatabaseWithLoaders:()=>Ir,parseFieldPath:()=>rr,pluginRecordsFile:()=>Dt,readClaudeSettingsLocal:()=>Tt,readManifestFromDir:()=>su,readPluginManifest:()=>nn,readPluginRecords:()=>Su,readPluginRecordsChecked:()=>Je,readPresetFile:()=>Gs,readProjectConfig:()=>ni,readProjectConfigById:()=>ko,refreshCcrProjectTakeover:()=>bn,refreshPiProjectTakeover:()=>Tn,refreshProjectTakeovers:()=>si,removeCcrProjectTakeover:()=>En,removeOpencodeProjectTakeover:()=>Sn,removePiProjectTakeover:()=>mn,removePluginRecord:()=>Pu,removeQwenProjectTakeover:()=>Fn,removeZcodeProjectTakeover:()=>Rn,replaceTemplateVariables:()=>ot,resolveOptions:()=>Is,resolvePluginPayloadDir:()=>pr,restoreClient:()=>Bo,sanitizeConfig:()=>jn,sanitizeTempFileKey:()=>ku,saveManifest:()=>zs,setCcrTakeover:()=>ui,setProjectTakeover:()=>jo,setValueByPath:()=>ir,shouldShowField:()=>Ps,sortFieldsByDependencies:()=>Os,stagePluginInstall:()=>_r,syncGlobalProjectTakeovers:()=>$o,unlinkSync:()=>S.unlinkSync,upsertPluginRecord:()=>mr,validateCardPayload:()=>Cr,validateInput:()=>Rs,validatePayload:()=>Sr,validatePluginManifest:()=>tn,validatePreset:()=>$s,writePluginRecords:()=>un,writeProjectConfig:()=>Lo});module.exports=mu(Ys);var le=re(require("node:path")),ct=re(require("node:os")),X=process.env.CCR_CONFIG_DIR||le.default.join(ct.default.homedir(),".claude-code-router"),Au=le.default.join(X,"config.json"),yu=le.default.join(X,"plugins"),Wt=le.default.join(X,"presets"),hu=le.default.join(X,".claude-code-router.pid"),Gt=3456,Kt="x-ccr-project",Jt=le.default.join(X,"client-state.json"),Fu=le.default.join(ct.default.tmpdir(),"claude-code-reference-count.txt"),vu=le.default.join(ct.default.homedir(),".claude","projects");function Ge(e){return e.replace(/[\\/.]/g,"-")}function Ee(e=process.cwd()){return le.default.join(X,Ge(e))}function ft(e=process.cwd()){return le.default.join(Ee(e),"config.json")}var _u={LOG:!1,OPENAI_API_KEY:"",OPENAI_BASE_URL:"",OPENAI_MODEL:""};var fr=require("child_process"),S=require("fs"),Yt=require("os"),B=require("path"),Qt=require("zlib"),dt="1",me="plugin.json",Re="plugin.js",lr="plugins.json",Xt=/^[a-z0-9][a-z0-9-]*$/i,dr=/^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/,de=25*1024*1024,Ke=2e3,Dr=3e4,P=class extends Error{code;constructor(t,n){super(t),this.name="PluginInstallError",this.code=n}};function en(e){if(typeof e!="string"||e.length===0||e.length>214||e.startsWith("-")||!dr.test(e))throw new P(`invalid plugin package request ${JSON.stringify(String(e??""))} (only npm package names are allowed)`,"invalid_spec")}function tn(e,t){let n=e;if(typeof n.name!="string"||n.name.length===0)throw new P(`${me} has no "name"`,"invalid_manifest");if(!Xt.test(n.name))throw new P(`invalid plugin name "${n.name}" (must match ${Xt.toString()})`,"invalid_manifest");if(typeof n.version!="string"||n.version.length===0)throw new P(`${me} for "${n.name}" has no "version"`,"invalid_manifest");let r=String(n.coreApi??dt);if(r.split(".")[0]!==dt)throw new P(`plugin "${n.name}" declares coreApi ${r}, incompatible with this CCR (core ${dt})`,"invalid_manifest");if(t!==void 0&&n.name!==t)throw new P(`manifest name "${n.name}" does not match install directory name "${t}"`,"invalid_manifest");return{name:n.name,version:n.version,coreApi:r,description:typeof n.description=="string"?n.description:void 0}}function nn(e){let t;try{t=(0,S.readFileSync)((0,B.join)(e,me),"utf8")}catch{throw new P(`${me} not found in ${e}`,"invalid_manifest")}let n;try{n=JSON.parse(t)}catch(r){throw new P(`${me} is not valid JSON: ${r.message}`,"invalid_manifest")}if(!n||typeof n!="object"||Array.isArray(n))throw new P(`${me} is not a JSON object`,"invalid_manifest");return n}function pr(e){for(let t of[e,(0,B.join)(e,"dist")])if((0,S.existsSync)((0,B.join)(t,me))&&(0,S.existsSync)((0,B.join)(t,Re)))return t;return null}function rn(e){let t=[e];for(;t.length>0;){let n=t.pop();for(let r of(0,S.readdirSync)(n,{withFileTypes:!0})){if(r.isSymbolicLink())throw new P(`refusing to install: payload contains a symlink "${(0,B.join)(n,r.name)}"`,"unsafe_archive_member");r.isDirectory()&&t.push((0,B.join)(n,r.name))}}}function Cr(e,t){let n=typeof t.card=="string"?t.card:typeof t.ui?.card=="string"?t.ui.card:void 0;if(typeof n=="string"&&n.length>0){if(!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(n))throw new P(`manifest declares an unsafe UI card path "${n}" (must be a plain file inside the payload)`,"unsafe_archive_member");if(!(0,S.existsSync)((0,B.join)(e,n)))throw new P(`manifest declares UI card "${n}" but the file is missing from the payload`,"invalid_manifest")}}function Dt(e){return(0,B.join)(e,"plugins",lr)}function Je(e){let t;try{t=(0,S.readFileSync)(Dt(e),"utf8")}catch{return{records:[],corrupted:!1}}try{let n=JSON.parse(t);return Array.isArray(n)?{records:n.filter(r=>r&&typeof r.name=="string").map(r=>({name:r.name,enabled:r.enabled!==!1,...typeof r.source=="string"&&r.source?{source:r.source}:{}})),corrupted:!1}:{records:[],corrupted:!0}}catch{return{records:[],corrupted:!0}}}function Su(e){return Je(e).records}function un(e,t){(0,S.mkdirSync)((0,B.join)(e,"plugins"),{recursive:!0}),(0,S.writeFileSync)(Dt(e),JSON.stringify(t,null,2)+`
|
|
15
|
-
`)}function Er(e){return new P(`${Dt(e)} is not valid JSON; refusing to overwrite it. Fix or remove the file (or pass --force to replace it with only the new record).`,"plugins_json_corrupted")}function gr(e,t){if(!t&&Je(e).corrupted)throw Er(e)}function mr(e,t,n=!1,r){let{records:i,corrupted:u}=Je(e);if(u&&!n)throw Er(e);let o=i.findIndex(E=>E.name===t),a={name:t,enabled:!0},c=typeof r=="string"&&r?r:o>=0?i[o].source:void 0;c&&(a.source=c),o>=0?i[o]=a:i.push(a),un(e,i)}function Pu(e,t){let{records:n,corrupted:r}=Je(e);if(r)return!1;let i=n.filter(u=>u.name!==t);return i.length===n.length?!1:(un(e,i),!0)}var ge=512;function Iu(e,t,n){if(e[t]&128)return 0;let r="";for(let u=0;u<n;u++){let o=e[t+u];o===0||o===32||(r+=String.fromCharCode(o))}if(!r)return 0;let i=parseInt(r.trim(),8);return Number.isFinite(i)?i:0}function wu(e,t){let n=e.subarray(148,156),r=Te(n,0,8).replace(/[ \0]/g,"");if(!/^[0-7]+$/.test(r))throw new P(`plugin archive has a corrupt tar header${t?` (near "${t}")`:""}`,"unsafe_archive_member");let i=parseInt(r,8);if(i===0)return;let u=0,o=0;for(let a=0;a<ge;a++){let c=a>=148&&a<156?32:e[a];u+=c,o+=c>127?c-256:c}if(i!==u&&i!==o)throw new P(`plugin archive has a corrupt tar header${t?` (near "${t}")`:""}`,"unsafe_archive_member")}function Te(e,t,n){let r=t,i=t+n;for(;r<i&&e[r]!==0;)r++;return e.toString("utf8",t,r)}function Ru(e){let t={},n=0;for(;n<e.length;){let r=n;for(;r<e.length&&e[r]!==32;)r++;if(r>=e.length)break;let i=parseInt(e.toString("utf8",n,r),10);if(!Number.isFinite(i)||i<=0)break;let u=n+i,o=e.indexOf(10,r+1),a=o>=0&&o<u?o:u-1,c=e.toString("utf8",r+1,a),E=c.indexOf("=");E>0&&(t[c.slice(0,E)]=c.slice(E+1)),n=u}return t}function xu(e,t){if(e.path!==void 0&&(t.path=e.path),e.linkpath!==void 0&&(t.linkpath=e.linkpath),e.size!==void 0){if(!/^\d+$/.test(e.size))throw new P(`plugin archive has a malformed PAX size record "${e.size}"`,"unsafe_archive_member");let n=Number(e.size);if(!Number.isSafeInteger(n)||n<0)throw new P(`plugin archive has an out-of-range PAX size record "${e.size}"`,"unsafe_archive_member");t.size=n}}async function Ar(e){let t=[],n=Buffer.alloc(0),r=0,i=0,u={},o={},a=null,c=0,E=0,h=(I,f)=>{let C=0;for(;!(I.length-C<ge);){let l=I.subarray(C,C+ge);if(l.every(st=>st===0))return{rest:Buffer.alloc(0),ended:!0};let D=String.fromCharCode(l[156]??48),d=Te(l,257,6),m=d.startsWith("ustar")?Te(l,345,155):"",s=Te(l,0,100),p=d.startsWith("ustar"),g=s.length>0&&/^[ -~]+$/.test(s),v=/^[0-7]+$/.test(Te(l,124,12).replace(/[ \0]/g,"")||"0");if(!p&&!(g&&v)){if(E>i+I.length)throw new P("plugin archive is truncated (member data missing)","extract_failed");return{rest:Buffer.alloc(0),ended:!0}}wu(l,m?`${m}/${s}`:s);let F=Iu(l,124,12),T=o.size??F;if(E+=T,E>de)throw new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large");let L=Math.ceil(T/ge),K=ge+L*ge;if(I.length-C<K){if(!f)throw new P("plugin archive is truncated (member data missing)","extract_failed");if(C===0)break;break}let k=i+C,ae=I.subarray(C+ge,C+ge+T);if(C+=K,D==="x"||D==="g"){xu(Ru(ae),D==="g"?u:o);continue}if(D==="L"){a=Te(ae,0,ae.length);continue}if(D==="K")continue;let oe=a??o.path??u.path??(m?`${m}/${s}`:s),be=o.linkpath??u.linkpath;if(a=null,o={},!oe.replace(/\/$/,""))throw new P("refusing archive member with an empty name","unsafe_archive_member");if(t.push({name:oe.replace(/\/$/,""),size:T,type:D,linkTarget:be,dataOffset:k+ge}),(D==="0"||D==="\0"||D==="7")&&(c+=1),c>Ke)throw new P(`plugin payload contains more than ${Ke} files`,"archive_too_many_files")}return{rest:I.subarray(C),ended:!1}},w=(0,S.createReadStream)(e).pipe((0,Qt.createGunzip)());try{for await(let I of w){if(r+=I.length,r>de)throw w.destroy(),new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large");n=n.length?Buffer.concat([n,I]):Buffer.from(I);let f=n.length,C=h(n,!0);if(i+=f-C.rest.length,n=C.rest,C.ended)return t}}catch(I){throw I instanceof P?I:new P(`failed to read plugin archive: ${I?.message??I}`,"extract_failed")}return h(n,!1),t}function Ou(e){if(e.startsWith("/")||e.startsWith("\\")||/^[a-zA-Z]:/.test(e)||e.split("/").some(t=>t===".."))throw new P(`refusing to extract unsafe archive member "${e}"`,"unsafe_archive_member")}async function yr(e){let t=(0,S.statSync)(e).size;if(t>de)throw new P(`plugin archive is ${t} bytes (limit ${de} bytes)`,"archive_too_large");hr(await Ar(e))}function hr(e){let t=0,n=0;for(let r of e){if(Ou(r.name),r.type==="2"||r.type==="1")throw new P(`refusing to extract archive link "${r.name}" (symlinks/hardlinks are not allowed in plugins)`,"unsafe_archive_member");if("346".includes(r.type)||r.type==="S"||r.type==="V")throw new P(`refusing to extract special archive member "${r.name}"`,"unsafe_archive_member");(r.type==="0"||r.type==="\0"||r.type==="7")&&(t+=r.size,n+=1)}if(t>de)throw new P(`plugin payload is ${t} bytes uncompressed (limit ${de} bytes)`,"archive_too_large");if(n>Ke)throw new P(`plugin payload contains ${n} files (limit ${Ke})`,"archive_too_many_files")}async function Fr(e,t){(0,S.mkdirSync)(t,{recursive:!0});let n=await Ar(e);hr(n);let r=(0,B.resolve)(t),i=E=>{let h=(0,B.resolve)(E);if(h!==r&&!h.startsWith(r+B.sep))throw new P(`refusing to extract "${E}" outside the target directory`,"unsafe_archive_member");return h},u=(0,S.createReadStream)(e).pipe((0,Qt.createGunzip)()),o=[];try{for await(let E of u)if(o.push(E),o.reduce((h,w)=>h+w.length,0)>de)throw u.destroy(),new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large")}catch(E){throw E instanceof P?E:new P(`failed to extract ${(0,B.basename)(e)}: ${E?.message??E}`,"extract_failed")}let a=Buffer.concat(o.map(E=>Buffer.from(E)));for(let E of n){let h=i((0,B.join)(t,E.name));if(E.type==="5"){(0,S.mkdirSync)(h,{recursive:!0});continue}if(E.type!=="0"&&E.type!=="\0"&&E.type!=="7")continue;if(!E.name)throw new P("refusing to extract archive member with an empty name","unsafe_archive_member");let w=E.dataOffset+E.size;if(w>a.length)throw new P(`plugin archive is truncated (member "${E.name}" data missing)`,"extract_failed");(0,S.mkdirSync)((0,B.dirname)(h),{recursive:!0}),(0,S.writeFileSync)(h,a.subarray(E.dataOffset,w),{mode:420})}rn(t);let c=(0,B.join)(t,"package");return(0,S.existsSync)(c)&&(0,S.statSync)(c).isDirectory()?c:t}function Bu(e,t){let n=new Set(["PATH","Path","path","TZ","LANG","LC_ALL","SYSTEMROOT","COMSPEC","APPDATA","LOCALAPPDATA","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","http_proxy","https_proxy","no_proxy"]),r={};for(let o of Object.keys(process.env))n.has(o)&&(r[o]=process.env[o]);r.HOME=e,r.USERPROFILE=e,r.TMPDIR=e,r.TEMP=e,r.TMP=e,r.CCR_CONFIG_DIR=process.env.CCR_CONFIG_DIR;let i=(0,B.join)(e,"npmrc"),u=(0,B.join)(e,"npmrc-global");return(0,S.writeFileSync)(i,"",{mode:384}),(0,S.writeFileSync)(u,"",{mode:384}),r.npm_config_userconfig=i,r.npm_config_globalconfig=u,r.npm_config_cache=t,r}async function vr(e,t,n={}){en(e),(0,S.mkdirSync)(t,{recursive:!0});let r=n.homeDir??(0,B.join)(t,"npm-home"),i=n.cacheDir??(0,B.join)(t,"npm-cache");(0,S.mkdirSync)(r,{recursive:!0}),(0,S.mkdirSync)(i,{recursive:!0});let u=["pack","--json","--prefer-offline","--ignore-scripts","--no-audit","--no-fund"];n.registry&&u.push("--registry",n.registry),u.push("--pack-destination",t,e);let o;try{o=await new Promise((E,h)=>{(0,fr.execFile)("npm",u,{cwd:t,encoding:"utf8",maxBuffer:16777216,timeout:n.timeoutMs??Dr,killSignal:"SIGKILL",env:Bu(r,i)},(I,f)=>{I?h(I):E(String(f??""))}).stdin?.end()})}catch(E){throw E?.killed||E?.signal==="SIGTERM"||E?.code==="ETIMEDOUT"?new P(`npm pack timed out for "${e}"`,"npm_pack_timeout"):new P(`npm pack failed for "${e}"`,"npm_pack_failed")}let a;try{a=JSON.parse(o)}catch{throw new P(`npm pack returned unexpected output for "${e}"`,"npm_pack_failed")}let c=a?.[0]?.filename;if(!c||c.includes("/")||c.includes("\\")||c.includes(".."))throw new P(`npm pack produced no archive for "${e}"`,"npm_pack_failed");return(0,B.join)(t,c)}function Nu(e){try{return(0,S.lstatSync)(e),!0}catch{return!1}}function _r(e,t,n,r,i){let u=(0,B.join)(n,"plugins");if((0,S.mkdirSync)(u,{recursive:!0}),(0,S.lstatSync)(u).isSymbolicLink()||!(0,S.lstatSync)(u).isDirectory())throw new P(`plugins directory is not a real directory: ${u}`,"unsafe_archive_member");let o=(0,B.join)(u,t.name);if((0,S.existsSync)(o)&&!r)throw new P(`plugin "${t.name}" is already installed at ${o} (use --force to replace it)`,"already_installed");gr(n,r);let a=(0,B.join)(u,`.${t.name}.staging-${process.pid}-${Date.now()}`);(0,S.mkdirSync)(a,{recursive:!0});try{(0,S.cpSync)(e,a,{recursive:!0});let c=tn(nn(a),t.name);if(!(0,S.existsSync)((0,B.join)(a,Re)))throw new P(`staged payload is missing its entry ${Re}`,"invalid_manifest");Nu(o)&&(0,S.rmSync)(o,{recursive:!0,force:!0}),(0,S.renameSync)(a,o),mr(n,c.name,r,i)}catch(c){throw(0,S.rmSync)(a,{recursive:!0,force:!0}),c}return o}function Sr(e){let t=nn(e),n=tn(t);if(!(0,S.existsSync)((0,B.join)(e,Re)))throw new P(`plugin entry ${Re} is missing from the payload`,"invalid_manifest");return Cr(e,t),rn(e),{manifest:n,raw:t}}async function Pr(e,t){return Tu(t.configDir,()=>bu(e,t))}async function bu(e,t){let n=t.tempRoot??(0,S.mkdtempSync)((0,B.join)((0,Yt.tmpdir)(),"ccr-plugin-add-")),r=t.tempRoot===void 0;try{await yr(e);let i=await Fr(e,(0,B.join)(n,"extract")),u=pr(i);if(!u)throw new P(`no ${me} + ${Re} found in ${e}`,"invalid_manifest");let{manifest:o}=Sr(u);return{target:_r(u,o,t.configDir,t.force??!1,t.source),manifest:o}}finally{r&&(0,S.rmSync)(n,{recursive:!0,force:!0})}}var lt=new Map;async function Tu(e,t){let n=(0,B.resolve)(e),r=lt.get(n)??Promise.resolve(),i,u=new Promise(a=>{i=a}),o=r.then(()=>u);lt.set(n,o),await r;try{return await t()}finally{i(),lt.get(n)===o&<.delete(n)}}async function Lu(e){en(e.spec);let t=e.tempRoot??(0,S.mkdtempSync)((0,B.join)((0,Yt.tmpdir)(),"ccr-plugin-add-")),n=e.tempRoot===void 0;try{let r=await vr(e.spec,(0,B.join)(t,"pack"),{registry:e.registry,cacheDir:e.cacheDir??(0,B.join)(t,"npm-cache"),homeDir:e.homeDir??(0,B.join)(t,"npm-home"),timeoutMs:e.timeoutMs});return await Pr(r,{configDir:e.configDir,force:e.force,tempRoot:t,source:e.spec})}finally{n&&(0,S.rmSync)(t,{recursive:!0,force:!0})}}var Mu="claude-code-router/token-speed-v2";function ku(e){return e.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,200)}function Uu(e){let t=e;return t?t.code==="ERR_DLOPEN_FAILED"||t.code==="MODULE_NOT_FOUND"||/NODE_MODULE_VERSION|was compiled against|Could not locate the bindings file|Dynamic require of/i.test(t.message??""):!1}function ju(e,t){let n=require("better-sqlite3");return t?new n(e,{readonly:!0,fileMustExist:!0}):new n(e)}function $u(e,t){let{DatabaseSync:n}=require("node:sqlite"),r=t?new n(e,{readOnly:!0}):new n(e);return{exec(u){r.exec(u)},prepare(u){let o=r.prepare(u);return{run(...a){let c=o.run(...a);return{changes:c.changes,lastInsertRowid:c.lastInsertRowid}},get:(...a)=>o.get(...a),all:(...a)=>o.all(...a)}},pragma(u,o){if(o?.simple){let a=r.prepare(`PRAGMA ${u}`).get();return a===void 0?void 0:Object.values(a)[0]}r.exec(`PRAGMA ${u}`)},transaction(u){return(...a)=>{r.exec("BEGIN");try{let c=u(...a);return r.exec("COMMIT"),c}catch(c){try{r.exec("ROLLBACK")}catch{}throw c}}},close(){r.close()}}}function Hu(e,t){return Ir(e,t,ju)}function Ir(e,t,n){let r=t?.readonly??!1;try{return{db:n(e,r),driver:"better-sqlite3"}}catch(i){if(!Uu(i))throw i;try{return{db:$u(e,r),driver:"node:sqlite",fallbackReason:i?.message??String(i)}}catch(u){let o=u;throw new Error(`No usable SQLite driver: better-sqlite3 failed to load (${i?.message}) and node:sqlite is unavailable (${o?.message}). Fix with: npm rebuild better-sqlite3 --runtime node --target <your node major> inside the claude-code-router package, or run ccr with Node >= 22.5.`)}}}var x=re(require("node:fs")),cn=re(require("node:os")),H=re(require("node:path")),Nr=require("node:crypto");var ke=["claudeCode","codex","pi","qwenCode","opencode"],ce={claudeCode:{id:"claudeCode",name:"Claude Code",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.claude/settings.json",modelAlias:"",quota:{}}},codex:{id:"codex",name:"Codex",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.codex/config.toml",modelAlias:"ccr-opus",quota:{}}},pi:{id:"pi",name:"pi",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.pi/agent",modelAlias:"ccr-opus",quota:{}}},qwenCode:{id:"qwenCode",name:"Qwen Code",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.qwen/settings.json",modelAlias:"ccr-opus",quota:{}}},opencode:{id:"opencode",name:"opencode",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.config/opencode/opencode.json",modelAlias:"ccr-opus",quota:{}}}},br=H.default.join(X,"backups","clients"),on=H.default.join(X,".statusline-backup.json"),sn=H.default.join(X,".model-env-backup.json"),vt=["ANTHROPIC_MODEL","ANTHROPIC_DEFAULT_SONNET_MODEL","ANTHROPIC_DEFAULT_OPUS_MODEL","ANTHROPIC_DEFAULT_HAIKU_MODEL","ANTHROPIC_REASONING_MODEL"],ln={CLAUDE_CODE_AUTO_COMPACT_WINDOW:"200000",CLAUDE_AUTOCOMPACT_PCT_OVERRIDE:"90",CLAUDE_CODE_SIMPLE:"1"},dn=2e5;function _(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function et(e){let t=e?.ContextWindow;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.floor(t);if(typeof t=="string"&&/^\d+$/.test(t.trim())){let n=parseInt(t.trim(),10);if(n>0)return n}return dn}function Dn(){return Jt}function zu(e){return H.default.join(Ee(e),"ccr-state.json")}function Vu(e){return N(e)}function qu(e){let t=N(Dn());return t&&t[e]||{}}function Zu(e,t){U(e,t)}function Wu(e,t){let n=Dn(),r=N(n);r[e]=t,U(n,r)}function Tr(e){try{x.default.existsSync(e)&&x.default.unlinkSync(e)}catch{}}function Gu(e){let t=Dn(),n=N(t);n&&n[e]&&(delete n[e],Object.keys(n).length>0?U(t,n):Tr(t))}function wr(e){return{read:()=>qu(e),write:t=>Wu(e,t),clear:()=>Gu(e)}}function Lr(e){if(!e)return;let t=zu(e);return{read:()=>Vu(t),write:n=>Zu(t,n),clear:()=>Tr(t)}}function Se(e){return e instanceof Error?e.message:String(e)}function _t(e){return e==="~"?cn.default.homedir():e.startsWith("~/")?H.default.join(cn.default.homedir(),e.slice(2)):e}function Ku(e){return ce[e]}function Ju(e,t){let r=(_(e.Clients)?e.Clients:{})[t];return _(r)?r:{}}function Ue(e){let t=e?.Router?.families;return _(t)&&Object.keys(t).length>0}function Xu(e){return!!(e?.StatusLine?.enabled||Ue(e))}function Yu(){return{claudeCode:{...ce.claudeCode.defaultConfig},codex:{...ce.codex.defaultConfig},pi:{...ce.pi.defaultConfig},qwenCode:{...ce.qwenCode.defaultConfig},opencode:{...ce.opencode.defaultConfig}}}function ee(e,t){let n=Ku(t),r=Ju(e,t),u=typeof r.enabled=="boolean"?!!r.enabled:t==="claudeCode"&&!_(e.Clients)?Xu(e):n.defaultConfig.enabled;return{...n.defaultConfig,...r,enabled:u,managed:!!r.managed,configPath:r.configPath||n.defaultConfig.configPath,modelAlias:r.modelAlias||n.defaultConfig.modelAlias}}function Mr(e){return ke.includes(e)}function pn(e,t){return ee(e,t).enabled}function Qu(e,t,n){let r=_(e.Clients)?{...e.Clients}:{},u={...ee(e,t),...n};return r[t]=u,e.Clients=r,u}function _e(e,t){return _t(ee(e,t).configPath)}function Cn(e){let t=H.default.dirname(e);x.default.existsSync(t)||x.default.mkdirSync(t,{recursive:!0})}function Le(e,t){if(!x.default.existsSync(t))return null;let n=H.default.join(br,e);x.default.mkdirSync(n,{recursive:!0});let r=new Date().toISOString().replace(/[:.]/g,"-"),i=H.default.extname(t)||".bak",u=H.default.join(n,`${r}${i}`);return x.default.copyFileSync(t,u),u}function eo(e){let t=H.default.join(br,e);if(!x.default.existsSync(t))return null;let n=x.default.readdirSync(t).filter(r=>!r.startsWith(".")).sort();return n.length===0?null:H.default.join(t,n[n.length-1])}function Me(e,t){let n=eo(e);return n?(Cn(t),x.default.copyFileSync(n,t),n):null}var ht=H.default.join(X,"pi-provider-snapshots.json");function to(e,t,n){let r=N(ht),i=_(r[e])?r[e]:{};i[t]=n,r[e]=i,U(ht,r)}function no(e,t){let n=N(ht),r=n[e],i=_(r)?r[t]:void 0;if(_(i))return delete r[t],Object.keys(r).length===0&&delete n[e],U(ht,n),i}function N(e){if(!x.default.existsSync(e))return{};let t;try{t=x.default.readFileSync(e,"utf-8")}catch{return{}}if(!t.trim())return{};let n;try{n=JSON.parse(t)}catch{return{}}return _(n)?n:{}}function U(e,t){let n=`${JSON.stringify(t,null,2)}
|
|
15
|
+
`)}function Er(e){return new P(`${Dt(e)} is not valid JSON; refusing to overwrite it. Fix or remove the file (or pass --force to replace it with only the new record).`,"plugins_json_corrupted")}function gr(e,t){if(!t&&Je(e).corrupted)throw Er(e)}function mr(e,t,n=!1,r){let{records:i,corrupted:u}=Je(e);if(u&&!n)throw Er(e);let o=i.findIndex(E=>E.name===t),a={name:t,enabled:!0},c=typeof r=="string"&&r?r:o>=0?i[o].source:void 0;c&&(a.source=c),o>=0?i[o]=a:i.push(a),un(e,i)}function Pu(e,t){let{records:n,corrupted:r}=Je(e);if(r)return!1;let i=n.filter(u=>u.name!==t);return i.length===n.length?!1:(un(e,i),!0)}var ge=512;function Iu(e,t,n){if(e[t]&128)return 0;let r="";for(let u=0;u<n;u++){let o=e[t+u];o===0||o===32||(r+=String.fromCharCode(o))}if(!r)return 0;let i=parseInt(r.trim(),8);return Number.isFinite(i)?i:0}function wu(e,t){let n=e.subarray(148,156),r=Te(n,0,8).replace(/[ \0]/g,"");if(!/^[0-7]+$/.test(r))throw new P(`plugin archive has a corrupt tar header${t?` (near "${t}")`:""}`,"unsafe_archive_member");let i=parseInt(r,8);if(i===0)return;let u=0,o=0;for(let a=0;a<ge;a++){let c=a>=148&&a<156?32:e[a];u+=c,o+=c>127?c-256:c}if(i!==u&&i!==o)throw new P(`plugin archive has a corrupt tar header${t?` (near "${t}")`:""}`,"unsafe_archive_member")}function Te(e,t,n){let r=t,i=t+n;for(;r<i&&e[r]!==0;)r++;return e.toString("utf8",t,r)}function Ru(e){let t={},n=0;for(;n<e.length;){let r=n;for(;r<e.length&&e[r]!==32;)r++;if(r>=e.length)break;let i=parseInt(e.toString("utf8",n,r),10);if(!Number.isFinite(i)||i<=0)break;let u=n+i,o=e.indexOf(10,r+1),a=o>=0&&o<u?o:u-1,c=e.toString("utf8",r+1,a),E=c.indexOf("=");E>0&&(t[c.slice(0,E)]=c.slice(E+1)),n=u}return t}function xu(e,t){if(e.path!==void 0&&(t.path=e.path),e.linkpath!==void 0&&(t.linkpath=e.linkpath),e.size!==void 0){if(!/^\d+$/.test(e.size))throw new P(`plugin archive has a malformed PAX size record "${e.size}"`,"unsafe_archive_member");let n=Number(e.size);if(!Number.isSafeInteger(n)||n<0)throw new P(`plugin archive has an out-of-range PAX size record "${e.size}"`,"unsafe_archive_member");t.size=n}}async function Ar(e){let t=[],n=Buffer.alloc(0),r=0,i=0,u={},o={},a=null,c=0,E=0,h=(I,f)=>{let C=0;for(;!(I.length-C<ge);){let l=I.subarray(C,C+ge);if(l.every(st=>st===0))return{rest:Buffer.alloc(0),ended:!0};let D=String.fromCharCode(l[156]??48),d=Te(l,257,6),m=d.startsWith("ustar")?Te(l,345,155):"",s=Te(l,0,100),p=d.startsWith("ustar"),g=s.length>0&&/^[ -~]+$/.test(s),v=/^[0-7]+$/.test(Te(l,124,12).replace(/[ \0]/g,"")||"0");if(!p&&!(g&&v)){if(E>i+I.length)throw new P("plugin archive is truncated (member data missing)","extract_failed");return{rest:Buffer.alloc(0),ended:!0}}wu(l,m?`${m}/${s}`:s);let F=Iu(l,124,12),T=o.size??F;if(E+=T,E>de)throw new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large");let L=Math.ceil(T/ge),K=ge+L*ge;if(I.length-C<K){if(!f)throw new P("plugin archive is truncated (member data missing)","extract_failed");if(C===0)break;break}let k=i+C,ae=I.subarray(C+ge,C+ge+T);if(C+=K,D==="x"||D==="g"){xu(Ru(ae),D==="g"?u:o);continue}if(D==="L"){a=Te(ae,0,ae.length);continue}if(D==="K")continue;let oe=a??o.path??u.path??(m?`${m}/${s}`:s),be=o.linkpath??u.linkpath;if(a=null,o={},!oe.replace(/\/$/,""))throw new P("refusing archive member with an empty name","unsafe_archive_member");if(t.push({name:oe.replace(/\/$/,""),size:T,type:D,linkTarget:be,dataOffset:k+ge}),(D==="0"||D==="\0"||D==="7")&&(c+=1),c>Ke)throw new P(`plugin payload contains more than ${Ke} files`,"archive_too_many_files")}return{rest:I.subarray(C),ended:!1}},w=(0,S.createReadStream)(e).pipe((0,Qt.createGunzip)());try{for await(let I of w){if(r+=I.length,r>de)throw w.destroy(),new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large");n=n.length?Buffer.concat([n,I]):Buffer.from(I);let f=n.length,C=h(n,!0);if(i+=f-C.rest.length,n=C.rest,C.ended)return t}}catch(I){throw I instanceof P?I:new P(`failed to read plugin archive: ${I?.message??I}`,"extract_failed")}return h(n,!1),t}function Ou(e){if(e.startsWith("/")||e.startsWith("\\")||/^[a-zA-Z]:/.test(e)||e.split("/").some(t=>t===".."))throw new P(`refusing to extract unsafe archive member "${e}"`,"unsafe_archive_member")}async function yr(e){let t=(0,S.statSync)(e).size;if(t>de)throw new P(`plugin archive is ${t} bytes (limit ${de} bytes)`,"archive_too_large");hr(await Ar(e))}function hr(e){let t=0,n=0;for(let r of e){if(Ou(r.name),r.type==="2"||r.type==="1")throw new P(`refusing to extract archive link "${r.name}" (symlinks/hardlinks are not allowed in plugins)`,"unsafe_archive_member");if("346".includes(r.type)||r.type==="S"||r.type==="V")throw new P(`refusing to extract special archive member "${r.name}"`,"unsafe_archive_member");(r.type==="0"||r.type==="\0"||r.type==="7")&&(t+=r.size,n+=1)}if(t>de)throw new P(`plugin payload is ${t} bytes uncompressed (limit ${de} bytes)`,"archive_too_large");if(n>Ke)throw new P(`plugin payload contains ${n} files (limit ${Ke})`,"archive_too_many_files")}async function Fr(e,t){(0,S.mkdirSync)(t,{recursive:!0});let n=await Ar(e);hr(n);let r=(0,B.resolve)(t),i=E=>{let h=(0,B.resolve)(E);if(h!==r&&!h.startsWith(r+B.sep))throw new P(`refusing to extract "${E}" outside the target directory`,"unsafe_archive_member");return h},u=(0,S.createReadStream)(e).pipe((0,Qt.createGunzip)()),o=[];try{for await(let E of u)if(o.push(E),o.reduce((h,w)=>h+w.length,0)>de)throw u.destroy(),new P(`plugin payload exceeds ${de} bytes uncompressed`,"archive_too_large")}catch(E){throw E instanceof P?E:new P(`failed to extract ${(0,B.basename)(e)}: ${E?.message??E}`,"extract_failed")}let a=Buffer.concat(o.map(E=>Buffer.from(E)));for(let E of n){let h=i((0,B.join)(t,E.name));if(E.type==="5"){(0,S.mkdirSync)(h,{recursive:!0});continue}if(E.type!=="0"&&E.type!=="\0"&&E.type!=="7")continue;if(!E.name)throw new P("refusing to extract archive member with an empty name","unsafe_archive_member");let w=E.dataOffset+E.size;if(w>a.length)throw new P(`plugin archive is truncated (member "${E.name}" data missing)`,"extract_failed");(0,S.mkdirSync)((0,B.dirname)(h),{recursive:!0}),(0,S.writeFileSync)(h,a.subarray(E.dataOffset,w),{mode:420})}rn(t);let c=(0,B.join)(t,"package");return(0,S.existsSync)(c)&&(0,S.statSync)(c).isDirectory()?c:t}function Bu(e,t){let n=new Set(["PATH","Path","path","TZ","LANG","LC_ALL","SYSTEMROOT","COMSPEC","APPDATA","LOCALAPPDATA","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","http_proxy","https_proxy","no_proxy"]),r={};for(let o of Object.keys(process.env))n.has(o)&&(r[o]=process.env[o]);r.HOME=e,r.USERPROFILE=e,r.TMPDIR=e,r.TEMP=e,r.TMP=e,r.CCR_CONFIG_DIR=process.env.CCR_CONFIG_DIR;let i=(0,B.join)(e,"npmrc"),u=(0,B.join)(e,"npmrc-global");return(0,S.writeFileSync)(i,"",{mode:384}),(0,S.writeFileSync)(u,"",{mode:384}),r.npm_config_userconfig=i,r.npm_config_globalconfig=u,r.npm_config_cache=t,r}async function vr(e,t,n={}){en(e),(0,S.mkdirSync)(t,{recursive:!0});let r=n.homeDir??(0,B.join)(t,"npm-home"),i=n.cacheDir??(0,B.join)(t,"npm-cache");(0,S.mkdirSync)(r,{recursive:!0}),(0,S.mkdirSync)(i,{recursive:!0});let u=["pack","--json","--prefer-offline","--ignore-scripts","--no-audit","--no-fund"];n.registry&&u.push("--registry",n.registry),u.push("--pack-destination",t,e);let o;try{o=await new Promise((E,h)=>{(0,fr.execFile)("npm",u,{cwd:t,encoding:"utf8",maxBuffer:16777216,timeout:n.timeoutMs??Dr,killSignal:"SIGKILL",env:Bu(r,i)},(I,f)=>{I?h(I):E(String(f??""))}).stdin?.end()})}catch(E){throw E?.killed||E?.signal==="SIGTERM"||E?.code==="ETIMEDOUT"?new P(`npm pack timed out for "${e}"`,"npm_pack_timeout"):new P(`npm pack failed for "${e}"`,"npm_pack_failed")}let a;try{a=JSON.parse(o)}catch{throw new P(`npm pack returned unexpected output for "${e}"`,"npm_pack_failed")}let c=a?.[0]?.filename;if(!c||c.includes("/")||c.includes("\\")||c.includes(".."))throw new P(`npm pack produced no archive for "${e}"`,"npm_pack_failed");return(0,B.join)(t,c)}function Nu(e){try{return(0,S.lstatSync)(e),!0}catch{return!1}}function _r(e,t,n,r,i){let u=(0,B.join)(n,"plugins");if((0,S.mkdirSync)(u,{recursive:!0}),(0,S.lstatSync)(u).isSymbolicLink()||!(0,S.lstatSync)(u).isDirectory())throw new P(`plugins directory is not a real directory: ${u}`,"unsafe_archive_member");let o=(0,B.join)(u,t.name);if((0,S.existsSync)(o)&&!r)throw new P(`plugin "${t.name}" is already installed at ${o} (use --force to replace it)`,"already_installed");gr(n,r);let a=(0,B.join)(u,`.${t.name}.staging-${process.pid}-${Date.now()}`);(0,S.mkdirSync)(a,{recursive:!0});try{(0,S.cpSync)(e,a,{recursive:!0});let c=tn(nn(a),t.name);if(!(0,S.existsSync)((0,B.join)(a,Re)))throw new P(`staged payload is missing its entry ${Re}`,"invalid_manifest");Nu(o)&&(0,S.rmSync)(o,{recursive:!0,force:!0}),(0,S.renameSync)(a,o),mr(n,c.name,r,i)}catch(c){throw(0,S.rmSync)(a,{recursive:!0,force:!0}),c}return o}function Sr(e){let t=nn(e),n=tn(t);if(!(0,S.existsSync)((0,B.join)(e,Re)))throw new P(`plugin entry ${Re} is missing from the payload`,"invalid_manifest");return Cr(e,t),rn(e),{manifest:n,raw:t}}async function Pr(e,t){return Tu(t.configDir,()=>bu(e,t))}async function bu(e,t){let n=t.tempRoot??(0,S.mkdtempSync)((0,B.join)((0,Yt.tmpdir)(),"ccr-plugin-add-")),r=t.tempRoot===void 0;try{await yr(e);let i=await Fr(e,(0,B.join)(n,"extract")),u=pr(i);if(!u)throw new P(`no ${me} + ${Re} found in ${e}`,"invalid_manifest");let{manifest:o}=Sr(u),a=(0,B.join)(i,"package.json");if((0,S.existsSync)(a)){let E;try{E=JSON.parse((0,S.readFileSync)(a,"utf8"))}catch{throw new P("invalid package.json","invalid_manifest")}if(!E||typeof E!="object"||Array.isArray(E)||E.version!==void 0&&E.version!==o.version)throw new P("package.json version does not match plugin.json; rebuild the plugin package","invalid_manifest")}return{target:_r(u,o,t.configDir,t.force??!1,t.source),manifest:o}}finally{r&&(0,S.rmSync)(n,{recursive:!0,force:!0})}}var lt=new Map;async function Tu(e,t){let n=(0,B.resolve)(e),r=lt.get(n)??Promise.resolve(),i,u=new Promise(a=>{i=a}),o=r.then(()=>u);lt.set(n,o),await r;try{return await t()}finally{i(),lt.get(n)===o&<.delete(n)}}async function Lu(e){en(e.spec);let t=e.tempRoot??(0,S.mkdtempSync)((0,B.join)((0,Yt.tmpdir)(),"ccr-plugin-add-")),n=e.tempRoot===void 0;try{let r=await vr(e.spec,(0,B.join)(t,"pack"),{registry:e.registry,cacheDir:e.cacheDir??(0,B.join)(t,"npm-cache"),homeDir:e.homeDir??(0,B.join)(t,"npm-home"),timeoutMs:e.timeoutMs});return await Pr(r,{configDir:e.configDir,force:e.force,tempRoot:t,source:e.spec})}finally{n&&(0,S.rmSync)(t,{recursive:!0,force:!0})}}var Mu="claude-code-router/token-speed-v2";function ku(e){return e.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,200)}function Uu(e){let t=e;return t?t.code==="ERR_DLOPEN_FAILED"||t.code==="MODULE_NOT_FOUND"||/NODE_MODULE_VERSION|was compiled against|Could not locate the bindings file|Dynamic require of/i.test(t.message??""):!1}function ju(e,t){let n=require("better-sqlite3");return t?new n(e,{readonly:!0,fileMustExist:!0}):new n(e)}function $u(e,t){let{DatabaseSync:n}=require("node:sqlite"),r=t?new n(e,{readOnly:!0}):new n(e);return{exec(u){r.exec(u)},prepare(u){let o=r.prepare(u);return{run(...a){let c=o.run(...a);return{changes:c.changes,lastInsertRowid:c.lastInsertRowid}},get:(...a)=>o.get(...a),all:(...a)=>o.all(...a)}},pragma(u,o){if(o?.simple){let a=r.prepare(`PRAGMA ${u}`).get();return a===void 0?void 0:Object.values(a)[0]}r.exec(`PRAGMA ${u}`)},transaction(u){return(...a)=>{r.exec("BEGIN");try{let c=u(...a);return r.exec("COMMIT"),c}catch(c){try{r.exec("ROLLBACK")}catch{}throw c}}},close(){r.close()}}}function Hu(e,t){return Ir(e,t,ju)}function Ir(e,t,n){let r=t?.readonly??!1;try{return{db:n(e,r),driver:"better-sqlite3"}}catch(i){if(!Uu(i))throw i;try{return{db:$u(e,r),driver:"node:sqlite",fallbackReason:i?.message??String(i)}}catch(u){let o=u;throw new Error(`No usable SQLite driver: better-sqlite3 failed to load (${i?.message}) and node:sqlite is unavailable (${o?.message}). Fix with: npm rebuild better-sqlite3 --runtime node --target <your node major> inside the claude-code-router package, or run ccr with Node >= 22.5.`)}}}var x=re(require("node:fs")),cn=re(require("node:os")),H=re(require("node:path")),Nr=require("node:crypto");var ke=["claudeCode","codex","pi","qwenCode","opencode"],ce={claudeCode:{id:"claudeCode",name:"Claude Code",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.claude/settings.json",modelAlias:"",quota:{}}},codex:{id:"codex",name:"Codex",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.codex/config.toml",modelAlias:"ccr-opus",quota:{}}},pi:{id:"pi",name:"pi",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.pi/agent",modelAlias:"ccr-opus",quota:{}}},qwenCode:{id:"qwenCode",name:"Qwen Code",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.qwen/settings.json",modelAlias:"ccr-opus",quota:{}}},opencode:{id:"opencode",name:"opencode",defaultConfig:{enabled:!1,managed:!1,configPath:"~/.config/opencode/opencode.json",modelAlias:"ccr-opus",quota:{}}}},br=H.default.join(X,"backups","clients"),on=H.default.join(X,".statusline-backup.json"),sn=H.default.join(X,".model-env-backup.json"),vt=["ANTHROPIC_MODEL","ANTHROPIC_DEFAULT_SONNET_MODEL","ANTHROPIC_DEFAULT_OPUS_MODEL","ANTHROPIC_DEFAULT_HAIKU_MODEL","ANTHROPIC_REASONING_MODEL"],ln={CLAUDE_CODE_AUTO_COMPACT_WINDOW:"200000",CLAUDE_AUTOCOMPACT_PCT_OVERRIDE:"90",CLAUDE_CODE_SIMPLE:"1"},dn=2e5;function _(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function et(e){let t=e?.ContextWindow;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.floor(t);if(typeof t=="string"&&/^\d+$/.test(t.trim())){let n=parseInt(t.trim(),10);if(n>0)return n}return dn}function Dn(){return Jt}function zu(e){return H.default.join(Ee(e),"ccr-state.json")}function Vu(e){return N(e)}function qu(e){let t=N(Dn());return t&&t[e]||{}}function Zu(e,t){U(e,t)}function Wu(e,t){let n=Dn(),r=N(n);r[e]=t,U(n,r)}function Tr(e){try{x.default.existsSync(e)&&x.default.unlinkSync(e)}catch{}}function Gu(e){let t=Dn(),n=N(t);n&&n[e]&&(delete n[e],Object.keys(n).length>0?U(t,n):Tr(t))}function wr(e){return{read:()=>qu(e),write:t=>Wu(e,t),clear:()=>Gu(e)}}function Lr(e){if(!e)return;let t=zu(e);return{read:()=>Vu(t),write:n=>Zu(t,n),clear:()=>Tr(t)}}function Se(e){return e instanceof Error?e.message:String(e)}function _t(e){return e==="~"?cn.default.homedir():e.startsWith("~/")?H.default.join(cn.default.homedir(),e.slice(2)):e}function Ku(e){return ce[e]}function Ju(e,t){let r=(_(e.Clients)?e.Clients:{})[t];return _(r)?r:{}}function Ue(e){let t=e?.Router?.families;return _(t)&&Object.keys(t).length>0}function Xu(e){return!!(e?.StatusLine?.enabled||Ue(e))}function Yu(){return{claudeCode:{...ce.claudeCode.defaultConfig},codex:{...ce.codex.defaultConfig},pi:{...ce.pi.defaultConfig},qwenCode:{...ce.qwenCode.defaultConfig},opencode:{...ce.opencode.defaultConfig}}}function ee(e,t){let n=Ku(t),r=Ju(e,t),u=typeof r.enabled=="boolean"?!!r.enabled:t==="claudeCode"&&!_(e.Clients)?Xu(e):n.defaultConfig.enabled;return{...n.defaultConfig,...r,enabled:u,managed:!!r.managed,configPath:r.configPath||n.defaultConfig.configPath,modelAlias:r.modelAlias||n.defaultConfig.modelAlias}}function Mr(e){return ke.includes(e)}function pn(e,t){return ee(e,t).enabled}function Qu(e,t,n){let r=_(e.Clients)?{...e.Clients}:{},u={...ee(e,t),...n};return r[t]=u,e.Clients=r,u}function _e(e,t){return _t(ee(e,t).configPath)}function Cn(e){let t=H.default.dirname(e);x.default.existsSync(t)||x.default.mkdirSync(t,{recursive:!0})}function Le(e,t){if(!x.default.existsSync(t))return null;let n=H.default.join(br,e);x.default.mkdirSync(n,{recursive:!0});let r=new Date().toISOString().replace(/[:.]/g,"-"),i=H.default.extname(t)||".bak",u=H.default.join(n,`${r}${i}`);return x.default.copyFileSync(t,u),u}function eo(e){let t=H.default.join(br,e);if(!x.default.existsSync(t))return null;let n=x.default.readdirSync(t).filter(r=>!r.startsWith(".")).sort();return n.length===0?null:H.default.join(t,n[n.length-1])}function Me(e,t){let n=eo(e);return n?(Cn(t),x.default.copyFileSync(n,t),n):null}var ht=H.default.join(X,"pi-provider-snapshots.json");function to(e,t,n){let r=N(ht),i=_(r[e])?r[e]:{};i[t]=n,r[e]=i,U(ht,r)}function no(e,t){let n=N(ht),r=n[e],i=_(r)?r[t]:void 0;if(_(i))return delete r[t],Object.keys(r).length===0&&delete n[e],U(ht,n),i}function N(e){if(!x.default.existsSync(e))return{};let t;try{t=x.default.readFileSync(e,"utf-8")}catch{return{}}if(!t.trim())return{};let n;try{n=JSON.parse(t)}catch{return{}}return _(n)?n:{}}function U(e,t){let n=`${JSON.stringify(t,null,2)}
|
|
16
16
|
`;if(x.default.existsSync(e))try{if(x.default.readFileSync(e,"utf-8")===n)return}catch{}Cn(e),x.default.writeFileSync(e,n,"utf-8")}function je(e,t=""){return`http://127.0.0.1:${e.PORT||3456}${t}`}function pe(e){return typeof e!="string"?!1:/^https?:\/\/(127\.0\.0\.1|localhost):\d+(?:\/.*)?$/i.test(e.trim())}function xe(e){return e?.enableExtendedContext===!0}function kr(e){if(e.Router?.enableFamilyRouting===!1)return[];if(!Ue(e))return[];let t=e.Router.families;return Object.keys(t).filter(n=>["opus","sonnet","haiku"].includes(n)&&_(t[n]))}function Ur(e){let t=kr(e);return t.includes("opus")?"opus":t[0]||null}function jr(e){let t=et(e),n=Ur(e);return xe(n?e.Router.families[n]:e.Router)?t:Math.min(t,dn)}function $r(e,t){_(e.env)||(e.env={});for(let a of vt)typeof e.env[a]=="string"&&e.env[a].startsWith("ccr-")&&delete e.env[a];if(!Ue(t))return;let n=t.Router.families,r=kr(t);for(let a of r){let c=n[a],E=xe(c)?"[1m]":"",h=`ccr-${a}${E}`;switch(a){case"opus":e.env.ANTHROPIC_DEFAULT_OPUS_MODEL=h;break;case"sonnet":e.env.ANTHROPIC_DEFAULT_SONNET_MODEL=h;break;case"haiku":e.env.ANTHROPIC_DEFAULT_HAIKU_MODEL=h;break}}let i=Ur(t);if(i){let a=n[i],c=xe(a)?"[1m]":"";e.env.ANTHROPIC_MODEL=`ccr-${i}${c}`}let o=r.find(a=>n[a]?.think)||i;if(o){let a=n[o],c=xe(a)?"[1m]":"";e.env.ANTHROPIC_REASONING_MODEL=`ccr-${o}${c}`}}function Hr(e,t,n,r){e.autoCompactEnabled=!0,_(e.env)||(e.env={}),e.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE==="0.8"&&delete e.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE;let i=String(r??et(t)),u=e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW,o=n?.read().autoCompactWindow;if(u===void 0||u===o||o===void 0){let E=o===void 0&&u!==void 0&&u!==i?u:n?.read().previousAutoCompactWindow;e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW=i,n?.write({autoCompactWindow:i,...E!==void 0?{previousAutoCompactWindow:E}:{}})}let c=ln.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE;(e.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE===void 0||e.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE===c)&&(e.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=c)}function zr(e,t){_(e.env)||(e.env={}),t.disableAttributionHeader===!1?delete e.env.CLAUDE_CODE_ATTRIBUTION_HEADER:e.env.CLAUDE_CODE_ATTRIBUTION_HEADER="0"}function ro(e){if(e.statusLine?.command==="ccr statusline"&&x.default.existsSync(on))try{let t=JSON.parse(x.default.readFileSync(on,"utf-8"));e.statusLine=t,x.default.unlinkSync(on)}catch{delete e.statusLine}if(x.default.existsSync(sn))try{let t=JSON.parse(x.default.readFileSync(sn,"utf-8"));_(e.env)||(e.env={});for(let[n,r]of Object.entries(t))e.env[n]=r;x.default.unlinkSync(sn)}catch{}}function io(e,t){if(ro(e),_(e.env)){pe(e.env.ANTHROPIC_BASE_URL)&&(delete e.env.ANTHROPIC_BASE_URL,delete e.env.ANTHROPIC_AUTH_TOKEN);for(let i of vt)typeof e.env[i]=="string"&&e.env[i].startsWith("ccr-")&&delete e.env[i];let r=t?.read().autoCompactWindow;e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW===r&&delete e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW,t?.clear();for(let[i,u]of Object.entries(ln))i!=="CLAUDE_CODE_AUTO_COMPACT_WINDOW"&&e.env[i]===u&&delete e.env[i];delete e.env.CLAUDE_CODE_ATTRIBUTION_HEADER,Object.keys(e.env).length===0&&delete e.env}e.statusLine?.command==="ccr statusline"&&delete e.statusLine,e.autoCompactEnabled===!0&&delete e.autoCompactEnabled}function uo(e){let t=_(e.env)?e.env:{};return t.ANTHROPIC_MODEL||t.ANTHROPIC_DEFAULT_SONNET_MODEL||t.ANTHROPIC_DEFAULT_OPUS_MODEL||t.ANTHROPIC_DEFAULT_HAIKU_MODEL}function Vr(e){let t=_(e.env)?e.env:{};return!!(pe(t.ANTHROPIC_BASE_URL)||vt.some(n=>typeof t[n]=="string"&&t[n].startsWith("ccr-"))||e.statusLine?.command==="ccr statusline")}function pt(e,t,n){let r=ee(e,"claudeCode"),i=_e(e,"claudeCode"),u=t||{};return{id:"claudeCode",name:ce.claudeCode.name,enabled:r.enabled,managed:Vr(u),configPath:r.configPath,exists:x.default.existsSync(i),activeModel:uo(u),details:n}}var oo={status(e){let t=_e(e,"claudeCode");try{return pt(e,N(t))}catch(n){return pt(e,{},Se(n))}},enable(e){let t=_e(e,"claudeCode");this.status(e).managed||Le("claudeCode",t);let r=N(t);return _(r.env)||(r.env={}),r.env.ANTHROPIC_BASE_URL=je(e),r.env.ANTHROPIC_AUTH_TOKEN=e.APIKEY||"test",$r(r,e),Hr(r,e,wr("claudeCode")),zr(r,e),e?.StatusLine?.enabled?r.statusLine={type:"command",command:"ccr statusline",padding:0}:r.statusLine?.command==="ccr statusline"&&delete r.statusLine,U(t,r),pt(e,r)},disable(e){let t=_e(e,"claudeCode");if(Me("claudeCode",t))return this.status(e);if(!x.default.existsSync(t))return this.status(e);let n=N(t);return io(n,wr("claudeCode")),U(t,n),pt(e,n)},restore(e){return this.disable(e)}};function St(e,t,n){_(e.env)||(e.env={}),e.env.ANTHROPIC_BASE_URL=je(t),e.env.ANTHROPIC_AUTH_TOKEN=t.APIKEY||"test",$r(e,t),Hr(e,t,Lr(n),jr(t)),zr(e,t),t?.StatusLine?.enabled?e.statusLine={type:"command",command:"ccr statusline",padding:0}:e.statusLine?.command==="ccr statusline"&&delete e.statusLine}function En(e,t,n){let r=Lr(t);if(_(e.env)){pe(e.env.ANTHROPIC_BASE_URL)&&(delete e.env.ANTHROPIC_BASE_URL,delete e.env.ANTHROPIC_AUTH_TOKEN);for(let c of vt)typeof e.env[c]=="string"&&e.env[c].startsWith("ccr-")&&delete e.env[c];let i=r?.read().autoCompactWindow,u=e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW,o=n?String(jr(n)):void 0;(u===i||i===void 0&&o!==void 0&&u===o)&&delete e.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW,r?.clear();for(let[c,E]of Object.entries(ln))c!=="CLAUDE_CODE_AUTO_COMPACT_WINDOW"&&e.env[c]===E&&delete e.env[c];delete e.env.CLAUDE_CODE_ATTRIBUTION_HEADER,Object.keys(e.env).length===0&&delete e.env}e.statusLine?.command==="ccr statusline"&&delete e.statusLine,e.autoCompactEnabled===!0&&delete e.autoCompactEnabled}function tt(e){return Vr(e)}function so(e){if(!e)return;let t=e.trim(),n=t.match(/^"((?:\\.|[^"\\])*)"/);if(n)return n[1].replace(/\\"/g,'"').replace(/\\\\/g,"\\");let r=t.match(/^'([^']*)'/);return r?r[1]:t.match(/^([^#\s]+)/)?.[1]}function $e(e){let t=!1,n=!1,r=!1;for(let i=0;i<e.length;i+=1){let u=e[i];if(r){r=!1;continue}if(u==="\\"&&n){r=!0;continue}if(u==='"'&&!t){n=!n;continue}if(u==="'"&&!n){t=!t;continue}if(u==="#"&&!t&&!n)return e.slice(0,i)}return e}function Ft(e,t){let n=!1;for(let r of e.split(/\r?\n/)){let i=$e(r).trim();if(!i)continue;if(/^\[[^\]]+\]$/.test(i)){n=!0;continue}if(n)continue;let u=i.match(/^([A-Za-z0-9_.-]+)\s*=\s*(.+)$/);if(u?.[1]===t)return so(u[2])}}function ao(e,t){return e.split(/\r?\n/).some(n=>$e(n).trim()===`[${t}]`)}function qr(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Rr(e){return typeof e=="number"?String(e):qr(e)}function co(e,t){let n=e?e.split(/\r?\n/):[],r=new Set,i=n.findIndex(a=>/^\s*\[[^\]]+\]\s*(?:#.*)?$/.test(a)),u=i===-1?n.length:i;for(let a=0;a<u;a+=1){let c=$e(n[a]).trim().match(/^([A-Za-z0-9_.-]+)\s*=/);c&&Object.prototype.hasOwnProperty.call(t,c[1])&&(n[a]=`${c[1]} = ${Rr(t[c[1]])}`,r.add(c[1]))}let o=Object.entries(t).filter(([a])=>!r.has(a)).map(([a,c])=>`${a} = ${Rr(c)}`);return o.length>0&&n.splice(u,0,...o,""),n.join(`
|
|
17
17
|
`).replace(/\n{3,}/g,`
|
|
18
18
|
|