@fungi.computer/grove 0.17.1 → 0.18.0

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.
Files changed (72) hide show
  1. package/dist/assets/{base-face-CsIbc1by.js → base-face-9ObbS-xX.js} +1 -1
  2. package/dist/assets/burger-DSUbtFiC.js +1 -0
  3. package/dist/assets/cat-Ti7rU0E2.js +1 -0
  4. package/dist/assets/conversation-toast-BxemDtnQ.js +56 -0
  5. package/dist/assets/document-Cfd1McDA.js +1 -0
  6. package/dist/assets/document-DZTTyAQ6.js +76 -0
  7. package/dist/assets/index-CQm9LO8C.js +25 -0
  8. package/dist/assets/index-D8R4KIKC.css +1 -0
  9. package/dist/assets/{mushroom-FKArpulr.js → mushroom-CXyBHPQt.js} +1 -1
  10. package/dist/assets/parakeet-BzQn0axB.js +35 -0
  11. package/dist/assets/parakeet-conversation-O1gOP0dj.js +4 -0
  12. package/dist/assets/renderer-HJftscjc.js +1 -0
  13. package/dist/assets/rolldown-runtime-CbXtAM7H.js +1 -0
  14. package/dist/assets/website-conversation-c3fqmIxA.js +1 -0
  15. package/dist/index.html +7 -12
  16. package/package.json +13 -6
  17. package/dist/assets/Effect-pxRavrBh.js +0 -76
  18. package/dist/assets/abort-signals-joV34wzR.js +0 -1
  19. package/dist/assets/anthropic-messages-CkLFXbme.js +0 -19
  20. package/dist/assets/azure-openai-responses-BjItkyTn.js +0 -1
  21. package/dist/assets/burger-BgftDtiM.js +0 -1
  22. package/dist/assets/cat-CfNEurUg.js +0 -1
  23. package/dist/assets/classifier-shared-JiMD88Sh.js +0 -1
  24. package/dist/assets/cloudflare-workers-ai-system-one-tEpgPfLW.js +0 -1
  25. package/dist/assets/compat-CxZajpXB.js +0 -2
  26. package/dist/assets/conversation-toast-DUFOMoQ9.js +0 -33
  27. package/dist/assets/diagnostics-CxvqSC4Q.js +0 -1
  28. package/dist/assets/document-BBvRlLC3.js +0 -1
  29. package/dist/assets/document-Bpcy9TTA.js +0 -1
  30. package/dist/assets/error-BTdmRKoB.js +0 -1
  31. package/dist/assets/error-body-C7MTmn8e.js +0 -1
  32. package/dist/assets/estimate-DElUjJag.js +0 -1
  33. package/dist/assets/extension-hook-Da3ATgkY.js +0 -890
  34. package/dist/assets/extensions-D2Z9guoO.js +0 -1
  35. package/dist/assets/github-copilot-headers-DRgtIyTm.js +0 -1
  36. package/dist/assets/google-generative-ai-DJB3dC5c.js +0 -1
  37. package/dist/assets/google-shared-DVq-_IDX.js +0 -8
  38. package/dist/assets/google-vertex-CYm5wNps.js +0 -1
  39. package/dist/assets/hash-yQufAZII.js +0 -1
  40. package/dist/assets/headers-FK4rgixo.js +0 -1
  41. package/dist/assets/index-BaCEAFz2.js +0 -117
  42. package/dist/assets/index-CIiuRnlU.css +0 -1
  43. package/dist/assets/mistral-conversations-DDg7eeLe.js +0 -4
  44. package/dist/assets/node.browser-CdLsHXpS.js +0 -1
  45. package/dist/assets/node.browser-HQ5SKBOf.js +0 -1
  46. package/dist/assets/openai-Cpe0uoXQ.js +0 -19
  47. package/dist/assets/openai-codex-responses-H7WhI66H.js +0 -9
  48. package/dist/assets/openai-codex.models-DXmil0i7.js +0 -1
  49. package/dist/assets/openai-completions-CkqQ2fFp.js +0 -5
  50. package/dist/assets/openai-decisions-DMV8tZy4.js +0 -2
  51. package/dist/assets/openai-prompt-cache-DXo9f3w5.js +0 -1
  52. package/dist/assets/openai-responses-Csql8sEY.js +0 -1
  53. package/dist/assets/openai-responses-shared-DAZ5Qapp.js +0 -13
  54. package/dist/assets/openrouter-cost-DOxSGpgH.js +0 -1
  55. package/dist/assets/openrouter-images-DFWtFOvI.js +0 -1
  56. package/dist/assets/parakeet-BUkzxkvS.js +0 -35
  57. package/dist/assets/parakeet-conversation-D8vRtIjX.js +0 -4
  58. package/dist/assets/pi-messages-DoPiztqV.js +0 -7
  59. package/dist/assets/preload-helper-CfILh1TC.js +0 -3
  60. package/dist/assets/provider-env-CcCbsTJq.js +0 -1
  61. package/dist/assets/provider-retry-RVfYd5Vz.js +0 -1
  62. package/dist/assets/renderer-BVZdPJB6.js +0 -1
  63. package/dist/assets/rolldown-runtime-hePW80VL.js +0 -1
  64. package/dist/assets/runtime-core-U8lOfyYX.js +0 -40
  65. package/dist/assets/sanitize-unicode-DmIE6hZJ.js +0 -1
  66. package/dist/assets/session-resources-CTNtT8Oa.js +0 -1
  67. package/dist/assets/streaming-json-Dg-jk7Sx.js +0 -6
  68. package/dist/assets/system-one-shared-D7AS4c2W.js +0 -1
  69. package/dist/assets/text-_WthCHzw.js +0 -6
  70. package/dist/assets/transform-messages-CCZNew0k.js +0 -1
  71. package/dist/assets/typesafe-system-one-Cl52u7Mq.js +0 -1
  72. package/dist/assets/website-conversation-CpPJ8N_o.js +0 -1
