@easbot/local-model-sdk 0.1.3
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/LICENSE +21 -0
- package/README.en.md +282 -0
- package/README.md +282 -0
- package/dist/index.cjs +119 -0
- package/dist/index.d.cts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.mjs +119 -0
- package/package.json +92 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {env,pipeline}from'@huggingface/transformers';import*as Ys from'os';import*as ei from'path';import ei__default,{win32,posix}from'path';import*as z from'fs';import {realpathSync,createWriteStream,readlinkSync,readdirSync,readdir as readdir$1,lstatSync}from'fs';import Nn,{realpath,readlink,readdir,lstat}from'fs/promises';import Wa from'zod';import {fileURLToPath}from'url';import {EventEmitter}from'events';import hn from'stream';import {StringDecoder}from'string_decoder';var Wn=Object.defineProperty;var Js=i=>{throw TypeError(i)};var Gn=(i,t,e)=>t in i?Wn(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var c=(i,t,e)=>Gn(i,typeof t!="symbol"?t+"":t,e),bs=(i,t,e)=>t.has(i)||Js("Cannot "+e);var n=(i,t,e)=>(bs(i,t,"read from private field"),e?e.call(i):t.get(i)),w=(i,t,e)=>t.has(i)?Js("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),u=(i,t,e,s)=>(bs(i,t,"write to private field"),t.set(i,e),e),m=(i,t,e)=>(bs(i,t,"access private method"),e);var Wi=(i,t,e,s)=>({set _(r){u(i,t,r);},get _(){return n(i,t,s)}});var gt=(g=>(g.MODEL_NOT_FOUND="MODEL_NOT_FOUND",g.MODEL_LOAD_ERROR="MODEL_LOAD_ERROR",g.MODEL_NOT_INITIALIZED="MODEL_NOT_INITIALIZED",g.GENERATION_ERROR="GENERATION_ERROR",g.EMBEDDING_ERROR="EMBEDDING_ERROR",g.INVALID_INPUT="INVALID_INPUT",g.UNSUPPORTED_FEATURE="UNSUPPORTED_FEATURE",g.CACHE_ERROR="CACHE_ERROR",g.PROCESSING_ERROR="PROCESSING_ERROR",g.ABORTED="ABORTED",g.OUT_OF_MEMORY="OUT_OF_MEMORY",g.UNKNOWN_ERROR="UNKNOWN_ERROR",g))(gt||{}),Ht={"qwen3-0.6b":{modelId:"qwen3-0.6b",huggingFaceId:"onnx-community/Qwen3-0.6B-ONNX",contextLength:32768,dtype:"q4",defaultSettings:{temperature:.7,topP:.9,topK:40,maxTokens:32e3,repetitionPenalty:1.1,stopSequences:[]}},"gemma-3-1b-it":{modelId:"gemma-3-1b-it",huggingFaceId:"onnx-community/gemma-3-1b-it-ONNX",contextLength:32768,dtype:"q4",defaultSettings:{temperature:.7,topP:.9,topK:40,maxTokens:32e3,repetitionPenalty:1.1,stopSequences:[]}}},Se={"bge-small-zh-v1.5":{modelId:"bge-small-zh-v1.5",huggingFaceId:"Xenova/bge-small-zh-v1.5",dimensions:512,maxEmbeddingsPerCall:32},"bge-base-zh-v1.5":{modelId:"bge-base-zh-v1.5",huggingFaceId:"Xenova/bge-base-zh-v1.5",dimensions:768,maxEmbeddingsPerCall:32},"bge-large-zh-v1.5":{modelId:"bge-large-zh-v1.5",huggingFaceId:"Xenova/bge-large-zh-v1.5",dimensions:1024,maxEmbeddingsPerCall:32},"all-MiniLM-L6-v2":{modelId:"all-MiniLM-L6-v2",huggingFaceId:"sentence-transformers/all-MiniLM-L6-v2",dimensions:384,maxEmbeddingsPerCall:32}};var T=class i extends Error{constructor(e,s,r){super(e);this.code=s;this.cause=r;this.name="LocalModelError",Error.captureStackTrace&&Error.captureStackTrace(this,i);}},nt=class{static modelLoadError(t){return new T(`\u6A21\u578B\u52A0\u8F7D\u5931\u8D25: ${t.message}`,"MODEL_LOAD_ERROR",t)}static generationError(t){return new T(`\u751F\u6210\u5931\u8D25: ${t.message}`,"GENERATION_ERROR",t)}static embeddingError(t){return new T(`\u5D4C\u5165\u5931\u8D25: ${t.message}`,"EMBEDDING_ERROR",t)}static validationError(t){return new T(t,"INVALID_INPUT")}static abortError(){return new T("\u64CD\u4F5C\u5DF2\u4E2D\u6B62","ABORTED")}static unsupportedFeature(t){return new T(`\u4E0D\u652F\u6301\u7684\u529F\u80FD: ${t}`,"UNSUPPORTED_FEATURE")}};var Vn=ei.join(Ys.homedir(),".cache","easbot","models"),Ue=class{constructor(t){c(this,"cacheDir");this.cacheDir=t.cacheDir||Vn;}getCachePath(t){return ei.join(this.cacheDir,t)}isCached(t){try{let e=this.getCachePath(t);return z.existsSync(e)&&z.statSync(e).isDirectory()}catch{return false}}async clear(t){try{if(t){let e=this.getCachePath(t);z.existsSync(e)&&await this.removeDirectory(e);}else z.existsSync(this.cacheDir)&&await this.removeDirectory(this.cacheDir);}catch(e){throw new T(`\u6E05\u7406\u7F13\u5B58\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`,"CACHE_ERROR",e instanceof Error?e:void 0)}}async getCacheSize(t){try{let e=t?this.getCachePath(t):this.cacheDir;return z.existsSync(e)?await this.getDirectorySize(e):0}catch(e){throw new T(`\u83B7\u53D6\u7F13\u5B58\u5927\u5C0F\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`,"CACHE_ERROR",e instanceof Error?e:void 0)}}async getDirectorySize(t){let e=0,s=z.readdirSync(t);for(let r of s){let o=ei.join(t,r),a=z.statSync(o);a.isDirectory()?e+=await this.getDirectorySize(o):e+=a.size;}return e}async removeDirectory(t){if(!z.existsSync(t))return;let e=z.readdirSync(t);for(let s of e){let r=ei.join(t,s);z.statSync(r).isDirectory()?await this.removeDirectory(r):z.unlinkSync(r);}z.rmdirSync(t);}ensureCacheDir(){try{z.existsSync(this.cacheDir)||z.mkdirSync(this.cacheDir,{recursive:!0});}catch(t){throw new T(`\u521B\u5EFA\u7F13\u5B58\u76EE\u5F55\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`,"CACHE_ERROR",t instanceof Error?t:void 0)}}};var Wr=(i,t,e)=>{let s=i instanceof RegExp?Zs(i,e):i,r=t instanceof RegExp?Zs(t,e):t,o=s!==null&&r!=null&&qn(s,r,e);return o&&{start:o[0],end:o[1],pre:e.slice(0,o[0]),body:e.slice(o[0]+s.length,o[1]),post:e.slice(o[1]+r.length)}},Zs=(i,t)=>{let e=t.match(i);return e?e[0]:null},qn=(i,t,e)=>{let s,r,o,a,l,h=e.indexOf(i),d=e.indexOf(t,h+1),p=h;if(h>=0&&d>0){if(i===t)return [h,d];for(s=[],o=e.length;p>=0&&!l;){if(p===h)s.push(p),h=e.indexOf(i,p+1);else if(s.length===1){let f=s.pop();f!==void 0&&(l=[f,d]);}else r=s.pop(),r!==void 0&&r<o&&(o=r,a=d),d=e.indexOf(t,p+1);p=h<d&&h>=0?h:d;}s.length&&a!==void 0&&(l=[o,a]);}return l},Gr="\0SLASH"+Math.random()+"\0",Vr="\0OPEN"+Math.random()+"\0",js="\0CLOSE"+Math.random()+"\0",qr="\0COMMA"+Math.random()+"\0",Hr="\0PERIOD"+Math.random()+"\0",Hn=new RegExp(Gr,"g"),Kn=new RegExp(Vr,"g"),Jn=new RegExp(js,"g"),Yn=new RegExp(qr,"g"),Zn=new RegExp(Hr,"g"),Xn=/\\\\/g,Qn=/\\{/g,to=/\\}/g,eo=/\\,/g,io=/\\./g,so=1e5;function Ss(i){return isNaN(i)?i.charCodeAt(0):parseInt(i,10)}function ro(i){return i.replace(Xn,Gr).replace(Qn,Vr).replace(to,js).replace(eo,qr).replace(io,Hr)}function no(i){return i.replace(Hn,"\\").replace(Kn,"{").replace(Jn,"}").replace(Yn,",").replace(Zn,".")}function Kr(i){if(!i)return [""];let t=[],e=Wr("{","}",i);if(!e)return i.split(",");let{pre:s,body:r,post:o}=e,a=s.split(",");a[a.length-1]+="{"+r+"}";let l=Kr(o);return o.length&&(a[a.length-1]+=l.shift(),a.push.apply(a,l)),t.push.apply(t,a),t}function oo(i,t={}){if(!i)return [];let{max:e=so}=t;return i.slice(0,2)==="{}"&&(i="\\{\\}"+i.slice(2)),hi(ro(i),e,true).map(no)}function ao(i){return "{"+i+"}"}function ho(i){return /^-?0\d/.test(i)}function lo(i,t){return i<=t}function co(i,t){return i>=t}function hi(i,t,e){let s=[],r=Wr("{","}",i);if(!r)return [i];let o=r.pre,a=r.post.length?hi(r.post,t,false):[""];if(/\$$/.test(r.pre))for(let l=0;l<a.length&&l<t;l++){let h=o+"{"+r.body+"}"+a[l];s.push(h);}else {let l=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(r.body),h=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(r.body),d=l||h,p=r.body.indexOf(",")>=0;if(!d&&!p)return r.post.match(/,(?!,).*\}/)?(i=r.pre+"{"+r.body+js+r.post,hi(i,t,true)):[i];let f;if(d)f=r.body.split(/\.\./);else if(f=Kr(r.body),f.length===1&&f[0]!==void 0&&(f=hi(f[0],t,false).map(ao),f.length===1))return a.map(y=>r.pre+f[0]+y);let g;if(d&&f[0]!==void 0&&f[1]!==void 0){let y=Ss(f[0]),S=Ss(f[1]),b=Math.max(f[0].length,f[1].length),x=f.length===3&&f[2]!==void 0?Math.abs(Ss(f[2])):1,E=lo;S<y&&(x*=-1,E=co);let k=f.some(ho);g=[];for(let L=y;E(L,S);L+=x){let D;if(h)D=String.fromCharCode(L),D==="\\"&&(D="");else if(D=String(L),k){let C=b-D.length;if(C>0){let P=new Array(C+1).join("0");L<0?D="-"+P+D.slice(1):D=P+D;}}g.push(D);}}else {g=[];for(let y=0;y<f.length;y++)g.push.apply(g,hi(f[y],t,false));}for(let y=0;y<g.length;y++)for(let S=0;S<a.length&&s.length<t;S++){let b=o+g[y]+a[S];(!e||d||b)&&s.push(b);}}return s}var os=i=>{if(typeof i!="string")throw new TypeError("invalid pattern");if(i.length>65536)throw new TypeError("pattern is too long")},uo={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",true],"[:alpha:]":["\\p{L}\\p{Nl}",true],"[:ascii:]":["\\x00-\\x7f",false],"[:blank:]":["\\p{Zs}\\t",true],"[:cntrl:]":["\\p{Cc}",true],"[:digit:]":["\\p{Nd}",true],"[:graph:]":["\\p{Z}\\p{C}",true,true],"[:lower:]":["\\p{Ll}",true],"[:print:]":["\\p{C}",true],"[:punct:]":["\\p{P}",true],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",true],"[:upper:]":["\\p{Lu}",true],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",true],"[:xdigit:]":["A-Fa-f0-9",false]},ii=i=>i.replace(/[[\]\\-]/g,"\\$&"),fo=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Xs=i=>i.join(""),po=(i,t)=>{let e=t;if(i.charAt(e)!=="[")throw new Error("not in a brace expression");let s=[],r=[],o=e+1,a=false,l=false,h=false,d=false,p=e,f="";t:for(;o<i.length;){let S=i.charAt(o);if((S==="!"||S==="^")&&o===e+1){d=true,o++;continue}if(S==="]"&&a&&!h){p=o+1;break}if(a=true,S==="\\"&&!h){h=true,o++;continue}if(S==="["&&!h){for(let[b,[x,E,k]]of Object.entries(uo))if(i.startsWith(b,o)){if(f)return ["$.",false,i.length-e,true];o+=b.length,k?r.push(x):s.push(x),l=l||E;continue t}}if(h=false,f){S>f?s.push(ii(f)+"-"+ii(S)):S===f&&s.push(ii(S)),f="",o++;continue}if(i.startsWith("-]",o+1)){s.push(ii(S+"-")),o+=2;continue}if(i.startsWith("-",o+1)){f=S,o+=2;continue}s.push(ii(S)),o++;}if(p<o)return ["",false,0,false];if(!s.length&&!r.length)return ["$.",false,i.length-e,true];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!d){let S=s[0].length===2?s[0].slice(-1):s[0];return [fo(S),false,p-e,false]}let g="["+(d?"^":"")+Xs(s)+"]",y="["+(d?"":"^")+Xs(r)+"]";return [s.length&&r.length?"("+g+"|"+y+")":s.length?g:y,l,p-e,true]},$e=(i,{windowsPathsNoEscape:t=false,magicalBraces:e=true}={})=>e?t?i.replace(/\[([^\/\\])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?i.replace(/\[([^\/\\{}])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),go=new Set(["!","?","+","*","@"]),Qs=i=>go.has(i),mo="(?!(?:^|/)\\.\\.?(?:$|/))",Gi="(?!\\.)",yo=new Set(["[","."]),wo=new Set(["..","."]),bo=new Set("().*{}+?[]^$\\!"),So=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Ws="[^/]",tr=Ws+"*?",er=Ws+"+?",W,Y,Yt,I,$,le,xe,ce,Wt,Ce,gi,Ie,Yr,me,tt,Xi,Ms,Zr,Jr=(tt=class{constructor(t,e,s={}){w(this,Ie);c(this,"type");w(this,W);w(this,Y);w(this,Yt,false);w(this,I,[]);w(this,$);w(this,le);w(this,xe);w(this,ce,false);w(this,Wt);w(this,Ce);w(this,gi,false);this.type=t,t&&u(this,Y,true),u(this,$,e),u(this,W,n(this,$)?n(n(this,$),W):this),u(this,Wt,n(this,W)===this?s:n(n(this,W),Wt)),u(this,xe,n(this,W)===this?[]:n(n(this,W),xe)),t==="!"&&!n(n(this,W),ce)&&n(this,xe).push(this),u(this,le,n(this,$)?n(n(this,$),I).length:0);}get hasMagic(){if(n(this,Y)!==void 0)return n(this,Y);for(let t of n(this,I))if(typeof t!="string"&&(t.type||t.hasMagic))return u(this,Y,true);return n(this,Y)}toString(){return n(this,Ce)!==void 0?n(this,Ce):this.type?u(this,Ce,this.type+"("+n(this,I).map(t=>String(t)).join("|")+")"):u(this,Ce,n(this,I).map(t=>String(t)).join(""))}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof tt&&n(e,$)===this))throw new Error("invalid part: "+e);n(this,I).push(e);}}toJSON(){let t=this.type===null?n(this,I).slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...n(this,I).map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===n(this,W)||n(n(this,W),ce)&&n(this,$)?.type==="!")&&t.push({}),t}isStart(){if(n(this,W)===this)return true;if(!n(this,$)?.isStart())return false;if(n(this,le)===0)return true;let t=n(this,$);for(let e=0;e<n(this,le);e++){let s=n(t,I)[e];if(!(s instanceof tt&&s.type==="!"))return false}return true}isEnd(){if(n(this,W)===this||n(this,$)?.type==="!")return true;if(!n(this,$)?.isEnd())return false;if(!this.type)return n(this,$)?.isEnd();let t=n(this,$)?n(n(this,$),I).length:0;return n(this,le)===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this));}clone(t){let e=new tt(this.type,t);for(let s of n(this,I))e.copyIn(s);return e}static fromGlob(t,e={}){var r;let s=new tt(null,void 0,e);return m(r=tt,me,Xi).call(r,t,s,0,e),s}toMMPattern(){if(this!==n(this,W))return n(this,W).toMMPattern();let t=this.toString(),[e,s,r,o]=this.toRegExpSource();if(!(r||n(this,Y)||n(this,Wt).nocase&&!n(this,Wt).nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return s;let a=(n(this,Wt).nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${e}$`,a),{_src:e,_glob:t})}get options(){return n(this,Wt)}toRegExpSource(t){let e=t??!!n(this,Wt).dot;if(n(this,W)===this&&m(this,Ie,Yr).call(this),!this.type){let h=this.isStart()&&this.isEnd()&&!n(this,I).some(g=>typeof g!="string"),d=n(this,I).map(g=>{var E;let[y,S,b,x]=typeof g=="string"?m(E=tt,me,Zr).call(E,g,n(this,Y),h):g.toRegExpSource(t);return u(this,Y,n(this,Y)||b),u(this,Yt,n(this,Yt)||x),y}).join(""),p="";if(this.isStart()&&typeof n(this,I)[0]=="string"&&!(n(this,I).length===1&&wo.has(n(this,I)[0]))){let g=yo,y=e&&g.has(d.charAt(0))||d.startsWith("\\.")&&g.has(d.charAt(2))||d.startsWith("\\.\\.")&&g.has(d.charAt(4)),S=!e&&!t&&g.has(d.charAt(0));p=y?mo:S?Gi:"";}let f="";return this.isEnd()&&n(n(this,W),ce)&&n(this,$)?.type==="!"&&(f="(?:$|\\/)"),[p+d+f,$e(d),u(this,Y,!!n(this,Y)),n(this,Yt)]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",o=m(this,Ie,Ms).call(this,e);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let h=this.toString();return u(this,I,[h]),this.type=null,u(this,Y,void 0),[h,$e(this.toString()),false,false]}let a=!s||t||e||!Gi?"":m(this,Ie,Ms).call(this,true);a===o&&(a=""),a&&(o=`(?:${o})(?:${a})*?`);let l="";if(this.type==="!"&&n(this,gi))l=(this.isStart()&&!e?Gi:"")+er;else {let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?Gi:"")+tr+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&a?")":this.type==="*"&&a?")?":`)${this.type}`;l=r+o+h;}return [l,$e(o),u(this,Y,!!n(this,Y)),n(this,Yt)]}},W=new WeakMap,Y=new WeakMap,Yt=new WeakMap,I=new WeakMap,$=new WeakMap,le=new WeakMap,xe=new WeakMap,ce=new WeakMap,Wt=new WeakMap,Ce=new WeakMap,gi=new WeakMap,Ie=new WeakSet,Yr=function(){if(this!==n(this,W))throw new Error("should only call on root");if(n(this,ce))return this;this.toString(),u(this,ce,true);let t;for(;t=n(this,xe).pop();){if(t.type!=="!")continue;let e=t,s=n(e,$);for(;s;){for(let r=n(e,le)+1;!s.type&&r<n(s,I).length;r++)for(let o of n(t,I)){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n(s,I)[r]);}e=s,s=n(e,$);}}return this},me=new WeakSet,Xi=function(t,e,s,r){var y,S;let o=false,a=false,l=-1,h=false;if(e.type===null){let b=s,x="";for(;b<t.length;){let E=t.charAt(b++);if(o||E==="\\"){o=!o,x+=E;continue}if(a){b===l+1?(E==="^"||E==="!")&&(h=true):E==="]"&&!(b===l+2&&h)&&(a=false),x+=E;continue}else if(E==="["){a=true,l=b,h=false,x+=E;continue}if(!r.noext&&Qs(E)&&t.charAt(b)==="("){e.push(x),x="";let k=new tt(E,e);b=m(y=tt,me,Xi).call(y,t,k,b,r),e.push(k);continue}x+=E;}return e.push(x),b}let d=s+1,p=new tt(null,e),f=[],g="";for(;d<t.length;){let b=t.charAt(d++);if(o||b==="\\"){o=!o,g+=b;continue}if(a){d===l+1?(b==="^"||b==="!")&&(h=true):b==="]"&&!(d===l+2&&h)&&(a=false),g+=b;continue}else if(b==="["){a=true,l=d,h=false,g+=b;continue}if(Qs(b)&&t.charAt(d)==="("){p.push(g),g="";let x=new tt(b,p);p.push(x),d=m(S=tt,me,Xi).call(S,t,x,d,r);continue}if(b==="|"){p.push(g),g="",f.push(p),p=new tt(null,e);continue}if(b===")")return g===""&&n(e,I).length===0&&u(e,gi,true),p.push(g),g="",e.push(...f,p),d;g+=b;}return e.type=null,u(e,Y,void 0),u(e,I,[t.substring(s-1)]),d},Ms=function(t){return n(this,I).map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[s,r,o,a]=e.toRegExpSource(t);return u(this,Yt,n(this,Yt)||a),s}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")},Zr=function(t,e,s=false){let r=false,o="",a=false;for(let l=0;l<t.length;l++){let h=t.charAt(l);if(r){r=false,o+=(bo.has(h)?"\\":"")+h;continue}if(h==="\\"){l===t.length-1?o+="\\\\":r=true;continue}if(h==="["){let[d,p,f,g]=po(t,l);if(f){o+=d,a=a||p,l+=f-1,e=e||g;continue}}if(h==="*"){o+=s&&t==="*"?er:tr,e=true;continue}if(h==="?"){o+=Ws,e=true;continue}o+=So(h);}return [o,$e(t),!!e,a]},w(tt,me),tt),Xr=(i,{windowsPathsNoEscape:t=false,magicalBraces:e=false}={})=>e?t?i.replace(/[?*()[\]{}]/g,"[$&]"):i.replace(/[?*()[\]\\{}]/g,"\\$&"):t?i.replace(/[?*()[\]]/g,"[$&]"):i.replace(/[?*()[\]\\]/g,"\\$&"),dt=(i,t,e={})=>(os(t),!e.nocomment&&t.charAt(0)==="#"?false:new ye(t,e).match(i)),Eo=/^\*+([^+@!?\*\[\(]*)$/,vo=i=>t=>!t.startsWith(".")&&t.endsWith(i),To=i=>t=>t.endsWith(i),xo=i=>(i=i.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(i)),Co=i=>(i=i.toLowerCase(),t=>t.toLowerCase().endsWith(i)),ko=/^\*+\.\*+$/,Ro=i=>!i.startsWith(".")&&i.includes("."),Mo=i=>i!=="."&&i!==".."&&i.includes("."),Oo=/^\.\*+$/,Lo=i=>i!=="."&&i!==".."&&i.startsWith("."),Do=/^\*+$/,Po=i=>i.length!==0&&!i.startsWith("."),Ao=i=>i.length!==0&&i!=="."&&i!=="..",Io=/^\?+([^+@!?\*\[\(]*)?$/,No=([i,t=""])=>{let e=Qr([i]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},_o=([i,t=""])=>{let e=tn([i]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},Fo=([i,t=""])=>{let e=tn([i]);return t?s=>e(s)&&s.endsWith(t):e},Uo=([i,t=""])=>{let e=Qr([i]);return t?s=>e(s)&&s.endsWith(t):e},Qr=([i])=>{let t=i.length;return e=>e.length===t&&!e.startsWith(".")},tn=([i])=>{let t=i.length;return e=>e.length===t&&e!=="."&&e!==".."},en=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",ir={win32:{sep:"\\"},posix:{sep:"/"}},Bo=en==="win32"?ir.win32.sep:ir.posix.sep;dt.sep=Bo;var ct=Symbol("globstar **");dt.GLOBSTAR=ct;var zo="[^/]",$o=zo+"*?",jo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Wo="(?:(?!(?:\\/|^)\\.).)*?",Go=(i,t={})=>e=>dt(e,i,t);dt.filter=Go;var Tt=(i,t={})=>Object.assign({},i,t),Vo=i=>{if(!i||typeof i!="object"||!Object.keys(i).length)return dt;let t=dt;return Object.assign((e,s,r={})=>t(e,s,Tt(i,r)),{Minimatch:class extends t.Minimatch{constructor(e,s={}){super(e,Tt(i,s));}static defaults(e){return t.defaults(Tt(i,e)).Minimatch}},AST:class extends t.AST{constructor(e,s,r={}){super(e,s,Tt(i,r));}static fromGlob(e,s={}){return t.AST.fromGlob(e,Tt(i,s))}},unescape:(e,s={})=>t.unescape(e,Tt(i,s)),escape:(e,s={})=>t.escape(e,Tt(i,s)),filter:(e,s={})=>t.filter(e,Tt(i,s)),defaults:e=>t.defaults(Tt(i,e)),makeRe:(e,s={})=>t.makeRe(e,Tt(i,s)),braceExpand:(e,s={})=>t.braceExpand(e,Tt(i,s)),match:(e,s,r={})=>t.match(e,s,Tt(i,r)),sep:t.sep,GLOBSTAR:ct})};dt.defaults=Vo;var sn=(i,t={})=>(os(i),t.nobrace||!/\{(?:(?!\{).)*\}/.test(i)?[i]:oo(i,{max:t.braceExpandMax}));dt.braceExpand=sn;var qo=(i,t={})=>new ye(i,t).makeRe();dt.makeRe=qo;var Ho=(i,t,e={})=>{let s=new ye(t,e);return i=i.filter(r=>s.match(r)),s.options.nonull&&!i.length&&i.push(t),i};dt.match=Ho;var sr=/[?*]|[+@!]\(.*?\)|\[|\]/,Ko=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),ye=class{constructor(i,t={}){c(this,"options");c(this,"set");c(this,"pattern");c(this,"windowsPathsNoEscape");c(this,"nonegate");c(this,"negate");c(this,"comment");c(this,"empty");c(this,"preserveMultipleSlashes");c(this,"partial");c(this,"globSet");c(this,"globParts");c(this,"nocase");c(this,"isWindows");c(this,"platform");c(this,"windowsNoMagicRoot");c(this,"regexp");os(i),t=t||{},this.options=t,this.pattern=i,this.platform=t.platform||en,this.isWindows=this.platform==="win32";let e="allowWindowsEscape";this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t[e]===false,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=false,this.nonegate=!!t.nonegate,this.comment=false,this.empty=false,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot!==void 0?t.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make();}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return true;for(let i of this.set)for(let t of i)if(typeof t!="string")return true;return false}debug(...i){}make(){let i=this.pattern,t=this.options;if(!t.nocomment&&i.charAt(0)==="#"){this.comment=true;return}if(!i){this.empty=true;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...r)=>console.error(...r)),this.debug(this.pattern,this.globSet);let e=this.globSet.map(r=>this.slashSplit(r));this.globParts=this.preprocess(e),this.debug(this.pattern,this.globParts);let s=this.globParts.map((r,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=r[0]===""&&r[1]===""&&(r[2]==="?"||!sr.test(r[2]))&&!sr.test(r[3]),h=/^[a-z]:/i.test(r[0]);if(l)return [...r.slice(0,4),...r.slice(4).map(d=>this.parse(d))];if(h)return [r[0],...r.slice(1).map(d=>this.parse(d))]}return r.map(l=>this.parse(l))});if(this.debug(this.pattern,s),this.set=s.filter(r=>r.indexOf(false)===-1),this.isWindows)for(let r=0;r<this.set.length;r++){let o=this.set[r];o[0]===""&&o[1]===""&&this.globParts[r][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?");}this.debug(this.pattern,this.set);}preprocess(i){if(this.options.noglobstar)for(let e=0;e<i.length;e++)for(let s=0;s<i[e].length;s++)i[e][s]==="**"&&(i[e][s]="*");let{optimizationLevel:t=1}=this.options;return t>=2?(i=this.firstPhasePreProcess(i),i=this.secondPhasePreProcess(i)):t>=1?i=this.levelOneOptimize(i):i=this.adjascentGlobstarOptimize(i),i}adjascentGlobstarOptimize(i){return i.map(t=>{let e=-1;for(;(e=t.indexOf("**",e+1))!==-1;){let s=e;for(;t[s+1]==="**";)s++;s!==e&&t.splice(e,s-e);}return t})}levelOneOptimize(i){return i.map(t=>(t=t.reduce((e,s)=>{let r=e[e.length-1];return s==="**"&&r==="**"?e:s===".."&&r&&r!==".."&&r!=="."&&r!=="**"?(e.pop(),e):(e.push(s),e)},[]),t.length===0?[""]:t))}levelTwoFileOptimize(i){Array.isArray(i)||(i=this.slashSplit(i));let t=false;do{if(t=false,!this.preserveMultipleSlashes){for(let s=1;s<i.length-1;s++){let r=i[s];s===1&&r===""&&i[0]===""||(r==="."||r==="")&&(t=true,i.splice(s,1),s--);}i[0]==="."&&i.length===2&&(i[1]==="."||i[1]==="")&&(t=true,i.pop());}let e=0;for(;(e=i.indexOf("..",e+1))!==-1;){let s=i[e-1];s&&s!=="."&&s!==".."&&s!=="**"&&(t=true,i.splice(e-1,2),e-=2);}}while(t);return i.length===0?[""]:i}firstPhasePreProcess(i){let t=false;do{t=false;for(let e of i){let s=-1;for(;(s=e.indexOf("**",s+1))!==-1;){let o=s;for(;e[o+1]==="**";)o++;o>s&&e.splice(s+1,o-s);let a=e[s+1],l=e[s+2],h=e[s+3];if(a!==".."||!l||l==="."||l===".."||!h||h==="."||h==="..")continue;t=true,e.splice(s,1);let d=e.slice(0);d[s]="**",i.push(d),s--;}if(!this.preserveMultipleSlashes){for(let o=1;o<e.length-1;o++){let a=e[o];o===1&&a===""&&e[0]===""||(a==="."||a==="")&&(t=true,e.splice(o,1),o--);}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(t=true,e.pop());}let r=0;for(;(r=e.indexOf("..",r+1))!==-1;){let o=e[r-1];if(o&&o!=="."&&o!==".."&&o!=="**"){t=true;let a=r===1&&e[r+1]==="**"?["."]:[];e.splice(r-1,2,...a),e.length===0&&e.push(""),r-=2;}}}}while(t);return i}secondPhasePreProcess(i){for(let t=0;t<i.length-1;t++)for(let e=t+1;e<i.length;e++){let s=this.partsMatch(i[t],i[e],!this.preserveMultipleSlashes);if(s){i[t]=[],i[e]=s;break}}return i.filter(t=>t.length)}partsMatch(i,t,e=false){let s=0,r=0,o=[],a="";for(;s<i.length&&r<t.length;)if(i[s]===t[r])o.push(a==="b"?t[r]:i[s]),s++,r++;else if(e&&i[s]==="**"&&t[r]===i[s+1])o.push(i[s]),s++;else if(e&&t[r]==="**"&&i[s]===t[r+1])o.push(t[r]),r++;else if(i[s]==="*"&&t[r]&&(this.options.dot||!t[r].startsWith("."))&&t[r]!=="**"){if(a==="b")return false;a="a",o.push(i[s]),s++,r++;}else if(t[r]==="*"&&i[s]&&(this.options.dot||!i[s].startsWith("."))&&i[s]!=="**"){if(a==="a")return false;a="b",o.push(t[r]),s++,r++;}else return false;return i.length===t.length&&o}parseNegate(){if(this.nonegate)return;let i=this.pattern,t=false,e=0;for(let s=0;s<i.length&&i.charAt(s)==="!";s++)t=!t,e++;e&&(this.pattern=i.slice(e)),this.negate=t;}matchOne(i,t,e=false){let s=this.options;if(this.isWindows){let S=typeof i[0]=="string"&&/^[a-z]:$/i.test(i[0]),b=!S&&i[0]===""&&i[1]===""&&i[2]==="?"&&/^[a-z]:$/i.test(i[3]),x=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),E=!x&&t[0]===""&&t[1]===""&&t[2]==="?"&&typeof t[3]=="string"&&/^[a-z]:$/i.test(t[3]),k=b?3:S?0:void 0,L=E?3:x?0:void 0;if(typeof k=="number"&&typeof L=="number"){let[D,C]=[i[k],t[L]];D.toLowerCase()===C.toLowerCase()&&(t[L]=D,L>k?t=t.slice(L):k>L&&(i=i.slice(k)));}}let{optimizationLevel:r=1}=this.options;r>=2&&(i=this.levelTwoFileOptimize(i)),this.debug("matchOne",this,{file:i,pattern:t}),this.debug("matchOne",i.length,t.length);for(var o=0,a=0,l=i.length,h=t.length;o<l&&a<h;o++,a++){this.debug("matchOne loop");var d=t[a],p=i[o];if(this.debug(t,d,p),d===false)return false;if(d===ct){this.debug("GLOBSTAR",[t,d,p]);var f=o,g=a+1;if(g===h){for(this.debug("** at the end");o<l;o++)if(i[o]==="."||i[o]===".."||!s.dot&&i[o].charAt(0)===".")return false;return true}for(;f<l;){var y=i[f];if(this.debug(`
|
|
2
|
+
globstar while`,i,f,t,g,y),this.matchOne(i.slice(f),t.slice(g),e))return this.debug("globstar found match!",f,l,y),true;if(y==="."||y===".."||!s.dot&&y.charAt(0)==="."){this.debug("dot detected!",i,f,t,g);break}this.debug("globstar swallow a segment, and continue"),f++;}return !!(e&&(this.debug(`
|
|
3
|
+
>>> no match, partial?`,i,f,t,g),f===l))}let S;if(typeof d=="string"?(S=p===d,this.debug("string match",d,p,S)):(S=d.test(p),this.debug("pattern match",d,p,S)),!S)return false}if(o===l&&a===h)return true;if(o===l)return e;if(a===h)return o===l-1&&i[o]==="";throw new Error("wtf?")}braceExpand(){return sn(this.pattern,this.options)}parse(i){os(i);let t=this.options;if(i==="**")return ct;if(i==="")return "";let e,s=null;(e=i.match(Do))?s=t.dot?Ao:Po:(e=i.match(Eo))?s=(t.nocase?t.dot?Co:xo:t.dot?To:vo)(e[1]):(e=i.match(Io))?s=(t.nocase?t.dot?_o:No:t.dot?Fo:Uo)(e):(e=i.match(ko))?s=t.dot?Mo:Ro:(e=i.match(Oo))&&(s=Lo);let r=Jr.fromGlob(i,this.options).toMMPattern();return s&&typeof r=="object"&&Reflect.defineProperty(r,"test",{value:s}),r}makeRe(){if(this.regexp||this.regexp===false)return this.regexp;let i=this.set;if(!i.length)return this.regexp=false,this.regexp;let t=this.options,e=t.noglobstar?$o:t.dot?jo:Wo,s=new Set(t.nocase?["i"]:[]),r=i.map(l=>{let h=l.map(p=>{if(p instanceof RegExp)for(let f of p.flags.split(""))s.add(f);return typeof p=="string"?Ko(p):p===ct?ct:p._src});h.forEach((p,f)=>{let g=h[f+1],y=h[f-1];p!==ct||y===ct||(y===void 0?g!==void 0&&g!==ct?h[f+1]="(?:\\/|"+e+"\\/)?"+g:h[f]=e:g===void 0?h[f-1]=y+"(?:\\/|\\/"+e+")?":g!==ct&&(h[f-1]=y+"(?:\\/|\\/"+e+"\\/)"+g,h[f+1]=ct));});let d=h.filter(p=>p!==ct);if(this.partial&&d.length>=1){let p=[];for(let f=1;f<=d.length;f++)p.push(d.slice(0,f).join("/"));return "(?:"+p.join("|")+")"}return d.join("/")}).join("|"),[o,a]=i.length>1?["(?:",")"]:["",""];r="^"+o+r+a+"$",this.partial&&(r="^(?:\\/|"+o+r.slice(1,-1)+a+")$"),this.negate&&(r="^(?!"+r+").+$");try{this.regexp=new RegExp(r,[...s].join(""));}catch{this.regexp=false;}return this.regexp}slashSplit(i){return this.preserveMultipleSlashes?i.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(i)?["",...i.split(/\/+/)]:i.split(/\/+/)}match(i,t=this.partial){if(this.debug("match",i,this.pattern),this.comment)return false;if(this.empty)return i==="";if(i==="/"&&t)return true;let e=this.options;this.isWindows&&(i=i.split("\\").join("/"));let s=this.slashSplit(i);this.debug(this.pattern,"split",s);let r=this.set;this.debug(this.pattern,"set",r);let o=s[s.length-1];if(!o)for(let a=s.length-2;!o&&a>=0;a--)o=s[a];for(let a=0;a<r.length;a++){let l=r[a],h=s;if(e.matchBase&&l.length===1&&(h=[o]),this.matchOne(h,l,t))return e.flipNegate?true:!this.negate}return e.flipNegate?false:this.negate}static defaults(i){return dt.defaults(i).Minimatch}};dt.AST=Jr;dt.Minimatch=ye;dt.escape=Xr;dt.unescape=$e;var Yo=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,rn=new Set,Os=typeof process=="object"&&process?process:{},nn=(i,t,e,s)=>{typeof Os.emitWarning=="function"?Os.emitWarning(i,t,e,s):console.error(`[${e}] ${t}: ${i}`);},as=globalThis.AbortController,rr=globalThis.AbortSignal;if(typeof as>"u"){rr=class{constructor(){c(this,"onabort");c(this,"_onabort",[]);c(this,"reason");c(this,"aborted",false);}addEventListener(e,s){this._onabort.push(s);}},as=class{constructor(){c(this,"signal",new rr);t();}abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=true;for(let s of this.signal._onabort)s(e);this.signal.onabort?.(e);}}};let i=Os.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{i&&(i=false,nn("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t));};}var Zo=i=>!rn.has(i),ne=i=>i&&i===Math.floor(i)&&i>0&&isFinite(i),on=i=>ne(i)?i<=Math.pow(2,8)?Uint8Array:i<=Math.pow(2,16)?Uint16Array:i<=Math.pow(2,32)?Uint32Array:i<=Number.MAX_SAFE_INTEGER?Qi:null:null,Qi=class extends Array{constructor(i){super(i),this.fill(0);}},qt,je,Xo=(qt=class{constructor(t,e){c(this,"heap");c(this,"length");if(!n(qt,je))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0;}static create(t){let e=on(t);if(!e)return [];u(qt,je,true);let s=new qt(t,e);return u(qt,je,false),s}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},je=new WeakMap,w(qt,je,false),qt),br,Sr,Ct,yt,Dt,ke,Pt,We,Ge,At,G,It,j,N,O,at,wt,rt,Z,Nt,X,_t,Ft,bt,St,Ut,de,ht,Ve,v,Ls,Re,Zt,mi,Et,an,Me,qe,yi,oe,ae,Ds,ts,es,A,Ps,li,he,As,He,cs=(He=class{constructor(t){w(this,v);w(this,Ct);w(this,yt);w(this,Dt);w(this,ke);w(this,Pt);w(this,We);w(this,Ge);w(this,At);c(this,"ttl");c(this,"ttlResolution");c(this,"ttlAutopurge");c(this,"updateAgeOnGet");c(this,"updateAgeOnHas");c(this,"allowStale");c(this,"noDisposeOnSet");c(this,"noUpdateTTL");c(this,"maxEntrySize");c(this,"sizeCalculation");c(this,"noDeleteOnFetchRejection");c(this,"noDeleteOnStaleGet");c(this,"allowStaleOnFetchAbort");c(this,"allowStaleOnFetchRejection");c(this,"ignoreFetchAbort");w(this,G);w(this,It);w(this,j);w(this,N);w(this,O);w(this,at);w(this,wt);w(this,rt);w(this,Z);w(this,Nt);w(this,X);w(this,_t);w(this,Ft);w(this,bt);w(this,St);w(this,Ut);w(this,de);w(this,ht);w(this,Ve);w(this,Re,()=>{});w(this,Zt,()=>{});w(this,mi,()=>{});w(this,Et,()=>false);w(this,Me,t=>{});w(this,qe,(t,e,s)=>{});w(this,yi,(t,e,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});c(this,br,"LRUCache");let{max:e=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:a,updateAgeOnHas:l,allowStale:h,dispose:d,onInsert:p,disposeAfter:f,noDisposeOnSet:g,noUpdateTTL:y,maxSize:S=0,maxEntrySize:b=0,sizeCalculation:x,fetchMethod:E,memoMethod:k,noDeleteOnFetchRejection:L,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:C,allowStaleOnFetchAbort:P,ignoreFetchAbort:U,perf:ut}=t;if(ut!==void 0&&typeof ut?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(u(this,At,ut??Yo),e!==0&&!ne(e))throw new TypeError("max option must be a nonnegative integer");let _=e?on(e):Array;if(!_)throw new Error("invalid max value: "+e);if(u(this,Ct,e),u(this,yt,S),this.maxEntrySize=b||n(this,yt),this.sizeCalculation=x,this.sizeCalculation){if(!n(this,yt)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(k!==void 0&&typeof k!="function")throw new TypeError("memoMethod must be a function if defined");if(u(this,Ge,k),E!==void 0&&typeof E!="function")throw new TypeError("fetchMethod must be a function if specified");if(u(this,We,E),u(this,de,!!E),u(this,j,new Map),u(this,N,new Array(e).fill(void 0)),u(this,O,new Array(e).fill(void 0)),u(this,at,new _(e)),u(this,wt,new _(e)),u(this,rt,0),u(this,Z,0),u(this,Nt,Xo.create(e)),u(this,G,0),u(this,It,0),typeof d=="function"&&u(this,Dt,d),typeof p=="function"&&u(this,ke,p),typeof f=="function"?(u(this,Pt,f),u(this,X,[])):(u(this,Pt,void 0),u(this,X,void 0)),u(this,Ut,!!n(this,Dt)),u(this,Ve,!!n(this,ke)),u(this,ht,!!n(this,Pt)),this.noDisposeOnSet=!!g,this.noUpdateTTL=!!y,this.noDeleteOnFetchRejection=!!L,this.allowStaleOnFetchRejection=!!C,this.allowStaleOnFetchAbort=!!P,this.ignoreFetchAbort=!!U,this.maxEntrySize!==0){if(n(this,yt)!==0&&!ne(n(this,yt)))throw new TypeError("maxSize must be a positive integer if specified");if(!ne(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");m(this,v,an).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!l,this.ttlResolution=ne(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!ne(this.ttl))throw new TypeError("ttl must be a positive integer if specified");m(this,v,Ls).call(this);}if(n(this,Ct)===0&&this.ttl===0&&n(this,yt)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!n(this,Ct)&&!n(this,yt)){let q="LRU_CACHE_UNBOUNDED";Zo(q)&&(rn.add(q),nn("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",q,He));}}get perf(){return n(this,At)}static unsafeExposeInternals(t){return {starts:n(t,Ft),ttls:n(t,bt),autopurgeTimers:n(t,St),sizes:n(t,_t),keyMap:n(t,j),keyList:n(t,N),valList:n(t,O),next:n(t,at),prev:n(t,wt),get head(){return n(t,rt)},get tail(){return n(t,Z)},free:n(t,Nt),isBackgroundFetch:e=>{var s;return m(s=t,v,A).call(s,e)},backgroundFetch:(e,s,r,o)=>{var a;return m(a=t,v,es).call(a,e,s,r,o)},moveToTail:e=>{var s;return m(s=t,v,li).call(s,e)},indexes:e=>{var s;return m(s=t,v,oe).call(s,e)},rindexes:e=>{var s;return m(s=t,v,ae).call(s,e)},isStale:e=>{var s;return n(s=t,Et).call(s,e)}}}get max(){return n(this,Ct)}get maxSize(){return n(this,yt)}get calculatedSize(){return n(this,It)}get size(){return n(this,G)}get fetchMethod(){return n(this,We)}get memoMethod(){return n(this,Ge)}get dispose(){return n(this,Dt)}get onInsert(){return n(this,ke)}get disposeAfter(){return n(this,Pt)}getRemainingTTL(t){return n(this,j).has(t)?1/0:0}*entries(){for(let t of m(this,v,oe).call(this))n(this,O)[t]!==void 0&&n(this,N)[t]!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield [n(this,N)[t],n(this,O)[t]]);}*rentries(){for(let t of m(this,v,ae).call(this))n(this,O)[t]!==void 0&&n(this,N)[t]!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield [n(this,N)[t],n(this,O)[t]]);}*keys(){for(let t of m(this,v,oe).call(this)){let e=n(this,N)[t];e!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield e);}}*rkeys(){for(let t of m(this,v,ae).call(this)){let e=n(this,N)[t];e!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield e);}}*values(){for(let t of m(this,v,oe).call(this))n(this,O)[t]!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield n(this,O)[t]);}*rvalues(){for(let t of m(this,v,ae).call(this))n(this,O)[t]!==void 0&&!m(this,v,A).call(this,n(this,O)[t])&&(yield n(this,O)[t]);}[(Sr=Symbol.iterator,br=Symbol.toStringTag,Sr)](){return this.entries()}find(t,e={}){for(let s of m(this,v,oe).call(this)){let r=n(this,O)[s],o=m(this,v,A).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&t(o,n(this,N)[s],this))return this.get(n(this,N)[s],e)}}forEach(t,e=this){for(let s of m(this,v,oe).call(this)){let r=n(this,O)[s],o=m(this,v,A).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(e,o,n(this,N)[s],this);}}rforEach(t,e=this){for(let s of m(this,v,ae).call(this)){let r=n(this,O)[s],o=m(this,v,A).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(e,o,n(this,N)[s],this);}}purgeStale(){let t=false;for(let e of m(this,v,ae).call(this,{allowStale:true}))n(this,Et).call(this,e)&&(m(this,v,he).call(this,n(this,N)[e],"expire"),t=true);return t}info(t){let e=n(this,j).get(t);if(e===void 0)return;let s=n(this,O)[e],r=m(this,v,A).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(n(this,bt)&&n(this,Ft)){let a=n(this,bt)[e],l=n(this,Ft)[e];if(a&&l){let h=a-(n(this,At).now()-l);o.ttl=h,o.start=Date.now();}}return n(this,_t)&&(o.size=n(this,_t)[e]),o}dump(){let t=[];for(let e of m(this,v,oe).call(this,{allowStale:true})){let s=n(this,N)[e],r=n(this,O)[e],o=m(this,v,A).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let a={value:o};if(n(this,bt)&&n(this,Ft)){a.ttl=n(this,bt)[e];let l=n(this,At).now()-n(this,Ft)[e];a.start=Math.floor(Date.now()-l);}n(this,_t)&&(a.size=n(this,_t)[e]),t.unshift([s,a]);}return t}load(t){this.clear();for(let[e,s]of t){if(s.start){let r=Date.now()-s.start;s.start=n(this,At).now()-r;}this.set(e,s.value,s);}}set(t,e,s={}){var g,y,S,b;if(e===void 0)return this.delete(t),this;let{ttl:r=this.ttl,start:o,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:h}=s,{noUpdateTTL:d=this.noUpdateTTL}=s,p=n(this,yi).call(this,t,e,s.size||0,l);if(this.maxEntrySize&&p>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),m(this,v,he).call(this,t,"set"),this;let f=n(this,G)===0?void 0:n(this,j).get(t);if(f===void 0)f=n(this,G)===0?n(this,Z):n(this,Nt).length!==0?n(this,Nt).pop():n(this,G)===n(this,Ct)?m(this,v,ts).call(this,false):n(this,G),n(this,N)[f]=t,n(this,O)[f]=e,n(this,j).set(t,f),n(this,at)[n(this,Z)]=f,n(this,wt)[f]=n(this,Z),u(this,Z,f),Wi(this,G)._++,n(this,qe).call(this,f,p,h),h&&(h.set="add"),d=false,n(this,Ve)&&((g=n(this,ke))==null||g.call(this,e,t,"add"));else {m(this,v,li).call(this,f);let x=n(this,O)[f];if(e!==x){if(n(this,de)&&m(this,v,A).call(this,x)){x.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:E}=x;E!==void 0&&!a&&(n(this,Ut)&&((y=n(this,Dt))==null||y.call(this,E,t,"set")),n(this,ht)&&n(this,X)?.push([E,t,"set"]));}else a||(n(this,Ut)&&((S=n(this,Dt))==null||S.call(this,x,t,"set")),n(this,ht)&&n(this,X)?.push([x,t,"set"]));if(n(this,Me).call(this,f),n(this,qe).call(this,f,p,h),n(this,O)[f]=e,h){h.set="replace";let E=x&&m(this,v,A).call(this,x)?x.__staleWhileFetching:x;E!==void 0&&(h.oldValue=E);}}else h&&(h.set="update");n(this,Ve)&&this.onInsert?.(e,t,e===x?"update":"replace");}if(r!==0&&!n(this,bt)&&m(this,v,Ls).call(this),n(this,bt)&&(d||n(this,mi).call(this,f,r,o),h&&n(this,Zt).call(this,h,f)),!a&&n(this,ht)&&n(this,X)){let x=n(this,X),E;for(;E=x?.shift();)(b=n(this,Pt))==null||b.call(this,...E);}return this}pop(){var t;try{for(;n(this,G);){let e=n(this,O)[n(this,rt)];if(m(this,v,ts).call(this,!0),m(this,v,A).call(this,e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(n(this,ht)&&n(this,X)){let e=n(this,X),s;for(;s=e?.shift();)(t=n(this,Pt))==null||t.call(this,...s);}}}has(t,e={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=e,o=n(this,j).get(t);if(o!==void 0){let a=n(this,O)[o];if(m(this,v,A).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(n(this,Et).call(this,o))r&&(r.has="stale",n(this,Zt).call(this,r,o));else return s&&n(this,Re).call(this,o),r&&(r.has="hit",n(this,Zt).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(t,e={}){let{allowStale:s=this.allowStale}=e,r=n(this,j).get(t);if(r===void 0||!s&&n(this,Et).call(this,r))return;let o=n(this,O)[r];return m(this,v,A).call(this,o)?o.__staleWhileFetching:o}async fetch(t,e={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:h=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:p=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:g=this.allowStaleOnFetchRejection,ignoreFetchAbort:y=this.ignoreFetchAbort,allowStaleOnFetchAbort:S=this.allowStaleOnFetchAbort,context:b,forceRefresh:x=false,status:E,signal:k}=e;if(!n(this,de))return E&&(E.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:E});let L={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:a,noDisposeOnSet:l,size:h,sizeCalculation:d,noUpdateTTL:p,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:g,allowStaleOnFetchAbort:S,ignoreFetchAbort:y,status:E,signal:k},D=n(this,j).get(t);if(D===void 0){E&&(E.fetch="miss");let C=m(this,v,es).call(this,t,D,L,b);return C.__returned=C}else {let C=n(this,O)[D];if(m(this,v,A).call(this,C)){let _=s&&C.__staleWhileFetching!==void 0;return E&&(E.fetch="inflight",_&&(E.returnedStale=true)),_?C.__staleWhileFetching:C.__returned=C}let P=n(this,Et).call(this,D);if(!x&&!P)return E&&(E.fetch="hit"),m(this,v,li).call(this,D),r&&n(this,Re).call(this,D),E&&n(this,Zt).call(this,E,D),C;let U=m(this,v,es).call(this,t,D,L,b),ut=U.__staleWhileFetching!==void 0&&s;return E&&(E.fetch=P?"stale":"refresh",ut&&P&&(E.returnedStale=true)),ut?U.__staleWhileFetching:U.__returned=U}}async forceFetch(t,e={}){let s=await this.fetch(t,e);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(t,e={}){let s=n(this,Ge);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:o,...a}=e,l=this.get(t,a);if(!o&&l!==void 0)return l;let h=s(t,l,{options:a,context:r});return this.set(t,h,a),h}get(t,e={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:a}=e,l=n(this,j).get(t);if(l!==void 0){let h=n(this,O)[l],d=m(this,v,A).call(this,h);return a&&n(this,Zt).call(this,a,l),n(this,Et).call(this,l)?(a&&(a.get="stale"),d?(a&&s&&h.__staleWhileFetching!==void 0&&(a.returnedStale=true),s?h.__staleWhileFetching:void 0):(o||m(this,v,he).call(this,t,"expire"),a&&s&&(a.returnedStale=true),s?h:void 0)):(a&&(a.get="hit"),d?h.__staleWhileFetching:(m(this,v,li).call(this,l),r&&n(this,Re).call(this,l),h))}else a&&(a.get="miss");}delete(t){return m(this,v,he).call(this,t,"delete")}clear(){return m(this,v,As).call(this,"delete")}},Ct=new WeakMap,yt=new WeakMap,Dt=new WeakMap,ke=new WeakMap,Pt=new WeakMap,We=new WeakMap,Ge=new WeakMap,At=new WeakMap,G=new WeakMap,It=new WeakMap,j=new WeakMap,N=new WeakMap,O=new WeakMap,at=new WeakMap,wt=new WeakMap,rt=new WeakMap,Z=new WeakMap,Nt=new WeakMap,X=new WeakMap,_t=new WeakMap,Ft=new WeakMap,bt=new WeakMap,St=new WeakMap,Ut=new WeakMap,de=new WeakMap,ht=new WeakMap,Ve=new WeakMap,v=new WeakSet,Ls=function(){let t=new Qi(n(this,Ct)),e=new Qi(n(this,Ct));u(this,bt,t),u(this,Ft,e);let s=this.ttlAutopurge?new Array(n(this,Ct)):void 0;u(this,St,s),u(this,mi,(a,l,h=n(this,At).now())=>{if(e[a]=l!==0?h:0,t[a]=l,s?.[a]&&(clearTimeout(s[a]),s[a]=void 0),l!==0&&s){let d=setTimeout(()=>{n(this,Et).call(this,a)&&m(this,v,he).call(this,n(this,N)[a],"expire");},l+1);d.unref&&d.unref(),s[a]=d;}}),u(this,Re,a=>{e[a]=t[a]!==0?n(this,At).now():0;}),u(this,Zt,(a,l)=>{if(t[l]){let h=t[l],d=e[l];if(!h||!d)return;a.ttl=h,a.start=d,a.now=r||o();let p=a.now-d;a.remainingTTL=h-p;}});let r=0,o=()=>{let a=n(this,At).now();if(this.ttlResolution>0){r=a;let l=setTimeout(()=>r=0,this.ttlResolution);l.unref&&l.unref();}return a};this.getRemainingTTL=a=>{let l=n(this,j).get(a);if(l===void 0)return 0;let h=t[l],d=e[l];if(!h||!d)return 1/0;let p=(r||o())-d;return h-p},u(this,Et,a=>{let l=e[a],h=t[a];return !!h&&!!l&&(r||o())-l>h});},Re=new WeakMap,Zt=new WeakMap,mi=new WeakMap,Et=new WeakMap,an=function(){let t=new Qi(n(this,Ct));u(this,It,0),u(this,_t,t),u(this,Me,e=>{u(this,It,n(this,It)-t[e]),t[e]=0;}),u(this,yi,(e,s,r,o)=>{if(m(this,v,A).call(this,s))return 0;if(!ne(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,e),!ne(r))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return r}),u(this,qe,(e,s,r)=>{if(t[e]=s,n(this,yt)){let o=n(this,yt)-t[e];for(;n(this,It)>o;)m(this,v,ts).call(this,true);}u(this,It,n(this,It)+t[e]),r&&(r.entrySize=s,r.totalCalculatedSize=n(this,It));});},Me=new WeakMap,qe=new WeakMap,yi=new WeakMap,oe=function*({allowStale:t=this.allowStale}={}){if(n(this,G))for(let e=n(this,Z);!(!m(this,v,Ds).call(this,e)||((t||!n(this,Et).call(this,e))&&(yield e),e===n(this,rt)));)e=n(this,wt)[e];},ae=function*({allowStale:t=this.allowStale}={}){if(n(this,G))for(let e=n(this,rt);!(!m(this,v,Ds).call(this,e)||((t||!n(this,Et).call(this,e))&&(yield e),e===n(this,Z)));)e=n(this,at)[e];},Ds=function(t){return t!==void 0&&n(this,j).get(n(this,N)[t])===t},ts=function(t){var o;let e=n(this,rt),s=n(this,N)[e],r=n(this,O)[e];return n(this,de)&&m(this,v,A).call(this,r)?r.__abortController.abort(new Error("evicted")):(n(this,Ut)||n(this,ht))&&(n(this,Ut)&&((o=n(this,Dt))==null||o.call(this,r,s,"evict")),n(this,ht)&&n(this,X)?.push([r,s,"evict"])),n(this,Me).call(this,e),n(this,St)?.[e]&&(clearTimeout(n(this,St)[e]),n(this,St)[e]=void 0),t&&(n(this,N)[e]=void 0,n(this,O)[e]=void 0,n(this,Nt).push(e)),n(this,G)===1?(u(this,rt,u(this,Z,0)),n(this,Nt).length=0):u(this,rt,n(this,at)[e]),n(this,j).delete(s),Wi(this,G)._--,e},es=function(t,e,s,r){let o=e===void 0?void 0:n(this,O)[e];if(m(this,v,A).call(this,o))return o;let a=new as,{signal:l}=s;l?.addEventListener("abort",()=>a.abort(l.reason),{signal:a.signal});let h={signal:a.signal,options:s,context:r},d=(b,x=false)=>{let{aborted:E}=a.signal,k=s.ignoreFetchAbort&&b!==void 0,L=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&b!==void 0);if(s.status&&(E&&!x?(s.status.fetchAborted=true,s.status.fetchError=a.signal.reason,k&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),E&&!k&&!x)return f(a.signal.reason,L);let D=y,C=n(this,O)[e];return (C===y||k&&x&&C===void 0)&&(b===void 0?D.__staleWhileFetching!==void 0?n(this,O)[e]=D.__staleWhileFetching:m(this,v,he).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,b,h.options))),b},p=b=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=b),f(b,false)),f=(b,x)=>{let{aborted:E}=a.signal,k=E&&s.allowStaleOnFetchAbort,L=k||s.allowStaleOnFetchRejection,D=L||s.noDeleteOnFetchRejection,C=y;if(n(this,O)[e]===y&&(!D||!x&&C.__staleWhileFetching===void 0?m(this,v,he).call(this,t,"fetch"):k||(n(this,O)[e]=C.__staleWhileFetching)),L)return s.status&&C.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),C.__staleWhileFetching;if(C.__returned===C)throw b},g=(b,x)=>{var k;let E=(k=n(this,We))==null?void 0:k.call(this,t,o,h);E&&E instanceof Promise&&E.then(L=>b(L===void 0?void 0:L),x),a.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(b(void 0),s.allowStaleOnFetchAbort&&(b=L=>d(L,true)));});};s.status&&(s.status.fetchDispatched=true);let y=new Promise(g).then(d,p),S=Object.assign(y,{__abortController:a,__staleWhileFetching:o,__returned:void 0});return e===void 0?(this.set(t,S,{...h.options,status:void 0}),e=n(this,j).get(t)):n(this,O)[e]=S,S},A=function(t){if(!n(this,de))return false;let e=t;return !!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof as},Ps=function(t,e){n(this,wt)[e]=t,n(this,at)[t]=e;},li=function(t){t!==n(this,Z)&&(t===n(this,rt)?u(this,rt,n(this,at)[t]):m(this,v,Ps).call(this,n(this,wt)[t],n(this,at)[t]),m(this,v,Ps).call(this,n(this,Z),t),u(this,Z,t));},he=function(t,e){var r,o;let s=false;if(n(this,G)!==0){let a=n(this,j).get(t);if(a!==void 0)if(n(this,St)?.[a]&&(clearTimeout(n(this,St)?.[a]),n(this,St)[a]=void 0),s=true,n(this,G)===1)m(this,v,As).call(this,e);else {n(this,Me).call(this,a);let l=n(this,O)[a];if(m(this,v,A).call(this,l)?l.__abortController.abort(new Error("deleted")):(n(this,Ut)||n(this,ht))&&(n(this,Ut)&&((r=n(this,Dt))==null||r.call(this,l,t,e)),n(this,ht)&&n(this,X)?.push([l,t,e])),n(this,j).delete(t),n(this,N)[a]=void 0,n(this,O)[a]=void 0,a===n(this,Z))u(this,Z,n(this,wt)[a]);else if(a===n(this,rt))u(this,rt,n(this,at)[a]);else {let h=n(this,wt)[a];n(this,at)[h]=n(this,at)[a];let d=n(this,at)[a];n(this,wt)[d]=n(this,wt)[a];}Wi(this,G)._--,n(this,Nt).push(a);}}if(n(this,ht)&&n(this,X)?.length){let a=n(this,X),l;for(;l=a?.shift();)(o=n(this,Pt))==null||o.call(this,...l);}return s},As=function(t){var e,s;for(let r of m(this,v,ae).call(this,{allowStale:true})){let o=n(this,O)[r];if(m(this,v,A).call(this,o))o.__abortController.abort(new Error("deleted"));else {let a=n(this,N)[r];n(this,Ut)&&((e=n(this,Dt))==null||e.call(this,o,a,t)),n(this,ht)&&n(this,X)?.push([o,a,t]);}}if(n(this,j).clear(),n(this,O).fill(void 0),n(this,N).fill(void 0),n(this,bt)&&n(this,Ft)){n(this,bt).fill(0),n(this,Ft).fill(0);for(let r of n(this,St)??[])r!==void 0&&clearTimeout(r);n(this,St)?.fill(void 0);}if(n(this,_t)&&n(this,_t).fill(0),u(this,rt,0),u(this,Z,0),n(this,Nt).length=0,u(this,It,0),u(this,G,0),n(this,ht)&&n(this,X)){let r=n(this,X),o;for(;o=r?.shift();)(s=n(this,Pt))==null||s.call(this,...o);}},He),nr=typeof process=="object"&&process?process:{stdout:null,stderr:null},ua=i=>!!i&&typeof i=="object"&&(i instanceof hs||i instanceof hn||fa(i)||pa(i)),fa=i=>!!i&&typeof i=="object"&&i instanceof EventEmitter&&typeof i.pipe=="function"&&i.pipe!==hn.Writable.prototype.pipe,pa=i=>!!i&&typeof i=="object"&&i instanceof EventEmitter&&typeof i.write=="function"&&typeof i.end=="function",Kt=Symbol("EOF"),Jt=Symbol("maybeEmitEnd"),re=Symbol("emittedEnd"),Vi=Symbol("emittingEnd"),si=Symbol("emittedError"),qi=Symbol("closed"),or=Symbol("read"),Hi=Symbol("flush"),ar=Symbol("flushChunk"),Ot=Symbol("encoding"),Be=Symbol("decoder"),H=Symbol("flowing"),ri=Symbol("paused"),ze=Symbol("resume"),K=Symbol("buffer"),ot=Symbol("pipes"),J=Symbol("bufferLength"),Es=Symbol("bufferPush"),Ki=Symbol("bufferShift"),st=Symbol("objectMode"),B=Symbol("destroyed"),vs=Symbol("error"),Ts=Symbol("emitData"),hr=Symbol("emitEnd"),xs=Symbol("emitEnd2"),$t=Symbol("async"),Cs=Symbol("abort"),Ji=Symbol("aborted"),ni=Symbol("signal"),Ee=Symbol("dataListeners"),mt=Symbol("discarded"),oi=i=>Promise.resolve().then(i),ga=i=>i(),ma=i=>i==="end"||i==="finish"||i==="prefinish",ya=i=>i instanceof ArrayBuffer||!!i&&typeof i=="object"&&i.constructor&&i.constructor.name==="ArrayBuffer"&&i.byteLength>=0,wa=i=>!Buffer.isBuffer(i)&&ArrayBuffer.isView(i),ln=class{constructor(i,t,e){c(this,"src");c(this,"dest");c(this,"opts");c(this,"ondrain");this.src=i,this.dest=t,this.opts=e,this.ondrain=()=>i[ze](),this.dest.on("drain",this.ondrain);}unpipe(){this.dest.removeListener("drain",this.ondrain);}proxyErrors(i){}end(){this.unpipe(),this.opts.end&&this.dest.end();}},ba=class extends ln{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe();}constructor(i,t,e){super(i,t,e),this.proxyErrors=s=>t.emit("error",s),i.on("error",this.proxyErrors);}},Sa=i=>!!i.objectMode,Ea=i=>!i.objectMode&&!!i.encoding&&i.encoding!=="buffer",Er,vr,Tr,xr,Cr,kr,Rr,Mr,Or,Lr,Dr,Pr,Ar,Ir,Nr,_r,Fr,Ur,Br,hs=class extends EventEmitter{constructor(...t){let e=t[0]||{};super();c(this,Br,false);c(this,Ur,false);c(this,Fr,[]);c(this,_r,[]);c(this,Nr);c(this,Ir);c(this,Ar);c(this,Pr);c(this,Dr,false);c(this,Lr,false);c(this,Or,false);c(this,Mr,false);c(this,Rr,null);c(this,kr,0);c(this,Cr,false);c(this,xr);c(this,Tr,false);c(this,vr,0);c(this,Er,false);c(this,"writable",true);c(this,"readable",true);if(e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Sa(e)?(this[st]=true,this[Ot]=null):Ea(e)?(this[Ot]=e.encoding,this[st]=false):(this[st]=false,this[Ot]=null),this[$t]=!!e.async,this[Be]=this[Ot]?new StringDecoder(this[Ot]):null,e&&e.debugExposeBuffer===true&&Object.defineProperty(this,"buffer",{get:()=>this[K]}),e&&e.debugExposePipes===true&&Object.defineProperty(this,"pipes",{get:()=>this[ot]});let{signal:s}=e;s&&(this[ni]=s,s.aborted?this[Cs]():s.addEventListener("abort",()=>this[Cs]()));}get bufferLength(){return this[J]}get encoding(){return this[Ot]}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[st]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[$t]}set async(t){this[$t]=this[$t]||!!t;}[(Br=H,Ur=ri,Fr=ot,_r=K,Nr=st,Ir=Ot,Ar=$t,Pr=Be,Dr=Kt,Lr=re,Or=Vi,Mr=qi,Rr=si,kr=J,Cr=B,xr=ni,Tr=Ji,vr=Ee,Er=mt,Cs)](){this[Ji]=true,this.emit("abort",this[ni]?.reason),this.destroy(this[ni]?.reason);}get aborted(){return this[Ji]}set aborted(t){}write(t,e,s){if(this[Ji])return false;if(this[Kt])throw new Error("write after end");if(this[B])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),true;typeof e=="function"&&(s=e,e="utf8"),e||(e="utf8");let r=this[$t]?oi:ga;if(!this[st]&&!Buffer.isBuffer(t)){if(wa(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(ya(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[st]?(this[H]&&this[J]!==0&&this[Hi](true),this[H]?this.emit("data",t):this[Es](t),this[J]!==0&&this.emit("readable"),s&&r(s),this[H]):t.length?(typeof t=="string"&&!(e===this[Ot]&&!this[Be]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[Ot]&&(t=this[Be].write(t)),this[H]&&this[J]!==0&&this[Hi](true),this[H]?this.emit("data",t):this[Es](t),this[J]!==0&&this.emit("readable"),s&&r(s),this[H]):(this[J]!==0&&this.emit("readable"),s&&r(s),this[H])}read(t){if(this[B])return null;if(this[mt]=false,this[J]===0||t===0||t&&t>this[J])return this[Jt](),null;this[st]&&(t=null),this[K].length>1&&!this[st]&&(this[K]=[this[Ot]?this[K].join(""):Buffer.concat(this[K],this[J])]);let e=this[or](t||null,this[K][0]);return this[Jt](),e}[or](t,e){if(this[st])this[Ki]();else {let s=e;t===s.length||t===null?this[Ki]():typeof s=="string"?(this[K][0]=s.slice(t),e=s.slice(0,t),this[J]-=t):(this[K][0]=s.subarray(t),e=s.subarray(0,t),this[J]-=t);}return this.emit("data",e),!this[K].length&&!this[Kt]&&this.emit("drain"),e}end(t,e,s){return typeof t=="function"&&(s=t,t=void 0),typeof e=="function"&&(s=e,e="utf8"),t!==void 0&&this.write(t,e),s&&this.once("end",s),this[Kt]=true,this.writable=false,(this[H]||!this[ri])&&this[Jt](),this}[ze](){this[B]||(!this[Ee]&&!this[ot].length&&(this[mt]=true),this[ri]=false,this[H]=true,this.emit("resume"),this[K].length?this[Hi]():this[Kt]?this[Jt]():this.emit("drain"));}resume(){return this[ze]()}pause(){this[H]=false,this[ri]=true,this[mt]=false;}get destroyed(){return this[B]}get flowing(){return this[H]}get paused(){return this[ri]}[Es](t){this[st]?this[J]+=1:this[J]+=t.length,this[K].push(t);}[Ki](){return this[st]?this[J]-=1:this[J]-=this[K][0].length,this[K].shift()}[Hi](t=false){do;while(this[ar](this[Ki]())&&this[K].length);!t&&!this[K].length&&!this[Kt]&&this.emit("drain");}[ar](t){return this.emit("data",t),this[H]}pipe(t,e){if(this[B])return t;this[mt]=false;let s=this[re];return e=e||{},t===nr.stdout||t===nr.stderr?e.end=false:e.end=e.end!==false,e.proxyErrors=!!e.proxyErrors,s?e.end&&t.end():(this[ot].push(e.proxyErrors?new ba(this,t,e):new ln(this,t,e)),this[$t]?oi(()=>this[ze]()):this[ze]()),t}unpipe(t){let e=this[ot].find(s=>s.dest===t);e&&(this[ot].length===1?(this[H]&&this[Ee]===0&&(this[H]=false),this[ot]=[]):this[ot].splice(this[ot].indexOf(e),1),e.unpipe());}addListener(t,e){return this.on(t,e)}on(t,e){let s=super.on(t,e);if(t==="data")this[mt]=false,this[Ee]++,!this[ot].length&&!this[H]&&this[ze]();else if(t==="readable"&&this[J]!==0)super.emit("readable");else if(ma(t)&&this[re])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[si]){let r=e;this[$t]?oi(()=>r.call(this,this[si])):r.call(this,this[si]);}return s}removeListener(t,e){return this.off(t,e)}off(t,e){let s=super.off(t,e);return t==="data"&&(this[Ee]=this.listeners("data").length,this[Ee]===0&&!this[mt]&&!this[ot].length&&(this[H]=false)),s}removeAllListeners(t){let e=super.removeAllListeners(t);return (t==="data"||t===void 0)&&(this[Ee]=0,!this[mt]&&!this[ot].length&&(this[H]=false)),e}get emittedEnd(){return this[re]}[Jt](){!this[Vi]&&!this[re]&&!this[B]&&this[K].length===0&&this[Kt]&&(this[Vi]=true,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[qi]&&this.emit("close"),this[Vi]=false);}emit(t,...e){let s=e[0];if(t!=="error"&&t!=="close"&&t!==B&&this[B])return false;if(t==="data")return !this[st]&&!s?false:this[$t]?(oi(()=>this[Ts](s)),true):this[Ts](s);if(t==="end")return this[hr]();if(t==="close"){if(this[qi]=true,!this[re]&&!this[B])return false;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[si]=s,super.emit(vs,s);let o=!this[ni]||this.listeners("error").length?super.emit("error",s):false;return this[Jt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Jt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let r=super.emit(t,...e);return this[Jt](),r}[Ts](t){for(let s of this[ot])s.dest.write(t)===false&&this.pause();let e=this[mt]?false:super.emit("data",t);return this[Jt](),e}[hr](){return this[re]?false:(this[re]=true,this.readable=false,this[$t]?(oi(()=>this[xs]()),true):this[xs]())}[xs](){if(this[Be]){let e=this[Be].end();if(e){for(let s of this[ot])s.dest.write(e);this[mt]||super.emit("data",e);}}for(let e of this[ot])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[st]||(t.dataLength=0);let e=this.promise();return this.on("data",s=>{t.push(s),this[st]||(t.dataLength+=s.length);}),await e,t}async concat(){if(this[st])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[Ot]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(B,()=>e(new Error("stream destroyed"))),this.on("error",s=>e(s)),this.on("end",()=>t());})}[Symbol.asyncIterator](){this[mt]=false;let t=false,e=async()=>(this.pause(),t=true,{value:void 0,done:true});return {next:()=>{if(t)return e();let s=this.read();if(s!==null)return Promise.resolve({done:false,value:s});if(this[Kt])return e();let r,o,a=p=>{this.off("data",l),this.off("end",h),this.off(B,d),e(),o(p);},l=p=>{this.off("error",a),this.off("end",h),this.off(B,d),this.pause(),r({value:p,done:!!this[Kt]});},h=()=>{this.off("error",a),this.off("data",l),this.off(B,d),e(),r({done:true,value:void 0});},d=()=>a(new Error("stream destroyed"));return new Promise((p,f)=>{o=f,r=p,this.once(B,d),this.once("error",a),this.once("end",h),this.once("data",l);})},throw:e,return:e,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[mt]=false;let t=false,e=()=>(this.pause(),this.off(vs,e),this.off(B,e),this.off("end",e),t=true,{done:true,value:void 0}),s=()=>{if(t)return e();let r=this.read();return r===null?e():{done:false,value:r}};return this.once("end",e),this.once(vs,e),this.once(B,e),{next:s,throw:e,return:e,[Symbol.iterator](){return this}}}destroy(t){if(this[B])return t?this.emit("error",t):this.emit(B),this;this[B]=true,this[mt]=true,this[K].length=0,this[J]=0;let e=this;return typeof e.close=="function"&&!this[qi]&&e.close(),t?this.emit("error",t):this.emit(B),this}static get isStream(){return ua}},va=realpathSync.native,ci={lstatSync:lstatSync,readdir:readdir$1,readdirSync:readdirSync,readlinkSync:readlinkSync,realpathSync:va,promises:{lstat:lstat,readdir:readdir,readlink:readlink,realpath:realpath}},cn=i=>!i||i===ci||i===z?ci:{...ci,...i,promises:{...ci.promises,...i.promises||{}}},dn=/^\\\\\?\\([a-z]:)\\?$/i,Ta=i=>i.replace(/\//g,"\\").replace(dn,"$1\\"),xa=/[\\\/]/,kt=0,un=1,fn=2,jt=4,pn=6,gn=8,ve=10,mn=12,xt=15,ai=~xt,ks=16,lr=32,di=64,Lt=128,Yi=256,is=512,cr=di|Lt|is,Ca=1023,Rs=i=>i.isFile()?gn:i.isDirectory()?jt:i.isSymbolicLink()?ve:i.isCharacterDevice()?fn:i.isBlockDevice()?pn:i.isSocket()?mn:i.isFIFO()?un:kt,dr=new cs({max:2**12}),ui=i=>{let t=dr.get(i);if(t)return t;let e=i.normalize("NFKD");return dr.set(i,e),e},ur=new cs({max:2**12}),Zi=i=>{let t=ur.get(i);if(t)return t;let e=ui(i.toLowerCase());return ur.set(i,e),e},fr=class extends cs{constructor(){super({max:256});}},ka=class extends cs{constructor(i=16*1024){super({maxSize:i,sizeCalculation:t=>t.length+1});}},yn=Symbol("PathScurry setAsCwd"),lt,wi,bi,Si,Ei,vi,Ti,xi,Ci,ki,Ri,Mi,Oi,Li,Di,Pi,Ai,Ii,Ni,ue,Oe,Gt,Xt,Qt,te,M,Le,ee,Vt,R,Ns,ss,fi,_s,Fs,pi,rs,Us,Bs,ns,wn,bn,Sn,zs,Ke,Je,En,De,zr,ft=(zr=class{constructor(i,t=kt,e,s,r,o,a){w(this,R);c(this,"name");c(this,"root");c(this,"roots");c(this,"parent");c(this,"nocase");c(this,"isCWD",false);w(this,lt);w(this,wi);w(this,bi);w(this,Si);w(this,Ei);w(this,vi);w(this,Ti);w(this,xi);w(this,Ci);w(this,ki);w(this,Ri);w(this,Mi);w(this,Oi);w(this,Li);w(this,Di);w(this,Pi);w(this,Ai);w(this,Ii);w(this,Ni);w(this,ue);w(this,Oe);w(this,Gt);w(this,Xt);w(this,Qt);w(this,te);w(this,M);w(this,Le);w(this,ee);w(this,Vt);w(this,Ke,[]);w(this,Je,false);w(this,De);this.name=i,u(this,ue,r?Zi(i):ui(i)),u(this,M,t&Ca),this.nocase=r,this.roots=s,this.root=e||this,u(this,Le,o),u(this,Gt,a.fullpath),u(this,Qt,a.relative),u(this,te,a.relativePosix),this.parent=a.parent,this.parent?u(this,lt,n(this.parent,lt)):u(this,lt,cn(a.fs));}get dev(){return n(this,wi)}get mode(){return n(this,bi)}get nlink(){return n(this,Si)}get uid(){return n(this,Ei)}get gid(){return n(this,vi)}get rdev(){return n(this,Ti)}get blksize(){return n(this,xi)}get ino(){return n(this,Ci)}get size(){return n(this,ki)}get blocks(){return n(this,Ri)}get atimeMs(){return n(this,Mi)}get mtimeMs(){return n(this,Oi)}get ctimeMs(){return n(this,Li)}get birthtimeMs(){return n(this,Di)}get atime(){return n(this,Pi)}get mtime(){return n(this,Ai)}get ctime(){return n(this,Ii)}get birthtime(){return n(this,Ni)}get parentPath(){return (this.parent||this).fullpath()}get path(){return this.parentPath}depth(){return n(this,Oe)!==void 0?n(this,Oe):this.parent?u(this,Oe,this.parent.depth()+1):u(this,Oe,0)}childrenCache(){return n(this,Le)}resolve(i){var s;if(!i)return this;let t=this.getRootString(i),e=i.substring(t.length).split(this.splitSep);return t?m(s=this.getRoot(t),R,Ns).call(s,e):m(this,R,Ns).call(this,e)}children(){let i=n(this,Le).get(this);if(i)return i;let t=Object.assign([],{provisional:0});return n(this,Le).set(this,t),u(this,M,n(this,M)&~ks),t}child(i,t){if(i===""||i===".")return this;if(i==="..")return this.parent||this;let e=this.children(),s=this.nocase?Zi(i):ui(i);for(let l of e)if(n(l,ue)===s)return l;let r=this.parent?this.sep:"",o=n(this,Gt)?n(this,Gt)+r+i:void 0,a=this.newChild(i,kt,{...t,parent:this,fullpath:o});return this.canReaddir()||u(a,M,n(a,M)|Lt),e.push(a),a}relative(){if(this.isCWD)return "";if(n(this,Qt)!==void 0)return n(this,Qt);let i=this.name,t=this.parent;if(!t)return u(this,Qt,this.name);let e=t.relative();return e+(!e||!t.parent?"":this.sep)+i}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return "";if(n(this,te)!==void 0)return n(this,te);let i=this.name,t=this.parent;if(!t)return u(this,te,this.fullpathPosix());let e=t.relativePosix();return e+(!e||!t.parent?"":"/")+i}fullpath(){if(n(this,Gt)!==void 0)return n(this,Gt);let i=this.name,t=this.parent;if(!t)return u(this,Gt,this.name);let e=t.fullpath()+(t.parent?this.sep:"")+i;return u(this,Gt,e)}fullpathPosix(){if(n(this,Xt)!==void 0)return n(this,Xt);if(this.sep==="/")return u(this,Xt,this.fullpath());if(!this.parent){let s=this.fullpath().replace(/\\/g,"/");return /^[a-z]:\//i.test(s)?u(this,Xt,`//?/${s}`):u(this,Xt,s)}let i=this.parent,t=i.fullpathPosix(),e=t+(!t||!i.parent?"":"/")+this.name;return u(this,Xt,e)}isUnknown(){return (n(this,M)&xt)===kt}isType(i){return this[`is${i}`]()}getType(){return this.isUnknown()?"Unknown":this.isDirectory()?"Directory":this.isFile()?"File":this.isSymbolicLink()?"SymbolicLink":this.isFIFO()?"FIFO":this.isCharacterDevice()?"CharacterDevice":this.isBlockDevice()?"BlockDevice":this.isSocket()?"Socket":"Unknown"}isFile(){return (n(this,M)&xt)===gn}isDirectory(){return (n(this,M)&xt)===jt}isCharacterDevice(){return (n(this,M)&xt)===fn}isBlockDevice(){return (n(this,M)&xt)===pn}isFIFO(){return (n(this,M)&xt)===un}isSocket(){return (n(this,M)&xt)===mn}isSymbolicLink(){return (n(this,M)&ve)===ve}lstatCached(){return n(this,M)&lr?this:void 0}readlinkCached(){return n(this,ee)}realpathCached(){return n(this,Vt)}readdirCached(){let i=this.children();return i.slice(0,i.provisional)}canReadlink(){if(n(this,ee))return true;if(!this.parent)return false;let i=n(this,M)&xt;return !(i!==kt&&i!==ve||n(this,M)&Yi||n(this,M)&Lt)}calledReaddir(){return !!(n(this,M)&ks)}isENOENT(){return !!(n(this,M)&Lt)}isNamed(i){return this.nocase?n(this,ue)===Zi(i):n(this,ue)===ui(i)}async readlink(){let i=n(this,ee);if(i)return i;if(this.canReadlink()&&this.parent)try{let t=await n(this,lt).promises.readlink(this.fullpath()),e=(await this.parent.realpath())?.resolve(t);if(e)return u(this,ee,e)}catch(t){m(this,R,Bs).call(this,t.code);return}}readlinkSync(){let i=n(this,ee);if(i)return i;if(this.canReadlink()&&this.parent)try{let t=n(this,lt).readlinkSync(this.fullpath()),e=this.parent.realpathSync()?.resolve(t);if(e)return u(this,ee,e)}catch(t){m(this,R,Bs).call(this,t.code);return}}async lstat(){if((n(this,M)&Lt)===0)try{return m(this,R,zs).call(this,await n(this,lt).promises.lstat(this.fullpath())),this}catch(i){m(this,R,Us).call(this,i.code);}}lstatSync(){if((n(this,M)&Lt)===0)try{return m(this,R,zs).call(this,n(this,lt).lstatSync(this.fullpath())),this}catch(i){m(this,R,Us).call(this,i.code);}}readdirCB(i,t=false){if(!this.canReaddir()){t?i(null,[]):queueMicrotask(()=>i(null,[]));return}let e=this.children();if(this.calledReaddir()){let r=e.slice(0,e.provisional);t?i(null,r):queueMicrotask(()=>i(null,r));return}if(n(this,Ke).push(i),n(this,Je))return;u(this,Je,true);let s=this.fullpath();n(this,lt).readdir(s,{withFileTypes:true},(r,o)=>{if(r)m(this,R,rs).call(this,r.code),e.provisional=0;else {for(let a of o)m(this,R,ns).call(this,a,e);m(this,R,ss).call(this,e);}m(this,R,En).call(this,e.slice(0,e.provisional));});}async readdir(){if(!this.canReaddir())return [];let i=this.children();if(this.calledReaddir())return i.slice(0,i.provisional);let t=this.fullpath();if(n(this,De))await n(this,De);else {let e=()=>{};u(this,De,new Promise(s=>e=s));try{for(let s of await n(this,lt).promises.readdir(t,{withFileTypes:!0}))m(this,R,ns).call(this,s,i);m(this,R,ss).call(this,i);}catch(s){m(this,R,rs).call(this,s.code),i.provisional=0;}u(this,De,void 0),e();}return i.slice(0,i.provisional)}readdirSync(){if(!this.canReaddir())return [];let i=this.children();if(this.calledReaddir())return i.slice(0,i.provisional);let t=this.fullpath();try{for(let e of n(this,lt).readdirSync(t,{withFileTypes:!0}))m(this,R,ns).call(this,e,i);m(this,R,ss).call(this,i);}catch(e){m(this,R,rs).call(this,e.code),i.provisional=0;}return i.slice(0,i.provisional)}canReaddir(){if(n(this,M)&cr)return false;let i=xt&n(this,M);return i===kt||i===jt||i===ve}shouldWalk(i,t){return (n(this,M)&jt)===jt&&!(n(this,M)&cr)&&!i.has(this)&&(!t||t(this))}async realpath(){if(n(this,Vt))return n(this,Vt);if(!((is|Yi|Lt)&n(this,M)))try{let i=await n(this,lt).promises.realpath(this.fullpath());return u(this,Vt,this.resolve(i))}catch{m(this,R,Fs).call(this);}}realpathSync(){if(n(this,Vt))return n(this,Vt);if(!((is|Yi|Lt)&n(this,M)))try{let i=n(this,lt).realpathSync(this.fullpath());return u(this,Vt,this.resolve(i))}catch{m(this,R,Fs).call(this);}}[yn](i){if(i===this)return;i.isCWD=false,this.isCWD=true;let t=new Set([]),e=[],s=this;for(;s&&s.parent;)t.add(s),u(s,Qt,e.join(this.sep)),u(s,te,e.join("/")),s=s.parent,e.push("..");for(s=i;s&&s.parent&&!t.has(s);)u(s,Qt,void 0),u(s,te,void 0),s=s.parent;}},lt=new WeakMap,wi=new WeakMap,bi=new WeakMap,Si=new WeakMap,Ei=new WeakMap,vi=new WeakMap,Ti=new WeakMap,xi=new WeakMap,Ci=new WeakMap,ki=new WeakMap,Ri=new WeakMap,Mi=new WeakMap,Oi=new WeakMap,Li=new WeakMap,Di=new WeakMap,Pi=new WeakMap,Ai=new WeakMap,Ii=new WeakMap,Ni=new WeakMap,ue=new WeakMap,Oe=new WeakMap,Gt=new WeakMap,Xt=new WeakMap,Qt=new WeakMap,te=new WeakMap,M=new WeakMap,Le=new WeakMap,ee=new WeakMap,Vt=new WeakMap,R=new WeakSet,Ns=function(i){let t=this;for(let e of i)t=t.child(e);return t},ss=function(i){var t;u(this,M,n(this,M)|ks);for(let e=i.provisional;e<i.length;e++){let s=i[e];s&&m(t=s,R,fi).call(t);}},fi=function(){n(this,M)&Lt||(u(this,M,(n(this,M)|Lt)&ai),m(this,R,_s).call(this));},_s=function(){var t;let i=this.children();i.provisional=0;for(let e of i)m(t=e,R,fi).call(t);},Fs=function(){u(this,M,n(this,M)|is),m(this,R,pi).call(this);},pi=function(){if(n(this,M)&di)return;let i=n(this,M);(i&xt)===jt&&(i&=ai),u(this,M,i|di),m(this,R,_s).call(this);},rs=function(i=""){i==="ENOTDIR"||i==="EPERM"?m(this,R,pi).call(this):i==="ENOENT"?m(this,R,fi).call(this):this.children().provisional=0;},Us=function(i=""){var t;i==="ENOTDIR"?m(t=this.parent,R,pi).call(t):i==="ENOENT"&&m(this,R,fi).call(this);},Bs=function(i=""){var e;let t=n(this,M);t|=Yi,i==="ENOENT"&&(t|=Lt),(i==="EINVAL"||i==="UNKNOWN")&&(t&=ai),u(this,M,t),i==="ENOTDIR"&&this.parent&&m(e=this.parent,R,pi).call(e);},ns=function(i,t){return m(this,R,bn).call(this,i,t)||m(this,R,wn).call(this,i,t)},wn=function(i,t){let e=Rs(i),s=this.newChild(i.name,e,{parent:this}),r=n(s,M)&xt;return r!==jt&&r!==ve&&r!==kt&&u(s,M,n(s,M)|di),t.unshift(s),t.provisional++,s},bn=function(i,t){for(let e=t.provisional;e<t.length;e++){let s=t[e];if((this.nocase?Zi(i.name):ui(i.name))===n(s,ue))return m(this,R,Sn).call(this,i,s,e,t)}},Sn=function(i,t,e,s){let r=t.name;return u(t,M,n(t,M)&ai|Rs(i)),r!==i.name&&(t.name=i.name),e!==s.provisional&&(e===s.length-1?s.pop():s.splice(e,1),s.unshift(t)),s.provisional++,t},zs=function(i){let{atime:t,atimeMs:e,birthtime:s,birthtimeMs:r,blksize:o,blocks:a,ctime:l,ctimeMs:h,dev:d,gid:p,ino:f,mode:g,mtime:y,mtimeMs:S,nlink:b,rdev:x,size:E,uid:k}=i;u(this,Pi,t),u(this,Mi,e),u(this,Ni,s),u(this,Di,r),u(this,xi,o),u(this,Ri,a),u(this,Ii,l),u(this,Li,h),u(this,wi,d),u(this,vi,p),u(this,Ci,f),u(this,bi,g),u(this,Ai,y),u(this,Oi,S),u(this,Si,b),u(this,Ti,x),u(this,ki,E),u(this,Ei,k);let L=Rs(i);u(this,M,n(this,M)&ai|L|lr),L!==kt&&L!==jt&&L!==ve&&u(this,M,n(this,M)|di);},Ke=new WeakMap,Je=new WeakMap,En=function(i){u(this,Je,false);let t=n(this,Ke).slice();n(this,Ke).length=0,t.forEach(e=>e(null,i));},De=new WeakMap,zr),vn=class Tn extends ft{constructor(e,s=kt,r,o,a,l,h){super(e,s,r,o,a,l,h);c(this,"sep","\\");c(this,"splitSep",xa);}newChild(e,s=kt,r={}){return new Tn(e,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}getRootString(e){return win32.parse(e).root}getRoot(e){if(e=Ta(e.toUpperCase()),e===this.root.name)return this.root;for(let[s,r]of Object.entries(this.roots))if(this.sameRoot(e,s))return this.roots[e]=r;return this.roots[e]=new Vs(e,this).root}sameRoot(e,s=this.root.name){return e=e.toUpperCase().replace(/\//g,"\\").replace(dn,"$1\\"),e===s}},xn=class Cn extends ft{constructor(e,s=kt,r,o,a,l,h){super(e,s,r,o,a,l,h);c(this,"splitSep","/");c(this,"sep","/");}getRootString(e){return e.startsWith("/")?"/":""}getRoot(e){return this.root}newChild(e,s=kt,r={}){return new Cn(e,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}},Ye,Ze,_i,Fi,$r,kn=($r=class{constructor(i=process.cwd(),t,e,{nocase:s,childrenCacheSize:r=16*1024,fs:o=ci}={}){c(this,"root");c(this,"rootPath");c(this,"roots");c(this,"cwd");w(this,Ye);w(this,Ze);w(this,_i);c(this,"nocase");w(this,Fi);u(this,Fi,cn(o)),(i instanceof URL||i.startsWith("file://"))&&(i=fileURLToPath(i));let a=t.resolve(i);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),u(this,Ye,new fr),u(this,Ze,new fr),u(this,_i,new ka(r));let l=a.substring(this.rootPath.length).split(e);if(l.length===1&&!l[0]&&l.pop(),s===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=s,this.root=this.newRoot(n(this,Fi)),this.roots[this.rootPath]=this.root;let h=this.root,d=l.length-1,p=t.sep,f=this.rootPath,g=false;for(let y of l){let S=d--;h=h.child(y,{relative:new Array(S).fill("..").join(p),relativePosix:new Array(S).fill("..").join("/"),fullpath:f+=(g?"":p)+y}),g=true;}this.cwd=h;}depth(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.depth()}childrenCache(){return n(this,_i)}resolve(...i){let t="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=n(this,Ye).get(t);if(e!==void 0)return e;let s=this.cwd.resolve(t).fullpath();return n(this,Ye).set(t,s),s}resolvePosix(...i){let t="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=n(this,Ze).get(t);if(e!==void 0)return e;let s=this.cwd.resolve(t).fullpathPosix();return n(this,Ze).set(t,s),s}relative(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.relative()}relativePosix(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.relativePosix()}basename(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.name}dirname(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),(i.parent||i).fullpath()}async readdir(i=this.cwd,t={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e}=t;if(i.canReaddir()){let s=await i.readdir();return e?s:s.map(r=>r.name)}else return []}readdirSync(i=this.cwd,t={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true}=t;return i.canReaddir()?e?i.readdirSync():i.readdirSync().map(s=>s.name):[]}async lstat(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.lstat()}lstatSync(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.lstatSync()}async readlink(i=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i.withFileTypes,i=this.cwd);let e=await i.readlink();return t?e:e?.fullpath()}readlinkSync(i=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i.withFileTypes,i=this.cwd);let e=i.readlinkSync();return t?e:e?.fullpath()}async realpath(i=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i.withFileTypes,i=this.cwd);let e=await i.realpath();return t?e:e?.fullpath()}realpathSync(i=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i.withFileTypes,i=this.cwd);let e=i.realpathSync();return t?e:e?.fullpath()}async walk(i=this.cwd,t={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true,follow:s=false,filter:r,walkFilter:o}=t,a=[];(!r||r(i))&&a.push(e?i:i.fullpath());let l=new Set,h=(p,f)=>{l.add(p),p.readdirCB((g,y)=>{if(g)return f(g);let S=y.length;if(!S)return f();let b=()=>{--S===0&&f();};for(let x of y)(!r||r(x))&&a.push(e?x:x.fullpath()),s&&x.isSymbolicLink()?x.realpath().then(E=>E?.isUnknown()?E.lstat():E).then(E=>E?.shouldWalk(l,o)?h(E,b):b()):x.shouldWalk(l,o)?h(x,b):b();},true);},d=i;return new Promise((p,f)=>{h(d,g=>{if(g)return f(g);p(a);});})}walkSync(i=this.cwd,t={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true,follow:s=false,filter:r,walkFilter:o}=t,a=[];(!r||r(i))&&a.push(e?i:i.fullpath());let l=new Set([i]);for(let h of l){let d=h.readdirSync();for(let p of d){(!r||r(p))&&a.push(e?p:p.fullpath());let f=p;if(p.isSymbolicLink()){if(!(s&&(f=p.realpathSync())))continue;f.isUnknown()&&f.lstatSync();}f.shouldWalk(l,o)&&l.add(f);}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(i=this.cwd,t={}){return typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd),this.stream(i,t)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(i=this.cwd,t={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true,follow:s=false,filter:r,walkFilter:o}=t;(!r||r(i))&&(yield e?i:i.fullpath());let a=new Set([i]);for(let l of a){let h=l.readdirSync();for(let d of h){(!r||r(d))&&(yield e?d:d.fullpath());let p=d;if(d.isSymbolicLink()){if(!(s&&(p=d.realpathSync())))continue;p.isUnknown()&&p.lstatSync();}p.shouldWalk(a,o)&&a.add(p);}}}stream(i=this.cwd,t={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true,follow:s=false,filter:r,walkFilter:o}=t,a=new hs({objectMode:true});(!r||r(i))&&a.write(e?i:i.fullpath());let l=new Set,h=[i],d=0,p=()=>{let f=false;for(;!f;){let g=h.shift();if(!g){d===0&&a.end();return}d++,l.add(g);let y=(b,x,E=false)=>{if(b)return a.emit("error",b);if(s&&!E){let k=[];for(let L of x)L.isSymbolicLink()&&k.push(L.realpath().then(D=>D?.isUnknown()?D.lstat():D));if(k.length){Promise.all(k).then(()=>y(null,x,true));return}}for(let k of x)k&&(!r||r(k))&&(a.write(e?k:k.fullpath())||(f=true));d--;for(let k of x){let L=k.realpathCached()||k;L.shouldWalk(l,o)&&h.push(L);}f&&!a.flowing?a.once("drain",p):S||p();},S=true;g.readdirCB(y,true),S=false;}};return p(),a}streamSync(i=this.cwd,t={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof ft||(t=i,i=this.cwd);let{withFileTypes:e=true,follow:s=false,filter:r,walkFilter:o}=t,a=new hs({objectMode:true}),l=new Set;(!r||r(i))&&a.write(e?i:i.fullpath());let h=[i],d=0,p=()=>{let f=false;for(;!f;){let g=h.shift();if(!g){d===0&&a.end();return}d++,l.add(g);let y=g.readdirSync();for(let S of y)(!r||r(S))&&(a.write(e?S:S.fullpath())||(f=true));d--;for(let S of y){let b=S;if(S.isSymbolicLink()){if(!(s&&(b=S.realpathSync())))continue;b.isUnknown()&&b.lstatSync();}b.shouldWalk(l,o)&&h.push(b);}}f&&!a.flowing&&a.once("drain",p);};return p(),a}chdir(i=this.cwd){let t=this.cwd;this.cwd=typeof i=="string"?this.cwd.resolve(i):i,this.cwd[yn](t);}},Ye=new WeakMap,Ze=new WeakMap,_i=new WeakMap,Fi=new WeakMap,$r),Vs=class extends kn{constructor(t=process.cwd(),e={}){let{nocase:s=true}=e;super(t,win32,"\\",{...e,nocase:s});c(this,"sep","\\");this.nocase=s;for(let r=this.cwd;r;r=r.parent)r.nocase=this.nocase;}parseRootPath(t){return win32.parse(t).root.toUpperCase()}newRoot(t){return new vn(this.rootPath,jt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")||t.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(t)}},qs=class extends kn{constructor(t=process.cwd(),e={}){let{nocase:s=false}=e;super(t,posix,"/",{...e,nocase:s});c(this,"sep","/");this.nocase=s;}parseRootPath(t){return "/"}newRoot(t){return new xn(this.rootPath,jt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")}},Rn=class extends qs{constructor(i=process.cwd(),t={}){let{nocase:e=true}=t;super(i,{...t,nocase:e});}};process.platform==="win32"?vn:xn;var Ra=process.platform==="win32"?Vs:process.platform==="darwin"?Rn:qs,Ma=i=>i.length>=1,Oa=i=>i.length>=1,V,vt,Q,Pe,Bt,Ui,fe,pe,ge,Xe,Qe,Mn=(Qe=class{constructor(t,e,s,r){w(this,V);w(this,vt);w(this,Q);c(this,"length");w(this,Pe);w(this,Bt);w(this,Ui);w(this,fe);w(this,pe);w(this,ge);w(this,Xe,true);if(!Ma(t))throw new TypeError("empty pattern list");if(!Oa(e))throw new TypeError("empty glob list");if(e.length!==t.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=t.length,s<0||s>=this.length)throw new TypeError("index out of range");if(u(this,V,t),u(this,vt,e),u(this,Q,s),u(this,Pe,r),n(this,Q)===0){if(this.isUNC()){let[o,a,l,h,...d]=n(this,V),[p,f,g,y,...S]=n(this,vt);d[0]===""&&(d.shift(),S.shift());let b=[o,a,l,h,""].join("/"),x=[p,f,g,y,""].join("/");u(this,V,[b,...d]),u(this,vt,[x,...S]),this.length=n(this,V).length;}else if(this.isDrive()||this.isAbsolute()){let[o,...a]=n(this,V),[l,...h]=n(this,vt);a[0]===""&&(a.shift(),h.shift());let d=o+"/",p=l+"/";u(this,V,[d,...a]),u(this,vt,[p,...h]),this.length=n(this,V).length;}}}pattern(){return n(this,V)[n(this,Q)]}isString(){return typeof n(this,V)[n(this,Q)]=="string"}isGlobstar(){return n(this,V)[n(this,Q)]===ct}isRegExp(){return n(this,V)[n(this,Q)]instanceof RegExp}globString(){return u(this,Ui,n(this,Ui)||(n(this,Q)===0?this.isAbsolute()?n(this,vt)[0]+n(this,vt).slice(1).join("/"):n(this,vt).join("/"):n(this,vt).slice(n(this,Q)).join("/")))}hasMore(){return this.length>n(this,Q)+1}rest(){return n(this,Bt)!==void 0?n(this,Bt):this.hasMore()?(u(this,Bt,new Qe(n(this,V),n(this,vt),n(this,Q)+1,n(this,Pe))),u(n(this,Bt),ge,n(this,ge)),u(n(this,Bt),pe,n(this,pe)),u(n(this,Bt),fe,n(this,fe)),n(this,Bt)):u(this,Bt,null)}isUNC(){let t=n(this,V);return n(this,pe)!==void 0?n(this,pe):u(this,pe,n(this,Pe)==="win32"&&n(this,Q)===0&&t[0]===""&&t[1]===""&&typeof t[2]=="string"&&!!t[2]&&typeof t[3]=="string"&&!!t[3])}isDrive(){let t=n(this,V);return n(this,fe)!==void 0?n(this,fe):u(this,fe,n(this,Pe)==="win32"&&n(this,Q)===0&&this.length>1&&typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]))}isAbsolute(){let t=n(this,V);return n(this,ge)!==void 0?n(this,ge):u(this,ge,t[0]===""&&t.length>1||this.isDrive()||this.isUNC())}root(){let t=n(this,V)[0];return typeof t=="string"&&this.isAbsolute()&&n(this,Q)===0?t:""}checkFollowGlobstar(){return !(n(this,Q)===0||!this.isGlobstar()||!n(this,Xe))}markFollowGlobstar(){return n(this,Q)===0||!this.isGlobstar()||!n(this,Xe)?false:(u(this,Xe,false),true)}},V=new WeakMap,vt=new WeakMap,Q=new WeakMap,Pe=new WeakMap,Bt=new WeakMap,Ui=new WeakMap,fe=new WeakMap,pe=new WeakMap,ge=new WeakMap,Xe=new WeakMap,Qe),La=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",pr=class{constructor(i,{nobrace:t,nocase:e,noext:s,noglobstar:r,platform:o=La}){c(this,"relative");c(this,"relativeChildren");c(this,"absolute");c(this,"absoluteChildren");c(this,"platform");c(this,"mmopts");this.relative=[],this.absolute=[],this.relativeChildren=[],this.absoluteChildren=[],this.platform=o,this.mmopts={dot:true,nobrace:t,nocase:e,noext:s,noglobstar:r,optimizationLevel:2,platform:o,nocomment:true,nonegate:true};for(let a of i)this.add(a);}add(i){let t=new ye(i,this.mmopts);for(let e=0;e<t.set.length;e++){let s=t.set[e],r=t.globParts[e];if(!s||!r)throw new Error("invalid pattern object");for(;s[0]==="."&&r[0]===".";)s.shift(),r.shift();let o=new Mn(s,r,0,this.platform),a=new ye(o.globString(),this.mmopts),l=r[r.length-1]==="**",h=o.isAbsolute();h?this.absolute.push(a):this.relative.push(a),l&&(h?this.absoluteChildren.push(a):this.relativeChildren.push(a));}}ignored(i){let t=i.fullpath(),e=`${t}/`,s=i.relative()||".",r=`${s}/`;for(let o of this.relative)if(o.match(s)||o.match(r))return true;for(let o of this.absolute)if(o.match(t)||o.match(e))return true;return false}childrenIgnored(i){let t=i.fullpath()+"/",e=(i.relative()||".")+"/";for(let s of this.relativeChildren)if(s.match(e))return true;for(let s of this.absoluteChildren)if(s.match(t))return true;return false}},Da=class On{constructor(t=new Map){c(this,"store");this.store=t;}copy(){return new On(new Map(this.store))}hasWalked(t,e){return this.store.get(t.fullpath())?.has(e.globString())}storeWalked(t,e){let s=t.fullpath(),r=this.store.get(s);r?r.add(e.globString()):this.store.set(s,new Set([e.globString()]));}},Pa=class{constructor(){c(this,"store",new Map);}add(i,t,e){let s=(t?2:0)|(e?1:0),r=this.store.get(i);this.store.set(i,r===void 0?s:s&r);}entries(){return [...this.store.entries()].map(([i,t])=>[i,!!(t&2),!!(t&1)])}},Aa=class{constructor(){c(this,"store",new Map);}add(i,t){if(!i.canReaddir())return;let e=this.store.get(i);e?e.find(s=>s.globString()===t.globString())||e.push(t):this.store.set(i,[t]);}get(i){let t=this.store.get(i);if(!t)throw new Error("attempting to walk unknown path");return t}entries(){return this.keys().map(i=>[i,this.store.get(i)])}keys(){return [...this.store.keys()].filter(i=>i.canReaddir())}},gr=class Ln{constructor(t,e){c(this,"hasWalkedCache");c(this,"matches",new Pa);c(this,"subwalks",new Aa);c(this,"patterns");c(this,"follow");c(this,"dot");c(this,"opts");this.opts=t,this.follow=!!t.follow,this.dot=!!t.dot,this.hasWalkedCache=e?e.copy():new Da;}processPatterns(t,e){this.patterns=e;let s=e.map(r=>[t,r]);for(let[r,o]of s){this.hasWalkedCache.storeWalked(r,o);let a=o.root(),l=o.isAbsolute()&&this.opts.absolute!==false;if(a){r=r.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let f=o.rest();if(f)o=f;else {this.matches.add(r,true,false);continue}}if(r.isENOENT())continue;let h,d,p=false;for(;typeof(h=o.pattern())=="string"&&(d=o.rest());)r=r.resolve(h),o=d,p=true;if(h=o.pattern(),d=o.rest(),p){if(this.hasWalkedCache.hasWalked(r,o))continue;this.hasWalkedCache.storeWalked(r,o);}if(typeof h=="string"){let f=h===".."||h===""||h===".";this.matches.add(r.resolve(h),l,f);continue}else if(h===ct){(!r.isSymbolicLink()||this.follow||o.checkFollowGlobstar())&&this.subwalks.add(r,o);let f=d?.pattern(),g=d?.rest();if(!d||(f===""||f===".")&&!g)this.matches.add(r,l,f===""||f===".");else if(f===".."){let y=r.parent||r;g?this.hasWalkedCache.hasWalked(y,g)||this.subwalks.add(y,g):this.matches.add(y,l,true);}}else h instanceof RegExp&&this.subwalks.add(r,o);}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new Ln(this.opts,this.hasWalkedCache)}filterEntries(t,e){let s=this.subwalks.get(t),r=this.child();for(let o of e)for(let a of s){let l=a.isAbsolute(),h=a.pattern(),d=a.rest();h===ct?r.testGlobstar(o,a,d,l):h instanceof RegExp?r.testRegExp(o,h,d,l):r.testString(o,h,d,l);}return r}testGlobstar(t,e,s,r){if((this.dot||!t.name.startsWith("."))&&(e.hasMore()||this.matches.add(t,r,false),t.canReaddir()&&(this.follow||!t.isSymbolicLink()?this.subwalks.add(t,e):t.isSymbolicLink()&&(s&&e.checkFollowGlobstar()?this.subwalks.add(t,s):e.markFollowGlobstar()&&this.subwalks.add(t,e)))),s){let o=s.pattern();if(typeof o=="string"&&o!==".."&&o!==""&&o!==".")this.testString(t,o,s.rest(),r);else if(o===".."){let a=t.parent||t;this.subwalks.add(a,s);}else o instanceof RegExp&&this.testRegExp(t,o,s.rest(),r);}}testRegExp(t,e,s,r){e.test(t.name)&&(s?this.subwalks.add(t,s):this.matches.add(t,r,false));}testString(t,e,s,r){t.isNamed(e)&&(s?this.subwalks.add(t,s):this.matches.add(t,r,false));}},Ia=(i,t)=>typeof i=="string"?new pr([i],t):Array.isArray(i)?new pr(i,t):i,ti,ie,Ae,Rt,Te,$s,jr,Dn=(jr=class{constructor(i,t,e){w(this,Rt);c(this,"path");c(this,"patterns");c(this,"opts");c(this,"seen",new Set);c(this,"paused",false);c(this,"aborted",false);w(this,ti,[]);w(this,ie);w(this,Ae);c(this,"signal");c(this,"maxDepth");c(this,"includeChildMatches");if(this.patterns=i,this.path=t,this.opts=e,u(this,Ae,!e.posix&&e.platform==="win32"?"\\":"/"),this.includeChildMatches=e.includeChildMatches!==false,(e.ignore||!this.includeChildMatches)&&(u(this,ie,Ia(e.ignore??[],e)),!this.includeChildMatches&&typeof n(this,ie).add!="function")){let s="cannot ignore child matches, ignore lacks add() method.";throw new Error(s)}this.maxDepth=e.maxDepth||1/0,e.signal&&(this.signal=e.signal,this.signal.addEventListener("abort",()=>{n(this,ti).length=0;}));}pause(){this.paused=true;}resume(){if(this.signal?.aborted)return;this.paused=false;let i;for(;!this.paused&&(i=n(this,ti).shift());)i();}onResume(i){this.signal?.aborted||(this.paused?n(this,ti).push(i):i());}async matchCheck(i,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=i.realpathCached()||await i.realpath(),!e)return;i=e;}let s=i.isUnknown()||this.opts.stat?await i.lstat():i;if(this.opts.follow&&this.opts.nodir&&s?.isSymbolicLink()){let r=await s.realpath();r&&(r.isUnknown()||this.opts.stat)&&await r.lstat();}return this.matchCheckTest(s,t)}matchCheckTest(i,t){return i&&(this.maxDepth===1/0||i.depth()<=this.maxDepth)&&(!t||i.canReaddir())&&(!this.opts.nodir||!i.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!i.isSymbolicLink()||!i.realpathCached()?.isDirectory())&&!m(this,Rt,Te).call(this,i)?i:void 0}matchCheckSync(i,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=i.realpathCached()||i.realpathSync(),!e)return;i=e;}let s=i.isUnknown()||this.opts.stat?i.lstatSync():i;if(this.opts.follow&&this.opts.nodir&&s?.isSymbolicLink()){let r=s.realpathSync();r&&(r?.isUnknown()||this.opts.stat)&&r.lstatSync();}return this.matchCheckTest(s,t)}matchFinish(i,t){if(m(this,Rt,Te).call(this,i))return;if(!this.includeChildMatches&&n(this,ie)?.add){let r=`${i.relativePosix()}/**`;n(this,ie).add(r);}let e=this.opts.absolute===void 0?t:this.opts.absolute;this.seen.add(i);let s=this.opts.mark&&i.isDirectory()?n(this,Ae):"";if(this.opts.withFileTypes)this.matchEmit(i);else if(e){let r=this.opts.posix?i.fullpathPosix():i.fullpath();this.matchEmit(r+s);}else {let r=this.opts.posix?i.relativePosix():i.relative(),o=this.opts.dotRelative&&!r.startsWith(".."+n(this,Ae))?"."+n(this,Ae):"";this.matchEmit(r?o+r+s:"."+s);}}async match(i,t,e){let s=await this.matchCheck(i,e);s&&this.matchFinish(s,t);}matchSync(i,t,e){let s=this.matchCheckSync(i,e);s&&this.matchFinish(s,t);}walkCB(i,t,e){this.signal?.aborted&&e(),this.walkCB2(i,t,new gr(this.opts),e);}walkCB2(i,t,e,s){if(m(this,Rt,$s).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2(i,t,e,s));return}e.processPatterns(i,t);let r=1,o=()=>{--r===0&&s();};for(let[a,l,h]of e.matches.entries())m(this,Rt,Te).call(this,a)||(r++,this.match(a,l,h).then(()=>o()));for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let l=a.readdirCached();a.calledReaddir()?this.walkCB3(a,l,e,o):a.readdirCB((h,d)=>this.walkCB3(a,d,e,o),true);}o();}walkCB3(i,t,e,s){e=e.filterEntries(i,t);let r=1,o=()=>{--r===0&&s();};for(let[a,l,h]of e.matches.entries())m(this,Rt,Te).call(this,a)||(r++,this.match(a,l,h).then(()=>o()));for(let[a,l]of e.subwalks.entries())r++,this.walkCB2(a,l,e.child(),o);o();}walkCBSync(i,t,e){this.signal?.aborted&&e(),this.walkCB2Sync(i,t,new gr(this.opts),e);}walkCB2Sync(i,t,e,s){if(m(this,Rt,$s).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2Sync(i,t,e,s));return}e.processPatterns(i,t);let r=1,o=()=>{--r===0&&s();};for(let[a,l,h]of e.matches.entries())m(this,Rt,Te).call(this,a)||this.matchSync(a,l,h);for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let l=a.readdirSync();this.walkCB3Sync(a,l,e,o);}o();}walkCB3Sync(i,t,e,s){e=e.filterEntries(i,t);let r=1,o=()=>{--r===0&&s();};for(let[a,l,h]of e.matches.entries())m(this,Rt,Te).call(this,a)||this.matchSync(a,l,h);for(let[a,l]of e.subwalks.entries())r++,this.walkCB2Sync(a,l,e.child(),o);o();}},ti=new WeakMap,ie=new WeakMap,Ae=new WeakMap,Rt=new WeakSet,Te=function(i){return this.seen.has(i)||!!n(this,ie)?.ignored?.(i)},$s=function(i){return !!n(this,ie)?.childrenIgnored?.(i)},jr),mr=class extends Dn{constructor(t,e,s){super(t,e,s);c(this,"matches",new Set);}matchEmit(t){this.matches.add(t);}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((t,e)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?e(this.signal.reason):t(this.matches);});}),this.matches}walkSync(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>{if(this.signal?.aborted)throw this.signal.reason}),this.matches}},yr=class extends Dn{constructor(t,e,s){super(t,e,s);c(this,"results");this.results=new hs({signal:this.signal,objectMode:true}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume());}matchEmit(t){this.results.write(t),this.results.flowing||this.pause();}stream(){let t=this.path;return t.isUnknown()?t.lstat().then(()=>{this.walkCB(t,this.patterns,()=>this.results.end());}):this.walkCB(t,this.patterns,()=>this.results.end()),this.results}streamSync(){return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>this.results.end()),this.results}},Na=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",Ne=class{constructor(i,t){c(this,"absolute");c(this,"cwd");c(this,"root");c(this,"dot");c(this,"dotRelative");c(this,"follow");c(this,"ignore");c(this,"magicalBraces");c(this,"mark");c(this,"matchBase");c(this,"maxDepth");c(this,"nobrace");c(this,"nocase");c(this,"nodir");c(this,"noext");c(this,"noglobstar");c(this,"pattern");c(this,"platform");c(this,"realpath");c(this,"scurry");c(this,"stat");c(this,"signal");c(this,"windowsPathsNoEscape");c(this,"withFileTypes");c(this,"includeChildMatches");c(this,"opts");c(this,"patterns");if(!t)throw new TypeError("glob options required");if(this.withFileTypes=!!t.withFileTypes,this.signal=t.signal,this.follow=!!t.follow,this.dot=!!t.dot,this.dotRelative=!!t.dotRelative,this.nodir=!!t.nodir,this.mark=!!t.mark,t.cwd?(t.cwd instanceof URL||t.cwd.startsWith("file://"))&&(t.cwd=fileURLToPath(t.cwd)):this.cwd="",this.cwd=t.cwd||"",this.root=t.root,this.magicalBraces=!!t.magicalBraces,this.nobrace=!!t.nobrace,this.noext=!!t.noext,this.realpath=!!t.realpath,this.absolute=t.absolute,this.includeChildMatches=t.includeChildMatches!==false,this.noglobstar=!!t.noglobstar,this.matchBase=!!t.matchBase,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:1/0,this.stat=!!t.stat,this.ignore=t.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");if(typeof i=="string"&&(i=[i]),this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===false,this.windowsPathsNoEscape&&(i=i.map(l=>l.replace(/\\/g,"/"))),this.matchBase){if(t.noglobstar)throw new TypeError("base matching requires globstar");i=i.map(l=>l.includes("/")?l:`./**/${l}`);}if(this.pattern=i,this.platform=t.platform||Na,this.opts={...t,platform:this.platform},t.scurry){if(this.scurry=t.scurry,t.nocase!==void 0&&t.nocase!==t.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else {let l=t.platform==="win32"?Vs:t.platform==="darwin"?Rn:t.platform?qs:Ra;this.scurry=new l(this.cwd,{nocase:t.nocase,fs:t.fs});}this.nocase=this.scurry.nocase;let e=this.platform==="darwin"||this.platform==="win32",s={...t,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:e,nocomment:true,noext:this.noext,nonegate:true,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape,debug:!!this.opts.debug},r=this.pattern.map(l=>new ye(l,s)),[o,a]=r.reduce((l,h)=>(l[0].push(...h.set),l[1].push(...h.globParts),l),[[],[]]);this.patterns=o.map((l,h)=>{let d=a[h];if(!d)throw new Error("invalid pattern object");return new Mn(l,d,0,this.platform)});}async walk(){return [...await new mr(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).walk()]}walkSync(){return [...new mr(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).walkSync()]}stream(){return new yr(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).stream()}streamSync(){return new yr(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).streamSync()}iterateSync(){return this.streamSync()[Symbol.iterator]()}[Symbol.iterator](){return this.iterateSync()}iterate(){return this.stream()[Symbol.asyncIterator]()}[Symbol.asyncIterator](){return this.iterate()}},_a=(i,t={})=>{Array.isArray(i)||(i=[i]);for(let e of i)if(new ye(e,t).hasMagic())return true;return false};function ds(i,t={}){return new Ne(i,t).streamSync()}function Pn(i,t={}){return new Ne(i,t).stream()}function An(i,t={}){return new Ne(i,t).walkSync()}async function wr(i,t={}){return new Ne(i,t).walk()}function us(i,t={}){return new Ne(i,t).iterateSync()}function In(i,t={}){return new Ne(i,t).iterate()}var Fa=ds,Ua=Object.assign(Pn,{sync:ds}),Ba=us,za=Object.assign(In,{sync:us}),$a=Object.assign(An,{stream:ds,iterate:us}),ls=Object.assign(wr,{glob:wr,globSync:An,sync:$a,globStream:Pn,stream:Ua,globStreamSync:ds,streamSync:Fa,globIterate:In,iterate:za,globIterateSync:us,iterateSync:Ba,Glob:Ne,hasMagic:_a,escape:Xr,unescape:$e});ls.glob=ls;var we;(D=>{D.Level=Wa.enum(["DEBUG","INFO","WARN","ERROR"]).meta({ref:"LogLevel",description:"Log level"});let t={DEBUG:0,INFO:1,WARN:2,ERROR:3},e="INFO";function s(C){return t[C]>=t[e]}function r(){return e}D.getLevel=r;let o=new Map;D.Default=L({service:"default"});let l="";function h(){return l}D.file=h;let d,p,f=false,g=()=>{},y=false;async function S(C){if(C.level&&(e=C.level),C.print){f=true;return}if(C.logPath)l=C.logPath;else {g=()=>{},f=true;return}try{d=await Nn.open(l,"a"),p=createWriteStream("",{fd:d.fd,autoClose:!1}),g=P=>{if(!(y||!p||p.destroyed))try{if(!p.writable)return;p.write(P,U=>{U&&!y&&(y=!0,setTimeout(()=>{y=!1;},1e3));});}catch{y||(y=!0,setTimeout(()=>{y=!1;},1e3));}},f=!0;}catch{g=P=>{try{process.stderr.write(P);}catch{}},f=true;}}D.init=S;async function b(){f&&(p&&!p.destroyed&&(await new Promise((C,P)=>{p.end(U=>{U?P(U):C();});}).catch(()=>{}),p=void 0),d&&(await d.close().catch(()=>{}),d=void 0),g=C=>{try{process.stderr.write(C);}catch{}},f=false);}D.close=b;function E(C,P=0){let U=C.message;return C.cause instanceof Error&&P<10?U+" Caused by: "+E(C.cause,P+1):U}let k=Date.now();function L(C){C=C||{};let P=C.service;if(P&&typeof P=="string"){let _=o.get(P);if(_)return _}function U(_,q){let ys=Object.entries({...C,...q}).filter(([Ks,se])=>se!=null).map(([Ks,se])=>{let ws=`${Ks}=`;return se instanceof Error?ws+E(se):typeof se=="object"?ws+JSON.stringify(se):ws+se}).join(" "),Mt=new Date,jn=Mt.getTime()-k;return k=Mt.getTime(),[Mt.getFullYear()+"-"+String(Mt.getMonth()+1).padStart(2,"0")+"-"+String(Mt.getDate()).padStart(2,"0")+"T"+String(Mt.getHours()).padStart(2,"0")+":"+String(Mt.getMinutes()).padStart(2,"0")+":"+String(Mt.getSeconds()).padStart(2,"0"),"+"+jn+"ms",ys,_].filter(Boolean).join(" ")+`
|
|
4
|
+
`}let ut={debug(_,q){s("DEBUG")&&g("DEBUG "+U(_,q));},info(_,q){s("INFO")&&g("INFO "+U(_,q));},error(_,q){s("ERROR")&&g("ERROR "+U(_,q));},warn(_,q){s("WARN")&&g("WARN "+U(_,q));},tag(_,q){return C&&(C[_]=q),ut},clone(){return D.create({...C})},time(_,q){let ys=Date.now();ut.info(_,{status:"started",...q});function Mt(){ut.info(_,{status:"completed",duration:Date.now()-ys,...q});}return {stop:Mt,[Symbol.dispose](){Mt();}}}};return P&&typeof P=="string"&&o.set(P,ut),ut}D.create=L;})(we||(we={}));var F=we.create({service:"transformers-engine"}),Ga=ei.join(Ys.homedir(),".cache","easbot","models");process.env.HF_HOME||(process.env.HF_HOME=Ga);env.allowLocalModels=true;env.allowRemoteModels=true;env.useBrowserCache=false;env.useFSCache=true;var fs=class{constructor(t){c(this,"pipeline",null);c(this,"tokenizer",null);c(this,"isInitialized",false);c(this,"config");c(this,"modelCache");this.config=t,this.modelCache=new Ue({cacheDir:t.cacheDir}),this.configureEnvironment();}configureEnvironment(){this.modelCache.ensureCacheDir(),process.env.HF_HOME||(process.env.HF_HOME=this.config.cacheDir),env.cacheDir=this.config.cacheDir,env.allowLocalModels=true,env.allowRemoteModels=true,env.useBrowserCache=false,env.useFSCache=true,env.backends?.onnx&&(env.backends.onnx.logLevel="error"),this.config.verbose&&F.debug("\u73AF\u5883\u914D\u7F6E\u5B8C\u6210",{cacheDir:this.config.cacheDir,hfHome:process.env.HF_HOME,modelId:this.config.modelId,modelType:this.config.modelType});}async initialize(){if(this.isInitialized){this.config.verbose&&F.debug("\u6A21\u578B\u5DF2\u521D\u59CB\u5316\uFF0C\u8DF3\u8FC7\u91CD\u590D\u52A0\u8F7D");return}try{this.config.verbose&&F.debug("\u5F00\u59CB\u521D\u59CB\u5316\u6A21\u578B");let t,e;if(this.config.modelType==="language"){let o=Ht[this.config.modelId];if(!o)throw new T(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");t=o.huggingFaceId,e=o.dtype;}else {let o=Se[this.config.modelId];if(!o)throw new T(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");t=o.huggingFaceId,e=o.dtype;}this.config.verbose&&(F.debug("\u52A0\u8F7D\u6A21\u578B",{huggingFaceId:t,dtype:e||"auto"}),this.modelCache.isCached(t)?F.debug("\u4F7F\u7528\u7F13\u5B58\u7684\u6A21\u578B"):F.debug("\u9996\u6B21\u4E0B\u8F7D\u6A21\u578B\uFF0C\u53EF\u80FD\u9700\u8981\u4E00\u4E9B\u65F6\u95F4"));let s={cache_dir:this.config.cacheDir,local_files_only:!0};if(e&&(s.dtype=e),this.modelCache.isCached(t))this.config.verbose&&F.debug("\u4F7F\u7528\u672C\u5730\u7F13\u5B58\u6A21\u578B");else throw this.config.verbose&&F.warn("\u672C\u5730\u7F13\u5B58\u4E0D\u5B58\u5728",{huggingFaceId:t,cacheDir:this.config.cacheDir}),new T(`\u6A21\u578B ${t} \u672A\u627E\u5230\u672C\u5730\u7F13\u5B58\u3002\u8BF7\u5148\u4E0B\u8F7D\u6A21\u578B\u5230: ${this.config.cacheDir}`,"MODEL_NOT_FOUND");this.config.modelType==="language"?this.pipeline=await pipeline("text-generation",t,s):this.pipeline=await pipeline("feature-extraction",t,s),this.tokenizer=this.pipeline.tokenizer,this.isInitialized=!0,this.config.verbose&&F.debug("\u6A21\u578B\u521D\u59CB\u5316\u6210\u529F",{modelId:this.config.modelId});}catch(t){throw this.config.verbose&&F.error("\u6A21\u578B\u521D\u59CB\u5316\u5931\u8D25",{error:t}),nt.modelLoadError(t instanceof Error?t:new Error(String(t)))}}extractAssistantResponse(t,e){let s=`<|im_start|>assistant
|
|
5
|
+
`,r=t.lastIndexOf(s);if(r!==-1){let p=t.slice(r+s.length);return p=p.replace(/<\|im_end\|>$/g,""),p.trim()}let o=`
|
|
6
|
+
assistant
|
|
7
|
+
`,a=t.lastIndexOf(o);if(a!==-1)return t.slice(a+o.length).trim();let l=`assistant
|
|
8
|
+
`,h=t.lastIndexOf(l);return h!==-1?t.slice(h+l.length).trim():(t.startsWith(e)?t.slice(e.length):t).trim()}async generate(t,e){if(!this.isInitialized)throw new T("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");if(this.config.modelType!=="language")throw new T("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u6587\u672C\u751F\u6210","UNSUPPORTED_FEATURE");if(e.abortSignal?.aborted)throw nt.abortError();try{this.config.verbose&&F.debug("\u5F00\u59CB\u751F\u6210\u6587\u672C");let s=await this.countTokens([t]),r=await this.pipeline(t,{max_new_tokens:e.maxTokens,temperature:e.temperature,top_p:e.topP,top_k:e.topK,repetition_penalty:e.repetitionPenalty,do_sample:e.temperature>0});if(e.abortSignal?.aborted)throw nt.abortError();let o=r[0]?.generated_text||"",a=this.extractAssistantResponse(o,t),l=await this.countTokens([a]);return this.config.verbose&&F.debug("\u751F\u6210\u5B8C\u6210",{completionTokens:l}),{text:a,finishReason:"stop",usage:{promptTokens:s,completionTokens:l,totalTokens:s+l}}}catch(s){throw this.config.verbose&&F.error("\u751F\u6210\u5931\u8D25",{error:s}),s instanceof T&&s.code==="ABORTED"?s:nt.generationError(s instanceof Error?s:new Error(String(s)))}}async generateStream(t,e,s){if(!this.isInitialized)throw new T("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");if(this.config.modelType!=="language")throw new T("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u6587\u672C\u751F\u6210","UNSUPPORTED_FEATURE");if(e.abortSignal?.aborted)throw nt.abortError();try{this.config.verbose&&F.debug("\u5F00\u59CB\u6D41\u5F0F\u751F\u6210\u6587\u672C\uFF08\u6A21\u62DF\u6D41\u5F0F\u8F93\u51FA\uFF09");let r=await this.pipeline(t,{max_new_tokens:e.maxTokens,temperature:e.temperature,top_p:e.topP,top_k:e.topK,repetition_penalty:e.repetitionPenalty,do_sample:e.temperature>0});if(e.abortSignal?.aborted)throw nt.abortError();let o=r[0]?.generated_text||"",a=this.extractAssistantResponse(o,t),l=a.split(/(\s+)/);for(let p of l){if(e.abortSignal?.aborted)throw nt.abortError();p.length>0&&s({type:"text-delta",textDelta:p});}s({type:"text-end"});let h=await this.countTokens([t]),d=await this.countTokens([a]);s({type:"finish",finishReason:"stop",usage:{promptTokens:h,completionTokens:d,totalTokens:h+d}}),this.config.verbose&&F.debug("\u6D41\u5F0F\u751F\u6210\u5B8C\u6210",{promptTokens:h,completionTokens:d,totalTokens:h+d});}catch(r){throw this.config.verbose&&F.error("\u6D41\u5F0F\u751F\u6210\u5931\u8D25",{error:r}),r instanceof T&&r.code==="ABORTED"?r:(s({type:"finish",finishReason:"error"}),nt.generationError(r instanceof Error?r:new Error(String(r))))}}async embed(t,e){if(!this.isInitialized)throw new T("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");if(this.config.modelType!=="embedding")throw new T("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u5D4C\u5165\u63A8\u7406","UNSUPPORTED_FEATURE");if(e?.aborted)throw nt.abortError();try{this.config.verbose&&F.debug("\u5F00\u59CB\u63A8\u7406",{textCount:t.length});let s=await this.pipeline(t,{pooling:"mean",normalize:!0});if(e?.aborted)throw nt.abortError();let r=[];if(s.dims&&s.dims.length===2){let[o,a]=s.dims,l=Array.from(s.data);for(let h=0;h<o;h++){let d=h*a,p=d+a;r.push(l.slice(d,p));}}else r.push(Array.from(s.data));return this.config.verbose&&F.debug("\u63A8\u7406\u5B8C\u6210",{embeddingCount:r.length}),r}catch(s){throw this.config.verbose&&F.error("\u63A8\u7406\u5931\u8D25",{error:s}),s instanceof T&&s.code==="ABORTED"?s:nt.embeddingError(s instanceof Error?s:new Error(String(s)))}}async countTokens(t){if(!this.isInitialized)throw new T("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");try{let e=0;for(let s of t){let r=await this.tokenizer(s);e+=r.input_ids.data.length;}return e}catch(e){return this.config.verbose&&F.error("\u8BA1\u7B97 token \u5931\u8D25",{error:e}),t.reduce((s,r)=>s+Math.ceil(r.length/4),0)}}async dispose(){this.config.verbose&&F.debug("\u5378\u8F7D\u6A21\u578B"),this.pipeline=null,this.tokenizer=null,this.isInitialized=false,this.config.verbose&&F.debug("\u6A21\u578B\u5DF2\u5378\u8F7D");}isReady(){return this.isInitialized}};var pt=class{static validateTexts(t){if(!Array.isArray(t))throw new T("\u8F93\u5165\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4","INVALID_INPUT");if(t.length===0)throw new T("\u8F93\u5165\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let e=0;e<t.length;e++){let s=t[e];if(typeof s!="string")throw new T(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${e} \u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B`,"INVALID_INPUT");if(s.trim().length===0)throw new T(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${e} \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}static validateMessages(t){if(!Array.isArray(t))throw new T("\u6D88\u606F\u5FC5\u987B\u662F\u6570\u7EC4","INVALID_INPUT");if(t.length===0)throw new T("\u6D88\u606F\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let e=0;e<t.length;e++){let s=t[e];if(!s||typeof s!="object")throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!s.role)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7F3A\u5C11 role \u5B57\u6BB5`,"INVALID_INPUT");if(!["system","user","assistant"].includes(s.role))throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 role "${s.role}" \u4E0D\u652F\u6301\uFF0C\u53EA\u652F\u6301 system\u3001user\u3001assistant`,"UNSUPPORTED_FEATURE");if(!s.content)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7F3A\u5C11 content \u5B57\u6BB5`,"INVALID_INPUT");if(typeof s.content=="string"){if(s.content.trim().length===0)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}else if(Array.isArray(s.content)){if(s.content.length===0)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content \u6570\u7EC4\u4E3A\u7A7A`,"INVALID_INPUT");for(let r=0;r<s.content.length;r++){let o=s.content[r];if(!o||typeof o!="object")throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content part ${r} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!o.type)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content part ${r} \u7F3A\u5C11 type \u5B57\u6BB5`,"INVALID_INPUT");if(o.type!=="text"&&o.type!=="reasoning")throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content part ${r} \u7C7B\u578B "${o.type}" \u4E0D\u652F\u6301\uFF0C\u53EA\u652F\u6301 text \u548C reasoning`,"UNSUPPORTED_FEATURE");if(!("text"in o)||typeof o.text!="string")throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content part ${r} \u7F3A\u5C11\u6709\u6548\u7684 text \u5B57\u6BB5`,"INVALID_INPUT");if(o.text.trim().length===0)throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content part ${r} \u7684 text \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}else throw new T(`\u6D88\u606F\u7D22\u5F15 ${e} \u7684 content \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6216\u6570\u7EC4`,"INVALID_INPUT")}}static validateGenerateOptions(t){if(t.temperature!==void 0&&(typeof t.temperature!="number"||t.temperature<0||t.temperature>2))throw new T("temperature \u5FC5\u987B\u662F 0 \u5230 2 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(t.topP!==void 0&&(typeof t.topP!="number"||t.topP<0||t.topP>1))throw new T("topP \u5FC5\u987B\u662F 0 \u5230 1 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(t.topK!==void 0&&(typeof t.topK!="number"||t.topK<1||!Number.isInteger(t.topK)))throw new T("topK \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(t.maxTokens!==void 0&&(typeof t.maxTokens!="number"||t.maxTokens<1||!Number.isInteger(t.maxTokens)))throw new T("maxTokens \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(t.repetitionPenalty!==void 0&&(typeof t.repetitionPenalty!="number"||t.repetitionPenalty<0))throw new T("repetitionPenalty \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 0 \u7684\u6570\u5B57","INVALID_INPUT")}};var ps=class{static createReadableStream(t,e){return new ReadableStream({async start(s){if(e?.aborted){s.error(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));return}let r=false,o=()=>{r=true,s.error(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));};e?.addEventListener("abort",o);try{if(await t(a=>{if(!r)try{s.enqueue(a),a.isFinished&&(s.close(),e?.removeEventListener("abort",o));}catch(l){s.error(l),e?.removeEventListener("abort",o);}}),!r)try{s.enqueue({textDelta:"",isFinished:!0,finishReason:"stop"}),s.close();}catch{}}catch(a){r||s.error(a instanceof T?a:new T(`\u751F\u6210\u5931\u8D25: ${a instanceof Error?a.message:String(a)}`,"GENERATION_ERROR",a instanceof Error?a:void 0));}finally{e?.removeEventListener("abort",o);}},cancel(){}})}static async*streamToAsyncIterator(t){let e=t.getReader();try{for(;;){let{done:s,value:r}=await e.read();if(s)break;yield r;}}finally{e.releaseLock();}}};function Va(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Bi=class{constructor(t,e,s){c(this,"specificationVersion","v2");c(this,"provider");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"engine");c(this,"modelConfig");if(this.provider=t,this.modelId=e,this.engine=s,this.modelConfig=Ht[e],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${e}`,"MODEL_NOT_FOUND")}convertToQwenFormat(t){let e=[];for(let s of t){let r="";switch(typeof s.content=="string"?r=s.content:Array.isArray(s.content)&&(r=s.content.filter(o=>o.type==="text").map(o=>"text"in o?o.text:"").join(`
|
|
9
|
+
`)),s.role){case "system":e.push(`<|im_start|>system
|
|
10
|
+
${r}<|im_end|>`);break;case "user":e.push(`<|im_start|>user
|
|
11
|
+
${r}<|im_end|>`);break;case "assistant":e.push(`<|im_start|>assistant
|
|
12
|
+
${r}<|im_end|>`);break;default:throw new T(`\u4E0D\u652F\u6301\u7684\u6D88\u606F\u89D2\u8272: ${s.role}`,"UNSUPPORTED_FEATURE")}}return e.push(`<|im_start|>assistant
|
|
13
|
+
`),e.join(`
|
|
14
|
+
`)}async doGenerate(t){pt.validateMessages(t.prompt);let e=this.convertToQwenFormat(t.prompt),s={temperature:t.temperature??this.modelConfig.defaultSettings.temperature,topP:t.topP??this.modelConfig.defaultSettings.topP,topK:t.topK??this.modelConfig.defaultSettings.topK,maxTokens:t.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:t.abortSignal};pt.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=await this.engine.generate(e,s);return {content:[{type:"text",text:r.text}],finishReason:r.finishReason,usage:{inputTokens:r.usage.promptTokens,outputTokens:r.usage.completionTokens,totalTokens:r.usage.totalTokens},warnings:[],rawCall:{rawPrompt:e,rawSettings:s}}}async doStream(t){pt.validateMessages(t.prompt);let e=this.convertToQwenFormat(t.prompt),s={temperature:t.temperature??this.modelConfig.defaultSettings.temperature,topP:t.topP??this.modelConfig.defaultSettings.topP,topK:t.topK??this.modelConfig.defaultSettings.topK,maxTokens:t.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:t.abortSignal};pt.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=ps.createReadableStream(async l=>{await this.engine.generateStream(e,s,h=>{h.type==="text-delta"?l({textDelta:h.textDelta||"",isFinished:false}):h.type==="finish"&&l({textDelta:"",isFinished:true,finishReason:h.finishReason});});},t.abortSignal),o=null;return {stream:r.pipeThrough(new TransformStream({transform(l,h){l.isFinished?(o&&(h.enqueue({type:"text-end",id:o}),o=null),h.enqueue({type:"finish",finishReason:l.finishReason||"stop",usage:{inputTokens:0,outputTokens:0,totalTokens:0}})):l.textDelta&&(o||(o=Va(),h.enqueue({type:"text-start",id:o})),h.enqueue({type:"text-delta",id:o,delta:l.textDelta}));}})),rawCall:{rawPrompt:e,rawSettings:s}}}};var zi=class i{static buildEnhancedPrompt(t,e){let s=[];s.push(i.buildSystemPrompt(e));for(let r of t){let o=i.formatMessage(r);o&&s.push(o);}return s.push(`<|im_start|>assistant
|
|
15
|
+
`),s.join(`
|
|
16
|
+
`)}static buildSystemPrompt(t){return t&&t.length>0?`<|im_start|>system
|
|
17
|
+
Environment: ipython
|
|
18
|
+
|
|
19
|
+
You have access to the following functions:
|
|
20
|
+
|
|
21
|
+
${i.formatToolsDefinition(t)}
|
|
22
|
+
|
|
23
|
+
FUNCTION CALLING INSTRUCTIONS:
|
|
24
|
+
|
|
25
|
+
1. OUTPUT FORMAT:
|
|
26
|
+
- To call a function, respond with JSON: {"name": "function_name", "parameters": {...}}
|
|
27
|
+
- Do NOT use markdown code blocks, backticks, or any other formatting
|
|
28
|
+
- Do NOT use variables - always use actual literal values
|
|
29
|
+
- Each function call must be a complete, valid JSON object on its own line
|
|
30
|
+
|
|
31
|
+
2. PARALLEL TOOL CALLS:
|
|
32
|
+
- You can call multiple functions in parallel by outputting multiple JSON objects, one per line
|
|
33
|
+
- Use parallel calls when tasks are independent and can be executed simultaneously
|
|
34
|
+
- Example: Fetching data from multiple sources, checking multiple conditions, etc.
|
|
35
|
+
|
|
36
|
+
3. SEQUENTIAL TOOL CALLS:
|
|
37
|
+
- After receiving tool results, you can make additional function calls if needed
|
|
38
|
+
- Use sequential calls when later calls depend on earlier results
|
|
39
|
+
- Always wait for tool results before making dependent calls
|
|
40
|
+
|
|
41
|
+
4. TOOL RESULTS:
|
|
42
|
+
- After calling functions, you will receive results in tool messages
|
|
43
|
+
- Use all tool results to formulate your final response
|
|
44
|
+
- Synthesize information from multiple tool results when applicable
|
|
45
|
+
|
|
46
|
+
5. WHEN NOT TO CALL FUNCTIONS:
|
|
47
|
+
- If you can answer directly without tools, respond with regular text
|
|
48
|
+
- Don't call functions unnecessarily
|
|
49
|
+
|
|
50
|
+
EXAMPLES:
|
|
51
|
+
|
|
52
|
+
Example 1 - Single function call:
|
|
53
|
+
User: What is the weather in Paris?
|
|
54
|
+
Assistant: {"name": "get_weather", "parameters": {"location": "Paris", "units": "celsius"}}
|
|
55
|
+
Tool: 22\xB0C
|
|
56
|
+
Assistant: The temperature in Paris is 22\xB0C.
|
|
57
|
+
|
|
58
|
+
Example 2 - Parallel function calls (independent tasks):
|
|
59
|
+
User: Compare the weather in Tokyo and London
|
|
60
|
+
Assistant: {"name": "get_weather", "parameters": {"location": "Tokyo", "units": "celsius"}}
|
|
61
|
+
{"name": "get_weather", "parameters": {"location": "London", "units": "celsius"}}
|
|
62
|
+
Tool: 18\xB0C
|
|
63
|
+
Tool: 15\xB0C
|
|
64
|
+
Assistant: Tokyo is currently 18\xB0C while London is 15\xB0C. Tokyo is warmer by 3 degrees.
|
|
65
|
+
|
|
66
|
+
Example 3 - Multiple different functions in parallel:
|
|
67
|
+
User: What's the weather and current time in New York?
|
|
68
|
+
Assistant: {"name": "get_weather", "parameters": {"location": "New York", "units": "fahrenheit"}}
|
|
69
|
+
{"name": "get_time", "parameters": {"timezone": "America/New_York"}}
|
|
70
|
+
Tool: 68\xB0F
|
|
71
|
+
Tool: 14:30 EST
|
|
72
|
+
Assistant: In New York, it's currently 68\xB0F and the time is 14:30 EST.
|
|
73
|
+
|
|
74
|
+
Example 4 - Sequential function calls (dependent tasks):
|
|
75
|
+
User: Read config.json and tell me the weather for the city specified in it
|
|
76
|
+
Assistant: {"name": "read_file", "parameters": {"path": "config.json"}}
|
|
77
|
+
Tool: {"city": "Tokyo", "units": "celsius"}
|
|
78
|
+
Assistant: {"name": "get_weather", "parameters": {"location": "Tokyo", "units": "celsius"}}
|
|
79
|
+
Tool: 18\xB0C
|
|
80
|
+
Assistant: According to config.json, the city is Tokyo. The current weather in Tokyo is 18\xB0C.
|
|
81
|
+
|
|
82
|
+
Example 5 - No function needed:
|
|
83
|
+
User: Hello, how are you?
|
|
84
|
+
Assistant: Hello! I'm doing well, thank you for asking. How can I help you today?
|
|
85
|
+
|
|
86
|
+
CRITICAL REMINDERS:
|
|
87
|
+
- Output only valid JSON for function calls, one per line
|
|
88
|
+
- No markdown formatting, no code blocks, no backticks
|
|
89
|
+
- Use actual values, never variables or placeholders
|
|
90
|
+
- Call multiple functions in parallel when tasks are independent
|
|
91
|
+
- Always use tool results in your final response
|
|
92
|
+
<|im_end|>`:`<|im_start|>system
|
|
93
|
+
You are a helpful AI assistant.
|
|
94
|
+
|
|
95
|
+
THINKING INSTRUCTIONS:
|
|
96
|
+
When you need to think deeply, wrap your reasoning process with <think> and </think> tags.
|
|
97
|
+
Example: <think>Let me analyze this problem...</think>
|
|
98
|
+
|
|
99
|
+
CRITICAL OUTPUT RULES:
|
|
100
|
+
1. NEVER output ANY format tags in your response, including:
|
|
101
|
+
- <|im_start|>, <|im_end|>, </|im_start|>, </|im_end|>
|
|
102
|
+
- Unpaired tags like </think> without <think>
|
|
103
|
+
- Any other markup or formatting tags
|
|
104
|
+
2. If you use <think> tags, ALWAYS use them as a COMPLETE PAIR: <think>content</think>
|
|
105
|
+
3. Your response must be clean, natural text without any formatting markers
|
|
106
|
+
4. Do NOT include any part of the conversation format in your output
|
|
107
|
+
<|im_end|>`}static formatToolsDefinition(t){return t.map(e=>{let s=e.inputSchema;return JSON.stringify({name:e.name,description:e.description||"No description",parameters:s},null,2)}).join(`
|
|
108
|
+
|
|
109
|
+
`)}static formatMessage(t){let e="";if(typeof t.content=="string")e=t.content;else if(Array.isArray(t.content)){let s=[];for(let r of t.content)if(r.type==="text")s.push("text"in r?r.text:"");else if(r.type==="tool-call"){let o={name:r.toolName,parameters:r.args||{}};s.push(JSON.stringify(o));}else if(r.type==="tool-result"){let o=r.result;s.push(typeof o=="string"?o:JSON.stringify(o));}e=s.join(`
|
|
110
|
+
`);}switch(t.role){case "system":return null;case "user":return `<|im_start|>user
|
|
111
|
+
${e}<|im_end|>`;case "assistant":return `<|im_start|>assistant
|
|
112
|
+
${e}<|im_end|>`;case "tool":return `<|im_start|>tool
|
|
113
|
+
${e}<|im_end|>`;default:{let s=t.role;throw new T(`\u4E0D\u652F\u6301\u7684\u6D88\u606F\u89D2\u8272: ${s}`,"UNSUPPORTED_FEATURE")}}}};var _e=class{static processThinkTags(t,e){let s={...t};for(;s.contentBuffer.length>0;)if(s.isInThinkTag){let r=s.contentBuffer.indexOf("</think>");if(r===-1){s.contentBuffer.length>0&&e.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:s.contentBuffer}),s.contentBuffer="";break}if(r>0){let o=s.contentBuffer.substring(0,r);o.length>0&&e.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:o});}e.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false,s.isInThinkTag=false,s.contentBuffer=s.contentBuffer.substring(r+8);}else {let r=s.contentBuffer.indexOf("<think>");if(r===-1){s.contentBuffer.length>0&&(s.textStarted||(s.textStarted=true,e.enqueue({type:"text-start",id:"txt-0"})),e.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer})),s.contentBuffer="";break}if(r>0){let o=s.contentBuffer.substring(0,r);s.textStarted||(s.textStarted=true,e.enqueue({type:"text-start",id:"txt-0"})),o.length>0&&e.enqueue({type:"text-delta",id:"txt-0",delta:o}),e.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false;}s.isInThinkTag=true,s.contentBuffer=s.contentBuffer.substring(r+7),s.reasoningStarted||(s.reasoningStarted=true,e.enqueue({type:"reasoning-start",id:"reasoning-0"}));}return s}static finishThinkParsing(t,e){let s={...t};return s.contentBuffer.length>0?s.isInThinkTag?(s.contentBuffer.length>0&&e.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:s.contentBuffer}),s.reasoningStarted&&(e.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)):(s.textStarted||(e.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),s.contentBuffer.length>0&&e.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),e.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):(s.textStarted&&(e.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s.reasoningStarted&&!s.isInThinkTag&&(e.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)),s}static removeThinkTags(t){return t.replace(/<think>[\s\S]*?<\/think>/g,"").trim()}};function qa(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Fe=class i{static extractToolCalls(t){let e=[],s=t,r=t.split(`
|
|
114
|
+
`),o=[];for(let a of r){let l=a.trim();if(!l){o.push(a);continue}try{let h=JSON.parse(l);if(h.name&&typeof h.name=="string"&&h.parameters&&typeof h.parameters=="object"){e.push({name:h.name,parameters:JSON.stringify(h.parameters)});continue}}catch{}o.push(a);}return s=o.join(`
|
|
115
|
+
`).trim(),{toolCalls:e,remainingText:s}}static processToolCalls(t,e,s){let r={...t},o=r.contentBuffer.split(`
|
|
116
|
+
`),a=[];for(let l=0;l<o.length;l++){let h=o[l];if(!h)continue;let d=h.trim();if(!d){a.push(h);continue}let p=false;try{let f=JSON.parse(d);if(f.name&&typeof f.name=="string"&&f.parameters&&typeof f.parameters=="object"){if(s&&s.length>0&&!s.some(b=>b.name===f.name)){a.push(h);continue}if(p=!0,a.length>0){let S=a.join(`
|
|
117
|
+
`);S.trim()&&(r.textStarted||(e.enqueue({type:"text-start",id:"txt-0"}),r.textStarted=!0),e.enqueue({type:"text-delta",id:"txt-0",delta:S+`
|
|
118
|
+
`})),a.length=0;}r.textStarted&&(e.enqueue({type:"text-end",id:"txt-0"}),r.textStarted=!1);let g=qa(),y=JSON.stringify(f.parameters);e.enqueue({type:"tool-input-start",id:g,toolName:f.name}),e.enqueue({type:"tool-input-delta",id:g,delta:y}),e.enqueue({type:"tool-input-end",id:g}),e.enqueue({type:"tool-call",toolCallId:g,toolName:f.name,input:y}),r.completedToolCalls.push({id:g,name:f.name,parameters:y});}}catch{}p||a.push(h);}return r.contentBuffer=a.join(`
|
|
119
|
+
`),r}static finishToolParsing(t,e){let s={...t};return s.contentBuffer.trim().length>0?(s.textStarted||(e.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),e.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),e.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):s.textStarted&&(e.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s}static removeToolCalls(t){let{remainingText:e}=i.extractToolCalls(t);return e}};function Bn(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var $i=class{constructor(t,e,s){c(this,"specificationVersion","v2");c(this,"provider");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"supportsToolCalling","experimental");c(this,"supportsThinking","experimental");c(this,"engine");c(this,"modelConfig");if(this.provider=t,this.modelId=e,this.engine=s,this.modelConfig=Ht[e],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${e}`,"MODEL_NOT_FOUND")}async doGenerate(t){pt.validateMessages(t.prompt);let e=t.tools?.filter(g=>"inputSchema"in g),s=zi.buildEnhancedPrompt(t.prompt,e),r={temperature:t.temperature??this.modelConfig.defaultSettings.temperature,topP:t.topP??this.modelConfig.defaultSettings.topP,topK:t.topK??this.modelConfig.defaultSettings.topK,maxTokens:t.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:t.abortSignal};pt.validateGenerateOptions(r),this.engine.isReady()||await this.engine.initialize();let o=await this.engine.generate(s,r),a=_e.removeThinkTags(o.text),{toolCalls:l,remainingText:h}=Fe.extractToolCalls(a),d=[];h.trim().length>0&&d.push({type:"text",text:h});for(let g of l)d.push({type:"tool-call",toolCallId:Bn(),toolName:g.name,input:g.parameters});let p=l.length>0?"tool-calls":o.finishReason,f=[];return {content:d,finishReason:p,usage:{inputTokens:o.usage.promptTokens,outputTokens:o.usage.completionTokens,totalTokens:o.usage.totalTokens},warnings:f,rawCall:{rawPrompt:s,rawSettings:r}}}async doStream(t){let e=Bn();pt.validateMessages(t.prompt);let s=t.tools?.filter(y=>"inputSchema"in y),r=zi.buildEnhancedPrompt(t.prompt,s),o={temperature:t.temperature??this.modelConfig.defaultSettings.temperature,topP:t.topP??this.modelConfig.defaultSettings.topP,topK:t.topK??this.modelConfig.defaultSettings.topK,maxTokens:t.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:t.abortSignal};pt.validateGenerateOptions(o),this.engine.isReady()||await this.engine.initialize();let a=null,l=null,h=y=>{a&&a.enqueue(y),l&&l.enqueue(y);},d=async()=>{try{let y={isInThinkTag:!1,reasoningStarted:!1,textStarted:!1,contentBuffer:""},S={contentBuffer:"",textStarted:!1,completedToolCalls:[]};h({type:"response-metadata",id:e,modelId:this.modelId,timestamp:new Date}),await this.engine.generateStream(r,o,b=>{if(b.type==="text-delta"){let x=b.textDelta||"";if(x.length===0)return;y.contentBuffer+=x;let E=_e.processThinkTags(y,{enqueue:h});y.isInThinkTag=E.isInThinkTag,y.reasoningStarted=E.reasoningStarted,y.textStarted=E.textStarted,S.contentBuffer+=E.contentBuffer,y.contentBuffer="";let k=Fe.processToolCalls(S,{enqueue:h},s);S.contentBuffer=k.contentBuffer,S.textStarted=k.textStarted,S.completedToolCalls=k.completedToolCalls;}else if(b.type==="text-end"){let x=_e.finishThinkParsing(y,{enqueue:h});y.textStarted=x.textStarted,y.reasoningStarted=x.reasoningStarted;let E=Fe.finishToolParsing(S,{enqueue:h});S.textStarted=E.textStarted;}else if(b.type==="finish"){let x=_e.finishThinkParsing(y,{enqueue:h});y.textStarted=x.textStarted,y.reasoningStarted=x.reasoningStarted;let E=Fe.finishToolParsing(S,{enqueue:h});S.textStarted=E.textStarted;let k=S.completedToolCalls.length>0;h({type:"finish",finishReason:k?"tool-calls":b.finishReason,usage:b.usage?{inputTokens:b.usage.promptTokens,outputTokens:b.usage.completionTokens,totalTokens:b.usage.totalTokens}:{inputTokens:0,outputTokens:0,totalTokens:0}});}});}catch(y){h({type:"error",error:y instanceof Error?y.message:String(y)}),h({type:"finish",finishReason:"error",usage:{inputTokens:0,outputTokens:0,totalTokens:0}});}finally{a&&a.close(),l&&l.close();}},p=new ReadableStream({start(y){a=y;}}),f=new ReadableStream({start(y){l=y;}});d();async function*g(y){let S=y.getReader();try{for(;;){let{done:b,value:x}=await S.read();if(b)break;yield x;}}finally{S.releaseLock();}}return {stream:p,fullStream:g(f),request:{body:r},response:{headers:{}}}}};var gs=class{constructor(t){c(this,"config");this.config=t;}createBatches(t){let e=[],s=this.config.batchSize;for(let r=0;r<t.length;r+=s)e.push(t.slice(r,r+s));return e}async processBatches(t,e,s){if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let r=this.createBatches(t),o=[];for(let a=0;a<r.length;a++){if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let l=r[a];if(l){try{let h=await e(l);o.push(...h);}catch(h){throw h instanceof T&&h.code==="ABORTED"?h:new T(`\u6279\u6B21 ${a+1}/${r.length} \u5904\u7406\u5931\u8D25: ${h instanceof Error?h.message:String(h)}`,"PROCESSING_ERROR",h instanceof Error?h:void 0)}a<r.length-1&&this.config.delayBetweenBatches&&this.config.delayBetweenBatches>0&&await this.delay(this.config.delayBetweenBatches,s);}}return o}async delay(t,e){return new Promise((s,r)=>{if(e?.aborted){r(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));return}let o=setTimeout(()=>{e?.removeEventListener("abort",a),s();},t),a=()=>{clearTimeout(o),r(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));};e?.addEventListener("abort",a);})}};var ji=class{constructor(t,e,s){c(this,"specificationVersion","v2");c(this,"provider");c(this,"modelId");c(this,"maxEmbeddingsPerCall");c(this,"supportsParallelCalls",false);c(this,"engine");c(this,"modelConfig");if(this.provider=t,this.modelId=e,this.engine=s,this.modelConfig=Se[e],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${e}`,"MODEL_NOT_FOUND");this.maxEmbeddingsPerCall=this.modelConfig.maxEmbeddingsPerCall;}async doEmbed(t){let{values:e,abortSignal:s}=t;if(pt.validateTexts(e),s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");this.engine.isReady()||await this.engine.initialize();let o=await new gs({batchSize:this.maxEmbeddingsPerCall,delayBetweenBatches:0}).processBatches(e,async l=>{if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");return await this.engine.embed(l,s)},s),a=await this.engine.countTokens(e);return {embeddings:o,usage:{tokens:a}}}};var be=we.create({service:"local-model-provider"}),Hs={cacheDir:ei__default.join(Ys.homedir(),".cache","easbot","models"),verbose:false,autoUnloadTimeout:300*1e3,maxCachedModels:3,memoryWarningThreshold:1.5*1024*1024*1024,useEnhancedModel:true,logPath:"",logLevel:"INFO"},ms=class{constructor(t){c(this,"config");c(this,"modelCache");c(this,"engines",new Map);c(this,"modelInfo",new Map);this.config={...Hs,...t},this.modelCache=new Ue({cacheDir:this.config.cacheDir});}languageModel(t,e){if(!Ht[t])throw new T(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${t}`,"MODEL_NOT_FOUND");let s=this.getOrCreateEngine(t,"language");return e?.useEnhancedModel??this.config.useEnhancedModel?(this.config.verbose&&be.debug("\u521B\u5EFA\u589E\u5F3A\u8BED\u8A00\u6A21\u578B",{modelId:t}),new $i("local",t,s)):(this.config.verbose&&be.debug("\u521B\u5EFA\u57FA\u7840\u8BED\u8A00\u6A21\u578B",{modelId:t}),new Bi("local",t,s))}textEmbeddingModel(t){if(!Se[t])throw new T(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${t}`,"MODEL_NOT_FOUND");let e=this.getOrCreateEngine(t,"embedding");return new ji("local",t,e)}chat(t,e){return this.languageModel(t,e)}getOrCreateEngine(t,e){let s=`${e}:${t}`;if(this.engines.has(s)){let o=this.modelInfo.get(s);return o&&(o.lastUsed=Date.now(),o.useCount++),this.config.verbose&&be.debug("\u590D\u7528\u5DF2\u52A0\u8F7D\u7684\u6A21\u578B",{engineKey:s}),this.engines.get(s)}this.engines.size>=this.config.maxCachedModels&&this.evictLeastRecentlyUsed(),this.config.verbose&&be.debug("\u521B\u5EFA\u65B0\u5F15\u64CE",{engineKey:s});let r=new fs({modelId:t,modelType:e,cacheDir:this.config.cacheDir,verbose:this.config.verbose});return this.engines.set(s,r),this.modelInfo.set(s,{modelId:t,modelType:e,isLoaded:false,lastUsed:Date.now(),useCount:1}),r}evictLeastRecentlyUsed(){let t=null,e=Number.POSITIVE_INFINITY;for(let[s,r]of this.modelInfo.entries())r.lastUsed<e&&(e=r.lastUsed,t=s);if(t){this.config.verbose&&be.debug("\u6DD8\u6C70\u6A21\u578B",{engineKey:t});let s=this.engines.get(t);s&&s.dispose().catch(r=>{be.error("\u5378\u8F7D\u6A21\u578B\u5931\u8D25",{error:r});}),this.engines.delete(t),this.modelInfo.delete(t);}}getLoadedModels(){return Array.from(this.modelInfo.values())}async dispose(){this.config.verbose&&be.debug("\u5378\u8F7D\u6240\u6709\u6A21\u578B");let t=Array.from(this.engines.values()).map(e=>e.dispose());await Promise.all(t),this.engines.clear(),this.modelInfo.clear(),this.config.verbose&&be.debug("\u6240\u6709\u6A21\u578B\u5DF2\u5378\u8F7D");}};function Ha(i){let t=new ms(i);if(i?.logPath){let s=i.logLevel||"DEBUG",r=ei__default.join(i.logPath,"local-model-sdk.log");we.init({print:false,logPath:r,level:s}).then(()=>{we.create({service:"local-model-sdk",module:"provider"}).debug("Local model provider created",{cacheDir:i?.cacheDir||Hs.cacheDir,useEnhancedModel:i?.useEnhancedModel??Hs.useEnhancedModel,logFile:r,logLevel:s});});}return Object.assign((s,r)=>t.languageModel(s,r),{languageModel:(s,r)=>t.languageModel(s,r),chat:(s,r)=>t.chat(s,r),textEmbeddingModel:s=>t.textEmbeddingModel(s)})}var Ka="0.1.0",Ja="@easbot/local-model-sdk",Ya="Complete local model SDK for EASBot - Transformers.js + ONNX implementation";export{gt as ErrorCode,nt as ErrorHandler,ji as LocalEmbeddingModel,$i as LocalEnhancedLanguageModel,Bi as LocalLanguageModel,T as LocalModelError,ms as LocalModelProvider,Ya as SDK_DESCRIPTION,Ja as SDK_NAME,Se as SUPPORTED_EMBEDDING_MODELS,Ht as SUPPORTED_LANGUAGE_MODELS,Ka as VERSION,Ha as createLocal};
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easbot/local-model-sdk",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Complete local model SDK for EASBot - Transformers.js + ONNX implementation supporting both Language Model (text generation) and Embedding (text embedding) with full AI SDK v2 compatibility",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"easbot",
|
|
19
|
+
"local-model",
|
|
20
|
+
"language-model",
|
|
21
|
+
"embedding",
|
|
22
|
+
"transformers",
|
|
23
|
+
"onnx",
|
|
24
|
+
"qwen",
|
|
25
|
+
"bge",
|
|
26
|
+
"ai-sdk",
|
|
27
|
+
"text-generation",
|
|
28
|
+
"text-embedding",
|
|
29
|
+
"chinese-nlp",
|
|
30
|
+
"offline-ai",
|
|
31
|
+
"privacy-first"
|
|
32
|
+
],
|
|
33
|
+
"author": "houjallen",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/houjallen/easbot.git",
|
|
38
|
+
"directory": "packages/local-model-sdk"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/houjallen/easbot/tree/main/packages/local-model-sdk#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/houjallen/easbot/issues"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"README.en.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@ai-sdk/provider": "^2.0.1",
|
|
52
|
+
"@ai-sdk/provider-utils": "^3.0.20",
|
|
53
|
+
"@huggingface/transformers": "^3.8.1",
|
|
54
|
+
"onnxruntime-node": "^1.20.1"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"ai": "^5.0.129"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "^2.3.13",
|
|
61
|
+
"@types/axios": "^0.14.4",
|
|
62
|
+
"@types/node": "^25.2.0",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
64
|
+
"dotenv": "^16.4.7",
|
|
65
|
+
"esbuild": "^0.27.3",
|
|
66
|
+
"esbuild-plugin-alias": "^0.2.1",
|
|
67
|
+
"tsup": "^8.5.1",
|
|
68
|
+
"typescript": "^5.9.3",
|
|
69
|
+
"vitest": "^4.0.18"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=18.0.0"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"dev": "tsup --watch --env.NODE_ENV development",
|
|
79
|
+
"build": "tsup --env.NODE_ENV production",
|
|
80
|
+
"test": "vitest",
|
|
81
|
+
"test:run": "vitest run",
|
|
82
|
+
"lint": "biome check .",
|
|
83
|
+
"lint:fix": "biome check --write .",
|
|
84
|
+
"lint:report": "biome check --reporter=summary ./src",
|
|
85
|
+
"format": "biome format .",
|
|
86
|
+
"format:fix": "biome format --write .",
|
|
87
|
+
"type-check": "tsc --noEmit",
|
|
88
|
+
"clean": "npx rimraf dist node_modules",
|
|
89
|
+
"publish:npm": "bash scripts/publish.sh",
|
|
90
|
+
"publish:npm:win": "powershell -ExecutionPolicy Bypass -File scripts/publish.ps1"
|
|
91
|
+
}
|
|
92
|
+
}
|