@easbot/ollama-sdk 0.2.23 → 0.2.25

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.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import ni,{win32,posix}from'path';import Ln,{realpath,readlink,readdir,lstat}from'fs/promises';import*as Yo from'fs';import {realpathSync,createWriteStream,readlinkSync,readdirSync,readdir as readdir$1,lstatSync}from'fs';import Ia from'zod';import {fileURLToPath}from'url';import {EventEmitter}from'events';import en from'stream';import {StringDecoder}from'string_decoder';import {formatLogTime}from'@easbot/utils';var Fn=Object.defineProperty;var Gi=s=>{throw TypeError(s)};var In=(s,t,e)=>t in s?Fn(s,t,{enumerable:true,configurable:true,writable:true,value:e}):s[t]=e;var c=(s,t,e)=>In(s,typeof t!="symbol"?t+"":t,e),ui=(s,t,e)=>t.has(s)||Gi("Cannot "+e);var r=(s,t,e)=>(ui(s,t,"read from private field"),e?e.call(s):t.get(s)),y=(s,t,e)=>t.has(s)?Gi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),p=(s,t,e,i)=>(ui(s,t,"write to private field"),t.set(s,e),e),m=(s,t,e)=>(ui(s,t,"access private method"),e);var Fs=(s,t,e,i)=>({set _(n){p(s,t,n);},get _(){return r(s,t,i)}});var Is=class{constructor(t="http://localhost:11434"){c(this,"baseURL",t);}async*streamChat(t){let e=await fetch(`${this.baseURL}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,stream:true})});if(!e.ok)throw new Error(`Ollama API error: ${e.status} ${e.statusText}`);if(!e.body)throw new Error("Response body is null");let i=e.body.getReader(),n=new TextDecoder,o="";try{for(;;){let{done:a,value:l}=await i.read();if(a){if(o.trim())try{yield JSON.parse(o);}catch{}break}o+=n.decode(l,{stream:!0});let h=o.split(`
2
- `);o=h.pop()||"";for(let d of h){let f=d.trim();if(f)try{yield JSON.parse(f);}catch{}}}}finally{i.releaseLock();}}async chat(t){let e=await fetch(`${this.baseURL}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,stream:false})});if(!e.ok)throw new Error(`Ollama API error: ${e.status} ${e.statusText}`);return e.json()}};var _e={numCtx:262144,temperature:.7,topK:40,topP:.9,repeatPenalty:1.1,numPredict:32e3},Dn=["numCtx","repeatPenalty","numPredict"];var ee=class extends Error{constructor(e,i){super(e);c(this,"cause",i);this.name="OllamaError",Object.setPrototypeOf(this,new.target.prototype);}},di=class extends ee{constructor(e,i,n){super(e,n);c(this,"url",i);this.name="ConnectionError";}},pi=class extends ee{constructor(e,i){super(`Model not found: ${e}`,i);c(this,"modelId",e);this.name="ModelNotFoundError";}},fi=class extends ee{constructor(e,i,n,o){super(e,o);c(this,"field",i);c(this,"value",n);this.name="ValidationError";}},gi=class extends ee{constructor(e,i,n){super(e,n);c(this,"timeoutMs",i);this.name="TimeoutError";}},Ze=class extends ee{constructor(e,i,n){super(`Invalid tool definition for "${e}": missing ${i}`,n);c(this,"toolName",e);c(this,"missingField",i);this.name="InvalidToolDefinitionError";}};var Nr=(s,t,e)=>{let i=s instanceof RegExp?Vi(s,e):s,n=t instanceof RegExp?Vi(t,e):t,o=i!==null&&n!=null&&Nn(i,n,e);return o&&{start:o[0],end:o[1],pre:e.slice(0,o[0]),body:e.slice(o[0]+i.length,o[1]),post:e.slice(o[1]+n.length)}},Vi=(s,t)=>{let e=t.match(s);return e?e[0]:null},Nn=(s,t,e)=>{let i,n,o,a,l,h=e.indexOf(s),d=e.indexOf(t,h+1),f=h;if(h>=0&&d>0){if(s===t)return [h,d];for(i=[],o=e.length;f>=0&&!l;){if(f===h)i.push(f),h=e.indexOf(s,f+1);else if(i.length===1){let u=i.pop();u!==void 0&&(l=[u,d]);}else n=i.pop(),n!==void 0&&n<o&&(o=n,a=d),d=e.indexOf(t,f+1);f=h<d&&h>=0?h:d;}i.length&&a!==void 0&&(l=[o,a]);}return l},jr="\0SLASH"+Math.random()+"\0",Wr="\0OPEN"+Math.random()+"\0",ji="\0CLOSE"+Math.random()+"\0",$r="\0COMMA"+Math.random()+"\0",zr="\0PERIOD"+Math.random()+"\0",jn=new RegExp(jr,"g"),Wn=new RegExp(Wr,"g"),$n=new RegExp(ji,"g"),zn=new RegExp($r,"g"),Un=new RegExp(zr,"g"),Bn=/\\\\/g,Gn=/\\{/g,Vn=/\\}/g,qn=/\\,/g,Jn=/\\./g,Hn=1e5;function mi(s){return isNaN(s)?s.charCodeAt(0):parseInt(s,10)}function Zn(s){return s.replace(Bn,jr).replace(Gn,Wr).replace(Vn,ji).replace(qn,$r).replace(Jn,zr)}function Kn(s){return s.replace(jn,"\\").replace(Wn,"{").replace($n,"}").replace(zn,",").replace(Un,".")}function Ur(s){if(!s)return [""];let t=[],e=Nr("{","}",s);if(!e)return s.split(",");let{pre:i,body:n,post:o}=e,a=i.split(",");a[a.length-1]+="{"+n+"}";let l=Ur(o);return o.length&&(a[a.length-1]+=l.shift(),a.push.apply(a,l)),t.push.apply(t,a),t}function Yn(s,t={}){if(!s)return [];let{max:e=Hn}=t;return s.slice(0,2)==="{}"&&(s="\\{\\}"+s.slice(2)),ss(Zn(s),e,true).map(Kn)}function Qn(s){return "{"+s+"}"}function Xn(s){return /^-?0\d/.test(s)}function to(s,t){return s<=t}function eo(s,t){return s>=t}function ss(s,t,e){let i=[],n=Nr("{","}",s);if(!n)return [s];let o=n.pre,a=n.post.length?ss(n.post,t,false):[""];if(/\$$/.test(n.pre))for(let l=0;l<a.length&&l<t;l++){let h=o+"{"+n.body+"}"+a[l];i.push(h);}else {let l=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(n.body),h=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body),d=l||h,f=n.body.indexOf(",")>=0;if(!d&&!f)return n.post.match(/,(?!,).*\}/)?(s=n.pre+"{"+n.body+ji+n.post,ss(s,t,true)):[s];let u;if(d)u=n.body.split(/\.\./);else if(u=Ur(n.body),u.length===1&&u[0]!==void 0&&(u=ss(u[0],t,false).map(Qn),u.length===1))return a.map(w=>n.pre+u[0]+w);let g;if(d&&u[0]!==void 0&&u[1]!==void 0){let w=mi(u[0]),v=mi(u[1]),S=Math.max(u[0].length,u[1].length),k=u.length===3&&u[2]!==void 0?Math.abs(mi(u[2])):1,b=to;v<w&&(k*=-1,b=eo);let O=u.some(Xn);g=[];for(let M=w;b(M,v);M+=k){let E;if(h)E=String.fromCharCode(M),E==="\\"&&(E="");else if(E=String(M),O){let I=S-E.length;if(I>0){let C=new Array(I+1).join("0");M<0?E="-"+C+E.slice(1):E=C+E;}}g.push(E);}}else {g=[];for(let w=0;w<u.length;w++)g.push.apply(g,ss(u[w],t,false));}for(let w=0;w<g.length;w++)for(let v=0;v<a.length&&i.length<t;v++){let S=o+g[w]+a[v];(!e||d||S)&&i.push(S);}}return i}var Qs=s=>{if(typeof s!="string")throw new TypeError("invalid pattern");if(s.length>65536)throw new TypeError("pattern is too long")},so={"[: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]},Ke=s=>s.replace(/[[\]\\-]/g,"\\$&"),io=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),qi=s=>s.join(""),ro=(s,t)=>{let e=t;if(s.charAt(e)!=="[")throw new Error("not in a brace expression");let i=[],n=[],o=e+1,a=false,l=false,h=false,d=false,f=e,u="";t:for(;o<s.length;){let v=s.charAt(o);if((v==="!"||v==="^")&&o===e+1){d=true,o++;continue}if(v==="]"&&a&&!h){f=o+1;break}if(a=true,v==="\\"&&!h){h=true,o++;continue}if(v==="["&&!h){for(let[S,[k,b,O]]of Object.entries(so))if(s.startsWith(S,o)){if(u)return ["$.",false,s.length-e,true];o+=S.length,O?n.push(k):i.push(k),l=l||b;continue t}}if(h=false,u){v>u?i.push(Ke(u)+"-"+Ke(v)):v===u&&i.push(Ke(v)),u="",o++;continue}if(s.startsWith("-]",o+1)){i.push(Ke(v+"-")),o+=2;continue}if(s.startsWith("-",o+1)){u=v,o+=2;continue}i.push(Ke(v)),o++;}if(f<o)return ["",false,0,false];if(!i.length&&!n.length)return ["$.",false,s.length-e,true];if(n.length===0&&i.length===1&&/^\\?.$/.test(i[0])&&!d){let v=i[0].length===2?i[0].slice(-1):i[0];return [io(v),false,f-e,false]}let g="["+(d?"^":"")+qi(i)+"]",w="["+(d?"":"^")+qi(n)+"]";return [i.length&&n.length?"("+g+"|"+w+")":i.length?g:w,l,f-e,true]},Ie=(s,{windowsPathsNoEscape:t=false,magicalBraces:e=true}={})=>e?t?s.replace(/\[([^\/\\])\]/g,"$1"):s.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?s.replace(/\[([^\/\\{}])\]/g,"$1"):s.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),no=new Set(["!","?","+","*","@"]),Ji=s=>no.has(s),oo="(?!(?:^|/)\\.\\.?(?:$|/))",Ds="(?!\\.)",ao=new Set(["[","."]),lo=new Set(["..","."]),ho=new Set("().*{}+?[]^$\\!"),co=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Wi="[^/]",Hi=Wi+"*?",Zi=Wi+"+?",B,K,qt,j,z,ae,be,le,Wt,ve,hs,Le,Gr,fe,X,Gs,Ei,Vr,Br=(X=class{constructor(t,e,i={}){y(this,Le);c(this,"type");y(this,B);y(this,K);y(this,qt,false);y(this,j,[]);y(this,z);y(this,ae);y(this,be);y(this,le,false);y(this,Wt);y(this,ve);y(this,hs,false);this.type=t,t&&p(this,K,true),p(this,z,e),p(this,B,r(this,z)?r(r(this,z),B):this),p(this,Wt,r(this,B)===this?i:r(r(this,B),Wt)),p(this,be,r(this,B)===this?[]:r(r(this,B),be)),t==="!"&&!r(r(this,B),le)&&r(this,be).push(this),p(this,ae,r(this,z)?r(r(this,z),j).length:0);}get hasMagic(){if(r(this,K)!==void 0)return r(this,K);for(let t of r(this,j))if(typeof t!="string"&&(t.type||t.hasMagic))return p(this,K,true);return r(this,K)}toString(){return r(this,ve)!==void 0?r(this,ve):this.type?p(this,ve,this.type+"("+r(this,j).map(t=>String(t)).join("|")+")"):p(this,ve,r(this,j).map(t=>String(t)).join(""))}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof X&&r(e,z)===this))throw new Error("invalid part: "+e);r(this,j).push(e);}}toJSON(){let t=this.type===null?r(this,j).slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...r(this,j).map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===r(this,B)||r(r(this,B),le)&&r(this,z)?.type==="!")&&t.push({}),t}isStart(){if(r(this,B)===this)return true;if(!r(this,z)?.isStart())return false;if(r(this,ae)===0)return true;let t=r(this,z);for(let e=0;e<r(this,ae);e++){let i=r(t,j)[e];if(!(i instanceof X&&i.type==="!"))return false}return true}isEnd(){if(r(this,B)===this||r(this,z)?.type==="!")return true;if(!r(this,z)?.isEnd())return false;if(!this.type)return r(this,z)?.isEnd();let t=r(this,z)?r(r(this,z),j).length:0;return r(this,ae)===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this));}clone(t){let e=new X(this.type,t);for(let i of r(this,j))e.copyIn(i);return e}static fromGlob(t,e={}){var n;let i=new X(null,void 0,e);return m(n=X,fe,Gs).call(n,t,i,0,e),i}toMMPattern(){if(this!==r(this,B))return r(this,B).toMMPattern();let t=this.toString(),[e,i,n,o]=this.toRegExpSource();if(!(n||r(this,K)||r(this,Wt).nocase&&!r(this,Wt).nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return i;let a=(r(this,Wt).nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${e}$`,a),{_src:e,_glob:t})}get options(){return r(this,Wt)}toRegExpSource(t){let e=t??!!r(this,Wt).dot;if(r(this,B)===this&&m(this,Le,Gr).call(this),!this.type){let h=this.isStart()&&this.isEnd()&&!r(this,j).some(g=>typeof g!="string"),d=r(this,j).map(g=>{var b;let[w,v,S,k]=typeof g=="string"?m(b=X,fe,Vr).call(b,g,r(this,K),h):g.toRegExpSource(t);return p(this,K,r(this,K)||S),p(this,qt,r(this,qt)||k),w}).join(""),f="";if(this.isStart()&&typeof r(this,j)[0]=="string"&&!(r(this,j).length===1&&lo.has(r(this,j)[0]))){let g=ao,w=e&&g.has(d.charAt(0))||d.startsWith("\\.")&&g.has(d.charAt(2))||d.startsWith("\\.\\.")&&g.has(d.charAt(4)),v=!e&&!t&&g.has(d.charAt(0));f=w?oo:v?Ds:"";}let u="";return this.isEnd()&&r(r(this,B),le)&&r(this,z)?.type==="!"&&(u="(?:$|\\/)"),[f+d+u,Ie(d),p(this,K,!!r(this,K)),r(this,qt)]}let i=this.type==="*"||this.type==="+",n=this.type==="!"?"(?:(?!(?:":"(?:",o=m(this,Le,Ei).call(this,e);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let h=this.toString();return p(this,j,[h]),this.type=null,p(this,K,void 0),[h,Ie(this.toString()),false,false]}let a=!i||t||e||!Ds?"":m(this,Le,Ei).call(this,true);a===o&&(a=""),a&&(o=`(?:${o})(?:${a})*?`);let l="";if(this.type==="!"&&r(this,hs))l=(this.isStart()&&!e?Ds:"")+Zi;else {let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?Ds:"")+Hi+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&a?")":this.type==="*"&&a?")?":`)${this.type}`;l=n+o+h;}return [l,Ie(o),p(this,K,!!r(this,K)),r(this,qt)]}},B=new WeakMap,K=new WeakMap,qt=new WeakMap,j=new WeakMap,z=new WeakMap,ae=new WeakMap,be=new WeakMap,le=new WeakMap,Wt=new WeakMap,ve=new WeakMap,hs=new WeakMap,Le=new WeakSet,Gr=function(){if(this!==r(this,B))throw new Error("should only call on root");if(r(this,le))return this;this.toString(),p(this,le,true);let t;for(;t=r(this,be).pop();){if(t.type!=="!")continue;let e=t,i=r(e,z);for(;i;){for(let n=r(e,ae)+1;!i.type&&n<r(i,j).length;n++)for(let o of r(t,j)){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(r(i,j)[n]);}e=i,i=r(e,z);}}return this},fe=new WeakSet,Gs=function(t,e,i,n){var w,v;let o=false,a=false,l=-1,h=false;if(e.type===null){let S=i,k="";for(;S<t.length;){let b=t.charAt(S++);if(o||b==="\\"){o=!o,k+=b;continue}if(a){S===l+1?(b==="^"||b==="!")&&(h=true):b==="]"&&!(S===l+2&&h)&&(a=false),k+=b;continue}else if(b==="["){a=true,l=S,h=false,k+=b;continue}if(!n.noext&&Ji(b)&&t.charAt(S)==="("){e.push(k),k="";let O=new X(b,e);S=m(w=X,fe,Gs).call(w,t,O,S,n),e.push(O);continue}k+=b;}return e.push(k),S}let d=i+1,f=new X(null,e),u=[],g="";for(;d<t.length;){let S=t.charAt(d++);if(o||S==="\\"){o=!o,g+=S;continue}if(a){d===l+1?(S==="^"||S==="!")&&(h=true):S==="]"&&!(d===l+2&&h)&&(a=false),g+=S;continue}else if(S==="["){a=true,l=d,h=false,g+=S;continue}if(Ji(S)&&t.charAt(d)==="("){f.push(g),g="";let k=new X(S,f);f.push(k),d=m(v=X,fe,Gs).call(v,t,k,d,n);continue}if(S==="|"){f.push(g),g="",u.push(f),f=new X(null,e);continue}if(S===")")return g===""&&r(e,j).length===0&&p(e,hs,true),f.push(g),g="",e.push(...u,f),d;g+=S;}return e.type=null,p(e,K,void 0),p(e,j,[t.substring(i-1)]),d},Ei=function(t){return r(this,j).map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[i,n,o,a]=e.toRegExpSource(t);return p(this,qt,r(this,qt)||a),i}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")},Vr=function(t,e,i=false){let n=false,o="",a=false,l=false;for(let h=0;h<t.length;h++){let d=t.charAt(h);if(n){n=false,o+=(ho.has(d)?"\\":"")+d;continue}if(d==="*"){if(l)continue;l=true,o+=i&&/^[*]+$/.test(t)?Zi:Hi,e=true;continue}else l=false;if(d==="\\"){h===t.length-1?o+="\\\\":n=true;continue}if(d==="["){let[f,u,g,w]=ro(t,h);if(g){o+=f,a=a||u,h+=g-1,e=e||w;continue}}if(d==="?"){o+=Wi,e=true;continue}o+=co(d);}return [o,Ie(t),!!e,a]},y(X,fe),X),qr=(s,{windowsPathsNoEscape:t=false,magicalBraces:e=false}={})=>e?t?s.replace(/[?*()[\]{}]/g,"[$&]"):s.replace(/[?*()[\]\\{}]/g,"\\$&"):t?s.replace(/[?*()[\]]/g,"[$&]"):s.replace(/[?*()[\]\\]/g,"\\$&"),lt=(s,t,e={})=>(Qs(t),!e.nocomment&&t.charAt(0)==="#"?false:new ge(t,e).match(s)),uo=/^\*+([^+@!?\*\[\(]*)$/,po=s=>t=>!t.startsWith(".")&&t.endsWith(s),fo=s=>t=>t.endsWith(s),go=s=>(s=s.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(s)),mo=s=>(s=s.toLowerCase(),t=>t.toLowerCase().endsWith(s)),yo=/^\*+\.\*+$/,wo=s=>!s.startsWith(".")&&s.includes("."),bo=s=>s!=="."&&s!==".."&&s.includes("."),vo=/^\.\*+$/,So=s=>s!=="."&&s!==".."&&s.startsWith("."),xo=/^\*+$/,ko=s=>s.length!==0&&!s.startsWith("."),Eo=s=>s.length!==0&&s!=="."&&s!=="..",Co=/^\?+([^+@!?\*\[\(]*)?$/,Oo=([s,t=""])=>{let e=Jr([s]);return t?(t=t.toLowerCase(),i=>e(i)&&i.toLowerCase().endsWith(t)):e},Ro=([s,t=""])=>{let e=Hr([s]);return t?(t=t.toLowerCase(),i=>e(i)&&i.toLowerCase().endsWith(t)):e},Mo=([s,t=""])=>{let e=Hr([s]);return t?i=>e(i)&&i.endsWith(t):e},Lo=([s,t=""])=>{let e=Jr([s]);return t?i=>e(i)&&i.endsWith(t):e},Jr=([s])=>{let t=s.length;return e=>e.length===t&&!e.startsWith(".")},Hr=([s])=>{let t=s.length;return e=>e.length===t&&e!=="."&&e!==".."},Zr=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Ki={win32:{sep:"\\"},posix:{sep:"/"}},Ao=Zr==="win32"?Ki.win32.sep:Ki.posix.sep;lt.sep=Ao;var at=Symbol("globstar **");lt.GLOBSTAR=at;var To="[^/]",_o=To+"*?",Po="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Fo="(?:(?!(?:\\/|^)\\.).)*?",Io=(s,t={})=>e=>lt(e,s,t);lt.filter=Io;var bt=(s,t={})=>Object.assign({},s,t),Do=s=>{if(!s||typeof s!="object"||!Object.keys(s).length)return lt;let t=lt;return Object.assign((e,i,n={})=>t(e,i,bt(s,n)),{Minimatch:class extends t.Minimatch{constructor(e,i={}){super(e,bt(s,i));}static defaults(e){return t.defaults(bt(s,e)).Minimatch}},AST:class extends t.AST{constructor(e,i,n={}){super(e,i,bt(s,n));}static fromGlob(e,i={}){return t.AST.fromGlob(e,bt(s,i))}},unescape:(e,i={})=>t.unescape(e,bt(s,i)),escape:(e,i={})=>t.escape(e,bt(s,i)),filter:(e,i={})=>t.filter(e,bt(s,i)),defaults:e=>t.defaults(bt(s,e)),makeRe:(e,i={})=>t.makeRe(e,bt(s,i)),braceExpand:(e,i={})=>t.braceExpand(e,bt(s,i)),match:(e,i,n={})=>t.match(e,i,bt(s,n)),sep:t.sep,GLOBSTAR:at})};lt.defaults=Do;var Kr=(s,t={})=>(Qs(s),t.nobrace||!/\{(?:(?!\{).)*\}/.test(s)?[s]:Yn(s,{max:t.braceExpandMax}));lt.braceExpand=Kr;var No=(s,t={})=>new ge(s,t).makeRe();lt.makeRe=No;var jo=(s,t,e={})=>{let i=new ge(t,e);return s=s.filter(n=>i.match(n)),i.options.nonull&&!s.length&&s.push(t),s};lt.match=jo;var Yi=/[?*]|[+@!]\(.*?\)|\[|\]/,Wo=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),ge=class{constructor(s,t={}){c(this,"options");c(this,"set");c(this,"pattern");c(this,"windowsPathsNoEscape");c(this,"nonegate");c(this,"negate");c(this,"comment");c(this,"empty");c(this,"preserveMultipleSlashes");c(this,"partial");c(this,"globSet");c(this,"globParts");c(this,"nocase");c(this,"isWindows");c(this,"platform");c(this,"windowsNoMagicRoot");c(this,"regexp");Qs(s),t=t||{},this.options=t,this.pattern=s,this.platform=t.platform||Zr,this.isWindows=this.platform==="win32";let e="allowWindowsEscape";this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t[e]===false,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=false,this.nonegate=!!t.nonegate,this.comment=false,this.empty=false,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot!==void 0?t.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make();}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return true;for(let s of this.set)for(let t of s)if(typeof t!="string")return true;return false}debug(...s){}make(){let s=this.pattern,t=this.options;if(!t.nocomment&&s.charAt(0)==="#"){this.comment=true;return}if(!s){this.empty=true;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...n)=>console.error(...n)),this.debug(this.pattern,this.globSet);let e=this.globSet.map(n=>this.slashSplit(n));this.globParts=this.preprocess(e),this.debug(this.pattern,this.globParts);let i=this.globParts.map((n,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=n[0]===""&&n[1]===""&&(n[2]==="?"||!Yi.test(n[2]))&&!Yi.test(n[3]),h=/^[a-z]:/i.test(n[0]);if(l)return [...n.slice(0,4),...n.slice(4).map(d=>this.parse(d))];if(h)return [n[0],...n.slice(1).map(d=>this.parse(d))]}return n.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(n=>n.indexOf(false)===-1),this.isWindows)for(let n=0;n<this.set.length;n++){let o=this.set[n];o[0]===""&&o[1]===""&&this.globParts[n][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?");}this.debug(this.pattern,this.set);}preprocess(s){if(this.options.noglobstar)for(let e=0;e<s.length;e++)for(let i=0;i<s[e].length;i++)s[e][i]==="**"&&(s[e][i]="*");let{optimizationLevel:t=1}=this.options;return t>=2?(s=this.firstPhasePreProcess(s),s=this.secondPhasePreProcess(s)):t>=1?s=this.levelOneOptimize(s):s=this.adjascentGlobstarOptimize(s),s}adjascentGlobstarOptimize(s){return s.map(t=>{let e=-1;for(;(e=t.indexOf("**",e+1))!==-1;){let i=e;for(;t[i+1]==="**";)i++;i!==e&&t.splice(e,i-e);}return t})}levelOneOptimize(s){return s.map(t=>(t=t.reduce((e,i)=>{let n=e[e.length-1];return i==="**"&&n==="**"?e:i===".."&&n&&n!==".."&&n!=="."&&n!=="**"?(e.pop(),e):(e.push(i),e)},[]),t.length===0?[""]:t))}levelTwoFileOptimize(s){Array.isArray(s)||(s=this.slashSplit(s));let t=false;do{if(t=false,!this.preserveMultipleSlashes){for(let i=1;i<s.length-1;i++){let n=s[i];i===1&&n===""&&s[0]===""||(n==="."||n==="")&&(t=true,s.splice(i,1),i--);}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(t=true,s.pop());}let e=0;for(;(e=s.indexOf("..",e+1))!==-1;){let i=s[e-1];i&&i!=="."&&i!==".."&&i!=="**"&&(t=true,s.splice(e-1,2),e-=2);}}while(t);return s.length===0?[""]:s}firstPhasePreProcess(s){let t=false;do{t=false;for(let e of s){let i=-1;for(;(i=e.indexOf("**",i+1))!==-1;){let o=i;for(;e[o+1]==="**";)o++;o>i&&e.splice(i+1,o-i);let a=e[i+1],l=e[i+2],h=e[i+3];if(a!==".."||!l||l==="."||l===".."||!h||h==="."||h==="..")continue;t=true,e.splice(i,1);let d=e.slice(0);d[i]="**",s.push(d),i--;}if(!this.preserveMultipleSlashes){for(let o=1;o<e.length-1;o++){let a=e[o];o===1&&a===""&&e[0]===""||(a==="."||a==="")&&(t=true,e.splice(o,1),o--);}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(t=true,e.pop());}let n=0;for(;(n=e.indexOf("..",n+1))!==-1;){let o=e[n-1];if(o&&o!=="."&&o!==".."&&o!=="**"){t=true;let a=n===1&&e[n+1]==="**"?["."]:[];e.splice(n-1,2,...a),e.length===0&&e.push(""),n-=2;}}}}while(t);return s}secondPhasePreProcess(s){for(let t=0;t<s.length-1;t++)for(let e=t+1;e<s.length;e++){let i=this.partsMatch(s[t],s[e],!this.preserveMultipleSlashes);if(i){s[t]=[],s[e]=i;break}}return s.filter(t=>t.length)}partsMatch(s,t,e=false){let i=0,n=0,o=[],a="";for(;i<s.length&&n<t.length;)if(s[i]===t[n])o.push(a==="b"?t[n]:s[i]),i++,n++;else if(e&&s[i]==="**"&&t[n]===s[i+1])o.push(s[i]),i++;else if(e&&t[n]==="**"&&s[i]===t[n+1])o.push(t[n]),n++;else if(s[i]==="*"&&t[n]&&(this.options.dot||!t[n].startsWith("."))&&t[n]!=="**"){if(a==="b")return false;a="a",o.push(s[i]),i++,n++;}else if(t[n]==="*"&&s[i]&&(this.options.dot||!s[i].startsWith("."))&&s[i]!=="**"){if(a==="a")return false;a="b",o.push(t[n]),i++,n++;}else return false;return s.length===t.length&&o}parseNegate(){if(this.nonegate)return;let s=this.pattern,t=false,e=0;for(let i=0;i<s.length&&s.charAt(i)==="!";i++)t=!t,e++;e&&(this.pattern=s.slice(e)),this.negate=t;}matchOne(s,t,e=false){let i=this.options;if(this.isWindows){let v=typeof s[0]=="string"&&/^[a-z]:$/i.test(s[0]),S=!v&&s[0]===""&&s[1]===""&&s[2]==="?"&&/^[a-z]:$/i.test(s[3]),k=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),b=!k&&t[0]===""&&t[1]===""&&t[2]==="?"&&typeof t[3]=="string"&&/^[a-z]:$/i.test(t[3]),O=S?3:v?0:void 0,M=b?3:k?0:void 0;if(typeof O=="number"&&typeof M=="number"){let[E,I]=[s[O],t[M]];E.toLowerCase()===I.toLowerCase()&&(t[M]=E,M>O?t=t.slice(M):O>M&&(s=s.slice(O)));}}let{optimizationLevel:n=1}=this.options;n>=2&&(s=this.levelTwoFileOptimize(s)),this.debug("matchOne",this,{file:s,pattern:t}),this.debug("matchOne",s.length,t.length);for(var o=0,a=0,l=s.length,h=t.length;o<l&&a<h;o++,a++){this.debug("matchOne loop");var d=t[a],f=s[o];if(this.debug(t,d,f),d===false)return false;if(d===at){this.debug("GLOBSTAR",[t,d,f]);var u=o,g=a+1;if(g===h){for(this.debug("** at the end");o<l;o++)if(s[o]==="."||s[o]===".."||!i.dot&&s[o].charAt(0)===".")return false;return true}for(;u<l;){var w=s[u];if(this.debug(`
3
- globstar while`,s,u,t,g,w),this.matchOne(s.slice(u),t.slice(g),e))return this.debug("globstar found match!",u,l,w),true;if(w==="."||w===".."||!i.dot&&w.charAt(0)==="."){this.debug("dot detected!",s,u,t,g);break}this.debug("globstar swallow a segment, and continue"),u++;}return !!(e&&(this.debug(`
4
- >>> no match, partial?`,s,u,t,g),u===l))}let v;if(typeof d=="string"?(v=f===d,this.debug("string match",d,f,v)):(v=d.test(f),this.debug("pattern match",d,f,v)),!v)return false}if(o===l&&a===h)return true;if(o===l)return e;if(a===h)return o===l-1&&s[o]==="";throw new Error("wtf?")}braceExpand(){return Kr(this.pattern,this.options)}parse(s){Qs(s);let t=this.options;if(s==="**")return at;if(s==="")return "";let e,i=null;(e=s.match(xo))?i=t.dot?Eo:ko:(e=s.match(uo))?i=(t.nocase?t.dot?mo:go:t.dot?fo:po)(e[1]):(e=s.match(Co))?i=(t.nocase?t.dot?Ro:Oo:t.dot?Mo:Lo)(e):(e=s.match(yo))?i=t.dot?bo:wo:(e=s.match(vo))&&(i=So);let n=Br.fromGlob(s,this.options).toMMPattern();return i&&typeof n=="object"&&Reflect.defineProperty(n,"test",{value:i}),n}makeRe(){if(this.regexp||this.regexp===false)return this.regexp;let s=this.set;if(!s.length)return this.regexp=false,this.regexp;let t=this.options,e=t.noglobstar?_o:t.dot?Po:Fo,i=new Set(t.nocase?["i"]:[]),n=s.map(l=>{let h=l.map(f=>{if(f instanceof RegExp)for(let u of f.flags.split(""))i.add(u);return typeof f=="string"?Wo(f):f===at?at:f._src});h.forEach((f,u)=>{let g=h[u+1],w=h[u-1];f!==at||w===at||(w===void 0?g!==void 0&&g!==at?h[u+1]="(?:\\/|"+e+"\\/)?"+g:h[u]=e:g===void 0?h[u-1]=w+"(?:\\/|\\/"+e+")?":g!==at&&(h[u-1]=w+"(?:\\/|\\/"+e+"\\/)"+g,h[u+1]=at));});let d=h.filter(f=>f!==at);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]=s.length>1?["(?:",")"]:["",""];n="^"+o+n+a+"$",this.partial&&(n="^(?:\\/|"+o+n.slice(1,-1)+a+")$"),this.negate&&(n="^(?!"+n+").+$");try{this.regexp=new RegExp(n,[...i].join(""));}catch{this.regexp=false;}return this.regexp}slashSplit(s){return this.preserveMultipleSlashes?s.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(s)?["",...s.split(/\/+/)]:s.split(/\/+/)}match(s,t=this.partial){if(this.debug("match",s,this.pattern),this.comment)return false;if(this.empty)return s==="";if(s==="/"&&t)return true;let e=this.options;this.isWindows&&(s=s.split("\\").join("/"));let i=this.slashSplit(s);this.debug(this.pattern,"split",i);let n=this.set;this.debug(this.pattern,"set",n);let o=i[i.length-1];if(!o)for(let a=i.length-2;!o&&a>=0;a--)o=i[a];for(let a=0;a<n.length;a++){let l=n[a],h=i;if(e.matchBase&&l.length===1&&(h=[o]),this.matchOne(h,l,t))return e.flipNegate?true:!this.negate}return e.flipNegate?false:this.negate}static defaults(s){return lt.defaults(s).Minimatch}};lt.AST=Br;lt.Minimatch=ge;lt.escape=qr;lt.unescape=Ie;var zo=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Yr=new Set,Ci=typeof process=="object"&&process?process:{},Qr=(s,t,e,i)=>{typeof Ci.emitWarning=="function"?Ci.emitWarning(s,t,e,i):console.error(`[${e}] ${t}: ${s}`);},Xs=globalThis.AbortController,Qi=globalThis.AbortSignal;if(typeof Xs>"u"){Qi=class{constructor(){c(this,"onabort");c(this,"_onabort",[]);c(this,"reason");c(this,"aborted",false);}addEventListener(e,i){this._onabort.push(i);}},Xs=class{constructor(){c(this,"signal",new Qi);t();}abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=true;for(let i of this.signal._onabort)i(e);this.signal.onabort?.(e);}}};let s=Ci.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{s&&(s=false,Qr("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t));};}var Uo=s=>!Yr.has(s),ie=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),Xr=s=>ie(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Vs:null:null,Vs=class extends Array{constructor(s){super(s),this.fill(0);}},Ut,De,Bo=(Ut=class{constructor(t,e){c(this,"heap");c(this,"length");if(!r(Ut,De))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0;}static create(t){let e=Xr(t);if(!e)return [];p(Ut,De,true);let i=new Ut(t,e);return p(Ut,De,false),i}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},De=new WeakMap,y(Ut,De,false),Ut),pr,fr,St,dt,Rt,Se,Mt,Ne,je,Lt,G,At,U,W,A,rt,pt,et,Y,Tt,Q,_t,Pt,ft,gt,Ft,he,nt,We,x,Oi,xe,Jt,cs,mt,tn,ke,$e,us,re,ne,Ri,qs,Js,N,Mi,is,oe,Li,ze,si=(ze=class{constructor(t){y(this,x);y(this,St);y(this,dt);y(this,Rt);y(this,Se);y(this,Mt);y(this,Ne);y(this,je);y(this,Lt);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");y(this,G);y(this,At);y(this,U);y(this,W);y(this,A);y(this,rt);y(this,pt);y(this,et);y(this,Y);y(this,Tt);y(this,Q);y(this,_t);y(this,Pt);y(this,ft);y(this,gt);y(this,Ft);y(this,he);y(this,nt);y(this,We);y(this,xe,()=>{});y(this,Jt,()=>{});y(this,cs,()=>{});y(this,mt,()=>false);y(this,ke,t=>{});y(this,$e,(t,e,i)=>{});y(this,us,(t,e,i,n)=>{if(i||n)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});c(this,pr,"LRUCache");let{max:e=0,ttl:i,ttlResolution:n=1,ttlAutopurge:o,updateAgeOnGet:a,updateAgeOnHas:l,allowStale:h,dispose:d,onInsert:f,disposeAfter:u,noDisposeOnSet:g,noUpdateTTL:w,maxSize:v=0,maxEntrySize:S=0,sizeCalculation:k,fetchMethod:b,memoMethod:O,noDeleteOnFetchRejection:M,noDeleteOnStaleGet:E,allowStaleOnFetchRejection:I,allowStaleOnFetchAbort:C,ignoreFetchAbort:_,perf:F}=t;if(F!==void 0&&typeof F?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(p(this,Lt,F??zo),e!==0&&!ie(e))throw new TypeError("max option must be a nonnegative integer");let P=e?Xr(e):Array;if(!P)throw new Error("invalid max value: "+e);if(p(this,St,e),p(this,dt,v),this.maxEntrySize=S||r(this,dt),this.sizeCalculation=k,this.sizeCalculation){if(!r(this,dt)&&!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(O!==void 0&&typeof O!="function")throw new TypeError("memoMethod must be a function if defined");if(p(this,je,O),b!==void 0&&typeof b!="function")throw new TypeError("fetchMethod must be a function if specified");if(p(this,Ne,b),p(this,he,!!b),p(this,U,new Map),p(this,W,new Array(e).fill(void 0)),p(this,A,new Array(e).fill(void 0)),p(this,rt,new P(e)),p(this,pt,new P(e)),p(this,et,0),p(this,Y,0),p(this,Tt,Bo.create(e)),p(this,G,0),p(this,At,0),typeof d=="function"&&p(this,Rt,d),typeof f=="function"&&p(this,Se,f),typeof u=="function"?(p(this,Mt,u),p(this,Q,[])):(p(this,Mt,void 0),p(this,Q,void 0)),p(this,Ft,!!r(this,Rt)),p(this,We,!!r(this,Se)),p(this,nt,!!r(this,Mt)),this.noDisposeOnSet=!!g,this.noUpdateTTL=!!w,this.noDeleteOnFetchRejection=!!M,this.allowStaleOnFetchRejection=!!I,this.allowStaleOnFetchAbort=!!C,this.ignoreFetchAbort=!!_,this.maxEntrySize!==0){if(r(this,dt)!==0&&!ie(r(this,dt)))throw new TypeError("maxSize must be a positive integer if specified");if(!ie(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");m(this,x,tn).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!E,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!l,this.ttlResolution=ie(n)||n===0?n:1,this.ttlAutopurge=!!o,this.ttl=i||0,this.ttl){if(!ie(this.ttl))throw new TypeError("ttl must be a positive integer if specified");m(this,x,Oi).call(this);}if(r(this,St)===0&&this.ttl===0&&r(this,dt)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,St)&&!r(this,dt)){let T="LRU_CACHE_UNBOUNDED";Uo(T)&&(Yr.add(T),Qr("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",T,ze));}}get perf(){return r(this,Lt)}static unsafeExposeInternals(t){return {starts:r(t,Pt),ttls:r(t,ft),autopurgeTimers:r(t,gt),sizes:r(t,_t),keyMap:r(t,U),keyList:r(t,W),valList:r(t,A),next:r(t,rt),prev:r(t,pt),get head(){return r(t,et)},get tail(){return r(t,Y)},free:r(t,Tt),isBackgroundFetch:e=>{var i;return m(i=t,x,N).call(i,e)},backgroundFetch:(e,i,n,o)=>{var a;return m(a=t,x,Js).call(a,e,i,n,o)},moveToTail:e=>{var i;return m(i=t,x,is).call(i,e)},indexes:e=>{var i;return m(i=t,x,re).call(i,e)},rindexes:e=>{var i;return m(i=t,x,ne).call(i,e)},isStale:e=>{var i;return r(i=t,mt).call(i,e)}}}get max(){return r(this,St)}get maxSize(){return r(this,dt)}get calculatedSize(){return r(this,At)}get size(){return r(this,G)}get fetchMethod(){return r(this,Ne)}get memoMethod(){return r(this,je)}get dispose(){return r(this,Rt)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,Mt)}getRemainingTTL(t){return r(this,U).has(t)?1/0:0}*entries(){for(let t of m(this,x,re).call(this))r(this,A)[t]!==void 0&&r(this,W)[t]!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield [r(this,W)[t],r(this,A)[t]]);}*rentries(){for(let t of m(this,x,ne).call(this))r(this,A)[t]!==void 0&&r(this,W)[t]!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield [r(this,W)[t],r(this,A)[t]]);}*keys(){for(let t of m(this,x,re).call(this)){let e=r(this,W)[t];e!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield e);}}*rkeys(){for(let t of m(this,x,ne).call(this)){let e=r(this,W)[t];e!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield e);}}*values(){for(let t of m(this,x,re).call(this))r(this,A)[t]!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield r(this,A)[t]);}*rvalues(){for(let t of m(this,x,ne).call(this))r(this,A)[t]!==void 0&&!m(this,x,N).call(this,r(this,A)[t])&&(yield r(this,A)[t]);}[(fr=Symbol.iterator,pr=Symbol.toStringTag,fr)](){return this.entries()}find(t,e={}){for(let i of m(this,x,re).call(this)){let n=r(this,A)[i],o=m(this,x,N).call(this,n)?n.__staleWhileFetching:n;if(o!==void 0&&t(o,r(this,W)[i],this))return this.get(r(this,W)[i],e)}}forEach(t,e=this){for(let i of m(this,x,re).call(this)){let n=r(this,A)[i],o=m(this,x,N).call(this,n)?n.__staleWhileFetching:n;o!==void 0&&t.call(e,o,r(this,W)[i],this);}}rforEach(t,e=this){for(let i of m(this,x,ne).call(this)){let n=r(this,A)[i],o=m(this,x,N).call(this,n)?n.__staleWhileFetching:n;o!==void 0&&t.call(e,o,r(this,W)[i],this);}}purgeStale(){let t=false;for(let e of m(this,x,ne).call(this,{allowStale:true}))r(this,mt).call(this,e)&&(m(this,x,oe).call(this,r(this,W)[e],"expire"),t=true);return t}info(t){let e=r(this,U).get(t);if(e===void 0)return;let i=r(this,A)[e],n=m(this,x,N).call(this,i)?i.__staleWhileFetching:i;if(n===void 0)return;let o={value:n};if(r(this,ft)&&r(this,Pt)){let a=r(this,ft)[e],l=r(this,Pt)[e];if(a&&l){let h=a-(r(this,Lt).now()-l);o.ttl=h,o.start=Date.now();}}return r(this,_t)&&(o.size=r(this,_t)[e]),o}dump(){let t=[];for(let e of m(this,x,re).call(this,{allowStale:true})){let i=r(this,W)[e],n=r(this,A)[e],o=m(this,x,N).call(this,n)?n.__staleWhileFetching:n;if(o===void 0||i===void 0)continue;let a={value:o};if(r(this,ft)&&r(this,Pt)){a.ttl=r(this,ft)[e];let l=r(this,Lt).now()-r(this,Pt)[e];a.start=Math.floor(Date.now()-l);}r(this,_t)&&(a.size=r(this,_t)[e]),t.unshift([i,a]);}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let n=Date.now()-i.start;i.start=r(this,Lt).now()-n;}this.set(e,i.value,i);}}set(t,e,i={}){var g,w,v,S;if(e===void 0)return this.delete(t),this;let{ttl:n=this.ttl,start:o,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:h}=i,{noUpdateTTL:d=this.noUpdateTTL}=i,f=r(this,us).call(this,t,e,i.size||0,l);if(this.maxEntrySize&&f>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),m(this,x,oe).call(this,t,"set"),this;let u=r(this,G)===0?void 0:r(this,U).get(t);if(u===void 0)u=r(this,G)===0?r(this,Y):r(this,Tt).length!==0?r(this,Tt).pop():r(this,G)===r(this,St)?m(this,x,qs).call(this,false):r(this,G),r(this,W)[u]=t,r(this,A)[u]=e,r(this,U).set(t,u),r(this,rt)[r(this,Y)]=u,r(this,pt)[u]=r(this,Y),p(this,Y,u),Fs(this,G)._++,r(this,$e).call(this,u,f,h),h&&(h.set="add"),d=false,r(this,We)&&((g=r(this,Se))==null||g.call(this,e,t,"add"));else {m(this,x,is).call(this,u);let k=r(this,A)[u];if(e!==k){if(r(this,he)&&m(this,x,N).call(this,k)){k.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:b}=k;b!==void 0&&!a&&(r(this,Ft)&&((w=r(this,Rt))==null||w.call(this,b,t,"set")),r(this,nt)&&r(this,Q)?.push([b,t,"set"]));}else a||(r(this,Ft)&&((v=r(this,Rt))==null||v.call(this,k,t,"set")),r(this,nt)&&r(this,Q)?.push([k,t,"set"]));if(r(this,ke).call(this,u),r(this,$e).call(this,u,f,h),r(this,A)[u]=e,h){h.set="replace";let b=k&&m(this,x,N).call(this,k)?k.__staleWhileFetching:k;b!==void 0&&(h.oldValue=b);}}else h&&(h.set="update");r(this,We)&&this.onInsert?.(e,t,e===k?"update":"replace");}if(n!==0&&!r(this,ft)&&m(this,x,Oi).call(this),r(this,ft)&&(d||r(this,cs).call(this,u,n,o),h&&r(this,Jt).call(this,h,u)),!a&&r(this,nt)&&r(this,Q)){let k=r(this,Q),b;for(;b=k?.shift();)(S=r(this,Mt))==null||S.call(this,...b);}return this}pop(){var t;try{for(;r(this,G);){let e=r(this,A)[r(this,et)];if(m(this,x,qs).call(this,!0),m(this,x,N).call(this,e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(r(this,nt)&&r(this,Q)){let e=r(this,Q),i;for(;i=e?.shift();)(t=r(this,Mt))==null||t.call(this,...i);}}}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:n}=e,o=r(this,U).get(t);if(o!==void 0){let a=r(this,A)[o];if(m(this,x,N).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(r(this,mt).call(this,o))n&&(n.has="stale",r(this,Jt).call(this,n,o));else return i&&r(this,xe).call(this,o),n&&(n.has="hit",r(this,Jt).call(this,n,o)),true}else n&&(n.has="miss");return false}peek(t,e={}){let{allowStale:i=this.allowStale}=e,n=r(this,U).get(t);if(n===void 0||!i&&r(this,mt).call(this,n))return;let o=r(this,A)[n];return m(this,x,N).call(this,o)?o.__staleWhileFetching:o}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:h=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:f=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:g=this.allowStaleOnFetchRejection,ignoreFetchAbort:w=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:S,forceRefresh:k=false,status:b,signal:O}=e;if(!r(this,he))return b&&(b.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:o,status:b});let M={allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:o,ttl:a,noDisposeOnSet:l,size:h,sizeCalculation:d,noUpdateTTL:f,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:g,allowStaleOnFetchAbort:v,ignoreFetchAbort:w,status:b,signal:O},E=r(this,U).get(t);if(E===void 0){b&&(b.fetch="miss");let I=m(this,x,Js).call(this,t,E,M,S);return I.__returned=I}else {let I=r(this,A)[E];if(m(this,x,N).call(this,I)){let P=i&&I.__staleWhileFetching!==void 0;return b&&(b.fetch="inflight",P&&(b.returnedStale=true)),P?I.__staleWhileFetching:I.__returned=I}let C=r(this,mt).call(this,E);if(!k&&!C)return b&&(b.fetch="hit"),m(this,x,is).call(this,E),n&&r(this,xe).call(this,E),b&&r(this,Jt).call(this,b,E),I;let _=m(this,x,Js).call(this,t,E,M,S),F=_.__staleWhileFetching!==void 0&&i;return b&&(b.fetch=C?"stale":"refresh",F&&C&&(b.returnedStale=true)),F?_.__staleWhileFetching:_.__returned=_}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=r(this,je);if(!i)throw new Error("no memoMethod provided to constructor");let{context:n,forceRefresh:o,...a}=e,l=this.get(t,a);if(!o&&l!==void 0)return l;let h=i(t,l,{options:a,context:n});return this.set(t,h,a),h}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:a}=e,l=r(this,U).get(t);if(l!==void 0){let h=r(this,A)[l],d=m(this,x,N).call(this,h);return a&&r(this,Jt).call(this,a,l),r(this,mt).call(this,l)?(a&&(a.get="stale"),d?(a&&i&&h.__staleWhileFetching!==void 0&&(a.returnedStale=true),i?h.__staleWhileFetching:void 0):(o||m(this,x,oe).call(this,t,"expire"),a&&i&&(a.returnedStale=true),i?h:void 0)):(a&&(a.get="hit"),d?h.__staleWhileFetching:(m(this,x,is).call(this,l),n&&r(this,xe).call(this,l),h))}else a&&(a.get="miss");}delete(t){return m(this,x,oe).call(this,t,"delete")}clear(){return m(this,x,Li).call(this,"delete")}},St=new WeakMap,dt=new WeakMap,Rt=new WeakMap,Se=new WeakMap,Mt=new WeakMap,Ne=new WeakMap,je=new WeakMap,Lt=new WeakMap,G=new WeakMap,At=new WeakMap,U=new WeakMap,W=new WeakMap,A=new WeakMap,rt=new WeakMap,pt=new WeakMap,et=new WeakMap,Y=new WeakMap,Tt=new WeakMap,Q=new WeakMap,_t=new WeakMap,Pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,Ft=new WeakMap,he=new WeakMap,nt=new WeakMap,We=new WeakMap,x=new WeakSet,Oi=function(){let t=new Vs(r(this,St)),e=new Vs(r(this,St));p(this,ft,t),p(this,Pt,e);let i=this.ttlAutopurge?new Array(r(this,St)):void 0;p(this,gt,i),p(this,cs,(a,l,h=r(this,Lt).now())=>{if(e[a]=l!==0?h:0,t[a]=l,i?.[a]&&(clearTimeout(i[a]),i[a]=void 0),l!==0&&i){let d=setTimeout(()=>{r(this,mt).call(this,a)&&m(this,x,oe).call(this,r(this,W)[a],"expire");},l+1);d.unref&&d.unref(),i[a]=d;}}),p(this,xe,a=>{e[a]=t[a]!==0?r(this,Lt).now():0;}),p(this,Jt,(a,l)=>{if(t[l]){let h=t[l],d=e[l];if(!h||!d)return;a.ttl=h,a.start=d,a.now=n||o();let f=a.now-d;a.remainingTTL=h-f;}});let n=0,o=()=>{let a=r(this,Lt).now();if(this.ttlResolution>0){n=a;let l=setTimeout(()=>n=0,this.ttlResolution);l.unref&&l.unref();}return a};this.getRemainingTTL=a=>{let l=r(this,U).get(a);if(l===void 0)return 0;let h=t[l],d=e[l];if(!h||!d)return 1/0;let f=(n||o())-d;return h-f},p(this,mt,a=>{let l=e[a],h=t[a];return !!h&&!!l&&(n||o())-l>h});},xe=new WeakMap,Jt=new WeakMap,cs=new WeakMap,mt=new WeakMap,tn=function(){let t=new Vs(r(this,St));p(this,At,0),p(this,_t,t),p(this,ke,e=>{p(this,At,r(this,At)-t[e]),t[e]=0;}),p(this,us,(e,i,n,o)=>{if(m(this,x,N).call(this,i))return 0;if(!ie(n))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(n=o(i,e),!ie(n))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 n}),p(this,$e,(e,i,n)=>{if(t[e]=i,r(this,dt)){let o=r(this,dt)-t[e];for(;r(this,At)>o;)m(this,x,qs).call(this,true);}p(this,At,r(this,At)+t[e]),n&&(n.entrySize=i,n.totalCalculatedSize=r(this,At));});},ke=new WeakMap,$e=new WeakMap,us=new WeakMap,re=function*({allowStale:t=this.allowStale}={}){if(r(this,G))for(let e=r(this,Y);!(!m(this,x,Ri).call(this,e)||((t||!r(this,mt).call(this,e))&&(yield e),e===r(this,et)));)e=r(this,pt)[e];},ne=function*({allowStale:t=this.allowStale}={}){if(r(this,G))for(let e=r(this,et);!(!m(this,x,Ri).call(this,e)||((t||!r(this,mt).call(this,e))&&(yield e),e===r(this,Y)));)e=r(this,rt)[e];},Ri=function(t){return t!==void 0&&r(this,U).get(r(this,W)[t])===t},qs=function(t){var o;let e=r(this,et),i=r(this,W)[e],n=r(this,A)[e];return r(this,he)&&m(this,x,N).call(this,n)?n.__abortController.abort(new Error("evicted")):(r(this,Ft)||r(this,nt))&&(r(this,Ft)&&((o=r(this,Rt))==null||o.call(this,n,i,"evict")),r(this,nt)&&r(this,Q)?.push([n,i,"evict"])),r(this,ke).call(this,e),r(this,gt)?.[e]&&(clearTimeout(r(this,gt)[e]),r(this,gt)[e]=void 0),t&&(r(this,W)[e]=void 0,r(this,A)[e]=void 0,r(this,Tt).push(e)),r(this,G)===1?(p(this,et,p(this,Y,0)),r(this,Tt).length=0):p(this,et,r(this,rt)[e]),r(this,U).delete(i),Fs(this,G)._--,e},Js=function(t,e,i,n){let o=e===void 0?void 0:r(this,A)[e];if(m(this,x,N).call(this,o))return o;let a=new Xs,{signal:l}=i;l?.addEventListener("abort",()=>a.abort(l.reason),{signal:a.signal});let h={signal:a.signal,options:i,context:n},d=(S,k=false)=>{let{aborted:b}=a.signal,O=i.ignoreFetchAbort&&S!==void 0,M=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&S!==void 0);if(i.status&&(b&&!k?(i.status.fetchAborted=true,i.status.fetchError=a.signal.reason,O&&(i.status.fetchAbortIgnored=true)):i.status.fetchResolved=true),b&&!O&&!k)return u(a.signal.reason,M);let E=w,I=r(this,A)[e];return (I===w||O&&k&&I===void 0)&&(S===void 0?E.__staleWhileFetching!==void 0?r(this,A)[e]=E.__staleWhileFetching:m(this,x,oe).call(this,t,"fetch"):(i.status&&(i.status.fetchUpdated=true),this.set(t,S,h.options))),S},f=S=>(i.status&&(i.status.fetchRejected=true,i.status.fetchError=S),u(S,false)),u=(S,k)=>{let{aborted:b}=a.signal,O=b&&i.allowStaleOnFetchAbort,M=O||i.allowStaleOnFetchRejection,E=M||i.noDeleteOnFetchRejection,I=w;if(r(this,A)[e]===w&&(!E||!k&&I.__staleWhileFetching===void 0?m(this,x,oe).call(this,t,"fetch"):O||(r(this,A)[e]=I.__staleWhileFetching)),M)return i.status&&I.__staleWhileFetching!==void 0&&(i.status.returnedStale=true),I.__staleWhileFetching;if(I.__returned===I)throw S},g=(S,k)=>{var O;let b=(O=r(this,Ne))==null?void 0:O.call(this,t,o,h);b&&b instanceof Promise&&b.then(M=>S(M===void 0?void 0:M),k),a.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(S(void 0),i.allowStaleOnFetchAbort&&(S=M=>d(M,true)));});};i.status&&(i.status.fetchDispatched=true);let w=new Promise(g).then(d,f),v=Object.assign(w,{__abortController:a,__staleWhileFetching:o,__returned:void 0});return e===void 0?(this.set(t,v,{...h.options,status:void 0}),e=r(this,U).get(t)):r(this,A)[e]=v,v},N=function(t){if(!r(this,he))return false;let e=t;return !!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof Xs},Mi=function(t,e){r(this,pt)[e]=t,r(this,rt)[t]=e;},is=function(t){t!==r(this,Y)&&(t===r(this,et)?p(this,et,r(this,rt)[t]):m(this,x,Mi).call(this,r(this,pt)[t],r(this,rt)[t]),m(this,x,Mi).call(this,r(this,Y),t),p(this,Y,t));},oe=function(t,e){var n,o;let i=false;if(r(this,G)!==0){let a=r(this,U).get(t);if(a!==void 0)if(r(this,gt)?.[a]&&(clearTimeout(r(this,gt)?.[a]),r(this,gt)[a]=void 0),i=true,r(this,G)===1)m(this,x,Li).call(this,e);else {r(this,ke).call(this,a);let l=r(this,A)[a];if(m(this,x,N).call(this,l)?l.__abortController.abort(new Error("deleted")):(r(this,Ft)||r(this,nt))&&(r(this,Ft)&&((n=r(this,Rt))==null||n.call(this,l,t,e)),r(this,nt)&&r(this,Q)?.push([l,t,e])),r(this,U).delete(t),r(this,W)[a]=void 0,r(this,A)[a]=void 0,a===r(this,Y))p(this,Y,r(this,pt)[a]);else if(a===r(this,et))p(this,et,r(this,rt)[a]);else {let h=r(this,pt)[a];r(this,rt)[h]=r(this,rt)[a];let d=r(this,rt)[a];r(this,pt)[d]=r(this,pt)[a];}Fs(this,G)._--,r(this,Tt).push(a);}}if(r(this,nt)&&r(this,Q)?.length){let a=r(this,Q),l;for(;l=a?.shift();)(o=r(this,Mt))==null||o.call(this,...l);}return i},Li=function(t){var e,i;for(let n of m(this,x,ne).call(this,{allowStale:true})){let o=r(this,A)[n];if(m(this,x,N).call(this,o))o.__abortController.abort(new Error("deleted"));else {let a=r(this,W)[n];r(this,Ft)&&((e=r(this,Rt))==null||e.call(this,o,a,t)),r(this,nt)&&r(this,Q)?.push([o,a,t]);}}if(r(this,U).clear(),r(this,A).fill(void 0),r(this,W).fill(void 0),r(this,ft)&&r(this,Pt)){r(this,ft).fill(0),r(this,Pt).fill(0);for(let n of r(this,gt)??[])n!==void 0&&clearTimeout(n);r(this,gt)?.fill(void 0);}if(r(this,_t)&&r(this,_t).fill(0),p(this,et,0),p(this,Y,0),r(this,Tt).length=0,p(this,At,0),p(this,G,0),r(this,nt)&&r(this,Q)){let n=r(this,Q),o;for(;o=n?.shift();)(i=r(this,Mt))==null||i.call(this,...o);}},ze),Xi=typeof process=="object"&&process?process:{stdout:null,stderr:null},ia=s=>!!s&&typeof s=="object"&&(s instanceof ti||s instanceof en||ra(s)||na(s)),ra=s=>!!s&&typeof s=="object"&&s instanceof EventEmitter&&typeof s.pipe=="function"&&s.pipe!==en.Writable.prototype.pipe,na=s=>!!s&&typeof s=="object"&&s instanceof EventEmitter&&typeof s.write=="function"&&typeof s.end=="function",Gt=Symbol("EOF"),Vt=Symbol("maybeEmitEnd"),se=Symbol("emittedEnd"),Ns=Symbol("emittingEnd"),Ye=Symbol("emittedError"),js=Symbol("closed"),tr=Symbol("read"),Ws=Symbol("flush"),er=Symbol("flushChunk"),Ct=Symbol("encoding"),Pe=Symbol("decoder"),J=Symbol("flowing"),Qe=Symbol("paused"),Fe=Symbol("resume"),H=Symbol("buffer"),it=Symbol("pipes"),Z=Symbol("bufferLength"),yi=Symbol("bufferPush"),$s=Symbol("bufferShift"),tt=Symbol("objectMode"),$=Symbol("destroyed"),wi=Symbol("error"),bi=Symbol("emitData"),sr=Symbol("emitEnd"),vi=Symbol("emitEnd2"),Nt=Symbol("async"),Si=Symbol("abort"),zs=Symbol("aborted"),Xe=Symbol("signal"),me=Symbol("dataListeners"),ut=Symbol("discarded"),ts=s=>Promise.resolve().then(s),oa=s=>s(),aa=s=>s==="end"||s==="finish"||s==="prefinish",la=s=>s instanceof ArrayBuffer||!!s&&typeof s=="object"&&s.constructor&&s.constructor.name==="ArrayBuffer"&&s.byteLength>=0,ha=s=>!Buffer.isBuffer(s)&&ArrayBuffer.isView(s),sn=class{constructor(s,t,e){c(this,"src");c(this,"dest");c(this,"opts");c(this,"ondrain");this.src=s,this.dest=t,this.opts=e,this.ondrain=()=>s[Fe](),this.dest.on("drain",this.ondrain);}unpipe(){this.dest.removeListener("drain",this.ondrain);}proxyErrors(s){}end(){this.unpipe(),this.opts.end&&this.dest.end();}},ca=class extends sn{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe();}constructor(s,t,e){super(s,t,e),this.proxyErrors=i=>this.dest.emit("error",i),s.on("error",this.proxyErrors);}},ua=s=>!!s.objectMode,da=s=>!s.objectMode&&!!s.encoding&&s.encoding!=="buffer",gr,mr,yr,wr,br,vr,Sr,xr,kr,Er,Cr,Or,Rr,Mr,Lr,Ar,Tr,_r,Pr,ti=class extends EventEmitter{constructor(...t){let e=t[0]||{};super();c(this,Pr,false);c(this,_r,false);c(this,Tr,[]);c(this,Ar,[]);c(this,Lr);c(this,Mr);c(this,Rr);c(this,Or);c(this,Cr,false);c(this,Er,false);c(this,kr,false);c(this,xr,false);c(this,Sr,null);c(this,vr,0);c(this,br,false);c(this,wr);c(this,yr,false);c(this,mr,0);c(this,gr,false);c(this,"writable",true);c(this,"readable",true);if(e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");ua(e)?(this[tt]=true,this[Ct]=null):da(e)?(this[Ct]=e.encoding,this[tt]=false):(this[tt]=false,this[Ct]=null),this[Nt]=!!e.async,this[Pe]=this[Ct]?new StringDecoder(this[Ct]):null,e&&e.debugExposeBuffer===true&&Object.defineProperty(this,"buffer",{get:()=>this[H]}),e&&e.debugExposePipes===true&&Object.defineProperty(this,"pipes",{get:()=>this[it]});let{signal:i}=e;i&&(this[Xe]=i,i.aborted?this[Si]():i.addEventListener("abort",()=>this[Si]()));}get bufferLength(){return this[Z]}get encoding(){return this[Ct]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[tt]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Nt]}set async(t){this[Nt]=this[Nt]||!!t;}[(Pr=J,_r=Qe,Tr=it,Ar=H,Lr=tt,Mr=Ct,Rr=Nt,Or=Pe,Cr=Gt,Er=se,kr=Ns,xr=js,Sr=Ye,vr=Z,br=$,wr=Xe,yr=zs,mr=me,gr=ut,Si)](){this[zs]=true,this.emit("abort",this[Xe]?.reason),this.destroy(this[Xe]?.reason);}get aborted(){return this[zs]}set aborted(t){}write(t,e,i){if(this[zs])return false;if(this[Gt])throw new Error("write after end");if(this[$])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),true;typeof e=="function"&&(i=e,e="utf8"),e||(e="utf8");let n=this[Nt]?ts:oa;if(!this[tt]&&!Buffer.isBuffer(t)){if(ha(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(la(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[tt]?(this[J]&&this[Z]!==0&&this[Ws](true),this[J]?this.emit("data",t):this[yi](t),this[Z]!==0&&this.emit("readable"),i&&n(i),this[J]):t.length?(typeof t=="string"&&!(e===this[Ct]&&!this[Pe]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[Ct]&&(t=this[Pe].write(t)),this[J]&&this[Z]!==0&&this[Ws](true),this[J]?this.emit("data",t):this[yi](t),this[Z]!==0&&this.emit("readable"),i&&n(i),this[J]):(this[Z]!==0&&this.emit("readable"),i&&n(i),this[J])}read(t){if(this[$])return null;if(this[ut]=false,this[Z]===0||t===0||t&&t>this[Z])return this[Vt](),null;this[tt]&&(t=null),this[H].length>1&&!this[tt]&&(this[H]=[this[Ct]?this[H].join(""):Buffer.concat(this[H],this[Z])]);let e=this[tr](t||null,this[H][0]);return this[Vt](),e}[tr](t,e){if(this[tt])this[$s]();else {let i=e;t===i.length||t===null?this[$s]():typeof i=="string"?(this[H][0]=i.slice(t),e=i.slice(0,t),this[Z]-=t):(this[H][0]=i.subarray(t),e=i.subarray(0,t),this[Z]-=t);}return this.emit("data",e),!this[H].length&&!this[Gt]&&this.emit("drain"),e}end(t,e,i){return typeof t=="function"&&(i=t,t=void 0),typeof e=="function"&&(i=e,e="utf8"),t!==void 0&&this.write(t,e),i&&this.once("end",i),this[Gt]=true,this.writable=false,(this[J]||!this[Qe])&&this[Vt](),this}[Fe](){this[$]||(!this[me]&&!this[it].length&&(this[ut]=true),this[Qe]=false,this[J]=true,this.emit("resume"),this[H].length?this[Ws]():this[Gt]?this[Vt]():this.emit("drain"));}resume(){return this[Fe]()}pause(){this[J]=false,this[Qe]=true,this[ut]=false;}get destroyed(){return this[$]}get flowing(){return this[J]}get paused(){return this[Qe]}[yi](t){this[tt]?this[Z]+=1:this[Z]+=t.length,this[H].push(t);}[$s](){return this[tt]?this[Z]-=1:this[Z]-=this[H][0].length,this[H].shift()}[Ws](t=false){do;while(this[er](this[$s]())&&this[H].length);!t&&!this[H].length&&!this[Gt]&&this.emit("drain");}[er](t){return this.emit("data",t),this[J]}pipe(t,e){if(this[$])return t;this[ut]=false;let i=this[se];return e=e||{},t===Xi.stdout||t===Xi.stderr?e.end=false:e.end=e.end!==false,e.proxyErrors=!!e.proxyErrors,i?e.end&&t.end():(this[it].push(e.proxyErrors?new ca(this,t,e):new sn(this,t,e)),this[Nt]?ts(()=>this[Fe]()):this[Fe]()),t}unpipe(t){let e=this[it].find(i=>i.dest===t);e&&(this[it].length===1?(this[J]&&this[me]===0&&(this[J]=false),this[it]=[]):this[it].splice(this[it].indexOf(e),1),e.unpipe());}addListener(t,e){return this.on(t,e)}on(t,e){let i=super.on(t,e);if(t==="data")this[ut]=false,this[me]++,!this[it].length&&!this[J]&&this[Fe]();else if(t==="readable"&&this[Z]!==0)super.emit("readable");else if(aa(t)&&this[se])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Ye]){let n=e;this[Nt]?ts(()=>n.call(this,this[Ye])):n.call(this,this[Ye]);}return i}removeListener(t,e){return this.off(t,e)}off(t,e){let i=super.off(t,e);return t==="data"&&(this[me]=this.listeners("data").length,this[me]===0&&!this[ut]&&!this[it].length&&(this[J]=false)),i}removeAllListeners(t){let e=super.removeAllListeners(t);return (t==="data"||t===void 0)&&(this[me]=0,!this[ut]&&!this[it].length&&(this[J]=false)),e}get emittedEnd(){return this[se]}[Vt](){!this[Ns]&&!this[se]&&!this[$]&&this[H].length===0&&this[Gt]&&(this[Ns]=true,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[js]&&this.emit("close"),this[Ns]=false);}emit(t,...e){let i=e[0];if(t!=="error"&&t!=="close"&&t!==$&&this[$])return false;if(t==="data")return !this[tt]&&!i?false:this[Nt]?(ts(()=>this[bi](i)),true):this[bi](i);if(t==="end")return this[sr]();if(t==="close"){if(this[js]=true,!this[se]&&!this[$])return false;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Ye]=i,super.emit(wi,i);let o=!this[Xe]||this.listeners("error").length?super.emit("error",i):false;return this[Vt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Vt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let n=super.emit(t,...e);return this[Vt](),n}[bi](t){for(let i of this[it])i.dest.write(t)===false&&this.pause();let e=this[ut]?false:super.emit("data",t);return this[Vt](),e}[sr](){return this[se]?false:(this[se]=true,this.readable=false,this[Nt]?(ts(()=>this[vi]()),true):this[vi]())}[vi](){if(this[Pe]){let e=this[Pe].end();if(e){for(let i of this[it])i.dest.write(e);this[ut]||super.emit("data",e);}}for(let e of this[it])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[tt]||(t.dataLength=0);let e=this.promise();return this.on("data",i=>{t.push(i),this[tt]||(t.dataLength+=i.length);}),await e,t}async concat(){if(this[tt])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[Ct]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on($,()=>e(new Error("stream destroyed"))),this.on("error",i=>e(i)),this.on("end",()=>t());})}[Symbol.asyncIterator](){this[ut]=false;let t=false,e=async()=>(this.pause(),t=true,{value:void 0,done:true});return {next:()=>{if(t)return e();let i=this.read();if(i!==null)return Promise.resolve({done:false,value:i});if(this[Gt])return e();let n,o,a=f=>{this.off("data",l),this.off("end",h),this.off($,d),e(),o(f);},l=f=>{this.off("error",a),this.off("end",h),this.off($,d),this.pause(),n({value:f,done:!!this[Gt]});},h=()=>{this.off("error",a),this.off("data",l),this.off($,d),e(),n({done:true,value:void 0});},d=()=>a(new Error("stream destroyed"));return new Promise((f,u)=>{o=u,n=f,this.once($,d),this.once("error",a),this.once("end",h),this.once("data",l);})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ut]=false;let t=false,e=()=>(this.pause(),this.off(wi,e),this.off($,e),this.off("end",e),t=true,{done:true,value:void 0}),i=()=>{if(t)return e();let n=this.read();return n===null?e():{done:false,value:n}};return this.once("end",e),this.once(wi,e),this.once($,e),{next:i,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[$])return t?this.emit("error",t):this.emit($),this;this[$]=true,this[ut]=true,this[H].length=0,this[Z]=0;let e=this;return typeof e.close=="function"&&!this[js]&&e.close(),t?this.emit("error",t):this.emit($),this}static get isStream(){return ia}},pa=realpathSync.native,rs={lstatSync:lstatSync,readdir:readdir$1,readdirSync:readdirSync,readlinkSync:readlinkSync,realpathSync:pa,promises:{lstat:lstat,readdir:readdir,readlink:readlink,realpath:realpath}},rn=s=>!s||s===rs||s===Yo?rs:{...rs,...s,promises:{...rs.promises,...s.promises||{}}},nn=/^\\\\\?\\([a-z]:)\\?$/i,fa=s=>s.replace(/\//g,"\\").replace(nn,"$1\\"),ga=/[\\\/]/,xt=0,on=1,an=2,jt=4,ln=6,hn=8,ye=10,cn=12,vt=15,es=~vt,xi=16,ir=32,ns=64,Ot=128,Us=256,Hs=512,rr=ns|Ot|Hs,ma=1023,ki=s=>s.isFile()?hn:s.isDirectory()?jt:s.isSymbolicLink()?ye:s.isCharacterDevice()?an:s.isBlockDevice()?ln:s.isSocket()?cn:s.isFIFO()?on:xt,nr=new si({max:2**12}),os=s=>{let t=nr.get(s);if(t)return t;let e=s.normalize("NFKD");return nr.set(s,e),e},or=new si({max:2**12}),Bs=s=>{let t=or.get(s);if(t)return t;let e=os(s.toLowerCase());return or.set(s,e),e},ar=class extends si{constructor(){super({max:256});}},ya=class extends si{constructor(s=16*1024){super({maxSize:s,sizeCalculation:t=>t.length+1});}},un=Symbol("PathScurry setAsCwd"),ot,ds,ps,fs,gs,ms,ys,ws,bs,vs,Ss,xs,ks,Es,Cs,Os,Rs,Ms,Ls,ce,Ee,$t,Ht,Zt,Kt,L,Ce,Yt,zt,R,Ti,Zs,as,_i,Pi,ls,Ks,Fi,Ii,Ys,dn,pn,fn,Di,Ue,Be,gn,Oe,Fr,ht=(Fr=class{constructor(s,t=xt,e,i,n,o,a){y(this,R);c(this,"name");c(this,"root");c(this,"roots");c(this,"parent");c(this,"nocase");c(this,"isCWD",false);y(this,ot);y(this,ds);y(this,ps);y(this,fs);y(this,gs);y(this,ms);y(this,ys);y(this,ws);y(this,bs);y(this,vs);y(this,Ss);y(this,xs);y(this,ks);y(this,Es);y(this,Cs);y(this,Os);y(this,Rs);y(this,Ms);y(this,Ls);y(this,ce);y(this,Ee);y(this,$t);y(this,Ht);y(this,Zt);y(this,Kt);y(this,L);y(this,Ce);y(this,Yt);y(this,zt);y(this,Ue,[]);y(this,Be,false);y(this,Oe);this.name=s,p(this,ce,n?Bs(s):os(s)),p(this,L,t&ma),this.nocase=n,this.roots=i,this.root=e||this,p(this,Ce,o),p(this,$t,a.fullpath),p(this,Zt,a.relative),p(this,Kt,a.relativePosix),this.parent=a.parent,this.parent?p(this,ot,r(this.parent,ot)):p(this,ot,rn(a.fs));}get dev(){return r(this,ds)}get mode(){return r(this,ps)}get nlink(){return r(this,fs)}get uid(){return r(this,gs)}get gid(){return r(this,ms)}get rdev(){return r(this,ys)}get blksize(){return r(this,ws)}get ino(){return r(this,bs)}get size(){return r(this,vs)}get blocks(){return r(this,Ss)}get atimeMs(){return r(this,xs)}get mtimeMs(){return r(this,ks)}get ctimeMs(){return r(this,Es)}get birthtimeMs(){return r(this,Cs)}get atime(){return r(this,Os)}get mtime(){return r(this,Rs)}get ctime(){return r(this,Ms)}get birthtime(){return r(this,Ls)}get parentPath(){return (this.parent||this).fullpath()}get path(){return this.parentPath}depth(){return r(this,Ee)!==void 0?r(this,Ee):this.parent?p(this,Ee,this.parent.depth()+1):p(this,Ee,0)}childrenCache(){return r(this,Ce)}resolve(s){var i;if(!s)return this;let t=this.getRootString(s),e=s.substring(t.length).split(this.splitSep);return t?m(i=this.getRoot(t),R,Ti).call(i,e):m(this,R,Ti).call(this,e)}children(){let s=r(this,Ce).get(this);if(s)return s;let t=Object.assign([],{provisional:0});return r(this,Ce).set(this,t),p(this,L,r(this,L)&~xi),t}child(s,t){if(s===""||s===".")return this;if(s==="..")return this.parent||this;let e=this.children(),i=this.nocase?Bs(s):os(s);for(let l of e)if(r(l,ce)===i)return l;let n=this.parent?this.sep:"",o=r(this,$t)?r(this,$t)+n+s:void 0,a=this.newChild(s,xt,{...t,parent:this,fullpath:o});return this.canReaddir()||p(a,L,r(a,L)|Ot),e.push(a),a}relative(){if(this.isCWD)return "";if(r(this,Zt)!==void 0)return r(this,Zt);let s=this.name,t=this.parent;if(!t)return p(this,Zt,this.name);let e=t.relative();return e+(!e||!t.parent?"":this.sep)+s}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return "";if(r(this,Kt)!==void 0)return r(this,Kt);let s=this.name,t=this.parent;if(!t)return p(this,Kt,this.fullpathPosix());let e=t.relativePosix();return e+(!e||!t.parent?"":"/")+s}fullpath(){if(r(this,$t)!==void 0)return r(this,$t);let s=this.name,t=this.parent;if(!t)return p(this,$t,this.name);let e=t.fullpath()+(t.parent?this.sep:"")+s;return p(this,$t,e)}fullpathPosix(){if(r(this,Ht)!==void 0)return r(this,Ht);if(this.sep==="/")return p(this,Ht,this.fullpath());if(!this.parent){let i=this.fullpath().replace(/\\/g,"/");return /^[a-z]:\//i.test(i)?p(this,Ht,`//?/${i}`):p(this,Ht,i)}let s=this.parent,t=s.fullpathPosix(),e=t+(!t||!s.parent?"":"/")+this.name;return p(this,Ht,e)}isUnknown(){return (r(this,L)&vt)===xt}isType(s){return this[`is${s}`]()}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 (r(this,L)&vt)===hn}isDirectory(){return (r(this,L)&vt)===jt}isCharacterDevice(){return (r(this,L)&vt)===an}isBlockDevice(){return (r(this,L)&vt)===ln}isFIFO(){return (r(this,L)&vt)===on}isSocket(){return (r(this,L)&vt)===cn}isSymbolicLink(){return (r(this,L)&ye)===ye}lstatCached(){return r(this,L)&ir?this:void 0}readlinkCached(){return r(this,Yt)}realpathCached(){return r(this,zt)}readdirCached(){let s=this.children();return s.slice(0,s.provisional)}canReadlink(){if(r(this,Yt))return true;if(!this.parent)return false;let s=r(this,L)&vt;return !(s!==xt&&s!==ye||r(this,L)&Us||r(this,L)&Ot)}calledReaddir(){return !!(r(this,L)&xi)}isENOENT(){return !!(r(this,L)&Ot)}isNamed(s){return this.nocase?r(this,ce)===Bs(s):r(this,ce)===os(s)}async readlink(){let s=r(this,Yt);if(s)return s;if(this.canReadlink()&&this.parent)try{let t=await r(this,ot).promises.readlink(this.fullpath()),e=(await this.parent.realpath())?.resolve(t);if(e)return p(this,Yt,e)}catch(t){m(this,R,Ii).call(this,t.code);return}}readlinkSync(){let s=r(this,Yt);if(s)return s;if(this.canReadlink()&&this.parent)try{let t=r(this,ot).readlinkSync(this.fullpath()),e=this.parent.realpathSync()?.resolve(t);if(e)return p(this,Yt,e)}catch(t){m(this,R,Ii).call(this,t.code);return}}async lstat(){if((r(this,L)&Ot)===0)try{return m(this,R,Di).call(this,await r(this,ot).promises.lstat(this.fullpath())),this}catch(s){m(this,R,Fi).call(this,s.code);}}lstatSync(){if((r(this,L)&Ot)===0)try{return m(this,R,Di).call(this,r(this,ot).lstatSync(this.fullpath())),this}catch(s){m(this,R,Fi).call(this,s.code);}}readdirCB(s,t=false){if(!this.canReaddir()){t?s(null,[]):queueMicrotask(()=>s(null,[]));return}let e=this.children();if(this.calledReaddir()){let n=e.slice(0,e.provisional);t?s(null,n):queueMicrotask(()=>s(null,n));return}if(r(this,Ue).push(s),r(this,Be))return;p(this,Be,true);let i=this.fullpath();r(this,ot).readdir(i,{withFileTypes:true},(n,o)=>{if(n)m(this,R,Ks).call(this,n.code),e.provisional=0;else {for(let a of o)m(this,R,Ys).call(this,a,e);m(this,R,Zs).call(this,e);}m(this,R,gn).call(this,e.slice(0,e.provisional));});}async readdir(){if(!this.canReaddir())return [];let s=this.children();if(this.calledReaddir())return s.slice(0,s.provisional);let t=this.fullpath();if(r(this,Oe))await r(this,Oe);else {let e=()=>{};p(this,Oe,new Promise(i=>e=i));try{for(let i of await r(this,ot).promises.readdir(t,{withFileTypes:!0}))m(this,R,Ys).call(this,i,s);m(this,R,Zs).call(this,s);}catch(i){m(this,R,Ks).call(this,i.code),s.provisional=0;}p(this,Oe,void 0),e();}return s.slice(0,s.provisional)}readdirSync(){if(!this.canReaddir())return [];let s=this.children();if(this.calledReaddir())return s.slice(0,s.provisional);let t=this.fullpath();try{for(let e of r(this,ot).readdirSync(t,{withFileTypes:!0}))m(this,R,Ys).call(this,e,s);m(this,R,Zs).call(this,s);}catch(e){m(this,R,Ks).call(this,e.code),s.provisional=0;}return s.slice(0,s.provisional)}canReaddir(){if(r(this,L)&rr)return false;let s=vt&r(this,L);return s===xt||s===jt||s===ye}shouldWalk(s,t){return (r(this,L)&jt)===jt&&!(r(this,L)&rr)&&!s.has(this)&&(!t||t(this))}async realpath(){if(r(this,zt))return r(this,zt);if(!((Hs|Us|Ot)&r(this,L)))try{let s=await r(this,ot).promises.realpath(this.fullpath());return p(this,zt,this.resolve(s))}catch{m(this,R,Pi).call(this);}}realpathSync(){if(r(this,zt))return r(this,zt);if(!((Hs|Us|Ot)&r(this,L)))try{let s=r(this,ot).realpathSync(this.fullpath());return p(this,zt,this.resolve(s))}catch{m(this,R,Pi).call(this);}}[un](s){if(s===this)return;s.isCWD=false,this.isCWD=true;let t=new Set([]),e=[],i=this;for(;i&&i.parent;)t.add(i),p(i,Zt,e.join(this.sep)),p(i,Kt,e.join("/")),i=i.parent,e.push("..");for(i=s;i&&i.parent&&!t.has(i);)p(i,Zt,void 0),p(i,Kt,void 0),i=i.parent;}},ot=new WeakMap,ds=new WeakMap,ps=new WeakMap,fs=new WeakMap,gs=new WeakMap,ms=new WeakMap,ys=new WeakMap,ws=new WeakMap,bs=new WeakMap,vs=new WeakMap,Ss=new WeakMap,xs=new WeakMap,ks=new WeakMap,Es=new WeakMap,Cs=new WeakMap,Os=new WeakMap,Rs=new WeakMap,Ms=new WeakMap,Ls=new WeakMap,ce=new WeakMap,Ee=new WeakMap,$t=new WeakMap,Ht=new WeakMap,Zt=new WeakMap,Kt=new WeakMap,L=new WeakMap,Ce=new WeakMap,Yt=new WeakMap,zt=new WeakMap,R=new WeakSet,Ti=function(s){let t=this;for(let e of s)t=t.child(e);return t},Zs=function(s){var t;p(this,L,r(this,L)|xi);for(let e=s.provisional;e<s.length;e++){let i=s[e];i&&m(t=i,R,as).call(t);}},as=function(){r(this,L)&Ot||(p(this,L,(r(this,L)|Ot)&es),m(this,R,_i).call(this));},_i=function(){var t;let s=this.children();s.provisional=0;for(let e of s)m(t=e,R,as).call(t);},Pi=function(){p(this,L,r(this,L)|Hs),m(this,R,ls).call(this);},ls=function(){if(r(this,L)&ns)return;let s=r(this,L);(s&vt)===jt&&(s&=es),p(this,L,s|ns),m(this,R,_i).call(this);},Ks=function(s=""){s==="ENOTDIR"||s==="EPERM"?m(this,R,ls).call(this):s==="ENOENT"?m(this,R,as).call(this):this.children().provisional=0;},Fi=function(s=""){var t;s==="ENOTDIR"?m(t=this.parent,R,ls).call(t):s==="ENOENT"&&m(this,R,as).call(this);},Ii=function(s=""){var e;let t=r(this,L);t|=Us,s==="ENOENT"&&(t|=Ot),(s==="EINVAL"||s==="UNKNOWN")&&(t&=es),p(this,L,t),s==="ENOTDIR"&&this.parent&&m(e=this.parent,R,ls).call(e);},Ys=function(s,t){return m(this,R,pn).call(this,s,t)||m(this,R,dn).call(this,s,t)},dn=function(s,t){let e=ki(s),i=this.newChild(s.name,e,{parent:this}),n=r(i,L)&vt;return n!==jt&&n!==ye&&n!==xt&&p(i,L,r(i,L)|ns),t.unshift(i),t.provisional++,i},pn=function(s,t){for(let e=t.provisional;e<t.length;e++){let i=t[e];if((this.nocase?Bs(s.name):os(s.name))===r(i,ce))return m(this,R,fn).call(this,s,i,e,t)}},fn=function(s,t,e,i){let n=t.name;return p(t,L,r(t,L)&es|ki(s)),n!==s.name&&(t.name=s.name),e!==i.provisional&&(e===i.length-1?i.pop():i.splice(e,1),i.unshift(t)),i.provisional++,t},Di=function(s){let{atime:t,atimeMs:e,birthtime:i,birthtimeMs:n,blksize:o,blocks:a,ctime:l,ctimeMs:h,dev:d,gid:f,ino:u,mode:g,mtime:w,mtimeMs:v,nlink:S,rdev:k,size:b,uid:O}=s;p(this,Os,t),p(this,xs,e),p(this,Ls,i),p(this,Cs,n),p(this,ws,o),p(this,Ss,a),p(this,Ms,l),p(this,Es,h),p(this,ds,d),p(this,ms,f),p(this,bs,u),p(this,ps,g),p(this,Rs,w),p(this,ks,v),p(this,fs,S),p(this,ys,k),p(this,vs,b),p(this,gs,O);let M=ki(s);p(this,L,r(this,L)&es|M|ir),M!==xt&&M!==jt&&M!==ye&&p(this,L,r(this,L)|ns);},Ue=new WeakMap,Be=new WeakMap,gn=function(s){p(this,Be,false);let t=r(this,Ue).slice();r(this,Ue).length=0,t.forEach(e=>e(null,s));},Oe=new WeakMap,Fr),mn=class yn extends ht{constructor(e,i=xt,n,o,a,l,h){super(e,i,n,o,a,l,h);c(this,"sep","\\");c(this,"splitSep",ga);}newChild(e,i=xt,n={}){return new yn(e,i,this.root,this.roots,this.nocase,this.childrenCache(),n)}getRootString(e){return win32.parse(e).root}getRoot(e){if(e=fa(e.toUpperCase()),e===this.root.name)return this.root;for(let[i,n]of Object.entries(this.roots))if(this.sameRoot(e,i))return this.roots[e]=n;return this.roots[e]=new zi(e,this).root}sameRoot(e,i=this.root.name){return e=e.toUpperCase().replace(/\//g,"\\").replace(nn,"$1\\"),e===i}},wn=class bn extends ht{constructor(e,i=xt,n,o,a,l,h){super(e,i,n,o,a,l,h);c(this,"splitSep","/");c(this,"sep","/");}getRootString(e){return e.startsWith("/")?"/":""}getRoot(e){return this.root}newChild(e,i=xt,n={}){return new bn(e,i,this.root,this.roots,this.nocase,this.childrenCache(),n)}},Ge,Ve,As,Ts,Ir,vn=(Ir=class{constructor(s=process.cwd(),t,e,{nocase:i,childrenCacheSize:n=16*1024,fs:o=rs}={}){c(this,"root");c(this,"rootPath");c(this,"roots");c(this,"cwd");y(this,Ge);y(this,Ve);y(this,As);c(this,"nocase");y(this,Ts);p(this,Ts,rn(o)),(s instanceof URL||s.startsWith("file://"))&&(s=fileURLToPath(s));let a=t.resolve(s);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),p(this,Ge,new ar),p(this,Ve,new ar),p(this,As,new ya(n));let l=a.substring(this.rootPath.length).split(e);if(l.length===1&&!l[0]&&l.pop(),i===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=i,this.root=this.newRoot(r(this,Ts)),this.roots[this.rootPath]=this.root;let h=this.root,d=l.length-1,f=t.sep,u=this.rootPath,g=false;for(let w of l){let v=d--;h=h.child(w,{relative:new Array(v).fill("..").join(f),relativePosix:new Array(v).fill("..").join("/"),fullpath:u+=(g?"":f)+w}),g=true;}this.cwd=h;}depth(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.depth()}childrenCache(){return r(this,As)}resolve(...s){let t="";for(let n=s.length-1;n>=0;n--){let o=s[n];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=r(this,Ge).get(t);if(e!==void 0)return e;let i=this.cwd.resolve(t).fullpath();return r(this,Ge).set(t,i),i}resolvePosix(...s){let t="";for(let n=s.length-1;n>=0;n--){let o=s[n];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=r(this,Ve).get(t);if(e!==void 0)return e;let i=this.cwd.resolve(t).fullpathPosix();return r(this,Ve).set(t,i),i}relative(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.relative()}relativePosix(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.relativePosix()}basename(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.name}dirname(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),(s.parent||s).fullpath()}async readdir(s=this.cwd,t={withFileTypes:true}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e}=t;if(s.canReaddir()){let i=await s.readdir();return e?i:i.map(n=>n.name)}else return []}readdirSync(s=this.cwd,t={withFileTypes:true}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true}=t;return s.canReaddir()?e?s.readdirSync():s.readdirSync().map(i=>i.name):[]}async lstat(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.lstat()}lstatSync(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.lstatSync()}async readlink(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=await s.readlink();return t?e:e?.fullpath()}readlinkSync(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=s.readlinkSync();return t?e:e?.fullpath()}async realpath(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=await s.realpath();return t?e:e?.fullpath()}realpathSync(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=s.realpathSync();return t?e:e?.fullpath()}async walk(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=[];(!n||n(s))&&a.push(e?s:s.fullpath());let l=new Set,h=(f,u)=>{l.add(f),f.readdirCB((g,w)=>{if(g)return u(g);let v=w.length;if(!v)return u();let S=()=>{--v===0&&u();};for(let k of w)(!n||n(k))&&a.push(e?k:k.fullpath()),i&&k.isSymbolicLink()?k.realpath().then(b=>b?.isUnknown()?b.lstat():b).then(b=>b?.shouldWalk(l,o)?h(b,S):S()):k.shouldWalk(l,o)?h(k,S):S();},true);},d=s;return new Promise((f,u)=>{h(d,g=>{if(g)return u(g);f(a);});})}walkSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=[];(!n||n(s))&&a.push(e?s:s.fullpath());let l=new Set([s]);for(let h of l){let d=h.readdirSync();for(let f of d){(!n||n(f))&&a.push(e?f:f.fullpath());let u=f;if(f.isSymbolicLink()){if(!(i&&(u=f.realpathSync())))continue;u.isUnknown()&&u.lstatSync();}u.shouldWalk(l,o)&&l.add(u);}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(s=this.cwd,t={}){return typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd),this.stream(s,t)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t;(!n||n(s))&&(yield e?s:s.fullpath());let a=new Set([s]);for(let l of a){let h=l.readdirSync();for(let d of h){(!n||n(d))&&(yield e?d:d.fullpath());let f=d;if(d.isSymbolicLink()){if(!(i&&(f=d.realpathSync())))continue;f.isUnknown()&&f.lstatSync();}f.shouldWalk(a,o)&&a.add(f);}}}stream(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=new ti({objectMode:true});(!n||n(s))&&a.write(e?s:s.fullpath());let l=new Set,h=[s],d=0,f=()=>{let u=false;for(;!u;){let g=h.shift();if(!g){d===0&&a.end();return}d++,l.add(g);let w=(S,k,b=false)=>{if(S)return a.emit("error",S);if(i&&!b){let O=[];for(let M of k)M.isSymbolicLink()&&O.push(M.realpath().then(E=>E?.isUnknown()?E.lstat():E));if(O.length){Promise.all(O).then(()=>w(null,k,true));return}}for(let O of k)O&&(!n||n(O))&&(a.write(e?O:O.fullpath())||(u=true));d--;for(let O of k){let M=O.realpathCached()||O;M.shouldWalk(l,o)&&h.push(M);}u&&!a.flowing?a.once("drain",f):v||f();},v=true;g.readdirCB(w,true),v=false;}};return f(),a}streamSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=new ti({objectMode:true}),l=new Set;(!n||n(s))&&a.write(e?s:s.fullpath());let h=[s],d=0,f=()=>{let u=false;for(;!u;){let g=h.shift();if(!g){d===0&&a.end();return}d++,l.add(g);let w=g.readdirSync();for(let v of w)(!n||n(v))&&(a.write(e?v:v.fullpath())||(u=true));d--;for(let v of w){let S=v;if(v.isSymbolicLink()){if(!(i&&(S=v.realpathSync())))continue;S.isUnknown()&&S.lstatSync();}S.shouldWalk(l,o)&&h.push(S);}}u&&!a.flowing&&a.once("drain",f);};return f(),a}chdir(s=this.cwd){let t=this.cwd;this.cwd=typeof s=="string"?this.cwd.resolve(s):s,this.cwd[un](t);}},Ge=new WeakMap,Ve=new WeakMap,As=new WeakMap,Ts=new WeakMap,Ir),zi=class extends vn{constructor(t=process.cwd(),e={}){let{nocase:i=true}=e;super(t,win32,"\\",{...e,nocase:i});c(this,"sep","\\");this.nocase=i;for(let n=this.cwd;n;n=n.parent)n.nocase=this.nocase;}parseRootPath(t){return win32.parse(t).root.toUpperCase()}newRoot(t){return new mn(this.rootPath,jt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")||t.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(t)}},Ui=class extends vn{constructor(t=process.cwd(),e={}){let{nocase:i=false}=e;super(t,posix,"/",{...e,nocase:i});c(this,"sep","/");this.nocase=i;}parseRootPath(t){return "/"}newRoot(t){return new wn(this.rootPath,jt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")}},Sn=class extends Ui{constructor(s=process.cwd(),t={}){let{nocase:e=true}=t;super(s,{...t,nocase:e});}};process.platform==="win32"?mn:wn;var wa=process.platform==="win32"?zi:process.platform==="darwin"?Sn:Ui,ba=s=>s.length>=1,va=s=>s.length>=1,Sa=Symbol.for("nodejs.util.inspect.custom"),V,ct,q,Re,It,_s,ue,de,pe,qe,Je,xn=(Je=class{constructor(t,e,i,n){y(this,V);y(this,ct);y(this,q);c(this,"length");y(this,Re);y(this,It);y(this,_s);y(this,ue);y(this,de);y(this,pe);y(this,qe,true);if(!ba(t))throw new TypeError("empty pattern list");if(!va(e))throw new TypeError("empty glob list");if(e.length!==t.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=t.length,i<0||i>=this.length)throw new TypeError("index out of range");if(p(this,V,t),p(this,ct,e),p(this,q,i),p(this,Re,n),r(this,q)===0){if(this.isUNC()){let[o,a,l,h,...d]=r(this,V),[f,u,g,w,...v]=r(this,ct);d[0]===""&&(d.shift(),v.shift());let S=[o,a,l,h,""].join("/"),k=[f,u,g,w,""].join("/");p(this,V,[S,...d]),p(this,ct,[k,...v]),this.length=r(this,V).length;}else if(this.isDrive()||this.isAbsolute()){let[o,...a]=r(this,V),[l,...h]=r(this,ct);a[0]===""&&(a.shift(),h.shift());let d=o+"/",f=l+"/";p(this,V,[d,...a]),p(this,ct,[f,...h]),this.length=r(this,V).length;}}}[Sa](){return "Pattern <"+r(this,ct).slice(r(this,q)).join("/")+">"}pattern(){return r(this,V)[r(this,q)]}isString(){return typeof r(this,V)[r(this,q)]=="string"}isGlobstar(){return r(this,V)[r(this,q)]===at}isRegExp(){return r(this,V)[r(this,q)]instanceof RegExp}globString(){return p(this,_s,r(this,_s)||(r(this,q)===0?this.isAbsolute()?r(this,ct)[0]+r(this,ct).slice(1).join("/"):r(this,ct).join("/"):r(this,ct).slice(r(this,q)).join("/")))}hasMore(){return this.length>r(this,q)+1}rest(){return r(this,It)!==void 0?r(this,It):this.hasMore()?(p(this,It,new Je(r(this,V),r(this,ct),r(this,q)+1,r(this,Re))),p(r(this,It),pe,r(this,pe)),p(r(this,It),de,r(this,de)),p(r(this,It),ue,r(this,ue)),r(this,It)):p(this,It,null)}isUNC(){let t=r(this,V);return r(this,de)!==void 0?r(this,de):p(this,de,r(this,Re)==="win32"&&r(this,q)===0&&t[0]===""&&t[1]===""&&typeof t[2]=="string"&&!!t[2]&&typeof t[3]=="string"&&!!t[3])}isDrive(){let t=r(this,V);return r(this,ue)!==void 0?r(this,ue):p(this,ue,r(this,Re)==="win32"&&r(this,q)===0&&this.length>1&&typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]))}isAbsolute(){let t=r(this,V);return r(this,pe)!==void 0?r(this,pe):p(this,pe,t[0]===""&&t.length>1||this.isDrive()||this.isUNC())}root(){let t=r(this,V)[0];return typeof t=="string"&&this.isAbsolute()&&r(this,q)===0?t:""}checkFollowGlobstar(){return !(r(this,q)===0||!this.isGlobstar()||!r(this,qe))}markFollowGlobstar(){return r(this,q)===0||!this.isGlobstar()||!r(this,qe)?false:(p(this,qe,false),true)}},V=new WeakMap,ct=new WeakMap,q=new WeakMap,Re=new WeakMap,It=new WeakMap,_s=new WeakMap,ue=new WeakMap,de=new WeakMap,pe=new WeakMap,qe=new WeakMap,Je),xa=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",lr=class{constructor(s,{nobrace:t,nocase:e,noext:i,noglobstar:n,platform:o=xa}){c(this,"relative");c(this,"relativeChildren");c(this,"absolute");c(this,"absoluteChildren");c(this,"platform");c(this,"mmopts");this.relative=[],this.absolute=[],this.relativeChildren=[],this.absoluteChildren=[],this.platform=o,this.mmopts={dot:true,nobrace:t,nocase:e,noext:i,noglobstar:n,optimizationLevel:2,platform:o,nocomment:true,nonegate:true};for(let a of s)this.add(a);}add(s){let t=new ge(s,this.mmopts);for(let e=0;e<t.set.length;e++){let i=t.set[e],n=t.globParts[e];if(!i||!n)throw new Error("invalid pattern object");for(;i[0]==="."&&n[0]===".";)i.shift(),n.shift();let o=new xn(i,n,0,this.platform),a=new ge(o.globString(),this.mmopts),l=n[n.length-1]==="**",h=o.isAbsolute();h?this.absolute.push(a):this.relative.push(a),l&&(h?this.absoluteChildren.push(a):this.relativeChildren.push(a));}}ignored(s){let t=s.fullpath(),e=`${t}/`,i=s.relative()||".",n=`${i}/`;for(let o of this.relative)if(o.match(i)||o.match(n))return true;for(let o of this.absolute)if(o.match(t)||o.match(e))return true;return false}childrenIgnored(s){let t=s.fullpath()+"/",e=(s.relative()||".")+"/";for(let i of this.relativeChildren)if(i.match(e))return true;for(let i of this.absoluteChildren)if(i.match(t))return true;return false}},ka=class kn{constructor(t=new Map){c(this,"store");this.store=t;}copy(){return new kn(new Map(this.store))}hasWalked(t,e){return this.store.get(t.fullpath())?.has(e.globString())}storeWalked(t,e){let i=t.fullpath(),n=this.store.get(i);n?n.add(e.globString()):this.store.set(i,new Set([e.globString()]));}},Ea=class{constructor(){c(this,"store",new Map);}add(s,t,e){let i=(t?2:0)|(e?1:0),n=this.store.get(s);this.store.set(s,n===void 0?i:i&n);}entries(){return [...this.store.entries()].map(([s,t])=>[s,!!(t&2),!!(t&1)])}},Ca=class{constructor(){c(this,"store",new Map);}add(s,t){if(!s.canReaddir())return;let e=this.store.get(s);e?e.find(i=>i.globString()===t.globString())||e.push(t):this.store.set(s,[t]);}get(s){let t=this.store.get(s);if(!t)throw new Error("attempting to walk unknown path");return t}entries(){return this.keys().map(s=>[s,this.store.get(s)])}keys(){return [...this.store.keys()].filter(s=>s.canReaddir())}},hr=class En{constructor(t,e){c(this,"hasWalkedCache");c(this,"matches",new Ea);c(this,"subwalks",new Ca);c(this,"patterns");c(this,"follow");c(this,"dot");c(this,"opts");this.opts=t,this.follow=!!t.follow,this.dot=!!t.dot,this.hasWalkedCache=e?e.copy():new ka;}processPatterns(t,e){this.patterns=e;let i=e.map(n=>[t,n]);for(let[n,o]of i){this.hasWalkedCache.storeWalked(n,o);let a=o.root(),l=o.isAbsolute()&&this.opts.absolute!==false;if(a){n=n.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let u=o.rest();if(u)o=u;else {this.matches.add(n,true,false);continue}}if(n.isENOENT())continue;let h,d,f=false;for(;typeof(h=o.pattern())=="string"&&(d=o.rest());)n=n.resolve(h),o=d,f=true;if(h=o.pattern(),d=o.rest(),f){if(this.hasWalkedCache.hasWalked(n,o))continue;this.hasWalkedCache.storeWalked(n,o);}if(typeof h=="string"){let u=h===".."||h===""||h===".";this.matches.add(n.resolve(h),l,u);continue}else if(h===at){(!n.isSymbolicLink()||this.follow||o.checkFollowGlobstar())&&this.subwalks.add(n,o);let u=d?.pattern(),g=d?.rest();if(!d||(u===""||u===".")&&!g)this.matches.add(n,l,u===""||u===".");else if(u===".."){let w=n.parent||n;g?this.hasWalkedCache.hasWalked(w,g)||this.subwalks.add(w,g):this.matches.add(w,l,true);}}else h instanceof RegExp&&this.subwalks.add(n,o);}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new En(this.opts,this.hasWalkedCache)}filterEntries(t,e){let i=this.subwalks.get(t),n=this.child();for(let o of e)for(let a of i){let l=a.isAbsolute(),h=a.pattern(),d=a.rest();h===at?n.testGlobstar(o,a,d,l):h instanceof RegExp?n.testRegExp(o,h,d,l):n.testString(o,h,d,l);}return n}testGlobstar(t,e,i,n){if((this.dot||!t.name.startsWith("."))&&(e.hasMore()||this.matches.add(t,n,false),t.canReaddir()&&(this.follow||!t.isSymbolicLink()?this.subwalks.add(t,e):t.isSymbolicLink()&&(i&&e.checkFollowGlobstar()?this.subwalks.add(t,i):e.markFollowGlobstar()&&this.subwalks.add(t,e)))),i){let o=i.pattern();if(typeof o=="string"&&o!==".."&&o!==""&&o!==".")this.testString(t,o,i.rest(),n);else if(o===".."){let a=t.parent||t;this.subwalks.add(a,i);}else o instanceof RegExp&&this.testRegExp(t,o,i.rest(),n);}}testRegExp(t,e,i,n){e.test(t.name)&&(i?this.subwalks.add(t,i):this.matches.add(t,n,false));}testString(t,e,i,n){t.isNamed(e)&&(i?this.subwalks.add(t,i):this.matches.add(t,n,false));}},Oa=(s,t)=>typeof s=="string"?new lr([s],t):Array.isArray(s)?new lr(s,t):s,He,Qt,Me,kt,we,Ni,Dr,Cn=(Dr=class{constructor(s,t,e){y(this,kt);c(this,"path");c(this,"patterns");c(this,"opts");c(this,"seen",new Set);c(this,"paused",false);c(this,"aborted",false);y(this,He,[]);y(this,Qt);y(this,Me);c(this,"signal");c(this,"maxDepth");c(this,"includeChildMatches");if(this.patterns=s,this.path=t,this.opts=e,p(this,Me,!e.posix&&e.platform==="win32"?"\\":"/"),this.includeChildMatches=e.includeChildMatches!==false,(e.ignore||!this.includeChildMatches)&&(p(this,Qt,Oa(e.ignore??[],e)),!this.includeChildMatches&&typeof r(this,Qt).add!="function")){let i="cannot ignore child matches, ignore lacks add() method.";throw new Error(i)}this.maxDepth=e.maxDepth||1/0,e.signal&&(this.signal=e.signal,this.signal.addEventListener("abort",()=>{r(this,He).length=0;}));}pause(){this.paused=true;}resume(){if(this.signal?.aborted)return;this.paused=false;let s;for(;!this.paused&&(s=r(this,He).shift());)s();}onResume(s){this.signal?.aborted||(this.paused?r(this,He).push(s):s());}async matchCheck(s,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=s.realpathCached()||await s.realpath(),!e)return;s=e;}let i=s.isUnknown()||this.opts.stat?await s.lstat():s;if(this.opts.follow&&this.opts.nodir&&i?.isSymbolicLink()){let n=await i.realpath();n&&(n.isUnknown()||this.opts.stat)&&await n.lstat();}return this.matchCheckTest(i,t)}matchCheckTest(s,t){return s&&(this.maxDepth===1/0||s.depth()<=this.maxDepth)&&(!t||s.canReaddir())&&(!this.opts.nodir||!s.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!s.isSymbolicLink()||!s.realpathCached()?.isDirectory())&&!m(this,kt,we).call(this,s)?s:void 0}matchCheckSync(s,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=s.realpathCached()||s.realpathSync(),!e)return;s=e;}let i=s.isUnknown()||this.opts.stat?s.lstatSync():s;if(this.opts.follow&&this.opts.nodir&&i?.isSymbolicLink()){let n=i.realpathSync();n&&(n?.isUnknown()||this.opts.stat)&&n.lstatSync();}return this.matchCheckTest(i,t)}matchFinish(s,t){if(m(this,kt,we).call(this,s))return;if(!this.includeChildMatches&&r(this,Qt)?.add){let n=`${s.relativePosix()}/**`;r(this,Qt).add(n);}let e=this.opts.absolute===void 0?t:this.opts.absolute;this.seen.add(s);let i=this.opts.mark&&s.isDirectory()?r(this,Me):"";if(this.opts.withFileTypes)this.matchEmit(s);else if(e){let n=this.opts.posix?s.fullpathPosix():s.fullpath();this.matchEmit(n+i);}else {let n=this.opts.posix?s.relativePosix():s.relative(),o=this.opts.dotRelative&&!n.startsWith(".."+r(this,Me))?"."+r(this,Me):"";this.matchEmit(n?o+n+i:"."+i);}}async match(s,t,e){let i=await this.matchCheck(s,e);i&&this.matchFinish(i,t);}matchSync(s,t,e){let i=this.matchCheckSync(s,e);i&&this.matchFinish(i,t);}walkCB(s,t,e){this.signal?.aborted&&e(),this.walkCB2(s,t,new hr(this.opts),e);}walkCB2(s,t,e,i){if(m(this,kt,Ni).call(this,s))return i();if(this.signal?.aborted&&i(),this.paused){this.onResume(()=>this.walkCB2(s,t,e,i));return}e.processPatterns(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())m(this,kt,we).call(this,a)||(n++,this.match(a,l,h).then(()=>o()));for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;n++;let l=a.readdirCached();a.calledReaddir()?this.walkCB3(a,l,e,o):a.readdirCB((h,d)=>this.walkCB3(a,d,e,o),true);}o();}walkCB3(s,t,e,i){e=e.filterEntries(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())m(this,kt,we).call(this,a)||(n++,this.match(a,l,h).then(()=>o()));for(let[a,l]of e.subwalks.entries())n++,this.walkCB2(a,l,e.child(),o);o();}walkCBSync(s,t,e){this.signal?.aborted&&e(),this.walkCB2Sync(s,t,new hr(this.opts),e);}walkCB2Sync(s,t,e,i){if(m(this,kt,Ni).call(this,s))return i();if(this.signal?.aborted&&i(),this.paused){this.onResume(()=>this.walkCB2Sync(s,t,e,i));return}e.processPatterns(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())m(this,kt,we).call(this,a)||this.matchSync(a,l,h);for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;n++;let l=a.readdirSync();this.walkCB3Sync(a,l,e,o);}o();}walkCB3Sync(s,t,e,i){e=e.filterEntries(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())m(this,kt,we).call(this,a)||this.matchSync(a,l,h);for(let[a,l]of e.subwalks.entries())n++,this.walkCB2Sync(a,l,e.child(),o);o();}},He=new WeakMap,Qt=new WeakMap,Me=new WeakMap,kt=new WeakSet,we=function(s){return this.seen.has(s)||!!r(this,Qt)?.ignored?.(s)},Ni=function(s){return !!r(this,Qt)?.childrenIgnored?.(s)},Dr),cr=class extends Cn{constructor(t,e,i){super(t,e,i);c(this,"matches",new Set);}matchEmit(t){this.matches.add(t);}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((t,e)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?e(this.signal.reason):t(this.matches);});}),this.matches}walkSync(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>{if(this.signal?.aborted)throw this.signal.reason}),this.matches}},ur=class extends Cn{constructor(t,e,i){super(t,e,i);c(this,"results");this.results=new ti({signal:this.signal,objectMode:true}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume());}matchEmit(t){this.results.write(t),this.results.flowing||this.pause();}stream(){let t=this.path;return t.isUnknown()?t.lstat().then(()=>{this.walkCB(t,this.patterns,()=>this.results.end());}):this.walkCB(t,this.patterns,()=>this.results.end()),this.results}streamSync(){return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>this.results.end()),this.results}},Ra=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",Ae=class{constructor(s,t){c(this,"absolute");c(this,"cwd");c(this,"root");c(this,"dot");c(this,"dotRelative");c(this,"follow");c(this,"ignore");c(this,"magicalBraces");c(this,"mark");c(this,"matchBase");c(this,"maxDepth");c(this,"nobrace");c(this,"nocase");c(this,"nodir");c(this,"noext");c(this,"noglobstar");c(this,"pattern");c(this,"platform");c(this,"realpath");c(this,"scurry");c(this,"stat");c(this,"signal");c(this,"windowsPathsNoEscape");c(this,"withFileTypes");c(this,"includeChildMatches");c(this,"opts");c(this,"patterns");if(!t)throw new TypeError("glob options required");if(this.withFileTypes=!!t.withFileTypes,this.signal=t.signal,this.follow=!!t.follow,this.dot=!!t.dot,this.dotRelative=!!t.dotRelative,this.nodir=!!t.nodir,this.mark=!!t.mark,t.cwd?(t.cwd instanceof URL||t.cwd.startsWith("file://"))&&(t.cwd=fileURLToPath(t.cwd)):this.cwd="",this.cwd=t.cwd||"",this.root=t.root,this.magicalBraces=!!t.magicalBraces,this.nobrace=!!t.nobrace,this.noext=!!t.noext,this.realpath=!!t.realpath,this.absolute=t.absolute,this.includeChildMatches=t.includeChildMatches!==false,this.noglobstar=!!t.noglobstar,this.matchBase=!!t.matchBase,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:1/0,this.stat=!!t.stat,this.ignore=t.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");if(typeof s=="string"&&(s=[s]),this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===false,this.windowsPathsNoEscape&&(s=s.map(l=>l.replace(/\\/g,"/"))),this.matchBase){if(t.noglobstar)throw new TypeError("base matching requires globstar");s=s.map(l=>l.includes("/")?l:`./**/${l}`);}if(this.pattern=s,this.platform=t.platform||Ra,this.opts={...t,platform:this.platform},t.scurry){if(this.scurry=t.scurry,t.nocase!==void 0&&t.nocase!==t.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else {let l=t.platform==="win32"?zi:t.platform==="darwin"?Sn:t.platform?Ui:wa;this.scurry=new l(this.cwd,{nocase:t.nocase,fs:t.fs});}this.nocase=this.scurry.nocase;let e=this.platform==="darwin"||this.platform==="win32",i={braceExpandMax:1e4,...t,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:e,nocomment:true,noext:this.noext,nonegate:true,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape,debug:!!this.opts.debug},n=this.pattern.map(l=>new ge(l,i)),[o,a]=n.reduce((l,h)=>(l[0].push(...h.set),l[1].push(...h.globParts),l),[[],[]]);this.patterns=o.map((l,h)=>{let d=a[h];if(!d)throw new Error("invalid pattern object");return new xn(l,d,0,this.platform)});}async walk(){return [...await new cr(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 cr(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 ur(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 ur(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()}},Ma=(s,t={})=>{Array.isArray(s)||(s=[s]);for(let e of s)if(new ge(e,t).hasMagic())return true;return false};function ii(s,t={}){return new Ae(s,t).streamSync()}function On(s,t={}){return new Ae(s,t).stream()}function Rn(s,t={}){return new Ae(s,t).walkSync()}async function dr(s,t={}){return new Ae(s,t).walk()}function ri(s,t={}){return new Ae(s,t).iterateSync()}function Mn(s,t={}){return new Ae(s,t).iterate()}var La=ii,Aa=Object.assign(On,{sync:ii}),Ta=ri,_a=Object.assign(Mn,{sync:ri}),Pa=Object.assign(Rn,{stream:ii,iterate:ri}),ei=Object.assign(dr,{glob:dr,globSync:Rn,sync:Pa,globStream:On,stream:Aa,globStreamSync:ii,streamSync:La,globIterate:Mn,iterate:_a,globIterateSync:ri,iterateSync:Ta,Glob:Ae,hasMagic:Ma,escape:qr,unescape:Ie});ei.glob=ei;var Dt;(I=>{I.Level=Ia.enum(["DEBUG","INFO","WARN","ERROR"]).meta({ref:"LogLevel",description:"Log level"});let t={DEBUG:0,INFO:1,WARN:2,ERROR:3},e="INFO";function i(C){return t[C]>=t[e]}function n(){return e}I.getLevel=n;let o=new Map;I.Default=E({service:"default"});let l="";function h(){return l}I.file=h;let d,f,u=false,g=()=>{},w=false,v=false;async function S(C){if(u)return;if(C.print){u=true;return}C.level&&(e=C.level);let _=C.logDir||ni.join(process.env.EASBOT_LOG_PATH??process.cwd(),"logs");C.logFile?l=ni.join(_,C.logFile??"ollama-sdk.log"):l=ni.join(_,"ollama-sdk.log");try{await Ln.mkdir(_,{recursive:!0}),d=await Ln.open(l,"a"),f=createWriteStream("",{fd:d.fd,autoClose:!1}),g=F=>{if(!(w||v||!f||f.destroyed))try{if(!f.writable)return;f.write(F,P=>{if(P&&!w){let T=P;if(T.code==="EPIPE"||T.code==="EIO"){v=!0,f?.destroy();return}w=!0,setTimeout(()=>{w=!1;},1e3);}});}catch(P){let T=P;if(T.code==="EPIPE"||T.code==="EIO"){v=!0,f?.destroy();return}w||(w=!0,setTimeout(()=>{w=!1;},1e3));}},u=!0;}catch{g=F=>{try{process.stderr.write(F);}catch{}},u=true;}}I.init=S;async function k(){u&&(f&&!f.destroyed&&(await new Promise((C,_)=>{f.end(F=>{F?_(F):C();});}).catch(()=>{}),f=void 0),d&&(await d.close().catch(()=>{}),d=void 0),g=C=>{try{process.stderr.write(C);}catch{}},u=false);}I.close=k;function O(C,_=0){let F=C.message;return C.cause instanceof Error&&_<10?F+" Caused by: "+O(C.cause,_+1):F}let M=Date.now();function E(C){C=C||{};let _=C.service;if(_&&typeof _=="string"){let T=o.get(_);if(T)return T}function F(T,D){let st=Object.entries({...C,...D}).filter(([Bi,te])=>te!=null).map(([Bi,te])=>{let ci=`${Bi}=`;return te instanceof Error?ci+O(te):typeof te=="object"?ci+JSON.stringify(te):ci+te}).join(" "),Bt=new Date,Te=Bt.getTime()-M;return M=Bt.getTime(),[formatLogTime(Bt),"+"+Te+"ms",st,T].filter(Boolean).join(" ")+`
5
- `}let P={debug(T,D){i("DEBUG")&&g("DEBUG "+F(T,D));},info(T,D){i("INFO")&&g("INFO "+F(T,D));},error(T,D){i("ERROR")&&g("ERROR "+F(T,D));},warn(T,D){i("WARN")&&g("WARN "+F(T,D));},tag(T,D){return C&&(C[T]=D),P},clone(){return I.create({...C})},time(T,D){let st=Date.now();P.info(T,{status:"started",...D});function Bt(){P.info(T,{status:"completed",duration:Date.now()-st,...D});}return {stop:Bt,[Symbol.dispose](){Bt();}}}};return _&&typeof _=="string"&&o.set(_,P),P}I.create=E;})(Dt||(Dt={}));function An(s,t,e){let i;return t?i="tool-calls":s?i="stop":i="other",{unified:i,raw:e}}var Et=Dt.create({service:"ollama-sdk",module:"native-language-model"});function oi(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ai(s){if(!s||s.trim().length===0)return false;try{return JSON.parse(s),!0}catch{return false}}function Tn(s){return typeof s=="string"?s:JSON.stringify(s)}function _n(s){return !s.tools||s.tools.length===0?{}:{tools:s.tools.map(t=>{if(!t.name)throw new Ze(t.name||"unknown","name");let e=t.inputSchema||t.parameters;if(!e)throw new Ze(t.name,"inputSchema");return {type:"function",function:{name:t.name,description:t.description,parameters:e}}})}}function Pn(s){let t=[];for(let e of s)try{switch(e.role){case "system":t.push({role:"system",content:e.content});break;case "user":{let i=e.content.filter(n=>n.type==="text").map(n=>n.text).join(`
6
- `);i&&t.push({role:"user",content:i});break}case "assistant":{let i="",n=[];for(let o of e.content)if(o.type==="text")i+=o.text;else if(o.type==="tool-call"){let a=o;n.push({id:a.toolCallId,type:"function",function:{name:a.toolName,arguments:JSON.stringify(a.input)}});}t.push({role:"assistant",content:i||null,tool_calls:n.length>0?n:void 0});break}case "tool":for(let i of e.content){let n=i.output,o;switch(n.type){case "text":case "error-text":o=n.value;break;case "content":case "json":case "error-json":o=JSON.stringify(n.value);break;default:o=String(n.value);break}t.push({role:"tool",tool_call_id:i.toolCallId,content:o});}break}}catch(i){Et.warn("Failed to convert message",{messageRole:e.role,error:i instanceof Error?i.message:String(i)});}return t}var li=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"client");this.modelId=t,this.client=new Is(e.baseURL);}async generate(t){return this.doGenerate(t)}async stream(t){return this.doStream(t)}async doStream(t){let e=oi();Et.debug("Stream request started",{traceId:e,modelId:this.modelId,hasTools:!!t.tools&&t.tools.length>0,toolCount:t.tools?.length||0,messageCount:t.prompt.length});let i=Pn(t.prompt),n=_n({tools:t.tools}),o=JSON.stringify({model:this.modelId,messages:i,options:_e,...n}),a=null,l=null,h=w=>{a&&a.enqueue(w),l&&l.enqueue(w);},d=async()=>{try{let w=!0,v=!1,S=!1,k="",b="",O=!1,M=[],E=[],I=()=>{if(E.length>0){for(let _ of E)h(_);E.length=0;}},C=null;for await(let _ of this.client.streamChat({model:this.modelId,messages:i,options:_e,...n})){if(C&&C.chunkCount++,w){w=!1;let F={type:"response-metadata",id:oi(),modelId:this.modelId,timestamp:new Date(_.created_at)};h(F),C&&C.eventCount++;}if(_.message?.tool_calls){S&&(E.push({type:"reasoning-end",id:"reasoning-0"}),S=!1),v&&(E.push({type:"text-end",id:"txt-0"}),v=!1);for(let F of _.message.tool_calls){if(!F.id||!F.function?.name){let Te=F.id?"function.name":"id";Et.error("Invalid tool call: missing field",{traceId:e,missingField:Te,toolCall:void 0}),E.push({type:"error",error:`Invalid tool call: missing ${Te}`});continue}let P=F.id,T=F.function.name,D=Tn(F.function.arguments),st=M.find(Te=>Te.id===P);st?(st.function.arguments+=D,Et.debug("Tool call arguments accumulated",{traceId:e,toolCallId:P,toolName:T,deltaLength:D.length,totalLength:st.function.arguments.length,isComplete:ai(st.function.arguments)}),D&&E.push({type:"tool-input-delta",id:P,delta:D})):(st={id:P,type:"function",function:{name:T,arguments:D},hasFinished:!1},M.push(st),C&&C.toolCallCount++,Et.debug("Tool call received",{traceId:e,toolCallId:P,toolName:T,argumentsLength:D.length,isComplete:ai(D)}),E.push({type:"tool-input-start",id:P,toolName:T}),D&&E.push({type:"tool-input-delta",id:P,delta:D}));let Bt=ai(st.function.arguments);!st.hasFinished&&Bt&&(Et.debug("Tool call arguments complete",{traceId:e,toolCallId:P,toolName:T,isComplete:Bt,argumentsLength:st.function.arguments.length}),E.push({type:"tool-input-end",id:P}),E.push({type:"tool-call",toolCallId:P,toolName:T,input:st.function.arguments}),st.hasFinished=!0);}I(),C&&(C.eventCount+=E.length);}if(_.message?.content){let F=_.message.content;for(b+=F;b.length>0;)if(O){let P=b.indexOf("</think>");if(P===-1){b.length>0&&E.push({type:"reasoning-delta",id:"reasoning-0",delta:b}),b="";break}else {if(P>0){let T=b.substring(0,P);E.push({type:"reasoning-delta",id:"reasoning-0",delta:T});}E.push({type:"reasoning-end",id:"reasoning-0"}),S=!1,O=!1,b=b.substring(P+8);}}else {let P=b.indexOf("<think>");if(P===-1){b.length>0&&(v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:b}),k+=b),b="";break}else {if(P>0){let T=b.substring(0,P);v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:T}),k+=T,E.push({type:"text-end",id:"txt-0"}),v=!1;}O=!0,b=b.substring(P+7),S||(S=!0,E.push({type:"reasoning-start",id:"reasoning-0"}));}}}if(I(),C&&(C.eventCount+=E.length),_.done){let F=M.filter(D=>!D.hasFinished);for(let D of F)E.push({type:"tool-input-end",id:D.id}),E.push({type:"tool-call",toolCallId:D.id,toolName:D.function.name,input:D.function.arguments});b.length>0&&(O?(E.push({type:"reasoning-delta",id:"reasoning-0",delta:b}),E.push({type:"reasoning-end",id:"reasoning-0"})):(v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:b}),k+=b)),v&&E.push({type:"text-end",id:"txt-0"});let T=M.length>0?"tool-calls":"stop";if(E.push({type:"finish",finishReason:T,usage:{inputTokens:{total:_.prompt_eval_count||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:_.eval_count||0,text:void 0,reasoning:void 0}},providerMetadata:{ollama:{totalDuration:_.total_duration||0,loadDuration:_.load_duration||0,promptEvalDuration:_.prompt_eval_duration||0,evalDuration:_.eval_duration||0}}}),I(),C&&(C.eventCount+=E.length),C);M.length=0;}}}catch(w){Et.error("Stream processing error",{traceId:e,error:w instanceof Error?w.message:String(w),stack:void 0}),h({type:"error",error:w instanceof Error?w.message:String(w)}),h({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(),l&&l.close();}},f=new ReadableStream({start(w){a=w;}}),u=new ReadableStream({start(w){l=w;}});d();async function*g(w){let v=w.getReader();try{for(;;){let{done:S,value:k}=await v.read();if(S)break;yield k;}}finally{v.releaseLock();}}return {stream:f,fullStream:g(u),request:{body:o},response:{}}}async doGenerate(t){let e=oi();Et.debug("Generate request started",{traceId:e,modelId:this.modelId,hasTools:!!t.tools&&t.tools.length>0,toolCount:t.tools?.length||0,messageCount:t.prompt.length});let i=Pn(t.prompt),n=_n({tools:t.tools}),o=await this.client.chat({model:this.modelId,messages:i,options:_e,...n}),a=[];if(o.message?.content&&a.push({type:"text",text:o.message.content}),o.message?.tool_calls){Et.debug("Tool calls received in generate",{traceId:e,toolCallCount:o.message.tool_calls.length});for(let d of o.message.tool_calls){let f=d.id||oi(),u=d.function.name,g=Tn(d.function.arguments);Et.debug("Processing tool call in generate",{traceId:e,toolCallId:f,toolName:u,argumentsLength:g.length,isComplete:ai(g)}),a.push({type:"tool-call",toolCallId:f,toolName:u,input:g});}}let l=!!(o.message?.tool_calls&&o.message.tool_calls.length>0),h=An(o.done??false,l,"stop");return Et.debug("Generate request completed",{traceId:e,finishReason:h,contentParts:a.length,hasToolCalls:l,inputTokens:o.prompt_eval_count||0,outputTokens:o.eval_count||0}),{content:a,finishReason:h,usage:{inputTokens:{total:o.prompt_eval_count||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:o.eval_count||0,text:void 0,reasoning:void 0}},providerMetadata:{ollama:{totalDuration:o.total_duration||0,loadDuration:o.load_duration||0,promptEvalDuration:o.prompt_eval_duration||0,evalDuration:o.eval_duration||0}},request:{body:JSON.stringify({model:this.modelId,messages:i,options:_e,...n})},response:{}}}};var Xt=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"nativeModel");this.modelId=t,this.nativeModel=new li(t,{baseURL:e.baseURL||"http://localhost:11434"});}doGenerate(t){return this.nativeModel.doGenerate(t)}doStream(t){return this.nativeModel.doStream(t)}async generate(t){return this.nativeModel.generate(t)}async stream(t){return this.nativeModel.stream(t)}};var Ps=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"maxEmbeddingsPerCall");c(this,"supportsParallelCalls",true);c(this,"baseURL");this.modelId=t,this.baseURL=e.baseURL||"http://localhost:11434";}async doEmbed(t){let{values:e,abortSignal:i}=t,n=Dt.create({service:"ollama-embedding"});if(!e||e.length===0)return n.warn("Empty values array provided",{modelId:this.modelId}),{embeddings:[],usage:{tokens:0},warnings:[]};n.debug("Generating text embeddings",{modelId:this.modelId,valuesCount:e.length,baseURL:this.baseURL});try{let o=await Promise.all(e.map(l=>this.generateSingleEmbedding(l,i))),a=e.reduce((l,h)=>l+this.estimateTokens(h),0);return n.debug("Text embeddings generated successfully",{modelId:this.modelId,embeddingsCount:o.length,totalTokens:a}),{embeddings:o,usage:{tokens:a},warnings:[]}}catch(o){throw n.error("Text embedding generation failed",{modelId:this.modelId,error:o instanceof Error?o.message:String(o),stack:void 0}),o}}async generateSingleEmbedding(t,e){let i=`${this.baseURL}/api/embeddings`;try{let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:this.modelId,prompt:t}),signal:e});if(!n.ok){let a=await n.text();throw new Error(`Ollama embedding API error (${n.status}): ${a}`)}let o=await n.json();if(!o.embedding||!Array.isArray(o.embedding))throw new Error("Invalid response format from Ollama embedding API");return o.embedding}catch(n){throw n instanceof TypeError&&n.message.includes("fetch")?new Error(`Failed to connect to Ollama server at ${this.baseURL}: ${n.message}`):n}}estimateTokens(t){let e=t.match(/[a-zA-Z]/g)?.length||0,i=t.match(/[\u4e00-\u9fa5]/g)?.length||0,n=t.length-e-i;return Math.ceil(e/4)+i+Math.ceil(n*.5)}};var hi=class{constructor(t,e,i={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Dt.create({service:"ollama-sdk",module:"reranking-model"}));this.modelId=t,this.languageModel=new Xt(t,e),this.options={totalScore:i.totalScore??1,useEnhancedPrompt:i.useEnhancedPrompt??true,promptLanguage:i.promptLanguage??"en"},this.log.debug("OllamaRerankingModel created",{modelId:t,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(t){let{query:e,documents:i,topN:n}=t,o;Array.isArray(i)?o=i:i.type==="text"?o=i.values.map((h,d)=>({content:h,id:`doc_${d+1}`})):o=i.values;let a=n??o.length;if(o.length===0)return {ranking:[],warnings:[]};try{let h=this.buildRerankPrompt(e,o),f=(await this.languageModel.doGenerate({prompt:[{role:"user",content:[{type:"text",text:h}]}],maxOutputTokens:500,temperature:.1})).content.find(g=>g.type==="text")?.text||"",u=this.parseRerankResult(f,o,a);return {ranking:u.results.map(g=>({index:g.index,relevanceScore:g.score,document:g.document})),warnings:u.warnings.map(g=>({type:"other",message:g}))}}catch(h){return this.log.error("Reranking failed",{error:h.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: ${h.message}`}]}}}buildRerankPrompt(t,e){let i=e.map((n,o)=>{let a=n.id||`doc_${o+1}`,l=n.content.slice(0,300);return `${o+1}. [ID: ${a}] ${l}`}).join(`
1
+ import ni,{win32,posix}from'path';import Ln,{realpath,readlink,readdir,lstat}from'fs/promises';import*as Qo from'fs';import {realpathSync,createWriteStream,readlinkSync,readdirSync,readdir as readdir$1,lstatSync}from'fs';import Da from'zod';import {fileURLToPath}from'url';import {EventEmitter}from'events';import en from'stream';import {StringDecoder}from'string_decoder';import {formatLogTime}from'@easbot/utils';var In=Object.defineProperty;var Gi=s=>{throw TypeError(s)};var Dn=(s,t,e)=>t in s?In(s,t,{enumerable:true,configurable:true,writable:true,value:e}):s[t]=e;var c=(s,t,e)=>Dn(s,typeof t!="symbol"?t+"":t,e),ui=(s,t,e)=>t.has(s)||Gi("Cannot "+e);var r=(s,t,e)=>(ui(s,t,"read from private field"),e?e.call(s):t.get(s)),y=(s,t,e)=>t.has(s)?Gi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),p=(s,t,e,i)=>(ui(s,t,"write to private field"),t.set(s,e),e),g=(s,t,e)=>(ui(s,t,"access private method"),e);var Fs=(s,t,e,i)=>({set _(n){p(s,t,n);},get _(){return r(s,t,i)}});var Is=class{constructor(t="http://localhost:11434"){c(this,"baseURL",t);}async*streamChat(t){let e=await fetch(`${this.baseURL}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,stream:true})});if(!e.ok)throw new Error(`Ollama API error: ${e.status} ${e.statusText}`);if(!e.body)throw new Error("Response body is null");let i=e.body.getReader(),n=new TextDecoder,o="";try{for(;;){let{done:a,value:l}=await i.read();if(a){if(o.trim())try{yield JSON.parse(o);}catch{}break}o+=n.decode(l,{stream:!0});let h=o.split(`
2
+ `);o=h.pop()||"";for(let d of h){let f=d.trim();if(f)try{yield JSON.parse(f);}catch{}}}}finally{i.releaseLock();}}async chat(t){let e=await fetch(`${this.baseURL}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,stream:false})});if(!e.ok)throw new Error(`Ollama API error: ${e.status} ${e.statusText}`);return e.json()}};var _e={numCtx:262144,temperature:.7,topK:40,topP:.9,repeatPenalty:1.1,numPredict:32e3},Nn=["numCtx","repeatPenalty","numPredict"];var ee=class extends Error{constructor(e,i){super(e);c(this,"cause",i);this.name="OllamaError",Object.setPrototypeOf(this,new.target.prototype);}},di=class extends ee{constructor(e,i,n){super(e,n);c(this,"url",i);this.name="ConnectionError";}},pi=class extends ee{constructor(e,i){super(`Model not found: ${e}`,i);c(this,"modelId",e);this.name="ModelNotFoundError";}},fi=class extends ee{constructor(e,i,n,o){super(e,o);c(this,"field",i);c(this,"value",n);this.name="ValidationError";}},gi=class extends ee{constructor(e,i,n){super(e,n);c(this,"timeoutMs",i);this.name="TimeoutError";}},Ze=class extends ee{constructor(e,i,n){super(`Invalid tool definition for "${e}": missing ${i}`,n);c(this,"toolName",e);c(this,"missingField",i);this.name="InvalidToolDefinitionError";}};var Nr=(s,t,e)=>{let i=s instanceof RegExp?Vi(s,e):s,n=t instanceof RegExp?Vi(t,e):t,o=i!==null&&n!=null&&jn(i,n,e);return o&&{start:o[0],end:o[1],pre:e.slice(0,o[0]),body:e.slice(o[0]+i.length,o[1]),post:e.slice(o[1]+n.length)}},Vi=(s,t)=>{let e=t.match(s);return e?e[0]:null},jn=(s,t,e)=>{let i,n,o,a,l,h=e.indexOf(s),d=e.indexOf(t,h+1),f=h;if(h>=0&&d>0){if(s===t)return [h,d];for(i=[],o=e.length;f>=0&&!l;){if(f===h)i.push(f),h=e.indexOf(s,f+1);else if(i.length===1){let u=i.pop();u!==void 0&&(l=[u,d]);}else n=i.pop(),n!==void 0&&n<o&&(o=n,a=d),d=e.indexOf(t,f+1);f=h<d&&h>=0?h:d;}i.length&&a!==void 0&&(l=[o,a]);}return l},jr="\0SLASH"+Math.random()+"\0",Wr="\0OPEN"+Math.random()+"\0",ji="\0CLOSE"+Math.random()+"\0",$r="\0COMMA"+Math.random()+"\0",zr="\0PERIOD"+Math.random()+"\0",Wn=new RegExp(jr,"g"),$n=new RegExp(Wr,"g"),zn=new RegExp(ji,"g"),Un=new RegExp($r,"g"),Bn=new RegExp(zr,"g"),Gn=/\\\\/g,Vn=/\\{/g,qn=/\\}/g,Jn=/\\,/g,Hn=/\\./g,Zn=1e5;function mi(s){return isNaN(s)?s.charCodeAt(0):parseInt(s,10)}function Kn(s){return s.replace(Gn,jr).replace(Vn,Wr).replace(qn,ji).replace(Jn,$r).replace(Hn,zr)}function Yn(s){return s.replace(Wn,"\\").replace($n,"{").replace(zn,"}").replace(Un,",").replace(Bn,".")}function Ur(s){if(!s)return [""];let t=[],e=Nr("{","}",s);if(!e)return s.split(",");let{pre:i,body:n,post:o}=e,a=i.split(",");a[a.length-1]+="{"+n+"}";let l=Ur(o);return o.length&&(a[a.length-1]+=l.shift(),a.push.apply(a,l)),t.push.apply(t,a),t}function Qn(s,t={}){if(!s)return [];let{max:e=Zn}=t;return s.slice(0,2)==="{}"&&(s="\\{\\}"+s.slice(2)),ss(Kn(s),e,true).map(Yn)}function Xn(s){return "{"+s+"}"}function to(s){return /^-?0\d/.test(s)}function eo(s,t){return s<=t}function so(s,t){return s>=t}function ss(s,t,e){let i=[],n=Nr("{","}",s);if(!n)return [s];let o=n.pre,a=n.post.length?ss(n.post,t,false):[""];if(/\$$/.test(n.pre))for(let l=0;l<a.length&&l<t;l++){let h=o+"{"+n.body+"}"+a[l];i.push(h);}else {let l=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(n.body),h=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body),d=l||h,f=n.body.indexOf(",")>=0;if(!d&&!f)return n.post.match(/,(?!,).*\}/)?(s=n.pre+"{"+n.body+ji+n.post,ss(s,t,true)):[s];let u;if(d)u=n.body.split(/\.\./);else if(u=Ur(n.body),u.length===1&&u[0]!==void 0&&(u=ss(u[0],t,false).map(Xn),u.length===1))return a.map(w=>n.pre+u[0]+w);let m;if(d&&u[0]!==void 0&&u[1]!==void 0){let w=mi(u[0]),v=mi(u[1]),S=Math.max(u[0].length,u[1].length),k=u.length===3&&u[2]!==void 0?Math.abs(mi(u[2])):1,b=eo;v<w&&(k*=-1,b=so);let R=u.some(to);m=[];for(let M=w;b(M,v);M+=k){let E;if(h)E=String.fromCharCode(M),E==="\\"&&(E="");else if(E=String(M),R){let F=S-E.length;if(F>0){let I=new Array(F+1).join("0");M<0?E="-"+I+E.slice(1):E=I+E;}}m.push(E);}}else {m=[];for(let w=0;w<u.length;w++)m.push.apply(m,ss(u[w],t,false));}for(let w=0;w<m.length;w++)for(let v=0;v<a.length&&i.length<t;v++){let S=o+m[w]+a[v];(!e||d||S)&&i.push(S);}}return i}var Qs=s=>{if(typeof s!="string")throw new TypeError("invalid pattern");if(s.length>65536)throw new TypeError("pattern is too long")},io={"[: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]},Ke=s=>s.replace(/[[\]\\-]/g,"\\$&"),ro=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),qi=s=>s.join(""),no=(s,t)=>{let e=t;if(s.charAt(e)!=="[")throw new Error("not in a brace expression");let i=[],n=[],o=e+1,a=false,l=false,h=false,d=false,f=e,u="";t:for(;o<s.length;){let v=s.charAt(o);if((v==="!"||v==="^")&&o===e+1){d=true,o++;continue}if(v==="]"&&a&&!h){f=o+1;break}if(a=true,v==="\\"&&!h){h=true,o++;continue}if(v==="["&&!h){for(let[S,[k,b,R]]of Object.entries(io))if(s.startsWith(S,o)){if(u)return ["$.",false,s.length-e,true];o+=S.length,R?n.push(k):i.push(k),l=l||b;continue t}}if(h=false,u){v>u?i.push(Ke(u)+"-"+Ke(v)):v===u&&i.push(Ke(v)),u="",o++;continue}if(s.startsWith("-]",o+1)){i.push(Ke(v+"-")),o+=2;continue}if(s.startsWith("-",o+1)){u=v,o+=2;continue}i.push(Ke(v)),o++;}if(f<o)return ["",false,0,false];if(!i.length&&!n.length)return ["$.",false,s.length-e,true];if(n.length===0&&i.length===1&&/^\\?.$/.test(i[0])&&!d){let v=i[0].length===2?i[0].slice(-1):i[0];return [ro(v),false,f-e,false]}let m="["+(d?"^":"")+qi(i)+"]",w="["+(d?"":"^")+qi(n)+"]";return [i.length&&n.length?"("+m+"|"+w+")":i.length?m:w,l,f-e,true]},Ie=(s,{windowsPathsNoEscape:t=false,magicalBraces:e=true}={})=>e?t?s.replace(/\[([^\/\\])\]/g,"$1"):s.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?s.replace(/\[([^\/\\{}])\]/g,"$1"):s.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),oo=new Set(["!","?","+","*","@"]),Ji=s=>oo.has(s),ao="(?!(?:^|/)\\.\\.?(?:$|/))",Ds="(?!\\.)",lo=new Set(["[","."]),ho=new Set(["..","."]),co=new Set("().*{}+?[]^$\\!"),uo=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Wi="[^/]",Hi=Wi+"*?",Zi=Wi+"+?",G,Y,qt,W,U,ae,be,le,$t,ve,hs,Le,Gr,fe,tt,Gs,Ei,Vr,Br=(tt=class{constructor(t,e,i={}){y(this,Le);c(this,"type");y(this,G);y(this,Y);y(this,qt,false);y(this,W,[]);y(this,U);y(this,ae);y(this,be);y(this,le,false);y(this,$t);y(this,ve);y(this,hs,false);this.type=t,t&&p(this,Y,true),p(this,U,e),p(this,G,r(this,U)?r(r(this,U),G):this),p(this,$t,r(this,G)===this?i:r(r(this,G),$t)),p(this,be,r(this,G)===this?[]:r(r(this,G),be)),t==="!"&&!r(r(this,G),le)&&r(this,be).push(this),p(this,ae,r(this,U)?r(r(this,U),W).length:0);}get hasMagic(){if(r(this,Y)!==void 0)return r(this,Y);for(let t of r(this,W))if(typeof t!="string"&&(t.type||t.hasMagic))return p(this,Y,true);return r(this,Y)}toString(){return r(this,ve)!==void 0?r(this,ve):this.type?p(this,ve,this.type+"("+r(this,W).map(t=>String(t)).join("|")+")"):p(this,ve,r(this,W).map(t=>String(t)).join(""))}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof tt&&r(e,U)===this))throw new Error("invalid part: "+e);r(this,W).push(e);}}toJSON(){let t=this.type===null?r(this,W).slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...r(this,W).map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===r(this,G)||r(r(this,G),le)&&r(this,U)?.type==="!")&&t.push({}),t}isStart(){if(r(this,G)===this)return true;if(!r(this,U)?.isStart())return false;if(r(this,ae)===0)return true;let t=r(this,U);for(let e=0;e<r(this,ae);e++){let i=r(t,W)[e];if(!(i instanceof tt&&i.type==="!"))return false}return true}isEnd(){if(r(this,G)===this||r(this,U)?.type==="!")return true;if(!r(this,U)?.isEnd())return false;if(!this.type)return r(this,U)?.isEnd();let t=r(this,U)?r(r(this,U),W).length:0;return r(this,ae)===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this));}clone(t){let e=new tt(this.type,t);for(let i of r(this,W))e.copyIn(i);return e}static fromGlob(t,e={}){var n;let i=new tt(null,void 0,e);return g(n=tt,fe,Gs).call(n,t,i,0,e),i}toMMPattern(){if(this!==r(this,G))return r(this,G).toMMPattern();let t=this.toString(),[e,i,n,o]=this.toRegExpSource();if(!(n||r(this,Y)||r(this,$t).nocase&&!r(this,$t).nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return i;let a=(r(this,$t).nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${e}$`,a),{_src:e,_glob:t})}get options(){return r(this,$t)}toRegExpSource(t){let e=t??!!r(this,$t).dot;if(r(this,G)===this&&g(this,Le,Gr).call(this),!this.type){let h=this.isStart()&&this.isEnd()&&!r(this,W).some(m=>typeof m!="string"),d=r(this,W).map(m=>{var b;let[w,v,S,k]=typeof m=="string"?g(b=tt,fe,Vr).call(b,m,r(this,Y),h):m.toRegExpSource(t);return p(this,Y,r(this,Y)||S),p(this,qt,r(this,qt)||k),w}).join(""),f="";if(this.isStart()&&typeof r(this,W)[0]=="string"&&!(r(this,W).length===1&&ho.has(r(this,W)[0]))){let m=lo,w=e&&m.has(d.charAt(0))||d.startsWith("\\.")&&m.has(d.charAt(2))||d.startsWith("\\.\\.")&&m.has(d.charAt(4)),v=!e&&!t&&m.has(d.charAt(0));f=w?ao:v?Ds:"";}let u="";return this.isEnd()&&r(r(this,G),le)&&r(this,U)?.type==="!"&&(u="(?:$|\\/)"),[f+d+u,Ie(d),p(this,Y,!!r(this,Y)),r(this,qt)]}let i=this.type==="*"||this.type==="+",n=this.type==="!"?"(?:(?!(?:":"(?:",o=g(this,Le,Ei).call(this,e);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let h=this.toString();return p(this,W,[h]),this.type=null,p(this,Y,void 0),[h,Ie(this.toString()),false,false]}let a=!i||t||e||!Ds?"":g(this,Le,Ei).call(this,true);a===o&&(a=""),a&&(o=`(?:${o})(?:${a})*?`);let l="";if(this.type==="!"&&r(this,hs))l=(this.isStart()&&!e?Ds:"")+Zi;else {let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?Ds:"")+Hi+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&a?")":this.type==="*"&&a?")?":`)${this.type}`;l=n+o+h;}return [l,Ie(o),p(this,Y,!!r(this,Y)),r(this,qt)]}},G=new WeakMap,Y=new WeakMap,qt=new WeakMap,W=new WeakMap,U=new WeakMap,ae=new WeakMap,be=new WeakMap,le=new WeakMap,$t=new WeakMap,ve=new WeakMap,hs=new WeakMap,Le=new WeakSet,Gr=function(){if(this!==r(this,G))throw new Error("should only call on root");if(r(this,le))return this;this.toString(),p(this,le,true);let t;for(;t=r(this,be).pop();){if(t.type!=="!")continue;let e=t,i=r(e,U);for(;i;){for(let n=r(e,ae)+1;!i.type&&n<r(i,W).length;n++)for(let o of r(t,W)){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(r(i,W)[n]);}e=i,i=r(e,U);}}return this},fe=new WeakSet,Gs=function(t,e,i,n){var w,v;let o=false,a=false,l=-1,h=false;if(e.type===null){let S=i,k="";for(;S<t.length;){let b=t.charAt(S++);if(o||b==="\\"){o=!o,k+=b;continue}if(a){S===l+1?(b==="^"||b==="!")&&(h=true):b==="]"&&!(S===l+2&&h)&&(a=false),k+=b;continue}else if(b==="["){a=true,l=S,h=false,k+=b;continue}if(!n.noext&&Ji(b)&&t.charAt(S)==="("){e.push(k),k="";let R=new tt(b,e);S=g(w=tt,fe,Gs).call(w,t,R,S,n),e.push(R);continue}k+=b;}return e.push(k),S}let d=i+1,f=new tt(null,e),u=[],m="";for(;d<t.length;){let S=t.charAt(d++);if(o||S==="\\"){o=!o,m+=S;continue}if(a){d===l+1?(S==="^"||S==="!")&&(h=true):S==="]"&&!(d===l+2&&h)&&(a=false),m+=S;continue}else if(S==="["){a=true,l=d,h=false,m+=S;continue}if(Ji(S)&&t.charAt(d)==="("){f.push(m),m="";let k=new tt(S,f);f.push(k),d=g(v=tt,fe,Gs).call(v,t,k,d,n);continue}if(S==="|"){f.push(m),m="",u.push(f),f=new tt(null,e);continue}if(S===")")return m===""&&r(e,W).length===0&&p(e,hs,true),f.push(m),m="",e.push(...u,f),d;m+=S;}return e.type=null,p(e,Y,void 0),p(e,W,[t.substring(i-1)]),d},Ei=function(t){return r(this,W).map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[i,n,o,a]=e.toRegExpSource(t);return p(this,qt,r(this,qt)||a),i}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")},Vr=function(t,e,i=false){let n=false,o="",a=false,l=false;for(let h=0;h<t.length;h++){let d=t.charAt(h);if(n){n=false,o+=(co.has(d)?"\\":"")+d;continue}if(d==="*"){if(l)continue;l=true,o+=i&&/^[*]+$/.test(t)?Zi:Hi,e=true;continue}else l=false;if(d==="\\"){h===t.length-1?o+="\\\\":n=true;continue}if(d==="["){let[f,u,m,w]=no(t,h);if(m){o+=f,a=a||u,h+=m-1,e=e||w;continue}}if(d==="?"){o+=Wi,e=true;continue}o+=uo(d);}return [o,Ie(t),!!e,a]},y(tt,fe),tt),qr=(s,{windowsPathsNoEscape:t=false,magicalBraces:e=false}={})=>e?t?s.replace(/[?*()[\]{}]/g,"[$&]"):s.replace(/[?*()[\]\\{}]/g,"\\$&"):t?s.replace(/[?*()[\]]/g,"[$&]"):s.replace(/[?*()[\]\\]/g,"\\$&"),lt=(s,t,e={})=>(Qs(t),!e.nocomment&&t.charAt(0)==="#"?false:new ge(t,e).match(s)),po=/^\*+([^+@!?\*\[\(]*)$/,fo=s=>t=>!t.startsWith(".")&&t.endsWith(s),go=s=>t=>t.endsWith(s),mo=s=>(s=s.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(s)),yo=s=>(s=s.toLowerCase(),t=>t.toLowerCase().endsWith(s)),wo=/^\*+\.\*+$/,bo=s=>!s.startsWith(".")&&s.includes("."),vo=s=>s!=="."&&s!==".."&&s.includes("."),So=/^\.\*+$/,xo=s=>s!=="."&&s!==".."&&s.startsWith("."),ko=/^\*+$/,Eo=s=>s.length!==0&&!s.startsWith("."),Co=s=>s.length!==0&&s!=="."&&s!=="..",Oo=/^\?+([^+@!?\*\[\(]*)?$/,Ro=([s,t=""])=>{let e=Jr([s]);return t?(t=t.toLowerCase(),i=>e(i)&&i.toLowerCase().endsWith(t)):e},Mo=([s,t=""])=>{let e=Hr([s]);return t?(t=t.toLowerCase(),i=>e(i)&&i.toLowerCase().endsWith(t)):e},Lo=([s,t=""])=>{let e=Hr([s]);return t?i=>e(i)&&i.endsWith(t):e},Ao=([s,t=""])=>{let e=Jr([s]);return t?i=>e(i)&&i.endsWith(t):e},Jr=([s])=>{let t=s.length;return e=>e.length===t&&!e.startsWith(".")},Hr=([s])=>{let t=s.length;return e=>e.length===t&&e!=="."&&e!==".."},Zr=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Ki={win32:{sep:"\\"},posix:{sep:"/"}},To=Zr==="win32"?Ki.win32.sep:Ki.posix.sep;lt.sep=To;var at=Symbol("globstar **");lt.GLOBSTAR=at;var _o="[^/]",Po=_o+"*?",Fo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Io="(?:(?!(?:\\/|^)\\.).)*?",Do=(s,t={})=>e=>lt(e,s,t);lt.filter=Do;var bt=(s,t={})=>Object.assign({},s,t),No=s=>{if(!s||typeof s!="object"||!Object.keys(s).length)return lt;let t=lt;return Object.assign((e,i,n={})=>t(e,i,bt(s,n)),{Minimatch:class extends t.Minimatch{constructor(e,i={}){super(e,bt(s,i));}static defaults(e){return t.defaults(bt(s,e)).Minimatch}},AST:class extends t.AST{constructor(e,i,n={}){super(e,i,bt(s,n));}static fromGlob(e,i={}){return t.AST.fromGlob(e,bt(s,i))}},unescape:(e,i={})=>t.unescape(e,bt(s,i)),escape:(e,i={})=>t.escape(e,bt(s,i)),filter:(e,i={})=>t.filter(e,bt(s,i)),defaults:e=>t.defaults(bt(s,e)),makeRe:(e,i={})=>t.makeRe(e,bt(s,i)),braceExpand:(e,i={})=>t.braceExpand(e,bt(s,i)),match:(e,i,n={})=>t.match(e,i,bt(s,n)),sep:t.sep,GLOBSTAR:at})};lt.defaults=No;var Kr=(s,t={})=>(Qs(s),t.nobrace||!/\{(?:(?!\{).)*\}/.test(s)?[s]:Qn(s,{max:t.braceExpandMax}));lt.braceExpand=Kr;var jo=(s,t={})=>new ge(s,t).makeRe();lt.makeRe=jo;var Wo=(s,t,e={})=>{let i=new ge(t,e);return s=s.filter(n=>i.match(n)),i.options.nonull&&!s.length&&s.push(t),s};lt.match=Wo;var Yi=/[?*]|[+@!]\(.*?\)|\[|\]/,$o=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),ge=class{constructor(s,t={}){c(this,"options");c(this,"set");c(this,"pattern");c(this,"windowsPathsNoEscape");c(this,"nonegate");c(this,"negate");c(this,"comment");c(this,"empty");c(this,"preserveMultipleSlashes");c(this,"partial");c(this,"globSet");c(this,"globParts");c(this,"nocase");c(this,"isWindows");c(this,"platform");c(this,"windowsNoMagicRoot");c(this,"regexp");Qs(s),t=t||{},this.options=t,this.pattern=s,this.platform=t.platform||Zr,this.isWindows=this.platform==="win32";let e="allowWindowsEscape";this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t[e]===false,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=false,this.nonegate=!!t.nonegate,this.comment=false,this.empty=false,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot!==void 0?t.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make();}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return true;for(let s of this.set)for(let t of s)if(typeof t!="string")return true;return false}debug(...s){}make(){let s=this.pattern,t=this.options;if(!t.nocomment&&s.charAt(0)==="#"){this.comment=true;return}if(!s){this.empty=true;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...n)=>console.error(...n)),this.debug(this.pattern,this.globSet);let e=this.globSet.map(n=>this.slashSplit(n));this.globParts=this.preprocess(e),this.debug(this.pattern,this.globParts);let i=this.globParts.map((n,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=n[0]===""&&n[1]===""&&(n[2]==="?"||!Yi.test(n[2]))&&!Yi.test(n[3]),h=/^[a-z]:/i.test(n[0]);if(l)return [...n.slice(0,4),...n.slice(4).map(d=>this.parse(d))];if(h)return [n[0],...n.slice(1).map(d=>this.parse(d))]}return n.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(n=>n.indexOf(false)===-1),this.isWindows)for(let n=0;n<this.set.length;n++){let o=this.set[n];o[0]===""&&o[1]===""&&this.globParts[n][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?");}this.debug(this.pattern,this.set);}preprocess(s){if(this.options.noglobstar)for(let e=0;e<s.length;e++)for(let i=0;i<s[e].length;i++)s[e][i]==="**"&&(s[e][i]="*");let{optimizationLevel:t=1}=this.options;return t>=2?(s=this.firstPhasePreProcess(s),s=this.secondPhasePreProcess(s)):t>=1?s=this.levelOneOptimize(s):s=this.adjascentGlobstarOptimize(s),s}adjascentGlobstarOptimize(s){return s.map(t=>{let e=-1;for(;(e=t.indexOf("**",e+1))!==-1;){let i=e;for(;t[i+1]==="**";)i++;i!==e&&t.splice(e,i-e);}return t})}levelOneOptimize(s){return s.map(t=>(t=t.reduce((e,i)=>{let n=e[e.length-1];return i==="**"&&n==="**"?e:i===".."&&n&&n!==".."&&n!=="."&&n!=="**"?(e.pop(),e):(e.push(i),e)},[]),t.length===0?[""]:t))}levelTwoFileOptimize(s){Array.isArray(s)||(s=this.slashSplit(s));let t=false;do{if(t=false,!this.preserveMultipleSlashes){for(let i=1;i<s.length-1;i++){let n=s[i];i===1&&n===""&&s[0]===""||(n==="."||n==="")&&(t=true,s.splice(i,1),i--);}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(t=true,s.pop());}let e=0;for(;(e=s.indexOf("..",e+1))!==-1;){let i=s[e-1];i&&i!=="."&&i!==".."&&i!=="**"&&(t=true,s.splice(e-1,2),e-=2);}}while(t);return s.length===0?[""]:s}firstPhasePreProcess(s){let t=false;do{t=false;for(let e of s){let i=-1;for(;(i=e.indexOf("**",i+1))!==-1;){let o=i;for(;e[o+1]==="**";)o++;o>i&&e.splice(i+1,o-i);let a=e[i+1],l=e[i+2],h=e[i+3];if(a!==".."||!l||l==="."||l===".."||!h||h==="."||h==="..")continue;t=true,e.splice(i,1);let d=e.slice(0);d[i]="**",s.push(d),i--;}if(!this.preserveMultipleSlashes){for(let o=1;o<e.length-1;o++){let a=e[o];o===1&&a===""&&e[0]===""||(a==="."||a==="")&&(t=true,e.splice(o,1),o--);}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(t=true,e.pop());}let n=0;for(;(n=e.indexOf("..",n+1))!==-1;){let o=e[n-1];if(o&&o!=="."&&o!==".."&&o!=="**"){t=true;let a=n===1&&e[n+1]==="**"?["."]:[];e.splice(n-1,2,...a),e.length===0&&e.push(""),n-=2;}}}}while(t);return s}secondPhasePreProcess(s){for(let t=0;t<s.length-1;t++)for(let e=t+1;e<s.length;e++){let i=this.partsMatch(s[t],s[e],!this.preserveMultipleSlashes);if(i){s[t]=[],s[e]=i;break}}return s.filter(t=>t.length)}partsMatch(s,t,e=false){let i=0,n=0,o=[],a="";for(;i<s.length&&n<t.length;)if(s[i]===t[n])o.push(a==="b"?t[n]:s[i]),i++,n++;else if(e&&s[i]==="**"&&t[n]===s[i+1])o.push(s[i]),i++;else if(e&&t[n]==="**"&&s[i]===t[n+1])o.push(t[n]),n++;else if(s[i]==="*"&&t[n]&&(this.options.dot||!t[n].startsWith("."))&&t[n]!=="**"){if(a==="b")return false;a="a",o.push(s[i]),i++,n++;}else if(t[n]==="*"&&s[i]&&(this.options.dot||!s[i].startsWith("."))&&s[i]!=="**"){if(a==="a")return false;a="b",o.push(t[n]),i++,n++;}else return false;return s.length===t.length&&o}parseNegate(){if(this.nonegate)return;let s=this.pattern,t=false,e=0;for(let i=0;i<s.length&&s.charAt(i)==="!";i++)t=!t,e++;e&&(this.pattern=s.slice(e)),this.negate=t;}matchOne(s,t,e=false){let i=this.options;if(this.isWindows){let v=typeof s[0]=="string"&&/^[a-z]:$/i.test(s[0]),S=!v&&s[0]===""&&s[1]===""&&s[2]==="?"&&/^[a-z]:$/i.test(s[3]),k=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),b=!k&&t[0]===""&&t[1]===""&&t[2]==="?"&&typeof t[3]=="string"&&/^[a-z]:$/i.test(t[3]),R=S?3:v?0:void 0,M=b?3:k?0:void 0;if(typeof R=="number"&&typeof M=="number"){let[E,F]=[s[R],t[M]];E.toLowerCase()===F.toLowerCase()&&(t[M]=E,M>R?t=t.slice(M):R>M&&(s=s.slice(R)));}}let{optimizationLevel:n=1}=this.options;n>=2&&(s=this.levelTwoFileOptimize(s)),this.debug("matchOne",this,{file:s,pattern:t}),this.debug("matchOne",s.length,t.length);for(var o=0,a=0,l=s.length,h=t.length;o<l&&a<h;o++,a++){this.debug("matchOne loop");var d=t[a],f=s[o];if(this.debug(t,d,f),d===false)return false;if(d===at){this.debug("GLOBSTAR",[t,d,f]);var u=o,m=a+1;if(m===h){for(this.debug("** at the end");o<l;o++)if(s[o]==="."||s[o]===".."||!i.dot&&s[o].charAt(0)===".")return false;return true}for(;u<l;){var w=s[u];if(this.debug(`
3
+ globstar while`,s,u,t,m,w),this.matchOne(s.slice(u),t.slice(m),e))return this.debug("globstar found match!",u,l,w),true;if(w==="."||w===".."||!i.dot&&w.charAt(0)==="."){this.debug("dot detected!",s,u,t,m);break}this.debug("globstar swallow a segment, and continue"),u++;}return !!(e&&(this.debug(`
4
+ >>> no match, partial?`,s,u,t,m),u===l))}let v;if(typeof d=="string"?(v=f===d,this.debug("string match",d,f,v)):(v=d.test(f),this.debug("pattern match",d,f,v)),!v)return false}if(o===l&&a===h)return true;if(o===l)return e;if(a===h)return o===l-1&&s[o]==="";throw new Error("wtf?")}braceExpand(){return Kr(this.pattern,this.options)}parse(s){Qs(s);let t=this.options;if(s==="**")return at;if(s==="")return "";let e,i=null;(e=s.match(ko))?i=t.dot?Co:Eo:(e=s.match(po))?i=(t.nocase?t.dot?yo:mo:t.dot?go:fo)(e[1]):(e=s.match(Oo))?i=(t.nocase?t.dot?Mo:Ro:t.dot?Lo:Ao)(e):(e=s.match(wo))?i=t.dot?vo:bo:(e=s.match(So))&&(i=xo);let n=Br.fromGlob(s,this.options).toMMPattern();return i&&typeof n=="object"&&Reflect.defineProperty(n,"test",{value:i}),n}makeRe(){if(this.regexp||this.regexp===false)return this.regexp;let s=this.set;if(!s.length)return this.regexp=false,this.regexp;let t=this.options,e=t.noglobstar?Po:t.dot?Fo:Io,i=new Set(t.nocase?["i"]:[]),n=s.map(l=>{let h=l.map(f=>{if(f instanceof RegExp)for(let u of f.flags.split(""))i.add(u);return typeof f=="string"?$o(f):f===at?at:f._src});h.forEach((f,u)=>{let m=h[u+1],w=h[u-1];f!==at||w===at||(w===void 0?m!==void 0&&m!==at?h[u+1]="(?:\\/|"+e+"\\/)?"+m:h[u]=e:m===void 0?h[u-1]=w+"(?:\\/|\\/"+e+")?":m!==at&&(h[u-1]=w+"(?:\\/|\\/"+e+"\\/)"+m,h[u+1]=at));});let d=h.filter(f=>f!==at);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]=s.length>1?["(?:",")"]:["",""];n="^"+o+n+a+"$",this.partial&&(n="^(?:\\/|"+o+n.slice(1,-1)+a+")$"),this.negate&&(n="^(?!"+n+").+$");try{this.regexp=new RegExp(n,[...i].join(""));}catch{this.regexp=false;}return this.regexp}slashSplit(s){return this.preserveMultipleSlashes?s.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(s)?["",...s.split(/\/+/)]:s.split(/\/+/)}match(s,t=this.partial){if(this.debug("match",s,this.pattern),this.comment)return false;if(this.empty)return s==="";if(s==="/"&&t)return true;let e=this.options;this.isWindows&&(s=s.split("\\").join("/"));let i=this.slashSplit(s);this.debug(this.pattern,"split",i);let n=this.set;this.debug(this.pattern,"set",n);let o=i[i.length-1];if(!o)for(let a=i.length-2;!o&&a>=0;a--)o=i[a];for(let a=0;a<n.length;a++){let l=n[a],h=i;if(e.matchBase&&l.length===1&&(h=[o]),this.matchOne(h,l,t))return e.flipNegate?true:!this.negate}return e.flipNegate?false:this.negate}static defaults(s){return lt.defaults(s).Minimatch}};lt.AST=Br;lt.Minimatch=ge;lt.escape=qr;lt.unescape=Ie;var Uo=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Yr=new Set,Ci=typeof process=="object"&&process?process:{},Qr=(s,t,e,i)=>{typeof Ci.emitWarning=="function"?Ci.emitWarning(s,t,e,i):console.error(`[${e}] ${t}: ${s}`);},Xs=globalThis.AbortController,Qi=globalThis.AbortSignal;if(typeof Xs>"u"){Qi=class{constructor(){c(this,"onabort");c(this,"_onabort",[]);c(this,"reason");c(this,"aborted",false);}addEventListener(e,i){this._onabort.push(i);}},Xs=class{constructor(){c(this,"signal",new Qi);t();}abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=true;for(let i of this.signal._onabort)i(e);this.signal.onabort?.(e);}}};let s=Ci.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{s&&(s=false,Qr("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t));};}var Bo=s=>!Yr.has(s),ie=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),Xr=s=>ie(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Vs:null:null,Vs=class extends Array{constructor(s){super(s),this.fill(0);}},Bt,De,Go=(Bt=class{constructor(t,e){c(this,"heap");c(this,"length");if(!r(Bt,De))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0;}static create(t){let e=Xr(t);if(!e)return [];p(Bt,De,true);let i=new Bt(t,e);return p(Bt,De,false),i}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},De=new WeakMap,y(Bt,De,false),Bt),pr,fr,St,dt,Mt,Se,Lt,Ne,je,At,V,Tt,B,$,T,rt,pt,st,Q,_t,X,Pt,Ft,ft,gt,It,he,nt,We,x,Oi,xe,Jt,cs,mt,tn,ke,$e,us,re,ne,Ri,qs,Js,j,Mi,is,oe,Li,ze,si=(ze=class{constructor(t){y(this,x);y(this,St);y(this,dt);y(this,Mt);y(this,Se);y(this,Lt);y(this,Ne);y(this,je);y(this,At);c(this,"ttl");c(this,"ttlResolution");c(this,"ttlAutopurge");c(this,"updateAgeOnGet");c(this,"updateAgeOnHas");c(this,"allowStale");c(this,"noDisposeOnSet");c(this,"noUpdateTTL");c(this,"maxEntrySize");c(this,"sizeCalculation");c(this,"noDeleteOnFetchRejection");c(this,"noDeleteOnStaleGet");c(this,"allowStaleOnFetchAbort");c(this,"allowStaleOnFetchRejection");c(this,"ignoreFetchAbort");y(this,V);y(this,Tt);y(this,B);y(this,$);y(this,T);y(this,rt);y(this,pt);y(this,st);y(this,Q);y(this,_t);y(this,X);y(this,Pt);y(this,Ft);y(this,ft);y(this,gt);y(this,It);y(this,he);y(this,nt);y(this,We);y(this,xe,()=>{});y(this,Jt,()=>{});y(this,cs,()=>{});y(this,mt,()=>false);y(this,ke,t=>{});y(this,$e,(t,e,i)=>{});y(this,us,(t,e,i,n)=>{if(i||n)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});c(this,pr,"LRUCache");let{max:e=0,ttl:i,ttlResolution:n=1,ttlAutopurge:o,updateAgeOnGet:a,updateAgeOnHas:l,allowStale:h,dispose:d,onInsert:f,disposeAfter:u,noDisposeOnSet:m,noUpdateTTL:w,maxSize:v=0,maxEntrySize:S=0,sizeCalculation:k,fetchMethod:b,memoMethod:R,noDeleteOnFetchRejection:M,noDeleteOnStaleGet:E,allowStaleOnFetchRejection:F,allowStaleOnFetchAbort:I,ignoreFetchAbort:C,perf:P}=t;if(P!==void 0&&typeof P?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(p(this,At,P??Uo),e!==0&&!ie(e))throw new TypeError("max option must be a nonnegative integer");let A=e?Xr(e):Array;if(!A)throw new Error("invalid max value: "+e);if(p(this,St,e),p(this,dt,v),this.maxEntrySize=S||r(this,dt),this.sizeCalculation=k,this.sizeCalculation){if(!r(this,dt)&&!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(R!==void 0&&typeof R!="function")throw new TypeError("memoMethod must be a function if defined");if(p(this,je,R),b!==void 0&&typeof b!="function")throw new TypeError("fetchMethod must be a function if specified");if(p(this,Ne,b),p(this,he,!!b),p(this,B,new Map),p(this,$,new Array(e).fill(void 0)),p(this,T,new Array(e).fill(void 0)),p(this,rt,new A(e)),p(this,pt,new A(e)),p(this,st,0),p(this,Q,0),p(this,_t,Go.create(e)),p(this,V,0),p(this,Tt,0),typeof d=="function"&&p(this,Mt,d),typeof f=="function"&&p(this,Se,f),typeof u=="function"?(p(this,Lt,u),p(this,X,[])):(p(this,Lt,void 0),p(this,X,void 0)),p(this,It,!!r(this,Mt)),p(this,We,!!r(this,Se)),p(this,nt,!!r(this,Lt)),this.noDisposeOnSet=!!m,this.noUpdateTTL=!!w,this.noDeleteOnFetchRejection=!!M,this.allowStaleOnFetchRejection=!!F,this.allowStaleOnFetchAbort=!!I,this.ignoreFetchAbort=!!C,this.maxEntrySize!==0){if(r(this,dt)!==0&&!ie(r(this,dt)))throw new TypeError("maxSize must be a positive integer if specified");if(!ie(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");g(this,x,tn).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!E,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!l,this.ttlResolution=ie(n)||n===0?n:1,this.ttlAutopurge=!!o,this.ttl=i||0,this.ttl){if(!ie(this.ttl))throw new TypeError("ttl must be a positive integer if specified");g(this,x,Oi).call(this);}if(r(this,St)===0&&this.ttl===0&&r(this,dt)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,St)&&!r(this,dt)){let D="LRU_CACHE_UNBOUNDED";Bo(D)&&(Yr.add(D),Qr("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",D,ze));}}get perf(){return r(this,At)}static unsafeExposeInternals(t){return {starts:r(t,Ft),ttls:r(t,ft),autopurgeTimers:r(t,gt),sizes:r(t,Pt),keyMap:r(t,B),keyList:r(t,$),valList:r(t,T),next:r(t,rt),prev:r(t,pt),get head(){return r(t,st)},get tail(){return r(t,Q)},free:r(t,_t),isBackgroundFetch:e=>{var i;return g(i=t,x,j).call(i,e)},backgroundFetch:(e,i,n,o)=>{var a;return g(a=t,x,Js).call(a,e,i,n,o)},moveToTail:e=>{var i;return g(i=t,x,is).call(i,e)},indexes:e=>{var i;return g(i=t,x,re).call(i,e)},rindexes:e=>{var i;return g(i=t,x,ne).call(i,e)},isStale:e=>{var i;return r(i=t,mt).call(i,e)}}}get max(){return r(this,St)}get maxSize(){return r(this,dt)}get calculatedSize(){return r(this,Tt)}get size(){return r(this,V)}get fetchMethod(){return r(this,Ne)}get memoMethod(){return r(this,je)}get dispose(){return r(this,Mt)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,Lt)}getRemainingTTL(t){return r(this,B).has(t)?1/0:0}*entries(){for(let t of g(this,x,re).call(this))r(this,T)[t]!==void 0&&r(this,$)[t]!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield [r(this,$)[t],r(this,T)[t]]);}*rentries(){for(let t of g(this,x,ne).call(this))r(this,T)[t]!==void 0&&r(this,$)[t]!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield [r(this,$)[t],r(this,T)[t]]);}*keys(){for(let t of g(this,x,re).call(this)){let e=r(this,$)[t];e!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield e);}}*rkeys(){for(let t of g(this,x,ne).call(this)){let e=r(this,$)[t];e!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield e);}}*values(){for(let t of g(this,x,re).call(this))r(this,T)[t]!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield r(this,T)[t]);}*rvalues(){for(let t of g(this,x,ne).call(this))r(this,T)[t]!==void 0&&!g(this,x,j).call(this,r(this,T)[t])&&(yield r(this,T)[t]);}[(fr=Symbol.iterator,pr=Symbol.toStringTag,fr)](){return this.entries()}find(t,e={}){for(let i of g(this,x,re).call(this)){let n=r(this,T)[i],o=g(this,x,j).call(this,n)?n.__staleWhileFetching:n;if(o!==void 0&&t(o,r(this,$)[i],this))return this.get(r(this,$)[i],e)}}forEach(t,e=this){for(let i of g(this,x,re).call(this)){let n=r(this,T)[i],o=g(this,x,j).call(this,n)?n.__staleWhileFetching:n;o!==void 0&&t.call(e,o,r(this,$)[i],this);}}rforEach(t,e=this){for(let i of g(this,x,ne).call(this)){let n=r(this,T)[i],o=g(this,x,j).call(this,n)?n.__staleWhileFetching:n;o!==void 0&&t.call(e,o,r(this,$)[i],this);}}purgeStale(){let t=false;for(let e of g(this,x,ne).call(this,{allowStale:true}))r(this,mt).call(this,e)&&(g(this,x,oe).call(this,r(this,$)[e],"expire"),t=true);return t}info(t){let e=r(this,B).get(t);if(e===void 0)return;let i=r(this,T)[e],n=g(this,x,j).call(this,i)?i.__staleWhileFetching:i;if(n===void 0)return;let o={value:n};if(r(this,ft)&&r(this,Ft)){let a=r(this,ft)[e],l=r(this,Ft)[e];if(a&&l){let h=a-(r(this,At).now()-l);o.ttl=h,o.start=Date.now();}}return r(this,Pt)&&(o.size=r(this,Pt)[e]),o}dump(){let t=[];for(let e of g(this,x,re).call(this,{allowStale:true})){let i=r(this,$)[e],n=r(this,T)[e],o=g(this,x,j).call(this,n)?n.__staleWhileFetching:n;if(o===void 0||i===void 0)continue;let a={value:o};if(r(this,ft)&&r(this,Ft)){a.ttl=r(this,ft)[e];let l=r(this,At).now()-r(this,Ft)[e];a.start=Math.floor(Date.now()-l);}r(this,Pt)&&(a.size=r(this,Pt)[e]),t.unshift([i,a]);}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let n=Date.now()-i.start;i.start=r(this,At).now()-n;}this.set(e,i.value,i);}}set(t,e,i={}){var m,w,v,S;if(e===void 0)return this.delete(t),this;let{ttl:n=this.ttl,start:o,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:h}=i,{noUpdateTTL:d=this.noUpdateTTL}=i,f=r(this,us).call(this,t,e,i.size||0,l);if(this.maxEntrySize&&f>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),g(this,x,oe).call(this,t,"set"),this;let u=r(this,V)===0?void 0:r(this,B).get(t);if(u===void 0)u=r(this,V)===0?r(this,Q):r(this,_t).length!==0?r(this,_t).pop():r(this,V)===r(this,St)?g(this,x,qs).call(this,false):r(this,V),r(this,$)[u]=t,r(this,T)[u]=e,r(this,B).set(t,u),r(this,rt)[r(this,Q)]=u,r(this,pt)[u]=r(this,Q),p(this,Q,u),Fs(this,V)._++,r(this,$e).call(this,u,f,h),h&&(h.set="add"),d=false,r(this,We)&&((m=r(this,Se))==null||m.call(this,e,t,"add"));else {g(this,x,is).call(this,u);let k=r(this,T)[u];if(e!==k){if(r(this,he)&&g(this,x,j).call(this,k)){k.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:b}=k;b!==void 0&&!a&&(r(this,It)&&((w=r(this,Mt))==null||w.call(this,b,t,"set")),r(this,nt)&&r(this,X)?.push([b,t,"set"]));}else a||(r(this,It)&&((v=r(this,Mt))==null||v.call(this,k,t,"set")),r(this,nt)&&r(this,X)?.push([k,t,"set"]));if(r(this,ke).call(this,u),r(this,$e).call(this,u,f,h),r(this,T)[u]=e,h){h.set="replace";let b=k&&g(this,x,j).call(this,k)?k.__staleWhileFetching:k;b!==void 0&&(h.oldValue=b);}}else h&&(h.set="update");r(this,We)&&this.onInsert?.(e,t,e===k?"update":"replace");}if(n!==0&&!r(this,ft)&&g(this,x,Oi).call(this),r(this,ft)&&(d||r(this,cs).call(this,u,n,o),h&&r(this,Jt).call(this,h,u)),!a&&r(this,nt)&&r(this,X)){let k=r(this,X),b;for(;b=k?.shift();)(S=r(this,Lt))==null||S.call(this,...b);}return this}pop(){var t;try{for(;r(this,V);){let e=r(this,T)[r(this,st)];if(g(this,x,qs).call(this,!0),g(this,x,j).call(this,e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(r(this,nt)&&r(this,X)){let e=r(this,X),i;for(;i=e?.shift();)(t=r(this,Lt))==null||t.call(this,...i);}}}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:n}=e,o=r(this,B).get(t);if(o!==void 0){let a=r(this,T)[o];if(g(this,x,j).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(r(this,mt).call(this,o))n&&(n.has="stale",r(this,Jt).call(this,n,o));else return i&&r(this,xe).call(this,o),n&&(n.has="hit",r(this,Jt).call(this,n,o)),true}else n&&(n.has="miss");return false}peek(t,e={}){let{allowStale:i=this.allowStale}=e,n=r(this,B).get(t);if(n===void 0||!i&&r(this,mt).call(this,n))return;let o=r(this,T)[n];return g(this,x,j).call(this,o)?o.__staleWhileFetching:o}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:h=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:f=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:w=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:S,forceRefresh:k=false,status:b,signal:R}=e;if(!r(this,he))return b&&(b.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:o,status:b});let M={allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:o,ttl:a,noDisposeOnSet:l,size:h,sizeCalculation:d,noUpdateTTL:f,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:v,ignoreFetchAbort:w,status:b,signal:R},E=r(this,B).get(t);if(E===void 0){b&&(b.fetch="miss");let F=g(this,x,Js).call(this,t,E,M,S);return F.__returned=F}else {let F=r(this,T)[E];if(g(this,x,j).call(this,F)){let A=i&&F.__staleWhileFetching!==void 0;return b&&(b.fetch="inflight",A&&(b.returnedStale=true)),A?F.__staleWhileFetching:F.__returned=F}let I=r(this,mt).call(this,E);if(!k&&!I)return b&&(b.fetch="hit"),g(this,x,is).call(this,E),n&&r(this,xe).call(this,E),b&&r(this,Jt).call(this,b,E),F;let C=g(this,x,Js).call(this,t,E,M,S),P=C.__staleWhileFetching!==void 0&&i;return b&&(b.fetch=I?"stale":"refresh",P&&I&&(b.returnedStale=true)),P?C.__staleWhileFetching:C.__returned=C}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=r(this,je);if(!i)throw new Error("no memoMethod provided to constructor");let{context:n,forceRefresh:o,...a}=e,l=this.get(t,a);if(!o&&l!==void 0)return l;let h=i(t,l,{options:a,context:n});return this.set(t,h,a),h}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:a}=e,l=r(this,B).get(t);if(l!==void 0){let h=r(this,T)[l],d=g(this,x,j).call(this,h);return a&&r(this,Jt).call(this,a,l),r(this,mt).call(this,l)?(a&&(a.get="stale"),d?(a&&i&&h.__staleWhileFetching!==void 0&&(a.returnedStale=true),i?h.__staleWhileFetching:void 0):(o||g(this,x,oe).call(this,t,"expire"),a&&i&&(a.returnedStale=true),i?h:void 0)):(a&&(a.get="hit"),d?h.__staleWhileFetching:(g(this,x,is).call(this,l),n&&r(this,xe).call(this,l),h))}else a&&(a.get="miss");}delete(t){return g(this,x,oe).call(this,t,"delete")}clear(){return g(this,x,Li).call(this,"delete")}},St=new WeakMap,dt=new WeakMap,Mt=new WeakMap,Se=new WeakMap,Lt=new WeakMap,Ne=new WeakMap,je=new WeakMap,At=new WeakMap,V=new WeakMap,Tt=new WeakMap,B=new WeakMap,$=new WeakMap,T=new WeakMap,rt=new WeakMap,pt=new WeakMap,st=new WeakMap,Q=new WeakMap,_t=new WeakMap,X=new WeakMap,Pt=new WeakMap,Ft=new WeakMap,ft=new WeakMap,gt=new WeakMap,It=new WeakMap,he=new WeakMap,nt=new WeakMap,We=new WeakMap,x=new WeakSet,Oi=function(){let t=new Vs(r(this,St)),e=new Vs(r(this,St));p(this,ft,t),p(this,Ft,e);let i=this.ttlAutopurge?new Array(r(this,St)):void 0;p(this,gt,i),p(this,cs,(a,l,h=r(this,At).now())=>{if(e[a]=l!==0?h:0,t[a]=l,i?.[a]&&(clearTimeout(i[a]),i[a]=void 0),l!==0&&i){let d=setTimeout(()=>{r(this,mt).call(this,a)&&g(this,x,oe).call(this,r(this,$)[a],"expire");},l+1);d.unref&&d.unref(),i[a]=d;}}),p(this,xe,a=>{e[a]=t[a]!==0?r(this,At).now():0;}),p(this,Jt,(a,l)=>{if(t[l]){let h=t[l],d=e[l];if(!h||!d)return;a.ttl=h,a.start=d,a.now=n||o();let f=a.now-d;a.remainingTTL=h-f;}});let n=0,o=()=>{let a=r(this,At).now();if(this.ttlResolution>0){n=a;let l=setTimeout(()=>n=0,this.ttlResolution);l.unref&&l.unref();}return a};this.getRemainingTTL=a=>{let l=r(this,B).get(a);if(l===void 0)return 0;let h=t[l],d=e[l];if(!h||!d)return 1/0;let f=(n||o())-d;return h-f},p(this,mt,a=>{let l=e[a],h=t[a];return !!h&&!!l&&(n||o())-l>h});},xe=new WeakMap,Jt=new WeakMap,cs=new WeakMap,mt=new WeakMap,tn=function(){let t=new Vs(r(this,St));p(this,Tt,0),p(this,Pt,t),p(this,ke,e=>{p(this,Tt,r(this,Tt)-t[e]),t[e]=0;}),p(this,us,(e,i,n,o)=>{if(g(this,x,j).call(this,i))return 0;if(!ie(n))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(n=o(i,e),!ie(n))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 n}),p(this,$e,(e,i,n)=>{if(t[e]=i,r(this,dt)){let o=r(this,dt)-t[e];for(;r(this,Tt)>o;)g(this,x,qs).call(this,true);}p(this,Tt,r(this,Tt)+t[e]),n&&(n.entrySize=i,n.totalCalculatedSize=r(this,Tt));});},ke=new WeakMap,$e=new WeakMap,us=new WeakMap,re=function*({allowStale:t=this.allowStale}={}){if(r(this,V))for(let e=r(this,Q);!(!g(this,x,Ri).call(this,e)||((t||!r(this,mt).call(this,e))&&(yield e),e===r(this,st)));)e=r(this,pt)[e];},ne=function*({allowStale:t=this.allowStale}={}){if(r(this,V))for(let e=r(this,st);!(!g(this,x,Ri).call(this,e)||((t||!r(this,mt).call(this,e))&&(yield e),e===r(this,Q)));)e=r(this,rt)[e];},Ri=function(t){return t!==void 0&&r(this,B).get(r(this,$)[t])===t},qs=function(t){var o;let e=r(this,st),i=r(this,$)[e],n=r(this,T)[e];return r(this,he)&&g(this,x,j).call(this,n)?n.__abortController.abort(new Error("evicted")):(r(this,It)||r(this,nt))&&(r(this,It)&&((o=r(this,Mt))==null||o.call(this,n,i,"evict")),r(this,nt)&&r(this,X)?.push([n,i,"evict"])),r(this,ke).call(this,e),r(this,gt)?.[e]&&(clearTimeout(r(this,gt)[e]),r(this,gt)[e]=void 0),t&&(r(this,$)[e]=void 0,r(this,T)[e]=void 0,r(this,_t).push(e)),r(this,V)===1?(p(this,st,p(this,Q,0)),r(this,_t).length=0):p(this,st,r(this,rt)[e]),r(this,B).delete(i),Fs(this,V)._--,e},Js=function(t,e,i,n){let o=e===void 0?void 0:r(this,T)[e];if(g(this,x,j).call(this,o))return o;let a=new Xs,{signal:l}=i;l?.addEventListener("abort",()=>a.abort(l.reason),{signal:a.signal});let h={signal:a.signal,options:i,context:n},d=(S,k=false)=>{let{aborted:b}=a.signal,R=i.ignoreFetchAbort&&S!==void 0,M=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&S!==void 0);if(i.status&&(b&&!k?(i.status.fetchAborted=true,i.status.fetchError=a.signal.reason,R&&(i.status.fetchAbortIgnored=true)):i.status.fetchResolved=true),b&&!R&&!k)return u(a.signal.reason,M);let E=w,F=r(this,T)[e];return (F===w||R&&k&&F===void 0)&&(S===void 0?E.__staleWhileFetching!==void 0?r(this,T)[e]=E.__staleWhileFetching:g(this,x,oe).call(this,t,"fetch"):(i.status&&(i.status.fetchUpdated=true),this.set(t,S,h.options))),S},f=S=>(i.status&&(i.status.fetchRejected=true,i.status.fetchError=S),u(S,false)),u=(S,k)=>{let{aborted:b}=a.signal,R=b&&i.allowStaleOnFetchAbort,M=R||i.allowStaleOnFetchRejection,E=M||i.noDeleteOnFetchRejection,F=w;if(r(this,T)[e]===w&&(!E||!k&&F.__staleWhileFetching===void 0?g(this,x,oe).call(this,t,"fetch"):R||(r(this,T)[e]=F.__staleWhileFetching)),M)return i.status&&F.__staleWhileFetching!==void 0&&(i.status.returnedStale=true),F.__staleWhileFetching;if(F.__returned===F)throw S},m=(S,k)=>{var R;let b=(R=r(this,Ne))==null?void 0:R.call(this,t,o,h);b&&b instanceof Promise&&b.then(M=>S(M===void 0?void 0:M),k),a.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(S(void 0),i.allowStaleOnFetchAbort&&(S=M=>d(M,true)));});};i.status&&(i.status.fetchDispatched=true);let w=new Promise(m).then(d,f),v=Object.assign(w,{__abortController:a,__staleWhileFetching:o,__returned:void 0});return e===void 0?(this.set(t,v,{...h.options,status:void 0}),e=r(this,B).get(t)):r(this,T)[e]=v,v},j=function(t){if(!r(this,he))return false;let e=t;return !!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof Xs},Mi=function(t,e){r(this,pt)[e]=t,r(this,rt)[t]=e;},is=function(t){t!==r(this,Q)&&(t===r(this,st)?p(this,st,r(this,rt)[t]):g(this,x,Mi).call(this,r(this,pt)[t],r(this,rt)[t]),g(this,x,Mi).call(this,r(this,Q),t),p(this,Q,t));},oe=function(t,e){var n,o;let i=false;if(r(this,V)!==0){let a=r(this,B).get(t);if(a!==void 0)if(r(this,gt)?.[a]&&(clearTimeout(r(this,gt)?.[a]),r(this,gt)[a]=void 0),i=true,r(this,V)===1)g(this,x,Li).call(this,e);else {r(this,ke).call(this,a);let l=r(this,T)[a];if(g(this,x,j).call(this,l)?l.__abortController.abort(new Error("deleted")):(r(this,It)||r(this,nt))&&(r(this,It)&&((n=r(this,Mt))==null||n.call(this,l,t,e)),r(this,nt)&&r(this,X)?.push([l,t,e])),r(this,B).delete(t),r(this,$)[a]=void 0,r(this,T)[a]=void 0,a===r(this,Q))p(this,Q,r(this,pt)[a]);else if(a===r(this,st))p(this,st,r(this,rt)[a]);else {let h=r(this,pt)[a];r(this,rt)[h]=r(this,rt)[a];let d=r(this,rt)[a];r(this,pt)[d]=r(this,pt)[a];}Fs(this,V)._--,r(this,_t).push(a);}}if(r(this,nt)&&r(this,X)?.length){let a=r(this,X),l;for(;l=a?.shift();)(o=r(this,Lt))==null||o.call(this,...l);}return i},Li=function(t){var e,i;for(let n of g(this,x,ne).call(this,{allowStale:true})){let o=r(this,T)[n];if(g(this,x,j).call(this,o))o.__abortController.abort(new Error("deleted"));else {let a=r(this,$)[n];r(this,It)&&((e=r(this,Mt))==null||e.call(this,o,a,t)),r(this,nt)&&r(this,X)?.push([o,a,t]);}}if(r(this,B).clear(),r(this,T).fill(void 0),r(this,$).fill(void 0),r(this,ft)&&r(this,Ft)){r(this,ft).fill(0),r(this,Ft).fill(0);for(let n of r(this,gt)??[])n!==void 0&&clearTimeout(n);r(this,gt)?.fill(void 0);}if(r(this,Pt)&&r(this,Pt).fill(0),p(this,st,0),p(this,Q,0),r(this,_t).length=0,p(this,Tt,0),p(this,V,0),r(this,nt)&&r(this,X)){let n=r(this,X),o;for(;o=n?.shift();)(i=r(this,Lt))==null||i.call(this,...o);}},ze),Xi=typeof process=="object"&&process?process:{stdout:null,stderr:null},ra=s=>!!s&&typeof s=="object"&&(s instanceof ti||s instanceof en||na(s)||oa(s)),na=s=>!!s&&typeof s=="object"&&s instanceof EventEmitter&&typeof s.pipe=="function"&&s.pipe!==en.Writable.prototype.pipe,oa=s=>!!s&&typeof s=="object"&&s instanceof EventEmitter&&typeof s.write=="function"&&typeof s.end=="function",Gt=Symbol("EOF"),Vt=Symbol("maybeEmitEnd"),se=Symbol("emittedEnd"),Ns=Symbol("emittingEnd"),Ye=Symbol("emittedError"),js=Symbol("closed"),tr=Symbol("read"),Ws=Symbol("flush"),er=Symbol("flushChunk"),Ot=Symbol("encoding"),Pe=Symbol("decoder"),H=Symbol("flowing"),Qe=Symbol("paused"),Fe=Symbol("resume"),Z=Symbol("buffer"),it=Symbol("pipes"),K=Symbol("bufferLength"),yi=Symbol("bufferPush"),$s=Symbol("bufferShift"),et=Symbol("objectMode"),z=Symbol("destroyed"),wi=Symbol("error"),bi=Symbol("emitData"),sr=Symbol("emitEnd"),vi=Symbol("emitEnd2"),jt=Symbol("async"),Si=Symbol("abort"),zs=Symbol("aborted"),Xe=Symbol("signal"),me=Symbol("dataListeners"),ut=Symbol("discarded"),ts=s=>Promise.resolve().then(s),aa=s=>s(),la=s=>s==="end"||s==="finish"||s==="prefinish",ha=s=>s instanceof ArrayBuffer||!!s&&typeof s=="object"&&s.constructor&&s.constructor.name==="ArrayBuffer"&&s.byteLength>=0,ca=s=>!Buffer.isBuffer(s)&&ArrayBuffer.isView(s),sn=class{constructor(s,t,e){c(this,"src");c(this,"dest");c(this,"opts");c(this,"ondrain");this.src=s,this.dest=t,this.opts=e,this.ondrain=()=>s[Fe](),this.dest.on("drain",this.ondrain);}unpipe(){this.dest.removeListener("drain",this.ondrain);}proxyErrors(s){}end(){this.unpipe(),this.opts.end&&this.dest.end();}},ua=class extends sn{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe();}constructor(s,t,e){super(s,t,e),this.proxyErrors=i=>this.dest.emit("error",i),s.on("error",this.proxyErrors);}},da=s=>!!s.objectMode,pa=s=>!s.objectMode&&!!s.encoding&&s.encoding!=="buffer",gr,mr,yr,wr,br,vr,Sr,xr,kr,Er,Cr,Or,Rr,Mr,Lr,Ar,Tr,_r,Pr,ti=class extends EventEmitter{constructor(...t){let e=t[0]||{};super();c(this,Pr,false);c(this,_r,false);c(this,Tr,[]);c(this,Ar,[]);c(this,Lr);c(this,Mr);c(this,Rr);c(this,Or);c(this,Cr,false);c(this,Er,false);c(this,kr,false);c(this,xr,false);c(this,Sr,null);c(this,vr,0);c(this,br,false);c(this,wr);c(this,yr,false);c(this,mr,0);c(this,gr,false);c(this,"writable",true);c(this,"readable",true);if(e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");da(e)?(this[et]=true,this[Ot]=null):pa(e)?(this[Ot]=e.encoding,this[et]=false):(this[et]=false,this[Ot]=null),this[jt]=!!e.async,this[Pe]=this[Ot]?new StringDecoder(this[Ot]):null,e&&e.debugExposeBuffer===true&&Object.defineProperty(this,"buffer",{get:()=>this[Z]}),e&&e.debugExposePipes===true&&Object.defineProperty(this,"pipes",{get:()=>this[it]});let{signal:i}=e;i&&(this[Xe]=i,i.aborted?this[Si]():i.addEventListener("abort",()=>this[Si]()));}get bufferLength(){return this[K]}get encoding(){return this[Ot]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[et]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[jt]}set async(t){this[jt]=this[jt]||!!t;}[(Pr=H,_r=Qe,Tr=it,Ar=Z,Lr=et,Mr=Ot,Rr=jt,Or=Pe,Cr=Gt,Er=se,kr=Ns,xr=js,Sr=Ye,vr=K,br=z,wr=Xe,yr=zs,mr=me,gr=ut,Si)](){this[zs]=true,this.emit("abort",this[Xe]?.reason),this.destroy(this[Xe]?.reason);}get aborted(){return this[zs]}set aborted(t){}write(t,e,i){if(this[zs])return false;if(this[Gt])throw new Error("write after end");if(this[z])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),true;typeof e=="function"&&(i=e,e="utf8"),e||(e="utf8");let n=this[jt]?ts:aa;if(!this[et]&&!Buffer.isBuffer(t)){if(ca(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(ha(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[et]?(this[H]&&this[K]!==0&&this[Ws](true),this[H]?this.emit("data",t):this[yi](t),this[K]!==0&&this.emit("readable"),i&&n(i),this[H]):t.length?(typeof t=="string"&&!(e===this[Ot]&&!this[Pe]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[Ot]&&(t=this[Pe].write(t)),this[H]&&this[K]!==0&&this[Ws](true),this[H]?this.emit("data",t):this[yi](t),this[K]!==0&&this.emit("readable"),i&&n(i),this[H]):(this[K]!==0&&this.emit("readable"),i&&n(i),this[H])}read(t){if(this[z])return null;if(this[ut]=false,this[K]===0||t===0||t&&t>this[K])return this[Vt](),null;this[et]&&(t=null),this[Z].length>1&&!this[et]&&(this[Z]=[this[Ot]?this[Z].join(""):Buffer.concat(this[Z],this[K])]);let e=this[tr](t||null,this[Z][0]);return this[Vt](),e}[tr](t,e){if(this[et])this[$s]();else {let i=e;t===i.length||t===null?this[$s]():typeof i=="string"?(this[Z][0]=i.slice(t),e=i.slice(0,t),this[K]-=t):(this[Z][0]=i.subarray(t),e=i.subarray(0,t),this[K]-=t);}return this.emit("data",e),!this[Z].length&&!this[Gt]&&this.emit("drain"),e}end(t,e,i){return typeof t=="function"&&(i=t,t=void 0),typeof e=="function"&&(i=e,e="utf8"),t!==void 0&&this.write(t,e),i&&this.once("end",i),this[Gt]=true,this.writable=false,(this[H]||!this[Qe])&&this[Vt](),this}[Fe](){this[z]||(!this[me]&&!this[it].length&&(this[ut]=true),this[Qe]=false,this[H]=true,this.emit("resume"),this[Z].length?this[Ws]():this[Gt]?this[Vt]():this.emit("drain"));}resume(){return this[Fe]()}pause(){this[H]=false,this[Qe]=true,this[ut]=false;}get destroyed(){return this[z]}get flowing(){return this[H]}get paused(){return this[Qe]}[yi](t){this[et]?this[K]+=1:this[K]+=t.length,this[Z].push(t);}[$s](){return this[et]?this[K]-=1:this[K]-=this[Z][0].length,this[Z].shift()}[Ws](t=false){do;while(this[er](this[$s]())&&this[Z].length);!t&&!this[Z].length&&!this[Gt]&&this.emit("drain");}[er](t){return this.emit("data",t),this[H]}pipe(t,e){if(this[z])return t;this[ut]=false;let i=this[se];return e=e||{},t===Xi.stdout||t===Xi.stderr?e.end=false:e.end=e.end!==false,e.proxyErrors=!!e.proxyErrors,i?e.end&&t.end():(this[it].push(e.proxyErrors?new ua(this,t,e):new sn(this,t,e)),this[jt]?ts(()=>this[Fe]()):this[Fe]()),t}unpipe(t){let e=this[it].find(i=>i.dest===t);e&&(this[it].length===1?(this[H]&&this[me]===0&&(this[H]=false),this[it]=[]):this[it].splice(this[it].indexOf(e),1),e.unpipe());}addListener(t,e){return this.on(t,e)}on(t,e){let i=super.on(t,e);if(t==="data")this[ut]=false,this[me]++,!this[it].length&&!this[H]&&this[Fe]();else if(t==="readable"&&this[K]!==0)super.emit("readable");else if(la(t)&&this[se])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Ye]){let n=e;this[jt]?ts(()=>n.call(this,this[Ye])):n.call(this,this[Ye]);}return i}removeListener(t,e){return this.off(t,e)}off(t,e){let i=super.off(t,e);return t==="data"&&(this[me]=this.listeners("data").length,this[me]===0&&!this[ut]&&!this[it].length&&(this[H]=false)),i}removeAllListeners(t){let e=super.removeAllListeners(t);return (t==="data"||t===void 0)&&(this[me]=0,!this[ut]&&!this[it].length&&(this[H]=false)),e}get emittedEnd(){return this[se]}[Vt](){!this[Ns]&&!this[se]&&!this[z]&&this[Z].length===0&&this[Gt]&&(this[Ns]=true,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[js]&&this.emit("close"),this[Ns]=false);}emit(t,...e){let i=e[0];if(t!=="error"&&t!=="close"&&t!==z&&this[z])return false;if(t==="data")return !this[et]&&!i?false:this[jt]?(ts(()=>this[bi](i)),true):this[bi](i);if(t==="end")return this[sr]();if(t==="close"){if(this[js]=true,!this[se]&&!this[z])return false;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Ye]=i,super.emit(wi,i);let o=!this[Xe]||this.listeners("error").length?super.emit("error",i):false;return this[Vt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Vt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let n=super.emit(t,...e);return this[Vt](),n}[bi](t){for(let i of this[it])i.dest.write(t)===false&&this.pause();let e=this[ut]?false:super.emit("data",t);return this[Vt](),e}[sr](){return this[se]?false:(this[se]=true,this.readable=false,this[jt]?(ts(()=>this[vi]()),true):this[vi]())}[vi](){if(this[Pe]){let e=this[Pe].end();if(e){for(let i of this[it])i.dest.write(e);this[ut]||super.emit("data",e);}}for(let e of this[it])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[et]||(t.dataLength=0);let e=this.promise();return this.on("data",i=>{t.push(i),this[et]||(t.dataLength+=i.length);}),await e,t}async concat(){if(this[et])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[Ot]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(z,()=>e(new Error("stream destroyed"))),this.on("error",i=>e(i)),this.on("end",()=>t());})}[Symbol.asyncIterator](){this[ut]=false;let t=false,e=async()=>(this.pause(),t=true,{value:void 0,done:true});return {next:()=>{if(t)return e();let i=this.read();if(i!==null)return Promise.resolve({done:false,value:i});if(this[Gt])return e();let n,o,a=f=>{this.off("data",l),this.off("end",h),this.off(z,d),e(),o(f);},l=f=>{this.off("error",a),this.off("end",h),this.off(z,d),this.pause(),n({value:f,done:!!this[Gt]});},h=()=>{this.off("error",a),this.off("data",l),this.off(z,d),e(),n({done:true,value:void 0});},d=()=>a(new Error("stream destroyed"));return new Promise((f,u)=>{o=u,n=f,this.once(z,d),this.once("error",a),this.once("end",h),this.once("data",l);})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ut]=false;let t=false,e=()=>(this.pause(),this.off(wi,e),this.off(z,e),this.off("end",e),t=true,{done:true,value:void 0}),i=()=>{if(t)return e();let n=this.read();return n===null?e():{done:false,value:n}};return this.once("end",e),this.once(wi,e),this.once(z,e),{next:i,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[z])return t?this.emit("error",t):this.emit(z),this;this[z]=true,this[ut]=true,this[Z].length=0,this[K]=0;let e=this;return typeof e.close=="function"&&!this[js]&&e.close(),t?this.emit("error",t):this.emit(z),this}static get isStream(){return ra}},fa=realpathSync.native,rs={lstatSync:lstatSync,readdir:readdir$1,readdirSync:readdirSync,readlinkSync:readlinkSync,realpathSync:fa,promises:{lstat:lstat,readdir:readdir,readlink:readlink,realpath:realpath}},rn=s=>!s||s===rs||s===Qo?rs:{...rs,...s,promises:{...rs.promises,...s.promises||{}}},nn=/^\\\\\?\\([a-z]:)\\?$/i,ga=s=>s.replace(/\//g,"\\").replace(nn,"$1\\"),ma=/[\\\/]/,xt=0,on=1,an=2,Wt=4,ln=6,hn=8,ye=10,cn=12,vt=15,es=~vt,xi=16,ir=32,ns=64,Rt=128,Us=256,Hs=512,rr=ns|Rt|Hs,ya=1023,ki=s=>s.isFile()?hn:s.isDirectory()?Wt:s.isSymbolicLink()?ye:s.isCharacterDevice()?an:s.isBlockDevice()?ln:s.isSocket()?cn:s.isFIFO()?on:xt,nr=new si({max:2**12}),os=s=>{let t=nr.get(s);if(t)return t;let e=s.normalize("NFKD");return nr.set(s,e),e},or=new si({max:2**12}),Bs=s=>{let t=or.get(s);if(t)return t;let e=os(s.toLowerCase());return or.set(s,e),e},ar=class extends si{constructor(){super({max:256});}},wa=class extends si{constructor(s=16*1024){super({maxSize:s,sizeCalculation:t=>t.length+1});}},un=Symbol("PathScurry setAsCwd"),ot,ds,ps,fs,gs,ms,ys,ws,bs,vs,Ss,xs,ks,Es,Cs,Os,Rs,Ms,Ls,ce,Ee,zt,Ht,Zt,Kt,L,Ce,Yt,Ut,O,Ti,Zs,as,_i,Pi,ls,Ks,Fi,Ii,Ys,dn,pn,fn,Di,Ue,Be,gn,Oe,Fr,ht=(Fr=class{constructor(s,t=xt,e,i,n,o,a){y(this,O);c(this,"name");c(this,"root");c(this,"roots");c(this,"parent");c(this,"nocase");c(this,"isCWD",false);y(this,ot);y(this,ds);y(this,ps);y(this,fs);y(this,gs);y(this,ms);y(this,ys);y(this,ws);y(this,bs);y(this,vs);y(this,Ss);y(this,xs);y(this,ks);y(this,Es);y(this,Cs);y(this,Os);y(this,Rs);y(this,Ms);y(this,Ls);y(this,ce);y(this,Ee);y(this,zt);y(this,Ht);y(this,Zt);y(this,Kt);y(this,L);y(this,Ce);y(this,Yt);y(this,Ut);y(this,Ue,[]);y(this,Be,false);y(this,Oe);this.name=s,p(this,ce,n?Bs(s):os(s)),p(this,L,t&ya),this.nocase=n,this.roots=i,this.root=e||this,p(this,Ce,o),p(this,zt,a.fullpath),p(this,Zt,a.relative),p(this,Kt,a.relativePosix),this.parent=a.parent,this.parent?p(this,ot,r(this.parent,ot)):p(this,ot,rn(a.fs));}get dev(){return r(this,ds)}get mode(){return r(this,ps)}get nlink(){return r(this,fs)}get uid(){return r(this,gs)}get gid(){return r(this,ms)}get rdev(){return r(this,ys)}get blksize(){return r(this,ws)}get ino(){return r(this,bs)}get size(){return r(this,vs)}get blocks(){return r(this,Ss)}get atimeMs(){return r(this,xs)}get mtimeMs(){return r(this,ks)}get ctimeMs(){return r(this,Es)}get birthtimeMs(){return r(this,Cs)}get atime(){return r(this,Os)}get mtime(){return r(this,Rs)}get ctime(){return r(this,Ms)}get birthtime(){return r(this,Ls)}get parentPath(){return (this.parent||this).fullpath()}get path(){return this.parentPath}depth(){return r(this,Ee)!==void 0?r(this,Ee):this.parent?p(this,Ee,this.parent.depth()+1):p(this,Ee,0)}childrenCache(){return r(this,Ce)}resolve(s){var i;if(!s)return this;let t=this.getRootString(s),e=s.substring(t.length).split(this.splitSep);return t?g(i=this.getRoot(t),O,Ti).call(i,e):g(this,O,Ti).call(this,e)}children(){let s=r(this,Ce).get(this);if(s)return s;let t=Object.assign([],{provisional:0});return r(this,Ce).set(this,t),p(this,L,r(this,L)&~xi),t}child(s,t){if(s===""||s===".")return this;if(s==="..")return this.parent||this;let e=this.children(),i=this.nocase?Bs(s):os(s);for(let l of e)if(r(l,ce)===i)return l;let n=this.parent?this.sep:"",o=r(this,zt)?r(this,zt)+n+s:void 0,a=this.newChild(s,xt,{...t,parent:this,fullpath:o});return this.canReaddir()||p(a,L,r(a,L)|Rt),e.push(a),a}relative(){if(this.isCWD)return "";if(r(this,Zt)!==void 0)return r(this,Zt);let s=this.name,t=this.parent;if(!t)return p(this,Zt,this.name);let e=t.relative();return e+(!e||!t.parent?"":this.sep)+s}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return "";if(r(this,Kt)!==void 0)return r(this,Kt);let s=this.name,t=this.parent;if(!t)return p(this,Kt,this.fullpathPosix());let e=t.relativePosix();return e+(!e||!t.parent?"":"/")+s}fullpath(){if(r(this,zt)!==void 0)return r(this,zt);let s=this.name,t=this.parent;if(!t)return p(this,zt,this.name);let e=t.fullpath()+(t.parent?this.sep:"")+s;return p(this,zt,e)}fullpathPosix(){if(r(this,Ht)!==void 0)return r(this,Ht);if(this.sep==="/")return p(this,Ht,this.fullpath());if(!this.parent){let i=this.fullpath().replace(/\\/g,"/");return /^[a-z]:\//i.test(i)?p(this,Ht,`//?/${i}`):p(this,Ht,i)}let s=this.parent,t=s.fullpathPosix(),e=t+(!t||!s.parent?"":"/")+this.name;return p(this,Ht,e)}isUnknown(){return (r(this,L)&vt)===xt}isType(s){return this[`is${s}`]()}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 (r(this,L)&vt)===hn}isDirectory(){return (r(this,L)&vt)===Wt}isCharacterDevice(){return (r(this,L)&vt)===an}isBlockDevice(){return (r(this,L)&vt)===ln}isFIFO(){return (r(this,L)&vt)===on}isSocket(){return (r(this,L)&vt)===cn}isSymbolicLink(){return (r(this,L)&ye)===ye}lstatCached(){return r(this,L)&ir?this:void 0}readlinkCached(){return r(this,Yt)}realpathCached(){return r(this,Ut)}readdirCached(){let s=this.children();return s.slice(0,s.provisional)}canReadlink(){if(r(this,Yt))return true;if(!this.parent)return false;let s=r(this,L)&vt;return !(s!==xt&&s!==ye||r(this,L)&Us||r(this,L)&Rt)}calledReaddir(){return !!(r(this,L)&xi)}isENOENT(){return !!(r(this,L)&Rt)}isNamed(s){return this.nocase?r(this,ce)===Bs(s):r(this,ce)===os(s)}async readlink(){let s=r(this,Yt);if(s)return s;if(this.canReadlink()&&this.parent)try{let t=await r(this,ot).promises.readlink(this.fullpath()),e=(await this.parent.realpath())?.resolve(t);if(e)return p(this,Yt,e)}catch(t){g(this,O,Ii).call(this,t.code);return}}readlinkSync(){let s=r(this,Yt);if(s)return s;if(this.canReadlink()&&this.parent)try{let t=r(this,ot).readlinkSync(this.fullpath()),e=this.parent.realpathSync()?.resolve(t);if(e)return p(this,Yt,e)}catch(t){g(this,O,Ii).call(this,t.code);return}}async lstat(){if((r(this,L)&Rt)===0)try{return g(this,O,Di).call(this,await r(this,ot).promises.lstat(this.fullpath())),this}catch(s){g(this,O,Fi).call(this,s.code);}}lstatSync(){if((r(this,L)&Rt)===0)try{return g(this,O,Di).call(this,r(this,ot).lstatSync(this.fullpath())),this}catch(s){g(this,O,Fi).call(this,s.code);}}readdirCB(s,t=false){if(!this.canReaddir()){t?s(null,[]):queueMicrotask(()=>s(null,[]));return}let e=this.children();if(this.calledReaddir()){let n=e.slice(0,e.provisional);t?s(null,n):queueMicrotask(()=>s(null,n));return}if(r(this,Ue).push(s),r(this,Be))return;p(this,Be,true);let i=this.fullpath();r(this,ot).readdir(i,{withFileTypes:true},(n,o)=>{if(n)g(this,O,Ks).call(this,n.code),e.provisional=0;else {for(let a of o)g(this,O,Ys).call(this,a,e);g(this,O,Zs).call(this,e);}g(this,O,gn).call(this,e.slice(0,e.provisional));});}async readdir(){if(!this.canReaddir())return [];let s=this.children();if(this.calledReaddir())return s.slice(0,s.provisional);let t=this.fullpath();if(r(this,Oe))await r(this,Oe);else {let e=()=>{};p(this,Oe,new Promise(i=>e=i));try{for(let i of await r(this,ot).promises.readdir(t,{withFileTypes:!0}))g(this,O,Ys).call(this,i,s);g(this,O,Zs).call(this,s);}catch(i){g(this,O,Ks).call(this,i.code),s.provisional=0;}p(this,Oe,void 0),e();}return s.slice(0,s.provisional)}readdirSync(){if(!this.canReaddir())return [];let s=this.children();if(this.calledReaddir())return s.slice(0,s.provisional);let t=this.fullpath();try{for(let e of r(this,ot).readdirSync(t,{withFileTypes:!0}))g(this,O,Ys).call(this,e,s);g(this,O,Zs).call(this,s);}catch(e){g(this,O,Ks).call(this,e.code),s.provisional=0;}return s.slice(0,s.provisional)}canReaddir(){if(r(this,L)&rr)return false;let s=vt&r(this,L);return s===xt||s===Wt||s===ye}shouldWalk(s,t){return (r(this,L)&Wt)===Wt&&!(r(this,L)&rr)&&!s.has(this)&&(!t||t(this))}async realpath(){if(r(this,Ut))return r(this,Ut);if(!((Hs|Us|Rt)&r(this,L)))try{let s=await r(this,ot).promises.realpath(this.fullpath());return p(this,Ut,this.resolve(s))}catch{g(this,O,Pi).call(this);}}realpathSync(){if(r(this,Ut))return r(this,Ut);if(!((Hs|Us|Rt)&r(this,L)))try{let s=r(this,ot).realpathSync(this.fullpath());return p(this,Ut,this.resolve(s))}catch{g(this,O,Pi).call(this);}}[un](s){if(s===this)return;s.isCWD=false,this.isCWD=true;let t=new Set([]),e=[],i=this;for(;i&&i.parent;)t.add(i),p(i,Zt,e.join(this.sep)),p(i,Kt,e.join("/")),i=i.parent,e.push("..");for(i=s;i&&i.parent&&!t.has(i);)p(i,Zt,void 0),p(i,Kt,void 0),i=i.parent;}},ot=new WeakMap,ds=new WeakMap,ps=new WeakMap,fs=new WeakMap,gs=new WeakMap,ms=new WeakMap,ys=new WeakMap,ws=new WeakMap,bs=new WeakMap,vs=new WeakMap,Ss=new WeakMap,xs=new WeakMap,ks=new WeakMap,Es=new WeakMap,Cs=new WeakMap,Os=new WeakMap,Rs=new WeakMap,Ms=new WeakMap,Ls=new WeakMap,ce=new WeakMap,Ee=new WeakMap,zt=new WeakMap,Ht=new WeakMap,Zt=new WeakMap,Kt=new WeakMap,L=new WeakMap,Ce=new WeakMap,Yt=new WeakMap,Ut=new WeakMap,O=new WeakSet,Ti=function(s){let t=this;for(let e of s)t=t.child(e);return t},Zs=function(s){var t;p(this,L,r(this,L)|xi);for(let e=s.provisional;e<s.length;e++){let i=s[e];i&&g(t=i,O,as).call(t);}},as=function(){r(this,L)&Rt||(p(this,L,(r(this,L)|Rt)&es),g(this,O,_i).call(this));},_i=function(){var t;let s=this.children();s.provisional=0;for(let e of s)g(t=e,O,as).call(t);},Pi=function(){p(this,L,r(this,L)|Hs),g(this,O,ls).call(this);},ls=function(){if(r(this,L)&ns)return;let s=r(this,L);(s&vt)===Wt&&(s&=es),p(this,L,s|ns),g(this,O,_i).call(this);},Ks=function(s=""){s==="ENOTDIR"||s==="EPERM"?g(this,O,ls).call(this):s==="ENOENT"?g(this,O,as).call(this):this.children().provisional=0;},Fi=function(s=""){var t;s==="ENOTDIR"?g(t=this.parent,O,ls).call(t):s==="ENOENT"&&g(this,O,as).call(this);},Ii=function(s=""){var e;let t=r(this,L);t|=Us,s==="ENOENT"&&(t|=Rt),(s==="EINVAL"||s==="UNKNOWN")&&(t&=es),p(this,L,t),s==="ENOTDIR"&&this.parent&&g(e=this.parent,O,ls).call(e);},Ys=function(s,t){return g(this,O,pn).call(this,s,t)||g(this,O,dn).call(this,s,t)},dn=function(s,t){let e=ki(s),i=this.newChild(s.name,e,{parent:this}),n=r(i,L)&vt;return n!==Wt&&n!==ye&&n!==xt&&p(i,L,r(i,L)|ns),t.unshift(i),t.provisional++,i},pn=function(s,t){for(let e=t.provisional;e<t.length;e++){let i=t[e];if((this.nocase?Bs(s.name):os(s.name))===r(i,ce))return g(this,O,fn).call(this,s,i,e,t)}},fn=function(s,t,e,i){let n=t.name;return p(t,L,r(t,L)&es|ki(s)),n!==s.name&&(t.name=s.name),e!==i.provisional&&(e===i.length-1?i.pop():i.splice(e,1),i.unshift(t)),i.provisional++,t},Di=function(s){let{atime:t,atimeMs:e,birthtime:i,birthtimeMs:n,blksize:o,blocks:a,ctime:l,ctimeMs:h,dev:d,gid:f,ino:u,mode:m,mtime:w,mtimeMs:v,nlink:S,rdev:k,size:b,uid:R}=s;p(this,Os,t),p(this,xs,e),p(this,Ls,i),p(this,Cs,n),p(this,ws,o),p(this,Ss,a),p(this,Ms,l),p(this,Es,h),p(this,ds,d),p(this,ms,f),p(this,bs,u),p(this,ps,m),p(this,Rs,w),p(this,ks,v),p(this,fs,S),p(this,ys,k),p(this,vs,b),p(this,gs,R);let M=ki(s);p(this,L,r(this,L)&es|M|ir),M!==xt&&M!==Wt&&M!==ye&&p(this,L,r(this,L)|ns);},Ue=new WeakMap,Be=new WeakMap,gn=function(s){p(this,Be,false);let t=r(this,Ue).slice();r(this,Ue).length=0,t.forEach(e=>e(null,s));},Oe=new WeakMap,Fr),mn=class yn extends ht{constructor(e,i=xt,n,o,a,l,h){super(e,i,n,o,a,l,h);c(this,"sep","\\");c(this,"splitSep",ma);}newChild(e,i=xt,n={}){return new yn(e,i,this.root,this.roots,this.nocase,this.childrenCache(),n)}getRootString(e){return win32.parse(e).root}getRoot(e){if(e=ga(e.toUpperCase()),e===this.root.name)return this.root;for(let[i,n]of Object.entries(this.roots))if(this.sameRoot(e,i))return this.roots[e]=n;return this.roots[e]=new zi(e,this).root}sameRoot(e,i=this.root.name){return e=e.toUpperCase().replace(/\//g,"\\").replace(nn,"$1\\"),e===i}},wn=class bn extends ht{constructor(e,i=xt,n,o,a,l,h){super(e,i,n,o,a,l,h);c(this,"splitSep","/");c(this,"sep","/");}getRootString(e){return e.startsWith("/")?"/":""}getRoot(e){return this.root}newChild(e,i=xt,n={}){return new bn(e,i,this.root,this.roots,this.nocase,this.childrenCache(),n)}},Ge,Ve,As,Ts,Ir,vn=(Ir=class{constructor(s=process.cwd(),t,e,{nocase:i,childrenCacheSize:n=16*1024,fs:o=rs}={}){c(this,"root");c(this,"rootPath");c(this,"roots");c(this,"cwd");y(this,Ge);y(this,Ve);y(this,As);c(this,"nocase");y(this,Ts);p(this,Ts,rn(o)),(s instanceof URL||s.startsWith("file://"))&&(s=fileURLToPath(s));let a=t.resolve(s);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),p(this,Ge,new ar),p(this,Ve,new ar),p(this,As,new wa(n));let l=a.substring(this.rootPath.length).split(e);if(l.length===1&&!l[0]&&l.pop(),i===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=i,this.root=this.newRoot(r(this,Ts)),this.roots[this.rootPath]=this.root;let h=this.root,d=l.length-1,f=t.sep,u=this.rootPath,m=false;for(let w of l){let v=d--;h=h.child(w,{relative:new Array(v).fill("..").join(f),relativePosix:new Array(v).fill("..").join("/"),fullpath:u+=(m?"":f)+w}),m=true;}this.cwd=h;}depth(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.depth()}childrenCache(){return r(this,As)}resolve(...s){let t="";for(let n=s.length-1;n>=0;n--){let o=s[n];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=r(this,Ge).get(t);if(e!==void 0)return e;let i=this.cwd.resolve(t).fullpath();return r(this,Ge).set(t,i),i}resolvePosix(...s){let t="";for(let n=s.length-1;n>=0;n--){let o=s[n];if(!(!o||o===".")&&(t=t?`${o}/${t}`:o,this.isAbsolute(o)))break}let e=r(this,Ve).get(t);if(e!==void 0)return e;let i=this.cwd.resolve(t).fullpathPosix();return r(this,Ve).set(t,i),i}relative(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.relative()}relativePosix(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.relativePosix()}basename(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.name}dirname(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),(s.parent||s).fullpath()}async readdir(s=this.cwd,t={withFileTypes:true}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e}=t;if(s.canReaddir()){let i=await s.readdir();return e?i:i.map(n=>n.name)}else return []}readdirSync(s=this.cwd,t={withFileTypes:true}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true}=t;return s.canReaddir()?e?s.readdirSync():s.readdirSync().map(i=>i.name):[]}async lstat(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.lstat()}lstatSync(s=this.cwd){return typeof s=="string"&&(s=this.cwd.resolve(s)),s.lstatSync()}async readlink(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=await s.readlink();return t?e:e?.fullpath()}readlinkSync(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=s.readlinkSync();return t?e:e?.fullpath()}async realpath(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=await s.realpath();return t?e:e?.fullpath()}realpathSync(s=this.cwd,{withFileTypes:t}={withFileTypes:false}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s.withFileTypes,s=this.cwd);let e=s.realpathSync();return t?e:e?.fullpath()}async walk(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=[];(!n||n(s))&&a.push(e?s:s.fullpath());let l=new Set,h=(f,u)=>{l.add(f),f.readdirCB((m,w)=>{if(m)return u(m);let v=w.length;if(!v)return u();let S=()=>{--v===0&&u();};for(let k of w)(!n||n(k))&&a.push(e?k:k.fullpath()),i&&k.isSymbolicLink()?k.realpath().then(b=>b?.isUnknown()?b.lstat():b).then(b=>b?.shouldWalk(l,o)?h(b,S):S()):k.shouldWalk(l,o)?h(k,S):S();},true);},d=s;return new Promise((f,u)=>{h(d,m=>{if(m)return u(m);f(a);});})}walkSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=[];(!n||n(s))&&a.push(e?s:s.fullpath());let l=new Set([s]);for(let h of l){let d=h.readdirSync();for(let f of d){(!n||n(f))&&a.push(e?f:f.fullpath());let u=f;if(f.isSymbolicLink()){if(!(i&&(u=f.realpathSync())))continue;u.isUnknown()&&u.lstatSync();}u.shouldWalk(l,o)&&l.add(u);}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(s=this.cwd,t={}){return typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd),this.stream(s,t)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t;(!n||n(s))&&(yield e?s:s.fullpath());let a=new Set([s]);for(let l of a){let h=l.readdirSync();for(let d of h){(!n||n(d))&&(yield e?d:d.fullpath());let f=d;if(d.isSymbolicLink()){if(!(i&&(f=d.realpathSync())))continue;f.isUnknown()&&f.lstatSync();}f.shouldWalk(a,o)&&a.add(f);}}}stream(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=new ti({objectMode:true});(!n||n(s))&&a.write(e?s:s.fullpath());let l=new Set,h=[s],d=0,f=()=>{let u=false;for(;!u;){let m=h.shift();if(!m){d===0&&a.end();return}d++,l.add(m);let w=(S,k,b=false)=>{if(S)return a.emit("error",S);if(i&&!b){let R=[];for(let M of k)M.isSymbolicLink()&&R.push(M.realpath().then(E=>E?.isUnknown()?E.lstat():E));if(R.length){Promise.all(R).then(()=>w(null,k,true));return}}for(let R of k)R&&(!n||n(R))&&(a.write(e?R:R.fullpath())||(u=true));d--;for(let R of k){let M=R.realpathCached()||R;M.shouldWalk(l,o)&&h.push(M);}u&&!a.flowing?a.once("drain",f):v||f();},v=true;m.readdirCB(w,true),v=false;}};return f(),a}streamSync(s=this.cwd,t={}){typeof s=="string"?s=this.cwd.resolve(s):s instanceof ht||(t=s,s=this.cwd);let{withFileTypes:e=true,follow:i=false,filter:n,walkFilter:o}=t,a=new ti({objectMode:true}),l=new Set;(!n||n(s))&&a.write(e?s:s.fullpath());let h=[s],d=0,f=()=>{let u=false;for(;!u;){let m=h.shift();if(!m){d===0&&a.end();return}d++,l.add(m);let w=m.readdirSync();for(let v of w)(!n||n(v))&&(a.write(e?v:v.fullpath())||(u=true));d--;for(let v of w){let S=v;if(v.isSymbolicLink()){if(!(i&&(S=v.realpathSync())))continue;S.isUnknown()&&S.lstatSync();}S.shouldWalk(l,o)&&h.push(S);}}u&&!a.flowing&&a.once("drain",f);};return f(),a}chdir(s=this.cwd){let t=this.cwd;this.cwd=typeof s=="string"?this.cwd.resolve(s):s,this.cwd[un](t);}},Ge=new WeakMap,Ve=new WeakMap,As=new WeakMap,Ts=new WeakMap,Ir),zi=class extends vn{constructor(t=process.cwd(),e={}){let{nocase:i=true}=e;super(t,win32,"\\",{...e,nocase:i});c(this,"sep","\\");this.nocase=i;for(let n=this.cwd;n;n=n.parent)n.nocase=this.nocase;}parseRootPath(t){return win32.parse(t).root.toUpperCase()}newRoot(t){return new mn(this.rootPath,Wt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")||t.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(t)}},Ui=class extends vn{constructor(t=process.cwd(),e={}){let{nocase:i=false}=e;super(t,posix,"/",{...e,nocase:i});c(this,"sep","/");this.nocase=i;}parseRootPath(t){return "/"}newRoot(t){return new wn(this.rootPath,Wt,void 0,this.roots,this.nocase,this.childrenCache(),{fs:t})}isAbsolute(t){return t.startsWith("/")}},Sn=class extends Ui{constructor(s=process.cwd(),t={}){let{nocase:e=true}=t;super(s,{...t,nocase:e});}};process.platform==="win32"?mn:wn;var ba=process.platform==="win32"?zi:process.platform==="darwin"?Sn:Ui,va=s=>s.length>=1,Sa=s=>s.length>=1,xa=Symbol.for("nodejs.util.inspect.custom"),q,ct,J,Re,Dt,_s,ue,de,pe,qe,Je,xn=(Je=class{constructor(t,e,i,n){y(this,q);y(this,ct);y(this,J);c(this,"length");y(this,Re);y(this,Dt);y(this,_s);y(this,ue);y(this,de);y(this,pe);y(this,qe,true);if(!va(t))throw new TypeError("empty pattern list");if(!Sa(e))throw new TypeError("empty glob list");if(e.length!==t.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=t.length,i<0||i>=this.length)throw new TypeError("index out of range");if(p(this,q,t),p(this,ct,e),p(this,J,i),p(this,Re,n),r(this,J)===0){if(this.isUNC()){let[o,a,l,h,...d]=r(this,q),[f,u,m,w,...v]=r(this,ct);d[0]===""&&(d.shift(),v.shift());let S=[o,a,l,h,""].join("/"),k=[f,u,m,w,""].join("/");p(this,q,[S,...d]),p(this,ct,[k,...v]),this.length=r(this,q).length;}else if(this.isDrive()||this.isAbsolute()){let[o,...a]=r(this,q),[l,...h]=r(this,ct);a[0]===""&&(a.shift(),h.shift());let d=o+"/",f=l+"/";p(this,q,[d,...a]),p(this,ct,[f,...h]),this.length=r(this,q).length;}}}[xa](){return "Pattern <"+r(this,ct).slice(r(this,J)).join("/")+">"}pattern(){return r(this,q)[r(this,J)]}isString(){return typeof r(this,q)[r(this,J)]=="string"}isGlobstar(){return r(this,q)[r(this,J)]===at}isRegExp(){return r(this,q)[r(this,J)]instanceof RegExp}globString(){return p(this,_s,r(this,_s)||(r(this,J)===0?this.isAbsolute()?r(this,ct)[0]+r(this,ct).slice(1).join("/"):r(this,ct).join("/"):r(this,ct).slice(r(this,J)).join("/")))}hasMore(){return this.length>r(this,J)+1}rest(){return r(this,Dt)!==void 0?r(this,Dt):this.hasMore()?(p(this,Dt,new Je(r(this,q),r(this,ct),r(this,J)+1,r(this,Re))),p(r(this,Dt),pe,r(this,pe)),p(r(this,Dt),de,r(this,de)),p(r(this,Dt),ue,r(this,ue)),r(this,Dt)):p(this,Dt,null)}isUNC(){let t=r(this,q);return r(this,de)!==void 0?r(this,de):p(this,de,r(this,Re)==="win32"&&r(this,J)===0&&t[0]===""&&t[1]===""&&typeof t[2]=="string"&&!!t[2]&&typeof t[3]=="string"&&!!t[3])}isDrive(){let t=r(this,q);return r(this,ue)!==void 0?r(this,ue):p(this,ue,r(this,Re)==="win32"&&r(this,J)===0&&this.length>1&&typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]))}isAbsolute(){let t=r(this,q);return r(this,pe)!==void 0?r(this,pe):p(this,pe,t[0]===""&&t.length>1||this.isDrive()||this.isUNC())}root(){let t=r(this,q)[0];return typeof t=="string"&&this.isAbsolute()&&r(this,J)===0?t:""}checkFollowGlobstar(){return !(r(this,J)===0||!this.isGlobstar()||!r(this,qe))}markFollowGlobstar(){return r(this,J)===0||!this.isGlobstar()||!r(this,qe)?false:(p(this,qe,false),true)}},q=new WeakMap,ct=new WeakMap,J=new WeakMap,Re=new WeakMap,Dt=new WeakMap,_s=new WeakMap,ue=new WeakMap,de=new WeakMap,pe=new WeakMap,qe=new WeakMap,Je),ka=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",lr=class{constructor(s,{nobrace:t,nocase:e,noext:i,noglobstar:n,platform:o=ka}){c(this,"relative");c(this,"relativeChildren");c(this,"absolute");c(this,"absoluteChildren");c(this,"platform");c(this,"mmopts");this.relative=[],this.absolute=[],this.relativeChildren=[],this.absoluteChildren=[],this.platform=o,this.mmopts={dot:true,nobrace:t,nocase:e,noext:i,noglobstar:n,optimizationLevel:2,platform:o,nocomment:true,nonegate:true};for(let a of s)this.add(a);}add(s){let t=new ge(s,this.mmopts);for(let e=0;e<t.set.length;e++){let i=t.set[e],n=t.globParts[e];if(!i||!n)throw new Error("invalid pattern object");for(;i[0]==="."&&n[0]===".";)i.shift(),n.shift();let o=new xn(i,n,0,this.platform),a=new ge(o.globString(),this.mmopts),l=n[n.length-1]==="**",h=o.isAbsolute();h?this.absolute.push(a):this.relative.push(a),l&&(h?this.absoluteChildren.push(a):this.relativeChildren.push(a));}}ignored(s){let t=s.fullpath(),e=`${t}/`,i=s.relative()||".",n=`${i}/`;for(let o of this.relative)if(o.match(i)||o.match(n))return true;for(let o of this.absolute)if(o.match(t)||o.match(e))return true;return false}childrenIgnored(s){let t=s.fullpath()+"/",e=(s.relative()||".")+"/";for(let i of this.relativeChildren)if(i.match(e))return true;for(let i of this.absoluteChildren)if(i.match(t))return true;return false}},Ea=class kn{constructor(t=new Map){c(this,"store");this.store=t;}copy(){return new kn(new Map(this.store))}hasWalked(t,e){return this.store.get(t.fullpath())?.has(e.globString())}storeWalked(t,e){let i=t.fullpath(),n=this.store.get(i);n?n.add(e.globString()):this.store.set(i,new Set([e.globString()]));}},Ca=class{constructor(){c(this,"store",new Map);}add(s,t,e){let i=(t?2:0)|(e?1:0),n=this.store.get(s);this.store.set(s,n===void 0?i:i&n);}entries(){return [...this.store.entries()].map(([s,t])=>[s,!!(t&2),!!(t&1)])}},Oa=class{constructor(){c(this,"store",new Map);}add(s,t){if(!s.canReaddir())return;let e=this.store.get(s);e?e.find(i=>i.globString()===t.globString())||e.push(t):this.store.set(s,[t]);}get(s){let t=this.store.get(s);if(!t)throw new Error("attempting to walk unknown path");return t}entries(){return this.keys().map(s=>[s,this.store.get(s)])}keys(){return [...this.store.keys()].filter(s=>s.canReaddir())}},hr=class En{constructor(t,e){c(this,"hasWalkedCache");c(this,"matches",new Ca);c(this,"subwalks",new Oa);c(this,"patterns");c(this,"follow");c(this,"dot");c(this,"opts");this.opts=t,this.follow=!!t.follow,this.dot=!!t.dot,this.hasWalkedCache=e?e.copy():new Ea;}processPatterns(t,e){this.patterns=e;let i=e.map(n=>[t,n]);for(let[n,o]of i){this.hasWalkedCache.storeWalked(n,o);let a=o.root(),l=o.isAbsolute()&&this.opts.absolute!==false;if(a){n=n.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let u=o.rest();if(u)o=u;else {this.matches.add(n,true,false);continue}}if(n.isENOENT())continue;let h,d,f=false;for(;typeof(h=o.pattern())=="string"&&(d=o.rest());)n=n.resolve(h),o=d,f=true;if(h=o.pattern(),d=o.rest(),f){if(this.hasWalkedCache.hasWalked(n,o))continue;this.hasWalkedCache.storeWalked(n,o);}if(typeof h=="string"){let u=h===".."||h===""||h===".";this.matches.add(n.resolve(h),l,u);continue}else if(h===at){(!n.isSymbolicLink()||this.follow||o.checkFollowGlobstar())&&this.subwalks.add(n,o);let u=d?.pattern(),m=d?.rest();if(!d||(u===""||u===".")&&!m)this.matches.add(n,l,u===""||u===".");else if(u===".."){let w=n.parent||n;m?this.hasWalkedCache.hasWalked(w,m)||this.subwalks.add(w,m):this.matches.add(w,l,true);}}else h instanceof RegExp&&this.subwalks.add(n,o);}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new En(this.opts,this.hasWalkedCache)}filterEntries(t,e){let i=this.subwalks.get(t),n=this.child();for(let o of e)for(let a of i){let l=a.isAbsolute(),h=a.pattern(),d=a.rest();h===at?n.testGlobstar(o,a,d,l):h instanceof RegExp?n.testRegExp(o,h,d,l):n.testString(o,h,d,l);}return n}testGlobstar(t,e,i,n){if((this.dot||!t.name.startsWith("."))&&(e.hasMore()||this.matches.add(t,n,false),t.canReaddir()&&(this.follow||!t.isSymbolicLink()?this.subwalks.add(t,e):t.isSymbolicLink()&&(i&&e.checkFollowGlobstar()?this.subwalks.add(t,i):e.markFollowGlobstar()&&this.subwalks.add(t,e)))),i){let o=i.pattern();if(typeof o=="string"&&o!==".."&&o!==""&&o!==".")this.testString(t,o,i.rest(),n);else if(o===".."){let a=t.parent||t;this.subwalks.add(a,i);}else o instanceof RegExp&&this.testRegExp(t,o,i.rest(),n);}}testRegExp(t,e,i,n){e.test(t.name)&&(i?this.subwalks.add(t,i):this.matches.add(t,n,false));}testString(t,e,i,n){t.isNamed(e)&&(i?this.subwalks.add(t,i):this.matches.add(t,n,false));}},Ra=(s,t)=>typeof s=="string"?new lr([s],t):Array.isArray(s)?new lr(s,t):s,He,Qt,Me,kt,we,Ni,Dr,Cn=(Dr=class{constructor(s,t,e){y(this,kt);c(this,"path");c(this,"patterns");c(this,"opts");c(this,"seen",new Set);c(this,"paused",false);c(this,"aborted",false);y(this,He,[]);y(this,Qt);y(this,Me);c(this,"signal");c(this,"maxDepth");c(this,"includeChildMatches");if(this.patterns=s,this.path=t,this.opts=e,p(this,Me,!e.posix&&e.platform==="win32"?"\\":"/"),this.includeChildMatches=e.includeChildMatches!==false,(e.ignore||!this.includeChildMatches)&&(p(this,Qt,Ra(e.ignore??[],e)),!this.includeChildMatches&&typeof r(this,Qt).add!="function")){let i="cannot ignore child matches, ignore lacks add() method.";throw new Error(i)}this.maxDepth=e.maxDepth||1/0,e.signal&&(this.signal=e.signal,this.signal.addEventListener("abort",()=>{r(this,He).length=0;}));}pause(){this.paused=true;}resume(){if(this.signal?.aborted)return;this.paused=false;let s;for(;!this.paused&&(s=r(this,He).shift());)s();}onResume(s){this.signal?.aborted||(this.paused?r(this,He).push(s):s());}async matchCheck(s,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=s.realpathCached()||await s.realpath(),!e)return;s=e;}let i=s.isUnknown()||this.opts.stat?await s.lstat():s;if(this.opts.follow&&this.opts.nodir&&i?.isSymbolicLink()){let n=await i.realpath();n&&(n.isUnknown()||this.opts.stat)&&await n.lstat();}return this.matchCheckTest(i,t)}matchCheckTest(s,t){return s&&(this.maxDepth===1/0||s.depth()<=this.maxDepth)&&(!t||s.canReaddir())&&(!this.opts.nodir||!s.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!s.isSymbolicLink()||!s.realpathCached()?.isDirectory())&&!g(this,kt,we).call(this,s)?s:void 0}matchCheckSync(s,t){if(t&&this.opts.nodir)return;let e;if(this.opts.realpath){if(e=s.realpathCached()||s.realpathSync(),!e)return;s=e;}let i=s.isUnknown()||this.opts.stat?s.lstatSync():s;if(this.opts.follow&&this.opts.nodir&&i?.isSymbolicLink()){let n=i.realpathSync();n&&(n?.isUnknown()||this.opts.stat)&&n.lstatSync();}return this.matchCheckTest(i,t)}matchFinish(s,t){if(g(this,kt,we).call(this,s))return;if(!this.includeChildMatches&&r(this,Qt)?.add){let n=`${s.relativePosix()}/**`;r(this,Qt).add(n);}let e=this.opts.absolute===void 0?t:this.opts.absolute;this.seen.add(s);let i=this.opts.mark&&s.isDirectory()?r(this,Me):"";if(this.opts.withFileTypes)this.matchEmit(s);else if(e){let n=this.opts.posix?s.fullpathPosix():s.fullpath();this.matchEmit(n+i);}else {let n=this.opts.posix?s.relativePosix():s.relative(),o=this.opts.dotRelative&&!n.startsWith(".."+r(this,Me))?"."+r(this,Me):"";this.matchEmit(n?o+n+i:"."+i);}}async match(s,t,e){let i=await this.matchCheck(s,e);i&&this.matchFinish(i,t);}matchSync(s,t,e){let i=this.matchCheckSync(s,e);i&&this.matchFinish(i,t);}walkCB(s,t,e){this.signal?.aborted&&e(),this.walkCB2(s,t,new hr(this.opts),e);}walkCB2(s,t,e,i){if(g(this,kt,Ni).call(this,s))return i();if(this.signal?.aborted&&i(),this.paused){this.onResume(()=>this.walkCB2(s,t,e,i));return}e.processPatterns(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())g(this,kt,we).call(this,a)||(n++,this.match(a,l,h).then(()=>o()));for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;n++;let l=a.readdirCached();a.calledReaddir()?this.walkCB3(a,l,e,o):a.readdirCB((h,d)=>this.walkCB3(a,d,e,o),true);}o();}walkCB3(s,t,e,i){e=e.filterEntries(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())g(this,kt,we).call(this,a)||(n++,this.match(a,l,h).then(()=>o()));for(let[a,l]of e.subwalks.entries())n++,this.walkCB2(a,l,e.child(),o);o();}walkCBSync(s,t,e){this.signal?.aborted&&e(),this.walkCB2Sync(s,t,new hr(this.opts),e);}walkCB2Sync(s,t,e,i){if(g(this,kt,Ni).call(this,s))return i();if(this.signal?.aborted&&i(),this.paused){this.onResume(()=>this.walkCB2Sync(s,t,e,i));return}e.processPatterns(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())g(this,kt,we).call(this,a)||this.matchSync(a,l,h);for(let a of e.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;n++;let l=a.readdirSync();this.walkCB3Sync(a,l,e,o);}o();}walkCB3Sync(s,t,e,i){e=e.filterEntries(s,t);let n=1,o=()=>{--n===0&&i();};for(let[a,l,h]of e.matches.entries())g(this,kt,we).call(this,a)||this.matchSync(a,l,h);for(let[a,l]of e.subwalks.entries())n++,this.walkCB2Sync(a,l,e.child(),o);o();}},He=new WeakMap,Qt=new WeakMap,Me=new WeakMap,kt=new WeakSet,we=function(s){return this.seen.has(s)||!!r(this,Qt)?.ignored?.(s)},Ni=function(s){return !!r(this,Qt)?.childrenIgnored?.(s)},Dr),cr=class extends Cn{constructor(t,e,i){super(t,e,i);c(this,"matches",new Set);}matchEmit(t){this.matches.add(t);}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((t,e)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?e(this.signal.reason):t(this.matches);});}),this.matches}walkSync(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>{if(this.signal?.aborted)throw this.signal.reason}),this.matches}},ur=class extends Cn{constructor(t,e,i){super(t,e,i);c(this,"results");this.results=new ti({signal:this.signal,objectMode:true}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume());}matchEmit(t){this.results.write(t),this.results.flowing||this.pause();}stream(){let t=this.path;return t.isUnknown()?t.lstat().then(()=>{this.walkCB(t,this.patterns,()=>this.results.end());}):this.walkCB(t,this.patterns,()=>this.results.end()),this.results}streamSync(){return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>this.results.end()),this.results}},Ma=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",Ae=class{constructor(s,t){c(this,"absolute");c(this,"cwd");c(this,"root");c(this,"dot");c(this,"dotRelative");c(this,"follow");c(this,"ignore");c(this,"magicalBraces");c(this,"mark");c(this,"matchBase");c(this,"maxDepth");c(this,"nobrace");c(this,"nocase");c(this,"nodir");c(this,"noext");c(this,"noglobstar");c(this,"pattern");c(this,"platform");c(this,"realpath");c(this,"scurry");c(this,"stat");c(this,"signal");c(this,"windowsPathsNoEscape");c(this,"withFileTypes");c(this,"includeChildMatches");c(this,"opts");c(this,"patterns");if(!t)throw new TypeError("glob options required");if(this.withFileTypes=!!t.withFileTypes,this.signal=t.signal,this.follow=!!t.follow,this.dot=!!t.dot,this.dotRelative=!!t.dotRelative,this.nodir=!!t.nodir,this.mark=!!t.mark,t.cwd?(t.cwd instanceof URL||t.cwd.startsWith("file://"))&&(t.cwd=fileURLToPath(t.cwd)):this.cwd="",this.cwd=t.cwd||"",this.root=t.root,this.magicalBraces=!!t.magicalBraces,this.nobrace=!!t.nobrace,this.noext=!!t.noext,this.realpath=!!t.realpath,this.absolute=t.absolute,this.includeChildMatches=t.includeChildMatches!==false,this.noglobstar=!!t.noglobstar,this.matchBase=!!t.matchBase,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:1/0,this.stat=!!t.stat,this.ignore=t.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");if(typeof s=="string"&&(s=[s]),this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===false,this.windowsPathsNoEscape&&(s=s.map(l=>l.replace(/\\/g,"/"))),this.matchBase){if(t.noglobstar)throw new TypeError("base matching requires globstar");s=s.map(l=>l.includes("/")?l:`./**/${l}`);}if(this.pattern=s,this.platform=t.platform||Ma,this.opts={...t,platform:this.platform},t.scurry){if(this.scurry=t.scurry,t.nocase!==void 0&&t.nocase!==t.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else {let l=t.platform==="win32"?zi:t.platform==="darwin"?Sn:t.platform?Ui:ba;this.scurry=new l(this.cwd,{nocase:t.nocase,fs:t.fs});}this.nocase=this.scurry.nocase;let e=this.platform==="darwin"||this.platform==="win32",i={braceExpandMax:1e4,...t,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:e,nocomment:true,noext:this.noext,nonegate:true,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape,debug:!!this.opts.debug},n=this.pattern.map(l=>new ge(l,i)),[o,a]=n.reduce((l,h)=>(l[0].push(...h.set),l[1].push(...h.globParts),l),[[],[]]);this.patterns=o.map((l,h)=>{let d=a[h];if(!d)throw new Error("invalid pattern object");return new xn(l,d,0,this.platform)});}async walk(){return [...await new cr(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 cr(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 ur(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 ur(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()}},La=(s,t={})=>{Array.isArray(s)||(s=[s]);for(let e of s)if(new ge(e,t).hasMagic())return true;return false};function ii(s,t={}){return new Ae(s,t).streamSync()}function On(s,t={}){return new Ae(s,t).stream()}function Rn(s,t={}){return new Ae(s,t).walkSync()}async function dr(s,t={}){return new Ae(s,t).walk()}function ri(s,t={}){return new Ae(s,t).iterateSync()}function Mn(s,t={}){return new Ae(s,t).iterate()}var Aa=ii,Ta=Object.assign(On,{sync:ii}),_a=ri,Pa=Object.assign(Mn,{sync:ri}),Fa=Object.assign(Rn,{stream:ii,iterate:ri}),ei=Object.assign(dr,{glob:dr,globSync:Rn,sync:Fa,globStream:On,stream:Ta,globStreamSync:ii,streamSync:Aa,globIterate:Mn,iterate:Pa,globIterateSync:ri,iterateSync:_a,Glob:Ae,hasMagic:La,escape:qr,unescape:Ie});ei.glob=ei;var Nt;(I=>{I.Level=Da.enum(["DEBUG","INFO","WARN","ERROR"]).meta({ref:"LogLevel",description:"Log level"});let t={DEBUG:0,INFO:1,WARN:2,ERROR:3},e="INFO";function i(C){return t[C]>=t[e]}function n(){return e}I.getLevel=n;let o=new Map;I.Default=F({service:"default"});let l="";function h(){return l}I.file=h;let d,f,u=false,m=false,w=C=>{try{m&&process.stderr.write(C);}catch{}},v=false,S=false;async function k(C){if(u)return;if(C.level&&(e=C.level),C.print&&(m=C.print??false),C.print){u=true;return}let P=C.logDir||ni.join(process.env.EASBOT_LOG_PATH??process.cwd(),"logs");C.logFile?l=ni.join(P,C.logFile??"ollama-sdk.log"):l=ni.join(P,"ollama-sdk.log");try{await Ln.mkdir(P,{recursive:!0}),d=await Ln.open(l,"a"),f=createWriteStream("",{fd:d.fd,autoClose:!1}),w=A=>{if(!(v||S||!f||f.destroyed))try{if(!f.writable)return;f.write(A,D=>{if(D&&!v){let _=D;if(_.code==="EPIPE"||_.code==="EIO"){S=!0,f?.destroy();return}v=!0,setTimeout(()=>{v=!1;},1e3);}});}catch(D){let _=D;if(_.code==="EPIPE"||_.code==="EIO"){S=!0,f?.destroy();return}v||(v=!0,setTimeout(()=>{v=!1;},1e3));}},u=!0;}catch{w=A=>{try{process.stderr.write(A);}catch{}},u=true;}}I.init=k;async function b(){u&&(f&&!f.destroyed&&(await new Promise((C,P)=>{f.end(A=>{A?P(A):C();});}).catch(()=>{}),f=void 0),d&&(await d.close().catch(()=>{}),d=void 0),w=C=>{try{process.stderr.write(C);}catch{}},u=false);}I.close=b;function M(C,P=0){let A=C.message;return C.cause instanceof Error&&P<10?A+" Caused by: "+M(C.cause,P+1):A}let E=Date.now();function F(C){C=C||{};let P=C.service;if(P&&typeof P=="string"){let _=o.get(P);if(_)return _}function A(_,N){let Te=Object.entries({...C,...N}).filter(([Bi,te])=>te!=null).map(([Bi,te])=>{let ci=`${Bi}=`;return te instanceof Error?ci+M(te):typeof te=="object"?ci+JSON.stringify(te):ci+te}).join(" "),Ct=new Date,Fn=Ct.getTime()-E;return E=Ct.getTime(),[formatLogTime(Ct),"+"+Fn+"ms",Te,_].filter(Boolean).join(" ")+`
5
+ `}let D={debug(_,N){i("DEBUG")&&w("DEBUG "+A(_,N));},info(_,N){i("INFO")&&w("INFO "+A(_,N));},error(_,N){i("ERROR")&&w("ERROR "+A(_,N));},warn(_,N){i("WARN")&&w("WARN "+A(_,N));},tag(_,N){return C&&(C[_]=N),D},clone(){return I.create({...C})},time(_,N){let Te=Date.now();D.info(_,{status:"started",...N});function Ct(){D.info(_,{status:"completed",duration:Date.now()-Te,...N});}return {stop:Ct,[Symbol.dispose](){Ct();}}}};return P&&typeof P=="string"&&o.set(P,D),D}I.create=F;})(Nt||(Nt={}));function An(s,t,e){let i;return t?i="tool-calls":s?i="stop":i="other",{unified:i,raw:e}}var Et=Nt.create({service:"ollama-sdk",module:"native-language-model"});function oi(){return `${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ai(s){if(!s||s.trim().length===0)return false;try{return JSON.parse(s),!0}catch{return false}}function Tn(s){return typeof s=="string"?s:JSON.stringify(s)}function _n(s){return !s.tools||s.tools.length===0?{}:{tools:s.tools.map(t=>{if(!t.name)throw new Ze(t.name||"unknown","name");let e=t.inputSchema||t.parameters;if(!e)throw new Ze(t.name,"inputSchema");return {type:"function",function:{name:t.name,description:t.description,parameters:e}}})}}function Pn(s){let t=[];for(let e of s)try{switch(e.role){case "system":t.push({role:"system",content:e.content});break;case "user":{let i=e.content.filter(n=>n.type==="text").map(n=>n.text).join(`
6
+ `);i&&t.push({role:"user",content:i});break}case "assistant":{let i="",n=[];for(let o of e.content)if(o.type==="text")i+=o.text;else if(o.type==="tool-call"){let a=o;n.push({id:a.toolCallId,type:"function",function:{name:a.toolName,arguments:JSON.stringify(a.input)}});}t.push({role:"assistant",content:i||null,tool_calls:n.length>0?n:void 0});break}case "tool":for(let i of e.content){let n=i.output,o;switch(n.type){case "text":case "error-text":o=n.value;break;case "content":case "json":case "error-json":o=JSON.stringify(n.value);break;default:o=String(n.value);break}t.push({role:"tool",tool_call_id:i.toolCallId,content:o});}break}}catch(i){Et.warn("Failed to convert message",{messageRole:e.role,error:i instanceof Error?i.message:String(i)});}return t}var li=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"client");this.modelId=t,this.client=new Is(e.baseURL);}async generate(t){return this.doGenerate(t)}async stream(t){return this.doStream(t)}async doStream(t){let e=oi();Et.debug("Stream request started",{traceId:e,modelId:this.modelId,hasTools:!!t.tools&&t.tools.length>0,toolCount:t.tools?.length||0,messageCount:t.prompt.length});let i=Pn(t.prompt),n=_n({tools:t.tools}),o=JSON.stringify({model:this.modelId,messages:i,options:_e,...n}),a=null,l=null,h=w=>{a&&a.enqueue(w),l&&l.enqueue(w);},d=async()=>{try{let w=!0,v=!1,S=!1,k="",b="",R=!1,M=[],E=[],F=()=>{if(E.length>0){for(let C of E)h(C);E.length=0;}},I=null;for await(let C of this.client.streamChat({model:this.modelId,messages:i,options:_e,...n})){if(I&&I.chunkCount++,w){w=!1;let P={type:"response-metadata",id:oi(),modelId:this.modelId,timestamp:new Date(C.created_at)};h(P),I&&I.eventCount++;}if(C.message?.tool_calls){S&&(E.push({type:"reasoning-end",id:"reasoning-0"}),S=!1),v&&(E.push({type:"text-end",id:"txt-0"}),v=!1);for(let P of C.message.tool_calls){if(!P.id||!P.function?.name){let Ct=P.id?"function.name":"id";Et.error("Invalid tool call: missing field",{traceId:e,missingField:Ct,toolCall:void 0}),E.push({type:"error",error:`Invalid tool call: missing ${Ct}`});continue}let A=P.id,D=P.function.name,_=Tn(P.function.arguments),N=M.find(Ct=>Ct.id===A);N?(N.function.arguments+=_,Et.debug("Tool call arguments accumulated",{traceId:e,toolCallId:A,toolName:D,deltaLength:_.length,totalLength:N.function.arguments.length,isComplete:ai(N.function.arguments)}),_&&E.push({type:"tool-input-delta",id:A,delta:_})):(N={id:A,type:"function",function:{name:D,arguments:_},hasFinished:!1},M.push(N),I&&I.toolCallCount++,Et.debug("Tool call received",{traceId:e,toolCallId:A,toolName:D,argumentsLength:_.length,isComplete:ai(_)}),E.push({type:"tool-input-start",id:A,toolName:D}),_&&E.push({type:"tool-input-delta",id:A,delta:_}));let Te=ai(N.function.arguments);!N.hasFinished&&Te&&(Et.debug("Tool call arguments complete",{traceId:e,toolCallId:A,toolName:D,isComplete:Te,argumentsLength:N.function.arguments.length}),E.push({type:"tool-input-end",id:A}),E.push({type:"tool-call",toolCallId:A,toolName:D,input:N.function.arguments}),N.hasFinished=!0);}F(),I&&(I.eventCount+=E.length);}if(C.message?.content){let P=C.message.content;for(b+=P;b.length>0;)if(R){let A=b.indexOf("</think>");if(A===-1){b.length>0&&E.push({type:"reasoning-delta",id:"reasoning-0",delta:b}),b="";break}else {if(A>0){let D=b.substring(0,A);E.push({type:"reasoning-delta",id:"reasoning-0",delta:D});}E.push({type:"reasoning-end",id:"reasoning-0"}),S=!1,R=!1,b=b.substring(A+8);}}else {let A=b.indexOf("<think>");if(A===-1){b.length>0&&(v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:b}),k+=b),b="";break}else {if(A>0){let D=b.substring(0,A);v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:D}),k+=D,E.push({type:"text-end",id:"txt-0"}),v=!1;}R=!0,b=b.substring(A+7),S||(S=!0,E.push({type:"reasoning-start",id:"reasoning-0"}));}}}if(F(),I&&(I.eventCount+=E.length),C.done){let P=M.filter(_=>!_.hasFinished);for(let _ of P)E.push({type:"tool-input-end",id:_.id}),E.push({type:"tool-call",toolCallId:_.id,toolName:_.function.name,input:_.function.arguments});b.length>0&&(R?(E.push({type:"reasoning-delta",id:"reasoning-0",delta:b}),E.push({type:"reasoning-end",id:"reasoning-0"})):(v||(v=!0,E.push({type:"text-start",id:"txt-0"})),E.push({type:"text-delta",id:"txt-0",delta:b}),k+=b)),v&&E.push({type:"text-end",id:"txt-0"});let D=M.length>0?"tool-calls":"stop";if(E.push({type:"finish",finishReason:D,usage:{inputTokens:{total:C.prompt_eval_count||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:C.eval_count||0,text:void 0,reasoning:void 0}},providerMetadata:{ollama:{totalDuration:C.total_duration||0,loadDuration:C.load_duration||0,promptEvalDuration:C.prompt_eval_duration||0,evalDuration:C.eval_duration||0}}}),F(),I&&(I.eventCount+=E.length),I);M.length=0;}}}catch(w){Et.error("Stream processing error",{traceId:e,error:w instanceof Error?w.message:String(w),stack:void 0}),h({type:"error",error:w instanceof Error?w.message:String(w)}),h({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(),l&&l.close();}},f=new ReadableStream({start(w){a=w;}}),u=new ReadableStream({start(w){l=w;}});d();async function*m(w){let v=w.getReader();try{for(;;){let{done:S,value:k}=await v.read();if(S)break;yield k;}}finally{v.releaseLock();}}return {stream:f,fullStream:m(u),request:{body:o},response:{}}}async doGenerate(t){let e=oi();Et.debug("Generate request started",{traceId:e,modelId:this.modelId,hasTools:!!t.tools&&t.tools.length>0,toolCount:t.tools?.length||0,messageCount:t.prompt.length});let i=Pn(t.prompt),n=_n({tools:t.tools}),o=await this.client.chat({model:this.modelId,messages:i,options:_e,...n}),a=[];if(o.message?.content&&a.push({type:"text",text:o.message.content}),o.message?.tool_calls){Et.debug("Tool calls received in generate",{traceId:e,toolCallCount:o.message.tool_calls.length});for(let d of o.message.tool_calls){let f=d.id||oi(),u=d.function.name,m=Tn(d.function.arguments);Et.debug("Processing tool call in generate",{traceId:e,toolCallId:f,toolName:u,argumentsLength:m.length,isComplete:ai(m)}),a.push({type:"tool-call",toolCallId:f,toolName:u,input:m});}}let l=!!(o.message?.tool_calls&&o.message.tool_calls.length>0),h=An(o.done??false,l,"stop");return Et.debug("Generate request completed",{traceId:e,finishReason:h,contentParts:a.length,hasToolCalls:l,inputTokens:o.prompt_eval_count||0,outputTokens:o.eval_count||0}),{content:a,finishReason:h,usage:{inputTokens:{total:o.prompt_eval_count||0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:o.eval_count||0,text:void 0,reasoning:void 0}},providerMetadata:{ollama:{totalDuration:o.total_duration||0,loadDuration:o.load_duration||0,promptEvalDuration:o.prompt_eval_duration||0,evalDuration:o.eval_duration||0}},request:{body:JSON.stringify({model:this.modelId,messages:i,options:_e,...n})},response:{}}}};var Xt=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"defaultObjectGenerationMode","json");c(this,"supportedUrls",{});c(this,"nativeModel");this.modelId=t,this.nativeModel=new li(t,{baseURL:e.baseURL||"http://localhost:11434"});}doGenerate(t){return this.nativeModel.doGenerate(t)}doStream(t){return this.nativeModel.doStream(t)}async generate(t){return this.nativeModel.generate(t)}async stream(t){return this.nativeModel.stream(t)}};var Ps=class{constructor(t,e={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"maxEmbeddingsPerCall");c(this,"supportsParallelCalls",true);c(this,"baseURL");this.modelId=t,this.baseURL=e.baseURL||"http://localhost:11434";}async doEmbed(t){let{values:e,abortSignal:i}=t,n=Nt.create({service:"ollama-embedding"});if(!e||e.length===0)return n.warn("Empty values array provided",{modelId:this.modelId}),{embeddings:[],usage:{tokens:0},warnings:[]};n.debug("Generating text embeddings",{modelId:this.modelId,valuesCount:e.length,baseURL:this.baseURL});try{let o=await Promise.all(e.map(l=>this.generateSingleEmbedding(l,i))),a=e.reduce((l,h)=>l+this.estimateTokens(h),0);return n.debug("Text embeddings generated successfully",{modelId:this.modelId,embeddingsCount:o.length,totalTokens:a}),{embeddings:o,usage:{tokens:a},warnings:[]}}catch(o){throw n.error("Text embedding generation failed",{modelId:this.modelId,error:o instanceof Error?o.message:String(o),stack:void 0}),o}}async generateSingleEmbedding(t,e){let i=`${this.baseURL}/api/embeddings`;try{let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:this.modelId,prompt:t}),signal:e});if(!n.ok){let a=await n.text();throw new Error(`Ollama embedding API error (${n.status}): ${a}`)}let o=await n.json();if(!o.embedding||!Array.isArray(o.embedding))throw new Error("Invalid response format from Ollama embedding API");return o.embedding}catch(n){throw n instanceof TypeError&&n.message.includes("fetch")?new Error(`Failed to connect to Ollama server at ${this.baseURL}: ${n.message}`):n}}estimateTokens(t){let e=t.match(/[a-zA-Z]/g)?.length||0,i=t.match(/[\u4e00-\u9fa5]/g)?.length||0,n=t.length-e-i;return Math.ceil(e/4)+i+Math.ceil(n*.5)}};var hi=class{constructor(t,e,i={}){c(this,"specificationVersion","v3");c(this,"provider","ollama");c(this,"modelId");c(this,"languageModel");c(this,"options");c(this,"log",Nt.create({service:"ollama-sdk",module:"reranking-model"}));this.modelId=t,this.languageModel=new Xt(t,e),this.options={totalScore:i.totalScore??1,useEnhancedPrompt:i.useEnhancedPrompt??true,promptLanguage:i.promptLanguage??"en"},this.log.debug("OllamaRerankingModel created",{modelId:t,totalScore:this.options.totalScore,useEnhancedPrompt:this.options.useEnhancedPrompt,promptLanguage:this.options.promptLanguage});}async doRerank(t){let{query:e,documents:i,topN:n}=t,o;Array.isArray(i)?o=i:i.type==="text"?o=i.values.map((h,d)=>({content:h,id:`doc_${d+1}`})):o=i.values;let a=n??o.length;if(o.length===0)return {ranking:[],warnings:[]};try{let h=this.buildRerankPrompt(e,o),f=(await this.languageModel.doGenerate({prompt:[{role:"user",content:[{type:"text",text:h}]}],maxOutputTokens:500,temperature:.1})).content.find(m=>m.type==="text")?.text||"",u=this.parseRerankResult(f,o,a);return {ranking:u.results.map(m=>({index:m.index,relevanceScore:m.score,document:m.document})),warnings:u.warnings.map(m=>({type:"other",message:m}))}}catch(h){return this.log.error("Reranking failed",{error:h.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: ${h.message}`}]}}}buildRerankPrompt(t,e){let i=e.map((n,o)=>{let a=n.id||`doc_${o+1}`,l=n.content.slice(0,300);return `${o+1}. [ID: ${a}] ${l}`}).join(`
7
7
 
8
8
  `);if(this.options.promptLanguage==="en")return `You are a professional information retrieval reranking expert. Please rank the following documents according to the query.
9
9
 
@@ -44,5 +44,5 @@ ${i}
44
44
 
45
45
  \u793A\u4F8B\u8F93\u51FA\u683C\u5F0F\uFF1A2,5,1,4,3
46
46
 
47
- \u8BF7\u53EA\u8F93\u51FA\u6392\u5E8F\u540E\u7684\u7F16\u53F7\uFF0C\u4E0D\u8981\u5305\u542B\u5176\u4ED6\u89E3\u91CA\u3002`}}parseRerankResult(t,e,i){let n=[];try{let o=t.match(/\d+/g)?.map(u=>parseInt(u,10)-1).filter(u=>u>=0&&u<e.length)||[],a=[],l=new Set;for(let u of o)l.has(u)||(l.add(u),a.push(u));let h=[];for(let u=0;u<a.length;u++){let g=a[u];if(g!==void 0&&g>=0&&g<e.length){let w=e[g];w&&h.push({index:g,score:this.options.totalScore*(1-u/a.length),document:w});}}let d=new Set(a);for(let u=0;u<e.length;u++)if(!d.has(u)){let g=this.options.totalScore*.1*(1-u/e.length);h.push({index:u,score:g,document:e[u]});}let f=i?h.slice(0,i):h;return this.log.debug("Parsed rerank results",{extractedNumbers:o,uniqueIndices:a,resultCount:f.length,topK:i}),{results:f,warnings:n}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:t}),{results:e.map((l,h)=>({index:h,score:this.options.totalScore*(1-h/e.length),document:l})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};function ja(s={}){if(s.logDir){let e=s.logLevel??"INFO",i=ni.join(s.logDir,"ollama-sdk.log");Dt.init({print:process.argv.includes("--print-logs"),logDir:s.logDir,level:e,logFile:"ollama-sdk.log"}).then(()=>{Dt.create({service:"ollama-sdk",module:"provider"}).debug("Ollama provider created",{baseURL:s.baseURL||"http://localhost:11434",logFile:i,logLevel:e});});}return Object.assign(e=>new Xt(e,s),{languageModel:e=>new Xt(e,s),chat:e=>new Xt(e,s),embeddingModel:e=>new Ps(e,s),rerankingModel:(e,i)=>new hi(e,s,i)})}var Wa="0.1.0";
48
- export{di as ConnectionError,pi as ModelNotFoundError,_e as OLLAMA_DEFAULT_OPTIONS,Dn as OLLAMA_SPECIFIC_PARAMS,Ps as OllamaEmbeddingModel,ee as OllamaError,Xt as OllamaLanguageModel,gi as TimeoutError,Wa as VERSION,fi as ValidationError,ja as createOllama};
47
+ \u8BF7\u53EA\u8F93\u51FA\u6392\u5E8F\u540E\u7684\u7F16\u53F7\uFF0C\u4E0D\u8981\u5305\u542B\u5176\u4ED6\u89E3\u91CA\u3002`}}parseRerankResult(t,e,i){let n=[];try{let o=t.match(/\d+/g)?.map(u=>parseInt(u,10)-1).filter(u=>u>=0&&u<e.length)||[],a=[],l=new Set;for(let u of o)l.has(u)||(l.add(u),a.push(u));let h=[];for(let u=0;u<a.length;u++){let m=a[u];if(m!==void 0&&m>=0&&m<e.length){let w=e[m];w&&h.push({index:m,score:this.options.totalScore*(1-u/a.length),document:w});}}let d=new Set(a);for(let u=0;u<e.length;u++)if(!d.has(u)){let m=this.options.totalScore*.1*(1-u/e.length);h.push({index:u,score:m,document:e[u]});}let f=i?h.slice(0,i):h;return this.log.debug("Parsed rerank results",{extractedNumbers:o,uniqueIndices:a,resultCount:f.length,topK:i}),{results:f,warnings:n}}catch(o){return this.log.error("Failed to parse rerank result",{error:o.message,text:t}),{results:e.map((l,h)=>({index:h,score:this.options.totalScore*(1-h/e.length),document:l})),warnings:[`Failed to parse rerank result: ${o.message}`]}}}};function Wa(s={}){if(s.logDir){let e=s.logLevel??"INFO",i=ni.join(s.logDir,"ollama-sdk.log");Nt.init({print:process.argv.includes("--print-logs"),logDir:s.logDir,level:e,logFile:"ollama-sdk.log"}).then(()=>{Nt.create({service:"ollama-sdk",module:"provider"}).debug("Ollama provider created",{baseURL:s.baseURL||"http://localhost:11434",logFile:i,logLevel:e});});}return Object.assign(e=>new Xt(e,s),{languageModel:e=>new Xt(e,s),chat:e=>new Xt(e,s),embeddingModel:e=>new Ps(e,s),rerankingModel:(e,i)=>new hi(e,s,i)})}var $a="0.1.0";
48
+ export{di as ConnectionError,pi as ModelNotFoundError,_e as OLLAMA_DEFAULT_OPTIONS,Nn as OLLAMA_SPECIFIC_PARAMS,Ps as OllamaEmbeddingModel,ee as OllamaError,Xt as OllamaLanguageModel,gi as TimeoutError,$a as VERSION,fi as ValidationError,Wa as createOllama};