@deslop/gateway 0.0.0-stage → 0.1.1223

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # Deslop Gateway
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ One MCP endpoint for every MCP server you connect; add servers on its page.
4
+
5
+ ```bash
6
+ npm install --global @deslop/gateway
7
+ gateway service install --url https://gateway.mp281x.xyz --auth https://auth.mp281x.xyz --admins <github-id>
8
+ ```
9
+
10
+ - **Register** only `https://<gateway>/mcp` in each harness; tools are named `<server>__<tool>`.
11
+ - **Admins** (`--admins`) add and connect servers; everyone signed in shares them.
12
+ - **Own tool**: `list_mcp_connections` explains a missing or failing server.
13
+
14
+ Common flags and service commands: [Deslop app runtime](https://github.com/MP281X/deslop/blob/main/packages/runtime/README.md).
Binary file
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./rolldown-runtime-WkwZ5CU-.js";import{$ as n,$a as r,$i as i,$n as a,$r as o,$t as s,A as c,Aa as l,Ai as u,An as d,Ar as f,At as p,B as m,Ba as h,Bi as g,Bn as _,Br as v,Bt as y,C as b,Ca as x,Ci as S,Cn as C,Cr as w,Ct as T,D as ee,Da as te,Di as E,Dn as ne,Dr as re,Dt as ie,E as ae,Ea as oe,Ei as se,En as ce,Er as D,Et as le,F as ue,Fa as de,Fi as fe,Fn as pe,Fr as me,Ft as he,G as ge,Ga as _e,Gi as ve,Gn as ye,Gr as be,Gt as xe,Ha as O,Hi as Se,Hn as Ce,Hr as we,Ht as Te,I as Ee,Ia as De,Ii as Oe,In as ke,Ir as Ae,It as je,J as Me,Ja as Ne,Ji as Pe,Jn as Fe,Jr as k,Jt as Ie,K as Le,Ka as Re,Ki as ze,Kn as Be,Kr as Ve,Kt as He,L as Ue,La as A,Li as We,Ln as Ge,Lr as Ke,Lt as qe,M as Je,Ma as Ye,Mi as Xe,Mn as j,Mr as Ze,Mt as Qe,N as $e,Na as et,Ni as tt,Nn as nt,Nr as rt,Nt as it,O as at,Oa as ot,Oi as st,On as ct,Or as M,Ot as lt,P as ut,Pa as dt,Pi as ft,Pn as pt,Pr as mt,Pt as ht,Q as gt,Qa as _t,Qi as vt,Qn as yt,Qr as bt,Qt as xt,R as St,Ra as Ct,Ri as wt,Rn as Tt,Rr as N,Rt as Et,S as Dt,Sa as Ot,Si as kt,Sn as At,Sr as jt,St as Mt,T as Nt,Ta as Pt,Ti as Ft,Tn as It,Tr as Lt,Tt as Rt,Ua as zt,Ui as Bt,Un as Vt,Ur as Ht,Ut,Va as Wt,Vi as Gt,Vn as Kt,Vr as qt,Vt as Jt,Wa as Yt,Wi as Xt,Wn as Zt,Wr as Qt,Wt as $t,X as en,Xa as P,Xi as tn,Xn as nn,Xr as rn,Xt as an,Y as on,Ya as sn,Yi as cn,Yn as ln,Yr as un,Yt as dn,Z as fn,Za as pn,Zi as mn,Zn as hn,Zr as gn,Zt as _n,_ as vn,_a as yn,_i as bn,_n as F,_r as xn,_t as Sn,a as Cn,aa as wn,ai as Tn,an as En,ar as Dn,at as I,b as On,ba as kn,bi as An,bn as jn,br as Mn,bt as Nn,c as Pn,ca as Fn,ci as In,cn as Ln,cr as Rn,ct as zn,d as Bn,da as Vn,di as L,dn as Hn,dr as Un,dt as Wn,ea as Gn,ei as Kn,en as qn,eo as Jn,er as Yn,et as Xn,f as Zn,fa as Qn,fi as $n,fn as er,fr as tr,ft as R,g as nr,ga as rr,gi as ir,gn as ar,gr as or,gt as sr,h as cr,ha as lr,hi as ur,hn as dr,hr as fr,ht as pr,i as mr,ia as hr,ii as gr,in as _r,ir as vr,it as yr,j as br,ja as xr,ji as Sr,jn as Cr,jr as wr,jt as Tr,k as Er,ka as Dr,ki as Or,kn as z,kr,kt as Ar,l as jr,la as Mr,li as B,ln as Nr,lr as Pr,lt as Fr,m as Ir,ma as Lr,mi as Rr,mn as V,mr as zr,mt as Br,n as Vr,na as Hr,ni as Ur,nn as Wr,no as Gr,nr as Kr,nt as qr,o as Jr,oa as Yr,oi as Xr,on as Zr,or as Qr,ot as $r,p as ei,pa as ti,pi as ni,pn as ri,pr as ii,pt as ai,q as oi,qa as si,qi as ci,qn as li,qr as ui,qt as di,r as fi,ra as pi,ri as mi,rn as hi,rr as gi,rt as _i,s as vi,sa as yi,si as bi,sn as xi,sr as Si,st as Ci,t as wi,ta as Ti,ti as Ei,tn as Di,to as Oi,tr as ki,tt as Ai,u as ji,ua as Mi,ui as H,un as Ni,ur as Pi,ut as Fi,v as Ii,va as Li,vi as U,vn as Ri,vr as zi,vt as Bi,w as Vi,wa as Hi,wi as Ui,wn as Wi,wr as Gi,wt as Ki,x as qi,xa as Ji,xi as Yi,xn as Xi,xr as Zi,xt as Qi,y as $i,ya as ea,yi as ta,yn as na,yr as ra,yt as ia,z as aa,za as oa,zi as sa,zn as ca,zr as la,zt as ua}from"./index-MrBwOWwH.js";var da={"~effect/Ref":{_A:_t},..._e,toJSON(){return{_id:`Ref`,ref:this.ref}}},fa=e=>{let t=Object.create(da);return t.ref=jt(e),t},pa=pn(2,(e,t)=>L(()=>{let[n,r]=t(e.ref.current);return e.ref.current=r,n})),ma=pn(2,(e,t)=>L(()=>e.ref.current=t(e.ref.current))),ha=()=>(e,t)=>{let n=Vn()(e),r=Or(n,t.makeEffect??Sn(t.group,{...t,flatten:!0}));n.runtime=(t.runtime??p)(typeof t.protocol==`function`?e=>Xe(r,Sr(t.protocol(e))):Xe(r,Sr(t.protocol))),n.mutation=T(r=>{let i=t.group.requests.get(r);return n.runtime.fn()(qt(function*({headers:e,payload:t,reactivityKeys:i}){let a=(yield*n)(r,t,{headers:e});return yield*i?Jt(a,i):a})).pipe(Tr({key:`AtomRpc:mutation:${JSON.stringify([e,r])}`,schema:Te({success:i.successSchema,error:ga(i)})}))});let i=T(e=>{let{headers:r,payload:i,reactivityKeys:a,tag:o,timeToLive:s}=e,c=t.group.requests.get(o),l=Qi(c.successSchema),u=l?n.runtime.pull(Un(n.use(e=>B(e(o,i,{headers:r}))))):n.runtime.atom(n.use(e=>e(o,i,{headers:r})));return a&&(u=n.runtime.factory.withReactivity(a)(u)),!l&&e.serializationKey&&(u=Tr(u,{key:`AtomRpc:${e.tag}:${e.serializationKey}`,schema:Te({success:c.successSchema,error:ga(c)})})),s&&(u=Mi(s)?Qe(u,s):le(u)),u});return n.query=(e,t,n)=>{let r={tag:e,payload:t,headers:n?.headers?ln(n.headers):void 0,reactivityKeys:n?.reactivityKeys,timeToLive:n?.timeToLive===void 0?void 0:Mr(n.timeToLive),serializationKey:n?.serializationKey};return i(r)},n},ga=e=>Xi([e.errorSchema,...Array.from(e.middlewares,e=>e.error),Bi]),_a={add(...e){let t=new Map(this.requests);for(let n of e)t.set(n._tag,n);return va({requests:t,annotations:this.annotations})},merge(...e){let t=new Map(this.requests),n=new Map(this.annotations.mapUnsafe);for(let r of e){for(let[e,n]of r.requests)t.set(e,n);for(let[e,t]of r.annotations.mapUnsafe)n.set(e,t)}return va({requests:t,annotations:rr(n)})},omit(...e){let t=new Map(this.requests);for(let n of e)t.delete(n);return va({requests:t,annotations:this.annotations})},middleware(e){let t=new Map;for(let[n,r]of this.requests)t.set(n,r.middleware(e));return va({requests:t,annotations:this.annotations})},toHandlers(e){let t=this;return be(function*(){let n=yield*rt(),r=ui(e)?yield*e:e,i=new Map;return t.requests.forEach((e,t)=>{i.set(e.key,{tag:e._tag,handler:r[t],context:n})}),rr(i)})},prefix(e){let t=new Map;for(let n of this.requests.values()){let r=n.prefix(e);t.set(r._tag,r)}return va({requests:t,annotations:this.annotations})},toLayer(e){return u(this.toHandlers(e))},of:_t,toLayerHandler(e,t){let n=this;return u(be(function*(){let r=yield*rt(),i=ui(t)?yield*t:t,a=new Map,o=n.requests.get(e);return a.set(o.key,{handler:i,context:r}),rr(a)}))},accessHandler(e){return mt(t=>{let n=this.requests.get(e),{handler:r,context:i}=Lr(t,n.key);return B((e,t)=>{t.rpc=n;let a=r(e,t),o=ia(a)?a.value:a;return ui(o)?bt(o,i):Si(o,i)})})},annotate(e,t){return va({requests:this.requests,annotations:Qn(this.annotations,e,t)})},annotateRpcs(e,t){return this.annotateRpcsMerge(lr(e,t))},annotateMerge(e){return va({requests:this.requests,annotations:yn(this.annotations,e)})},annotateRpcsMerge(e){let t=new Map;for(let[n,r]of this.requests)t.set(n,r.annotateMerge(yn(e,r.annotations)));return va({requests:t,annotations:this.annotations})}},va=e=>Object.assign(function(){},_a,{requests:e.requests,annotations:e.annotations}),ya=(...e)=>va({requests:new Map(e.map(e=>[e._tag,e])),annotations:ti()}),ba=`~effect/rpc/RpcMiddleware`,xa=()=>(e,t)=>{let n=Re(),r;n!==0&&(si(2),r=new globalThis.Error,si(n));function i(){}let a=i;return Object.setPrototypeOf(i,Object.getPrototypeOf(Vn(e))),i.key=e,Object.defineProperty(i,"stack",{get(){return r?.stack}}),a[ba]=ba,a.error=t?.error??ri,a.requiredForClient=t?.requiredForClient??!1,i},Sa=(e,t)=>u(be(function*(){let n=(yield*rt()).pipe(Li(tt)),r=ui(t)?yield*t:t;return rr(new Map([[`${e.key}/Client`,e=>bn(r(e),e=>yn(n,e))]]))})),Ca={name:`ellipsis`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]],aliases:[`more-horizontal`]};Ca.node;var wa=pr(Ca),Ta={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};Ta.node;var Ea=pr(Ta),Da={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};Da.node;var Oa=pr(Da),ka={name:`server`,size:24,node:[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]};ka.node;var Aa=pr(ka),ja={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};ja.node;var Ma=pr(ja),Na=t((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,E());else{var t=n(l);t!==null&&ie(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function ee(){return g?!0:!(e.unstable_now()-T<w)}function te(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&ee());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&ie(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?E():S=!1}}}var E;if(typeof y==`function`)E=function(){y(te)};else if(typeof MessageChannel<`u`){var ne=new MessageChannel,re=ne.port2;ne.port1.onmessage=te,E=function(){re.postMessage(null)}}else E=function(){_(te,0)};function ie(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,ie(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,E()))),r},e.unstable_shouldYield=ee,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Pa=t(((e,t)=>{t.exports=Na()})),W=e(Gr(),1),Fa=e(Pa(),1);function Ia(e){let t=Fa.unstable_scheduleCallback(4,e);return()=>Fa.unstable_cancelCallback(t)}var La=W.createContext(y({scheduleTask:Ia,defaultIdleTTL:400})),Ra=new WeakMap,za=0,Ba=new Set;function Va(e){za++;try{return e()}finally{za--}}function Ha(e){if(za===0)return e();Ba.size===0&&queueMicrotask(Ua),Ba.add(e)}function Ua(){for(let e of Ba)Ba.delete(e),e()}function Wa(e,t){let n=Ra.get(e);n===void 0&&(n=new WeakMap,Ra.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=0,a,o={subscribe(n){i++;let r=e.subscribe(t,()=>Ha(n));return()=>{i--,Ba.delete(n),r()}},snapshot(){return Va(()=>e.get(t))},getServerSnapshot(){return(i===0||a===void 0)&&(a={value:Va(()=>Rt(t,e))}),a.value}};return n.set(t,o),o}function Ga(e,t){let n=Wa(e,t);return W.useEffect(Ua),W.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}function Ka(e,t,n){let r=Wa(e,t),i=W.useMemo(()=>{let e;return t=>(e!==void 0&&Object.is(e.source,t)||(e={source:t,value:n(t)}),e.value)},[n]);return W.useEffect(Ua),W.useSyncExternalStore(r.subscribe,()=>i(r.snapshot()),()=>i(r.getServerSnapshot()))}var qa=(e,t)=>{let n=W.useContext(La);return t?Ka(n,e,t):Ga(n,e)};function Ja(e,t){W.useEffect(()=>e.mount(t),[t,e])}function Ya(e,t,n){return n?.mode===`promise`||n?.mode===`promiseExit`?W.useCallback(r=>{e.set(t,r);let i=mi(ua(e,t,{suspendOnWaiting:!0}));return n.mode===`promise`?i.then(Xa):i},[e,t,n.mode]):W.useCallback(n=>{e.set(t,typeof n==`function`?n(e.get(t)):n)},[e,t])}var Xa=e=>{if(tn(e))return e.value;throw yi(e.cause)},Za=(e,t)=>{let n=W.useContext(La);return Ja(n,e),Ya(n,e,t)},Qa=(e,t)=>{let n=W.useContext(La);return[Ga(n,e),Ya(n,e,t)]},$a={suspendOnWaiting:new WeakMap,default:new WeakMap};function eo(e,t,n){let r=n?$a.suspendOnWaiting:$a.default,i=r.get(e);i===void 0&&(i=new WeakMap,r.set(e,i));let a=i.get(t);return a===void 0&&(a=new Promise(r=>{let a=e.subscribe(t,e=>{e._tag===`Initial`||n&&e.waiting||(setTimeout(a,1e3),r(),i.delete(t))})}),i.set(t,a)),a}function to(e,t,n){let r=Ga(e,t);if(r._tag===`Initial`||n&&r.waiting)throw eo(e,t,n);return r}var no=(e,t)=>{let n=to(W.useContext(La),e,t?.suspendOnWaiting??!1);if(n._tag===`Failure`&&!t?.includeFailure)throw yi(n.cause);return n};Fn(`MachineSchemaEncodeError`);var G=class extends Fn(`MachineSchemaDecodeError`){},ro=class extends Fn(`InfiniteTransitionError`){},io=class extends Fn(`StartupError`){},ao=class extends Fn(`ChildAlreadyExistsError`){};Fn(`ProcessLocalError`);var oo=class extends Fn(`StoppedError`){},so=e=>e instanceof ro||e instanceof G,co=e=>so(e)?N(e):me(e),lo=e=>so(e)||e instanceof io?e:new io({cause:i(e)}),K=e=>e,uo=`~effect/Machine/Target`,fo=Symbol(`effect/Machine/TargetSnapshot`),po=Symbol(`effect/Machine/StateInput`),mo=Symbol(`effect/Machine/HistoryTarget`),ho=Symbol(`effect/Machine/InitialTarget`),go=Symbol(`effect/Machine/ChoiceTarget`),_o=Symbol(`effect/Machine/NoTarget`),vo=Symbol(`effect/Machine/Declined`),yo=Symbol(`effect/Machine/TargetSelection`),bo=Symbol(`effect/Machine/StateUpdate`),xo=Symbol(`effect/Machine/CombinedTarget`),So=Symbol(`effect/Machine/SelectedBranch`),Co=(e,t,n,r)=>Object.freeze({[yo]:yo,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),wo=Co(`none`,void 0,`local`),To=e=>P(e,yo),Eo=(e,t)=>Object.freeze({[bo]:bo,path:e,value:t}),Do=e=>P(e,bo),Oo=(e,t)=>Object.freeze({[xo]:xo,target:e,update:t}),ko=e=>P(e,xo),Ao=(e,t,n,r)=>Object.freeze({[So]:So,owner:e,branchIndex:t,branchKey:n,result:r}),jo=e=>P(e,So),Mo=Object.freeze({[_o]:_o}),No=()=>Mo,Po=e=>P(e,_o),Fo=Object.freeze({[vo]:vo}),Io=()=>Fo,Lo=e=>P(e,vo),Ro=(e,t)=>({[mo]:mo,path:e,parent:t}),zo=e=>P(e,mo),Bo=(e,t,n)=>({[ho]:ho,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),Vo=e=>P(e,ho),Ho=(e,t,n)=>({[go]:go,path:e,parent:t,...n===void 0?{}:{values:n}}),Uo=e=>P(e,go),Wo=(e,t)=>{if(!z(t)&&t.type===`history`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`history`,history:t.history===`deep`?`deep`:`shallow`,initial:void 0,states:void 0};if(!z(t)&&t.type===`choice`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`choice`,history:void 0,initial:void 0,states:void 0};if(z(t))return{schema:t,output:void 0,annotations:nt(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=P(t,`schema`)&&z(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:nt(n);if(t.type===`parallel`&&!P(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(P(t,`states`)){if(t.type===`final`)throw Error(`Machine.make expected compound state "${e}" to be active`);if(t.type===`parallel`)return{schema:n,output:z(t.output)?t.output:void 0,annotations:r,type:`parallel`,history:void 0,initial:void 0,states:t.states};let i=`initial`in t?t.initial:void 0;if(typeof i!=`string`)throw Error(`Machine.make expected compound state "${e}" to declare an initial child`);return{schema:n,output:void 0,annotations:r,type:`compound`,history:void 0,initial:i,states:t.states}}let i=z(t.output)?t.output:void 0;return t.type===`final`?{schema:n,output:i,annotations:r,type:`final`,history:void 0,initial:void 0,states:void 0}:{schema:n,output:void 0,annotations:r,type:`atomic`,history:void 0,initial:void 0,states:void 0}},Go=e=>{let t=new Map,n=0,r=(e,i)=>{let a=[];for(let o of Object.keys(e)){if(o.includes(`.`))throw Error(`Machine state keys cannot contain ".": "${o}"`);let s=i===void 0||i===``?o:`${i}.${o}`,c=Wo(s,e[o]),l,u,d={path:s,key:o,annotations:c.annotations,order:n};switch(c.type){case`atomic`:l={...d,type:`atomic`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:void 0};break;case`compound`:l={...d,type:`compound`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:s===``?c.initial:`${s}.${c.initial}`},u=c.states;break;case`parallel`:l={...d,type:`parallel`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0},u=c.states;break;case`final`:l={...d,type:`final`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0};break;case`history`:if(i===void 0)throw Error(`Machine history state "${s}" must belong to a parent state`);l={...d,type:`history`,schema:void 0,output:void 0,history:c.history,parent:i,children:[],initial:void 0};break;case`choice`:if(i===void 0)throw Error(`Machine choice state "${s}" must belong to a parent state`);l={...d,type:`choice`,schema:void 0,output:void 0,history:void 0,parent:i,children:[],initial:void 0}}if(t.set(s,l),n+=1,c.type!==`history`&&c.type!==`choice`&&(a.push(s),u!==void 0)){let e=r(u,s);if(l.type===`compound`){if(!e.includes(l.initial)&&t.get(l.initial)?.type!==`choice`)throw Error(`Machine.make expected compound state "${s}" initial child to exist`);l={...l,children:e}}else if(l.type===`parallel`)l={...l,children:e};else throw Error(`Machine state "${s}" cannot declare child states`);t.set(s,l)}}return a};return{byPath:t,roots:r(e,void 0)}},Ko=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],qo=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,Jo=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=K(e).handlers[n.path];if(r===void 0)continue;if(n.type===`choice`){let e=r.choice;e!==void 0&&t.push({source:n.path,trigger:{type:`choice`},reenter:!1,acceptance:`required`,branches:Ko(e)});continue}for(let e of Reflect.ownKeys(r.on??{})){let i=r.on?.[e];t.push({source:n.path,trigger:{type:`event`,event:e},reenter:P(i,`reenter`)&&i.reenter===!0,acceptance:qo(i),branches:Ko(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:qo(r.always),branches:Ko(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:qo(r.onDone),branches:Ko(r.onDone)});let i=r.invoke===void 0?[]:Array.isArray(r.invoke)?r.invoke:[r.invoke];for(let e of i){let r=`child`in e?String(e.child.id):String(e.id);for(let i of[`element`,`done`,`failure`,`snapshot`]){let a=i===`element`?e.onElement:i===`done`?e.onDone:i===`failure`?e.onFailure:e.onSnapshot;a!==void 0&&t.push({source:n.path,trigger:{type:`invoke`,id:r,outcome:i},reenter:typeof a==`object`&&!!a&&a.reenter===!0,acceptance:qo(a),branches:Ko(a)})}}}return t},Yo=(e,t,n)=>({[uo]:uo,[fo]:n?.snapshot,path:e,value:t,values:n?.values}),Xo=e=>P(e,uo),Zo=e=>({[po]:po,input:e}),Qo=e=>P(e,po),$o=e=>P(e,`path`)&&P(e,`value`),es=(e,t,n)=>{if(e.path===t)return O(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return h();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),P(e,`state`)&&$o(e.state))return es(e.state,t,n);if(P(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if($o(r)){let e=es(r,t,n);if(A(e))return e}}return h()},q=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},ts=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},ns=new WeakMap,rs=Symbol(`effect/Machine/EventConstruction`),is=new WeakMap,as=new WeakMap,os=new WeakMap,ss=e=>{let t=e,n=as.get(t);if(n!==void 0)return n;let r=C(pe(e));return as.set(t,r),r},cs=e=>{let t=e,n=os.get(t);if(n!==void 0)return n;let r=Wi(pe(e));return os.set(t,r),r},ls=Symbol.for(`effect/Machine/protocol`),us=e=>{let t=e[ls];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},ds=(e,t)=>{Object.defineProperty(e,ls,{value:t,enumerable:!1})},fs=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),P(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&P(t,`make`)&&n(t)};for(let t of e)n(t);return t},ps=(e,t)=>{let n=ns.get(e);if(n===void 0)throw Error(`Machine expected an event protocol created with Machine.events, Machine.internalEvents, or Machine.emittedEvents`);if(t!==void 0&&n.kind!==t)throw Error(`Machine expected a ${t} event protocol`);return n},ms=e=>ps(e.events,`public`).schemas,hs=e=>ps(e.internalEvents,`internal`).schemas,gs=e=>ps(e.emittedEvents,`emitted`).schemas,_s=e=>{let t=ms(e),n=hs(e),r=gs(e),i=new Set(Reflect.ownKeys(e.events));for(let t of Reflect.ownKeys(e.internalEvents))if(i.has(t))throw Error(`Public and internal machine event tags must be disjoint: ${String(t)}`);let a=[...t,...n];ds(e,{event:Xi(a),emit:Xi(r),eventConstructors:fs(a),emissionConstructors:fs(r)})},vs=(e,t)=>ds(t,us(e)),ys=e=>P(e,`_tag`)?String(e._tag):void 0,bs=(e,t,n,r)=>{let i=r,a;if(typeof r==`object`&&r)try{i={...r}}catch(e){i=void 0,a=e}let o={[rs]:rs,_tag:n};return is.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},xs=e=>typeof e==`object`&&!!e&&is.has(e),Ss=(e,t)=>{let n=[],r=e=>{if(P(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null)for(let t of Reflect.ownKeys(e.cases))r(Reflect.get(e.cases,t));else if(P(e,`members`)&&Array.isArray(e.members))for(let t of e.members)r(t);else n.push(e)};for(let e of t)r(e);let i=Object.create(null),a=e=>Tt(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:li(e)?[e.symbol]:Ge(e)?e.enums.map(([,e])=>e):Be(e)?e.types.flatMap(a):Vt(e)?a(e.thunk()):[],o=e=>{let t=Fe(e.ast);if(_(t)){let e=t.propertySignatures.find(({name:e})=>e===`_tag`),n=e===void 0?[]:a(e.type);if(n.length>0)return n}try{return Xi([e]).pipe(pt(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(P(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>bs(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},Cs=(e,t)=>{let n=Object.freeze(Array.from(t)),r=Ss(e,n);return ns.set(r,{kind:e,schemas:n}),Object.freeze(r)},ws=(e,t,n,r)=>ss(t)(n).pipe(un(t=>new G({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),Ts=(e,t,n,r)=>{let i=cs(t)(n);if(l(i))throw new G({machineId:e.id,boundary:r.boundary,cause:i.failure,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}});return i.success},Es=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new G({machineId:e.id,boundary:r.boundary,cause:d(t)?t:P(n,`~effect/SchemaIssue/Issue`)?new ar(n):i(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},Ds=(e,t,n)=>new G({machineId:e.id,boundary:n,event:String(t._tag),cause:i(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),Os=(e,t)=>{if(t.inputError!==void 0)throw t.inputError;return typeof t.input==`object`&&t.input!==null?{...t.input,_tag:e._tag}:{_tag:e._tag}},ks=(e,t,n,r)=>new G({machineId:e.id,boundary:n,event:String(t._tag),cause:i(r)}),As=(e,t,n,r)=>{let i=is.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;return i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema)?N(Ds(e,n,r)):Rr({try:()=>Os(n,i),catch:t=>ks(e,n,r,t)}).pipe(v(t=>i.schema.makeEffect(t).pipe(un(t=>new G({machineId:e.id,boundary:r,event:String(n._tag),cause:new ar(t)})))))},js=(e,t,n,r)=>{let i=is.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;if(i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema))throw Ds(e,n,r);let o;try{o=Os(n,i)}catch(t){throw ks(e,n,r,t)}return Es(e,i.schema,o,{boundary:r,event:String(n._tag)})},Ms=(e,t)=>{let n=us(e);if(xs(t))return As(e,n,t,`event`);let r=ys(t);return ws(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Ns=(e,t)=>{let n=us(e);if(xs(t))return js(e,n,t,`event`);let r=ys(t);return Ts(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Ps=(e,t)=>{let n=us(e);if(xs(t))return As(e,n,t,`emission`);let r=ys(t);return ws(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Fs=(e,t)=>{let n=us(e);if(xs(t))return js(e,n,t,`emission`);let r=ys(t);return Ts(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Is=(e,t,n)=>Ts(e,t,n,{boundary:`input`}),Ls=(e,t,n)=>Qo(n)?ts(t).makeEffect(n.input).pipe(un(n=>new G({machineId:e.id,boundary:`state`,state:t.path,cause:new ar(n)}))):ws(e,ts(t),n,{boundary:`state`,state:t.path}),J=(e,t,n)=>Qo(n)?Es(e,ts(t),n.input,{boundary:`state`,state:t.path}):Ts(e,ts(t),n,{boundary:`state`,state:t.path}),Rs=(e,t,n)=>t.output===void 0?B(n):ws(e,t.output,n,{boundary:`output`,state:t.path}),zs=(e,t,n)=>t.output===void 0?n:Ts(e,t.output,n,{boundary:`output`,state:t.path}),Bs=(e,t)=>{let n=new Set(Y(e,t.parent)),r=n=>{let i=q(e,n);if(i.type===`compound`){let e=i.children.filter(e=>t.active.has(e));if(e.length!==1)throw Error(`Machine history expected compound state "${n}" to retain one active child`);t.mode===`deep`&&r(e[0])}else if(i.type===`parallel`)for(let e of i.children){if(!t.active.has(e))throw Error(`Machine history expected parallel state "${n}" to retain region "${e}"`);t.mode===`deep`&&r(e)}};r(t.parent);for(let r of t.active){if(!n.has(r)&&!Ys(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&Js(r,t.parent)&&q(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},Vs=(e,t)=>{let n=new Map;for(let[r,i]of Object.entries(t.history??{})){let t=q(e,r);if(t.type!==`history`||t.parent===void 0||t.history!==i.mode)throw Error(`Machine snapshot contains invalid history record "${r}"`);let a=new Set,o=new Map;for(let n of i.active){if(a.has(n))throw Error(`Machine snapshot contains invalid remembered state "${n}"`);let r=q(e,n);if(r.type===`history`||r.type===`choice`||!(Ys(n,t.parent)||Y(e,t.parent).includes(n)))throw Error(`Machine snapshot contains invalid remembered value for "${n}"`);a.add(n);let s=Object.prototype.hasOwnProperty.call(i.values,n);if(r.schema===void 0){if(s)throw Error(`Machine snapshot contains a value for structural state "${n}"`)}else{if(!s)throw Error(`Machine snapshot omits remembered value for "${n}"`);o.set(n,J(e,r,i.values[n]))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)throw Error(`Machine snapshot contains incomplete history record "${r}"`);n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o}),Bs(e,n.get(r))}return n},Hs=qt(function*(e,t){let n=new Map;for(let[r,a]of Object.entries(t.history??{})){let t=e.stateNodes.byPath.get(r);if(t===void 0||t.type!==`history`||t.parent===void 0||t.history!==a.mode)return yield*N(new G({machineId:e.id,boundary:`history`,state:r,cause:i(Error(`Machine snapshot contains invalid history record "${r}"`))}));let o=new Set,s=new Map;for(let n of a.active){let r=e.stateNodes.byPath.get(n);if(o.has(n)||r===void 0||r.type===`history`||r.type===`choice`||!(Ys(n,t.parent)||Y(e,t.parent).includes(n)))return yield*N(new G({machineId:e.id,boundary:`history`,state:n,cause:i(Error(`Machine snapshot contains invalid remembered state "${n}"`))}));o.add(n);let c=Object.prototype.hasOwnProperty.call(a.values,n);if(r.schema===void 0){if(c)return yield*N(new G({machineId:e.id,boundary:`history`,state:n,cause:i(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!c)return yield*N(new G({machineId:e.id,boundary:`history`,state:n,cause:i(Error(`Machine snapshot omits remembered value for "${n}"`))}));s.set(n,yield*ws(e,ts(r),a.values[n],{boundary:`history`,state:n}))}}if(!o.has(t.parent)||Object.keys(a.values).length!==s.size)return yield*N(new G({machineId:e.id,boundary:`history`,state:r,cause:i(Error(`Machine snapshot contains incomplete history record "${r}"`))}));n.set(r,{mode:a.mode,parent:t.parent,active:o,values:s});try{Bs(e,n.get(r))}catch(t){return yield*N(new G({machineId:e.id,boundary:`history`,state:r,cause:i(t)}))}}return n}),Us=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>Zs(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},Ws=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),Gs=e=>e.machineReferences,Ks=new WeakMap,qs=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Js=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),Ys=(e,t)=>e===t||Js(e,t),Y=(e,t)=>{let n=Ks.get(e.stateNodes);n===void 0&&(n=new Map,Ks.set(e.stateNodes,n));let r=n.get(t);if(r!==void 0)return r;let i=[],a=t;for(;a!==void 0;)i.unshift(a),a=q(e,a).parent;return n.set(t,i),i},Xs=(e,t)=>Y(e,t).length,Zs=(e,t,n)=>q(e,t).order-q(e,n).order,Qs=(e,t,n)=>q(e,n).children.some(e=>t.active.has(e)),$s=(e,t)=>{let n=Array.from(t.active).filter(n=>!Qs(e,t,n)).sort((t,n)=>Zs(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},ec=(e,t)=>$s(e,t)[0],tc=(e,t,n)=>{let r=$s(e,t).filter(e=>Ys(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},nc=(e,t)=>{for(let n of t.active)if(q(e,n).parent===void 0)return n;throw Error(`Machine expected an active root state`)},rc=(e,t,n)=>{let r={},i=Y(e,n);for(let e=0;e<i.length-1;e++){let n=i[e];t.values.has(n)&&(r[n]=t.values.get(n))}return r},ic=(e,t,n)=>{let r=q(e,n).parent;return r===void 0?void 0:t.values.get(r)},ac=(e,t)=>{let n=r=>t.active.has(r)?[r,...q(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},oc=(e,t,n)=>{let r=q(e,n),i={path:n,value:t.values.get(n)};if(r.type===`compound`){let a=r.children.find(e=>t.active.has(e));if(a===void 0)throw Error(`Machine expected compound state "${n}" to have an active child`);i.state=oc(e,t,a)}if(r.type===`parallel`){let a={};for(let i of r.children){if(!t.active.has(i))throw Error(`Machine expected parallel state "${n}" to have active child region "${i}"`);let r=q(e,i);a[r.key]=oc(e,t,i)}i.states=a}return i},sc=(e,t)=>{let n=oc(e,t,nc(e,t)),r=Array.from(t.outputs).map(([e,t])=>({path:e,output:t}));return r.length>0&&(n.completed=r),t.history.size>0&&Object.assign(n,{history:Us(e,t.history)}),n},cc=(e,t,n)=>{let r=oc(e,t,n);return t.history.size>0&&Object.assign(r,{history:Us(e,t.history)}),r},lc=(e,t,n)=>{if(!P(n,`state`)||!$o(n.state))throw Error(`Machine expected compound snapshot "${t.path}" to include an active child state`);let r=q(e,String(n.state.path));if(r.parent!==t.path)throw Error(`Machine expected snapshot "${r.path}" to be a child of "${t.path}"`);return n.state},uc=(e,t)=>{if(!P(t,`states`)||typeof t.states!=`object`||t.states===null)throw Error(`Machine expected parallel snapshot "${e.path}" to include active child regions`);return t.states},dc=(e,t,n,r)=>{let i=q(e,n),a=r[i.key];if(!qs(r,i.key)||!$o(a))throw Error(`Machine expected parallel snapshot "${t.path}" to include region "${i.key}"`);let o=q(e,String(a.path));if(o.path!==i.path)throw Error(`Machine expected snapshot "${o.path}" to be region "${i.path}"`);return a},fc=(e,t)=>{let n=new Set,r=new Map,i=t.completed,a=t=>{let i=q(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,J(e,i,t.value));if(i.type===`compound`&&a(lc(e,i,t)),i.type===`parallel`){let n=uc(i,t);for(let t of i.children)a(dc(e,i,t,n))}};a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:Vs(e,t)}},pc=(e,t)=>fc(e,t),mc=(e,t)=>{try{return fc(e,t)}catch(t){throw t instanceof G?t:new G({machineId:e.id,boundary:`configuration`,cause:i(t)})}},hc=qt(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=qt(function*(t){let i=q(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,yield*Ls(e,i,t.value));if(i.type===`compound`&&(yield*a(lc(e,i,t))),i.type===`parallel`){let n=uc(i,t);for(let t of i.children)yield*a(dc(e,i,t,n))}});yield*a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:yield*Hs(e,t)}}),gc=(e,t)=>hc(e,t).pipe(wr(t=>{if(Hr(t))return la(Yr(t,t=>t instanceof G?t:new G({machineId:e.id,boundary:`configuration`,cause:Gn(t)})));let n=Ti(t);return A(n)&&n.value instanceof G?N(n.value):N(new G({machineId:e.id,boundary:`configuration`,cause:t}))})),_c=(e,t,n,r)=>{if(r.length===0)return n;let i=new Set(r),a=new Map(n.history);for(let n of e.stateNodes.byPath.values()){if(n.type!==`history`||n.parent===void 0||!i.has(n.parent))continue;let r=n.history===`deep`?`deep`:`shallow`,o=new Set;for(let r of Y(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&Js(i,n.parent)||r===`shallow`&&q(e,i).parent===n.parent)&&o.add(i);let s=new Map;for(let e of o)t.values.has(e)&&s.set(e,t.values.get(e));a.set(n.path,{mode:r,parent:n.parent,active:o,values:s})}return{active:n.active,values:n.values,outputs:n.outputs,history:a}},vc=(e,t)=>e.history.get(t),yc=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=Y(e,n.parent),s=new Set(o);for(let c of o){let o=q(e,c);if(o.type===`parallel`){for(let e of o.children)if(!(s.has(e)||n.active.has(e)||!t.active.has(e)))for(let n of t.active)Ys(n,e)&&(r.add(n),t.values.has(n)&&i.set(n,t.values.get(n)),t.outputs.has(n)&&a.set(n,t.outputs.get(n)))}}return{active:r,values:i,outputs:a,history:t.history}};qt(function*(e,t,n,r,i){let a=q(e,n),o=new Set,s=new Map,c=new Map,l=Y(e,a.path),u=new Set(l);for(let n of l){let c=q(e,n);if(o.add(n),c.schema===void 0){if((n===a.path?r:i!==void 0&&qs(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===a.path)s.set(n,yield*Ls(e,c,r));else if(i!==void 0&&qs(i,n))s.set(n,yield*Ls(e,c,i[n]));else if(t.values.has(n))s.set(n,t.values.get(n));else throw Error(`Machine target "${a.path}" requires a value for ancestor state "${n}"`)}for(let n of l){let r=q(e,n);if(r.type===`parallel`){for(let e of r.children)if(!u.has(e)&&t.active.has(e))for(let n of t.active)Ys(n,e)&&(o.add(n),t.values.has(n)&&s.set(n,t.values.get(n)),t.outputs.has(n)&&c.set(n,t.outputs.get(n)))}}if(a.type===`compound`||a.type===`parallel`)throw Error(`Machine target "${a.path}" must include an active child state`);return{active:o,values:s,outputs:c,history:t.history}}),qt(function*(e,t,n,r){let i=yield*hc(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Y(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=q(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&qs(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&qs(r,i))o.set(i,yield*Ls(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=q(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)Ys(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&qs(r,n))for(let[t,i]of Object.entries(r)){if(!Ys(t,n))continue;let r=q(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,yield*Ls(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var bc=(e,t,n,r,i,a=!1)=>{let o=q(e,n),s=new Set,c=new Map,l=new Map,u=Y(e,o.path),d=new Set(u);for(let n of u){let a=q(e,n);if(s.add(n),a.schema===void 0){if((n===o.path?r:i!==void 0&&qs(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===o.path)c.set(n,J(e,a,r));else if(i!==void 0&&qs(i,n))c.set(n,J(e,a,i[n]));else if(t.values.has(n))c.set(n,t.values.get(n));else throw Error(`Machine target "${o.path}" requires a value for ancestor state "${n}"`)}for(let n of u){let r=q(e,n);if(r.type===`parallel`&&n!==o.path){for(let e of r.children)if(!d.has(e)&&t.active.has(e))for(let n of t.active)Ys(n,e)&&(s.add(n),t.values.has(n)&&c.set(n,t.values.get(n)),t.outputs.has(n)&&l.set(n,t.outputs.get(n)))}}if(!a&&(o.type===`compound`||o.type===`parallel`))throw Error(`Machine target "${o.path}" must include an active child state`);return{active:s,values:c,outputs:l,history:t.history}},xc=(e,t,n)=>{let r=bc(e,t,n.path,n.value,n.values,!0);if(n.children===void 0)return r;let i=new Set(r.active),a=new Map(r.values);for(let[t,r]of n.children){let n=q(e,t);i.add(t),n.schema!==void 0&&a.set(t,J(e,n,r))}return{...r,active:i,values:a}},Sc=(e,t,n,r)=>{let i=fc(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Y(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=q(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&qs(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&qs(r,i))o.set(i,J(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=q(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)Ys(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&qs(r,n))for(let[t,i]of Object.entries(r)){if(!Ys(t,n))continue;let r=q(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,J(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},Cc=(e,t,n)=>{if(Xo(n)){let r=n[fo];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return Sc(e,t,r,n.values)}return bc(e,t,n.path,n.value,n.values)}if($o(n)){let r=mc(e,n);return{...r,history:new Map([...t.history,...r.history])}}throw Error(`Machine expected transition target to be a snapshot or target builder result`)},wc=(e,t)=>K(e).handlers[t],Tc=(e,t,n)=>q(e,n).children.find(e=>t.active.has(e)),Ec=(e,t)=>q(e,t).type===`final`,Dc=(e,t)=>wc(e,t)?.onDone!==void 0,Oc=(e,t,n)=>{if(!t.active.has(n))return!1;let r=q(e,n);if(r.type===`compound`){let r=Tc(e,t,n);return r!==void 0&&(n===``?!Dc(e,r)&&Oc(e,t,r):Ec(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!Oc(e,t,n))return!1;return!0}return Ec(e,n)},kc=(e,t)=>{let n=nc(e,t);return Oc(e,t,n)&&!Dc(e,n)},Ac=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),jc=qt(function*(e,t,n,r,i){let a=q(e,n),o=wc(e,n)?.output?.({state:t.values.get(n),containingState:ic(e,t,n),ancestors:rc(e,t,n),event:r,outputs:i});return yield*Rs(e,a,o)}),Mc=qt(function*(e,t,n,r,i,a){if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=q(e,n);if(o.type===`compound`){let o=Tc(e,t,n);if(o===void 0||(n===``?Dc(e,o):!Ec(e,o)))return;let s=yield*Mc(e,t,o,r,i,a);if(s===void 0)return;let c=Ac(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=yield*Mc(e,t,n,r,i,a);o===void 0?c=!1:s[q(e,n).key]=o.output}if(!c)return;let l=Ac(i,n,yield*jc(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Ec(e,n))return;let s=Ac(i,n,yield*jc(e,t,n,r));return s.isNew&&a.push(s),s}),Nc=qt(function*(e,t,n){let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=Xs(e,n)-Xs(e,t);return r===0?Zs(e,t,n):r}))yield*Mc(e,a,t,n,r,i);return{configuration:a,completions:i}}),Pc=(e,t,n,r,i)=>{let a=q(e,n),o=wc(e,n)?.output?.({state:t.values.get(n),containingState:ic(e,t,n),ancestors:rc(e,t,n),event:r,outputs:i});return zs(e,a,o)},Fc=(e,t,n,r,i,a)=>{if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=q(e,n);if(o.type===`compound`){let o=Tc(e,t,n);if(o===void 0||(n===``?Dc(e,o):!Ec(e,o)))return;let s=Fc(e,t,o,r,i,a);if(s===void 0)return;let c=Ac(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=Fc(e,t,n,r,i,a);o===void 0?c=!1:s[q(e,n).key]=o.output}if(!c)return;let l=Ac(i,n,Pc(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Ec(e,n))return;let s=Ac(i,n,Pc(e,t,n,r));return s.isNew&&a.push(s),s},Ic=(e,t,n)=>{let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=Xs(e,n)-Xs(e,t);return r===0?Zs(e,t,n):r}))Fc(e,a,t,n,r,i);return{configuration:a,completions:i}},Lc=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},Rc=(e,t)=>{if(t.decoded!==void 0&&typeof t.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.schema===void 0){if(Object.hasOwn(t,`data`)||Object.hasOwn(t,`decoded`))throw Error(`Machine structural state "${e.path}" cannot construct data`)}else{if(t.decoded===!0){if(!Object.hasOwn(t,`data`))throw Error(`Machine decoded construction requires data`);return t.data}return Zo(Object.hasOwn(t,`data`)?t.data:{})}},zc=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=Lc(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return Yo(t,Rc(i,e))}let a=new Map,o=(t,n)=>{let i=Lc(n);if(Reflect.ownKeys(i).some(e=>e!==`data`&&e!==`decoded`&&e!==`states`))throw Error(`Machine state construction accepts only data, decoded, and states`);let s=e.byPath.get(t);if(s===void 0||s.type===`history`)throw Error(`Machine invalid construction state "${t}"`);let c=Rc(s,i);if(Object.hasOwn(i,`states`)){if(s.type!==`compound`&&s.type!==`parallel`)throw Error(`Machine state "${t}" has no child construction`);let n=Lc(i.states),c=Reflect.ownKeys(n),l=s.children.filter(t=>e.byPath.get(t)?.type!==`history`);if(s.type===`compound`?c.length!==1:c.length!==l.length&&(c.length!==1||r===void 0||r!==t&&!r.startsWith(`${t}.`)))throw Error(`Machine explicit states for "${t}" must select ${s.type===`compound`?`one child`:`every region`}`);for(let r of c){let i=t===``?String(r):`${t}.${String(r)}`;if(typeof r!=`string`||e.byPath.get(i)?.parent!==t||e.byPath.get(i)?.type===`history`)throw Error(`Machine unknown child "${String(r)}"`);a.set(i,o(i,n[r]))}}return c},s=o(t,n),c=new Map(a);c.set(t,s);let l=t,u=Lc(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=Lc(u.states),i=Object.keys(n);if(i.length!==1||t.type===`parallel`&&(r===void 0||r!==l&&!r.startsWith(`${l}.`)))break;let a=i[0];l=l===``?a:`${l}.${a}`,u=Lc(n[a])}let d=e.byPath.get(l),f=c.get(l),p=Object.fromEntries([...c].filter(([e,t])=>t!==void 0&&e!==l&&!e.startsWith(`${l}.`)));if(d.type===`choice`)return Ho(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return Yo(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...Bo(l,f,p),...m.size===0?{}:{children:m}}},Bc=(e,t,n)=>{let r=Lc(n);if(Reflect.ownKeys(r).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine update construction accepts only data and decoded`);let i=e.byPath.get(t);if(i?.schema===void 0)throw Error(`Machine update requires a valued state`);return Eo(t,Rc(i,r))},Vc=(e,t,n=``)=>{let r=Lc(t),i=e.byPath.get(n);zc(e,n,r);let a=Rc(i,r);if(i.type===`choice`)return Ho(n,i.parent);if(i.type===`atomic`||i.type===`final`)return{path:n,value:a};if(r.states===void 0)throw Error(`Machine history fallback requires a complete explicit tree`);let o=Lc(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,Vc(e,r,n===``?t:`${n}.${t}`)]));return i.type===`parallel`?{path:n,value:a,states:s}:{path:n,value:a,state:Object.values(s)[0]}},Hc=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},Uc=`root`,Wc=e=>{let t=new Map,n=(e,r)=>{let i=!z(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!z(e)&&`states`in e)for(let[t,i]of Object.entries(e.states))n(i,r===``?t:`${r}.${t}`)};if(n(e.node,``),t.has(`root`))throw Error(`Machine top-level state name "${Uc}" is reserved for the root`);return t},Gc=(e,t)=>{let n=Wc(e),r=t.input!==void 0,i=new Map;for(let e of[`effects`,`streams`,`timers`,`logic`,`children`])if(t[e]!==void 0)for(let[n,r]of Object.entries(Hc(t[e],`Machine ${e} must be a source map`))){if(i.has(n))throw Error(`Machine source name "${n}" is registered more than once`);i.set(n,Object.freeze({kind:e,value:r}))}let a=new Map;if(t.branches!==void 0)for(let[o,s]of Object.entries(Hc(t.branches,`Machine branches must be a map`))){let t=Hc(s,`Machine branches "${o}" must be a branch record`);for(let e of Reflect.ownKeys(t)){if(typeof e!=`string`)throw Error(`Machine branches cannot use symbol keys`);if(e.length===0||String(Number(e))===e)throw Error(`Machine branches require non-index string branch keys`)}let c=Object.entries(t);if(c.length===0)throw Error(`Machine branches "${o}" requires a branch`);a.set(o,Object.freeze(Object.fromEntries(c.map(([t,s])=>{let c={...Hc(s,`Machine branch "${o}.${t}" must be a declaration`)};for(let e of Reflect.ownKeys(c))if(typeof e!=`string`||![`target`,`update`,`history`,`none`,`initialize`,`title`].includes(e))throw Error(`Machine branch "${o}.${t}" contains an unknown declaration field`);if(c.initialize!==void 0&&c.initialize!==!0)throw Error(`Machine branch "${o}.${t}" declares initialize: true; its resolver supplies input`);if(c.title!==void 0&&(typeof c.title!=`string`||c.title.length===0))throw Error(`Machine branch title must be a non-empty string`);return qc({root:e,input:r,paths:n,sources:i,branches:a},c),[t,Object.freeze(c)]}))))}return{root:e,input:r,paths:n,sources:i,branches:a}},Kc=(e,t)=>{let n=e===`root`?``:typeof e==`string`&&e!==``?e:void 0,r=n===void 0?void 0:t.paths.get(n);if(n===void 0||r===void 0)throw Error(`Machine target ${String(e)} is not a declared state path`);return{path:n,kind:r}},qc=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=Kc(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return Co(`update`,n.path,`branch`)}if(n.length!==1)throw Error(`Machine transition must declare exactly one destination operation`);let r=n[0];if(r===`none`){if(t.none!==!0||t.update!==void 0)throw Error(`Machine targetless transition requires none: true`);return wo}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return Co(`state`,``,`branch`)}let i=Kc(t[r],e);if(r===`target`&&i.path===``)throw Error(`Machine root is not a destination; use initialize to reconstruct it from machine input`);if(r===`history`!=(i.kind===`history`))throw Error(`Machine history references require a history transition`);let a=t.update===void 0?void 0:Kc(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return Co(i.kind,i.path,r===`history`?`full`:`branch`,a)},Jc=(e,t,n,r)=>{let i=Hc(t,`Machine invocation for "${n}" must be an object`),a=typeof i.src==`string`?e.sources.get(i.src):void 0;if(a===void 0)throw Error(`Machine invocation for "${n}" names an unknown source`);let{src:o,input:s,...c}=i,l=typeof s==`function`?e=>s(r(e)):s;if(a.kind===`children`)return{...c,child:a.value,...l===void 0?{}:{input:l}};let u=typeof a.value==`function`&&!(a.kind===`effects`&&ui(a.value))&&!(a.kind===`streams`&&gi(a.value));if(u!==(typeof l==`function`))throw Error(`Machine invocation "${o}" requires input exactly when its source takes an argument`);let d=u?e=>a.value(l(e)):()=>a.value,f={effects:`effect`,streams:`stream`,timers:`after`,logic:`logic`}[a.kind];return{...c,sourceName:o,id:c.id??o,[f]:!u&&(a.kind===`timers`||a.kind===`logic`)?a.value:d}},Yc=Symbol(`effect/Machine/InitialEvent`),Xc=Symbol(`effect/Machine/SnapshotBuilderState`),Zc=Symbol(`effect/Machine/ChildMachineLogic`),Qc=new WeakSet,$c=e=>Qc.has(e),el=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},tl=e=>typeof e==`function`?e:()=>e,nl=e=>{if(typeof e==`object`&&e&&P(e,`decoded`)&&e.decoded===!0&&P(e,`data`)){let t=el(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return tl(t.data)}let t=tl(e);return n=>Zo(e===void 0?{}:t(n))},rl=e=>{if(e.decoded!==void 0&&typeof e.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.decoded===!0){if(!P(e,`data`))throw Error(`Machine decoded construction requires data`);return tl(e.data)}let t=tl(e.data);return n=>Zo(P(e,`data`)?t(n):{})},il=(e,t)=>{let n=(e,t,r)=>{if(P(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&P(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(z(e)||!(`states`in e)){if(i!==void 0)throw Error(`Machine state "${r}" cannot declare initial children`);if(o!==void 0)throw Error(`Machine state "${r}" has no children`);return{node:e,handlers:s}}let c=o===void 0?{}:el(o,`child handlers`);for(let t of Object.keys(c))if(!Object.prototype.hasOwnProperty.call(e.states,t))throw Error(`Machine unknown child "${t}"`);let l=Object.create(null),u=Object.create(null),d=Object.create(null),f=e.type===`parallel`,p;if(f){let t=i===void 0?{}:el(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!z(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!z(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=nl(r)}}else{let t=el(i,`initial edge for "${r}"`);if(Reflect.ownKeys(t).some(e=>![`target`,`data`,`decoded`].includes(String(e))))throw Error(`Machine initial edge accepts only target, data, and decoded`);let n=r===``?``:`${r}.`,a=typeof t.target==`string`&&t.target.startsWith(n)?t.target.slice(n.length):void 0,o=a===void 0||!Object.hasOwn(e.states,a)?void 0:e.states[a],s=o===void 0||z(o)?`state`:o.type;if(a===void 0||o===void 0||s===`history`)throw Error(`Machine initial target must be a direct child of "${r===``?`root`:r}"`);if(p=a,s===`choice`&&(P(t,`data`)||P(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=rl(t),l=e.states[a];if(P(t,`data`)&&!z(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);P(t,`data`)&&(d[a]=c)}for(let[t,i]of Object.entries(e.states)){let e=r===``?t:`${r}.${t}`,a=n(i,c[t]===void 0?{}:el(c[t],`state handler`),e);l[t]=a.node,(z(i)||i.type!==`history`)&&(c[t]!==void 0||!z(i)&&`states`in i)&&(u[t]=a.handlers)}let m=Object.freeze({...e,states:Object.freeze(l),...f?{}:{initial:p}}),h=Object.entries(d),g=e=>{let t=typeof e.ancestors==`object`&&e.ancestors!==null?e.ancestors:{},n={...e,root:r===``?e.state:t[``]},i=Object.fromEntries(h.map(([e,t])=>[e,t(n)]));return{[Xc]:i}};return Qc.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},al=(e,t)=>{let n=[`effect`,`stream`,`after`,`logic`,`child`].filter(t=>t in e);if(n.length!==1)throw Error(`Machine invocation for state "${t}" must define exactly one source`);if(n[0]!==`child`&&typeof e.id!=`string`)throw Error(`Machine invocation for state "${t}" requires a string id`);if((n[0]===`effect`||n[0]===`stream`)&&typeof e[n[0]]!=`function`)throw Error(`Machine invocation for state "${t}" requires a source callback`);return Object.freeze(e)},ol=e=>`child`in e?e.child.id:e.id,sl=(e,t)=>{let n=new Set;for(let r of e){let e=ol(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},cl=e=>e===void 0?[]:Array.isArray(e)?e:[e],ll=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(Ns(e,t))},emit:t=>{r.push(Fs(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},ul=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},dl=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(Zo(t.length===0?{}:t[0])),enumerable:!1}),t},fl=e=>{let t={};return Object.defineProperty(t,Xc,{value:e,enumerable:!1}),t},pl=(e,t,n)=>{let r=fl(n);for(let i of t.children){let a=ul(e,i);a.schema===void 0||P(n,a.key)||(r[a.key]=dl(r=>{let i=Object.assign({},n);return i[a.key]=r,pl(e,t,i)}))}return r},ml=(e,t)=>{let n=ul(e,t);if(n.type===`parallel`)return pl(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=ul(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return dl(e=>fl({[r.key]:e}))},hl=(e,t)=>{if(typeof t!=`object`||!t||!P(t,Xc))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[Xc]},gl=Symbol(`effect/Machine/InvocationEvent`),_l=(e,t,n)=>({[gl]:!0,path:e,id:t,type:`done`,output:n}),vl=(e,t,n)=>({[gl]:!0,path:e,id:t,type:`element`,element:n}),yl=(e,t,n)=>({[gl]:!0,path:e,id:t,type:`failure`,error:n}),bl=(e,t,n)=>({[gl]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),xl=e=>typeof e==`object`&&!!e&&gl in e,Sl=new WeakMap,Cl=new WeakMap,wl=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},Tl=(e,t)=>{let n=Object.create(e);return Cl.set(n,wl(e,t)),n},El=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return wl(e,n);let r=Cl.get(e);if(r!==void 0)return r;let i=Sl.get(e);if(i!==void 0)return i;let a=wl(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>N(new oo)},parent:void 0});return Sl.set(e,a),a},Dl=e=>{if(e!==void 0)return typeof e==`function`?{reenter:!1,declinable:!1,targets:void 0,transition:e,evaluate:void 0}:{reenter:e.reenter===!0,declinable:e.declinable===!0,targets:e.targets,transition:e.transition,evaluate:e.evaluate}},Ol=(e,t,n)=>{let r=ll(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},kl=(e,t,n,r)=>{let i=ll(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Lo(a.result)?{declined:!0}:{declined:!1,state:Po(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},Al=(e,t,n)=>{let r=ll(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},jl=(e,t,n,r)=>{let i=new Set(t.active),a=new Map(t.values),o=[],s=[],c=[],l=[],u=!0;for(;u;){u=!1;for(let d of Array.from(i).sort((t,n)=>Zs(e,t,n))){let f=q(e,d);if(f.type===`compound`&&!f.children.some(e=>i.has(e))){if(f.initial===void 0)throw Error(`Machine shallow history expected compound state "${d}" to have an initial child`);let p=q(e,f.initial),m={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences};if(p.type===`choice`){let t=su(e,m,Ho(p.path,d,Object.fromEntries(a)),n),r=m;for(let i of[t.target,...t.additionalTargets]){if(i===void 0)throw Error(`Machine initial choice "${p.path}" must resolve to an active state target`);let t=Vo(i)?Nl(e,r,i,n):zo(i)?Pl(e,r,i,n):void 0;r=Cc(e,r,t?.target??i),t!==void 0&&(o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions))}i.clear(),a.clear();for(let e of r.active)i.add(e);for(let[e,t]of r.values)a.set(e,t);o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions),u=!0;continue}if(i.add(p.path),p.schema!==void 0){let t=K(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,J(e,p,Zo({}))),u=!0;continue}let i=Al(e,t,{...El(e,m),state:m.values.get(d),containingState:ic(e,m,d),ancestors:rc(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...$c(t)?{}:{builder:ml(e,d)}}),l=hl(d,i.value);a.set(p.path,J(e,p,l[p.key])),o.push(...i.commands),s.push(...i.raisedEvents),c.push(...i.emittedEvents)}u=!0}if(f.type===`parallel`){let l=f.children.filter(e=>!i.has(e));if(l.length>0){let f=l.filter(t=>q(e,t).schema!==void 0),p={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences},m=f.length===0?void 0:K(e).handlers[d]?.initialize,h=m===void 0?void 0:Al(e,m,{...El(e,p),state:p.values.get(d),containingState:ic(e,p,d),ancestors:rc(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...$c(m)?{}:{builder:ml(e,d)}}),g=h===void 0?void 0:hl(d,h.value);for(let t of l){let n=q(e,t);if(i.add(n.path),n.schema!==void 0){if(h===void 0){a.set(n.path,J(e,n,Zo({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&$c(m)){a.set(n.path,J(e,n,Zo({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,J(e,n,g[n.key]))}}h!==void 0&&(o.push(...h.commands),s.push(...h.raisedEvents),c.push(...h.emittedEvents)),u=!0}}}}return{configuration:{active:i,values:a,outputs:new Map,history:t.history},commands:o,raisedEvents:s,emittedEvents:c,transitions:l}};function Ml(e,t,n,r){let i=xc(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>q(e,t).type===`choice`))return jl(e,i,r,n.input);let a=[],o=[],s=[],c=[];for(let t of n.children?.keys()??[]){let n=q(e,t);if(n.type!==`choice`)continue;let l=su(e,i,Ho(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=Vo(t)?Nl(e,i,t,r):zo(t)?Pl(e,i,t,r):void 0;i=Cc(e,i,n?.target??t),n!==void 0&&(a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents),c.push(...n.transitions))}a.push(...l.commands),o.push(...l.raisedEvents),s.push(...l.emittedEvents),c.push(...l.transitions)}let l=jl(e,i,r,n.input);return c.length===0?l:{...l,commands:[...a,...l.commands],raisedEvents:[...o,...l.raisedEvents],emittedEvents:[...s,...l.emittedEvents],transitions:[...c,...l.transitions]}}function Nl(e,t,n,r){let i=Ml(e,t,n,r),a=cc(e,i.configuration,n.path);return{target:Yo(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Pl(e,t,n,r){let i=q(e,n.path);if(i.type!==`history`||i.parent!==n.parent)throw Error(`Machine expected history target "${n.path}" to resolve to its declared parent`);let a=vc(t,n.path);if(a!==void 0){let i=jl(e,yc(e,t,a),r),o=cc(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:Yo(n.parent,o.value,{snapshot:o,values:s}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}let o=i.key,s=K(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=kl(e,s,{event:r,target:t=>Vc(e.stateNodes,t),owner:n.parent});if(c.state===void 0||zo(c.state)||!$o(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=au(c.state)===void 0?void 0:su(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?mc(e,c.state):Cc(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=Cc(e,u,t);if(!u.active.has(n.parent))throw Error(`Machine history default for "${n.path}" returned a configuration that does not contain owner state "${n.parent}"`);let d=cc(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:Yo(n.parent,d.value,{snapshot:d,values:f}),commands:[...c.commands,...l?.commands??[]],raisedEvents:[...c.raisedEvents,...l?.raisedEvents??[]],emittedEvents:[...c.emittedEvents,...l?.emittedEvents??[]],transitions:l?.transitions??[]}}var Fl=(e,t)=>{if(!t.transition.declinable)return t;let n=kl(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},Il=(e,t)=>[...Y(e,t)].reverse(),Ll=(e,t,n)=>{let r=Y(e,t),i=Y(e,n),a,o=Math.min(r.length,i.length);for(let e=0;e<o&&r[e]===i[e];e++)a=r[e];return a},Rl=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||Js(e,t)?t:e},zl=(e,t,n)=>Hl(e,Array.from(t.active).filter(e=>n===void 0||Js(e,n))),Bl=(e,t,n)=>Ul(e,Array.from(t.active).filter(e=>n===void 0||Js(e,n))),Vl=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),Hl=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Y(e,n).length-Y(e,t).length;return r===0?q(e,n).order-q(e,t).order:r}),Ul=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Y(e,t).length-Y(e,n).length;return r===0?Zs(e,t,n):r}),Wl=(e,t,n,r)=>({...El(e,t),state:t.values.get(n),containingState:ic(e,t,n),ancestors:rc(e,t,n),event:r}),Gl=(e,t,n,r,i)=>({...El(e,t),state:t.values.get(n),containingState:ic(e,t,n),ancestors:rc(e,t,n),event:r,snapshot:i}),Kl=(e,t,n,r,i,a)=>({...El(e,t),state:t.values.get(n),containingState:ic(e,t,n),ancestors:rc(e,t,n),event:r,output:i,snapshot:a}),ql=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=Ol(e,K(e).handlers[c]?.[i],Wl(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},Jl=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=sc(e,t);for(let o of $s(e,t))for(let c of Il(e,o)){let l=Dl(K(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Fl(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...El(e,t),state:t.values.get(c),containingState:ic(e,t,c),ancestors:rc(e,t,c),event:n,snapshot:s()}}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},Yl=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=sc(e,t);for(let o of r){let r=Dl(K(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=Fl(e,{sourcePath:o.path,leafPath:tc(e,t,o.path),trigger:{type:`done`},transition:r,context:Kl(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},Xl=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=sc(e,t);for(let o of $s(e,t))for(let c of Il(e,o)){let l=Dl(K(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Fl(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:Gl(e,t,c,n,s())}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},Zl=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=K(e).handlers[n.path],i=cl(r?.invoke).find(e=>{let t=`child`in e?e.child?.id:e.id;return String(t)===n.id});if(i===void 0)return[];let a=Dl(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=sc(e,t),s={...El(e,t),state:t.values.get(n.path),containingState:ic(e,t,n.path),ancestors:rc(e,t,n.path),snapshot:o,id:n.id,...n.type===`element`?{element:n.element}:n.type===`done`?{output:n.output}:n.type===`failure`?{error:n.error}:{snapshot:n.snapshot}},c=Fl(e,{sourcePath:n.path,leafPath:tc(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},Ql=e=>{if(zo(e)||Uo(e)||Xo(e)||$o(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},$l=(e,t,n,r)=>{if(n===void 0||r===void 0)return;let i=typeof r==`object`&&r&&`path`in r?String(r.path):`<unknown>`;if(!n.some(e=>i===e||e===``||i.startsWith(`${e}.`))){let r=t.type===`event`?String(t.event):t.type;throw Error(`Machine transition from "${e}" on "${r}" returned target "${i}" outside declared targets: ${n.length===0?`none`:n.map(e=>`"${e}"`).join(`, `)}`)}},eu=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},tu=(e,t)=>Array.from(t).sort((t,n)=>Zs(e,t.selection.sourcePath,n.selection.sourcePath)),nu=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&Js(e.sourcePath,t.sourcePath))),ru=(e,t)=>{let n=[];for(let r of tu(e,t)){let e=!1,t=new Set;for(let i of n){let n=r.update!==void 0&&i.update!==void 0&&r.update.path===i.update.path;if(eu(r.exitPaths,i.exitPaths)||n){if(Js(r.selection.sourcePath,i.selection.sourcePath))t.add(i);else{e=!0;break}}}if(!e){for(let e of t){let t=n.indexOf(e);t>=0&&n.splice(t,1)}n.push(r)}}return n},iu=(e,t={})=>{let n={...t},r=[],i=e=>{if(Uo(e))Object.assign(n,e.values??{}),r.push(e);else if(typeof e==`object`&&e&&`path`in e&&`value`in e&&(e.value!==void 0&&(n[String(e.path)]=e.value),`state`in e&&i(e.state),`states`in e&&typeof e.states==`object`&&e.states!==null))for(let t of Object.values(e.states))i(t)};return i(e),r.map(e=>({target:Ho(e.path,e.parent,n),values:n}))},au=(e,t={})=>iu(e,t)[0],ou=(e,t)=>{if(Uo(e))return Ho(e.path,e.parent,{...t,...e.values??{}});if(Vo(e))return{...e,values:{...t,...e.values}};if(!Xo(e)||Object.keys(t).length===0)return e;let n=e[fo];return Yo(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function su(e,t,n,r){let i=[n],a=[],o=[],s=[],c=[],l=[],u=0;for(;i.length>0;){let n=i.shift();for(;;){let a=iu(n),d=a[0];if(d===void 0)break;if(i.unshift(...a.slice(1).map(({target:e})=>e)),u+=1,u>1e3)throw new ro({machineId:e.id,state:d.target.path,maxIterations:lu});let f=q(e,d.target.path);if(f.type!==`choice`||f.parent!==d.target.parent)throw Error(`Machine expected choice target "${d.target.path}" to resolve to its declared parent`);let p=K(e).handlers[f.path]?.choice;if(p===void 0||typeof p.transition!=`function`)throw Error(`Machine choice state "${f.path}" requires an implementation`);let m=new Map(t.values);for(let[t,n]of Object.entries(d.values)){let r=q(e,t);r.schema!==void 0&&m.set(t,J(e,r,n))}let h={active:new Set([...t.active,...Object.keys(d.values)]),values:m,outputs:t.outputs,history:t.history,...t.machineReferences===void 0?{}:{machineReferences:t.machineReferences}},g=kl(e,p.transition,{...El(e,h),containingState:ic(e,h,f.path),ancestors:rc(e,h,f.path),event:r},p.evaluate);if(g.state===void 0)throw Error(`Machine choice resolver for "${f.path}" must return a target`);$l(f.path,{type:`choice`},p.targets,g.state);let _=Ql(g.state);n=ou(g.state,d.values);let v=au(n);l.push({source:f.path,trigger:{type:`choice`},reenter:!1,branchIndex:g.branchIndex,branchKey:g.branchKey,target:_,resolvedTarget:v?.target.path??_,updates:[]}),o.push(...g.commands),s.push(...g.raisedEvents),c.push(...g.emittedEvents)}if(!Xo(n)&&!$o(n)&&!zo(n)&&!Vo(n))throw Error(`Machine choice resolver must return a concrete typed target`);a.push(n)}return{target:a[0],additionalTargets:a.slice(1),commands:o,raisedEvents:s,emittedEvents:c,transitions:l}}var cu=(e,t,n)=>{let r=n.leafPath,i=n.collected??kl(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=ko(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||Do(o)?void 0:o;$l(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(Do(o)?o:void 0),l=c===void 0?void 0:(()=>{let n=q(e,c.path);if(!t.active.has(n.path)||n.schema===void 0)throw Error(`Machine state update owner "${n.path}" must be an active valued state`);return{path:n.path,value:J(e,n,c.value)}})(),u=l!==void 0&&(Vo(s)||Uo(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:su(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&Vo(f)?Nl(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=zo(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&zo(m)){let i=n.transition.reenter?q(e,n.sourcePath).parent:Ll(e,r,m.parent),a=g===void 0?zl(e,t,i):Hl(e,Array.from(t.active).filter(e=>Ys(e,m.parent)));h=Pl(e,a.includes(m.parent)?_c(e,t,t,a):t,m,n.context.event)}let _=h===void 0?m:h.target,v=[],y=[],b=[],x=[],S=[];for(let r of d?.additionalTargets??[]){if(Vo(r)){let i=Nl(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions);continue}if(!zo(r)){S.push(r);continue}let i=Pl(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions)}let C=_===void 0?void 0:S.length===0||s===void 0?Ql(_):Ql(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:Cc(e,t,_);for(let t of S)w=Cc(e,w,t);if(a!==void 0&&l!==void 0&&!w.active.has(l.path))throw Error(`Machine combined target exited its updating owner "${l.path}"`);l!==void 0&&(w={...w,values:new Map(w.values).set(l.path,l.value)});let T=n.transition.reenter||!Vl(t,w),ee=T||l!==void 0;if(!T)return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:T,stabilize:ee,exitPaths:[],entryPaths:[],choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]};let te=C===void 0?q(e,n.sourcePath).parent:Ll(e,r,C),E=q(e,n.sourcePath).parent,ne=n.transition.reenter?Rl(te,E):te;return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:T,stabilize:ee,exitPaths:g===void 0?zl(e,t,ne):Hl(e,Array.from(t.active).filter(e=>Ys(e,g.parent))),entryPaths:g===void 0?Bl(e,w,ne):Ul(e,Array.from(w.active).filter(e=>Ys(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},lu=1e3,uu={_tag:Yc},du=(e,t)=>kc(e,pc(e,t)),fu=(e,t,n)=>gc(e,t).pipe(v(t=>Nc(e,t,n)),v(t=>{let n=nc(e,t.configuration);return!kc(e,t.configuration)||!t.configuration.outputs.has(n)?me(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):B(t.configuration.outputs.get(n))})),pu=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Is(e,e.input,void 0),t):[Is(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=Nl(e,i,r,uu),o=Cc(e,i,a.target),s=sc(e,o),c=ac(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=ql(e,o,c,uu,`entry`),p=hu(e,o,uu,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:uu,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:sc(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:sc(e,t.next),event:t.event,transitions:t.transitions,commands:t.commands,raisedEvents:t.raisedEvents,emittedEvents:t.emittedEvents,exitPaths:t.exitPaths,entryPaths:t.entryPaths,changed:t.changed}))};return p.done?{...m,done:!0,output:p.output}:{...m,done:!1,output:void 0}},mu=(e,t,n,r)=>{if(r.length===0)return{next:t,event:n,transitions:[],commands:[],raisedEvents:[],emittedEvents:[],exitPaths:[],entryPaths:[],changed:!1,stabilize:!1};let i=nu(r),a=[];for(let n of i)a.push(cu(e,t,n));let o=ru(e,a),s=tu(e,o),c=s.flatMap(e=>[{source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:Ql(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Ql(e.target),updates:e.update===void 0?[]:[e.update.path]},...e.choiceTransitions]),l=t;for(let e of s)e.update!==void 0&&(l={...l,values:new Map(l.values).set(e.update.path,e.update.value)});let u=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let t of u)t.target!==void 0&&(l=Cc(e,l,t.target));let d=o.some(e=>e.changed),f=o.some(e=>e.stabilize),p=s.flatMap(e=>e.commands),m=s.flatMap(e=>e.raisedEvents),h=s.flatMap(e=>e.emittedEvents);if(!d)return{next:l,event:n,transitions:c,commands:p,raisedEvents:m,emittedEvents:h,exitPaths:[],entryPaths:[],changed:!1,stabilize:f};let g=Hl(e,s.flatMap(e=>e.exitPaths)),_=Ul(e,s.flatMap(e=>e.entryPaths));l=_c(e,t,l,g);let v=ql(e,t,g,n,`exit`),y=ql(e,l,_,n,`entry`);return{next:l,event:n,transitions:c,commands:[...v.commands,...p,...y.commands],raisedEvents:[...v.raisedEvents,...m,...y.raisedEvents],emittedEvents:[...v.emittedEvents,...h,...y.emittedEvents],exitPaths:g,entryPaths:_,changed:!0,stabilize:f}},hu=(e,t,n,r,i,a,o)=>{let s=t,c=n,l=!0,u=0,d=0,f=!1,p,m=[];for(;;){if(u+=1,u>1e3)throw new ro({machineId:e.id,state:String(ec(e,s)),maxIterations:lu});let t=Ic(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>K(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=Yl(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=mu(e,s,c,n);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}if(kc(e,s)){let t=nc(e,s);if(!s.outputs.has(t))throw Error(`Machine reached a terminal configuration without a completed root output`);f=!0,p=s.outputs.get(t);break}let h=l?Jl(e,s,c):[];if(h.length>0){let t=mu(e,s,c,h);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}let g=i[d];if(g===void 0)break;d+=1;let _=g;c=_;let v=Xl(e,s,_);if(v.length===0){l=!0;continue}let y=mu(e,s,_,v);r.push(...y.commands),i.push(...y.raisedEvents),a.push(...y.emittedEvents),o.push(y),s=y.next,l=!0}let h={next:s,commands:r,emittedEvents:a,microsteps:o};return f?{...h,done:!0,output:p}:{...h,done:!1,output:void 0}},gu=(e,t,n)=>{let r=xl(n)?n:Ns(e,n);if(kc(e,t)){let n=Ic(e,t,r),i=nc(e,n.configuration);if(!n.configuration.outputs.has(i))throw Error(`Machine reached a terminal configuration without a completed root output`);return{event:r,next:n.configuration,commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.configuration.outputs.get(i)}}let i=xl(r)?Zl(e,t,r):Xl(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=mu(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...hu(e,a.next,r,o,s,c,l),event:r}},_u=(e,...t)=>Rr({try:()=>pu(e,...t),catch:lo}),vu=(e,t)=>({raise:n=>Ms(e,n).pipe(v(e=>t.sendTo(t.self,e))),emit:n=>Ps(e,n).pipe(v(e=>t.emit(e)))}),yu=(e,t)=>we(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),bu=(e,t)=>Lt(Array.from(e,e=>t.emit(e)),{discard:!0}),xu=new WeakMap,Su=e=>{let t=xu.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>N(new oo)},parent:void 0};return xu.set(e,n),n},Cu=(e,t)=>{let n=t===void 0?Su(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},wu=new Set([`initialize`,`invoke`,`on`,`output`]),Tu=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!wu.has(t))return!1;return!0},Eu=e=>{let t=[],n=[],r=[],i=new Map;for(let a of e.stateNodes.byPath.values()){if(t.push(a),a.type===`choice`||a.type===`history`)return;(a.type===`atomic`||a.type===`final`)&&n.push(a.path),a.type===`final`&&r.push(a.path);let o=K(e).handlers[a.path];if(!Tu(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=Dl(o.on[e]);if(t!==void 0){if(t.declinable)return;s.set(e,t)}}s.size>0&&i.set(a.path,s)}n.sort((t,n)=>Zs(e,t,n)),r.sort((t,n)=>Zs(e,t,n)),t.sort((e,t)=>e.order-t.order);let a=new Map(t.map((e,t)=>[e.path,t])),o=e=>{let t=a.get(e);if(t===void 0)throw Error(`Machine expected compiled state path "${e}"`);return t},s=n.map(o),c=t.map(e=>e.parent===void 0?-1:o(e.parent)),l=t.map(e=>e.children.map(o)),u=t.map(t=>Y(e,t.path).slice(0,-1).map(o)),d=t.map(e=>i.get(e.path)),f=new Map;for(let e of s){let t=new Map,n=[e,...u[e].slice().reverse()];for(let e of n)for(let[n,r]of d[e]??[])t.has(n)||t.set(n,{sourceIndex:e,transition:r});f.set(e,t)}return{valued:Object.freeze(t.map(e=>e.schema!==void 0)),flat:t.every(e=>e.parent===void 0&&(e.type===`atomic`||e.type===`final`))||t[0]?.path===``&&t[0].type===`compound`&&t[0].schema===void 0&&(K(e).handlers[``]===void 0||Reflect.ownKeys(K(e).handlers[``]).every(e=>e===`initialize`))&&t.slice(1).every(e=>e.parent===``&&(e.type===`atomic`||e.type===`final`))&&[...i.values()].every(e=>[...e.values()].every(e=>e.targets!==void 0&&e.targets.every(e=>e!==``))),nodes:t,indexByPath:a,parentIndices:c,childIndices:l,ancestorIndices:u,rootIndices:t.flatMap((e,t)=>e.parent===void 0?[t]:[]),leafIndices:s,finalIndices:r.map(o),dispatchByLeaf:f}},Du=e=>({active:e.active.slice(),activeLeaves:e.activeLeaves.slice(),values:e.values.slice(),completed:e.completed.slice(),outputs:e.outputs.slice(),completedOrder:e.completedOrder.slice()}),Ou=(e,t)=>t?{...e,next:Du(e.next)}:e,ku=(e,t,n)=>{e.values[t]=n},Au=(e,t)=>{let n=new Uint8Array(e.nodes.length),r=Array(e.nodes.length),i=new Uint8Array(e.nodes.length),a=Array(e.nodes.length),o=[];for(let i of t.active){let a=e.indexByPath.get(i);if(a===void 0)throw Error(`Machine expected indexed active path "${i}"`);n[a]=1,e.valued[a]&&(r[a]=t.values.get(i))}for(let[n,r]of t.outputs){let t=e.indexByPath.get(n);if(t===void 0)throw Error(`Machine expected indexed completed path "${n}"`);i[t]=1,a[t]=r,o.push(t)}return{active:n,activeLeaves:e.leafIndices.filter(e=>n[e]===1),values:r,completed:i,outputs:a,completedOrder:o}},ju=(e,t)=>{let n=new Set,r=new Map,i=new Map;for(let i=0;i<e.nodes.length;i++){if(t.active[i]!==1)continue;let a=e.nodes[i].path;n.add(a),e.valued[i]&&r.set(a,t.values[i])}for(let n of t.completedOrder)t.completed[n]===1&&i.set(e.nodes[n].path,t.outputs[n]);return{active:n,values:r,outputs:i,history:new Map}},Mu=(e,t,n)=>{let r=e.nodes[n],i={path:r.path,value:e.valued[n]?t.values[n]:void 0};if(r.type===`compound`){let a=e.childIndices[n].find(e=>t.active[e]===1);if(a===void 0)throw Error(`Machine expected indexed compound state "${r.path}" to have an active child`);i.state=Mu(e,t,a)}else if(r.type===`parallel`){let a={};for(let i of e.childIndices[n]){if(t.active[i]!==1)throw Error(`Machine expected indexed parallel state "${r.path}" to have active region "${e.nodes[i].path}"`);a[e.nodes[i].key]=Mu(e,t,i)}i.states=a}return i},Nu=(e,t)=>{let n=e.rootIndices.find(e=>t.active[e]===1);if(n===void 0)throw Error(`Machine expected an active indexed root state`);let r=Mu(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Pu=(e,t,n,r,i,a)=>{let o=t.parentIndices[r],s={};for(let e of t.ancestorIndices[r])t.valued[e]&&(s[t.nodes[e].path]=n.values[e]);return{...Cu(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:Nu(t,n)}},Fu=Object.freeze([]),Iu=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(Ns(e,t))},emit:t=>{(o??=[]).push(Fs(e,t))},sendTo:(e,t)=>{(i??=[]).push({_tag:`SendTo`,target:e,event:t})},stop:e=>{(i??=[]).push({_tag:`Stop`,child:e})}},c=r===void 0?{result:t(n,s),branchIndex:0,branchKey:void 0}:r(n,s);return{state:Po(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??Fu,raisedEvents:a??Fu,emittedEvents:o??Fu}},Lu=(e,t,n,r,i)=>{let a=[];for(let o of n.activeLeaves){let s=t.dispatchByLeaf.get(o).get(r._tag);if(s!==void 0){let{sourceIndex:c,transition:l}=s;if(!a.some(e=>e.sourceIndex===c)){let s=t.nodes[c].path;a.push({sourceIndex:c,leafIndex:o,sourcePath:s,leafPath:t.nodes[o].path,trigger:{type:`event`,event:r._tag},transition:l,context:Pu(e,t,n,c,r,i)})}}}return a},Ru=(e,t)=>{if(e.active===t.active)return!0;for(let n=0;n<e.active.length;n++)if(e.active[n]!==t.active[n])return!1;return!0},zu=(e,t,n,r,i)=>{if((Xo(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&Xo(r)&&r[fo]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=J(e,t.nodes[i],r.value),{...n,values:a}}return Au(t,Cc(e,ju(t,n),r))},Bu=(e,t,n,r)=>{let i=Iu(e,r.transition.transition,r.context,r.transition.evaluate),a=ko(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(Do(o)?o:void 0),c=s===void 0?void 0:(()=>{let r=t.indexByPath.get(s.path),i=r===void 0?void 0:t.nodes[r];if(r===void 0||i===void 0||n.active[r]!==1||i.schema===void 0)throw Error(`Machine state update owner "${s.path}" must be an active valued state`);return{path:i.path,value:J(e,i,s.value)}})(),l=o===void 0||Do(o)?void 0:o;$l(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&Vo(l)?Nl(e,(()=>{let e=ju(t,n);return c===void 0?e:{...e,values:new Map(e.values).set(c.path,c.value)}})(),l,r.context.event):void 0,d=u?.target??l;if(d!==void 0&&!Xo(d)&&!$o(d))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let f=d===void 0?c===void 0?n:(()=>{let e=Du(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():zu(e,t,n,d,r.leafIndex);if(a!==void 0&&c!==void 0){let e=t.indexByPath.get(c.path);if(f.active[e]!==1)throw Error(`Machine combined target exited its updating owner "${c.path}"`);let n=f.values.slice();n[e]=c.value,f={...f,values:n}}let p=r.transition.reenter||!Ru(n,f),m=p||c!==void 0;if(!p)return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!1,stabilize:m,exitPaths:[],entryPaths:[],choiceTransitions:u?.transitions??[]};let h=d===void 0?void 0:Ql(d),g=h===void 0?t.nodes[r.sourceIndex].parent:Ll(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?Rl(g,_):g;return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!0,stabilize:m,exitPaths:zl(e,ju(t,n),v),entryPaths:Bl(e,ju(t,f),v),choiceTransitions:u?.transitions??[]}},Vu=(e,t,n,r,i,a)=>{let o=e=>({source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:Ql(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:Ql(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=Bu(e,t,n,i[0]);return{next:s.next,event:r,...a?{transitions:[o(s)]}:void 0,commands:s.commands,raisedEvents:s.raisedEvents,emittedEvents:s.emittedEvents,exitPaths:s.exitPaths,entryPaths:s.entryPaths,changed:s.changed}}let s=tu(e,ru(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&Js(t.sourcePath,e.sourcePath))).map(r=>Bu(e,t,n,r)))),c=n;if(s.length===1)c=s[0].next;else{for(let e of s)if(e.update!==void 0){let n=c.values.slice();n[t.indexByPath.get(e.update.path)]=e.update.value,c={...c,values:n}}let n=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let r of n)r.target!==void 0&&(c=zu(e,t,c,r.target,r.selection.leafIndex))}let l=s.flatMap(e=>e.commands),u=s.flatMap(e=>e.raisedEvents),d=s.flatMap(e=>e.emittedEvents),f=s.some(e=>e.changed);return{next:c,event:r,...a?{transitions:s.map(o)}:void 0,commands:l,raisedEvents:u,emittedEvents:d,exitPaths:f?Hl(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?Ul(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},Hu=(e,t,n,r,i,a)=>{let o=n,s=r,c,l,u,d,f=0,p=0;for(;;){if(p+=1,p>1e3)throw new ro({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:lu});let n=o.activeLeaves[0];if(n===void 0)throw Error(`Machine expected an active indexed root state`);if(t.nodes[n].type===`final`){let n=Ic(e,ju(t,o),s).configuration,i=nc(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:Au(t,n),commands:c??Fu,emittedEvents:u??Fu,microsteps:d??Fu,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=Dl(K(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=Iu(e,h.transition,{...Cu(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:Nu(t,o)},h.evaluate),f=Do(r.state)?r.state:void 0,p=f===void 0?r.state:void 0;if(f!==void 0){let r=t.nodes[n];if(f.path!==m||r.schema===void 0)throw Error(`Machine state update owner "${f.path}" must be the active valued state`);ku(o,n,J(e,r,f.value))}if($l(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!Xo(p)&&!$o(p))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let g=o;if(p!==void 0){let r=t.indexByPath.get(String(p.path)),i=Xo(p)?p[fo]===void 0&&p.values===void 0:!(`state`in p)&&!(`states`in p)&&!(`completed`in p)&&!(`history`in p);r===n&&i&&o.completedOrder.length===0&&t.valued[n]?ku(o,n,J(e,t.nodes[n],p.value)):g=zu(e,t,o,p,n)}let _=h.reenter||!Ru(o,g),v=g.activeLeaves[0];if(v===void 0)throw Error(`Machine expected an active indexed transition target`);let y={next:g,event:s,...i?{transitions:[{source:m,trigger:{type:`event`,event:s._tag},reenter:h.reenter,branchIndex:r.branchIndex,branchKey:r.branchKey,target:p===void 0?void 0:Ql(p),resolvedTarget:p===void 0?void 0:Ql(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:Fu,entryPaths:_?[t.nodes[v].path]:Fu,changed:_};o=g,(d??=[]).push(Ou(y,i)),r.commands.length>0&&(c??=[]).push(...r.commands),r.raisedEvents.length>0&&(l??=[]).push(...r.raisedEvents),r.emittedEvents.length>0&&(u??=[]).push(...r.emittedEvents)}if(t.nodes[o.activeLeaves[0]].type===`final`)continue;let g=l?.[f];if(g===void 0)return{event:r,next:o,commands:c??Fu,emittedEvents:u??Fu,microsteps:d??Fu,done:!1,output:void 0};f+=1,s=g}},Uu=(e,t,n,r,i,a)=>{if(xl(r)){let i=gu(e,a===void 0?ju(t,n):Ws(ju(t,n),a),r);return{event:i.event,next:Au(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:Au(t,e.next),event:e.event,transitions:e.transitions,commands:e.commands,raisedEvents:e.raisedEvents,emittedEvents:e.emittedEvents,exitPaths:e.exitPaths,entryPaths:e.entryPaths,changed:e.changed})),done:i.done,output:i.output}}let o=Ns(e,r);if(t.flat)return Hu(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=ju(t,n);if(kc(e,r)){let n=Ic(e,r,o).configuration,i=nc(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:Au(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=Lu(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=Vu(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[Ou(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new ro({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:lu});if(t.finalIndices.some(e=>l.active[e]===1)){let n=Ic(e,ju(t,l),u).configuration;if(l=Au(t,n),kc(e,n)){let t=nc(e,n);if(!n.outputs.has(t))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!0,output:n.outputs.get(t)}}}let n=f[h];if(n===void 0)return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!1,output:void 0};h+=1,u=n;let r=Lu(e,t,l,n,a);if(r.length===0)continue;let s=Vu(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(Ou(s,i))}},Wu=new WeakMap,Gu=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>sc(e,t),plan:(t,n,r,i)=>gu(e,i===void 0?t:Ws(t,i),n)}),Ku=(e,t)=>({fromConfiguration:e=>Au(t,e),toConfiguration:e=>ju(t,e),snapshot:e=>Nu(t,e),plan:(n,r,i=!1,a)=>Uu(e,t,n,r,i,a),...Object.values(K(e).handlers).some(e=>e.initialize!==void 0&&!$c(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Is(e,e.input,void 0),n):[Is(e,e.input,n[0])],a=e.initial(...i),o=Vo(a)?Ml(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,uu).configuration:mc(e,a),s=Ic(e,r===void 0?o:Ws(o,r),uu).configuration,c=Au(t,s),l=Nu(t,c);if(!kc(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:ac(e,s),done:!1,output:void 0};let u=nc(e,s);if(!s.outputs.has(u))throw Error(`Machine reached a terminal configuration without a completed root output`);return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:ac(e,s),done:!0,output:s.outputs.get(u)}}}}),qu=e=>{let t=Wu.get(e);if(t!==void 0)return t;let n=Eu(e),r=n===void 0?Gu(e):Ku(e,n);return Wu.set(e,r),r},Ju=`Machine.invocation:`,Yu=e=>e.startsWith(Ju),Xu=(e,t)=>{if(e.values===void 0?e.values=[t]:e.values.push(t),e.waiter!==void 0){let t=e.waiter;e.waiter=void 0,g(t,U)}},Zu=e=>H(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,B(t)}let t=Xt();return e.waiter=t,wt(t).pipe(D(Zu(e)))}),Qu=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),$u=(e,t,n)=>{if(e.closed)return h();let r=e.children.get(t);return r!==void 0&&Qu(r,n)?O(r.ref):h()},ed=e=>{if(e.observers!==void 0)for(let t of e.observers)Xu(t,$u(e,t.id,t.child))},td=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&ed(e))},nd=(e,t,n,r,i)=>{let a=e.children.get(t);if(e.closed||a===void 0||a._tag!==`Starting`||a.token!==n)return!1;e.children.delete(t);let o=a.ownerKey===void 0?{_tag:`Started`,token:n,descriptor:i,ref:r}:{_tag:`Started`,token:n,descriptor:i,ref:r,ownerKey:a.ownerKey,ownerPath:a.ownerPath,ownerActive:a.ownerActive===!0};return e.children.set(t,o),typeof t==`string`&&ed(e),!0},rd=e=>be(function*(){let t=yield*Zi(),n=0,r=0,i=0,o=0;return{rootSessionId:e,stream:Kr(t).pipe(Qr(L(()=>{n+=1})),a(L(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>o++,publishUnsafe:i=>{n!==0&&xn(t,{...i,sequence:r++,rootSessionId:e})},close:zi(t)}}),id=e=>({id:e.id,sessionId:e.sessionId}),ad=e=>e.flatMap(e=>{if(typeof e!=`object`||!e||!(`_tag`in e))return[];if(e._tag===`SendTo`&&`target`in e&&`event`in e){let t=e.target;return typeof t==`object`&&t&&`id`in t?[{_tag:`SendTo`,target:`sessionId`in t?id(t):{id:String(t.id)},event:e.event}]:[]}if(e._tag===`Stop`&&`child`in e){let t=e.child;return typeof t==`string`?[{_tag:`Stop`,target:{id:t}}]:typeof t==`object`&&t&&`id`in t?[{_tag:`Stop`,target:`sessionId`in t?id(t):{id:String(t.id)}}]:[]}return[]}),od=e=>typeof e!=`object`||!e||!(`microsteps`in e)||!Array.isArray(e.microsteps)?[]:e.microsteps.map(e=>({event:e.event,transitions:Array.isArray(e.transitions)?e.transitions:[],raisedEvents:Array.isArray(e.raisedEvents)?e.raisedEvents:[],emittedEvents:Array.isArray(e.emittedEvents)?e.emittedEvents:[],commands:ad(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),sd=Symbol.for(`effect/Machine/activeSnapshotObserver`),cd=Symbol.for(`effect/Machine/snapshotObserver`),ld=e=>typeof e==`object`&&!!e&&cd in e,ud=Symbol.for(`effect/Machine/sendParentOverride`),dd=Symbol.for(`effect/Machine/acknowledgedSend`),fd=Symbol(`effect/Machine/AcknowledgedMessage`),X=e=>typeof e==`object`&&!!e&&fd in e,pd=e=>X(e)?e.event:e,md=(e,t)=>{e!==void 0&&X(e)&&(e.deferred!==void 0&&g(e.deferred,B(t)),e.inspection?.complete(t))},hd=(e,t)=>{e!==void 0&&X(e)&&e.deferred!==void 0&&g(e.deferred,la(t))},gd=e=>{e!==void 0&&X(e)&&e.deferred!==void 0&&g(e.deferred,N(new oo))},_d=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,vd=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),yd=e=>e?._tag===`Childless`||e?.childless===!0,bd=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},xd=e=>{if(e.items===void 0)return h();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),O(t)},Sd=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)gd(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},Cd=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),wd=(e,t,n)=>{if(e.closed)return!1;for(bd(e,t),n?.();e.items!==void 0&&e.receivers.size>0;){let t=e.receivers.values().next().value;e.receivers.delete(t),t(U)}return!0},Td=e=>H(()=>{let t=xd(e);return A(t)?B(t.value):e.closed?Ve:f(t=>(e.receivers.add(t),L(()=>{e.receivers.delete(t)}))).pipe(D(Td(e)))}),Ed=e=>{Sd(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(Ve)},Dd=class extends Vn()(`effect/Machine/MachineRuntime`){},Od=(e,t)=>Kn(e,Dd,t),kd=e=>{switch(e.status){case`active`:return;case`done`:return{_tag:`Done`,output:e.output,snapshot:e};case`error`:{let t=e.cause.reasons.find(hr);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(pi);return n===void 0?e.cause.reasons.find(wn)===void 0?{_tag:`Cause`,cause:e.cause,snapshot:e}:{_tag:`Interrupted`,cause:e.cause,snapshot:e}:{_tag:`Defect`,defect:n.defect,cause:e.cause,snapshot:e}}case`stopped`:return{_tag:`Stopped`,snapshot:e}}},Ad=(e,t)=>H(()=>e(t)).pipe(Ke,M),jd=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=L(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return L(()=>new n)},Md=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Nd=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&X(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,Pd=(e,t,n,r,i,a)=>{let o=e.nextDeliveryId(),s=e.nextMacrostepId(),c={deliveryId:o,macrostepId:s,source:r,event:n,causedBy:i,complete:i=>{let a=od(i.plan);e.publishUnsafe({_tag:`EventProcessed`,subject:t,macrostepId:s,deliveryId:o,source:r,event:n,before:{status:`active`,state:i.before},after:{status:`active`,state:i.after},handled:a.some(e=>e.transitions.length>0),configurationChanged:a.some(e=>e.changed),microsteps:a})}};return{[fd]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},Fd=(e,t,n)=>{if(!X(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:id(t),event:r.event,causedBy:r.causedBy})},Id=class{registry;self;runtime;services;sendAcknowledged;scopedServices;constructor(e,t,n,r,i){this.registry=e,this.self=t,this.runtime=n,this.services=r,this.sendAcknowledged=i}has(e){for(let t of this.registry.children.values())if(t.ownerActive&&t.ownerKey===e)return!0;return!1}stopEntry(e){return e.ownerActive=!1,e._tag===`Started`?e.ref.stop:U}spawn(e,t){let n=Symbol(),r,i=()=>{let e=this.registry.children.get(t.id);return e?.token===n&&e.ownerKey===t.key&&e.ownerActive===!0};return H(()=>{if(this.registry.closed)return Ve;if(this.has(t.key)||this.registry.children.has(t.id))return N(new ao({id:t.duplicateId}));let a=e(),o=this.registry.scope??=Oe(`parallel`);this.registry.children.set(t.id,{_tag:`Starting`,token:n,ownerKey:t.key,ownerPath:t.path,ownerActive:!0});let s={...this.self,send:e=>t.sendParent(i,e),sendInspected:(e,t,n)=>i()?vd(this.self,e,t,n):U,...this.sendAcknowledged===void 0?void 0:{[dd]:e=>i()?this.sendAcknowledged(e):Ve}},c={detached:!0,id:t.id,sendParent:e=>t.sendParent(i,e),onOutcome:e=>t.onOutcome(i,e,r?.sessionId),...t.onSnapshot===void 0?void 0:{onSnapshot:e=>t.onSnapshot(i,e)},onReadySync:e=>(r=e,nd(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>td(this.registry,t.id,n),skipStoppedOutcome:!0,parent:s,runtime:this.runtime,origin:{_tag:`Invoke`,ownerPath:t.path,invokeId:t.duplicateId},...t.activityKind===void 0||this.runtime.inspection===void 0||this.self.inspectionSubject===void 0?void 0:{activity:{id:t.duplicateId,owner:this.self.inspectionSubject,ownerPath:t.path,kind:t.activityKind}}},l=a.execution,u=this.services!==void 0&&t.onSnapshot===void 0&&l?._tag===`Compiled`&&l.childless&&l.drain._tag===`Owned`&&l.initialSync!==void 0,d=(u?v(this.runtime.nextSessionId,e=>this.runtime.startCompiledSync(a,c,this.scopedServices??=Qn(this.services,tt,o),e)):this.runtime.start(a,c)).pipe(gn(e=>tn(e)?U:(td(this.registry,t.id,n),r===void 0?U:r.stop)));return(u?d:We(d,o)).pipe(M)})}stopAll(){return H(()=>{let e=[];for(let t of this.registry.children.values())t.ownerActive&&e.push(this.stopEntry(t));return e.length===0?U:e.length===1?e[0]:Lt(e,{concurrency:`unbounded`,discard:!0})})}stopPaths(e){if(e.length===0)return;let t=new Set(e),n=[];for(let e of this.registry.children.values())e.ownerActive&&e.ownerPath!==void 0&&t.has(e.ownerPath)&&n.push(this.stopEntry(e));return n.length===0?void 0:n.length===1?n[0]:Lt(n,{concurrency:`unbounded`,discard:!0})}},Ld=Pi(h()).pipe(hn(Dn)),Rd=e=>U,zd=(e,t)=>{},Bd=()=>void 0,Vd=Symbol(`effect/Machine/EmissionsClosed`),Hd=()=>{let e,t=H(()=>{let t=e;return t===Vd?B(void 0):t===void 0?Zi().pipe(v(t=>L(()=>{let n=e;return n===Vd?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(v(([e,n])=>n?zi(t).pipe(re(e)):B(e))))):B(t)});return{emit:t=>H(()=>e===void 0||e===Vd?U:or(e,t).pipe(M)),close:()=>{let t=e;return e=Vd,t===void 0||t===Vd?U:zi(t)},stream:Un(t.pipe(k(e=>e===void 0?yt:Kr(e))))}},Ud={close:()=>U,spawn:(()=>me(Error(`Childless machine logic cannot spawn a process`))),get:()=>B(h()),changes:()=>Ld,sendTo:()=>U,stop:()=>U,owned:{spawn:()=>me(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>U,stopPaths:()=>void 0}},Wd=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>H(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return U;let t=fe(i.scope,e),n,r;for(let e of i.children.values())e._tag===`Started`&&(n===void 0?n=e.ref.stop:(r??=[n],r.push(e.ref.stop)));t!==void 0&&(n===void 0?n=t:(r??=[n],r.push(t)));let a=r??n;return a===void 0?U:Array.isArray(a)?Lt(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>L(()=>td(i,e,t)),s=(e,t,n,r)=>L(()=>nd(i,e,t,n,r)),c=e=>{let t=typeof e==`string`?e:e.id;return L(()=>{if(i.closed)return h();let n=i.children.get(t);return n!==void 0&&Qu(n,e)?O(n.ref):h()})},l=e=>{let t=typeof e==`string`?e:e.id;return ki(zr((n,r)=>L(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(v(n=>{let a=L(()=>{i.observers!==void 0&&(i.observers.delete(n),i.observers.size===0&&(i.observers=void 0)),n.values=void 0,n.waiter=void 0});return ft(r,a).pipe(D(L(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),Xu(n,$u(i,t,e))})),re(Zu(n)))}))))},u=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return H(()=>{if(i.closed)return U;let o=i.children.get(a);return o!==void 0&&Qu(o,e)?vd(o.ref,t,n,r):U})},d=e=>{let t=typeof e==`string`?e:e.id;return H(()=>{if(i.closed)return U;let n=i.children.get(t);return n!==void 0&&Qu(n,e)?n.ref.stop:U})};function f(n,r){let a=typeof n==`object`&&n&&Zc in n?n:void 0,c=a===void 0?n:a[Zc](r?.input),l=a===void 0?r:{id:a.id,descriptor:a},u=Symbol(),d=l?.id??u,f;return H(()=>i.closed?Ve:typeof d==`string`&&(i.children.has(d)||Yu(d))?N(new ao({id:d})):(i.scope??=Oe(`parallel`),i.children.set(d,{_tag:`Starting`,token:u}),t.start(c,{detached:!0,...l?.id===void 0?void 0:{id:l.id},...l?.onOutcome===void 0?void 0:{onOutcome:l.onOutcome},...l?.[sd]===void 0?void 0:{onSnapshot:l[sd]},...l?.[ud]===void 0?void 0:{sendParent:l[ud]},onReady:(e,t)=>L(()=>{f=e}).pipe(D(s(d,u,e,l?.descriptor)),v(e=>e?U:t)),onStop:o(d,u),parent:e,runtime:t,origin:{_tag:`Spawn`,address:l?.id}}).pipe(gn(e=>cn(e)?o(d,u).pipe(D(f===void 0?U:f.stop)):U),We(i.scope))))}return{close:a,spawn:f,get:c,changes:l,sendTo:u,stop:d,owned:new Id(i,e,t,n,r)}},Gd=(e,t,n,r)=>L(()=>Wd(e,t,n,r)),Kd=(e,t)=>`${e.length}:${e}${t}`,qd=(e,t)=>`${Ju}${Kd(e,t)}`,Jd=e=>({initial:()=>U,run:()=>e}),Yd=(e,t,n)=>({initial:()=>U,run:({parent:r})=>{let i=r?.[dd];return i===void 0?me(Error(`Stream invocation requires an acknowledged parent machine`)):Pr(e,e=>i(vl(t,n,e)).pipe(M,wr(()=>Ve)))}}),Xd=(e,t)=>typeof e==`function`?e(t):e,Zd=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),Qd=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Jd(e.effect(t)),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot,activityKind:`Effect`};if(`after`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>Jd(In(Xd(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>Yd(e.stream(t),n,r),onDone:e.onDone,onFailure:e.onFailure,activityKind:`Stream`}}if(`logic`in e)return{id:String(e.id),address:String(e.address),src:()=>Xd(e.logic,t),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot};if(`child`in e){let n=e.child;return{id:n.id,address:n.id,descriptor:n,src:()=>n[Zc](`input`in e?Xd(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},$d=e=>e.length===0?U:e.length===1?e[0]:Lt(e,{discard:!0}),ef=(e,t,n)=>(n===void 0||e.self.sendInspected===void 0?e.self.send(t):e.self.sendInspected(t,e.self.inspectionSubject,{_tag:`Activity`,activitySessionId:n})).pipe(Ze(`StoppedError`,()=>U)),tf=e=>e instanceof ro||e instanceof G||e instanceof oo,nf=(e,t,n,r,a,o,s,c,l,u,d,f)=>H(()=>{let p=Kd(n,r),m=d===void 0?s:()=>{let t=s();return{...t,run:i=>An(H(()=>t.run(i)),`Machine.invoke`,{attributes:{"machine.id":e.self.id,"machine.sessionId":e.self.sessionId,"machine.state.path":n,"machine.invoke.id":r,"machine.invoke.source":f??r,"machine.invoke.kind":d,"machine.invoke.sessionId":i.self.sessionId},captureStackTrace:!1})}};return t.spawn(m,{key:p,path:n,id:a,duplicateId:r,...o===void 0?void 0:{descriptor:o},...d===void 0?void 0:{activityKind:d},sendParent:(t,n)=>t()?e.self.send(n):U,onOutcome:(t,a,s)=>D(Yi,H(()=>a._tag===`Stopped`||!t()?U:a._tag===`Done`?c===void 0?e.failCause(i(Error(`Invocation "${r}" completed without the required onDone handler`))):ef(e,_l(n,r,a.output),d===void 0?void 0:s):a._tag===`Failure`&&l!==void 0&&(o===void 0||!tf(a.error))?ef(e,yl(n,r,a.error),d===void 0?void 0:s):e.failCause(a.cause))),...u===void 0?void 0:{onSnapshot:(t,i)=>t()?ef(e,bl(n,r,i)):U}})}),rf=(e,t)=>Yu(e)?N(new ao({id:t})):void 0,af=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:rf(String(r.address),i);return a===void 0?nf(e,t,n,i,r.address===void 0?qd(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},of=(e,t,n,r)=>{let i=r.child,a=rf(i.id,i.id);return a===void 0?nf(e,t,n,i.id,i.id,i,i[Zc],r.onDone,r.onFailure,r.onSnapshot,void 0):a},sf=(e,t,n,r,i,a)=>{let o=Zd(t),s=Ul(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...Gs(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:ic(e,r,i),ancestors:rc(e,r,i),event:a};return cl(wc(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?of(t,n,i,e):af(t,n,i,Qd(e,s,i)))});return s.length===0?void 0:$d(s)},cf=Symbol(`effect/Machine/CompiledStoppedCompletion`),lf=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[dd](e){return this.sendAcknowledgedEffect(e)}[cd](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=Ud;processScope;processContext;compiledContext;current;lifecycle=`Active`;runState=`Initializing`;completion;waiter;termination;terminationSnapshot;worker;interruptRequested=!1;offerRevision=0;snapshotObservers;changesFlushScheduled=!1;inFlightMessage;externalEmissions;emissionsPubSub;activity;initialEntryPaths;initialMicrosteps;initializing;constructor(e,t,n,r){this.logic=e,this.options=t,this.services=n,this.sessionId=r,this.id=t.id??r;let i=t.runtime.inspection;i!==void 0&&(this.inspectionSubject=Md(e,this.id,r),this.initializing=!0,t.activity!==void 0&&(this.activity={...t.activity,sessionId:r})),this.externalEmissions=t.emissions,this.send=i===void 0?e=>this.offerMessage(e):e=>this.offerEvent(e,void 0,void 0),this.address={id:this.id,sessionId:r,stop:H(()=>this.stopFromProcess()),send:this.send,...i===void 0?void 0:{inspectionSubject:this.inspectionSubject,sendInspected:(e,t,n)=>this.offerEvent(e,t,n)}}}get inspector(){return this.options.runtime.inspection}causation(){return Nd(this.inFlightMessage,this.initializing===!0)}publishCreated(){let e=this.inspector,t=this.inspectionSubject;e!==void 0&&t!==void 0&&e.publishUnsafe(this.activity===void 0?{_tag:`Created`,subject:t,parent:this.options.parent?.inspectionSubject,origin:this.options.origin??{_tag:`Root`},definition:this.logic.inspection?.definition}:{_tag:`ActivityStarted`,subject:this.activity.owner,activity:this.activity})}publishInitialized(e){if(this.initializing=!1,this.activity!==void 0)return;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe({_tag:`Initialized`,subject:n,snapshot:{status:`active`,state:e},initialEntryPaths:this.initialEntryPaths??[],microsteps:od({microsteps:this.initialMicrosteps??[]})})}publishStartFailed(e){this.initializing=!1;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe(this.activity===void 0?{_tag:`StartFailed`,subject:n,cause:e}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:ci(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=Wd(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?Rd:this.inspector===void 0?e.send:t=>vd(e,t,this.inspectionSubject,this.causation()));this.processScope={self:this.address,parent:e,spawn:this.childRuntime.spawn,sendParent:t,emit:e=>this.emitEvent(e),sendTo:((e,t)=>_d(e)?this.inspector===void 0?e.send(t):vd(e,t,this.inspectionSubject,this.causation()):this.childRuntime.sendTo(e,t,this.inspectionSubject,this.causation())),stopChild:this.childRuntime.stop,failCause:e=>this.failCause(e),inspectInitial:this.inspector===void 0?zd:(e,t=[])=>{this.initialEntryPaths=e,this.initialMicrosteps=t}};let n=this.execution.initialSync,r;try{r=n(this.processScope)}catch(e){return this.runState=`Idle`,this.publishStartFailed(Gn(e)),N(e)}return this.runState=`Idle`,this.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:r.state}},this.publishInitialized(r.state),this.compiledContext=new uf(this.processScope,this.childRuntime.owned,this),`executionState`in r&&(this.compiledContext.executionState=r.executionState),this.options.onReadySync!==void 0&&!this.options.onReadySync(this)&&this.requestTerminationSync({_tag:`Stopped`}),r.done===!0&&this.lifecycle===`Active`&&this.requestTerminationSync({_tag:`Done`,output:r.output}),r.done===!1&&this.execution.childless&&this.lifecycle===`Active`&&this.mailbox.items===void 0?B(this):(this.runState=`Draining`,o(this.drainRuntime(),this.services).pipe(re(this)))}initialize(){let e=this;return be(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*Gd(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?Rd:e.inspector===void 0?t.send:n=>vd(t,n,e.inspectionSubject,e.causation()));e.processScope={self:e.address,parent:t,spawn:e.childRuntime.spawn,sendParent:n,emit:t=>e.emitEvent(t),sendTo:((t,n)=>_d(t)?e.inspector===void 0?t.send(n):vd(t,n,e.inspectionSubject,e.causation()):e.childRuntime.sendTo(t,n,e.inspectionSubject,e.causation())),stopChild:e.childRuntime.stop,failCause:t=>e.failCause(t),inspectInitial:e.inspector===void 0?zd:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>cn(t)?e.childRuntime.close(t):U,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(k(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(gn(t=>(cn(t)&&e.publishStartFailed(t.cause),r(t))),Ae(L(()=>{e.runState=`Idle`}))),o=a.state;return e.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:o}},e.publishInitialized(o),e.execution.drain._tag===`Process`?e.processContext={...e.processScope,receive:rn,poll:L(()=>Ct(xd(e.mailbox),pd)),receiveMessage:rn,pollMessage:L(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:L(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new uf(e.processScope,e.childRuntime.owned,e),`executionState`in a&&(e.compiledContext.executionState=a.executionState)),e.options.onReadySync!==void 0&&!e.options.onReadySync(e)?yield*e.requestTermination({_tag:`Stopped`}):e.options.onReady!==void 0&&(yield*e.options.onReady(e,e.requestTermination({_tag:`Stopped`}).pipe(M))),e.options.onSnapshot!==void 0&&(yield*Ad(e.options.onSnapshot,{status:`active`,state:o})),a.done===!0&&e.lifecycle===`Active`&&(yield*e.requestTermination({_tag:`Done`,output:a.output})),a.done===!1&&e.execution.childless&&e.lifecycle===`Active`&&e.mailbox.items===void 0||(e.runState=`Draining`,yield*e.drainRuntime()),e})}get state(){return L(()=>this.current.snapshot.state)}get snapshot(){return L(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return H(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=Xt(),wt(this.waiter)))}get stop(){return ur(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return L(()=>this.requestTerminationSync(e))}hasTerminationRequest(){return this.lifecycle===`TerminationRequested`}requestTerminationSync(e){return this.lifecycle===`Active`&&(this.lifecycle=`TerminationRequested`,this.termination=e,this.terminationSnapshot=this.reserveTermination(e),!0)}reserveTermination(e){let t=this.current;if(t===void 0||t.terminalizing||t.snapshot.status!==`active`)return;let n=e._tag===`Stopped`?{status:`stopped`,state:t.snapshot.state}:e._tag===`Done`?{status:`done`,state:t.snapshot.state,output:e.output}:{status:`error`,state:t.snapshot.state,cause:e.cause};return this.current={...t,terminalizing:!0},n}stopFromProcess(){let e=this.requestTermination({_tag:`Stopped`}).pipe(M);return this.runState===`Initializing`?e:e.pipe(D(Ve))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(v(e=>e?Qt(this.settleRequestedTermination()).pipe(M):U))}sendAcknowledgedEffect(e){return ir(t=>Bt().pipe(v(n=>this.offerEvent(e,void 0,void 0,n).pipe(D(t(wt(n)))))))}offerEvent(e,t,n,r){return H(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?Pd(i,a,e,t,n,r):r===void 0?e:{[fd]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return ur(ta(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return N(new oo);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&Fd(n,r,e),this.offerRevision+=1;let i=this.execution.drain,a=this.compiledContext,o=this.runState===`Idle`&&a!==void 0&&i._tag===`Owned`?i.runSync:void 0;if(o===void 0&&bd(this.mailbox,e),this.runState!==`Idle`)return U;if(this.runState=`Draining`,o!==void 0){let n;try{n=o(a,e)}catch(e){n=me(e)}return n!==void 0||this.hasTerminationRequest()?this.startWorker(n):(this.runState=`Idle`,this.scheduleChangesFlush(t.currentDispatcher),U)}return this.startWorker(void 0)}))}startWorker(e){let t=o(this.drainRuntime(e),this.services);return(this.options.detached===!0?Qt(t,{startImmediately:!0}):Ht(t,{startImmediately:!0})).pipe(v(e=>L(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(v(t=>t?Qt(this.interruptAndFinish(e)):U))),M)}stopEffect(){return H(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?U:this.requestTermination({_tag:`Stopped`}).pipe(v(e=>e?this.settleRequestedTermination():this.awaitCompletion())))}finishIdleChildlessStop(){if(!this.execution.childless||this.runState!==`Idle`||this.worker!==void 0||this.lifecycle!==`Active`||this.options.onOutcome!==void 0&&this.options.skipStoppedOutcome!==!0||this.options.onStop!==void 0||this.inspector!==void 0||this.current.changes!==void 0||this.externalEmissions!==void 0||this.emissionsPubSub!==void 0&&this.emissionsPubSub!==Vd||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=Vd;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,Sd(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),gd(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=cf,this.lifecycle=`Completed`,this.waiter!==void 0&&(g(this.waiter,this.resolveCompletion(cf)),this.waiter=void 0),!0}settleRequestedTermination(){return H(()=>this.runState===`Draining`?this.worker===void 0?(this.interruptRequested=!0,this.awaitCompletion()):this.interruptAndFinish(this.worker).pipe(D(this.awaitCompletion())):this.finishRequestedTermination())}interruptAndFinish(e){return w(e).pipe(D(H(()=>this.lifecycle===`Completed`?U:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?U:this.join.pipe(Ke,M)}resolveCompletion(e){if(e!==cf)return e;let t=N(new oo);return this.completion=t,t}drainRuntime(e){let t=this;return ir(n=>be(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(H(()=>{if(i!==void 0){let e=i;return i=void 0,e}let e=t.execution.drain;return e._tag===`Process`?e.run(t.processContext):e.run(t.compiledContext)})).pipe(Ke);if(t.flushPendingChanges(),cn(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(A(e.value))return yield*t.requestTermination({_tag:`Done`,output:e.value.value}),yield*t.finishRequestedTermination();if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();if(t.offerRevision!==r)r=t.offerRevision;else{t.runState=`Idle`,t.worker=void 0;return}}}))}finishRequestedTermination(){return H(()=>{if(this.lifecycle!==`TerminationRequested`)return U;let e=this.termination;if(e===void 0)return U;let t=this.terminationSnapshot??this.reserveTermination(e);if(t===void 0)return this.awaitCompletion();let n=e._tag===`Stopped`?vt:e._tag===`Done`?mn(e.output):ci(e.cause),r=e._tag===`Stopped`?cf:e._tag===`Done`?B(e.output):la(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?U:H(()=>this.options.onOutcome(kd(t))).pipe(Ke,M),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(D(L(()=>a.publishUnsafe(this.activity===void 0?{_tag:`Terminated`,subject:o,snapshot:t}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:t.status===`stopped`?Pe():n}))));return ur(L(()=>{Sd(this.mailbox)}).pipe(D(this.childRuntime.close(n)),D(this.setAndPublishSnapshot(t)),D(s),D(L(()=>{e._tag===`Failure`?hd(this.inFlightMessage,e.cause):gd(this.inFlightMessage),this.inFlightMessage=void 0})),D(i),D(this.options.onStop??U),D(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:U),D(L(()=>{this.options.onStopSync?.(this),this.runState=`Idle`,this.worker=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.completion=r,this.lifecycle=`Completed`,this.waiter!==void 0&&(g(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?B(e):or(e.changes,[e]).pipe(re(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe($n(()=>Ad(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?U:or(e.changes,mn(void 0)).pipe(M)}emitEvent(e){let t=this.externalEmissions===void 0?H(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===Vd?U:or(this.emissionsPubSub,e).pipe(M)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe($n(()=>L(()=>n.publishUnsafe({_tag:`Emitted`,subject:r,emission:e,causedBy:this.causation()}))))}shutdownEmissions(){return this.closeEmissions()}closeEmissions(){if(this.externalEmissions!==void 0)return this.externalEmissions.close();let e=this.emissionsPubSub;return this.emissionsPubSub=Vd,e===void 0||e===Vd?U:zi(e)}getOrCreateEmissions(){return H(()=>{let e=this.emissionsPubSub;return e===Vd?B(void 0):e===void 0?Zi().pipe(v(e=>L(()=>{let t=this.emissionsPubSub;return t===Vd?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(v(([t,n])=>n?zi(e).pipe(re(t)):B(t))))):B(e)})}emissionsStream(){return Un(this.getOrCreateEmissions().pipe(k(e=>e===void 0?yt:Kr(e))))}setAndPublishSnapshot(e){return H(()=>{this.flushPendingChanges();let t={revision:this.current.revision+1,snapshot:e,terminalizing:!0,changes:this.current.changes};return this.current=t,this.notifySnapshotObservers(),this.publishSnapshot(t).pipe(v(e=>this.completeChanges(e)),M)})}setActiveState(e){return H(()=>this.commitActiveState(e)??U)}pollCompiledMessage(){let e=xd(this.mailbox);return A(e)&&(this.inFlightMessage=X(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=X(e)?e:void 0}completeCompiledMessage(e){md(this.inFlightMessage,e),this.inFlightMessage=void 0}compiledState(){return this.current.snapshot.state}commitCompiledState(e){return this.commitActiveState(e,!0)}commitActiveState(e,t=!1){let n=this.current;if(n.terminalizing||n.snapshot.status!==`active`)return;let r=n.pendingChanges;r!==void 0&&(n.pendingChanges=void 0);let i={status:`active`,state:e},a={revision:n.revision+1,snapshot:i,terminalizing:!1,changes:n.changes};return this.current=a,a.changes!==void 0&&(r===void 0?t?a.pendingChanges=[a]:xn(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:xn(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:Ad(this.options.onSnapshot,i)}notifySnapshotObservers(){if(this.snapshotObservers!==void 0)for(let e of this.snapshotObservers)e()}scheduleChangesFlush(e){this.changesFlushScheduled||this.current.pendingChanges===void 0||(this.changesFlushScheduled=!0,e.scheduleTask(()=>{this.changesFlushScheduled=!1,this.flushPendingChanges()},0))}flushPendingChanges(){let e=this.current,t=e?.pendingChanges;t!==void 0&&e.changes!==void 0&&(e.pendingChanges=void 0,xn(e.changes,t))}updateState(e){return H(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?U:e(t.snapshot.state).pipe(v(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?U:this.setActiveState(e)}))})}getOrCreateChanges(){return H(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?Zi({replay:1}).pipe(v(e=>L(()=>{let t=this.current;return t.snapshot.status===`active`?t.changes===void 0?(this.current={...t,changes:e},[e,!1]):[t.changes,!0]:[void 0,!0]}).pipe(v(([t,n])=>n?zi(e).pipe(re(t)):B(t))))):B(e.changes):B(void 0)})}changesStream(){let e=this;return Un(be(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return Pi(e.current.snapshot);let n=yield*ra(t),r=e.current;return r.snapshot.status===`active`?Pi(r.snapshot).pipe(hn(ki(ii(Mn(n))).pipe(Yn(e=>e.revision>r.revision),vr(e=>e.snapshot)))):Pi(r.snapshot)}))}},uf=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return Ct(this.process.pollCompiledMessage(),pd)}pollMessage(){return this.process.pollCompiledMessage()}beginMessage(e){this.process.beginCompiledMessage(e)}state(){return this.process.compiledState()}completeMessage(e){this.process.completeCompiledMessage(e)}commit(e){return this.process.commitCompiledState(e)}runAfterChanges(e){return this.process.flushPendingChanges(),e}},df=qt(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*rt(),i=e.execution,a=new lf(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(gn(e=>cn(e)?a.shutdownEmissions().pipe(D(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:U)):U))}),ff=(e,t,n,r)=>new lf(e,t,n,r).initializeCompiledSync(),pf=`~effect/SynchronizedRef`,mf={..._e,[pf]:pf,toJSON(){return{_id:`SynchronizedRef`,value:this.backing.ref.current}}},hf=e=>{let t=Object.create(mf);return t.semaphore=fr(1),t.backing=fa(e),t},gf=e=>L(()=>hf(e)),_f=e=>e.backing.ref.current,vf=e=>L(()=>_f(e)),yf=pn(2,(e,t)=>e.semaphore.withPermit(pa(e.backing,t))),bf=pn(2,(e,t)=>e.semaphore.withPermit(H(()=>{let n=_f(e);return k(t(n),([t,n])=>(e.backing.ref.current=n,t))}))),xf=pn(2,(e,t)=>e.semaphore.withPermit(ma(e.backing,t))),Sf=qt(function*(e,t){let{detached:n,id:r,onOutcome:i,onReady:a,onReadySync:o,onSnapshot:s,onStop:c,onStopSync:l,parent:u,runtime:d,sendParent:f}=t,p=t.sessionId??(yield*d.nextSessionId),m=r??p,h=d.inspection,g=h===void 0?void 0:Md(e,m,p),_=h===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:p},y,b,x=Cd(),S=t.emissions??Hd(),C=yield*Bt(),T=yield*Bt(),ee=wt(T).pipe(Ke,M),te=!0,E,ne=ze(C,{_tag:`Stopped`}).pipe(M),ie=(e,t)=>H(()=>wd(x,e,t)?U:N(new oo)),ae=h===void 0?void 0:(e,t,n,r)=>H(()=>{let i=h.isActive()?Pd(h,g,e,t,n,r):r===void 0?e:{[fd]:!0,event:e,deferred:r};return ie(i,()=>Fd(h,g,i))}),oe=e.execution?._tag===`Compiled`?e=>ir(t=>Bt().pipe(v(n=>(h===void 0?ie({[fd]:!0,event:e,deferred:n}):ae(e,void 0,void 0,n)).pipe(D(t(wt(n))))),k(e=>e))):void 0,se={id:m,sessionId:p,stop:H(()=>te?ne:ne.pipe(D(rn))),send:h===void 0?e=>ie(e):e=>ae(e,void 0,void 0),...h===void 0?void 0:{inspectionSubject:g,sendInspected:ae}},{changes:ce,close:le,get:ue,owned:de,sendTo:fe,spawn:pe,stop:me}=Ud;yd(e.execution)||({changes:ce,close:le,get:ue,owned:de,sendTo:fe,spawn:pe,stop:me}=yield*Gd(se,d,void 0,oe===void 0?void 0:e=>oe(e)));let he=e=>tn(e)?U:(h!==void 0&&h.publishUnsafe(_===void 0?{_tag:`StartFailed`,subject:g,cause:e.cause}:{_tag:`ActivityStopped`,subject:_.owner,activity:_,exit:e}),le(e).pipe(D(S.close()),D(t.inspectionRoot===!0&&h!==void 0?h.close:U))),ge=l===void 0?c??U:L(()=>l(Qe)),_e=h===void 0?Bd:()=>Nd(E,te),ye=f??(u===void 0?Rd:h===void 0?u.send:e=>vd(u,e,g,_e())),xe=h===void 0?S.emit:e=>S.emit(e).pipe($n(()=>L(()=>h.publishUnsafe({_tag:`Emitted`,subject:g,emission:e,causedBy:_e()})))),O={self:se,parent:u,spawn:pe,sendParent:ye,emit:xe,sendTo:h===void 0?((e,t)=>_d(e)?e.send(t):fe(e,t)):((e,t)=>_d(e)?vd(e,t,g,_e()):fe(e,t,g,_e())),stopChild:me,failCause:e=>ze(C,{_tag:`Failure`,cause:e}).pipe(M),inspectInitial:h===void 0?zd:(e,t=[])=>{y=e,b=t}};h!==void 0&&h.publishUnsafe(_===void 0?{_tag:`Created`,subject:g,parent:u?.inspectionSubject,origin:t.origin??{_tag:`Root`},definition:e.inspection?.definition}:{_tag:`ActivityStarted`,subject:_.owner,activity:_});let Ce=yield*e.initial(O).pipe(gn(he),Ae(L(()=>{te=!1}))),we=yield*gf({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:Ce}});_===void 0&&h?.publishUnsafe({_tag:`Initialized`,subject:g,snapshot:{status:`active`,state:Ce},initialEntryPaths:y??[],microsteps:od({microsteps:b??[]})});let Te=s===void 0?e=>e.changes===void 0?B(e):or(e.changes,[e]).pipe(re(e)):e=>{let t=e.changes===void 0?B(e):or(e.changes,[e]).pipe(re(e)),n=e.snapshot;return n.status===`active`?t.pipe($n(()=>Ad(s,n))):t},Ee=e=>e.changes===void 0?U:or(e.changes,mn(void 0)).pipe(M),Oe=e=>e.snapshot.status===`active`?B(e):Ee(e).pipe(re(e)),ke=e=>vf(we).pipe(v(t=>t.revision===e.revision?Te(e).pipe(v(Oe)):B(void 0))),je=e=>bf(we,t=>t.terminalizing?B([void 0,t]):k(e(t.snapshot),e=>{if(e===void 0)return[void 0,t];let n={revision:t.revision+1,snapshot:e,terminalizing:!1,changes:t.changes};return[n,n]})).pipe(v(e=>e===void 0?B(void 0):ke(e)),k(e=>e?.snapshot)),Me=e=>yf(we,t=>t.terminalizing||t.snapshot.status!==`active`?[void 0,t]:[{revision:t.revision+1,snapshot:e(t.snapshot),terminalizing:!0,changes:t.changes},{...t,terminalizing:!0}]).pipe(k(e=>e?.snapshot)),Ne=e=>xf(we,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(v(Te),v(Oe),M),Fe=h===void 0?e=>je(t=>B(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(M):t=>vf(we).pipe(v(n=>je(e=>B(e.status===`active`?{status:`active`,state:t}:void 0)).pipe($n(r=>L(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&h.publishUnsafe({_tag:`StateChanged`,subject:g,before:n.snapshot.state,after:t,causedByDeliveryId:E!==void 0&&X(E)?E.inspection?.deliveryId:void 0})})))),M),Ie=(e,n,r)=>{let a=i===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?U:H(()=>i(kd(e))).pipe(Ke,M),o=h===void 0?S.close():S.close().pipe(D(L(()=>h.publishUnsafe(_===void 0?{_tag:`Terminated`,subject:g,snapshot:e}:{_tag:`ActivityStopped`,subject:_.owner,activity:_,exit:e.status===`stopped`?Pe():n}))));return ur(L(()=>Ed(x)).pipe(D(le(n)),D(Ne(e)),D(o),D(L(()=>{cn(n)?hd(E,n.cause):gd(E),E=void 0})),D(a),D(ge),D(t.inspectionRoot===!0&&h!==void 0?h.close:U),D(r)))},Le=Me(e=>({status:`stopped`,state:e.state})),Re=e=>Me(t=>({status:`error`,state:t.state,cause:e})),Be=e=>Me(t=>({status:`done`,state:t.state,output:e})),Ve=e=>Ie(e,vt,Gt(T,new oo)),He=(e,t)=>{let n=ci(t);return Ie(e,n,Se(T,t))},Ue=(e,t)=>{let n=mn(t);return Ie(e,n,ze(T,t))},We=ur(ne.pipe(D(ee))),Ge=e.execution?._tag===`Compiled`?{receiveMessage:Td(x).pipe($n(e=>L(()=>{E=X(e)?e:void 0}))),pollMessage:L(()=>xd(x)).pipe($n(e=>L(()=>{A(e)&&(E=X(e.value)?e.value:void 0)}))),completeMessage:e=>{md(E,e),E=void 0}}:void 0,qe=h===void 0||e.execution?._tag===`Compiled`?Td(x).pipe(k(pd)):Td(x).pipe($n(e=>L(()=>{E=e})),k(pd)),Je=h===void 0||e.execution?._tag===`Compiled`?L(()=>xd(x)).pipe(k(Ct(pd))):L(()=>xd(x)).pipe($n(e=>L(()=>{A(e)&&(E=e.value)})),k(Ct(pd))),Ye=h===void 0?e=>je(t=>t.status===`active`?e(t.state).pipe(k(e=>({status:`active`,state:e}))):B(void 0)).pipe(M):t=>vf(we).pipe(v(n=>je(e=>e.status===`active`?t(e.state).pipe(k(e=>({status:`active`,state:e}))):B(void 0)).pipe($n(t=>L(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&h.publishUnsafe({_tag:`StateChanged`,subject:g,before:n.snapshot.state,after:t.state,causedByDeliveryId:E!==void 0&&X(E)?E.inspection?.deliveryId:void 0})})))),M),Xe={...O,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:de}:void 0,...Ge,receive:qe,poll:Je,state:vf(we).pipe(k(e=>e.snapshot.state)),setState:Fe,updateState:Ye},j=bf(we,e=>e.snapshot.status===`active`?e.changes===void 0?Zi({replay:1}).pipe(k(t=>[t,{...e,changes:t}])):B([e.changes,e]):B([void 0,e])),Ze=Un(be(function*(){let e=yield*j;if(e===void 0)return Pi((yield*vf(we)).snapshot);let t=yield*ra(e),n=yield*vf(we);return n.snapshot.status===`active`?Pi(n.snapshot).pipe(hn(ki(ii(Mn(t))).pipe(Yn(e=>e.revision>n.revision),vr(e=>e.snapshot)))):Pi(n.snapshot)})),Qe={id:m,sessionId:p,...h===void 0?void 0:{inspectionSubject:g,sendInspected:ae},state:vf(we).pipe(k(e=>e.snapshot.state)),snapshot:vf(we).pipe(k(e=>e.snapshot)),changes:Ze,emissions:S.stream,join:wt(T),stop:We,send:se.send,...oe===void 0?void 0:{[dd]:oe},child:ue,childChanges:ce};o!==void 0&&!o(Qe)?yield*ne:a!==void 0&&(yield*a(Qe,ne)),s!==void 0&&(yield*Ad(s,{status:`active`,state:Ce}));let $e=e=>{switch(e._tag){case`Stopped`:return Le;case`Done`:return Be(e.output);case`Failure`:return Re(e.cause)}},et=(e,t)=>{switch(e._tag){case`Stopped`:return Ve(t);case`Done`:return Ue(t,e.output);case`Failure`:return He(t,e.cause)}},tt=e=>n===!0?Qt(e,{startImmediately:!0}):Ht(e,{startImmediately:!0}),nt=yield*ve(C),rt=De(nt)?yield*ir(t=>t(H(()=>e.run(Xe))).pipe(Ke,v(e=>ze(C,cn(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(tt):void 0;return yield*tt(ir(e=>be(function*(){let t=A(nt)?yield*nt.value:yield*e(wt(C)),n=yield*$e(t);return rt!==void 0&&(yield*w(rt)),n===void 0?yield*ee:yield*et(t,n)}))),Qe}),Cf=((e,t)=>e.execution?._tag===`Compiled`?df(e,t):Sf(e,t)),wf=jd(Cf,ff),Tf=new WeakMap,Ef=e=>H(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),we(t,e=>e.stop,{discard:!0})}),Df=()=>{let e=new Set,t={live:e,hooks:{onReadySync:n=>!t.closed&&(e.add(n),!0),onStopSync:t=>{e.delete(t)}},closed:!1};return t},Of=e=>v(Xr,t=>{let n=Tf.get(t);if(n!==void 0)return e(n.hooks);let r=Df();return Tf.set(t,r),D(ft(t,Ef(r)),e(r.hooks))});qt(function*(e,t,n){let r=yield*wf,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*Of(t=>Sf(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*Of(t=>df(e,{...i,...t})):yield*me(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*Of(t=>Cf(e,{...i,...t}))});var kf=qt(function*(e,t){let n=yield*wf;return yield*Of(r=>Cf(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),Af=qt(function*(e,t,n){let r=yield*wf,i=yield*r.nextSessionId,a=yield*rd(i);r.inspection=a;let o=Hd(),s=yield*Bt(),c=n===void 0?{detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}}:{...n,detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}},l=yield*kr(Of(n=>{let r={...c,...n};return t===`generic`?Sf(e,r):t===`compiled`?e.execution?._tag===`Compiled`?df(e,r):me(Error(`Machine cannot force the compiled runtime for generic process logic`)):Cf(e,r)}).pipe(gn(e=>sa(s,e))));return{id:n?.id??i,sessionId:i,changes:Un(wt(s).pipe(k(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),jf=((e,t)=>Af(e,`auto`,t));Ri({_tag:Hn(`MachineSnapshot`),version:Hn(2),active:xi(Ri({path:F,value:j(Ni)})),completed:j(xi(Ri({path:F,output:j(Ni)}))),history:j(dr(F,Ri({mode:er([`shallow`,`deep`]),active:xi(F),values:dr(F,Ni)})))});var Mf=(e,t,n)=>{let r=q(e,n);if(r.type===`compound`){let r=Tc(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return Mf(e,t,r)}return r.output},Nf=(e,t)=>be(function*(){let n=yield*gc(e,t),r=new Map,i=new Set,a=t.completed??[];if(!Array.isArray(a))throw Error(`Machine snapshot completion metadata must be an array`);for(let t of a){if(typeof t!=`object`||!t||typeof t.path!=`string`)throw Error(`Machine snapshot contains malformed completion metadata`);let a=t.path;if(i.has(a))throw Error(`Machine snapshot contains duplicate completion "${a}"`);if(!n.active.has(a)||!Oc(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=Mf(e,n,a);if(o===void 0){if(t.output!==void 0)throw Error(`Machine snapshot contains an output for state "${a}" without an output schema`);r.set(a,void 0)}else r.set(a,yield*ws(e,o,t.output,{boundary:`output`,state:a}))}return sc(e,{...n,outputs:r})}).pipe(wr(t=>Pf(e,t))),Pf=(e,t)=>{if(Hr(t))return la(Yr(t,t=>t instanceof G?t:new G({machineId:e.id,boundary:`configuration`,cause:Gn(t)})));let n=Ti(t);return A(n)&&n.value instanceof G?N(n.value):N(new G({machineId:e.id,boundary:`configuration`,cause:t}))},Ff=e=>e.length===0?U:e.length===1?e[0]:Lt(e,{discard:!0}),If=(e,t)=>({event:e.event,next:t(e.next),commands:e.commands,emittedEvents:e.emittedEvents,microsteps:e.microsteps.map(e=>({...e,transitions:e.transitions??[],next:t(e.next)})),done:e.done,output:e.output}),Lf=new WeakMap,Rf=e=>{let t=Lf.get(e);if(t!==void 0)return t;let n=Object.values(K(e).handlers).some(e=>e.invoke!==void 0);return Lf.set(e,n),n},zf=B(h()),Bf=(e,t)=>{let n=qu(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=vu(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return du(e,r)?fu(e,r,uu).pipe(k(O)):void 0},o=e=>H(()=>c(e)??zf),s=(e,t,r,a,s)=>{let c=a.commands.length===0?void 0:yu(a.commands,e.scope),l=a.emittedEvents.length===0?void 0:bu(a.emittedEvents,i(e)),u=()=>{let i=H(()=>(t&&e.completeMessage({before:r,plan:If(a,n.snapshot),after:s}),a.done?B(O(a.output)):o(e)));return l===void 0?i:l.pipe(D(i))},d=()=>{let t=e.commit(s),n=u(),r=t===void 0?n:t.pipe(D(n));return t===void 0&&l===void 0?r:e.runAfterChanges(r)};return c===void 0?d():e.runAfterChanges(c.pipe(D(H(d))))},c=(t,r)=>{let i=r;for(;;){let r;if(i!==void 0)r=i,i=void 0,t.beginMessage(r);else{let e=t.pollMessage();if(De(e))return;r=e.value}let a=X(r),c=a?r.event:r,l=t.state(),u;try{u=n.plan(t.executionState??n.fromConfiguration(mc(e,l)),c,a,t.scope)}catch(e){return co(e)}if(t.executionState=u.next,u.microsteps.length===0){a&&t.completeMessage({before:l,plan:If(u,n.snapshot),after:l});continue}let d=n.snapshot(u.next);if(u.commands.length>0||u.emittedEvents.length>0||u.done)return s(t,a,l,u,d);let f=t.commit(d);if(f!==void 0)return t.runAfterChanges(f.pipe(D(H(()=>(a&&t.completeMessage({before:l,plan:If(u,n.snapshot),after:d}),o(t))))));a&&t.completeMessage({before:l,plan:If(u,n.snapshot),after:d})}};return{run:e=>Od(a(e)??o(e),e.scope),runSync:(e,t)=>{let n=a(e);n!==void 0&&e.beginMessage(t);let r=n??c(e,t);return r===void 0?void 0:Od(r,e.scope)}}},Vf=class{initialized=!1;initial;constructor(e){this.initial=e}},Hf=(e,t)=>{let n=qu(e);return r=>{let i=r.state();if(t&&du(e,i))return fu(e,i,uu).pipe(k(O));let a=r.scope,o=r.executionState,s=o instanceof Vf?o:new Vf;r.executionState=s;let c,l,u;return u=H(()=>{let t=r.pollMessage();if(De(t))return l=void 0,B(h());let o=t.value,s=X(o),d=s?o.event:o,f=i,p;try{p=n.plan(l??n.fromConfiguration(mc(e,i)),d,s,a)}catch(e){return co(e)}if(l=p.next,p.microsteps.length===0)return s&&r.completeMessage({before:f,plan:If(p,n.snapshot),after:i}),u;let m=p.microsteps.some(e=>e.changed),g=m?p.microsteps.flatMap(e=>e.exitPaths):[],_=new Map;if(m){for(let e of p.microsteps)if(e.changed)for(let t of e.entryPaths)_.set(t,e.event)}let v=n.toConfiguration(p.next),y=n.snapshot(p.next),b=[];if(p.commands.length>0&&b.push(yu(p.commands,a)),m){let e=r.ownedChildren.stopPaths(g);e!==void 0&&b.push(e)}let x=[];if(p.emittedEvents.length>0&&x.push(bu(p.emittedEvents,c??=vu(e,a))),p.done)x.push(r.ownedChildren.stopAll());else if(m)for(let[t,n]of _){let i=sf(e,a,r.ownedChildren,v,[t],n);i!==void 0&&x.push(i)}let S=()=>{let e=r.commit(y);return i=y,e},C=()=>{let e=H(()=>(s&&r.completeMessage({before:f,plan:If(p,n.snapshot),after:y}),p.done?B(O(p.output)):u));return x.length===0?e:Ff(x).pipe(D(e))},w=()=>{let e=S(),t=C(),n=e===void 0?t:e.pipe(D(t));return e===void 0&&x.length===0?n:r.runAfterChanges(n)};return b.length===0?w():r.runAfterChanges(Ff(b).pipe(D(H(w))))}),Od(H(()=>{if(s.initialized)return u;let t=s.initial,o=t?.activeConfiguration??mc(e,i);l=t?.configuration??n.fromConfiguration(o);let c=sf(e,a,r.ownedChildren,o,t?.entryPaths??ac(e,o),uu);return s.initial=void 0,s.initialized=!0,c===void 0?u:c.pipe(D(u))}),a)}},Uf=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},Wf=(e,t)=>{let n=Rf(e),r=qu(e),i=t._tag===`Initial`?t.args:[],a=t._tag===`Initial`?r.initial:void 0,o=a===void 0?void 0:e=>{try{let t=a(i,e);e.inspectInitial(t.initialEntryPaths);let r=Uf(t);return n?{...r,executionState:new Vf({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw lo(e)}},s=t=>a===void 0?Od(_u(Tl(e,t),...i).pipe(v(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:yu(n.commands,t),i=n.emittedEvents.length===0?void 0:bu(n.emittedEvents,vu(e,t)),a=B(Uf(n));return r===void 0?i===void 0?a:i.pipe(D(a)):i===void 0?r.pipe(D(a)):r.pipe(D(i),D(a))})),t):Rr({try:()=>o(t),catch:lo});return{inspection:{kind:`Machine`,definition:e},execution:{_tag:`Compiled`,childless:!n,...t._tag===`Initial`?{initial:s}:{},...o===void 0?{}:{initialSync:o},drain:n?{_tag:`Owned`,run:Hf(e,t._tag===`Resume`)}:{_tag:`Owned`,...Bf(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?Od(Nf(e,t.snapshot),n):s(n).pipe(k(e=>e.state)),run:t=>Od(be(function*(){let{completeMessage:r,pollMessage:i,receiveMessage:a,state:o,setState:s}=t;if(r===void 0||i===void 0||a===void 0)return yield*me(Error(`Machine statechart started without acknowledged mailbox access`));let c,l=yield*o;if(du(e,l))return yield*fu(e,l,uu);if(!n){let n,o=h(),u;for(;c===void 0;){let d=A(o)?o.value:yield*a;o=h();let f=X(d),p=f?d.event:d,m=l,g;try{g=gu(e,Ws(n??mc(e,l),t),p)}catch(e){return yield*co(e)}if(n=g.next,g.microsteps.length>0){let n=sc(e,g.next);yield*yu(g.commands,t),yield*s(n),l=n,g.emittedEvents.length>0&&(yield*bu(g.emittedEvents,u??=vu(e,t))),g.done&&(c={output:g.output})}f&&r({before:m,plan:If(g,t=>sc(e,t)),after:l}),c===void 0&&(o=yield*i,De(o)&&(n=void 0))}return c===void 0?yield*me(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}let u=t.ownedChildren;if(u===void 0)return yield*me(Error(`Invoking statechart started without an owned child runtime`));let d=(n,r,i)=>sf(e,t,u,n,r,i)??U,f=e=>u.stopPaths(e)??U;return yield*be(function*(){let n=yield*gc(e,l);yield*d(n,ac(e,n),uu),n=void 0;let o=h(),p;for(;c===void 0;){let m=A(o)?o.value:yield*a;o=h();let g=X(m),_=g?m.event:m,v=l,y;try{y=gu(e,Ws(n??mc(e,l),t),_)}catch(e){return yield*co(e)}if(n=y.next,y.microsteps.length>0){let n=y.microsteps.some(e=>e.changed),r=y.microsteps.flatMap(e=>e.exitPaths),i=new Map;for(let e of y.microsteps)if(e.changed)for(let t of e.entryPaths)i.set(t,e.event);let a=sc(e,y.next);if(yield*yu(y.commands,t),n&&(yield*f(r)),yield*s(a),l=a,y.emittedEvents.length>0&&(yield*bu(y.emittedEvents,p??=vu(e,t))),y.done)c={output:y.output},yield*u.stopAll();else if(n)for(let[e,t]of i)yield*d(y.next,[e],t)}g&&r({before:v,plan:If(y,t=>sc(e,t)),after:l}),c===void 0&&(o=yield*i,De(o)&&(n=void 0))}return c===void 0?yield*me(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}).pipe(gn(()=>u.stopAll()))}),t)}},Gf=new WeakMap,Kf=(e,...t)=>{if(t.length>0)return Wf(e,{_tag:`Initial`,args:t});let n=Gf.get(e);if(n!==void 0)return n;let r=Wf(e,{_tag:`Initial`,args:t});return Gf.set(e,r),r},qf=(e,t)=>Wf(e,{_tag:`Resume`,snapshot:t}),Jf=(e,...t)=>jf(Kf(e,...t),e.id===void 0?void 0:{id:e.id}),Yf=(e,t)=>kf(qf(e,t),e.id===void 0?void 0:{id:e.id}),Xf={atomic:[`schema`,`type`,`annotations`],final:[`schema`,`type`,`output`,`annotations`],compound:[`schema`,`type`,`states`,`annotations`],parallel:[`schema`,`type`,`output`,`states`,`annotations`],history:[`type`,`history`,`annotations`],choice:[`type`,`annotations`]},Zf=[`title`,`description`,`documentation`],Qf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),$f=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},Z=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},ep=e=>Number.isFinite(Number(e)),tp=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,np=(e,t)=>{if(t.has(e))return`opaque`;if(Ce(e)||ca(e)||Zt(e)||ye(e)||li(e)||Ge(e))return`tagged`;if(Tt(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return Be(e)?tp(e.types.map(e=>np(e,n))):Vt(e)?np(e.thunk(),n):ke(e)?`opaque`:`untagged`},rp=(e,t=new Set)=>{if(t.has(e))return`opaque`;if(_(e)){let n=e.propertySignatures.find(({name:e})=>e===`_tag`)?.type;return n===void 0||Kt(n)?`untagged`:np(n,new Set(t).add(e))}let n=new Set(t).add(e);return Be(e)?tp(e.types.map(e=>rp(e,n))):Vt(e)?rp(e.thunk(),n):ke(e)?`opaque`:`untagged`},ip=e=>z(e)&&rp(Fe(e.ast))!==`untagged`,ap=(e,t,n)=>{let r=$f(t,n);return typeof n==`symbol`?Z(e,r,`state keys must be strings, not symbols`):typeof n==`number`?Z(e,r,`state keys cannot use numeric forms`):n===``?Z(e,r,`state keys cannot be empty`):n===`__proto__`?Z(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?Z(e,r,`state keys cannot contain "."`):ep(n)?Z(e,r,`state keys cannot use numeric forms`):r},op=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&Z(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&Z(e,$f(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},sp=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!Qf(n,r))return;let a=n[r];(typeof a!=`object`||!a||z(a)||a.type!==`history`)&&Z(e,`${t}.${r}`,i)},cp=(e,t,n,r)=>{let i=Xf[r];for(let a of Reflect.ownKeys(n))i.includes(a)||Z(e,t,`${r} states cannot declare property "${String(a)}"`)},lp=(e,t,n)=>{op(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))Zf.includes(r)||Z(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&Z(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},up=(e,t,n,r,i=!1)=>{op(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:ap(e,n,a),s=t[a];if(z(s)){ip(s)||Z(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}op(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:Qf(s,`states`)?`compound`:`atomic`;if(cp(e,o,s,l),l===`history`||l===`choice`){r||Z(e,o,`${l} states must be declared below an active parent state`),Qf(s,`annotations`)&&lp(e,o,s.annotations),l===`history`&&Qf(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&Z(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=Qf(s,`schema`);u&&!ip(s.schema)&&Z(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&Qf(s,`annotations`)&&Z(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&Qf(s,`annotations`)&&lp(e,o,s.annotations),l===`atomic`&&Qf(s,`type`)&&s.type!==`active`&&Z(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&Z(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&Qf(s,`type`)&&s.type!==`active`&&Z(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&Z(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&Qf(s,`output`)&&!z(s.output)&&Z(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?(sp(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&sp(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),up(e,s.states,o,!0)):l===`parallel`&&(Qf(s,`states`)||Z(e,`${o}.states`,`parallel states must declare child regions`),sp(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),up(e,s.states,o,!0))}},dp=e=>typeof e==`object`&&e?Object.freeze({...e}):e,fp=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(z(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=fp(i.states)),`annotations`in i&&(a.annotations=dp(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},pp=e=>fp(e),mp=(e,t=``)=>{if(z(e)||typeof e!=`object`||!e)return e;if(`~effect/Machine/State`in e&&e[`~effect/Machine/State`]===`~effect/Machine/State`&&`node`in e)return e.node;let n=e,r={...n};if(Qf(n,`fields`)&&(Qf(n,`schema`)&&Z(`Machine.state`,t,`declare fields or schema, not both`),op(`Machine.state`,t,n.fields,`state fields`),Qf(n.fields,`_tag`)&&Z(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=na(t,n.fields),delete r.fields),Qf(n,`states`)){op(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))ap(`Machine.state`,t,r),e[r]=mp(n.states[r],r);r.states=e}return t===``?(up(`Machine.state`,{"":r},``,!1,!0),pp({"":r})[``]):r},hp=`~effect/Machine`,gp=`~effect/Machine/ChildMachine`,_p={...Ne,...Jn,[hp]:hp,toJSON(){return{_id:`Machine`}}},vp=(e,t)=>{let n=Object.create(_p);return n.states=e.states,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents,n.emittedEvents=e.emittedEvents,n.parent=e.parent,n.input=e.input,n.id=e.id,n.initial=e.initial,n.initialDefinition=e.initialDefinition,n.stateNodes=e.stateNodes,n.handlers=t,vs(e,n),n},yp=e=>e.kind===`none`?wo:Co(e.kind,e.path,e.scope,e.updatePath),bp=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),xp=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],Sp=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!P(e,`target`)||typeof e.target!=`function`)throw Error(`Machine transition for state "${r}" on "${String(i)}" requires a target selector`);let a=e.target(t);if(!To(a))throw Error(`Machine transition for state "${r}" on "${String(i)}" must select exactly one target`);if(a.updatePath!==void 0){let e=n.byPath.get(a.updatePath);if(a.kind!==`state`&&a.kind!==`choice`||a.scope!==`local`&&a.scope!==`branch`||a.path===void 0||e===void 0||e.schema===void 0||e.type!==`compound`&&e.type!==`parallel`||!Js(r,e.path)||!Js(a.path,e.path))throw Error(`Machine updating owner "${a.updatePath}" must be a valued ancestor retained by source "${r}" and target "${a.path}"`)}return{...e,selection:a}},Cp=(e,t,n)=>{if(t.kind===`none`){if(e!==void 0)throw Error(`Machine targetless transition resolver must return undefined`);return}if(t.kind===`update`){if(!Do(e)||e.path!==t.path)throw Error(`Machine state update for "${t.path}" must return its selected update builder`);return}if(t.updatePath!==void 0){if(!ko(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(ko(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=ko(e)?e.target:e,i=typeof r==`object`&&r&&P(r,`path`)&&typeof r.path==`string`?r.path:void 0,a=t.path===void 0?void 0:n.byPath.get(t.path),o=(t.scope===`local`||t.scope===`branch`)&&(a?.type===`compound`||a?.type===`parallel`);if(i===void 0||i!==t.path&&!(o&&Js(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},wp=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:Io};delete a.target;let o=e.resolve(a,n);if(Lo(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return Cp(o,e.selection,r),o},Tp=e=>e.kind===`update`?void 0:e.path,Ep=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},Dp=(e,t,n)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch record`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" cannot use symbol keys`);let r=Object.keys(e);if(r.length===0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch`);return Object.freeze(r.map(r=>{if(r.length===0||Ep(r))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires non-index string branch keys`);let i=e[r];if(typeof i!=`object`||!i||!P(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!To(a))throw Error(`Machine transition branch "${r}" must select exactly one target`);if(o!==void 0&&(typeof o!=`string`||o.length===0))throw Error(`Machine transition branch "${r}" title must be a non-empty string`);return Object.freeze({key:r,title:o??r,selection:yp(a)})}))},Op=(e,t,n,r={},i)=>{let a=Lc(r);if(e.kind===`choice`&&e.updatePath!==void 0){let{update:n,...r}=a;if(Reflect.ownKeys(r).length>0)throw Error(`Machine pseudo-state construction accepts no data`);let i=t.byPath.get(e.path);return Oo(Ho(i.path,i.parent),Bc(t,e.updatePath,n))}if(e.kind===`none`||e.kind===`history`||e.kind===`choice`){if(Reflect.ownKeys(a).length>0)throw Error(`Machine pseudo-state construction accepts no data`);if(e.kind===`none`)return;let n=t.byPath.get(e.path);return e.kind===`history`?Ro(n.path,n.parent):Ho(n.path,n.parent)}if(e.kind===`update`)return Bc(t,e.path,a);if(e.path===``){if(Reflect.ownKeys(a).some(e=>e!==`input`))throw Error(`Machine initialize branches accept input only`);if(n.initialize===void 0)throw Error(`Machine root initialization is unavailable`);return n.initialize(a.input)}if(e.updatePath!==void 0){let{update:n,...r}=a;return Oo(zc(t,e.path,r,i),Bc(t,e.updatePath,n))}return zc(t,e.path,a,i)},kp=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>Ao(t,a,e.key,e.selection.kind===`none`?No():Op(e.selection,n,r,o,i))]))),Ap=(e,t,n)=>{if(t.kind===`none`){if(!Po(e))throw Error(`Machine targetless branch must return its selected targetless builder`)}else{if(e===void 0)throw Error(`Machine transition branch selected "${t.path}" without constructing its target`);Cp(e,t,n)}},jp=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),Mp=(e,t,n,r)=>{if(typeof e!=`object`||!e)throw Error(`Machine transition for "${n}" must be an object`);let i={...e},a=[`target`,`update`,`initialize`,`history`,`none`,`branches`,`data`,`decoded`,`resolve`,`guard`,`reenter`,`declinable`];for(let e of Reflect.ownKeys(i))if(typeof e!=`string`||!a.includes(e))throw Error(`Machine transition contains an unknown field`);for(let e of[`resolve`,`guard`])if(i[e]!==void 0&&typeof i[e]!=`function`)throw Error(`Machine transition ${e} must be a function`);let o=typeof i.guard==`function`?i.guard:void 0,s=typeof i.resolve==`function`?i.resolve:void 0;if(i.decoded!==void 0&&typeof i.decoded!=`boolean`)throw Error(`Machine decoded must be a boolean construction flag`);let c=Object.prototype.hasOwnProperty.call(i,`data`);if(i.decoded===!0&&!c)throw Error(`Machine decoded construction requires data`);if(c&&s!==void 0)throw Error(`Machine data and resolve are mutually exclusive`);let l=i.data,u=typeof l==`function`?l:()=>l,d=o!==void 0,f=d||i.declinable===!0;if(typeof i.branches==`string`){let e=t.branches.get(i.branches);if(e===void 0||s===void 0)throw Error(`Machine branching transition requires a registered group and resolver`);if([`target`,`update`,`initialize`,`history`,`none`,`data`,`decoded`].some(e=>i[e]!==void 0))throw Error(`Machine branching transition cannot redeclare its destination`);let a=Object.fromEntries(Object.entries(e).map(([e,i])=>[e,{title:i.title,target:Sp({target:()=>qc(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?Io():s(e,t)}}let p=qc(t,i);if(s!==void 0&&p.kind!==`none`)throw Error(`Machine advanced construction requires a declared branch group`);let m=i.initialize,h=m!==void 0;if(h&&(c||i.decoded!==void 0))throw Error(`Machine initialize accepts machine input instead of data`);if(h&&!t.input&&m!==!0)throw Error(`Machine initialize requires true when the machine declares no input`);let g=t.input?typeof m==`function`?m:()=>m:()=>void 0;return{target:()=>p,reenter:i.reenter,declinable:f,resolve:(e,a)=>{if(d&&!o(e))return Io();if(s!==void 0)return s(e,a);if(h)return Op(p,r,t,{input:g(e)});let l=u(e);return Op(p,r,t,p.updatePath===void 0?{...c?{data:l}:{},...i.decoded===void 0?{}:{decoded:i.decoded}}:p.kind===`choice`?{update:{data:l,decoded:i.decoded}}:{...l.target===void 0?{}:{data:l.target,decoded:i.decoded},update:{data:l.update,decoded:i.decoded}},n)}}},Np=(e,t,n,r,i)=>{let a=Mp(e,r,n,t);if(typeof a!=`object`||!a)throw Error(`Machine transition for state "${n}" on "${String(i)}" must be an object`);let o=a,s=o.reenter===!0,c=o.declinable===!0;if(P(o,`branches`)){let e=o;if(typeof e.branches!=`function`||typeof e.resolve!=`function`)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" requires branches and resolve`);let a=e.resolve,l=Dp(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:Io};delete s.target,s.select=kp(l,u,t,r,n);let d=a(s,o);if(Lo(d)){if(!c)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" returned decline without declaring declinable: true`);return{result:d,branchIndex:-1,branchKey:void 0}}if(!jo(d)||d.owner!==u)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" must select one declared branch`);let f=l[d.branchIndex];if(f===void 0||d.branchKey!==f.key)throw Error(`Machine branching transition returned invalid branch evidence`);return Ap(d.result,f.selection,t),{result:d.result,branchIndex:d.branchIndex,branchKey:d.branchKey}};return{reenter:s,declinable:c,targets:[...new Set(l.flatMap(e=>Tp(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:Tp(e.selection),selection:bp(e.selection),updates:xp(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=Sp(a,void 0,t,n,i),u=(e,r)=>({result:wp(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:Tp(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:Tp(l.selection),selection:bp(l.selection),updates:xp(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},Pp=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=Np(e[a],t,n,r,a);return i},Fp=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=Jc(r,e,n,e=>jp(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=Np(i[e],t,n,r,e));return al(i,n)});return sl(i,n),Array.isArray(e)?Object.freeze(i):i[0]},Ip=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!P(n,o))throw Error(`Machine received handler for unknown state "${s}"`);let c=a[o];if(typeof c!=`object`||!c)throw Error(`Machine expected state "${s}" handler to be an object`);let{states:l,...u}=c;typeof u.history==`object`&&u.history!==null&&(u.history=Object.freeze(Object.fromEntries(Object.entries(u.history).map(([e,t])=>[e,typeof t==`object`&&t?Object.freeze({...t}):t]))));let d=u.on;if(typeof d==`object`&&d&&(u.on=Pp(d,t,s,i)),u.always!==void 0&&(u.always=Np(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=Np(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=Np(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=Fp(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!P(u.choice,`transition`)||typeof u.choice.transition!=`function`||!P(u.choice,`targets`)||!Array.isArray(u.choice.targets)||u.choice.targets.length===0))throw Error(`Machine choice state "${s}" requires a transition`);if(e[s]=u,l!==void 0){let r=Wo(s,n[o]);if(r.states===void 0)throw Error(`Machine expected state "${s}" to declare child states`);if(typeof l!=`object`||!l)throw Error(`Machine expected state "${s}" child handlers to be an object`);Ip(e,t,r.states,s,i,l)}}},Lp=e=>e===``?Uc:e,Rp=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=Jo(e),r=new Map;for(let e of n)e.trigger.type===`choice`&&r.set(e.source,e);for(let e of n)for(let t of e.branches){let n=t.updates[0],i=t.selection.path;if(t.selection.kind!==`choice`||n===void 0||i===void 0)continue;let a=[i],o=new Set;for(;a.length>0;){let t=a.shift();if(!o.has(t)){o.add(t);for(let i of r.get(t)?.branches??[]){let{kind:r,path:o}=i.selection;if(o!==void 0&&r!==`none`&&r!==`update`){if(r===`choice`)a.push(o);else if(!Js(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${Lp(e.source)}" updates "${Lp(n)}" before choice "${t}", whose ${r} targets "${Lp(o)}" outside that owner`)}}}}}}},zp=(e,t)=>(n=>{let r=il(t.root,n),i=Object.assign(Object.create(_p),e);if(vs(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=Go(i.states),i.stateNodes.byPath.get(``).schema===void 0&&n.root!==void 0)throw Error(`Machine schema-less root cannot construct data`);let a=i.stateNodes.byPath.get(``).schema===void 0?()=>void 0:nl(n.root);i.initial=e=>({...Bo(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);Ip(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Is(i,i.input,e))},{"":r.handlers});let s=vp(i,o);return Rp(s),s}),Bp=e=>{let t=mp(e),n=Vp();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},Vp=()=>({path:(e=>e),get:((e,t)=>es(e,t).pipe(Ct(e=>e.value))),getWithParents:((e,t)=>{let n={};return es(e,t,n).pipe(Ct(e=>({value:e.value,parents:n})))}),getSnapshot:es,matches:((e,t)=>A(es(e,t)))}),Hp=e=>{if(Object.hasOwn(e,`initial`)||Object.hasOwn(e,`initialConfiguration`))throw Error(`Machine initial edges and root data belong in handle`);let t=Object.freeze({"":e.root.node}),n=Object.create(Jn);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??Cs(`internal`,[]),n.emittedEvents=e.emittedEvents??Cs(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=zp(n,Gc(e.root,e)),_s(n),n},Up=e=>{for(let[t,n]of Object.entries(e))if(Object.hasOwn(n,`_tag`))throw Error(`Machine event "${t}" fields cannot declare _tag`);return Object.keys(e).length===0?[]:[jn(e)]},Wp=e=>Cs(`public`,Up(e)),Gp=(e,t)=>Kp(e,t,e=>t.input===void 0?Kf(t):Kf(t,e)),Kp=(e,t,n)=>({[gp]:gp,id:e,machine:t,[Zc]:n}),qp=Jf,Jp=Yf,Yp=(e,t)=>{try{let n=pu(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},Xp=(e,t)=>{try{let n=Tn(Nf(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!du(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=Tn(fu(e,r,uu));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},Zp={spawn:()=>me(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>N(new oo),stop:()=>U},Qp=(e,t)=>{if(e.snapshot.status!==`active`)return h();try{let n=e.machine,r=mc(n,e.snapshot.state);for(let e of ac(n,r)){let i=wc(n,e);for(let a of cl(i?.invoke)){if(!(`child`in a)||a.child.id!==t.id||a.child.machine!==t.machine)continue;let i=t.machine,o;`input`in a&&(o=typeof a.input==`function`?a.input({...Gs(r)??El(n,r),children:Zp,state:r.values.get(e),containingState:ic(n,r,e),ancestors:rc(n,r,e),event:uu}):a.input);let s=Yp(i,i.input===void 0?[]:[o]);return s===void 0?void 0:O(s)}}return h()}catch{return}},$p=class extends Fn(`ChildNotActiveError`){},em=new WeakMap,tm=new WeakMap,nm=e=>typeof e==`object`&&!!e&&tm.has(e),rm=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return T(e);let t=kt(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=S(t,n);A(r)&&r.value===e&&Ui(t,n)});return r=>{let i=S(t,r);if(A(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return Ft(t,r,o),n.register(a,{key:r,entry:o}),a}},im=(e,t)=>bi(Gi(t,e=>e.stop).pipe($n(t=>L(()=>e.setSelf(s(t)))),v(()=>rn))),am=(e,t)=>im(e,e.result(t).pipe(v(e=>e.start))),om=(e,t,n)=>im(e,Jp(t,n)),sm=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[Mt](t):t(e),cm=(e,t)=>{let n;return r=>{let i=e(r);return n!==void 0&&n.inputs.length===i.length&&n.inputs.every((e,t)=>Object.is(e,i[t]))||(n={inputs:i,value:t(...i)}),n.value}},lm=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},um=e=>e.snapshot,dm=Ar(e=>e.registry).pipe(le),fm=e=>H(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,U):D(t,fm(e))}),pm=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},mm=(e,t,n)=>Et(n=>{let r=_n(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:dt(Ct(n.self(),qn),()=>He(!0))},(r,i)=>{let a=r.get(e),o=r.get(dm),s=pm(t,o);Ie(a)||s.draining?(r.setSelf(He(!0)),s.pending.push(ua(o,e).pipe(v(e=>n(e,i)),Ke,k(e=>{let t=xe(e);r.setSelf(s.pending.length===0?t:qn(t))}))),s.draining||(s.draining=!0,Ur(fm(s)))):di(a)?r.setSelf(_n(a,()=>void 0)):Ei(n(a.value,i),{onExit:e=>r.setSelf(xe(e))})}).pipe(qe),hm=e=>Ar(t=>{let n=t(e);return Ie(n)?He(n.waiting):di(n)?$t(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?$t(n.value.cause,{previous:t.self(),waiting:n.waiting}):s(n.value.state,{waiting:n.waiting})}).pipe(ht(sn),je(cm(t=>[sm(e,t)],e=>_n(e,e=>e.state)))),gm=e=>Ar(t=>{let n=t(e);if(Ie(n))return He(n.waiting);if(di(n))return $t(n.cause,{previous:t.self(),waiting:n.waiting});if(De(n.value)){let e=t.self();return A(e)&&di(e.value)?e.value:s(h(),{waiting:n.waiting})}return n.value.value.status===`error`?$t(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):s(O(n.value.value.state),{waiting:n.waiting})}).pipe(ht(sn),je(cm(t=>[sm(e,t)],e=>_n(e,Ct(e=>e.state))))),_m=(e,t)=>Ar(n=>{let r=n(e);if(Ie(r))return He(r.waiting);if(di(r))return $t(r.cause,{previous:n.self(),waiting:r.waiting});if(De(r.value))return s(h());let i=r.value.value,a=gr(i.child(t)),o=Ei(Yi.pipe(D(i.childChanges(t).pipe(Pr(e=>L(()=>n.setSelf(s(e))))))));return n.addFinalizer(o),s(a)}).pipe(qe),vm=(e,t)=>ld(e)?e[cd](()=>t(gr(e.snapshot))):Ei(e.changes.pipe(Pr(e=>L(()=>t(e))))),ym=(e,t,n)=>{let r=Ar(t=>{let n=t(e);if(Ie(n))return He(n.waiting);if(di(n))return $t(n.cause,{previous:t.self(),waiting:n.waiting});if(De(n.value))return s(h());let r=n.value.value;return t.addFinalizer(vm(r,e=>t.setSelf(s(O(e))))),s(O(gr(r.snapshot)))}).pipe(je(cm(()=>[],()=>{let e=n();return e===void 0?He(!0):s(Ct(e,um),{waiting:!0})}))),i=new WeakMap,a=e=>A(e)?B(e.value):N(new $p({id:t.id})),o=mm(e,i,(e,t)=>v(a(e),e=>e.send(t))),c=mm(e,i,(e,t)=>v(a(e),e=>e.stop)),l=bm(e,n);return{ref:e,snapshot:r,result:gm(r),send:o,stop:c,child:l}},bm=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=T(n=>{let r=Gp(n,a);return ym(_m(e,r),r,lm(()=>{let e=t();return e===void 0||De(e)?e:Qp(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},xm=(e,t,n)=>{let r=qe(e),i=Ar(e=>{let t=e(r);if(Ie(t))return He(t.waiting);if(di(t))return $t(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(vm(n,t=>e.setSelf(s(t,{waiting:t.status===`active`}))));let i=gr(n.snapshot);return s(i,{waiting:i.status===`active`})}).pipe(je(cm(()=>[],()=>{let e=n();return e===void 0?He(!0):s(um(e),{waiting:!0})}))),a=new WeakMap,o=mm(r,a,(e,t)=>e.send(t)),c=mm(r,a,(e,t)=>e.stop),l=bm(lt(r,O),()=>{let e=n();return e===void 0?void 0:O(e)}),u={ref:r,snapshot:i,result:hm(i),send:o,stop:c,child:l};return tm.set(u,t),u},Sm=(e,t)=>es(e,t).pipe(Ct(e=>e.value)),Cm=(e,t)=>es(e,t),wm=(e,t)=>lt(e,t).pipe(ht(sn),je(cm(t=>[sm(e,t)],e=>_n(e,t)))),Tm=new WeakMap,Em=(e,t,n,r)=>{let i=Tm.get(e);i===void 0&&(i=new Map,Tm.set(e,i));let a=i.get(t);a===void 0&&(a=new Map,i.set(t,a));let o=a.get(n);if(o!==void 0)return o;let s=r();return a.set(n,s),s},Dm=(e,t)=>Em(e,`select`,t,()=>wm(e.result,e=>Sm(e,t))),Om=(e,t)=>Em(e,`selectSnapshot`,t,()=>wm(e.result,e=>Cm(e,t))),km=(e,t)=>Em(e,`selectChild`,t,()=>wm(e.result,Ye(e=>Sm(e,t)))),Am=(e,t)=>Em(e,`selectSnapshotChild`,t,()=>wm(e.result,Ye(e=>Cm(e,t)))),jm=(e,t)=>Em(e,`matches`,t,()=>wm(e.result,e=>A(es(e,t)))),Mm=(e,t)=>Em(e,`matchesChild`,t,()=>wm(e.result,xr(e=>A(es(e,t))))),Nm=(e,t,n)=>{let r=e.atom(()=>qp(t,...n)),i=xm(e.atom(e=>am(e,r)),t,lm(()=>Yp(t,n)));return em.set(i,r),i},Pm=(e,t,n)=>xm(e.atom(e=>om(e,t,n)),t,lm(()=>Xp(t,n))),Fm=(e,t,n)=>{let r={owner:e,source:t},i=it(t,e=>e(r.source),{initialValueTarget:t}).pipe(ht((e,t)=>r.source.equals(e,t)),je(e=>sm(r.source,e)));return n!==void 0&&(i=i.pipe(he(n))),i},Im=(e,t)=>{let n=rm(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=rm(r=>{let a=n(r);return Fm(a,i(a.bridge),t.label?.(r,e))})}return r},Lm=e=>{let t=((t,...n)=>Nm(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>Pm(e,t,n)),family:((t,n)=>Im(n=>Nm(e,t,[n]),n))}},Rm=nm;pn(2,Dm);var zm=pn(2,Om);pn(2,km);var Bm=pn(2,Am);pn(2,jm),pn(2,Mm);var Vm=Lm,Hm=e=>{let t=Wm(W.useMemo(()=>Um(e.machine,e.path),[e.machine,e.path]));if(di(t))throw yi(t.cause);return Ie(t)?e.pending??null:A(t.value)?e.children(t.value.value):e.inactive??null},Um=(e,t)=>Rm(e)?zm(e,t):Bm(e,t),Wm=e=>Gm(W.useContext(La),e),Gm=(e,t)=>{let n=W.useMemo(()=>{let n,r,i=e=>dn(e)?(n=e,e):Ie(e)&&n!==void 0?n:e;return{subscribe:n=>e.subscribe(t,n),snapshot:()=>i(e.get(t)),serverSnapshot:()=>r??=i(Rt(t,e))}},[e,t]);return W.useSyncExternalStore(n.subscribe,n.snapshot,n.serverSnapshot)},Km=Hm;function qm(e){return _i(e.defaultTagName??`div`,e,e)}var Q=sr(),$=Oi();function Jm(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,orientation:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`horizontal`:i,o;t[4]===n?o=t[5]:(o=R(`shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch`,n),t[4]=n,t[5]=o);let s;return t[6]!==a||t[7]!==r||t[8]!==o?(s=(0,$.jsx)(jr,{"data-slot":`separator`,orientation:a,className:o,...r}),t[6]=a,t[7]=r,t[8]=o,t[9]=s):s=t[9],s}function Ym(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`group/item-group flex w-full flex-col gap-4 has-data-[size=sm]:gap-2.5 has-data-[size=xs]:gap-2`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{role:`list`,"data-slot":`item-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Xm(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`my-2`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(Jm,{"data-slot":`item-separator`,orientation:`horizontal`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Zm=ai(`group/item flex w-full flex-wrap items-center rounded-md border text-xs/relaxed transition-colors duration-100 outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [a]:transition-colors [a]:hover:bg-muted`,{variants:{variant:{default:`border-transparent`,outline:`border-border`,muted:`border-transparent bg-muted/50`},size:{default:`gap-2.5 px-3 py-2.5`,sm:`gap-2.5 px-3 py-2.5`,xs:`gap-2.5 px-2.5 py-2 in-data-[slot=dropdown-menu-content]:p-0`}},defaultVariants:{variant:`default`,size:`default`}});function Qm(e){let t=(0,Q.c)(15),n,r,i,a,o,s;if(t[0]!==e){let{className:c,variant:l,size:u,render:d,...f}=e;n=d,s=l===void 0?`default`:l,r=u===void 0?`default`:u,o=qm,i=`div`,a=zn({className:R(Zm({variant:s,size:r,className:c}))},f),t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s}else n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6];let c;t[7]!==r||t[8]!==s?(c={slot:`item`,variant:s,size:r},t[7]=r,t[8]=s,t[9]=c):c=t[9];let l;return t[10]!==n||t[11]!==i||t[12]!==a||t[13]!==c?(l={defaultTagName:i,props:a,render:n,state:c},t[10]=n,t[11]=i,t[12]=a,t[13]=c,t[14]=l):l=t[14],o(l)}var $m=ai(`flex shrink-0 items-center justify-center gap-2 group-has-data-[slot=item-description]/item:translate-y-0.5 group-has-data-[slot=item-description]/item:self-start [&_svg]:pointer-events-none`,{variants:{variant:{default:`bg-transparent`,icon:`[&_svg:not([class*='size-'])]:size-4`,image:`size-8 overflow-hidden rounded-sm group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover`}},defaultVariants:{variant:`default`}});function eh(e){let t=(0,Q.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,variant:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`default`:i,o;t[4]!==n||t[5]!==a?(o=R($m({variant:a,className:n})),t[4]=n,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==o||t[9]!==a?(s=(0,$.jsx)(`div`,{"data-slot":`item-media`,"data-variant":a,className:o,...r}),t[7]=r,t[8]=o,t[9]=a,t[10]=s):s=t[10],s}function th(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`flex flex-1 flex-col gap-1 group-data-[size=xs]/item:gap-0.5 [&+[data-slot=item-content]]:flex-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`item-content`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function nh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`line-clamp-1 flex w-fit items-center gap-2 text-xs/relaxed leading-snug font-medium underline-offset-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`item-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function rh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`line-clamp-2 text-left text-xs/relaxed font-normal text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`p`,{"data-slot":`item-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ih(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`flex items-center gap-2`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`item-actions`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ah(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`animate-pulse rounded-md bg-muted`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`skeleton`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function oh(e){let t=(0,Q.c)(5),n=e.label,r;t[0]===e.children?r=t[1]:(r=oe(e.children,sh),t[0]=e.children,t[1]=r);let i;return t[2]!==e.label||t[3]!==r?(i=(0,$.jsx)(Ym,{"aria-label":n,className:`gap-0 has-data-[size=sm]:gap-0 has-data-[size=xs]:gap-0`,children:r}),t[2]=e.label,t[3]=r,t[4]=i):i=t[4],i}function sh(e,t){return(0,$.jsxs)(W.Fragment,{children:[e,(0,$.jsx)(Xm,{className:`my-0`})]},e.key??t)}function ch(e){let t=(0,Q.c)(11),n=e.label,r=e.label,i;if(t[0]!==e.media||t[1]!==e.rows){let n;t[3]===e.media?n=t[4]:(n=t=>(0,$.jsxs)(Qm,{role:`listitem`,size:`sm`,"aria-hidden":!0,children:[e.media===!0&&(0,$.jsx)(eh,{children:(0,$.jsx)(ah,{className:`size-8`})}),(0,$.jsxs)(th,{children:[(0,$.jsx)(ah,{className:`h-4 w-1/3`}),(0,$.jsx)(ah,{className:`h-3 w-1/2`})]})]},t),t[3]=e.media,t[4]=n),i=oe(ot(1,e.rows),n),t[0]=e.media,t[1]=e.rows,t[2]=i}else i=t[2];let a;t[5]!==e.label||t[6]!==i?(a=(0,$.jsx)(oh,{label:r,children:i}),t[5]=e.label,t[6]=i,t[7]=a):a=t[7];let o;return t[8]!==e.label||t[9]!==a?(o=(0,$.jsx)(`div`,{"aria-busy":`true`,"aria-label":n,role:`status`,children:a}),t[8]=e.label,t[9]=a,t[10]=o):o=t[10],o}function lh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`flex items-center gap-2 text-xs/relaxed leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`label`,{"data-slot":`label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var uh=ai(`group/field flex w-full gap-2 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:`flex-col *:w-full [&>.sr-only]:w-auto`,horizontal:`flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`,responsive:`flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`}},defaultVariants:{orientation:`vertical`}});function dh(e){let t=(0,Q.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,orientation:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`vertical`:i,o;t[4]!==n||t[5]!==a?(o=R(uh({orientation:a}),n),t[4]=n,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==a||t[8]!==r||t[9]!==o?(s=(0,$.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":a,className:o,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function fh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border has-[>[data-slot=field]]:not-has-[:disabled,[data-disabled]]:hover:bg-input/40 has-[>[data-slot=field]]:has-[:focus-visible]:border-ring has-[>[data-slot=field]]:has-[:focus-visible]:ring-2 has-[>[data-slot=field]]:has-[:focus-visible]:ring-ring/30 *:data-[slot=field]:p-2 dark:has-data-checked:bg-primary/10`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(lh,{"data-slot":`field-label`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ph(e){let t=(0,Q.c)(15),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:r,children:n,errors:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o;bb0:{if(n){o=n;break bb0}if(!i?.length){o=null;break bb0}let e;t[5]===i?e=t[6]:(e=[...new Map(i.map(hh)).values()],t[5]=i,t[6]=e);let r=e;if(r?.length==1){o=r[0]?.message;break bb0}let a;t[7]===r?a=t[8]:(a=(0,$.jsx)(`ul`,{className:`ml-4 flex list-disc flex-col gap-1`,children:r.map(mh)}),t[7]=r,t[8]=a),o=a}let s=o;if(!s)return null;let c;t[9]===r?c=t[10]:(c=R(`text-xs/relaxed font-normal text-destructive`,r),t[9]=r,t[10]=c);let l;return t[11]!==s||t[12]!==a||t[13]!==c?(l=(0,$.jsx)(`div`,{role:`alert`,"data-slot":`field-error`,className:c,...a,children:s}),t[11]=s,t[12]=a,t[13]=c,t[14]=l):l=t[14],l}function mh(e,t){return e?.message&&(0,$.jsx)(`li`,{children:e.message},t)}function hh(e){return[e?.message,e]}function gh(e){let t=(0,Q.c)(5),n=e.className,r;t[0]===e.result?r=t[1]:(r=de(Ct(Ut(e.result),_h)),t[0]=e.result,t[1]=r);let i;return t[2]!==e.className||t[3]!==r?(i=(0,$.jsx)(ph,{className:n,children:r}),t[2]=e.className,t[3]=r,t[4]=i):i=t[4],i}function _h(e){return e.message}var vh=ai(`inline-block size-1.5 shrink-0 rounded-full`,{defaultVariants:{status:`live`},variants:{status:{error:`bg-destructive`,live:`bg-primary`,off:`border-muted-foreground border`,quiet:`bg-muted-foreground/50`,warning:`bg-warning`}}});function yh(e){let t=(0,Q.c)(6),n;t[0]!==e.className||t[1]!==e.status||t[2]!==e.waiting?(n=R(vh({status:e.status}),e.waiting===!0&&`motion-safe:animate-pulse`,e.className),t[0]=e.className,t[1]=e.status,t[2]=e.waiting,t[3]=n):n=t[3];let r;return t[4]===n?r=t[5]:(r=(0,$.jsx)(`span`,{"data-slot":`status-dot`,"aria-hidden":`true`,className:n}),t[4]=n,t[5]=r),r}var bh=W.createContext(void 0);function xh(e){let t=W.useContext(bh);if(!e&&t===void 0)throw Error(Ci(27));return t}var Sh=W.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=xh(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`),d={open:c,transitionStatus:s.useState(`transitionStatus`)};return _i(`div`,e,{state:d,ref:[s.context.backdropRef,t],stateAttributesMapping:m,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),Ch=W.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=xh(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=$r({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,ut(Ee,e.nativeEvent))}return _i(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})}),wh=W.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xh(),c=ue(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),_i(`p`,e,{ref:t,props:[{id:c},o]})}),Th=W.createContext(void 0);function Eh(){let e=W.useContext(Th);if(e===void 0)throw Error(Ci(26));return e}var Dh=`--nested-dialogs`,Oh=`data-nested-dialog-open`,kh={...aa,...Le,nestedDialogOpen(e){return e?{[Oh]:``}:null}},Ah=W.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,l=xh(),u=l.useState(`descriptionElementId`),d=l.useState(`disablePointerDismissal`),f=l.useState(`floatingRootContext`),p=l.useState(`popupProps`),m=l.useState(`modal`),h=l.useState(`mounted`),g=l.useState(`nested`),_=l.useState(`nestedOpenDialogCount`),v=l.useState(`open`),y=l.useState(`openMethod`),b=l.useState(`titleElementId`),x=l.useState(`transitionStatus`),S=l.useState(`role`),C=f.useState(`floatingId`);Eh(),oi({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}});let w=o===void 0?cr(l.context.popupRef):o,T=_>0,ee=l.useStateSetter(`popupElement`),te=_i(`div`,e,{state:{open:v,nested:g,transitionStatus:x,nestedDialogOpen:T},props:[p,{id:C,"aria-labelledby":b,"aria-describedby":u,role:S,...ei,hidden:!h,onKeyDown(e){at.has(e.key)&&e.stopPropagation()},style:{[Dh]:_}},s],ref:[t,l.context.popupRef,ee],stateAttributesMapping:kh});return(0,$.jsx)(c,{context:f,openInteractionType:y,disabled:!h,closeOnFocusOut:!d,initialFocus:w,returnFocus:a,modal:m!==!1,restoreFocus:`popup`,children:te})}),jh=W.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=xh(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,$.jsx)(Th.Provider,{value:n,children:(0,$.jsxs)(br,{ref:t,...r,children:[a&&o===!0&&(0,$.jsx)(ae,{ref:i.context.internalBackdropRef,inert:ee(!s)}),e.children]})}):null});function Mh({store:e,parentContext:t,isDrawer:n}){let r=e.useState(`open`),i=e.useState(`mounted`),a=e.useState(`disablePointerDismissal`),o=e.useState(`modal`),s=e.useState(`popupElement`),c=e.useState(`floatingRootContext`),[l,u]=W.useState(0),[d,f]=W.useState(0),p=l===0,m=Er(c,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?`intentional`:{mouse:o===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}},outsidePress(t){if(!e.context.outsidePressEnabledRef.current||`button`in t&&t.button!==0)return!1;if(`touches`in t){if(t.type===`touchend`){if(t.changedTouches.length!==1||t.touches.length!==0)return!1}else if(t.touches.length!==1)return!1}let n=$e(t);if(p&&!a){if(o){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||Je(n,s)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return Nt(r&&o===!0,s),e.useContextCallback(`onNestedDialogOpen`,(t,n)=>{(e.select(`open`)||e.select(`mounted`))&&(u(t),f(n))}),Fr(()=>{!r&&!i&&(u(0),f(0))},[r,i]),Fr(()=>(t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(l+1,d+ +!!n),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,l,d,t]),$i(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var Nh={...Bn,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role},Ph=class extends Dt{constructor(e,t,n){let r=new Zn,i=Fh(e,r,t,n);super(i,Ih(r),Nh)}setOpen=(e,t)=>{t.preventUnmountOnClose=()=>{this.set(`preventUnmountingOnClose`,!0)},!e&&t.trigger==null&&this.state.activeTriggerId!=null&&(t.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(e,t),!t.isCanceled&&(this.state.floatingRootContext.dispatchOpenChange(e,t),this.update(nr(this.state,e,t.trigger)))}};function Fh(e,t,n,r=!1){return{...ji(t,n,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:`dialog`,...e}}function Ih(e){return{popupRef:W.createRef(),backdropRef:W.createRef(),internalBackdropRef:W.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function Lh(e,t){let{children:n,open:r,defaultOpen:i=!1,onOpenChange:a,onOpenChangeComplete:o,disablePointerDismissal:s=!1,modal:c=!0,actionsRef:l,handle:u,triggerId:d,defaultTriggerId:f=null}=t,p=e===`drawer`,m=e===`alert-dialog`,h=m?!0:c,g=m||s,_=m?`alertdialog`:`dialog`,v=xh(!0),y={modal:h,disablePointerDismissal:g,nested:v!=null,role:_},b=On((e,t)=>new Ph({open:i,openProp:r,activeTriggerId:f,triggerIdProp:d,...y},e,t),!0);b.useControlledProp(`openProp`,r),b.useControlledProp(`triggerIdProp`,d),b.useSyncedValues(y),b.useContextCallback(`onOpenChange`,a),b.useContextCallback(`onOpenChangeComplete`,o);let x=b.useState(`open`),S=b.useState(`mounted`),C=b.useState(`payload`);qi(b,x),vn(b);let{forceUnmount:w}=Ii(x,b);W.useImperativeHandle(l,()=>({unmount:w,close:()=>b.setOpen(!1,ut(Ue))}),[w,b]);let T=x||S||u!=null;return(0,$.jsxs)(bh.Provider,{value:b,children:[u&&(0,$.jsx)(Ir,{handle:u,store:b}),T&&(0,$.jsx)(Mh,{store:b,parentContext:v?.context,isDrawer:p}),typeof n==`function`?n({payload:C}):n]})}var Rh=Vi(function(e){return Lh(`dialog`,e)}),zh=W.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xh(),c=ue(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),_i(`h2`,e,{ref:t,props:[{id:c},o]})});function Bh(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(Rh,{"data-slot":`dialog`,...n}),t[2]=n,t[3]=r),r}function Vh(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(jh,{"data-slot":`dialog-portal`,...n}),t[2]=n,t[3]=r),r}function Hh(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(Ch,{"data-slot":`dialog-close`,...n}),t[2]=n,t[3]=r),r}function Uh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`fixed inset-0 isolate z-50 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(Sh,{"data-slot":`dialog-overlay`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Wh(e){let t=(0,Q.c)(15),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:r,children:n,showCloseButton:a,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=a===void 0||a,s;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Uh,{}),t[5]=s):s=t[5];let c;t[6]===r?c=t[7]:(c=R(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-xs/relaxed text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,r),t[6]=r,t[7]=c);let l;t[8]===o?l=t[9]:(l=o&&(0,$.jsxs)(Ch,{"data-slot":`dialog-close`,render:(0,$.jsx)(qr,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,$.jsx)(Ma,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[8]=o,t[9]=l);let u;return t[10]!==n||t[11]!==i||t[12]!==c||t[13]!==l?(u=(0,$.jsxs)(Vh,{children:[s,(0,$.jsxs)(Ah,{"data-slot":`dialog-content`,className:c,...i,children:[n,l]})]}),t[10]=n,t[11]=i,t[12]=c,t[13]=l,t[14]=u):u=t[14],u}function Gh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`text-sm font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(zh,{"data-slot":`dialog-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Kh(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`text-xs/relaxed text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(wh,{"data-slot":`dialog-description`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var qh=`data-valid`,Jh=`data-invalid`,Yh={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},Xh={disabled:!1,valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Zh={valid(e){return e===null?null:e?{[qh]:``}:{[Jh]:``}}},Qh={invalid:void 0,name:void 0,validityData:{state:Yh,errors:[],error:``,value:``,initialValue:null},setValidityData:I,disabled:void 0,setTouched:I,setDirty:I,setFilled:I,setFocused:I,focusOwnerRef:{current:void 0},validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Xh,registerFieldControl:I,validation:{getValidationProps:(e,t=yr)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:I,getInputControl:()=>null,commit:async()=>{},change:I}},$h=W.createContext(Qh);function eg(e=!0){let t=W.useContext($h);if(t.setValidityData===I&&!e)throw Error(Ci(28));return t}var tg=W.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:I,validationMode:`onSubmit`,submitCountRef:{current:0}});function ng(){return W.useContext(tg)}var rg=W.createContext({controlId:void 0,registerControlId:I,resetControlId:I,labelId:void 0,setLabelId:I,messageIds:[],setMessageIds:I,getDescriptionProps:e=>e});function ig(){return W.useContext(rg)}function ag(e,t,n){let{setFocused:r,focusOwnerRef:i}=eg(),a=Fi(t=>{(t?!e:i.current===a)&&(i.current=t&&a,n?.(t),r(t))});return Fr(()=>{let e=t.current;return e?.getRootNode()?.activeElement===e&&a(!0),()=>a(!1)},[e,t,a]),a}function og(e,t,n,r,i=!0,a){let{registerFieldControl:o}=eg(),s=Wn(()=>Symbol());Fr(()=>{let c=s.current;i?o(c,{controlRef:e,getValue:r,id:t,name:a,value:n}):o(c,void 0)},[e,i,r,t,a,o,s,n]),Fr(()=>{let e=s.current;return()=>{o(e,void 0)}},[o,s])}function sg(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=ig(),o=ue(),s=Wn(()=>Symbol()),c=W.useRef(!1),l=W.useRef(!1),u=Fi(()=>{c.current&&i!==I&&(c.current=!1,i(s.current,void 0))});return Fr(()=>{if(!n||i===I){u();return}let e;if(t!==void 0)l.current=!0,e=t;else if(l.current)e=o;else{a();return}e===void 0?u():(c.current=!0,i(s.current,e))},[t,n,i,a,o,s,u]),Fr(()=>u,[u]),(n?r:void 0)??t??o}var cg=W.forwardRef(function(e,t){let{render:n,className:r,id:i,name:a,value:o,disabled:s=!1,onValueChange:c,defaultValue:l,autoFocus:u=!1,style:d,...f}=e,{state:p,name:m,disabled:h,setTouched:g,setDirty:_,validityData:v,setFilled:y,validationMode:x,validation:S}=eg(),{clearErrors:C,elementRef:w,submitCountRef:T}=ng(),ee=h||s,te=m??a,E={...p,disabled:ee},{labelId:ne}=ig(),re=sg({id:i}),ie=o!==void 0,ae=o==null?void 0:String(o),oe=Fi(()=>S.inputRef.current?.value);og(S.inputRef,re,ae,oe,!ee,a),Fr(()=>{let e=ae??S.inputRef.current?.value;e!==void 0&&y(e!==``)},[ae,l,S.inputRef,y]),b(ae,()=>{ae!==void 0&&(C(te),_(ae!==(v.initialValue??``)),S.change(ae))});let se=W.useRef(null),ce=ag(ee,se),D=ge();return _i(`input`,e,{ref:[t,se],state:E,props:[{id:re,disabled:ee,name:te,ref:S.inputRef,"aria-labelledby":ne,autoFocus:u,...ie?{value:o}:{defaultValue:l},onChange(e){let t=e.currentTarget.value,n=ut(St,e.nativeEvent);c?.(t,n),!ie&&(_(t!==(v.initialValue??``)),y(t!==``),!e.nativeEvent.defaultPrevented&&!n.isCanceled&&(C(te),S.change(t)))},onFocus(){ce(!0)},onBlur(e){if(g(!0),ce(!1),x===`onBlur`){let t=e.currentTarget.value;S.commit(t),ie&&queueMicrotask(()=>{let e=S.inputRef.current?.value;e!==void 0&&e!==t&&e!==(v.initialValue??``)&&S.commit(e)})}},onKeyDown(e){if(e.currentTarget.tagName===`INPUT`&&e.key===`Enter`){g(!0);let t=e.currentTarget.value,n=e.currentTarget.form;if(n&&n===w.current&&!e.defaultPrevented){let t=e.currentTarget,n=T.current;D.start(0,()=>{T.current===n&&S.commit(t.value)})}else S.commit(t)}}},f,e=>S.getValidationProps(ee,e)],stateAttributesMapping:Zh})}),lg=W.forwardRef(function(e,t){return(0,$.jsx)(cg,{ref:t,...e})});function ug(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,type:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=R(`h-7 w-full min-w-0 rounded-md border border-input bg-input/20 px-2 py-0.5 text-sm transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-xs/relaxed file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-xs/relaxed dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[4]=n,t[5]=a);let o;return t[6]!==r||t[7]!==a||t[8]!==i?(o=(0,$.jsx)(lg,{type:i,"data-slot":`input`,className:a,...r}),t[6]=r,t[7]=a,t[8]=i,t[9]=o):o=t[9],o}function dg(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`group/input-group relative flex h-7 w-full min-w-0 items-center rounded-md border border-input bg-input/20 transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-data-[align=block-end]:rounded-md has-data-[align=block-start]:rounded-md has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-2 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/30 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-2 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[textarea]:rounded-md has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`input-group`,role:`group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var fg=ai(`flex h-auto cursor-text items-center justify-center gap-1 py-2 text-xs/relaxed font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 **:data-[slot=kbd]:rounded-[calc(var(--radius-sm)-2px)] **:data-[slot=kbd]:bg-muted-foreground/10 **:data-[slot=kbd]:px-1 **:data-[slot=kbd]:text-[0.625rem] [&>svg:not([class*='size-'])]:size-3.5`,{variants:{align:{"inline-start":`order-first pl-2 has-[>button]:ml-[-0.275rem] has-[>kbd]:ml-[-0.275rem]`,"inline-end":`order-last pr-2 has-[>button]:mr-[-0.275rem] has-[>kbd]:mr-[-0.275rem]`,"block-start":`order-first w-full justify-start px-2 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2`,"block-end":`order-last w-full justify-start px-2 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2`}},defaultVariants:{align:`inline-start`}});function pg(e){let t=(0,Q.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,align:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`inline-start`:i,o;t[4]!==a||t[5]!==n?(o=R(fg({align:a}),n),t[4]=a,t[5]=n,t[6]=o):o=t[6];let s;return t[7]!==a||t[8]!==r||t[9]!==o?(s=(0,$.jsx)(`div`,{role:`group`,"data-slot":`input-group-addon`,"data-align":a,className:o,onClick:mg,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function mg(e){e.target.closest(`button`)||e.currentTarget.parentElement?.querySelector(`input`)?.focus()}var hg=ai(`flex items-center gap-2 rounded-md text-xs/relaxed shadow-none`,{variants:{size:{xs:`h-5 gap-1 rounded-[calc(var(--radius-sm)-2px)] px-1 [&>svg:not([class*='size-'])]:size-3`,sm:`gap-1`,"icon-xs":`size-6 p-0 has-[>svg]:p-0`,"icon-sm":`size-7 p-0 has-[>svg]:p-0`}},defaultVariants:{size:`xs`}});function gg(e){let t=(0,Q.c)(15),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:n,type:i,variant:a,size:o,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s=i===void 0?`button`:i,c=a===void 0?`ghost`:a,l=o===void 0?`xs`:o,u;t[6]!==n||t[7]!==l?(u=R(hg({size:l}),n),t[6]=n,t[7]=l,t[8]=u):u=t[8];let d;return t[9]!==r||t[10]!==l||t[11]!==u||t[12]!==s||t[13]!==c?(d=(0,$.jsx)(qr,{type:s,"data-size":l,variant:c,className:u,...r}),t[9]=r,t[10]=l,t[11]=u,t[12]=s,t[13]=c,t[14]=d):d=t[14],d}function _g(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=R(`flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(ug,{"data-slot":`input-group-control`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}En(Zr(_r(`AUTH_URL`)),De);function vg(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function yg(e){return It(on)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}Vn()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var bg=class e extends xa()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:on}){static layerClient=t=>Sa(e,e=>be(function*(){return yield*e.next({...e.request,headers:nn(e.request.headers,`authorization`,`Bearer ${yield*t}`)})}))},xg=Bp,Sg=Hp,Cg=Wp,wg=F.check(ct(/^[a-z0-9][a-z0-9_-]{0,23}$/u)),Tg=V.check(ne(2048),Cr(e=>{if(!URL.canParse(e))return!1;let t=new URL(e);return t.protocol===`https:`&&t.username===``&&t.password===``&&t.hash===``},{expected:`a public HTTPS URL without credentials or a fragment`})),Eg=Ri({url:Tg}),Dg=Ri({id:wg}),Og=Ri({hidden:Ln,id:wg,tool:V}),kg=Ri({authorization_endpoint:V,authorization_response_iss_parameter_supported:j(Ln),client_id_metadata_document_supported:j(Ln),issuer:V,registration_endpoint:j(V),token_endpoint:V});Ri({client_id:V});var Ag=Ri({access_token:V,expires_in:j(Nr.check(ce(0))),refresh_token:j(V),token_type:F.check(ct(/^Bearer$/iu))}),jg=Ri({client:jn({Document:{},Registered:{clientId:V}}),metadata:kg,scope:F}),Mg=jn({Authorized:{expiresAt:Nr,token:Ag},Connected:{},Disconnected:{}}),Ng=Ri({src:F,theme:j(er([`light`,`dark`]))}),Pg=Ri({error:j(F),generation:V,hidden:xi(F),icons:j(xi(Ng)),id:wg,instructions:j(F),link:Mg,mode:er([`oauth`,`public`]),name:V,oauth:j(jg),tools:xi(F),url:Tg});dr(F,Pg);var Fg=Ri({error:j(F),hidden:xi(F),icons:xi(Ng),id:wg,name:V,status:er([`Connected`,`Not connected`,`Expired`]),tools:xi(F),url:Tg});jn({Discovered:{icons:xi(Ng),instructions:j(F),tools:xi(F)},Failed:{error:F}}),Ri({code:j(V),error:j(F),iss:j(V),state:V});var Ig=class extends ya(Nn(`gateway.servers`,{error:on,stream:!0,success:xi(Fg)}),Nn(`gateway.calls`,{error:on,stream:!0,success:wg}),Nn(`gateway.add`,{error:on,payload:Eg,success:Fg}),Nn(`gateway.disconnect`,{error:on,payload:Dg}),Nn(`gateway.remove`,{error:on,payload:Dg}),Nn(`gateway.hide`,{error:on,payload:Og})).middleware(bg){},Lg=`${window.location.origin}/mcp`,Rg=class extends ha()(`@deslop/gateway/lib/utils/RpcClient`,{group:Ig,protocol:Me(`@deslop/gateway`)}){};function zg(e){return`/oauth/connect?${new URLSearchParams({id:e})}`}function Bg(e){return Rn(e,e=>r(e(se(`1 second`)),E(e=>e.input._tag===`RpcClientError`)))}var Vg=le(Rg.runtime.atom(Bg(Un(k(Rg,e=>e(`gateway.servers`,void 0)))))),Hg=le(Rg.runtime.atom(Bg(tr(Un(k(Rg,e=>e(`gateway.calls`,void 0))))))),Ug=T(e=>ie(t=>{let n=dt(t.self(),()=>-1);return xt(t(Hg),{onFailure:()=>n,onInitial:()=>n,onSuccess:t=>ea(t.value[0]===e,{onFalse:()=>n,onTrue:()=>t.value[1]})})})),Wg=T(e=>Rg.runtime.fn(()=>v(Rg,t=>t(`gateway.disconnect`,{id:e})))),Gg=T(e=>Rg.runtime.fn(t=>v(Rg,n=>n(`gateway.hide`,{...t,id:e})),{concurrent:!0})),Kg=T(e=>Rg.runtime.fn(()=>v(Rg,t=>t(`gateway.remove`,{id:e})))),qg=Vm(Rg.runtime).make(Sg({effects:{add:qt(function*(e){yield*r(At(Tg)(e),un(e=>on.make({cause:e,message:`Enter a public HTTPS MCP URL without credentials or a fragment, outside the gateway itself.`})));let t=yield*(yield*Rg)(`gateway.add`,{url:e});t.status!==`Connected`&&location.assign(zg(t.id))})},events:Cg({Cancel:{},Open:{},Submit:{},Typed:{url:F}}),root:xg({states:{Adding:{fields:{url:F}},Closed:{},Editing:{fields:{error:F,url:F}}}})}).handle({initial:{target:`Closed`},states:{Adding:{invoke:{input:e=>e.state.url,onDone:{target:`Closed`},onFailure:{data:e=>({error:e.error.message,url:e.state.url}),target:`Editing`},src:`add`}},Closed:{on:{Open:{data:{error:``,url:``},target:`Editing`}}},Editing:{on:{Cancel:{target:`Closed`},Submit:{data:e=>({url:e.state.url}),target:`Adding`},Typed:{data:e=>({error:``,url:e.event.url}),update:`Editing`}}}}})),Jg=Ki(()=>ni({catch:e=>on.make({cause:e,message:`Cannot copy the gateway endpoint. Select and copy its URL instead.`}),try:()=>navigator.clipboard.writeText(Lg)}));function Yg(e){let t=(0,Q.c)(13),n;t[0]===e.server.id?n=t[1]:(n=Ug(e.server.id),t[0]=e.server.id,t[1]=n);let i=qa(n),a;t[2]===i?a=t[3]:(a=ea(i>=0,{onFalse:e_,onTrue:$g}),t[2]=i,t[3]=a);let o;t[4]===e.server.status?o=t[5]:(o=r(Wr(e.server.status),hi(`Connected`,Qg),hi(`Expired`,Zg),Di(Xg)),t[4]=e.server.status,t[5]=o);let s;t[6]!==i||t[7]!==a||t[8]!==o?(s=(0,$.jsx)(yh,{className:a,status:o},i),t[6]=i,t[7]=a,t[8]=o,t[9]=s):s=t[9];let c;return t[10]!==e.server.status||t[11]!==s?(c=(0,$.jsxs)(rh,{className:`flex items-center gap-1.5`,children:[s,e.server.status]}),t[10]=e.server.status,t[11]=s,t[12]=c):c=t[12],c}function Xg(){return`off`}function Zg(){return`error`}function Qg(){return`live`}function $g(){return`port-blink`}function e_(){}function t_(e){let t=(0,Q.c)(30),n;t[0]===e.server.id?n=t[1]:(n=Wg(e.server.id),t[0]=e.server.id,t[1]=n);let[,r]=Qa(n),i;t[2]===e.server.id?i=t[3]:(i=Gg(e.server.id),t[2]=e.server.id,t[3]=i);let[,a]=Qa(i),o=`Manage ${e.server.name}`,s;t[4]!==e.busy||t[5]!==o?(s=(0,$.jsx)(qr,{variant:`ghost`,size:`icon-sm`,"aria-label":o,disabled:e.busy}),t[4]=e.busy,t[5]=o,t[6]=s):s=t[6];let c;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(wa,{}),t[7]=c):c=t[7];let l;t[8]===s?l=t[9]:(l=(0,$.jsx)(Pn,{render:s,children:c}),t[8]=s,t[9]=l);let u;t[10]!==e.server.id||t[11]!==e.server.status?(u=e.server.status===`Connected`&&(0,$.jsx)(mr,{onClick:()=>location.assign(zg(e.server.id)),children:`Reconnect`}),t[10]=e.server.id,t[11]=e.server.status,t[12]=u):u=t[12];let d;t[13]!==r||t[14]!==e.server.status?(d=e.server.status===`Connected`&&(0,$.jsx)(mr,{onClick:()=>r(),children:`Disconnect`}),t[13]=r,t[14]=e.server.status,t[15]=d):d=t[15];let f;t[16]!==a||t[17]!==e.server.hidden||t[18]!==e.server.tools?(f=Hi(e.server.tools)&&(0,$.jsxs)(Cn,{children:[(0,$.jsx)(vi,{children:`Tools`}),(0,$.jsx)(Jr,{children:oe(e.server.tools,t=>(0,$.jsx)(Vr,{checked:!kn(e.server.hidden,t),onCheckedChange:e=>a({hidden:!e,tool:t}),children:(0,$.jsx)(`span`,{className:`font-mono`,children:t})},t))})]}),t[16]=a,t[17]=e.server.hidden,t[18]=e.server.tools,t[19]=f):f=t[19];let p;t[20]===e.onRemove?p=t[21]:(p=(0,$.jsx)(mr,{variant:`destructive`,onClick:e.onRemove,children:`Remove`}),t[20]=e.onRemove,t[21]=p);let m;t[22]!==u||t[23]!==d||t[24]!==f||t[25]!==p?(m=(0,$.jsxs)(fi,{align:`end`,className:`w-auto min-w-36`,children:[u,d,f,p]}),t[22]=u,t[23]=d,t[24]=f,t[25]=p,t[26]=m):m=t[26];let h;return t[27]!==m||t[28]!==l?(h=(0,$.jsxs)(wi,{children:[l,m]}),t[27]=m,t[28]=l,t[29]=h):h=t[29],h}function n_(e){let t=(0,Q.c)(29),n;t[0]===e.server.id?n=t[1]:(n=Kg(e.server.id),t[0]=e.server.id,t[1]=n);let[r,i]=Qa(n),a=e.open,o=e.onOpenChange,s;t[2]===e.server.name?s=t[3]:(s=(0,$.jsxs)(Gh,{children:[`Remove `,e.server.name,`?`]}),t[2]=e.server.name,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Kh,{children:`Its tools will no longer be available through the gateway. This does not revoke the provider’s grant.`}),t[4]=c):c=t[4];let l;t[5]===r?l=t[6]:(l=(0,$.jsx)(gh,{result:r}),t[5]=r,t[6]=l);let u;t[7]===r?u=t[8]:(u=an(r),t[7]=r,t[8]=u);let d;t[9]===u?d=t[10]:(d=(0,$.jsx)(Hh,{render:(0,$.jsx)(qr,{variant:`ghost`,disabled:u}),children:`Cancel`}),t[9]=u,t[10]=d);let f;t[11]===r?f=t[12]:(f=an(r),t[11]=r,t[12]=f);let p;t[13]===i?p=t[14]:(p=()=>i(),t[13]=i,t[14]=p);let m;t[15]!==f||t[16]!==p?(m=(0,$.jsx)(qr,{variant:`destructive`,disabled:f,onClick:p,children:`Remove server`}),t[15]=f,t[16]=p,t[17]=m):m=t[17];let h;t[18]!==m||t[19]!==d?(h=(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[d,m]}),t[18]=m,t[19]=d,t[20]=h):h=t[20];let g;t[21]!==h||t[22]!==s||t[23]!==l?(g=(0,$.jsxs)(Wh,{children:[s,c,l,h]}),t[21]=h,t[22]=s,t[23]=l,t[24]=g):g=t[24];let _;return t[25]!==e.onOpenChange||t[26]!==e.open||t[27]!==g?(_=(0,$.jsx)(Bh,{open:a,onOpenChange:o,children:g}),t[25]=e.onOpenChange,t[26]=e.open,t[27]=g,t[28]=_):_=t[28],_}function r_(e){let t=(0,Q.c)(5),[n,r]=(0,W.useState)(0),i;if(t[0]!==n||t[1]!==e.sources){let a;t[3]===n?a=t[4]:(a=e=>(0,$.jsx)(`span`,{className:`bg-icon-tile flex size-8 items-center justify-center overflow-hidden rounded-md`,children:(0,$.jsx)(`img`,{src:e,alt:``,className:`size-6`,onError:()=>r(n+1)})}),t[3]=n,t[4]=a),i=oa(x(e.sources,n),{onNone:i_,onSome:a}),t[0]=n,t[1]=e.sources,t[2]=i}else i=t[2];return i}function i_(){return(0,$.jsx)(Aa,{className:`text-muted-foreground size-6`})}function a_(e){let t=(0,Q.c)(9),n,r,i;if(t[0]!==e.server.icons||t[1]!==e.server.url){let a=new URL(e.server.url).hostname;r=Ji([...oe(Dr(e.server.icons,Yt(zt,s_)),o_),`https://${a}/favicon.ico`,`https://${st(/^(?:api|app|mcp)\./u,``)(a)}/favicon.ico`]),n=r_,i=Pt(r,` `),t[0]=e.server.icons,t[1]=e.server.url,t[2]=n,t[3]=r,t[4]=i}else n=t[2],r=t[3],i=t[4];let a;return t[5]!==n||t[6]!==r||t[7]!==i?(a=(0,$.jsx)(n,{sources:r},i),t[5]=n,t[6]=r,t[7]=i,t[8]=a):a=t[8],a}function o_(e){return e.src}function s_(e){return e.theme===`dark`}function c_(e){let t=(0,Q.c)(74),n;t[0]===e.server.id?n=t[1]:(n=Wg(e.server.id),t[0]=e.server.id,t[1]=n);let[i]=Qa(n),a;t[2]===e.server.id?a=t[3]:(a=Kg(e.server.id),t[2]=e.server.id,t[3]=a);let[o]=Qa(a),s;t[4]===e.server.id?s=t[5]:(s=Gg(e.server.id),t[4]=e.server.id,t[5]=s);let[c]=Qa(s),[l,u]=(0,W.useState)(!1),d;t[6]!==i||t[7]!==c||t[8]!==o?(d=an(i)||an(o)||an(c),t[6]=i,t[7]=c,t[8]=o,t[9]=d):d=t[9];let f=d,p;if(t[10]!==e.server.hidden||t[11]!==e.server.tools){let n;t[13]===e.server.hidden?n=t[14]:(n=t=>!kn(e.server.hidden,t),t[13]=e.server.hidden,t[14]=n),p=Ot(e.server.tools,n),t[10]=e.server.hidden,t[11]=e.server.tools,t[12]=p}else p=t[12];let m=p,h,g,_,v,y,b;if(t[15]!==f||t[16]!==i||t[17]!==c||t[18]!==e.server||t[19]!==m){let n;t[26]===i?n=t[27]:(n=()=>Ct(Ut(i),h_),t[26]=i,t[27]=n);let a;t[28]===c?a=t[29]:(a=()=>Ct(Ut(c),m_),t[28]=c,t[29]=a);let o=r(et(e.server.error),Wt(n),Wt(a));h=Qm,g=`listitem`,t[30]===e.server?_=t[31]:(_=(0,$.jsx)(eh,{children:(0,$.jsx)(a_,{server:e.server})}),t[30]=e.server,t[31]=_);let s;t[32]===e.server.name?s=t[33]:(s=(0,$.jsx)(nh,{children:e.server.name}),t[32]=e.server.name,t[33]=s);let l;t[34]===e.server.url?l=t[35]:(l=new URL(e.server.url),t[34]=e.server.url,t[35]=l);let d;t[36]===l.hostname?d=t[37]:(d=(0,$.jsx)(rh,{className:`font-mono`,children:l.hostname}),t[36]=l.hostname,t[37]=d),t[38]!==s||t[39]!==d?(v=(0,$.jsxs)(th,{children:[s,d]}),t[38]=s,t[39]=d,t[40]=v):v=t[40];let p;t[41]===e.server?p=t[42]:(p=(0,$.jsx)(Yg,{server:e.server}),t[41]=e.server,t[42]=p);let x;if(t[43]!==f||t[44]!==e.server.id||t[45]!==e.server.status||t[46]!==e.server.tools||t[47]!==m){let n;t[49]!==e.server.tools||t[50]!==m?(n=()=>te(e.server.tools,{onEmpty:p_,onNonEmpty:e=>(0,$.jsxs)(rh,{className:`w-12 text-right font-mono`,children:[m.length,`/`,e.length]})}),t[49]=e.server.tools,t[50]=m,t[51]=n):n=t[51];let i;t[52]!==f||t[53]!==e.server.id?(i=t=>(0,$.jsx)(qr,{size:`sm`,variant:`outline`,disabled:f,onClick:()=>location.assign(zg(e.server.id)),children:ea(t===`Expired`,{onFalse:f_,onTrue:d_})}),t[52]=f,t[53]=e.server.id,t[54]=i):i=t[54],x=r(Wr(e.server.status),hi(`Connected`,n),Di(i)),t[43]=f,t[44]=e.server.id,t[45]=e.server.status,t[46]=e.server.tools,t[47]=m,t[48]=x}else x=t[48];let S;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>u(!0),t[55]=S):S=t[55];let C;t[56]!==f||t[57]!==e.server?(C=(0,$.jsx)(t_,{busy:f,onRemove:S,server:e.server}),t[56]=f,t[57]=e.server,t[58]=C):C=t[58],t[59]!==p||t[60]!==x||t[61]!==C?(y=(0,$.jsxs)(ih,{children:[p,x,C]}),t[59]=p,t[60]=x,t[61]=C,t[62]=y):y=t[62],b=oa(o,{onNone:u_,onSome:l_}),t[15]=f,t[16]=i,t[17]=c,t[18]=e.server,t[19]=m,t[20]=h,t[21]=g,t[22]=_,t[23]=v,t[24]=y,t[25]=b}else h=t[20],g=t[21],_=t[22],v=t[23],y=t[24],b=t[25];let x;t[63]!==l||t[64]!==e.server?(x=(0,$.jsx)(n_,{open:l,onOpenChange:u,server:e.server}),t[63]=l,t[64]=e.server,t[65]=x):x=t[65];let S;return t[66]!==h||t[67]!==x||t[68]!==g||t[69]!==_||t[70]!==v||t[71]!==y||t[72]!==b?(S=(0,$.jsxs)(h,{role:g,children:[_,v,y,b,x]}),t[66]=h,t[67]=x,t[68]=g,t[69]=_,t[70]=v,t[71]=y,t[72]=b,t[73]=S):S=t[73],S}function l_(e){return(0,$.jsx)(ph,{className:`basis-full break-words`,children:e})}function u_(){return null}function d_(){return`Reconnect`}function f_(){return`Connect`}function p_(){return null}function m_(e){return e.message}function h_(e){return e.message}function g_(e){let t=(0,Q.c)(33),n=Za(qg.send),r;t[0]===n?r=t[1]:(r=e=>{e.preventDefault(),n({_tag:`Submit`})},t[0]=n,t[1]=r);let i=e.error!==``,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(fh,{htmlFor:`mcp-url`,children:`MCP URL`}),t[2]=a):a=t[2];let o;t[3]===n?o=t[4]:(o=e=>n({_tag:`Typed`,url:e.target.value}),t[3]=n,t[4]=o);let s=e.error!==``,c;t[5]!==e.adding||t[6]!==e.url||t[7]!==o||t[8]!==s?(c=(0,$.jsx)(ug,{id:`mcp-url`,type:`url`,autoComplete:`url`,placeholder:`https://example.com/mcp`,required:!0,autoFocus:!0,value:e.url,disabled:e.adding,onChange:o,"aria-invalid":s,"aria-describedby":`mcp-add-error`}),t[5]=e.adding,t[6]=e.url,t[7]=o,t[8]=s,t[9]=c):c=t[9];let l;t[10]===e.error?l=t[11]:(l=(0,$.jsx)(ph,{id:`mcp-add-error`,children:e.error}),t[10]=e.error,t[11]=l);let u;t[12]!==i||t[13]!==c||t[14]!==l?(u=(0,$.jsxs)(dh,{"data-invalid":i,children:[a,c,l]}),t[12]=i,t[13]=c,t[14]=l,t[15]=u):u=t[15];let d;t[16]===n?d=t[17]:(d=()=>n({_tag:`Cancel`}),t[16]=n,t[17]=d);let f;t[18]!==e.adding||t[19]!==d?(f=(0,$.jsx)(qr,{variant:`ghost`,type:`button`,disabled:e.adding,onClick:d,children:`Cancel`}),t[18]=e.adding,t[19]=d,t[20]=f):f=t[20];let p=e.adding,m;t[21]===e.adding?m=t[22]:(m=ea(e.adding,{onFalse:v_,onTrue:__}),t[21]=e.adding,t[22]=m);let h;t[23]!==e.adding||t[24]!==m?(h=(0,$.jsx)(qr,{type:`submit`,disabled:p,children:m}),t[23]=e.adding,t[24]=m,t[25]=h):h=t[25];let g;t[26]!==h||t[27]!==f?(g=(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[f,h]}),t[26]=h,t[27]=f,t[28]=g):g=t[28];let _;return t[29]!==r||t[30]!==g||t[31]!==u?(_=(0,$.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:r,children:[u,g]}),t[29]=r,t[30]=g,t[31]=u,t[32]=_):_=t[32],_}function __(){return`Adding…`}function v_(){return`Add server`}function y_(){let e=(0,Q.c)(16),[t,n]=Qa(Jg),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(_g,{readOnly:!0,value:Lg,"aria-label":`Gateway endpoint`}),e[0]=r):r=e[0];let i;e[1]===n?i=e[2]:(i=()=>n(),e[1]=n,e[2]=i);let a;e[3]===t?a=e[4]:(a=an(t),e[3]=t,e[4]=a);let o;e[5]===t?o=e[6]:(o=ea(dn(t),{onFalse:x_,onTrue:b_}),e[5]=t,e[6]=o);let s;e[7]!==i||e[8]!==a||e[9]!==o?(s=(0,$.jsxs)(dg,{children:[r,(0,$.jsx)(pg,{align:`inline-end`,children:(0,$.jsx)(gg,{size:`icon-xs`,onClick:i,disabled:a,"aria-label":`Copy gateway endpoint`,children:o})})]}),e[7]=i,e[8]=a,e[9]=o,e[10]=s):s=e[10];let c;e[11]===t?c=e[12]:(c=(0,$.jsx)(gh,{result:t}),e[11]=t,e[12]=c);let l;return e[13]!==s||e[14]!==c?(l=(0,$.jsxs)(dh,{className:`max-w-sm`,children:[s,c]}),e[13]=s,e[14]=c,e[15]=l):l=e[15],l}function b_(){return(0,$.jsx)(Br,{})}function x_(){return(0,$.jsx)(Ea,{})}function S_(e){let t=(0,Q.c)(10),n=Za(qg.send),r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(y_,{}),t[0]=r):r=t[0];let i;t[1]===n?i=t[2]:(i=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[r,(0,$.jsx)(Km,{machine:qg,path:`Closed`,children:()=>(0,$.jsxs)(qr,{onClick:()=>n({_tag:`Open`}),children:[(0,$.jsx)(Oa,{}),`Add server`]})})]}),t[1]=n,t[2]=i);let a,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Km,{machine:qg,path:`Editing`,children:D_}),o=(0,$.jsx)(Km,{machine:qg,path:`Adding`,children:E_}),t[3]=a,t[4]=o):(a=t[3],o=t[4]);let s;t[5]===e.servers?s=t[6]:(s=te(e.servers,{onEmpty:T_,onNonEmpty:C_}),t[5]=e.servers,t[6]=s);let c;return t[7]!==i||t[8]!==s?(c=(0,$.jsxs)($.Fragment,{children:[i,a,o,s]}),t[7]=i,t[8]=s,t[9]=c):c=t[9],c}function C_(e){return(0,$.jsx)(oh,{label:`MCP servers`,children:oe(e,w_)})}function w_(e){return(0,$.jsx)(c_,{server:e},e.id)}function T_(){return(0,$.jsx)(gt,{children:(0,$.jsx)(Xn,{children:(0,$.jsx)(Ai,{children:`No servers yet`})})})}function E_(e){return(0,$.jsx)(g_,{url:e.value.url,error:``,adding:!0})}function D_(e){return(0,$.jsx)(g_,{url:e.value.url,error:e.value.error,adding:!1})}function O_(){let e=(0,Q.c)(5),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={includeFailure:!0},e[0]=t):t=e[0];let n=no(Vg,t);if(dn(n)){let t;return e[1]===n.value?t=e[2]:(t=(0,$.jsx)(S_,{servers:n.value}),e[1]=n.value,e[2]=t),t}let r;return e[3]===n.cause?r=e[4]:(r=oa(Ti(n.cause),{onNone:()=>(0,$.jsx)(en,{error:yi(n.cause),reset:M_}),onSome:k_}),e[3]=n.cause,e[4]=r),r}function k_(e){return e._tag===`AuthError`?e.error===`access_denied`?(0,$.jsx)(gt,{children:(0,$.jsxs)(Xn,{children:[(0,$.jsx)(Ai,{children:`Admins only`}),(0,$.jsx)(n,{children:e.message})]})}):yg(e)?(0,$.jsx)(fn,{href:vg(location.href)}):(0,$.jsx)(en,{error:e,reset:A_}):(0,$.jsx)(en,{error:e,reset:j_})}function A_(){return location.reload()}function j_(){return location.reload()}function M_(){return location.reload()}function N_(){let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:`Servers`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`main`,{className:`pb-safe flex min-h-0 flex-1 justify-center overflow-y-auto px-4 pt-8 md:pt-16`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-3xl flex-col gap-5 self-start`,children:[t,(0,$.jsx)(W.Suspense,{fallback:(0,$.jsx)(ch,{label:`MCP servers`,media:!0,rows:4}),children:(0,$.jsx)(O_,{})})]})}),e[1]=n):n=e[1],n}export{N_ as component};
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" shape-rendering="crispEdges"><rect width="64" height="64" fill="#fafafa"/><path fill="#0a0a0a" d="M15 7h2v1h-2zM13 8h2v1h-2zM17 8h1v1h-1zM12 9h1v1h-1zM18 9h1v2h-1zM11 10h1v2h-1zM19 11h2v1h-2zM9 12h2v1h-2zM21 12h2v1h-2zM8 13h1v1h-1zM23 13h2v1h-2zM25 14h2v1h-2zM7 14h1v2h-1zM27 15h2v1h-2zM8 16h1v1h-1zM29 16h2v1h-2zM31 17h2v1h-2zM9 17h1v2h-1zM33 18h2v1h-2zM10 19h1v1h-1zM35 19h2v1h-2zM11 20h2v1h-2zM37 20h2v1h-2zM13 21h2v1h-2zM39 21h2v1h-2zM14 22h1v1h-1zM41 22h2v1h-2zM43 23h2v1h-2zM13 23h1v2h-1zM45 24h2v1h-2zM14 25h1v1h-1zM47 25h2v1h-2zM15 26h2v1h-2zM49 26h2v1h-2zM53 26h2v1h-2zM51 27h2v1h-2zM55 27h1v1h-1zM26 31h1v1h-1zM56 28h1v4h-1zM26 32h3v1h-3zM55 32h1v1h-1zM29 33h2v1h-2zM53 33h2v1h-2zM31 34h2v1h-2zM51 34h2v1h-2zM33 35h2v1h-2zM49 35h2v1h-2zM49 36h1v1h-1zM17 27h1v12h-1zM26 33h1v6h-1zM50 37h1v2h-1zM15 39h2v1h-2zM27 39h2v1h-2zM49 39h1v1h-1zM14 40h1v1h-1zM29 40h1v1h-1zM44 40h1v1h-1zM47 40h2v1h-2zM44 41h3v1h-3zM13 41h1v2h-1zM30 41h1v2h-1zM14 43h1v1h-1zM29 43h1v1h-1zM15 44h2v1h-2zM27 44h2v1h-2zM17 45h2v1h-2zM25 45h2v1h-2zM19 46h2v1h-2zM23 46h2v1h-2zM21 47h2v1h-2zM35 36h1v12h-1zM44 42h1v6h-1zM33 48h2v1h-2zM45 48h2v1h-2zM32 49h1v1h-1zM47 49h1v1h-1zM31 50h1v2h-1zM48 50h1v2h-1zM32 52h1v1h-1zM47 52h1v1h-1zM33 53h2v1h-2zM45 53h2v1h-2zM35 54h2v1h-2zM43 54h2v1h-2zM37 55h2v1h-2zM41 55h2v1h-2zM39 56h2v1h-2z"/><path fill="#8b7ec8" d="M10 17h1v1h-1zM10 18h3v1h-3zM11 19h4v1h-4zM13 20h4v1h-4zM15 21h4v1h-4zM17 22h4v1h-4zM14 23h1v1h-1zM18 23h5v1h-5zM14 24h3v1h-3zM18 24h7v1h-7zM15 25h7v1h-7zM23 25h4v1h-4zM17 26h5v1h-5zM25 26h4v1h-4zM18 27h5v1h-5zM27 27h4v1h-4zM18 28h7v1h-7zM28 28h5v1h-5zM23 29h4v1h-4zM28 29h7v1h-7zM25 30h7v1h-7zM33 30h4v1h-4zM27 31h5v1h-5zM35 31h4v1h-4zM29 32h4v1h-4zM36 32h5v1h-5zM31 33h4v1h-4zM36 33h7v1h-7zM33 34h7v1h-7zM41 34h4v1h-4zM35 35h5v1h-5zM43 35h3v1h-3zM36 36h5v1h-5zM45 36h1v1h-1zM36 37h7v1h-7zM41 38h4v1h-4zM43 39h3v1h-3zM18 29h4v12h-4zM45 40h1v1h-1zM19 41h3v1h-3zM21 42h1v1h-1zM36 38h4v12h-4zM37 50h3v1h-3zM39 51h1v1h-1z"/><path fill="#282726" d="M12 10h1v1h-1zM12 11h2v1h-2zM13 12h1v1h-1zM8 14h1v1h-1zM8 15h3v1h-3zM9 16h4v1h-4zM11 17h4v1h-4zM13 18h4v1h-4zM15 19h4v1h-4zM17 20h4v1h-4zM19 21h4v1h-4zM21 22h4v1h-4zM23 23h4v1h-4zM25 24h4v1h-4zM27 25h4v1h-4zM29 26h4v1h-4zM31 27h4v1h-4zM33 28h4v1h-4zM35 29h4v1h-4zM50 29h1v1h-1zM37 30h4v1h-4zM50 30h2v1h-2zM39 31h4v1h-4zM51 31h1v1h-1zM41 32h4v1h-4zM43 33h4v1h-4zM45 34h3v1h-3zM47 35h1v1h-1z"/><path fill="#403e3c" d="M15 8h2v1h-2zM13 9h3v1h-3zM17 11h2v1h-2zM11 12h2v1h-2zM15 12h6v1h-6zM9 13h14v1h-14zM10 14h15v1h-15zM12 15h15v1h-15zM14 16h15v1h-15zM16 17h15v1h-15zM18 18h15v1h-15zM20 19h15v1h-15zM22 20h15v1h-15zM24 21h15v1h-15zM26 22h15v1h-15zM28 23h15v1h-15zM30 24h15v1h-15zM32 25h15v1h-15zM34 26h15v1h-15zM36 27h15v1h-15zM53 27h2v1h-2zM38 28h16v1h-16zM40 29h10v1h-10zM42 30h8v1h-8zM44 31h7v1h-7zM46 32h4v1h-4z"/><path fill="#838280" d="M16 9h1v1h-1zM13 10h2v1h-2zM9 14h1v1h-1zM11 15h1v1h-1zM13 16h1v1h-1zM15 17h1v1h-1zM17 18h1v1h-1zM19 19h1v1h-1zM21 20h1v1h-1zM23 21h1v1h-1zM25 22h1v1h-1zM27 23h1v1h-1zM29 24h1v1h-1zM31 25h1v1h-1zM33 26h1v1h-1zM35 27h1v1h-1zM37 28h1v1h-1zM54 28h1v1h-1zM39 29h1v1h-1zM51 29h2v1h-2zM41 30h1v1h-1zM43 31h1v1h-1zM45 32h1v1h-1zM50 32h1v1h-1zM47 33h2v1h-2z"/><path fill="#5e409d" d="M22 25h1v2h-1zM22 29h1v1h-1zM22 30h3v1h-3zM32 30h1v2h-1zM40 34h1v2h-1zM46 35h1v2h-1zM49 37h1v1h-1zM40 38h1v1h-1zM47 38h3v1h-3zM40 39h3v1h-3zM46 39h3v1h-3zM22 31h4v10h-4zM46 40h1v1h-1zM22 41h3v1h-3zM22 42h1v1h-1zM40 40h4v10h-4zM40 50h3v1h-3zM40 51h1v1h-1z"/><path fill="#cecdc3" d="M17 39h1v1h-1zM26 39h1v1h-1zM15 40h3v1h-3zM26 40h3v1h-3zM16 41h3v1h-3zM25 41h3v1h-3zM18 42h3v1h-3zM23 42h3v1h-3zM20 43h4v1h-4zM35 48h1v1h-1zM44 48h1v1h-1zM33 49h3v1h-3zM44 49h3v1h-3zM34 50h3v1h-3zM43 50h3v1h-3zM36 51h3v1h-3zM41 51h3v1h-3zM38 52h4v1h-4z"/><path fill="#dfded8" d="M15 41h1v1h-1zM28 41h1v1h-1zM17 42h1v1h-1zM26 42h1v1h-1zM19 43h1v1h-1zM24 43h1v1h-1zM21 44h2v1h-2zM33 50h1v1h-1zM46 50h1v1h-1zM35 51h1v1h-1zM44 51h1v1h-1zM37 52h1v1h-1zM42 52h1v1h-1zM39 53h2v1h-2z"/><path fill="#e6e4d9" d="M15 45h2v1h-2zM27 45h2v1h-2zM17 46h2v1h-2zM25 46h2v1h-2zM19 47h2v1h-2zM23 47h2v1h-2zM21 48h2v1h-2zM33 54h2v1h-2zM45 54h2v1h-2zM35 55h2v1h-2zM43 55h2v1h-2zM37 56h2v1h-2zM41 56h2v1h-2zM39 57h2v1h-2z"/><path fill="#b7b5ac" d="M14 41h1v1h-1zM14 42h3v1h-3zM15 43h4v1h-4zM17 44h4v1h-4zM19 45h3v1h-3zM21 46h1v1h-1zM32 50h1v1h-1zM32 51h3v1h-3zM33 52h4v1h-4zM35 53h4v1h-4zM37 54h3v1h-3zM39 55h1v1h-1z"/><path fill="#878580" d="M29 41h1v1h-1zM27 42h3v1h-3zM25 43h4v1h-4zM23 44h4v1h-4zM22 45h3v1h-3zM22 46h1v1h-1zM47 50h1v1h-1zM45 51h3v1h-3zM43 52h4v1h-4zM41 53h4v1h-4zM40 54h3v1h-3zM40 55h1v1h-1z"/><path fill="#1c1b1a" d="M17 9h1v1h-1zM15 10h3v1h-3zM14 11h3v1h-3zM14 12h1v1h-1zM55 28h1v1h-1zM53 29h3v1h-3zM52 30h4v2h-4zM51 32h4v1h-4zM49 33h4v1h-4zM48 34h3v1h-3zM48 35h1v1h-1z"/><path fill="#a699d0" d="M15 22h2v1h-2zM16 23h2v1h-2zM23 26h2v1h-2zM24 27h3v1h-3zM26 28h2v1h-2zM33 31h2v1h-2zM34 32h2v1h-2zM41 35h2v1h-2zM42 36h3v1h-3zM47 36h2v1h-2zM44 37h4v1h-4z"/><path fill="#c5bde0" d="M15 23h1v1h-1zM17 24h1v1h-1zM23 27h1v1h-1zM25 28h1v1h-1zM27 29h1v1h-1zM33 32h1v1h-1zM35 33h1v1h-1zM41 36h1v1h-1zM43 37h1v1h-1zM48 37h1v1h-1zM45 38h2v1h-2z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" shape-rendering="crispEdges"><path fill="#0a0a0a" d="M15 7h2v1h-2zM13 8h2v1h-2zM17 8h1v1h-1zM12 9h1v1h-1zM18 9h1v2h-1zM11 10h1v2h-1zM19 11h2v1h-2zM9 12h2v1h-2zM21 12h2v1h-2zM8 13h1v1h-1zM23 13h2v1h-2zM25 14h2v1h-2zM7 14h1v2h-1zM27 15h2v1h-2zM8 16h1v1h-1zM29 16h2v1h-2zM31 17h2v1h-2zM9 17h1v2h-1zM33 18h2v1h-2zM10 19h1v1h-1zM35 19h2v1h-2zM11 20h2v1h-2zM37 20h2v1h-2zM13 21h2v1h-2zM39 21h2v1h-2zM14 22h1v1h-1zM41 22h2v1h-2zM43 23h2v1h-2zM13 23h1v2h-1zM45 24h2v1h-2zM14 25h1v1h-1zM47 25h2v1h-2zM15 26h2v1h-2zM49 26h2v1h-2zM53 26h2v1h-2zM51 27h2v1h-2zM55 27h1v1h-1zM26 31h1v1h-1zM56 28h1v4h-1zM26 32h3v1h-3zM55 32h1v1h-1zM29 33h2v1h-2zM53 33h2v1h-2zM31 34h2v1h-2zM51 34h2v1h-2zM33 35h2v1h-2zM49 35h2v1h-2zM49 36h1v1h-1zM17 27h1v12h-1zM26 33h1v6h-1zM50 37h1v2h-1zM15 39h2v1h-2zM27 39h2v1h-2zM49 39h1v1h-1zM14 40h1v1h-1zM29 40h1v1h-1zM44 40h1v1h-1zM47 40h2v1h-2zM44 41h3v1h-3zM13 41h1v2h-1zM30 41h1v2h-1zM14 43h1v1h-1zM29 43h1v1h-1zM15 44h2v1h-2zM27 44h2v1h-2zM17 45h2v1h-2zM25 45h2v1h-2zM19 46h2v1h-2zM23 46h2v1h-2zM21 47h2v1h-2zM35 36h1v12h-1zM44 42h1v6h-1zM33 48h2v1h-2zM45 48h2v1h-2zM32 49h1v1h-1zM47 49h1v1h-1zM31 50h1v2h-1zM48 50h1v2h-1zM32 52h1v1h-1zM47 52h1v1h-1zM33 53h2v1h-2zM45 53h2v1h-2zM35 54h2v1h-2zM43 54h2v1h-2zM37 55h2v1h-2zM41 55h2v1h-2zM39 56h2v1h-2z"/><path fill="#8b7ec8" d="M10 17h1v1h-1zM10 18h3v1h-3zM11 19h4v1h-4zM13 20h4v1h-4zM15 21h4v1h-4zM17 22h4v1h-4zM14 23h1v1h-1zM18 23h5v1h-5zM14 24h3v1h-3zM18 24h7v1h-7zM15 25h7v1h-7zM23 25h4v1h-4zM17 26h5v1h-5zM25 26h4v1h-4zM18 27h5v1h-5zM27 27h4v1h-4zM18 28h7v1h-7zM28 28h5v1h-5zM23 29h4v1h-4zM28 29h7v1h-7zM25 30h7v1h-7zM33 30h4v1h-4zM27 31h5v1h-5zM35 31h4v1h-4zM29 32h4v1h-4zM36 32h5v1h-5zM31 33h4v1h-4zM36 33h7v1h-7zM33 34h7v1h-7zM41 34h4v1h-4zM35 35h5v1h-5zM43 35h3v1h-3zM36 36h5v1h-5zM45 36h1v1h-1zM36 37h7v1h-7zM41 38h4v1h-4zM43 39h3v1h-3zM18 29h4v12h-4zM45 40h1v1h-1zM19 41h3v1h-3zM21 42h1v1h-1zM36 38h4v12h-4zM37 50h3v1h-3zM39 51h1v1h-1z"/><path fill="#403e3c" d="M12 10h1v1h-1zM12 11h2v1h-2zM13 12h1v1h-1zM8 14h1v1h-1zM8 15h3v1h-3zM9 16h4v1h-4zM11 17h4v1h-4zM13 18h4v1h-4zM15 19h4v1h-4zM17 20h4v1h-4zM19 21h4v1h-4zM21 22h4v1h-4zM23 23h4v1h-4zM25 24h4v1h-4zM27 25h4v1h-4zM29 26h4v1h-4zM31 27h4v1h-4zM33 28h4v1h-4zM35 29h4v1h-4zM50 29h1v1h-1zM37 30h4v1h-4zM50 30h2v1h-2zM39 31h4v1h-4zM51 31h1v1h-1zM41 32h4v1h-4zM43 33h4v1h-4zM45 34h3v1h-3zM47 35h1v1h-1z"/><path fill="#575653" d="M15 8h2v1h-2zM13 9h3v1h-3zM17 11h2v1h-2zM11 12h2v1h-2zM15 12h6v1h-6zM9 13h14v1h-14zM10 14h15v1h-15zM12 15h15v1h-15zM14 16h15v1h-15zM16 17h15v1h-15zM18 18h15v1h-15zM20 19h15v1h-15zM22 20h15v1h-15zM24 21h15v1h-15zM26 22h15v1h-15zM28 23h15v1h-15zM30 24h15v1h-15zM32 25h15v1h-15zM34 26h15v1h-15zM36 27h15v1h-15zM53 27h2v1h-2zM38 28h16v1h-16zM40 29h10v1h-10zM42 30h8v1h-8zM44 31h7v1h-7zM46 32h4v1h-4z"/><path fill="#92918f" d="M16 9h1v1h-1zM13 10h2v1h-2zM9 14h1v1h-1zM11 15h1v1h-1zM13 16h1v1h-1zM15 17h1v1h-1zM17 18h1v1h-1zM19 19h1v1h-1zM21 20h1v1h-1zM23 21h1v1h-1zM25 22h1v1h-1zM27 23h1v1h-1zM29 24h1v1h-1zM31 25h1v1h-1zM33 26h1v1h-1zM35 27h1v1h-1zM37 28h1v1h-1zM54 28h1v1h-1zM39 29h1v1h-1zM51 29h2v1h-2zM41 30h1v1h-1zM43 31h1v1h-1zM45 32h1v1h-1zM50 32h1v1h-1zM47 33h2v1h-2z"/><path fill="#5e409d" d="M22 25h1v2h-1zM22 29h1v1h-1zM22 30h3v1h-3zM32 30h1v2h-1zM40 34h1v2h-1zM46 35h1v2h-1zM49 37h1v1h-1zM40 38h1v1h-1zM47 38h3v1h-3zM40 39h3v1h-3zM46 39h3v1h-3zM22 31h4v10h-4zM46 40h1v1h-1zM22 41h3v1h-3zM22 42h1v1h-1zM40 40h4v10h-4zM40 50h3v1h-3zM40 51h1v1h-1z"/><path fill="#cecdc3" d="M17 39h1v1h-1zM26 39h1v1h-1zM15 40h3v1h-3zM26 40h3v1h-3zM16 41h3v1h-3zM25 41h3v1h-3zM18 42h3v1h-3zM23 42h3v1h-3zM20 43h4v1h-4zM35 48h1v1h-1zM44 48h1v1h-1zM33 49h3v1h-3zM44 49h3v1h-3zM34 50h3v1h-3zM43 50h3v1h-3zM36 51h3v1h-3zM41 51h3v1h-3zM38 52h4v1h-4z"/><path fill="#dfded8" d="M15 41h1v1h-1zM28 41h1v1h-1zM17 42h1v1h-1zM26 42h1v1h-1zM19 43h1v1h-1zM24 43h1v1h-1zM21 44h2v1h-2zM33 50h1v1h-1zM46 50h1v1h-1zM35 51h1v1h-1zM44 51h1v1h-1zM37 52h1v1h-1zM42 52h1v1h-1zM39 53h2v1h-2z"/><path fill="#000000" fill-opacity="0.353" d="M15 45h2v1h-2zM27 45h2v1h-2zM17 46h2v1h-2zM25 46h2v1h-2zM19 47h2v1h-2zM23 47h2v1h-2zM21 48h2v1h-2zM33 54h2v1h-2zM45 54h2v1h-2zM35 55h2v1h-2zM43 55h2v1h-2zM37 56h2v1h-2zM41 56h2v1h-2zM39 57h2v1h-2z"/><path fill="#b7b5ac" d="M14 41h1v1h-1zM14 42h3v1h-3zM15 43h4v1h-4zM17 44h4v1h-4zM19 45h3v1h-3zM21 46h1v1h-1zM32 50h1v1h-1zM32 51h3v1h-3zM33 52h4v1h-4zM35 53h4v1h-4zM37 54h3v1h-3zM39 55h1v1h-1z"/><path fill="#878580" d="M29 41h1v1h-1zM27 42h3v1h-3zM25 43h4v1h-4zM23 44h4v1h-4zM22 45h3v1h-3zM22 46h1v1h-1zM47 50h1v1h-1zM45 51h3v1h-3zM43 52h4v1h-4zM41 53h4v1h-4zM40 54h3v1h-3zM40 55h1v1h-1z"/><path fill="#343331" d="M17 9h1v1h-1zM15 10h3v1h-3zM14 11h3v1h-3zM14 12h1v1h-1zM55 28h1v1h-1zM53 29h3v1h-3zM52 30h4v2h-4zM51 32h4v1h-4zM49 33h4v1h-4zM48 34h3v1h-3zM48 35h1v1h-1z"/><path fill="#a699d0" d="M15 22h2v1h-2zM16 23h2v1h-2zM23 26h2v1h-2zM24 27h3v1h-3zM26 28h2v1h-2zM33 31h2v1h-2zM34 32h2v1h-2zM41 35h2v1h-2zM42 36h3v1h-3zM47 36h2v1h-2zM44 37h4v1h-4z"/><path fill="#c5bde0" d="M15 23h1v1h-1zM17 24h1v1h-1zM23 27h1v1h-1zM25 28h1v1h-1zM27 29h1v1h-1zM33 32h1v1h-1zM35 33h1v1h-1zM41 36h1v1h-1zM43 37h1v1h-1zM48 37h1v1h-1zM45 38h2v1h-2z"/></svg>