@@ -1 +0,0 @@
1
- import{$i as e,Jn as t,Nn as n,Qi as r,Qn as i,Ta as a,_a as o,ba as s,ea as c,fa as l,ji as ee,na as te,pa as ne,ra as re,va as ie,wa as ae,xa as oe}from"./Effect-pxRavrBh.js";import{$i as se,$o as ce,Ai as le,Bi as ue,Fi as u,Ga as d,Gi as f,Hi as p,Ka as m,Ki as de,La as fe,Mi as pe,Na as h,Pi as g,Ta as me,Ti as _,Ui as v,Va as he,Wa as y,Xi as ge,_r as _e,c as ve,ca as ye,cs as be,ea as b,gi as x,i as xe,ji as S,la as Se,oa as Ce,rr as we,sa as Te,si as Ee,ss as De,us as Oe,va as ke,vi as C,vr as Ae,wi as w,wo as je,xa as Me,xi as Ne,yr as Pe,zi as Fe}from"./extension-hook-Da3ATgkY.js";var Ie=g.pipe(f(fe(1)),f(h(80))),Le=[`CANCELLED`,`CAPABILITY_DENIED`,`CAPABILITY_REVOKED`,`COMMAND_NOT_DECLARED`,`CONFLICT`,`DAILY_LIMIT_REACHED`,`DELIVERY_PENDING`,`DISCONNECTED`,`FILE_TOO_LARGE`,`HOST_FAILURE`,`IDENTITY`,`INSUFFICIENT_CREDIT`,`INVALID_ARGUMENT`,`MEDIA_PROVIDER_FAILURE`,`MEDIA_PROVIDER_FAILURE_UNCHARGED`,`PROTOCOL`,`SAFETY_FILTER_REFUSED`,`SELECTION_CHANGED`,`SETUP_REQUIRED`,`TIMEOUT`];u({name:w(`AppError`),code:_(Le),retryable:C,need:d(g)});var T=class extends Error{code;retryable;need;constructor(e,t){super(e,{cause:t.cause}),this.name=`AppError`,this.code=t.code,this.retryable=t.retryable,this.need=t.need}};function Re(e){return`This needs ${e??`setup`} first.`}Re(void 0);function ze(e,t){console.error(JSON.stringify({source:`agar`,operation:e,failureKind:t instanceof Error?`Error`:`NonErrorThrown`}),je(t))}var Be=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 E=globalThis[Be],Ve=E?E.RpcTarget:class{},He=async function(){}.constructor,Ue=typeof Buffer<`u`?Buffer.prototype:void 0;function We(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 He.prototype:return`function`;case Array.prototype:return`array`;case Date.prototype:return`date`;case Uint8Array.prototype:case Ue: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 j.prototype:return`stub`;case M.prototype:return`rpc-promise`;default:if(E){if(t==E.RpcStub.prototype||e instanceof E.ServiceStub)return`rpc-target`;if(t==E.RpcPromise.prototype||t==E.RpcProperty.prototype)return`rpc-thenable`}return e instanceof Ve?`rpc-target`:e instanceof Error?`error`:`unsupported`}}function Ge(){throw Error(`RPC map() implementation was not loaded.`)}var Ke={applyMap:Ge,sendMap:Ge};function qe(){throw Error(`Stream implementation was not loaded.`)}var D={createWritableStreamHook:qe,createWritableStreamFromHook:qe,createReadableStreamHook:qe},O=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}}},k=class extends O{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)}}},Je=new k(Error(`Attempted to use RPC stub after it has been disposed.`)),Ye=(e,t,n)=>e.call(t,n);function Xe(e,t){let n=Ye;Ye=e;try{return t()}finally{Ye=n}}var A=Symbol(`realStub`),Ze={apply(e,t,n){let r=e.raw;return new M(Ye(r.hook,r.pathIfPromise||[],N.fromAppParams(n)),[])},get(e,t,n){let r=e.raw;if(t===A)return r;if(t in M.prototype)return r[t];if(typeof t==`string`)return new M(r.hook,r.pathIfPromise?[...r.pathIfPromise,t]:[t]);if(t===Symbol.dispose&&(!r.pathIfPromise||r.pathIfPromise.length==0))return()=>{r.hook.dispose(),r.hook=Je}},has(e,t){let n=e.raw;return t===A?!0:t in M.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.`)}},j=class e extends Ve{constructor(e,t){if(super(),!(e instanceof O)){let n=e;if(e=n instanceof Ve||n instanceof Function?st.create(n,void 0):new P(N.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,Ze)}hook;pathIfPromise;dup(){let t=this[A];return t.pathIfPromise?new e(t.hook.get(t.pathIfPromise)):new e(t.hook.dup())}onRpcBroken(e){this[A].hook.onBroken(e)}map(e){let{hook:t,pathIfPromise:n}=this[A];return Ke.sendMap(t,n||[],e)}toString(){return`[object RpcStub]`}},M=class extends j{constructor(e,t){if(e instanceof O)super(e,t??[]);else{if(t!==void 0)throw TypeError(`RpcPromise constructor expected one argument, received two.`);let n=We(e);if(n===`rpc-promise`){let t=nt(e);if(t.pathIfPromise.length>0)super(t.hook,t.pathIfPromise);else{let e=t.hook;t.hook=Je,super(e,[])}}else if(n===`rpc-thenable`)super(st.create(e,void 0),[]);else{let t=new ct(Promise.resolve(e).then(e=>new P(N.fromAppReturn(e))));t.ignoreUnhandledRejections(),super(t,[])}}}then(e,t){return rt(this).then(...arguments)}catch(e){return rt(this).catch(...arguments)}finally(e){return rt(this).finally(...arguments)}toString(){return`[object RpcPromise]`}};function Qe(e){let{hook:t,pathIfPromise:n}=e[A];return n&&n.length>0?t.get(n):t}function $e(e){let{hook:t,pathIfPromise:n}=e[A];return n?t.get(n):t.dup()}function et(e){let{hook:t,pathIfPromise:n}=e[A];if(!(n&&n.length>0))return t}function tt(e){return e[A].hook}function nt(e){return e[A]}async function rt(e){let{hook:t,pathIfPromise:n}=e[A];return n.length>0&&(t=t.get(n)),(await t.pull()).deliverResolve()}var N=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 st.create(e,t)}if(this.source===`return`){let r=this.rpcTargets?.get(e);return r?n?r.dup():(this.rpcTargets?.delete(e),r):(r=st.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 D.createWritableStreamHook(e);if(this.source===`return`){let t=this.rpcTargets?.get(e);return t?n?t.dup():(this.rpcTargets?.delete(e),t):(t=D.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 D.createReadableStreamHook(e);if(this.source===`return`){let t=this.rpcTargets?.get(e);return t?n?t.dup():(this.rpcTargets?.delete(e),t):(t=D.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(We(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?$e(t):Qe(t),t instanceof M){let e=new M(a,[]);return this.promises.push({parent:r,property:n,promise:e}),e}return this.hooks.push(a),new j(a)}case`function`:case`rpc-target`:{let n=e,r;return r=a?a.getHookForRpcTarget(n,t,i):st.create(n,t),this.hooks.push(r),new j(r)}case`rpc-thenable`:{let o=e,s;return s=a?new M(a.getHookForRpcTarget(o,t,i),[]):new M(st.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):D.createWritableStreamHook(n),this.hooks.push(r),n}case`readable`:{let n=e,r;return r=a?a.getHookForReadableStream(n,t,i):D.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 M)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=et(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 M?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(We(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=et(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)):ot(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=D.createWritableStreamHook(t),n.dispose();return}case`readable`:{let t=e,n=this.rpcTargets?.get(t);n?this.rpcTargets.delete(t):n=D.createReadableStreamHook(t),n.dispose();return}default:return}}ignoreUnhandledRejections(){this.hooks?(this.hooks.forEach(e=>{e.ignoreUnhandledRejections()}),this.promises.forEach(e=>tt(e.promise).ignoreUnhandledRejections())):this.ignoreUnhandledRejectionsImpl(this.value)}ignoreUnhandledRejectionsImpl(e){switch(We(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`:tt(e).ignoreUnhandledRejections();return;case`rpc-thenable`:e.then(e=>{},e=>{});return;default:return}}};function it(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(We(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}=nt(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 M){let{hook:t,pathIfPromise:n}=nt(e);return{hook:t,remainingPath:n||[]}}return{value:e,parent:t,owner:r}}var at=class extends O{call(e,t){let n;try{let{value:t,owner:r}=this.getValue();n=it(t,void 0,e,r)}catch(e){return t.dispose(),new k(e)}return n.hook?n.hook.call(n.remainingPath,t):typeof n.value==`function`?new ct(t.deliverCall(n.value,n.parent).then(e=>new P(e))):(t.dispose(),new k(TypeError(`'${e.join(`.`)}' is not a function.`)))}map(e,t,n){try{let r;try{let{value:t,owner:n}=this.getValue();r=it(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):Ke.applyMap(r.value,r.parent,r.owner,t,n)}catch(e){return new k(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=it(t,void 0,e,n);return r.hook?r.hook.get(r.remainingPath):new P(N.deepCopyFrom(r.value,r.parent,r.owner))}catch(e){return new k(e)}}},P=class e extends at{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(N.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 j&&this.payload.value.onRpcBroken(e)}};function ot(e){if(Symbol.dispose in e)try{e[Symbol.dispose]()}catch(e){Promise.reject(e)}}var st=class e extends at{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=>N.fromAppReturn(e)):Promise.reject(Error(`Tried to resolve a non-promise stub.`))}ignoreUnhandledRejections(){}dispose(){this.target&&=(this.refcount&&--this.refcount.count==0&&ot(this.target),void 0)}onBroken(e){let t=this.target;t&&`then`in t&&Promise.resolve(t).then(()=>{},e)}},ct=class e extends O{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)}},lt={maxBigIntDigits:16384,maxDepth:256,maxMessageSize:33554432},ut=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,dt=[`ArrayBuffer`,`DataView`,`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`BigInt64Array`,`BigUint64Array`,`Float32Array`,`Float64Array`];function ft(e){return dt.includes(e)}var pt={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},mt={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},ht=new Map;for(let e of Object.keys(mt))ht.set(mt[e],e);function gt(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 _t=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 vt(e,t){let n=await new Response(e).blob();return n.type===t?n:n.slice(0,n.size,t)}var yt={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError},F=class e{exporter;source;encodingLevel;constructor(e,t,n){this.exporter=e,this.source=t,this.encodingLevel=n}static devaluate(t,n,r=_t,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(We(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=ht.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=pt[t];!ut&&i&&(n=n.slice(),gt(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=D.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=D.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}=nt(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 lt}};function bt(e,t){return new M(new ct(new Response(t).arrayBuffer().then(t=>{let n=new Uint8Array(t),r=new Request(e,{body:n});return new P(N.fromAppReturn(r))})),[])}function xt(e,t){return new M(new ct(vt(e,t).then(e=>new P(N.fromAppReturn(e)))),[])}var I=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=N.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(!ft(t[2])){let e=t[2].slice(0,64);throw TypeError(`Unknown bytes type marker: ${e}`)}let n=t[2],r=pt[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(!ut&&r!==void 0&&gt(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=yt[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=bt(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=xt(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 M(e,[]);return this.promises.push({promise:t,parent:n,property:r}),t}return this.hooks.push(e),new M(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 M(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 M(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 j(e)}}break;case`writable`:if(typeof t[1]==`number`){let e=this.importer.importStub(t[1]),n=D.createWritableStreamFromHook(e);return this.hooks.push(e),n}break;case`readable`:if(typeof t[1]==`number`){let e=this.importer.getPipeReadable(t[1]),n=D.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}},St=16,Ct=8,wt=16,Tt=64;function Et(e){return 2+e.length*3}function Dt(e,t,n=0){if(n>=Tt)return Ct;switch(typeof e){case`string`:return Et(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 wt+e.byteLength;if(typeof Blob<`u`&&e instanceof Blob)return wt+e.size;if(e instanceof Date)return 16;if(t??=new WeakSet,t.has(e))return Ct;if(t.add(e),e instanceof Array){let r=St;for(let i of e)r+=Ct+Dt(i,t,n+1);return r}if(e instanceof Error){let r=St+Et(e.name)+Et(e.message)+Et(e.stack??``);for(let i of Object.keys(e))r+=Ct+Et(i)+Dt(e[i],t,n+1);return r}let r=St;for(let i of Object.keys(e))r+=Ct+Et(i)+Dt(e[i],t,n+1);return r}default:return 16}}var L=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 k(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)}},R=class e extends O{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)}},Ot=class extends R{session;constructor(e){super(!1,e),this.session=e.session}dispose(){if(this.session){let e=this.session;this.session=void 0,e.shutdown()}}},kt=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={...lt,...n.limits},this.exports.push({hook:t,refcount:1}),this.imports.push(new L(this,0,!1)),this.readLoop().catch(e=>this.abort(e))}getMainImport(){return new Ot(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,F.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 j){let{hook:n,pathIfPromise:r}=nt(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=F.devaluate(t.value,void 0,this,t,this.encodingLevel);this.send([`resolve`,e,n]),r&&this.releaseExport(e,1)},t=>{this.send([`reject`,e,F.devaluate(t,void 0,this,void 0,this.encodingLevel)]),r&&this.releaseExport(e,1)}).catch(t=>{try{this.send([`reject`,e,F.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 R&&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 L(this,e,!1),this.imports[e]=t),new R(!1,t)}importPromise(e){if(this.abortReason)throw this.abortReason;if(this.imports[e])return new k(Error(`Bug in RPC system: The peer sent a promise reusing an existing export ID.`));let t=new L(this,e,!0);return this.imports[e]=t,new R(!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 L(this,n,!1);this.imports.push(r);let i=new R(!1,r),a=D.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=F.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 L(this,this.imports.length,!1);return this.imports.push(i),new R(!0,i)}sendStream(e,t,n){if(this.abortReason)throw n.dispose(),this.abortReason;let r=[`pipeline`,e,t],i;try{i=F.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=Dt(a));let s=this.imports.length,c=new L(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 L(this,this.imports.length,!1);return this.imports.push(a),new R(!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`,F.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 P(new I(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 P(new I(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=D.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 P(new I(this,this.encodingLevel).evaluate(n[2])));else{let e=new I(this,this.encodingLevel).evaluate(n[2]);e.dispose(),t.resolve(new k(e.value))}}else n[0]==`resolve`&&new I(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 I(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}},At=class{#e;#t;constructor(e,t,n={}){let r;r=t?new P(N.fromAppReturn(t)):new k(Error(`This connection has no main object.`)),this.#e=new kt(e,r,n),this.#t=new j(this.#e.getMainImport())}getRemoteMain(){return this.#t}getStats(){return this.#e.getStats()}drain(){return this.#e.drain()}};function jt(e,t,n){return new At(new Mt(e),t,n).getRemoteMain()}var Mt=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))}},z,Nt=class{context;captureMap=new Map;instructions=[];constructor(e,t){this.context=z?{parent:z,captures:[],subject:z.capture(e),path:t}:{parent:void 0,captures:[],subject:e,path:t},z=this}unregister(){z=this.context.parent}makeInput(){return new Ft(this,0)}makeOutput(e){let t;try{t=F.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 Ft(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=F.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 Ft(this,this.instructions.length)}pushGet(e,t){let n=this.capture(e.dup());return this.instructions.push([`pipeline`,n,t]),new Ft(this,this.instructions.length)}capture(e){if(e instanceof Ft&&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){}};Ke.sendMap=(e,t,n)=>{let r=new Nt(e,t),i;try{i=N.fromAppReturn(Xe(r.pushCall.bind(r),()=>n(new M(r.makeInput(),[]))))}finally{r.unregister()}if(i instanceof Promise)throw i.catch(e=>{}),Error(`RPC map() callbacks cannot be async.`);return new M(r.makeOutput(i),[])};function Pt(){throw Error(`Attempted to use an abstract placeholder from a mapper function. Please make sure your map function has no side effects.`)}var Ft=class extends O{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(z)return z.pushGet(this,e);Pt()}call(e,t){t.dispose(),Pt()}map(e,t,n){for(let e of t)e.dispose();Pt()}pull(){Pt()}ignoreUnhandledRejections(){}onBroken(e){Pt()}},It=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 I(this).evaluateCopy(t);if(e.value instanceof j){let t=et(e.value);if(t){this.variables.push(t);continue}}this.variables.push(new P(e))}return new I(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 lt}};function Lt(e,t,n,r,i){let a=new It(r,new P(N.deepCopyFrom(e,t,n)));try{return a.apply(i)}finally{a.dispose()}}Ke.applyMap=(e,t,n,r,i)=>{try{let a;if(e instanceof M)throw Error(`applyMap() can't be called on RpcPromise`);if(e instanceof Array){let t=[];try{for(let a of e)t.push(Lt(a,e,n,r,i))}catch(e){for(let e of t)e.dispose();throw e}a=N.fromArray(t)}else a=e==null?N.fromAppReturn(e):Lt(e,t,n,r,i);return new P(a)}finally{for(let e of r)e.dispose()}};var Rt=class e extends O{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 ct((r===`write`?t.deliverStreamWrite(n.writer):t.deliverCall(n.writer[r],n.writer)).then(e=>new P(e)))}catch(e){return t.dispose(),new k(e)}}map(e,t,n){for(let e of t)e.dispose();return new k(Error(`Cannot use map() on a WritableStream`))}get(e){return new k(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)}},zt=262144,Bt=1073741824,Vt=65536,Ht=2,Ut=1.25,Wt=.9,Gt=3,Kt=class{now;window=zt;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?Ht:Ut,s=a*this.minRtt*o;s=Math.min(s,e.windowAtSend*o),s=e.windowFullAtSend?Math.max(s,e.windowAtSend*Wt):Math.max(s,this.window),this.window=Math.max(Math.min(s,Bt),Vt),this.inStartupPhase&&e.sentTime>=this.roundStartTime&&(this.window>this.lastRoundWindow*Ut?this.roundsWithoutIncrease=0:++this.roundsWithoutIncrease>=Gt&&(this.inStartupPhase=!1),this.roundStartTime=t,this.lastRoundWindow=this.window)}return this.bytesInFlight<this.window}};function qt(e){let t,n=!1,r=new Kt(()=>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=N.fromAppParams([n]),{promise:l,size:ee}=e.stream([`write`],c);if(ee===void 0)return l.catch(e=>{throw t===void 0&&(t=e),e});{let{token:e,shouldBlock:n}=r.onSend(ee);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`],N.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`],N.fromAppParams([n]));r.then(()=>o(),()=>o())}})}var Jt=class e extends O{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 k(Error(`Cannot call methods on a ReadableStream stub`))}map(e,t,n){for(let e of t)e.dispose();return new k(Error(`Cannot use map() on a ReadableStream`))}get(e){return new k(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){}};D.createWritableStreamHook=Rt.create,D.createWritableStreamFromHook=qt,D.createReadableStreamHook=Jt.create;var Yt=j,Xt=Ve,Zt=jt;function Qt(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 $t(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 en(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 tn=[2,3],nn=`fungi.app.ready.v3`,rn=`fungi.app.ready`,an=`fungi.app.connect`,B=e=>g.pipe(f(fe(1)),f(h(e))),on=e=>d(B(e)),sn=pe.pipe(f(me()),f(y(Number.isSafeInteger,{message:`Expected a safe integer`}))),cn=sn.pipe(f(Me(0))),ln=sn.pipe(f(ke(0))),un=u({appId:B(160),releaseId:B(160),surfaceId:B(160)}),dn=u({editing:C,surface:p([B(160),le])}),fn=p([u({kind:w(`compose`),requestId:B(160),text:B(2e3)}),u({kind:w(`navigate`),requestId:B(160),params:x(u({key:B(64),value:B(4096)})).pipe(f(h(16)))})]),V=m(_([`granted`,`missing`])),pn=u({"agent.list":V,"agent.manage":V,"agent.read":V,"agent.send":V,"computer.list":V,"computer.readFile":V,"computer.writeFile":V,"computer.execute":V,"git.repository":V,"workflow.publish":V,"workflow.arm":V,"workflow.run":V,"app.events.emit":V,"llm.generation":V,"media.generation":V,"media.share":V}),mn=_([`ready`,`missing`,`unknown`]),hn=u({models:mn,media:mn,git:mn,terminal:_([`ready`,`exec-only`,`missing`,`unknown`]),terminalReason:d(g)}),gn=_([`model`,`media`,`git`,`computer`]),_n=_([`opened`,`unavailable`]),vn=u({computerId:p([B(256),le]),computerName:d(S(g)),teamHasComputers:d(S(C)),computerAccessGranted:d(C),setup:d(hn),permissions:d(pn),focus:dn,openRequest:p([le,fn]),visibility:_([`visible`,`hidden`])}),yn=_([`connecting`,`connected`,`suspended`,`disconnected`,`disposing`,`disposed`]),bn=u({altKey:C,ctrlKey:C,id:B(160),key:B(64),metaKey:C,shiftKey:C}),xn=u({action:d(v),availability:d(v),category:B(160),description:on(512),id:B(160),projections:d(v),title:B(160)}),Sn=u({arguments:d(v),commandId:B(321),origin:_([`agent`,`browser`,`keyboard`,`menu`,`palette`,`programmatic`,`slash`,`terminal`]),requestId:B(160)}),Cn=p([u({result:d(v),status:w(`handled`)}),u({error:v,status:w(`failed`)})]),wn=e=>B(e).pipe(f(y(e=>{for(let t=0;t<e.length;t+=1)if(Qt(e.charCodeAt(t)))return!1;return!0},{message:`Expected one line of plain text`}))),Tn={id:B(64),text:wn(80),end:m(C),priority:m(w(`low`))},En=m(pe.pipe(f(me()),f(Se({minimum:0,maximum:9999})))),Dn=x(p([u({...Tn,kind:w(`text`),tone:m(_([`neutral`,`success`,`warning`,`error`]))}),u({...Tn,kind:w(`button`),icon:m(_([`folder`,`ports`,`processes`,`access`])),count:En,tone:m(_([`neutral`,`success`,`warning`,`error`])),busy:m(C),title:m(wn(1024)),disabled:m(C),opens:m(w(`dialog`)),expanded:m(C)}),u({...Tn,kind:w(`toggle`),pressed:C}),u({...Tn,kind:w(`menu`),count:En,title:m(wn(1024)),options:x(u({id:B(64),text:wn(80),checked:m(C),disabled:m(C)})).pipe(f(h(16)),f(y(e=>new Set(e.map(e=>e.id)).size===e.length,{message:`Expected unique status option ids`})))})])).pipe(f(h(6)),f(y(e=>new Set(e.map(e=>e.id)).size===e.length,{message:`Expected unique status item ids`}))),On=u({computerId:B(256),path:B(1024)}),kn=B(80).pipe(f(y(e=>e.trim()===e,{message:`Expected a trimmed title`}))),H=B(64),An=B(80),jn=e=>new Set(e.map(e=>e.id)).size===e.length,Mn=u({id:H,label:An,siblings:d(x(u({id:H,label:An})).pipe(f(h(16)),f(y(jn,{message:`Expected unique crumb sibling ids`}))))}),Nn=u({id:H,label:An,icon:d(w(`play`)),variant:d(_([`primary`,`outline`,`ghost`])),tone:d(w(`destructive`)),disabled:d(C)}),Pn=e=>x(Nn).pipe(f(h(e)),f(y(jn,{message:`Expected unique header command ids`}))),Fn=u({id:H,label:An,presentation:d(w(`bead`)),tone:d(_([`neutral`,`info`,`warning`,`success`,`error`]))}),In={status:d(x(Fn).pipe(f(h(4)),f(y(jn,{message:`Expected unique header status ids`})))),crumbs:d(x(Mn).pipe(f(h(8)),f(y(jn,{message:`Expected unique crumb ids`})))),primary:d(Pn(3)),menu:d(Pn(12))},Ln=u({contractVersion:w(2),canGoBack:C,canGoForward:C,title:d(kn),...In}),Rn=u({canGoBack:C,canGoForward:C,title:d(g),...In}),zn=p([u({kind:w(`crumb`),crumbId:H,siblingId:d(H)}),u({kind:w(`action`),actionId:H})]),Bn=S(u({agentId:B(256),sessionId:B(256)})),Vn=e=>d(x(_(e)).pipe(f(h(e.length)))),Hn=u({agents:d(x(_([`agent.list`,`agent.manage`,`agent.read`,`agent.send`])).pipe(f(h(4)))),computers:d(x(_([`computer.list`,`computer.readFile`,`computer.writeFile`,`computer.execute`])).pipe(f(h(4)))),git:Vn([`git.repository`]),workflows:Vn([`workflow.publish`,`workflow.arm`,`workflow.run`]),events:Vn([`app.events.emit`]),generation:Vn([`llm.generation`,`media.generation`,`media.share`])}),Un=_([`granted`,`declined`,`customize`]),Wn=u({message:B(512),tone:d(_([`info`,`success`,`warning`,`error`]))}),Gn=_(Le);u({code:Gn.pick([`DELIVERY_PENDING`])});var Kn=u({code:Gn,message:B(512),retryable:C,need:m(Ie)}),qn=p([u({protocolVersion:w(3),type:w(nn)}),u({protocolVersion:w(2),type:w(rn)})]),Jn=u({epoch:B(160),protocolVersion:_(tn),type:w(an)}),Yn=u({epoch:B(160),protocolVersion:_(tn)}),Xn={[Symbol.dispose]:d(v)},Zn=p([u({...Xn,ok:w(!0),value:v}),u({...Xn,error:Kn,ok:w(!1)})]);function U(e,t,n=`PROTOCOL`){return ee(se(e,{onExcessProperty:`error`}),i({onFailure:e=>{throw new T(`The peer sent malformed protocol data`,{cause:e,code:n,retryable:!1})},onSuccess:t}))}function W(e){return Object.freeze(e)}function Qn(e,t){let n=e.arguments===void 0?void 0:Oe(e.arguments),r={origin:e.origin,signal:t};return n!==void 0&&Object.assign(r,{arguments:n}),W(r)}var $n=U(xn,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}),W(Ur(()=>De(t)))},`INVALID_ARGUMENT`),er=U(B(321),e=>e),tr=U(Sn,e=>{let t=e.arguments===void 0?void 0:Oe(e.arguments),n={commandId:e.commandId,origin:e.origin,requestId:e.requestId};return t!==void 0&&Object.assign(n,{arguments:t}),W(n)}),nr=U(p([ue,v]),e=>e===void 0?void 0:Oe(e)),rr=U(Jn,e=>W(e));U(Yn,e=>W(e));var ir=U(vn,e=>{let t={computerId:e.computerId,focus:W({...e.focus}),openRequest:e.openRequest===null?null:W({...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=W({...e.setup})),e.permissions!==void 0&&(t.permissions=W({...e.permissions})),W(t)}),ar=U(Kn,e=>W({...e})),or=U(dn,e=>W({...e}),`INVALID_ARGUMENT`),sr=U(un,e=>W({...e})),cr=U(yn,e=>e),lr=U(Dn,e=>W(e.map(e=>e.kind===`menu`?W({...e,options:W(e.options.map(e=>W(e)))}):W(e))),`INVALID_ARGUMENT`),ur=U(u({itemId:B(64),optionId:m(B(64)),anchor:m(u({start:pe.pipe(f(Se({minimum:0,maximum:1e5}))),width:pe.pipe(f(Se({minimum:0,maximum:1e5})))}))}),e=>W(e.anchor===void 0?{...e}:{...e,anchor:W({...e.anchor})}),`INVALID_ARGUMENT`),dr=U(On,e=>W({...e}),`INVALID_ARGUMENT`);function fr(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}),W(t)}function pr(e){let t={id:e.id,label:e.label};return e.siblings===void 0?W(t):W({...t,siblings:W(e.siblings.map(e=>W({...e})))})}function mr(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}),W(t)}function hr(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:W(e.crumbs.map(pr))}),e.primary!==void 0&&(t={...t,primary:W(e.primary.map(mr))}),e.menu!==void 0&&(t={...t,menu:W(e.menu.map(mr))}),e.status!==void 0&&(t={...t,status:W(e.status.map(fr))}),W(t)}var gr=U(Ln,hr,`INVALID_ARGUMENT`),_r=U(Rn,e=>{let t=e.title?.trim();return vr({...hr({...e,title:t===void 0||t.length===0?void 0:t}),contractVersion:2})},`INVALID_ARGUMENT`),vr=U(Ln,e=>W({...hr(e),contractVersion:2}),`INVALID_ARGUMENT`),yr=U(zn,e=>e.kind===`action`?W({...e}):W(e.siblingId===void 0?{kind:e.kind,crumbId:e.crumbId}:e),`INVALID_ARGUMENT`),br=U(Bn,e=>e===null?null:W({...e}),`INVALID_ARGUMENT`),xr=U(Hn,e=>W({agents:W([...new Set(e.agents??[])]),computers:W([...new Set(e.computers??[])]),...e.git&&{git:W([...new Set(e.git)])},...e.workflows&&{workflows:W([...new Set(e.workflows)])},...e.events&&{events:W([...new Set(e.events)])},...e.generation&&{generation:W([...new Set(e.generation)])}}),`INVALID_ARGUMENT`),Sr=U(gn,e=>e,`INVALID_ARGUMENT`);U(qn,e=>W(e));var Cr=U(B(512),e=>e),wr=U(Wn,e=>W({...e}),`INVALID_ARGUMENT`);U(u({id:B(160),repeat:C}),e=>W(e));var Tr=U(x(bn).pipe(f(h(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 W(e.map(e=>W({...e})))});function Er(e){return U(u({value:v,version:cn}),t=>W({value:e(t.value),version:t.version}))}var Dr=Er(ir),Or=U(u({capabilities:x(v).pipe(f(h(128))),context:v}),e=>W({capabilities:W(e.capabilities.map(e=>Pr(e))),context:Dr(e.context)})),kr=Er(cr),Ar=Er(Tr),jr=Er(Cr),Mr=ee(kr,e=>{if(e.value!==`connected`&&e.value!==`suspended`)throw new T(`The host lifecycle is invalid`,{code:`PROTOCOL`,retryable:!1});return W({value:e.value,version:e.version})});function Nr(e){return U(u({handle:v,id:B(160),version:ln}),t=>{if(!(t.handle instanceof Yt)&&!(e&&t.handle instanceof Xt))throw new T(`A capability handle is invalid`,{code:`PROTOCOL`,retryable:!1});return W({handle:t.handle,id:t.id,version:t.version})})}var Pr=Nr(!1),Fr=Nr(!0);function Ir(e){let t=e?Fr:Pr;return U(u({capabilities:x(v).pipe(f(h(128))),context:v,identity:v,lifecycle:v,reservedChords:v,theme:v}),e=>W({capabilities:W(e.capabilities.map(e=>t(e))),context:Dr(e.context),identity:sr(e.identity),lifecycle:Mr(e.lifecycle),reservedChords:Ar(e.reservedChords),theme:jr(e.theme)}))}var Lr=Ir(!1);Ir(!0);function G(e){return U(Zn,t=>t.ok?W({ok:!0,value:e(t.value)}):W({ok:!1,error:ar(t.error)}))}var Rr=G(Lr),zr=G(U(u({commandId:B(321)}),e=>W(e)));G(U(Cn,e=>{if(e.status===`failed`)return W({status:`failed`,error:Ur(()=>be(e.error))});let t=e.result===void 0?void 0:Oe(e.result);return W(t===void 0?{status:`handled`}:{status:`handled`,result:t})}));var Br=G(U(ue,()=>void 0)),Vr=G(U(Un,e=>e)),Hr=G(U(_n,e=>e));G(U(C,e=>e)),G(U(C,e=>e));function Ur(e){try{return e()}catch(e){throw new T(`The command metadata is invalid`,{cause:e,code:`INVALID_ARGUMENT`,retryable:!1})}}var Wr=p([u({kind:w(`saveFile`),name:B(255).pipe(f(he(/^[^\p{Cc}/\\]+$/u))),mime:B(255),bytes:Fe}),u({kind:w(`copyText`),text:g})]);function Gr(e){let n=se(Wr,{onExcessProperty:`error`})(e);if(t(n))return{kind:`refused`,reason:`invalid-request`};let r=n.success;return r.kind===`saveFile`?r.name===`.`||r.name===`..`?{kind:`refused`,reason:`invalid-request`}:r.bytes.byteLength>33554432?{kind:`refused`,reason:`too-large`}:{...r,bytes:new Uint8Array(r.bytes)}:r.text.length>1048576||new TextEncoder().encode(r.text).byteLength>1048576?{kind:`refused`,reason:`too-large`}:r}var Kr=G(U(p([u({kind:w(`saved`)}),u({kind:w(`copied`)}),u({kind:w(`refused`),reason:_([`no-user-gesture`,`too-large`,`invalid-request`,`unavailable`,`denied`,`busy`])})]),e=>W(e)));function qr(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 Jr(e){let t=new Map,n=qr(0),r=!1,i=e=>{let t=new Map;try{for(let n of e){let e=Pr(n),r=Zr(e.id,e.version);if(t.has(r))throw K(e.handle),new T(`Duplicate capability grant`,{code:`PROTOCOL`,retryable:!1});t.set(r,e.handle)}}catch(e){for(let e of t.values())K(e);throw e}return t};for(let[n,r]of i(e))t.set(n,r);let a=e=>{for(let t of e)K(t)},o=e=>{if(r)throw new T(`The app connection is disposed`,{code:`DISCONNECTED`,retryable:!0});let n=Zr(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 Yr=a().transform(t=>{let n=e(Object).safeParse(t);if(!n.success)return;let r=Object.create(n.data),i=b(u({[Symbol.dispose]:d(Te(Function))}))(r);return{owner:n.data,dispose:i[Symbol.dispose]}});function K(e){try{let t=Yr.parse(e);if(t===void 0||Xr.has(t.owner))return;Xr.add(t.owner),t.dispose?.call(t.owner)}catch(e){console.warn(`RPC value disposal failed`,e)}}var Xr=new WeakSet;function Zr(e,t){return`${e}@${String(t)}`}var Qr=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 q(e,t,n){return new Qr(e,t,n)}function J(t){let n=o(t),i=e(Object),s=o(Object.fromEntries(Object.keys(t).map(e=>[e,a().optional()])));return a().transform(e=>{let t=i.parse(e),a=Object.create(t),o=s.parse(a),c=Object.fromEntries(Object.entries(o).flatMap(([e,n])=>n===void 0?[]:[[e,r().parse(n).bind(t)]]));return{...n.parse(c),[Symbol.dispose](){K(e)}}})}function Y(e){return a().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{K(t)}})}function X(e){return r({output:ie(a().transform(t=>{try{return e.parse(t)}catch(e){throw K(t),e instanceof T?e:new T(`The capability returned a malformed result`,{cause:e,code:`PROTOCOL`,retryable:!1})}}))})}var $r=X(Y(te())),ei=J({fetch:X(e(Response)),close:$r}),ti=oe().trim().min(1).max(256).refine(e=>!/[\p{Cc}\p{Cf}]/u.test(e),{message:`An Agent name cannot contain control or invisible characters`}),Z=g.pipe(f(fe(1)),f(h(256))),ni=de(e=>Ee.safeParse(e).success,{expected:`an Avatar v1 descriptor`}),Q=u({agentId:Z,name:Z,avatar:ni,sessionOperations:x(_([`agent.read`,`agent.send`,`agent.manage`]))});l(()=>s({agents:re(s({agentId:oe(),name:oe()}))}));var ri=p([_([`new`,`none`]),u({computerId:Z})]),ii=u({computerId:Z,name:Z,createdAt:pe.pipe(f(me()))}),ai=S(x(ii)),oi=b(ai,{onExcessProperty:`error`}),si=u({name:Z,requestId:Z,computer:m(ri),avatar:m(ni)}),ci=x(Q),li=b(ci,{onExcessProperty:`error`}),ui=b(Z),di=b(Te(Response)),fi=q(`agent.list`,1,l(()=>J({list:X(Y(a().transform(e=>li(e))))}))),pi=q(`agent.manage`,1,l(()=>J({open:X(ei),computers:X(Y(a().transform(e=>oi(e)))),create:X(Y(a().transform(e=>b(Q)(e))))}))),mi=u({agentId:Z,name:Z}),hi=q(`agent.rename`,1,l(()=>J({rename:X(Y(a().transform(e=>b(Q)(e))))})));async function gi(e,t){let n=b(mi)(t),r=await e.require(hi).rename(n);return b(Q)(r)}var _i=u({agentId:Z,avatar:ni}),vi=q(`agent.avatar`,1,l(()=>J({setAvatar:X(Y(a().transform(e=>b(Q)(e))))})));async function yi(e,t){let n=b(_i)(t),r=await e.require(vi).setAvatar(n);return b(Q)(r)}var bi=u({agentId:Z}),xi=u({agentId:Z,expectedContent:S(g),content:g}),Si=u({agentId:Z,home:S(u({name:g})),content:S(g),bytes:Ne.pipe(f(Me(0))),limit:Ne.pipe(f(ke(0)))}),Ci=q(`agent.instructions`,2,l(()=>J({read:X(Y(a().transform(e=>b(Si)(e)))),set:X(Y(a().transform(e=>b(Si)(e))))})));async function wi(e,t){let n=b(bi)({agentId:t});return b(Si)(await e.require(Ci).read(n))}async function Ti(e,t){let n=b(xi)(t);return b(Si)(await e.require(Ci).set(n))}var Ei=l(()=>ae([o({status:ne(`pending`),revision:oe()}),o({status:ne(`approved`),revision:oe()})])),Di=l(()=>ae([Ei,o({error:oe()})])),Oi=q(`agent.toolPolicy`,1,l(()=>J({status:X(Y(ae([Ei,c()]))),approve:X(Y(Di))}))),ki=q(`agent.read`,1,l(()=>J({open:X(ei),openInbox:X(ei)}))),$=q(`agent.send`,1,l(()=>J({open:X(ei),openInbox:X(ei)})));async function Ai(e,t){let n=b(si)(t),r=await e.require(pi).create(n);return b(Q)(r)}async function ji(e){let t=oi(await e.require(pi).computers());return t===null?null:[...t].sort((e,t)=>t.createdAt-e.createdAt)}async function Mi(e,t){let n=await e(),r,i,a=()=>{if(i)throw new T(`The Agent connection is closed`,{code:`DISCONNECTED`,retryable:!0})},o=async e=>{try{await e.close()}finally{e[Symbol.dispose]()}};return{fetch:async i=>{a(),i.signal.throwIfAborted();let o=i.method===`GET`||i.method===`HEAD`||e===t?n:await(r??=t());a(),i.signal.throwIfAborted();let s=di(await o.fetch(i));return s.body===null?s:new Response(s.body.pipeThrough(new TransformStream,{signal:i.signal}),s)},close:()=>(i||(i=Promise.all([o(n),...r?[r.then(o)]:[]]).then(()=>void 0),i.catch(e=>{ze(`agents.close`,e)})),i)}}var Ni=`https://agent-session.fungi.invalid`;async function Pi(e,t){let n=ui(t.agentId),r=`/agents/id-${encodeURIComponent(n)}`,i=`${Ni}${r}`,a=e.has(ki)?e.require(ki):e.has($)?e.require($):e.require(pi),o=()=>a.open({agentId:n}),s=await Mi(o,e.has(ki)?()=>(e.has($)?e.require($):e.require(pi)).open({agentId:n}):o);return Object.freeze({baseUrl:i,fetch:async(e,t)=>{let n=new Request(e,t),i=new URL(n.url);if(i.origin!==Ni||!i.pathname.startsWith(`${r}/`))throw new T(`The Agent request target is invalid`,{code:`INVALID_ARGUMENT`,retryable:!1});return i.pathname=i.pathname.slice(r.length),s.fetch(new Request(i,n))},close:s.close})}var Fi=`${Ni}/member`;async function Ii(e){let t=e.has(ki)?ki:$,n=()=>e.require(t).openInbox(),r=await Mi(n,e.has(ki)?()=>e.require($).openInbox():n);return Object.freeze({baseUrl:Fi,fetch:async(e,t)=>{let n=new Request(e,t),i=new URL(n.url);if(i.origin!==Ni||!i.pathname.startsWith(`/member/inbox`))throw new T(`The inbox request target is invalid`,{code:`INVALID_ARGUMENT`,retryable:!1});return i.pathname=i.pathname.slice(7),r.fetch(new Request(i,n))},close:r.close})}Object.freeze({module:_e,operation:Ae,gate:Pe}),ge(we),b(Ce(we));var Li=class extends n()(`@fungi.computer/shiitake/ExtensionRead`){},Ri=class extends n()(`@fungi.computer/shiitake/ExtensionTx`){},zi=class extends ce(`ExtensionStateError`){},Bi=class extends ce(`AdmissionError`){},Vi=class extends ce(`ExtensionCommandError`){},Hi=class extends ce(`ExtensionStop`){};ce(`ExtensionActivationError`),b(xe),b(ve),ye(g);export{_r as $,Jr as A,tr as B,Ti as C,X as D,J as E,Rr as F,Er as G,rr as H,Gr as I,sr as J,or as K,Kr as L,qr as M,Qn as N,$r as O,br as P,gr as Q,$n as R,yi as S,ei as T,ir as U,nr as V,ar as W,dr as X,cr as Y,yr as Z,ji as _,Xt as _t,Hi as a,Hr as at,wi as b,T as bt,Ci as c,Cr as ct,ti as d,an as dt,Vr as et,hi as f,nn as ft,Ai as g,Yt as gt,Oi as h,$t as ht,zi as i,Sr as it,K as j,q as k,fi as l,wr as lt,$ as m,en as mt,Vi as n,zr as nt,Ri as o,ur as ot,ki as p,rn as pt,Or as q,Li as r,Tr as rt,vi as s,lr as st,Bi as t,xr as tt,pi as u,Br as ut,Pi as v,Zt as vt,Y as w,gi as x,Ii as y,ze as yt,er as z};
@@ -1 +0,0 @@
1
- function e(e){let t=e[e.length-1];return t&&t.role!==`user`?`agent`:`user`}function t(e){return e.some(e=>e.role===`user`&&Array.isArray(e.content)||e.role===`toolResult`&&Array.isArray(e.content)?e.content.some(e=>e.type===`image`):!1)}function n(t){let n={"X-Initiator":e(t.messages),"Openai-Intent":`conversation-edits`};return t.hasImages&&(n[`Copilot-Vision-Request`]=`true`),n}export{t as n,n as t};
@@ -1 +0,0 @@
1
- import{n as e}from"./text-_WthCHzw.js";import{a as t,n,s as r}from"./preload-helper-CfILh1TC.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a,t as o}from"./error-body-C7MTmn8e.js";import{n as s}from"./headers-FK4rgixo.js";import{t as c}from"./sanitize-unicode-DmIE6hZJ.js";import{i as l}from"./transform-messages-CCZNew0k.js";import{a as u,c as d,d as f,f as p,i as m,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./google-shared-DVq-_IDX.js";import{calculateCost as w,clampThinkingLevel as T,getIdentityHeaders as E}from"./compat-CxZajpXB.js";var D=0,O=(e,t,r)=>{let s=new i,c=n(t);return(async()=>{let t={role:`assistant`,content:[],api:`google-generative-ai`,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`pending`,timestamp:Date.now()};try{if(r?.fetch&&r.fetch!==globalThis.fetch)throw Error(`Custom fetch is not supported by the Google Generative AI adapter`);let n=r?.apiKey;if(!n)throw Error(`No API key for provider: ${e.provider}`);let i=A(e,n,r?.headers,r?.identity),a=j(e,c,r),o=await r?.onPayload?.(a,e);o!==void 0&&(a=o);let l=await h(()=>i.models.generateContentStream(a),r);s.push({type:`start`,partial:t});let f=null,p=t.content,g=()=>p.length-1;for await(let n of l){await r?.onProviderStreamEvent?.(n,e),t.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=m(e);(!f||n&&f.type!==`thinking`||!n&&f.type!==`text`)&&(f&&(f.type===`text`?s.push({type:`text_end`,contentIndex:p.length-1,content:f.text,partial:t}):s.push({type:`thinking_end`,contentIndex:g(),content:f.thinking,partial:t})),n?(f={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(f),s.push({type:`thinking_start`,contentIndex:g(),partial:t})):(f={type:`text`,text:``},t.content.push(f),s.push({type:`text_start`,contentIndex:g(),partial:t}))),f.type===`thinking`?(f.thinking+=e.text,f.thinkingSignature=d(f.thinkingSignature,e.thoughtSignature),s.push({type:`thinking_delta`,contentIndex:g(),delta:e.text,partial:t})):(f.text+=e.text,f.textSignature=d(f.textSignature,e.thoughtSignature),s.push({type:`text_delta`,contentIndex:g(),delta:e.text,partial:t}))}if(e.functionCall){f&&=(f.type===`text`?s.push({type:`text_end`,contentIndex:g(),content:f.text,partial:t}):s.push({type:`thinking_end`,contentIndex:g(),content:f.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++D}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),s.push({type:`toolcall_start`,contentIndex:g(),partial:t}),s.push({type:`toolcall_delta`,contentIndex:g(),delta:JSON.stringify(r.arguments),partial:t}),s.push({type:`toolcall_end`,contentIndex:g(),toolCall:r,partial:t})}}i?.finishReason&&(t.rawStopReason=i.finishReason,t.stopReason=u(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&t.stopReason===`stop`&&(t.stopReason=`toolUse`)),n.usageMetadata&&(t.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:n.usageMetadata.thoughtsTokenCount||0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},w(e,t.usage))}if(f&&(f.type===`text`?s.push({type:`text_end`,contentIndex:g(),content:f.text,partial:t}):s.push({type:`thinking_end`,contentIndex:g(),content:f.thinking,partial:t})),r?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`pending`)throw Error(`Google stream ended without a finish reason`);if(t.stopReason===`aborted`||t.stopReason===`error`){let e=t.rawStopReason?`Provider stopped with: ${t.rawStopReason}`:`An unknown error occurred`;throw Error(e)}s.push({type:`done`,reason:t.stopReason,message:t}),s.end()}catch(e){t.stopReason=r?.signal?.aborted?`aborted`:`error`,t.errorMessage=o(a(e)),s.push({type:`error`,reason:t.stopReason,error:t}),s.end()}})(),s},k=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...l(e,t,n,r),toolChoice:n?.toolChoice};if(!n?.reasoning)return O(e,t,{...i,thinking:{enabled:!1}});let a=T(e,n.reasoning);if(a===`off`)return O(e,t,{...i,thinking:{enabled:!1}});let o=x(e,a);return y(e)?O(e,t,{...i,thinking:{enabled:!0,level:p(o)}}):O(e,t,{...i,thinking:{enabled:!0,budgetTokens:M(e,o,n.thinkingBudgets)}})};function A(e,t,n,r){let i={};e.baseUrl&&(i.baseUrl=e.baseUrl,i.apiVersion=``);let a=s(E(e,r),e.headers,n);return a&&(i.headers=a),new g({apiKey:t,httpOptions:Object.keys(i).length>0?i:void 0})}function j(n,i,a={}){let o=S(n,i),s=r(i.messages),l=t(i.messages),u={};a.temperature!==void 0&&(u.temperature=a.temperature),a.maxTokens!==void 0&&(u.maxOutputTokens=a.maxTokens);let d=C(n.id),p=l.length>0?v(l,a.toolChoice,d):void 0,m=s?e(s):``,h={...Object.keys(u).length>0&&u,...m&&{systemInstruction:c(m)},...l.length>0&&{tools:_(l,!1,d)},...p!==void 0&&{toolConfig:{functionCallingConfig:{mode:p}}}};if(a.thinking?.enabled&&n.reasoning){let e={includeThoughts:!0};a.thinking.level===void 0?a.thinking.budgetTokens!==void 0&&(e.thinkingBudget=a.thinking.budgetTokens):e.thinkingLevel=f(a.thinking.level),h.thinkingConfig=e}else n.reasoning&&a.thinking&&!a.thinking.enabled&&(h.thinkingConfig=b(n));if(a.signal){if(a.signal.aborted)throw Error(`Request aborted`);h.abortSignal=a.signal}return{model:n.id,contents:o,config:h}}function M(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash-lite`)?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{O as stream,k as streamSimple};