@fungi.computer/inkcap 0.18.3 → 0.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$i as t,Aa as n,Ai as r,Ar as i,Ci as a,Cr as o,Da as s,Di as c,Dr as l,Ea as u,Ei as d,Er as f,Fi as p,Fr as m,Gr as h,Hr as g,Ir as ee,Ja as te,Kr as ne,Ma as _,Mi as v,Mr as re,Na as y,Ni as ie,Nr as ae,Oa as b,Oi as x,Or as oe,Pi as S,Pr as se,Qa as ce,Qi as C,Qr as le,Sa as ue,Si as de,Sr as fe,Ta as pe,Ti as w,Tr as me,Ur as he,Vn as ge,Vr as _e,Wr as ve,Xi as ye,Xr as T,Ya as be,Zi as xe,Zr as Se,_i as Ce,_r as we,aa as Te,ao as Ee,ba as E,bi as De,br as Oe,ca as D,da as ke,dr as Ae,fa as je,fo as Me,fr as Ne,ga as O,gi as Pe,gr as Fe,hi as Ie,ia as Le,io as Re,ja as ze,ji as Be,jr as Ve,ka as He,ki as Ue,kr as We,la as k,ma as A,mr as Ge,na as j,no as Ke,nr as qe,oa as M,oo as Je,pa as Ye,pr as Xe,ra as Ze,ro as Qe,so as $e,ta as N,ti as et,uo as tt,ur as nt,va as rt,vi as it,vr as at,wa as ot,wi as P,wr as F,xa as st,xr as ct,ya as lt,yi as ut,yr as dt,zr as ft}from"./tree-path-DQAnGoeW.js";var pt=new WeakMap,mt=`~effect/Redacted`,ht=e=>$e(e,mt),gt=(e,t)=>{let n=Object.create(_t);return t?.label&&(n.label=t.label),pt.set(n,e),n},_t={[mt]:{_A:e=>e},label:void 0,...Ke,toJSON(){return this.toString()},toString(){return`<redacted${tt(this.label)?`:`+this.label:``}>`},[Je](){return Ee(pt.get(this))},[Re](e){return ht(e)&&Qe(pt.get(this),pt.get(e))}},I=e(xe(),1),L=ye(),vt=I.createContext(void 0),yt=e=>{let t=I.useContext(vt);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},bt=({client:e,children:t})=>(I.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,L.jsx)(vt.Provider,{value:e,children:t})),xt={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},St=new class{#e=xt;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function Ct(e){setTimeout(e,0)}var wt=typeof window>`u`||`Deno`in globalThis;function Tt(){}function Et(e,t){return typeof e==`function`?e(t):e}function Dt(e){return typeof e==`number`&&e>=0&&e!==1/0}function Ot(e,t){return Math.max(e+(t||0)-Date.now(),0)}function R(e,t){return typeof e==`function`?e(t):e}function kt(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==jt(o,t.options))return!1}else if(!Nt(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function At(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(Mt(t.options.mutationKey)!==Mt(a))return!1}else if(!Nt(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function jt(e,t){return(t?.queryKeyHashFn||Mt)(e)}function Mt(e){return JSON.stringify(e,(e,t)=>Rt(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Nt(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e&&t&&typeof e==`object`&&typeof t==`object`){if(Array.isArray(e)&&Array.isArray(t)){for(let n=0;n<t.length;n++)if(!Nt(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Nt(e[r],t[r]))return!1;return!0}return!1}var Pt=Object.prototype.hasOwnProperty;function Ft(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=Lt(e)&&Lt(t);if(!r&&!(Rt(e)&&Rt(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:Pt.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Ft(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function It(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Lt(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Rt(e){if(!zt(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!zt(n)||!n.hasOwnProperty(`isPrototypeOf`)||Object.getPrototypeOf(e)!==Object.prototype)}function zt(e){return Object.prototype.toString.call(e)===`[object Object]`}function Bt(e){return new Promise(t=>{St.setTimeout(t,e)})}function Vt(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Ft(e,t)}function Ht(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function Ut(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var Wt=Symbol();function Gt(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Wt?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function Kt(e,t){return typeof e==`function`?e(...t):!!e}function qt(e,t,n){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r?i:(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0}),i))}),e}var Jt=()=>wt,Yt=()=>Jt(),Xt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Zt=new class extends Xt{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},Qt=Ct;function $t(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=Qt,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var z=$t(),en=new class extends Xt{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function tn(e){return Math.min(1e3*2**e,3e4)}function nn(e){return(e??`online`)!==`online`||en.isOnline()}var rn=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function an(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(Tt);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new rn(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>Zt.isFocused()&&(e.networkMode===`always`||en.isOnline())&&e.canRun(),p=()=>nn(e.networkMode)&&e.canRun(),m=e=>{c()||(r?.(),i=`resolved`,a(e))},h=e=>{c()||(r?.(),i=`rejected`,o(e))},g=()=>new Promise(t=>{r=e=>{(c()||f())&&t(e)},e.onPause?.()}).then(()=>{r=void 0,c()||e.onContinue?.()}),ee=()=>{if(c())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(m).catch(r=>{if(c())return;let i=e.retry??(Yt()?0:3),a=e.retryDelay??tn,o=typeof a==`function`?a(n,r):a,s=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);if(t||!s){h(r);return}n++,e.onFail?.(n,r),Bt(o).then(()=>f()?void 0:g()).then(()=>{t?h(r):ee()})})};return{promise:s,status:()=>i,cancel:l,continue:()=>(r?.(),s),cancelRetry:u,continueRetry:d,canStart:p,start:()=>(p()?ee():g().then(ee),s)}}var on=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Dt(this.gcTime)&&(this.#e=St.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Yt()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(St.clearTimeout(this.#e),this.#e=void 0)}};function sn(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{qt(e,()=>t.signal,()=>n=!0)},u=Gt(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject(t.signal.reason);if(r==null&&e.pages.length)return Promise.resolve(e);let a=(()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})(),o=await u(a),{maxPages:s}=t.options,c=i?Ut:Ht;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?ln:cn,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]??r.initialPageParam:cn(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.fetchFn=t.options.persister?()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):l}}}function cn(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function ln(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var un=class extends on{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=pn(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#a?.promise}setOptions(e){if(this.options={...this.#o,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=pn(this.options);e.data!==void 0&&(this.setState(fn(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Vt(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#c({type:`setState`,state:e})}cancel(e){let t=this.#a?.promise;return this.#a?.cancel(e),t?t.then(Tt).catch(Tt):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>R(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Wt||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>R(e.options.staleTime,this)===`static`)}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!Ot(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#a?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#a?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){let t=this.observers.indexOf(e);t!==-1&&(this.observers.splice(t,1),this.observers.length||(this.#a&&(this.#s||this.state.fetchStatus===`paused`&&this.state.status===`pending`?this.#a.cancel({revert:!0}):this.#a.cancelRetry()),this.scheduleGc()),this.#r.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#a?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#a)return this.#a.continueRetry(),this.#a.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#s=!0,n.signal)})},i=()=>{let e=Gt(this.options,t),n=(()=>{let e={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#s=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(e),e})();(this.#e===`infinite`?sn(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta});let o=this.#a=an({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof rn&&e.revert&&this.setState({...this.#n,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await o.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#r.config.onSuccess?.(e,this),this.#r.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof rn){if(e.silent)return this.#a.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#r.config.onError?.(e,this),this.#r.config.onSettled?.(this.state.data,e,this),e}finally{this.#a===o&&(this.#a=void 0),this.scheduleGc()}}#c(e){let t=t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...dn(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...fn(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}};this.state=t(this.state),z.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function dn(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:nn(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function fn(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function pn(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var mn=class extends Xt{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),gn(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return _n(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return _n(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof R(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!It(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&vn(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||R(this.options.enabled,this.#t)!==R(t.enabled,this.#t)||R(this.options.staleTime,this.#t)!==R(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||R(this.options.enabled,this.#t)!==R(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return It(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch().then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(Tt)),t}#h(e){return!Yt()&&R(this.options.enabled,this.#t)!==!1&&Dt(e)}#g(){this.#b();let e=R(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Ot(this.#r.dataUpdatedAt,e)+1;this.#u=St.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#f=e,!(this.#f===0||!this.#h(this.#f))&&(this.#d=St.setInterval(()=>{(this.options.refetchIntervalInBackground||Zt.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(St.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(St.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&gn(e,t),o=i&&vn(e,n,t,r);(a||o)&&(l={...l,...dn(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=Vt(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=Vt(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,ee=m===`pending`,te=m===`error`,ne=ee&&g,_=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:ee,isSuccess:m===`success`,isError:te,isInitialLoading:ne,isLoading:ne,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!ee,isLoadingError:te&&!_,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:te&&_,isStale:yn(e,t),refetch:this.refetch,isEnabled:R(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),It(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();z.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function hn(e,t){return R(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||R(t.retryOnMount,e)!==!1)}function gn(e,t){return hn(e,t)||e.state.data!==void 0&&_n(e,t,t.refetchOnMount)}function _n(e,t,n){if(R(t.enabled,e)!==!1&&R(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&yn(e,t)}return!1}function vn(e,t,n,r){return(e!==t||R(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&yn(e,n)}function yn(e,t){return R(t.enabled,e)!==!1&&e.isStaleByTime(R(t.staleTime,e))}var bn=class extends on{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||xn(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??(this.state.status===`pending`?this.execute(this.state.variables):Promise.resolve())}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey},r=this.#r=an({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)}),i=this.state.status===`pending`,a=!r.canStart();try{if(i)t();else{this.#i({type:`pending`,variables:e,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:a})}let o=await r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#i({type:`success`,data:o}),o}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#r===r&&(this.#r=void 0),this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),z.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function xn(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var Sn=class extends Xt{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new bn({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=Cn(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=Cn(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=Cn(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=Cn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){z.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>At(t,e))}findAll(e={}){return this.getAll().filter(t=>At(e,t))}notify(e){z.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return z.batch(()=>Promise.all(e.map(e=>e.continue().catch(Tt))))}};function Cn(e){return e.options.scope?.id}function wn(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var Tn=class extends Xt{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,z.batch(()=>{let e=this.#i,t=this.#p(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!It(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(wn(e,n).forEach(e=>{e.destroy()}),wn(n,e).forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})),this.#h()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#p(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){let n=new Set;return t.map((r,i)=>{let a=e[i];return r.defaultedQueryOptions.notifyOnChangeProps?a:r.observer.trackResult(a,e=>{n.has(e)||(n.add(e),t.forEach(t=>{t.observer.trackProp(e)}))})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=Ft(this.#a,t(e))),this.#a}return e}#f(){return!this.#r?.combine||this.#i.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#p(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new mn(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#h())}#h(){if(this.hasListeners()){let e=this.#f(),t=this.#a,n=e?t:this.#d(this.#u(this.#t,this.#l),this.#r?.combine);(e||t!==n)&&z.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},En=class extends Xt{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??jt(r,t),a=this.get(i);return a||(a=new un({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){z.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>kt(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>kt(e,t)):t}notify(e){z.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){z.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){z.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},Dn=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new En,this.#t=e.mutationCache||new Sn,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=Zt.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=en.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(R(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Et(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return z.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;z.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return z.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=z.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Tt).catch(Tt)}invalidateQueries(e,t={}){return z.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=z.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Tt)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Tt)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(R(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(R(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Tt).catch(Tt)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Tt).catch(Tt)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return en.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Mt(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Nt(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Mt(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Nt(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=jt(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===Wt&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},On=I.createContext(!1),kn=()=>I.useContext(On);On.Provider;function An(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var jn=I.createContext(An()),Mn=()=>I.useContext(jn),Nn=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?Kt(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},Pn=e=>{I.useEffect(()=>{e.clearReset()},[e])},Fn=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||Kt(n,[e.error,r])),In=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},Ln=(e,t)=>e?.suspense&&t.isPending,Rn=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function zn({queries:e,...t},n){let r=yt(n),i=kn(),a=Mn(),o=t.subscribed!==!1,s=I.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=i?`isRestoring`:o?`optimistic`:void 0,t}),[e,r,i,o]);s.forEach(e=>{In(e);let t=r.getQueryCache().get(e.queryHash);Nn(e,a,t)}),Pn(a);let[c]=I.useState(()=>new Tn(r,s,t)),[l,u,d]=c.getOptimisticResult(s,t.combine),f=!i&&o;I.useSyncExternalStore(I.useCallback(e=>f?c.subscribe(z.batchCalls(e)):Tt,[c,f]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),I.useEffect(()=>{c.setQueries(s,t)},[s,t,c]);let p=l.some((e,t)=>Ln(s[t],e))?l.flatMap((e,t)=>{let n=s[t];return n&&Ln(n,e)?Rn(n,new mn(r,n),a):[]}):[];if(p.length>0)throw Promise.all(p);let m=l.find((e,t)=>{let n=s[t];return n&&Fn({result:e,errorResetBoundary:a,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(m)throw m.error;return u(d())}function Bn(e,t,n){let r=kn(),i=Mn(),a=yt(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,In(o),Nn(o,i,s),Pn(i);let[l]=I.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(I.useSyncExternalStore(I.useCallback(e=>{let t=d?l.subscribe(z.batchCalls(e)):Tt;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),I.useEffect(()=>{l.setOptions(o)},[o,l]),Ln(o,u))throw Rn(o,l,i);if(Fn({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Vn(e,t){return Bn(e,mn,t)}function Hn(e){return e}var Un=a(),Wn=P(()=>de(`status`,[x({status:w(`available`)}).strict(),x({status:w(`unavailable`),reason:v()}).strict()])),Gn=Un,Kn=P(()=>r(v(),Gn)),qn=e=>Gn.parse(e),Jn=P(()=>x({code:v().min(1).max(160),message:v().min(1).max(512),details:Gn.optional()}).strict()),Yn=e=>Jn.parse(e),Xn=Kn,B=P(()=>v().refine(e=>e.trim().length>0)),Zn=Wn,Qn=P(()=>ie([x({type:w(`action`)}).strict(),x({type:w(`custom`),data:Kn}).strict(),x({type:w(`choice`),options:ut(x({value:Gn,label:B,description:B.optional()}))}).strict(),x({type:w(`form`),submitLabel:B.optional()}).strict(),x({type:w(`confirmation`),message:B,confirmLabel:B.optional(),cancelLabel:B.optional()}).strict()])),$n=P(()=>x({inputSchema:Xn.optional(),outputSchema:Xn.optional(),presentation:Qn.optional()}).strict()),er=P(()=>c().int().refine(e=>Number.isSafeInteger(e))),tr=P(()=>x({hint:B.pipe(v().max(120)),words:ut(x({word:v().regex(/^\S{1,64}$/u),description:B.pipe(v().max(512)).optional(),arguments:Kn}).strict()).max(32).optional(),text:x({field:B.pipe(v().max(120)),arguments:Kn,requestIdField:B.pipe(v().max(120)).optional()}).strict().optional()}).strict().refine(e=>e.words!==void 0||e.text!==void 0,`slash arguments need words or text`)),nr=P(()=>x({order:er.optional()}).strict()),rr=P(()=>x({bindings:x({order:er.optional(),values:ut(B).max(16)}).strict().optional(),agent:x({keybind:B.optional(),order:er.optional()}).strict().optional(),help:nr.optional(),menu:nr.optional(),palette:nr.optional(),slash:x({aliases:ut(B).max(16),consumesDraft:De().optional(),order:er.optional(),arguments:tr.optional()}).strict().optional()}).strict()),ir=P(()=>x({id:B.refine(e=>!e.includes(`:`)),title:B,category:B,description:B.optional(),projections:rr.optional(),action:$n.optional(),availability:Zn.optional()}).strict()),ar=e=>ir.parse(e),or=P(()=>x({inputSchema:Xn.optional(),outputSchema:Xn.optional()}).strict()),sr=v().min(1).brand(),cr=P(()=>x({commandId:sr,command:x({namespace:v(),id:v()}).strict(),sourceId:v(),scope:v().optional(),title:v(),category:v(),description:v().optional(),order:c(),availability:Wn,action:or.optional(),keybind:v().optional()}).strict());ut(cr);var lr=8192,V=B.pipe(v().max(lr)),ur=B.pipe(v().max(60)),dr=p({protocol:/^https?$/u}),fr=x({label:V,value:V}).strict(),pr={summary:V.optional(),facts:ut(fr).max(4).optional(),body:V.optional(),bodyLabel:V.optional(),details:ut(fr).max(24).optional()};de(`type`,[x({type:w(`choice`),message:ur,...pr,current:V.optional(),collapsedGroup:V.optional(),options:ut(x({value:V,label:V,description:V.optional(),group:V.optional(),destructive:w(!0).optional()}).strict()).min(1).max(256)}).strict(),x({type:w(`text`),message:ur,...pr,placeholder:V.optional(),secret:De().optional()}).strict(),x({type:w(`confirmation`),message:ur,...pr,confirmLabel:V.optional(),cancelLabel:V.optional(),destructive:w(!0).optional()}).strict(),x({type:w(`decision`),message:ur,...pr,options:ut(x({value:V,label:V,description:V.optional(),destructive:w(!0).optional()}).strict()).min(1).max(8).refine(e=>new Set(e.map(e=>e.value)).size===e.length,`Decision option values must be unique`),multiple:De().optional(),other:x({label:V,placeholder:V.optional(),maxLength:c().int().min(1).max(lr),blank:V.optional()}).strict().optional(),escape:V.optional()}).strict().refine(e=>[e.escape,e.other?.blank].every(t=>t===void 0||e.options.some(e=>e.value===t)),`A decision's escape and blank answers must be offered options`)]),P(()=>de(`type`,[x({type:w(`info`),message:V,links:ut(x({url:dr,label:V.optional()}).strict()).max(16).optional()}).strict(),x({type:w(`progress`),message:V}).strict(),x({type:w(`handoff`),url:dr,code:V.optional(),message:V.optional()}).strict(),x({type:w(`success`),message:V}).strict()]));var mr=class extends Error{code;details;constructor(e,t,n){super(t),this.code=e,this.details=n,this.name=`WhistleActionError`}},hr=class extends Error{constructor(){super(`Whistle runtime is closed`),this.name=`WhistleClosedError`}};function gr(){let e=!1,t=Jr,n=[],r=[],i=!1,a=[],o=new Set,s=()=>{for(let e of o)e()};return Object.freeze({close:()=>{e||(e=!0,n=[],a=[],r=[],t=Jr,s(),o.clear())},contribute:t=>{if(Tr(t),e)throw new hr;Er(t,n),Dr(t,n);let r=Symbol(`whistle-contribution`);wr(t)||(n=[...n,{contribution:Or(t),generation:r}],i=!0,s());let a=!0;return Kr(o=>{if(!a||e)return;let c={...t,commands:o};Tr(c);let l=n.findIndex(e=>e.generation===r),u=n.filter(e=>e.generation!==r);Er(c,u),Dr(c,u);let d=Or(c);if(wr(c)){if(l<0)return;n=u}else n=l<0?[...n,{contribution:d,generation:r}]:n.map(e=>e.generation===r?{contribution:d,generation:r}:e);i=!0,s()},()=>{a&&(a=!1,n.find(e=>e.generation===r)!==void 0&&(n=n.filter(e=>e.generation!==r),i=!0,s()))})},execute:async(t,r)=>{if(t.namespace.trim().length===0||t.id.trim().length===0)return{status:`invalid`};if(e)return{status:`closed`};let i=Cr(t,n);if(i===void 0)return{status:`missing`};let o;try{let e=Xr(i);if(e.status===`unavailable`)return e;let n=a.at(-1)?.presenter;r.interaction===void 0&&n!==void 0&&_r.has(r.origin)&&(o=n({commandId:Sr(t.namespace,t.id),title:i.title}));let s={...r,signal:r.signal??new AbortController().signal};o!==void 0&&(s.interaction=o.interaction,s.signal=AbortSignal.any([s.signal,o.interaction.signal]));let c=await i.handler(s);return o?.settle({status:`handled`}),c===void 0?{status:`handled`}:{status:`handled`,result:c}}catch(e){let t=Qr(e instanceof Error?e:Error(`Command handler threw a non-Error value`));return o?.settle(o.interaction.signal.aborted?{status:`cancelled`}:{status:`failed`,message:t.message}),{status:`failed`,error:t}}},present:t=>{let n={presenter:t};return e||(a=[...a,n]),()=>{a=a.filter(e=>e!==n)}},snapshot:()=>{if(e)return Jr;let a=n.flatMap(e=>e.contribution.commands.map(Xr));return(i||a.some((e,t)=>!Zr(e,r[t])))&&(t=$r(n,a),r=a,i=!1),t},subscribe:t=>e?()=>void 0:(o.add(t),()=>{o.delete(t)})})}var _r=new Set([`browser`,`keyboard`,`menu`,`palette`,`slash`,`terminal`]),vr=16,yr=32,br=64,xr=256;function Sr(e,t){return sr.parse(`${e}:${t}`)}function Cr(e,t){for(let n of t)if(n.contribution.namespace===e.namespace){for(let t of n.contribution.commands)if(t.id===e.id)return t}}function wr(e){return e.commands.length===0}function Tr(e){H(e.sourceId,`source ID`),H(e.namespace,`namespace`),e.scope!==void 0&&H(e.scope,`scope`);for(let t of e.commands)Br(t)}function Er(e,t){t.find(t=>t.contribution.namespace===e.namespace&&t.contribution.sourceId!==e.sourceId)!==void 0&&qr(`Namespace is already owned by another source`);let n=new Set,r=new Set;for(let i of t){let t=i.contribution.scope===e.scope;for(let e of i.contribution.commands)if(n.add(Sr(i.contribution.namespace,e.id)),t)for(let t of e.projections?.slash?.aliases??[])r.add(t)}for(let t of e.commands){let i=Sr(e.namespace,t.id);n.has(i)&&qr(`Canonical command ID is already registered`),n.add(i);for(let e of t.projections?.slash?.aliases??[])r.has(e)&&qr(`Slash alias is already registered`),r.add(e)}}function Dr(e,t){t.length>=br&&qr(`Live contribution capacity exceeded`),t.reduce((e,t)=>e+t.contribution.commands.length,0)+e.commands.length>xr&&qr(`Live command capacity exceeded`)}function Or(e){let t={sourceId:e.sourceId,namespace:e.namespace,commands:e.commands.map(kr)};return e.scope===void 0?t:{...t,scope:e.scope}}function kr(e){let t={id:e.id,title:e.title,category:e.category,handler:e.handler};return e.description!==void 0&&(t.description=e.description),e.action!==void 0&&(t.action=Ar(e.action)),e.availability!==void 0&&(t.availability=e.availability),e.projections!==void 0&&(t.projections=Pr(e.projections)),t}function Ar(e){let t={};return e.inputSchema!==void 0&&(t.inputSchema=jr(e.inputSchema)),e.outputSchema!==void 0&&(t.outputSchema=jr(e.outputSchema)),e.presentation!==void 0&&(t.presentation=Nr(e.presentation)),Object.freeze(t)}function jr(e){return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Mr(t)])))}function Mr(e){return Array.isArray(e)?Object.freeze(e.map(Mr)):e!==null&&e instanceof Object?Object.freeze(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Mr(t)]))):e}function Nr(e){switch(e.type){case`action`:return Object.freeze({type:`action`});case`custom`:return Object.freeze({type:`custom`,data:jr(e.data)});case`choice`:return Object.freeze({type:`choice`,options:Object.freeze(e.options.map(e=>Object.freeze({...e,value:Mr(e.value)})))});case`form`:return Object.freeze({...e});case`confirmation`:return Object.freeze({...e})}}function Pr(e){let t={};return e.bindings!==void 0&&(t.bindings=Fr(e.bindings)),e.agent!==void 0&&(t.agent=Ir(e.agent)),e.help!==void 0&&(t.help=Lr(e.help.order)),e.menu!==void 0&&(t.menu=Lr(e.menu.order)),e.palette!==void 0&&(t.palette=Lr(e.palette.order)),e.slash!==void 0&&(t.slash=Rr(e.slash)),t}function Fr(e){let t={values:[...e.values]};return e.order!==void 0&&(t.order=e.order),t}function Ir(e){let t={};return e.keybind!==void 0&&(t.keybind=e.keybind),e.order!==void 0&&(t.order=e.order),t}function Lr(e){let t={};return e!==void 0&&(t.order=e),t}function Rr(e){let t={aliases:[...e.aliases]};return e.order!==void 0&&(t.order=e.order),e.consumesDraft!==void 0&&(t.consumesDraft=e.consumesDraft),e.arguments!==void 0&&(t.arguments=zr(e.arguments)),t}function zr(e){let t={hint:e.hint};return e.words!==void 0&&(t.words=Object.freeze(e.words.map(e=>Object.freeze({...e,arguments:jr(e.arguments)})))),e.text!==void 0&&(t.text=Object.freeze({...e.text,arguments:jr(e.text.arguments)})),Object.freeze(t)}function Br(e){H(e.id,`command ID`,!0),H(e.title,`title`),H(e.category,`category`),Vr(e.action),Hr(e.projections)}function Vr(e){if(e?.presentation!==void 0)switch(e.presentation.type){case`action`:case`custom`:return;case`choice`:for(let t of e.presentation.options)H(t.label,`choice label`),t.description!==void 0&&H(t.description,`choice description`);return;case`form`:e.presentation.submitLabel!==void 0&&H(e.presentation.submitLabel,`submit label`);return;case`confirmation`:H(e.presentation.message,`confirmation message`),e.presentation.confirmLabel!==void 0&&H(e.presentation.confirmLabel,`confirmation label`),e.presentation.cancelLabel!==void 0&&H(e.presentation.cancelLabel,`cancellation label`)}}function Hr(e){if(e!==void 0){for(let t of[e.bindings,e.palette,e.slash,e.help,e.menu,e.agent])t!==void 0&&Gr(t.order);if(e.bindings!==void 0&&Wr(e.bindings.values,`binding`),e.slash!==void 0){Wr(e.slash.aliases,`slash alias`);for(let t of e.slash.aliases)/\s/u.test(t)&&qr(`slash alias must not contain whitespace`);Ur(e.slash.arguments)}e.agent?.keybind!==void 0&&H(e.agent.keybind,`agent keybind`)}}function Ur(e){if(e===void 0)return;H(e.hint,`argument hint`),e.words===void 0&&e.text===void 0&&qr(`slash arguments need words or text`);let t=new Set;for(let n of e.words??[])H(n.word,`argument word`),/\s/u.test(n.word)&&qr(`argument word must not contain whitespace`),t.has(n.word)&&qr(`argument word is repeated`),t.add(n.word),n.description!==void 0&&H(n.description,`argument word description`);t.size>yr&&qr(`argument word count exceeds 32`),e.text!==void 0&&(H(e.text.field,`argument text field`),e.text.requestIdField!==void 0&&H(e.text.requestIdField,`request id field`))}function Wr(e,t){e.length>vr&&qr(`${t} count exceeds 16`);for(let n of e)H(n,t)}function H(e,t,n=!1){e.trim().length===0&&qr(`${t} must not be blank`),n&&e.includes(`:`)&&qr(`${t} must not contain a colon`)}function Gr(e){e!==void 0&&!Number.isSafeInteger(e)&&qr(`order must be a safe integer`)}function Kr(e=()=>void 0,t=()=>void 0){return Object.freeze({update:e,dispose:t})}function qr(e){throw Error(e)}var Jr=Object.freeze({bindings:Object.freeze([]),palette:Object.freeze([]),slash:Object.freeze([]),help:Object.freeze([]),menu:Object.freeze([]),agent:Object.freeze([])}),Yr=Object.freeze({status:`available`});function Xr(e){let t=e.availability?.()??Yr;return t.status===`available`?Yr:Object.freeze({status:`unavailable`,reason:t.reason})}function Zr(e,t){return e.status===`available`?t?.status===`available`:t?.status===`unavailable`&&e.reason===t.reason}function Qr(e){if(e instanceof mr){let t={code:e.code,message:e.message};return Object.freeze(e.details===void 0?t:{...t,details:Mr(e.details)})}return Object.freeze({code:`command_failed`,message:e.message})}function $r(e,t){let n=[],r=[],i=[],a=[],o=[],s=[],c=0;for(let l of e){let e=l.contribution;for(let l of e.commands){let u=l.projections,d=t[c++]??Yr;if(u?.bindings!==void 0)for(let t of u.bindings.values)n.push({...oi(e,l,u.bindings.order,d),binding:t});if(u?.palette!==void 0&&r.push({...oi(e,l,u.palette.order,d)}),u?.slash!==void 0)for(let t of u.slash.aliases){let n={...oi(e,l,u.slash.order,d),alias:t};u.slash.consumesDraft!==void 0&&(n={...n,consumesDraft:u.slash.consumesDraft}),u.slash.arguments!==void 0&&(n={...n,arguments:u.slash.arguments}),i.push(n)}u?.help!==void 0&&a.push({...oi(e,l,u.help.order,d)}),u?.menu!==void 0&&o.push({...oi(e,l,u.menu.order,d)}),u?.agent!==void 0&&s.push(ci(e,l,u.agent,d))}}return ri(n),ii(i),ni(r),ni(a),ni(o),ni(s),Object.freeze({bindings:ai(n),palette:ai(r),slash:ai(i),help:ai(a),menu:ai(o),agent:ai(s)})}var ei=new TextEncoder;function ti(e,t){let n=ei.encode(e),r=ei.encode(t),i=Math.min(n.length,r.length);for(let e=0;e<i;e+=1){let t=n[e]??0,i=r[e]??0;if(t!==i)return t<i?-1:1}return n.length<r.length?-1:+(n.length>r.length)}function ni(e){e.sort((e,t)=>e.order-t.order||ti(e.commandId,t.commandId))}function ri(e){e.sort((e,t)=>e.order-t.order||ti(e.commandId,t.commandId)||ti(e.binding,t.binding))}function ii(e){e.sort((e,t)=>e.order-t.order||ti(e.commandId,t.commandId)||ti(e.alias,t.alias))}function ai(e){return Object.freeze(e.map(e=>Object.freeze(e)))}function oi(e,t,n,r){let i=si(e,t,n,r);return e.scope===void 0?i:{...i,scope:e.scope}}function si(e,t,n,r){let i={commandId:Sr(e.namespace,t.id),command:Object.freeze({namespace:e.namespace,id:t.id}),sourceId:e.sourceId,title:t.title,category:t.category,order:n??0,availability:r},a=t.description===void 0?i:{...i,description:t.description};return t.action===void 0?a:{...a,action:t.action}}function ci(e,t,n,r){let i=oi(e,t,n.order,r),a=i.action===void 0?i:{...i,action:li(i.action)};return n.keybind===void 0?a:{...a,keybind:n.keybind}}function li(e){let t={};return e.inputSchema!==void 0&&(t.inputSchema=e.inputSchema),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),Object.freeze(t)}var ui=new WeakMap;function di(e,t){let n=!1,r=[];for(let i of t){let{availability:t,handler:a,...o}=i,s=a,c=t===void 0?o:{...o,availability:t()},l=ui.get(e)??new Map;ui.set(e,l);let u=l.get(i.id),d=()=>e.register(c,async({arguments:e,origin:t,signal:n})=>{let r=await s(e===void 0?{origin:t,signal:n}:{arguments:e,origin:t,signal:n});return r===void 0?void 0:qn(r)}),f=(u?u.then(d):d()).then(e=>{n?e():r.push(e)},e=>{console.warn(`App command ${i.id} was not registered`,e)});l.set(i.id,f),f.finally(()=>{l.get(i.id)===f&&l.delete(i.id)})}return()=>{if(!n){n=!0;for(let e of r.splice(0))e()}}}var fi=k({code:D.check(n(/^[a-z][a-z0-9_]{0,63}$/))}),pi=e=>{let t=rt(fi)(e);return ce(t)&&e instanceof Error?t.value.code:void 0};function mi(e,t){let n={source:`agar`,operation:e,failureKind:t instanceof Error?`Error`:`NonErrorThrown`},r=pi(t),i=r===void 0?n:{...n,code:r};console.error(JSON.stringify(i),gt(t))}var hi=Symbol(`workers-module`);Symbol.dispose||(Symbol.dispose=Symbol.for(`dispose`)),Symbol.asyncDispose||(Symbol.asyncDispose=Symbol.for(`asyncDispose`)),Promise.withResolvers||(Promise.withResolvers=function(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}});var gi=globalThis[hi],_i=gi?gi.RpcTarget:class{},vi=async function(){}.constructor,yi=typeof Buffer<`u`?Buffer.prototype:void 0;function bi(e){switch(typeof e){case`boolean`:case`number`:case`string`:return`primitive`;case`undefined`:return`undefined`;case`object`:case`function`:break;case`bigint`:return`bigint`;default:return`unsupported`}if(e===null)return`primitive`;let t=Object.getPrototypeOf(e);switch(t){case Object.prototype:return`object`;case Function.prototype:case vi.prototype:return`function`;case Array.prototype:return`array`;case Date.prototype:return`date`;case Uint8Array.prototype:case yi:case ArrayBuffer.prototype:case DataView.prototype:case Int8Array.prototype:case Uint8ClampedArray.prototype:case Int16Array.prototype:case Uint16Array.prototype:case Int32Array.prototype:case Uint32Array.prototype:case BigInt64Array.prototype:case BigUint64Array.prototype:case Float32Array.prototype:case Float64Array.prototype:return`bytes`;case WritableStream.prototype:return`writable`;case ReadableStream.prototype:return`readable`;case URL.prototype:return`url`;case Headers.prototype:return`headers`;case Request.prototype:return`request`;case Response.prototype:return`response`;case Blob.prototype:return`blob`;case Ai.prototype:return`stub`;case G.prototype:return`rpc-promise`;default:if(gi){if(t==gi.RpcStub.prototype||e instanceof gi.ServiceStub)return`rpc-target`;if(t==gi.RpcPromise.prototype||t==gi.RpcProperty.prototype)return`rpc-thenable`}return e instanceof _i?`rpc-target`:e instanceof Error?`error`:`unsupported`}}function xi(){throw Error(`RPC map() implementation was not loaded.`)}var Si={applyMap:xi,sendMap:xi};function Ci(){throw Error(`Stream implementation was not loaded.`)}var U={createWritableStreamHook:Ci,createWritableStreamFromHook:Ci,createReadableStreamHook:Ci},wi=class{stream(e,t){let n=this.call(e,t),r;try{r=n.pull()}catch(e){throw n.dispose(),e}let i;return r instanceof Promise?i=r.then(e=>{e.dispose()}):(r.dispose(),i=Promise.resolve()),{promise:i}}},W=class extends wi{error;constructor(e){super(),this.error=e}call(e,t){return t.dispose(),this}map(e,t,n){for(let e of t)e.dispose();return this}get(e){return this}dup(){return this}pull(){return Promise.reject(this.error)}ignoreUnhandledRejections(){}dispose(){}onBroken(e){try{e(this.error)}catch(e){Promise.resolve(e)}}},Ti=new W(Error(`Attempted to use RPC stub after it has been disposed.`)),Ei=(e,t,n)=>e.call(t,n);function Di(e,t){let n=Ei;Ei=e;try{return t()}finally{Ei=n}}var Oi=Symbol(`realStub`),ki={apply(e,t,n){let r=e.raw;return new G(Ei(r.hook,r.pathIfPromise||[],K.fromAppParams(n)),[])},get(e,t,n){let r=e.raw;if(t===Oi)return r;if(t in G.prototype)return r[t];if(typeof t==`string`)return new G(r.hook,r.pathIfPromise?[...r.pathIfPromise,t]:[t]);if(t===Symbol.dispose&&(!r.pathIfPromise||r.pathIfPromise.length==0))return()=>{r.hook.dispose(),r.hook=Ti}},has(e,t){let n=e.raw;return t===Oi?!0:t in G.prototype?t in n:typeof t==`string`||t===Symbol.dispose&&(!n.pathIfPromise||n.pathIfPromise.length==0)},construct(e,t){throw Error(`An RPC stub cannot be used as a constructor.`)},defineProperty(e,t,n){throw Error(`Can't define properties on RPC stubs.`)},deleteProperty(e,t){throw Error(`Can't delete properties on RPC stubs.`)},getOwnPropertyDescriptor(e,t){},getPrototypeOf(e){return Object.getPrototypeOf(e.raw)},isExtensible(e){return!1},ownKeys(e){return[]},preventExtensions(e){return!0},set(e,t,n,r){throw Error(`Can't assign properties on RPC stubs.`)},setPrototypeOf(e,t){throw Error(`Can't override prototype of RPC stubs.`)}},Ai=class e extends _i{constructor(e,t){if(super(),!(e instanceof wi)){let n=e;if(e=n instanceof _i||n instanceof Function?Vi.create(n,void 0):new zi(K.fromAppReturn(n)),t)throw TypeError(`RpcStub constructor expected one argument, received two.`)}this.hook=e,this.pathIfPromise=t;let n=()=>{};return n.raw=this,new Proxy(n,ki)}hook;pathIfPromise;dup(){let t=this[Oi];return t.pathIfPromise?new e(t.hook.get(t.pathIfPromise)):new e(t.hook.dup())}onRpcBroken(e){this[Oi].hook.onBroken(e)}map(e){let{hook:t,pathIfPromise:n}=this[Oi];return Si.sendMap(t,n||[],e)}toString(){return`[object RpcStub]`}},G=class extends Ai{constructor(e,t){if(e instanceof wi)super(e,t??[]);else{if(t!==void 0)throw TypeError(`RpcPromise constructor expected one argument, received two.`);let n=bi(e);if(n===`rpc-promise`){let t=Fi(e);if(t.pathIfPromise.length>0)super(t.hook,t.pathIfPromise);else{let e=t.hook;t.hook=Ti,super(e,[])}}else if(n===`rpc-thenable`)super(Vi.create(e,void 0),[]);else{let t=new Hi(Promise.resolve(e).then(e=>new zi(K.fromAppReturn(e))));t.ignoreUnhandledRejections(),super(t,[])}}}then(e,t){return Ii(this).then(...arguments)}catch(e){return Ii(this).catch(...arguments)}finally(e){return Ii(this).finally(...arguments)}toString(){return`[object RpcPromise]`}};function ji(e){let{hook:t,pathIfPromise:n}=e[Oi];return n&&n.length>0?t.get(n):t}function Mi(e){let{hook:t,pathIfPromise:n}=e[Oi];return n?t.get(n):t.dup()}function Ni(e){let{hook:t,pathIfPromise:n}=e[Oi];if(!(n&&n.length>0))return t}function Pi(e){return e[Oi].hook}function Fi(e){return e[Oi]}async function Ii(e){let{hook:t,pathIfPromise:n}=e[Oi];return n.length>0&&(t=t.get(n)),(await t.pull()).deliverResolve()}var K=class e{value;source;hooks;promises;static fromAppParams(t){return new e(t,`params`)}static fromAppReturn(t){return new e(t,`return`)}static fromArray(t){let n=[],r=[],i=[];for(let e of t){e.ensureDeepCopied();for(let t of e.hooks)n.push(t);for(let t of e.promises)t.parent===e&&(t={parent:i,property:i.length,promise:t.promise}),r.push(t);i.push(e.value)}return new e(i,`owned`,n,r)}static forEvaluate(t,n){return new e(null,`owned`,t,n)}static deepCopyFrom(t,n,r){let i=new e(null,`owned`,[],[]);return i.value=i.deepCopy(t,n,`value`,i,!0,r),i}constructor(e,t,n,r){this.value=e,this.source=t,this.hooks=n,this.promises=r}rpcTargets;getHookForRpcTarget(e,t,n=!0){if(this.source===`params`){if(n){let t=e;typeof t.dup==`function`&&(e=t.dup())}return Vi.create(e,t)}if(this.source===`return`){let r=this.rpcTargets?.get(e);return r?n?r.dup():(this.rpcTargets?.delete(e),r):(r=Vi.create(e,t),n?(this.rpcTargets||=new Map,this.rpcTargets.set(e,r),r.dup()):r)}throw Error(`owned payload shouldn't contain raw RpcTargets`)}getHookForWritableStream(e,t,n=!0){if(this.source===`params`)return U.createWritableStreamHook(e);if(this.source===`return`){let t=this.rpcTargets?.get(e);return t?n?t.dup():(this.rpcTargets?.delete(e),t):(t=U.createWritableStreamHook(e),n?(this.rpcTargets||=new Map,this.rpcTargets.set(e,t),t.dup()):t)}throw Error(`owned payload shouldn't contain raw WritableStreams`)}getHookForReadableStream(e,t,n=!0){if(this.source===`params`)return U.createReadableStreamHook(e);if(this.source===`return`){let t=this.rpcTargets?.get(e);return t?n?t.dup():(this.rpcTargets?.delete(e),t):(t=U.createReadableStreamHook(e),n?(this.rpcTargets||=new Map,this.rpcTargets.set(e,t),t.dup()):t)}throw Error(`owned payload shouldn't contain raw ReadableStreams`)}deepCopy(e,t,n,r,i,a){switch(bi(e)){case`unsupported`:return e;case`primitive`:case`bigint`:case`date`:case`bytes`:case`blob`:case`url`:case`error`:case`undefined`:return e;case`array`:{let t=e,n=t.length,r=Array(n);for(let e=0;e<n;e++)r[e]=this.deepCopy(t[e],t,e,r,i,a);return r}case`object`:{let t={},n=e;for(let e in n)t[e]=this.deepCopy(n[e],n,e,t,i,a);return t}case`stub`:case`rpc-promise`:{let t=e,a;if(a=i?Mi(t):ji(t),t instanceof G){let e=new G(a,[]);return this.promises.push({parent:r,property:n,promise:e}),e}return this.hooks.push(a),new Ai(a)}case`function`:case`rpc-target`:{let n=e,r;return r=a?a.getHookForRpcTarget(n,t,i):Vi.create(n,t),this.hooks.push(r),new Ai(r)}case`rpc-thenable`:{let o=e,s;return s=a?new G(a.getHookForRpcTarget(o,t,i),[]):new G(Vi.create(o,t),[]),this.promises.push({parent:r,property:n,promise:s}),s}case`writable`:{let n=e,r;return r=a?a.getHookForWritableStream(n,t,i):U.createWritableStreamHook(n),this.hooks.push(r),n}case`readable`:{let n=e,r;return r=a?a.getHookForReadableStream(n,t,i):U.createReadableStreamHook(n),this.hooks.push(r),n}case`headers`:return new Headers(e);case`request`:{let t=e;return t.body&&this.deepCopy(t.body,t,`body`,t,i,a),new Request(t)}case`response`:{let t=e;return t.body&&this.deepCopy(t.body,t,`body`,t,i,a),new Response(t.body,t)}default:throw Error(`unreachable`)}}ensureDeepCopied(){if(this.source!==`owned`){let e=this.source===`params`;this.hooks=[],this.promises=[];try{this.value=this.deepCopy(this.value,void 0,`value`,this,e,this)}catch(e){throw this.hooks=void 0,this.promises=void 0,e}if(this.source=`owned`,this.rpcTargets&&this.rpcTargets.size>0)throw Error(`Not all rpcTargets were accounted for in deep-copy?`);this.rpcTargets=void 0}}deliverTo(t,n,r){if(this.ensureDeepCopied(),this.value instanceof G)e.deliverRpcPromiseTo(this.value,t,n,r);else{t[n]=this.value;for(let t of this.promises)e.deliverRpcPromiseTo(t.promise,t.parent,t.property,r)}}static deliverRpcPromiseTo(t,n,r,i){let a=Ni(t);if(!a)throw Error(`property promises should have been resolved earlier`);let o=a.pull();o instanceof e?o.deliverTo(n,r,i):i.push(o.then(e=>{let t=[];if(e.deliverTo(n,r,t),t.length>0)return Promise.all(t)}))}async deliverCall(t,n){try{let r=[];this.deliverTo(this,`value`,r),r.length>0&&await Promise.all(r);let i=Function.prototype.apply.call(t,n,this.value);return i instanceof G?e.fromAppReturn(i):e.fromAppReturn(await i)}finally{this.dispose()}}async deliverStreamWrite(t){try{let n=[];this.deliverTo(this,`value`,n),n.length>0&&await Promise.all(n);let r=this.value[0];return(this.hooks.length>0||this.promises.length>0)&&r instanceof Object?(Symbol.dispose in r||Object.defineProperty(r,Symbol.dispose,{value:()=>this.dispose(),writable:!0,enumerable:!1,configurable:!0}),await t.write(r),e.fromAppReturn(void 0)):(await t.write(r),this.dispose(),e.fromAppReturn(void 0))}catch(e){throw this.dispose(),e}}async deliverResolve(){try{let e=[];this.deliverTo(this,`value`,e),e.length>0&&await Promise.all(e);let t=this.value;return t instanceof Object&&(Symbol.dispose in t||Object.defineProperty(t,Symbol.dispose,{value:()=>this.dispose(),writable:!0,enumerable:!1,configurable:!0})),t}catch(e){throw this.dispose(),e}}dispose(){if(this.source===`owned`)this.hooks.forEach(e=>e.dispose()),this.promises.forEach(e=>e.promise[Symbol.dispose]());else if(this.source===`return`&&(this.disposeImpl(this.value,void 0),this.rpcTargets&&this.rpcTargets.size>0))throw Error(`Not all rpcTargets were accounted for in disposeImpl()?`);this.source=`owned`,this.hooks=[],this.promises=[]}disposeImpl(e,t){switch(bi(e)){case`unsupported`:case`primitive`:case`bigint`:case`bytes`:case`blob`:case`date`:case`url`:case`error`:case`undefined`:return;case`array`:{let t=e,n=t.length;for(let e=0;e<n;e++)this.disposeImpl(t[e],t);return}case`object`:{let t=e;for(let e in t)this.disposeImpl(t[e],t);return}case`stub`:case`rpc-promise`:{let t=Ni(e);t&&t.dispose();return}case`function`:case`rpc-target`:{let t=e,n=this.rpcTargets?.get(t);n?(n.dispose(),this.rpcTargets.delete(t)):Bi(t);return}case`rpc-thenable`:return;case`headers`:return;case`request`:{let t=e;t.body&&this.disposeImpl(t.body,t);return}case`response`:{let t=e;t.body&&this.disposeImpl(t.body,t);return}case`writable`:{let t=e,n=this.rpcTargets?.get(t);n?this.rpcTargets.delete(t):n=U.createWritableStreamHook(t),n.dispose();return}case`readable`:{let t=e,n=this.rpcTargets?.get(t);n?this.rpcTargets.delete(t):n=U.createReadableStreamHook(t),n.dispose();return}default:return}}ignoreUnhandledRejections(){this.hooks?(this.hooks.forEach(e=>{e.ignoreUnhandledRejections()}),this.promises.forEach(e=>Pi(e.promise).ignoreUnhandledRejections())):this.ignoreUnhandledRejectionsImpl(this.value)}ignoreUnhandledRejectionsImpl(e){switch(bi(e)){case`unsupported`:case`primitive`:case`bigint`:case`bytes`:case`blob`:case`date`:case`error`:case`undefined`:case`function`:case`rpc-target`:case`writable`:case`readable`:case`url`:case`headers`:case`request`:case`response`:return;case`array`:{let t=e,n=t.length;for(let e=0;e<n;e++)this.ignoreUnhandledRejectionsImpl(t[e]);return}case`object`:{let t=e;for(let e in t)this.ignoreUnhandledRejectionsImpl(t[e]);return}case`stub`:case`rpc-promise`:Pi(e).ignoreUnhandledRejections();return;case`rpc-thenable`:e.then(e=>{},e=>{});return;default:return}}};function Li(e,t,n,r){for(let i=0;i<n.length;i++){t=e;let a=n[i];if(a in Object.prototype){e=void 0;continue}switch(bi(e)){case`object`:case`function`:e=Object.hasOwn(e,a)?e[a]:void 0;break;case`array`:e=Number.isInteger(a)&&a>=0?e[a]:void 0;break;case`rpc-target`:case`rpc-thenable`:if(Object.hasOwn(e,a))throw TypeError(`Attempted to access property '${a}', which is an instance property of the RpcTarget. To avoid leaking private internals, instance properties cannot be accessed over RPC. If you want to make this property available over RPC, define it as a method or getter on the class, instead of an instance property.`);e=e[a],r=null;break;case`stub`:case`rpc-promise`:{let{hook:t,pathIfPromise:r}=Fi(e);return{hook:t,remainingPath:r?r.concat(n.slice(i)):n.slice(i)}}case`writable`:e=void 0;break;case`readable`:e=void 0;break;case`primitive`:case`bigint`:case`bytes`:case`blob`:case`date`:case`error`:case`url`:case`headers`:case`request`:case`response`:e=void 0;break;case`undefined`:e=e[a];break;case`unsupported`:if(i===0)throw TypeError(`RPC stub points at a non-serializable type.`);{let e=n.slice(0,i).join(`.`),t=n.slice(0,i).join(`.`);throw TypeError(`'${e}' is not a serializable type, so property ${t} cannot be accessed.`)}default:throw TypeError(`unreachable`)}}if(e instanceof G){let{hook:t,pathIfPromise:n}=Fi(e);return{hook:t,remainingPath:n||[]}}return{value:e,parent:t,owner:r}}var Ri=class extends wi{call(e,t){let n;try{let{value:t,owner:r}=this.getValue();n=Li(t,void 0,e,r)}catch(e){return t.dispose(),new W(e)}return n.hook?n.hook.call(n.remainingPath,t):typeof n.value==`function`?new Hi(t.deliverCall(n.value,n.parent).then(e=>new zi(e))):(t.dispose(),new W(TypeError(`'${e.join(`.`)}' is not a function.`)))}map(e,t,n){try{let r;try{let{value:t,owner:n}=this.getValue();r=Li(t,void 0,e,n)}catch(e){for(let e of t)e.dispose();throw e}return r.hook?r.hook.map(r.remainingPath,t,n):Si.applyMap(r.value,r.parent,r.owner,t,n)}catch(e){return new W(e)}}get(e){try{let{value:t,owner:n}=this.getValue();if(e.length===0&&n===null){if(t instanceof Object&&`then`in t)return this.dup();throw Error(`Can't dup an RpcTarget stub as a promise.`)}let r=Li(t,void 0,e,n);return r.hook?r.hook.get(r.remainingPath):new zi(K.deepCopyFrom(r.value,r.parent,r.owner))}catch(e){return new W(e)}}},zi=class e extends Ri{constructor(e){super(),this.payload=e}payload;getPayload(){if(this.payload)return this.payload;throw Error(`Attempted to use an RPC StubHook after it was disposed.`)}getValue(){let e=this.getPayload();return{value:e.value,owner:e}}dup(){let t=this.getPayload();return new e(K.deepCopyFrom(t.value,void 0,t))}pull(){return this.getPayload()}ignoreUnhandledRejections(){this.payload&&this.payload.ignoreUnhandledRejections()}dispose(){this.payload&&=(this.payload.dispose(),void 0)}onBroken(e){this.payload&&this.payload.value instanceof Ai&&this.payload.value.onRpcBroken(e)}};function Bi(e){if(Symbol.dispose in e)try{e[Symbol.dispose]()}catch(e){Promise.reject(e)}}var Vi=class e extends Ri{static create(t,n){return typeof t!=`function`&&(n=void 0),new e(t,n)}constructor(e,t,n){super(),this.target=e,this.parent=t,n?n.refcount&&(this.refcount=n.refcount,++this.refcount.count):Symbol.dispose in e&&(this.refcount={count:1})}target;parent;refcount;getTarget(){if(this.target)return this.target;throw Error(`Attempted to use an RPC StubHook after it was disposed.`)}getValue(){return{value:this.getTarget(),owner:null}}dup(){return new e(this.getTarget(),this.parent,this)}pull(){let e=this.getTarget();return`then`in e?Promise.resolve(e).then(e=>K.fromAppReturn(e)):Promise.reject(Error(`Tried to resolve a non-promise stub.`))}ignoreUnhandledRejections(){}dispose(){this.target&&=(this.refcount&&--this.refcount.count==0&&Bi(this.target),void 0)}onBroken(e){let t=this.target;t&&`then`in t&&Promise.resolve(t).then(()=>{},e)}},Hi=class e extends wi{promise;resolution;constructor(e){super(),this.promise=e.then(e=>(this.resolution=e,e))}call(t,n){return n.ensureDeepCopied(),new e(this.promise.then(e=>e.call(t,n),e=>{throw n.dispose(),e}))}stream(e,t){return t.ensureDeepCopied(),{promise:this.promise.then(n=>n.stream(e,t).promise,e=>{throw t.dispose(),e})}}map(t,n,r){return new e(this.promise.then(e=>e.map(t,n,r),e=>{for(let e of n)e.dispose();throw e}))}get(t){return new e(this.promise.then(e=>e.get(t)))}dup(){return this.resolution?this.resolution.dup():new e(this.promise.then(e=>e.dup()))}pull(){return this.resolution?this.resolution.pull():this.promise.then(e=>e.pull())}ignoreUnhandledRejections(){this.resolution?this.resolution.ignoreUnhandledRejections():this.promise.then(e=>{e.ignoreUnhandledRejections()},e=>{})}dispose(){this.promise.then(e=>e.dispose(),()=>{})}onBroken(e){this.resolution?this.resolution.onBroken(e):this.promise.then(t=>{t.onBroken(e)},e)}},Ui={maxBigIntDigits:16384,maxDepth:256,maxMessageSize:33554432},Wi=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Gi=[`ArrayBuffer`,`DataView`,`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`BigInt64Array`,`BigUint64Array`,`Float32Array`,`Float64Array`];function Ki(e){return Gi.includes(e)}var qi={ArrayBuffer:void 0,DataView:void 0,Int8Array:void 0,Uint8Array:void 0,Uint8ClampedArray:void 0,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,BigInt64Array:8,BigUint64Array:8,Float32Array:4,Float64Array:8},Ji={ArrayBuffer:ArrayBuffer.prototype,DataView:DataView.prototype,Int8Array:Int8Array.prototype,Uint8ClampedArray:Uint8ClampedArray.prototype,Int16Array:Int16Array.prototype,Uint16Array:Uint16Array.prototype,Int32Array:Int32Array.prototype,Uint32Array:Uint32Array.prototype,BigInt64Array:BigInt64Array.prototype,BigUint64Array:BigUint64Array.prototype,Float32Array:Float32Array.prototype,Float64Array:Float64Array.prototype},Yi=new Map;for(let e of Object.keys(Ji))Yi.set(Ji[e],e);function Xi(e,t){if(t!==2&&t!==4&&t!==8)throw RangeError(`Unsupported element size: ${t}`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);for(let r=0;r<e.byteLength;r+=t)switch(t){case 2:n.setUint16(r,n.getUint16(r,!1),!0);break;case 4:n.setUint32(r,n.getUint32(r,!1),!0);break;case 8:n.setBigUint64(r,n.getBigUint64(r,!1),!0)}}var Zi=new class{exportStub(e){throw Error(`Cannot serialize RPC stubs without an RPC session.`)}exportPromise(e){throw Error(`Cannot serialize RPC stubs without an RPC session.`)}getImport(e){}unexport(e){}createPipe(e){throw Error(`Cannot create pipes without an RPC session.`)}onSendError(e){}};async function Qi(e,t){let n=await new Response(e).blob();return n.type===t?n:n.slice(0,n.size,t)}var $i={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError},ea=class e{exporter;source;encodingLevel;constructor(e,t,n){this.exporter=e,this.source=t,this.encodingLevel=n}static devaluate(t,n,r=Zi,i,a=`string`){let o=new e(r,i,a);try{return o.devaluateImpl(t,n,0)}catch(e){if(o.exports)try{r.unexport(o.exports)}catch{}throw e}}exports;devaluateImpl(e,t,n){if(n>=256)throw Error(`Serialization exceeded maximum allowed depth. (Does the message contain cycles?)`);switch(bi(e)){case`unsupported`:{let t;try{t=`Cannot serialize value: ${e}`}catch{t=`Cannot serialize value: (couldn't stringify value)`}throw TypeError(t)}case`primitive`:return typeof e==`number`&&!isFinite(e)?this.encodingLevel===`structuredClonable`?e:e===1/0?[`inf`]:e===-1/0?[`-inf`]:[`nan`]:e;case`object`:{let t=e,r={};for(let e in t)r[e]=this.devaluateImpl(t[e],t,n+1);return r}case`array`:{let t=e,r=t.length,i=Array(r);for(let e=0;e<r;e++)i[e]=this.devaluateImpl(t[e],t,n+1);return[i]}case`bigint`:return this.encodingLevel===`structuredClonable`?e:[`bigint`,e.toString()];case`date`:{if(this.encodingLevel===`structuredClonable`)return e;let t=e.getTime();return[`date`,Number.isNaN(t)?null:t]}case`bytes`:{let t=Yi.get(Object.getPrototypeOf(e)),n;if(t===`ArrayBuffer`)n=new Uint8Array(e);else if(t===void 0)n=e;else{let r=e;n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);let i=qi[t];!Wi&&i&&(n=n.slice(),Xi(n,i))}if(this.encodingLevel===`structuredClonable`||this.encodingLevel===`jsonCompatibleWithBytes`)return t===void 0?[`bytes`,n]:[`bytes`,n,t];let r;if(n.toBase64)r=n.toBase64({omitPadding:!0});else if(typeof Buffer<`u`)r=(n instanceof Buffer?n:Buffer.from(n.buffer,n.byteOffset,n.byteLength)).toString(`base64`);else{let e=``;for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);r=btoa(e)}return r=r.replace(/=+$/,``),t===void 0?[`bytes`,r]:[`bytes`,r,t]}case`url`:return[`url`,e.href];case`headers`:return[`headers`,[...e]];case`request`:{let t=e,r={};t.method!==`GET`&&(r.method=t.method);let i=[...t.headers];if(i.length>0&&(r.headers=i),t.body)r.body=this.devaluateImpl(t.body,t,n+1),r.duplex=t.duplex||`half`;else if(t.body===void 0&&![`GET`,`HEAD`,`OPTIONS`,`TRACE`,`DELETE`].includes(t.method)){let e=t.arrayBuffer(),n=new ReadableStream({async start(t){try{t.enqueue(new Uint8Array(await e)),t.close()}catch(e){t.error(e)}}}),i=U.createReadableStreamHook(n);r.body=[`readable`,this.exporter.createPipe(n,i)],r.duplex=t.duplex||`half`}t.cache&&t.cache!=="default"&&(r.cache=t.cache),t.redirect!==`follow`&&(r.redirect=t.redirect),t.integrity&&(r.integrity=t.integrity),t.mode&&t.mode!==`cors`&&(r.mode=t.mode),t.credentials&&t.credentials!==`same-origin`&&(r.credentials=t.credentials),t.referrer&&t.referrer!==`about:client`&&(r.referrer=t.referrer),t.referrerPolicy&&(r.referrerPolicy=t.referrerPolicy),t.keepalive&&(r.keepalive=t.keepalive);let a=t;return a.cf&&(r.cf=a.cf),a.encodeResponseBody&&a.encodeResponseBody!==`automatic`&&(r.encodeResponseBody=a.encodeResponseBody),[`request`,t.url,r]}case`response`:{let t=e,r=this.devaluateImpl(t.body,t,n+1),i={};t.status!==200&&(i.status=t.status),t.statusText&&(i.statusText=t.statusText);let a=[...t.headers];a.length>0&&(i.headers=a);let o=t;if(o.cf&&(i.cf=o.cf),o.encodeBody&&o.encodeBody!==`automatic`&&(i.encodeBody=o.encodeBody),o.webSocket)throw TypeError(`Can't serialize a Response containing a webSocket.`);return[`response`,r,i]}case`blob`:{let t=e,n=t.stream(),r=U.createReadableStreamHook(n),i=this.exporter.createPipe(n,r);return[`blob`,t.type,[`readable`,i]]}case`error`:{let t=e,r=this.exporter.onSendError(t);r&&(t=r);let i=t,a,o=(e,r)=>{let i=this.exports?.length??0;try{let i=this.devaluateImpl(r,t,n+1);a||={},a[e]=i}catch{if(this.exports&&this.exports.length>i){let e=this.exports.splice(i);try{this.exporter.unexport(e)}catch{}}}};for(let e of Object.keys(t))e!==`name`&&e!==`message`&&e!==`stack`&&o(e,i[e]);`cause`in t&&o(`cause`,i.cause),t instanceof AggregateError&&o(`errors`,t.errors);let s=[`error`,t.name,t.message];return a?(s.push(r&&r.stack?r.stack:null),s.push(a)):r&&r.stack&&s.push(r.stack),s}case`undefined`:return this.encodingLevel===`structuredClonable`?void 0:[`undefined`];case`stub`:case`rpc-promise`:{if(!this.source)throw Error(`Can't serialize RPC stubs in this context.`);let{hook:t,pathIfPromise:n}=Fi(e),r=this.exporter.getImport(t);return r===void 0?(t=n?t.get(n):t.dup(),this.devaluateHook(n?`promise`:`export`,t)):n?n.length>0?[`pipeline`,r,n]:[`pipeline`,r]:[`import`,r]}case`function`:case`rpc-target`:{if(!this.source)throw Error(`Can't serialize RPC stubs in this context.`);let n=this.source.getHookForRpcTarget(e,t);return this.devaluateHook(`export`,n)}case`rpc-thenable`:{if(!this.source)throw Error(`Can't serialize RPC stubs in this context.`);let n=this.source.getHookForRpcTarget(e,t);return this.devaluateHook(`promise`,n)}case`writable`:{if(!this.source)throw Error(`Can't serialize WritableStream in this context.`);let n=this.source.getHookForWritableStream(e,t);return this.devaluateHook(`writable`,n)}case`readable`:{if(!this.source)throw Error(`Can't serialize ReadableStream in this context.`);let n=e,r=this.source.getHookForReadableStream(n,t);return[`readable`,this.exporter.createPipe(n,r)]}default:throw Error(`unreachable`)}}devaluateHook(e,t){this.exports||=[];let n=e===`promise`?this.exporter.exportPromise(t):this.exporter.exportStub(t);return this.exports.push(n),[e,n]}};new class{importStub(e){throw Error(`Cannot deserialize RPC stubs without an RPC session.`)}importPromise(e){throw Error(`Cannot deserialize RPC stubs without an RPC session.`)}getExport(e){}getPipeReadable(e){throw Error(`Cannot retrieve pipe readable without an RPC session.`)}getLimits(){return Ui}};function ta(e,t){return new G(new Hi(new Response(t).arrayBuffer().then(t=>{let n=new Uint8Array(t),r=new Request(e,{body:n});return new zi(K.fromAppReturn(r))})),[])}function na(e,t){return new G(new Hi(Qi(e,t).then(e=>new zi(K.fromAppReturn(e)))),[])}var ra=class e{importer;encodingLevel;limits;constructor(e,t=`string`){this.importer=e,this.encodingLevel=t,this.limits=e.getLimits()}hooks=[];promises=[];evaluate(e){return this.evaluateWithDepth(e,0)}evaluateWithDepth(e,t){let n=K.forEvaluate(this.hooks,this.promises);try{return n.value=this.evaluateImpl(e,n,`value`,t),n}catch(e){throw n.dispose(),e}}evaluateCopy(e){return this.evaluate(structuredClone(e))}evaluateImpl(t,n,r,i){let a=this.limits.maxDepth;if(i>=a)throw TypeError(`Deserialization exceeded maximum allowed message depth of ${a}.`);if(this.encodingLevel===`structuredClonable`&&(t instanceof Date||typeof t==`bigint`))return t;if(t instanceof Array){if(t.length==1&&t[0]instanceof Array){let e=t[0];for(let t=0;t<e.length;t++)e[t]=this.evaluateImpl(e[t],e,t,i+1);return e}switch(t[0]){case`bigint`:if(typeof t[1]==`string`){let e=t[1],n=this.limits.maxBigIntDigits;if(e.length>n)throw TypeError(`Deserialized bigint exceeds maximum length of ${n} digits.`);return BigInt(e)}break;case`date`:if(t[1]===null)return new Date(NaN);if(typeof t[1]==`number`)return new Date(t[1]);break;case`bytes`:{let e;if(t[1]instanceof Uint8Array)e=t[1];else if(typeof t[1]==`string`){if(typeof Buffer<`u`)e=Buffer.from(t[1],`base64`);else if(Uint8Array.fromBase64)e=Uint8Array.fromBase64(t[1]);else{let n=atob(t[1]),r=n.length;e=new Uint8Array(r);for(let t=0;t<r;t++)e[t]=n.charCodeAt(t)}}else break;if(t.length===2)return e;if(typeof t[2]!=`string`)throw TypeError(`Unknown bytes type marker type: ${typeof t[2]}`);if(!Ki(t[2])){let e=t[2].slice(0,64);throw TypeError(`Unknown bytes type marker: ${e}`)}let n=t[2],r=qi[n];if(r!==void 0&&e.byteLength%r!==0)throw TypeError(`Invalid byte length ${e.byteLength} for ${n}; expected a multiple of ${r}`);let i=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);switch(!Wi&&r!==void 0&&Xi(new Uint8Array(i),r),n){case`ArrayBuffer`:return i;case`DataView`:return new DataView(i);case`Int8Array`:return new Int8Array(i);case`Uint8Array`:return new Uint8Array(i);case`Uint8ClampedArray`:return new Uint8ClampedArray(i);case`Int16Array`:return new Int16Array(i);case`Uint16Array`:return new Uint16Array(i);case`Int32Array`:return new Int32Array(i);case`Uint32Array`:return new Uint32Array(i);case`BigInt64Array`:return new BigInt64Array(i);case`BigUint64Array`:return new BigUint64Array(i);case`Float32Array`:return new Float32Array(i);case`Float64Array`:return new Float64Array(i)}}case`error`:if(t.length>=3&&typeof t[1]==`string`&&typeof t[2]==`string`){let e=$i[t[1]]||Error,n=e===AggregateError?new e([],t[2]):new e(t[2]);if(typeof t[3]==`string`&&(n.stack=t[3]),t.length>=5){let e=t[4];if(!e||typeof e!=`object`||Array.isArray(e))break;let r=n,a=e;for(let e of Object.keys(a))if(e!==`name`&&e!==`message`&&e!==`stack`){if(e in Object.prototype||e===`toJSON`){this.evaluateImpl(a[e],n,e,i+1);continue}r[e]=this.evaluateImpl(a[e],n,e,i+1)}}return n}break;case`undefined`:if(t.length===1)return;break;case`inf`:return 1/0;case`-inf`:return-1/0;case`nan`:return NaN;case`url`:if(t.length===2&&typeof t[1]==`string`)return new URL(t[1]);break;case`headers`:if(t.length===2&&t[1]instanceof Array)return new Headers(t[1]);break;case`request`:{if(t.length!==3||typeof t[1]!=`string`)break;let e=t[1],a=t[2];if(typeof a!=`object`||!a)break;if(a.body&&(a.body=this.evaluateImpl(a.body,a,`body`,i+1),!(a.body===null||typeof a.body==`string`||a.body instanceof Uint8Array||a.body instanceof ReadableStream)))throw TypeError(`Request body must be of type ReadableStream.`);if(a.signal&&(a.signal=this.evaluateImpl(a.signal,a,`signal`,i+1),!(a.signal instanceof AbortSignal)))throw TypeError(`Request siganl must be of type AbortSignal.`);if(a.headers&&!(a.headers instanceof Array))throw TypeError(`Request headers must be serialized as an array of pairs.`);let o=new Request(e,a);if(a.body instanceof ReadableStream&&o.body===void 0){let e=ta(o,a.body);return this.promises.push({promise:e,parent:n,property:r}),e}return o}case`response`:{if(t.length!==3)break;let e=this.evaluateImpl(t[1],n,r,i+1);if(!(e===null||typeof e==`string`||e instanceof Uint8Array||e instanceof ReadableStream))throw TypeError(`Response body must be of type ReadableStream.`);let a=t[2];if(typeof a!=`object`||!a)break;if(a.webSocket)throw TypeError(`Can't deserialize a Response containing a webSocket.`);if(a.headers&&!(a.headers instanceof Array))throw TypeError(`Request headers must be serialized as an array of pairs.`);return new Response(e,a)}case`blob`:{if(t.length!==3||typeof t[1]!=`string`)break;let e=t[1],a=this.evaluateImpl(t[2],n,r,i+1);if(!(a instanceof ReadableStream))throw TypeError(`Blob content must be serialized as a ReadableStream.`);let o=na(a,e);return this.promises.push({promise:o,parent:n,property:r}),o}case`import`:case`pipeline`:{if(t.length<2||t.length>4||typeof t[1]!=`number`)break;let a=this.importer.getExport(t[1]);if(!a)throw Error(`no such entry on exports table: ${t[1]}`);let o=t[0]==`pipeline`,s=e=>{if(o){let t=new G(e,[]);return this.promises.push({promise:t,parent:n,property:r}),t}return this.hooks.push(e),new G(e,[])};if(t.length==2)return s(o?a.get([]):a.dup());let c=t[2];if(!(c instanceof Array)||!c.every(e=>typeof e==`string`||typeof e==`number`))break;if(t.length==3)return s(a.get(c));let l=t[3];if(!(l instanceof Array))break;return l=new e(this.importer).evaluateWithDepth([l],i),s(a.call(c,l))}case`remap`:{if(t.length!==5||typeof t[1]!=`number`||!(t[2]instanceof Array)||!(t[3]instanceof Array)||!(t[4]instanceof Array))break;let e=this.importer.getExport(t[1]);if(!e)throw Error(`no such entry on exports table: ${t[1]}`);let i=t[2];if(!i.every(e=>typeof e==`string`||typeof e==`number`))break;let a=t[3].map(e=>{if(!(e instanceof Array)||e.length!==2||e[0]!==`import`&&e[0]!==`export`||typeof e[1]!=`number`)throw TypeError(`unknown map capture: ${JSON.stringify(e)}`);if(e[0]===`export`)return this.importer.importStub(e[1]);{let t=this.importer.getExport(e[1]);if(!t)throw Error(`no such entry on exports table: ${e[1]}`);return t.dup()}}),o=t[4],s=new G(e.map(i,a,o),[]);return this.promises.push({promise:s,parent:n,property:r}),s}case`export`:case`promise`:if(typeof t[1]==`number`){if(t[0]==`promise`){let e=new G(this.importer.importPromise(t[1]),[]);return this.promises.push({parent:n,property:r,promise:e}),e}{let e=this.importer.importStub(t[1]);return this.hooks.push(e),new Ai(e)}}break;case`writable`:if(typeof t[1]==`number`){let e=this.importer.importStub(t[1]),n=U.createWritableStreamFromHook(e);return this.hooks.push(e),n}break;case`readable`:if(typeof t[1]==`number`){let e=this.importer.getPipeReadable(t[1]),n=U.createReadableStreamHook(e);return this.hooks.push(n),e}}throw TypeError(`unknown special value: ${JSON.stringify(t)}`)}if(t instanceof Object){let e=t;for(let t in e)t in Object.prototype||t===`toJSON`?(this.evaluateImpl(e[t],e,t,i+1),delete e[t]):e[t]=this.evaluateImpl(e[t],e,t,i+1);return e}return t}},ia=16,aa=8,oa=16,sa=64;function ca(e){return 2+e.length*3}function la(e,t,n=0){if(n>=sa)return aa;switch(typeof e){case`string`:return ca(e);case`number`:return 16;case`bigint`:return 16;case`boolean`:return 8;case`undefined`:return 16;case`object`:{if(e===null)return 8;if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)return oa+e.byteLength;if(typeof Blob<`u`&&e instanceof Blob)return oa+e.size;if(e instanceof Date)return 16;if(t??=new WeakSet,t.has(e))return aa;if(t.add(e),e instanceof Array){let r=ia;for(let i of e)r+=aa+la(i,t,n+1);return r}if(e instanceof Error){let r=ia+ca(e.name)+ca(e.message)+ca(e.stack??``);for(let i of Object.keys(e))r+=aa+ca(i)+la(e[i],t,n+1);return r}let r=ia;for(let i of Object.keys(e))r+=aa+ca(i)+la(e[i],t,n+1);return r}default:return 16}}var ua=class{session;importId;constructor(e,t,n){this.session=e,this.importId=t,n&&(this.activePull=Promise.withResolvers())}localRefcount=0;remoteRefcount=1;activePull;resolution;onBrokenRegistrations;resolve(e){if(this.localRefcount==0){e.dispose();return}if(this.resolution=e,this.sendRelease(),this.onBrokenRegistrations){for(let t of this.onBrokenRegistrations){let n=this.session.onBrokenCallbacks[t],r=this.session.onBrokenCallbacks.length;e.onBroken(n),this.session.onBrokenCallbacks[r]===n?delete this.session.onBrokenCallbacks[r]:delete this.session.onBrokenCallbacks[t]}this.onBrokenRegistrations=void 0}this.activePull&&=(this.activePull.resolve(),void 0)}async awaitResolution(){return this.activePull||=(this.session.sendPull(this.importId),Promise.withResolvers()),await this.activePull.promise,this.resolution.pull()}dispose(){this.resolution?this.resolution.dispose():(this.abort(Error(`RPC was canceled because the RpcPromise was disposed.`)),this.sendRelease())}abort(e){if(!this.resolution){if(this.resolution=new W(e),this.activePull&&=(this.activePull.reject(e),void 0),this.onBrokenRegistrations)for(let e of this.onBrokenRegistrations)delete this.session.onBrokenCallbacks[e];this.onBrokenRegistrations=void 0}}onBroken(e){if(this.resolution)this.resolution.onBroken(e);else{let t=this.session.onBrokenCallbacks.length;this.session.onBrokenCallbacks.push(e),this.onBrokenRegistrations||=[],this.onBrokenRegistrations.push(t)}}sendRelease(){this.remoteRefcount>0&&(this.session.sendRelease(this.importId,this.remoteRefcount),this.remoteRefcount=0)}},da=class e extends wi{isPromise;entry;constructor(e,t){super(),this.isPromise=e,++t.localRefcount,this.entry=t}collectPath(e){return this}getEntry(){if(this.entry)return this.entry;throw Error(`This RpcImportHook was already disposed.`)}getEntryTakingOwnership(e){try{return this.getEntry()}catch(t){throw e(),t}}call(e,t){let n=this.getEntryTakingOwnership(()=>t.dispose());return n.resolution?n.resolution.call(e,t):n.session.sendCall(n.importId,e,t)}stream(e,t){let n=this.getEntryTakingOwnership(()=>t.dispose());return n.resolution?n.resolution.stream(e,t):n.session.sendStream(n.importId,e,t)}map(e,t,n){let r=this.getEntryTakingOwnership(()=>{for(let e of t)e.dispose()});return r.resolution?r.resolution.map(e,t,n):r.session.sendMap(r.importId,e,t,n)}get(e){let t=this.getEntry();return t.resolution?t.resolution.get(e):t.session.sendCall(t.importId,e)}dup(){return new e(!1,this.getEntry())}pull(){let e=this.getEntry();if(!this.isPromise)throw Error(`Can't pull this hook because it's not a promise hook.`);return e.resolution?e.resolution.pull():e.awaitResolution()}ignoreUnhandledRejections(){}dispose(){let e=this.entry;this.entry=void 0,e&&--e.localRefcount===0&&e.dispose()}onBroken(e){this.entry&&this.entry.onBroken(e)}},fa=class extends da{session;constructor(e){super(!1,e),this.session=e.session}dispose(){if(this.session){let e=this.session;this.session=void 0,e.shutdown()}}},pa=class{transport;options;exports=[];reverseExports=new Map;imports=[];abortReason;cancelReadLoop;nextExportId=-1;onBatchDone;pullCount=0;onBrokenCallbacks=[];encodingLevel;limits;constructor(e,t,n){this.transport=e,this.options=n;let r=`string`;if(`encodingLevel`in e){let t=e.encodingLevel;if(t!==void 0){if(t!==`string`&&t!==`jsonCompatible`&&t!==`jsonCompatibleWithBytes`&&t!==`structuredClonable`)throw TypeError(`Unknown transport encodingLevel: ${String(t)}`);r=t}}this.encodingLevel=r,this.limits={...Ui,...n.limits},this.exports.push({hook:t,refcount:1}),this.imports.push(new ua(this,0,!1)),this.readLoop().catch(e=>this.abort(e))}getMainImport(){return new fa(this.imports[0])}shutdown(){this.abort(Error(`RPC session was shut down by disposing the main stub`),!1)}exportStub(e){if(this.abortReason)throw this.abortReason;let t=this.reverseExports.get(e);if(t!==void 0)return++this.exports[t].refcount,t;{let t=this.nextExportId--;return this.exports[t]={hook:e,refcount:1},this.reverseExports.set(e,t),this.watchExport(t,e),t}}exportPromise(e){if(this.abortReason)throw this.abortReason;let t=this.nextExportId--;return this.exports[t]={hook:e,refcount:1},this.reverseExports.set(e,t),this.ensureResolvingExport(t),t}unexport(e){for(let t of e)this.releaseExport(t,1)}watchExport(e,t){t.onBroken(n=>{queueMicrotask(()=>{if(this.abortReason===void 0&&this.exports[e]?.hook===t)try{this.send([`reject`,e,ea.devaluate(n,void 0,this,void 0,this.encodingLevel)])}catch(e){this.abort(e)}})})}releaseExport(e,t){let n=this.exports[e];if(!n)throw Error(`no such export ID: ${e}`);if(n.refcount<t)throw Error(`refcount would go negative: ${n.refcount} < ${t}`);n.refcount-=t,n.refcount===0&&(delete this.exports[e],this.reverseExports.delete(n.hook),n.hook.dispose())}onSendError(e){if(this.options.onSendError)return this.options.onSendError(e)}ensureResolvingExport(e){let t=this.exports[e];if(!t)throw Error(`no such export ID: ${e}`);if(!t.pull){let n=async()=>{let e=t.hook;for(;;){let t=await e.pull();if(t.value instanceof Ai){let{hook:n,pathIfPromise:r}=Fi(t.value);if(r&&r.length==0&&this.getImport(e)===void 0){e=n;continue}}return t}},r=t.autoRelease;++this.pullCount,t.pull=n().then(t=>{let n=ea.devaluate(t.value,void 0,this,t,this.encodingLevel);this.send([`resolve`,e,n]),r&&this.releaseExport(e,1)},t=>{this.send([`reject`,e,ea.devaluate(t,void 0,this,void 0,this.encodingLevel)]),r&&this.releaseExport(e,1)}).catch(t=>{try{this.send([`reject`,e,ea.devaluate(t,void 0,this,void 0,this.encodingLevel)]),r&&this.releaseExport(e,1)}catch(e){this.abort(e)}}).finally(()=>{--this.pullCount===0&&this.onBatchDone&&this.onBatchDone.resolve()})}}getImport(e){if(e instanceof da&&e.entry&&e.entry.session===this)return e.entry.importId}importStub(e){if(this.abortReason)throw this.abortReason;let t=this.imports[e];return t||(t=new ua(this,e,!1),this.imports[e]=t),new da(!1,t)}importPromise(e){if(this.abortReason)throw this.abortReason;if(this.imports[e])return new W(Error(`Bug in RPC system: The peer sent a promise reusing an existing export ID.`));let t=new ua(this,e,!0);return this.imports[e]=t,new da(!0,t)}getExport(e){return this.exports[e]?.hook}getPipeReadable(e){let t=this.exports[e];if(!t||!t.pipeReadable)throw Error(`Export ${e} is not a pipe or its readable end was already consumed.`);let n=t.pipeReadable;return t.pipeReadable=void 0,n}getLimits(){return this.limits}createPipe(e,t){if(this.abortReason)throw this.abortReason;this.send([`pipe`]);let n=this.imports.length,r=new ua(this,n,!1);this.imports.push(r);let i=new da(!1,r),a=U.createWritableStreamFromHook(i);return e.pipeTo(a).catch(()=>{}).finally(()=>t.dispose()),n}send(e){if(this.abortReason!==void 0)return 0;if(this.encodingLevel===`string`){let t;try{t=JSON.stringify(e)}catch(e){try{this.abort(e)}catch{}throw e}try{let e=this.transport.send(t);e!==void 0&&typeof e.catch==`function`&&e.catch(e=>this.abort(e,!1))}catch(e){queueMicrotask(()=>this.abort(e,!1))}return t.length}try{let t=this.transport.send(e);if(typeof t==`number`)return t;let n=t;n&&typeof n.then==`function`&&Promise.resolve(n).catch(e=>this.abort(e,!1));return}catch(e){queueMicrotask(()=>this.abort(e,!1));return}}sendCall(e,t,n){if(this.abortReason)throw n?.dispose(),this.abortReason;let r=[`pipeline`,e,t];if(n){let e;try{e=ea.devaluate(n.value,void 0,this,n,this.encodingLevel)}catch(e){throw n.dispose(),e}r.push(e[0])}this.send([`push`,r]);let i=new ua(this,this.imports.length,!1);return this.imports.push(i),new da(!0,i)}sendStream(e,t,n){if(this.abortReason)throw n.dispose(),this.abortReason;let r=[`pipeline`,e,t],i;try{i=ea.devaluate(n.value,void 0,this,n,this.encodingLevel)}catch(e){throw n.dispose(),e}r.push(i[0]);let a=[`stream`,r],o=this.send(a);o===void 0&&(o=la(a));let s=this.imports.length,c=new ua(this,s,!0);return c.remoteRefcount=0,c.localRefcount=1,this.imports.push(c),{promise:c.awaitResolution().then(e=>{e.dispose(),delete this.imports[s]},e=>{throw delete this.imports[s],e}),size:o}}sendMap(e,t,n,r){if(this.abortReason){for(let e of n)e.dispose();throw this.abortReason}let i=[`remap`,e,t,n.map(e=>{let t=this.getImport(e);return t===void 0?[`export`,this.exportStub(e)]:[`import`,t]}),r];this.send([`push`,i]);let a=new ua(this,this.imports.length,!1);return this.imports.push(a),new da(!0,a)}sendPull(e){if(this.abortReason)throw this.abortReason;this.send([`pull`,e])}sendRelease(e,t){this.abortReason||(this.send([`release`,e,t]),delete this.imports[e])}abort(e,t=!0){if(this.abortReason===void 0){if(this.cancelReadLoop?.(e),this.cancelReadLoop=void 0,t)try{let t=[`abort`,ea.devaluate(e,void 0,this,void 0,this.encodingLevel)];if(this.encodingLevel===`string`){let e=this.transport.send(JSON.stringify(t));e!==void 0&&typeof e.catch==`function`&&e.catch(e=>{})}else{let e=this.transport.send(t);e&&typeof e.then==`function`&&Promise.resolve(e).catch(e=>{})}}catch{}if(e===void 0&&(e=`undefined`),this.abortReason=e,this.onBatchDone&&this.onBatchDone.reject(e),this.transport.abort)try{this.transport.abort(e)}catch(e){Promise.resolve(e)}for(let t of Object.values(this.onBrokenCallbacks))try{t(e)}catch(e){Promise.resolve(e)}for(let t in this.imports)this.imports[t].abort(e);for(let e in this.exports)this.exports[e].hook.dispose()}}async readLoop(){for(;!this.abortReason;){let e=Promise.withResolvers();this.cancelReadLoop=e.reject;let t;try{t=await Promise.race([this.transport.receive(),e.promise])}finally{this.cancelReadLoop===e.reject&&(this.cancelReadLoop=void 0)}if(this.encodingLevel===`string`&&t.length>this.limits.maxMessageSize)throw TypeError(`Incoming message exceeds maximum size of ${this.limits.maxMessageSize} UTF-16 code units.`);if(this.abortReason)break;let n=this.encodingLevel===`string`?JSON.parse(t):t;if(n instanceof Array)switch(n[0]){case`push`:if(n.length>1){let e=new zi(new ra(this,this.encodingLevel).evaluate(n[1]));e.ignoreUnhandledRejections(),this.exports.push({hook:e,refcount:1});continue}break;case`stream`:if(n.length>1){let e=new zi(new ra(this,this.encodingLevel).evaluate(n[1]));e.ignoreUnhandledRejections();let t=this.exports.length;this.exports.push({hook:e,refcount:1,autoRelease:!0}),this.ensureResolvingExport(t);continue}break;case`pipe`:{let{readable:e,writable:t}=new TransformStream,n=U.createWritableStreamHook(t),r=this.exports.length;this.exports.push({hook:n,refcount:1,pipeReadable:e}),this.watchExport(r,n);continue}case`pull`:{let e=n[1];if(typeof e==`number`){this.ensureResolvingExport(e);continue}break}case`resolve`:case`reject`:{let e=n[1];if(typeof e==`number`&&n.length>2){let t=this.imports[e];if(t){if(n[0]==`resolve`)t.resolve(new zi(new ra(this,this.encodingLevel).evaluate(n[2])));else{let e=new ra(this,this.encodingLevel).evaluate(n[2]);e.dispose(),t.resolve(new W(e.value))}}else n[0]==`resolve`&&new ra(this,this.encodingLevel).evaluate(n[2]).dispose();continue}break}case`release`:{let e=n[1],t=n[2];if(typeof e==`number`&&typeof t==`number`){this.releaseExport(e,t);continue}break}case`abort`:{let e=new ra(this,this.encodingLevel).evaluate(n[1]);e.dispose(),this.abort(e.value,!1);break}}throw Error(`bad RPC message: ${JSON.stringify(n)}`)}}async drain(){if(this.abortReason)throw this.abortReason;if(this.pullCount>0){let{promise:e,resolve:t,reject:n}=Promise.withResolvers();this.onBatchDone={resolve:t,reject:n},await e}}getStats(){let e={imports:0,exports:0};for(let t in this.imports)++e.imports;for(let t in this.exports)++e.exports;return e}},ma=class{#e;#t;constructor(e,t,n={}){let r;r=t?new zi(K.fromAppReturn(t)):new W(Error(`This connection has no main object.`)),this.#e=new pa(e,r,n),this.#t=new Ai(this.#e.getMainImport())}getRemoteMain(){return this.#t}getStats(){return this.#e.getStats()}drain(){return this.#e.drain()}};function ha(e,t,n){return new ma(new ga(e),t,n).getRemoteMain()}var ga=class{encodingLevel=`structuredClonable`;constructor(e){this.#e=e,e.start(),e.addEventListener(`message`,e=>{this.#i||(e.data===null?this.#a(Error(`Peer closed MessagePort connection.`)):this.#t?(this.#t(e.data),this.#t=void 0,this.#n=void 0):this.#r.push(e.data))}),e.addEventListener(`messageerror`,e=>{this.#a(Error(`MessagePort message error.`))})}#e;#t;#n;#r=[];#i;send(e){if(this.#i)throw this.#i;this.#e.postMessage(e)}async receive(){if(this.#r.length>0)return this.#r.shift();if(this.#i)throw this.#i;return new Promise((e,t)=>{this.#t=e,this.#n=t})}abort(e){try{this.#e.postMessage(null)}catch{}this.#e.close(),this.#i||=e}#a(e){this.#i||(this.#i=e,this.#n&&=(this.#n(e),this.#t=void 0,void 0))}},_a,va=class{context;captureMap=new Map;instructions=[];constructor(e,t){this.context=_a?{parent:_a,captures:[],subject:_a.capture(e),path:t}:{parent:void 0,captures:[],subject:e,path:t},_a=this}unregister(){_a=this.context.parent}makeInput(){return new ba(this,0)}makeOutput(e){let t;try{t=ea.devaluate(e.value,void 0,this,e)}finally{e.dispose()}return this.instructions.push(t),this.context.parent?(this.context.parent.instructions.push([`remap`,this.context.subject,this.context.path,this.context.captures.map(e=>[`import`,e]),this.instructions]),new ba(this.context.parent,this.context.parent.instructions.length)):this.context.subject.map(this.context.path,this.context.captures,this.instructions)}pushCall(e,t,n){let r=ea.devaluate(n.value,void 0,this,n);r=r[0];let i=this.capture(e.dup());return this.instructions.push([`pipeline`,i,t,r]),new ba(this,this.instructions.length)}pushGet(e,t){let n=this.capture(e.dup());return this.instructions.push([`pipeline`,n,t]),new ba(this,this.instructions.length)}capture(e){if(e instanceof ba&&e.mapper===this)return e.idx;let t=this.captureMap.get(e);if(t===void 0){if(this.context.parent){let t=this.context.parent.capture(e);this.context.captures.push(t)}else this.context.captures.push(e);t=-this.context.captures.length,this.captureMap.set(e,t)}return t}exportStub(e){throw Error(`Can't construct an RpcTarget or RPC callback inside a mapper function. Try creating a new RpcStub outside the callback first, then using it inside the callback.`)}exportPromise(e){return this.exportStub(e)}getImport(e){return this.capture(e)}unexport(e){}createPipe(e){throw Error(`Cannot send ReadableStream inside a mapper function.`)}onSendError(e){}};Si.sendMap=(e,t,n)=>{let r=new va(e,t),i;try{i=K.fromAppReturn(Di(r.pushCall.bind(r),()=>n(new G(r.makeInput(),[]))))}finally{r.unregister()}if(i instanceof Promise)throw i.catch(e=>{}),Error(`RPC map() callbacks cannot be async.`);return new G(r.makeOutput(i),[])};function ya(){throw Error(`Attempted to use an abstract placeholder from a mapper function. Please make sure your map function has no side effects.`)}var ba=class extends wi{mapper;idx;constructor(e,t){super(),this.mapper=e,this.idx=t}dup(){return this}dispose(){}get(e){if(e.length==0)return this;if(_a)return _a.pushGet(this,e);ya()}call(e,t){t.dispose(),ya()}map(e,t,n){for(let e of t)e.dispose();ya()}pull(){ya()}ignoreUnhandledRejections(){}onBroken(e){ya()}},xa=class{captures;variables;constructor(e,t){this.captures=e,this.variables=[t]}dispose(){for(let e of this.variables)e.dispose()}apply(e){try{if(e.length<1)throw Error(`Invalid empty mapper function.`);for(let t of e.slice(0,-1)){let e=new ra(this).evaluateCopy(t);if(e.value instanceof Ai){let t=Ni(e.value);if(t){this.variables.push(t);continue}}this.variables.push(new zi(e))}return new ra(this).evaluateCopy(e[e.length-1])}finally{for(let e of this.variables)e.dispose()}}importStub(e){throw Error(`A mapper function cannot refer to exports.`)}importPromise(e){return this.importStub(e)}getExport(e){return e<0?this.captures[-e-1]:this.variables[e]}getPipeReadable(e){throw Error(`A mapper function cannot use pipe readables.`)}getLimits(){return Ui}};function Sa(e,t,n,r,i){let a=new xa(r,new zi(K.deepCopyFrom(e,t,n)));try{return a.apply(i)}finally{a.dispose()}}Si.applyMap=(e,t,n,r,i)=>{try{let a;if(e instanceof G)throw Error(`applyMap() can't be called on RpcPromise`);if(e instanceof Array){let t=[];try{for(let a of e)t.push(Sa(a,e,n,r,i))}catch(e){for(let e of t)e.dispose();throw e}a=K.fromArray(t)}else a=e==null?K.fromAppReturn(e):Sa(e,t,n,r,i);return new zi(a)}finally{for(let e of r)e.dispose()}};var Ca=class e extends wi{state;static create(t){let n=t.getWriter();return new e({refcount:1,writer:n,closed:!1})}constructor(e,t){super(),this.state=e,t&&++e.refcount}getState(){if(this.state)return this.state;throw Error(`Attempted to use a WritableStreamStubHook after it was disposed.`)}call(e,t){try{let n=this.getState();if(e.length!==1||typeof e[0]!=`string`)throw Error(`WritableStream stub only supports direct method calls`);let r=e[0];if(r!==`write`&&r!==`close`&&r!==`abort`)throw Error(`Unknown WritableStream method: ${r}`);return(r===`close`||r===`abort`)&&(n.closed=!0),new Hi((r===`write`?t.deliverStreamWrite(n.writer):t.deliverCall(n.writer[r],n.writer)).then(e=>new zi(e)))}catch(e){return t.dispose(),new W(e)}}map(e,t,n){for(let e of t)e.dispose();return new W(Error(`Cannot use map() on a WritableStream`))}get(e){return new W(Error(`Cannot access properties on a WritableStream stub`))}dup(){let t=this.getState();return new e(t,this)}pull(){return Promise.reject(Error(`Cannot pull a WritableStream stub`))}ignoreUnhandledRejections(){}dispose(){let e=this.state;this.state=void 0,e&&--e.refcount===0&&(e.closed||e.writer.abort(Error(`WritableStream RPC stub was disposed without calling close()`)).catch(()=>{}),e.writer.releaseLock())}onBroken(e){this.getState().writer.closed.then(void 0,e)}},wa=262144,Ta=1073741824,Ea=65536,Da=2,Oa=1.25,ka=.9,Aa=3,ja=class{now;window=wa;bytesInFlight=0;inStartupPhase=!0;delivered=0;deliveredTime=0;firstAckTime=0;firstAckDelivered=0;minRtt=1/0;roundsWithoutIncrease=0;lastRoundWindow=0;roundStartTime=0;constructor(e){this.now=e}onSend(e){this.bytesInFlight+=e;let t={sentTime:this.now(),size:e,deliveredAtSend:this.delivered,deliveredTimeAtSend:this.deliveredTime,windowAtSend:this.window,windowFullAtSend:this.bytesInFlight>=this.window};return{token:t,shouldBlock:t.windowFullAtSend}}onError(e){this.bytesInFlight-=e.size}onAck(e){let t=this.now();this.delivered+=e.size,this.deliveredTime=t,this.bytesInFlight-=e.size;let n=t-e.sentTime;if(this.minRtt=Math.min(this.minRtt,n),this.firstAckTime===0)this.firstAckTime=t,this.firstAckDelivered=this.delivered;else{let n,r;e.deliveredTimeAtSend===0?(n=this.firstAckTime,r=this.firstAckDelivered):(n=e.deliveredTimeAtSend,r=e.deliveredAtSend);let i=t-n,a=(this.delivered-r)/i,o=this.inStartupPhase?Da:Oa,s=a*this.minRtt*o;s=Math.min(s,e.windowAtSend*o),s=e.windowFullAtSend?Math.max(s,e.windowAtSend*ka):Math.max(s,this.window),this.window=Math.max(Math.min(s,Ta),Ea),this.inStartupPhase&&e.sentTime>=this.roundStartTime&&(this.window>this.lastRoundWindow*Oa?this.roundsWithoutIncrease=0:++this.roundsWithoutIncrease>=Aa&&(this.inStartupPhase=!1),this.roundStartTime=t,this.lastRoundWindow=this.window)}return this.bytesInFlight<this.window}};function Ma(e){let t,n=!1,r=new ja(()=>performance.now()),i,a,o=()=>{n||(n=!0,e.dispose())};return new WritableStream({start(n){e.onBroken(e=>{t===void 0&&(t=e,n.error(e),o()),a&&=(a(e),i=void 0,void 0)})},write(n,s){if(t!==void 0)throw t;let c=K.fromAppParams([n]),{promise:l,size:u}=e.stream([`write`],c);if(u===void 0)return l.catch(e=>{throw t===void 0&&(t=e),e});{let{token:e,shouldBlock:n}=r.onSend(u);if(l.then(()=>{r.onAck(e)&&i&&(i(),i=void 0,a=void 0)},n=>{r.onError(e),t===void 0&&(t=n,s.error(n),o()),a&&=(a(n),i=void 0,void 0)}),n)return new Promise((e,t)=>{i=e,a=t})}},async close(){if(t!==void 0)throw o(),t;let{promise:n}=e.stream([`close`],K.fromAppParams([]));try{await n}catch(e){throw t??e}finally{o()}},abort(n){if(t!==void 0)return;t=n??Error(`WritableStream was aborted`),a&&=(a(t),i=void 0,void 0);let{promise:r}=e.stream([`abort`],K.fromAppParams([n]));r.then(()=>o(),()=>o())}})}var Na=class e extends wi{state;static create(t){return new e({refcount:1,stream:t,canceled:!1})}constructor(e,t){super(),this.state=e,t&&++e.refcount}call(e,t){return t.dispose(),new W(Error(`Cannot call methods on a ReadableStream stub`))}map(e,t,n){for(let e of t)e.dispose();return new W(Error(`Cannot use map() on a ReadableStream`))}get(e){return new W(Error(`Cannot access properties on a ReadableStream stub`))}dup(){let t=this.state;if(!t)throw Error(`Attempted to dup a ReadableStreamStubHook after it was disposed.`);return new e(t,this)}pull(){return Promise.reject(Error(`Cannot pull a ReadableStream stub`))}ignoreUnhandledRejections(){}dispose(){let e=this.state;this.state=void 0,e&&--e.refcount===0&&(e.canceled||(e.canceled=!0,e.stream.locked||e.stream.cancel(Error(`ReadableStream RPC stub was disposed without being consumed`)).catch(()=>{})))}onBroken(e){}};U.createWritableStreamHook=Ca.create,U.createWritableStreamFromHook=Ma,U.createReadableStreamHook=Na.create;var Pa=Ai,Fa=_i,Ia=ha;function La(e){return e<32||e>=127&&e<=159||e===1564||e>=8203&&e<=8207||e===8232||e===8233||e>=8234&&e<=8238||e>=8294&&e<=8297||e===65279}function Ra(e,t){let n=e.find(e=>e.id===t.itemId);if(n===void 0||n.kind===`text`)return!1;if(n.kind===`menu`){let e=n.options.find(e=>e.id===t.optionId);return e!==void 0&&e.disabled!==!0}return t.optionId===void 0?n.kind!==`button`||n.disabled!==!0:!1}Object.freeze({publish:()=>Promise.resolve(),onBack:()=>()=>void 0,onForward:()=>()=>void 0,onActivate:()=>()=>void 0});function za(e,t){if(t.kind===`action`){let n=[...e.primary??[],...e.menu??[]].find(e=>e.id===t.actionId);return n!==void 0&&n.disabled!==!0}let n=e.crumbs?.find(e=>e.id===t.crumbId);return n===void 0?!1:t.siblingId===void 0||n.siblings?.some(e=>e.id===t.siblingId)===!0}var Ba=[2,3],Va=`fungi.app.ready.v3`,Ha=`fungi.app.ready`,Ua=`fungi.app.connect`,q=e=>D.pipe(O(He(1)),O(b(e))),Wa=e=>_(q(e)),Ga=M.pipe(O(s()),O(ze(Number.isSafeInteger,{message:`Expected a safe integer`}))),Ka=Ga.pipe(O(u(0))),qa=Ga.pipe(O(pe(0))),Ja=k({appId:q(160),releaseId:q(160),surfaceId:q(160)}),Ya=k({editing:t,surface:Ye([q(160),Le])}),Xa=Ye([k({kind:N(`compose`),requestId:q(160),text:q(2e3)}),k({kind:N(`navigate`),requestId:q(160),params:C(k({key:q(64),value:q(4096)})).pipe(O(b(16)))})]),J=y(j([`granted`,`missing`])),Za=k({"agent.list":J,"agent.manage":J,"agent.read":J,"agent.send":J,"computer.list":J,"computer.readFile":J,"computer.writeFile":J,"computer.execute":J,"git.repository":J,"workflow.publish":J,"workflow.arm":J,"workflow.run":J,"app.events.emit":J,"llm.generation":J,"media.generation":J,"media.share":J}),Qa=j([`ready`,`missing`,`unknown`]),$a=k({models:Qa,media:Qa,git:Qa,terminal:j([`ready`,`exec-only`,`missing`,`unknown`]),terminalReason:_(D)}),eo=j([`model`,`media`,`git`,`computer`]),to=j([`opened`,`unavailable`]),no=k({computerId:Ye([q(256),Le]),computerName:_(Te(D)),teamHasComputers:_(Te(t)),computerAccessGranted:_(t),setup:_($a),permissions:_(Za),focus:Ya,openRequest:Ye([Le,Xa]),visibility:j([`visible`,`hidden`])}),ro=j([`connecting`,`connected`,`suspended`,`disconnected`,`disposing`,`disposed`]),io=k({altKey:t,ctrlKey:t,id:q(160),key:q(64),metaKey:t,shiftKey:t}),ao=k({action:_(A),availability:_(A),category:q(160),description:Wa(512),id:q(160),projections:_(A),title:q(160)}),oo=k({arguments:_(A),commandId:q(321),origin:j([`agent`,`browser`,`keyboard`,`menu`,`palette`,`programmatic`,`slash`,`terminal`]),requestId:q(160)}),so=Ye([k({result:_(A),status:N(`handled`)}),k({error:A,status:N(`failed`)})]),co=e=>q(e).pipe(O(ze(e=>{for(let t=0;t<e.length;t+=1)if(La(e.charCodeAt(t)))return!1;return!0},{message:`Expected one line of plain text`}))),lo={id:q(64),text:co(80),end:y(t),priority:y(N(`low`))},uo=y(M.pipe(O(s()),O(ot({minimum:0,maximum:9999})))),fo=C(Ye([k({...lo,kind:N(`text`),tone:y(j([`neutral`,`success`,`warning`,`error`]))}),k({...lo,kind:N(`button`),icon:y(j([`folder`,`ports`,`processes`,`access`])),count:uo,tone:y(j([`neutral`,`success`,`warning`,`error`])),busy:y(t),title:y(co(1024)),disabled:y(t),opens:y(N(`dialog`)),expanded:y(t)}),k({...lo,kind:N(`toggle`),pressed:t}),k({...lo,kind:N(`menu`),count:uo,title:y(co(1024)),options:C(k({id:q(64),text:co(80),checked:y(t),disabled:y(t)})).pipe(O(b(16)),O(ze(e=>new Set(e.map(e=>e.id)).size===e.length,{message:`Expected unique status option ids`})))})])).pipe(O(b(6)),O(ze(e=>new Set(e.map(e=>e.id)).size===e.length,{message:`Expected unique status item ids`}))),po=k({computerId:q(256),path:q(1024)}),mo=q(80).pipe(O(ze(e=>e.trim()===e,{message:`Expected a trimmed title`}))),ho=q(64),go=q(80),_o=e=>new Set(e.map(e=>e.id)).size===e.length,vo=k({id:ho,label:go,siblings:_(C(k({id:ho,label:go})).pipe(O(b(16)),O(ze(_o,{message:`Expected unique crumb sibling ids`}))))}),yo=k({id:ho,label:go,icon:_(N(`play`)),variant:_(j([`primary`,`outline`,`ghost`])),tone:_(N(`destructive`)),disabled:_(t)}),bo=e=>C(yo).pipe(O(b(e)),O(ze(_o,{message:`Expected unique header command ids`}))),xo=k({id:ho,label:go,presentation:_(N(`bead`)),tone:_(j([`neutral`,`info`,`warning`,`success`,`error`]))}),So={status:_(C(xo).pipe(O(b(4)),O(ze(_o,{message:`Expected unique header status ids`})))),crumbs:_(C(vo).pipe(O(b(8)),O(ze(_o,{message:`Expected unique crumb ids`})))),primary:_(bo(3)),menu:_(bo(12))},Co=k({contractVersion:N(2),canGoBack:t,canGoForward:t,title:_(mo),...So}),wo=k({canGoBack:t,canGoForward:t,title:_(D),...So}),To=Ye([k({kind:N(`crumb`),crumbId:ho,siblingId:_(ho)}),k({kind:N(`action`),actionId:ho})]),Eo=Te(k({agentId:q(256),sessionId:q(256)})),Do=e=>_(C(j(e)).pipe(O(b(e.length)))),Oo=k({agents:_(C(j([`agent.list`,`agent.manage`,`agent.read`,`agent.send`])).pipe(O(b(4)))),computers:_(C(j([`computer.list`,`computer.readFile`,`computer.writeFile`,`computer.execute`])).pipe(O(b(4)))),git:Do([`git.repository`]),workflows:Do([`workflow.publish`,`workflow.arm`,`workflow.run`]),events:Do([`app.events.emit`]),generation:Do([`llm.generation`,`media.generation`,`media.share`])}),ko=j([`granted`,`declined`,`customize`]),Ao=k({message:q(512),tone:_(j([`info`,`success`,`warning`,`error`]))}),jo=j(Se);k({code:jo.pick([`DELIVERY_PENDING`])});var Mo=k({code:jo,message:q(512),retryable:t,need:y(et)}),No=Ye([k({protocolVersion:N(3),type:N(Va)}),k({protocolVersion:N(2),type:N(Ha)})]),Po=k({epoch:q(160),protocolVersion:j(Ba),type:N(Ua)}),Fo=k({epoch:q(160),protocolVersion:j(Ba)}),Io={[Symbol.dispose]:_(A)},Lo=Ye([k({...Io,ok:N(!0),value:A}),k({...Io,error:Mo,ok:N(!1)})]);function Y(e,t,n=`PROTOCOL`){return Me(lt(e,{onExcessProperty:`error`}),be({onFailure:e=>{throw new T(`The peer sent malformed protocol data`,{cause:e,code:n,retryable:!1})},onSuccess:t}))}function X(e){return Object.freeze(e)}function Ro(e,t){let n=e.arguments===void 0?void 0:qn(e.arguments),r={origin:e.origin,signal:t};return n!==void 0&&Object.assign(r,{arguments:n}),X(r)}var zo=Y(ao,e=>{let t={category:e.category,id:e.id,title:e.title};return e.action!==void 0&&Object.assign(t,{action:e.action}),e.availability!==void 0&&Object.assign(t,{availability:e.availability}),e.description!==void 0&&Object.assign(t,{description:e.description}),e.projections!==void 0&&Object.assign(t,{projections:e.projections}),X(As(()=>ar(t)))},`INVALID_ARGUMENT`),Bo=Y(q(321),e=>e),Vo=Y(oo,e=>{let t=e.arguments===void 0?void 0:qn(e.arguments),n={commandId:e.commandId,origin:e.origin,requestId:e.requestId};return t!==void 0&&Object.assign(n,{arguments:t}),X(n)}),Ho=Y(Ye([je,A]),e=>e===void 0?void 0:qn(e)),Uo=Y(Po,e=>X(e));Y(Fo,e=>X(e));var Wo=Y(no,e=>{let t={computerId:e.computerId,focus:X({...e.focus}),openRequest:e.openRequest===null?null:X({...e.openRequest}),visibility:e.visibility};return e.teamHasComputers!==void 0&&(t.teamHasComputers=e.teamHasComputers),e.computerName!==void 0&&(t.computerName=e.computerName),e.computerAccessGranted!==void 0&&(t.computerAccessGranted=e.computerAccessGranted),e.setup!==void 0&&(t.setup=X({...e.setup})),e.permissions!==void 0&&(t.permissions=X({...e.permissions})),X(t)}),Go=Y(Mo,e=>X({...e})),Ko=Y(Ya,e=>X({...e}),`INVALID_ARGUMENT`),qo=Y(Ja,e=>X({...e})),Jo=Y(ro,e=>e),Yo=Y(fo,e=>X(e.map(e=>e.kind===`menu`?X({...e,options:X(e.options.map(e=>X(e)))}):X(e))),`INVALID_ARGUMENT`),Xo=Y(k({itemId:q(64),optionId:y(q(64)),anchor:y(k({start:M.pipe(O(ot({minimum:0,maximum:1e5}))),width:M.pipe(O(ot({minimum:0,maximum:1e5})))}))}),e=>X(e.anchor===void 0?{...e}:{...e,anchor:X({...e.anchor})}),`INVALID_ARGUMENT`),Zo=Y(po,e=>X({...e}),`INVALID_ARGUMENT`);function Qo(e){let t={id:e.id,label:e.label};return e.presentation!==void 0&&(t={...t,presentation:e.presentation}),e.tone!==void 0&&(t={...t,tone:e.tone}),X(t)}function $o(e){let t={id:e.id,label:e.label};return e.siblings===void 0?X(t):X({...t,siblings:X(e.siblings.map(e=>X({...e})))})}function es(e){let t={id:e.id,label:e.label};return e.icon!==void 0&&(t={...t,icon:e.icon}),e.variant!==void 0&&(t={...t,variant:e.variant}),e.tone!==void 0&&(t={...t,tone:e.tone}),e.disabled!==void 0&&(t={...t,disabled:e.disabled}),X(t)}function ts(e){let t={canGoBack:e.canGoBack,canGoForward:e.canGoForward};return e.title!==void 0&&(t={...t,title:e.title}),e.crumbs!==void 0&&(t={...t,crumbs:X(e.crumbs.map($o))}),e.primary!==void 0&&(t={...t,primary:X(e.primary.map(es))}),e.menu!==void 0&&(t={...t,menu:X(e.menu.map(es))}),e.status!==void 0&&(t={...t,status:X(e.status.map(Qo))}),X(t)}var ns=Y(Co,ts,`INVALID_ARGUMENT`),rs=Y(wo,e=>{let t=e.title?.trim();return is({...ts({...e,title:t===void 0||t.length===0?void 0:t}),contractVersion:2})},`INVALID_ARGUMENT`),is=Y(Co,e=>X({...ts(e),contractVersion:2}),`INVALID_ARGUMENT`),as=Y(To,e=>e.kind===`action`?X({...e}):X(e.siblingId===void 0?{kind:e.kind,crumbId:e.crumbId}:e),`INVALID_ARGUMENT`),os=Y(Eo,e=>e===null?null:X({...e}),`INVALID_ARGUMENT`),ss=Y(Oo,e=>X({agents:X([...new Set(e.agents??[])]),computers:X([...new Set(e.computers??[])]),...e.git&&{git:X([...new Set(e.git)])},...e.workflows&&{workflows:X([...new Set(e.workflows)])},...e.events&&{events:X([...new Set(e.events)])},...e.generation&&{generation:X([...new Set(e.generation)])}}),`INVALID_ARGUMENT`),cs=Y(eo,e=>e,`INVALID_ARGUMENT`);Y(No,e=>X(e));var ls=Y(q(512),e=>e),us=Y(Ao,e=>X({...e}),`INVALID_ARGUMENT`);Y(k({id:q(160),repeat:t}),e=>X(e));var ds=Y(C(io).pipe(O(b(64))),e=>{if(new Set(e.map(e=>e.id)).size!==e.length)throw new T(`Reserved chords are invalid`,{code:`PROTOCOL`,retryable:!1});return X(e.map(e=>X({...e})))});function fs(e){return Y(k({value:A,version:Ka}),t=>X({value:e(t.value),version:t.version}))}var ps=fs(Wo),ms=Y(k({capabilities:C(A).pipe(O(b(128))),context:A}),e=>X({capabilities:X(e.capabilities.map(e=>bs(e))),context:ps(e.context)})),hs=fs(Jo),gs=fs(ds),_s=fs(ls),vs=Me(hs,e=>{if(e.value!==`connected`&&e.value!==`suspended`)throw new T(`The host lifecycle is invalid`,{code:`PROTOCOL`,retryable:!1});return X({value:e.value,version:e.version})});function ys(e){return Y(k({handle:A,id:q(160),version:qa}),t=>{if(!(t.handle instanceof Pa)&&!(e&&t.handle instanceof Fa))throw new T(`A capability handle is invalid`,{code:`PROTOCOL`,retryable:!1});return X({handle:t.handle,id:t.id,version:t.version})})}var bs=ys(!1),xs=ys(!0);function Ss(e){let t=e?xs:bs;return Y(k({capabilities:C(A).pipe(O(b(128))),context:A,identity:A,lifecycle:A,reservedChords:A,theme:A}),e=>X({capabilities:X(e.capabilities.map(e=>t(e))),context:ps(e.context),identity:qo(e.identity),lifecycle:vs(e.lifecycle),reservedChords:gs(e.reservedChords),theme:_s(e.theme)}))}var Cs=Ss(!1);Ss(!0);function ws(e){return Y(Lo,t=>t.ok?X({ok:!0,value:e(t.value)}):X({ok:!1,error:Go(t.error)}))}var Ts=ws(Cs),Es=ws(Y(k({commandId:q(321)}),e=>X(e)));ws(Y(so,e=>{if(e.status===`failed`)return X({status:`failed`,error:As(()=>Yn(e.error))});let t=e.result===void 0?void 0:qn(e.result);return X(t===void 0?{status:`handled`}:{status:`handled`,result:t})}));var Ds=ws(Y(je,()=>void 0)),Os=ws(Y(ko,e=>e)),ks=ws(Y(to,e=>e));ws(Y(t,e=>e)),ws(Y(t,e=>e));function As(e){try{return e()}catch(e){throw new T(`The command metadata is invalid`,{cause:e,code:`INVALID_ARGUMENT`,retryable:!1})}}var js=Ye([k({kind:N(`saveFile`),name:q(255).pipe(O(n(/^[^\p{Cc}/\\]+$/u))),mime:q(255),bytes:ke}),k({kind:N(`copyText`),text:D})]);function Ms(e){let t=lt(js,{onExcessProperty:`error`})(e);if(te(t))return{kind:`refused`,reason:`invalid-request`};let n=t.success;return n.kind===`saveFile`?n.name===`.`||n.name===`..`?{kind:`refused`,reason:`invalid-request`}:n.bytes.byteLength>33554432?{kind:`refused`,reason:`too-large`}:{...n,bytes:new Uint8Array(n.bytes)}:n.text.length>1048576||new TextEncoder().encode(n.text).byteLength>1048576?{kind:`refused`,reason:`too-large`}:n}var Ns=ws(Y(Ye([k({kind:N(`saved`)}),k({kind:N(`copied`)}),k({kind:N(`refused`),reason:j([`no-user-gesture`,`too-large`,`invalid-request`,`unavailable`,`denied`,`busy`])})]),e=>X(e)));function Ps(e){let t=e,n=new Set;return{get:()=>t,subscribe(e){n.add(e);let t=!0;return()=>{t&&(t=!1,n.delete(e))}},update(e){if(!Object.is(t,e)){t=e;for(let e of Array.from(n))try{e(t)}catch(e){console.warn(`App store subscriber failed`,e)}}}}}function Fs(e){let t=new Map,n=Ps(0),r=!1,i=e=>{let t=new Map;try{for(let n of e){let e=bs(n),r=zs(e.id,e.version);if(t.has(r))throw Ls(e.handle),new T(`Duplicate capability grant`,{code:`PROTOCOL`,retryable:!1});t.set(r,e.handle)}}catch(e){for(let e of t.values())Ls(e);throw e}return t};for(let[n,r]of i(e))t.set(n,r);let a=e=>{for(let t of e)Ls(t)},o=e=>{if(r)throw new T(`The app connection is disposed`,{code:`DISCONNECTED`,retryable:!0});let n=zs(e.id,e.version);return t.get(n)};return{directory:Object.freeze({get version(){return n.get()},subscribe:e=>n.subscribe(e),has(e){return!!o(e)},require(e){let t=o(e);if(!t)throw new T(`The capability is not granted`,{code:`CAPABILITY_DENIED`,retryable:!1});try{return e.schema.parse(t)}catch(e){throw new T(`The capability interface is malformed`,{cause:e,code:`PROTOCOL`,retryable:!1})}}}),replace(e){if(r)throw new T(`The app connection is disposed`,{code:`DISCONNECTED`,retryable:!0});let o=i(e),s=[...t.values()];t.clear();for(let[e,n]of o)t.set(e,n);a(s.filter(e=>![...o.values()].includes(e))),n.update(n.get()+1)},disconnect(){r||(r=!0,a(t.values()),t.clear(),n.update(n.get()+1))}}}var Is=S().transform(e=>{let t=Ce(Object).safeParse(e);if(!t.success)return;let n=Object.create(t.data),r=E(k({[Symbol.dispose]:_(ue(Function))}))(n);return{owner:t.data,dispose:r[Symbol.dispose]}});function Ls(e){try{let t=Is.parse(e);if(t===void 0||Rs.has(t.owner))return;Rs.add(t.owner),t.dispose?.call(t.owner)}catch(e){console.warn(`RPC value disposal failed`,e)}}var Rs=new WeakSet;function zs(e,t){return`${e}@${String(t)}`}function Bs(e){let t=(0,I.useCallback)(t=>e?.subscribe(t)??(()=>void 0),[e]),n=(0,I.useCallback)(()=>e?.get(),[e]);return(0,I.useSyncExternalStore)(t,n,n)}function Vs(e){return Bs(e?.context)??null}function Hs(e){return Vs(e)?.computerId??null}function Us(e,t,n,r){let i=(0,I.useRef)(t);i.current=t;let a=(0,I.useRef)(n);a.current=n;let o=(0,I.useRef)(r);o.current=r;let s=JSON.stringify(t),c=n!==void 0;(0,I.useEffect)(()=>{e&&e.ui.reportStatus(i.current).catch(e=>{o.current?o.current(e):console.error(`Window status report failed`,e)})},[e,s]),(0,I.useEffect)(()=>{if(!(!e||!c))return e.ui.onStatusAction(e=>a.current?.(e)??!1)},[e,c]),(0,I.useEffect)(()=>()=>{e?.ui.reportStatus([]).catch(e=>{console.error(`Window status report failed`,e)})},[e])}function Ws(e,{sourceId:t,namespace:n},r){let i=(0,I.useMemo)(()=>gr(),[]),a=(0,I.useMemo)(r,[r]);return(0,I.useEffect)(()=>{let e=i.contribute({sourceId:t,namespace:n,commands:a});return()=>{e.dispose()}},[i,t,n,a]),(0,I.useEffect)(()=>e?di(e.commands,a):void 0,[e,a]),i}function Gs(e,{canGoBack:t,canGoForward:n,title:r,crumbs:i,primary:a,menu:o,status:s,onBack:c,onForward:l,onCrumb:u,onAction:d}){let f=(0,I.useRef)(c),p=(0,I.useRef)(l),m=(0,I.useRef)(u),h=(0,I.useRef)(d);(0,I.useEffect)(()=>{f.current=c,p.current=l,m.current=u,h.current=d},[c,l,u,d]),(0,I.useEffect)(()=>{if(!e)return;let t=e.onBack(()=>f.current()),n=e.onForward(()=>p.current()),r=e.onActivate(e=>{if(e.kind===`action`){let t=h.current;return t?.(e.actionId),t!==void 0}let t=m.current;return e.siblingId===void 0?t?.(e.crumbId):t?.(e.crumbId,e.siblingId),t!==void 0});return()=>{t(),n(),r(),Ks(e,{canGoBack:!1,canGoForward:!1})}},[e]);let g=JSON.stringify([i,a,o,s]),ee=(0,I.useRef)({crumbs:i,primary:a,menu:o,status:s});(0,I.useEffect)(()=>{ee.current={crumbs:i,primary:a,menu:o,status:s}},[i,a,o,s]),(0,I.useEffect)(()=>{if(!e)return;let i={canGoBack:t,canGoForward:n};r!==void 0&&(i={...i,title:r});let a=ee.current;a.crumbs!==void 0&&(i={...i,crumbs:a.crumbs}),a.primary!==void 0&&(i={...i,primary:a.primary}),a.menu!==void 0&&(i={...i,menu:a.menu}),a.status!==void 0&&(i={...i,status:a.status}),Ks(e,i)},[e,t,n,r,g])}function Ks(e,t){e.publish(t).catch(e=>{e instanceof T&&e.code===`DISCONNECTED`||console.warn(`App navigation report failed`,e)})}var qs=class{id;version;#e;constructor(e,t,n){this.id=e,this.version=t,this.#e=n,Object.freeze(this)}get schema(){return this.#e}};function Js(e,t,n){return new qs(e,t,n)}function Z(e){let t=x(e),n=Ce(Object),r=x(Object.fromEntries(Object.keys(e).map(e=>[e,S().optional()])));return S().transform(e=>{let i=n.parse(e),a=Object.create(i),o=r.parse(a),s=Object.fromEntries(Object.entries(o).flatMap(([e,t])=>t===void 0?[]:[[e,Pe().parse(t).bind(i)]]));return{...t.parse(s),[Symbol.dispose](){Ls(e)}}})}function Q(e){return S().transform(t=>{try{return e.parse(t)}catch(e){throw e instanceof T?e:new T(`The capability returned malformed data`,{cause:e,code:`PROTOCOL`,retryable:!1})}finally{Ls(t)}})}function $(e){return Pe({output:Ue(S().transform(t=>{try{return e.parse(t)}catch(e){throw Ls(t),e instanceof T?e:new T(`The capability returned a malformed result`,{cause:e,code:`PROTOCOL`,retryable:!1})}}))})}var Ys=$(Q(it()));Z({fetch:$(Ce(Response)),close:Ys});var Xs=d({status:c()}),Zs=3,Qs=/network ?(?:changed|error)|failed to fetch|load failed|network connection was lost/iu;function $s(e){let t=[];for(let n=e;n!==void 0&&t.length<5;n=n instanceof Error?n.cause:void 0)t.push(n);return t}function ec(e){return $s(e).some(e=>{if(e instanceof TypeError)return!0;if(e instanceof T)return e.code===`HOST_FAILURE`&&e.retryable;let t=Xs.safeParse(e);return t.success?t.data.status>=500:e instanceof Error&&Qs.test(e.message)})}function tc(e,t){return e<Zs&&ec(t)}function nc(e){return 250*2**e}function rc(e){return e instanceof T?e:new T(`App operation failed`,{cause:e,code:`HOST_FAILURE`,retryable:!1})}var ic=new WeakMap,ac={of(e,...t){return[e?.identity.surfaceId??null,e?.context.get().computerId??null,...t]}};function oc(e){let t={};return e&&ic.set(t,e),t}function sc(){let e=new Dn({defaultOptions:{queries:{retry:!1,staleTime:3e4,refetchOnWindowFocus:!1},mutations:{retry:!1}}}),t=new Map;return e.getQueryCache().subscribe(n=>{let r=n.query;if(n.type===`removed`){t.get(r.queryHash)?.release(),t.delete(r.queryHash);return}let i=r.meta&&ic.get(r.meta),a=t.get(r.queryHash);if(a?.app===i||(a?.release(),t.delete(r.queryHash),!i))return;let o=()=>{queueMicrotask(()=>{e.getQueryCache().get(r.queryHash)===r&&t.get(r.queryHash)?.app===i&&e.resetQueries({predicate:e=>e===r})})},s=i.capabilities.subscribe(o);t.set(r.queryHash,{app:i,release:s}),a&&o()}),e}function cc(e,t,n,r){let i=e?.context.get().computerId;return Hn({queryKey:n,meta:oc(e),enabled:e!==null,retry:tc,retryDelay:nc,queryFn:async({signal:n})=>{try{if(!e)throw new T(`No App connection`,{code:`DISCONNECTED`,retryable:!0});if(e.context.get().computerId!==i)throw new T(`The selected Computer changed`,{code:`SELECTION_CHANGED`,retryable:!1});return await r(e.capabilities.require(t),n)}catch(e){throw rc(e)}}})}var lc=6e4;Be({path:v().min(1).max(4096).startsWith(`/`).refine(e=>!e.includes(`\0`),`Path cannot contain null bytes`).default(`/`)});var uc=Ie({added:`added`,modified:`modified`,deleted:`deleted`,renamed:`renamed`,untracked:`untracked`,conflicted:`conflicted`}),dc=Be({path:v().min(1).max(4096),status:uc,renamedFrom:v().min(1).max(4096).optional()}),fc=de(`kind`,[Be({kind:w(`not_repository`)}),Be({kind:w(`changes`),root:v().min(1).max(4096),branch:v().min(1).max(1024).nullable(),files:ut(dc).max(500),patch:v().max(lc),truncated:De()})]);String.raw`exec 2>/dev/null
2
+ unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR \
3
+ GIT_ALTERNATE_OBJECT_DIRECTORIES GIT_CONFIG GIT_CONFIG_PARAMETERS GIT_CONFIG_COUNT \
4
+ GIT_EXTERNAL_DIFF GIT_ATTR_SOURCE
5
+ export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null GIT_OPTIONAL_LOCKS=0 \
6
+ GIT_TERMINAL_PROMPT=0 GIT_NO_LAZY_FETCH=1
7
+ [ "$(git rev-parse --is-inside-work-tree)" = true ] || { printf 'fungi:not-repository\0'; exit 0; }
8
+ printf 'fungi:repository\0'
9
+ git rev-parse --show-prefix | tr -d '\n'; printf '\0'
10
+ top=$(git rev-parse --show-toplevel) && cd "$top" || exit 0
11
+ index=$(git rev-parse --path-format=absolute --git-path index) || exit 0
12
+ objects=$(git rev-parse --path-format=absolute --git-path objects) || exit 0
13
+ exclude=$(git rev-parse --path-format=absolute --git-path info/exclude) || exit 0
14
+ format=$(git rev-parse --show-object-format) || exit 0
15
+ head=$(git rev-parse -q --verify HEAD)
16
+ branch=$(git symbolic-ref -q HEAD)
17
+ shadow=$(mktemp -d) || exit 0
18
+ trap 'rm -rf "$shadow"' EXIT
19
+ mkdir "$shadow/refs" "$shadow/info" || exit 0
20
+ git config -f "$shadow/config" core.repositoryformatversion 1 || exit 0
21
+ git config -f "$shadow/config" extensions.objectFormat "$format" || exit 0
22
+ git config -f "$shadow/config" core.bare false || exit 0
23
+ git config -f "$shadow/config" core.quotepath false || exit 0
24
+ for key in core.filemode core.ignorecase core.symlinks core.precomposeunicode; do
25
+ value=$(git config --type=bool "$key") || continue
26
+ git config -f "$shadow/config" "$key" "$value" || exit 0
27
+ done
28
+ for key in core.autocrlf core.eol; do
29
+ value=$(git config "$key") || continue
30
+ git config -f "$shadow/config" "$key" "$value" || exit 0
31
+ done
32
+ gitdir=$(git rev-parse --absolute-git-dir) || exit 0
33
+ for shared in "$gitdir"/sharedindex.*; do
34
+ [ ! -f "$shared" ] || ln -s "$shared" "$shadow/" || exit 0
35
+ done
36
+ [ ! -f "$exclude" ] || cp "$exclude" "$shadow/info/exclude" || exit 0
37
+ if [ -n "$branch" ]; then printf 'ref: %s\n' "$branch"; else printf '%s\n' "$head"; fi >"$shadow/HEAD"
38
+ export GIT_DIR="$shadow" GIT_WORK_TREE="$top" GIT_INDEX_FILE="$index" GIT_OBJECT_DIRECTORY="$objects"
39
+ [ -z "$branch" ] || [ -z "$head" ] || git update-ref "$branch" "$head" || exit 0
40
+ git status --porcelain=v2 --branch -z --untracked-files=all --ignore-submodules=all
41
+ printf 'fungi:patch\0'
42
+ base=$(git rev-parse -q --verify HEAD || git hash-object -t tree /dev/null)
43
+ git diff --no-ext-diff --no-textconv --no-color --find-renames --ignore-submodules=all "$base"
44
+ git ls-files --others --exclude-standard -z | xargs -r -0 -n 1 git diff --no-index --no-ext-diff --no-textconv --no-color -- /dev/null
45
+ exit 0`,Js(`app.backend`,1,P(()=>Z({request:$(Q(S().transform(e=>qn(e))))})));var pc=Js(`app.methods`,1,P(()=>Z({call:$(Q(S().transform(e=>qn(e))))})));Js(`app.region`,1,P(()=>Z({connect:$(Z({messages:$(Ce(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(v().parse(e))}})))),send:Ys,close:Ys}))})));var mc=rt(st(k({error:N(`too_large`)})));async function hc(e,t){let n,r=()=>n??=e.close(),i=()=>{r().catch(e=>{mi(`files.read.abort-close`,e)})};t.signal?.addEventListener(`abort`,i,{once:!0});try{t.signal?.throwIfAborted();let n=await e.response();try{let e=E(ue(Response))(n);if(e.status===413){let t=mc(await e.text());throw new T(`App file exceeds the read bound`,{code:t._tag===`Some`?`FILE_TOO_LARGE`:`PROTOCOL`,retryable:!1})}if(!e.ok)throw Error(`App file unavailable (${String(e.status)})`);let r=await e.blob();return t.signal?.throwIfAborted(),new File([r],t.name,{type:r.type,lastModified:0})}finally{Ls(n)}}finally{t.signal?.removeEventListener(`abort`,i);try{await r()}finally{e[Symbol.dispose]()}}}async function gc(e,t,n){let r,i=()=>r??=e.close(),a=()=>{i().catch(e=>{mi(`files.write.abort-close`,e)})};n.signal?.addEventListener(`abort`,a,{once:!0});try{n.signal?.throwIfAborted(),await e.write(t.stream())}finally{n.signal?.removeEventListener(`abort`,a);try{await i()}catch(e){mi(`files.write.remote-close`,e)}try{e[Symbol.dispose]()}catch(e){mi(`files.write.local-dispose`,e)}}}var _c=Ie([`exec`,`write`,`media`]),vc=P(()=>Be({error:w(`attachment_budget_exceeded`),kind:_c,retryAfterMs:c()})),yc=P(()=>Be({error:w(`unavailable`),ref:v().min(1).max(128)}));P(()=>ie([Be({error:Ie([`revoked`,`not_granted`,`command_list`,`grantor_lost_authority`,`unavailable`])}),yc,vc])),P(()=>Be({error:Ie([`too_large`,`invalid_path`,`invalid`])})),P(()=>ie([Be({error:Ie([`not_granted`,`command_list`,`too_large`,`conflict`,`capacity`,`unfunded`,`admission_unavailable`,`backend_unavailable`,`unavailable`])}),yc])),P(()=>ie([Be({error:Ie([`capacity`,`unfunded`,`admission_unavailable`,`backend_unavailable`])}),yc])),P(()=>Be({error:w(`timeout`),requestId:v()}));var bc=Ie([`revoked`,`not_granted`,`command_list`,`grantor_lost_authority`,`attachment_budget_exceeded`,`too_large`,`invalid_path`,`invalid`,`not_found`,`conflict`,`timeout`,`capacity`,`unfunded`,`admission_unavailable`,`backend_unavailable`,`unavailable`]);P(()=>ie([Be({error:bc.exclude([`attachment_budget_exceeded`,`timeout`])}),yc]));function xc(e){return e===void 0||e===``?``:` (ref ${e})`}var Sc={revoked:()=>`This App's access to the Computer was removed.`,not_granted:()=>`This App doesn't have access to this Computer.`,command_list:()=>`This Computer's command list doesn't allow these commands. Ask its creator or a Team owner/admin for access.`,grantor_lost_authority:()=>`The person who gave this App Computer access no longer has it.`,attachment_budget_exceeded:()=>`This App has used its Computer allowance for now. Try again later.`,too_large:()=>`That's too large for the Computer to take. Try something smaller.`,invalid_path:()=>`That path isn't allowed on this Computer.`,invalid:()=>`The Computer couldn't accept that request as written.`,not_found:()=>`That file or folder isn't on the Computer.`,conflict:()=>`It changed on the Computer while this was running. Reload it and try again.`,timeout:()=>`The Computer didn't finish in time. It may still be running the command.`,capacity:()=>`The Computer's host is full right now. Try again in a minute.`,unfunded:()=>`This Team is out of Computer credit. Add credit to keep using it.`,admission_unavailable:()=>`We couldn't check this Computer's access just now. Try again shortly.`,backend_unavailable:()=>`The machine behind this Computer isn't available right now. Try again shortly.`,unavailable:e=>`The Computer didn't answer, and we don't know why yet${xc(e)}.`};function Cc(e,t){return Sc[e](t)}var wc=k({path:D,entries:C(k({name:D,type:j([`file`,`directory`,`symlink`]),size:M,modifiedAt:M})),nextOffset:Te(M)}),Tc=Js(`computer.list`,1,P(()=>Z({list:$(Q(S().transform(e=>E(wc)(e))))}))),Ec=Ye([k({state:j([`running`,`sleeping`,`starting`])}),k({state:N(`start_failed`),reason:y(D.pipe(O(He(1)),O(b(1024))))}),k({state:N(`queued`),position:M.pipe(O(s()),O(pe(0)))})]),Dc=k({enabled:t,effective:t,blockedBy:Te(j([`team`,`global`]))}),Oc=k({computerId:Ze,name:Ze,runtime:Ec,backends:C(k({id:Ze,kind:j([`platform-container`,`on-box-vm`,`local`]),status:j([`ready`,`queued`,`online`,`offline`]),queuePosition:Te(M.pipe(O(s()),O(pe(0)))),hostId:Te(D),hostLabel:Te(D),folderLabel:Te(D),detachable:t})),internet:Dc});Js(`computer.instrument.read`,1,P(()=>Z({read:$(Q(S().transform(e=>E(Oc)(e))))}))),Js(`computer.instrument.control`,1,P(()=>Z({start:$(Q(S().transform(e=>E(Ec)(e)))),setInternetAccess:$(Q(S().transform(e=>E(Dc)(e)))),detachLocal:$(Q(S().transform(e=>E(k({detached:t}))(e))))})));var kc=k({ports:C(k({port:M.pipe(O(s()),O(ot({minimum:1,maximum:65535}))),previewUrl:Ze,openMode:j([`inline`,`external-only`])})).pipe(O(b(64)))}),Ac=Ye([kc,k({error:N(`port_previews_not_configured`)})]),jc=k({port:M.annotate({message:`Use a port from 1 to 65535.`}).check(s({message:`Use a port from 1 to 65535.`}),ot({minimum:1,maximum:65535},{message:`Use a port from 1 to 65535.`})),exposed:t}),Mc=k({port:M.pipe(O(s()),O(ot({minimum:1,maximum:65535}))),removed:t});Js(`computer.ports`,2,P(()=>Z({list:$(Q(S().transform(e=>E(Ac)(e)))),expose:$(Q(S().transform(e=>E(jc)(e)))),unexpose:$(Q(S().transform(e=>E(Mc)(e))))})));var Nc=j([`synced`,`pending`,`unknown`]),Pc=k({port:Te(jc.fields.port),id:Ze,command:Ze,cwd:Te(D),startedAt:M.pipe(O(s()),O(u(0))),state:j([`running`,`exited`,`uncertain`]),exitCode:Te(M.pipe(O(s()))),sync:Nc,endedAt:Te(M.pipe(O(s()),O(u(0)))),endedReason:Te(N(`idle-sleep`))}),Fc=k({processes:C(Pc)}),Ic=k({process:Pc,signalled:t}),Lc=k({process:Pc,lines:C(D.pipe(O(b(2e3)))).pipe(O(b(200))),truncated:t});k({requestId:Ze.pipe(O(b(256))),command:Ze.pipe(O(b(16384))),cwd:y(D),port:y(jc.fields.port)}),Js(`computer.processes`,1,P(()=>Z({start:$(Q(S().transform(e=>E(Pc)(e)))),list:$(Q(S().transform(e=>E(Fc)(e)))),kill:$(Q(S().transform(e=>E(Ic)(e)))),logs:$(Q(S().transform(e=>E(Lc)(e))))})));var Rc=k({error:j(bc.options),ref:_(D)});function zc(e){let t=rt(Rc)(e);if(ce(t)){let{error:e,ref:n}=t.value,r=Cc(e,n);return e===`not_granted`||e===`revoked`||e===`grantor_lost_authority`?{reason:`not-granted`,message:r,action:`grant`}:{reason:`failed`,message:r,action:`retry`}}let n=le(e);return n.action===`setup`?{reason:`no-runtime`,message:`No Computer is running to answer this yet.`,action:`setup`}:n.action===`grant`?{reason:`not-granted`,message:`This App needs permission to see this Computer.`,action:`grant`}:{reason:`failed`,message:n.message,action:`retry`}}var Bc=Js(`computer.readFile`,1,P(()=>Z({open:$(Z({response:$(Ce(Response)),close:Ys}))})));async function Vc(e,t,n){return await hc(await e.require(Bc).open(t),{...n,name:t.path.split(`/`).at(-1)??`file`})}async function Hc(e,t){return E(wc)(await e.require(Tc).list(t))}var Uc=Js(`computer.writeFile`,3,P(()=>Z({open:$(Z({write:Ys,close:Ys})),mkdir:Ys,replace:$(Q(S().transform(e=>E(Wc)(e))))}))),Wc=Ye([k({kind:N(`replaced`),path:Ze,bytes:M.pipe(O(s()),O(u(0)))}),k({kind:N(`conflict`)})]);async function Gc(e,t,n){n.signal?.throwIfAborted();let r=await e.require(Uc).replace(t);if(r.kind===`conflict`)throw new T(`Computer file changed since it was opened`,{code:`CONFLICT`,retryable:!1});return{path:r.path,bytes:r.bytes}}var Kc=k({computerName:Ze.pipe(O(b(256))),teamName:Ze.pipe(O(b(256))),modelDoor:Ze.pipe(O(b(256))),uptimeSeconds:M.pipe(O(s()),O(u(0))),version:Ze.pipe(O(b(64)))});Js(`computer.terminal`,2,P(()=>Z({open:$(Z({information:$(Q(S().transform(e=>E(Kc)(e)))),output:$(Ce(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(Ce(Uint8Array).parse(e))}})))),input:$(Ce(WritableStream)),resize:Ys,close:Ys}))})));async function qc(e,t,n){await gc(await e.require(Uc).open({path:t.path}),t.content,n)}var Jc=se*10,Yc=class{constructor(e={}){let t=!oe(e.bounce)||!oe(e.duration);this.timeStep=.02,this.restThreshold=5e-4,this.restDuration=200,this.maxDuration=6e4,this.maxRestSteps=this.restDuration/this.timeStep/se,this.maxIterations=this.maxDuration/this.timeStep/se,this.bn=F(Oe(e.bounce,.5),-1,1),this.pd=F(Oe(e.duration,628),10*ae.timeScale,Jc*ae.timeScale),this.m=F(Oe(e.mass,1),1,Jc),this.s=F(Oe(e.stiffness,100),m,Jc),this.d=F(Oe(e.damping,10),m,Jc),this.v=F(Oe(e.velocity,0),-Jc,Jc),this.w0=0,this.zeta=0,this.wd=0,this.b=0,this.completed=!1,this.solverDuration=0,this.settlingDuration=0,this.parent=null,this.onComplete=e.onComplete||ee,t&&this.calculateSDFromBD(),this.compute(),this.ease=e=>{let t=e*this.settlingDuration,n=this.completed,r=this.pd;return t>=r&&!n&&(this.completed=!0,this.onComplete(this.parent)),t<r&&n&&(this.completed=!1),e===0||e===1?e:this.solve(e*this.solverDuration)}}solve(e){let{zeta:t,w0:n,wd:r,b:i}=this,a=e;return a=t<1?f(-a*t*n)*(1*me(r*a)+i*Ve(r*a)):t===1?(1+i*a)*f(-a*n):((1+i)*f((-t*n+r)*a)+(1-i)*f((-t*n-r)*a))/2,1-a}calculateSDFromBD(){let e=ae.timeScale===1?this.pd/se:this.pd;this.m=1,this.v=0,this.s=We(2*ct/e,2),this.d=this.bn>=0?(1-this.bn)*4*ct/e:4*ct/(e*(1+this.bn)),this.s=i(F(this.s,m,Jc),3),this.d=i(F(this.d,m,300),3)}calculateBDFromSD(){let e=2*ct/re(this.s);this.pd=e*(ae.timeScale===1?se:1),this.bn=this.d/(2*re(this.s))<=1?1-this.d*e/(4*ct):4*ct/(this.d*e)-1,this.bn=i(F(this.bn,-1,1),3),this.pd=i(F(this.pd,10*ae.timeScale,Jc*ae.timeScale),3)}compute(){let{maxRestSteps:e,maxIterations:t,restThreshold:n,timeStep:r,m:a,d:o,s,v:c}=this,l=this.w0=F(re(s/a),m,se),u=this.zeta=o/(2*re(s*a));u<1?(this.wd=l*re(1-u*u),this.b=(u*l+-c)/this.wd):u===1?(this.wd=0,this.b=-c+l):(this.wd=l*re(u*u-1),this.b=(u*l+-c)/this.wd);let d=0,f=0,p=0;for(;f<=e&&p<=t;)fe(1-this.solve(d))<n?f++:f=0,this.solverDuration=d,d+=r,p++;this.settlingDuration=i(this.solverDuration*se,0)*ae.timeScale}get bounce(){return this.bn}set bounce(e){this.bn=F(Oe(e,1),-1,1),this.calculateSDFromBD(),this.compute()}get duration(){return this.pd}set duration(e){this.pd=F(Oe(e,1),10*ae.timeScale,Jc*ae.timeScale),this.calculateSDFromBD(),this.compute()}get stiffness(){return this.s}set stiffness(e){this.s=F(Oe(e,100),m,Jc),this.calculateBDFromSD(),this.compute()}get damping(){return this.d}set damping(e){this.d=F(Oe(e,10),m,Jc),this.calculateBDFromSD(),this.compute()}get mass(){return this.m}set mass(e){this.m=F(Oe(e,1),1,Jc),this.compute()}get velocity(){return this.v}set velocity(e){this.v=F(Oe(e,0),-Jc,Jc),this.compute()}},Xc=e=>new Yc(e),Zc=(e=10,t)=>{let n=t?o:l;return t=>n(F(t,0,1)*e)*(1/e)},Qc=Object.freeze({ease:`linear`,duration:0});function $c(e,t){let n=_e(e,t.duration);return n<=0?Qc:e.steps>0?{ease:Zc(e.steps),duration:n}:{ease:Xc({bounce:ft(e,t.bounce),duration:n}),duration:n}}function el(e,t){let n=g(e,t.duration);return{ease:e.steps>0?Zc(e.steps):t.ease,duration:n}}var tl={dot:{y:-4,height:8,cy:0},pill:{y:-16,height:32,cy:0},bang:{y:-16,height:20,cy:12}};function nl({className:e,glyph:t,motion:n}){let r=`caps-status-${(0,I.useId)().replaceAll(`:`,``)}`,i=(0,I.useRef)(null),a=(0,I.useRef)(null),o=(0,I.useRef)(null),s=(0,I.useRef)(null),c=(0,I.useRef)(null),l=(0,I.useRef)(null),u=(0,I.useRef)(tl[t]).current,d=(0,I.useRef)(t===`dot`?1:4).current,f=(0,I.useRef)(+(t===`bang`)).current,p=(0,I.useRef)(t),m=ve(s),{reduced:h}=m;return(0,I.useLayoutEffect)(()=>{if(!i.current||!a.current||!c.current||!l.current)return;let e=tl[t],n=h||p.current===t;p.current=t;let r=he(i.current),o=n?{duration:0}:$c(r,{bounce:.3,duration:360}),s=dt(i.current,{y:e.y,height:e.height,...o}),u=dt(a.current,{cy:e.cy,...n?{duration:0}:{delay:g(r,35),...$c(r,{bounce:.3,duration:420})}}),d=dt(c.current,{gradientTransform:`matrix(1 0 0 ${t===`dot`?`1`:`4`} 0 0)`,...o}),f=dt(l.current,{opacity:+(t===`bang`),...n?Qc:el(r,{ease:`inOutSine`,duration:220})});return()=>{s.cancel(),u.cancel(),d.cancel(),f.cancel()}},[t,h]),(0,I.useLayoutEffect)(()=>{if(!o.current||!s.current||h||n===`none`)return;let e=n===`pulse`?dt(o.current,{opacity:[1,.45],...el(m,{ease:`inOutSine`,duration:750}),alternate:!0,loop:!0}):dt(o.current,{keyframes:{"0%":{translateY:0,scaleX:1,scaleY:1},"18%":{translateY:.25,scaleX:1.1,scaleY:.91},"42%":{translateY:-1.3,scaleX:.94,scaleY:1.06},"62%":{translateY:-1.65,scaleX:1,scaleY:1},"82%":{translateY:.15,scaleX:1.06,scaleY:.95},"100%":{translateY:0,scaleX:1,scaleY:1}},...el(m,{ease:`inOutSine`,duration:1e3}),loop:!0}),t=Xe(s.current,t=>{t?e.resume():e.pause()});return()=>{t(),e.revert()}},[n,h,m]),(0,L.jsxs)(`svg`,{ref:s,"aria-hidden":`true`,className:`caps-status-bead ${e??``}`,width:`8`,height:`8`,viewBox:`-4 -4 8 8`,focusable:`false`,children:[(0,L.jsxs)(`defs`,{children:[(0,L.jsx)(Ge,{id:r,values:at}),(0,L.jsx)(we,{ref:c,id:`${r}-surface`,transform:`matrix(1 0 0 ${String(d)} 0 0)`}),(0,L.jsxs)(`radialGradient`,{id:`${r}-drop-light`,gradientUnits:`userSpaceOnUse`,cx:`-1.2`,cy:`10.4`,r:`5.6`,children:[(0,L.jsx)(`stop`,{offset:`0`,stopColor:`var(--color-white)`,style:{stopOpacity:`calc(var(--depth) * 0.5)`}}),(0,L.jsx)(`stop`,{offset:`1`,stopColor:`var(--color-white)`,stopOpacity:`0`})]}),(0,L.jsx)(Fe,{id:`${r}-shadow`}),(0,L.jsx)(`mask`,{id:`${r}-silhouette`,maskUnits:`userSpaceOnUse`,x:`-12`,y:`-24`,width:`24`,height:`48`,style:{maskType:`alpha`},children:(0,L.jsxs)(`g`,{fill:`var(--color-white)`,filter:`url(#${r})`,children:[(0,L.jsx)(`rect`,{ref:i,x:`-4`,y:u.y,width:`8`,height:u.height,rx:`4`}),(0,L.jsx)(`circle`,{ref:a,cx:`0`,cy:u.cy,r:`4`})]})})]}),(0,L.jsx)(`g`,{ref:o,filter:`url(#${r}-shadow)`,children:(0,L.jsxs)(`g`,{mask:`url(#${r}-silhouette)`,children:[(0,L.jsx)(`rect`,{x:`-12`,y:`-24`,width:`24`,height:`48`,fill:`url(#${r}-surface)`}),(0,L.jsx)(`rect`,{ref:l,x:`-12`,y:`-24`,width:`24`,height:`48`,fill:`url(#${r}-drop-light)`,opacity:f})]})})]})}var rl=.28;function il(e,t){switch(e){case`ring`:return{dashes:1,track:0,arc:0,sweep:0,disc:0,tick:0,cross:0};case`arc`:return{dashes:0,track:1,arc:1,sweep:t===void 0?rl:Math.min(1,Math.max(0,t)),disc:0,tick:0,cross:0};case`check`:return{dashes:0,track:0,arc:1,sweep:1,disc:1,tick:1,cross:0};case`cross`:return{dashes:0,track:0,arc:1,sweep:1,disc:1,tick:0,cross:1}}}var al=7.25;function ol({className:e,glyph:t,progress:n}){let r=`caps-status-mark-${(0,I.useId)().replaceAll(`:`,``)}`,i=(0,I.useRef)(null),a=(0,I.useRef)(null),o=(0,I.useRef)(null),s=(0,I.useRef)(null),c=(0,I.useRef)(null),l=(0,I.useRef)(null),u=(0,I.useRef)(null),d=(0,I.useRef)(null),f=(0,I.useRef)(il(t,n)).current,p=(0,I.useRef)(t),m=h();(0,I.useLayoutEffect)(()=>{let e=i.current,r=a.current,c=o.current,f=s.current,h=l.current,g=u.current,ee=d.current;if(!e||!r||!c||!f||!h||!g||!ee)return;let te=il(t,n),ne=p.current;p.current=t;let _=he(e),v=m||ne===t&&t!==`arc`,re=v?m?{ease:_.ease,duration:_.fast}:Qc:el(_,{ease:`outQuad`,duration:160}),y=(t===`check`||t===`cross`)&&!v,ie=el(_,{ease:`inOutSine`,duration:220}),ae=[dt(r,{opacity:te.dashes,...re}),dt(c,{opacity:te.track*.28,...re}),dt(f,{opacity:te.arc,"stroke-dasharray":`${String(te.sweep)} 1`,...v?m?Qc:re:ie}),dt(h,{r:te.disc*al,...y?{delay:ie.duration*.7,...$c(_,{bounce:.35,duration:360})}:m?Qc:el(_,{ease:`inCubic`,duration:140})}),dt(g,{"stroke-dashoffset":1-te.tick,...y&&te.tick>0?{delay:ie.duration*.7+_.fast,...el(_,{ease:`outCubic`,duration:240})}:Qc}),dt(ee,{"stroke-dashoffset":1-te.cross,...y&&te.cross>0?{delay:ie.duration*.7+_.fast,...el(_,{ease:`outCubic`,duration:240})}:Qc})];return t===`cross`&&y&&_.shake>0&&ae.push(dt(e,{translateX:[0,-_.shake,_.shake,-_.shake/2,0],delay:ie.duration+_.fast,...el(_,{ease:`linear`,duration:300})})),()=>{for(let e of ae)e.cancel()}},[t,n,m]);let g=t===`arc`&&n===void 0&&!m;return(0,I.useLayoutEffect)(()=>{if(!g||!c.current||!i.current)return;let e=he(i.current),t=dt(c.current,{rotate:[0,360],...el(e,{ease:`linear`,duration:900}),loop:!0}),n=Xe(i.current,e=>{e?t.resume():t.pause()});return()=>{n(),t.revert()}},[g]),(0,L.jsxs)(`svg`,{ref:i,"aria-hidden":`true`,className:`caps-status-mark ${e??``}`,viewBox:`0 0 16 16`,focusable:`false`,children:[(0,L.jsxs)(`defs`,{children:[(0,L.jsx)(we,{id:`${r}-surface`,transform:`matrix(1.6 0 0 1.6 8 8)`}),(0,L.jsxs)(`mask`,{id:`${r}-knock`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`16`,height:`16`,children:[(0,L.jsx)(`rect`,{width:`16`,height:`16`,fill:`var(--color-white)`}),(0,L.jsx)(`path`,{ref:u,d:`M4.9 8.3 7.1 10.5 11.2 5.9`,fill:`none`,stroke:`var(--color-black)`,strokeWidth:`1.9`,strokeLinecap:`round`,strokeLinejoin:`round`,pathLength:1,strokeDasharray:`1 1`,strokeDashoffset:1-f.tick}),(0,L.jsx)(`path`,{ref:d,d:`M5.4 5.4 10.6 10.6 M10.6 5.4 5.4 10.6`,fill:`none`,stroke:`var(--color-black)`,strokeWidth:`1.9`,strokeLinecap:`round`,pathLength:1,strokeDasharray:`1 1`,strokeDashoffset:1-f.cross})]})]}),(0,L.jsx)(`circle`,{ref:a,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeDasharray:`1.7 2.2`,opacity:f.dashes}),(0,L.jsx)(`circle`,{ref:o,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,opacity:f.track*.28}),(0,L.jsx)(`g`,{ref:c,className:`caps-status-mark-spin`,children:(0,L.jsx)(`circle`,{ref:s,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,pathLength:1,strokeDasharray:`${String(f.sweep)} 1`,transform:`rotate(-90 8 8)`,opacity:f.arc})}),(0,L.jsx)(`circle`,{ref:l,cx:`8`,cy:`8`,r:f.disc*al,fill:`url(#${r}-surface)`,mask:`url(#${r}-knock)`})]})}var sl=new Set([`ring`,`arc`,`check`,`cross`]);function cl(e){return sl.has(e)}var ll={neutral:`text-base-content`,primary:`text-primary`,secondary:`text-secondary`,accent:`text-accent`,success:`text-success`,info:`text-info`,warning:`text-warning`,error:`text-error`},ul=(0,I.forwardRef)(function({className:e,label:t,glyph:n=`dot`,motion:r=`none`,tone:i=`neutral`,size:a=`default`,appearance:o=`plain`,progress:s,...c},l){return(0,L.jsxs)(`span`,{...c,className:ne(`caps-status`,a===`compact`&&`caps-status-compact`,o===`chip`&&`caps-status-chip`,e),"data-tone":o===`chip`?i:void 0,"data-glyph":n,"data-motion":r,ref:l,children:[cl(n)?(0,L.jsx)(ol,{className:ll[i],glyph:n,progress:s}):(0,L.jsx)(nl,{className:ll[i],glyph:n,motion:r}),t===void 0?null:(0,L.jsx)(`span`,{children:t})]})}),dl=(0,I.forwardRef)(function({className:e,count:t,density:n=`row`,dismissAriaLabel:r,dismissLabel:i=`Dismiss`,message:a,onDismiss:o,onRetry:s,retryAriaLabel:c,retryLabel:l=`Retry`,role:u=`status`,...d},f){return(0,L.jsxs)(`div`,{...d,className:ne(`caps-failure-line`,e),"data-density":n,ref:f,role:u,children:[(0,L.jsx)(ul,{glyph:`dot`,tone:`error`}),(0,L.jsxs)(`span`,{className:`caps-failure-line-copy`,children:[(0,L.jsx)(`span`,{children:a}),t!==void 0&&t>1?(0,L.jsxs)(`span`,{className:`caps-failure-line-count`,children:[`Failed `,t,` times`]}):null]}),s||o?(0,L.jsxs)(`span`,{className:`caps-failure-line-actions`,children:[s?(0,L.jsx)(Ae,{"aria-label":c,size:`sm`,variant:`outline`,onClick:s,children:l}):null,o?(0,L.jsx)(Ae,{"aria-label":r,size:`sm`,variant:`ghost`,onClick:o,children:i}):null]}):null]})});function fl(e){return e.name.startsWith(`.`)}function pl(e,t,n=0){return cc(e,Tc,ac.of(e,`tree`,e?.capabilities.version??0,t,n),async(e,r)=>{let i=await e.list({path:t,offset:n,limit:256});return r.throwIfAborted(),{...i,entries:i.entries.filter(e=>!fl(e))}})}function ml(){return{known:new Set,projected:new Map}}function hl(e,t){t.known.clear(),t.projected.clear(),e.resetPaths([])}function gl(e,t,n){t.length===0&&hl(e,n);for(let{request:r,listing:i}of t){let t=`${r?.path??i.path}:${String(r?.offset??0)}`,a=i.entries.filter(e=>e.type!==`symlink`).map(e=>_l(i.path,e.name,e.type)),o=n.projected.get(t)??[];n.projected.set(t,a);let s=new Set([...n.projected.values()].flat());for(let t of o)if(!s.has(t)){e.getItem(t)&&e.remove(t,{recursive:!0});for(let e of n.known)(e===t||t.endsWith(`/`)&&e.startsWith(t))&&n.known.delete(e)}vl(e,i,n.known)}}function _l(e,t,n){return`${e.endsWith(`/`)?e:`${e}/`}${t}${n===`directory`?`/`:``}`}function vl(e,t,n){let r=t.entries.filter(e=>e.type!==`symlink`).map(e=>_l(t.path,e.name,e.type)),i=r.filter(t=>!n.has(t)&&!e.getItem(t));i.length>0&&e.batch(i.map(e=>({type:`add`,path:e}))),n.add(t.path);for(let e of r)n.add(e);return i}function yl(e,t){let n=t===`/`?`/`:t.replace(/\/+$/,``);if(n!==`/`&&e!==n&&!e.startsWith(`${n}/`))return[];let r=n===`/`?e.split(`/`).filter(Boolean):e.slice(n.length).split(`/`).filter(Boolean),i=[n],a=n;for(let e of r.slice(0,-1))a=`${a===`/`?``:a}/${e}`,i.push(a);return i}function bl({app:e,rootPath:t,activePath:n}){let r=yt(),i=Hs(e),a=(0,I.useCallback)(t=>e.capabilities.subscribe(t),[e]),o=(0,I.useCallback)(()=>e.capabilities.version,[e]),s=(0,I.useSyncExternalStore)(a,o,o),c=(0,I.useMemo)(()=>({app:e,rootPath:t,computerId:i,version:s}),[e,t,i,s]),[l,u]=(0,I.useState)(null),d=l?.scope===c?l:null,f=n?yl(n,t):[],p=d?.activePath===n?d.path:f.at(-1)??t,m=new Map;for(let e of[t,...f])m.set(`${e}:0`,{path:e,offset:0});for(let e of d?.pages??[])m.set(`${e.path}:${String(e.offset)}`,e);let h=[...m.values()],g=(t,n)=>ac.of(e,`tree`,s,t,n);return{scope:c,snapshot:zn({queries:h.map(({path:t,offset:n})=>pl(e,t,n)),combine:e=>({listings:e.flatMap((e,t)=>e.data?[{request:h[t],listing:e.data}]:[]),busy:e.some(e=>e.isFetching),failure:e.find(e=>e.error)?.error??null})}),focusedPath:p,requestPage:(e,t)=>{let i=e.replace(/\/+$/,``)||`/`,a=g(i,t);r.getQueryState(a)?.status===`error`&&r.invalidateQueries({queryKey:a,exact:!0}),u(e=>({scope:c,activePath:n,path:i,pages:[...e?.scope===c?e.pages.filter(e=>e.path!==i||e.offset!==t):[],{path:i,offset:t}]}))},reload:()=>{r.invalidateQueries({queryKey:ac.of(e,`tree`,s)})}}}var xl=nt(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),Sl=nt(`FilePlus2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M3 15h6`,key:`4e2qda`}],[`path`,{d:`M6 12v6`,key:`1u72j0`}]]),Cl=nt(`FolderOpen`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),wl=(0,I.forwardRef)(function({className:e,count:t,label:n,tone:r=`neutral`,...i},a){return(0,L.jsxs)(`span`,{...i,className:ne(`inline-flex items-center gap-xs`,e),ref:a,children:[(0,L.jsx)(`span`,{className:r===`warning`?`badge badge-warning badge-sm tabular-nums caps-numeric`:`badge badge-neutral badge-sm tabular-nums caps-numeric`,children:t}),n===void 0?null:(0,L.jsx)(`span`,{className:`text-sm text-base-content`,children:n})]})}),Tl={2:`h2`,3:`h3`,4:`h4`};function El(e,t){let{reduced:n}=t,r=e&&!n,i=g(t,600),[a,o]=(0,I.useState)(r);return(0,I.useEffect)(()=>{if(o(r),!r)return;let e=globalThis.setTimeout(()=>{o(!1)},i);return()=>{globalThis.clearTimeout(e)}},[r,i]),a}var Dl=(0,L.jsx)(Ne,{decorative:!0,pace:`idle`,size:`md`,tone:`primary`,variant:`wander`}),Ol=(0,I.forwardRef)(function({actions:e,secondaryAction:t,className:n,description:r,headingLevel:i=2,primaryAction:a,suggestions:o,thinking:s=!1,title:c,visual:l,renderVisual:u,variant:d=`plain`,...f},p){let m=(0,I.useId)(),h=(0,I.useRef)(null),g=ve(h),ee=El(d===`speech`,g)&&!s,te=Tl[i],_=l??(d===`panel`?`blobs`:void 0),v=u?u({speaking:ee,thinking:s}):_===`blobs`?Dl:_,re=`${m}-reason`,y=(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(te,{ref:h,className:`empty-state-title`,id:f[`aria-labelledby`]?void 0:m,children:c}),(0,L.jsx)(`p`,{children:r}),a?(0,L.jsxs)(`div`,{className:`empty-state-primary`,children:[(0,L.jsxs)(`div`,{className:`empty-state-action-row`,children:[(0,L.jsx)(Ae,{"aria-describedby":a.disabled&&a.disabledReason?re:void 0,disabled:a.disabled,loading:a.pending===!0,onClick:a.onSelect,variant:`primary`,children:a.label}),t]}),a.disabled&&a.disabledReason?(0,L.jsx)(`span`,{className:`empty-state-reason`,id:re,children:a.disabledReason}):null]}):null,o&&o.length>0?(0,L.jsx)(`ul`,{"aria-label":`Try one of these`,className:`empty-state-suggestions`,children:o.map((e,t)=>(0,L.jsx)(`li`,{children:(0,L.jsx)(Ae,{disabled:e.disabled,loading:e.pending===!0,size:`sm`,variant:`outline`,onClick:e.onSelect,children:e.label})},`${String(t)}:${e.label}`))}):null,e?(0,L.jsx)(`div`,{className:`empty-state-actions`,children:e}):null]});return(0,L.jsxs)(`section`,{...f,"aria-labelledby":f[`aria-labelledby`]??m,className:ne(`empty-state`,d!==`plain`&&`empty-state-${d}`,n),ref:p,children:[v?(0,L.jsx)(`div`,{"aria-hidden":`true`,className:`empty-state-visual`,children:v}):null,d===`speech`?(0,L.jsx)(`div`,{className:`empty-state-bubble`,children:y}):y]})}),kl=ie([fc,d({error:v()})]);function Al(e,t){return cc(e,pc,ac.of(e,`changes`,e?.capabilities.version??0,t),async(e,n)=>{let r=kl.parse(await e.call(`gitChanges`,JSON.stringify({path:t})));if(n.throwIfAborted(),`error`in r){let e=zc(r);throw new T(e.message,{code:e.reason===`not-granted`?`CAPABILITY_DENIED`:`HOST_FAILURE`,retryable:e.reason!==`not-granted`})}return r})}var jl={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,untracked:`U`,conflicted:`C`},Ml={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,untracked:`New, not yet staged`,conflicted:`Conflicted`};function Nl(e){let t=new Map;for(let n of e.split(qe)){let e=ge(n).at(0)?.files.at(0);e!==void 0&&t.set(e.name,{patch:n,additions:e.hunks.reduce((e,t)=>e+t.additionLines,0),deletions:e.hunks.reduce((e,t)=>e+t.deletionLines,0)})}return t}export{Ho as $,ac as A,Ia as At,Bs as B,Uc as C,Ua as Ct,qc as D,Ra as Dt,Gc as E,za as Et,Js as F,Vn as Ft,Ro as G,Fs as H,Ws as I,bt as It,Ms as J,os as K,Vs as L,yt as Lt,Z as M,mr as Mt,$ as N,Yn as Nt,pc as O,Pa as Ot,Ys as P,qn as Pt,Vo as Q,Hs as R,gt as Rt,Tc as S,Ds as St,Vc as T,Ha as Tt,Ls as U,Us as V,Ps as W,zo as X,Ns as Y,Bo as Z,dl as _,ks as _t,Ol as a,ms as at,el as b,ls as bt,Sl as c,Zo as ct,pl as d,rs as dt,Uo as et,fl as f,Os as ft,bl as g,cs as gt,gl as h,ds as ht,Al as i,Ko as it,Q as j,mi as jt,sc as k,Fa as kt,xl as l,as as lt,yl as m,Es as mt,Ml as n,Go as nt,wl as o,qo as ot,hl as p,ss as pt,Ts as q,jl as r,fs as rt,Cl as s,Jo as st,Nl as t,Wo as tt,ml as u,ns as ut,ul as v,Xo as vt,Hc as w,Va as wt,$c as x,us as xt,Qc as y,Yo as yt,Gs as z};