@easbot/local-model-sdk 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
- 'use strict';var transformers=require('@huggingface/transformers'),tr=require('os'),ii=require('path'),z=require('fs'),Bn=require('fs/promises'),Ka=require('zod'),url=require('url'),events=require('events'),pn=require('stream'),string_decoder=require('string_decoder'),utils=require('@easbot/utils'),ai$1=require('ai');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var tr__namespace=/*#__PURE__*/_interopNamespace(tr);var ii__namespace=/*#__PURE__*/_interopNamespace(ii);var z__namespace=/*#__PURE__*/_interopNamespace(z);var Bn__default=/*#__PURE__*/_interopDefault(Bn);var Ka__default=/*#__PURE__*/_interopDefault(Ka);var pn__default=/*#__PURE__*/_interopDefault(pn);var Hn=Object.defineProperty;var er=i=>{throw TypeError(i)};var Kn=(i,e,t)=>e in i?Hn(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var c=(i,e,t)=>Kn(i,typeof e!="symbol"?e+"":e,t),xs=(i,e,t)=>e.has(i)||er("Cannot "+t);var n=(i,e,t)=>(xs(i,e,"read from private field"),t?t.call(i):e.get(i)),w=(i,e,t)=>e.has(i)?er("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),f=(i,e,t,s)=>(xs(i,e,"write to private field"),e.set(i,t),t),y=(i,e,t)=>(xs(i,e,"access private method"),t);var qi=(i,e,t,s)=>({set _(r){f(i,e,r);},get _(){return n(i,e,s)}});var me=(u=>(u.MODEL_NOT_FOUND="MODEL_NOT_FOUND",u.MODEL_LOAD_ERROR="MODEL_LOAD_ERROR",u.MODEL_NOT_INITIALIZED="MODEL_NOT_INITIALIZED",u.GENERATION_ERROR="GENERATION_ERROR",u.EMBEDDING_ERROR="EMBEDDING_ERROR",u.INVALID_INPUT="INVALID_INPUT",u.UNSUPPORTED_FEATURE="UNSUPPORTED_FEATURE",u.CACHE_ERROR="CACHE_ERROR",u.PROCESSING_ERROR="PROCESSING_ERROR",u.ABORTED="ABORTED",u.OUT_OF_MEMORY="OUT_OF_MEMORY",u.UNKNOWN_ERROR="UNKNOWN_ERROR",u))(me||{});function Vi(i,e,t){let s;return e?s="error":i?s="stop":s="other",{unified:s,raw:t}}var xe={"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:[]}}},bt={"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,dtype:"q4"},"bge-large-zh-v1.5":{modelId:"bge-large-zh-v1.5",huggingFaceId:"Xenova/bge-large-zh-v1.5",dimensions:1024,maxEmbeddingsPerCall:32,dtype:"q4"},"all-MiniLM-L6-v2":{modelId:"all-MiniLM-L6-v2",huggingFaceId:"sentence-transformers/all-MiniLM-L6-v2",dimensions:384,maxEmbeddingsPerCall:32,dtype:"q4"}};var x=class i extends Error{constructor(t,s,r){super(t);this.code=s;this.cause=r;this.name="LocalModelError",Error.captureStackTrace&&Error.captureStackTrace(this,i);}},ne=class{static modelLoadError(e){return new x(`\u6A21\u578B\u52A0\u8F7D\u5931\u8D25: ${e.message}`,"MODEL_LOAD_ERROR",e)}static generationError(e){return new x(`\u751F\u6210\u5931\u8D25: ${e.message}`,"GENERATION_ERROR",e)}static embeddingError(e){return new x(`\u5D4C\u5165\u5931\u8D25: ${e.message}`,"EMBEDDING_ERROR",e)}static validationError(e){return new x(e,"INVALID_INPUT")}static abortError(){return new x("\u64CD\u4F5C\u5DF2\u4E2D\u6B62","ABORTED")}static unsupportedFeature(e){return new x(`\u4E0D\u652F\u6301\u7684\u529F\u80FD: ${e}`,"UNSUPPORTED_FEATURE")}};var Jn=ii__namespace.join(tr__namespace.homedir(),".cache","easbot","models"),$t=class{constructor(e){c(this,"cacheDir");this.cacheDir=e.cacheDir||Jn;}getCachePath(e){return ii__namespace.join(this.cacheDir,e)}isCached(e){try{let t=this.getCachePath(e);return z__namespace.existsSync(t)&&z__namespace.statSync(t).isDirectory()}catch{return false}}async clear(e){try{if(e){let t=this.getCachePath(e);z__namespace.existsSync(t)&&await this.removeDirectory(t);}else z__namespace.existsSync(this.cacheDir)&&await this.removeDirectory(this.cacheDir);}catch(t){throw new x(`\u6E05\u7406\u7F13\u5B58\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`,"CACHE_ERROR",t instanceof Error?t:void 0)}}async getCacheSize(e){try{let t=e?this.getCachePath(e):this.cacheDir;return z__namespace.existsSync(t)?await this.getDirectorySize(t):0}catch(t){throw new x(`\u83B7\u53D6\u7F13\u5B58\u5927\u5C0F\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`,"CACHE_ERROR",t instanceof Error?t:void 0)}}async getDirectorySize(e){let t=0,s=z__namespace.readdirSync(e);for(let r of s){let o=ii__namespace.join(e,r),a=z__namespace.statSync(o);a.isDirectory()?t+=await this.getDirectorySize(o):t+=a.size;}return t}async removeDirectory(e){if(!z__namespace.existsSync(e))return;let t=z__namespace.readdirSync(e);for(let s of t){let r=ii__namespace.join(e,s);z__namespace.statSync(r).isDirectory()?await this.removeDirectory(r):z__namespace.unlinkSync(r);}z__namespace.rmdirSync(e);}ensureCacheDir(){try{z__namespace.existsSync(this.cacheDir)||z__namespace.mkdirSync(this.cacheDir,{recursive:!0});}catch(e){throw new x(`\u521B\u5EFA\u7F13\u5B58\u76EE\u5F55\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`,"CACHE_ERROR",e instanceof Error?e:void 0)}}};var Kr=(i,e,t)=>{let s=i instanceof RegExp?ir(i,t):i,r=e instanceof RegExp?ir(e,t):e,o=s!==null&&r!=null&&Yn(s,r,t);return o&&{start:o[0],end:o[1],pre:t.slice(0,o[0]),body:t.slice(o[0]+s.length,o[1]),post:t.slice(o[1]+r.length)}},ir=(i,e)=>{let t=e.match(i);return t?t[0]:null},Yn=(i,e,t)=>{let s,r,o,a,h,l=t.indexOf(i),d=t.indexOf(e,l+1),g=l;if(l>=0&&d>0){if(i===e)return [l,d];for(s=[],o=t.length;g>=0&&!h;){if(g===l)s.push(g),l=t.indexOf(i,g+1);else if(s.length===1){let p=s.pop();p!==void 0&&(h=[p,d]);}else r=s.pop(),r!==void 0&&r<o&&(o=r,a=d),d=t.indexOf(e,g+1);g=l<d&&l>=0?l:d;}s.length&&a!==void 0&&(h=[o,a]);}return h},Jr="\0SLASH"+Math.random()+"\0",Yr="\0OPEN"+Math.random()+"\0",Vs="\0CLOSE"+Math.random()+"\0",Zr="\0COMMA"+Math.random()+"\0",Xr="\0PERIOD"+Math.random()+"\0",Zn=new RegExp(Jr,"g"),Xn=new RegExp(Yr,"g"),Qn=new RegExp(Vs,"g"),eo=new RegExp(Zr,"g"),to=new RegExp(Xr,"g"),io=/\\\\/g,so=/\\{/g,ro=/\\}/g,no=/\\,/g,oo=/\\./g,ao=1e5;function Ts(i){return isNaN(i)?i.charCodeAt(0):parseInt(i,10)}function lo(i){return i.replace(io,Jr).replace(so,Yr).replace(ro,Vs).replace(no,Zr).replace(oo,Xr)}function ho(i){return i.replace(Zn,"\\").replace(Xn,"{").replace(Qn,"}").replace(eo,",").replace(to,".")}function Qr(i){if(!i)return [""];let e=[],t=Kr("{","}",i);if(!t)return i.split(",");let{pre:s,body:r,post:o}=t,a=s.split(",");a[a.length-1]+="{"+r+"}";let h=Qr(o);return o.length&&(a[a.length-1]+=h.shift(),a.push.apply(a,h)),e.push.apply(e,a),e}function co(i,e={}){if(!i)return [];let{max:t=ao}=e;return i.slice(0,2)==="{}"&&(i="\\{\\}"+i.slice(2)),hi(lo(i),t,true).map(ho)}function uo(i){return "{"+i+"}"}function po(i){return /^-?0\d/.test(i)}function fo(i,e){return i<=e}function go(i,e){return i>=e}function hi(i,e,t){let s=[],r=Kr("{","}",i);if(!r)return [i];let o=r.pre,a=r.post.length?hi(r.post,e,false):[""];if(/\$$/.test(r.pre))for(let h=0;h<a.length&&h<e;h++){let l=o+"{"+r.body+"}"+a[h];s.push(l);}else {let h=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(r.body),l=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(r.body),d=h||l,g=r.body.indexOf(",")>=0;if(!d&&!g)return r.post.match(/,(?!,).*\}/)?(i=r.pre+"{"+r.body+Vs+r.post,hi(i,e,true)):[i];let p;if(d)p=r.body.split(/\.\./);else if(p=Qr(r.body),p.length===1&&p[0]!==void 0&&(p=hi(p[0],e,false).map(uo),p.length===1))return a.map(m=>r.pre+p[0]+m);let u;if(d&&p[0]!==void 0&&p[1]!==void 0){let m=Ts(p[0]),b=Ts(p[1]),S=Math.max(p[0].length,p[1].length),T=p.length===3&&p[2]!==void 0?Math.abs(Ts(p[2])):1,v=fo;b<m&&(T*=-1,v=go);let k=p.some(po);u=[];for(let C=m;v(C,b);C+=T){let O;if(l)O=String.fromCharCode(C),O==="\\"&&(O="");else if(O=String(C),k){let D=S-O.length;if(D>0){let P=new Array(D+1).join("0");C<0?O="-"+P+O.slice(1):O=P+O;}}u.push(O);}}else {u=[];for(let m=0;m<p.length;m++)u.push.apply(u,hi(p[m],e,false));}for(let m=0;m<u.length;m++)for(let b=0;b<a.length&&s.length<e;b++){let S=o+u[m]+a[b];(!t||d||S)&&s.push(S);}}return s}var hs=i=>{if(typeof i!="string")throw new TypeError("invalid pattern");if(i.length>65536)throw new TypeError("pattern is too long")},mo={"[: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]},si=i=>i.replace(/[[\]\\-]/g,"\\$&"),yo=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),sr=i=>i.join(""),wo=(i,e)=>{let t=e;if(i.charAt(t)!=="[")throw new Error("not in a brace expression");let s=[],r=[],o=t+1,a=false,h=false,l=false,d=false,g=t,p="";e:for(;o<i.length;){let b=i.charAt(o);if((b==="!"||b==="^")&&o===t+1){d=true,o++;continue}if(b==="]"&&a&&!l){g=o+1;break}if(a=true,b==="\\"&&!l){l=true,o++;continue}if(b==="["&&!l){for(let[S,[T,v,k]]of Object.entries(mo))if(i.startsWith(S,o)){if(p)return ["$.",false,i.length-t,true];o+=S.length,k?r.push(T):s.push(T),h=h||v;continue e}}if(l=false,p){b>p?s.push(si(p)+"-"+si(b)):b===p&&s.push(si(b)),p="",o++;continue}if(i.startsWith("-]",o+1)){s.push(si(b+"-")),o+=2;continue}if(i.startsWith("-",o+1)){p=b,o+=2;continue}s.push(si(b)),o++;}if(g<o)return ["",false,0,false];if(!s.length&&!r.length)return ["$.",false,i.length-t,true];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!d){let b=s[0].length===2?s[0].slice(-1):s[0];return [yo(b),false,g-t,false]}let u="["+(d?"^":"")+sr(s)+"]",m="["+(d?"":"^")+sr(r)+"]";return [s.length&&r.length?"("+u+"|"+m+")":s.length?u:m,h,g-t,true]},jt=(i,{windowsPathsNoEscape:e=false,magicalBraces:t=true}={})=>t?e?i.replace(/\[([^\/\\])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):e?i.replace(/\[([^\/\\{}])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),bo=new Set(["!","?","+","*","@"]),rr=i=>bo.has(i),So="(?!(?:^|/)\\.\\.?(?:$|/))",Hi="(?!\\.)",vo=new Set(["[","."]),Eo=new Set(["..","."]),xo=new Set("().*{}+?[]^$\\!"),To=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Hs="[^/]",nr=Hs+"*?",or=Hs+"+?",q,X,Ye,N,j,ct,xt,dt,Ge,Tt,mi,At,tn,yt,te,ts,Ds,sn,en=(te=class{constructor(e,t,s={}){w(this,At);c(this,"type");w(this,q);w(this,X);w(this,Ye,false);w(this,N,[]);w(this,j);w(this,ct);w(this,xt);w(this,dt,false);w(this,Ge);w(this,Tt);w(this,mi,false);this.type=e,e&&f(this,X,true),f(this,j,t),f(this,q,n(this,j)?n(n(this,j),q):this),f(this,Ge,n(this,q)===this?s:n(n(this,q),Ge)),f(this,xt,n(this,q)===this?[]:n(n(this,q),xt)),e==="!"&&!n(n(this,q),dt)&&n(this,xt).push(this),f(this,ct,n(this,j)?n(n(this,j),N).length:0);}get hasMagic(){if(n(this,X)!==void 0)return n(this,X);for(let e of n(this,N))if(typeof e!="string"&&(e.type||e.hasMagic))return f(this,X,true);return n(this,X)}toString(){return n(this,Tt)!==void 0?n(this,Tt):this.type?f(this,Tt,this.type+"("+n(this,N).map(e=>String(e)).join("|")+")"):f(this,Tt,n(this,N).map(e=>String(e)).join(""))}push(...e){for(let t of e)if(t!==""){if(typeof t!="string"&&!(t instanceof te&&n(t,j)===this))throw new Error("invalid part: "+t);n(this,N).push(t);}}toJSON(){let e=this.type===null?n(this,N).slice().map(t=>typeof t=="string"?t:t.toJSON()):[this.type,...n(this,N).map(t=>t.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===n(this,q)||n(n(this,q),dt)&&n(this,j)?.type==="!")&&e.push({}),e}isStart(){if(n(this,q)===this)return true;if(!n(this,j)?.isStart())return false;if(n(this,ct)===0)return true;let e=n(this,j);for(let t=0;t<n(this,ct);t++){let s=n(e,N)[t];if(!(s instanceof te&&s.type==="!"))return false}return true}isEnd(){if(n(this,q)===this||n(this,j)?.type==="!")return true;if(!n(this,j)?.isEnd())return false;if(!this.type)return n(this,j)?.isEnd();let e=n(this,j)?n(n(this,j),N).length:0;return n(this,ct)===e-1}copyIn(e){typeof e=="string"?this.push(e):this.push(e.clone(this));}clone(e){let t=new te(this.type,e);for(let s of n(this,N))t.copyIn(s);return t}static fromGlob(e,t={}){var r;let s=new te(null,void 0,t);return y(r=te,yt,ts).call(r,e,s,0,t),s}toMMPattern(){if(this!==n(this,q))return n(this,q).toMMPattern();let e=this.toString(),[t,s,r,o]=this.toRegExpSource();if(!(r||n(this,X)||n(this,Ge).nocase&&!n(this,Ge).nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return s;let a=(n(this,Ge).nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return n(this,Ge)}toRegExpSource(e){let t=e??!!n(this,Ge).dot;if(n(this,q)===this&&y(this,At,tn).call(this),!this.type){let l=this.isStart()&&this.isEnd()&&!n(this,N).some(u=>typeof u!="string"),d=n(this,N).map(u=>{var v;let[m,b,S,T]=typeof u=="string"?y(v=te,yt,sn).call(v,u,n(this,X),l):u.toRegExpSource(e);return f(this,X,n(this,X)||S),f(this,Ye,n(this,Ye)||T),m}).join(""),g="";if(this.isStart()&&typeof n(this,N)[0]=="string"&&!(n(this,N).length===1&&Eo.has(n(this,N)[0]))){let u=vo,m=t&&u.has(d.charAt(0))||d.startsWith("\\.")&&u.has(d.charAt(2))||d.startsWith("\\.\\.")&&u.has(d.charAt(4)),b=!t&&!e&&u.has(d.charAt(0));g=m?So:b?Hi:"";}let p="";return this.isEnd()&&n(n(this,q),dt)&&n(this,j)?.type==="!"&&(p="(?:$|\\/)"),[g+d+p,jt(d),f(this,X,!!n(this,X)),n(this,Ye)]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",o=y(this,At,Ds).call(this,t);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString();return f(this,N,[l]),this.type=null,f(this,X,void 0),[l,jt(this.toString()),false,false]}let a=!s||e||t||!Hi?"":y(this,At,Ds).call(this,true);a===o&&(a=""),a&&(o=`(?:${o})(?:${a})*?`);let h="";if(this.type==="!"&&n(this,mi))h=(this.isStart()&&!t?Hi:"")+or;else {let l=this.type==="!"?"))"+(this.isStart()&&!t&&!e?Hi:"")+nr+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&a?")":this.type==="*"&&a?")?":`)${this.type}`;h=r+o+l;}return [h,jt(o),f(this,X,!!n(this,X)),n(this,Ye)]}},q=new WeakMap,X=new WeakMap,Ye=new WeakMap,N=new WeakMap,j=new WeakMap,ct=new WeakMap,xt=new WeakMap,dt=new WeakMap,Ge=new WeakMap,Tt=new WeakMap,mi=new WeakMap,At=new WeakSet,tn=function(){if(this!==n(this,q))throw new Error("should only call on root");if(n(this,dt))return this;this.toString(),f(this,dt,true);let e;for(;e=n(this,xt).pop();){if(e.type!=="!")continue;let t=e,s=n(t,j);for(;s;){for(let r=n(t,ct)+1;!s.type&&r<n(s,N).length;r++)for(let o of n(e,N)){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n(s,N)[r]);}t=s,s=n(t,j);}}return this},yt=new WeakSet,ts=function(e,t,s,r){var m,b;let o=false,a=false,h=-1,l=false;if(t.type===null){let S=s,T="";for(;S<e.length;){let v=e.charAt(S++);if(o||v==="\\"){o=!o,T+=v;continue}if(a){S===h+1?(v==="^"||v==="!")&&(l=true):v==="]"&&!(S===h+2&&l)&&(a=false),T+=v;continue}else if(v==="["){a=true,h=S,l=false,T+=v;continue}if(!r.noext&&rr(v)&&e.charAt(S)==="("){t.push(T),T="";let k=new te(v,t);S=y(m=te,yt,ts).call(m,e,k,S,r),t.push(k);continue}T+=v;}return t.push(T),S}let d=s+1,g=new te(null,t),p=[],u="";for(;d<e.length;){let S=e.charAt(d++);if(o||S==="\\"){o=!o,u+=S;continue}if(a){d===h+1?(S==="^"||S==="!")&&(l=true):S==="]"&&!(d===h+2&&l)&&(a=false),u+=S;continue}else if(S==="["){a=true,h=d,l=false,u+=S;continue}if(rr(S)&&e.charAt(d)==="("){g.push(u),u="";let T=new te(S,g);g.push(T),d=y(b=te,yt,ts).call(b,e,T,d,r);continue}if(S==="|"){g.push(u),u="",p.push(g),g=new te(null,t);continue}if(S===")")return u===""&&n(t,N).length===0&&f(t,mi,true),g.push(u),u="",t.push(...p,g),d;u+=S;}return t.type=null,f(t,X,void 0),f(t,N,[e.substring(s-1)]),d},Ds=function(e){return n(this,N).map(t=>{if(typeof t=="string")throw new Error("string type in extglob ast??");let[s,r,o,a]=t.toRegExpSource(e);return f(this,Ye,n(this,Ye)||a),s}).filter(t=>!(this.isStart()&&this.isEnd())||!!t).join("|")},sn=function(e,t,s=false){let r=false,o="",a=false,h=false;for(let l=0;l<e.length;l++){let d=e.charAt(l);if(r){r=false,o+=(xo.has(d)?"\\":"")+d;continue}if(d==="*"){if(h)continue;h=true,o+=s&&/^[*]+$/.test(e)?or:nr,t=true;continue}else h=false;if(d==="\\"){l===e.length-1?o+="\\\\":r=true;continue}if(d==="["){let[g,p,u,m]=wo(e,l);if(u){o+=g,a=a||p,l+=u-1,t=t||m;continue}}if(d==="?"){o+=Hs,t=true;continue}o+=To(d);}return [o,jt(e),!!t,a]},w(te,yt),te),rn=(i,{windowsPathsNoEscape:e=false,magicalBraces:t=false}={})=>t?e?i.replace(/[?*()[\]{}]/g,"[$&]"):i.replace(/[?*()[\]\\{}]/g,"\\$&"):e?i.replace(/[?*()[\]]/g,"[$&]"):i.replace(/[?*()[\]\\]/g,"\\$&"),de=(i,e,t={})=>(hs(e),!t.nocomment&&e.charAt(0)==="#"?false:new wt(e,t).match(i)),ko=/^\*+([^+@!?\*\[\(]*)$/,Mo=i=>e=>!e.startsWith(".")&&e.endsWith(i),Ro=i=>e=>e.endsWith(i),Lo=i=>(i=i.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(i)),Co=i=>(i=i.toLowerCase(),e=>e.toLowerCase().endsWith(i)),Oo=/^\*+\.\*+$/,Po=i=>!i.startsWith(".")&&i.includes("."),Do=i=>i!=="."&&i!==".."&&i.includes("."),Ao=/^\.\*+$/,Io=i=>i!=="."&&i!==".."&&i.startsWith("."),No=/^\*+$/,_o=i=>i.length!==0&&!i.startsWith("."),Fo=i=>i.length!==0&&i!=="."&&i!=="..",Uo=/^\?+([^+@!?\*\[\(]*)?$/,$o=([i,e=""])=>{let t=nn([i]);return e?(e=e.toLowerCase(),s=>t(s)&&s.toLowerCase().endsWith(e)):t},Bo=([i,e=""])=>{let t=on([i]);return e?(e=e.toLowerCase(),s=>t(s)&&s.toLowerCase().endsWith(e)):t},zo=([i,e=""])=>{let t=on([i]);return e?s=>t(s)&&s.endsWith(e):t},jo=([i,e=""])=>{let t=nn([i]);return e?s=>t(s)&&s.endsWith(e):t},nn=([i])=>{let e=i.length;return t=>t.length===e&&!t.startsWith(".")},on=([i])=>{let e=i.length;return t=>t.length===e&&t!=="."&&t!==".."},an=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",ar={win32:{sep:"\\"},posix:{sep:"/"}},Wo=an==="win32"?ar.win32.sep:ar.posix.sep;de.sep=Wo;var ce=Symbol("globstar **");de.GLOBSTAR=ce;var Go="[^/]",qo=Go+"*?",Vo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Ho="(?:(?!(?:\\/|^)\\.).)*?",Ko=(i,e={})=>t=>de(t,i,e);de.filter=Ko;var Te=(i,e={})=>Object.assign({},i,e),Jo=i=>{if(!i||typeof i!="object"||!Object.keys(i).length)return de;let e=de;return Object.assign((t,s,r={})=>e(t,s,Te(i,r)),{Minimatch:class extends e.Minimatch{constructor(t,s={}){super(t,Te(i,s));}static defaults(t){return e.defaults(Te(i,t)).Minimatch}},AST:class extends e.AST{constructor(t,s,r={}){super(t,s,Te(i,r));}static fromGlob(t,s={}){return e.AST.fromGlob(t,Te(i,s))}},unescape:(t,s={})=>e.unescape(t,Te(i,s)),escape:(t,s={})=>e.escape(t,Te(i,s)),filter:(t,s={})=>e.filter(t,Te(i,s)),defaults:t=>e.defaults(Te(i,t)),makeRe:(t,s={})=>e.makeRe(t,Te(i,s)),braceExpand:(t,s={})=>e.braceExpand(t,Te(i,s)),match:(t,s,r={})=>e.match(t,s,Te(i,r)),sep:e.sep,GLOBSTAR:ce})};de.defaults=Jo;var ln=(i,e={})=>(hs(i),e.nobrace||!/\{(?:(?!\{).)*\}/.test(i)?[i]:co(i,{max:e.braceExpandMax}));de.braceExpand=ln;var Yo=(i,e={})=>new wt(i,e).makeRe();de.makeRe=Yo;var Zo=(i,e,t={})=>{let s=new wt(e,t);return i=i.filter(r=>s.match(r)),s.options.nonull&&!i.length&&i.push(e),i};de.match=Zo;var lr=/[?*]|[+@!]\(.*?\)|\[|\]/,Xo=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),wt=class{constructor(i,e={}){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");hs(i),e=e||{},this.options=e,this.pattern=i,this.platform=e.platform||an,this.isWindows=this.platform==="win32";let t="allowWindowsEscape";this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e[t]===false,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=false,this.nonegate=!!e.nonegate,this.comment=false,this.empty=false,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.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 e of i)if(typeof e!="string")return true;return false}debug(...i){}make(){let i=this.pattern,e=this.options;if(!e.nocomment&&i.charAt(0)==="#"){this.comment=true;return}if(!i){this.empty=true;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...r)=>console.error(...r)),this.debug(this.pattern,this.globSet);let t=this.globSet.map(r=>this.slashSplit(r));this.globParts=this.preprocess(t),this.debug(this.pattern,this.globParts);let s=this.globParts.map((r,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=r[0]===""&&r[1]===""&&(r[2]==="?"||!lr.test(r[2]))&&!lr.test(r[3]),l=/^[a-z]:/i.test(r[0]);if(h)return [...r.slice(0,4),...r.slice(4).map(d=>this.parse(d))];if(l)return [r[0],...r.slice(1).map(d=>this.parse(d))]}return r.map(h=>this.parse(h))});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 t=0;t<i.length;t++)for(let s=0;s<i[t].length;s++)i[t][s]==="**"&&(i[t][s]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(i=this.firstPhasePreProcess(i),i=this.secondPhasePreProcess(i)):e>=1?i=this.levelOneOptimize(i):i=this.adjascentGlobstarOptimize(i),i}adjascentGlobstarOptimize(i){return i.map(e=>{let t=-1;for(;(t=e.indexOf("**",t+1))!==-1;){let s=t;for(;e[s+1]==="**";)s++;s!==t&&e.splice(t,s-t);}return e})}levelOneOptimize(i){return i.map(e=>(e=e.reduce((t,s)=>{let r=t[t.length-1];return s==="**"&&r==="**"?t:s===".."&&r&&r!==".."&&r!=="."&&r!=="**"?(t.pop(),t):(t.push(s),t)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(i){Array.isArray(i)||(i=this.slashSplit(i));let e=false;do{if(e=false,!this.preserveMultipleSlashes){for(let s=1;s<i.length-1;s++){let r=i[s];s===1&&r===""&&i[0]===""||(r==="."||r==="")&&(e=true,i.splice(s,1),s--);}i[0]==="."&&i.length===2&&(i[1]==="."||i[1]==="")&&(e=true,i.pop());}let t=0;for(;(t=i.indexOf("..",t+1))!==-1;){let s=i[t-1];s&&s!=="."&&s!==".."&&s!=="**"&&(e=true,i.splice(t-1,2),t-=2);}}while(e);return i.length===0?[""]:i}firstPhasePreProcess(i){let e=false;do{e=false;for(let t of i){let s=-1;for(;(s=t.indexOf("**",s+1))!==-1;){let o=s;for(;t[o+1]==="**";)o++;o>s&&t.splice(s+1,o-s);let a=t[s+1],h=t[s+2],l=t[s+3];if(a!==".."||!h||h==="."||h===".."||!l||l==="."||l==="..")continue;e=true,t.splice(s,1);let d=t.slice(0);d[s]="**",i.push(d),s--;}if(!this.preserveMultipleSlashes){for(let o=1;o<t.length-1;o++){let a=t[o];o===1&&a===""&&t[0]===""||(a==="."||a==="")&&(e=true,t.splice(o,1),o--);}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=true,t.pop());}let r=0;for(;(r=t.indexOf("..",r+1))!==-1;){let o=t[r-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=true;let a=r===1&&t[r+1]==="**"?["."]:[];t.splice(r-1,2,...a),t.length===0&&t.push(""),r-=2;}}}}while(e);return i}secondPhasePreProcess(i){for(let e=0;e<i.length-1;e++)for(let t=e+1;t<i.length;t++){let s=this.partsMatch(i[e],i[t],!this.preserveMultipleSlashes);if(s){i[e]=[],i[t]=s;break}}return i.filter(e=>e.length)}partsMatch(i,e,t=false){let s=0,r=0,o=[],a="";for(;s<i.length&&r<e.length;)if(i[s]===e[r])o.push(a==="b"?e[r]:i[s]),s++,r++;else if(t&&i[s]==="**"&&e[r]===i[s+1])o.push(i[s]),s++;else if(t&&e[r]==="**"&&i[s]===e[r+1])o.push(e[r]),r++;else if(i[s]==="*"&&e[r]&&(this.options.dot||!e[r].startsWith("."))&&e[r]!=="**"){if(a==="b")return false;a="a",o.push(i[s]),s++,r++;}else if(e[r]==="*"&&i[s]&&(this.options.dot||!i[s].startsWith("."))&&i[s]!=="**"){if(a==="a")return false;a="b",o.push(e[r]),s++,r++;}else return false;return i.length===e.length&&o}parseNegate(){if(this.nonegate)return;let i=this.pattern,e=false,t=0;for(let s=0;s<i.length&&i.charAt(s)==="!";s++)e=!e,t++;t&&(this.pattern=i.slice(t)),this.negate=e;}matchOne(i,e,t=false){let s=this.options;if(this.isWindows){let b=typeof i[0]=="string"&&/^[a-z]:$/i.test(i[0]),S=!b&&i[0]===""&&i[1]===""&&i[2]==="?"&&/^[a-z]:$/i.test(i[3]),T=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),v=!T&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),k=S?3:b?0:void 0,C=v?3:T?0:void 0;if(typeof k=="number"&&typeof C=="number"){let[O,D]=[i[k],e[C]];O.toLowerCase()===D.toLowerCase()&&(e[C]=O,C>k?e=e.slice(C):k>C&&(i=i.slice(k)));}}let{optimizationLevel:r=1}=this.options;r>=2&&(i=this.levelTwoFileOptimize(i)),this.debug("matchOne",this,{file:i,pattern:e}),this.debug("matchOne",i.length,e.length);for(var o=0,a=0,h=i.length,l=e.length;o<h&&a<l;o++,a++){this.debug("matchOne loop");var d=e[a],g=i[o];if(this.debug(e,d,g),d===false)return false;if(d===ce){this.debug("GLOBSTAR",[e,d,g]);var p=o,u=a+1;if(u===l){for(this.debug("** at the end");o<h;o++)if(i[o]==="."||i[o]===".."||!s.dot&&i[o].charAt(0)===".")return false;return true}for(;p<h;){var m=i[p];if(this.debug(`
2
- globstar while`,i,p,e,u,m),this.matchOne(i.slice(p),e.slice(u),t))return this.debug("globstar found match!",p,h,m),true;if(m==="."||m===".."||!s.dot&&m.charAt(0)==="."){this.debug("dot detected!",i,p,e,u);break}this.debug("globstar swallow a segment, and continue"),p++;}return !!(t&&(this.debug(`
3
- >>> no match, partial?`,i,p,e,u),p===h))}let b;if(typeof d=="string"?(b=g===d,this.debug("string match",d,g,b)):(b=d.test(g),this.debug("pattern match",d,g,b)),!b)return false}if(o===h&&a===l)return true;if(o===h)return t;if(a===l)return o===h-1&&i[o]==="";throw new Error("wtf?")}braceExpand(){return ln(this.pattern,this.options)}parse(i){hs(i);let e=this.options;if(i==="**")return ce;if(i==="")return "";let t,s=null;(t=i.match(No))?s=e.dot?Fo:_o:(t=i.match(ko))?s=(e.nocase?e.dot?Co:Lo:e.dot?Ro:Mo)(t[1]):(t=i.match(Uo))?s=(e.nocase?e.dot?Bo:$o:e.dot?zo:jo)(t):(t=i.match(Oo))?s=e.dot?Do:Po:(t=i.match(Ao))&&(s=Io);let r=en.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 e=this.options,t=e.noglobstar?qo:e.dot?Vo:Ho,s=new Set(e.nocase?["i"]:[]),r=i.map(h=>{let l=h.map(g=>{if(g instanceof RegExp)for(let p of g.flags.split(""))s.add(p);return typeof g=="string"?Xo(g):g===ce?ce:g._src});l.forEach((g,p)=>{let u=l[p+1],m=l[p-1];g!==ce||m===ce||(m===void 0?u!==void 0&&u!==ce?l[p+1]="(?:\\/|"+t+"\\/)?"+u:l[p]=t:u===void 0?l[p-1]=m+"(?:\\/|\\/"+t+")?":u!==ce&&(l[p-1]=m+"(?:\\/|\\/"+t+"\\/)"+u,l[p+1]=ce));});let d=l.filter(g=>g!==ce);if(this.partial&&d.length>=1){let g=[];for(let p=1;p<=d.length;p++)g.push(d.slice(0,p).join("/"));return "(?:"+g.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,e=this.partial){if(this.debug("match",i,this.pattern),this.comment)return false;if(this.empty)return i==="";if(i==="/"&&e)return true;let t=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 h=r[a],l=s;if(t.matchBase&&h.length===1&&(l=[o]),this.matchOne(l,h,e))return t.flipNegate?true:!this.negate}return t.flipNegate?false:this.negate}static defaults(i){return de.defaults(i).Minimatch}};de.AST=en;de.Minimatch=wt;de.escape=rn;de.unescape=jt;var ea=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,hn=new Set,As=typeof process=="object"&&process?process:{},cn=(i,e,t,s)=>{typeof As.emitWarning=="function"?As.emitWarning(i,e,t,s):console.error(`[${t}] ${e}: ${i}`);},cs=globalThis.AbortController,hr=globalThis.AbortSignal;if(typeof cs>"u"){hr=class{constructor(){c(this,"onabort");c(this,"_onabort",[]);c(this,"reason");c(this,"aborted",false);}addEventListener(t,s){this._onabort.push(s);}},cs=class{constructor(){c(this,"signal",new hr);e();}abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let s of this.signal._onabort)s(t);this.signal.onabort?.(t);}}};let i=As.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{i&&(i=false,cn("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",e));};}var ta=i=>!hn.has(i),ot=i=>i&&i===Math.floor(i)&&i>0&&isFinite(i),dn=i=>ot(i)?i<=Math.pow(2,8)?Uint8Array:i<=Math.pow(2,16)?Uint16Array:i<=Math.pow(2,32)?Uint32Array:i<=Number.MAX_SAFE_INTEGER?is:null:null,is=class extends Array{constructor(i){super(i),this.fill(0);}},He,Wt,ia=(He=class{constructor(e,t){c(this,"heap");c(this,"length");if(!n(He,Wt))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}static create(e){let t=dn(e);if(!t)return [];f(He,Wt,true);let s=new He(e,t);return f(He,Wt,false),s}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Wt=new WeakMap,w(He,Wt,false),He),Tr,kr,Me,we,De,kt,Ae,Gt,qt,Ie,V,Ne,W,_,L,ae,be,re,Q,_e,ee,Fe,Ue,Se,ve,$e,ut,le,Vt,E,Is,Mt,Ze,yi,Ee,un,Rt,Ht,wi,at,lt,Ns,ss,rs,I,_s,ci,ht,Fs,Kt,ps=(Kt=class{constructor(e){w(this,E);w(this,Me);w(this,we);w(this,De);w(this,kt);w(this,Ae);w(this,Gt);w(this,qt);w(this,Ie);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,V);w(this,Ne);w(this,W);w(this,_);w(this,L);w(this,ae);w(this,be);w(this,re);w(this,Q);w(this,_e);w(this,ee);w(this,Fe);w(this,Ue);w(this,Se);w(this,ve);w(this,$e);w(this,ut);w(this,le);w(this,Vt);w(this,Mt,()=>{});w(this,Ze,()=>{});w(this,yi,()=>{});w(this,Ee,()=>false);w(this,Rt,e=>{});w(this,Ht,(e,t,s)=>{});w(this,wi,(e,t,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});c(this,Tr,"LRUCache");let{max:t=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:a,updateAgeOnHas:h,allowStale:l,dispose:d,onInsert:g,disposeAfter:p,noDisposeOnSet:u,noUpdateTTL:m,maxSize:b=0,maxEntrySize:S=0,sizeCalculation:T,fetchMethod:v,memoMethod:k,noDeleteOnFetchRejection:C,noDeleteOnStaleGet:O,allowStaleOnFetchRejection:D,allowStaleOnFetchAbort:P,ignoreFetchAbort:F,perf:U}=e;if(U!==void 0&&typeof U?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(f(this,Ie,U??ea),t!==0&&!ot(t))throw new TypeError("max option must be a nonnegative integer");let ie=t?dn(t):Array;if(!ie)throw new Error("invalid max value: "+t);if(f(this,Me,t),f(this,we,b),this.maxEntrySize=S||n(this,we),this.sizeCalculation=T,this.sizeCalculation){if(!n(this,we)&&!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(f(this,qt,k),v!==void 0&&typeof v!="function")throw new TypeError("fetchMethod must be a function if specified");if(f(this,Gt,v),f(this,ut,!!v),f(this,W,new Map),f(this,_,new Array(t).fill(void 0)),f(this,L,new Array(t).fill(void 0)),f(this,ae,new ie(t)),f(this,be,new ie(t)),f(this,re,0),f(this,Q,0),f(this,_e,ia.create(t)),f(this,V,0),f(this,Ne,0),typeof d=="function"&&f(this,De,d),typeof g=="function"&&f(this,kt,g),typeof p=="function"?(f(this,Ae,p),f(this,ee,[])):(f(this,Ae,void 0),f(this,ee,void 0)),f(this,$e,!!n(this,De)),f(this,Vt,!!n(this,kt)),f(this,le,!!n(this,Ae)),this.noDisposeOnSet=!!u,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!C,this.allowStaleOnFetchRejection=!!D,this.allowStaleOnFetchAbort=!!P,this.ignoreFetchAbort=!!F,this.maxEntrySize!==0){if(n(this,we)!==0&&!ot(n(this,we)))throw new TypeError("maxSize must be a positive integer if specified");if(!ot(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");y(this,E,un).call(this);}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!O,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!h,this.ttlResolution=ot(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!ot(this.ttl))throw new TypeError("ttl must be a positive integer if specified");y(this,E,Is).call(this);}if(n(this,Me)===0&&this.ttl===0&&n(this,we)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!n(this,Me)&&!n(this,we)){let A="LRU_CACHE_UNBOUNDED";ta(A)&&(hn.add(A),cn("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",A,Kt));}}get perf(){return n(this,Ie)}static unsafeExposeInternals(e){return {starts:n(e,Ue),ttls:n(e,Se),autopurgeTimers:n(e,ve),sizes:n(e,Fe),keyMap:n(e,W),keyList:n(e,_),valList:n(e,L),next:n(e,ae),prev:n(e,be),get head(){return n(e,re)},get tail(){return n(e,Q)},free:n(e,_e),isBackgroundFetch:t=>{var s;return y(s=e,E,I).call(s,t)},backgroundFetch:(t,s,r,o)=>{var a;return y(a=e,E,rs).call(a,t,s,r,o)},moveToTail:t=>{var s;return y(s=e,E,ci).call(s,t)},indexes:t=>{var s;return y(s=e,E,at).call(s,t)},rindexes:t=>{var s;return y(s=e,E,lt).call(s,t)},isStale:t=>{var s;return n(s=e,Ee).call(s,t)}}}get max(){return n(this,Me)}get maxSize(){return n(this,we)}get calculatedSize(){return n(this,Ne)}get size(){return n(this,V)}get fetchMethod(){return n(this,Gt)}get memoMethod(){return n(this,qt)}get dispose(){return n(this,De)}get onInsert(){return n(this,kt)}get disposeAfter(){return n(this,Ae)}getRemainingTTL(e){return n(this,W).has(e)?1/0:0}*entries(){for(let e of y(this,E,at).call(this))n(this,L)[e]!==void 0&&n(this,_)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield [n(this,_)[e],n(this,L)[e]]);}*rentries(){for(let e of y(this,E,lt).call(this))n(this,L)[e]!==void 0&&n(this,_)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield [n(this,_)[e],n(this,L)[e]]);}*keys(){for(let e of y(this,E,at).call(this)){let t=n(this,_)[e];t!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield t);}}*rkeys(){for(let e of y(this,E,lt).call(this)){let t=n(this,_)[e];t!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield t);}}*values(){for(let e of y(this,E,at).call(this))n(this,L)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield n(this,L)[e]);}*rvalues(){for(let e of y(this,E,lt).call(this))n(this,L)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield n(this,L)[e]);}[(kr=Symbol.iterator,Tr=Symbol.toStringTag,kr)](){return this.entries()}find(e,t={}){for(let s of y(this,E,at).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&e(o,n(this,_)[s],this))return this.get(n(this,_)[s],t)}}forEach(e,t=this){for(let s of y(this,E,at).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&e.call(t,o,n(this,_)[s],this);}}rforEach(e,t=this){for(let s of y(this,E,lt).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&e.call(t,o,n(this,_)[s],this);}}purgeStale(){let e=false;for(let t of y(this,E,lt).call(this,{allowStale:true}))n(this,Ee).call(this,t)&&(y(this,E,ht).call(this,n(this,_)[t],"expire"),e=true);return e}info(e){let t=n(this,W).get(e);if(t===void 0)return;let s=n(this,L)[t],r=y(this,E,I).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(n(this,Se)&&n(this,Ue)){let a=n(this,Se)[t],h=n(this,Ue)[t];if(a&&h){let l=a-(n(this,Ie).now()-h);o.ttl=l,o.start=Date.now();}}return n(this,Fe)&&(o.size=n(this,Fe)[t]),o}dump(){let e=[];for(let t of y(this,E,at).call(this,{allowStale:true})){let s=n(this,_)[t],r=n(this,L)[t],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let a={value:o};if(n(this,Se)&&n(this,Ue)){a.ttl=n(this,Se)[t];let h=n(this,Ie).now()-n(this,Ue)[t];a.start=Math.floor(Date.now()-h);}n(this,Fe)&&(a.size=n(this,Fe)[t]),e.unshift([s,a]);}return e}load(e){this.clear();for(let[t,s]of e){if(s.start){let r=Date.now()-s.start;s.start=n(this,Ie).now()-r;}this.set(t,s.value,s);}}set(e,t,s={}){var u,m,b,S;if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:o,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:l}=s,{noUpdateTTL:d=this.noUpdateTTL}=s,g=n(this,wi).call(this,e,t,s.size||0,h);if(this.maxEntrySize&&g>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=true),y(this,E,ht).call(this,e,"set"),this;let p=n(this,V)===0?void 0:n(this,W).get(e);if(p===void 0)p=n(this,V)===0?n(this,Q):n(this,_e).length!==0?n(this,_e).pop():n(this,V)===n(this,Me)?y(this,E,ss).call(this,false):n(this,V),n(this,_)[p]=e,n(this,L)[p]=t,n(this,W).set(e,p),n(this,ae)[n(this,Q)]=p,n(this,be)[p]=n(this,Q),f(this,Q,p),qi(this,V)._++,n(this,Ht).call(this,p,g,l),l&&(l.set="add"),d=false,n(this,Vt)&&((u=n(this,kt))==null||u.call(this,t,e,"add"));else {y(this,E,ci).call(this,p);let T=n(this,L)[p];if(t!==T){if(n(this,ut)&&y(this,E,I).call(this,T)){T.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:v}=T;v!==void 0&&!a&&(n(this,$e)&&((m=n(this,De))==null||m.call(this,v,e,"set")),n(this,le)&&n(this,ee)?.push([v,e,"set"]));}else a||(n(this,$e)&&((b=n(this,De))==null||b.call(this,T,e,"set")),n(this,le)&&n(this,ee)?.push([T,e,"set"]));if(n(this,Rt).call(this,p),n(this,Ht).call(this,p,g,l),n(this,L)[p]=t,l){l.set="replace";let v=T&&y(this,E,I).call(this,T)?T.__staleWhileFetching:T;v!==void 0&&(l.oldValue=v);}}else l&&(l.set="update");n(this,Vt)&&this.onInsert?.(t,e,t===T?"update":"replace");}if(r!==0&&!n(this,Se)&&y(this,E,Is).call(this),n(this,Se)&&(d||n(this,yi).call(this,p,r,o),l&&n(this,Ze).call(this,l,p)),!a&&n(this,le)&&n(this,ee)){let T=n(this,ee),v;for(;v=T?.shift();)(S=n(this,Ae))==null||S.call(this,...v);}return this}pop(){var e;try{for(;n(this,V);){let t=n(this,L)[n(this,re)];if(y(this,E,ss).call(this,!0),y(this,E,I).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(n(this,le)&&n(this,ee)){let t=n(this,ee),s;for(;s=t?.shift();)(e=n(this,Ae))==null||e.call(this,...s);}}}has(e,t={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=t,o=n(this,W).get(e);if(o!==void 0){let a=n(this,L)[o];if(y(this,E,I).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(n(this,Ee).call(this,o))r&&(r.has="stale",n(this,Ze).call(this,r,o));else return s&&n(this,Mt).call(this,o),r&&(r.has="hit",n(this,Ze).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(e,t={}){let{allowStale:s=this.allowStale}=t,r=n(this,W).get(e);if(r===void 0||!s&&n(this,Ee).call(this,r))return;let o=n(this,L)[r];return y(this,E,I).call(this,o)?o.__staleWhileFetching:o}async fetch(e,t={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:l=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:g=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:m=this.ignoreFetchAbort,allowStaleOnFetchAbort:b=this.allowStaleOnFetchAbort,context:S,forceRefresh:T=false,status:v,signal:k}=t;if(!n(this,ut))return v&&(v.fetch="get"),this.get(e,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:v});let C={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:a,noDisposeOnSet:h,size:l,sizeCalculation:d,noUpdateTTL:g,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:b,ignoreFetchAbort:m,status:v,signal:k},O=n(this,W).get(e);if(O===void 0){v&&(v.fetch="miss");let D=y(this,E,rs).call(this,e,O,C,S);return D.__returned=D}else {let D=n(this,L)[O];if(y(this,E,I).call(this,D)){let ie=s&&D.__staleWhileFetching!==void 0;return v&&(v.fetch="inflight",ie&&(v.returnedStale=true)),ie?D.__staleWhileFetching:D.__returned=D}let P=n(this,Ee).call(this,O);if(!T&&!P)return v&&(v.fetch="hit"),y(this,E,ci).call(this,O),r&&n(this,Mt).call(this,O),v&&n(this,Ze).call(this,v,O),D;let F=y(this,E,rs).call(this,e,O,C,S),U=F.__staleWhileFetching!==void 0&&s;return v&&(v.fetch=P?"stale":"refresh",U&&P&&(v.returnedStale=true)),U?F.__staleWhileFetching:F.__returned=F}}async forceFetch(e,t={}){let s=await this.fetch(e,t);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(e,t={}){let s=n(this,qt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:o,...a}=t,h=this.get(e,a);if(!o&&h!==void 0)return h;let l=s(e,h,{options:a,context:r});return this.set(e,l,a),l}get(e,t={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:a}=t,h=n(this,W).get(e);if(h!==void 0){let l=n(this,L)[h],d=y(this,E,I).call(this,l);return a&&n(this,Ze).call(this,a,h),n(this,Ee).call(this,h)?(a&&(a.get="stale"),d?(a&&s&&l.__staleWhileFetching!==void 0&&(a.returnedStale=true),s?l.__staleWhileFetching:void 0):(o||y(this,E,ht).call(this,e,"expire"),a&&s&&(a.returnedStale=true),s?l:void 0)):(a&&(a.get="hit"),d?l.__staleWhileFetching:(y(this,E,ci).call(this,h),r&&n(this,Mt).call(this,h),l))}else a&&(a.get="miss");}delete(e){return y(this,E,ht).call(this,e,"delete")}clear(){return y(this,E,Fs).call(this,"delete")}},Me=new WeakMap,we=new WeakMap,De=new WeakMap,kt=new WeakMap,Ae=new WeakMap,Gt=new WeakMap,qt=new WeakMap,Ie=new WeakMap,V=new WeakMap,Ne=new WeakMap,W=new WeakMap,_=new WeakMap,L=new WeakMap,ae=new WeakMap,be=new WeakMap,re=new WeakMap,Q=new WeakMap,_e=new WeakMap,ee=new WeakMap,Fe=new WeakMap,Ue=new WeakMap,Se=new WeakMap,ve=new WeakMap,$e=new WeakMap,ut=new WeakMap,le=new WeakMap,Vt=new WeakMap,E=new WeakSet,Is=function(){let e=new is(n(this,Me)),t=new is(n(this,Me));f(this,Se,e),f(this,Ue,t);let s=this.ttlAutopurge?new Array(n(this,Me)):void 0;f(this,ve,s),f(this,yi,(a,h,l=n(this,Ie).now())=>{if(t[a]=h!==0?l:0,e[a]=h,s?.[a]&&(clearTimeout(s[a]),s[a]=void 0),h!==0&&s){let d=setTimeout(()=>{n(this,Ee).call(this,a)&&y(this,E,ht).call(this,n(this,_)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}),f(this,Mt,a=>{t[a]=e[a]!==0?n(this,Ie).now():0;}),f(this,Ze,(a,h)=>{if(e[h]){let l=e[h],d=t[h];if(!l||!d)return;a.ttl=l,a.start=d,a.now=r||o();let g=a.now-d;a.remainingTTL=l-g;}});let r=0,o=()=>{let a=n(this,Ie).now();if(this.ttlResolution>0){r=a;let h=setTimeout(()=>r=0,this.ttlResolution);h.unref&&h.unref();}return a};this.getRemainingTTL=a=>{let h=n(this,W).get(a);if(h===void 0)return 0;let l=e[h],d=t[h];if(!l||!d)return 1/0;let g=(r||o())-d;return l-g},f(this,Ee,a=>{let h=t[a],l=e[a];return !!l&&!!h&&(r||o())-h>l});},Mt=new WeakMap,Ze=new WeakMap,yi=new WeakMap,Ee=new WeakMap,un=function(){let e=new is(n(this,Me));f(this,Ne,0),f(this,Fe,e),f(this,Rt,t=>{f(this,Ne,n(this,Ne)-e[t]),e[t]=0;}),f(this,wi,(t,s,r,o)=>{if(y(this,E,I).call(this,s))return 0;if(!ot(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,t),!ot(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}),f(this,Ht,(t,s,r)=>{if(e[t]=s,n(this,we)){let o=n(this,we)-e[t];for(;n(this,Ne)>o;)y(this,E,ss).call(this,true);}f(this,Ne,n(this,Ne)+e[t]),r&&(r.entrySize=s,r.totalCalculatedSize=n(this,Ne));});},Rt=new WeakMap,Ht=new WeakMap,wi=new WeakMap,at=function*({allowStale:e=this.allowStale}={}){if(n(this,V))for(let t=n(this,Q);!(!y(this,E,Ns).call(this,t)||((e||!n(this,Ee).call(this,t))&&(yield t),t===n(this,re)));)t=n(this,be)[t];},lt=function*({allowStale:e=this.allowStale}={}){if(n(this,V))for(let t=n(this,re);!(!y(this,E,Ns).call(this,t)||((e||!n(this,Ee).call(this,t))&&(yield t),t===n(this,Q)));)t=n(this,ae)[t];},Ns=function(e){return e!==void 0&&n(this,W).get(n(this,_)[e])===e},ss=function(e){var o;let t=n(this,re),s=n(this,_)[t],r=n(this,L)[t];return n(this,ut)&&y(this,E,I).call(this,r)?r.__abortController.abort(new Error("evicted")):(n(this,$e)||n(this,le))&&(n(this,$e)&&((o=n(this,De))==null||o.call(this,r,s,"evict")),n(this,le)&&n(this,ee)?.push([r,s,"evict"])),n(this,Rt).call(this,t),n(this,ve)?.[t]&&(clearTimeout(n(this,ve)[t]),n(this,ve)[t]=void 0),e&&(n(this,_)[t]=void 0,n(this,L)[t]=void 0,n(this,_e).push(t)),n(this,V)===1?(f(this,re,f(this,Q,0)),n(this,_e).length=0):f(this,re,n(this,ae)[t]),n(this,W).delete(s),qi(this,V)._--,t},rs=function(e,t,s,r){let o=t===void 0?void 0:n(this,L)[t];if(y(this,E,I).call(this,o))return o;let a=new cs,{signal:h}=s;h?.addEventListener("abort",()=>a.abort(h.reason),{signal:a.signal});let l={signal:a.signal,options:s,context:r},d=(S,T=false)=>{let{aborted:v}=a.signal,k=s.ignoreFetchAbort&&S!==void 0,C=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&S!==void 0);if(s.status&&(v&&!T?(s.status.fetchAborted=true,s.status.fetchError=a.signal.reason,k&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),v&&!k&&!T)return p(a.signal.reason,C);let O=m,D=n(this,L)[t];return (D===m||k&&T&&D===void 0)&&(S===void 0?O.__staleWhileFetching!==void 0?n(this,L)[t]=O.__staleWhileFetching:y(this,E,ht).call(this,e,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e,S,l.options))),S},g=S=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=S),p(S,false)),p=(S,T)=>{let{aborted:v}=a.signal,k=v&&s.allowStaleOnFetchAbort,C=k||s.allowStaleOnFetchRejection,O=C||s.noDeleteOnFetchRejection,D=m;if(n(this,L)[t]===m&&(!O||!T&&D.__staleWhileFetching===void 0?y(this,E,ht).call(this,e,"fetch"):k||(n(this,L)[t]=D.__staleWhileFetching)),C)return s.status&&D.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),D.__staleWhileFetching;if(D.__returned===D)throw S},u=(S,T)=>{var k;let v=(k=n(this,Gt))==null?void 0:k.call(this,e,o,l);v&&v instanceof Promise&&v.then(C=>S(C===void 0?void 0:C),T),a.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(S(void 0),s.allowStaleOnFetchAbort&&(S=C=>d(C,true)));});};s.status&&(s.status.fetchDispatched=true);let m=new Promise(u).then(d,g),b=Object.assign(m,{__abortController:a,__staleWhileFetching:o,__returned:void 0});return t===void 0?(this.set(e,b,{...l.options,status:void 0}),t=n(this,W).get(e)):n(this,L)[t]=b,b},I=function(e){if(!n(this,ut))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof cs},_s=function(e,t){n(this,be)[t]=e,n(this,ae)[e]=t;},ci=function(e){e!==n(this,Q)&&(e===n(this,re)?f(this,re,n(this,ae)[e]):y(this,E,_s).call(this,n(this,be)[e],n(this,ae)[e]),y(this,E,_s).call(this,n(this,Q),e),f(this,Q,e));},ht=function(e,t){var r,o;let s=false;if(n(this,V)!==0){let a=n(this,W).get(e);if(a!==void 0)if(n(this,ve)?.[a]&&(clearTimeout(n(this,ve)?.[a]),n(this,ve)[a]=void 0),s=true,n(this,V)===1)y(this,E,Fs).call(this,t);else {n(this,Rt).call(this,a);let h=n(this,L)[a];if(y(this,E,I).call(this,h)?h.__abortController.abort(new Error("deleted")):(n(this,$e)||n(this,le))&&(n(this,$e)&&((r=n(this,De))==null||r.call(this,h,e,t)),n(this,le)&&n(this,ee)?.push([h,e,t])),n(this,W).delete(e),n(this,_)[a]=void 0,n(this,L)[a]=void 0,a===n(this,Q))f(this,Q,n(this,be)[a]);else if(a===n(this,re))f(this,re,n(this,ae)[a]);else {let l=n(this,be)[a];n(this,ae)[l]=n(this,ae)[a];let d=n(this,ae)[a];n(this,be)[d]=n(this,be)[a];}qi(this,V)._--,n(this,_e).push(a);}}if(n(this,le)&&n(this,ee)?.length){let a=n(this,ee),h;for(;h=a?.shift();)(o=n(this,Ae))==null||o.call(this,...h);}return s},Fs=function(e){var t,s;for(let r of y(this,E,lt).call(this,{allowStale:true})){let o=n(this,L)[r];if(y(this,E,I).call(this,o))o.__abortController.abort(new Error("deleted"));else {let a=n(this,_)[r];n(this,$e)&&((t=n(this,De))==null||t.call(this,o,a,e)),n(this,le)&&n(this,ee)?.push([o,a,e]);}}if(n(this,W).clear(),n(this,L).fill(void 0),n(this,_).fill(void 0),n(this,Se)&&n(this,Ue)){n(this,Se).fill(0),n(this,Ue).fill(0);for(let r of n(this,ve)??[])r!==void 0&&clearTimeout(r);n(this,ve)?.fill(void 0);}if(n(this,Fe)&&n(this,Fe).fill(0),f(this,re,0),f(this,Q,0),n(this,_e).length=0,f(this,Ne,0),f(this,V,0),n(this,le)&&n(this,ee)){let r=n(this,ee),o;for(;o=r?.shift();)(s=n(this,Ae))==null||s.call(this,...o);}},Kt),cr=typeof process=="object"&&process?process:{stdout:null,stderr:null},ma=i=>!!i&&typeof i=="object"&&(i instanceof ds||i instanceof pn__default.default||ya(i)||wa(i)),ya=i=>!!i&&typeof i=="object"&&i instanceof events.EventEmitter&&typeof i.pipe=="function"&&i.pipe!==pn__default.default.Writable.prototype.pipe,wa=i=>!!i&&typeof i=="object"&&i instanceof events.EventEmitter&&typeof i.write=="function"&&typeof i.end=="function",Ke=Symbol("EOF"),Je=Symbol("maybeEmitEnd"),nt=Symbol("emittedEnd"),Ki=Symbol("emittingEnd"),ri=Symbol("emittedError"),Ji=Symbol("closed"),dr=Symbol("read"),Yi=Symbol("flush"),ur=Symbol("flushChunk"),Oe=Symbol("encoding"),Bt=Symbol("decoder"),J=Symbol("flowing"),ni=Symbol("paused"),zt=Symbol("resume"),Y=Symbol("buffer"),oe=Symbol("pipes"),Z=Symbol("bufferLength"),ks=Symbol("bufferPush"),Zi=Symbol("bufferShift"),se=Symbol("objectMode"),B=Symbol("destroyed"),Ms=Symbol("error"),Rs=Symbol("emitData"),pr=Symbol("emitEnd"),Ls=Symbol("emitEnd2"),je=Symbol("async"),Cs=Symbol("abort"),Xi=Symbol("aborted"),oi=Symbol("signal"),St=Symbol("dataListeners"),ye=Symbol("discarded"),ai=i=>Promise.resolve().then(i),ba=i=>i(),Sa=i=>i==="end"||i==="finish"||i==="prefinish",va=i=>i instanceof ArrayBuffer||!!i&&typeof i=="object"&&i.constructor&&i.constructor.name==="ArrayBuffer"&&i.byteLength>=0,Ea=i=>!Buffer.isBuffer(i)&&ArrayBuffer.isView(i),fn=class{constructor(i,e,t){c(this,"src");c(this,"dest");c(this,"opts");c(this,"ondrain");this.src=i,this.dest=e,this.opts=t,this.ondrain=()=>i[zt](),this.dest.on("drain",this.ondrain);}unpipe(){this.dest.removeListener("drain",this.ondrain);}proxyErrors(i){}end(){this.unpipe(),this.opts.end&&this.dest.end();}},xa=class extends fn{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe();}constructor(i,e,t){super(i,e,t),this.proxyErrors=s=>this.dest.emit("error",s),i.on("error",this.proxyErrors);}},Ta=i=>!!i.objectMode,ka=i=>!i.objectMode&&!!i.encoding&&i.encoding!=="buffer",Mr,Rr,Lr,Cr,Or,Pr,Dr,Ar,Ir,Nr,_r,Fr,Ur,$r,Br,zr,jr,Wr,Gr,ds=class extends events.EventEmitter{constructor(...e){let t=e[0]||{};super();c(this,Gr,false);c(this,Wr,false);c(this,jr,[]);c(this,zr,[]);c(this,Br);c(this,$r);c(this,Ur);c(this,Fr);c(this,_r,false);c(this,Nr,false);c(this,Ir,false);c(this,Ar,false);c(this,Dr,null);c(this,Pr,0);c(this,Or,false);c(this,Cr);c(this,Lr,false);c(this,Rr,0);c(this,Mr,false);c(this,"writable",true);c(this,"readable",true);if(t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Ta(t)?(this[se]=true,this[Oe]=null):ka(t)?(this[Oe]=t.encoding,this[se]=false):(this[se]=false,this[Oe]=null),this[je]=!!t.async,this[Bt]=this[Oe]?new string_decoder.StringDecoder(this[Oe]):null,t&&t.debugExposeBuffer===true&&Object.defineProperty(this,"buffer",{get:()=>this[Y]}),t&&t.debugExposePipes===true&&Object.defineProperty(this,"pipes",{get:()=>this[oe]});let{signal:s}=t;s&&(this[oi]=s,s.aborted?this[Cs]():s.addEventListener("abort",()=>this[Cs]()));}get bufferLength(){return this[Z]}get encoding(){return this[Oe]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[se]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[je]}set async(e){this[je]=this[je]||!!e;}[(Gr=J,Wr=ni,jr=oe,zr=Y,Br=se,$r=Oe,Ur=je,Fr=Bt,_r=Ke,Nr=nt,Ir=Ki,Ar=Ji,Dr=ri,Pr=Z,Or=B,Cr=oi,Lr=Xi,Rr=St,Mr=ye,Cs)](){this[Xi]=true,this.emit("abort",this[oi]?.reason),this.destroy(this[oi]?.reason);}get aborted(){return this[Xi]}set aborted(e){}write(e,t,s){if(this[Xi])return false;if(this[Ke])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 t=="function"&&(s=t,t="utf8"),t||(t="utf8");let r=this[je]?ai:ba;if(!this[se]&&!Buffer.isBuffer(e)){if(Ea(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(va(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[se]?(this[J]&&this[Z]!==0&&this[Yi](true),this[J]?this.emit("data",e):this[ks](e),this[Z]!==0&&this.emit("readable"),s&&r(s),this[J]):e.length?(typeof e=="string"&&!(t===this[Oe]&&!this[Bt]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[Oe]&&(e=this[Bt].write(e)),this[J]&&this[Z]!==0&&this[Yi](true),this[J]?this.emit("data",e):this[ks](e),this[Z]!==0&&this.emit("readable"),s&&r(s),this[J]):(this[Z]!==0&&this.emit("readable"),s&&r(s),this[J])}read(e){if(this[B])return null;if(this[ye]=false,this[Z]===0||e===0||e&&e>this[Z])return this[Je](),null;this[se]&&(e=null),this[Y].length>1&&!this[se]&&(this[Y]=[this[Oe]?this[Y].join(""):Buffer.concat(this[Y],this[Z])]);let t=this[dr](e||null,this[Y][0]);return this[Je](),t}[dr](e,t){if(this[se])this[Zi]();else {let s=t;e===s.length||e===null?this[Zi]():typeof s=="string"?(this[Y][0]=s.slice(e),t=s.slice(0,e),this[Z]-=e):(this[Y][0]=s.subarray(e),t=s.subarray(0,e),this[Z]-=e);}return this.emit("data",t),!this[Y].length&&!this[Ke]&&this.emit("drain"),t}end(e,t,s){return typeof e=="function"&&(s=e,e=void 0),typeof t=="function"&&(s=t,t="utf8"),e!==void 0&&this.write(e,t),s&&this.once("end",s),this[Ke]=true,this.writable=false,(this[J]||!this[ni])&&this[Je](),this}[zt](){this[B]||(!this[St]&&!this[oe].length&&(this[ye]=true),this[ni]=false,this[J]=true,this.emit("resume"),this[Y].length?this[Yi]():this[Ke]?this[Je]():this.emit("drain"));}resume(){return this[zt]()}pause(){this[J]=false,this[ni]=true,this[ye]=false;}get destroyed(){return this[B]}get flowing(){return this[J]}get paused(){return this[ni]}[ks](e){this[se]?this[Z]+=1:this[Z]+=e.length,this[Y].push(e);}[Zi](){return this[se]?this[Z]-=1:this[Z]-=this[Y][0].length,this[Y].shift()}[Yi](e=false){do;while(this[ur](this[Zi]())&&this[Y].length);!e&&!this[Y].length&&!this[Ke]&&this.emit("drain");}[ur](e){return this.emit("data",e),this[J]}pipe(e,t){if(this[B])return e;this[ye]=false;let s=this[nt];return t=t||{},e===cr.stdout||e===cr.stderr?t.end=false:t.end=t.end!==false,t.proxyErrors=!!t.proxyErrors,s?t.end&&e.end():(this[oe].push(t.proxyErrors?new xa(this,e,t):new fn(this,e,t)),this[je]?ai(()=>this[zt]()):this[zt]()),e}unpipe(e){let t=this[oe].find(s=>s.dest===e);t&&(this[oe].length===1?(this[J]&&this[St]===0&&(this[J]=false),this[oe]=[]):this[oe].splice(this[oe].indexOf(t),1),t.unpipe());}addListener(e,t){return this.on(e,t)}on(e,t){let s=super.on(e,t);if(e==="data")this[ye]=false,this[St]++,!this[oe].length&&!this[J]&&this[zt]();else if(e==="readable"&&this[Z]!==0)super.emit("readable");else if(Sa(e)&&this[nt])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[ri]){let r=t;this[je]?ai(()=>r.call(this,this[ri])):r.call(this,this[ri]);}return s}removeListener(e,t){return this.off(e,t)}off(e,t){let s=super.off(e,t);return e==="data"&&(this[St]=this.listeners("data").length,this[St]===0&&!this[ye]&&!this[oe].length&&(this[J]=false)),s}removeAllListeners(e){let t=super.removeAllListeners(e);return (e==="data"||e===void 0)&&(this[St]=0,!this[ye]&&!this[oe].length&&(this[J]=false)),t}get emittedEnd(){return this[nt]}[Je](){!this[Ki]&&!this[nt]&&!this[B]&&this[Y].length===0&&this[Ke]&&(this[Ki]=true,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Ji]&&this.emit("close"),this[Ki]=false);}emit(e,...t){let s=t[0];if(e!=="error"&&e!=="close"&&e!==B&&this[B])return false;if(e==="data")return !this[se]&&!s?false:this[je]?(ai(()=>this[Rs](s)),true):this[Rs](s);if(e==="end")return this[pr]();if(e==="close"){if(this[Ji]=true,!this[nt]&&!this[B])return false;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[ri]=s,super.emit(Ms,s);let o=!this[oi]||this.listeners("error").length?super.emit("error",s):false;return this[Je](),o}else if(e==="resume"){let o=super.emit("resume");return this[Je](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...t);return this[Je](),r}[Rs](e){for(let s of this[oe])s.dest.write(e)===false&&this.pause();let t=this[ye]?false:super.emit("data",e);return this[Je](),t}[pr](){return this[nt]?false:(this[nt]=true,this.readable=false,this[je]?(ai(()=>this[Ls]()),true):this[Ls]())}[Ls](){if(this[Bt]){let t=this[Bt].end();if(t){for(let s of this[oe])s.dest.write(t);this[ye]||super.emit("data",t);}}for(let t of this[oe])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[se]||(e.dataLength=0);let t=this.promise();return this.on("data",s=>{e.push(s),this[se]||(e.dataLength+=s.length);}),await t,e}async concat(){if(this[se])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[Oe]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(B,()=>t(new Error("stream destroyed"))),this.on("error",s=>t(s)),this.on("end",()=>e());})}[Symbol.asyncIterator](){this[ye]=false;let e=false,t=async()=>(this.pause(),e=true,{value:void 0,done:true});return {next:()=>{if(e)return t();let s=this.read();if(s!==null)return Promise.resolve({done:false,value:s});if(this[Ke])return t();let r,o,a=g=>{this.off("data",h),this.off("end",l),this.off(B,d),t(),o(g);},h=g=>{this.off("error",a),this.off("end",l),this.off(B,d),this.pause(),r({value:g,done:!!this[Ke]});},l=()=>{this.off("error",a),this.off("data",h),this.off(B,d),t(),r({done:true,value:void 0});},d=()=>a(new Error("stream destroyed"));return new Promise((g,p)=>{o=p,r=g,this.once(B,d),this.once("error",a),this.once("end",l),this.once("data",h);})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ye]=false;let e=false,t=()=>(this.pause(),this.off(Ms,t),this.off(B,t),this.off("end",t),e=true,{done:true,value:void 0}),s=()=>{if(e)return t();let r=this.read();return r===null?t():{done:false,value:r}};return this.once("end",t),this.once(Ms,t),this.once(B,t),{next:s,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[B])return e?this.emit("error",e):this.emit(B),this;this[B]=true,this[ye]=true,this[Y].length=0,this[Z]=0;let t=this;return typeof t.close=="function"&&!this[Ji]&&t.close(),e?this.emit("error",e):this.emit(B),this}static get isStream(){return ma}},Ma=z.realpathSync.native,di={lstatSync:z.lstatSync,readdir:z.readdir,readdirSync:z.readdirSync,readlinkSync:z.readlinkSync,realpathSync:Ma,promises:{lstat:Bn.lstat,readdir:Bn.readdir,readlink:Bn.readlink,realpath:Bn.realpath}},gn=i=>!i||i===di||i===z__namespace?di:{...di,...i,promises:{...di.promises,...i.promises||{}}},mn=/^\\\\\?\\([a-z]:)\\?$/i,Ra=i=>i.replace(/\//g,"\\").replace(mn,"$1\\"),La=/[\\\/]/,Re=0,yn=1,wn=2,We=4,bn=6,Sn=8,vt=10,vn=12,ke=15,li=~ke,Os=16,fr=32,ui=64,Pe=128,Qi=256,ns=512,gr=ui|Pe|ns,Ca=1023,Ps=i=>i.isFile()?Sn:i.isDirectory()?We:i.isSymbolicLink()?vt:i.isCharacterDevice()?wn:i.isBlockDevice()?bn:i.isSocket()?vn:i.isFIFO()?yn:Re,mr=new ps({max:2**12}),pi=i=>{let e=mr.get(i);if(e)return e;let t=i.normalize("NFKD");return mr.set(i,t),t},yr=new ps({max:2**12}),es=i=>{let e=yr.get(i);if(e)return e;let t=pi(i.toLowerCase());return yr.set(i,t),t},wr=class extends ps{constructor(){super({max:256});}},Oa=class extends ps{constructor(i=16*1024){super({maxSize:i,sizeCalculation:e=>e.length+1});}},En=Symbol("PathScurry setAsCwd"),he,bi,Si,vi,Ei,xi,Ti,ki,Mi,Ri,Li,Ci,Oi,Pi,Di,Ai,Ii,Ni,_i,pt,Lt,qe,Xe,Qe,et,R,Ct,tt,Ve,M,$s,os,fi,Bs,zs,gi,as,js,Ws,ls,xn,Tn,kn,Gs,Jt,Yt,Mn,Ot,qr,pe=(qr=class{constructor(i,e=Re,t,s,r,o,a){w(this,M);c(this,"name");c(this,"root");c(this,"roots");c(this,"parent");c(this,"nocase");c(this,"isCWD",false);w(this,he);w(this,bi);w(this,Si);w(this,vi);w(this,Ei);w(this,xi);w(this,Ti);w(this,ki);w(this,Mi);w(this,Ri);w(this,Li);w(this,Ci);w(this,Oi);w(this,Pi);w(this,Di);w(this,Ai);w(this,Ii);w(this,Ni);w(this,_i);w(this,pt);w(this,Lt);w(this,qe);w(this,Xe);w(this,Qe);w(this,et);w(this,R);w(this,Ct);w(this,tt);w(this,Ve);w(this,Jt,[]);w(this,Yt,false);w(this,Ot);this.name=i,f(this,pt,r?es(i):pi(i)),f(this,R,e&Ca),this.nocase=r,this.roots=s,this.root=t||this,f(this,Ct,o),f(this,qe,a.fullpath),f(this,Qe,a.relative),f(this,et,a.relativePosix),this.parent=a.parent,this.parent?f(this,he,n(this.parent,he)):f(this,he,gn(a.fs));}get dev(){return n(this,bi)}get mode(){return n(this,Si)}get nlink(){return n(this,vi)}get uid(){return n(this,Ei)}get gid(){return n(this,xi)}get rdev(){return n(this,Ti)}get blksize(){return n(this,ki)}get ino(){return n(this,Mi)}get size(){return n(this,Ri)}get blocks(){return n(this,Li)}get atimeMs(){return n(this,Ci)}get mtimeMs(){return n(this,Oi)}get ctimeMs(){return n(this,Pi)}get birthtimeMs(){return n(this,Di)}get atime(){return n(this,Ai)}get mtime(){return n(this,Ii)}get ctime(){return n(this,Ni)}get birthtime(){return n(this,_i)}get parentPath(){return (this.parent||this).fullpath()}get path(){return this.parentPath}depth(){return n(this,Lt)!==void 0?n(this,Lt):this.parent?f(this,Lt,this.parent.depth()+1):f(this,Lt,0)}childrenCache(){return n(this,Ct)}resolve(i){var s;if(!i)return this;let e=this.getRootString(i),t=i.substring(e.length).split(this.splitSep);return e?y(s=this.getRoot(e),M,$s).call(s,t):y(this,M,$s).call(this,t)}children(){let i=n(this,Ct).get(this);if(i)return i;let e=Object.assign([],{provisional:0});return n(this,Ct).set(this,e),f(this,R,n(this,R)&~Os),e}child(i,e){if(i===""||i===".")return this;if(i==="..")return this.parent||this;let t=this.children(),s=this.nocase?es(i):pi(i);for(let h of t)if(n(h,pt)===s)return h;let r=this.parent?this.sep:"",o=n(this,qe)?n(this,qe)+r+i:void 0,a=this.newChild(i,Re,{...e,parent:this,fullpath:o});return this.canReaddir()||f(a,R,n(a,R)|Pe),t.push(a),a}relative(){if(this.isCWD)return "";if(n(this,Qe)!==void 0)return n(this,Qe);let i=this.name,e=this.parent;if(!e)return f(this,Qe,this.name);let t=e.relative();return t+(!t||!e.parent?"":this.sep)+i}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return "";if(n(this,et)!==void 0)return n(this,et);let i=this.name,e=this.parent;if(!e)return f(this,et,this.fullpathPosix());let t=e.relativePosix();return t+(!t||!e.parent?"":"/")+i}fullpath(){if(n(this,qe)!==void 0)return n(this,qe);let i=this.name,e=this.parent;if(!e)return f(this,qe,this.name);let t=e.fullpath()+(e.parent?this.sep:"")+i;return f(this,qe,t)}fullpathPosix(){if(n(this,Xe)!==void 0)return n(this,Xe);if(this.sep==="/")return f(this,Xe,this.fullpath());if(!this.parent){let s=this.fullpath().replace(/\\/g,"/");return /^[a-z]:\//i.test(s)?f(this,Xe,`//?/${s}`):f(this,Xe,s)}let i=this.parent,e=i.fullpathPosix(),t=e+(!e||!i.parent?"":"/")+this.name;return f(this,Xe,t)}isUnknown(){return (n(this,R)&ke)===Re}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,R)&ke)===Sn}isDirectory(){return (n(this,R)&ke)===We}isCharacterDevice(){return (n(this,R)&ke)===wn}isBlockDevice(){return (n(this,R)&ke)===bn}isFIFO(){return (n(this,R)&ke)===yn}isSocket(){return (n(this,R)&ke)===vn}isSymbolicLink(){return (n(this,R)&vt)===vt}lstatCached(){return n(this,R)&fr?this:void 0}readlinkCached(){return n(this,tt)}realpathCached(){return n(this,Ve)}readdirCached(){let i=this.children();return i.slice(0,i.provisional)}canReadlink(){if(n(this,tt))return true;if(!this.parent)return false;let i=n(this,R)&ke;return !(i!==Re&&i!==vt||n(this,R)&Qi||n(this,R)&Pe)}calledReaddir(){return !!(n(this,R)&Os)}isENOENT(){return !!(n(this,R)&Pe)}isNamed(i){return this.nocase?n(this,pt)===es(i):n(this,pt)===pi(i)}async readlink(){let i=n(this,tt);if(i)return i;if(this.canReadlink()&&this.parent)try{let e=await n(this,he).promises.readlink(this.fullpath()),t=(await this.parent.realpath())?.resolve(e);if(t)return f(this,tt,t)}catch(e){y(this,M,Ws).call(this,e.code);return}}readlinkSync(){let i=n(this,tt);if(i)return i;if(this.canReadlink()&&this.parent)try{let e=n(this,he).readlinkSync(this.fullpath()),t=this.parent.realpathSync()?.resolve(e);if(t)return f(this,tt,t)}catch(e){y(this,M,Ws).call(this,e.code);return}}async lstat(){if((n(this,R)&Pe)===0)try{return y(this,M,Gs).call(this,await n(this,he).promises.lstat(this.fullpath())),this}catch(i){y(this,M,js).call(this,i.code);}}lstatSync(){if((n(this,R)&Pe)===0)try{return y(this,M,Gs).call(this,n(this,he).lstatSync(this.fullpath())),this}catch(i){y(this,M,js).call(this,i.code);}}readdirCB(i,e=false){if(!this.canReaddir()){e?i(null,[]):queueMicrotask(()=>i(null,[]));return}let t=this.children();if(this.calledReaddir()){let r=t.slice(0,t.provisional);e?i(null,r):queueMicrotask(()=>i(null,r));return}if(n(this,Jt).push(i),n(this,Yt))return;f(this,Yt,true);let s=this.fullpath();n(this,he).readdir(s,{withFileTypes:true},(r,o)=>{if(r)y(this,M,as).call(this,r.code),t.provisional=0;else {for(let a of o)y(this,M,ls).call(this,a,t);y(this,M,os).call(this,t);}y(this,M,Mn).call(this,t.slice(0,t.provisional));});}async readdir(){if(!this.canReaddir())return [];let i=this.children();if(this.calledReaddir())return i.slice(0,i.provisional);let e=this.fullpath();if(n(this,Ot))await n(this,Ot);else {let t=()=>{};f(this,Ot,new Promise(s=>t=s));try{for(let s of await n(this,he).promises.readdir(e,{withFileTypes:!0}))y(this,M,ls).call(this,s,i);y(this,M,os).call(this,i);}catch(s){y(this,M,as).call(this,s.code),i.provisional=0;}f(this,Ot,void 0),t();}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 e=this.fullpath();try{for(let t of n(this,he).readdirSync(e,{withFileTypes:!0}))y(this,M,ls).call(this,t,i);y(this,M,os).call(this,i);}catch(t){y(this,M,as).call(this,t.code),i.provisional=0;}return i.slice(0,i.provisional)}canReaddir(){if(n(this,R)&gr)return false;let i=ke&n(this,R);return i===Re||i===We||i===vt}shouldWalk(i,e){return (n(this,R)&We)===We&&!(n(this,R)&gr)&&!i.has(this)&&(!e||e(this))}async realpath(){if(n(this,Ve))return n(this,Ve);if(!((ns|Qi|Pe)&n(this,R)))try{let i=await n(this,he).promises.realpath(this.fullpath());return f(this,Ve,this.resolve(i))}catch{y(this,M,zs).call(this);}}realpathSync(){if(n(this,Ve))return n(this,Ve);if(!((ns|Qi|Pe)&n(this,R)))try{let i=n(this,he).realpathSync(this.fullpath());return f(this,Ve,this.resolve(i))}catch{y(this,M,zs).call(this);}}[En](i){if(i===this)return;i.isCWD=false,this.isCWD=true;let e=new Set([]),t=[],s=this;for(;s&&s.parent;)e.add(s),f(s,Qe,t.join(this.sep)),f(s,et,t.join("/")),s=s.parent,t.push("..");for(s=i;s&&s.parent&&!e.has(s);)f(s,Qe,void 0),f(s,et,void 0),s=s.parent;}},he=new WeakMap,bi=new WeakMap,Si=new WeakMap,vi=new WeakMap,Ei=new WeakMap,xi=new WeakMap,Ti=new WeakMap,ki=new WeakMap,Mi=new WeakMap,Ri=new WeakMap,Li=new WeakMap,Ci=new WeakMap,Oi=new WeakMap,Pi=new WeakMap,Di=new WeakMap,Ai=new WeakMap,Ii=new WeakMap,Ni=new WeakMap,_i=new WeakMap,pt=new WeakMap,Lt=new WeakMap,qe=new WeakMap,Xe=new WeakMap,Qe=new WeakMap,et=new WeakMap,R=new WeakMap,Ct=new WeakMap,tt=new WeakMap,Ve=new WeakMap,M=new WeakSet,$s=function(i){let e=this;for(let t of i)e=e.child(t);return e},os=function(i){var e;f(this,R,n(this,R)|Os);for(let t=i.provisional;t<i.length;t++){let s=i[t];s&&y(e=s,M,fi).call(e);}},fi=function(){n(this,R)&Pe||(f(this,R,(n(this,R)|Pe)&li),y(this,M,Bs).call(this));},Bs=function(){var e;let i=this.children();i.provisional=0;for(let t of i)y(e=t,M,fi).call(e);},zs=function(){f(this,R,n(this,R)|ns),y(this,M,gi).call(this);},gi=function(){if(n(this,R)&ui)return;let i=n(this,R);(i&ke)===We&&(i&=li),f(this,R,i|ui),y(this,M,Bs).call(this);},as=function(i=""){i==="ENOTDIR"||i==="EPERM"?y(this,M,gi).call(this):i==="ENOENT"?y(this,M,fi).call(this):this.children().provisional=0;},js=function(i=""){var e;i==="ENOTDIR"?y(e=this.parent,M,gi).call(e):i==="ENOENT"&&y(this,M,fi).call(this);},Ws=function(i=""){var t;let e=n(this,R);e|=Qi,i==="ENOENT"&&(e|=Pe),(i==="EINVAL"||i==="UNKNOWN")&&(e&=li),f(this,R,e),i==="ENOTDIR"&&this.parent&&y(t=this.parent,M,gi).call(t);},ls=function(i,e){return y(this,M,Tn).call(this,i,e)||y(this,M,xn).call(this,i,e)},xn=function(i,e){let t=Ps(i),s=this.newChild(i.name,t,{parent:this}),r=n(s,R)&ke;return r!==We&&r!==vt&&r!==Re&&f(s,R,n(s,R)|ui),e.unshift(s),e.provisional++,s},Tn=function(i,e){for(let t=e.provisional;t<e.length;t++){let s=e[t];if((this.nocase?es(i.name):pi(i.name))===n(s,pt))return y(this,M,kn).call(this,i,s,t,e)}},kn=function(i,e,t,s){let r=e.name;return f(e,R,n(e,R)&li|Ps(i)),r!==i.name&&(e.name=i.name),t!==s.provisional&&(t===s.length-1?s.pop():s.splice(t,1),s.unshift(e)),s.provisional++,e},Gs=function(i){let{atime:e,atimeMs:t,birthtime:s,birthtimeMs:r,blksize:o,blocks:a,ctime:h,ctimeMs:l,dev:d,gid:g,ino:p,mode:u,mtime:m,mtimeMs:b,nlink:S,rdev:T,size:v,uid:k}=i;f(this,Ai,e),f(this,Ci,t),f(this,_i,s),f(this,Di,r),f(this,ki,o),f(this,Li,a),f(this,Ni,h),f(this,Pi,l),f(this,bi,d),f(this,xi,g),f(this,Mi,p),f(this,Si,u),f(this,Ii,m),f(this,Oi,b),f(this,vi,S),f(this,Ti,T),f(this,Ri,v),f(this,Ei,k);let C=Ps(i);f(this,R,n(this,R)&li|C|fr),C!==Re&&C!==We&&C!==vt&&f(this,R,n(this,R)|ui);},Jt=new WeakMap,Yt=new WeakMap,Mn=function(i){f(this,Yt,false);let e=n(this,Jt).slice();n(this,Jt).length=0,e.forEach(t=>t(null,i));},Ot=new WeakMap,qr),Rn=class Ln extends pe{constructor(t,s=Re,r,o,a,h,l){super(t,s,r,o,a,h,l);c(this,"sep","\\");c(this,"splitSep",La);}newChild(t,s=Re,r={}){return new Ln(t,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}getRootString(t){return ii.win32.parse(t).root}getRoot(t){if(t=Ra(t.toUpperCase()),t===this.root.name)return this.root;for(let[s,r]of Object.entries(this.roots))if(this.sameRoot(t,s))return this.roots[t]=r;return this.roots[t]=new Js(t,this).root}sameRoot(t,s=this.root.name){return t=t.toUpperCase().replace(/\//g,"\\").replace(mn,"$1\\"),t===s}},Cn=class On extends pe{constructor(t,s=Re,r,o,a,h,l){super(t,s,r,o,a,h,l);c(this,"splitSep","/");c(this,"sep","/");}getRootString(t){return t.startsWith("/")?"/":""}getRoot(t){return this.root}newChild(t,s=Re,r={}){return new On(t,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}},Zt,Xt,Fi,Ui,Vr,Pn=(Vr=class{constructor(i=process.cwd(),e,t,{nocase:s,childrenCacheSize:r=16*1024,fs:o=di}={}){c(this,"root");c(this,"rootPath");c(this,"roots");c(this,"cwd");w(this,Zt);w(this,Xt);w(this,Fi);c(this,"nocase");w(this,Ui);f(this,Ui,gn(o)),(i instanceof URL||i.startsWith("file://"))&&(i=url.fileURLToPath(i));let a=e.resolve(i);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),f(this,Zt,new wr),f(this,Xt,new wr),f(this,Fi,new Oa(r));let h=a.substring(this.rootPath.length).split(t);if(h.length===1&&!h[0]&&h.pop(),s===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=s,this.root=this.newRoot(n(this,Ui)),this.roots[this.rootPath]=this.root;let l=this.root,d=h.length-1,g=e.sep,p=this.rootPath,u=false;for(let m of h){let b=d--;l=l.child(m,{relative:new Array(b).fill("..").join(g),relativePosix:new Array(b).fill("..").join("/"),fullpath:p+=(u?"":g)+m}),u=true;}this.cwd=l;}depth(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.depth()}childrenCache(){return n(this,Fi)}resolve(...i){let e="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(e=e?`${o}/${e}`:o,this.isAbsolute(o)))break}let t=n(this,Zt).get(e);if(t!==void 0)return t;let s=this.cwd.resolve(e).fullpath();return n(this,Zt).set(e,s),s}resolvePosix(...i){let e="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(e=e?`${o}/${e}`:o,this.isAbsolute(o)))break}let t=n(this,Xt).get(e);if(t!==void 0)return t;let s=this.cwd.resolve(e).fullpathPosix();return n(this,Xt).set(e,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,e={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t}=e;if(i.canReaddir()){let s=await i.readdir();return t?s:s.map(r=>r.name)}else return []}readdirSync(i=this.cwd,e={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true}=e;return i.canReaddir()?t?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:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=await i.readlink();return e?t:t?.fullpath()}readlinkSync(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=i.readlinkSync();return e?t:t?.fullpath()}async realpath(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=await i.realpath();return e?t:t?.fullpath()}realpathSync(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=i.realpathSync();return e?t:t?.fullpath()}async walk(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=[];(!r||r(i))&&a.push(t?i:i.fullpath());let h=new Set,l=(g,p)=>{h.add(g),g.readdirCB((u,m)=>{if(u)return p(u);let b=m.length;if(!b)return p();let S=()=>{--b===0&&p();};for(let T of m)(!r||r(T))&&a.push(t?T:T.fullpath()),s&&T.isSymbolicLink()?T.realpath().then(v=>v?.isUnknown()?v.lstat():v).then(v=>v?.shouldWalk(h,o)?l(v,S):S()):T.shouldWalk(h,o)?l(T,S):S();},true);},d=i;return new Promise((g,p)=>{l(d,u=>{if(u)return p(u);g(a);});})}walkSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=[];(!r||r(i))&&a.push(t?i:i.fullpath());let h=new Set([i]);for(let l of h){let d=l.readdirSync();for(let g of d){(!r||r(g))&&a.push(t?g:g.fullpath());let p=g;if(g.isSymbolicLink()){if(!(s&&(p=g.realpathSync())))continue;p.isUnknown()&&p.lstatSync();}p.shouldWalk(h,o)&&h.add(p);}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(i=this.cwd,e={}){return typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd),this.stream(i,e)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e;(!r||r(i))&&(yield t?i:i.fullpath());let a=new Set([i]);for(let h of a){let l=h.readdirSync();for(let d of l){(!r||r(d))&&(yield t?d:d.fullpath());let g=d;if(d.isSymbolicLink()){if(!(s&&(g=d.realpathSync())))continue;g.isUnknown()&&g.lstatSync();}g.shouldWalk(a,o)&&a.add(g);}}}stream(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=new ds({objectMode:true});(!r||r(i))&&a.write(t?i:i.fullpath());let h=new Set,l=[i],d=0,g=()=>{let p=false;for(;!p;){let u=l.shift();if(!u){d===0&&a.end();return}d++,h.add(u);let m=(S,T,v=false)=>{if(S)return a.emit("error",S);if(s&&!v){let k=[];for(let C of T)C.isSymbolicLink()&&k.push(C.realpath().then(O=>O?.isUnknown()?O.lstat():O));if(k.length){Promise.all(k).then(()=>m(null,T,true));return}}for(let k of T)k&&(!r||r(k))&&(a.write(t?k:k.fullpath())||(p=true));d--;for(let k of T){let C=k.realpathCached()||k;C.shouldWalk(h,o)&&l.push(C);}p&&!a.flowing?a.once("drain",g):b||g();},b=true;u.readdirCB(m,true),b=false;}};return g(),a}streamSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=new ds({objectMode:true}),h=new Set;(!r||r(i))&&a.write(t?i:i.fullpath());let l=[i],d=0,g=()=>{let p=false;for(;!p;){let u=l.shift();if(!u){d===0&&a.end();return}d++,h.add(u);let m=u.readdirSync();for(let b of m)(!r||r(b))&&(a.write(t?b:b.fullpath())||(p=true));d--;for(let b of m){let S=b;if(b.isSymbolicLink()){if(!(s&&(S=b.realpathSync())))continue;S.isUnknown()&&S.lstatSync();}S.shouldWalk(h,o)&&l.push(S);}}p&&!a.flowing&&a.once("drain",g);};return g(),a}chdir(i=this.cwd){let e=this.cwd;this.cwd=typeof i=="string"?this.cwd.resolve(i):i,this.cwd[En](e);}},Zt=new WeakMap,Xt=new WeakMap,Fi=new WeakMap,Ui=new WeakMap,Vr),Js=class extends Pn{constructor(e=process.cwd(),t={}){let{nocase:s=true}=t;super(e,ii.win32,"\\",{...t,nocase:s});c(this,"sep","\\");this.nocase=s;for(let r=this.cwd;r;r=r.parent)r.nocase=this.nocase;}parseRootPath(e){return ii.win32.parse(e).root.toUpperCase()}newRoot(e){return new Rn(this.rootPath,We,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")||e.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(e)}},Ys=class extends Pn{constructor(e=process.cwd(),t={}){let{nocase:s=false}=t;super(e,ii.posix,"/",{...t,nocase:s});c(this,"sep","/");this.nocase=s;}parseRootPath(e){return "/"}newRoot(e){return new Cn(this.rootPath,We,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")}},Dn=class extends Ys{constructor(i=process.cwd(),e={}){let{nocase:t=true}=e;super(i,{...e,nocase:t});}};process.platform==="win32"?Rn:Cn;var Pa=process.platform==="win32"?Js:process.platform==="darwin"?Dn:Ys,Da=i=>i.length>=1,Aa=i=>i.length>=1,Ia=Symbol.for("nodejs.util.inspect.custom"),H,fe,K,Pt,Be,$i,ft,gt,mt,Qt,ei,An=(ei=class{constructor(e,t,s,r){w(this,H);w(this,fe);w(this,K);c(this,"length");w(this,Pt);w(this,Be);w(this,$i);w(this,ft);w(this,gt);w(this,mt);w(this,Qt,true);if(!Da(e))throw new TypeError("empty pattern list");if(!Aa(t))throw new TypeError("empty glob list");if(t.length!==e.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=e.length,s<0||s>=this.length)throw new TypeError("index out of range");if(f(this,H,e),f(this,fe,t),f(this,K,s),f(this,Pt,r),n(this,K)===0){if(this.isUNC()){let[o,a,h,l,...d]=n(this,H),[g,p,u,m,...b]=n(this,fe);d[0]===""&&(d.shift(),b.shift());let S=[o,a,h,l,""].join("/"),T=[g,p,u,m,""].join("/");f(this,H,[S,...d]),f(this,fe,[T,...b]),this.length=n(this,H).length;}else if(this.isDrive()||this.isAbsolute()){let[o,...a]=n(this,H),[h,...l]=n(this,fe);a[0]===""&&(a.shift(),l.shift());let d=o+"/",g=h+"/";f(this,H,[d,...a]),f(this,fe,[g,...l]),this.length=n(this,H).length;}}}[Ia](){return "Pattern <"+n(this,fe).slice(n(this,K)).join("/")+">"}pattern(){return n(this,H)[n(this,K)]}isString(){return typeof n(this,H)[n(this,K)]=="string"}isGlobstar(){return n(this,H)[n(this,K)]===ce}isRegExp(){return n(this,H)[n(this,K)]instanceof RegExp}globString(){return f(this,$i,n(this,$i)||(n(this,K)===0?this.isAbsolute()?n(this,fe)[0]+n(this,fe).slice(1).join("/"):n(this,fe).join("/"):n(this,fe).slice(n(this,K)).join("/")))}hasMore(){return this.length>n(this,K)+1}rest(){return n(this,Be)!==void 0?n(this,Be):this.hasMore()?(f(this,Be,new ei(n(this,H),n(this,fe),n(this,K)+1,n(this,Pt))),f(n(this,Be),mt,n(this,mt)),f(n(this,Be),gt,n(this,gt)),f(n(this,Be),ft,n(this,ft)),n(this,Be)):f(this,Be,null)}isUNC(){let e=n(this,H);return n(this,gt)!==void 0?n(this,gt):f(this,gt,n(this,Pt)==="win32"&&n(this,K)===0&&e[0]===""&&e[1]===""&&typeof e[2]=="string"&&!!e[2]&&typeof e[3]=="string"&&!!e[3])}isDrive(){let e=n(this,H);return n(this,ft)!==void 0?n(this,ft):f(this,ft,n(this,Pt)==="win32"&&n(this,K)===0&&this.length>1&&typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]))}isAbsolute(){let e=n(this,H);return n(this,mt)!==void 0?n(this,mt):f(this,mt,e[0]===""&&e.length>1||this.isDrive()||this.isUNC())}root(){let e=n(this,H)[0];return typeof e=="string"&&this.isAbsolute()&&n(this,K)===0?e:""}checkFollowGlobstar(){return !(n(this,K)===0||!this.isGlobstar()||!n(this,Qt))}markFollowGlobstar(){return n(this,K)===0||!this.isGlobstar()||!n(this,Qt)?false:(f(this,Qt,false),true)}},H=new WeakMap,fe=new WeakMap,K=new WeakMap,Pt=new WeakMap,Be=new WeakMap,$i=new WeakMap,ft=new WeakMap,gt=new WeakMap,mt=new WeakMap,Qt=new WeakMap,ei),Na=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",br=class{constructor(i,{nobrace:e,nocase:t,noext:s,noglobstar:r,platform:o=Na}){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:e,nocase:t,noext:s,noglobstar:r,optimizationLevel:2,platform:o,nocomment:true,nonegate:true};for(let a of i)this.add(a);}add(i){let e=new wt(i,this.mmopts);for(let t=0;t<e.set.length;t++){let s=e.set[t],r=e.globParts[t];if(!s||!r)throw new Error("invalid pattern object");for(;s[0]==="."&&r[0]===".";)s.shift(),r.shift();let o=new An(s,r,0,this.platform),a=new wt(o.globString(),this.mmopts),h=r[r.length-1]==="**",l=o.isAbsolute();l?this.absolute.push(a):this.relative.push(a),h&&(l?this.absoluteChildren.push(a):this.relativeChildren.push(a));}}ignored(i){let e=i.fullpath(),t=`${e}/`,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(e)||o.match(t))return true;return false}childrenIgnored(i){let e=i.fullpath()+"/",t=(i.relative()||".")+"/";for(let s of this.relativeChildren)if(s.match(t))return true;for(let s of this.absoluteChildren)if(s.match(e))return true;return false}},_a=class In{constructor(e=new Map){c(this,"store");this.store=e;}copy(){return new In(new Map(this.store))}hasWalked(e,t){return this.store.get(e.fullpath())?.has(t.globString())}storeWalked(e,t){let s=e.fullpath(),r=this.store.get(s);r?r.add(t.globString()):this.store.set(s,new Set([t.globString()]));}},Fa=class{constructor(){c(this,"store",new Map);}add(i,e,t){let s=(e?2:0)|(t?1:0),r=this.store.get(i);this.store.set(i,r===void 0?s:s&r);}entries(){return [...this.store.entries()].map(([i,e])=>[i,!!(e&2),!!(e&1)])}},Ua=class{constructor(){c(this,"store",new Map);}add(i,e){if(!i.canReaddir())return;let t=this.store.get(i);t?t.find(s=>s.globString()===e.globString())||t.push(e):this.store.set(i,[e]);}get(i){let e=this.store.get(i);if(!e)throw new Error("attempting to walk unknown path");return e}entries(){return this.keys().map(i=>[i,this.store.get(i)])}keys(){return [...this.store.keys()].filter(i=>i.canReaddir())}},Sr=class Nn{constructor(e,t){c(this,"hasWalkedCache");c(this,"matches",new Fa);c(this,"subwalks",new Ua);c(this,"patterns");c(this,"follow");c(this,"dot");c(this,"opts");this.opts=e,this.follow=!!e.follow,this.dot=!!e.dot,this.hasWalkedCache=t?t.copy():new _a;}processPatterns(e,t){this.patterns=t;let s=t.map(r=>[e,r]);for(let[r,o]of s){this.hasWalkedCache.storeWalked(r,o);let a=o.root(),h=o.isAbsolute()&&this.opts.absolute!==false;if(a){r=r.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let p=o.rest();if(p)o=p;else {this.matches.add(r,true,false);continue}}if(r.isENOENT())continue;let l,d,g=false;for(;typeof(l=o.pattern())=="string"&&(d=o.rest());)r=r.resolve(l),o=d,g=true;if(l=o.pattern(),d=o.rest(),g){if(this.hasWalkedCache.hasWalked(r,o))continue;this.hasWalkedCache.storeWalked(r,o);}if(typeof l=="string"){let p=l===".."||l===""||l===".";this.matches.add(r.resolve(l),h,p);continue}else if(l===ce){(!r.isSymbolicLink()||this.follow||o.checkFollowGlobstar())&&this.subwalks.add(r,o);let p=d?.pattern(),u=d?.rest();if(!d||(p===""||p===".")&&!u)this.matches.add(r,h,p===""||p===".");else if(p===".."){let m=r.parent||r;u?this.hasWalkedCache.hasWalked(m,u)||this.subwalks.add(m,u):this.matches.add(m,h,true);}}else l instanceof RegExp&&this.subwalks.add(r,o);}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new Nn(this.opts,this.hasWalkedCache)}filterEntries(e,t){let s=this.subwalks.get(e),r=this.child();for(let o of t)for(let a of s){let h=a.isAbsolute(),l=a.pattern(),d=a.rest();l===ce?r.testGlobstar(o,a,d,h):l instanceof RegExp?r.testRegExp(o,l,d,h):r.testString(o,l,d,h);}return r}testGlobstar(e,t,s,r){if((this.dot||!e.name.startsWith("."))&&(t.hasMore()||this.matches.add(e,r,false),e.canReaddir()&&(this.follow||!e.isSymbolicLink()?this.subwalks.add(e,t):e.isSymbolicLink()&&(s&&t.checkFollowGlobstar()?this.subwalks.add(e,s):t.markFollowGlobstar()&&this.subwalks.add(e,t)))),s){let o=s.pattern();if(typeof o=="string"&&o!==".."&&o!==""&&o!==".")this.testString(e,o,s.rest(),r);else if(o===".."){let a=e.parent||e;this.subwalks.add(a,s);}else o instanceof RegExp&&this.testRegExp(e,o,s.rest(),r);}}testRegExp(e,t,s,r){t.test(e.name)&&(s?this.subwalks.add(e,s):this.matches.add(e,r,false));}testString(e,t,s,r){e.isNamed(t)&&(s?this.subwalks.add(e,s):this.matches.add(e,r,false));}},$a=(i,e)=>typeof i=="string"?new br([i],e):Array.isArray(i)?new br(i,e):i,ti,it,Dt,Le,Et,qs,Hr,_n=(Hr=class{constructor(i,e,t){w(this,Le);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,it);w(this,Dt);c(this,"signal");c(this,"maxDepth");c(this,"includeChildMatches");if(this.patterns=i,this.path=e,this.opts=t,f(this,Dt,!t.posix&&t.platform==="win32"?"\\":"/"),this.includeChildMatches=t.includeChildMatches!==false,(t.ignore||!this.includeChildMatches)&&(f(this,it,$a(t.ignore??[],t)),!this.includeChildMatches&&typeof n(this,it).add!="function")){let s="cannot ignore child matches, ignore lacks add() method.";throw new Error(s)}this.maxDepth=t.maxDepth||1/0,t.signal&&(this.signal=t.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,e){if(e&&this.opts.nodir)return;let t;if(this.opts.realpath){if(t=i.realpathCached()||await i.realpath(),!t)return;i=t;}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,e)}matchCheckTest(i,e){return i&&(this.maxDepth===1/0||i.depth()<=this.maxDepth)&&(!e||i.canReaddir())&&(!this.opts.nodir||!i.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!i.isSymbolicLink()||!i.realpathCached()?.isDirectory())&&!y(this,Le,Et).call(this,i)?i:void 0}matchCheckSync(i,e){if(e&&this.opts.nodir)return;let t;if(this.opts.realpath){if(t=i.realpathCached()||i.realpathSync(),!t)return;i=t;}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,e)}matchFinish(i,e){if(y(this,Le,Et).call(this,i))return;if(!this.includeChildMatches&&n(this,it)?.add){let r=`${i.relativePosix()}/**`;n(this,it).add(r);}let t=this.opts.absolute===void 0?e:this.opts.absolute;this.seen.add(i);let s=this.opts.mark&&i.isDirectory()?n(this,Dt):"";if(this.opts.withFileTypes)this.matchEmit(i);else if(t){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,Dt))?"."+n(this,Dt):"";this.matchEmit(r?o+r+s:"."+s);}}async match(i,e,t){let s=await this.matchCheck(i,t);s&&this.matchFinish(s,e);}matchSync(i,e,t){let s=this.matchCheckSync(i,t);s&&this.matchFinish(s,e);}walkCB(i,e,t){this.signal?.aborted&&t(),this.walkCB2(i,e,new Sr(this.opts),t);}walkCB2(i,e,t,s){if(y(this,Le,qs).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2(i,e,t,s));return}t.processPatterns(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,Et).call(this,a)||(r++,this.match(a,h,l).then(()=>o()));for(let a of t.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let h=a.readdirCached();a.calledReaddir()?this.walkCB3(a,h,t,o):a.readdirCB((l,d)=>this.walkCB3(a,d,t,o),true);}o();}walkCB3(i,e,t,s){t=t.filterEntries(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,Et).call(this,a)||(r++,this.match(a,h,l).then(()=>o()));for(let[a,h]of t.subwalks.entries())r++,this.walkCB2(a,h,t.child(),o);o();}walkCBSync(i,e,t){this.signal?.aborted&&t(),this.walkCB2Sync(i,e,new Sr(this.opts),t);}walkCB2Sync(i,e,t,s){if(y(this,Le,qs).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2Sync(i,e,t,s));return}t.processPatterns(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,Et).call(this,a)||this.matchSync(a,h,l);for(let a of t.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let h=a.readdirSync();this.walkCB3Sync(a,h,t,o);}o();}walkCB3Sync(i,e,t,s){t=t.filterEntries(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,Et).call(this,a)||this.matchSync(a,h,l);for(let[a,h]of t.subwalks.entries())r++,this.walkCB2Sync(a,h,t.child(),o);o();}},ti=new WeakMap,it=new WeakMap,Dt=new WeakMap,Le=new WeakSet,Et=function(i){return this.seen.has(i)||!!n(this,it)?.ignored?.(i)},qs=function(i){return !!n(this,it)?.childrenIgnored?.(i)},Hr),vr=class extends _n{constructor(e,t,s){super(e,t,s);c(this,"matches",new Set);}matchEmit(e){this.matches.add(e);}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((e,t)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?t(this.signal.reason):e(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}},Er=class extends _n{constructor(e,t,s){super(e,t,s);c(this,"results");this.results=new ds({signal:this.signal,objectMode:true}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume());}matchEmit(e){this.results.write(e),this.results.flowing||this.pause();}stream(){let e=this.path;return e.isUnknown()?e.lstat().then(()=>{this.walkCB(e,this.patterns,()=>this.results.end());}):this.walkCB(e,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}},Ba=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",It=class{constructor(i,e){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(!e)throw new TypeError("glob options required");if(this.withFileTypes=!!e.withFileTypes,this.signal=e.signal,this.follow=!!e.follow,this.dot=!!e.dot,this.dotRelative=!!e.dotRelative,this.nodir=!!e.nodir,this.mark=!!e.mark,e.cwd?(e.cwd instanceof URL||e.cwd.startsWith("file://"))&&(e.cwd=url.fileURLToPath(e.cwd)):this.cwd="",this.cwd=e.cwd||"",this.root=e.root,this.magicalBraces=!!e.magicalBraces,this.nobrace=!!e.nobrace,this.noext=!!e.noext,this.realpath=!!e.realpath,this.absolute=e.absolute,this.includeChildMatches=e.includeChildMatches!==false,this.noglobstar=!!e.noglobstar,this.matchBase=!!e.matchBase,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:1/0,this.stat=!!e.stat,this.ignore=e.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");if(typeof i=="string"&&(i=[i]),this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===false,this.windowsPathsNoEscape&&(i=i.map(h=>h.replace(/\\/g,"/"))),this.matchBase){if(e.noglobstar)throw new TypeError("base matching requires globstar");i=i.map(h=>h.includes("/")?h:`./**/${h}`);}if(this.pattern=i,this.platform=e.platform||Ba,this.opts={...e,platform:this.platform},e.scurry){if(this.scurry=e.scurry,e.nocase!==void 0&&e.nocase!==e.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else {let h=e.platform==="win32"?Js:e.platform==="darwin"?Dn:e.platform?Ys:Pa;this.scurry=new h(this.cwd,{nocase:e.nocase,fs:e.fs});}this.nocase=this.scurry.nocase;let t=this.platform==="darwin"||this.platform==="win32",s={braceExpandMax:1e4,...e,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:t,nocomment:true,noext:this.noext,nonegate:true,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape,debug:!!this.opts.debug},r=this.pattern.map(h=>new wt(h,s)),[o,a]=r.reduce((h,l)=>(h[0].push(...l.set),h[1].push(...l.globParts),h),[[],[]]);this.patterns=o.map((h,l)=>{let d=a[l];if(!d)throw new Error("invalid pattern object");return new An(h,d,0,this.platform)});}async walk(){return [...await new vr(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 vr(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 Er(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 Er(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()}},za=(i,e={})=>{Array.isArray(i)||(i=[i]);for(let t of i)if(new wt(t,e).hasMagic())return true;return false};function fs(i,e={}){return new It(i,e).streamSync()}function Fn(i,e={}){return new It(i,e).stream()}function Un(i,e={}){return new It(i,e).walkSync()}async function xr(i,e={}){return new It(i,e).walk()}function gs(i,e={}){return new It(i,e).iterateSync()}function $n(i,e={}){return new It(i,e).iterate()}var ja=fs,Wa=Object.assign(Fn,{sync:fs}),Ga=gs,qa=Object.assign($n,{sync:gs}),Va=Object.assign(Un,{stream:fs,iterate:gs}),us=Object.assign(xr,{glob:xr,globSync:Un,sync:Va,globStream:Fn,stream:Wa,globStreamSync:fs,streamSync:ja,globIterate:$n,iterate:qa,globIterateSync:gs,iterateSync:Ga,Glob:It,hasMagic:za,escape:rn,unescape:jt});us.glob=us;var Ce;(D=>{D.Level=Ka__default.default.enum(["DEBUG","INFO","WARN","ERROR"]).meta({ref:"LogLevel",description:"Log level"});let e={DEBUG:0,INFO:1,WARN:2,ERROR:3},t="INFO";function s(P){return e[P]>=e[t]}function r(){return t}D.getLevel=r;let o=new Map;D.Default=O({service:"default"});let h="";function l(){return h}D.file=l;let d,g,p=false,u=()=>{},m=false,b=false;async function S(P){if(p)return;if(P.print){p=true;return}P.level&&(t=P.level);let F=P.logDir||ii__namespace.default.join(process.env.EASBOT_LOG_PATH??process.cwd(),"logs");P.logFile?h=ii__namespace.default.join(F,P.logFile??"local-model-sdk.log"):h=ii__namespace.default.join(F,"local-model-sdk.log");try{await Bn__default.default.mkdir(F,{recursive:!0}),d=await Bn__default.default.open(h,"a"),g=z.createWriteStream("",{fd:d.fd,autoClose:!1}),u=U=>{if(!(m||b||!g||g.destroyed))try{if(!g.writable)return;g.write(U,ie=>{if(ie&&!m){let A=ie;if(A.code==="EPIPE"||A.code==="EIO"){b=!0,g?.destroy();return}m=!0,setTimeout(()=>{m=!1;},1e3);}});}catch(ie){let A=ie;if(A.code==="EPIPE"||A.code==="EIO"){b=!0,g?.destroy();return}m||(m=!0,setTimeout(()=>{m=!1;},1e3));}},p=!0;}catch{u=U=>{try{process.stderr.write(U);}catch{}},p=true;}}D.init=S;async function T(){p&&(g&&!g.destroyed&&(await new Promise((P,F)=>{g.end(U=>{U?F(U):P();});}).catch(()=>{}),g=void 0),d&&(await d.close().catch(()=>{}),d=void 0),u=P=>{try{process.stderr.write(P);}catch{}},p=false);}D.close=T;function k(P,F=0){let U=P.message;return P.cause instanceof Error&&F<10?U+" Caused by: "+k(P.cause,F+1):U}let C=Date.now();function O(P){P=P||{};let F=P.service;if(F&&typeof F=="string"){let A=o.get(F);if(A)return A}function U(A,ue){let vs=Object.entries({...P,...ue}).filter(([Qs,rt])=>rt!=null).map(([Qs,rt])=>{let Es=`${Qs}=`;return rt instanceof Error?Es+k(rt):typeof rt=="object"?Es+JSON.stringify(rt):Es+rt}).join(" "),Ut=new Date,Vn=Ut.getTime()-C;return C=Ut.getTime(),[utils.formatLogTime(Ut),"+"+Vn+"ms",vs,A].filter(Boolean).join(" ")+`
4
- `}let ie={debug(A,ue){s("DEBUG")&&u("DEBUG "+U(A,ue));},info(A,ue){s("INFO")&&u("INFO "+U(A,ue));},error(A,ue){s("ERROR")&&u("ERROR "+U(A,ue));},warn(A,ue){s("WARN")&&u("WARN "+U(A,ue));},tag(A,ue){return P&&(P[A]=ue),ie},clone(){return D.create({...P})},time(A,ue){let vs=Date.now();ie.info(A,{status:"started",...ue});function Ut(){ie.info(A,{status:"completed",duration:Date.now()-vs,...ue});}return {stop:Ut,[Symbol.dispose](){Ut();}}}};return F&&typeof F=="string"&&o.set(F,ie),ie}D.create=O;})(Ce||(Ce={}));var $=Ce.create({service:"transformers-engine"});var Ya=ii__namespace.join(tr__namespace.homedir(),".cache","easbot","models");process.env.HF_HOME||(process.env.HF_HOME=Ya);transformers.env.allowLocalModels=true;transformers.env.allowRemoteModels=true;transformers.env.useBrowserCache=false;transformers.env.useFSCache=true;var ys=class{constructor(e){c(this,"pipeline",null);c(this,"tokenizer",null);c(this,"isInitialized",false);c(this,"config");c(this,"modelCache");this.config=e,this.modelCache=new $t({cacheDir:e.cacheDir}),this.configureEnvironment();}configureEnvironment(){this.modelCache.ensureCacheDir(),process.env.HF_HOME||(process.env.HF_HOME=this.config.cacheDir),transformers.env.cacheDir=this.config.cacheDir,transformers.env.allowLocalModels=true,transformers.env.allowRemoteModels=true,transformers.env.useBrowserCache=false,transformers.env.useFSCache=true,transformers.env.backends?.onnx&&(transformers.env.backends.onnx.logLevel="error"),this.config.verbose&&$.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&&$.debug("\u6A21\u578B\u5DF2\u521D\u59CB\u5316\uFF0C\u8DF3\u8FC7\u91CD\u590D\u52A0\u8F7D");return}try{this.config.verbose&&$.debug("\u5F00\u59CB\u521D\u59CB\u5316\u6A21\u578B");let e,t;if(this.config.modelType==="language"){let o=xe[this.config.modelId];if(!o)throw new x(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");e=o.huggingFaceId,t=o.dtype;}else {let o=bt[this.config.modelId];if(!o)throw new x(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");e=o.huggingFaceId,t=o.dtype;}this.config.verbose&&($.debug("\u52A0\u8F7D\u6A21\u578B",{huggingFaceId:e,dtype:t||"auto"}),this.modelCache.isCached(e)?$.debug("\u4F7F\u7528\u7F13\u5B58\u7684\u6A21\u578B"):$.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(t&&(s.dtype=t),this.modelCache.isCached(e))this.config.verbose&&$.debug("\u4F7F\u7528\u672C\u5730\u7F13\u5B58\u6A21\u578B");else throw this.config.verbose&&$.warn("\u672C\u5730\u7F13\u5B58\u4E0D\u5B58\u5728",{huggingFaceId:e,cacheDir:this.config.cacheDir}),new x(`\u6A21\u578B ${e} \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 transformers.pipeline("text-generation",e,s):this.pipeline=await transformers.pipeline("feature-extraction",e,s),this.tokenizer=this.pipeline.tokenizer,this.isInitialized=!0,this.config.verbose&&$.debug("\u6A21\u578B\u521D\u59CB\u5316\u6210\u529F",{modelId:this.config.modelId});}catch(e){throw this.config.verbose&&$.error("\u6A21\u578B\u521D\u59CB\u5316\u5931\u8D25",{error:e}),ne.modelLoadError(e instanceof Error?e:new Error(String(e)))}}extractAssistantResponse(e,t){let s=`<|im_start|>assistant
5
- `,r=e.lastIndexOf(s);if(r!==-1){let g=e.slice(r+s.length);return g=g.replace(/<\|im_end\|>$/g,""),g.trim()}let o=`
1
+ 'use strict';var ir=require('os'),ii=require('path'),z=require('fs'),zn=require('fs/promises'),Ja=require('zod'),url=require('url'),events=require('events'),fn=require('stream'),string_decoder=require('string_decoder'),utils=require('@easbot/utils'),ai$1=require('ai');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ir__namespace=/*#__PURE__*/_interopNamespace(ir);var ii__namespace=/*#__PURE__*/_interopNamespace(ii);var z__namespace=/*#__PURE__*/_interopNamespace(z);var zn__default=/*#__PURE__*/_interopDefault(zn);var Ja__default=/*#__PURE__*/_interopDefault(Ja);var fn__default=/*#__PURE__*/_interopDefault(fn);var Kn=Object.defineProperty;var tr=i=>{throw TypeError(i)};var Jn=(i,e,t)=>e in i?Kn(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var c=(i,e,t)=>Jn(i,typeof e!="symbol"?e+"":e,t),Ts=(i,e,t)=>e.has(i)||tr("Cannot "+t);var n=(i,e,t)=>(Ts(i,e,"read from private field"),t?t.call(i):e.get(i)),w=(i,e,t)=>e.has(i)?tr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),g=(i,e,t,s)=>(Ts(i,e,"write to private field"),e.set(i,t),t),y=(i,e,t)=>(Ts(i,e,"access private method"),t);var qi=(i,e,t,s)=>({set _(r){g(i,e,r);},get _(){return n(i,e,s)}});var me=(p=>(p.MODEL_NOT_FOUND="MODEL_NOT_FOUND",p.MODEL_LOAD_ERROR="MODEL_LOAD_ERROR",p.MODEL_NOT_INITIALIZED="MODEL_NOT_INITIALIZED",p.GENERATION_ERROR="GENERATION_ERROR",p.EMBEDDING_ERROR="EMBEDDING_ERROR",p.INVALID_INPUT="INVALID_INPUT",p.UNSUPPORTED_FEATURE="UNSUPPORTED_FEATURE",p.CACHE_ERROR="CACHE_ERROR",p.PROCESSING_ERROR="PROCESSING_ERROR",p.ABORTED="ABORTED",p.OUT_OF_MEMORY="OUT_OF_MEMORY",p.UNKNOWN_ERROR="UNKNOWN_ERROR",p))(me||{});function Vi(i,e,t){let s;return e?s="error":i?s="stop":s="other",{unified:s,raw:t}}var Te={"qwen3-0.6b":{modelId:"qwen3-0.6b",huggingFaceId:"onnx-community/Qwen3-0.6B-ONNX",contextLength:32768,device:"cpu",dtype:"q4f16",defaultSettings:{temperature:0,topP:.9,topK:40,maxTokens:32e3,repetitionPenalty:1.1,stopSequences:[]}},"qwen3.5-0.8b":{modelId:"qwen3.5-0.8b",huggingFaceId:"onnx-community/Qwen3.5-0.8B-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:[]}}},wt={"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,dtype:"q4"},"bge-large-zh-v1.5":{modelId:"bge-large-zh-v1.5",huggingFaceId:"Xenova/bge-large-zh-v1.5",dimensions:1024,maxEmbeddingsPerCall:32,dtype:"q4"},"all-MiniLM-L6-v2":{modelId:"all-MiniLM-L6-v2",huggingFaceId:"sentence-transformers/all-MiniLM-L6-v2",dimensions:384,maxEmbeddingsPerCall:32,dtype:"q4"}};var T=class i extends Error{constructor(t,s,r){super(t);c(this,"code",s);c(this,"cause",r);this.name="LocalModelError",Error.captureStackTrace&&Error.captureStackTrace(this,i);}},ne=class{static modelLoadError(e){return new T(`\u6A21\u578B\u52A0\u8F7D\u5931\u8D25: ${e.message}`,"MODEL_LOAD_ERROR",e)}static generationError(e){return new T(`\u751F\u6210\u5931\u8D25: ${e.message}`,"GENERATION_ERROR",e)}static embeddingError(e){return new T(`\u5D4C\u5165\u5931\u8D25: ${e.message}`,"EMBEDDING_ERROR",e)}static validationError(e){return new T(e,"INVALID_INPUT")}static abortError(){return new T("\u64CD\u4F5C\u5DF2\u4E2D\u6B62","ABORTED")}static unsupportedFeature(e){return new T(`\u4E0D\u652F\u6301\u7684\u529F\u80FD: ${e}`,"UNSUPPORTED_FEATURE")}};var Yn=ii__namespace.join(ir__namespace.homedir(),".cache","easbot","models"),$t=class{constructor(e){c(this,"cacheDir");this.cacheDir=e.cacheDir||Yn;}getCachePath(e){return ii__namespace.join(this.cacheDir,e)}isCached(e){try{let t=this.getCachePath(e);return z__namespace.existsSync(t)&&z__namespace.statSync(t).isDirectory()}catch{return false}}async clear(e){try{if(e){let t=this.getCachePath(e);z__namespace.existsSync(t)&&await this.removeDirectory(t);}else z__namespace.existsSync(this.cacheDir)&&await this.removeDirectory(this.cacheDir);}catch(t){throw new T(`\u6E05\u7406\u7F13\u5B58\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`,"CACHE_ERROR",t instanceof Error?t:void 0)}}async getCacheSize(e){try{let t=e?this.getCachePath(e):this.cacheDir;return z__namespace.existsSync(t)?await this.getDirectorySize(t):0}catch(t){throw new T(`\u83B7\u53D6\u7F13\u5B58\u5927\u5C0F\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`,"CACHE_ERROR",t instanceof Error?t:void 0)}}async getDirectorySize(e){let t=0,s=z__namespace.readdirSync(e);for(let r of s){let o=ii__namespace.join(e,r),a=z__namespace.statSync(o);a.isDirectory()?t+=await this.getDirectorySize(o):t+=a.size;}return t}async removeDirectory(e){if(!z__namespace.existsSync(e))return;let t=z__namespace.readdirSync(e);for(let s of t){let r=ii__namespace.join(e,s);z__namespace.statSync(r).isDirectory()?await this.removeDirectory(r):z__namespace.unlinkSync(r);}z__namespace.rmdirSync(e);}ensureCacheDir(){try{z__namespace.existsSync(this.cacheDir)||z__namespace.mkdirSync(this.cacheDir,{recursive:!0});}catch(e){throw new T(`\u521B\u5EFA\u7F13\u5B58\u76EE\u5F55\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`,"CACHE_ERROR",e instanceof Error?e:void 0)}}};var Jr=(i,e,t)=>{let s=i instanceof RegExp?sr(i,t):i,r=e instanceof RegExp?sr(e,t):e,o=s!==null&&r!=null&&Zn(s,r,t);return o&&{start:o[0],end:o[1],pre:t.slice(0,o[0]),body:t.slice(o[0]+s.length,o[1]),post:t.slice(o[1]+r.length)}},sr=(i,e)=>{let t=e.match(i);return t?t[0]:null},Zn=(i,e,t)=>{let s,r,o,a,h,l=t.indexOf(i),d=t.indexOf(e,l+1),f=l;if(l>=0&&d>0){if(i===e)return [l,d];for(s=[],o=t.length;f>=0&&!h;){if(f===l)s.push(f),l=t.indexOf(i,f+1);else if(s.length===1){let u=s.pop();u!==void 0&&(h=[u,d]);}else r=s.pop(),r!==void 0&&r<o&&(o=r,a=d),d=t.indexOf(e,f+1);f=l<d&&l>=0?l:d;}s.length&&a!==void 0&&(h=[o,a]);}return h},Yr="\0SLASH"+Math.random()+"\0",Zr="\0OPEN"+Math.random()+"\0",Vs="\0CLOSE"+Math.random()+"\0",Xr="\0COMMA"+Math.random()+"\0",Qr="\0PERIOD"+Math.random()+"\0",Xn=new RegExp(Yr,"g"),Qn=new RegExp(Zr,"g"),eo=new RegExp(Vs,"g"),to=new RegExp(Xr,"g"),io=new RegExp(Qr,"g"),so=/\\\\/g,ro=/\\{/g,no=/\\}/g,oo=/\\,/g,ao=/\\./g,lo=1e5;function xs(i){return isNaN(i)?i.charCodeAt(0):parseInt(i,10)}function ho(i){return i.replace(so,Yr).replace(ro,Zr).replace(no,Vs).replace(oo,Xr).replace(ao,Qr)}function co(i){return i.replace(Xn,"\\").replace(Qn,"{").replace(eo,"}").replace(to,",").replace(io,".")}function en(i){if(!i)return [""];let e=[],t=Jr("{","}",i);if(!t)return i.split(",");let{pre:s,body:r,post:o}=t,a=s.split(",");a[a.length-1]+="{"+r+"}";let h=en(o);return o.length&&(a[a.length-1]+=h.shift(),a.push.apply(a,h)),e.push.apply(e,a),e}function uo(i,e={}){if(!i)return [];let{max:t=lo}=e;return i.slice(0,2)==="{}"&&(i="\\{\\}"+i.slice(2)),hi(ho(i),t,true).map(co)}function po(i){return "{"+i+"}"}function fo(i){return /^-?0\d/.test(i)}function go(i,e){return i<=e}function mo(i,e){return i>=e}function hi(i,e,t){let s=[],r=Jr("{","}",i);if(!r)return [i];let o=r.pre,a=r.post.length?hi(r.post,e,false):[""];if(/\$$/.test(r.pre))for(let h=0;h<a.length&&h<e;h++){let l=o+"{"+r.body+"}"+a[h];s.push(l);}else {let h=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(r.body),l=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(r.body),d=h||l,f=r.body.indexOf(",")>=0;if(!d&&!f)return r.post.match(/,(?!,).*\}/)?(i=r.pre+"{"+r.body+Vs+r.post,hi(i,e,true)):[i];let u;if(d)u=r.body.split(/\.\./);else if(u=en(r.body),u.length===1&&u[0]!==void 0&&(u=hi(u[0],e,false).map(po),u.length===1))return a.map(m=>r.pre+u[0]+m);let p;if(d&&u[0]!==void 0&&u[1]!==void 0){let m=xs(u[0]),b=xs(u[1]),S=Math.max(u[0].length,u[1].length),x=u.length===3&&u[2]!==void 0?Math.abs(xs(u[2])):1,v=go;b<m&&(x*=-1,v=mo);let k=u.some(fo);p=[];for(let C=m;v(C,b);C+=x){let O;if(l)O=String.fromCharCode(C),O==="\\"&&(O="");else if(O=String(C),k){let D=S-O.length;if(D>0){let P=new Array(D+1).join("0");C<0?O="-"+P+O.slice(1):O=P+O;}}p.push(O);}}else {p=[];for(let m=0;m<u.length;m++)p.push.apply(p,hi(u[m],e,false));}for(let m=0;m<p.length;m++)for(let b=0;b<a.length&&s.length<e;b++){let S=o+p[m]+a[b];(!t||d||S)&&s.push(S);}}return s}var hs=i=>{if(typeof i!="string")throw new TypeError("invalid pattern");if(i.length>65536)throw new TypeError("pattern is too long")},yo={"[: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]},si=i=>i.replace(/[[\]\\-]/g,"\\$&"),wo=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),rr=i=>i.join(""),bo=(i,e)=>{let t=e;if(i.charAt(t)!=="[")throw new Error("not in a brace expression");let s=[],r=[],o=t+1,a=false,h=false,l=false,d=false,f=t,u="";e:for(;o<i.length;){let b=i.charAt(o);if((b==="!"||b==="^")&&o===t+1){d=true,o++;continue}if(b==="]"&&a&&!l){f=o+1;break}if(a=true,b==="\\"&&!l){l=true,o++;continue}if(b==="["&&!l){for(let[S,[x,v,k]]of Object.entries(yo))if(i.startsWith(S,o)){if(u)return ["$.",false,i.length-t,true];o+=S.length,k?r.push(x):s.push(x),h=h||v;continue e}}if(l=false,u){b>u?s.push(si(u)+"-"+si(b)):b===u&&s.push(si(b)),u="",o++;continue}if(i.startsWith("-]",o+1)){s.push(si(b+"-")),o+=2;continue}if(i.startsWith("-",o+1)){u=b,o+=2;continue}s.push(si(b)),o++;}if(f<o)return ["",false,0,false];if(!s.length&&!r.length)return ["$.",false,i.length-t,true];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!d){let b=s[0].length===2?s[0].slice(-1):s[0];return [wo(b),false,f-t,false]}let p="["+(d?"^":"")+rr(s)+"]",m="["+(d?"":"^")+rr(r)+"]";return [s.length&&r.length?"("+p+"|"+m+")":s.length?p:m,h,f-t,true]},jt=(i,{windowsPathsNoEscape:e=false,magicalBraces:t=true}={})=>t?e?i.replace(/\[([^\/\\])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):e?i.replace(/\[([^\/\\{}])\]/g,"$1"):i.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),So=new Set(["!","?","+","*","@"]),nr=i=>So.has(i),vo="(?!(?:^|/)\\.\\.?(?:$|/))",Hi="(?!\\.)",Eo=new Set(["[","."]),To=new Set(["..","."]),xo=new Set("().*{}+?[]^$\\!"),ko=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Hs="[^/]",or=Hs+"*?",ar=Hs+"+?",q,X,Je,N,j,ht,Et,ct,We,Tt,mi,Dt,sn,mt,te,ts,Ds,rn,tn=(te=class{constructor(e,t,s={}){w(this,Dt);c(this,"type");w(this,q);w(this,X);w(this,Je,false);w(this,N,[]);w(this,j);w(this,ht);w(this,Et);w(this,ct,false);w(this,We);w(this,Tt);w(this,mi,false);this.type=e,e&&g(this,X,true),g(this,j,t),g(this,q,n(this,j)?n(n(this,j),q):this),g(this,We,n(this,q)===this?s:n(n(this,q),We)),g(this,Et,n(this,q)===this?[]:n(n(this,q),Et)),e==="!"&&!n(n(this,q),ct)&&n(this,Et).push(this),g(this,ht,n(this,j)?n(n(this,j),N).length:0);}get hasMagic(){if(n(this,X)!==void 0)return n(this,X);for(let e of n(this,N))if(typeof e!="string"&&(e.type||e.hasMagic))return g(this,X,true);return n(this,X)}toString(){return n(this,Tt)!==void 0?n(this,Tt):this.type?g(this,Tt,this.type+"("+n(this,N).map(e=>String(e)).join("|")+")"):g(this,Tt,n(this,N).map(e=>String(e)).join(""))}push(...e){for(let t of e)if(t!==""){if(typeof t!="string"&&!(t instanceof te&&n(t,j)===this))throw new Error("invalid part: "+t);n(this,N).push(t);}}toJSON(){let e=this.type===null?n(this,N).slice().map(t=>typeof t=="string"?t:t.toJSON()):[this.type,...n(this,N).map(t=>t.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===n(this,q)||n(n(this,q),ct)&&n(this,j)?.type==="!")&&e.push({}),e}isStart(){if(n(this,q)===this)return true;if(!n(this,j)?.isStart())return false;if(n(this,ht)===0)return true;let e=n(this,j);for(let t=0;t<n(this,ht);t++){let s=n(e,N)[t];if(!(s instanceof te&&s.type==="!"))return false}return true}isEnd(){if(n(this,q)===this||n(this,j)?.type==="!")return true;if(!n(this,j)?.isEnd())return false;if(!this.type)return n(this,j)?.isEnd();let e=n(this,j)?n(n(this,j),N).length:0;return n(this,ht)===e-1}copyIn(e){typeof e=="string"?this.push(e):this.push(e.clone(this));}clone(e){let t=new te(this.type,e);for(let s of n(this,N))t.copyIn(s);return t}static fromGlob(e,t={}){var r;let s=new te(null,void 0,t);return y(r=te,mt,ts).call(r,e,s,0,t),s}toMMPattern(){if(this!==n(this,q))return n(this,q).toMMPattern();let e=this.toString(),[t,s,r,o]=this.toRegExpSource();if(!(r||n(this,X)||n(this,We).nocase&&!n(this,We).nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return s;let a=(n(this,We).nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return n(this,We)}toRegExpSource(e){let t=e??!!n(this,We).dot;if(n(this,q)===this&&y(this,Dt,sn).call(this),!this.type){let l=this.isStart()&&this.isEnd()&&!n(this,N).some(p=>typeof p!="string"),d=n(this,N).map(p=>{var v;let[m,b,S,x]=typeof p=="string"?y(v=te,mt,rn).call(v,p,n(this,X),l):p.toRegExpSource(e);return g(this,X,n(this,X)||S),g(this,Je,n(this,Je)||x),m}).join(""),f="";if(this.isStart()&&typeof n(this,N)[0]=="string"&&!(n(this,N).length===1&&To.has(n(this,N)[0]))){let p=Eo,m=t&&p.has(d.charAt(0))||d.startsWith("\\.")&&p.has(d.charAt(2))||d.startsWith("\\.\\.")&&p.has(d.charAt(4)),b=!t&&!e&&p.has(d.charAt(0));f=m?vo:b?Hi:"";}let u="";return this.isEnd()&&n(n(this,q),ct)&&n(this,j)?.type==="!"&&(u="(?:$|\\/)"),[f+d+u,jt(d),g(this,X,!!n(this,X)),n(this,Je)]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",o=y(this,Dt,Ds).call(this,t);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString();return g(this,N,[l]),this.type=null,g(this,X,void 0),[l,jt(this.toString()),false,false]}let a=!s||e||t||!Hi?"":y(this,Dt,Ds).call(this,true);a===o&&(a=""),a&&(o=`(?:${o})(?:${a})*?`);let h="";if(this.type==="!"&&n(this,mi))h=(this.isStart()&&!t?Hi:"")+ar;else {let l=this.type==="!"?"))"+(this.isStart()&&!t&&!e?Hi:"")+or+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&a?")":this.type==="*"&&a?")?":`)${this.type}`;h=r+o+l;}return [h,jt(o),g(this,X,!!n(this,X)),n(this,Je)]}},q=new WeakMap,X=new WeakMap,Je=new WeakMap,N=new WeakMap,j=new WeakMap,ht=new WeakMap,Et=new WeakMap,ct=new WeakMap,We=new WeakMap,Tt=new WeakMap,mi=new WeakMap,Dt=new WeakSet,sn=function(){if(this!==n(this,q))throw new Error("should only call on root");if(n(this,ct))return this;this.toString(),g(this,ct,true);let e;for(;e=n(this,Et).pop();){if(e.type!=="!")continue;let t=e,s=n(t,j);for(;s;){for(let r=n(t,ht)+1;!s.type&&r<n(s,N).length;r++)for(let o of n(e,N)){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n(s,N)[r]);}t=s,s=n(t,j);}}return this},mt=new WeakSet,ts=function(e,t,s,r){var m,b;let o=false,a=false,h=-1,l=false;if(t.type===null){let S=s,x="";for(;S<e.length;){let v=e.charAt(S++);if(o||v==="\\"){o=!o,x+=v;continue}if(a){S===h+1?(v==="^"||v==="!")&&(l=true):v==="]"&&!(S===h+2&&l)&&(a=false),x+=v;continue}else if(v==="["){a=true,h=S,l=false,x+=v;continue}if(!r.noext&&nr(v)&&e.charAt(S)==="("){t.push(x),x="";let k=new te(v,t);S=y(m=te,mt,ts).call(m,e,k,S,r),t.push(k);continue}x+=v;}return t.push(x),S}let d=s+1,f=new te(null,t),u=[],p="";for(;d<e.length;){let S=e.charAt(d++);if(o||S==="\\"){o=!o,p+=S;continue}if(a){d===h+1?(S==="^"||S==="!")&&(l=true):S==="]"&&!(d===h+2&&l)&&(a=false),p+=S;continue}else if(S==="["){a=true,h=d,l=false,p+=S;continue}if(nr(S)&&e.charAt(d)==="("){f.push(p),p="";let x=new te(S,f);f.push(x),d=y(b=te,mt,ts).call(b,e,x,d,r);continue}if(S==="|"){f.push(p),p="",u.push(f),f=new te(null,t);continue}if(S===")")return p===""&&n(t,N).length===0&&g(t,mi,true),f.push(p),p="",t.push(...u,f),d;p+=S;}return t.type=null,g(t,X,void 0),g(t,N,[e.substring(s-1)]),d},Ds=function(e){return n(this,N).map(t=>{if(typeof t=="string")throw new Error("string type in extglob ast??");let[s,r,o,a]=t.toRegExpSource(e);return g(this,Je,n(this,Je)||a),s}).filter(t=>!(this.isStart()&&this.isEnd())||!!t).join("|")},rn=function(e,t,s=false){let r=false,o="",a=false,h=false;for(let l=0;l<e.length;l++){let d=e.charAt(l);if(r){r=false,o+=(xo.has(d)?"\\":"")+d;continue}if(d==="*"){if(h)continue;h=true,o+=s&&/^[*]+$/.test(e)?ar:or,t=true;continue}else h=false;if(d==="\\"){l===e.length-1?o+="\\\\":r=true;continue}if(d==="["){let[f,u,p,m]=bo(e,l);if(p){o+=f,a=a||u,l+=p-1,t=t||m;continue}}if(d==="?"){o+=Hs,t=true;continue}o+=ko(d);}return [o,jt(e),!!t,a]},w(te,mt),te),nn=(i,{windowsPathsNoEscape:e=false,magicalBraces:t=false}={})=>t?e?i.replace(/[?*()[\]{}]/g,"[$&]"):i.replace(/[?*()[\]\\{}]/g,"\\$&"):e?i.replace(/[?*()[\]]/g,"[$&]"):i.replace(/[?*()[\]\\]/g,"\\$&"),de=(i,e,t={})=>(hs(e),!t.nocomment&&e.charAt(0)==="#"?false:new yt(e,t).match(i)),Mo=/^\*+([^+@!?\*\[\(]*)$/,Ro=i=>e=>!e.startsWith(".")&&e.endsWith(i),Lo=i=>e=>e.endsWith(i),Co=i=>(i=i.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(i)),Oo=i=>(i=i.toLowerCase(),e=>e.toLowerCase().endsWith(i)),Po=/^\*+\.\*+$/,Do=i=>!i.startsWith(".")&&i.includes("."),Ao=i=>i!=="."&&i!==".."&&i.includes("."),Io=/^\.\*+$/,No=i=>i!=="."&&i!==".."&&i.startsWith("."),_o=/^\*+$/,Fo=i=>i.length!==0&&!i.startsWith("."),Uo=i=>i.length!==0&&i!=="."&&i!=="..",$o=/^\?+([^+@!?\*\[\(]*)?$/,Bo=([i,e=""])=>{let t=on([i]);return e?(e=e.toLowerCase(),s=>t(s)&&s.toLowerCase().endsWith(e)):t},zo=([i,e=""])=>{let t=an([i]);return e?(e=e.toLowerCase(),s=>t(s)&&s.toLowerCase().endsWith(e)):t},jo=([i,e=""])=>{let t=an([i]);return e?s=>t(s)&&s.endsWith(e):t},Wo=([i,e=""])=>{let t=on([i]);return e?s=>t(s)&&s.endsWith(e):t},on=([i])=>{let e=i.length;return t=>t.length===e&&!t.startsWith(".")},an=([i])=>{let e=i.length;return t=>t.length===e&&t!=="."&&t!==".."},ln=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",lr={win32:{sep:"\\"},posix:{sep:"/"}},Go=ln==="win32"?lr.win32.sep:lr.posix.sep;de.sep=Go;var ce=Symbol("globstar **");de.GLOBSTAR=ce;var qo="[^/]",Vo=qo+"*?",Ho="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Ko="(?:(?!(?:\\/|^)\\.).)*?",Jo=(i,e={})=>t=>de(t,i,e);de.filter=Jo;var xe=(i,e={})=>Object.assign({},i,e),Yo=i=>{if(!i||typeof i!="object"||!Object.keys(i).length)return de;let e=de;return Object.assign((t,s,r={})=>e(t,s,xe(i,r)),{Minimatch:class extends e.Minimatch{constructor(t,s={}){super(t,xe(i,s));}static defaults(t){return e.defaults(xe(i,t)).Minimatch}},AST:class extends e.AST{constructor(t,s,r={}){super(t,s,xe(i,r));}static fromGlob(t,s={}){return e.AST.fromGlob(t,xe(i,s))}},unescape:(t,s={})=>e.unescape(t,xe(i,s)),escape:(t,s={})=>e.escape(t,xe(i,s)),filter:(t,s={})=>e.filter(t,xe(i,s)),defaults:t=>e.defaults(xe(i,t)),makeRe:(t,s={})=>e.makeRe(t,xe(i,s)),braceExpand:(t,s={})=>e.braceExpand(t,xe(i,s)),match:(t,s,r={})=>e.match(t,s,xe(i,r)),sep:e.sep,GLOBSTAR:ce})};de.defaults=Yo;var hn=(i,e={})=>(hs(i),e.nobrace||!/\{(?:(?!\{).)*\}/.test(i)?[i]:uo(i,{max:e.braceExpandMax}));de.braceExpand=hn;var Zo=(i,e={})=>new yt(i,e).makeRe();de.makeRe=Zo;var Xo=(i,e,t={})=>{let s=new yt(e,t);return i=i.filter(r=>s.match(r)),s.options.nonull&&!i.length&&i.push(e),i};de.match=Xo;var hr=/[?*]|[+@!]\(.*?\)|\[|\]/,Qo=i=>i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),yt=class{constructor(i,e={}){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");hs(i),e=e||{},this.options=e,this.pattern=i,this.platform=e.platform||ln,this.isWindows=this.platform==="win32";let t="allowWindowsEscape";this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e[t]===false,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=false,this.nonegate=!!e.nonegate,this.comment=false,this.empty=false,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.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 e of i)if(typeof e!="string")return true;return false}debug(...i){}make(){let i=this.pattern,e=this.options;if(!e.nocomment&&i.charAt(0)==="#"){this.comment=true;return}if(!i){this.empty=true;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...r)=>console.error(...r)),this.debug(this.pattern,this.globSet);let t=this.globSet.map(r=>this.slashSplit(r));this.globParts=this.preprocess(t),this.debug(this.pattern,this.globParts);let s=this.globParts.map((r,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=r[0]===""&&r[1]===""&&(r[2]==="?"||!hr.test(r[2]))&&!hr.test(r[3]),l=/^[a-z]:/i.test(r[0]);if(h)return [...r.slice(0,4),...r.slice(4).map(d=>this.parse(d))];if(l)return [r[0],...r.slice(1).map(d=>this.parse(d))]}return r.map(h=>this.parse(h))});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 t=0;t<i.length;t++)for(let s=0;s<i[t].length;s++)i[t][s]==="**"&&(i[t][s]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(i=this.firstPhasePreProcess(i),i=this.secondPhasePreProcess(i)):e>=1?i=this.levelOneOptimize(i):i=this.adjascentGlobstarOptimize(i),i}adjascentGlobstarOptimize(i){return i.map(e=>{let t=-1;for(;(t=e.indexOf("**",t+1))!==-1;){let s=t;for(;e[s+1]==="**";)s++;s!==t&&e.splice(t,s-t);}return e})}levelOneOptimize(i){return i.map(e=>(e=e.reduce((t,s)=>{let r=t[t.length-1];return s==="**"&&r==="**"?t:s===".."&&r&&r!==".."&&r!=="."&&r!=="**"?(t.pop(),t):(t.push(s),t)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(i){Array.isArray(i)||(i=this.slashSplit(i));let e=false;do{if(e=false,!this.preserveMultipleSlashes){for(let s=1;s<i.length-1;s++){let r=i[s];s===1&&r===""&&i[0]===""||(r==="."||r==="")&&(e=true,i.splice(s,1),s--);}i[0]==="."&&i.length===2&&(i[1]==="."||i[1]==="")&&(e=true,i.pop());}let t=0;for(;(t=i.indexOf("..",t+1))!==-1;){let s=i[t-1];s&&s!=="."&&s!==".."&&s!=="**"&&(e=true,i.splice(t-1,2),t-=2);}}while(e);return i.length===0?[""]:i}firstPhasePreProcess(i){let e=false;do{e=false;for(let t of i){let s=-1;for(;(s=t.indexOf("**",s+1))!==-1;){let o=s;for(;t[o+1]==="**";)o++;o>s&&t.splice(s+1,o-s);let a=t[s+1],h=t[s+2],l=t[s+3];if(a!==".."||!h||h==="."||h===".."||!l||l==="."||l==="..")continue;e=true,t.splice(s,1);let d=t.slice(0);d[s]="**",i.push(d),s--;}if(!this.preserveMultipleSlashes){for(let o=1;o<t.length-1;o++){let a=t[o];o===1&&a===""&&t[0]===""||(a==="."||a==="")&&(e=true,t.splice(o,1),o--);}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=true,t.pop());}let r=0;for(;(r=t.indexOf("..",r+1))!==-1;){let o=t[r-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=true;let a=r===1&&t[r+1]==="**"?["."]:[];t.splice(r-1,2,...a),t.length===0&&t.push(""),r-=2;}}}}while(e);return i}secondPhasePreProcess(i){for(let e=0;e<i.length-1;e++)for(let t=e+1;t<i.length;t++){let s=this.partsMatch(i[e],i[t],!this.preserveMultipleSlashes);if(s){i[e]=[],i[t]=s;break}}return i.filter(e=>e.length)}partsMatch(i,e,t=false){let s=0,r=0,o=[],a="";for(;s<i.length&&r<e.length;)if(i[s]===e[r])o.push(a==="b"?e[r]:i[s]),s++,r++;else if(t&&i[s]==="**"&&e[r]===i[s+1])o.push(i[s]),s++;else if(t&&e[r]==="**"&&i[s]===e[r+1])o.push(e[r]),r++;else if(i[s]==="*"&&e[r]&&(this.options.dot||!e[r].startsWith("."))&&e[r]!=="**"){if(a==="b")return false;a="a",o.push(i[s]),s++,r++;}else if(e[r]==="*"&&i[s]&&(this.options.dot||!i[s].startsWith("."))&&i[s]!=="**"){if(a==="a")return false;a="b",o.push(e[r]),s++,r++;}else return false;return i.length===e.length&&o}parseNegate(){if(this.nonegate)return;let i=this.pattern,e=false,t=0;for(let s=0;s<i.length&&i.charAt(s)==="!";s++)e=!e,t++;t&&(this.pattern=i.slice(t)),this.negate=e;}matchOne(i,e,t=false){let s=this.options;if(this.isWindows){let b=typeof i[0]=="string"&&/^[a-z]:$/i.test(i[0]),S=!b&&i[0]===""&&i[1]===""&&i[2]==="?"&&/^[a-z]:$/i.test(i[3]),x=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),v=!x&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),k=S?3:b?0:void 0,C=v?3:x?0:void 0;if(typeof k=="number"&&typeof C=="number"){let[O,D]=[i[k],e[C]];O.toLowerCase()===D.toLowerCase()&&(e[C]=O,C>k?e=e.slice(C):k>C&&(i=i.slice(k)));}}let{optimizationLevel:r=1}=this.options;r>=2&&(i=this.levelTwoFileOptimize(i)),this.debug("matchOne",this,{file:i,pattern:e}),this.debug("matchOne",i.length,e.length);for(var o=0,a=0,h=i.length,l=e.length;o<h&&a<l;o++,a++){this.debug("matchOne loop");var d=e[a],f=i[o];if(this.debug(e,d,f),d===false)return false;if(d===ce){this.debug("GLOBSTAR",[e,d,f]);var u=o,p=a+1;if(p===l){for(this.debug("** at the end");o<h;o++)if(i[o]==="."||i[o]===".."||!s.dot&&i[o].charAt(0)===".")return false;return true}for(;u<h;){var m=i[u];if(this.debug(`
2
+ globstar while`,i,u,e,p,m),this.matchOne(i.slice(u),e.slice(p),t))return this.debug("globstar found match!",u,h,m),true;if(m==="."||m===".."||!s.dot&&m.charAt(0)==="."){this.debug("dot detected!",i,u,e,p);break}this.debug("globstar swallow a segment, and continue"),u++;}return !!(t&&(this.debug(`
3
+ >>> no match, partial?`,i,u,e,p),u===h))}let b;if(typeof d=="string"?(b=f===d,this.debug("string match",d,f,b)):(b=d.test(f),this.debug("pattern match",d,f,b)),!b)return false}if(o===h&&a===l)return true;if(o===h)return t;if(a===l)return o===h-1&&i[o]==="";throw new Error("wtf?")}braceExpand(){return hn(this.pattern,this.options)}parse(i){hs(i);let e=this.options;if(i==="**")return ce;if(i==="")return "";let t,s=null;(t=i.match(_o))?s=e.dot?Uo:Fo:(t=i.match(Mo))?s=(e.nocase?e.dot?Oo:Co:e.dot?Lo:Ro)(t[1]):(t=i.match($o))?s=(e.nocase?e.dot?zo:Bo:e.dot?jo:Wo)(t):(t=i.match(Po))?s=e.dot?Ao:Do:(t=i.match(Io))&&(s=No);let r=tn.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 e=this.options,t=e.noglobstar?Vo:e.dot?Ho:Ko,s=new Set(e.nocase?["i"]:[]),r=i.map(h=>{let l=h.map(f=>{if(f instanceof RegExp)for(let u of f.flags.split(""))s.add(u);return typeof f=="string"?Qo(f):f===ce?ce:f._src});l.forEach((f,u)=>{let p=l[u+1],m=l[u-1];f!==ce||m===ce||(m===void 0?p!==void 0&&p!==ce?l[u+1]="(?:\\/|"+t+"\\/)?"+p:l[u]=t:p===void 0?l[u-1]=m+"(?:\\/|\\/"+t+")?":p!==ce&&(l[u-1]=m+"(?:\\/|\\/"+t+"\\/)"+p,l[u+1]=ce));});let d=l.filter(f=>f!==ce);if(this.partial&&d.length>=1){let f=[];for(let u=1;u<=d.length;u++)f.push(d.slice(0,u).join("/"));return "(?:"+f.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,e=this.partial){if(this.debug("match",i,this.pattern),this.comment)return false;if(this.empty)return i==="";if(i==="/"&&e)return true;let t=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 h=r[a],l=s;if(t.matchBase&&h.length===1&&(l=[o]),this.matchOne(l,h,e))return t.flipNegate?true:!this.negate}return t.flipNegate?false:this.negate}static defaults(i){return de.defaults(i).Minimatch}};de.AST=tn;de.Minimatch=yt;de.escape=nn;de.unescape=jt;var ta=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,cn=new Set,As=typeof process=="object"&&process?process:{},dn=(i,e,t,s)=>{typeof As.emitWarning=="function"?As.emitWarning(i,e,t,s):console.error(`[${t}] ${e}: ${i}`);},cs=globalThis.AbortController,cr=globalThis.AbortSignal;if(typeof cs>"u"){cr=class{constructor(){c(this,"onabort");c(this,"_onabort",[]);c(this,"reason");c(this,"aborted",false);}addEventListener(t,s){this._onabort.push(s);}},cs=class{constructor(){c(this,"signal",new cr);e();}abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let s of this.signal._onabort)s(t);this.signal.onabort?.(t);}}};let i=As.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{i&&(i=false,dn("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",e));};}var ia=i=>!cn.has(i),nt=i=>i&&i===Math.floor(i)&&i>0&&isFinite(i),un=i=>nt(i)?i<=Math.pow(2,8)?Uint8Array:i<=Math.pow(2,16)?Uint16Array:i<=Math.pow(2,32)?Uint32Array:i<=Number.MAX_SAFE_INTEGER?is:null:null,is=class extends Array{constructor(i){super(i),this.fill(0);}},Ve,Wt,sa=(Ve=class{constructor(e,t){c(this,"heap");c(this,"length");if(!n(Ve,Wt))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}static create(e){let t=un(e);if(!t)return [];g(Ve,Wt,true);let s=new Ve(e,t);return g(Ve,Wt,false),s}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Wt=new WeakMap,w(Ve,Wt,false),Ve),kr,Mr,Me,we,De,xt,Ae,Gt,qt,Ie,V,Ne,W,_,L,ae,be,re,Q,_e,ee,Fe,Ue,Se,ve,$e,dt,le,Vt,E,Is,kt,Ye,yi,Ee,pn,Mt,Ht,wi,ot,at,Ns,ss,rs,I,_s,ci,lt,Fs,Kt,ps=(Kt=class{constructor(e){w(this,E);w(this,Me);w(this,we);w(this,De);w(this,xt);w(this,Ae);w(this,Gt);w(this,qt);w(this,Ie);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,V);w(this,Ne);w(this,W);w(this,_);w(this,L);w(this,ae);w(this,be);w(this,re);w(this,Q);w(this,_e);w(this,ee);w(this,Fe);w(this,Ue);w(this,Se);w(this,ve);w(this,$e);w(this,dt);w(this,le);w(this,Vt);w(this,kt,()=>{});w(this,Ye,()=>{});w(this,yi,()=>{});w(this,Ee,()=>false);w(this,Mt,e=>{});w(this,Ht,(e,t,s)=>{});w(this,wi,(e,t,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});c(this,kr,"LRUCache");let{max:t=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:a,updateAgeOnHas:h,allowStale:l,dispose:d,onInsert:f,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:m,maxSize:b=0,maxEntrySize:S=0,sizeCalculation:x,fetchMethod:v,memoMethod:k,noDeleteOnFetchRejection:C,noDeleteOnStaleGet:O,allowStaleOnFetchRejection:D,allowStaleOnFetchAbort:P,ignoreFetchAbort:F,perf:$}=e;if($!==void 0&&typeof $?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(g(this,Ie,$??ta),t!==0&&!nt(t))throw new TypeError("max option must be a nonnegative integer");let ie=t?un(t):Array;if(!ie)throw new Error("invalid max value: "+t);if(g(this,Me,t),g(this,we,b),this.maxEntrySize=S||n(this,we),this.sizeCalculation=x,this.sizeCalculation){if(!n(this,we)&&!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(g(this,qt,k),v!==void 0&&typeof v!="function")throw new TypeError("fetchMethod must be a function if specified");if(g(this,Gt,v),g(this,dt,!!v),g(this,W,new Map),g(this,_,new Array(t).fill(void 0)),g(this,L,new Array(t).fill(void 0)),g(this,ae,new ie(t)),g(this,be,new ie(t)),g(this,re,0),g(this,Q,0),g(this,_e,sa.create(t)),g(this,V,0),g(this,Ne,0),typeof d=="function"&&g(this,De,d),typeof f=="function"&&g(this,xt,f),typeof u=="function"?(g(this,Ae,u),g(this,ee,[])):(g(this,Ae,void 0),g(this,ee,void 0)),g(this,$e,!!n(this,De)),g(this,Vt,!!n(this,xt)),g(this,le,!!n(this,Ae)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!C,this.allowStaleOnFetchRejection=!!D,this.allowStaleOnFetchAbort=!!P,this.ignoreFetchAbort=!!F,this.maxEntrySize!==0){if(n(this,we)!==0&&!nt(n(this,we)))throw new TypeError("maxSize must be a positive integer if specified");if(!nt(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");y(this,E,pn).call(this);}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!O,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!h,this.ttlResolution=nt(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!nt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");y(this,E,Is).call(this);}if(n(this,Me)===0&&this.ttl===0&&n(this,we)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!n(this,Me)&&!n(this,we)){let A="LRU_CACHE_UNBOUNDED";ia(A)&&(cn.add(A),dn("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",A,Kt));}}get perf(){return n(this,Ie)}static unsafeExposeInternals(e){return {starts:n(e,Ue),ttls:n(e,Se),autopurgeTimers:n(e,ve),sizes:n(e,Fe),keyMap:n(e,W),keyList:n(e,_),valList:n(e,L),next:n(e,ae),prev:n(e,be),get head(){return n(e,re)},get tail(){return n(e,Q)},free:n(e,_e),isBackgroundFetch:t=>{var s;return y(s=e,E,I).call(s,t)},backgroundFetch:(t,s,r,o)=>{var a;return y(a=e,E,rs).call(a,t,s,r,o)},moveToTail:t=>{var s;return y(s=e,E,ci).call(s,t)},indexes:t=>{var s;return y(s=e,E,ot).call(s,t)},rindexes:t=>{var s;return y(s=e,E,at).call(s,t)},isStale:t=>{var s;return n(s=e,Ee).call(s,t)}}}get max(){return n(this,Me)}get maxSize(){return n(this,we)}get calculatedSize(){return n(this,Ne)}get size(){return n(this,V)}get fetchMethod(){return n(this,Gt)}get memoMethod(){return n(this,qt)}get dispose(){return n(this,De)}get onInsert(){return n(this,xt)}get disposeAfter(){return n(this,Ae)}getRemainingTTL(e){return n(this,W).has(e)?1/0:0}*entries(){for(let e of y(this,E,ot).call(this))n(this,L)[e]!==void 0&&n(this,_)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield [n(this,_)[e],n(this,L)[e]]);}*rentries(){for(let e of y(this,E,at).call(this))n(this,L)[e]!==void 0&&n(this,_)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield [n(this,_)[e],n(this,L)[e]]);}*keys(){for(let e of y(this,E,ot).call(this)){let t=n(this,_)[e];t!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield t);}}*rkeys(){for(let e of y(this,E,at).call(this)){let t=n(this,_)[e];t!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield t);}}*values(){for(let e of y(this,E,ot).call(this))n(this,L)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield n(this,L)[e]);}*rvalues(){for(let e of y(this,E,at).call(this))n(this,L)[e]!==void 0&&!y(this,E,I).call(this,n(this,L)[e])&&(yield n(this,L)[e]);}[(Mr=Symbol.iterator,kr=Symbol.toStringTag,Mr)](){return this.entries()}find(e,t={}){for(let s of y(this,E,ot).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&e(o,n(this,_)[s],this))return this.get(n(this,_)[s],t)}}forEach(e,t=this){for(let s of y(this,E,ot).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&e.call(t,o,n(this,_)[s],this);}}rforEach(e,t=this){for(let s of y(this,E,at).call(this)){let r=n(this,L)[s],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&e.call(t,o,n(this,_)[s],this);}}purgeStale(){let e=false;for(let t of y(this,E,at).call(this,{allowStale:true}))n(this,Ee).call(this,t)&&(y(this,E,lt).call(this,n(this,_)[t],"expire"),e=true);return e}info(e){let t=n(this,W).get(e);if(t===void 0)return;let s=n(this,L)[t],r=y(this,E,I).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(n(this,Se)&&n(this,Ue)){let a=n(this,Se)[t],h=n(this,Ue)[t];if(a&&h){let l=a-(n(this,Ie).now()-h);o.ttl=l,o.start=Date.now();}}return n(this,Fe)&&(o.size=n(this,Fe)[t]),o}dump(){let e=[];for(let t of y(this,E,ot).call(this,{allowStale:true})){let s=n(this,_)[t],r=n(this,L)[t],o=y(this,E,I).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let a={value:o};if(n(this,Se)&&n(this,Ue)){a.ttl=n(this,Se)[t];let h=n(this,Ie).now()-n(this,Ue)[t];a.start=Math.floor(Date.now()-h);}n(this,Fe)&&(a.size=n(this,Fe)[t]),e.unshift([s,a]);}return e}load(e){this.clear();for(let[t,s]of e){if(s.start){let r=Date.now()-s.start;s.start=n(this,Ie).now()-r;}this.set(t,s.value,s);}}set(e,t,s={}){var p,m,b,S;if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:o,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:l}=s,{noUpdateTTL:d=this.noUpdateTTL}=s,f=n(this,wi).call(this,e,t,s.size||0,h);if(this.maxEntrySize&&f>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=true),y(this,E,lt).call(this,e,"set"),this;let u=n(this,V)===0?void 0:n(this,W).get(e);if(u===void 0)u=n(this,V)===0?n(this,Q):n(this,_e).length!==0?n(this,_e).pop():n(this,V)===n(this,Me)?y(this,E,ss).call(this,false):n(this,V),n(this,_)[u]=e,n(this,L)[u]=t,n(this,W).set(e,u),n(this,ae)[n(this,Q)]=u,n(this,be)[u]=n(this,Q),g(this,Q,u),qi(this,V)._++,n(this,Ht).call(this,u,f,l),l&&(l.set="add"),d=false,n(this,Vt)&&((p=n(this,xt))==null||p.call(this,t,e,"add"));else {y(this,E,ci).call(this,u);let x=n(this,L)[u];if(t!==x){if(n(this,dt)&&y(this,E,I).call(this,x)){x.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:v}=x;v!==void 0&&!a&&(n(this,$e)&&((m=n(this,De))==null||m.call(this,v,e,"set")),n(this,le)&&n(this,ee)?.push([v,e,"set"]));}else a||(n(this,$e)&&((b=n(this,De))==null||b.call(this,x,e,"set")),n(this,le)&&n(this,ee)?.push([x,e,"set"]));if(n(this,Mt).call(this,u),n(this,Ht).call(this,u,f,l),n(this,L)[u]=t,l){l.set="replace";let v=x&&y(this,E,I).call(this,x)?x.__staleWhileFetching:x;v!==void 0&&(l.oldValue=v);}}else l&&(l.set="update");n(this,Vt)&&this.onInsert?.(t,e,t===x?"update":"replace");}if(r!==0&&!n(this,Se)&&y(this,E,Is).call(this),n(this,Se)&&(d||n(this,yi).call(this,u,r,o),l&&n(this,Ye).call(this,l,u)),!a&&n(this,le)&&n(this,ee)){let x=n(this,ee),v;for(;v=x?.shift();)(S=n(this,Ae))==null||S.call(this,...v);}return this}pop(){var e;try{for(;n(this,V);){let t=n(this,L)[n(this,re)];if(y(this,E,ss).call(this,!0),y(this,E,I).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(n(this,le)&&n(this,ee)){let t=n(this,ee),s;for(;s=t?.shift();)(e=n(this,Ae))==null||e.call(this,...s);}}}has(e,t={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=t,o=n(this,W).get(e);if(o!==void 0){let a=n(this,L)[o];if(y(this,E,I).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(n(this,Ee).call(this,o))r&&(r.has="stale",n(this,Ye).call(this,r,o));else return s&&n(this,kt).call(this,o),r&&(r.has="hit",n(this,Ye).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(e,t={}){let{allowStale:s=this.allowStale}=t,r=n(this,W).get(e);if(r===void 0||!s&&n(this,Ee).call(this,r))return;let o=n(this,L)[r];return y(this,E,I).call(this,o)?o.__staleWhileFetching:o}async fetch(e,t={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:l=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:f=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:p=this.allowStaleOnFetchRejection,ignoreFetchAbort:m=this.ignoreFetchAbort,allowStaleOnFetchAbort:b=this.allowStaleOnFetchAbort,context:S,forceRefresh:x=false,status:v,signal:k}=t;if(!n(this,dt))return v&&(v.fetch="get"),this.get(e,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:v});let C={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:a,noDisposeOnSet:h,size:l,sizeCalculation:d,noUpdateTTL:f,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:p,allowStaleOnFetchAbort:b,ignoreFetchAbort:m,status:v,signal:k},O=n(this,W).get(e);if(O===void 0){v&&(v.fetch="miss");let D=y(this,E,rs).call(this,e,O,C,S);return D.__returned=D}else {let D=n(this,L)[O];if(y(this,E,I).call(this,D)){let ie=s&&D.__staleWhileFetching!==void 0;return v&&(v.fetch="inflight",ie&&(v.returnedStale=true)),ie?D.__staleWhileFetching:D.__returned=D}let P=n(this,Ee).call(this,O);if(!x&&!P)return v&&(v.fetch="hit"),y(this,E,ci).call(this,O),r&&n(this,kt).call(this,O),v&&n(this,Ye).call(this,v,O),D;let F=y(this,E,rs).call(this,e,O,C,S),$=F.__staleWhileFetching!==void 0&&s;return v&&(v.fetch=P?"stale":"refresh",$&&P&&(v.returnedStale=true)),$?F.__staleWhileFetching:F.__returned=F}}async forceFetch(e,t={}){let s=await this.fetch(e,t);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(e,t={}){let s=n(this,qt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:o,...a}=t,h=this.get(e,a);if(!o&&h!==void 0)return h;let l=s(e,h,{options:a,context:r});return this.set(e,l,a),l}get(e,t={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:a}=t,h=n(this,W).get(e);if(h!==void 0){let l=n(this,L)[h],d=y(this,E,I).call(this,l);return a&&n(this,Ye).call(this,a,h),n(this,Ee).call(this,h)?(a&&(a.get="stale"),d?(a&&s&&l.__staleWhileFetching!==void 0&&(a.returnedStale=true),s?l.__staleWhileFetching:void 0):(o||y(this,E,lt).call(this,e,"expire"),a&&s&&(a.returnedStale=true),s?l:void 0)):(a&&(a.get="hit"),d?l.__staleWhileFetching:(y(this,E,ci).call(this,h),r&&n(this,kt).call(this,h),l))}else a&&(a.get="miss");}delete(e){return y(this,E,lt).call(this,e,"delete")}clear(){return y(this,E,Fs).call(this,"delete")}},Me=new WeakMap,we=new WeakMap,De=new WeakMap,xt=new WeakMap,Ae=new WeakMap,Gt=new WeakMap,qt=new WeakMap,Ie=new WeakMap,V=new WeakMap,Ne=new WeakMap,W=new WeakMap,_=new WeakMap,L=new WeakMap,ae=new WeakMap,be=new WeakMap,re=new WeakMap,Q=new WeakMap,_e=new WeakMap,ee=new WeakMap,Fe=new WeakMap,Ue=new WeakMap,Se=new WeakMap,ve=new WeakMap,$e=new WeakMap,dt=new WeakMap,le=new WeakMap,Vt=new WeakMap,E=new WeakSet,Is=function(){let e=new is(n(this,Me)),t=new is(n(this,Me));g(this,Se,e),g(this,Ue,t);let s=this.ttlAutopurge?new Array(n(this,Me)):void 0;g(this,ve,s),g(this,yi,(a,h,l=n(this,Ie).now())=>{if(t[a]=h!==0?l:0,e[a]=h,s?.[a]&&(clearTimeout(s[a]),s[a]=void 0),h!==0&&s){let d=setTimeout(()=>{n(this,Ee).call(this,a)&&y(this,E,lt).call(this,n(this,_)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}),g(this,kt,a=>{t[a]=e[a]!==0?n(this,Ie).now():0;}),g(this,Ye,(a,h)=>{if(e[h]){let l=e[h],d=t[h];if(!l||!d)return;a.ttl=l,a.start=d,a.now=r||o();let f=a.now-d;a.remainingTTL=l-f;}});let r=0,o=()=>{let a=n(this,Ie).now();if(this.ttlResolution>0){r=a;let h=setTimeout(()=>r=0,this.ttlResolution);h.unref&&h.unref();}return a};this.getRemainingTTL=a=>{let h=n(this,W).get(a);if(h===void 0)return 0;let l=e[h],d=t[h];if(!l||!d)return 1/0;let f=(r||o())-d;return l-f},g(this,Ee,a=>{let h=t[a],l=e[a];return !!l&&!!h&&(r||o())-h>l});},kt=new WeakMap,Ye=new WeakMap,yi=new WeakMap,Ee=new WeakMap,pn=function(){let e=new is(n(this,Me));g(this,Ne,0),g(this,Fe,e),g(this,Mt,t=>{g(this,Ne,n(this,Ne)-e[t]),e[t]=0;}),g(this,wi,(t,s,r,o)=>{if(y(this,E,I).call(this,s))return 0;if(!nt(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,t),!nt(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}),g(this,Ht,(t,s,r)=>{if(e[t]=s,n(this,we)){let o=n(this,we)-e[t];for(;n(this,Ne)>o;)y(this,E,ss).call(this,true);}g(this,Ne,n(this,Ne)+e[t]),r&&(r.entrySize=s,r.totalCalculatedSize=n(this,Ne));});},Mt=new WeakMap,Ht=new WeakMap,wi=new WeakMap,ot=function*({allowStale:e=this.allowStale}={}){if(n(this,V))for(let t=n(this,Q);!(!y(this,E,Ns).call(this,t)||((e||!n(this,Ee).call(this,t))&&(yield t),t===n(this,re)));)t=n(this,be)[t];},at=function*({allowStale:e=this.allowStale}={}){if(n(this,V))for(let t=n(this,re);!(!y(this,E,Ns).call(this,t)||((e||!n(this,Ee).call(this,t))&&(yield t),t===n(this,Q)));)t=n(this,ae)[t];},Ns=function(e){return e!==void 0&&n(this,W).get(n(this,_)[e])===e},ss=function(e){var o;let t=n(this,re),s=n(this,_)[t],r=n(this,L)[t];return n(this,dt)&&y(this,E,I).call(this,r)?r.__abortController.abort(new Error("evicted")):(n(this,$e)||n(this,le))&&(n(this,$e)&&((o=n(this,De))==null||o.call(this,r,s,"evict")),n(this,le)&&n(this,ee)?.push([r,s,"evict"])),n(this,Mt).call(this,t),n(this,ve)?.[t]&&(clearTimeout(n(this,ve)[t]),n(this,ve)[t]=void 0),e&&(n(this,_)[t]=void 0,n(this,L)[t]=void 0,n(this,_e).push(t)),n(this,V)===1?(g(this,re,g(this,Q,0)),n(this,_e).length=0):g(this,re,n(this,ae)[t]),n(this,W).delete(s),qi(this,V)._--,t},rs=function(e,t,s,r){let o=t===void 0?void 0:n(this,L)[t];if(y(this,E,I).call(this,o))return o;let a=new cs,{signal:h}=s;h?.addEventListener("abort",()=>a.abort(h.reason),{signal:a.signal});let l={signal:a.signal,options:s,context:r},d=(S,x=false)=>{let{aborted:v}=a.signal,k=s.ignoreFetchAbort&&S!==void 0,C=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&S!==void 0);if(s.status&&(v&&!x?(s.status.fetchAborted=true,s.status.fetchError=a.signal.reason,k&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),v&&!k&&!x)return u(a.signal.reason,C);let O=m,D=n(this,L)[t];return (D===m||k&&x&&D===void 0)&&(S===void 0?O.__staleWhileFetching!==void 0?n(this,L)[t]=O.__staleWhileFetching:y(this,E,lt).call(this,e,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e,S,l.options))),S},f=S=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=S),u(S,false)),u=(S,x)=>{let{aborted:v}=a.signal,k=v&&s.allowStaleOnFetchAbort,C=k||s.allowStaleOnFetchRejection,O=C||s.noDeleteOnFetchRejection,D=m;if(n(this,L)[t]===m&&(!O||!x&&D.__staleWhileFetching===void 0?y(this,E,lt).call(this,e,"fetch"):k||(n(this,L)[t]=D.__staleWhileFetching)),C)return s.status&&D.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),D.__staleWhileFetching;if(D.__returned===D)throw S},p=(S,x)=>{var k;let v=(k=n(this,Gt))==null?void 0:k.call(this,e,o,l);v&&v instanceof Promise&&v.then(C=>S(C===void 0?void 0:C),x),a.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(S(void 0),s.allowStaleOnFetchAbort&&(S=C=>d(C,true)));});};s.status&&(s.status.fetchDispatched=true);let m=new Promise(p).then(d,f),b=Object.assign(m,{__abortController:a,__staleWhileFetching:o,__returned:void 0});return t===void 0?(this.set(e,b,{...l.options,status:void 0}),t=n(this,W).get(e)):n(this,L)[t]=b,b},I=function(e){if(!n(this,dt))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof cs},_s=function(e,t){n(this,be)[t]=e,n(this,ae)[e]=t;},ci=function(e){e!==n(this,Q)&&(e===n(this,re)?g(this,re,n(this,ae)[e]):y(this,E,_s).call(this,n(this,be)[e],n(this,ae)[e]),y(this,E,_s).call(this,n(this,Q),e),g(this,Q,e));},lt=function(e,t){var r,o;let s=false;if(n(this,V)!==0){let a=n(this,W).get(e);if(a!==void 0)if(n(this,ve)?.[a]&&(clearTimeout(n(this,ve)?.[a]),n(this,ve)[a]=void 0),s=true,n(this,V)===1)y(this,E,Fs).call(this,t);else {n(this,Mt).call(this,a);let h=n(this,L)[a];if(y(this,E,I).call(this,h)?h.__abortController.abort(new Error("deleted")):(n(this,$e)||n(this,le))&&(n(this,$e)&&((r=n(this,De))==null||r.call(this,h,e,t)),n(this,le)&&n(this,ee)?.push([h,e,t])),n(this,W).delete(e),n(this,_)[a]=void 0,n(this,L)[a]=void 0,a===n(this,Q))g(this,Q,n(this,be)[a]);else if(a===n(this,re))g(this,re,n(this,ae)[a]);else {let l=n(this,be)[a];n(this,ae)[l]=n(this,ae)[a];let d=n(this,ae)[a];n(this,be)[d]=n(this,be)[a];}qi(this,V)._--,n(this,_e).push(a);}}if(n(this,le)&&n(this,ee)?.length){let a=n(this,ee),h;for(;h=a?.shift();)(o=n(this,Ae))==null||o.call(this,...h);}return s},Fs=function(e){var t,s;for(let r of y(this,E,at).call(this,{allowStale:true})){let o=n(this,L)[r];if(y(this,E,I).call(this,o))o.__abortController.abort(new Error("deleted"));else {let a=n(this,_)[r];n(this,$e)&&((t=n(this,De))==null||t.call(this,o,a,e)),n(this,le)&&n(this,ee)?.push([o,a,e]);}}if(n(this,W).clear(),n(this,L).fill(void 0),n(this,_).fill(void 0),n(this,Se)&&n(this,Ue)){n(this,Se).fill(0),n(this,Ue).fill(0);for(let r of n(this,ve)??[])r!==void 0&&clearTimeout(r);n(this,ve)?.fill(void 0);}if(n(this,Fe)&&n(this,Fe).fill(0),g(this,re,0),g(this,Q,0),n(this,_e).length=0,g(this,Ne,0),g(this,V,0),n(this,le)&&n(this,ee)){let r=n(this,ee),o;for(;o=r?.shift();)(s=n(this,Ae))==null||s.call(this,...o);}},Kt),dr=typeof process=="object"&&process?process:{stdout:null,stderr:null},ya=i=>!!i&&typeof i=="object"&&(i instanceof ds||i instanceof fn__default.default||wa(i)||ba(i)),wa=i=>!!i&&typeof i=="object"&&i instanceof events.EventEmitter&&typeof i.pipe=="function"&&i.pipe!==fn__default.default.Writable.prototype.pipe,ba=i=>!!i&&typeof i=="object"&&i instanceof events.EventEmitter&&typeof i.write=="function"&&typeof i.end=="function",He=Symbol("EOF"),Ke=Symbol("maybeEmitEnd"),rt=Symbol("emittedEnd"),Ki=Symbol("emittingEnd"),ri=Symbol("emittedError"),Ji=Symbol("closed"),ur=Symbol("read"),Yi=Symbol("flush"),pr=Symbol("flushChunk"),Oe=Symbol("encoding"),Bt=Symbol("decoder"),J=Symbol("flowing"),ni=Symbol("paused"),zt=Symbol("resume"),Y=Symbol("buffer"),oe=Symbol("pipes"),Z=Symbol("bufferLength"),ks=Symbol("bufferPush"),Zi=Symbol("bufferShift"),se=Symbol("objectMode"),B=Symbol("destroyed"),Ms=Symbol("error"),Rs=Symbol("emitData"),fr=Symbol("emitEnd"),Ls=Symbol("emitEnd2"),ze=Symbol("async"),Cs=Symbol("abort"),Xi=Symbol("aborted"),oi=Symbol("signal"),bt=Symbol("dataListeners"),ye=Symbol("discarded"),ai=i=>Promise.resolve().then(i),Sa=i=>i(),va=i=>i==="end"||i==="finish"||i==="prefinish",Ea=i=>i instanceof ArrayBuffer||!!i&&typeof i=="object"&&i.constructor&&i.constructor.name==="ArrayBuffer"&&i.byteLength>=0,Ta=i=>!Buffer.isBuffer(i)&&ArrayBuffer.isView(i),gn=class{constructor(i,e,t){c(this,"src");c(this,"dest");c(this,"opts");c(this,"ondrain");this.src=i,this.dest=e,this.opts=t,this.ondrain=()=>i[zt](),this.dest.on("drain",this.ondrain);}unpipe(){this.dest.removeListener("drain",this.ondrain);}proxyErrors(i){}end(){this.unpipe(),this.opts.end&&this.dest.end();}},xa=class extends gn{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe();}constructor(i,e,t){super(i,e,t),this.proxyErrors=s=>this.dest.emit("error",s),i.on("error",this.proxyErrors);}},ka=i=>!!i.objectMode,Ma=i=>!i.objectMode&&!!i.encoding&&i.encoding!=="buffer",Rr,Lr,Cr,Or,Pr,Dr,Ar,Ir,Nr,_r,Fr,Ur,$r,Br,zr,jr,Wr,Gr,qr,ds=class extends events.EventEmitter{constructor(...e){let t=e[0]||{};super();c(this,qr,false);c(this,Gr,false);c(this,Wr,[]);c(this,jr,[]);c(this,zr);c(this,Br);c(this,$r);c(this,Ur);c(this,Fr,false);c(this,_r,false);c(this,Nr,false);c(this,Ir,false);c(this,Ar,null);c(this,Dr,0);c(this,Pr,false);c(this,Or);c(this,Cr,false);c(this,Lr,0);c(this,Rr,false);c(this,"writable",true);c(this,"readable",true);if(t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");ka(t)?(this[se]=true,this[Oe]=null):Ma(t)?(this[Oe]=t.encoding,this[se]=false):(this[se]=false,this[Oe]=null),this[ze]=!!t.async,this[Bt]=this[Oe]?new string_decoder.StringDecoder(this[Oe]):null,t&&t.debugExposeBuffer===true&&Object.defineProperty(this,"buffer",{get:()=>this[Y]}),t&&t.debugExposePipes===true&&Object.defineProperty(this,"pipes",{get:()=>this[oe]});let{signal:s}=t;s&&(this[oi]=s,s.aborted?this[Cs]():s.addEventListener("abort",()=>this[Cs]()));}get bufferLength(){return this[Z]}get encoding(){return this[Oe]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[se]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[ze]}set async(e){this[ze]=this[ze]||!!e;}[(qr=J,Gr=ni,Wr=oe,jr=Y,zr=se,Br=Oe,$r=ze,Ur=Bt,Fr=He,_r=rt,Nr=Ki,Ir=Ji,Ar=ri,Dr=Z,Pr=B,Or=oi,Cr=Xi,Lr=bt,Rr=ye,Cs)](){this[Xi]=true,this.emit("abort",this[oi]?.reason),this.destroy(this[oi]?.reason);}get aborted(){return this[Xi]}set aborted(e){}write(e,t,s){if(this[Xi])return false;if(this[He])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 t=="function"&&(s=t,t="utf8"),t||(t="utf8");let r=this[ze]?ai:Sa;if(!this[se]&&!Buffer.isBuffer(e)){if(Ta(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Ea(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[se]?(this[J]&&this[Z]!==0&&this[Yi](true),this[J]?this.emit("data",e):this[ks](e),this[Z]!==0&&this.emit("readable"),s&&r(s),this[J]):e.length?(typeof e=="string"&&!(t===this[Oe]&&!this[Bt]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[Oe]&&(e=this[Bt].write(e)),this[J]&&this[Z]!==0&&this[Yi](true),this[J]?this.emit("data",e):this[ks](e),this[Z]!==0&&this.emit("readable"),s&&r(s),this[J]):(this[Z]!==0&&this.emit("readable"),s&&r(s),this[J])}read(e){if(this[B])return null;if(this[ye]=false,this[Z]===0||e===0||e&&e>this[Z])return this[Ke](),null;this[se]&&(e=null),this[Y].length>1&&!this[se]&&(this[Y]=[this[Oe]?this[Y].join(""):Buffer.concat(this[Y],this[Z])]);let t=this[ur](e||null,this[Y][0]);return this[Ke](),t}[ur](e,t){if(this[se])this[Zi]();else {let s=t;e===s.length||e===null?this[Zi]():typeof s=="string"?(this[Y][0]=s.slice(e),t=s.slice(0,e),this[Z]-=e):(this[Y][0]=s.subarray(e),t=s.subarray(0,e),this[Z]-=e);}return this.emit("data",t),!this[Y].length&&!this[He]&&this.emit("drain"),t}end(e,t,s){return typeof e=="function"&&(s=e,e=void 0),typeof t=="function"&&(s=t,t="utf8"),e!==void 0&&this.write(e,t),s&&this.once("end",s),this[He]=true,this.writable=false,(this[J]||!this[ni])&&this[Ke](),this}[zt](){this[B]||(!this[bt]&&!this[oe].length&&(this[ye]=true),this[ni]=false,this[J]=true,this.emit("resume"),this[Y].length?this[Yi]():this[He]?this[Ke]():this.emit("drain"));}resume(){return this[zt]()}pause(){this[J]=false,this[ni]=true,this[ye]=false;}get destroyed(){return this[B]}get flowing(){return this[J]}get paused(){return this[ni]}[ks](e){this[se]?this[Z]+=1:this[Z]+=e.length,this[Y].push(e);}[Zi](){return this[se]?this[Z]-=1:this[Z]-=this[Y][0].length,this[Y].shift()}[Yi](e=false){do;while(this[pr](this[Zi]())&&this[Y].length);!e&&!this[Y].length&&!this[He]&&this.emit("drain");}[pr](e){return this.emit("data",e),this[J]}pipe(e,t){if(this[B])return e;this[ye]=false;let s=this[rt];return t=t||{},e===dr.stdout||e===dr.stderr?t.end=false:t.end=t.end!==false,t.proxyErrors=!!t.proxyErrors,s?t.end&&e.end():(this[oe].push(t.proxyErrors?new xa(this,e,t):new gn(this,e,t)),this[ze]?ai(()=>this[zt]()):this[zt]()),e}unpipe(e){let t=this[oe].find(s=>s.dest===e);t&&(this[oe].length===1?(this[J]&&this[bt]===0&&(this[J]=false),this[oe]=[]):this[oe].splice(this[oe].indexOf(t),1),t.unpipe());}addListener(e,t){return this.on(e,t)}on(e,t){let s=super.on(e,t);if(e==="data")this[ye]=false,this[bt]++,!this[oe].length&&!this[J]&&this[zt]();else if(e==="readable"&&this[Z]!==0)super.emit("readable");else if(va(e)&&this[rt])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[ri]){let r=t;this[ze]?ai(()=>r.call(this,this[ri])):r.call(this,this[ri]);}return s}removeListener(e,t){return this.off(e,t)}off(e,t){let s=super.off(e,t);return e==="data"&&(this[bt]=this.listeners("data").length,this[bt]===0&&!this[ye]&&!this[oe].length&&(this[J]=false)),s}removeAllListeners(e){let t=super.removeAllListeners(e);return (e==="data"||e===void 0)&&(this[bt]=0,!this[ye]&&!this[oe].length&&(this[J]=false)),t}get emittedEnd(){return this[rt]}[Ke](){!this[Ki]&&!this[rt]&&!this[B]&&this[Y].length===0&&this[He]&&(this[Ki]=true,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Ji]&&this.emit("close"),this[Ki]=false);}emit(e,...t){let s=t[0];if(e!=="error"&&e!=="close"&&e!==B&&this[B])return false;if(e==="data")return !this[se]&&!s?false:this[ze]?(ai(()=>this[Rs](s)),true):this[Rs](s);if(e==="end")return this[fr]();if(e==="close"){if(this[Ji]=true,!this[rt]&&!this[B])return false;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[ri]=s,super.emit(Ms,s);let o=!this[oi]||this.listeners("error").length?super.emit("error",s):false;return this[Ke](),o}else if(e==="resume"){let o=super.emit("resume");return this[Ke](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...t);return this[Ke](),r}[Rs](e){for(let s of this[oe])s.dest.write(e)===false&&this.pause();let t=this[ye]?false:super.emit("data",e);return this[Ke](),t}[fr](){return this[rt]?false:(this[rt]=true,this.readable=false,this[ze]?(ai(()=>this[Ls]()),true):this[Ls]())}[Ls](){if(this[Bt]){let t=this[Bt].end();if(t){for(let s of this[oe])s.dest.write(t);this[ye]||super.emit("data",t);}}for(let t of this[oe])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[se]||(e.dataLength=0);let t=this.promise();return this.on("data",s=>{e.push(s),this[se]||(e.dataLength+=s.length);}),await t,e}async concat(){if(this[se])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[Oe]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(B,()=>t(new Error("stream destroyed"))),this.on("error",s=>t(s)),this.on("end",()=>e());})}[Symbol.asyncIterator](){this[ye]=false;let e=false,t=async()=>(this.pause(),e=true,{value:void 0,done:true});return {next:()=>{if(e)return t();let s=this.read();if(s!==null)return Promise.resolve({done:false,value:s});if(this[He])return t();let r,o,a=f=>{this.off("data",h),this.off("end",l),this.off(B,d),t(),o(f);},h=f=>{this.off("error",a),this.off("end",l),this.off(B,d),this.pause(),r({value:f,done:!!this[He]});},l=()=>{this.off("error",a),this.off("data",h),this.off(B,d),t(),r({done:true,value:void 0});},d=()=>a(new Error("stream destroyed"));return new Promise((f,u)=>{o=u,r=f,this.once(B,d),this.once("error",a),this.once("end",l),this.once("data",h);})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ye]=false;let e=false,t=()=>(this.pause(),this.off(Ms,t),this.off(B,t),this.off("end",t),e=true,{done:true,value:void 0}),s=()=>{if(e)return t();let r=this.read();return r===null?t():{done:false,value:r}};return this.once("end",t),this.once(Ms,t),this.once(B,t),{next:s,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[B])return e?this.emit("error",e):this.emit(B),this;this[B]=true,this[ye]=true,this[Y].length=0,this[Z]=0;let t=this;return typeof t.close=="function"&&!this[Ji]&&t.close(),e?this.emit("error",e):this.emit(B),this}static get isStream(){return ya}},Ra=z.realpathSync.native,di={lstatSync:z.lstatSync,readdir:z.readdir,readdirSync:z.readdirSync,readlinkSync:z.readlinkSync,realpathSync:Ra,promises:{lstat:zn.lstat,readdir:zn.readdir,readlink:zn.readlink,realpath:zn.realpath}},mn=i=>!i||i===di||i===z__namespace?di:{...di,...i,promises:{...di.promises,...i.promises||{}}},yn=/^\\\\\?\\([a-z]:)\\?$/i,La=i=>i.replace(/\//g,"\\").replace(yn,"$1\\"),Ca=/[\\\/]/,Re=0,wn=1,bn=2,je=4,Sn=6,vn=8,St=10,En=12,ke=15,li=~ke,Os=16,gr=32,ui=64,Pe=128,Qi=256,ns=512,mr=ui|Pe|ns,Oa=1023,Ps=i=>i.isFile()?vn:i.isDirectory()?je:i.isSymbolicLink()?St:i.isCharacterDevice()?bn:i.isBlockDevice()?Sn:i.isSocket()?En:i.isFIFO()?wn:Re,yr=new ps({max:2**12}),pi=i=>{let e=yr.get(i);if(e)return e;let t=i.normalize("NFKD");return yr.set(i,t),t},wr=new ps({max:2**12}),es=i=>{let e=wr.get(i);if(e)return e;let t=pi(i.toLowerCase());return wr.set(i,t),t},br=class extends ps{constructor(){super({max:256});}},Pa=class extends ps{constructor(i=16*1024){super({maxSize:i,sizeCalculation:e=>e.length+1});}},Tn=Symbol("PathScurry setAsCwd"),he,bi,Si,vi,Ei,Ti,xi,ki,Mi,Ri,Li,Ci,Oi,Pi,Di,Ai,Ii,Ni,_i,ut,Rt,Ge,Ze,Xe,Qe,R,Lt,et,qe,M,$s,os,fi,Bs,zs,gi,as,js,Ws,ls,xn,kn,Mn,Gs,Jt,Yt,Rn,Ct,Vr,pe=(Vr=class{constructor(i,e=Re,t,s,r,o,a){w(this,M);c(this,"name");c(this,"root");c(this,"roots");c(this,"parent");c(this,"nocase");c(this,"isCWD",false);w(this,he);w(this,bi);w(this,Si);w(this,vi);w(this,Ei);w(this,Ti);w(this,xi);w(this,ki);w(this,Mi);w(this,Ri);w(this,Li);w(this,Ci);w(this,Oi);w(this,Pi);w(this,Di);w(this,Ai);w(this,Ii);w(this,Ni);w(this,_i);w(this,ut);w(this,Rt);w(this,Ge);w(this,Ze);w(this,Xe);w(this,Qe);w(this,R);w(this,Lt);w(this,et);w(this,qe);w(this,Jt,[]);w(this,Yt,false);w(this,Ct);this.name=i,g(this,ut,r?es(i):pi(i)),g(this,R,e&Oa),this.nocase=r,this.roots=s,this.root=t||this,g(this,Lt,o),g(this,Ge,a.fullpath),g(this,Xe,a.relative),g(this,Qe,a.relativePosix),this.parent=a.parent,this.parent?g(this,he,n(this.parent,he)):g(this,he,mn(a.fs));}get dev(){return n(this,bi)}get mode(){return n(this,Si)}get nlink(){return n(this,vi)}get uid(){return n(this,Ei)}get gid(){return n(this,Ti)}get rdev(){return n(this,xi)}get blksize(){return n(this,ki)}get ino(){return n(this,Mi)}get size(){return n(this,Ri)}get blocks(){return n(this,Li)}get atimeMs(){return n(this,Ci)}get mtimeMs(){return n(this,Oi)}get ctimeMs(){return n(this,Pi)}get birthtimeMs(){return n(this,Di)}get atime(){return n(this,Ai)}get mtime(){return n(this,Ii)}get ctime(){return n(this,Ni)}get birthtime(){return n(this,_i)}get parentPath(){return (this.parent||this).fullpath()}get path(){return this.parentPath}depth(){return n(this,Rt)!==void 0?n(this,Rt):this.parent?g(this,Rt,this.parent.depth()+1):g(this,Rt,0)}childrenCache(){return n(this,Lt)}resolve(i){var s;if(!i)return this;let e=this.getRootString(i),t=i.substring(e.length).split(this.splitSep);return e?y(s=this.getRoot(e),M,$s).call(s,t):y(this,M,$s).call(this,t)}children(){let i=n(this,Lt).get(this);if(i)return i;let e=Object.assign([],{provisional:0});return n(this,Lt).set(this,e),g(this,R,n(this,R)&~Os),e}child(i,e){if(i===""||i===".")return this;if(i==="..")return this.parent||this;let t=this.children(),s=this.nocase?es(i):pi(i);for(let h of t)if(n(h,ut)===s)return h;let r=this.parent?this.sep:"",o=n(this,Ge)?n(this,Ge)+r+i:void 0,a=this.newChild(i,Re,{...e,parent:this,fullpath:o});return this.canReaddir()||g(a,R,n(a,R)|Pe),t.push(a),a}relative(){if(this.isCWD)return "";if(n(this,Xe)!==void 0)return n(this,Xe);let i=this.name,e=this.parent;if(!e)return g(this,Xe,this.name);let t=e.relative();return t+(!t||!e.parent?"":this.sep)+i}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return "";if(n(this,Qe)!==void 0)return n(this,Qe);let i=this.name,e=this.parent;if(!e)return g(this,Qe,this.fullpathPosix());let t=e.relativePosix();return t+(!t||!e.parent?"":"/")+i}fullpath(){if(n(this,Ge)!==void 0)return n(this,Ge);let i=this.name,e=this.parent;if(!e)return g(this,Ge,this.name);let t=e.fullpath()+(e.parent?this.sep:"")+i;return g(this,Ge,t)}fullpathPosix(){if(n(this,Ze)!==void 0)return n(this,Ze);if(this.sep==="/")return g(this,Ze,this.fullpath());if(!this.parent){let s=this.fullpath().replace(/\\/g,"/");return /^[a-z]:\//i.test(s)?g(this,Ze,`//?/${s}`):g(this,Ze,s)}let i=this.parent,e=i.fullpathPosix(),t=e+(!e||!i.parent?"":"/")+this.name;return g(this,Ze,t)}isUnknown(){return (n(this,R)&ke)===Re}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,R)&ke)===vn}isDirectory(){return (n(this,R)&ke)===je}isCharacterDevice(){return (n(this,R)&ke)===bn}isBlockDevice(){return (n(this,R)&ke)===Sn}isFIFO(){return (n(this,R)&ke)===wn}isSocket(){return (n(this,R)&ke)===En}isSymbolicLink(){return (n(this,R)&St)===St}lstatCached(){return n(this,R)&gr?this:void 0}readlinkCached(){return n(this,et)}realpathCached(){return n(this,qe)}readdirCached(){let i=this.children();return i.slice(0,i.provisional)}canReadlink(){if(n(this,et))return true;if(!this.parent)return false;let i=n(this,R)&ke;return !(i!==Re&&i!==St||n(this,R)&Qi||n(this,R)&Pe)}calledReaddir(){return !!(n(this,R)&Os)}isENOENT(){return !!(n(this,R)&Pe)}isNamed(i){return this.nocase?n(this,ut)===es(i):n(this,ut)===pi(i)}async readlink(){let i=n(this,et);if(i)return i;if(this.canReadlink()&&this.parent)try{let e=await n(this,he).promises.readlink(this.fullpath()),t=(await this.parent.realpath())?.resolve(e);if(t)return g(this,et,t)}catch(e){y(this,M,Ws).call(this,e.code);return}}readlinkSync(){let i=n(this,et);if(i)return i;if(this.canReadlink()&&this.parent)try{let e=n(this,he).readlinkSync(this.fullpath()),t=this.parent.realpathSync()?.resolve(e);if(t)return g(this,et,t)}catch(e){y(this,M,Ws).call(this,e.code);return}}async lstat(){if((n(this,R)&Pe)===0)try{return y(this,M,Gs).call(this,await n(this,he).promises.lstat(this.fullpath())),this}catch(i){y(this,M,js).call(this,i.code);}}lstatSync(){if((n(this,R)&Pe)===0)try{return y(this,M,Gs).call(this,n(this,he).lstatSync(this.fullpath())),this}catch(i){y(this,M,js).call(this,i.code);}}readdirCB(i,e=false){if(!this.canReaddir()){e?i(null,[]):queueMicrotask(()=>i(null,[]));return}let t=this.children();if(this.calledReaddir()){let r=t.slice(0,t.provisional);e?i(null,r):queueMicrotask(()=>i(null,r));return}if(n(this,Jt).push(i),n(this,Yt))return;g(this,Yt,true);let s=this.fullpath();n(this,he).readdir(s,{withFileTypes:true},(r,o)=>{if(r)y(this,M,as).call(this,r.code),t.provisional=0;else {for(let a of o)y(this,M,ls).call(this,a,t);y(this,M,os).call(this,t);}y(this,M,Rn).call(this,t.slice(0,t.provisional));});}async readdir(){if(!this.canReaddir())return [];let i=this.children();if(this.calledReaddir())return i.slice(0,i.provisional);let e=this.fullpath();if(n(this,Ct))await n(this,Ct);else {let t=()=>{};g(this,Ct,new Promise(s=>t=s));try{for(let s of await n(this,he).promises.readdir(e,{withFileTypes:!0}))y(this,M,ls).call(this,s,i);y(this,M,os).call(this,i);}catch(s){y(this,M,as).call(this,s.code),i.provisional=0;}g(this,Ct,void 0),t();}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 e=this.fullpath();try{for(let t of n(this,he).readdirSync(e,{withFileTypes:!0}))y(this,M,ls).call(this,t,i);y(this,M,os).call(this,i);}catch(t){y(this,M,as).call(this,t.code),i.provisional=0;}return i.slice(0,i.provisional)}canReaddir(){if(n(this,R)&mr)return false;let i=ke&n(this,R);return i===Re||i===je||i===St}shouldWalk(i,e){return (n(this,R)&je)===je&&!(n(this,R)&mr)&&!i.has(this)&&(!e||e(this))}async realpath(){if(n(this,qe))return n(this,qe);if(!((ns|Qi|Pe)&n(this,R)))try{let i=await n(this,he).promises.realpath(this.fullpath());return g(this,qe,this.resolve(i))}catch{y(this,M,zs).call(this);}}realpathSync(){if(n(this,qe))return n(this,qe);if(!((ns|Qi|Pe)&n(this,R)))try{let i=n(this,he).realpathSync(this.fullpath());return g(this,qe,this.resolve(i))}catch{y(this,M,zs).call(this);}}[Tn](i){if(i===this)return;i.isCWD=false,this.isCWD=true;let e=new Set([]),t=[],s=this;for(;s&&s.parent;)e.add(s),g(s,Xe,t.join(this.sep)),g(s,Qe,t.join("/")),s=s.parent,t.push("..");for(s=i;s&&s.parent&&!e.has(s);)g(s,Xe,void 0),g(s,Qe,void 0),s=s.parent;}},he=new WeakMap,bi=new WeakMap,Si=new WeakMap,vi=new WeakMap,Ei=new WeakMap,Ti=new WeakMap,xi=new WeakMap,ki=new WeakMap,Mi=new WeakMap,Ri=new WeakMap,Li=new WeakMap,Ci=new WeakMap,Oi=new WeakMap,Pi=new WeakMap,Di=new WeakMap,Ai=new WeakMap,Ii=new WeakMap,Ni=new WeakMap,_i=new WeakMap,ut=new WeakMap,Rt=new WeakMap,Ge=new WeakMap,Ze=new WeakMap,Xe=new WeakMap,Qe=new WeakMap,R=new WeakMap,Lt=new WeakMap,et=new WeakMap,qe=new WeakMap,M=new WeakSet,$s=function(i){let e=this;for(let t of i)e=e.child(t);return e},os=function(i){var e;g(this,R,n(this,R)|Os);for(let t=i.provisional;t<i.length;t++){let s=i[t];s&&y(e=s,M,fi).call(e);}},fi=function(){n(this,R)&Pe||(g(this,R,(n(this,R)|Pe)&li),y(this,M,Bs).call(this));},Bs=function(){var e;let i=this.children();i.provisional=0;for(let t of i)y(e=t,M,fi).call(e);},zs=function(){g(this,R,n(this,R)|ns),y(this,M,gi).call(this);},gi=function(){if(n(this,R)&ui)return;let i=n(this,R);(i&ke)===je&&(i&=li),g(this,R,i|ui),y(this,M,Bs).call(this);},as=function(i=""){i==="ENOTDIR"||i==="EPERM"?y(this,M,gi).call(this):i==="ENOENT"?y(this,M,fi).call(this):this.children().provisional=0;},js=function(i=""){var e;i==="ENOTDIR"?y(e=this.parent,M,gi).call(e):i==="ENOENT"&&y(this,M,fi).call(this);},Ws=function(i=""){var t;let e=n(this,R);e|=Qi,i==="ENOENT"&&(e|=Pe),(i==="EINVAL"||i==="UNKNOWN")&&(e&=li),g(this,R,e),i==="ENOTDIR"&&this.parent&&y(t=this.parent,M,gi).call(t);},ls=function(i,e){return y(this,M,kn).call(this,i,e)||y(this,M,xn).call(this,i,e)},xn=function(i,e){let t=Ps(i),s=this.newChild(i.name,t,{parent:this}),r=n(s,R)&ke;return r!==je&&r!==St&&r!==Re&&g(s,R,n(s,R)|ui),e.unshift(s),e.provisional++,s},kn=function(i,e){for(let t=e.provisional;t<e.length;t++){let s=e[t];if((this.nocase?es(i.name):pi(i.name))===n(s,ut))return y(this,M,Mn).call(this,i,s,t,e)}},Mn=function(i,e,t,s){let r=e.name;return g(e,R,n(e,R)&li|Ps(i)),r!==i.name&&(e.name=i.name),t!==s.provisional&&(t===s.length-1?s.pop():s.splice(t,1),s.unshift(e)),s.provisional++,e},Gs=function(i){let{atime:e,atimeMs:t,birthtime:s,birthtimeMs:r,blksize:o,blocks:a,ctime:h,ctimeMs:l,dev:d,gid:f,ino:u,mode:p,mtime:m,mtimeMs:b,nlink:S,rdev:x,size:v,uid:k}=i;g(this,Ai,e),g(this,Ci,t),g(this,_i,s),g(this,Di,r),g(this,ki,o),g(this,Li,a),g(this,Ni,h),g(this,Pi,l),g(this,bi,d),g(this,Ti,f),g(this,Mi,u),g(this,Si,p),g(this,Ii,m),g(this,Oi,b),g(this,vi,S),g(this,xi,x),g(this,Ri,v),g(this,Ei,k);let C=Ps(i);g(this,R,n(this,R)&li|C|gr),C!==Re&&C!==je&&C!==St&&g(this,R,n(this,R)|ui);},Jt=new WeakMap,Yt=new WeakMap,Rn=function(i){g(this,Yt,false);let e=n(this,Jt).slice();n(this,Jt).length=0,e.forEach(t=>t(null,i));},Ct=new WeakMap,Vr),Ln=class Cn extends pe{constructor(t,s=Re,r,o,a,h,l){super(t,s,r,o,a,h,l);c(this,"sep","\\");c(this,"splitSep",Ca);}newChild(t,s=Re,r={}){return new Cn(t,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}getRootString(t){return ii.win32.parse(t).root}getRoot(t){if(t=La(t.toUpperCase()),t===this.root.name)return this.root;for(let[s,r]of Object.entries(this.roots))if(this.sameRoot(t,s))return this.roots[t]=r;return this.roots[t]=new Js(t,this).root}sameRoot(t,s=this.root.name){return t=t.toUpperCase().replace(/\//g,"\\").replace(yn,"$1\\"),t===s}},On=class Pn extends pe{constructor(t,s=Re,r,o,a,h,l){super(t,s,r,o,a,h,l);c(this,"splitSep","/");c(this,"sep","/");}getRootString(t){return t.startsWith("/")?"/":""}getRoot(t){return this.root}newChild(t,s=Re,r={}){return new Pn(t,s,this.root,this.roots,this.nocase,this.childrenCache(),r)}},Zt,Xt,Fi,Ui,Hr,Dn=(Hr=class{constructor(i=process.cwd(),e,t,{nocase:s,childrenCacheSize:r=16*1024,fs:o=di}={}){c(this,"root");c(this,"rootPath");c(this,"roots");c(this,"cwd");w(this,Zt);w(this,Xt);w(this,Fi);c(this,"nocase");w(this,Ui);g(this,Ui,mn(o)),(i instanceof URL||i.startsWith("file://"))&&(i=url.fileURLToPath(i));let a=e.resolve(i);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),g(this,Zt,new br),g(this,Xt,new br),g(this,Fi,new Pa(r));let h=a.substring(this.rootPath.length).split(t);if(h.length===1&&!h[0]&&h.pop(),s===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=s,this.root=this.newRoot(n(this,Ui)),this.roots[this.rootPath]=this.root;let l=this.root,d=h.length-1,f=e.sep,u=this.rootPath,p=false;for(let m of h){let b=d--;l=l.child(m,{relative:new Array(b).fill("..").join(f),relativePosix:new Array(b).fill("..").join("/"),fullpath:u+=(p?"":f)+m}),p=true;}this.cwd=l;}depth(i=this.cwd){return typeof i=="string"&&(i=this.cwd.resolve(i)),i.depth()}childrenCache(){return n(this,Fi)}resolve(...i){let e="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(e=e?`${o}/${e}`:o,this.isAbsolute(o)))break}let t=n(this,Zt).get(e);if(t!==void 0)return t;let s=this.cwd.resolve(e).fullpath();return n(this,Zt).set(e,s),s}resolvePosix(...i){let e="";for(let r=i.length-1;r>=0;r--){let o=i[r];if(!(!o||o===".")&&(e=e?`${o}/${e}`:o,this.isAbsolute(o)))break}let t=n(this,Xt).get(e);if(t!==void 0)return t;let s=this.cwd.resolve(e).fullpathPosix();return n(this,Xt).set(e,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,e={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t}=e;if(i.canReaddir()){let s=await i.readdir();return t?s:s.map(r=>r.name)}else return []}readdirSync(i=this.cwd,e={withFileTypes:true}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true}=e;return i.canReaddir()?t?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:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=await i.readlink();return e?t:t?.fullpath()}readlinkSync(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=i.readlinkSync();return e?t:t?.fullpath()}async realpath(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=await i.realpath();return e?t:t?.fullpath()}realpathSync(i=this.cwd,{withFileTypes:e}={withFileTypes:false}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i.withFileTypes,i=this.cwd);let t=i.realpathSync();return e?t:t?.fullpath()}async walk(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=[];(!r||r(i))&&a.push(t?i:i.fullpath());let h=new Set,l=(f,u)=>{h.add(f),f.readdirCB((p,m)=>{if(p)return u(p);let b=m.length;if(!b)return u();let S=()=>{--b===0&&u();};for(let x of m)(!r||r(x))&&a.push(t?x:x.fullpath()),s&&x.isSymbolicLink()?x.realpath().then(v=>v?.isUnknown()?v.lstat():v).then(v=>v?.shouldWalk(h,o)?l(v,S):S()):x.shouldWalk(h,o)?l(x,S):S();},true);},d=i;return new Promise((f,u)=>{l(d,p=>{if(p)return u(p);f(a);});})}walkSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=[];(!r||r(i))&&a.push(t?i:i.fullpath());let h=new Set([i]);for(let l of h){let d=l.readdirSync();for(let f of d){(!r||r(f))&&a.push(t?f:f.fullpath());let u=f;if(f.isSymbolicLink()){if(!(s&&(u=f.realpathSync())))continue;u.isUnknown()&&u.lstatSync();}u.shouldWalk(h,o)&&h.add(u);}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(i=this.cwd,e={}){return typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd),this.stream(i,e)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e;(!r||r(i))&&(yield t?i:i.fullpath());let a=new Set([i]);for(let h of a){let l=h.readdirSync();for(let d of l){(!r||r(d))&&(yield t?d:d.fullpath());let f=d;if(d.isSymbolicLink()){if(!(s&&(f=d.realpathSync())))continue;f.isUnknown()&&f.lstatSync();}f.shouldWalk(a,o)&&a.add(f);}}}stream(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=new ds({objectMode:true});(!r||r(i))&&a.write(t?i:i.fullpath());let h=new Set,l=[i],d=0,f=()=>{let u=false;for(;!u;){let p=l.shift();if(!p){d===0&&a.end();return}d++,h.add(p);let m=(S,x,v=false)=>{if(S)return a.emit("error",S);if(s&&!v){let k=[];for(let C of x)C.isSymbolicLink()&&k.push(C.realpath().then(O=>O?.isUnknown()?O.lstat():O));if(k.length){Promise.all(k).then(()=>m(null,x,true));return}}for(let k of x)k&&(!r||r(k))&&(a.write(t?k:k.fullpath())||(u=true));d--;for(let k of x){let C=k.realpathCached()||k;C.shouldWalk(h,o)&&l.push(C);}u&&!a.flowing?a.once("drain",f):b||f();},b=true;p.readdirCB(m,true),b=false;}};return f(),a}streamSync(i=this.cwd,e={}){typeof i=="string"?i=this.cwd.resolve(i):i instanceof pe||(e=i,i=this.cwd);let{withFileTypes:t=true,follow:s=false,filter:r,walkFilter:o}=e,a=new ds({objectMode:true}),h=new Set;(!r||r(i))&&a.write(t?i:i.fullpath());let l=[i],d=0,f=()=>{let u=false;for(;!u;){let p=l.shift();if(!p){d===0&&a.end();return}d++,h.add(p);let m=p.readdirSync();for(let b of m)(!r||r(b))&&(a.write(t?b:b.fullpath())||(u=true));d--;for(let b of m){let S=b;if(b.isSymbolicLink()){if(!(s&&(S=b.realpathSync())))continue;S.isUnknown()&&S.lstatSync();}S.shouldWalk(h,o)&&l.push(S);}}u&&!a.flowing&&a.once("drain",f);};return f(),a}chdir(i=this.cwd){let e=this.cwd;this.cwd=typeof i=="string"?this.cwd.resolve(i):i,this.cwd[Tn](e);}},Zt=new WeakMap,Xt=new WeakMap,Fi=new WeakMap,Ui=new WeakMap,Hr),Js=class extends Dn{constructor(e=process.cwd(),t={}){let{nocase:s=true}=t;super(e,ii.win32,"\\",{...t,nocase:s});c(this,"sep","\\");this.nocase=s;for(let r=this.cwd;r;r=r.parent)r.nocase=this.nocase;}parseRootPath(e){return ii.win32.parse(e).root.toUpperCase()}newRoot(e){return new Ln(this.rootPath,je,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")||e.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(e)}},Ys=class extends Dn{constructor(e=process.cwd(),t={}){let{nocase:s=false}=t;super(e,ii.posix,"/",{...t,nocase:s});c(this,"sep","/");this.nocase=s;}parseRootPath(e){return "/"}newRoot(e){return new On(this.rootPath,je,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")}},An=class extends Ys{constructor(i=process.cwd(),e={}){let{nocase:t=true}=e;super(i,{...e,nocase:t});}};process.platform==="win32"?Ln:On;var Da=process.platform==="win32"?Js:process.platform==="darwin"?An:Ys,Aa=i=>i.length>=1,Ia=i=>i.length>=1,Na=Symbol.for("nodejs.util.inspect.custom"),H,fe,K,Ot,Be,$i,pt,ft,gt,Qt,ei,In=(ei=class{constructor(e,t,s,r){w(this,H);w(this,fe);w(this,K);c(this,"length");w(this,Ot);w(this,Be);w(this,$i);w(this,pt);w(this,ft);w(this,gt);w(this,Qt,true);if(!Aa(e))throw new TypeError("empty pattern list");if(!Ia(t))throw new TypeError("empty glob list");if(t.length!==e.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=e.length,s<0||s>=this.length)throw new TypeError("index out of range");if(g(this,H,e),g(this,fe,t),g(this,K,s),g(this,Ot,r),n(this,K)===0){if(this.isUNC()){let[o,a,h,l,...d]=n(this,H),[f,u,p,m,...b]=n(this,fe);d[0]===""&&(d.shift(),b.shift());let S=[o,a,h,l,""].join("/"),x=[f,u,p,m,""].join("/");g(this,H,[S,...d]),g(this,fe,[x,...b]),this.length=n(this,H).length;}else if(this.isDrive()||this.isAbsolute()){let[o,...a]=n(this,H),[h,...l]=n(this,fe);a[0]===""&&(a.shift(),l.shift());let d=o+"/",f=h+"/";g(this,H,[d,...a]),g(this,fe,[f,...l]),this.length=n(this,H).length;}}}[Na](){return "Pattern <"+n(this,fe).slice(n(this,K)).join("/")+">"}pattern(){return n(this,H)[n(this,K)]}isString(){return typeof n(this,H)[n(this,K)]=="string"}isGlobstar(){return n(this,H)[n(this,K)]===ce}isRegExp(){return n(this,H)[n(this,K)]instanceof RegExp}globString(){return g(this,$i,n(this,$i)||(n(this,K)===0?this.isAbsolute()?n(this,fe)[0]+n(this,fe).slice(1).join("/"):n(this,fe).join("/"):n(this,fe).slice(n(this,K)).join("/")))}hasMore(){return this.length>n(this,K)+1}rest(){return n(this,Be)!==void 0?n(this,Be):this.hasMore()?(g(this,Be,new ei(n(this,H),n(this,fe),n(this,K)+1,n(this,Ot))),g(n(this,Be),gt,n(this,gt)),g(n(this,Be),ft,n(this,ft)),g(n(this,Be),pt,n(this,pt)),n(this,Be)):g(this,Be,null)}isUNC(){let e=n(this,H);return n(this,ft)!==void 0?n(this,ft):g(this,ft,n(this,Ot)==="win32"&&n(this,K)===0&&e[0]===""&&e[1]===""&&typeof e[2]=="string"&&!!e[2]&&typeof e[3]=="string"&&!!e[3])}isDrive(){let e=n(this,H);return n(this,pt)!==void 0?n(this,pt):g(this,pt,n(this,Ot)==="win32"&&n(this,K)===0&&this.length>1&&typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]))}isAbsolute(){let e=n(this,H);return n(this,gt)!==void 0?n(this,gt):g(this,gt,e[0]===""&&e.length>1||this.isDrive()||this.isUNC())}root(){let e=n(this,H)[0];return typeof e=="string"&&this.isAbsolute()&&n(this,K)===0?e:""}checkFollowGlobstar(){return !(n(this,K)===0||!this.isGlobstar()||!n(this,Qt))}markFollowGlobstar(){return n(this,K)===0||!this.isGlobstar()||!n(this,Qt)?false:(g(this,Qt,false),true)}},H=new WeakMap,fe=new WeakMap,K=new WeakMap,Ot=new WeakMap,Be=new WeakMap,$i=new WeakMap,pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,Qt=new WeakMap,ei),_a=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",Sr=class{constructor(i,{nobrace:e,nocase:t,noext:s,noglobstar:r,platform:o=_a}){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:e,nocase:t,noext:s,noglobstar:r,optimizationLevel:2,platform:o,nocomment:true,nonegate:true};for(let a of i)this.add(a);}add(i){let e=new yt(i,this.mmopts);for(let t=0;t<e.set.length;t++){let s=e.set[t],r=e.globParts[t];if(!s||!r)throw new Error("invalid pattern object");for(;s[0]==="."&&r[0]===".";)s.shift(),r.shift();let o=new In(s,r,0,this.platform),a=new yt(o.globString(),this.mmopts),h=r[r.length-1]==="**",l=o.isAbsolute();l?this.absolute.push(a):this.relative.push(a),h&&(l?this.absoluteChildren.push(a):this.relativeChildren.push(a));}}ignored(i){let e=i.fullpath(),t=`${e}/`,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(e)||o.match(t))return true;return false}childrenIgnored(i){let e=i.fullpath()+"/",t=(i.relative()||".")+"/";for(let s of this.relativeChildren)if(s.match(t))return true;for(let s of this.absoluteChildren)if(s.match(e))return true;return false}},Fa=class Nn{constructor(e=new Map){c(this,"store");this.store=e;}copy(){return new Nn(new Map(this.store))}hasWalked(e,t){return this.store.get(e.fullpath())?.has(t.globString())}storeWalked(e,t){let s=e.fullpath(),r=this.store.get(s);r?r.add(t.globString()):this.store.set(s,new Set([t.globString()]));}},Ua=class{constructor(){c(this,"store",new Map);}add(i,e,t){let s=(e?2:0)|(t?1:0),r=this.store.get(i);this.store.set(i,r===void 0?s:s&r);}entries(){return [...this.store.entries()].map(([i,e])=>[i,!!(e&2),!!(e&1)])}},$a=class{constructor(){c(this,"store",new Map);}add(i,e){if(!i.canReaddir())return;let t=this.store.get(i);t?t.find(s=>s.globString()===e.globString())||t.push(e):this.store.set(i,[e]);}get(i){let e=this.store.get(i);if(!e)throw new Error("attempting to walk unknown path");return e}entries(){return this.keys().map(i=>[i,this.store.get(i)])}keys(){return [...this.store.keys()].filter(i=>i.canReaddir())}},vr=class _n{constructor(e,t){c(this,"hasWalkedCache");c(this,"matches",new Ua);c(this,"subwalks",new $a);c(this,"patterns");c(this,"follow");c(this,"dot");c(this,"opts");this.opts=e,this.follow=!!e.follow,this.dot=!!e.dot,this.hasWalkedCache=t?t.copy():new Fa;}processPatterns(e,t){this.patterns=t;let s=t.map(r=>[e,r]);for(let[r,o]of s){this.hasWalkedCache.storeWalked(r,o);let a=o.root(),h=o.isAbsolute()&&this.opts.absolute!==false;if(a){r=r.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let u=o.rest();if(u)o=u;else {this.matches.add(r,true,false);continue}}if(r.isENOENT())continue;let l,d,f=false;for(;typeof(l=o.pattern())=="string"&&(d=o.rest());)r=r.resolve(l),o=d,f=true;if(l=o.pattern(),d=o.rest(),f){if(this.hasWalkedCache.hasWalked(r,o))continue;this.hasWalkedCache.storeWalked(r,o);}if(typeof l=="string"){let u=l===".."||l===""||l===".";this.matches.add(r.resolve(l),h,u);continue}else if(l===ce){(!r.isSymbolicLink()||this.follow||o.checkFollowGlobstar())&&this.subwalks.add(r,o);let u=d?.pattern(),p=d?.rest();if(!d||(u===""||u===".")&&!p)this.matches.add(r,h,u===""||u===".");else if(u===".."){let m=r.parent||r;p?this.hasWalkedCache.hasWalked(m,p)||this.subwalks.add(m,p):this.matches.add(m,h,true);}}else l instanceof RegExp&&this.subwalks.add(r,o);}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new _n(this.opts,this.hasWalkedCache)}filterEntries(e,t){let s=this.subwalks.get(e),r=this.child();for(let o of t)for(let a of s){let h=a.isAbsolute(),l=a.pattern(),d=a.rest();l===ce?r.testGlobstar(o,a,d,h):l instanceof RegExp?r.testRegExp(o,l,d,h):r.testString(o,l,d,h);}return r}testGlobstar(e,t,s,r){if((this.dot||!e.name.startsWith("."))&&(t.hasMore()||this.matches.add(e,r,false),e.canReaddir()&&(this.follow||!e.isSymbolicLink()?this.subwalks.add(e,t):e.isSymbolicLink()&&(s&&t.checkFollowGlobstar()?this.subwalks.add(e,s):t.markFollowGlobstar()&&this.subwalks.add(e,t)))),s){let o=s.pattern();if(typeof o=="string"&&o!==".."&&o!==""&&o!==".")this.testString(e,o,s.rest(),r);else if(o===".."){let a=e.parent||e;this.subwalks.add(a,s);}else o instanceof RegExp&&this.testRegExp(e,o,s.rest(),r);}}testRegExp(e,t,s,r){t.test(e.name)&&(s?this.subwalks.add(e,s):this.matches.add(e,r,false));}testString(e,t,s,r){e.isNamed(t)&&(s?this.subwalks.add(e,s):this.matches.add(e,r,false));}},Ba=(i,e)=>typeof i=="string"?new Sr([i],e):Array.isArray(i)?new Sr(i,e):i,ti,tt,Pt,Le,vt,qs,Kr,Fn=(Kr=class{constructor(i,e,t){w(this,Le);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,tt);w(this,Pt);c(this,"signal");c(this,"maxDepth");c(this,"includeChildMatches");if(this.patterns=i,this.path=e,this.opts=t,g(this,Pt,!t.posix&&t.platform==="win32"?"\\":"/"),this.includeChildMatches=t.includeChildMatches!==false,(t.ignore||!this.includeChildMatches)&&(g(this,tt,Ba(t.ignore??[],t)),!this.includeChildMatches&&typeof n(this,tt).add!="function")){let s="cannot ignore child matches, ignore lacks add() method.";throw new Error(s)}this.maxDepth=t.maxDepth||1/0,t.signal&&(this.signal=t.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,e){if(e&&this.opts.nodir)return;let t;if(this.opts.realpath){if(t=i.realpathCached()||await i.realpath(),!t)return;i=t;}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,e)}matchCheckTest(i,e){return i&&(this.maxDepth===1/0||i.depth()<=this.maxDepth)&&(!e||i.canReaddir())&&(!this.opts.nodir||!i.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!i.isSymbolicLink()||!i.realpathCached()?.isDirectory())&&!y(this,Le,vt).call(this,i)?i:void 0}matchCheckSync(i,e){if(e&&this.opts.nodir)return;let t;if(this.opts.realpath){if(t=i.realpathCached()||i.realpathSync(),!t)return;i=t;}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,e)}matchFinish(i,e){if(y(this,Le,vt).call(this,i))return;if(!this.includeChildMatches&&n(this,tt)?.add){let r=`${i.relativePosix()}/**`;n(this,tt).add(r);}let t=this.opts.absolute===void 0?e:this.opts.absolute;this.seen.add(i);let s=this.opts.mark&&i.isDirectory()?n(this,Pt):"";if(this.opts.withFileTypes)this.matchEmit(i);else if(t){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,Pt))?"."+n(this,Pt):"";this.matchEmit(r?o+r+s:"."+s);}}async match(i,e,t){let s=await this.matchCheck(i,t);s&&this.matchFinish(s,e);}matchSync(i,e,t){let s=this.matchCheckSync(i,t);s&&this.matchFinish(s,e);}walkCB(i,e,t){this.signal?.aborted&&t(),this.walkCB2(i,e,new vr(this.opts),t);}walkCB2(i,e,t,s){if(y(this,Le,qs).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2(i,e,t,s));return}t.processPatterns(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,vt).call(this,a)||(r++,this.match(a,h,l).then(()=>o()));for(let a of t.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let h=a.readdirCached();a.calledReaddir()?this.walkCB3(a,h,t,o):a.readdirCB((l,d)=>this.walkCB3(a,d,t,o),true);}o();}walkCB3(i,e,t,s){t=t.filterEntries(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,vt).call(this,a)||(r++,this.match(a,h,l).then(()=>o()));for(let[a,h]of t.subwalks.entries())r++,this.walkCB2(a,h,t.child(),o);o();}walkCBSync(i,e,t){this.signal?.aborted&&t(),this.walkCB2Sync(i,e,new vr(this.opts),t);}walkCB2Sync(i,e,t,s){if(y(this,Le,qs).call(this,i))return s();if(this.signal?.aborted&&s(),this.paused){this.onResume(()=>this.walkCB2Sync(i,e,t,s));return}t.processPatterns(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,vt).call(this,a)||this.matchSync(a,h,l);for(let a of t.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;r++;let h=a.readdirSync();this.walkCB3Sync(a,h,t,o);}o();}walkCB3Sync(i,e,t,s){t=t.filterEntries(i,e);let r=1,o=()=>{--r===0&&s();};for(let[a,h,l]of t.matches.entries())y(this,Le,vt).call(this,a)||this.matchSync(a,h,l);for(let[a,h]of t.subwalks.entries())r++,this.walkCB2Sync(a,h,t.child(),o);o();}},ti=new WeakMap,tt=new WeakMap,Pt=new WeakMap,Le=new WeakSet,vt=function(i){return this.seen.has(i)||!!n(this,tt)?.ignored?.(i)},qs=function(i){return !!n(this,tt)?.childrenIgnored?.(i)},Kr),Er=class extends Fn{constructor(e,t,s){super(e,t,s);c(this,"matches",new Set);}matchEmit(e){this.matches.add(e);}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((e,t)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?t(this.signal.reason):e(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}},Tr=class extends Fn{constructor(e,t,s){super(e,t,s);c(this,"results");this.results=new ds({signal:this.signal,objectMode:true}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume());}matchEmit(e){this.results.write(e),this.results.flowing||this.pause();}stream(){let e=this.path;return e.isUnknown()?e.lstat().then(()=>{this.walkCB(e,this.patterns,()=>this.results.end());}):this.walkCB(e,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}},za=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",At=class{constructor(i,e){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(!e)throw new TypeError("glob options required");if(this.withFileTypes=!!e.withFileTypes,this.signal=e.signal,this.follow=!!e.follow,this.dot=!!e.dot,this.dotRelative=!!e.dotRelative,this.nodir=!!e.nodir,this.mark=!!e.mark,e.cwd?(e.cwd instanceof URL||e.cwd.startsWith("file://"))&&(e.cwd=url.fileURLToPath(e.cwd)):this.cwd="",this.cwd=e.cwd||"",this.root=e.root,this.magicalBraces=!!e.magicalBraces,this.nobrace=!!e.nobrace,this.noext=!!e.noext,this.realpath=!!e.realpath,this.absolute=e.absolute,this.includeChildMatches=e.includeChildMatches!==false,this.noglobstar=!!e.noglobstar,this.matchBase=!!e.matchBase,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:1/0,this.stat=!!e.stat,this.ignore=e.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");if(typeof i=="string"&&(i=[i]),this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===false,this.windowsPathsNoEscape&&(i=i.map(h=>h.replace(/\\/g,"/"))),this.matchBase){if(e.noglobstar)throw new TypeError("base matching requires globstar");i=i.map(h=>h.includes("/")?h:`./**/${h}`);}if(this.pattern=i,this.platform=e.platform||za,this.opts={...e,platform:this.platform},e.scurry){if(this.scurry=e.scurry,e.nocase!==void 0&&e.nocase!==e.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else {let h=e.platform==="win32"?Js:e.platform==="darwin"?An:e.platform?Ys:Da;this.scurry=new h(this.cwd,{nocase:e.nocase,fs:e.fs});}this.nocase=this.scurry.nocase;let t=this.platform==="darwin"||this.platform==="win32",s={braceExpandMax:1e4,...e,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:t,nocomment:true,noext:this.noext,nonegate:true,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape,debug:!!this.opts.debug},r=this.pattern.map(h=>new yt(h,s)),[o,a]=r.reduce((h,l)=>(h[0].push(...l.set),h[1].push(...l.globParts),h),[[],[]]);this.patterns=o.map((h,l)=>{let d=a[l];if(!d)throw new Error("invalid pattern object");return new In(h,d,0,this.platform)});}async walk(){return [...await new Er(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 Er(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 Tr(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 Tr(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()}},ja=(i,e={})=>{Array.isArray(i)||(i=[i]);for(let t of i)if(new yt(t,e).hasMagic())return true;return false};function fs(i,e={}){return new At(i,e).streamSync()}function Un(i,e={}){return new At(i,e).stream()}function $n(i,e={}){return new At(i,e).walkSync()}async function xr(i,e={}){return new At(i,e).walk()}function gs(i,e={}){return new At(i,e).iterateSync()}function Bn(i,e={}){return new At(i,e).iterate()}var Wa=fs,Ga=Object.assign(Un,{sync:fs}),qa=gs,Va=Object.assign(Bn,{sync:gs}),Ha=Object.assign($n,{stream:fs,iterate:gs}),us=Object.assign(xr,{glob:xr,globSync:$n,sync:Ha,globStream:Un,stream:Ga,globStreamSync:fs,streamSync:Wa,globIterate:Bn,iterate:Va,globIterateSync:gs,iterateSync:qa,Glob:At,hasMagic:ja,escape:nn,unescape:jt});us.glob=us;var Ce;(D=>{D.Level=Ja__default.default.enum(["DEBUG","INFO","WARN","ERROR"]).meta({ref:"LogLevel",description:"Log level"});let e={DEBUG:0,INFO:1,WARN:2,ERROR:3},t="INFO";function s(P){return e[P]>=e[t]}function r(){return t}D.getLevel=r;let o=new Map;D.Default=O({service:"default"});let h="";function l(){return h}D.file=l;let d,f,u=false,p=()=>{},m=false,b=false;async function S(P){if(u)return;if(P.print){u=true;return}P.level&&(t=P.level);let F=P.logDir||ii__namespace.default.join(process.env.EASBOT_LOG_PATH??process.cwd(),"logs");P.logFile?h=ii__namespace.default.join(F,P.logFile??"local-model-sdk.log"):h=ii__namespace.default.join(F,"local-model-sdk.log");try{await zn__default.default.mkdir(F,{recursive:!0}),d=await zn__default.default.open(h,"a"),f=z.createWriteStream("",{fd:d.fd,autoClose:!1}),p=$=>{if(!(m||b||!f||f.destroyed))try{if(!f.writable)return;f.write($,ie=>{if(ie&&!m){let A=ie;if(A.code==="EPIPE"||A.code==="EIO"){b=!0,f?.destroy();return}m=!0,setTimeout(()=>{m=!1;},1e3);}});}catch(ie){let A=ie;if(A.code==="EPIPE"||A.code==="EIO"){b=!0,f?.destroy();return}m||(m=!0,setTimeout(()=>{m=!1;},1e3));}},u=!0;}catch{p=$=>{try{process.stderr.write($);}catch{}},u=true;}}D.init=S;async function x(){u&&(f&&!f.destroyed&&(await new Promise((P,F)=>{f.end($=>{$?F($):P();});}).catch(()=>{}),f=void 0),d&&(await d.close().catch(()=>{}),d=void 0),p=P=>{try{process.stderr.write(P);}catch{}},u=false);}D.close=x;function k(P,F=0){let $=P.message;return P.cause instanceof Error&&F<10?$+" Caused by: "+k(P.cause,F+1):$}let C=Date.now();function O(P){P=P||{};let F=P.service;if(F&&typeof F=="string"){let A=o.get(F);if(A)return A}function $(A,ue){let vs=Object.entries({...P,...ue}).filter(([er,st])=>st!=null).map(([er,st])=>{let Es=`${er}=`;return st instanceof Error?Es+k(st):typeof st=="object"?Es+JSON.stringify(st):Es+st}).join(" "),Ut=new Date,Hn=Ut.getTime()-C;return C=Ut.getTime(),[utils.formatLogTime(Ut),"+"+Hn+"ms",vs,A].filter(Boolean).join(" ")+`
4
+ `}let ie={debug(A,ue){s("DEBUG")&&p("DEBUG "+$(A,ue));},info(A,ue){s("INFO")&&p("INFO "+$(A,ue));},error(A,ue){s("ERROR")&&p("ERROR "+$(A,ue));},warn(A,ue){s("WARN")&&p("WARN "+$(A,ue));},tag(A,ue){return P&&(P[A]=ue),ie},clone(){return D.create({...P})},time(A,ue){let vs=Date.now();ie.info(A,{status:"started",...ue});function Ut(){ie.info(A,{status:"completed",duration:Date.now()-vs,...ue});}return {stop:Ut,[Symbol.dispose](){Ut();}}}};return F&&typeof F=="string"&&o.set(F,ie),ie}D.create=O;})(Ce||(Ce={}));var It=null;async function Za(){if(!It){It=(await import('@huggingface/transformers')).env;let e=ii__namespace.join(ir__namespace.homedir(),".cache","easbot","models");process.env.HF_HOME||(process.env.HF_HOME=e),It.allowLocalModels=true,It.allowRemoteModels=true,It.useBrowserCache=false,It.useFSCache=true;}return It}var Zs=null;async function jn(){return Zs||(Zs=(await import('@huggingface/transformers')).pipeline),Zs}var U=Ce.create({service:"transformers-engine"});var ys=class{constructor(e){c(this,"pipeline",null);c(this,"tokenizer",null);c(this,"isInitialized",false);c(this,"config");c(this,"modelCache");this.config=e,this.modelCache=new $t({cacheDir:e.cacheDir});}async configureEnvironment(){let e=await Za();this.modelCache.ensureCacheDir(),process.env.HF_HOME||(process.env.HF_HOME=this.config.cacheDir),e.cacheDir=this.config.cacheDir,e.allowLocalModels=true,e.allowRemoteModels=true,e.useBrowserCache=false,e.useFSCache=true,e.backends?.onnx&&(e.backends.onnx.logLevel="error"),this.config.verbose&&U.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&&U.debug("\u6A21\u578B\u5DF2\u521D\u59CB\u5316\uFF0C\u8DF3\u8FC7\u91CD\u590D\u52A0\u8F7D");return}await this.configureEnvironment();try{this.config.verbose&&U.debug("\u5F00\u59CB\u521D\u59CB\u5316\u6A21\u578B");let e,t,s;if(this.config.modelType==="language"){let a=Te[this.config.modelId];if(!a)throw new T(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");e=a.huggingFaceId,t=a.dtype,s=a.device;}else {let a=wt[this.config.modelId];if(!a)throw new T(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${this.config.modelId}`,"MODEL_NOT_FOUND");e=a.huggingFaceId,t=a.dtype;}this.config.verbose&&(U.debug("\u52A0\u8F7D\u6A21\u578B",{huggingFaceId:e,dtype:t||"auto"}),this.modelCache.isCached(e)?U.debug("\u4F7F\u7528\u7F13\u5B58\u7684\u6A21\u578B"):U.debug("\u9996\u6B21\u4E0B\u8F7D\u6A21\u578B\uFF0C\u53EF\u80FD\u9700\u8981\u4E00\u4E9B\u65F6\u95F4"));let r={cache_dir:this.config.cacheDir,local_files_only:!0};if(t&&(r.dtype=t),s&&(r.device=s),this.modelCache.isCached(e))this.config.verbose&&U.debug("\u4F7F\u7528\u672C\u5730\u7F13\u5B58\u6A21\u578B");else throw this.config.verbose&&U.warn("\u672C\u5730\u7F13\u5B58\u4E0D\u5B58\u5728",{huggingFaceId:e,cacheDir:this.config.cacheDir}),new T(`\u6A21\u578B ${e} \u672A\u627E\u5230\u672C\u5730\u7F13\u5B58\u3002\u8BF7\u5148\u4E0B\u8F7D\u6A21\u578B\u5230: ${this.config.cacheDir}`,"MODEL_NOT_FOUND");if(this.config.modelType==="language"){let a=this.config.pipelineType||"text-generation";this.config.verbose&&U.debug("\u52A0\u8F7D\u8BED\u8A00\u6A21\u578B pipeline",{pipelineType:a,huggingFaceId:e});let h=await jn();this.pipeline=await h(a,e,r);}else {let a=await jn();this.pipeline=await a("feature-extraction",e,r);}this.tokenizer=this.pipeline.tokenizer,this.isInitialized=!0,this.config.verbose&&U.debug("\u6A21\u578B\u521D\u59CB\u5316\u6210\u529F",{modelId:this.config.modelId});}catch(e){throw this.config.verbose&&U.error("\u6A21\u578B\u521D\u59CB\u5316\u5931\u8D25",{error:e}),ne.modelLoadError(e instanceof Error?e:new Error(String(e)))}}extractAssistantResponse(e,t){let s=`<|im_start|>assistant
5
+ `,r=e.lastIndexOf(s);if(r!==-1){let f=e.slice(r+s.length);return f=f.replace(/<\|im_end\|>$/g,""),f.trim()}let o=`
6
6
  assistant
7
7
  `,a=e.lastIndexOf(o);if(a!==-1)return e.slice(a+o.length).trim();let h=`assistant
8
- `,l=e.lastIndexOf(h);return l!==-1?e.slice(l+h.length).trim():(e.startsWith(t)?e.slice(t.length):e).trim()}async generate(e,t){let r=xe[this.config.modelId]?.defaultSettings||{temperature:.7,topP:.9,topK:40,maxTokens:2048,repetitionPenalty:1.1,stopSequences:[]},o={temperature:t.temperature??r.temperature,topP:t.topP??r.topP,topK:t.topK??r.topK,maxTokens:t.maxTokens??r.maxTokens,repetitionPenalty:t.repetitionPenalty??r.repetitionPenalty,stopSequences:t.stopSequences??r.stopSequences,abortSignal:t.abortSignal};if(this.config.modelType!=="language")throw new x("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u6587\u672C\u751F\u6210","UNSUPPORTED_FEATURE");if(t.abortSignal?.aborted)throw ne.abortError();try{this.config.verbose&&$.debug("\u5F00\u59CB\u751F\u6210\u6587\u672C");let a=await this.countTokens([e]),h=await this.pipeline(e,{max_new_tokens:o.maxTokens,temperature:o.temperature,top_p:o.topP,top_k:o.topK,repetition_penalty:o.repetitionPenalty,do_sample:o.temperature>0});if(t.abortSignal?.aborted)throw ne.abortError();let l=h[0]?.generated_text||"",d=this.extractAssistantResponse(l,e),g=await this.countTokens([d]);return this.config.verbose&&$.debug("\u751F\u6210\u5B8C\u6210",{completionTokens:g}),{content:d,finishReason:Vi(!0,!1),usage:{promptTokens:a,completionTokens:g,totalTokens:a+g}}}catch(a){throw this.config.verbose&&$.error("\u751F\u6210\u5931\u8D25",{error:a}),a instanceof x&&a.code==="ABORTED"?a:ne.generationError(a instanceof Error?a:new Error(String(a)))}}async generateStream(e,t,s){let o=xe[this.config.modelId]?.defaultSettings||{temperature:.7,topP:.9,topK:40,maxTokens:2048,repetitionPenalty:1.1,stopSequences:[]};if(!this.isInitialized)throw new x("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");if(this.config.modelType!=="language")throw new x("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u6587\u672C\u751F\u6210","UNSUPPORTED_FEATURE");if(t.abortSignal?.aborted)throw ne.abortError();try{this.config.verbose&&$.debug("\u5F00\u59CB\u6D41\u5F0F\u751F\u6210\u6587\u672C\uFF08\u6A21\u62DF\u6D41\u5F0F\u8F93\u51FA\uFF09");let a=await this.pipeline(e,{max_new_tokens:t.maxTokens??o.maxTokens,temperature:t.temperature??o.temperature,top_p:t.topP??o.topP,top_k:t.topK??o.topK,repetition_penalty:t.repetitionPenalty??o.repetitionPenalty,do_sample:(t.temperature??o.temperature)>0});if(t.abortSignal?.aborted)throw ne.abortError();let h=a[0]?.generated_text||"",l=this.extractAssistantResponse(h,e),d=l.split(/(\s+)/);for(let u of d){if(t.abortSignal?.aborted)throw ne.abortError();u.length>0&&s({type:"text-delta",delta:u});}s({type:"text-end"});let g=await this.countTokens([e]),p=await this.countTokens([l]);s({type:"finish",finishReason:Vi(!0,!1),usage:{promptTokens:g,completionTokens:p,totalTokens:g+p}}),this.config.verbose&&$.debug("\u6D41\u5F0F\u751F\u6210\u5B8C\u6210",{promptTokens:g,completionTokens:p,totalTokens:g+p});}catch(a){throw this.config.verbose&&$.error("\u6D41\u5F0F\u751F\u6210\u5931\u8D25",{error:a}),a instanceof x&&a.code==="ABORTED"?a:(s({type:"finish",finishReason:Vi(false,true,"generation_error"),usage:{promptTokens:0,completionTokens:0,totalTokens:0}}),ne.generationError(a instanceof Error?a:new Error(String(a))))}}async embed(e,t){if(!this.isInitialized)throw new x("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");if(this.config.modelType!=="embedding")throw new x("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u5D4C\u5165\u63A8\u7406","UNSUPPORTED_FEATURE");if(t?.aborted)throw ne.abortError();try{this.config.verbose&&$.debug("\u5F00\u59CB\u63A8\u7406",{textCount:e.length});let s=await this.pipeline(e,{pooling:"mean",normalize:!0});if(t?.aborted)throw ne.abortError();let r=[];if(s.dims&&s.dims.length===2){let[o,a]=s.dims,h=Array.from(s.data);for(let l=0;l<o;l++){let d=l*a,g=d+a;r.push(h.slice(d,g));}}else r.push(Array.from(s.data));return this.config.verbose&&$.debug("\u63A8\u7406\u5B8C\u6210",{embeddingCount:r.length}),r}catch(s){throw this.config.verbose&&$.error("\u63A8\u7406\u5931\u8D25",{error:s}),s instanceof x&&s.code==="ABORTED"?s:ne.embeddingError(s instanceof Error?s:new Error(String(s)))}}async countTokens(e){if(!this.isInitialized)throw new x("\u6A21\u578B\u672A\u521D\u59CB\u5316\uFF0C\u8BF7\u5148\u8C03\u7528 initialize() \u65B9\u6CD5","MODEL_NOT_INITIALIZED");try{let t=0;for(let s of e){let r=await this.tokenizer(s);t+=r.input_ids.data.length;}return t}catch(t){return this.config.verbose&&$.error("\u8BA1\u7B97 token \u5931\u8D25",{error:t}),e.reduce((s,r)=>s+Math.ceil(r.length/4),0)}}async dispose(){this.config.verbose&&$.debug("\u5378\u8F7D\u6A21\u578B"),this.pipeline=null,this.tokenizer=null,this.isInitialized=false,this.config.verbose&&$.debug("\u6A21\u578B\u5DF2\u5378\u8F7D");}isReady(){return this.isInitialized}};var ge=class{static validateTexts(e){if(!Array.isArray(e))throw new x("\u8F93\u5165\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4","INVALID_INPUT");if(e.length===0)throw new x("\u8F93\u5165\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let t=0;t<e.length;t++){let s=e[t];if(typeof s!="string")throw new x(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${t} \u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B`,"INVALID_INPUT");if(s.trim().length===0)throw new x(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${t} \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}static validateMessages(e){if(!Array.isArray(e))throw new x("\u6D88\u606F\u5FC5\u987B\u662F\u6570\u7EC4","INVALID_INPUT");if(e.length===0)throw new x("\u6D88\u606F\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let t=0;t<e.length;t++){let s=e[t];if(!s||typeof s!="object")throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!s.role)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7F3A\u5C11 role \u5B57\u6BB5`,"INVALID_INPUT");if(!["system","user","assistant"].includes(s.role))throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 role "${s.role}" \u4E0D\u652F\u6301\uFF0C\u53EA\u652F\u6301 system\u3001user\u3001assistant`,"UNSUPPORTED_FEATURE");if(!s.content)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7F3A\u5C11 content \u5B57\u6BB5`,"INVALID_INPUT");if(typeof s.content=="string"){if(s.content.trim().length===0)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}else if(Array.isArray(s.content)){if(s.content.length===0)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \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 x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content part ${r} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!o.type)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content part ${r} \u7F3A\u5C11 type \u5B57\u6BB5`,"INVALID_INPUT");if(o.type!=="text"&&o.type!=="reasoning")throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \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 x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content part ${r} \u7F3A\u5C11\u6709\u6548\u7684 text \u5B57\u6BB5`,"INVALID_INPUT");if(o.text.trim().length===0)throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content part ${r} \u7684 text \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}else throw new x(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6216\u6570\u7EC4`,"INVALID_INPUT")}}static validateGenerateOptions(e){if(e.temperature!==void 0&&(typeof e.temperature!="number"||e.temperature<0||e.temperature>2))throw new x("temperature \u5FC5\u987B\u662F 0 \u5230 2 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(e.topP!==void 0&&(typeof e.topP!="number"||e.topP<0||e.topP>1))throw new x("topP \u5FC5\u987B\u662F 0 \u5230 1 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(e.topK!==void 0&&(typeof e.topK!="number"||e.topK<1||!Number.isInteger(e.topK)))throw new x("topK \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(e.maxTokens!==void 0&&(typeof e.maxTokens!="number"||e.maxTokens<1||!Number.isInteger(e.maxTokens)))throw new x("maxTokens \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(e.repetitionPenalty!==void 0&&(typeof e.repetitionPenalty!="number"||e.repetitionPenalty<0))throw new x("repetitionPenalty \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 0 \u7684\u6570\u5B57","INVALID_INPUT")}};var ws=class{static createReadableStream(e,t){return new ReadableStream({async start(s){if(t?.aborted){s.error(new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));return}let r=false,o=()=>{r=true,s.error(new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));};t?.addEventListener("abort",o);try{if(await e(a=>{if(!r)try{s.enqueue(a),a.isFinished&&(s.close(),t?.removeEventListener("abort",o));}catch(h){s.error(h),t?.removeEventListener("abort",o);}}),!r)try{s.enqueue({textDelta:"",isFinished:!0,finishReason:"stop"}),s.close();}catch{}}catch(a){r||s.error(a instanceof x?a:new x(`\u751F\u6210\u5931\u8D25: ${a instanceof Error?a.message:String(a)}`,"GENERATION_ERROR",a instanceof Error?a:void 0));}finally{t?.removeEventListener("abort",o);}},cancel(){}})}static async*streamToAsyncIterator(e){let t=e.getReader();try{for(;;){let{done:s,value:r}=await t.read();if(s)break;yield r;}}finally{t.releaseLock();}}};function Za(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Nt=class{constructor(e,t,s){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"engine");c(this,"modelConfig");if(this.provider=e,this.modelId=t,this.engine=s,this.modelConfig=xe[t],!this.modelConfig)throw new x(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND")}async generate(e){return this.doGenerate(e)}async stream(e){return this.doStream(e)}convertToQwenFormat(e){let t=[];for(let s of e){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(`
8
+ `,l=e.lastIndexOf(h);return l!==-1?e.slice(l+h.length).trim():(e.startsWith(t)?e.slice(t.length):e).trim()}async generate(e,t){let r=Te[this.config.modelId]?.defaultSettings||{temperature:.7,topP:.9,topK:40,maxTokens:2048,repetitionPenalty:1.1,stopSequences:[]},o={temperature:t.temperature??r.temperature,topP:t.topP??r.topP,topK:t.topK??r.topK,maxTokens:t.maxTokens??r.maxTokens,repetitionPenalty:t.repetitionPenalty??r.repetitionPenalty,stopSequences:t.stopSequences??r.stopSequences,abortSignal:t.abortSignal};if(this.config.modelType!=="language")throw new T("\u5F53\u524D\u6A21\u578B\u4E0D\u652F\u6301\u6587\u672C\u751F\u6210","UNSUPPORTED_FEATURE");if(t.abortSignal?.aborted)throw ne.abortError();try{this.config.verbose&&U.debug("\u5F00\u59CB\u751F\u6210\u6587\u672C");let a=await this.countTokens([e]),h=await this.pipeline(e,{max_new_tokens:o.maxTokens,temperature:o.temperature,top_p:o.topP,top_k:o.topK,repetition_penalty:o.repetitionPenalty,do_sample:o.temperature>0});if(t.abortSignal?.aborted)throw ne.abortError();let l=h[0]?.generated_text||"",d=this.extractAssistantResponse(l,e),f=await this.countTokens([d]);return this.config.verbose&&U.debug("\u751F\u6210\u5B8C\u6210",{completionTokens:f}),{content:d,finishReason:Vi(!0,!1),usage:{promptTokens:a,completionTokens:f,totalTokens:a+f}}}catch(a){throw this.config.verbose&&U.error("\u751F\u6210\u5931\u8D25",{error:a}),a instanceof T&&a.code==="ABORTED"?a:ne.generationError(a instanceof Error?a:new Error(String(a)))}}async generateStream(e,t,s){let o=Te[this.config.modelId]?.defaultSettings||{temperature:.7,topP:.9,topK:40,maxTokens:2048,repetitionPenalty:1.1,stopSequences:[]};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(t.abortSignal?.aborted)throw ne.abortError();try{this.config.verbose&&U.debug("\u5F00\u59CB\u6D41\u5F0F\u751F\u6210\u6587\u672C\uFF08\u6A21\u62DF\u6D41\u5F0F\u8F93\u51FA\uFF09");let{TextStreamer:a}=await import('@huggingface/transformers'),h=await this.pipeline(e,{max_new_tokens:t.maxTokens??o.maxTokens,temperature:t.temperature??o.temperature,top_p:t.topP??o.topP,top_k:t.topK??o.topK,repetition_penalty:t.repetitionPenalty??o.repetitionPenalty,do_sample:(t.temperature??o.temperature)>0});if(t.abortSignal?.aborted)throw ne.abortError();let l=h[0]?.generated_text||"",d=this.extractAssistantResponse(l,e),f=d.split(/(\s+)/);for(let m of f){if(t.abortSignal?.aborted)throw ne.abortError();m.length>0&&s({type:"text-delta",delta:m});}s({type:"text-end"});let u=await this.countTokens([e]),p=await this.countTokens([d]);s({type:"finish",finishReason:Vi(!0,!1),usage:{promptTokens:u,completionTokens:p,totalTokens:u+p}}),this.config.verbose&&U.debug("\u6D41\u5F0F\u751F\u6210\u5B8C\u6210",{promptTokens:u,completionTokens:p,totalTokens:u+p});}catch(a){throw this.config.verbose&&U.error("\u6D41\u5F0F\u751F\u6210\u5931\u8D25",{error:a}),a instanceof T&&a.code==="ABORTED"?a:(s({type:"finish",finishReason:Vi(false,true,"generation_error"),usage:{promptTokens:0,completionTokens:0,totalTokens:0}}),ne.generationError(a instanceof Error?a:new Error(String(a))))}}async embed(e,t){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(t?.aborted)throw ne.abortError();try{this.config.verbose&&U.debug("\u5F00\u59CB\u63A8\u7406",{textCount:e.length});let s=await this.pipeline(e,{pooling:"mean",normalize:!0});if(t?.aborted)throw ne.abortError();let r=[];if(s.dims&&s.dims.length===2){let[o,a]=s.dims,h=Array.from(s.data);for(let l=0;l<o;l++){let d=l*a,f=d+a;r.push(h.slice(d,f));}}else r.push(Array.from(s.data));return this.config.verbose&&U.debug("\u63A8\u7406\u5B8C\u6210",{embeddingCount:r.length}),r}catch(s){throw this.config.verbose&&U.error("\u63A8\u7406\u5931\u8D25",{error:s}),s instanceof T&&s.code==="ABORTED"?s:ne.embeddingError(s instanceof Error?s:new Error(String(s)))}}async countTokens(e){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 t=0;for(let s of e){let r=await this.tokenizer(s);t+=r.input_ids.data.length;}return t}catch(t){return this.config.verbose&&U.error("\u8BA1\u7B97 token \u5931\u8D25",{error:t}),e.reduce((s,r)=>s+Math.ceil(r.length/4),0)}}async dispose(){this.config.verbose&&U.debug("\u5378\u8F7D\u6A21\u578B"),this.pipeline=null,this.tokenizer=null,this.isInitialized=false,this.config.verbose&&U.debug("\u6A21\u578B\u5DF2\u5378\u8F7D");}isReady(){return this.isInitialized}};var ge=class{static validateTexts(e){if(!Array.isArray(e))throw new T("\u8F93\u5165\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4","INVALID_INPUT");if(e.length===0)throw new T("\u8F93\u5165\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let t=0;t<e.length;t++){let s=e[t];if(typeof s!="string")throw new T(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${t} \u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B`,"INVALID_INPUT");if(s.trim().length===0)throw new T(`\u8F93\u5165\u6570\u7EC4\u7D22\u5F15 ${t} \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}static validateMessages(e){if(!Array.isArray(e))throw new T("\u6D88\u606F\u5FC5\u987B\u662F\u6570\u7EC4","INVALID_INPUT");if(e.length===0)throw new T("\u6D88\u606F\u6570\u7EC4\u4E0D\u80FD\u4E3A\u7A7A","INVALID_INPUT");for(let t=0;t<e.length;t++){let s=e[t];if(!s||typeof s!="object")throw new T(`\u6D88\u606F\u7D22\u5F15 ${t} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!s.role)throw new T(`\u6D88\u606F\u7D22\u5F15 ${t} \u7F3A\u5C11 role \u5B57\u6BB5`,"INVALID_INPUT");if(!["system","user","assistant"].includes(s.role))throw new T(`\u6D88\u606F\u7D22\u5F15 ${t} \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 ${t} \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 ${t} \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 ${t} \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 ${t} \u7684 content part ${r} \u4E0D\u662F\u6709\u6548\u5BF9\u8C61`,"INVALID_INPUT");if(!o.type)throw new T(`\u6D88\u606F\u7D22\u5F15 ${t} \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 ${t} \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 ${t} \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 ${t} \u7684 content part ${r} \u7684 text \u662F\u7A7A\u5B57\u7B26\u4E32`,"INVALID_INPUT")}}else throw new T(`\u6D88\u606F\u7D22\u5F15 ${t} \u7684 content \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6216\u6570\u7EC4`,"INVALID_INPUT")}}static validateGenerateOptions(e){if(e.temperature!==void 0&&(typeof e.temperature!="number"||e.temperature<0||e.temperature>2))throw new T("temperature \u5FC5\u987B\u662F 0 \u5230 2 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(e.topP!==void 0&&(typeof e.topP!="number"||e.topP<0||e.topP>1))throw new T("topP \u5FC5\u987B\u662F 0 \u5230 1 \u4E4B\u95F4\u7684\u6570\u5B57","INVALID_INPUT");if(e.topK!==void 0&&(typeof e.topK!="number"||e.topK<1||!Number.isInteger(e.topK)))throw new T("topK \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(e.maxTokens!==void 0&&(typeof e.maxTokens!="number"||e.maxTokens<1||!Number.isInteger(e.maxTokens)))throw new T("maxTokens \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 1 \u7684\u6574\u6570","INVALID_INPUT");if(e.repetitionPenalty!==void 0&&(typeof e.repetitionPenalty!="number"||e.repetitionPenalty<0))throw new T("repetitionPenalty \u5FC5\u987B\u662F\u5927\u4E8E\u7B49\u4E8E 0 \u7684\u6570\u5B57","INVALID_INPUT")}};var ws=class{static createReadableStream(e,t){return new ReadableStream({async start(s){if(t?.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"));};t?.addEventListener("abort",o);try{if(await e(a=>{if(!r)try{s.enqueue(a),a.isFinished&&(s.close(),t?.removeEventListener("abort",o));}catch(h){s.error(h),t?.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{t?.removeEventListener("abort",o);}},cancel(){}})}static async*streamToAsyncIterator(e){let t=e.getReader();try{for(;;){let{done:s,value:r}=await t.read();if(s)break;yield r;}}finally{t.releaseLock();}}};function Xa(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Nt=class{constructor(e,t,s){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"engine");c(this,"modelConfig");if(this.provider=e,this.modelId=t,this.engine=s,this.modelConfig=Te[t],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND")}async generate(e){return this.doGenerate(e)}async stream(e){return this.doStream(e)}convertToQwenFormat(e){let t=[];for(let s of e){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
9
  `)),s.role){case "system":t.push(`<|im_start|>system
10
10
  ${r}<|im_end|>`);break;case "user":t.push(`<|im_start|>user
11
11
  ${r}<|im_end|>`);break;case "assistant":t.push(`<|im_start|>assistant
12
- ${r}<|im_end|>`);break;default:throw new x(`\u4E0D\u652F\u6301\u7684\u6D88\u606F\u89D2\u8272: ${s.role}`,"UNSUPPORTED_FEATURE")}}return t.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 t.push(`<|im_start|>assistant
13
13
  `),t.join(`
14
- `)}async doGenerate(e){ge.validateMessages(e.prompt);let t=this.convertToQwenFormat(e.prompt),s={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=await this.engine.generate(t,s);return {content:[{type:"text",text:r.content||""}],finishReason:r.finishReason,usage:{inputTokens:r.usage.promptTokens,inputTokenDetails:{noCacheTokens:void 0,cacheReadTokens:void 0,cacheWriteTokens:void 0},outputTokens:r.usage.completionTokens,outputTokenDetails:{textTokens:void 0,reasoningTokens:void 0},totalTokens:(r.usage.promptTokens||0)+(r.usage.completionTokens||0)},warnings:[],rawCall:{rawPrompt:t,rawSettings:s}}}async doStream(e){ge.validateMessages(e.prompt);let t=this.convertToQwenFormat(e.prompt),s={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=ws.createReadableStream(async h=>{await this.engine.generateStream(t,s,l=>{if(l.type==="text-delta"){let d=l.delta||"";h({textDelta:d,isFinished:false});}else l.type==="finish"&&h({textDelta:"",isFinished:true,finishReason:l.finishReason});});},e.abortSignal),o=null;return {stream:r.pipeThrough(new TransformStream({transform(h,l){h.isFinished?(o&&(l.enqueue({type:"text-end",id:o}),o=null),l.enqueue({type:"finish",finishReason:h.finishReason||"stop",usage:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}})):h.textDelta&&(o||(o=Za(),l.enqueue({type:"text-start",id:o})),l.enqueue({type:"text-delta",id:o,delta:h.textDelta}));}})),rawCall:{rawPrompt:t,rawSettings:s}}}};var Bi=class i{static buildEnhancedPrompt(e,t){let s=[];s.push(i.buildSystemPrompt(t));for(let r of e){let o=i.formatMessage(r);o&&s.push(o);}return s.push(`<|im_start|>assistant
14
+ `)}async doGenerate(e){ge.validateMessages(e.prompt);let t=this.convertToQwenFormat(e.prompt),s={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxOutputTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=await this.engine.generate(t,s);return {content:[{type:"text",text:r.content||""}],finishReason:r.finishReason,usage:{inputTokens:r.usage.promptTokens,inputTokenDetails:{noCacheTokens:void 0,cacheReadTokens:void 0,cacheWriteTokens:void 0},outputTokens:r.usage.completionTokens,outputTokenDetails:{textTokens:void 0,reasoningTokens:void 0},totalTokens:(r.usage.promptTokens||0)+(r.usage.completionTokens||0)},warnings:[],rawCall:{rawPrompt:t,rawSettings:s}}}async doStream(e){ge.validateMessages(e.prompt);let t=this.convertToQwenFormat(e.prompt),s={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(s),this.engine.isReady()||await this.engine.initialize();let r=ws.createReadableStream(async h=>{await this.engine.generateStream(t,s,l=>{if(l.type==="text-delta"){let d=l.delta||"";h({textDelta:d,isFinished:false});}else l.type==="finish"&&h({textDelta:"",isFinished:true,finishReason:l.finishReason});});},e.abortSignal),o=null;return {stream:r.pipeThrough(new TransformStream({transform(h,l){h.isFinished?(o&&(l.enqueue({type:"text-end",id:o}),o=null),l.enqueue({type:"finish",finishReason:h.finishReason||"stop",usage:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}})):h.textDelta&&(o||(o=Xa(),l.enqueue({type:"text-start",id:o})),l.enqueue({type:"text-delta",id:o,delta:h.textDelta}));}})),rawCall:{rawPrompt:t,rawSettings:s}}}};var Bi=class i{static buildEnhancedPrompt(e,t){let s=[];s.push(i.buildSystemPrompt(t));for(let r of e){let o=i.formatMessage(r);o&&s.push(o);}return s.push(`<|im_start|>assistant
15
15
  `),s.join(`
16
16
  `)}static buildSystemPrompt(e){return e&&e.length>0?`<|im_start|>system
17
17
  Environment: ipython
@@ -110,15 +110,15 @@ CRITICAL OUTPUT RULES:
110
110
  `);}switch(e.role){case "system":return null;case "user":return `<|im_start|>user
111
111
  ${t}<|im_end|>`;case "assistant":return `<|im_start|>assistant
112
112
  ${t}<|im_end|>`;case "tool":return `<|im_start|>tool
113
- ${t}<|im_end|>`;default:{let s=e.role;throw new x(`\u4E0D\u652F\u6301\u7684\u6D88\u606F\u89D2\u8272: ${s}`,"UNSUPPORTED_FEATURE")}}}};var _t=class{static processThinkTags(e,t){let s={...e};for(;s.contentBuffer.length>0;)if(s.isInThinkTag){let r=s.contentBuffer.indexOf("</think>");if(r===-1){s.contentBuffer.length>0&&t.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&&t.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:o});}t.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,t.enqueue({type:"text-start",id:"txt-0"})),t.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,t.enqueue({type:"text-start",id:"txt-0"})),o.length>0&&t.enqueue({type:"text-delta",id:"txt-0",delta:o}),t.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,t.enqueue({type:"reasoning-start",id:"reasoning-0"}));}return s}static finishThinkParsing(e,t){let s={...e};return s.contentBuffer.length>0?s.isInThinkTag?(s.contentBuffer.length>0&&t.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:s.contentBuffer}),s.reasoningStarted&&(t.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)):(s.textStarted||(t.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),s.contentBuffer.length>0&&t.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):(s.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s.reasoningStarted&&!s.isInThinkTag&&(t.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)),s}static removeThinkTags(e){return e.replace(/<think>[\s\S]*?<\/think>/g,"").trim()}};function Xa(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Ft=class i{static extractToolCalls(e){let t=[],s=e,r=e.split(`
113
+ ${t}<|im_end|>`;default:{let s=e.role;throw new T(`\u4E0D\u652F\u6301\u7684\u6D88\u606F\u89D2\u8272: ${s}`,"UNSUPPORTED_FEATURE")}}}};var _t=class{static processThinkTags(e,t){let s={...e};for(;s.contentBuffer.length>0;)if(s.isInThinkTag){let r=s.contentBuffer.indexOf("</think>");if(r===-1){s.contentBuffer.length>0&&t.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&&t.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:o});}t.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,t.enqueue({type:"text-start",id:"txt-0"})),t.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,t.enqueue({type:"text-start",id:"txt-0"})),o.length>0&&t.enqueue({type:"text-delta",id:"txt-0",delta:o}),t.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,t.enqueue({type:"reasoning-start",id:"reasoning-0"}));}return s}static finishThinkParsing(e,t){let s={...e};return s.contentBuffer.length>0?s.isInThinkTag?(s.contentBuffer.length>0&&t.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:s.contentBuffer}),s.reasoningStarted&&(t.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)):(s.textStarted||(t.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),s.contentBuffer.length>0&&t.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):(s.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s.reasoningStarted&&!s.isInThinkTag&&(t.enqueue({type:"reasoning-end",id:"reasoning-0"}),s.reasoningStarted=false)),s}static removeThinkTags(e){return e.replace(/<think>[\s\S]*?<\/think>/g,"").trim()}};function Qa(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var Ft=class i{static extractToolCalls(e){let t=[],s=e,r=e.split(`
114
114
  `),o=[];for(let a of r){let h=a.trim();if(!h){o.push(a);continue}try{let l=JSON.parse(h);if(l.name&&typeof l.name=="string"&&l.parameters&&typeof l.parameters=="object"){t.push({name:l.name,parameters:JSON.stringify(l.parameters)});continue}}catch{}o.push(a);}return s=o.join(`
115
115
  `).trim(),{toolCalls:t,remainingText:s}}static processToolCalls(e,t,s){let r={...e},o=r.contentBuffer.split(`
116
- `),a=[];for(let h=0;h<o.length;h++){let l=o[h];if(!l)continue;let d=l.trim();if(!d){a.push(l);continue}let g=false;try{let p=JSON.parse(d);if(p.name&&typeof p.name=="string"&&p.parameters&&typeof p.parameters=="object"){if(s&&s.length>0&&!s.some(S=>S.name===p.name)){a.push(l);continue}if(g=!0,a.length>0){let b=a.join(`
116
+ `),a=[];for(let h=0;h<o.length;h++){let l=o[h];if(!l)continue;let d=l.trim();if(!d){a.push(l);continue}let f=false;try{let u=JSON.parse(d);if(u.name&&typeof u.name=="string"&&u.parameters&&typeof u.parameters=="object"){if(s&&s.length>0&&!s.some(S=>S.name===u.name)){a.push(l);continue}if(f=!0,a.length>0){let b=a.join(`
117
117
  `);b.trim()&&(r.textStarted||(t.enqueue({type:"text-start",id:"txt-0"}),r.textStarted=!0),t.enqueue({type:"text-delta",id:"txt-0",delta:b+`
118
- `})),a.length=0;}r.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),r.textStarted=!1);let u=Xa(),m=JSON.stringify(p.parameters);t.enqueue({type:"tool-input-start",id:u,toolName:p.name}),t.enqueue({type:"tool-input-delta",id:u,delta:m}),t.enqueue({type:"tool-input-end",id:u}),t.enqueue({type:"tool-call",toolCallId:u,toolName:p.name,input:m}),r.completedToolCalls.push({id:u,name:p.name,parameters:m});}}catch{}g||a.push(l);}return r.contentBuffer=a.join(`
119
- `),r}static finishToolParsing(e,t){let s={...e};return s.contentBuffer.trim().length>0?(s.textStarted||(t.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),t.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):s.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s}static removeToolCalls(e){let{remainingText:t}=i.extractToolCalls(e);return t}};function Gn(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var zi=class{constructor(e,t,s){c(this,"specificationVersion","v3");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=e,this.modelId=t,this.engine=s,this.modelConfig=xe[t],!this.modelConfig)throw new x(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND")}async generate(e){return this.doGenerate(e)}async stream(e){return this.doStream(e)}async doGenerate(e){ge.validateMessages(e.prompt);let t=e.tools?.filter(u=>"inputSchema"in u),s=Bi.buildEnhancedPrompt(e.prompt,t),r={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(r),this.engine.isReady()||await this.engine.initialize();let o=await this.engine.generate(s,r),a=_t.removeThinkTags(o.content||""),{toolCalls:h,remainingText:l}=Ft.extractToolCalls(a),d=[];l.trim().length>0&&d.push({type:"text",text:l});for(let u of h)d.push({type:"tool-call",toolCallId:Gn(),toolName:u.name,input:u.parameters});let g=h.length>0?"tool-calls":o.finishReason,p=[];return {content:d,finishReason:g,usage:{inputTokens:{total:o.usage.promptTokens,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:o.usage.completionTokens,text:void 0,reasoning:void 0}},warnings:p,rawCall:{rawPrompt:s,rawSettings:r}}}async doStream(e){let t=Gn();ge.validateMessages(e.prompt);let s=e.tools?.filter(m=>"inputSchema"in m),r=Bi.buildEnhancedPrompt(e.prompt,s),o={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(o),this.engine.isReady()||await this.engine.initialize();let a=null,h=null,l=m=>{a&&a.enqueue(m),h&&h.enqueue(m);},d=async()=>{try{let m={isInThinkTag:!1,reasoningStarted:!1,textStarted:!1,contentBuffer:""},b={contentBuffer:"",textStarted:!1,completedToolCalls:[]};l({type:"response-metadata",id:t,modelId:this.modelId,timestamp:new Date}),await this.engine.generateStream(r,o,S=>{if(S.type==="text-delta"){let T=S.delta||"";if(T.length===0)return;m.contentBuffer+=T;let v=_t.processThinkTags(m,{enqueue:l});m.isInThinkTag=v.isInThinkTag,m.reasoningStarted=v.reasoningStarted,m.textStarted=v.textStarted,b.contentBuffer+=v.contentBuffer,m.contentBuffer="";let k=Ft.processToolCalls(b,{enqueue:l},s);b.contentBuffer=k.contentBuffer,b.textStarted=k.textStarted,b.completedToolCalls=k.completedToolCalls;}else if(S.type==="text-end"){let T=_t.finishThinkParsing(m,{enqueue:l});m.textStarted=T.textStarted,m.reasoningStarted=T.reasoningStarted;let v=Ft.finishToolParsing(b,{enqueue:l});b.textStarted=v.textStarted;}else if(S.type==="finish"){let T=_t.finishThinkParsing(m,{enqueue:l});m.textStarted=T.textStarted,m.reasoningStarted=T.reasoningStarted;let v=Ft.finishToolParsing(b,{enqueue:l});b.textStarted=v.textStarted;let k=b.completedToolCalls.length>0;l({type:"finish",finishReason:k?"tool-calls":S.finishReason,usage:S.usage?{inputTokens:{total:S.usage.promptTokens||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:S.usage.completionTokens||0,text:void 0,reasoning:void 0}}:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}});}});}catch(m){l({type:"error",error:m instanceof Error?m.message:String(m)}),l({type:"finish",finishReason:"error",usage:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}});}finally{a&&a.close(),h&&h.close();}},g=new ReadableStream({start(m){a=m;}}),p=new ReadableStream({start(m){h=m;}});d();async function*u(m){let b=m.getReader();try{for(;;){let{done:S,value:T}=await b.read();if(S)break;yield T;}}finally{b.releaseLock();}}return {stream:g,fullStream:u(p),request:{body:r},response:{headers:{}}}}};var bs=class{constructor(e){c(this,"config");this.config=e;}createBatches(e){let t=[],s=this.config.batchSize;for(let r=0;r<e.length;r+=s)t.push(e.slice(r,r+s));return t}async processBatches(e,t,s){if(s?.aborted)throw new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let r=this.createBatches(e),o=[];for(let a=0;a<r.length;a++){if(s?.aborted)throw new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let h=r[a];if(h){try{let l=await t(h);o.push(...l);}catch(l){throw l instanceof x&&l.code==="ABORTED"?l:new x(`\u6279\u6B21 ${a+1}/${r.length} \u5904\u7406\u5931\u8D25: ${l instanceof Error?l.message:String(l)}`,"PROCESSING_ERROR",l instanceof Error?l:void 0)}a<r.length-1&&this.config.delayBetweenBatches&&this.config.delayBetweenBatches>0&&await this.delay(this.config.delayBetweenBatches,s);}}return o}async delay(e,t){return new Promise((s,r)=>{if(t?.aborted){r(new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));return}let o=setTimeout(()=>{t?.removeEventListener("abort",a),s();},e),a=()=>{clearTimeout(o),r(new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));};t?.addEventListener("abort",a);})}};var ji=class{constructor(e,t,s){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"maxEmbeddingsPerCall");c(this,"supportsParallelCalls",false);c(this,"engine");c(this,"modelConfig");if(this.provider=e,this.modelId=t,this.engine=s,this.modelConfig=bt[t],!this.modelConfig)throw new x(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND");this.maxEmbeddingsPerCall=this.modelConfig.maxEmbeddingsPerCall;}async doEmbed(e){let{values:t,abortSignal:s}=e;if(ge.validateTexts(t),s?.aborted)throw new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");this.engine.isReady()||await this.engine.initialize();let o=await new bs({batchSize:this.maxEmbeddingsPerCall,delayBetweenBatches:0}).processBatches(t,async h=>{if(s?.aborted)throw new x("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");return await this.engine.embed(h,s)},s),a=await this.engine.countTokens(t);return {embeddings:o,usage:{tokens:a},warnings:[]}}};var Wi=class{constructor(e,t,s,r={}){c(this,"specificationVersion","v3");c(this,"provider","local");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Ce.create({service:"local-model-sdk",module:"reranking-model"}));this.modelId=e,this.languageModel=new Nt("local",e,s),this.options={llm:this.languageModel,totalScore:r.totalScore??1,useEnhancedPrompt:r.useEnhancedPrompt??false,promptLanguage:r.promptLanguage??"en"},this.log.debug("LocalRerankingModel created",{modelId:e,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(e){let{query:t,documents:s,topN:r}=e,o;Array.isArray(s)?o=s:s.type==="text"?o=s.values.map((l,d)=>({content:l,id:`doc_${d+1}`})):o=s.values;let a=r??o.length;if(o.length===0)return {ranking:[],warnings:[]};try{let l=this.buildRerankPrompt(t,o),g=(await this.languageModel.doGenerate({prompt:[{role:"user",content:[{type:"text",text:l}]}],maxOutputTokens:500,temperature:.1})).content.find(u=>u.type==="text")?.text||"",p=this.parseRerankResult(g,o,a);return {ranking:p.results.map(u=>({index:u.index,relevanceScore:u.score,document:u.document})),warnings:p.warnings.map(u=>({type:"other",message:u})),response:{timestamp:new Date,modelId:this.modelId}}}catch(l){return this.log.error("Reranking failed",{error:l.message}),{ranking:o.map((g,p)=>({index:p,relevanceScore:this.options.totalScore*(1-p/o.length),document:g})),warnings:[{type:"other",message:`Reranking failed, using original order: ${l.message}`}],response:{timestamp:new Date,modelId:this.modelId}}}}buildRerankPrompt(e,t){let s=t.map((r,o)=>{let a=r.id||`doc_${o+1}`,h=r.content.slice(0,300);return `${o+1}. [ID: ${a}] ${h}`}).join(`
118
+ `})),a.length=0;}r.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),r.textStarted=!1);let p=Qa(),m=JSON.stringify(u.parameters);t.enqueue({type:"tool-input-start",id:p,toolName:u.name}),t.enqueue({type:"tool-input-delta",id:p,delta:m}),t.enqueue({type:"tool-input-end",id:p}),t.enqueue({type:"tool-call",toolCallId:p,toolName:u.name,input:m}),r.completedToolCalls.push({id:p,name:u.name,parameters:m});}}catch{}f||a.push(l);}return r.contentBuffer=a.join(`
119
+ `),r}static finishToolParsing(e,t){let s={...e};return s.contentBuffer.trim().length>0?(s.textStarted||(t.enqueue({type:"text-start",id:"txt-0"}),s.textStarted=true),t.enqueue({type:"text-delta",id:"txt-0",delta:s.contentBuffer}),t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false):s.textStarted&&(t.enqueue({type:"text-end",id:"txt-0"}),s.textStarted=false),s}static removeToolCalls(e){let{remainingText:t}=i.extractToolCalls(e);return t}};function qn(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}var zi=class{constructor(e,t,s){c(this,"specificationVersion","v3");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=e,this.modelId=t,this.engine=s,this.modelConfig=Te[t],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND")}async generate(e){return this.doGenerate(e)}async stream(e){return this.doStream(e)}async doGenerate(e){ge.validateMessages(e.prompt);let t=e.tools?.filter(p=>"inputSchema"in p),s=Bi.buildEnhancedPrompt(e.prompt,t),r={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(r),this.engine.isReady()||await this.engine.initialize();let o=await this.engine.generate(s,r),a=_t.removeThinkTags(o.content||""),{toolCalls:h,remainingText:l}=Ft.extractToolCalls(a),d=[];l.trim().length>0&&d.push({type:"text",text:l});for(let p of h)d.push({type:"tool-call",toolCallId:qn(),toolName:p.name,input:p.parameters});let f=h.length>0?"tool-calls":o.finishReason,u=[];return {content:d,finishReason:f,usage:{inputTokens:{total:o.usage.promptTokens,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:o.usage.completionTokens,text:void 0,reasoning:void 0}},warnings:u,rawCall:{rawPrompt:s,rawSettings:r}}}async doStream(e){let t=qn();ge.validateMessages(e.prompt);let s=e.tools?.filter(m=>"inputSchema"in m),r=Bi.buildEnhancedPrompt(e.prompt,s),o={temperature:e.temperature??this.modelConfig.defaultSettings.temperature,topP:e.topP??this.modelConfig.defaultSettings.topP,topK:e.topK??this.modelConfig.defaultSettings.topK,maxTokens:e.maxTokens??this.modelConfig.defaultSettings.maxTokens,repetitionPenalty:this.modelConfig.defaultSettings.repetitionPenalty,stopSequences:this.modelConfig.defaultSettings.stopSequences,abortSignal:e.abortSignal};ge.validateGenerateOptions(o),this.engine.isReady()||await this.engine.initialize();let a=null,h=null,l=m=>{a&&a.enqueue(m),h&&h.enqueue(m);},d=async()=>{try{let m={isInThinkTag:!1,reasoningStarted:!1,textStarted:!1,contentBuffer:""},b={contentBuffer:"",textStarted:!1,completedToolCalls:[]};l({type:"response-metadata",id:t,modelId:this.modelId,timestamp:new Date}),await this.engine.generateStream(r,o,S=>{if(S.type==="text-delta"){let x=S.delta||"";if(x.length===0)return;m.contentBuffer+=x;let v=_t.processThinkTags(m,{enqueue:l});m.isInThinkTag=v.isInThinkTag,m.reasoningStarted=v.reasoningStarted,m.textStarted=v.textStarted,b.contentBuffer+=v.contentBuffer,m.contentBuffer="";let k=Ft.processToolCalls(b,{enqueue:l},s);b.contentBuffer=k.contentBuffer,b.textStarted=k.textStarted,b.completedToolCalls=k.completedToolCalls;}else if(S.type==="text-end"){let x=_t.finishThinkParsing(m,{enqueue:l});m.textStarted=x.textStarted,m.reasoningStarted=x.reasoningStarted;let v=Ft.finishToolParsing(b,{enqueue:l});b.textStarted=v.textStarted;}else if(S.type==="finish"){let x=_t.finishThinkParsing(m,{enqueue:l});m.textStarted=x.textStarted,m.reasoningStarted=x.reasoningStarted;let v=Ft.finishToolParsing(b,{enqueue:l});b.textStarted=v.textStarted;let k=b.completedToolCalls.length>0;l({type:"finish",finishReason:k?"tool-calls":S.finishReason,usage:S.usage?{inputTokens:{total:S.usage.promptTokens||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:S.usage.completionTokens||0,text:void 0,reasoning:void 0}}:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}});}});}catch(m){l({type:"error",error:m instanceof Error?m.message:String(m)}),l({type:"finish",finishReason:"error",usage:{inputTokens:{total:0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:0,text:void 0,reasoning:void 0}}});}finally{a&&a.close(),h&&h.close();}},f=new ReadableStream({start(m){a=m;}}),u=new ReadableStream({start(m){h=m;}});d();async function*p(m){let b=m.getReader();try{for(;;){let{done:S,value:x}=await b.read();if(S)break;yield x;}}finally{b.releaseLock();}}return {stream:f,fullStream:p(u),request:{body:r},response:{headers:{}}}}};var bs=class{constructor(e){c(this,"config");this.config=e;}createBatches(e){let t=[],s=this.config.batchSize;for(let r=0;r<e.length;r+=s)t.push(e.slice(r,r+s));return t}async processBatches(e,t,s){if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let r=this.createBatches(e),o=[];for(let a=0;a<r.length;a++){if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");let h=r[a];if(h){try{let l=await t(h);o.push(...l);}catch(l){throw l instanceof T&&l.code==="ABORTED"?l:new T(`\u6279\u6B21 ${a+1}/${r.length} \u5904\u7406\u5931\u8D25: ${l instanceof Error?l.message:String(l)}`,"PROCESSING_ERROR",l instanceof Error?l:void 0)}a<r.length-1&&this.config.delayBetweenBatches&&this.config.delayBetweenBatches>0&&await this.delay(this.config.delayBetweenBatches,s);}}return o}async delay(e,t){return new Promise((s,r)=>{if(t?.aborted){r(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));return}let o=setTimeout(()=>{t?.removeEventListener("abort",a),s();},e),a=()=>{clearTimeout(o),r(new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED"));};t?.addEventListener("abort",a);})}};var ji=class{constructor(e,t,s){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"maxEmbeddingsPerCall");c(this,"supportsParallelCalls",false);c(this,"engine");c(this,"modelConfig");if(this.provider=e,this.modelId=t,this.engine=s,this.modelConfig=wt[t],!this.modelConfig)throw new T(`\u4E0D\u652F\u6301\u7684\u6A21\u578B ID: ${t}`,"MODEL_NOT_FOUND");this.maxEmbeddingsPerCall=this.modelConfig.maxEmbeddingsPerCall;}async doEmbed(e){let{values:t,abortSignal:s}=e;if(ge.validateTexts(t),s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");this.engine.isReady()||await this.engine.initialize();let o=await new bs({batchSize:this.maxEmbeddingsPerCall,delayBetweenBatches:0}).processBatches(t,async h=>{if(s?.aborted)throw new T("\u64CD\u4F5C\u5DF2\u53D6\u6D88","ABORTED");return await this.engine.embed(h,s)},s),a=await this.engine.countTokens(t);return {embeddings:o,usage:{tokens:a},warnings:[]}}};var Wi=class{constructor(e,t,s,r={}){c(this,"specificationVersion","v3");c(this,"provider","local");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Ce.create({service:"local-model-sdk",module:"reranking-model"}));this.modelId=e,this.languageModel=new Nt("local",e,s),this.options={llm:this.languageModel,totalScore:r.totalScore??1,useEnhancedPrompt:true,promptLanguage:r.promptLanguage??"en"},this.log.debug("LocalRerankingModel created",{modelId:e,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(e){let{query:t,documents:s,topN:r}=e,o;Array.isArray(s)?o=s:s.type==="text"?o=s.values.map((l,d)=>({content:l,id:`doc_${d+1}`})):o=s.values;let a=r??o.length;if(o.length===0)return {ranking:[],warnings:[]};try{let l=this.buildRerankPrompt(t,o),f=(await this.languageModel.doGenerate({prompt:[{role:"user",content:[{type:"text",text:l}]}],maxOutputTokens:2048,temperature:0,topP:1,topK:1})).content.find(p=>p.type==="text")?.text||"",u=this.parseRerankResult(f,o,a);return {ranking:u.results.map(p=>({index:p.index,relevanceScore:p.score,document:p.document})),warnings:u.warnings.map(p=>({type:"other",message:p})),response:{timestamp:new Date,modelId:this.modelId}}}catch(l){return this.log.error("Reranking failed",{error:l.message}),{ranking:o.map((f,u)=>({index:u,relevanceScore:this.options.totalScore*(1-u/o.length),document:f})),warnings:[{type:"other",message:`Reranking failed, using original order: ${l.message}`}],response:{timestamp:new Date,modelId:this.modelId}}}}buildRerankPrompt(e,t){let s=t.map((r,o)=>{let a=r.id||`doc_${o+1}`,h=r.content.slice(0,300);return `${o+1}. [ID: ${a}] ${h}`}).join(`
120
120
 
121
- `);if(this.options.useEnhancedPrompt)if(this.options.promptLanguage==="en"){this.options.totalScore===1?"1.0":`${this.options.totalScore}`;return `You are a professional information retrieval reranking expert. Please rank the following documents according to the query.
121
+ `);if(this.options.useEnhancedPrompt)if(this.options.promptLanguage==="en"){let r=this.options.totalScore===1?"1.0":`${this.options.totalScore}`;return `You are a professional information retrieval reranking expert. Please rank the following documents according to the query.
122
122
 
123
123
  User query: ${e}
124
124
 
@@ -129,14 +129,9 @@ Please rank the documents according to the following requirements:
129
129
  1. Carefully analyze the user's query intent and key information needs
130
130
  2. Evaluate each document's relevance to the query
131
131
  3. Consider the document's completeness, accuracy, and usefulness
132
- 4. Return to ranked document numbers separated by commas
132
+ 4. Return the ranked document numbers separated by commas
133
133
  5. Most relevant documents should be at the front
134
-
135
- Use a scoring scale from ${this.options.totalScore*.1} to ${this.options.totalScore} where ${this.options.totalScore*.1} is most relevant and ${this.options.totalScore} is least relevant.
136
- The actual score for each position should be calculated dynamically. For example:
137
- - If totalScore is 10: scores might be: 9, 7, 10, 4, 2
138
- - If totalScore is 1: scores might be: 0.2, 0.5, 1.0, 0.06, 0.04
139
- - If totalScore is 5: scores might be: 0.1, 0.25, 0.5, 0.03, 0.02
134
+ 6. Use a scoring scale from ${r}
140
135
 
141
136
  Example output format: 2,5,1,4,3
142
137
 
@@ -161,9 +156,9 @@ ${s}
161
156
 
162
157
  ${s}
163
158
 
164
- \u8F93\u51FA\u683C\u5F0F\uFF1A1,2,3,4,5\uFF08\u6700\u76F8\u5173\u7684\u6392\u5728\u524D\u9762\uFF09`}parseRerankResult(e,t,s){let r=[];try{let o=e.match(/\d+/g)?.map(u=>parseInt(u,10)-1).filter(u=>u>=0&&u<t.length)||[],a=[],h=new Set;for(let u of o)h.has(u)||(h.add(u),a.push(u));let l=[],d=new Set;for(let u of a)if(u!==void 0&&u>=0&&u<t.length&&!d.has(u)){d.add(u);let m=t[u];m&&l.push({index:u,score:this.options.totalScore*(1-l.length/a.length),document:m});}let g=new Set(a);for(let u=0;u<t.length;u++)if(!g.has(u)){let m=this.options.totalScore*.1*(1-u/t.length);l.push({index:u,score:m,document:t[u]});}let p=s?l.slice(0,s):l;return this.log.debug("Parsed rerank results",{extractedNumbers:o,uniqueIndices:a,resultCount:p.length,topK:s}),{results:p,warnings:r}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:e}),{results:t.map((h,l)=>({index:l,score:this.options.totalScore*(1-l/t.length),document:h})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};var Gi=class{constructor(e,t,s={}){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Ce.create({service:"local-model-sdk",module:"llm-reranking-model"}));this.modelId=e,this.languageModel=t,this.provider=t.provider||"external",this.options={llm:t,totalScore:s.totalScore??1,useEnhancedPrompt:s.useEnhancedPrompt??false,promptLanguage:s.promptLanguage??"en",modelOptions:s.modelOptions??{temperature:.1,maxTokens:3e4}},this.log.debug("LLMRerankingModel created",{modelId:e,provider:this.provider,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(e){let{query:t,documents:s,topN:r,abortSignal:o}=e,a;Array.isArray(s)?a=s:s.type==="text"?a=s.values.map((d,g)=>({content:d,id:`doc_${g+1}`})):a=s.values;let h=r??a.length;if(a.length===0)return {ranking:[],warnings:[]};try{let d=this.buildRerankPrompt(t,a),g=await ai$1.streamText({model:this.languageModel,prompt:d,maxOutputTokens:this.options.modelOptions.maxTokens,temperature:this.options.modelOptions.temperature,abortSignal:o}).text,p=this.extractTextContent(g),u=this.parseRerankResult(p,a,h);return {ranking:u.results.map(m=>({index:m.index,relevanceScore:m.score})),warnings:u.warnings.map(m=>({type:"other",message:m})),response:{timestamp:new Date,modelId:this.modelId}}}catch(d){return this.log.error("Reranking failed",{error:d.message}),{ranking:a.map((p,u)=>({index:u,relevanceScore:this.options.totalScore*(1-u/a.length)})),warnings:[{type:"other",message:`Reranking failed, using original order: ${d.message}`}],response:{timestamp:new Date,modelId:this.modelId}}}}extractTextContent(e){if(typeof e=="string")return e;if(e.text!==void 0)return e.text;if(e.content&&Array.isArray(e.content)){let t=e.content.find(s=>s.type==="text");if(t?.text)return t.text}return String(e)}buildRerankPrompt(e,t){let s=t.map((r,o)=>{let a=r.id||`doc_${o+1}`,h=r.content.slice(0,300);return `${o+1}. [ID: ${a}] ${h}`}).join(`
159
+ \u8F93\u51FA\u683C\u5F0F\uFF1A1,2,3,4,5\uFF08\u6700\u76F8\u5173\u7684\u6392\u5728\u524D\u9762\uFF09`}parseRerankResult(e,t,s){let r=[];try{let a=e.replaceAll(/<thinking>[\s\S]*?<\/thinking>/gi,"").replaceAll(/<think>[\s\S]*?<\/think>/gi,"").replaceAll(/<answer>[\s\S]*?<\/answer>/gi,"").trim().match(/\d+/g)?.map(m=>parseInt(m,10)-1).filter(m=>m>=0&&m<t.length)||[],h=[],l=new Set;for(let m of a)l.has(m)||(l.add(m),h.push(m));let d=[],f=new Set;for(let m of h)if(m!==void 0&&m>=0&&m<t.length&&!f.has(m)){f.add(m);let b=t[m];b&&d.push({index:m,score:this.options.totalScore*(1-d.length/h.length),document:b});}let u=new Set(h);for(let m=0;m<t.length;m++)if(!u.has(m)){let b=this.options.totalScore*.1*(1-m/t.length);d.push({index:m,score:b,document:t[m]});}let p=s?d.slice(0,s):d;return this.log.debug("Parsed rerank results",{extractedNumbers:a,uniqueIndices:h,resultCount:p.length,topK:s}),{results:p,warnings:r}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:e}),{results:t.map((h,l)=>({index:l,score:this.options.totalScore*(1-l/t.length),document:h})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};var Gi=class{constructor(e,t,s={}){c(this,"specificationVersion","v3");c(this,"provider");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Ce.create({service:"local-model-sdk",module:"llm-reranking-model"}));this.modelId=e,this.languageModel=t,this.provider=t.provider||"external",this.options={llm:t,totalScore:s.totalScore??1,useEnhancedPrompt:s.useEnhancedPrompt??false,promptLanguage:s.promptLanguage??"en",modelOptions:s.modelOptions??{temperature:.1,maxTokens:3e4}},this.log.debug("LLMRerankingModel created",{modelId:e,provider:this.provider,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(e){let{query:t,documents:s,topN:r,abortSignal:o}=e,a;Array.isArray(s)?a=s:s.type==="text"?a=s.values.map((d,f)=>({content:d,id:`doc_${f+1}`})):a=s.values;let h=r??a.length;if(a.length===0)return {ranking:[],warnings:[]};try{let d=this.buildRerankPrompt(t,a),f="",u=null;for(let m=0;m<2;m++)try{if(f=await(await ai$1.streamText({model:this.languageModel,prompt:d,maxOutputTokens:this.options.modelOptions.maxTokens,temperature:this.options.modelOptions.temperature,abortSignal:o})).text,this.log.debug("LLM raw output",{textContent:f,textLength:f?.length,attempt:m}),f&&f.trim().length>0)break;u=new Error("LLM returned empty response");}catch(b){u=b,this.log.warn(`LLM attempt ${m+1} failed: ${u.message}`);}if(!f||f.trim().length===0)throw this.log.warn("LLM returned empty response, using fallback"),u||new Error("LLM returned empty response");let p=this.parseRerankResult(f,a,h);return {ranking:p.results.map(m=>({index:m.index,relevanceScore:m.score,document:m.document})),warnings:p.warnings.map(m=>({type:"other",message:m})),response:{timestamp:new Date,modelId:this.modelId}}}catch(d){return this.log.error("Reranking failed",{error:d.message}),{ranking:a.map((u,p)=>({index:p,relevanceScore:this.options.totalScore*(1-p/a.length),document:u})),warnings:[{type:"other",message:`Reranking failed, using original order: ${d.message}`}],response:{timestamp:new Date,modelId:this.modelId}}}}extractTextContent(e){if(typeof e=="string")return e;if(e.text!==void 0)return e.text;if(e.content&&Array.isArray(e.content)){let t=e.content.find(s=>s.type==="text");if(t?.text)return t.text}return String(e)}buildRerankPrompt(e,t){let s=t.map((r,o)=>{let a=r.id||`doc_${o+1}`,h=r.content.slice(0,300);return `${o+1}. [ID: ${a}] ${h}`}).join(`
165
160
 
166
- `);if(this.options.useEnhancedPrompt)if(this.options.promptLanguage==="en"){this.options.totalScore===1?"1.0":`${this.options.totalScore}`;return `You are a professional information retrieval reranking expert. Please rank the following documents according to the query.
161
+ `);if(this.options.useEnhancedPrompt)if(this.options.promptLanguage==="en"){let r=this.options.totalScore===1?"1.0":`${this.options.totalScore}`;return `You are a professional information retrieval reranking expert. Please rank the following documents according to the query.
167
162
 
168
163
  User query: ${e}
169
164
 
@@ -174,14 +169,9 @@ Please rank the documents according to the following requirements:
174
169
  1. Carefully analyze the user's query intent and key information needs
175
170
  2. Evaluate each document's relevance to the query
176
171
  3. Consider the document's completeness, accuracy, and usefulness
177
- 4. Return to ranked document numbers separated by commas
172
+ 4. Return the ranked document numbers separated by commas
178
173
  5. Most relevant documents should be at the front
179
-
180
- Use a scoring scale from ${this.options.totalScore*.1} to ${this.options.totalScore} where ${this.options.totalScore*.1} is most relevant and ${this.options.totalScore} is least relevant.
181
- The actual score for each position should be calculated dynamically. For example:
182
- - If totalScore is 10: scores might be: 9, 7, 10, 4, 2
183
- - If totalScore is 1: scores might be: 0.2, 0.5, 1.0, 0.06, 0.04
184
- - If totalScore is 5: scores might be: 0.1, 0.25, 0.5, 0.03, 0.02
174
+ 6. Use a scoring scale from ${r}
185
175
 
186
176
  Example output format: 2,5,1,4,3
187
177
 
@@ -206,4 +196,4 @@ ${s}
206
196
 
207
197
  ${s}
208
198
 
209
- \u8F93\u51FA\u683C\u5F0F\uFF1A1,2,3,4,5\uFF08\u6700\u76F8\u5173\u7684\u6392\u5728\u524D\u9762\uFF09`}parseRerankResult(e,t,s){let r=[];try{let o=e.match(/\d+/g)?.map(u=>parseInt(u,10)-1).filter(u=>u>=0&&u<t.length)||[],a=[],h=new Set;for(let u of o)h.has(u)||(h.add(u),a.push(u));let l=[],d=new Set;for(let u of a)u!==void 0&&u>=0&&u<t.length&&!d.has(u)&&(d.add(u),l.push({index:u,score:this.options.totalScore*(1-l.length/a.length)}));let g=new Set(a);for(let u=0;u<t.length;u++)if(!g.has(u)){let m=this.options.totalScore*.1*(1-u/t.length);l.push({index:u,score:m});}let p=s?l.slice(0,s):l;return this.log.debug("Parsed rerank results",{extractedNumbers:o,uniqueIndices:a,resultCount:p.length,topK:s}),{results:p,warnings:r}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:e}),{results:t.map((h,l)=>({index:l,score:this.options.totalScore*(1-l/t.length)})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};var st=Ce.create({service:"local-model-provider"}),Xs={cacheDir:ii__namespace.default.join(process.env.EASBOT_CACHE_PATH??`${ii__namespace.default.join(tr__namespace.homedir(),".cache","easbot")}`,"models"),verbose:false,autoUnloadTimeout:300*1e3,maxCachedModels:3,memoryWarningThreshold:1.5*1024*1024*1024,useEnhancedModel:true,logDir:"",logLevel:"INFO"},Ss=class{constructor(e){c(this,"config");c(this,"modelCache");c(this,"engines",new Map);c(this,"modelInfo",new Map);this.config={...Xs,...e},this.modelCache=new $t({cacheDir:this.config.cacheDir});}languageModel(e,t){if(!xe[e])throw new x(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${e}`,"MODEL_NOT_FOUND");let s=this.getOrCreateEngine(e,"language");return t?.useEnhancedModel??this.config.useEnhancedModel?(this.config.verbose&&st.debug("\u521B\u5EFA\u589E\u5F3A\u8BED\u8A00\u6A21\u578B",{modelId:e}),new zi("local",e,s)):(this.config.verbose&&st.debug("\u521B\u5EFA\u57FA\u7840\u8BED\u8A00\u6A21\u578B",{modelId:e}),new Nt("local",e,s))}embeddingModel(e){if(!bt[e])throw new x(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${e}`,"MODEL_NOT_FOUND");let t=this.getOrCreateEngine(e,"embedding");return new ji("local",e,t)}chat(e,t){return this.languageModel(e,t)}rerankingModel(e,t){if(this.config.verbose&&st.debug("\u521B\u5EFA\u91CD\u6392\u5E8F\u6A21\u578B",{modelId:e,hasExternalLlm:!!t?.llm}),t?.llm)return new Gi(e,t.llm,t);if(!xe[e])throw new x(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${e}`,"MODEL_NOT_FOUND");let s=this.getOrCreateEngine(e,"language");return new Wi(e,this.config,s,t)}getOrCreateEngine(e,t){let s=`${t}:${e}`;if(this.engines.has(s)){let o=this.modelInfo.get(s);return o&&(o.lastUsed=Date.now(),o.useCount++),this.config.verbose&&st.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&&st.debug("\u521B\u5EFA\u65B0\u5F15\u64CE",{engineKey:s});let r=new ys({modelId:e,modelType:t,cacheDir:this.config.cacheDir,verbose:this.config.verbose});return this.engines.set(s,r),this.modelInfo.set(s,{modelId:e,modelType:t,isLoaded:false,lastUsed:Date.now(),useCount:1}),r}evictLeastRecentlyUsed(){let e=null,t=Number.POSITIVE_INFINITY;for(let[s,r]of this.modelInfo.entries())r.lastUsed<t&&(t=r.lastUsed,e=s);if(e){this.config.verbose&&st.debug("\u6DD8\u6C70\u6A21\u578B",{engineKey:e});let s=this.engines.get(e);s&&s.dispose().catch(r=>{st.error("\u5378\u8F7D\u6A21\u578B\u5931\u8D25",{error:r});}),this.engines.delete(e),this.modelInfo.delete(e);}}getLoadedModels(){return Array.from(this.modelInfo.values())}async dispose(){this.config.verbose&&st.debug("\u5378\u8F7D\u6240\u6709\u6A21\u578B");let e=Array.from(this.engines.values()).map(t=>t.dispose());await Promise.all(e),this.engines.clear(),this.modelInfo.clear(),this.config.verbose&&st.debug("\u6240\u6709\u6A21\u578B\u5DF2\u5378\u8F7D");}};function el(i){let e=new Ss(i);if(i?.logDir){let s=i.logLevel??"INFO",r=ii__namespace.default.join(i.logDir,"local-model-sdk.log");Ce.init({print:process.argv.includes("--print-logs"),logDir:i.logDir,level:s,logFile:"local-model-sdk.log"}).then(()=>{Ce.create({service:"local-model-sdk",module:"provider"}).debug("Local model provider created",{cacheDir:i?.cacheDir||Xs.cacheDir,useEnhancedModel:i?.useEnhancedModel??Xs.useEnhancedModel,logFile:r,logLevel:s});});}return Object.assign((s,r)=>e.languageModel(s,r),{languageModel:(s,r)=>e.languageModel(s,r),chat:(s,r)=>e.chat(s,r),embeddingModel:s=>e.embeddingModel(s),rerankingModel:(s,r)=>e.rerankingModel(s,r)})}var tl="0.1.0",il="@easbot/local-model-sdk",sl="Complete local model SDK for EASBot - Transformers.js + ONNX implementation";exports.ErrorCode=me;exports.ErrorHandler=ne;exports.LLMRerankingModel=Gi;exports.LocalEmbeddingModel=ji;exports.LocalEnhancedLanguageModel=zi;exports.LocalLanguageModel=Nt;exports.LocalModelError=x;exports.LocalModelProvider=Ss;exports.LocalRerankingModel=Wi;exports.SDK_DESCRIPTION=sl;exports.SDK_NAME=il;exports.SUPPORTED_EMBEDDING_MODELS=bt;exports.SUPPORTED_LANGUAGE_MODELS=xe;exports.VERSION=tl;exports.createLocal=el;
199
+ \u8F93\u51FA\u683C\u5F0F\uFF1A1,2,3,4,5\uFF08\u6700\u76F8\u5173\u7684\u6392\u5728\u524D\u9762\uFF09`}parseRerankResult(e,t,s){let r=[];try{let o=e.match(/\d+/g)?.map(p=>parseInt(p,10)-1).filter(p=>p>=0&&p<t.length)||[],a=[],h=new Set;for(let p of o)h.has(p)||(h.add(p),a.push(p));let l=[],d=new Set;for(let p of a)if(p!==void 0&&p>=0&&p<t.length&&!d.has(p)){d.add(p);let m=t[p];m&&l.push({index:p,score:this.options.totalScore*(1-l.length/a.length),document:m});}let f=new Set(a);for(let p=0;p<t.length;p++)if(!f.has(p)){let m=this.options.totalScore*.1*(1-p/t.length);l.push({index:p,score:m,document:t[p]});}let u=s?l.slice(0,s):l;return this.log.debug("Parsed rerank results",{extractedNumbers:o,uniqueIndices:a,resultCount:u.length,topK:s}),{results:u,warnings:r}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:e}),{results:t.map((h,l)=>({index:l,score:this.options.totalScore*(1-l/t.length),document:h})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};var it=Ce.create({service:"local-model-provider"}),Qs={cacheDir:ii__namespace.default.join(process.env.EASBOT_CACHE_PATH??`${ii__namespace.default.join(ir__namespace.homedir(),".cache","easbot")}`,"models"),verbose:false,autoUnloadTimeout:300*1e3,maxCachedModels:3,memoryWarningThreshold:1.5*1024*1024*1024,useEnhancedModel:true,logDir:"",logLevel:"INFO"},Ss=class{constructor(e){c(this,"config");c(this,"modelCache");c(this,"engines",new Map);c(this,"modelInfo",new Map);this.config={...Qs,...e},this.modelCache=new $t({cacheDir:this.config.cacheDir});}languageModel(e,t){if(!Te[e])throw new T(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${e}`,"MODEL_NOT_FOUND");let s=this.getOrCreateEngine(e,"language");return t?.useEnhancedModel??this.config.useEnhancedModel?(this.config.verbose&&it.debug("\u521B\u5EFA\u589E\u5F3A\u8BED\u8A00\u6A21\u578B",{modelId:e}),new zi("local",e,s)):(this.config.verbose&&it.debug("\u521B\u5EFA\u57FA\u7840\u8BED\u8A00\u6A21\u578B",{modelId:e}),new Nt("local",e,s))}embeddingModel(e){if(!wt[e])throw new T(`\u4E0D\u652F\u6301\u7684 Embedding Model ID: ${e}`,"MODEL_NOT_FOUND");let t=this.getOrCreateEngine(e,"embedding");return new ji("local",e,t)}chat(e,t){return this.languageModel(e,t)}rerankingModel(e,t){if(this.config.verbose&&it.debug("\u521B\u5EFA\u91CD\u6392\u5E8F\u6A21\u578B",{modelId:e,hasExternalLlm:!!t?.llm}),t?.llm)return new Gi(e,t.llm,t);if(!Te[e])throw new T(`\u4E0D\u652F\u6301\u7684 Language Model ID: ${e}`,"MODEL_NOT_FOUND");let s=this.getOrCreateEngine(e,"language");return new Wi(e,this.config,s,t)}getOrCreateEngine(e,t){let s=`${t}:${e}`;if(this.engines.has(s)){let o=this.modelInfo.get(s);return o&&(o.lastUsed=Date.now(),o.useCount++),this.config.verbose&&it.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&&it.debug("\u521B\u5EFA\u65B0\u5F15\u64CE",{engineKey:s});let r=new ys({modelId:e,modelType:t,cacheDir:this.config.cacheDir,verbose:this.config.verbose});return this.engines.set(s,r),this.modelInfo.set(s,{modelId:e,modelType:t,isLoaded:false,lastUsed:Date.now(),useCount:1}),r}evictLeastRecentlyUsed(){let e=null,t=Number.POSITIVE_INFINITY;for(let[s,r]of this.modelInfo.entries())r.lastUsed<t&&(t=r.lastUsed,e=s);if(e){this.config.verbose&&it.debug("\u6DD8\u6C70\u6A21\u578B",{engineKey:e});let s=this.engines.get(e);s&&s.dispose().catch(r=>{it.error("\u5378\u8F7D\u6A21\u578B\u5931\u8D25",{error:r});}),this.engines.delete(e),this.modelInfo.delete(e);}}getLoadedModels(){return Array.from(this.modelInfo.values())}async dispose(){this.config.verbose&&it.debug("\u5378\u8F7D\u6240\u6709\u6A21\u578B");let e=Array.from(this.engines.values()).map(t=>t.dispose());await Promise.all(e),this.engines.clear(),this.modelInfo.clear(),this.config.verbose&&it.debug("\u6240\u6709\u6A21\u578B\u5DF2\u5378\u8F7D");}};function tl(i){let e=new Ss(i);if(i?.logDir){let s=i.logLevel??"INFO",r=ii__namespace.default.join(i.logDir,"local-model-sdk.log");Ce.init({print:process.argv.includes("--print-logs"),logDir:i.logDir,level:s,logFile:"local-model-sdk.log"}).then(()=>{Ce.create({service:"local-model-sdk",module:"provider"}).debug("Local model provider created",{cacheDir:i?.cacheDir||Qs.cacheDir,useEnhancedModel:i?.useEnhancedModel??Qs.useEnhancedModel,logFile:r,logLevel:s});});}return Object.assign((s,r)=>e.languageModel(s,r),{languageModel:(s,r)=>e.languageModel(s,r),chat:(s,r)=>e.chat(s,r),embeddingModel:s=>e.embeddingModel(s),rerankingModel:(s,r)=>e.rerankingModel(s,r)})}var il="0.1.0",sl="@easbot/local-model-sdk",rl="Complete local model SDK for EASBot - Transformers.js + ONNX implementation";exports.ErrorCode=me;exports.ErrorHandler=ne;exports.LLMRerankingModel=Gi;exports.LocalEmbeddingModel=ji;exports.LocalEnhancedLanguageModel=zi;exports.LocalLanguageModel=Nt;exports.LocalModelError=T;exports.LocalModelProvider=Ss;exports.LocalRerankingModel=Wi;exports.SDK_DESCRIPTION=rl;exports.SDK_NAME=sl;exports.SUPPORTED_EMBEDDING_MODELS=wt;exports.SUPPORTED_LANGUAGE_MODELS=Te;exports.VERSION=il;exports.createLocal=tl;