pipane 0.1.3 → 0.1.5
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/client/assets/index-BtDAXAo1.css +1 -0
- package/dist/client/assets/{index-D16nGmo3.js → index-CAQqlK61.js} +1 -1
- package/dist/client/assets/{index-Bf_69wyB.js → index-CJEeBmBj.js} +1 -1
- package/dist/client/assets/{index-CekVLaL6.js → index-DUEhKmPQ.js} +1 -1
- package/dist/client/assets/{index-Cp2vV6HJ.js → index-XEVKscP-.js} +77 -67
- package/dist/client/assets/{index-D14II7Hd.js → index-woI4agCy.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/server/process-pool.js +18 -1
- package/dist/server/server/ws-handler.js +143 -77
- package/dist/server/shared/jsonl-sync.js +73 -3
- package/package.json +1 -1
- package/dist/client/assets/index-CUE9pgq9.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{g as KA,c as ut,t as Dt,a as ct}from"./index-Cp2vV6HJ.js";import{c as ht,d as lt,e as wt}from"./_node-stub_stream-DDexIdn_.js";function ZA(l,d){for(var w=0;w<d.length;w++){const h=d[w];if(typeof h!="string"&&!Array.isArray(h)){for(const y in h)if(y!=="default"&&!(y in l)){const g=Object.getOwnPropertyDescriptor(h,y);g&&Object.defineProperty(l,y,g.get?g:{enumerable:!0,get:()=>h[y]})}}}return Object.freeze(Object.defineProperty(l,Symbol.toStringTag,{value:"Module"}))}var _A={};const fI=KA(ht),yI=KA(lt),Ze=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),ft=ZA({__proto__:null,default:Ze},[Ze]),Yg=KA(ft);var De,Xe;function yt(){if(Xe)return De;Xe=1;const l=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,w=typeof AbortController=="function"?AbortController:class{constructor(){this.signal=new g}abort(s=new Error("This operation was aborted")){this.signal.reason=this.signal.reason||s,this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort",target:this.signal})}},h=typeof AbortSignal=="function",y=typeof w.AbortSignal=="function",g=h?AbortSignal:y?w.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(s){s.type==="abort"&&(this.aborted=!0,this.onabort(s),this._listeners.forEach(a=>a(s),this))}onabort(){}addEventListener(s,a){s==="abort"&&this._listeners.push(a)}removeEventListener(s,a){s==="abort"&&(this._listeners=this._listeners.filter(D=>D!==a))}},n=new Set,u=(o,s)=>{const a=`LRU_CACHE_OPTION_${o}`;Q(a)&&I(a,`${o} option`,`options.${s}`,E)},t=(o,s)=>{const a=`LRU_CACHE_METHOD_${o}`;if(Q(a)){const{prototype:D}=E,{get:f}=Object.getOwnPropertyDescriptor(D,o);I(a,`${o} method`,`cache.${s}()`,f)}},A=(o,s)=>{const a=`LRU_CACHE_PROPERTY_${o}`;if(Q(a)){const{prototype:D}=E,{get:f}=Object.getOwnPropertyDescriptor(D,o);I(a,`${o} property`,`cache.${s}`,f)}},C=(...o)=>{typeof process=="object"&&process&&typeof process.emitWarning=="function"?process.emitWarning(...o):console.error(...o)},Q=o=>!n.has(o),I=(o,s,a,D)=>{n.add(o);const f=`The ${s} is deprecated. Please use ${a} instead.`;C(f,"DeprecationWarning",o,D)},r=o=>o&&o===Math.floor(o)&&o>0&&isFinite(o),i=o=>r(o)?o<=Math.pow(2,8)?Uint8Array:o<=Math.pow(2,16)?Uint16Array:o<=Math.pow(2,32)?Uint32Array:o<=Number.MAX_SAFE_INTEGER?e:null:null;class e extends Array{constructor(s){super(s),this.fill(0)}}class B{constructor(s){if(s===0)return[];const a=i(s);this.heap=new a(s),this.length=0}push(s){this.heap[this.length++]=s}pop(){return this.heap[--this.length]}}class E{constructor(s={}){const{max:a=0,ttl:D,ttlResolution:f=1,ttlAutopurge:F,updateAgeOnGet:S,updateAgeOnHas:p,allowStale:G,dispose:N,disposeAfter:m,noDisposeOnSet:J,noUpdateTTL:v,maxSize:X=0,maxEntrySize:CA=0,sizeCalculation:z,fetchMethod:j,fetchContext:iA,noDeleteOnFetchRejection:aA,noDeleteOnStaleGet:uA,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:SA,ignoreFetchAbort:UA}=s,{length:FA,maxAge:QA,stale:yA}=s instanceof E?{}:s;if(a!==0&&!r(a))throw new TypeError("max option must be a nonnegative integer");const HA=a?i(a):Array;if(!HA)throw new Error("invalid max value: "+a);if(this.max=a,this.maxSize=X,this.maxEntrySize=CA||this.maxSize,this.sizeCalculation=z||FA,this.sizeCalculation){if(!this.maxSize&&!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(this.fetchMethod=j||null,this.fetchMethod&&typeof this.fetchMethod!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=iA,!this.fetchMethod&&iA!==void 0)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(a).fill(null),this.valList=new Array(a).fill(null),this.next=new HA(a),this.prev=new HA(a),this.head=0,this.tail=0,this.free=new B(a),this.initialFill=1,this.size=0,typeof N=="function"&&(this.dispose=N),typeof m=="function"?(this.disposeAfter=m,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!J,this.noUpdateTTL=!!v,this.noDeleteOnFetchRejection=!!aA,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!SA,this.ignoreFetchAbort=!!UA,this.maxEntrySize!==0){if(this.maxSize!==0&&!r(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!r(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!G||!!yA,this.noDeleteOnStaleGet=!!uA,this.updateAgeOnGet=!!S,this.updateAgeOnHas=!!p,this.ttlResolution=r(f)||f===0?f:1,this.ttlAutopurge=!!F,this.ttl=D||QA||0,this.ttl){if(!r(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(this.max===0&&this.ttl===0&&this.maxSize===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const XA="LRU_CACHE_UNBOUNDED";Q(XA)&&(n.add(XA),C("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",XA,E))}yA&&u("stale","allowStale"),QA&&u("maxAge","ttl"),FA&&u("length","sizeCalculation")}getRemainingTTL(s){return this.has(s,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new e(this.max),this.starts=new e(this.max),this.setItemTTL=(D,f,F=l.now())=>{if(this.starts[D]=f!==0?F:0,this.ttls[D]=f,f!==0&&this.ttlAutopurge){const S=setTimeout(()=>{this.isStale(D)&&this.delete(this.keyList[D])},f+1);S.unref&&S.unref()}},this.updateItemAge=D=>{this.starts[D]=this.ttls[D]!==0?l.now():0},this.statusTTL=(D,f)=>{D&&(D.ttl=this.ttls[f],D.start=this.starts[f],D.now=s||a(),D.remainingTTL=D.now+D.ttl-D.start)};let s=0;const a=()=>{const D=l.now();if(this.ttlResolution>0){s=D;const f=setTimeout(()=>s=0,this.ttlResolution);f.unref&&f.unref()}return D};this.getRemainingTTL=D=>{const f=this.keyMap.get(D);return f===void 0?0:this.ttls[f]===0||this.starts[f]===0?1/0:this.starts[f]+this.ttls[f]-(s||a())},this.isStale=D=>this.ttls[D]!==0&&this.starts[D]!==0&&(s||a())-this.starts[D]>this.ttls[D]}updateItemAge(s){}statusTTL(s,a){}setItemTTL(s,a,D){}isStale(s){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new e(this.max),this.removeItemSize=s=>{this.calculatedSize-=this.sizes[s],this.sizes[s]=0},this.requireSize=(s,a,D,f)=>{if(this.isBackgroundFetch(a))return 0;if(!r(D))if(f){if(typeof f!="function")throw new TypeError("sizeCalculation must be a function");if(D=f(a,s),!r(D))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 D},this.addItemSize=(s,a,D)=>{if(this.sizes[s]=a,this.maxSize){const f=this.maxSize-this.sizes[s];for(;this.calculatedSize>f;)this.evict(!0)}this.calculatedSize+=this.sizes[s],D&&(D.entrySize=a,D.totalCalculatedSize=this.calculatedSize)}}removeItemSize(s){}addItemSize(s,a){}requireSize(s,a,D,f){if(D||f)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:s=this.allowStale}={}){if(this.size)for(let a=this.tail;!(!this.isValidIndex(a)||((s||!this.isStale(a))&&(yield a),a===this.head));)a=this.prev[a]}*rindexes({allowStale:s=this.allowStale}={}){if(this.size)for(let a=this.head;!(!this.isValidIndex(a)||((s||!this.isStale(a))&&(yield a),a===this.tail));)a=this.next[a]}isValidIndex(s){return s!==void 0&&this.keyMap.get(this.keyList[s])===s}*entries(){for(const s of this.indexes())this.valList[s]!==void 0&&this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield[this.keyList[s],this.valList[s]])}*rentries(){for(const s of this.rindexes())this.valList[s]!==void 0&&this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield[this.keyList[s],this.valList[s]])}*keys(){for(const s of this.indexes())this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.keyList[s])}*rkeys(){for(const s of this.rindexes())this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.keyList[s])}*values(){for(const s of this.indexes())this.valList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.valList[s])}*rvalues(){for(const s of this.rindexes())this.valList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.valList[s])}[Symbol.iterator](){return this.entries()}find(s,a){for(const D of this.indexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;if(F!==void 0&&s(F,this.keyList[D],this))return this.get(this.keyList[D],a)}}forEach(s,a=this){for(const D of this.indexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;F!==void 0&&s.call(a,F,this.keyList[D],this)}}rforEach(s,a=this){for(const D of this.rindexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;F!==void 0&&s.call(a,F,this.keyList[D],this)}}get prune(){return t("prune","purgeStale"),this.purgeStale}purgeStale(){let s=!1;for(const a of this.rindexes({allowStale:!0}))this.isStale(a)&&(this.delete(this.keyList[a]),s=!0);return s}dump(){const s=[];for(const a of this.indexes({allowStale:!0})){const D=this.keyList[a],f=this.valList[a],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;if(F===void 0)continue;const S={value:F};if(this.ttls){S.ttl=this.ttls[a];const p=l.now()-this.starts[a];S.start=Math.floor(Date.now()-p)}this.sizes&&(S.size=this.sizes[a]),s.unshift([D,S])}return s}load(s){this.clear();for(const[a,D]of s){if(D.start){const f=Date.now()-D.start;D.start=l.now()-f}this.set(a,D.value,D)}}dispose(s,a,D){}set(s,a,{ttl:D=this.ttl,start:f,noDisposeOnSet:F=this.noDisposeOnSet,size:S=0,sizeCalculation:p=this.sizeCalculation,noUpdateTTL:G=this.noUpdateTTL,status:N}={}){if(S=this.requireSize(s,a,S,p),this.maxEntrySize&&S>this.maxEntrySize)return N&&(N.set="miss",N.maxEntrySizeExceeded=!0),this.delete(s),this;let m=this.size===0?void 0:this.keyMap.get(s);if(m===void 0)m=this.newIndex(),this.keyList[m]=s,this.valList[m]=a,this.keyMap.set(s,m),this.next[this.tail]=m,this.prev[m]=this.tail,this.tail=m,this.size++,this.addItemSize(m,S,N),N&&(N.set="add"),G=!1;else{this.moveToTail(m);const J=this.valList[m];if(a!==J){if(this.isBackgroundFetch(J)?J.__abortController.abort(new Error("replaced")):F||(this.dispose(J,s,"set"),this.disposeAfter&&this.disposed.push([J,s,"set"])),this.removeItemSize(m),this.valList[m]=a,this.addItemSize(m,S,N),N){N.set="replace";const v=J&&this.isBackgroundFetch(J)?J.__staleWhileFetching:J;v!==void 0&&(N.oldValue=v)}}else N&&(N.set="update")}if(D!==0&&this.ttl===0&&!this.ttls&&this.initializeTTLTracking(),G||this.setItemTTL(m,D,f),this.statusTTL(N,m),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return this.size===0?this.tail:this.size===this.max&&this.max!==0?this.evict(!1):this.free.length!==0?this.free.pop():this.initialFill++}pop(){if(this.size){const s=this.valList[this.head];return this.evict(!0),s}}evict(s){const a=this.head,D=this.keyList[a],f=this.valList[a];return this.isBackgroundFetch(f)?f.__abortController.abort(new Error("evicted")):(this.dispose(f,D,"evict"),this.disposeAfter&&this.disposed.push([f,D,"evict"])),this.removeItemSize(a),s&&(this.keyList[a]=null,this.valList[a]=null,this.free.push(a)),this.head=this.next[a],this.keyMap.delete(D),this.size--,a}has(s,{updateAgeOnHas:a=this.updateAgeOnHas,status:D}={}){const f=this.keyMap.get(s);if(f!==void 0)if(this.isStale(f))D&&(D.has="stale",this.statusTTL(D,f));else return a&&this.updateItemAge(f),D&&(D.has="hit"),this.statusTTL(D,f),!0;else D&&(D.has="miss");return!1}peek(s,{allowStale:a=this.allowStale}={}){const D=this.keyMap.get(s);if(D!==void 0&&(a||!this.isStale(D))){const f=this.valList[D];return this.isBackgroundFetch(f)?f.__staleWhileFetching:f}}backgroundFetch(s,a,D,f){const F=a===void 0?void 0:this.valList[a];if(this.isBackgroundFetch(F))return F;const S=new w;D.signal&&D.signal.addEventListener("abort",()=>S.abort(D.signal.reason));const p={signal:S.signal,options:D,context:f},G=(X,CA=!1)=>{const{aborted:z}=S.signal,j=D.ignoreFetchAbort&&X!==void 0;return D.status&&(z&&!CA?(D.status.fetchAborted=!0,D.status.fetchError=S.signal.reason,j&&(D.status.fetchAbortIgnored=!0)):D.status.fetchResolved=!0),z&&!j&&!CA?m(S.signal.reason):(this.valList[a]===v&&(X===void 0?v.__staleWhileFetching?this.valList[a]=v.__staleWhileFetching:this.delete(s):(D.status&&(D.status.fetchUpdated=!0),this.set(s,X,p.options))),X)},N=X=>(D.status&&(D.status.fetchRejected=!0,D.status.fetchError=X),m(X)),m=X=>{const{aborted:CA}=S.signal,z=CA&&D.allowStaleOnFetchAbort,j=z||D.allowStaleOnFetchRejection,iA=j||D.noDeleteOnFetchRejection;if(this.valList[a]===v&&(!iA||v.__staleWhileFetching===void 0?this.delete(s):z||(this.valList[a]=v.__staleWhileFetching)),j)return D.status&&v.__staleWhileFetching!==void 0&&(D.status.returnedStale=!0),v.__staleWhileFetching;if(v.__returned===v)throw X},J=(X,CA)=>{this.fetchMethod(s,F,p).then(z=>X(z),CA),S.signal.addEventListener("abort",()=>{(!D.ignoreFetchAbort||D.allowStaleOnFetchAbort)&&(X(),D.allowStaleOnFetchAbort&&(X=z=>G(z,!0)))})};D.status&&(D.status.fetchDispatched=!0);const v=new Promise(J).then(G,N);return v.__abortController=S,v.__staleWhileFetching=F,v.__returned=null,a===void 0?(this.set(s,v,{...p.options,status:void 0}),a=this.keyMap.get(s)):this.valList[a]=v,v}isBackgroundFetch(s){return s&&typeof s=="object"&&typeof s.then=="function"&&Object.prototype.hasOwnProperty.call(s,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(s,"__returned")&&(s.__returned===s||s.__returned===null)}async fetch(s,{allowStale:a=this.allowStale,updateAgeOnGet:D=this.updateAgeOnGet,noDeleteOnStaleGet:f=this.noDeleteOnStaleGet,ttl:F=this.ttl,noDisposeOnSet:S=this.noDisposeOnSet,size:p=0,sizeCalculation:G=this.sizeCalculation,noUpdateTTL:N=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:J=this.allowStaleOnFetchRejection,ignoreFetchAbort:v=this.ignoreFetchAbort,allowStaleOnFetchAbort:X=this.allowStaleOnFetchAbort,fetchContext:CA=this.fetchContext,forceRefresh:z=!1,status:j,signal:iA}={}){if(!this.fetchMethod)return j&&(j.fetch="get"),this.get(s,{allowStale:a,updateAgeOnGet:D,noDeleteOnStaleGet:f,status:j});const aA={allowStale:a,updateAgeOnGet:D,noDeleteOnStaleGet:f,ttl:F,noDisposeOnSet:S,size:p,sizeCalculation:G,noUpdateTTL:N,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:J,allowStaleOnFetchAbort:X,ignoreFetchAbort:v,status:j,signal:iA};let uA=this.keyMap.get(s);if(uA===void 0){j&&(j.fetch="miss");const Z=this.backgroundFetch(s,uA,aA,CA);return Z.__returned=Z}else{const Z=this.valList[uA];if(this.isBackgroundFetch(Z)){const yA=a&&Z.__staleWhileFetching!==void 0;return j&&(j.fetch="inflight",yA&&(j.returnedStale=!0)),yA?Z.__staleWhileFetching:Z.__returned=Z}const SA=this.isStale(uA);if(!z&&!SA)return j&&(j.fetch="hit"),this.moveToTail(uA),D&&this.updateItemAge(uA),this.statusTTL(j,uA),Z;const UA=this.backgroundFetch(s,uA,aA,CA),FA=UA.__staleWhileFetching!==void 0,QA=FA&&a;return j&&(j.fetch=FA&&SA?"stale":"refresh",QA&&SA&&(j.returnedStale=!0)),QA?UA.__staleWhileFetching:UA.__returned=UA}}get(s,{allowStale:a=this.allowStale,updateAgeOnGet:D=this.updateAgeOnGet,noDeleteOnStaleGet:f=this.noDeleteOnStaleGet,status:F}={}){const S=this.keyMap.get(s);if(S!==void 0){const p=this.valList[S],G=this.isBackgroundFetch(p);return this.statusTTL(F,S),this.isStale(S)?(F&&(F.get="stale"),G?(F&&(F.returnedStale=a&&p.__staleWhileFetching!==void 0),a?p.__staleWhileFetching:void 0):(f||this.delete(s),F&&(F.returnedStale=a),a?p:void 0)):(F&&(F.get="hit"),G?p.__staleWhileFetching:(this.moveToTail(S),D&&this.updateItemAge(S),p))}else F&&(F.get="miss")}connect(s,a){this.prev[a]=s,this.next[s]=a}moveToTail(s){s!==this.tail&&(s===this.head?this.head=this.next[s]:this.connect(this.prev[s],this.next[s]),this.connect(this.tail,s),this.tail=s)}get del(){return t("del","delete"),this.delete}delete(s){let a=!1;if(this.size!==0){const D=this.keyMap.get(s);if(D!==void 0)if(a=!0,this.size===1)this.clear();else{this.removeItemSize(D);const f=this.valList[D];this.isBackgroundFetch(f)?f.__abortController.abort(new Error("deleted")):(this.dispose(f,s,"delete"),this.disposeAfter&&this.disposed.push([f,s,"delete"])),this.keyMap.delete(s),this.keyList[D]=null,this.valList[D]=null,D===this.tail?this.tail=this.prev[D]:D===this.head?this.head=this.next[D]:(this.next[this.prev[D]]=this.next[D],this.prev[this.next[D]]=this.prev[D]),this.size--,this.free.push(D)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return a}clear(){for(const s of this.rindexes({allowStale:!0})){const a=this.valList[s];if(this.isBackgroundFetch(a))a.__abortController.abort(new Error("deleted"));else{const D=this.keyList[s];this.dispose(a,D,"delete"),this.disposeAfter&&this.disposed.push([a,D,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return t("reset","clear"),this.clear}get length(){return A("length","size"),this.size}static get AbortController(){return w}static get AbortSignal(){return g}}return De=E,De}var jA={};const _e=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),dt=ZA({__proto__:null,default:_e},[_e]),Dg=KA(dt);var xA={},je;function Ft(){if(je)return xA;je=1;var l=xA&&xA.__createBinding||(Object.create?(function(t,A,C,Q){Q===void 0&&(Q=C);var I=Object.getOwnPropertyDescriptor(A,C);(!I||("get"in I?!A.__esModule:I.writable||I.configurable))&&(I={enumerable:!0,get:function(){return A[C]}}),Object.defineProperty(t,Q,I)}):(function(t,A,C,Q){Q===void 0&&(Q=C),t[Q]=A[C]})),d=xA&&xA.__setModuleDefault||(Object.create?(function(t,A){Object.defineProperty(t,"default",{enumerable:!0,value:A})}):function(t,A){t.default=A}),w=xA&&xA.__importStar||function(t){if(t&&t.__esModule)return t;var A={};if(t!=null)for(var C in t)C!=="default"&&Object.prototype.hasOwnProperty.call(t,C)&&l(A,t,C);return d(A,t),A};Object.defineProperty(xA,"__esModule",{value:!0}),xA.req=xA.json=xA.toBuffer=void 0;const h=w(fI),y=w(yI);async function g(t){let A=0;const C=[];for await(const Q of t)A+=Q.length,C.push(Q);return Buffer.concat(C,A)}xA.toBuffer=g;async function n(t){const C=(await g(t)).toString("utf8");try{return JSON.parse(C)}catch(Q){const I=Q;throw I.message+=` (input: ${C})`,I}}xA.json=n;function u(t,A={}){const Q=((typeof t=="string"?t:t.href).startsWith("https:")?y:h).request(t,A),I=new Promise((r,i)=>{Q.once("response",r).once("error",i).end()});return Q.then=I.then.bind(I),Q}return xA.req=u,xA}var ze;function dI(){return ze||(ze=1,(function(l){var d=jA&&jA.__createBinding||(Object.create?(function(C,Q,I,r){r===void 0&&(r=I);var i=Object.getOwnPropertyDescriptor(Q,I);(!i||("get"in i?!Q.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return Q[I]}}),Object.defineProperty(C,r,i)}):(function(C,Q,I,r){r===void 0&&(r=I),C[r]=Q[I]})),w=jA&&jA.__setModuleDefault||(Object.create?(function(C,Q){Object.defineProperty(C,"default",{enumerable:!0,value:Q})}):function(C,Q){C.default=Q}),h=jA&&jA.__importStar||function(C){if(C&&C.__esModule)return C;var Q={};if(C!=null)for(var I in C)I!=="default"&&Object.prototype.hasOwnProperty.call(C,I)&&d(Q,C,I);return w(Q,C),Q},y=jA&&jA.__exportStar||function(C,Q){for(var I in C)I!=="default"&&!Object.prototype.hasOwnProperty.call(Q,I)&&d(Q,C,I)};Object.defineProperty(l,"__esModule",{value:!0}),l.Agent=void 0;const g=h(Dg),n=h(fI),u=yI;y(Ft(),l);const t=Symbol("AgentBaseInternalState");class A extends n.Agent{constructor(Q){super(Q),this[t]={}}isSecureEndpoint(Q){if(Q){if(typeof Q.secureEndpoint=="boolean")return Q.secureEndpoint;if(typeof Q.protocol=="string")return Q.protocol==="https:"}const{stack:I}=new Error;return typeof I!="string"?!1:I.split(`
|
|
1
|
+
import{g as KA,c as ut,t as Dt,a as ct}from"./index-XEVKscP-.js";import{c as ht,d as lt,e as wt}from"./_node-stub_stream-DDexIdn_.js";function ZA(l,d){for(var w=0;w<d.length;w++){const h=d[w];if(typeof h!="string"&&!Array.isArray(h)){for(const y in h)if(y!=="default"&&!(y in l)){const g=Object.getOwnPropertyDescriptor(h,y);g&&Object.defineProperty(l,y,g.get?g:{enumerable:!0,get:()=>h[y]})}}}return Object.freeze(Object.defineProperty(l,Symbol.toStringTag,{value:"Module"}))}var _A={};const fI=KA(ht),yI=KA(lt),Ze=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),ft=ZA({__proto__:null,default:Ze},[Ze]),Yg=KA(ft);var De,Xe;function yt(){if(Xe)return De;Xe=1;const l=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,w=typeof AbortController=="function"?AbortController:class{constructor(){this.signal=new g}abort(s=new Error("This operation was aborted")){this.signal.reason=this.signal.reason||s,this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort",target:this.signal})}},h=typeof AbortSignal=="function",y=typeof w.AbortSignal=="function",g=h?AbortSignal:y?w.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(s){s.type==="abort"&&(this.aborted=!0,this.onabort(s),this._listeners.forEach(a=>a(s),this))}onabort(){}addEventListener(s,a){s==="abort"&&this._listeners.push(a)}removeEventListener(s,a){s==="abort"&&(this._listeners=this._listeners.filter(D=>D!==a))}},n=new Set,u=(o,s)=>{const a=`LRU_CACHE_OPTION_${o}`;Q(a)&&I(a,`${o} option`,`options.${s}`,E)},t=(o,s)=>{const a=`LRU_CACHE_METHOD_${o}`;if(Q(a)){const{prototype:D}=E,{get:f}=Object.getOwnPropertyDescriptor(D,o);I(a,`${o} method`,`cache.${s}()`,f)}},A=(o,s)=>{const a=`LRU_CACHE_PROPERTY_${o}`;if(Q(a)){const{prototype:D}=E,{get:f}=Object.getOwnPropertyDescriptor(D,o);I(a,`${o} property`,`cache.${s}`,f)}},C=(...o)=>{typeof process=="object"&&process&&typeof process.emitWarning=="function"?process.emitWarning(...o):console.error(...o)},Q=o=>!n.has(o),I=(o,s,a,D)=>{n.add(o);const f=`The ${s} is deprecated. Please use ${a} instead.`;C(f,"DeprecationWarning",o,D)},r=o=>o&&o===Math.floor(o)&&o>0&&isFinite(o),i=o=>r(o)?o<=Math.pow(2,8)?Uint8Array:o<=Math.pow(2,16)?Uint16Array:o<=Math.pow(2,32)?Uint32Array:o<=Number.MAX_SAFE_INTEGER?e:null:null;class e extends Array{constructor(s){super(s),this.fill(0)}}class B{constructor(s){if(s===0)return[];const a=i(s);this.heap=new a(s),this.length=0}push(s){this.heap[this.length++]=s}pop(){return this.heap[--this.length]}}class E{constructor(s={}){const{max:a=0,ttl:D,ttlResolution:f=1,ttlAutopurge:F,updateAgeOnGet:S,updateAgeOnHas:p,allowStale:G,dispose:N,disposeAfter:m,noDisposeOnSet:J,noUpdateTTL:v,maxSize:X=0,maxEntrySize:CA=0,sizeCalculation:z,fetchMethod:j,fetchContext:iA,noDeleteOnFetchRejection:aA,noDeleteOnStaleGet:uA,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:SA,ignoreFetchAbort:UA}=s,{length:FA,maxAge:QA,stale:yA}=s instanceof E?{}:s;if(a!==0&&!r(a))throw new TypeError("max option must be a nonnegative integer");const HA=a?i(a):Array;if(!HA)throw new Error("invalid max value: "+a);if(this.max=a,this.maxSize=X,this.maxEntrySize=CA||this.maxSize,this.sizeCalculation=z||FA,this.sizeCalculation){if(!this.maxSize&&!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(this.fetchMethod=j||null,this.fetchMethod&&typeof this.fetchMethod!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=iA,!this.fetchMethod&&iA!==void 0)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(a).fill(null),this.valList=new Array(a).fill(null),this.next=new HA(a),this.prev=new HA(a),this.head=0,this.tail=0,this.free=new B(a),this.initialFill=1,this.size=0,typeof N=="function"&&(this.dispose=N),typeof m=="function"?(this.disposeAfter=m,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!J,this.noUpdateTTL=!!v,this.noDeleteOnFetchRejection=!!aA,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!SA,this.ignoreFetchAbort=!!UA,this.maxEntrySize!==0){if(this.maxSize!==0&&!r(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!r(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!G||!!yA,this.noDeleteOnStaleGet=!!uA,this.updateAgeOnGet=!!S,this.updateAgeOnHas=!!p,this.ttlResolution=r(f)||f===0?f:1,this.ttlAutopurge=!!F,this.ttl=D||QA||0,this.ttl){if(!r(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(this.max===0&&this.ttl===0&&this.maxSize===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){const XA="LRU_CACHE_UNBOUNDED";Q(XA)&&(n.add(XA),C("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",XA,E))}yA&&u("stale","allowStale"),QA&&u("maxAge","ttl"),FA&&u("length","sizeCalculation")}getRemainingTTL(s){return this.has(s,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new e(this.max),this.starts=new e(this.max),this.setItemTTL=(D,f,F=l.now())=>{if(this.starts[D]=f!==0?F:0,this.ttls[D]=f,f!==0&&this.ttlAutopurge){const S=setTimeout(()=>{this.isStale(D)&&this.delete(this.keyList[D])},f+1);S.unref&&S.unref()}},this.updateItemAge=D=>{this.starts[D]=this.ttls[D]!==0?l.now():0},this.statusTTL=(D,f)=>{D&&(D.ttl=this.ttls[f],D.start=this.starts[f],D.now=s||a(),D.remainingTTL=D.now+D.ttl-D.start)};let s=0;const a=()=>{const D=l.now();if(this.ttlResolution>0){s=D;const f=setTimeout(()=>s=0,this.ttlResolution);f.unref&&f.unref()}return D};this.getRemainingTTL=D=>{const f=this.keyMap.get(D);return f===void 0?0:this.ttls[f]===0||this.starts[f]===0?1/0:this.starts[f]+this.ttls[f]-(s||a())},this.isStale=D=>this.ttls[D]!==0&&this.starts[D]!==0&&(s||a())-this.starts[D]>this.ttls[D]}updateItemAge(s){}statusTTL(s,a){}setItemTTL(s,a,D){}isStale(s){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new e(this.max),this.removeItemSize=s=>{this.calculatedSize-=this.sizes[s],this.sizes[s]=0},this.requireSize=(s,a,D,f)=>{if(this.isBackgroundFetch(a))return 0;if(!r(D))if(f){if(typeof f!="function")throw new TypeError("sizeCalculation must be a function");if(D=f(a,s),!r(D))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 D},this.addItemSize=(s,a,D)=>{if(this.sizes[s]=a,this.maxSize){const f=this.maxSize-this.sizes[s];for(;this.calculatedSize>f;)this.evict(!0)}this.calculatedSize+=this.sizes[s],D&&(D.entrySize=a,D.totalCalculatedSize=this.calculatedSize)}}removeItemSize(s){}addItemSize(s,a){}requireSize(s,a,D,f){if(D||f)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:s=this.allowStale}={}){if(this.size)for(let a=this.tail;!(!this.isValidIndex(a)||((s||!this.isStale(a))&&(yield a),a===this.head));)a=this.prev[a]}*rindexes({allowStale:s=this.allowStale}={}){if(this.size)for(let a=this.head;!(!this.isValidIndex(a)||((s||!this.isStale(a))&&(yield a),a===this.tail));)a=this.next[a]}isValidIndex(s){return s!==void 0&&this.keyMap.get(this.keyList[s])===s}*entries(){for(const s of this.indexes())this.valList[s]!==void 0&&this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield[this.keyList[s],this.valList[s]])}*rentries(){for(const s of this.rindexes())this.valList[s]!==void 0&&this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield[this.keyList[s],this.valList[s]])}*keys(){for(const s of this.indexes())this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.keyList[s])}*rkeys(){for(const s of this.rindexes())this.keyList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.keyList[s])}*values(){for(const s of this.indexes())this.valList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.valList[s])}*rvalues(){for(const s of this.rindexes())this.valList[s]!==void 0&&!this.isBackgroundFetch(this.valList[s])&&(yield this.valList[s])}[Symbol.iterator](){return this.entries()}find(s,a){for(const D of this.indexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;if(F!==void 0&&s(F,this.keyList[D],this))return this.get(this.keyList[D],a)}}forEach(s,a=this){for(const D of this.indexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;F!==void 0&&s.call(a,F,this.keyList[D],this)}}rforEach(s,a=this){for(const D of this.rindexes()){const f=this.valList[D],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;F!==void 0&&s.call(a,F,this.keyList[D],this)}}get prune(){return t("prune","purgeStale"),this.purgeStale}purgeStale(){let s=!1;for(const a of this.rindexes({allowStale:!0}))this.isStale(a)&&(this.delete(this.keyList[a]),s=!0);return s}dump(){const s=[];for(const a of this.indexes({allowStale:!0})){const D=this.keyList[a],f=this.valList[a],F=this.isBackgroundFetch(f)?f.__staleWhileFetching:f;if(F===void 0)continue;const S={value:F};if(this.ttls){S.ttl=this.ttls[a];const p=l.now()-this.starts[a];S.start=Math.floor(Date.now()-p)}this.sizes&&(S.size=this.sizes[a]),s.unshift([D,S])}return s}load(s){this.clear();for(const[a,D]of s){if(D.start){const f=Date.now()-D.start;D.start=l.now()-f}this.set(a,D.value,D)}}dispose(s,a,D){}set(s,a,{ttl:D=this.ttl,start:f,noDisposeOnSet:F=this.noDisposeOnSet,size:S=0,sizeCalculation:p=this.sizeCalculation,noUpdateTTL:G=this.noUpdateTTL,status:N}={}){if(S=this.requireSize(s,a,S,p),this.maxEntrySize&&S>this.maxEntrySize)return N&&(N.set="miss",N.maxEntrySizeExceeded=!0),this.delete(s),this;let m=this.size===0?void 0:this.keyMap.get(s);if(m===void 0)m=this.newIndex(),this.keyList[m]=s,this.valList[m]=a,this.keyMap.set(s,m),this.next[this.tail]=m,this.prev[m]=this.tail,this.tail=m,this.size++,this.addItemSize(m,S,N),N&&(N.set="add"),G=!1;else{this.moveToTail(m);const J=this.valList[m];if(a!==J){if(this.isBackgroundFetch(J)?J.__abortController.abort(new Error("replaced")):F||(this.dispose(J,s,"set"),this.disposeAfter&&this.disposed.push([J,s,"set"])),this.removeItemSize(m),this.valList[m]=a,this.addItemSize(m,S,N),N){N.set="replace";const v=J&&this.isBackgroundFetch(J)?J.__staleWhileFetching:J;v!==void 0&&(N.oldValue=v)}}else N&&(N.set="update")}if(D!==0&&this.ttl===0&&!this.ttls&&this.initializeTTLTracking(),G||this.setItemTTL(m,D,f),this.statusTTL(N,m),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return this.size===0?this.tail:this.size===this.max&&this.max!==0?this.evict(!1):this.free.length!==0?this.free.pop():this.initialFill++}pop(){if(this.size){const s=this.valList[this.head];return this.evict(!0),s}}evict(s){const a=this.head,D=this.keyList[a],f=this.valList[a];return this.isBackgroundFetch(f)?f.__abortController.abort(new Error("evicted")):(this.dispose(f,D,"evict"),this.disposeAfter&&this.disposed.push([f,D,"evict"])),this.removeItemSize(a),s&&(this.keyList[a]=null,this.valList[a]=null,this.free.push(a)),this.head=this.next[a],this.keyMap.delete(D),this.size--,a}has(s,{updateAgeOnHas:a=this.updateAgeOnHas,status:D}={}){const f=this.keyMap.get(s);if(f!==void 0)if(this.isStale(f))D&&(D.has="stale",this.statusTTL(D,f));else return a&&this.updateItemAge(f),D&&(D.has="hit"),this.statusTTL(D,f),!0;else D&&(D.has="miss");return!1}peek(s,{allowStale:a=this.allowStale}={}){const D=this.keyMap.get(s);if(D!==void 0&&(a||!this.isStale(D))){const f=this.valList[D];return this.isBackgroundFetch(f)?f.__staleWhileFetching:f}}backgroundFetch(s,a,D,f){const F=a===void 0?void 0:this.valList[a];if(this.isBackgroundFetch(F))return F;const S=new w;D.signal&&D.signal.addEventListener("abort",()=>S.abort(D.signal.reason));const p={signal:S.signal,options:D,context:f},G=(X,CA=!1)=>{const{aborted:z}=S.signal,j=D.ignoreFetchAbort&&X!==void 0;return D.status&&(z&&!CA?(D.status.fetchAborted=!0,D.status.fetchError=S.signal.reason,j&&(D.status.fetchAbortIgnored=!0)):D.status.fetchResolved=!0),z&&!j&&!CA?m(S.signal.reason):(this.valList[a]===v&&(X===void 0?v.__staleWhileFetching?this.valList[a]=v.__staleWhileFetching:this.delete(s):(D.status&&(D.status.fetchUpdated=!0),this.set(s,X,p.options))),X)},N=X=>(D.status&&(D.status.fetchRejected=!0,D.status.fetchError=X),m(X)),m=X=>{const{aborted:CA}=S.signal,z=CA&&D.allowStaleOnFetchAbort,j=z||D.allowStaleOnFetchRejection,iA=j||D.noDeleteOnFetchRejection;if(this.valList[a]===v&&(!iA||v.__staleWhileFetching===void 0?this.delete(s):z||(this.valList[a]=v.__staleWhileFetching)),j)return D.status&&v.__staleWhileFetching!==void 0&&(D.status.returnedStale=!0),v.__staleWhileFetching;if(v.__returned===v)throw X},J=(X,CA)=>{this.fetchMethod(s,F,p).then(z=>X(z),CA),S.signal.addEventListener("abort",()=>{(!D.ignoreFetchAbort||D.allowStaleOnFetchAbort)&&(X(),D.allowStaleOnFetchAbort&&(X=z=>G(z,!0)))})};D.status&&(D.status.fetchDispatched=!0);const v=new Promise(J).then(G,N);return v.__abortController=S,v.__staleWhileFetching=F,v.__returned=null,a===void 0?(this.set(s,v,{...p.options,status:void 0}),a=this.keyMap.get(s)):this.valList[a]=v,v}isBackgroundFetch(s){return s&&typeof s=="object"&&typeof s.then=="function"&&Object.prototype.hasOwnProperty.call(s,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(s,"__returned")&&(s.__returned===s||s.__returned===null)}async fetch(s,{allowStale:a=this.allowStale,updateAgeOnGet:D=this.updateAgeOnGet,noDeleteOnStaleGet:f=this.noDeleteOnStaleGet,ttl:F=this.ttl,noDisposeOnSet:S=this.noDisposeOnSet,size:p=0,sizeCalculation:G=this.sizeCalculation,noUpdateTTL:N=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:J=this.allowStaleOnFetchRejection,ignoreFetchAbort:v=this.ignoreFetchAbort,allowStaleOnFetchAbort:X=this.allowStaleOnFetchAbort,fetchContext:CA=this.fetchContext,forceRefresh:z=!1,status:j,signal:iA}={}){if(!this.fetchMethod)return j&&(j.fetch="get"),this.get(s,{allowStale:a,updateAgeOnGet:D,noDeleteOnStaleGet:f,status:j});const aA={allowStale:a,updateAgeOnGet:D,noDeleteOnStaleGet:f,ttl:F,noDisposeOnSet:S,size:p,sizeCalculation:G,noUpdateTTL:N,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:J,allowStaleOnFetchAbort:X,ignoreFetchAbort:v,status:j,signal:iA};let uA=this.keyMap.get(s);if(uA===void 0){j&&(j.fetch="miss");const Z=this.backgroundFetch(s,uA,aA,CA);return Z.__returned=Z}else{const Z=this.valList[uA];if(this.isBackgroundFetch(Z)){const yA=a&&Z.__staleWhileFetching!==void 0;return j&&(j.fetch="inflight",yA&&(j.returnedStale=!0)),yA?Z.__staleWhileFetching:Z.__returned=Z}const SA=this.isStale(uA);if(!z&&!SA)return j&&(j.fetch="hit"),this.moveToTail(uA),D&&this.updateItemAge(uA),this.statusTTL(j,uA),Z;const UA=this.backgroundFetch(s,uA,aA,CA),FA=UA.__staleWhileFetching!==void 0,QA=FA&&a;return j&&(j.fetch=FA&&SA?"stale":"refresh",QA&&SA&&(j.returnedStale=!0)),QA?UA.__staleWhileFetching:UA.__returned=UA}}get(s,{allowStale:a=this.allowStale,updateAgeOnGet:D=this.updateAgeOnGet,noDeleteOnStaleGet:f=this.noDeleteOnStaleGet,status:F}={}){const S=this.keyMap.get(s);if(S!==void 0){const p=this.valList[S],G=this.isBackgroundFetch(p);return this.statusTTL(F,S),this.isStale(S)?(F&&(F.get="stale"),G?(F&&(F.returnedStale=a&&p.__staleWhileFetching!==void 0),a?p.__staleWhileFetching:void 0):(f||this.delete(s),F&&(F.returnedStale=a),a?p:void 0)):(F&&(F.get="hit"),G?p.__staleWhileFetching:(this.moveToTail(S),D&&this.updateItemAge(S),p))}else F&&(F.get="miss")}connect(s,a){this.prev[a]=s,this.next[s]=a}moveToTail(s){s!==this.tail&&(s===this.head?this.head=this.next[s]:this.connect(this.prev[s],this.next[s]),this.connect(this.tail,s),this.tail=s)}get del(){return t("del","delete"),this.delete}delete(s){let a=!1;if(this.size!==0){const D=this.keyMap.get(s);if(D!==void 0)if(a=!0,this.size===1)this.clear();else{this.removeItemSize(D);const f=this.valList[D];this.isBackgroundFetch(f)?f.__abortController.abort(new Error("deleted")):(this.dispose(f,s,"delete"),this.disposeAfter&&this.disposed.push([f,s,"delete"])),this.keyMap.delete(s),this.keyList[D]=null,this.valList[D]=null,D===this.tail?this.tail=this.prev[D]:D===this.head?this.head=this.next[D]:(this.next[this.prev[D]]=this.next[D],this.prev[this.next[D]]=this.prev[D]),this.size--,this.free.push(D)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return a}clear(){for(const s of this.rindexes({allowStale:!0})){const a=this.valList[s];if(this.isBackgroundFetch(a))a.__abortController.abort(new Error("deleted"));else{const D=this.keyList[s];this.dispose(a,D,"delete"),this.disposeAfter&&this.disposed.push([a,D,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return t("reset","clear"),this.clear}get length(){return A("length","size"),this.size}static get AbortController(){return w}static get AbortSignal(){return g}}return De=E,De}var jA={};const _e=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),dt=ZA({__proto__:null,default:_e},[_e]),Dg=KA(dt);var xA={},je;function Ft(){if(je)return xA;je=1;var l=xA&&xA.__createBinding||(Object.create?(function(t,A,C,Q){Q===void 0&&(Q=C);var I=Object.getOwnPropertyDescriptor(A,C);(!I||("get"in I?!A.__esModule:I.writable||I.configurable))&&(I={enumerable:!0,get:function(){return A[C]}}),Object.defineProperty(t,Q,I)}):(function(t,A,C,Q){Q===void 0&&(Q=C),t[Q]=A[C]})),d=xA&&xA.__setModuleDefault||(Object.create?(function(t,A){Object.defineProperty(t,"default",{enumerable:!0,value:A})}):function(t,A){t.default=A}),w=xA&&xA.__importStar||function(t){if(t&&t.__esModule)return t;var A={};if(t!=null)for(var C in t)C!=="default"&&Object.prototype.hasOwnProperty.call(t,C)&&l(A,t,C);return d(A,t),A};Object.defineProperty(xA,"__esModule",{value:!0}),xA.req=xA.json=xA.toBuffer=void 0;const h=w(fI),y=w(yI);async function g(t){let A=0;const C=[];for await(const Q of t)A+=Q.length,C.push(Q);return Buffer.concat(C,A)}xA.toBuffer=g;async function n(t){const C=(await g(t)).toString("utf8");try{return JSON.parse(C)}catch(Q){const I=Q;throw I.message+=` (input: ${C})`,I}}xA.json=n;function u(t,A={}){const Q=((typeof t=="string"?t:t.href).startsWith("https:")?y:h).request(t,A),I=new Promise((r,i)=>{Q.once("response",r).once("error",i).end()});return Q.then=I.then.bind(I),Q}return xA.req=u,xA}var ze;function dI(){return ze||(ze=1,(function(l){var d=jA&&jA.__createBinding||(Object.create?(function(C,Q,I,r){r===void 0&&(r=I);var i=Object.getOwnPropertyDescriptor(Q,I);(!i||("get"in i?!Q.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return Q[I]}}),Object.defineProperty(C,r,i)}):(function(C,Q,I,r){r===void 0&&(r=I),C[r]=Q[I]})),w=jA&&jA.__setModuleDefault||(Object.create?(function(C,Q){Object.defineProperty(C,"default",{enumerable:!0,value:Q})}):function(C,Q){C.default=Q}),h=jA&&jA.__importStar||function(C){if(C&&C.__esModule)return C;var Q={};if(C!=null)for(var I in C)I!=="default"&&Object.prototype.hasOwnProperty.call(C,I)&&d(Q,C,I);return w(Q,C),Q},y=jA&&jA.__exportStar||function(C,Q){for(var I in C)I!=="default"&&!Object.prototype.hasOwnProperty.call(Q,I)&&d(Q,C,I)};Object.defineProperty(l,"__esModule",{value:!0}),l.Agent=void 0;const g=h(Dg),n=h(fI),u=yI;y(Ft(),l);const t=Symbol("AgentBaseInternalState");class A extends n.Agent{constructor(Q){super(Q),this[t]={}}isSecureEndpoint(Q){if(Q){if(typeof Q.secureEndpoint=="boolean")return Q.secureEndpoint;if(typeof Q.protocol=="string")return Q.protocol==="https:"}const{stack:I}=new Error;return typeof I!="string"?!1:I.split(`
|
|
2
2
|
`).some(r=>r.indexOf("(https.js:")!==-1||r.indexOf("node:https:")!==-1)}incrementSockets(Q){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;this.sockets[Q]||(this.sockets[Q]=[]);const I=new g.Socket({writable:!1});return this.sockets[Q].push(I),this.totalSocketCount++,I}decrementSockets(Q,I){if(!this.sockets[Q]||I===null)return;const r=this.sockets[Q],i=r.indexOf(I);i!==-1&&(r.splice(i,1),this.totalSocketCount--,r.length===0&&delete this.sockets[Q])}getName(Q){return this.isSecureEndpoint(Q)?u.Agent.prototype.getName.call(this,Q):super.getName(Q)}createSocket(Q,I,r){const i={...I,secureEndpoint:this.isSecureEndpoint(I)},e=this.getName(i),B=this.incrementSockets(e);Promise.resolve().then(()=>this.connect(Q,i)).then(E=>{if(this.decrementSockets(e,B),E instanceof n.Agent)try{return E.addRequest(Q,i)}catch(o){return r(o)}this[t].currentSocket=E,super.createSocket(Q,I,r)},E=>{this.decrementSockets(e,B),r(E)})}createConnection(){const Q=this[t].currentSocket;if(this[t].currentSocket=void 0,!Q)throw new Error("No socket was returned in the `connect()` function");return Q}get defaultPort(){return this[t].defaultPort??(this.protocol==="https:"?443:80)}set defaultPort(Q){this[t]&&(this[t].defaultPort=Q)}get protocol(){return this[t].protocol??(this.isSecureEndpoint()?"https:":"http:")}set protocol(Q){this[t]&&(this[t].protocol=Q)}}l.Agent=A})(jA)),jA}var kI={exports:{}},ce,$e;function pt(){if($e)return ce;$e=1;var l=1e3,d=l*60,w=d*60,h=w*24,y=h*7,g=h*365.25;ce=function(C,Q){Q=Q||{};var I=typeof C;if(I==="string"&&C.length>0)return n(C);if(I==="number"&&isFinite(C))return Q.long?t(C):u(C);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(C))};function n(C){if(C=String(C),!(C.length>100)){var Q=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(C);if(Q){var I=parseFloat(Q[1]),r=(Q[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return I*g;case"weeks":case"week":case"w":return I*y;case"days":case"day":case"d":return I*h;case"hours":case"hour":case"hrs":case"hr":case"h":return I*w;case"minutes":case"minute":case"mins":case"min":case"m":return I*d;case"seconds":case"second":case"secs":case"sec":case"s":return I*l;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return I;default:return}}}}function u(C){var Q=Math.abs(C);return Q>=h?Math.round(C/h)+"d":Q>=w?Math.round(C/w)+"h":Q>=d?Math.round(C/d)+"m":Q>=l?Math.round(C/l)+"s":C+"ms"}function t(C){var Q=Math.abs(C);return Q>=h?A(C,Q,h,"day"):Q>=w?A(C,Q,w,"hour"):Q>=d?A(C,Q,d,"minute"):Q>=l?A(C,Q,l,"second"):C+" ms"}function A(C,Q,I,r){var i=Q>=I*1.5;return Math.round(C/I)+" "+r+(i?"s":"")}return ce}var he,AC;function St(){if(AC)return he;AC=1;function l(d){h.debug=h,h.default=h,h.coerce=A,h.disable=u,h.enable=g,h.enabled=t,h.humanize=pt(),h.destroy=C,Object.keys(d).forEach(Q=>{h[Q]=d[Q]}),h.names=[],h.skips=[],h.formatters={};function w(Q){let I=0;for(let r=0;r<Q.length;r++)I=(I<<5)-I+Q.charCodeAt(r),I|=0;return h.colors[Math.abs(I)%h.colors.length]}h.selectColor=w;function h(Q){let I,r=null,i,e;function B(...E){if(!B.enabled)return;const o=B,s=Number(new Date),a=s-(I||s);o.diff=a,o.prev=I,o.curr=s,I=s,E[0]=h.coerce(E[0]),typeof E[0]!="string"&&E.unshift("%O");let D=0;E[0]=E[0].replace(/%([a-zA-Z%])/g,(F,S)=>{if(F==="%%")return"%";D++;const p=h.formatters[S];if(typeof p=="function"){const G=E[D];F=p.call(o,G),E.splice(D,1),D--}return F}),h.formatArgs.call(o,E),(o.log||h.log).apply(o,E)}return B.namespace=Q,B.useColors=h.useColors(),B.color=h.selectColor(Q),B.extend=y,B.destroy=h.destroy,Object.defineProperty(B,"enabled",{enumerable:!0,configurable:!1,get:()=>r!==null?r:(i!==h.namespaces&&(i=h.namespaces,e=h.enabled(Q)),e),set:E=>{r=E}}),typeof h.init=="function"&&h.init(B),B}function y(Q,I){const r=h(this.namespace+(typeof I>"u"?":":I)+Q);return r.log=this.log,r}function g(Q){h.save(Q),h.namespaces=Q,h.names=[],h.skips=[];const I=(typeof Q=="string"?Q:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const r of I)r[0]==="-"?h.skips.push(r.slice(1)):h.names.push(r)}function n(Q,I){let r=0,i=0,e=-1,B=0;for(;r<Q.length;)if(i<I.length&&(I[i]===Q[r]||I[i]==="*"))I[i]==="*"?(e=i,B=r,i++):(r++,i++);else if(e!==-1)i=e+1,B++,r=B;else return!1;for(;i<I.length&&I[i]==="*";)i++;return i===I.length}function u(){const Q=[...h.names,...h.skips.map(I=>"-"+I)].join(",");return h.enable(""),Q}function t(Q){for(const I of h.skips)if(n(Q,I))return!1;for(const I of h.names)if(n(Q,I))return!0;return!1}function A(Q){return Q instanceof Error?Q.stack||Q.message:Q}function C(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return h.enable(h.load()),h}return he=l,he}var gC;function Bg(){return gC||(gC=1,(function(l,d){var w={};d.formatArgs=y,d.save=g,d.load=n,d.useColors=h,d.storage=u(),d.destroy=(()=>{let A=!1;return()=>{A||(A=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),d.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function h(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let A;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(A=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(A[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function y(A){if(A[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+A[0]+(this.useColors?"%c ":" ")+"+"+l.exports.humanize(this.diff),!this.useColors)return;const C="color: "+this.color;A.splice(1,0,C,"color: inherit");let Q=0,I=0;A[0].replace(/%[a-zA-Z%]/g,r=>{r!=="%%"&&(Q++,r==="%c"&&(I=Q))}),A.splice(I,0,C)}d.log=console.debug||console.log||(()=>{});function g(A){try{A?d.storage.setItem("debug",A):d.storage.removeItem("debug")}catch{}}function n(){let A;try{A=d.storage.getItem("debug")||d.storage.getItem("DEBUG")}catch{}return!A&&typeof process<"u"&&"env"in process&&(A=w.DEBUG),A}function u(){try{return localStorage}catch{}}l.exports=St()(d);const{formatters:t}=l.exports;t.j=function(A){try{return JSON.stringify(A)}catch(C){return"[UnexpectedJSONParseError]: "+C.message}}})(kI,kI.exports)),kI.exports}var le={},IC;function Rt(){if(IC)return le;IC=1;var l={},d=Yg.parse,w={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443},h=String.prototype.endsWith||function(u){return u.length<=this.length&&this.indexOf(u,this.length-u.length)!==-1};function y(u){var t=typeof u=="string"?d(u):u||{},A=t.protocol,C=t.host,Q=t.port;if(typeof C!="string"||!C||typeof A!="string"||(A=A.split(":",1)[0],C=C.replace(/:\d*$/,""),Q=parseInt(Q)||w[A]||0,!g(C,Q)))return"";var I=n("npm_config_"+A+"_proxy")||n(A+"_proxy")||n("npm_config_proxy")||n("all_proxy");return I&&I.indexOf("://")===-1&&(I=A+"://"+I),I}function g(u,t){var A=(n("npm_config_no_proxy")||n("no_proxy")).toLowerCase();return A?A==="*"?!1:A.split(/[,\s]/).every(function(C){if(!C)return!0;var Q=C.match(/^(.+):(\d+)$/),I=Q?Q[1]:C,r=Q?parseInt(Q[2]):0;return r&&r!==t?!0:/^[.*]/.test(I)?(I.charAt(0)==="*"&&(I=I.slice(1)),!h.call(u,I)):u!==I}):!0}function n(u){return l[u.toLowerCase()]||l[u.toUpperCase()]||""}return le.getProxyForUrl=y,le}var PA={};const eC=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),kt=ZA({__proto__:null,default:eC},[eC]),xg=KA(kt),CC=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),Mt=ZA({__proto__:null,default:CC},[CC]),ne=KA(Mt);var BC;function mQ(){if(BC)return PA;BC=1;var l=PA&&PA.__createBinding||(Object.create?(function(r,i,e,B){B===void 0&&(B=e);var E=Object.getOwnPropertyDescriptor(i,e);(!E||("get"in E?!i.__esModule:E.writable||E.configurable))&&(E={enumerable:!0,get:function(){return i[e]}}),Object.defineProperty(r,B,E)}):(function(r,i,e,B){B===void 0&&(B=e),r[B]=i[e]})),d=PA&&PA.__setModuleDefault||(Object.create?(function(r,i){Object.defineProperty(r,"default",{enumerable:!0,value:i})}):function(r,i){r.default=i}),w=PA&&PA.__importStar||function(r){if(r&&r.__esModule)return r;var i={};if(r!=null)for(var e in r)e!=="default"&&Object.prototype.hasOwnProperty.call(r,e)&&l(i,r,e);return d(i,r),i},h=PA&&PA.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(PA,"__esModule",{value:!0}),PA.HttpProxyAgent=void 0;const y=w(Dg),g=w(xg),n=h(Bg()),u=ne,t=dI(),A=Yg,C=(0,n.default)("http-proxy-agent");class Q extends t.Agent{constructor(i,e){super(e),this.proxy=typeof i=="string"?new A.URL(i):i,this.proxyHeaders=e?.headers??{},C("Creating new HttpProxyAgent instance: %o",this.proxy.href);const B=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,""),E=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol==="https:"?443:80;this.connectOpts={...e?I(e,"headers"):null,host:B,port:E}}addRequest(i,e){i._header=null,this.setRequestProps(i,e),super.addRequest(i,e)}setRequestProps(i,e){const{proxy:B}=this,E=e.secureEndpoint?"https:":"http:",o=i.getHeader("host")||"localhost",s=`${E}//${o}`,a=new A.URL(i.path,s);e.port!==80&&(a.port=String(e.port)),i.path=String(a);const D=typeof this.proxyHeaders=="function"?this.proxyHeaders():{...this.proxyHeaders};if(B.username||B.password){const f=`${decodeURIComponent(B.username)}:${decodeURIComponent(B.password)}`;D["Proxy-Authorization"]=`Basic ${Buffer.from(f).toString("base64")}`}D["Proxy-Connection"]||(D["Proxy-Connection"]=this.keepAlive?"Keep-Alive":"close");for(const f of Object.keys(D)){const F=D[f];F&&i.setHeader(f,F)}}async connect(i,e){i._header=null,i.path.includes("://")||this.setRequestProps(i,e);let B,E;C("Regenerating stored HTTP header string for request"),i._implicitHeader(),i.outputData&&i.outputData.length>0&&(C("Patching connection write() output buffer with updated header"),B=i.outputData[0].data,E=B.indexOf(`\r
|
|
3
3
|
\r
|
|
4
4
|
`)+4,i.outputData[0].data=i._header+B.substring(E),C("Output buffer: %o",i.outputData[0].data));let o;return this.proxy.protocol==="https:"?(C("Creating `tls.Socket`: %o",this.connectOpts),o=g.connect(this.connectOpts)):(C("Creating `net.Socket`: %o",this.connectOpts),o=y.connect(this.connectOpts)),await(0,u.once)(o,"connect"),o}}Q.protocols=["http","https"],PA.HttpProxyAgent=Q;function I(r,...i){const e={};let B;for(B in r)i.includes(B)||(e[B]=r[B]);return e}return PA}var qA={};const QC=new Proxy({},{get(l,d){return d==="__esModule"?!0:new Proxy(function(){},{get:()=>()=>{},apply:()=>({})})}}),Gt=ZA({__proto__:null,default:QC},[QC]),Nt=KA(Gt);var wg={},tC;function Ut(){if(tC)return wg;tC=1;var l=wg&&wg.__importDefault||function(y){return y&&y.__esModule?y:{default:y}};Object.defineProperty(wg,"__esModule",{value:!0}),wg.parseProxyResponse=void 0;const w=(0,l(Bg()).default)("https-proxy-agent:parse-proxy-response");function h(y){return new Promise((g,n)=>{let u=0;const t=[];function A(){const i=y.read();i?r(i):y.once("readable",A)}function C(){y.removeListener("end",Q),y.removeListener("error",I),y.removeListener("readable",A)}function Q(){C(),w("onend"),n(new Error("Proxy connection ended before receiving CONNECT response"))}function I(i){C(),w("onerror %o",i),n(i)}function r(i){t.push(i),u+=i.length;const e=Buffer.concat(t,u),B=e.indexOf(`\r
|
package/dist/client/index.html
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
if (colorTheme && colorTheme !== "default") root.setAttribute("data-color-theme", colorTheme);
|
|
18
18
|
})();
|
|
19
19
|
</script>
|
|
20
|
-
<script type="module" crossorigin src="/assets/index-
|
|
21
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
20
|
+
<script type="module" crossorigin src="/assets/index-XEVKscP-.js"></script>
|
|
21
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BtDAXAo1.css">
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
24
24
|
<div id="app">
|
|
@@ -47,6 +47,12 @@ export class ProcessPool {
|
|
|
47
47
|
}
|
|
48
48
|
return all;
|
|
49
49
|
}
|
|
50
|
+
/** Return recent stderr lines for a process (tail). */
|
|
51
|
+
getRecentStderr(proc, maxLines = 12) {
|
|
52
|
+
if (!proc?.recentStderr?.length)
|
|
53
|
+
return [];
|
|
54
|
+
return proc.recentStderr.slice(Math.max(0, proc.recentStderr.length - maxLines));
|
|
55
|
+
}
|
|
50
56
|
/**
|
|
51
57
|
* Spawn a new RPC process for the given cwd.
|
|
52
58
|
* Does not wait for readiness — call waitForReady() separately.
|
|
@@ -71,8 +77,18 @@ export class ProcessPool {
|
|
|
71
77
|
env: { ...parentEnv, ...(this.spawnConfig.env ?? {}) },
|
|
72
78
|
stdio: ["pipe", "pipe", "pipe"],
|
|
73
79
|
});
|
|
80
|
+
const recentStderr = [];
|
|
74
81
|
child.stderr?.on("data", (data) => {
|
|
75
|
-
|
|
82
|
+
const text = data.toString();
|
|
83
|
+
process.stderr.write(`[pi#${procId}] ${text}`);
|
|
84
|
+
for (const line of text.split(/\r?\n/)) {
|
|
85
|
+
const trimmed = line.trim();
|
|
86
|
+
if (!trimmed)
|
|
87
|
+
continue;
|
|
88
|
+
recentStderr.push(trimmed);
|
|
89
|
+
if (recentStderr.length > 60)
|
|
90
|
+
recentStderr.splice(0, recentStderr.length - 60);
|
|
91
|
+
}
|
|
76
92
|
});
|
|
77
93
|
const rl = readline.createInterface({ input: child.stdout, terminal: false });
|
|
78
94
|
const proc = {
|
|
@@ -83,6 +99,7 @@ export class ProcessPool {
|
|
|
83
99
|
pendingRequests: new Map(),
|
|
84
100
|
requestId: 0,
|
|
85
101
|
lastResponseTime: Date.now(),
|
|
102
|
+
recentStderr,
|
|
86
103
|
};
|
|
87
104
|
// Set up response handler
|
|
88
105
|
rl.on("line", (line) => {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { WebSocket } from "ws";
|
|
13
13
|
import { copyFile } from "node:fs/promises";
|
|
14
|
+
import { existsSync } from "node:fs";
|
|
14
15
|
import path from "node:path";
|
|
15
16
|
import { URL } from "node:url";
|
|
16
17
|
import { getAgentDir } from "@mariozechner/pi-coding-agent";
|
|
@@ -379,56 +380,75 @@ export class WsHandler {
|
|
|
379
380
|
const turnId = makeTurnId();
|
|
380
381
|
debugTurn("prompt_start", { turnId, sessionPath, hasModel: !!command.model });
|
|
381
382
|
let proc;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
383
|
+
try {
|
|
384
|
+
if (sessionPath === "__new__") {
|
|
385
|
+
const cwd = command.cwd || this.defaultCwd;
|
|
386
|
+
proc = await this.acquireProcess(cwd);
|
|
387
|
+
await this.pool.waitForReady(proc);
|
|
388
|
+
await this.pool.sendRpc(proc, { type: "new_session" });
|
|
389
|
+
const stateResp = await this.pool.sendRpc(proc, { type: "get_state" });
|
|
390
|
+
sessionPath = stateResp.data?.sessionFile;
|
|
391
|
+
if (!sessionPath)
|
|
392
|
+
throw new Error("Failed to get session path from new session");
|
|
393
|
+
this.busyProcesses.add(proc);
|
|
394
|
+
// Create attached session with empty state (new session)
|
|
395
|
+
this.createAttachedSession(sessionPath);
|
|
396
|
+
ws.send(JSON.stringify({
|
|
397
|
+
type: "session_attached",
|
|
398
|
+
sessionPath,
|
|
399
|
+
cwd,
|
|
400
|
+
firstMessage: command.message,
|
|
401
|
+
}));
|
|
402
|
+
this.lifecycle.attach(sessionPath, proc);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
proc = await this.acquireForSession(sessionPath);
|
|
406
|
+
}
|
|
407
|
+
if (!command.model) {
|
|
408
|
+
throw new Error(`BUG: prompt command received without model. sessionPath=${sessionPath}`);
|
|
409
|
+
}
|
|
410
|
+
await this.pool.sendRpcChecked(proc, {
|
|
411
|
+
type: "set_model",
|
|
412
|
+
provider: command.model.provider,
|
|
413
|
+
modelId: command.model.modelId,
|
|
414
|
+
});
|
|
415
|
+
const modelState = await this.pool.sendRpcChecked(proc, { type: "get_state" });
|
|
416
|
+
const activeModel = modelState.data?.model;
|
|
417
|
+
if (!activeModel || activeModel.provider !== command.model.provider || activeModel.id !== command.model.modelId) {
|
|
418
|
+
throw new Error(`Failed to switch model to ${command.model.provider}/${command.model.modelId}`);
|
|
419
|
+
}
|
|
420
|
+
if (command.thinkingLevel) {
|
|
421
|
+
await this.pool.sendRpcChecked(proc, { type: "set_thinking_level", level: command.thinkingLevel });
|
|
422
|
+
}
|
|
423
|
+
this.setupTurnEventForwarding(proc, sessionPath, ws, turnId);
|
|
424
|
+
const promptCmd = { type: "prompt", message: command.message };
|
|
425
|
+
if (command.images?.length > 0) {
|
|
426
|
+
promptCmd.images = command.images;
|
|
427
|
+
}
|
|
428
|
+
const response = await this.pool.sendRpc(proc, promptCmd);
|
|
429
|
+
const enriched = { ...response };
|
|
430
|
+
if (!enriched.data)
|
|
431
|
+
enriched.data = {};
|
|
432
|
+
enriched.data.newSessionPath = sessionPath;
|
|
433
|
+
ws.send(JSON.stringify({ ...enriched, id, command: "prompt" }));
|
|
404
434
|
}
|
|
405
|
-
|
|
406
|
-
|
|
435
|
+
catch (err) {
|
|
436
|
+
if (proc && sessionPath && this.lifecycle.getAttachedProcess(sessionPath) === proc) {
|
|
437
|
+
const detailed = this.buildPromptFailureMessage(err, proc, sessionPath);
|
|
438
|
+
this.injectSessionError(sessionPath, detailed);
|
|
439
|
+
this.releaseProcess(sessionPath);
|
|
440
|
+
if ((err?.message || "").includes("Timeout waiting for RPC response to prompt") && proc.process.exitCode === null) {
|
|
441
|
+
proc.process.kill("SIGTERM");
|
|
442
|
+
}
|
|
443
|
+
throw new Error(detailed);
|
|
444
|
+
}
|
|
445
|
+
if (proc) {
|
|
446
|
+
this.busyProcesses.delete(proc);
|
|
447
|
+
if (proc.process.exitCode === null)
|
|
448
|
+
proc.process.kill("SIGTERM");
|
|
449
|
+
}
|
|
450
|
+
throw err;
|
|
407
451
|
}
|
|
408
|
-
await this.pool.sendRpcChecked(proc, {
|
|
409
|
-
type: "set_model",
|
|
410
|
-
provider: command.model.provider,
|
|
411
|
-
modelId: command.model.modelId,
|
|
412
|
-
});
|
|
413
|
-
const modelState = await this.pool.sendRpcChecked(proc, { type: "get_state" });
|
|
414
|
-
const activeModel = modelState.data?.model;
|
|
415
|
-
if (!activeModel || activeModel.provider !== command.model.provider || activeModel.id !== command.model.modelId) {
|
|
416
|
-
throw new Error(`Failed to switch model to ${command.model.provider}/${command.model.modelId}`);
|
|
417
|
-
}
|
|
418
|
-
if (command.thinkingLevel) {
|
|
419
|
-
await this.pool.sendRpcChecked(proc, { type: "set_thinking_level", level: command.thinkingLevel });
|
|
420
|
-
}
|
|
421
|
-
this.setupTurnEventForwarding(proc, sessionPath, ws, turnId);
|
|
422
|
-
const promptCmd = { type: "prompt", message: command.message };
|
|
423
|
-
if (command.images?.length > 0) {
|
|
424
|
-
promptCmd.images = command.images;
|
|
425
|
-
}
|
|
426
|
-
const response = await this.pool.sendRpc(proc, promptCmd);
|
|
427
|
-
const enriched = { ...response };
|
|
428
|
-
if (!enriched.data)
|
|
429
|
-
enriched.data = {};
|
|
430
|
-
enriched.data.newSessionPath = sessionPath;
|
|
431
|
-
ws.send(JSON.stringify({ ...enriched, id, command: "prompt" }));
|
|
432
452
|
}
|
|
433
453
|
async handleSteer(ws, id, command) {
|
|
434
454
|
const sessionPath = command.sessionPath;
|
|
@@ -559,39 +579,57 @@ export class WsHandler {
|
|
|
559
579
|
const newFilename = `${timestamp}_${newId}.jsonl`;
|
|
560
580
|
const newSessionPath = path.join(sessionsDir, newFilename);
|
|
561
581
|
await copyFile(sessionPath, newSessionPath);
|
|
562
|
-
const
|
|
582
|
+
const forkCwd = getSessionCwd(sessionPath);
|
|
583
|
+
const cwd = (forkCwd && existsSync(forkCwd)) ? forkCwd : this.defaultCwd;
|
|
563
584
|
const proc = await this.acquireProcess(cwd);
|
|
564
585
|
await this.pool.waitForReady(proc);
|
|
565
586
|
this.busyProcesses.add(proc);
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
587
|
+
try {
|
|
588
|
+
// Create attached session, seeded from the forked file
|
|
589
|
+
this.createAttachedSession(newSessionPath);
|
|
590
|
+
ws.send(JSON.stringify({ type: "session_attached", sessionPath: newSessionPath, cwd, firstMessage: message }));
|
|
591
|
+
this.lifecycle.attach(newSessionPath, proc);
|
|
592
|
+
await this.pool.sendRpc(proc, { type: "switch_session", sessionPath: newSessionPath });
|
|
593
|
+
if (!command.model) {
|
|
594
|
+
throw new Error(`BUG: fork_prompt command received without model. sessionPath=${newSessionPath}`);
|
|
595
|
+
}
|
|
596
|
+
await this.pool.sendRpcChecked(proc, {
|
|
597
|
+
type: "set_model",
|
|
598
|
+
provider: command.model.provider,
|
|
599
|
+
modelId: command.model.modelId,
|
|
600
|
+
});
|
|
601
|
+
const modelState = await this.pool.sendRpcChecked(proc, { type: "get_state" });
|
|
602
|
+
const activeModel = modelState.data?.model;
|
|
603
|
+
if (!activeModel || activeModel.provider !== command.model.provider || activeModel.id !== command.model.modelId) {
|
|
604
|
+
throw new Error(`Failed to switch model to ${command.model.provider}/${command.model.modelId}`);
|
|
605
|
+
}
|
|
606
|
+
if (command.thinkingLevel) {
|
|
607
|
+
await this.pool.sendRpcChecked(proc, { type: "set_thinking_level", level: command.thinkingLevel });
|
|
608
|
+
}
|
|
609
|
+
const turnId = makeTurnId();
|
|
610
|
+
this.setupTurnEventForwarding(proc, newSessionPath, ws, turnId);
|
|
611
|
+
const promptCmd = { type: "prompt", message };
|
|
612
|
+
if (command.images?.length > 0) {
|
|
613
|
+
promptCmd.images = command.images;
|
|
614
|
+
}
|
|
615
|
+
await this.pool.sendRpc(proc, promptCmd);
|
|
616
|
+
ws.send(JSON.stringify({ id, type: "response", command: "fork_prompt", success: true, data: { newSessionPath } }));
|
|
586
617
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
618
|
+
catch (err) {
|
|
619
|
+
if (this.lifecycle.getAttachedProcess(newSessionPath) === proc) {
|
|
620
|
+
const detailed = this.buildPromptFailureMessage(err, proc, newSessionPath);
|
|
621
|
+
this.injectSessionError(newSessionPath, detailed);
|
|
622
|
+
this.releaseProcess(newSessionPath);
|
|
623
|
+
if ((err?.message || "").includes("Timeout waiting for RPC response to prompt") && proc.process.exitCode === null) {
|
|
624
|
+
proc.process.kill("SIGTERM");
|
|
625
|
+
}
|
|
626
|
+
throw new Error(detailed);
|
|
627
|
+
}
|
|
628
|
+
this.busyProcesses.delete(proc);
|
|
629
|
+
if (proc.process.exitCode === null)
|
|
630
|
+
proc.process.kill("SIGTERM");
|
|
631
|
+
throw err;
|
|
592
632
|
}
|
|
593
|
-
await this.pool.sendRpc(proc, promptCmd);
|
|
594
|
-
ws.send(JSON.stringify({ id, type: "response", command: "fork_prompt", success: true, data: { newSessionPath } }));
|
|
595
633
|
}
|
|
596
634
|
async handleSetSessionName(ws, id, command) {
|
|
597
635
|
const sessionPath = command.sessionPath;
|
|
@@ -603,6 +641,33 @@ export class WsHandler {
|
|
|
603
641
|
ws.send(JSON.stringify({ ...response, id, command: "set_session_name" }));
|
|
604
642
|
}
|
|
605
643
|
// ── Internal helpers ─────────────────────────────────────────────────
|
|
644
|
+
buildPromptFailureMessage(err, proc, sessionPath) {
|
|
645
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
646
|
+
const session = this.attachedSessions.get(sessionPath);
|
|
647
|
+
const sessionError = session?.toState().error;
|
|
648
|
+
const stderrTail = this.pool.getRecentStderr(proc, 12);
|
|
649
|
+
let message = raw;
|
|
650
|
+
if (raw.includes("Timeout waiting for RPC response to prompt")) {
|
|
651
|
+
message = "Prompt timed out waiting for pi RPC response";
|
|
652
|
+
}
|
|
653
|
+
if (sessionError) {
|
|
654
|
+
message += `\nLast agent error: ${sessionError}`;
|
|
655
|
+
}
|
|
656
|
+
if (stderrTail.length > 0) {
|
|
657
|
+
message += `\nRecent pi stderr:\n${stderrTail.join("\n")}`;
|
|
658
|
+
}
|
|
659
|
+
return message;
|
|
660
|
+
}
|
|
661
|
+
injectSessionError(sessionPath, errorMessage) {
|
|
662
|
+
const session = this.attachedSessions.get(sessionPath);
|
|
663
|
+
if (!session)
|
|
664
|
+
return;
|
|
665
|
+
session.applyEvent({
|
|
666
|
+
type: "turn_end",
|
|
667
|
+
message: { role: "assistant", errorMessage },
|
|
668
|
+
});
|
|
669
|
+
this.pushUpdateToSubscribers(sessionPath, session);
|
|
670
|
+
}
|
|
606
671
|
sleep(ms) {
|
|
607
672
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
608
673
|
}
|
|
@@ -632,7 +697,8 @@ export class WsHandler {
|
|
|
632
697
|
const existing = this.lifecycle.getAttachedProcess(sessionPath);
|
|
633
698
|
if (existing)
|
|
634
699
|
return existing;
|
|
635
|
-
const
|
|
700
|
+
const sessionCwd = getSessionCwd(sessionPath);
|
|
701
|
+
const cwd = (sessionCwd && existsSync(sessionCwd)) ? sessionCwd : this.defaultCwd;
|
|
636
702
|
const proc = await this.acquireProcess(cwd);
|
|
637
703
|
this.busyProcesses.add(proc);
|
|
638
704
|
this.lifecycle.attach(sessionPath, proc);
|
|
@@ -11,21 +11,91 @@
|
|
|
11
11
|
* This module is isomorphic — works in both Node.js and browser.
|
|
12
12
|
*/
|
|
13
13
|
// ── Hashing ────────────────────────────────────────────────────────────────
|
|
14
|
+
/**
|
|
15
|
+
* Pure JS SHA-256 for environments without SubtleCrypto (HTTP browser contexts).
|
|
16
|
+
*/
|
|
17
|
+
function sha256js(str) {
|
|
18
|
+
const K = [
|
|
19
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
20
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
21
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
22
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
23
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
24
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
25
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
26
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
27
|
+
];
|
|
28
|
+
const rr = (v, n) => (v >>> n) | (v << (32 - n));
|
|
29
|
+
// UTF-8 encode
|
|
30
|
+
const bytes = new TextEncoder().encode(str);
|
|
31
|
+
const bitLen = bytes.length * 8;
|
|
32
|
+
// Padding
|
|
33
|
+
const padded = new Uint8Array(Math.ceil((bytes.length + 9) / 64) * 64);
|
|
34
|
+
padded.set(bytes);
|
|
35
|
+
padded[bytes.length] = 0x80;
|
|
36
|
+
const dv = new DataView(padded.buffer);
|
|
37
|
+
dv.setUint32(padded.length - 4, bitLen, false);
|
|
38
|
+
if (bitLen > 0xffffffff)
|
|
39
|
+
dv.setUint32(padded.length - 8, Math.floor(bitLen / 0x100000000), false);
|
|
40
|
+
let [h0, h1, h2, h3, h4, h5, h6, h7] = [
|
|
41
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
42
|
+
];
|
|
43
|
+
const w = new Int32Array(64);
|
|
44
|
+
for (let off = 0; off < padded.length; off += 64) {
|
|
45
|
+
for (let i = 0; i < 16; i++)
|
|
46
|
+
w[i] = dv.getInt32(off + i * 4, false);
|
|
47
|
+
for (let i = 16; i < 64; i++) {
|
|
48
|
+
const s0 = rr(w[i - 15], 7) ^ rr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
49
|
+
const s1 = rr(w[i - 2], 17) ^ rr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
50
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
|
51
|
+
}
|
|
52
|
+
let [a, b, c, d, e, f, g, h] = [h0, h1, h2, h3, h4, h5, h6, h7];
|
|
53
|
+
for (let i = 0; i < 64; i++) {
|
|
54
|
+
const S1 = rr(e, 6) ^ rr(e, 11) ^ rr(e, 25);
|
|
55
|
+
const ch = (e & f) ^ (~e & g);
|
|
56
|
+
const t1 = (h + S1 + ch + K[i] + w[i]) | 0;
|
|
57
|
+
const S0 = rr(a, 2) ^ rr(a, 13) ^ rr(a, 22);
|
|
58
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
59
|
+
const t2 = (S0 + maj) | 0;
|
|
60
|
+
h = g;
|
|
61
|
+
g = f;
|
|
62
|
+
f = e;
|
|
63
|
+
e = (d + t1) | 0;
|
|
64
|
+
d = c;
|
|
65
|
+
c = b;
|
|
66
|
+
b = a;
|
|
67
|
+
a = (t1 + t2) | 0;
|
|
68
|
+
}
|
|
69
|
+
h0 = (h0 + a) | 0;
|
|
70
|
+
h1 = (h1 + b) | 0;
|
|
71
|
+
h2 = (h2 + c) | 0;
|
|
72
|
+
h3 = (h3 + d) | 0;
|
|
73
|
+
h4 = (h4 + e) | 0;
|
|
74
|
+
h5 = (h5 + f) | 0;
|
|
75
|
+
h6 = (h6 + g) | 0;
|
|
76
|
+
h7 = (h7 + h) | 0;
|
|
77
|
+
}
|
|
78
|
+
return [h0, h1, h2, h3, h4, h5, h6, h7].map(v => (v >>> 0).toString(16).padStart(8, "0")).join("");
|
|
79
|
+
}
|
|
14
80
|
/**
|
|
15
81
|
* Compute a hex SHA-256 hash of a string.
|
|
16
82
|
* Works in both Node.js (crypto) and browser (SubtleCrypto).
|
|
17
83
|
*/
|
|
18
84
|
export async function computeHash(data) {
|
|
19
85
|
if (typeof globalThis.crypto?.subtle?.digest === "function") {
|
|
20
|
-
// Browser or Node 20+
|
|
86
|
+
// Browser or Node 20+ (requires secure context in browsers)
|
|
21
87
|
const encoded = new TextEncoder().encode(data);
|
|
22
88
|
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", encoded);
|
|
23
89
|
const hashArray = new Uint8Array(hashBuffer);
|
|
24
90
|
return Array.from(hashArray).map(b => b.toString(16).padStart(2, "0")).join("");
|
|
25
91
|
}
|
|
26
92
|
// Node.js fallback
|
|
27
|
-
|
|
28
|
-
|
|
93
|
+
if (typeof globalThis.process !== "undefined") {
|
|
94
|
+
const { createHash } = await import("node:crypto");
|
|
95
|
+
return createHash("sha256").update(data, "utf8").digest("hex");
|
|
96
|
+
}
|
|
97
|
+
// Browser insecure context fallback (no SubtleCrypto) — pure JS SHA-256
|
|
98
|
+
return sha256js(data);
|
|
29
99
|
}
|
|
30
100
|
// Note: computeHashSync is NOT in this shared module because it depends on
|
|
31
101
|
// node:crypto which is stubbed in the client Vite build. It lives in
|
package/package.json
CHANGED