tokmon 0.22.4 → 0.22.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.
@@ -149,7 +149,7 @@ ${t}${n[i]}`;return e.cause&&(r+=` {
149
149
  ${n4(e.cause,`${t} `)}
150
150
  ${t}}`),r},EP=`~effect/Fiber/${lhe}`,_he={_A:Fe,_E:Fe},Phe={id:0},ZC=()=>globalThis[lf];var _F;_F=EP;class r4{constructor(t,n=!0){Q(this,_F);Q(this,"id");Q(this,"interruptible");Q(this,"currentOpCount");Q(this,"currentLoopCount");Q(this,"_stack");Q(this,"_observers");Q(this,"_exit");Q(this,"_currentExit");Q(this,"_children");Q(this,"_interruptedCause");Q(this,"_yielded");Q(this,"context");Q(this,"currentScheduler");Q(this,"currentTracerContext");Q(this,"currentSpan");Q(this,"currentLogLevel");Q(this,"minimumLogLevel");Q(this,"currentStackFrame");Q(this,"runtimeMetrics");Q(this,"maxOpsBeforeYield");Q(this,"currentPreventYield");Q(this,"_dispatcher");this[EP]=_he,this.setContext(t),this.id=++Phe.id,this.currentOpCount=0,this.currentLoopCount=0,this.interruptible=n,this._stack=[],this._observers=[],this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0}get currentDispatcher(){return this._dispatcher??(this._dispatcher=this.currentScheduler.makeDispatcher())}getRef(t){return gde(this.context,t)}addObserver(t){return this._exit?(t(this._exit),kd):(this._observers.push(t),()=>{const n=this._observers.indexOf(t);n>=0&&this._observers.splice(n,1)})}interruptUnsafe(t,n){if(this._exit)return;let r=YC(t);this.currentStackFrame&&(r=PP(r,vl(Sy,this.currentStackFrame))),n&&(r=PP(r,n)),this._interruptedCause=this._interruptedCause?mhe(this._interruptedCause,r):r,this.interruptible&&this.evaluate(wn(this._interruptedCause))}pollUnsafe(){return this._exit}evaluate(t){var r,i;if((r=this.runtimeMetrics)==null||r.recordFiberStart(this.context),this._exit)return;if(this._yielded!==void 0){const o=this._yielded;this._yielded=void 0,o()}const n=this.runLoop(t);if(n!==Xa){this._exit=n,(i=this.runtimeMetrics)==null||i.recordFiberEnd(this.context,this._exit);for(let o=0;o<this._observers.length;o++)this._observers[o](n);this._observers.length=0}}runLoop(t){const n=globalThis[lf];globalThis[lf]=this;let r=!1,i=t;this.currentOpCount=0;const o=++this.currentLoopCount;try{for(;;){if(this.currentOpCount++,!r&&!this.currentPreventYield&&this.currentScheduler.shouldYield(this)){r=!0;const a=i;i=Ze(tE,()=>a)}if(i=this.currentTracerContext?this.currentTracerContext(i,this):i[dn](this),o!==this.currentLoopCount)return Xa;if(i===Xa){const a=this._yielded;return sd in a?(this._yielded=void 0,a):Xa}}}catch(a){return it(i,dn)?this.runLoop(yl(a)):yl(`Fiber.runLoop: Not a valid effect: ${String(i)}`)}finally{globalThis[lf]=n}}getCont(t){for(;;){const n=this._stack.pop();if(!n)return;const r=n[Es]&&n[Es](this);if(r)return r[t]=r,r;if(n[t])return n}}yieldWith(t){return this._yielded=t,Xa}children(){return this._children??(this._children=new Set)}pipe(){return Sn(this,arguments)}setContext(t){this.context=t;const n=this.getRef(WU);n!==this.currentScheduler&&(this.currentScheduler=n,this._dispatcher=void 0),this.currentSpan=t.mapUnsafe.get(KU),this.currentLogLevel=this.getRef(rhe),this.minimumLogLevel=this.getRef(ihe),this.currentStackFrame=t.mapUnsafe.get(YU.key),this.maxOpsBeforeYield=this.getRef(Vde),this.currentPreventYield=this.getRef(Wde),this.runtimeMetrics=t.mapUnsafe.get(Jde);const r=t.mapUnsafe.get(XU);this.currentTracerContext=r?r.context:void 0}get currentSpanLocal(){var t;return((t=this.currentSpan)==null?void 0:t._tag)==="Span"?this.currentSpan:void 0}}const Oy=e=>{if(!e.currentStackFrame)return;const t=new Map;return t.set(Sy.key,e.currentStackFrame),ca(t)},i4=e=>{const t=e;return t._exit?Be(t._exit):bi(n=>t._exit?n(Be(t._exit)):Yt(e.addObserver(r=>n(Be(r)))))},o4=e=>bi(t=>{const n=e[Symbol.iterator](),r=[];let i;function o(){let a=n.next();for(;!a.done;){if(a.value._exit){r.push(a.value._exit),a=n.next();continue}i=a.value.addObserver(u=>{r.push(u),o()});return}t(Be(r))}return o(),Yt(()=>i==null?void 0:i())}),eE=e=>ut(t=>Ohe(e,t.id)),Ohe=ce(e=>it(e[0],EP),(e,t,n)=>ut(r=>{let i=Oy(r);return i=i&&n?xl(i,n):i??n,e.interruptUnsafe(t,i),f4(i4(e))})),am=e=>ut(t=>{const n=Oy(t);for(const r of e)r.interruptUnsafe(t.id,n);return f4(o4(e))}),Be=It,wn=Vr,Cy=zi,Yt=xi({op:"Sync",[dn](e){const t=this[qe](),n=e.getCont(_r);return n?n[_r](t,e):e.yieldWith(It(t))}}),Zt=xi({op:"Suspend",[dn](e){return this[qe]()}}),Che=xi({op:"Yield",[dn](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(Hr)},this[qe]??0),e.yieldWith(()=>{t=!0})}}),tE=Che(0),Ehe=e=>Be(He(e)),khe=Be(Wr()),Ey=e=>yl(e),a4=e=>Zt(()=>Cy(Un(e))),Rt=Be(void 0),Ahe=e=>s4(function(t,n){Un(()=>e(n)).then(r=>t(Be(r)),r=>t(Ey(r)))},e.length!==0),jhe=e=>ut(t=>e(t.id)),s4=xi({op:"Async",single:!1,[dn](e){const t=Un(()=>this[qe][0].bind(e.currentScheduler));let n=!1,r=!1;const i=this[qe][1]?new AbortController:void 0,o=t(a=>{n||(n=!0,r?e.evaluate(a):r=a)},i==null?void 0:i.signal);return r!==!1?r:(r=!0,e._yielded=()=>{n=!0},i===void 0&&o===void 0||e._stack.push(The(()=>(n=!0,i==null||i.abort(),o??Hr))),Xa)}}),The=xi({op:"AsyncFinalizer",[Es](e){e.interruptible&&(e.interruptible=!1,e._stack.push(Iy))},[$i](e,t){return dhe(e)?Ze(this[qe](),()=>wn(e)):wn(e)}}),bi=e=>s4(e,e.length>=2),Rhe=bi(kd),Ihe=(...e)=>Zt(()=>fd(e.length===1?e[0]():e[1].call(e[0].self))),u4=(e,...t)=>{const n=t.length===0?function(){return Zt(()=>fd(e.apply(this,arguments)))}:function(){let r=Zt(()=>fd(e.apply(this,arguments)));for(let i=0;i<t.length;i++)r=t[i](r,...arguments);return r};return l4(e.length,n)},l4=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),Mhe=(e,...t)=>l4(e.length,t.length===0?function(){return QL(()=>e.apply(this,arguments))}:function(){let n=QL(()=>e.apply(this,arguments));for(const r of t)n=r(n);return n}),QL=e=>{try{const t=e();let n;for(;;){const r=t.next(n);if(r.done)return Be(r.value);const o=r.value.asEffect(),a=o;if(a&&a._tag==="Success"){n=a.value;continue}else{if(a&&a._tag==="Failure")return o;{let u=!0;return Zt(()=>u?(u=!1,Ze(o,c=>fd(t,c))):Zt(()=>fd(e())))}}}}catch(t){return Ey(t)}},fd=xi({op:"Iterator",single:!1,[_r](e,t){const n=this[qe][0];for(;;){const r=n.next(e);if(r.done)return Be(r.value);const i=r.value.asEffect();if(Pr(i)){if(i._tag==="Failure")return i}else return t._stack.push(this),i;e=i.value}},[dn](e){return this[_r](this[qe][1],e)}}),Nl=ce(2,(e,t)=>{const n=Be(t);return Ze(e,r=>n)}),Td=ce(2,(e,t)=>Ze(e,n=>Ln(t)?t:Un(()=>t(n)))),c4=ce(2,(e,t)=>Ze(e,n=>Nl(Ln(t)?t:Un(()=>t(n)),n))),f4=e=>Ze(e,t=>Hr),$he=(e,t)=>ut(n=>bi(r=>{let i=!1;const o=new Set,a=c=>{i=!0,r(o.size===0?c:Ze(_4(am(o)),()=>c))};let u=0;for(const c of e){if(i)break;const f=u++,h=$y(n,c,!0,!0,!1);o.add(h),h.addObserver(d=>{o.delete(h);const g=!i;a(d),g&&(t!=null&&t.onWinner)&&t.onWinner({fiber:h,index:f,parentFiber:n})})}return am(o)})),d4=ce(e=>Ln(e[1]),(e,t,n)=>$he([e,t],n)),Ze=ce(2,(e,t)=>{const n=Object.create(Nhe);return n[qe]=e,n[_r]=t.length!==1?r=>t(r):t,n}),Nhe=jd({op:"OnSuccess",[dn](e){return e._stack.push(this),this[qe]}}),Pr=e=>sd in e,Lhe=ce(2,(e,t)=>Pr(e)?e._tag==="Success"?t(e.value):e:Ze(e,t)),Dhe=e=>Ze(e,Fe),Qt=ce(2,(e,t)=>Ze(e,n=>Be(Un(()=>t(n))))),Fhe=ce(2,(e,t)=>Pr(e)?Hhe(e,t):Qt(e,t)),Bhe=ce(2,(e,t)=>Pr(e)?Ghe(e,t):ape(e,t)),zhe=ce(2,(e,t)=>Pr(e)?Khe(e,t):spe(e,t)),qhe=ce(2,(e,t)=>{if(Pr(e)){if(e._tag==="Success")return e;const n=Fs(e.cause);return hn(n)?e:t(n.success)}return Ay(e,t)}),Uhe=e=>Vr(YC(e)),nE=e=>e._tag==="Success",Vhe=e=>e._tag==="Failure",Whe=e=>e._tag==="Failure"?So(e.cause):pi(e),Hr=It(void 0),Hhe=ce(2,(e,t)=>e._tag==="Success"?It(t(e.value)):e),Ghe=ce(2,(e,t)=>{if(e._tag==="Success")return e;const n=Fs(e.cause);return hn(n)?e:zi(t(n.success))}),Khe=ce(2,(e,t)=>{if(e._tag==="Success")return It(t.onSuccess(e.value));const n=Fs(e.cause);return hn(n)?e:zi(t.onFailure(n.success))}),Xhe=ce(2,(e,t)=>nE(e)?t:e),Yhe=e=>{const t=[];for(const n of e)n._tag==="Failure"&&t.push(...n.cause.reasons);return t.length===0?Hr:Vr(ud(t))},Qhe=e=>nE(e)?He(e.value):Wr(),Jhe=e=>ut(t=>Be(yde(t.context,e))),ky=ce(2,(e,t)=>ut(n=>{const r=n.context,i=t(r);return r===i?e:(n.setContext(i),S4(e,()=>{n.setContext(r)}))})),h4=ce(3,(e,t,n)=>ky(e,r=>{const i=_y(r,t),o=n(i);return i===o?r:Aa(r,t,o)})),Zhe=()=>epe,epe=ut(e=>Be(e.context)),p4=e=>ut(t=>e(t.context)),Rd=ce(2,(e,t)=>Pr(e)?e:ky(e,xl(t))),Id=function(){return arguments.length===1?ce(2,(e,t)=>JL(e,arguments[0],t)):ce(3,(e,t,n)=>JL(e,t,n)).apply(this,arguments)},JL=(e,t,n)=>ky(e,r=>r.mapUnsafe.get(t.key)===n?r:Aa(r,t,n)),g4=ce(e=>Ln(e[1]),(e,t,n)=>tpe(e,t,(r,i)=>[r,i],n)),tpe=ce(e=>Ln(e[1]),(e,t,n,r)=>r!=null&&r.concurrent?Qt(Ape([e,t],{concurrency:2}),([i,o])=>Un(()=>n(i,o))):Ze(e,i=>Qt(t,o=>Un(()=>n(i,o))))),npe=ce(e=>Ln(e[0]),(e,t)=>aE({while:$C,body:Oa(t!=null&&t.disableYield?e:Ze(e,n=>tE)),step:kd})),Md=ce(2,(e,t)=>{const n=Object.create(rpe);return n[qe]=e,n[$i]=t.length!==1?r=>t(r):t,n}),rpe=jd({op:"OnFailure",[dn](e){return e._stack.push(this),this[qe]}}),m4=ce(3,(e,t,n)=>Md(e,r=>{const i=t(r);return hn(i)?wn(i.failure):Un(()=>n(i.success,r))})),Ay=ce(2,(e,t)=>m4(e,Fs,n=>t(n))),ipe=ce(2,(e,t)=>Md(e,n=>Td(Un(()=>t(n)),wn(n)))),ope=ce(e=>Ln(e[0]),(e,t,n,r)=>Md(e,i=>{const o=Fs(i);if(hn(o))return wn(o.failure);const a=t(o.success);return hn(a)?r?Un(()=>r(a.failure)):wn(i):Un(()=>n(a.success))})),ape=ce(2,(e,t)=>Ay(e,n=>a4(()=>t(n)))),spe=ce(2,(e,t)=>rE(e,{onFailure:n=>a4(()=>t.onFailure(n)),onSuccess:n=>Yt(()=>t.onSuccess(n))})),upe=e=>Ay(e,Ey),lpe=ce(e=>Ln(e[0]),(e,t)=>{if(!(t!=null&&t.log))return rE(e,{onFailure:r=>Rt,onSuccess:r=>Rt});const n=L4(t.log===!0?void 0:t.log);return jy(e,{onFailure(r){const i=fhe(r);return hn(i)?wn(i.failure):t.message===void 0?n(r):n(t.message,r)},onSuccess:r=>Rt})}),g1=e=>dpe(e,{onFailure:pi,onSuccess:So}),jy=ce(2,(e,t)=>{const n=Object.create(cpe);return n[qe]=e,n[_r]=t.onSuccess.length!==1?r=>t.onSuccess(r):t.onSuccess,n[$i]=t.onFailure.length!==1?r=>t.onFailure(r):t.onFailure,n}),cpe=jd({op:"OnSuccessAndFailure",[dn](e){return e._stack.push(this),this[qe]}}),rE=ce(2,(e,t)=>jy(e,{onFailure:n=>{const r=n.reasons.find(zC);return r?Un(()=>t.onFailure(r.error)):wn(n)},onSuccess:t.onSuccess})),fpe=ce(2,(e,t)=>rE(e,{onFailure:n=>Yt(()=>t.onFailure(n)),onSuccess:n=>Yt(()=>t.onSuccess(n))})),dpe=ce(2,(e,t)=>{if(Pr(e)){if(e._tag==="Success")return It(t.onSuccess(e.value));const n=Fs(e.cause);return hn(n)?e:It(t.onFailure(n.success))}return fpe(e,t)}),Ty=e=>Pr(e)?It(e):hpe(e),hpe=xi({op:"Exit",[dn](e){return e._stack.push(this),this[qe]},[_r](e,t,n){return Be(n??It(e))},[$i](e,t,n){return Be(n??Vr(e))}}),ppe=ce(2,(e,t)=>Td(lE(t),e)),y4=ce(2,(e,t)=>d4(e,Ze(lE(t.duration),t.orElse))),gpe=ce(2,(e,t)=>y4(e,{duration:t,orElse:()=>Cy(new Jpe)})),ZL="~effect/Scope",eD="~effect/Scope/Closeable",Ry=Xr("effect/Scope"),v4=(e,t)=>Zt(()=>x4(e,t)??Rt),x4=(e,t)=>{if(e.state._tag==="Closed")return;const n={_tag:"Closed",exit:t};if(e.state._tag==="Empty"){e.state=n;return}const{finalizers:r}=e.state;if(e.state=n,r.size!==0)return r.size===1?r.values().next().value(t):mpe(e,r,t)},mpe=u4(function*(e,t,n){let r=[];const i=[],o=Array.from(t.values()),a=ZC();for(let u=o.length-1;u>=0;u--){const c=o[u];e.strategy==="sequential"?r.push(yield*Ty(c(n))):i.push($y(a,c(n),!0,!0,"inherit"))}return i.length>0&&(r=yield*o4(i)),yield*Yhe(r)}),ype=(e,t)=>{const n=oE(t);if(e.state._tag==="Closed")return n.state=e.state,n;const r={};return dd(e,r,i=>v4(n,i)),dd(n,r,i=>Yt(()=>iE(e,r))),n},bl=(e,t)=>Zt(()=>e.state._tag==="Closed"?t(e.state.exit):(dd(e,{},t),Rt)),vpe=(e,t)=>bl(e,Oa(t)),dd=(e,t,n)=>{e.state._tag==="Empty"?e.state={_tag:"Open",finalizers:new Map([[t,n]])}:e.state._tag==="Open"&&e.state.finalizers.set(t,n)},iE=(e,t)=>{e.state._tag==="Open"&&e.state.finalizers.delete(t)},oE=(e="sequential")=>({[eD]:eD,[ZL]:ZL,strategy:e,state:xpe}),xpe={_tag:"Empty"},b4=Ry.asEffect(),bpe=Id(Ry),w4=e=>Zt(()=>{const t=oE();return ja(e(t),n=>Zt(()=>x4(t,n)??Rt))}),wpe=(e,t,n)=>p4(r=>C4(i=>Ze(b4,o=>c4(n!=null&&n.interruptible?i(e):e,a=>bl(o,u=>Rd(t(a,u),r)))))),S4=xi({op:"OnExit",single:!1,[dn](e){return e._stack.push(this),this[qe][0]},[Es](e){e.interruptible&&this[qe][2]!==!0&&(e._stack.push(Iy),e.interruptible=!1)},[_r](e,t,n){n??(n=It(e));const r=this[qe][1](n);return r?Ze(r,i=>n):n},[$i](e,t,n){n??(n=Vr(e));const r=this[qe][1](n);return r?Ze(r,i=>n):n}}),ja=ce(2,S4),Spe=ce(2,(e,t)=>ja(e,n=>t)),_pe=ce(3,(e,t,n)=>ja(e,r=>{const i=t(r);return hn(i)?Rt:n(i.success,r)})),Ppe=ce(2,(e,t)=>_pe(e,Whe,t)),Ope=ce(3,(e,t,n)=>ja(e,r=>{if(r._tag!=="Failure")return Rt;const i=t(r.cause);return hn(i)?Rt:n(i.success,r.cause)})),Cpe=ce(2,(e,t)=>Ope(QC,t)(e)),Epe=ut(e=>wn(YC(e.id))),_4=e=>ut(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(Iy)),e)),P4=xi({op:"SetInterruptible",[Es](e){if(e.interruptible=this[qe],e._interruptedCause&&e.interruptible)return()=>wn(e._interruptedCause)}}),Iy=P4(!0),kpe=P4(!1),O4=e=>ut(t=>t.interruptible?e:(t.interruptible=!0,t._stack.push(kpe),t._interruptedCause?wn(t._interruptedCause):e)),C4=e=>ut(t=>t.interruptible?(t.interruptible=!1,t._stack.push(Iy),e(O4)):e(Fe)),Ape=(e,t)=>qce(e)?(t==null?void 0:t.mode)==="result"?Ya(e,g1,t):Ya(e,Fe,t):t!=null&&t.discard?t.mode==="result"?Ya(Object.values(e),g1,t):Ya(Object.values(e),Fe,t):Zt(()=>{const n={};return Nl(Ya(Object.entries(e),([r,i])=>Qt((t==null?void 0:t.mode)==="result"?g1(i):i,o=>{n[r]=o}),{discard:!0,concurrency:t==null?void 0:t.concurrency}),n)}),aE=xi({op:"While",[_r](e,t){return this[qe].step(e),this[qe].while()?(t._stack.push(this),this[qe].body()):Hr},[dn](e){return this[qe].while()?(e._stack.push(this),this[qe].body()):Hr}}),Ya=ce(e=>typeof e[1]=="function",(e,t,n)=>ut(r=>{const i=(n==null?void 0:n.concurrency)==="inherit"?r.getRef(Zde):(n==null?void 0:n.concurrency)??1,o=i==="unbounded"?Number.POSITIVE_INFINITY:Math.max(1,i);if(o===1)return jpe(e,t,n);const a=Fi(e);let u=a.length;if(u===0)return n!=null&&n.discard?Rt:Be([]);const c=n!=null&&n.discard?void 0:new Array(u),f=Tpe({f:t,out:c},a,{concurrency:o});return f?Nl(f,c):Be(c)})),jpe=(e,t,n)=>Zt(()=>{const r=n!=null&&n.discard?void 0:[],i=e[Symbol.iterator]();let o=i.next(),a=0;return Nl(aE({while:()=>!o.done,body:()=>t(o.value,a++),step:u=>{r&&r.push(u),o=i.next()}}),r)}),E4=e=>{const t=e.onItem,n=e.step;return(r,i,o)=>{let a=(o==null?void 0:o.start)??0;const u=(o==null?void 0:o.end)??i.length,c=(o==null?void 0:o.concurrency)??1;let f=!1,h,d,g,m=!1,v,x;const b=()=>{let O=!1;for(;!v&&a<u;a++){const _=i[a],C=x??t(r,_,a);if(Pr(C)){if(v=n(r,_,C,a),v)break}else{if(c===1)return Ze(Ty(C),E=>(v=n(r,_,E,a),a++,v??b()??Rt));if(h){x=void 0;const E=$y(h,C,!0,!0,"inherit");if(E._exit){if(v=n(r,_,E._exit,a),v)break;continue}d?d.add(E):d=new Set([E]);const P=a;if(E.addObserver(A=>{if(d.delete(E),v){if(!m&&A._tag==="Failure")for(const j of A.cause.reasons)j._tag!=="Interrupt"&&(v._tag==="Failure"?v.cause.reasons.push(j):v=Vr(ud([j])))}else{const j=n(r,_,A,P);j&&(v=j._tag==="Failure"?Vr(ud(j.cause.reasons.slice())):j,b())}if(O){const j=b();j&&g(j)}else f&&d.size===0&&g(v??Rt)}),d.size<c)continue;O=!0,a++;return}else return bi(E=>{h=ZC(),x=C,g=E;const P=b();return P?E(P):Zt(()=>(v=Hr,m=!0,d?am(d):Rt))})}}if(f=!0,v){if(d&&d.size>0){const _=Oy(h);d.forEach(C=>C.interruptUnsafe(h.id,_));return}if(g||v._tag==="Failure")return v}else if(g)if(d)d.size===0&&g(Rt);else return Hr};return b()}},My=()=>E4,Tpe=E4({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag==="Failure")return n;e.out&&(e.out[r]=n.value)}}),$y=(e,t,n=!1,r=!1,i=!1)=>{const o=i==="inherit"?e.interruptible:!i,a=new r4(e.context,o);return n?a.evaluate(t):e.currentDispatcher.scheduleTask(()=>a.evaluate(t),0),!r&&!a._exit&&(e.children().add(a),a.addObserver(()=>e._children.delete(a))),a},k4=ce(e=>Ln(e[0]),(e,t,n)=>ut(r=>{const i=$y(r,e,n==null?void 0:n.startImmediately,!0,n==null?void 0:n.uninterruptible);if(!i._exit)if(t.state._tag!=="Closed"){const o={};dd(t,o,()=>jhe(u=>u===i.id?Rt:eE(i))),i.addObserver(()=>iE(t,o))}else i.interruptUnsafe(r.id,Oy(r));return Be(i)})),Rpe=ce(e=>Ln(e[0]),(e,t)=>Ze(b4,n=>k4(e,n,t))),$d=e=>(t,n)=>{const r=new r4(n!=null&&n.scheduler?Aa(e,WU,n.scheduler):e,(n==null?void 0:n.uninterruptible)!==!0);if(r.evaluate(t),r._exit)return r;if(n!=null&&n.signal)if(n.signal.aborted)r.interruptUnsafe();else{const i=()=>r.interruptUnsafe();n.signal.addEventListener("abort",i,{once:!0}),r.addObserver(()=>n.signal.removeEventListener("abort",i))}return n!=null&&n.onFiberStart&&n.onFiberStart(r),r},Ipe=ce(2,(e,t)=>{if(e._exit)return e;if(t.state._tag==="Closed")return e.interruptUnsafe(e.id),e;const n={};return dd(t,n,()=>eE(e)),e.addObserver(()=>iE(t,n)),e}),Mpe=$d(gi()),A4=e=>{const t=$d(e);return(n,r)=>{const i=t(n,r);return r!=null&&r.onExit&&i.addObserver(r.onExit),o=>i.interruptUnsafe(o)}},$pe=A4(gi()),sE=e=>{const t=$d(e);return(n,r)=>{const i=t(n,r);return new Promise(o=>{i.addObserver(a=>o(a))})}},Npe=sE(gi()),j4=e=>{const t=sE(e);return(n,r)=>t(n,r).then(i=>{if(i._tag==="Failure")throw JC(i.cause);return i.value})},Lpe=j4(gi()),uE=e=>{const t=$d(e);return n=>{var o;if(Pr(n))return n;const r=new GU("sync"),i=t(n,{scheduler:r});return(o=i.currentDispatcher)==null||o.flush(),i._exit??yl(new Zpe(i))}},Dpe=uE(gi()),T4=e=>{const t=uE(e);return n=>{const r=t(n);if(r._tag==="Failure")throw JC(r.cause);return r.value}},Fpe=T4(gi()),tD=Be(!0),nD=Be(!1);class Bpe{constructor(t){Q(this,"waiters",[]);Q(this,"scheduled",!1);Q(this,"isOpen");Q(this,"flushWaiters",()=>{this.scheduled=!1;const t=this.waiters;this.waiters=[];for(let n=0;n<t.length;n++)t[n](Hr)});Q(this,"open",ut(t=>this.isOpen?nD:(this.isOpen=!0,this.scheduleUnsafe(t))));Q(this,"release",ut(t=>this.isOpen?nD:this.scheduleUnsafe(t)));Q(this,"await",bi(t=>this.isOpen?t(Rt):(this.waiters.push(t),Yt(()=>{const n=this.waiters.indexOf(t);n!==-1&&this.waiters.splice(n,1)}))));Q(this,"close",Yt(()=>this.closeUnsafe()));Q(this,"whenOpen",t=>Ze(this.await,()=>t));this.isOpen=t}scheduleUnsafe(t){return this.scheduled||this.waiters.length===0||(this.scheduled=!0,t.currentDispatcher.scheduleTask(this.flushWaiters,0)),tD}openUnsafe(){return this.isOpen?!1:(this.isOpen=!0,this.flushWaiters(),!0)}closeUnsafe(){return this.isOpen?(this.isOpen=!1,!0):!1}}const zpe=e=>new Bpe(e??!1),kP=BigInt(0),qpe={_tag:"Span",spanId:"noop",traceId:"noop",sampled:!1,status:{_tag:"Ended",startTime:kP,endTime:kP,exit:Hr},attributes:new Map,links:[],kind:"internal",attribute(){},event(){},end(){},addLinks(){}},Upe=e=>Object.assign(Object.create(qpe),e),R4=e=>e?hs(e.annotations,OP)?e._tag==="Span"?R4(MU(e.parent)):Wr():He(e):Wr(),I4=(e,t,n)=>{const r=!e.getRef(ehe)||(n==null?void 0:n.annotations)&&hs(n.annotations,OP),i=(n==null?void 0:n.parent)!==void 0?He(n.parent):n!=null&&n.root?Wr():R4(e.currentSpan);let o;if(r)o=Upe({name:t,parent:i,annotations:Aa((n==null?void 0:n.annotations)??gi(),OP,!0)});else{const a=e.getRef(Yde),u=e.getRef(Ll),c=e.getRef(QU),f=e.getRef(the),h=e.getRef(nhe),d=(n==null?void 0:n.level)??e.getRef(Kde),g=(n==null?void 0:n.links)!==void 0?[...h,...n.links]:h.slice();o=a.span({name:t,parent:i,annotations:(n==null?void 0:n.annotations)??gi(),links:g,startTime:c?u.currentTimeNanosUnsafe():BigInt(0),kind:(n==null?void 0:n.kind)??"internal",root:(n==null?void 0:n.root)??Ds(i),sampled:(n==null?void 0:n.sampled)??(ga(i)&&i.value.sampled===!1?!1:!$4(e.getRef(Xde),d))});for(const[m,v]of Object.entries(f))o.attribute(m,v);if((n==null?void 0:n.attributes)!==void 0)for(const[m,v]of Object.entries(n.attributes))o.attribute(m,v)}return o},Vpe=(e,t)=>_4(ut(n=>{const r=_y(n.context,Ry),i=I4(n,e,t??{}),o=n.getRef(Ll),a=n.getRef(QU);return Nl(bl(r,u=>Hpe(i,u,o,a)),i)})),Wpe=(e,t)=>(t=typeof t=="function"?t:hy,h4(YU,n=>({name:e,stack:t,parent:n}))),Hpe=(e,t,n,r)=>Yt(()=>{e.status._tag!=="Ended"&&e.end(r?n.currentTimeNanosUnsafe():kP,t)}),Gpe=(e,...t)=>{const n=t.length===1?void 0:t[0],r=t[t.length-1];return ut(i=>{const o=I4(i,e,n),a=i.getRef(Ll);return ja(Un(()=>r(o)),u=>Yt(()=>{o.status._tag!=="Ended"&&o.end(a.currentTimeNanosUnsafe(),u)}))})},rD=Id(Hde),Kpe=function(){const e=Ln(arguments[0]),t=e?arguments[1]:arguments[0];let n=e?arguments[2]:arguments[1],r=Fe;return t._tag==="Span"&&(n=ahe(n),r=Wpe(t.name,n==null?void 0:n.captureStackTrace)),e?rD(r(arguments[0]),t):i=>rD(r(i),t)},Ll=Pt("effect/Clock",{defaultValue:()=>new Ype}),Xpe=2**31-1;class Ype{constructor(){Q(this,"currentTimeMillis",Yt(()=>this.currentTimeMillisUnsafe()));Q(this,"currentTimeNanos",Yt(()=>this.currentTimeNanosUnsafe()))}currentTimeMillisUnsafe(){return Date.now()}currentTimeNanosUnsafe(){return Qpe()}sleep(t){const n=zU(t);return n<=0?tE:bi(r=>{if(n>Xpe)return;const i=setTimeout(()=>r(Rt),n);return Yt(()=>clearTimeout(i))})}}const iD=(function(){const e=BigInt(1e6);if(typeof performance>"u"||typeof performance.now>"u")return()=>BigInt(Date.now())*e;if(typeof performance.timeOrigin=="number"&&performance.timeOrigin===0)return()=>BigInt(Math.round(performance.now()*1e6));const t=BigInt(Date.now())*e-BigInt(Math.round(performance.now()*1e6));return()=>t+BigInt(Math.round(performance.now()*1e6))})(),Qpe=(function(){const e=typeof process=="object"&&"hrtime"in process&&typeof process.hrtime.bigint=="function"?process.hrtime:void 0;if(!e)return iD;const t=iD()-e.bigint();return()=>t+e.bigint()})(),M4=e=>ut(t=>e(t.getRef(Ll))),lE=e=>M4(t=>t.sleep(GC(e))),oD="~effect/Cause/TimeoutError";var PF,OF;class Jpe extends(OF=UC("TimeoutError"),PF=oD,OF){constructor(n){super({message:n});Q(this,PF,oD)}}const aD="~effect/Cause/AsyncFiberError";var CF,EF;class Zpe extends(EF=UC("AsyncFiberError"),CF=aD,EF){constructor(n){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:n});Q(this,CF,aD)}}const ege=Pt("effect/Console/CurrentConsole",{defaultValue:()=>globalThis.console}),tge=e=>{switch(e){case"All":return Number.MIN_SAFE_INTEGER;case"Fatal":return 5e4;case"Error":return 4e4;case"Warn":return 3e4;case"Info":return 2e4;case"Debug":return 1e4;case"Trace":return 0;case"None":return Number.MAX_SAFE_INTEGER}},nge=zfe(Bfe,tge),$4=qfe(nge),rge=Pt("effect/Loggers/CurrentLoggers",{defaultValue:()=>new Set([fge,dge])}),ige=Pt("effect/Logger/LogToStderr",{defaultValue:aU}),oge="~effect/Logger",age={[oge]:{_Message:Fe,_Output:Fe},pipe(){return Sn(this,arguments)}},N4=e=>{const t=Object.create(age);return t.log=e,t},sge=e=>e.replace(/[\s="]/g,"_"),uge=(e,t)=>`${sge(e[0])}=${t-e[1]}ms`,L4=e=>(...t)=>{let n;for(let r=0,i=t.length;r<i;r++){const o=t[r];by(o)&&(n?t.splice(r,1):t=t.slice(0,r).concat(t.slice(r+1)),n=n?ud(n.reasons.concat(o.reasons)):o,r--)}return n===void 0&&(n=Sfe),ut(r=>{const i=e??r.currentLogLevel;if($4(r.minimumLogLevel,i))return Rt;const o=r.getRef(Ll),a=r.getRef(rge);if(a.size>0){const u=new Date(o.currentTimeMillisUnsafe());for(const c of a)c.log({cause:n,fiber:r,date:u,logLevel:i,message:t})}return Rt})},lge=e=>`${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}.${e.getMilliseconds().toString().padStart(3,"0")}`,cge=typeof process=="object"&&process!==null&&typeof process.stdout=="object"&&process.stdout!==null;cge&&process.stdout.isTTY;const fge=N4(({cause:e,date:t,fiber:n,logLevel:r,message:i})=>{const o=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&o.push(t4(e));const a=t.getTime(),u=n.getRef(ohe);let c="";for(const g of u)c+=` ${uge(g,a)}`;const f=n.getRef(XC);Object.keys(f).length>0&&o.push(f);const h=n.getRef(ege);(n.getRef(ige)?h.error:h.log)(`[${lge(t)}] ${r.toUpperCase()} (#${n.id})${c}:`,...o)}),dge=N4(({cause:e,fiber:t,logLevel:n,message:r})=>{const i=t.getRef(Ll),o=t.getRef(XC),a=t.currentSpan;if(a===void 0||a._tag==="ExternalSpan")return;const u={};for(const[c,f]of Object.entries(o))u[c]=f;u["effect.fiberId"]=t.id,u["effect.logLevel"]=n.toUpperCase(),e.reasons.length>0&&(u["effect.cause"]=t4(e)),a.event(pfe(Array.isArray(r)&&r.length===1?r[0]:r),i.currentTimeNanosUnsafe(),u)}),hge=by,pge=wfe,AP=ud,jP=e=>new yU(e),TP=e=>new xU(e),RP=che,gge=ghe,D4=JC,Nd=Fs,mge=hhe,yge=QC,cE=Afe,ps=Tfe,vge=mU,m1=It,cf=Vr,Ld=zi,xge=yl,bge=Uhe,F4=Hr,wge=nE,B4=Vhe,Sge=Qhe,_ge="~effect/Deferred",Pge={[_ge]:{_A:Fe,_E:Fe},pipe(){return Sn(this,arguments)}},fE=()=>{const e=Object.create(Pge);return e.resumes=void 0,e.effect=void 0,e},dE=e=>bi(t=>e.effect?t(e.effect):(e.resumes??(e.resumes=[]),e.resumes.push(t),Yt(()=>{const n=e.resumes.indexOf(t);e.resumes.splice(n,1)}))),Oge=ce(2,(e,t)=>Yt(()=>ff(e,t))),z4=Oge,ff=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){for(let n=0;n<e.resumes.length;n++)e.resumes[n](t);e.resumes=void 0}return!0},Cge=ce(2,(e,t)=>C4(n=>Ze(Ty(n(e)),r=>z4(t,r)))),Ege=XC,sD=Ry,hE=oE,sm=bpe,kge=bl,Age=vpe,um=ype,Ny=v4,jge="~effect/Layer",uD="~effect/Layer/MemoMap",Tge={[jge]:{_ROut:Fe,_E:Fe,_RIn:Fe},pipe(){return Sn(this,arguments)}},q4=e=>{const t=Object.create(Tge);return t.build=e,t},pE=e=>q4((t,n)=>{const r=um(n);return ja(e(t,r),i=>i._tag==="Failure"?Ny(r,i):Rt)}),Rge=e=>{const t=pE((n,r)=>n.getOrElseMemoize(t,r,e));return t};class Ige{constructor(){Q(this,"map",new Map)}get[uD](){return uD}getOrElseMemoize(t,n,r){if(this.map.has(t)){const u=this.map.get(t);return u.observers++,Td(bl(n,c=>u.finalizer(c)),u.effect)}const i=hE(),o=fE(),a={observers:1,effect:dE(o),finalizer:u=>Zt(()=>(a.observers--,a.observers===0?(this.map.delete(t),Ny(i,u)):Rt))};return this.map.set(t,a),bl(n,a.finalizer).pipe(Ze(()=>r(this,i)),ja(u=>(a.effect=u,z4(o,u))))}}const gE=()=>new Ige,Sm=class Sm extends Xr()("effect/Layer/CurrentMemoMap"){};Q(Sm,"getOrCreate",pde(Sm,gE));let hd=Sm;const mE=ce(3,(e,t,n)=>Id(Qt(e.build(t,n),Aa(hd,t)),hd,t)),Mge=ce(2,(e,t)=>ut(n=>mE(e,hd.getOrCreate(n.context),t))),yE=function(){return arguments.length===1?e=>lD(vl(arguments[0],e)):lD(vl(arguments[0],arguments[1]))},lD=e=>q4(Oa(Be(e))),IP=function(){return arguments.length===1?e=>cD(arguments[0],e):cD(arguments[0],arguments[1])},cD=(e,t)=>MP(Qt(t,n=>vl(e,n))),MP=e=>Rge((t,n)=>sm(e,n)),U4=(e,t,n)=>{const r=um(n,"parallel");return Ya(e,i=>i.build(t,um(r,"sequential")),{concurrency:e.length}).pipe(Qt(i=>vde(...i)))},V4=(...e)=>pE((t,n)=>U4(e,t,n)),$ge=(e,t,n)=>pE((r,i)=>Ze(Array.isArray(t)?U4(t,r,i):t.build(r,i),o=>e.build(r,i).pipe(Rd(o),Qt(a=>n(a,o))))),$P=ce(2,(e,t)=>$ge(e,t,Fe)),Nge=class extends dy{constructor(t){super(),t&&Object.assign(this,t)}},wl=ce(2,(e,t)=>m4(e,Fge,n=>t(n))),fD=e=>e.reasons.some(Lge),Lge=e=>e._tag==="Fail"&&cE(e.error),Dge=VU(Nd,e=>cE(e)?So(e):pi(e)),Fge=VU(Nd,e=>cE(e)?So(e.value):pi(e)),vE=ce(2,(e,t)=>jy(e,{onSuccess:t.onSuccess,onFailure:n=>{const r=Dge(n);return hn(r)?t.onFailure(r.failure):t.onDone(r.success.value)}})),W4="~effect/Schedule",dD=Pt("effect/Schedule/CurrentMetadata",{defaultValue:Oa({input:void 0,output:void 0,duration:KC,attempt:0,start:0,now:0,elapsed:0,elapsedSincePrevious:0})}),Bge={[W4]:{_Out:Fe,_In:Fe,_Env:Fe},pipe(){return Sn(this,arguments)}},zge=e=>it(e,W4),Dd=e=>{const t=Object.create(Bge);return t.step=e,t},xE=()=>{let e=0,t,n;return(r,i)=>{n===void 0&&(n=r);const o=r-n,a=t===void 0?0:r-t;return t=r,{input:i,attempt:++e,start:n,now:r,elapsed:o,elapsedSincePrevious:a}}},H4=e=>Dd(Qt(e,t=>{const n=xE();return(r,i)=>t(n(r,i))})),ks=e=>Md(e.step,t=>Be(()=>wn(t))),qge=e=>M4(t=>Qt(ks(e),n=>{const r=xE();return i=>Zt(()=>{const o=t.currentTimeMillisUnsafe();return Ze(n(o,i),([a,u])=>{const c=r(o,i);return c.output=a,c.duration=u,Nl(lE(u),c)})})})),Uge=ce(2,(e,t)=>Vge(e,t,(n,r)=>[n,r])),Vge=ce(3,(e,t,n)=>Dd(Qt(g4(ks(e),ks(t)),([r,i])=>(o,a)=>vE(r(o,a),{onSuccess:u=>i(o,a).pipe(Qt(c=>[n(u[0],c[0]),Lde(u[1],c[1])]),wl(c=>ps(n(u[0],c)))),onDone:u=>i(o,a).pipe(Ze(c=>ps(n(u,c[0]))),wl(c=>ps(n(u,c)))),onFailure:wn})))),G4=ce(2,(e,t)=>Wge(e,t,(n,r)=>[n,r])),Wge=ce(3,(e,t,n)=>Dd(Qt(g4(ks(e),ks(t)),([r,i])=>(o,a)=>vE(r(o,a),{onSuccess:u=>i(o,a).pipe(Qt(c=>[n(u[0],c[0]),Nde(u[1],c[1])]),wl(c=>Be([n(u[0],c),u[1]]))),onFailure:wn,onDone:u=>i(o,a).pipe(Qt(c=>[n(u,c[0]),c[1]]),wl(c=>ps(n(u,c))))})))),K4=(e,t=2)=>{const n=zU(GC(e));return H4(Be(r=>{const i=cd(n*Math.pow(t,r.attempt-1));return Be([i,i])}))},X4=e=>Dd(Qt(ks(e),t=>(n,r)=>vE(t(n,r),{onSuccess:i=>Be([r,i[1]]),onFailure:wn,onDone:()=>ps(r)}))),Hge=e=>Bp(Y4,({attempt:t})=>Be(t<=e)),bE=e=>{const t=GC(e);return H4(Be(n=>Be([n.attempt-1,t])))},Bp=ce(2,(e,t)=>Dd(Qt(ks(e),n=>{const r=xE();return(i,o)=>Ze(n(i,o),a=>{const[u,c]=a,f=t({...r(i,o),output:u,duration:c});return Ze(Ln(f)?f:Be(f),h=>h?Be(a):ps(u))})}))),Y4=bE(KC),Gge=(e,t,n)=>w4(r=>Ze(n!=null&&n.local?mE(t,gE(),r):Mge(t,r),i=>Rd(e,i))),Kge=ce(e=>Ln(e[0]),(e,t,n)=>LU(t)?Rd(e,t):Gge(e,Array.isArray(t)?V4(...t):t,n)),Xge=ce(3,(e,t,n)=>Ze(qge(t),r=>{let i=dD.defaultValue(),o;const a=Ay(Zt(()=>Id(e,dD,i)),u=>(o=u,Ze(r(u),c=>(i=c,a))));return wl(a,u=>Un(()=>n(o,u)))})),Yge=ce(2,(e,t)=>{const n=typeof t=="function"?t(Fe):zge(t)?t:Jge(t);return Xge(e,n,Cy)}),Qge=X4(Y4),Jge=e=>{let t=e.schedule?X4(e.schedule):Qge;return e.while&&(t=Bp(t,({input:n})=>{const r=e.while(n);return Ln(r)?r:Be(r)})),e.until&&(t=Bp(t,({input:n})=>{const r=e.until(n);return Ln(r)?Qt(r,i=>!i):Be(!r)})),e.times!==void 0&&(t=Bp(t,({attempt:n})=>Be(n<=e.times))),t},Du=Ln,Q4=Ya,J4=aE,Zge=Ahe,Mt=Be,wE=khe,eme=Ehe,vo=Zt,zr=Yt,jt=Rt,hD=bi,tme=Rhe,NP=Ihe,vt=Cy,nme=wn,rme=Ey,lm=ut,Gr=Ze,ime=Dhe,ome=Td,ame=c4,pD=Ty,Bs=Qt,pd=Md,sme=ope,zp=upe,ume=ipe,lme=Yge,cme=lpe,fme=gpe,dme=y4,hme=ppe,Z4=d4,pme=jy,cm=Zhe,e5=p4,gme=Kge,gs=Rd,mme=Jhe,yme=ky,vme=Id,xme=w4,t5=wpe,n5=Spe,bme=Ppe,r5=ja,LP=Epe,SE=O4,wme=Cpe,i5=npe,Sme=Vpe,_me=Gpe,gD=Kpe,Pme=k4,_E=Rpe,DP=Mpe,fm=$d,Ome=A4,Cme=$pe,df=Lpe,Eme=j4,kme=Npe,Ame=sE,PE=Fpe,jme=T4,o5=Dpe,Tme=uE,ms=u4,Rme=L4("Error"),Ime=ce(e=>Du(e[0]),(e,...t)=>h4(e,Ege,n=>{const r={...n};return t.length===1?Object.assign(r,t[0]):r[t[0]]=t[1],r})),a5=Fhe,zs=Bhe,gd=zhe,Tu=Lhe,Mme=qhe,FP=Mhe;function Xc(e,t,n){return t==="__proto__"?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n,e}function s5(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function $me(e){return t=>{var n;return(n=s5(t))==null?void 0:n[e]}}const Nme=$me("identifier"),OE=Ca(e=>{const t=Nme(e);return typeof t=="string"?t:e.getExpected(OE)}),Lme=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&"),qp=new WeakMap,u5="~effect/data/Redacted",Dme=e=>it(e,u5),mD=(e,t)=>{const n=Object.create(Fme);return qp.set(n,e),n},Fme={[u5]:{_A:e=>e},label:void 0,...ka,toJSON(){return this.toString()},toString(){return`<redacted${NC(this.label)?":"+this.label:""}>`},[Vn](){return Bt(qp.get(this))},[Wn](e){return Dme(e)&&Sr(qp.get(this),qp.get(e))}},BP="~effect/SchemaIssue/Issue";function Bme(e){return it(e,BP)}var kF;let qi=(kF=BP,class{constructor(){Q(this,kF,BP)}toString(){return Xme(this)}}),zme=class extends qi{constructor(n,r,i){super();Q(this,"_tag","Filter");Q(this,"actual");Q(this,"filter");Q(this,"issue");this.actual=n,this.filter=r,this.issue=i}};class qme extends qi{constructor(n,r,i){super();Q(this,"_tag","Encoding");Q(this,"ast");Q(this,"actual");Q(this,"issue");this.ast=n,this.actual=r,this.issue=i}}class mi extends qi{constructor(n,r){super();Q(this,"_tag","Pointer");Q(this,"path");Q(this,"issue");this.path=n,this.issue=r}}class l5 extends qi{constructor(n){super();Q(this,"_tag","MissingKey");Q(this,"annotations");this.annotations=n}}class c5 extends qi{constructor(n,r){super();Q(this,"_tag","UnexpectedKey");Q(this,"ast");Q(this,"actual");this.ast=n,this.actual=r}}class $n extends qi{constructor(n,r,i){super();Q(this,"_tag","Composite");Q(this,"ast");Q(this,"actual");Q(this,"issues");this.ast=n,this.actual=r,this.issues=i}}class Ui extends qi{constructor(n,r){super();Q(this,"_tag","InvalidType");Q(this,"ast");Q(this,"actual");this.ast=n,this.actual=r}}class dm extends qi{constructor(n,r){super();Q(this,"_tag","InvalidValue");Q(this,"actual");Q(this,"annotations");this.actual=n,this.annotations=r}}class yD extends qi{constructor(n,r,i){super();Q(this,"_tag","AnyOf");Q(this,"ast");Q(this,"actual");Q(this,"issues");this.ast=n,this.actual=r,this.issues=i}}class Ume extends qi{constructor(n,r,i){super();Q(this,"_tag","OneOf");Q(this,"ast");Q(this,"actual");Q(this,"successes");this.ast=n,this.actual=r,this.successes=i}}function zP(e,t){if(Bme(t))return t;if(typeof t=="string")return new dm(He(e),{message:t});const n=typeof t.issue=="string"?new dm(He(e),{message:t.issue}):t.issue;return new mi(t.path,n)}function Vme(e,t){if(t!==void 0)return typeof t=="boolean"?t?void 0:new dm(He(e)):zP(e,t)}function Wme(e,t,n){return Array.isArray(n)?rm(n)?n.length===1?zP(e,n[0]):new $n(t,He(e),lde(n,r=>zP(e,r))):void 0:Vme(e,n)}const Hme=e=>{const t=md(e);if(t!==void 0)return t;switch(e._tag){case"InvalidType":return qP(OE(e.ast),vD(e.actual));case"InvalidValue":return`Invalid data ${vD(e.actual)}`;case"MissingKey":return"Missing key";case"UnexpectedKey":return`Unexpected key with value ${Jt(e.actual)}`;case"Forbidden":return"Forbidden operation";case"OneOf":return`Expected exactly one member to match the input ${Jt(e.actual)}`}},Gme=e=>md(e.issue)??md(e);function qP(e,t){return`Expected ${e}, got ${t}`}function Eu(e,t,n,r){switch(e._tag){case"Filter":{const i=r(e);if(i!==void 0)return[{path:t,message:i}];switch(e.issue._tag){case"InvalidValue":return[{path:t,message:qP(f5(e.filter),Jt(e.actual))}];default:return Eu(e.issue,t,n,r)}}case"Encoding":return Eu(e.issue,t,n,r);case"Pointer":return Eu(e.issue,[...t,...e.path],n,r);case"Composite":return e.issues.flatMap(i=>Eu(i,t,n,r));case"AnyOf":{const i=md(e);if(e.issues.length===0){if(i!==void 0)return[{path:t,message:i}];const o=qP(OE(e.ast),Jt(e.actual));return[{path:t,message:o}]}return e.issues.flatMap(o=>Eu(o,t,n,r))}default:return[{path:t,message:n(e)}]}}function f5(e){var n;const t=(n=e.annotations)==null?void 0:n.expected;if(typeof t=="string")return t;switch(e._tag){case"Filter":return"<filter>";case"FilterGroup":return e.checks.map(r=>f5(r)).join(" & ")}}function Kme(){return e=>Eu(e,[],Hme,Gme).map(Yme).join(`
151
151
  `)}const Xme=Kme();function Yme(e){let t=e.message;if(e.path&&e.path.length>0){const n=ffe(e.path);t+=`
152
- at ${n}`}return t}function md(e){switch(e._tag){case"InvalidType":case"OneOf":case"Composite":case"AnyOf":return Bc(e.ast.annotations);case"InvalidValue":case"Forbidden":return Bc(e.annotations);case"MissingKey":return Bc(e.annotations,"messageMissingKey");case"UnexpectedKey":return Bc(e.ast.annotations,"messageUnexpectedKey");case"Filter":return Bc(e.filter.annotations);case"Encoding":return md(e.issue)}}function Bc(e,t="message"){const n=e==null?void 0:e[t];if(typeof n=="string")return n}function vD(e){return Ds(e)?"no value provided":Jt(e.value)}class Sl extends dy{constructor(n){super();Q(this,"run");this.run=n}map(n){return new Sl((r,i)=>this.run(r,i).pipe(a5(HC(n))))}compose(n){return xD(this)?n:xD(n)?this:new Sl((r,i)=>this.run(r,i).pipe(Tu(o=>n.run(o,i))))}}const d5=new Sl(Mt);function xD(e){return e.run===d5.run}function _l(){return d5}function sr(e){return Qme(HC(e))}function Qme(e){return new Sl(t=>Mt(e(t)))}function Jme(e){return new Sl(t=>{const n=Hfe(t,Dce);return ga(n)?Mt(n):Bs(e,He)})}function Zme(){return sr(globalThis.String)}function h5(){return sr(globalThis.Number)}const UP="~effect/SchemaTransformation/Transformation";var AF;AF=UP;const _m=class _m{constructor(t,n){Q(this,AF,UP);Q(this,"_tag","Transformation");Q(this,"decode");Q(this,"encode");this.decode=t,this.encode=n}flip(){return new _m(this.encode,this.decode)}compose(t){return new _m(this.decode.compose(t.decode),t.encode.compose(this.encode))}};let Or=_m;function eye(e){return it(e,UP)}const p5=e=>eye(e)?e:new Or(e.decode,e.encode);function Ly(e){return new Or(sr(e.decode),sr(e.encode))}const tye=new Or(_l(),_l());function CE(){return tye}const g5=new Or(h5(),Zme()),m5=e=>Ly({decode:t=>{const n=new Error(t.message);return typeof t.name=="string"&&t.name!=="Error"&&(n.name=t.name),typeof t.stack=="string"&&(n.stack=t.stack),n},encode:t=>{const n={name:t.name,message:t.message};return e!=null&&e.includeStack&&typeof t.stack=="string"&&(n.stack=t.stack),n}});function qs(e){return t=>t._tag===e}const y5=qs("Declaration"),nye=qs("Never"),hm=qs("Literal"),rye=qs("UniqueSymbol"),iye=qs("Arrays"),oye=qs("Objects"),aye=qs("Union");class pn{constructor(t,n){Q(this,"to");Q(this,"transformation");this.to=t,this.transformation=n}}const sye={};class Pl{constructor(t,n,r=void 0,i=void 0){Q(this,"isOptional");Q(this,"isMutable");Q(this,"defaultValue");Q(this,"annotations");this.isOptional=t,this.isMutable=n,this.defaultValue=r,this.annotations=i}}const bD="~effect/Schema";var jF;jF=bD;class cr{constructor(t=void 0,n=void 0,r=void 0,i=void 0){Q(this,jF,bD);Q(this,"annotations");Q(this,"checks");Q(this,"encoding");Q(this,"context");this.annotations=t,this.checks=n,this.encoding=r,this.context=i}toString(){return`<${this._tag}>`}}class Fd extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Declaration");Q(this,"typeParameters");Q(this,"run");this.typeParameters=n,this.run=r}getParser(){const n=this.run(this.typeParameters);return(r,i)=>Ds(r)?wE:a5(n(r.value,this,i),He)}recur(n){const r=Ol(this.typeParameters,n);return r===this.typeParameters?this:new Fd(r,this.run,this.annotations,this.checks,void 0,this.context)}getExpected(){var r;const n=(r=this.annotations)==null?void 0:r.expected;return typeof n=="string"?n:"<Declaration>"}}let uye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Null")}getParser(){return By(this,null)}getExpected(){return"null"}};const EE=new uye;let lye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Undefined")}getParser(){return By(this,void 0)}toCodecJson(){return fn(this,[v5])}getExpected(){return"undefined"}};const v5=new pn(EE,new Or(sr(()=>{}),sr(()=>null))),cye=new lye;let fye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Void")}getParser(){return By(this,void 0)}toCodecJson(){return fn(this,[v5])}getExpected(){return"void"}};const dye=new fye;let hye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Never")}getParser(){return Us(this,Bce)}getExpected(){return"never"}};const pye=new hye;let gye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Any")}getParser(){return Us(this,lU)}getExpected(){return"any"}};const mye=new gye;let yye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Unknown")}getParser(){return Us(this,lU)}getExpected(){return"unknown"}};const kE=new yye;let hf=class extends cr{constructor(n,r,i,o,a){super(r,i,o,a);Q(this,"_tag","Literal");Q(this,"literal");if(typeof n=="number"&&!globalThis.Number.isFinite(n))throw new Error(`A numeric literal must be finite, got ${Jt(n)}`);this.literal=n}getParser(){return By(this,this.literal)}toCodecJson(){return typeof this.literal=="bigint"?wD(this):this}toCodecStringTree(){return typeof this.literal=="string"?this:wD(this)}getExpected(){return typeof this.literal=="string"?JSON.stringify(this.literal):globalThis.String(this.literal)}};function wD(e){const t=globalThis.String(e.literal);return fn(e,[new pn(new hf(t),new Or(sr(()=>e.literal),sr(()=>t)))])}let vye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","String")}getParser(){return Us(this,NC)}getExpected(){return"string"}};const x5=new vye;let xye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Number")}getParser(){return Us(this,uU)}toCodecJson(){return this.checks&&(Yc(this.checks,"isFinite")||Yc(this.checks,"isInt"))?this:fn(this,[jye])}toCodecStringTree(){return this.checks&&(Yc(this.checks,"isFinite")||Yc(this.checks,"isInt"))?fn(this,[zye]):fn(this,[qye])}getExpected(){return"number"}};function Yc(e,t){return e.some(n=>{var r,i;switch(n._tag){case"Filter":return((i=(r=n.annotations)==null?void 0:r.meta)==null?void 0:i._tag)===t;case"FilterGroup":return Yc(n.checks,t)}})}const b5=new xye;let bye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Boolean")}getParser(){return Us(this,Lce)}getExpected(){return"boolean"}};const wye=new bye;class Dy extends cr{constructor(n,r,i,o,a,u,c){super(o,a,u,c);Q(this,"_tag","Arrays");Q(this,"isMutable");Q(this,"elements");Q(this,"rest");this.isMutable=n,this.elements=r,this.rest=i;const f=r.findIndex(ho);if(f!==-1&&(r.slice(f+1).some(h=>!ho(h))||i.length>1))throw new Error("A required element cannot follow an optional element. ts(1257)");if(i.length>1&&i.slice(1).some(ho))throw new Error("An optional element cannot follow a rest element. ts(1266)")}getParser(n){const r=this,i=r.elements.map(d=>({ast:d,parser:n(d)})),o=r.rest.map(d=>({ast:d,parser:n(d)})),a=i.length,[u,...c]=o,f=c.length;function h(d,g){return g<a?i[g]:g>=d?c[g-d]:u}return FP(function*(d,g){if(d._tag==="None")return d;const m=d.value;if(!Array.isArray(m))return yield*vt(new Ui(r,d));const v=m.length,x={ast:r,getParser:h,oinput:d,len:v,tailThreshold:_ye(v,a,f),output:new globalThis.Array(v),issues:void 0,options:g},b=AE(g==null?void 0:g.concurrency),O=Sye(x,m,{concurrency:b==null?void 0:b.concurrency,end:r.rest.length===0?a:Math.max(v,a+f)});if(O&&(yield*O),r.rest.length===0&&v>a)for(let _=a;_<=v-1;_++){const C=new mi([_],new c5(r,m[_]));if(g.errors==="all")x.issues?x.issues.push(C):x.issues=[C];else return yield*vt(new $n(r,d,[C]))}return x.issues?yield*vt(new $n(r,d,x.issues)):He(x.output)})}recur(n){const r=Ol(this.elements,n),i=Ol(this.rest,n);return r===this.elements&&i===this.rest?this:new Dy(this.isMutable,r,i,this.annotations,this.checks,void 0,this.context)}getExpected(){return"array"}}const Sye=My()({onItem(e,t,n){const r=n<e.len?He(t):Wr();return e.getParser(e.tailThreshold,n).parser(r,e.options)},step(e,t,n,r){var i;if(n._tag==="Failure")return pm(e,e.ast,r,n);if(n.value._tag==="Some")e.output[r]=n.value.value;else{const o=e.getParser(e.tailThreshold,r);if(ho(o.ast))return;const a=new mi([r],new l5((i=o.ast.context)==null?void 0:i.annotations));if(e.options.errors==="all")e.issues?e.issues.push(a):e.issues=[a];else return Ld(new $n(e.ast,e.oinput,[a]))}}});function _ye(e,t,n){return Math.max(t,e-n)}const AE=e=>(e=e==="unbounded"?1/0:e??1,e>1?{concurrency:e}:void 0),pm=(e,t,n,r)=>{const i=Nd(r.cause);if(hn(i))return r;const o=new mi([n],i.success);if(e.options.errors==="all")e.issues?e.issues.push(o):e.issues=[o];else return Ld(new $n(t,e.oinput,[o]))},jE="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",Pye=new globalThis.RegExp(`(?:${jE}|Infinity|-Infinity|NaN)`);function w5(e,t){const n=fa(t);switch(n._tag){case"String":return Object.keys(e);case"TemplateLiteral":{const r=Lye(n);return Object.keys(e).filter(i=>r.test(i))}case"Symbol":return Object.getOwnPropertySymbols(e);case"Number":return Object.keys(e).filter(r=>Pye.test(r));case"Union":return[...new Set(n.types.flatMap(r=>w5(e,r)))];default:return[]}}class S5{constructor(t,n){Q(this,"name");Q(this,"type");this.name=t,this.type=n}}class Oye{constructor(t,n,r){Q(this,"parameter");Q(this,"type");Q(this,"merge");if(this.parameter=t,this.type=n,this.merge=r,ho(n)&&!M5(n))throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}}class TE extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Objects");Q(this,"propertySignatures");Q(this,"indexSignatures");this.propertySignatures=n,this.indexSignatures=r;const c=n.map(f=>f.name).filter((f,h,d)=>d.indexOf(f)!==h);if(c.length>0)throw new Error(`Duplicate identifiers: ${JSON.stringify(c)}. ts(2300)`)}getParser(n){const r=this,i=[],o=new Set,a=[];for(const f of r.propertySignatures)i.push(f.name),o.add(f.name),a.push({ps:f,parser:n(f.type),name:f.name,type:f.type});const u=r.indexSignatures.length;if(r.propertySignatures.length===0&&r.indexSignatures.length===0)return Us(r,Fce);const c=u>0?My()({onItem:FP(function*(f,[h,d]){const m=n(D5(d.parameter))(He(h),f.options),v=Pr(m)?m:yield*pD(m);if(v._tag==="Failure"){const C=pm(f,r,h,v);C&&(yield*C);return}const x=He(f.input[h]),O=n(d.type)(x,f.options),_=Pr(O)?O:yield*pD(O);if(_._tag==="Failure"){const C=pm(f,r,h,_);C&&(yield*C);return}else if(v.value._tag==="Some"&&_.value._tag==="Some"){const C=v.value.value,E=_.value.value;if(d.merge&&d.merge.decode&&Object.hasOwn(f.out,C)){const[P,A]=d.merge.decode.combine([C,f.out[C]],[C,E]);Xc(f.out,P,A)}else Xc(f.out,C,E)}}),step:(f,h,d)=>d._tag==="Failure"?d:void 0}):void 0;return FP(function*(f,h){if(f._tag==="None")return f;const d=f.value;if(!(typeof d=="object"&&d!==null&&!Array.isArray(d)))return yield*vt(new Ui(r,f));const g={},m={ast:r,oinput:f,input:d,out:g,issues:void 0,options:h},v=h.errors==="all",x=h.onExcessProperty==="error",b=h.onExcessProperty==="preserve";let O;if(r.indexSignatures.length===0&&(x||b)){O=Reflect.ownKeys(d);for(let E=0;E<O.length;E++){const P=O[E];if(!o.has(P))if(x){const A=new mi([P],new c5(r,d[P]));if(v){m.issues?m.issues.push(A):m.issues=[A];continue}else return yield*vt(new $n(r,f,[A]))}else Xc(g,P,d[P])}}const _=AE(h==null?void 0:h.concurrency),C=Cye(m,a,_);if(C&&(yield*C),c){const E=ude();for(let A=0;A<u;A++){const j=r.indexSignatures[A],R=w5(d,j.parameter);for(let M=0;M<R.length;M++){const F=R[M];E.push([F,j])}}const P=c(m,E,_);P&&(yield*P)}if(m.issues)return yield*vt(new $n(r,f,m.issues));if(h.propertyOrder==="original"){const E=(O??Reflect.ownKeys(d)).concat(i),P={};for(const A of E)Object.hasOwn(g,A)&&Xc(P,A,g[A]);return He(P)}return He(g)})}rebuild(n,r){const i=Ol(this.propertySignatures,a=>{const u=n(a.type);return u===a.type?a:new S5(a.name,u)}),o=Ol(this.indexSignatures,a=>{var h;const u=n(a.parameter),c=n(a.type),f=r?(h=a.merge)==null?void 0:h.flip():a.merge;return u===a.parameter&&c===a.type&&f===a.merge?a:new Oye(u,c,f)});return i===this.propertySignatures&&o===this.indexSignatures?this:new TE(i,o,this.annotations,this.checks,void 0,this.context)}flip(n){return this.rebuild(n,!0)}recur(n){return this.rebuild(n,!1)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?"object | array":"object"}}const Cye=My()({onItem(e,t){const n=Object.hasOwn(e.input,t.name)?He(e.input[t.name]):Wr();return t.parser(n,e.options)},step(e,t,n){var r;if(n._tag==="Failure")return pm(e,e.ast,t.name,n);if(n.value._tag==="Some")Xc(e.out,t.name,n.value.value);else if(!ho(t.type)){const i=new mi([t.name],new l5((r=t.type.context)==null?void 0:r.annotations));if(e.options.errors==="all"){e.issues?e.issues.push(i):e.issues=[i];return}else return Ld(new $n(e.ast,e.oinput,[i]))}}});function RE(e,t,n){return new TE(Reflect.ownKeys(e).map(r=>new S5(r,e[r].ast)),[],n,t)}function _5(e){return e.ast}function IE(e,t,n){return new Bd(e.map(_5),t,void 0,n)}function P5(e){switch(e._tag){case"Null":return["null"];case"Undefined":case"Void":return["undefined"];case"String":case"TemplateLiteral":return["string"];case"Number":return["number"];case"Boolean":return["boolean"];case"Symbol":case"UniqueSymbol":return["symbol"];case"BigInt":return["bigint"];case"Arrays":return["array"];case"ObjectKeyword":return["object","array","function"];case"Objects":return e.propertySignatures.length||e.indexSignatures.length?["object"]:["object","array"];case"Enum":return Array.from(new Set(e.enums.map(([,t])=>typeof t)));case"Literal":return[typeof e.literal];case"Union":return Array.from(new Set(e.types.flatMap(P5)));default:return["null","undefined","string","number","boolean","symbol","bigint","object","array","function"]}}function ME(e){var t;switch(e._tag){default:return[];case"Declaration":{const n=(t=e.annotations)==null?void 0:t["~sentinels"];return Array.isArray(n)?n:[]}case"Objects":return e.propertySignatures.flatMap(n=>{const r=n.type;if(!ho(r)){if(hm(r))return[{key:n.name,literal:r.literal}];if(rye(r))return[{key:n.name,literal:r.symbol}]}return[]});case"Arrays":return e.elements.flatMap((n,r)=>hm(n)&&!ho(n)?[{key:r,literal:n.literal}]:[]);case"Suspend":return ME(e.thunk())}}const SD=new WeakMap;function Eye(e){var n,r;let t=SD.get(e);if(t)return t;t={};for(const i of e){const o=fa(i);if(nye(o))continue;const a=P5(o),u=ME(o);t.byType??(t.byType={});for(const c of a)((n=t.byType)[c]??(n[c]=[])).push(i);if(u.length>0){t.bySentinel??(t.bySentinel=new Map);for(const{key:c,literal:f}of u){let h=t.bySentinel.get(c);h||t.bySentinel.set(c,h=new Map);let d=h.get(f);d||h.set(f,d=[]),d.push(i)}}else{t.otherwise??(t.otherwise={});for(const c of a)((r=t.otherwise)[c]??(r[c]=[])).push(i)}}return SD.set(e,t),t}function _D(e){return t=>{const n=fa(t);return n._tag==="Literal"?n.literal===e:n._tag==="UniqueSymbol"?n.symbol===e:!0}}function kye(e,t){var i,o;const n=Eye(t),r=e===null?"null":Array.isArray(e)?"array":typeof e;if(n.bySentinel){const a=((i=n.otherwise)==null?void 0:i[r])??[];if(r==="object"||r==="array"){for(const[u,c]of n.bySentinel)if(Object.hasOwn(e,u)){const f=c.get(e[u]);if(f)return[...f,...a].filter(_D(e))}}return a}return(((o=n.byType)==null?void 0:o[r])??[]).filter(_D(e))}let Bd=class O5 extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Union");Q(this,"types");Q(this,"mode");this.types=n,this.mode=r}getParser(n){const r=this;return(i,o)=>{if(i._tag==="None")return Mt(i);const a=i.value,u=kye(a,r.types),c={ast:r,recur:n,oinput:i,input:a,out:void 0,successes:[],issues:void 0,options:o},f=AE(o==null?void 0:o.concurrency),h=Aye(c,u,f);return h?Gr(h,d=>c.out?Mt(c.out):vt(new yD(r,a,c.issues??[]))):c.out?Mt(c.out):vt(new yD(r,a,c.issues??[]))}}recur(n){const r=Ol(this.types,n);return r===this.types?this:new O5(r,this.mode,this.annotations,this.checks,void 0,this.context)}getExpected(n){var o;const r=(o=this.annotations)==null?void 0:o.expected;if(typeof r=="string")return r;if(this.types.length===0)return"never";const i=this.types.map(a=>{const u=fa(a);switch(u._tag){case"Arrays":{const c=u.elements.filter(hm);if(c.length>0)return`${PD(u.isMutable)}[ ${c.map(f=>{var h;return n(f)+OD((h=f.context)==null?void 0:h.isOptional)}).join(", ")}, ... ]`;break}case"Objects":{const c=u.propertySignatures.filter(f=>hm(f.type));if(c.length>0)return`{ ${c.map(f=>{var h,d;return`${PD((h=f.type.context)==null?void 0:h.isMutable)}${nm(f.name)}${OD((d=f.type.context)==null?void 0:d.isOptional)}: ${n(f.type)}`}).join(", ")}, ... }`;break}}return n(u)});return Array.from(new Set(i)).join(" | ")}};const Aye=My()({onItem(e,t){return e.recur(t)(e.oinput,e.options)},step(e,t,n){if(n._tag==="Failure"){const r=Nd(n.cause);if(hn(r))return n;e.issues?e.issues.push(r.success):e.issues=[r.success]}else{if(e.out&&e.ast.mode==="oneOf")return e.successes.push(t),Ld(new Ume(e.ast,e.input,e.successes));if(e.out=n.value,e.successes.push(t),e.ast.mode==="anyOf")return F4}}}),C5=new Bd([new hf("Infinity"),new hf("-Infinity"),new hf("NaN")],"anyOf"),jye=new pn(new Bd([b5,C5],"anyOf"),new Or(h5(),sr(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function PD(e){return e?"":"readonly "}function OD(e){return e?"?":""}class gm extends dy{constructor(n,r=void 0,i=!1){super();Q(this,"_tag","Filter");Q(this,"run");Q(this,"annotations");Q(this,"aborted");this.run=n,this.annotations=r,this.aborted=i}annotate(n){return new gm(this.run,{...this.annotations,...n},this.aborted)}abort(){return new gm(this.run,this.annotations,!0)}and(n,r){return new mm([this,n],r)}}class mm extends dy{constructor(n,r=void 0){super();Q(this,"_tag","FilterGroup");Q(this,"checks");Q(this,"annotations");this.checks=n,this.annotations=r}annotate(n){return new mm(this.checks,{...this.annotations,...n})}and(n,r){return new mm([this,n],r)}}function E5(e,t,n=!1){return new gm((r,i,o)=>Wme(r,i,e(r,i,o)),t,n)}function Tye(e,t){const n=e.source;return E5(r=>e.test(r),{expected:`a string matching the RegExp ${n}`,meta:{_tag:"isPattern",regExp:e},toArbitraryConstraint:{string:{patterns:[e.source]}},...t})}function Fy(e,t){const n=Object.getOwnPropertyDescriptors(e);return t(n),Object.create(Object.getPrototypeOf(e),n)}function fn(e,t){return e.encoding===t?e:Fy(e,n=>{n.encoding.value=t})}function $E(e,t){return e.context===t?e:Fy(e,n=>{n.context.value=t})}function k5(e,t){if(e.checks){const n=e.checks[e.checks.length-1];return A5(e,$U(e.checks.slice(0,-1),n.annotate(t)))}return Fy(e,n=>{n.annotations.value={...n.annotations.value,...t}})}function A5(e,t){return e.checks===t?e:Fy(e,n=>{n.checks.value=t})}function NE(e,t){return A5(e,e.checks?[...e.checks,...t]:t)}function j5(e,t){const n=e,r=n[n.length-1],i=t(r.to);return i!==r.to?$U(e.slice(0,e.length-1),new pn(i,r.transformation)):e}function Rye(e){return t=>t.encoding?fn(t,j5(t.encoding,e)):t}function Iye(e,t,n){const r=new pn(e,t);return fn(n,n.encoding?[...n.encoding,r]:[r])}function Ol(e,t){let n=!1;const r=new Array(e.length);for(let i=0;i<e.length;i++){const o=e[i],a=t(o);a!==o&&(n=!0),r[i]=a}return n?r:e}function T5(e,t){const n=e.context?new Pl(e.context.isOptional,e.context.isMutable,e.context.defaultValue,{...e.context.annotations,...t}):new Pl(!1,!1,void 0,t);return $E(e,n)}const R5=Rye(I5);function I5(e){const t=e.context?e.context.isOptional===!1?new Pl(!0,e.context.isMutable,e.context.defaultValue,e.context.annotations):e.context:new Pl(!0,!1);return R5($E(e,t))}function Mye(e,t){const n=new Or(Jme(t),_l()),r=[new pn(kE,n)],i=e.context?new Pl(e.context.isOptional,e.context.isMutable,r,e.context.annotations):new Pl(!1,!1,r);return $E(e,i)}function $ye(e,t,n){return Iye(e,n,t)}function ho(e){var t;return((t=e.context)==null?void 0:t.isOptional)??!1}const ym=Ca(e=>{var n;if(e.encoding)return ym(fn(e,void 0));const t=e;return((n=t.recur)==null?void 0:n.call(t,ym))??t}),fa=Ca(e=>ym(ys(e)));function Nye(e,t){const n=t,r=n.length,i=n[r-1],o=[new pn(ys(fn(e,void 0)),n[0].transformation.flip())];for(let u=1;u<r;u++)o.unshift(new pn(ys(n[u-1].to),n[u].transformation.flip()));const a=ys(i.to);return a.encoding?fn(a,[...a.encoding,...o]):fn(a,o)}const ys=Ca(e=>{var n,r;if(e.encoding)return Nye(e,e.encoding);const t=e;return((n=t.flip)==null?void 0:n.call(t,ys))??((r=t.recur)==null?void 0:r.call(t,ys))??t});function M5(e){switch(e._tag){case"Undefined":return!0;case"Union":return e.types.some(M5);default:return!1}}function $5(e,t){return e.encodedParts.map(n=>Dye(n,N5(n),t)).join("")}const Lye=Ca(e=>new globalThis.RegExp(`^${$5(e,!0)}$`));function N5(e){switch(e._tag){case"Literal":return Lme(globalThis.String(e.literal));case"String":return Fye;case"Number":return jE;case"BigInt":return Uye;case"TemplateLiteral":return $5(e,!1);case"Union":return e.types.map(N5).join("|")}}function Dye(e,t,n){if(aye(e)){if(!n)return`(?:${t})`}else if(!n)return t;return`(${t})`}function By(e,t){const n=eme(t);return r=>r._tag==="None"?wE:r.value===t?n:vt(new Ui(e,r))}function Us(e,t){return n=>n._tag==="None"?wE:t(n.value)?Mt(n):vt(new Ui(e,n))}function L5(e){function t(n){return n.encoding?fn(n,j5(n.encoding,t)):e(n)}return Ca(t)}const D5=L5(e=>{switch(e._tag){default:return e;case"Number":return e.toCodecStringTree();case"Union":return e.recur(D5)}}),Fye="[\\s\\S]*?",CD=new globalThis.RegExp(`^${jE}$`);function Bye(e){return Tye(CD,{expected:"a string representing a finite number",meta:{_tag:"isStringFinite",regExp:CD},...e})}const F5=NE(x5,[Bye()]),zye=new pn(F5,g5),qye=new pn(new Bd([F5,C5],"anyOf"),g5),Uye="-?\\d+";function VP(e,t,n,r,i){for(let o=0;o<e.length;o++){const a=e[o];if(a._tag==="FilterGroup")VP(a.checks,t,n,r,i);else{const u=a.run(t,r,i);if(u&&(n.push(new zme(t,a,u)),a.aborted||(i==null?void 0:i.errors)!=="all"))return}}}const B5="~effect/Schema/Class",Vye="~structural";function Wye(e){const t=new Set,n=new Set;return r(e);function r(i){if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return globalThis.Number.isFinite(i);if(typeof i!="object"||i===void 0||t.has(i))return!1;if(n.has(i))return!0;t.add(i);const o=Array.isArray(i)?i.every(r):Object.keys(i).every(a=>r(i[a]));return t.delete(i),o&&n.add(i),o}}const Hye=new Fd([],()=>(e,t)=>Wye(e)?Mt(e):vt(new Ui(t,He(e))),{typeConstructor:{_tag:"effect/Json"},generation:{runtime:"Schema.Json",Type:"Schema.Json"},expected:"JSON value",toCodecJson:()=>new pn(kE,CE())}),Gye=new pn(EE,new Or(_l(),sr(()=>null))),Kye=new pn(Hye,CE()),Xye=i4,Qc=eE,Yye=am,WP=ZC,Qye=Ipe,z5=zpe,Jye=Symbol.for("effect/MutableList/Empty"),Zye=()=>({head:void 0,tail:void 0,length:0}),ED=()=>({array:[],mutable:!0,offset:0,next:void 0}),HP=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=ED(),e.tail=e.tail.next):e.head=e.tail=ED(),e.tail.array.push(t),e.length++},eve=(e,t)=>tve(e,Fi(t),!Array.isArray(t)),tve=(e,t,n=!1)=>{if(t.length===0)return 0;const r={array:t,mutable:n,offset:0,next:void 0};return e.head?e.tail=e.tail.next=r:e.head=e.tail=r,e.length+=t.length,t.length},Up=e=>{e.head=e.tail=void 0,e.length=0},q5=(e,t)=>{var o;if(t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&((o=e.head)==null?void 0:o.offset)===0&&!e.head.next){const a=e.head.array;return Up(e),a}const n=new Array(t);let r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i,e.length-=t,e.length===0&&Up(e),n;i=i.next}return Up(e),n},nve=e=>{if(!e.head)return Jye;const t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length&&(e.head.next?e.head=e.head.next:Up(e)),t},rve="~effect/Queue",ive="~effect/Queue/Enqueue",ove="~effect/Queue/Dequeue",y1={_A:Fe,_E:Fe},ave={[rve]:y1,[ive]:y1,[ove]:y1,...ka,toJSON(){return{_id:"effect/Queue",state:this.state._tag,size:hve(this)}}},sve=e=>ut(t=>{const n=Object.create(ave);return n.dispatcher=t.currentDispatcher,n.capacity=(e==null?void 0:e.capacity)??Number.POSITIVE_INFINITY,n.strategy=(e==null?void 0:e.strategy)??"suspend",n.messages=Zye(),n.scheduleRunning=!1,n.state={_tag:"Open",takers:new Set,offers:new Set,awaiters:new Set},Be(n)}),uve=e=>sve({capacity:e}),lve=(e,t)=>Zt(()=>{if(e.state._tag!=="Open")return Be(Fi(t));const n=cve(e,t);return n.length===0?It([]):e.strategy==="dropping"?Be(n):vve(e,n)}),cve=(e,t)=>{if(e.state._tag!=="Open")return Fi(t);if(e.capacity===Number.POSITIVE_INFINITY||e.strategy==="sliding")return eve(e.messages,t),e.strategy==="sliding"&&q5(e.messages,e.messages.length-e.capacity),AD(e),[];const n=e.capacity<=0?e.state.takers.size:e.capacity-e.messages.length;if(n===0)return Fi(t);const r=[];let i=0;for(const o of t)i<n?HP(e.messages,o):r.push(o),i++;return AD(e),r},Jc=ce(2,(e,t)=>Yt(()=>fve(e,t))),fve=(e,t)=>{if(e.state._tag!=="Open")return!1;const n=Vr(t),r=Xhe(n,gve);return e.state.offers.size===0&&e.messages.length===0?(V5(e,r),!0):(e.state={...e.state,_tag:"Closing",exit:r},!0)},kD=e=>Jc(e,vU(VC())),dve=e=>U5(e,1,Number.POSITIVE_INFINITY),U5=(e,t,n)=>Zt(()=>yve(e,t,n)??Td(xve(e),U5(e,1,n))),hve=e=>e.state._tag==="Done"?0:e.messages.length,pve=It(!0),gve=zi(VC()),mve=e=>{if(e.scheduleRunning=!1,!(e.state._tag==="Done"||e.state.takers.size===0)){for(const t of e.state.takers)if(e.state.takers.delete(t),t(Hr),e.messages.length===0)break}},AD=e=>{e.scheduleRunning||e.state._tag==="Done"||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>mve(e),0))},yve=(e,t,n)=>{if(e.state._tag==="Done")return e.state.exit;if(n<=0||t<=0)return It([]);if(e.capacity<=0&&e.state.offers.size>0){e.capacity=1,v1(e),e.capacity=0;const r=[nve(e.messages)];return v1(e),It(r)}if(t=Math.min(t,e.capacity||1),t<=e.messages.length){const r=q5(e.messages,n);return v1(e),It(r)}},vve=(e,t)=>bi(n=>{if(e.state._tag!=="Open")return n(It(t));const r={_tag:"Array",remaining:t,offset:0,resume:n};return e.state.offers.add(r),Yt(()=>{e.state._tag==="Open"&&e.state.offers.delete(r)})}),v1=e=>{if(e.state._tag==="Done")return fD(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag==="Closing"&&e.messages.length===0?(V5(e,e.state.exit),fD(e.state.exit.cause)):!1;let t=e.capacity-e.messages.length;for(const n of e.state.offers){if(t===0)break;if(n._tag==="Single")HP(e.messages,n.message),t--,n.resume(pve),e.state.offers.delete(n);else{for(;n.offset<n.remaining.length;n.offset++){if(t===0)return!1;HP(e.messages,n.remaining[n.offset]),t--}n.resume(It([])),e.state.offers.delete(n)}}return!1},xve=e=>bi(t=>e.state._tag==="Done"?t(e.state.exit):(e.state.takers.add(t),Yt(()=>{e.state._tag!=="Done"&&e.state.takers.delete(t)}))),V5=(e,t)=>{if(e.state._tag==="Done")return;const n=e.state;e.state={_tag:"Done",exit:t};for(const r of n.takers)r(t);n.takers.clear();for(const r of n.awaiters)r(t);n.awaiters.clear()},bve="~effect/Channel",wve={[bve]:{_Env:Fe,_InErr:Fe,_InElem:Fe,_OutErr:Fe,_OutElem:Fe},pipe(){return Sn(this,arguments)}},LE=e=>{const t=Object.create(wve);return t.transform=(n,r)=>pd(e(n,r),i=>Mt(nme(i))),t},Sve=e=>LE((t,n)=>e),DE=e=>e.transform,_ve=e=>Sve(Mt(dve(e))),Pve=e=>LE((t,n)=>{let r;return Mt(vo(()=>r||e.pipe(sm(n),Gr(i=>DE(i)(t,n)),Gr(i=>r=i))))}),Ove=(e,t,n)=>vo(()=>{const r=hE(),i=DE(e)(ps(),r);return wl(Gr(i,t),Mt).pipe(r5(o=>Ny(r,o)))}),Cve=ce(2,(e,t)=>LE((n,r)=>Bs(gs(DE(e)(n,r),t),gs(t)))),Eve=ce(2,(e,t)=>Ove(e,n=>i5(Gr(n,t),{disableYield:!0}))),Dl=e=>e,Zc=Ca(e=>{var t;switch(e._tag){case"Declaration":{const n=(t=e.annotations)==null?void 0:t[B5];if(py(n)){const r=n(e.typeParameters),i=Zc(r.to);return fn(e,i===r.to?[r]:[new pn(i,r.transformation)])}return e}case"Objects":case"Arrays":return e.recur(n=>{var i;const r=(i=n.context)==null?void 0:i.defaultValue;return r?fn(Zc(n),r):Zc(n)});case"Suspend":return e.recur(Zc);default:return e}});function zy(e){const t=Zc(ym(e.ast)),n=FE(t);return(r,i)=>n(r,i!=null&&i.disableChecks?i!=null&&i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i==null?void 0:i.parseOptions)}function W5(e){const t=zy(e);return(n,r)=>Sge(o5(t(n,r)))}function kve(e){const t=zy(e);return(n,r)=>PE(zs(t(n,r),i=>new Error(i.toString(),{cause:i})))}function As(e){return FE(e.ast)}function Ave(e){return Rve(As(e))}const jve=Ave;function Tve(e){return FE(ys(e.ast))}function FE(e){const t=Vp(e);return(n,r)=>Tu(t(He(n),r??sye),i=>i._tag==="None"?vt(new dm(i)):Mt(i.value))}function Rve(e){return(t,n)=>PE(zs(e(t,n),r=>new Error(r.toString(),{cause:r})))}const Vp=Ca(e=>{var i;let t;const n=(i=s5(e))==null?void 0:i.parseOptions;if(!e.context&&!e.encoding&&!e.checks)return(o,a)=>(t??(t=e.getParser(Vp)),n&&(a={...a,...n}),t(o,a));const r=iye(e)||oye(e)||y5(e)&&e.typeParameters.length>0;return(o,a)=>{n&&(a={...a,...n});const u=e.encoding;let c;if(u){const h=u,d=h.length;for(let g=d-1;g>=0;g--){const m=h[g],v=m.to,x=Vp(v);if(c=c?Tu(c,b=>x(b,a)):x(o,a),m.transformation._tag==="Transformation"){const b=m.transformation.decode;c=Tu(c,O=>b.run(O,a))}else c=m.transformation.decode(c,a)}c=zs(c,g=>new qme(e,o,g))}t??(t=e.getParser(Vp));let f=c?Tu(c,h=>t(h,a)):t(o,a);if(e.checks&&!(a!=null&&a.disableChecks)){const h=e.checks;(a==null?void 0:a.errors)==="all"&&r&&ga(o)&&(f=Mme(f,d=>{const g=[];VP(h.filter(v=>{var x;return(x=v.annotations)==null?void 0:x[Vye]}),o.value,g,e,a);const m=VL(g)?d._tag==="Composite"&&d.ast===e?new $n(e,d.actual,[...d.issues,...g]):new $n(e,o,[d,...g]):d;return vt(m)})),f=Tu(f,d=>{if(ga(d)){const g=d.value,m=[];if(VP(h,g,m,e,a),VL(m))return vt(new $n(e,d,m))}return Mt(d)})}return f}}),GP="~effect/Schema/Schema",Ive={[GP]:GP,pipe(){return Sn(this,arguments)},annotate(e){return this.rebuild(k5(this.ast,e))},annotateKey(e){return this.rebuild(T5(this.ast,e))},check(...e){return this.rebuild(NE(this.ast,e))}};function BE(e,t){const n=Object.create(Ive);return t&&Object.assign(n,t),n.ast=e,n.rebuild=r=>BE(r,t),n.makeEffect=sU(zy(n),zs(r=>new qy(r))),n.make=kve(n),n.makeOption=W5(n),n}const jD="~effect/Schema/SchemaError";var TF;TF=jD;class qy{constructor(t){Q(this,TF,jD);Q(this,"_tag","SchemaError");Q(this,"name","SchemaError");Q(this,"issue");this.issue=t}get message(){return this.issue.toString()}toString(){return`SchemaError(${this.message})`}}const Mve=Nve($ve);function $ve(e){switch(e._tag){case"BigInt":case"Symbol":case"UniqueSymbol":return 0;default:return 1}}function Nve(e){return t=>{const n=new Map;for(let o=0;o<t.length;o++)n.set(fa(t[o]),o);const r=[...t].sort((o,a)=>{o=fa(o),a=fa(a);const u=e(o),c=e(a);return u!==c?u-c:n.get(o)-n.get(a)});return r.some((o,a)=>o!==t[a])?r:t}}const pf=GP;function Uy(){return(e,t,n)=>ht(new Fd(e.map(_5),r=>t(r.map(i=>ht(i))),n))}function H5(e,t){return Uy()([],()=>(n,r)=>e(n)?Mt(n):vt(new Ui(r,He(n))),t)}function TD(e){const t=As(e);return(n,r)=>zs(t(n,r),i=>new qy(i))}const Lve=jve;function Dve(e){const t=Tve(e);return(n,r)=>zs(t(n,r),i=>new qy(i))}const Fve=Dve,ht=BE;function zE(e){return it(e,pf)&&e[pf]===pf}const KP=Dl(e=>ht(I5(e.ast),{schema:e})),Fl=Dl(e=>KP(Y5(e)));function da(e){const t=ht(new hf(e),{literal:e,transform(n){return t.pipe(xm(da(n),{decode:sr(()=>n),encode:sr(()=>e)}))}});return t}const RD=ht(pye),ID=ht(mye),G5=ht(kE),Bve=ht(EE),zve=ht(cye),ar=ht(x5),K5=ht(b5),qve=ht(wye),vm=ht(dye);function qE(e,t){return ht(e,{fields:t,mapFields(n,r){const i=n(this.fields);return qE(RE(i,r!=null&&r.unsafePreserveChecks?this.ast.checks:void 0),i)}})}function Nn(e){return qE(RE(e,void 0),e)}const XP=Dl(e=>ht(new Dy(!1,[],[e.ast]),{schema:e})),Uve=Dl(e=>ht(new Dy(!1,[e.ast],[e.ast]),{schema:e}));function X5(e,t){return ht(e,{members:t,mapMembers(n,r){const i=n(this.members);return X5(IE(i,this.ast.mode,r!=null&&r.unsafePreserveChecks?this.ast.checks:void 0),i)}})}function yi(e,t){return X5(IE(e,"anyOf",void 0),e)}function Vy(e){const t=e.map(da);return ht(IE(t,"anyOf",void 0),{literals:e,members:t,mapMembers(n){return yi(n(this.members))},pick(n){return Vy(n)},transform(n){return yi(t.map((r,i)=>r.transform(n[i])))}})}const Vve=Dl(e=>yi([e,Bve])),Y5=Dl(e=>yi([e,zve]));function xm(e,t){return n=>ht($ye(n.ast,e.ast,t?p5(t):CE()),{from:n,to:e})}function Wve(e){return t=>ht(Mye(t.ast,e),{schema:t})}function fr(e){return da(e).pipe(Wve(Mt(e)))}function Hve(e,t){return Nn({_tag:fr(e),...t})}function Gve(e,t){return H5(n=>n instanceof e,t)}function zd(){return(e,t)=>new pn(e.ast,p5(t))}const Kve=E5;function Xve(e){return Kve(t=>globalThis.Number.isFinite(t),{expected:"a finite number",meta:{_tag:"isFinite"},toArbitraryConstraint:{number:{noDefaultInfinity:!0,noNaN:!0}},...e})}function MD(e,t){const n=Uy()([e,t],([r,i])=>(o,a,u)=>{if(!pge(o))return vt(new Ui(a,He(o)));switch(o._tag){case"Fail":return gd(As(r)(o.error,u),{onSuccess:jP,onFailure:c=>new $n(a,He(o),[new mi(["error"],c)])});case"Die":return gd(As(i)(o.defect,u),{onSuccess:TP,onFailure:c=>new $n(a,He(o),[new mi(["defect"],c)])});case"Interrupt":return Mt(o)}},{typeConstructor:{_tag:"effect/Cause/Failure"},generation:{runtime:"Schema.CauseReason(?, ?)",Type:"Cause.Failure<?, ?>",importDeclaration:'import * as Cause from "effect/Cause"'},expected:"Cause.Failure",toCodec:([r,i])=>zd()(yi([Nn({_tag:da("Fail"),error:r}),Nn({_tag:da("Die"),defect:i}),Nn({_tag:da("Interrupt"),fiberId:Y5(Jve)})]),Ly({decode:o=>{switch(o._tag){case"Fail":return jP(o.error);case"Die":return TP(o.defect);case"Interrupt":return RP(o.fiberId)}},encode:Fe})),toArbitrary:([r,i])=>Q5(r,i),toEquivalence:([r,i])=>J5(r,i),toFormatter:([r,i])=>Z5(r,i)});return ht(n.ast,{error:e,defect:t})}function Q5(e,t){return(n,r)=>n.oneof(r!=null&&r.isSuspend?{maxDepth:2,depthIdentifier:"Cause.Failure"}:{},n.constant(RP()),n.integer({min:1}).map(RP),e.map(i=>jP(i)),t.map(i=>TP(i)))}function J5(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case"Fail":return e(n.error,r.error);case"Die":return t(n.defect,r.defect);case"Interrupt":return n.fiberId===r.fiberId}}}function Z5(e,t){return n=>{switch(n._tag){case"Fail":return`Fail(${e(n.error)})`;case"Die":return`Die(${t(n.defect)})`;case"Interrupt":return"Interrupt"}}}function $D(e,t){const n=Uy()([e,t],([r,i])=>{const o=XP(MD(r,i));return(a,u,c)=>hge(a)?gd(As(o)(a.reasons,c),{onSuccess:AP,onFailure:f=>new $n(u,He(a),[new mi(["failures"],f)])}):vt(new Ui(u,He(a)))},{typeConstructor:{_tag:"effect/Cause"},generation:{runtime:"Schema.Cause(?, ?)",Type:"Cause.Cause<?, ?>",importDeclaration:'import * as Cause from "effect/Cause"'},expected:"Cause",toCodec:([r,i])=>zd()(XP(MD(r,i)),Ly({decode:AP,encode:({reasons:o})=>o})),toArbitrary:([r,i])=>e6(r,i),toEquivalence:([r,i])=>t6(r,i),toFormatter:([r,i])=>n6(r,i)});return ht(n.ast,{error:e,defect:t})}function e6(e,t){return(n,r)=>n.array(Q5(e,t)(n,r)).map(AP)}function t6(e,t){const n=ufe(J5(e,t));return(r,i)=>n(r.reasons,i.reasons)}function n6(e,t){const n=Z5(e,t);return r=>`Cause([${r.reasons.map(n).join(", ")}])`}const r6=Nn({message:ar,name:KP(ar),stack:KP(ar)}),Yve=Gve(globalThis.Error,{typeConstructor:{_tag:"Error"},generation:{runtime:"Schema.Error",Type:"globalThis.Error"},expected:"Error",toCodecJson:()=>zd()(r6,m5()),toArbitrary:()=>e=>e.string().map(t=>new globalThis.Error(t))}),ND=new Or(_l(),sr(e=>{try{return JSON.parse(JSON.stringify(e))}catch{return Jt(e)}})),wi=yi([r6.pipe(xm(Yve,m5())),ID.pipe(xm(G5.annotate({toCodecJson:()=>zd()(ID,ND),toArbitrary:()=>e=>e.json()}),ND))]);function Qve(e,t,n){const r=Uy()([e,t,n],([i,o,a])=>{const u=$D(o,a);return(c,f,h)=>{if(!vge(c))return vt(new Ui(f,He(c)));switch(c._tag){case"Success":return gd(As(i)(c.value,h),{onSuccess:m1,onFailure:d=>new $n(f,He(c),[new mi(["value"],d)])});case"Failure":return gd(As(u)(c.cause,h),{onSuccess:cf,onFailure:d=>new $n(f,He(c),[new mi(["cause"],d)])})}}},{typeConstructor:{_tag:"effect/Exit"},generation:{runtime:"Schema.Exit(?, ?, ?)",Type:"Exit.Exit<?, ?, ?>",importDeclaration:'import * as Exit from "effect/Exit"'},expected:"Exit",toCodec:([i,o,a])=>zd()(yi([Nn({_tag:da("Success"),value:i}),Nn({_tag:da("Failure"),cause:$D(o,a)})]),Ly({decode:u=>u._tag==="Success"?m1(u.value):cf(u.cause),encode:u=>wge(u)?{_tag:"Success",value:u.value}:{_tag:"Failure",cause:u.cause}})),toArbitrary:([i,o,a])=>(u,c)=>u.oneof(c!=null&&c.isSuspend?{maxDepth:2,depthIdentifier:"Exit"}:{},i.map(f=>m1(f)),e6(o,a)(u,c).map(f=>cf(f))),toEquivalence:([i,o,a])=>{const u=t6(o,a);return(c,f)=>{if(c._tag!==f._tag)return!1;switch(c._tag){case"Success":return i(c.value,f.value);case"Failure":return u(c.cause,f.cause)}}},toFormatter:([i,o,a])=>{const u=n6(o,a);return c=>{switch(c._tag){case"Success":return`Exit.Success(${i(c.value)})`;case"Failure":return`Exit.Failure(${u(c.cause)})`}}}});return ht(r.ast,{value:e,error:t,defect:n})}const Jve=K5.check(Xve()),Zve=globalThis.Symbol.for("immer-draftable");function UE(e,t,n,r,i){var c,f,h,d;const o=t0e(n,t,r),a=i6(t),u=(d=class extends e{constructor(...[g,m]){g=g??{};const v=n.make(g,m);super({...g,...v},{...m,disableChecks:!0})}get[(h=pf,f=a,c=Zve,f)](){return a}static get ast(){return o(this).ast}static pipe(){return Sn(this,arguments)}static rebuild(g){return o(this).rebuild(g)}static make(g,m){return new this(g,m)}static makeOption(g,m){return W5(o(this))(g??{},m)}static makeEffect(g,m){return zs(zy(o(this))(g??{},m),v=>new qy(v))}static annotate(g){return this.rebuild(k5(this.ast,g))}static annotateKey(g){return this.rebuild(T5(this.ast,g))}static check(...g){return this.rebuild(NE(this.ast,g))}static extend(g){return(m,v)=>{const x={...n.fields,...m};return UE(this,g,qE(RE(x,n.ast.checks,{identifier:g}),x),v,i)}}static mapFields(g,m){return n.mapFields(g,m)}},Q(d,h,pf),Q(d,c,!0),Q(d,"identifier",t),Q(d,"fields",n.fields),d);return i!==void 0&&Object.assign(u.prototype,i(t)),u}function e0e(e){return new Or(sr(t=>new e(t)),_l())}function i6(e){return`~effect/Schema/Class/${e}`}function t0e(e,t,n){let r;return i=>{if(r===void 0){const o=e0e(i),a=ht(new Fd([e.ast],()=>(u,c)=>u instanceof i||it(u,i6(t))?Mt(u):vt(new Ui(c,He(u))),{identifier:t,[B5]:([u])=>new pn(u,o),toCodec:([u])=>new pn(u.ast,o),toArbitrary:([u])=>()=>u.map(c=>new i(c)),toFormatter:([u])=>c=>`${i.identifier}(${u(c)})`,"~sentinels":ME(e.ast),...n}));r=e.pipe(xm(a,o))}return r}}function VE(e){return zE(e)}const n0e=e=>(t,n)=>{const r=VE(t)?t:Nn(t);return UE(Nge,e,r,n,i=>({toString(){return`${i}(${Jt({...this})})`}}))},Yr=e=>(t,n)=>{const r=VE(t)?t:Nn(t);return UE(wU,e,r,n,o=>({name:o}))},r0e=e=>(t,n,r)=>Yr(e)(VE(n)?n.mapFields(i=>({_tag:fr(t),...i}),{unsafePreserveChecks:!0}):Hve(t,n),r);function x1(e){return ht(o6(e.ast))}const o6=L5(e=>{const t=i0e(e,o6);return t!==e&&ho(e)?R5(t):t});function i0e(e,t){var n,r;switch(e._tag){case"Declaration":{const i=((n=e.annotations)==null?void 0:n.toCodecJson)??((r=e.annotations)==null?void 0:r.toCodec);if(py(i)){const o=y5(e)?e.typeParameters.map(c=>BE(fa(c))):[],a=i(o),u=t(a.to);return fn(e,u===a.to?[a]:[new pn(u,a.transformation)])}return fn(e,[Gye])}case"Unknown":case"ObjectKeyword":return fn(e,[Kye]);case"Undefined":case"Void":case"Literal":case"Number":return e.toCodecJson();case"UniqueSymbol":case"Symbol":case"BigInt":return e.toCodecStringTree();case"Objects":{if(e.propertySignatures.some(i=>typeof i.name!="string"))throw new globalThis.Error("Objects property names must be strings",{cause:e});return e.recur(t)}case"Union":{const i=Mve(e.types);return i!==e.types?new Bd(i,e.mode,e.annotations,e.checks,e.encoding,e.context).recur(t):e.recur(t)}case"Arrays":case"Suspend":return e.recur(t)}return e}const o0e="~effect/Stream",a0e={_R:Fe,_E:Fe,_A:Fe},s0e={[o0e]:a0e,pipe(){return Sn(this,arguments)}},u0e=e=>{const t=Object.create(s0e);return t.channel=e,t},l0e="~effect/Stream",c0e=e=>it(e,l0e),WE=u0e,f0e=e=>e.channel,d0e=e=>WE(_ve(e)),h0e=e=>WE(Pve(Bs(e,f0e))),p0e=ce(2,(e,t)=>WE(Cve(e.channel,t))),g0e=ce(2,(e,t)=>Eve(e.channel,n=>{let r=0;return J4({while:()=>r<n.length,body:()=>t(n[r++]),step:kd})})),YP="~effect/FiberSet",m0e=e=>it(e,YP),y0e={[YP]:YP,[Symbol.iterator](){return this.state._tag==="Closed"?Yfe():this.state.backing[Symbol.iterator]()},...ka,toJSON(){return{_id:"FiberMap",state:this.state}}},v0e=(e,t)=>{const n=Object.create(y0e);return n.state={_tag:"Open",backing:e},n.deferred=t,n},x0e=()=>t5(zr(()=>v0e(new Set,fE())),e=>vo(()=>{const t=e.state;if(t._tag==="Closed")return jt;e.state={_tag:"Closed"};const n=t.backing;return Yye(n).pipe(Cge(e.deferred))})),a6=-1,b0e=Fde(zde(yge,Bde(a6))),w0e=ce(e=>m0e(e[0]),(e,t,n)=>{if(e.state._tag==="Closed"){t.interruptUnsafe(a6);return}else if(e.state.backing.has(t))return;e.state.backing.add(t),t.addObserver(r=>{e.state._tag!=="Closed"&&(e.state.backing.delete(t),B4(r)&&((n==null?void 0:n.propagateInterruption)===!0?!b0e(r.cause):!gge(r.cause))&&ff(e.deferred,r))})}),S0e=(function(){let e;return()=>(e===void 0&&(e=DP(LP)),e)})(),_0e=e=>()=>Bs(cm(),t=>{const n=fm(t);return(r,i)=>{if(e.state._tag==="Closed")return S0e();const o=n(r,i);return w0e(e,o),o}}),LD=e=>dE(e.deferred),P0e="~effect/interfaces/PrimaryKey",DD="~effect/ManagedRuntime",O0e=(e,t)=>{const n=(t==null?void 0:t.memoMap)??gE(),r=hE("parallel"),i=um(r,"sequential"),o={onFiberStart:Qye(r)},a=h=>h?{...h,onFiberStart:h.onFiberStart?d=>{o.onFiberStart(d),h.onFiberStart(d)}:o.onFiberStart}:o;let u;const c=lm(h=>(u||(u=DP(ame(mE(e,n,i),d=>zr(()=>{f.cachedContext=d})),{...o,scheduler:h.currentScheduler})),ime(Xye(u)))),f={[DD]:DD,memoMap:n,scope:r,contextEffect:c,cachedContext:void 0,context(){return f.cachedContext===void 0?df(f.contextEffect):Promise.resolve(f.cachedContext)},dispose(){return df(f.disposeEffect)},disposeEffect:vo(()=>(f.contextEffect=rme("ManagedRuntime disposed"),f.cachedContext=void 0,Ny(f.scope,F4))),runFork(h,d){return f.cachedContext===void 0?DP(Su(f,h),a(d)):fm(f.cachedContext)(h,a(d))},runCallback(h,d){return f.cachedContext===void 0?Cme(Su(f,h),a(d)):Ome(f.cachedContext)(h,a(d))},runSyncExit(h){return f.cachedContext===void 0?o5(Su(f,h)):Tme(f.cachedContext)(h)},runSync(h){return f.cachedContext===void 0?PE(Su(f,h)):jme(f.cachedContext)(h)},runPromiseExit(h,d){return f.cachedContext===void 0?kme(Su(f,h),a(d)):Ame(f.cachedContext)(h,a(d))},runPromise(h,d){return f.cachedContext===void 0?df(Su(f,h),a(d)):Eme(f.cachedContext)(h,a(d))}};return f};function Su(e,t){return Gr(e.contextEffect,n=>gs(t,n))}const QP="~effect/rpc/RpcSchema/StreamSchema";function s6(e){return it(e,QP)}function u6(e){return s6(e)?He({success:e.success,error:e.error}):Wr()}const C0e=H5(c0e);function E0e(e,t){return ht(C0e.ast,{[QP]:QP,success:e,error:t})}const FD="~effect/rpc/Rpc",k0e={[FD]:FD,pipe(){return Sn(this,arguments)},setSuccess(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:e,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},setError(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:e,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},setPayload(e){return Ko({_tag:this._tag,payloadSchema:zE(e)?e:Nn(e),successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},middleware(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:new Set([...this.middlewares,e])})},prefix(e){return Ko({_tag:`${e}${this._tag}`,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},annotate(e,t){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,middlewares:this.middlewares,annotations:Aa(this.annotations,e,t)})},annotateMerge(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,middlewares:this.middlewares,annotations:xl(this.annotations,e)})}},Ko=e=>{function t(){}return Object.setPrototypeOf(t,k0e),Object.assign(t,e),t.key=`effect/rpc/Rpc/${e._tag}`,t},Bl=(e,t)=>{const n=(t==null?void 0:t.success)??vm,r=(t==null?void 0:t.error)??RD,i=(t==null?void 0:t.defect)??wi;let o;return t!=null&&t.primaryKey?o=class extends n0e(`effect/rpc/Rpc/${e}`)(t.payload){[P0e](){return t.primaryKey(this)}}:o=zE(t==null?void 0:t.payload)?t==null?void 0:t.payload:t!=null&&t.payload?Nn(t==null?void 0:t.payload):vm,Ko({_tag:e,payloadSchema:o,successSchema:t!=null&&t.stream?E0e(n,r):n,errorSchema:t!=null&&t.stream?RD:r,defectSchema:i,annotations:gi(),middlewares:new Set})},b1=new WeakMap,A0e=e=>{if(b1.has(e))return b1.get(e);const t=e,n=new Set([t.errorSchema]),r=u6(t.successSchema);ga(r)&&n.add(r.value.error);for(const o of t.middlewares)n.add(o.error);const i=Qve(ga(r)?vm:t.successSchema,yi([...n]),t.defectSchema);return b1.set(e,i),i},j0e="~effect/rpc/Rpc/Wrapper",T0e=e=>j0e in e,BD=Symbol.for("~effect/http/Headers"),yd=Object.create(null);Object.defineProperties(yd,{[BD]:{value:BD},[my]:{value(e){return $0e(this,hs(e,N0e))}},toJSON:{value(){return yy(this)}},[Wn]:{value(e){return I0e(this,e)}},[Vn]:{value(){return DC(this)}},toString:{value:BL.toString},[Cs]:{value:BL[Cs]}});const R0e=e=>Object.assign(Object.create(yd),e),I0e=ede(sfe()),HE=Object.create(yd),M0e=e=>{if(e===void 0)return HE;if(Symbol.iterator in e){const n=Object.create(yd);for(const[r,i]of e)n[r.toLowerCase()]=i;return n}const t=Object.create(yd);for(const[n,r]of Object.entries(e))Array.isArray(r)?t[n.toLowerCase()]=r.join(", "):r!==void 0&&(t[n.toLowerCase()]=r);return t},zD=ce(2,(e,t)=>{const n=R0e(e);return Object.assign(n,t),n}),$0e=ce(2,(e,t)=>{const n={...e},r=i=>{if(typeof i=="string"){const o=i.toLowerCase();o in e&&(n[o]=mD(e[o]))}else for(const o in e)i.test(o)&&(n[o]=mD(e[o]))};if(Array.isArray(t))for(let i=0;i<t.length;i++)r(t[i]);else r(t);return n}),N0e=Pt("effect/Headers/CurrentRedactedNames",{defaultValue:()=>["authorization","cookie","set-cookie","x-api-key"]}),L0e="~effect/http/HttpClientError";class GE extends Yr(L0e)({_tag:fr("HttpError"),kind:Vy(["EncodeError","DecodeError","TransportError","InvalidUrlError","StatusCodeError","EmptyBodyError"]),cause:Fl(wi)}){static fromHttpClientError(t){return new GE({_tag:"HttpError",kind:t.reason._tag,cause:t.reason})}}const qD="~effect/socket/Socket",KE=Xr("effect/socket/Socket"),D0e=e=>KE.of({[qD]:qD,runRaw:e.runRaw,run:e.run??((t,n)=>e.runRaw(r=>typeof r=="string"?t(F0e.encode(r)):r instanceof Uint8Array?t(r):t(new Uint8Array(r)),n)),runString:e.runString??(e.run?(t,n)=>e.run(r=>t(w1.decode(r)),n):(t,n)=>e.runRaw(r=>typeof r=="string"?t(r):r instanceof Uint8Array?t(w1.decode(r)):t(w1.decode(new Uint8Array(r))),n)),writer:e.writer}),F0e=new TextEncoder,w1=new TextDecoder,B0e="~effect/socket/Socket/CloseEvent",z0e=e=>it(e,B0e),Wp="~effect/socket/Socket/SocketError",q0e=e=>it(e,Wp);class l6 extends Yr("effect/socket/Socket/SocketReadError")({_tag:fr("SocketReadError"),cause:wi}){constructor(){super(...arguments);Q(this,"message","An error occurred during Read")}}class U0e extends Yr("effect/socket/Socket/SocketWriteError")({_tag:fr("SocketWriteError"),cause:wi}){constructor(){super(...arguments);Q(this,"message","An error occurred during Write")}}class bm extends Yr("effect/socket/Socket/SocketOpenError")({_tag:fr("SocketOpenError"),kind:Vy(["Unknown","Timeout"]),cause:wi}){get message(){return this.kind==="Timeout"?'timeout waiting for "open"':"An error occurred during Open"}}class wm extends Yr("effect/socket/Socket/SocketCloseError")({_tag:fr("SocketCloseError"),code:K5,closeReason:Fl(ar)}){static filterClean(t){return function(n){return Fu.is(n)&&n.reason._tag==="SocketCloseError"&&t(n.reason.code)?So(n.reason):pi(n)}}get message(){return this.closeReason?`${this.code}: ${this.closeReason}`:`${this.code}`}}const c6=yi([l6,U0e,bm,wm]);var RF,IF;class Fu extends(IF=r0e(Wp)("SocketError",{_tag:fr("SocketError"),reason:c6}),RF=Wp,IF){constructor(n){var t=(...KSe)=>(super(...KSe),Q(this,RF,Wp),Q(this,"message",this.reason.message),this);"cause"in n.reason?t({...n,cause:n.reason.cause}):t(n)}static is(n){return q0e(n)}}const V0e=e=>!0;class W0e extends Xr()("~effect/socket/Socket/WebSocket"){}class f6 extends Xr()("@effect/platform/Socket/WebSocketConstructor"){}const H0e=yE(f6)((e,t)=>new globalThis.WebSocket(e,t)),G0e=(e,t)=>f6.use(n=>K0e(t5((typeof e=="string"?Mt(e):e).pipe(Bs(r=>n(r,t==null?void 0:t.protocols))),r=>zr(()=>r.close(1e3))),t)),K0e=(e,t)=>lm(n=>{let r;const i=z5(!1),o=n.context,a=(t==null?void 0:t.closeCodeIsError)??V0e,u=(h,d)=>xme(ms(function*(g){const m=yield*x0e().pipe(sm(g)),v=yield*sm(e,g),x=yield*vme(_0e(m)(),W0e,v);let b=!1;function O(E){if(E.data instanceof Blob){const A=Gr(Zge(()=>E.data.arrayBuffer()),j=>{const R=h(new Uint8Array(j));return Du(R)?R:jt});return x(A)}const P=h(E.data);Du(P)&&x(P)}function _(E){v.removeEventListener("message",O),v.removeEventListener("close",C),ff(m.deferred,vt(new Fu({reason:b?new l6({cause:E}):new bm({kind:"Unknown",cause:E})})))}function C(E){const P=typeof E.code=="number"?E.code:1001;v.removeEventListener("message",O),v.removeEventListener("error",_),ff(m.deferred,vt(new Fu({reason:new wm({code:P,closeReason:E.reason})})))}if(v.addEventListener("close",C,{once:!0}),v.addEventListener("error",_,{once:!0}),v.addEventListener("message",O),v.readyState!==1){const E=fE();v.addEventListener("open",()=>{b=!0,ff(E,jt)},{once:!0}),yield*dE(E).pipe(dme({duration:(t==null?void 0:t.openTimeout)??1e4,orElse:()=>vt(new Fu({reason:new bm({kind:"Timeout",cause:new Error('timeout waiting for "open"')})}))}),Z4(LD(m)))}return b=!0,r=v,i.openUnsafe(),d!=null&&d.onOpen&&(yield*d.onOpen),yield*sme(LD(m),wm.filterClean(E=>!a(E)),()=>jt)})).pipe(yme(g=>xl(o,g)),n5(zr(()=>{i.closeUnsafe(),r=void 0}))),f=Mt(h=>i.whenOpen(zr(()=>{const d=r;z0e(h)?d.close(h.code,h.reason):d.send(h)})));return Mt(D0e({runRaw:u,writer:f}))}),X0e=sU(G0e,IP(KE));class d6 extends Xr()("effect/workers/Transferable/Collector"){}const Y0e=()=>{let e=[];const t=i=>{e.push(...i)},n=()=>e,r=()=>{const i=e;return e=[],i};return d6.of({addAllUnsafe:t,addAll:i=>zr(()=>t(i)),readUnsafe:n,read:zr(n),clearUnsafe:r,clear:zr(r)})};class Q0e extends Yr("effect/workers/WorkerError/WorkerSpawnError")({_tag:fr("WorkerSpawnError"),message:ar,cause:Fl(wi)}){}class J0e extends Yr("effect/workers/WorkerError/WorkerSendError")({_tag:fr("WorkerSendError"),message:ar,cause:Fl(wi)}){}class Z0e extends Yr("effect/workers/WorkerError/WorkerReceiveError")({_tag:fr("WorkerReceiveError"),message:ar,cause:Fl(wi)}){}class exe extends Yr("effect/workers/WorkerError/WorkerUnknownError")({_tag:fr("WorkerUnknownError"),message:ar,cause:Fl(wi)}){}const txe=yi([Q0e,J0e,Z0e,exe]),S1="~effect/rpc/RpcClientError";class JP extends Yr("effect/rpc/RpcClientError/RpcClientDefect")({_tag:fr("RpcClientDefect"),message:ar,cause:wi}){}var MF,$F;class UD extends($F=Yr(S1)({_tag:fr("RpcClientError"),reason:yi([txe,c6,GE,JP])}),MF=S1,$F){constructor(){super(...arguments);Q(this,MF,S1)}get message(){return`${this.reason._tag}: ${this.reason.message}`}}const Pp=e=>typeof e=="bigint"?e:BigInt(e),nxe={_tag:"Ping"};var ZP;try{ZP=new TextDecoder}catch{}var ye,Ni,J=0,dt={},We,oa,Dr=0,Ai=0,cn,po,ur=[],Ue,VD={useRecords:!1,mapsAsObjects:!0};class h6{}const p6=new h6;p6.name="MessagePack 0xC1";var ha=!1,WD=2,rxe;class vd{constructor(t){t&&(t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.sequential&&t.trusted!==!1&&(t.trusted=!0,!t.structures&&t.useRecords!=!1&&(t.structures=[],t.maxSharedStructures||(t.maxSharedStructures=0))),t.structures?t.structures.sharedLength=t.structures.length:t.getStructures&&((t.structures=[]).uninitialized=!0,t.structures.sharedLength=0),t.int64AsNumber&&(t.int64AsType="number")),Object.assign(this,t)}unpack(t,n){if(ye)return b6(()=>(tO(),this?this.unpack(t,n):vd.prototype.unpack.call(VD,t,n)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<"u"?Buffer.from(t):new Uint8Array(t)),typeof n=="object"?(Ni=n.end||t.length,J=n.start||0):(J=0,Ni=n>-1?n:t.length),Ai=0,oa=null,cn=null,ye=t;try{Ue=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(r){throw ye=null,t instanceof Uint8Array?r:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof vd){if(dt=this,this.structures)return We=this.structures,Op(n);(!We||We.length>0)&&(We=[])}else dt=VD,(!We||We.length>0)&&(We=[]);return Op(n)}unpackMultiple(t,n){let r,i=0;try{ha=!0;let o=t.length,a=this?this.unpack(t,o):Wy.unpack(t,o);if(n){if(n(a,i,J)===!1)return;for(;J<o;)if(i=J,n(Op(),i,J)===!1)return}else{for(r=[a];J<o;)i=J,r.push(Op());return r}}catch(o){throw o.lastPosition=i,o.values=r,o}finally{ha=!1,tO()}}_mergeStructures(t,n){t=t||[],Object.isFrozen(t)&&(t=t.map(r=>r.slice(0)));for(let r=0,i=t.length;r<i;r++){let o=t[r];o&&(o.isShared=!0,r>=32&&(o.highByte=r-32>>5))}t.sharedLength=t.length;for(let r in n||[])if(r>=0){let i=t[r],o=n[r];o&&(i&&((t.restoreStructures||(t.restoreStructures=[]))[r]=i),t[r]=o)}return this.structures=t}decode(t,n){return this.unpack(t,n)}}function Op(e){try{if(!dt.trusted&&!ha){let n=We.sharedLength||0;n<We.length&&(We.length=n)}let t;if(dt.randomAccessStructure&&ye[J]<64&&ye[J]>=32&&rxe||(t=Ft()),cn&&(J=cn.postBundlePosition,cn=null),ha&&(We.restoreStructures=null),J==Ni)We&&We.restoreStructures&&HD(),We=null,ye=null,po&&(po=null);else{if(J>Ni)throw new Error("Unexpected end of MessagePack data");if(!ha){let n;try{n=JSON.stringify(t,(r,i)=>typeof i=="bigint"?`${i}n`:i).slice(0,100)}catch(r){n="(JSON view not available "+r+")"}throw new Error("Data read, but end of buffer not reached "+n)}}return t}catch(t){throw We&&We.restoreStructures&&HD(),tO(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer")||J>Ni)&&(t.incomplete=!0),t}}function HD(){for(let e in We.restoreStructures)We[e]=We.restoreStructures[e];We.restoreStructures=null}function Ft(){let e=ye[J++];if(e<160)if(e<128){if(e<64)return e;{let t=We[e&63]||dt.getStructures&&g6()[e&63];return t?(t.read||(t.read=XE(t,e&63)),t.read()):e}}else if(e<144)if(e-=128,dt.mapsAsObjects){let t={};for(let n=0;n<e;n++){let r=y6();r==="__proto__"&&(r="__proto_"),t[r]=Ft()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(Ft(),Ft());return t}else{e-=144;let t=new Array(e);for(let n=0;n<e;n++)t[n]=Ft();return dt.freezeData?Object.freeze(t):t}else if(e<192){let t=e-160;if(Ai>=J)return oa.slice(J-Dr,(J+=t)-Dr);if(Ai==0&&Ni<140){let n=t<16?YE(t):m6(t);if(n!=null)return n}return eO(t)}else{let t;switch(e){case 192:return null;case 193:return cn?(t=Ft(),t>0?cn[1].slice(cn.position1,cn.position1+=t):cn[0].slice(cn.position0,cn.position0-=t)):p6;case 194:return!1;case 195:return!0;case 196:if(t=ye[J++],t===void 0)throw new Error("Unexpected end of buffer");return _1(t);case 197:return t=Ue.getUint16(J),J+=2,_1(t);case 198:return t=Ue.getUint32(J),J+=4,_1(t);case 199:return Ha(ye[J++]);case 200:return t=Ue.getUint16(J),J+=2,Ha(t);case 201:return t=Ue.getUint32(J),J+=4,Ha(t);case 202:if(t=Ue.getFloat32(J),dt.useFloat32>2){let n=QE[(ye[J]&127)<<1|ye[J+1]>>7];return J+=4,(n*t+(t>0?.5:-.5)>>0)/n}return J+=4,t;case 203:return t=Ue.getFloat64(J),J+=8,t;case 204:return ye[J++];case 205:return t=Ue.getUint16(J),J+=2,t;case 206:return t=Ue.getUint32(J),J+=4,t;case 207:return dt.int64AsType==="number"?(t=Ue.getUint32(J)*4294967296,t+=Ue.getUint32(J+4)):dt.int64AsType==="string"?t=Ue.getBigUint64(J).toString():dt.int64AsType==="auto"?(t=Ue.getBigUint64(J),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=Ue.getBigUint64(J),J+=8,t;case 208:return Ue.getInt8(J++);case 209:return t=Ue.getInt16(J),J+=2,t;case 210:return t=Ue.getInt32(J),J+=4,t;case 211:return dt.int64AsType==="number"?(t=Ue.getInt32(J)*4294967296,t+=Ue.getUint32(J+4)):dt.int64AsType==="string"?t=Ue.getBigInt64(J).toString():dt.int64AsType==="auto"?(t=Ue.getBigInt64(J),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=Ue.getBigInt64(J),J+=8,t;case 212:if(t=ye[J++],t==114)return JD(ye[J++]&63);{let n=ur[t];if(n)return n.read?(J++,n.read(Ft())):n.noBuffer?(J++,n()):n(ye.subarray(J,++J));throw new Error("Unknown extension "+t)}case 213:return t=ye[J],t==114?(J++,JD(ye[J++]&63,ye[J++])):Ha(2);case 214:return Ha(4);case 215:return Ha(8);case 216:return Ha(16);case 217:return t=ye[J++],Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):oxe(t);case 218:return t=Ue.getUint16(J),J+=2,Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):axe(t);case 219:return t=Ue.getUint32(J),J+=4,Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):sxe(t);case 220:return t=Ue.getUint16(J),J+=2,KD(t);case 221:return t=Ue.getUint32(J),J+=4,KD(t);case 222:return t=Ue.getUint16(J),J+=2,XD(t);case 223:return t=Ue.getUint32(J),J+=4,XD(t);default:if(e>=224)return e-256;if(e===void 0){let n=new Error("Unexpected end of MessagePack data");throw n.incomplete=!0,n}throw new Error("Unknown MessagePack token "+e)}}}const ixe=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function XE(e,t){function n(){if(n.count++>WD){let i;try{i=e.read=new Function("r","return function(){return "+(dt.freezeData?"Object.freeze":"")+"({"+e.map(o=>o==="__proto__"?"__proto_:r()":ixe.test(o)?o+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"})}")(Ft)}catch{return WD=1/0,n()}return e.read0=i,e.highByte===0&&(e.read=GD(t,e.read)),i()}let r={};for(let i=0,o=e.length;i<o;i++){let a=e[i];a==="__proto__"&&(a="__proto_"),r[a]=Ft()}return dt.freezeData?Object.freeze(r):r}return n.count=0,e.read0=n,e.highByte===0?GD(t,n):n}const GD=(e,t)=>function(){let n=ye[J++];if(n===0)return t();let r=e<32?-(e+(n<<5)):e+(n<<5),i=We[r]||g6()[r];if(!i)throw new Error("Record id is not defined for "+r);return i.read||(i.read=XE(i,e)),i.read()};function g6(){let e=b6(()=>(ye=null,dt.getStructures()));return We=dt._mergeStructures(e,We)}var eO=qd,oxe=qd,axe=qd,sxe=qd;function qd(e){let t;if(e<16&&(t=YE(e)))return t;if(e>64&&ZP)return ZP.decode(ye.subarray(J,J+=e));const n=J+e,r=[];for(t="";J<n;){const i=ye[J++];if((i&128)===0)r.push(i);else if((i&224)===192){const o=ye[J++]&63,a=(i&31)<<6|o;a<128?r.push(65533):r.push(a)}else if((i&240)===224){const o=ye[J++]&63,a=ye[J++]&63,u=(i&31)<<12|o<<6|a;u<2048||u>=55296&&u<=57343?r.push(65533):r.push(u)}else if((i&248)===240){const o=ye[J++]&63,a=ye[J++]&63,u=ye[J++]&63;let c=(i&7)<<18|o<<12|a<<6|u;c<65536||c>1114111?r.push(65533):(c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|c&1023),r.push(c))}else r.push(65533);r.length>=4096&&(t+=sn.apply(String,r),r.length=0)}return r.length>0&&(t+=sn.apply(String,r)),t}function KD(e){let t=new Array(e);for(let n=0;n<e;n++)t[n]=Ft();return dt.freezeData?Object.freeze(t):t}function XD(e){if(dt.mapsAsObjects){let t={};for(let n=0;n<e;n++){let r=y6();r==="__proto__"&&(r="__proto_"),t[r]=Ft()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(Ft(),Ft());return t}}var sn=String.fromCharCode;function m6(e){let t=J,n=new Array(e);for(let r=0;r<e;r++){const i=ye[J++];if((i&128)>0){J=t;return}n[r]=i}return sn.apply(String,n)}function YE(e){if(e<4)if(e<2){if(e===0)return"";{let t=ye[J++];if((t&128)>1){J-=1;return}return sn(t)}}else{let t=ye[J++],n=ye[J++];if((t&128)>0||(n&128)>0){J-=2;return}if(e<3)return sn(t,n);let r=ye[J++];if((r&128)>0){J-=3;return}return sn(t,n,r)}else{let t=ye[J++],n=ye[J++],r=ye[J++],i=ye[J++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){J-=4;return}if(e<6){if(e===4)return sn(t,n,r,i);{let o=ye[J++];if((o&128)>0){J-=5;return}return sn(t,n,r,i,o)}}else if(e<8){let o=ye[J++],a=ye[J++];if((o&128)>0||(a&128)>0){J-=6;return}if(e<7)return sn(t,n,r,i,o,a);let u=ye[J++];if((u&128)>0){J-=7;return}return sn(t,n,r,i,o,a,u)}else{let o=ye[J++],a=ye[J++],u=ye[J++],c=ye[J++];if((o&128)>0||(a&128)>0||(u&128)>0||(c&128)>0){J-=8;return}if(e<10){if(e===8)return sn(t,n,r,i,o,a,u,c);{let f=ye[J++];if((f&128)>0){J-=9;return}return sn(t,n,r,i,o,a,u,c,f)}}else if(e<12){let f=ye[J++],h=ye[J++];if((f&128)>0||(h&128)>0){J-=10;return}if(e<11)return sn(t,n,r,i,o,a,u,c,f,h);let d=ye[J++];if((d&128)>0){J-=11;return}return sn(t,n,r,i,o,a,u,c,f,h,d)}else{let f=ye[J++],h=ye[J++],d=ye[J++],g=ye[J++];if((f&128)>0||(h&128)>0||(d&128)>0||(g&128)>0){J-=12;return}if(e<14){if(e===12)return sn(t,n,r,i,o,a,u,c,f,h,d,g);{let m=ye[J++];if((m&128)>0){J-=13;return}return sn(t,n,r,i,o,a,u,c,f,h,d,g,m)}}else{let m=ye[J++],v=ye[J++];if((m&128)>0||(v&128)>0){J-=14;return}if(e<15)return sn(t,n,r,i,o,a,u,c,f,h,d,g,m,v);let x=ye[J++];if((x&128)>0){J-=15;return}return sn(t,n,r,i,o,a,u,c,f,h,d,g,m,v,x)}}}}}function YD(){let e=ye[J++],t;if(e<192)t=e-160;else switch(e){case 217:t=ye[J++];break;case 218:t=Ue.getUint16(J),J+=2;break;case 219:t=Ue.getUint32(J),J+=4;break;default:throw new Error("Expected string")}return qd(t)}function _1(e){return dt.copyBuffers?Uint8Array.prototype.slice.call(ye,J,J+=e):ye.subarray(J,J+=e)}function Ha(e){let t=ye[J++];if(ur[t]){let n;return ur[t](ye.subarray(J,n=J+=e),r=>{J=r;try{return Ft()}finally{J=n}})}else throw new Error("Unknown extension type "+t)}var QD=new Array(4096);function y6(){let e=ye[J++];if(e>=160&&e<192){if(e=e-160,Ai>=J)return oa.slice(J-Dr,(J+=e)-Dr);if(!(Ai==0&&Ni<180))return eO(e)}else return J--,v6(Ft());let t=(e<<5^(e>1?Ue.getUint16(J):e>0?ye[J]:0))&4095,n=QD[t],r=J,i=J+e-3,o,a=0;if(n&&n.bytes==e){for(;r<i;){if(o=Ue.getUint32(r),o!=n[a++]){r=1879048192;break}r+=4}for(i+=3;r<i;)if(o=ye[r++],o!=n[a++]){r=1879048192;break}if(r===i)return J=r,n.string;i-=3,r=J}for(n=[],QD[t]=n,n.bytes=e;r<i;)o=Ue.getUint32(r),n.push(o),r+=4;for(i+=3;r<i;)o=ye[r++],n.push(o);let u=e<16?YE(e):m6(e);return u!=null?n.string=u:n.string=eO(e)}function v6(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return e.toString();if(e==null)return e+"";if(dt.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(t=>["string","number","boolean","bigint"].includes(typeof t)))return e.flat().toString();throw new Error(`Invalid property type for record: ${typeof e}`)}const JD=(e,t)=>{let n=Ft().map(v6),r=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,n.highByte=t);let i=We[e];return i&&(i.isShared||ha)&&((We.restoreStructures||(We.restoreStructures=[]))[e]=i),We[e]=n,n.read=XE(n,r),(n.read0||n.read)()};ur[0]=()=>{};ur[0].noBuffer=!0;ur[66]=e=>{let t=e.byteLength%8||8,n=BigInt(e[0]&128?e[0]-256:e[0]);for(let r=1;r<t;r++)n<<=BigInt(8),n+=BigInt(e[r]);if(e.byteLength!==t){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(o,a)=>{let u=a-o;if(u<=40){let d=r.getBigUint64(o);for(let g=o+8;g<a;g+=8)d<<=BigInt(64),d|=r.getBigUint64(g);return d}let c=o+(u>>4<<3),f=i(o,c),h=i(c,a);return f<<BigInt((a-c)*8)|h};n=n<<BigInt((r.byteLength-t)*8)|i(t,r.byteLength)}return n};let ZD={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError=="function"?AggregateError:null};ur[101]=()=>{let e=Ft();if(!ZD[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return ZD[e[0]](e[1],{cause:e[2]})};ur[105]=e=>{if(dt.structuredClone===!1)throw new Error("Structured clone extension is disabled");let t=Ue.getUint32(J-4);po||(po=new Map);let n=ye[J],r;n>=144&&n<160||n==220||n==221?r=[]:n>=128&&n<144||n==222||n==223?r=new Map:(n>=199&&n<=201||n>=212&&n<=216)&&ye[J+1]===115?r=new Set:r={};let i={target:r};po.set(t,i);let o=Ft();if(i.used)Object.assign(r,o);else return i.target=o;if(r instanceof Map)for(let[a,u]of o.entries())r.set(a,u);if(r instanceof Set)for(let a of Array.from(o))r.add(a);return r};ur[112]=e=>{if(dt.structuredClone===!1)throw new Error("Structured clone extension is disabled");let t=Ue.getUint32(J-4),n=po.get(t);return n.used=!0,n.target};ur[115]=()=>new Set(Ft());const x6=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");let uxe=typeof globalThis=="object"?globalThis:window;ur[116]=e=>{let t=e[0],n=Uint8Array.prototype.slice.call(e,1).buffer,r=x6[t];if(!r){if(t===16)return n;if(t===17)return new DataView(n);throw new Error("Could not find typed array for code "+t)}return new uxe[r](n)};ur[120]=()=>{let e=Ft();return new RegExp(e[0],e[1])};const lxe=[];ur[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=J;return J+=t-e.length,cn=lxe,cn=[YD(),YD()],cn.position0=0,cn.position1=0,cn.postBundlePosition=J,J=n,Ft()};ur[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date("invalid");function b6(e){let t=Ni,n=J,r=Dr,i=Ai,o=oa,a=po,u=cn,c=new Uint8Array(ye.slice(0,Ni)),f=We,h=We.slice(0,We.length),d=dt,g=ha,m=e();return Ni=t,J=n,Dr=r,Ai=i,oa=o,po=a,cn=u,ye=c,ha=g,We=f,We.splice(0,We.length,...h),dt=d,Ue=new DataView(ye.buffer,ye.byteOffset,ye.byteLength),m}function tO(){ye=null,po=null,We=null}const QE=new Array(147);for(let e=0;e<256;e++)QE[e]=+("1e"+Math.floor(45.15-e*.30103));var Wy=new vd({useRecords:!1});Wy.unpack;Wy.unpackMultiple;Wy.unpack;let cxe=new Float32Array(1);new Uint8Array(cxe.buffer,0,4);let Hp;try{Hp=new TextEncoder}catch{}let nO,rO;const Cl=typeof Buffer<"u",Cp=Cl?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,w6=Cl?Buffer:Uint8Array,eF=Cl?4294967296:2144337920;let re,zc,at,ee=0,kn,Et=null,fxe;const dxe=21760,hxe=/[\u0080-\uFFFF]/,_u=Symbol("record-id");class pxe extends vd{constructor(t){super(t),this.offset=0;let n,r,i,o,a=w6.prototype.utf8Write?function(T,N){return re.utf8Write(T,N,re.byteLength-N)}:Hp&&Hp.encodeInto?function(T,N){return Hp.encodeInto(T,re.subarray(N)).written}:!1,u=this;t||(t={});let c=t&&t.sequential,f=t.structures||t.saveStructures,h=t.maxSharedStructures;if(h==null&&(h=f?32:0),h>8160)throw new Error("Maximum maxSharedStructure is 8160");t.structuredClone&&t.moreTypes==null&&(this.moreTypes=!0);let d=t.maxOwnStructures;d==null&&(d=f?32:64),!this.structures&&t.useRecords!=!1&&(this.structures=[]);let g=h>32||d+h>64,m=h+64,v=h+d+64;if(v>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let x=[],b=0,O=0;this.pack=this.encode=function(T,N){if(re||(re=new Cp(8192),at=re.dataView||(re.dataView=new DataView(re.buffer,0,8192)),ee=0),kn=re.length-10,kn-ee<2048?(re=new Cp(re.length),at=re.dataView||(re.dataView=new DataView(re.buffer,0,re.length)),kn=re.length-10,ee=0):ee=ee+7&2147483640,n=ee,N&xxe&&(ee+=N&255),o=u.structuredClone?new Map:null,u.bundleStrings&&typeof T!="string"?(Et=[],Et.size=1/0):Et=null,i=u.structures,i){i.uninitialized&&(i=u._mergeStructures(u.getStructures()));let z=i.sharedLength||0;if(z>h)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+i.sharedLength);if(!i.transitions){i.transitions=Object.create(null);for(let q=0;q<z;q++){let W=i[q];if(!W)continue;let Z,Y=i.transitions;for(let U=0,K=W.length;U<K;U++){let ae=W[U];Z=Y[ae],Z||(Z=Y[ae]=Object.create(null)),Y=Z}Y[_u]=q+64}this.lastNamedStructuresLength=z}c||(i.nextId=z+64)}r&&(r=!1);let B;try{u.randomAccessStructure&&!u.readOnlyStructures&&T&&typeof T=="object"?T.constructor===Object?L(T):T.constructor!==Map&&!Array.isArray(T)&&!rO.some(q=>T instanceof q)?L(T.toJSON?T.toJSON():T):E(T):E(T);let z=Et;if(Et&&nF(n,E,0),o&&o.idsToInsert){let q=o.idsToInsert.sort((U,K)=>U.offset>K.offset?1:-1),W=q.length,Z=-1;for(;z&&W>0;){let U=q[--W].offset+n;U<z.stringsPosition+n&&Z===-1&&(Z=0),U>z.position+n?Z>=0&&(Z+=6):(Z>=0&&(at.setUint32(z.position+n,at.getUint32(z.position+n)+Z),Z=-1),z=z.previous,W++)}Z>=0&&z&&at.setUint32(z.position+n,at.getUint32(z.position+n)+Z),ee+=q.length*6,ee>kn&&M(ee),u.offset=ee;let Y=gxe(re.subarray(n,ee),q);return o=null,Y}return u.offset=ee,N&yxe?(re.start=n,re.end=ee,re):re.subarray(n,ee)}catch(z){throw B=z,z}finally{if(i&&(_(),r&&u.saveStructures)){let z=i.sharedLength||0,q=re.subarray(n,ee),W=mxe(i,u);if(!B)return u.saveStructures(W,W.isCompatible)===!1?(i.uninitialized=!0,u.pack(T,N)):(u.lastNamedStructuresLength=z,re.length>1073741824&&(re=null),q)}re.length>1073741824&&(re=null),N&vxe&&(ee=n)}};const _=()=>{O<10&&O++;let T=i.sharedLength||0;if(i.length>T&&!c&&(i.length=T),b>1e4)i.transitions=null,O=0,b=0,x.length>0&&(x=[]);else if(x.length>0&&!c){for(let N=0,B=x.length;N<B;N++)x[N][_u]=0;x=[]}},C=T=>{var N=T.length;N<16?re[ee++]=144|N:N<65536?(re[ee++]=220,re[ee++]=N>>8,re[ee++]=N&255):(re[ee++]=221,at.setUint32(ee,N),ee+=4);for(let B=0;B<N;B++)E(T[B])},E=T=>{ee>kn&&(re=M(ee));var N=typeof T,B;if(N==="string"){let z=T.length;if(Et&&z>=4&&z<4096){if((Et.size+=z)>dxe){let Y,U=(Et[0]?Et[0].length*3+Et[1].length:0)+10;ee+U>kn&&(re=M(ee+U));let K;Et.position?(K=Et,re[ee]=200,ee+=3,re[ee++]=98,Y=ee-n,ee+=4,nF(n,E,0),at.setUint16(Y+n-3,ee-n-Y)):(re[ee++]=214,re[ee++]=98,Y=ee-n,ee+=4),Et=["",""],Et.previous=K,Et.size=0,Et.position=Y}let Z=hxe.test(T);Et[Z?0:1]+=T,re[ee++]=193,E(Z?-z:z);return}let q;z<32?q=1:z<256?q=2:z<65536?q=3:q=5;let W=z*3;if(ee+W>kn&&(re=M(ee+W)),z<64||!a){let Z,Y,U,K=ee+q;for(Z=0;Z<z;Z++)Y=T.charCodeAt(Z),Y<128?re[K++]=Y:Y<2048?(re[K++]=Y>>6|192,re[K++]=Y&63|128):(Y&64512)===55296&&((U=T.charCodeAt(Z+1))&64512)===56320?(Y=65536+((Y&1023)<<10)+(U&1023),Z++,re[K++]=Y>>18|240,re[K++]=Y>>12&63|128,re[K++]=Y>>6&63|128,re[K++]=Y&63|128):(re[K++]=Y>>12|224,re[K++]=Y>>6&63|128,re[K++]=Y&63|128);B=K-ee-q}else B=a(T,ee+q);B<32?re[ee++]=160|B:B<256?(q<2&&re.copyWithin(ee+2,ee+1,ee+1+B),re[ee++]=217,re[ee++]=B):B<65536?(q<3&&re.copyWithin(ee+3,ee+2,ee+2+B),re[ee++]=218,re[ee++]=B>>8,re[ee++]=B&255):(q<5&&re.copyWithin(ee+5,ee+3,ee+3+B),re[ee++]=219,at.setUint32(ee,B),ee+=4),ee+=B}else if(N==="number")if(T>>>0===T)T<32||T<128&&this.useRecords===!1||T<64&&!this.randomAccessStructure?re[ee++]=T:T<256?(re[ee++]=204,re[ee++]=T):T<65536?(re[ee++]=205,re[ee++]=T>>8,re[ee++]=T&255):(re[ee++]=206,at.setUint32(ee,T),ee+=4);else if(T>>0===T)T>=-32?re[ee++]=256+T:T>=-128?(re[ee++]=208,re[ee++]=T+256):T>=-32768?(re[ee++]=209,at.setInt16(ee,T),ee+=2):(re[ee++]=210,at.setInt32(ee,T),ee+=4);else{let z;if((z=this.useFloat32)>0&&T<4294967296&&T>=-2147483648){re[ee++]=202,at.setFloat32(ee,T);let q;if(z<4||(q=T*QE[(re[ee]&127)<<1|re[ee+1]>>7])>>0===q){ee+=4;return}else ee--}re[ee++]=203,at.setFloat64(ee,T),ee+=8}else if(N==="object"||N==="function")if(!T)re[ee++]=192;else{if(o){let q=o.get(T);if(q){if(!q.id){let W=o.idsToInsert||(o.idsToInsert=[]);q.id=W.push(q)}re[ee++]=214,re[ee++]=112,at.setUint32(ee,q.id),ee+=4;return}else o.set(T,{offset:ee-n})}let z=T.constructor;if(z===Object)R(T);else if(z===Array)C(T);else if(z===Map)if(this.mapAsEmptyObject)re[ee++]=128;else{B=T.size,B<16?re[ee++]=128|B:B<65536?(re[ee++]=222,re[ee++]=B>>8,re[ee++]=B&255):(re[ee++]=223,at.setUint32(ee,B),ee+=4);for(let[q,W]of T)E(q),E(W)}else{for(let q=0,W=nO.length;q<W;q++){let Z=rO[q];if(T instanceof Z){let Y=nO[q];if(Y.write){Y.type&&(re[ee++]=212,re[ee++]=Y.type,re[ee++]=0);let he=Y.write.call(this,T);he===T?Array.isArray(T)?C(T):R(T):E(he);return}let U=re,K=at,ae=ee;re=null;let pe;try{pe=Y.pack.call(this,T,he=>(re=U,U=null,ee+=he,ee>kn&&M(ee),{target:re,targetView:at,position:ee-he}),E)}finally{U&&(re=U,at=K,ee=ae,kn=re.length-10)}pe&&(pe.length+ee>kn&&M(pe.length+ee),ee=tF(pe,re,ee,Y.type));return}}if(Array.isArray(T))C(T);else{if(T.toJSON){const q=T.toJSON();if(q!==T)return E(q)}if(N==="function")return E(this.writeFunction&&this.writeFunction(T));R(T)}}}else if(N==="boolean")re[ee++]=T?195:194;else if(N==="bigint"){if(T<9223372036854776e3&&T>=-9223372036854776e3)re[ee++]=211,at.setBigInt64(ee,T);else if(T<18446744073709552e3&&T>0)re[ee++]=207,at.setBigUint64(ee,T);else if(this.largeBigIntToFloat)re[ee++]=203,at.setFloat64(ee,Number(T));else{if(this.largeBigIntToString)return E(T.toString());if(this.useBigIntExtension||this.moreTypes){let z=T<0?BigInt(-1):BigInt(0),q;if(T>>BigInt(65536)===z){let W=BigInt(18446744073709552e3)-BigInt(1),Z=[];for(;Z.push(T&W),T>>BigInt(63)!==z;)T>>=BigInt(64);q=new Uint8Array(new BigUint64Array(Z).buffer),q.reverse()}else{let W=T<0,Z=(W?~T:T).toString(16);if(Z.length%2?Z="0"+Z:parseInt(Z.charAt(0),16)>=8&&(Z="00"+Z),Cl)q=Buffer.from(Z,"hex");else{q=new Uint8Array(Z.length/2);for(let Y=0;Y<q.length;Y++)q[Y]=parseInt(Z.slice(Y*2,Y*2+2),16)}if(W)for(let Y=0;Y<q.length;Y++)q[Y]=~q[Y]}q.length+ee>kn&&M(q.length+ee),ee=tF(q,re,ee,66);return}else throw new RangeError(T+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}ee+=8}else if(N==="undefined")this.encodeUndefinedAsNil?re[ee++]=192:(re[ee++]=212,re[ee++]=0,re[ee++]=0);else throw new Error("Unknown type: "+N)},P=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?T=>{let N;if(this.skipValues){N=[];for(let q in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(q))&&!this.skipValues.includes(T[q])&&N.push(q)}else N=Object.keys(T);let B=N.length;B<16?re[ee++]=128|B:B<65536?(re[ee++]=222,re[ee++]=B>>8,re[ee++]=B&255):(re[ee++]=223,at.setUint32(ee,B),ee+=4);let z;if(this.coercibleKeyAsNumber)for(let q=0;q<B;q++){z=N[q];let W=Number(z);E(isNaN(W)?z:W),E(T[z])}else for(let q=0;q<B;q++)E(z=N[q]),E(T[z])}:T=>{re[ee++]=222;let N=ee-n;ee+=2;let B=0;for(let z in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(z))&&(E(z),E(T[z]),B++);if(B>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');re[N+++n]=B>>8,re[N+n]=B&255},A=this.useRecords===!1?P:t.progressiveRecords&&!g?T=>{let N,B=i.transitions||(i.transitions=Object.create(null)),z=ee++-n,q;for(let W in T)if(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W)){if(N=B[W],N)B=N;else{let Z=Object.keys(T),Y=B;B=i.transitions;let U=0;for(let K=0,ae=Z.length;K<ae;K++){let pe=Z[K];N=B[pe],N||(N=B[pe]=Object.create(null),U++),B=N}z+n+1==ee?(ee--,F(B,Z,U)):$(B,Z,z,U),q=!0,B=Y[W]}E(T[W])}if(!q){let W=B[_u];W?re[z+n]=W:$(B,Object.keys(T),z,0)}}:T=>{let N,B=i.transitions||(i.transitions=Object.create(null)),z=0;for(let W in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W))&&(N=B[W],N||(N=B[W]=Object.create(null),z++),B=N);let q=B[_u];q?q>=96&&g?(re[ee++]=((q-=96)&31)+96,re[ee++]=q>>5):re[ee++]=q:F(B,B.__keys__||Object.keys(T),z);for(let W in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W))&&E(T[W])},j=typeof this.useRecords=="function"&&this.useRecords,R=j?T=>{j(T)?A(T):P(T)}:A,M=T=>{let N;if(T>16777216){if(T-n>eF)throw new Error("Packed buffer would be larger than maximum buffer size");N=Math.min(eF,Math.round(Math.max((T-n)*(T>67108864?1.25:2),4194304)/4096)*4096)}else N=(Math.max(T-n<<2,re.length-1)>>12)+1<<12;let B=new Cp(N);return at=B.dataView||(B.dataView=new DataView(B.buffer,0,N)),T=Math.min(T,re.length),re.copy?re.copy(B,0,n,T):B.set(re.slice(n,T)),ee-=n,n=0,kn=B.length-10,re=B},F=(T,N,B)=>{let z=i.nextId;z||(z=64),z<m&&this.shouldShareStructure&&!this.shouldShareStructure(N)?(z=i.nextOwnId,z<v||(z=m),i.nextOwnId=z+1):(z>=v&&(z=m),i.nextId=z+1);let q=N.highByte=z>=96&&g?z-96>>5:-1;T[_u]=z,T.__keys__=N,i[z-64]=N,z<m?(N.isShared=!0,i.sharedLength=z-63,r=!0,q>=0?(re[ee++]=(z&31)+96,re[ee++]=q):re[ee++]=z):(q>=0?(re[ee++]=213,re[ee++]=114,re[ee++]=(z&31)+96,re[ee++]=q):(re[ee++]=212,re[ee++]=114,re[ee++]=z),B&&(b+=O*B),x.length>=d&&(x.shift()[_u]=0),x.push(T),E(N))},$=(T,N,B,z)=>{let q=re,W=ee,Z=kn,Y=n;re=zc,ee=0,n=0,re||(zc=re=new Cp(8192)),kn=re.length-10,F(T,N,z),zc=re;let U=ee;if(re=q,ee=W,kn=Z,n=Y,U>1){let K=ee+U-1;K>kn&&M(K);let ae=B+n;re.copyWithin(ae+U,ae+1,ee),re.set(zc.slice(0,U),ae),ee=K}else re[B+n]=zc[0]},L=T=>{let N=fxe(T,re,n,ee,i,M,(B,z,q)=>{if(q)return r=!0;ee=z;let W=re;return E(B),_(),W!==re?{position:ee,targetView:at,target:re}:ee},this);if(N===0)return R(T);ee=N}}useBuffer(t){re=t,re.dataView||(re.dataView=new DataView(re.buffer,re.byteOffset,re.byteLength)),at=re.dataView,ee=0}set position(t){ee=t}get position(){return ee}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}rO=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,h6];nO=[{pack(e,t,n){let r=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&r>=0&&r<4294967296){let{target:i,targetView:o,position:a}=t(6);i[a++]=214,i[a++]=255,o.setUint32(a,r)}else if(r>0&&r<4294967296){let{target:i,targetView:o,position:a}=t(10);i[a++]=215,i[a++]=255,o.setUint32(a,e.getMilliseconds()*4e6+(r/1e3/4294967296>>0)),o.setUint32(a+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return t(0),n(this.onInvalidDate());let{target:i,targetView:o,position:a}=t(3);i[a++]=212,i[a++]=255,i[a++]=255}else{let{target:i,targetView:o,position:a}=t(15);i[a++]=199,i[a++]=12,i[a++]=255,o.setUint32(a,e.getMilliseconds()*1e6),o.setBigInt64(a+4,BigInt(Math.floor(r)))}}},{pack(e,t,n){if(this.setAsEmptyObject)return t(0),n({});let r=Array.from(e),{target:i,position:o}=t(this.moreTypes?3:0);this.moreTypes&&(i[o++]=212,i[o++]=115,i[o++]=0),n(r)}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=101,r[i++]=0),n([e.name,e.message,e.cause])}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=120,r[i++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?P1(e,16,t):O1(Cl?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==w6&&this.moreTypes?P1(e,x6.indexOf(n.name),t):O1(e,t)}},{pack(e,t){this.moreTypes?P1(e,17,t):O1(Cl?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:n,position:r}=t(1);n[r]=193}}];function P1(e,t,n,r){let i=e.byteLength;if(i+1<256){var{target:o,position:a}=n(4+i);o[a++]=199,o[a++]=i+1}else if(i+1<65536){var{target:o,position:a}=n(5+i);o[a++]=200,o[a++]=i+1>>8,o[a++]=i+1&255}else{var{target:o,position:a,targetView:u}=n(7+i);o[a++]=201,u.setUint32(a,i+1),a+=4}o[a++]=116,o[a++]=t,e.buffer||(e=new Uint8Array(e)),o.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a)}function O1(e,t){let n=e.byteLength;var r,i;if(n<256){var{target:r,position:i}=t(n+2);r[i++]=196,r[i++]=n}else if(n<65536){var{target:r,position:i}=t(n+3);r[i++]=197,r[i++]=n>>8,r[i++]=n&255}else{var{target:r,position:i,targetView:o}=t(n+5);r[i++]=198,o.setUint32(i,n),i+=4}r.set(e,i)}function tF(e,t,n,r){let i=e.length;switch(i){case 1:t[n++]=212;break;case 2:t[n++]=213;break;case 4:t[n++]=214;break;case 8:t[n++]=215;break;case 16:t[n++]=216;break;default:i<256?(t[n++]=199,t[n++]=i):i<65536?(t[n++]=200,t[n++]=i>>8,t[n++]=i&255):(t[n++]=201,t[n++]=i>>24,t[n++]=i>>16&255,t[n++]=i>>8&255,t[n++]=i&255)}return t[n++]=r,t.set(e,n),n+=i,n}function gxe(e,t){let n,r=t.length*6,i=e.length-r;for(;n=t.pop();){let o=n.offset,a=n.id;e.copyWithin(o+r,o,i),r-=6;let u=o+r;e[u++]=214,e[u++]=105,e[u++]=a>>24,e[u++]=a>>16&255,e[u++]=a>>8&255,e[u++]=a&255,i=o}return e}function nF(e,t,n){if(Et.length>0){at.setUint32(Et.position+e,ee+n-Et.position-e),Et.stringsPosition=ee-e;let r=Et;Et=null,t(r[0]),t(r[1])}}function mxe(e,t){return e.isCompatible=n=>{let r=!n||(t.lastNamedStructuresLength||0)===n.length;return r||t._mergeStructures(n),r},e}let S6=new pxe({useRecords:!1});S6.pack;S6.pack;const yxe=512,vxe=1024,xxe=2048;class JE extends Xr()("effect/rpc/RpcSerialization"){}const bxe=JE.of({contentType:"application/json",includesFraming:!1,makeUnsafe:()=>{const e=new TextDecoder;return{decode:t=>{const n=JSON.parse(typeof t=="string"?t:e.decode(t));return Array.isArray(n)?n:[n]},encode:t=>JSON.stringify(t)}}}),wxe=yE(JE)(bxe),Sxe=e=>vo(()=>{const t=new Set,n=new Map,r=new Map;let i=(o,a)=>e5(u=>{let c=n.get(o);return c||(c=[],n.set(o,c)),c.push([a,u]),jt});return Bs(e((o,a)=>{const u=r.get(o);return u?u(a):i(o,a)},t),o=>({...o,run(a,u){return NP(function*(){t.add(a),r.set(a,u);const c=n.get(a);if(c){n.delete(a);for(const[f,h]of c)yield*gs(vo(()=>u(f)),h)}return yield*r5(tme,()=>(t.delete(a),r.delete(a),jt))})}}))});let _xe=BigInt(0);const Pxe=ms(function*(e,t){const n=(t==null?void 0:t.spanPrefix)??"RpcClient",r=(t==null?void 0:t.supportsAck)??!0,i=(t==null?void 0:t.disableTracing)??!1,o=(t==null?void 0:t.generateRequestId)??(()=>_xe++),a=yield*cm(),u=hs(a,sD),c=new Map;let f=!1;yield*Age(u,lm(_=>(f=!0,h(bge(_.id)))));const h=ms(function*(_){for(const[C,E]of c)c.delete(C),E._tag==="Queue"?yield*_._tag==="Success"?kD(E.queue):Jc(E.queue,_.cause):E.resume(_)}),d=_=>{const C=s6(_.successSchema),E=v(_);return(P,A)=>{const j=A!=null&&A.headers?M0e(A.headers):HE,R=(A==null?void 0:A.context)??gi();if(!C){const F=$=>g(_,E,$,_.payloadSchema.make(P),j,R,(A==null?void 0:A.discard)??!1);return i?F(void 0):_me(`${n}.${_._tag}`,{attributes:t.spanAttributes},F)}const M=m(_,E,_.payloadSchema.make(P),j,(A==null?void 0:A.streamBufferSize)??16,R);return A!=null&&A.asQueue?M:h0e(Bs(M,d0e))}},g=(_,C,E,P,A,j,R)=>lm(M=>{if(f)return LP;const F=o(),$=C(T=>t.onFromClient({message:T,context:j,discard:R}),{_tag:"Request",id:F,tag:_._tag,payload:P,...E?{traceId:E.traceId,spanId:E.spanId,sampled:E.sampled}:{},headers:zD(M.getRef(iF),A)});if(R)return $;let L;return wme(hD(T=>{const N={_tag:"Effect",rpc:_,context:j,resume(B){T(B),L&&!L.pollUnsafe()&&M.currentDispatcher.scheduleTask(()=>{L.interruptUnsafe(M.id)},0)}};c.set(F,N),L=$.pipe(E?gD(E,{captureStackTrace:!1}):Fe,fm(M.context)),L.addObserver(B=>{if(B._tag==="Failure")return T(B)})}),T=>(c.delete(F),ome(Qc(L),x(F,Array.from(T),j))))}),m=ms(function*(_,C,E,P,A,j){if(f)return yield*LP;const R=i?void 0:yield*Sme(`${n}.${_._tag}`,{attributes:t.spanAttributes}),M=WP(),F=o(),$=_y(M.context,sD);yield*kge($,T=>c.has(F)?(c.delete(F),x(F,B4(T)?Array.from(mge(T.cause)):[],j)):jt);const L=yield*uve(A);return c.set(F,{_tag:"Queue",rpc:_,queue:L,scope:$,context:j}),yield*C(T=>t.onFromClient({message:T,context:j,discard:!1}),{_tag:"Request",id:F,tag:_._tag,payload:E,...R?{traceId:R.traceId,spanId:R.spanId,sampled:R.sampled}:{},headers:zD(M.getRef(iF),P)}).pipe(R?gD(R,{captureStackTrace:!1}):Fe,pd(T=>Jc(L,T)),SE,Pme($,{startImmediately:!0})),L}),v=_=>{const C=[];for(const E of _.middlewares.values()){const P=a.mapUnsafe.get(`${E.key}/Client`);P&&C.push(P)}return C.length===0?(E,P)=>E(P):function E(P,A,j=C.length-1){return j===-1?P(A):C[j]({rpc:_,request:A,next(R){return E(P,R,j-1)}})}},x=(_,C,E)=>hD(P=>{const A=WP();t.onFromClient({message:{_tag:"Interrupt",requestId:_,interruptors:C},context:E,discard:!1}).pipe(fme(1e3),fm(A.context)).addObserver(()=>{P(jt)})}),b=_=>{switch(_._tag){case"Chunk":{const C=_.requestId,E=c.get(C);return!E||E._tag!=="Queue"?jt:lve(E.queue,_.values).pipe(r?Gr(()=>t.onFromClient({message:{_tag:"Ack",requestId:_.requestId},context:E.context,discard:!1})):Fe,pd(P=>Jc(E.queue,P)))}case"Exit":{const C=_.requestId,E=c.get(C);return E?(c.delete(C),E._tag==="Effect"?(E.resume(_.exit),jt):_.exit._tag==="Success"?kD(E.queue):Jc(E.queue,_.exit.cause)):jt}case"Defect":return h(xge(_.defect));case"ClientEnd":return jt}};let O;if(t.flatten){const _=new Map;O=function(E,P,A){let j=_.get(E);return j||(j=d(e.requests.get(E)),_.set(E,j)),j(P,A)}}else O={},e.requests.forEach(_=>{O[_._tag]=d(_)});return{client:O,write:b}});let Oxe=0;const Cxe=ms(function*(e,t){const n=Oxe++,{run:r,send:i,supportsAck:o,supportsTransferables:a}=yield*Hy,u=new Map,{client:c,write:f}=yield*Pxe(e,{...t,supportsAck:o,onFromClient({message:h}){switch(h._tag){case"Request":{const d=e.requests.get(h.tag),g=a?Y0e():void 0,m=WP(),v={rpc:d,context:g?Aa(m.context,d6,g):m.context,schemas:Exe(d)};return u.set(h.id,v),v.schemas.encodePayload(h.payload).pipe(gs(v.context),zp,Gr(x=>i(n,{...h,id:String(h.id),payload:x,headers:Object.entries(h.headers)},g&&g.readUnsafe())))}case"Ack":return u.get(h.requestId)?i(n,{_tag:"Ack",requestId:String(h.requestId)}):jt;case"Interrupt":return u.get(h.requestId)?(u.delete(h.requestId),i(n,{_tag:"Interrupt",requestId:String(h.requestId)})):jt;case"Eof":return jt}}});return yield*r(n,h=>{switch(h._tag){case"Chunk":{const d=Pp(h.requestId),g=u.get(d);return!g||Ds(g.schemas.decodeChunk)?jt:g.schemas.decodeChunk.value(h.values).pipe(gs(g.context),zp,Gr(m=>f({_tag:"Chunk",clientId:0,requestId:Pp(h.requestId),values:m})),bme(m=>f({_tag:"Exit",clientId:0,requestId:Pp(h.requestId),exit:cf(m)})))}case"Exit":{const d=Pp(h.requestId),g=u.get(d);return g?(u.delete(d),g.schemas.decodeExit(h.exit).pipe(gs(g.context),zp,pme({onSuccess:m=>f({_tag:"Exit",clientId:0,requestId:d,exit:m}),onFailure:m=>f({_tag:"Exit",clientId:0,requestId:d,exit:cf(m)})}))):jt}case"Defect":return f({_tag:"Defect",clientId:0,defect:Txe(h.defect)});case"ClientProtocolError":{const d=Ld(h.error);return Q4(u.keys(),g=>f({_tag:"Exit",clientId:0,requestId:g,exit:d}))}default:return jt}}).pipe(pd(Rme),SE,_E),c}),rF=new WeakMap,Exe=e=>{let t=rF.get(e);if(t!==void 0)return t;const n=u6(e.successSchema);return t={decodeChunk:HC(n,r=>TD(x1(Uve(r.success)))),encodePayload:Fve(x1(e.payloadSchema)),decodeExit:TD(x1(A0e(e)))},rF.set(e,t),t},iF=Pt("effect/rpc/RpcClient/CurrentHeaders",{defaultValue:()=>HE});class Hy extends Xr()("effect/rpc/RpcClient/Protocol"){}Q(Hy,"make",Sxe);const kxe=e=>Hy.make(ms(function*(t,n){const r=yield*KE,i=yield*JE,o=yield*mme(iO),a=new Map,u=yield*r.writer;let c=i.makeUnsafe();const f=yield*jxe(u(c.encode(nxe)));let h;const d=vo(()=>(h=void 0,ga(o)?o.value.onConnect:jt)),g=m=>Q4(n,v=>t(v,m));return yield*vo(()=>(c=i.makeUnsafe(),f.reset(),r.runRaw(m=>{try{const v=c.decode(m);if(v.length===0)return;let x=0;return J4({while:()=>x<v.length,body:()=>{const b=v[x++];if(b._tag==="Pong")return f.onPong(),jt;if("requestId"in b){const O=a.get(b.requestId);if(O!==void 0)return b._tag==="Exit"&&a.delete(b.requestId),t(O,b)}return g(b)},step:kd})}catch(v){return g({_tag:"ClientProtocolError",error:new UD({reason:new JP({message:"Error decoding message",cause:v})})})}},{onOpen:d}).pipe(Z4(Gr(f.timeout,()=>vt(new Fu({reason:new bm({kind:"Timeout",cause:new Error("ping timeout")})}))))))).pipe(Gr(()=>vt(new Fu({reason:new wm({code:1e3})}))),ga(o)?n5(o.value.onDisconnect):Fe,ume(m=>{const v=Nd(m),x=Gfe(v);return x&&v.success.reason._tag==="SocketOpenError"?jt:(h=new UD({reason:x?v.success.reason:new JP({message:"Unknown socket error",cause:D4(m)})}),g({_tag:"ClientProtocolError",error:h}))}),lme((e==null?void 0:e.retryPolicy)??Axe),Ime({module:"RpcClient",method:"makeProtocolSocket"}),_E),{send(m,v){if(h)return vt(h);v._tag==="Request"&&a.set(v.id,m);const x=c.encode(v);return x===void 0?jt:zp(u(x))},supportsAck:!0,supportsTransferables:!1}})),Axe=K4(500,1.5).pipe(G4(bE(5e3))),jxe=ms(function*(e){let t=!0;const n=z5(),r=()=>{t=!0,n.closeUnsafe()},i=()=>{t=!0};return yield*vo(()=>t?(t=!1,e):n.open).pipe(hme("5 seconds"),cme,i5,SE,_E),{timeout:n.await,reset:r,onPong:i}});class iO extends Xr()("effect/rpc/RpcClient/ConnectionHooks"){}const Txe=Lve(wi),Rxe={add(...e){const t=new Map(this.requests);for(const n of e)t.set(n._tag,n);return Zi({requests:t,annotations:this.annotations})},merge(...e){const t=new Map(this.requests),n=new Map(this.annotations.mapUnsafe);for(const r of e){for(const[i,o]of r.requests)t.set(i,o);for(const[i,o]of r.annotations.mapUnsafe)n.set(i,o)}return Zi({requests:t,annotations:ca(n)})},omit(...e){const t=new Map(this.requests);for(const n of e)t.delete(n);return Zi({requests:t,annotations:this.annotations})},middleware(e){const t=new Map;for(const[n,r]of this.requests)t.set(n,r.middleware(e));return Zi({requests:t,annotations:this.annotations})},toHandlers(e){const t=this;return NP(function*(){const n=yield*cm(),r=Du(e)?yield*e:e,i=new Map;for(const[o,a]of Object.entries(r)){const u=t.requests.get(o);i.set(u.key,{tag:u._tag,handler:a,context:n})}return ca(i)})},prefix(e){const t=new Map;for(const n of this.requests.values()){const r=n.prefix(e);t.set(r._tag,r)}return Zi({requests:t,annotations:this.annotations})},toLayer(e){return MP(this.toHandlers(e))},of:Fe,toLayerHandler(e,t){const n=this;return MP(NP(function*(){const r=yield*cm(),i=Du(t)?yield*t:t,o=new Map,a=n.requests.get(e);return o.set(a.key,{handler:i,context:r}),ca(o)}))},accessHandler(e){return e5(t=>{const n=this.requests.get(e),{handler:r,context:i}=t.mapUnsafe.get(n.key);return Mt((o,a)=>{a.rpc=n;const u=r(o,a),c=T0e(u)?u.value:u;return Du(c)?gme(c,i):p0e(c,i)})})},annotate(e,t){return Zi({requests:this.requests,annotations:Aa(this.annotations,e,t)})},annotateRpcs(e,t){return this.annotateRpcsMerge(vl(e,t))},annotateMerge(e){return Zi({requests:this.requests,annotations:xl(this.annotations,e)})},annotateRpcsMerge(e){const t=new Map;for(const[n,r]of this.requests)t.set(n,r.annotateMerge(xl(e,r.annotations)));return Zi({requests:t,annotations:this.annotations})}},Zi=e=>Object.assign(function(){},Rxe,{requests:e.requests,annotations:e.annotations}),Ixe=(...e)=>Zi({requests:new Map(e.map(t=>[t._tag,t])),annotations:gi()}),Mxe="/ws",Fr={getConfig:"tokmon.getConfig",setConfig:"tokmon.setConfig",refresh:"tokmon.refresh",browseFs:"tokmon.browseFs",snapshot:"tokmon.snapshot",config:"tokmon.config"},$xe=Vy(["all","summary","table","billing","peak"]),ZE=()=>G5,Nxe=ZE(),ek=ZE(),Lxe=Nn({name:ar,path:ar,dir:qve}),Dxe=Nn({path:ar,parent:Vve(ar),entries:XP(Lxe)}),Fxe=ZE(),tk=Nn({}),Bxe=Bl(Fr.getConfig,{payload:tk,success:ek}),zxe=Bl(Fr.setConfig,{payload:Nxe,success:ek}),qxe=Bl(Fr.refresh,{payload:Nn({scope:$xe}),success:vm}),Uxe=Bl(Fr.browseFs,{payload:Nn({path:ar}),success:Dxe}),Vxe=Bl(Fr.snapshot,{payload:tk,success:Fxe,stream:!0}),Wxe=Bl(Fr.config,{payload:tk,success:ek,stream:!0}),Hxe=Ixe(Bxe,zxe,qxe,Uxe,Vxe,Wxe);class Ep extends Xr()("tokmon/client/DaemonRpcClient/TokmonRpcClient"){}const Gxe=new Function("specifier","return import(specifier)");function Kxe(e,t){const n=typeof window>"u"?void 0:window.location.origin,r=new URL(e,n);if(r.protocol==="http:"?r.protocol="ws:":r.protocol==="https:"&&(r.protocol="wss:"),r.protocol!=="ws:"&&r.protocol!=="wss:")throw new Error(`unsupported daemon RPC protocol: ${r.protocol}`);return r.pathname=Mxe,t&&r.searchParams.set("wsToken",t),r.toString()}function Xxe(e){return e==="node"?!0:e==="browser"?!1:typeof window>"u"}async function Yxe(e,t){return Xxe(t)?(await Gxe("@effect/platform-node/NodeSocket")).layerWebSocket(e):X0e(e).pipe($P(H0e))}function Qxe(e){const t=e.reconnectBaseDelayMs??250,n=K4(cd(t),1.5).pipe(G4(bE(cd(2500))));return typeof e.reconnectAttempts=="number"?n.pipe(Uge(Hge(e.reconnectAttempts))):n}function Jxe(e,t={}){const n=Kxe(e,t.wsToken),r=new Set;let i=null,o=null,a=!1;const u=(m,v)=>{var x;(x=t.onConn)==null||x.call(t,m,v)},c=m=>{const v=m??i;(m===void 0||m===i)&&(i=null),o=null,v&&v.runtime.dispose().catch(()=>{})},f=async()=>{const m=await Yxe(n,t.transport),v=yE(iO,iO.of({onConnect:zr(()=>{u("live")}),onDisconnect:zr(()=>{a||(u("reconnecting"),c())})}));return IP(Hy,kxe({retryPolicy:Qxe(t)})).pipe($P(V4(m,wxe,v)))},h=async()=>{if(a)throw new Error("daemon RPC client is closed");return i||o||(u("connecting"),o=(async()=>{let m;try{const v=await f(),x=IP(Ep,Cxe(Hxe)).pipe($P(v));if(m=O0e(x),await m.runPromise(Ep.asEffect()),a)throw await m.dispose(),new Error("daemon RPC client is closed");return i={runtime:m},i}catch(v){throw o=null,await(m==null?void 0:m.dispose().catch(()=>{})),a||u("error",v),v}})(),o)},d=async m=>{const v=await h();try{return await v.runtime.runPromise(Ep.use(x=>m(x)))}catch(x){throw a||(c(v),u("error",x)),x}},g=(m,v)=>{if(a)return()=>{};let x=null,b=!1,O=null;const _=()=>{if(!x)return;const P=x;x=null,r.delete(P),((i==null?void 0:i.runtime.runPromise(Qc(P)))??df(Qc(P))).catch(()=>{})},C=()=>{var P;a||b||O||(O=setTimeout(()=>{O=null,E()},t.reconnectBaseDelayMs??250),(P=O.unref)==null||P.call(O))},E=()=>{(async()=>{try{const P=await h();if(a||b)return;x=P.runtime.runFork(Ep.use(A=>m(A).pipe(g0e(j=>zr(()=>{try{v(j)}catch{}})))).pipe(pd(A=>zr(()=>{!a&&!b&&(c(P),u("error",D4(A)),C())})))),r.add(x),x.addObserver(()=>{x&&r.delete(x)})}catch(P){!a&&!b&&(c(),u("error",P),C())}})()};return E(),()=>{b=!0,O&&(clearTimeout(O),O=null),_()}};return{getConfig:()=>d(m=>m[Fr.getConfig]({})),setConfig:m=>d(v=>v[Fr.setConfig](m)),refresh:(m="all")=>d(v=>v[Fr.refresh]({scope:m})),browseFs:m=>d(v=>v[Fr.browseFs]({path:m})),subscribeSnapshot:m=>g(v=>v[Fr.snapshot]({}),m),subscribeConfig:m=>g(v=>v[Fr.config]({}),m),async close(){if(a)return;a=!0,u("closed");const m=[...r];r.clear();const v=i??await(o==null?void 0:o.catch(()=>null))??null;await Promise.all(m.map(x=>((v==null?void 0:v.runtime.runPromise(Qc(x)))??df(Qc(x))).catch(()=>{}))),i=null,o=null,v&&await v.runtime.dispose().catch(()=>{})}}}let C1=null;const oO=new Set;function Zxe(e){if(e!=="closed")for(const t of oO)t(e)}function Ud(){return C1||(C1=Jxe(window.location.origin,{transport:"browser",onConn:Zxe})),C1}function ebe(e){return oO.add(e),()=>{oO.delete(e)}}async function tbe(){return SO(await Ud().getConfig()).config}async function nbe(e){return SO(await Ud().setConfig(e)).config}async function rbe(e){return Ud().browseFs(e)}function _6(e){return Ud().subscribeConfig(t=>{e(SO(t).config)})}const Tt="focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",oF='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])';function P6(e,{active:t,onEscape:n,initialFocusRef:r}){D.useEffect(()=>{var c,f;if(!t)return;const i=document.activeElement,o=e.current,a=o==null?void 0:o.querySelector(oF);(f=(c=(r==null?void 0:r.current)??a??o)==null?void 0:c.focus)==null||f.call(c);const u=h=>{if(h.key==="Escape"){h.stopPropagation(),n();return}if(h.key!=="Tab"||!e.current)return;const d=e.current.querySelectorAll(oF),g=Array.from(d).filter(x=>x.offsetParent!==null||x===document.activeElement);if(g.length===0)return;const m=g[0],v=g[g.length-1];h.shiftKey&&document.activeElement===m?(h.preventDefault(),v.focus()):!h.shiftKey&&document.activeElement===v&&(h.preventDefault(),m.focus())};return document.addEventListener("keydown",u),()=>{var h;document.removeEventListener("keydown",u),(h=i==null?void 0:i.focus)==null||h.call(i)}},[t])}function aF(e,t={}){return{mode:"add",editingId:null,providerId:t.providerId??wf[0],name:t.name??"",homeDir:t.homeDir??"~",color:t.color??yG(e.accounts)}}function ibe(e){return{mode:"edit",editingId:e.id,providerId:e.providerId,name:e.name,homeDir:e.homeDir,color:e.color||us[e.providerId].color}}function obe(e,t){const n=e.mode==="edit"?t.filter(r=>r.id!==e.editingId):t;return e.mode==="edit"?e.editingId??"":w3(e.name.trim()||"account",n)}function abe(e,t){const n=e.name.trim(),r=e.homeDir.trim()||"~";return n?e.mode==="add"?{ok:!0,account:{id:w3(n,t),providerId:e.providerId,name:n,homeDir:r,color:e.color},mode:"add",editingId:null}:{ok:!0,account:{id:e.editingId,providerId:e.providerId,name:n,homeDir:r,color:e.color},mode:"edit",editingId:e.editingId}:{ok:!1,error:"Name required"}}function nk({title:e,right:t,children:n}){return w.jsxs("section",{className:"mb-6 last:mb-0",children:[w.jsxs("div",{className:"mb-2.5 flex items-center gap-2 border-b border-line pb-1.5",children:[w.jsx("h3",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:e}),t&&w.jsx("div",{className:"ml-auto",children:t})]}),n]})}function Vo({label:e,hint:t,children:n}){return w.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsx("div",{className:"text-sm text-fg",children:e}),t&&w.jsx("div",{className:"text-[11px] text-fg-faint",children:t})]}),w.jsx("div",{className:"shrink-0",children:n})]})}function kp({label:e,hint:t,children:n}){return w.jsxs("div",{children:[w.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:e}),n,t&&w.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:t})]})}function sF({value:e,min:t,unit:n,onChange:r}){const i=c=>r(Math.max(t,Math.round(c))),[o,a]=D.useState(null),u=()=>{if(o===null)return;const c=Number(o);i(Number.isFinite(c)&&o.trim()!==""?c:t),a(null)};return w.jsxs("div",{className:"flex items-center overflow-hidden rounded border border-line",children:[w.jsx("button",{type:"button","aria-label":"decrease",onClick:()=>i(e-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${Tt}`,children:"−"}),w.jsx("input",{type:"number",inputMode:"numeric",min:t,value:o??e,onChange:c=>{const f=c.target.value;a(f);const h=Number(f);f.trim()!==""&&Number.isFinite(h)&&h>=t&&i(h)},onBlur:u,"aria-label":`value (${n})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${Tt} [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),w.jsx("span",{className:"px-1.5 text-[10px] text-fg-faint",children:n}),w.jsx("button",{type:"button","aria-label":"increase",onClick:()=>i(e+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${Tt}`,children:"+"})]})}function qc({label:e,onClick:t,disabled:n,danger:r,children:i}){return w.jsx("button",{type:"button","aria-label":e,title:e,disabled:n,onClick:t,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${Tt} ${r?"hover:bg-warning/15 hover:text-warning":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:i})}function sbe({draft:e,patch:t}){return w.jsxs(nk,{title:"General",children:[w.jsx(Vo,{label:"Refresh interval",hint:"dashboard poll, seconds",children:w.jsx(sF,{value:e.interval,min:1,unit:"s",onChange:n=>t(r=>({...r,interval:n}))})}),w.jsx(Vo,{label:"Billing poll",hint:"billing refresh, minutes",children:w.jsx(sF,{value:e.billingInterval,min:1,unit:"m",onChange:n=>t(r=>({...r,billingInterval:n}))})}),w.jsx(Vo,{label:"Clear screen",hint:"redraw on each refresh",children:w.jsx(er,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:e.clearScreen?"on":"off",onChange:n=>t(r=>({...r,clearScreen:n==="on"}))})}),w.jsx(Vo,{label:"Privacy mode",hint:"hide email addresses by default",children:w.jsx(er,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:e.privacyMode?"on":"off",onChange:n=>t(r=>({...r,privacyMode:n==="on"}))})}),w.jsx(Vo,{label:"Timezone",hint:"IANA name · empty = System",children:w.jsx(ube,{value:e.timezone,onChange:n=>t(r=>({...r,timezone:n}))})}),w.jsx(Vo,{label:"Dashboard",hint:"grid shows all · single cycles",children:w.jsx(er,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:e.dashboardLayout,onChange:n=>t(r=>({...r,dashboardLayout:n}))})}),w.jsx(Vo,{label:"Default focus",hint:"on open",children:w.jsx(er,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:e.defaultFocus,onChange:n=>t(r=>({...r,defaultFocus:n}))})}),w.jsx(Vo,{label:"ASCII mode",hint:"glyph fallback",children:w.jsx(er,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:e.ascii,onChange:n=>t(r=>({...r,ascii:n}))})})]})}function ube({value:e,onChange:t}){const[n,r]=D.useState(e??""),[i,o]=D.useState(!1);D.useEffect(()=>{r(e??""),o(!1)},[e]);const a=u=>{const c=_O(u);r(c);const f=c.trim();if(!f){o(!1),t(null);return}b3(f)?(o(!1),t(f)):o(!0)};return w.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[w.jsx("input",{type:"text",value:n,placeholder:"System",spellCheck:!1,"aria-invalid":i,onChange:u=>a(u.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${Tt} ${i?"border-warning":"border-line"}`}),i&&w.jsx("span",{className:"text-[10px] text-warning",children:"invalid timezone"})]})}function lbe({draft:e,patch:t}){const n=(r,i)=>t(o=>({...o,knownProviders:o.knownProviders.includes(r)?o.knownProviders:[...o.knownProviders,r],disabledProviders:i?o.disabledProviders.filter(a=>a!==r):Array.from(new Set([...o.disabledProviders,r]))}));return w.jsx(nk,{title:"Providers",children:w.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:wf.map(r=>{const i=!e.disabledProviders.includes(r),o=us[r];return w.jsxs("button",{type:"button",role:"switch","aria-checked":i,onClick:()=>n(r,!i),className:`flex items-center gap-2.5 rounded border px-3 py-2 text-left text-xs transition ${Tt} ${i?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:border-line-2"}`,children:[w.jsx("span",{className:"inline-flex size-4 shrink-0 items-center justify-center rounded-sm border",style:{borderColor:i?ls(o.color):"var(--color-line-2)",background:i?ls(o.color):"transparent"},children:i&&w.jsx(zu,{className:"size-3 text-bg-0"})}),w.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:ls(o.color)},"aria-hidden":!0}),w.jsx("span",{className:`font-medium ${i?"text-fg":"text-fg-faint"}`,children:o.name}),w.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-wide text-fg-faint",children:i?"tracking":"off"})]},r)})})})}function cbe(e,t){return t?t.accounts.find(n=>n.id===e.id)??null:null}function fbe({draft:e,patch:t,snapshot:n,onEdit:r,onConfigure:i,onAdd:o}){const a=pG(e,void 0,(n==null?void 0:n.accounts)??void 0),u=h=>t(d=>({...d,activeAccountId:h})),c=h=>t(d=>({...d,accounts:d.accounts.filter(g=>g.id!==h),activeAccountId:d.activeAccountId===h?null:d.activeAccountId})),f=(h,d)=>t(g=>{const m=[...g.accounts],v=h+d;return v<0||v>=m.length?g:([m[h],m[v]]=[m[v],m[h]],{...g,accounts:m})});return w.jsx(nk,{title:"Accounts",right:w.jsxs("button",{type:"button",onClick:o,className:`flex items-center gap-1 rounded border border-accent/60 bg-bg-1 px-2 py-1 text-[11px] text-accent transition hover:bg-bg-2 ${Tt}`,children:[w.jsx(HG,{className:"size-3"})," Add account"]}),children:a.length===0?w.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"None configured — enabled providers track automatically."}):w.jsx("ul",{className:"flex flex-col gap-1.5",role:"radiogroup","aria-label":"Active account",children:a.map(h=>{var _;const d=us[h.providerId],g=cbe(h,n),m=(g==null?void 0:g.email)||(g==null?void 0:g.displayName)||h.name||d.name,v=(g==null?void 0:g.plan)??((_=g==null?void 0:g.billing)==null?void 0:_.plan)??null,x=ls(h.color||d.color),b=h.id===e.activeAccountId,O=h.source==="configured";return w.jsxs("li",{className:"flex items-center gap-2.5 rounded border border-line bg-bg-2/60 px-2.5 py-2",children:[w.jsx("button",{type:"button",role:"radio","aria-checked":b,"aria-label":`Set ${h.name} active`,title:b?"Active account (click to clear)":"Set active",onClick:()=>u(b?null:h.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${Tt}`,style:{borderColor:x},children:b&&w.jsx("span",{className:"size-2 rounded-full",style:{background:x}})}),w.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:x},"aria-hidden":!0}),w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx(Zp,{value:m,privacyMode:e.privacyMode,className:"truncate text-sm text-fg-bright"}),w.jsx("span",{className:"shrink-0 rounded bg-bg-3 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-dim",children:d.name}),v&&w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:v}),w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-faint",children:h.source==="auto"?"auto":"configured"})]}),w.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:h.homeDir})]}),w.jsx("div",{className:"flex shrink-0 items-center gap-0.5",children:O&&h.explicitIndex!==void 0?w.jsxs(w.Fragment,{children:[w.jsx(qc,{label:"Move up",disabled:h.explicitIndex===0,onClick:()=>f(h.explicitIndex,-1),children:w.jsx(C3,{className:"size-3.5"})}),w.jsx(qc,{label:"Move down",disabled:h.explicitIndex===e.accounts.length-1,onClick:()=>f(h.explicitIndex,1),children:w.jsx(CO,{className:"size-3.5"})}),w.jsx(qc,{label:"Edit account",onClick:()=>r(h),children:w.jsx(FT,{className:"size-3.5"})}),w.jsx(qc,{label:"Delete account",danger:!0,onClick:()=>c(h.id),children:w.jsx(GG,{className:"size-3.5"})})]}):w.jsx(qc,{label:"Configure account",onClick:()=>i(h),children:w.jsx(FT,{className:"size-3.5"})})})]},`${h.source}:${h.id}`)})})})}function dbe(e){const t=(e??"").trim();return t.length>0?t:"~"}function E1(e){const t=(e??"").trim();return t.length>0?t:"~"}function hbe(e){const t=[];e.parent!==null&&t.push({kind:"parent",key:"..",label:"..",path:e.parent});for(const n of[...e.entries].filter(r=>r.dir).sort((r,i)=>r.name.localeCompare(i.name)))t.push({kind:"entry",key:n.path,label:n.name,path:n.path});return t}function pbe({editor:e,accounts:t,onChange:n,onCancel:r,onSubmit:i}){const o=D.useRef(null),a=D.useRef(null),[u,c]=D.useState(null),f=ls(e.color);P6(o,{active:!0,onEscape:r,initialFocusRef:a});const h=obe(e,t),d=()=>{const g=abe(e,t);if(!g.ok){c(g.error);return}i(g.account,g.mode,g.editingId)};return w.jsx("div",{className:"dialog-fade fixed inset-0 z-[70] flex items-start justify-center overflow-y-auto bg-bg-0/60 p-4 backdrop-blur-sm",onMouseDown:g=>{g.target===g.currentTarget&&r()},role:"dialog","aria-modal":"true","aria-label":e.mode==="add"?"New account":"Edit account",children:w.jsxs("div",{ref:o,tabIndex:-1,className:"dialog-pop my-8 w-full max-w-[460px] overflow-hidden rounded-md border-l-2 border border-line-2 bg-bg-1 focus:outline-none",style:{borderLeftColor:f},children:[w.jsxs("div",{className:"flex items-center gap-2 border-b border-line px-4 py-3",children:[w.jsx("span",{className:"size-2.5 rounded-full",style:{background:f},"aria-hidden":!0}),w.jsx("span",{className:"font-display text-xs uppercase tracking-wider text-fg-bright",children:e.mode==="add"?"New account":"Edit account"})]}),w.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[w.jsx(kp,{label:"Provider",hint:"which tool this account tracks",children:w.jsx("div",{className:"flex flex-wrap gap-1.5",children:wf.map(g=>{const m=g===e.providerId,v=us[g];return w.jsxs("button",{type:"button",onClick:()=>n({...e,providerId:g}),"aria-pressed":m,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${Tt} ${m?"border-line-2 bg-bg-3 text-fg-bright":"border-line text-fg-dim hover:text-fg"}`,children:[w.jsx("span",{className:"size-2 rounded-full",style:{background:ls(v.color)},"aria-hidden":!0}),v.name]},g)})})}),w.jsx(kp,{label:"Name",hint:"display name for this account",children:w.jsx("input",{ref:a,type:"text",value:e.name,placeholder:"e.g. Work, Personal",spellCheck:!1,onChange:g=>{c(null),n({...e,name:_O(g.target.value)})},onKeyDown:g=>{g.key==="Enter"&&d()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${Tt}`})}),w.jsx(kp,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:w.jsx(gbe,{value:e.homeDir,onChange:g=>n({...e,homeDir:g}),onEnter:d})}),w.jsx(kp,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:w.jsx("div",{className:"flex flex-wrap gap-1.5",children:cG.map(g=>{const m=g===e.color;return w.jsx("button",{type:"button","aria-label":g,"aria-pressed":m,title:g,onClick:()=>n({...e,color:g}),className:`size-6 rounded-full border-2 transition ${Tt} ${m?"scale-110":"border-transparent hover:scale-105"}`,style:{background:ls(g),borderColor:m?"var(--color-fg-bright)":"transparent"}},g)})})}),w.jsxs("div",{className:"flex items-center gap-2 rounded border border-line bg-bg-2/50 px-2.5 py-1.5 text-xs",children:[w.jsx("span",{className:"text-fg-faint",children:"id"}),w.jsx("span",{className:"font-mono text-fg",style:{color:f},children:h||"account"}),w.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:e.mode==="add"?"auto-generated from name":"fixed"})]}),u&&w.jsx("p",{className:"text-xs text-warning",children:u})]}),w.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[w.jsx("button",{type:"button",onClick:r,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${Tt}`,children:"cancel"}),w.jsxs("button",{type:"button",onClick:d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," ",e.mode==="add"?"Add account":"Save account"]})]})]})})}function gbe({value:e,onChange:t,onEnter:n}){const[r,i]=D.useState(!1),[o,a]=D.useState(null),[u,c]=D.useState("~"),[f,h]=D.useState(!1),[d,g]=D.useState(null),m=D.useRef(0),v=D.useCallback(async A=>{const j=++m.current,R=dbe(A);c(R),h(!0),g(null);try{const M=await rbe(R);if(j!==m.current)return;a(M)}catch(M){if(j!==m.current)return;a(null),g(M instanceof Error?M.message:"cannot read folder")}finally{j===m.current&&h(!1)}},[]);D.useEffect(()=>()=>{m.current++},[]);const x=()=>{i(!0),v(e)},b=()=>{m.current++,i(!1),h(!1),g(null)},O=A=>{f||v(A)},_=()=>{!o||f||(t(E1(o.path)),b())},C=o?hbe(o):[],E=C.filter(A=>A.kind==="entry"),P=E1((o==null?void 0:o.path)??u);return w.jsxs("div",{className:"relative",children:[w.jsxs("div",{className:"flex overflow-hidden rounded border border-line bg-bg-2",children:[w.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2.5",children:[w.jsx(ax,{className:"size-4 shrink-0 text-fg-faint"}),w.jsx("input",{type:"text",value:e,placeholder:"~",spellCheck:!1,onChange:A=>{b(),t(_O(A.target.value))},onKeyDown:A=>{A.key==="Enter"&&n()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${Tt}`})]}),w.jsxs("button",{type:"button",onClick:x,disabled:f,className:`flex shrink-0 items-center gap-1 border-l border-line bg-bg-1 px-2.5 py-1.5 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${Tt}`,children:[w.jsx(CO,{className:"size-3.5"})," Browse"]})]}),r&&w.jsxs("div",{className:"mt-2 overflow-hidden rounded border border-line-2 bg-bg-1 shadow-[0_18px_60px_rgba(0,0,0,0.35)]",children:[w.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-2 px-2.5 py-2",children:[w.jsx(ax,{className:"size-4 shrink-0 text-accent"}),w.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg-bright",title:P,children:P}),f&&w.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),w.jsx("button",{type:"button",onClick:b,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${Tt}`,children:w.jsx(qu,{className:"size-3.5"})})]}),d?w.jsxs("div",{className:"px-2.5 py-3",children:[w.jsxs("div",{className:"text-xs text-warning",children:["can't read ",E1(u)]}),w.jsx("button",{type:"button",onClick:()=>{f||v(u)},disabled:f,className:`mt-2 rounded border border-line bg-bg-2 px-2 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg disabled:opacity-50 ${Tt}`,children:"retry"})]}):w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[C.map(A=>w.jsxs("button",{type:"button",onClick:()=>O(A.path),disabled:f,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${Tt} ${A.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[A.kind==="parent"?w.jsx(C3,{className:"size-3.5 shrink-0"}):w.jsx(ax,{className:"size-3.5 shrink-0 text-fg-faint"}),w.jsx("span",{className:"min-w-0 truncate font-mono",children:A.label})]},A.key)),!f&&E.length===0&&w.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),f&&!o&&w.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"loading folders..."})]}),w.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-line px-2.5 py-2",children:w.jsxs("button",{type:"button",onClick:_,disabled:!o||f,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-2.5 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," Select this folder"]})})]})]})]})}const mbe=[{value:"general",label:"General"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function ybe({onClose:e,snapshot:t}){const n=D.useRef(null),[r,i]=D.useState(null),[o,a]=D.useState(null),[u,c]=D.useState(!1),[f,h]=D.useState(null),[d,g]=D.useState(!1),[m,v]=D.useState(null),[x,b]=D.useState("general");D.useEffect(()=>{let C=!0;return tbe().then(E=>{C&&i(E)}).catch(E=>{C&&a(E instanceof Error?E.message:"load failed")}),()=>{C=!1}},[]),D.useEffect(()=>{if(!d)return _6(C=>{d||i(C)})},[d]),P6(n,{active:!m,onEscape:e}),D.useEffect(()=>{const C=n.current;C&&(m?C.setAttribute("inert",""):C.removeAttribute("inert"))},[m]);const O=C=>{g(!0),h(null),i(E=>E&&C(E))},_=async()=>{if(r){c(!0),h(null);try{const C=await nbe(r);i(C),g(!1),e()}catch(C){h(C instanceof Error?C.message:"save failed")}finally{c(!1)}}};return w.jsxs("div",{className:"dialog-fade fixed inset-0 z-[60] flex items-start justify-center overflow-y-auto bg-bg-0/70 p-4 backdrop-blur-sm",onMouseDown:C=>{C.target===C.currentTarget&&!m&&e()},role:"dialog","aria-modal":"true","aria-label":"Settings",children:[w.jsxs("div",{ref:n,tabIndex:-1,className:"dialog-pop relative my-6 flex w-full max-w-[720px] flex-col overflow-hidden rounded-md border border-line-2 bg-bg-1 focus:outline-none",children:[w.jsx("div",{className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim",children:"settings"}),w.jsx("button",{type:"button",onClick:e,"aria-label":"Close",className:`absolute right-2 top-2 z-10 rounded p-1 text-fg-faint transition hover:text-fg ${Tt}`,children:w.jsx(qu,{className:"size-4"})}),w.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-5 pb-4 pt-9",children:o?w.jsx("div",{className:"rounded border border-warning/50 bg-bg-2 p-4 text-sm text-warning",children:o}):r?w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-line pb-3",children:w.jsx(er,{size:"xs",ariaLabel:"settings section",options:mbe,value:x,onChange:b,containerClassName:"flex items-center overflow-hidden rounded border border-line bg-bg-1",btnClassName:"px-3 py-1.5 text-[11px] transition"})}),x==="general"&&w.jsx(sbe,{draft:r,patch:O}),x==="providers"&&w.jsx(lbe,{draft:r,patch:O}),x==="accounts"&&w.jsx(fbe,{draft:r,patch:O,snapshot:t,onEdit:C=>v(ibe(C)),onConfigure:C=>v(aF(r,{providerId:C.providerId,name:C.name,homeDir:C.homeDir,color:C.color})),onAdd:()=>v(aF(r))})]}):w.jsx("div",{className:"py-10 text-center text-sm text-fg-dim",children:"loading config…"})}),w.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-line px-5 py-3",children:[f&&w.jsx("span",{className:"mr-auto text-xs text-warning",children:f}),d&&!f&&w.jsx("span",{className:"mr-auto text-xs text-fg-faint",children:"unsaved changes"}),w.jsx("button",{type:"button",onClick:e,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${Tt}`,children:"cancel"}),w.jsxs("button",{type:"button",onClick:_,disabled:!r||u||!d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," ",u?"saving…":"save"]})]})]}),m&&r&&w.jsx(pbe,{editor:m,accounts:r.accounts,onChange:v,onCancel:()=>v(null),onSubmit:(C,E,P)=>{O(A=>E==="add"?{...A,accounts:[...A.accounts,C]}:{...A,accounts:A.accounts.map(j=>j.id===P?C:j)}),v(null)}})]})}const vbe="modulepreload",xbe=function(e,t){return new URL(e,t).href},uF={},O6=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let a=function(h){return Promise.all(h.map(d=>Promise.resolve(d).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};const u=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),f=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));i=a(n.map(h=>{if(h=xbe(h,r),h in uF)return;uF[h]=!0;const d=h.endsWith(".css"),g=d?'[rel="stylesheet"]':"";if(!!r)for(let x=u.length-1;x>=0;x--){const b=u[x];if(b.href===h&&(!d||b.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${g}`))return;const v=document.createElement("link");if(v.rel=d?"stylesheet":vbe,d||(v.as="script"),v.crossOrigin="",v.href=h,f&&v.setAttribute("nonce",f),document.head.appendChild(v),d)return new Promise((x,b)=>{v.addEventListener("load",x),v.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${h}`)))})}))}function o(a){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=a,window.dispatchEvent(u),!u.defaultPrevented)throw a}return i.then(a=>{for(const u of a||[])u.status==="rejected"&&o(u.reason);return t().catch(o)})};function Gy({title:e,titleTag:t,right:n,captureName:r,children:i,className:o="",bodyClassName:a=""}){const u=D.useRef(null);return w.jsxs("section",{ref:u,className:`group relative rounded-md border border-line bg-bg-1/80 transition-colors hover:border-line-2 ${o}`,children:[e&&w.jsxs("div",{className:"pointer-events-none absolute -top-[7px] left-3 flex items-center gap-2 bg-bg-1 px-1.5",children:[w.jsx("span",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:e}),t!=null&&w.jsx("span",{className:"text-[10px] normal-case tracking-normal text-fg-faint",children:t})]}),n&&w.jsx("div",{"data-chrome":!0,className:"absolute right-2 top-2 z-20 flex items-center gap-1.5 rounded bg-bg-1 px-0.5",children:n}),r&&w.jsx("div",{"data-chrome":!0,className:"absolute -top-[11px] right-3 z-20",children:w.jsx(bbe,{getNode:()=>u.current,name:r})}),w.jsx("div",{className:`p-4 ${a}`,children:i})]})}function bbe({getNode:e,name:t}){const n=MC();return w.jsx("button",{type:"button",title:"Share this panel","aria-label":"Share this panel as an image",onClick:()=>{const r=e();r&&n({kind:"panel",node:r,captureName:t})},className:"rounded border border-transparent bg-bg-1 p-1 text-fg-faint opacity-0 transition hover:border-line hover:text-accent group-hover:opacity-100 focus-visible:opacity-100",children:w.jsx(FG,{className:"size-3.5"})})}function wbe({derived:e,periodLabel:t}){const n=e.totals,r=e.timeline.map(a=>a.total).slice(-30),i=e.timeline.map(a=>a.tokens).slice(-30),o=e.cacheSavingsSeries.map(a=>a.value).slice(-30);return w.jsxs("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-3",children:[w.jsx(Uc,{label:`spend · ${t}`,value:Je(n.cost),accent:"text-cost",spark:r,sparkColor:"var(--color-cost)"}),w.jsx(Uc,{label:"tokens",value:Mn(n.tokens),spark:i,sparkColor:"var(--color-fg-dim)"}),w.jsx(Uc,{label:"cache saved",value:Je(n.cacheSavings),accent:"text-positive",spark:o,sparkColor:"var(--color-positive)"}),w.jsx(Uc,{label:"calls",value:ya(n.calls)}),w.jsx(Uc,{label:"burn · today",value:`${Je(e.burnRate)}/hr`,accent:"text-warning"})]})}function Uc({label:e,value:t,accent:n="text-fg-bright",spark:r,sparkColor:i}){return w.jsxs("div",{className:"rise flex min-w-0 flex-col rounded-md border border-line bg-bg-1/80 p-3.5 transition-colors hover:border-line-2",children:[w.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:e}),w.jsx("div",{className:`tnum mt-1.5 text-xl sm:text-2xl ${n}`,children:t}),r&&r.length>1&&w.jsx("div",{className:"mt-auto overflow-hidden pt-2 text-right",children:w.jsx(Pf,{data:r,color:i??"currentColor",className:"text-sm opacity-70"})})]})}function Sbe({accounts:e,nameOf:t,privacyMode:n}){return e.length===0?w.jsx(Gy,{title:"accounts",children:w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no accounts match the current filter"})}):w.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[repeat(auto-fit,minmax(min(340px,100%),1fr))]",children:e.map((r,i)=>w.jsx(_be,{account:r,index:i,providerName:t(r.providerId),privacyMode:n},r.id))})}function _be({account:e,index:t,providerName:n,privacyMode:r}){var h,d,g,m,v,x;const i=e.dashboard,o=((h=e.billing)==null?void 0:h.metrics)??[],a=((d=e.billing)==null?void 0:d.modelSpend)??[],u=(g=e.billing)==null?void 0:g.activity,c=bG(e.providerId),f=e.name&&e.name!==n;return w.jsxs("div",{className:"rise group relative overflow-hidden rounded-md border bg-bg-1/50 p-4 transition-colors",style:{animationDelay:`${t*40}ms`,borderColor:`color-mix(in oklab, ${c} 50%, var(--color-line))`},children:[w.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[w.jsx("span",{style:{color:c},children:"●"}),w.jsx("span",{className:"font-display text-sm tracking-wide text-fg-bright",children:n}),f&&w.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs text-fg-faint",children:[w.jsx("span",{"aria-hidden":!0,children:"·"}),w.jsx(Zp,{value:e.name,privacyMode:r,className:"truncate text-fg-faint"})]})]}),((m=e.billing)==null?void 0:m.plan)&&w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:e.billing.plan})]}),i&&w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[w.jsx(k1,{label:"today",cost:i.today.cost,tokens:i.today.tokens}),w.jsx(k1,{label:"week",cost:i.week.cost,tokens:i.week.tokens}),w.jsx(k1,{label:"month",cost:i.month.cost,tokens:i.month.tokens})]}),w.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-line-faint pt-3 text-xs",children:[w.jsxs("span",{className:"text-fg-dim",children:["burn ",w.jsxs("span",{className:"tnum text-warning",children:[Je(i.burnRate),"/hr"]})]}),w.jsxs("span",{className:"text-fg-dim",children:["saved ",w.jsx("span",{className:"tnum text-positive",children:Je(i.month.cacheSavings)})]})]})]}),o.length>0&&w.jsx("div",{className:`flex flex-col gap-2 ${i?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:o.slice(0,8).map((b,O)=>w.jsx(Obe,{metric:b},`${b.label}${O}`))}),a.length>0&&w.jsxs("div",{className:"mt-3 flex flex-col gap-1 border-t border-line-faint pt-3",children:[w.jsx("div",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"spend by model"}),a.slice(0,4).map(b=>w.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[w.jsx("span",{className:"min-w-0 truncate text-fg-dim",children:Li(b.name)}),w.jsxs("span",{className:"tnum shrink-0 text-cost",children:[Je(b.usd),w.jsxs("span",{className:"ml-1.5 text-fg-faint",children:[ya(b.requests)," req"]})]})]},b.name))]}),i&&i.series.length>0&&w.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[w.jsx(Pf,{data:i.series,color:c,className:"text-sm"}),w.jsxs("span",{className:"ml-auto text-[10px] text-fg-faint",children:[i.series.length,"d"]})]}),!i&&u&&u.series.length>0&&w.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[w.jsx(Pf,{data:u.series,color:c,className:"text-sm"}),w.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:u.summary})]}),o.length===0&&((v=e.billing)==null?void 0:v.error)&&w.jsxs("div",{className:`flex items-start gap-1.5 text-xs text-warning ${i?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:[w.jsx("span",{"aria-hidden":!0,children:"⚠"}),w.jsx("span",{children:EO(e.billing.error,r)})]}),!i&&o.length===0&&!((x=e.billing)!=null&&x.error)&&a.length===0&&!(u&&u.series.length)&&w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:e.hasUsage?"no usage data":"billing-only · no live metrics"})]})}function k1({label:e,cost:t,tokens:n}){const r=t>0||n===0;return w.jsxs("div",{children:[w.jsx("div",{className:"text-[10px] uppercase text-fg-faint",children:e}),w.jsx("div",{className:`tnum text-sm ${r?"text-cost":"text-fg-bright"}`,children:r?Je(t):Mn(n)}),w.jsx("div",{className:"tnum text-[10px] text-fg-faint",children:r?Mn(n):Je(t)})]})}function Pbe(e){return e.format.kind==="dollars"?Je(e.used):e.format.kind==="count"?`${ya(e.used)}${e.format.suffix?" "+e.format.suffix:""}`:`${Math.round(e.used)}%`}function Obe({metric:e}){const t=e.format.kind==="percent"?Math.min(1,Math.max(0,e.used/100)):e.limit!=null&&e.limit>0?Math.min(1,Math.max(0,e.used/e.limit)):null,n=t==null?"var(--color-accent)":t>=.9?"var(--color-warning)":t>=.7?"var(--color-cost)":"var(--color-positive)";return w.jsxs("div",{children:[w.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[w.jsx("span",{className:"truncate text-fg-dim",children:e.label}),w.jsxs("span",{className:"tnum text-fg",children:[Pbe(e),e.format.kind!=="percent"&&e.limit!=null&&w.jsxs("span",{className:"text-fg-faint",children:[" / ",e.format.kind==="dollars"?Je(e.limit):ya(e.limit)]}),e.resetsAt&&w.jsxs("span",{className:"ml-1.5 text-fg-faint",children:["· ",e.resetsAt]})]})]}),t!=null&&w.jsx("div",{className:"mt-1 h-1.5 w-full overflow-hidden rounded-full bg-bg-3",role:"progressbar","aria-label":e.label,"aria-valuenow":Math.round(t*100),"aria-valuemin":0,"aria-valuemax":100,children:w.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${t*100}%`,background:n}})})]})}const Cbe=[0,.32,.55,.78,1],lF=e=>e===0?"var(--color-bg-2)":`color-mix(in oklab, var(--color-cost) ${Cbe[e]*100}%, var(--color-bg-2))`,C6=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function Ebe(e,t){const n=e,r=n.filter(h=>t(h)>0);if(r.length===0)return null;const i=n.reduce((h,d)=>h+t(d),0),o=r.reduce((h,d)=>t(d)>t(h)?d:h),a=new Array(7).fill(0);for(const h of n)a[_f(uo(h.date))]+=t(h);const u=a.indexOf(Math.max(...a)),c=new Set(r.map(h=>h.date));let f=0;for(let h=uo(r[r.length-1].date);c.has(wd(h));h-=ta)f++;return{active:r.length,total:i,top:o,avg:i/r.length,busiest:u,streak:f,costed:e.some(h=>h.cost>0)}}function kbe(e,t,n){const r=new Map(e.map(x=>[x.date,n(x)]));if(e.length===0)return null;const i=e[e.length-1].date,o=e[0].date;let a=uo(i),u=uo(o);(a-u)/(ta*7)>t&&(u=a-t*7*ta),u-=_f(u)*ta;const c=Math.max(...e.map(n),0),f=x=>{if(x<=0||c<=0)return 0;const b=x/c;return b>.66?4:b>.4?3:b>.15?2:1},h=[];let d=new Array(7).fill(null);const g=[];let m=-1,v=0;for(let x=u;x<=a;x+=ta){const b=wd(x),O=_f(x);O===0&&d.some(Boolean)&&(h.push(d),d=new Array(7).fill(null),v++);const _=new Date(x).getUTCMonth();_!==m&&O===0&&(g.push({col:v,text:_G[_]}),m=_);const C=x>=uo(o);d[O]=C?{date:b,cost:r.get(b)??0,level:f(r.get(b)??0)}:null}return d.some(Boolean)&&h.push(d),{weeks:h,monthLabels:g}}function Abe({derived:e,maxWeeks:t=26,periodLabel:n}){const[r,i]=D.useState(null),[o,a]=D.useState(null),u=r??o,c=D.useMemo(()=>new Map(e.calendar.map(x=>[x.date,x])),[e.calendar]),f=D.useMemo(()=>e.calendar.some(x=>x.cost>0),[e.calendar]),h=x=>f?x.cost:x.tokens,d=D.useMemo(()=>Ebe(e.calendar,h),[e,f]),g=D.useMemo(()=>kbe(e.calendar,t,h),[e,t]),m=g?`repeat(${g.weeks.length}, minmax(0,1fr))`:void 0,v=g?g.weeks.length*25:void 0;return w.jsx(w.Fragment,{children:w.jsx(Gy,{title:"daily spend",titleTag:n,captureName:"calendar",children:!g||!d?w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no usage yet"}):w.jsxs("div",{className:"grid gap-x-8 gap-y-5 pt-1 md:grid-cols-[minmax(0,1fr)_210px] md:items-start",children:[w.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[w.jsx("div",{className:"pl-6",children:w.jsx("div",{className:"grid gap-[3px] text-[9px] text-fg-faint",style:{gridTemplateColumns:m,maxWidth:v},children:g.weeks.map((x,b)=>{const O=g.monthLabels.find(_=>_.col===b);return w.jsx("div",{className:"truncate",children:(O==null?void 0:O.text)??""},b)})})}),w.jsxs("div",{className:"flex gap-[3px]",children:[w.jsx("div",{className:"flex w-5 shrink-0 flex-col gap-[3px] text-[9px] text-fg-faint",children:["M","","W","","F","",""].map((x,b)=>w.jsx("div",{className:"flex flex-1 items-center",children:x},b))}),w.jsx("div",{className:"grid min-w-0 flex-1 gap-[3px]",style:{gridTemplateColumns:m,maxWidth:v},onMouseLeave:()=>i(null),children:g.weeks.map((x,b)=>w.jsx("div",{className:"flex flex-col gap-[3px]",children:x.map((O,_)=>O===null?w.jsx("div",{className:"aspect-square"},_):w.jsx("button",{type:"button","aria-label":`${xs(O.date)} — click to pin`,"aria-pressed":(o==null?void 0:o.date)===O.date,className:`aspect-square block rounded-[3px] p-0 transition duration-150 hover:scale-[1.18] hover:ring-1 hover:ring-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent ${(o==null?void 0:o.date)===O.date?"ring-1 ring-fg-bright":""}`,style:{background:lF(O.level)},onMouseEnter:()=>i(c.get(O.date)??null),onFocus:()=>i(c.get(O.date)??null),onClick:()=>a(C=>(C==null?void 0:C.date)===O.date?null:c.get(O.date)??null)},_))},b))})]}),w.jsxs("div",{className:"flex items-center gap-1.5 pl-6 pt-1 text-[9px] text-fg-faint",children:["less",[0,1,2,3,4].map(x=>w.jsx("span",{className:"size-[11px] rounded-[2px]",style:{background:lF(x)}},x)),"more"]})]}),w.jsxs("div",{className:"relative border-line-faint md:border-l md:pl-6",children:[w.jsxs("div",{className:`grid grid-cols-2 gap-x-6 gap-y-4 transition-opacity duration-200 md:grid-cols-1 ${u?"opacity-0":"opacity-100"}`,children:[w.jsx(ap,{label:"busiest day",value:d.costed?Je(d.top.cost):Mn(d.top.tokens),sub:xs(d.top.date),valueClass:"text-cost"}),w.jsx(ap,{label:"daily average",value:d.costed?Je(d.avg):Mn(d.avg),sub:`across ${d.active} active days`}),w.jsx(ap,{label:"top weekday",value:C6[d.busiest],valueClass:"text-fg-bright"}),w.jsx(ap,{label:"latest streak",value:`${d.streak}d`,sub:d.streak>0?"in a row":"idle today",valueClass:"text-positive"})]}),u&&w.jsx("div",{className:"dialog-fade absolute inset-0 md:pl-6",children:w.jsx(jbe,{day:u,pinned:!r&&u===o})})]})]})})})}function jbe({day:e,pinned:t=!1}){return w.jsxs("div",{className:"font-mono text-[11px]",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-3 border-b border-line-faint pb-2",children:[w.jsxs("span",{className:"text-fg-dim",children:[C6[_f(uo(e.date))]," · ",xs(e.date),t&&w.jsx("span",{className:"ml-1.5 text-[9px] uppercase tracking-wide text-accent",children:"pinned"})]}),w.jsx("span",{className:"tnum text-cost",children:e.cost>0?Je(e.cost):"—"})]}),e.cost>0?w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"grid grid-cols-3 gap-2 py-2 text-[10px]",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"calls"}),w.jsx("div",{className:"tnum text-fg",children:ya(e.calls)})]}),w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"tokens"}),w.jsx("div",{className:"tnum text-fg",children:Mn(e.tokens)})]}),w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"saved"}),w.jsx("div",{className:"tnum text-positive",children:Je(e.cacheSavings)})]})]}),w.jsxs("div",{className:"flex flex-col gap-1 border-t border-line-faint pt-2",children:[e.models.slice(0,5).map(n=>w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx("span",{className:"size-1.5 shrink-0 rounded-full",style:{background:Em(n.name)}}),w.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-dim",children:Li(n.name)}),w.jsx("span",{className:"tnum w-16 shrink-0 text-right text-fg",children:Je(n.cost)})]},n.name)),e.models.length>5&&w.jsxs("div",{className:"pt-0.5 text-fg-faint",children:["+",e.models.length-5," more"]})]})]}):w.jsx("div",{className:"pt-2 text-fg-faint",children:"no spend this day"})]})}const Tbe=[{value:"cost",label:"cost"},{value:"tokens",label:"tokens"},{value:"calls",label:"calls"}],cF="1.75rem minmax(6rem,12rem) minmax(3.5rem,1fr) 3rem 5.5rem 5rem auto auto auto";function Rbe({derived:e,limit:t,periodLabel:n}){const[r,i]=D.useState(e.totals.cost>0?"cost":"tokens"),o=[...e.byModel].sort((h,d)=>d[r]-h[r]),a=t?o.slice(0,t):o,u=r==="tokens"?"tokenShare":r==="calls"?"callShare":"share",c=r==="tokens"?"block":"hidden md:block",f=r==="calls"?"block":"hidden lg:block";return w.jsx(Gy,{title:"model leaderboard",titleTag:n,captureName:"models",right:w.jsx(er,{options:Tbe,value:r,onChange:i,size:"xs",ariaLabel:"sort models by",containerClassName:"flex items-center gap-0.5",btnClassName:"rounded px-1.5 py-0.5 text-[11px] transition"}),children:a.length===0?w.jsx(K9,{children:"no models in period"}):w.jsxs("div",{className:"mt-6 flex flex-col overflow-x-auto",children:[w.jsxs("div",{className:"grid items-center gap-x-3 border-b border-line px-2 pb-1.5 font-display text-[10px] uppercase tracking-wide text-fg-faint",style:{gridTemplateColumns:cF},children:[w.jsx("span",{}),w.jsx("span",{}),w.jsx("span",{children:"share"}),w.jsx("span",{className:"text-right",children:"%"}),w.jsx("span",{className:"text-right text-cost/70",children:"cost"}),w.jsx("span",{className:"text-right",children:"trend"}),w.jsx("span",{className:"hidden text-right lg:block",children:"$/call"}),w.jsx("span",{className:`text-right ${c}`,children:"tokens"}),w.jsx("span",{className:`text-right ${f}`,children:"calls"})]}),a.map((h,d)=>w.jsxs("div",{className:"grid items-center gap-x-3 rounded border-b border-line-faint px-2 py-2 transition-colors last:border-0 hover:bg-bg-2/40",style:{gridTemplateColumns:cF},children:[w.jsxs("span",{className:`tnum text-xs ${d===0?"font-medium text-accent":d<3?"text-fg-dim":"text-fg-faint"}`,children:["#",d+1]}),w.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[w.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:h.color}}),w.jsx("span",{className:"truncate text-fg",title:h.model,children:Li(h.model)})]}),w.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-bg-3",children:w.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,h[u]*100)}%`,minWidth:h[u]>0?"2px":0,background:h.color}})}),w.jsx("span",{className:"tnum text-right text-[11px] text-fg-dim",children:S3(h[u],h[u]>0&&h[u]<.01?1:0)}),w.jsx("span",{className:"tnum text-right text-xs text-cost",children:Je(h.cost)}),w.jsx("span",{className:"overflow-hidden text-right",children:w.jsx(Pf,{data:h.trend.slice(-30),color:h.color,className:"text-sm"})}),w.jsx("span",{className:"tnum hidden text-right text-xs text-fg-dim lg:block",children:Je(h.calls?h.cost/h.calls:0)}),w.jsx("span",{className:`tnum text-right text-xs text-fg-dim ${c}`,children:h.tokens>0?Mn(h.tokens):w.jsx("span",{className:"text-fg-faint",children:"—"})}),w.jsx("span",{className:`tnum text-right text-xs text-fg-faint ${f}`,children:ya(h.calls)})]},h.model))]})})}/**
152
+ at ${n}`}return t}function md(e){switch(e._tag){case"InvalidType":case"OneOf":case"Composite":case"AnyOf":return Bc(e.ast.annotations);case"InvalidValue":case"Forbidden":return Bc(e.annotations);case"MissingKey":return Bc(e.annotations,"messageMissingKey");case"UnexpectedKey":return Bc(e.ast.annotations,"messageUnexpectedKey");case"Filter":return Bc(e.filter.annotations);case"Encoding":return md(e.issue)}}function Bc(e,t="message"){const n=e==null?void 0:e[t];if(typeof n=="string")return n}function vD(e){return Ds(e)?"no value provided":Jt(e.value)}class Sl extends dy{constructor(n){super();Q(this,"run");this.run=n}map(n){return new Sl((r,i)=>this.run(r,i).pipe(a5(HC(n))))}compose(n){return xD(this)?n:xD(n)?this:new Sl((r,i)=>this.run(r,i).pipe(Tu(o=>n.run(o,i))))}}const d5=new Sl(Mt);function xD(e){return e.run===d5.run}function _l(){return d5}function sr(e){return Qme(HC(e))}function Qme(e){return new Sl(t=>Mt(e(t)))}function Jme(e){return new Sl(t=>{const n=Hfe(t,Dce);return ga(n)?Mt(n):Bs(e,He)})}function Zme(){return sr(globalThis.String)}function h5(){return sr(globalThis.Number)}const UP="~effect/SchemaTransformation/Transformation";var AF;AF=UP;const _m=class _m{constructor(t,n){Q(this,AF,UP);Q(this,"_tag","Transformation");Q(this,"decode");Q(this,"encode");this.decode=t,this.encode=n}flip(){return new _m(this.encode,this.decode)}compose(t){return new _m(this.decode.compose(t.decode),t.encode.compose(this.encode))}};let Or=_m;function eye(e){return it(e,UP)}const p5=e=>eye(e)?e:new Or(e.decode,e.encode);function Ly(e){return new Or(sr(e.decode),sr(e.encode))}const tye=new Or(_l(),_l());function CE(){return tye}const g5=new Or(h5(),Zme()),m5=e=>Ly({decode:t=>{const n=new Error(t.message);return typeof t.name=="string"&&t.name!=="Error"&&(n.name=t.name),typeof t.stack=="string"&&(n.stack=t.stack),n},encode:t=>{const n={name:t.name,message:t.message};return e!=null&&e.includeStack&&typeof t.stack=="string"&&(n.stack=t.stack),n}});function qs(e){return t=>t._tag===e}const y5=qs("Declaration"),nye=qs("Never"),hm=qs("Literal"),rye=qs("UniqueSymbol"),iye=qs("Arrays"),oye=qs("Objects"),aye=qs("Union");class pn{constructor(t,n){Q(this,"to");Q(this,"transformation");this.to=t,this.transformation=n}}const sye={};class Pl{constructor(t,n,r=void 0,i=void 0){Q(this,"isOptional");Q(this,"isMutable");Q(this,"defaultValue");Q(this,"annotations");this.isOptional=t,this.isMutable=n,this.defaultValue=r,this.annotations=i}}const bD="~effect/Schema";var jF;jF=bD;class cr{constructor(t=void 0,n=void 0,r=void 0,i=void 0){Q(this,jF,bD);Q(this,"annotations");Q(this,"checks");Q(this,"encoding");Q(this,"context");this.annotations=t,this.checks=n,this.encoding=r,this.context=i}toString(){return`<${this._tag}>`}}class Fd extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Declaration");Q(this,"typeParameters");Q(this,"run");this.typeParameters=n,this.run=r}getParser(){const n=this.run(this.typeParameters);return(r,i)=>Ds(r)?wE:a5(n(r.value,this,i),He)}recur(n){const r=Ol(this.typeParameters,n);return r===this.typeParameters?this:new Fd(r,this.run,this.annotations,this.checks,void 0,this.context)}getExpected(){var r;const n=(r=this.annotations)==null?void 0:r.expected;return typeof n=="string"?n:"<Declaration>"}}let uye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Null")}getParser(){return By(this,null)}getExpected(){return"null"}};const EE=new uye;let lye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Undefined")}getParser(){return By(this,void 0)}toCodecJson(){return fn(this,[v5])}getExpected(){return"undefined"}};const v5=new pn(EE,new Or(sr(()=>{}),sr(()=>null))),cye=new lye;let fye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Void")}getParser(){return By(this,void 0)}toCodecJson(){return fn(this,[v5])}getExpected(){return"void"}};const dye=new fye;let hye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Never")}getParser(){return Us(this,Bce)}getExpected(){return"never"}};const pye=new hye;let gye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Any")}getParser(){return Us(this,lU)}getExpected(){return"any"}};const mye=new gye;let yye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Unknown")}getParser(){return Us(this,lU)}getExpected(){return"unknown"}};const kE=new yye;let hf=class extends cr{constructor(n,r,i,o,a){super(r,i,o,a);Q(this,"_tag","Literal");Q(this,"literal");if(typeof n=="number"&&!globalThis.Number.isFinite(n))throw new Error(`A numeric literal must be finite, got ${Jt(n)}`);this.literal=n}getParser(){return By(this,this.literal)}toCodecJson(){return typeof this.literal=="bigint"?wD(this):this}toCodecStringTree(){return typeof this.literal=="string"?this:wD(this)}getExpected(){return typeof this.literal=="string"?JSON.stringify(this.literal):globalThis.String(this.literal)}};function wD(e){const t=globalThis.String(e.literal);return fn(e,[new pn(new hf(t),new Or(sr(()=>e.literal),sr(()=>t)))])}let vye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","String")}getParser(){return Us(this,NC)}getExpected(){return"string"}};const x5=new vye;let xye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Number")}getParser(){return Us(this,uU)}toCodecJson(){return this.checks&&(Yc(this.checks,"isFinite")||Yc(this.checks,"isInt"))?this:fn(this,[jye])}toCodecStringTree(){return this.checks&&(Yc(this.checks,"isFinite")||Yc(this.checks,"isInt"))?fn(this,[zye]):fn(this,[qye])}getExpected(){return"number"}};function Yc(e,t){return e.some(n=>{var r,i;switch(n._tag){case"Filter":return((i=(r=n.annotations)==null?void 0:r.meta)==null?void 0:i._tag)===t;case"FilterGroup":return Yc(n.checks,t)}})}const b5=new xye;let bye=class extends cr{constructor(){super(...arguments);Q(this,"_tag","Boolean")}getParser(){return Us(this,Lce)}getExpected(){return"boolean"}};const wye=new bye;class Dy extends cr{constructor(n,r,i,o,a,u,c){super(o,a,u,c);Q(this,"_tag","Arrays");Q(this,"isMutable");Q(this,"elements");Q(this,"rest");this.isMutable=n,this.elements=r,this.rest=i;const f=r.findIndex(ho);if(f!==-1&&(r.slice(f+1).some(h=>!ho(h))||i.length>1))throw new Error("A required element cannot follow an optional element. ts(1257)");if(i.length>1&&i.slice(1).some(ho))throw new Error("An optional element cannot follow a rest element. ts(1266)")}getParser(n){const r=this,i=r.elements.map(d=>({ast:d,parser:n(d)})),o=r.rest.map(d=>({ast:d,parser:n(d)})),a=i.length,[u,...c]=o,f=c.length;function h(d,g){return g<a?i[g]:g>=d?c[g-d]:u}return FP(function*(d,g){if(d._tag==="None")return d;const m=d.value;if(!Array.isArray(m))return yield*vt(new Ui(r,d));const v=m.length,x={ast:r,getParser:h,oinput:d,len:v,tailThreshold:_ye(v,a,f),output:new globalThis.Array(v),issues:void 0,options:g},b=AE(g==null?void 0:g.concurrency),O=Sye(x,m,{concurrency:b==null?void 0:b.concurrency,end:r.rest.length===0?a:Math.max(v,a+f)});if(O&&(yield*O),r.rest.length===0&&v>a)for(let _=a;_<=v-1;_++){const C=new mi([_],new c5(r,m[_]));if(g.errors==="all")x.issues?x.issues.push(C):x.issues=[C];else return yield*vt(new $n(r,d,[C]))}return x.issues?yield*vt(new $n(r,d,x.issues)):He(x.output)})}recur(n){const r=Ol(this.elements,n),i=Ol(this.rest,n);return r===this.elements&&i===this.rest?this:new Dy(this.isMutable,r,i,this.annotations,this.checks,void 0,this.context)}getExpected(){return"array"}}const Sye=My()({onItem(e,t,n){const r=n<e.len?He(t):Wr();return e.getParser(e.tailThreshold,n).parser(r,e.options)},step(e,t,n,r){var i;if(n._tag==="Failure")return pm(e,e.ast,r,n);if(n.value._tag==="Some")e.output[r]=n.value.value;else{const o=e.getParser(e.tailThreshold,r);if(ho(o.ast))return;const a=new mi([r],new l5((i=o.ast.context)==null?void 0:i.annotations));if(e.options.errors==="all")e.issues?e.issues.push(a):e.issues=[a];else return Ld(new $n(e.ast,e.oinput,[a]))}}});function _ye(e,t,n){return Math.max(t,e-n)}const AE=e=>(e=e==="unbounded"?1/0:e??1,e>1?{concurrency:e}:void 0),pm=(e,t,n,r)=>{const i=Nd(r.cause);if(hn(i))return r;const o=new mi([n],i.success);if(e.options.errors==="all")e.issues?e.issues.push(o):e.issues=[o];else return Ld(new $n(t,e.oinput,[o]))},jE="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",Pye=new globalThis.RegExp(`(?:${jE}|Infinity|-Infinity|NaN)`);function w5(e,t){const n=fa(t);switch(n._tag){case"String":return Object.keys(e);case"TemplateLiteral":{const r=Lye(n);return Object.keys(e).filter(i=>r.test(i))}case"Symbol":return Object.getOwnPropertySymbols(e);case"Number":return Object.keys(e).filter(r=>Pye.test(r));case"Union":return[...new Set(n.types.flatMap(r=>w5(e,r)))];default:return[]}}class S5{constructor(t,n){Q(this,"name");Q(this,"type");this.name=t,this.type=n}}class Oye{constructor(t,n,r){Q(this,"parameter");Q(this,"type");Q(this,"merge");if(this.parameter=t,this.type=n,this.merge=r,ho(n)&&!M5(n))throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}}class TE extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Objects");Q(this,"propertySignatures");Q(this,"indexSignatures");this.propertySignatures=n,this.indexSignatures=r;const c=n.map(f=>f.name).filter((f,h,d)=>d.indexOf(f)!==h);if(c.length>0)throw new Error(`Duplicate identifiers: ${JSON.stringify(c)}. ts(2300)`)}getParser(n){const r=this,i=[],o=new Set,a=[];for(const f of r.propertySignatures)i.push(f.name),o.add(f.name),a.push({ps:f,parser:n(f.type),name:f.name,type:f.type});const u=r.indexSignatures.length;if(r.propertySignatures.length===0&&r.indexSignatures.length===0)return Us(r,Fce);const c=u>0?My()({onItem:FP(function*(f,[h,d]){const m=n(D5(d.parameter))(He(h),f.options),v=Pr(m)?m:yield*pD(m);if(v._tag==="Failure"){const C=pm(f,r,h,v);C&&(yield*C);return}const x=He(f.input[h]),O=n(d.type)(x,f.options),_=Pr(O)?O:yield*pD(O);if(_._tag==="Failure"){const C=pm(f,r,h,_);C&&(yield*C);return}else if(v.value._tag==="Some"&&_.value._tag==="Some"){const C=v.value.value,E=_.value.value;if(d.merge&&d.merge.decode&&Object.hasOwn(f.out,C)){const[P,A]=d.merge.decode.combine([C,f.out[C]],[C,E]);Xc(f.out,P,A)}else Xc(f.out,C,E)}}),step:(f,h,d)=>d._tag==="Failure"?d:void 0}):void 0;return FP(function*(f,h){if(f._tag==="None")return f;const d=f.value;if(!(typeof d=="object"&&d!==null&&!Array.isArray(d)))return yield*vt(new Ui(r,f));const g={},m={ast:r,oinput:f,input:d,out:g,issues:void 0,options:h},v=h.errors==="all",x=h.onExcessProperty==="error",b=h.onExcessProperty==="preserve";let O;if(r.indexSignatures.length===0&&(x||b)){O=Reflect.ownKeys(d);for(let E=0;E<O.length;E++){const P=O[E];if(!o.has(P))if(x){const A=new mi([P],new c5(r,d[P]));if(v){m.issues?m.issues.push(A):m.issues=[A];continue}else return yield*vt(new $n(r,f,[A]))}else Xc(g,P,d[P])}}const _=AE(h==null?void 0:h.concurrency),C=Cye(m,a,_);if(C&&(yield*C),c){const E=ude();for(let A=0;A<u;A++){const j=r.indexSignatures[A],R=w5(d,j.parameter);for(let M=0;M<R.length;M++){const F=R[M];E.push([F,j])}}const P=c(m,E,_);P&&(yield*P)}if(m.issues)return yield*vt(new $n(r,f,m.issues));if(h.propertyOrder==="original"){const E=(O??Reflect.ownKeys(d)).concat(i),P={};for(const A of E)Object.hasOwn(g,A)&&Xc(P,A,g[A]);return He(P)}return He(g)})}rebuild(n,r){const i=Ol(this.propertySignatures,a=>{const u=n(a.type);return u===a.type?a:new S5(a.name,u)}),o=Ol(this.indexSignatures,a=>{var h;const u=n(a.parameter),c=n(a.type),f=r?(h=a.merge)==null?void 0:h.flip():a.merge;return u===a.parameter&&c===a.type&&f===a.merge?a:new Oye(u,c,f)});return i===this.propertySignatures&&o===this.indexSignatures?this:new TE(i,o,this.annotations,this.checks,void 0,this.context)}flip(n){return this.rebuild(n,!0)}recur(n){return this.rebuild(n,!1)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?"object | array":"object"}}const Cye=My()({onItem(e,t){const n=Object.hasOwn(e.input,t.name)?He(e.input[t.name]):Wr();return t.parser(n,e.options)},step(e,t,n){var r;if(n._tag==="Failure")return pm(e,e.ast,t.name,n);if(n.value._tag==="Some")Xc(e.out,t.name,n.value.value);else if(!ho(t.type)){const i=new mi([t.name],new l5((r=t.type.context)==null?void 0:r.annotations));if(e.options.errors==="all"){e.issues?e.issues.push(i):e.issues=[i];return}else return Ld(new $n(e.ast,e.oinput,[i]))}}});function RE(e,t,n){return new TE(Reflect.ownKeys(e).map(r=>new S5(r,e[r].ast)),[],n,t)}function _5(e){return e.ast}function IE(e,t,n){return new Bd(e.map(_5),t,void 0,n)}function P5(e){switch(e._tag){case"Null":return["null"];case"Undefined":case"Void":return["undefined"];case"String":case"TemplateLiteral":return["string"];case"Number":return["number"];case"Boolean":return["boolean"];case"Symbol":case"UniqueSymbol":return["symbol"];case"BigInt":return["bigint"];case"Arrays":return["array"];case"ObjectKeyword":return["object","array","function"];case"Objects":return e.propertySignatures.length||e.indexSignatures.length?["object"]:["object","array"];case"Enum":return Array.from(new Set(e.enums.map(([,t])=>typeof t)));case"Literal":return[typeof e.literal];case"Union":return Array.from(new Set(e.types.flatMap(P5)));default:return["null","undefined","string","number","boolean","symbol","bigint","object","array","function"]}}function ME(e){var t;switch(e._tag){default:return[];case"Declaration":{const n=(t=e.annotations)==null?void 0:t["~sentinels"];return Array.isArray(n)?n:[]}case"Objects":return e.propertySignatures.flatMap(n=>{const r=n.type;if(!ho(r)){if(hm(r))return[{key:n.name,literal:r.literal}];if(rye(r))return[{key:n.name,literal:r.symbol}]}return[]});case"Arrays":return e.elements.flatMap((n,r)=>hm(n)&&!ho(n)?[{key:r,literal:n.literal}]:[]);case"Suspend":return ME(e.thunk())}}const SD=new WeakMap;function Eye(e){var n,r;let t=SD.get(e);if(t)return t;t={};for(const i of e){const o=fa(i);if(nye(o))continue;const a=P5(o),u=ME(o);t.byType??(t.byType={});for(const c of a)((n=t.byType)[c]??(n[c]=[])).push(i);if(u.length>0){t.bySentinel??(t.bySentinel=new Map);for(const{key:c,literal:f}of u){let h=t.bySentinel.get(c);h||t.bySentinel.set(c,h=new Map);let d=h.get(f);d||h.set(f,d=[]),d.push(i)}}else{t.otherwise??(t.otherwise={});for(const c of a)((r=t.otherwise)[c]??(r[c]=[])).push(i)}}return SD.set(e,t),t}function _D(e){return t=>{const n=fa(t);return n._tag==="Literal"?n.literal===e:n._tag==="UniqueSymbol"?n.symbol===e:!0}}function kye(e,t){var i,o;const n=Eye(t),r=e===null?"null":Array.isArray(e)?"array":typeof e;if(n.bySentinel){const a=((i=n.otherwise)==null?void 0:i[r])??[];if(r==="object"||r==="array"){for(const[u,c]of n.bySentinel)if(Object.hasOwn(e,u)){const f=c.get(e[u]);if(f)return[...f,...a].filter(_D(e))}}return a}return(((o=n.byType)==null?void 0:o[r])??[]).filter(_D(e))}let Bd=class O5 extends cr{constructor(n,r,i,o,a,u){super(i,o,a,u);Q(this,"_tag","Union");Q(this,"types");Q(this,"mode");this.types=n,this.mode=r}getParser(n){const r=this;return(i,o)=>{if(i._tag==="None")return Mt(i);const a=i.value,u=kye(a,r.types),c={ast:r,recur:n,oinput:i,input:a,out:void 0,successes:[],issues:void 0,options:o},f=AE(o==null?void 0:o.concurrency),h=Aye(c,u,f);return h?Gr(h,d=>c.out?Mt(c.out):vt(new yD(r,a,c.issues??[]))):c.out?Mt(c.out):vt(new yD(r,a,c.issues??[]))}}recur(n){const r=Ol(this.types,n);return r===this.types?this:new O5(r,this.mode,this.annotations,this.checks,void 0,this.context)}getExpected(n){var o;const r=(o=this.annotations)==null?void 0:o.expected;if(typeof r=="string")return r;if(this.types.length===0)return"never";const i=this.types.map(a=>{const u=fa(a);switch(u._tag){case"Arrays":{const c=u.elements.filter(hm);if(c.length>0)return`${PD(u.isMutable)}[ ${c.map(f=>{var h;return n(f)+OD((h=f.context)==null?void 0:h.isOptional)}).join(", ")}, ... ]`;break}case"Objects":{const c=u.propertySignatures.filter(f=>hm(f.type));if(c.length>0)return`{ ${c.map(f=>{var h,d;return`${PD((h=f.type.context)==null?void 0:h.isMutable)}${nm(f.name)}${OD((d=f.type.context)==null?void 0:d.isOptional)}: ${n(f.type)}`}).join(", ")}, ... }`;break}}return n(u)});return Array.from(new Set(i)).join(" | ")}};const Aye=My()({onItem(e,t){return e.recur(t)(e.oinput,e.options)},step(e,t,n){if(n._tag==="Failure"){const r=Nd(n.cause);if(hn(r))return n;e.issues?e.issues.push(r.success):e.issues=[r.success]}else{if(e.out&&e.ast.mode==="oneOf")return e.successes.push(t),Ld(new Ume(e.ast,e.input,e.successes));if(e.out=n.value,e.successes.push(t),e.ast.mode==="anyOf")return F4}}}),C5=new Bd([new hf("Infinity"),new hf("-Infinity"),new hf("NaN")],"anyOf"),jye=new pn(new Bd([b5,C5],"anyOf"),new Or(h5(),sr(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function PD(e){return e?"":"readonly "}function OD(e){return e?"?":""}class gm extends dy{constructor(n,r=void 0,i=!1){super();Q(this,"_tag","Filter");Q(this,"run");Q(this,"annotations");Q(this,"aborted");this.run=n,this.annotations=r,this.aborted=i}annotate(n){return new gm(this.run,{...this.annotations,...n},this.aborted)}abort(){return new gm(this.run,this.annotations,!0)}and(n,r){return new mm([this,n],r)}}class mm extends dy{constructor(n,r=void 0){super();Q(this,"_tag","FilterGroup");Q(this,"checks");Q(this,"annotations");this.checks=n,this.annotations=r}annotate(n){return new mm(this.checks,{...this.annotations,...n})}and(n,r){return new mm([this,n],r)}}function E5(e,t,n=!1){return new gm((r,i,o)=>Wme(r,i,e(r,i,o)),t,n)}function Tye(e,t){const n=e.source;return E5(r=>e.test(r),{expected:`a string matching the RegExp ${n}`,meta:{_tag:"isPattern",regExp:e},toArbitraryConstraint:{string:{patterns:[e.source]}},...t})}function Fy(e,t){const n=Object.getOwnPropertyDescriptors(e);return t(n),Object.create(Object.getPrototypeOf(e),n)}function fn(e,t){return e.encoding===t?e:Fy(e,n=>{n.encoding.value=t})}function $E(e,t){return e.context===t?e:Fy(e,n=>{n.context.value=t})}function k5(e,t){if(e.checks){const n=e.checks[e.checks.length-1];return A5(e,$U(e.checks.slice(0,-1),n.annotate(t)))}return Fy(e,n=>{n.annotations.value={...n.annotations.value,...t}})}function A5(e,t){return e.checks===t?e:Fy(e,n=>{n.checks.value=t})}function NE(e,t){return A5(e,e.checks?[...e.checks,...t]:t)}function j5(e,t){const n=e,r=n[n.length-1],i=t(r.to);return i!==r.to?$U(e.slice(0,e.length-1),new pn(i,r.transformation)):e}function Rye(e){return t=>t.encoding?fn(t,j5(t.encoding,e)):t}function Iye(e,t,n){const r=new pn(e,t);return fn(n,n.encoding?[...n.encoding,r]:[r])}function Ol(e,t){let n=!1;const r=new Array(e.length);for(let i=0;i<e.length;i++){const o=e[i],a=t(o);a!==o&&(n=!0),r[i]=a}return n?r:e}function T5(e,t){const n=e.context?new Pl(e.context.isOptional,e.context.isMutable,e.context.defaultValue,{...e.context.annotations,...t}):new Pl(!1,!1,void 0,t);return $E(e,n)}const R5=Rye(I5);function I5(e){const t=e.context?e.context.isOptional===!1?new Pl(!0,e.context.isMutable,e.context.defaultValue,e.context.annotations):e.context:new Pl(!0,!1);return R5($E(e,t))}function Mye(e,t){const n=new Or(Jme(t),_l()),r=[new pn(kE,n)],i=e.context?new Pl(e.context.isOptional,e.context.isMutable,r,e.context.annotations):new Pl(!1,!1,r);return $E(e,i)}function $ye(e,t,n){return Iye(e,n,t)}function ho(e){var t;return((t=e.context)==null?void 0:t.isOptional)??!1}const ym=Ca(e=>{var n;if(e.encoding)return ym(fn(e,void 0));const t=e;return((n=t.recur)==null?void 0:n.call(t,ym))??t}),fa=Ca(e=>ym(ys(e)));function Nye(e,t){const n=t,r=n.length,i=n[r-1],o=[new pn(ys(fn(e,void 0)),n[0].transformation.flip())];for(let u=1;u<r;u++)o.unshift(new pn(ys(n[u-1].to),n[u].transformation.flip()));const a=ys(i.to);return a.encoding?fn(a,[...a.encoding,...o]):fn(a,o)}const ys=Ca(e=>{var n,r;if(e.encoding)return Nye(e,e.encoding);const t=e;return((n=t.flip)==null?void 0:n.call(t,ys))??((r=t.recur)==null?void 0:r.call(t,ys))??t});function M5(e){switch(e._tag){case"Undefined":return!0;case"Union":return e.types.some(M5);default:return!1}}function $5(e,t){return e.encodedParts.map(n=>Dye(n,N5(n),t)).join("")}const Lye=Ca(e=>new globalThis.RegExp(`^${$5(e,!0)}$`));function N5(e){switch(e._tag){case"Literal":return Lme(globalThis.String(e.literal));case"String":return Fye;case"Number":return jE;case"BigInt":return Uye;case"TemplateLiteral":return $5(e,!1);case"Union":return e.types.map(N5).join("|")}}function Dye(e,t,n){if(aye(e)){if(!n)return`(?:${t})`}else if(!n)return t;return`(${t})`}function By(e,t){const n=eme(t);return r=>r._tag==="None"?wE:r.value===t?n:vt(new Ui(e,r))}function Us(e,t){return n=>n._tag==="None"?wE:t(n.value)?Mt(n):vt(new Ui(e,n))}function L5(e){function t(n){return n.encoding?fn(n,j5(n.encoding,t)):e(n)}return Ca(t)}const D5=L5(e=>{switch(e._tag){default:return e;case"Number":return e.toCodecStringTree();case"Union":return e.recur(D5)}}),Fye="[\\s\\S]*?",CD=new globalThis.RegExp(`^${jE}$`);function Bye(e){return Tye(CD,{expected:"a string representing a finite number",meta:{_tag:"isStringFinite",regExp:CD},...e})}const F5=NE(x5,[Bye()]),zye=new pn(F5,g5),qye=new pn(new Bd([F5,C5],"anyOf"),g5),Uye="-?\\d+";function VP(e,t,n,r,i){for(let o=0;o<e.length;o++){const a=e[o];if(a._tag==="FilterGroup")VP(a.checks,t,n,r,i);else{const u=a.run(t,r,i);if(u&&(n.push(new zme(t,a,u)),a.aborted||(i==null?void 0:i.errors)!=="all"))return}}}const B5="~effect/Schema/Class",Vye="~structural";function Wye(e){const t=new Set,n=new Set;return r(e);function r(i){if(i===null||typeof i=="string"||typeof i=="boolean")return!0;if(typeof i=="number")return globalThis.Number.isFinite(i);if(typeof i!="object"||i===void 0||t.has(i))return!1;if(n.has(i))return!0;t.add(i);const o=Array.isArray(i)?i.every(r):Object.keys(i).every(a=>r(i[a]));return t.delete(i),o&&n.add(i),o}}const Hye=new Fd([],()=>(e,t)=>Wye(e)?Mt(e):vt(new Ui(t,He(e))),{typeConstructor:{_tag:"effect/Json"},generation:{runtime:"Schema.Json",Type:"Schema.Json"},expected:"JSON value",toCodecJson:()=>new pn(kE,CE())}),Gye=new pn(EE,new Or(_l(),sr(()=>null))),Kye=new pn(Hye,CE()),Xye=i4,Qc=eE,Yye=am,WP=ZC,Qye=Ipe,z5=zpe,Jye=Symbol.for("effect/MutableList/Empty"),Zye=()=>({head:void 0,tail:void 0,length:0}),ED=()=>({array:[],mutable:!0,offset:0,next:void 0}),HP=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=ED(),e.tail=e.tail.next):e.head=e.tail=ED(),e.tail.array.push(t),e.length++},eve=(e,t)=>tve(e,Fi(t),!Array.isArray(t)),tve=(e,t,n=!1)=>{if(t.length===0)return 0;const r={array:t,mutable:n,offset:0,next:void 0};return e.head?e.tail=e.tail.next=r:e.head=e.tail=r,e.length+=t.length,t.length},Up=e=>{e.head=e.tail=void 0,e.length=0},q5=(e,t)=>{var o;if(t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&((o=e.head)==null?void 0:o.offset)===0&&!e.head.next){const a=e.head.array;return Up(e),a}const n=new Array(t);let r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i,e.length-=t,e.length===0&&Up(e),n;i=i.next}return Up(e),n},nve=e=>{if(!e.head)return Jye;const t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length&&(e.head.next?e.head=e.head.next:Up(e)),t},rve="~effect/Queue",ive="~effect/Queue/Enqueue",ove="~effect/Queue/Dequeue",y1={_A:Fe,_E:Fe},ave={[rve]:y1,[ive]:y1,[ove]:y1,...ka,toJSON(){return{_id:"effect/Queue",state:this.state._tag,size:hve(this)}}},sve=e=>ut(t=>{const n=Object.create(ave);return n.dispatcher=t.currentDispatcher,n.capacity=(e==null?void 0:e.capacity)??Number.POSITIVE_INFINITY,n.strategy=(e==null?void 0:e.strategy)??"suspend",n.messages=Zye(),n.scheduleRunning=!1,n.state={_tag:"Open",takers:new Set,offers:new Set,awaiters:new Set},Be(n)}),uve=e=>sve({capacity:e}),lve=(e,t)=>Zt(()=>{if(e.state._tag!=="Open")return Be(Fi(t));const n=cve(e,t);return n.length===0?It([]):e.strategy==="dropping"?Be(n):vve(e,n)}),cve=(e,t)=>{if(e.state._tag!=="Open")return Fi(t);if(e.capacity===Number.POSITIVE_INFINITY||e.strategy==="sliding")return eve(e.messages,t),e.strategy==="sliding"&&q5(e.messages,e.messages.length-e.capacity),AD(e),[];const n=e.capacity<=0?e.state.takers.size:e.capacity-e.messages.length;if(n===0)return Fi(t);const r=[];let i=0;for(const o of t)i<n?HP(e.messages,o):r.push(o),i++;return AD(e),r},Jc=ce(2,(e,t)=>Yt(()=>fve(e,t))),fve=(e,t)=>{if(e.state._tag!=="Open")return!1;const n=Vr(t),r=Xhe(n,gve);return e.state.offers.size===0&&e.messages.length===0?(V5(e,r),!0):(e.state={...e.state,_tag:"Closing",exit:r},!0)},kD=e=>Jc(e,vU(VC())),dve=e=>U5(e,1,Number.POSITIVE_INFINITY),U5=(e,t,n)=>Zt(()=>yve(e,t,n)??Td(xve(e),U5(e,1,n))),hve=e=>e.state._tag==="Done"?0:e.messages.length,pve=It(!0),gve=zi(VC()),mve=e=>{if(e.scheduleRunning=!1,!(e.state._tag==="Done"||e.state.takers.size===0)){for(const t of e.state.takers)if(e.state.takers.delete(t),t(Hr),e.messages.length===0)break}},AD=e=>{e.scheduleRunning||e.state._tag==="Done"||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>mve(e),0))},yve=(e,t,n)=>{if(e.state._tag==="Done")return e.state.exit;if(n<=0||t<=0)return It([]);if(e.capacity<=0&&e.state.offers.size>0){e.capacity=1,v1(e),e.capacity=0;const r=[nve(e.messages)];return v1(e),It(r)}if(t=Math.min(t,e.capacity||1),t<=e.messages.length){const r=q5(e.messages,n);return v1(e),It(r)}},vve=(e,t)=>bi(n=>{if(e.state._tag!=="Open")return n(It(t));const r={_tag:"Array",remaining:t,offset:0,resume:n};return e.state.offers.add(r),Yt(()=>{e.state._tag==="Open"&&e.state.offers.delete(r)})}),v1=e=>{if(e.state._tag==="Done")return fD(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag==="Closing"&&e.messages.length===0?(V5(e,e.state.exit),fD(e.state.exit.cause)):!1;let t=e.capacity-e.messages.length;for(const n of e.state.offers){if(t===0)break;if(n._tag==="Single")HP(e.messages,n.message),t--,n.resume(pve),e.state.offers.delete(n);else{for(;n.offset<n.remaining.length;n.offset++){if(t===0)return!1;HP(e.messages,n.remaining[n.offset]),t--}n.resume(It([])),e.state.offers.delete(n)}}return!1},xve=e=>bi(t=>e.state._tag==="Done"?t(e.state.exit):(e.state.takers.add(t),Yt(()=>{e.state._tag!=="Done"&&e.state.takers.delete(t)}))),V5=(e,t)=>{if(e.state._tag==="Done")return;const n=e.state;e.state={_tag:"Done",exit:t};for(const r of n.takers)r(t);n.takers.clear();for(const r of n.awaiters)r(t);n.awaiters.clear()},bve="~effect/Channel",wve={[bve]:{_Env:Fe,_InErr:Fe,_InElem:Fe,_OutErr:Fe,_OutElem:Fe},pipe(){return Sn(this,arguments)}},LE=e=>{const t=Object.create(wve);return t.transform=(n,r)=>pd(e(n,r),i=>Mt(nme(i))),t},Sve=e=>LE((t,n)=>e),DE=e=>e.transform,_ve=e=>Sve(Mt(dve(e))),Pve=e=>LE((t,n)=>{let r;return Mt(vo(()=>r||e.pipe(sm(n),Gr(i=>DE(i)(t,n)),Gr(i=>r=i))))}),Ove=(e,t,n)=>vo(()=>{const r=hE(),i=DE(e)(ps(),r);return wl(Gr(i,t),Mt).pipe(r5(o=>Ny(r,o)))}),Cve=ce(2,(e,t)=>LE((n,r)=>Bs(gs(DE(e)(n,r),t),gs(t)))),Eve=ce(2,(e,t)=>Ove(e,n=>i5(Gr(n,t),{disableYield:!0}))),Dl=e=>e,Zc=Ca(e=>{var t;switch(e._tag){case"Declaration":{const n=(t=e.annotations)==null?void 0:t[B5];if(py(n)){const r=n(e.typeParameters),i=Zc(r.to);return fn(e,i===r.to?[r]:[new pn(i,r.transformation)])}return e}case"Objects":case"Arrays":return e.recur(n=>{var i;const r=(i=n.context)==null?void 0:i.defaultValue;return r?fn(Zc(n),r):Zc(n)});case"Suspend":return e.recur(Zc);default:return e}});function zy(e){const t=Zc(ym(e.ast)),n=FE(t);return(r,i)=>n(r,i!=null&&i.disableChecks?i!=null&&i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i==null?void 0:i.parseOptions)}function W5(e){const t=zy(e);return(n,r)=>Sge(o5(t(n,r)))}function kve(e){const t=zy(e);return(n,r)=>PE(zs(t(n,r),i=>new Error(i.toString(),{cause:i})))}function As(e){return FE(e.ast)}function Ave(e){return Rve(As(e))}const jve=Ave;function Tve(e){return FE(ys(e.ast))}function FE(e){const t=Vp(e);return(n,r)=>Tu(t(He(n),r??sye),i=>i._tag==="None"?vt(new dm(i)):Mt(i.value))}function Rve(e){return(t,n)=>PE(zs(e(t,n),r=>new Error(r.toString(),{cause:r})))}const Vp=Ca(e=>{var i;let t;const n=(i=s5(e))==null?void 0:i.parseOptions;if(!e.context&&!e.encoding&&!e.checks)return(o,a)=>(t??(t=e.getParser(Vp)),n&&(a={...a,...n}),t(o,a));const r=iye(e)||oye(e)||y5(e)&&e.typeParameters.length>0;return(o,a)=>{n&&(a={...a,...n});const u=e.encoding;let c;if(u){const h=u,d=h.length;for(let g=d-1;g>=0;g--){const m=h[g],v=m.to,x=Vp(v);if(c=c?Tu(c,b=>x(b,a)):x(o,a),m.transformation._tag==="Transformation"){const b=m.transformation.decode;c=Tu(c,O=>b.run(O,a))}else c=m.transformation.decode(c,a)}c=zs(c,g=>new qme(e,o,g))}t??(t=e.getParser(Vp));let f=c?Tu(c,h=>t(h,a)):t(o,a);if(e.checks&&!(a!=null&&a.disableChecks)){const h=e.checks;(a==null?void 0:a.errors)==="all"&&r&&ga(o)&&(f=Mme(f,d=>{const g=[];VP(h.filter(v=>{var x;return(x=v.annotations)==null?void 0:x[Vye]}),o.value,g,e,a);const m=VL(g)?d._tag==="Composite"&&d.ast===e?new $n(e,d.actual,[...d.issues,...g]):new $n(e,o,[d,...g]):d;return vt(m)})),f=Tu(f,d=>{if(ga(d)){const g=d.value,m=[];if(VP(h,g,m,e,a),VL(m))return vt(new $n(e,d,m))}return Mt(d)})}return f}}),GP="~effect/Schema/Schema",Ive={[GP]:GP,pipe(){return Sn(this,arguments)},annotate(e){return this.rebuild(k5(this.ast,e))},annotateKey(e){return this.rebuild(T5(this.ast,e))},check(...e){return this.rebuild(NE(this.ast,e))}};function BE(e,t){const n=Object.create(Ive);return t&&Object.assign(n,t),n.ast=e,n.rebuild=r=>BE(r,t),n.makeEffect=sU(zy(n),zs(r=>new qy(r))),n.make=kve(n),n.makeOption=W5(n),n}const jD="~effect/Schema/SchemaError";var TF;TF=jD;class qy{constructor(t){Q(this,TF,jD);Q(this,"_tag","SchemaError");Q(this,"name","SchemaError");Q(this,"issue");this.issue=t}get message(){return this.issue.toString()}toString(){return`SchemaError(${this.message})`}}const Mve=Nve($ve);function $ve(e){switch(e._tag){case"BigInt":case"Symbol":case"UniqueSymbol":return 0;default:return 1}}function Nve(e){return t=>{const n=new Map;for(let o=0;o<t.length;o++)n.set(fa(t[o]),o);const r=[...t].sort((o,a)=>{o=fa(o),a=fa(a);const u=e(o),c=e(a);return u!==c?u-c:n.get(o)-n.get(a)});return r.some((o,a)=>o!==t[a])?r:t}}const pf=GP;function Uy(){return(e,t,n)=>ht(new Fd(e.map(_5),r=>t(r.map(i=>ht(i))),n))}function H5(e,t){return Uy()([],()=>(n,r)=>e(n)?Mt(n):vt(new Ui(r,He(n))),t)}function TD(e){const t=As(e);return(n,r)=>zs(t(n,r),i=>new qy(i))}const Lve=jve;function Dve(e){const t=Tve(e);return(n,r)=>zs(t(n,r),i=>new qy(i))}const Fve=Dve,ht=BE;function zE(e){return it(e,pf)&&e[pf]===pf}const KP=Dl(e=>ht(I5(e.ast),{schema:e})),Fl=Dl(e=>KP(Y5(e)));function da(e){const t=ht(new hf(e),{literal:e,transform(n){return t.pipe(xm(da(n),{decode:sr(()=>n),encode:sr(()=>e)}))}});return t}const RD=ht(pye),ID=ht(mye),G5=ht(kE),Bve=ht(EE),zve=ht(cye),ar=ht(x5),K5=ht(b5),qve=ht(wye),vm=ht(dye);function qE(e,t){return ht(e,{fields:t,mapFields(n,r){const i=n(this.fields);return qE(RE(i,r!=null&&r.unsafePreserveChecks?this.ast.checks:void 0),i)}})}function Nn(e){return qE(RE(e,void 0),e)}const XP=Dl(e=>ht(new Dy(!1,[],[e.ast]),{schema:e})),Uve=Dl(e=>ht(new Dy(!1,[e.ast],[e.ast]),{schema:e}));function X5(e,t){return ht(e,{members:t,mapMembers(n,r){const i=n(this.members);return X5(IE(i,this.ast.mode,r!=null&&r.unsafePreserveChecks?this.ast.checks:void 0),i)}})}function yi(e,t){return X5(IE(e,"anyOf",void 0),e)}function Vy(e){const t=e.map(da);return ht(IE(t,"anyOf",void 0),{literals:e,members:t,mapMembers(n){return yi(n(this.members))},pick(n){return Vy(n)},transform(n){return yi(t.map((r,i)=>r.transform(n[i])))}})}const Vve=Dl(e=>yi([e,Bve])),Y5=Dl(e=>yi([e,zve]));function xm(e,t){return n=>ht($ye(n.ast,e.ast,t?p5(t):CE()),{from:n,to:e})}function Wve(e){return t=>ht(Mye(t.ast,e),{schema:t})}function fr(e){return da(e).pipe(Wve(Mt(e)))}function Hve(e,t){return Nn({_tag:fr(e),...t})}function Gve(e,t){return H5(n=>n instanceof e,t)}function zd(){return(e,t)=>new pn(e.ast,p5(t))}const Kve=E5;function Xve(e){return Kve(t=>globalThis.Number.isFinite(t),{expected:"a finite number",meta:{_tag:"isFinite"},toArbitraryConstraint:{number:{noDefaultInfinity:!0,noNaN:!0}},...e})}function MD(e,t){const n=Uy()([e,t],([r,i])=>(o,a,u)=>{if(!pge(o))return vt(new Ui(a,He(o)));switch(o._tag){case"Fail":return gd(As(r)(o.error,u),{onSuccess:jP,onFailure:c=>new $n(a,He(o),[new mi(["error"],c)])});case"Die":return gd(As(i)(o.defect,u),{onSuccess:TP,onFailure:c=>new $n(a,He(o),[new mi(["defect"],c)])});case"Interrupt":return Mt(o)}},{typeConstructor:{_tag:"effect/Cause/Failure"},generation:{runtime:"Schema.CauseReason(?, ?)",Type:"Cause.Failure<?, ?>",importDeclaration:'import * as Cause from "effect/Cause"'},expected:"Cause.Failure",toCodec:([r,i])=>zd()(yi([Nn({_tag:da("Fail"),error:r}),Nn({_tag:da("Die"),defect:i}),Nn({_tag:da("Interrupt"),fiberId:Y5(Jve)})]),Ly({decode:o=>{switch(o._tag){case"Fail":return jP(o.error);case"Die":return TP(o.defect);case"Interrupt":return RP(o.fiberId)}},encode:Fe})),toArbitrary:([r,i])=>Q5(r,i),toEquivalence:([r,i])=>J5(r,i),toFormatter:([r,i])=>Z5(r,i)});return ht(n.ast,{error:e,defect:t})}function Q5(e,t){return(n,r)=>n.oneof(r!=null&&r.isSuspend?{maxDepth:2,depthIdentifier:"Cause.Failure"}:{},n.constant(RP()),n.integer({min:1}).map(RP),e.map(i=>jP(i)),t.map(i=>TP(i)))}function J5(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case"Fail":return e(n.error,r.error);case"Die":return t(n.defect,r.defect);case"Interrupt":return n.fiberId===r.fiberId}}}function Z5(e,t){return n=>{switch(n._tag){case"Fail":return`Fail(${e(n.error)})`;case"Die":return`Die(${t(n.defect)})`;case"Interrupt":return"Interrupt"}}}function $D(e,t){const n=Uy()([e,t],([r,i])=>{const o=XP(MD(r,i));return(a,u,c)=>hge(a)?gd(As(o)(a.reasons,c),{onSuccess:AP,onFailure:f=>new $n(u,He(a),[new mi(["failures"],f)])}):vt(new Ui(u,He(a)))},{typeConstructor:{_tag:"effect/Cause"},generation:{runtime:"Schema.Cause(?, ?)",Type:"Cause.Cause<?, ?>",importDeclaration:'import * as Cause from "effect/Cause"'},expected:"Cause",toCodec:([r,i])=>zd()(XP(MD(r,i)),Ly({decode:AP,encode:({reasons:o})=>o})),toArbitrary:([r,i])=>e6(r,i),toEquivalence:([r,i])=>t6(r,i),toFormatter:([r,i])=>n6(r,i)});return ht(n.ast,{error:e,defect:t})}function e6(e,t){return(n,r)=>n.array(Q5(e,t)(n,r)).map(AP)}function t6(e,t){const n=ufe(J5(e,t));return(r,i)=>n(r.reasons,i.reasons)}function n6(e,t){const n=Z5(e,t);return r=>`Cause([${r.reasons.map(n).join(", ")}])`}const r6=Nn({message:ar,name:KP(ar),stack:KP(ar)}),Yve=Gve(globalThis.Error,{typeConstructor:{_tag:"Error"},generation:{runtime:"Schema.Error",Type:"globalThis.Error"},expected:"Error",toCodecJson:()=>zd()(r6,m5()),toArbitrary:()=>e=>e.string().map(t=>new globalThis.Error(t))}),ND=new Or(_l(),sr(e=>{try{return JSON.parse(JSON.stringify(e))}catch{return Jt(e)}})),wi=yi([r6.pipe(xm(Yve,m5())),ID.pipe(xm(G5.annotate({toCodecJson:()=>zd()(ID,ND),toArbitrary:()=>e=>e.json()}),ND))]);function Qve(e,t,n){const r=Uy()([e,t,n],([i,o,a])=>{const u=$D(o,a);return(c,f,h)=>{if(!vge(c))return vt(new Ui(f,He(c)));switch(c._tag){case"Success":return gd(As(i)(c.value,h),{onSuccess:m1,onFailure:d=>new $n(f,He(c),[new mi(["value"],d)])});case"Failure":return gd(As(u)(c.cause,h),{onSuccess:cf,onFailure:d=>new $n(f,He(c),[new mi(["cause"],d)])})}}},{typeConstructor:{_tag:"effect/Exit"},generation:{runtime:"Schema.Exit(?, ?, ?)",Type:"Exit.Exit<?, ?, ?>",importDeclaration:'import * as Exit from "effect/Exit"'},expected:"Exit",toCodec:([i,o,a])=>zd()(yi([Nn({_tag:da("Success"),value:i}),Nn({_tag:da("Failure"),cause:$D(o,a)})]),Ly({decode:u=>u._tag==="Success"?m1(u.value):cf(u.cause),encode:u=>wge(u)?{_tag:"Success",value:u.value}:{_tag:"Failure",cause:u.cause}})),toArbitrary:([i,o,a])=>(u,c)=>u.oneof(c!=null&&c.isSuspend?{maxDepth:2,depthIdentifier:"Exit"}:{},i.map(f=>m1(f)),e6(o,a)(u,c).map(f=>cf(f))),toEquivalence:([i,o,a])=>{const u=t6(o,a);return(c,f)=>{if(c._tag!==f._tag)return!1;switch(c._tag){case"Success":return i(c.value,f.value);case"Failure":return u(c.cause,f.cause)}}},toFormatter:([i,o,a])=>{const u=n6(o,a);return c=>{switch(c._tag){case"Success":return`Exit.Success(${i(c.value)})`;case"Failure":return`Exit.Failure(${u(c.cause)})`}}}});return ht(r.ast,{value:e,error:t,defect:n})}const Jve=K5.check(Xve()),Zve=globalThis.Symbol.for("immer-draftable");function UE(e,t,n,r,i){var c,f,h,d;const o=t0e(n,t,r),a=i6(t),u=(d=class extends e{constructor(...[g,m]){g=g??{};const v=n.make(g,m);super({...g,...v},{...m,disableChecks:!0})}get[(h=pf,f=a,c=Zve,f)](){return a}static get ast(){return o(this).ast}static pipe(){return Sn(this,arguments)}static rebuild(g){return o(this).rebuild(g)}static make(g,m){return new this(g,m)}static makeOption(g,m){return W5(o(this))(g??{},m)}static makeEffect(g,m){return zs(zy(o(this))(g??{},m),v=>new qy(v))}static annotate(g){return this.rebuild(k5(this.ast,g))}static annotateKey(g){return this.rebuild(T5(this.ast,g))}static check(...g){return this.rebuild(NE(this.ast,g))}static extend(g){return(m,v)=>{const x={...n.fields,...m};return UE(this,g,qE(RE(x,n.ast.checks,{identifier:g}),x),v,i)}}static mapFields(g,m){return n.mapFields(g,m)}},Q(d,h,pf),Q(d,c,!0),Q(d,"identifier",t),Q(d,"fields",n.fields),d);return i!==void 0&&Object.assign(u.prototype,i(t)),u}function e0e(e){return new Or(sr(t=>new e(t)),_l())}function i6(e){return`~effect/Schema/Class/${e}`}function t0e(e,t,n){let r;return i=>{if(r===void 0){const o=e0e(i),a=ht(new Fd([e.ast],()=>(u,c)=>u instanceof i||it(u,i6(t))?Mt(u):vt(new Ui(c,He(u))),{identifier:t,[B5]:([u])=>new pn(u,o),toCodec:([u])=>new pn(u.ast,o),toArbitrary:([u])=>()=>u.map(c=>new i(c)),toFormatter:([u])=>c=>`${i.identifier}(${u(c)})`,"~sentinels":ME(e.ast),...n}));r=e.pipe(xm(a,o))}return r}}function VE(e){return zE(e)}const n0e=e=>(t,n)=>{const r=VE(t)?t:Nn(t);return UE(Nge,e,r,n,i=>({toString(){return`${i}(${Jt({...this})})`}}))},Yr=e=>(t,n)=>{const r=VE(t)?t:Nn(t);return UE(wU,e,r,n,o=>({name:o}))},r0e=e=>(t,n,r)=>Yr(e)(VE(n)?n.mapFields(i=>({_tag:fr(t),...i}),{unsafePreserveChecks:!0}):Hve(t,n),r);function x1(e){return ht(o6(e.ast))}const o6=L5(e=>{const t=i0e(e,o6);return t!==e&&ho(e)?R5(t):t});function i0e(e,t){var n,r;switch(e._tag){case"Declaration":{const i=((n=e.annotations)==null?void 0:n.toCodecJson)??((r=e.annotations)==null?void 0:r.toCodec);if(py(i)){const o=y5(e)?e.typeParameters.map(c=>BE(fa(c))):[],a=i(o),u=t(a.to);return fn(e,u===a.to?[a]:[new pn(u,a.transformation)])}return fn(e,[Gye])}case"Unknown":case"ObjectKeyword":return fn(e,[Kye]);case"Undefined":case"Void":case"Literal":case"Number":return e.toCodecJson();case"UniqueSymbol":case"Symbol":case"BigInt":return e.toCodecStringTree();case"Objects":{if(e.propertySignatures.some(i=>typeof i.name!="string"))throw new globalThis.Error("Objects property names must be strings",{cause:e});return e.recur(t)}case"Union":{const i=Mve(e.types);return i!==e.types?new Bd(i,e.mode,e.annotations,e.checks,e.encoding,e.context).recur(t):e.recur(t)}case"Arrays":case"Suspend":return e.recur(t)}return e}const o0e="~effect/Stream",a0e={_R:Fe,_E:Fe,_A:Fe},s0e={[o0e]:a0e,pipe(){return Sn(this,arguments)}},u0e=e=>{const t=Object.create(s0e);return t.channel=e,t},l0e="~effect/Stream",c0e=e=>it(e,l0e),WE=u0e,f0e=e=>e.channel,d0e=e=>WE(_ve(e)),h0e=e=>WE(Pve(Bs(e,f0e))),p0e=ce(2,(e,t)=>WE(Cve(e.channel,t))),g0e=ce(2,(e,t)=>Eve(e.channel,n=>{let r=0;return J4({while:()=>r<n.length,body:()=>t(n[r++]),step:kd})})),YP="~effect/FiberSet",m0e=e=>it(e,YP),y0e={[YP]:YP,[Symbol.iterator](){return this.state._tag==="Closed"?Yfe():this.state.backing[Symbol.iterator]()},...ka,toJSON(){return{_id:"FiberMap",state:this.state}}},v0e=(e,t)=>{const n=Object.create(y0e);return n.state={_tag:"Open",backing:e},n.deferred=t,n},x0e=()=>t5(zr(()=>v0e(new Set,fE())),e=>vo(()=>{const t=e.state;if(t._tag==="Closed")return jt;e.state={_tag:"Closed"};const n=t.backing;return Yye(n).pipe(Cge(e.deferred))})),a6=-1,b0e=Fde(zde(yge,Bde(a6))),w0e=ce(e=>m0e(e[0]),(e,t,n)=>{if(e.state._tag==="Closed"){t.interruptUnsafe(a6);return}else if(e.state.backing.has(t))return;e.state.backing.add(t),t.addObserver(r=>{e.state._tag!=="Closed"&&(e.state.backing.delete(t),B4(r)&&((n==null?void 0:n.propagateInterruption)===!0?!b0e(r.cause):!gge(r.cause))&&ff(e.deferred,r))})}),S0e=(function(){let e;return()=>(e===void 0&&(e=DP(LP)),e)})(),_0e=e=>()=>Bs(cm(),t=>{const n=fm(t);return(r,i)=>{if(e.state._tag==="Closed")return S0e();const o=n(r,i);return w0e(e,o),o}}),LD=e=>dE(e.deferred),P0e="~effect/interfaces/PrimaryKey",DD="~effect/ManagedRuntime",O0e=(e,t)=>{const n=(t==null?void 0:t.memoMap)??gE(),r=hE("parallel"),i=um(r,"sequential"),o={onFiberStart:Qye(r)},a=h=>h?{...h,onFiberStart:h.onFiberStart?d=>{o.onFiberStart(d),h.onFiberStart(d)}:o.onFiberStart}:o;let u;const c=lm(h=>(u||(u=DP(ame(mE(e,n,i),d=>zr(()=>{f.cachedContext=d})),{...o,scheduler:h.currentScheduler})),ime(Xye(u)))),f={[DD]:DD,memoMap:n,scope:r,contextEffect:c,cachedContext:void 0,context(){return f.cachedContext===void 0?df(f.contextEffect):Promise.resolve(f.cachedContext)},dispose(){return df(f.disposeEffect)},disposeEffect:vo(()=>(f.contextEffect=rme("ManagedRuntime disposed"),f.cachedContext=void 0,Ny(f.scope,F4))),runFork(h,d){return f.cachedContext===void 0?DP(Su(f,h),a(d)):fm(f.cachedContext)(h,a(d))},runCallback(h,d){return f.cachedContext===void 0?Cme(Su(f,h),a(d)):Ome(f.cachedContext)(h,a(d))},runSyncExit(h){return f.cachedContext===void 0?o5(Su(f,h)):Tme(f.cachedContext)(h)},runSync(h){return f.cachedContext===void 0?PE(Su(f,h)):jme(f.cachedContext)(h)},runPromiseExit(h,d){return f.cachedContext===void 0?kme(Su(f,h),a(d)):Ame(f.cachedContext)(h,a(d))},runPromise(h,d){return f.cachedContext===void 0?df(Su(f,h),a(d)):Eme(f.cachedContext)(h,a(d))}};return f};function Su(e,t){return Gr(e.contextEffect,n=>gs(t,n))}const QP="~effect/rpc/RpcSchema/StreamSchema";function s6(e){return it(e,QP)}function u6(e){return s6(e)?He({success:e.success,error:e.error}):Wr()}const C0e=H5(c0e);function E0e(e,t){return ht(C0e.ast,{[QP]:QP,success:e,error:t})}const FD="~effect/rpc/Rpc",k0e={[FD]:FD,pipe(){return Sn(this,arguments)},setSuccess(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:e,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},setError(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:e,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},setPayload(e){return Ko({_tag:this._tag,payloadSchema:zE(e)?e:Nn(e),successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},middleware(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:new Set([...this.middlewares,e])})},prefix(e){return Ko({_tag:`${e}${this._tag}`,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,annotations:this.annotations,middlewares:this.middlewares})},annotate(e,t){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,middlewares:this.middlewares,annotations:Aa(this.annotations,e,t)})},annotateMerge(e){return Ko({_tag:this._tag,payloadSchema:this.payloadSchema,successSchema:this.successSchema,errorSchema:this.errorSchema,defectSchema:this.defectSchema,middlewares:this.middlewares,annotations:xl(this.annotations,e)})}},Ko=e=>{function t(){}return Object.setPrototypeOf(t,k0e),Object.assign(t,e),t.key=`effect/rpc/Rpc/${e._tag}`,t},Bl=(e,t)=>{const n=(t==null?void 0:t.success)??vm,r=(t==null?void 0:t.error)??RD,i=(t==null?void 0:t.defect)??wi;let o;return t!=null&&t.primaryKey?o=class extends n0e(`effect/rpc/Rpc/${e}`)(t.payload){[P0e](){return t.primaryKey(this)}}:o=zE(t==null?void 0:t.payload)?t==null?void 0:t.payload:t!=null&&t.payload?Nn(t==null?void 0:t.payload):vm,Ko({_tag:e,payloadSchema:o,successSchema:t!=null&&t.stream?E0e(n,r):n,errorSchema:t!=null&&t.stream?RD:r,defectSchema:i,annotations:gi(),middlewares:new Set})},b1=new WeakMap,A0e=e=>{if(b1.has(e))return b1.get(e);const t=e,n=new Set([t.errorSchema]),r=u6(t.successSchema);ga(r)&&n.add(r.value.error);for(const o of t.middlewares)n.add(o.error);const i=Qve(ga(r)?vm:t.successSchema,yi([...n]),t.defectSchema);return b1.set(e,i),i},j0e="~effect/rpc/Rpc/Wrapper",T0e=e=>j0e in e,BD=Symbol.for("~effect/http/Headers"),yd=Object.create(null);Object.defineProperties(yd,{[BD]:{value:BD},[my]:{value(e){return $0e(this,hs(e,N0e))}},toJSON:{value(){return yy(this)}},[Wn]:{value(e){return I0e(this,e)}},[Vn]:{value(){return DC(this)}},toString:{value:BL.toString},[Cs]:{value:BL[Cs]}});const R0e=e=>Object.assign(Object.create(yd),e),I0e=ede(sfe()),HE=Object.create(yd),M0e=e=>{if(e===void 0)return HE;if(Symbol.iterator in e){const n=Object.create(yd);for(const[r,i]of e)n[r.toLowerCase()]=i;return n}const t=Object.create(yd);for(const[n,r]of Object.entries(e))Array.isArray(r)?t[n.toLowerCase()]=r.join(", "):r!==void 0&&(t[n.toLowerCase()]=r);return t},zD=ce(2,(e,t)=>{const n=R0e(e);return Object.assign(n,t),n}),$0e=ce(2,(e,t)=>{const n={...e},r=i=>{if(typeof i=="string"){const o=i.toLowerCase();o in e&&(n[o]=mD(e[o]))}else for(const o in e)i.test(o)&&(n[o]=mD(e[o]))};if(Array.isArray(t))for(let i=0;i<t.length;i++)r(t[i]);else r(t);return n}),N0e=Pt("effect/Headers/CurrentRedactedNames",{defaultValue:()=>["authorization","cookie","set-cookie","x-api-key"]}),L0e="~effect/http/HttpClientError";class GE extends Yr(L0e)({_tag:fr("HttpError"),kind:Vy(["EncodeError","DecodeError","TransportError","InvalidUrlError","StatusCodeError","EmptyBodyError"]),cause:Fl(wi)}){static fromHttpClientError(t){return new GE({_tag:"HttpError",kind:t.reason._tag,cause:t.reason})}}const qD="~effect/socket/Socket",KE=Xr("effect/socket/Socket"),D0e=e=>KE.of({[qD]:qD,runRaw:e.runRaw,run:e.run??((t,n)=>e.runRaw(r=>typeof r=="string"?t(F0e.encode(r)):r instanceof Uint8Array?t(r):t(new Uint8Array(r)),n)),runString:e.runString??(e.run?(t,n)=>e.run(r=>t(w1.decode(r)),n):(t,n)=>e.runRaw(r=>typeof r=="string"?t(r):r instanceof Uint8Array?t(w1.decode(r)):t(w1.decode(new Uint8Array(r))),n)),writer:e.writer}),F0e=new TextEncoder,w1=new TextDecoder,B0e="~effect/socket/Socket/CloseEvent",z0e=e=>it(e,B0e),Wp="~effect/socket/Socket/SocketError",q0e=e=>it(e,Wp);class l6 extends Yr("effect/socket/Socket/SocketReadError")({_tag:fr("SocketReadError"),cause:wi}){constructor(){super(...arguments);Q(this,"message","An error occurred during Read")}}class U0e extends Yr("effect/socket/Socket/SocketWriteError")({_tag:fr("SocketWriteError"),cause:wi}){constructor(){super(...arguments);Q(this,"message","An error occurred during Write")}}class bm extends Yr("effect/socket/Socket/SocketOpenError")({_tag:fr("SocketOpenError"),kind:Vy(["Unknown","Timeout"]),cause:wi}){get message(){return this.kind==="Timeout"?'timeout waiting for "open"':"An error occurred during Open"}}class wm extends Yr("effect/socket/Socket/SocketCloseError")({_tag:fr("SocketCloseError"),code:K5,closeReason:Fl(ar)}){static filterClean(t){return function(n){return Fu.is(n)&&n.reason._tag==="SocketCloseError"&&t(n.reason.code)?So(n.reason):pi(n)}}get message(){return this.closeReason?`${this.code}: ${this.closeReason}`:`${this.code}`}}const c6=yi([l6,U0e,bm,wm]);var RF,IF;class Fu extends(IF=r0e(Wp)("SocketError",{_tag:fr("SocketError"),reason:c6}),RF=Wp,IF){constructor(n){var t=(...KSe)=>(super(...KSe),Q(this,RF,Wp),Q(this,"message",this.reason.message),this);"cause"in n.reason?t({...n,cause:n.reason.cause}):t(n)}static is(n){return q0e(n)}}const V0e=e=>!0;class W0e extends Xr()("~effect/socket/Socket/WebSocket"){}class f6 extends Xr()("@effect/platform/Socket/WebSocketConstructor"){}const H0e=yE(f6)((e,t)=>new globalThis.WebSocket(e,t)),G0e=(e,t)=>f6.use(n=>K0e(t5((typeof e=="string"?Mt(e):e).pipe(Bs(r=>n(r,t==null?void 0:t.protocols))),r=>zr(()=>r.close(1e3))),t)),K0e=(e,t)=>lm(n=>{let r;const i=z5(!1),o=n.context,a=(t==null?void 0:t.closeCodeIsError)??V0e,u=(h,d)=>xme(ms(function*(g){const m=yield*x0e().pipe(sm(g)),v=yield*sm(e,g),x=yield*vme(_0e(m)(),W0e,v);let b=!1;function O(E){if(E.data instanceof Blob){const A=Gr(Zge(()=>E.data.arrayBuffer()),j=>{const R=h(new Uint8Array(j));return Du(R)?R:jt});return x(A)}const P=h(E.data);Du(P)&&x(P)}function _(E){v.removeEventListener("message",O),v.removeEventListener("close",C),ff(m.deferred,vt(new Fu({reason:b?new l6({cause:E}):new bm({kind:"Unknown",cause:E})})))}function C(E){const P=typeof E.code=="number"?E.code:1001;v.removeEventListener("message",O),v.removeEventListener("error",_),ff(m.deferred,vt(new Fu({reason:new wm({code:P,closeReason:E.reason})})))}if(v.addEventListener("close",C,{once:!0}),v.addEventListener("error",_,{once:!0}),v.addEventListener("message",O),v.readyState!==1){const E=fE();v.addEventListener("open",()=>{b=!0,ff(E,jt)},{once:!0}),yield*dE(E).pipe(dme({duration:(t==null?void 0:t.openTimeout)??1e4,orElse:()=>vt(new Fu({reason:new bm({kind:"Timeout",cause:new Error('timeout waiting for "open"')})}))}),Z4(LD(m)))}return b=!0,r=v,i.openUnsafe(),d!=null&&d.onOpen&&(yield*d.onOpen),yield*sme(LD(m),wm.filterClean(E=>!a(E)),()=>jt)})).pipe(yme(g=>xl(o,g)),n5(zr(()=>{i.closeUnsafe(),r=void 0}))),f=Mt(h=>i.whenOpen(zr(()=>{const d=r;z0e(h)?d.close(h.code,h.reason):d.send(h)})));return Mt(D0e({runRaw:u,writer:f}))}),X0e=sU(G0e,IP(KE));class d6 extends Xr()("effect/workers/Transferable/Collector"){}const Y0e=()=>{let e=[];const t=i=>{e.push(...i)},n=()=>e,r=()=>{const i=e;return e=[],i};return d6.of({addAllUnsafe:t,addAll:i=>zr(()=>t(i)),readUnsafe:n,read:zr(n),clearUnsafe:r,clear:zr(r)})};class Q0e extends Yr("effect/workers/WorkerError/WorkerSpawnError")({_tag:fr("WorkerSpawnError"),message:ar,cause:Fl(wi)}){}class J0e extends Yr("effect/workers/WorkerError/WorkerSendError")({_tag:fr("WorkerSendError"),message:ar,cause:Fl(wi)}){}class Z0e extends Yr("effect/workers/WorkerError/WorkerReceiveError")({_tag:fr("WorkerReceiveError"),message:ar,cause:Fl(wi)}){}class exe extends Yr("effect/workers/WorkerError/WorkerUnknownError")({_tag:fr("WorkerUnknownError"),message:ar,cause:Fl(wi)}){}const txe=yi([Q0e,J0e,Z0e,exe]),S1="~effect/rpc/RpcClientError";class JP extends Yr("effect/rpc/RpcClientError/RpcClientDefect")({_tag:fr("RpcClientDefect"),message:ar,cause:wi}){}var MF,$F;class UD extends($F=Yr(S1)({_tag:fr("RpcClientError"),reason:yi([txe,c6,GE,JP])}),MF=S1,$F){constructor(){super(...arguments);Q(this,MF,S1)}get message(){return`${this.reason._tag}: ${this.reason.message}`}}const Pp=e=>typeof e=="bigint"?e:BigInt(e),nxe={_tag:"Ping"};var ZP;try{ZP=new TextDecoder}catch{}var ye,Ni,J=0,dt={},We,oa,Dr=0,Ai=0,cn,po,ur=[],Ue,VD={useRecords:!1,mapsAsObjects:!0};class h6{}const p6=new h6;p6.name="MessagePack 0xC1";var ha=!1,WD=2,rxe;class vd{constructor(t){t&&(t.useRecords===!1&&t.mapsAsObjects===void 0&&(t.mapsAsObjects=!0),t.sequential&&t.trusted!==!1&&(t.trusted=!0,!t.structures&&t.useRecords!=!1&&(t.structures=[],t.maxSharedStructures||(t.maxSharedStructures=0))),t.structures?t.structures.sharedLength=t.structures.length:t.getStructures&&((t.structures=[]).uninitialized=!0,t.structures.sharedLength=0),t.int64AsNumber&&(t.int64AsType="number")),Object.assign(this,t)}unpack(t,n){if(ye)return b6(()=>(tO(),this?this.unpack(t,n):vd.prototype.unpack.call(VD,t,n)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<"u"?Buffer.from(t):new Uint8Array(t)),typeof n=="object"?(Ni=n.end||t.length,J=n.start||0):(J=0,Ni=n>-1?n:t.length),Ai=0,oa=null,cn=null,ye=t;try{Ue=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(r){throw ye=null,t instanceof Uint8Array?r:new Error("Source must be a Uint8Array or Buffer but was a "+(t&&typeof t=="object"?t.constructor.name:typeof t))}if(this instanceof vd){if(dt=this,this.structures)return We=this.structures,Op(n);(!We||We.length>0)&&(We=[])}else dt=VD,(!We||We.length>0)&&(We=[]);return Op(n)}unpackMultiple(t,n){let r,i=0;try{ha=!0;let o=t.length,a=this?this.unpack(t,o):Wy.unpack(t,o);if(n){if(n(a,i,J)===!1)return;for(;J<o;)if(i=J,n(Op(),i,J)===!1)return}else{for(r=[a];J<o;)i=J,r.push(Op());return r}}catch(o){throw o.lastPosition=i,o.values=r,o}finally{ha=!1,tO()}}_mergeStructures(t,n){t=t||[],Object.isFrozen(t)&&(t=t.map(r=>r.slice(0)));for(let r=0,i=t.length;r<i;r++){let o=t[r];o&&(o.isShared=!0,r>=32&&(o.highByte=r-32>>5))}t.sharedLength=t.length;for(let r in n||[])if(r>=0){let i=t[r],o=n[r];o&&(i&&((t.restoreStructures||(t.restoreStructures=[]))[r]=i),t[r]=o)}return this.structures=t}decode(t,n){return this.unpack(t,n)}}function Op(e){try{if(!dt.trusted&&!ha){let n=We.sharedLength||0;n<We.length&&(We.length=n)}let t;if(dt.randomAccessStructure&&ye[J]<64&&ye[J]>=32&&rxe||(t=Ft()),cn&&(J=cn.postBundlePosition,cn=null),ha&&(We.restoreStructures=null),J==Ni)We&&We.restoreStructures&&HD(),We=null,ye=null,po&&(po=null);else{if(J>Ni)throw new Error("Unexpected end of MessagePack data");if(!ha){let n;try{n=JSON.stringify(t,(r,i)=>typeof i=="bigint"?`${i}n`:i).slice(0,100)}catch(r){n="(JSON view not available "+r+")"}throw new Error("Data read, but end of buffer not reached "+n)}}return t}catch(t){throw We&&We.restoreStructures&&HD(),tO(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer")||J>Ni)&&(t.incomplete=!0),t}}function HD(){for(let e in We.restoreStructures)We[e]=We.restoreStructures[e];We.restoreStructures=null}function Ft(){let e=ye[J++];if(e<160)if(e<128){if(e<64)return e;{let t=We[e&63]||dt.getStructures&&g6()[e&63];return t?(t.read||(t.read=XE(t,e&63)),t.read()):e}}else if(e<144)if(e-=128,dt.mapsAsObjects){let t={};for(let n=0;n<e;n++){let r=y6();r==="__proto__"&&(r="__proto_"),t[r]=Ft()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(Ft(),Ft());return t}else{e-=144;let t=new Array(e);for(let n=0;n<e;n++)t[n]=Ft();return dt.freezeData?Object.freeze(t):t}else if(e<192){let t=e-160;if(Ai>=J)return oa.slice(J-Dr,(J+=t)-Dr);if(Ai==0&&Ni<140){let n=t<16?YE(t):m6(t);if(n!=null)return n}return eO(t)}else{let t;switch(e){case 192:return null;case 193:return cn?(t=Ft(),t>0?cn[1].slice(cn.position1,cn.position1+=t):cn[0].slice(cn.position0,cn.position0-=t)):p6;case 194:return!1;case 195:return!0;case 196:if(t=ye[J++],t===void 0)throw new Error("Unexpected end of buffer");return _1(t);case 197:return t=Ue.getUint16(J),J+=2,_1(t);case 198:return t=Ue.getUint32(J),J+=4,_1(t);case 199:return Ha(ye[J++]);case 200:return t=Ue.getUint16(J),J+=2,Ha(t);case 201:return t=Ue.getUint32(J),J+=4,Ha(t);case 202:if(t=Ue.getFloat32(J),dt.useFloat32>2){let n=QE[(ye[J]&127)<<1|ye[J+1]>>7];return J+=4,(n*t+(t>0?.5:-.5)>>0)/n}return J+=4,t;case 203:return t=Ue.getFloat64(J),J+=8,t;case 204:return ye[J++];case 205:return t=Ue.getUint16(J),J+=2,t;case 206:return t=Ue.getUint32(J),J+=4,t;case 207:return dt.int64AsType==="number"?(t=Ue.getUint32(J)*4294967296,t+=Ue.getUint32(J+4)):dt.int64AsType==="string"?t=Ue.getBigUint64(J).toString():dt.int64AsType==="auto"?(t=Ue.getBigUint64(J),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=Ue.getBigUint64(J),J+=8,t;case 208:return Ue.getInt8(J++);case 209:return t=Ue.getInt16(J),J+=2,t;case 210:return t=Ue.getInt32(J),J+=4,t;case 211:return dt.int64AsType==="number"?(t=Ue.getInt32(J)*4294967296,t+=Ue.getUint32(J+4)):dt.int64AsType==="string"?t=Ue.getBigInt64(J).toString():dt.int64AsType==="auto"?(t=Ue.getBigInt64(J),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=Ue.getBigInt64(J),J+=8,t;case 212:if(t=ye[J++],t==114)return JD(ye[J++]&63);{let n=ur[t];if(n)return n.read?(J++,n.read(Ft())):n.noBuffer?(J++,n()):n(ye.subarray(J,++J));throw new Error("Unknown extension "+t)}case 213:return t=ye[J],t==114?(J++,JD(ye[J++]&63,ye[J++])):Ha(2);case 214:return Ha(4);case 215:return Ha(8);case 216:return Ha(16);case 217:return t=ye[J++],Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):oxe(t);case 218:return t=Ue.getUint16(J),J+=2,Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):axe(t);case 219:return t=Ue.getUint32(J),J+=4,Ai>=J?oa.slice(J-Dr,(J+=t)-Dr):sxe(t);case 220:return t=Ue.getUint16(J),J+=2,KD(t);case 221:return t=Ue.getUint32(J),J+=4,KD(t);case 222:return t=Ue.getUint16(J),J+=2,XD(t);case 223:return t=Ue.getUint32(J),J+=4,XD(t);default:if(e>=224)return e-256;if(e===void 0){let n=new Error("Unexpected end of MessagePack data");throw n.incomplete=!0,n}throw new Error("Unknown MessagePack token "+e)}}}const ixe=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function XE(e,t){function n(){if(n.count++>WD){let i;try{i=e.read=new Function("r","return function(){return "+(dt.freezeData?"Object.freeze":"")+"({"+e.map(o=>o==="__proto__"?"__proto_:r()":ixe.test(o)?o+":r()":"["+JSON.stringify(o)+"]:r()").join(",")+"})}")(Ft)}catch{return WD=1/0,n()}return e.read0=i,e.highByte===0&&(e.read=GD(t,e.read)),i()}let r={};for(let i=0,o=e.length;i<o;i++){let a=e[i];a==="__proto__"&&(a="__proto_"),r[a]=Ft()}return dt.freezeData?Object.freeze(r):r}return n.count=0,e.read0=n,e.highByte===0?GD(t,n):n}const GD=(e,t)=>function(){let n=ye[J++];if(n===0)return t();let r=e<32?-(e+(n<<5)):e+(n<<5),i=We[r]||g6()[r];if(!i)throw new Error("Record id is not defined for "+r);return i.read||(i.read=XE(i,e)),i.read()};function g6(){let e=b6(()=>(ye=null,dt.getStructures()));return We=dt._mergeStructures(e,We)}var eO=qd,oxe=qd,axe=qd,sxe=qd;function qd(e){let t;if(e<16&&(t=YE(e)))return t;if(e>64&&ZP)return ZP.decode(ye.subarray(J,J+=e));const n=J+e,r=[];for(t="";J<n;){const i=ye[J++];if((i&128)===0)r.push(i);else if((i&224)===192){const o=ye[J++]&63,a=(i&31)<<6|o;a<128?r.push(65533):r.push(a)}else if((i&240)===224){const o=ye[J++]&63,a=ye[J++]&63,u=(i&31)<<12|o<<6|a;u<2048||u>=55296&&u<=57343?r.push(65533):r.push(u)}else if((i&248)===240){const o=ye[J++]&63,a=ye[J++]&63,u=ye[J++]&63;let c=(i&7)<<18|o<<12|a<<6|u;c<65536||c>1114111?r.push(65533):(c>65535&&(c-=65536,r.push(c>>>10&1023|55296),c=56320|c&1023),r.push(c))}else r.push(65533);r.length>=4096&&(t+=sn.apply(String,r),r.length=0)}return r.length>0&&(t+=sn.apply(String,r)),t}function KD(e){let t=new Array(e);for(let n=0;n<e;n++)t[n]=Ft();return dt.freezeData?Object.freeze(t):t}function XD(e){if(dt.mapsAsObjects){let t={};for(let n=0;n<e;n++){let r=y6();r==="__proto__"&&(r="__proto_"),t[r]=Ft()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(Ft(),Ft());return t}}var sn=String.fromCharCode;function m6(e){let t=J,n=new Array(e);for(let r=0;r<e;r++){const i=ye[J++];if((i&128)>0){J=t;return}n[r]=i}return sn.apply(String,n)}function YE(e){if(e<4)if(e<2){if(e===0)return"";{let t=ye[J++];if((t&128)>1){J-=1;return}return sn(t)}}else{let t=ye[J++],n=ye[J++];if((t&128)>0||(n&128)>0){J-=2;return}if(e<3)return sn(t,n);let r=ye[J++];if((r&128)>0){J-=3;return}return sn(t,n,r)}else{let t=ye[J++],n=ye[J++],r=ye[J++],i=ye[J++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){J-=4;return}if(e<6){if(e===4)return sn(t,n,r,i);{let o=ye[J++];if((o&128)>0){J-=5;return}return sn(t,n,r,i,o)}}else if(e<8){let o=ye[J++],a=ye[J++];if((o&128)>0||(a&128)>0){J-=6;return}if(e<7)return sn(t,n,r,i,o,a);let u=ye[J++];if((u&128)>0){J-=7;return}return sn(t,n,r,i,o,a,u)}else{let o=ye[J++],a=ye[J++],u=ye[J++],c=ye[J++];if((o&128)>0||(a&128)>0||(u&128)>0||(c&128)>0){J-=8;return}if(e<10){if(e===8)return sn(t,n,r,i,o,a,u,c);{let f=ye[J++];if((f&128)>0){J-=9;return}return sn(t,n,r,i,o,a,u,c,f)}}else if(e<12){let f=ye[J++],h=ye[J++];if((f&128)>0||(h&128)>0){J-=10;return}if(e<11)return sn(t,n,r,i,o,a,u,c,f,h);let d=ye[J++];if((d&128)>0){J-=11;return}return sn(t,n,r,i,o,a,u,c,f,h,d)}else{let f=ye[J++],h=ye[J++],d=ye[J++],g=ye[J++];if((f&128)>0||(h&128)>0||(d&128)>0||(g&128)>0){J-=12;return}if(e<14){if(e===12)return sn(t,n,r,i,o,a,u,c,f,h,d,g);{let m=ye[J++];if((m&128)>0){J-=13;return}return sn(t,n,r,i,o,a,u,c,f,h,d,g,m)}}else{let m=ye[J++],v=ye[J++];if((m&128)>0||(v&128)>0){J-=14;return}if(e<15)return sn(t,n,r,i,o,a,u,c,f,h,d,g,m,v);let x=ye[J++];if((x&128)>0){J-=15;return}return sn(t,n,r,i,o,a,u,c,f,h,d,g,m,v,x)}}}}}function YD(){let e=ye[J++],t;if(e<192)t=e-160;else switch(e){case 217:t=ye[J++];break;case 218:t=Ue.getUint16(J),J+=2;break;case 219:t=Ue.getUint32(J),J+=4;break;default:throw new Error("Expected string")}return qd(t)}function _1(e){return dt.copyBuffers?Uint8Array.prototype.slice.call(ye,J,J+=e):ye.subarray(J,J+=e)}function Ha(e){let t=ye[J++];if(ur[t]){let n;return ur[t](ye.subarray(J,n=J+=e),r=>{J=r;try{return Ft()}finally{J=n}})}else throw new Error("Unknown extension type "+t)}var QD=new Array(4096);function y6(){let e=ye[J++];if(e>=160&&e<192){if(e=e-160,Ai>=J)return oa.slice(J-Dr,(J+=e)-Dr);if(!(Ai==0&&Ni<180))return eO(e)}else return J--,v6(Ft());let t=(e<<5^(e>1?Ue.getUint16(J):e>0?ye[J]:0))&4095,n=QD[t],r=J,i=J+e-3,o,a=0;if(n&&n.bytes==e){for(;r<i;){if(o=Ue.getUint32(r),o!=n[a++]){r=1879048192;break}r+=4}for(i+=3;r<i;)if(o=ye[r++],o!=n[a++]){r=1879048192;break}if(r===i)return J=r,n.string;i-=3,r=J}for(n=[],QD[t]=n,n.bytes=e;r<i;)o=Ue.getUint32(r),n.push(o),r+=4;for(i+=3;r<i;)o=ye[r++],n.push(o);let u=e<16?YE(e):m6(e);return u!=null?n.string=u:n.string=eO(e)}function v6(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return e.toString();if(e==null)return e+"";if(dt.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(t=>["string","number","boolean","bigint"].includes(typeof t)))return e.flat().toString();throw new Error(`Invalid property type for record: ${typeof e}`)}const JD=(e,t)=>{let n=Ft().map(v6),r=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,n.highByte=t);let i=We[e];return i&&(i.isShared||ha)&&((We.restoreStructures||(We.restoreStructures=[]))[e]=i),We[e]=n,n.read=XE(n,r),(n.read0||n.read)()};ur[0]=()=>{};ur[0].noBuffer=!0;ur[66]=e=>{let t=e.byteLength%8||8,n=BigInt(e[0]&128?e[0]-256:e[0]);for(let r=1;r<t;r++)n<<=BigInt(8),n+=BigInt(e[r]);if(e.byteLength!==t){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(o,a)=>{let u=a-o;if(u<=40){let d=r.getBigUint64(o);for(let g=o+8;g<a;g+=8)d<<=BigInt(64),d|=r.getBigUint64(g);return d}let c=o+(u>>4<<3),f=i(o,c),h=i(c,a);return f<<BigInt((a-c)*8)|h};n=n<<BigInt((r.byteLength-t)*8)|i(t,r.byteLength)}return n};let ZD={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError=="function"?AggregateError:null};ur[101]=()=>{let e=Ft();if(!ZD[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return ZD[e[0]](e[1],{cause:e[2]})};ur[105]=e=>{if(dt.structuredClone===!1)throw new Error("Structured clone extension is disabled");let t=Ue.getUint32(J-4);po||(po=new Map);let n=ye[J],r;n>=144&&n<160||n==220||n==221?r=[]:n>=128&&n<144||n==222||n==223?r=new Map:(n>=199&&n<=201||n>=212&&n<=216)&&ye[J+1]===115?r=new Set:r={};let i={target:r};po.set(t,i);let o=Ft();if(i.used)Object.assign(r,o);else return i.target=o;if(r instanceof Map)for(let[a,u]of o.entries())r.set(a,u);if(r instanceof Set)for(let a of Array.from(o))r.add(a);return r};ur[112]=e=>{if(dt.structuredClone===!1)throw new Error("Structured clone extension is disabled");let t=Ue.getUint32(J-4),n=po.get(t);return n.used=!0,n.target};ur[115]=()=>new Set(Ft());const x6=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");let uxe=typeof globalThis=="object"?globalThis:window;ur[116]=e=>{let t=e[0],n=Uint8Array.prototype.slice.call(e,1).buffer,r=x6[t];if(!r){if(t===16)return n;if(t===17)return new DataView(n);throw new Error("Could not find typed array for code "+t)}return new uxe[r](n)};ur[120]=()=>{let e=Ft();return new RegExp(e[0],e[1])};const lxe=[];ur[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=J;return J+=t-e.length,cn=lxe,cn=[YD(),YD()],cn.position0=0,cn.position1=0,cn.postBundlePosition=J,J=n,Ft()};ur[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date("invalid");function b6(e){let t=Ni,n=J,r=Dr,i=Ai,o=oa,a=po,u=cn,c=new Uint8Array(ye.slice(0,Ni)),f=We,h=We.slice(0,We.length),d=dt,g=ha,m=e();return Ni=t,J=n,Dr=r,Ai=i,oa=o,po=a,cn=u,ye=c,ha=g,We=f,We.splice(0,We.length,...h),dt=d,Ue=new DataView(ye.buffer,ye.byteOffset,ye.byteLength),m}function tO(){ye=null,po=null,We=null}const QE=new Array(147);for(let e=0;e<256;e++)QE[e]=+("1e"+Math.floor(45.15-e*.30103));var Wy=new vd({useRecords:!1});Wy.unpack;Wy.unpackMultiple;Wy.unpack;let cxe=new Float32Array(1);new Uint8Array(cxe.buffer,0,4);let Hp;try{Hp=new TextEncoder}catch{}let nO,rO;const Cl=typeof Buffer<"u",Cp=Cl?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,w6=Cl?Buffer:Uint8Array,eF=Cl?4294967296:2144337920;let re,zc,at,ee=0,kn,Et=null,fxe;const dxe=21760,hxe=/[\u0080-\uFFFF]/,_u=Symbol("record-id");class pxe extends vd{constructor(t){super(t),this.offset=0;let n,r,i,o,a=w6.prototype.utf8Write?function(T,N){return re.utf8Write(T,N,re.byteLength-N)}:Hp&&Hp.encodeInto?function(T,N){return Hp.encodeInto(T,re.subarray(N)).written}:!1,u=this;t||(t={});let c=t&&t.sequential,f=t.structures||t.saveStructures,h=t.maxSharedStructures;if(h==null&&(h=f?32:0),h>8160)throw new Error("Maximum maxSharedStructure is 8160");t.structuredClone&&t.moreTypes==null&&(this.moreTypes=!0);let d=t.maxOwnStructures;d==null&&(d=f?32:64),!this.structures&&t.useRecords!=!1&&(this.structures=[]);let g=h>32||d+h>64,m=h+64,v=h+d+64;if(v>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let x=[],b=0,O=0;this.pack=this.encode=function(T,N){if(re||(re=new Cp(8192),at=re.dataView||(re.dataView=new DataView(re.buffer,0,8192)),ee=0),kn=re.length-10,kn-ee<2048?(re=new Cp(re.length),at=re.dataView||(re.dataView=new DataView(re.buffer,0,re.length)),kn=re.length-10,ee=0):ee=ee+7&2147483640,n=ee,N&xxe&&(ee+=N&255),o=u.structuredClone?new Map:null,u.bundleStrings&&typeof T!="string"?(Et=[],Et.size=1/0):Et=null,i=u.structures,i){i.uninitialized&&(i=u._mergeStructures(u.getStructures()));let z=i.sharedLength||0;if(z>h)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+i.sharedLength);if(!i.transitions){i.transitions=Object.create(null);for(let q=0;q<z;q++){let W=i[q];if(!W)continue;let Z,Y=i.transitions;for(let U=0,K=W.length;U<K;U++){let ae=W[U];Z=Y[ae],Z||(Z=Y[ae]=Object.create(null)),Y=Z}Y[_u]=q+64}this.lastNamedStructuresLength=z}c||(i.nextId=z+64)}r&&(r=!1);let B;try{u.randomAccessStructure&&!u.readOnlyStructures&&T&&typeof T=="object"?T.constructor===Object?L(T):T.constructor!==Map&&!Array.isArray(T)&&!rO.some(q=>T instanceof q)?L(T.toJSON?T.toJSON():T):E(T):E(T);let z=Et;if(Et&&nF(n,E,0),o&&o.idsToInsert){let q=o.idsToInsert.sort((U,K)=>U.offset>K.offset?1:-1),W=q.length,Z=-1;for(;z&&W>0;){let U=q[--W].offset+n;U<z.stringsPosition+n&&Z===-1&&(Z=0),U>z.position+n?Z>=0&&(Z+=6):(Z>=0&&(at.setUint32(z.position+n,at.getUint32(z.position+n)+Z),Z=-1),z=z.previous,W++)}Z>=0&&z&&at.setUint32(z.position+n,at.getUint32(z.position+n)+Z),ee+=q.length*6,ee>kn&&M(ee),u.offset=ee;let Y=gxe(re.subarray(n,ee),q);return o=null,Y}return u.offset=ee,N&yxe?(re.start=n,re.end=ee,re):re.subarray(n,ee)}catch(z){throw B=z,z}finally{if(i&&(_(),r&&u.saveStructures)){let z=i.sharedLength||0,q=re.subarray(n,ee),W=mxe(i,u);if(!B)return u.saveStructures(W,W.isCompatible)===!1?(i.uninitialized=!0,u.pack(T,N)):(u.lastNamedStructuresLength=z,re.length>1073741824&&(re=null),q)}re.length>1073741824&&(re=null),N&vxe&&(ee=n)}};const _=()=>{O<10&&O++;let T=i.sharedLength||0;if(i.length>T&&!c&&(i.length=T),b>1e4)i.transitions=null,O=0,b=0,x.length>0&&(x=[]);else if(x.length>0&&!c){for(let N=0,B=x.length;N<B;N++)x[N][_u]=0;x=[]}},C=T=>{var N=T.length;N<16?re[ee++]=144|N:N<65536?(re[ee++]=220,re[ee++]=N>>8,re[ee++]=N&255):(re[ee++]=221,at.setUint32(ee,N),ee+=4);for(let B=0;B<N;B++)E(T[B])},E=T=>{ee>kn&&(re=M(ee));var N=typeof T,B;if(N==="string"){let z=T.length;if(Et&&z>=4&&z<4096){if((Et.size+=z)>dxe){let Y,U=(Et[0]?Et[0].length*3+Et[1].length:0)+10;ee+U>kn&&(re=M(ee+U));let K;Et.position?(K=Et,re[ee]=200,ee+=3,re[ee++]=98,Y=ee-n,ee+=4,nF(n,E,0),at.setUint16(Y+n-3,ee-n-Y)):(re[ee++]=214,re[ee++]=98,Y=ee-n,ee+=4),Et=["",""],Et.previous=K,Et.size=0,Et.position=Y}let Z=hxe.test(T);Et[Z?0:1]+=T,re[ee++]=193,E(Z?-z:z);return}let q;z<32?q=1:z<256?q=2:z<65536?q=3:q=5;let W=z*3;if(ee+W>kn&&(re=M(ee+W)),z<64||!a){let Z,Y,U,K=ee+q;for(Z=0;Z<z;Z++)Y=T.charCodeAt(Z),Y<128?re[K++]=Y:Y<2048?(re[K++]=Y>>6|192,re[K++]=Y&63|128):(Y&64512)===55296&&((U=T.charCodeAt(Z+1))&64512)===56320?(Y=65536+((Y&1023)<<10)+(U&1023),Z++,re[K++]=Y>>18|240,re[K++]=Y>>12&63|128,re[K++]=Y>>6&63|128,re[K++]=Y&63|128):(re[K++]=Y>>12|224,re[K++]=Y>>6&63|128,re[K++]=Y&63|128);B=K-ee-q}else B=a(T,ee+q);B<32?re[ee++]=160|B:B<256?(q<2&&re.copyWithin(ee+2,ee+1,ee+1+B),re[ee++]=217,re[ee++]=B):B<65536?(q<3&&re.copyWithin(ee+3,ee+2,ee+2+B),re[ee++]=218,re[ee++]=B>>8,re[ee++]=B&255):(q<5&&re.copyWithin(ee+5,ee+3,ee+3+B),re[ee++]=219,at.setUint32(ee,B),ee+=4),ee+=B}else if(N==="number")if(T>>>0===T)T<32||T<128&&this.useRecords===!1||T<64&&!this.randomAccessStructure?re[ee++]=T:T<256?(re[ee++]=204,re[ee++]=T):T<65536?(re[ee++]=205,re[ee++]=T>>8,re[ee++]=T&255):(re[ee++]=206,at.setUint32(ee,T),ee+=4);else if(T>>0===T)T>=-32?re[ee++]=256+T:T>=-128?(re[ee++]=208,re[ee++]=T+256):T>=-32768?(re[ee++]=209,at.setInt16(ee,T),ee+=2):(re[ee++]=210,at.setInt32(ee,T),ee+=4);else{let z;if((z=this.useFloat32)>0&&T<4294967296&&T>=-2147483648){re[ee++]=202,at.setFloat32(ee,T);let q;if(z<4||(q=T*QE[(re[ee]&127)<<1|re[ee+1]>>7])>>0===q){ee+=4;return}else ee--}re[ee++]=203,at.setFloat64(ee,T),ee+=8}else if(N==="object"||N==="function")if(!T)re[ee++]=192;else{if(o){let q=o.get(T);if(q){if(!q.id){let W=o.idsToInsert||(o.idsToInsert=[]);q.id=W.push(q)}re[ee++]=214,re[ee++]=112,at.setUint32(ee,q.id),ee+=4;return}else o.set(T,{offset:ee-n})}let z=T.constructor;if(z===Object)R(T);else if(z===Array)C(T);else if(z===Map)if(this.mapAsEmptyObject)re[ee++]=128;else{B=T.size,B<16?re[ee++]=128|B:B<65536?(re[ee++]=222,re[ee++]=B>>8,re[ee++]=B&255):(re[ee++]=223,at.setUint32(ee,B),ee+=4);for(let[q,W]of T)E(q),E(W)}else{for(let q=0,W=nO.length;q<W;q++){let Z=rO[q];if(T instanceof Z){let Y=nO[q];if(Y.write){Y.type&&(re[ee++]=212,re[ee++]=Y.type,re[ee++]=0);let he=Y.write.call(this,T);he===T?Array.isArray(T)?C(T):R(T):E(he);return}let U=re,K=at,ae=ee;re=null;let pe;try{pe=Y.pack.call(this,T,he=>(re=U,U=null,ee+=he,ee>kn&&M(ee),{target:re,targetView:at,position:ee-he}),E)}finally{U&&(re=U,at=K,ee=ae,kn=re.length-10)}pe&&(pe.length+ee>kn&&M(pe.length+ee),ee=tF(pe,re,ee,Y.type));return}}if(Array.isArray(T))C(T);else{if(T.toJSON){const q=T.toJSON();if(q!==T)return E(q)}if(N==="function")return E(this.writeFunction&&this.writeFunction(T));R(T)}}}else if(N==="boolean")re[ee++]=T?195:194;else if(N==="bigint"){if(T<9223372036854776e3&&T>=-9223372036854776e3)re[ee++]=211,at.setBigInt64(ee,T);else if(T<18446744073709552e3&&T>0)re[ee++]=207,at.setBigUint64(ee,T);else if(this.largeBigIntToFloat)re[ee++]=203,at.setFloat64(ee,Number(T));else{if(this.largeBigIntToString)return E(T.toString());if(this.useBigIntExtension||this.moreTypes){let z=T<0?BigInt(-1):BigInt(0),q;if(T>>BigInt(65536)===z){let W=BigInt(18446744073709552e3)-BigInt(1),Z=[];for(;Z.push(T&W),T>>BigInt(63)!==z;)T>>=BigInt(64);q=new Uint8Array(new BigUint64Array(Z).buffer),q.reverse()}else{let W=T<0,Z=(W?~T:T).toString(16);if(Z.length%2?Z="0"+Z:parseInt(Z.charAt(0),16)>=8&&(Z="00"+Z),Cl)q=Buffer.from(Z,"hex");else{q=new Uint8Array(Z.length/2);for(let Y=0;Y<q.length;Y++)q[Y]=parseInt(Z.slice(Y*2,Y*2+2),16)}if(W)for(let Y=0;Y<q.length;Y++)q[Y]=~q[Y]}q.length+ee>kn&&M(q.length+ee),ee=tF(q,re,ee,66);return}else throw new RangeError(T+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}ee+=8}else if(N==="undefined")this.encodeUndefinedAsNil?re[ee++]=192:(re[ee++]=212,re[ee++]=0,re[ee++]=0);else throw new Error("Unknown type: "+N)},P=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?T=>{let N;if(this.skipValues){N=[];for(let q in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(q))&&!this.skipValues.includes(T[q])&&N.push(q)}else N=Object.keys(T);let B=N.length;B<16?re[ee++]=128|B:B<65536?(re[ee++]=222,re[ee++]=B>>8,re[ee++]=B&255):(re[ee++]=223,at.setUint32(ee,B),ee+=4);let z;if(this.coercibleKeyAsNumber)for(let q=0;q<B;q++){z=N[q];let W=Number(z);E(isNaN(W)?z:W),E(T[z])}else for(let q=0;q<B;q++)E(z=N[q]),E(T[z])}:T=>{re[ee++]=222;let N=ee-n;ee+=2;let B=0;for(let z in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(z))&&(E(z),E(T[z]),B++);if(B>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');re[N+++n]=B>>8,re[N+n]=B&255},A=this.useRecords===!1?P:t.progressiveRecords&&!g?T=>{let N,B=i.transitions||(i.transitions=Object.create(null)),z=ee++-n,q;for(let W in T)if(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W)){if(N=B[W],N)B=N;else{let Z=Object.keys(T),Y=B;B=i.transitions;let U=0;for(let K=0,ae=Z.length;K<ae;K++){let pe=Z[K];N=B[pe],N||(N=B[pe]=Object.create(null),U++),B=N}z+n+1==ee?(ee--,F(B,Z,U)):$(B,Z,z,U),q=!0,B=Y[W]}E(T[W])}if(!q){let W=B[_u];W?re[z+n]=W:$(B,Object.keys(T),z,0)}}:T=>{let N,B=i.transitions||(i.transitions=Object.create(null)),z=0;for(let W in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W))&&(N=B[W],N||(N=B[W]=Object.create(null),z++),B=N);let q=B[_u];q?q>=96&&g?(re[ee++]=((q-=96)&31)+96,re[ee++]=q>>5):re[ee++]=q:F(B,B.__keys__||Object.keys(T),z);for(let W in T)(typeof T.hasOwnProperty!="function"||T.hasOwnProperty(W))&&E(T[W])},j=typeof this.useRecords=="function"&&this.useRecords,R=j?T=>{j(T)?A(T):P(T)}:A,M=T=>{let N;if(T>16777216){if(T-n>eF)throw new Error("Packed buffer would be larger than maximum buffer size");N=Math.min(eF,Math.round(Math.max((T-n)*(T>67108864?1.25:2),4194304)/4096)*4096)}else N=(Math.max(T-n<<2,re.length-1)>>12)+1<<12;let B=new Cp(N);return at=B.dataView||(B.dataView=new DataView(B.buffer,0,N)),T=Math.min(T,re.length),re.copy?re.copy(B,0,n,T):B.set(re.slice(n,T)),ee-=n,n=0,kn=B.length-10,re=B},F=(T,N,B)=>{let z=i.nextId;z||(z=64),z<m&&this.shouldShareStructure&&!this.shouldShareStructure(N)?(z=i.nextOwnId,z<v||(z=m),i.nextOwnId=z+1):(z>=v&&(z=m),i.nextId=z+1);let q=N.highByte=z>=96&&g?z-96>>5:-1;T[_u]=z,T.__keys__=N,i[z-64]=N,z<m?(N.isShared=!0,i.sharedLength=z-63,r=!0,q>=0?(re[ee++]=(z&31)+96,re[ee++]=q):re[ee++]=z):(q>=0?(re[ee++]=213,re[ee++]=114,re[ee++]=(z&31)+96,re[ee++]=q):(re[ee++]=212,re[ee++]=114,re[ee++]=z),B&&(b+=O*B),x.length>=d&&(x.shift()[_u]=0),x.push(T),E(N))},$=(T,N,B,z)=>{let q=re,W=ee,Z=kn,Y=n;re=zc,ee=0,n=0,re||(zc=re=new Cp(8192)),kn=re.length-10,F(T,N,z),zc=re;let U=ee;if(re=q,ee=W,kn=Z,n=Y,U>1){let K=ee+U-1;K>kn&&M(K);let ae=B+n;re.copyWithin(ae+U,ae+1,ee),re.set(zc.slice(0,U),ae),ee=K}else re[B+n]=zc[0]},L=T=>{let N=fxe(T,re,n,ee,i,M,(B,z,q)=>{if(q)return r=!0;ee=z;let W=re;return E(B),_(),W!==re?{position:ee,targetView:at,target:re}:ee},this);if(N===0)return R(T);ee=N}}useBuffer(t){re=t,re.dataView||(re.dataView=new DataView(re.buffer,re.byteOffset,re.byteLength)),at=re.dataView,ee=0}set position(t){ee=t}get position(){return ee}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}rO=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,h6];nO=[{pack(e,t,n){let r=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&r>=0&&r<4294967296){let{target:i,targetView:o,position:a}=t(6);i[a++]=214,i[a++]=255,o.setUint32(a,r)}else if(r>0&&r<4294967296){let{target:i,targetView:o,position:a}=t(10);i[a++]=215,i[a++]=255,o.setUint32(a,e.getMilliseconds()*4e6+(r/1e3/4294967296>>0)),o.setUint32(a+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return t(0),n(this.onInvalidDate());let{target:i,targetView:o,position:a}=t(3);i[a++]=212,i[a++]=255,i[a++]=255}else{let{target:i,targetView:o,position:a}=t(15);i[a++]=199,i[a++]=12,i[a++]=255,o.setUint32(a,e.getMilliseconds()*1e6),o.setBigInt64(a+4,BigInt(Math.floor(r)))}}},{pack(e,t,n){if(this.setAsEmptyObject)return t(0),n({});let r=Array.from(e),{target:i,position:o}=t(this.moreTypes?3:0);this.moreTypes&&(i[o++]=212,i[o++]=115,i[o++]=0),n(r)}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=101,r[i++]=0),n([e.name,e.message,e.cause])}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=120,r[i++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?P1(e,16,t):O1(Cl?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==w6&&this.moreTypes?P1(e,x6.indexOf(n.name),t):O1(e,t)}},{pack(e,t){this.moreTypes?P1(e,17,t):O1(Cl?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:n,position:r}=t(1);n[r]=193}}];function P1(e,t,n,r){let i=e.byteLength;if(i+1<256){var{target:o,position:a}=n(4+i);o[a++]=199,o[a++]=i+1}else if(i+1<65536){var{target:o,position:a}=n(5+i);o[a++]=200,o[a++]=i+1>>8,o[a++]=i+1&255}else{var{target:o,position:a,targetView:u}=n(7+i);o[a++]=201,u.setUint32(a,i+1),a+=4}o[a++]=116,o[a++]=t,e.buffer||(e=new Uint8Array(e)),o.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a)}function O1(e,t){let n=e.byteLength;var r,i;if(n<256){var{target:r,position:i}=t(n+2);r[i++]=196,r[i++]=n}else if(n<65536){var{target:r,position:i}=t(n+3);r[i++]=197,r[i++]=n>>8,r[i++]=n&255}else{var{target:r,position:i,targetView:o}=t(n+5);r[i++]=198,o.setUint32(i,n),i+=4}r.set(e,i)}function tF(e,t,n,r){let i=e.length;switch(i){case 1:t[n++]=212;break;case 2:t[n++]=213;break;case 4:t[n++]=214;break;case 8:t[n++]=215;break;case 16:t[n++]=216;break;default:i<256?(t[n++]=199,t[n++]=i):i<65536?(t[n++]=200,t[n++]=i>>8,t[n++]=i&255):(t[n++]=201,t[n++]=i>>24,t[n++]=i>>16&255,t[n++]=i>>8&255,t[n++]=i&255)}return t[n++]=r,t.set(e,n),n+=i,n}function gxe(e,t){let n,r=t.length*6,i=e.length-r;for(;n=t.pop();){let o=n.offset,a=n.id;e.copyWithin(o+r,o,i),r-=6;let u=o+r;e[u++]=214,e[u++]=105,e[u++]=a>>24,e[u++]=a>>16&255,e[u++]=a>>8&255,e[u++]=a&255,i=o}return e}function nF(e,t,n){if(Et.length>0){at.setUint32(Et.position+e,ee+n-Et.position-e),Et.stringsPosition=ee-e;let r=Et;Et=null,t(r[0]),t(r[1])}}function mxe(e,t){return e.isCompatible=n=>{let r=!n||(t.lastNamedStructuresLength||0)===n.length;return r||t._mergeStructures(n),r},e}let S6=new pxe({useRecords:!1});S6.pack;S6.pack;const yxe=512,vxe=1024,xxe=2048;class JE extends Xr()("effect/rpc/RpcSerialization"){}const bxe=JE.of({contentType:"application/json",includesFraming:!1,makeUnsafe:()=>{const e=new TextDecoder;return{decode:t=>{const n=JSON.parse(typeof t=="string"?t:e.decode(t));return Array.isArray(n)?n:[n]},encode:t=>JSON.stringify(t)}}}),wxe=yE(JE)(bxe),Sxe=e=>vo(()=>{const t=new Set,n=new Map,r=new Map;let i=(o,a)=>e5(u=>{let c=n.get(o);return c||(c=[],n.set(o,c)),c.push([a,u]),jt});return Bs(e((o,a)=>{const u=r.get(o);return u?u(a):i(o,a)},t),o=>({...o,run(a,u){return NP(function*(){t.add(a),r.set(a,u);const c=n.get(a);if(c){n.delete(a);for(const[f,h]of c)yield*gs(vo(()=>u(f)),h)}return yield*r5(tme,()=>(t.delete(a),r.delete(a),jt))})}}))});let _xe=BigInt(0);const Pxe=ms(function*(e,t){const n=(t==null?void 0:t.spanPrefix)??"RpcClient",r=(t==null?void 0:t.supportsAck)??!0,i=(t==null?void 0:t.disableTracing)??!1,o=(t==null?void 0:t.generateRequestId)??(()=>_xe++),a=yield*cm(),u=hs(a,sD),c=new Map;let f=!1;yield*Age(u,lm(_=>(f=!0,h(bge(_.id)))));const h=ms(function*(_){for(const[C,E]of c)c.delete(C),E._tag==="Queue"?yield*_._tag==="Success"?kD(E.queue):Jc(E.queue,_.cause):E.resume(_)}),d=_=>{const C=s6(_.successSchema),E=v(_);return(P,A)=>{const j=A!=null&&A.headers?M0e(A.headers):HE,R=(A==null?void 0:A.context)??gi();if(!C){const F=$=>g(_,E,$,_.payloadSchema.make(P),j,R,(A==null?void 0:A.discard)??!1);return i?F(void 0):_me(`${n}.${_._tag}`,{attributes:t.spanAttributes},F)}const M=m(_,E,_.payloadSchema.make(P),j,(A==null?void 0:A.streamBufferSize)??16,R);return A!=null&&A.asQueue?M:h0e(Bs(M,d0e))}},g=(_,C,E,P,A,j,R)=>lm(M=>{if(f)return LP;const F=o(),$=C(T=>t.onFromClient({message:T,context:j,discard:R}),{_tag:"Request",id:F,tag:_._tag,payload:P,...E?{traceId:E.traceId,spanId:E.spanId,sampled:E.sampled}:{},headers:zD(M.getRef(iF),A)});if(R)return $;let L;return wme(hD(T=>{const N={_tag:"Effect",rpc:_,context:j,resume(B){T(B),L&&!L.pollUnsafe()&&M.currentDispatcher.scheduleTask(()=>{L.interruptUnsafe(M.id)},0)}};c.set(F,N),L=$.pipe(E?gD(E,{captureStackTrace:!1}):Fe,fm(M.context)),L.addObserver(B=>{if(B._tag==="Failure")return T(B)})}),T=>(c.delete(F),ome(Qc(L),x(F,Array.from(T),j))))}),m=ms(function*(_,C,E,P,A,j){if(f)return yield*LP;const R=i?void 0:yield*Sme(`${n}.${_._tag}`,{attributes:t.spanAttributes}),M=WP(),F=o(),$=_y(M.context,sD);yield*kge($,T=>c.has(F)?(c.delete(F),x(F,B4(T)?Array.from(mge(T.cause)):[],j)):jt);const L=yield*uve(A);return c.set(F,{_tag:"Queue",rpc:_,queue:L,scope:$,context:j}),yield*C(T=>t.onFromClient({message:T,context:j,discard:!1}),{_tag:"Request",id:F,tag:_._tag,payload:E,...R?{traceId:R.traceId,spanId:R.spanId,sampled:R.sampled}:{},headers:zD(M.getRef(iF),P)}).pipe(R?gD(R,{captureStackTrace:!1}):Fe,pd(T=>Jc(L,T)),SE,Pme($,{startImmediately:!0})),L}),v=_=>{const C=[];for(const E of _.middlewares.values()){const P=a.mapUnsafe.get(`${E.key}/Client`);P&&C.push(P)}return C.length===0?(E,P)=>E(P):function E(P,A,j=C.length-1){return j===-1?P(A):C[j]({rpc:_,request:A,next(R){return E(P,R,j-1)}})}},x=(_,C,E)=>hD(P=>{const A=WP();t.onFromClient({message:{_tag:"Interrupt",requestId:_,interruptors:C},context:E,discard:!1}).pipe(fme(1e3),fm(A.context)).addObserver(()=>{P(jt)})}),b=_=>{switch(_._tag){case"Chunk":{const C=_.requestId,E=c.get(C);return!E||E._tag!=="Queue"?jt:lve(E.queue,_.values).pipe(r?Gr(()=>t.onFromClient({message:{_tag:"Ack",requestId:_.requestId},context:E.context,discard:!1})):Fe,pd(P=>Jc(E.queue,P)))}case"Exit":{const C=_.requestId,E=c.get(C);return E?(c.delete(C),E._tag==="Effect"?(E.resume(_.exit),jt):_.exit._tag==="Success"?kD(E.queue):Jc(E.queue,_.exit.cause)):jt}case"Defect":return h(xge(_.defect));case"ClientEnd":return jt}};let O;if(t.flatten){const _=new Map;O=function(E,P,A){let j=_.get(E);return j||(j=d(e.requests.get(E)),_.set(E,j)),j(P,A)}}else O={},e.requests.forEach(_=>{O[_._tag]=d(_)});return{client:O,write:b}});let Oxe=0;const Cxe=ms(function*(e,t){const n=Oxe++,{run:r,send:i,supportsAck:o,supportsTransferables:a}=yield*Hy,u=new Map,{client:c,write:f}=yield*Pxe(e,{...t,supportsAck:o,onFromClient({message:h}){switch(h._tag){case"Request":{const d=e.requests.get(h.tag),g=a?Y0e():void 0,m=WP(),v={rpc:d,context:g?Aa(m.context,d6,g):m.context,schemas:Exe(d)};return u.set(h.id,v),v.schemas.encodePayload(h.payload).pipe(gs(v.context),zp,Gr(x=>i(n,{...h,id:String(h.id),payload:x,headers:Object.entries(h.headers)},g&&g.readUnsafe())))}case"Ack":return u.get(h.requestId)?i(n,{_tag:"Ack",requestId:String(h.requestId)}):jt;case"Interrupt":return u.get(h.requestId)?(u.delete(h.requestId),i(n,{_tag:"Interrupt",requestId:String(h.requestId)})):jt;case"Eof":return jt}}});return yield*r(n,h=>{switch(h._tag){case"Chunk":{const d=Pp(h.requestId),g=u.get(d);return!g||Ds(g.schemas.decodeChunk)?jt:g.schemas.decodeChunk.value(h.values).pipe(gs(g.context),zp,Gr(m=>f({_tag:"Chunk",clientId:0,requestId:Pp(h.requestId),values:m})),bme(m=>f({_tag:"Exit",clientId:0,requestId:Pp(h.requestId),exit:cf(m)})))}case"Exit":{const d=Pp(h.requestId),g=u.get(d);return g?(u.delete(d),g.schemas.decodeExit(h.exit).pipe(gs(g.context),zp,pme({onSuccess:m=>f({_tag:"Exit",clientId:0,requestId:d,exit:m}),onFailure:m=>f({_tag:"Exit",clientId:0,requestId:d,exit:cf(m)})}))):jt}case"Defect":return f({_tag:"Defect",clientId:0,defect:Txe(h.defect)});case"ClientProtocolError":{const d=Ld(h.error);return Q4(u.keys(),g=>f({_tag:"Exit",clientId:0,requestId:g,exit:d}))}default:return jt}}).pipe(pd(Rme),SE,_E),c}),rF=new WeakMap,Exe=e=>{let t=rF.get(e);if(t!==void 0)return t;const n=u6(e.successSchema);return t={decodeChunk:HC(n,r=>TD(x1(Uve(r.success)))),encodePayload:Fve(x1(e.payloadSchema)),decodeExit:TD(x1(A0e(e)))},rF.set(e,t),t},iF=Pt("effect/rpc/RpcClient/CurrentHeaders",{defaultValue:()=>HE});class Hy extends Xr()("effect/rpc/RpcClient/Protocol"){}Q(Hy,"make",Sxe);const kxe=e=>Hy.make(ms(function*(t,n){const r=yield*KE,i=yield*JE,o=yield*mme(iO),a=new Map,u=yield*r.writer;let c=i.makeUnsafe();const f=yield*jxe(u(c.encode(nxe)));let h;const d=vo(()=>(h=void 0,ga(o)?o.value.onConnect:jt)),g=m=>Q4(n,v=>t(v,m));return yield*vo(()=>(c=i.makeUnsafe(),f.reset(),r.runRaw(m=>{try{const v=c.decode(m);if(v.length===0)return;let x=0;return J4({while:()=>x<v.length,body:()=>{const b=v[x++];if(b._tag==="Pong")return f.onPong(),jt;if("requestId"in b){const O=a.get(b.requestId);if(O!==void 0)return b._tag==="Exit"&&a.delete(b.requestId),t(O,b)}return g(b)},step:kd})}catch(v){return g({_tag:"ClientProtocolError",error:new UD({reason:new JP({message:"Error decoding message",cause:v})})})}},{onOpen:d}).pipe(Z4(Gr(f.timeout,()=>vt(new Fu({reason:new bm({kind:"Timeout",cause:new Error("ping timeout")})}))))))).pipe(Gr(()=>vt(new Fu({reason:new wm({code:1e3})}))),ga(o)?n5(o.value.onDisconnect):Fe,ume(m=>{const v=Nd(m),x=Gfe(v);return x&&v.success.reason._tag==="SocketOpenError"?jt:(h=new UD({reason:x?v.success.reason:new JP({message:"Unknown socket error",cause:D4(m)})}),g({_tag:"ClientProtocolError",error:h}))}),lme((e==null?void 0:e.retryPolicy)??Axe),Ime({module:"RpcClient",method:"makeProtocolSocket"}),_E),{send(m,v){if(h)return vt(h);v._tag==="Request"&&a.set(v.id,m);const x=c.encode(v);return x===void 0?jt:zp(u(x))},supportsAck:!0,supportsTransferables:!1}})),Axe=K4(500,1.5).pipe(G4(bE(5e3))),jxe=ms(function*(e){let t=!0;const n=z5(),r=()=>{t=!0,n.closeUnsafe()},i=()=>{t=!0};return yield*vo(()=>t?(t=!1,e):n.open).pipe(hme("5 seconds"),cme,i5,SE,_E),{timeout:n.await,reset:r,onPong:i}});class iO extends Xr()("effect/rpc/RpcClient/ConnectionHooks"){}const Txe=Lve(wi),Rxe={add(...e){const t=new Map(this.requests);for(const n of e)t.set(n._tag,n);return Zi({requests:t,annotations:this.annotations})},merge(...e){const t=new Map(this.requests),n=new Map(this.annotations.mapUnsafe);for(const r of e){for(const[i,o]of r.requests)t.set(i,o);for(const[i,o]of r.annotations.mapUnsafe)n.set(i,o)}return Zi({requests:t,annotations:ca(n)})},omit(...e){const t=new Map(this.requests);for(const n of e)t.delete(n);return Zi({requests:t,annotations:this.annotations})},middleware(e){const t=new Map;for(const[n,r]of this.requests)t.set(n,r.middleware(e));return Zi({requests:t,annotations:this.annotations})},toHandlers(e){const t=this;return NP(function*(){const n=yield*cm(),r=Du(e)?yield*e:e,i=new Map;for(const[o,a]of Object.entries(r)){const u=t.requests.get(o);i.set(u.key,{tag:u._tag,handler:a,context:n})}return ca(i)})},prefix(e){const t=new Map;for(const n of this.requests.values()){const r=n.prefix(e);t.set(r._tag,r)}return Zi({requests:t,annotations:this.annotations})},toLayer(e){return MP(this.toHandlers(e))},of:Fe,toLayerHandler(e,t){const n=this;return MP(NP(function*(){const r=yield*cm(),i=Du(t)?yield*t:t,o=new Map,a=n.requests.get(e);return o.set(a.key,{handler:i,context:r}),ca(o)}))},accessHandler(e){return e5(t=>{const n=this.requests.get(e),{handler:r,context:i}=t.mapUnsafe.get(n.key);return Mt((o,a)=>{a.rpc=n;const u=r(o,a),c=T0e(u)?u.value:u;return Du(c)?gme(c,i):p0e(c,i)})})},annotate(e,t){return Zi({requests:this.requests,annotations:Aa(this.annotations,e,t)})},annotateRpcs(e,t){return this.annotateRpcsMerge(vl(e,t))},annotateMerge(e){return Zi({requests:this.requests,annotations:xl(this.annotations,e)})},annotateRpcsMerge(e){const t=new Map;for(const[n,r]of this.requests)t.set(n,r.annotateMerge(xl(e,r.annotations)));return Zi({requests:t,annotations:this.annotations})}},Zi=e=>Object.assign(function(){},Rxe,{requests:e.requests,annotations:e.annotations}),Ixe=(...e)=>Zi({requests:new Map(e.map(t=>[t._tag,t])),annotations:gi()}),Mxe="/ws",Fr={getConfig:"tokmon.getConfig",setConfig:"tokmon.setConfig",refresh:"tokmon.refresh",browseFs:"tokmon.browseFs",snapshot:"tokmon.snapshot",config:"tokmon.config"},$xe=Vy(["all","summary","table","billing","peak"]),ZE=()=>G5,Nxe=ZE(),ek=ZE(),Lxe=Nn({name:ar,path:ar,dir:qve}),Dxe=Nn({path:ar,parent:Vve(ar),entries:XP(Lxe)}),Fxe=ZE(),tk=Nn({}),Bxe=Bl(Fr.getConfig,{payload:tk,success:ek}),zxe=Bl(Fr.setConfig,{payload:Nxe,success:ek}),qxe=Bl(Fr.refresh,{payload:Nn({scope:$xe}),success:vm}),Uxe=Bl(Fr.browseFs,{payload:Nn({path:ar}),success:Dxe}),Vxe=Bl(Fr.snapshot,{payload:tk,success:Fxe,stream:!0}),Wxe=Bl(Fr.config,{payload:tk,success:ek,stream:!0}),Hxe=Ixe(Bxe,zxe,qxe,Uxe,Vxe,Wxe);class Ep extends Xr()("tokmon/client/DaemonRpcClient/TokmonRpcClient"){}const Gxe=new Function("specifier","return import(specifier)");function Kxe(e,t){const n=typeof window>"u"?void 0:window.location.origin,r=new URL(e,n);if(r.protocol==="http:"?r.protocol="ws:":r.protocol==="https:"&&(r.protocol="wss:"),r.protocol!=="ws:"&&r.protocol!=="wss:")throw new Error(`unsupported daemon RPC protocol: ${r.protocol}`);return r.pathname=Mxe,t&&r.searchParams.set("wsToken",t),r.toString()}function Xxe(e){return e==="node"?!0:e==="browser"?!1:typeof window>"u"}async function Yxe(e,t){return Xxe(t)?(await Gxe("@effect/platform-node/NodeSocket")).layerWebSocket(e):X0e(e).pipe($P(H0e))}function Qxe(e){const t=e.reconnectBaseDelayMs??250,n=K4(cd(t),1.5).pipe(G4(bE(cd(2500))));return typeof e.reconnectAttempts=="number"?n.pipe(Uge(Hge(e.reconnectAttempts))):n}function Jxe(e,t={}){const n=Kxe(e,t.wsToken),r=new Set;let i=null,o=null,a=!1;const u=(m,v)=>{var x;(x=t.onConn)==null||x.call(t,m,v)},c=m=>{const v=m??i;(m===void 0||m===i)&&(i=null),o=null,v&&v.runtime.dispose().catch(()=>{})},f=async()=>{const m=await Yxe(n,t.transport),v=yE(iO,iO.of({onConnect:zr(()=>{u("live")}),onDisconnect:zr(()=>{a||u("reconnecting")})}));return IP(Hy,kxe({retryPolicy:Qxe(t)})).pipe($P(V4(m,wxe,v)))},h=async()=>{if(a)throw new Error("daemon RPC client is closed");return i||o||(u("connecting"),o=(async()=>{let m;try{const v=await f(),x=IP(Ep,Cxe(Hxe)).pipe($P(v));if(m=O0e(x),await m.runPromise(Ep.asEffect()),a)throw await m.dispose(),new Error("daemon RPC client is closed");return i={runtime:m},i}catch(v){throw o=null,await(m==null?void 0:m.dispose().catch(()=>{})),a||u("error",v),v}})(),o)},d=async m=>{const v=await h();try{return await v.runtime.runPromise(Ep.use(x=>m(x)))}catch(x){throw a||(c(v),u("error",x)),x}},g=(m,v)=>{if(a)return()=>{};let x=null,b=!1,O=null;const _=()=>{if(!x)return;const P=x;x=null,r.delete(P),((i==null?void 0:i.runtime.runPromise(Qc(P)))??df(Qc(P))).catch(()=>{})},C=()=>{var P;a||b||O||(O=setTimeout(()=>{O=null,E()},t.reconnectBaseDelayMs??250),(P=O.unref)==null||P.call(O))},E=()=>{(async()=>{try{const P=await h();if(a||b)return;x=P.runtime.runFork(Ep.use(A=>m(A).pipe(g0e(j=>zr(()=>{try{v(j)}catch{}})))).pipe(pd(A=>zr(()=>{!a&&!b&&(c(P),u("error",D4(A)),C())})))),r.add(x),x.addObserver(()=>{x&&r.delete(x)})}catch(P){!a&&!b&&(c(),u("error",P),C())}})()};return E(),()=>{b=!0,O&&(clearTimeout(O),O=null),_()}};return{getConfig:()=>d(m=>m[Fr.getConfig]({})),setConfig:m=>d(v=>v[Fr.setConfig](m)),refresh:(m="all")=>d(v=>v[Fr.refresh]({scope:m})),browseFs:m=>d(v=>v[Fr.browseFs]({path:m})),subscribeSnapshot:m=>g(v=>v[Fr.snapshot]({}),m),subscribeConfig:m=>g(v=>v[Fr.config]({}),m),async close(){if(a)return;a=!0,u("closed");const m=[...r];r.clear();const v=i??await(o==null?void 0:o.catch(()=>null))??null;await Promise.all(m.map(x=>((v==null?void 0:v.runtime.runPromise(Qc(x)))??df(Qc(x))).catch(()=>{}))),i=null,o=null,v&&await v.runtime.dispose().catch(()=>{})}}}let C1=null;const oO=new Set;function Zxe(e){if(e!=="closed")for(const t of oO)t(e)}function Ud(){return C1||(C1=Jxe(window.location.origin,{transport:"browser",onConn:Zxe})),C1}function ebe(e){return oO.add(e),()=>{oO.delete(e)}}async function tbe(){return SO(await Ud().getConfig()).config}async function nbe(e){return SO(await Ud().setConfig(e)).config}async function rbe(e){return Ud().browseFs(e)}function _6(e){return Ud().subscribeConfig(t=>{e(SO(t).config)})}const Tt="focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",oF='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])';function P6(e,{active:t,onEscape:n,initialFocusRef:r}){D.useEffect(()=>{var c,f;if(!t)return;const i=document.activeElement,o=e.current,a=o==null?void 0:o.querySelector(oF);(f=(c=(r==null?void 0:r.current)??a??o)==null?void 0:c.focus)==null||f.call(c);const u=h=>{if(h.key==="Escape"){h.stopPropagation(),n();return}if(h.key!=="Tab"||!e.current)return;const d=e.current.querySelectorAll(oF),g=Array.from(d).filter(x=>x.offsetParent!==null||x===document.activeElement);if(g.length===0)return;const m=g[0],v=g[g.length-1];h.shiftKey&&document.activeElement===m?(h.preventDefault(),v.focus()):!h.shiftKey&&document.activeElement===v&&(h.preventDefault(),m.focus())};return document.addEventListener("keydown",u),()=>{var h;document.removeEventListener("keydown",u),(h=i==null?void 0:i.focus)==null||h.call(i)}},[t])}function aF(e,t={}){return{mode:"add",editingId:null,providerId:t.providerId??wf[0],name:t.name??"",homeDir:t.homeDir??"~",color:t.color??yG(e.accounts)}}function ibe(e){return{mode:"edit",editingId:e.id,providerId:e.providerId,name:e.name,homeDir:e.homeDir,color:e.color||us[e.providerId].color}}function obe(e,t){const n=e.mode==="edit"?t.filter(r=>r.id!==e.editingId):t;return e.mode==="edit"?e.editingId??"":w3(e.name.trim()||"account",n)}function abe(e,t){const n=e.name.trim(),r=e.homeDir.trim()||"~";return n?e.mode==="add"?{ok:!0,account:{id:w3(n,t),providerId:e.providerId,name:n,homeDir:r,color:e.color},mode:"add",editingId:null}:{ok:!0,account:{id:e.editingId,providerId:e.providerId,name:n,homeDir:r,color:e.color},mode:"edit",editingId:e.editingId}:{ok:!1,error:"Name required"}}function nk({title:e,right:t,children:n}){return w.jsxs("section",{className:"mb-6 last:mb-0",children:[w.jsxs("div",{className:"mb-2.5 flex items-center gap-2 border-b border-line pb-1.5",children:[w.jsx("h3",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:e}),t&&w.jsx("div",{className:"ml-auto",children:t})]}),n]})}function Vo({label:e,hint:t,children:n}){return w.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsx("div",{className:"text-sm text-fg",children:e}),t&&w.jsx("div",{className:"text-[11px] text-fg-faint",children:t})]}),w.jsx("div",{className:"shrink-0",children:n})]})}function kp({label:e,hint:t,children:n}){return w.jsxs("div",{children:[w.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:e}),n,t&&w.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:t})]})}function sF({value:e,min:t,unit:n,onChange:r}){const i=c=>r(Math.max(t,Math.round(c))),[o,a]=D.useState(null),u=()=>{if(o===null)return;const c=Number(o);i(Number.isFinite(c)&&o.trim()!==""?c:t),a(null)};return w.jsxs("div",{className:"flex items-center overflow-hidden rounded border border-line",children:[w.jsx("button",{type:"button","aria-label":"decrease",onClick:()=>i(e-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${Tt}`,children:"−"}),w.jsx("input",{type:"number",inputMode:"numeric",min:t,value:o??e,onChange:c=>{const f=c.target.value;a(f);const h=Number(f);f.trim()!==""&&Number.isFinite(h)&&h>=t&&i(h)},onBlur:u,"aria-label":`value (${n})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${Tt} [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),w.jsx("span",{className:"px-1.5 text-[10px] text-fg-faint",children:n}),w.jsx("button",{type:"button","aria-label":"increase",onClick:()=>i(e+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${Tt}`,children:"+"})]})}function qc({label:e,onClick:t,disabled:n,danger:r,children:i}){return w.jsx("button",{type:"button","aria-label":e,title:e,disabled:n,onClick:t,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${Tt} ${r?"hover:bg-warning/15 hover:text-warning":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:i})}function sbe({draft:e,patch:t}){return w.jsxs(nk,{title:"General",children:[w.jsx(Vo,{label:"Refresh interval",hint:"dashboard poll, seconds",children:w.jsx(sF,{value:e.interval,min:1,unit:"s",onChange:n=>t(r=>({...r,interval:n}))})}),w.jsx(Vo,{label:"Billing poll",hint:"billing refresh, minutes",children:w.jsx(sF,{value:e.billingInterval,min:1,unit:"m",onChange:n=>t(r=>({...r,billingInterval:n}))})}),w.jsx(Vo,{label:"Clear screen",hint:"redraw on each refresh",children:w.jsx(er,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:e.clearScreen?"on":"off",onChange:n=>t(r=>({...r,clearScreen:n==="on"}))})}),w.jsx(Vo,{label:"Privacy mode",hint:"hide email addresses by default",children:w.jsx(er,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:e.privacyMode?"on":"off",onChange:n=>t(r=>({...r,privacyMode:n==="on"}))})}),w.jsx(Vo,{label:"Timezone",hint:"IANA name · empty = System",children:w.jsx(ube,{value:e.timezone,onChange:n=>t(r=>({...r,timezone:n}))})}),w.jsx(Vo,{label:"Dashboard",hint:"grid shows all · single cycles",children:w.jsx(er,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:e.dashboardLayout,onChange:n=>t(r=>({...r,dashboardLayout:n}))})}),w.jsx(Vo,{label:"Default focus",hint:"on open",children:w.jsx(er,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:e.defaultFocus,onChange:n=>t(r=>({...r,defaultFocus:n}))})}),w.jsx(Vo,{label:"ASCII mode",hint:"glyph fallback",children:w.jsx(er,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:e.ascii,onChange:n=>t(r=>({...r,ascii:n}))})})]})}function ube({value:e,onChange:t}){const[n,r]=D.useState(e??""),[i,o]=D.useState(!1);D.useEffect(()=>{r(e??""),o(!1)},[e]);const a=u=>{const c=_O(u);r(c);const f=c.trim();if(!f){o(!1),t(null);return}b3(f)?(o(!1),t(f)):o(!0)};return w.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[w.jsx("input",{type:"text",value:n,placeholder:"System",spellCheck:!1,"aria-invalid":i,onChange:u=>a(u.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${Tt} ${i?"border-warning":"border-line"}`}),i&&w.jsx("span",{className:"text-[10px] text-warning",children:"invalid timezone"})]})}function lbe({draft:e,patch:t}){const n=(r,i)=>t(o=>({...o,knownProviders:o.knownProviders.includes(r)?o.knownProviders:[...o.knownProviders,r],disabledProviders:i?o.disabledProviders.filter(a=>a!==r):Array.from(new Set([...o.disabledProviders,r]))}));return w.jsx(nk,{title:"Providers",children:w.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:wf.map(r=>{const i=!e.disabledProviders.includes(r),o=us[r];return w.jsxs("button",{type:"button",role:"switch","aria-checked":i,onClick:()=>n(r,!i),className:`flex items-center gap-2.5 rounded border px-3 py-2 text-left text-xs transition ${Tt} ${i?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:border-line-2"}`,children:[w.jsx("span",{className:"inline-flex size-4 shrink-0 items-center justify-center rounded-sm border",style:{borderColor:i?ls(o.color):"var(--color-line-2)",background:i?ls(o.color):"transparent"},children:i&&w.jsx(zu,{className:"size-3 text-bg-0"})}),w.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:ls(o.color)},"aria-hidden":!0}),w.jsx("span",{className:`font-medium ${i?"text-fg":"text-fg-faint"}`,children:o.name}),w.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-wide text-fg-faint",children:i?"tracking":"off"})]},r)})})})}function cbe(e,t){return t?t.accounts.find(n=>n.id===e.id)??null:null}function fbe({draft:e,patch:t,snapshot:n,onEdit:r,onConfigure:i,onAdd:o}){const a=pG(e,void 0,(n==null?void 0:n.accounts)??void 0),u=h=>t(d=>({...d,activeAccountId:h})),c=h=>t(d=>({...d,accounts:d.accounts.filter(g=>g.id!==h),activeAccountId:d.activeAccountId===h?null:d.activeAccountId})),f=(h,d)=>t(g=>{const m=[...g.accounts],v=h+d;return v<0||v>=m.length?g:([m[h],m[v]]=[m[v],m[h]],{...g,accounts:m})});return w.jsx(nk,{title:"Accounts",right:w.jsxs("button",{type:"button",onClick:o,className:`flex items-center gap-1 rounded border border-accent/60 bg-bg-1 px-2 py-1 text-[11px] text-accent transition hover:bg-bg-2 ${Tt}`,children:[w.jsx(HG,{className:"size-3"})," Add account"]}),children:a.length===0?w.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"None configured — enabled providers track automatically."}):w.jsx("ul",{className:"flex flex-col gap-1.5",role:"radiogroup","aria-label":"Active account",children:a.map(h=>{var _;const d=us[h.providerId],g=cbe(h,n),m=(g==null?void 0:g.email)||(g==null?void 0:g.displayName)||h.name||d.name,v=(g==null?void 0:g.plan)??((_=g==null?void 0:g.billing)==null?void 0:_.plan)??null,x=ls(h.color||d.color),b=h.id===e.activeAccountId,O=h.source==="configured";return w.jsxs("li",{className:"flex items-center gap-2.5 rounded border border-line bg-bg-2/60 px-2.5 py-2",children:[w.jsx("button",{type:"button",role:"radio","aria-checked":b,"aria-label":`Set ${h.name} active`,title:b?"Active account (click to clear)":"Set active",onClick:()=>u(b?null:h.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${Tt}`,style:{borderColor:x},children:b&&w.jsx("span",{className:"size-2 rounded-full",style:{background:x}})}),w.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:x},"aria-hidden":!0}),w.jsxs("div",{className:"min-w-0 flex-1",children:[w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx(Zp,{value:m,privacyMode:e.privacyMode,className:"truncate text-sm text-fg-bright"}),w.jsx("span",{className:"shrink-0 rounded bg-bg-3 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-dim",children:d.name}),v&&w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:v}),w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-faint",children:h.source==="auto"?"auto":"configured"})]}),w.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:h.homeDir})]}),w.jsx("div",{className:"flex shrink-0 items-center gap-0.5",children:O&&h.explicitIndex!==void 0?w.jsxs(w.Fragment,{children:[w.jsx(qc,{label:"Move up",disabled:h.explicitIndex===0,onClick:()=>f(h.explicitIndex,-1),children:w.jsx(C3,{className:"size-3.5"})}),w.jsx(qc,{label:"Move down",disabled:h.explicitIndex===e.accounts.length-1,onClick:()=>f(h.explicitIndex,1),children:w.jsx(CO,{className:"size-3.5"})}),w.jsx(qc,{label:"Edit account",onClick:()=>r(h),children:w.jsx(FT,{className:"size-3.5"})}),w.jsx(qc,{label:"Delete account",danger:!0,onClick:()=>c(h.id),children:w.jsx(GG,{className:"size-3.5"})})]}):w.jsx(qc,{label:"Configure account",onClick:()=>i(h),children:w.jsx(FT,{className:"size-3.5"})})})]},`${h.source}:${h.id}`)})})})}function dbe(e){const t=(e??"").trim();return t.length>0?t:"~"}function E1(e){const t=(e??"").trim();return t.length>0?t:"~"}function hbe(e){const t=[];e.parent!==null&&t.push({kind:"parent",key:"..",label:"..",path:e.parent});for(const n of[...e.entries].filter(r=>r.dir).sort((r,i)=>r.name.localeCompare(i.name)))t.push({kind:"entry",key:n.path,label:n.name,path:n.path});return t}function pbe({editor:e,accounts:t,onChange:n,onCancel:r,onSubmit:i}){const o=D.useRef(null),a=D.useRef(null),[u,c]=D.useState(null),f=ls(e.color);P6(o,{active:!0,onEscape:r,initialFocusRef:a});const h=obe(e,t),d=()=>{const g=abe(e,t);if(!g.ok){c(g.error);return}i(g.account,g.mode,g.editingId)};return w.jsx("div",{className:"dialog-fade fixed inset-0 z-[70] flex items-start justify-center overflow-y-auto bg-bg-0/60 p-4 backdrop-blur-sm",onMouseDown:g=>{g.target===g.currentTarget&&r()},role:"dialog","aria-modal":"true","aria-label":e.mode==="add"?"New account":"Edit account",children:w.jsxs("div",{ref:o,tabIndex:-1,className:"dialog-pop my-8 w-full max-w-[460px] overflow-hidden rounded-md border-l-2 border border-line-2 bg-bg-1 focus:outline-none",style:{borderLeftColor:f},children:[w.jsxs("div",{className:"flex items-center gap-2 border-b border-line px-4 py-3",children:[w.jsx("span",{className:"size-2.5 rounded-full",style:{background:f},"aria-hidden":!0}),w.jsx("span",{className:"font-display text-xs uppercase tracking-wider text-fg-bright",children:e.mode==="add"?"New account":"Edit account"})]}),w.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[w.jsx(kp,{label:"Provider",hint:"which tool this account tracks",children:w.jsx("div",{className:"flex flex-wrap gap-1.5",children:wf.map(g=>{const m=g===e.providerId,v=us[g];return w.jsxs("button",{type:"button",onClick:()=>n({...e,providerId:g}),"aria-pressed":m,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${Tt} ${m?"border-line-2 bg-bg-3 text-fg-bright":"border-line text-fg-dim hover:text-fg"}`,children:[w.jsx("span",{className:"size-2 rounded-full",style:{background:ls(v.color)},"aria-hidden":!0}),v.name]},g)})})}),w.jsx(kp,{label:"Name",hint:"display name for this account",children:w.jsx("input",{ref:a,type:"text",value:e.name,placeholder:"e.g. Work, Personal",spellCheck:!1,onChange:g=>{c(null),n({...e,name:_O(g.target.value)})},onKeyDown:g=>{g.key==="Enter"&&d()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${Tt}`})}),w.jsx(kp,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:w.jsx(gbe,{value:e.homeDir,onChange:g=>n({...e,homeDir:g}),onEnter:d})}),w.jsx(kp,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:w.jsx("div",{className:"flex flex-wrap gap-1.5",children:cG.map(g=>{const m=g===e.color;return w.jsx("button",{type:"button","aria-label":g,"aria-pressed":m,title:g,onClick:()=>n({...e,color:g}),className:`size-6 rounded-full border-2 transition ${Tt} ${m?"scale-110":"border-transparent hover:scale-105"}`,style:{background:ls(g),borderColor:m?"var(--color-fg-bright)":"transparent"}},g)})})}),w.jsxs("div",{className:"flex items-center gap-2 rounded border border-line bg-bg-2/50 px-2.5 py-1.5 text-xs",children:[w.jsx("span",{className:"text-fg-faint",children:"id"}),w.jsx("span",{className:"font-mono text-fg",style:{color:f},children:h||"account"}),w.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:e.mode==="add"?"auto-generated from name":"fixed"})]}),u&&w.jsx("p",{className:"text-xs text-warning",children:u})]}),w.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[w.jsx("button",{type:"button",onClick:r,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${Tt}`,children:"cancel"}),w.jsxs("button",{type:"button",onClick:d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," ",e.mode==="add"?"Add account":"Save account"]})]})]})})}function gbe({value:e,onChange:t,onEnter:n}){const[r,i]=D.useState(!1),[o,a]=D.useState(null),[u,c]=D.useState("~"),[f,h]=D.useState(!1),[d,g]=D.useState(null),m=D.useRef(0),v=D.useCallback(async A=>{const j=++m.current,R=dbe(A);c(R),h(!0),g(null);try{const M=await rbe(R);if(j!==m.current)return;a(M)}catch(M){if(j!==m.current)return;a(null),g(M instanceof Error?M.message:"cannot read folder")}finally{j===m.current&&h(!1)}},[]);D.useEffect(()=>()=>{m.current++},[]);const x=()=>{i(!0),v(e)},b=()=>{m.current++,i(!1),h(!1),g(null)},O=A=>{f||v(A)},_=()=>{!o||f||(t(E1(o.path)),b())},C=o?hbe(o):[],E=C.filter(A=>A.kind==="entry"),P=E1((o==null?void 0:o.path)??u);return w.jsxs("div",{className:"relative",children:[w.jsxs("div",{className:"flex overflow-hidden rounded border border-line bg-bg-2",children:[w.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2.5",children:[w.jsx(ax,{className:"size-4 shrink-0 text-fg-faint"}),w.jsx("input",{type:"text",value:e,placeholder:"~",spellCheck:!1,onChange:A=>{b(),t(_O(A.target.value))},onKeyDown:A=>{A.key==="Enter"&&n()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${Tt}`})]}),w.jsxs("button",{type:"button",onClick:x,disabled:f,className:`flex shrink-0 items-center gap-1 border-l border-line bg-bg-1 px-2.5 py-1.5 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${Tt}`,children:[w.jsx(CO,{className:"size-3.5"})," Browse"]})]}),r&&w.jsxs("div",{className:"mt-2 overflow-hidden rounded border border-line-2 bg-bg-1 shadow-[0_18px_60px_rgba(0,0,0,0.35)]",children:[w.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-2 px-2.5 py-2",children:[w.jsx(ax,{className:"size-4 shrink-0 text-accent"}),w.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg-bright",title:P,children:P}),f&&w.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),w.jsx("button",{type:"button",onClick:b,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${Tt}`,children:w.jsx(qu,{className:"size-3.5"})})]}),d?w.jsxs("div",{className:"px-2.5 py-3",children:[w.jsxs("div",{className:"text-xs text-warning",children:["can't read ",E1(u)]}),w.jsx("button",{type:"button",onClick:()=>{f||v(u)},disabled:f,className:`mt-2 rounded border border-line bg-bg-2 px-2 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg disabled:opacity-50 ${Tt}`,children:"retry"})]}):w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[C.map(A=>w.jsxs("button",{type:"button",onClick:()=>O(A.path),disabled:f,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${Tt} ${A.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[A.kind==="parent"?w.jsx(C3,{className:"size-3.5 shrink-0"}):w.jsx(ax,{className:"size-3.5 shrink-0 text-fg-faint"}),w.jsx("span",{className:"min-w-0 truncate font-mono",children:A.label})]},A.key)),!f&&E.length===0&&w.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),f&&!o&&w.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"loading folders..."})]}),w.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-line px-2.5 py-2",children:w.jsxs("button",{type:"button",onClick:_,disabled:!o||f,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-2.5 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," Select this folder"]})})]})]})]})}const mbe=[{value:"general",label:"General"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function ybe({onClose:e,snapshot:t}){const n=D.useRef(null),[r,i]=D.useState(null),[o,a]=D.useState(null),[u,c]=D.useState(!1),[f,h]=D.useState(null),[d,g]=D.useState(!1),[m,v]=D.useState(null),[x,b]=D.useState("general");D.useEffect(()=>{let C=!0;return tbe().then(E=>{C&&i(E)}).catch(E=>{C&&a(E instanceof Error?E.message:"load failed")}),()=>{C=!1}},[]),D.useEffect(()=>{if(!d)return _6(C=>{d||i(C)})},[d]),P6(n,{active:!m,onEscape:e}),D.useEffect(()=>{const C=n.current;C&&(m?C.setAttribute("inert",""):C.removeAttribute("inert"))},[m]);const O=C=>{g(!0),h(null),i(E=>E&&C(E))},_=async()=>{if(r){c(!0),h(null);try{const C=await nbe(r);i(C),g(!1),e()}catch(C){h(C instanceof Error?C.message:"save failed")}finally{c(!1)}}};return w.jsxs("div",{className:"dialog-fade fixed inset-0 z-[60] flex items-start justify-center overflow-y-auto bg-bg-0/70 p-4 backdrop-blur-sm",onMouseDown:C=>{C.target===C.currentTarget&&!m&&e()},role:"dialog","aria-modal":"true","aria-label":"Settings",children:[w.jsxs("div",{ref:n,tabIndex:-1,className:"dialog-pop relative my-6 flex w-full max-w-[720px] flex-col overflow-hidden rounded-md border border-line-2 bg-bg-1 focus:outline-none",children:[w.jsx("div",{className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim",children:"settings"}),w.jsx("button",{type:"button",onClick:e,"aria-label":"Close",className:`absolute right-2 top-2 z-10 rounded p-1 text-fg-faint transition hover:text-fg ${Tt}`,children:w.jsx(qu,{className:"size-4"})}),w.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-5 pb-4 pt-9",children:o?w.jsx("div",{className:"rounded border border-warning/50 bg-bg-2 p-4 text-sm text-warning",children:o}):r?w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-line pb-3",children:w.jsx(er,{size:"xs",ariaLabel:"settings section",options:mbe,value:x,onChange:b,containerClassName:"flex items-center overflow-hidden rounded border border-line bg-bg-1",btnClassName:"px-3 py-1.5 text-[11px] transition"})}),x==="general"&&w.jsx(sbe,{draft:r,patch:O}),x==="providers"&&w.jsx(lbe,{draft:r,patch:O}),x==="accounts"&&w.jsx(fbe,{draft:r,patch:O,snapshot:t,onEdit:C=>v(ibe(C)),onConfigure:C=>v(aF(r,{providerId:C.providerId,name:C.name,homeDir:C.homeDir,color:C.color})),onAdd:()=>v(aF(r))})]}):w.jsx("div",{className:"py-10 text-center text-sm text-fg-dim",children:"loading config…"})}),w.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-line px-5 py-3",children:[f&&w.jsx("span",{className:"mr-auto text-xs text-warning",children:f}),d&&!f&&w.jsx("span",{className:"mr-auto text-xs text-fg-faint",children:"unsaved changes"}),w.jsx("button",{type:"button",onClick:e,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${Tt}`,children:"cancel"}),w.jsxs("button",{type:"button",onClick:_,disabled:!r||u||!d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${Tt}`,children:[w.jsx(zu,{className:"size-3.5"})," ",u?"saving…":"save"]})]})]}),m&&r&&w.jsx(pbe,{editor:m,accounts:r.accounts,onChange:v,onCancel:()=>v(null),onSubmit:(C,E,P)=>{O(A=>E==="add"?{...A,accounts:[...A.accounts,C]}:{...A,accounts:A.accounts.map(j=>j.id===P?C:j)}),v(null)}})]})}const vbe="modulepreload",xbe=function(e,t){return new URL(e,t).href},uF={},O6=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let a=function(h){return Promise.all(h.map(d=>Promise.resolve(d).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};const u=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),f=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));i=a(n.map(h=>{if(h=xbe(h,r),h in uF)return;uF[h]=!0;const d=h.endsWith(".css"),g=d?'[rel="stylesheet"]':"";if(!!r)for(let x=u.length-1;x>=0;x--){const b=u[x];if(b.href===h&&(!d||b.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${h}"]${g}`))return;const v=document.createElement("link");if(v.rel=d?"stylesheet":vbe,d||(v.as="script"),v.crossOrigin="",v.href=h,f&&v.setAttribute("nonce",f),document.head.appendChild(v),d)return new Promise((x,b)=>{v.addEventListener("load",x),v.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${h}`)))})}))}function o(a){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=a,window.dispatchEvent(u),!u.defaultPrevented)throw a}return i.then(a=>{for(const u of a||[])u.status==="rejected"&&o(u.reason);return t().catch(o)})};function Gy({title:e,titleTag:t,right:n,captureName:r,children:i,className:o="",bodyClassName:a=""}){const u=D.useRef(null);return w.jsxs("section",{ref:u,className:`group relative rounded-md border border-line bg-bg-1/80 transition-colors hover:border-line-2 ${o}`,children:[e&&w.jsxs("div",{className:"pointer-events-none absolute -top-[7px] left-3 flex items-center gap-2 bg-bg-1 px-1.5",children:[w.jsx("span",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:e}),t!=null&&w.jsx("span",{className:"text-[10px] normal-case tracking-normal text-fg-faint",children:t})]}),n&&w.jsx("div",{"data-chrome":!0,className:"absolute right-2 top-2 z-20 flex items-center gap-1.5 rounded bg-bg-1 px-0.5",children:n}),r&&w.jsx("div",{"data-chrome":!0,className:"absolute -top-[11px] right-3 z-20",children:w.jsx(bbe,{getNode:()=>u.current,name:r})}),w.jsx("div",{className:`p-4 ${a}`,children:i})]})}function bbe({getNode:e,name:t}){const n=MC();return w.jsx("button",{type:"button",title:"Share this panel","aria-label":"Share this panel as an image",onClick:()=>{const r=e();r&&n({kind:"panel",node:r,captureName:t})},className:"rounded border border-transparent bg-bg-1 p-1 text-fg-faint opacity-0 transition hover:border-line hover:text-accent group-hover:opacity-100 focus-visible:opacity-100",children:w.jsx(FG,{className:"size-3.5"})})}function wbe({derived:e,periodLabel:t}){const n=e.totals,r=e.timeline.map(a=>a.total).slice(-30),i=e.timeline.map(a=>a.tokens).slice(-30),o=e.cacheSavingsSeries.map(a=>a.value).slice(-30);return w.jsxs("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-3",children:[w.jsx(Uc,{label:`spend · ${t}`,value:Je(n.cost),accent:"text-cost",spark:r,sparkColor:"var(--color-cost)"}),w.jsx(Uc,{label:"tokens",value:Mn(n.tokens),spark:i,sparkColor:"var(--color-fg-dim)"}),w.jsx(Uc,{label:"cache saved",value:Je(n.cacheSavings),accent:"text-positive",spark:o,sparkColor:"var(--color-positive)"}),w.jsx(Uc,{label:"calls",value:ya(n.calls)}),w.jsx(Uc,{label:"burn · today",value:`${Je(e.burnRate)}/hr`,accent:"text-warning"})]})}function Uc({label:e,value:t,accent:n="text-fg-bright",spark:r,sparkColor:i}){return w.jsxs("div",{className:"rise flex min-w-0 flex-col rounded-md border border-line bg-bg-1/80 p-3.5 transition-colors hover:border-line-2",children:[w.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:e}),w.jsx("div",{className:`tnum mt-1.5 text-xl sm:text-2xl ${n}`,children:t}),r&&r.length>1&&w.jsx("div",{className:"mt-auto overflow-hidden pt-2 text-right",children:w.jsx(Pf,{data:r,color:i??"currentColor",className:"text-sm opacity-70"})})]})}function Sbe({accounts:e,nameOf:t,privacyMode:n}){return e.length===0?w.jsx(Gy,{title:"accounts",children:w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no accounts match the current filter"})}):w.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[repeat(auto-fit,minmax(min(340px,100%),1fr))]",children:e.map((r,i)=>w.jsx(_be,{account:r,index:i,providerName:t(r.providerId),privacyMode:n},r.id))})}function _be({account:e,index:t,providerName:n,privacyMode:r}){var h,d,g,m,v,x;const i=e.dashboard,o=((h=e.billing)==null?void 0:h.metrics)??[],a=((d=e.billing)==null?void 0:d.modelSpend)??[],u=(g=e.billing)==null?void 0:g.activity,c=bG(e.providerId),f=e.name&&e.name!==n;return w.jsxs("div",{className:"rise group relative overflow-hidden rounded-md border bg-bg-1/50 p-4 transition-colors",style:{animationDelay:`${t*40}ms`,borderColor:`color-mix(in oklab, ${c} 50%, var(--color-line))`},children:[w.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[w.jsx("span",{style:{color:c},children:"●"}),w.jsx("span",{className:"font-display text-sm tracking-wide text-fg-bright",children:n}),f&&w.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs text-fg-faint",children:[w.jsx("span",{"aria-hidden":!0,children:"·"}),w.jsx(Zp,{value:e.name,privacyMode:r,className:"truncate text-fg-faint"})]})]}),((m=e.billing)==null?void 0:m.plan)&&w.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:e.billing.plan})]}),i&&w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[w.jsx(k1,{label:"today",cost:i.today.cost,tokens:i.today.tokens}),w.jsx(k1,{label:"week",cost:i.week.cost,tokens:i.week.tokens}),w.jsx(k1,{label:"month",cost:i.month.cost,tokens:i.month.tokens})]}),w.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-line-faint pt-3 text-xs",children:[w.jsxs("span",{className:"text-fg-dim",children:["burn ",w.jsxs("span",{className:"tnum text-warning",children:[Je(i.burnRate),"/hr"]})]}),w.jsxs("span",{className:"text-fg-dim",children:["saved ",w.jsx("span",{className:"tnum text-positive",children:Je(i.month.cacheSavings)})]})]})]}),o.length>0&&w.jsx("div",{className:`flex flex-col gap-2 ${i?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:o.slice(0,8).map((b,O)=>w.jsx(Obe,{metric:b},`${b.label}${O}`))}),a.length>0&&w.jsxs("div",{className:"mt-3 flex flex-col gap-1 border-t border-line-faint pt-3",children:[w.jsx("div",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"spend by model"}),a.slice(0,4).map(b=>w.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[w.jsx("span",{className:"min-w-0 truncate text-fg-dim",children:Li(b.name)}),w.jsxs("span",{className:"tnum shrink-0 text-cost",children:[Je(b.usd),w.jsxs("span",{className:"ml-1.5 text-fg-faint",children:[ya(b.requests)," req"]})]})]},b.name))]}),i&&i.series.length>0&&w.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[w.jsx(Pf,{data:i.series,color:c,className:"text-sm"}),w.jsxs("span",{className:"ml-auto text-[10px] text-fg-faint",children:[i.series.length,"d"]})]}),!i&&u&&u.series.length>0&&w.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[w.jsx(Pf,{data:u.series,color:c,className:"text-sm"}),w.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:u.summary})]}),o.length===0&&((v=e.billing)==null?void 0:v.error)&&w.jsxs("div",{className:`flex items-start gap-1.5 text-xs text-warning ${i?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:[w.jsx("span",{"aria-hidden":!0,children:"⚠"}),w.jsx("span",{children:EO(e.billing.error,r)})]}),!i&&o.length===0&&!((x=e.billing)!=null&&x.error)&&a.length===0&&!(u&&u.series.length)&&w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:e.hasUsage?"no usage data":"billing-only · no live metrics"})]})}function k1({label:e,cost:t,tokens:n}){const r=t>0||n===0;return w.jsxs("div",{children:[w.jsx("div",{className:"text-[10px] uppercase text-fg-faint",children:e}),w.jsx("div",{className:`tnum text-sm ${r?"text-cost":"text-fg-bright"}`,children:r?Je(t):Mn(n)}),w.jsx("div",{className:"tnum text-[10px] text-fg-faint",children:r?Mn(n):Je(t)})]})}function Pbe(e){return e.format.kind==="dollars"?Je(e.used):e.format.kind==="count"?`${ya(e.used)}${e.format.suffix?" "+e.format.suffix:""}`:`${Math.round(e.used)}%`}function Obe({metric:e}){const t=e.format.kind==="percent"?Math.min(1,Math.max(0,e.used/100)):e.limit!=null&&e.limit>0?Math.min(1,Math.max(0,e.used/e.limit)):null,n=t==null?"var(--color-accent)":t>=.9?"var(--color-warning)":t>=.7?"var(--color-cost)":"var(--color-positive)";return w.jsxs("div",{children:[w.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[w.jsx("span",{className:"truncate text-fg-dim",children:e.label}),w.jsxs("span",{className:"tnum text-fg",children:[Pbe(e),e.format.kind!=="percent"&&e.limit!=null&&w.jsxs("span",{className:"text-fg-faint",children:[" / ",e.format.kind==="dollars"?Je(e.limit):ya(e.limit)]}),e.resetsAt&&w.jsxs("span",{className:"ml-1.5 text-fg-faint",children:["· ",e.resetsAt]})]})]}),t!=null&&w.jsx("div",{className:"mt-1 h-1.5 w-full overflow-hidden rounded-full bg-bg-3",role:"progressbar","aria-label":e.label,"aria-valuenow":Math.round(t*100),"aria-valuemin":0,"aria-valuemax":100,children:w.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${t*100}%`,background:n}})})]})}const Cbe=[0,.32,.55,.78,1],lF=e=>e===0?"var(--color-bg-2)":`color-mix(in oklab, var(--color-cost) ${Cbe[e]*100}%, var(--color-bg-2))`,C6=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function Ebe(e,t){const n=e,r=n.filter(h=>t(h)>0);if(r.length===0)return null;const i=n.reduce((h,d)=>h+t(d),0),o=r.reduce((h,d)=>t(d)>t(h)?d:h),a=new Array(7).fill(0);for(const h of n)a[_f(uo(h.date))]+=t(h);const u=a.indexOf(Math.max(...a)),c=new Set(r.map(h=>h.date));let f=0;for(let h=uo(r[r.length-1].date);c.has(wd(h));h-=ta)f++;return{active:r.length,total:i,top:o,avg:i/r.length,busiest:u,streak:f,costed:e.some(h=>h.cost>0)}}function kbe(e,t,n){const r=new Map(e.map(x=>[x.date,n(x)]));if(e.length===0)return null;const i=e[e.length-1].date,o=e[0].date;let a=uo(i),u=uo(o);(a-u)/(ta*7)>t&&(u=a-t*7*ta),u-=_f(u)*ta;const c=Math.max(...e.map(n),0),f=x=>{if(x<=0||c<=0)return 0;const b=x/c;return b>.66?4:b>.4?3:b>.15?2:1},h=[];let d=new Array(7).fill(null);const g=[];let m=-1,v=0;for(let x=u;x<=a;x+=ta){const b=wd(x),O=_f(x);O===0&&d.some(Boolean)&&(h.push(d),d=new Array(7).fill(null),v++);const _=new Date(x).getUTCMonth();_!==m&&O===0&&(g.push({col:v,text:_G[_]}),m=_);const C=x>=uo(o);d[O]=C?{date:b,cost:r.get(b)??0,level:f(r.get(b)??0)}:null}return d.some(Boolean)&&h.push(d),{weeks:h,monthLabels:g}}function Abe({derived:e,maxWeeks:t=26,periodLabel:n}){const[r,i]=D.useState(null),[o,a]=D.useState(null),u=r??o,c=D.useMemo(()=>new Map(e.calendar.map(x=>[x.date,x])),[e.calendar]),f=D.useMemo(()=>e.calendar.some(x=>x.cost>0),[e.calendar]),h=x=>f?x.cost:x.tokens,d=D.useMemo(()=>Ebe(e.calendar,h),[e,f]),g=D.useMemo(()=>kbe(e.calendar,t,h),[e,t]),m=g?`repeat(${g.weeks.length}, minmax(0,1fr))`:void 0,v=g?g.weeks.length*25:void 0;return w.jsx(w.Fragment,{children:w.jsx(Gy,{title:"daily spend",titleTag:n,captureName:"calendar",children:!g||!d?w.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no usage yet"}):w.jsxs("div",{className:"grid gap-x-8 gap-y-5 pt-1 md:grid-cols-[minmax(0,1fr)_210px] md:items-start",children:[w.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[w.jsx("div",{className:"pl-6",children:w.jsx("div",{className:"grid gap-[3px] text-[9px] text-fg-faint",style:{gridTemplateColumns:m,maxWidth:v},children:g.weeks.map((x,b)=>{const O=g.monthLabels.find(_=>_.col===b);return w.jsx("div",{className:"truncate",children:(O==null?void 0:O.text)??""},b)})})}),w.jsxs("div",{className:"flex gap-[3px]",children:[w.jsx("div",{className:"flex w-5 shrink-0 flex-col gap-[3px] text-[9px] text-fg-faint",children:["M","","W","","F","",""].map((x,b)=>w.jsx("div",{className:"flex flex-1 items-center",children:x},b))}),w.jsx("div",{className:"grid min-w-0 flex-1 gap-[3px]",style:{gridTemplateColumns:m,maxWidth:v},onMouseLeave:()=>i(null),children:g.weeks.map((x,b)=>w.jsx("div",{className:"flex flex-col gap-[3px]",children:x.map((O,_)=>O===null?w.jsx("div",{className:"aspect-square"},_):w.jsx("button",{type:"button","aria-label":`${xs(O.date)} — click to pin`,"aria-pressed":(o==null?void 0:o.date)===O.date,className:`aspect-square block rounded-[3px] p-0 transition duration-150 hover:scale-[1.18] hover:ring-1 hover:ring-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent ${(o==null?void 0:o.date)===O.date?"ring-1 ring-fg-bright":""}`,style:{background:lF(O.level)},onMouseEnter:()=>i(c.get(O.date)??null),onFocus:()=>i(c.get(O.date)??null),onClick:()=>a(C=>(C==null?void 0:C.date)===O.date?null:c.get(O.date)??null)},_))},b))})]}),w.jsxs("div",{className:"flex items-center gap-1.5 pl-6 pt-1 text-[9px] text-fg-faint",children:["less",[0,1,2,3,4].map(x=>w.jsx("span",{className:"size-[11px] rounded-[2px]",style:{background:lF(x)}},x)),"more"]})]}),w.jsxs("div",{className:"relative border-line-faint md:border-l md:pl-6",children:[w.jsxs("div",{className:`grid grid-cols-2 gap-x-6 gap-y-4 transition-opacity duration-200 md:grid-cols-1 ${u?"opacity-0":"opacity-100"}`,children:[w.jsx(ap,{label:"busiest day",value:d.costed?Je(d.top.cost):Mn(d.top.tokens),sub:xs(d.top.date),valueClass:"text-cost"}),w.jsx(ap,{label:"daily average",value:d.costed?Je(d.avg):Mn(d.avg),sub:`across ${d.active} active days`}),w.jsx(ap,{label:"top weekday",value:C6[d.busiest],valueClass:"text-fg-bright"}),w.jsx(ap,{label:"latest streak",value:`${d.streak}d`,sub:d.streak>0?"in a row":"idle today",valueClass:"text-positive"})]}),u&&w.jsx("div",{className:"dialog-fade absolute inset-0 md:pl-6",children:w.jsx(jbe,{day:u,pinned:!r&&u===o})})]})]})})})}function jbe({day:e,pinned:t=!1}){return w.jsxs("div",{className:"font-mono text-[11px]",children:[w.jsxs("div",{className:"flex items-baseline justify-between gap-3 border-b border-line-faint pb-2",children:[w.jsxs("span",{className:"text-fg-dim",children:[C6[_f(uo(e.date))]," · ",xs(e.date),t&&w.jsx("span",{className:"ml-1.5 text-[9px] uppercase tracking-wide text-accent",children:"pinned"})]}),w.jsx("span",{className:"tnum text-cost",children:e.cost>0?Je(e.cost):"—"})]}),e.cost>0?w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"grid grid-cols-3 gap-2 py-2 text-[10px]",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"calls"}),w.jsx("div",{className:"tnum text-fg",children:ya(e.calls)})]}),w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"tokens"}),w.jsx("div",{className:"tnum text-fg",children:Mn(e.tokens)})]}),w.jsxs("div",{children:[w.jsx("div",{className:"text-fg-faint",children:"saved"}),w.jsx("div",{className:"tnum text-positive",children:Je(e.cacheSavings)})]})]}),w.jsxs("div",{className:"flex flex-col gap-1 border-t border-line-faint pt-2",children:[e.models.slice(0,5).map(n=>w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx("span",{className:"size-1.5 shrink-0 rounded-full",style:{background:Em(n.name)}}),w.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-dim",children:Li(n.name)}),w.jsx("span",{className:"tnum w-16 shrink-0 text-right text-fg",children:Je(n.cost)})]},n.name)),e.models.length>5&&w.jsxs("div",{className:"pt-0.5 text-fg-faint",children:["+",e.models.length-5," more"]})]})]}):w.jsx("div",{className:"pt-2 text-fg-faint",children:"no spend this day"})]})}const Tbe=[{value:"cost",label:"cost"},{value:"tokens",label:"tokens"},{value:"calls",label:"calls"}],cF="1.75rem minmax(6rem,12rem) minmax(3.5rem,1fr) 3rem 5.5rem 5rem auto auto auto";function Rbe({derived:e,limit:t,periodLabel:n}){const[r,i]=D.useState(e.totals.cost>0?"cost":"tokens"),o=[...e.byModel].sort((h,d)=>d[r]-h[r]),a=t?o.slice(0,t):o,u=r==="tokens"?"tokenShare":r==="calls"?"callShare":"share",c=r==="tokens"?"block":"hidden md:block",f=r==="calls"?"block":"hidden lg:block";return w.jsx(Gy,{title:"model leaderboard",titleTag:n,captureName:"models",right:w.jsx(er,{options:Tbe,value:r,onChange:i,size:"xs",ariaLabel:"sort models by",containerClassName:"flex items-center gap-0.5",btnClassName:"rounded px-1.5 py-0.5 text-[11px] transition"}),children:a.length===0?w.jsx(K9,{children:"no models in period"}):w.jsxs("div",{className:"mt-6 flex flex-col overflow-x-auto",children:[w.jsxs("div",{className:"grid items-center gap-x-3 border-b border-line px-2 pb-1.5 font-display text-[10px] uppercase tracking-wide text-fg-faint",style:{gridTemplateColumns:cF},children:[w.jsx("span",{}),w.jsx("span",{}),w.jsx("span",{children:"share"}),w.jsx("span",{className:"text-right",children:"%"}),w.jsx("span",{className:"text-right text-cost/70",children:"cost"}),w.jsx("span",{className:"text-right",children:"trend"}),w.jsx("span",{className:"hidden text-right lg:block",children:"$/call"}),w.jsx("span",{className:`text-right ${c}`,children:"tokens"}),w.jsx("span",{className:`text-right ${f}`,children:"calls"})]}),a.map((h,d)=>w.jsxs("div",{className:"grid items-center gap-x-3 rounded border-b border-line-faint px-2 py-2 transition-colors last:border-0 hover:bg-bg-2/40",style:{gridTemplateColumns:cF},children:[w.jsxs("span",{className:`tnum text-xs ${d===0?"font-medium text-accent":d<3?"text-fg-dim":"text-fg-faint"}`,children:["#",d+1]}),w.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[w.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:h.color}}),w.jsx("span",{className:"truncate text-fg",title:h.model,children:Li(h.model)})]}),w.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-bg-3",children:w.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,h[u]*100)}%`,minWidth:h[u]>0?"2px":0,background:h.color}})}),w.jsx("span",{className:"tnum text-right text-[11px] text-fg-dim",children:S3(h[u],h[u]>0&&h[u]<.01?1:0)}),w.jsx("span",{className:"tnum text-right text-xs text-cost",children:Je(h.cost)}),w.jsx("span",{className:"overflow-hidden text-right",children:w.jsx(Pf,{data:h.trend.slice(-30),color:h.color,className:"text-sm"})}),w.jsx("span",{className:"tnum hidden text-right text-xs text-fg-dim lg:block",children:Je(h.calls?h.cost/h.calls:0)}),w.jsx("span",{className:`tnum text-right text-xs text-fg-dim ${c}`,children:h.tokens>0?Mn(h.tokens):w.jsx("span",{className:"text-fg-faint",children:"—"})}),w.jsx("span",{className:`tnum text-right text-xs text-fg-faint ${f}`,children:ya(h.calls)})]},h.model))]})})}/**
153
153
  * table-core
154
154
  *
155
155
  * Copyright (c) TanStack
@@ -170,4 +170,4 @@ ${t}}`),r},EP=`~effect/Fiber/${lhe}`,_he={_A:Fe,_E:Fe},Phe={id:0},ZC=()=>globalT
170
170
  * LICENSE.md file in the root directory of this source tree.
171
171
  *
172
172
  * @license MIT
173
- */function N1(e,t){return e?Ewe(e)?D.createElement(e,t):e:null}function Ewe(e){return kwe(e)||typeof e=="function"||Awe(e)}function kwe(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function Awe(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function jwe(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=D.useState(()=>({current:vwe(t)})),[r,i]=D.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...e,state:{...r,...e.state},onStateChange:a=>{i(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const Pu=Ibe(),N6=w.jsx("span",{className:"text-fg-faint",children:"—"}),Twe=e=>`${xs(e.label)} ${e.label} ${e.models.map(Li).join(" ")} ${e.models.join(" ")}`.toLowerCase();function Rwe(e){return D.useMemo(()=>[Pu.accessor("label",{header:e,cell:t=>w.jsxs("button",{type:"button","aria-expanded":t.row.getIsExpanded(),onClick:n=>{n.stopPropagation(),t.row.toggleExpanded()},className:"flex items-center gap-1 rounded text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[w.jsx("span",{"aria-hidden":!0,className:t.row.getIsExpanded()?"text-accent":"text-fg-faint",children:t.row.getIsExpanded()?"▾":"▸"}),w.jsx("span",{className:"text-fg",children:xs(t.getValue())})]})}),Pu.display({id:"models",header:"models",cell:t=>w.jsx("span",{className:"line-clamp-1 text-fg-dim",children:t.row.original.models.map(Li).join(", ")})}),Pu.accessor("total",{header:"tokens",meta:{align:"right"},cell:t=>t.getValue()>0?w.jsx("span",{className:"text-fg",children:Mn(t.getValue())}):N6}),Pu.accessor("cacheSavings",{header:"saved",meta:{align:"right",hiddenSm:!0},cell:t=>w.jsx("span",{className:"text-positive",children:Je(t.getValue())})}),Pu.accessor("count",{header:"calls",meta:{align:"right",hiddenSm:!0},cell:t=>w.jsx("span",{className:"text-fg-dim",children:Jp(t.getValue())})}),Pu.accessor("cost",{header:"cost",meta:{align:"right"},cell:t=>w.jsx("span",{className:"text-cost",children:Je(t.getValue())})})],[e])}const Iwe=e=>`py-2 pr-3${(e==null?void 0:e.align)==="right"?" text-right":""}${e!=null&&e.hiddenSm?" hidden sm:table-cell":""}`;function Mwe({rows:e,granLabel:t,q:n}){const[r,i]=D.useState([{id:"label",desc:!0}]),[o,a]=D.useState({}),c=Rwe(t==="monthly"?"month":t==="weekly"?"week":"date"),f=jwe({data:e,columns:c,state:{sorting:r,expanded:o,globalFilter:n},onSortingChange:i,onExpandedChange:a,getRowCanExpand:()=>!0,globalFilterFn:(g,m,v)=>!String(v).trim()||Twe(g.original).includes(String(v).trim().toLowerCase()),getCoreRowModel:xwe(),getSortedRowModel:Cwe(),getFilteredRowModel:Owe(),getExpandedRowModel:bwe()}),h=f.getRowModel().rows,d=D.useMemo(()=>h.reduce((g,m)=>({total:g.total+m.original.total,cost:g.cost+m.original.cost,cacheSavings:g.cacheSavings+m.original.cacheSavings,count:g.count+m.original.count}),{total:0,cost:0,cacheSavings:0,count:0}),[h]);return w.jsx(Gy,{title:`explore · ${t}`,captureName:"explore",children:w.jsx("div",{className:"max-h-[calc(100vh-240px)] overflow-auto",children:w.jsxs("table",{className:"w-full border-collapse text-xs",children:[w.jsxs("colgroup",{children:[w.jsx("col",{}),w.jsx("col",{style:{width:"34%"}}),w.jsx("col",{style:{width:"13%"}}),w.jsx("col",{style:{width:"12%"}}),w.jsx("col",{style:{width:"11%"}}),w.jsx("col",{style:{width:"13%"}})]}),w.jsx("thead",{children:w.jsx("tr",{className:"sticky top-0 z-10 bg-bg-1 text-[11px] shadow-[inset_0_-1px_0_var(--color-line)]",children:f.getHeaderGroups()[0].headers.map(g=>{const m=g.column.columnDef.meta,v=g.column.getIsSorted();return w.jsx("th",{className:`py-2 pr-3 font-normal ${(m==null?void 0:m.align)==="right"?"text-right":"text-left"}${m!=null&&m.hiddenSm?" hidden sm:table-cell":""}`,children:g.column.getCanSort()?w.jsxs("button",{type:"button",onClick:g.column.getToggleSortingHandler(),className:`flex w-full items-center gap-1 text-fg-faint transition hover:text-fg ${(m==null?void 0:m.align)==="right"?"justify-end":""}`,children:[N1(g.column.columnDef.header,g.getContext()),v&&w.jsx("span",{className:"text-accent",children:v==="asc"?"▲":"▼"})]}):w.jsx("span",{className:"text-fg-faint",children:N1(g.column.columnDef.header,g.getContext())})},g.id)})})}),w.jsxs("tbody",{children:[h.length===0&&w.jsx("tr",{children:w.jsx("td",{colSpan:6,className:"py-8 text-center text-fg-faint",children:n.trim()?`no rows match “${n.trim()}”`:"no usage in this range"})}),h.map(g=>w.jsxs(D.Fragment,{children:[w.jsx("tr",{className:"cursor-pointer border-b border-line-faint transition hover:bg-bg-2/60",onClick:()=>g.toggleExpanded(),children:g.getVisibleCells().map(m=>w.jsx("td",{className:`${Iwe(m.column.columnDef.meta)}${m.column.id==="label"?" whitespace-nowrap":""} tnum`,children:N1(m.column.columnDef.cell,m.getContext())},m.id))}),g.getIsExpanded()&&g.original.breakdown.map(m=>{const v=pa(m);return w.jsxs("tr",{className:"border-b border-line-faint bg-bg-0/40 text-[11px]",children:[w.jsxs("td",{className:"py-1.5 pr-3 pl-5 text-fg-dim",colSpan:2,children:[w.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full align-middle",style:{background:Em(m.name)}}),Li(m.name)]}),w.jsx("td",{className:"tnum py-1.5 pr-3 text-right text-fg-dim",children:v>0?Mn(v):N6}),w.jsx("td",{className:"tnum hidden py-1.5 pr-3 text-right text-positive/80 sm:table-cell",children:Je(m.cacheSavings)}),w.jsx("td",{className:"tnum hidden py-1.5 pr-3 text-right text-fg-faint sm:table-cell",children:ya(m.count)}),w.jsx("td",{className:"tnum py-1.5 text-right text-cost/90",children:Je(m.cost)})]},m.name)})]},g.id))]}),h.length>0&&w.jsx("tfoot",{children:w.jsxs("tr",{className:"sticky bottom-0 z-10 bg-bg-1 text-fg shadow-[inset_0_1px_0_var(--color-line)]",children:[w.jsxs("td",{className:"py-2 pr-3 font-display text-[11px] uppercase text-fg-dim",colSpan:2,children:["total · ",h.length]}),w.jsx("td",{className:"tnum py-2 pr-3 text-right",children:Mn(d.total)}),w.jsx("td",{className:"tnum hidden py-2 pr-3 text-right text-positive sm:table-cell",children:Je(d.cacheSavings)}),w.jsx("td",{className:"tnum hidden py-2 pr-3 text-right sm:table-cell",children:Jp(d.count)}),w.jsx("td",{className:"tnum py-2 text-right text-cost",children:Je(d.cost)})]})})]})})})}const Xy=()=>O6(()=>import("./timeline-pvwrpASn.js"),[],import.meta.url),Vd=()=>O6(()=>import("./breakdown-UyMKAeuQ.js"),[],import.meta.url);Xy();Vd();const $we=D.lazy(()=>Xy().then(e=>({default:e.CostTimeline}))),Nwe=D.lazy(()=>Xy().then(e=>({default:e.CumulativeSpend}))),Lwe=D.lazy(()=>Xy().then(e=>({default:e.CacheSavings}))),L6=D.lazy(()=>Vd().then(e=>({default:e.CostByModel}))),D6=D.lazy(()=>Vd().then(e=>({default:e.ProviderDonut}))),hF=D.lazy(()=>Vd().then(e=>({default:e.TokenComposition}))),Dwe=D.lazy(()=>Vd().then(e=>({default:e.CacheByModel}))),Fwe=({className:e})=>w.jsx("div",{className:e,"aria-hidden":!0}),Jo=({children:e})=>w.jsx(D.Suspense,{fallback:null,children:e}),pF=[{key:"overview",label:"overview"},{key:"analytics",label:"analytics"},{key:"models",label:"models"},{key:"explore",label:"explore"}],Bwe=[{value:"daily",label:"daily"},{value:"weekly",label:"weekly"},{value:"monthly",label:"monthly"}];function zwe({derived:e,periodLabel:t,scopeLabel:n,providers:r,privacyMode:i}){const o=a=>{var u;return((u=r.find(c=>c.id===a))==null?void 0:u.name)??a};return w.jsxs("div",{className:"flex flex-col gap-4",children:[w.jsx(wbe,{derived:e,periodLabel:t}),w.jsx(D.Suspense,{fallback:w.jsx(Fwe,{className:"h-[clamp(320px,42vh,560px)]"}),children:w.jsx($we,{derived:e,periodLabel:n,heightClass:"h-[clamp(320px,42vh,560px)]"})}),w.jsx(Sbe,{accounts:e.cardAccounts,nameOf:o,privacyMode:i})]})}function qwe({derived:e,scopeLabel:t}){const n=e.byProvider.length>1;return w.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[w.jsx("div",{className:"md:col-span-2",children:w.jsx(Abe,{derived:e,periodLabel:t})}),w.jsx(Jo,{children:w.jsx(L6,{derived:e,periodLabel:t})}),w.jsx(Jo,{children:n?w.jsx(D6,{derived:e,periodLabel:t}):w.jsx(hF,{derived:e,periodLabel:t})}),n&&w.jsx(Jo,{children:w.jsx(hF,{derived:e,periodLabel:t})}),w.jsx("div",{className:n?void 0:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Lwe,{derived:e,periodLabel:t})})}),w.jsx("div",{className:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Nwe,{derived:e,height:300,periodLabel:t})})})]})}function Uwe({derived:e,scopeLabel:t}){const n=e.byProvider.length>1;return w.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[w.jsx("div",{className:"md:col-span-2",children:w.jsx(Rbe,{derived:e,periodLabel:t})}),w.jsx("div",{className:n?void 0:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(L6,{derived:e,metric:"tokens",limit:12,periodLabel:t})})}),n&&w.jsx(Jo,{children:w.jsx(D6,{derived:e,periodLabel:t})}),w.jsx("div",{className:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Dwe,{derived:e,periodLabel:t})})})]})}function Vwe({snapshot:e,filters:t,periodLabel:n,privacyMode:r}){const[i,o]=D.useState(""),[a,u]=D.useState("daily"),c=MC(),f=t.models.length===1?t.models[0]:null,h=D.useMemo(()=>jG(e,t,a),[e,t,a]),d=D.useMemo(()=>f?TG(e,t,f):null,[e,t,f]),g=D.useMemo(()=>(e?km(e,t):[]).some(v=>v.tableState!=="ready"),[e,t]),m=a!=="daily"?`showing up to ${a==="monthly"?"12 months":"12 weeks"}`:`scoped to ${n}`;return w.jsxs("div",{className:"flex flex-col gap-3",children:[w.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx("span",{className:"text-xs text-fg-faint",children:"granularity:"}),w.jsx(er,{options:Bwe,value:a,onChange:u,size:"sm",ariaLabel:"row granularity",btnClassName:"px-3 py-1 text-xs capitalize transition"})]}),m&&w.jsx("span",{className:"text-xs text-fg-faint",children:m}),g&&w.jsxs("span",{className:"text-xs text-fg-faint",role:"status",children:["loading history",w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),f&&d&&w.jsxs("button",{type:"button",onClick:()=>c({kind:"model",model:f,periodLabel:n,tz:(e==null?void 0:e.tz)??"",version:(e==null?void 0:e.version)??"",...d,accounts:d.accounts.map(v=>({...v,name:EO(v.name,r)}))}),className:"flex items-center gap-1.5 rounded border border-line bg-bg-1 px-2.5 py-1 text-xs text-fg-dim transition hover:border-accent/60 hover:text-accent active:scale-[0.97] max-sm:py-2",title:"Create a shareable model image",children:[w.jsx(O3,{className:"size-3.5"}),w.jsx("span",{children:"share model"})]}),w.jsxs("div",{className:"ml-auto flex items-center gap-1.5 rounded border border-line bg-bg-1 px-2 py-1 text-xs focus-within:border-line-2",children:[w.jsx(qG,{className:"size-3 text-fg-faint"}),w.jsx("input",{type:"search",value:i,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Escape"&&o("")},placeholder:"filter rows…","aria-label":"Filter rows by date or model",autoComplete:"off",spellCheck:!1,className:"w-32 bg-transparent text-fg outline-none placeholder:text-fg-faint [&::-webkit-search-cancel-button]:appearance-none"}),i&&w.jsx("button",{type:"button",onClick:()=>o(""),"aria-label":"Clear filter",children:w.jsx(qu,{className:"size-3 text-fg-faint hover:text-fg","aria-hidden":!0})})]})]}),w.jsx(Mwe,{rows:h,granLabel:a,q:i})]})}function sk(e,t,n){try{return e(t)}catch(r){return GV("[nuqs] Error while parsing value `%s`: %O"+(n?" (for key `%s`)":""),t,r,n),null}}function Si(e){function t(n){if(typeof n>"u")return null;let r="";if(Array.isArray(n)){if(n[0]===void 0)return null;r=n[0]}return typeof n=="string"&&(r=n),sk(e.parse,r)}return{type:"single",eq:(n,r)=>n===r,...e,parseServerSide:t,withDefault(n){return{...this,defaultValue:n,parseServerSide(r){return t(r)??n}}},withOptions(n){return{...this,...n}}}}const L1=Si({parse:e=>e,serialize:String});Si({parse:e=>{const t=parseInt(e);return t==t?t:null},serialize:e=>""+Math.round(e)});Si({parse:e=>{const t=parseInt(e);return t==t?t-1:null},serialize:e=>""+Math.round(e+1)});Si({parse:e=>{const t=parseInt(e,16);return t==t?t:null},serialize:e=>{const t=Math.round(e).toString(16);return(t.length&1?"0":"")+t}});Si({parse:e=>{const t=parseFloat(e);return t==t?t:null},serialize:String});Si({parse:e=>e.toLowerCase()==="true",serialize:String});function uk(e,t){return e.valueOf()===t.valueOf()}Si({parse:e=>{const t=parseInt(e);return t==t?new Date(t):null},serialize:e=>""+e.valueOf(),eq:uk});Si({parse:e=>{const t=new Date(e);return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString(),eq:uk});Si({parse:e=>{const t=new Date(e.slice(0,10));return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString().slice(0,10),eq:uk});function Wwe(e){return Hwe(e)}function Hwe(e){return Si({parse:t=>{const n=t;return e.includes(n)?n:null},serialize:String})}function gF(e,t=","){const n=e.eq??((i,o)=>i===o),r=encodeURIComponent(t);return Si({parse:i=>i===""?[]:i.split(t).map((o,a)=>sk(e.parse,o.replaceAll(r,t),`[${a}]`)).filter(o=>o!=null),serialize:i=>i.map(o=>(e.serialize?e.serialize(o):String(o)).replaceAll(t,r)).join(t),eq(i,o){return i===o?!0:i.length!==o.length?!1:i.every((a,u)=>n(a,o[u]))}})}const D1=pO(),Gwe={};function Kwe(e,t={}){const n=D.useId(),r=tW(),i=nW(),{history:o="replace",scroll:a=(r==null?void 0:r.scroll)??!1,shallow:u=(r==null?void 0:r.shallow)??!0,throttleMs:c=ef.timeMs,limitUrlUpdates:f=r==null?void 0:r.limitUrlUpdates,clearOnDefault:h=(r==null?void 0:r.clearOnDefault)??!0,startTransition:d,urlKeys:g=Gwe}=t,m=Object.keys(e).join(","),v=D.useMemo(()=>Object.fromEntries(Object.keys(e).map(R=>[R,g[R]??R])),[m,JSON.stringify(g)]),x=eW(Object.values(v)),b=x.searchParams,O=D.useRef({}),_=D.useMemo(()=>Object.fromEntries(Object.keys(e).map(R=>[R,e[R].defaultValue??null])),[Object.values(e).map(({defaultValue:R})=>R).join(",")]),C=V0.useQueuedQueries(Object.values(v)),[E,P]=D.useState(()=>F1(e,g,b??new URLSearchParams,C).state),A=D.useRef(E);if(St("[nuq+ %s `%s`] render - state: %O, iSP: %s",n,m,E,b),Object.keys(O.current).join("&")!==Object.values(v).join("&")){const{state:R,hasChanged:M}=F1(e,g,b,C,O.current,A.current);M&&(St("[nuq+ %s `%s`] State changed: %O",n,m,{state:R,initialSearchParams:b,queuedQueries:C,queryRef:O.current,stateRef:A.current}),A.current=R,P(R)),O.current=Object.fromEntries(Object.entries(v).map(([F,$])=>{var L;return[$,((L=e[F])==null?void 0:L.type)==="multi"?b==null?void 0:b.getAll($):(b==null?void 0:b.get($))??null]}))}D.useEffect(()=>{const{state:R,hasChanged:M}=F1(e,g,b,C,O.current,A.current);M&&(St("[nuq+ %s `%s`] State changed: %O",n,m,{state:R,initialSearchParams:b,queuedQueries:C,queryRef:O.current,stateRef:A.current}),A.current=R,P(R))},[Object.values(v).map(R=>`${R}=${b==null?void 0:b.getAll(R)}`).join("&"),JSON.stringify(C)]),D.useEffect(()=>{const R=Object.keys(e).reduce((M,F)=>(M[F]=({state:$,query:L})=>{P(T=>{const{defaultValue:N}=e[F],B=v[F],z=$??N??null,q=T[F]??N??null;return Object.is(q,z)?(St("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). no change, skipping, resolved: %O",n,m,B,$,N,A.current),T):(A.current={...A.current,[F]:z},O.current[B]=L,St("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). updateInternalState, resolved: %O",n,m,B,$,N,A.current),A.current)})},M),{});for(const M of Object.keys(e)){const F=v[M];St("[nuq+ %s `%s`] Subscribing to sync for `%s`",n,F,m),D1.on(F,R[M])}return()=>{for(const M of Object.keys(e)){const F=v[M];St("[nuq+ %s `%s`] Unsubscribing to sync for `%s`",n,F,m),D1.off(F,R[M])}}},[m,v]);const j=D.useCallback((R,M={})=>{var q,W,Z,Y,U,K;const F=Object.fromEntries(Object.keys(e).map(ae=>[ae,null])),$=typeof R=="function"?R(mF(A.current,_))??F:R??F;St("[nuq+ %s `%s`] setState: %O",n,m,$);let L,T=0,N=!1;const B=[];for(let[ae,pe]of Object.entries($)){const he=e[ae],Ce=v[ae];if(!he||pe===void 0)continue;(M.clearOnDefault??he.clearOnDefault??h)&&pe!==null&&he.defaultValue!==void 0&&(he.eq??((se,Se)=>se===Se))(pe,he.defaultValue)&&(pe=null);const Le=pe===null?null:(he.serialize??String)(pe);D1.emit(Ce,{state:pe,query:Le});const Oe={key:Ce,query:Le,options:{history:M.history??he.history??o,shallow:M.shallow??he.shallow??u,scroll:M.scroll??he.scroll??a,startTransition:M.startTransition??he.startTransition??d}};if(((q=M==null?void 0:M.limitUrlUpdates)==null?void 0:q.method)==="debounce"||(f==null?void 0:f.method)==="debounce"||((W=he.limitUrlUpdates)==null?void 0:W.method)==="debounce"){Oe.options.shallow===!0&&console.warn(bd(422));const se=((Z=M==null?void 0:M.limitUrlUpdates)==null?void 0:Z.timeMs)??(f==null?void 0:f.timeMs)??((Y=he.limitUrlUpdates)==null?void 0:Y.timeMs)??ef.timeMs,Se=V0.push(Oe,se,x,i);T<se&&(L=Se,T=se)}else{const se=((U=M==null?void 0:M.limitUrlUpdates)==null?void 0:U.timeMs)??((K=he==null?void 0:he.limitUrlUpdates)==null?void 0:K.timeMs)??(f==null?void 0:f.timeMs)??M.throttleMs??he.throttleMs??c;B.push(V0.abort(Ce)),Ip.push(Oe,se),N=!0}}const z=B.reduce((ae,pe)=>pe(ae),N?Ip.flush(x,i):Ip.getPendingPromise(x));return L??z},[m,o,u,a,c,f==null?void 0:f.method,f==null?void 0:f.timeMs,d,v,x.updateUrl,x.getSearchParamsSnapshot,x.rateLimitFactor,i,_]);return[D.useMemo(()=>mF(E,_),[E,_]),j]}function F1(e,t,n,r,i,o){let a=!1;const u=Object.entries(e).reduce((c,[f,h])=>{const d=(t==null?void 0:t[f])??f,g=r[d],m=h.type==="multi"?[]:null,v=g===void 0?(h.type==="multi"?n==null?void 0:n.getAll(d):n==null?void 0:n.get(d))??m:g;return i&&o&&DF(i[d]??m,v)?(c[f]=o[f]??null,c):(a=!0,c[f]=(oW(v)?null:sk(h.parse,v,d))??null,i&&(i[d]=v),c)},{});if(!a){const c=Object.keys(e),f=Object.keys(o??{});a=c.length!==f.length||c.some(h=>!f.includes(h))}return{state:u,hasChanged:a}}function mF(e,t){return Object.fromEntries(Object.keys(e).map(n=>[n,e[n]??t[n]??null]))}const Xwe=["7d","30d","90d","mtd","all"];function Ywe(){const[e,t]=Kwe({p:gF(L1).withDefault([]),m:gF(L1).withDefault([]),a:L1.withDefault("all"),period:Wwe(Xwe).withDefault(CG.period)},{history:"replace"}),n=D.useMemo(()=>({providers:e.p,models:e.m,account:e.a,period:e.period}),[e.p,e.m,e.a,e.period]),r=D.useCallback(i=>{t(o=>{const a={providers:o.p,models:o.m,account:o.a,period:o.period},u=typeof i=="function"?i(a):i;return{p:u.providers,m:u.models,a:u.account,period:u.period}})},[t]);return[n,r]}function Qwe(){const[e,t]=D.useState(null),[n,r]=D.useState("connecting"),i=D.useRef(null);return D.useEffect(()=>{let o=!1;const a=Ud(),u=ebe(f=>{o||r(f)}),c=a.subscribeSnapshot(f=>{o||(t(f),r("live"))});return i.current=c,()=>{var f;o=!0,u(),(f=i.current)==null||f.call(i),i.current=null}},[]),{snapshot:e,conn:n}}const fO=e=>`/${e}`,F6=D.createContext(null),Yy=()=>{const e=D.useContext(F6);if(!e)throw new Error("useDashboard outside provider");return e};function Jwe(e=1e3){const[t,n]=D.useState(()=>Date.now());return D.useEffect(()=>{const r=setInterval(()=>n(Date.now()),e);return()=>clearInterval(r)},[e]),t}function Zwe(){const[e,t]=D.useState(()=>document.documentElement.classList.contains("light")?"light":"dark");return D.useEffect(()=>{document.documentElement.classList.toggle("light",e==="light")},[e]),[e,()=>{const r=e==="dark"?"light":"dark";try{localStorage.setItem("tokmon-theme",r)}catch{}t(r)}]}function eSe({theme:e,onToggle:t}){return w.jsx("button",{type:"button",onClick:t,title:e==="dark"?"Switch to light":"Switch to dark","aria-label":"Toggle theme",className:"rounded border border-line bg-bg-1 p-1.5 text-fg-dim transition hover:border-line-2 hover:text-fg max-sm:p-2.5",children:e==="dark"?w.jsx(UG,{className:"size-3.5"}):w.jsx(VG,{className:"size-3.5"})})}function tSe({conn:e,freshAt:t}){const n=Jwe(),r=e==="live"?"var(--color-positive)":e==="error"?"var(--color-warning)":"var(--color-cost)",i=t?SG(t,n):null,o=e==="live"?i??"live":e==="connecting"?"connecting…":e==="reconnecting"?i?`reconnecting · ${i}`:"reconnecting…":i?`offline · ${i}`:"offline";return w.jsxs("span",{className:"flex items-center gap-1.5 text-xs",role:"status","aria-label":e==="live"?"live":e,children:[w.jsxs("span",{className:"relative flex size-2",children:[e==="live"&&w.jsx("span",{className:"absolute inline-flex size-full animate-ping rounded-full opacity-60",style:{background:r}}),w.jsx("span",{className:"relative inline-flex size-2 rounded-full",style:{background:r}})]}),w.jsx("span",{className:"inline-block truncate text-fg-dim max-sm:max-w-[7rem]","aria-hidden":!0,children:o})]})}function B1({label:e}){return w.jsxs("div",{className:"flex min-h-[50vh] flex-col items-center justify-center gap-2 text-sm text-fg-dim",children:[w.jsxs("span",{className:"font-display text-lg text-fg-dim",children:["tokmon",w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),w.jsx("span",{className:"text-fg-faint",children:e})]})}function nSe({onOpen:e}){return w.jsx("button",{type:"button",onClick:e,title:"Settings","aria-label":"Open settings",className:"rounded border border-line bg-bg-1 p-1.5 text-fg-dim transition hover:border-line-2 hover:text-fg max-sm:p-2.5",children:w.jsx(WG,{className:"size-3.5"})})}function rSe(){var M,F;const{snapshot:e,conn:t}=Qwe(),[n,r]=Ywe(),[i,o]=Zwe(),[a,u]=D.useState(!1),[c,f]=D.useState(Ho.privacyMode);D.useEffect(()=>_6($=>f($.privacyMode)),[]);const h=D.useMemo(()=>DG(e,n),[e,n]),d=((M=_3.find($=>$.key===n.period))==null?void 0:M.label)??n.period,g=n.period==="all"?void 0:d,m=uG({select:$=>$.location.pathname}),v=((F=pF.find($=>fO($.key)===m))==null?void 0:F.key)??"overview";D.useEffect(()=>{var q;if(!e)return;const $=new Set(e.providers.map(W=>W.id)),L=new Set(e.accounts.map(W=>W.id)),T=n.providers.filter(W=>$.has(W)),N=n.account==="all"||L.has(n.account)?n.account:"all",B=new Set;for(const W of e.accounts)for(const Z of((q=W.table)==null?void 0:q.monthly)??[])for(const Y of Z.breakdown)B.add(Y.name);const z=B.size>0?n.models.filter(W=>B.has(W)):n.models;(T.length!==n.providers.length||N!==n.account||z.length!==n.models.length)&&r(W=>({...W,providers:T,account:N,models:z}))},[e,n,r]);const x=(e==null?void 0:e.accounts.filter($=>$.hasUsage))??[],b=x.length>0,O=((e==null?void 0:e.accounts)??[]).some(J1),_=((e==null?void 0:e.accounts)??[]).some($=>$.hasBilling&&!J1($)),C=b&&x.every($=>$.table!=null),E=D.useRef(!1);D.useEffect(()=>{C&&(E.current=!0)},[C]);const[P,A]=D.useState(!1);D.useEffect(()=>{const $=setTimeout(()=>A(!0),12e3);return()=>clearTimeout($)},[]);const j=!b||C||E.current||P,R=D.useMemo(()=>e?{snapshot:e,filters:n,derived:h,periodLabel:d,scopeLabel:g,privacyMode:c}:null,[e,n,h,d,g,c]);return w.jsxs("div",{className:"min-h-screen",children:[w.jsxs("header",{className:"relative z-30 border-b border-line bg-bg-0/80 backdrop-blur",children:[w.jsxs("div",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px]",children:[w.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 py-3.5",children:[w.jsx("span",{className:"font-display text-2xl text-fg-bright",children:"TOKMON"}),w.jsxs("span",{className:"hidden text-sm text-fg-faint sm:inline",children:["~/usage ",w.jsx("span",{className:"text-prompt",children:"$"})," ",w.jsx("span",{className:"text-fg-dim",children:v}),w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),w.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-3",children:[w.jsx(tSe,{conn:t,freshAt:(e==null?void 0:e.generatedAt)??null}),w.jsx(nSe,{onOpen:()=>u(!0)}),w.jsx(eSe,{theme:i,onToggle:o}),j&&(b||O)&&w.jsx($ce,{derived:h,periodLabel:d,tz:(e==null?void 0:e.tz)??"",version:(e==null?void 0:e.version)??""})]})]}),w.jsx("nav",{className:"-mb-px flex items-center gap-1 overflow-x-auto",children:pF.map($=>w.jsx(bO,{to:fO($.key),className:`relative shrink-0 border-b-2 px-3 py-2 font-display text-xs uppercase tracking-wider transition ${v===$.key?"border-accent text-fg-bright":"border-transparent text-fg-faint hover:text-fg-dim"}`,children:$.label},$.key))})]}),w.jsx(KG,{snapshot:e,derived:h,filters:n,setFilters:r,privacyMode:c})]}),w.jsxs("main",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px] py-5",children:[(e==null?void 0:e.seeded)&&w.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim",role:"status",children:[w.jsx("span",{className:"inline-flex size-2 rounded-full",style:{background:"var(--color-cost)"},"aria-hidden":!0}),"showing cached data — refreshing…"]}),e?!b&&!O?_&&!P&&t!=="error"?w.jsx(B1,{label:"reading billing…"}):w.jsx("div",{className:"rounded-md border border-line bg-bg-1 p-8 text-center text-sm text-fg-dim",children:"No providers detected. Open tokmon, enable a provider, then refresh."}):!j||!R?w.jsx(B1,{label:t==="error"?"connection lost — retrying…":"reading usage history…"}):w.jsx(F6.Provider,{value:R,children:w.jsx(v3,{})}):w.jsx(B1,{label:t==="error"?"connection lost — retrying…":"reading usage…"})]}),w.jsxs("footer",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px] py-6 text-center text-[11px] text-fg-faint",children:["tokmon",e!=null&&e.version?` v${e.version}`:""," · by David Ilie · live LLM usage dashboard"]}),a&&w.jsx(ybe,{snapshot:e,onClose:()=>u(!1)})]})}function yF(){const{derived:e,periodLabel:t,scopeLabel:n,snapshot:r,privacyMode:i}=Yy();return w.jsx("div",{children:w.jsx(zwe,{derived:e,periodLabel:t,scopeLabel:n,providers:r.providers,privacyMode:i})})}function iSe(){const{derived:e,scopeLabel:t}=Yy();return w.jsx("div",{children:w.jsx(qwe,{derived:e,scopeLabel:t})})}function oSe(){const{derived:e,scopeLabel:t}=Yy();return w.jsx("div",{children:w.jsx(Uwe,{derived:e,scopeLabel:t})})}function aSe(){const{snapshot:e,filters:t,periodLabel:n,privacyMode:r}=Yy();return w.jsx("div",{children:w.jsx(Vwe,{snapshot:e,filters:t,periodLabel:n,privacyMode:r})})}const dO=WH({component:rSe}),Rp=(e,t)=>g3({getParentRoute:()=>dO,path:fO(e),component:t}),sSe=dO.addChildren([g3({getParentRoute:()=>dO,path:"/",component:yF}),Rp("overview",yF),Rp("analytics",iSe),Rp("models",oSe),Rp("explore",aSe)]),uSe=iG({routeTree:sSe,history:eH(),defaultViewTransition:!0});function lSe(){return w.jsx(sG,{router:uSe})}WV.createRoot(document.getElementById("root")).render(w.jsx(D.StrictMode,{children:w.jsx(gW,{children:w.jsx(Mce,{children:w.jsx(lSe,{})})})}));export{ir as $,Pa as A,Of as B,vSe as C,Tn as D,K9 as E,Jm as F,Oce as G,ds as H,Me as I,Xt as J,Y_ as K,ay as L,di as M,qr as N,Dt as O,Gy as P,ws as Q,TQ as R,er as S,eo as T,me as U,Ii as V,Rs as W,ly as X,cy as Y,ba as Z,li as _,Mq as a,JO as a0,vne as a1,ci as a2,co as a3,Ns as a4,fSe as a5,pSe as a6,Li as a7,Mn as a8,S3 as a9,pa as aa,ip as ab,xs as b,gSe as c,wG as d,mSe as e,Hae as f,_ce as g,Je as h,Ve as i,w as j,H as k,Ne as l,Cce as m,_z as n,Nee as o,xa as p,lt as q,D as r,ySe as s,Fee as t,hSe as u,$e as v,pg as w,bn as x,Qe as y,dSe as z};
173
+ */function N1(e,t){return e?Ewe(e)?D.createElement(e,t):e:null}function Ewe(e){return kwe(e)||typeof e=="function"||Awe(e)}function kwe(e){return typeof e=="function"&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function Awe(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function jwe(e){const t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=D.useState(()=>({current:vwe(t)})),[r,i]=D.useState(()=>n.current.initialState);return n.current.setOptions(o=>({...o,...e,state:{...r,...e.state},onStateChange:a=>{i(a),e.onStateChange==null||e.onStateChange(a)}})),n.current}const Pu=Ibe(),N6=w.jsx("span",{className:"text-fg-faint",children:"—"}),Twe=e=>`${xs(e.label)} ${e.label} ${e.models.map(Li).join(" ")} ${e.models.join(" ")}`.toLowerCase();function Rwe(e){return D.useMemo(()=>[Pu.accessor("label",{header:e,cell:t=>w.jsxs("button",{type:"button","aria-expanded":t.row.getIsExpanded(),onClick:n=>{n.stopPropagation(),t.row.toggleExpanded()},className:"flex items-center gap-1 rounded text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[w.jsx("span",{"aria-hidden":!0,className:t.row.getIsExpanded()?"text-accent":"text-fg-faint",children:t.row.getIsExpanded()?"▾":"▸"}),w.jsx("span",{className:"text-fg",children:xs(t.getValue())})]})}),Pu.display({id:"models",header:"models",cell:t=>w.jsx("span",{className:"line-clamp-1 text-fg-dim",children:t.row.original.models.map(Li).join(", ")})}),Pu.accessor("total",{header:"tokens",meta:{align:"right"},cell:t=>t.getValue()>0?w.jsx("span",{className:"text-fg",children:Mn(t.getValue())}):N6}),Pu.accessor("cacheSavings",{header:"saved",meta:{align:"right",hiddenSm:!0},cell:t=>w.jsx("span",{className:"text-positive",children:Je(t.getValue())})}),Pu.accessor("count",{header:"calls",meta:{align:"right",hiddenSm:!0},cell:t=>w.jsx("span",{className:"text-fg-dim",children:Jp(t.getValue())})}),Pu.accessor("cost",{header:"cost",meta:{align:"right"},cell:t=>w.jsx("span",{className:"text-cost",children:Je(t.getValue())})})],[e])}const Iwe=e=>`py-2 pr-3${(e==null?void 0:e.align)==="right"?" text-right":""}${e!=null&&e.hiddenSm?" hidden sm:table-cell":""}`;function Mwe({rows:e,granLabel:t,q:n}){const[r,i]=D.useState([{id:"label",desc:!0}]),[o,a]=D.useState({}),c=Rwe(t==="monthly"?"month":t==="weekly"?"week":"date"),f=jwe({data:e,columns:c,state:{sorting:r,expanded:o,globalFilter:n},onSortingChange:i,onExpandedChange:a,getRowCanExpand:()=>!0,globalFilterFn:(g,m,v)=>!String(v).trim()||Twe(g.original).includes(String(v).trim().toLowerCase()),getCoreRowModel:xwe(),getSortedRowModel:Cwe(),getFilteredRowModel:Owe(),getExpandedRowModel:bwe()}),h=f.getRowModel().rows,d=D.useMemo(()=>h.reduce((g,m)=>({total:g.total+m.original.total,cost:g.cost+m.original.cost,cacheSavings:g.cacheSavings+m.original.cacheSavings,count:g.count+m.original.count}),{total:0,cost:0,cacheSavings:0,count:0}),[h]);return w.jsx(Gy,{title:`explore · ${t}`,captureName:"explore",children:w.jsx("div",{className:"max-h-[calc(100vh-240px)] overflow-auto",children:w.jsxs("table",{className:"w-full border-collapse text-xs",children:[w.jsxs("colgroup",{children:[w.jsx("col",{}),w.jsx("col",{style:{width:"34%"}}),w.jsx("col",{style:{width:"13%"}}),w.jsx("col",{style:{width:"12%"}}),w.jsx("col",{style:{width:"11%"}}),w.jsx("col",{style:{width:"13%"}})]}),w.jsx("thead",{children:w.jsx("tr",{className:"sticky top-0 z-10 bg-bg-1 text-[11px] shadow-[inset_0_-1px_0_var(--color-line)]",children:f.getHeaderGroups()[0].headers.map(g=>{const m=g.column.columnDef.meta,v=g.column.getIsSorted();return w.jsx("th",{className:`py-2 pr-3 font-normal ${(m==null?void 0:m.align)==="right"?"text-right":"text-left"}${m!=null&&m.hiddenSm?" hidden sm:table-cell":""}`,children:g.column.getCanSort()?w.jsxs("button",{type:"button",onClick:g.column.getToggleSortingHandler(),className:`flex w-full items-center gap-1 text-fg-faint transition hover:text-fg ${(m==null?void 0:m.align)==="right"?"justify-end":""}`,children:[N1(g.column.columnDef.header,g.getContext()),v&&w.jsx("span",{className:"text-accent",children:v==="asc"?"▲":"▼"})]}):w.jsx("span",{className:"text-fg-faint",children:N1(g.column.columnDef.header,g.getContext())})},g.id)})})}),w.jsxs("tbody",{children:[h.length===0&&w.jsx("tr",{children:w.jsx("td",{colSpan:6,className:"py-8 text-center text-fg-faint",children:n.trim()?`no rows match “${n.trim()}”`:"no usage in this range"})}),h.map(g=>w.jsxs(D.Fragment,{children:[w.jsx("tr",{className:"cursor-pointer border-b border-line-faint transition hover:bg-bg-2/60",onClick:()=>g.toggleExpanded(),children:g.getVisibleCells().map(m=>w.jsx("td",{className:`${Iwe(m.column.columnDef.meta)}${m.column.id==="label"?" whitespace-nowrap":""} tnum`,children:N1(m.column.columnDef.cell,m.getContext())},m.id))}),g.getIsExpanded()&&g.original.breakdown.map(m=>{const v=pa(m);return w.jsxs("tr",{className:"border-b border-line-faint bg-bg-0/40 text-[11px]",children:[w.jsxs("td",{className:"py-1.5 pr-3 pl-5 text-fg-dim",colSpan:2,children:[w.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full align-middle",style:{background:Em(m.name)}}),Li(m.name)]}),w.jsx("td",{className:"tnum py-1.5 pr-3 text-right text-fg-dim",children:v>0?Mn(v):N6}),w.jsx("td",{className:"tnum hidden py-1.5 pr-3 text-right text-positive/80 sm:table-cell",children:Je(m.cacheSavings)}),w.jsx("td",{className:"tnum hidden py-1.5 pr-3 text-right text-fg-faint sm:table-cell",children:ya(m.count)}),w.jsx("td",{className:"tnum py-1.5 text-right text-cost/90",children:Je(m.cost)})]},m.name)})]},g.id))]}),h.length>0&&w.jsx("tfoot",{children:w.jsxs("tr",{className:"sticky bottom-0 z-10 bg-bg-1 text-fg shadow-[inset_0_1px_0_var(--color-line)]",children:[w.jsxs("td",{className:"py-2 pr-3 font-display text-[11px] uppercase text-fg-dim",colSpan:2,children:["total · ",h.length]}),w.jsx("td",{className:"tnum py-2 pr-3 text-right",children:Mn(d.total)}),w.jsx("td",{className:"tnum hidden py-2 pr-3 text-right text-positive sm:table-cell",children:Je(d.cacheSavings)}),w.jsx("td",{className:"tnum hidden py-2 pr-3 text-right sm:table-cell",children:Jp(d.count)}),w.jsx("td",{className:"tnum py-2 text-right text-cost",children:Je(d.cost)})]})})]})})})}const Xy=()=>O6(()=>import("./timeline-BQpqTU-a.js"),[],import.meta.url),Vd=()=>O6(()=>import("./breakdown-Bj0BAVYf.js"),[],import.meta.url);Xy();Vd();const $we=D.lazy(()=>Xy().then(e=>({default:e.CostTimeline}))),Nwe=D.lazy(()=>Xy().then(e=>({default:e.CumulativeSpend}))),Lwe=D.lazy(()=>Xy().then(e=>({default:e.CacheSavings}))),L6=D.lazy(()=>Vd().then(e=>({default:e.CostByModel}))),D6=D.lazy(()=>Vd().then(e=>({default:e.ProviderDonut}))),hF=D.lazy(()=>Vd().then(e=>({default:e.TokenComposition}))),Dwe=D.lazy(()=>Vd().then(e=>({default:e.CacheByModel}))),Fwe=({className:e})=>w.jsx("div",{className:e,"aria-hidden":!0}),Jo=({children:e})=>w.jsx(D.Suspense,{fallback:null,children:e}),pF=[{key:"overview",label:"overview"},{key:"analytics",label:"analytics"},{key:"models",label:"models"},{key:"explore",label:"explore"}],Bwe=[{value:"daily",label:"daily"},{value:"weekly",label:"weekly"},{value:"monthly",label:"monthly"}];function zwe({derived:e,periodLabel:t,scopeLabel:n,providers:r,privacyMode:i}){const o=a=>{var u;return((u=r.find(c=>c.id===a))==null?void 0:u.name)??a};return w.jsxs("div",{className:"flex flex-col gap-4",children:[w.jsx(wbe,{derived:e,periodLabel:t}),w.jsx(D.Suspense,{fallback:w.jsx(Fwe,{className:"h-[clamp(320px,42vh,560px)]"}),children:w.jsx($we,{derived:e,periodLabel:n,heightClass:"h-[clamp(320px,42vh,560px)]"})}),w.jsx(Sbe,{accounts:e.cardAccounts,nameOf:o,privacyMode:i})]})}function qwe({derived:e,scopeLabel:t}){const n=e.byProvider.length>1;return w.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[w.jsx("div",{className:"md:col-span-2",children:w.jsx(Abe,{derived:e,periodLabel:t})}),w.jsx(Jo,{children:w.jsx(L6,{derived:e,periodLabel:t})}),w.jsx(Jo,{children:n?w.jsx(D6,{derived:e,periodLabel:t}):w.jsx(hF,{derived:e,periodLabel:t})}),n&&w.jsx(Jo,{children:w.jsx(hF,{derived:e,periodLabel:t})}),w.jsx("div",{className:n?void 0:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Lwe,{derived:e,periodLabel:t})})}),w.jsx("div",{className:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Nwe,{derived:e,height:300,periodLabel:t})})})]})}function Uwe({derived:e,scopeLabel:t}){const n=e.byProvider.length>1;return w.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[w.jsx("div",{className:"md:col-span-2",children:w.jsx(Rbe,{derived:e,periodLabel:t})}),w.jsx("div",{className:n?void 0:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(L6,{derived:e,metric:"tokens",limit:12,periodLabel:t})})}),n&&w.jsx(Jo,{children:w.jsx(D6,{derived:e,periodLabel:t})}),w.jsx("div",{className:"md:col-span-2",children:w.jsx(Jo,{children:w.jsx(Dwe,{derived:e,periodLabel:t})})})]})}function Vwe({snapshot:e,filters:t,periodLabel:n,privacyMode:r}){const[i,o]=D.useState(""),[a,u]=D.useState("daily"),c=MC(),f=t.models.length===1?t.models[0]:null,h=D.useMemo(()=>jG(e,t,a),[e,t,a]),d=D.useMemo(()=>f?TG(e,t,f):null,[e,t,f]),g=D.useMemo(()=>(e?km(e,t):[]).some(v=>v.tableState!=="ready"),[e,t]),m=a!=="daily"?`showing up to ${a==="monthly"?"12 months":"12 weeks"}`:`scoped to ${n}`;return w.jsxs("div",{className:"flex flex-col gap-3",children:[w.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[w.jsxs("div",{className:"flex items-center gap-2",children:[w.jsx("span",{className:"text-xs text-fg-faint",children:"granularity:"}),w.jsx(er,{options:Bwe,value:a,onChange:u,size:"sm",ariaLabel:"row granularity",btnClassName:"px-3 py-1 text-xs capitalize transition"})]}),m&&w.jsx("span",{className:"text-xs text-fg-faint",children:m}),g&&w.jsxs("span",{className:"text-xs text-fg-faint",role:"status",children:["loading history",w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),f&&d&&w.jsxs("button",{type:"button",onClick:()=>c({kind:"model",model:f,periodLabel:n,tz:(e==null?void 0:e.tz)??"",version:(e==null?void 0:e.version)??"",...d,accounts:d.accounts.map(v=>({...v,name:EO(v.name,r)}))}),className:"flex items-center gap-1.5 rounded border border-line bg-bg-1 px-2.5 py-1 text-xs text-fg-dim transition hover:border-accent/60 hover:text-accent active:scale-[0.97] max-sm:py-2",title:"Create a shareable model image",children:[w.jsx(O3,{className:"size-3.5"}),w.jsx("span",{children:"share model"})]}),w.jsxs("div",{className:"ml-auto flex items-center gap-1.5 rounded border border-line bg-bg-1 px-2 py-1 text-xs focus-within:border-line-2",children:[w.jsx(qG,{className:"size-3 text-fg-faint"}),w.jsx("input",{type:"search",value:i,onChange:v=>o(v.target.value),onKeyDown:v=>{v.key==="Escape"&&o("")},placeholder:"filter rows…","aria-label":"Filter rows by date or model",autoComplete:"off",spellCheck:!1,className:"w-32 bg-transparent text-fg outline-none placeholder:text-fg-faint [&::-webkit-search-cancel-button]:appearance-none"}),i&&w.jsx("button",{type:"button",onClick:()=>o(""),"aria-label":"Clear filter",children:w.jsx(qu,{className:"size-3 text-fg-faint hover:text-fg","aria-hidden":!0})})]})]}),w.jsx(Mwe,{rows:h,granLabel:a,q:i})]})}function sk(e,t,n){try{return e(t)}catch(r){return GV("[nuqs] Error while parsing value `%s`: %O"+(n?" (for key `%s`)":""),t,r,n),null}}function Si(e){function t(n){if(typeof n>"u")return null;let r="";if(Array.isArray(n)){if(n[0]===void 0)return null;r=n[0]}return typeof n=="string"&&(r=n),sk(e.parse,r)}return{type:"single",eq:(n,r)=>n===r,...e,parseServerSide:t,withDefault(n){return{...this,defaultValue:n,parseServerSide(r){return t(r)??n}}},withOptions(n){return{...this,...n}}}}const L1=Si({parse:e=>e,serialize:String});Si({parse:e=>{const t=parseInt(e);return t==t?t:null},serialize:e=>""+Math.round(e)});Si({parse:e=>{const t=parseInt(e);return t==t?t-1:null},serialize:e=>""+Math.round(e+1)});Si({parse:e=>{const t=parseInt(e,16);return t==t?t:null},serialize:e=>{const t=Math.round(e).toString(16);return(t.length&1?"0":"")+t}});Si({parse:e=>{const t=parseFloat(e);return t==t?t:null},serialize:String});Si({parse:e=>e.toLowerCase()==="true",serialize:String});function uk(e,t){return e.valueOf()===t.valueOf()}Si({parse:e=>{const t=parseInt(e);return t==t?new Date(t):null},serialize:e=>""+e.valueOf(),eq:uk});Si({parse:e=>{const t=new Date(e);return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString(),eq:uk});Si({parse:e=>{const t=new Date(e.slice(0,10));return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString().slice(0,10),eq:uk});function Wwe(e){return Hwe(e)}function Hwe(e){return Si({parse:t=>{const n=t;return e.includes(n)?n:null},serialize:String})}function gF(e,t=","){const n=e.eq??((i,o)=>i===o),r=encodeURIComponent(t);return Si({parse:i=>i===""?[]:i.split(t).map((o,a)=>sk(e.parse,o.replaceAll(r,t),`[${a}]`)).filter(o=>o!=null),serialize:i=>i.map(o=>(e.serialize?e.serialize(o):String(o)).replaceAll(t,r)).join(t),eq(i,o){return i===o?!0:i.length!==o.length?!1:i.every((a,u)=>n(a,o[u]))}})}const D1=pO(),Gwe={};function Kwe(e,t={}){const n=D.useId(),r=tW(),i=nW(),{history:o="replace",scroll:a=(r==null?void 0:r.scroll)??!1,shallow:u=(r==null?void 0:r.shallow)??!0,throttleMs:c=ef.timeMs,limitUrlUpdates:f=r==null?void 0:r.limitUrlUpdates,clearOnDefault:h=(r==null?void 0:r.clearOnDefault)??!0,startTransition:d,urlKeys:g=Gwe}=t,m=Object.keys(e).join(","),v=D.useMemo(()=>Object.fromEntries(Object.keys(e).map(R=>[R,g[R]??R])),[m,JSON.stringify(g)]),x=eW(Object.values(v)),b=x.searchParams,O=D.useRef({}),_=D.useMemo(()=>Object.fromEntries(Object.keys(e).map(R=>[R,e[R].defaultValue??null])),[Object.values(e).map(({defaultValue:R})=>R).join(",")]),C=V0.useQueuedQueries(Object.values(v)),[E,P]=D.useState(()=>F1(e,g,b??new URLSearchParams,C).state),A=D.useRef(E);if(St("[nuq+ %s `%s`] render - state: %O, iSP: %s",n,m,E,b),Object.keys(O.current).join("&")!==Object.values(v).join("&")){const{state:R,hasChanged:M}=F1(e,g,b,C,O.current,A.current);M&&(St("[nuq+ %s `%s`] State changed: %O",n,m,{state:R,initialSearchParams:b,queuedQueries:C,queryRef:O.current,stateRef:A.current}),A.current=R,P(R)),O.current=Object.fromEntries(Object.entries(v).map(([F,$])=>{var L;return[$,((L=e[F])==null?void 0:L.type)==="multi"?b==null?void 0:b.getAll($):(b==null?void 0:b.get($))??null]}))}D.useEffect(()=>{const{state:R,hasChanged:M}=F1(e,g,b,C,O.current,A.current);M&&(St("[nuq+ %s `%s`] State changed: %O",n,m,{state:R,initialSearchParams:b,queuedQueries:C,queryRef:O.current,stateRef:A.current}),A.current=R,P(R))},[Object.values(v).map(R=>`${R}=${b==null?void 0:b.getAll(R)}`).join("&"),JSON.stringify(C)]),D.useEffect(()=>{const R=Object.keys(e).reduce((M,F)=>(M[F]=({state:$,query:L})=>{P(T=>{const{defaultValue:N}=e[F],B=v[F],z=$??N??null,q=T[F]??N??null;return Object.is(q,z)?(St("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). no change, skipping, resolved: %O",n,m,B,$,N,A.current),T):(A.current={...A.current,[F]:z},O.current[B]=L,St("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). updateInternalState, resolved: %O",n,m,B,$,N,A.current),A.current)})},M),{});for(const M of Object.keys(e)){const F=v[M];St("[nuq+ %s `%s`] Subscribing to sync for `%s`",n,F,m),D1.on(F,R[M])}return()=>{for(const M of Object.keys(e)){const F=v[M];St("[nuq+ %s `%s`] Unsubscribing to sync for `%s`",n,F,m),D1.off(F,R[M])}}},[m,v]);const j=D.useCallback((R,M={})=>{var q,W,Z,Y,U,K;const F=Object.fromEntries(Object.keys(e).map(ae=>[ae,null])),$=typeof R=="function"?R(mF(A.current,_))??F:R??F;St("[nuq+ %s `%s`] setState: %O",n,m,$);let L,T=0,N=!1;const B=[];for(let[ae,pe]of Object.entries($)){const he=e[ae],Ce=v[ae];if(!he||pe===void 0)continue;(M.clearOnDefault??he.clearOnDefault??h)&&pe!==null&&he.defaultValue!==void 0&&(he.eq??((se,Se)=>se===Se))(pe,he.defaultValue)&&(pe=null);const Le=pe===null?null:(he.serialize??String)(pe);D1.emit(Ce,{state:pe,query:Le});const Oe={key:Ce,query:Le,options:{history:M.history??he.history??o,shallow:M.shallow??he.shallow??u,scroll:M.scroll??he.scroll??a,startTransition:M.startTransition??he.startTransition??d}};if(((q=M==null?void 0:M.limitUrlUpdates)==null?void 0:q.method)==="debounce"||(f==null?void 0:f.method)==="debounce"||((W=he.limitUrlUpdates)==null?void 0:W.method)==="debounce"){Oe.options.shallow===!0&&console.warn(bd(422));const se=((Z=M==null?void 0:M.limitUrlUpdates)==null?void 0:Z.timeMs)??(f==null?void 0:f.timeMs)??((Y=he.limitUrlUpdates)==null?void 0:Y.timeMs)??ef.timeMs,Se=V0.push(Oe,se,x,i);T<se&&(L=Se,T=se)}else{const se=((U=M==null?void 0:M.limitUrlUpdates)==null?void 0:U.timeMs)??((K=he==null?void 0:he.limitUrlUpdates)==null?void 0:K.timeMs)??(f==null?void 0:f.timeMs)??M.throttleMs??he.throttleMs??c;B.push(V0.abort(Ce)),Ip.push(Oe,se),N=!0}}const z=B.reduce((ae,pe)=>pe(ae),N?Ip.flush(x,i):Ip.getPendingPromise(x));return L??z},[m,o,u,a,c,f==null?void 0:f.method,f==null?void 0:f.timeMs,d,v,x.updateUrl,x.getSearchParamsSnapshot,x.rateLimitFactor,i,_]);return[D.useMemo(()=>mF(E,_),[E,_]),j]}function F1(e,t,n,r,i,o){let a=!1;const u=Object.entries(e).reduce((c,[f,h])=>{const d=(t==null?void 0:t[f])??f,g=r[d],m=h.type==="multi"?[]:null,v=g===void 0?(h.type==="multi"?n==null?void 0:n.getAll(d):n==null?void 0:n.get(d))??m:g;return i&&o&&DF(i[d]??m,v)?(c[f]=o[f]??null,c):(a=!0,c[f]=(oW(v)?null:sk(h.parse,v,d))??null,i&&(i[d]=v),c)},{});if(!a){const c=Object.keys(e),f=Object.keys(o??{});a=c.length!==f.length||c.some(h=>!f.includes(h))}return{state:u,hasChanged:a}}function mF(e,t){return Object.fromEntries(Object.keys(e).map(n=>[n,e[n]??t[n]??null]))}const Xwe=["7d","30d","90d","mtd","all"];function Ywe(){const[e,t]=Kwe({p:gF(L1).withDefault([]),m:gF(L1).withDefault([]),a:L1.withDefault("all"),period:Wwe(Xwe).withDefault(CG.period)},{history:"replace"}),n=D.useMemo(()=>({providers:e.p,models:e.m,account:e.a,period:e.period}),[e.p,e.m,e.a,e.period]),r=D.useCallback(i=>{t(o=>{const a={providers:o.p,models:o.m,account:o.a,period:o.period},u=typeof i=="function"?i(a):i;return{p:u.providers,m:u.models,a:u.account,period:u.period}})},[t]);return[n,r]}function Qwe(){const[e,t]=D.useState(null),[n,r]=D.useState("connecting"),i=D.useRef(null);return D.useEffect(()=>{let o=!1;const a=Ud(),u=ebe(f=>{o||r(f)}),c=a.subscribeSnapshot(f=>{o||(t(f),r("live"))});return i.current=c,()=>{var f;o=!0,u(),(f=i.current)==null||f.call(i),i.current=null}},[]),{snapshot:e,conn:n}}const fO=e=>`/${e}`,F6=D.createContext(null),Yy=()=>{const e=D.useContext(F6);if(!e)throw new Error("useDashboard outside provider");return e};function Jwe(e=1e3){const[t,n]=D.useState(()=>Date.now());return D.useEffect(()=>{const r=setInterval(()=>n(Date.now()),e);return()=>clearInterval(r)},[e]),t}function Zwe(){const[e,t]=D.useState(()=>document.documentElement.classList.contains("light")?"light":"dark");return D.useEffect(()=>{document.documentElement.classList.toggle("light",e==="light")},[e]),[e,()=>{const r=e==="dark"?"light":"dark";try{localStorage.setItem("tokmon-theme",r)}catch{}t(r)}]}function eSe({theme:e,onToggle:t}){return w.jsx("button",{type:"button",onClick:t,title:e==="dark"?"Switch to light":"Switch to dark","aria-label":"Toggle theme",className:"rounded border border-line bg-bg-1 p-1.5 text-fg-dim transition hover:border-line-2 hover:text-fg max-sm:p-2.5",children:e==="dark"?w.jsx(UG,{className:"size-3.5"}):w.jsx(VG,{className:"size-3.5"})})}function tSe({conn:e,freshAt:t}){const n=Jwe(),r=e==="live"?"var(--color-positive)":e==="error"?"var(--color-warning)":"var(--color-cost)",i=t?SG(t,n):null,o=e==="live"?i??"live":e==="connecting"?"connecting…":e==="reconnecting"?i?`reconnecting · ${i}`:"reconnecting…":i?`offline · ${i}`:"offline";return w.jsxs("span",{className:"flex items-center gap-1.5 text-xs",role:"status","aria-label":e==="live"?"live":e,children:[w.jsxs("span",{className:"relative flex size-2",children:[e==="live"&&w.jsx("span",{className:"absolute inline-flex size-full animate-ping rounded-full opacity-60",style:{background:r}}),w.jsx("span",{className:"relative inline-flex size-2 rounded-full",style:{background:r}})]}),w.jsx("span",{className:"inline-block truncate text-fg-dim max-sm:max-w-[7rem]","aria-hidden":!0,children:o})]})}function B1({label:e}){return w.jsxs("div",{className:"flex min-h-[50vh] flex-col items-center justify-center gap-2 text-sm text-fg-dim",children:[w.jsxs("span",{className:"font-display text-lg text-fg-dim",children:["tokmon",w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),w.jsx("span",{className:"text-fg-faint",children:e})]})}function nSe({onOpen:e}){return w.jsx("button",{type:"button",onClick:e,title:"Settings","aria-label":"Open settings",className:"rounded border border-line bg-bg-1 p-1.5 text-fg-dim transition hover:border-line-2 hover:text-fg max-sm:p-2.5",children:w.jsx(WG,{className:"size-3.5"})})}function rSe(){var M,F;const{snapshot:e,conn:t}=Qwe(),[n,r]=Ywe(),[i,o]=Zwe(),[a,u]=D.useState(!1),[c,f]=D.useState(Ho.privacyMode);D.useEffect(()=>_6($=>f($.privacyMode)),[]);const h=D.useMemo(()=>DG(e,n),[e,n]),d=((M=_3.find($=>$.key===n.period))==null?void 0:M.label)??n.period,g=n.period==="all"?void 0:d,m=uG({select:$=>$.location.pathname}),v=((F=pF.find($=>fO($.key)===m))==null?void 0:F.key)??"overview";D.useEffect(()=>{var q;if(!e)return;const $=new Set(e.providers.map(W=>W.id)),L=new Set(e.accounts.map(W=>W.id)),T=n.providers.filter(W=>$.has(W)),N=n.account==="all"||L.has(n.account)?n.account:"all",B=new Set;for(const W of e.accounts)for(const Z of((q=W.table)==null?void 0:q.monthly)??[])for(const Y of Z.breakdown)B.add(Y.name);const z=B.size>0?n.models.filter(W=>B.has(W)):n.models;(T.length!==n.providers.length||N!==n.account||z.length!==n.models.length)&&r(W=>({...W,providers:T,account:N,models:z}))},[e,n,r]);const x=(e==null?void 0:e.accounts.filter($=>$.hasUsage))??[],b=x.length>0,O=((e==null?void 0:e.accounts)??[]).some(J1),_=((e==null?void 0:e.accounts)??[]).some($=>$.hasBilling&&!J1($)),C=b&&x.every($=>$.table!=null),E=D.useRef(!1);D.useEffect(()=>{C&&(E.current=!0)},[C]);const[P,A]=D.useState(!1);D.useEffect(()=>{const $=setTimeout(()=>A(!0),12e3);return()=>clearTimeout($)},[]);const j=!b||C||E.current||P,R=D.useMemo(()=>e?{snapshot:e,filters:n,derived:h,periodLabel:d,scopeLabel:g,privacyMode:c}:null,[e,n,h,d,g,c]);return w.jsxs("div",{className:"min-h-screen",children:[w.jsxs("header",{className:"relative z-30 border-b border-line bg-bg-0/80 backdrop-blur",children:[w.jsxs("div",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px]",children:[w.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 py-3.5",children:[w.jsx("span",{className:"font-display text-2xl text-fg-bright",children:"TOKMON"}),w.jsxs("span",{className:"hidden text-sm text-fg-faint sm:inline",children:["~/usage ",w.jsx("span",{className:"text-prompt",children:"$"})," ",w.jsx("span",{className:"text-fg-dim",children:v}),w.jsx("span",{className:"cursor-blink text-accent",children:"▋"})]}),w.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-3",children:[w.jsx(tSe,{conn:t,freshAt:(e==null?void 0:e.generatedAt)??null}),w.jsx(nSe,{onOpen:()=>u(!0)}),w.jsx(eSe,{theme:i,onToggle:o}),j&&(b||O)&&w.jsx($ce,{derived:h,periodLabel:d,tz:(e==null?void 0:e.tz)??"",version:(e==null?void 0:e.version)??""})]})]}),w.jsx("nav",{className:"-mb-px flex items-center gap-1 overflow-x-auto",children:pF.map($=>w.jsx(bO,{to:fO($.key),className:`relative shrink-0 border-b-2 px-3 py-2 font-display text-xs uppercase tracking-wider transition ${v===$.key?"border-accent text-fg-bright":"border-transparent text-fg-faint hover:text-fg-dim"}`,children:$.label},$.key))})]}),w.jsx(KG,{snapshot:e,derived:h,filters:n,setFilters:r,privacyMode:c})]}),w.jsxs("main",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px] py-5",children:[(e==null?void 0:e.seeded)&&w.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim",role:"status",children:[w.jsx("span",{className:"inline-flex size-2 rounded-full",style:{background:"var(--color-cost)"},"aria-hidden":!0}),"showing cached data — refreshing…"]}),e?!b&&!O?_&&!P&&t!=="error"?w.jsx(B1,{label:"reading billing…"}):w.jsx("div",{className:"rounded-md border border-line bg-bg-1 p-8 text-center text-sm text-fg-dim",children:"No providers detected. Open tokmon, enable a provider, then refresh."}):!j||!R?w.jsx(B1,{label:t==="error"?"connection lost — retrying…":"reading usage history…"}):w.jsx(F6.Provider,{value:R,children:w.jsx(v3,{})}):w.jsx(B1,{label:t==="error"?"connection lost — retrying…":"reading usage…"})]}),w.jsxs("footer",{className:"mx-auto max-w-[1600px] px-5 2xl:max-w-[1920px] py-6 text-center text-[11px] text-fg-faint",children:["tokmon",e!=null&&e.version?` v${e.version}`:""," · by David Ilie · live LLM usage dashboard"]}),a&&w.jsx(ybe,{snapshot:e,onClose:()=>u(!1)})]})}function yF(){const{derived:e,periodLabel:t,scopeLabel:n,snapshot:r,privacyMode:i}=Yy();return w.jsx("div",{children:w.jsx(zwe,{derived:e,periodLabel:t,scopeLabel:n,providers:r.providers,privacyMode:i})})}function iSe(){const{derived:e,scopeLabel:t}=Yy();return w.jsx("div",{children:w.jsx(qwe,{derived:e,scopeLabel:t})})}function oSe(){const{derived:e,scopeLabel:t}=Yy();return w.jsx("div",{children:w.jsx(Uwe,{derived:e,scopeLabel:t})})}function aSe(){const{snapshot:e,filters:t,periodLabel:n,privacyMode:r}=Yy();return w.jsx("div",{children:w.jsx(Vwe,{snapshot:e,filters:t,periodLabel:n,privacyMode:r})})}const dO=WH({component:rSe}),Rp=(e,t)=>g3({getParentRoute:()=>dO,path:fO(e),component:t}),sSe=dO.addChildren([g3({getParentRoute:()=>dO,path:"/",component:yF}),Rp("overview",yF),Rp("analytics",iSe),Rp("models",oSe),Rp("explore",aSe)]),uSe=iG({routeTree:sSe,history:eH(),defaultViewTransition:!0});function lSe(){return w.jsx(sG,{router:uSe})}WV.createRoot(document.getElementById("root")).render(w.jsx(D.StrictMode,{children:w.jsx(gW,{children:w.jsx(Mce,{children:w.jsx(lSe,{})})})}));export{ir as $,Pa as A,Of as B,vSe as C,Tn as D,K9 as E,Jm as F,Oce as G,ds as H,Me as I,Xt as J,Y_ as K,ay as L,di as M,qr as N,Dt as O,Gy as P,ws as Q,TQ as R,er as S,eo as T,me as U,Ii as V,Rs as W,ly as X,cy as Y,ba as Z,li as _,Mq as a,JO as a0,vne as a1,ci as a2,co as a3,Ns as a4,fSe as a5,pSe as a6,Li as a7,Mn as a8,S3 as a9,pa as aa,ip as ab,xs as b,gSe as c,wG as d,mSe as e,Hae as f,_ce as g,Je as h,Ve as i,w as j,H as k,Ne as l,Cce as m,_z as n,Nee as o,xa as p,lt as q,D as r,ySe as s,Fee as t,hSe as u,$e as v,pg as w,bn as x,Qe as y,dSe as z};