@fungi.computer/grove 0.2.1 → 0.3.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.
- package/dist/assets/{anthropic-messages-NIo9paF2.js → anthropic-messages-BrTyy87S.js} +3 -3
- package/dist/assets/{azure-openai-responses-DVDapogw.js → azure-openai-responses-CxbiKRMB.js} +1 -1
- package/dist/assets/burger-Zw2lKYST.js +1 -0
- package/dist/assets/cat-Dg3HQp8e.js +1 -0
- package/dist/assets/{compat-wIVDvT_3.js → compat-DgqxVOn_.js} +2 -2
- package/dist/assets/{extension-hook-DCZVg8jj.js → extension-hook-CBuX_bUG.js} +117 -117
- package/dist/assets/extensions-DEfvRHbZ.js +1 -0
- package/dist/assets/{google-generative-ai-CrPXPiH2.js → google-generative-ai-0DBJk_8o.js} +1 -1
- package/dist/assets/{google-shared-CSSwo4u4.js → google-shared-BL1Pe-wK.js} +1 -1
- package/dist/assets/{google-vertex-G6njJPqz.js → google-vertex-DFCQBu0N.js} +1 -1
- package/dist/assets/index-HgPChePI.js +171 -0
- package/dist/assets/{index-BmdZJzrt.css → index-u-fIUxtz.css} +1 -1
- package/dist/assets/{mistral-conversations-DYDnZWmT.js → mistral-conversations-C3vHwl30.js} +1 -1
- package/dist/assets/{mushroom-CO06GGdJ.js → mushroom-DcQ2lek6.js} +1 -1
- package/dist/assets/{node.browser-BJm5CXR1.js → node.browser-C4Y5T0IC.js} +1 -1
- package/dist/assets/{openai-codex-responses-dWbmTJNd.js → openai-codex-responses-CK2Z6kMm.js} +1 -1
- package/dist/assets/{openai-completions-2Qvw2FRG.js → openai-completions-C35dP-q-.js} +1 -1
- package/dist/assets/{openai-responses-BvoV9Y7s.js → openai-responses-DPFd_3HO.js} +1 -1
- package/dist/assets/{openai-responses-shared-JWDc0New.js → openai-responses-shared-DaKV5GAS.js} +1 -1
- package/dist/assets/parakeet-conversation-Di3EPCdu.js +4 -0
- package/dist/assets/{renderer-DPA8RMmh.js → renderer-cVoUiOqk.js} +1 -1
- package/dist/assets/runtime-core-DOL1texL.js +1 -0
- package/dist/assets/{transform-messages-DdT3SC0y.js → transform-messages-utWG7TCG.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +10 -10
- package/dist/assets/burger-CdmYCtZ0.js +0 -1
- package/dist/assets/cat-DPVVX4Jw.js +0 -1
- package/dist/assets/extensions-CVJs4Snj.js +0 -1
- package/dist/assets/index-BJuRfQVe.js +0 -171
- package/dist/assets/parakeet-conversation-CN_nK0S9.js +0 -4
- package/dist/assets/runtime-core-DlPx0Rnp.js +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/compat-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/compat-DgqxVOn_.js","assets/preload-helper-DY31Aviq.js","assets/provider-env-CcCbsTJq.js","assets/rolldown-runtime-hePW80VL.js","assets/diagnostics-CxvqSC4Q.js","assets/models-BM_0GHMS.js","assets/json-parse-M7s0500m.js","assets/openai-codex-responses-CK2Z6kMm.js","assets/headers-FK4rgixo.js","assets/transform-messages-utWG7TCG.js","assets/runtime-core-DOL1texL.js","assets/Effect-BY0T-p9d.js","assets/index-HgPChePI.js","assets/document-DjWTbvB5.js","assets/base-face-Dc6wvM5e.js","assets/index-u-fIUxtz.css","assets/extensions-DEfvRHbZ.js","assets/error-body-pkrba6pf.js","assets/openai-prompt-cache-DXo9f3w5.js","assets/openai-responses-shared-DaKV5GAS.js","assets/sanitize-unicode-DmIE6hZJ.js","assets/hash-yQufAZII.js","assets/abort-signals-joV34wzR.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{$ as e,$i as t,$n as n,$r as r,$t as i,A as a,Ai as o,An as s,Ar as c,At as l,B as u,Br as d,Bt as f,C as p,Ci as m,Cr as ee,Ct as te,D as ne,Di as h,Dn as re,Dr as ie,Dt as ae,E as oe,Ei as se,En as ce,Er as le,Et as ue,Fr as de,Ft as fe,G as pe,Gi as me,Gr as g,Gt as he,H as ge,Hi as _e,Hn as ve,Hr as ye,Ht as be,I as xe,In as Se,Ir as Ce,It as we,J as Te,Ji as Ee,Jr as De,Jt as Oe,K as ke,Ki as Ae,Kn as je,Kr as Me,Kt as Ne,L as Pe,Ln as Fe,Lr as Ie,Lt as Le,M as Re,Mr as ze,Mt as Be,N as Ve,Nn as He,Nr as Ue,Nt as We,O as Ge,Oi as Ke,On as qe,Or as Je,Ot as Ye,P as Xe,Pn as Ze,Pr as Qe,Pt as $e,Qi as et,Qn as tt,Qr as nt,Qt as rt,R as it,Rn as at,Rr as ot,Rt as st,S as ct,Si as lt,So as ut,Sr as dt,St as _,T as ft,Ti as pt,Tn as mt,Tr as ht,U as gt,Un as _t,Ur as vt,Ut as yt,V as bt,Vn as xt,Vr as St,Vt as Ct,W as wt,Wi as Tt,Wn as Et,Wt as Dt,X as Ot,Xi as kt,Xr as At,Xt as jt,Y as Mt,Yr as Nt,Yt as Pt,Z as Ft,Zr as It,Zt as Lt,_ as Rt,_a as zt,_i as Bt,_n as Vt,_o as Ht,_r as Ut,_t as Wt,a as Gt,aa as Kt,ai as qt,an as Jt,b as Yt,bi as Xt,bn as Zt,br as Qt,bt as $t,c as en,ca as tn,ci as nn,cn as rn,cr as an,ct as on,d as sn,da as cn,di as ln,dn as un,dr as dn,dt as v,ea as fn,en as pn,er as mn,et as hn,f as gn,fi as _n,fn as vn,fr as yn,ft as bn,g as y,gi as xn,gn as Sn,gt as Cn,h as wn,ha as Tn,hi as En,hn as Dn,hr as On,i as kn,ia as b,ii as An,in as jn,ir as Mn,it as Nn,j as x,jn as Pn,jr as Fn,jt as In,k as Ln,ki as Rn,kn as zn,kr as Bn,kt as Vn,l as Hn,la as Un,li as Wn,ln as Gn,lr as Kn,lt as qn,m as Jn,ma as S,mi as Yn,mn as Xn,mr as Zn,mt as Qn,na as $n,ni as er,nn as tr,nt as nr,o as rr,oa as ir,oi as ar,on as or,or as sr,ot as cr,p as lr,pa as ur,pi as dr,pn as fr,pr,pt as C,q as mr,qi as hr,qn as gr,qt as _r,r as vr,ra as yr,ri as br,rn as xr,rt as Sr,s as Cr,sa as wr,si as Tr,sn as Er,t as Dr,ta as Or,ti as kr,tn as Ar,tt as jr,u as Mr,ui as Nr,un as Pr,ur as Fr,ut as Ir,v as Lr,va as Rr,vi as zr,vn as Br,vt as Vr,w as Hr,wr as Ur,wt as Wr,x as Gr,xi as Kr,xr as qr,xt as Jr,y as w,yi as Yr,yn as Xr,yr as Zr,yt as Qr,z as $r,zr as ei,zt as ti}from"./Effect-BY0T-p9d.js";import{l as ni,t as ri}from"./preload-helper-DY31Aviq.js";var ii=e=>e>0?Math.floor(e):0,ai=e=>Math.max(1,ii(e)),oi=e=>{let t=e[Symbol.iterator]().next();if(t.done)throw Error(`headUnsafe: empty iterable`);return t.value},si=`~effect/BigDecimal`,ci={[si]:si,[qt](){let e=gi(this);return kr(An(String(e.value)),br(e.scale))},[r](e){return li(e)&&xi(this,e)===0},toString(){return`BigDecimal(${Ci(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[ei](){return this.toJSON()},pipe(){return o(this,arguments)}},li=e=>ar(e,si),ui=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(ci);return n.value=e,n.scale=t,n},di=(e,t)=>{let n=ui(e,t);return n.normalized=n,n},fi=BigInt(0),pi=BigInt(1),mi=BigInt(10),hi=di(fi,0),gi=e=>{if(e.normalized===void 0){if(e.value===fi)e.normalized=hi;else{let t=`${e.value}`,n=t.length;for(;t[n-1]===`0`;)n--;e.normalized=di(BigInt(t.slice(0,n)),e.scale-(t.length-n))}}return e.normalized},_i=100,vi=[pi],yi=(e,t)=>e===t?0:e<t?-1:1,bi=(e,t)=>{let n=`${e.value<fi?-e.value:e.value}`,r=`${t.value<fi?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==fi)return i<fi?-1:1;let a=Math.max(n.length,r.length);return dn(n.padEnd(a,`0`),r.padEnd(a,`0`))},xi=(e,t)=>{if(e.scale===t.scale)return yi(e.value,t.value);let n=Si(e),r=Si(t);if(n!==r)return n<r?-1:1;if(n===0)return 0;let i=e.scale-t.scale,a=Math.abs(i);if(a>_i)return n===-1?bi(t,e):bi(e,t);let o=vi[a]??=mi**BigInt(a);return i>0?yi(e.value,t.value*o):yi(e.value*o,t.value)},Si=e=>e.value===fi?0:e.value<fi?-1:1,Ci=e=>{let t=gi(e);if(Math.abs(t.scale)>=16)return wi(t);let n=t.value<fi,r=`${n?-t.value:t.value}`,i=t.scale>0?r.padStart(t.scale+1,`0`):r.padEnd(r.length-t.scale,`0`),a=i.length-t.scale,o=t.scale>0?`${i.slice(0,a)}.${i.slice(a)}`:i;return n?`-${o}`:o},wi=e=>{if(Ti(e))return`0e+0`;let t=gi(e),n=`${t.value}`,r=t.value<fi?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},Ti=e=>e.value===fi,Ei=Qt,Di=`~effect/encoding/EncodingError`,Oi=class extends Ei(`EncodingError`){[Di]=Di},ki=Ue,Ai=Ur,ji=ee,Mi=dt,Ni=rt,Pi=l,Fi=Be,Ii=Oe,Li=Pt,Ri=_r,zi=In,Bi=Fn,Vi=ht;ce()(`effect/Cause/StackTrace`),ce()(`effect/Cause/InterruptorStackTrace`);var Hi=c,Ui=Bn,Wi=Je,Gi=ie,Ki=Ct,qi=ti,Ji=st,Yi=f,Xi=we,Zi={"~effect/Deferred":{_A:pt,_E:pt},pipe(){return o(this,arguments)}},Qi=function(){this.resumes=void 0,this.effect=void 0};Qi.prototype=Zi;var $i=()=>new Qi,ea=()=>Vt(()=>$i()),ta=e=>Ye(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),Vt(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),na=m(2,(e,t)=>Vt(()=>aa(e,t))),ra=m(2,(e,t)=>na(e,Je(t))),ia=m(2,(e,t)=>na(e,c(t))),aa=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let n=e.resumes;e.resumes=void 0;for(let e=0;e<n.length;e++)n[e](t)}return!0},oa=fr,sa=un,ca=vn,la=jn,ua=Er,da=or,fa=Gn,pa=Pr,ma=rn,ha=$e,ga=`~effect/DateTime`,_a=`~effect/DateTime/TimeZone`,va={[ga]:ga,pipe(){return o(this,arguments)},[ei](){return this.toString()},toJSON(){return ba(this).toJSON()}};({...va}),{...va};var ya={[_a]:_a,[ei](){return this.toString()}};({...ya}),{...ya};var ba=e=>new Date(e.epochMilliseconds);globalThis.Number;var xa=m(2,(e,t)=>{if(!globalThis.Number.isFinite(e)||!globalThis.Number.isFinite(t)||t===0)return NaN;if(globalThis.Number.isInteger(e)&&globalThis.Number.isInteger(t))return e%t;let[n,r]=Sa(e),[i,a]=Sa(t),o=Math.min(r,a),s=n*BigInt(10)**BigInt(r-o)%(i*BigInt(10)**BigInt(a-o));if(s===BigInt(0))return e<0||Object.is(e,-0)?-0:0;let c=globalThis.Number(`${s}e${o}`);return c===0?Math.sign(e)*globalThis.Number.MIN_VALUE:c});function Sa(e){if(globalThis.Number.isInteger(e))return[BigInt(e),0];let t=Math.abs(e).toExponential(),n=t.indexOf(`e`),r=t.slice(0,n).replace(`.`,``);return[BigInt(r)*(e<0?-BigInt(1):BigInt(1)),globalThis.Number(t.slice(n+1))-r.length+1]}globalThis.String;var Ca=e=>e.trim(),wa=m(2,(e,t)=>Vn(e,Oa,e=>t(e))),Ta=e=>e.reasons.some(Ea),Ea=e=>e._tag===`Fail`&&Bi(e.error),Da=e=>{let t,n=!1;for(let r of e.reasons)Ea(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?at(e):n?at(Ai(e.reasons.filter(e=>!Ea(e)))):je(t)},Oa=e=>{let t=Da(e);return xt(t)?t:je(t.success.value)},ka=e=>{let t=Da(e);return xt(t)?Ui(t.failure):Hi(t.success.value)},Aa=mt(`effect/Metric/CurrentMetricAttributes`,{defaultValue:()=>({})}),ja=mt(`effect/Metric/MetricRegistry`,{defaultValue:()=>new Map}),Ma=`~effect/Metric`,Na=class{[Ma]=Ma;#e;#t=``;id;description;attributes;constructor(e,t,n){this.id=e,this.description=t,this.attributes=n}valueUnsafe(e){return this.hook(e).get(e)}modifyUnsafe(e,t){return this.hook(t).modify(e,t)}updateUnsafe(e,t){return this.hook(t).update(e,t)}hook(e){let t=zn(e,Aa);t!==this.#e&&(this.#e=t,this.#t=Ba(this,Ha(this.attributes,t)));let n=zn(e,ja),r=n.get(this.#t);return Yr(r)&&(r={id:this.id,type:this.type,description:this.description,attributes:Object.keys(t).length>0?Ha(this.attributes,t):this.attributes,hooks:this.createHooks()},n.set(this.#t,r)),r.hooks}pipe(){return o(this,arguments)}},Pa=BigInt(0),Fa=class extends Na{type=`Counter`;#e;#t;constructor(e,t){super(e,t?.description,Ua(t?.attributes)),this.#e=t?.bigint??!1,this.#t=t?.incremental??!1}createHooks(){let e=this.#e?Pa:0,t=this.#t?this.#e?e=>e>=Pa:e=>e>=0:e=>!0;return Va(()=>({count:e,incremental:this.#t}),n=>{t(n)&&(e+=n)})}},Ia=class extends Na{type;metric;valueUnsafe;updateUnsafe;modifyUnsafe;constructor(e,t,n,r){super(e.id,e.description,e.attributes),this.metric=e,this.valueUnsafe=t,this.updateUnsafe=n,this.modifyUnsafe=r,this.type=e.type}createHooks(){return this.metric.createHooks()}},La=(e,t)=>new Fa(e,t),Ra=m(2,(e,t)=>We(n=>Vt(()=>e.updateUnsafe(t,n)))),za=m(2,(e,t)=>{let n=Wa(t);return new Ia(e,t=>e.valueUnsafe(n(t)),(t,r)=>e.updateUnsafe(t,n(r)),(t,r)=>e.modifyUnsafe(t,n(r)))});function Ba(e,t){let n=Object.entries(t).sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0]));return JSON.stringify([e.type,e.id,e.description,n])}function Va(e,t,n){return{get:e,update:t,modify:n??t}}function Ha(e,t){return{...Ua(e),...Ua(t)}}function Ua(e){return _n(e)&&Array.isArray(e)?e.reduce((e,[t,n])=>(g(e,t,n),e),{}):e}function Wa(e){let t,n={};return r=>{let i=zn(r,Aa);return i!==t&&(t=i,n=Ha(i,e)),re(r,Aa,n)}}ce()(`effect/DateTime/CurrentTimeZone`);var Ga=e=>qa(typeof e==`string`?Ja.encode(e):e),Ka=e=>{let t=Ya(e),n=t.length;if(n%4!=0)return at(new Oi({kind:`Decode`,module:`Base64`,input:t,message:`Length must be a multiple of 4, but is ${n}`}));let r=t.indexOf(`=`);if(r!==-1&&(r<n-2||r===n-2&&t[n-1]!==`=`))return at(new Oi({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));try{let e=t.endsWith(`==`)?2:+!!t.endsWith(`=`),r=new Uint8Array(n/4*3-e);for(let e=0,i=0;e<n;e+=4,i+=3){let n=Qa(t.charCodeAt(e))<<18|Qa(t.charCodeAt(e+1))<<12|Qa(t.charCodeAt(e+2))<<6|Qa(t.charCodeAt(e+3));r[i]=n>>16,r[i+1]=n>>8&255,r[i+2]=n&255}return je(r)}catch(e){return at(new Oi({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},qa=e=>{let t=e.length,n=``,r;for(r=2;r<t;r+=3)n+=Xa[e[r-2]>>2],n+=Xa[(e[r-2]&3)<<4|e[r-1]>>4],n+=Xa[(e[r-1]&15)<<2|e[r]>>6],n+=Xa[e[r]&63];return r===t+1&&(n+=Xa[e[r-2]>>2],n+=Xa[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=Xa[e[r-2]>>2],n+=Xa[(e[r-2]&3)<<4|e[r-1]>>4],n+=Xa[(e[r-1]&15)<<2],n+=`=`),n},Ja=new TextEncoder,Ya=e=>e.replace(/[\n\r]/g,``),Xa=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Za=new Uint8Array(123).fill(255);for(let e=0;e<64;e++)Za[Xa.charCodeAt(e)]=e;Za[61]=0;var Qa=e=>{if(e>=Za.length||Za[e]===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return Za[e]};Ei(`CookiesError`),{...ot},{...ot};var $a=new WeakMap,eo=`~effect/Redacted`,to=e=>ar(e,eo),no=(e,t)=>{let n=Object.create(ro);return t?.label&&(n.label=t.label),$a.set(n,e),n},ro={[eo]:{_A:e=>e},label:void 0,...Zr,toJSON(){return this.toString()},toString(){return`<redacted${Bt(this.label)?`:`+this.label:``}>`},[qt](){return er($a.get(this))},[r](e){return to(e)&&At($a.get(this),$a.get(e))}};({...Zr});function io(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function ao(e){return t=>io(t)?.[e]}var oo=`~structural`,so=`~identifier`,co=`~sentinels`,lo=`~constructor`,uo=[`title`,`description`,`default`,`examples`,`readOnly`,`writeOnly`,`format`,`contentEncoding`,`contentMediaType`,`contentSchema`],fo=ao(`identifier`),po=ao(so),mo=ao(`title`),ho=ao(`description`),go=se(e=>{let t=io(e)?.identifier;return typeof t==`string`?t:e.getExpected(go)}),_o=new Set([co,oo,`representation`,`arbitraryConstraint`,`toJsonSchema`,`toCode`,`toEquivalence`,`toFormatter`,`toCodec`,`toCodecJson`,`toCodecStringTree`,`toCodecIso`,`toCodecArbitrary`]),T=Symbol(),vo=Hi,yo=vo(T),bo=vo(T),xo=e=>e===T?Mn():sr(e),So=e=>e._tag===`None`?yo:vo(e.value),Co=`~effect/SchemaIssue/Issue`;function wo(e){return ar(e,Co)&&e[Co]===Co}function To(e){return Object.hasOwn(e,`input`)}var Eo=class{[Co]=Co;constructor(e,t){t?.reportInput===!0&&e!==T&&(this.input=e)}},Do=class extends Eo{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},Oo=class extends Eo{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},ko=class extends Eo{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},Ao=class extends Eo{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},jo=class extends Eo{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Mo=class extends Eo{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},No=class extends Eo{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Po=class extends Eo{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Fo=class extends Eo{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Io=class extends Eo{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},Lo=class extends Eo{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Ro(e,t,n){if(wo(e))return e;if(typeof e==`string`)return new Po({message:e},t,n);let r=typeof e.issue==`string`?new Po({message:e.issue},t,n):e.issue;return new ko(e.path,r)}function zo(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Po(void 0,t,n):Ro(e,t,n)}function Bo(e,t,n,r){return Array.isArray(t)?Ze(t)?t.length===1?Ro(t[0],n,r):new Mo(e,Se(t,e=>Ro(e,n,r)),n,r):void 0:zo(t,n,r)}var Vo=e=>{let t=Qo(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Ko(go(e.ast),e);case`InvalidValue`:{let t=Go(e);if(t!==void 0)return Ko(t,e);let n=Wo(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Wo(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Wo(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},Ho=e=>Qo(e.issue)??Qo(e);function Uo(e){return t=>({issues:qo(t,[],e?.leafHook??Vo,e?.checkHook??Ho)})}function Wo(e){return To(e)?d(e.input):void 0}function Go(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Ko(e,t){let n=Wo(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function qo(e,t,n,r){switch(e._tag){case`Filter`:{let i=r(e);if(i!==void 0)return[{path:t,message:i}];if(e.issue._tag!==`InvalidValue`)return qo(e.issue,t,n,r);let a=Go(e.issue);return[{path:t,message:a===void 0?Ko(Jo(e.filter),e):Ko(a,e.issue)}]}case`Encoding`:return qo(e.issue,t,n,r);case`Pointer`:return qo(e.issue,[...t,...e.path],n,r);case`Composite`:return e.issues.flatMap(e=>qo(e,t,n,r));case`AnyOf`:return e.issues.length===0?[{path:t,message:Qo(e)??Ko(go(e.ast),e)}]:e.issues.flatMap(e=>qo(e,t,n,r));default:return[{path:t,message:n(e)}]}}function Jo(e){let t=e.annotations?.expected;if(typeof t==`string`)return t;switch(e._tag){case`Filter`:return`<filter>`;case`FilterGroup`:return e.checks.map(e=>Jo(e)).join(` & `)}}function Yo(){return e=>Zo(e,``)}var Xo=Yo();function Zo(e,t){let n;switch(e._tag){case`Filter`:{let r=Ho(e);if(r!==void 0)n=r;else{if(e.issue._tag!==`InvalidValue`)return Zo(e.issue,t);let r=Go(e.issue);n=r===void 0?Ko(Jo(e.filter),e):Ko(r,e.issue)}break}case`Encoding`:return Zo(e.issue,t);case`Pointer`:return Zo(e.issue,t+ye(e.path));case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>Zo(e,t)).join(`
|
|
3
|
-
`);n=Qo(e)??Ko(go(e.ast),e);break;default:n=Vo(e)}return t?`${n}\n at ${t}`:n}function Qo(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return Qo(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function $o(e){let t;for(let n of e.reasons){if(!ki(n)||!wo(n.error))return;t??=n.error}return t}function es(e,t){let n=$o(e);if(n===void 0)throw Error(t,{cause:e});return n}var ts=e=>Ga(e).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`),ns=e=>{let t=e.replace(/[\n\r]/g,``),n=t.length;if(n%4==1)return at(new Oi({module:`Base64Url`,kind:`Decode`,input:t,message:`Length should be a multiple of 4, but is ${n}`}));if(!/^[-_A-Z0-9]*?={0,2}$/i.test(t))return at(new Oi({module:`Base64Url`,kind:`Decode`,input:t,message:`Invalid input`}));let r=n%4==2?`${t}==`:n%4==3?`${t}=`:t;return r=r.replace(/-/g,`+`).replace(/_/g,`/`),Ka(r)},rs=e=>Object.assign(Object.create(Rn),e),is=rs({_tag:`Passthrough`});function as(){return is}function os(){return is}function ss(e){return rs({_tag:`Transform`,transform:e})}function cs(e){return rs({_tag:`TransformEffect`,transform:e})}function ls(e){return rs({_tag:`TransformOptional`,transform:e})}function us(e){return rs({_tag:`TransformOptionalEffect`,transform:e})}function ds(){return ls(()=>Mn())}function fs(e){return us(t=>{let n=gr(t,_n);return mn(n)?v(n):Pe(e,sr)})}function ps(){return ss(globalThis.String)}function ms(){return ss(globalThis.Number)}function hs(){return ss(globalThis.BigInt)}function gs(){return ss(e=>new globalThis.Date(e))}function _s(){return ss(Ca)}function vs(e){return cs((t,n)=>Qr({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Po({expected:`a valid JSON string`},t,n)}))}function ys(e){return cs((t,n)=>Qr({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new Po({expected:`a JSON-serializable value`},t,n)}))}function bs(){return ss(Ga)}function xs(){return cs((e,t)=>$r(a(Ka(e)),()=>new Po({expected:`a valid Base64 string`},e,t)))}var Ss=class extends Ke{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Ss(this.encode,this.decode)}},Cs=`~effect/SchemaTransformation/Transformation`,ws=class extends Ke{[Cs]=Cs;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new ws(this.encode,this.decode)}};function Ts(e){return ar(e,Cs)&&e[Cs]===Cs}var Es=e=>Ts(e)?e:new ws(e.decode,e.encode);function Ds(){return new ws(_s(),as())}var Os=new ws(as(),as());function ks(){return Os}var As=new ws(ms(),ps()),js=new ws(hs(),ps()),Ms=new ws(gs(),ss(St)),Ns=new ws(xs(),bs());function Ps(e){return new ws(vs(e??{}),ys(e))}function Fs(e){return t=>t._tag===e}var Is=Fs(`Declaration`),Ls=Fs(`Null`),Rs=Fs(`Undefined`),zs=Fs(`Never`),Bs=Fs(`String`),Vs=Fs(`Number`),Hs=Fs(`Boolean`),Us=Fs(`Literal`),Ws=Fs(`UniqueSymbol`),Gs=Fs(`Arrays`),Ks=Fs(`Objects`),qs=Fs(`Union`),Js=Fs(`Suspend`),Ys=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},Xs={},Zs=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},Qs=`~effect/Schema`,$s=class{[Qs]=Qs;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}},ec=class extends $s{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>t===T?yo:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=Dl(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new ec(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},tc=new class extends $s{_tag=`Null`;getParser(){return Jl(this,null)}getExpected(){return`null`}},nc=class extends $s{_tag=`Undefined`;getParser(){return Jl(this,void 0)}toCodecJson(){return hl(this,[rc])}getExpected(){return`undefined`}},rc=new Ys(tc,new ws(ss(()=>void 0),ss(()=>null))),ic=new nc,ac=new class extends $s{_tag=`Never`;getParser(){return Yl(this,Nr)}getExpected(){return`never`}},oc=new class extends $s{_tag=`Unknown`;getParser(){return Yl(this,Xt)}getExpected(){return`unknown`}},sc=class extends $s{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${d(e)}`);this.literal=e}getParser(){return Jl(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?cc(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:cc(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function cc(e){let t=globalThis.String(e.literal);return hl(e,[new Ys(new sc(t),new ws(ss(()=>e.literal),ss(()=>t)))])}var lc=new class extends $s{_tag=`String`;getParser(){return Yl(this,Bt)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&du(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},uc=class extends $s{_tag=`Number`;getParser(){return Yl(this,dr)}matchKey(e,t){return this._match(eu,e,t)}matchPart(e,t){return this._match($l,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:du(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(dc(this.checks,`effect/schema/isFinite`)||dc(this.checks,`effect/schema/isInt`))?this:hl(this,[ul])}toCodecStringTree(){return this.toCodecJson()===this?hl(this,[ru]):hl(this,[iu])}getExpected(){return`number`}};function dc(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&dc(e.checks,t))}var fc=new uc,pc=new class extends $s{_tag=`Boolean`;getParser(){return Yl(this,nn)}getExpected(){return`boolean`}},mc=new class extends $s{_tag=`Symbol`;getParser(){return Yl(this,zr)}matchKey(e,t){return t.disableChecks||!this.checks?e:du(this.checks,e,void 0,this,t)?void 0:e}toCodecStringTree(){return hl(this,[lu])}getExpected(){return`symbol`}},hc=new class extends $s{_tag=`BigInt`;getParser(){return Yl(this,Tr)}matchPart(e,t){if(!au.test(e))return;let n=globalThis.BigInt(e);return t.disableChecks||!this.checks?n:du(this.checks,n,void 0,this,t)?void 0:n}toCodecStringTree(){return hl(this,[su])}getExpected(){return`bigint`}},gc=class extends $s{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(Rl(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(Rl(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}let c=e=>{let{input:t,len:r,options:i}=e;if(n.rest.length===0&&r>a)for(let o=a;o<r;o++){let r=new jo(n,t[o],i),a=new ko([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return y(new Mo(n,[a],t,i))}return e.issues?y(new Mo(n,e.issues,t,i)):vo(e.output)},l=(e,t)=>{let r=e.length,i={ast:n,getParser:s,input:e,len:r,tailThreshold:Math.max(a,r-o),output:new globalThis.Array(r),issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:Jt(t.concurrency),f=d===1?yc(i,e,0,u):bc(i,e,{concurrency:d,end:u});if(!f)return c(i);if(fe(f))return Yt(f,()=>c(i));let p=!0;return bn(()=>p?(p=!1,w(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===T)return yo;try{return Array.isArray(e)?(r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)}))),l(e,a)):y(new No(n,e,a))}catch(e){return lr(e)}}}_rebuild(e,t,n){let r=Dl(this.elements,e),i=Dl(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new gc(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function _c(e,t,n,r){if(n._tag===`Failure`)return xc(e,e.ast,r,n);let i=n===bo?t:n[qr];if(i!==T)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(Rl(t.ast))return;let n=new ko([r],new Ao(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return Wi(new Mo(e.ast,[n],e.input,e.options))}}var vc={onItem(e,t,n){let r=n<e.len?t:T;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:_c},yc=pn()(vc),bc=i()(vc),xc=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=$o(r.cause);if(i===void 0)return Ui(Pi(r.cause,r=>new Mo(t,[new ko([n],r)],e.input,e.options)));let a=new ko([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return Wi(new Mo(t,[a],e.input,e.options))},Sc=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function Cc(e,t,n=Xs){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(r=>Object.prototype.propertyIsEnumerable.call(e,r)&&t.matchKey(r,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(Xl(Wl(t)))}var wc=class{name;type;constructor(e,t){this.name=e,this.type=t}};function Tc(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(Tc);default:return!1}}function Ec(e){let t=_l(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(Ec);default:return!1}}function Dc(e){return Tc(e)&&Ec(e)}var Oc=class{parameter;type;constructor(e,t){if(!Dc(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Rl(t)&&!ql(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},kc=class extends $s{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o}getParser(e,t=e){let n=this,r=n.propertySignatures.length,a=n.indexSignatures.length;if(!r&&!a)return Yl(n,ln);let o,s,c=()=>(o||(o=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type})),s=a?n.indexSignatures.map(n=>({is:n,parserKey:e(Xl(n.parameter)),parserValue:t(n.type)})):void 0),o),l=()=>{let e=new Set(n.propertySignatures.map(e=>typeof e.name==`number`?globalThis.String(e.name):e.name)),t=(t,i,a,o,s)=>{if(s._tag===`Failure`)return xc(t,n,i,s)??Ki;let c=s===bo?o:s[qr];if(a!==T&&c!==T){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return Ki;g(t.out,a,c)}return Ki},l=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!fe(t))return w(wn(t),t=>l(e,r,i,t));a=t}if(a._tag===`Failure`)return xc(e,n,r,a)??Ki;let o=a===bo?r:a[qr],s=e.input[r],c=i.parserValue(s,e.options);return fe(c)?t(e,r,o,s,c):w(wn(c),n=>t(e,r,o,s,n))},u=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return fe(a)?t(e,n,n,i,a):w(wn(a),r=>t(e,n,n,i,r))},d=a?i()({onItem:(e,[t,n])=>n.is.parameter===lc?u(e,t,n):l(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return p(function*(t,i){if(t===T)return T;if(!(typeof t==`object`&&t&&!Array.isArray(t)))return yield*y(new No(n,t,i));c();let f=t,p={},m={ast:n,input:f,out:p,issues:void 0,options:i},ee=i.errors===`all`,te=i.onExcessProperty===`error`,ne=i.concurrency===void 0?1:Jt(i.concurrency),h=a&&te?n.indexSignatures.map(e=>Cc(f,e.parameter,i)):void 0;if(te){let r=h?new Set(e):e;if(h)for(let e of h)for(let t of e)r.add(t);let a=Reflect.ownKeys(f);for(let e=0;e<a.length;e++){let o=a[e];if(!r.has(o)&&Object.prototype.propertyIsEnumerable.call(f,o)){let e=new jo(n,f[o],i),r=new ko([o],e);if(ee){m.issues?m.issues.push(r):m.issues=[r];continue}return yield*y(new Mo(n,[r],t,i))}}}if(r){let e=ne===1?Mc(m,o):Nc(m,o,{concurrency:ne});e&&(yield*e)}if(a&&ne===1)for(let e=0;e<a;e++){let t=s[e],n=t.is.parameter===lc?u:l,r=h?.[e]??(t.is.parameter===lc?Object.keys(f):Cc(f,t.is.parameter,i));for(let e=0;e<r.length;e++){let i=n(m,r[e],t);if(!fe(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(d){let e=Pn();for(let t=0;t<a;t++){let n=s[t],r=h?.[t]??(n.is.parameter===lc?Object.keys(f):Cc(f,n.is.parameter,i));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=d(m,e,{concurrency:ne});t&&(yield*t)}return m.issues?yield*y(new Mo(n,m.issues,t,i)):p})};if(a)return l();let u,d=(e,t,n)=>{let r=o[t];return w(wn(n),n=>{let i=Ac(e,r,n);if(i)return i;let a=()=>vo(e.out),s=Mc(e,o.slice(t+1));return s?Yt(s,a):a()})};return(e,t)=>{if(e===T)return yo;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&Jt(t.concurrency)!==1)return(u??=l())(e,t);if(!(typeof e==`object`&&e&&!Array.isArray(e)))return y(new No(n,e,t));let r=c(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=Kc(i,s),l=c?i[s]:T,u=n.parser(l,t);if(!fe(u))return d(o,e,u);if(u===bo){c&&g(a,s,l);continue}let f=Ac(o,n,u);if(f)return f}}catch(e){return lr(e)}return vo(a)}}_rebuild(e,t,n,r){let i=Dl(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new wc(t.name,n)}),a=Dl(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new Oc(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new kc(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function Ac(e,t,n){if(n._tag===`Failure`)return xc(e,e.ast,t.name,n);if(n===bo)return;let r=n[qr];if(r!==T){g(e.out,t.name,r);return}if(delete e.out[t.name],!Rl(t.type)){let n=new ko([t.name],new Ao(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return Wi(new Mo(e.ast,[n],e.input,e.options))}}var jc={onItem(e,t){if(!Kc(e.input,t.name))return t.parser(T,e.options);let n=e.input[t.name];return g(e.out,t.name,n),t.parser(n,e.options)},step:Ac},Mc=pn()(jc),Nc=i()(jc);function Pc(e,t){return e?t?[...e,...t]:e:t}function Fc(e,t,n){return new kc(Reflect.ownKeys(e).map(t=>new wc(t,e[t].ast)),[],n,t)}function Ic(e){return e.ast}function Lc(e,t=void 0){return new gc(!1,e.map(e=>e.ast),[],void 0,t)}function Rc(e,t,n){return new Jc(e.map(Ic),t,void 0,n)}function zc(e){if(e.encoding)throw Error(`mutable does not support encodings`);return new gc(!0,e.elements,e.rest,e.annotations,e.checks,void 0,e.context,e.encodingChecks)}var Bc=h(e=>{for(;;){if(Js(e))return oc;let t=e.encoding;if(!t)return e.recur?.(Bc,pt)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==pt))return oc;e=t[t.length-1].to}});function Vc(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(Vc)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function Hc(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[co];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!Rl(t)){if(Us(t))return[{key:e.name,literal:t.literal}];if(Ws(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!Rl(e)){if(Us(e))return[{key:t,literal:e.literal}];if(Ws(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>Hc(Bc(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return Hc(e.thunk())}}var Uc=new WeakMap,Wc=Object.freeze([]),Gc=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Kc=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function qc(e){let t=Uc.get(e);if(t)return t;let n,r=0,i,a,o=!0,s=[];for(let t=0;t<e.length;t++){let c=e[t],l=Bc(c);if(zs(l))continue;if(Us(l)||Ws(l)){a??=new Map;let e=Us(l)?l.literal:l.symbol;s[t]=e;let n=a.get(e);n||a.set(e,n=[]),n.push(t)}else o=!1;let u=Hc(l);if(u.length){n??=new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=Vc(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??Wc);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??Wc;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=new Map;for(let[e,t]of i)a.set(e,Object.freeze(Array.from(t)));let o=Object.freeze(e.map((e,t)=>t));t=(e,t)=>{if(En(e)){let n=Kc(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??Wc;if(t)return o}return Wc}}else if(n){let e;for(let t of n)(!e||t[1][0].size>e[1][0].size)&&t[1][1].size===r&&(e=t);t=(t,r)=>{let a=Gc(t);if(!En(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=Kc(t,n),u=c?t[n]:void 0;if(c&&(!r||u!==void 0)){let e=i.get(u);if(!e)return l(a);for(let t of e)o.add(t);s=n}}if(s===void 0)for(let[e,[i,a]]of n){let n=Kc(t,e),s=n?t[e]:void 0;if(n&&(!r||s!==void 0)){let e=i.get(s);if(e)for(let t of e)o.add(t)}else if(r)for(let e of a)o.add(e)}for(let[e,[i,a]]of n){if(e===s)continue;let n=Kc(t,e),c=n?t[e]:void 0;if(n&&(!r||c!==void 0)){let e=i.get(c);for(let t of o)a.has(t)&&!e?.has(t)&&o.delete(t)}}return Array.from(o).sort((e,t)=>e-t)}}else t=e=>{let t=l(Gc(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return Uc.set(e,t),t}var Jc=class extends $s{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this,r=t!==void 0,i=[],a=t=>i[t]??=e(n.types[t]),o;return(e,t)=>{if(e===T)return yo;let i=(o??=qc(n.types))(e,r);if(i.length===0)return y(new Io(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:fe(r)?Yc(n,r.cause,e,t):Xc(n,r,e,t)}return Zc(n,a,i,e,t)}}_rebuild(e,t,n){let r=Dl(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new Jc(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=Wl(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Us);if(t.length>0)return`${tl(n.isMutable)}[ ${t.map(t=>e(t)+nl(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Us(e.type));if(t.length>0)return`{ ${t.map(t=>`${tl(t.type.context?.isMutable)}${vt(t.name)}${nl(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function Yc(e,t,n,r){let i=$o(t);return i?Wi(new Io(e,[i],n,r)):Ui(t)}function Xc(e,t,n,r){return Mr(t,t=>Yc(e,t,n,r))}function Zc(e,t,n,r,i){let a={ast:e,parser:t,input:r,out:void 0,successes:e.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},o=$c(a,n);if(!o)return a.out?a.out:y(new Io(e,a.issues??[],r,i));if(fe(o))return Qc(o,a);let s=!0;return bn(()=>s?(s=!1,Qc(o,a)):Zc(e,t,n,r,i))}function Qc(e,t){return Yt(e,e=>t.out===bo?v(t.input):t.out?t.out:y(new Io(t.ast,t.issues??[],t.input,t.options)))}var $c=pn()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=$o(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(e.ast.types[t]),Wi(new Lo(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return Ki}}}),el=new Jc([new sc(`Infinity`),new sc(`-Infinity`),new sc(`NaN`)]);function tl(e){return e?``:`readonly `}function nl(e){return e?`?`:``}var rl=class extends $s{_tag=`Suspend`;thunk;constructor(e,t,n,r,i){if(n)throw Error(`Cannot add checks to Suspend`);super(t,void 0,r,i);let a;this.thunk=()=>a??=e()}getParser(e){let t;return(n,r)=>(t??=e(this.thunk()))(n,r)}recur(e){return new rl(()=>e(this.thunk()),this.annotations,void 0,void 0,this.context)}getExpected(e){return e(this.thunk())}},il=class extends Ke{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new il(this.run,{...this.annotations,...e},this.aborted)}abort(){return new il(this.run,this.annotations,!0)}and(e,t){return new al([this,e],t)}},al=class extends Ke{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new al(this.checks,{...this.annotations,...e})}and(e,t){return new al([this,e],t)}};function ol(e,t,n=!1){return new il((t,n,r)=>Bo(n,e(t,n,r),t,r),t,n)}function sl(e,t){return new il((t,n,r)=>e(t)?void 0:new Po(void 0,t,r),t,!0)}function cl(e){return ol(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}var ll=bl(fc,[cl()]),ul=new Ys(new Jc([ll,el]),new ws(ms(),ss(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function dl(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return ol(e=>(n.lastIndex=0,n.test(e)),{expected:`a string matching the RegExp ${r.source}`,representation:{id:`effect/schema/isPattern`,payload:r},toJsonSchema:()=>[{},!0],arbitraryConstraint:{patterns:[r]},...t})}var fl=new WeakMap;function pl(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&fl.set(n,ml(e)),n}function ml(e){let t=fl.get(e);if(t!==void 0)return t;if(e.encoding===void 0)return e;let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,{encoding:void 0});return fl.set(e,n),n}function hl(e,t){return e.encoding===t?e:pl(e,{encoding:t})}function gl(e,t){if(e.context===t)return e;let n=ml(e);return n.context===t&&n.encoding===e.encoding?n:pl(e,{context:t})}function _l(e){return e.encoding?_l(e.encoding[e.encoding.length-1].to):e}function vl(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return yl(e,s(e.checks.slice(0,-1),n.annotate(t)))}return pl(e,{annotations:{...e.annotations,...t}})}function yl(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:pl(e,{checks:t})}function bl(e,t){return yl(e,Pc(e.checks,t))}function xl(e,t){let n=t(e.to);return n===e.to?e:new Ys(n,e.transformation)}function Sl(e,t){let n=e,r=n[n.length-1],i=xl(r,t);return i===r?e:s(e.slice(0,e.length-1),i)}function Cl(e){return t=>t.encoding?hl(t,Sl(t.encoding,e)):t}function wl(e,t){return Cl(e=>gl(e,t))(e)}function Tl(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:hl(r,Sl(r.encoding,n))}return e(r)}return h(n)}function El(e,t,n){let r=new Ys(e,t);return hl(n,n.encoding?[...n.encoding,r]:[r])}function Dl(e,t){let n;for(let r=0;r<e.length;r++){let i=e[r],a=t(i);if(n)n[r]=a;else if(a!==i){n=Array(e.length);for(let t=0;t<r;t++)n[t]=e[t];n[r]=a}}return n??e}function Ol(e,t){return gl(e,e.context?new Zs(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new Zs(!1,!1,void 0,t))}var kl=h(e=>Al(gl(e,e.context?e.context.isOptional===!1?new Zs(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new Zs(!0,!1)))),Al=Cl(kl),jl=se(e=>kl(new Jc([e,ic]))),Ml=h(e=>Nl(gl(e,e.context?e.context.isMutable===!1?new Zs(e.context.isOptional,!0,e.context.constructorDefault,e.context.annotations):e.context:new Zs(!1,!0)))),Nl=Cl(Ml);function Pl(e,t){return gl(e,e.context?new Zs(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new Zs(!1,!1,t))}function Fl(e,t,n){return El(e,n,t)}function Il(e){let t=[],n=[];function r(e){switch(e._tag){case`Literal`:xn(e.literal)&&!t.includes(e.literal)&&t.push(e.literal);return;case`UniqueSymbol`:t.includes(e.symbol)||t.push(e.symbol);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)r(e.types[t]);return;default:n.push(e)}}return r(e),{literals:t,parameters:n}}function Ll(e,t){let{literals:n,parameters:r}=Il(e);return new kc(n.map(e=>new wc(e,t)),r.map(e=>new Oc(e,t)))}function Rl(e){return e.context?.isOptional??!1}function zl(e){return e.context?.isMutable??!1}function Bl(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(Bl)}function Vl(e){function t(e){return Bl(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return He(n)?n:void 0}function Hl(e){let t=!0;function n(e){return t=t&&!e.encoding&&!Js(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}var Ul=h(e=>{let t=ml(e);if(t!==e){let n=Ul(t);return n===t&&e.encoding===void 0?e:gl(n,e.context)}let n=`recur`in e?e.recur(Ul):e;if(`encodingChecks`in n&&n.encodingChecks){let t=Hl(e)?n.encodingChecks:Gs(n)||Ks(n)||Is(n)&&n.typeParameters.length>0?Vl(n.encodingChecks):void 0;return pl(n,{encodingChecks:void 0,checks:Pc(n.checks,t)})}return n}),Wl=h(e=>Ul(Kl(e)));function Gl(e,t){let n=t,r=n.length,i=n[r-1],a=[new Ys(Kl(hl(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new Ys(Kl(n[e-1].to),n[e].transformation.flip()));let o=Kl(i.to);return o.encoding?hl(o,[...o.encoding,...a]):hl(o,a)}var Kl=se(e=>{if(e.encoding)return Gl(e,e.encoding);let t=ml(e);if(t!==e){let n=Kl(t);return n===t?e:gl(n,e.context)}return`flip`in e?e.flip(Kl):`recur`in e?e.recur(Kl):e});function ql(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some(ql);default:return!1}}function Jl(e,t){let n=t===0?bo:vo(t);return(r,i)=>r===T?yo:r===t?n:y(new No(e,r,i))}function Yl(e,t){return(n,r)=>n===T?yo:t(n)?bo:y(new No(e,n,r))}var Xl=Tl(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(Xl)}}),Zl=Tl(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(Zl)}}),Ql=`[\\s\\S]*?`,$l=new globalThis.RegExp(`^${Sc}$`),eu=new globalThis.RegExp(`^(?:${Sc}|Infinity|-Infinity|NaN)$`);function tu(e){return dl($l,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:$l.source}),...e})}var nu=bl(lc,[tu()]),ru=new Ys(nu,As),iu=new Ys(new Jc([nu,el]),As),au=new globalThis.RegExp(`^-?\\d+$`);function ou(e){return dl(au,{expected:`a string representing a bigint`,representation:{id:`effect/schema/isStringBigInt`,payload:null},toJsonSchema:()=>({pattern:au.source}),...e})}var su=new Ys(bl(lc,[ou({expected:`a string representing a bigint`})]),js),cu=new globalThis.RegExp(`^Symbol\\(([\\s\\S]*)\\)$`),lu=new Ys(bl(lc,[uu()]),new ws(ss(e=>globalThis.Symbol.for(cu.exec(e)[1])),cs((e,t)=>globalThis.Symbol.keyFor(e)===void 0?y(new Fo({message:`cannot serialize to string, Symbol is not registered`},e,t)):v(globalThis.String(e)))));function uu(e){return dl(cu,{expected:`a string representing a symbol`,representation:{id:`effect/schema/isStringSymbol`,payload:null},toJsonSchema:()=>({pattern:cu.source}),...e})}function du(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=du(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new Do(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function fu(e){if(!Is(e))return;let t=e.annotations?.[lo];return Wn(t)?t(e.typeParameters):void 0}var pu=io,mu=mo,hu=ho;function gu(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function _u(e){return e===void 0||typeof e==`string`}function vu(e,t){let n=new WeakMap,r=[];outer:for(;;){if(typeof e!=`object`||!e){if(!t(e))return!1}else{let t=e,i=n.get(t);if(i===!1)return!1;if(i===void 0){let e=Array.isArray(t);if(!e){let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null)return!1}n.set(t,!1),r.push({value:t,keys:e?t.length:Object.keys(t),index:0})}}for(;r.length>0;){let t=r[r.length-1],i=t.keys;if(typeof i==`number`){if(t.index<i){e=t.value[t.index++];continue outer}}else if(t.index<i.length){e=t.value[i[t.index++]];continue outer}n.set(t.value,!0),r.pop()}return!0}}function yu(e){return vu(e,gu)}var bu=new ec([],()=>(e,t,n)=>yu(e)?bo:y(new No(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>wu}),xu=new Ys(bu,ks()),Su=new Ys(new Jc([new gc(!1,[],[bu]),new kc([],[new Oc(lc,bu)])]),ks());function Cu(e){return vu(e,_u)}var wu=new Ys(new ec([],()=>(e,t,n)=>Cu(e)?bo:y(new No(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),ks()),Tu=(e,t,n)=>e===bo?n(t):Yt(e,n);function Eu(e){if(e._tag===`Middleware`)return(t,n,r)=>Du(t===bo?e.decode(vo(xo(n)),r):e.decode(Pe(t,xo),r));let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===bo?vo(t):e;case`Transform`:{let e=e=>e===T?yo:vo(t.transform(e));return(t,n)=>Tu(t,n,e)}case`TransformOptional`:{let e=e=>So(t.transform(xo(e)));return(t,n)=>Tu(t,n,e)}case`TransformEffect`:return(e,n,r)=>Tu(e,n,e=>e===T?yo:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>Tu(e,n,e=>Du(t.transform(xo(e),r)))}}var Du=e=>Yt(e,So),Ou=(e,t,n,r)=>Mr(r,r=>Lr(()=>Pi(r,r=>new Oo(e,r,t,n))));function ku(e,t){let n=Eu(e.link.transformation),r;return(i,a)=>{if(i===T)return yo;if(e.isConstructed(i))return bo;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function Au(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==T&&r!==void 0)return t(r,i);let a=n;if(fe(a)&&a._tag===`Success`){let e=t(a[qr],i);return e===bo?a:e}return Yt(Ou(e,r,i,a),e=>{let n=t(e,i);return n===bo?vo(e):n})}}function ju(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:Au(e,n)}function Mu(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?fu(e):void 0,o=a?ku(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Eu(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);if(u&&!n.disableChecks){if(fe(r)){if(r._tag===`Success`){let i=r===bo?t:r[qr];if(t!==T&&i!==T){let i=du(u,t,void 0,e,n);i&&(r=y(new Mo(e,i,t,n)))}}}else r=w(r,r=>{if(t!==T&&r!==T){let r=du(u,t,void 0,e,n);if(r)return y(new Mo(e,r,t,n))}return v(r)})}if(s&&!n.disableChecks){if(fe(r)){if(r._tag===`Success`){let i=r===bo?t:r[qr];if(i===T)return r;let a=du(s,i,void 0,e,n);a&&(r=y(new Mo(e,a,i,n)))}}else r=w(r,t=>{if(t!==T){let r=du(s,t,void 0,e,n);if(r)return y(new Mo(e,r,t,n))}return v(t)})}return r},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[qr],o=t(a,r)):o=Yt(o,e=>{let n=t(e,r);return n===bo?vo(e):n})}if(o._tag===`Success`){let e=o[qr],t=p(e,r);return t===bo?o:t}return o=Ou(e,n,r,o),Yt(o,e=>{let t=p(e,r);return t===bo?vo(e):t})}:p}var Nu=Symbol(),Pu=new WeakMap,Fu=e=>zu(e).parser,Iu=e=>zu(e).makeEffect,Lu=e=>ju(e,Iu),Ru=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Mu(this.ast,Fu)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Mu(this.ast,Iu,Lu)}};function zu(e){let t=Pu.get(e);if(t!==void 0)return t;let n=new Ru(e);return Pu.set(e,n),n}function Bu(e){let t=e.ast,n;return(e,r)=>(n??=rd(ud,Ul(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Vu(e){let t=Bu(e);return(e,n)=>{let r=cr(t(e,n));return qi(r)?sr(r.value):(es(r.cause,`Option adapter can only return none for schema issues`),Mn())}}function Hu(e){return cd(Ul(e.ast))}function Uu(e){return Gu(e.ast)}function Wu(e){{let t=id(td(e));return e=>{let n=t(e,Xs);return qi(n)?!0:(es(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Gu(e){let t=Ul(e),n=e=>(n=Wu(t),n(e));return e=>n(e)}function Ku(e,t){let n=td(e.ast);return t===void 0?n:(e,r)=>n(e,$u(t,r))}function qu(e,t){return id(Ku(e,t))}function Ju(e,t){return ad(Ku(e,t))}function Yu(e,t){return od(Ku(e,t))}function Xu(e,t){let n=td(Kl(e.ast));return t===void 0?n:(e,r)=>n(e,$u(t,r))}function Zu(e,t){return id(Xu(e,t))}function Qu(e,t){return od(Xu(e,t))}var $u=(e,t)=>t?{...e,...t}:e,ed=e=>e===T?y(new Po):v(e);function td(e){return rd(ld,e)}function nd(e,t){return e===bo?v(t):fe(e)?e[qr]===T?ed(T):e:Yt(e,ed)}function rd(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??Xs);return a===bo?v(r):fe(a)?a[qr]===T?ed(T):a:Yt(a,ed)}}function id(e){return(t,n)=>cr(e(t,n))}function ad(e){let t=id(e);return(e,n)=>{let r=t(e,n);return qi(r)?sr(r.value):(es(r.cause,`Option adapter can only return none for schema issues`),Mn())}}function od(e){let t=id(e);return(e,n)=>{let r=t(e,n);return qi(r)?je(r.value):at(es(r.cause,`Result adapter can only return schema issues`))}}function sd(e,t){let n=cr(e);if(qi(n))return n.value;let r=es(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function cd(e){let t,n;return(r,i)=>{t??=zu(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??Xs,o=t.make;if(o!==void 0&&r!==T){let e;try{e=o(r,a)}catch(e){throw es(Mi(e),`Constructor adapter can only throw schema issues`),e}if(e!==Nu&&e!==T)return e}return sd(nd((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}var ld=e=>zu(e).parser,ud=e=>zu(e).makeEffect,dd=`~effect/Schema/Schema`,fd=Symbol(),pd={[dd]:dd,get make(){let e=Hu(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=Bu(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=Vu(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return o(this,arguments)},annotate(e){return this.rebuild(vl(this.ast,e))},annotateKey(e){return this.rebuild(Ol(this.ast,e))},check(...e){return this.rebuild(bl(this.ast,e))},rebuild(e){return md(e,this[fd])}};function md(e,t){function n(){}let r=Object.setPrototypeOf(n,pd);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r[fd]=t,r.ast=e,r}function hd(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function gd(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function _d(e){return encodeURI(hd(e)).replace(/#/g,`%23`)}function vd(e){if(e.length===0||e===`#`)return``;if(!e.startsWith(`#`))return;let t=e.slice(1);try{if(encodeURI(t).replace(/%25/g,`%`).replace(/#/g,`%23`)!==t)return;let e=decodeURIComponent(t);return e.startsWith(`/`)&&!/~(?:[^01]|$)/.test(e)?e:void 0}catch{return}}function yd(e){let t=vd(e);return t===void 0?void 0:t.length===0?[]:t.slice(1).split(`/`).map(gd)}function bd(e){return e.reduce((e,t)=>`${e}/${_d(t)}`,`#`)}var xd=`http://json-schema.org/draft-07/schema#`;function Sd(e,t){return e===t||e===(t.endsWith(`#`)?t.slice(0,-1):`${t}#`)}function Cd(e){return{dialect:`draft-07`,...Fd(e,qd)}}function wd(e,t){return n(e,!1,!0);function n(e,r,i=!1){if(!Yn(e))return e;let a=r||!i&&Pd(e.$id),o={};for(let t of Object.keys(e)){let r=e[t],i=r;switch(t){case`$defs`:case`properties`:case`patternProperties`:case`dependentSchemas`:i=Dd(r,e=>n(e,a))??r;break;case`allOf`:case`anyOf`:case`oneOf`:case`prefixItems`:i=Array.isArray(r)?r.map(e=>n(e,a)):r;break;case`not`:case`additionalProperties`:case`propertyNames`:case`unevaluatedProperties`:case`items`:case`contains`:case`unevaluatedItems`:case`if`:case`then`:case`else`:case`contentSchema`:i=n(r,a)}g(o,t,i)}return t(o,a),o}}function Td(e,t){return wd(e,e=>{Ed(e,t)})}function Ed(e,t){typeof e.$ref==`string`&&g(e,`$ref`,t(e.$ref,`$ref`)),typeof e.$dynamicRef==`string`&&g(e,`$dynamicRef`,t(e.$dynamicRef,`$dynamicRef`))}function Dd(e,t){if(!Yn(e))return;let n={};for(let r of Object.keys(e))g(n,r,t(e[r],r));return n}function Od(e,t,n){let r=new Map,i=[],a=kd;function o(e,n=[],r=[]){return n.length===0&&t?.trackIds&&(a=jd(Yn(e)?u(e):void 0,kd)??kd),l(e,n,r,{sourceRoot:[],targetRoot:[],uri:a})}function s(){for(let[e,t,n]of i){let i=t,a=Ad(t,n);if(a!==void 0){let e=yd(a.hash);if(a.hash=``,e!==void 0){let n=r.get(Nd(a.href,e));n!==void 0&&(i=Md(t,n))}}g(e,`$ref`,i)}}let c=n(o);return s(),c;function l(n,r,a,o){if(typeof n==`boolean`)return d(r,a,o),t?.booleanAdapter?.(n)??n;if(!Yn(n))return n;let s=o,c=u(n);if(r.length>0&&t?.trackIds&&Pd(c)){let e=jd(c,o.uri);e!==void 0&&(s={parent:o,sourceRoot:r,targetRoot:a,uri:e})}d(r,a,s);let f=s.uri;return e(n,{isDocumentRoot:r.length===0,schema(e,t,n=t){return l(e,[...r,t],[...a,n],s)},schemaAt(e,t,n){return l(e,[...r,...t],[...a,...n],s)},schemaArray(e,t,n=t){return Array.isArray(e)?e.map((e,i)=>l(e,[...r,t,String(i)],[...a,n,String(i)],s)):e},schemaMap(e,t,n=t){return Yn(e)?Dd(e,(e,i)=>l(e,[...r,t,i],[...a,n,i],s)):e},reference(e,t){typeof t==`string`?i.push([e,t,f]):g(e,`$ref`,t)}})}function u(e){return t?.ignoreRefSiblings===!0&&typeof e.$ref==`string`?void 0:e.$id}function d(e,t,n){n.parent!==void 0&&d(e,t,n.parent),r.set(Nd(n.uri,e.slice(n.sourceRoot.length)),t.slice(n.targetRoot.length))}}var kd=`https://effect.invalid/.json-schema/`;function Ad(e,t){return URL.canParse(e,t)?new URL(e,t):void 0}function jd(e,t){if(typeof e!=`string`)return;let n=Ad(e,t);if(n!==void 0)return n.hash=``,n.href}function Md(e,t){let n=e.indexOf(`#`);return n===-1&&t.length===0?e:`${n===-1?e:e.slice(0,n)}${bd(t)}`}function Nd(e,t){return`${e}\u0000${JSON.stringify(t)}`}function Pd(e){return typeof e==`string`&&e.length>0&&e[0]!==`#`}function Fd(e,t,n){return Od(t,{...n,trackIds:!0},t=>({schema:t(e.schema),definitions:Dd(e.definitions,(e,n)=>t(e,[`$defs`,n],[`definitions`,n]))}))}var Id=new Set([`properties`,`patternProperties`]),Ld=new Set([`allOf`,`anyOf`,`oneOf`]),Rd=new Set([`not`,`additionalProperties`,`propertyNames`,`contains`,`if`,`then`,`else`,`contentSchema`]);function zd(e,t,n,r,i,a=Id){let o;if(a.has(t))o=r.schemaMap(n,t);else if(Ld.has(t))o=r.schemaArray(n,t);else if(i.has(t))o=r.schema(n,t);else return!1;return g(e,t,o),!0}var Bd=[`$anchor`,`$defs`,`$dynamicAnchor`,`$dynamicRef`,`$vocabulary`,`contentSchema`,`dependentRequired`,`dependentSchemas`,`maxContains`,`minContains`,`prefixItems`,`unevaluatedItems`,`unevaluatedProperties`];[...Bd],[...Bd];var Vd=/^[A-Za-z_][-A-Za-z0-9._]*$/,Hd=/^[A-Za-z][-A-Za-z0-9._:]*$/;function Ud(e,t,n){throw Error(`Cannot convert JSON Schema keyword "${e}" to ${t}: ${n}`)}function Wd(e,t,n,r){for(let i of t)Object.hasOwn(e,i)&&Ud(i,n,`it is not active in ${r} but would become active in the target`)}var Gd=[`additionalItems`,`definitions`,`dependencies`];function Kd(e,t,n,r,i){n.isDocumentRoot?g(e,`$schema`,Sd(t,`https://json-schema.org/draft/2020-12/schema`)?r:t):Sd(t,`https://json-schema.org/draft/2020-12/schema`)||Ud(`$schema`,i,`an embedded resource cannot declare a different dialect`)}function qd(e,t){Wd(e,Gd,`Draft-07`,`Draft 2020-12`);let n={},r,i,a;for(let o of Object.keys(e)){let s=e[o];if(!zd(n,o,s,t,Rd))switch(o){case`$ref`:r=s;break;case`$schema`:Kd(n,s,t,xd,`Draft-07`);break;case`$id`:case`$anchor`:break;case`$defs`:g(n,`definitions`,t.schemaMap(s,o,`definitions`));break;case`prefixItems`:i=s;break;case`items`:a=s;break;case`dependentRequired`:case`dependentSchemas`:case`minContains`:case`maxContains`:break;case`$dynamicRef`:case`$dynamicAnchor`:case`$vocabulary`:case`unevaluatedProperties`:case`unevaluatedItems`:Ud(o,`Draft-07`,`the target dialect has no equivalent`);case`required`:if(Array.isArray(s)&&s.length===0)break;g(n,o,s);break;default:g(n,o,s)}}if(Jd(n,i,a,t),Object.hasOwn(e,`contains`)){let t=e.minContains,r=e.maxContains;(t!==void 0&&t!==1||r!==void 0)&&Ud(`minContains/maxContains`,`Draft-07`,`contains cardinality cannot be represented`),Object.hasOwn(e,`minContains`)&&g(n,`minContains`,t)}else Object.hasOwn(e,`minContains`)&&g(n,`minContains`,e.minContains),Object.hasOwn(e,`maxContains`)&&g(n,`maxContains`,e.maxContains);return Xd(e,n,t,`draft-07`),Qd(e,n,`$id`,`Draft-07`),Yd(n,r,t),n}function Jd(e,t,n,r){if(t===void 0){n!==void 0&&g(e,`items`,r.schema(n,`items`));return}g(e,`items`,r.schemaArray(t,`prefixItems`,`items`)),n!==void 0&&g(e,`additionalItems`,r.schema(n,`items`,`additionalItems`))}function Yd(e,t,n){if(t!==void 0){if(typeof t==`string`&&Object.keys(e).length>0){let r={};n.reference(r,t),Zd(e,r)}else n.reference(e,t)}}function Xd(e,t,n,r){let i=Yn(e.dependentRequired)?e.dependentRequired:void 0,a=Yn(e.dependentSchemas)?e.dependentSchemas:void 0;if(i===void 0&&a===void 0)return;let o={},s=new Set([...Object.keys(i??{}),...Object.keys(a??{})]);for(let e of s){let t=i?.[e],s=a?.[e],c=r===`draft-04`&&Array.isArray(t)&&t.length===0;s===void 0?c||g(o,e,t):t===void 0||c?g(o,e,n.schemaAt(s,[`dependentSchemas`,e],[`dependencies`,e])):g(o,e,{allOf:[n.schemaAt(s,[`dependentSchemas`,e],[`dependencies`,e,`allOf`,`0`]),{required:t}]})}Object.keys(o).length>0&&g(t,`dependencies`,o)}function Zd(e,t){Array.isArray(e.allOf)?e.allOf.push(t):g(e,`allOf`,[t])}function Qd(e,t,n,r){let i=e.$id,a=e.$anchor;if(a===void 0){i!==void 0&&g(t,n,i);return}(typeof a!=`string`||!Vd.test(a))&&Ud(`$anchor`,r,`the anchor is not valid`),Hd.test(a)||Ud(`$anchor`,r,`the anchor cannot be represented as a plain-name fragment identifier`),i===void 0?g(t,n,`#${a}`):Ud(`$anchor`,r,`it cannot be combined with the schema $id`)}function $d(e){return md(ef(e.ast),{schema:e})}var ef=Tl(e=>{let t=of(e,ef),n=e.context;return t===e||n===void 0?t:wl(t,tf(n))});function tf(e){return e.constructorDefault===void 0?e:new Zs(e.isOptional,e.isMutable,void 0,e.annotations)}function nf(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function rf(e){return t=>{let n=[...t].sort((t,n)=>e(Wl(t))-e(Wl(n)));return n.some((e,n)=>e!==t[n])?n:t}}var af=rf(e=>{switch(e._tag){case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function of(e,t){switch(e._tag){case`Declaration`:{let n=e.annotations?.toCodecJson??e.annotations?.toCodec;if(!Wn(n))return hl(e,[xu]);let r=n(e.typeParameters.map(e=>md(Wl(e))));return r===void 0?e:hl(e,[xl(r,t)])}case`Unknown`:return hl(e,[xu]);case`ObjectKeyword`:return hl(e,[Su]);case`Undefined`:case`Void`:case`Literal`:case`Number`:return e.toCodecJson();case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return nf(e),e.recur(t,Zl);case`Union`:{let n=af(e.types);return n===e.types?e.recur(t):new Jc(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}globalThis.RegExp;var sf=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`);function cf(e,t){return t.length>0&&(e+=`\n at ${ye(t)}`),Error(e)}function lf(e){return`#/$defs/${_d(e)}`}var uf=new Set([..._o,so,...uo]);function df(e,t){if(e===void 0)return;let n={},r=e.title;typeof r==`string`&&(n.title=r);let i=e.description,a=e.expected;typeof i==`string`?n.description=i:t?.generateDescriptions===!0&&typeof a==`string`&&(n.description=a);let o=e.default;yu(o)&&(n.default=o);let s=e.examples;Array.isArray(s)&&yu(s)&&(n.examples=s);let c=e.readOnly;typeof c==`boolean`&&(n.readOnly=c);let l=e.writeOnly;typeof l==`boolean`&&(n.writeOnly=l);let u=e.format;typeof u==`string`&&(n.format=u);let d=e.contentEncoding;typeof d==`string`&&(n.contentEncoding=d);let f=e.contentMediaType;typeof f==`string`&&(n.contentMediaType=f);let p=e.contentSchema;if(yu(p)&&(n.contentSchema=p),t?.includeAnnotationKey!==void 0)for(let[r,i]of Object.entries(e))uf.has(r)||!t.includeAnnotationKey(r)||yu(i)&&g(n,r,i);return Object.keys(n).length===0?void 0:n}function ff(e){let t=e.type===`number`||e.type===`integer`?e.type:void 0,n=e;if(t!==void 0&&(n={...e},delete n.type),Array.isArray(n.allOf)){let e=[],r=!1;for(let i of n.allOf){let n=ff(i);n.type!==void 0&&(r=!0,(t===void 0||n.type===`integer`)&&(t=n.type)),Object.keys(n.schema).length>0&&e.push(n.schema)}if(r){let{allOf:t,...r}=n;n=e.length===0?r:{...r,allOf:e}}}return{type:t,schema:n}}function pf(e){if(!Array.isArray(e.anyOf)||e.anyOf.length!==2||e.anyOf[0]?.type!==`number`)return!1;let t=e.anyOf[1];return t?.type===`string`&&Array.isArray(t.enum)&&t.enum.length===3&&t.enum.includes(`NaN`)&&t.enum.includes(`Infinity`)&&t.enum.includes(`-Infinity`)}var mf=`|type|format|pattern|multipleOf|minimum|maximum|exclusiveMinimum|exclusiveMaximum|minLength|maxLength|minItems|maxItems|uniqueItems|minProperties|maxProperties|propertyNames|`;function hf(e,t){return Object.keys(e).every(e=>t.includes(`|${e}|`))}function gf(e,t){return typeof e.$ref!=`string`&&t.every(t=>!Object.hasOwn(e,t))}var _f=`|title|description|default|examples|readOnly|writeOnly|`,vf=mf+_f;function yf(e,t,n){if(Object.keys(e).length===0)return t;let r=Object.keys(t);if(r.length===0)return e;let i=e.type===`number`||e.type===`integer`?e.type:void 0,a=pf(e);if(i!==void 0||a){let r=ff(t);if(r.type!==void 0){let t=i===`integer`||r.type===`integer`?`integer`:`number`,o={...e,type:t};a&&delete o.anyOf;let s=Object.keys(r.schema);return s.length===0?o:hf(r.schema,_f)&&gf(o,s)?{...o,...r.schema}:yf(o,r.schema,n)}}if(n&&gf(e,r))return{...e,...t};let o=Array.isArray(t.allOf)&&r.length===1?t.allOf:[t];return Array.isArray(e.allOf)?{...e,allOf:[...e.allOf,...o]}:typeof e.$ref==`string`?{allOf:[e,...o]}:{...e,allOf:o}}function bf(e,t=new Set){return typeof e==`boolean`?e:t.has(e)?!0:(t.add(e),e.every(e=>bf(e,t)))}function xf(e){return Array.isArray(e)}function Sf(e,t,n,r){let i=new Map,a=new Map,o=new WeakMap,s=new Map,c=new Map,l=Object.keys(n);for(let e of l)m(e,[`references`,e]);let u=Se(e,(e,n)=>h(e,t[n],[]));for(let[e,t]of s.values())if(!bf(e))for(let e of t)Array.isArray(e.oneOf)&&(e.anyOf=e.oneOf,delete e.oneOf);for(let e of l){let t=n[e],r=te(t);if(r===void 0)continue;let o=i.get(e)[0],s=c.get(r),l=s?.find(e=>At(i.get(e)[0],o));l===void 0?s===void 0?c.set(r,[e]):s.push(e):a.set(e,l)}let d=Se(u,ee),f={};for(let e of l)a.has(e)||g(f,e,ee(i.get(e)[0]));return{dialect:`draft-2020-12`,schemas:d,definitions:f};function p(e){return Array.isArray(e.oneOf)&&s.get(e.oneOf)?.[1].push(e),e}function m(e,t){if(!Object.hasOwn(n,e))throw cf(`Invalid reference ${e}`,[...t,`$ref`]);let r=i.get(e);if(r!==void 0)return r;let a=[{},[]];return i.set(e,a),a[0]=h(n[e],[`references`,e],a[1]),a}function ee(e){return Td(e,e=>{let t=vd(e);if(t===void 0){if(/^#(?:\/|%2f)/i.test(e))throw Error(`Invalid JSON Pointer URI fragment ${JSON.stringify(e)}`);return e}if(!t.startsWith(`/$defs/`))return e;let n=t.indexOf(`/`,7),r=a.get(gd(t.slice(7,n<0?void 0:n)));return r===void 0?e:e.replace(/^#(?:\/|%2f).*?(?:\/|%2f).*?(?=\/|%2f|$)/i,lf(r))})}function te(e){if(e._tag===`Reference`)return;let t=e.checks.length===0?e.annotations:e.checks[e.checks.length-1].annotations;return typeof t?.identifier!=`string`&&typeof t?.[`~identifier`]==`string`?t[so]:void 0}function ne(e,t,n,i){let a=e.annotations,o=a?.toJsonSchema;if(o!==void 0){let s=o({type:t,schemas:e.representation?.schemas?.map((e,t)=>h(e,[...n,`representation`,`schemas`,t],i))??[]}),c=xf(s);c&&i.push(!1);let l=c?s[0]:s,u=df(a,r),d=u===void 0?l:{...l,...u},f=u===void 0?mf:vf;return[d,e._tag===`Filter`&&hf(d,f)&&(u===void 0||hf(u,_f))?!0:void 0]}if(e._tag===`Filter`){i.push(!1);return}let s=e.checks.flatMap((e,r)=>{let a=ne(e,t,[...n,`checks`,r],i);return a===void 0?[]:[a[0]]});if(s.length===0)return;let c=df(a,r),l={allOf:s};return[c===void 0?l:{...l,...c}]}function h(e,t,n){if(e._tag===`Reference`)return n.push(m(e.$ref,t)[1]),{$ref:lf(e.$ref)};let i=o.get(e);if(i!==void 0)return n.push(i[1]),i[0];let a=[];n.push(a);let s=re(e,t,a),c=df(e.annotations,r);c!==void 0&&(s={...s,...c});for(let n=0;n<e.checks.length;n++){let r=typeof s.type==`string`&&Cf(s.type)?s.type:void 0,i=ne(e.checks[n],r,[...t,`checks`,n],a);i!==void 0&&(s=yf(s,...i))}return o.set(e,[s,a]),p(s)}function re(e,t,n){switch(e._tag){case`Any`:case`Unknown`:return{};case`ObjectKeyword`:return{anyOf:[{type:`object`},{type:`array`}]};case`Void`:case`Undefined`:case`Null`:return{type:`null`};case`BigInt`:return{type:`string`,allOf:[{pattern:`^-?\\d+$`}]};case`Symbol`:return{type:`string`,allOf:[{pattern:`^Symbol\\(([\\s\\S]*)\\)$`}]};case`UniqueSymbol`:return globalThis.Symbol.keyFor(e.symbol)===void 0?{not:{}}:{type:`string`,enum:[globalThis.String(e.symbol)]};case`Declaration`:return n.push(!1),{};case`Suspend`:return h(e.thunk,[...t,`thunk`],n);case`Never`:return{not:{}};case`String`:return{type:`string`};case`Number`:return{anyOf:[{type:`number`},{type:`string`,enum:[`NaN`,`Infinity`,`-Infinity`]}]};case`Boolean`:return{type:`boolean`};case`Literal`:{let t=e.literal;return typeof t==`bigint`?{type:`string`,enum:[globalThis.String(t)]}:{type:typeof t,enum:[t]}}case`Enum`:{let n=e.enums.map(([e,n],r)=>{if(typeof n==`number`&&!globalThis.Number.isFinite(n))throw cf(`Invalid numeric enum value ${globalThis.String(n)}`,[...t,`enums`,r,1]);return{type:typeof n,enum:[n],title:e}});return n.length===0?{not:{}}:{anyOf:n}}case`TemplateLiteral`:return{type:`string`,pattern:`^${e.parts.map(Tf).join(``)}$`};case`Arrays`:{if(e.rest.length>1)throw cf(`Invalid schema representation document`,[...t,`rest`]);let i={type:`array`},a=e.elements.length,o=e.elements.map((e,i)=>{e.isOptional&&a--;let o=h(e.type,[...t,`elements`,i,`type`],n),s=df(e.annotations,r);return s===void 0?o:p(yf(o,s))});if(o.length>0?(i.prefixItems=o,i.maxItems=e.elements.length,a>0&&(i.minItems=a)):i.items=!1,e.rest.length===1){delete i.maxItems;let r=h(e.rest[0],[...t,`rest`,0],n);Object.keys(r).length>0?i.items=r:delete i.items}return i}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return{not:{type:`null`}};let i={type:`object`},a={},o=[];for(let i=0;i<e.propertySignatures.length;i++){let s=e.propertySignatures[i];if(typeof s.name!=`string`)throw cf(`Invalid schema representation document`,[...t,`propertySignatures`,i,`name`]);let c=s.name,l=h(s.type,[...t,`propertySignatures`,i,`type`],n),u=df(s.annotations,r);g(a,c,u===void 0?l:p(yf(l,u))),s.isOptional||o.push(c)}e.propertySignatures.length>0&&(i.properties=a),o.length>0&&(i.required=o);let s={},c=[],l=[],u=!1;for(let r=0;r<e.indexSignatures.length;r++){let i=e.indexSignatures[r],a=h(i.type,[...t,`indexSignatures`,r,`type`],n);At(a,{not:{}})&&(a=!1),l.push(a);let o=ie(i.parameter,[...t,`indexSignatures`,r,`parameter`],new Set);if(o===void 0){u=!0,n.push(!1);continue}if(o.length===0)c.push(a);else for(let e of o){let t=s[e];g(s,e,t===void 0?a:t===!1||a===!1?!1:p(yf(t,a)))}}let d=Object.keys(s).length>0;if(d&&(i.patternProperties=s),u&&r?.onExcessProperty===`error`){let r=[];e.propertySignatures.length>0&&r.push({enum:Object.keys(a)});for(let i=0;i<e.indexSignatures.length;i++)r.push(h(e.indexSignatures[i].parameter,[...t,`indexSignatures`,i,`parameter`],n));i.propertyNames=r.length===1?r[0]:{anyOf:r},i.additionalProperties=l.length===1?l[0]:{anyOf:l},c.length>0&&(i.allOf=c.map(e=>({type:`object`,additionalProperties:e})))}else c.length===0?i.additionalProperties=u||r?.onExcessProperty!==`error`:c.length===1&&e.propertySignatures.length===0&&!d?i.additionalProperties=c[0]:c.length>0&&(i.allOf=c.map(e=>({type:`object`,additionalProperties:e})));return typeof i.additionalProperties==`object`&&i.additionalProperties!==null&&Object.keys(i.additionalProperties).length===0&&delete i.additionalProperties,i}case`Union`:{let r=[],i=e.types.map((e,n)=>h(e,[...t,`types`,n],r));if(n.push(r),i.length===0)return{not:{}};let a=e.options?.mode??`anyOf`;if(a===`anyOf`&&i.length>1){let e=wf(i);if(e!==void 0)return e}return a===`oneOf`&&s.set(i,[r,[]]),{[a]:i}}}}function ie(e,t,r){switch(e._tag){case`Reference`:{if(!Object.hasOwn(n,e.$ref))throw cf(`Invalid reference ${e.$ref}`,[...t,`$ref`]);if(m(e.$ref,t),r.has(e.$ref))return;let i=new Set(r).add(e.$ref);return ie(n[e.$ref],[`references`,e.$ref],i)}case`String`:{if(e.checks.length===0)return[];if(e.checks.length!==1||e.checks[0]._tag!==`Filter`||e.checks[0].annotations?.toJsonSchema===void 0)return;let n=[],r=h(e,t,n);return bf(n)&&r.type===`string`&&typeof r.pattern==`string`&&hf(r,`|type|pattern|title|description|default|examples|readOnly|writeOnly|`)?[r.pattern]:void 0}case`TemplateLiteral`:return e.checks.length===0?[`^${e.parts.map(Tf).join(``)}$`]:void 0;case`Union`:{if(e.types.length===0||e.checks.length>0||e.options?.mode===`oneOf`)return;let n=[];for(let i=0;i<e.types.length;i++){let a=ie(e.types[i],[...t,`types`,i],r);if(a===void 0)return;if(a.length===0)return[];n.push(...a)}return n}default:throw cf(`Invalid schema representation document`,t)}}}function Cf(e){return e===`string`||e===`number`||e===`boolean`||e===`array`||e===`object`||e===`null`||e===`integer`}function wf(e){let t,n=[];for(let r of e){if(Object.keys(r).length!==2||r.type===void 0||!Array.isArray(r.enum)||r.enum.length===0)return;if(t===void 0)t=r.type;else if(r.type!==t)return;for(let e of r.enum){if(n.includes(e))return;n.push(e)}}return{type:t,enum:n}}function Tf(e){switch(e._tag){case`Literal`:return sf(globalThis.String(e.literal));case`String`:return Ql;case`Number`:return Sc;case`TemplateLiteral`:return e.parts.map(Tf).join(``);case`Union`:return`(?:${e.types.map(Tf).join(`|`)})`;default:throw cf(`Invalid schema representation document`,[])}}function Ef(e,t){let n=Sf([e.representation],[[`representation`]],e.references,t);return{dialect:n.dialect,schema:n.schemas[0],definitions:n.definitions}}var Df=({identifier:e})=>e;function Of(e){return e===void 0?void 0:{annotations:e}}function kf(e,t){let{references:n,representations:r}=Af([e],t);return{representation:r[0],references:n}}function Af(e,t){let n={},r=new Map,i=new Set,a=new Map,o=new Set;for(let t of e)f(t);let s=t?.referencePolicy??Df;for(let e of a.values())for(let t of e.values()){let e=s({ast:t.ast,occurrences:t.occurrences,identifier:t.identifier});e===void 0?t.isRecursive&&(t.reference=c(`${t.ast._tag}_`,t,``)):t.reference=c(e,t,e===t.identifier||!e.endsWith(`_`)?`_`:``)}return{representations:Se(e,e=>m(e)),references:n};function c(e,t,n=`_`){let i=e,a=0;for(;r.has(i);){if(r.get(i)===t)return i;i=`${e}${n}${++a}`}return r.set(i,t),i}function l(e,t,n){let r=t.fallback;return r===void 0?n===t.identifier?e:vl(e,{identifier:n}):po(e)===r?e:vl(e,{[so]:r})}function u(e,t){if(!Object.hasOwn(n,e)&&!i.has(e)){i.add(e);let r=ee(t);i.delete(e),g(n,e,r)}return{_tag:`Reference`,$ref:e}}function d(e){let t=_l(e),n=ml(t),r=fo(t),i=r===void 0?(t===e?void 0:fo(e))??po(t):void 0;i!==void 0&&(r=`${i}Encoded`);let o=a.get(n);o===void 0&&(o=new Map,a.set(n,o));let s=o.get(r);return s===void 0&&(s={ast:n,identifier:r,fallback:i,occurrences:0,isRecursive:!1,reference:void 0},o.set(r,s)),s}function f(e){let t=d(e),n=t.ast;if(t.occurrences++,o.has(t)){t.isRecursive=!0;return}if(!(t.occurrences>1)){switch(o.add(t),p(n.checks),n._tag){case`Declaration`:case`Arrays`:case`Objects`:case`Union`:n.recur(e=>(f(e),e));break;case`TemplateLiteral`:n.parts.forEach(f);break;case`Suspend`:f(n.thunk())}o.delete(t)}}function p(e){e?.forEach(e=>{e.annotations?.representation?.schemas?.forEach(e=>f(Ul(e))),e._tag===`FilterGroup`&&p(e.checks)})}function m(e){let t=d(e),n=t.ast,r=t.reference;return r===void 0?ee(n):u(r,t.identifier===void 0?n:l(n,t,r))}function ee(e){let t=te(e.checks);switch(e._tag){case`Declaration`:return{_tag:`Declaration`,typeParameters:e.typeParameters.map(e=>m(e)),checks:t,...h(e.annotations)};case`Null`:case`Undefined`:case`Void`:case`Never`:case`Unknown`:case`Any`:case`String`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`ObjectKeyword`:return{_tag:e._tag,checks:t,...Of(e.annotations)};case`Literal`:return{_tag:`Literal`,literal:e.literal,checks:t,...Of(e.annotations)};case`UniqueSymbol`:return{_tag:`UniqueSymbol`,symbol:e.symbol,checks:t,...Of(e.annotations)};case`Enum`:return{_tag:`Enum`,enums:e.enums,checks:t,...Of(e.annotations)};case`TemplateLiteral`:return{_tag:`TemplateLiteral`,parts:e.parts.map(e=>m(e)),checks:t,...Of(e.annotations)};case`Arrays`:return{_tag:`Arrays`,elements:e.elements.map(e=>{let t=_l(e),n=t.context?.annotations;return{isOptional:Rl(t),type:m(e),...Of(n)}}),rest:e.rest.map(e=>m(e)),checks:t,...Of(e.annotations)};case`Objects`:return{_tag:`Objects`,propertySignatures:e.propertySignatures.map(e=>{let t=_l(e.type),n=t.context?.annotations;return{name:e.name,type:m(e.type),isOptional:Rl(t),isMutable:zl(t),...Of(n)}}),indexSignatures:e.indexSignatures.map(e=>({parameter:m(e.parameter),type:m(e.type)})),checks:t,...Of(e.annotations)};case`Union`:return{_tag:`Union`,types:e.types.map(e=>m(e)),...e.options===void 0?{}:{options:e.options},checks:t,...Of(e.annotations)};case`Suspend`:return{_tag:`Suspend`,checks:[],thunk:m(e.thunk()),...Of(e.annotations)}}}function te(e){return e?.map(ne)??[]}function ne(e){switch(e._tag){case`Filter`:return{_tag:`Filter`,aborted:e.aborted,...re(e.annotations)};case`FilterGroup`:return{_tag:`FilterGroup`,checks:Se(e.checks,ne),...re(e.annotations)}}}function h(e){if(e===void 0)return;let{representation:t,...n}=e;return{...t===void 0?void 0:{representation:t},...Object.keys(n).length===0?void 0:{annotations:n}}}function re(e){if(e===void 0)return;let{representation:t,...n}=e,r=t===void 0?void 0:t.schemas===void 0?t:{...t,schemas:t.schemas.map(e=>m(Ul(e)))};return{...r===void 0?void 0:{representation:r},...Object.keys(n).length===0?void 0:{annotations:n}}}}function jf(e){return qi(e)?e.value:{issues:[{message:zi(e.cause)}]}}function Mf(e,t){let n=Ku(e),r={errors:`all`,...t?.parseOptions},i=Uo(t),a=e=>{let t=new Zt(`sync`),a=jr(u(n(e,r),{onFailure:i,onSuccess:e=>({value:e})}),{scheduler:t});a.currentDispatcher?.flush();let o=a.pollUnsafe();return o?jf(o):new Promise(e=>{a.addObserver(t=>{e(jf(t))})})};if(Object.hasOwn(e,`~standard`)){let t=e;return`validate`in t[`~standard`]||Object.assign(t[`~standard`],{validate:a}),t}return Object.assign(e,{"~standard":{version:1,vendor:`effect`,validate:a}})}function Nf(e){return Ef(kf(ef(e)))}function Pf(e,t){let n=Nf(e);if(t===`draft-2020-12`){let e=n.schema;return Object.keys(n.definitions).length>0&&(e.$defs=n.definitions),e}if(t===`draft-07`){let e=Cd(n),t=e.schema;return Object.keys(e.definitions).length>0&&(t.definitions=e.definitions),t}throw new globalThis.Error(`Unsupported target: ${t}`)}function Ff(e){let t={input(t){return Pf(e.ast,t.target)},output(t){return Pf(Ul(e.ast),t.target)}};if(Object.hasOwn(e,`~standard`)){let n=e;return`jsonSchema`in n[`~standard`]||Object.assign(n[`~standard`],{jsonSchema:t}),n}return Object.assign(e,{"~standard":{version:1,vendor:`effect`,jsonSchema:t}})}var If=se(e=>Lf(e));function Lf(e){let t=io(e)?.toEquivalence;if(t)return t(Is(e)?e.typeParameters.map(Lf):[]);switch(e._tag){case`Never`:return Nt();case`Declaration`:return Rf(e);case`Null`:case`Undefined`:case`Void`:case`Unknown`:case`Any`:case`String`:case`Number`:case`Boolean`:case`BigInt`:case`Symbol`:case`Literal`:case`UniqueSymbol`:case`ObjectKeyword`:case`Enum`:case`TemplateLiteral`:return At;case`Arrays`:{let t=e.elements.map(Lf),n=e.rest.map(Lf),[r,...i]=n,a=i.length;return De((o,s)=>{if(!Array.isArray(o)||!Array.isArray(s))return!1;let c=o.length;if(c!==s.length)return!1;let l=0;for(;l<Math.min(c,e.elements.length);l++)if(!t[l](o[l],s[l]))return!1;if(n.length>0){for(;l<c-a;l++)if(!r(o[l],s[l]))return!1;for(let e=0;e<a;e++)if(!i[e](o[l+e],s[l+e]))return!1}return!0})}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return At;let t=e.propertySignatures.map(e=>Lf(e.type)),n=e.indexSignatures.map(e=>Lf(e.type));return De((r,i)=>{if(!Yn(r)||!Yn(i))return!1;for(let n=0;n<t.length;n++){let a=e.propertySignatures[n],o=a.name,s=Object.hasOwn(r,o),c=Object.hasOwn(i,o);if(Rl(a.type)&&s!==c||s&&c&&!t[n](r[o],i[o]))return!1}for(let t=0;t<n.length;t++){let a=e.indexSignatures[t],o=Cc(r,a.parameter),s=Cc(i,a.parameter);if(o.length!==s.length)return!1;for(let e=0;e<o.length;e++){let a=o[e];if(!Object.hasOwn(i,a)||!n[t](r[a],i[a]))return!1}}return!0})}case`Union`:{let t=Ul(e).types,n=qc(t),r=t.map((t,n)=>[Gu(t),Lf(e.types[n])]);return De((e,t)=>{let i=n(e,!1);for(let n=0;n<i.length;n++){let[a,o]=r[i[n]];if(a(e)&&a(t))return o(e,t)}return!1})}case`Suspend`:{let t;return De((n,r)=>(t??=If(e.thunk()))(n,r))}}}function Rf(e){let t=e.annotations?.representation;if(t===void 0)return At;switch(t.id){case`effect/schema/Option`:{let[t]=zf(e);return(e,n)=>e._tag===n._tag&&(e._tag===`None`||t(e.value,n.value))}case`effect/schema/Result`:{let[t,n]=zf(e);return(e,r)=>e._tag===r._tag&&(e._tag===`Success`?t(e.success,r.success):n(e.failure,r.failure))}case`effect/schema/CauseReason`:{let[t,n]=zf(e);return Bf(t,n)}case`effect/schema/Cause`:{let[t,n]=zf(e);return Vf(t,n)}case`effect/schema/Exit`:{let[t,n,r]=zf(e),i=Vf(n,r);return(e,n)=>e._tag===n._tag&&(e._tag===`Success`?t(e.value,n.value):i(e.cause,n.cause))}case`effect/schema/ReadonlyMap`:{let[t,n]=zf(e);return It(t,n)}case`effect/schema/ReadonlySet`:return nt(zf(e)[0]);case`effect/schema/RegExp`:return(e,t)=>e.source===t.source&&e.flags===t.flags;case`effect/schema/URL`:return(e,t)=>e.toString()===t.toString();default:return At}}function zf(e){return e.typeParameters.map(Lf)}function Bf(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case`Fail`:return e(n.error,r.error);case`Die`:return t(n.defect,r.defect);case`Interrupt`:return n.fiberId===r.fiberId}}}function Vf(e,t){let n=Me(Bf(e,t));return(e,t)=>n(e.reasons,t.reasons)}var Hf=m(2,(e,t)=>({...e,...t})),Uf=e=>e,Wf=`~effect/Schema/SchemaError`;function Gf(e){return ar(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}var Kf=dd;function qf(){return(e,t,n)=>D(new ec(e.map(Ic),e=>t(e.map(e=>D(e))),n))}function Jf(e,t){return qf()([],()=>(t,n,r)=>e(t)?v(t):y(new No(n,t,r)),t)}var Yf=class extends Ei(`SchemaError`){[Wf]=Wf;constructor(e){let t=Ce();Ie(0);try{super({issue:e})}finally{Ie(t)}}get message(){return Xo(this.issue)}toString(){return`SchemaError(${this.message})`}};function Xf(e){return Gf(e)}function Zf(e){return fe(e)?Qf(e):Mr(e,e=>Lr(()=>Pi(e,e=>new Yf(e))))}function Qf(e){return qi(e)?e:Ui(Pi(e.cause,e=>new Yf(e)))}function $f(e,t){let n;for(let r of e.reasons){if(!ki(r)||!Xf(r.error))throw new globalThis.Error(t,{cause:e});n??=r.error}if(n===void 0)throw new globalThis.Error(t,{cause:e});return n}function ep(e){let t=cr(e);if(qi(t))return t.value;throw $f(t.cause,`Sync adapter can only throw schema errors`)}function tp(e,t){return Mf(e,t)}function np(e){return Ff(e)}var rp=Uu;function ip(e,t){let n=Ku(e,t);return(e,t)=>Zf(n(e,t))}function ap(e,t){let n=qu(e,t);return(e,t)=>Qf(n(e,t))}var op=Ju;function E(e,t){let n=Yu(e,t);return(e,t)=>Et(n(e,t),e=>new Yf(e))}var sp=E;function cp(e,t){let n=ip(e,t);return(e,t)=>ep(n(e,t))}var lp=cp;function up(e,t){let n=Xu(e,t);return(e,t)=>Zf(n(e,t))}function dp(e,t){let n=Zu(e,t);return(e,t)=>Qf(n(e,t))}function fp(e,t){let n=Qu(e,t);return(e,t)=>Et(n(e,t),e=>new Yf(e))}var pp=fp;function mp(e,t){let n=up(e,t);return(e,t)=>ep(n(e,t))}var hp=mp,D=md;function gp(e){return ar(e,Kf)&&e[Kf]===Kf}var O=Uf(e=>D(kl(e.ast),{schema:e})),k=Uf(e=>{let t=Fp(e);return D(jl(e.ast),{schema:t})}),_p=Uf(e=>D(Ml(e.ast),{schema:e})),vp=Uf(e=>D(Ul(e.ast),{schema:e})),yp=Uf(e=>D(Wl(e.ast),{schema:e}));function A(e){let t=D(new sc(e),{literal:e,transform(n){return t.pipe(zp(A(n),{decode:ss(()=>n),encode:ss(()=>e)}))}});return t}var bp=D(ac),xp=D(oc),Sp=D(tc),Cp=D(ic),j=D(lc),M=D(fc),wp=D(pc),Tp=D(mc),Ep=D(hc);function Dp(e,t){return D(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Dp(Fc(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function N(e){return Dp(Fc(e,void 0),e)}function Op(e,t){return D(Ll(e.ast,t.ast),{key:e,value:t})}function kp(e,t){return D(e,{elements:t,mapElements(e,t){let n=e(this.elements);return kp(Lc(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Ap(e){return kp(Lc(e),e)}var jp=Uf(e=>D(new gc(!1,[],[e.ast]),{value:e})),Mp=Uf(e=>D(new gc(!1,[e.ast],[e.ast]),{value:e})),Np=Uf(e=>D(zc(e.ast),{schema:e}));function Pp(e,t){return D(e,{members:t,mapMembers(e,t){let n=e(this.members);return Pp(Rc(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function P(e,t){return Pp(Rc(e,t,void 0),e)}function F(e){let t=e.map(A);return D(Rc(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return P(e(this.members))},pick(e){return F(e)},transform(e){return P(t.map((t,n)=>t.transform(e[n])))}})}var I=Uf(e=>P([e,Sp])),Fp=Uf(e=>P([e,Cp]));function Ip(e){return D(new rl(()=>e().ast))}function L(...e){return t=>t.check(...e)}function Lp(e,t){return n=>D(bl(n.ast,[sl(e,t)]),{schema:n})}function Rp(e){return t=>D(t.ast,{schema:t,identifier:e})}function zp(e,t){return n=>D(Fl(n.ast,e.ast,t?Es(t):ks()),{from:n,to:e})}function Bp(e,t){return n=>t?zp(n,t)(e):zp(n)(e)}function Vp(e){return t=>D(Pl(t.ast,e),{schema:t})}function Hp(e){return Mr(e,e=>Lr(()=>Pi(e,e=>e.issue)))}function Up(e,t){let n=t?.encodingStrategy===`omit`?ds():as();return t=>k(yp(t)).pipe(zp(t,{decode:fs(Hp(e)),encode:n}))}function Wp(e,t){return n=>vp(n).pipe(Up(e,t),Bp(k(n)))}function Gp(e){return A(e).pipe(Vp(v(e)))}function Kp(e,t){return Jf(t=>t instanceof e,t)}function qp(){return(e,t)=>new Ys(e.ast,Es(t))}var R=ol,Jp=`^\\S[\\s\\S]*\\S$|^\\S$|^$`;function Yp(e){let t=new globalThis.RegExp(Jp);return R(e=>e.trim()===e,{expected:`a string with no leading or trailing whitespace`,representation:{id:`effect/schema/isTrimmed`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isTrimmed()`}),arbitraryConstraint:{patterns:[{source:Jp,flags:``}]},...e})}function Xp(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new RegExp(${d(n)})`:`new RegExp(${d(n)}, ${d(r)})`;return dl(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}var Zp=e=>e?new globalThis.RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;function Qp(e,t){let n=Zp(e);return Xp(n,{expected:e?`a UUID v${e}`:`a UUID`,representation:{id:`effect/schema/isUUID`,payload:{version:e??null}},toJsonSchema:()=>({pattern:n.source,format:`uuid`}),toCode:()=>({runtime:e===void 0?`Schema.isUUID()`:`Schema.isUUID(${e})`}),...t})}function $p(e){let t=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;return Xp(t,{expected:`a base64 encoded string`,representation:{id:`effect/schema/isBase64`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isBase64()`}),...e})}function em(e,t,n){if(e.length===0)return t.length===0?{}:[{},!0];let r={pattern:new globalThis.RegExp(n).source};return e===t?r:[r,!0]}function tm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`^${sf(e)}`),i=e.replace(/[\uD800-\uDBFF]$/,``);return R(t=>t.startsWith(e),{expected:`a string starting with ${n}`,representation:{id:`effect/schema/isStartingWith`,payload:{startsWith:e}},toJsonSchema:()=>em(i,e,`^${sf(i)}`),toCode:()=>({runtime:`Schema.isStartingWith(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}function nm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`${sf(e)}$`),i=e.replace(/^[\uDC00-\uDFFF]/,``);return R(t=>t.endsWith(e),{expected:`a string ending with ${n}`,representation:{id:`effect/schema/isEndingWith`,payload:{endsWith:e}},toJsonSchema:()=>em(i,e,`${sf(i)}$`),toCode:()=>({runtime:`Schema.isEndingWith(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}function rm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(sf(e)),i=e.replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,``);return R(t=>t.includes(e),{expected:`a string including ${n}`,representation:{id:`effect/schema/isIncluding`,payload:{includes:e}},toJsonSchema:()=>em(i,e,sf(i)),toCode:()=>({runtime:`Schema.isIncluding(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}var im=D(ll),am=cl;function om(e){let t=yn(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value greater than ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r,exclusiveMinimum:!0},...e.annotate?.(r),...i})}function sm(e){let t=pr(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value greater than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r},...e.annotate?.(r),...i})}function cm(e){let t=Zn(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value less than ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r,exclusiveMaximum:!0},...e.annotate?.(r),...i})}function lm(e){let t=On(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value less than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r},...e.annotate?.(r),...i})}function um(e){let t=pr(e.order),n=yn(e.order),r=On(e.order),i=Zn(e.order),a=e.formatter??d;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return R(e=>c(e,o.minimum)&&l(e,o.maximum),{expected:`a value between ${a(o.minimum)}${o.exclusiveMinimum?` (excluded)`:``} and ${a(o.maximum)}${o.exclusiveMaximum?` (excluded)`:``}`,arbitraryConstraint:{order:e.order,minimum:o.minimum,maximum:o.maximum,...o.exclusiveMinimum&&{exclusiveMinimum:!0},...o.exclusiveMaximum&&{exclusiveMaximum:!0}},...e.annotate?.(o),...s})}}function dm(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${d(e)}`);return e}var fm=om({order:Fr,annotate:e=>({representation:{id:`effect/schema/isGreaterThan`,payload:{exclusiveMinimum:dm(e)}},toJsonSchema:()=>({exclusiveMinimum:e}),toCode:()=>({runtime:`Schema.isGreaterThan(${d(e)})`})})}),z=sm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualTo`,payload:{minimum:dm(e)}},toJsonSchema:()=>({minimum:e}),toCode:()=>({runtime:`Schema.isGreaterThanOrEqualTo(${d(e)})`})})}),pm=cm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isLessThan`,payload:{exclusiveMaximum:dm(e)}},toJsonSchema:()=>({exclusiveMaximum:e}),toCode:()=>({runtime:`Schema.isLessThan(${d(e)})`})})}),mm=lm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualTo`,payload:{maximum:dm(e)}},toJsonSchema:()=>({maximum:e}),toCode:()=>({runtime:`Schema.isLessThanOrEqualTo(${d(e)})`})})}),hm=um({order:Fr,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:dm(e.minimum),maximum:dm(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${d(e.minimum)}, maximum: ${d(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}});function gm(e,t){if(!globalThis.Number.isFinite(e)||e===0)throw new globalThis.RangeError(`Expected a finite non-zero number, got ${globalThis.String(e)}`);return e=globalThis.Math.abs(e),R(t=>xa(t,e)===0,{expected:`a value that is a multiple of ${e}`,representation:{id:`effect/schema/isMultipleOf`,payload:{divisor:e}},toJsonSchema:()=>({multipleOf:e}),toCode:()=>({runtime:`Schema.isMultipleOf(${d(e)})`}),...t})}function _m(e){return R(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>[{type:`integer`},!0],toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}var B=M.check(_m()),vm=B.check(z(0));function ym(e){if(globalThis.Number.isNaN(e.getTime()))throw new globalThis.RangeError(`Expected a valid Date, got ${d(e)}`);return e.toISOString()}function bm(e){return`new Date(${d(e.getTime())})`}var xm=om({order:Kn,annotate:e=>({representation:{id:`effect/schema/isGreaterThanDate`,payload:{exclusiveMinimum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanDate(${bm(e)})`})})}),Sm=sm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualToDate`,payload:{minimum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanOrEqualToDate(${bm(e)})`})})}),Cm=cm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isLessThanDate`,payload:{exclusiveMaximum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanDate(${bm(e)})`})})}),wm=lm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualToDate`,payload:{maximum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanOrEqualToDate(${bm(e)})`})})}),Tm=um({order:Kn,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetweenDate`,payload:{minimum:ym(e.minimum),maximum:ym(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenDate({ minimum: ${bm(e.minimum)}, maximum: ${bm(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}}),Em=om({order:an,annotate:e=>({representation:{id:`effect/schema/isGreaterThanBigInt`,payload:{exclusiveMinimum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanBigInt(${d(e)})`})})}),Dm=sm({order:an,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualToBigInt`,payload:{minimum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanOrEqualToBigInt(${d(e)})`})})}),Om=cm({order:an,annotate:e=>({representation:{id:`effect/schema/isLessThanBigInt`,payload:{exclusiveMaximum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanBigInt(${d(e)})`})})}),km=lm({order:an,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualToBigInt`,payload:{maximum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanOrEqualToBigInt(${d(e)})`})})}),Am=um({order:an,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetweenBigInt`,payload:{minimum:e.minimum.toString(10),maximum:e.maximum.toString(10),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenBigInt({ minimum: ${d(e.minimum)}, maximum: ${d(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}});function jm(e,t){return e=zm(e),Mm(e,Math.ceil(e/2),t)}function Mm(e,t,n){return R(t=>t.length>=e,{expected:`a value with a length of at least ${e}`,representation:{id:`effect/schema/isMinLength`,payload:{minLength:e}},toJsonSchema:({type:n})=>n===`string`?e<=1?{minLength:t}:[{minLength:t},!0]:n===`array`?{minItems:e}:n===void 0?[{minLength:t,minItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMinLength(${e})`}),[oo]:!0,arbitraryConstraint:{minLength:e},...n})}function Nm(e){return Mm(1,1,e)}function V(e,t){return e=zm(e),R(t=>t.length<=e,{expected:`a value with a length of at most ${e}`,representation:{id:`effect/schema/isMaxLength`,payload:{maxLength:e}},toJsonSchema:({type:t})=>t===`string`?e===0?{maxLength:e}:[{maxLength:e},!0]:t===`array`?{maxItems:e}:t===void 0?[{maxLength:e,maxItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMaxLength(${e})`}),[oo]:!0,arbitraryConstraint:{maxLength:e},...t})}function Pm(e,t,n){return e=zm(e),t=zm(t),R(n=>n.length>=e&&n.length<=t,{expected:e===t?`a value with a length of ${e}`:`a value with a length between ${e} and ${t}`,representation:{id:`effect/schema/isBetweenLength`,payload:{minimum:e,maximum:t}},toJsonSchema:({type:n})=>n===`string`?t===0||Math.ceil(e/2)>t?{minLength:Math.ceil(e/2),maxLength:t}:[{minLength:Math.ceil(e/2),maxLength:t},!0]:n===`array`?{minItems:e,maxItems:t}:n===void 0?[{minLength:Math.ceil(e/2),maxLength:t,minItems:e,maxItems:t},!0]:[{},!0],toCode:()=>({runtime:`Schema.isBetweenLength(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minLength:e,maxLength:t},...n})}function Fm(e,t){return e=zm(e),R(t=>Rm(t,e)>=e,{expected:`a string with at least ${e} code points`,representation:{id:`effect/schema/isMinCodePoints`,payload:{minCodePoints:e}},toJsonSchema:()=>({minLength:e}),toCode:()=>({runtime:`Schema.isMinCodePoints(${e})`}),arbitraryConstraint:{minCodePoints:e},...t})}function Im(e,t){return e=zm(e),R(t=>Rm(t,e+1)<=e,{expected:`a string with at most ${e} code points`,representation:{id:`effect/schema/isMaxCodePoints`,payload:{maxCodePoints:e}},toJsonSchema:()=>({maxLength:e}),toCode:()=>({runtime:`Schema.isMaxCodePoints(${e})`}),arbitraryConstraint:{maxCodePoints:e},...t})}function Lm(e,t,n){return e=zm(e),t=zm(t),R(n=>{let r=Rm(n,t+1);return r>=e&&r<=t},{expected:e===t?`a string with ${e} code points`:`a string with between ${e} and ${t} code points`,representation:{id:`effect/schema/isBetweenCodePoints`,payload:{minimum:e,maximum:t}},toJsonSchema:()=>({allOf:[{minLength:e},{maxLength:t}]}),toCode:()=>({runtime:`Schema.isBetweenCodePoints(${e}, ${t})`}),arbitraryConstraint:{minCodePoints:e,maxCodePoints:t},...n})}function Rm(e,t){if(t===0)return 0;let n=0;for(let r of e)if(++n>=t)break;return n}function zm(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${e}`);return Math.max(0,Math.floor(e))}function Bm(e,t){return e=zm(e),R(t=>t.size>=e,{expected:`a value with a size of at least ${e}`,representation:{id:`effect/schema/isMinSize`,payload:{minSize:e}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isMinSize(${e})`}),[oo]:!0,arbitraryConstraint:{minSize:e},...t})}function Vm(e,t){return e=zm(e),R(t=>t.size<=e,{expected:`a value with a size of at most ${e}`,representation:{id:`effect/schema/isMaxSize`,payload:{maxSize:e}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isMaxSize(${e})`}),[oo]:!0,arbitraryConstraint:{maxSize:e},...t})}function Hm(e,t,n){return e=zm(e),t=zm(t),R(n=>n.size>=e&&n.size<=t,{expected:e===t?`a value with a size of ${e}`:`a value with a size between ${e} and ${t}`,representation:{id:`effect/schema/isBetweenSize`,payload:{minimum:e,maximum:t}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenSize(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minSize:e,maxSize:t},...n})}function Um(e,t){return e=zm(e),R(t=>Reflect.ownKeys(t).length>=e,{expected:`a value with at least ${e===1?`1 entry`:`${e} entries`}`,representation:{id:`effect/schema/isMinProperties`,payload:{minProperties:e}},toJsonSchema:({type:t})=>t===`object`?{minProperties:e}:[{minProperties:e},!0],toCode:()=>({runtime:`Schema.isMinProperties(${e})`}),[oo]:!0,arbitraryConstraint:{minProperties:e},...t})}function Wm(e,t){return e=zm(e),R(t=>Reflect.ownKeys(t).length<=e,{expected:`a value with at most ${e===1?`1 entry`:`${e} entries`}`,representation:{id:`effect/schema/isMaxProperties`,payload:{maxProperties:e}},toJsonSchema:({type:t})=>t===`object`?{maxProperties:e}:[{maxProperties:e},!0],toCode:()=>({runtime:`Schema.isMaxProperties(${e})`}),[oo]:!0,arbitraryConstraint:{maxProperties:e},...t})}function Gm(e,t,n){return e=zm(e),t=zm(t),R(n=>Reflect.ownKeys(n).length>=e&&Reflect.ownKeys(n).length<=t,{expected:e===t?`a value with exactly ${e===1?`1 entry`:`${e} entries`}`:`a value with between ${e} and ${t} entries`,representation:{id:`effect/schema/isBetweenProperties`,payload:{minimum:e,maximum:t}},toJsonSchema:({type:n})=>n===`object`?{minProperties:e,maxProperties:t}:[{minProperties:e,maxProperties:t},!0],toCode:()=>({runtime:`Schema.isBetweenProperties(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minProperties:e,maxProperties:t},...n})}var Km=j.check(Nm());globalThis.RegExp,globalThis.URL;var qm=j.annotate({expected:`a string that will be decoded as a Date`}),Jm=Jf(e=>e instanceof globalThis.Date&&!globalThis.Number.isNaN(e.getTime()),{representation:{id:`effect/schema/Date`,payload:null},toCode:()=>({runtime:`Schema.Date`,Type:`globalThis.Date`}),expected:`a valid Date`,toCodecJson:()=>qp()(qm,Ms)}),Ym=j.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function Xm(e,t){return Ym.pipe(zp(e,Ps(t)))}globalThis.File,globalThis.FormData,globalThis.URLSearchParams;var Zm=j.annotate({expected:`a string that will be decoded as a number`}).pipe(zp(M,As)),Qm=j.check(Yp()),$m=j.annotate({expected:`a string that will be decoded as a trimmed string`}).pipe(zp(Qm,Ds())),eh=j.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),th=Kp(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>qp()(eh,Ns)});function nh(e){return If(e.ast)}function rh(e,t){return kf(e.ast,t)}function ih(e,t){return Ef(kf(ef(e.ast),t),t)}var ah=$d,oh=D(vl(bu,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),sh=Op(j,oh),ch=b(()=>ur({id:S().min(1).max(256),name:S().min(1).max(128),kind:Kt(`agent`).optional()})),lh=b(()=>S().min(1).max(256)),uh=b(()=>ur({agentId:lh,sessionId:lh,commandId:lh,outcome:Tt([`completed`,`failed`,`interrupted`,`cancelled`,`outcome_unknown`]),diagnostic:S().min(1).max(200).optional()})),dh=ur({author:ch.optional(),sourceRequestId:lh.optional(),delegation:ur({ancestors:kt(lh).max(8),maxDepth:tn().int().min(1).max(8),reply:uh.optional()}).optional()});function fh(e){let t=dh.safeParse(e);return t.success?t.data.author:void 0}var ph=e=>crypto.getRandomValues(new Uint8Array(e)),mh=(e,t,n)=>{let r=256-256%e.length;if(r===256){let r=e.length-1;return(i=t)=>{if(!i)return``;let a=``;for(;;){let t=n(i),o=i;for(;o--;)if(a+=e[t[o]&r],a.length>=i)return a}}}let i=Math.ceil(409.6*t/r);return(a=t)=>{if(!a)return``;let o=``;for(;;){let t=n(i),s=i;for(;s--;)if(t[s]<r&&(o+=e[t[s]%e.length],o.length>=a))return o}}},hh=(e,t=21)=>mh(e,t|0,ph),gh=`abcdefghijklmnopqrstuvwxyz0123456789`;function _h(e=21){if(e===1/0||e===-1/0)throw RangeError(`nanoid length must be finite`);return hh(gh,e)()}var vh=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,yh=/^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$/,bh=S().min(1).max(64).regex(vh),xh=S().min(1).max(64).regex(vh),Sh=S().min(1).max(32).regex(yh),Ch=Un({prefix:Sh}),wh=Un({family:bh,version:Kt(1),kinds:cn(xh,Ch)}).superRefine((e,t)=>{let n=Object.entries(e.kinds);if(n.length<1||n.length>64){t.addIssue({code:`custom`,message:`Identifier families must declare between one and 64 kinds`});return}let r=new Set;for(let[,e]of n){if(r.has(e.prefix)){t.addIssue({code:`custom`,message:`Identifier kind prefixes must be distinct`});return}r.add(e.prefix)}}),Th=S(),Eh=/^[a-z0-9]+$/,Dh=new TextEncoder;function Oh(e){return e===32||e>=9&&e<=13}function kh(e){let t=0,n=e.length;for(;t<n&&Oh(e.charCodeAt(t));)t+=1;for(;n>t&&Oh(e.charCodeAt(n-1));)--n;return e.slice(t,n).replace(/[A-Z]/g,e=>String.fromCharCode(e.charCodeAt(0)+32))}function Ah(e){let t=`${e.prefix}_`;function n(e){if(!e.startsWith(t))return!1;let n=e.slice(t.length);return n.length===21&&Eh.test(n)}let r=b(()=>fn(e=>{let t=Th.safeParse(e);return t.success&&n(t.data)}));function i(i){let a,o=i,s=Dh.encode(o).byteLength,c=r.safeParse(o),l=o.startsWith(t)?o.slice(t.length):void 0;if(s<3||s>96)a=`bounds`;else if(l!==void 0&&Array.from(l).length!==21)a=`bounds`;else if(c.success)return{ok:!0,value:c.data};else a=n(kh(o))?`non_canonical`:`grammar`;return{ok:!1,error:{code:`invalid_id`,family:e.family,kind:e.kind,version:1,reason:a}}}let a=b(()=>Th.transform((e,t)=>{let n=i(e);return n.ok?n.value:(t.addIssue({code:`custom`,message:n.error.reason}),ut)}));function o(){let n;try{n=_h(21)}catch{throw e.entropyUnavailable()}return r.parse(`${t}${n}`)}return{family:e.family,kind:e.kind,version:1,generate:o,schema:a,parse:i,is:e=>i(e).ok}}var jh=cn(S(),Un({family:S(),kind:S(),version:Kt(1),generate:me(),schema:Ae(_e),parse:me(),is:me()})),Mh=class extends Error{name=`CairnDefinitionError`;code=`invalid_definition`;constructor(){super(`Cairn identifier family definition is invalid`)}},Nh=class extends Error{name=`CairnGenerationError`;code=`entropy_unavailable`;family;kind;version=1;constructor(e){super(`Cairn entropy source is unavailable`),this.family=e.family,this.kind=e.kind}};function Ph(e){let t;try{t=wh.safeParse(e)}catch{throw new Mh}if(!t.success)throw new Mh;let n=t.data,r={};for(let[t,i]of Object.entries(n.kinds)){let a=i.prefix;r[t]=Ah({family:e.family,kind:t,prefix:a,entropyUnavailable:()=>new Nh({family:n.family,kind:t})})}let i=fn(e=>{let t=jh.safeParse(e);if(!t.success)return!1;let r=Object.entries(t.data);return r.length===Object.keys(n.kinds).length&&r.every(([e,t])=>Object.hasOwn(n.kinds,e)&&t.kind===e&&t.family===n.family)}).safeParse(r);if(!i.success)throw new Mh;return i.data}var Fh=Symbol.for(`effect/MutableList/Empty`),Ih=()=>({head:void 0,tail:void 0,length:0}),Lh=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},Rh=()=>({array:[],mutable:!0,offset:0,next:void 0}),zh=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=Rh(),e.tail=e.tail.next):e.head=e.tail=Rh(),e.tail.array.push(t),e.length++},Bh=e=>{e.head=e.tail=void 0,e.length=0},Vh=(e,t)=>{if(t=ii(t),t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return Bh(e),t}let n=Array(t),r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,e.length===0?Bh(e):Lh(e),n;i=i.next}return Bh(e),n},Hh=e=>{if(!e.head)return Fh;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:Bh(e):Lh(e),t},Uh=`~effect/Queue`,Wh=`~effect/Queue/Enqueue`,Gh=`~effect/Queue/Dequeue`,Kh={_A:pt,_E:pt},qh={[Uh]:Kh,[Wh]:Kh,[Gh]:Kh,...Zr,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:cg(this)}}},Jh=e=>de(t=>{let n=Object.create(qh);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=Ih(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},Xn(n)}),Yh=e=>Jh({capacity:e}),Xh=m(2,(e,t)=>Sn(()=>Zh(e,t)?ug:e.state._tag===`Open`&&e.strategy===`suspend`?yg(e,t):lg)),Zh=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.strategy===`sliding`?(Hh(e.messages),zh(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(zh(e.messages,t),pg(e),!0):(zh(e.messages,t),mg(e),!0):!1,Qh=m(2,(e,t)=>$h(e,ee(t))),$h=m(2,(e,t)=>Vt(()=>eg(e,t))),eg=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=Bn(t),r=be(n,dg);return e.state.offers.size===0&&e.messages.length===0?(wg(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},mg(e),!0)},tg=e=>eg(e,ee(Ut())),ng=e=>Vt(()=>rg(e)),rg=e=>{if(e.state._tag===`Done`)return!1;Bh(e.messages);let t=e.state.offers;wg(e,e.state._tag===`Open`?fg:e.state.exit);for(let e of t)xg(e);return!0},ig=e=>ag(e,1,1/0),ag=m(3,(e,t,n)=>(t=ii(t),n=ii(n),gg(()=>hg(e,t,n)??ue(vg(e,()=>_g(e,t)),ag(e,t,n))))),og=e=>gg(()=>sg(e)??ue(vg(e,()=>_g(e,1)),og(e))),sg=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=Hh(e.messages);return Cg(e),c(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=Sg(e.state.offers);return Cg(e),c(t)}},cg=e=>e.state._tag===`Done`?0:e.messages.length,lg=c(!1),ug=c(!0),dg=Je(Ut()),fg=Le(),pg=e=>{if(e.state._tag!==`Done`&&e.state.takers.size!==0){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(Ct),e.messages.length===0))break}},mg=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,pg(e)},0))},hg=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return c([]);if(!_g(e,t))return;let r=e.messages.length>0?Vh(e.messages,n):[Sg(e.state.offers)];return Cg(e),c(r)},gg=Qe({op:`QueueTake`,[le](e){let t=this[qr]();return ze(t)?t[le](e):t}}),_g=(e,t)=>e.messages.length>=(e.state._tag===`Closing`?1:Math.min(t,e.capacity||1))||e.capacity<=0&&e.state._tag!==`Done`&&e.state.offers.size>0,vg=(e,t)=>Ye(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(Ct);let r={ready:t,resume:n};return e.state.takers.add(r),Vt(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),yg=(e,t)=>Ye(n=>Zh(e,t)?n(ug):bg(e,{_tag:`Single`,message:t,resume:n})),bg=(e,t)=>{if(e.state._tag!==`Open`)return xg(t);let n=e.state.offers;return n.add(t),Vt(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&wg(e,e.state.exit))})},xg=e=>e._tag===`Single`?e.resume(lg):e.resume(c(e.remaining.slice(e.offset))),Sg=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(ug),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(c([]))),n},Cg=e=>{if(e.state._tag===`Done`)return Ta(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(wg(e,e.state.exit),Ta(e.state.exit.cause));for(let t of e.state.offers){let n=e.capacity-e.messages.length;if(n<=0)break;if(t._tag===`Single`)zh(e.messages,t.message),e.state.offers.delete(t),t.resume(ug);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;zh(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(c([]))}let r=e.state;if(r._tag===`Done`)return Ta(r.exit.cause)}return!1},wg=(e,t)=>{if(e.state._tag===`Done`)return;let n=e.state;e.state={_tag:`Done`,exit:t};for(let e of n.takers)e.resume(t);n.takers.clear();for(let e of n.awaiters)e(t);n.awaiters.clear()},Tg=yt,Eg=he,Dg=Dt,Og=Ne,kg=tr,Ag=Ar,jg=e=>new Ng(e),Mg=(e,t,n)=>Ye(r=>{if(e.free>=t)return r(n);let i=()=>{e.free<t||(e.waiters.delete(i),r(n))};return e.waiters.add(i),Vt(()=>{e.waiters.delete(i)})}),Ng=class{waiters=new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){let t=Sn(()=>this.free<e?Mg(this,e,t):(this.taken+=e,Xn(e)));return t}takeIfAvailable(e){return Sn(()=>this.free<e?Xn(!1):(this.taken+=e,Xn(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{for(let e of this.waiters){if(this.free<=0)break;e()}},0),this.free}resize(e){return de(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),Xr))}release(e){return de(t=>Xn(this.releaseUnsafe(t,e)))}get releaseAll(){return de(e=>Xn(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>Br(n=>{let r=Sn(()=>{if(this.free<e){let t=Mg(this,e,Xr);return jt(n(t),()=>r)}return this.taken+=e,xr(n(t),()=>{this.releaseUnsafe(Lt(),e)},!0)});return r})}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>Br(n=>this.free<e?Dn:(this.taken+=e,xr(n(ae(t)),()=>{this.releaseUnsafe(Lt(),e)},!0)))}},Pg=e=>Vt(()=>new Ng(e)),Fg=`~effect/Channel`,Ig=e=>ar(e,Fg),Lg={[Fg]:{_Env:pt,_InErr:pt,_InElem:pt,_OutErr:pt,_OutElem:pt},pipe(){return o(this,arguments)}},Rg=e=>{let t=Object.create(Lg);return t.transform=(t,n)=>Mr(e(t,n),e=>v(Rt(e))),t},zg=(e,t)=>Rg((n,r)=>w(Hg(e)(n,r),e=>t(e,r))),Bg=e=>Rg((t,n)=>e),Vg=e=>Rg(ct(function*(t,n){let r=pa(n),i=e=>ma(r,ka(e)),a=yield*pe(e(t,n,r),i);return pe(a,i)})),Hg=e=>e.transform,Ug=4096,Wg=(e,t,n)=>Jh({capacity:n?.bufferSize,strategy:n?.strategy}).pipe(Qn(t=>da(e,ng(t))),Qn(n=>la(t(n),e).pipe(Mr(e=>$h(n,e)),Ge(e)))),Gg=(e,t)=>Rg((n,r)=>xe(Wg(r,e,t),ig)),Kg=e=>Rg((t,n)=>bn(()=>Hg(e())(t,n))),qg=e=>Bg(C(()=>{let t=e();return bn(()=>{let e=t.next();return e.done?Vi(e.value):v(e.value)})})),Jg=(e,t=Ug)=>{let n=ai(t);return Bg(C(()=>{let t=e(),r=Mn();return bn(()=>{if(r._tag===`Some`)return Vi(r.value);let e=[];for(;e.length<n;){let n=t.next();if(n.done){if(e.length===0)return Vi(n.value);r=sr(n.value);break}e.push(n.value)}return v(e)})}))},Yg=(e,t=Ug)=>Jg(()=>e[Symbol.iterator](),t),Xg=e=>$g(v(e)),Zg=Bg(v(Vi())),Qg=e=>Bg(Rt(e)),$g=e=>Bg(C(()=>{let t=!1;return bn(()=>t?Vi():(t=!0,e))})),e_=e=>Bg(v(ig(e))),t_=m(2,(e,t)=>zg(e,e=>C(()=>{let n=0;return xe(e,e=>t(e,n++))}))),n_=e=>e===void 0||e!==`unbounded`&&e<=1,r_=m(e=>Ig(e[0]),(e,t,n)=>n_(n?.concurrency)?i_(e,t):a_(e,t,n)),i_=(e,t)=>Rg((n,r)=>{let i=0;return xe(Hg(e)(n,r),w(e=>t(e,i++)))}),a_=(e,t,n)=>Vg(ct(function*(r,i,a){let o=0,s=yield*Hg(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:n.concurrency,l=yield*Yh(0);yield*da(a,ng(l));let u=nr(yield*gn()),d=Og(a);if(n.unordered){let e=jg(c),n=lt(e.release(1)),r=bt({onFailure:e=>w($h(l,e),n),onSuccess:e=>w(Xh(l,e),n)});yield*e.take(1).pipe(w(()=>s),w(e=>{let n=o++;return d(u(r(bn(()=>t(e,n))))),_}),ft({disableYield:!0}),Mr(t=>e.withPermits(c-1)($h(l,t))),Ge(a))}else{let e=yield*Yh(c-2);yield*da(a,ng(e)),yield*og(e).pipe(Gr,w(e=>Xh(l,e)),ft({disableYield:!0}),Mr(e=>$h(l,e)),Ge(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,eg(l,e.cause))};yield*s.pipe(w(i=>{if(n)return Rt(n);let a=o++,s=u(bn(()=>t(i,a)));return d(s),s.addObserver(r),Xh(e,Eg(s))}),ft({disableYield:!0}),Mr(t=>Xh(e,Ui(t)).pipe(Gt($h(e,t)))),Ge(a))}return og(l)})),o_=m(e=>Ig(e[0]),(e,t,n)=>n_(n?.concurrency)?s_(e,t):c_(e,t,n)),s_=(e,t)=>Rg((n,r)=>xe(Hg(e)(n,r),e=>{let i,a,o=w(e,e=>(a??=pa(r),Yt(Hg(t(e))(n,a),e=>(i=s(e),i)))),s=wa(e=>{if(i=void 0,a.state._tag===`Empty`)return o;let t=ma(a,Ki);return a=void 0,w(t,()=>o)});return bn(()=>i??o)})),c_=(e,t,n)=>e.pipe(t_(t),h_(n)),l_=e=>o_(e,pt),u_=e=>zg(e,e=>{let t,n=0,r=bn(function r(){if(t===void 0)return w(e,e=>{switch(e.length){case 0:return r();case 1:return v(e[0]);default:return t=e,v(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),v(i)});return v(r)}),d_=m(2,(e,t)=>zg(e,e=>v(w(e,function n(r){let i=[];for(let e=0;e<r.length;e++)t(r[e])&&i.push(r[e]);return Ze(i)?v(i):w(e,n)})))),f_=m(2,(e,t)=>Rg((n,r)=>{let i=pa(r);return xe(Hg(e)(n,i),e=>{let a=e.pipe(Mr(e=>{if(Ta(e))return Rt(e);let o=i;return i=pa(r),ma(o,Ui(e)).pipe(Gt(Hg(t(e))(n,i)),w(e=>(a=e,e)))}));return bn(()=>a)})})),p_=m(3,(e,t,n)=>f_(e,e=>{let r=t(e);return xt(r)?Qg(r.failure):n(r.success,e)})),m_=m(2,(e,t)=>p_(e,Ii,e=>t(e))),h_=m(2,(t,{bufferSize:n=16,concurrency:r,switch:i=!1})=>Vg(ct(function*(a,o,s){let c=r===`unbounded`?2**53-1:Math.max(1,r),l=i?void 0:jg(c),u=yield*Ag(!0),d=new Set,f=yield*Yh(n);yield*da(s,ng(f));let p=yield*Hg(t)(a,o);return yield*x(function*(){for(;;){let t;l&&(d.size<c?yield*l.take(1):(t=yield*oe(p),yield*e(l.take(1),Gt(Eg(t),wt))));let n=t===void 0?yield*p:yield*Eg(t),r=pa(s),i=yield*Hg(n)(a,r);for(;d.size>=c;){let e=oi(d);d.delete(e),d.size===0&&(yield*u.open),yield*Dg(e)}let o=yield*i.pipe(Qn(()=>Wr),w(e=>Xh(f,e)),ft({disableYield:!0}),pe(ct(function*(e){let t=ka(e),n=yield*wn(ma(r,t));if(!d.has(o))return;let i=Xi([t,n]);Ji(i)&&(yield*$h(f,i.cause)),d.delete(o),l&&(yield*l.release(1)),d.size===0&&(yield*u.open)})),oe);u.closeUnsafe(),d.add(o)}}).pipe(Mr(e=>{let t=Da(e);return ve(t)?u.whenOpen($h(f,e)):$h(f,e)}),Ge(s)),og(f)}))),g_=m(e=>Ig(e[0])&&Ig(e[1]),(e,t,n)=>Vg(ct(function*(r,i,a){let o=n?.haltStrategy??`both`,s=yield*Yh(0);yield*da(a,ng(s));let c=0;function l(e,t){if(c++,!Ta(t))return $h(s,t);switch(o){case`both`:return c===2?$h(s,t):_;case`left`:case`right`:return e===o?$h(s,t):_;case`either`:return $h(s,t)}}let u=(e,t,n)=>Hg(t)(r,n).pipe(w(e=>e.pipe(w(e=>Xh(s,e)),ft)),pe(t=>mr(ka(t),e=>ma(n,e)).pipe(bt({onFailure:t=>l(e,t),onSuccess:()=>l(e,t)}))),Ge(a));return yield*u(`left`,e,pa(a)),yield*u(`right`,t,pa(a)),og(s)}))),__=e=>Rg((t,n)=>{let r;return v(bn(()=>r||e.pipe(la(n),w(e=>Hg(e)(t,n)),w(e=>r=e))))}),v_=m(2,(e,t)=>g_(e,Bg(v(w(t,Vi))),{haltStrategy:`either`})),y_=m(2,(e,t)=>Vg((n,r,i)=>ua(i,t).pipe(Gt(Hg(e)(n,r))))),b_=m(2,(e,t)=>y_(e,e=>t)),x_=(e,t,n)=>bn(()=>{let r=ca(),i=Hg(e)(Vi(),r);return wa(w(i,t),n||v).pipe(ke(e=>ma(r,e)))}),S_=m(2,(e,t)=>x_(e,e=>ft(w(e,t),{disableYield:!0}))),C_=ct(function*(e){let t=jg(1),n=yield*gn(),r=zn(n,oa);return(yield*Hg(e)(Vi(),r)).pipe(Ft(n),t.withPermits(1))},Mr(e=>v(Rt(e)))),w_=(e,t)=>Hg(e)(Vi(),t),T_=`~effect/Stream`,E_={_R:pt,_E:pt,_A:pt},D_=function(e){this.channel=e};D_.prototype={[T_]:E_,pipe(){return o(this,arguments)}};var O_=e=>new D_(e),k_=`~effect/Stream`,A_=e=>ar(e,k_),j_=O_,M_=e=>j_($g(xe(e,Fe))),N_=e=>j_(Bg(e)),P_=(e,t)=>j_(Rg((n,r)=>w(w_(e.channel,r),e=>t(e,r)))),F_=e=>e.channel,I_=(e,t)=>j_(Gg(e,t)),L_=j_(Zg),R_=e=>j_(Xg(Fe(e))),z_=e=>j_(Kg(()=>e().channel)),B_=e=>j_(Qg(e)),V_=(e,t)=>Array.isArray(e)&&t?.chunkSize===void 0?H_(e):j_(Yg(e,t?.chunkSize)),H_=e=>Ze(e)?j_(Xg(e)):L_,U_=e=>j_(e_(e)),W_=(e,t)=>N_(C(()=>{let n=e,r=!1;return bn(function e(){return r?Vi():w(t(n),([t,i])=>(tt(i)?r=!0:n=i.value,Ze(t)?v(t):e()))})})),G_=e=>j_(__(xe(e,F_))),K_=m(2,(e,t)=>z_(()=>{let n=0;return j_(t_(e.channel,Se(e=>t(e,n++))))})),q_=m(e=>A_(e[0]),(e,t,n)=>e.channel.pipe(u_,r_(t,n),t_(Fe),j_)),J_=e=>e.pipe(K_(je),rv(e=>R_(at(e)))),Y_=m(e=>A_(e[0]),(e,t,n)=>e.channel.pipe(u_,o_(e=>t(e).channel,n),j_)),X_=m(2,(e,t)=>{let n=j_(l_(qg(()=>Q_(e,t))));return Z_.set(n,[e,t]),n}),Z_=new WeakMap;function*Q_(e,t){let n=[t,e];for(;n.length>0;){let e=n.pop(),t=Z_.get(e);t===void 0?yield e.channel:n.push(t[1],t[0])}}var $_=m(e=>A_(e[0])&&A_(e[1]),(e,t,n)=>j_(g_(F_(e),F_(t),n))),ev=m(2,(e,t)=>j_(d_(F_(e),t))),tv=m(2,ct(function*(e,t){let n,r=yield*C_(e.channel),i=Mr(r,e=>(n=e,Rt(e))),[a,o]=yield*qn(e=>t.transform(i,e)),s=n?L_:N_(v(r));return o&&(s=X_(H_(o),s)),[a,s]})),nv=m(2,(e,t)=>e.channel.pipe(f_(e=>t(e).channel),j_)),rv=m(2,(e,t)=>j_(m_(e.channel,e=>t(e).channel))),iv=m(e=>A_(e[0]),(e,t,n)=>P_(e,(e,r)=>C(()=>{let r=0,i=!1;return w(bn(()=>i?Vi():e),e=>{let a=e.findIndex(e=>t(e,r++));if(a>=0){i=!0;let t=e.slice(0,n?.excludeLast?a:a+1);return Ze(t)?v(t):Vi()}return v(e)})}))),av=m(2,(e,t)=>j_(v_(e.channel,t))),ov=m(2,(e,t)=>j_(b_(e.channel,t))),sv=m(2,(e,t)=>S_(e.channel,e=>{let n=0;return te({while:()=>n<e.length,body:()=>t(e[n++]),step:Kr})})),cv=m(2,(e,t)=>({[Symbol.asyncIterator](){let n=Nn(t),r=nr(t),i=ca(),a,o,s,c,l=e=>{if(c)return c;let t=s;return c=n(Cr(Gt(t?Dg(t):_,ma(i,e)),{done:!0,value:void 0})),c},u=async e=>{try{await l(e)}catch(e){await n(Xe(`Suppressed error while closing Stream async iterator`,e))}};return{async next(){if(c)return c;if(o){let e=o.next();if(!e.done)return e;o=void 0}let t=r(a??w(w_(e.channel,i),e=>(a=e,e)));s=t;let d=await n(Tg(t));if(s===t&&(s=void 0),qi(d))return o=d.value[Symbol.iterator](),o.next();if(Ta(d.cause))return l(Ki);if(c&&Ni(d.cause))return c;throw await u(d),Fi(d.cause)},return(){return l(Ki)},async throw(e){throw await u(Gi(e)),e}}}})),lv=e=>cv(e,qe()),uv=Km.check(V(256)),dv=B.check(z(0)),fv=N({id:uv,kind:Km.check(V(64)),summary:Km.check(V(200)),since:dv,expiresAt:k(dv),inbox:k(A(!1))}),pv=fv.mapFields(e=>({...e,extensionId:uv})),mv=4096,hv=jp(pv).check(V(64)),gv=j.pipe(L(jm(1)),L(V(256))),_v=N({providerId:gv,modelId:gv,reasoning:k(F([`minimal`,`low`,`medium`,`high`,`xhigh`,`max`]))}),vv=cp(I(_v)),yv=cp(Xm(I(_v))),bv=F([`contract`,`extensions`,`instructions`,`model`,`runtime`,`store`,`tools`]),xv=F([`closed`,`conflict`,`incompatible`,`invalid`,`rejected`,`unavailable`,`state_reset_required`,`storage_pressure`]),Sv=j.pipe(L(jm(1)),L(V(256))),Cv=N({_tag:A(`ShiitakeError`),boundary:bv,cause:xv,message:j,requestId:O(Sv)}),H=class extends Error{boundary;requestId;_tag=`ShiitakeError`;cause;underlying;constructor(e,t,n,r,i){super(n),this.boundary=e,this.requestId=r,this.name=`ShiitakeError`,this.cause=t,this.underlying=i}},wv=new TextEncoder;function Tv(e){return j.check(jm(1),V(e),R(t=>wv.encode(t).byteLength<=e))}var Ev=/\p{Cs}/u,Dv=Tv(256).check(R(e=>!Ev.test(e))),Ov=Tv(262144),kv=N({type:A(`image`),data:j.check(jm(1),V(1048576),$p()),mimeType:j.check(R(e=>[`image/png`,`image/jpeg`,`image/gif`,`image/webp`].includes(e)))}),Av=jp(kv).check(jm(1),V(8)),jv=F([`steer`,`followUp`]),Mv=Dv,Nv=E(Tv(512)),Pv=N({requestId:Dv}),Fv=N({delivery:jv,requestId:Dv,type:A(`prompt`),text:j.check(V(262144),R(e=>wv.encode(e).byteLength<=262144)),images:O(Av)}).check(R(e=>(e.text.length>0||(e.images?.length??0)>0)&&wv.encode(e.text).byteLength+(e.images??[]).reduce((e,t)=>e+t.data.length,0)<=1048576)),Iv=N({type:A(`abort`)}),Lv=N({commandId:Dv,onlyIfPending:k(wp),type:A(`cancel`)}),Rv=N({type:A(`operator`),requestId:Dv,author:F([`operator`,`party`]),text:Ov}),zv=N({type:A(`branch`),entryId:Dv}),Bv=N({type:A(`fork`),entryId:Dv}),Vv=j.check(jm(1),V(4096)),Hv=N({type:A(`compact`),requestId:Dv,instructions:O(Vv)}),Uv=P([Fv,Hv]),Wv=j.check(R(e=>e.length>0&&e.trim()===e&&!/\p{Cc}/u.test(e)&&Array.from(e).length<=120)),Gv=P([Fv,Iv,Lv,zv,Bv,Rv,Hv,N({type:A(`title`),title:I(Wv)})]),Kv=N({command:Gv}),qv=N({includeSandboxFailures:k(wp),limit:k(B.check(hm({minimum:1,maximum:200}))),before:k(Tv(512))}),Jv=N({includeSandboxFailures:k(A(`true`)),limit:k(Zm.check(_m(),hm({minimum:1,maximum:200}))),before:k(Tv(512))}),Yv=N({includeSandboxFailures:k(wp),after:k(j)}),Xv=N({includeSandboxFailures:k(A(`true`)),mode:k(A(`subscribe`)),after:k(j),limit:k(Zm.check(_m(),hm({minimum:1,maximum:200})))}),Zv={onExcessProperty:`error`},Qv=E(Mv,Zv),$v=E(Pv,Zv),ey=E(Uv,Zv);E(Dv);var ty=E(Gv,Zv);E(Kv,Zv);var ny=E(P([qv,Cp]),Zv);E(Jv,Zv);var ry=E(Yv,Zv);E(Xv,Zv);function iy(e){let t=Qv(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session id is invalid`);return t.success}function ay(e){let t=Nv(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session cursor is invalid`);return t.success}function oy(e){let t=$v(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session creation request is invalid`);return t.success.requestId}function sy(e){let t=ny(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Read options are invalid`);let n=t.success??{},r={limit:n.limit??200};return n.before!==void 0&&(r={...r,before:n.before}),n.includeSandboxFailures!==void 0&&(r={...r,includeSandboxFailures:n.includeSandboxFailures}),Object.freeze(r)}function cy(e){let t=ry(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Subscribe options are invalid`);let n={};return t.success.after!==void 0&&(n={...n,after:t.success.after}),t.success.includeSandboxFailures!==void 0&&(n={...n,includeSandboxFailures:t.success.includeSandboxFailures}),Object.freeze(n)}function ly(e,t){if(xt(e))throw new H(`contract`,`invalid`,t);return e.success}var uy=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/,dy=1e3,fy=221;function py(e,t){if(t>16)return t;if(Array.isArray(e)){let n=t;for(let r of e)n=Math.max(n,py(r,t+1));return n}if(e===null)return t;let n=cn(S(),yr()).safeParse(e);if(!n.success)return t;let r=t;for(let e of Object.values(n.data))r=Math.max(r,py(e,t+1));return r}var my=b(()=>cn(S(),yr()).superRefine((e,t)=>{Object.keys(e).length>100&&t.addIssue({code:`custom`,message:`Sample exceeds the entry bound`}),JSON.stringify(e).length>4e3&&t.addIssue({code:`custom`,message:`Sample exceeds the byte bound`}),py(e,0)>16&&t.addIssue({code:`custom`,message:`Sample exceeds the depth bound`})})),hy=b(()=>Un({query:S().max(200),maxResults:tn().int().min(1).max(50).default(50)})),gy=b(()=>Un({path:S().max(160),detail:Tt([`index`,`full`]).default(`full`),methods:kt(S().max(80)).max(50).optional()})),_y=Un({cursor:S().max(400).optional(),limit:tn().int().min(1).max(50).default(50),namespace:S().min(1).max(160).regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/).optional()}),vy=b(()=>Un({path:S().max(160),capabilityNotes:S().max(500).optional()})),yy=Un({path:S().max(160),description:S().max(1e3).optional(),score:tn().min(0).max(fy),matchReason:S().max(500).optional(),sample:my.optional(),capabilityNotes:S().max(500).optional(),peers:kt(vy).max(1e3).optional()}),by=b(()=>Un({results:kt(yy).max(50),total:tn().int().min(0).max(dy),truncated:t(),topScore:tn().min(0).max(fy),margin:tn().min(0).max(fy),catalogStamp:S().length(16).regex(/^[0-9a-f]{16}$/)})),xy=Un({results:kt(yy).max(50),total:tn().int().min(0).max(dy),nextCursor:S().max(400).nullable(),catalogStamp:S().length(16).regex(/^[0-9a-f]{16}$/)}),Sy=b(()=>Un({path:S().max(160),description:S().max(1e3).optional(),types:S().max(2e4),inputSchema:yr().refine(e=>JSON.stringify(e).length<=2e4&&py(e,0)<=16,`Input schema exceeds the description bounds`).optional(),kind:Tt([`module`,`operation`]),usage:S().max(300).optional()}));b(()=>Un({code:Tt([`empty_query`,`empty_catalog`,`unknown_target`,`duplicate_operation`,`invalid_input`]),message:S().max(1e3)}));var Cy=b(()=>Un({"~standard":Un({jsonSchema:Un({input:Ae(Function),output:Ae(Function)})})})),wy=b(()=>fn(e=>Cy.safeParse(e).success,`Expected a Standard JSON Schema`)),Ty=b(()=>Un({path:S().min(3).max(160).regex(uy),description:S().max(1e3).optional(),input:wy,output:wy.optional(),capabilityNotes:S().max(500).optional(),instructions:S().max(1e3).optional()})),Ey=b(()=>Un({revision:S().min(1).max(160),operations:kt(Ty).max(dy)})),Dy=class extends Error{code;failure;constructor(e,t,n){let r=t.slice(0,1e3);super(r,n),this.name=`ForageError`,this.code=e,this.failure={code:e,message:r}}},Oy=yr(),ky=b(()=>zt([S(),tn(),t()]));function Ay(e){return e!==null&&!Array.isArray(e)&&!ky.safeParse(e).success}function jy(e,t){if(e===t)return 0;let n=Math.min(e.length,t.length);for(let r=0;r<n;r+=1){let n=e.charCodeAt(r)-t.charCodeAt(r);if(n!==0)return n}return e.length-t.length}function My(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`).replace(/[_./:-]/g,` `).toLowerCase().trim()}function Ny(e){return e.split(/[^a-zA-Z0-9]+/).filter(e=>e.length>0)}var Py=new Set([`the`,`a`,`an`,`for`,`to`,`of`,`that`,`this`,`with`,`in`,`on`]);function Fy(e){return Py.has(e)}function Iy(e){let t=[],n=n=>{n!==e&&n.length>=3&&!t.includes(n)&&t.push(n)};return e.endsWith(`ing`)&&e.length>4&&n(e.slice(0,-3)),e.endsWith(`ed`)&&e.length>3&&n(e.slice(0,-2)),e.endsWith(`ies`)&&e.length>4&&(n(e.slice(0,-3)),n(`${e.slice(0,-3)}y`)),e.endsWith(`es`)&&e.length>3&&n(e.slice(0,-2)),e.endsWith(`s`)&&!e.endsWith(`ss`)&&e.length>3&&n(e.slice(0,-1)),t}function Ly(e){if(e===null)return`null`;let t=ky.safeParse(e);return t.success?JSON.stringify(t.data):Array.isArray(e)?`[${e.map(e=>Ly(e)).join(`,`)}]`:Ay(e)?`{${Object.entries(e).sort(([e],[t])=>jy(e,t)).map(([e,t])=>`${JSON.stringify(e)}:${Ly(t)}`).join(`,`)}}`:`null`}function Ry(e){let t=14695981039346656037n,n=(1n<<64n)-1n;for(let r=0;r<e.length;r+=1)t^=BigInt(e.charCodeAt(r)),t=t*1099511628211n&n;return t.toString(16).padStart(16,`0`)}function zy(e){return e.slice(e.indexOf(`.`)+1)}function By(e){return e.slice(0,e.indexOf(`.`))}var Vy=b(()=>zt([t(),ir({$ref:S().optional(),$defs:cn(S(),Vy).optional(),definitions:cn(S(),Vy).optional(),const:Rr().optional(),enum:kt(Rr()).optional(),oneOf:kt(Vy).optional(),anyOf:kt(Vy).optional(),allOf:kt(Vy).optional(),type:zt([S(),kt(S())]).optional(),properties:cn(S(),Vy).optional(),additionalProperties:Vy.optional(),required:kt(S()).optional(),prefixItems:kt(Vy).optional(),items:zt([Vy,kt(Vy)]).optional(),examples:kt(Rr()).optional(),default:Rr().optional()})])),Hy=new WeakMap;function Uy(e,t){let n=Hy.get(e),r=n?.[t];if(r!==void 0)return r;let i;try{i=Vy.parse(e[`~standard`].jsonSchema[t]({target:`draft-2020-12`}))}catch{throw new Dy(`invalid_input`,`Schema cannot be projected to JSON Schema`)}let a=Oy.safeParse(i),o={node:i,json:a.success?a.data:void 0};return n===void 0&&(n={},Hy.set(e,n)),n[t]=o,o}function Wy(e,t){return Uy(e,t).node}function Gy(e){return Array.isArray(e)}var Ky=256,qy=/^#\/(?:\$defs|definitions)\/([^/]+)$/u;function Jy(e,t,n){let r=qy.exec(e)?.[1];if(r===void 0||n.expanding.has(r))return`unknown`;let i=n.definitions[r];if(i===void 0)return`unknown`;if(n.budget.expansions+=1,n.budget.expansions>Ky)throw new Dy(`invalid_input`,`Schema references expand more than ${String(Ky)} times; flatten its shared definitions`);return Xy(i,t,{definitions:n.definitions,expanding:new Set([...n.expanding,r]),budget:n.budget})}function Yy(e,t){if(e===!0||e===!1)return!1;if(e.$ref!==void 0){let n=qy.exec(e.$ref)?.[1],r=n===void 0||t.expanding.has(n)?void 0:t.definitions[n];return n!==void 0&&r!==void 0&&Yy(r,{definitions:t.definitions,expanding:new Set([...t.expanding,n]),budget:t.budget})}return e.const===void 0?e.enum!==void 0&&e.enum.length>1||e.oneOf!==void 0&&e.oneOf.length>1||e.anyOf!==void 0&&e.anyOf.length>1:!1}function Xy(e,t,n){if(e===void 0||e===!0||e===!1||t>12)return`unknown`;if(e.$ref)return Jy(e.$ref,t,n);if(e.const!==void 0)return JSON.stringify(e.const);if(e.enum)return e.enum.map(e=>JSON.stringify(e)).join(` | `);if(e.oneOf)return e.oneOf.map(e=>Xy(e,t+1,n)).join(` | `);if(e.anyOf)return e.anyOf.map(e=>Xy(e,t+1,n)).join(` | `);if(e.allOf)return e.allOf.map(e=>{let r=Xy(e,t+1,n);return Yy(e,n)?`(${r})`:r}).join(` & `);if(e.type===`object`||e.properties){let r=Object.entries(e.properties??{}).sort(([e],[t])=>jy(e,t));if(r.length===0){let r=e.additionalProperties;return r===!1?`Record<string, never>`:r&&r!==!0?`Record<string, ${Xy(r,t+1,n)}>`:`Record<string, unknown>`}let i=new Set(e.required??[]);return`{
|
|
4
|
-
${r.map(([e,r])=>{let a=
|
|
3
|
+
`);n=Qo(e)??Ko(go(e.ast),e);break;default:n=Vo(e)}return t?`${n}\n at ${t}`:n}function Qo(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return Qo(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function $o(e){let t;for(let n of e.reasons){if(!ki(n)||!wo(n.error))return;t??=n.error}return t}function es(e,t){let n=$o(e);if(n===void 0)throw Error(t,{cause:e});return n}var ts=e=>Ga(e).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`),ns=e=>{let t=e.replace(/[\n\r]/g,``),n=t.length;if(n%4==1)return at(new Oi({module:`Base64Url`,kind:`Decode`,input:t,message:`Length should be a multiple of 4, but is ${n}`}));if(!/^[-_A-Z0-9]*?={0,2}$/i.test(t))return at(new Oi({module:`Base64Url`,kind:`Decode`,input:t,message:`Invalid input`}));let r=n%4==2?`${t}==`:n%4==3?`${t}=`:t;return r=r.replace(/-/g,`+`).replace(/_/g,`/`),Ka(r)},rs=e=>Object.assign(Object.create(Rn),e),is=rs({_tag:`Passthrough`});function as(){return is}function os(){return is}function ss(e){return rs({_tag:`Transform`,transform:e})}function cs(e){return rs({_tag:`TransformEffect`,transform:e})}function ls(e){return rs({_tag:`TransformOptional`,transform:e})}function us(e){return rs({_tag:`TransformOptionalEffect`,transform:e})}function ds(){return ls(()=>Mn())}function fs(e){return us(t=>{let n=gr(t,_n);return mn(n)?v(n):Pe(e,sr)})}function ps(){return ss(globalThis.String)}function ms(){return ss(globalThis.Number)}function hs(){return ss(globalThis.BigInt)}function gs(){return ss(e=>new globalThis.Date(e))}function _s(){return ss(Ca)}function vs(e){return cs((t,n)=>Qr({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Po({expected:`a valid JSON string`},t,n)}))}function ys(e){return cs((t,n)=>Qr({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new Po({expected:`a JSON-serializable value`},t,n)}))}function bs(){return ss(Ga)}function xs(){return cs((e,t)=>$r(a(Ka(e)),()=>new Po({expected:`a valid Base64 string`},e,t)))}var Ss=class extends Ke{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Ss(this.encode,this.decode)}},Cs=`~effect/SchemaTransformation/Transformation`,ws=class extends Ke{[Cs]=Cs;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new ws(this.encode,this.decode)}};function Ts(e){return ar(e,Cs)&&e[Cs]===Cs}var Es=e=>Ts(e)?e:new ws(e.decode,e.encode);function Ds(){return new ws(_s(),as())}var Os=new ws(as(),as());function ks(){return Os}var As=new ws(ms(),ps()),js=new ws(hs(),ps()),Ms=new ws(gs(),ss(St)),Ns=new ws(xs(),bs());function Ps(e){return new ws(vs(e??{}),ys(e))}function Fs(e){return t=>t._tag===e}var Is=Fs(`Declaration`),Ls=Fs(`Null`),Rs=Fs(`Undefined`),zs=Fs(`Never`),Bs=Fs(`String`),Vs=Fs(`Number`),Hs=Fs(`Boolean`),Us=Fs(`Literal`),Ws=Fs(`UniqueSymbol`),Gs=Fs(`Arrays`),Ks=Fs(`Objects`),qs=Fs(`Union`),Js=Fs(`Suspend`),Ys=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},Xs={},Zs=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},Qs=`~effect/Schema`,$s=class{[Qs]=Qs;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}},ec=class extends $s{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>t===T?yo:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=Dl(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new ec(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},tc=new class extends $s{_tag=`Null`;getParser(){return Jl(this,null)}getExpected(){return`null`}},nc=class extends $s{_tag=`Undefined`;getParser(){return Jl(this,void 0)}toCodecJson(){return hl(this,[rc])}getExpected(){return`undefined`}},rc=new Ys(tc,new ws(ss(()=>void 0),ss(()=>null))),ic=new nc,ac=new class extends $s{_tag=`Never`;getParser(){return Yl(this,Nr)}getExpected(){return`never`}},oc=new class extends $s{_tag=`Unknown`;getParser(){return Yl(this,Xt)}getExpected(){return`unknown`}},sc=class extends $s{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${d(e)}`);this.literal=e}getParser(){return Jl(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?cc(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:cc(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function cc(e){let t=globalThis.String(e.literal);return hl(e,[new Ys(new sc(t),new ws(ss(()=>e.literal),ss(()=>t)))])}var lc=new class extends $s{_tag=`String`;getParser(){return Yl(this,Bt)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&du(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},uc=class extends $s{_tag=`Number`;getParser(){return Yl(this,dr)}matchKey(e,t){return this._match(eu,e,t)}matchPart(e,t){return this._match($l,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:du(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(dc(this.checks,`effect/schema/isFinite`)||dc(this.checks,`effect/schema/isInt`))?this:hl(this,[ul])}toCodecStringTree(){return this.toCodecJson()===this?hl(this,[ru]):hl(this,[iu])}getExpected(){return`number`}};function dc(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&dc(e.checks,t))}var fc=new uc,pc=new class extends $s{_tag=`Boolean`;getParser(){return Yl(this,nn)}getExpected(){return`boolean`}},mc=new class extends $s{_tag=`Symbol`;getParser(){return Yl(this,zr)}matchKey(e,t){return t.disableChecks||!this.checks?e:du(this.checks,e,void 0,this,t)?void 0:e}toCodecStringTree(){return hl(this,[lu])}getExpected(){return`symbol`}},hc=new class extends $s{_tag=`BigInt`;getParser(){return Yl(this,Tr)}matchPart(e,t){if(!au.test(e))return;let n=globalThis.BigInt(e);return t.disableChecks||!this.checks?n:du(this.checks,n,void 0,this,t)?void 0:n}toCodecStringTree(){return hl(this,[su])}getExpected(){return`bigint`}},gc=class extends $s{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(Rl(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(Rl(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}let c=e=>{let{input:t,len:r,options:i}=e;if(n.rest.length===0&&r>a)for(let o=a;o<r;o++){let r=new jo(n,t[o],i),a=new ko([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return y(new Mo(n,[a],t,i))}return e.issues?y(new Mo(n,e.issues,t,i)):vo(e.output)},l=(e,t)=>{let r=e.length,i={ast:n,getParser:s,input:e,len:r,tailThreshold:Math.max(a,r-o),output:new globalThis.Array(r),issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:Jt(t.concurrency),f=d===1?yc(i,e,0,u):bc(i,e,{concurrency:d,end:u});if(!f)return c(i);if(fe(f))return Yt(f,()=>c(i));let p=!0;return bn(()=>p?(p=!1,w(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===T)return yo;try{return Array.isArray(e)?(r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)}))),l(e,a)):y(new No(n,e,a))}catch(e){return lr(e)}}}_rebuild(e,t,n){let r=Dl(this.elements,e),i=Dl(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new gc(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function _c(e,t,n,r){if(n._tag===`Failure`)return xc(e,e.ast,r,n);let i=n===bo?t:n[qr];if(i!==T)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(Rl(t.ast))return;let n=new ko([r],new Ao(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return Wi(new Mo(e.ast,[n],e.input,e.options))}}var vc={onItem(e,t,n){let r=n<e.len?t:T;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:_c},yc=pn()(vc),bc=i()(vc),xc=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=$o(r.cause);if(i===void 0)return Ui(Pi(r.cause,r=>new Mo(t,[new ko([n],r)],e.input,e.options)));let a=new ko([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return Wi(new Mo(t,[a],e.input,e.options))},Sc=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function Cc(e,t,n=Xs){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(r=>Object.prototype.propertyIsEnumerable.call(e,r)&&t.matchKey(r,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(Xl(Wl(t)))}var wc=class{name;type;constructor(e,t){this.name=e,this.type=t}};function Tc(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(Tc);default:return!1}}function Ec(e){let t=_l(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(Ec);default:return!1}}function Dc(e){return Tc(e)&&Ec(e)}var Oc=class{parameter;type;constructor(e,t){if(!Dc(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Rl(t)&&!ql(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},kc=class extends $s{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o}getParser(e,t=e){let n=this,r=n.propertySignatures.length,a=n.indexSignatures.length;if(!r&&!a)return Yl(n,ln);let o,s,c=()=>(o||(o=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type})),s=a?n.indexSignatures.map(n=>({is:n,parserKey:e(Xl(n.parameter)),parserValue:t(n.type)})):void 0),o),l=()=>{let e=new Set(n.propertySignatures.map(e=>typeof e.name==`number`?globalThis.String(e.name):e.name)),t=(t,i,a,o,s)=>{if(s._tag===`Failure`)return xc(t,n,i,s)??Ki;let c=s===bo?o:s[qr];if(a!==T&&c!==T){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return Ki;g(t.out,a,c)}return Ki},l=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!fe(t))return w(wn(t),t=>l(e,r,i,t));a=t}if(a._tag===`Failure`)return xc(e,n,r,a)??Ki;let o=a===bo?r:a[qr],s=e.input[r],c=i.parserValue(s,e.options);return fe(c)?t(e,r,o,s,c):w(wn(c),n=>t(e,r,o,s,n))},u=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return fe(a)?t(e,n,n,i,a):w(wn(a),r=>t(e,n,n,i,r))},d=a?i()({onItem:(e,[t,n])=>n.is.parameter===lc?u(e,t,n):l(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return p(function*(t,i){if(t===T)return T;if(!(typeof t==`object`&&t&&!Array.isArray(t)))return yield*y(new No(n,t,i));c();let f=t,p={},m={ast:n,input:f,out:p,issues:void 0,options:i},ee=i.errors===`all`,te=i.onExcessProperty===`error`,ne=i.concurrency===void 0?1:Jt(i.concurrency),h=a&&te?n.indexSignatures.map(e=>Cc(f,e.parameter,i)):void 0;if(te){let r=h?new Set(e):e;if(h)for(let e of h)for(let t of e)r.add(t);let a=Reflect.ownKeys(f);for(let e=0;e<a.length;e++){let o=a[e];if(!r.has(o)&&Object.prototype.propertyIsEnumerable.call(f,o)){let e=new jo(n,f[o],i),r=new ko([o],e);if(ee){m.issues?m.issues.push(r):m.issues=[r];continue}return yield*y(new Mo(n,[r],t,i))}}}if(r){let e=ne===1?Mc(m,o):Nc(m,o,{concurrency:ne});e&&(yield*e)}if(a&&ne===1)for(let e=0;e<a;e++){let t=s[e],n=t.is.parameter===lc?u:l,r=h?.[e]??(t.is.parameter===lc?Object.keys(f):Cc(f,t.is.parameter,i));for(let e=0;e<r.length;e++){let i=n(m,r[e],t);if(!fe(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(d){let e=Pn();for(let t=0;t<a;t++){let n=s[t],r=h?.[t]??(n.is.parameter===lc?Object.keys(f):Cc(f,n.is.parameter,i));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=d(m,e,{concurrency:ne});t&&(yield*t)}return m.issues?yield*y(new Mo(n,m.issues,t,i)):p})};if(a)return l();let u,d=(e,t,n)=>{let r=o[t];return w(wn(n),n=>{let i=Ac(e,r,n);if(i)return i;let a=()=>vo(e.out),s=Mc(e,o.slice(t+1));return s?Yt(s,a):a()})};return(e,t)=>{if(e===T)return yo;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&Jt(t.concurrency)!==1)return(u??=l())(e,t);if(!(typeof e==`object`&&e&&!Array.isArray(e)))return y(new No(n,e,t));let r=c(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=Kc(i,s),l=c?i[s]:T,u=n.parser(l,t);if(!fe(u))return d(o,e,u);if(u===bo){c&&g(a,s,l);continue}let f=Ac(o,n,u);if(f)return f}}catch(e){return lr(e)}return vo(a)}}_rebuild(e,t,n,r){let i=Dl(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new wc(t.name,n)}),a=Dl(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new Oc(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new kc(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function Ac(e,t,n){if(n._tag===`Failure`)return xc(e,e.ast,t.name,n);if(n===bo)return;let r=n[qr];if(r!==T){g(e.out,t.name,r);return}if(delete e.out[t.name],!Rl(t.type)){let n=new ko([t.name],new Ao(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return Wi(new Mo(e.ast,[n],e.input,e.options))}}var jc={onItem(e,t){if(!Kc(e.input,t.name))return t.parser(T,e.options);let n=e.input[t.name];return g(e.out,t.name,n),t.parser(n,e.options)},step:Ac},Mc=pn()(jc),Nc=i()(jc);function Pc(e,t){return e?t?[...e,...t]:e:t}function Fc(e,t,n){return new kc(Reflect.ownKeys(e).map(t=>new wc(t,e[t].ast)),[],n,t)}function Ic(e){return e.ast}function Lc(e,t=void 0){return new gc(!1,e.map(e=>e.ast),[],void 0,t)}function Rc(e,t,n){return new Jc(e.map(Ic),t,void 0,n)}function zc(e){if(e.encoding)throw Error(`mutable does not support encodings`);return new gc(!0,e.elements,e.rest,e.annotations,e.checks,void 0,e.context,e.encodingChecks)}var Bc=h(e=>{for(;;){if(Js(e))return oc;let t=e.encoding;if(!t)return e.recur?.(Bc,pt)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==pt))return oc;e=t[t.length-1].to}});function Vc(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(Vc)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function Hc(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[co];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!Rl(t)){if(Us(t))return[{key:e.name,literal:t.literal}];if(Ws(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!Rl(e)){if(Us(e))return[{key:t,literal:e.literal}];if(Ws(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>Hc(Bc(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return Hc(e.thunk())}}var Uc=new WeakMap,Wc=Object.freeze([]),Gc=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Kc=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function qc(e){let t=Uc.get(e);if(t)return t;let n,r=0,i,a,o=!0,s=[];for(let t=0;t<e.length;t++){let c=e[t],l=Bc(c);if(zs(l))continue;if(Us(l)||Ws(l)){a??=new Map;let e=Us(l)?l.literal:l.symbol;s[t]=e;let n=a.get(e);n||a.set(e,n=[]),n.push(t)}else o=!1;let u=Hc(l);if(u.length){n??=new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=Vc(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??Wc);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??Wc;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=new Map;for(let[e,t]of i)a.set(e,Object.freeze(Array.from(t)));let o=Object.freeze(e.map((e,t)=>t));t=(e,t)=>{if(En(e)){let n=Kc(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??Wc;if(t)return o}return Wc}}else if(n){let e;for(let t of n)(!e||t[1][0].size>e[1][0].size)&&t[1][1].size===r&&(e=t);t=(t,r)=>{let a=Gc(t);if(!En(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=Kc(t,n),u=c?t[n]:void 0;if(c&&(!r||u!==void 0)){let e=i.get(u);if(!e)return l(a);for(let t of e)o.add(t);s=n}}if(s===void 0)for(let[e,[i,a]]of n){let n=Kc(t,e),s=n?t[e]:void 0;if(n&&(!r||s!==void 0)){let e=i.get(s);if(e)for(let t of e)o.add(t)}else if(r)for(let e of a)o.add(e)}for(let[e,[i,a]]of n){if(e===s)continue;let n=Kc(t,e),c=n?t[e]:void 0;if(n&&(!r||c!==void 0)){let e=i.get(c);for(let t of o)a.has(t)&&!e?.has(t)&&o.delete(t)}}return Array.from(o).sort((e,t)=>e-t)}}else t=e=>{let t=l(Gc(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return Uc.set(e,t),t}var Jc=class extends $s{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this,r=t!==void 0,i=[],a=t=>i[t]??=e(n.types[t]),o;return(e,t)=>{if(e===T)return yo;let i=(o??=qc(n.types))(e,r);if(i.length===0)return y(new Io(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:fe(r)?Yc(n,r.cause,e,t):Xc(n,r,e,t)}return Zc(n,a,i,e,t)}}_rebuild(e,t,n){let r=Dl(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new Jc(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=Wl(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Us);if(t.length>0)return`${tl(n.isMutable)}[ ${t.map(t=>e(t)+nl(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Us(e.type));if(t.length>0)return`{ ${t.map(t=>`${tl(t.type.context?.isMutable)}${vt(t.name)}${nl(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function Yc(e,t,n,r){let i=$o(t);return i?Wi(new Io(e,[i],n,r)):Ui(t)}function Xc(e,t,n,r){return Mr(t,t=>Yc(e,t,n,r))}function Zc(e,t,n,r,i){let a={ast:e,parser:t,input:r,out:void 0,successes:e.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},o=$c(a,n);if(!o)return a.out?a.out:y(new Io(e,a.issues??[],r,i));if(fe(o))return Qc(o,a);let s=!0;return bn(()=>s?(s=!1,Qc(o,a)):Zc(e,t,n,r,i))}function Qc(e,t){return Yt(e,e=>t.out===bo?v(t.input):t.out?t.out:y(new Io(t.ast,t.issues??[],t.input,t.options)))}var $c=pn()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=$o(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(e.ast.types[t]),Wi(new Lo(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return Ki}}}),el=new Jc([new sc(`Infinity`),new sc(`-Infinity`),new sc(`NaN`)]);function tl(e){return e?``:`readonly `}function nl(e){return e?`?`:``}var rl=class extends $s{_tag=`Suspend`;thunk;constructor(e,t,n,r,i){if(n)throw Error(`Cannot add checks to Suspend`);super(t,void 0,r,i);let a;this.thunk=()=>a??=e()}getParser(e){let t;return(n,r)=>(t??=e(this.thunk()))(n,r)}recur(e){return new rl(()=>e(this.thunk()),this.annotations,void 0,void 0,this.context)}getExpected(e){return e(this.thunk())}},il=class extends Ke{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new il(this.run,{...this.annotations,...e},this.aborted)}abort(){return new il(this.run,this.annotations,!0)}and(e,t){return new al([this,e],t)}},al=class extends Ke{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new al(this.checks,{...this.annotations,...e})}and(e,t){return new al([this,e],t)}};function ol(e,t,n=!1){return new il((t,n,r)=>Bo(n,e(t,n,r),t,r),t,n)}function sl(e,t){return new il((t,n,r)=>e(t)?void 0:new Po(void 0,t,r),t,!0)}function cl(e){return ol(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}var ll=bl(fc,[cl()]),ul=new Ys(new Jc([ll,el]),new ws(ms(),ss(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function dl(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return ol(e=>(n.lastIndex=0,n.test(e)),{expected:`a string matching the RegExp ${r.source}`,representation:{id:`effect/schema/isPattern`,payload:r},toJsonSchema:()=>[{},!0],arbitraryConstraint:{patterns:[r]},...t})}var fl=new WeakMap;function pl(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&fl.set(n,ml(e)),n}function ml(e){let t=fl.get(e);if(t!==void 0)return t;if(e.encoding===void 0)return e;let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,{encoding:void 0});return fl.set(e,n),n}function hl(e,t){return e.encoding===t?e:pl(e,{encoding:t})}function gl(e,t){if(e.context===t)return e;let n=ml(e);return n.context===t&&n.encoding===e.encoding?n:pl(e,{context:t})}function _l(e){return e.encoding?_l(e.encoding[e.encoding.length-1].to):e}function vl(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return yl(e,s(e.checks.slice(0,-1),n.annotate(t)))}return pl(e,{annotations:{...e.annotations,...t}})}function yl(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:pl(e,{checks:t})}function bl(e,t){return yl(e,Pc(e.checks,t))}function xl(e,t){let n=t(e.to);return n===e.to?e:new Ys(n,e.transformation)}function Sl(e,t){let n=e,r=n[n.length-1],i=xl(r,t);return i===r?e:s(e.slice(0,e.length-1),i)}function Cl(e){return t=>t.encoding?hl(t,Sl(t.encoding,e)):t}function wl(e,t){return Cl(e=>gl(e,t))(e)}function Tl(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:hl(r,Sl(r.encoding,n))}return e(r)}return h(n)}function El(e,t,n){let r=new Ys(e,t);return hl(n,n.encoding?[...n.encoding,r]:[r])}function Dl(e,t){let n;for(let r=0;r<e.length;r++){let i=e[r],a=t(i);if(n)n[r]=a;else if(a!==i){n=Array(e.length);for(let t=0;t<r;t++)n[t]=e[t];n[r]=a}}return n??e}function Ol(e,t){return gl(e,e.context?new Zs(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new Zs(!1,!1,void 0,t))}var kl=h(e=>Al(gl(e,e.context?e.context.isOptional===!1?new Zs(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new Zs(!0,!1)))),Al=Cl(kl),jl=se(e=>kl(new Jc([e,ic]))),Ml=h(e=>Nl(gl(e,e.context?e.context.isMutable===!1?new Zs(e.context.isOptional,!0,e.context.constructorDefault,e.context.annotations):e.context:new Zs(!1,!0)))),Nl=Cl(Ml);function Pl(e,t){return gl(e,e.context?new Zs(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new Zs(!1,!1,t))}function Fl(e,t,n){return El(e,n,t)}function Il(e){let t=[],n=[];function r(e){switch(e._tag){case`Literal`:xn(e.literal)&&!t.includes(e.literal)&&t.push(e.literal);return;case`UniqueSymbol`:t.includes(e.symbol)||t.push(e.symbol);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)r(e.types[t]);return;default:n.push(e)}}return r(e),{literals:t,parameters:n}}function Ll(e,t){let{literals:n,parameters:r}=Il(e);return new kc(n.map(e=>new wc(e,t)),r.map(e=>new Oc(e,t)))}function Rl(e){return e.context?.isOptional??!1}function zl(e){return e.context?.isMutable??!1}function Bl(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(Bl)}function Vl(e){function t(e){return Bl(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return He(n)?n:void 0}function Hl(e){let t=!0;function n(e){return t=t&&!e.encoding&&!Js(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}var Ul=h(e=>{let t=ml(e);if(t!==e){let n=Ul(t);return n===t&&e.encoding===void 0?e:gl(n,e.context)}let n=`recur`in e?e.recur(Ul):e;if(`encodingChecks`in n&&n.encodingChecks){let t=Hl(e)?n.encodingChecks:Gs(n)||Ks(n)||Is(n)&&n.typeParameters.length>0?Vl(n.encodingChecks):void 0;return pl(n,{encodingChecks:void 0,checks:Pc(n.checks,t)})}return n}),Wl=h(e=>Ul(Kl(e)));function Gl(e,t){let n=t,r=n.length,i=n[r-1],a=[new Ys(Kl(hl(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new Ys(Kl(n[e-1].to),n[e].transformation.flip()));let o=Kl(i.to);return o.encoding?hl(o,[...o.encoding,...a]):hl(o,a)}var Kl=se(e=>{if(e.encoding)return Gl(e,e.encoding);let t=ml(e);if(t!==e){let n=Kl(t);return n===t?e:gl(n,e.context)}return`flip`in e?e.flip(Kl):`recur`in e?e.recur(Kl):e});function ql(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some(ql);default:return!1}}function Jl(e,t){let n=t===0?bo:vo(t);return(r,i)=>r===T?yo:r===t?n:y(new No(e,r,i))}function Yl(e,t){return(n,r)=>n===T?yo:t(n)?bo:y(new No(e,n,r))}var Xl=Tl(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(Xl)}}),Zl=Tl(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(Zl)}}),Ql=`[\\s\\S]*?`,$l=new globalThis.RegExp(`^${Sc}$`),eu=new globalThis.RegExp(`^(?:${Sc}|Infinity|-Infinity|NaN)$`);function tu(e){return dl($l,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:$l.source}),...e})}var nu=bl(lc,[tu()]),ru=new Ys(nu,As),iu=new Ys(new Jc([nu,el]),As),au=new globalThis.RegExp(`^-?\\d+$`);function ou(e){return dl(au,{expected:`a string representing a bigint`,representation:{id:`effect/schema/isStringBigInt`,payload:null},toJsonSchema:()=>({pattern:au.source}),...e})}var su=new Ys(bl(lc,[ou({expected:`a string representing a bigint`})]),js),cu=new globalThis.RegExp(`^Symbol\\(([\\s\\S]*)\\)$`),lu=new Ys(bl(lc,[uu()]),new ws(ss(e=>globalThis.Symbol.for(cu.exec(e)[1])),cs((e,t)=>globalThis.Symbol.keyFor(e)===void 0?y(new Fo({message:`cannot serialize to string, Symbol is not registered`},e,t)):v(globalThis.String(e)))));function uu(e){return dl(cu,{expected:`a string representing a symbol`,representation:{id:`effect/schema/isStringSymbol`,payload:null},toJsonSchema:()=>({pattern:cu.source}),...e})}function du(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=du(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new Do(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function fu(e){if(!Is(e))return;let t=e.annotations?.[lo];return Wn(t)?t(e.typeParameters):void 0}var pu=io,mu=mo,hu=ho;function gu(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function _u(e){return e===void 0||typeof e==`string`}function vu(e,t){let n=new WeakMap,r=[];outer:for(;;){if(typeof e!=`object`||!e){if(!t(e))return!1}else{let t=e,i=n.get(t);if(i===!1)return!1;if(i===void 0){let e=Array.isArray(t);if(!e){let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null)return!1}n.set(t,!1),r.push({value:t,keys:e?t.length:Object.keys(t),index:0})}}for(;r.length>0;){let t=r[r.length-1],i=t.keys;if(typeof i==`number`){if(t.index<i){e=t.value[t.index++];continue outer}}else if(t.index<i.length){e=t.value[i[t.index++]];continue outer}n.set(t.value,!0),r.pop()}return!0}}function yu(e){return vu(e,gu)}var bu=new ec([],()=>(e,t,n)=>yu(e)?bo:y(new No(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>wu}),xu=new Ys(bu,ks()),Su=new Ys(new Jc([new gc(!1,[],[bu]),new kc([],[new Oc(lc,bu)])]),ks());function Cu(e){return vu(e,_u)}var wu=new Ys(new ec([],()=>(e,t,n)=>Cu(e)?bo:y(new No(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),ks()),Tu=(e,t,n)=>e===bo?n(t):Yt(e,n);function Eu(e){if(e._tag===`Middleware`)return(t,n,r)=>Du(t===bo?e.decode(vo(xo(n)),r):e.decode(Pe(t,xo),r));let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===bo?vo(t):e;case`Transform`:{let e=e=>e===T?yo:vo(t.transform(e));return(t,n)=>Tu(t,n,e)}case`TransformOptional`:{let e=e=>So(t.transform(xo(e)));return(t,n)=>Tu(t,n,e)}case`TransformEffect`:return(e,n,r)=>Tu(e,n,e=>e===T?yo:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>Tu(e,n,e=>Du(t.transform(xo(e),r)))}}var Du=e=>Yt(e,So),Ou=(e,t,n,r)=>Mr(r,r=>Lr(()=>Pi(r,r=>new Oo(e,r,t,n))));function ku(e,t){let n=Eu(e.link.transformation),r;return(i,a)=>{if(i===T)return yo;if(e.isConstructed(i))return bo;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function Au(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==T&&r!==void 0)return t(r,i);let a=n;if(fe(a)&&a._tag===`Success`){let e=t(a[qr],i);return e===bo?a:e}return Yt(Ou(e,r,i,a),e=>{let n=t(e,i);return n===bo?vo(e):n})}}function ju(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:Au(e,n)}function Mu(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?fu(e):void 0,o=a?ku(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Eu(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);if(u&&!n.disableChecks){if(fe(r)){if(r._tag===`Success`){let i=r===bo?t:r[qr];if(t!==T&&i!==T){let i=du(u,t,void 0,e,n);i&&(r=y(new Mo(e,i,t,n)))}}}else r=w(r,r=>{if(t!==T&&r!==T){let r=du(u,t,void 0,e,n);if(r)return y(new Mo(e,r,t,n))}return v(r)})}if(s&&!n.disableChecks){if(fe(r)){if(r._tag===`Success`){let i=r===bo?t:r[qr];if(i===T)return r;let a=du(s,i,void 0,e,n);a&&(r=y(new Mo(e,a,i,n)))}}else r=w(r,t=>{if(t!==T){let r=du(s,t,void 0,e,n);if(r)return y(new Mo(e,r,t,n))}return v(t)})}return r},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[qr],o=t(a,r)):o=Yt(o,e=>{let n=t(e,r);return n===bo?vo(e):n})}if(o._tag===`Success`){let e=o[qr],t=p(e,r);return t===bo?o:t}return o=Ou(e,n,r,o),Yt(o,e=>{let t=p(e,r);return t===bo?vo(e):t})}:p}var Nu=Symbol(),Pu=new WeakMap,Fu=e=>zu(e).parser,Iu=e=>zu(e).makeEffect,Lu=e=>ju(e,Iu),Ru=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Mu(this.ast,Fu)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Mu(this.ast,Iu,Lu)}};function zu(e){let t=Pu.get(e);if(t!==void 0)return t;let n=new Ru(e);return Pu.set(e,n),n}function Bu(e){let t=e.ast,n;return(e,r)=>(n??=rd(ud,Ul(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Vu(e){let t=Bu(e);return(e,n)=>{let r=cr(t(e,n));return qi(r)?sr(r.value):(es(r.cause,`Option adapter can only return none for schema issues`),Mn())}}function Hu(e){return cd(Ul(e.ast))}function Uu(e){return Gu(e.ast)}function Wu(e){{let t=id(td(e));return e=>{let n=t(e,Xs);return qi(n)?!0:(es(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Gu(e){let t=Ul(e),n=e=>(n=Wu(t),n(e));return e=>n(e)}function Ku(e,t){let n=td(e.ast);return t===void 0?n:(e,r)=>n(e,$u(t,r))}function qu(e,t){return id(Ku(e,t))}function Ju(e,t){return ad(Ku(e,t))}function Yu(e,t){return od(Ku(e,t))}function Xu(e,t){let n=td(Kl(e.ast));return t===void 0?n:(e,r)=>n(e,$u(t,r))}function Zu(e,t){return id(Xu(e,t))}function Qu(e,t){return od(Xu(e,t))}var $u=(e,t)=>t?{...e,...t}:e,ed=e=>e===T?y(new Po):v(e);function td(e){return rd(ld,e)}function nd(e,t){return e===bo?v(t):fe(e)?e[qr]===T?ed(T):e:Yt(e,ed)}function rd(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??Xs);return a===bo?v(r):fe(a)?a[qr]===T?ed(T):a:Yt(a,ed)}}function id(e){return(t,n)=>cr(e(t,n))}function ad(e){let t=id(e);return(e,n)=>{let r=t(e,n);return qi(r)?sr(r.value):(es(r.cause,`Option adapter can only return none for schema issues`),Mn())}}function od(e){let t=id(e);return(e,n)=>{let r=t(e,n);return qi(r)?je(r.value):at(es(r.cause,`Result adapter can only return schema issues`))}}function sd(e,t){let n=cr(e);if(qi(n))return n.value;let r=es(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function cd(e){let t,n;return(r,i)=>{t??=zu(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??Xs,o=t.make;if(o!==void 0&&r!==T){let e;try{e=o(r,a)}catch(e){throw es(Mi(e),`Constructor adapter can only throw schema issues`),e}if(e!==Nu&&e!==T)return e}return sd(nd((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}var ld=e=>zu(e).parser,ud=e=>zu(e).makeEffect,dd=`~effect/Schema/Schema`,fd=Symbol(),pd={[dd]:dd,get make(){let e=Hu(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=Bu(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=Vu(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return o(this,arguments)},annotate(e){return this.rebuild(vl(this.ast,e))},annotateKey(e){return this.rebuild(Ol(this.ast,e))},check(...e){return this.rebuild(bl(this.ast,e))},rebuild(e){return md(e,this[fd])}};function md(e,t){function n(){}let r=Object.setPrototypeOf(n,pd);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r[fd]=t,r.ast=e,r}function hd(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function gd(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function _d(e){return encodeURI(hd(e)).replace(/#/g,`%23`)}function vd(e){if(e.length===0||e===`#`)return``;if(!e.startsWith(`#`))return;let t=e.slice(1);try{if(encodeURI(t).replace(/%25/g,`%`).replace(/#/g,`%23`)!==t)return;let e=decodeURIComponent(t);return e.startsWith(`/`)&&!/~(?:[^01]|$)/.test(e)?e:void 0}catch{return}}function yd(e){let t=vd(e);return t===void 0?void 0:t.length===0?[]:t.slice(1).split(`/`).map(gd)}function bd(e){return e.reduce((e,t)=>`${e}/${_d(t)}`,`#`)}var xd=`http://json-schema.org/draft-07/schema#`;function Sd(e,t){return e===t||e===(t.endsWith(`#`)?t.slice(0,-1):`${t}#`)}function Cd(e){return{dialect:`draft-07`,...Fd(e,qd)}}function wd(e,t){return n(e,!1,!0);function n(e,r,i=!1){if(!Yn(e))return e;let a=r||!i&&Pd(e.$id),o={};for(let t of Object.keys(e)){let r=e[t],i=r;switch(t){case`$defs`:case`properties`:case`patternProperties`:case`dependentSchemas`:i=Dd(r,e=>n(e,a))??r;break;case`allOf`:case`anyOf`:case`oneOf`:case`prefixItems`:i=Array.isArray(r)?r.map(e=>n(e,a)):r;break;case`not`:case`additionalProperties`:case`propertyNames`:case`unevaluatedProperties`:case`items`:case`contains`:case`unevaluatedItems`:case`if`:case`then`:case`else`:case`contentSchema`:i=n(r,a)}g(o,t,i)}return t(o,a),o}}function Td(e,t){return wd(e,e=>{Ed(e,t)})}function Ed(e,t){typeof e.$ref==`string`&&g(e,`$ref`,t(e.$ref,`$ref`)),typeof e.$dynamicRef==`string`&&g(e,`$dynamicRef`,t(e.$dynamicRef,`$dynamicRef`))}function Dd(e,t){if(!Yn(e))return;let n={};for(let r of Object.keys(e))g(n,r,t(e[r],r));return n}function Od(e,t,n){let r=new Map,i=[],a=kd;function o(e,n=[],r=[]){return n.length===0&&t?.trackIds&&(a=jd(Yn(e)?u(e):void 0,kd)??kd),l(e,n,r,{sourceRoot:[],targetRoot:[],uri:a})}function s(){for(let[e,t,n]of i){let i=t,a=Ad(t,n);if(a!==void 0){let e=yd(a.hash);if(a.hash=``,e!==void 0){let n=r.get(Nd(a.href,e));n!==void 0&&(i=Md(t,n))}}g(e,`$ref`,i)}}let c=n(o);return s(),c;function l(n,r,a,o){if(typeof n==`boolean`)return d(r,a,o),t?.booleanAdapter?.(n)??n;if(!Yn(n))return n;let s=o,c=u(n);if(r.length>0&&t?.trackIds&&Pd(c)){let e=jd(c,o.uri);e!==void 0&&(s={parent:o,sourceRoot:r,targetRoot:a,uri:e})}d(r,a,s);let f=s.uri;return e(n,{isDocumentRoot:r.length===0,schema(e,t,n=t){return l(e,[...r,t],[...a,n],s)},schemaAt(e,t,n){return l(e,[...r,...t],[...a,...n],s)},schemaArray(e,t,n=t){return Array.isArray(e)?e.map((e,i)=>l(e,[...r,t,String(i)],[...a,n,String(i)],s)):e},schemaMap(e,t,n=t){return Yn(e)?Dd(e,(e,i)=>l(e,[...r,t,i],[...a,n,i],s)):e},reference(e,t){typeof t==`string`?i.push([e,t,f]):g(e,`$ref`,t)}})}function u(e){return t?.ignoreRefSiblings===!0&&typeof e.$ref==`string`?void 0:e.$id}function d(e,t,n){n.parent!==void 0&&d(e,t,n.parent),r.set(Nd(n.uri,e.slice(n.sourceRoot.length)),t.slice(n.targetRoot.length))}}var kd=`https://effect.invalid/.json-schema/`;function Ad(e,t){return URL.canParse(e,t)?new URL(e,t):void 0}function jd(e,t){if(typeof e!=`string`)return;let n=Ad(e,t);if(n!==void 0)return n.hash=``,n.href}function Md(e,t){let n=e.indexOf(`#`);return n===-1&&t.length===0?e:`${n===-1?e:e.slice(0,n)}${bd(t)}`}function Nd(e,t){return`${e}\u0000${JSON.stringify(t)}`}function Pd(e){return typeof e==`string`&&e.length>0&&e[0]!==`#`}function Fd(e,t,n){return Od(t,{...n,trackIds:!0},t=>({schema:t(e.schema),definitions:Dd(e.definitions,(e,n)=>t(e,[`$defs`,n],[`definitions`,n]))}))}var Id=new Set([`properties`,`patternProperties`]),Ld=new Set([`allOf`,`anyOf`,`oneOf`]),Rd=new Set([`not`,`additionalProperties`,`propertyNames`,`contains`,`if`,`then`,`else`,`contentSchema`]);function zd(e,t,n,r,i,a=Id){let o;if(a.has(t))o=r.schemaMap(n,t);else if(Ld.has(t))o=r.schemaArray(n,t);else if(i.has(t))o=r.schema(n,t);else return!1;return g(e,t,o),!0}var Bd=[`$anchor`,`$defs`,`$dynamicAnchor`,`$dynamicRef`,`$vocabulary`,`contentSchema`,`dependentRequired`,`dependentSchemas`,`maxContains`,`minContains`,`prefixItems`,`unevaluatedItems`,`unevaluatedProperties`];[...Bd],[...Bd];var Vd=/^[A-Za-z_][-A-Za-z0-9._]*$/,Hd=/^[A-Za-z][-A-Za-z0-9._:]*$/;function Ud(e,t,n){throw Error(`Cannot convert JSON Schema keyword "${e}" to ${t}: ${n}`)}function Wd(e,t,n,r){for(let i of t)Object.hasOwn(e,i)&&Ud(i,n,`it is not active in ${r} but would become active in the target`)}var Gd=[`additionalItems`,`definitions`,`dependencies`];function Kd(e,t,n,r,i){n.isDocumentRoot?g(e,`$schema`,Sd(t,`https://json-schema.org/draft/2020-12/schema`)?r:t):Sd(t,`https://json-schema.org/draft/2020-12/schema`)||Ud(`$schema`,i,`an embedded resource cannot declare a different dialect`)}function qd(e,t){Wd(e,Gd,`Draft-07`,`Draft 2020-12`);let n={},r,i,a;for(let o of Object.keys(e)){let s=e[o];if(!zd(n,o,s,t,Rd))switch(o){case`$ref`:r=s;break;case`$schema`:Kd(n,s,t,xd,`Draft-07`);break;case`$id`:case`$anchor`:break;case`$defs`:g(n,`definitions`,t.schemaMap(s,o,`definitions`));break;case`prefixItems`:i=s;break;case`items`:a=s;break;case`dependentRequired`:case`dependentSchemas`:case`minContains`:case`maxContains`:break;case`$dynamicRef`:case`$dynamicAnchor`:case`$vocabulary`:case`unevaluatedProperties`:case`unevaluatedItems`:Ud(o,`Draft-07`,`the target dialect has no equivalent`);case`required`:if(Array.isArray(s)&&s.length===0)break;g(n,o,s);break;default:g(n,o,s)}}if(Jd(n,i,a,t),Object.hasOwn(e,`contains`)){let t=e.minContains,r=e.maxContains;(t!==void 0&&t!==1||r!==void 0)&&Ud(`minContains/maxContains`,`Draft-07`,`contains cardinality cannot be represented`),Object.hasOwn(e,`minContains`)&&g(n,`minContains`,t)}else Object.hasOwn(e,`minContains`)&&g(n,`minContains`,e.minContains),Object.hasOwn(e,`maxContains`)&&g(n,`maxContains`,e.maxContains);return Xd(e,n,t,`draft-07`),Qd(e,n,`$id`,`Draft-07`),Yd(n,r,t),n}function Jd(e,t,n,r){if(t===void 0){n!==void 0&&g(e,`items`,r.schema(n,`items`));return}g(e,`items`,r.schemaArray(t,`prefixItems`,`items`)),n!==void 0&&g(e,`additionalItems`,r.schema(n,`items`,`additionalItems`))}function Yd(e,t,n){if(t!==void 0){if(typeof t==`string`&&Object.keys(e).length>0){let r={};n.reference(r,t),Zd(e,r)}else n.reference(e,t)}}function Xd(e,t,n,r){let i=Yn(e.dependentRequired)?e.dependentRequired:void 0,a=Yn(e.dependentSchemas)?e.dependentSchemas:void 0;if(i===void 0&&a===void 0)return;let o={},s=new Set([...Object.keys(i??{}),...Object.keys(a??{})]);for(let e of s){let t=i?.[e],s=a?.[e],c=r===`draft-04`&&Array.isArray(t)&&t.length===0;s===void 0?c||g(o,e,t):t===void 0||c?g(o,e,n.schemaAt(s,[`dependentSchemas`,e],[`dependencies`,e])):g(o,e,{allOf:[n.schemaAt(s,[`dependentSchemas`,e],[`dependencies`,e,`allOf`,`0`]),{required:t}]})}Object.keys(o).length>0&&g(t,`dependencies`,o)}function Zd(e,t){Array.isArray(e.allOf)?e.allOf.push(t):g(e,`allOf`,[t])}function Qd(e,t,n,r){let i=e.$id,a=e.$anchor;if(a===void 0){i!==void 0&&g(t,n,i);return}(typeof a!=`string`||!Vd.test(a))&&Ud(`$anchor`,r,`the anchor is not valid`),Hd.test(a)||Ud(`$anchor`,r,`the anchor cannot be represented as a plain-name fragment identifier`),i===void 0?g(t,n,`#${a}`):Ud(`$anchor`,r,`it cannot be combined with the schema $id`)}function $d(e){return md(ef(e.ast),{schema:e})}var ef=Tl(e=>{let t=of(e,ef),n=e.context;return t===e||n===void 0?t:wl(t,tf(n))});function tf(e){return e.constructorDefault===void 0?e:new Zs(e.isOptional,e.isMutable,void 0,e.annotations)}function nf(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function rf(e){return t=>{let n=[...t].sort((t,n)=>e(Wl(t))-e(Wl(n)));return n.some((e,n)=>e!==t[n])?n:t}}var af=rf(e=>{switch(e._tag){case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function of(e,t){switch(e._tag){case`Declaration`:{let n=e.annotations?.toCodecJson??e.annotations?.toCodec;if(!Wn(n))return hl(e,[xu]);let r=n(e.typeParameters.map(e=>md(Wl(e))));return r===void 0?e:hl(e,[xl(r,t)])}case`Unknown`:return hl(e,[xu]);case`ObjectKeyword`:return hl(e,[Su]);case`Undefined`:case`Void`:case`Literal`:case`Number`:return e.toCodecJson();case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return nf(e),e.recur(t,Zl);case`Union`:{let n=af(e.types);return n===e.types?e.recur(t):new Jc(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}globalThis.RegExp;var sf=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`);function cf(e,t){return t.length>0&&(e+=`\n at ${ye(t)}`),Error(e)}function lf(e){return`#/$defs/${_d(e)}`}var uf=new Set([..._o,so,...uo]);function df(e,t){if(e===void 0)return;let n={},r=e.title;typeof r==`string`&&(n.title=r);let i=e.description,a=e.expected;typeof i==`string`?n.description=i:t?.generateDescriptions===!0&&typeof a==`string`&&(n.description=a);let o=e.default;yu(o)&&(n.default=o);let s=e.examples;Array.isArray(s)&&yu(s)&&(n.examples=s);let c=e.readOnly;typeof c==`boolean`&&(n.readOnly=c);let l=e.writeOnly;typeof l==`boolean`&&(n.writeOnly=l);let u=e.format;typeof u==`string`&&(n.format=u);let d=e.contentEncoding;typeof d==`string`&&(n.contentEncoding=d);let f=e.contentMediaType;typeof f==`string`&&(n.contentMediaType=f);let p=e.contentSchema;if(yu(p)&&(n.contentSchema=p),t?.includeAnnotationKey!==void 0)for(let[r,i]of Object.entries(e))uf.has(r)||!t.includeAnnotationKey(r)||yu(i)&&g(n,r,i);return Object.keys(n).length===0?void 0:n}function ff(e){let t=e.type===`number`||e.type===`integer`?e.type:void 0,n=e;if(t!==void 0&&(n={...e},delete n.type),Array.isArray(n.allOf)){let e=[],r=!1;for(let i of n.allOf){let n=ff(i);n.type!==void 0&&(r=!0,(t===void 0||n.type===`integer`)&&(t=n.type)),Object.keys(n.schema).length>0&&e.push(n.schema)}if(r){let{allOf:t,...r}=n;n=e.length===0?r:{...r,allOf:e}}}return{type:t,schema:n}}function pf(e){if(!Array.isArray(e.anyOf)||e.anyOf.length!==2||e.anyOf[0]?.type!==`number`)return!1;let t=e.anyOf[1];return t?.type===`string`&&Array.isArray(t.enum)&&t.enum.length===3&&t.enum.includes(`NaN`)&&t.enum.includes(`Infinity`)&&t.enum.includes(`-Infinity`)}var mf=`|type|format|pattern|multipleOf|minimum|maximum|exclusiveMinimum|exclusiveMaximum|minLength|maxLength|minItems|maxItems|uniqueItems|minProperties|maxProperties|propertyNames|`;function hf(e,t){return Object.keys(e).every(e=>t.includes(`|${e}|`))}function gf(e,t){return typeof e.$ref!=`string`&&t.every(t=>!Object.hasOwn(e,t))}var _f=`|title|description|default|examples|readOnly|writeOnly|`,vf=mf+_f;function yf(e,t,n){if(Object.keys(e).length===0)return t;let r=Object.keys(t);if(r.length===0)return e;let i=e.type===`number`||e.type===`integer`?e.type:void 0,a=pf(e);if(i!==void 0||a){let r=ff(t);if(r.type!==void 0){let t=i===`integer`||r.type===`integer`?`integer`:`number`,o={...e,type:t};a&&delete o.anyOf;let s=Object.keys(r.schema);return s.length===0?o:hf(r.schema,_f)&&gf(o,s)?{...o,...r.schema}:yf(o,r.schema,n)}}if(n&&gf(e,r))return{...e,...t};let o=Array.isArray(t.allOf)&&r.length===1?t.allOf:[t];return Array.isArray(e.allOf)?{...e,allOf:[...e.allOf,...o]}:typeof e.$ref==`string`?{allOf:[e,...o]}:{...e,allOf:o}}function bf(e,t=new Set){return typeof e==`boolean`?e:t.has(e)?!0:(t.add(e),e.every(e=>bf(e,t)))}function xf(e){return Array.isArray(e)}function Sf(e,t,n,r){let i=new Map,a=new Map,o=new WeakMap,s=new Map,c=new Map,l=Object.keys(n);for(let e of l)m(e,[`references`,e]);let u=Se(e,(e,n)=>h(e,t[n],[]));for(let[e,t]of s.values())if(!bf(e))for(let e of t)Array.isArray(e.oneOf)&&(e.anyOf=e.oneOf,delete e.oneOf);for(let e of l){let t=n[e],r=te(t);if(r===void 0)continue;let o=i.get(e)[0],s=c.get(r),l=s?.find(e=>At(i.get(e)[0],o));l===void 0?s===void 0?c.set(r,[e]):s.push(e):a.set(e,l)}let d=Se(u,ee),f={};for(let e of l)a.has(e)||g(f,e,ee(i.get(e)[0]));return{dialect:`draft-2020-12`,schemas:d,definitions:f};function p(e){return Array.isArray(e.oneOf)&&s.get(e.oneOf)?.[1].push(e),e}function m(e,t){if(!Object.hasOwn(n,e))throw cf(`Invalid reference ${e}`,[...t,`$ref`]);let r=i.get(e);if(r!==void 0)return r;let a=[{},[]];return i.set(e,a),a[0]=h(n[e],[`references`,e],a[1]),a}function ee(e){return Td(e,e=>{let t=vd(e);if(t===void 0){if(/^#(?:\/|%2f)/i.test(e))throw Error(`Invalid JSON Pointer URI fragment ${JSON.stringify(e)}`);return e}if(!t.startsWith(`/$defs/`))return e;let n=t.indexOf(`/`,7),r=a.get(gd(t.slice(7,n<0?void 0:n)));return r===void 0?e:e.replace(/^#(?:\/|%2f).*?(?:\/|%2f).*?(?=\/|%2f|$)/i,lf(r))})}function te(e){if(e._tag===`Reference`)return;let t=e.checks.length===0?e.annotations:e.checks[e.checks.length-1].annotations;return typeof t?.identifier!=`string`&&typeof t?.[`~identifier`]==`string`?t[so]:void 0}function ne(e,t,n,i){let a=e.annotations,o=a?.toJsonSchema;if(o!==void 0){let s=o({type:t,schemas:e.representation?.schemas?.map((e,t)=>h(e,[...n,`representation`,`schemas`,t],i))??[]}),c=xf(s);c&&i.push(!1);let l=c?s[0]:s,u=df(a,r),d=u===void 0?l:{...l,...u},f=u===void 0?mf:vf;return[d,e._tag===`Filter`&&hf(d,f)&&(u===void 0||hf(u,_f))?!0:void 0]}if(e._tag===`Filter`){i.push(!1);return}let s=e.checks.flatMap((e,r)=>{let a=ne(e,t,[...n,`checks`,r],i);return a===void 0?[]:[a[0]]});if(s.length===0)return;let c=df(a,r),l={allOf:s};return[c===void 0?l:{...l,...c}]}function h(e,t,n){if(e._tag===`Reference`)return n.push(m(e.$ref,t)[1]),{$ref:lf(e.$ref)};let i=o.get(e);if(i!==void 0)return n.push(i[1]),i[0];let a=[];n.push(a);let s=re(e,t,a),c=df(e.annotations,r);c!==void 0&&(s={...s,...c});for(let n=0;n<e.checks.length;n++){let r=typeof s.type==`string`&&Cf(s.type)?s.type:void 0,i=ne(e.checks[n],r,[...t,`checks`,n],a);i!==void 0&&(s=yf(s,...i))}return o.set(e,[s,a]),p(s)}function re(e,t,n){switch(e._tag){case`Any`:case`Unknown`:return{};case`ObjectKeyword`:return{anyOf:[{type:`object`},{type:`array`}]};case`Void`:case`Undefined`:case`Null`:return{type:`null`};case`BigInt`:return{type:`string`,allOf:[{pattern:`^-?\\d+$`}]};case`Symbol`:return{type:`string`,allOf:[{pattern:`^Symbol\\(([\\s\\S]*)\\)$`}]};case`UniqueSymbol`:return globalThis.Symbol.keyFor(e.symbol)===void 0?{not:{}}:{type:`string`,enum:[globalThis.String(e.symbol)]};case`Declaration`:return n.push(!1),{};case`Suspend`:return h(e.thunk,[...t,`thunk`],n);case`Never`:return{not:{}};case`String`:return{type:`string`};case`Number`:return{anyOf:[{type:`number`},{type:`string`,enum:[`NaN`,`Infinity`,`-Infinity`]}]};case`Boolean`:return{type:`boolean`};case`Literal`:{let t=e.literal;return typeof t==`bigint`?{type:`string`,enum:[globalThis.String(t)]}:{type:typeof t,enum:[t]}}case`Enum`:{let n=e.enums.map(([e,n],r)=>{if(typeof n==`number`&&!globalThis.Number.isFinite(n))throw cf(`Invalid numeric enum value ${globalThis.String(n)}`,[...t,`enums`,r,1]);return{type:typeof n,enum:[n],title:e}});return n.length===0?{not:{}}:{anyOf:n}}case`TemplateLiteral`:return{type:`string`,pattern:`^${e.parts.map(Tf).join(``)}$`};case`Arrays`:{if(e.rest.length>1)throw cf(`Invalid schema representation document`,[...t,`rest`]);let i={type:`array`},a=e.elements.length,o=e.elements.map((e,i)=>{e.isOptional&&a--;let o=h(e.type,[...t,`elements`,i,`type`],n),s=df(e.annotations,r);return s===void 0?o:p(yf(o,s))});if(o.length>0?(i.prefixItems=o,i.maxItems=e.elements.length,a>0&&(i.minItems=a)):i.items=!1,e.rest.length===1){delete i.maxItems;let r=h(e.rest[0],[...t,`rest`,0],n);Object.keys(r).length>0?i.items=r:delete i.items}return i}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return{not:{type:`null`}};let i={type:`object`},a={},o=[];for(let i=0;i<e.propertySignatures.length;i++){let s=e.propertySignatures[i];if(typeof s.name!=`string`)throw cf(`Invalid schema representation document`,[...t,`propertySignatures`,i,`name`]);let c=s.name,l=h(s.type,[...t,`propertySignatures`,i,`type`],n),u=df(s.annotations,r);g(a,c,u===void 0?l:p(yf(l,u))),s.isOptional||o.push(c)}e.propertySignatures.length>0&&(i.properties=a),o.length>0&&(i.required=o);let s={},c=[],l=[],u=!1;for(let r=0;r<e.indexSignatures.length;r++){let i=e.indexSignatures[r],a=h(i.type,[...t,`indexSignatures`,r,`type`],n);At(a,{not:{}})&&(a=!1),l.push(a);let o=ie(i.parameter,[...t,`indexSignatures`,r,`parameter`],new Set);if(o===void 0){u=!0,n.push(!1);continue}if(o.length===0)c.push(a);else for(let e of o){let t=s[e];g(s,e,t===void 0?a:t===!1||a===!1?!1:p(yf(t,a)))}}let d=Object.keys(s).length>0;if(d&&(i.patternProperties=s),u&&r?.onExcessProperty===`error`){let r=[];e.propertySignatures.length>0&&r.push({enum:Object.keys(a)});for(let i=0;i<e.indexSignatures.length;i++)r.push(h(e.indexSignatures[i].parameter,[...t,`indexSignatures`,i,`parameter`],n));i.propertyNames=r.length===1?r[0]:{anyOf:r},i.additionalProperties=l.length===1?l[0]:{anyOf:l},c.length>0&&(i.allOf=c.map(e=>({type:`object`,additionalProperties:e})))}else c.length===0?i.additionalProperties=u||r?.onExcessProperty!==`error`:c.length===1&&e.propertySignatures.length===0&&!d?i.additionalProperties=c[0]:c.length>0&&(i.allOf=c.map(e=>({type:`object`,additionalProperties:e})));return typeof i.additionalProperties==`object`&&i.additionalProperties!==null&&Object.keys(i.additionalProperties).length===0&&delete i.additionalProperties,i}case`Union`:{let r=[],i=e.types.map((e,n)=>h(e,[...t,`types`,n],r));if(n.push(r),i.length===0)return{not:{}};let a=e.options?.mode??`anyOf`;if(a===`anyOf`&&i.length>1){let e=wf(i);if(e!==void 0)return e}return a===`oneOf`&&s.set(i,[r,[]]),{[a]:i}}}}function ie(e,t,r){switch(e._tag){case`Reference`:{if(!Object.hasOwn(n,e.$ref))throw cf(`Invalid reference ${e.$ref}`,[...t,`$ref`]);if(m(e.$ref,t),r.has(e.$ref))return;let i=new Set(r).add(e.$ref);return ie(n[e.$ref],[`references`,e.$ref],i)}case`String`:{if(e.checks.length===0)return[];if(e.checks.length!==1||e.checks[0]._tag!==`Filter`||e.checks[0].annotations?.toJsonSchema===void 0)return;let n=[],r=h(e,t,n);return bf(n)&&r.type===`string`&&typeof r.pattern==`string`&&hf(r,`|type|pattern|title|description|default|examples|readOnly|writeOnly|`)?[r.pattern]:void 0}case`TemplateLiteral`:return e.checks.length===0?[`^${e.parts.map(Tf).join(``)}$`]:void 0;case`Union`:{if(e.types.length===0||e.checks.length>0||e.options?.mode===`oneOf`)return;let n=[];for(let i=0;i<e.types.length;i++){let a=ie(e.types[i],[...t,`types`,i],r);if(a===void 0)return;if(a.length===0)return[];n.push(...a)}return n}default:throw cf(`Invalid schema representation document`,t)}}}function Cf(e){return e===`string`||e===`number`||e===`boolean`||e===`array`||e===`object`||e===`null`||e===`integer`}function wf(e){let t,n=[];for(let r of e){if(Object.keys(r).length!==2||r.type===void 0||!Array.isArray(r.enum)||r.enum.length===0)return;if(t===void 0)t=r.type;else if(r.type!==t)return;for(let e of r.enum){if(n.includes(e))return;n.push(e)}}return{type:t,enum:n}}function Tf(e){switch(e._tag){case`Literal`:return sf(globalThis.String(e.literal));case`String`:return Ql;case`Number`:return Sc;case`TemplateLiteral`:return e.parts.map(Tf).join(``);case`Union`:return`(?:${e.types.map(Tf).join(`|`)})`;default:throw cf(`Invalid schema representation document`,[])}}function Ef(e,t){let n=Sf([e.representation],[[`representation`]],e.references,t);return{dialect:n.dialect,schema:n.schemas[0],definitions:n.definitions}}var Df=({identifier:e})=>e;function Of(e){return e===void 0?void 0:{annotations:e}}function kf(e,t){let{references:n,representations:r}=Af([e],t);return{representation:r[0],references:n}}function Af(e,t){let n={},r=new Map,i=new Set,a=new Map,o=new Set;for(let t of e)f(t);let s=t?.referencePolicy??Df;for(let e of a.values())for(let t of e.values()){let e=s({ast:t.ast,occurrences:t.occurrences,identifier:t.identifier});e===void 0?t.isRecursive&&(t.reference=c(`${t.ast._tag}_`,t,``)):t.reference=c(e,t,e===t.identifier||!e.endsWith(`_`)?`_`:``)}return{representations:Se(e,e=>m(e)),references:n};function c(e,t,n=`_`){let i=e,a=0;for(;r.has(i);){if(r.get(i)===t)return i;i=`${e}${n}${++a}`}return r.set(i,t),i}function l(e,t,n){let r=t.fallback;return r===void 0?n===t.identifier?e:vl(e,{identifier:n}):po(e)===r?e:vl(e,{[so]:r})}function u(e,t){if(!Object.hasOwn(n,e)&&!i.has(e)){i.add(e);let r=ee(t);i.delete(e),g(n,e,r)}return{_tag:`Reference`,$ref:e}}function d(e){let t=_l(e),n=ml(t),r=fo(t),i=r===void 0?(t===e?void 0:fo(e))??po(t):void 0;i!==void 0&&(r=`${i}Encoded`);let o=a.get(n);o===void 0&&(o=new Map,a.set(n,o));let s=o.get(r);return s===void 0&&(s={ast:n,identifier:r,fallback:i,occurrences:0,isRecursive:!1,reference:void 0},o.set(r,s)),s}function f(e){let t=d(e),n=t.ast;if(t.occurrences++,o.has(t)){t.isRecursive=!0;return}if(!(t.occurrences>1)){switch(o.add(t),p(n.checks),n._tag){case`Declaration`:case`Arrays`:case`Objects`:case`Union`:n.recur(e=>(f(e),e));break;case`TemplateLiteral`:n.parts.forEach(f);break;case`Suspend`:f(n.thunk())}o.delete(t)}}function p(e){e?.forEach(e=>{e.annotations?.representation?.schemas?.forEach(e=>f(Ul(e))),e._tag===`FilterGroup`&&p(e.checks)})}function m(e){let t=d(e),n=t.ast,r=t.reference;return r===void 0?ee(n):u(r,t.identifier===void 0?n:l(n,t,r))}function ee(e){let t=te(e.checks);switch(e._tag){case`Declaration`:return{_tag:`Declaration`,typeParameters:e.typeParameters.map(e=>m(e)),checks:t,...h(e.annotations)};case`Null`:case`Undefined`:case`Void`:case`Never`:case`Unknown`:case`Any`:case`String`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`ObjectKeyword`:return{_tag:e._tag,checks:t,...Of(e.annotations)};case`Literal`:return{_tag:`Literal`,literal:e.literal,checks:t,...Of(e.annotations)};case`UniqueSymbol`:return{_tag:`UniqueSymbol`,symbol:e.symbol,checks:t,...Of(e.annotations)};case`Enum`:return{_tag:`Enum`,enums:e.enums,checks:t,...Of(e.annotations)};case`TemplateLiteral`:return{_tag:`TemplateLiteral`,parts:e.parts.map(e=>m(e)),checks:t,...Of(e.annotations)};case`Arrays`:return{_tag:`Arrays`,elements:e.elements.map(e=>{let t=_l(e),n=t.context?.annotations;return{isOptional:Rl(t),type:m(e),...Of(n)}}),rest:e.rest.map(e=>m(e)),checks:t,...Of(e.annotations)};case`Objects`:return{_tag:`Objects`,propertySignatures:e.propertySignatures.map(e=>{let t=_l(e.type),n=t.context?.annotations;return{name:e.name,type:m(e.type),isOptional:Rl(t),isMutable:zl(t),...Of(n)}}),indexSignatures:e.indexSignatures.map(e=>({parameter:m(e.parameter),type:m(e.type)})),checks:t,...Of(e.annotations)};case`Union`:return{_tag:`Union`,types:e.types.map(e=>m(e)),...e.options===void 0?{}:{options:e.options},checks:t,...Of(e.annotations)};case`Suspend`:return{_tag:`Suspend`,checks:[],thunk:m(e.thunk()),...Of(e.annotations)}}}function te(e){return e?.map(ne)??[]}function ne(e){switch(e._tag){case`Filter`:return{_tag:`Filter`,aborted:e.aborted,...re(e.annotations)};case`FilterGroup`:return{_tag:`FilterGroup`,checks:Se(e.checks,ne),...re(e.annotations)}}}function h(e){if(e===void 0)return;let{representation:t,...n}=e;return{...t===void 0?void 0:{representation:t},...Object.keys(n).length===0?void 0:{annotations:n}}}function re(e){if(e===void 0)return;let{representation:t,...n}=e,r=t===void 0?void 0:t.schemas===void 0?t:{...t,schemas:t.schemas.map(e=>m(Ul(e)))};return{...r===void 0?void 0:{representation:r},...Object.keys(n).length===0?void 0:{annotations:n}}}}function jf(e){return qi(e)?e.value:{issues:[{message:zi(e.cause)}]}}function Mf(e,t){let n=Ku(e),r={errors:`all`,...t?.parseOptions},i=Uo(t),a=e=>{let t=new Zt(`sync`),a=jr(u(n(e,r),{onFailure:i,onSuccess:e=>({value:e})}),{scheduler:t});a.currentDispatcher?.flush();let o=a.pollUnsafe();return o?jf(o):new Promise(e=>{a.addObserver(t=>{e(jf(t))})})};if(Object.hasOwn(e,`~standard`)){let t=e;return`validate`in t[`~standard`]||Object.assign(t[`~standard`],{validate:a}),t}return Object.assign(e,{"~standard":{version:1,vendor:`effect`,validate:a}})}function Nf(e){return Ef(kf(ef(e)))}function Pf(e,t){let n=Nf(e);if(t===`draft-2020-12`){let e=n.schema;return Object.keys(n.definitions).length>0&&(e.$defs=n.definitions),e}if(t===`draft-07`){let e=Cd(n),t=e.schema;return Object.keys(e.definitions).length>0&&(t.definitions=e.definitions),t}throw new globalThis.Error(`Unsupported target: ${t}`)}function Ff(e){let t={input(t){return Pf(e.ast,t.target)},output(t){return Pf(Ul(e.ast),t.target)}};if(Object.hasOwn(e,`~standard`)){let n=e;return`jsonSchema`in n[`~standard`]||Object.assign(n[`~standard`],{jsonSchema:t}),n}return Object.assign(e,{"~standard":{version:1,vendor:`effect`,jsonSchema:t}})}var If=se(e=>Lf(e));function Lf(e){let t=io(e)?.toEquivalence;if(t)return t(Is(e)?e.typeParameters.map(Lf):[]);switch(e._tag){case`Never`:return Nt();case`Declaration`:return Rf(e);case`Null`:case`Undefined`:case`Void`:case`Unknown`:case`Any`:case`String`:case`Number`:case`Boolean`:case`BigInt`:case`Symbol`:case`Literal`:case`UniqueSymbol`:case`ObjectKeyword`:case`Enum`:case`TemplateLiteral`:return At;case`Arrays`:{let t=e.elements.map(Lf),n=e.rest.map(Lf),[r,...i]=n,a=i.length;return De((o,s)=>{if(!Array.isArray(o)||!Array.isArray(s))return!1;let c=o.length;if(c!==s.length)return!1;let l=0;for(;l<Math.min(c,e.elements.length);l++)if(!t[l](o[l],s[l]))return!1;if(n.length>0){for(;l<c-a;l++)if(!r(o[l],s[l]))return!1;for(let e=0;e<a;e++)if(!i[e](o[l+e],s[l+e]))return!1}return!0})}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return At;let t=e.propertySignatures.map(e=>Lf(e.type)),n=e.indexSignatures.map(e=>Lf(e.type));return De((r,i)=>{if(!Yn(r)||!Yn(i))return!1;for(let n=0;n<t.length;n++){let a=e.propertySignatures[n],o=a.name,s=Object.hasOwn(r,o),c=Object.hasOwn(i,o);if(Rl(a.type)&&s!==c||s&&c&&!t[n](r[o],i[o]))return!1}for(let t=0;t<n.length;t++){let a=e.indexSignatures[t],o=Cc(r,a.parameter),s=Cc(i,a.parameter);if(o.length!==s.length)return!1;for(let e=0;e<o.length;e++){let a=o[e];if(!Object.hasOwn(i,a)||!n[t](r[a],i[a]))return!1}}return!0})}case`Union`:{let t=Ul(e).types,n=qc(t),r=t.map((t,n)=>[Gu(t),Lf(e.types[n])]);return De((e,t)=>{let i=n(e,!1);for(let n=0;n<i.length;n++){let[a,o]=r[i[n]];if(a(e)&&a(t))return o(e,t)}return!1})}case`Suspend`:{let t;return De((n,r)=>(t??=If(e.thunk()))(n,r))}}}function Rf(e){let t=e.annotations?.representation;if(t===void 0)return At;switch(t.id){case`effect/schema/Option`:{let[t]=zf(e);return(e,n)=>e._tag===n._tag&&(e._tag===`None`||t(e.value,n.value))}case`effect/schema/Result`:{let[t,n]=zf(e);return(e,r)=>e._tag===r._tag&&(e._tag===`Success`?t(e.success,r.success):n(e.failure,r.failure))}case`effect/schema/CauseReason`:{let[t,n]=zf(e);return Bf(t,n)}case`effect/schema/Cause`:{let[t,n]=zf(e);return Vf(t,n)}case`effect/schema/Exit`:{let[t,n,r]=zf(e),i=Vf(n,r);return(e,n)=>e._tag===n._tag&&(e._tag===`Success`?t(e.value,n.value):i(e.cause,n.cause))}case`effect/schema/ReadonlyMap`:{let[t,n]=zf(e);return It(t,n)}case`effect/schema/ReadonlySet`:return nt(zf(e)[0]);case`effect/schema/RegExp`:return(e,t)=>e.source===t.source&&e.flags===t.flags;case`effect/schema/URL`:return(e,t)=>e.toString()===t.toString();default:return At}}function zf(e){return e.typeParameters.map(Lf)}function Bf(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case`Fail`:return e(n.error,r.error);case`Die`:return t(n.defect,r.defect);case`Interrupt`:return n.fiberId===r.fiberId}}}function Vf(e,t){let n=Me(Bf(e,t));return(e,t)=>n(e.reasons,t.reasons)}var Hf=m(2,(e,t)=>({...e,...t})),Uf=e=>e,Wf=`~effect/Schema/SchemaError`;function Gf(e){return ar(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}var Kf=dd;function qf(){return(e,t,n)=>D(new ec(e.map(Ic),e=>t(e.map(e=>D(e))),n))}function Jf(e,t){return qf()([],()=>(t,n,r)=>e(t)?v(t):y(new No(n,t,r)),t)}var Yf=class extends Ei(`SchemaError`){[Wf]=Wf;constructor(e){let t=Ce();Ie(0);try{super({issue:e})}finally{Ie(t)}}get message(){return Xo(this.issue)}toString(){return`SchemaError(${this.message})`}};function Xf(e){return Gf(e)}function Zf(e){return fe(e)?Qf(e):Mr(e,e=>Lr(()=>Pi(e,e=>new Yf(e))))}function Qf(e){return qi(e)?e:Ui(Pi(e.cause,e=>new Yf(e)))}function $f(e,t){let n;for(let r of e.reasons){if(!ki(r)||!Xf(r.error))throw new globalThis.Error(t,{cause:e});n??=r.error}if(n===void 0)throw new globalThis.Error(t,{cause:e});return n}function ep(e){let t=cr(e);if(qi(t))return t.value;throw $f(t.cause,`Sync adapter can only throw schema errors`)}function tp(e,t){return Mf(e,t)}function np(e){return Ff(e)}var rp=Uu;function ip(e,t){let n=Ku(e,t);return(e,t)=>Zf(n(e,t))}function ap(e,t){let n=qu(e,t);return(e,t)=>Qf(n(e,t))}var op=Ju;function E(e,t){let n=Yu(e,t);return(e,t)=>Et(n(e,t),e=>new Yf(e))}var sp=E;function cp(e,t){let n=ip(e,t);return(e,t)=>ep(n(e,t))}var lp=cp;function up(e,t){let n=Xu(e,t);return(e,t)=>Zf(n(e,t))}function dp(e,t){let n=Zu(e,t);return(e,t)=>Qf(n(e,t))}function fp(e,t){let n=Qu(e,t);return(e,t)=>Et(n(e,t),e=>new Yf(e))}var pp=fp;function mp(e,t){let n=up(e,t);return(e,t)=>ep(n(e,t))}var hp=mp,D=md;function gp(e){return ar(e,Kf)&&e[Kf]===Kf}var O=Uf(e=>D(kl(e.ast),{schema:e})),k=Uf(e=>{let t=Fp(e);return D(jl(e.ast),{schema:t})}),_p=Uf(e=>D(Ml(e.ast),{schema:e})),vp=Uf(e=>D(Ul(e.ast),{schema:e})),yp=Uf(e=>D(Wl(e.ast),{schema:e}));function A(e){let t=D(new sc(e),{literal:e,transform(n){return t.pipe(zp(A(n),{decode:ss(()=>n),encode:ss(()=>e)}))}});return t}var bp=D(ac),xp=D(oc),Sp=D(tc),Cp=D(ic),j=D(lc),M=D(fc),wp=D(pc),Tp=D(mc),Ep=D(hc);function Dp(e,t){return D(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Dp(Fc(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function N(e){return Dp(Fc(e,void 0),e)}function Op(e,t){return D(Ll(e.ast,t.ast),{key:e,value:t})}function kp(e,t){return D(e,{elements:t,mapElements(e,t){let n=e(this.elements);return kp(Lc(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Ap(e){return kp(Lc(e),e)}var jp=Uf(e=>D(new gc(!1,[],[e.ast]),{value:e})),Mp=Uf(e=>D(new gc(!1,[e.ast],[e.ast]),{value:e})),Np=Uf(e=>D(zc(e.ast),{schema:e}));function Pp(e,t){return D(e,{members:t,mapMembers(e,t){let n=e(this.members);return Pp(Rc(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function P(e,t){return Pp(Rc(e,t,void 0),e)}function F(e){let t=e.map(A);return D(Rc(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return P(e(this.members))},pick(e){return F(e)},transform(e){return P(t.map((t,n)=>t.transform(e[n])))}})}var I=Uf(e=>P([e,Sp])),Fp=Uf(e=>P([e,Cp]));function Ip(e){return D(new rl(()=>e().ast))}function L(...e){return t=>t.check(...e)}function Lp(e,t){return n=>D(bl(n.ast,[sl(e,t)]),{schema:n})}function Rp(e){return t=>D(t.ast,{schema:t,identifier:e})}function zp(e,t){return n=>D(Fl(n.ast,e.ast,t?Es(t):ks()),{from:n,to:e})}function Bp(e,t){return n=>t?zp(n,t)(e):zp(n)(e)}function Vp(e){return t=>D(Pl(t.ast,e),{schema:t})}function Hp(e){return Mr(e,e=>Lr(()=>Pi(e,e=>e.issue)))}function Up(e,t){let n=t?.encodingStrategy===`omit`?ds():as();return t=>k(yp(t)).pipe(zp(t,{decode:fs(Hp(e)),encode:n}))}function Wp(e,t){return n=>vp(n).pipe(Up(e,t),Bp(k(n)))}function Gp(e){return A(e).pipe(Vp(v(e)))}function Kp(e,t){return Jf(t=>t instanceof e,t)}function qp(){return(e,t)=>new Ys(e.ast,Es(t))}var R=ol,Jp=`^\\S[\\s\\S]*\\S$|^\\S$|^$`;function Yp(e){let t=new globalThis.RegExp(Jp);return R(e=>e.trim()===e,{expected:`a string with no leading or trailing whitespace`,representation:{id:`effect/schema/isTrimmed`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isTrimmed()`}),arbitraryConstraint:{patterns:[{source:Jp,flags:``}]},...e})}function Xp(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new RegExp(${d(n)})`:`new RegExp(${d(n)}, ${d(r)})`;return dl(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}var Zp=e=>e?new globalThis.RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;function Qp(e,t){let n=Zp(e);return Xp(n,{expected:e?`a UUID v${e}`:`a UUID`,representation:{id:`effect/schema/isUUID`,payload:{version:e??null}},toJsonSchema:()=>({pattern:n.source,format:`uuid`}),toCode:()=>({runtime:e===void 0?`Schema.isUUID()`:`Schema.isUUID(${e})`}),...t})}function $p(e){let t=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;return Xp(t,{expected:`a base64 encoded string`,representation:{id:`effect/schema/isBase64`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isBase64()`}),...e})}function em(e,t,n){if(e.length===0)return t.length===0?{}:[{},!0];let r={pattern:new globalThis.RegExp(n).source};return e===t?r:[r,!0]}function tm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`^${sf(e)}`),i=e.replace(/[\uD800-\uDBFF]$/,``);return R(t=>t.startsWith(e),{expected:`a string starting with ${n}`,representation:{id:`effect/schema/isStartingWith`,payload:{startsWith:e}},toJsonSchema:()=>em(i,e,`^${sf(i)}`),toCode:()=>({runtime:`Schema.isStartingWith(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}function nm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`${sf(e)}$`),i=e.replace(/^[\uDC00-\uDFFF]/,``);return R(t=>t.endsWith(e),{expected:`a string ending with ${n}`,representation:{id:`effect/schema/isEndingWith`,payload:{endsWith:e}},toJsonSchema:()=>em(i,e,`${sf(i)}$`),toCode:()=>({runtime:`Schema.isEndingWith(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}function rm(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(sf(e)),i=e.replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,``);return R(t=>t.includes(e),{expected:`a string including ${n}`,representation:{id:`effect/schema/isIncluding`,payload:{includes:e}},toJsonSchema:()=>em(i,e,sf(i)),toCode:()=>({runtime:`Schema.isIncluding(${d(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}var im=D(ll),am=cl;function om(e){let t=yn(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value greater than ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r,exclusiveMinimum:!0},...e.annotate?.(r),...i})}function sm(e){let t=pr(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value greater than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r},...e.annotate?.(r),...i})}function cm(e){let t=Zn(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value less than ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r,exclusiveMaximum:!0},...e.annotate?.(r),...i})}function lm(e){let t=On(e.order),n=e.formatter??d;return(r,i)=>R(e=>t(e,r),{expected:`a value less than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r},...e.annotate?.(r),...i})}function um(e){let t=pr(e.order),n=yn(e.order),r=On(e.order),i=Zn(e.order),a=e.formatter??d;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return R(e=>c(e,o.minimum)&&l(e,o.maximum),{expected:`a value between ${a(o.minimum)}${o.exclusiveMinimum?` (excluded)`:``} and ${a(o.maximum)}${o.exclusiveMaximum?` (excluded)`:``}`,arbitraryConstraint:{order:e.order,minimum:o.minimum,maximum:o.maximum,...o.exclusiveMinimum&&{exclusiveMinimum:!0},...o.exclusiveMaximum&&{exclusiveMaximum:!0}},...e.annotate?.(o),...s})}}function dm(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${d(e)}`);return e}var fm=om({order:Fr,annotate:e=>({representation:{id:`effect/schema/isGreaterThan`,payload:{exclusiveMinimum:dm(e)}},toJsonSchema:()=>({exclusiveMinimum:e}),toCode:()=>({runtime:`Schema.isGreaterThan(${d(e)})`})})}),z=sm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualTo`,payload:{minimum:dm(e)}},toJsonSchema:()=>({minimum:e}),toCode:()=>({runtime:`Schema.isGreaterThanOrEqualTo(${d(e)})`})})}),pm=cm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isLessThan`,payload:{exclusiveMaximum:dm(e)}},toJsonSchema:()=>({exclusiveMaximum:e}),toCode:()=>({runtime:`Schema.isLessThan(${d(e)})`})})}),mm=lm({order:Fr,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualTo`,payload:{maximum:dm(e)}},toJsonSchema:()=>({maximum:e}),toCode:()=>({runtime:`Schema.isLessThanOrEqualTo(${d(e)})`})})}),hm=um({order:Fr,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:dm(e.minimum),maximum:dm(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${d(e.minimum)}, maximum: ${d(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}});function gm(e,t){if(!globalThis.Number.isFinite(e)||e===0)throw new globalThis.RangeError(`Expected a finite non-zero number, got ${globalThis.String(e)}`);return e=globalThis.Math.abs(e),R(t=>xa(t,e)===0,{expected:`a value that is a multiple of ${e}`,representation:{id:`effect/schema/isMultipleOf`,payload:{divisor:e}},toJsonSchema:()=>({multipleOf:e}),toCode:()=>({runtime:`Schema.isMultipleOf(${d(e)})`}),...t})}function _m(e){return R(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>[{type:`integer`},!0],toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}var B=M.check(_m()),vm=B.check(z(0));function ym(e){if(globalThis.Number.isNaN(e.getTime()))throw new globalThis.RangeError(`Expected a valid Date, got ${d(e)}`);return e.toISOString()}function bm(e){return`new Date(${d(e.getTime())})`}var xm=om({order:Kn,annotate:e=>({representation:{id:`effect/schema/isGreaterThanDate`,payload:{exclusiveMinimum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanDate(${bm(e)})`})})}),Sm=sm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualToDate`,payload:{minimum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanOrEqualToDate(${bm(e)})`})})}),Cm=cm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isLessThanDate`,payload:{exclusiveMaximum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanDate(${bm(e)})`})})}),wm=lm({order:Kn,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualToDate`,payload:{maximum:ym(e)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanOrEqualToDate(${bm(e)})`})})}),Tm=um({order:Kn,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetweenDate`,payload:{minimum:ym(e.minimum),maximum:ym(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenDate({ minimum: ${bm(e.minimum)}, maximum: ${bm(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}}),Em=om({order:an,annotate:e=>({representation:{id:`effect/schema/isGreaterThanBigInt`,payload:{exclusiveMinimum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanBigInt(${d(e)})`})})}),Dm=sm({order:an,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualToBigInt`,payload:{minimum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isGreaterThanOrEqualToBigInt(${d(e)})`})})}),Om=cm({order:an,annotate:e=>({representation:{id:`effect/schema/isLessThanBigInt`,payload:{exclusiveMaximum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanBigInt(${d(e)})`})})}),km=lm({order:an,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualToBigInt`,payload:{maximum:e.toString(10)}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isLessThanOrEqualToBigInt(${d(e)})`})})}),Am=um({order:an,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetweenBigInt`,payload:{minimum:e.minimum.toString(10),maximum:e.maximum.toString(10),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenBigInt({ minimum: ${d(e.minimum)}, maximum: ${d(e.maximum)}, exclusiveMinimum: ${d(t)}, exclusiveMaximum: ${d(n)} })`})}}});function jm(e,t){return e=zm(e),Mm(e,Math.ceil(e/2),t)}function Mm(e,t,n){return R(t=>t.length>=e,{expected:`a value with a length of at least ${e}`,representation:{id:`effect/schema/isMinLength`,payload:{minLength:e}},toJsonSchema:({type:n})=>n===`string`?e<=1?{minLength:t}:[{minLength:t},!0]:n===`array`?{minItems:e}:n===void 0?[{minLength:t,minItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMinLength(${e})`}),[oo]:!0,arbitraryConstraint:{minLength:e},...n})}function Nm(e){return Mm(1,1,e)}function V(e,t){return e=zm(e),R(t=>t.length<=e,{expected:`a value with a length of at most ${e}`,representation:{id:`effect/schema/isMaxLength`,payload:{maxLength:e}},toJsonSchema:({type:t})=>t===`string`?e===0?{maxLength:e}:[{maxLength:e},!0]:t===`array`?{maxItems:e}:t===void 0?[{maxLength:e,maxItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMaxLength(${e})`}),[oo]:!0,arbitraryConstraint:{maxLength:e},...t})}function Pm(e,t,n){return e=zm(e),t=zm(t),R(n=>n.length>=e&&n.length<=t,{expected:e===t?`a value with a length of ${e}`:`a value with a length between ${e} and ${t}`,representation:{id:`effect/schema/isBetweenLength`,payload:{minimum:e,maximum:t}},toJsonSchema:({type:n})=>n===`string`?t===0||Math.ceil(e/2)>t?{minLength:Math.ceil(e/2),maxLength:t}:[{minLength:Math.ceil(e/2),maxLength:t},!0]:n===`array`?{minItems:e,maxItems:t}:n===void 0?[{minLength:Math.ceil(e/2),maxLength:t,minItems:e,maxItems:t},!0]:[{},!0],toCode:()=>({runtime:`Schema.isBetweenLength(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minLength:e,maxLength:t},...n})}function Fm(e,t){return e=zm(e),R(t=>Rm(t,e)>=e,{expected:`a string with at least ${e} code points`,representation:{id:`effect/schema/isMinCodePoints`,payload:{minCodePoints:e}},toJsonSchema:()=>({minLength:e}),toCode:()=>({runtime:`Schema.isMinCodePoints(${e})`}),arbitraryConstraint:{minCodePoints:e},...t})}function Im(e,t){return e=zm(e),R(t=>Rm(t,e+1)<=e,{expected:`a string with at most ${e} code points`,representation:{id:`effect/schema/isMaxCodePoints`,payload:{maxCodePoints:e}},toJsonSchema:()=>({maxLength:e}),toCode:()=>({runtime:`Schema.isMaxCodePoints(${e})`}),arbitraryConstraint:{maxCodePoints:e},...t})}function Lm(e,t,n){return e=zm(e),t=zm(t),R(n=>{let r=Rm(n,t+1);return r>=e&&r<=t},{expected:e===t?`a string with ${e} code points`:`a string with between ${e} and ${t} code points`,representation:{id:`effect/schema/isBetweenCodePoints`,payload:{minimum:e,maximum:t}},toJsonSchema:()=>({allOf:[{minLength:e},{maxLength:t}]}),toCode:()=>({runtime:`Schema.isBetweenCodePoints(${e}, ${t})`}),arbitraryConstraint:{minCodePoints:e,maxCodePoints:t},...n})}function Rm(e,t){if(t===0)return 0;let n=0;for(let r of e)if(++n>=t)break;return n}function zm(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${e}`);return Math.max(0,Math.floor(e))}function Bm(e,t){return e=zm(e),R(t=>t.size>=e,{expected:`a value with a size of at least ${e}`,representation:{id:`effect/schema/isMinSize`,payload:{minSize:e}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isMinSize(${e})`}),[oo]:!0,arbitraryConstraint:{minSize:e},...t})}function Vm(e,t){return e=zm(e),R(t=>t.size<=e,{expected:`a value with a size of at most ${e}`,representation:{id:`effect/schema/isMaxSize`,payload:{maxSize:e}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isMaxSize(${e})`}),[oo]:!0,arbitraryConstraint:{maxSize:e},...t})}function Hm(e,t,n){return e=zm(e),t=zm(t),R(n=>n.size>=e&&n.size<=t,{expected:e===t?`a value with a size of ${e}`:`a value with a size between ${e} and ${t}`,representation:{id:`effect/schema/isBetweenSize`,payload:{minimum:e,maximum:t}},toJsonSchema:()=>[{},!0],toCode:()=>({runtime:`Schema.isBetweenSize(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minSize:e,maxSize:t},...n})}function Um(e,t){return e=zm(e),R(t=>Reflect.ownKeys(t).length>=e,{expected:`a value with at least ${e===1?`1 entry`:`${e} entries`}`,representation:{id:`effect/schema/isMinProperties`,payload:{minProperties:e}},toJsonSchema:({type:t})=>t===`object`?{minProperties:e}:[{minProperties:e},!0],toCode:()=>({runtime:`Schema.isMinProperties(${e})`}),[oo]:!0,arbitraryConstraint:{minProperties:e},...t})}function Wm(e,t){return e=zm(e),R(t=>Reflect.ownKeys(t).length<=e,{expected:`a value with at most ${e===1?`1 entry`:`${e} entries`}`,representation:{id:`effect/schema/isMaxProperties`,payload:{maxProperties:e}},toJsonSchema:({type:t})=>t===`object`?{maxProperties:e}:[{maxProperties:e},!0],toCode:()=>({runtime:`Schema.isMaxProperties(${e})`}),[oo]:!0,arbitraryConstraint:{maxProperties:e},...t})}function Gm(e,t,n){return e=zm(e),t=zm(t),R(n=>Reflect.ownKeys(n).length>=e&&Reflect.ownKeys(n).length<=t,{expected:e===t?`a value with exactly ${e===1?`1 entry`:`${e} entries`}`:`a value with between ${e} and ${t} entries`,representation:{id:`effect/schema/isBetweenProperties`,payload:{minimum:e,maximum:t}},toJsonSchema:({type:n})=>n===`object`?{minProperties:e,maxProperties:t}:[{minProperties:e,maxProperties:t},!0],toCode:()=>({runtime:`Schema.isBetweenProperties(${e}, ${t})`}),[oo]:!0,arbitraryConstraint:{minProperties:e,maxProperties:t},...n})}var Km=j.check(Nm());globalThis.RegExp,globalThis.URL;var qm=j.annotate({expected:`a string that will be decoded as a Date`}),Jm=Jf(e=>e instanceof globalThis.Date&&!globalThis.Number.isNaN(e.getTime()),{representation:{id:`effect/schema/Date`,payload:null},toCode:()=>({runtime:`Schema.Date`,Type:`globalThis.Date`}),expected:`a valid Date`,toCodecJson:()=>qp()(qm,Ms)}),Ym=j.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function Xm(e,t){return Ym.pipe(zp(e,Ps(t)))}globalThis.File,globalThis.FormData,globalThis.URLSearchParams;var Zm=j.annotate({expected:`a string that will be decoded as a number`}).pipe(zp(M,As)),Qm=j.check(Yp()),$m=j.annotate({expected:`a string that will be decoded as a trimmed string`}).pipe(zp(Qm,Ds())),eh=j.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),th=Kp(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>qp()(eh,Ns)});function nh(e){return If(e.ast)}function rh(e,t){return kf(e.ast,t)}function ih(e,t){return Ef(kf(ef(e.ast),t),t)}var ah=$d,oh=D(vl(bu,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),sh=Op(j,oh),ch=b(()=>ur({id:S().min(1).max(256),name:S().min(1).max(128),kind:Kt(`agent`).optional()})),lh=b(()=>S().min(1).max(256)),uh=b(()=>ur({agentId:lh,sessionId:lh,commandId:lh,outcome:Tt([`completed`,`failed`,`interrupted`,`cancelled`,`outcome_unknown`]),diagnostic:S().min(1).max(200).optional()})),dh=ur({author:ch.optional(),sourceRequestId:lh.optional(),delegation:ur({ancestors:kt(lh).max(8),maxDepth:tn().int().min(1).max(8),reply:uh.optional()}).optional()});function fh(e){let t=dh.safeParse(e);return t.success?t.data.author:void 0}var ph=e=>crypto.getRandomValues(new Uint8Array(e)),mh=(e,t,n)=>{let r=256-256%e.length;if(r===256){let r=e.length-1;return(i=t)=>{if(!i)return``;let a=``;for(;;){let t=n(i),o=i;for(;o--;)if(a+=e[t[o]&r],a.length>=i)return a}}}let i=Math.ceil(409.6*t/r);return(a=t)=>{if(!a)return``;let o=``;for(;;){let t=n(i),s=i;for(;s--;)if(t[s]<r&&(o+=e[t[s]%e.length],o.length>=a))return o}}},hh=(e,t=21)=>mh(e,t|0,ph),gh=`abcdefghijklmnopqrstuvwxyz0123456789`;function _h(e=21){if(e===1/0||e===-1/0)throw RangeError(`nanoid length must be finite`);return hh(gh,e)()}var vh=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,yh=/^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$/,bh=S().min(1).max(64).regex(vh),xh=S().min(1).max(64).regex(vh),Sh=S().min(1).max(32).regex(yh),Ch=Un({prefix:Sh}),wh=Un({family:bh,version:Kt(1),kinds:cn(xh,Ch)}).superRefine((e,t)=>{let n=Object.entries(e.kinds);if(n.length<1||n.length>64){t.addIssue({code:`custom`,message:`Identifier families must declare between one and 64 kinds`});return}let r=new Set;for(let[,e]of n){if(r.has(e.prefix)){t.addIssue({code:`custom`,message:`Identifier kind prefixes must be distinct`});return}r.add(e.prefix)}}),Th=S(),Eh=/^[a-z0-9]+$/,Dh=new TextEncoder;function Oh(e){return e===32||e>=9&&e<=13}function kh(e){let t=0,n=e.length;for(;t<n&&Oh(e.charCodeAt(t));)t+=1;for(;n>t&&Oh(e.charCodeAt(n-1));)--n;return e.slice(t,n).replace(/[A-Z]/g,e=>String.fromCharCode(e.charCodeAt(0)+32))}function Ah(e){let t=`${e.prefix}_`;function n(e){if(!e.startsWith(t))return!1;let n=e.slice(t.length);return n.length===21&&Eh.test(n)}let r=b(()=>fn(e=>{let t=Th.safeParse(e);return t.success&&n(t.data)}));function i(i){let a,o=i,s=Dh.encode(o).byteLength,c=r.safeParse(o),l=o.startsWith(t)?o.slice(t.length):void 0;if(s<3||s>96)a=`bounds`;else if(l!==void 0&&Array.from(l).length!==21)a=`bounds`;else if(c.success)return{ok:!0,value:c.data};else a=n(kh(o))?`non_canonical`:`grammar`;return{ok:!1,error:{code:`invalid_id`,family:e.family,kind:e.kind,version:1,reason:a}}}let a=b(()=>Th.transform((e,t)=>{let n=i(e);return n.ok?n.value:(t.addIssue({code:`custom`,message:n.error.reason}),ut)}));function o(){let n;try{n=_h(21)}catch{throw e.entropyUnavailable()}return r.parse(`${t}${n}`)}return{family:e.family,kind:e.kind,version:1,generate:o,schema:a,parse:i,is:e=>i(e).ok}}var jh=cn(S(),Un({family:S(),kind:S(),version:Kt(1),generate:me(),schema:Ae(_e),parse:me(),is:me()})),Mh=class extends Error{name=`CairnDefinitionError`;code=`invalid_definition`;constructor(){super(`Cairn identifier family definition is invalid`)}},Nh=class extends Error{name=`CairnGenerationError`;code=`entropy_unavailable`;family;kind;version=1;constructor(e){super(`Cairn entropy source is unavailable`),this.family=e.family,this.kind=e.kind}};function Ph(e){let t;try{t=wh.safeParse(e)}catch{throw new Mh}if(!t.success)throw new Mh;let n=t.data,r={};for(let[t,i]of Object.entries(n.kinds)){let a=i.prefix;r[t]=Ah({family:e.family,kind:t,prefix:a,entropyUnavailable:()=>new Nh({family:n.family,kind:t})})}let i=fn(e=>{let t=jh.safeParse(e);if(!t.success)return!1;let r=Object.entries(t.data);return r.length===Object.keys(n.kinds).length&&r.every(([e,t])=>Object.hasOwn(n.kinds,e)&&t.kind===e&&t.family===n.family)}).safeParse(r);if(!i.success)throw new Mh;return i.data}var Fh=Symbol.for(`effect/MutableList/Empty`),Ih=()=>({head:void 0,tail:void 0,length:0}),Lh=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},Rh=()=>({array:[],mutable:!0,offset:0,next:void 0}),zh=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=Rh(),e.tail=e.tail.next):e.head=e.tail=Rh(),e.tail.array.push(t),e.length++},Bh=e=>{e.head=e.tail=void 0,e.length=0},Vh=(e,t)=>{if(t=ii(t),t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return Bh(e),t}let n=Array(t),r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,e.length===0?Bh(e):Lh(e),n;i=i.next}return Bh(e),n},Hh=e=>{if(!e.head)return Fh;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:Bh(e):Lh(e),t},Uh=`~effect/Queue`,Wh=`~effect/Queue/Enqueue`,Gh=`~effect/Queue/Dequeue`,Kh={_A:pt,_E:pt},qh={[Uh]:Kh,[Wh]:Kh,[Gh]:Kh,...Zr,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:cg(this)}}},Jh=e=>de(t=>{let n=Object.create(qh);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=Ih(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},Xn(n)}),Yh=e=>Jh({capacity:e}),Xh=m(2,(e,t)=>Sn(()=>Zh(e,t)?ug:e.state._tag===`Open`&&e.strategy===`suspend`?yg(e,t):lg)),Zh=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.strategy===`sliding`?(Hh(e.messages),zh(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(zh(e.messages,t),pg(e),!0):(zh(e.messages,t),mg(e),!0):!1,Qh=m(2,(e,t)=>$h(e,ee(t))),$h=m(2,(e,t)=>Vt(()=>eg(e,t))),eg=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=Bn(t),r=be(n,dg);return e.state.offers.size===0&&e.messages.length===0?(wg(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},mg(e),!0)},tg=e=>eg(e,ee(Ut())),ng=e=>Vt(()=>rg(e)),rg=e=>{if(e.state._tag===`Done`)return!1;Bh(e.messages);let t=e.state.offers;wg(e,e.state._tag===`Open`?fg:e.state.exit);for(let e of t)xg(e);return!0},ig=e=>ag(e,1,1/0),ag=m(3,(e,t,n)=>(t=ii(t),n=ii(n),gg(()=>hg(e,t,n)??ue(vg(e,()=>_g(e,t)),ag(e,t,n))))),og=e=>gg(()=>sg(e)??ue(vg(e,()=>_g(e,1)),og(e))),sg=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=Hh(e.messages);return Cg(e),c(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=Sg(e.state.offers);return Cg(e),c(t)}},cg=e=>e.state._tag===`Done`?0:e.messages.length,lg=c(!1),ug=c(!0),dg=Je(Ut()),fg=Le(),pg=e=>{if(e.state._tag!==`Done`&&e.state.takers.size!==0){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(Ct),e.messages.length===0))break}},mg=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,pg(e)},0))},hg=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return c([]);if(!_g(e,t))return;let r=e.messages.length>0?Vh(e.messages,n):[Sg(e.state.offers)];return Cg(e),c(r)},gg=Qe({op:`QueueTake`,[le](e){let t=this[qr]();return ze(t)?t[le](e):t}}),_g=(e,t)=>e.messages.length>=(e.state._tag===`Closing`?1:Math.min(t,e.capacity||1))||e.capacity<=0&&e.state._tag!==`Done`&&e.state.offers.size>0,vg=(e,t)=>Ye(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(Ct);let r={ready:t,resume:n};return e.state.takers.add(r),Vt(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),yg=(e,t)=>Ye(n=>Zh(e,t)?n(ug):bg(e,{_tag:`Single`,message:t,resume:n})),bg=(e,t)=>{if(e.state._tag!==`Open`)return xg(t);let n=e.state.offers;return n.add(t),Vt(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&wg(e,e.state.exit))})},xg=e=>e._tag===`Single`?e.resume(lg):e.resume(c(e.remaining.slice(e.offset))),Sg=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(ug),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(c([]))),n},Cg=e=>{if(e.state._tag===`Done`)return Ta(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(wg(e,e.state.exit),Ta(e.state.exit.cause));for(let t of e.state.offers){let n=e.capacity-e.messages.length;if(n<=0)break;if(t._tag===`Single`)zh(e.messages,t.message),e.state.offers.delete(t),t.resume(ug);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;zh(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(c([]))}let r=e.state;if(r._tag===`Done`)return Ta(r.exit.cause)}return!1},wg=(e,t)=>{if(e.state._tag===`Done`)return;let n=e.state;e.state={_tag:`Done`,exit:t};for(let e of n.takers)e.resume(t);n.takers.clear();for(let e of n.awaiters)e(t);n.awaiters.clear()},Tg=yt,Eg=he,Dg=Dt,Og=Ne,kg=tr,Ag=Ar,jg=e=>new Ng(e),Mg=(e,t,n)=>Ye(r=>{if(e.free>=t)return r(n);let i=()=>{e.free<t||(e.waiters.delete(i),r(n))};return e.waiters.add(i),Vt(()=>{e.waiters.delete(i)})}),Ng=class{waiters=new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){let t=Sn(()=>this.free<e?Mg(this,e,t):(this.taken+=e,Xn(e)));return t}takeIfAvailable(e){return Sn(()=>this.free<e?Xn(!1):(this.taken+=e,Xn(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{for(let e of this.waiters){if(this.free<=0)break;e()}},0),this.free}resize(e){return de(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),Xr))}release(e){return de(t=>Xn(this.releaseUnsafe(t,e)))}get releaseAll(){return de(e=>Xn(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>Br(n=>{let r=Sn(()=>{if(this.free<e){let t=Mg(this,e,Xr);return jt(n(t),()=>r)}return this.taken+=e,xr(n(t),()=>{this.releaseUnsafe(Lt(),e)},!0)});return r})}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>Br(n=>this.free<e?Dn:(this.taken+=e,xr(n(ae(t)),()=>{this.releaseUnsafe(Lt(),e)},!0)))}},Pg=e=>Vt(()=>new Ng(e)),Fg=`~effect/Channel`,Ig=e=>ar(e,Fg),Lg={[Fg]:{_Env:pt,_InErr:pt,_InElem:pt,_OutErr:pt,_OutElem:pt},pipe(){return o(this,arguments)}},Rg=e=>{let t=Object.create(Lg);return t.transform=(t,n)=>Mr(e(t,n),e=>v(Rt(e))),t},zg=(e,t)=>Rg((n,r)=>w(Hg(e)(n,r),e=>t(e,r))),Bg=e=>Rg((t,n)=>e),Vg=e=>Rg(ct(function*(t,n){let r=pa(n),i=e=>ma(r,ka(e)),a=yield*pe(e(t,n,r),i);return pe(a,i)})),Hg=e=>e.transform,Ug=4096,Wg=(e,t,n)=>Jh({capacity:n?.bufferSize,strategy:n?.strategy}).pipe(Qn(t=>da(e,ng(t))),Qn(n=>la(t(n),e).pipe(Mr(e=>$h(n,e)),Ge(e)))),Gg=(e,t)=>Rg((n,r)=>xe(Wg(r,e,t),ig)),Kg=e=>Rg((t,n)=>bn(()=>Hg(e())(t,n))),qg=e=>Bg(C(()=>{let t=e();return bn(()=>{let e=t.next();return e.done?Vi(e.value):v(e.value)})})),Jg=(e,t=Ug)=>{let n=ai(t);return Bg(C(()=>{let t=e(),r=Mn();return bn(()=>{if(r._tag===`Some`)return Vi(r.value);let e=[];for(;e.length<n;){let n=t.next();if(n.done){if(e.length===0)return Vi(n.value);r=sr(n.value);break}e.push(n.value)}return v(e)})}))},Yg=(e,t=Ug)=>Jg(()=>e[Symbol.iterator](),t),Xg=e=>$g(v(e)),Zg=Bg(v(Vi())),Qg=e=>Bg(Rt(e)),$g=e=>Bg(C(()=>{let t=!1;return bn(()=>t?Vi():(t=!0,e))})),e_=e=>Bg(v(ig(e))),t_=m(2,(e,t)=>zg(e,e=>C(()=>{let n=0;return xe(e,e=>t(e,n++))}))),n_=e=>e===void 0||e!==`unbounded`&&e<=1,r_=m(e=>Ig(e[0]),(e,t,n)=>n_(n?.concurrency)?i_(e,t):a_(e,t,n)),i_=(e,t)=>Rg((n,r)=>{let i=0;return xe(Hg(e)(n,r),w(e=>t(e,i++)))}),a_=(e,t,n)=>Vg(ct(function*(r,i,a){let o=0,s=yield*Hg(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:n.concurrency,l=yield*Yh(0);yield*da(a,ng(l));let u=nr(yield*gn()),d=Og(a);if(n.unordered){let e=jg(c),n=lt(e.release(1)),r=bt({onFailure:e=>w($h(l,e),n),onSuccess:e=>w(Xh(l,e),n)});yield*e.take(1).pipe(w(()=>s),w(e=>{let n=o++;return d(u(r(bn(()=>t(e,n))))),_}),ft({disableYield:!0}),Mr(t=>e.withPermits(c-1)($h(l,t))),Ge(a))}else{let e=yield*Yh(c-2);yield*da(a,ng(e)),yield*og(e).pipe(Gr,w(e=>Xh(l,e)),ft({disableYield:!0}),Mr(e=>$h(l,e)),Ge(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,eg(l,e.cause))};yield*s.pipe(w(i=>{if(n)return Rt(n);let a=o++,s=u(bn(()=>t(i,a)));return d(s),s.addObserver(r),Xh(e,Eg(s))}),ft({disableYield:!0}),Mr(t=>Xh(e,Ui(t)).pipe(Gt($h(e,t)))),Ge(a))}return og(l)})),o_=m(e=>Ig(e[0]),(e,t,n)=>n_(n?.concurrency)?s_(e,t):c_(e,t,n)),s_=(e,t)=>Rg((n,r)=>xe(Hg(e)(n,r),e=>{let i,a,o=w(e,e=>(a??=pa(r),Yt(Hg(t(e))(n,a),e=>(i=s(e),i)))),s=wa(e=>{if(i=void 0,a.state._tag===`Empty`)return o;let t=ma(a,Ki);return a=void 0,w(t,()=>o)});return bn(()=>i??o)})),c_=(e,t,n)=>e.pipe(t_(t),h_(n)),l_=e=>o_(e,pt),u_=e=>zg(e,e=>{let t,n=0,r=bn(function r(){if(t===void 0)return w(e,e=>{switch(e.length){case 0:return r();case 1:return v(e[0]);default:return t=e,v(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),v(i)});return v(r)}),d_=m(2,(e,t)=>zg(e,e=>v(w(e,function n(r){let i=[];for(let e=0;e<r.length;e++)t(r[e])&&i.push(r[e]);return Ze(i)?v(i):w(e,n)})))),f_=m(2,(e,t)=>Rg((n,r)=>{let i=pa(r);return xe(Hg(e)(n,i),e=>{let a=e.pipe(Mr(e=>{if(Ta(e))return Rt(e);let o=i;return i=pa(r),ma(o,Ui(e)).pipe(Gt(Hg(t(e))(n,i)),w(e=>(a=e,e)))}));return bn(()=>a)})})),p_=m(3,(e,t,n)=>f_(e,e=>{let r=t(e);return xt(r)?Qg(r.failure):n(r.success,e)})),m_=m(2,(e,t)=>p_(e,Ii,e=>t(e))),h_=m(2,(t,{bufferSize:n=16,concurrency:r,switch:i=!1})=>Vg(ct(function*(a,o,s){let c=r===`unbounded`?2**53-1:Math.max(1,r),l=i?void 0:jg(c),u=yield*Ag(!0),d=new Set,f=yield*Yh(n);yield*da(s,ng(f));let p=yield*Hg(t)(a,o);return yield*x(function*(){for(;;){let t;l&&(d.size<c?yield*l.take(1):(t=yield*oe(p),yield*e(l.take(1),Gt(Eg(t),wt))));let n=t===void 0?yield*p:yield*Eg(t),r=pa(s),i=yield*Hg(n)(a,r);for(;d.size>=c;){let e=oi(d);d.delete(e),d.size===0&&(yield*u.open),yield*Dg(e)}let o=yield*i.pipe(Qn(()=>Wr),w(e=>Xh(f,e)),ft({disableYield:!0}),pe(ct(function*(e){let t=ka(e),n=yield*wn(ma(r,t));if(!d.has(o))return;let i=Xi([t,n]);Ji(i)&&(yield*$h(f,i.cause)),d.delete(o),l&&(yield*l.release(1)),d.size===0&&(yield*u.open)})),oe);u.closeUnsafe(),d.add(o)}}).pipe(Mr(e=>{let t=Da(e);return ve(t)?u.whenOpen($h(f,e)):$h(f,e)}),Ge(s)),og(f)}))),g_=m(e=>Ig(e[0])&&Ig(e[1]),(e,t,n)=>Vg(ct(function*(r,i,a){let o=n?.haltStrategy??`both`,s=yield*Yh(0);yield*da(a,ng(s));let c=0;function l(e,t){if(c++,!Ta(t))return $h(s,t);switch(o){case`both`:return c===2?$h(s,t):_;case`left`:case`right`:return e===o?$h(s,t):_;case`either`:return $h(s,t)}}let u=(e,t,n)=>Hg(t)(r,n).pipe(w(e=>e.pipe(w(e=>Xh(s,e)),ft)),pe(t=>mr(ka(t),e=>ma(n,e)).pipe(bt({onFailure:t=>l(e,t),onSuccess:()=>l(e,t)}))),Ge(a));return yield*u(`left`,e,pa(a)),yield*u(`right`,t,pa(a)),og(s)}))),__=e=>Rg((t,n)=>{let r;return v(bn(()=>r||e.pipe(la(n),w(e=>Hg(e)(t,n)),w(e=>r=e))))}),v_=m(2,(e,t)=>g_(e,Bg(v(w(t,Vi))),{haltStrategy:`either`})),y_=m(2,(e,t)=>Vg((n,r,i)=>ua(i,t).pipe(Gt(Hg(e)(n,r))))),b_=m(2,(e,t)=>y_(e,e=>t)),x_=(e,t,n)=>bn(()=>{let r=ca(),i=Hg(e)(Vi(),r);return wa(w(i,t),n||v).pipe(ke(e=>ma(r,e)))}),S_=m(2,(e,t)=>x_(e,e=>ft(w(e,t),{disableYield:!0}))),C_=ct(function*(e){let t=jg(1),n=yield*gn(),r=zn(n,oa);return(yield*Hg(e)(Vi(),r)).pipe(Ft(n),t.withPermits(1))},Mr(e=>v(Rt(e)))),w_=(e,t)=>Hg(e)(Vi(),t),T_=`~effect/Stream`,E_={_R:pt,_E:pt,_A:pt},D_=function(e){this.channel=e};D_.prototype={[T_]:E_,pipe(){return o(this,arguments)}};var O_=e=>new D_(e),k_=`~effect/Stream`,A_=e=>ar(e,k_),j_=O_,M_=e=>j_($g(xe(e,Fe))),N_=e=>j_(Bg(e)),P_=(e,t)=>j_(Rg((n,r)=>w(w_(e.channel,r),e=>t(e,r)))),F_=e=>e.channel,I_=(e,t)=>j_(Gg(e,t)),L_=j_(Zg),R_=e=>j_(Xg(Fe(e))),z_=e=>j_(Kg(()=>e().channel)),B_=e=>j_(Qg(e)),V_=(e,t)=>Array.isArray(e)&&t?.chunkSize===void 0?H_(e):j_(Yg(e,t?.chunkSize)),H_=e=>Ze(e)?j_(Xg(e)):L_,U_=e=>j_(e_(e)),W_=(e,t)=>N_(C(()=>{let n=e,r=!1;return bn(function e(){return r?Vi():w(t(n),([t,i])=>(tt(i)?r=!0:n=i.value,Ze(t)?v(t):e()))})})),G_=e=>j_(__(xe(e,F_))),K_=m(2,(e,t)=>z_(()=>{let n=0;return j_(t_(e.channel,Se(e=>t(e,n++))))})),q_=m(e=>A_(e[0]),(e,t,n)=>e.channel.pipe(u_,r_(t,n),t_(Fe),j_)),J_=e=>e.pipe(K_(je),rv(e=>R_(at(e)))),Y_=m(e=>A_(e[0]),(e,t,n)=>e.channel.pipe(u_,o_(e=>t(e).channel,n),j_)),X_=m(2,(e,t)=>{let n=j_(l_(qg(()=>Q_(e,t))));return Z_.set(n,[e,t]),n}),Z_=new WeakMap;function*Q_(e,t){let n=[t,e];for(;n.length>0;){let e=n.pop(),t=Z_.get(e);t===void 0?yield e.channel:n.push(t[1],t[0])}}var $_=m(e=>A_(e[0])&&A_(e[1]),(e,t,n)=>j_(g_(F_(e),F_(t),n))),ev=m(2,(e,t)=>j_(d_(F_(e),t))),tv=m(2,ct(function*(e,t){let n,r=yield*C_(e.channel),i=Mr(r,e=>(n=e,Rt(e))),[a,o]=yield*qn(e=>t.transform(i,e)),s=n?L_:N_(v(r));return o&&(s=X_(H_(o),s)),[a,s]})),nv=m(2,(e,t)=>e.channel.pipe(f_(e=>t(e).channel),j_)),rv=m(2,(e,t)=>j_(m_(e.channel,e=>t(e).channel))),iv=m(e=>A_(e[0]),(e,t,n)=>P_(e,(e,r)=>C(()=>{let r=0,i=!1;return w(bn(()=>i?Vi():e),e=>{let a=e.findIndex(e=>t(e,r++));if(a>=0){i=!0;let t=e.slice(0,n?.excludeLast?a:a+1);return Ze(t)?v(t):Vi()}return v(e)})}))),av=m(2,(e,t)=>j_(v_(e.channel,t))),ov=m(2,(e,t)=>j_(b_(e.channel,t))),sv=m(2,(e,t)=>S_(e.channel,e=>{let n=0;return te({while:()=>n<e.length,body:()=>t(e[n++]),step:Kr})})),cv=m(2,(e,t)=>({[Symbol.asyncIterator](){let n=Nn(t),r=nr(t),i=ca(),a,o,s,c,l=e=>{if(c)return c;let t=s;return c=n(Cr(Gt(t?Dg(t):_,ma(i,e)),{done:!0,value:void 0})),c},u=async e=>{try{await l(e)}catch(e){await n(Xe(`Suppressed error while closing Stream async iterator`,e))}};return{async next(){if(c)return c;if(o){let e=o.next();if(!e.done)return e;o=void 0}let t=r(a??w(w_(e.channel,i),e=>(a=e,e)));s=t;let d=await n(Tg(t));if(s===t&&(s=void 0),qi(d))return o=d.value[Symbol.iterator](),o.next();if(Ta(d.cause))return l(Ki);if(c&&Ni(d.cause))return c;throw await u(d),Fi(d.cause)},return(){return l(Ki)},async throw(e){throw await u(Gi(e)),e}}}})),lv=e=>cv(e,qe()),uv=Km.check(V(256)),dv=B.check(z(0)),fv=N({id:uv,kind:Km.check(V(64)),summary:Km.check(V(200)),since:dv,expiresAt:k(dv),inbox:k(A(!1))}),pv=fv.mapFields(e=>({...e,extensionId:uv})),mv=4096,hv=jp(pv).check(V(64)),gv=j.pipe(L(jm(1)),L(V(256))),_v=N({providerId:gv,modelId:gv,reasoning:k(F([`minimal`,`low`,`medium`,`high`,`xhigh`,`max`]))}),vv=cp(I(_v)),yv=cp(Xm(I(_v))),bv=F([`contract`,`extensions`,`instructions`,`model`,`runtime`,`store`,`tools`]),xv=F([`closed`,`conflict`,`incompatible`,`invalid`,`rejected`,`unavailable`,`state_reset_required`,`storage_pressure`]),Sv=j.pipe(L(jm(1)),L(V(256))),Cv=N({_tag:A(`ShiitakeError`),boundary:bv,cause:xv,message:j,requestId:O(Sv)}),H=class extends Error{boundary;requestId;_tag=`ShiitakeError`;cause;underlying;constructor(e,t,n,r,i){super(n),this.boundary=e,this.requestId=r,this.name=`ShiitakeError`,this.cause=t,this.underlying=i}},wv=new TextEncoder;function Tv(e){return j.check(jm(1),V(e),R(t=>wv.encode(t).byteLength<=e))}var Ev=/\p{Cs}/u,Dv=Tv(256).check(R(e=>!Ev.test(e))),Ov=Tv(262144),kv=N({type:A(`image`),data:j.check(jm(1),V(1048576),$p()),mimeType:j.check(R(e=>[`image/png`,`image/jpeg`,`image/gif`,`image/webp`].includes(e)))}),Av=jp(kv).check(jm(1),V(8)),jv=F([`steer`,`followUp`]),Mv=Dv,Nv=E(N({commandId:Dv,timeoutMs:B.check(z(0),mm(3e4))}),{onExcessProperty:`error`});E(N({commandId:Dv,timeoutMs:Zm.check(_m(),hm({minimum:0,maximum:3e4}))}),{onExcessProperty:`error`});var Pv=E(Tv(512)),Fv=N({requestId:Dv}),Iv=N({delivery:jv,requestId:Dv,type:A(`prompt`),text:j.check(V(262144),R(e=>wv.encode(e).byteLength<=262144)),images:O(Av)}).check(R(e=>(e.text.length>0||(e.images?.length??0)>0)&&wv.encode(e.text).byteLength+(e.images??[]).reduce((e,t)=>e+t.data.length,0)<=1048576)),Lv=N({type:A(`abort`)}),Rv=N({commandId:Dv,onlyIfPending:k(wp),type:A(`cancel`)}),zv=N({type:A(`operator`),requestId:Dv,author:F([`operator`,`party`]),text:Ov}),Bv=N({type:A(`branch`),entryId:Dv}),Vv=N({type:A(`fork`),entryId:Dv}),Hv=j.check(jm(1),V(4096)),Uv=N({type:A(`compact`),requestId:Dv,instructions:O(Hv)}),Wv=P([Iv,Uv]),Gv=j.check(R(e=>e.length>0&&e.trim()===e&&!/\p{Cc}/u.test(e)&&Array.from(e).length<=120)),Kv=P([Iv,Lv,Rv,Bv,Vv,zv,Uv,N({type:A(`title`),title:I(Gv)})]),qv=N({command:Kv}),Jv=N({includeSandboxFailures:k(wp),limit:k(B.check(hm({minimum:1,maximum:200}))),before:k(Tv(512))}),Yv=N({includeSandboxFailures:k(A(`true`)),limit:k(Zm.check(_m(),hm({minimum:1,maximum:200}))),before:k(Tv(512))}),Xv=N({includeSandboxFailures:k(wp),after:k(j)}),Zv=N({includeSandboxFailures:k(A(`true`)),mode:k(A(`subscribe`)),after:k(j),limit:k(Zm.check(_m(),hm({minimum:1,maximum:200})))}),Qv={onExcessProperty:`error`},$v=E(Mv,Qv),ey=E(Fv,Qv),ty=E(Wv,Qv);E(Dv);var ny=E(Kv,Qv);E(qv,Qv);var ry=E(P([Jv,Cp]),Qv);E(Yv,Qv);var iy=E(Xv,Qv);E(Zv,Qv);function ay(e){let t=$v(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session id is invalid`);return t.success}function oy(e){let t=Pv(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session cursor is invalid`);return t.success}function sy(e){let t=ey(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session creation request is invalid`);return t.success.requestId}function cy(e){let t=ry(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Read options are invalid`);let n=t.success??{},r={limit:n.limit??200};return n.before!==void 0&&(r={...r,before:n.before}),n.includeSandboxFailures!==void 0&&(r={...r,includeSandboxFailures:n.includeSandboxFailures}),Object.freeze(r)}function ly(e){let t=iy(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Subscribe options are invalid`);let n={};return t.success.after!==void 0&&(n={...n,after:t.success.after}),t.success.includeSandboxFailures!==void 0&&(n={...n,includeSandboxFailures:t.success.includeSandboxFailures}),Object.freeze(n)}function uy(e,t){if(xt(e))throw new H(`contract`,`invalid`,t);return e.success}var dy=/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/,fy=1e3,py=221;function my(e,t){if(t>16)return t;if(Array.isArray(e)){let n=t;for(let r of e)n=Math.max(n,my(r,t+1));return n}if(e===null)return t;let n=cn(S(),yr()).safeParse(e);if(!n.success)return t;let r=t;for(let e of Object.values(n.data))r=Math.max(r,my(e,t+1));return r}var hy=b(()=>cn(S(),yr()).superRefine((e,t)=>{Object.keys(e).length>100&&t.addIssue({code:`custom`,message:`Sample exceeds the entry bound`}),JSON.stringify(e).length>4e3&&t.addIssue({code:`custom`,message:`Sample exceeds the byte bound`}),my(e,0)>16&&t.addIssue({code:`custom`,message:`Sample exceeds the depth bound`})})),gy=b(()=>Un({query:S().max(200),maxResults:tn().int().min(1).max(50).default(50)})),_y=b(()=>Un({path:S().max(160),detail:Tt([`index`,`full`]).default(`full`),methods:kt(S().max(80)).max(50).optional()})),vy=Un({cursor:S().max(400).optional(),limit:tn().int().min(1).max(50).default(50),namespace:S().min(1).max(160).regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/).optional()}),yy=b(()=>Un({path:S().max(160),capabilityNotes:S().max(500).optional()})),by=Un({path:S().max(160),description:S().max(1e3).optional(),score:tn().min(0).max(py),matchReason:S().max(500).optional(),sample:hy.optional(),capabilityNotes:S().max(500).optional(),peers:kt(yy).max(1e3).optional()}),xy=b(()=>Un({results:kt(by).max(50),total:tn().int().min(0).max(fy),truncated:t(),topScore:tn().min(0).max(py),margin:tn().min(0).max(py),catalogStamp:S().length(16).regex(/^[0-9a-f]{16}$/)})),Sy=Un({results:kt(by).max(50),total:tn().int().min(0).max(fy),nextCursor:S().max(400).nullable(),catalogStamp:S().length(16).regex(/^[0-9a-f]{16}$/)}),Cy=b(()=>Un({path:S().max(160),description:S().max(1e3).optional(),types:S().max(2e4),inputSchema:yr().refine(e=>JSON.stringify(e).length<=2e4&&my(e,0)<=16,`Input schema exceeds the description bounds`).optional(),kind:Tt([`module`,`operation`]),usage:S().max(300).optional()}));b(()=>Un({code:Tt([`empty_query`,`empty_catalog`,`unknown_target`,`duplicate_operation`,`invalid_input`]),message:S().max(1e3)}));var wy=b(()=>Un({"~standard":Un({jsonSchema:Un({input:Ae(Function),output:Ae(Function)})})})),Ty=b(()=>fn(e=>wy.safeParse(e).success,`Expected a Standard JSON Schema`)),Ey=b(()=>Un({path:S().min(3).max(160).regex(dy),description:S().max(1e3).optional(),input:Ty,output:Ty.optional(),capabilityNotes:S().max(500).optional(),instructions:S().max(1e3).optional()})),Dy=b(()=>Un({revision:S().min(1).max(160),operations:kt(Ey).max(fy)})),Oy=class extends Error{code;failure;constructor(e,t,n){let r=t.slice(0,1e3);super(r,n),this.name=`ForageError`,this.code=e,this.failure={code:e,message:r}}},ky=yr(),Ay=b(()=>zt([S(),tn(),t()]));function jy(e){return e!==null&&!Array.isArray(e)&&!Ay.safeParse(e).success}function My(e,t){if(e===t)return 0;let n=Math.min(e.length,t.length);for(let r=0;r<n;r+=1){let n=e.charCodeAt(r)-t.charCodeAt(r);if(n!==0)return n}return e.length-t.length}function Ny(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`).replace(/[_./:-]/g,` `).toLowerCase().trim()}function Py(e){return e.split(/[^a-zA-Z0-9]+/).filter(e=>e.length>0)}var Fy=new Set([`the`,`a`,`an`,`for`,`to`,`of`,`that`,`this`,`with`,`in`,`on`]);function Iy(e){return Fy.has(e)}function Ly(e){let t=[],n=n=>{n!==e&&n.length>=3&&!t.includes(n)&&t.push(n)};return e.endsWith(`ing`)&&e.length>4&&n(e.slice(0,-3)),e.endsWith(`ed`)&&e.length>3&&n(e.slice(0,-2)),e.endsWith(`ies`)&&e.length>4&&(n(e.slice(0,-3)),n(`${e.slice(0,-3)}y`)),e.endsWith(`es`)&&e.length>3&&n(e.slice(0,-2)),e.endsWith(`s`)&&!e.endsWith(`ss`)&&e.length>3&&n(e.slice(0,-1)),t}function Ry(e){if(e===null)return`null`;let t=Ay.safeParse(e);return t.success?JSON.stringify(t.data):Array.isArray(e)?`[${e.map(e=>Ry(e)).join(`,`)}]`:jy(e)?`{${Object.entries(e).sort(([e],[t])=>My(e,t)).map(([e,t])=>`${JSON.stringify(e)}:${Ry(t)}`).join(`,`)}}`:`null`}function zy(e){let t=14695981039346656037n,n=(1n<<64n)-1n;for(let r=0;r<e.length;r+=1)t^=BigInt(e.charCodeAt(r)),t=t*1099511628211n&n;return t.toString(16).padStart(16,`0`)}function By(e){return e.slice(e.indexOf(`.`)+1)}function Vy(e){return e.slice(0,e.indexOf(`.`))}var Hy=b(()=>zt([t(),ir({$ref:S().optional(),$defs:cn(S(),Hy).optional(),definitions:cn(S(),Hy).optional(),const:Rr().optional(),enum:kt(Rr()).optional(),oneOf:kt(Hy).optional(),anyOf:kt(Hy).optional(),allOf:kt(Hy).optional(),type:zt([S(),kt(S())]).optional(),properties:cn(S(),Hy).optional(),additionalProperties:Hy.optional(),required:kt(S()).optional(),prefixItems:kt(Hy).optional(),items:zt([Hy,kt(Hy)]).optional(),examples:kt(Rr()).optional(),default:Rr().optional()})])),Uy=new WeakMap;function Wy(e,t){let n=Uy.get(e),r=n?.[t];if(r!==void 0)return r;let i;try{i=Hy.parse(e[`~standard`].jsonSchema[t]({target:`draft-2020-12`}))}catch{throw new Oy(`invalid_input`,`Schema cannot be projected to JSON Schema`)}let a=ky.safeParse(i),o={node:i,json:a.success?a.data:void 0};return n===void 0&&(n={},Uy.set(e,n)),n[t]=o,o}function Gy(e,t){return Wy(e,t).node}function Ky(e){return Array.isArray(e)}var qy=256,Jy=/^#\/(?:\$defs|definitions)\/([^/]+)$/u;function Yy(e,t,n){let r=Jy.exec(e)?.[1];if(r===void 0||n.expanding.has(r))return`unknown`;let i=n.definitions[r];if(i===void 0)return`unknown`;if(n.budget.expansions+=1,n.budget.expansions>qy)throw new Oy(`invalid_input`,`Schema references expand more than ${String(qy)} times; flatten its shared definitions`);return Zy(i,t,{definitions:n.definitions,expanding:new Set([...n.expanding,r]),budget:n.budget})}function Xy(e,t){if(e===!0||e===!1)return!1;if(e.$ref!==void 0){let n=Jy.exec(e.$ref)?.[1],r=n===void 0||t.expanding.has(n)?void 0:t.definitions[n];return n!==void 0&&r!==void 0&&Xy(r,{definitions:t.definitions,expanding:new Set([...t.expanding,n]),budget:t.budget})}return e.const===void 0?e.enum!==void 0&&e.enum.length>1||e.oneOf!==void 0&&e.oneOf.length>1||e.anyOf!==void 0&&e.anyOf.length>1:!1}function Zy(e,t,n){if(e===void 0||e===!0||e===!1||t>12)return`unknown`;if(e.$ref)return Yy(e.$ref,t,n);if(e.const!==void 0)return JSON.stringify(e.const);if(e.enum)return e.enum.map(e=>JSON.stringify(e)).join(` | `);if(e.oneOf)return e.oneOf.map(e=>Zy(e,t+1,n)).join(` | `);if(e.anyOf)return e.anyOf.map(e=>Zy(e,t+1,n)).join(` | `);if(e.allOf)return e.allOf.map(e=>{let r=Zy(e,t+1,n);return Xy(e,n)?`(${r})`:r}).join(` & `);if(e.type===`object`||e.properties){let r=Object.entries(e.properties??{}).sort(([e],[t])=>My(e,t));if(r.length===0){let r=e.additionalProperties;return r===!1?`Record<string, never>`:r&&r!==!0?`Record<string, ${Zy(r,t+1,n)}>`:`Record<string, unknown>`}let i=new Set(e.required??[]);return`{
|
|
4
|
+
${r.map(([e,r])=>{let a=Zy(r,t+1,n),o=i.has(e)?``:`?`,s=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)?e:JSON.stringify(e);return`${` `.repeat(t+1)}${s}${o}: ${a};`}).join(`
|
|
5
5
|
`)}
|
|
6
|
-
${` `.repeat(t)}}`}if(e.type===`array`){let r=e.items;if(e.prefixItems&&e.prefixItems.length>0){let i=e.prefixItems.map(e=>
|
|
6
|
+
${` `.repeat(t)}}`}if(e.type===`array`){let r=e.items;if(e.prefixItems&&e.prefixItems.length>0){let i=e.prefixItems.map(e=>Zy(e,t+1,n));return r!==void 0&&r!==!0&&!Ky(r)&&i.push(`...${Zy(r,t+1,n)}[]`),`[${i.join(`, `)}]`}if(r!==void 0&&Ky(r))return`[${r.map(e=>Zy(e,t+1,n)).join(`, `)}][]`;let i=Zy(r,t+1,n);return`${r!==void 0&&r!==!0&&r!==!1&&(r.oneOf!==void 0||r.anyOf!==void 0||r.allOf!==void 0)?`(${i})`:i}[]`}switch(e.type){case`string`:return`string`;case`number`:case`integer`:return`number`;case`boolean`:return`boolean`;case`null`:return`null`;default:return`unknown`}}function Qy(e,t=`input`){let n=Gy(e,t);return Zy(n,0,{definitions:n===!0||n===!1?{}:{...n.definitions,...n.$defs},expanding:new Set,budget:{expansions:0}})}function $y(e){return e.replace(/[^A-Za-z0-9_$]/g,`_`)}function eb(e,t,n){let r=`(input: ${t}) => Promise<${n}>`;for(let t of e.split(`.`).reverse())r=`{ [${JSON.stringify(t)}]: ${r} }`;return r}function tb(e){return e.length===0?``:`export declare const env: ${e.map(e=>e.indexEnvironment).join(` & `)};`}function nb(e){let t=e.map(e=>e.types).join(`
|
|
7
7
|
|
|
8
|
-
`);return e.length===0?t:`${t}\nexport declare const env: ${e.map(e=>e.environment).join(` & `)};`}function
|
|
9
|
-
`))}function gb(e,t){if(e===t)return`exact`;if(e.startsWith(t))return`startsWith`;let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);if(RegExp(`\\b${n}\\b`).test(e))return`phrase`;let r=Ny(e);return r.some(e=>e===t)?`token`:r.some(e=>e.startsWith(t))?`prefix`:r.some(e=>e.includes(t))?`substring`:e.includes(t)?`includes`:`none`}function _b(e,t,n){let r=My(e),i=`none`,a=0,o=[];for(let e of n){let n=[e,...Iy(e)],s=`none`;for(let e of n){let t=gb(r,e);if(t!==`none`){s=t;break}}if(s===`none`)continue;let c=pb[s]*mb(t);c>a?(i=s,a=c,o=[e]):c===a&&!o.includes(e)&&o.push(e)}return{level:i,score:a,matchedTokens:o}}function vb(e,t){let n=My(e);return[t,...Iy(t)].some(e=>n.includes(e))}function yb(e){let t=[];for(let[n,r]of e){if(r.level===`none`)continue;let e=r.matchedTokens.slice(0,4).map(e=>e.slice(0,20));t.push(`${n}:${r.level}(${e.join(` `)})`)}return t.length>0?t.join(`; `):void 0}function bb(e){let t=by.safeParse(e);if(!t.success)throw new Dy(`invalid_input`,`Search output exceeded its bounds`);return t.data}function xb(e){return[zy(e.path),(e.description??``).trim().toLowerCase().replace(/\s+/g,` `),e.fingerprint].join(`\0`)}function Sb(e){return bb({results:[],total:0,truncated:!1,topScore:0,margin:0,catalogStamp:e})}function Cb(e,t,n,r,i){let a=By(e.path),o=zy(e.path),s=e.description??``,c=[e.path,a,o,s],l=_b(e.path,`path`,n),u=_b(a,`namespace`,n),d=_b(o,`method`,n),f=_b(s,`description`,n),p=r.filter(e=>c.some(t=>vb(t,e))).length,m=p/r.length,ee=My(`${e.path} ${s}`).includes(t);if(m<i&&!ee)return;let te=Math.max(l.score,u.score,d.score,f.score);if(te===0)return;let ne=p===r.length?25:m*10,h=r[0];h&&c.some(e=>vb(e,h))&&(ne+=8),(l.level===`exact`||d.level===`exact`)&&(ne+=20);let re={path:e.path,score:te+ne};s&&(re.description=s);let ie=yb([[`method`,d],[`description`,f],[`path`,l],[`namespace`,u]]);return ie&&(re.matchReason=ie),e.sample&&(re.sample=e.sample),e.capabilityNotes&&(re.capabilityNotes=e.capabilityNotes),{result:re,cluster:xb(e),pathScore:l.score}}function wb(e){let t=new Map;for(let n of e){let e=t.get(n.cluster)??[];e.push(n),t.set(n.cluster,e)}let n=[];for(let e of t.values()){let t=[...e].sort((e,t)=>t.pathScore-e.pathScore||t.result.score-e.result.score||jy(e.result.path,t.result.path)),r=t[0];if(!r)continue;let i=[],a=t.slice(1).sort((e,t)=>jy(e.result.path,t.result.path));for(let e of a){let t={path:e.result.path};e.result.capabilityNotes&&(t.capabilityNotes=e.result.capabilityNotes),i.push(t)}let o={...r.result,score:Math.max(...t.map(e=>e.result.score))};i.length>0&&(o.peers=i),n.push(o)}return n.sort((e,t)=>t.score-e.score||jy(e.path,t.path))}function Tb(e,t,n){let r=e.slice(0,t),i=r[0],a=r[1];return bb({results:r,total:e.length,truncated:e.length>t,topScore:i?.score??0,margin:i&&a?i.score-a.score:0,catalogStamp:n})}function Eb(e,t,n=50,r){let i=Math.min(50,Math.max(1,Math.floor(n))),a=My(t),o=Ny(a),s=o.filter(e=>!Fy(e));if(s.length===0)return Sb(r);let c=s.length<=2?1:.6,l=[];for(let t of e){let e=Cb(t,a,o,s,c);e&&l.push(e)}return Tb(wb(l),i,r)}var Db=ur({catalogStamp:xy.shape.catalogStamp,namespace:_y.shape.namespace.unwrap().nullable(),after:yy.shape.path});function Ob(e,t,n){let r=_y.safeParse(n);if(!r.success)throw new Dy(`invalid_input`,r.error.message);let i=r.data,a=i.namespace??null,o=e.filter(e=>a===null||e.path.startsWith(`${a}.`)).sort((e,t)=>jy(By(e.path),By(t.path))||jy(e.path,t.path)),s=0;if(i.cursor!==void 0){let e;try{e=Db.parse(JSON.parse(i.cursor))}catch(e){throw new Dy(`invalid_input`,`Invalid listing cursor`,{cause:e})}if(e.catalogStamp!==t||e.namespace!==a)throw new Dy(`invalid_input`,`Listing cursor belongs to a different catalog or namespace`);let n=o.findIndex(t=>t.path===e.after);if(n<0)throw new Dy(`invalid_input`,`Listing cursor operation is absent from this view`);s=n+1}let c=o.slice(s,s+i.limit),l=c.at(-1);return xy.parse({results:c,total:o.length,catalogStamp:t,nextCursor:s+c.length<o.length&&l!==void 0?JSON.stringify({catalogStamp:t,namespace:a,after:l.path}):null})}var kb=1e6;function Ab(e){let t=Ey.safeParse(e);if(!t.success)throw new Dy(`invalid_input`,t.error.message);if(t.data.operations.length===0)throw new Dy(`empty_catalog`,`Catalog must contain an operation`);let n=[...t.data.operations].sort((e,t)=>jy(e.path,t.path)),r=new Set,i=0;for(let e of n){if(r.has(e.path))throw new Dy(`duplicate_operation`,`Duplicate operation path: ${e.path}`);r.add(e.path);let t=sb(e.input,`input`);if(t===void 0)throw new Dy(`invalid_input`,`Schema projection is too large: ${e.path}`);let n=e.output?sb(e.output,`output`):0;if(n===void 0)throw new Dy(`invalid_input`,`Schema output projection is too large: ${e.path}`);if(i+=t+n+e.path.length,i+=e.description?.length??0,i+=e.capabilityNotes?.length??0,i+=e.instructions?.length??0,i>kb)throw new Dy(`invalid_input`,`Catalog metadata exceeds the bounded projection`)}let a=n.map(e=>fb(e));for(let e of a)if(tb([e.rendered]).length>2e4)throw new Dy(`invalid_input`,`Operation description exceeds the bounded output: ${e.path}`);return{revision:t.data.revision,operations:a}}function jb(e){let t=Ab(e),n=Object.freeze(t.operations),r=hb(n),i=n.map(e=>{let t={path:e.path,score:0};return e.description!==void 0&&(t.description=e.description),e.sample!==void 0&&(t.sample=e.sample),e.capabilityNotes!==void 0&&(t.capabilityNotes=e.capabilityNotes),t});return Object.freeze({revision:t.revision,search:e=>{let t=hy.safeParse(e);if(!t.success)throw new Dy(`invalid_input`,t.error.message);if(t.data.query.trim().length===0)throw new Dy(`empty_query`,`Search query must not be empty`);return Eb(n,t.data.query,t.data.maxResults,r)},describe:e=>{let t=gy.safeParse(e);if(!t.success)throw new Dy(`invalid_input`,t.error.message);if(t.data.path.trim().length===0)throw new Dy(`empty_query`,`Description target must not be empty`);return db(n,t.data)},list:e=>Ob(i,r,e),stamp:()=>r})}var Mb=b(()=>S().min(1).max(75).regex(/^[A-Za-z][A-Za-z0-9_]*$/));b(()=>zt([cn(S(),yr()),t()]));var Nb=b(()=>Un({tool:Mb,title:S().max(120),description:S().max(1e3),input:cn(S(),yr()),output:cn(S(),yr()),call:cn(S(),yr())}).catchall(yr()));b(()=>Or(`kind`,[ur({kind:Kt(`unindexed`)}),ur({kind:Kt(`ready`),tools:kt(Nb).max(100).refine(e=>new Set(e.map(e=>e.tool)).size===e.length,{message:`Tool family names must be distinct`})})]));var Pb=Object.freeze({replay:`safe`,path:`forage.search`,description:`Search operation names and descriptions with short keywords, such as read or shell. If no results match, retry with one relevant keyword. Describe known operation paths directly with forage.describe.`,input:hy,output:by}),Fb=Object.freeze({replay:`safe`,path:`forage.describe`,description:`Describe a capability`,input:gy,output:Sy}),Ib=Object.freeze({replay:`safe`,path:`forage.list`,description:`List every available operation in stable namespace then path order (UTF-16 code units). Use limit (1–50) and nextCursor to page without duplicates, optionally filtering by exact namespace. total counts all operations in that filter; summaries match search, with score 0 and no peer merging. A cursor belongs to this catalog and filter; describe paths before calling them.`,input:_y,output:xy});Object.freeze({createCatalog:jb,forageSearchDefinition:Pb,forageDescribeDefinition:Fb,forageListDefinition:Ib});var Lb=`invalid_definition`,Rb=`runtime_closed`,zb=`source_failure`,U=class extends Error{code=Lb;constructor(e){super(e),this.name=`MyceliumDefinitionError`}},Bb=class extends Error{code=Rb;constructor(e=`Mycelium runtime is closed`){super(e),this.name=`MyceliumClosedError`}},Vb=class extends Error{sourceId;phase;code=zb;constructor(e,t){super(e===void 0?`Capability source ${t} failed`:`Capability source ${t} failed: ${e}`),this.sourceId=e,this.phase=t,this.name=`MyceliumSourceError`}},Hb=class extends Error{issues;constructor(e){super(`Invalid operation input`),this.issues=e,this.name=`InvalidOperationInput`}},Ub=class extends Error{issues;constructor(e){super(`Operation output failed its declared schema`),this.issues=e,this.name=`InvalidOperationOutput`}},Wb=class extends Ei(`SourceInvalid`){},Gb=class extends Ei(`GuestThrew`){},Kb=class extends Ei(`DeadlineExceeded`){},qb=class extends Ei(`SandboxBusy`){code=`sandbox-busy`},Jb=class extends Ei(`Cancelled`){},Yb=class extends Ei(`DispatchLost`){},Xb=class extends Ei(`SandboxCrashed`){},Zb=class extends Ei(`BadResponse`){},Qb=class extends Ei(`ResultTooLarge`){},$b=class extends Ei(`ResultNotJson`){},ex=class extends Ei(`CapabilityFailed`){constructor(e){super(e),this.message=rx(this)}},tx=class extends Ei(`Unknown`){};function nx(e,t){switch(e._tag){case`SourceInvalid`:return new Wb({line:e.line,column:e.column,excerpt:e.excerpt,ref:t});case`GuestThrew`:return new Gb({name:e.name,message:e.message,missingVariable:e.missingVariable,transportMessage:e.transportMessage,ref:t});case`DeadlineExceeded`:return new Kb({limitMs:e.limitMs,elapsedMs:e.elapsedMs,acknowledged:e.acknowledged,ref:t});case`SandboxBusy`:return new qb({capacity:e.capacity,waitedMs:e.waitedMs,ref:t});case`Cancelled`:return new Jb({by:e.by,acknowledged:e.acknowledged,ref:t});case`DispatchLost`:return new Yb({elapsedMs:e.elapsedMs,transport:e.transport,errno:e.errno,rawCause:e.rawCause,ref:t});case`SandboxCrashed`:return new Xb({exit:e.exit,errno:e.errno,rawCause:e.rawCause,ref:t});case`BadResponse`:return new Zb({reason:e.reason,rawCause:e.rawCause,ref:t});case`ResultTooLarge`:return new Qb({size:e.size,ref:t});case`ResultNotJson`:return new $b({kind:e.kind,rawCause:e.rawCause,ref:t});case`CapabilityFailed`:return new ex({namespace:e.namespace,operation:e.operation,cause:e.cause,rawCause:e.rawCause,ref:t});case`Unknown`:return new tx({rawCause:e.rawCause,ref:t})}}function rx(e,t=!0){let n;switch(e._tag){case`SourceInvalid`:n=`SyntaxError in submitted source line ${String(e.line)}, column ${String(e.column)}: ${e.excerpt.slice(0,160)}. Nothing ran. Fix quote/heredoc nesting: quote multi-line shell text with a JavaScript template literal or \\n escapes; escape backticks and \${ inside it. If a nested heredoc is hard to quote, write the script with Files, then execute it.`;break;case`GuestThrew`:{let t=e.name.slice(0,80),r=e.message.slice(0,512),i=e.missingVariable;n=`${t}: ${r}${i===void 0?``:`. Declare ${i} with const or let before assigning it; this sandbox does not create implicit globals. Each execute call has its own variables.`}`;break}case`DeadlineExceeded`:n=`execute hit its ${String(e.limitMs)} ms deadline after ${String(e.elapsedMs)} ms; split the work or persist progress${e.acknowledged===!1?`; sandbox did not acknowledge cancellation`:``}`;break;case`SandboxBusy`:n=`sandbox-busy: all ${String(e.capacity)} sandbox slots remained occupied after waiting ${String(e.waitedMs)} ms. Nothing ran; retry this call after capacity becomes available.`;break;case`Cancelled`:n=e.acknowledged===!1?`Sandbox did not acknowledge cancellation`:`Execution was cancelled`;break;case`DispatchLost`:n=`The sandbox lost contact after ${String(e.elapsedMs)} ms; a running command may still be running; check its effects before retrying`;break;case`SandboxCrashed`:n=`The sandbox process stopped before answering; check effects before retrying`;break;case`BadResponse`:n=`The sandbox returned an unreadable result; retry once, split the call if it recurs`;break;case`ResultTooLarge`:n=`Sandbox result exceeds 256 KiB`;break;case`ResultNotJson`:n=`Sandbox returned non-JSON data`;break;case`CapabilityFailed`:n=e.cause.message.slice(0,1e3);break;case`Unknown`:return`The sandbox failed for an unrecognized reason${t?` (ref ${e.ref??`unavailable`})`:``}`}return!t||e.ref===void 0?n:`${n} (ref ${e.ref})`}var ix=b(()=>zt([Ae(Wb),Ae(Gb),Ae(Kb),Ae(qb),Ae(Jb),Ae(Yb),Ae(Xb),Ae(Zb),Ae(Qb),Ae($b),Ae(ex),Ae(tx)])),ax=b(()=>Rr().pipe(zt([Ae(Error).transform(e=>({kind:`error`,value:e})),hr().transform(e=>({kind:`null`,value:e})),Ee().transform(e=>({kind:`undefined`,value:e})),S().transform(e=>({kind:`string`,value:e})),t().transform(e=>({kind:`boolean`,value:e})),zt([tn(),wr(),Kt(1/0),Kt(-1/0)]).transform(e=>({kind:`number`,value:e})),et().transform(e=>({kind:`bigint`,value:e})),Tn().transform(e=>({kind:`symbol`,value:e})),Ae(Function).transform(e=>({kind:`function`,value:e})),kt(Rr()).transform(e=>({kind:`array`,value:e})),zt([Ae(Object),cn(S(),Rr())]).transform(e=>({kind:`object`,value:e})),Rr().transform(()=>({kind:`opaque`}))])));function ox(e){return ix.safeParse(e).success}function sx(e){let t=ix.safeParse(e);return t.success?t.data:new tx({rawCause:e})}function cx(e){let t=ax.parse(e);switch(t.kind){case`error`:case`array`:case`null`:return`object`;default:return t.kind}}b(()=>yr().optional());function lx(e){return ux(e,new Set)}function ux(e,t){let n=ax.parse(e);switch(n.kind){case`null`:case`undefined`:return null;case`string`:case`boolean`:return n.value;case`number`:return Number.isFinite(n.value)?n.value:String(n.value);case`bigint`:case`symbol`:return String(n.value);case`function`:return{kind:`function`,name:n.value.name};case`opaque`:return{kind:`opaque`};case`error`:case`array`:case`object`:{let r=n.value;if(t.has(e))return{kind:`circular_reference`};t.add(e);try{if(n.kind===`array`)return n.value.map(e=>ux(e,t));let e=Object.fromEntries(Object.entries(r).map(([e,n])=>[e,ux(n,t)]));if(n.kind===`error`){let r=n.value;e.name=r.name,e.message=r.message,r.stack!==void 0&&(e.stack=r.stack),r.cause!==void 0&&(e.cause=ux(r.cause,t)),r instanceof AggregateError&&(e.errors=ux(r.errors,t))}return e}finally{t.delete(e)}}}}var dx=b(()=>Un({name:Kt(`ReferenceError`),message:S().regex(/^[\p{ID_Start}_$][\p{ID_Continue}$]* is not defined$/u)}).transform(e=>({...e,missingVariable:e.message.slice(0,-15)})));b(()=>zt([dx,Un({name:S(),message:S()})]).and(Un({transportMessage:S().max(512).optional()})));var fx=b(()=>ur({v:Kt(1),kind:Kt(`sandbox_failure`),tag:Tt([`SourceInvalid`,`GuestThrew`,`DeadlineExceeded`,`SandboxBusy`,`Cancelled`,`DispatchLost`,`SandboxCrashed`,`BadResponse`,`ResultTooLarge`,`ResultNotJson`,`CapabilityFailed`,`Unknown`]),ref:S().min(1).max(32),message:S().max(160)})),px=E(Xm(xp)),mx=b(()=>S().transform((e,t)=>{let n=px(e);return xt(n)?(t.addIssue({code:`custom`,message:`Invalid sandbox transport JSON`}),ut):n.success})).pipe(fx);ur({error:mx}),b(()=>Rr().pipe(zt([Kt(`Execution timed out`).transform(()=>({kind:`deadline`})),Rr().transform(e=>({kind:`bad_response`,rawCause:e}))])));var hx=ur({sandboxCapacity:$n().positive().optional(),admissionWaitMs:$n().min(1).max(9e5).optional()});function gx(e,t){let n=hx.safeParse(e??{}),r=$n().positive().safeParse(t??2);if(!n.success||!r.success)throw new U(`Sandbox admission policy is invalid`);return Object.freeze({capacity:n.data.sandboxCapacity??Math.min(32,Math.max(2,r.data)),waitMs:n.data.admissionWaitMs??5e3})}var _x=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,7,9,32,4,318,1,78,5,71,10,50,3,123,2,54,14,32,10,3,1,11,3,46,10,8,0,46,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,3,0,158,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,68,8,2,0,3,0,2,3,2,4,2,0,15,1,83,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,7,19,58,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,199,7,137,9,54,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,55,9,266,3,10,1,2,0,49,6,4,4,14,10,5350,0,7,14,11465,27,2343,9,87,9,39,4,60,6,26,9,535,9,470,0,2,54,8,3,82,0,12,1,19628,1,4178,9,519,45,3,22,543,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,101,0,161,6,10,9,357,0,62,13,499,13,245,1,2,9,233,0,3,0,8,1,6,0,475,6,110,6,6,9,4759,9,787719,239],vx=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,13,10,2,14,2,6,2,1,2,10,2,14,2,6,2,1,4,51,13,310,10,21,11,7,25,5,2,41,2,8,70,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,7,25,39,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,39,27,10,22,251,41,7,1,17,5,57,28,11,0,9,21,43,17,47,20,28,22,13,52,58,1,3,0,14,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,20,1,64,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,31,9,2,0,3,0,2,37,2,0,26,0,2,0,45,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,38,6,186,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,19,72,200,32,32,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,24,43,261,18,16,0,2,12,2,33,125,0,80,921,103,110,18,195,2637,96,16,1071,18,5,26,3994,6,582,6842,29,1763,568,8,30,18,78,18,29,19,47,17,3,32,20,6,18,433,44,212,63,33,24,3,24,45,74,6,0,67,12,65,1,2,0,15,4,10,7381,42,31,98,114,8702,3,2,6,2,1,2,290,16,0,30,2,3,0,15,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,1845,30,7,5,262,61,147,44,11,6,17,0,322,29,19,43,485,27,229,29,3,0,208,30,2,2,2,1,2,6,3,4,10,1,225,6,2,3,2,1,2,14,2,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42719,33,4381,3,5773,3,7472,16,621,2467,541,1507,4938,6,8489],yx=`·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛-࢟࣊-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍୕-ୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄ఼ా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ೳഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ඁ-ඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ຼ່-໎໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜕ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠏-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᪿ--ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭᳴᳷-᳹᷀-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯・꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧ꠬ꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_・`,bx=`ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࡰ-ࢇࢉ-ࢠ-ࣉऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౝౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽ-ೞೠೡೱೲഄ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄຆ-ຊຌ-ຣລວ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜑᜟ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭌᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-Ა-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳳᳵᳶᳺᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆿㇰ-ㇿ㐀-䶿一-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ--ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭩꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ`,xx={3:`abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile`,5:`class enum extends super const export import`,6:`enum`,strict:`implements interface let package private protected public static yield`,strictBind:`eval arguments`},Sx=`break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this`,Cx={5:Sx,"5module":Sx+` export import`,6:Sx+` const class extends export import super`},wx=/^in(stanceof)?$/,Tx=RegExp(`[`+bx+`]`),Ex=RegExp(`[`+bx+yx+`]`);function Dx(e,t){for(var n=65536,r=0;r<t.length;r+=2){if(n+=t[r],n>e)return!1;if(n+=t[r+1],n>=e)return!0}return!1}function Ox(e,t){return e<65?e===36:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&Tx.test(String.fromCharCode(e)):t!==!1&&Dx(e,vx)}function kx(e,t){return e<48?e===36:e<58?!0:e<65?!1:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&Ex.test(String.fromCharCode(e)):t===!1?!1:Dx(e,vx)||Dx(e,_x)}var W=function(e,t){t===void 0&&(t={}),this.label=e,this.keyword=t.keyword,this.beforeExpr=!!t.beforeExpr,this.startsExpr=!!t.startsExpr,this.isLoop=!!t.isLoop,this.isAssign=!!t.isAssign,this.prefix=!!t.prefix,this.postfix=!!t.postfix,this.binop=t.binop||null,this.updateContext=null};function Ax(e,t){return new W(e,{beforeExpr:!0,binop:t})}var jx={beforeExpr:!0},Mx={startsExpr:!0},Nx={};function G(e,t){return t===void 0&&(t={}),t.keyword=e,Nx[e]=new W(e,t)}var K={num:new W(`num`,Mx),regexp:new W(`regexp`,Mx),string:new W(`string`,Mx),name:new W(`name`,Mx),privateId:new W(`privateId`,Mx),eof:new W(`eof`),bracketL:new W(`[`,{beforeExpr:!0,startsExpr:!0}),bracketR:new W(`]`),braceL:new W(`{`,{beforeExpr:!0,startsExpr:!0}),braceR:new W(`}`),parenL:new W(`(`,{beforeExpr:!0,startsExpr:!0}),parenR:new W(`)`),comma:new W(`,`,jx),semi:new W(`;`,jx),colon:new W(`:`,jx),dot:new W(`.`),question:new W(`?`,jx),questionDot:new W(`?.`),arrow:new W(`=>`,jx),template:new W(`template`),invalidTemplate:new W(`invalidTemplate`),ellipsis:new W(`...`,jx),backQuote:new W("`",Mx),dollarBraceL:new W("${",{beforeExpr:!0,startsExpr:!0}),eq:new W(`=`,{beforeExpr:!0,isAssign:!0}),assign:new W(`_=`,{beforeExpr:!0,isAssign:!0}),incDec:new W(`++/--`,{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new W(`!/~`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:Ax(`||`,1),logicalAND:Ax(`&&`,2),bitwiseOR:Ax(`|`,3),bitwiseXOR:Ax(`^`,4),bitwiseAND:Ax(`&`,5),equality:Ax(`==/!=/===/!==`,6),relational:Ax(`</>/<=/>=`,7),bitShift:Ax(`<</>>/>>>`,8),plusMin:new W(`+/-`,{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:Ax(`%`,10),star:Ax(`*`,10),slash:Ax(`/`,10),starstar:new W(`**`,{beforeExpr:!0}),coalesce:Ax(`??`,1),_break:G(`break`),_case:G(`case`,jx),_catch:G(`catch`),_continue:G(`continue`),_debugger:G(`debugger`),_default:G(`default`,jx),_do:G(`do`,{isLoop:!0,beforeExpr:!0}),_else:G(`else`,jx),_finally:G(`finally`),_for:G(`for`,{isLoop:!0}),_function:G(`function`,Mx),_if:G(`if`),_return:G(`return`,jx),_switch:G(`switch`),_throw:G(`throw`,jx),_try:G(`try`),_var:G(`var`),_const:G(`const`),_while:G(`while`,{isLoop:!0}),_with:G(`with`),_new:G(`new`,{beforeExpr:!0,startsExpr:!0}),_this:G(`this`,Mx),_super:G(`super`,Mx),_class:G(`class`,Mx),_extends:G(`extends`,jx),_export:G(`export`),_import:G(`import`,Mx),_null:G(`null`,Mx),_true:G(`true`,Mx),_false:G(`false`,Mx),_in:G(`in`,{beforeExpr:!0,binop:7}),_instanceof:G(`instanceof`,{beforeExpr:!0,binop:7}),_typeof:G(`typeof`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:G(`void`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:G(`delete`,{beforeExpr:!0,prefix:!0,startsExpr:!0})},Px=/\r\n?|\n|\u2028|\u2029/,Fx=new RegExp(Px.source,`g`);function Ix(e){return e===10||e===13||e===8232||e===8233}function Lx(e,t,n){n===void 0&&(n=e.length);for(var r=t;r<n;r++){var i=e.charCodeAt(r);if(Ix(i))return r<n-1&&i===13&&e.charCodeAt(r+1)===10?r+2:r+1}return-1}var Rx=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,zx=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Bx=Object.prototype,Vx=Bx.hasOwnProperty,Hx=Bx.toString,Ux=Object.hasOwn||(function(e,t){return Vx.call(e,t)}),Wx=Array.isArray||(function(e){return Hx.call(e)===`[object Array]`}),Gx=Object.create(null);function Kx(e){return Gx[e]||(Gx[e]=RegExp(`^(?:`+e.replace(/ /g,`|`)+`)$`))}function qx(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}var Jx=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/,Yx=function(e,t){this.line=e,this.column=t};Yx.prototype.offset=function(e){return new Yx(this.line,this.column+e)};var Xx=function(e,t,n){this.start=t,this.end=n,e.sourceFile!==null&&(this.source=e.sourceFile)};function Zx(e,t){for(var n=1,r=0;;){var i=Lx(e,r,t);if(i<0)return new Yx(n,t-r);++n,r=i}}var Qx={ecmaVersion:null,sourceType:`script`,strict:!1,onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:null,allowSuperOutsideMethod:null,allowHashBang:!1,checkPrivateFields:!0,locations:!1,startLocation:null,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1},$x=!1;function eS(e){var t={};for(var n in Qx)t[n]=e&&Ux(e,n)?e[n]:Qx[n];if(t.ecmaVersion===`latest`?t.ecmaVersion=1e8:t.ecmaVersion==null?(!$x&&typeof console==`object`&&console.warn&&($x=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.
|
|
10
|
-
Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=11):t.ecmaVersion>=2015&&(t.ecmaVersion-=2009),t.allowReserved??=t.ecmaVersion<5,(!e||e.allowHashBang==null)&&(t.allowHashBang=t.ecmaVersion>=14),
|
|
11
|
-
`,n-1)+1,this.options.locations&&(this.curLine=this.input.slice(0,this.lineStart).split(Px).length)):this.lineStart=0,this.type=K.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=e.sourceType===`module`,this.strict=this.inModule||e.strict===!0||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&e.allowHashBang&&this.input.slice(0,2)===`#!`&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType===`commonjs`?rS:nS),this.regexpState=null,this.privateNameStack=[]},SS={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},canAwait:{configurable:!0},allowReturn:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0},allowNewDotTarget:{configurable:!0},allowUsing:{configurable:!0},inClassStaticBlock:{configurable:!0}};xS.prototype.parse=function(){var e=this,t=this.options.program||this.startNode();return this.nextToken(),this.catchStackOverflow(function(){return e.parseTopLevel(t)})},SS.inFunction.get=function(){return(this.currentVarScope().flags&rS)>0},SS.inGenerator.get=function(){return(this.currentVarScope().flags&aS)>0},SS.inAsync.get=function(){return(this.currentVarScope().flags&iS)>0},SS.canAwait.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e].flags;if(t&(uS|dS))return!1;if(t&rS)return(t&iS)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction},SS.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&nS)},SS.allowSuper.get=function(){return(this.currentThisScope().flags&cS)>0||this.options.allowSuperOutsideMethod},SS.allowDirectSuper.get=function(){return(this.currentThisScope().flags&lS)>0},SS.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())},SS.allowNewDotTarget.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e].flags;if(t&(uS|dS)||t&rS&&!(t&oS))return!0}return!1},SS.allowUsing.get=function(){var e=this.currentScope().flags;return!(e&fS||!this.inModule&&e&nS)},SS.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&uS)>0},xS.extend=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];for(var n=this,r=0;r<e.length;r++)n=e[r](n);return n},xS.parse=function(e,t){return new this(t,e).parse()},xS.parseExpressionAt=function(e,t,n){var r=new this(n,e,t);return r.nextToken(),r.parseExpression()},xS.tokenizer=function(e,t){return new this(t,e)},Object.defineProperties(xS.prototype,SS);var CS=xS.prototype,wS=/^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;CS.strictDirective=function(e){if(this.options.ecmaVersion<5)return!1;for(;;){zx.lastIndex=e,e+=zx.exec(this.input)[0].length;var t=wS.exec(this.input.slice(e));if(!t)return!1;if((t[1]||t[2])===`use strict`){zx.lastIndex=e+t[0].length;var n=zx.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===`;`||i===`}`||Px.test(n[0])&&!(/[(`.[+\-/*%<>=,?^&]/.test(i)||i===`!`&&this.input.charAt(r+1)===`=`)}e+=t[0].length,zx.lastIndex=e,e+=zx.exec(this.input)[0].length,this.input[e]===`;`&&e++}},CS.eat=function(e){return this.type===e&&(this.next(),!0)},CS.isContextual=function(e){return this.type===K.name&&this.value===e&&!this.containsEsc},CS.eatContextual=function(e){return this.isContextual(e)?(this.next(),!0):!1},CS.catchStackOverflow=function(e){try{return e()}catch(e){if(e instanceof Error&&(/\bstack\b.*\b(exceeded|overflow)\b/i.test(e.message)||/\btoo much recursion\b/i.test(e.message)))this.raise(this.start,`Not enough stack space to parse input`);else throw e}},CS.expectContextual=function(e){this.eatContextual(e)||this.unexpected()},CS.canInsertSemicolon=function(){return this.type===K.eof||this.type===K.braceR||Px.test(this.input.slice(this.lastTokEnd,this.start))},CS.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},CS.semicolon=function(){!this.eat(K.semi)&&!this.insertSemicolon()&&this.unexpected()},CS.afterTrailingComma=function(e,t){if(this.type===e)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),t||this.next(),!0},CS.expect=function(e){this.eat(e)||this.unexpected()},CS.unexpected=function(e){this.raise(e??this.start,`Unexpected token`)};var TS=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};CS.checkPatternErrors=function(e,t){if(e){e.trailingComma>-1&&this.raiseRecoverable(e.trailingComma,`Comma is not permitted after the rest element`);var n=t?e.parenthesizedAssign:e.parenthesizedBind;n>-1&&this.raiseRecoverable(n,t?`Assigning to rvalue`:`Parenthesized pattern`)}},CS.checkExpressionErrors=function(e,t){if(!e)return!1;var n=e.shorthandAssign,r=e.doubleProto;if(!t)return n>=0||r>=0;n>=0&&this.raise(n,`Shorthand property assignments are valid only in destructuring patterns`),r>=0&&this.raiseRecoverable(r,`Redefinition of __proto__ property`)},CS.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,`Yield expression cannot be a default value`),this.awaitPos&&this.raise(this.awaitPos,`Await expression cannot be a default value`)},CS.isSimpleAssignTarget=function(e){return e.type===`ParenthesizedExpression`?this.isSimpleAssignTarget(e.expression):e.type===`Identifier`||e.type===`MemberExpression`};var q=xS.prototype;q.parseTopLevel=function(e){var t=Object.create(null);for(e.body||=[];this.type!==K.eof;){var n=this.parseStatement(null,!0,t);e.body.push(n)}if(this.inModule)for(var r=0,i=Object.keys(this.undefinedExports);r<i.length;r+=1){var a=i[r];this.raiseRecoverable(this.undefinedExports[a].start,`Export '`+a+`' is not defined`)}return this.adaptDirectivePrologue(e.body),this.next(),e.sourceType=this.options.sourceType===`commonjs`?`script`:this.options.sourceType,this.finishNode(e,`Program`)};var ES={kind:`loop`},DS={kind:`switch`};q.isLet=function(e){if(this.options.ecmaVersion<6||!this.isContextual(`let`))return!1;zx.lastIndex=this.pos;var t=zx.exec(this.input),n=this.pos+t[0].length,r=this.fullCharCodeAt(n);if(r===91||r===92)return!0;if(e)return!1;if(r===123)return!0;if(Ox(r)){var i=n;do n+=r<=65535?1:2;while(kx(r=this.fullCharCodeAt(n)));if(r===92)return!0;var a=this.input.slice(i,n);if(!wx.test(a))return!0}return!1},q.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual(`async`))return!1;zx.lastIndex=this.pos;var e=zx.exec(this.input),t=this.pos+e[0].length,n;return!Px.test(this.input.slice(this.pos,t))&&this.input.slice(t,t+8)===`function`&&(t+8===this.input.length||!(kx(n=this.fullCharCodeAt(t+8))||n===92))},q.isUsingKeyword=function(e,t){if(this.options.ecmaVersion<17||!this.isContextual(e?`await`:`using`))return!1;zx.lastIndex=this.pos;var n=zx.exec(this.input),r=this.pos+n[0].length;if(Px.test(this.input.slice(this.pos,r)))return!1;if(e){var i=r+5,a;if(this.input.slice(r,i)!==`using`||i===this.input.length||kx(a=this.fullCharCodeAt(i))||a===92)return!1;zx.lastIndex=i;var o=zx.exec(this.input);if(r=i+o[0].length,o&&Px.test(this.input.slice(i,r)))return!1}var s=this.fullCharCodeAt(r);if(!Ox(s)&&s!==92)return!1;var c=r;do r+=s<=65535?1:2;while(kx(s=this.fullCharCodeAt(r)));if(s===92)return!0;var l=this.input.slice(c,r);if(wx.test(l))return!1;if(t&&!e&&l===`of`){zx.lastIndex=r;var u=zx.exec(this.input);if(r+=u[0].length,this.input.charCodeAt(r)!==61||(s=this.input.charCodeAt(r+1))===61||s===62)return!1}return!0},q.isAwaitUsing=function(e){return this.isUsingKeyword(!0,e)},q.isUsing=function(e){return this.isUsingKeyword(!1,e)},q.parseStatement=function(e,t,n){var r=this.type,i=this.startNode(),a;switch(this.isLet(e)&&(r=K._var,a=`let`),r){case K._break:case K._continue:return this.parseBreakContinueStatement(i,r.keyword);case K._debugger:return this.parseDebuggerStatement(i);case K._do:return this.parseDoStatement(i);case K._for:return this.parseForStatement(i);case K._function:return e&&(this.strict||e!==`if`&&e!==`label`)&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!e);case K._class:return e&&this.unexpected(),this.parseClass(i,!0);case K._if:return this.parseIfStatement(i);case K._return:return this.parseReturnStatement(i);case K._switch:return this.parseSwitchStatement(i);case K._throw:return this.parseThrowStatement(i);case K._try:return this.parseTryStatement(i);case K._const:case K._var:return a||=this.value,e&&a!==`var`&&this.unexpected(),this.parseVarStatement(i,a);case K._while:return this.parseWhileStatement(i);case K._with:return this.parseWithStatement(i);case K.braceL:return this.parseBlock(!0,i);case K.semi:return this.parseEmptyStatement(i);case K._export:case K._import:if(this.options.ecmaVersion>10&&r===K._import){zx.lastIndex=this.pos;var o=zx.exec(this.input),s=this.pos+o[0].length,c=this.input.charCodeAt(s);if(c===40||c===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(t||this.raise(this.start,`'import' and 'export' may only appear at the top level`),this.inModule||this.raise(this.start,`'import' and 'export' may appear only with 'sourceType: module'`)),r===K._import?this.parseImport(i):this.parseExport(i,n);default:if(this.isAsyncFunction())return e&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!e);var l=this.isAwaitUsing(!1)?`await using`:this.isUsing(!1)?`using`:null;if(l)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),e&&this.raise(this.start,`Using declaration is not allowed in single-statement positions`),l===`await using`&&(this.canAwait||this.raise(this.start,`Await using cannot appear outside of async function`),this.next()),this.next(),this.parseVar(i,!1,l),this.semicolon(),this.finishNode(i,`VariableDeclaration`);var u=this.value,d=this.parseExpression();return r===K.name&&d.type===`Identifier`&&this.eat(K.colon)?this.parseLabeledStatement(i,u,d,e):this.parseExpressionStatement(i,d)}},q.parseBreakContinueStatement=function(e,t){var n=t===`break`;this.next(),this.eat(K.semi)||this.insertSemicolon()?e.label=null:this.type===K.name?(e.label=this.parseIdent(),this.semicolon()):this.unexpected();for(var r=0;r<this.labels.length;++r){var i=this.labels[r];if((e.label==null||i.name===e.label.name)&&(i.kind!=null&&(n||i.kind===`loop`)||e.label&&n))break}return r===this.labels.length&&this.raise(e.start,`Unsyntactic `+t),this.finishNode(e,n?`BreakStatement`:`ContinueStatement`)},q.parseDebuggerStatement=function(e){return this.next(),this.semicolon(),this.finishNode(e,`DebuggerStatement`)},q.parseDoStatement=function(e){return this.next(),this.labels.push(ES),e.body=this.parseStatement(`do`),this.labels.pop(),this.expect(K._while),e.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(K.semi):this.semicolon(),this.finishNode(e,`DoWhileStatement`)},q.parseForStatement=function(e){this.next();var t=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual(`await`)?this.lastTokStart:-1;if(this.labels.push(ES),this.enterScope(0),this.expect(K.parenL),this.type===K.semi)return t>-1&&this.unexpected(t),this.parseFor(e,null);var n=this.isLet();if(this.type===K._var||this.type===K._const||n){var r=this.startNode(),i=n?`let`:this.value;return this.next(),this.parseVar(r,!0,i),this.finishNode(r,`VariableDeclaration`),this.parseForAfterInit(e,r,t)}var a=this.isContextual(`let`),o=!1,s=this.isUsing(!0)?`using`:this.isAwaitUsing(!0)?`await using`:null;if(s){var c=this.startNode();return this.next(),s===`await using`&&(this.canAwait||this.raise(this.start,`Await using cannot appear outside of async function`),this.next()),this.parseVar(c,!0,s),this.finishNode(c,`VariableDeclaration`),this.parseForAfterInit(e,c,t)}var l=this.containsEsc,u=new TS,d=this.start,f=t>-1?this.parseExprSubscripts(u,`await`):this.parseExpression(!0,u);return this.type===K._in||(o=this.options.ecmaVersion>=6&&this.isContextual(`of`))?(t>-1?(this.type===K._in&&this.unexpected(t),e.await=!0):o&&this.options.ecmaVersion>=8&&(f.start===d&&!l&&f.type===`Identifier`&&f.name===`async`?this.unexpected():this.options.ecmaVersion>=9&&(e.await=!1)),a&&o&&this.raise(f.start,`The left-hand side of a for-of loop may not start with 'let'.`),this.toAssignable(f,!1,u),this.checkLValPattern(f),this.parseForIn(e,f)):(this.checkExpressionErrors(u,!0),t>-1&&this.unexpected(t),this.parseFor(e,f))},q.parseForAfterInit=function(e,t,n){return(this.type===K._in||this.options.ecmaVersion>=6&&this.isContextual(`of`))&&t.declarations.length===1?(this.type===K._in?((t.kind===`using`||t.kind===`await using`)&&!t.declarations[0].init&&this.raise(this.start,`Using declaration is not allowed in for-in loops`),this.options.ecmaVersion>=9&&n>-1&&this.unexpected(n)):this.options.ecmaVersion>=9&&(e.await=n>-1),this.parseForIn(e,t)):(n>-1&&this.unexpected(n),this.parseFor(e,t))},q.parseFunctionStatement=function(e,t,n){return this.next(),this.parseFunction(e,kS|(n?0:AS),!1,t)},q.parseIfStatement=function(e){return this.next(),e.test=this.parseParenExpression(),e.consequent=this.parseStatement(`if`),e.alternate=this.eat(K._else)?this.parseStatement(`if`):null,this.finishNode(e,`IfStatement`)},q.parseReturnStatement=function(e){return this.allowReturn||this.raise(this.start,`'return' outside of function`),this.next(),this.eat(K.semi)||this.insertSemicolon()?e.argument=null:(e.argument=this.parseExpression(),this.semicolon()),this.finishNode(e,`ReturnStatement`)},q.parseSwitchStatement=function(e){this.next(),e.discriminant=this.parseParenExpression(),e.cases=[],this.expect(K.braceL),this.labels.push(DS),this.enterScope(fS);for(var t,n=!1;this.type!==K.braceR;)if(this.type===K._case||this.type===K._default){var r=this.type===K._case;t&&this.finishNode(t,`SwitchCase`),e.cases.push(t=this.startNode()),t.consequent=[],this.next(),r?t.test=this.parseExpression():(n&&this.raiseRecoverable(this.lastTokStart,`Multiple default clauses`),n=!0,t.test=null),this.expect(K.colon)}else t||this.unexpected(),t.consequent.push(this.parseStatement(null));return this.exitScope(),t&&this.finishNode(t,`SwitchCase`),this.next(),this.labels.pop(),this.finishNode(e,`SwitchStatement`)},q.parseThrowStatement=function(e){return this.next(),Px.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,`Illegal newline after throw`),e.argument=this.parseExpression(),this.semicolon(),this.finishNode(e,`ThrowStatement`)};var OS=[];q.parseCatchClauseParam=function(){var e=this.parseBindingAtom(),t=e.type===`Identifier`;return this.enterScope(t?sS:0),this.checkLValPattern(e,t?yS:_S),this.expect(K.parenR),e},q.parseTryStatement=function(e){if(this.next(),e.block=this.parseBlock(),e.handler=null,this.type===K._catch){var t=this.startNode();this.next(),this.eat(K.parenL)?t.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),t.param=null,this.enterScope(0)),t.body=this.parseBlock(!1),this.exitScope(),e.handler=this.finishNode(t,`CatchClause`)}return e.finalizer=this.eat(K._finally)?this.parseBlock():null,!e.handler&&!e.finalizer&&this.raise(e.start,`Missing catch or finally clause`),this.finishNode(e,`TryStatement`)},q.parseVarStatement=function(e,t,n){return this.next(),this.parseVar(e,!1,t,n),this.semicolon(),this.finishNode(e,`VariableDeclaration`)},q.parseWhileStatement=function(e){return this.next(),e.test=this.parseParenExpression(),this.labels.push(ES),e.body=this.parseStatement(`while`),this.labels.pop(),this.finishNode(e,`WhileStatement`)},q.parseWithStatement=function(e){return this.strict&&this.raise(this.start,`'with' in strict mode`),this.next(),e.object=this.parseParenExpression(),e.body=this.parseStatement(`with`),this.finishNode(e,`WithStatement`)},q.parseEmptyStatement=function(e){return this.next(),this.finishNode(e,`EmptyStatement`)},q.parseLabeledStatement=function(e,t,n,r){for(var i=0,a=this.labels;i<a.length;i+=1)a[i].name===t&&this.raise(n.start,`Label '`+t+`' is already declared`);for(var o=this.type.isLoop?`loop`:this.type===K._switch?`switch`:null,s=this.labels.length-1;s>=0;s--){var c=this.labels[s];if(c.statementStart===e.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:t,kind:o,statementStart:this.start}),e.body=this.parseStatement(r?r.indexOf(`label`)===-1?r+`label`:r:`label`),this.labels.pop(),e.label=n,this.finishNode(e,`LabeledStatement`)},q.parseExpressionStatement=function(e,t){return e.expression=t,this.semicolon(),this.finishNode(e,`ExpressionStatement`)},q.parseBlock=function(e,t,n){for(e===void 0&&(e=!0),t===void 0&&(t=this.startNode()),t.body=[],this.expect(K.braceL),e&&this.enterScope(0);this.type!==K.braceR;){var r=this.parseStatement(null);t.body.push(r)}return n&&(this.strict=!1),this.next(),e&&this.exitScope(),this.finishNode(t,`BlockStatement`)},q.parseFor=function(e,t){return e.init=t,this.expect(K.semi),e.test=this.type===K.semi?null:this.parseExpression(),this.expect(K.semi),e.update=this.type===K.parenR?null:this.parseExpression(),this.expect(K.parenR),e.body=this.parseStatement(`for`),this.exitScope(),this.labels.pop(),this.finishNode(e,`ForStatement`)},q.parseForIn=function(e,t){var n=this.type===K._in;return this.next(),t.type===`VariableDeclaration`&&t.declarations[0].init!=null&&(!n||this.options.ecmaVersion<8||this.strict||t.kind!==`var`||t.declarations[0].id.type!==`Identifier`)&&this.raise(t.start,(n?`for-in`:`for-of`)+` loop variable declaration may not have an initializer`),e.left=t,e.right=n?this.parseExpression():this.parseMaybeAssign(),this.expect(K.parenR),e.body=this.parseStatement(`for`),this.exitScope(),this.labels.pop(),this.finishNode(e,n?`ForInStatement`:`ForOfStatement`)},q.parseVar=function(e,t,n,r){for(e.declarations=[],e.kind=n;;){var i=this.startNode();if(this.parseVarId(i,n),this.eat(K.eq)?i.init=this.parseMaybeAssign(t):!r&&n===`const`&&!(this.type===K._in||this.options.ecmaVersion>=6&&this.isContextual(`of`))?this.unexpected():!r&&(n===`using`||n===`await using`)&&this.options.ecmaVersion>=17&&this.type!==K._in&&!this.isContextual(`of`)?this.raise(this.lastTokEnd,`Missing initializer in `+n+` declaration`):!r&&i.id.type!==`Identifier`&&!(t&&(this.type===K._in||this.isContextual(`of`)))?this.raise(this.lastTokEnd,`Complex binding patterns require an initialization value`):i.init=null,e.declarations.push(this.finishNode(i,`VariableDeclarator`)),!this.eat(K.comma))break}return e},q.parseVarId=function(e,t){e.id=t===`using`||t===`await using`?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(e.id,t===`var`?gS:_S,!1)};var kS=1,AS=2,jS=4;q.parseFunction=function(e,t,n,r,i){this.initFunction(e),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===K.star&&t&AS&&this.unexpected(),e.generator=this.eat(K.star)),this.options.ecmaVersion>=8&&(e.async=!!r),t&kS&&(e.id=t&jS&&this.type!==K.name?null:this.parseIdent(),e.id&&!(t&AS)&&this.checkLValSimple(e.id,this.strict||e.generator||e.async?this.treatFunctionsAsVar?gS:_S:vS));var a=this.yieldPos,o=this.awaitPos,s=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(mS(e.async,e.generator)),t&kS||(e.id=this.type===K.name?this.parseIdent():null),this.parseFunctionParams(e),this.parseFunctionBody(e,n,!1,i),this.yieldPos=a,this.awaitPos=o,this.awaitIdentPos=s,this.finishNode(e,t&kS?`FunctionDeclaration`:`FunctionExpression`)},q.parseFunctionParams=function(e){this.expect(K.parenL),e.params=this.parseBindingList(K.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()},q.parseClass=function(e,t){this.next();var n=this.strict;this.strict=!0,this.parseClassId(e,t),this.parseClassSuper(e);var r=this.enterClassBody(),i=this.startNode(),a=!1;for(i.body=[],this.expect(K.braceL);this.type!==K.braceR;){var o=this.parseClassElement(e.superClass!==null);o&&(i.body.push(o),o.type===`MethodDefinition`&&o.kind===`constructor`?(a&&this.raiseRecoverable(o.start,`Duplicate constructor in the same class`),a=!0):o.key&&o.key.type===`PrivateIdentifier`&&MS(r,o)&&this.raiseRecoverable(o.key.start,`Identifier '#`+o.key.name+`' has already been declared`))}return this.strict=n,this.next(),e.body=this.finishNode(i,`ClassBody`),this.exitClassBody(),this.finishNode(e,t?`ClassDeclaration`:`ClassExpression`)},q.parseClassElement=function(e){if(this.eat(K.semi))return null;var t=this.options.ecmaVersion,n=this.startNode(),r=``,i=!1,a=!1,o=`method`,s=!1;if(this.eatContextual(`static`)){if(t>=13&&this.eat(K.braceL))return this.parseClassStaticBlock(n),n;this.isClassElementNameStart()||this.type===K.star?s=!0:r=`static`}if(n.static=s,!r&&t>=8&&this.eatContextual(`async`)&&((this.isClassElementNameStart()||this.type===K.star)&&!this.canInsertSemicolon()?a=!0:r=`async`),!r&&(t>=9||!a)&&this.eat(K.star)&&(i=!0),!r&&!a&&!i){var c=this.value;(this.eatContextual(`get`)||this.eatContextual(`set`))&&(this.isClassElementNameStart()?o=c:r=c)}if(r?(n.computed=!1,n.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),n.key.name=r,this.finishNode(n.key,`Identifier`)):this.parseClassElementName(n),t<13||this.type===K.parenL||o!==`method`||i||a){var l=!n.static&&NS(n,`constructor`),u=l&&e;l&&o!==`method`&&this.raise(n.key.start,`Constructor can't have get/set modifier`),n.kind=l?`constructor`:o,this.parseClassMethod(n,i,a,u)}else this.parseClassField(n);return n},q.isClassElementNameStart=function(){return this.type===K.name||this.type===K.privateId||this.type===K.num||this.type===K.string||this.type===K.bracketL||this.type.keyword},q.parseClassElementName=function(e){this.type===K.privateId?(this.value===`constructor`&&this.raise(this.start,`Classes can't have an element named '#constructor'`),e.computed=!1,e.key=this.parsePrivateIdent()):this.parsePropertyName(e)},q.parseClassMethod=function(e,t,n,r){var i=e.key;e.kind===`constructor`?(t&&this.raise(i.start,`Constructor can't be a generator`),n&&this.raise(i.start,`Constructor can't be an async method`)):e.static&&NS(e,`prototype`)&&this.raise(i.start,`Classes may not have a static property named prototype`);var a=e.value=this.parseMethod(t,n,r);return e.kind===`get`&&a.params.length!==0&&this.raiseRecoverable(a.start,`getter should have no params`),e.kind===`set`&&a.params.length!==1&&this.raiseRecoverable(a.start,`setter should have exactly one param`),e.kind===`set`&&a.params[0].type===`RestElement`&&this.raiseRecoverable(a.params[0].start,`Setter cannot use rest params`),this.finishNode(e,`MethodDefinition`)},q.parseClassField=function(e){return NS(e,`constructor`)?this.raise(e.key.start,`Classes can't have a field named 'constructor'`):e.static&&NS(e,`prototype`)&&this.raise(e.key.start,`Classes can't have a static field named 'prototype'`),this.eat(K.eq)?(this.enterScope(dS|cS),e.value=this.parseMaybeAssign(),this.exitScope()):e.value=null,this.semicolon(),this.finishNode(e,`PropertyDefinition`)},q.parseClassStaticBlock=function(e){e.body=[];var t=this.labels;for(this.labels=[],this.enterScope(uS|cS);this.type!==K.braceR;){var n=this.parseStatement(null);e.body.push(n)}return this.next(),this.exitScope(),this.labels=t,this.finishNode(e,`StaticBlock`)},q.parseClassId=function(e,t){this.type===K.name?(e.id=this.parseIdent(),t&&this.checkLValSimple(e.id,_S,!1)):(t===!0&&this.unexpected(),e.id=null)},q.parseClassSuper=function(e){e.superClass=this.eat(K._extends)?this.parseExprSubscripts(null,!1):null},q.enterClassBody=function(){var e={declared:Object.create(null),used:[]};return this.privateNameStack.push(e),e.declared},q.exitClassBody=function(){var e=this.privateNameStack.pop(),t=e.declared,n=e.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,i=r===0?null:this.privateNameStack[r-1],a=0;a<n.length;++a){var o=n[a];Ux(t,o.name)||(i?i.used.push(o):this.raiseRecoverable(o.start,`Private field '#`+o.name+`' must be declared in an enclosing class`))}};function MS(e,t){var n=t.key.name,r=e[n],i=`true`;return t.type===`MethodDefinition`&&(t.kind===`get`||t.kind===`set`)&&(i=(t.static?`s`:`i`)+t.kind),r===`iget`&&i===`iset`||r===`iset`&&i===`iget`||r===`sget`&&i===`sset`||r===`sset`&&i===`sget`?(e[n]=`true`,!1):r?!0:(e[n]=i,!1)}function NS(e,t){var n=e.computed,r=e.key;return!n&&(r.type===`Identifier`&&r.name===t||r.type===`Literal`&&r.value===t)}q.parseExportAllDeclaration=function(e,t){return this.options.ecmaVersion>=11&&(this.eatContextual(`as`)?(e.exported=this.parseModuleExportName(),this.checkExport(t,e.exported,this.lastTokStart)):e.exported=null),this.expectContextual(`from`),this.type!==K.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,`ExportAllDeclaration`)},q.parseExport=function(e,t){if(this.next(),this.eat(K.star))return this.parseExportAllDeclaration(e,t);if(this.eat(K._default))return this.checkExport(t,`default`,this.lastTokStart),e.declaration=this.parseExportDefaultDeclaration(),this.finishNode(e,`ExportDefaultDeclaration`);if(this.shouldParseExportStatement())e.declaration=this.parseExportDeclaration(e),e.declaration.type===`VariableDeclaration`?this.checkVariableExport(t,e.declaration.declarations):this.checkExport(t,e.declaration.id,e.declaration.id.start),e.specifiers=[],e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[]);else{if(e.declaration=null,e.specifiers=this.parseExportSpecifiers(t),this.eatContextual(`from`))this.type!==K.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause());else{for(var n=0,r=e.specifiers;n<r.length;n+=1){var i=r[n];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type===`Literal`&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[])}this.semicolon()}return this.finishNode(e,`ExportNamedDeclaration`)},q.parseExportDeclaration=function(e){return this.parseStatement(null)},q.parseExportDefaultDeclaration=function(){var e;if(this.type===K._function||(e=this.isAsyncFunction())){var t=this.startNode();return this.next(),e&&this.next(),this.parseFunction(t,kS|jS,!1,e)}if(this.type===K._class){var n=this.startNode();return this.parseClass(n,`nullableID`)}var r=this.parseMaybeAssign();return this.semicolon(),r},q.checkExport=function(e,t,n){e&&(typeof t!=`string`&&(t=t.type===`Identifier`?t.name:t.value),Ux(e,t)&&this.raiseRecoverable(n,`Duplicate export '`+t+`'`),e[t]=!0)},q.checkPatternExport=function(e,t){var n=t.type;if(n===`Identifier`)this.checkExport(e,t,t.start);else if(n===`ObjectPattern`)for(var r=0,i=t.properties;r<i.length;r+=1){var a=i[r];this.checkPatternExport(e,a)}else if(n===`ArrayPattern`)for(var o=0,s=t.elements;o<s.length;o+=1){var c=s[o];c&&this.checkPatternExport(e,c)}else n===`Property`?this.checkPatternExport(e,t.value):n===`AssignmentPattern`?this.checkPatternExport(e,t.left):n===`RestElement`&&this.checkPatternExport(e,t.argument)},q.checkVariableExport=function(e,t){if(e)for(var n=0,r=t;n<r.length;n+=1){var i=r[n];this.checkPatternExport(e,i.id)}},q.shouldParseExportStatement=function(){return this.type.keyword===`var`||this.type.keyword===`const`||this.type.keyword===`class`||this.type.keyword===`function`||this.isLet()||this.isAsyncFunction()},q.parseExportSpecifier=function(e){var t=this.startNode();return t.local=this.parseModuleExportName(),t.exported=this.eatContextual(`as`)?this.parseModuleExportName():t.local,this.checkExport(e,t.exported,t.exported.start),this.finishNode(t,`ExportSpecifier`)},q.parseExportSpecifiers=function(e){var t=[],n=!0;for(this.expect(K.braceL);!this.eat(K.braceR);){if(n)n=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;t.push(this.parseExportSpecifier(e))}return t},q.parseImport=function(e){return this.next(),this.type===K.string?(e.specifiers=OS,e.source=this.parseExprAtom()):(e.specifiers=this.parseImportSpecifiers(),this.expectContextual(`from`),e.source=this.type===K.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,`ImportDeclaration`)},q.parseImportSpecifier=function(){var e=this.startNode();return e.imported=this.parseModuleExportName(),this.eatContextual(`as`)?e.local=this.parseIdent():(this.checkUnreserved(e.imported),e.local=e.imported),this.checkLValSimple(e.local,_S),this.finishNode(e,`ImportSpecifier`)},q.parseImportDefaultSpecifier=function(){var e=this.startNode();return e.local=this.parseIdent(),this.checkLValSimple(e.local,_S),this.finishNode(e,`ImportDefaultSpecifier`)},q.parseImportNamespaceSpecifier=function(){var e=this.startNode();return this.next(),this.expectContextual(`as`),e.local=this.parseIdent(),this.checkLValSimple(e.local,_S),this.finishNode(e,`ImportNamespaceSpecifier`)},q.parseImportSpecifiers=function(){var e=[],t=!0;if(this.type===K.name&&(e.push(this.parseImportDefaultSpecifier()),!this.eat(K.comma)))return e;if(this.type===K.star)return e.push(this.parseImportNamespaceSpecifier()),e;for(this.expect(K.braceL);!this.eat(K.braceR);){if(t)t=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;e.push(this.parseImportSpecifier())}return e},q.parseWithClause=function(){var e=[];if(!this.eat(K._with))return e;this.expect(K.braceL);for(var t={},n=!0;!this.eat(K.braceR);){if(n)n=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;var r=this.parseImportAttribute(),i=r.key.type===`Identifier`?r.key.name:r.key.value;Ux(t,i)&&this.raiseRecoverable(r.key.start,`Duplicate attribute key '`+i+`'`),t[i]=!0,e.push(r)}return e},q.parseImportAttribute=function(){var e=this.startNode();return e.key=this.type===K.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!==`never`),this.expect(K.colon),this.type!==K.string&&this.unexpected(),e.value=this.parseExprAtom(),this.finishNode(e,`ImportAttribute`)},q.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===K.string){var e=this.parseLiteral(this.value);return Jx.test(e.value)&&this.raise(e.start,`An export name cannot include a lone surrogate.`),e}return this.parseIdent(!0)},q.adaptDirectivePrologue=function(e){for(var t=0;t<e.length&&this.isDirectiveCandidate(e[t]);++t)e[t].directive=e[t].expression.raw.slice(1,-1)},q.isDirectiveCandidate=function(e){return this.options.ecmaVersion>=5&&e.type===`ExpressionStatement`&&e.expression.type===`Literal`&&typeof e.expression.value==`string`&&(this.input[e.start]===`"`||this.input[e.start]===`'`)};var PS=xS.prototype;PS.toAssignable=function(e,t,n){if(this.options.ecmaVersion>=6&&e)switch(e.type){case`Identifier`:this.inAsync&&e.name===`await`&&this.raise(e.start,`Cannot use 'await' as identifier inside an async function`);break;case`ObjectPattern`:case`ArrayPattern`:case`AssignmentPattern`:case`RestElement`:break;case`ObjectExpression`:e.type=`ObjectPattern`,n&&this.checkPatternErrors(n,!0);for(var r=0,i=e.properties;r<i.length;r+=1){var a=i[r];this.toAssignable(a,t),a.type===`RestElement`&&(a.argument.type===`ArrayPattern`||a.argument.type===`ObjectPattern`)&&this.raise(a.argument.start,`Unexpected token`)}break;case`Property`:e.kind!==`init`&&this.raise(e.key.start,`Object pattern can't contain getter or setter`),this.toAssignable(e.value,t);break;case`ArrayExpression`:e.type=`ArrayPattern`,n&&this.checkPatternErrors(n,!0),this.toAssignableList(e.elements,t);break;case`SpreadElement`:e.type=`RestElement`,this.toAssignable(e.argument,t),e.argument.type===`AssignmentPattern`&&this.raise(e.argument.start,`Rest elements cannot have a default value`);break;case`AssignmentExpression`:e.operator!==`=`&&this.raise(e.left.end,`Only '=' operator can be used for specifying default value.`),e.type=`AssignmentPattern`,delete e.operator,this.toAssignable(e.left,t);break;case`ParenthesizedExpression`:this.toAssignable(e.expression,t,n);break;case`ChainExpression`:this.raiseRecoverable(e.start,`Optional chaining cannot appear in left-hand side`);break;case`MemberExpression`:if(!t)break;default:this.raise(e.start,`Assigning to rvalue`)}else n&&this.checkPatternErrors(n,!0);return e},PS.toAssignableList=function(e,t){for(var n=e.length,r=0;r<n;r++){var i=e[r];i&&this.toAssignable(i,t)}if(n){var a=e[n-1];this.options.ecmaVersion===6&&t&&a&&a.type===`RestElement`&&a.argument.type!==`Identifier`&&this.unexpected(a.argument.start)}return e},PS.parseSpread=function(e){var t=this.startNode();return this.next(),t.argument=this.parseMaybeAssign(!1,e),this.finishNode(t,`SpreadElement`)},PS.parseRestBinding=function(){var e=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==K.name&&this.unexpected(),e.argument=this.parseBindingAtom(),this.finishNode(e,`RestElement`)},PS.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case K.bracketL:var e=this.startNode();return this.next(),e.elements=this.parseBindingList(K.bracketR,!0,!0),this.finishNode(e,`ArrayPattern`);case K.braceL:return this.parseObj(!0)}return this.parseIdent()},PS.parseBindingList=function(e,t,n,r){for(var i=[],a=!0;!this.eat(e);)if(a?a=!1:this.expect(K.comma),t&&this.type===K.comma)i.push(null);else if(n&&this.afterTrailingComma(e))break;else if(this.type===K.ellipsis){var o=this.parseRestBinding();this.parseBindingListItem(o),i.push(o),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`),this.expect(e);break}else i.push(this.parseAssignableListItem(r));return i},PS.parseAssignableListItem=function(e){var t=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(t),t},PS.parseBindingListItem=function(e){return e},PS.parseMaybeDefault=function(e,t,n){if(n||=this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(K.eq))return n;var r=this.startNodeAt(e,t);return r.left=n,r.right=this.parseMaybeAssign(),this.finishNode(r,`AssignmentPattern`)},PS.checkLValSimple=function(e,t,n){t===void 0&&(t=hS);var r=t!==hS;switch(e.type){case`Identifier`:this.strict&&this.reservedWordsStrictBind.test(e.name)&&this.raiseRecoverable(e.start,(r?`Binding `:`Assigning to `)+e.name+` in strict mode`),r&&(t===_S&&e.name===`let`&&this.raiseRecoverable(e.start,`let is disallowed as a lexically bound name`),n&&(Ux(n,e.name)&&this.raiseRecoverable(e.start,`Argument name clash`),n[e.name]=!0),t!==bS&&this.declareName(e.name,t,e.start));break;case`ChainExpression`:this.raiseRecoverable(e.start,`Optional chaining cannot appear in left-hand side`);break;case`MemberExpression`:r&&this.raiseRecoverable(e.start,`Binding member expression`);break;case`ParenthesizedExpression`:return r&&this.raiseRecoverable(e.start,`Binding parenthesized expression`),this.checkLValSimple(e.expression,t,n);default:this.raise(e.start,(r?`Binding`:`Assigning to`)+` rvalue`)}},PS.checkLValPattern=function(e,t,n){switch(t===void 0&&(t=hS),e.type){case`ObjectPattern`:for(var r=0,i=e.properties;r<i.length;r+=1){var a=i[r];this.checkLValInnerPattern(a,t,n)}break;case`ArrayPattern`:for(var o=0,s=e.elements;o<s.length;o+=1){var c=s[o];c&&this.checkLValInnerPattern(c,t,n)}break;default:this.checkLValSimple(e,t,n)}},PS.checkLValInnerPattern=function(e,t,n){switch(t===void 0&&(t=hS),e.type){case`Property`:this.checkLValInnerPattern(e.value,t,n);break;case`AssignmentPattern`:this.checkLValPattern(e.left,t,n);break;case`RestElement`:this.checkLValPattern(e.argument,t,n);break;default:this.checkLValPattern(e,t,n)}};var FS=function(e,t,n,r,i){this.token=e,this.isExpr=!!t,this.preserveSpace=!!n,this.override=r,this.generator=!!i},IS={b_stat:new FS(`{`,!1),b_expr:new FS(`{`,!0),b_tmpl:new FS("${",!1),p_stat:new FS(`(`,!1),p_expr:new FS(`(`,!0),q_tmpl:new FS("`",!0,!0,function(e){return e.tryReadTemplateToken()}),f_stat:new FS(`function`,!1),f_expr:new FS(`function`,!0),f_expr_gen:new FS(`function`,!0,!1,null,!0),f_gen:new FS(`function`,!1,!1,null,!0)},LS=xS.prototype;LS.initialContext=function(){return[IS.b_stat]},LS.curContext=function(){return this.context[this.context.length-1]},LS.braceIsBlock=function(e){var t=this.curContext();return t===IS.f_expr||t===IS.f_stat?!0:e===K.colon&&(t===IS.b_stat||t===IS.b_expr)?!t.isExpr:e===K._return||e===K.name&&this.exprAllowed?Px.test(this.input.slice(this.lastTokEnd,this.start)):e===K._else||e===K.semi||e===K.eof||e===K.parenR||e===K.arrow?!0:e===K.braceL?t===IS.b_stat:e===K._var||e===K._const||e===K.name?!1:!this.exprAllowed},LS.inGeneratorContext=function(){for(var e=this.context.length-1;e>=1;e--){var t=this.context[e];if(t.token===`function`)return t.generator}return!1},LS.updateContext=function(e){var t,n=this.type;n.keyword&&e===K.dot?this.exprAllowed=!1:(t=n.updateContext)?t.call(this,e):this.exprAllowed=n.beforeExpr},LS.overrideContext=function(e){this.curContext()!==e&&(this.context[this.context.length-1]=e)},K.parenR.updateContext=K.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var e=this.context.pop();e===IS.b_stat&&this.curContext().token===`function`&&(e=this.context.pop()),this.exprAllowed=!e.isExpr},K.braceL.updateContext=function(e){this.context.push(this.braceIsBlock(e)?IS.b_stat:IS.b_expr),this.exprAllowed=!0},K.dollarBraceL.updateContext=function(){this.context.push(IS.b_tmpl),this.exprAllowed=!0},K.parenL.updateContext=function(e){var t=e===K._if||e===K._for||e===K._with||e===K._while;this.context.push(t?IS.p_stat:IS.p_expr),this.exprAllowed=!0},K.incDec.updateContext=function(){},K._function.updateContext=K._class.updateContext=function(e){e.beforeExpr&&e!==K._else&&(e!==K.semi||this.curContext()===IS.p_stat)&&!(e===K._return&&Px.test(this.input.slice(this.lastTokEnd,this.start)))&&(e!==K.colon&&e!==K.braceL||this.curContext()!==IS.b_stat)?this.context.push(IS.f_expr):this.context.push(IS.f_stat),this.exprAllowed=!1},K.colon.updateContext=function(){this.curContext().token===`function`&&this.context.pop(),this.exprAllowed=!0},K.backQuote.updateContext=function(){this.curContext()===IS.q_tmpl?this.context.pop():this.context.push(IS.q_tmpl),this.exprAllowed=!1},K.star.updateContext=function(e){if(e===K._function){var t=this.context.length-1;this.context[t]===IS.f_expr?this.context[t]=IS.f_expr_gen:this.context[t]=IS.f_gen}this.exprAllowed=!0},K.name.updateContext=function(e){var t=!1;this.options.ecmaVersion>=6&&e!==K.dot&&(this.value===`of`&&!this.exprAllowed||this.value===`yield`&&this.inGeneratorContext())&&(t=!0),this.exprAllowed=t};var J=xS.prototype;J.checkPropClash=function(e,t,n){if(!(this.options.ecmaVersion>=9&&e.type===`SpreadElement`)&&!(this.options.ecmaVersion>=6&&(e.computed||e.method||e.shorthand))){var r=e.key,i;switch(r.type){case`Identifier`:i=r.name;break;case`Literal`:i=String(r.value);break;default:return}var a=e.kind;if(this.options.ecmaVersion>=6){i===`__proto__`&&a===`init`&&(t.proto&&(n?n.doubleProto<0&&(n.doubleProto=r.start):this.raiseRecoverable(r.start,`Redefinition of __proto__ property`)),t.proto=!0);return}i=`$`+i;var o=t[i];o?(a===`init`?this.strict&&o.init||o.get||o.set:o.init||o[a])&&this.raiseRecoverable(r.start,`Redefinition of property`):o=t[i]={init:!1,get:!1,set:!1},o[a]=!0}},J.parseExpression=function(e,t){var n=this;return this.catchStackOverflow(function(){var r=n.start,i=n.startLoc,a=n.parseMaybeAssign(e,t);if(n.type===K.comma){var o=n.startNodeAt(r,i);for(o.expressions=[a];n.eat(K.comma);)o.expressions.push(n.parseMaybeAssign(e,t));return n.finishNode(o,`SequenceExpression`)}return a})},J.parseMaybeAssign=function(e,t,n){if(this.isContextual(`yield`)){if(this.inGenerator)return this.parseYield(e);this.exprAllowed=!1}var r=!1,i=-1,a=-1,o=-1;t?(i=t.parenthesizedAssign,a=t.trailingComma,o=t.doubleProto,t.parenthesizedAssign=t.trailingComma=-1):(t=new TS,r=!0);var s=this.start,c=this.startLoc;(this.type===K.parenL||this.type===K.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=e===`await`);var l=this.parseMaybeConditional(e,t);if(n&&(l=n.call(this,l,s,c)),this.type.isAssign){var u=this.startNodeAt(s,c);return u.operator=this.value,this.type===K.eq&&(l=this.toAssignable(l,!1,t)),r||(t.parenthesizedAssign=t.trailingComma=t.doubleProto=-1),t.shorthandAssign>=l.start&&(t.shorthandAssign=-1),this.type===K.eq?this.checkLValPattern(l):this.checkLValSimple(l),u.left=l,this.next(),u.right=this.parseMaybeAssign(e),o>-1&&(t.doubleProto=o),this.finishNode(u,`AssignmentExpression`)}return r&&this.checkExpressionErrors(t,!0),i>-1&&(t.parenthesizedAssign=i),a>-1&&(t.trailingComma=a),l},J.parseMaybeConditional=function(e,t){var n=this.start,r=this.startLoc,i=this.parseExprOps(e,t);if(this.checkExpressionErrors(t))return i;if((i.type!==`ArrowFunctionExpression`||i.start!==n)&&this.eat(K.question)){var a=this.startNodeAt(n,r);return a.test=i,a.consequent=this.parseMaybeAssign(),this.expect(K.colon),a.alternate=this.parseMaybeAssign(e),this.finishNode(a,`ConditionalExpression`)}return i},J.parseExprOps=function(e,t){var n=this.start,r=this.startLoc,i=this.parseMaybeUnary(t,!1,!1,e);return this.checkExpressionErrors(t)||i.start===n&&i.type===`ArrowFunctionExpression`?i:this.parseExprOp(i,n,r,-1,e)},J.parseExprOp=function(e,t,n,r,i){var a=this.type.binop;if(a!=null&&(!i||this.type!==K._in)&&a>r){var o=this.type===K.logicalOR||this.type===K.logicalAND,s=this.type===K.coalesce;s&&(a=K.logicalAND.binop);var c=this.value;this.next();var l=this.start,u=this.startLoc,d=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),l,u,a,i),f=this.buildBinary(t,n,e,d,c,o||s);return(o&&this.type===K.coalesce||s&&(this.type===K.logicalOR||this.type===K.logicalAND))&&this.raiseRecoverable(this.start,`Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses`),this.parseExprOp(f,t,n,r,i)}return e},J.buildBinary=function(e,t,n,r,i,a){r.type===`PrivateIdentifier`&&this.raise(r.start,`Private identifier can only be left side of binary expression`);var o=this.startNodeAt(e,t);return o.left=n,o.operator=i,o.right=r,this.finishNode(o,a?`LogicalExpression`:`BinaryExpression`)},J.parseMaybeUnary=function(e,t,n,r){var i=this.start,a=this.startLoc,o;if(this.isContextual(`await`)&&this.canAwait)o=this.parseAwait(r),t=!0;else if(this.type.prefix){var s=this.startNode(),c=this.type===K.incDec;s.operator=this.value,s.prefix=!0,this.next(),s.argument=this.parseMaybeUnary(null,!0,c,r),this.checkExpressionErrors(e,!0),c?this.checkLValSimple(s.argument):this.strict&&s.operator===`delete`&&RS(s.argument)?this.raiseRecoverable(s.start,`Deleting local variable in strict mode`):s.operator===`delete`&&zS(s.argument)?this.raiseRecoverable(s.start,`Private fields can not be deleted`):t=!0,o=this.finishNode(s,c?`UpdateExpression`:`UnaryExpression`)}else if(!t&&this.type===K.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),o=this.parsePrivateIdent(),this.type!==K._in&&this.unexpected();else{if(o=this.parseExprSubscripts(e,r),this.checkExpressionErrors(e))return o;for(;this.type.postfix&&!this.canInsertSemicolon();){var l=this.startNodeAt(i,a);l.operator=this.value,l.prefix=!1,l.argument=o,this.checkLValSimple(o),this.next(),o=this.finishNode(l,`UpdateExpression`)}}if(!n&&(o.type!==`ArrowFunctionExpression`||o.start!==i)&&this.eat(K.starstar)){if(t)this.unexpected(this.lastTokStart);else return this.buildBinary(i,a,o,this.parseMaybeUnary(null,!1,!1,r),`**`,!1)}else return o};function RS(e){return e.type===`Identifier`||e.type===`ParenthesizedExpression`&&RS(e.expression)}function zS(e){return e.type===`MemberExpression`&&e.property.type===`PrivateIdentifier`||e.type===`ChainExpression`&&zS(e.expression)||e.type===`ParenthesizedExpression`&&zS(e.expression)}J.parseExprSubscripts=function(e,t){var n=this.start,r=this.startLoc,i=this.parseExprAtom(e,t);if(i.type===`ArrowFunctionExpression`&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==`)`)return i;var a=this.parseSubscripts(i,n,r,!1,t);return e&&a.type===`MemberExpression`&&(e.parenthesizedAssign>=a.start&&(e.parenthesizedAssign=-1),e.parenthesizedBind>=a.start&&(e.parenthesizedBind=-1),e.trailingComma>=a.start&&(e.trailingComma=-1)),a},J.parseSubscripts=function(e,t,n,r,i){for(var a=this.options.ecmaVersion>=8&&e.type===`Identifier`&&e.name===`async`&&this.lastTokEnd===e.end&&!this.canInsertSemicolon()&&e.end-e.start===5&&this.potentialArrowAt===e.start,o=!1;;){var s=this.parseSubscript(e,t,n,r,a,o,i);if(s.optional&&(o=!0),s===e||s.type===`ArrowFunctionExpression`){if(o){var c=this.startNodeAt(t,n);c.expression=s,s=this.finishNode(c,`ChainExpression`)}return s}e=s}},J.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(K.arrow)},J.parseSubscriptAsyncArrow=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!0,r)},J.parseSubscript=function(e,t,n,r,i,a,o){var s=this.options.ecmaVersion>=11,c=s&&this.eat(K.questionDot);r&&c&&this.raise(this.lastTokStart,`Optional chaining cannot appear in the callee of new expressions`);var l=this.eat(K.bracketL);if(l||c&&this.type!==K.parenL&&this.type!==K.backQuote||this.eat(K.dot)){var u=this.startNodeAt(t,n);u.object=e,l?(u.property=this.parseExpression(),this.expect(K.bracketR)):u.property=this.type===K.privateId&&e.type!==`Super`?this.parsePrivateIdent():this.parseIdent(this.options.allowReserved!==`never`),u.computed=!!l,s&&(u.optional=c),e=this.finishNode(u,`MemberExpression`)}else if(!r&&this.eat(K.parenL)){var d=new TS,f=this.yieldPos,p=this.awaitPos,m=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var ee=this.parseExprList(K.parenR,this.options.ecmaVersion>=8,!1,d);if(i&&!c&&this.shouldParseAsyncArrow())return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,`Cannot use 'await' as identifier inside an async function`),this.yieldPos=f,this.awaitPos=p,this.awaitIdentPos=m,this.parseSubscriptAsyncArrow(t,n,ee,o);this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=p||this.awaitPos,this.awaitIdentPos=m||this.awaitIdentPos;var te=this.startNodeAt(t,n);te.callee=e,te.arguments=ee,s&&(te.optional=c),e=this.finishNode(te,`CallExpression`)}else if(this.type===K.backQuote){(c||a)&&this.raise(this.start,`Optional chaining cannot appear in the tag of tagged template expressions`);var ne=this.startNodeAt(t,n);ne.tag=e,ne.quasi=this.parseTemplate({isTagged:!0}),e=this.finishNode(ne,`TaggedTemplateExpression`)}return e},J.parseExprAtom=function(e,t,n){this.type===K.slash&&this.readRegexp();var r,i=this.potentialArrowAt===this.start;switch(this.type){case K._super:return this.allowSuper||this.raise(this.start,`'super' keyword outside a method`),r=this.startNode(),this.next(),this.type===K.parenL&&!this.allowDirectSuper&&this.raise(r.start,`super() call outside constructor of a subclass`),this.type!==K.dot&&this.type!==K.bracketL&&this.type!==K.parenL&&this.unexpected(),this.finishNode(r,`Super`);case K._this:return r=this.startNode(),this.next(),this.finishNode(r,`ThisExpression`);case K.name:var a=this.start,o=this.startLoc,s=this.containsEsc,c=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!s&&c.name===`async`&&!this.canInsertSemicolon()&&this.eat(K._function))return this.overrideContext(IS.f_expr),this.parseFunction(this.startNodeAt(a,o),0,!1,!0,t);if(i&&!this.canInsertSemicolon()){if(this.eat(K.arrow))return this.parseArrowExpression(this.startNodeAt(a,o),[c],!1,t);if(this.options.ecmaVersion>=8&&c.name===`async`&&this.type===K.name&&!s&&(!this.potentialArrowInForAwait||this.value!==`of`||this.containsEsc))return c=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(K.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(a,o),[c],!0,t)}return c;case K.regexp:var l=this.value;return r=this.parseLiteral(l.value),r.regex={pattern:l.pattern,flags:l.flags},r;case K.num:case K.string:return this.parseLiteral(this.value);case K._null:case K._true:case K._false:return r=this.startNode(),r.value=this.type===K._null?null:this.type===K._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,`Literal`);case K.parenL:var u=this.start,d=this.parseParenAndDistinguishExpression(i,t);return e&&(e.parenthesizedAssign<0&&!this.isSimpleAssignTarget(d)&&(e.parenthesizedAssign=u),e.parenthesizedBind<0&&(e.parenthesizedBind=u)),d;case K.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(K.bracketR,!0,!0,e),this.finishNode(r,`ArrayExpression`);case K.braceL:return this.overrideContext(IS.b_expr),this.parseObj(!1,e);case K._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case K._class:return this.parseClass(this.startNode(),!1);case K._new:return this.parseNew();case K.backQuote:return this.parseTemplate();case K._import:return this.options.ecmaVersion>=11?this.parseExprImport(n):this.unexpected();default:return this.parseExprAtomDefault()}},J.parseExprAtomDefault=function(){this.unexpected()},J.parseExprImport=function(e){var t=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword import`),this.next(),this.type===K.parenL&&!e)return this.parseDynamicImport(t);if(this.type===K.dot){var n=this.startNodeAt(t.start,t.loc&&t.loc.start);return n.name=`import`,t.meta=this.finishNode(n,`Identifier`),this.parseImportMeta(t)}this.unexpected()},J.parseDynamicImport=function(e){if(this.next(),e.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(K.parenR)?e.options=null:(this.expect(K.comma),this.afterTrailingComma(K.parenR)?e.options=null:(e.options=this.parseMaybeAssign(),this.eat(K.parenR)||(this.expect(K.comma),this.afterTrailingComma(K.parenR)||this.unexpected())));else if(!this.eat(K.parenR)){var t=this.start;this.eat(K.comma)&&this.eat(K.parenR)?this.raiseRecoverable(t,`Trailing comma is not allowed in import()`):this.unexpected(t)}return this.finishNode(e,`ImportExpression`)},J.parseImportMeta=function(e){this.next();var t=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!==`meta`&&this.raiseRecoverable(e.property.start,`The only valid meta property for import is 'import.meta'`),t&&this.raiseRecoverable(e.start,`'import.meta' must not contain escaped characters`),this.options.sourceType!==`module`&&!this.options.allowImportExportEverywhere&&this.raiseRecoverable(e.start,`Cannot use 'import.meta' outside a module`),this.finishNode(e,`MetaProperty`)},J.parseLiteral=function(e){var t=this.startNode();return t.value=e,t.raw=this.input.slice(this.start,this.end),t.raw.charCodeAt(t.raw.length-1)===110&&(t.bigint=t.value==null?t.raw.slice(0,-1).replace(/_/g,``):t.value.toString()),this.next(),this.finishNode(t,`Literal`)},J.parseParenExpression=function(){this.expect(K.parenL);var e=this.parseExpression();return this.expect(K.parenR),e},J.shouldParseArrow=function(e){return!this.canInsertSemicolon()},J.parseParenAndDistinguishExpression=function(e,t){var n=this.start,r=this.startLoc,i,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var o=this.start,s=this.startLoc,c=[],l=!0,u=!1,d=new TS,f=this.yieldPos,p=this.awaitPos,m;for(this.yieldPos=0,this.awaitPos=0;this.type!==K.parenR;){if(l?l=!1:this.expect(K.comma),a&&this.afterTrailingComma(K.parenR,!0)){u=!0;break}if(this.type===K.ellipsis){m=this.start,c.push(this.parseParenItem(this.parseRestBinding())),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`);break}c.push(this.parseMaybeAssign(!1,d,this.parseParenItem))}var ee=this.lastTokEnd,te=this.lastTokEndLoc;if(this.expect(K.parenR),e&&this.shouldParseArrow(c)&&this.eat(K.arrow))return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=f,this.awaitPos=p,this.parseParenArrowList(n,r,c,t);(!c.length||u)&&this.unexpected(this.lastTokStart),m&&this.unexpected(m),this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=p||this.awaitPos,c.length>1?(i=this.startNodeAt(o,s),i.expressions=c,this.finishNodeAt(i,`SequenceExpression`,ee,te)):i=c[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var ne=this.startNodeAt(n,r);return ne.expression=i,this.finishNode(ne,`ParenthesizedExpression`)}return i},J.parseParenItem=function(e){return e},J.parseParenArrowList=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!1,r)};var BS=[];J.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword new`);var e=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===K.dot){var t=this.startNodeAt(e.start,e.loc&&e.loc.start);t.name=`new`,e.meta=this.finishNode(t,`Identifier`),this.next();var n=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!==`target`&&this.raiseRecoverable(e.property.start,`The only valid meta property for new is 'new.target'`),n&&this.raiseRecoverable(e.start,`'new.target' must not contain escaped characters`),this.allowNewDotTarget||this.raiseRecoverable(e.start,`'new.target' can only be used in functions and class static block`),this.finishNode(e,`MetaProperty`)}var r=this.start,i=this.startLoc;return e.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,i,!0,!1),e.callee.type===`Super`&&this.raiseRecoverable(r,`Invalid use of 'super'`),e.arguments=this.eat(K.parenL)?this.parseExprList(K.parenR,this.options.ecmaVersion>=8,!1):BS,this.finishNode(e,`NewExpression`)},J.parseTemplateElement=function(e){var t=e.isTagged,n=this.startNode();return this.type===K.invalidTemplate?(t||this.raiseRecoverable(this.start,`Bad escape sequence in untagged template literal`),n.value={raw:this.value.replace(/\r\n?/g,`
|
|
8
|
+
`);return e.length===0?t:`${t}\nexport declare const env: ${e.map(e=>e.environment).join(` & `)};`}function rb(e){let t=$y(e.path.replace(/\./g,`$`)),n=Qy(e.input,`input`),r=e.output?Qy(e.output,`output`):`unknown`;return Object.freeze({indexEnvironment:eb(e.path,n,r),environment:eb(e.path,`${t}_Input`,`${t}_Output`),types:`export type ${t}_Input = ${n};\nexport type ${t}_Output = ${r};`})}function ib(e){let t=Gy(e,`input`);if(t===!0||t===!1||!t.properties)return;let n=t.properties,r={},i=!1,a=Object.entries(n).sort(([e],[t])=>My(e,t));for(let[e,t]of a){if(t===!0||t===!1)continue;let n=t,a=n.examples;if(a&&a.length>0){let t=ky.safeParse(a[0]);t.success&&(r[e]=t.data,i=!0)}else if(n.default!==void 0){let t=ky.safeParse(n.default);t.success&&(r[e]=t.data,i=!0)}}return i?r:void 0}function ab(e){let t=Wy(e,`input`).json;if(t===void 0)throw new Oy(`invalid_input`,`Schema cannot be projected to JSON Schema`);return t}function ob(e,t=`input`){let n=Wy(e,t);return n.fingerprint??=Ry(n.json??null),n.fingerprint}function sb(e,t){if(t>16)return t;if(Array.isArray(e)){let n=t;for(let r of e)n=Math.max(n,sb(r,t+1));return n}if(!jy(e))return t;let n=t;for(let r of Object.values(e))n=Math.max(n,sb(r,t+1));return n}function cb(e,t){let n=Wy(e,t);return n.size??={bytes:lb(e,t,n.json)},n.size.bytes}function lb(e,t,n){if(!n)return;let r=JSON.stringify(n);if(r.length>2e4||sb(n,0)>16)return;if(t===`output`)return r.length;let i=ib(e);if(!i)return r.length;if(Object.keys(i).length>100||sb(i,0)>16)return;let a;try{a=JSON.stringify(i)}catch{throw new Oy(`invalid_input`,`Derived schema sample cannot be serialized`)}if(!(!a||a.length>4e3))return r.length+a.length}function ub(e){return e&&e.length>0?e:void 0}function db(e){let t=Cy.safeParse(e);if(!t.success)throw new Oy(`invalid_input`,`Description output exceeded its bounds`);return t.data}function fb(e,t){let n=e.find(e=>e.path===t.path);if(n){let e=`env.${n.path}`,t={path:n.path,description:ub(n.description),types:nb([n.rendered]),kind:`operation`,inputSchema:n.inputSchema,usage:`await ${e}({ ... })`};if(t.types.length>2e4)throw new Oy(`invalid_input`,`Description types exceed the bounded output`);return db(t)}let r=`${t.path}.`,i=e.filter(e=>e.path.startsWith(r)).sort((e,t)=>My(e.path,t.path));if(i.length===0)throw new Oy(`unknown_target`,`Unknown target: ${t.path}`);let a=i[0];if(!a)throw new Oy(`unknown_target`,`Unknown target: ${t.path}`);let o=t.methods?.length?i.filter(e=>t.methods?.includes(e.path.slice(r.length))):i,s;if(s=t.detail===`index`||t.methods?.length&&o.length===0?tb(i.map(e=>e.rendered)):nb((o.length>0?o:i).map(e=>e.rendered)),s.length>2e4)throw new Oy(`invalid_input`,`Description types exceed the bounded output`);return db({path:t.path,description:ub(a.instructions),types:s,kind:`module`})}function pb(e){return Object.freeze({...e,fingerprint:ob(e.input),inputSchema:ab(e.input),sample:ib(e.input),rendered:rb(e)})}var mb={exact:14,startsWith:9,phrase:6,token:4,prefix:2,substring:2,includes:1};function hb(e){switch(e){case`path`:return 12;case`namespace`:return 8;case`method`:return 10;case`description`:return 5;default:return 5}}function gb(e){return zy([...e].sort((e,t)=>My(e.path,t.path)).map(e=>Ry([e.path,e.description??null,e.capabilityNotes??null,e.instructions??null,e.fingerprint,e.output===void 0?null:ob(e.output,`output`)])).join(`
|
|
9
|
+
`))}function _b(e,t){if(e===t)return`exact`;if(e.startsWith(t))return`startsWith`;let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);if(RegExp(`\\b${n}\\b`).test(e))return`phrase`;let r=Py(e);return r.some(e=>e===t)?`token`:r.some(e=>e.startsWith(t))?`prefix`:r.some(e=>e.includes(t))?`substring`:e.includes(t)?`includes`:`none`}function vb(e,t,n){let r=Ny(e),i=`none`,a=0,o=[];for(let e of n){let n=[e,...Ly(e)],s=`none`;for(let e of n){let t=_b(r,e);if(t!==`none`){s=t;break}}if(s===`none`)continue;let c=mb[s]*hb(t);c>a?(i=s,a=c,o=[e]):c===a&&!o.includes(e)&&o.push(e)}return{level:i,score:a,matchedTokens:o}}function yb(e,t){let n=Ny(e);return[t,...Ly(t)].some(e=>n.includes(e))}function bb(e){let t=[];for(let[n,r]of e){if(r.level===`none`)continue;let e=r.matchedTokens.slice(0,4).map(e=>e.slice(0,20));t.push(`${n}:${r.level}(${e.join(` `)})`)}return t.length>0?t.join(`; `):void 0}function xb(e){let t=xy.safeParse(e);if(!t.success)throw new Oy(`invalid_input`,`Search output exceeded its bounds`);return t.data}function Sb(e){return[By(e.path),(e.description??``).trim().toLowerCase().replace(/\s+/g,` `),e.fingerprint].join(`\0`)}function Cb(e){return xb({results:[],total:0,truncated:!1,topScore:0,margin:0,catalogStamp:e})}function wb(e,t,n,r,i){let a=Vy(e.path),o=By(e.path),s=e.description??``,c=[e.path,a,o,s],l=vb(e.path,`path`,n),u=vb(a,`namespace`,n),d=vb(o,`method`,n),f=vb(s,`description`,n),p=r.filter(e=>c.some(t=>yb(t,e))).length,m=p/r.length,ee=Ny(`${e.path} ${s}`).includes(t);if(m<i&&!ee)return;let te=Math.max(l.score,u.score,d.score,f.score);if(te===0)return;let ne=p===r.length?25:m*10,h=r[0];h&&c.some(e=>yb(e,h))&&(ne+=8),(l.level===`exact`||d.level===`exact`)&&(ne+=20);let re={path:e.path,score:te+ne};s&&(re.description=s);let ie=bb([[`method`,d],[`description`,f],[`path`,l],[`namespace`,u]]);return ie&&(re.matchReason=ie),e.sample&&(re.sample=e.sample),e.capabilityNotes&&(re.capabilityNotes=e.capabilityNotes),{result:re,cluster:Sb(e),pathScore:l.score}}function Tb(e){let t=new Map;for(let n of e){let e=t.get(n.cluster)??[];e.push(n),t.set(n.cluster,e)}let n=[];for(let e of t.values()){let t=[...e].sort((e,t)=>t.pathScore-e.pathScore||t.result.score-e.result.score||My(e.result.path,t.result.path)),r=t[0];if(!r)continue;let i=[],a=t.slice(1).sort((e,t)=>My(e.result.path,t.result.path));for(let e of a){let t={path:e.result.path};e.result.capabilityNotes&&(t.capabilityNotes=e.result.capabilityNotes),i.push(t)}let o={...r.result,score:Math.max(...t.map(e=>e.result.score))};i.length>0&&(o.peers=i),n.push(o)}return n.sort((e,t)=>t.score-e.score||My(e.path,t.path))}function Eb(e,t,n){let r=e.slice(0,t),i=r[0],a=r[1];return xb({results:r,total:e.length,truncated:e.length>t,topScore:i?.score??0,margin:i&&a?i.score-a.score:0,catalogStamp:n})}function Db(e,t,n=50,r){let i=Math.min(50,Math.max(1,Math.floor(n))),a=Ny(t),o=Py(a),s=o.filter(e=>!Iy(e));if(s.length===0)return Cb(r);let c=s.length<=2?1:.6,l=[];for(let t of e){let e=wb(t,a,o,s,c);e&&l.push(e)}return Eb(Tb(l),i,r)}var Ob=ur({catalogStamp:Sy.shape.catalogStamp,namespace:vy.shape.namespace.unwrap().nullable(),after:by.shape.path});function kb(e,t,n){let r=vy.safeParse(n);if(!r.success)throw new Oy(`invalid_input`,r.error.message);let i=r.data,a=i.namespace??null,o=e.filter(e=>a===null||e.path.startsWith(`${a}.`)).sort((e,t)=>My(Vy(e.path),Vy(t.path))||My(e.path,t.path)),s=0;if(i.cursor!==void 0){let e;try{e=Ob.parse(JSON.parse(i.cursor))}catch(e){throw new Oy(`invalid_input`,`Invalid listing cursor`,{cause:e})}if(e.catalogStamp!==t||e.namespace!==a)throw new Oy(`invalid_input`,`Listing cursor belongs to a different catalog or namespace`);let n=o.findIndex(t=>t.path===e.after);if(n<0)throw new Oy(`invalid_input`,`Listing cursor operation is absent from this view`);s=n+1}let c=o.slice(s,s+i.limit),l=c.at(-1);return Sy.parse({results:c,total:o.length,catalogStamp:t,nextCursor:s+c.length<o.length&&l!==void 0?JSON.stringify({catalogStamp:t,namespace:a,after:l.path}):null})}var Ab=1e6;function jb(e){let t=Dy.safeParse(e);if(!t.success)throw new Oy(`invalid_input`,t.error.message);if(t.data.operations.length===0)throw new Oy(`empty_catalog`,`Catalog must contain an operation`);let n=[...t.data.operations].sort((e,t)=>My(e.path,t.path)),r=new Set,i=0;for(let e of n){if(r.has(e.path))throw new Oy(`duplicate_operation`,`Duplicate operation path: ${e.path}`);r.add(e.path);let t=cb(e.input,`input`);if(t===void 0)throw new Oy(`invalid_input`,`Schema projection is too large: ${e.path}`);let n=e.output?cb(e.output,`output`):0;if(n===void 0)throw new Oy(`invalid_input`,`Schema output projection is too large: ${e.path}`);if(i+=t+n+e.path.length,i+=e.description?.length??0,i+=e.capabilityNotes?.length??0,i+=e.instructions?.length??0,i>Ab)throw new Oy(`invalid_input`,`Catalog metadata exceeds the bounded projection`)}let a=n.map(e=>pb(e));for(let e of a)if(nb([e.rendered]).length>2e4)throw new Oy(`invalid_input`,`Operation description exceeds the bounded output: ${e.path}`);return{revision:t.data.revision,operations:a}}function Mb(e){let t=jb(e),n=Object.freeze(t.operations),r=gb(n),i=n.map(e=>{let t={path:e.path,score:0};return e.description!==void 0&&(t.description=e.description),e.sample!==void 0&&(t.sample=e.sample),e.capabilityNotes!==void 0&&(t.capabilityNotes=e.capabilityNotes),t});return Object.freeze({revision:t.revision,search:e=>{let t=gy.safeParse(e);if(!t.success)throw new Oy(`invalid_input`,t.error.message);if(t.data.query.trim().length===0)throw new Oy(`empty_query`,`Search query must not be empty`);return Db(n,t.data.query,t.data.maxResults,r)},describe:e=>{let t=_y.safeParse(e);if(!t.success)throw new Oy(`invalid_input`,t.error.message);if(t.data.path.trim().length===0)throw new Oy(`empty_query`,`Description target must not be empty`);return fb(n,t.data)},list:e=>kb(i,r,e),stamp:()=>r})}var Nb=b(()=>S().min(1).max(75).regex(/^[A-Za-z][A-Za-z0-9_]*$/));b(()=>zt([cn(S(),yr()),t()]));var Pb=b(()=>Un({tool:Nb,title:S().max(120),description:S().max(1e3),input:cn(S(),yr()),output:cn(S(),yr()),call:cn(S(),yr())}).catchall(yr()));b(()=>Or(`kind`,[ur({kind:Kt(`unindexed`)}),ur({kind:Kt(`ready`),tools:kt(Pb).max(100).refine(e=>new Set(e.map(e=>e.tool)).size===e.length,{message:`Tool family names must be distinct`})})]));var Fb=Object.freeze({replay:`safe`,path:`forage.search`,description:`Search operation names and descriptions with short keywords, such as read or shell. If no results match, retry with one relevant keyword. Describe known operation paths directly with forage.describe.`,input:gy,output:xy}),Ib=Object.freeze({replay:`safe`,path:`forage.describe`,description:`Describe a capability`,input:_y,output:Cy}),Lb=Object.freeze({replay:`safe`,path:`forage.list`,description:`List every available operation in stable namespace then path order (UTF-16 code units). Use limit (1–50) and nextCursor to page without duplicates, optionally filtering by exact namespace. total counts all operations in that filter; summaries match search, with score 0 and no peer merging. A cursor belongs to this catalog and filter; describe paths before calling them.`,input:vy,output:Sy});Object.freeze({createCatalog:Mb,forageSearchDefinition:Fb,forageDescribeDefinition:Ib,forageListDefinition:Lb});var Rb=`invalid_definition`,zb=`runtime_closed`,Bb=`source_failure`,U=class extends Error{code=Rb;constructor(e){super(e),this.name=`MyceliumDefinitionError`}},Vb=class extends Error{code=zb;constructor(e=`Mycelium runtime is closed`){super(e),this.name=`MyceliumClosedError`}},Hb=class extends Error{sourceId;phase;code=Bb;constructor(e,t){super(e===void 0?`Capability source ${t} failed`:`Capability source ${t} failed: ${e}`),this.sourceId=e,this.phase=t,this.name=`MyceliumSourceError`}},Ub=class extends Error{issues;constructor(e){super(`Invalid operation input`),this.issues=e,this.name=`InvalidOperationInput`}},Wb=class extends Error{issues;constructor(e){super(`Operation output failed its declared schema`),this.issues=e,this.name=`InvalidOperationOutput`}},Gb=class extends Ei(`SourceInvalid`){},Kb=class extends Ei(`GuestThrew`){},qb=class extends Ei(`DeadlineExceeded`){},Jb=class extends Ei(`SandboxBusy`){code=`sandbox-busy`},Yb=class extends Ei(`Cancelled`){},Xb=class extends Ei(`DispatchLost`){},Zb=class extends Ei(`SandboxCrashed`){},Qb=class extends Ei(`BadResponse`){},$b=class extends Ei(`ResultTooLarge`){},ex=class extends Ei(`ResultNotJson`){},tx=class extends Ei(`CapabilityFailed`){constructor(e){super(e),this.message=ix(this)}},nx=class extends Ei(`Unknown`){};function rx(e,t){switch(e._tag){case`SourceInvalid`:return new Gb({line:e.line,column:e.column,excerpt:e.excerpt,ref:t});case`GuestThrew`:return new Kb({name:e.name,message:e.message,missingVariable:e.missingVariable,transportMessage:e.transportMessage,ref:t});case`DeadlineExceeded`:return new qb({limitMs:e.limitMs,elapsedMs:e.elapsedMs,acknowledged:e.acknowledged,ref:t});case`SandboxBusy`:return new Jb({capacity:e.capacity,waitedMs:e.waitedMs,ref:t});case`Cancelled`:return new Yb({by:e.by,acknowledged:e.acknowledged,ref:t});case`DispatchLost`:return new Xb({elapsedMs:e.elapsedMs,transport:e.transport,errno:e.errno,rawCause:e.rawCause,ref:t});case`SandboxCrashed`:return new Zb({exit:e.exit,errno:e.errno,rawCause:e.rawCause,ref:t});case`BadResponse`:return new Qb({reason:e.reason,rawCause:e.rawCause,ref:t});case`ResultTooLarge`:return new $b({size:e.size,ref:t});case`ResultNotJson`:return new ex({kind:e.kind,rawCause:e.rawCause,ref:t});case`CapabilityFailed`:return new tx({namespace:e.namespace,operation:e.operation,cause:e.cause,rawCause:e.rawCause,ref:t});case`Unknown`:return new nx({rawCause:e.rawCause,ref:t})}}function ix(e,t=!0){let n;switch(e._tag){case`SourceInvalid`:n=`SyntaxError in submitted source line ${String(e.line)}, column ${String(e.column)}: ${e.excerpt.slice(0,160)}. Nothing ran. Fix quote/heredoc nesting: quote multi-line shell text with a JavaScript template literal or \\n escapes; escape backticks and \${ inside it. If a nested heredoc is hard to quote, write the script with Files, then execute it.`;break;case`GuestThrew`:{let t=e.name.slice(0,80),r=e.message.slice(0,512),i=e.missingVariable;n=`${t}: ${r}${i===void 0?``:`. Declare ${i} with const or let before assigning it; this sandbox does not create implicit globals. Each execute call has its own variables.`}`;break}case`DeadlineExceeded`:n=`execute hit its ${String(e.limitMs)} ms deadline after ${String(e.elapsedMs)} ms; split the work or persist progress${e.acknowledged===!1?`; sandbox did not acknowledge cancellation`:``}`;break;case`SandboxBusy`:n=`sandbox-busy: all ${String(e.capacity)} sandbox slots remained occupied after waiting ${String(e.waitedMs)} ms. Nothing ran; retry this call after capacity becomes available.`;break;case`Cancelled`:n=e.acknowledged===!1?`Sandbox did not acknowledge cancellation`:`Execution was cancelled`;break;case`DispatchLost`:n=`The sandbox lost contact after ${String(e.elapsedMs)} ms; a running command may still be running; check its effects before retrying`;break;case`SandboxCrashed`:n=`The sandbox process stopped before answering; check effects before retrying`;break;case`BadResponse`:n=`The sandbox returned an unreadable result; retry once, split the call if it recurs`;break;case`ResultTooLarge`:n=`Sandbox result exceeds 256 KiB`;break;case`ResultNotJson`:n=`Sandbox returned non-JSON data`;break;case`CapabilityFailed`:n=e.cause.message.slice(0,1e3);break;case`Unknown`:return`The sandbox failed for an unrecognized reason${t?` (ref ${e.ref??`unavailable`})`:``}`}return!t||e.ref===void 0?n:`${n} (ref ${e.ref})`}var ax=b(()=>zt([Ae(Gb),Ae(Kb),Ae(qb),Ae(Jb),Ae(Yb),Ae(Xb),Ae(Zb),Ae(Qb),Ae($b),Ae(ex),Ae(tx),Ae(nx)])),ox=b(()=>Rr().pipe(zt([Ae(Error).transform(e=>({kind:`error`,value:e})),hr().transform(e=>({kind:`null`,value:e})),Ee().transform(e=>({kind:`undefined`,value:e})),S().transform(e=>({kind:`string`,value:e})),t().transform(e=>({kind:`boolean`,value:e})),zt([tn(),wr(),Kt(1/0),Kt(-1/0)]).transform(e=>({kind:`number`,value:e})),et().transform(e=>({kind:`bigint`,value:e})),Tn().transform(e=>({kind:`symbol`,value:e})),Ae(Function).transform(e=>({kind:`function`,value:e})),kt(Rr()).transform(e=>({kind:`array`,value:e})),zt([Ae(Object),cn(S(),Rr())]).transform(e=>({kind:`object`,value:e})),Rr().transform(()=>({kind:`opaque`}))])));function sx(e){return ax.safeParse(e).success}function cx(e){let t=ax.safeParse(e);return t.success?t.data:new nx({rawCause:e})}function lx(e){let t=ox.parse(e);switch(t.kind){case`error`:case`array`:case`null`:return`object`;default:return t.kind}}b(()=>yr().optional());function ux(e){return dx(e,new Set)}function dx(e,t){let n=ox.parse(e);switch(n.kind){case`null`:case`undefined`:return null;case`string`:case`boolean`:return n.value;case`number`:return Number.isFinite(n.value)?n.value:String(n.value);case`bigint`:case`symbol`:return String(n.value);case`function`:return{kind:`function`,name:n.value.name};case`opaque`:return{kind:`opaque`};case`error`:case`array`:case`object`:{let r=n.value;if(t.has(e))return{kind:`circular_reference`};t.add(e);try{if(n.kind===`array`)return n.value.map(e=>dx(e,t));let e=Object.fromEntries(Object.entries(r).map(([e,n])=>[e,dx(n,t)]));if(n.kind===`error`){let r=n.value;e.name=r.name,e.message=r.message,r.stack!==void 0&&(e.stack=r.stack),r.cause!==void 0&&(e.cause=dx(r.cause,t)),r instanceof AggregateError&&(e.errors=dx(r.errors,t))}return e}finally{t.delete(e)}}}}var fx=b(()=>Un({name:Kt(`ReferenceError`),message:S().regex(/^[\p{ID_Start}_$][\p{ID_Continue}$]* is not defined$/u)}).transform(e=>({...e,missingVariable:e.message.slice(0,-15)})));b(()=>zt([fx,Un({name:S(),message:S()})]).and(Un({transportMessage:S().max(512).optional()})));var px=b(()=>ur({v:Kt(1),kind:Kt(`sandbox_failure`),tag:Tt([`SourceInvalid`,`GuestThrew`,`DeadlineExceeded`,`SandboxBusy`,`Cancelled`,`DispatchLost`,`SandboxCrashed`,`BadResponse`,`ResultTooLarge`,`ResultNotJson`,`CapabilityFailed`,`Unknown`]),ref:S().min(1).max(32),message:S().max(160)})),mx=E(Xm(xp)),hx=b(()=>S().transform((e,t)=>{let n=mx(e);return xt(n)?(t.addIssue({code:`custom`,message:`Invalid sandbox transport JSON`}),ut):n.success})).pipe(px);ur({error:hx}),b(()=>Rr().pipe(zt([Kt(`Execution timed out`).transform(()=>({kind:`deadline`})),Rr().transform(e=>({kind:`bad_response`,rawCause:e}))])));var gx=ur({sandboxCapacity:$n().positive().optional(),admissionWaitMs:$n().min(1).max(9e5).optional()});function _x(e,t){let n=gx.safeParse(e??{}),r=$n().positive().safeParse(t??2);if(!n.success||!r.success)throw new U(`Sandbox admission policy is invalid`);return Object.freeze({capacity:n.data.sandboxCapacity??Math.min(32,Math.max(2,r.data)),waitMs:n.data.admissionWaitMs??5e3})}var vx=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,7,9,32,4,318,1,78,5,71,10,50,3,123,2,54,14,32,10,3,1,11,3,46,10,8,0,46,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,3,0,158,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,68,8,2,0,3,0,2,3,2,4,2,0,15,1,83,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,7,19,58,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,199,7,137,9,54,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,55,9,266,3,10,1,2,0,49,6,4,4,14,10,5350,0,7,14,11465,27,2343,9,87,9,39,4,60,6,26,9,535,9,470,0,2,54,8,3,82,0,12,1,19628,1,4178,9,519,45,3,22,543,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,101,0,161,6,10,9,357,0,62,13,499,13,245,1,2,9,233,0,3,0,8,1,6,0,475,6,110,6,6,9,4759,9,787719,239],yx=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,13,10,2,14,2,6,2,1,2,10,2,14,2,6,2,1,4,51,13,310,10,21,11,7,25,5,2,41,2,8,70,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,7,25,39,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,39,27,10,22,251,41,7,1,17,5,57,28,11,0,9,21,43,17,47,20,28,22,13,52,58,1,3,0,14,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,20,1,64,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,31,9,2,0,3,0,2,37,2,0,26,0,2,0,45,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,38,6,186,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,19,72,200,32,32,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,24,43,261,18,16,0,2,12,2,33,125,0,80,921,103,110,18,195,2637,96,16,1071,18,5,26,3994,6,582,6842,29,1763,568,8,30,18,78,18,29,19,47,17,3,32,20,6,18,433,44,212,63,33,24,3,24,45,74,6,0,67,12,65,1,2,0,15,4,10,7381,42,31,98,114,8702,3,2,6,2,1,2,290,16,0,30,2,3,0,15,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,1845,30,7,5,262,61,147,44,11,6,17,0,322,29,19,43,485,27,229,29,3,0,208,30,2,2,2,1,2,6,3,4,10,1,225,6,2,3,2,1,2,14,2,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42719,33,4381,3,5773,3,7472,16,621,2467,541,1507,4938,6,8489],bx=`·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛-࢟࣊-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍୕-ୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄ఼ా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ೳഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ඁ-ඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ຼ່-໎໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜕ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠏-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᪿ--ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭᳴᳷-᳹᷀-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯・꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧ꠬ꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_・`,xx=`ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࡰ-ࢇࢉ-ࢠ-ࣉऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౝౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽ-ೞೠೡೱೲഄ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄຆ-ຊຌ-ຣລວ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜑᜟ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭌᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-Ა-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳳᳵᳶᳺᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆿㇰ-ㇿ㐀-䶿一-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ--ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭩꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ`,Sx={3:`abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile`,5:`class enum extends super const export import`,6:`enum`,strict:`implements interface let package private protected public static yield`,strictBind:`eval arguments`},Cx=`break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this`,wx={5:Cx,"5module":Cx+` export import`,6:Cx+` const class extends export import super`},Tx=/^in(stanceof)?$/,Ex=RegExp(`[`+xx+`]`),Dx=RegExp(`[`+xx+bx+`]`);function Ox(e,t){for(var n=65536,r=0;r<t.length;r+=2){if(n+=t[r],n>e)return!1;if(n+=t[r+1],n>=e)return!0}return!1}function kx(e,t){return e<65?e===36:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&Ex.test(String.fromCharCode(e)):t!==!1&&Ox(e,yx)}function Ax(e,t){return e<48?e===36:e<58?!0:e<65?!1:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&Dx.test(String.fromCharCode(e)):t===!1?!1:Ox(e,yx)||Ox(e,vx)}var W=function(e,t){t===void 0&&(t={}),this.label=e,this.keyword=t.keyword,this.beforeExpr=!!t.beforeExpr,this.startsExpr=!!t.startsExpr,this.isLoop=!!t.isLoop,this.isAssign=!!t.isAssign,this.prefix=!!t.prefix,this.postfix=!!t.postfix,this.binop=t.binop||null,this.updateContext=null};function jx(e,t){return new W(e,{beforeExpr:!0,binop:t})}var Mx={beforeExpr:!0},Nx={startsExpr:!0},Px={};function G(e,t){return t===void 0&&(t={}),t.keyword=e,Px[e]=new W(e,t)}var K={num:new W(`num`,Nx),regexp:new W(`regexp`,Nx),string:new W(`string`,Nx),name:new W(`name`,Nx),privateId:new W(`privateId`,Nx),eof:new W(`eof`),bracketL:new W(`[`,{beforeExpr:!0,startsExpr:!0}),bracketR:new W(`]`),braceL:new W(`{`,{beforeExpr:!0,startsExpr:!0}),braceR:new W(`}`),parenL:new W(`(`,{beforeExpr:!0,startsExpr:!0}),parenR:new W(`)`),comma:new W(`,`,Mx),semi:new W(`;`,Mx),colon:new W(`:`,Mx),dot:new W(`.`),question:new W(`?`,Mx),questionDot:new W(`?.`),arrow:new W(`=>`,Mx),template:new W(`template`),invalidTemplate:new W(`invalidTemplate`),ellipsis:new W(`...`,Mx),backQuote:new W("`",Nx),dollarBraceL:new W("${",{beforeExpr:!0,startsExpr:!0}),eq:new W(`=`,{beforeExpr:!0,isAssign:!0}),assign:new W(`_=`,{beforeExpr:!0,isAssign:!0}),incDec:new W(`++/--`,{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new W(`!/~`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:jx(`||`,1),logicalAND:jx(`&&`,2),bitwiseOR:jx(`|`,3),bitwiseXOR:jx(`^`,4),bitwiseAND:jx(`&`,5),equality:jx(`==/!=/===/!==`,6),relational:jx(`</>/<=/>=`,7),bitShift:jx(`<</>>/>>>`,8),plusMin:new W(`+/-`,{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:jx(`%`,10),star:jx(`*`,10),slash:jx(`/`,10),starstar:new W(`**`,{beforeExpr:!0}),coalesce:jx(`??`,1),_break:G(`break`),_case:G(`case`,Mx),_catch:G(`catch`),_continue:G(`continue`),_debugger:G(`debugger`),_default:G(`default`,Mx),_do:G(`do`,{isLoop:!0,beforeExpr:!0}),_else:G(`else`,Mx),_finally:G(`finally`),_for:G(`for`,{isLoop:!0}),_function:G(`function`,Nx),_if:G(`if`),_return:G(`return`,Mx),_switch:G(`switch`),_throw:G(`throw`,Mx),_try:G(`try`),_var:G(`var`),_const:G(`const`),_while:G(`while`,{isLoop:!0}),_with:G(`with`),_new:G(`new`,{beforeExpr:!0,startsExpr:!0}),_this:G(`this`,Nx),_super:G(`super`,Nx),_class:G(`class`,Nx),_extends:G(`extends`,Mx),_export:G(`export`),_import:G(`import`,Nx),_null:G(`null`,Nx),_true:G(`true`,Nx),_false:G(`false`,Nx),_in:G(`in`,{beforeExpr:!0,binop:7}),_instanceof:G(`instanceof`,{beforeExpr:!0,binop:7}),_typeof:G(`typeof`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:G(`void`,{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:G(`delete`,{beforeExpr:!0,prefix:!0,startsExpr:!0})},Fx=/\r\n?|\n|\u2028|\u2029/,Ix=new RegExp(Fx.source,`g`);function Lx(e){return e===10||e===13||e===8232||e===8233}function Rx(e,t,n){n===void 0&&(n=e.length);for(var r=t;r<n;r++){var i=e.charCodeAt(r);if(Lx(i))return r<n-1&&i===13&&e.charCodeAt(r+1)===10?r+2:r+1}return-1}var zx=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Bx=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Vx=Object.prototype,Hx=Vx.hasOwnProperty,Ux=Vx.toString,Wx=Object.hasOwn||(function(e,t){return Hx.call(e,t)}),Gx=Array.isArray||(function(e){return Ux.call(e)===`[object Array]`}),Kx=Object.create(null);function qx(e){return Kx[e]||(Kx[e]=RegExp(`^(?:`+e.replace(/ /g,`|`)+`)$`))}function Jx(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}var Yx=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/,Xx=function(e,t){this.line=e,this.column=t};Xx.prototype.offset=function(e){return new Xx(this.line,this.column+e)};var Zx=function(e,t,n){this.start=t,this.end=n,e.sourceFile!==null&&(this.source=e.sourceFile)};function Qx(e,t){for(var n=1,r=0;;){var i=Rx(e,r,t);if(i<0)return new Xx(n,t-r);++n,r=i}}var $x={ecmaVersion:null,sourceType:`script`,strict:!1,onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:null,allowSuperOutsideMethod:null,allowHashBang:!1,checkPrivateFields:!0,locations:!1,startLocation:null,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1},eS=!1;function tS(e){var t={};for(var n in $x)t[n]=e&&Wx(e,n)?e[n]:$x[n];if(t.ecmaVersion===`latest`?t.ecmaVersion=1e8:t.ecmaVersion==null?(!eS&&typeof console==`object`&&console.warn&&(eS=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.
|
|
10
|
+
Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=11):t.ecmaVersion>=2015&&(t.ecmaVersion-=2009),t.allowReserved??=t.ecmaVersion<5,(!e||e.allowHashBang==null)&&(t.allowHashBang=t.ecmaVersion>=14),Gx(t.onToken)){var r=t.onToken;t.onToken=function(e){return r.push(e)}}if(Gx(t.onComment)&&(t.onComment=nS(t,t.onComment)),t.sourceType===`commonjs`&&t.allowAwaitOutsideFunction)throw Error(`Cannot use allowAwaitOutsideFunction with sourceType: commonjs`);return t}function nS(e,t){return function(n,r,i,a,o,s){var c={type:n?`Block`:`Line`,value:r,start:i,end:a};e.locations&&(c.loc=new Zx(this,o,s)),e.ranges&&(c.range=[i,a]),t.push(c)}}var rS=1,iS=2,aS=4,oS=8,sS=16,cS=32,lS=64,uS=128,dS=256,fS=512,pS=1024,mS=rS|iS|dS;function hS(e,t){return iS|(e?aS:0)|(t?oS:0)}var gS=0,_S=1,vS=2,yS=3,bS=4,xS=5,SS=function(e,t,n){this.options=e=tS(e),this.sourceFile=e.sourceFile,this.keywords=qx(wx[e.ecmaVersion>=6?6:e.sourceType===`module`?`5module`:5]);var r=``;e.allowReserved!==!0&&(r=Sx[e.ecmaVersion>=6?6:e.ecmaVersion===5?5:3],e.sourceType===`module`&&(r+=` await`)),this.reservedWords=qx(r);var i=(r?r+` `:``)+Sx.strict;this.reservedWordsStrict=qx(i),this.reservedWordsStrictBind=qx(i+` `+Sx.strictBind),this.input=String(t),this.containsEsc=!1,this.pos=n||0,this.curLine=1,e.startLocation?(this.lineStart=this.pos-e.startLocation.column,this.curLine=e.startLocation.line):n?(this.lineStart=this.input.lastIndexOf(`
|
|
11
|
+
`,n-1)+1,this.options.locations&&(this.curLine=this.input.slice(0,this.lineStart).split(Fx).length)):this.lineStart=0,this.type=K.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=e.sourceType===`module`,this.strict=this.inModule||e.strict===!0||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&e.allowHashBang&&this.input.slice(0,2)===`#!`&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType===`commonjs`?iS:rS),this.regexpState=null,this.privateNameStack=[]},CS={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},canAwait:{configurable:!0},allowReturn:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0},allowNewDotTarget:{configurable:!0},allowUsing:{configurable:!0},inClassStaticBlock:{configurable:!0}};SS.prototype.parse=function(){var e=this,t=this.options.program||this.startNode();return this.nextToken(),this.catchStackOverflow(function(){return e.parseTopLevel(t)})},CS.inFunction.get=function(){return(this.currentVarScope().flags&iS)>0},CS.inGenerator.get=function(){return(this.currentVarScope().flags&oS)>0},CS.inAsync.get=function(){return(this.currentVarScope().flags&aS)>0},CS.canAwait.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e].flags;if(t&(dS|fS))return!1;if(t&iS)return(t&aS)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction},CS.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&rS)},CS.allowSuper.get=function(){return(this.currentThisScope().flags&lS)>0||this.options.allowSuperOutsideMethod},CS.allowDirectSuper.get=function(){return(this.currentThisScope().flags&uS)>0},CS.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())},CS.allowNewDotTarget.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e].flags;if(t&(dS|fS)||t&iS&&!(t&sS))return!0}return!1},CS.allowUsing.get=function(){var e=this.currentScope().flags;return!(e&pS||!this.inModule&&e&rS)},CS.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&dS)>0},SS.extend=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];for(var n=this,r=0;r<e.length;r++)n=e[r](n);return n},SS.parse=function(e,t){return new this(t,e).parse()},SS.parseExpressionAt=function(e,t,n){var r=new this(n,e,t);return r.nextToken(),r.parseExpression()},SS.tokenizer=function(e,t){return new this(t,e)},Object.defineProperties(SS.prototype,CS);var wS=SS.prototype,TS=/^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;wS.strictDirective=function(e){if(this.options.ecmaVersion<5)return!1;for(;;){Bx.lastIndex=e,e+=Bx.exec(this.input)[0].length;var t=TS.exec(this.input.slice(e));if(!t)return!1;if((t[1]||t[2])===`use strict`){Bx.lastIndex=e+t[0].length;var n=Bx.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===`;`||i===`}`||Fx.test(n[0])&&!(/[(`.[+\-/*%<>=,?^&]/.test(i)||i===`!`&&this.input.charAt(r+1)===`=`)}e+=t[0].length,Bx.lastIndex=e,e+=Bx.exec(this.input)[0].length,this.input[e]===`;`&&e++}},wS.eat=function(e){return this.type===e&&(this.next(),!0)},wS.isContextual=function(e){return this.type===K.name&&this.value===e&&!this.containsEsc},wS.eatContextual=function(e){return this.isContextual(e)?(this.next(),!0):!1},wS.catchStackOverflow=function(e){try{return e()}catch(e){if(e instanceof Error&&(/\bstack\b.*\b(exceeded|overflow)\b/i.test(e.message)||/\btoo much recursion\b/i.test(e.message)))this.raise(this.start,`Not enough stack space to parse input`);else throw e}},wS.expectContextual=function(e){this.eatContextual(e)||this.unexpected()},wS.canInsertSemicolon=function(){return this.type===K.eof||this.type===K.braceR||Fx.test(this.input.slice(this.lastTokEnd,this.start))},wS.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},wS.semicolon=function(){!this.eat(K.semi)&&!this.insertSemicolon()&&this.unexpected()},wS.afterTrailingComma=function(e,t){if(this.type===e)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),t||this.next(),!0},wS.expect=function(e){this.eat(e)||this.unexpected()},wS.unexpected=function(e){this.raise(e??this.start,`Unexpected token`)};var ES=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};wS.checkPatternErrors=function(e,t){if(e){e.trailingComma>-1&&this.raiseRecoverable(e.trailingComma,`Comma is not permitted after the rest element`);var n=t?e.parenthesizedAssign:e.parenthesizedBind;n>-1&&this.raiseRecoverable(n,t?`Assigning to rvalue`:`Parenthesized pattern`)}},wS.checkExpressionErrors=function(e,t){if(!e)return!1;var n=e.shorthandAssign,r=e.doubleProto;if(!t)return n>=0||r>=0;n>=0&&this.raise(n,`Shorthand property assignments are valid only in destructuring patterns`),r>=0&&this.raiseRecoverable(r,`Redefinition of __proto__ property`)},wS.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,`Yield expression cannot be a default value`),this.awaitPos&&this.raise(this.awaitPos,`Await expression cannot be a default value`)},wS.isSimpleAssignTarget=function(e){return e.type===`ParenthesizedExpression`?this.isSimpleAssignTarget(e.expression):e.type===`Identifier`||e.type===`MemberExpression`};var q=SS.prototype;q.parseTopLevel=function(e){var t=Object.create(null);for(e.body||=[];this.type!==K.eof;){var n=this.parseStatement(null,!0,t);e.body.push(n)}if(this.inModule)for(var r=0,i=Object.keys(this.undefinedExports);r<i.length;r+=1){var a=i[r];this.raiseRecoverable(this.undefinedExports[a].start,`Export '`+a+`' is not defined`)}return this.adaptDirectivePrologue(e.body),this.next(),e.sourceType=this.options.sourceType===`commonjs`?`script`:this.options.sourceType,this.finishNode(e,`Program`)};var DS={kind:`loop`},OS={kind:`switch`};q.isLet=function(e){if(this.options.ecmaVersion<6||!this.isContextual(`let`))return!1;Bx.lastIndex=this.pos;var t=Bx.exec(this.input),n=this.pos+t[0].length,r=this.fullCharCodeAt(n);if(r===91||r===92)return!0;if(e)return!1;if(r===123)return!0;if(kx(r)){var i=n;do n+=r<=65535?1:2;while(Ax(r=this.fullCharCodeAt(n)));if(r===92)return!0;var a=this.input.slice(i,n);if(!Tx.test(a))return!0}return!1},q.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual(`async`))return!1;Bx.lastIndex=this.pos;var e=Bx.exec(this.input),t=this.pos+e[0].length,n;return!Fx.test(this.input.slice(this.pos,t))&&this.input.slice(t,t+8)===`function`&&(t+8===this.input.length||!(Ax(n=this.fullCharCodeAt(t+8))||n===92))},q.isUsingKeyword=function(e,t){if(this.options.ecmaVersion<17||!this.isContextual(e?`await`:`using`))return!1;Bx.lastIndex=this.pos;var n=Bx.exec(this.input),r=this.pos+n[0].length;if(Fx.test(this.input.slice(this.pos,r)))return!1;if(e){var i=r+5,a;if(this.input.slice(r,i)!==`using`||i===this.input.length||Ax(a=this.fullCharCodeAt(i))||a===92)return!1;Bx.lastIndex=i;var o=Bx.exec(this.input);if(r=i+o[0].length,o&&Fx.test(this.input.slice(i,r)))return!1}var s=this.fullCharCodeAt(r);if(!kx(s)&&s!==92)return!1;var c=r;do r+=s<=65535?1:2;while(Ax(s=this.fullCharCodeAt(r)));if(s===92)return!0;var l=this.input.slice(c,r);if(Tx.test(l))return!1;if(t&&!e&&l===`of`){Bx.lastIndex=r;var u=Bx.exec(this.input);if(r+=u[0].length,this.input.charCodeAt(r)!==61||(s=this.input.charCodeAt(r+1))===61||s===62)return!1}return!0},q.isAwaitUsing=function(e){return this.isUsingKeyword(!0,e)},q.isUsing=function(e){return this.isUsingKeyword(!1,e)},q.parseStatement=function(e,t,n){var r=this.type,i=this.startNode(),a;switch(this.isLet(e)&&(r=K._var,a=`let`),r){case K._break:case K._continue:return this.parseBreakContinueStatement(i,r.keyword);case K._debugger:return this.parseDebuggerStatement(i);case K._do:return this.parseDoStatement(i);case K._for:return this.parseForStatement(i);case K._function:return e&&(this.strict||e!==`if`&&e!==`label`)&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!e);case K._class:return e&&this.unexpected(),this.parseClass(i,!0);case K._if:return this.parseIfStatement(i);case K._return:return this.parseReturnStatement(i);case K._switch:return this.parseSwitchStatement(i);case K._throw:return this.parseThrowStatement(i);case K._try:return this.parseTryStatement(i);case K._const:case K._var:return a||=this.value,e&&a!==`var`&&this.unexpected(),this.parseVarStatement(i,a);case K._while:return this.parseWhileStatement(i);case K._with:return this.parseWithStatement(i);case K.braceL:return this.parseBlock(!0,i);case K.semi:return this.parseEmptyStatement(i);case K._export:case K._import:if(this.options.ecmaVersion>10&&r===K._import){Bx.lastIndex=this.pos;var o=Bx.exec(this.input),s=this.pos+o[0].length,c=this.input.charCodeAt(s);if(c===40||c===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(t||this.raise(this.start,`'import' and 'export' may only appear at the top level`),this.inModule||this.raise(this.start,`'import' and 'export' may appear only with 'sourceType: module'`)),r===K._import?this.parseImport(i):this.parseExport(i,n);default:if(this.isAsyncFunction())return e&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!e);var l=this.isAwaitUsing(!1)?`await using`:this.isUsing(!1)?`using`:null;if(l)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),e&&this.raise(this.start,`Using declaration is not allowed in single-statement positions`),l===`await using`&&(this.canAwait||this.raise(this.start,`Await using cannot appear outside of async function`),this.next()),this.next(),this.parseVar(i,!1,l),this.semicolon(),this.finishNode(i,`VariableDeclaration`);var u=this.value,d=this.parseExpression();return r===K.name&&d.type===`Identifier`&&this.eat(K.colon)?this.parseLabeledStatement(i,u,d,e):this.parseExpressionStatement(i,d)}},q.parseBreakContinueStatement=function(e,t){var n=t===`break`;this.next(),this.eat(K.semi)||this.insertSemicolon()?e.label=null:this.type===K.name?(e.label=this.parseIdent(),this.semicolon()):this.unexpected();for(var r=0;r<this.labels.length;++r){var i=this.labels[r];if((e.label==null||i.name===e.label.name)&&(i.kind!=null&&(n||i.kind===`loop`)||e.label&&n))break}return r===this.labels.length&&this.raise(e.start,`Unsyntactic `+t),this.finishNode(e,n?`BreakStatement`:`ContinueStatement`)},q.parseDebuggerStatement=function(e){return this.next(),this.semicolon(),this.finishNode(e,`DebuggerStatement`)},q.parseDoStatement=function(e){return this.next(),this.labels.push(DS),e.body=this.parseStatement(`do`),this.labels.pop(),this.expect(K._while),e.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(K.semi):this.semicolon(),this.finishNode(e,`DoWhileStatement`)},q.parseForStatement=function(e){this.next();var t=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual(`await`)?this.lastTokStart:-1;if(this.labels.push(DS),this.enterScope(0),this.expect(K.parenL),this.type===K.semi)return t>-1&&this.unexpected(t),this.parseFor(e,null);var n=this.isLet();if(this.type===K._var||this.type===K._const||n){var r=this.startNode(),i=n?`let`:this.value;return this.next(),this.parseVar(r,!0,i),this.finishNode(r,`VariableDeclaration`),this.parseForAfterInit(e,r,t)}var a=this.isContextual(`let`),o=!1,s=this.isUsing(!0)?`using`:this.isAwaitUsing(!0)?`await using`:null;if(s){var c=this.startNode();return this.next(),s===`await using`&&(this.canAwait||this.raise(this.start,`Await using cannot appear outside of async function`),this.next()),this.parseVar(c,!0,s),this.finishNode(c,`VariableDeclaration`),this.parseForAfterInit(e,c,t)}var l=this.containsEsc,u=new ES,d=this.start,f=t>-1?this.parseExprSubscripts(u,`await`):this.parseExpression(!0,u);return this.type===K._in||(o=this.options.ecmaVersion>=6&&this.isContextual(`of`))?(t>-1?(this.type===K._in&&this.unexpected(t),e.await=!0):o&&this.options.ecmaVersion>=8&&(f.start===d&&!l&&f.type===`Identifier`&&f.name===`async`?this.unexpected():this.options.ecmaVersion>=9&&(e.await=!1)),a&&o&&this.raise(f.start,`The left-hand side of a for-of loop may not start with 'let'.`),this.toAssignable(f,!1,u),this.checkLValPattern(f),this.parseForIn(e,f)):(this.checkExpressionErrors(u,!0),t>-1&&this.unexpected(t),this.parseFor(e,f))},q.parseForAfterInit=function(e,t,n){return(this.type===K._in||this.options.ecmaVersion>=6&&this.isContextual(`of`))&&t.declarations.length===1?(this.type===K._in?((t.kind===`using`||t.kind===`await using`)&&!t.declarations[0].init&&this.raise(this.start,`Using declaration is not allowed in for-in loops`),this.options.ecmaVersion>=9&&n>-1&&this.unexpected(n)):this.options.ecmaVersion>=9&&(e.await=n>-1),this.parseForIn(e,t)):(n>-1&&this.unexpected(n),this.parseFor(e,t))},q.parseFunctionStatement=function(e,t,n){return this.next(),this.parseFunction(e,AS|(n?0:jS),!1,t)},q.parseIfStatement=function(e){return this.next(),e.test=this.parseParenExpression(),e.consequent=this.parseStatement(`if`),e.alternate=this.eat(K._else)?this.parseStatement(`if`):null,this.finishNode(e,`IfStatement`)},q.parseReturnStatement=function(e){return this.allowReturn||this.raise(this.start,`'return' outside of function`),this.next(),this.eat(K.semi)||this.insertSemicolon()?e.argument=null:(e.argument=this.parseExpression(),this.semicolon()),this.finishNode(e,`ReturnStatement`)},q.parseSwitchStatement=function(e){this.next(),e.discriminant=this.parseParenExpression(),e.cases=[],this.expect(K.braceL),this.labels.push(OS),this.enterScope(pS);for(var t,n=!1;this.type!==K.braceR;)if(this.type===K._case||this.type===K._default){var r=this.type===K._case;t&&this.finishNode(t,`SwitchCase`),e.cases.push(t=this.startNode()),t.consequent=[],this.next(),r?t.test=this.parseExpression():(n&&this.raiseRecoverable(this.lastTokStart,`Multiple default clauses`),n=!0,t.test=null),this.expect(K.colon)}else t||this.unexpected(),t.consequent.push(this.parseStatement(null));return this.exitScope(),t&&this.finishNode(t,`SwitchCase`),this.next(),this.labels.pop(),this.finishNode(e,`SwitchStatement`)},q.parseThrowStatement=function(e){return this.next(),Fx.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,`Illegal newline after throw`),e.argument=this.parseExpression(),this.semicolon(),this.finishNode(e,`ThrowStatement`)};var kS=[];q.parseCatchClauseParam=function(){var e=this.parseBindingAtom(),t=e.type===`Identifier`;return this.enterScope(t?cS:0),this.checkLValPattern(e,t?bS:vS),this.expect(K.parenR),e},q.parseTryStatement=function(e){if(this.next(),e.block=this.parseBlock(),e.handler=null,this.type===K._catch){var t=this.startNode();this.next(),this.eat(K.parenL)?t.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),t.param=null,this.enterScope(0)),t.body=this.parseBlock(!1),this.exitScope(),e.handler=this.finishNode(t,`CatchClause`)}return e.finalizer=this.eat(K._finally)?this.parseBlock():null,!e.handler&&!e.finalizer&&this.raise(e.start,`Missing catch or finally clause`),this.finishNode(e,`TryStatement`)},q.parseVarStatement=function(e,t,n){return this.next(),this.parseVar(e,!1,t,n),this.semicolon(),this.finishNode(e,`VariableDeclaration`)},q.parseWhileStatement=function(e){return this.next(),e.test=this.parseParenExpression(),this.labels.push(DS),e.body=this.parseStatement(`while`),this.labels.pop(),this.finishNode(e,`WhileStatement`)},q.parseWithStatement=function(e){return this.strict&&this.raise(this.start,`'with' in strict mode`),this.next(),e.object=this.parseParenExpression(),e.body=this.parseStatement(`with`),this.finishNode(e,`WithStatement`)},q.parseEmptyStatement=function(e){return this.next(),this.finishNode(e,`EmptyStatement`)},q.parseLabeledStatement=function(e,t,n,r){for(var i=0,a=this.labels;i<a.length;i+=1)a[i].name===t&&this.raise(n.start,`Label '`+t+`' is already declared`);for(var o=this.type.isLoop?`loop`:this.type===K._switch?`switch`:null,s=this.labels.length-1;s>=0;s--){var c=this.labels[s];if(c.statementStart===e.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:t,kind:o,statementStart:this.start}),e.body=this.parseStatement(r?r.indexOf(`label`)===-1?r+`label`:r:`label`),this.labels.pop(),e.label=n,this.finishNode(e,`LabeledStatement`)},q.parseExpressionStatement=function(e,t){return e.expression=t,this.semicolon(),this.finishNode(e,`ExpressionStatement`)},q.parseBlock=function(e,t,n){for(e===void 0&&(e=!0),t===void 0&&(t=this.startNode()),t.body=[],this.expect(K.braceL),e&&this.enterScope(0);this.type!==K.braceR;){var r=this.parseStatement(null);t.body.push(r)}return n&&(this.strict=!1),this.next(),e&&this.exitScope(),this.finishNode(t,`BlockStatement`)},q.parseFor=function(e,t){return e.init=t,this.expect(K.semi),e.test=this.type===K.semi?null:this.parseExpression(),this.expect(K.semi),e.update=this.type===K.parenR?null:this.parseExpression(),this.expect(K.parenR),e.body=this.parseStatement(`for`),this.exitScope(),this.labels.pop(),this.finishNode(e,`ForStatement`)},q.parseForIn=function(e,t){var n=this.type===K._in;return this.next(),t.type===`VariableDeclaration`&&t.declarations[0].init!=null&&(!n||this.options.ecmaVersion<8||this.strict||t.kind!==`var`||t.declarations[0].id.type!==`Identifier`)&&this.raise(t.start,(n?`for-in`:`for-of`)+` loop variable declaration may not have an initializer`),e.left=t,e.right=n?this.parseExpression():this.parseMaybeAssign(),this.expect(K.parenR),e.body=this.parseStatement(`for`),this.exitScope(),this.labels.pop(),this.finishNode(e,n?`ForInStatement`:`ForOfStatement`)},q.parseVar=function(e,t,n,r){for(e.declarations=[],e.kind=n;;){var i=this.startNode();if(this.parseVarId(i,n),this.eat(K.eq)?i.init=this.parseMaybeAssign(t):!r&&n===`const`&&!(this.type===K._in||this.options.ecmaVersion>=6&&this.isContextual(`of`))?this.unexpected():!r&&(n===`using`||n===`await using`)&&this.options.ecmaVersion>=17&&this.type!==K._in&&!this.isContextual(`of`)?this.raise(this.lastTokEnd,`Missing initializer in `+n+` declaration`):!r&&i.id.type!==`Identifier`&&!(t&&(this.type===K._in||this.isContextual(`of`)))?this.raise(this.lastTokEnd,`Complex binding patterns require an initialization value`):i.init=null,e.declarations.push(this.finishNode(i,`VariableDeclarator`)),!this.eat(K.comma))break}return e},q.parseVarId=function(e,t){e.id=t===`using`||t===`await using`?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(e.id,t===`var`?_S:vS,!1)};var AS=1,jS=2,MS=4;q.parseFunction=function(e,t,n,r,i){this.initFunction(e),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===K.star&&t&jS&&this.unexpected(),e.generator=this.eat(K.star)),this.options.ecmaVersion>=8&&(e.async=!!r),t&AS&&(e.id=t&MS&&this.type!==K.name?null:this.parseIdent(),e.id&&!(t&jS)&&this.checkLValSimple(e.id,this.strict||e.generator||e.async?this.treatFunctionsAsVar?_S:vS:yS));var a=this.yieldPos,o=this.awaitPos,s=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(hS(e.async,e.generator)),t&AS||(e.id=this.type===K.name?this.parseIdent():null),this.parseFunctionParams(e),this.parseFunctionBody(e,n,!1,i),this.yieldPos=a,this.awaitPos=o,this.awaitIdentPos=s,this.finishNode(e,t&AS?`FunctionDeclaration`:`FunctionExpression`)},q.parseFunctionParams=function(e){this.expect(K.parenL),e.params=this.parseBindingList(K.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()},q.parseClass=function(e,t){this.next();var n=this.strict;this.strict=!0,this.parseClassId(e,t),this.parseClassSuper(e);var r=this.enterClassBody(),i=this.startNode(),a=!1;for(i.body=[],this.expect(K.braceL);this.type!==K.braceR;){var o=this.parseClassElement(e.superClass!==null);o&&(i.body.push(o),o.type===`MethodDefinition`&&o.kind===`constructor`?(a&&this.raiseRecoverable(o.start,`Duplicate constructor in the same class`),a=!0):o.key&&o.key.type===`PrivateIdentifier`&&NS(r,o)&&this.raiseRecoverable(o.key.start,`Identifier '#`+o.key.name+`' has already been declared`))}return this.strict=n,this.next(),e.body=this.finishNode(i,`ClassBody`),this.exitClassBody(),this.finishNode(e,t?`ClassDeclaration`:`ClassExpression`)},q.parseClassElement=function(e){if(this.eat(K.semi))return null;var t=this.options.ecmaVersion,n=this.startNode(),r=``,i=!1,a=!1,o=`method`,s=!1;if(this.eatContextual(`static`)){if(t>=13&&this.eat(K.braceL))return this.parseClassStaticBlock(n),n;this.isClassElementNameStart()||this.type===K.star?s=!0:r=`static`}if(n.static=s,!r&&t>=8&&this.eatContextual(`async`)&&((this.isClassElementNameStart()||this.type===K.star)&&!this.canInsertSemicolon()?a=!0:r=`async`),!r&&(t>=9||!a)&&this.eat(K.star)&&(i=!0),!r&&!a&&!i){var c=this.value;(this.eatContextual(`get`)||this.eatContextual(`set`))&&(this.isClassElementNameStart()?o=c:r=c)}if(r?(n.computed=!1,n.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),n.key.name=r,this.finishNode(n.key,`Identifier`)):this.parseClassElementName(n),t<13||this.type===K.parenL||o!==`method`||i||a){var l=!n.static&&PS(n,`constructor`),u=l&&e;l&&o!==`method`&&this.raise(n.key.start,`Constructor can't have get/set modifier`),n.kind=l?`constructor`:o,this.parseClassMethod(n,i,a,u)}else this.parseClassField(n);return n},q.isClassElementNameStart=function(){return this.type===K.name||this.type===K.privateId||this.type===K.num||this.type===K.string||this.type===K.bracketL||this.type.keyword},q.parseClassElementName=function(e){this.type===K.privateId?(this.value===`constructor`&&this.raise(this.start,`Classes can't have an element named '#constructor'`),e.computed=!1,e.key=this.parsePrivateIdent()):this.parsePropertyName(e)},q.parseClassMethod=function(e,t,n,r){var i=e.key;e.kind===`constructor`?(t&&this.raise(i.start,`Constructor can't be a generator`),n&&this.raise(i.start,`Constructor can't be an async method`)):e.static&&PS(e,`prototype`)&&this.raise(i.start,`Classes may not have a static property named prototype`);var a=e.value=this.parseMethod(t,n,r);return e.kind===`get`&&a.params.length!==0&&this.raiseRecoverable(a.start,`getter should have no params`),e.kind===`set`&&a.params.length!==1&&this.raiseRecoverable(a.start,`setter should have exactly one param`),e.kind===`set`&&a.params[0].type===`RestElement`&&this.raiseRecoverable(a.params[0].start,`Setter cannot use rest params`),this.finishNode(e,`MethodDefinition`)},q.parseClassField=function(e){return PS(e,`constructor`)?this.raise(e.key.start,`Classes can't have a field named 'constructor'`):e.static&&PS(e,`prototype`)&&this.raise(e.key.start,`Classes can't have a static field named 'prototype'`),this.eat(K.eq)?(this.enterScope(fS|lS),e.value=this.parseMaybeAssign(),this.exitScope()):e.value=null,this.semicolon(),this.finishNode(e,`PropertyDefinition`)},q.parseClassStaticBlock=function(e){e.body=[];var t=this.labels;for(this.labels=[],this.enterScope(dS|lS);this.type!==K.braceR;){var n=this.parseStatement(null);e.body.push(n)}return this.next(),this.exitScope(),this.labels=t,this.finishNode(e,`StaticBlock`)},q.parseClassId=function(e,t){this.type===K.name?(e.id=this.parseIdent(),t&&this.checkLValSimple(e.id,vS,!1)):(t===!0&&this.unexpected(),e.id=null)},q.parseClassSuper=function(e){e.superClass=this.eat(K._extends)?this.parseExprSubscripts(null,!1):null},q.enterClassBody=function(){var e={declared:Object.create(null),used:[]};return this.privateNameStack.push(e),e.declared},q.exitClassBody=function(){var e=this.privateNameStack.pop(),t=e.declared,n=e.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,i=r===0?null:this.privateNameStack[r-1],a=0;a<n.length;++a){var o=n[a];Wx(t,o.name)||(i?i.used.push(o):this.raiseRecoverable(o.start,`Private field '#`+o.name+`' must be declared in an enclosing class`))}};function NS(e,t){var n=t.key.name,r=e[n],i=`true`;return t.type===`MethodDefinition`&&(t.kind===`get`||t.kind===`set`)&&(i=(t.static?`s`:`i`)+t.kind),r===`iget`&&i===`iset`||r===`iset`&&i===`iget`||r===`sget`&&i===`sset`||r===`sset`&&i===`sget`?(e[n]=`true`,!1):r?!0:(e[n]=i,!1)}function PS(e,t){var n=e.computed,r=e.key;return!n&&(r.type===`Identifier`&&r.name===t||r.type===`Literal`&&r.value===t)}q.parseExportAllDeclaration=function(e,t){return this.options.ecmaVersion>=11&&(this.eatContextual(`as`)?(e.exported=this.parseModuleExportName(),this.checkExport(t,e.exported,this.lastTokStart)):e.exported=null),this.expectContextual(`from`),this.type!==K.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,`ExportAllDeclaration`)},q.parseExport=function(e,t){if(this.next(),this.eat(K.star))return this.parseExportAllDeclaration(e,t);if(this.eat(K._default))return this.checkExport(t,`default`,this.lastTokStart),e.declaration=this.parseExportDefaultDeclaration(),this.finishNode(e,`ExportDefaultDeclaration`);if(this.shouldParseExportStatement())e.declaration=this.parseExportDeclaration(e),e.declaration.type===`VariableDeclaration`?this.checkVariableExport(t,e.declaration.declarations):this.checkExport(t,e.declaration.id,e.declaration.id.start),e.specifiers=[],e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[]);else{if(e.declaration=null,e.specifiers=this.parseExportSpecifiers(t),this.eatContextual(`from`))this.type!==K.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause());else{for(var n=0,r=e.specifiers;n<r.length;n+=1){var i=r[n];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type===`Literal`&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[])}this.semicolon()}return this.finishNode(e,`ExportNamedDeclaration`)},q.parseExportDeclaration=function(e){return this.parseStatement(null)},q.parseExportDefaultDeclaration=function(){var e;if(this.type===K._function||(e=this.isAsyncFunction())){var t=this.startNode();return this.next(),e&&this.next(),this.parseFunction(t,AS|MS,!1,e)}if(this.type===K._class){var n=this.startNode();return this.parseClass(n,`nullableID`)}var r=this.parseMaybeAssign();return this.semicolon(),r},q.checkExport=function(e,t,n){e&&(typeof t!=`string`&&(t=t.type===`Identifier`?t.name:t.value),Wx(e,t)&&this.raiseRecoverable(n,`Duplicate export '`+t+`'`),e[t]=!0)},q.checkPatternExport=function(e,t){var n=t.type;if(n===`Identifier`)this.checkExport(e,t,t.start);else if(n===`ObjectPattern`)for(var r=0,i=t.properties;r<i.length;r+=1){var a=i[r];this.checkPatternExport(e,a)}else if(n===`ArrayPattern`)for(var o=0,s=t.elements;o<s.length;o+=1){var c=s[o];c&&this.checkPatternExport(e,c)}else n===`Property`?this.checkPatternExport(e,t.value):n===`AssignmentPattern`?this.checkPatternExport(e,t.left):n===`RestElement`&&this.checkPatternExport(e,t.argument)},q.checkVariableExport=function(e,t){if(e)for(var n=0,r=t;n<r.length;n+=1){var i=r[n];this.checkPatternExport(e,i.id)}},q.shouldParseExportStatement=function(){return this.type.keyword===`var`||this.type.keyword===`const`||this.type.keyword===`class`||this.type.keyword===`function`||this.isLet()||this.isAsyncFunction()},q.parseExportSpecifier=function(e){var t=this.startNode();return t.local=this.parseModuleExportName(),t.exported=this.eatContextual(`as`)?this.parseModuleExportName():t.local,this.checkExport(e,t.exported,t.exported.start),this.finishNode(t,`ExportSpecifier`)},q.parseExportSpecifiers=function(e){var t=[],n=!0;for(this.expect(K.braceL);!this.eat(K.braceR);){if(n)n=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;t.push(this.parseExportSpecifier(e))}return t},q.parseImport=function(e){return this.next(),this.type===K.string?(e.specifiers=kS,e.source=this.parseExprAtom()):(e.specifiers=this.parseImportSpecifiers(),this.expectContextual(`from`),e.source=this.type===K.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,`ImportDeclaration`)},q.parseImportSpecifier=function(){var e=this.startNode();return e.imported=this.parseModuleExportName(),this.eatContextual(`as`)?e.local=this.parseIdent():(this.checkUnreserved(e.imported),e.local=e.imported),this.checkLValSimple(e.local,vS),this.finishNode(e,`ImportSpecifier`)},q.parseImportDefaultSpecifier=function(){var e=this.startNode();return e.local=this.parseIdent(),this.checkLValSimple(e.local,vS),this.finishNode(e,`ImportDefaultSpecifier`)},q.parseImportNamespaceSpecifier=function(){var e=this.startNode();return this.next(),this.expectContextual(`as`),e.local=this.parseIdent(),this.checkLValSimple(e.local,vS),this.finishNode(e,`ImportNamespaceSpecifier`)},q.parseImportSpecifiers=function(){var e=[],t=!0;if(this.type===K.name&&(e.push(this.parseImportDefaultSpecifier()),!this.eat(K.comma)))return e;if(this.type===K.star)return e.push(this.parseImportNamespaceSpecifier()),e;for(this.expect(K.braceL);!this.eat(K.braceR);){if(t)t=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;e.push(this.parseImportSpecifier())}return e},q.parseWithClause=function(){var e=[];if(!this.eat(K._with))return e;this.expect(K.braceL);for(var t={},n=!0;!this.eat(K.braceR);){if(n)n=!1;else if(this.expect(K.comma),this.afterTrailingComma(K.braceR))break;var r=this.parseImportAttribute(),i=r.key.type===`Identifier`?r.key.name:r.key.value;Wx(t,i)&&this.raiseRecoverable(r.key.start,`Duplicate attribute key '`+i+`'`),t[i]=!0,e.push(r)}return e},q.parseImportAttribute=function(){var e=this.startNode();return e.key=this.type===K.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!==`never`),this.expect(K.colon),this.type!==K.string&&this.unexpected(),e.value=this.parseExprAtom(),this.finishNode(e,`ImportAttribute`)},q.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===K.string){var e=this.parseLiteral(this.value);return Yx.test(e.value)&&this.raise(e.start,`An export name cannot include a lone surrogate.`),e}return this.parseIdent(!0)},q.adaptDirectivePrologue=function(e){for(var t=0;t<e.length&&this.isDirectiveCandidate(e[t]);++t)e[t].directive=e[t].expression.raw.slice(1,-1)},q.isDirectiveCandidate=function(e){return this.options.ecmaVersion>=5&&e.type===`ExpressionStatement`&&e.expression.type===`Literal`&&typeof e.expression.value==`string`&&(this.input[e.start]===`"`||this.input[e.start]===`'`)};var FS=SS.prototype;FS.toAssignable=function(e,t,n){if(this.options.ecmaVersion>=6&&e)switch(e.type){case`Identifier`:this.inAsync&&e.name===`await`&&this.raise(e.start,`Cannot use 'await' as identifier inside an async function`);break;case`ObjectPattern`:case`ArrayPattern`:case`AssignmentPattern`:case`RestElement`:break;case`ObjectExpression`:e.type=`ObjectPattern`,n&&this.checkPatternErrors(n,!0);for(var r=0,i=e.properties;r<i.length;r+=1){var a=i[r];this.toAssignable(a,t),a.type===`RestElement`&&(a.argument.type===`ArrayPattern`||a.argument.type===`ObjectPattern`)&&this.raise(a.argument.start,`Unexpected token`)}break;case`Property`:e.kind!==`init`&&this.raise(e.key.start,`Object pattern can't contain getter or setter`),this.toAssignable(e.value,t);break;case`ArrayExpression`:e.type=`ArrayPattern`,n&&this.checkPatternErrors(n,!0),this.toAssignableList(e.elements,t);break;case`SpreadElement`:e.type=`RestElement`,this.toAssignable(e.argument,t),e.argument.type===`AssignmentPattern`&&this.raise(e.argument.start,`Rest elements cannot have a default value`);break;case`AssignmentExpression`:e.operator!==`=`&&this.raise(e.left.end,`Only '=' operator can be used for specifying default value.`),e.type=`AssignmentPattern`,delete e.operator,this.toAssignable(e.left,t);break;case`ParenthesizedExpression`:this.toAssignable(e.expression,t,n);break;case`ChainExpression`:this.raiseRecoverable(e.start,`Optional chaining cannot appear in left-hand side`);break;case`MemberExpression`:if(!t)break;default:this.raise(e.start,`Assigning to rvalue`)}else n&&this.checkPatternErrors(n,!0);return e},FS.toAssignableList=function(e,t){for(var n=e.length,r=0;r<n;r++){var i=e[r];i&&this.toAssignable(i,t)}if(n){var a=e[n-1];this.options.ecmaVersion===6&&t&&a&&a.type===`RestElement`&&a.argument.type!==`Identifier`&&this.unexpected(a.argument.start)}return e},FS.parseSpread=function(e){var t=this.startNode();return this.next(),t.argument=this.parseMaybeAssign(!1,e),this.finishNode(t,`SpreadElement`)},FS.parseRestBinding=function(){var e=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==K.name&&this.unexpected(),e.argument=this.parseBindingAtom(),this.finishNode(e,`RestElement`)},FS.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case K.bracketL:var e=this.startNode();return this.next(),e.elements=this.parseBindingList(K.bracketR,!0,!0),this.finishNode(e,`ArrayPattern`);case K.braceL:return this.parseObj(!0)}return this.parseIdent()},FS.parseBindingList=function(e,t,n,r){for(var i=[],a=!0;!this.eat(e);)if(a?a=!1:this.expect(K.comma),t&&this.type===K.comma)i.push(null);else if(n&&this.afterTrailingComma(e))break;else if(this.type===K.ellipsis){var o=this.parseRestBinding();this.parseBindingListItem(o),i.push(o),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`),this.expect(e);break}else i.push(this.parseAssignableListItem(r));return i},FS.parseAssignableListItem=function(e){var t=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(t),t},FS.parseBindingListItem=function(e){return e},FS.parseMaybeDefault=function(e,t,n){if(n||=this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(K.eq))return n;var r=this.startNodeAt(e,t);return r.left=n,r.right=this.parseMaybeAssign(),this.finishNode(r,`AssignmentPattern`)},FS.checkLValSimple=function(e,t,n){t===void 0&&(t=gS);var r=t!==gS;switch(e.type){case`Identifier`:this.strict&&this.reservedWordsStrictBind.test(e.name)&&this.raiseRecoverable(e.start,(r?`Binding `:`Assigning to `)+e.name+` in strict mode`),r&&(t===vS&&e.name===`let`&&this.raiseRecoverable(e.start,`let is disallowed as a lexically bound name`),n&&(Wx(n,e.name)&&this.raiseRecoverable(e.start,`Argument name clash`),n[e.name]=!0),t!==xS&&this.declareName(e.name,t,e.start));break;case`ChainExpression`:this.raiseRecoverable(e.start,`Optional chaining cannot appear in left-hand side`);break;case`MemberExpression`:r&&this.raiseRecoverable(e.start,`Binding member expression`);break;case`ParenthesizedExpression`:return r&&this.raiseRecoverable(e.start,`Binding parenthesized expression`),this.checkLValSimple(e.expression,t,n);default:this.raise(e.start,(r?`Binding`:`Assigning to`)+` rvalue`)}},FS.checkLValPattern=function(e,t,n){switch(t===void 0&&(t=gS),e.type){case`ObjectPattern`:for(var r=0,i=e.properties;r<i.length;r+=1){var a=i[r];this.checkLValInnerPattern(a,t,n)}break;case`ArrayPattern`:for(var o=0,s=e.elements;o<s.length;o+=1){var c=s[o];c&&this.checkLValInnerPattern(c,t,n)}break;default:this.checkLValSimple(e,t,n)}},FS.checkLValInnerPattern=function(e,t,n){switch(t===void 0&&(t=gS),e.type){case`Property`:this.checkLValInnerPattern(e.value,t,n);break;case`AssignmentPattern`:this.checkLValPattern(e.left,t,n);break;case`RestElement`:this.checkLValPattern(e.argument,t,n);break;default:this.checkLValPattern(e,t,n)}};var IS=function(e,t,n,r,i){this.token=e,this.isExpr=!!t,this.preserveSpace=!!n,this.override=r,this.generator=!!i},LS={b_stat:new IS(`{`,!1),b_expr:new IS(`{`,!0),b_tmpl:new IS("${",!1),p_stat:new IS(`(`,!1),p_expr:new IS(`(`,!0),q_tmpl:new IS("`",!0,!0,function(e){return e.tryReadTemplateToken()}),f_stat:new IS(`function`,!1),f_expr:new IS(`function`,!0),f_expr_gen:new IS(`function`,!0,!1,null,!0),f_gen:new IS(`function`,!1,!1,null,!0)},RS=SS.prototype;RS.initialContext=function(){return[LS.b_stat]},RS.curContext=function(){return this.context[this.context.length-1]},RS.braceIsBlock=function(e){var t=this.curContext();return t===LS.f_expr||t===LS.f_stat?!0:e===K.colon&&(t===LS.b_stat||t===LS.b_expr)?!t.isExpr:e===K._return||e===K.name&&this.exprAllowed?Fx.test(this.input.slice(this.lastTokEnd,this.start)):e===K._else||e===K.semi||e===K.eof||e===K.parenR||e===K.arrow?!0:e===K.braceL?t===LS.b_stat:e===K._var||e===K._const||e===K.name?!1:!this.exprAllowed},RS.inGeneratorContext=function(){for(var e=this.context.length-1;e>=1;e--){var t=this.context[e];if(t.token===`function`)return t.generator}return!1},RS.updateContext=function(e){var t,n=this.type;n.keyword&&e===K.dot?this.exprAllowed=!1:(t=n.updateContext)?t.call(this,e):this.exprAllowed=n.beforeExpr},RS.overrideContext=function(e){this.curContext()!==e&&(this.context[this.context.length-1]=e)},K.parenR.updateContext=K.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var e=this.context.pop();e===LS.b_stat&&this.curContext().token===`function`&&(e=this.context.pop()),this.exprAllowed=!e.isExpr},K.braceL.updateContext=function(e){this.context.push(this.braceIsBlock(e)?LS.b_stat:LS.b_expr),this.exprAllowed=!0},K.dollarBraceL.updateContext=function(){this.context.push(LS.b_tmpl),this.exprAllowed=!0},K.parenL.updateContext=function(e){var t=e===K._if||e===K._for||e===K._with||e===K._while;this.context.push(t?LS.p_stat:LS.p_expr),this.exprAllowed=!0},K.incDec.updateContext=function(){},K._function.updateContext=K._class.updateContext=function(e){e.beforeExpr&&e!==K._else&&(e!==K.semi||this.curContext()===LS.p_stat)&&!(e===K._return&&Fx.test(this.input.slice(this.lastTokEnd,this.start)))&&(e!==K.colon&&e!==K.braceL||this.curContext()!==LS.b_stat)?this.context.push(LS.f_expr):this.context.push(LS.f_stat),this.exprAllowed=!1},K.colon.updateContext=function(){this.curContext().token===`function`&&this.context.pop(),this.exprAllowed=!0},K.backQuote.updateContext=function(){this.curContext()===LS.q_tmpl?this.context.pop():this.context.push(LS.q_tmpl),this.exprAllowed=!1},K.star.updateContext=function(e){if(e===K._function){var t=this.context.length-1;this.context[t]===LS.f_expr?this.context[t]=LS.f_expr_gen:this.context[t]=LS.f_gen}this.exprAllowed=!0},K.name.updateContext=function(e){var t=!1;this.options.ecmaVersion>=6&&e!==K.dot&&(this.value===`of`&&!this.exprAllowed||this.value===`yield`&&this.inGeneratorContext())&&(t=!0),this.exprAllowed=t};var J=SS.prototype;J.checkPropClash=function(e,t,n){if(!(this.options.ecmaVersion>=9&&e.type===`SpreadElement`)&&!(this.options.ecmaVersion>=6&&(e.computed||e.method||e.shorthand))){var r=e.key,i;switch(r.type){case`Identifier`:i=r.name;break;case`Literal`:i=String(r.value);break;default:return}var a=e.kind;if(this.options.ecmaVersion>=6){i===`__proto__`&&a===`init`&&(t.proto&&(n?n.doubleProto<0&&(n.doubleProto=r.start):this.raiseRecoverable(r.start,`Redefinition of __proto__ property`)),t.proto=!0);return}i=`$`+i;var o=t[i];o?(a===`init`?this.strict&&o.init||o.get||o.set:o.init||o[a])&&this.raiseRecoverable(r.start,`Redefinition of property`):o=t[i]={init:!1,get:!1,set:!1},o[a]=!0}},J.parseExpression=function(e,t){var n=this;return this.catchStackOverflow(function(){var r=n.start,i=n.startLoc,a=n.parseMaybeAssign(e,t);if(n.type===K.comma){var o=n.startNodeAt(r,i);for(o.expressions=[a];n.eat(K.comma);)o.expressions.push(n.parseMaybeAssign(e,t));return n.finishNode(o,`SequenceExpression`)}return a})},J.parseMaybeAssign=function(e,t,n){if(this.isContextual(`yield`)){if(this.inGenerator)return this.parseYield(e);this.exprAllowed=!1}var r=!1,i=-1,a=-1,o=-1;t?(i=t.parenthesizedAssign,a=t.trailingComma,o=t.doubleProto,t.parenthesizedAssign=t.trailingComma=-1):(t=new ES,r=!0);var s=this.start,c=this.startLoc;(this.type===K.parenL||this.type===K.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=e===`await`);var l=this.parseMaybeConditional(e,t);if(n&&(l=n.call(this,l,s,c)),this.type.isAssign){var u=this.startNodeAt(s,c);return u.operator=this.value,this.type===K.eq&&(l=this.toAssignable(l,!1,t)),r||(t.parenthesizedAssign=t.trailingComma=t.doubleProto=-1),t.shorthandAssign>=l.start&&(t.shorthandAssign=-1),this.type===K.eq?this.checkLValPattern(l):this.checkLValSimple(l),u.left=l,this.next(),u.right=this.parseMaybeAssign(e),o>-1&&(t.doubleProto=o),this.finishNode(u,`AssignmentExpression`)}return r&&this.checkExpressionErrors(t,!0),i>-1&&(t.parenthesizedAssign=i),a>-1&&(t.trailingComma=a),l},J.parseMaybeConditional=function(e,t){var n=this.start,r=this.startLoc,i=this.parseExprOps(e,t);if(this.checkExpressionErrors(t))return i;if((i.type!==`ArrowFunctionExpression`||i.start!==n)&&this.eat(K.question)){var a=this.startNodeAt(n,r);return a.test=i,a.consequent=this.parseMaybeAssign(),this.expect(K.colon),a.alternate=this.parseMaybeAssign(e),this.finishNode(a,`ConditionalExpression`)}return i},J.parseExprOps=function(e,t){var n=this.start,r=this.startLoc,i=this.parseMaybeUnary(t,!1,!1,e);return this.checkExpressionErrors(t)||i.start===n&&i.type===`ArrowFunctionExpression`?i:this.parseExprOp(i,n,r,-1,e)},J.parseExprOp=function(e,t,n,r,i){var a=this.type.binop;if(a!=null&&(!i||this.type!==K._in)&&a>r){var o=this.type===K.logicalOR||this.type===K.logicalAND,s=this.type===K.coalesce;s&&(a=K.logicalAND.binop);var c=this.value;this.next();var l=this.start,u=this.startLoc,d=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),l,u,a,i),f=this.buildBinary(t,n,e,d,c,o||s);return(o&&this.type===K.coalesce||s&&(this.type===K.logicalOR||this.type===K.logicalAND))&&this.raiseRecoverable(this.start,`Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses`),this.parseExprOp(f,t,n,r,i)}return e},J.buildBinary=function(e,t,n,r,i,a){r.type===`PrivateIdentifier`&&this.raise(r.start,`Private identifier can only be left side of binary expression`);var o=this.startNodeAt(e,t);return o.left=n,o.operator=i,o.right=r,this.finishNode(o,a?`LogicalExpression`:`BinaryExpression`)},J.parseMaybeUnary=function(e,t,n,r){var i=this.start,a=this.startLoc,o;if(this.isContextual(`await`)&&this.canAwait)o=this.parseAwait(r),t=!0;else if(this.type.prefix){var s=this.startNode(),c=this.type===K.incDec;s.operator=this.value,s.prefix=!0,this.next(),s.argument=this.parseMaybeUnary(null,!0,c,r),this.checkExpressionErrors(e,!0),c?this.checkLValSimple(s.argument):this.strict&&s.operator===`delete`&&zS(s.argument)?this.raiseRecoverable(s.start,`Deleting local variable in strict mode`):s.operator===`delete`&&BS(s.argument)?this.raiseRecoverable(s.start,`Private fields can not be deleted`):t=!0,o=this.finishNode(s,c?`UpdateExpression`:`UnaryExpression`)}else if(!t&&this.type===K.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),o=this.parsePrivateIdent(),this.type!==K._in&&this.unexpected();else{if(o=this.parseExprSubscripts(e,r),this.checkExpressionErrors(e))return o;for(;this.type.postfix&&!this.canInsertSemicolon();){var l=this.startNodeAt(i,a);l.operator=this.value,l.prefix=!1,l.argument=o,this.checkLValSimple(o),this.next(),o=this.finishNode(l,`UpdateExpression`)}}if(!n&&(o.type!==`ArrowFunctionExpression`||o.start!==i)&&this.eat(K.starstar)){if(t)this.unexpected(this.lastTokStart);else return this.buildBinary(i,a,o,this.parseMaybeUnary(null,!1,!1,r),`**`,!1)}else return o};function zS(e){return e.type===`Identifier`||e.type===`ParenthesizedExpression`&&zS(e.expression)}function BS(e){return e.type===`MemberExpression`&&e.property.type===`PrivateIdentifier`||e.type===`ChainExpression`&&BS(e.expression)||e.type===`ParenthesizedExpression`&&BS(e.expression)}J.parseExprSubscripts=function(e,t){var n=this.start,r=this.startLoc,i=this.parseExprAtom(e,t);if(i.type===`ArrowFunctionExpression`&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==`)`)return i;var a=this.parseSubscripts(i,n,r,!1,t);return e&&a.type===`MemberExpression`&&(e.parenthesizedAssign>=a.start&&(e.parenthesizedAssign=-1),e.parenthesizedBind>=a.start&&(e.parenthesizedBind=-1),e.trailingComma>=a.start&&(e.trailingComma=-1)),a},J.parseSubscripts=function(e,t,n,r,i){for(var a=this.options.ecmaVersion>=8&&e.type===`Identifier`&&e.name===`async`&&this.lastTokEnd===e.end&&!this.canInsertSemicolon()&&e.end-e.start===5&&this.potentialArrowAt===e.start,o=!1;;){var s=this.parseSubscript(e,t,n,r,a,o,i);if(s.optional&&(o=!0),s===e||s.type===`ArrowFunctionExpression`){if(o){var c=this.startNodeAt(t,n);c.expression=s,s=this.finishNode(c,`ChainExpression`)}return s}e=s}},J.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(K.arrow)},J.parseSubscriptAsyncArrow=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!0,r)},J.parseSubscript=function(e,t,n,r,i,a,o){var s=this.options.ecmaVersion>=11,c=s&&this.eat(K.questionDot);r&&c&&this.raise(this.lastTokStart,`Optional chaining cannot appear in the callee of new expressions`);var l=this.eat(K.bracketL);if(l||c&&this.type!==K.parenL&&this.type!==K.backQuote||this.eat(K.dot)){var u=this.startNodeAt(t,n);u.object=e,l?(u.property=this.parseExpression(),this.expect(K.bracketR)):u.property=this.type===K.privateId&&e.type!==`Super`?this.parsePrivateIdent():this.parseIdent(this.options.allowReserved!==`never`),u.computed=!!l,s&&(u.optional=c),e=this.finishNode(u,`MemberExpression`)}else if(!r&&this.eat(K.parenL)){var d=new ES,f=this.yieldPos,p=this.awaitPos,m=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var ee=this.parseExprList(K.parenR,this.options.ecmaVersion>=8,!1,d);if(i&&!c&&this.shouldParseAsyncArrow())return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,`Cannot use 'await' as identifier inside an async function`),this.yieldPos=f,this.awaitPos=p,this.awaitIdentPos=m,this.parseSubscriptAsyncArrow(t,n,ee,o);this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=p||this.awaitPos,this.awaitIdentPos=m||this.awaitIdentPos;var te=this.startNodeAt(t,n);te.callee=e,te.arguments=ee,s&&(te.optional=c),e=this.finishNode(te,`CallExpression`)}else if(this.type===K.backQuote){(c||a)&&this.raise(this.start,`Optional chaining cannot appear in the tag of tagged template expressions`);var ne=this.startNodeAt(t,n);ne.tag=e,ne.quasi=this.parseTemplate({isTagged:!0}),e=this.finishNode(ne,`TaggedTemplateExpression`)}return e},J.parseExprAtom=function(e,t,n){this.type===K.slash&&this.readRegexp();var r,i=this.potentialArrowAt===this.start;switch(this.type){case K._super:return this.allowSuper||this.raise(this.start,`'super' keyword outside a method`),r=this.startNode(),this.next(),this.type===K.parenL&&!this.allowDirectSuper&&this.raise(r.start,`super() call outside constructor of a subclass`),this.type!==K.dot&&this.type!==K.bracketL&&this.type!==K.parenL&&this.unexpected(),this.finishNode(r,`Super`);case K._this:return r=this.startNode(),this.next(),this.finishNode(r,`ThisExpression`);case K.name:var a=this.start,o=this.startLoc,s=this.containsEsc,c=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!s&&c.name===`async`&&!this.canInsertSemicolon()&&this.eat(K._function))return this.overrideContext(LS.f_expr),this.parseFunction(this.startNodeAt(a,o),0,!1,!0,t);if(i&&!this.canInsertSemicolon()){if(this.eat(K.arrow))return this.parseArrowExpression(this.startNodeAt(a,o),[c],!1,t);if(this.options.ecmaVersion>=8&&c.name===`async`&&this.type===K.name&&!s&&(!this.potentialArrowInForAwait||this.value!==`of`||this.containsEsc))return c=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(K.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(a,o),[c],!0,t)}return c;case K.regexp:var l=this.value;return r=this.parseLiteral(l.value),r.regex={pattern:l.pattern,flags:l.flags},r;case K.num:case K.string:return this.parseLiteral(this.value);case K._null:case K._true:case K._false:return r=this.startNode(),r.value=this.type===K._null?null:this.type===K._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,`Literal`);case K.parenL:var u=this.start,d=this.parseParenAndDistinguishExpression(i,t);return e&&(e.parenthesizedAssign<0&&!this.isSimpleAssignTarget(d)&&(e.parenthesizedAssign=u),e.parenthesizedBind<0&&(e.parenthesizedBind=u)),d;case K.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(K.bracketR,!0,!0,e),this.finishNode(r,`ArrayExpression`);case K.braceL:return this.overrideContext(LS.b_expr),this.parseObj(!1,e);case K._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case K._class:return this.parseClass(this.startNode(),!1);case K._new:return this.parseNew();case K.backQuote:return this.parseTemplate();case K._import:return this.options.ecmaVersion>=11?this.parseExprImport(n):this.unexpected();default:return this.parseExprAtomDefault()}},J.parseExprAtomDefault=function(){this.unexpected()},J.parseExprImport=function(e){var t=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword import`),this.next(),this.type===K.parenL&&!e)return this.parseDynamicImport(t);if(this.type===K.dot){var n=this.startNodeAt(t.start,t.loc&&t.loc.start);return n.name=`import`,t.meta=this.finishNode(n,`Identifier`),this.parseImportMeta(t)}this.unexpected()},J.parseDynamicImport=function(e){if(this.next(),e.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(K.parenR)?e.options=null:(this.expect(K.comma),this.afterTrailingComma(K.parenR)?e.options=null:(e.options=this.parseMaybeAssign(),this.eat(K.parenR)||(this.expect(K.comma),this.afterTrailingComma(K.parenR)||this.unexpected())));else if(!this.eat(K.parenR)){var t=this.start;this.eat(K.comma)&&this.eat(K.parenR)?this.raiseRecoverable(t,`Trailing comma is not allowed in import()`):this.unexpected(t)}return this.finishNode(e,`ImportExpression`)},J.parseImportMeta=function(e){this.next();var t=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!==`meta`&&this.raiseRecoverable(e.property.start,`The only valid meta property for import is 'import.meta'`),t&&this.raiseRecoverable(e.start,`'import.meta' must not contain escaped characters`),this.options.sourceType!==`module`&&!this.options.allowImportExportEverywhere&&this.raiseRecoverable(e.start,`Cannot use 'import.meta' outside a module`),this.finishNode(e,`MetaProperty`)},J.parseLiteral=function(e){var t=this.startNode();return t.value=e,t.raw=this.input.slice(this.start,this.end),t.raw.charCodeAt(t.raw.length-1)===110&&(t.bigint=t.value==null?t.raw.slice(0,-1).replace(/_/g,``):t.value.toString()),this.next(),this.finishNode(t,`Literal`)},J.parseParenExpression=function(){this.expect(K.parenL);var e=this.parseExpression();return this.expect(K.parenR),e},J.shouldParseArrow=function(e){return!this.canInsertSemicolon()},J.parseParenAndDistinguishExpression=function(e,t){var n=this.start,r=this.startLoc,i,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var o=this.start,s=this.startLoc,c=[],l=!0,u=!1,d=new ES,f=this.yieldPos,p=this.awaitPos,m;for(this.yieldPos=0,this.awaitPos=0;this.type!==K.parenR;){if(l?l=!1:this.expect(K.comma),a&&this.afterTrailingComma(K.parenR,!0)){u=!0;break}if(this.type===K.ellipsis){m=this.start,c.push(this.parseParenItem(this.parseRestBinding())),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`);break}c.push(this.parseMaybeAssign(!1,d,this.parseParenItem))}var ee=this.lastTokEnd,te=this.lastTokEndLoc;if(this.expect(K.parenR),e&&this.shouldParseArrow(c)&&this.eat(K.arrow))return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=f,this.awaitPos=p,this.parseParenArrowList(n,r,c,t);(!c.length||u)&&this.unexpected(this.lastTokStart),m&&this.unexpected(m),this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=p||this.awaitPos,c.length>1?(i=this.startNodeAt(o,s),i.expressions=c,this.finishNodeAt(i,`SequenceExpression`,ee,te)):i=c[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var ne=this.startNodeAt(n,r);return ne.expression=i,this.finishNode(ne,`ParenthesizedExpression`)}return i},J.parseParenItem=function(e){return e},J.parseParenArrowList=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!1,r)};var VS=[];J.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword new`);var e=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===K.dot){var t=this.startNodeAt(e.start,e.loc&&e.loc.start);t.name=`new`,e.meta=this.finishNode(t,`Identifier`),this.next();var n=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!==`target`&&this.raiseRecoverable(e.property.start,`The only valid meta property for new is 'new.target'`),n&&this.raiseRecoverable(e.start,`'new.target' must not contain escaped characters`),this.allowNewDotTarget||this.raiseRecoverable(e.start,`'new.target' can only be used in functions and class static block`),this.finishNode(e,`MetaProperty`)}var r=this.start,i=this.startLoc;return e.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,i,!0,!1),e.callee.type===`Super`&&this.raiseRecoverable(r,`Invalid use of 'super'`),e.arguments=this.eat(K.parenL)?this.parseExprList(K.parenR,this.options.ecmaVersion>=8,!1):VS,this.finishNode(e,`NewExpression`)},J.parseTemplateElement=function(e){var t=e.isTagged,n=this.startNode();return this.type===K.invalidTemplate?(t||this.raiseRecoverable(this.start,`Bad escape sequence in untagged template literal`),n.value={raw:this.value.replace(/\r\n?/g,`
|
|
12
12
|
`),cooked:null}):n.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,`
|
|
13
|
-
`),cooked:this.value},this.next(),n.tail=this.type===K.backQuote,this.finishNode(n,`TemplateElement`)},J.parseTemplate=function(e){e===void 0&&(e={});var t=e.isTagged;t===void 0&&(t=!1);var n=this.startNode();this.next(),n.expressions=[];var r=this.parseTemplateElement({isTagged:t});for(n.quasis=[r];!r.tail;)this.type===K.eof&&this.raise(this.pos,`Unterminated template literal`),this.expect(K.dollarBraceL),n.expressions.push(this.parseExpression()),this.expect(K.braceR),n.quasis.push(r=this.parseTemplateElement({isTagged:t}));return this.next(),this.finishNode(n,`TemplateLiteral`)},J.isAsyncProp=function(e){return!e.computed&&e.key.type===`Identifier`&&e.key.name===`async`&&(this.type===K.name||this.type===K.num||this.type===K.string||this.type===K.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===K.star)&&!Px.test(this.input.slice(this.lastTokEnd,this.start))},J.parseObj=function(e,t){var n=this.startNode(),r=!0,i={};for(n.properties=[],this.next();!this.eat(K.braceR);){if(r)r=!1;else if(this.expect(K.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(K.braceR))break;var a=this.parseProperty(e,t);e||this.checkPropClash(a,i,t),n.properties.push(a)}return this.finishNode(n,e?`ObjectPattern`:`ObjectExpression`)},J.parseProperty=function(e,t){var n=this.startNode(),r,i,a,o;if(this.options.ecmaVersion>=9&&this.eat(K.ellipsis))return e?(n.argument=this.parseIdent(!1),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`),this.finishNode(n,`RestElement`)):(n.argument=this.parseMaybeAssign(!1,t),this.type===K.comma&&t&&t.trailingComma<0&&(t.trailingComma=this.start),this.finishNode(n,`SpreadElement`));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(e||t)&&(a=this.start,o=this.startLoc),e||(r=this.eat(K.star)));var s=this.containsEsc;return this.parsePropertyName(n),!e&&!s&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(n)?(i=!0,r=this.options.ecmaVersion>=9&&this.eat(K.star),this.parsePropertyName(n)):i=!1,this.parsePropertyValue(n,e,r,i,a,o,t,s),this.finishNode(n,`Property`)},J.parseGetterSetter=function(e){var t=e.key.name;this.parsePropertyName(e),e.value=this.parseMethod(!1),e.kind=t;var n=e.kind===`get`?0:1;if(e.value.params.length!==n){var r=e.value.start;e.kind===`get`?this.raiseRecoverable(r,`getter should have no params`):this.raiseRecoverable(r,`setter should have exactly one param`)}else e.kind===`set`&&e.value.params[0].type===`RestElement`&&this.raiseRecoverable(e.value.params[0].start,`Setter cannot use rest params`)},J.parsePropertyValue=function(e,t,n,r,i,a,o,s){(n||r)&&this.type===K.colon&&this.unexpected(),this.eat(K.colon)?(e.value=t?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,o),e.kind=`init`):this.options.ecmaVersion>=6&&this.type===K.parenL?(t&&this.unexpected(),e.method=!0,e.value=this.parseMethod(n,r),e.kind=`init`):!t&&!s&&this.options.ecmaVersion>=5&&!e.computed&&e.key.type===`Identifier`&&(e.key.name===`get`||e.key.name===`set`)&&this.type!==K.comma&&this.type!==K.braceR&&this.type!==K.eq?((n||r)&&this.unexpected(),this.parseGetterSetter(e)):this.options.ecmaVersion>=6&&!e.computed&&e.key.type===`Identifier`?((n||r)&&this.unexpected(),this.checkUnreserved(e.key),e.key.name===`await`&&!this.awaitIdentPos&&(this.awaitIdentPos=i),t?e.value=this.parseMaybeDefault(i,a,this.copyNode(e.key)):this.type===K.eq&&o?(o.shorthandAssign<0&&(o.shorthandAssign=this.start),e.value=this.parseMaybeDefault(i,a,this.copyNode(e.key))):e.value=this.copyNode(e.key),e.kind=`init`,e.shorthand=!0):this.unexpected()},J.parsePropertyName=function(e){if(this.options.ecmaVersion>=6){if(this.eat(K.bracketL))return e.computed=!0,e.key=this.parseMaybeAssign(),this.expect(K.bracketR),e.key;e.computed=!1}return e.key=this.type===K.num||this.type===K.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!==`never`)},J.initFunction=function(e){e.id=null,this.options.ecmaVersion>=6&&(e.generator=e.expression=!1),this.options.ecmaVersion>=8&&(e.async=!1)},J.parseMethod=function(e,t,n){var r=this.startNode(),i=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=e),this.options.ecmaVersion>=8&&(r.async=!!t),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(mS(t,r.generator)|cS|(n?lS:0)),this.expect(K.parenL),r.params=this.parseBindingList(K.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=i,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(r,`FunctionExpression`)},J.parseArrowExpression=function(e,t,n,r){var i=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.enterScope(mS(n,!1)|oS),this.initFunction(e),this.options.ecmaVersion>=8&&(e.async=!!n),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,e.params=this.toAssignableList(t,!0),this.parseFunctionBody(e,!0,!1,r),this.yieldPos=i,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(e,`ArrowFunctionExpression`)},J.parseFunctionBody=function(e,t,n,r){var i=t&&this.type!==K.braceL,a=this.strict,o=!1;if(i)e.body=this.parseMaybeAssign(r),e.expression=!0,this.checkParams(e,!1);else{var s=this.options.ecmaVersion>=7&&!this.isSimpleParamList(e.params);(!a||s)&&(o=this.strictDirective(this.end),o&&s&&this.raiseRecoverable(e.start,`Illegal 'use strict' directive in function with non-simple parameter list`));var c=this.labels;this.labels=[],o&&(this.strict=!0),this.checkParams(e,!a&&!o&&!t&&!n&&this.isSimpleParamList(e.params)),this.strict&&e.id&&this.checkLValSimple(e.id,bS),e.body=this.parseBlock(!1,void 0,o&&!a),e.expression=!1,this.adaptDirectivePrologue(e.body.body),this.labels=c}this.exitScope()},J.isSimpleParamList=function(e){for(var t=0,n=e;t<n.length;t+=1)if(n[t].type!==`Identifier`)return!1;return!0},J.checkParams=function(e,t){for(var n=Object.create(null),r=0,i=e.params;r<i.length;r+=1){var a=i[r];this.checkLValInnerPattern(a,gS,t?null:n)}},J.parseExprList=function(e,t,n,r){for(var i=[],a=!0;!this.eat(e);){if(a)a=!1;else if(this.expect(K.comma),t&&this.afterTrailingComma(e))break;var o=void 0;n&&this.type===K.comma?o=null:this.type===K.ellipsis?(o=this.parseSpread(r),r&&this.type===K.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):o=this.parseMaybeAssign(!1,r),i.push(o)}return i},J.checkUnreserved=function(e){var t=e.start,n=e.end,r=e.name;this.inGenerator&&r===`yield`&&this.raiseRecoverable(t,`Cannot use 'yield' as identifier inside a generator`),this.inAsync&&r===`await`&&this.raiseRecoverable(t,`Cannot use 'await' as identifier inside an async function`),!(this.currentThisScope().flags&pS)&&r===`arguments`&&this.raiseRecoverable(t,`Cannot use 'arguments' in class field initializer`),this.inClassStaticBlock&&(r===`arguments`||r===`await`)&&this.raise(t,`Cannot use `+r+` in class static initialization block`),this.keywords.test(r)&&this.raise(t,`Unexpected keyword '`+r+`'`),!(this.options.ecmaVersion<6&&this.input.slice(t,n).indexOf(`\\`)!==-1)&&(this.strict?this.reservedWordsStrict:this.reservedWords).test(r)&&(!this.inAsync&&r===`await`&&this.raiseRecoverable(t,`Cannot use keyword 'await' outside an async function`),this.raiseRecoverable(t,`The keyword '`+r+`' is reserved`))},J.parseIdent=function(e){var t=this.parseIdentNode();return this.next(!!e),this.finishNode(t,`Identifier`),e||(this.checkUnreserved(t),t.name===`await`&&!this.awaitIdentPos&&(this.awaitIdentPos=t.start)),t},J.parseIdentNode=function(){var e=this.startNode();return this.type===K.name?e.name=this.value:this.type.keyword?(e.name=this.type.keyword,(e.name===`class`||e.name===`function`)&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=K.name):this.unexpected(),e},J.parsePrivateIdent=function(){var e=this.startNode();return this.type===K.privateId?e.name=this.value:this.unexpected(),this.next(),this.finishNode(e,`PrivateIdentifier`),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(e.start,`Private field '#`+e.name+`' must be declared in an enclosing class`):this.privateNameStack[this.privateNameStack.length-1].used.push(e)),e},J.parseYield=function(e){this.yieldPos||=this.start;var t=this.startNode();return this.next(),this.type===K.semi||this.canInsertSemicolon()||this.type!==K.star&&!this.type.startsExpr?(t.delegate=!1,t.argument=null):(t.delegate=this.eat(K.star),t.argument=this.parseMaybeAssign(e)),this.finishNode(t,`YieldExpression`)},J.parseAwait=function(e){this.awaitPos||=this.start;var t=this.startNode();return this.next(),t.argument=this.parseMaybeUnary(null,!0,!1,e),this.finishNode(t,`AwaitExpression`)};var VS=xS.prototype;VS.raise=function(e,t){var n=Zx(this.input,e);t+=` (`+n.line+`:`+n.column+`)`,this.sourceFile&&(t+=` in `+this.sourceFile);var r=SyntaxError(t);throw r.pos=e,r.loc=n,r.raisedAt=this.pos,r},VS.raiseRecoverable=VS.raise,VS.curPosition=function(){if(this.options.locations)return new Yx(this.curLine,this.pos-this.lineStart)};var HS=xS.prototype,US=function(e){this.flags=e,this.var=[],this.lexical=[],this.functions=[]};HS.enterScope=function(e){this.scopeStack.push(new US(e))},HS.exitScope=function(){this.scopeStack.pop()},HS.treatFunctionsAsVarInScope=function(e){return e.flags&rS||!this.inModule&&e.flags&nS},HS.declareName=function(e,t,n){var r=!1;if(t===_S){var i=this.currentScope();r=i.lexical.indexOf(e)>-1||i.functions.indexOf(e)>-1||i.var.indexOf(e)>-1,i.lexical.push(e),this.inModule&&i.flags&nS&&delete this.undefinedExports[e]}else if(t===yS)this.currentScope().lexical.push(e);else if(t===vS){var a=this.currentScope();r=this.treatFunctionsAsVar?a.lexical.indexOf(e)>-1:a.lexical.indexOf(e)>-1||a.var.indexOf(e)>-1,a.functions.push(e)}else for(var o=this.scopeStack.length-1;o>=0;--o){var s=this.scopeStack[o];if(s.lexical.indexOf(e)>-1&&!(s.flags&sS&&s.lexical[0]===e)||!this.treatFunctionsAsVarInScope(s)&&s.functions.indexOf(e)>-1){r=!0;break}if(s.var.push(e),this.inModule&&s.flags&nS&&delete this.undefinedExports[e],s.flags&pS)break}r&&this.raiseRecoverable(n,`Identifier '`+e+`' has already been declared`)},HS.checkLocalExport=function(e){this.scopeStack[0].lexical.indexOf(e.name)===-1&&this.scopeStack[0].var.indexOf(e.name)===-1&&(this.undefinedExports[e.name]=e)},HS.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]},HS.currentVarScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(pS|dS|uS))return t}},HS.currentThisScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(pS|dS|uS)&&!(t.flags&oS))return t}};var WS=function(e,t,n){this.type=``,this.start=t,this.end=0,e.options.locations&&(this.loc=new Xx(e,n)),e.options.directSourceFile&&(this.sourceFile=e.options.directSourceFile),e.options.ranges&&(this.range=[t,0])},GS=xS.prototype;GS.startNode=function(){return new WS(this,this.start,this.startLoc)},GS.startNodeAt=function(e,t){return new WS(this,e,t)};function KS(e,t,n,r){return e.type=t,e.end=n,this.options.locations&&(e.loc.end=r),this.options.ranges&&(e.range[1]=n),e}GS.finishNode=function(e,t){return KS.call(this,e,t,this.lastTokEnd,this.lastTokEndLoc)},GS.finishNodeAt=function(e,t,n,r){return KS.call(this,e,t,n,r)},GS.copyNode=function(e){var t=new WS(this,e.start,this.startLoc);for(var n in e)t[n]=e[n];return t};var qS=`Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz`,JS=`ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS`,YS=JS+` Extended_Pictographic`,XS=YS,ZS=XS+` EBase EComp EMod EPres ExtPict`,QS=ZS,$S={9:JS,10:YS,11:XS,12:ZS,13:QS,14:QS},eC={9:``,10:``,11:``,12:``,13:``,14:`Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji`},tC=`Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu`,nC=`Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb`,rC=nC+` Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd`,iC=rC+` Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho`,aC=iC+` Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi`,oC=aC+` Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith`,sC={9:nC,10:rC,11:iC,12:aC,13:oC,14:oC+` `+qS},cC={};function lC(e){var t=cC[e]={binary:Kx($S[e]+` `+tC),binaryOfStrings:Kx(eC[e]),nonBinary:{General_Category:Kx(tC),Script:Kx(sC[e])}};t.nonBinary.Script_Extensions=t.nonBinary.Script,t.nonBinary.gc=t.nonBinary.General_Category,t.nonBinary.sc=t.nonBinary.Script,t.nonBinary.scx=t.nonBinary.Script_Extensions}for(var uC=0,dC=[9,10,11,12,13,14];uC<dC.length;uC+=1){var fC=dC[uC];lC(fC)}var Y=xS.prototype,pC=function(e,t){this.parent=e,this.base=t||this};pC.prototype.separatedFrom=function(e){for(var t=this;t;t=t.parent)for(var n=e;n;n=n.parent)if(t.base===n.base&&t!==n)return!0;return!1},pC.prototype.sibling=function(){return new pC(this.parent,this.base)};var mC=function(e){this.parser=e,this.validFlags=`gim`+(e.options.ecmaVersion>=6?`uy`:``)+(e.options.ecmaVersion>=9?`s`:``)+(e.options.ecmaVersion>=13?`d`:``)+(e.options.ecmaVersion>=15?`v`:``),this.unicodeProperties=cC[e.options.ecmaVersion>=14?14:e.options.ecmaVersion],this.source=``,this.flags=``,this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue=``,this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};mC.prototype.reset=function(e,t,n){var r=n.indexOf(`v`)!==-1,i=n.indexOf(`u`)!==-1;this.start=e|0,this.source=t+``,this.flags=n,r&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)},mC.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,`Invalid regular expression: /`+this.source+`/: `+e)},mC.prototype.at=function(e,t){t===void 0&&(t=!1);var n=this.source,r=n.length;if(e>=r)return-1;var i=n.charCodeAt(e);if(!(t||this.switchU)||i<=55295||i>=57344||e+1>=r)return i;var a=n.charCodeAt(e+1);return a>=56320&&a<=57343?(i<<10)+a-56613888:i},mC.prototype.nextIndex=function(e,t){t===void 0&&(t=!1);var n=this.source,r=n.length;if(e>=r)return r;var i=n.charCodeAt(e),a;return!(t||this.switchU)||i<=55295||i>=57344||e+1>=r||(a=n.charCodeAt(e+1))<56320||a>57343?e+1:e+2},mC.prototype.current=function(e){return e===void 0&&(e=!1),this.at(this.pos,e)},mC.prototype.lookahead=function(e){return e===void 0&&(e=!1),this.at(this.nextIndex(this.pos,e),e)},mC.prototype.advance=function(e){e===void 0&&(e=!1),this.pos=this.nextIndex(this.pos,e)},mC.prototype.eat=function(e,t){return t===void 0&&(t=!1),this.current(t)===e&&(this.advance(t),!0)},mC.prototype.eatChars=function(e,t){t===void 0&&(t=!1);for(var n=this.pos,r=0,i=e;r<i.length;r+=1){var a=i[r],o=this.at(n,t);if(o===-1||o!==a)return!1;n=this.nextIndex(n,t)}return this.pos=n,!0},Y.validateRegExpFlags=function(e){for(var t=e.validFlags,n=e.flags,r=!1,i=!1,a=0;a<n.length;a++){var o=n.charAt(a);t.indexOf(o)===-1&&this.raise(e.start,`Invalid regular expression flag`),n.indexOf(o,a+1)>-1&&this.raise(e.start,`Duplicate regular expression flag`),o===`u`&&(r=!0),o===`v`&&(i=!0)}this.options.ecmaVersion>=15&&r&&i&&this.raise(e.start,`Invalid regular expression flag`)};function hC(e){for(var t in e)return!0;return!1}Y.validateRegExpPattern=function(e){this.regexp_pattern(e),!e.switchN&&this.options.ecmaVersion>=9&&hC(e.groupNames)&&(e.switchN=!0,this.regexp_pattern(e))},Y.regexp_pattern=function(e){e.pos=0,e.lastIntValue=0,e.lastStringValue=``,e.lastAssertionIsQuantifiable=!1,e.numCapturingParens=0,e.maxBackReference=0,e.groupNames=Object.create(null),e.backReferenceNames.length=0,e.branchID=null,this.regexp_disjunction(e),e.pos!==e.source.length&&(e.eat(41)&&e.raise(`Unmatched ')'`),(e.eat(93)||e.eat(125))&&e.raise(`Lone quantifier brackets`)),e.maxBackReference>e.numCapturingParens&&e.raise(`Invalid escape`);for(var t=0,n=e.backReferenceNames;t<n.length;t+=1){var r=n[t];e.groupNames[r]||e.raise(`Invalid named capture referenced`)}},Y.regexp_disjunction=function(e){var t=this.options.ecmaVersion>=16;for(t&&(e.branchID=new pC(e.branchID,null)),this.regexp_alternative(e);e.eat(124);)t&&(e.branchID=e.branchID.sibling()),this.regexp_alternative(e);t&&(e.branchID=e.branchID.parent),this.regexp_eatQuantifier(e,!0)&&e.raise(`Nothing to repeat`),e.eat(123)&&e.raise(`Lone quantifier brackets`)},Y.regexp_alternative=function(e){for(;e.pos<e.source.length&&this.regexp_eatTerm(e););},Y.regexp_eatTerm=function(e){return this.regexp_eatAssertion(e)?(e.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(e)&&e.switchU&&e.raise(`Invalid quantifier`),!0):(e.switchU?this.regexp_eatAtom(e):this.regexp_eatExtendedAtom(e))?(this.regexp_eatQuantifier(e),!0):!1},Y.regexp_eatAssertion=function(e){var t=e.pos;if(e.lastAssertionIsQuantifiable=!1,e.eat(94)||e.eat(36))return!0;if(e.eat(92)){if(e.eat(66)||e.eat(98))return!0;e.pos=t}if(e.eat(40)&&e.eat(63)){var n=!1;if(this.options.ecmaVersion>=9&&(n=e.eat(60)),e.eat(61)||e.eat(33))return this.regexp_disjunction(e),e.eat(41)||e.raise(`Unterminated group`),e.lastAssertionIsQuantifiable=!n,!0}return e.pos=t,!1},Y.regexp_eatQuantifier=function(e,t){return t===void 0&&(t=!1),this.regexp_eatQuantifierPrefix(e,t)?(e.eat(63),!0):!1},Y.regexp_eatQuantifierPrefix=function(e,t){return e.eat(42)||e.eat(43)||e.eat(63)||this.regexp_eatBracedQuantifier(e,t)},Y.regexp_eatBracedQuantifier=function(e,t){var n=e.pos;if(e.eat(123)){var r=0,i=-1;if(this.regexp_eatDecimalDigits(e)&&(r=e.lastIntValue,e.eat(44)&&this.regexp_eatDecimalDigits(e)&&(i=e.lastIntValue),e.eat(125)))return i!==-1&&i<r&&!t&&e.raise(`numbers out of order in {} quantifier`),!0;e.switchU&&!t&&e.raise(`Incomplete quantifier`),e.pos=n}return!1},Y.regexp_eatAtom=function(e){return this.regexp_eatPatternCharacters(e)||e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)},Y.regexp_eatReverseSolidusAtomEscape=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatAtomEscape(e))return!0;e.pos=t}return!1},Y.regexp_eatUncapturingGroup=function(e){var t=e.pos;if(e.eat(40)){if(e.eat(63)){if(this.options.ecmaVersion>=16){var n=this.regexp_eatModifiers(e),r=e.eat(45);if(n||r){for(var i=0;i<n.length;i++){var a=n.charAt(i);n.indexOf(a,i+1)>-1&&e.raise(`Duplicate regular expression modifiers`)}if(r){var o=this.regexp_eatModifiers(e);!n&&!o&&e.current()===58&&e.raise(`Invalid regular expression modifiers`);for(var s=0;s<o.length;s++){var c=o.charAt(s);(o.indexOf(c,s+1)>-1||n.indexOf(c)>-1)&&e.raise(`Duplicate regular expression modifiers`)}}}}if(e.eat(58)){if(this.regexp_disjunction(e),e.eat(41))return!0;e.raise(`Unterminated group`)}}e.pos=t}return!1},Y.regexp_eatCapturingGroup=function(e){if(e.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(e):e.current()===63&&e.raise(`Invalid group`),this.regexp_disjunction(e),e.eat(41))return e.numCapturingParens+=1,!0;e.raise(`Unterminated group`)}return!1},Y.regexp_eatModifiers=function(e){for(var t=``,n=0;(n=e.current())!==-1&&gC(n);)t+=qx(n),e.advance();return t};function gC(e){return e===105||e===109||e===115}Y.regexp_eatExtendedAtom=function(e){return e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)||this.regexp_eatInvalidBracedQuantifier(e)||this.regexp_eatExtendedPatternCharacter(e)},Y.regexp_eatInvalidBracedQuantifier=function(e){return this.regexp_eatBracedQuantifier(e,!0)&&e.raise(`Nothing to repeat`),!1},Y.regexp_eatSyntaxCharacter=function(e){var t=e.current();return _C(t)?(e.lastIntValue=t,e.advance(),!0):!1};function _C(e){return e===36||e>=40&&e<=43||e===46||e===63||e>=91&&e<=94||e>=123&&e<=125}Y.regexp_eatPatternCharacters=function(e){for(var t=e.pos,n=0;(n=e.current())!==-1&&!_C(n);)e.advance();return e.pos!==t},Y.regexp_eatExtendedPatternCharacter=function(e){var t=e.current();return t!==-1&&t!==36&&!(t>=40&&t<=43)&&t!==46&&t!==63&&t!==91&&t!==94&&t!==124&&(e.advance(),!0)},Y.regexp_groupSpecifier=function(e){if(e.eat(63)){this.regexp_eatGroupName(e)||e.raise(`Invalid group`);var t=this.options.ecmaVersion>=16,n=e.groupNames[e.lastStringValue];if(n){if(t)for(var r=0,i=n;r<i.length;r+=1)i[r].separatedFrom(e.branchID)||e.raise(`Duplicate capture group name`);else e.raise(`Duplicate capture group name`)}t?(n||(e.groupNames[e.lastStringValue]=[])).push(e.branchID):e.groupNames[e.lastStringValue]=!0}},Y.regexp_eatGroupName=function(e){if(e.lastStringValue=``,e.eat(60)){if(this.regexp_eatRegExpIdentifierName(e)&&e.eat(62))return!0;e.raise(`Invalid capture group name`)}return!1},Y.regexp_eatRegExpIdentifierName=function(e){if(e.lastStringValue=``,this.regexp_eatRegExpIdentifierStart(e)){for(e.lastStringValue+=qx(e.lastIntValue);this.regexp_eatRegExpIdentifierPart(e);)e.lastStringValue+=qx(e.lastIntValue);return!0}return!1},Y.regexp_eatRegExpIdentifierStart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),vC(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function vC(e){return Ox(e,!0)||e===36||e===95}Y.regexp_eatRegExpIdentifierPart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),yC(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function yC(e){return kx(e,!0)||e===36||e===95||e===8204||e===8205}Y.regexp_eatAtomEscape=function(e){return this.regexp_eatBackReference(e)||this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)||e.switchN&&this.regexp_eatKGroupName(e)?!0:(e.switchU&&(e.current()===99&&e.raise(`Invalid unicode escape`),e.raise(`Invalid escape`)),!1)},Y.regexp_eatBackReference=function(e){var t=e.pos;if(this.regexp_eatDecimalEscape(e)){var n=e.lastIntValue;if(e.switchU)return n>e.maxBackReference&&(e.maxBackReference=n),!0;if(n<=e.numCapturingParens)return!0;e.pos=t}return!1},Y.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise(`Invalid named reference`)}return!1},Y.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e,!1)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)},Y.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1},Y.regexp_eatZero=function(e){return e.current()===48&&!jC(e.lookahead())&&(e.lastIntValue=0,e.advance(),!0)},Y.regexp_eatControlEscape=function(e){var t=e.current();return t===116?(e.lastIntValue=9,e.advance(),!0):t===110?(e.lastIntValue=10,e.advance(),!0):t===118?(e.lastIntValue=11,e.advance(),!0):t===102?(e.lastIntValue=12,e.advance(),!0):t===114&&(e.lastIntValue=13,e.advance(),!0)},Y.regexp_eatControlLetter=function(e){var t=e.current();return bC(t)?(e.lastIntValue=t%32,e.advance(),!0):!1};function bC(e){return e>=65&&e<=90||e>=97&&e<=122}Y.regexp_eatRegExpUnicodeEscapeSequence=function(e,t){t===void 0&&(t=!1);var n=e.pos,r=t||e.switchU;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var i=e.lastIntValue;if(r&&i>=55296&&i<=56319){var a=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var o=e.lastIntValue;if(o>=56320&&o<=57343)return e.lastIntValue=(i-55296)*1024+(o-56320)+65536,!0}e.pos=a,e.lastIntValue=i}return!0}if(r&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&xC(e.lastIntValue))return!0;r&&e.raise(`Invalid unicode escape`),e.pos=n}return!1};function xC(e){return e>=0&&e<=1114111}Y.regexp_eatIdentityEscape=function(e){if(e.switchU)return this.regexp_eatSyntaxCharacter(e)?!0:e.eat(47)?(e.lastIntValue=47,!0):!1;var t=e.current();return t!==99&&(!e.switchN||t!==107)&&(e.lastIntValue=t,e.advance(),!0)},Y.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(t>=49&&t<=57){do e.lastIntValue=10*e.lastIntValue+(t-48),e.advance();while((t=e.current())>=48&&t<=57);return!0}return!1};var SC=0,CC=1,wC=2;Y.regexp_eatCharacterClassEscape=function(e){var t=e.current();if(TC(t))return e.lastIntValue=-1,e.advance(),CC;var n=!1;if(e.switchU&&this.options.ecmaVersion>=9&&((n=t===80)||t===112)){e.lastIntValue=-1,e.advance();var r;if(e.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(e))&&e.eat(125))return n&&r===wC&&e.raise(`Invalid property name`),r;e.raise(`Invalid property name`)}return SC};function TC(e){return e===100||e===68||e===115||e===83||e===119||e===87}Y.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var n=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var r=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,n,r),CC}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var i=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,i)}return SC},Y.regexp_validateUnicodePropertyNameAndValue=function(e,t,n){Ux(e.unicodeProperties.nonBinary,t)||e.raise(`Invalid property name`),e.unicodeProperties.nonBinary[t].test(n)||e.raise(`Invalid property value`)},Y.regexp_validateUnicodePropertyNameOrValue=function(e,t){if(e.unicodeProperties.binary.test(t))return CC;if(e.switchV&&e.unicodeProperties.binaryOfStrings.test(t))return wC;e.raise(`Invalid property name`)},Y.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue=``;EC(t=e.current());)e.lastStringValue+=qx(t),e.advance();return e.lastStringValue!==``};function EC(e){return bC(e)||e===95}Y.regexp_eatUnicodePropertyValue=function(e){var t=0;for(e.lastStringValue=``;DC(t=e.current());)e.lastStringValue+=qx(t),e.advance();return e.lastStringValue!==``};function DC(e){return EC(e)||jC(e)}Y.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)},Y.regexp_eatCharacterClass=function(e){if(e.eat(91)){var t=e.eat(94),n=this.regexp_classContents(e);return e.eat(93)||e.raise(`Unterminated character class`),t&&n===wC&&e.raise(`Negated character class may contain strings`),!0}return!1},Y.regexp_classContents=function(e){return e.current()===93?CC:e.switchV?this.regexp_classSetExpression(e):(this.regexp_nonEmptyClassRanges(e),CC)},Y.regexp_nonEmptyClassRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassAtom(e)){var n=e.lastIntValue;e.switchU&&(t===-1||n===-1)&&e.raise(`Invalid character class`),t!==-1&&n!==-1&&t>n&&e.raise(`Range out of order in character class`)}}},Y.regexp_eatClassAtom=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatClassEscape(e))return!0;if(e.switchU){var n=e.current();(n===99||PC(n))&&e.raise(`Invalid class escape`),e.raise(`Invalid escape`)}e.pos=t}var r=e.current();return r!==93&&(e.lastIntValue=r,e.advance(),!0)},Y.regexp_eatClassEscape=function(e){var t=e.pos;if(e.eat(98))return e.lastIntValue=8,!0;if(e.switchU&&e.eat(45))return e.lastIntValue=45,!0;if(!e.switchU&&e.eat(99)){if(this.regexp_eatClassControlLetter(e))return!0;e.pos=t}return this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)},Y.regexp_classSetExpression=function(e){var t=CC,n;if(!this.regexp_eatClassSetRange(e)){if(n=this.regexp_eatClassSetOperand(e)){n===wC&&(t=wC);for(var r=e.pos;e.eatChars([38,38]);){if(e.current()!==38&&(n=this.regexp_eatClassSetOperand(e))){n!==wC&&(t=CC);continue}e.raise(`Invalid character in character class`)}if(r!==e.pos)return t;for(;e.eatChars([45,45]);)this.regexp_eatClassSetOperand(e)||e.raise(`Invalid character in character class`);if(r!==e.pos)return t}else e.raise(`Invalid character in character class`)}for(;;)if(!this.regexp_eatClassSetRange(e)){if(n=this.regexp_eatClassSetOperand(e),!n)return t;n===wC&&(t=wC)}},Y.regexp_eatClassSetRange=function(e){var t=e.pos;if(this.regexp_eatClassSetCharacter(e)){var n=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassSetCharacter(e)){var r=e.lastIntValue;return n!==-1&&r!==-1&&n>r&&e.raise(`Range out of order in character class`),!0}e.pos=t}return!1},Y.regexp_eatClassSetOperand=function(e){return this.regexp_eatClassSetCharacter(e)?CC:this.regexp_eatClassStringDisjunction(e)||this.regexp_eatNestedClass(e)},Y.regexp_eatNestedClass=function(e){var t=e.pos;if(e.eat(91)){var n=e.eat(94),r=this.regexp_classContents(e);if(e.eat(93))return n&&r===wC&&e.raise(`Negated character class may contain strings`),r;e.pos=t}if(e.eat(92)){var i=this.regexp_eatCharacterClassEscape(e);if(i)return i;e.pos=t}return null},Y.regexp_eatClassStringDisjunction=function(e){var t=e.pos;if(e.eatChars([92,113])){if(e.eat(123)){var n=this.regexp_classStringDisjunctionContents(e);if(e.eat(125))return n}else e.raise(`Invalid escape`);e.pos=t}return null},Y.regexp_classStringDisjunctionContents=function(e){for(var t=this.regexp_classString(e);e.eat(124);)this.regexp_classString(e)===wC&&(t=wC);return t},Y.regexp_classString=function(e){for(var t=0;this.regexp_eatClassSetCharacter(e);)t++;return t===1?CC:wC},Y.regexp_eatClassSetCharacter=function(e){var t=e.pos;if(e.eat(92))return this.regexp_eatCharacterEscape(e)||this.regexp_eatClassSetReservedPunctuator(e)?!0:e.eat(98)?(e.lastIntValue=8,!0):(e.pos=t,!1);var n=e.current();return n<0||n===e.lookahead()&&OC(n)||kC(n)?!1:(e.advance(),e.lastIntValue=n,!0)};function OC(e){return e===33||e>=35&&e<=38||e>=42&&e<=44||e===46||e>=58&&e<=64||e===94||e===96||e===126}function kC(e){return e===40||e===41||e===45||e===47||e>=91&&e<=93||e>=123&&e<=125}Y.regexp_eatClassSetReservedPunctuator=function(e){var t=e.current();return AC(t)?(e.lastIntValue=t,e.advance(),!0):!1};function AC(e){return e===33||e===35||e===37||e===38||e===44||e===45||e>=58&&e<=62||e===64||e===96||e===126}Y.regexp_eatClassControlLetter=function(e){var t=e.current();return jC(t)||t===95?(e.lastIntValue=t%32,e.advance(),!0):!1},Y.regexp_eatHexEscapeSequence=function(e){var t=e.pos;if(e.eat(120)){if(this.regexp_eatFixedHexDigits(e,2))return!0;e.switchU&&e.raise(`Invalid escape`),e.pos=t}return!1},Y.regexp_eatDecimalDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;jC(n=e.current());)e.lastIntValue=10*e.lastIntValue+(n-48),e.advance();return e.pos!==t};function jC(e){return e>=48&&e<=57}Y.regexp_eatHexDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;MC(n=e.current());)e.lastIntValue=16*e.lastIntValue+NC(n),e.advance();return e.pos!==t};function MC(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function NC(e){return e>=65&&e<=70?10+(e-65):e>=97&&e<=102?10+(e-97):e-48}Y.regexp_eatLegacyOctalEscapeSequence=function(e){if(this.regexp_eatOctalDigit(e)){var t=e.lastIntValue;if(this.regexp_eatOctalDigit(e)){var n=e.lastIntValue;e.lastIntValue=t<=3&&this.regexp_eatOctalDigit(e)?t*64+n*8+e.lastIntValue:t*8+n}else e.lastIntValue=t;return!0}return!1},Y.regexp_eatOctalDigit=function(e){var t=e.current();return PC(t)?(e.lastIntValue=t-48,e.advance(),!0):(e.lastIntValue=0,!1)};function PC(e){return e>=48&&e<=55}Y.regexp_eatFixedHexDigits=function(e,t){var n=e.pos;e.lastIntValue=0;for(var r=0;r<t;++r){var i=e.current();if(!MC(i))return e.pos=n,!1;e.lastIntValue=16*e.lastIntValue+NC(i),e.advance()}return!0};var FC=function(e){this.type=e.type,this.value=e.value,this.start=e.start,this.end=e.end,e.options.locations&&(this.loc=new Xx(e,e.startLoc,e.endLoc)),e.options.ranges&&(this.range=[e.start,e.end])},X=xS.prototype;X.next=function(e){!e&&this.type.keyword&&this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword `+this.type.keyword),this.options.onToken&&this.options.onToken(new FC(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},X.getToken=function(){return this.next(),new FC(this)},typeof Symbol<`u`&&(X[Symbol.iterator]=function(){var e=this;return{next:function(){var t=e.getToken();return{done:t.type===K.eof,value:t}}}}),X.nextToken=function(){var e=this.curContext();if((!e||!e.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(K.eof);if(e.override)return e.override(this);this.readToken(this.fullCharCodeAtPos())},X.readToken=function(e){return Ox(e,this.options.ecmaVersion>=6)||e===92?this.readWord():this.getTokenFromCode(e)},X.fullCharCodeAt=function(e){var t=this.input.charCodeAt(e);if(t<=55295||t>=56320)return t;var n=this.input.charCodeAt(e+1);return n<=56319||n>=57344?t:(t<<10)+n-56613888},X.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)},X.skipBlockComment=function(){var e=this.options.onComment&&this.curPosition(),t=this.pos,n=this.input.indexOf(`*/`,this.pos+=2);if(n===-1&&this.raise(this.pos-2,`Unterminated comment`),this.pos=n+2,this.options.locations)for(var r=void 0,i=t;(r=Lx(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(t+2,n),t,this.pos,e,this.curPosition())},X.skipLineComment=function(e){for(var t=this.pos,n=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=e);this.pos<this.input.length&&!Ix(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(t+e,this.pos),t,this.pos,n,this.curPosition())},X.skipSpace=function(){loop:for(;this.pos<this.input.length;){var e=this.input.charCodeAt(this.pos);switch(e){case 32:case 160:++this.pos;break;case 13:this.input.charCodeAt(this.pos+1)===10&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break loop}break;default:if(e>8&&e<14||e>=5760&&Rx.test(String.fromCharCode(e)))++this.pos;else break loop}}},X.finishToken=function(e,t){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var n=this.type;this.type=e,this.value=t,this.updateContext(n)},X.readToken_dot=function(){var e=this.input.charCodeAt(this.pos+1);if(e>=48&&e<=57)return this.readNumber(!0);var t=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&e===46&&t===46?(this.pos+=3,this.finishToken(K.ellipsis)):(++this.pos,this.finishToken(K.dot))},X.readToken_slash=function(){var e=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):e===61?this.finishOp(K.assign,2):this.finishOp(K.slash,1)},X.readToken_mult_modulo_exp=function(e){var t=this.input.charCodeAt(this.pos+1),n=1,r=e===42?K.star:K.modulo;return this.options.ecmaVersion>=7&&e===42&&t===42&&(++n,r=K.starstar,t=this.input.charCodeAt(this.pos+2)),t===61?this.finishOp(K.assign,n+1):this.finishOp(r,n)},X.readToken_pipe_amp=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?this.options.ecmaVersion>=12&&this.input.charCodeAt(this.pos+2)===61?this.finishOp(K.assign,3):this.finishOp(e===124?K.logicalOR:K.logicalAND,2):t===61?this.finishOp(K.assign,2):this.finishOp(e===124?K.bitwiseOR:K.bitwiseAND,1)},X.readToken_caret=function(){return this.input.charCodeAt(this.pos+1)===61?this.finishOp(K.assign,2):this.finishOp(K.bitwiseXOR,1)},X.readToken_plus_min=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?t===45&&!this.inModule&&this.input.charCodeAt(this.pos+2)===62&&(this.lastTokEnd===0||Px.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(K.incDec,2):t===61?this.finishOp(K.assign,2):this.finishOp(K.plusMin,1)},X.readToken_lt_gt=function(e){var t=this.input.charCodeAt(this.pos+1),n=1;return t===e?(n=e===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+n)===61?this.finishOp(K.assign,n+1):this.finishOp(K.bitShift,n)):t===33&&e===60&&!this.inModule&&this.input.charCodeAt(this.pos+2)===45&&this.input.charCodeAt(this.pos+3)===45?(this.skipLineComment(4),this.skipSpace(),this.nextToken()):(t===61&&(n=2),this.finishOp(K.relational,n))},X.readToken_eq_excl=function(e){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(K.equality,this.input.charCodeAt(this.pos+2)===61?3:2):e===61&&t===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(K.arrow)):this.finishOp(e===61?K.eq:K.prefix,1)},X.readToken_question=function(){var e=this.options.ecmaVersion;if(e>=11){var t=this.input.charCodeAt(this.pos+1);if(t===46){var n=this.input.charCodeAt(this.pos+2);if(n<48||n>57)return this.finishOp(K.questionDot,2)}if(t===63)return e>=12&&this.input.charCodeAt(this.pos+2)===61?this.finishOp(K.assign,3):this.finishOp(K.coalesce,2)}return this.finishOp(K.question,1)},X.readToken_numberSign=function(){var e=this.options.ecmaVersion,t=35;if(e>=13&&(++this.pos,t=this.fullCharCodeAtPos(),Ox(t,!0)||t===92))return this.finishToken(K.privateId,this.readWord1());this.raise(this.pos,`Unexpected character '`+qx(t)+`'`)},X.getTokenFromCode=function(e){switch(e){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(K.parenL);case 41:return++this.pos,this.finishToken(K.parenR);case 59:return++this.pos,this.finishToken(K.semi);case 44:return++this.pos,this.finishToken(K.comma);case 91:return++this.pos,this.finishToken(K.bracketL);case 93:return++this.pos,this.finishToken(K.bracketR);case 123:return++this.pos,this.finishToken(K.braceL);case 125:return++this.pos,this.finishToken(K.braceR);case 58:return++this.pos,this.finishToken(K.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(K.backQuote);case 48:var t=this.input.charCodeAt(this.pos+1);if(t===120||t===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(t===111||t===79)return this.readRadixNumber(8);if(t===98||t===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(e);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(e);case 124:case 38:return this.readToken_pipe_amp(e);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(e);case 60:case 62:return this.readToken_lt_gt(e);case 61:case 33:return this.readToken_eq_excl(e);case 63:return this.readToken_question();case 126:return this.finishOp(K.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,`Unexpected character '`+qx(e)+`'`)},X.finishOp=function(e,t){var n=this.input.slice(this.pos,this.pos+t);return this.pos+=t,this.finishToken(e,n)},X.readRegexp=function(){for(var e,t,n=this.pos;;){this.pos>=this.input.length&&this.raise(n,`Unterminated regular expression`);var r=this.input.charAt(this.pos);if(Px.test(r)&&this.raise(n,`Unterminated regular expression`),e)e=!1;else{if(r===`[`)t=!0;else if(r===`]`&&t)t=!1;else if(r===`/`&&!t)break;e=r===`\\`}++this.pos}var i=this.input.slice(n,this.pos);++this.pos;var a=this.pos,o=this.readWord1();this.containsEsc&&this.unexpected(a);var s=this.regexpState||=new mC(this);s.reset(n,i,o),this.validateRegExpFlags(s),this.validateRegExpPattern(s);var c=null;try{c=new RegExp(i,o)}catch{}return this.finishToken(K.regexp,{pattern:i,flags:o,value:c})},X.readInt=function(e,t,n){for(var r=this.options.ecmaVersion>=12&&t===void 0,i=n&&this.input.charCodeAt(this.pos)===48,a=this.pos,o=0,s=0,c=0,l=t??1/0;c<l;++c,++this.pos){var u=this.input.charCodeAt(this.pos),d=void 0;if(r&&u===95){i&&this.raiseRecoverable(this.pos,`Numeric separator is not allowed in legacy octal numeric literals`),s===95&&this.raiseRecoverable(this.pos,`Numeric separator must be exactly one underscore`),c===0&&this.raiseRecoverable(this.pos,`Numeric separator is not allowed at the first of digits`),s=u;continue}if(d=u>=97?u-97+10:u>=65?u-65+10:u>=48&&u<=57?u-48:1/0,d>=e)break;s=u,o=o*e+d}return r&&s===95&&this.raiseRecoverable(this.pos-1,`Numeric separator is not allowed at the last of digits`),this.pos===a||t!=null&&this.pos-a!==t?null:o};function IC(e,t){return t?parseInt(e,8):parseFloat(e.replace(/_/g,``))}function LC(e){return typeof BigInt==`function`?BigInt(e.replace(/_/g,``)):null}X.readRadixNumber=function(e){var t=this.pos;this.pos+=2;var n=this.readInt(e);return n??this.raise(this.start+2,`Expected number in radix `+e),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(n=LC(this.input.slice(t,this.pos)),++this.pos):Ox(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`),this.finishToken(K.num,n)},X.readNumber=function(e){var t=this.pos;!e&&this.readInt(10,void 0,!0)===null&&this.raise(t,`Invalid number`);var n=this.pos-t>=2&&this.input.charCodeAt(t)===48;n&&this.strict&&this.raise(t,`Invalid number`);var r=this.input.charCodeAt(this.pos);if(!n&&!e&&this.options.ecmaVersion>=11&&r===110){var i=LC(this.input.slice(t,this.pos));return++this.pos,Ox(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`),this.finishToken(K.num,i)}n&&/[89]/.test(this.input.slice(t,this.pos))&&(n=!1),r===46&&!n&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!n&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(t,`Invalid number`)),Ox(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`);var a=IC(this.input.slice(t,this.pos),n);return this.finishToken(K.num,a)},X.readCodePoint=function(){var e=this.input.charCodeAt(this.pos),t;if(e===123){this.options.ecmaVersion<6&&this.unexpected();var n=++this.pos;t=this.readHexChar(this.input.indexOf(`}`,this.pos)-this.pos),++this.pos,t>1114111&&this.invalidStringToken(n,`Code point out of bounds`)}else t=this.readHexChar(4);return t},X.readString=function(e){for(var t=``,n=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,`Unterminated string constant`);var r=this.input.charCodeAt(this.pos);if(r===e)break;r===92?(t+=this.input.slice(n,this.pos),t+=this.readEscapedChar(!1),n=this.pos):r===8232||r===8233?(this.options.ecmaVersion<10&&this.raise(this.start,`Unterminated string constant`),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(Ix(r)&&this.raise(this.start,`Unterminated string constant`),++this.pos)}return t+=this.input.slice(n,this.pos++),this.finishToken(K.string,t)};var RC={};X.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e===RC)this.readInvalidTemplateToken();else throw e}this.inTemplateElement=!1},X.invalidStringToken=function(e,t){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw RC;this.raise(e,t)},X.readTmplToken=function(){for(var e=``,t=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,`Unterminated template`);var n=this.input.charCodeAt(this.pos);if(n===96||n===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===K.template||this.type===K.invalidTemplate)?n===36?(this.pos+=2,this.finishToken(K.dollarBraceL)):(++this.pos,this.finishToken(K.backQuote)):(e+=this.input.slice(t,this.pos),this.finishToken(K.template,e));if(n===92)e+=this.input.slice(t,this.pos),e+=this.readEscapedChar(!0),t=this.pos;else if(Ix(n)){switch(e+=this.input.slice(t,this.pos),++this.pos,n){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:e+=`
|
|
13
|
+
`),cooked:this.value},this.next(),n.tail=this.type===K.backQuote,this.finishNode(n,`TemplateElement`)},J.parseTemplate=function(e){e===void 0&&(e={});var t=e.isTagged;t===void 0&&(t=!1);var n=this.startNode();this.next(),n.expressions=[];var r=this.parseTemplateElement({isTagged:t});for(n.quasis=[r];!r.tail;)this.type===K.eof&&this.raise(this.pos,`Unterminated template literal`),this.expect(K.dollarBraceL),n.expressions.push(this.parseExpression()),this.expect(K.braceR),n.quasis.push(r=this.parseTemplateElement({isTagged:t}));return this.next(),this.finishNode(n,`TemplateLiteral`)},J.isAsyncProp=function(e){return!e.computed&&e.key.type===`Identifier`&&e.key.name===`async`&&(this.type===K.name||this.type===K.num||this.type===K.string||this.type===K.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===K.star)&&!Fx.test(this.input.slice(this.lastTokEnd,this.start))},J.parseObj=function(e,t){var n=this.startNode(),r=!0,i={};for(n.properties=[],this.next();!this.eat(K.braceR);){if(r)r=!1;else if(this.expect(K.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(K.braceR))break;var a=this.parseProperty(e,t);e||this.checkPropClash(a,i,t),n.properties.push(a)}return this.finishNode(n,e?`ObjectPattern`:`ObjectExpression`)},J.parseProperty=function(e,t){var n=this.startNode(),r,i,a,o;if(this.options.ecmaVersion>=9&&this.eat(K.ellipsis))return e?(n.argument=this.parseIdent(!1),this.type===K.comma&&this.raiseRecoverable(this.start,`Comma is not permitted after the rest element`),this.finishNode(n,`RestElement`)):(n.argument=this.parseMaybeAssign(!1,t),this.type===K.comma&&t&&t.trailingComma<0&&(t.trailingComma=this.start),this.finishNode(n,`SpreadElement`));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(e||t)&&(a=this.start,o=this.startLoc),e||(r=this.eat(K.star)));var s=this.containsEsc;return this.parsePropertyName(n),!e&&!s&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(n)?(i=!0,r=this.options.ecmaVersion>=9&&this.eat(K.star),this.parsePropertyName(n)):i=!1,this.parsePropertyValue(n,e,r,i,a,o,t,s),this.finishNode(n,`Property`)},J.parseGetterSetter=function(e){var t=e.key.name;this.parsePropertyName(e),e.value=this.parseMethod(!1),e.kind=t;var n=e.kind===`get`?0:1;if(e.value.params.length!==n){var r=e.value.start;e.kind===`get`?this.raiseRecoverable(r,`getter should have no params`):this.raiseRecoverable(r,`setter should have exactly one param`)}else e.kind===`set`&&e.value.params[0].type===`RestElement`&&this.raiseRecoverable(e.value.params[0].start,`Setter cannot use rest params`)},J.parsePropertyValue=function(e,t,n,r,i,a,o,s){(n||r)&&this.type===K.colon&&this.unexpected(),this.eat(K.colon)?(e.value=t?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,o),e.kind=`init`):this.options.ecmaVersion>=6&&this.type===K.parenL?(t&&this.unexpected(),e.method=!0,e.value=this.parseMethod(n,r),e.kind=`init`):!t&&!s&&this.options.ecmaVersion>=5&&!e.computed&&e.key.type===`Identifier`&&(e.key.name===`get`||e.key.name===`set`)&&this.type!==K.comma&&this.type!==K.braceR&&this.type!==K.eq?((n||r)&&this.unexpected(),this.parseGetterSetter(e)):this.options.ecmaVersion>=6&&!e.computed&&e.key.type===`Identifier`?((n||r)&&this.unexpected(),this.checkUnreserved(e.key),e.key.name===`await`&&!this.awaitIdentPos&&(this.awaitIdentPos=i),t?e.value=this.parseMaybeDefault(i,a,this.copyNode(e.key)):this.type===K.eq&&o?(o.shorthandAssign<0&&(o.shorthandAssign=this.start),e.value=this.parseMaybeDefault(i,a,this.copyNode(e.key))):e.value=this.copyNode(e.key),e.kind=`init`,e.shorthand=!0):this.unexpected()},J.parsePropertyName=function(e){if(this.options.ecmaVersion>=6){if(this.eat(K.bracketL))return e.computed=!0,e.key=this.parseMaybeAssign(),this.expect(K.bracketR),e.key;e.computed=!1}return e.key=this.type===K.num||this.type===K.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!==`never`)},J.initFunction=function(e){e.id=null,this.options.ecmaVersion>=6&&(e.generator=e.expression=!1),this.options.ecmaVersion>=8&&(e.async=!1)},J.parseMethod=function(e,t,n){var r=this.startNode(),i=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=e),this.options.ecmaVersion>=8&&(r.async=!!t),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(hS(t,r.generator)|lS|(n?uS:0)),this.expect(K.parenL),r.params=this.parseBindingList(K.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=i,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(r,`FunctionExpression`)},J.parseArrowExpression=function(e,t,n,r){var i=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.enterScope(hS(n,!1)|sS),this.initFunction(e),this.options.ecmaVersion>=8&&(e.async=!!n),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,e.params=this.toAssignableList(t,!0),this.parseFunctionBody(e,!0,!1,r),this.yieldPos=i,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(e,`ArrowFunctionExpression`)},J.parseFunctionBody=function(e,t,n,r){var i=t&&this.type!==K.braceL,a=this.strict,o=!1;if(i)e.body=this.parseMaybeAssign(r),e.expression=!0,this.checkParams(e,!1);else{var s=this.options.ecmaVersion>=7&&!this.isSimpleParamList(e.params);(!a||s)&&(o=this.strictDirective(this.end),o&&s&&this.raiseRecoverable(e.start,`Illegal 'use strict' directive in function with non-simple parameter list`));var c=this.labels;this.labels=[],o&&(this.strict=!0),this.checkParams(e,!a&&!o&&!t&&!n&&this.isSimpleParamList(e.params)),this.strict&&e.id&&this.checkLValSimple(e.id,xS),e.body=this.parseBlock(!1,void 0,o&&!a),e.expression=!1,this.adaptDirectivePrologue(e.body.body),this.labels=c}this.exitScope()},J.isSimpleParamList=function(e){for(var t=0,n=e;t<n.length;t+=1)if(n[t].type!==`Identifier`)return!1;return!0},J.checkParams=function(e,t){for(var n=Object.create(null),r=0,i=e.params;r<i.length;r+=1){var a=i[r];this.checkLValInnerPattern(a,_S,t?null:n)}},J.parseExprList=function(e,t,n,r){for(var i=[],a=!0;!this.eat(e);){if(a)a=!1;else if(this.expect(K.comma),t&&this.afterTrailingComma(e))break;var o=void 0;n&&this.type===K.comma?o=null:this.type===K.ellipsis?(o=this.parseSpread(r),r&&this.type===K.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):o=this.parseMaybeAssign(!1,r),i.push(o)}return i},J.checkUnreserved=function(e){var t=e.start,n=e.end,r=e.name;this.inGenerator&&r===`yield`&&this.raiseRecoverable(t,`Cannot use 'yield' as identifier inside a generator`),this.inAsync&&r===`await`&&this.raiseRecoverable(t,`Cannot use 'await' as identifier inside an async function`),!(this.currentThisScope().flags&mS)&&r===`arguments`&&this.raiseRecoverable(t,`Cannot use 'arguments' in class field initializer`),this.inClassStaticBlock&&(r===`arguments`||r===`await`)&&this.raise(t,`Cannot use `+r+` in class static initialization block`),this.keywords.test(r)&&this.raise(t,`Unexpected keyword '`+r+`'`),!(this.options.ecmaVersion<6&&this.input.slice(t,n).indexOf(`\\`)!==-1)&&(this.strict?this.reservedWordsStrict:this.reservedWords).test(r)&&(!this.inAsync&&r===`await`&&this.raiseRecoverable(t,`Cannot use keyword 'await' outside an async function`),this.raiseRecoverable(t,`The keyword '`+r+`' is reserved`))},J.parseIdent=function(e){var t=this.parseIdentNode();return this.next(!!e),this.finishNode(t,`Identifier`),e||(this.checkUnreserved(t),t.name===`await`&&!this.awaitIdentPos&&(this.awaitIdentPos=t.start)),t},J.parseIdentNode=function(){var e=this.startNode();return this.type===K.name?e.name=this.value:this.type.keyword?(e.name=this.type.keyword,(e.name===`class`||e.name===`function`)&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=K.name):this.unexpected(),e},J.parsePrivateIdent=function(){var e=this.startNode();return this.type===K.privateId?e.name=this.value:this.unexpected(),this.next(),this.finishNode(e,`PrivateIdentifier`),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(e.start,`Private field '#`+e.name+`' must be declared in an enclosing class`):this.privateNameStack[this.privateNameStack.length-1].used.push(e)),e},J.parseYield=function(e){this.yieldPos||=this.start;var t=this.startNode();return this.next(),this.type===K.semi||this.canInsertSemicolon()||this.type!==K.star&&!this.type.startsExpr?(t.delegate=!1,t.argument=null):(t.delegate=this.eat(K.star),t.argument=this.parseMaybeAssign(e)),this.finishNode(t,`YieldExpression`)},J.parseAwait=function(e){this.awaitPos||=this.start;var t=this.startNode();return this.next(),t.argument=this.parseMaybeUnary(null,!0,!1,e),this.finishNode(t,`AwaitExpression`)};var HS=SS.prototype;HS.raise=function(e,t){var n=Qx(this.input,e);t+=` (`+n.line+`:`+n.column+`)`,this.sourceFile&&(t+=` in `+this.sourceFile);var r=SyntaxError(t);throw r.pos=e,r.loc=n,r.raisedAt=this.pos,r},HS.raiseRecoverable=HS.raise,HS.curPosition=function(){if(this.options.locations)return new Xx(this.curLine,this.pos-this.lineStart)};var US=SS.prototype,WS=function(e){this.flags=e,this.var=[],this.lexical=[],this.functions=[]};US.enterScope=function(e){this.scopeStack.push(new WS(e))},US.exitScope=function(){this.scopeStack.pop()},US.treatFunctionsAsVarInScope=function(e){return e.flags&iS||!this.inModule&&e.flags&rS},US.declareName=function(e,t,n){var r=!1;if(t===vS){var i=this.currentScope();r=i.lexical.indexOf(e)>-1||i.functions.indexOf(e)>-1||i.var.indexOf(e)>-1,i.lexical.push(e),this.inModule&&i.flags&rS&&delete this.undefinedExports[e]}else if(t===bS)this.currentScope().lexical.push(e);else if(t===yS){var a=this.currentScope();r=this.treatFunctionsAsVar?a.lexical.indexOf(e)>-1:a.lexical.indexOf(e)>-1||a.var.indexOf(e)>-1,a.functions.push(e)}else for(var o=this.scopeStack.length-1;o>=0;--o){var s=this.scopeStack[o];if(s.lexical.indexOf(e)>-1&&!(s.flags&cS&&s.lexical[0]===e)||!this.treatFunctionsAsVarInScope(s)&&s.functions.indexOf(e)>-1){r=!0;break}if(s.var.push(e),this.inModule&&s.flags&rS&&delete this.undefinedExports[e],s.flags&mS)break}r&&this.raiseRecoverable(n,`Identifier '`+e+`' has already been declared`)},US.checkLocalExport=function(e){this.scopeStack[0].lexical.indexOf(e.name)===-1&&this.scopeStack[0].var.indexOf(e.name)===-1&&(this.undefinedExports[e.name]=e)},US.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]},US.currentVarScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(mS|fS|dS))return t}},US.currentThisScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(mS|fS|dS)&&!(t.flags&sS))return t}};var GS=function(e,t,n){this.type=``,this.start=t,this.end=0,e.options.locations&&(this.loc=new Zx(e,n)),e.options.directSourceFile&&(this.sourceFile=e.options.directSourceFile),e.options.ranges&&(this.range=[t,0])},KS=SS.prototype;KS.startNode=function(){return new GS(this,this.start,this.startLoc)},KS.startNodeAt=function(e,t){return new GS(this,e,t)};function qS(e,t,n,r){return e.type=t,e.end=n,this.options.locations&&(e.loc.end=r),this.options.ranges&&(e.range[1]=n),e}KS.finishNode=function(e,t){return qS.call(this,e,t,this.lastTokEnd,this.lastTokEndLoc)},KS.finishNodeAt=function(e,t,n,r){return qS.call(this,e,t,n,r)},KS.copyNode=function(e){var t=new GS(this,e.start,this.startLoc);for(var n in e)t[n]=e[n];return t};var JS=`Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz`,YS=`ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS`,XS=YS+` Extended_Pictographic`,ZS=XS,QS=ZS+` EBase EComp EMod EPres ExtPict`,$S=QS,eC={9:YS,10:XS,11:ZS,12:QS,13:$S,14:$S},tC={9:``,10:``,11:``,12:``,13:``,14:`Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji`},nC=`Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu`,rC=`Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb`,iC=rC+` Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd`,aC=iC+` Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho`,oC=aC+` Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi`,sC=oC+` Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith`,cC={9:rC,10:iC,11:aC,12:oC,13:sC,14:sC+` `+JS},lC={};function uC(e){var t=lC[e]={binary:qx(eC[e]+` `+nC),binaryOfStrings:qx(tC[e]),nonBinary:{General_Category:qx(nC),Script:qx(cC[e])}};t.nonBinary.Script_Extensions=t.nonBinary.Script,t.nonBinary.gc=t.nonBinary.General_Category,t.nonBinary.sc=t.nonBinary.Script,t.nonBinary.scx=t.nonBinary.Script_Extensions}for(var dC=0,fC=[9,10,11,12,13,14];dC<fC.length;dC+=1){var pC=fC[dC];uC(pC)}var Y=SS.prototype,mC=function(e,t){this.parent=e,this.base=t||this};mC.prototype.separatedFrom=function(e){for(var t=this;t;t=t.parent)for(var n=e;n;n=n.parent)if(t.base===n.base&&t!==n)return!0;return!1},mC.prototype.sibling=function(){return new mC(this.parent,this.base)};var hC=function(e){this.parser=e,this.validFlags=`gim`+(e.options.ecmaVersion>=6?`uy`:``)+(e.options.ecmaVersion>=9?`s`:``)+(e.options.ecmaVersion>=13?`d`:``)+(e.options.ecmaVersion>=15?`v`:``),this.unicodeProperties=lC[e.options.ecmaVersion>=14?14:e.options.ecmaVersion],this.source=``,this.flags=``,this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue=``,this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};hC.prototype.reset=function(e,t,n){var r=n.indexOf(`v`)!==-1,i=n.indexOf(`u`)!==-1;this.start=e|0,this.source=t+``,this.flags=n,r&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)},hC.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,`Invalid regular expression: /`+this.source+`/: `+e)},hC.prototype.at=function(e,t){t===void 0&&(t=!1);var n=this.source,r=n.length;if(e>=r)return-1;var i=n.charCodeAt(e);if(!(t||this.switchU)||i<=55295||i>=57344||e+1>=r)return i;var a=n.charCodeAt(e+1);return a>=56320&&a<=57343?(i<<10)+a-56613888:i},hC.prototype.nextIndex=function(e,t){t===void 0&&(t=!1);var n=this.source,r=n.length;if(e>=r)return r;var i=n.charCodeAt(e),a;return!(t||this.switchU)||i<=55295||i>=57344||e+1>=r||(a=n.charCodeAt(e+1))<56320||a>57343?e+1:e+2},hC.prototype.current=function(e){return e===void 0&&(e=!1),this.at(this.pos,e)},hC.prototype.lookahead=function(e){return e===void 0&&(e=!1),this.at(this.nextIndex(this.pos,e),e)},hC.prototype.advance=function(e){e===void 0&&(e=!1),this.pos=this.nextIndex(this.pos,e)},hC.prototype.eat=function(e,t){return t===void 0&&(t=!1),this.current(t)===e&&(this.advance(t),!0)},hC.prototype.eatChars=function(e,t){t===void 0&&(t=!1);for(var n=this.pos,r=0,i=e;r<i.length;r+=1){var a=i[r],o=this.at(n,t);if(o===-1||o!==a)return!1;n=this.nextIndex(n,t)}return this.pos=n,!0},Y.validateRegExpFlags=function(e){for(var t=e.validFlags,n=e.flags,r=!1,i=!1,a=0;a<n.length;a++){var o=n.charAt(a);t.indexOf(o)===-1&&this.raise(e.start,`Invalid regular expression flag`),n.indexOf(o,a+1)>-1&&this.raise(e.start,`Duplicate regular expression flag`),o===`u`&&(r=!0),o===`v`&&(i=!0)}this.options.ecmaVersion>=15&&r&&i&&this.raise(e.start,`Invalid regular expression flag`)};function gC(e){for(var t in e)return!0;return!1}Y.validateRegExpPattern=function(e){this.regexp_pattern(e),!e.switchN&&this.options.ecmaVersion>=9&&gC(e.groupNames)&&(e.switchN=!0,this.regexp_pattern(e))},Y.regexp_pattern=function(e){e.pos=0,e.lastIntValue=0,e.lastStringValue=``,e.lastAssertionIsQuantifiable=!1,e.numCapturingParens=0,e.maxBackReference=0,e.groupNames=Object.create(null),e.backReferenceNames.length=0,e.branchID=null,this.regexp_disjunction(e),e.pos!==e.source.length&&(e.eat(41)&&e.raise(`Unmatched ')'`),(e.eat(93)||e.eat(125))&&e.raise(`Lone quantifier brackets`)),e.maxBackReference>e.numCapturingParens&&e.raise(`Invalid escape`);for(var t=0,n=e.backReferenceNames;t<n.length;t+=1){var r=n[t];e.groupNames[r]||e.raise(`Invalid named capture referenced`)}},Y.regexp_disjunction=function(e){var t=this.options.ecmaVersion>=16;for(t&&(e.branchID=new mC(e.branchID,null)),this.regexp_alternative(e);e.eat(124);)t&&(e.branchID=e.branchID.sibling()),this.regexp_alternative(e);t&&(e.branchID=e.branchID.parent),this.regexp_eatQuantifier(e,!0)&&e.raise(`Nothing to repeat`),e.eat(123)&&e.raise(`Lone quantifier brackets`)},Y.regexp_alternative=function(e){for(;e.pos<e.source.length&&this.regexp_eatTerm(e););},Y.regexp_eatTerm=function(e){return this.regexp_eatAssertion(e)?(e.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(e)&&e.switchU&&e.raise(`Invalid quantifier`),!0):(e.switchU?this.regexp_eatAtom(e):this.regexp_eatExtendedAtom(e))?(this.regexp_eatQuantifier(e),!0):!1},Y.regexp_eatAssertion=function(e){var t=e.pos;if(e.lastAssertionIsQuantifiable=!1,e.eat(94)||e.eat(36))return!0;if(e.eat(92)){if(e.eat(66)||e.eat(98))return!0;e.pos=t}if(e.eat(40)&&e.eat(63)){var n=!1;if(this.options.ecmaVersion>=9&&(n=e.eat(60)),e.eat(61)||e.eat(33))return this.regexp_disjunction(e),e.eat(41)||e.raise(`Unterminated group`),e.lastAssertionIsQuantifiable=!n,!0}return e.pos=t,!1},Y.regexp_eatQuantifier=function(e,t){return t===void 0&&(t=!1),this.regexp_eatQuantifierPrefix(e,t)?(e.eat(63),!0):!1},Y.regexp_eatQuantifierPrefix=function(e,t){return e.eat(42)||e.eat(43)||e.eat(63)||this.regexp_eatBracedQuantifier(e,t)},Y.regexp_eatBracedQuantifier=function(e,t){var n=e.pos;if(e.eat(123)){var r=0,i=-1;if(this.regexp_eatDecimalDigits(e)&&(r=e.lastIntValue,e.eat(44)&&this.regexp_eatDecimalDigits(e)&&(i=e.lastIntValue),e.eat(125)))return i!==-1&&i<r&&!t&&e.raise(`numbers out of order in {} quantifier`),!0;e.switchU&&!t&&e.raise(`Incomplete quantifier`),e.pos=n}return!1},Y.regexp_eatAtom=function(e){return this.regexp_eatPatternCharacters(e)||e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)},Y.regexp_eatReverseSolidusAtomEscape=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatAtomEscape(e))return!0;e.pos=t}return!1},Y.regexp_eatUncapturingGroup=function(e){var t=e.pos;if(e.eat(40)){if(e.eat(63)){if(this.options.ecmaVersion>=16){var n=this.regexp_eatModifiers(e),r=e.eat(45);if(n||r){for(var i=0;i<n.length;i++){var a=n.charAt(i);n.indexOf(a,i+1)>-1&&e.raise(`Duplicate regular expression modifiers`)}if(r){var o=this.regexp_eatModifiers(e);!n&&!o&&e.current()===58&&e.raise(`Invalid regular expression modifiers`);for(var s=0;s<o.length;s++){var c=o.charAt(s);(o.indexOf(c,s+1)>-1||n.indexOf(c)>-1)&&e.raise(`Duplicate regular expression modifiers`)}}}}if(e.eat(58)){if(this.regexp_disjunction(e),e.eat(41))return!0;e.raise(`Unterminated group`)}}e.pos=t}return!1},Y.regexp_eatCapturingGroup=function(e){if(e.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(e):e.current()===63&&e.raise(`Invalid group`),this.regexp_disjunction(e),e.eat(41))return e.numCapturingParens+=1,!0;e.raise(`Unterminated group`)}return!1},Y.regexp_eatModifiers=function(e){for(var t=``,n=0;(n=e.current())!==-1&&_C(n);)t+=Jx(n),e.advance();return t};function _C(e){return e===105||e===109||e===115}Y.regexp_eatExtendedAtom=function(e){return e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)||this.regexp_eatInvalidBracedQuantifier(e)||this.regexp_eatExtendedPatternCharacter(e)},Y.regexp_eatInvalidBracedQuantifier=function(e){return this.regexp_eatBracedQuantifier(e,!0)&&e.raise(`Nothing to repeat`),!1},Y.regexp_eatSyntaxCharacter=function(e){var t=e.current();return vC(t)?(e.lastIntValue=t,e.advance(),!0):!1};function vC(e){return e===36||e>=40&&e<=43||e===46||e===63||e>=91&&e<=94||e>=123&&e<=125}Y.regexp_eatPatternCharacters=function(e){for(var t=e.pos,n=0;(n=e.current())!==-1&&!vC(n);)e.advance();return e.pos!==t},Y.regexp_eatExtendedPatternCharacter=function(e){var t=e.current();return t!==-1&&t!==36&&!(t>=40&&t<=43)&&t!==46&&t!==63&&t!==91&&t!==94&&t!==124&&(e.advance(),!0)},Y.regexp_groupSpecifier=function(e){if(e.eat(63)){this.regexp_eatGroupName(e)||e.raise(`Invalid group`);var t=this.options.ecmaVersion>=16,n=e.groupNames[e.lastStringValue];if(n){if(t)for(var r=0,i=n;r<i.length;r+=1)i[r].separatedFrom(e.branchID)||e.raise(`Duplicate capture group name`);else e.raise(`Duplicate capture group name`)}t?(n||(e.groupNames[e.lastStringValue]=[])).push(e.branchID):e.groupNames[e.lastStringValue]=!0}},Y.regexp_eatGroupName=function(e){if(e.lastStringValue=``,e.eat(60)){if(this.regexp_eatRegExpIdentifierName(e)&&e.eat(62))return!0;e.raise(`Invalid capture group name`)}return!1},Y.regexp_eatRegExpIdentifierName=function(e){if(e.lastStringValue=``,this.regexp_eatRegExpIdentifierStart(e)){for(e.lastStringValue+=Jx(e.lastIntValue);this.regexp_eatRegExpIdentifierPart(e);)e.lastStringValue+=Jx(e.lastIntValue);return!0}return!1},Y.regexp_eatRegExpIdentifierStart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),yC(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function yC(e){return kx(e,!0)||e===36||e===95}Y.regexp_eatRegExpIdentifierPart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),bC(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function bC(e){return Ax(e,!0)||e===36||e===95||e===8204||e===8205}Y.regexp_eatAtomEscape=function(e){return this.regexp_eatBackReference(e)||this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)||e.switchN&&this.regexp_eatKGroupName(e)?!0:(e.switchU&&(e.current()===99&&e.raise(`Invalid unicode escape`),e.raise(`Invalid escape`)),!1)},Y.regexp_eatBackReference=function(e){var t=e.pos;if(this.regexp_eatDecimalEscape(e)){var n=e.lastIntValue;if(e.switchU)return n>e.maxBackReference&&(e.maxBackReference=n),!0;if(n<=e.numCapturingParens)return!0;e.pos=t}return!1},Y.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise(`Invalid named reference`)}return!1},Y.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e,!1)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)},Y.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1},Y.regexp_eatZero=function(e){return e.current()===48&&!MC(e.lookahead())&&(e.lastIntValue=0,e.advance(),!0)},Y.regexp_eatControlEscape=function(e){var t=e.current();return t===116?(e.lastIntValue=9,e.advance(),!0):t===110?(e.lastIntValue=10,e.advance(),!0):t===118?(e.lastIntValue=11,e.advance(),!0):t===102?(e.lastIntValue=12,e.advance(),!0):t===114&&(e.lastIntValue=13,e.advance(),!0)},Y.regexp_eatControlLetter=function(e){var t=e.current();return xC(t)?(e.lastIntValue=t%32,e.advance(),!0):!1};function xC(e){return e>=65&&e<=90||e>=97&&e<=122}Y.regexp_eatRegExpUnicodeEscapeSequence=function(e,t){t===void 0&&(t=!1);var n=e.pos,r=t||e.switchU;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var i=e.lastIntValue;if(r&&i>=55296&&i<=56319){var a=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var o=e.lastIntValue;if(o>=56320&&o<=57343)return e.lastIntValue=(i-55296)*1024+(o-56320)+65536,!0}e.pos=a,e.lastIntValue=i}return!0}if(r&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&SC(e.lastIntValue))return!0;r&&e.raise(`Invalid unicode escape`),e.pos=n}return!1};function SC(e){return e>=0&&e<=1114111}Y.regexp_eatIdentityEscape=function(e){if(e.switchU)return this.regexp_eatSyntaxCharacter(e)?!0:e.eat(47)?(e.lastIntValue=47,!0):!1;var t=e.current();return t!==99&&(!e.switchN||t!==107)&&(e.lastIntValue=t,e.advance(),!0)},Y.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(t>=49&&t<=57){do e.lastIntValue=10*e.lastIntValue+(t-48),e.advance();while((t=e.current())>=48&&t<=57);return!0}return!1};var CC=0,wC=1,TC=2;Y.regexp_eatCharacterClassEscape=function(e){var t=e.current();if(EC(t))return e.lastIntValue=-1,e.advance(),wC;var n=!1;if(e.switchU&&this.options.ecmaVersion>=9&&((n=t===80)||t===112)){e.lastIntValue=-1,e.advance();var r;if(e.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(e))&&e.eat(125))return n&&r===TC&&e.raise(`Invalid property name`),r;e.raise(`Invalid property name`)}return CC};function EC(e){return e===100||e===68||e===115||e===83||e===119||e===87}Y.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var n=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var r=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,n,r),wC}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var i=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,i)}return CC},Y.regexp_validateUnicodePropertyNameAndValue=function(e,t,n){Wx(e.unicodeProperties.nonBinary,t)||e.raise(`Invalid property name`),e.unicodeProperties.nonBinary[t].test(n)||e.raise(`Invalid property value`)},Y.regexp_validateUnicodePropertyNameOrValue=function(e,t){if(e.unicodeProperties.binary.test(t))return wC;if(e.switchV&&e.unicodeProperties.binaryOfStrings.test(t))return TC;e.raise(`Invalid property name`)},Y.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue=``;DC(t=e.current());)e.lastStringValue+=Jx(t),e.advance();return e.lastStringValue!==``};function DC(e){return xC(e)||e===95}Y.regexp_eatUnicodePropertyValue=function(e){var t=0;for(e.lastStringValue=``;OC(t=e.current());)e.lastStringValue+=Jx(t),e.advance();return e.lastStringValue!==``};function OC(e){return DC(e)||MC(e)}Y.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)},Y.regexp_eatCharacterClass=function(e){if(e.eat(91)){var t=e.eat(94),n=this.regexp_classContents(e);return e.eat(93)||e.raise(`Unterminated character class`),t&&n===TC&&e.raise(`Negated character class may contain strings`),!0}return!1},Y.regexp_classContents=function(e){return e.current()===93?wC:e.switchV?this.regexp_classSetExpression(e):(this.regexp_nonEmptyClassRanges(e),wC)},Y.regexp_nonEmptyClassRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassAtom(e)){var n=e.lastIntValue;e.switchU&&(t===-1||n===-1)&&e.raise(`Invalid character class`),t!==-1&&n!==-1&&t>n&&e.raise(`Range out of order in character class`)}}},Y.regexp_eatClassAtom=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatClassEscape(e))return!0;if(e.switchU){var n=e.current();(n===99||FC(n))&&e.raise(`Invalid class escape`),e.raise(`Invalid escape`)}e.pos=t}var r=e.current();return r!==93&&(e.lastIntValue=r,e.advance(),!0)},Y.regexp_eatClassEscape=function(e){var t=e.pos;if(e.eat(98))return e.lastIntValue=8,!0;if(e.switchU&&e.eat(45))return e.lastIntValue=45,!0;if(!e.switchU&&e.eat(99)){if(this.regexp_eatClassControlLetter(e))return!0;e.pos=t}return this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)},Y.regexp_classSetExpression=function(e){var t=wC,n;if(!this.regexp_eatClassSetRange(e)){if(n=this.regexp_eatClassSetOperand(e)){n===TC&&(t=TC);for(var r=e.pos;e.eatChars([38,38]);){if(e.current()!==38&&(n=this.regexp_eatClassSetOperand(e))){n!==TC&&(t=wC);continue}e.raise(`Invalid character in character class`)}if(r!==e.pos)return t;for(;e.eatChars([45,45]);)this.regexp_eatClassSetOperand(e)||e.raise(`Invalid character in character class`);if(r!==e.pos)return t}else e.raise(`Invalid character in character class`)}for(;;)if(!this.regexp_eatClassSetRange(e)){if(n=this.regexp_eatClassSetOperand(e),!n)return t;n===TC&&(t=TC)}},Y.regexp_eatClassSetRange=function(e){var t=e.pos;if(this.regexp_eatClassSetCharacter(e)){var n=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassSetCharacter(e)){var r=e.lastIntValue;return n!==-1&&r!==-1&&n>r&&e.raise(`Range out of order in character class`),!0}e.pos=t}return!1},Y.regexp_eatClassSetOperand=function(e){return this.regexp_eatClassSetCharacter(e)?wC:this.regexp_eatClassStringDisjunction(e)||this.regexp_eatNestedClass(e)},Y.regexp_eatNestedClass=function(e){var t=e.pos;if(e.eat(91)){var n=e.eat(94),r=this.regexp_classContents(e);if(e.eat(93))return n&&r===TC&&e.raise(`Negated character class may contain strings`),r;e.pos=t}if(e.eat(92)){var i=this.regexp_eatCharacterClassEscape(e);if(i)return i;e.pos=t}return null},Y.regexp_eatClassStringDisjunction=function(e){var t=e.pos;if(e.eatChars([92,113])){if(e.eat(123)){var n=this.regexp_classStringDisjunctionContents(e);if(e.eat(125))return n}else e.raise(`Invalid escape`);e.pos=t}return null},Y.regexp_classStringDisjunctionContents=function(e){for(var t=this.regexp_classString(e);e.eat(124);)this.regexp_classString(e)===TC&&(t=TC);return t},Y.regexp_classString=function(e){for(var t=0;this.regexp_eatClassSetCharacter(e);)t++;return t===1?wC:TC},Y.regexp_eatClassSetCharacter=function(e){var t=e.pos;if(e.eat(92))return this.regexp_eatCharacterEscape(e)||this.regexp_eatClassSetReservedPunctuator(e)?!0:e.eat(98)?(e.lastIntValue=8,!0):(e.pos=t,!1);var n=e.current();return n<0||n===e.lookahead()&&kC(n)||AC(n)?!1:(e.advance(),e.lastIntValue=n,!0)};function kC(e){return e===33||e>=35&&e<=38||e>=42&&e<=44||e===46||e>=58&&e<=64||e===94||e===96||e===126}function AC(e){return e===40||e===41||e===45||e===47||e>=91&&e<=93||e>=123&&e<=125}Y.regexp_eatClassSetReservedPunctuator=function(e){var t=e.current();return jC(t)?(e.lastIntValue=t,e.advance(),!0):!1};function jC(e){return e===33||e===35||e===37||e===38||e===44||e===45||e>=58&&e<=62||e===64||e===96||e===126}Y.regexp_eatClassControlLetter=function(e){var t=e.current();return MC(t)||t===95?(e.lastIntValue=t%32,e.advance(),!0):!1},Y.regexp_eatHexEscapeSequence=function(e){var t=e.pos;if(e.eat(120)){if(this.regexp_eatFixedHexDigits(e,2))return!0;e.switchU&&e.raise(`Invalid escape`),e.pos=t}return!1},Y.regexp_eatDecimalDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;MC(n=e.current());)e.lastIntValue=10*e.lastIntValue+(n-48),e.advance();return e.pos!==t};function MC(e){return e>=48&&e<=57}Y.regexp_eatHexDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;NC(n=e.current());)e.lastIntValue=16*e.lastIntValue+PC(n),e.advance();return e.pos!==t};function NC(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function PC(e){return e>=65&&e<=70?10+(e-65):e>=97&&e<=102?10+(e-97):e-48}Y.regexp_eatLegacyOctalEscapeSequence=function(e){if(this.regexp_eatOctalDigit(e)){var t=e.lastIntValue;if(this.regexp_eatOctalDigit(e)){var n=e.lastIntValue;e.lastIntValue=t<=3&&this.regexp_eatOctalDigit(e)?t*64+n*8+e.lastIntValue:t*8+n}else e.lastIntValue=t;return!0}return!1},Y.regexp_eatOctalDigit=function(e){var t=e.current();return FC(t)?(e.lastIntValue=t-48,e.advance(),!0):(e.lastIntValue=0,!1)};function FC(e){return e>=48&&e<=55}Y.regexp_eatFixedHexDigits=function(e,t){var n=e.pos;e.lastIntValue=0;for(var r=0;r<t;++r){var i=e.current();if(!NC(i))return e.pos=n,!1;e.lastIntValue=16*e.lastIntValue+PC(i),e.advance()}return!0};var IC=function(e){this.type=e.type,this.value=e.value,this.start=e.start,this.end=e.end,e.options.locations&&(this.loc=new Zx(e,e.startLoc,e.endLoc)),e.options.ranges&&(this.range=[e.start,e.end])},X=SS.prototype;X.next=function(e){!e&&this.type.keyword&&this.containsEsc&&this.raiseRecoverable(this.start,`Escape sequence in keyword `+this.type.keyword),this.options.onToken&&this.options.onToken(new IC(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},X.getToken=function(){return this.next(),new IC(this)},typeof Symbol<`u`&&(X[Symbol.iterator]=function(){var e=this;return{next:function(){var t=e.getToken();return{done:t.type===K.eof,value:t}}}}),X.nextToken=function(){var e=this.curContext();if((!e||!e.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(K.eof);if(e.override)return e.override(this);this.readToken(this.fullCharCodeAtPos())},X.readToken=function(e){return kx(e,this.options.ecmaVersion>=6)||e===92?this.readWord():this.getTokenFromCode(e)},X.fullCharCodeAt=function(e){var t=this.input.charCodeAt(e);if(t<=55295||t>=56320)return t;var n=this.input.charCodeAt(e+1);return n<=56319||n>=57344?t:(t<<10)+n-56613888},X.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)},X.skipBlockComment=function(){var e=this.options.onComment&&this.curPosition(),t=this.pos,n=this.input.indexOf(`*/`,this.pos+=2);if(n===-1&&this.raise(this.pos-2,`Unterminated comment`),this.pos=n+2,this.options.locations)for(var r=void 0,i=t;(r=Rx(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(t+2,n),t,this.pos,e,this.curPosition())},X.skipLineComment=function(e){for(var t=this.pos,n=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=e);this.pos<this.input.length&&!Lx(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(t+e,this.pos),t,this.pos,n,this.curPosition())},X.skipSpace=function(){loop:for(;this.pos<this.input.length;){var e=this.input.charCodeAt(this.pos);switch(e){case 32:case 160:++this.pos;break;case 13:this.input.charCodeAt(this.pos+1)===10&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break loop}break;default:if(e>8&&e<14||e>=5760&&zx.test(String.fromCharCode(e)))++this.pos;else break loop}}},X.finishToken=function(e,t){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var n=this.type;this.type=e,this.value=t,this.updateContext(n)},X.readToken_dot=function(){var e=this.input.charCodeAt(this.pos+1);if(e>=48&&e<=57)return this.readNumber(!0);var t=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&e===46&&t===46?(this.pos+=3,this.finishToken(K.ellipsis)):(++this.pos,this.finishToken(K.dot))},X.readToken_slash=function(){var e=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):e===61?this.finishOp(K.assign,2):this.finishOp(K.slash,1)},X.readToken_mult_modulo_exp=function(e){var t=this.input.charCodeAt(this.pos+1),n=1,r=e===42?K.star:K.modulo;return this.options.ecmaVersion>=7&&e===42&&t===42&&(++n,r=K.starstar,t=this.input.charCodeAt(this.pos+2)),t===61?this.finishOp(K.assign,n+1):this.finishOp(r,n)},X.readToken_pipe_amp=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?this.options.ecmaVersion>=12&&this.input.charCodeAt(this.pos+2)===61?this.finishOp(K.assign,3):this.finishOp(e===124?K.logicalOR:K.logicalAND,2):t===61?this.finishOp(K.assign,2):this.finishOp(e===124?K.bitwiseOR:K.bitwiseAND,1)},X.readToken_caret=function(){return this.input.charCodeAt(this.pos+1)===61?this.finishOp(K.assign,2):this.finishOp(K.bitwiseXOR,1)},X.readToken_plus_min=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?t===45&&!this.inModule&&this.input.charCodeAt(this.pos+2)===62&&(this.lastTokEnd===0||Fx.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(K.incDec,2):t===61?this.finishOp(K.assign,2):this.finishOp(K.plusMin,1)},X.readToken_lt_gt=function(e){var t=this.input.charCodeAt(this.pos+1),n=1;return t===e?(n=e===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+n)===61?this.finishOp(K.assign,n+1):this.finishOp(K.bitShift,n)):t===33&&e===60&&!this.inModule&&this.input.charCodeAt(this.pos+2)===45&&this.input.charCodeAt(this.pos+3)===45?(this.skipLineComment(4),this.skipSpace(),this.nextToken()):(t===61&&(n=2),this.finishOp(K.relational,n))},X.readToken_eq_excl=function(e){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(K.equality,this.input.charCodeAt(this.pos+2)===61?3:2):e===61&&t===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(K.arrow)):this.finishOp(e===61?K.eq:K.prefix,1)},X.readToken_question=function(){var e=this.options.ecmaVersion;if(e>=11){var t=this.input.charCodeAt(this.pos+1);if(t===46){var n=this.input.charCodeAt(this.pos+2);if(n<48||n>57)return this.finishOp(K.questionDot,2)}if(t===63)return e>=12&&this.input.charCodeAt(this.pos+2)===61?this.finishOp(K.assign,3):this.finishOp(K.coalesce,2)}return this.finishOp(K.question,1)},X.readToken_numberSign=function(){var e=this.options.ecmaVersion,t=35;if(e>=13&&(++this.pos,t=this.fullCharCodeAtPos(),kx(t,!0)||t===92))return this.finishToken(K.privateId,this.readWord1());this.raise(this.pos,`Unexpected character '`+Jx(t)+`'`)},X.getTokenFromCode=function(e){switch(e){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(K.parenL);case 41:return++this.pos,this.finishToken(K.parenR);case 59:return++this.pos,this.finishToken(K.semi);case 44:return++this.pos,this.finishToken(K.comma);case 91:return++this.pos,this.finishToken(K.bracketL);case 93:return++this.pos,this.finishToken(K.bracketR);case 123:return++this.pos,this.finishToken(K.braceL);case 125:return++this.pos,this.finishToken(K.braceR);case 58:return++this.pos,this.finishToken(K.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(K.backQuote);case 48:var t=this.input.charCodeAt(this.pos+1);if(t===120||t===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(t===111||t===79)return this.readRadixNumber(8);if(t===98||t===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(e);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(e);case 124:case 38:return this.readToken_pipe_amp(e);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(e);case 60:case 62:return this.readToken_lt_gt(e);case 61:case 33:return this.readToken_eq_excl(e);case 63:return this.readToken_question();case 126:return this.finishOp(K.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,`Unexpected character '`+Jx(e)+`'`)},X.finishOp=function(e,t){var n=this.input.slice(this.pos,this.pos+t);return this.pos+=t,this.finishToken(e,n)},X.readRegexp=function(){for(var e,t,n=this.pos;;){this.pos>=this.input.length&&this.raise(n,`Unterminated regular expression`);var r=this.input.charAt(this.pos);if(Fx.test(r)&&this.raise(n,`Unterminated regular expression`),e)e=!1;else{if(r===`[`)t=!0;else if(r===`]`&&t)t=!1;else if(r===`/`&&!t)break;e=r===`\\`}++this.pos}var i=this.input.slice(n,this.pos);++this.pos;var a=this.pos,o=this.readWord1();this.containsEsc&&this.unexpected(a);var s=this.regexpState||=new hC(this);s.reset(n,i,o),this.validateRegExpFlags(s),this.validateRegExpPattern(s);var c=null;try{c=new RegExp(i,o)}catch{}return this.finishToken(K.regexp,{pattern:i,flags:o,value:c})},X.readInt=function(e,t,n){for(var r=this.options.ecmaVersion>=12&&t===void 0,i=n&&this.input.charCodeAt(this.pos)===48,a=this.pos,o=0,s=0,c=0,l=t??1/0;c<l;++c,++this.pos){var u=this.input.charCodeAt(this.pos),d=void 0;if(r&&u===95){i&&this.raiseRecoverable(this.pos,`Numeric separator is not allowed in legacy octal numeric literals`),s===95&&this.raiseRecoverable(this.pos,`Numeric separator must be exactly one underscore`),c===0&&this.raiseRecoverable(this.pos,`Numeric separator is not allowed at the first of digits`),s=u;continue}if(d=u>=97?u-97+10:u>=65?u-65+10:u>=48&&u<=57?u-48:1/0,d>=e)break;s=u,o=o*e+d}return r&&s===95&&this.raiseRecoverable(this.pos-1,`Numeric separator is not allowed at the last of digits`),this.pos===a||t!=null&&this.pos-a!==t?null:o};function LC(e,t){return t?parseInt(e,8):parseFloat(e.replace(/_/g,``))}function RC(e){return typeof BigInt==`function`?BigInt(e.replace(/_/g,``)):null}X.readRadixNumber=function(e){var t=this.pos;this.pos+=2;var n=this.readInt(e);return n??this.raise(this.start+2,`Expected number in radix `+e),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(n=RC(this.input.slice(t,this.pos)),++this.pos):kx(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`),this.finishToken(K.num,n)},X.readNumber=function(e){var t=this.pos;!e&&this.readInt(10,void 0,!0)===null&&this.raise(t,`Invalid number`);var n=this.pos-t>=2&&this.input.charCodeAt(t)===48;n&&this.strict&&this.raise(t,`Invalid number`);var r=this.input.charCodeAt(this.pos);if(!n&&!e&&this.options.ecmaVersion>=11&&r===110){var i=RC(this.input.slice(t,this.pos));return++this.pos,kx(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`),this.finishToken(K.num,i)}n&&/[89]/.test(this.input.slice(t,this.pos))&&(n=!1),r===46&&!n&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!n&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(t,`Invalid number`)),kx(this.fullCharCodeAtPos())&&this.raise(this.pos,`Identifier directly after number`);var a=LC(this.input.slice(t,this.pos),n);return this.finishToken(K.num,a)},X.readCodePoint=function(){var e=this.input.charCodeAt(this.pos),t;if(e===123){this.options.ecmaVersion<6&&this.unexpected();var n=++this.pos;t=this.readHexChar(this.input.indexOf(`}`,this.pos)-this.pos),++this.pos,t>1114111&&this.invalidStringToken(n,`Code point out of bounds`)}else t=this.readHexChar(4);return t},X.readString=function(e){for(var t=``,n=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,`Unterminated string constant`);var r=this.input.charCodeAt(this.pos);if(r===e)break;r===92?(t+=this.input.slice(n,this.pos),t+=this.readEscapedChar(!1),n=this.pos):r===8232||r===8233?(this.options.ecmaVersion<10&&this.raise(this.start,`Unterminated string constant`),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(Lx(r)&&this.raise(this.start,`Unterminated string constant`),++this.pos)}return t+=this.input.slice(n,this.pos++),this.finishToken(K.string,t)};var zC={};X.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e===zC)this.readInvalidTemplateToken();else throw e}this.inTemplateElement=!1},X.invalidStringToken=function(e,t){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw zC;this.raise(e,t)},X.readTmplToken=function(){for(var e=``,t=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,`Unterminated template`);var n=this.input.charCodeAt(this.pos);if(n===96||n===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===K.template||this.type===K.invalidTemplate)?n===36?(this.pos+=2,this.finishToken(K.dollarBraceL)):(++this.pos,this.finishToken(K.backQuote)):(e+=this.input.slice(t,this.pos),this.finishToken(K.template,e));if(n===92)e+=this.input.slice(t,this.pos),e+=this.readEscapedChar(!0),t=this.pos;else if(Lx(n)){switch(e+=this.input.slice(t,this.pos),++this.pos,n){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:e+=`
|
|
14
14
|
`;break;default:e+=String.fromCharCode(n)}this.options.locations&&(++this.curLine,this.lineStart=this.pos),t=this.pos}else++this.pos}},X.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case`\\`:++this.pos;break;case`$`:if(this.input[this.pos+1]!==`{`)break;case"`":return this.finishToken(K.invalidTemplate,this.input.slice(this.start,this.pos));case`\r`:this.input[this.pos+1]===`
|
|
15
15
|
`&&++this.pos;case`
|
|
16
16
|
`:case`\u2028`:case`\u2029`:++this.curLine,this.lineStart=this.pos+1}this.raise(this.start,`Unterminated template`)},X.readEscapedChar=function(e){var t=this.input.charCodeAt(++this.pos);switch(++this.pos,t){case 110:return`
|
|
17
|
-
`;case 114:return`\r`;case 120:return String.fromCharCode(this.readHexChar(2));case 117:return qx(this.readCodePoint());case 116:return` `;case 98:return`\b`;case 118:return`\v`;case 102:return`\f`;case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),``;case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,`Invalid escape sequence`),e){var n=this.pos-1;this.invalidStringToken(n,`Invalid escape sequence in template string`)}default:if(t>=48&&t<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],i=parseInt(r,8);return i>255&&(r=r.slice(0,-1),i=parseInt(r,8)),this.pos+=r.length-1,t=this.input.charCodeAt(this.pos),(r!==`0`||t===56||t===57)&&(this.strict||e)&&this.invalidStringToken(this.pos-1-r.length,e?`Octal literal in template string`:`Octal literal in strict mode`),String.fromCharCode(i)}return Ix(t)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),``):String.fromCharCode(t)}},X.readHexChar=function(e){var t=this.pos,n=this.readInt(16,e);return n===null&&this.invalidStringToken(t,`Bad character escape sequence`),n},X.readWord1=function(){this.containsEsc=!1;for(var e=``,t=!0,n=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(kx(i,r))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,e+=this.input.slice(n,this.pos);var a=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,`Expecting Unicode escape sequence \\uXXXX`),++this.pos;var o=this.readCodePoint();(t?Ox:kx)(o,r)||this.invalidStringToken(a,`Invalid Unicode escape`),e+=qx(o),n=this.pos}else break;t=!1}return e+this.input.slice(n,this.pos)},X.readWord=function(){var e=this.readWord1(),t=K.name;return this.keywords.test(e)&&(t=Nx[e]),this.finishToken(t,e)},xS.acorn={Parser:xS,version:`8.18.0`,defaultOptions:Qx,Position:Yx,SourceLocation:Xx,getLineInfo:Zx,Node:WS,TokenType:W,tokTypes:K,keywordTypes:Nx,TokContext:FS,tokContexts:IS,isIdentifierChar:kx,isIdentifierStart:Ox,Token:FC,isNewLine:Ix,lineBreak:Px,lineBreakG:Fx,nonASCIIwhitespace:Rx};function zC(e,t){return xS.parse(e,t)}b(()=>Or(`ok`,[ur({ok:Kt(!0),value:Rr()}),ur({ok:Kt(!1),error:ur({kind:Kt(`guest_threw`),name:S().max(80),message:S().max(512),transportMessage:S().max(512).optional()})})]));var BC=b(()=>S().regex(/^[A-Za-z][A-Za-z0-9_]*$/u)),VC=BC.refine(e=>{if(e===`env`)return!1;try{return zC(`let ${e};`,{ecmaVersion:`latest`,sourceType:`module`}),!0}catch(e){if(!(e instanceof SyntaxError))throw e;return!1}},`Invalid sandbox transport alias`);b(()=>cn(VC,kt(BC).min(1))),b(()=>cn(VC,kt(S().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u))));var HC=F([`read`,`write`]),UC=wp,WC=N({access:k(HC),confirm:k(UC)}),GC=F([`none`,`read`,`write`]),KC=E(WC),qC=E(GC);function JC(e){let t=KC({access:e.access,confirm:e.confirm});if(xt(t))throw new U(`Access labels must be access: "read" | "write" and confirm: boolean`);return{access:t.success.access??`write`,confirm:t.success.confirm??!1}}function YC(e,t){let n=`${t.module}.${t.operation}`;switch(e){case`not-granted`:return`${n} is not granted to this Agent.`;case`read-only`:return`${n} changes something, and this Agent has read-only access to ${t.module}.`;case`confirmation-unavailable`:return`${n} needs a person's approval, and no one can be asked here.`;case`declined`:return`${n} was not approved.`}}function XC(e,t){return Object.freeze({refused:!0,module:t.module,operation:t.operation,reason:e,message:YC(e,t)})}function ZC(e,t,n){let r=e.sessionGrants?.(t),i=r!==void 0&&Object.hasOwn(r,n)?r:e.grants;if(i===void 0||!Object.hasOwn(i,n))return e.required?.includes(n)===!0?`none`:e.defaultGrant??`write`;let a=qC(i[n]);return ve(a)?a.success:`none`}async function QC(e,t,n,r,i){let a=await $C(e,t,n,r,i);return a!==void 0&&e.onRefused?.(a,t),a}async function $C(e,t,n,r,i){await e.beforeCall?.(i),i.throwIfAborted();let a=ew(e,t,n);if(a!==void 0)return a;if(!(!n.confirm&&(e.confirmWrites!==!0||n.access===`read`)))return e.confirm===void 0?XC(`confirmation-unavailable`,n):await e.confirm({module:n.module,operation:n.operation,access:n.access,sessionId:t.sessionId,input:r},i)?(await e.beforeCall?.(i),i.throwIfAborted(),ew(e,t,n)):XC(`declined`,n)}function ew(e,t,n){let r=ZC(e,t,n.module);if(r===`none`)return XC(`not-granted`,n);if(r===`read`&&n.access!==`read`)return XC(`read-only`,n)}function tw(e,t,n){let r={module:e.module,operation:e.descriptor.name,...JC(e)};return{...e,prepare:i=>Vr({try:e=>QC(t,n,r,i.arguments,e),catch:()=>({message:`Access check failed`})}).pipe(w(t=>t===void 0?e.prepare(i):v({execute:()=>R_({type:`result`,result:{content:[{type:`text`,text:JSON.stringify(t)}],isError:!1}})})))}}var nw=Uo();async function rw(e){let t=await Sr(e);if(qi(t))return{value:t.value};let n=Ii(t.cause);if(xt(n))throw Fi(t.cause);return{issues:nw(n.success.issue).issues}}function iw(e){let t=ah(e),n=np(t)[`~standard`].jsonSchema,r=ip(t),i=up(t);return Object.freeze({description:{"~standard":{jsonSchema:{input:n.input,output:n.input}}},decode:e=>rw(r(e)),encode:e=>rw(i(e))})}function aw(e){let t=async t=>e[`~standard`].validate(t);return Object.freeze({description:e,decode:t,encode:t})}function ow(e){return gp(e)?iw(e):aw(e)}var sw=Symbol(`mycelium.operation`),cw=Symbol(`mycelium.module`),lw=new WeakMap,uw=new WeakMap;function dw(e){let t=Object.freeze({[sw]:!0}),n=ow(e.input),r=e.output===void 0?void 0:ow(e.output),i={replay:e.replay??`unsafe`,...JC(e),input:n.description,invoke:async(t,i)=>{let a=await n.decode(t);if(a.issues!==void 0)throw new Hb(a.issues);let o=await e.execute(a.value,i);if(r===void 0)return o;let s=await r.encode(o);if(s.issues!==void 0)throw new Zb({reason:`Capability output failed its declared schema`,rawCause:new Ub(s.issues)});return s.value}};e.description!==void 0&&(i.description=e.description),r!==void 0&&(i.output=r.description);let a=Object.freeze(i);return lw.set(t,a),t}function fw(e){let t=kt(BC).safeParse(e.namespace??[]);if(!t.success)throw new U(`Invalid module namespace`);let n=Object.freeze({[cw]:!0}),r={id:e.id,grantKey:e.id,name:e.name??e.id,namespace:Object.freeze(t.data),operations:Object.freeze({...e.operations})};e.description!==void 0&&(r.description=e.description);let i=Object.freeze(r);return uw.set(n,i),n}function pw(e){return uw.has(e)}function mw(e){return lw.get(e)}function hw(e){return uw.get(e)}function gw(e,t,n){let r=hw(e);if(r===void 0)throw new U(`Unknown module registration`);let i={};for(let[e,a]of Object.entries(r.operations)){let r=n===``?e:`${n}.${e}`;if(pw(a)){let n=hw(a);if(n===void 0)throw new U(`Unknown child module registration`);i[e]=gw(a,t,[r,...n.namespace].join(`.`));continue}let o=mw(a);if(o===void 0)throw new U(`Unknown operation registration: ${e}`);let s=Object.freeze({[sw]:!0});lw.set(s,Object.freeze({...o,invoke:async(e,n)=>{let i=await t({operation:r,context:n});return i.kind===`refuse`?i.value:await o.invoke(e,n)}})),i[e]=s}return _w(fw(r.description===void 0?{id:r.id,name:r.name,namespace:r.namespace,operations:i}:{id:r.id,name:r.name,namespace:r.namespace,description:r.description,operations:i}),r.grantKey)}function _w(e,t){let n=hw(e);if(n===void 0)throw new U(`Unknown module registration`);let r=Object.freeze({[cw]:!0});return uw.set(r,Object.freeze({...n,grantKey:t})),r}function vw(e,t){if(t.length===0||t.length>160)throw new U(`Grant key must be non-empty and bounded`);return _w(e,t)}function yw(e,t){return gw(e,t,``)}function bw(e,t){return e<t?-1:+(e>t)}function xw(e){return e instanceof Error?e.message:`Capability declarations could not be compiled`}var Sw=160;function Cw(e){if(e.length===0||e.length>Sw)throw new U(`Module id must be non-empty and bounded`)}function ww(e){if(!e.split(`.`).every(e=>BC.safeParse(e).success))throw new U(`Operation key must be a path segment or a dotted relative path`)}function Tw(e){let t=e.replace(/[^A-Za-z0-9_]/g,`_`);return/^[A-Za-z]/.test(t)?t:`module_${t}`}function Ew(e){let t=Tw(e);return VC.safeParse(t).success?t:`module_${t}`}function Dw(e,t){let n=new Set([`forage`,`env`]),r=new Map;for(let i of e){let e=t===`logical`?i.namespace:[],a=t===`logical`?Tw(i.name):Ew(i.name),o=t=>[...e,t].join(`.`),s=a,c=2;for(;n.has(o(s));)s=`${a}_${String(c)}`,c+=1;n.add(o(s)),r.set(i.id,s)}return r}var Ow=14695981039346656037n,kw=1099511628211n,Aw=18446744073709551615n;function jw(e,t){let n=e,r=BigInt(t.length);for(let e=0;e<8;e+=1)n=(n^r&255n)*kw&Aw,r>>=8n;for(let e=0;e<t.length;e+=1){let r=t.charCodeAt(e);n=(n^BigInt(r&255))*kw&Aw,n=(n^BigInt(r>>>8&255))*kw&Aw}return n}function Mw(e,t,n){let r=jw(Ow,e),i=[...t.entries()].sort(([e],[t])=>bw(e,t));for(let[e,t]of i)r=jw(r,e),r=jw(r,t);let a=[...n].sort((e,t)=>bw(e.id,t.id));for(let e of a)r=jw(r,e.id),r=jw(r,e.version);return`installed-${r.toString(16).padStart(16,`0`)}`}function Nw(){return[Fb,Pb,Ib]}function Pw(e,t,n,r,i,a=[]){return Object.entries(t.operations).flatMap(([t,o])=>{if(ww(t),pw(o)){let s=hw(o);if(s===void 0)throw new U(`Unknown child module registration`);return Pw(e,s,n,[...r,t,...s.namespace],s.description??i,[...a,t,...s.namespace])}let s=mw(o);if(s===void 0)throw new U(`Unknown operation registration: ${[...r,t].join(`.`)}`);return[Object.freeze({grantKey:e,path:[...r,t].join(`.`),namespace:n,name:[...a,t].join(`.`),moduleDescription:i,operation:s})]})}function Fw(e,t=[]){let n=e.map(e=>{let t=hw(e);if(t===void 0)throw new U(`Unknown module registration`);return Cw(t.id),t}).sort((e,t)=>bw(e.id,t.id)),r=new Set;for(let e of n){if(r.has(e.id))throw new U(`Duplicate module id: ${e.id}`);r.add(e.id)}let i=Dw(n,`transport`),a=Dw(n,`logical`),o=Object.freeze(Object.fromEntries(n.map(e=>{let t=i.get(e.id);if(t===void 0)throw new U(`Missing module alias: ${e.id}`);let n=a.get(e.id);if(n===void 0)throw new U(`Missing logical alias: ${e.id}`);return[t,Object.freeze([...e.namespace,n])]}))),s=n.flatMap(e=>{let t=i.get(e.id);if(t===void 0)throw new U(`Missing module alias: ${e.id}`);let n=o[t];if(n===void 0)throw new U(`Missing namespace path: ${e.id}`);return Pw(e.grantKey,e,t,n,e.description)}).sort((e,t)=>bw(e.path,t.path)),c=new Set(s.map(e=>e.path));if(c.size!==s.length)throw new U(`Duplicate operation path`);for(let e of Nw()){if(c.has(e.path))throw new U(`Reserved intrinsic path: ${e.path}`);c.add(e.path)}for(let e of c){let t=e.split(`.`);for(let n=1;n<t.length;n+=1)if(c.has(t.slice(0,n).join(`.`)))throw new U(`Operation conflicts with namespace: ${e}`)}let l;try{l=jb({revision:`prepared-content-stamp`,operations:[...s.map(({path:e,moduleDescription:t,operation:n})=>{let r={path:e,input:n.input};return n.description!==void 0&&(r.description=n.description),n.output!==void 0&&(r.output=n.output),t!==void 0&&(r.instructions=t),r}),...Nw()]})}catch(e){throw new U(xw(e))}let u=Mw(l.stamp(),i,t),d=Object.freeze({revision:u,search:l.search,describe:l.describe,list:l.list,stamp:l.stamp}),f=Object.freeze(Object.fromEntries([...i.entries()].map(([e,t])=>[t,e])));return Object.freeze({revision:u,catalog:d,operations:Object.freeze(s),moduleAliases:f,namespacePaths:o})}function Iw(){return null}var Lw=yr(),Rw=b(()=>zt([hr(),S(),t(),tn()])),zw=b(()=>cn(S(),Rr())),Bw=b(()=>hx.extend({timeoutMs:tn().int().min(1).max(9e5).optional(),abortGraceMs:tn().int().min(1).max(3e4).optional()}).optional()),Vw=64,Hw=262144,Uw=new TextEncoder,Ww=e=>{e(v(void 0))};function Gw(e){let t=Bw.safeParse(e);if(!t.success)throw new U(`Execution policy is invalid`);return Object.freeze({timeoutMs:t.data?.timeoutMs??18e4,abortGraceMs:t.data?.abortGraceMs??5e3,...gx({sandboxCapacity:t.data?.sandboxCapacity,admissionWaitMs:t.data?.admissionWaitMs},(t.data?.sandboxCapacity,void 0))})}function Kw(e){return x(function*(){let t=yield*Pg(e);return Object.freeze({createGroup:()=>{let e=0,n=new Set,r=Hn(t=>e===0?(t(v(void 0)),C(()=>void 0)):(n.add(t),C(()=>n.delete(t))));return Object.freeze({start:r=>Jr(i=>C(()=>{e+=1}).pipe(Gt(ne(i(t.withPermits(1)(r)).pipe(Jn(C(()=>{if(--e,e===0){let e=[...n];n.clear(),e.forEach(Ww)}}))))))),awaitIdle:r})}})})}function qw(e,t=0){if(t>Vw)throw Error(`JSON value exceeds the nesting bound`);let n=Rw.safeParse(e);if(n.success)return n.data;if(Array.isArray(e))return e.map(e=>qw(e,t+1));let r=zw.safeParse(e);if(!r.success)throw r.error;return Object.fromEntries(Object.entries(r.data).filter(([,e])=>e!==void 0).map(([e,n])=>[e,qw(n,t+1)]))}function Jw(e){return Lw.parse(qw(e))}function Yw(e){let t=JSON.stringify(Jw(e)),n=Uw.encode(t).byteLength;if(n>Hw)throw new Qb({size:n});return Object.freeze({text:t})}function Xw(e,t){return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Object.freeze(Object.fromEntries(Object.entries(n).map(([n,r])=>[n,async i=>{t();try{return Jw(await r(i))}catch(t){throw ox(t)?t:t instanceof Dy?new ex({namespace:e,operation:n,cause:{kind:`Forage`,message:t.message},rawCause:t}):t instanceof Hb?new ex({namespace:e,operation:n,cause:{kind:`InvalidInput`,message:`Invalid operation input: ${Ht({issues:t.issues})}; use forage.describe`},rawCause:t}):t}}])))])))}function Zw(e){return Hn(t=>{let n=t.bind(void 0,_);return e.aborted?n():e.addEventListener(`abort`,n,{once:!0}),C(e.removeEventListener.bind(e,`abort`,n))})}function Qw(e,t){if(e===void 0)return()=>void 0;let n=t.bind(void 0);return e.aborted?(n(),()=>void 0):(e.addEventListener(`abort`,n,{once:!0}),e.removeEventListener.bind(e,`abort`,n))}function $w(e,t,n){return e===`deadline_exceeded`?new Kb({limitMs:t,elapsedMs:n??0}):new Jb({by:`caller`})}function eT(e){return ha.pipe(xe(t=>t-e))}function tT(t){return ha.pipe(w(n=>bn(()=>{let r=t.executionId,i=new AbortController,a=n,o={kind:`waiting`},s,c=e=>{s===void 0&&o.kind!==`refused`&&(s=e,i.abort())},l=e=>{let n=new qb({capacity:t.policy.capacity,waitedMs:Math.max(0,e-a)});return o={kind:`refused`,failure:n},n},u=()=>{if(i.signal.aborted)throw $w(s,t.policy.timeoutMs)},d=Qw(t.callerSignal,()=>{c(`cancelled`)}),f=n+t.policy.timeoutMs,p={executionId:r,deadlineAt:f,signal:i.signal,images:t.images};t.toolCallId!==void 0&&Object.assign(p,{toolCallId:t.toolCallId}),t.output!==void 0&&Object.assign(p,{output:t.output});let m=Object.freeze(p),ee=bn(()=>ha.pipe(w(e=>o.kind===`refused`?y(o.failure):(e>=f&&c(`deadline_exceeded`),i.signal.aborted?eT(n).pipe(w(e=>y($w(s,t.policy.timeoutMs,e)))):e>=a+t.policy.waitMs?y(l(e)):(o={kind:`admitted`},t.sandbox.execute(Object.freeze({executionId:r,code:t.code,timeoutMs:t.policy.timeoutMs,bindings:Xw(t.createBindings(m),u),modules:t.modules,namespacePaths:t.namespacePaths,sessionId:t.sessionId}),i.signal).pipe(Mr(e=>Ni(e)?Rt(e):y(sx(Fi(e)))))))))),te=e=>Dg(e).pipe(Wt({duration:t.policy.abortGraceMs,orElse:()=>y(s===`deadline_exceeded`?new Kb({limitMs:t.policy.timeoutMs,elapsedMs:t.policy.timeoutMs,acknowledged:!1}):new Jb({by:`caller`,acknowledged:!1}))})),ne,h=!1,re=e=>(h=!0,eT(n).pipe(w(n=>{let i=sx(e),a=i instanceof Kb?new Kb({limitMs:i.limitMs,elapsedMs:n,acknowledged:i.acknowledged}):i,o=nx(a,r),s=cn(S(),yr()).parse(lx(a));s.ref=r;let c={kind:`sandbox_failure`,ref:r,executionId:r,adapter:t.sandbox.adapter??`effect`,buildSha:t.sandbox.buildSha??Iw(),tag:o._tag,fields:s,healthAlert:o._tag===`Unknown`},l=bn(()=>t.sandbox.onFailure?.(c)??_);return Xe(`sandbox_failure`,c).pipe(rr({executionId:r,ref:r,adapter:c.adapter,tag:c.tag,buildSha:c.buildSha}),Gt(o._tag===`Unknown`?Ra(za(La(`sandbox_unknown`),{adapter:c.adapter}),1).pipe(Gt(Xe(`sandbox_health_alert`).pipe(rr({ref:r,adapter:c.adapter})))):_),Gt(l.pipe(Mr(e=>Xe(`sandbox_failure_record_failed`,e)))),Cr(o))})));return x(function*(){if(i.signal.aborted){let e=yield*eT(n);return yield*y($w(s,t.policy.timeoutMs,e))}a=yield*ha,ne=yield*t.backingWork.start(ee);let r=yield*ha,u=Ir(Math.max(0,a+t.policy.waitMs-r)).pipe(Gt(ha),w(e=>o.kind===`admitted`?wt:o.kind===`refused`?v({kind:`busy`,failure:o.failure}):i.signal.aborted?v({kind:`cancelled`}):e>=f?(c(`deadline_exceeded`),v({kind:`deadline`})):v({kind:`busy`,failure:l(e)}))),d=yield*e(Tg(ne).pipe(xe(e=>Object.freeze({kind:`settled`,exit:e}))),e(Ir(Math.max(0,f-r)).pipe(Gt(C(()=>(c(`deadline_exceeded`),Object.freeze({kind:`deadline`}))))),e(Zw(i.signal).pipe(Cr(Object.freeze({kind:`cancelled`}))),u))),p=o.kind===`refused`?o.failure:d.kind===`busy`?d.failure:void 0;if(p!==void 0)return yield*te(ne).pipe(Gt(y(p)));if(d.kind===`settled`)return yield*ge(d.exit,{onFailure:e=>s===void 0?Rt(e):eT(n).pipe(w(e=>y($w(s,t.policy.timeoutMs,e)))),onSuccess:e=>Qr({try:()=>Yw(e),catch:t=>ox(t)?t:new $b({kind:cx(e),rawCause:t})})});d.kind===`deadline`&&c(`deadline_exceeded`);let m=yield*eT(n);return yield*te(ne).pipe(Gt(y($w(s,t.policy.timeoutMs,m))))}).pipe(Te(()=>(c(`cancelled`),(ne===void 0?_:Dg(ne).pipe(Cn(t.policy.abortGraceMs),en)).pipe(Gt(bn(()=>h?_:re(new Jb({by:`operator`})).pipe(en))))))).pipe(sn(e=>re(e).pipe(w(y))),Jn(C(d)))})))}var nT=Ip(()=>P([Cp,Sp,wp,M,j,th,Kp(AbortSignal),jp(nT),rT])),rT=Op(j,nT);function iT(e){return cp(rT)(e)}var aT=Op(j,oh),oT=cp(N({samplingParams:O(aT),samplingParamsByThinkingLevel:O(N({off:O(aT),minimal:O(aT),low:O(aT),medium:O(aT),high:O(aT),xhigh:O(aT),max:O(aT)}))}));function sT(e){return{...e,...oT(e)}}function cT(e){if(e===void 0)return;let{onPayload:t,onProviderStreamEvent:n,onResponse:r,...i}=e,a={...i};return t!==void 0&&(a.onPayload=(e,n)=>t(iT(e),sT(n))),n!==void 0&&(a.onProviderStreamEvent=(e,t)=>n(iT(e),sT(t))),r!==void 0&&(a.onResponse=(e,t)=>r(e,sT(t))),a}var lT=async(e,t,n)=>{let{streamSimple:r}=await ri(async()=>{let{streamSimple:e}=await import(`./compat-wIVDvT_3.js`);return{streamSimple:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));return r(e,ni(t),cT(n))},uT=N({error:N({code:j})});op(N({type:A(`response.failed`),response:uT})),op(Xm(uT)),cp(Kp(Uint8Array));var dT=[/prompt (?:is )?too long/i,/prompt exceeds max length/i,/request_too_large/i,/input is too long for requested model/i,/exceeds the context window/i,/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,/input token count.*exceeds the maximum/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/maximum context length is \d+ tokens/i,/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,/exceeds the limit of \d+/i,/exceeds the available context size/i,/greater than the context length/i,/context window exceeds limit/i,/exceeded model token limit/i,/too large for model with \d+ maximum context length/i,/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,/model_context_window_exceeded/i,/prompt too long; exceeded (?:max )?context length/i,/range of input length should be/i,/context[_ ]length[_ ]exceeded/i,/too many tokens/i,/token limit exceeded/i],fT=/^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i,pT=[/^(Throttling error|Service unavailable):/i,/rate limit/i,/too many requests/i];function mT(e,t){return!!(e.stopReason===`error`&&e.errorMessage&&!pT.some(t=>t.test(e.errorMessage))&&(dT.some(t=>t.test(e.errorMessage))||e.provider===`cerebras`&&fT.test(e.errorMessage))||t&&e.stopReason===`stop`&&e.usage.input+e.usage.cacheRead>t||t&&e.stopReason===`length`&&e.usage.output===0&&e.usage.input+e.usage.cacheRead>=t*.99)}function hT(e,t){return e.stopReason===`length`&&t>0&&e.usage.output<t}function gT(e){return new RegExp(e.join(`|`),`i`)}var _T=gT([`GoUsageLimitError`,`FreeUsageLimitError`,`Monthly usage limit reached`,`available balance`,`insufficient_quota`,`out of budget`,`quota exceeded`,`billing`,`subscription_sharing_usage_limit_exceeded`]),vT=gT(`overloaded,server_busy,servers are currently busy,currently experiencing high demand,model is at capacity,rate.?limit,too many requests,429,500,502,503,504,520,524,service.?(?:is.?)?(?:temporarily.?)?unavailable,server.?error,internal.?error,provider.?returned.?(?:an.?)?error,exceeded request buffer limit while retrying upstream,unable to forward upstream,network.?error,connection.?error,connection.?refused,connection.?lost,other side closed,fetch failed,getaddrinfo,ENOTFOUND,EAI_AGAIN,upstream.?connect,reset before headers,socket hang up,socket connection was closed,timed? out,timeout,terminated,websocket.?closed,websocket.?error,ended without,stream ended before message_stop,stream ended before a terminal response event,http2 request did not get a response,pending stream has been canceled,retry delay,you can retry your request,try your request again,please retry your request,ResourceExhausted,subscription_sharing_usage_unavailable,subscription_sharing_user_unavailable`.split(`,`)),yT=6e4;function bT(e,t){let n=e.baseDelayMs*2**Math.max(0,t-1);return Math.min(Number.isSafeInteger(n)?n:2**53-1,e.maxAgentDelayMs??6e4)}var xT=class extends Error{constructor(){super(`Aborted`)}};function ST(e,t){return new Promise((n,r)=>{if(t?.aborted){r(new xT);return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(new xT)},{once:!0})})}async function CT(e,t,n,r){let i=t?.enabled?t.maxRetries:0,a=0,o;for(;;){let s=await e();if(s.stopReason===`aborted`)return o&&await r?.onRetryFinished?.(!1,o.attempt),s;if(s.stopReason!==`error`)return o&&await r?.onRetryFinished?.(!0,o.attempt),s;if(a>=i||!wT(s))return o&&await r?.onRetryFinished?.(!1,o.attempt,s.errorMessage),s;a++,o={attempt:a,errorMessage:s.errorMessage||`Unknown error`};let c=bT(t,a);await r?.onRetryScheduled?.(a,i,c,o.errorMessage);try{await ST(c,n)}catch(e){if(await r?.onRetryFinished?.(!1,a,o.errorMessage),e instanceof xT){let{errorMessage:e,...t}=s;return{...t,stopReason:`aborted`}}throw e}await r?.onRetryAttemptStart?.()}}function wT(e){if(e.stopReason!==`error`||!e.errorMessage)return!1;let t=e.errorMessage;return!_T.test(t)&&vT.test(t)}var TT={assign:0,create:0,clone:0,discard:0,update:0};function ET(e){return OT(e,null)}function DT(e){return OT(typeof e,`object`)&&!ET(e)}function OT(e,t){return e===t}function kT(e){return OT(e,`__proto__`)||OT(e,`constructor`)||OT(e,`prototype`)}function AT(e,t){return kT(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function jT(e){return Object.getOwnPropertyNames(e)}var MT={immutableTypes:!1,maxErrors:8,maxInstantiationCount:128,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function NT(){return MT}function PT(e){return NT().immutableTypes?Object.freeze(e):e}function FT(e,t){for(let n of Object.keys(t))Object.defineProperty(e,n,{configurable:!0,writable:!0,enumerable:!1,value:t[n]});return e}function IT(e,t){return{...e,...t}}function LT(e,t,n={}){TT.create+=1;let r=IT(t,n);return PT(NT().enumerableKind?IT(r,e):FT(r,e))}function RT(e){return DT(e)}function zT(e){return RT(e)&&AT(e,`~optional`)}function BT(e){return jT(e).filter(t=>!zT(e[t]))}function VT(e,t={}){let n=BT(e);return LT({"~kind":`Object`},{type:`object`,...n.length>0?{required:n}:{},properties:e},t)}var HT;(function(e){e[e.Array=0]=`Array`,e[e.BigInt=1]=`BigInt`,e[e.Boolean=2]=`Boolean`,e[e.Date=3]=`Date`,e[e.Constructor=4]=`Constructor`,e[e.Function=5]=`Function`,e[e.Null=6]=`Null`,e[e.Number=7]=`Number`,e[e.Object=8]=`Object`,e[e.RegExp=9]=`RegExp`,e[e.String=10]=`String`,e[e.Symbol=11]=`Symbol`,e[e.TypeArray=12]=`TypeArray`,e[e.Undefined=13]=`Undefined`})(HT||={}),Array.from({length:256}).map((e,t)=>BigInt(t));var UT=new Float64Array(1);new DataView(UT.buffer),new Uint8Array(UT.buffer),new TextEncoder;var WT=`-?(?:0|[1-9][0-9]*)`,GT=`-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?`;function KT(e){return LT({"~kind":`String`},{type:`string`},e)}var qT=`^${WT}$`;`${GT}`;function JT(e,t){return Array.from({length:t-e+1},(t,n)=>String.fromCharCode(e+n))}var YT=[...JT(97,122),...JT(65,90)],XT=[`0`,...JT(49,57)];[...XT],[...YT,...XT],[...XT],new RegExp(qT);var ZT={enabled:!0,maxRetries:3,baseDelayMs:2e3,maxAgentDelayMs:6e4},QT=3e5,$T=1e3;function eE(e,t){return mT(e,t)}var tE=(e,t,n)=>({_tag:`MuleError`,phase:e,message:t,cause:n}),nE=(e,t)=>({kind:e,value:`mule_${e}_${_h()}`,parent:t}),rE=()=>_;function iE(e,t){let n={role:`toolResult`,toolCallId:e.id,toolName:e.name,content:t.content,isError:t.isError,timestamp:Date.now()};return t.usage!==void 0&&(n.usage=t.usage),n}var aE=(e,t)=>({content:[{type:`text`,text:e}],isError:!0,terminate:t});function oE(e,t){return e.find(e=>e.descriptor.name===t.name)}function sE(e,t,n,r){return r({type:`tool_execution_end`,run:t,turn:n,toolCall:e.identity,call:e.call,result:e.result})}function cE(e,t,n,r,i){let a=nE(`tool_call`,r);return x(function*(){if(yield*i({type:`tool_execution_start`,replay:e?.replay??`unsafe`,run:n,turn:r,toolCall:a,call:t}),e===void 0){let e=aE(`Tool "${t.name}" not found`),o={call:t,identity:a,result:e};return yield*sE(o,n,r,i),{kind:`finalized`,value:o}}let o=yield*hn(e.prepare(t));if(xt(o)){let e=aE(o.failure.message,o.failure.terminate),s={call:t,identity:a,result:e};return yield*sE(s,n,r,i),{kind:`finalized`,value:s}}return{kind:`prepared`,call:t,identity:a,tool:o.success}})}function lE(e,t,n,r){return x(function*(){let i,a;yield*sv(J_(e.tool.execute()),o=>xt(o)?(a=o.failure,_):i===void 0?o.success.type===`result`?(i=o.success.result,_):r({type:`tool_execution_update`,run:t,turn:n,toolCall:e.identity,call:e.call,result:o.success.result}):_);let o=a===void 0?i??aE(`Tool "${e.call.name}" returned no result`):aE(a.message),s={call:e.call,identity:e.identity,result:o};return yield*sE(s,t,n,r),s})}function uE(e,t,n,r){let i=iE(e.call,e.result),a=nE(`tool_result`,e.identity);return x(function*(){return yield*r({type:`message_start`,run:t,turn:n,message:a,value:i}),yield*r({type:`message_end`,run:t,turn:n,message:a,value:i,data:e.result.data}),i})}function dE(e,t,n,r,i){let a=t.tools??[],o=t.toolExecution===`sequential`||e.some(e=>oE(a,e)?.executionMode===`sequential`);return x(function*(){let t=e=>e.kind===`finalized`?v(e.value):lE(e,n,r,i),s=o?yield*Hr(e,e=>w(cE(oE(a,e),e,n,r,i),t)):yield*x(function*(){let o=yield*Hr(e,e=>cE(oE(a,e),e,n,r,i));return yield*kn(o.map(t),{concurrency:`unbounded`})});return{messages:yield*Hr(s,e=>uE(e,n,r,i)),terminate:s.length>0&&s.every(e=>e.result.terminate===!0)}})}var fE=e=>aE(`Tool call "${e.name}" was not executed: the response hit the output token limit, so its arguments may be truncated. Re-issue the tool call with complete arguments.`);function pE(e,t,n,r){return x(function*(){let i=yield*Hr(e,e=>x(function*(){let i=nE(`tool_call`,n),a={call:e,identity:i,result:fE(e)};return yield*r({type:`tool_execution_start`,replay:`unsafe`,run:t,turn:n,toolCall:i,call:e}),yield*sE(a,t,n,r),a}));return yield*Hr(i,e=>uE(e,t,n,r))})}function mE(e,t){return Vr({try:n=>{let r=()=>{t.abort(n.reason)};return n.aborted?r():n.addEventListener(`abort`,r,{once:!0}),Promise.resolve(e.next()).finally(()=>{n.removeEventListener(`abort`,r)})},catch:e=>tE(`model`,`Pi model stream failed`,e)})}function hE(e,t){return t===void 0?e:e.pipe(Wt({duration:t,orElse:()=>y(tE(`model`,`Model stream was idle for ${String(t)} ms; the provider connection stopped responding. Retry the run.`))}))}function gE(e,t,n,r,i,a){let o=nE(`message`,r);return on(x(function*(){let s=new AbortController;yield*vr(()=>C(()=>{s.abort(`Mule model scope closed`)}));let c=(e.resolveApiKey===void 0?void 0:yield*e.resolveApiKey(e.model.provider))??e.streamOptions?.apiKey,l={...e.streamOptions,maxRetries:0,signal:s.signal};c!==void 0&&(l.apiKey=c);let u=e.prepareSystemPrompt===void 0?e.systemPrompt:yield*e.prepareSystemPrompt();e.prepareSystemPrompt!==void 0&&(yield*i({type:`model_prompt`,run:n,turn:r,attempt:a,systemPrompt:u}));let d={systemPrompt:u,messages:t},f=(e.tools??[]).map(e=>e.descriptor);f.length>0&&(d.tools=f);let p=yield*hE(Vr({try:async()=>(e.stream??lT)(e.model,ni(d),l),catch:e=>tE(`model`,`Pi model stream could not start`,e)}),e.modelStreamIdleTimeoutMs),m={started:!1,terminal:void 0},ee=yield*Dr(C(()=>p[Symbol.asyncIterator]()),e=>Vr({try:()=>(s.abort(`Mule model stream closed`),new Promise(t=>{let n=setTimeout(t,$T);Promise.resolve(e.return?.()).then(()=>{clearTimeout(n),t()},()=>{clearTimeout(n),t()})})),catch:e=>tE(`model`,`Pi model stream failed`,e)}).pipe(Re)),te=e=>{switch(e.type){case`start`:return t.push(e.partial),m.started=!0,i({type:`message_start`,run:n,turn:r,message:o,value:e.partial});case`text_start`:case`text_delta`:case`text_end`:case`thinking_start`:case`thinking_delta`:case`thinking_end`:case`toolcall_start`:case`toolcall_delta`:case`toolcall_end`:return m.started&&(t[t.length-1]=e.partial),i({type:`message_update`,run:n,turn:r,message:o,value:e.partial,event:e});case`done`:return m.terminal=e.message,_;case`error`:return m.terminal=e.error,_}},ne=()=>hE(mE(ee,s),e.modelStreamIdleTimeoutMs),h=yield*ne();for(;!h.done;)yield*te(h.value),h=yield*ne();let re=m.terminal??(yield*hE(Vr({try:()=>p.result(),catch:e=>tE(`model`,`Pi model stream did not settle`,e)}),e.modelStreamIdleTimeoutMs));return m.started?t[t.length-1]=re:(t.push(re),yield*i({type:`message_start`,run:n,turn:r,message:o,value:re})),yield*i({type:`message_end`,run:n,turn:r,message:o,value:re}),{identity:o,message:re}}))}function _E(e,t,n,r,i){return x(function*(){let a=e.retry===void 0?void 0:{...e.retry};if(a?.enabled&&[a.maxRetries,a.baseDelayMs,a.maxAgentDelayMs??6e4].some(e=>!Number.isSafeInteger(e)||e<0))return yield*y(tE(`model`,`Retry policy requires non-negative safe-integer counts and delays`));let o,s=0,c=0,l=!1,u,d=t=>e.onRetry===void 0?_:e.onRetry(t),f=(e,t)=>x(function*(){l=!0,yield*d(t===void 0?{type:`retry_finished`,run:n,turn:r,attempt:c,success:e}:{type:`retry_finished`,run:n,turn:r,attempt:c,success:e,finalError:t})});return yield*x(function*(){for(;;){if(o!==void 0){let e=t.indexOf(o.message);e!==-1&&t.splice(e,1)}o=yield*gE(e,t,n,r,i,++s);let l=o.message;if(l.stopReason!==`error`||a===void 0||!a.enabled||c>=a.maxRetries)return c>0&&(yield*f(l.stopReason!==`error`&&l.stopReason!==`aborted`,l.stopReason===`error`?l.errorMessage:void 0)),o;if(!(yield*Qr({try:()=>e.retryable(l),catch:e=>tE(`model`,`Typed model retry decision failed`,e)})))return c>0&&(yield*f(!1,l.errorMessage)),o;c++,u=l.errorMessage??`Unknown error`;let p=yield*Qr({try:()=>e.retryAfterMs?.(l),catch:e=>tE(`model`,`Model retry delay observation failed`,e)}),m=Math.max(bT(a,c),p!==void 0&&Number.isSafeInteger(p)&&p>=0&&p<=6e4?p:0);yield*d({type:`retry_scheduled`,run:n,turn:r,attempt:c,maxAttempts:a.maxRetries,delayMs:m,errorMessage:u}),yield*Ir(m),yield*d({type:`retry_attempt_started`,run:n,turn:r,attempt:c})}}).pipe(Te(()=>c===0||l?_:f(!1,u)))})}var vE=e=>e.stopReason===`aborted`?`cancelled`:e.stopReason===`error`?`failed`:`completed`;function yE(e,t,n,r,i,a){return Hr(e,e=>x(function*(){let o=nE(`message`,i);t.push(e),n.push(e),yield*a({type:`message_start`,run:r,turn:i,message:o,value:e}),yield*a({type:`message_end`,run:r,turn:i,message:o,value:e})})).pipe(en)}function bE(e,t,n,r,i,a,o){return x(function*(){yield*o({type:`turn_start`,run:r,turn:i}),yield*yE(a,t,n,r,i,o);let s=yield*_E(e,t,r,i,o),c=vE(s.message)!==`completed`,l=s.message.content.filter(e=>e.type===`toolCall`),u=l.length===0||c?{messages:[],terminate:!1}:s.message.stopReason===`length`?{messages:yield*pE(l,r,i,o),terminate:!1}:yield*dE(l,e,r,i,o);return t.push(...u.messages),n.push(s.message,...u.messages),yield*o({type:`turn_end`,run:r,turn:i,message:s.message,toolResults:u.messages}),{message:s.message,toolResults:u.messages,terminate:u.terminate}})}function xE(e,t,n,r,i,a){let o=nE(`turn`,i);return x(function*(){if(vE(t.message)!==`completed`)return{message:t.message,toolResults:[],terminate:!0};let s=yield*Hr(t.tools,n=>x(function*(){if(n.state===`completed`&&n.message!==void 0)return{message:n.message,terminate:n.result.terminate===!0,recorded:!0};let r=oE(e.tools??[],n.call),s;if(t.message.stopReason!==`length`&&(n.state===`pending`||n.state===`started`&&n.replay===`safe`&&r?.replay===`safe`)){let e=yield*cE(r,n.call,i,o,a);s=e.kind===`finalized`?e.value:yield*lE(e,i,o,a)}else s={call:n.call,identity:nE(`tool_call`,o),result:n.state===`completed`?n.result:n.state===`pending`&&t.message.stopReason===`length`?fE(n.call):aE(`Interrupted by a restart; it may or may not have completed; check before retrying.`)},yield*a({type:`tool_execution_start`,replay:`unsafe`,run:i,turn:o,toolCall:s.identity,call:s.call}),yield*sE(s,i,o,a);return{message:yield*uE(s,i,o,a),terminate:s.result.terminate===!0,recorded:!1}})),c=s.filter(({recorded:e})=>!e).map(({message:e})=>e);return n.push(...c),r.push(...c),{message:t.message,toolResults:s.map(({message:e})=>e),terminate:s.length>0&&s.every(({terminate:e})=>e)}})}function SE(e,t,n,r){return x(function*(){if(e.shouldStopAfterTurn!==void 0&&(yield*e.shouldStopAfterTurn({message:t.message,toolResults:t.toolResults,context:n,newMessages:r})))return{continue:!1,pending:[]};let i=e.getSteeringMessages===void 0?[]:[...yield*e.getSteeringMessages()];if(t.message.content.some(e=>e.type===`toolCall`)&&!t.terminate||i.length>0)return{continue:!0,pending:i};let a=e.getFollowUpMessages===void 0?[]:[...yield*e.getFollowUpMessages()];return{continue:a.length>0,pending:a}})}function CE(e,t,n,r,i,a){return x(function*(){return yield*a({type:`run_end`,run:e,terminal:t,outcome:i}),{status:i,run:e,terminal:t,message:n,messages:r}})}function wE(e,t=rE){return x(function*(){let n=yield*Pg(1),r={started:!1,ended:!1},i=e=>bn(()=>(e.type===`run_end`&&(r.ended=!0),n.withPermits(1)(t(e)))).pipe(Qn(()=>C(()=>{e.type===`run_start`&&(r.started=!0)}))),a=nE(`run`),o=nE(`terminal`,a);return yield*EE(e,i,a,o).pipe(ke(e=>{let t=TE(e);return!r.started||r.ended||t===void 0?_:i({type:`run_end`,run:a,terminal:o,outcome:t}).pipe(Re)}))})}function TE(e){if(qi(e))return;if(Ni(e.cause))return`cancelled`;let t=Li(e.cause);if(!(mn(t)&&t.value.phase===`listener`))return`failed`}function EE(e,t,n,r){return x(function*(){let i=[...e.messages],a=[],o=e.getSteeringMessages===void 0?[]:[...yield*e.getSteeringMessages()],s,c;if(yield*t({type:`run_start`,run:n}),e.resume!==void 0){let s=yield*xE(e,e.resume,i,a,n,t),c=vE(s.message),l=c===`completed`?yield*SE(e,s,i,a):{continue:!1,pending:[]};if(!l.continue&&o.length===0)return yield*CE(n,r,s.message,a,c,t);o.push(...l.pending)}do{let l=yield*bE(e,i,a,n,nE(`turn`,n),o,t);s=l.message;let u=vE(l.message);if(u!==`completed`)return yield*CE(n,r,l.message,a,u,t);if(e.prepareNextTurn!==void 0&&!l.terminate&&l.message.content.some(e=>e.type===`toolCall`)){let t=yield*e.prepareNextTurn({message:l.message,toolResults:l.toolResults,context:i,newMessages:a});t!==void 0&&i.splice(0,i.length,...t)}let d=yield*SE(e,l,i,a);o=[...d.pending],c=d.continue}while(c);return yield*CE(n,r,s,a,`completed`,t)})}var DE={run:wE},OE=class{#e=new Map;#t;constructor(e=8){this.#t=e}push(e,t){let n=this.#e.get(e)??[];if(n.length>=this.#t)throw new ex({namespace:`execute`,operation:`images`,cause:{kind:`Unavailable`,message:`Image collector cap reached for this execution (max ${String(this.#t)} images). Process images one at a time or write them to files.`}});let r=`img_${String(n.length)}`;return n.push(Object.freeze({...t})),this.#e.set(e,n),r}drain(e){let t=this.#e.get(e);return t===void 0?[]:(this.#e.delete(e),t)}dispose(e){this.#e.delete(e)}},kE=8192,AE=new TextEncoder,jE=()=>new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!1}),ME=class e{wake;#e={stdout:{decoder:jE(),pendingBytes:0},stderr:{decoder:jE(),pendingBytes:0}};#t=jE();#n=Array.from({length:kE},()=>void 0);#r=0;#i=0;#a=0;#o=0;#s=0;#c=0;#l=!1;#u=!1;constructor(e){this.wake=e}static make(){return Jh({capacity:1,strategy:`dropping`}).pipe(xe(t=>new e(t)))}write(e,t){if(this.#u||t.length===0)return;let n=this.#e[e];this.#c+=t.length;for(let e=0;e<t.length;e++){let r=t.subarray(e,e+1);n.pendingBytes++;let i=n.decoder.decode(r,{stream:!0});if(i.length===0)continue;let a=+(n.pendingBytes>1&&this.#t.decode(r,{stream:!0}).length===0);this.#t.decode(),this.#f(i,n.pendingBytes-a),n.pendingBytes=a}this.#l=!0,Zh(this.wake,void 0)}#d(){let e=this.#n[this.#r];if(e===void 0)throw Error(`Missing output ring entry`);this.#n[this.#r]=void 0,this.#r=(this.#r+1)%kE,this.#i--,this.#a-=e.textBytes,this.#o-=e.newlines,this.#s+=e.rawBytes}#f(e,t){if(e.length===0)return;let n={text:e,rawBytes:t,textBytes:AE.encode(e).length,newlines:e.split(`
|
|
18
|
-
`).length-1};for(this.#i===kE&&this.#d(),this.#n[(this.#r+this.#i)%kE]=n,this.#i++,this.#a+=n.textBytes,this.#o+=n.newlines;this.#a>kE||this.#o>=200;)this.#d()}snapshot(){let e=``;for(let t=0;t<this.#i;t++){let n=this.#n[(this.#r+t)%kE];if(n===void 0)throw Error(`Missing output ring entry`);e+=n.text}return{tail:e,droppedBytes:this.#s,totalBytes:this.#c}}#p(){if(!this.#l)return;this.#l=!1;let{tail:e,...t}=this.snapshot();return{type:`update`,result:{isError:!1,content:[{type:`text`,text:e}],data:t}}}finish(){if(!this.#u){this.#u=!0;for(let e of[this.#e.stdout,this.#e.stderr]){let t=e.decoder.decode();this.#f(t,e.pendingBytes),e.pendingBytes=0,t.length>0&&(this.#l=!0)}return this.#p()}}get updates(){return U_(this.wake).pipe(q_(()=>Ir(`100 millis`).pipe(xe(()=>this.#u?void 0:this.#p()))),ev(e=>e!==void 0))}dispose(){this.#u=!0,this.#n.fill(void 0),this.#r=this.#i=this.#a=this.#o=0,this.#c=this.#s=0,this.#l=!1;for(let e of[this.#e.stdout,this.#e.stderr])e.decoder.decode(),e.pendingBytes=0}},NE=N({code:j}),PE='Run async JavaScript in the sandbox. Each call is a fresh sandbox, not a REPL: nothing survives between calls, so redefine helpers or persist state to a file. Never shadow injected module names with local bindings. Find operations with await forage.search({ query }) using one short keyword such as read or shell, or page them all with forage.list({limit:50}), optionally by namespace, until nextCursor is null. Inspect input with await forage.describe({ path }) before calling; describe known paths directly. Call an operation as await env.<path>({ ... }) with the exact dotted path, for example await env.computers.local.exec({ command: "pwd" }); a bare computers.local.exec is not defined. Put multiline shell commands in a template literal. Code is JavaScript first, so double each backslash the shell needs (`\\\\(` passes `\\(`; `\\(` becomes `(`). For file edits, prefer Files operations when available. Explicitly return the final value. Before treating a shell or process result as success, check status, exitCode and stderr.';function FE(e,t,n,r){let i={module:e.grantKey,operation:e.name,access:e.operation.access,confirm:e.operation.confirm};return async a=>await QC(n,{sessionId:r},i,a,t.signal)??await e.operation.invoke(a,t)}function IE(e,t,n,r){let i=0,a=new Map;for(let o of e){let e=o.namespace,s=o.name,c=a.get(e)??new Map;c.set(s,e=>FE(o,Object.freeze({...t,operationOrdinal:i++}),n,r)(e)),a.set(e,c)}return Object.freeze(Object.fromEntries([...a].map(([e,t])=>[e,Object.freeze(Object.fromEntries(t))])))}function LE(e,t){let n=e.safeParse(t);if(!n.success)throw new Hb(n.error.issues);return n.data}function RE(e){return Object.freeze({list:t=>Promise.resolve().then(()=>e.list(LE(_y,t))),describe:t=>Promise.resolve().then(()=>e.describe(LE(gy,t))),search:t=>Promise.resolve().then(()=>e.search(LE(hy,t)))})}function zE(e,t,n,r,i){return Object.freeze({...IE(e,n,r,i),forage:RE(t)})}function BE(e,t,n,r,i,a,o,s){let c=n.execution??Gw(void 0),l=new OE,u=(u,d,f,p,m)=>tT({executionId:u,toolCallId:p,output:m,images:Object.freeze({push:e=>l.push(u,e)}),code:d,callerSignal:f,policy:c,sandbox:n,backingWork:r,createBindings:n=>zE(e,t,Object.freeze({...n,toolCallCode:d}),s,o),modules:i,namespacePaths:a,sessionId:o}),d=(e,t)=>bn(()=>{let n=_h();return u(n,e,t).pipe(Jn(C(()=>{l.dispose(n)})))}),f=(e,t,n)=>bn(()=>{let r=_h(),i=()=>l.drain(r);return u(r,e,void 0,t,n).pipe(gt({onSuccess:e=>v(VE({text:e.text,isError:!1},i())),onFailure:e=>{let t=i();return e instanceof Qb&&t.length>0?v(VE({text:rx(e),isError:!0},t)):y(HE(e))}}),Jn(C(()=>{l.dispose(r)})))}),p={replay:`unsafe`,descriptor:{name:`execute`,description:PE,parameters:VT({code:KT()},{additionalProperties:!1})},prepare:e=>ip(NE)(e.arguments).pipe(xe(({code:t})=>({execute:()=>G_(x(function*(){let n=yield*ME.make();yield*vr(()=>C(()=>{n.dispose()}));let r=yield*Ln(f(t,e.id,{write:(e,t)=>{n.write(e,t)}}),{startImmediately:!0});return $_(n.updates,M_(Tg(r)).pipe(Y_(e=>{let t=n.finish();return X_(V_(t===void 0?[]:[t]),M_(e))})),{haltStrategy:`right`}).pipe(iv(e=>e.type===`result`))}))})),it(()=>({message:`Invalid execute arguments`})))};return Object.freeze({effectTool:p,execute:d})}function VE(e,t){let n=t.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType})),r=[{type:`text`,text:e.text},...n];return t.length===0?{type:`result`,result:{content:r,isError:e.isError}}:{type:`result`,result:{content:r,data:{images:t.map(e=>({bytes:e.bytes,mimeType:e.mimeType,path:e.path}))},isError:e.isError}}}function HE(e){let t={_tag:`MuleError`,phase:`tool`,message:ox(e)?rx(e):e.message};return e instanceof qb?{...t,cause:e}:t}function UE(e,t){return e<t?-1:+(e>t)}var WE=128,GE=b(()=>S().min(1).max(160)),KE=b(()=>Un({version:S().min(1).max(160),modules:kt(Rr())})),qE=1e3;function JE(e){if(e.length>WE)throw new U(`Capability source count exceeds bound`);let t=[...e].sort((e,t)=>UE(e.id,t.id)),n=new Set;for(let e of t){if(!GE.safeParse(e.id).success)throw new U(`Capability source id must be non-empty and bounded`);if(n.has(e.id))throw new U(`Duplicate capability source id: ${e.id}`);n.add(e.id)}return t}function YE(e){if(e>qE)throw new U(`Candidate module count exceeds bound`)}function XE(e,t){let n=KE.safeParse(e);if(!n.success)throw new U(`Capability source snapshot must have a non-empty bounded version`);YE(t+n.data.modules.length)}function ZE(e,t,n,r,i){return Jr(a=>x(function*(){let o=t=>Vr({try:()=>t.release(),catch:()=>new Vb(e.id,`release`)}).pipe(sn(e=>C(()=>{n.push(e)}))),s=yield*Qr({try:()=>{let t=new AbortController;return{controller:t,outcome:e.acquire(i===void 0?{signal:t.signal,invalidate:r}:{signal:t.signal,invalidate:r,session:i}).then(e=>Hi(e),()=>Wi(new Vb(e.id,`acquire`)))}},catch:()=>new Vb(e.id,`acquire`)});yield*da(t,Ot(()=>s.outcome).pipe(w(e=>qi(e)?o(e.value):_)));let c=yield*a(Ot(()=>s.outcome)).pipe(Te(()=>C(()=>{s.controller.abort()})));return Ji(c)?yield*Rt(c.cause):c.value}))}function QE(e){return x(function*(){let t=yield*Qr({try:()=>JE(e.sources),catch:e=>e instanceof U?e:new U(`Capability sources are invalid`)});yield*Qr({try:()=>{YE(e.modules.length)},catch:e=>e instanceof U?e:new U(`Static capability modules are invalid`)});let n=yield*sa(),r=[],i=!1,a=[...e.modules],o=[];return yield*x(function*(){for(let s of t){let t=yield*ZE(s,n,r,()=>{i=!0},e.session);yield*Qr({try:()=>{XE(t.snapshot,a.length)},catch:e=>e instanceof U?e:new U(`Capability source snapshot is invalid`)}),a.push(...t.snapshot.modules),o.push({id:s.id,version:t.snapshot.version})}let s=e.precompiled??(yield*Qr({try:()=>Fw(a,o),catch:e=>e instanceof U?e:new U(`Capability compilation failed`)})),c=e.backingWork.createGroup(),l=BE(s.operations,s.catalog,e.sandbox,c,s.moduleAliases,s.namespacePaths,e.session?.sessionId??null,e.access),u=!1;return Object.freeze({compiled:s,executeDoor:l,isStale:()=>i,close:()=>x(function*(){u||(u=!0,yield*c.awaitIdle,yield*ma(n,Ki));let e=r[0];e!==void 0&&(yield*y(e))})})}).pipe(ke(e=>qi(e)?_:ma(n,e)))})}var $E=2;function eD(e){return x(function*(){for(let t=0;t<$E;t+=1){let t=yield*QE(e);if(!t.isStale())return t;yield*t.close()}return yield*y(new Vb(void 0,`stale`))})}function tD(e,t,n){return Jr(r=>r(e.take(1)).pipe(w(()=>C(t).pipe(Jn(e.release(1)))),w(n)))}function nD(e,t){return $t(e.candidate.close().pipe(gt({onFailure:t=>ra(e.settled,t).pipe(Gt(y(t))),onSuccess:()=>ia(e.settled,void 0).pipe(Gt(C(()=>{t.delete(e)})))})))}function rD(e,t){return e.runCleanup?nD(e.installed,t):ta(e.installed.settled)}function iD(e,t){return kn(e.map(e=>rD(e,t).pipe(wn)),{concurrency:`unbounded`}).pipe(w(e=>{let t=e.find(Ji);return t===void 0?_:Rt(t.cause)}))}function aD(e){return x(function*(){let t=yield*Pg(1),n=yield*Qr({try:()=>Gw(e.execution),catch:e=>e instanceof U?e:new U(`Execution policy is invalid`)}),r=yield*Kw(n.capacity),i=Object.freeze({execute:e.sandbox.execute,adapter:e.sandbox.adapter,buildSha:e.sandbox.buildSha,onFailure:e.onSandboxFailure,execution:n}),a=yield*Qr({try:()=>Fw(e.modules),catch:e=>e instanceof U?e:new U(`Capability compilation failed`)}),o=yield*Qr({try:()=>Object.freeze(e.tools.map(t=>tw(t,e.access,{sessionId:e.session?.sessionId??null}))),catch:e=>e instanceof U?e:new U(`Direct tool labels are invalid`)}),s,c=new Set,l=!1;if(e.sources.length===0){let t={candidate:yield*eD({...e,sandbox:i,backingWork:r,precompiled:a}),settled:yield*ea(),leases:0,retired:!1,closing:!1};s=t,c.add(t)}let u=()=>tD(t,()=>(l=!0,[...c].map(e=>{e.retired=!0;let t=e.leases===0&&!e.closing;return t&&(e.closing=!0),{installed:e,runCleanup:t}})),e=>iD(e,c));return yield*vr(()=>u().pipe(Mt)),Object.freeze({acquire:()=>t.withPermits(1)(x(function*(){if(l)return yield*y(new Bb);if(s===void 0||s.candidate.isStale()){let t=yield*eD({...e,sandbox:i,backingWork:r}),n=s,a={candidate:t,settled:yield*ea(),leases:0,retired:!1,closing:!1};s=a,c.add(a),n!==void 0&&(n.retired=!0,n.leases===0&&!n.closing&&(n.closing=!0,yield*nD(n,c)))}let n=s;n.leases+=1;let a,u=()=>tD(t,()=>{if(a!==void 0)return a?{installed:n,runCleanup:!1}:void 0;if(--n.leases,a=n.retired&&n.leases===0&&!n.closing,a)return n.closing=!0,{installed:n,runCleanup:!0}},e=>e===void 0?_:rD(e,c));return yield*vr(()=>u().pipe(Mt)),Object.freeze({revision:n.candidate.compiled.revision,catalog:n.candidate.compiled.catalog,executeDoor:n.candidate.executeDoor,effectExecuteTool:n.candidate.executeDoor.effectTool,tools:o,release:u})})),close:u})})}function oD(e){return Object.freeze({adapter:e.adapter??`promise`,buildSha:e.buildSha,execute:(t,n)=>$t(Vr({try:()=>e.execute(t,n),catch:sx}))})}function sD(e){return aD({modules:e.modules??[],sources:e.sources??[],session:e.session,execution:e.execution,sandbox:e.sandbox,onSandboxFailure:e.onSandboxFailure,tools:e.tools??[],access:e.access??{}}).pipe(xe(e=>Object.freeze({acquire:()=>e.acquire().pipe(xe(e=>Object.freeze({revision:e.revision,catalog:e.catalog,executeTool:e.effectExecuteTool,tools:e.tools,release:e.release}))),close:e.close})))}async function cD(e,t){let n=await Sr(e,t);if(qi(n))return n.value;let r=Li(n.cause);if(mn(r))throw r.value;if(Ni(n.cause))throw t?.signal?.reason instanceof Error?t.signal.reason:new DOMException(`The operation was aborted`,`AbortError`);let i=Fi(n.cause);throw i instanceof Error?i:Error(`Effect failed without an Error cause`)}async function lD(e){let t=await cD(sa()),n=e.onSandboxFailure;try{let r=await cD(aD({modules:e.modules??[],sources:e.sources??[],session:e.session,execution:e.execution,sandbox:oD(e.sandbox),onSandboxFailure:n===void 0?void 0:e=>Ot(()=>n(e)),tools:e.tools??[],access:e.access??{}}).pipe(la(t))),i=async e=>{let t=await cD(sa());try{let n=await cD(r.acquire().pipe(la(t)),e?.signal===void 0?void 0:{signal:e.signal}),i;return Object.freeze({revision:n.revision,catalog:n.catalog,executeTool:n.effectExecuteTool,tools:n.tools,release:()=>(i??=cD(n.release().pipe(Jn(ma(t,Ki)))),i)})}catch(e){throw await cD(ma(t,Ki)),e}},a;return Object.freeze({acquire:i,close:()=>(a??=cD(r.close().pipe(Jn(ma(t,Ki)))),a)})}catch(e){throw await cD(ma(t,Ki)),e}}var uD=Ip(()=>P([Sp,wp,im,j,Np(jp(uD)),_p(Op(j,uD))])),dD=j.check(jm(1),V(256)),fD=j.check(jm(1),V(128)),pD=N({kind:A(`sandbox_failure`),ref:dD,executionId:dD,adapter:fD,buildSha:I(fD),tag:F([`SourceInvalid`,`GuestThrew`,`DeadlineExceeded`,`SandboxBusy`,`Cancelled`,`DispatchLost`,`SandboxCrashed`,`BadResponse`,`ResultTooLarge`,`ResultNotJson`,`CapabilityFailed`,`Unknown`]),fields:Op(j,uD),healthAlert:wp});function mD(e){return dw(e)}function hD(e){return fw(e)}var gD=Object.freeze({module:hD,operation:mD,make:lD,gate:yw,grantAs:vw}),_D=oh,vD=4096,yD=new TextEncoder,bD=_D.check(R(e=>yD.encode(JSON.stringify(e)).byteLength<=vD)),xD=E(bD);function SD(e,t){if(gp(e))return ve(E(e)(t));let n=e[`~standard`].validate(t);if(ar(n,`then`))throw new H(`contract`,`invalid`,`Host metadata schema must validate synchronously`);return n.issues===void 0}function CD(e,t){let n=xD(t);if(xt(n))throw new H(`contract`,`invalid`,`Host metadata is not JSON within 4096 bytes`);if(e!==void 0&&!SD(e.schema,n.success))throw new H(`contract`,`invalid`,`Host metadata does not match the host's schema`);return n.success}function wD(e,t){return JSON.stringify(e)===JSON.stringify(t)}function TD(e,t){jr(Xe(`shiitake_operation_failed`,no(t)).pipe(rr({operation:e,errorKind:t instanceof Error?`error`:`non-error`})))}var ED=64,DD=256,OD=new WeakMap;function kD(e,t){return e===`closed`||t===`closed`?`closed`:e===`reset`||t===`reset`?`reset`:e===`durable`||t===`durable`?`durable`:`progress`}function AD(e,t){if(e.pendingCount>=DD){e.pendingCount=0,e.pendingReason=void 0,e.reset=!0;return}e.pendingCount+=1,e.pendingReason=e.pendingReason===`durable`||t===`durable`?`durable`:`progress`}function jD(e,t){if(e.closed||e.reset)return;let n=e.wake;if(n===void 0){AD(e,t);return}e.wake=void 0;try{n(t)}catch(t){TD(`observation-delivery`,t),e.pendingCount=0,e.pendingReason=void 0,e.reset=!0}}function MD(e,t,n=`durable`){let r=OD.get(e);if(r!==void 0)for(let e of r)try{e(t,n)}catch(e){TD(`owner-observation-publish`,e);continue}}function ND(e){let t=new Map,n=new Set,r=OD.get(e)??new Set,i=!1,a=e=>{if(e.closed)return`closed`;if(e.reset)return e.reset=!1,`reset`;if(e.pendingCount===0)return;e.pendingCount=0;let t=e.pendingReason;return e.pendingReason=void 0,t===`durable`?`durable`:`progress`},o=e=>{if(e.closed)return;e.closed=!0,e.pendingCount=0,e.pendingReason=void 0,e.reset=!1;let r=e.wake;e.wake=void 0,n.delete(e);let i=t.get(e.sessionId);if(i?.delete(e),i?.size===0&&t.delete(e.sessionId),r!==void 0)try{r(`closed`)}catch(e){TD(`observation-listener-close`,e)}},s=(e,r)=>{let i=e===null?n:t.get(e);if(i!==void 0)for(let e of i)jD(e,r)};return r.add(s),OD.set(e,r),Object.freeze({register:e=>bn(()=>{if(i)return y(new H(`runtime`,`closed`,`Shiitake is closed`));if(n.size>=ED)return y(new H(`runtime`,`rejected`,`Observation capacity is exhausted`));let r={sessionId:e,closed:!1,pendingCount:0,pendingReason:void 0,reset:!1,wake:void 0},s=t.get(e)??new Set;s.add(r),t.set(e,s),n.add(r);let c=C(()=>a(r)),l=Hn(e=>{let t=a(r);if(t!==void 0){e(v(t));return}let n=t=>{e(v(t))};return r.wake=n,C(()=>{r.wake===n&&(r.wake=void 0)})});return v(Object.freeze({pollSignal:c,awaitSignal:l,close:()=>{o(r)}}))}),close:C(()=>{if(!i){i=!0,r.delete(s),r.size===0&&OD.delete(e);for(let e of n)o(e)}})})}var PD=200,FD={onExcessProperty:`error`},ID=new TextEncoder,LD=B.pipe(L(z(0))),RD=j.pipe(L(jm(1)),L(R(e=>ID.encode(e).byteLength<=256)));E(N({limit:O(B.pipe(L(hm({minimum:1,maximum:PD})))),after:O(j)}),FD);var zD=Xm(Ap([LD,RD]));E(zD),hp(zD),E(N({session_id:RD,last_activity_at:LD,state:F([`needs_you`,`running`,`errored`,`done`]),bytes:B.pipe(L(z(0)))}),FD);var BD=cp(N({extension_id:j,value_json:j})),VD=cp(Xm(fv)),HD=cp(pv),UD=hp(Xm(fv));function WD(e){e.sql.exec(`CREATE TABLE IF NOT EXISTS session_attention_grants (
|
|
17
|
+
`;case 114:return`\r`;case 120:return String.fromCharCode(this.readHexChar(2));case 117:return Jx(this.readCodePoint());case 116:return` `;case 98:return`\b`;case 118:return`\v`;case 102:return`\f`;case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),``;case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,`Invalid escape sequence`),e){var n=this.pos-1;this.invalidStringToken(n,`Invalid escape sequence in template string`)}default:if(t>=48&&t<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],i=parseInt(r,8);return i>255&&(r=r.slice(0,-1),i=parseInt(r,8)),this.pos+=r.length-1,t=this.input.charCodeAt(this.pos),(r!==`0`||t===56||t===57)&&(this.strict||e)&&this.invalidStringToken(this.pos-1-r.length,e?`Octal literal in template string`:`Octal literal in strict mode`),String.fromCharCode(i)}return Lx(t)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),``):String.fromCharCode(t)}},X.readHexChar=function(e){var t=this.pos,n=this.readInt(16,e);return n===null&&this.invalidStringToken(t,`Bad character escape sequence`),n},X.readWord1=function(){this.containsEsc=!1;for(var e=``,t=!0,n=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(Ax(i,r))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,e+=this.input.slice(n,this.pos);var a=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,`Expecting Unicode escape sequence \\uXXXX`),++this.pos;var o=this.readCodePoint();(t?kx:Ax)(o,r)||this.invalidStringToken(a,`Invalid Unicode escape`),e+=Jx(o),n=this.pos}else break;t=!1}return e+this.input.slice(n,this.pos)},X.readWord=function(){var e=this.readWord1(),t=K.name;return this.keywords.test(e)&&(t=Px[e]),this.finishToken(t,e)},SS.acorn={Parser:SS,version:`8.18.0`,defaultOptions:$x,Position:Xx,SourceLocation:Zx,getLineInfo:Qx,Node:GS,TokenType:W,tokTypes:K,keywordTypes:Px,TokContext:IS,tokContexts:LS,isIdentifierChar:Ax,isIdentifierStart:kx,Token:IC,isNewLine:Lx,lineBreak:Fx,lineBreakG:Ix,nonASCIIwhitespace:zx};function BC(e,t){return SS.parse(e,t)}b(()=>Or(`ok`,[ur({ok:Kt(!0),value:Rr()}),ur({ok:Kt(!1),error:ur({kind:Kt(`guest_threw`),name:S().max(80),message:S().max(512),transportMessage:S().max(512).optional()})})]));var VC=b(()=>S().regex(/^[A-Za-z][A-Za-z0-9_]*$/u)),HC=VC.refine(e=>{if(e===`env`)return!1;try{return BC(`let ${e};`,{ecmaVersion:`latest`,sourceType:`module`}),!0}catch(e){if(!(e instanceof SyntaxError))throw e;return!1}},`Invalid sandbox transport alias`);b(()=>cn(HC,kt(VC).min(1))),b(()=>cn(HC,kt(S().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u))));var UC=F([`read`,`write`]),WC=wp,GC=N({access:k(UC),confirm:k(WC)}),KC=F([`none`,`read`,`write`]),qC=E(GC),JC=E(KC);function YC(e){let t=qC({access:e.access,confirm:e.confirm});if(xt(t))throw new U(`Access labels must be access: "read" | "write" and confirm: boolean`);return{access:t.success.access??`write`,confirm:t.success.confirm??!1}}function XC(e,t){let n=`${t.module}.${t.operation}`;switch(e){case`not-granted`:return`${n} is not granted to this Agent.`;case`read-only`:return`${n} changes something, and this Agent has read-only access to ${t.module}.`;case`confirmation-unavailable`:return`${n} needs a person's approval, and no one can be asked here.`;case`declined`:return`${n} was not approved.`}}function ZC(e,t){return Object.freeze({refused:!0,module:t.module,operation:t.operation,reason:e,message:XC(e,t)})}function QC(e,t,n){let r=e.sessionGrants?.(t),i=r!==void 0&&Object.hasOwn(r,n)?r:e.grants;if(i===void 0||!Object.hasOwn(i,n))return e.required?.includes(n)===!0?`none`:e.defaultGrant??`write`;let a=JC(i[n]);return ve(a)?a.success:`none`}async function $C(e,t,n,r,i){let a=await ew(e,t,n,r,i);return a!==void 0&&e.onRefused?.(a,t),a}async function ew(e,t,n,r,i){await e.beforeCall?.(i),i.throwIfAborted();let a=tw(e,t,n);if(a!==void 0)return a;if(!(!n.confirm&&(e.confirmWrites!==!0||n.access===`read`)))return e.confirm===void 0?ZC(`confirmation-unavailable`,n):await e.confirm({module:n.module,operation:n.operation,access:n.access,sessionId:t.sessionId,input:r},i)?(await e.beforeCall?.(i),i.throwIfAborted(),tw(e,t,n)):ZC(`declined`,n)}function tw(e,t,n){let r=QC(e,t,n.module);if(r===`none`)return ZC(`not-granted`,n);if(r===`read`&&n.access!==`read`)return ZC(`read-only`,n)}function nw(e,t,n){let r={module:e.module,operation:e.descriptor.name,...YC(e)};return{...e,prepare:i=>Vr({try:e=>$C(t,n,r,i.arguments,e),catch:()=>({message:`Access check failed`})}).pipe(w(t=>t===void 0?e.prepare(i):v({execute:()=>R_({type:`result`,result:{content:[{type:`text`,text:JSON.stringify(t)}],isError:!1}})})))}}var rw=Uo();async function iw(e){let t=await Sr(e);if(qi(t))return{value:t.value};let n=Ii(t.cause);if(xt(n))throw Fi(t.cause);return{issues:rw(n.success.issue).issues}}function aw(e){let t=ah(e),n=np(t)[`~standard`].jsonSchema,r=ip(t),i=up(t);return Object.freeze({description:{"~standard":{jsonSchema:{input:n.input,output:n.input}}},decode:e=>iw(r(e)),encode:e=>iw(i(e))})}function ow(e){let t=async t=>e[`~standard`].validate(t);return Object.freeze({description:e,decode:t,encode:t})}function sw(e){return gp(e)?aw(e):ow(e)}var cw=Symbol(`mycelium.operation`),lw=Symbol(`mycelium.module`),uw=new WeakMap,dw=new WeakMap;function fw(e){let t=Object.freeze({[cw]:!0}),n=sw(e.input),r=e.output===void 0?void 0:sw(e.output),i={replay:e.replay??`unsafe`,...YC(e),input:n.description,invoke:async(t,i)=>{let a=await n.decode(t);if(a.issues!==void 0)throw new Ub(a.issues);let o=await e.execute(a.value,i);if(r===void 0)return o;let s=await r.encode(o);if(s.issues!==void 0)throw new Qb({reason:`Capability output failed its declared schema`,rawCause:new Wb(s.issues)});return s.value}};e.description!==void 0&&(i.description=e.description),r!==void 0&&(i.output=r.description);let a=Object.freeze(i);return uw.set(t,a),t}function pw(e){let t=kt(VC).safeParse(e.namespace??[]);if(!t.success)throw new U(`Invalid module namespace`);let n=Object.freeze({[lw]:!0}),r={id:e.id,grantKey:e.id,name:e.name??e.id,namespace:Object.freeze(t.data),operations:Object.freeze({...e.operations})};e.description!==void 0&&(r.description=e.description);let i=Object.freeze(r);return dw.set(n,i),n}function mw(e){return dw.has(e)}function hw(e){return uw.get(e)}function gw(e){return dw.get(e)}function _w(e,t,n){let r=gw(e);if(r===void 0)throw new U(`Unknown module registration`);let i={};for(let[e,a]of Object.entries(r.operations)){let r=n===``?e:`${n}.${e}`;if(mw(a)){let n=gw(a);if(n===void 0)throw new U(`Unknown child module registration`);i[e]=_w(a,t,[r,...n.namespace].join(`.`));continue}let o=hw(a);if(o===void 0)throw new U(`Unknown operation registration: ${e}`);let s=Object.freeze({[cw]:!0});uw.set(s,Object.freeze({...o,invoke:async(e,n)=>{let i=await t({operation:r,context:n});return i.kind===`refuse`?i.value:await o.invoke(e,n)}})),i[e]=s}return vw(pw(r.description===void 0?{id:r.id,name:r.name,namespace:r.namespace,operations:i}:{id:r.id,name:r.name,namespace:r.namespace,description:r.description,operations:i}),r.grantKey)}function vw(e,t){let n=gw(e);if(n===void 0)throw new U(`Unknown module registration`);let r=Object.freeze({[lw]:!0});return dw.set(r,Object.freeze({...n,grantKey:t})),r}function yw(e,t){if(t.length===0||t.length>160)throw new U(`Grant key must be non-empty and bounded`);return vw(e,t)}function bw(e,t){return _w(e,t,``)}function xw(e,t){return e<t?-1:+(e>t)}function Sw(e){return e instanceof Error?e.message:`Capability declarations could not be compiled`}var Cw=160;function ww(e){if(e.length===0||e.length>Cw)throw new U(`Module id must be non-empty and bounded`)}function Tw(e){if(!e.split(`.`).every(e=>VC.safeParse(e).success))throw new U(`Operation key must be a path segment or a dotted relative path`)}function Ew(e){let t=e.replace(/[^A-Za-z0-9_]/g,`_`);return/^[A-Za-z]/.test(t)?t:`module_${t}`}function Dw(e){let t=Ew(e);return HC.safeParse(t).success?t:`module_${t}`}function Ow(e,t){let n=new Set([`forage`,`env`]),r=new Map;for(let i of e){let e=t===`logical`?i.namespace:[],a=t===`logical`?Ew(i.name):Dw(i.name),o=t=>[...e,t].join(`.`),s=a,c=2;for(;n.has(o(s));)s=`${a}_${String(c)}`,c+=1;n.add(o(s)),r.set(i.id,s)}return r}var kw=14695981039346656037n,Aw=1099511628211n,jw=18446744073709551615n;function Mw(e,t){let n=e,r=BigInt(t.length);for(let e=0;e<8;e+=1)n=(n^r&255n)*Aw&jw,r>>=8n;for(let e=0;e<t.length;e+=1){let r=t.charCodeAt(e);n=(n^BigInt(r&255))*Aw&jw,n=(n^BigInt(r>>>8&255))*Aw&jw}return n}function Nw(e,t,n){let r=Mw(kw,e),i=[...t.entries()].sort(([e],[t])=>xw(e,t));for(let[e,t]of i)r=Mw(r,e),r=Mw(r,t);let a=[...n].sort((e,t)=>xw(e.id,t.id));for(let e of a)r=Mw(r,e.id),r=Mw(r,e.version);return`installed-${r.toString(16).padStart(16,`0`)}`}function Pw(){return[Ib,Fb,Lb]}function Fw(e,t,n,r,i,a=[]){return Object.entries(t.operations).flatMap(([t,o])=>{if(Tw(t),mw(o)){let s=gw(o);if(s===void 0)throw new U(`Unknown child module registration`);return Fw(e,s,n,[...r,t,...s.namespace],s.description??i,[...a,t,...s.namespace])}let s=hw(o);if(s===void 0)throw new U(`Unknown operation registration: ${[...r,t].join(`.`)}`);return[Object.freeze({grantKey:e,path:[...r,t].join(`.`),namespace:n,name:[...a,t].join(`.`),moduleDescription:i,operation:s})]})}function Iw(e,t=[]){let n=e.map(e=>{let t=gw(e);if(t===void 0)throw new U(`Unknown module registration`);return ww(t.id),t}).sort((e,t)=>xw(e.id,t.id)),r=new Set;for(let e of n){if(r.has(e.id))throw new U(`Duplicate module id: ${e.id}`);r.add(e.id)}let i=Ow(n,`transport`),a=Ow(n,`logical`),o=Object.freeze(Object.fromEntries(n.map(e=>{let t=i.get(e.id);if(t===void 0)throw new U(`Missing module alias: ${e.id}`);let n=a.get(e.id);if(n===void 0)throw new U(`Missing logical alias: ${e.id}`);return[t,Object.freeze([...e.namespace,n])]}))),s=n.flatMap(e=>{let t=i.get(e.id);if(t===void 0)throw new U(`Missing module alias: ${e.id}`);let n=o[t];if(n===void 0)throw new U(`Missing namespace path: ${e.id}`);return Fw(e.grantKey,e,t,n,e.description)}).sort((e,t)=>xw(e.path,t.path)),c=new Set(s.map(e=>e.path));if(c.size!==s.length)throw new U(`Duplicate operation path`);for(let e of Pw()){if(c.has(e.path))throw new U(`Reserved intrinsic path: ${e.path}`);c.add(e.path)}for(let e of c){let t=e.split(`.`);for(let n=1;n<t.length;n+=1)if(c.has(t.slice(0,n).join(`.`)))throw new U(`Operation conflicts with namespace: ${e}`)}let l;try{l=Mb({revision:`prepared-content-stamp`,operations:[...s.map(({path:e,moduleDescription:t,operation:n})=>{let r={path:e,input:n.input};return n.description!==void 0&&(r.description=n.description),n.output!==void 0&&(r.output=n.output),t!==void 0&&(r.instructions=t),r}),...Pw()]})}catch(e){throw new U(Sw(e))}let u=Nw(l.stamp(),i,t),d=Object.freeze({revision:u,search:l.search,describe:l.describe,list:l.list,stamp:l.stamp}),f=Object.freeze(Object.fromEntries([...i.entries()].map(([e,t])=>[t,e])));return Object.freeze({revision:u,catalog:d,operations:Object.freeze(s),moduleAliases:f,namespacePaths:o})}function Lw(){return null}var Rw=yr(),zw=b(()=>zt([hr(),S(),t(),tn()])),Bw=b(()=>cn(S(),Rr())),Vw=b(()=>gx.extend({timeoutMs:tn().int().min(1).max(9e5).optional(),abortGraceMs:tn().int().min(1).max(3e4).optional()}).optional()),Hw=64,Uw=262144,Ww=new TextEncoder,Gw=e=>{e(v(void 0))};function Kw(e){let t=Vw.safeParse(e);if(!t.success)throw new U(`Execution policy is invalid`);return Object.freeze({timeoutMs:t.data?.timeoutMs??18e4,abortGraceMs:t.data?.abortGraceMs??5e3,..._x({sandboxCapacity:t.data?.sandboxCapacity,admissionWaitMs:t.data?.admissionWaitMs},(t.data?.sandboxCapacity,void 0))})}function qw(e){return x(function*(){let t=yield*Pg(e);return Object.freeze({createGroup:()=>{let e=0,n=new Set,r=Hn(t=>e===0?(t(v(void 0)),C(()=>void 0)):(n.add(t),C(()=>n.delete(t))));return Object.freeze({start:r=>Jr(i=>C(()=>{e+=1}).pipe(Gt(ne(i(t.withPermits(1)(r)).pipe(Jn(C(()=>{if(--e,e===0){let e=[...n];n.clear(),e.forEach(Gw)}}))))))),awaitIdle:r})}})})}function Jw(e,t=0){if(t>Hw)throw Error(`JSON value exceeds the nesting bound`);let n=zw.safeParse(e);if(n.success)return n.data;if(Array.isArray(e))return e.map(e=>Jw(e,t+1));let r=Bw.safeParse(e);if(!r.success)throw r.error;return Object.fromEntries(Object.entries(r.data).filter(([,e])=>e!==void 0).map(([e,n])=>[e,Jw(n,t+1)]))}function Yw(e){return Rw.parse(Jw(e))}function Xw(e){let t=JSON.stringify(Yw(e)),n=Ww.encode(t).byteLength;if(n>Uw)throw new $b({size:n});return Object.freeze({text:t})}function Zw(e,t){return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Object.freeze(Object.fromEntries(Object.entries(n).map(([n,r])=>[n,async i=>{t();try{return Yw(await r(i))}catch(t){throw sx(t)?t:t instanceof Oy?new tx({namespace:e,operation:n,cause:{kind:`Forage`,message:t.message},rawCause:t}):t instanceof Ub?new tx({namespace:e,operation:n,cause:{kind:`InvalidInput`,message:`Invalid operation input: ${Ht({issues:t.issues})}; use forage.describe`},rawCause:t}):t}}])))])))}function Qw(e){return Hn(t=>{let n=t.bind(void 0,_);return e.aborted?n():e.addEventListener(`abort`,n,{once:!0}),C(e.removeEventListener.bind(e,`abort`,n))})}function $w(e,t){if(e===void 0)return()=>void 0;let n=t.bind(void 0);return e.aborted?(n(),()=>void 0):(e.addEventListener(`abort`,n,{once:!0}),e.removeEventListener.bind(e,`abort`,n))}function eT(e,t,n){return e===`deadline_exceeded`?new qb({limitMs:t,elapsedMs:n??0}):new Yb({by:`caller`})}function tT(e){return ha.pipe(xe(t=>t-e))}function nT(t){return ha.pipe(w(n=>bn(()=>{let r=t.executionId,i=new AbortController,a=n,o={kind:`waiting`},s,c=e=>{s===void 0&&o.kind!==`refused`&&(s=e,i.abort())},l=e=>{let n=new Jb({capacity:t.policy.capacity,waitedMs:Math.max(0,e-a)});return o={kind:`refused`,failure:n},n},u=()=>{if(i.signal.aborted)throw eT(s,t.policy.timeoutMs)},d=$w(t.callerSignal,()=>{c(`cancelled`)}),f=n+t.policy.timeoutMs,p={executionId:r,deadlineAt:f,signal:i.signal,images:t.images};t.toolCallId!==void 0&&Object.assign(p,{toolCallId:t.toolCallId}),t.output!==void 0&&Object.assign(p,{output:t.output});let m=Object.freeze(p),ee=bn(()=>ha.pipe(w(e=>o.kind===`refused`?y(o.failure):(e>=f&&c(`deadline_exceeded`),i.signal.aborted?tT(n).pipe(w(e=>y(eT(s,t.policy.timeoutMs,e)))):e>=a+t.policy.waitMs?y(l(e)):(o={kind:`admitted`},t.sandbox.execute(Object.freeze({executionId:r,code:t.code,timeoutMs:t.policy.timeoutMs,bindings:Zw(t.createBindings(m),u),modules:t.modules,namespacePaths:t.namespacePaths,sessionId:t.sessionId}),i.signal).pipe(Mr(e=>Ni(e)?Rt(e):y(cx(Fi(e)))))))))),te=e=>Dg(e).pipe(Wt({duration:t.policy.abortGraceMs,orElse:()=>y(s===`deadline_exceeded`?new qb({limitMs:t.policy.timeoutMs,elapsedMs:t.policy.timeoutMs,acknowledged:!1}):new Yb({by:`caller`,acknowledged:!1}))})),ne,h=!1,re=e=>(h=!0,tT(n).pipe(w(n=>{let i=cx(e),a=i instanceof qb?new qb({limitMs:i.limitMs,elapsedMs:n,acknowledged:i.acknowledged}):i,o=rx(a,r),s=cn(S(),yr()).parse(ux(a));s.ref=r;let c={kind:`sandbox_failure`,ref:r,executionId:r,adapter:t.sandbox.adapter??`effect`,buildSha:t.sandbox.buildSha??Lw(),tag:o._tag,fields:s,healthAlert:o._tag===`Unknown`},l=bn(()=>t.sandbox.onFailure?.(c)??_);return Xe(`sandbox_failure`,c).pipe(rr({executionId:r,ref:r,adapter:c.adapter,tag:c.tag,buildSha:c.buildSha}),Gt(o._tag===`Unknown`?Ra(za(La(`sandbox_unknown`),{adapter:c.adapter}),1).pipe(Gt(Xe(`sandbox_health_alert`).pipe(rr({ref:r,adapter:c.adapter})))):_),Gt(l.pipe(Mr(e=>Xe(`sandbox_failure_record_failed`,e)))),Cr(o))})));return x(function*(){if(i.signal.aborted){let e=yield*tT(n);return yield*y(eT(s,t.policy.timeoutMs,e))}a=yield*ha,ne=yield*t.backingWork.start(ee);let r=yield*ha,u=Ir(Math.max(0,a+t.policy.waitMs-r)).pipe(Gt(ha),w(e=>o.kind===`admitted`?wt:o.kind===`refused`?v({kind:`busy`,failure:o.failure}):i.signal.aborted?v({kind:`cancelled`}):e>=f?(c(`deadline_exceeded`),v({kind:`deadline`})):v({kind:`busy`,failure:l(e)}))),d=yield*e(Tg(ne).pipe(xe(e=>Object.freeze({kind:`settled`,exit:e}))),e(Ir(Math.max(0,f-r)).pipe(Gt(C(()=>(c(`deadline_exceeded`),Object.freeze({kind:`deadline`}))))),e(Qw(i.signal).pipe(Cr(Object.freeze({kind:`cancelled`}))),u))),p=o.kind===`refused`?o.failure:d.kind===`busy`?d.failure:void 0;if(p!==void 0)return yield*te(ne).pipe(Gt(y(p)));if(d.kind===`settled`)return yield*ge(d.exit,{onFailure:e=>s===void 0?Rt(e):tT(n).pipe(w(e=>y(eT(s,t.policy.timeoutMs,e)))),onSuccess:e=>Qr({try:()=>Xw(e),catch:t=>sx(t)?t:new ex({kind:lx(e),rawCause:t})})});d.kind===`deadline`&&c(`deadline_exceeded`);let m=yield*tT(n);return yield*te(ne).pipe(Gt(y(eT(s,t.policy.timeoutMs,m))))}).pipe(Te(()=>(c(`cancelled`),(ne===void 0?_:Dg(ne).pipe(Cn(t.policy.abortGraceMs),en)).pipe(Gt(bn(()=>h?_:re(new Yb({by:`operator`})).pipe(en))))))).pipe(sn(e=>re(e).pipe(w(y))),Jn(C(d)))})))}var rT=Ip(()=>P([Cp,Sp,wp,M,j,th,Kp(AbortSignal),jp(rT),iT])),iT=Op(j,rT);function aT(e){return cp(iT)(e)}var oT=Op(j,oh),sT=cp(N({samplingParams:O(oT),samplingParamsByThinkingLevel:O(N({off:O(oT),minimal:O(oT),low:O(oT),medium:O(oT),high:O(oT),xhigh:O(oT),max:O(oT)}))}));function cT(e){return{...e,...sT(e)}}function lT(e){if(e===void 0)return;let{onPayload:t,onProviderStreamEvent:n,onResponse:r,...i}=e,a={...i};return t!==void 0&&(a.onPayload=(e,n)=>t(aT(e),cT(n))),n!==void 0&&(a.onProviderStreamEvent=(e,t)=>n(aT(e),cT(t))),r!==void 0&&(a.onResponse=(e,t)=>r(e,cT(t))),a}var uT=async(e,t,n)=>{let{streamSimple:r}=await ri(async()=>{let{streamSimple:e}=await import(`./compat-DgqxVOn_.js`);return{streamSimple:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));return r(e,ni(t),lT(n))},dT=N({error:N({code:j})});op(N({type:A(`response.failed`),response:dT})),op(Xm(dT)),cp(Kp(Uint8Array));var fT=[/prompt (?:is )?too long/i,/prompt exceeds max length/i,/request_too_large/i,/input is too long for requested model/i,/exceeds the context window/i,/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,/input token count.*exceeds the maximum/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/maximum context length is \d+ tokens/i,/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,/exceeds the limit of \d+/i,/exceeds the available context size/i,/greater than the context length/i,/context window exceeds limit/i,/exceeded model token limit/i,/too large for model with \d+ maximum context length/i,/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,/model_context_window_exceeded/i,/prompt too long; exceeded (?:max )?context length/i,/range of input length should be/i,/context[_ ]length[_ ]exceeded/i,/too many tokens/i,/token limit exceeded/i],pT=/^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i,mT=[/^(Throttling error|Service unavailable):/i,/rate limit/i,/too many requests/i];function hT(e,t){return!!(e.stopReason===`error`&&e.errorMessage&&!mT.some(t=>t.test(e.errorMessage))&&(fT.some(t=>t.test(e.errorMessage))||e.provider===`cerebras`&&pT.test(e.errorMessage))||t&&e.stopReason===`stop`&&e.usage.input+e.usage.cacheRead>t||t&&e.stopReason===`length`&&e.usage.output===0&&e.usage.input+e.usage.cacheRead>=t*.99)}function gT(e,t){return e.stopReason===`length`&&t>0&&e.usage.output<t}function _T(e){return new RegExp(e.join(`|`),`i`)}var vT=_T([`GoUsageLimitError`,`FreeUsageLimitError`,`Monthly usage limit reached`,`available balance`,`insufficient_quota`,`out of budget`,`quota exceeded`,`billing`,`subscription_sharing_usage_limit_exceeded`]),yT=_T(`overloaded,server_busy,servers are currently busy,currently experiencing high demand,model is at capacity,rate.?limit,too many requests,429,500,502,503,504,520,524,service.?(?:is.?)?(?:temporarily.?)?unavailable,server.?error,internal.?error,provider.?returned.?(?:an.?)?error,exceeded request buffer limit while retrying upstream,unable to forward upstream,network.?error,connection.?error,connection.?refused,connection.?lost,other side closed,fetch failed,getaddrinfo,ENOTFOUND,EAI_AGAIN,upstream.?connect,reset before headers,socket hang up,socket connection was closed,timed? out,timeout,terminated,websocket.?closed,websocket.?error,ended without,stream ended before message_stop,stream ended before a terminal response event,http2 request did not get a response,pending stream has been canceled,retry delay,you can retry your request,try your request again,please retry your request,ResourceExhausted,subscription_sharing_usage_unavailable,subscription_sharing_user_unavailable`.split(`,`)),bT=6e4;function xT(e,t){let n=e.baseDelayMs*2**Math.max(0,t-1);return Math.min(Number.isSafeInteger(n)?n:2**53-1,e.maxAgentDelayMs??6e4)}var ST=class extends Error{constructor(){super(`Aborted`)}};function CT(e,t){return new Promise((n,r)=>{if(t?.aborted){r(new ST);return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(new ST)},{once:!0})})}async function wT(e,t,n,r){let i=t?.enabled?t.maxRetries:0,a=0,o;for(;;){let s=await e();if(s.stopReason===`aborted`)return o&&await r?.onRetryFinished?.(!1,o.attempt),s;if(s.stopReason!==`error`)return o&&await r?.onRetryFinished?.(!0,o.attempt),s;if(a>=i||!TT(s))return o&&await r?.onRetryFinished?.(!1,o.attempt,s.errorMessage),s;a++,o={attempt:a,errorMessage:s.errorMessage||`Unknown error`};let c=xT(t,a);await r?.onRetryScheduled?.(a,i,c,o.errorMessage);try{await CT(c,n)}catch(e){if(await r?.onRetryFinished?.(!1,a,o.errorMessage),e instanceof ST){let{errorMessage:e,...t}=s;return{...t,stopReason:`aborted`}}throw e}await r?.onRetryAttemptStart?.()}}function TT(e){if(e.stopReason!==`error`||!e.errorMessage)return!1;let t=e.errorMessage;return!vT.test(t)&&yT.test(t)}var ET={assign:0,create:0,clone:0,discard:0,update:0};function DT(e){return kT(e,null)}function OT(e){return kT(typeof e,`object`)&&!DT(e)}function kT(e,t){return e===t}function AT(e){return kT(e,`__proto__`)||kT(e,`constructor`)||kT(e,`prototype`)}function jT(e,t){return AT(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function MT(e){return Object.getOwnPropertyNames(e)}var NT={immutableTypes:!1,maxErrors:8,maxInstantiationCount:128,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function PT(){return NT}function FT(e){return PT().immutableTypes?Object.freeze(e):e}function IT(e,t){for(let n of Object.keys(t))Object.defineProperty(e,n,{configurable:!0,writable:!0,enumerable:!1,value:t[n]});return e}function LT(e,t){return{...e,...t}}function RT(e,t,n={}){ET.create+=1;let r=LT(t,n);return FT(PT().enumerableKind?LT(r,e):IT(r,e))}function zT(e){return OT(e)}function BT(e){return zT(e)&&jT(e,`~optional`)}function VT(e){return MT(e).filter(t=>!BT(e[t]))}function HT(e,t={}){let n=VT(e);return RT({"~kind":`Object`},{type:`object`,...n.length>0?{required:n}:{},properties:e},t)}var UT;(function(e){e[e.Array=0]=`Array`,e[e.BigInt=1]=`BigInt`,e[e.Boolean=2]=`Boolean`,e[e.Date=3]=`Date`,e[e.Constructor=4]=`Constructor`,e[e.Function=5]=`Function`,e[e.Null=6]=`Null`,e[e.Number=7]=`Number`,e[e.Object=8]=`Object`,e[e.RegExp=9]=`RegExp`,e[e.String=10]=`String`,e[e.Symbol=11]=`Symbol`,e[e.TypeArray=12]=`TypeArray`,e[e.Undefined=13]=`Undefined`})(UT||={}),Array.from({length:256}).map((e,t)=>BigInt(t));var WT=new Float64Array(1);new DataView(WT.buffer),new Uint8Array(WT.buffer),new TextEncoder;var GT=`-?(?:0|[1-9][0-9]*)`,KT=`-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?`;function qT(e){return RT({"~kind":`String`},{type:`string`},e)}var JT=`^${GT}$`;`${KT}`;function YT(e,t){return Array.from({length:t-e+1},(t,n)=>String.fromCharCode(e+n))}var XT=[...YT(97,122),...YT(65,90)],ZT=[`0`,...YT(49,57)];[...ZT],[...XT,...ZT],[...ZT],new RegExp(JT);var QT={enabled:!0,maxRetries:3,baseDelayMs:2e3,maxAgentDelayMs:6e4},$T={firstEventMs:6e4,idleMs:12e4,attemptMs:6e5,outputBytes:2097152},eE=1e3,tE=Symbol(`Mule model limit`);function nE(e,t){return hT(e,t)}var rE=(e,t,n)=>({_tag:`MuleError`,phase:e,message:t,cause:n}),iE=(e,t)=>({kind:e,value:`mule_${e}_${_h()}`,parent:t}),aE=()=>_;function oE(e,t){let n={role:`toolResult`,toolCallId:e.id,toolName:e.name,content:t.content,isError:t.isError,timestamp:Date.now()};return t.usage!==void 0&&(n.usage=t.usage),n}var sE=(e,t)=>({content:[{type:`text`,text:e}],isError:!0,terminate:t});function cE(e,t){return e.find(e=>e.descriptor.name===t.name)}function lE(e,t,n,r){return r({type:`tool_execution_end`,run:t,turn:n,toolCall:e.identity,call:e.call,result:e.result})}function uE(e,t,n,r,i){let a=iE(`tool_call`,r);return x(function*(){if(yield*i({type:`tool_execution_start`,replay:e?.replay??`unsafe`,run:n,turn:r,toolCall:a,call:t}),e===void 0){let e=sE(`Tool "${t.name}" not found`),o={call:t,identity:a,result:e};return yield*lE(o,n,r,i),{kind:`finalized`,value:o}}let o=yield*hn(e.prepare(t));if(xt(o)){let e=sE(o.failure.message,o.failure.terminate),s={call:t,identity:a,result:e};return yield*lE(s,n,r,i),{kind:`finalized`,value:s}}return{kind:`prepared`,call:t,identity:a,tool:o.success}})}function dE(e,t,n,r){return x(function*(){let i,a;yield*sv(J_(e.tool.execute()),o=>xt(o)?(a=o.failure,_):i===void 0?o.success.type===`result`?(i=o.success.result,_):r({type:`tool_execution_update`,run:t,turn:n,toolCall:e.identity,call:e.call,result:o.success.result}):_);let o=a===void 0?i??sE(`Tool "${e.call.name}" returned no result`):sE(a.message),s={call:e.call,identity:e.identity,result:o};return yield*lE(s,t,n,r),s})}function fE(e,t,n,r){let i=oE(e.call,e.result),a=iE(`tool_result`,e.identity);return x(function*(){return yield*r({type:`message_start`,run:t,turn:n,message:a,value:i}),yield*r({type:`message_end`,run:t,turn:n,message:a,value:i,data:e.result.data}),i})}function pE(e,t,n,r,i){let a=t.tools??[],o=t.toolExecution===`sequential`||e.some(e=>cE(a,e)?.executionMode===`sequential`);return x(function*(){let t=e=>e.kind===`finalized`?v(e.value):dE(e,n,r,i),s=o?yield*Hr(e,e=>w(uE(cE(a,e),e,n,r,i),t)):yield*x(function*(){let o=yield*Hr(e,e=>uE(cE(a,e),e,n,r,i));return yield*kn(o.map(t),{concurrency:`unbounded`})});return{messages:yield*Hr(s,e=>fE(e,n,r,i)),terminate:s.length>0&&s.every(e=>e.result.terminate===!0)}})}var mE=e=>sE(`Tool call "${e.name}" was not executed: the response hit the output token limit, so its arguments may be truncated. Re-issue the tool call with complete arguments.`);function hE(e,t,n,r){return x(function*(){let i=yield*Hr(e,e=>x(function*(){let i=iE(`tool_call`,n),a={call:e,identity:i,result:mE(e)};return yield*r({type:`tool_execution_start`,replay:`unsafe`,run:t,turn:n,toolCall:i,call:e}),yield*lE(a,t,n,r),a}));return yield*Hr(i,e=>fE(e,t,n,r))})}function gE(e,t){return Vr({try:n=>{let r=()=>{t.abort(n.reason)};return n.aborted?r():n.addEventListener(`abort`,r,{once:!0}),Promise.resolve(e.next()).finally(()=>{n.removeEventListener(`abort`,r)})},catch:e=>rE(`model`,`Pi model stream failed`,e)})}function _E(e,t,n){return e.pipe(Wt({duration:t,orElse:()=>y(rE(`model`,n(),tE))}))}function vE(e,t,n,r,i,a){let o=iE(`message`,r),s,c={started:!1,terminal:void 0};return on(x(function*(){let l=e.modelStreamLimits,u=Math.min(l?.firstEventMs??$T.firstEventMs,$T.firstEventMs),d=Math.min(l?.attemptMs??$T.attemptMs,$T.attemptMs),f=Math.min(l?.outputBytes??$T.outputBytes,$T.outputBytes);if([u,d,f,e.modelStreamIdleTimeoutMs??1].some(e=>!Number.isSafeInteger(e)||e<=0))return yield*y(rE(`model`,`Model stream limits must be positive safe integers`));let p=Date.now(),m=p,ee=0,te=0,ne=new TextEncoder,h=!1,re=e=>rE(`model`,`Model ${e} after ${String(Date.now()-p)} ms (max provider gap ${String(Math.max(ee,Date.now()-m))} ms, streamed ${String(te)} bytes)`,tE),ie=t=>{let n=Date.now()-p,r=d-n,i=Math.min(h?$T.idleMs:u,e.modelStreamIdleTimeoutMs??$T.idleMs)-(Date.now()-m),a=r<=i?`attempt timed out`:h?`stream timed out (silence)`:`first event timed out`;return _E(t,Math.max(0,Math.min(r,i)),()=>re(a).message)},ae=new AbortController;yield*vr(()=>C(()=>{ae.abort(`Mule model scope closed`)}));let oe=(e.resolveApiKey===void 0?void 0:yield*e.resolveApiKey(e.model.provider))??e.streamOptions?.apiKey,se={...e.streamOptions,maxRetries:0,signal:ae.signal};oe!==void 0&&(se.apiKey=oe);let ce=e.prepareSystemPrompt===void 0?e.systemPrompt:yield*e.prepareSystemPrompt();e.prepareSystemPrompt!==void 0&&(yield*i({type:`model_prompt`,run:n,turn:r,attempt:a,systemPrompt:ce}));let le={systemPrompt:ce,messages:t},ue=(e.tools??[]).map(e=>e.descriptor);ue.length>0&&(le.tools=ue);let de=yield*ie(Vr({try:async()=>(e.stream??uT)(e.model,ni(le),se),catch:e=>rE(`model`,`Pi model stream could not start`,e)})),fe=yield*Dr(C(()=>de[Symbol.asyncIterator]()),e=>Vr({try:()=>(ae.abort(`Mule model stream closed`),new Promise(t=>{let n=setTimeout(t,eE);Promise.resolve(e.return?.()).then(()=>{clearTimeout(n),t()},()=>{clearTimeout(n),t()})})),catch:e=>rE(`model`,`Pi model stream failed`,e)}).pipe(Re)),pe=e=>{let a=Date.now();if(ee=Math.max(ee,a-m),m=a,h=!0,(e.type===`text_delta`||e.type===`thinking_delta`||e.type===`toolcall_delta`)&&(te+=ne.encode(e.delta).byteLength,te>f))return y(re(`output limit exceeded`));switch(`partial`in e&&(s=e.partial),e.type){case`start`:return t.push(e.partial),c.started=!0,i({type:`message_start`,run:n,turn:r,message:o,value:e.partial});case`text_start`:case`text_delta`:case`text_end`:case`thinking_start`:case`thinking_delta`:case`thinking_end`:case`toolcall_start`:case`toolcall_delta`:case`toolcall_end`:return c.started&&(t[t.length-1]=e.partial),i({type:`message_update`,run:n,turn:r,message:o,value:e.partial,event:e});case`done`:return c.terminal=e.message,_;case`error`:return c.terminal=e.error,_}},me=()=>ie(gE(fe,ae)),g=yield*me();for(;!g.done;)yield*pe(g.value),g=yield*me();let he=c.terminal??(yield*ie(Vr({try:()=>de.result(),catch:e=>rE(`model`,`Pi model stream did not settle`,e)})));return c.started?t[t.length-1]=he:(t.push(he),yield*i({type:`message_start`,run:n,turn:r,message:o,value:he})),yield*i({type:`message_end`,run:n,turn:r,message:o,value:he}),{identity:o,message:he}}).pipe(sn(l=>{if(l.cause!==tE)return y(l);let u={role:`assistant`,content:s?.content??[],api:e.model.api,provider:e.model.provider,model:e.model.id,usage:s?.usage??{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,timestamp:Date.now(),errorMessage:e.retry?.enabled&&a>e.retry.maxRetries?`The model failed ${String(a)} times on this conversation: ${l.message}`:l.message};return x(function*(){return c.started?t[t.length-1]=u:(t.push(u),yield*i({type:`message_start`,run:n,turn:r,message:o,value:u})),yield*i({type:`message_end`,run:n,turn:r,message:o,value:u}),{identity:o,message:u,limitReached:!0}})})))}function yE(e,t,n,r,i){return x(function*(){let a=e.retry===void 0?void 0:{...e.retry};if(a?.enabled&&[a.maxRetries,a.baseDelayMs,a.maxAgentDelayMs??6e4].some(e=>!Number.isSafeInteger(e)||e<0))return yield*y(rE(`model`,`Retry policy requires non-negative safe-integer counts and delays`));let o,s=0,c=0,l=!1,u,d=t=>e.onRetry===void 0?_:e.onRetry(t),f=(e,t)=>x(function*(){l=!0,yield*d(t===void 0?{type:`retry_finished`,run:n,turn:r,attempt:c,success:e}:{type:`retry_finished`,run:n,turn:r,attempt:c,success:e,finalError:t})});return yield*x(function*(){for(;;){if(o!==void 0){let e=t.indexOf(o.message);e!==-1&&t.splice(e,1)}o=yield*vE(e,t,n,r,i,++s);let l=o.message;if(l.stopReason!==`error`||a===void 0||!a.enabled||c>=a.maxRetries)return c>0&&(yield*f(l.stopReason!==`error`&&l.stopReason!==`aborted`,l.stopReason===`error`?l.errorMessage:void 0)),o;if(!(yield*Qr({try:()=>o?.limitReached===!0||e.retryable(l),catch:e=>rE(`model`,`Typed model retry decision failed`,e)})))return c>0&&(yield*f(!1,l.errorMessage)),o;c++,u=l.errorMessage??`Unknown error`;let p=yield*Qr({try:()=>e.retryAfterMs?.(l),catch:e=>rE(`model`,`Model retry delay observation failed`,e)}),m=Math.max(xT(a,c),p!==void 0&&Number.isSafeInteger(p)&&p>=0&&p<=6e4?p:0);yield*d({type:`retry_scheduled`,run:n,turn:r,attempt:c,maxAttempts:a.maxRetries,delayMs:m,errorMessage:u}),yield*Ir(m),yield*d({type:`retry_attempt_started`,run:n,turn:r,attempt:c})}}).pipe(Te(()=>c===0||l?_:f(!1,u)))})}var bE=e=>e.stopReason===`aborted`?`cancelled`:e.stopReason===`error`?`failed`:`completed`;function xE(e,t,n,r,i,a){return Hr(e,e=>x(function*(){let o=iE(`message`,i);t.push(e),n.push(e),yield*a({type:`message_start`,run:r,turn:i,message:o,value:e}),yield*a({type:`message_end`,run:r,turn:i,message:o,value:e})})).pipe(en)}function SE(e,t,n,r,i,a,o){return x(function*(){yield*o({type:`turn_start`,run:r,turn:i}),yield*xE(a,t,n,r,i,o);let s=yield*yE(e,t,r,i,o),c=bE(s.message)!==`completed`,l=s.message.content.filter(e=>e.type===`toolCall`),u=l.length===0||c?{messages:[],terminate:!1}:s.message.stopReason===`length`?{messages:yield*hE(l,r,i,o),terminate:!1}:yield*pE(l,e,r,i,o);t.push(...u.messages),n.push(s.message,...u.messages),yield*o({type:`turn_end`,run:r,turn:i,message:s.message,toolResults:u.messages});let d={message:s.message,toolResults:u.messages,terminate:u.terminate};return s.limitReached&&s.message.errorMessage!==void 0?{...d,modelLimitReason:s.message.errorMessage}:d})}function CE(e,t,n,r,i,a){let o=iE(`turn`,i);return x(function*(){if(bE(t.message)!==`completed`)return{message:t.message,toolResults:[],terminate:!0};let s=yield*Hr(t.tools,n=>x(function*(){if(n.state===`completed`&&n.message!==void 0)return{message:n.message,terminate:n.result.terminate===!0,recorded:!0};let r=cE(e.tools??[],n.call),s;if(t.message.stopReason!==`length`&&(n.state===`pending`||n.state===`started`&&n.replay===`safe`&&r?.replay===`safe`)){let e=yield*uE(r,n.call,i,o,a);s=e.kind===`finalized`?e.value:yield*dE(e,i,o,a)}else s={call:n.call,identity:iE(`tool_call`,o),result:n.state===`completed`?n.result:n.state===`pending`&&t.message.stopReason===`length`?mE(n.call):sE(`Interrupted by a restart; it may or may not have completed; check before retrying.`)},yield*a({type:`tool_execution_start`,replay:`unsafe`,run:i,turn:o,toolCall:s.identity,call:s.call}),yield*lE(s,i,o,a);return{message:yield*fE(s,i,o,a),terminate:s.result.terminate===!0,recorded:!1}})),c=s.filter(({recorded:e})=>!e).map(({message:e})=>e);return n.push(...c),r.push(...c),{message:t.message,toolResults:s.map(({message:e})=>e),terminate:s.length>0&&s.every(({terminate:e})=>e)}})}function wE(e,t,n,r){return x(function*(){if(e.shouldStopAfterTurn!==void 0&&(yield*e.shouldStopAfterTurn({message:t.message,toolResults:t.toolResults,context:n,newMessages:r})))return{continue:!1,pending:[]};let i=e.getSteeringMessages===void 0?[]:[...yield*e.getSteeringMessages()];if(t.message.content.some(e=>e.type===`toolCall`)&&!t.terminate||i.length>0)return{continue:!0,pending:i};let a=e.getFollowUpMessages===void 0?[]:[...yield*e.getFollowUpMessages()];return{continue:a.length>0,pending:a}})}function TE(e,t,n,r,i,a,o){return x(function*(){yield*a({type:`run_end`,run:e,terminal:t,outcome:i});let s={status:i,run:e,terminal:t,message:n,messages:r};return o===void 0?s:{...s,modelLimitReason:o}})}function EE(e,t=aE){return x(function*(){let n=yield*Pg(1),r={started:!1,ended:!1},i=e=>bn(()=>(e.type===`run_end`&&(r.ended=!0),n.withPermits(1)(t(e)))).pipe(Qn(()=>C(()=>{e.type===`run_start`&&(r.started=!0)}))),a=iE(`run`),o=iE(`terminal`,a);return yield*OE(e,i,a,o).pipe(ke(e=>{let t=DE(e);return!r.started||r.ended||t===void 0?_:i({type:`run_end`,run:a,terminal:o,outcome:t}).pipe(Re)}))})}function DE(e){if(qi(e))return;if(Ni(e.cause))return`cancelled`;let t=Li(e.cause);if(!(mn(t)&&t.value.phase===`listener`))return`failed`}function OE(e,t,n,r){return x(function*(){let i=[...e.messages],a=[],o=e.getSteeringMessages===void 0?[]:[...yield*e.getSteeringMessages()],s,c;if(yield*t({type:`run_start`,run:n}),e.resume!==void 0){let s=yield*CE(e,e.resume,i,a,n,t),c=bE(s.message),l=c===`completed`?yield*wE(e,s,i,a):{continue:!1,pending:[]};if(!l.continue&&o.length===0)return yield*TE(n,r,s.message,a,c,t);o.push(...l.pending)}do{let l=yield*SE(e,i,a,n,iE(`turn`,n),o,t);s=l.message;let u=bE(l.message);if(u!==`completed`)return yield*TE(n,r,l.message,a,u,t,l.modelLimitReason);if(e.prepareNextTurn!==void 0&&!l.terminate&&l.message.content.some(e=>e.type===`toolCall`)){let t=yield*e.prepareNextTurn({message:l.message,toolResults:l.toolResults,context:i,newMessages:a});t!==void 0&&i.splice(0,i.length,...t)}let d=yield*wE(e,l,i,a);o=[...d.pending],c=d.continue}while(c);return yield*TE(n,r,s,a,`completed`,t)})}var kE={run:EE},AE=class{#e=new Map;#t;constructor(e=8){this.#t=e}push(e,t){let n=this.#e.get(e)??[];if(n.length>=this.#t)throw new tx({namespace:`execute`,operation:`images`,cause:{kind:`Unavailable`,message:`Image collector cap reached for this execution (max ${String(this.#t)} images). Process images one at a time or write them to files.`}});let r=`img_${String(n.length)}`;return n.push(Object.freeze({...t})),this.#e.set(e,n),r}drain(e){let t=this.#e.get(e);return t===void 0?[]:(this.#e.delete(e),t)}dispose(e){this.#e.delete(e)}},jE=8192,ME=new TextEncoder,NE=()=>new TextDecoder(`utf-8`,{ignoreBOM:!0,fatal:!1}),PE=class e{wake;#e={stdout:{decoder:NE(),pendingBytes:0},stderr:{decoder:NE(),pendingBytes:0}};#t=NE();#n=Array.from({length:jE},()=>void 0);#r=0;#i=0;#a=0;#o=0;#s=0;#c=0;#l=!1;#u=!1;constructor(e){this.wake=e}static make(){return Jh({capacity:1,strategy:`dropping`}).pipe(xe(t=>new e(t)))}write(e,t){if(this.#u||t.length===0)return;let n=this.#e[e];this.#c+=t.length;for(let e=0;e<t.length;e++){let r=t.subarray(e,e+1);n.pendingBytes++;let i=n.decoder.decode(r,{stream:!0});if(i.length===0)continue;let a=+(n.pendingBytes>1&&this.#t.decode(r,{stream:!0}).length===0);this.#t.decode(),this.#f(i,n.pendingBytes-a),n.pendingBytes=a}this.#l=!0,Zh(this.wake,void 0)}#d(){let e=this.#n[this.#r];if(e===void 0)throw Error(`Missing output ring entry`);this.#n[this.#r]=void 0,this.#r=(this.#r+1)%jE,this.#i--,this.#a-=e.textBytes,this.#o-=e.newlines,this.#s+=e.rawBytes}#f(e,t){if(e.length===0)return;let n={text:e,rawBytes:t,textBytes:ME.encode(e).length,newlines:e.split(`
|
|
18
|
+
`).length-1};for(this.#i===jE&&this.#d(),this.#n[(this.#r+this.#i)%jE]=n,this.#i++,this.#a+=n.textBytes,this.#o+=n.newlines;this.#a>jE||this.#o>=200;)this.#d()}snapshot(){let e=``;for(let t=0;t<this.#i;t++){let n=this.#n[(this.#r+t)%jE];if(n===void 0)throw Error(`Missing output ring entry`);e+=n.text}return{tail:e,droppedBytes:this.#s,totalBytes:this.#c}}#p(){if(!this.#l)return;this.#l=!1;let{tail:e,...t}=this.snapshot();return{type:`update`,result:{isError:!1,content:[{type:`text`,text:e}],data:t}}}finish(){if(!this.#u){this.#u=!0;for(let e of[this.#e.stdout,this.#e.stderr]){let t=e.decoder.decode();this.#f(t,e.pendingBytes),e.pendingBytes=0,t.length>0&&(this.#l=!0)}return this.#p()}}get updates(){return U_(this.wake).pipe(q_(()=>Ir(`100 millis`).pipe(xe(()=>this.#u?void 0:this.#p()))),ev(e=>e!==void 0))}dispose(){this.#u=!0,this.#n.fill(void 0),this.#r=this.#i=this.#a=this.#o=0,this.#c=this.#s=0,this.#l=!1;for(let e of[this.#e.stdout,this.#e.stderr])e.decoder.decode(),e.pendingBytes=0}},FE=N({code:j}),IE='Run async JavaScript in the sandbox. Each call is a fresh sandbox, not a REPL: nothing survives between calls, so redefine helpers or persist state to a file. Never shadow injected module names with local bindings. Find operations with await forage.search({ query }) using one short keyword such as read or shell, or page them all with forage.list({limit:50}), optionally by namespace, until nextCursor is null. Inspect input with await forage.describe({ path }) before calling; describe known paths directly. Call an operation as await env.<path>({ ... }) with the exact dotted path, for example await env.computers.local.exec({ command: "pwd" }); a bare computers.local.exec is not defined. Put multiline shell commands in a template literal. Code is JavaScript first, so double each backslash the shell needs (`\\\\(` passes `\\(`; `\\(` becomes `(`). For file edits, prefer Files operations when available. Explicitly return the final value. Before treating a shell or process result as success, check status, exitCode and stderr.';function LE(e,t,n,r){let i={module:e.grantKey,operation:e.name,access:e.operation.access,confirm:e.operation.confirm};return async a=>await $C(n,{sessionId:r},i,a,t.signal)??await e.operation.invoke(a,t)}function RE(e,t,n,r){let i=0,a=new Map;for(let o of e){let e=o.namespace,s=o.name,c=a.get(e)??new Map;c.set(s,e=>LE(o,Object.freeze({...t,operationOrdinal:i++}),n,r)(e)),a.set(e,c)}return Object.freeze(Object.fromEntries([...a].map(([e,t])=>[e,Object.freeze(Object.fromEntries(t))])))}function zE(e,t){let n=e.safeParse(t);if(!n.success)throw new Ub(n.error.issues);return n.data}function BE(e){return Object.freeze({list:t=>Promise.resolve().then(()=>e.list(zE(vy,t))),describe:t=>Promise.resolve().then(()=>e.describe(zE(_y,t))),search:t=>Promise.resolve().then(()=>e.search(zE(gy,t)))})}function VE(e,t,n,r,i){return Object.freeze({...RE(e,n,r,i),forage:BE(t)})}function HE(e,t,n,r,i,a,o,s){let c=n.execution??Kw(void 0),l=new AE,u=(u,d,f,p,m)=>nT({executionId:u,toolCallId:p,output:m,images:Object.freeze({push:e=>l.push(u,e)}),code:d,callerSignal:f,policy:c,sandbox:n,backingWork:r,createBindings:n=>VE(e,t,Object.freeze({...n,toolCallCode:d}),s,o),modules:i,namespacePaths:a,sessionId:o}),d=(e,t)=>bn(()=>{let n=_h();return u(n,e,t).pipe(Jn(C(()=>{l.dispose(n)})))}),f=(e,t,n)=>bn(()=>{let r=_h(),i=()=>l.drain(r);return u(r,e,void 0,t,n).pipe(gt({onSuccess:e=>v(UE({text:e.text,isError:!1},i())),onFailure:e=>{let t=i();return e instanceof $b&&t.length>0?v(UE({text:ix(e),isError:!0},t)):y(WE(e))}}),Jn(C(()=>{l.dispose(r)})))}),p={replay:`unsafe`,descriptor:{name:`execute`,description:IE,parameters:HT({code:qT()},{additionalProperties:!1})},prepare:e=>ip(FE)(e.arguments).pipe(xe(({code:t})=>({execute:()=>G_(x(function*(){let n=yield*PE.make();yield*vr(()=>C(()=>{n.dispose()}));let r=yield*Ln(f(t,e.id,{write:(e,t)=>{n.write(e,t)}}),{startImmediately:!0});return $_(n.updates,M_(Tg(r)).pipe(Y_(e=>{let t=n.finish();return X_(V_(t===void 0?[]:[t]),M_(e))})),{haltStrategy:`right`}).pipe(iv(e=>e.type===`result`))}))})),it(()=>({message:`Invalid execute arguments`})))};return Object.freeze({effectTool:p,execute:d})}function UE(e,t){let n=t.map(e=>({type:`image`,data:e.data,mimeType:e.mimeType})),r=[{type:`text`,text:e.text},...n];return t.length===0?{type:`result`,result:{content:r,isError:e.isError}}:{type:`result`,result:{content:r,data:{images:t.map(e=>({bytes:e.bytes,mimeType:e.mimeType,path:e.path}))},isError:e.isError}}}function WE(e){let t={_tag:`MuleError`,phase:`tool`,message:sx(e)?ix(e):e.message};return e instanceof Jb?{...t,cause:e}:t}function GE(e,t){return e<t?-1:+(e>t)}var KE=128,qE=b(()=>S().min(1).max(160)),JE=b(()=>Un({version:S().min(1).max(160),modules:kt(Rr())})),YE=1e3;function XE(e){if(e.length>KE)throw new U(`Capability source count exceeds bound`);let t=[...e].sort((e,t)=>GE(e.id,t.id)),n=new Set;for(let e of t){if(!qE.safeParse(e.id).success)throw new U(`Capability source id must be non-empty and bounded`);if(n.has(e.id))throw new U(`Duplicate capability source id: ${e.id}`);n.add(e.id)}return t}function ZE(e){if(e>YE)throw new U(`Candidate module count exceeds bound`)}function QE(e,t){let n=JE.safeParse(e);if(!n.success)throw new U(`Capability source snapshot must have a non-empty bounded version`);ZE(t+n.data.modules.length)}function $E(e,t,n,r,i){return Jr(a=>x(function*(){let o=t=>Vr({try:()=>t.release(),catch:()=>new Hb(e.id,`release`)}).pipe(sn(e=>C(()=>{n.push(e)}))),s=yield*Qr({try:()=>{let t=new AbortController;return{controller:t,outcome:e.acquire(i===void 0?{signal:t.signal,invalidate:r}:{signal:t.signal,invalidate:r,session:i}).then(e=>Hi(e),()=>Wi(new Hb(e.id,`acquire`)))}},catch:()=>new Hb(e.id,`acquire`)});yield*da(t,Ot(()=>s.outcome).pipe(w(e=>qi(e)?o(e.value):_)));let c=yield*a(Ot(()=>s.outcome)).pipe(Te(()=>C(()=>{s.controller.abort()})));return Ji(c)?yield*Rt(c.cause):c.value}))}function eD(e){return x(function*(){let t=yield*Qr({try:()=>XE(e.sources),catch:e=>e instanceof U?e:new U(`Capability sources are invalid`)});yield*Qr({try:()=>{ZE(e.modules.length)},catch:e=>e instanceof U?e:new U(`Static capability modules are invalid`)});let n=yield*sa(),r=[],i=!1,a=[...e.modules],o=[];return yield*x(function*(){for(let s of t){let t=yield*$E(s,n,r,()=>{i=!0},e.session);yield*Qr({try:()=>{QE(t.snapshot,a.length)},catch:e=>e instanceof U?e:new U(`Capability source snapshot is invalid`)}),a.push(...t.snapshot.modules),o.push({id:s.id,version:t.snapshot.version})}let s=e.precompiled??(yield*Qr({try:()=>Iw(a,o),catch:e=>e instanceof U?e:new U(`Capability compilation failed`)})),c=e.backingWork.createGroup(),l=HE(s.operations,s.catalog,e.sandbox,c,s.moduleAliases,s.namespacePaths,e.session?.sessionId??null,e.access),u=!1;return Object.freeze({compiled:s,executeDoor:l,isStale:()=>i,close:()=>x(function*(){u||(u=!0,yield*c.awaitIdle,yield*ma(n,Ki));let e=r[0];e!==void 0&&(yield*y(e))})})}).pipe(ke(e=>qi(e)?_:ma(n,e)))})}var tD=2;function nD(e){return x(function*(){for(let t=0;t<tD;t+=1){let t=yield*eD(e);if(!t.isStale())return t;yield*t.close()}return yield*y(new Hb(void 0,`stale`))})}function rD(e,t,n){return Jr(r=>r(e.take(1)).pipe(w(()=>C(t).pipe(Jn(e.release(1)))),w(n)))}function iD(e,t){return $t(e.candidate.close().pipe(gt({onFailure:t=>ra(e.settled,t).pipe(Gt(y(t))),onSuccess:()=>ia(e.settled,void 0).pipe(Gt(C(()=>{t.delete(e)})))})))}function aD(e,t){return e.runCleanup?iD(e.installed,t):ta(e.installed.settled)}function oD(e,t){return kn(e.map(e=>aD(e,t).pipe(wn)),{concurrency:`unbounded`}).pipe(w(e=>{let t=e.find(Ji);return t===void 0?_:Rt(t.cause)}))}function sD(e){return x(function*(){let t=yield*Pg(1),n=yield*Qr({try:()=>Kw(e.execution),catch:e=>e instanceof U?e:new U(`Execution policy is invalid`)}),r=yield*qw(n.capacity),i=Object.freeze({execute:e.sandbox.execute,adapter:e.sandbox.adapter,buildSha:e.sandbox.buildSha,onFailure:e.onSandboxFailure,execution:n}),a=yield*Qr({try:()=>Iw(e.modules),catch:e=>e instanceof U?e:new U(`Capability compilation failed`)}),o=yield*Qr({try:()=>Object.freeze(e.tools.map(t=>nw(t,e.access,{sessionId:e.session?.sessionId??null}))),catch:e=>e instanceof U?e:new U(`Direct tool labels are invalid`)}),s,c=new Set,l=!1;if(e.sources.length===0){let t={candidate:yield*nD({...e,sandbox:i,backingWork:r,precompiled:a}),settled:yield*ea(),leases:0,retired:!1,closing:!1};s=t,c.add(t)}let u=()=>rD(t,()=>(l=!0,[...c].map(e=>{e.retired=!0;let t=e.leases===0&&!e.closing;return t&&(e.closing=!0),{installed:e,runCleanup:t}})),e=>oD(e,c));return yield*vr(()=>u().pipe(Mt)),Object.freeze({acquire:()=>t.withPermits(1)(x(function*(){if(l)return yield*y(new Vb);if(s===void 0||s.candidate.isStale()){let t=yield*nD({...e,sandbox:i,backingWork:r}),n=s,a={candidate:t,settled:yield*ea(),leases:0,retired:!1,closing:!1};s=a,c.add(a),n!==void 0&&(n.retired=!0,n.leases===0&&!n.closing&&(n.closing=!0,yield*iD(n,c)))}let n=s;n.leases+=1;let a,u=()=>rD(t,()=>{if(a!==void 0)return a?{installed:n,runCleanup:!1}:void 0;if(--n.leases,a=n.retired&&n.leases===0&&!n.closing,a)return n.closing=!0,{installed:n,runCleanup:!0}},e=>e===void 0?_:aD(e,c));return yield*vr(()=>u().pipe(Mt)),Object.freeze({revision:n.candidate.compiled.revision,catalog:n.candidate.compiled.catalog,executeDoor:n.candidate.executeDoor,effectExecuteTool:n.candidate.executeDoor.effectTool,tools:o,release:u})})),close:u})})}function cD(e){return Object.freeze({adapter:e.adapter??`promise`,buildSha:e.buildSha,execute:(t,n)=>$t(Vr({try:()=>e.execute(t,n),catch:cx}))})}function lD(e){return sD({modules:e.modules??[],sources:e.sources??[],session:e.session,execution:e.execution,sandbox:e.sandbox,onSandboxFailure:e.onSandboxFailure,tools:e.tools??[],access:e.access??{}}).pipe(xe(e=>Object.freeze({acquire:()=>e.acquire().pipe(xe(e=>Object.freeze({revision:e.revision,catalog:e.catalog,executeTool:e.effectExecuteTool,tools:e.tools,release:e.release}))),close:e.close})))}async function uD(e,t){let n=await Sr(e,t);if(qi(n))return n.value;let r=Li(n.cause);if(mn(r))throw r.value;if(Ni(n.cause))throw t?.signal?.reason instanceof Error?t.signal.reason:new DOMException(`The operation was aborted`,`AbortError`);let i=Fi(n.cause);throw i instanceof Error?i:Error(`Effect failed without an Error cause`)}async function dD(e){let t=await uD(sa()),n=e.onSandboxFailure;try{let r=await uD(sD({modules:e.modules??[],sources:e.sources??[],session:e.session,execution:e.execution,sandbox:cD(e.sandbox),onSandboxFailure:n===void 0?void 0:e=>Ot(()=>n(e)),tools:e.tools??[],access:e.access??{}}).pipe(la(t))),i=async e=>{let t=await uD(sa());try{let n=await uD(r.acquire().pipe(la(t)),e?.signal===void 0?void 0:{signal:e.signal}),i;return Object.freeze({revision:n.revision,catalog:n.catalog,executeTool:n.effectExecuteTool,tools:n.tools,release:()=>(i??=uD(n.release().pipe(Jn(ma(t,Ki)))),i)})}catch(e){throw await uD(ma(t,Ki)),e}},a;return Object.freeze({acquire:i,close:()=>(a??=uD(r.close().pipe(Jn(ma(t,Ki)))),a)})}catch(e){throw await uD(ma(t,Ki)),e}}var fD=Ip(()=>P([Sp,wp,im,j,Np(jp(fD)),_p(Op(j,fD))])),pD=j.check(jm(1),V(256)),mD=j.check(jm(1),V(128)),hD=N({kind:A(`sandbox_failure`),ref:pD,executionId:pD,adapter:mD,buildSha:I(mD),tag:F([`SourceInvalid`,`GuestThrew`,`DeadlineExceeded`,`SandboxBusy`,`Cancelled`,`DispatchLost`,`SandboxCrashed`,`BadResponse`,`ResultTooLarge`,`ResultNotJson`,`CapabilityFailed`,`Unknown`]),fields:Op(j,fD),healthAlert:wp});function gD(e){return fw(e)}function _D(e){return pw(e)}var vD=Object.freeze({module:_D,operation:gD,make:dD,gate:bw,grantAs:yw}),yD=oh,bD=4096,xD=new TextEncoder,SD=yD.check(R(e=>xD.encode(JSON.stringify(e)).byteLength<=bD)),CD=E(SD);function wD(e,t){if(gp(e))return ve(E(e)(t));let n=e[`~standard`].validate(t);if(ar(n,`then`))throw new H(`contract`,`invalid`,`Host metadata schema must validate synchronously`);return n.issues===void 0}function TD(e,t){let n=CD(t);if(xt(n))throw new H(`contract`,`invalid`,`Host metadata is not JSON within 4096 bytes`);if(e!==void 0&&!wD(e.schema,n.success))throw new H(`contract`,`invalid`,`Host metadata does not match the host's schema`);return n.success}function ED(e,t){return JSON.stringify(e)===JSON.stringify(t)}function DD(e,t){jr(Xe(`shiitake_operation_failed`,no(t)).pipe(rr({operation:e,errorKind:t instanceof Error?`error`:`non-error`})))}var OD=64,kD=256,AD=new WeakMap;function jD(e,t){return e===`closed`||t===`closed`?`closed`:e===`reset`||t===`reset`?`reset`:e===`durable`||t===`durable`?`durable`:e===`activity`||t===`activity`?`activity`:`progress`}function MD(e,t){if(e.pendingCount>=kD){e.pendingCount=0,e.pendingReason=void 0,e.reset=!0;return}e.pendingCount+=1,e.pendingReason=e.pendingReason===`durable`||t===`durable`?`durable`:e.pendingReason===`activity`||t===`activity`?`activity`:`progress`}function ND(e,t){if(e.closed||e.reset)return;let n=e.wake;if(n===void 0){MD(e,t);return}e.wake=void 0;try{n(t)}catch(t){DD(`observation-delivery`,t),e.pendingCount=0,e.pendingReason=void 0,e.reset=!0}}function PD(e,t,n=`durable`){let r=AD.get(e);if(r!==void 0)for(let e of r)try{e({kind:`session`,sessionId:t,reason:n})}catch(e){DD(`owner-observation-publish`,e);continue}}function FD(e){let t=AD.get(e);if(t!==void 0)for(let e of t)try{e({kind:`agent-execution`})}catch(e){DD(`owner-execution-change-publish`,e)}}function ID(e){let t=new Map,n=new Set,r=AD.get(e)??new Set,i=!1,a=e=>{if(e.closed)return`closed`;if(e.reset)return e.reset=!1,`reset`;if(e.pendingCount===0)return;e.pendingCount=0;let t=e.pendingReason;return e.pendingReason=void 0,t??`progress`},o=e=>{if(e.closed)return;e.closed=!0,e.pendingCount=0,e.pendingReason=void 0,e.reset=!1;let r=e.wake;e.wake=void 0,n.delete(e);let i=t.get(e.sessionId);if(i?.delete(e),i?.size===0&&t.delete(e.sessionId),r!==void 0)try{r(`closed`)}catch(e){DD(`observation-listener-close`,e)}},s=e=>{if(e.kind===`agent-execution`){for(let e of n)e.queued&&!e.settlementOnly&&ND(e,`activity`);return}let r=e.sessionId===null?n:t.get(e.sessionId);if(r!==void 0)for(let t of r)t.settlementOnly&&e.reason!==`settlement`||ND(t,e.reason===`settlement`?`durable`:e.reason)};return r.add(s),AD.set(e,r),Object.freeze({register:(e,r)=>bn(()=>{if(i)return y(new H(`runtime`,`closed`,`Shiitake is closed`));if(n.size>=OD)return y(new H(`runtime`,`rejected`,`Observation capacity is exhausted`));let s={sessionId:e,settlementOnly:r===`settlement`,closed:!1,pendingCount:0,pendingReason:void 0,queued:!0,reset:!1,wake:void 0},c=t.get(e)??new Set;c.add(s),t.set(e,c),n.add(s);let l=C(()=>a(s)),u=Hn(e=>{let t=a(s);if(t!==void 0){e(v(t));return}let n=t=>{e(v(t))};return s.wake=n,C(()=>{s.wake===n&&(s.wake=void 0)})});return v(Object.freeze({pollSignal:l,awaitSignal:u,close:()=>{o(s)},setQueued:e=>{s.closed||(s.queued=e)}}))}),close:C(()=>{if(!i){i=!0,r.delete(s),r.size===0&&AD.delete(e);for(let e of n)o(e)}})})}var LD=200,RD={onExcessProperty:`error`},zD=new TextEncoder,BD=B.pipe(L(z(0))),VD=j.pipe(L(jm(1)),L(R(e=>zD.encode(e).byteLength<=256)));E(N({limit:O(B.pipe(L(hm({minimum:1,maximum:LD})))),after:O(j)}),RD);var HD=Xm(Ap([BD,VD]));E(HD),hp(HD),E(N({session_id:VD,last_activity_at:BD,state:F([`needs_you`,`running`,`errored`,`done`]),bytes:B.pipe(L(z(0)))}),RD);var UD=cp(N({extension_id:j,value_json:j})),WD=cp(Xm(fv)),GD=cp(pv),KD=hp(Xm(fv));function qD(e){e.sql.exec(`CREATE TABLE IF NOT EXISTS session_attention_grants (
|
|
19
19
|
extension_id TEXT PRIMARY KEY
|
|
20
20
|
)`),e.sql.exec(`CREATE TABLE IF NOT EXISTS session_attention (
|
|
21
21
|
session_id TEXT NOT NULL REFERENCES sessions(id),
|
|
@@ -23,8 +23,8 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
|
|
|
23
23
|
id TEXT NOT NULL,
|
|
24
24
|
value_json TEXT NOT NULL,
|
|
25
25
|
PRIMARY KEY (session_id, extension_id, id)
|
|
26
|
-
)`),e.sql.exec(`CREATE INDEX IF NOT EXISTS idx_session_attention_owner ON session_attention(extension_id, session_id)`)}function
|
|
27
|
-
ON CONFLICT (session_id, extension_id, id) DO UPDATE SET value_json = excluded.value_json`,t,n,r.id,UD(r))}function JD(e,t,n,r){e.sql.exec(`DELETE FROM session_attention WHERE session_id = ? AND extension_id = ? AND id = ?`,t,n,r)}function YD(e,t,n){let r=cp(N({session_id:j}));return e.sql.exec(`SELECT DISTINCT session_id FROM session_attention WHERE extension_id = ? AND session_id > ? ORDER BY session_id LIMIT 64`,t,n).toArray().map(e=>r(e).session_id)}function XD(e,t){let n=cp(N({extension_id:j})),r=new Set(e.sql.exec(`SELECT extension_id FROM session_attention_grants LIMIT 64`).toArray().map(e=>n(e).extension_id)),i=new Set(t),a=[];for(let t of r)i.has(t)||(e.sql.exec(`DELETE FROM session_attention_grants WHERE extension_id = ?`,t),a.push(t));for(let t of i)r.has(t)||(e.sql.exec(`INSERT INTO session_attention_grants (extension_id) VALUES (?)`,t),a.push(t));return a}var ZD=new TextEncoder,QD=new TextDecoder,$D=/^[A-Za-z0-9_-]+$/u,eO=N({v:A(1),generation:j.pipe(L(jm(1)),L(V(128)),L(R(e=>ZD.encode(e).byteLength<=128))),sequence:B.pipe(L(fm(0)),L(mm(2**53-1)))}),tO={onExcessProperty:`error`},nO=E(eO,tO),rO=E(Xm(eO),tO);function iO(e){let t=nO({v:1,...e});if(t._tag===`Failure`)return;let n=JSON.stringify(t.success);if(ZD.encode(n).byteLength>384)return;let r=ts(n);return ZD.encode(r).byteLength<=512?r:void 0}function aO(e){if(ZD.encode(e).byteLength>512||!$D.test(e))return;let t=ns(e);if(t._tag===`Failure`||t.success.byteLength>384)return;let n=QD.decode(t.success),r=rO(n);if(r._tag===`Failure`)return;let i=JSON.stringify(r.success);if(i===n&&ts(i)===e)return Object.freeze({generation:r.success.generation,sequence:r.success.sequence})}var oO=N({status:F([`accepted`,`duplicate`]),cursor:B.check(z(0))});P([F([`accepted`,`duplicate`,`refused`]),oO,N({status:F([`accepted`,`duplicate`,`refused`]),receipt:oh})]),Ei(`PostError`);var sO=j.check(jm(1),V(256));N({postKey:sO}),B.check(z(1),mm(64)),Ph({family:`post`,version:1,kinds:{work:{prefix:`post_work`}}});var cO=N({key:sO,kind:sO,address:xp,event:xp});Xm(P([N({state:A(`pending`),envelope:cO,attempts:B.check(z(0)),nextAttemptAt:M.check(z(0)),jobId:k(sO),delivery:k(cO),nextKey:k(sO)}),N({state:A(`delivered`),receipt:k(oh),nextKey:k(sO)}),N({state:A(`dead`),envelope:cO,attempts:B.check(z(0)),reason:F([`refused`,`exhausted`]),receipt:k(oh),delivery:k(cO),nextKey:k(sO)})])),N({key:j,value:j}),N({due:I(M.check(z(0)))});var lO=j.check(jm(1),V(256)),uO=N({kind:A(`agent`),agentId:lO,sessionId:lO}),dO=N({commandId:lO,outcome:F([`completed`,`failed`,`interrupted`,`cancelled`,`outcome_unknown`]),diagnostic:O(j.check(jm(1),V(200)))}),fO=N({key:lO,to:uO,from:uO,replyTo:jp(uO),content:j,createdAt:M.check(z(0)),meta:O(oh),reply:O(dO)}),pO=N({jobId:lO,sessionId:lO,commandFactId:lO,recovery:k(N({maxRecoveries:B.check(z(0))}))}),mO=N({work:N({sessionId:lO,commandFactId:lO}),mail:k(fO)}),hO=N({work:pO,mail:k(fO)}),gO=e=>{let t=cp(hO)(e),n={sessionId:t.work.sessionId,commandFactId:t.work.commandFactId},r=t.mail===void 0?{work:n}:{work:n,mail:t.mail},i={jobId:t.work.jobId,queue:t.work.sessionId,lane:`default`,priority:0,payload:r,state:`queued`};return t.work.recovery===void 0?i:{...i,recovery:t.work.recovery}},_O=e=>cp(mO)(e.payload),vO=j.check(jm(1),V(256)),yO=N({agentId:vO,sessionId:vO,...dO.fields}),bO=`fungi_agent_reply`,xO=RegExp(`<(?=\\s*/?\\s*${bO})`,`giu`);function SO(e){return e.replace(xO,`<`)}function CO(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}function wO(e){let t=[[`agent_id`,e.agentId],[`session_id`,e.sessionId],[`command_id`,e.commandId],[`outcome`,e.outcome]];return e.diagnostic!==void 0&&t.push([`diagnostic`,e.diagnostic]),`<${bO} ${t.map(([e,t])=>`${e}="${CO(t)}"`).join(` `)}>`}function TO(e,t){let n=Array.isArray(e.content)?e.content.map(e=>e.type===`text`?{...e,text:SO(e.text)}:e):SO(e.content);if(t===void 0)return{...e,content:n};let r=wO(t),i=`</${bO}>`;return{...e,content:Array.isArray(n)?[{type:`text`,text:r},...n,{type:`text`,text:i}]:`${r}\n${n}\n${i}`}}var EO={onExcessProperty:`error`},DO=new TextEncoder,OO=e=>j.pipe(L(jm(1)),L(R(t=>DO.encode(t).byteLength<=e))),kO=OO(256),AO=OO(4096),jO=j.pipe(L(Xp(/^[0-9a-f]{64}$/u))),MO=Ip(()=>P([j,M,wp,Sp,jp(MO),Op(j,MO)])),NO=N({type:A(`text`),text:j,textSignature:O(j)}),PO=N({type:A(`thinking`),thinking:j,thinkingSignature:O(j),redacted:O(wp)}),FO=N({type:A(`image`),data:j,mimeType:j}),IO=N({type:A(`toolCall`),id:j,name:j,arguments:Op(j,MO),thoughtSignature:O(j),namespace:O(j),argumentsError:O(j)}),LO=N({input:M,output:M,cacheRead:M,cacheWrite:M,cacheWrite1h:O(M),reasoning:O(M),totalTokens:M,cost:N({input:M,output:M,cacheRead:M,cacheWrite:M,total:M})}),RO=N({role:A(`user`),content:P([j,Np(jp(P([NO,FO])))]),timestamp:M}),zO=N({role:A(`user`),content:j,timestamp:M}),BO=N({name:j,description:j,parameters:Op(j,MO),constrainedSampling:O(P([A(!1),N({type:A(`json_schema`),strict:F([`prefer`,`require`])}),N({type:A(`grammar`),variants:N({openai_lark:O(j),openai_regex:O(j)})})]))}),VO=P([N({role:A(`system`),content:P([j,Np(jp(NO))]),sections:O(Op(j,P([j,Sp]))),toolsAdded:O(Np(jp(BO))),toolsRemoved:O(Np(jp(N({name:j})))),timestamp:M}),RO,N({role:A(`assistant`),content:Np(jp(P([NO,PO,IO]))),api:j,provider:j,model:j,responseModel:O(j),responseId:O(j),diagnostics:O(Np(jp(N({type:j,timestamp:M,error:O(N({name:O(j),message:j,stack:O(j),code:O(P([j,M]))})),details:O(Op(j,MO))})))),usage:LO,stopReason:F([`pending`,`stop`,`length`,`toolUse`,`error`,`aborted`,`deferred`]),deferred:O(N({provider:j,modelId:j,api:j,id:j,expiresAt:O(M),pollAfterMs:O(M),data:O(MO)})),errorMessage:O(j),rawStopReason:O(j),providerThinkingLevel:O(j),endTurn:O(wp),timestamp:M,durationMs:O(M)}),N({role:A(`toolResult`),toolCallId:j,toolName:j,content:Np(jp(P([NO,FO]))),usage:O(LO),isError:wp,timestamp:M,durationMs:O(M)})]),HO=F([`run`,`turn`,`message`,`tool_call`,`tool_result`,`terminal`]),UO=Ip(()=>N({kind:HO,value:kO,parent:k(UO)})),WO=P([N({type:A(`auto_retry_start`),run:UO,attempt:M,maxAttempts:M,delayMs:M,errorMessage:j}),N({type:A(`auto_retry_attempt`),run:UO,attempt:M}),N({type:A(`auto_retry_end`),run:UO,attempt:M,success:wp,finalError:O(j)})]),GO=N({core:jO,extensions:jp(Ap([kO,j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)))])).pipe(L(V(128)))}),KO=N({content:Np(jp(P([NO,FO]))),usage:k(LO),isError:wp,terminate:k(wp)}),qO={workId:kO},JO=F([`manual`,`threshold`,`overflow`]),YO=Xm(P([N({...qO,kind:A(`sandbox_failure`),event:pD}),N({kind:A(`document`),workId:Sp,extensionId:kO,name:kO,valueJson:j}),N({kind:A(`model_preference`),workId:Sp,preference:I(_v)}),N({...qO,kind:A(`command`),meta:O(bD),reply:O(yO),delivery:O(F([`steer`,`followUp`])),requestId:kO,targetWorkId:O(kO),receiptId:kO,message:RO,contract:GO}),N({...qO,kind:A(`command`),work:A(`compact`),instructions:O(Vv),meta:O(bD),requestId:kO,receiptId:kO,timestamp:B.check(z(0)),contract:GO}),N({kind:A(`operator`),workId:Sp,requestId:kO,author:F([`operator`,`party`]),meta:O(bD),message:zO}),N({...qO,kind:A(`cancellation`),requestId:kO,receiptId:kO,targetWorkId:kO,meta:O(bD)}),N({...qO,kind:A(`model_selection`),provider:kO,model:kO,catalogRevision:kO,definitionRevision:kO,selectionPolicyRevision:kO}),N({...qO,kind:A(`run_started`),run:UO,contract:GO}),N({...qO,kind:A(`turn_started`),run:UO,turn:UO}),N({...qO,kind:A(`model_prompt`),run:UO,turn:UO,attempt:M.pipe(L(_m()),L(fm(0))),contract:GO,systemPrompt:j.pipe(L(R(e=>DO.encode(e).byteLength<=1048576)))}),N({...qO,kind:A(`message_start`),run:UO,turn:UO,message:UO,role:F([`assistant`,`system`,`toolResult`,`user`])}),N({...qO,kind:A(`message`),data:O(MO),run:UO,turn:UO,message:UO,value:VO}),N({...qO,kind:A(`tool_intent`),replay:F([`safe`,`unsafe`]).pipe(Wp(v(`unsafe`))),contract:GO,run:UO,turn:UO,toolCall:UO,call:IO}),N({...qO,kind:A(`tool_outcome`),data:O(MO),run:UO,turn:UO,toolCall:UO,call:IO,result:KO}),N({...qO,kind:A(`live_retry`),event:WO}),N({...qO,kind:A(`compaction`),head:kO,model:Ap([RO]),data:N({reason:O(JO),resumesRun:wp,tokensBefore:M,tokensAfter:O(M),usage:LO,contextRevision:kO,receipt:O(AO),details:O(N({readFiles:jp(j),modifiedFiles:jp(j)}))})}),N({...qO,kind:A(`compaction_notice`),trigger:JO,result:A(`nothing_to_compact`),diagnostic:O(j.check(V(200)))}),N({...qO,kind:A(`compaction_notice`),trigger:JO,result:A(`failed`),usage:O(LO),diagnostic:O(j.check(V(200)))}),N({...qO,kind:A(`compaction_notice`),trigger:JO,result:A(`stale`),usage:O(LO)}),N({...qO,kind:A(`compaction_notice`),trigger:JO,result:A(`insufficient`),usage:O(LO)}),N({...qO,kind:A(`run_terminal`),run:UO,terminal:UO,diagnostic:O(j.check(V(200))),outcome:F([`completed`,`cancelled`,`failed`])}),N({...qO,kind:A(`work_terminal`),diagnostic:O(j),outcome:F([`completed`,`interrupted`,`cancelled`,`failed`])})])),XO=Xm(xp),ZO=E(YO,EO),QO=hp(XO),$O=cp(YO,EO);function ek(e){return`work`in e}function tk(e){return e.kind===`command`&&!ek(e)?e:void 0}function nk(e){return ek(e)?e.timestamp:e.message.timestamp}function rk(e){return TO(e.author===`party`?e.message:{role:`user`,content:`[A human operator replied to the user on your behalf]\n${e.message.content}`,timestamp:e.message.timestamp})}function ik(e){return TO(e.message,e.reply)}function ak(e){return e.author===`party`?e.message:{role:`assistant`,content:[{type:`text`,text:e.message.content}],api:`operator`,provider:`operator`,model:`operator`,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:e.message.timestamp}}function ok(e){return _t(ZO(e),e=>e.kind===`command`&&!ek(e)&&e.delivery===void 0?{...e,delivery:`followUp`}:e)}function sk(e){let t=QO(e);return $O(t),t}var ck=j.pipe(L(jm(1))),lk=B.pipe(L(z(0))),uk={onExcessProperty:`error`},dk=N({value_json:j}),fk=N({state_version:B.pipe(L(z(1))),revision:ck}),pk=N({status:F([`running`,`stopped`]),reason:I(j),stopped_at:I(lk),revision:ck}),mk=N({extension_id:ck,key:ck,due_at:lk}),hk=N({collection:ck,key:ck,value_json:j}),gk=N({sequence:lk}),_k=N({due:F([0,1]),next_due_at:I(lk)});function vk(e){return new H(`store`,`unavailable`,e)}function yk(e,t,n){let r=E(e,uk);return t.map(e=>{let t=r(e);if(t._tag===`Failure`)throw vk(n);return t.success})}function bk(e){e.transactionSync(()=>{e.sql.exec(`CREATE TABLE IF NOT EXISTS shiitake_extension_records (
|
|
26
|
+
)`),e.sql.exec(`CREATE INDEX IF NOT EXISTS idx_session_attention_owner ON session_attention(extension_id, session_id)`)}function JD(e,t){return e.sql.exec(`SELECT a.extension_id, a.value_json FROM session_attention a JOIN shiitake_extension_status s ON s.extension_id = a.extension_id AND s.status = 'running' JOIN session_attention_grants g ON g.extension_id = a.extension_id WHERE a.session_id = ? ORDER BY a.extension_id, a.id LIMIT ?`,t,64).toArray().map(e=>{let t=UD(e);return GD({...WD(t.value_json),extensionId:t.extension_id})})}function YD(e,t){return e.sql.exec(`SELECT 1 FROM session_attention a JOIN shiitake_extension_status s ON s.extension_id = a.extension_id AND s.status = 'running' JOIN session_attention_grants g ON g.extension_id = a.extension_id WHERE a.session_id = ? AND json_extract(a.value_json, '$.inbox') IS NOT 0 LIMIT 1`,t).toArray().length>0}function XD(e,t,n,r){if(cp(N({count:B}))(e.sql.exec(`SELECT COUNT(*) AS count FROM session_attention WHERE session_id = ? AND NOT (extension_id = ? AND id = ?)`,t,n,r.id).one()).count>=64)throw new H(`contract`,`invalid`,`Session attention capacity reached`);if(cp(N({count:B}))(e.sql.exec(`SELECT COUNT(*) AS count FROM session_attention WHERE extension_id = ? AND NOT (session_id = ? AND id = ?)`,n,t,r.id).one()).count>=4096)throw new H(`contract`,`invalid`,`Extension attention capacity reached`);e.sql.exec(`INSERT INTO session_attention (session_id, extension_id, id, value_json) VALUES (?, ?, ?, ?)
|
|
27
|
+
ON CONFLICT (session_id, extension_id, id) DO UPDATE SET value_json = excluded.value_json`,t,n,r.id,KD(r))}function ZD(e,t,n,r){e.sql.exec(`DELETE FROM session_attention WHERE session_id = ? AND extension_id = ? AND id = ?`,t,n,r)}function QD(e,t,n){let r=cp(N({session_id:j}));return e.sql.exec(`SELECT DISTINCT session_id FROM session_attention WHERE extension_id = ? AND session_id > ? ORDER BY session_id LIMIT 64`,t,n).toArray().map(e=>r(e).session_id)}function $D(e,t){let n=cp(N({extension_id:j})),r=new Set(e.sql.exec(`SELECT extension_id FROM session_attention_grants LIMIT 64`).toArray().map(e=>n(e).extension_id)),i=new Set(t),a=[];for(let t of r)i.has(t)||(e.sql.exec(`DELETE FROM session_attention_grants WHERE extension_id = ?`,t),a.push(t));for(let t of i)r.has(t)||(e.sql.exec(`INSERT INTO session_attention_grants (extension_id) VALUES (?)`,t),a.push(t));return a}var eO=new TextEncoder,tO=new TextDecoder,nO=/^[A-Za-z0-9_-]+$/u,rO=N({v:A(1),generation:j.pipe(L(jm(1)),L(V(128)),L(R(e=>eO.encode(e).byteLength<=128))),sequence:B.pipe(L(fm(0)),L(mm(2**53-1)))}),iO={onExcessProperty:`error`},aO=E(rO,iO),oO=E(Xm(rO),iO);function sO(e){let t=aO({v:1,...e});if(t._tag===`Failure`)return;let n=JSON.stringify(t.success);if(eO.encode(n).byteLength>384)return;let r=ts(n);return eO.encode(r).byteLength<=512?r:void 0}function cO(e){if(eO.encode(e).byteLength>512||!nO.test(e))return;let t=ns(e);if(t._tag===`Failure`||t.success.byteLength>384)return;let n=tO.decode(t.success),r=oO(n);if(r._tag===`Failure`)return;let i=JSON.stringify(r.success);if(i===n&&ts(i)===e)return Object.freeze({generation:r.success.generation,sequence:r.success.sequence})}var lO=N({status:F([`accepted`,`duplicate`]),cursor:B.check(z(0))});P([F([`accepted`,`duplicate`,`refused`]),lO,N({status:F([`accepted`,`duplicate`,`refused`]),receipt:oh})]),Ei(`PostError`);var uO=j.check(jm(1),V(256));N({postKey:uO}),B.check(z(1),mm(64)),Ph({family:`post`,version:1,kinds:{work:{prefix:`post_work`}}});var dO=N({key:uO,kind:uO,address:xp,event:xp});Xm(P([N({state:A(`pending`),envelope:dO,attempts:B.check(z(0)),nextAttemptAt:M.check(z(0)),deadlineAt:k(M.check(z(0))),jobId:k(uO),delivery:k(dO),nextKey:k(uO)}),N({state:A(`delivered`),receipt:k(oh),nextKey:k(uO)}),N({state:A(`dead`),envelope:dO,attempts:B.check(z(0)),reason:F([`refused`,`exhausted`,`expired`]),deadlineAt:k(M.check(z(0))),receipt:k(oh),delivery:k(dO),nextKey:k(uO)})])),N({key:j,value:j}),N({due:I(M.check(z(0)))});var fO=j.check(jm(1),V(256)),pO=262144,mO=j.check(R(e=>new TextEncoder().encode(e).byteLength<=pO,{message:`Mail content must be at most ${String(pO)} UTF-8 bytes`})),hO=N({kind:A(`agent`),agentId:fO,sessionId:fO}),gO=N({kind:A(`agent`),agentId:fO,sessionId:O(fO)}),_O=N({kind:A(`system`),systemId:A(`hub`)}),vO=N({commandId:fO,outcome:F([`completed`,`failed`,`interrupted`,`cancelled`,`outcome_unknown`]),diagnostic:O(j.check(jm(1),V(200)))}),yO=F([`recipient_offline`,`recipient_left`]),bO=N({outcome:A(`undeliverable`),reason:yO}),xO=N({outcome:A(`accepted`),commandId:fO});P([vO,bO,xO]);var SO=P([vO,xO,N({outcome:A(`undeliverable`),reason:A(`recipient_left`)})]),CO=`[redacted]`,wO=/\b(bearer|basic)\s+[^\s"',;]+/giu,TO=/\b((?:api[_-]?key|access[_-]?token|refresh[_-]?token|token|secret|password|authorization)["']?\s*[:=]\s*["']?)(?!(?:bearer|basic)\s)[^\s"',;&]+/giu,EO=/[A-Za-z0-9][\w-]{23,}/gu;function DO(e){return e.replace(wO,`$1 ${CO}`).replace(TO,`$1${CO}`).replace(EO,e=>/\d/u.test(e)&&/[A-Za-z]/u.test(e)?CO:e)}function OO(e){let t=DO(e.replace(/[\p{Cc}\p{Zl}\p{Zp}\s]+/gu,` `).trim()).slice(0,200).trimEnd();return t.length===0?void 0:t}var kO={key:fO,to:gO,replyTo:jp(hO),content:mO,createdAt:M.check(z(0)),meta:O(oh)},AO=P([N({...kO,from:hO,reply:O(SO)}),N({...kO,from:_O,reply:N({outcome:A(`undeliverable`),reason:A(`recipient_offline`)})})]),jO=N({jobId:fO,sessionId:fO,commandFactId:fO,recovery:k(N({maxRecoveries:B.check(z(0))}))}),MO=N({work:N({sessionId:fO,commandFactId:fO}),mail:k(AO)}),NO=N({work:jO,mail:k(AO)}),PO=e=>{let t=cp(NO)(e),n={sessionId:t.work.sessionId,commandFactId:t.work.commandFactId},r=t.mail===void 0?{work:n}:{work:n,mail:t.mail},i={jobId:t.work.jobId,queue:t.work.sessionId,lane:`default`,priority:0,payload:r,state:`queued`};return t.work.recovery===void 0?i:{...i,recovery:t.work.recovery}},FO=e=>cp(MO)(e.payload);function IO(e,t,n,r){let i=cp(fO)(t),a=cp(hO)(e.from),o=cp(xO)({outcome:`accepted`,commandId:n});return{key:`${e.key}:accepted`,to:a,from:{...e.to,sessionId:i},replyTo:[],content:`Work accepted.`,createdAt:r,reply:o}}var LO=j.check(jm(1),V(256)),RO=P([N({agentId:LO,sessionId:LO,...vO.fields}),N({agentId:LO,sessionId:O(LO),...bO.fields})]),zO=`fungi_agent_reply`,BO=RegExp(`<(?=\\s*/?\\s*${zO})`,`giu`);function VO(e){return e.replace(BO,`<`)}function HO(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}function UO(e){let t=[[`agent_id`,e.agentId]];return e.sessionId!==void 0&&t.push([`session_id`,e.sessionId]),e.outcome!==`undeliverable`&&t.push([`command_id`,e.commandId]),t.push([`outcome`,e.outcome]),e.outcome!==`undeliverable`&&e.diagnostic!==void 0&&t.push([`diagnostic`,e.diagnostic]),e.outcome===`undeliverable`&&t.push([`reason`,e.reason]),`<${zO} ${t.map(([e,t])=>`${e}="${HO(t)}"`).join(` `)}>`}function WO(e,t){let n=Array.isArray(e.content)?e.content.map(e=>e.type===`text`?{...e,text:VO(e.text)}:e):VO(e.content);if(t===void 0)return{...e,content:n};let r=UO(t),i=`</${zO}>`;return{...e,content:Array.isArray(n)?[{type:`text`,text:r},...n,{type:`text`,text:i}]:`${r}\n${n}\n${i}`}}var GO={onExcessProperty:`error`},KO=new TextEncoder,qO=e=>j.pipe(L(jm(1)),L(R(t=>KO.encode(t).byteLength<=e))),JO=qO(256),YO=qO(4096),XO=j.pipe(L(Xp(/^[0-9a-f]{64}$/u))),ZO=Ip(()=>P([j,M,wp,Sp,jp(ZO),Op(j,ZO)])),QO=N({type:A(`text`),text:j,textSignature:O(j)}),$O=N({type:A(`thinking`),thinking:j,thinkingSignature:O(j),redacted:O(wp)}),ek=N({type:A(`image`),data:j,mimeType:j}),tk=N({type:A(`toolCall`),id:j,name:j,arguments:Op(j,ZO),thoughtSignature:O(j),namespace:O(j),argumentsError:O(j)}),nk=N({input:M,output:M,cacheRead:M,cacheWrite:M,cacheWrite1h:O(M),reasoning:O(M),totalTokens:M,cost:N({input:M,output:M,cacheRead:M,cacheWrite:M,total:M})}),rk=N({role:A(`user`),content:P([j,Np(jp(P([QO,ek])))]),timestamp:M}),ik=N({role:A(`user`),content:j,timestamp:M}),ak=N({name:j,description:j,parameters:Op(j,ZO),constrainedSampling:O(P([A(!1),N({type:A(`json_schema`),strict:F([`prefer`,`require`])}),N({type:A(`grammar`),variants:N({openai_lark:O(j),openai_regex:O(j)})})]))}),ok=P([N({role:A(`system`),content:P([j,Np(jp(QO))]),sections:O(Op(j,P([j,Sp]))),toolsAdded:O(Np(jp(ak))),toolsRemoved:O(Np(jp(N({name:j})))),timestamp:M}),rk,N({role:A(`assistant`),content:Np(jp(P([QO,$O,tk]))),api:j,provider:j,model:j,responseModel:O(j),responseId:O(j),diagnostics:O(Np(jp(N({type:j,timestamp:M,error:O(N({name:O(j),message:j,stack:O(j),code:O(P([j,M]))})),details:O(Op(j,ZO))})))),usage:nk,stopReason:F([`pending`,`stop`,`length`,`toolUse`,`error`,`aborted`,`deferred`]),deferred:O(N({provider:j,modelId:j,api:j,id:j,expiresAt:O(M),pollAfterMs:O(M),data:O(ZO)})),errorMessage:O(j),providerError:O(j),rawStopReason:O(j),providerThinkingLevel:O(j),endTurn:O(wp),timestamp:M,durationMs:O(M)}),N({role:A(`toolResult`),toolCallId:j,toolName:j,content:Np(jp(P([QO,ek]))),usage:O(nk),isError:wp,timestamp:M,durationMs:O(M)})]),sk=F([`run`,`turn`,`message`,`tool_call`,`tool_result`,`terminal`]),ck=Ip(()=>N({kind:sk,value:JO,parent:k(ck)})),lk=P([N({type:A(`auto_retry_start`),run:ck,attempt:M,maxAttempts:M,delayMs:M,errorMessage:j}),N({type:A(`auto_retry_attempt`),run:ck,attempt:M}),N({type:A(`auto_retry_end`),run:ck,attempt:M,success:wp,finalError:O(j)})]),uk=N({core:XO,extensions:jp(Ap([JO,j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)))])).pipe(L(V(128)))}),dk=N({content:Np(jp(P([QO,ek]))),usage:k(nk),isError:wp,terminate:k(wp)}),fk={workId:JO},pk=F([`manual`,`threshold`,`overflow`]),mk=Xm(P([N({...fk,kind:A(`sandbox_failure`),event:hD}),N({kind:A(`document`),workId:Sp,extensionId:JO,name:JO,valueJson:j}),N({kind:A(`model_preference`),workId:Sp,preference:I(_v)}),N({...fk,kind:A(`command`),meta:O(SD),reply:O(RO),delivery:O(F([`steer`,`followUp`])),requestId:JO,targetWorkId:O(JO),receiptId:JO,message:rk,contract:uk}),N({...fk,kind:A(`command`),work:A(`compact`),instructions:O(Hv),meta:O(SD),requestId:JO,receiptId:JO,timestamp:B.check(z(0)),contract:uk}),N({kind:A(`operator`),workId:Sp,requestId:JO,author:F([`operator`,`party`]),meta:O(SD),message:ik}),N({...fk,kind:A(`cancellation`),requestId:JO,receiptId:JO,targetWorkId:JO,meta:O(SD)}),N({...fk,kind:A(`model_selection`),provider:JO,model:JO,catalogRevision:JO,definitionRevision:JO,selectionPolicyRevision:JO}),N({...fk,kind:A(`run_started`),run:ck,contract:uk}),N({...fk,kind:A(`turn_started`),run:ck,turn:ck}),N({...fk,kind:A(`model_prompt`),run:ck,turn:ck,attempt:M.pipe(L(_m()),L(fm(0))),contract:uk,systemPrompt:j.pipe(L(R(e=>KO.encode(e).byteLength<=1048576)))}),N({...fk,kind:A(`message_start`),run:ck,turn:ck,message:ck,role:F([`assistant`,`system`,`toolResult`,`user`])}),N({...fk,kind:A(`message`),data:O(ZO),run:ck,turn:ck,message:ck,value:ok}),N({...fk,kind:A(`tool_intent`),replay:F([`safe`,`unsafe`]).pipe(Wp(v(`unsafe`))),contract:uk,run:ck,turn:ck,toolCall:ck,call:tk}),N({...fk,kind:A(`tool_outcome`),data:O(ZO),run:ck,turn:ck,toolCall:ck,call:tk,result:dk}),N({...fk,kind:A(`live_retry`),event:lk}),N({...fk,kind:A(`compaction`),head:JO,model:Ap([rk]),data:N({reason:O(pk),resumesRun:wp,tokensBefore:M,tokensAfter:O(M),usage:nk,contextRevision:JO,receipt:O(YO),details:O(N({readFiles:jp(j),modifiedFiles:jp(j)}))})}),N({...fk,kind:A(`compaction_notice`),trigger:pk,result:A(`nothing_to_compact`),diagnostic:O(j.check(V(200)))}),N({...fk,kind:A(`compaction_notice`),trigger:pk,result:A(`failed`),usage:O(nk),diagnostic:O(j.check(V(200)))}),N({...fk,kind:A(`compaction_notice`),trigger:pk,result:A(`stale`),usage:O(nk)}),N({...fk,kind:A(`compaction_notice`),trigger:pk,result:A(`insufficient`),usage:O(nk)}),N({...fk,kind:A(`run_terminal`),run:ck,terminal:ck,diagnostic:O(j.check(V(200))),outcome:F([`completed`,`cancelled`,`failed`])}),N({...fk,kind:A(`work_terminal`),diagnostic:O(j),outcome:F([`completed`,`interrupted`,`cancelled`,`failed`])})])),hk=Xm(xp),gk=E(mk,GO),_k=hp(hk),vk=cp(mk,GO);function yk(e){return`work`in e}function bk(e){return e.kind===`command`&&!yk(e)?e:void 0}function xk(e){return yk(e)?e.timestamp:e.message.timestamp}function Sk(e){return WO(e.author===`party`?e.message:{role:`user`,content:`[A human operator replied to the user on your behalf]\n${e.message.content}`,timestamp:e.message.timestamp})}function Ck(e){return WO(e.message,e.reply)}function wk(e){return e.author===`party`?e.message:{role:`assistant`,content:[{type:`text`,text:e.message.content}],api:`operator`,provider:`operator`,model:`operator`,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:e.message.timestamp}}function Tk(e){return _t(gk(e),e=>e.kind===`command`&&!yk(e)&&e.delivery===void 0?{...e,delivery:`followUp`}:e)}function Ek(e){let t=_k(e);return vk(t),t}var Dk=j.pipe(L(jm(1))),Ok=B.pipe(L(z(0))),kk={onExcessProperty:`error`},Ak=N({value_json:j}),jk=N({state_version:B.pipe(L(z(1))),revision:Dk}),Mk=N({status:F([`running`,`stopped`]),reason:I(j),stopped_at:I(Ok),revision:Dk}),Nk=N({extension_id:Dk,key:Dk,due_at:Ok}),Pk=N({collection:Dk,key:Dk,value_json:j}),Fk=N({sequence:Ok}),Ik=N({due:F([0,1]),next_due_at:I(Ok)});function Lk(e){return new H(`store`,`unavailable`,e)}function Rk(e,t,n){let r=E(e,kk);return t.map(e=>{let t=r(e);if(t._tag===`Failure`)throw Lk(n);return t.success})}function zk(e){e.transactionSync(()=>{e.sql.exec(`CREATE TABLE IF NOT EXISTS shiitake_extension_records (
|
|
28
28
|
extension_id TEXT NOT NULL,
|
|
29
29
|
collection TEXT NOT NULL,
|
|
30
30
|
key TEXT NOT NULL,
|
|
@@ -53,58 +53,58 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
|
|
|
53
53
|
ON shiitake_extension_timers(due_at, extension_id, key)`),e.sql.exec(`CREATE TABLE IF NOT EXISTS shiitake_settled_cursors (
|
|
54
54
|
consumer TEXT PRIMARY KEY,
|
|
55
55
|
sequence INTEGER NOT NULL CHECK (sequence >= 0)
|
|
56
|
-
)`)})}function
|
|
57
|
-
WHERE extension_id = ? AND collection = ? AND key = ?`,t,n,r).toArray(),`Stored extension record is invalid`)[0]?.value_json}function
|
|
56
|
+
)`)})}function Bk(e,t,n,r){return Rk(Ak,e.sql.exec(`SELECT value_json FROM shiitake_extension_records
|
|
57
|
+
WHERE extension_id = ? AND collection = ? AND key = ?`,t,n,r).toArray(),`Stored extension record is invalid`)[0]?.value_json}function Vk(e,t,n,r){return Rk(Ak,e.sql.exec(`SELECT value_json FROM shiitake_extension_records
|
|
58
58
|
WHERE extension_id = ? AND collection = ?
|
|
59
59
|
AND (? IS NULL OR index_value = ?)
|
|
60
60
|
AND (? IS NULL OR key > ?)
|
|
61
|
-
ORDER BY key LIMIT ?`,t,n,r.index??null,r.index??null,r.after??null,r.after??null,r.limit).toArray(),`Stored extension record is invalid`).map(({value_json:e})=>e)}function
|
|
61
|
+
ORDER BY key LIMIT ?`,t,n,r.index??null,r.index??null,r.after??null,r.after??null,r.limit).toArray(),`Stored extension record is invalid`).map(({value_json:e})=>e)}function Hk(e,t,n,r,i,a){e.sql.exec(`INSERT INTO shiitake_extension_records
|
|
62
62
|
(extension_id, collection, key, index_value, value_json)
|
|
63
63
|
VALUES (?, ?, ?, ?, ?)
|
|
64
64
|
ON CONFLICT(extension_id, collection, key) DO UPDATE SET
|
|
65
|
-
index_value = excluded.index_value, value_json = excluded.value_json`,t,n,r,i,a)}function
|
|
66
|
-
WHERE extension_id = ? AND collection = ? AND key = ?`,t,n,r)}function
|
|
67
|
-
WHERE extension_id = ? ORDER BY collection, key`,t).toArray(),`Stored extension record is invalid`).map(e=>({collection:e.collection,key:e.key,valueJson:e.value_json}))}function
|
|
68
|
-
WHERE extension_id = ?`,t).toArray(),`Extension ledger is invalid`)[0];return n===void 0?void 0:{version:n.state_version,revision:n.revision}}function
|
|
65
|
+
index_value = excluded.index_value, value_json = excluded.value_json`,t,n,r,i,a)}function Uk(e,t,n,r){e.sql.exec(`DELETE FROM shiitake_extension_records
|
|
66
|
+
WHERE extension_id = ? AND collection = ? AND key = ?`,t,n,r)}function Wk(e,t){return Rk(Pk,e.sql.exec(`SELECT collection, key, value_json FROM shiitake_extension_records
|
|
67
|
+
WHERE extension_id = ? ORDER BY collection, key`,t).toArray(),`Stored extension record is invalid`).map(e=>({collection:e.collection,key:e.key,valueJson:e.value_json}))}function Gk(e,t){e.sql.exec(`DELETE FROM shiitake_extension_records WHERE extension_id = ?`,t)}function Kk(e,t){let n=Rk(jk,e.sql.exec(`SELECT state_version, revision FROM shiitake_extension_state
|
|
68
|
+
WHERE extension_id = ?`,t).toArray(),`Extension ledger is invalid`)[0];return n===void 0?void 0:{version:n.state_version,revision:n.revision}}function qk(e,t,n,r){e.sql.exec(`INSERT INTO shiitake_extension_state (extension_id, state_version, revision)
|
|
69
69
|
VALUES (?, ?, ?)
|
|
70
70
|
ON CONFLICT(extension_id) DO UPDATE SET
|
|
71
|
-
state_version = excluded.state_version, revision = excluded.revision`,t,n,r)}function
|
|
72
|
-
WHERE extension_id = ?`,t).toArray(),`Extension status is invalid`)[0];return n===void 0?void 0:{status:n.status,reason:n.reason,stoppedAt:n.stopped_at,revision:n.revision}}function
|
|
71
|
+
state_version = excluded.state_version, revision = excluded.revision`,t,n,r)}function Jk(e,t){let n=Rk(Mk,e.sql.exec(`SELECT status, reason, stopped_at, revision FROM shiitake_extension_status
|
|
72
|
+
WHERE extension_id = ?`,t).toArray(),`Extension status is invalid`)[0];return n===void 0?void 0:{status:n.status,reason:n.reason,stoppedAt:n.stopped_at,revision:n.revision}}function Yk(e,t,n){e.sql.exec(`INSERT INTO shiitake_extension_status
|
|
73
73
|
(extension_id, status, reason, stopped_at, revision)
|
|
74
74
|
VALUES (?, ?, ?, ?, ?)
|
|
75
75
|
ON CONFLICT(extension_id) DO UPDATE SET status = excluded.status,
|
|
76
76
|
reason = excluded.reason, stopped_at = excluded.stopped_at,
|
|
77
|
-
revision = excluded.revision`,t,n.status,n.reason,n.stoppedAt,n.revision)}function
|
|
77
|
+
revision = excluded.revision`,t,n.status,n.reason,n.stoppedAt,n.revision)}function Xk(e,t,n,r){e.sql.exec(`INSERT INTO shiitake_extension_timers (extension_id, key, due_at)
|
|
78
78
|
VALUES (?, ?, ?)
|
|
79
|
-
ON CONFLICT(extension_id, key) DO UPDATE SET due_at = excluded.due_at`,t,n,r)}function
|
|
80
|
-
WHERE extension_id = ? AND key = ?`,t,n).toArray(),`Extension timer is invalid`)[0]?.due_at}function
|
|
81
|
-
WHERE due_at <= ? AND extension_id IN (${
|
|
82
|
-
ORDER BY due_at, extension_id, key LIMIT ?`,n,...t,r).toArray(),`Extension timer is invalid`).map(e=>({extensionId:e.extension_id,key:e.key,dueAt:e.due_at}))}function
|
|
79
|
+
ON CONFLICT(extension_id, key) DO UPDATE SET due_at = excluded.due_at`,t,n,r)}function Zk(e,t,n){e.sql.exec(`DELETE FROM shiitake_extension_timers WHERE extension_id = ? AND key = ?`,t,n)}function Qk(e,t){e.sql.exec(`DELETE FROM shiitake_extension_timers WHERE extension_id = ?`,t)}function $k(e,t,n){return Rk(Nk,e.sql.exec(`SELECT extension_id, key, due_at FROM shiitake_extension_timers
|
|
80
|
+
WHERE extension_id = ? AND key = ?`,t,n).toArray(),`Extension timer is invalid`)[0]?.due_at}function eA(e){return e.map(()=>`?`).join(`, `)}function tA(e,t,n,r){return t.length===0?[]:Rk(Nk,e.sql.exec(`SELECT extension_id, key, due_at FROM shiitake_extension_timers
|
|
81
|
+
WHERE due_at <= ? AND extension_id IN (${eA(t)})
|
|
82
|
+
ORDER BY due_at, extension_id, key LIMIT ?`,n,...t,r).toArray(),`Extension timer is invalid`).map(e=>({extensionId:e.extension_id,key:e.key,dueAt:e.due_at}))}function nA(e,t,n){if(t.length===0)return{due:!1,nextWakeAt:null};let r=eA(t),i=Rk(Ik,e.sql.exec(`SELECT
|
|
83
83
|
EXISTS (SELECT 1 FROM shiitake_extension_timers
|
|
84
84
|
WHERE due_at <= ? AND extension_id IN (${r})) AS due,
|
|
85
85
|
(SELECT MIN(due_at) FROM shiitake_extension_timers
|
|
86
|
-
WHERE due_at > ? AND extension_id IN (${r})) AS next_due_at`,n,...t,n,...t).toArray(),`Extension timer is invalid`)[0];if(i===void 0)throw
|
|
87
|
-
ON CONFLICT(consumer) DO UPDATE SET sequence = MAX(sequence, excluded.sequence)`,t,n)}var
|
|
86
|
+
WHERE due_at > ? AND extension_id IN (${r})) AS next_due_at`,n,...t,n,...t).toArray(),`Extension timer is invalid`)[0];if(i===void 0)throw Lk(`Extension timer is unavailable`);return{due:i.due===1,nextWakeAt:i.next_due_at}}function rA(e,t){return Rk(Fk,e.sql.exec(`SELECT sequence FROM shiitake_settled_cursors WHERE consumer = ?`,t).toArray(),`Settled cursor is invalid`)[0]?.sequence}function iA(e,t,n){e.sql.exec(`INSERT INTO shiitake_settled_cursors (consumer, sequence) VALUES (?, ?)
|
|
87
|
+
ON CONFLICT(consumer) DO UPDATE SET sequence = MAX(sequence, excluded.sequence)`,t,n)}var aA=N({extension_id:j,name:j,initial_json:j,fork:F([`inherit-at-fork-point`,`current`,`fresh`]),max_bytes:B.pipe(L(fm(0)))});function oA(e){e.sql.exec(`CREATE TABLE IF NOT EXISTS session_document_specs (
|
|
88
88
|
extension_id TEXT NOT NULL, name TEXT NOT NULL, initial_json TEXT NOT NULL,
|
|
89
89
|
fork TEXT NOT NULL, max_bytes INTEGER NOT NULL,
|
|
90
90
|
PRIMARY KEY (extension_id, name)
|
|
91
|
-
)`)}function
|
|
91
|
+
)`)}function sA(e,t){e.sql.exec(`INSERT INTO session_document_specs
|
|
92
92
|
(extension_id, name, initial_json, fork, max_bytes) VALUES (?, ?, ?, ?, ?)
|
|
93
93
|
ON CONFLICT(extension_id, name) DO UPDATE SET initial_json = excluded.initial_json,
|
|
94
|
-
fork = excluded.fork, max_bytes = excluded.max_bytes`,t.extensionId,t.name,t.initialJson,t.fork,t.maxBytes)}function
|
|
94
|
+
fork = excluded.fork, max_bytes = excluded.max_bytes`,t.extensionId,t.name,t.initialJson,t.fork,t.maxBytes)}function cA(e,t){return e.sql.exec(`SELECT extension_id, name, initial_json, fork, max_bytes FROM session_document_specs ORDER BY extension_id, name`).toArray().flatMap(e=>{let n=cp(aA)(e);if(n.fork===`inherit-at-fork-point`)return[];let r=n.fork===`fresh`?n.initial_json:t(n.extension_id,n.name)??n.initial_json;if(new TextEncoder().encode(r).byteLength>n.max_bytes)throw new H(`store`,`rejected`,`Session document exceeds its declared size bound`);return[{kind:`document`,workId:null,extensionId:n.extension_id,name:n.name,valueJson:r}]})}var lA=rp(j),uA=`The conversation history before this point was compacted into the following summary:
|
|
95
95
|
|
|
96
96
|
<summary>
|
|
97
|
-
`,
|
|
98
|
-
</summary>`;function
|
|
97
|
+
`,dA=`
|
|
98
|
+
</summary>`;function fA(e,t){return{role:`user`,content:[{type:`text`,text:uA+e+dA}],timestamp:t}}function pA(e){let t=Array.isArray(e.content)?e.content[0]:void 0,n=t?.type===`text`?t.text:void 0;if(n===void 0||!n.startsWith(uA)||!n.endsWith(dA))throw Error(`Compaction model message is not a summary`);return n.slice(uA.length,n.length-dA.length)}function mA(){return{edited:new Set,read:new Set,written:new Set}}function hA(e,t){if(e.role===`assistant`)for(let n of e.content){if(n.type!==`toolCall`)continue;let e=n.arguments.path;lA(e)&&(n.name===`edit`&&t.edited.add(e),n.name===`read`&&t.read.add(e),n.name===`write`&&t.written.add(e))}}function gA(e){let t=new Set([...e.edited,...e.written]);return{modifiedFiles:[...t].sort(),readFiles:[...e.read].filter(e=>!t.has(e)).sort()}}function _A(e,t){let n=[];return e.length>0&&n.push(`<read-files>\n${e.join(`
|
|
99
99
|
`)}\n</read-files>`),t.length>0&&n.push(`<modified-files>\n${t.join(`
|
|
100
100
|
`)}\n</modified-files>`),n.length===0?``:`\n\n${n.join(`
|
|
101
101
|
|
|
102
|
-
`)}`}var
|
|
103
|
-
`)}`),n.length>0&&r.push(`[Assistant tool calls]: ${n.join(`; `)}`),r}function
|
|
102
|
+
`)}`}var vA=2e3;function yA(e){return e.filter(e=>e.type===`text`).map(e=>e.text??``).join(``)}function bA(e){if(e.length<=vA)return e;let t=String(e.length-vA);return`${e.slice(0,vA)}\n\n[... ${t} more characters truncated]`}function xA(e){let t=lA(e.content)?e.content:yA(e.content);return t?`[User]: ${t}`:void 0}function SA(e){let t=[],n=[];for(let r of e.content)if(r.type===`text`)t.push(r.text);else if(r.type===`toolCall`){let e=Object.entries(r.arguments).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(`, `);n.push(`${r.name}(${e})`)}let r=[];return t.length>0&&r.push(`[Assistant]: ${t.join(`
|
|
103
|
+
`)}`),n.length>0&&r.push(`[Assistant tool calls]: ${n.join(`; `)}`),r}function CA(e){let t=yA(e.content);return t?`[Tool result]: ${bA(t)}`:void 0}function wA(e){let t=[];for(let n of e)if(n.role===`system`){let e=lA(n.content)?n.content:yA(n.content);e&&t.push(`[System]: ${e}`)}else if(n.role===`user`){let e=xA(n);e!==void 0&&t.push(e)}else if(n.role===`assistant`)t.push(...SA(n));else{let e=CA(n);e!==void 0&&t.push(e)}return t.join(`
|
|
104
104
|
|
|
105
|
-
`)}function
|
|
105
|
+
`)}function TA(e,t,n){return n.enabled?e>t-n.reserveTokens:!1}function EA(e,t,n){return!n.enabled||n.backgroundTokens===0?!1:e>t-n.reserveTokens-n.backgroundTokens&&!TA(e,t,n)}var DA={enabled:!0,reserveTokens:16384,keepRecentTokens:2e4,backgroundTokens:32768},OA=`You are a context summarization assistant. Your task is to read a conversation between a user and an AI coding assistant, then produce a structured summary following the exact format specified.
|
|
106
106
|
|
|
107
|
-
Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`,
|
|
107
|
+
Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`,kA=`The messages above are a conversation to summarize. Create a structured context checkpoint summary that another LLM will use to continue the work.
|
|
108
108
|
|
|
109
109
|
Use this EXACT format:
|
|
110
110
|
|
|
@@ -135,7 +135,7 @@ Use this EXACT format:
|
|
|
135
135
|
- [Any data, examples, or references needed to continue]
|
|
136
136
|
- [Or "(none)" if not applicable]
|
|
137
137
|
|
|
138
|
-
Keep each section concise. Preserve exact file paths, function names, and error messages.`,
|
|
138
|
+
Keep each section concise. Preserve exact file paths, function names, and error messages.`,AA=`The messages above are NEW conversation messages to incorporate into the existing summary provided in <previous-summary> tags.
|
|
139
139
|
|
|
140
140
|
Update the existing structured summary with new information. RULES:
|
|
141
141
|
- PRESERVE all existing information from the previous summary
|
|
@@ -172,7 +172,7 @@ Use this EXACT format:
|
|
|
172
172
|
## Critical Context
|
|
173
173
|
- [Preserve important context, add new if needed]
|
|
174
174
|
|
|
175
|
-
Keep each section concise. Preserve exact file paths, function names, and error messages.`,
|
|
175
|
+
Keep each section concise. Preserve exact file paths, function names, and error messages.`,jA=`The messages above are earlier context from an ongoing conversation. Later messages are stored separately and do not need to be reconstructed.
|
|
176
176
|
|
|
177
177
|
Create a concise checkpoint of the user's request and the progress shown above. This checkpoint will be placed before the later messages so the conversation can continue with the necessary context.
|
|
178
178
|
|
|
@@ -185,15 +185,15 @@ Create a concise checkpoint of the user's request and the progress shown above.
|
|
|
185
185
|
## Context Needed to Continue
|
|
186
186
|
- [Information from these messages needed to understand the later work]
|
|
187
187
|
|
|
188
|
-
Only summarize information explicitly present above. Do not infer or recreate later messages.`;function
|
|
188
|
+
Only summarize information explicitly present above. Do not infer or recreate later messages.`;function MA(e,t){if(e.stopReason===`error`){let n=e.errorMessage;return`${t} failed: ${n!==void 0&&n.length>0?n:`Unknown error`}`}return e.stopReason===`length`?`${t} failed: generation hit the token cap and the summary is incomplete`:e.content.some(e=>e.type===`toolCall`)?`${t} attempted to call a tool`:void 0}var NA=Op(j.check(jm(1),V(160)),F([`none`,`read`,`write`])).check(R(e=>Object.keys(e).length<=256)),PA=E(N({version:B.check(z(0),mm(2**53-1)),grants:NA}),{onExcessProperty:`error`}),FA=E(Xm(NA)),IA=hp(Xm(NA)),LA=E(N({version:B,grants_json:j}));function RA(e){e.sql.exec(`CREATE TABLE IF NOT EXISTS session_tool_grants (
|
|
189
189
|
session_id TEXT PRIMARY KEY,
|
|
190
190
|
version INTEGER NOT NULL,
|
|
191
191
|
grants_json TEXT NOT NULL
|
|
192
|
-
)`)}function
|
|
192
|
+
)`)}function zA(e,t,n){let r=PA(n);if(xt(r))throw new H(`contract`,`invalid`,`Session grants delivery is invalid`);let i=IA(r.success.grants),a=BA(e,t);if(a!==void 0){if(r.success.version<a.version)throw new H(`contract`,`conflict`,`Session grants delivery is older than the stored delivery`);if(r.success.version===a.version&&a.grantsJson===i)return`unchanged`}return e.sql.exec(`INSERT INTO session_tool_grants (session_id, version, grants_json)
|
|
193
193
|
VALUES (?, ?, ?)
|
|
194
194
|
ON CONFLICT(session_id) DO UPDATE SET
|
|
195
|
-
version = excluded.version, grants_json = excluded.grants_json`,t,r.success.version,i),`applied`}function
|
|
196
|
-
SELECT ?, version, grants_json FROM session_tool_grants WHERE session_id = ?`,n,t)}var
|
|
195
|
+
version = excluded.version, grants_json = excluded.grants_json`,t,r.success.version,i),`applied`}function BA(e,t){let[n]=e.sql.exec(`SELECT version, grants_json FROM session_tool_grants WHERE session_id = ?`,t).toArray();if(n===void 0)return;let r=LA(n);if(xt(r))throw new H(`store`,`unavailable`,`Stored Session grants are invalid`);return{version:r.success.version,grantsJson:r.success.grants_json}}function VA(e,t){let n=BA(e,t);if(n===void 0)return null;let r=FA(n.grantsJson);if(xt(r))throw new H(`store`,`unavailable`,`Stored Session grants are invalid`);return{version:n.version,grants:r.success}}function HA(e,t,n){e.sql.exec(`INSERT INTO session_tool_grants (session_id, version, grants_json)
|
|
196
|
+
SELECT ?, version, grants_json FROM session_tool_grants WHERE session_id = ?`,n,t)}var UA=200,WA={onExcessProperty:`error`},GA=new TextEncoder,KA=j.pipe(L(jm(1)),L(R(e=>GA.encode(e).byteLength<=256))),qA=B.pipe(L(z(0))),JA=F([0,1,2]),YA=F([`needs_you`,`running`,`errored`,`done`]),XA=F([`completed`,`failed`,`cancelled`,`outcome_unknown`,`interrupted`]),ZA=N({session_id:KA,title:I(j),created_at:qA,last_activity_at:qA,settled_at:I(qA),state:YA,tier:JA}),QA=E(ZA,WA);E(ZA.mapFields(Hf({revision:qA})),WA),E(N({revision:qA}),WA);var $A=E(N({outcome:I(XA)}),WA),ej=Xm(Ap([JA,qA,KA])),tj=E(ej),nj=hp(ej),rj=`session_id, title, created_at, last_activity_at, settled_at, state, tier`;function ij(e){return new H(`store`,`unavailable`,e)}function aj(e){switch(e){case`needs_you`:return 0;case`running`:return 1;case`errored`:case`done`:return 2}}function oj(e,t,n){if(n)return`needs_you`;if(e.state!==`idle`)return`running`;switch(t){case`failed`:case`interrupted`:case`outcome_unknown`:return`errored`;case`completed`:case`cancelled`:case null:return`done`}}function sj(e){e.sql.exec(`
|
|
197
197
|
CREATE TABLE IF NOT EXISTS session_inbox (
|
|
198
198
|
session_id TEXT PRIMARY KEY REFERENCES sessions(id),
|
|
199
199
|
title TEXT,
|
|
@@ -223,34 +223,34 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
223
223
|
session_id TEXT PRIMARY KEY,
|
|
224
224
|
revision INTEGER NOT NULL
|
|
225
225
|
) STRICT
|
|
226
|
-
`),e.sql.exec(`CREATE INDEX IF NOT EXISTS idx_session_inbox_tombstones_revision ON session_inbox_tombstones(revision)`)}function
|
|
226
|
+
`),e.sql.exec(`CREATE INDEX IF NOT EXISTS idx_session_inbox_tombstones_revision ON session_inbox_tombstones(revision)`)}function cj(e){e.sql.exec(`UPDATE session_inbox_clock SET revision = revision + 1 WHERE singleton = 1`)}var lj=`(SELECT revision FROM session_inbox_clock WHERE singleton = 1)`;function uj(e,t){let n=t.title===void 0?``:t.title,r=t.title===void 0?0:1;cj(e),e.sql.exec(`INSERT INTO session_inbox
|
|
227
227
|
(session_id, title, created_at, last_activity_at, settled_at, outcome,
|
|
228
228
|
state, tier, revision)
|
|
229
229
|
SELECT id, ?, created_at, COALESCE(?, created_at), NULL, NULL, 'done', 2,
|
|
230
|
-
${
|
|
230
|
+
${lj}
|
|
231
231
|
FROM sessions
|
|
232
232
|
WHERE id = ?
|
|
233
233
|
ON CONFLICT (session_id) DO UPDATE SET
|
|
234
234
|
title = CASE WHEN ? = 1 THEN excluded.title ELSE title END,
|
|
235
235
|
last_activity_at = MAX(last_activity_at, excluded.last_activity_at),
|
|
236
|
-
revision = excluded.revision`,n,t.activityAt??null,t.sessionId,r)}function
|
|
237
|
-
VALUES (?, ${
|
|
238
|
-
ON CONFLICT (session_id) DO UPDATE SET revision = excluded.revision`,t)}function
|
|
239
|
-
SET outcome = ?, state = ?, tier = ?, revision = ${
|
|
236
|
+
revision = excluded.revision`,n,t.activityAt??null,t.sessionId,r)}function dj(e,t){cj(e),e.sql.exec(`INSERT INTO session_inbox_tombstones (session_id, revision)
|
|
237
|
+
VALUES (?, ${lj})
|
|
238
|
+
ON CONFLICT (session_id) DO UPDATE SET revision = excluded.revision`,t)}function fj(e,t,n){let r=e.sql.exec(`SELECT outcome FROM session_inbox WHERE session_id = ?`,t.queue).toArray()[0];if(r===void 0)return;let i=$A(r);if(i._tag===`Failure`)throw ij(`Stored inbox row is invalid`);let a=t.settled?.outcome??i.success.outcome,o=oj(t.head,a,YD(e,t.queue));cj(e),e.sql.exec(`UPDATE session_inbox
|
|
239
|
+
SET outcome = ?, state = ?, tier = ?, revision = ${lj},
|
|
240
240
|
settled_at = CASE WHEN ? = 1 THEN ? ELSE settled_at END,
|
|
241
241
|
last_activity_at = MAX(last_activity_at, ?)
|
|
242
|
-
WHERE session_id = ?`,a,o,
|
|
242
|
+
WHERE session_id = ?`,a,o,aj(o),t.settled===void 0?0:1,n,n,t.queue)}function pj(e,t,n){let r=e.sql.exec(`SELECT outcome FROM session_inbox WHERE session_id = ?`,t).toArray()[0];if(r===void 0)return;let i=$A(r);if(i._tag===`Failure`)throw ij(`Stored inbox row is invalid`);let a=oj(n,i.success.outcome,YD(e,t));cj(e),e.sql.exec(`UPDATE session_inbox SET state = ?, tier = ?, revision = ${lj} WHERE session_id = ?`,a,aj(a),t)}function mj(e){if(e.title===null)return Object.freeze({sessionId:e.session_id,state:`unavailable`});let t={sessionId:e.session_id,title:e.title,createdAt:e.created_at,lastActivityAt:e.last_activity_at,state:e.state};return Object.freeze(e.settled_at===null?t:{...t,settledAt:e.settled_at})}function hj(e){let t=tj(e);if(t._tag===`Failure`)throw new H(`contract`,`invalid`,`Session cursor is invalid`);return t.success}function gj(e,t){let n=t===void 0?void 0:hj(t),r=n===void 0?e.sql.exec(`SELECT ${rj} FROM session_inbox
|
|
243
243
|
ORDER BY tier ASC, last_activity_at DESC, session_id ASC
|
|
244
|
-
LIMIT ?`,
|
|
244
|
+
LIMIT ?`,UA).toArray():e.sql.exec(`SELECT ${rj} FROM session_inbox
|
|
245
245
|
WHERE tier > ?
|
|
246
246
|
OR (tier = ? AND last_activity_at < ?)
|
|
247
247
|
OR (tier = ? AND last_activity_at = ? AND session_id > ?)
|
|
248
248
|
ORDER BY tier ASC, last_activity_at DESC, session_id ASC
|
|
249
|
-
LIMIT ?`,n[0],n[0],n[1],n[0],n[1],n[2],
|
|
249
|
+
LIMIT ?`,n[0],n[0],n[1],n[0],n[1],n[2],UA).toArray(),i=[],a;for(let e of r){let t=QA(e);if(t._tag===`Failure`)throw ij(`Stored inbox row is invalid`);let n=t.success;a=[n.tier,n.last_activity_at,n.session_id],i.push(mj(n))}return{sessions:i,next:r.length===UA&&a!==void 0?nj(a):void 0}}var _j=Ph({family:`session`,version:1,kinds:{session:{prefix:`session`},work:{prefix:`session_work`},fact:{prefix:`session_fact`},receipt:{prefix:`session_receipt`}}});function vj(e){let t=[...e].reverse().find(({entry:e})=>e.kind===`message`&&e.value.role===`assistant`);if(t?.entry.kind!==`message`||t.entry.value.role!==`assistant`)return;let n=e.filter(({sequence:e})=>e>t.sequence);if(n.some(({entry:e})=>e.kind===`turn_started`||e.kind===`compaction`&&e.data.resumesRun||e.kind===`live_retry`&&e.event.type===`auto_retry_start`))return;let r=n.flatMap(({entry:e})=>e.kind===`message`&&e.value.role===`toolResult`?[e.value]:[]),i=t.entry.value.content.flatMap(e=>{if(e.type!==`toolCall`)return[];let t=[...n].reverse().find(({entry:t})=>t.kind===`tool_outcome`&&t.call.id===e.id)?.entry;if(t?.kind===`tool_outcome`)return[{call:e,state:`completed`,result:t.data===void 0?t.result:{...t.result,data:t.data},message:r.find(t=>t.toolCallId===e.id)}];let i=[...n].reverse().find(({entry:t})=>t.kind===`tool_intent`&&t.call.id===e.id)?.entry;return[i?.kind===`tool_intent`?{call:e,state:`started`,replay:i.replay}:{call:e,state:`pending`}]});return{message:t.entry.value,tools:i}}function yj(e,t){let n=new Set(e.flatMap(({entry:e})=>e.kind===`run_terminal`?[e.workId]:[])),r=new Set,i=new Map;for(let a of e){let e=a.entry;if(e.kind===`message`&&(e.value.role===`assistant`&&i.set(e.workId,a.id),(n.has(e.workId)||e.workId===t)&&(e.value.role!==`assistant`||e.value.stopReason!==`error`&&e.value.stopReason!==`aborted`)&&r.add(a.id)),e.kind===`compaction`&&e.data.resumesRun||e.kind===`live_retry`&&e.event.type===`auto_retry_start`){let t=i.get(e.workId);t!==void 0&&r.delete(t)}}return r}function bj(e){let t=[...e].reverse(),n=t.find(({entry:e})=>e.kind===`run_terminal`);if(n?.entry.kind!==`run_terminal`||e.some(({sequence:e,entry:t})=>e>n.sequence&&(t.kind===`run_started`||t.kind===`compaction`&&t.data.resumesRun)))return;if(n.entry.outcome===`cancelled`)return`cancelled`;if(n.entry.outcome!==`failed`)return;let r=t.find(({entry:e})=>e.kind===`turn_started`),i=t.find(({sequence:e,entry:t})=>t.kind===`message`&&t.value.role===`assistant`&&e>(r?.sequence??0));return i?.entry.kind===`message`&&i.entry.value.role===`assistant`&&i.entry.value.stopReason===`error`&&!e.some(({sequence:e,entry:t})=>e>i.sequence&&t.kind===`live_retry`&&t.event.type===`auto_retry_start`)?void 0:`failed`}var xj={onExcessProperty:`error`},Sj=new TextEncoder,Z=j.pipe(L(jm(1)),L(R(e=>Sj.encode(e).byteLength<=256))),Cj=B.pipe(L(fm(0))),wj=B.pipe(L(z(0))),Tj=N({id:Z,leaf_id:I(Z)}),Ej=N({session_id:Z}),Dj=N({id:Z,leaf_id:I(Z),created_at:wj,updated_at:wj,metadata_json:I(j)}),Oj=Xm(N({title:Gv})),kj=E(Oj,xj),Aj=hp(Oj),jj=N({id:Z}),Mj=N({version:B,protocol:A(`shiitake.extension/v0`)}),Nj=N({name:Z}),Pj=N({id:Z,session_id:Z,parent_id:I(Z),sequence:Cj,type:j,role:I(F([`user`,`assistant`,`tool_result`])),state:F([`complete`,`streaming`]),request_id:I(Z),work_id:I(Z),data_json:j,timestamp:wj,completed_at:I(wj),damaged:F([0,1])}),Fj=N({id:Z,session_id:Z,sequence:Cj,request_id:Z,work_id:Z,data_json:j,timestamp:wj,origin_kind:F([`user`,`extension`]),origin_id:I(Z),origin_correlation:I(Z)}),Ij=N({kind:A(`extension`),extensionId:Z,correlation:I(Z)}),Lj=P([N({kind:A(`user`)}),Ij]),Rj=E(Lj,xj),zj=nh(Lj),Bj=e=>[`id`,`session_id`,`sequence`,`request_id`,`work_id`,`data_json`,`timestamp`,`origin_kind`,`origin_id`,`origin_correlation`].map(t=>e+t).join(`, `),Vj=N({next_sequence:Cj}),Hj=N({present:A(1)}),Uj=E(Ej,xj),Wj=E(Dj,xj),Gj=E(jj,xj),Kj=E(Mj,xj),qj=E(Nj,xj),Jj=E(N({candidate_id:I(Z),path_count:B.pipe(L(fm(0))),root_count:B.pipe(L(z(0))),missing_parent_count:B.pipe(L(z(0))),leaf_state:F([`complete`,`streaming`])}),xj),Yj=E(Pj,xj),Xj=E(Fj,xj),Zj=E(Vj,xj),Qj=E(Hj,xj);function $j(e){return`${[`id`,`session_id`,`parent_id`,`sequence`,`type`,`role`,`state`,`request_id`,`work_id`,`data_json`,`timestamp`,`completed_at`].map(t=>`${e}.${t}`).join(`, `)},
|
|
250
250
|
EXISTS (SELECT 1 FROM session_lineage_damage AS damage
|
|
251
|
-
WHERE damage.session_id = ${e}.session_id) AS damaged`}var
|
|
251
|
+
WHERE damage.session_id = ${e}.session_id) AS damaged`}var eM=$j(`session_entries`);function tM(e,t){return t===void 0?e:{...e,meta:t}}function nM(e,t){if(gM(e,t)===void 0)return;let n=e.sql.exec(`SELECT id, leaf_id, created_at, updated_at, metadata_json
|
|
252
252
|
FROM sessions
|
|
253
|
-
WHERE id = ?`,t).toArray()[0];if(n===void 0)return;let r=
|
|
253
|
+
WHERE id = ?`,t).toArray()[0];if(n===void 0)return;let r=Wj(n);if(r._tag===`Failure`)throw Q(`Stored Session summary row is invalid`);let i=oM(e,t,r.success),a=r.success.metadata_json;if(a===null)return i;let o=kj(a);if(o._tag===`Failure`)throw Q(`Stored Session title is invalid`);return Object.freeze({createdAt:r.success.created_at,updatedAt:r.success.updated_at,title:o.success.title})}var rM=E(N({id:Z,sequence:Cj}),xj);function iM(e,t,n,r){let i=e.sql.exec(`SELECT command.id AS id, command.sequence AS sequence
|
|
254
254
|
FROM session_entries AS command
|
|
255
255
|
WHERE command.session_id = ? AND command.type = 'command'
|
|
256
256
|
AND command.role = 'user' AND command.state = 'complete'
|
|
@@ -261,13 +261,13 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
261
261
|
AND cancelled.type = 'cancellation'
|
|
262
262
|
AND cancelled.sequence < command.sequence
|
|
263
263
|
)
|
|
264
|
-
ORDER BY command.sequence ASC LIMIT 1`,t).toArray()[0];if(i===void 0)return null;let a=
|
|
264
|
+
ORDER BY command.sequence ASC LIMIT 1`,t).toArray()[0];if(i===void 0)return null;let a=rM(i);if(a._tag===`Failure`)throw Q(`Stored Session first prompt is invalid`);let o=a.success;return r<o.sequence?null:e.sql.exec(`SELECT 1 AS present FROM session_entries AS parent
|
|
265
265
|
WHERE parent.session_id = ? AND parent.sequence < ?
|
|
266
266
|
AND (SELECT COUNT(*) FROM session_entries AS child
|
|
267
267
|
WHERE child.parent_id = parent.id
|
|
268
268
|
AND child.session_id = parent.session_id
|
|
269
269
|
AND child.state = 'complete') > 1
|
|
270
|
-
LIMIT 1`,t,o.sequence).toArray()[0]===void 0?o.id:
|
|
270
|
+
LIMIT 1`,t,o.sequence).toArray()[0]===void 0?o.id:aM(e,t,n)}function aM(e,t,n){let r=Jj(e.sql.exec(`WITH RECURSIVE branch (id, parent_id, sequence, type, role, state, work_id) AS (
|
|
271
271
|
SELECT id, parent_id, sequence, type, role, state, work_id
|
|
272
272
|
FROM session_entries
|
|
273
273
|
WHERE session_id = ? AND id = ?
|
|
@@ -297,30 +297,30 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
297
297
|
SELECT 1 FROM session_entries AS parent
|
|
298
298
|
WHERE parent.session_id = ? AND parent.id = child.parent_id
|
|
299
299
|
)) AS missing_parent_count,
|
|
300
|
-
(SELECT state FROM branch WHERE id = ?) AS leaf_state`,t,n,t,t,n).one());if(r._tag===`Failure`||r.success.leaf_state!==`complete`||r.success.root_count!==1||r.success.missing_parent_count!==0)throw Q(`Stored Session summary lineage is invalid`);return r.success.candidate_id}function
|
|
300
|
+
(SELECT state FROM branch WHERE id = ?) AS leaf_state`,t,n,t,t,n).one());if(r._tag===`Failure`||r.success.leaf_state!==`complete`||r.success.root_count!==1||r.success.missing_parent_count!==0)throw Q(`Stored Session summary lineage is invalid`);return r.success.candidate_id}function oM(e,t,n){if(n.leaf_id===null)return Object.freeze({createdAt:n.created_at,updatedAt:n.updated_at,title:``});let r=_M(e,t,n.leaf_id);if(r?.state!==`complete`)throw Q(`Stored Session summary leaf is invalid`);let i=iM(e,t,n.leaf_id,r.sequence),a=i===null?void 0:_M(e,t,i)?.entry,o=a===void 0?void 0:bk(a);if(o!==void 0)return Object.freeze({createdAt:n.created_at,updatedAt:n.updated_at,title:Array.from(iP(o.message.content)?o.message.content.filter(e=>e.type===`text`).map(e=>e.text).join(``)||`Image prompt`:o.message.content).slice(0,120).join(``)})}function sM(e,t){try{return nM(e,t)?.title??``}catch(e){if(e instanceof H&&e.cause===`unavailable`)return null;throw e}}function Q(e){return new H(`store`,`unavailable`,e)}function cM(e){return new H(`store`,`incompatible`,e)}function lM(e){return e.kind===`command`||e.kind===`cancellation`||e.kind===`operator`?e.requestId:null}function uM(e){return e.kind===`command`?yk(e)?null:`user`:e.kind===`operator`?e.author===`party`?`user`:`assistant`:e.kind===`message_start`?e.role===`toolResult`?`tool_result`:e.role:e.kind===`message`?e.value.role===`toolResult`?`tool_result`:e.value.role:null}function dM(e,t){return e.kind===t.kind&&e.value===t.value&&e.parent?.kind===t.parent?.kind&&e.parent?.value===t.parent?.value}function fM(e,t){let n=Yj(t);if(n._tag===`Failure`)throw Q(`Stored Session entry row is invalid`);let r=n.success;if(r.damaged===1)throw rN(e,r.session_id);let i=Tk(r.data_json);if(i._tag===`Failure`)throw Q(`Stored Session entry data is invalid`);let a=i.success;if(r.type!==a.kind||r.work_id!==a.workId||r.request_id!==lM(a)||r.role!==uM(a))throw Q(`Stored Session entry columns disagree with its data`);return Object.freeze({id:r.id,sessionId:r.session_id,parentId:r.parent_id,sequence:r.sequence,state:r.state,timestamp:r.timestamp,completedAt:r.completed_at,entry:a})}function pM(e){let t=Xj(e);if(t._tag===`Failure`)throw Q(`Stored command admission row is invalid`);let n=t.success,r=Tk(n.data_json);if(r._tag===`Failure`||r.success.kind!==`command`)throw Q(`Stored command admission data is invalid`);let i=r.success;if(n.request_id!==i.requestId||n.work_id!==i.workId||n.id!==i.receiptId||n.id!==i.workId||n.timestamp!==xk(i))throw Q(`Stored command admission columns disagree with its data`);let a=Rj(n.origin_kind===`user`?{kind:`user`}:{kind:`extension`,extensionId:n.origin_id,correlation:n.origin_correlation});if(a._tag===`Failure`||n.origin_kind===`user`&&(n.origin_id!==null||n.origin_correlation!==null))throw Q(`Stored command admission origin is invalid`);return Object.freeze({id:n.id,sessionId:n.session_id,sequence:n.sequence,timestamp:n.timestamp,entry:i,origin:a.success})}function mM(e,t){return gM(e,t)!==void 0}var hM=E(N({...Tj.fields,damaged:F([0,1])}),xj);function gM(e,t){let n=e.sql.exec(`SELECT id, leaf_id,
|
|
301
301
|
EXISTS (SELECT 1 FROM session_lineage_damage
|
|
302
302
|
WHERE session_id = sessions.id) AS damaged
|
|
303
|
-
FROM sessions WHERE id = ?`,t).toArray()[0];if(n===void 0)return;let r=
|
|
303
|
+
FROM sessions WHERE id = ?`,t).toArray()[0];if(n===void 0)return;let r=hM(n);if(r._tag===`Failure`)throw Q(`Stored Session row is invalid`);if(r.success.damaged===1)throw rN(e,t);return Object.freeze({id:r.success.id,leaf_id:r.success.leaf_id})}function _M(e,t,n){let r=e.sql.exec(`SELECT ${eM}
|
|
304
304
|
FROM session_entries
|
|
305
|
-
WHERE session_id = ? AND id = ?`,t,n).toArray()[0];return r===void 0?void 0:
|
|
305
|
+
WHERE session_id = ? AND id = ?`,t,n).toArray()[0];return r===void 0?void 0:fM(e,r)}function vM(e,t){if(t.leaf_id===null){let n=e.sql.exec(`SELECT 1 AS present
|
|
306
306
|
FROM session_entries
|
|
307
307
|
WHERE session_id = ?
|
|
308
|
-
LIMIT 1`,t.id).toArray()[0];if(n===void 0)return;throw
|
|
308
|
+
LIMIT 1`,t.id).toArray()[0];if(n===void 0)return;throw Qj(n)._tag===`Failure`?Q(`Session entry presence is invalid`):Q(`Session leaf is invalid`)}let n=_M(e,t.id,t.leaf_id);if(n?.state!==`complete`)throw Q(`Session leaf is invalid`);return n}function yM(e,t){let n=e.sql.exec(`SELECT ${eM}
|
|
309
309
|
FROM session_entries
|
|
310
|
-
WHERE id = ?`,t).toArray()[0];return n===void 0?void 0:
|
|
310
|
+
WHERE id = ?`,t).toArray()[0];return n===void 0?void 0:fM(e,n)}function bM(e,t,n){let[r,i]=`id`in n?[`id`,n.id]:`requestId`in n?[`request_id`,n.requestId]:[`work_id`,n.workId],a=e.sql.exec(`SELECT ${Bj(``)}
|
|
311
311
|
FROM session_command_admissions
|
|
312
|
-
WHERE session_id = ? AND ${r} = ?`,t,i).toArray()[0];return a===void 0?void 0:
|
|
312
|
+
WHERE session_id = ? AND ${r} = ?`,t,i).toArray()[0];return a===void 0?void 0:pM(a)}var xM=`FROM session_command_admissions AS a
|
|
313
313
|
WHERE a.session_id = ?
|
|
314
314
|
AND NOT EXISTS (
|
|
315
315
|
SELECT 1 FROM session_entries AS e
|
|
316
316
|
WHERE e.session_id = a.session_id AND e.work_id = a.work_id
|
|
317
317
|
AND e.type IN ('command', 'cancellation', 'run_terminal', 'work_terminal')
|
|
318
|
-
)`,
|
|
318
|
+
)`,SM=cp(N({identity:I(j)}));function CM(e,t,n){let{identity:r}=SM(e.sql.exec(`SELECT json_extract(?, ?) AS identity`,JSON.stringify(n??null),t).one());if(r===null||r.length===0)throw new H(`runtime`,`rejected`,`Request author is required`);return{path:t,value:r}}function wM(e,t,n,r){let i=MM(e,t,n);if(i!==void 0&&CM(e,r.path,i.entry.meta).value!==r.value)throw new H(`runtime`,`rejected`,`Message author does not match`)}function TM(e,t,n){let r=e.sql.exec(`SELECT ${Bj(`a.`)} ${xM}
|
|
319
319
|
AND json_extract(a.data_json, '$.work') IS NULL
|
|
320
320
|
AND a.origin_kind = 'user'
|
|
321
321
|
AND (? IS NULL OR json_extract(json_extract(a.data_json, '$.meta'), ?) = ?)
|
|
322
|
-
ORDER BY a.sequence DESC LIMIT 1`,t,n?.path??null,n?.path??null,n?.value??null).toArray()[0];return r===void 0?void 0:
|
|
323
|
-
ORDER BY a.sequence ASC LIMIT ?`,t,n).toArray().map(
|
|
322
|
+
ORDER BY a.sequence DESC LIMIT 1`,t,n?.path??null,n?.path??null,n?.value??null).toArray()[0];return r===void 0?void 0:pM(r)}var EM=cp(N({total:B.check(z(0))}));function DM(e,t,n,r=`all`){let i=r===`prompts`?`AND json_extract(a.data_json, '$.work') IS NULL`:``,a=EM(e.sql.exec(`SELECT COUNT(*) AS total ${xM} ${i}`,t).one()).total;return{commands:e.sql.exec(`SELECT ${Bj(`a.`)} ${xM} ${i}
|
|
323
|
+
ORDER BY a.sequence ASC LIMIT ?`,t,n).toArray().map(pM),total:a}}function OM(e,t,n,r,i=200){return e.sql.exec(`SELECT ${Bj(`a.`)}
|
|
324
324
|
FROM session_command_admissions AS a
|
|
325
325
|
WHERE a.session_id = ?
|
|
326
326
|
AND json_extract(a.data_json, '$.delivery') = ?
|
|
@@ -330,22 +330,22 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
330
330
|
WHERE e.session_id = a.session_id AND e.work_id = a.work_id
|
|
331
331
|
AND e.type IN ('command', 'run_terminal', 'work_terminal')
|
|
332
332
|
)
|
|
333
|
-
ORDER BY a.sequence ASC LIMIT ?`,t,n,r??null,r??null,i).toArray().map(
|
|
333
|
+
ORDER BY a.sequence ASC LIMIT ?`,t,n,r??null,r??null,i).toArray().map(pM)}function kM(e,t,n){return OM(e,t,`steer`,n,1).length>0}function AM(e,t,n,r){return e.transactionSync(()=>OM(e,t,n,r).map(n=>{let r=bk(_M(e,t,n.id)?.entry??fN(e,{sessionId:t,id:n.id,entry:n.entry}).entry);if(r===void 0)throw Q(`Session control admission is invalid`);return{workId:r.workId,requestId:r.requestId,message:Ck(r)}}))}function jM(e,t){e.transactionSync(()=>{let n=e.sql.exec(`SELECT ${Bj(`a.`)}
|
|
334
334
|
FROM session_command_admissions AS a
|
|
335
335
|
WHERE a.session_id = ?
|
|
336
336
|
AND json_extract(a.data_json, '$.delivery') = 'steer'
|
|
337
337
|
AND json_extract(a.data_json, '$.targetWorkId') = ?
|
|
338
|
-
ORDER BY a.sequence ASC`,t.sessionId,t.parentWorkId).toArray().map(
|
|
338
|
+
ORDER BY a.sequence ASC`,t.sessionId,t.parentWorkId).toArray().map(pM);for(let r of n){if(e.sql.exec(`SELECT 1 AS present FROM session_entries WHERE session_id = ? AND work_id = ? AND type IN ('run_terminal', 'work_terminal') LIMIT 1`,t.sessionId,r.entry.workId).toArray()[0]!==void 0)continue;if(_M(e,t.sessionId,r.id)===void 0){t.enqueue({jobId:r.entry.workId,sessionId:t.sessionId,commandFactId:r.id});continue}let n=t.outcome===`failed`||t.outcome===`interrupted`?t.diagnostic:void 0,i={kind:`work_terminal`,workId:r.entry.workId,outcome:t.outcome};n!==void 0&&(i={...i,diagnostic:n}),fN(e,{sessionId:t.sessionId,id:_j.fact.generate(),entry:i})}})}function MM(e,t,n){return bM(e,t,{id:n})}function NM(e,t,n){return bM(e,t,{workId:n})}function PM(e,t,n){return bM(e,t,{requestId:n})}function FM(e,t,n){return gM(e,t),Object.freeze(e.sql.exec(`SELECT ${eM}
|
|
339
339
|
FROM session_entries
|
|
340
340
|
WHERE session_id = ? AND work_id = ?
|
|
341
|
-
ORDER BY sequence ASC`,t,n).toArray().map(t=>
|
|
341
|
+
ORDER BY sequence ASC`,t,n).toArray().map(t=>fM(e,t)))}function IM(e,t,n){let r=e.sql.exec(`SELECT ${eM}
|
|
342
342
|
FROM session_entries
|
|
343
343
|
WHERE session_id = ? AND work_id = ? AND type = 'live_retry'
|
|
344
344
|
ORDER BY sequence DESC
|
|
345
|
-
LIMIT 1`,t,n).toArray()[0];if(r===void 0)return;let i=
|
|
345
|
+
LIMIT 1`,t,n).toArray()[0];if(r===void 0)return;let i=fM(e,r);if(i.entry.kind!==`live_retry`)throw Q(`Stored live retry entry is invalid`);return{event:i.entry.event,timestamp:i.timestamp}}function LM(e,t,n,r){return e.sql.exec(`SELECT 1 FROM session_entries INDEXED BY idx_session_entries_successful_tool
|
|
346
346
|
WHERE session_id = ? AND work_id = ? AND type = 'tool_outcome'
|
|
347
347
|
AND json_extract(data_json, '$.result.isError') = 0
|
|
348
|
-
AND json_extract(data_json, '$.call.id') = ? LIMIT 1`,t,n,r).toArray().length>0}function
|
|
348
|
+
AND json_extract(data_json, '$.call.id') = ? LIMIT 1`,t,n,r).toArray().length>0}function RM(e,t,n){let r=e.sql.exec(`SELECT ${$j(`intent`)}
|
|
349
349
|
FROM session_entries AS intent
|
|
350
350
|
WHERE intent.session_id = ? AND intent.work_id = ?
|
|
351
351
|
AND intent.type = 'tool_intent'
|
|
@@ -358,9 +358,9 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
358
358
|
json_extract(intent.data_json, '$.toolCall.value')
|
|
359
359
|
)
|
|
360
360
|
ORDER BY intent.sequence DESC
|
|
361
|
-
LIMIT 1`,t,n).toArray()[0];if(r===void 0)return;let i=
|
|
361
|
+
LIMIT 1`,t,n).toArray()[0];if(r===void 0)return;let i=fM(e,r);if(i.entry.kind!==`tool_intent`)throw Q(`Stored tool intent is invalid`);return i.entry.call.name}function zM(e,t){let n=Zj(e.sql.exec(`SELECT COALESCE(MAX(sequence), 0) + 1 AS next_sequence
|
|
362
362
|
FROM session_entries
|
|
363
|
-
WHERE session_id = ?`,t).one());if(n._tag===`Failure`)throw Q(`Next Session sequence is invalid`);return n.success.next_sequence}function
|
|
363
|
+
WHERE session_id = ?`,t).one());if(n._tag===`Failure`)throw Q(`Next Session sequence is invalid`);return n.success.next_sequence}function BM(e,t){let n=Zj(e.sql.exec(`SELECT COALESCE(MAX(sequence), 0) + 1 AS next_sequence
|
|
364
364
|
FROM (
|
|
365
365
|
SELECT sequence
|
|
366
366
|
FROM session_command_admissions
|
|
@@ -369,9 +369,9 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
369
369
|
SELECT sequence
|
|
370
370
|
FROM session_entries
|
|
371
371
|
WHERE session_id = ? AND type = 'command'
|
|
372
|
-
)`,t,t).one());if(n._tag===`Failure`)throw Q(`Next command admission sequence is invalid`);return n.success.next_sequence}function
|
|
372
|
+
)`,t,t).one());if(n._tag===`Failure`)throw Q(`Next command admission sequence is invalid`);return n.success.next_sequence}function VM(e,t){let n=gM(e,t);if(n!==void 0)return n;let r=Date.now();e.sql.exec(`INSERT INTO sessions
|
|
373
373
|
(id, cwd, parent_session, leaf_id, created_at, updated_at, metadata_json)
|
|
374
|
-
VALUES (?, '/', NULL, NULL, ?, ?, NULL)`,t,r,r),
|
|
374
|
+
VALUES (?, '/', NULL, NULL, ?, ?, NULL)`,t,r,r),uj(e,{sessionId:t,activityAt:r,title:``});let i=gM(e,t);if(i===void 0)throw Q(`Created Session row is unavailable`);return i}function HM(e,t,n){return e.transactionSync(()=>UM(e,t,n))}function UM(e,t,n){let r=e.sql.exec(`SELECT session_id FROM session_creation_receipts WHERE request_id = ?`,t).toArray()[0];if(r!==void 0){let e=Uj(r);if(e._tag===`Failure`)throw Q(`Session creation receipt is invalid`);return e.success.session_id}n();let i=_j.session.generate();return VM(e,i),e.sql.exec(`INSERT INTO session_creation_receipts (request_id, session_id) VALUES (?, ?)`,t,i),i}function WM(e,t){return e.transactionSync(()=>{if(!(e.sql.exec(`SELECT id FROM sessions WHERE id = ?`,t.sessionId).toArray().length>0))return!1;t.assertIdleSession(t.sessionId),t.recordInboxDeletion(t.sessionId);for(let n of[`DELETE FROM session_command_admissions WHERE session_id = ?`,`DELETE FROM session_attention WHERE session_id = ?`,`DELETE FROM session_tool_grants WHERE session_id = ?`,`DELETE FROM session_inbox WHERE session_id = ?`,`DELETE FROM session_creation_receipts WHERE session_id = ?`,`DELETE FROM sessions WHERE id = ?`,`DELETE FROM session_entries WHERE session_id = ?`,`DELETE FROM session_lineage_damage WHERE session_id = ?`])e.sql.exec(n,t.sessionId);return!0})}var GM=3,KM=`shiitake.extension/v0`;function qM(e,t){let n=e.sql.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?`,t).toArray()[0];if(n===void 0)return!1;if(qj(n)._tag===`Failure`)throw Q(`Store catalog row is invalid`);return!0}function JM(e){if(!qM(e,`woodstock_schema`))return qM(e,`sessions`)?`unmarked`:`fresh`;if(!e.sql.exec(`PRAGMA table_info(woodstock_schema)`).toArray().some(e=>e.name===`protocol`))return`unmarked`;let t=e.sql.exec(`SELECT version, protocol FROM woodstock_schema`).toArray();if(t.length!==1)return`unmarked`;let n=Kj(t[0]);return n._tag===`Success`&&n.success.version===GM?`v0`:`unmarked`}function YM(e){let t=JM(e);if(t!==`v0`){if(t===`unmarked`)throw cM(`Woodstock store has no current v0 schema marker; incompatible storage requires explicit host custody. To reset, stop the owning host before resetting a local store, then remove its database file and the file's .owner.sqlite sidecar. Reset discards that store's data. For the Hub, a Hub Agent is erased only with its Team; Team erasure is destructive and separately authorized, never a routine single-Agent repair. No migration runs.`);e.sql.exec(`CREATE TABLE woodstock_schema (version INTEGER NOT NULL, protocol TEXT NOT NULL)`),e.sql.exec(`INSERT INTO woodstock_schema (version, protocol) VALUES (?, ?)`,GM,KM)}}function XM(e){e.sql.exec(`
|
|
375
375
|
CREATE TABLE IF NOT EXISTS session_entries (
|
|
376
376
|
id TEXT PRIMARY KEY,
|
|
377
377
|
session_id TEXT NOT NULL,
|
|
@@ -387,9 +387,9 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
387
387
|
completed_at INTEGER,
|
|
388
388
|
UNIQUE (session_id, sequence)
|
|
389
389
|
)
|
|
390
|
-
`)}var
|
|
390
|
+
`)}var ZM=[`session_entries_lineage_insert`,`session_entries_lineage_update`,`session_entries_lineage_delete`,`session_entries_damaged_session`,`session_entries_lineage_replace`,`session_entries_lineage_replace_position`],QM=E(N({installed:B.pipe(L(z(0)))}),xj),$M=E(N({session_id:j}),xj),eN=`Woodstock Session holds a broken lineage; a store never repairs itself — delete this Session (deleteSession), or reset the owning store`,tN=E(N({damaged:B.pipe(L(fm(0))),first:j}),xj),nN=class extends H{store;sessionId;constructor(e,t,n){super(`store`,`unavailable`,n),this.store=e,this.sessionId=t}get diagnostic(){return`${this.store}: Woodstock Session ${this.sessionId} holds a broken lineage; delete it with deleteSession("${this.sessionId}"), or reset the owning store`}};function rN(e,t){let n=e.storeName??`Woodstock store`;return new nN(n,t,`${n}: ${aN(e,t)}`)}function iN(e,t){return e.sql.exec(`SELECT session_id FROM session_lineage_damage WHERE session_id = ?`,t).toArray().length>0}function aN(e,t){let n=tN(e.sql.exec(`SELECT COUNT(*) AS damaged, MIN(session_id) AS first FROM session_lineage_damage`).one());if(n._tag===`Failure`)throw Q(`Stored Session lineage damage is invalid`);let{damaged:r,first:i}=n.success;return`Woodstock Session ${t} holds a broken lineage (this store has ${String(r)} damaged Session${r===1?``:`s`}, first ${i}); a store never repairs itself — delete this Session with deleteSession("${t}"), or reset the owning store: for a Durable Object, erase all of its storage (DurableObjectStorage.deleteAll(); a Hub Agent is erased only with its Team, POST /operator/teams/:teamId/erasure-durable-objects); for a local store, remove its file and the file's .owner.sqlite sidecar`}function oN(e){e.sql.exec(`CREATE TABLE IF NOT EXISTS session_lineage_damage (session_id TEXT PRIMARY KEY)`);let t=QM(e.sql.exec(`SELECT COUNT(*) AS installed FROM sqlite_master
|
|
391
391
|
WHERE type = 'trigger'
|
|
392
|
-
AND name IN (SELECT value FROM json_each(?))`,JSON.stringify(
|
|
392
|
+
AND name IN (SELECT value FROM json_each(?))`,JSON.stringify(ZM)).one());if(t._tag===`Failure`)throw Q(`Stored Session lineage guards are invalid`);if(t.success.installed!==ZM.length){let t=e.sql.exec(`SELECT child.session_id AS session_id
|
|
393
393
|
FROM session_entries AS child
|
|
394
394
|
LEFT JOIN session_entries AS parent ON parent.id = child.parent_id
|
|
395
395
|
WHERE child.parent_id IS NOT NULL
|
|
@@ -400,7 +400,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
400
400
|
UNION
|
|
401
401
|
SELECT session_id FROM session_entries
|
|
402
402
|
WHERE parent_id IS NULL AND state = 'complete'
|
|
403
|
-
GROUP BY session_id HAVING COUNT(*) > 1`).toArray().map(e=>{let t
|
|
403
|
+
GROUP BY session_id HAVING COUNT(*) > 1`).toArray().map(e=>{let t=$M(e);if(t._tag===`Failure`)throw Q(`Stored Session lineage audit is invalid`);return t.success.session_id});for(let n of t)e.sql.exec(`INSERT OR IGNORE INTO session_lineage_damage (session_id) VALUES (?)`,n),uj(e,{sessionId:n,title:null})}e.sql.exec(`
|
|
404
404
|
CREATE TRIGGER IF NOT EXISTS session_entries_lineage_replace
|
|
405
405
|
BEFORE INSERT ON session_entries
|
|
406
406
|
WHEN EXISTS (
|
|
@@ -430,7 +430,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
430
430
|
WHEN EXISTS (
|
|
431
431
|
SELECT 1 FROM session_lineage_damage WHERE session_id = NEW.session_id)
|
|
432
432
|
BEGIN
|
|
433
|
-
SELECT RAISE(ABORT, '${
|
|
433
|
+
SELECT RAISE(ABORT, '${eN}');
|
|
434
434
|
END
|
|
435
435
|
`),e.sql.exec(`
|
|
436
436
|
CREATE TRIGGER IF NOT EXISTS session_entries_lineage_insert
|
|
@@ -465,7 +465,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
465
465
|
BEGIN
|
|
466
466
|
SELECT RAISE(ABORT, 'Session entry still has children');
|
|
467
467
|
END
|
|
468
|
-
`)}function
|
|
468
|
+
`)}function sN(e){e.transactionSync(()=>{YM(e),e.sql.exec(`
|
|
469
469
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
470
470
|
id TEXT PRIMARY KEY,
|
|
471
471
|
cwd TEXT NOT NULL,
|
|
@@ -475,7 +475,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
475
475
|
updated_at INTEGER NOT NULL,
|
|
476
476
|
metadata_json TEXT
|
|
477
477
|
)
|
|
478
|
-
`),
|
|
478
|
+
`),XM(e),oA(e),qD(e),RA(e),sj(e),e.sql.exec(`
|
|
479
479
|
CREATE TABLE IF NOT EXISTS session_creation_receipts (
|
|
480
480
|
request_id TEXT PRIMARY KEY,
|
|
481
481
|
session_id TEXT NOT NULL UNIQUE REFERENCES sessions(id)
|
|
@@ -488,7 +488,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
488
488
|
ON session_entries(session_id, json_extract(data_json, '$.targetWorkId'))
|
|
489
489
|
WHERE type = 'cancellation'`),e.sql.exec(`CREATE INDEX IF NOT EXISTS idx_session_entries_successful_tool
|
|
490
490
|
ON session_entries(session_id, work_id, json_extract(data_json, '$.call.id'))
|
|
491
|
-
WHERE type = 'tool_outcome' AND json_extract(data_json, '$.result.isError') = 0`),
|
|
491
|
+
WHERE type = 'tool_outcome' AND json_extract(data_json, '$.result.isError') = 0`),oN(e),e.sql.exec(`
|
|
492
492
|
CREATE TABLE IF NOT EXISTS session_request_withdrawals (
|
|
493
493
|
session_id TEXT NOT NULL,
|
|
494
494
|
request_id TEXT NOT NULL,
|
|
@@ -513,14 +513,14 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
513
513
|
UNIQUE (session_id, request_id),
|
|
514
514
|
UNIQUE (session_id, work_id)
|
|
515
515
|
)
|
|
516
|
-
`)}),
|
|
516
|
+
`)}),zk(e)}function cN(e,t){let n=gM(e,t)?.leaf_id;return n==null?null:PN(e,t,n)}function lN(e,t){let n=gM(e,t)?.leaf_id;return n==null?null:NN(e,t,n)?.sequence??null}function uN(e,t,n){return e.transactionSync(()=>fN(e,{sessionId:t,id:_j.fact.generate(),entry:{kind:`model_preference`,workId:null,preference:n}}))}function dN(e,t,n){e.transactionSync(()=>{VM(e,t);let r=n===null?null:Aj({title:n});e.sql.exec(`SELECT 1 FROM sessions WHERE id = ? AND metadata_json IS ?`,t,r).toArray().length>0||(e.sql.exec(`UPDATE sessions SET metadata_json = ? WHERE id = ?`,r,t),uj(e,{sessionId:t,title:sM(e,t)}))})}function fN(e,t){let n=vM(e,VM(e,t.sessionId)),r=t.state??`complete`;if(r===`streaming`!=(t.entry.kind===`message_start`))throw Q(`A message start must be the streaming entry`);if(r===`streaming`&&t.entry.kind===`message_start`&&t.id!==t.entry.message.value)throw Q(`Message placeholder identity does not match its row`);let i=Date.now(),a=zM(e,t.sessionId);e.sql.exec(`INSERT INTO session_entries
|
|
517
517
|
(id, session_id, parent_id, sequence, type, role, state,
|
|
518
518
|
request_id, work_id, data_json, timestamp, completed_at)
|
|
519
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t.id,t.sessionId,n?.id??null,a,t.entry.kind,
|
|
519
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t.id,t.sessionId,n?.id??null,a,t.entry.kind,uM(t.entry),r,lM(t.entry),t.entry.workId,Ek(t.entry),i,r===`complete`?i:null),r===`complete`&&(e.sql.exec(`UPDATE sessions SET leaf_id = ?, updated_at = ? WHERE id = ?`,t.id,i,t.sessionId),uj(e,t.entry.kind===`command`?{sessionId:t.sessionId,activityAt:i,title:sM(e,t.sessionId)}:{sessionId:t.sessionId,activityAt:i}));let o=_M(e,t.sessionId,t.id);if(o===void 0)throw Q(`Appended Session entry is unavailable`);return o}function pN(e,t){let n=vM(e,VM(e,t.sessionId)),r=_M(e,t.sessionId,t.id),i=Date.now(),a=r?.state===`streaming`&&r.parentId!==(n?.id??null),o=a?n?.id??null:r?.parentId??n?.id??null,s=a?zM(e,t.sessionId):r?.sequence??zM(e,t.sessionId),c=r?.timestamp??i;if(t.id!==t.entry.message.value)throw Q(`Completed message identity does not match its row`);if(r!==void 0){let e=r.entry;if(e.kind!==`message_start`&&e.kind!==`message`)throw Q(`Completed Session leaf is not a message entry`);if(e.workId!==t.entry.workId||!dM(e.run,t.entry.run)||!dM(e.turn,t.entry.turn)||!dM(e.message,t.entry.message)||e.kind===`message_start`&&e.role!==t.entry.value.role)throw Q(`Completed message does not match its placeholder`)}e.sql.exec(`INSERT OR REPLACE INTO session_entries
|
|
520
520
|
(id, session_id, parent_id, sequence, type, role, state,
|
|
521
521
|
request_id, work_id, data_json, timestamp, completed_at)
|
|
522
522
|
VALUES (?, ?, ?, ?, 'message', ?, 'complete',
|
|
523
|
-
NULL, ?, ?, ?, ?)`,t.id,t.sessionId,o,s,
|
|
523
|
+
NULL, ?, ?, ?, ?)`,t.id,t.sessionId,o,s,uM(t.entry),t.entry.workId,Ek(t.entry),c,i),e.sql.exec(`UPDATE sessions SET leaf_id = ?, updated_at = ? WHERE id = ?`,t.id,i,t.sessionId),uj(e,{sessionId:t.sessionId,activityAt:i});let l=_M(e,t.sessionId,t.id);if(l===void 0)throw Q(`Completed Session leaf is unavailable`);return l}var mN=4e3,hN=4194304,gN={selected:`WITH RECURSIVE branch (id, parent_id, sequence, state) AS (
|
|
524
524
|
SELECT id, parent_id, sequence, state
|
|
525
525
|
FROM session_entries
|
|
526
526
|
WHERE session_id = ? AND id = ?
|
|
@@ -540,7 +540,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
540
540
|
JOIN branch AS child ON parent.id = child.parent_id
|
|
541
541
|
WHERE parent.session_id = ? AND child.sequence > ?
|
|
542
542
|
AND parent.state != 'streaming'
|
|
543
|
-
)`},
|
|
543
|
+
)`},_N={selected:{empty:`Selected Session leaf is unavailable`,missingParent:`Selected Session path has a missing parent`,invalid:`Selected Session path is invalid`},fork:{empty:`Fork entry is unavailable`,missingParent:`Fork path has a missing parent`,invalid:`Fork path is invalid`}},vN=B.pipe(L(z(0))),yN=E(N({length:vN,root_id:I(Z),root_parent_id:I(j),broken:vN,newest_id:I(Z),newest_sequence:I(Cj)}),xj),bN=E(N({sequence:Cj}),xj),xN=E(N({work_id:Z}),xj),SN=E(N({work_id:Z,diagnostic:j}),xj);function CN(e,t,n,r,...i){return e.sql.exec(`${gN[t.walk]} ${r}`,t.sessionId,t.tipId,t.sessionId,n,...i).toArray()}function wN(e,t,n,r){let i=_N[r],a=yN(e.sql.exec(`${gN[r]},
|
|
544
544
|
kept AS MATERIALIZED (
|
|
545
545
|
SELECT id, parent_id, sequence FROM branch
|
|
546
546
|
WHERE state != 'streaming'
|
|
@@ -558,7 +558,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
558
558
|
WHERE previous IS NOT NULL AND parent_id IS NOT previous) AS broken,
|
|
559
559
|
(SELECT id FROM kept ORDER BY sequence DESC LIMIT 1) AS newest_id,
|
|
560
560
|
(SELECT sequence FROM kept ORDER BY sequence DESC LIMIT 1)
|
|
561
|
-
AS newest_sequence`,t,n,t,0).one());if(a._tag===`Failure`)throw Q(`Stored Session lineage check is invalid`);let o=a.success;if(o.length===0||o.root_id===null||o.newest_id===null||o.newest_sequence===null)throw Q(i.empty);if(o.root_parent_id!==null)throw Q(i.missingParent);if(o.broken!==0)throw Q(i.invalid);return Object.freeze({sessionId:t,walk:r,tipId:n,rootId:o.root_id,newestId:o.newest_id,newestSequence:o.newest_sequence})}var
|
|
561
|
+
AS newest_sequence`,t,n,t,0).one());if(a._tag===`Failure`)throw Q(`Stored Session lineage check is invalid`);let o=a.success;if(o.length===0||o.root_id===null||o.newest_id===null||o.newest_sequence===null)throw Q(i.empty);if(o.root_parent_id!==null)throw Q(i.missingParent);if(o.broken!==0)throw Q(i.invalid);return Object.freeze({sessionId:t,walk:r,tipId:n,rootId:o.root_id,newestId:o.newest_id,newestSequence:o.newest_sequence})}var TN=E(N({state:F([`complete`,`streaming`]),newest_sequence:Cj,root_id:I(Z),root_parent_id:I(j)}),xj);function EN(e,t){let n=gM(e,t.sessionId),r=t.leafId??n?.leaf_id;if(r==null)return;let i=_N.selected,a=e.sql.exec(`SELECT tip.state AS state, tip.sequence AS newest_sequence,
|
|
562
562
|
root.id AS root_id, root.parent_id AS root_parent_id
|
|
563
563
|
FROM session_entries AS tip
|
|
564
564
|
LEFT JOIN (
|
|
@@ -566,12 +566,12 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
566
566
|
WHERE session_id = ? AND state = 'complete'
|
|
567
567
|
ORDER BY sequence ASC LIMIT 1
|
|
568
568
|
) AS root
|
|
569
|
-
WHERE tip.session_id = ? AND tip.id = ?`,t.sessionId,t.sessionId,r).toArray()[0];if(a===void 0)throw Q(i.empty);let o=
|
|
569
|
+
WHERE tip.session_id = ? AND tip.id = ?`,t.sessionId,t.sessionId,r).toArray()[0];if(a===void 0)throw Q(i.empty);let o=TN(a);if(o._tag===`Failure`)throw Q(`Stored Session lineage ends are invalid`);if(o.success.state!==`complete`||o.success.root_id===null)throw Q(i.empty);if(o.success.root_parent_id!==null)throw Q(i.missingParent);return Object.freeze({sessionId:t.sessionId,walk:`selected`,tipId:r,rootId:o.success.root_id,newestId:r,newestSequence:o.success.newest_sequence})}function DN(e,t,n,r){let i=Object.freeze(CN(e,t,n-1,`SELECT ${eM}
|
|
570
570
|
FROM session_entries
|
|
571
571
|
WHERE session_id = ? AND state != 'streaming'
|
|
572
572
|
AND sequence BETWEEN ? AND ?
|
|
573
573
|
AND id IN (SELECT id FROM branch)
|
|
574
|
-
ORDER BY sequence ASC`,t.sessionId,n,r).map(t=>
|
|
574
|
+
ORDER BY sequence ASC`,t.sessionId,n,r).map(t=>fM(e,t))),a=_N.selected,o=i[0];if(o!==void 0&&o.parentId!==null&&o.sequence!==n)throw Q(a.missingParent);let s;for(let e of i){if(s!==void 0&&e.parentId!==s.id)throw Q(a.invalid);s=e}return i}var ON=E(N({sizes:Xm(jp(Ap([Cj,vN]))),deepest_parent:I(j),deepest_sequence:I(Cj)}),xj);function kN(e,t,n,r,i,a){let o=`SELECT
|
|
575
575
|
(SELECT json_group_array(json_array(sequence, bytes)) FROM (
|
|
576
576
|
SELECT sequence, LENGTH(CAST(data_json AS BLOB)) AS bytes
|
|
577
577
|
FROM session_entries
|
|
@@ -586,7 +586,7 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
586
586
|
(SELECT sequence FROM branch ORDER BY sequence ASC LIMIT 1)
|
|
587
587
|
AS deepest_sequence`,s=e=>`CASE WHEN ${e}.state != 'streaming'
|
|
588
588
|
AND ${e}.sequence < ? AND ${e}.sequence > ?
|
|
589
|
-
THEN 1 ELSE 0 END`,c=
|
|
589
|
+
THEN 1 ELSE 0 END`,c=ON((n===`newest`?e.sql.exec(`WITH RECURSIVE branch (id, parent_id, sequence, state, taken) AS (
|
|
590
590
|
SELECT id, parent_id, sequence, state,
|
|
591
591
|
${s(`session_entries`)}
|
|
592
592
|
FROM session_entries
|
|
@@ -599,25 +599,25 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
599
599
|
WHERE parent.session_id = ? AND +parent.sequence < child.sequence
|
|
600
600
|
AND child.taken < ? AND child.sequence > ?
|
|
601
601
|
)
|
|
602
|
-
${o}`,i,r,t.sessionId,t.tipId,i,r,t.sessionId,a,r,r,i,a).toArray():
|
|
602
|
+
${o}`,i,r,t.sessionId,t.tipId,i,r,t.sessionId,a,r,r,i,a).toArray():CN(e,t,r,o,t.sessionId,r,i,a))[0]);if(c._tag===`Failure`)throw Q(`Stored Session entry size is invalid`);let{sizes:l,deepest_parent:u,deepest_sequence:d}=c.success;if(!(u===null||d===null||d<=r||n===`newest`&&l.length===a))throw Q(_N.selected.missingParent);return Object.freeze(l.map(([e,t])=>({sequence:e,bytes:t})).sort((e,t)=>n===`newest`?t.sequence-e.sequence:e.sequence-t.sequence))}function AN(e,t,n){let r=kN(e,t,n.from,n.after??0,n.before??2**53-1,n.rows+1),i=0,a=0;for(let e of r){if(i===n.rows||i>0&&a+e.bytes>hN)break;a+=e.bytes,i+=1}let o=r[0],s=r[i-1];return Object.freeze(o===void 0||s===void 0?{rows:Object.freeze([]),more:!1}:{rows:DN(e,t,Math.min(o.sequence,s.sequence),Math.max(o.sequence,s.sequence)),more:r.length>i})}function jN(e,t,n){return CN(e,t,n-1,`SELECT 1 AS present
|
|
603
603
|
FROM session_entries
|
|
604
604
|
WHERE session_id = ? AND state != 'streaming' AND sequence = ?
|
|
605
|
-
AND id IN (SELECT id FROM branch)`,t.sessionId,n).length>0}function
|
|
606
|
-
WHERE session_id = ? AND id = ? AND state != 'streaming'`,t.sessionId,n).toArray()[0];if(r===void 0)return;let i=
|
|
607
|
-
AND ${e}.sequence > (SELECT MIN(sequence) FROM targets)`,[i]=
|
|
605
|
+
AND id IN (SELECT id FROM branch)`,t.sessionId,n).length>0}function MN(e,t,n){let r=e.sql.exec(`SELECT sequence FROM session_entries
|
|
606
|
+
WHERE session_id = ? AND id = ? AND state != 'streaming'`,t.sessionId,n).toArray()[0];if(r===void 0)return;let i=bN(r);if(i._tag===`Failure`)throw Q(`Stored Session entry sequence is invalid`);return jN(e,t,i.success.sequence)?i.success.sequence:void 0}function NN(e,t,n){let r=e=>`${e}.id NOT IN (SELECT id FROM targets)
|
|
607
|
+
AND ${e}.sequence > (SELECT MIN(sequence) FROM targets)`,[i]=HN(e.sql.exec(`WITH RECURSIVE targets AS MATERIALIZED (
|
|
608
608
|
SELECT id, sequence FROM session_entries
|
|
609
609
|
WHERE session_id = ? AND type = 'model_preference'
|
|
610
610
|
AND state != 'streaming'
|
|
611
611
|
),
|
|
612
|
-
${
|
|
613
|
-
${
|
|
612
|
+
${RN(r(`child`))}
|
|
613
|
+
${zN(r(`walk`))}`,t,t,n,t).toArray());return i===void 0?void 0:_M(e,t,i)}function PN(e,t,n){let r=NN(e,t,n)?.entry;return r?.kind===`model_preference`?r.preference:null}function FN(e,t,n,r){if(t===void 0)return;let i=CN(e,t,0,`SELECT ${eM}
|
|
614
614
|
FROM session_entries
|
|
615
615
|
WHERE session_id = ? AND state != 'streaming' AND type = 'document'
|
|
616
616
|
AND json_extract(data_json, '$.extensionId') = ?
|
|
617
617
|
AND json_extract(data_json, '$.name') = ?
|
|
618
618
|
AND id IN (SELECT id FROM branch)
|
|
619
619
|
ORDER BY sequence DESC
|
|
620
|
-
LIMIT 1`,t.sessionId,n,r)[0],a=i===void 0?void 0:
|
|
620
|
+
LIMIT 1`,t.sessionId,n,r)[0],a=i===void 0?void 0:fM(e,i).entry;if(a!==void 0){if(a.kind!==`document`||a.extensionId!==n||a.name!==r)throw Q(`Stored Session document disagrees with its row`);return a.valueJson}}var IN=E(N({sequence:I(Cj)}),xj);function LN(e,t,n){if(n.size===0)return Object.freeze({commands:new Set,diagnostics:new Map,cancellations:new Map});let r=JSON.stringify([...n]),i=IN(e.sql.exec(`SELECT MIN(sequence) AS sequence FROM (
|
|
621
621
|
SELECT MIN(sequence) AS sequence
|
|
622
622
|
FROM session_entries INDEXED BY idx_session_entries_work
|
|
623
623
|
WHERE work_id IN (SELECT value FROM json_each(?))
|
|
@@ -628,11 +628,11 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
628
628
|
WHERE session_id = ? AND type = 'cancellation'
|
|
629
629
|
AND json_extract(data_json, '$.targetWorkId')
|
|
630
630
|
IN (SELECT value FROM json_each(?))
|
|
631
|
-
)`,r,t.sessionId,t.sessionId,r).one());if(i._tag===`Failure`)throw Q(`Stored Session work order is invalid`);if(i.success.sequence===null)return Object.freeze({commands:new Set,diagnostics:new Map,cancellations:new Map});let a=i.success.sequence-1,o=new Set(
|
|
631
|
+
)`,r,t.sessionId,t.sessionId,r).one());if(i._tag===`Failure`)throw Q(`Stored Session work order is invalid`);if(i.success.sequence===null)return Object.freeze({commands:new Set,diagnostics:new Map,cancellations:new Map});let a=i.success.sequence-1,o=new Set(CN(e,t,a,`SELECT DISTINCT work_id
|
|
632
632
|
FROM session_entries
|
|
633
633
|
WHERE session_id = ? AND sequence > ? AND state != 'streaming' AND type = 'command'
|
|
634
634
|
AND work_id IN (SELECT value FROM json_each(?))
|
|
635
|
-
AND id IN (SELECT id FROM branch)`,t.sessionId,a,r).map(e=>{let t=
|
|
635
|
+
AND id IN (SELECT id FROM branch)`,t.sessionId,a,r).map(e=>{let t=xN(e);if(t._tag===`Failure`)throw Q(`Stored Session command work is invalid`);return t.success.work_id})),s=new Map;for(let n of CN(e,t,a,`SELECT work_id, diagnostic FROM (
|
|
636
636
|
SELECT work_id, sequence,
|
|
637
637
|
json_extract(data_json, '$.diagnostic') AS diagnostic
|
|
638
638
|
FROM session_entries
|
|
@@ -642,13 +642,13 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
642
642
|
AND id IN (SELECT id FROM branch)
|
|
643
643
|
)
|
|
644
644
|
WHERE diagnostic IS NOT NULL
|
|
645
|
-
ORDER BY sequence ASC`,t.sessionId,a,r)){let e=
|
|
645
|
+
ORDER BY sequence ASC`,t.sessionId,a,r)){let e=SN(n);if(e._tag===`Failure`)throw Q(`Stored Session diagnostic is invalid`);s.set(e.success.work_id,e.success.diagnostic)}let c=new Map;for(let{entry:n}of CN(e,t,a,`SELECT ${eM}
|
|
646
646
|
FROM session_entries
|
|
647
647
|
WHERE session_id = ? AND sequence > ? AND state != 'streaming' AND type = 'cancellation'
|
|
648
648
|
AND json_extract(data_json, '$.targetWorkId')
|
|
649
649
|
IN (SELECT value FROM json_each(?))
|
|
650
650
|
AND id IN (SELECT id FROM branch)
|
|
651
|
-
ORDER BY sequence ASC`,t.sessionId,a,r).map(t=>
|
|
651
|
+
ORDER BY sequence ASC`,t.sessionId,a,r).map(t=>fM(e,t)))n.kind===`cancellation`&&n.meta!==void 0&&c.set(n.targetWorkId,n.meta);return Object.freeze({commands:o,diagnostics:s,cancellations:c})}function RN(e){return`walk (id, parent_id, sequence, state) AS (
|
|
652
652
|
SELECT id, parent_id, sequence, state
|
|
653
653
|
FROM session_entries
|
|
654
654
|
WHERE session_id = ? AND id = ?
|
|
@@ -658,27 +658,27 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
658
658
|
JOIN walk AS child ON parent.id = child.parent_id
|
|
659
659
|
WHERE parent.session_id = ? AND +parent.sequence < child.sequence
|
|
660
660
|
AND ${e}
|
|
661
|
-
)`}function
|
|
661
|
+
)`}function zN(e){return`SELECT id, parent_id, target, continues FROM (
|
|
662
662
|
SELECT id, parent_id, sequence,
|
|
663
663
|
id IN (SELECT id FROM targets) AS target,
|
|
664
664
|
COALESCE((${e}), 0) AS continues
|
|
665
665
|
FROM walk
|
|
666
666
|
)
|
|
667
667
|
WHERE target = 1 OR sequence = (SELECT MIN(sequence) FROM walk)
|
|
668
|
-
ORDER BY sequence DESC`}var
|
|
669
|
-
THEN json_extract(${e}.data_json, '$.head') END`}var
|
|
668
|
+
ORDER BY sequence DESC`}var BN=F([0,1]),VN=E(N({id:Z,parent_id:I(j),target:BN,continues:BN}),xj);function HN(e){let t=_N.selected;if(e.length===0)throw Q(t.empty);let n=e.map(e=>{let t=VN(e);if(t._tag===`Failure`)throw Q(`Stored Session walk row is invalid`);return t.success}),r=n.at(-1);if(r?.continues===1&&r.parent_id!==null)throw Q(t.missingParent);return n.flatMap(e=>e.target===1?[e.id]:[])}function UN(e){return`CASE WHEN ${e}.type = 'compaction' AND ${e}.state != 'streaming'
|
|
669
|
+
THEN json_extract(${e}.data_json, '$.head') END`}var WN=`WITH RECURSIVE walk (id, parent_id, sequence, state, head) AS (
|
|
670
670
|
SELECT id, parent_id, sequence, state,
|
|
671
|
-
${
|
|
671
|
+
${UN(`session_entries`)}
|
|
672
672
|
FROM session_entries
|
|
673
673
|
WHERE session_id = ? AND id = ?
|
|
674
674
|
UNION ALL
|
|
675
675
|
SELECT parent.id, parent.parent_id, parent.sequence, parent.state,
|
|
676
|
-
COALESCE(child.head, ${
|
|
676
|
+
COALESCE(child.head, ${UN(`parent`)})
|
|
677
677
|
FROM session_entries AS parent
|
|
678
678
|
JOIN walk AS child ON parent.id = child.parent_id
|
|
679
679
|
WHERE parent.session_id = ? AND +parent.sequence < child.sequence
|
|
680
680
|
AND (child.head IS NOT child.id OR child.state = 'streaming')
|
|
681
|
-
)`;function
|
|
681
|
+
)`;function GN(e,t,n,r,i){let a=JSON.stringify(r.flatMap(({entry:e})=>e.kind===`command`?[e.workId]:[])),o=e=>`${e}.sequence > (SELECT MIN(sequence) FROM targets)`,s=HN(e.sql.exec(`WITH RECURSIVE targets AS MATERIALIZED (
|
|
682
682
|
SELECT id, sequence FROM session_entries
|
|
683
683
|
WHERE session_id = ? AND type = 'compaction' AND work_id = ?
|
|
684
684
|
AND sequence < ? AND state != 'streaming'
|
|
@@ -691,31 +691,31 @@ Only summarize information explicitly present above. Do not infer or recreate la
|
|
|
691
691
|
IN (SELECT value FROM json_each(?))
|
|
692
692
|
AND sequence < ? AND state != 'streaming'
|
|
693
693
|
),
|
|
694
|
-
${
|
|
695
|
-
${
|
|
694
|
+
${RN(o(`child`))}
|
|
695
|
+
${zN(o(`walk`))}`,t,i,n.sequence,t,a,n.sequence,t,n.id,t).toArray());return s.length===0?Object.freeze([]):Object.freeze(e.sql.exec(`SELECT ${eM}
|
|
696
696
|
FROM session_entries
|
|
697
697
|
WHERE id IN (SELECT value FROM json_each(?))
|
|
698
|
-
ORDER BY sequence ASC`,JSON.stringify(s)).toArray().map(t=>
|
|
699
|
-
SELECT ${
|
|
698
|
+
ORDER BY sequence ASC`,JSON.stringify(s)).toArray().map(t=>fM(e,t)))}function KN(e,t,n){let r=_N.selected,i=e.sql.exec(`${WN}
|
|
699
|
+
SELECT ${eM}
|
|
700
700
|
FROM session_entries
|
|
701
701
|
WHERE id IN (SELECT id FROM walk) AND state != 'streaming'
|
|
702
|
-
ORDER BY sequence ASC`,t,n,t).toArray().map(t=>
|
|
702
|
+
ORDER BY sequence ASC`,t,n,t).toArray().map(t=>fM(e,t)),a=i[0];if(a===void 0)throw Q(r.empty);let o,s;for(let e of i){if(s!==void 0&&e.parentId!==s.id)throw Q(r.invalid);e.entry.kind===`compaction`&&(o=e.entry.head),s=e}let c=o===a.id;if(!c&&a.parentId!==null)throw Q(r.missingParent);return Object.freeze({rows:Object.freeze(i),compacted:c})}function qN(e,t){let n=gM(e,t.sessionId)?.leaf_id;if(n==null)return Object.freeze([]);let r=KN(e,t.sessionId,n),i=r.rows[0];return!r.compacted||i===void 0?r.rows:Object.freeze([...GN(e,t.sessionId,i,r.rows,t.workId??null),...r.rows])}function JN(e,t,n){return e.entry.kind===`compaction`&&e.entry.workId===t||e.entry.kind===`cancellation`&&n.has(e.entry.targetWorkId)}function YN(e,t,n,r,i){let a=EN(e,{sessionId:t,leafId:n.id});if(a===void 0)throw Q(`Accepted Session command lineage is unavailable`);let o=r===void 0?[]:CN(e,r,n.sequence,`SELECT ${eM}
|
|
703
703
|
FROM session_entries
|
|
704
704
|
WHERE session_id = ? AND sequence > ? AND state != 'streaming'
|
|
705
705
|
AND id IN (SELECT id FROM branch)
|
|
706
706
|
AND (work_id = ?
|
|
707
707
|
OR (type = 'command'
|
|
708
708
|
AND json_extract(data_json, '$.targetWorkId') = ?))
|
|
709
|
-
ORDER BY sequence ASC`,t,n.sequence,i,i).map(t=>
|
|
709
|
+
ORDER BY sequence ASC`,t,n.sequence,i,i).map(t=>fM(e,t)),s;for(let e of o)e.entry.kind===`compaction`&&(s=e.entry.head);let c=0,l;if(s===void 0){let r=KN(e,t,n.id);l=r.rows,r.compacted&&(c=r.rows[0]?.sequence??0)}else{let t=s;c=o.find(({id:e})=>e===t)?.sequence??MN(e,a,t)??0,l=c>n.sequence?[]:DN(e,a,Math.max(c,1),n.sequence)}if(c===0)return Object.freeze([...l,...o]);let u=[...l,...o.filter(({sequence:e})=>e>=c)],d=new Set(u.flatMap(({entry:e})=>e.kind===`command`?[e.workId]:[]));return Object.freeze([...GN(e,t,l[0]??n,u,i),...o.filter(e=>e.sequence<c&&JN(e,i,d)),...u])}function XN(e){let t=new Set,n=new Set;for(let{entry:r}of e)r.kind===`command`&&t.add(r.workId),r.kind===`cancellation`&&!t.has(r.targetWorkId)&&n.add(r.targetWorkId);return n}function ZN(e,t){let n=XN(e),r;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n?.entry.kind===`compaction`){r=n;break}}let i=r?.entry.kind===`compaction`?r.entry:void 0,a=i===void 0?-1:e.findIndex(({id:e})=>e===i.head),o=a>=0?e.slice(a):e,s=yj(o,t),c=[];i!==void 0&&c.push(...i.model);for(let e of o){let t=bk(e.entry);t!==void 0&&!n.has(t.workId)&&c.push(Ck(t)),e.entry.kind===`operator`&&c.push(Sk(e.entry)),e.entry.kind===`message`&&s.has(e.id)&&c.push(e.entry.value)}return Object.freeze(c)}function QN(e,t){return e.transactionSync(()=>{let n=_M(e,t.sessionId,t.commandFactId),r=`replay`,i=MM(e,t.sessionId,t.commandFactId);if(n===void 0&&i!==void 0&&(n=fN(e,{sessionId:i.sessionId,id:i.id,entry:i.entry}),r=`new`),n?.entry.kind!==`command`)throw Q(`Accepted Session command is unavailable`);if(i!==void 0&&Ek(n.entry)!==Ek(i.entry))throw Q(`Accepted Session command disagrees with its admission`);e.sql.exec(`DELETE FROM session_entries WHERE session_id = ? AND work_id = ? AND state = 'streaming' AND type = 'message_start'`,t.sessionId,n.entry.workId);let a=FM(e,t.sessionId,n.entry.workId),o=n.entry.workId,s=EN(e,{sessionId:t.sessionId}),c=YN(e,t.sessionId,n,s,o),l=Object.freeze({...n,entry:n.entry});return Object.freeze({command:l,modelPreference:PN(e,t.sessionId,n.id),messages:ZN(c,n.entry.workId),path:c,entryDelivery:r,resume:vj(a),abnormalTerminal:bj(a)})})}function $N(e,t){let n=gM(e,t.sessionId)?.leaf_id;if(n==null)return`stale`;let r=e.sql.exec(`${WN}
|
|
710
710
|
SELECT sequence
|
|
711
711
|
FROM session_entries
|
|
712
|
-
WHERE state != 'streaming' AND id = ? AND id IN (SELECT id FROM walk)`,t.sessionId,n,t.sessionId,t.head).toArray()[0];if(r===void 0)return`stale`;if(
|
|
712
|
+
WHERE state != 'streaming' AND id = ? AND id IN (SELECT id FROM walk)`,t.sessionId,n,t.sessionId,t.head).toArray()[0];if(r===void 0)return`stale`;if(bN(r)._tag===`Failure`)throw Q(`Stored Session entry sequence is invalid`);return`current`}function eP(e,t){return e.transactionSync(()=>{let n={kind:`compaction_notice`,workId:t.workId,trigger:t.trigger},r;if(t.result===`stale`||t.result===`insufficient`){let e={...n,result:t.result};r=t.usage===void 0?e:{...e,usage:t.usage}}else if(t.result===`failed`){let e={...n,result:`failed`},i=t.diagnostic===void 0?e:{...e,diagnostic:t.diagnostic.slice(0,200)};r=t.usage===void 0?i:{...i,usage:t.usage}}else{let e={...n,result:`nothing_to_compact`};r=t.diagnostic===void 0?e:{...e,diagnostic:t.diagnostic.slice(0,200)}}return fN(e,{sessionId:t.sessionId,id:_j.fact.generate(),entry:r})})}function tP(e,t){return e.transactionSync(()=>rP(e,t))}function nP(e,t){return e.transactionSync(()=>$N(e,{sessionId:t.sessionId,head:t.head})===`stale`?`stale`:rP(e,t))}function rP(e,t){if(gM(e,t.sessionId)?.leaf_id!==t.expectedLeafId)throw new H(`store`,`conflict`,`Session leaf changed during compaction`);let n={kind:`compaction`,workId:t.workId,head:t.head,model:[fA(t.summary,Date.now())],data:{reason:t.trigger,resumesRun:t.resumesRun??!1,tokensBefore:t.tokensBefore,tokensAfter:t.tokensAfter,usage:t.usage,contextRevision:t.contextRevision}},r=t.receipt===void 0?n:{...n,data:{...n.data,receipt:t.receipt}};return fN(e,{sessionId:t.sessionId,id:_j.fact.generate(),entry:t.details===void 0?r:{...r,data:{...r.data,details:t.details}}})}function iP(e){return Array.isArray(e)}function aP(e){if(e.images===void 0)return e.text;let t=[];return e.text.length>0&&t.push({type:`text`,text:e.text}),t.push(...e.images),t}function oP(e,t){return!iP(e)||!iP(t)?e===t:e.length===t.length&&e.every((e,n)=>{let r=t[n];return e.type===`text`?r?.type===`text`&&e.text===r.text:r?.type===`image`&&e.data===r.data&&e.mimeType===r.mimeType})}function sP(e,t){if(t.type===`compact`)return yk(e)&&e.instructions===t.instructions;let n=bk(e);return n?.delivery===t.delivery&&oP(n.message.content,aP(t))}function cP(e,t,n,r,i,a){let o={kind:`command`,requestId:e.requestId,receiptId:t,workId:t};if(e.type===`compact`){let t={...o,work:`compact`,timestamp:n,contract:r};return e.instructions===void 0?t:{...t,instructions:e.instructions}}let s={...o,delivery:e.delivery,message:{role:`user`,content:aP(e),timestamp:n},contract:r},c=i===void 0?s:{...s,targetWorkId:i};return a===void 0?c:{...c,reply:a}}function lP(e,t){return e?.agentId===t?.agentId&&e?.sessionId===t?.sessionId&&e?.outcome===t?.outcome&&(e?.outcome===`undeliverable`?t?.outcome===`undeliverable`&&e.reason===t.reason:t?.outcome!==`undeliverable`&&e?.commandId===t?.commandId&&e?.diagnostic===t?.diagnostic)}function uP(e,t,n,r,i,a,o,s,c){let l=PM(e,t,n.requestId);if(l!==void 0){if(!sP(l.entry,n)||!ED(l.entry.meta,r)||!lP(bk(l.entry)?.reply,c)||!zj(l.origin,i))throw new H(`contract`,`conflict`,`Request id conflicts with an accepted Session command`);return pP(l,`replay`)}let u=_j.fact.generate();VM(e,t);let d=Date.now(),f=cP(n,u,d,a,s,c);e.sql.exec(`INSERT INTO session_command_admissions
|
|
713
713
|
(id, session_id, sequence, request_id, work_id, data_json, timestamp,
|
|
714
714
|
origin_kind, origin_id, origin_correlation)
|
|
715
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,u,t,
|
|
715
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,u,t,BM(e,t),n.requestId,u,Ek(tM(f,r)),d,i.kind,i.kind===`user`?null:i.extensionId,i.kind===`user`?null:i.correlation);let p=MM(e,t,u);if(p===void 0)throw Q(`Accepted Session command admission is unavailable`);return o?.({jobId:u,sessionId:t,commandFactId:u}),pP(p,`new`)}function dP(e,t,n){if(e.sql.exec(`SELECT 1 FROM session_request_withdrawals WHERE session_id = ? AND request_id = ?`,t,n).toArray().length>0)throw new H(`contract`,`closed`,`Request was withdrawn`,n)}function fP(e,t,n){let r=PM(e,t,n);if(r!==void 0)return{status:`accepted`,commandId:r.id};let i=e.sql.exec(`SELECT id FROM session_entries WHERE session_id = ? AND request_id = ? AND type = 'operator'`,t,n).toArray()[0];if(i!==void 0){let e=Gj(i);if(e._tag===`Failure`)throw Q(`Stored operator receipt is invalid`);return{status:`accepted`,commandId:e.success.id}}return e.sql.exec(`INSERT OR IGNORE INTO session_request_withdrawals(session_id, request_id) VALUES (?, ?)`,t,n),{status:`unknown`}}function pP(e,t){let n=Object.freeze({sessionId:e.sessionId,requestId:e.entry.requestId,commandId:e.id});return Object.freeze({accepted:n,command:e,delivery:t})}function mP(e,t,n){if(e.entry.kind!==`cancellation`)throw Q(`Accepted Session cancellation is unavailable`);return Object.freeze({accepted:Object.freeze({commandId:e.entry.targetWorkId,entryId:e.id}),delivery:t,active:n})}function hP(e,t,n,r,i){return e.transactionSync(()=>{let a=n(),o=a.state===`running`?NM(e,t,a.jobId):void 0,s=o===void 0?void 0:_P(e,t,o.id,n,r,!1,i);for(let a=BM(e,t);a>0;){let{commands:o}=DM(e,t,64);if(o.length===0)return s;a-=o.length;for(let a of o){if(_P(e,t,a.id,n,r,!1,i,!0)===void 0)throw Q(`Pending Session command could not be cancelled`);fN(e,{sessionId:t,id:a.id,entry:a.entry})}}throw Q(`Session cancellation did not settle its pending admissions`)})}function gP(e,t,n,r,i,a=!1,o){return e.transactionSync(()=>_P(e,t,n,r,i,a,o))}function _P(e,t,n,r,i,a=!1,o,s=!1){let c=r(),l=MM(e,t,n);if(l?.entry.kind!==`command`)return;let u=FM(e,t,l.entry.workId),d=u.find(({entry:e})=>e.kind===`cancellation`);if(d?.entry.kind===`cancellation`)return mP(d,`replay`,c.state===`running`&&c.jobId===l.entry.workId);let f=c.state===`running`&&c.jobId===l.entry.workId;if(!f&&u.some(({entry:e})=>e.kind===`run_terminal`||e.kind===`work_terminal`)||a&&(f||u.some(({entry:e})=>e.kind===`command`))||bk(l.entry)?.delivery===`steer`&&u.some(({entry:e})=>e.kind===`command`)&&!f)return;let p=_j.fact.generate(),m=i({jobId:l.entry.workId,cancellationId:p,onlyIfPending:a});if(m.status===`missing`&&bk(l.entry)?.delivery!==`steer`&&!s||m.status===`conflict`&&a)return;if(m.status!==`recorded`&&m.status!==`missing`)throw new H(`store`,`conflict`,`Session cancellation identity conflicts`);let ee=fN(e,{sessionId:t,id:p,entry:tM({kind:`cancellation`,requestId:p,receiptId:p,workId:l.entry.workId,targetWorkId:l.entry.workId},o)});return m.status===`missing`&&fN(e,{sessionId:t,id:_j.fact.generate(),entry:{kind:`work_terminal`,workId:l.entry.workId,outcome:`cancelled`}}),mP(ee,`new`,f)}function vP(e,t){e.transactionSync(()=>{t.assertIdleSession?.(t.sessionId);let n=gM(e,t.sessionId);if(n===void 0)throw Q(`Session is unavailable for branch selection`);vM(e,n);let r=_M(e,t.sessionId,t.entryId);if(r?.state!==`complete`)throw Q(`Selected branch entry is unavailable`);let i=Date.now();e.sql.exec(`UPDATE sessions SET leaf_id = ?, updated_at = ? WHERE id = ?`,r.id,i,n.id),uj(e,{sessionId:n.id,activityAt:i,title:sM(e,n.id)})})}function yP(e,t){return e.transactionSync(()=>{if(dP(e,t.sessionId,t.requestId),gM(e,t.sessionId)===void 0)throw Q(`Session is unavailable for an operator entry`);let n=e.sql.exec(`SELECT id FROM session_entries WHERE session_id = ? AND request_id = ?`,t.sessionId,t.requestId).toArray()[0];if(n!==void 0){let r=Gj(n);if(r._tag===`Failure`)throw Q(`Stored Session entry identity is invalid`);let i=_M(e,t.sessionId,r.success.id);if(i?.entry.kind===`operator`&&i.entry.author===t.author&&ED(i.entry.meta,t.meta)&&i.entry.message.content===t.text)return!1;throw new H(`store`,`conflict`,`Request id already names another Session entry`)}t.assertIdleSession(t.sessionId);let r={kind:`operator`,workId:null,requestId:t.requestId,author:t.author,message:{role:`user`,content:t.text,timestamp:Date.now()}};return fN(e,{sessionId:t.sessionId,id:_j.fact.generate(),entry:tM(r,t.meta)}),!0})}function bP(e,t){return e.transactionSync(()=>{if(t.assertIdleSession?.(t.sessionId),gM(e,t.sessionId)===void 0)throw Q(`Source Session is unavailable`);let n=wN(e,t.sessionId,t.entryId,`fork`),r=_j.session.generate(),i=Date.now();e.sql.exec(`INSERT INTO sessions
|
|
716
716
|
(id, cwd, parent_session, leaf_id, created_at, updated_at, metadata_json)
|
|
717
|
-
VALUES (?, '/', ?, NULL, ?, ?, NULL)`,r,t.sessionId,i,i),
|
|
717
|
+
VALUES (?, '/', ?, NULL, ?, ?, NULL)`,r,t.sessionId,i,i),HA(e,t.sessionId,r);let a=null,o=null,s=1,c=new Map,l=0;for(;;){let t=AN(e,n,{after:l,from:`oldest`,rows:mN});for(let n of t.rows){let t=_j.fact.generate();c.set(n.id,t);let i=n.entry.kind===`compaction`?{...n.entry,head:c.get(n.entry.head)??(()=>{throw Q(`Fork compaction boundary is unavailable`)})()}:n.entry;e.sql.exec(`INSERT INTO session_entries
|
|
718
718
|
(id, session_id, parent_id, sequence, type, role, state,
|
|
719
719
|
request_id, work_id, data_json, timestamp, completed_at)
|
|
720
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t,r,a,s,i.kind,Gj(i),n.state,Wj(i),i.workId,sk(i),n.timestamp,n.completedAt),a=t,o=t,s+=1,l=n.sequence}if(!t.more)break}if(o===null)throw Q(`Fork path is empty`);e.sql.exec(`UPDATE sessions SET leaf_id = ?, updated_at = ? WHERE id = ?`,o,i,r);let u=oN(e,{sessionId:t.sessionId});for(let t of Uk(e,(t,n)=>hN(e,u,t,n)))KM(e,{sessionId:r,id:QA.fact.generate(),entry:t});return GA(e,{sessionId:r,activityAt:i,title:Hj(e,r)}),r})}function tP(e,t,n,r){if(Zj(e,t)===void 0)throw Q(`Session document owner is unavailable`);return hN(e,oN(e,{sessionId:t}),n,r)}function nP(e,t,n,r,i){if(Zj(e,t)===void 0)throw Q(`Session document owner is unavailable`);KM(e,{sessionId:t,id:QA.fact.generate(),entry:{kind:`document`,workId:null,extensionId:n,name:r,valueJson:i}})}var rP=2097152,iP=200,aP=200,oP=new TextEncoder;function sP(e){return new H(`store`,`unavailable`,e)}function cP(e,t,n){let r=new Map;for(let e of n)e.entry.kind===`command`&&r.set(e.entry.workId,e.entry.workId);let i=n.flatMap(({entry:e})=>(e.kind===`run_terminal`||e.kind===`work_terminal`)&&!r.has(e.workId)?[e.workId]:[]);for(let n of i)pM(e,t,n)!==void 0&&r.set(n,n);return r}function lP(e,t){return n=>{let r=pM(e,t,n)?.origin;return r?.kind===`extension`?{extensionId:r.extensionId,correlation:r.correlation}:void 0}}function uP(e,t,n){return{commandIds:cP(e,t,n),diagnostics:pP(n),cancellations:new Map(n.flatMap(({entry:e})=>e.kind===`cancellation`&&e.meta!==void 0?[[e.targetWorkId,e.meta]]:[])),origin:lP(e,t)}}function dP(e,t,n,r){let i=_N(e,n,new Set(r.flatMap(({entry:e})=>e.kind===`message`||e.kind===`run_terminal`||e.kind===`work_terminal`?[e.workId]:[]))),a=new Map;for(let e of i.commands)a.set(e,e);for(let{entry:n}of r)(n.kind===`run_terminal`||n.kind===`work_terminal`)&&!a.has(n.workId)&&pM(e,t,n.workId)!==void 0&&a.set(n.workId,n.workId);return{commandIds:a,diagnostics:i.diagnostics,cancellations:i.cancellations,origin:lP(e,t)}}function fP(e,t){let n=tk(e.entry);if(n!==void 0){let r=t.origin(n.workId),i={id:e.id,sequence:e.sequence,commandId:n.workId,requestId:n.requestId,value:n.message};return n.meta!==void 0&&(i={...i,meta:n.meta}),r!==void 0&&(i={...i,origin:r}),Object.freeze(i)}if(e.entry.kind===`operator`){let t={id:e.id,sequence:e.sequence,commandId:null,requestId:e.entry.requestId,value:ak(e.entry)};return e.entry.meta!==void 0&&(t={...t,meta:e.entry.meta}),Object.freeze(t)}if(e.entry.kind===`message`){let n={id:e.entry.message.value,sequence:e.sequence,commandId:t.commandIds.get(e.entry.workId)??null,value:e.entry.value};return Object.freeze(e.entry.data===void 0?n:{...n,data:e.entry.data})}}function pP(e){let t=new Map;for(let{entry:n}of e)(n.kind===`work_terminal`||n.kind===`run_terminal`)&&n.diagnostic!==void 0&&t.set(n.workId,n.diagnostic);return t}function mP(e,{commandIds:t,diagnostics:n,cancellations:r}){if(e.entry.kind!==`run_terminal`&&e.entry.kind!==`work_terminal`)return;let i=t.get(e.entry.workId);if(i===void 0)return;let a={commandId:i,outcome:e.entry.outcome,sequence:e.sequence,diagnostic:n.get(e.entry.workId)??null},o=e.entry.outcome===`cancelled`?r.get(e.entry.workId):void 0;return Object.freeze(o===void 0?a:{...a,meta:o})}function hP(e,t,n){let r=[];for(let i of n){let a=i.entry;if(a.kind!==`compaction`)continue;let o=n.find(e=>e.id===a.head)?.sequence??fN(e,t,a.head);if(o===void 0)throw sP(`Session compaction horizon is unavailable`);r.push(Object.freeze({id:i.id,sequence:o,at:i.timestamp,tokensBefore:a.data.tokensBefore,tokensAfter:a.data.tokensAfter??null,trigger:a.data.reason??null}))}return Object.freeze(r)}function gP(e){return Object.freeze(e.flatMap(({id:e,sequence:t,timestamp:n,entry:r})=>r.kind===`compaction_notice`?[Object.freeze({id:e,sequence:t,at:n,trigger:r.trigger,result:r.result,diagnostic:r.result===`stale`||r.result===`insufficient`?null:r.diagnostic??null})]:[]))}function _P(e){return oP.encode(JSON.stringify(e)).byteLength}function vP(e,t){let n=iO({generation:e,sequence:t});if(n===void 0)throw sP(`Session cursor is unavailable`);return n}function yP(e,t,n,r,i=!1){let a=fP(t,r),o=mP(t,r),s=i&&t.entry.kind===`sandbox_failure`?t.entry.event:void 0;if(a!==void 0&&e.messages.length===n)return!1;let c=(a===void 0?0:_P(a))+(o===void 0?0:_P(o))+(s===void 0?0:_P(s));if(c>rP)throw sP(`Session projection entry exceeds the read bound`);return e.bytes+c>rP?!1:(a!==void 0&&e.messages.push(a),o!==void 0&&e.terminals.push(o),s!==void 0&&e.sandboxFailures.push(s),e.bytes+=c,!0)}function bP(e,t,n,r,i,a=!1){let o={messages:[],terminals:[],sandboxFailures:[],bytes:0},s=0;for(let t=0;t<e.length&&s!==aP;t+=1){let c=e[i===`forward`?t:e.length-1-t];if(c===void 0||!yP(o,c,n,r,a))break;s+=1}if(s===0&&e.length>0)throw sP(`Session page cannot make bounded progress`);let c=i===`backward`?[...o.messages].reverse():o.messages,l=i===`backward`?[...o.terminals].reverse():o.terminals,u=i===`backward`?[...o.sandboxFailures].reverse():o.sandboxFailures;return Object.freeze({messages:Object.freeze(c),terminals:Object.freeze(l),sandboxFailures:Object.freeze(u),consumed:s,hasMore:t||s<e.length})}function xP(e){return Array.isArray(e)}function SP(e,t){let{commands:n,total:r}=cM(e,t,aP+1,`prompts`),i=[],a=oP.encode(JSON.stringify({prompts:[],hasMore:!1,total:r})).byteLength;for(let e of n){let t=wP(e),n=oP.encode(JSON.stringify(t)).byteLength+(i.length===0?0:1);if(i.length===aP||a+n>rP)return{prompts:i,hasMore:!0,total:r};i.push(t),a+=n}return{prompts:i,hasMore:!1,total:r}}function CP(e,t,n){let r=oM(e,t,n);return r===void 0?null:wP(r)}function wP(e){let t=tk(e.entry);if(t===void 0)throw sP(`Pending Session prompt is unavailable`);let n=t.message.content,r=xP(n)?{commandId:e.entry.workId,requestId:t.requestId,text:n.filter(e=>e.type===`text`).map(e=>e.text).join(``),images:n.filter(e=>e.type===`image`),delivery:t.delivery??`followUp`}:{commandId:e.entry.workId,requestId:t.requestId,text:n,delivery:t.delivery??`followUp`},i=e.entry.meta===void 0?r:{...r,meta:e.entry.meta};return e.origin.kind===`extension`?{...i,origin:{extensionId:e.origin.extensionId,correlation:e.origin.correlation}}:i}function TP(e,t,n){let r=aO(n);if(r?.generation===t.rootId)return dN(e,t,r.sequence)?r.sequence:void 0}function EP(e,t,n,r,i=()=>({})){return e.transactionSync(()=>{let a=SP(e,t),o=oN(e,{sessionId:t});if(o===void 0)return Object.freeze({sessionId:t,cursor:null,hasMore:!1,oldestCursor:null,messages:Object.freeze([]),terminals:Object.freeze([]),compactions:Object.freeze([]),compactionNotices:Object.freeze([]),pending:a,activity:r.facts,progress:r.progress,toolOutput:r.toolOutput,extensions:i(),attention:GD(e,t)});let s=o.rootId,c=n.before===void 0?2**53-1:TP(e,o,n.before);if(c===void 0)throw sP(`Session read cursor is unavailable`);let l=uN(e,o,{before:c,from:`newest`,rows:aP}),u=bP(l.rows,l.more,n.limit,dP(e,t,o,l.rows),`backward`,n.includeSandboxFailures===!0),d=l.rows.slice(l.rows.length-u.consumed),f=l.rows.at(-1),p=d[0],m={sessionId:t,cursor:f===void 0?null:vP(s,f.sequence),hasMore:u.hasMore,oldestCursor:u.hasMore&&p!==void 0?vP(s,p.sequence):null,messages:u.messages,terminals:u.terminals,compactions:hP(e,o,d),compactionNotices:gP(d),pending:a,activity:r.facts,progress:n.before===void 0?r.progress:null,toolOutput:n.before===void 0?r.toolOutput:[],extensions:i(),attention:GD(e,t)};return Object.freeze(n.includeSandboxFailures===!0?{...m,sandboxFailures:u.sandboxFailures}:m)})}var DP=Object.freeze({kind:`reset`});function OP(e,t,n){if(n===void 0)return 0;if(n.generation===t.rootId)return dN(e,t,n.sequence)?n.sequence:void 0}function kP(e,t,n,r,i,a,o,s,c){let l=uN(e,t,{after:n,from:`oldest`,rows:aP}),u=bP(l.rows,l.more,iP,dP(e,t.sessionId,t,l.rows),`forward`,c),d=l.rows.slice(0,u.consumed),f=d.at(-1)?.sequence??t.newestSequence,p={kind:`update`,delivery:r,cursor:vP(t.rootId,f),messages:u.messages,terminals:u.terminals,compactions:hP(e,t,d),compactionNotices:gP(d),pending:s,activity:i.facts,extensions:a,attention:o},m=[Object.freeze(c?{...p,sandboxFailures:u.sandboxFailures}:p)];return r===`live`&&!u.hasMore&&i.progress!==null&&m.push(Object.freeze({kind:`progress`,progress:i.progress,activity:i.facts})),Object.freeze({kind:`page`,frames:Object.freeze(u.hasMore?m:[...m,{kind:`tool_output`,toolOutput:i.toolOutput,activity:i.facts}]),hasMore:u.hasMore})}function AP(e,t,n,r,i,a=()=>({}),o=!1){let s=n===void 0?void 0:aO(n);return n!==void 0&&s===void 0?DP:e.transactionSync(()=>{let c=SP(e,t),l=oN(e,{sessionId:t});if(l===void 0)return n===void 0?{kind:`page`,frames:[{kind:`update`,delivery:r,cursor:null,messages:[],terminals:[],compactions:[],compactionNotices:[],activity:i.facts,extensions:a(),attention:GD(e,t),pending:c}],hasMore:!1}:DP;let u=OP(e,l,s);return u===void 0?DP:kP(e,l,u,r,i,a(),GD(e,t),c,o)})}function jP(e,t,n){let r=pM(e,t,n);if(r===void 0)throw sP(`Accepted Session command is unavailable`);let i=gM(e,t,r.entry.workId),a=uP(e,t,i),o=i.flatMap(e=>{let t=mP(e,a);return t===void 0?[]:[t]}).at(-1);if(o===void 0)return;let s=i.flatMap(({entry:e})=>e.kind===`message`&&e.value.role===`assistant`?[e.value]:[]),c=s.at(-1),l=o.outcome===`cancelled`?o.meta:r.entry.meta,u=fh(r.entry.meta);return{acceptedSender:u?.kind===`agent`?u.id:null,terminal:l===void 0?o:{...o,meta:l},content:o.outcome===`cancelled`?``:c?.content.flatMap(e=>e.type===`text`?[e.text]:[]).join(``).trim()??``,usage:s.map(({provider:e,model:t,usage:n})=>({provider:e,model:t,usage:n})),toolCalls:new Set(i.flatMap(({entry:e})=>e.kind===`tool_intent`?[e.call.id]:[])).size}}var MP=new WeakMap;function NP(e,t,n){let r=MP.get(e)?.get(t);return r?.workId===n?[...r.slots.values()].filter(e=>e!==null):[]}var PP=E(N({droppedBytes:B.check(z(0)),totalBytes:B.check(z(0))}),{onExcessProperty:`error`});function FP(e,t){return x(function*(){let n=yield*LP(e,t),r=()=>{MD(e,t.sessionId,`progress`)};return{started:e=>C(()=>{n.slots.size<4&&!n.slots.has(e.toolCall.value)&&n.slots.set(e.toolCall.value,null)}),update:e=>C(()=>{let t=n.slots.get(e.toolCall.value);if(t===void 0)return;let i=PP(e.result.data);if(xt(i))return;let a=e.result.content.filter(e=>e.type===`text`).map(e=>e.text).join(``);new TextEncoder().encode(a).byteLength>8192||a.split(`
|
|
721
|
-
`).length>200||i.success.droppedBytes>i.success.totalBytes||(n.slots.set(e.toolCall.value,{toolCallId:e.call.id,revision:(t?.revision??0)+1,tail:a,...i.success}),r())}),terminal:e=>C(()=>{n.slots.delete(e.toolCall.value)&&r()})}})}function IP(e){let t=MP.get(e);if(t!==void 0)return t;let n=new Map;return MP.set(e,n),n}function LP(e,t){return x(function*(){let n=IP(e),r=n.get(t.sessionId);if(r?.workId===t.commandId)return r;let i={workId:t.commandId,value:null,slots:new Map};return n.set(t.sessionId,i),yield*vr(()=>C(()=>{n.get(t.sessionId)===i&&(n.delete(t.sessionId),(i.value!==null||i.slots.size>0)&&MD(e,t.sessionId,`progress`))})),i})}function RP(e){return new H(`runtime`,`rejected`,e)}function zP(e,t,n){let r=IP(e).get(t);return r?.workId===n?r.value:null}function BP(e){let t=``,n=``;for(let r of e.value.content)r.type===`text`&&(t+=r.text),r.type===`thinking`&&(n+=r.thinking);return{text:t,thinking:n}}function VP(e,t,n){return x(function*(){let r=yield*LP(e,t),i,a=C(()=>{let n=r.value!==null;r.value=null,n&&MD(e,t.sessionId,`progress`),i=void 0});return yield*vr(()=>a),Object.freeze({started:e=>C(()=>{i=e,r.value=null}),update:n=>bn(()=>{let a=i;if(a===void 0)return y(RP(`Mule progress arrived before its message start`));if(a.run.value!==n.run.value||a.turn.value!==n.turn.value||a.message.value!==n.message.value)return y(RP(`Mule progress identity conflicts`));let o=r.value,s=BP(n);return o?.text===s.text&&o.thinking===s.thinking?_:(r.value=Object.freeze({messageId:n.message.value,revision:(o?.revision??0)+1,text:s.text,thinking:s.thinking,textTruncated:!1,thinkingTruncated:!1}),MD(e,t.sessionId,`progress`),_)}),terminal:e=>a.pipe(Gt(n(e)))})})}var HP=new WeakMap;function UP(e){let t=HP.get(e);if(t!==void 0)return t;let n=new Map;return HP.set(e,n),n}function WP(e,t){return UP(e).get(t)??null}function GP(e,t,n){UP(e).set(t,Object.freeze({trigger:n})),MD(e,t,`progress`)}function KP(e,t){UP(e).delete(t)&&MD(e,t,`progress`)}var qP=Object.freeze({admitNew:()=>{}});function JP(e){return e===void 0?qP:Object.freeze({admitNew:()=>{if(e.underPressure())throw new H(`store`,`storage_pressure`,`Storage is near its budget. New Sessions and prompts are refused until space is freed; running work continues.`)}})}function YP(e,t){let n=PN(e,t);return MD(e,t.sessionId),n}function XP(e,t){let n=FN(e,t);return MD(e,t.sessionId),n}function ZP(e,t){let n=IN(e,t);return n!==`stale`&&MD(e,t.sessionId),n}function QP(e){return new H(`store`,`rejected`,e)}function $P(e){return new H(`store`,`conflict`,e)}function $(e){return Qr({try:e,catch:e=>e instanceof H?e:new H(`store`,`rejected`,`Native Session store operation failed`,void 0,e)})}function eF(e){return $(()=>{VM(e)})}function tF(e,t,n,r,i,a,o){return $(()=>{let s=XN(e,t,n,i,a,r,o);return s?.delivery===`new`&&MD(e,t),s})}function nF(e,t){return $(()=>{let n=dM(e,t.sessionId,t.delivery,t.workId);return n.length>0&&MD(e,t.sessionId),n})}function rF(e,t){return $(()=>{fM(e,t),MD(e,t.sessionId)})}function iF(e,t,n,r,i){return $(()=>{let a=YN(e,t,n,r,i);return MD(e,t),a?.accepted})}function aF(e,t){return $(()=>{QN(e,{sessionId:t.sessionId,entryId:t.entryId,assertIdleSession:t.assertIdleSession}),MD(e,t.sessionId)})}function oF(e,t){return $(()=>{$N(e,t)&&MD(e,t.sessionId)})}function sF(e,t){return $(()=>{let n=eP(e,{sessionId:t.sessionId,entryId:t.entryId,assertIdleSession:t.assertIdleSession});return MD(e,n),Object.freeze({sessionId:n})})}function cF(e,t){return $(()=>{let n=MN(e,{sessionId:iy(t.sessionId),commandFactId:t.commandFactId});return n.entryDelivery===`new`&&MD(e,t.sessionId),n})}function lF(e){return e.content.flatMap(e=>e.type===`text`?[e.text]:[]).join(``).trim()}function uF(e,t){return $(()=>{let n=pM(e,t.sessionId,t.commandFactId);if(n===void 0)throw QP(`Accepted Session command is unavailable`);let r=gM(e,t.sessionId,n.entry.workId);for(let e=r.length-1;e>=0;--e){let t=r[e]?.entry;if(t?.kind===`message`&&t.value.role===`assistant`)return lF(t.value)}return``})}function dF(e,t,n){return $(()=>{let r=pM(e,t.sessionId,t.commandFactId);if(r===void 0)throw QP(`Accepted Session command is unavailable`);if(n!==`cancelled`)return r.entry.meta;let i=gM(e,t.sessionId,r.entry.workId).find(({entry:e})=>e.kind===`cancellation`);return i?.entry.kind===`cancellation`?i.entry.meta:void 0})}function fF(e,t){return $(()=>{let n=pM(e,t.sessionId,t.commandFactId);if(n===void 0)throw QP(`Accepted Session command is unavailable`);return pP(gM(e,t.sessionId,n.entry.workId)).get(n.entry.workId)})}function pF(e,t,n,r,i=()=>({})){return $(()=>EP(e,iy(t),sy(r),n,i))}function mF(e,t,n){return $(()=>CM(e,oy({requestId:t}),n))}function hF(e,t){return $(()=>wM(e,{sessionId:iy(t.sessionId),assertIdleSession:t.assertIdleSession,recordInboxDeletion:t=>{KA(e,t)}}))}function gF(e,t){return $(()=>ZA(e,t))}function _F(e,t,n,r,i,a=()=>({}),o=!1){return $(()=>AP(e,iy(t),n,r,i,a,o))}function vF(e,t){return sk(e)===sk(t)}function yF(e,t){return e.kind===t.kind&&e.value===t.value&&e.parent?.kind===t.parent?.kind&&e.parent?.value===t.parent?.value}function bF(e,t){return e.core===t.core&&e.extensions.length===t.extensions.length&&e.extensions.every(([e,n],r)=>{let i=t.extensions[r];return i?.[0]===e&&i[1]===n})}function xF(e,t,n,r,i){e.transactionSync(()=>{i?.();let a=gM(e,t.sessionId,t.commandId).find(r);if(a!==void 0){if(n.kind===`work_terminal`&&a.entry.kind===`run_terminal`||vF(a.entry,n))return`replay`;throw $P(`Mule event identity conflicts`)}for(let r=0;r<3;r+=1){let r=QA.fact.generate();if(eM(e,r)===void 0&&pM(e,t.sessionId,r)===void 0)return KM(e,{sessionId:t.sessionId,id:r,entry:n}),`new`}throw QP(`Session fact identity allocation failed`)})===`new`&&MD(e,t.sessionId)}function SF(e,t,n){return $(()=>{xF(e,t,{kind:`sandbox_failure`,workId:t.commandId,event:n},({entry:e})=>e.kind===`sandbox_failure`&&e.event.ref===n.ref)})}function CF(e,t,n,r){let i=pM(e,t,n);if(i?.entry.workId!==r)throw QP(`Accepted Session work is unavailable`);return i.origin.kind===`extension`?Object.freeze({extensionId:i.origin.extensionId,correlation:i.origin.correlation}):null}function wF(e,t,n,r){let i=CF(e,t,n,r),a=gM(e,t,r).map(({entry:e})=>e),o=new Set(a.flatMap(e=>e.kind===`tool_intent`?[e.call.id]:[])).size,s=a.filter(e=>e.kind===`run_terminal`||e.kind===`work_terminal`).at(-1);return Object.freeze({terminal:s?.kind===`run_terminal`||s?.kind===`work_terminal`?s.outcome:`missing`,origin:i,toolCalls:o})}function TF(e,t){return $(()=>{if(pM(e,t.sessionId,t.commandFactId)?.entry.workId!==t.workId)throw QP(`Settled Session work is unavailable`);let n={workId:t.workId,kind:`work_terminal`,outcome:t.outcome};xF(e,{sessionId:t.sessionId,commandId:t.workId},t.diagnostic===void 0?n:{...n,diagnostic:t.diagnostic},({entry:e})=>e.kind===`work_terminal`||e.kind===`run_terminal`&&e.outcome===t.outcome,()=>{e.sql.exec(`DELETE FROM session_entries WHERE session_id = ? AND work_id = ? AND state = 'streaming' AND type = 'message_start'`,t.sessionId,t.workId)})})}function EF(e,t,n,r,i){return $(()=>{let a=r.type===`run_start`?{kind:`run_started`,workId:t.commandId,run:r.run,contract:n}:r.type===`turn_start`?{kind:`turn_started`,workId:t.commandId,run:r.run,turn:r.turn}:{kind:`run_terminal`,workId:t.commandId,run:r.run,terminal:r.terminal,outcome:r.outcome};a.kind===`run_terminal`&&i!==void 0&&(a={...a,diagnostic:i}),xF(e,t,a,({entry:e})=>e.kind===a.kind?e.kind===`run_started`&&a.kind===`run_started`?yF(e.run,a.run)&&bF(e.contract,n):e.kind===`turn_started`&&a.kind===`turn_started`?yF(e.turn,a.turn):e.kind===`run_terminal`&&a.kind===`run_terminal`&&yF(e.terminal,a.terminal):!1)})}function DF(e,t,n){return $(()=>{let r={kind:`message_start`,workId:t.commandId,run:n.run,turn:n.turn,message:n.message,role:n.value.role};e.transactionSync(()=>{let i=gM(e,t.sessionId,t.commandId).find(({entry:e})=>(e.kind===`message_start`||e.kind===`message`)&&yF(e.message,n.message));if(i!==void 0){if(i.entry.kind===`message`){if(i.entry.workId!==r.workId||!yF(i.entry.run,r.run)||!yF(i.entry.turn,r.turn)||i.entry.value.role!==r.role)throw $P(`Mule message-start identity conflicts`);return`replay`}if(!vF(i.entry,r))throw $P(`Mule message-start identity conflicts`);return`replay`}return KM(e,{sessionId:t.sessionId,id:n.message.value,entry:r,state:`streaming`}),`new`})===`new`&&MD(e,t.sessionId)})}function OF(e,t,n,r){return $(()=>{xF(e,t,{kind:`model_prompt`,workId:t.commandId,run:r.run,turn:r.turn,attempt:r.attempt,contract:n,systemPrompt:r.systemPrompt},({entry:e})=>e.kind===`model_prompt`&&yF(e.turn,r.turn)&&e.attempt===r.attempt&&bF(e.contract,n))})}function kF(e,t,n){return $(()=>{let r={kind:`message`,workId:t.commandId,run:n.run,turn:n.turn,message:n.message,value:n.value},i=n.data===void 0?r:{...r,data:n.data};e.transactionSync(()=>{let r=gM(e,t.sessionId,t.commandId).find(({entry:e})=>(e.kind===`message_start`||e.kind===`message`)&&yF(e.message,n.message));if(r?.entry.kind===`message`){if(!vF(r.entry,i))throw $P(`Mule completed-message identity conflicts`);return`replay`}return qM(e,{sessionId:t.sessionId,id:n.message.value,entry:i}),`new`})===`new`&&MD(e,t.sessionId)})}function AF(e,t,n,r){return $(()=>{xF(e,t,{kind:`tool_intent`,replay:r.replay,contract:n,workId:t.commandId,run:r.run,turn:r.turn,toolCall:r.toolCall,call:r.call},({entry:e})=>e.kind===`tool_intent`&&yF(e.toolCall,r.toolCall)&&bF(e.contract,n))})}function jF(e,t,n){return $(()=>{let{data:r,...i}=n.result,a={kind:`tool_outcome`,workId:t.commandId,run:n.run,turn:n.turn,toolCall:n.toolCall,call:n.call,result:i};xF(e,t,r===void 0?a:{...a,data:r},({entry:e})=>e.kind===`tool_outcome`&&yF(e.toolCall,n.toolCall))})}function MF(e,t,n,r){return $(()=>{let i=gM(e,t.sessionId,t.commandId).find(({entry:e})=>e.kind===`turn_started`&&yF(e.turn,r));if(i===void 0)throw $P(`Retry has no recorded turn`);xF(e,t,{kind:`live_retry`,workId:t.commandId,event:n},({entry:e,sequence:t})=>t>i.sequence&&e.kind===`live_retry`&&e.event.type===n.type&&e.event.attempt===n.attempt&&yF(e.event.run,n.run))}).pipe(it(NF))}var NF=()=>({_tag:`MuleError`,phase:`listener`,message:`Woodstock could not record the Mule event`});function PF(e,t,n){return x(function*(){let r=yield*VP(e,t,n=>kF(e,t,n)),i=yield*FP(e,t),a=(a,o)=>{switch(a.type){case`model_prompt`:return OF(e,t,n,a);case`run_start`:case`turn_start`:case`run_end`:return EF(e,t,n,a,o);case`message_start`:return a.value.role===`user`?_:DF(e,t,a).pipe(Gt(a.value.role===`assistant`?r.started(a):_));case`message_update`:return r.update(a);case`message_end`:return a.value.role===`user`?_:a.value.role===`assistant`?r.terminal(a):kF(e,t,a);case`tool_execution_start`:return AF(e,t,n,a).pipe(Gt(i.started(a)));case`tool_execution_end`:return jF(e,t,a).pipe(Gt(i.terminal(a)));case`tool_execution_update`:return i.update(a);case`turn_end`:return _}};return(e,t)=>a(e,t).pipe(it(NF))})}function FF(e,t,n){return $(()=>jP(e,iy(t),iy(n)))}var IF=j.pipe(L(jm(1)),L(V(128)),L(Xp(/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/u))),LF=j.pipe(L(jm(1)),L(V(64)),L(Xp(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u))),RF=IF.pipe(Rp(`ExtensionId`)),zF=j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)),Rp(`ExtensionRevision`)),BF=j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)),Rp(`ExtensionFingerprint`)),VF=class extends Ei(`ExtensionHookError`){};function HF(e){return bn(()=>{let t=e();return Ve(t)?t:Vr({try:()=>Promise.resolve(t),catch:e=>new VF({cause:e})})})}var UF=class extends Error{constructor(){super(`Extension transaction handler must return synchronously`),this.name=`AsyncExtensionTransactionError`}};function WF(e,t){let r=e(t);if(r instanceof Promise||Ve(r)&&!n(r))throw new UF;return r}export{vM as $,Ei as $a,O as $i,hv as $n,Jf as $r,Ak as $t,MF as A,oa as Aa,Sm as Ai,wT as An,sh as Ar,Qk as At,zP as B,Wi as Ba,V as Bi,ey as Bn,Op as Br,Mk as Bt,pF as C,Wl as Ca,nm as Ci,oD as Cn,jp as Cr,fA as Ct,uF as D,ls as Da,xm as Di,ZT as Dn,im as Dr,Zk as Dt,wF as E,ss as Ea,Em as Ei,DE as En,Jm as Er,Jk as Et,nF as F,la as Fa,Cm as Fi,lT as Fn,Mp as Fr,Hk as Ft,_j as G,Mi as Ga,Um as Gi,iy as Gn,Ap as Gr,xk as Gt,CP as H,qi as Ha,Vm as Hi,sy as Hn,N as Hr,Tk as Ht,JP as I,ta as Ia,mm as Ii,fw as In,Km as Ir,zk as It,GN as J,Ri as Ja,Xp as Ji,H as Jn,Fp as Jr,kk as Jt,WN as K,Vi as Ka,Bm as Ki,cy as Kn,th as Kr,Sk as Kt,GP as L,ea as La,km as Li,dw as Ln,Sp as Lr,Ek as Lt,SF as M,ma as Ma,_m as Mi,bT as Mn,F as Mr,oA as Mt,TF as N,fa as Na,pm as Ni,mT as Nn,vm as Nr,sA as Nt,fF as O,no as Oa,z as Oi,QT as On,B as Or,Yk as Ot,rF as P,sa as Pa,Om as Pi,hT as Pn,bp as Pr,pA as Pt,Yj as Q,Fi as Qa,k as Qi,fv as Qn,L as Qr,Ok as Qt,KP as R,ia as Ra,wm as Ri,yw as Rn,I as Rr,Nk as Rt,CF as S,mu as Sa,Hm as Si,pD as Sn,fh as Sr,lA as St,_F as T,os as Ta,fm as Ti,eE as Tn,wp as Tr,qk as Tt,vj as U,Yi as Ua,Fm as Ui,ty as Un,Tp as Ur,Rk as Ut,NP as V,Ji as Va,Wm as Vi,ay as Vn,j as Vr,bk as Vt,IM as W,Ki as Wa,jm as Wi,oy as Wn,$m as Wr,Ik as Wt,NN as X,Ni as Xa,Qp as Xi,vv as Xn,xp as Xr,Lk as Xt,jN as Y,Li as Ya,tm as Yi,Cv as Yn,P as Yr,Pk as Yt,uM as Z,zi as Za,R as Zi,yv as Zn,Rp as Zr,Ck as Zt,cF as _,Bs as _a,Am as _i,TD as _n,tg as _r,qA as _t,BF as a,rh as aa,op as ai,rk as an,B_ as ar,DN as at,eF as b,pu as ba,Pm as bi,_D as bn,Ph as br,cA as bt,LF as c,Ku as ca,pp as ci,gO as cn,W_ as cr,HM as ct,XP as d,Hs as da,dp as di,YD as dn,G_ as dr,GM as dt,Lp as ea,qf as ei,jk as en,mv as er,yM as et,aF as f,yu as fa,fp as fi,XD as fn,Ag as fr,KN as ft,sF as g,Ks as ga,hm as gi,MD as gn,Eg as gr,JA as gt,hF as h,Vs as ha,rp as hi,ND as hn,Dg as hr,ej as ht,RF as i,ih as ia,ap as ii,ek as in,ov as ir,hM as it,oF as j,da as ja,rm as ji,CT as jn,A as jr,aA as jt,dF as k,wa as ka,Dm as ki,yT as kn,oh as kr,Xk as kt,iF as l,Ys as la,hp as li,_O as ln,tv as lr,RM as lt,mF as m,Ls as ma,Kp as mi,kD as mn,Tg as mr,nP as mt,HF as n,Gp as na,lp as ni,VO as nn,nv as nr,UM as nt,IF as o,tp as oa,E as oi,tk as on,av as or,tP as ot,tF as p,Us as pa,Xm as pi,qD as pn,kg as pr,AN as pt,aM as q,ji as qa,gm as qi,ly as qn,Cp as qr,Dk as qt,WF as r,ah as ra,ip as ri,ik as rn,L_ as rr,_M as rt,zF as s,Wp as sa,cp as si,yO as sn,q_ as sr,oN as st,UF as t,Ip as ta,sp as ti,AO as tn,I_ as tr,iM as tt,YP as u,Gs as ua,Bp as ui,JD as un,lv as ur,WM as ut,PF as v,Rs as va,Lm as vi,bD as vn,Qh as vr,bA as vt,gF as w,ks as wa,am as wi,sD as wn,Ep as wr,dA as wt,FF as x,hu as xa,Gm as xi,gD as xn,_h as xr,uA as xt,ZP as y,qs as ya,Tm as yi,CD as yn,Zh as yr,SA as yt,WP as z,Xi as za,Im as zi,kv as zn,M as zr,wk as zt};
|
|
720
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t,r,a,s,i.kind,uM(i),n.state,lM(i),i.workId,Ek(i),n.timestamp,n.completedAt),a=t,o=t,s+=1,l=n.sequence}if(!t.more)break}if(o===null)throw Q(`Fork path is empty`);e.sql.exec(`UPDATE sessions SET leaf_id = ?, updated_at = ? WHERE id = ?`,o,i,r);let u=EN(e,{sessionId:t.sessionId});for(let t of cA(e,(t,n)=>FN(e,u,t,n)))fN(e,{sessionId:r,id:_j.fact.generate(),entry:t});return uj(e,{sessionId:r,activityAt:i,title:sM(e,r)}),r})}function xP(e,t,n,r){if(gM(e,t)===void 0)throw Q(`Session document owner is unavailable`);return FN(e,EN(e,{sessionId:t}),n,r)}function SP(e,t,n,r,i){if(gM(e,t)===void 0)throw Q(`Session document owner is unavailable`);fN(e,{sessionId:t,id:_j.fact.generate(),entry:{kind:`document`,workId:null,extensionId:n,name:r,valueJson:i}})}var CP=2097152,wP=200,TP=200,EP=new TextEncoder;function DP(e){return new H(`store`,`unavailable`,e)}function OP(e,t,n){let r=new Map;for(let e of n)e.entry.kind===`command`&&r.set(e.entry.workId,e.entry.workId);let i=n.flatMap(({entry:e})=>(e.kind===`run_terminal`||e.kind===`work_terminal`)&&!r.has(e.workId)?[e.workId]:[]);for(let n of i)MM(e,t,n)!==void 0&&r.set(n,n);return r}function kP(e,t){return n=>{let r=MM(e,t,n)?.origin;return r?.kind===`extension`?{extensionId:r.extensionId,correlation:r.correlation}:void 0}}function AP(e,t,n){return{commandIds:OP(e,t,n),diagnostics:NP(n),cancellations:new Map(n.flatMap(({entry:e})=>e.kind===`cancellation`&&e.meta!==void 0?[[e.targetWorkId,e.meta]]:[])),origin:kP(e,t)}}function jP(e,t,n,r){let i=LN(e,n,new Set(r.flatMap(({entry:e})=>e.kind===`message`||e.kind===`run_terminal`||e.kind===`work_terminal`?[e.workId]:[]))),a=new Map;for(let e of i.commands)a.set(e,e);for(let{entry:n}of r)(n.kind===`run_terminal`||n.kind===`work_terminal`)&&!a.has(n.workId)&&MM(e,t,n.workId)!==void 0&&a.set(n.workId,n.workId);return{commandIds:a,diagnostics:i.diagnostics,cancellations:i.cancellations,origin:kP(e,t)}}function MP(e,t){let n=bk(e.entry);if(n!==void 0){let r=t.origin(n.workId),i={id:e.id,sequence:e.sequence,commandId:n.workId,requestId:n.requestId,value:n.message};return n.meta!==void 0&&(i={...i,meta:n.meta}),r!==void 0&&(i={...i,origin:r}),Object.freeze(i)}if(e.entry.kind===`operator`){let t={id:e.id,sequence:e.sequence,commandId:null,requestId:e.entry.requestId,value:wk(e.entry)};return e.entry.meta!==void 0&&(t={...t,meta:e.entry.meta}),Object.freeze(t)}if(e.entry.kind===`message`){let n={id:e.entry.message.value,sequence:e.sequence,commandId:t.commandIds.get(e.entry.workId)??null,value:e.entry.value};return Object.freeze(e.entry.data===void 0?n:{...n,data:e.entry.data})}}function NP(e){let t=new Map;for(let{entry:n}of e)(n.kind===`work_terminal`||n.kind===`run_terminal`)&&n.diagnostic!==void 0&&t.set(n.workId,n.diagnostic);return t}function PP(e,{commandIds:t,diagnostics:n,cancellations:r}){if(e.entry.kind!==`run_terminal`&&e.entry.kind!==`work_terminal`)return;let i=t.get(e.entry.workId);if(i===void 0)return;let a={commandId:i,outcome:e.entry.outcome,sequence:e.sequence,diagnostic:n.get(e.entry.workId)??null},o=e.entry.outcome===`cancelled`?r.get(e.entry.workId):void 0;return Object.freeze(o===void 0?a:{...a,meta:o})}function FP(e,t,n){let r=[];for(let i of n){let a=i.entry;if(a.kind!==`compaction`)continue;let o=n.find(e=>e.id===a.head)?.sequence??MN(e,t,a.head);if(o===void 0)throw DP(`Session compaction horizon is unavailable`);r.push(Object.freeze({id:i.id,sequence:o,at:i.timestamp,tokensBefore:a.data.tokensBefore,tokensAfter:a.data.tokensAfter??null,trigger:a.data.reason??null}))}return Object.freeze(r)}function IP(e){return Object.freeze(e.flatMap(({id:e,sequence:t,timestamp:n,entry:r})=>r.kind===`compaction_notice`?[Object.freeze({id:e,sequence:t,at:n,trigger:r.trigger,result:r.result,diagnostic:r.result===`stale`||r.result===`insufficient`?null:r.diagnostic??null})]:[]))}function LP(e){return EP.encode(JSON.stringify(e)).byteLength}function RP(e,t){let n=sO({generation:e,sequence:t});if(n===void 0)throw DP(`Session cursor is unavailable`);return n}function zP(e,t,n,r,i=!1){let a=MP(t,r),o=PP(t,r),s=i&&t.entry.kind===`sandbox_failure`?t.entry.event:void 0;if(a!==void 0&&e.messages.length===n)return!1;let c=(a===void 0?0:LP(a))+(o===void 0?0:LP(o))+(s===void 0?0:LP(s));if(c>CP)throw DP(`Session projection entry exceeds the read bound`);return e.bytes+c>CP?!1:(a!==void 0&&e.messages.push(a),o!==void 0&&e.terminals.push(o),s!==void 0&&e.sandboxFailures.push(s),e.bytes+=c,!0)}function BP(e,t,n,r,i,a=!1){let o={messages:[],terminals:[],sandboxFailures:[],bytes:0},s=0;for(let t=0;t<e.length&&s!==TP;t+=1){let c=e[i===`forward`?t:e.length-1-t];if(c===void 0||!zP(o,c,n,r,a))break;s+=1}if(s===0&&e.length>0)throw DP(`Session page cannot make bounded progress`);let c=i===`backward`?[...o.messages].reverse():o.messages,l=i===`backward`?[...o.terminals].reverse():o.terminals,u=i===`backward`?[...o.sandboxFailures].reverse():o.sandboxFailures;return Object.freeze({messages:Object.freeze(c),terminals:Object.freeze(l),sandboxFailures:Object.freeze(u),consumed:s,hasMore:t||s<e.length})}function VP(e){return Array.isArray(e)}function HP(e,t){let{commands:n,total:r}=DM(e,t,TP+1,`prompts`),i=[],a=EP.encode(JSON.stringify({prompts:[],hasMore:!1,total:r})).byteLength;for(let e of n){let t=WP(e),n=EP.encode(JSON.stringify(t)).byteLength+(i.length===0?0:1);if(i.length===TP||a+n>CP)return{prompts:i,hasMore:!0,total:r};i.push(t),a+=n}return{prompts:i,hasMore:!1,total:r}}function UP(e,t,n){let r=TM(e,t,n);return r===void 0?null:WP(r)}function WP(e){let t=bk(e.entry);if(t===void 0)throw DP(`Pending Session prompt is unavailable`);let n=t.message.content,r=VP(n)?{commandId:e.entry.workId,requestId:t.requestId,text:n.filter(e=>e.type===`text`).map(e=>e.text).join(``),images:n.filter(e=>e.type===`image`),delivery:t.delivery??`followUp`}:{commandId:e.entry.workId,requestId:t.requestId,text:n,delivery:t.delivery??`followUp`},i=e.entry.meta===void 0?r:{...r,meta:e.entry.meta};return e.origin.kind===`extension`?{...i,origin:{extensionId:e.origin.extensionId,correlation:e.origin.correlation}}:i}function GP(e,t,n){let r=cO(n);if(r?.generation===t.rootId)return jN(e,t,r.sequence)?r.sequence:void 0}function KP(e,t,n,r,i=()=>({})){return e.transactionSync(()=>{let a=HP(e,t),o=EN(e,{sessionId:t});if(o===void 0)return Object.freeze({sessionId:t,cursor:null,hasMore:!1,oldestCursor:null,messages:Object.freeze([]),terminals:Object.freeze([]),compactions:Object.freeze([]),compactionNotices:Object.freeze([]),pending:a,activity:r.facts,progress:r.progress,toolOutput:r.toolOutput,extensions:i(),attention:JD(e,t)});let s=o.rootId,c=n.before===void 0?2**53-1:GP(e,o,n.before);if(c===void 0)throw DP(`Session read cursor is unavailable`);let l=AN(e,o,{before:c,from:`newest`,rows:TP}),u=BP(l.rows,l.more,n.limit,jP(e,t,o,l.rows),`backward`,n.includeSandboxFailures===!0),d=l.rows.slice(l.rows.length-u.consumed),f=l.rows.at(-1),p=d[0],m={sessionId:t,cursor:f===void 0?null:RP(s,f.sequence),hasMore:u.hasMore,oldestCursor:u.hasMore&&p!==void 0?RP(s,p.sequence):null,messages:u.messages,terminals:u.terminals,compactions:FP(e,o,d),compactionNotices:IP(d),pending:a,activity:r.facts,progress:n.before===void 0?r.progress:null,toolOutput:n.before===void 0?r.toolOutput:[],extensions:i(),attention:JD(e,t)};return Object.freeze(n.includeSandboxFailures===!0?{...m,sandboxFailures:u.sandboxFailures}:m)})}var qP=Object.freeze({kind:`reset`});function JP(e,t,n){if(n===void 0)return 0;if(n.generation===t.rootId)return jN(e,t,n.sequence)?n.sequence:void 0}function YP(e,t,n,r,i,a,o,s,c){let l=AN(e,t,{after:n,from:`oldest`,rows:TP}),u=BP(l.rows,l.more,wP,jP(e,t.sessionId,t,l.rows),`forward`,c),d=l.rows.slice(0,u.consumed),f=d.at(-1)?.sequence??t.newestSequence,p={kind:`update`,delivery:r,cursor:RP(t.rootId,f),messages:u.messages,terminals:u.terminals,compactions:FP(e,t,d),compactionNotices:IP(d),pending:s,activity:i.facts,extensions:a,attention:o},m=[Object.freeze(c?{...p,sandboxFailures:u.sandboxFailures}:p)];return r===`live`&&!u.hasMore&&i.progress!==null&&m.push(Object.freeze({kind:`progress`,progress:i.progress,activity:i.facts})),Object.freeze({kind:`page`,frames:Object.freeze(u.hasMore?m:[...m,{kind:`tool_output`,toolOutput:i.toolOutput,activity:i.facts}]),hasMore:u.hasMore})}function XP(e,t,n,r,i,a=()=>({}),o=!1){let s=n===void 0?void 0:cO(n);return n!==void 0&&s===void 0?qP:e.transactionSync(()=>{let c=HP(e,t),l=EN(e,{sessionId:t});if(l===void 0)return n===void 0?{kind:`page`,frames:[{kind:`update`,delivery:r,cursor:null,messages:[],terminals:[],compactions:[],compactionNotices:[],activity:i.facts,extensions:a(),attention:JD(e,t),pending:c}],hasMore:!1}:qP;let u=JP(e,l,s);return u===void 0?qP:YP(e,l,u,r,i,a(),JD(e,t),c,o)})}function ZP(e,t,n){let r=MM(e,t,n);if(r===void 0)throw DP(`Accepted Session command is unavailable`);let i=FM(e,t,r.entry.workId),a=AP(e,t,i),o=i.flatMap(e=>{let t=PP(e,a);return t===void 0?[]:[t]}).at(-1);if(o===void 0)return;let s=i.flatMap(({entry:e})=>e.kind===`message`&&e.value.role===`assistant`?[e.value]:[]),c=s.at(-1),l=o.outcome===`cancelled`?o.meta:r.entry.meta,u=fh(r.entry.meta);return{acceptedSender:u?.kind===`agent`?u.id:null,terminal:l===void 0?o:{...o,meta:l},content:o.outcome===`cancelled`?``:c?.content.flatMap(e=>e.type===`text`?[e.text]:[]).join(``).trim()??``,usage:s.map(({provider:e,model:t,usage:n})=>({provider:e,model:t,usage:n})),toolCalls:new Set(i.flatMap(({entry:e})=>e.kind===`tool_intent`?[e.call.id]:[])).size}}var QP=new WeakMap;function $P(e,t,n){let r=QP.get(e)?.get(t);return r?.workId===n?[...r.slots.values()].filter(e=>e!==null):[]}var eF=E(N({droppedBytes:B.check(z(0)),totalBytes:B.check(z(0))}),{onExcessProperty:`error`});function tF(e,t){return x(function*(){let n=yield*rF(e,t),r=()=>{PD(e,t.sessionId,`progress`)};return{started:e=>C(()=>{n.slots.size<4&&!n.slots.has(e.toolCall.value)&&n.slots.set(e.toolCall.value,null)}),update:e=>C(()=>{let t=n.slots.get(e.toolCall.value);if(t===void 0)return;let i=eF(e.result.data);if(xt(i))return;let a=e.result.content.filter(e=>e.type===`text`).map(e=>e.text).join(``);new TextEncoder().encode(a).byteLength>8192||a.split(`
|
|
721
|
+
`).length>200||i.success.droppedBytes>i.success.totalBytes||(n.slots.set(e.toolCall.value,{toolCallId:e.call.id,revision:(t?.revision??0)+1,tail:a,...i.success}),r())}),terminal:e=>C(()=>{n.slots.delete(e.toolCall.value)&&r()})}})}function nF(e){let t=QP.get(e);if(t!==void 0)return t;let n=new Map;return QP.set(e,n),n}function rF(e,t){return x(function*(){let n=nF(e),r=n.get(t.sessionId);if(r?.workId===t.commandId)return r;let i={workId:t.commandId,value:null,slots:new Map};return n.set(t.sessionId,i),yield*vr(()=>C(()=>{n.get(t.sessionId)===i&&(n.delete(t.sessionId),(i.value!==null||i.slots.size>0)&&PD(e,t.sessionId,`progress`))})),i})}function iF(e){return new H(`runtime`,`rejected`,e)}function aF(e,t,n){let r=nF(e).get(t);return r?.workId===n?r.value:null}function oF(e){let t=``,n=``;for(let r of e.value.content)r.type===`text`&&(t+=r.text),r.type===`thinking`&&(n+=r.thinking);return{text:t,thinking:n}}function sF(e,t,n){return x(function*(){let r=yield*rF(e,t),i,a=C(()=>{let n=r.value!==null;r.value=null,n&&PD(e,t.sessionId,`progress`),i=void 0});return yield*vr(()=>a),Object.freeze({started:e=>C(()=>{i=e,r.value=null}),update:n=>bn(()=>{let a=i;if(a===void 0)return y(iF(`Mule progress arrived before its message start`));if(a.run.value!==n.run.value||a.turn.value!==n.turn.value||a.message.value!==n.message.value)return y(iF(`Mule progress identity conflicts`));let o=r.value,s=oF(n);return o?.text===s.text&&o.thinking===s.thinking?_:(r.value=Object.freeze({messageId:n.message.value,revision:(o?.revision??0)+1,text:s.text,thinking:s.thinking,textTruncated:!1,thinkingTruncated:!1}),PD(e,t.sessionId,`progress`),_)}),terminal:e=>a.pipe(Gt(n(e)))})})}var cF=new WeakMap;function lF(e){let t=cF.get(e);if(t!==void 0)return t;let n=new Map;return cF.set(e,n),n}function uF(e,t){return lF(e).get(t)??null}function dF(e,t,n){lF(e).set(t,Object.freeze({trigger:n})),PD(e,t,`progress`)}function fF(e,t){lF(e).delete(t)&&PD(e,t,`progress`)}var pF=Object.freeze({admitNew:()=>{}});function mF(e){return e===void 0?pF:Object.freeze({admitNew:()=>{if(e.underPressure())throw new H(`store`,`storage_pressure`,`Storage is near its budget. New Sessions and prompts are refused until space is freed; running work continues.`)}})}function hF(e,t){let n=eP(e,t);return PD(e,t.sessionId),n}function gF(e,t){let n=tP(e,t);return PD(e,t.sessionId),n}function _F(e,t){let n=nP(e,t);return n!==`stale`&&PD(e,t.sessionId),n}function vF(e){return new H(`store`,`rejected`,e)}function yF(e){return new H(`store`,`conflict`,e)}function $(e){return Qr({try:e,catch:e=>e instanceof H?e:new H(`store`,`rejected`,`Native Session store operation failed`,void 0,e)})}function bF(e){return $(()=>{sN(e)})}function xF(e,t,n,r,i,a,o){return $(()=>{let s=gP(e,t,n,i,a,r,o);return s?.delivery===`new`&&PD(e,t,`settlement`),s})}function SF(e,t){return $(()=>{let n=AM(e,t.sessionId,t.delivery,t.workId);return n.length>0&&PD(e,t.sessionId),n})}function CF(e,t){return $(()=>{jM(e,t),PD(e,t.sessionId,`settlement`)})}function wF(e,t,n,r,i){return $(()=>{let a=hP(e,t,n,r,i);return PD(e,t,`settlement`),a?.accepted})}function TF(e,t){return $(()=>{vP(e,{sessionId:t.sessionId,entryId:t.entryId,assertIdleSession:t.assertIdleSession}),PD(e,t.sessionId)})}function EF(e,t){return $(()=>{yP(e,t)&&PD(e,t.sessionId)})}function DF(e,t){return $(()=>{let n=bP(e,{sessionId:t.sessionId,entryId:t.entryId,assertIdleSession:t.assertIdleSession});return PD(e,n),Object.freeze({sessionId:n})})}function OF(e,t){return $(()=>{let n=QN(e,{sessionId:ay(t.sessionId),commandFactId:t.commandFactId});return n.entryDelivery===`new`&&PD(e,t.sessionId),n})}function kF(e){return e.content.flatMap(e=>e.type===`text`?[e.text]:[]).join(``).trim()}function AF(e,t){return $(()=>{let n=MM(e,t.sessionId,t.commandFactId);if(n===void 0)throw vF(`Accepted Session command is unavailable`);let r=FM(e,t.sessionId,n.entry.workId);for(let e=r.length-1;e>=0;--e){let t=r[e]?.entry;if(t?.kind===`message`&&t.value.role===`assistant`)return kF(t.value)}return``})}function jF(e,t,n){return $(()=>{let r=MM(e,t.sessionId,t.commandFactId);if(r===void 0)throw vF(`Accepted Session command is unavailable`);if(n!==`cancelled`)return r.entry.meta;let i=FM(e,t.sessionId,r.entry.workId).find(({entry:e})=>e.kind===`cancellation`);return i?.entry.kind===`cancellation`?i.entry.meta:void 0})}function MF(e,t){return $(()=>{let n=MM(e,t.sessionId,t.commandFactId);if(n===void 0)throw vF(`Accepted Session command is unavailable`);return NP(FM(e,t.sessionId,n.entry.workId)).get(n.entry.workId)})}function NF(e,t,n,r,i=()=>({})){return $(()=>KP(e,ay(t),cy(r),n,i))}function PF(e,t,n){return $(()=>HM(e,sy({requestId:t}),n))}function FF(e,t,n){return UM(e,sy({requestId:t}),n)}function IF(e,t){return $(()=>WM(e,{sessionId:ay(t.sessionId),assertIdleSession:t.assertIdleSession,recordInboxDeletion:t=>{dj(e,t)}}))}function LF(e,t){return $(()=>gj(e,t))}function RF(e,t,n,r,i,a=()=>({}),o=!1){return $(()=>XP(e,ay(t),n,r,i,a,o))}function zF(e,t){return Ek(e)===Ek(t)}function BF(e,t){return e.kind===t.kind&&e.value===t.value&&e.parent?.kind===t.parent?.kind&&e.parent?.value===t.parent?.value}function VF(e,t){return e.core===t.core&&e.extensions.length===t.extensions.length&&e.extensions.every(([e,n],r)=>{let i=t.extensions[r];return i?.[0]===e&&i[1]===n})}function HF(e,t,n,r,i){e.transactionSync(()=>{i?.();let a=FM(e,t.sessionId,t.commandId).find(r);if(a!==void 0){if(n.kind===`work_terminal`&&a.entry.kind===`run_terminal`||zF(a.entry,n))return`replay`;throw yF(`Mule event identity conflicts`)}for(let r=0;r<3;r+=1){let r=_j.fact.generate();if(yM(e,r)===void 0&&MM(e,t.sessionId,r)===void 0)return fN(e,{sessionId:t.sessionId,id:r,entry:n}),`new`}throw vF(`Session fact identity allocation failed`)})===`new`&&PD(e,t.sessionId,n.kind===`run_terminal`||n.kind===`work_terminal`?`settlement`:`durable`)}function UF(e,t,n){return $(()=>{HF(e,t,{kind:`sandbox_failure`,workId:t.commandId,event:n},({entry:e})=>e.kind===`sandbox_failure`&&e.event.ref===n.ref)})}function WF(e,t,n,r){let i=MM(e,t,n);if(i?.entry.workId!==r)throw vF(`Accepted Session work is unavailable`);return i.origin.kind===`extension`?Object.freeze({extensionId:i.origin.extensionId,correlation:i.origin.correlation}):null}function GF(e,t,n,r){let i=WF(e,t,n,r),a=FM(e,t,r).map(({entry:e})=>e),o=new Set(a.flatMap(e=>e.kind===`tool_intent`?[e.call.id]:[])).size,s=a.filter(e=>e.kind===`run_terminal`||e.kind===`work_terminal`).at(-1);return Object.freeze({terminal:s?.kind===`run_terminal`||s?.kind===`work_terminal`?s.outcome:`missing`,origin:i,toolCalls:o})}function KF(e,t){return $(()=>{if(MM(e,t.sessionId,t.commandFactId)?.entry.workId!==t.workId)throw vF(`Settled Session work is unavailable`);let n={workId:t.workId,kind:`work_terminal`,outcome:t.outcome};HF(e,{sessionId:t.sessionId,commandId:t.workId},t.diagnostic===void 0?n:{...n,diagnostic:t.diagnostic},({entry:e})=>e.kind===`work_terminal`||e.kind===`run_terminal`&&e.outcome===t.outcome,()=>{e.sql.exec(`DELETE FROM session_entries WHERE session_id = ? AND work_id = ? AND state = 'streaming' AND type = 'message_start'`,t.sessionId,t.workId)})})}function qF(e,t,n,r,i){return $(()=>{let a=r.type===`run_start`?{kind:`run_started`,workId:t.commandId,run:r.run,contract:n}:r.type===`turn_start`?{kind:`turn_started`,workId:t.commandId,run:r.run,turn:r.turn}:{kind:`run_terminal`,workId:t.commandId,run:r.run,terminal:r.terminal,outcome:r.outcome};a.kind===`run_terminal`&&i!==void 0&&(a={...a,diagnostic:i}),HF(e,t,a,({entry:e})=>e.kind===a.kind?e.kind===`run_started`&&a.kind===`run_started`?BF(e.run,a.run)&&VF(e.contract,n):e.kind===`turn_started`&&a.kind===`turn_started`?BF(e.turn,a.turn):e.kind===`run_terminal`&&a.kind===`run_terminal`&&BF(e.terminal,a.terminal):!1)})}function JF(e,t,n){return $(()=>{let r={kind:`message_start`,workId:t.commandId,run:n.run,turn:n.turn,message:n.message,role:n.value.role};e.transactionSync(()=>{let i=FM(e,t.sessionId,t.commandId).find(({entry:e})=>(e.kind===`message_start`||e.kind===`message`)&&BF(e.message,n.message));if(i!==void 0){if(i.entry.kind===`message`){if(i.entry.workId!==r.workId||!BF(i.entry.run,r.run)||!BF(i.entry.turn,r.turn)||i.entry.value.role!==r.role)throw yF(`Mule message-start identity conflicts`);return`replay`}if(!zF(i.entry,r))throw yF(`Mule message-start identity conflicts`);return`replay`}return fN(e,{sessionId:t.sessionId,id:n.message.value,entry:r,state:`streaming`}),`new`})===`new`&&PD(e,t.sessionId)})}function YF(e,t,n,r){return $(()=>{HF(e,t,{kind:`model_prompt`,workId:t.commandId,run:r.run,turn:r.turn,attempt:r.attempt,contract:n,systemPrompt:r.systemPrompt},({entry:e})=>e.kind===`model_prompt`&&BF(e.turn,r.turn)&&e.attempt===r.attempt&&VF(e.contract,n))})}function XF(e,t,n){return $(()=>{let r={kind:`message`,workId:t.commandId,run:n.run,turn:n.turn,message:n.message,value:n.value},i=n.data===void 0?r:{...r,data:n.data};e.transactionSync(()=>{let r=FM(e,t.sessionId,t.commandId).find(({entry:e})=>(e.kind===`message_start`||e.kind===`message`)&&BF(e.message,n.message));if(r?.entry.kind===`message`){if(!zF(r.entry,i))throw yF(`Mule completed-message identity conflicts`);return`replay`}return pN(e,{sessionId:t.sessionId,id:n.message.value,entry:i}),`new`})===`new`&&PD(e,t.sessionId)})}function ZF(e,t,n,r){return $(()=>{HF(e,t,{kind:`tool_intent`,replay:r.replay,contract:n,workId:t.commandId,run:r.run,turn:r.turn,toolCall:r.toolCall,call:r.call},({entry:e})=>e.kind===`tool_intent`&&BF(e.toolCall,r.toolCall)&&VF(e.contract,n))})}function QF(e,t,n){return $(()=>{let{data:r,...i}=n.result,a={kind:`tool_outcome`,workId:t.commandId,run:n.run,turn:n.turn,toolCall:n.toolCall,call:n.call,result:i};HF(e,t,r===void 0?a:{...a,data:r},({entry:e})=>e.kind===`tool_outcome`&&BF(e.toolCall,n.toolCall))})}function $F(e,t,n,r){return $(()=>{let i=FM(e,t.sessionId,t.commandId).find(({entry:e})=>e.kind===`turn_started`&&BF(e.turn,r));if(i===void 0)throw yF(`Retry has no recorded turn`);HF(e,t,{kind:`live_retry`,workId:t.commandId,event:n},({entry:e,sequence:t})=>t>i.sequence&&e.kind===`live_retry`&&e.event.type===n.type&&e.event.attempt===n.attempt&&BF(e.event.run,n.run))}).pipe(it(eI))}var eI=()=>({_tag:`MuleError`,phase:`listener`,message:`Woodstock could not record the Mule event`});function tI(e,t,n){return x(function*(){let r=yield*sF(e,t,n=>XF(e,t,n)),i=yield*tF(e,t),a=(a,o)=>{switch(a.type){case`model_prompt`:return YF(e,t,n,a);case`run_start`:case`turn_start`:case`run_end`:return qF(e,t,n,a,o);case`message_start`:return a.value.role===`user`?_:JF(e,t,a).pipe(Gt(a.value.role===`assistant`?r.started(a):_));case`message_update`:return r.update(a);case`message_end`:return a.value.role===`user`?_:a.value.role===`assistant`?r.terminal(a):XF(e,t,a);case`tool_execution_start`:return ZF(e,t,n,a).pipe(Gt(i.started(a)));case`tool_execution_end`:return QF(e,t,a).pipe(Gt(i.terminal(a)));case`tool_execution_update`:return i.update(a);case`turn_end`:return _}};return(e,t)=>a(e,t).pipe(it(eI))})}function nI(e,t,n){return $(()=>ZP(e,ay(t),ay(n)))}var rI=j.pipe(L(jm(1)),L(V(128)),L(Xp(/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/u))),iI=j.pipe(L(jm(1)),L(V(64)),L(Xp(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u))),aI=rI.pipe(Rp(`ExtensionId`)),oI=j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)),Rp(`ExtensionRevision`)),sI=j.pipe(L(Xp(/^sha256:[0-9a-f]{64}$/u)),Rp(`ExtensionFingerprint`)),cI=class extends Ei(`ExtensionHookError`){};function lI(e){return bn(()=>{let t=e();return Ve(t)?t:Vr({try:()=>Promise.resolve(t),catch:e=>new cI({cause:e})})})}var uI=class extends Error{constructor(){super(`Extension transaction handler must return synchronously`),this.name=`AsyncExtensionTransactionError`}};function dI(e,t){let r=e(t);if(r instanceof Promise||Ve(r)&&!n(r))throw new uI;return r}export{mM as $,Ri as $a,Xp as $i,H as $n,Fp as $r,qk as $t,jF as A,os as Aa,fm as Ai,nE as An,wp as Ar,hA as At,uF as B,la as Ba,Cm as Bi,pw as Bn,Mp as Br,Uk as Bt,WF as C,Rs as Ca,Lm as Ci,SD as Cn,Qh as Cr,OA as Ct,GF as D,mu as Da,Hm as Di,hD as Dn,fh as Dr,pA as Dt,RF as E,hu as Ea,Gm as Ei,vD as En,_h as Er,fA as Et,CF as F,oa as Fa,Sm as Fi,wT as Fn,sh as Fr,MA as Ft,nN as G,Wi as Ga,V as Gi,oy as Gn,Op as Gr,tA as Gt,$P as H,ea as Ha,km as Hi,bw as Hn,Sp as Hr,zk as Ht,SF as I,da as Ia,rm as Ii,xT as In,A as Ir,sA as It,wM as J,Yi as Ja,Fm as Ji,sy as Jn,Tp as Jr,Kk as Jt,Ij as K,Ji as Ka,Wm as Ki,cy as Kn,j as Kr,Bk as Kt,mF as L,ma as La,_m as Li,hT as Ln,F as Lr,iA as Lt,EF as M,ls as Ma,xm as Mi,QT as Mn,im as Mr,wA as Mt,UF as N,no as Na,z as Ni,bT as Nn,B as Nr,TA as Nt,AF as O,Wl as Oa,nm as Oi,cD as On,jp as Or,gA as Ot,KF as P,wa as Pa,Dm as Pi,TT as Pn,oh as Pr,EA as Pt,kM as Q,ji as Qa,gm as Qi,uy as Qn,Cp as Qr,Hk as Qt,dF as R,fa as Ra,pm as Ri,gT as Rn,vm as Rr,Gk as Rt,nI as S,Bs as Sa,Am as Si,DD as Sn,tg as Sr,kA as St,LF as T,pu as Ta,Pm as Ti,yD as Tn,Ph as Tr,AA as Tt,UP as U,ia as Ua,wm as Ui,kv as Un,I as Ur,Wk as Ut,aF as V,ta as Va,mm as Vi,fw as Vn,Km as Vr,Zk as Vt,Lj as W,Xi as Wa,Im as Wi,ty as Wn,M as Wr,rA as Wt,ZN as X,Mi as Xa,Um as Xi,Nv as Xn,Ap as Xr,$k as Xt,dP as Y,Ki as Ya,jm as Yi,ay as Yn,$m as Yr,Jk as Yt,$N as Z,Vi as Za,Bm as Zi,ly as Zn,th as Zr,nA as Zt,DF as _,yu as _a,fp as _i,XD as _n,Ag as _r,pj as _t,sI as a,Lp as aa,qf as ai,yk as an,mv as ar,PM as at,_F as b,Vs as ba,rp as bi,FD as bn,Dg as br,VA as bt,iI as c,ah as ca,ip as ci,nk as cn,L_ as cr,EN as ct,gF as d,tp as da,E as di,PO as dn,av as dr,uN as dt,tm as ea,P as ei,Yk as en,Li as eo,Cv as er,LM as et,TF as f,Wp as fa,cp as fi,OO as fn,q_ as fr,dN as ft,IF as g,Hs as ga,dp as gi,$D as gn,G_ as gr,yj as gt,FF as h,Gs as ha,Bp as hi,QD as hn,lv as hr,SP as ht,aI as i,O as ia,Jf as ii,Ck as in,Ei as io,hv as ir,IM as it,$F as j,ss as ja,Em as ji,kE as jn,Jm as jr,_A as jt,MF as k,ks as ka,am as ki,lD as kn,Ep as kr,mA as kt,wF as l,ih as la,ap as li,RO as ln,ov as lr,cN as lt,PF as m,Ys as ma,hp as mi,ZD as mn,tv as mr,XN as mt,lI as n,R as na,Rp as ni,YO as nn,zi as no,yv as nr,CM as nt,rI as o,Ip as oa,sp as oi,Sk as on,I_ as or,qN as ot,xF as p,Ku as pa,pp as pi,FO as pn,W_ as pr,fP as pt,uP as q,qi as qa,Vm as qi,ny as qn,N as qr,Vk as qt,dI as r,k as ra,L as ri,ok as rn,Fi as ro,fv as rr,lN as rt,oI as s,Gp as sa,lp as si,bk as sn,nv as sr,xP as st,uI as t,Qp as ta,xp as ti,Xk as tn,Ni as to,vv as tr,RM as tt,hF as u,rh as ua,op as ui,IO as un,B_ as ur,iN as ut,OF as v,Us as va,Xm as vi,jD as vn,kg as vr,fj as vt,NF as w,qs as wa,Tm as wi,TD as wn,Zh as wr,jA as wt,bF as x,Ks as xa,hm as xi,PD as xn,Eg as xr,DA as xt,tI as y,Ls as ya,Kp as yi,ID as yn,Tg as yr,zA as yt,fF as z,sa as za,Om as zi,uT as zn,bp as zr,Qk as zt};
|