@telepath-computer/television 0.1.27 → 0.1.28

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.
@@ -1,6 +1,6 @@
1
- var Dd=Object.defineProperty;var Ya=e=>{throw TypeError(e)};var Ld=(e,t,n)=>t in e?Dd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>Ld(e,typeof t!="symbol"?t+"":t,n),Ci=(e,t,n)=>t.has(e)||Ya("Cannot "+n);var d=(e,t,n)=>(Ci(e,t,"read from private field"),n?n.call(e):t.get(e)),I=(e,t,n)=>t.has(e)?Ya("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),C=(e,t,n,s)=>(Ci(e,t,"write to private field"),s?s.call(e,n):t.set(e,n),n),y=(e,t,n)=>(Ci(e,t,"access private method"),n);var Xa=(e,t,n,s)=>({set _(r){C(e,t,r,n)},get _(){return d(e,t,s)}});(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=n(r);fetch(r.href,i)}})();const Ja=new WeakMap;function Md(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&"then"in e&&typeof e.then=="function"}function yn(e){return typeof e=="string"?e:typeof e=="symbol"?e.description??e.toString():e.name||"(anonymous class)"}function Qa(){return new Error("register(Key, factory) requires a factory function. Wrap existing instances as () => instance.")}function Od(){return new Error("register(Key, factory) does not accept async factories. Await setup before registering.")}class Nd{constructor(){m(this,"entries",new Map);m(this,"constructionStack",[])}register(t,n){if(n===void 0){if(typeof t!="function")throw Qa();this.validateClassRegistration(t),this.storeFactory(t,()=>this.instantiateClass(t));return}if(typeof n!="function")throw Qa();if(n.constructor.name==="AsyncFunction")throw Od();this.storeFactory(t,n)}has(t){var n;return((n=this.entries.get(t))==null?void 0:n.factory)!==void 0}resolve(t){return this.resolveAny(t)}storeFactory(t,n){const s=this.getOrCreateEntry(t);s.factory=n,s.instance=void 0,s.error=void 0}validateClassRegistration(t){const n=Ja.get(t);if(n){if(t.length!==n.length)throw new Error(`${yn(t)} cannot be registered with register(Class). @injectable(...) declared ${n.length} dependencies but constructor arity is ${t.length}. Use register(Key, () => value) instead.`);return}if(t.length!==0)throw new Error(`${yn(t)} cannot be registered with register(Class). Undecorated classes must have zero required constructor parameters. Use register(Key, () => value) instead.`)}instantiateClass(t){const n=Ja.get(t);if(!n)return new t;const s=n.map(r=>this.resolveAny(r));return new t(...s)}resolveAny(t){return this.getOrCreateEntry(t).proxy}getOrCreateEntry(t){let n=this.entries.get(t);return n||(n={key:t},n.proxy=this.createProxy(n),this.entries.set(t,n),n)}createProxy(t){return new Proxy({},{get:(n,s)=>{if(s==="then")return;const r=this.getInstance(t),i=Reflect.get(r,s,r);return typeof i=="function"?i.bind(r):i},set:(n,s,r)=>{const i=this.getInstance(t);return Reflect.set(i,s,r,i)},has:(n,s)=>{const r=this.getInstance(t);return s in r}})}getInstance(t){if(t.instance)return t.instance;if(t.error)throw t.error;if(!t.factory)throw new Error(`${yn(t.key)} was resolved but never registered`);const n=this.constructionStack.indexOf(t.key);if(n!==-1){const s=[...this.constructionStack.slice(n),t.key].map(r=>yn(r)).join(" -> ");throw new Error(`Circular dependency detected: ${s}`)}this.constructionStack.push(t.key);try{const s=t.factory();if(Md(s))throw new Error(`Factory for ${yn(t.key)} returned a Promise. Await setup before registering.`);if(typeof s!="object"||s===null)throw new Error(`Factory for ${yn(t.key)} returned a non-object value. Wrap primitives in an object.`);return t.instance=s,s}catch(s){throw t.error=s,s}finally{this.constructionStack.pop()}}}const Ze=new Nd,Wd=new Set(["target","currentTarget","eventPhase","defaultPrevented","isTrusted","timeStamp","srcElement","returnValue","cancelBubble","NONE","CAPTURING_PHASE","AT_TARGET","BUBBLING_PHASE","composedPath","stopPropagation","stopImmediatePropagation","preventDefault","initEvent"]);function Fd(e){for(const t of Object.keys(e))if(Wd.has(t))throw new Error(`Event payload key "${t}" is reserved; choose a different property name`)}function Ud(e,t){Fd(t);for(const n of Object.keys(t))Object.defineProperty(e,n,{value:t[n],writable:!0,enumerable:!0,configurable:!0})}function rt(){class e extends Event{constructor(n,s){const{type:r,bubbles:i,cancelable:o,composed:a,...c}=s??{};if(r!==void 0)throw new Error('Do not pass "type" in init; use the constructor argument instead');super(n,{bubbles:i,cancelable:o,composed:a}),Ud(this,c)}}return e}class ln extends globalThis.EventTarget{}const B=rt(),yl=rt(),es=rt(),kl="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Pr=32,Zd=16,wl=10,ec=0xffffffffffff;var Bt;(function(e){e.Base32IncorrectEncoding="B32_ENC_INVALID",e.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",e.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",e.EncodeTimeNegative="ENC_TIME_NEG",e.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",e.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",e.PRNGDetectFailure="PRNG_DETECT",e.ULIDInvalid="ULID_INVALID",e.Unexpected="UNEXPECTED",e.UUIDInvalid="UUID_INVALID"})(Bt||(Bt={}));class us extends Error{constructor(t,n){super(`${n} (${t})`),this.name="ULIDError",this.code=t}}function jd(e){const t=Math.floor(e()*Pr)%Pr;return kl.charAt(t)}function Hd(e){const t=Bd(),n=t&&(t.crypto||t.msCrypto)||null;if(typeof(n==null?void 0:n.getRandomValues)=="function")return()=>{const s=new Uint8Array(1);return n.getRandomValues(s),s[0]/256};if(typeof(n==null?void 0:n.randomBytes)=="function")return()=>n.randomBytes(1).readUInt8()/256;throw new us(Bt.PRNGDetectFailure,"Failed to find a reliable PRNG")}function Bd(){return qd()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function Vd(e,t){let n="";for(;e>0;e--)n=jd(t)+n;return n}function Gd(e,t=wl){if(isNaN(e))throw new us(Bt.EncodeTimeValueMalformed,`Time must be a number: ${e}`);if(e>ec)throw new us(Bt.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ec}: ${e}`);if(e<0)throw new us(Bt.EncodeTimeNegative,`Time must be positive: ${e}`);if(Number.isInteger(e)===!1)throw new us(Bt.EncodeTimeValueMalformed,`Time must be an integer: ${e}`);let n,s="";for(let r=t;r>0;r--)n=e%Pr,s=kl.charAt(n)+s,e=(e-n)/Pr;return s}function qd(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function en(e,t){const n=Hd(),s=Date.now();return Gd(s,wl)+Vd(Zd,n)}function b(e,t,n){function s(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const l=o.prototype,h=Object.keys(l);for(let f=0;f<h.length;f++){const w=h[f];w in a||(a[w]=l[w].bind(a))}}const r=(n==null?void 0:n.Parent)??Object;class i extends r{}Object.defineProperty(i,"name",{value:e});function o(a){var c;const l=n!=null&&n.Parent?new i:this;s(l,a),(c=l._zod).deferred??(c.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(o,"init",{value:s}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,l;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(l=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:l.has(e)}}),Object.defineProperty(o,"name",{value:e}),o}class Cn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class bl extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Sl={};function It(e){return Sl}function xl(e){const t=Object.values(e).filter(s=>typeof s=="number");return Object.entries(e).filter(([s,r])=>t.indexOf(+s)===-1).map(([s,r])=>r)}function Xi(e,t){return typeof t=="bigint"?t.toString():t}function ei(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function jo(e){return e==null}function Ho(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Kd(e,t){const n=(e.toString().split(".")[1]||"").length,s=t.toString();let r=(s.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(s)){const c=s.match(/\d?e-(\d?)/);c!=null&&c[1]&&(r=Number.parseInt(c[1]))}const i=n>r?n:r,o=Number.parseInt(e.toFixed(i).replace(".","")),a=Number.parseInt(t.toFixed(i).replace(".",""));return o%a/10**i}const tc=Symbol("evaluating");function q(e,t,n){let s;Object.defineProperty(e,t,{get(){if(s!==tc)return s===void 0&&(s=tc,s=n()),s},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function un(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Pt(...e){const t={};for(const n of e){const s=Object.getOwnPropertyDescriptors(n);Object.assign(t,s)}return Object.defineProperties({},t)}function nc(e){return JSON.stringify(e)}function Yd(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const El="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ys(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Xd=ei(()=>{var e;if(typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)!=null&&e.includes("Cloudflare")))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Fn(e){if(ys(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ys(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Al(e){return Fn(e)?{...e}:Array.isArray(e)?[...e]:e}const Jd=new Set(["string","number","symbol"]);function Un(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dt(e,t,n){const s=new e._zod.constr(t??e._zod.def);return(!t||n!=null&&n.parent)&&(s._zod.parent=e),s}function P(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if((t==null?void 0:t.message)!==void 0){if((t==null?void 0:t.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Qd(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const ep={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function tp(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return un(this,"shape",o),o},checks:[]});return Dt(e,i)}function np(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return un(this,"shape",o),o},checks:[]});return Dt(e,i)}function sp(e,t){if(!Fn(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const i=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Pt(e._zod.def,{get shape(){const i={...e._zod.def.shape,...t};return un(this,"shape",i),i}});return Dt(e,r)}function rp(e,t){if(!Fn(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return un(this,"shape",s),s}});return Dt(e,n)}function ip(e,t){const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t._zod.def.shape};return un(this,"shape",s),s},get catchall(){return t._zod.def.catchall},checks:[]});return Dt(e,n)}function op(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Pt(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const l in n){if(!(l in a))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(c[l]=e?new e({type:"optional",innerType:a[l]}):a[l])}else for(const l in a)c[l]=e?new e({type:"optional",innerType:a[l]}):a[l];return un(this,"shape",c),c},checks:[]});return Dt(t,o)}function ap(e,t,n){const s=Pt(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new e({type:"nonoptional",innerType:r[o]}))}else for(const o in r)i[o]=new e({type:"nonoptional",innerType:r[o]});return un(this,"shape",i),i}});return Dt(t,s)}function An(e,t=0){var n;if(e.aborted===!0)return!0;for(let s=t;s<e.issues.length;s++)if(((n=e.issues[s])==null?void 0:n.continue)!==!0)return!0;return!1}function Tn(e,t){return t.map(n=>{var s;return(s=n).path??(s.path=[]),n.path.unshift(e),n})}function lr(e){return typeof e=="string"?e:e==null?void 0:e.message}function Ct(e,t,n){var r,i,o,a,c,l;const s={...e,path:e.path??[]};if(!e.message){const h=lr((o=(i=(r=e.inst)==null?void 0:r._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,e))??lr((a=t==null?void 0:t.error)==null?void 0:a.call(t,e))??lr((c=n.customError)==null?void 0:c.call(n,e))??lr((l=n.localeError)==null?void 0:l.call(n,e))??"Invalid input";s.message=h}return delete s.inst,delete s.continue,t!=null&&t.reportInput||delete s.input,s}function Bo(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function ks(...e){const[t,n,s]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:s}:{...t}}const Tl=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Xi,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Il=b("$ZodError",Tl),Cl=b("$ZodError",Tl,{Parent:Error});function cp(e,t=n=>n.message){const n={},s=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):s.push(t(r));return{formErrors:s,fieldErrors:n}}function lp(e,t=n=>n.message){const n={_errors:[]},s=r=>{for(const i of r.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>s({issues:o}));else if(i.code==="invalid_key")s({issues:i.issues});else if(i.code==="invalid_element")s({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return s(e),n}const Vo=e=>(t,n,s,r)=>{const i=s?Object.assign(s,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new Cn;if(o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>Ct(c,i,It())));throw El(a,r==null?void 0:r.callee),a}return o.value},Go=e=>async(t,n,s,r)=>{const i=s?Object.assign(s,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>Ct(c,i,It())));throw El(a,r==null?void 0:r.callee),a}return o.value},ti=e=>(t,n,s)=>{const r=s?{...s,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},r);if(i instanceof Promise)throw new Cn;return i.issues.length?{success:!1,error:new(e??Il)(i.issues.map(o=>Ct(o,r,It())))}:{success:!0,data:i.value}},up=ti(Cl),ni=e=>async(t,n,s)=>{const r=s?Object.assign(s,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(o=>Ct(o,r,It())))}:{success:!0,data:i.value}},hp=ni(Cl),dp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Vo(e)(t,n,r)},pp=e=>(t,n,s)=>Vo(e)(t,n,s),fp=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Go(e)(t,n,r)},gp=e=>async(t,n,s)=>Go(e)(t,n,s),mp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return ti(e)(t,n,r)},vp=e=>(t,n,s)=>ti(e)(t,n,s),_p=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return ni(e)(t,n,r)},yp=e=>async(t,n,s)=>ni(e)(t,n,s),kp=/^[cC][^\s-]{8,}$/,wp=/^[0-9a-z]+$/,bp=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sp=/^[0-9a-vA-V]{20}$/,xp=/^[A-Za-z0-9]{27}$/,Ep=/^[a-zA-Z0-9_-]{21}$/,Ap=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Tp=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,sc=e=>e?new 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|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Ip=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Cp="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function zp(){return new RegExp(Cp,"u")}const $p=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Rp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Pp=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Dp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Lp=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,zl=/^[A-Za-z0-9_-]*$/,Mp=/^\+[1-9]\d{6,14}$/,$l="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Op=new RegExp(`^${$l}$`);function Rl(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Np(e){return new RegExp(`^${Rl(e)}$`)}function Wp(e){const t=Rl({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const s=`${t}(?:${n.join("|")})`;return new RegExp(`^${$l}T(?:${s})$`)}const Fp=e=>{const t=e?`[\\s\\S]{${(e==null?void 0:e.minimum)??0},${(e==null?void 0:e.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Up=/^-?\d+$/,Pl=/^-?\d+(?:\.\d+)?$/,Zp=/^(?:true|false)$/i,jp=/^[^A-Z]*$/,Hp=/^[^a-z]*$/,Le=b("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Dl={number:"number",bigint:"bigint",object:"date"},Ll=b("$ZodCheckLessThan",(e,t)=>{Le.init(e,t);const n=Dl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?r.maximum=t.value:r.exclusiveMaximum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value<=t.value:s.value<t.value)||s.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ml=b("$ZodCheckGreaterThan",(e,t)=>{Le.init(e,t);const n=Dl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?r.minimum=t.value:r.exclusiveMinimum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value>=t.value:s.value>t.value)||s.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Bp=b("$ZodCheckMultipleOf",(e,t)=>{Le.init(e,t),e._zod.onattach.push(n=>{var s;(s=n._zod.bag).multipleOf??(s.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):Kd(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Vp=b("$ZodCheckNumberFormat",(e,t)=>{var o;Le.init(e,t),t.format=t.format||"float64";const n=(o=t.format)==null?void 0:o.includes("int"),s=n?"int":"number",[r,i]=ep[t.format];e._zod.onattach.push(a=>{const c=a._zod.bag;c.format=t.format,c.minimum=r,c.maximum=i,n&&(c.pattern=Up)}),e._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:s,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort});return}}c<r&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),Gp=b("$ZodCheckMaxLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(s._zod.bag.maximum=t.maximum)}),e._zod.check=s=>{const r=s.value;if(r.length<=t.maximum)return;const o=Bo(r);s.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),qp=b("$ZodCheckMinLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(s._zod.bag.minimum=t.minimum)}),e._zod.check=s=>{const r=s.value;if(r.length>=t.minimum)return;const o=Bo(r);s.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Kp=b("$ZodCheckLengthEquals",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=s=>{const r=s.value,i=r.length;if(i===t.length)return;const o=Bo(r),a=i>t.length;s.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:s.value,inst:e,continue:!t.abort})}}),si=b("$ZodCheckStringFormat",(e,t)=>{var n,s;Le.init(e,t),e._zod.onattach.push(r=>{const i=r._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(s=e._zod).check??(s.check=()=>{})}),Yp=b("$ZodCheckRegex",(e,t)=>{si.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Xp=b("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=jp),si.init(e,t)}),Jp=b("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Hp),si.init(e,t)}),Qp=b("$ZodCheckIncludes",(e,t)=>{Le.init(e,t);const n=Un(t.includes),s=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=s,e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(s)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),ef=b("$ZodCheckStartsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`^${Un(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.startsWith(t.prefix)||s.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:s.value,inst:e,continue:!t.abort})}}),tf=b("$ZodCheckEndsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`.*${Un(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.endsWith(t.suffix)||s.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:s.value,inst:e,continue:!t.abort})}}),nf=b("$ZodCheckOverwrite",(e,t)=>{Le.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class sf{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const s=t.split(`
1
+ var Dd=Object.defineProperty;var Ya=e=>{throw TypeError(e)};var Ld=(e,t,n)=>t in e?Dd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>Ld(e,typeof t!="symbol"?t+"":t,n),Ci=(e,t,n)=>t.has(e)||Ya("Cannot "+n);var d=(e,t,n)=>(Ci(e,t,"read from private field"),n?n.call(e):t.get(e)),I=(e,t,n)=>t.has(e)?Ya("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),C=(e,t,n,s)=>(Ci(e,t,"write to private field"),s?s.call(e,n):t.set(e,n),n),y=(e,t,n)=>(Ci(e,t,"access private method"),n);var Xa=(e,t,n,s)=>({set _(r){C(e,t,r,n)},get _(){return d(e,t,s)}});(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=n(r);fetch(r.href,i)}})();const Ja=new WeakMap;function Md(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&"then"in e&&typeof e.then=="function"}function yn(e){return typeof e=="string"?e:typeof e=="symbol"?e.description??e.toString():e.name||"(anonymous class)"}function Qa(){return new Error("register(Key, factory) requires a factory function. Wrap existing instances as () => instance.")}function Od(){return new Error("register(Key, factory) does not accept async factories. Await setup before registering.")}class Nd{constructor(){m(this,"entries",new Map);m(this,"constructionStack",[])}register(t,n){if(n===void 0){if(typeof t!="function")throw Qa();this.validateClassRegistration(t),this.storeFactory(t,()=>this.instantiateClass(t));return}if(typeof n!="function")throw Qa();if(n.constructor.name==="AsyncFunction")throw Od();this.storeFactory(t,n)}has(t){var n;return((n=this.entries.get(t))==null?void 0:n.factory)!==void 0}resolve(t){return this.resolveAny(t)}storeFactory(t,n){const s=this.getOrCreateEntry(t);s.factory=n,s.instance=void 0,s.error=void 0}validateClassRegistration(t){const n=Ja.get(t);if(n){if(t.length!==n.length)throw new Error(`${yn(t)} cannot be registered with register(Class). @injectable(...) declared ${n.length} dependencies but constructor arity is ${t.length}. Use register(Key, () => value) instead.`);return}if(t.length!==0)throw new Error(`${yn(t)} cannot be registered with register(Class). Undecorated classes must have zero required constructor parameters. Use register(Key, () => value) instead.`)}instantiateClass(t){const n=Ja.get(t);if(!n)return new t;const s=n.map(r=>this.resolveAny(r));return new t(...s)}resolveAny(t){return this.getOrCreateEntry(t).proxy}getOrCreateEntry(t){let n=this.entries.get(t);return n||(n={key:t},n.proxy=this.createProxy(n),this.entries.set(t,n),n)}createProxy(t){return new Proxy({},{get:(n,s)=>{if(s==="then")return;const r=this.getInstance(t),i=Reflect.get(r,s,r);return typeof i=="function"?i.bind(r):i},set:(n,s,r)=>{const i=this.getInstance(t);return Reflect.set(i,s,r,i)},has:(n,s)=>{const r=this.getInstance(t);return s in r}})}getInstance(t){if(t.instance)return t.instance;if(t.error)throw t.error;if(!t.factory)throw new Error(`${yn(t.key)} was resolved but never registered`);const n=this.constructionStack.indexOf(t.key);if(n!==-1){const s=[...this.constructionStack.slice(n),t.key].map(r=>yn(r)).join(" -> ");throw new Error(`Circular dependency detected: ${s}`)}this.constructionStack.push(t.key);try{const s=t.factory();if(Md(s))throw new Error(`Factory for ${yn(t.key)} returned a Promise. Await setup before registering.`);if(typeof s!="object"||s===null)throw new Error(`Factory for ${yn(t.key)} returned a non-object value. Wrap primitives in an object.`);return t.instance=s,s}catch(s){throw t.error=s,s}finally{this.constructionStack.pop()}}}const Ze=new Nd,Wd=new Set(["target","currentTarget","eventPhase","defaultPrevented","isTrusted","timeStamp","srcElement","returnValue","cancelBubble","NONE","CAPTURING_PHASE","AT_TARGET","BUBBLING_PHASE","composedPath","stopPropagation","stopImmediatePropagation","preventDefault","initEvent"]);function Fd(e){for(const t of Object.keys(e))if(Wd.has(t))throw new Error(`Event payload key "${t}" is reserved; choose a different property name`)}function Ud(e,t){Fd(t);for(const n of Object.keys(t))Object.defineProperty(e,n,{value:t[n],writable:!0,enumerable:!0,configurable:!0})}function rt(){class e extends Event{constructor(n,s){const{type:r,bubbles:i,cancelable:o,composed:a,...c}=s??{};if(r!==void 0)throw new Error('Do not pass "type" in init; use the constructor argument instead');super(n,{bubbles:i,cancelable:o,composed:a}),Ud(this,c)}}return e}class ln extends globalThis.EventTarget{}const yl="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Pr=32,Zd=16,kl=10,ec=0xffffffffffff;var Bt;(function(e){e.Base32IncorrectEncoding="B32_ENC_INVALID",e.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",e.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",e.EncodeTimeNegative="ENC_TIME_NEG",e.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",e.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",e.PRNGDetectFailure="PRNG_DETECT",e.ULIDInvalid="ULID_INVALID",e.Unexpected="UNEXPECTED",e.UUIDInvalid="UUID_INVALID"})(Bt||(Bt={}));class us extends Error{constructor(t,n){super(`${n} (${t})`),this.name="ULIDError",this.code=t}}function jd(e){const t=Math.floor(e()*Pr)%Pr;return yl.charAt(t)}function Hd(e){const t=Bd(),n=t&&(t.crypto||t.msCrypto)||null;if(typeof(n==null?void 0:n.getRandomValues)=="function")return()=>{const s=new Uint8Array(1);return n.getRandomValues(s),s[0]/256};if(typeof(n==null?void 0:n.randomBytes)=="function")return()=>n.randomBytes(1).readUInt8()/256;throw new us(Bt.PRNGDetectFailure,"Failed to find a reliable PRNG")}function Bd(){return qd()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function Vd(e,t){let n="";for(;e>0;e--)n=jd(t)+n;return n}function Gd(e,t=kl){if(isNaN(e))throw new us(Bt.EncodeTimeValueMalformed,`Time must be a number: ${e}`);if(e>ec)throw new us(Bt.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ec}: ${e}`);if(e<0)throw new us(Bt.EncodeTimeNegative,`Time must be positive: ${e}`);if(Number.isInteger(e)===!1)throw new us(Bt.EncodeTimeValueMalformed,`Time must be an integer: ${e}`);let n,s="";for(let r=t;r>0;r--)n=e%Pr,s=yl.charAt(n)+s,e=(e-n)/Pr;return s}function qd(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function en(e,t){const n=Hd(),s=Date.now();return Gd(s,kl)+Vd(Zd,n)}function b(e,t,n){function s(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const l=o.prototype,h=Object.keys(l);for(let f=0;f<h.length;f++){const w=h[f];w in a||(a[w]=l[w].bind(a))}}const r=(n==null?void 0:n.Parent)??Object;class i extends r{}Object.defineProperty(i,"name",{value:e});function o(a){var c;const l=n!=null&&n.Parent?new i:this;s(l,a),(c=l._zod).deferred??(c.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(o,"init",{value:s}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,l;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(l=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:l.has(e)}}),Object.defineProperty(o,"name",{value:e}),o}class Cn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class wl extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const bl={};function It(e){return bl}function Sl(e){const t=Object.values(e).filter(s=>typeof s=="number");return Object.entries(e).filter(([s,r])=>t.indexOf(+s)===-1).map(([s,r])=>r)}function Xi(e,t){return typeof t=="bigint"?t.toString():t}function ei(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function jo(e){return e==null}function Ho(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Kd(e,t){const n=(e.toString().split(".")[1]||"").length,s=t.toString();let r=(s.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(s)){const c=s.match(/\d?e-(\d?)/);c!=null&&c[1]&&(r=Number.parseInt(c[1]))}const i=n>r?n:r,o=Number.parseInt(e.toFixed(i).replace(".","")),a=Number.parseInt(t.toFixed(i).replace(".",""));return o%a/10**i}const tc=Symbol("evaluating");function q(e,t,n){let s;Object.defineProperty(e,t,{get(){if(s!==tc)return s===void 0&&(s=tc,s=n()),s},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function un(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Pt(...e){const t={};for(const n of e){const s=Object.getOwnPropertyDescriptors(n);Object.assign(t,s)}return Object.defineProperties({},t)}function nc(e){return JSON.stringify(e)}function Yd(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const xl="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ys(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Xd=ei(()=>{var e;if(typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)!=null&&e.includes("Cloudflare")))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Fn(e){if(ys(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ys(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function El(e){return Fn(e)?{...e}:Array.isArray(e)?[...e]:e}const Jd=new Set(["string","number","symbol"]);function Un(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dt(e,t,n){const s=new e._zod.constr(t??e._zod.def);return(!t||n!=null&&n.parent)&&(s._zod.parent=e),s}function P(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if((t==null?void 0:t.message)!==void 0){if((t==null?void 0:t.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Qd(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const ep={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function tp(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return un(this,"shape",o),o},checks:[]});return Dt(e,i)}function np(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return un(this,"shape",o),o},checks:[]});return Dt(e,i)}function sp(e,t){if(!Fn(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const i=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Pt(e._zod.def,{get shape(){const i={...e._zod.def.shape,...t};return un(this,"shape",i),i}});return Dt(e,r)}function rp(e,t){if(!Fn(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return un(this,"shape",s),s}});return Dt(e,n)}function ip(e,t){const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t._zod.def.shape};return un(this,"shape",s),s},get catchall(){return t._zod.def.catchall},checks:[]});return Dt(e,n)}function op(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Pt(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const l in n){if(!(l in a))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(c[l]=e?new e({type:"optional",innerType:a[l]}):a[l])}else for(const l in a)c[l]=e?new e({type:"optional",innerType:a[l]}):a[l];return un(this,"shape",c),c},checks:[]});return Dt(t,o)}function ap(e,t,n){const s=Pt(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new e({type:"nonoptional",innerType:r[o]}))}else for(const o in r)i[o]=new e({type:"nonoptional",innerType:r[o]});return un(this,"shape",i),i}});return Dt(t,s)}function An(e,t=0){var n;if(e.aborted===!0)return!0;for(let s=t;s<e.issues.length;s++)if(((n=e.issues[s])==null?void 0:n.continue)!==!0)return!0;return!1}function Tn(e,t){return t.map(n=>{var s;return(s=n).path??(s.path=[]),n.path.unshift(e),n})}function lr(e){return typeof e=="string"?e:e==null?void 0:e.message}function Ct(e,t,n){var r,i,o,a,c,l;const s={...e,path:e.path??[]};if(!e.message){const h=lr((o=(i=(r=e.inst)==null?void 0:r._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,e))??lr((a=t==null?void 0:t.error)==null?void 0:a.call(t,e))??lr((c=n.customError)==null?void 0:c.call(n,e))??lr((l=n.localeError)==null?void 0:l.call(n,e))??"Invalid input";s.message=h}return delete s.inst,delete s.continue,t!=null&&t.reportInput||delete s.input,s}function Bo(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function ks(...e){const[t,n,s]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:s}:{...t}}const Al=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Xi,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Tl=b("$ZodError",Al),Il=b("$ZodError",Al,{Parent:Error});function cp(e,t=n=>n.message){const n={},s=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):s.push(t(r));return{formErrors:s,fieldErrors:n}}function lp(e,t=n=>n.message){const n={_errors:[]},s=r=>{for(const i of r.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>s({issues:o}));else if(i.code==="invalid_key")s({issues:i.issues});else if(i.code==="invalid_element")s({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return s(e),n}const Vo=e=>(t,n,s,r)=>{const i=s?Object.assign(s,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new Cn;if(o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>Ct(c,i,It())));throw xl(a,r==null?void 0:r.callee),a}return o.value},Go=e=>async(t,n,s,r)=>{const i=s?Object.assign(s,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>Ct(c,i,It())));throw xl(a,r==null?void 0:r.callee),a}return o.value},ti=e=>(t,n,s)=>{const r=s?{...s,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},r);if(i instanceof Promise)throw new Cn;return i.issues.length?{success:!1,error:new(e??Tl)(i.issues.map(o=>Ct(o,r,It())))}:{success:!0,data:i.value}},up=ti(Il),ni=e=>async(t,n,s)=>{const r=s?Object.assign(s,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(o=>Ct(o,r,It())))}:{success:!0,data:i.value}},hp=ni(Il),dp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Vo(e)(t,n,r)},pp=e=>(t,n,s)=>Vo(e)(t,n,s),fp=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Go(e)(t,n,r)},gp=e=>async(t,n,s)=>Go(e)(t,n,s),mp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return ti(e)(t,n,r)},vp=e=>(t,n,s)=>ti(e)(t,n,s),_p=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return ni(e)(t,n,r)},yp=e=>async(t,n,s)=>ni(e)(t,n,s),kp=/^[cC][^\s-]{8,}$/,wp=/^[0-9a-z]+$/,bp=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sp=/^[0-9a-vA-V]{20}$/,xp=/^[A-Za-z0-9]{27}$/,Ep=/^[a-zA-Z0-9_-]{21}$/,Ap=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Tp=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,sc=e=>e?new 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|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Ip=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Cp="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function zp(){return new RegExp(Cp,"u")}const $p=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Rp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Pp=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Dp=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Lp=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Cl=/^[A-Za-z0-9_-]*$/,Mp=/^\+[1-9]\d{6,14}$/,zl="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Op=new RegExp(`^${zl}$`);function $l(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Np(e){return new RegExp(`^${$l(e)}$`)}function Wp(e){const t=$l({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const s=`${t}(?:${n.join("|")})`;return new RegExp(`^${zl}T(?:${s})$`)}const Fp=e=>{const t=e?`[\\s\\S]{${(e==null?void 0:e.minimum)??0},${(e==null?void 0:e.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Up=/^-?\d+$/,Rl=/^-?\d+(?:\.\d+)?$/,Zp=/^(?:true|false)$/i,jp=/^[^A-Z]*$/,Hp=/^[^a-z]*$/,Le=b("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Pl={number:"number",bigint:"bigint",object:"date"},Dl=b("$ZodCheckLessThan",(e,t)=>{Le.init(e,t);const n=Pl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?r.maximum=t.value:r.exclusiveMaximum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value<=t.value:s.value<t.value)||s.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ll=b("$ZodCheckGreaterThan",(e,t)=>{Le.init(e,t);const n=Pl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?r.minimum=t.value:r.exclusiveMinimum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value>=t.value:s.value>t.value)||s.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Bp=b("$ZodCheckMultipleOf",(e,t)=>{Le.init(e,t),e._zod.onattach.push(n=>{var s;(s=n._zod.bag).multipleOf??(s.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):Kd(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Vp=b("$ZodCheckNumberFormat",(e,t)=>{var o;Le.init(e,t),t.format=t.format||"float64";const n=(o=t.format)==null?void 0:o.includes("int"),s=n?"int":"number",[r,i]=ep[t.format];e._zod.onattach.push(a=>{const c=a._zod.bag;c.format=t.format,c.minimum=r,c.maximum=i,n&&(c.pattern=Up)}),e._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:s,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort});return}}c<r&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),Gp=b("$ZodCheckMaxLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(s._zod.bag.maximum=t.maximum)}),e._zod.check=s=>{const r=s.value;if(r.length<=t.maximum)return;const o=Bo(r);s.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),qp=b("$ZodCheckMinLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(s._zod.bag.minimum=t.minimum)}),e._zod.check=s=>{const r=s.value;if(r.length>=t.minimum)return;const o=Bo(r);s.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Kp=b("$ZodCheckLengthEquals",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!jo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=s=>{const r=s.value,i=r.length;if(i===t.length)return;const o=Bo(r),a=i>t.length;s.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:s.value,inst:e,continue:!t.abort})}}),si=b("$ZodCheckStringFormat",(e,t)=>{var n,s;Le.init(e,t),e._zod.onattach.push(r=>{const i=r._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(s=e._zod).check??(s.check=()=>{})}),Yp=b("$ZodCheckRegex",(e,t)=>{si.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Xp=b("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=jp),si.init(e,t)}),Jp=b("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Hp),si.init(e,t)}),Qp=b("$ZodCheckIncludes",(e,t)=>{Le.init(e,t);const n=Un(t.includes),s=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=s,e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(s)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),ef=b("$ZodCheckStartsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`^${Un(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.startsWith(t.prefix)||s.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:s.value,inst:e,continue:!t.abort})}}),tf=b("$ZodCheckEndsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`.*${Un(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.endsWith(t.suffix)||s.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:s.value,inst:e,continue:!t.abort})}}),nf=b("$ZodCheckOverwrite",(e,t)=>{Le.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class sf{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const s=t.split(`
2
2
  `).filter(o=>o),r=Math.min(...s.map(o=>o.length-o.trimStart().length)),i=s.map(o=>o.slice(r)).map(o=>" ".repeat(this.indent*2)+o);for(const o of i)this.content.push(o)}compile(){const t=Function,n=this==null?void 0:this.args,r=[...((this==null?void 0:this.content)??[""]).map(i=>` ${i}`)];return new t(...n,r.join(`
3
- `))}}const rf={major:4,minor:3,patch:6},ie=b("$ZodType",(e,t)=>{var r;var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=rf;const s=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&s.unshift(e);for(const i of s)for(const o of i._zod.onattach)o(e);if(s.length===0)(n=e._zod).deferred??(n.deferred=[]),(r=e._zod.deferred)==null||r.push(()=>{e._zod.run=e._zod.parse});else{const i=(a,c,l)=>{let h=An(a),f;for(const w of c){if(w._zod.def.when){if(!w._zod.def.when(a))continue}else if(h)continue;const v=a.issues.length,E=w._zod.check(a);if(E instanceof Promise&&(l==null?void 0:l.async)===!1)throw new Cn;if(f||E instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await E,a.issues.length!==v&&(h||(h=An(a,v)))});else{if(a.issues.length===v)continue;h||(h=An(a,v))}}return f?f.then(()=>a):a},o=(a,c,l)=>{if(An(a))return a.aborted=!0,a;const h=i(c,s,l);if(h instanceof Promise){if(l.async===!1)throw new Cn;return h.then(f=>e._zod.parse(f,l))}return e._zod.parse(h,l)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){const h=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});return h instanceof Promise?h.then(f=>o(f,a,c)):o(h,a,c)}const l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new Cn;return l.then(h=>i(h,s,c))}return i(l,s,c)}}q(e,"~standard",()=>({validate:i=>{var o;try{const a=up(e,i);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return hp(e,i).then(c=>{var l;return c.success?{value:c.data}:{issues:(l=c.error)==null?void 0:l.issues}})}},vendor:"zod",version:1}))}),qo=b("$ZodString",(e,t)=>{var n;ie.init(e,t),e._zod.pattern=[...((n=e==null?void 0:e._zod.bag)==null?void 0:n.patterns)??[]].pop()??Fp(e._zod.bag),e._zod.parse=(s,r)=>{if(t.coerce)try{s.value=String(s.value)}catch{}return typeof s.value=="string"||s.issues.push({expected:"string",code:"invalid_type",input:s.value,inst:e}),s}}),se=b("$ZodStringFormat",(e,t)=>{si.init(e,t),qo.init(e,t)}),of=b("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Tp),se.init(e,t)}),af=b("$ZodUUID",(e,t)=>{if(t.version){const s={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(s===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=sc(s))}else t.pattern??(t.pattern=sc());se.init(e,t)}),cf=b("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Ip),se.init(e,t)}),lf=b("$ZodURL",(e,t)=>{se.init(e,t),e._zod.check=n=>{try{const s=n.value.trim(),r=new URL(s);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(r.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=r.href:n.value=s;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),uf=b("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=zp()),se.init(e,t)}),hf=b("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Ep),se.init(e,t)}),df=b("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=kp),se.init(e,t)}),pf=b("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=wp),se.init(e,t)}),ff=b("$ZodULID",(e,t)=>{t.pattern??(t.pattern=bp),se.init(e,t)}),gf=b("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Sp),se.init(e,t)}),mf=b("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=xp),se.init(e,t)}),vf=b("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Wp(t)),se.init(e,t)}),_f=b("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Op),se.init(e,t)}),yf=b("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Np(t)),se.init(e,t)}),kf=b("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Ap),se.init(e,t)}),wf=b("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=$p),se.init(e,t),e._zod.bag.format="ipv4"}),bf=b("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Rp),se.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Sf=b("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Pp),se.init(e,t)}),xf=b("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Dp),se.init(e,t),e._zod.check=n=>{const s=n.value.split("/");try{if(s.length!==2)throw new Error;const[r,i]=s;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Ol(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Ef=b("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Lp),se.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Ol(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Af(e){if(!zl.test(e))return!1;const t=e.replace(/[-_]/g,s=>s==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Ol(n)}const Tf=b("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=zl),se.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Af(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),If=b("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Mp),se.init(e,t)});function Cf(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[s]=n;if(!s)return!1;const r=JSON.parse(atob(s));return!("typ"in r&&(r==null?void 0:r.typ)!=="JWT"||!r.alg||t&&(!("alg"in r)||r.alg!==t))}catch{return!1}}const zf=b("$ZodJWT",(e,t)=>{se.init(e,t),e._zod.check=n=>{Cf(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Nl=b("$ZodNumber",(e,t)=>{ie.init(e,t),e._zod.pattern=e._zod.bag.pattern??Pl,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const r=n.value;if(typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r))return n;const i=typeof r=="number"?Number.isNaN(r)?"NaN":Number.isFinite(r)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:r,inst:e,...i?{received:i}:{}}),n}}),$f=b("$ZodNumberFormat",(e,t)=>{Vp.init(e,t),Nl.init(e,t)}),Rf=b("$ZodBoolean",(e,t)=>{ie.init(e,t),e._zod.pattern=Zp,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=!!n.value}catch{}const r=n.value;return typeof r=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:r,inst:e}),n}}),Pf=b("$ZodUnknown",(e,t)=>{ie.init(e,t),e._zod.parse=n=>n}),Df=b("$ZodNever",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function rc(e,t,n){e.issues.length&&t.issues.push(...Tn(n,e.issues)),t.value[n]=e.value}const Lf=b("$ZodArray",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);const i=[];for(let o=0;o<r.length;o++){const a=r[o],c=t.element._zod.run({value:a,issues:[]},s);c instanceof Promise?i.push(c.then(l=>rc(l,n,o))):rc(c,n,o)}return i.length?Promise.all(i).then(()=>n):n}});function Dr(e,t,n,s,r){if(e.issues.length){if(r&&!(n in s))return;t.issues.push(...Tn(n,e.issues))}e.value===void 0?n in s&&(t.value[n]=void 0):t.value[n]=e.value}function Wl(e){var s,r,i,o;const t=Object.keys(e.shape);for(const a of t)if(!((o=(i=(r=(s=e.shape)==null?void 0:s[a])==null?void 0:r._zod)==null?void 0:i.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=Qd(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Fl(e,t,n,s,r,i){const o=[],a=r.keySet,c=r.catchall._zod,l=c.def.type,h=c.optout==="optional";for(const f in t){if(a.has(f))continue;if(l==="never"){o.push(f);continue}const w=c.run({value:t[f],issues:[]},s);w instanceof Promise?e.push(w.then(v=>Dr(v,n,f,t,h))):Dr(w,n,f,t,h)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const Mf=b("$ZodObject",(e,t)=>{ie.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!(n!=null&&n.get)){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const s=ei(()=>Wl(t));q(e._zod,"propValues",()=>{const a=t.shape,c={};for(const l in a){const h=a[l]._zod;if(h.values){c[l]??(c[l]=new Set);for(const f of h.values)c[l].add(f)}}return c});const r=ys,i=t.catchall;let o;e._zod.parse=(a,c)=>{o??(o=s.value);const l=a.value;if(!r(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const h=[],f=o.shape;for(const w of o.keys){const v=f[w],E=v._zod.optout==="optional",x=v._zod.run({value:l[w],issues:[]},c);x instanceof Promise?h.push(x.then(z=>Dr(z,a,w,l,E))):Dr(x,a,w,l,E)}return i?Fl(h,l,a,c,s.value,e):h.length?Promise.all(h).then(()=>a):a}}),Of=b("$ZodObjectJIT",(e,t)=>{Mf.init(e,t);const n=e._zod.parse,s=ei(()=>Wl(t)),r=w=>{var ye;const v=new sf(["shape","payload","ctx"]),E=s.value,x=M=>{const G=nc(M);return`shape[${G}]._zod.run({ value: input[${G}], issues: [] }, ctx)`};v.write("const input = payload.value;");const z=Object.create(null);let K=0;for(const M of E.keys)z[M]=`key_${K++}`;v.write("const newResult = {};");for(const M of E.keys){const G=z[M],U=nc(M),Te=w[M],X=((ye=Te==null?void 0:Te._zod)==null?void 0:ye.optout)==="optional";v.write(`const ${G} = ${x(M)};`),X?v.write(`
3
+ `))}}const rf={major:4,minor:3,patch:6},ie=b("$ZodType",(e,t)=>{var r;var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=rf;const s=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&s.unshift(e);for(const i of s)for(const o of i._zod.onattach)o(e);if(s.length===0)(n=e._zod).deferred??(n.deferred=[]),(r=e._zod.deferred)==null||r.push(()=>{e._zod.run=e._zod.parse});else{const i=(a,c,l)=>{let h=An(a),f;for(const w of c){if(w._zod.def.when){if(!w._zod.def.when(a))continue}else if(h)continue;const v=a.issues.length,E=w._zod.check(a);if(E instanceof Promise&&(l==null?void 0:l.async)===!1)throw new Cn;if(f||E instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await E,a.issues.length!==v&&(h||(h=An(a,v)))});else{if(a.issues.length===v)continue;h||(h=An(a,v))}}return f?f.then(()=>a):a},o=(a,c,l)=>{if(An(a))return a.aborted=!0,a;const h=i(c,s,l);if(h instanceof Promise){if(l.async===!1)throw new Cn;return h.then(f=>e._zod.parse(f,l))}return e._zod.parse(h,l)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){const h=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});return h instanceof Promise?h.then(f=>o(f,a,c)):o(h,a,c)}const l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new Cn;return l.then(h=>i(h,s,c))}return i(l,s,c)}}q(e,"~standard",()=>({validate:i=>{var o;try{const a=up(e,i);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return hp(e,i).then(c=>{var l;return c.success?{value:c.data}:{issues:(l=c.error)==null?void 0:l.issues}})}},vendor:"zod",version:1}))}),qo=b("$ZodString",(e,t)=>{var n;ie.init(e,t),e._zod.pattern=[...((n=e==null?void 0:e._zod.bag)==null?void 0:n.patterns)??[]].pop()??Fp(e._zod.bag),e._zod.parse=(s,r)=>{if(t.coerce)try{s.value=String(s.value)}catch{}return typeof s.value=="string"||s.issues.push({expected:"string",code:"invalid_type",input:s.value,inst:e}),s}}),se=b("$ZodStringFormat",(e,t)=>{si.init(e,t),qo.init(e,t)}),of=b("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Tp),se.init(e,t)}),af=b("$ZodUUID",(e,t)=>{if(t.version){const s={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(s===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=sc(s))}else t.pattern??(t.pattern=sc());se.init(e,t)}),cf=b("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Ip),se.init(e,t)}),lf=b("$ZodURL",(e,t)=>{se.init(e,t),e._zod.check=n=>{try{const s=n.value.trim(),r=new URL(s);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(r.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=r.href:n.value=s;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),uf=b("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=zp()),se.init(e,t)}),hf=b("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Ep),se.init(e,t)}),df=b("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=kp),se.init(e,t)}),pf=b("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=wp),se.init(e,t)}),ff=b("$ZodULID",(e,t)=>{t.pattern??(t.pattern=bp),se.init(e,t)}),gf=b("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Sp),se.init(e,t)}),mf=b("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=xp),se.init(e,t)}),vf=b("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Wp(t)),se.init(e,t)}),_f=b("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Op),se.init(e,t)}),yf=b("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Np(t)),se.init(e,t)}),kf=b("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Ap),se.init(e,t)}),wf=b("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=$p),se.init(e,t),e._zod.bag.format="ipv4"}),bf=b("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Rp),se.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Sf=b("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Pp),se.init(e,t)}),xf=b("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Dp),se.init(e,t),e._zod.check=n=>{const s=n.value.split("/");try{if(s.length!==2)throw new Error;const[r,i]=s;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Ml(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Ef=b("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Lp),se.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Ml(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Af(e){if(!Cl.test(e))return!1;const t=e.replace(/[-_]/g,s=>s==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Ml(n)}const Tf=b("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Cl),se.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Af(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),If=b("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Mp),se.init(e,t)});function Cf(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[s]=n;if(!s)return!1;const r=JSON.parse(atob(s));return!("typ"in r&&(r==null?void 0:r.typ)!=="JWT"||!r.alg||t&&(!("alg"in r)||r.alg!==t))}catch{return!1}}const zf=b("$ZodJWT",(e,t)=>{se.init(e,t),e._zod.check=n=>{Cf(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Ol=b("$ZodNumber",(e,t)=>{ie.init(e,t),e._zod.pattern=e._zod.bag.pattern??Rl,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const r=n.value;if(typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r))return n;const i=typeof r=="number"?Number.isNaN(r)?"NaN":Number.isFinite(r)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:r,inst:e,...i?{received:i}:{}}),n}}),$f=b("$ZodNumberFormat",(e,t)=>{Vp.init(e,t),Ol.init(e,t)}),Rf=b("$ZodBoolean",(e,t)=>{ie.init(e,t),e._zod.pattern=Zp,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=!!n.value}catch{}const r=n.value;return typeof r=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:r,inst:e}),n}}),Pf=b("$ZodUnknown",(e,t)=>{ie.init(e,t),e._zod.parse=n=>n}),Df=b("$ZodNever",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function rc(e,t,n){e.issues.length&&t.issues.push(...Tn(n,e.issues)),t.value[n]=e.value}const Lf=b("$ZodArray",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);const i=[];for(let o=0;o<r.length;o++){const a=r[o],c=t.element._zod.run({value:a,issues:[]},s);c instanceof Promise?i.push(c.then(l=>rc(l,n,o))):rc(c,n,o)}return i.length?Promise.all(i).then(()=>n):n}});function Dr(e,t,n,s,r){if(e.issues.length){if(r&&!(n in s))return;t.issues.push(...Tn(n,e.issues))}e.value===void 0?n in s&&(t.value[n]=void 0):t.value[n]=e.value}function Nl(e){var s,r,i,o;const t=Object.keys(e.shape);for(const a of t)if(!((o=(i=(r=(s=e.shape)==null?void 0:s[a])==null?void 0:r._zod)==null?void 0:i.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=Qd(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Wl(e,t,n,s,r,i){const o=[],a=r.keySet,c=r.catchall._zod,l=c.def.type,h=c.optout==="optional";for(const f in t){if(a.has(f))continue;if(l==="never"){o.push(f);continue}const w=c.run({value:t[f],issues:[]},s);w instanceof Promise?e.push(w.then(v=>Dr(v,n,f,t,h))):Dr(w,n,f,t,h)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const Mf=b("$ZodObject",(e,t)=>{ie.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!(n!=null&&n.get)){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const s=ei(()=>Nl(t));q(e._zod,"propValues",()=>{const a=t.shape,c={};for(const l in a){const h=a[l]._zod;if(h.values){c[l]??(c[l]=new Set);for(const f of h.values)c[l].add(f)}}return c});const r=ys,i=t.catchall;let o;e._zod.parse=(a,c)=>{o??(o=s.value);const l=a.value;if(!r(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const h=[],f=o.shape;for(const w of o.keys){const v=f[w],E=v._zod.optout==="optional",x=v._zod.run({value:l[w],issues:[]},c);x instanceof Promise?h.push(x.then(z=>Dr(z,a,w,l,E))):Dr(x,a,w,l,E)}return i?Wl(h,l,a,c,s.value,e):h.length?Promise.all(h).then(()=>a):a}}),Of=b("$ZodObjectJIT",(e,t)=>{Mf.init(e,t);const n=e._zod.parse,s=ei(()=>Nl(t)),r=w=>{var ye;const v=new sf(["shape","payload","ctx"]),E=s.value,x=M=>{const G=nc(M);return`shape[${G}]._zod.run({ value: input[${G}], issues: [] }, ctx)`};v.write("const input = payload.value;");const z=Object.create(null);let K=0;for(const M of E.keys)z[M]=`key_${K++}`;v.write("const newResult = {};");for(const M of E.keys){const G=z[M],U=nc(M),Te=w[M],X=((ye=Te==null?void 0:Te._zod)==null?void 0:ye.optout)==="optional";v.write(`const ${G} = ${x(M)};`),X?v.write(`
4
4
  if (${G}.issues.length) {
5
5
  if (${U} in input) {
6
6
  payload.issues = payload.issues.concat(${G}.issues.map(iss => ({
@@ -34,9 +34,9 @@ var Dd=Object.defineProperty;var Ya=e=>{throw TypeError(e)};var Ld=(e,t,n)=>t in
34
34
  newResult[${U}] = ${G}.value;
35
35
  }
36
36
 
37
- `)}v.write("payload.value = newResult;"),v.write("return payload;");const Z=v.compile();return(M,G)=>Z(w,M,G)};let i;const o=ys,a=!Sl.jitless,l=a&&Xd.value,h=t.catchall;let f;e._zod.parse=(w,v)=>{f??(f=s.value);const E=w.value;return o(E)?a&&l&&(v==null?void 0:v.async)===!1&&v.jitless!==!0?(i||(i=r(t.shape)),w=i(w,v),h?Fl([],E,w,v,f,e):w):n(w,v):(w.issues.push({expected:"object",code:"invalid_type",input:E,inst:e}),w)}});function ic(e,t,n,s){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const r=e.filter(i=>!An(i));return r.length===1?(t.value=r[0].value,r[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(o=>Ct(o,s,It())))}),t)}const Ul=b("$ZodUnion",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),q(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),q(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),q(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(i=>i._zod.pattern);return new RegExp(`^(${r.map(i=>Ho(i.source)).join("|")})$`)}});const n=t.options.length===1,s=t.options[0]._zod.run;e._zod.parse=(r,i)=>{if(n)return s(r,i);let o=!1;const a=[];for(const c of t.options){const l=c._zod.run({value:r.value,issues:[]},i);if(l instanceof Promise)a.push(l),o=!0;else{if(l.issues.length===0)return l;a.push(l)}}return o?Promise.all(a).then(c=>ic(c,r,e,i)):ic(a,r,e,i)}}),Nf=b("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Ul.init(e,t);const n=e._zod.parse;q(e._zod,"propValues",()=>{const r={};for(const i of t.options){const o=i._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(const[a,c]of Object.entries(o)){r[a]||(r[a]=new Set);for(const l of c)r[a].add(l)}}return r});const s=ei(()=>{var o;const r=t.options,i=new Map;for(const a of r){const c=(o=a._zod.propValues)==null?void 0:o[t.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(const l of c){if(i.has(l))throw new Error(`Duplicate discriminator value "${String(l)}"`);i.set(l,a)}}return i});e._zod.parse=(r,i)=>{const o=r.value;if(!ys(o))return r.issues.push({code:"invalid_type",expected:"object",input:o,inst:e}),r;const a=s.value.get(o==null?void 0:o[t.discriminator]);return a?a._zod.run(r,i):t.unionFallback?n(r,i):(r.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),r)}}),Wf=b("$ZodIntersection",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value,i=t.left._zod.run({value:r,issues:[]},s),o=t.right._zod.run({value:r,issues:[]},s);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([c,l])=>oc(n,c,l)):oc(n,i,o)}});function Ji(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Fn(e)&&Fn(t)){const n=Object.keys(t),s=Object.keys(e).filter(i=>n.indexOf(i)!==-1),r={...e,...t};for(const i of s){const o=Ji(e[i],t[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};r[i]=o.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let s=0;s<e.length;s++){const r=e[s],i=t[s],o=Ji(r,i);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function oc(e,t,n){const s=new Map;let r;for(const a of t.issues)if(a.code==="unrecognized_keys"){r??(r=a);for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).r=!0;else e.issues.push(a);const i=[...s].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(i.length&&r&&e.issues.push({...r,keys:i}),An(e))return e;const o=Ji(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Ff=b("$ZodRecord",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Fn(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;const i=[],o=t.keyType._zod.values;if(o){n.value={};const a=new Set;for(const l of o)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){a.add(typeof l=="number"?l.toString():l);const h=t.valueType._zod.run({value:r[l],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(l,f.issues)),n.value[l]=f.value})):(h.issues.length&&n.issues.push(...Tn(l,h.issues)),n.value[l]=h.value)}let c;for(const l in r)a.has(l)||(c=c??[],c.push(l));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(r)){if(a==="__proto__")continue;let c=t.keyType._zod.run({value:a,issues:[]},s);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&Pl.test(a)&&c.issues.length){const f=t.keyType._zod.run({value:Number(a),issues:[]},s);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(c=f)}if(c.issues.length){t.mode==="loose"?n.value[a]=r[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(f=>Ct(f,s,It())),input:a,path:[a],inst:e});continue}const h=t.valueType._zod.run({value:r[a],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(a,f.issues)),n.value[c.value]=f.value})):(h.issues.length&&n.issues.push(...Tn(a,h.issues)),n.value[c.value]=h.value)}}return i.length?Promise.all(i).then(()=>n):n}}),Uf=b("$ZodEnum",(e,t)=>{ie.init(e,t);const n=xl(t.entries),s=new Set(n);e._zod.values=s,e._zod.pattern=new RegExp(`^(${n.filter(r=>Jd.has(typeof r)).map(r=>typeof r=="string"?Un(r):r.toString()).join("|")})$`),e._zod.parse=(r,i)=>{const o=r.value;return s.has(o)||r.issues.push({code:"invalid_value",values:n,input:o,inst:e}),r}}),Zf=b("$ZodLiteral",(e,t)=>{if(ie.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(s=>typeof s=="string"?Un(s):s?Un(s.toString()):String(s)).join("|")})$`),e._zod.parse=(s,r)=>{const i=s.value;return n.has(i)||s.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),s}}),jf=b("$ZodTransform",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new bl(e.constructor.name);const r=t.transform(n.value,n);if(s.async)return(r instanceof Promise?r:Promise.resolve(r)).then(o=>(n.value=o,n));if(r instanceof Promise)throw new Cn;return n.value=r,n}});function ac(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Zl=b("$ZodOptional",(e,t)=>{ie.init(e,t),e._zod.optin="optional",e._zod.optout="optional",q(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),q(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ho(n.source)})?$`):void 0}),e._zod.parse=(n,s)=>{if(t.innerType._zod.optin==="optional"){const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>ac(i,n.value)):ac(r,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,s)}}),Hf=b("$ZodExactOptional",(e,t)=>{Zl.init(e,t),q(e._zod,"values",()=>t.innerType._zod.values),q(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,s)=>t.innerType._zod.run(n,s)}),Bf=b("$ZodNullable",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.innerType._zod.optin),q(e._zod,"optout",()=>t.innerType._zod.optout),q(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ho(n.source)}|null)$`):void 0}),q(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,s)=>n.value===null?n:t.innerType._zod.run(n,s)}),Vf=b("$ZodDefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);if(n.value===void 0)return n.value=t.defaultValue,n;const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>cc(i,t)):cc(r,t)}});function cc(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Gf=b("$ZodPrefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>(s.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,s))}),qf=b("$ZodNonOptional",(e,t)=>{ie.init(e,t),q(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(s=>s!==void 0)):void 0}),e._zod.parse=(n,s)=>{const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>lc(i,e)):lc(r,e)}});function lc(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Kf=b("$ZodCatch",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.innerType._zod.optin),q(e._zod,"optout",()=>t.innerType._zod.optout),q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(o=>Ct(o,s,It()))},input:n.value}),n.issues=[]),n)):(n.value=r.value,r.issues.length&&(n.value=t.catchValue({...n,error:{issues:r.issues.map(i=>Ct(i,s,It()))},input:n.value}),n.issues=[]),n)}}),Yf=b("$ZodPipe",(e,t)=>{ie.init(e,t),q(e._zod,"values",()=>t.in._zod.values),q(e._zod,"optin",()=>t.in._zod.optin),q(e._zod,"optout",()=>t.out._zod.optout),q(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,s)=>{if(s.direction==="backward"){const i=t.out._zod.run(n,s);return i instanceof Promise?i.then(o=>ur(o,t.in,s)):ur(i,t.in,s)}const r=t.in._zod.run(n,s);return r instanceof Promise?r.then(i=>ur(i,t.out,s)):ur(r,t.out,s)}});function ur(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Xf=b("$ZodReadonly",(e,t)=>{ie.init(e,t),q(e._zod,"propValues",()=>t.innerType._zod.propValues),q(e._zod,"values",()=>t.innerType._zod.values),q(e._zod,"optin",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optin}),q(e._zod,"optout",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optout}),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(uc):uc(r)}});function uc(e){return e.value=Object.freeze(e.value),e}const Jf=b("$ZodCustom",(e,t)=>{Le.init(e,t),ie.init(e,t),e._zod.parse=(n,s)=>n,e._zod.check=n=>{const s=n.value,r=t.fn(s);if(r instanceof Promise)return r.then(i=>hc(i,n,s,e));hc(r,n,s,e)}});function hc(e,t,n,s){if(!e){const r={code:"custom",input:n,inst:s,path:[...s._zod.def.path??[]],continue:!s._zod.def.abort};s._zod.def.params&&(r.params=s._zod.def.params),t.issues.push(ks(r))}}var dc;class Qf{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const s=n[0];return this._map.set(t,s),s&&typeof s=="object"&&"id"in s&&this._idmap.set(s.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const s={...this.get(n)??{}};delete s.id;const r={...s,...this._map.get(t)};return Object.keys(r).length?r:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function eg(){return new Qf}(dc=globalThis).__zod_globalRegistry??(dc.__zod_globalRegistry=eg());const hs=globalThis.__zod_globalRegistry;function tg(e,t){return new e({type:"string",...P(t)})}function ng(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...P(t)})}function pc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...P(t)})}function sg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...P(t)})}function rg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...P(t)})}function ig(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...P(t)})}function og(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...P(t)})}function ag(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...P(t)})}function cg(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...P(t)})}function lg(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...P(t)})}function ug(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...P(t)})}function hg(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...P(t)})}function dg(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...P(t)})}function pg(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...P(t)})}function fg(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...P(t)})}function gg(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...P(t)})}function mg(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...P(t)})}function vg(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...P(t)})}function _g(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...P(t)})}function yg(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...P(t)})}function kg(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...P(t)})}function wg(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...P(t)})}function bg(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...P(t)})}function Sg(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...P(t)})}function xg(e,t){return new e({type:"string",format:"date",check:"string_format",...P(t)})}function Eg(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...P(t)})}function Ag(e,t){return new e({type:"string",format:"duration",check:"string_format",...P(t)})}function Tg(e,t){return new e({type:"number",checks:[],...P(t)})}function Ig(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...P(t)})}function Cg(e,t){return new e({type:"boolean",...P(t)})}function zg(e){return new e({type:"unknown"})}function $g(e,t){return new e({type:"never",...P(t)})}function fc(e,t){return new Ll({check:"less_than",...P(t),value:e,inclusive:!1})}function zi(e,t){return new Ll({check:"less_than",...P(t),value:e,inclusive:!0})}function gc(e,t){return new Ml({check:"greater_than",...P(t),value:e,inclusive:!1})}function $i(e,t){return new Ml({check:"greater_than",...P(t),value:e,inclusive:!0})}function mc(e,t){return new Bp({check:"multiple_of",...P(t),value:e})}function jl(e,t){return new Gp({check:"max_length",...P(t),maximum:e})}function Lr(e,t){return new qp({check:"min_length",...P(t),minimum:e})}function Hl(e,t){return new Kp({check:"length_equals",...P(t),length:e})}function Rg(e,t){return new Yp({check:"string_format",format:"regex",...P(t),pattern:e})}function Pg(e){return new Xp({check:"string_format",format:"lowercase",...P(e)})}function Dg(e){return new Jp({check:"string_format",format:"uppercase",...P(e)})}function Lg(e,t){return new Qp({check:"string_format",format:"includes",...P(t),includes:e})}function Mg(e,t){return new ef({check:"string_format",format:"starts_with",...P(t),prefix:e})}function Og(e,t){return new tf({check:"string_format",format:"ends_with",...P(t),suffix:e})}function Bn(e){return new nf({check:"overwrite",tx:e})}function Ng(e){return Bn(t=>t.normalize(e))}function Wg(){return Bn(e=>e.trim())}function Fg(){return Bn(e=>e.toLowerCase())}function Ug(){return Bn(e=>e.toUpperCase())}function Zg(){return Bn(e=>Yd(e))}function jg(e,t,n){return new e({type:"array",element:t,...P(n)})}function Hg(e,t,n){return new e({type:"custom",check:"custom",fn:t,...P(n)})}function Bg(e){const t=Vg(n=>(n.addIssue=s=>{if(typeof s=="string")n.issues.push(ks(s,n.value,t._zod.def));else{const r=s;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(ks(r))}},e(n.value,n)));return t}function Vg(e,t){const n=new Le({check:"custom",...P(t)});return n._zod.check=e,n}function Bl(e){let t=(e==null?void 0:e.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:(e==null?void 0:e.metadata)??hs,target:t,unrepresentable:(e==null?void 0:e.unrepresentable)??"throw",override:(e==null?void 0:e.override)??(()=>{}),io:(e==null?void 0:e.io)??"output",counter:0,seen:new Map,cycles:(e==null?void 0:e.cycles)??"ref",reused:(e==null?void 0:e.reused)??"inline",external:(e==null?void 0:e.external)??void 0}}function pe(e,t,n={path:[],schemaPath:[]}){var h,f;var s;const r=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=(f=(h=e._zod).toJSONSchema)==null?void 0:f.call(h);if(a)o.schema=a;else{const w={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,w);else{const E=o.schema,x=t.processors[r.type];if(!x)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);x(e,t,E,w)}const v=e._zod.parent;v&&(o.ref||(o.ref=v),pe(v,t,w),t.seen.get(v).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io==="input"&&Ce(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&o.schema._prefault&&((s=o.schema).default??(s.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Vl(e,t){var o,a,c,l;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=new Map;for(const h of e.seen.entries()){const f=(o=e.metadataRegistry.get(h[0]))==null?void 0:o.id;if(f){const w=s.get(f);if(w&&w!==h[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);s.set(f,h[0])}}const r=h=>{var x;const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const z=(x=e.external.registry.get(h[0]))==null?void 0:x.id,K=e.external.uri??(ye=>ye);if(z)return{ref:K(z)};const Z=h[1].defId??h[1].schema.id??`schema${e.counter++}`;return h[1].defId=Z,{defId:Z,ref:`${K("__shared")}#/${f}/${Z}`}}if(h[1]===n)return{ref:"#"};const v=`#/${f}/`,E=h[1].schema.id??`__schema${e.counter++}`;return{defId:E,ref:v+E}},i=h=>{if(h[1].schema.$ref)return;const f=h[1],{ref:w,defId:v}=r(h);f.def={...f.schema},v&&(f.defId=v);const E=f.schema;for(const x in E)delete E[x];E.$ref=w};if(e.cycles==="throw")for(const h of e.seen.entries()){const f=h[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
37
+ `)}v.write("payload.value = newResult;"),v.write("return payload;");const Z=v.compile();return(M,G)=>Z(w,M,G)};let i;const o=ys,a=!bl.jitless,l=a&&Xd.value,h=t.catchall;let f;e._zod.parse=(w,v)=>{f??(f=s.value);const E=w.value;return o(E)?a&&l&&(v==null?void 0:v.async)===!1&&v.jitless!==!0?(i||(i=r(t.shape)),w=i(w,v),h?Wl([],E,w,v,f,e):w):n(w,v):(w.issues.push({expected:"object",code:"invalid_type",input:E,inst:e}),w)}});function ic(e,t,n,s){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const r=e.filter(i=>!An(i));return r.length===1?(t.value=r[0].value,r[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(o=>Ct(o,s,It())))}),t)}const Fl=b("$ZodUnion",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),q(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),q(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),q(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(i=>i._zod.pattern);return new RegExp(`^(${r.map(i=>Ho(i.source)).join("|")})$`)}});const n=t.options.length===1,s=t.options[0]._zod.run;e._zod.parse=(r,i)=>{if(n)return s(r,i);let o=!1;const a=[];for(const c of t.options){const l=c._zod.run({value:r.value,issues:[]},i);if(l instanceof Promise)a.push(l),o=!0;else{if(l.issues.length===0)return l;a.push(l)}}return o?Promise.all(a).then(c=>ic(c,r,e,i)):ic(a,r,e,i)}}),Nf=b("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Fl.init(e,t);const n=e._zod.parse;q(e._zod,"propValues",()=>{const r={};for(const i of t.options){const o=i._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(const[a,c]of Object.entries(o)){r[a]||(r[a]=new Set);for(const l of c)r[a].add(l)}}return r});const s=ei(()=>{var o;const r=t.options,i=new Map;for(const a of r){const c=(o=a._zod.propValues)==null?void 0:o[t.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(const l of c){if(i.has(l))throw new Error(`Duplicate discriminator value "${String(l)}"`);i.set(l,a)}}return i});e._zod.parse=(r,i)=>{const o=r.value;if(!ys(o))return r.issues.push({code:"invalid_type",expected:"object",input:o,inst:e}),r;const a=s.value.get(o==null?void 0:o[t.discriminator]);return a?a._zod.run(r,i):t.unionFallback?n(r,i):(r.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),r)}}),Wf=b("$ZodIntersection",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value,i=t.left._zod.run({value:r,issues:[]},s),o=t.right._zod.run({value:r,issues:[]},s);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([c,l])=>oc(n,c,l)):oc(n,i,o)}});function Ji(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Fn(e)&&Fn(t)){const n=Object.keys(t),s=Object.keys(e).filter(i=>n.indexOf(i)!==-1),r={...e,...t};for(const i of s){const o=Ji(e[i],t[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};r[i]=o.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let s=0;s<e.length;s++){const r=e[s],i=t[s],o=Ji(r,i);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function oc(e,t,n){const s=new Map;let r;for(const a of t.issues)if(a.code==="unrecognized_keys"){r??(r=a);for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).r=!0;else e.issues.push(a);const i=[...s].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(i.length&&r&&e.issues.push({...r,keys:i}),An(e))return e;const o=Ji(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Ff=b("$ZodRecord",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Fn(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;const i=[],o=t.keyType._zod.values;if(o){n.value={};const a=new Set;for(const l of o)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){a.add(typeof l=="number"?l.toString():l);const h=t.valueType._zod.run({value:r[l],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(l,f.issues)),n.value[l]=f.value})):(h.issues.length&&n.issues.push(...Tn(l,h.issues)),n.value[l]=h.value)}let c;for(const l in r)a.has(l)||(c=c??[],c.push(l));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(r)){if(a==="__proto__")continue;let c=t.keyType._zod.run({value:a,issues:[]},s);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&Rl.test(a)&&c.issues.length){const f=t.keyType._zod.run({value:Number(a),issues:[]},s);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(c=f)}if(c.issues.length){t.mode==="loose"?n.value[a]=r[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(f=>Ct(f,s,It())),input:a,path:[a],inst:e});continue}const h=t.valueType._zod.run({value:r[a],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(a,f.issues)),n.value[c.value]=f.value})):(h.issues.length&&n.issues.push(...Tn(a,h.issues)),n.value[c.value]=h.value)}}return i.length?Promise.all(i).then(()=>n):n}}),Uf=b("$ZodEnum",(e,t)=>{ie.init(e,t);const n=Sl(t.entries),s=new Set(n);e._zod.values=s,e._zod.pattern=new RegExp(`^(${n.filter(r=>Jd.has(typeof r)).map(r=>typeof r=="string"?Un(r):r.toString()).join("|")})$`),e._zod.parse=(r,i)=>{const o=r.value;return s.has(o)||r.issues.push({code:"invalid_value",values:n,input:o,inst:e}),r}}),Zf=b("$ZodLiteral",(e,t)=>{if(ie.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(s=>typeof s=="string"?Un(s):s?Un(s.toString()):String(s)).join("|")})$`),e._zod.parse=(s,r)=>{const i=s.value;return n.has(i)||s.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),s}}),jf=b("$ZodTransform",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new wl(e.constructor.name);const r=t.transform(n.value,n);if(s.async)return(r instanceof Promise?r:Promise.resolve(r)).then(o=>(n.value=o,n));if(r instanceof Promise)throw new Cn;return n.value=r,n}});function ac(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Ul=b("$ZodOptional",(e,t)=>{ie.init(e,t),e._zod.optin="optional",e._zod.optout="optional",q(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),q(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ho(n.source)})?$`):void 0}),e._zod.parse=(n,s)=>{if(t.innerType._zod.optin==="optional"){const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>ac(i,n.value)):ac(r,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,s)}}),Hf=b("$ZodExactOptional",(e,t)=>{Ul.init(e,t),q(e._zod,"values",()=>t.innerType._zod.values),q(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,s)=>t.innerType._zod.run(n,s)}),Bf=b("$ZodNullable",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.innerType._zod.optin),q(e._zod,"optout",()=>t.innerType._zod.optout),q(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Ho(n.source)}|null)$`):void 0}),q(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,s)=>n.value===null?n:t.innerType._zod.run(n,s)}),Vf=b("$ZodDefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);if(n.value===void 0)return n.value=t.defaultValue,n;const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>cc(i,t)):cc(r,t)}});function cc(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Gf=b("$ZodPrefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>(s.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,s))}),qf=b("$ZodNonOptional",(e,t)=>{ie.init(e,t),q(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(s=>s!==void 0)):void 0}),e._zod.parse=(n,s)=>{const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>lc(i,e)):lc(r,e)}});function lc(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Kf=b("$ZodCatch",(e,t)=>{ie.init(e,t),q(e._zod,"optin",()=>t.innerType._zod.optin),q(e._zod,"optout",()=>t.innerType._zod.optout),q(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(o=>Ct(o,s,It()))},input:n.value}),n.issues=[]),n)):(n.value=r.value,r.issues.length&&(n.value=t.catchValue({...n,error:{issues:r.issues.map(i=>Ct(i,s,It()))},input:n.value}),n.issues=[]),n)}}),Yf=b("$ZodPipe",(e,t)=>{ie.init(e,t),q(e._zod,"values",()=>t.in._zod.values),q(e._zod,"optin",()=>t.in._zod.optin),q(e._zod,"optout",()=>t.out._zod.optout),q(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,s)=>{if(s.direction==="backward"){const i=t.out._zod.run(n,s);return i instanceof Promise?i.then(o=>ur(o,t.in,s)):ur(i,t.in,s)}const r=t.in._zod.run(n,s);return r instanceof Promise?r.then(i=>ur(i,t.out,s)):ur(r,t.out,s)}});function ur(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Xf=b("$ZodReadonly",(e,t)=>{ie.init(e,t),q(e._zod,"propValues",()=>t.innerType._zod.propValues),q(e._zod,"values",()=>t.innerType._zod.values),q(e._zod,"optin",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optin}),q(e._zod,"optout",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optout}),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(uc):uc(r)}});function uc(e){return e.value=Object.freeze(e.value),e}const Jf=b("$ZodCustom",(e,t)=>{Le.init(e,t),ie.init(e,t),e._zod.parse=(n,s)=>n,e._zod.check=n=>{const s=n.value,r=t.fn(s);if(r instanceof Promise)return r.then(i=>hc(i,n,s,e));hc(r,n,s,e)}});function hc(e,t,n,s){if(!e){const r={code:"custom",input:n,inst:s,path:[...s._zod.def.path??[]],continue:!s._zod.def.abort};s._zod.def.params&&(r.params=s._zod.def.params),t.issues.push(ks(r))}}var dc;class Qf{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const s=n[0];return this._map.set(t,s),s&&typeof s=="object"&&"id"in s&&this._idmap.set(s.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const s={...this.get(n)??{}};delete s.id;const r={...s,...this._map.get(t)};return Object.keys(r).length?r:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function eg(){return new Qf}(dc=globalThis).__zod_globalRegistry??(dc.__zod_globalRegistry=eg());const hs=globalThis.__zod_globalRegistry;function tg(e,t){return new e({type:"string",...P(t)})}function ng(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...P(t)})}function pc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...P(t)})}function sg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...P(t)})}function rg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...P(t)})}function ig(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...P(t)})}function og(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...P(t)})}function ag(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...P(t)})}function cg(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...P(t)})}function lg(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...P(t)})}function ug(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...P(t)})}function hg(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...P(t)})}function dg(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...P(t)})}function pg(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...P(t)})}function fg(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...P(t)})}function gg(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...P(t)})}function mg(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...P(t)})}function vg(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...P(t)})}function _g(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...P(t)})}function yg(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...P(t)})}function kg(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...P(t)})}function wg(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...P(t)})}function bg(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...P(t)})}function Sg(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...P(t)})}function xg(e,t){return new e({type:"string",format:"date",check:"string_format",...P(t)})}function Eg(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...P(t)})}function Ag(e,t){return new e({type:"string",format:"duration",check:"string_format",...P(t)})}function Tg(e,t){return new e({type:"number",checks:[],...P(t)})}function Ig(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...P(t)})}function Cg(e,t){return new e({type:"boolean",...P(t)})}function zg(e){return new e({type:"unknown"})}function $g(e,t){return new e({type:"never",...P(t)})}function fc(e,t){return new Dl({check:"less_than",...P(t),value:e,inclusive:!1})}function zi(e,t){return new Dl({check:"less_than",...P(t),value:e,inclusive:!0})}function gc(e,t){return new Ll({check:"greater_than",...P(t),value:e,inclusive:!1})}function $i(e,t){return new Ll({check:"greater_than",...P(t),value:e,inclusive:!0})}function mc(e,t){return new Bp({check:"multiple_of",...P(t),value:e})}function Zl(e,t){return new Gp({check:"max_length",...P(t),maximum:e})}function Lr(e,t){return new qp({check:"min_length",...P(t),minimum:e})}function jl(e,t){return new Kp({check:"length_equals",...P(t),length:e})}function Rg(e,t){return new Yp({check:"string_format",format:"regex",...P(t),pattern:e})}function Pg(e){return new Xp({check:"string_format",format:"lowercase",...P(e)})}function Dg(e){return new Jp({check:"string_format",format:"uppercase",...P(e)})}function Lg(e,t){return new Qp({check:"string_format",format:"includes",...P(t),includes:e})}function Mg(e,t){return new ef({check:"string_format",format:"starts_with",...P(t),prefix:e})}function Og(e,t){return new tf({check:"string_format",format:"ends_with",...P(t),suffix:e})}function Bn(e){return new nf({check:"overwrite",tx:e})}function Ng(e){return Bn(t=>t.normalize(e))}function Wg(){return Bn(e=>e.trim())}function Fg(){return Bn(e=>e.toLowerCase())}function Ug(){return Bn(e=>e.toUpperCase())}function Zg(){return Bn(e=>Yd(e))}function jg(e,t,n){return new e({type:"array",element:t,...P(n)})}function Hg(e,t,n){return new e({type:"custom",check:"custom",fn:t,...P(n)})}function Bg(e){const t=Vg(n=>(n.addIssue=s=>{if(typeof s=="string")n.issues.push(ks(s,n.value,t._zod.def));else{const r=s;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(ks(r))}},e(n.value,n)));return t}function Vg(e,t){const n=new Le({check:"custom",...P(t)});return n._zod.check=e,n}function Hl(e){let t=(e==null?void 0:e.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:(e==null?void 0:e.metadata)??hs,target:t,unrepresentable:(e==null?void 0:e.unrepresentable)??"throw",override:(e==null?void 0:e.override)??(()=>{}),io:(e==null?void 0:e.io)??"output",counter:0,seen:new Map,cycles:(e==null?void 0:e.cycles)??"ref",reused:(e==null?void 0:e.reused)??"inline",external:(e==null?void 0:e.external)??void 0}}function pe(e,t,n={path:[],schemaPath:[]}){var h,f;var s;const r=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=(f=(h=e._zod).toJSONSchema)==null?void 0:f.call(h);if(a)o.schema=a;else{const w={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,w);else{const E=o.schema,x=t.processors[r.type];if(!x)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);x(e,t,E,w)}const v=e._zod.parent;v&&(o.ref||(o.ref=v),pe(v,t,w),t.seen.get(v).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io==="input"&&Ce(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&o.schema._prefault&&((s=o.schema).default??(s.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Bl(e,t){var o,a,c,l;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=new Map;for(const h of e.seen.entries()){const f=(o=e.metadataRegistry.get(h[0]))==null?void 0:o.id;if(f){const w=s.get(f);if(w&&w!==h[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);s.set(f,h[0])}}const r=h=>{var x;const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const z=(x=e.external.registry.get(h[0]))==null?void 0:x.id,K=e.external.uri??(ye=>ye);if(z)return{ref:K(z)};const Z=h[1].defId??h[1].schema.id??`schema${e.counter++}`;return h[1].defId=Z,{defId:Z,ref:`${K("__shared")}#/${f}/${Z}`}}if(h[1]===n)return{ref:"#"};const v=`#/${f}/`,E=h[1].schema.id??`__schema${e.counter++}`;return{defId:E,ref:v+E}},i=h=>{if(h[1].schema.$ref)return;const f=h[1],{ref:w,defId:v}=r(h);f.def={...f.schema},v&&(f.defId=v);const E=f.schema;for(const x in E)delete E[x];E.$ref=w};if(e.cycles==="throw")for(const h of e.seen.entries()){const f=h[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
38
38
 
39
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const h of e.seen.entries()){const f=h[1];if(t===h[0]){i(h);continue}if(e.external){const v=(c=e.external.registry.get(h[0]))==null?void 0:c.id;if(t!==h[0]&&v){i(h);continue}}if((l=e.metadataRegistry.get(h[0]))==null?void 0:l.id){i(h);continue}if(f.cycle){i(h);continue}if(f.count>1&&e.reused==="ref"){i(h);continue}}}function Gl(e,t){var o,a,c;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=l=>{const h=e.seen.get(l);if(h.ref===null)return;const f=h.def??h.schema,w={...f},v=h.ref;if(h.ref=null,v){s(v);const x=e.seen.get(v),z=x.schema;if(z.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(z)):Object.assign(f,z),Object.assign(f,w),l._zod.parent===v)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in w||delete f[Z];if(z.$ref&&x.def)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in x.def&&JSON.stringify(f[Z])===JSON.stringify(x.def[Z])&&delete f[Z]}const E=l._zod.parent;if(E&&E!==v){s(E);const x=e.seen.get(E);if(x!=null&&x.schema.$ref&&(f.$ref=x.schema.$ref,x.def))for(const z in f)z==="$ref"||z==="allOf"||z in x.def&&JSON.stringify(f[z])===JSON.stringify(x.def[z])&&delete f[z]}e.override({zodSchema:l,jsonSchema:f,path:h.path??[]})};for(const l of[...e.seen.entries()].reverse())s(l[0]);const r={};if(e.target==="draft-2020-12"?r.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?r.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?r.$schema="http://json-schema.org/draft-04/schema#":e.target,(o=e.external)!=null&&o.uri){const l=(a=e.external.registry.get(t))==null?void 0:a.id;if(!l)throw new Error("Schema is missing an `id` property");r.$id=e.external.uri(l)}Object.assign(r,n.def??n.schema);const i=((c=e.external)==null?void 0:c.defs)??{};for(const l of e.seen.entries()){const h=l[1];h.def&&h.defId&&(i[h.defId]=h.def)}e.external||Object.keys(i).length>0&&(e.target==="draft-2020-12"?r.$defs=i:r.definitions=i);try{const l=JSON.parse(JSON.stringify(r));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:Mr(t,"input",e.processors),output:Mr(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function Ce(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const s=e._zod.def;if(s.type==="transform")return!0;if(s.type==="array")return Ce(s.element,n);if(s.type==="set")return Ce(s.valueType,n);if(s.type==="lazy")return Ce(s.getter(),n);if(s.type==="promise"||s.type==="optional"||s.type==="nonoptional"||s.type==="nullable"||s.type==="readonly"||s.type==="default"||s.type==="prefault")return Ce(s.innerType,n);if(s.type==="intersection")return Ce(s.left,n)||Ce(s.right,n);if(s.type==="record"||s.type==="map")return Ce(s.keyType,n)||Ce(s.valueType,n);if(s.type==="pipe")return Ce(s.in,n)||Ce(s.out,n);if(s.type==="object"){for(const r in s.shape)if(Ce(s.shape[r],n))return!0;return!1}if(s.type==="union"){for(const r of s.options)if(Ce(r,n))return!0;return!1}if(s.type==="tuple"){for(const r of s.items)if(Ce(r,n))return!0;return!!(s.rest&&Ce(s.rest,n))}return!1}const Gg=(e,t={})=>n=>{const s=Bl({...n,processors:t});return pe(e,s),Vl(s,e),Gl(s,e)},Mr=(e,t,n={})=>s=>{const{libraryOptions:r,target:i}=s??{},o=Bl({...r??{},target:i,io:t,processors:n});return pe(e,o),Vl(o,e),Gl(o,e)},qg={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Kg=(e,t,n,s)=>{const r=n;r.type="string";const{minimum:i,maximum:o,format:a,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof i=="number"&&(r.minLength=i),typeof o=="number"&&(r.maxLength=o),a&&(r.format=qg[a]??a,r.format===""&&delete r.format,a==="time"&&delete r.format),l&&(r.contentEncoding=l),c&&c.size>0){const h=[...c];h.length===1?r.pattern=h[0].source:h.length>1&&(r.allOf=[...h.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},Yg=(e,t,n,s)=>{const r=n,{minimum:i,maximum:o,format:a,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:h}=e._zod.bag;typeof a=="string"&&a.includes("int")?r.type="integer":r.type="number",typeof h=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.minimum=h,r.exclusiveMinimum=!0):r.exclusiveMinimum=h),typeof i=="number"&&(r.minimum=i,typeof h=="number"&&t.target!=="draft-04"&&(h>=i?delete r.minimum:delete r.exclusiveMinimum)),typeof l=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.maximum=l,r.exclusiveMaximum=!0):r.exclusiveMaximum=l),typeof o=="number"&&(r.maximum=o,typeof l=="number"&&t.target!=="draft-04"&&(l<=o?delete r.maximum:delete r.exclusiveMaximum)),typeof c=="number"&&(r.multipleOf=c)},Xg=(e,t,n,s)=>{n.type="boolean"},Jg=(e,t,n,s)=>{n.not={}},Qg=(e,t,n,s)=>{},em=(e,t,n,s)=>{const r=e._zod.def,i=xl(r.entries);i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},tm=(e,t,n,s)=>{const r=e._zod.def,i=[];for(const o of r.values)if(o===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},nm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},sm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},rm=(e,t,n,s)=>{const r=n,i=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(r.minItems=o),typeof a=="number"&&(r.maxItems=a),r.type="array",r.items=pe(i.element,t,{...s,path:[...s.path,"items"]})},im=(e,t,n,s)=>{var l;const r=n,i=e._zod.def;r.type="object",r.properties={};const o=i.shape;for(const h in o)r.properties[h]=pe(o[h],t,{...s,path:[...s.path,"properties",h]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(h=>{const f=i.shape[h]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(r.required=Array.from(c)),((l=i.catchall)==null?void 0:l._zod.def.type)==="never"?r.additionalProperties=!1:i.catchall?i.catchall&&(r.additionalProperties=pe(i.catchall,t,{...s,path:[...s.path,"additionalProperties"]})):t.io==="output"&&(r.additionalProperties=!1)},om=(e,t,n,s)=>{const r=e._zod.def,i=r.inclusive===!1,o=r.options.map((a,c)=>pe(a,t,{...s,path:[...s.path,i?"oneOf":"anyOf",c]}));i?n.oneOf=o:n.anyOf=o},am=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.left,t,{...s,path:[...s.path,"allOf",0]}),o=pe(r.right,t,{...s,path:[...s.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,c=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=c},cm=(e,t,n,s)=>{const r=n,i=e._zod.def;r.type="object";const o=i.keyType,a=o._zod.bag,c=a==null?void 0:a.patterns;if(i.mode==="loose"&&c&&c.size>0){const h=pe(i.valueType,t,{...s,path:[...s.path,"patternProperties","*"]});r.patternProperties={};for(const f of c)r.patternProperties[f.source]=h}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(r.propertyNames=pe(i.keyType,t,{...s,path:[...s.path,"propertyNames"]})),r.additionalProperties=pe(i.valueType,t,{...s,path:[...s.path,"additionalProperties"]});const l=o._zod.values;if(l){const h=[...l].filter(f=>typeof f=="string"||typeof f=="number");h.length>0&&(r.required=h)}},lm=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.innerType,t,s),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=r.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},um=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},hm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},dm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(r.defaultValue)))},pm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType;let o;try{o=r.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},fm=(e,t,n,s)=>{const r=e._zod.def,i=t.io==="input"?r.in._zod.def.type==="transform"?r.out:r.in:r.out;pe(i,t,s);const o=t.seen.get(e);o.ref=i},gm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.readOnly=!0},ql=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},mm=b("ZodISODateTime",(e,t)=>{vf.init(e,t),ae.init(e,t)});function vm(e){return Sg(mm,e)}const _m=b("ZodISODate",(e,t)=>{_f.init(e,t),ae.init(e,t)});function ym(e){return xg(_m,e)}const km=b("ZodISOTime",(e,t)=>{yf.init(e,t),ae.init(e,t)});function wm(e){return Eg(km,e)}const bm=b("ZodISODuration",(e,t)=>{kf.init(e,t),ae.init(e,t)});function Sm(e){return Ag(bm,e)}const Kl=(e,t)=>{Il.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>lp(e,n)},flatten:{value:n=>cp(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Xi,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Xi,2)}},isEmpty:{get(){return e.issues.length===0}}})},vc=b("ZodError",Kl),He=b("ZodError",Kl,{Parent:Error}),xm=Vo(He),Em=Go(He),Am=ti(He),Tm=ni(He),Im=dp(He),Cm=pp(He),zm=fp(He),$m=gp(He),Rm=mp(He),Pm=vp(He),Dm=_p(He),Lm=yp(He),oe=b("ZodType",(e,t)=>(ie.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Mr(e,"input"),output:Mr(e,"output")}}),e.toJSONSchema=Gg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Pt(t,{checks:[...t.checks??[],...n.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0}),e.with=e.check,e.clone=(n,s)=>Dt(e,n,s),e.brand=()=>e,e.register=(n,s)=>(n.add(e,s),e),e.parse=(n,s)=>xm(e,n,s,{callee:e.parse}),e.safeParse=(n,s)=>Am(e,n,s),e.parseAsync=async(n,s)=>Em(e,n,s,{callee:e.parseAsync}),e.safeParseAsync=async(n,s)=>Tm(e,n,s),e.spa=e.safeParseAsync,e.encode=(n,s)=>Im(e,n,s),e.decode=(n,s)=>Cm(e,n,s),e.encodeAsync=async(n,s)=>zm(e,n,s),e.decodeAsync=async(n,s)=>$m(e,n,s),e.safeEncode=(n,s)=>Rm(e,n,s),e.safeDecode=(n,s)=>Pm(e,n,s),e.safeEncodeAsync=async(n,s)=>Dm(e,n,s),e.safeDecodeAsync=async(n,s)=>Lm(e,n,s),e.refine=(n,s)=>e.check(Tv(n,s)),e.superRefine=n=>e.check(Iv(n)),e.overwrite=n=>e.check(Bn(n)),e.optional=()=>kc(e),e.exactOptional=()=>fv(e),e.nullable=()=>wc(e),e.nullish=()=>kc(wc(e)),e.nonoptional=n=>kv(e,n),e.array=()=>R(e),e.or=n=>W([e,n]),e.and=n=>ri(e,n),e.transform=n=>bc(e,dv(n)),e.default=n=>vv(e,n),e.prefault=n=>yv(e,n),e.catch=n=>bv(e,n),e.pipe=n=>bc(e,n),e.readonly=()=>Ev(e),e.describe=n=>{const s=e.clone();return hs.add(s,{description:n}),s},Object.defineProperty(e,"description",{get(){var n;return(n=hs.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return hs.get(e);const s=e.clone();return hs.add(s,n[0]),s},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),Yl=b("_ZodString",(e,t)=>{qo.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Kg(e,s,r);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...s)=>e.check(Rg(...s)),e.includes=(...s)=>e.check(Lg(...s)),e.startsWith=(...s)=>e.check(Mg(...s)),e.endsWith=(...s)=>e.check(Og(...s)),e.min=(...s)=>e.check(Lr(...s)),e.max=(...s)=>e.check(jl(...s)),e.length=(...s)=>e.check(Hl(...s)),e.nonempty=(...s)=>e.check(Lr(1,...s)),e.lowercase=s=>e.check(Pg(s)),e.uppercase=s=>e.check(Dg(s)),e.trim=()=>e.check(Wg()),e.normalize=(...s)=>e.check(Ng(...s)),e.toLowerCase=()=>e.check(Fg()),e.toUpperCase=()=>e.check(Ug()),e.slugify=()=>e.check(Zg())}),Mm=b("ZodString",(e,t)=>{qo.init(e,t),Yl.init(e,t),e.email=n=>e.check(ng(Om,n)),e.url=n=>e.check(ag(Nm,n)),e.jwt=n=>e.check(bg(Qm,n)),e.emoji=n=>e.check(cg(Wm,n)),e.guid=n=>e.check(pc(_c,n)),e.uuid=n=>e.check(sg(hr,n)),e.uuidv4=n=>e.check(rg(hr,n)),e.uuidv6=n=>e.check(ig(hr,n)),e.uuidv7=n=>e.check(og(hr,n)),e.nanoid=n=>e.check(lg(Fm,n)),e.guid=n=>e.check(pc(_c,n)),e.cuid=n=>e.check(ug(Um,n)),e.cuid2=n=>e.check(hg(Zm,n)),e.ulid=n=>e.check(dg(jm,n)),e.base64=n=>e.check(yg(Ym,n)),e.base64url=n=>e.check(kg(Xm,n)),e.xid=n=>e.check(pg(Hm,n)),e.ksuid=n=>e.check(fg(Bm,n)),e.ipv4=n=>e.check(gg(Vm,n)),e.ipv6=n=>e.check(mg(Gm,n)),e.cidrv4=n=>e.check(vg(qm,n)),e.cidrv6=n=>e.check(_g(Km,n)),e.e164=n=>e.check(wg(Jm,n)),e.datetime=n=>e.check(vm(n)),e.date=n=>e.check(ym(n)),e.time=n=>e.check(wm(n)),e.duration=n=>e.check(Sm(n))});function u(e){return tg(Mm,e)}const ae=b("ZodStringFormat",(e,t)=>{se.init(e,t),Yl.init(e,t)}),Om=b("ZodEmail",(e,t)=>{cf.init(e,t),ae.init(e,t)}),_c=b("ZodGUID",(e,t)=>{of.init(e,t),ae.init(e,t)}),hr=b("ZodUUID",(e,t)=>{af.init(e,t),ae.init(e,t)}),Nm=b("ZodURL",(e,t)=>{lf.init(e,t),ae.init(e,t)}),Wm=b("ZodEmoji",(e,t)=>{uf.init(e,t),ae.init(e,t)}),Fm=b("ZodNanoID",(e,t)=>{hf.init(e,t),ae.init(e,t)}),Um=b("ZodCUID",(e,t)=>{df.init(e,t),ae.init(e,t)}),Zm=b("ZodCUID2",(e,t)=>{pf.init(e,t),ae.init(e,t)}),jm=b("ZodULID",(e,t)=>{ff.init(e,t),ae.init(e,t)}),Hm=b("ZodXID",(e,t)=>{gf.init(e,t),ae.init(e,t)}),Bm=b("ZodKSUID",(e,t)=>{mf.init(e,t),ae.init(e,t)}),Vm=b("ZodIPv4",(e,t)=>{wf.init(e,t),ae.init(e,t)}),Gm=b("ZodIPv6",(e,t)=>{bf.init(e,t),ae.init(e,t)}),qm=b("ZodCIDRv4",(e,t)=>{Sf.init(e,t),ae.init(e,t)}),Km=b("ZodCIDRv6",(e,t)=>{xf.init(e,t),ae.init(e,t)}),Ym=b("ZodBase64",(e,t)=>{Ef.init(e,t),ae.init(e,t)}),Xm=b("ZodBase64URL",(e,t)=>{Tf.init(e,t),ae.init(e,t)}),Jm=b("ZodE164",(e,t)=>{If.init(e,t),ae.init(e,t)}),Qm=b("ZodJWT",(e,t)=>{zf.init(e,t),ae.init(e,t)}),Xl=b("ZodNumber",(e,t)=>{Nl.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Yg(e,s,r),e.gt=(s,r)=>e.check(gc(s,r)),e.gte=(s,r)=>e.check($i(s,r)),e.min=(s,r)=>e.check($i(s,r)),e.lt=(s,r)=>e.check(fc(s,r)),e.lte=(s,r)=>e.check(zi(s,r)),e.max=(s,r)=>e.check(zi(s,r)),e.int=s=>e.check(yc(s)),e.safe=s=>e.check(yc(s)),e.positive=s=>e.check(gc(0,s)),e.nonnegative=s=>e.check($i(0,s)),e.negative=s=>e.check(fc(0,s)),e.nonpositive=s=>e.check(zi(0,s)),e.multipleOf=(s,r)=>e.check(mc(s,r)),e.step=(s,r)=>e.check(mc(s,r)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function N(e){return Tg(Xl,e)}const ev=b("ZodNumberFormat",(e,t)=>{$f.init(e,t),Xl.init(e,t)});function yc(e){return Ig(ev,e)}const tv=b("ZodBoolean",(e,t)=>{Rf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Xg(e,n,s)});function _e(e){return Cg(tv,e)}const nv=b("ZodUnknown",(e,t)=>{Pf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Qg()});function _(){return zg(nv)}const sv=b("ZodNever",(e,t)=>{Df.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Jg(e,n,s)});function rv(e){return $g(sv,e)}const iv=b("ZodArray",(e,t)=>{Lf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>rm(e,n,s,r),e.element=t.element,e.min=(n,s)=>e.check(Lr(n,s)),e.nonempty=n=>e.check(Lr(1,n)),e.max=(n,s)=>e.check(jl(n,s)),e.length=(n,s)=>e.check(Hl(n,s)),e.unwrap=()=>e.element});function R(e,t){return jg(iv,e,t)}const Jl=b("ZodObject",(e,t)=>{Of.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>im(e,n,s,r),q(e,"shape",()=>t.shape),e.keyof=()=>eu(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:_()}),e.loose=()=>e.clone({...e._zod.def,catchall:_()}),e.strict=()=>e.clone({...e._zod.def,catchall:rv()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>sp(e,n),e.safeExtend=n=>rp(e,n),e.merge=n=>ip(e,n),e.pick=n=>tp(e,n),e.omit=n=>np(e,n),e.partial=(...n)=>op(tu,e,n[0]),e.required=(...n)=>ap(nu,e,n[0])});function Ko(e,t){const n={type:"object",shape:e??{},...P(t)};return new Jl(n)}function p(e,t){return new Jl({type:"object",shape:e,catchall:_(),...P(t)})}const Ql=b("ZodUnion",(e,t)=>{Ul.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>om(e,n,s,r),e.options=t.options});function W(e,t){return new Ql({type:"union",options:e,...P(t)})}const ov=b("ZodDiscriminatedUnion",(e,t)=>{Ql.init(e,t),Nf.init(e,t)});function av(e,t,n){return new ov({type:"union",options:t,discriminator:e,...P(n)})}const cv=b("ZodIntersection",(e,t)=>{Wf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>am(e,n,s,r)});function ri(e,t){return new cv({type:"intersection",left:e,right:t})}const lv=b("ZodRecord",(e,t)=>{Ff.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>cm(e,n,s,r),e.keyType=t.keyType,e.valueType=t.valueType});function k(e,t,n){return new lv({type:"record",keyType:e,valueType:t,...P(n)})}const Qi=b("ZodEnum",(e,t)=>{Uf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>em(e,s,r),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(s,r)=>{const i={};for(const o of s)if(n.has(o))i[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Qi({...t,checks:[],...P(r),entries:i})},e.exclude=(s,r)=>{const i={...t.entries};for(const o of s)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Qi({...t,checks:[],...P(r),entries:i})}});function eu(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(s=>[s,s])):e;return new Qi({type:"enum",entries:n,...P(t)})}const uv=b("ZodLiteral",(e,t)=>{Zf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>tm(e,n,s),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function S(e,t){return new uv({type:"literal",values:Array.isArray(e)?e:[e],...P(t)})}const hv=b("ZodTransform",(e,t)=>{jf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>sm(e,n),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new bl(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(ks(i,n.value,t));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(ks(o))}};const r=t.transform(n.value,n);return r instanceof Promise?r.then(i=>(n.value=i,n)):(n.value=r,n)}});function dv(e){return new hv({type:"transform",transform:e})}const tu=b("ZodOptional",(e,t)=>{Zl.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>ql(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function kc(e){return new tu({type:"optional",innerType:e})}const pv=b("ZodExactOptional",(e,t)=>{Hf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>ql(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function fv(e){return new pv({type:"optional",innerType:e})}const gv=b("ZodNullable",(e,t)=>{Bf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>lm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function wc(e){return new gv({type:"nullable",innerType:e})}const mv=b("ZodDefault",(e,t)=>{Vf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>hm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function vv(e,t){return new mv({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Al(t)}})}const _v=b("ZodPrefault",(e,t)=>{Gf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>dm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function yv(e,t){return new _v({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Al(t)}})}const nu=b("ZodNonOptional",(e,t)=>{qf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>um(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function kv(e,t){return new nu({type:"nonoptional",innerType:e,...P(t)})}const wv=b("ZodCatch",(e,t)=>{Kf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>pm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function bv(e,t){return new wv({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Sv=b("ZodPipe",(e,t)=>{Yf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>fm(e,n,s,r),e.in=t.in,e.out=t.out});function bc(e,t){return new Sv({type:"pipe",in:e,out:t})}const xv=b("ZodReadonly",(e,t)=>{Xf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>gm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function Ev(e){return new xv({type:"readonly",innerType:e})}const Av=b("ZodCustom",(e,t)=>{Jf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>nm(e,n)});function Tv(e,t={}){return Hg(Av,e,t)}function Iv(e){return Bg(e)}const su=Ko({kind:S("file"),path:u()}),Cv=Ko({id:u(),type:S("markdown"),title:u(),token:u(),source:su}),zv=Ko({id:u(),type:S("html"),title:u(),token:u(),source:su});av("type",[Cv,zv]);const ru="markdown";function $v(e){const t=e.type??ru;return{id:e.id??en(),type:t,title:e.title,token:e.token??en(),source:e.source}}const st=4,We=6,iu=2,eo=2,Rv=st,Pv=We,Yo="auto",zt="auto",Zt=120,Sc=75,ce=16,Tt=Zt*st+ce*(st-1),In=Zt*We+ce*(We-1),Dv=200,Lv=4,dr=150,Mv=10,xc=2;function to(e,t={}){return{id:t.id??en(),type:"card",artifactID:e,width:t.width??Yo,height:t.height??zt}}function no(e,t){return e.some(n=>ou(n,t))}function ou(e,t){switch(e.type){case"card":return e.artifactID===t;case"row":return e.children.some(n=>n.artifactID===t);case"stack":return e.children.some(n=>ou(n,t))}}function Ri(e){return e.layout.flatMap(au)}function au(e){switch(e.type){case"card":return[e.artifactID];case"row":return e.children.map(t=>t.artifactID);case"stack":return e.children.flatMap(au)}}const Ov=4,Nv=/^[0-9A-HJKMNP-TV-Z]{26}$/;function cu(e){return hu(e)}function lu(e,t){return hu(e.flatMap(n=>pu(n,t)))}function uu(e){const t=[],n=new Set;for(const s of e){if(s.type==="row"){t.push(`Top-level rows are invalid: ${s.id}`);continue}fu(s,"strip",t,n)}return{valid:t.length===0,errors:t}}function zn(e){const t=cu(e),n=uu(t);if(!n.valid)throw new Error(`Invalid layout: ${n.errors.join("; ")}`);return{totalNodes:t.length,nodes:t.filter(s=>s.type!=="row").map(Zv)}}function hu(e){const t=[];for(const n of e){const s=du(n);for(const r of s){if(r.type==="row"){t.push(...r.children.map(_t));continue}t.push(r)}}return t}function du(e){switch(e.type){case"card":return[_t(e)];case"row":{const t=e.children.map(_t);return t.length===0?[]:t.length===1?[t[0]]:[{...e,children:t}]}case"stack":{const t=[];for(const n of e.children){const s=du(n);for(const r of s){if(r.type==="stack"){t.push(...r.children.map(so));continue}if(r.type==="row"){t.push({...r,children:r.children.map(_t)});continue}t.push(_t(r))}}return t.length===0?[]:t.length===1?[so(t[0])]:[{...e,children:t}]}}}function pu(e,t){switch(e.type){case"card":return e.artifactID===t?[]:[_t(e)];case"row":{const n=e.children.filter(s=>s.artifactID!==t).map(_t);return n.length===0?[]:n.length===1?[n[0]]:[{...e,children:n}]}case"stack":{const n=e.children.flatMap(s=>pu(s,t).filter(i=>i.type!=="stack"));return n.length===0?[]:n.length===1?[so(n[0])]:[{...e,children:n}]}}}function fu(e,t,n,s){switch(e.type){case"card":gu(e,t,n,s);return;case"row":Wv(e,t,n,s);return;case"stack":Fv(e,t,n,s);return}}function gu(e,t,n,s){Xo(e.id,n),typeof e.artifactID!="string"||e.artifactID.length===0?n.push(`Card ${e.id} is missing artifactID`):s.has(e.artifactID)?n.push(`Duplicate artifactID in layout: ${e.artifactID}`):s.add(e.artifactID),Uv(e.width)||n.push(`Card ${e.id} width must be an integer in the range 2-4`),mu(e.height)||n.push(`Card ${e.id} height must be an integer in the range 2-6 or "auto"`);const r=jt(e.width);t==="row"&&r<iu&&n.push(`Row child ${e.id} must be at least 2 columns wide`)}function Wv(e,t,n,s){if(Xo(e.id,n),t!=="stack"&&n.push(`Row ${e.id} may only appear inside a stack`),mu(e.height,Ov)||n.push(`Row ${e.id} height must be an integer in the range 2-4 or "auto"`),!Array.isArray(e.children)||e.children.length===0){n.push(`Row ${e.id} must contain card nodes`);return}let r=0;for(const i of e.children){if(i.type!=="card"){n.push(`Row ${e.id} must contain only card nodes`);continue}gu(i,"row",n,s),r+=jt(i.width)}r!==st&&n.push(`Row ${e.id} children must sum to 4 columns`)}function Fv(e,t,n,s){if(Xo(e.id,n),t!=="strip"&&n.push(`Invalid nested stack at ${e.id}; stack children cannot contain another nested stack`),!Array.isArray(e.children)||e.children.length===0){n.push(`Stack ${e.id} must contain at least one child`);return}let r=0,i=0;for(const a of e.children){if(a.type==="stack"){n.push(`Stack ${e.id} cannot contain another nested stack`);continue}if(fu(a,"stack",n,s),a.height===zt){i+=1;continue}r+=a.height}if(r>We&&n.push(`Stack ${e.id} exceeds the 6-row budget`),i===0)return;const o=We-r;if(o<i*eo||o%i!==0){n.push(`Stack ${e.id} has auto-height children that cannot resolve to whole height >= 2`);return}o/i<eo&&n.push(`Stack ${e.id} has auto-height children below the minimum row size`)}function Xo(e,t){(typeof e!="string"||!Nv.test(e))&&t.push(`Node id must be a ULID: ${String(e)}`)}function Uv(e){return e===Yo||Number.isInteger(e)&&e>=iu&&e<=Rv}function mu(e,t=Pv){return e===zt||Number.isInteger(e)&&e>=eo&&e<=t}function jt(e){return e===Yo?st:e}function Zv(e){if(e.type==="card")return{id:e.id,type:"card",width:jt(e.width),cards:[{id:e.id,artifactID:e.artifactID,col:1,row:1,width:jt(e.width),height:vu(e.height,We)}]};const t=jv(e.children),n=[];let s=1;for(let r=0;r<e.children.length;r+=1){const i=e.children[r],o=t[r];if(i.type==="card")n.push({id:i.id,artifactID:i.artifactID,col:1,row:s,width:jt(i.width),height:o});else{let a=1;for(const c of i.children)n.push({id:c.id,artifactID:c.artifactID,col:a,row:s,width:jt(c.width),height:o}),a+=jt(c.width)}s+=o}return{id:e.id,type:"stack",width:n.reduce((r,i)=>Math.max(r,i.col+i.width-1),1),cards:n}}function jv(e){let t=0,n=0;for(const r of e)r.height===zt?n+=1:t+=r.height;const s=n>0?(We-t)/n:0;return e.map(r=>vu(r.height,s))}function vu(e,t){return e===zt?t:e}function _t(e){return{...e}}function so(e){return e.type==="card"?_t(e):{...e,children:e.children.map(_t)}}const Pi="create-artifact",Di="remove-artifact",pr="update-layout";class Hv extends ln{constructor(n){var r;super();m(this,"artifacts",new Map);m(this,"activeWorkspaceID",null);m(this,"scrollPosition",0);m(this,"artifactReloadVersions",new Map);m(this,"activeWorkspaceData",null);m(this,"clientStore");m(this,"serverManager");m(this,"pendingMutations",new Map);m(this,"pendingWorkspaceCreates",new Map);m(this,"pendingWorkspaceDeletes",new Map);this.clientStore=n.clientStore,this.serverManager=n.serverManager;const s=this.clientStore.get();this.activeWorkspaceID=(s==null?void 0:s.lastWorkspaceID)??null,this.activeWorkspaceID&&(this.scrollPosition=((r=s==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0)}get workspaces(){return[...this.serverManager.servers.values()].flatMap(n=>[...n.workspaces.values()])}get activeWorkspace(){return this.activeWorkspaceData}get activeWorkspaceServerURL(){var n;return this.activeWorkspaceID?((n=this.findWorkspace(this.activeWorkspaceID))==null?void 0:n.serverURL)??null:null}get activeArtifacts(){return(this.activeWorkspaceData?Ri(this.activeWorkspaceData):[]).map(n=>this.artifacts.get(n)).filter(n=>n!==void 0)}getArtifactURL(n){const s=this.activeWorkspaceServerURL;if(!s)return null;const r=this.serverManager.servers.get(s),i=this.artifacts.get(n);if(!(r!=null&&r.getArtifactURL)||!i)return null;const o=r.getArtifactURL(i);if(i.type!=="html")return o;const a=this.artifactReloadVersions.get(n)??0,c=new URL(o);return c.searchParams.set("rev",String(a)),c.toString()}setActiveWorkspace(n){this.selectWorkspace(n)}setScrollPosition(n){const s=Math.max(0,n);this.scrollPosition!==s&&(this.scrollPosition=s,this.persistWorkspaceViewState(),this.dispatchEvent(new B("change")))}createArtifact(n){var c;const s=this.activeWorkspaceData;if(!s)return;const r=this.snapshotState(),i=$v({id:en(),type:n.type??ru,title:n.title,source:{kind:"file",path:n.path}});no(s.layout,i.id)||(s.layout=[...s.layout,to(i.id)]),this.artifacts.set(i.id,i),this.scrollPosition=Bv(s.layout),this.persistWorkspaceViewState(),this.dispatchEvent(new B("change"));const o=((c=this.findWorkspace(s.id))==null?void 0:c.server)??null,a=this.getMutationKey(Pi,i.id);this.pendingMutations.set(a,r),this.sendServerMessage(o,{type:"create-artifact",id:i.id,path:n.path,artifactType:i.type,workspaceID:s.id})||(this.pendingMutations.delete(a),this.restoreState(r),this.dispatchEvent(new B("change")))}removeArtifact(n){var a;const s=this.activeWorkspaceData;if(!s||!this.artifacts.has(n))return;const r=this.snapshotState();this.removeArtifactLocally(n),this.dispatchEvent(new B("change"));const i=((a=this.findWorkspace(s.id))==null?void 0:a.server)??null,o=this.getMutationKey(Di,n);this.pendingMutations.set(o,r),this.sendServerMessage(i,{type:"remove-artifact",artifactID:n,workspaceID:s.id})||(this.pendingMutations.delete(o),this.restoreState(r),this.dispatchEvent(new B("change")))}handleServerEvent(n,s){var r;switch(s.type){case"workspace-list":this.syncActiveWorkspaceState(n,!0);break;case"workspace-updated":this.syncActiveWorkspaceState(n,!1),Array.isArray(s.fields.layout)&&this.pendingMutations.delete(this.getMutationKey(pr,s.workspaceID));break;case"workspace-removed":{this.syncActiveWorkspaceState(n,!1);const i=this.pendingWorkspaceDeletes.get(s.workspaceID);i&&(this.pendingWorkspaceDeletes.delete(s.workspaceID),i.resolve());break}case"workspace-created":if(this.pendingWorkspaceCreates.has(s.workspace.id)){const i=this.pendingWorkspaceCreates.get(s.workspace.id);this.pendingWorkspaceCreates.delete(s.workspace.id),this.selectWorkspace(s.workspace.id),i==null||i.resolve();return}this.syncActiveWorkspaceState(n,!1);break;case"workspace":this.applyWorkspaceSnapshot(s.workspace,s.artifacts);break;case"artifact-created":this.pendingMutations.delete(this.getMutationKey(Pi,s.artifact.id)),this.applyArtifactCreated(s);break;case"artifact-updated":this.applyArtifactUpdated(s);break;case"artifact-removed":if(this.pendingMutations.delete(this.getMutationKey(Di,s.artifactID)),((r=this.activeWorkspaceData)==null?void 0:r.id)!==s.workspaceID)return;this.removeArtifactLocally(s.artifactID)&&this.dispatchEvent(new B("change"));break;case"error":this.handleServerError(s);break}}createWorkspace(n,s){const r=this.serverManager.servers.get(n)??null,i=en(),o=Ec();return this.pendingWorkspaceCreates.set(i,o),this.sendServerMessage(r,{type:"create-workspace",id:i,name:s})||(this.pendingWorkspaceCreates.delete(i),o.reject(new Error(`Server unavailable: ${n}`))),o.promise}deleteWorkspace(){var o;const n=this.activeWorkspaceData;if(!n)return Promise.reject(new Error("No active workspace"));const s=this.pendingWorkspaceDeletes.get(n.id);if(s)return s.promise;const r=((o=this.findWorkspace(n.id))==null?void 0:o.server)??null,i=Ec();return this.pendingWorkspaceDeletes.set(n.id,i),this.sendServerMessage(r,{type:"delete-workspace",workspaceID:n.id})||(this.pendingWorkspaceDeletes.delete(n.id),i.reject(new Error(`Server unavailable: ${n.id}`))),i.promise}renameWorkspace(n){var i;const s=this.activeWorkspaceData;if(!s)return;const r=((i=this.findWorkspace(s.id))==null?void 0:i.server)??null;s.name=n,this.dispatchEvent(new B("change")),this.sendServerMessage(r,{type:"update-workspace",workspaceID:s.id,fields:{name:n}})}setLayout(n){var l;const s=this.activeWorkspaceData;if(!s)return;const r=cu(n);if(!uu(r).valid)return;const o=this.snapshotState();s.layout=r,this.dispatchEvent(new B("change"));const a=((l=this.findWorkspace(s.id))==null?void 0:l.server)??null,c=this.getMutationKey(pr,s.id);this.pendingMutations.set(c,o),this.sendServerMessage(a,{type:"update-workspace",workspaceID:s.id,fields:{layout:r.map(h=>structuredClone(h))}})||(this.pendingMutations.delete(c),this.restoreState(o),this.dispatchEvent(new B("change")))}syncActiveWorkspaceState(n,s){const r=this.activeWorkspaceID?this.findWorkspace(this.activeWorkspaceID):null;if(!r){const i=this.pickNextWorkspace();if(!i){const o=this.activeWorkspaceID!==null||this.activeWorkspaceData!==null||this.artifacts.size>0;this.activeWorkspaceID=null,this.activeWorkspaceData=null,this.artifacts.clear(),this.scrollPosition=0,o&&this.dispatchEvent(new B("change"));return}this.selectWorkspace(i.workspace.id);return}this.applyServerWorkspaceState(r.workspace),s&&r.serverURL===n&&this.requestWorkspace(r.serverURL,r.workspace.id)}hasPendingLayoutMutation(n){return this.pendingMutations.has(this.getMutationKey(pr,n))}selectWorkspace(n){const s=this.findWorkspace(n);s&&(this.activeWorkspaceID=n,this.activeWorkspaceData=structuredClone(s.workspace),this.artifacts.clear(),this.restoreWorkspaceViewState(),this.persistActiveWorkspace(),this.requestWorkspace(s.serverURL,n),this.dispatchEvent(new B("change")))}requestWorkspace(n,s){const r=this.serverManager.servers.get(n);this.sendServerMessage(r??null,{type:"get-workspace",workspaceID:s})}applyWorkspaceSnapshot(n,s){if(n.id===this.activeWorkspaceID){this.applyServerWorkspaceState(n),this.artifacts.clear();for(const r of s)this.artifacts.set(r.id,structuredClone(r));this.restoreWorkspaceViewState(),this.dispatchEvent(new B("change"))}}applyServerWorkspaceState(n){if(!this.activeWorkspaceData||this.activeWorkspaceData.id!==n.id){this.activeWorkspaceData=structuredClone(n);return}this.activeWorkspaceData.name=n.name,this.hasPendingLayoutMutation(n.id)||(this.activeWorkspaceData.layout=n.layout.map(s=>structuredClone(s)))}applyArtifactCreated(n){var s;((s=this.activeWorkspaceData)==null?void 0:s.id)===n.workspaceID&&(no(this.activeWorkspaceData.layout,n.artifact.id)||(this.activeWorkspaceData.layout=[...this.activeWorkspaceData.layout,to(n.artifact.id)]),this.artifacts.set(n.artifact.id,n.artifact),this.dispatchEvent(new B("change")))}applyArtifactUpdated(n){const s=this.artifacts.get(n.artifactID);s&&(Object.assign(s,n.fields),s.type==="html"&&this.artifactReloadVersions.set(n.artifactID,(this.artifactReloadVersions.get(n.artifactID)??0)+1),this.dispatchEvent(new B("change")))}removeArtifactLocally(n){if(!this.activeWorkspaceData)return!1;const s=this.artifacts.delete(n);this.artifactReloadVersions.delete(n);const r=Ri(this.activeWorkspaceData).length;return this.activeWorkspaceData.layout=lu(this.activeWorkspaceData.layout,n),!(!s&&r===Ri(this.activeWorkspaceData).length)}snapshotState(){return{activeWorkspaceData:this.activeWorkspaceData?structuredClone(this.activeWorkspaceData):null,scrollPosition:this.scrollPosition,artifacts:new Map([...this.artifacts.entries()].map(([n,s])=>[n,structuredClone(s)]))}}restoreState(n){this.activeWorkspaceData=n.activeWorkspaceData?structuredClone(n.activeWorkspaceData):null,this.scrollPosition=n.scrollPosition,this.artifacts.clear();for(const[s,r]of n.artifacts.entries())this.artifacts.set(s,structuredClone(r));this.persistWorkspaceViewState()}handleServerError(n){const s=n.request;if(s){if(s.type==="create-artifact"){const r=this.getMutationKey(Pi,s.id),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="create-workspace"){const r=this.pendingWorkspaceCreates.get(s.id);if(!r)return;this.pendingWorkspaceCreates.delete(s.id),r.reject(new Error(n.message));return}if(s.type==="delete-workspace"){const r=this.pendingWorkspaceDeletes.get(s.workspaceID);if(!r)return;this.pendingWorkspaceDeletes.delete(s.workspaceID),r.reject(new Error(n.message));return}if(s.type==="update-workspace"&&Array.isArray(s.fields.layout)){const r=this.getMutationKey(pr,s.workspaceID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="remove-artifact"){const r=this.getMutationKey(Di,s.artifactID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"))}}}restoreWorkspaceViewState(){var s,r;if(!this.activeWorkspaceID){this.scrollPosition=0;return}const n=((r=(s=this.clientStore.get())==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0;this.scrollPosition=Math.max(0,n),this.persistWorkspaceViewState()}persistActiveWorkspace(){this.clientStore.update(n=>{n.lastWorkspaceID=this.activeWorkspaceID})}persistWorkspaceViewState(){this.activeWorkspaceID&&this.clientStore.update(n=>{var s,r;(s=n.workspaces)[r=this.activeWorkspaceID]??(s[r]={scrollPosition:0}),n.workspaces[this.activeWorkspaceID].scrollPosition=this.scrollPosition})}findWorkspace(n){for(const[s,r]of this.serverManager.servers){const i=r.workspaces.get(n);if(i)return{serverURL:s,server:r,workspace:i}}return null}pickNextWorkspace(){var s;const n=(s=this.clientStore.get())==null?void 0:s.lastWorkspaceID;if(n){const r=this.findWorkspace(n);if(r)return r}for(const[r,i]of this.serverManager.servers){const o=i.workspaces.values().next().value;if(o)return{serverURL:r,server:i,workspace:o}}return null}sendServerMessage(n,s){return n?n.send(s):!1}getServers(){return this.serverManager.servers}getMutationKey(n,s){return`${n}:${s}`}}function Bv(e){var s;const t=zn(e);if(t.nodes.length<=1)return 0;let n=0;for(let r=0;r<t.nodes.length-1;r+=1)n+=((s=t.nodes[r])==null?void 0:s.width)??0;return n}function Ec(){let e,t;return{promise:new Promise((s,r)=>{e=s,t=r}),resolve:e,reject:t}}var _u=Symbol.for("immer-nothing"),Ac=Symbol.for("immer-draftable"),Fe=Symbol.for("immer-state");function Ye(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var ws=Object.getPrototypeOf;function Zn(e){return!!e&&!!e[Fe]}function tn(e){var t;return e?yu(e)||Array.isArray(e)||!!e[Ac]||!!((t=e.constructor)!=null&&t[Ac])||Ys(e)||oi(e):!1}var Vv=Object.prototype.constructor.toString(),Tc=new WeakMap;function yu(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let s=Tc.get(n);return s===void 0&&(s=Function.toString.call(n),Tc.set(n,s)),s===Vv}function Or(e,t,n=!0){ii(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((s,r)=>t(r,s,e))}function ii(e){const t=e[Fe];return t?t.type_:Array.isArray(e)?1:Ys(e)?2:oi(e)?3:0}function ro(e,t){return ii(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function ku(e,t,n){const s=ii(e);s===2?e.set(t,n):s===3?e.add(n):e[t]=n}function Gv(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Ys(e){return e instanceof Map}function oi(e){return e instanceof Set}function Wt(e){return e.copy_||e.base_}function io(e,t){if(Ys(e))return new Map(e);if(oi(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const n=yu(e);if(t===!0||t==="class_only"&&!n){const s=Object.getOwnPropertyDescriptors(e);delete s[Fe];let r=Reflect.ownKeys(s);for(let i=0;i<r.length;i++){const o=r[i],a=s[o];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(s[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[o]})}return Object.create(ws(e),s)}else{const s=ws(e);if(s!==null&&n)return{...e};const r=Object.create(s);return Object.assign(r,e)}}function Jo(e,t=!1){return ai(e)||Zn(e)||!tn(e)||(ii(e)>1&&Object.defineProperties(e,{set:fr,add:fr,clear:fr,delete:fr}),Object.freeze(e),t&&Object.values(e).forEach(n=>Jo(n,!0))),e}function qv(){Ye(2)}var fr={value:qv};function ai(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var Kv={};function nn(e){const t=Kv[e];return t||Ye(0,e),t}var bs;function wu(){return bs}function Yv(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ic(e,t){t&&(nn("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function oo(e){ao(e),e.drafts_.forEach(Xv),e.drafts_=null}function ao(e){e===bs&&(bs=e.parent_)}function Cc(e){return bs=Yv(bs,e)}function Xv(e){const t=e[Fe];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function zc(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return e!==void 0&&e!==n?(n[Fe].modified_&&(oo(t),Ye(4)),tn(e)&&(e=Nr(t,e),t.parent_||Wr(t,e)),t.patches_&&nn("Patches").generateReplacementPatches_(n[Fe].base_,e,t.patches_,t.inversePatches_)):e=Nr(t,n,[]),oo(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==_u?e:void 0}function Nr(e,t,n){if(ai(t))return t;const s=e.immer_.shouldUseStrictIteration(),r=t[Fe];if(!r)return Or(t,(i,o)=>$c(e,r,t,i,o,n),s),t;if(r.scope_!==e)return t;if(!r.modified_)return Wr(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;const i=r.copy_;let o=i,a=!1;r.type_===3&&(o=new Set(i),i.clear(),a=!0),Or(o,(c,l)=>$c(e,r,i,c,l,n,a),s),Wr(e,i,!1),n&&e.patches_&&nn("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function $c(e,t,n,s,r,i,o){if(r==null||typeof r!="object"&&!o)return;const a=ai(r);if(!(a&&!o)){if(Zn(r)){const c=i&&t&&t.type_!==3&&!ro(t.assigned_,s)?i.concat(s):void 0,l=Nr(e,r,c);if(ku(n,s,l),Zn(l))e.canAutoFreeze_=!1;else return}else o&&n.add(r);if(tn(r)&&!a){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[s]===r&&a)return;Nr(e,r),(!t||!t.scope_.parent_)&&typeof s!="symbol"&&(Ys(n)?n.has(s):Object.prototype.propertyIsEnumerable.call(n,s))&&Wr(e,r)}}}function Wr(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Jo(t,n)}function Jv(e,t){const n=Array.isArray(e),s={type_:n?1:0,scope_:t?t.scope_:wu(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let r=s,i=Qo;n&&(r=[s],i=Ss);const{revoke:o,proxy:a}=Proxy.revocable(r,i);return s.draft_=a,s.revoke_=o,a}var Qo={get(e,t){if(t===Fe)return e;const n=Wt(e);if(!ro(n,t))return Qv(e,n,t);const s=n[t];return e.finalized_||!tn(s)?s:s===Li(e.base_,t)?(Mi(e),e.copy_[t]=lo(s,e)):s},has(e,t){return t in Wt(e)},ownKeys(e){return Reflect.ownKeys(Wt(e))},set(e,t,n){const s=bu(Wt(e),t);if(s!=null&&s.set)return s.set.call(e.draft_,n),!0;if(!e.modified_){const r=Li(Wt(e),t),i=r==null?void 0:r[Fe];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(Gv(n,r)&&(n!==void 0||ro(e.base_,t)))return!0;Mi(e),co(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Li(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Mi(e),co(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=Wt(e),s=Reflect.getOwnPropertyDescriptor(n,t);return s&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:s.enumerable,value:n[t]}},defineProperty(){Ye(11)},getPrototypeOf(e){return ws(e.base_)},setPrototypeOf(){Ye(12)}},Ss={};Or(Qo,(e,t)=>{Ss[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});Ss.deleteProperty=function(e,t){return Ss.set.call(this,e,t,void 0)};Ss.set=function(e,t,n){return Qo.set.call(this,e[0],t,n,e[0])};function Li(e,t){const n=e[Fe];return(n?Wt(n):e)[t]}function Qv(e,t,n){var r;const s=bu(t,n);return s?"value"in s?s.value:(r=s.get)==null?void 0:r.call(e.draft_):void 0}function bu(e,t){if(!(t in e))return;let n=ws(e);for(;n;){const s=Object.getOwnPropertyDescriptor(n,t);if(s)return s;n=ws(n)}}function co(e){e.modified_||(e.modified_=!0,e.parent_&&co(e.parent_))}function Mi(e){e.copy_||(e.copy_=io(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var e_=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,s)=>{if(typeof t=="function"&&typeof n!="function"){const i=n;n=t;const o=this;return function(c=i,...l){return o.produce(c,h=>n.call(this,h,...l))}}typeof n!="function"&&Ye(6),s!==void 0&&typeof s!="function"&&Ye(7);let r;if(tn(t)){const i=Cc(this),o=lo(t,void 0);let a=!0;try{r=n(o),a=!1}finally{a?oo(i):ao(i)}return Ic(i,s),zc(r,i)}else if(!t||typeof t!="object"){if(r=n(t),r===void 0&&(r=t),r===_u&&(r=void 0),this.autoFreeze_&&Jo(r,!0),s){const i=[],o=[];nn("Patches").generateReplacementPatches_(t,r,i,o),s(i,o)}return r}else Ye(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(o,...a)=>this.produceWithPatches(o,c=>t(c,...a));let s,r;return[this.produce(t,n,(o,a)=>{s=o,r=a}),s,r]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){tn(e)||Ye(8),Zn(e)&&(e=t_(e));const t=Cc(this),n=lo(e,void 0);return n[Fe].isManual_=!0,ao(t),n}finishDraft(e,t){const n=e&&e[Fe];(!n||!n.isManual_)&&Ye(9);const{scope_:s}=n;return Ic(s,t),zc(void 0,s)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(r.path.length===0&&r.op==="replace"){e=r.value;break}}n>-1&&(t=t.slice(n+1));const s=nn("Patches").applyPatches_;return Zn(e)?s(e,t):this.produce(e,r=>s(r,t))}};function lo(e,t){const n=Ys(e)?nn("MapSet").proxyMap_(e,t):oi(e)?nn("MapSet").proxySet_(e,t):Jv(e,t);return(t?t.scope_:wu()).drafts_.push(n),n}function t_(e){return Zn(e)||Ye(10,e),Su(e)}function Su(e){if(!tn(e)||ai(e))return e;const t=e[Fe];let n,s=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=io(e,t.scope_.immer_.useStrictShallowCopy_),s=t.scope_.immer_.shouldUseStrictIteration()}else n=io(e,!0);return Or(n,(r,i)=>{ku(n,r,Su(i))},s),t&&(t.finalized_=!1),n}var n_=new e_,s_=n_.produce,r_=Object.defineProperty,i_=(e,t,n)=>t in e?r_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gr=(e,t,n)=>i_(e,typeof t!="symbol"?t+"":t,n);function o_(e){return{all:e=e||new Map,on:function(t,n){var s=e.get(t);s?s.push(n):e.set(t,[n])},off:function(t,n){var s=e.get(t);s&&(n?s.splice(s.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var s=e.get(t);s&&s.slice().map(function(r){r(n)}),(s=e.get("*"))&&s.slice().map(function(r){r(t,n)})}}}var a_=class{constructor(){gr(this,"emitter",o_()),gr(this,"on",(e,t)=>(this.emitter.on(e,t),{dispose:()=>this.emitter.off(e,t)})),gr(this,"once",(e,t)=>{const n=s=>{t(s),this.emitter.off(e,n)};return this.emitter.on(e,n),{dispose:()=>this.emitter.off(e,n)}}),gr(this,"off",this.emitter.off)}emit(e,...[t]){this.emitter.emit(e,t)}},c_="store-",l_=class extends a_{emitChange(e){this.emit("change",{state:e})}},u_=class{constructor(e,t,n){this.emitter=new l_,this.id=e,this.initValue=t,this.key=`${c_}${e}`,this.storage=(n==null?void 0:n.storage)==="session"?sessionStorage:localStorage,this.get()===void 0&&this.storage.setItem(this.key,JSON.stringify(t))}get(){const e=this.storage.getItem(this.key);return e===null?void 0:JSON.parse(e)}update(e){const t=this.get()??{},n=s_(t,e);this.storage.setItem(this.key,JSON.stringify(n)),this.emitter.emitChange(n)}reset(){this.storage.setItem(this.key,JSON.stringify(this.initValue)),this.emitter.emitChange(this.initValue)}on(e,t){return this.emitter.on(e,({state:n})=>t(n))}subscribe(e){const t=this.on("change",e),n=this.get();return n!==void 0&&e(n),t}};const h_="Local";function kt(e){return new URL(e).origin}function d_(e){return{servers:[{url:kt(e),name:h_}],lastWorkspaceID:null,workspaces:{}}}function p_(e,t){return new u_(e,d_(t))}const f_=4401;class uo extends Error{constructor(t="Authentication required"){super(t),this.name="AuthError"}}class ho extends ln{constructor(n){super();m(this,"url");m(this,"name");m(this,"token");m(this,"status","disconnected");m(this,"workspaces",new Map);m(this,"createSocket");m(this,"socket",null);m(this,"connectAttempt",0);this.url=kt(n.url),this.name=n.name,this.token=n.token??null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}async connect(){var r;this.connectAttempt+=1;const n=this.connectAttempt;(r=this.socket)==null||r.close(),this.status="connecting",this.dispatchEvent(new B("change"));const s=this.createSocket(g_(this.url,this.token));return this.socket=s,await new Promise((i,o)=>{let a=!1;const c=()=>{a||this.connectAttempt!==n||(a=!0,this.status="connected",this.dispatchEvent(new B("change")),i())},l=h=>{a||this.connectAttempt!==n||(a=!0,this.status="disconnected",this.dispatchEvent(new B("change")),o(h))};s.addEventListener("message",h=>{const f=v_(h);this.applyServerMessage(f),this.dispatchEvent(new yl("server-message",{serverURL:this.url,message:f})),a||c()}),s.addEventListener("close",h=>{if(this.connectAttempt===n){if(this.socket=null,m_(h)===f_){l(new uo);return}if(!a){l(new Error("Connection closed before initialization"));return}this.status="disconnected",this.dispatchEvent(new B("change"))}}),s.addEventListener("error",()=>{l(new Error("WebSocket connection failed"))})})}disconnect(){var n;this.connectAttempt+=1,(n=this.socket)==null||n.close(),this.socket=null,this.status="disconnected",this.dispatchEvent(new B("change"))}send(n){return!this.socket||this.socket.readyState!==1?!1:(this.socket.send(JSON.stringify(n)),!0)}getArtifactURL(n){const s=new URL(this.url);return s.pathname=`/artifact/${n.id}`,s.search="",s.searchParams.set("token",n.token),s.hash="",s.toString()}applyServerMessage(n){switch(n.type){case"workspace-list":this.workspaces=new Map(n.workspaces.map(s=>[s.id,structuredClone(s)]));break;case"workspace-created":this.workspaces.set(n.workspace.id,structuredClone(n.workspace));break;case"workspace-updated":{const s=this.workspaces.get(n.workspaceID);s&&(typeof n.fields.name=="string"&&(s.name=n.fields.name),Array.isArray(n.fields.layout)&&(s.layout=n.fields.layout));break}case"workspace-removed":this.workspaces.delete(n.workspaceID);break;case"artifact-created":{const s=this.workspaces.get(n.workspaceID);s&&!no(s.layout,n.artifact.id)&&(s.layout=[...s.layout,to(n.artifact.id)]);break}case"artifact-removed":{const s=this.workspaces.get(n.workspaceID);s&&(s.layout=lu(s.layout,n.artifactID));break}}}}function g_(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname="/ws",n.search="",t&&n.searchParams.set("token",t),n.hash="",n.toString()}function m_(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="number"?e.code:null}function v_(e){const t=typeof e=="string"?e:typeof e=="object"&&e!==null&&"data"in e&&typeof e.data=="string"?e.data:"";return JSON.parse(t)}class __ extends ln{constructor(n){super();m(this,"servers",new Map);m(this,"localServerURL");m(this,"activeServer",null);m(this,"clientStore");m(this,"createSocket");m(this,"serverListeners",new Map);this.clientStore=n.clientStore,this.localServerURL=n.localServerURL?kt(n.localServerURL):null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}add(n){const s=kt(n.url);this.servers.get(s)&&this.remove(s),this.servers.set(s,n);const i=()=>{this.dispatchEvent(new B("change"))},o=a=>{this.dispatchEvent(new yl("server-message",{serverURL:a.serverURL,message:a.message}))};n.addEventListener("change",i),n.addEventListener("server-message",o),this.serverListeners.set(s,{onServerChange:i,onServerMessage:o}),this.dispatchEvent(new B("change"))}remove(n){const s=kt(n);if(this.localServerURL&&s===this.localServerURL)return;const r=this.servers.get(s);if(!r)return;const i=this.serverListeners.get(s);i&&(r.removeEventListener("change",i.onServerChange),r.removeEventListener("server-message",i.onServerMessage),this.serverListeners.delete(s)),r.disconnect(),this.servers.delete(s),this.activeServer===r&&(this.activeServer=null),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>a.url!==s)}),this.dispatchEvent(new B("change"))}setActive(n){this.activeServer=n,this.dispatchEvent(new B("change"))}connectConfiguredServers(n){var i;const s=((i=this.clientStore.get())==null?void 0:i.servers)??[];for(const o of s){const a=new ho({url:o.url,name:o.name,createSocket:this.createSocket});this.add(a),a.connect().catch(()=>{})}const r=n?this.servers.get(kt(n))??null:null;this.setActive(r??this.servers.values().next().value??null)}addServer(n,s){const r=kt(n);this.remove(r),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>kt(a.url)!==r),o.servers.push({url:r,name:s})});const i=new ho({url:r,name:s,createSocket:this.createSocket});this.add(i),this.setActive(i),i.connect().catch(()=>{})}removeServer(n){this.remove(n)}}const te={authenticate:"authenticate",document_did_change:"document/didChange",document_did_close:"document/didClose",document_did_focus:"document/didFocus",document_did_open:"document/didOpen",document_did_save:"document/didSave",initialize:"initialize",logout:"logout",nes_accept:"nes/accept",nes_close:"nes/close",nes_reject:"nes/reject",nes_start:"nes/start",nes_suggest:"nes/suggest",session_cancel:"session/cancel",session_close:"session/close",session_fork:"session/fork",session_list:"session/list",session_load:"session/load",session_new:"session/new",session_prompt:"session/prompt",session_resume:"session/resume",session_set_config_option:"session/set_config_option",session_set_mode:"session/set_mode",session_set_model:"session/set_model"},ct={fs_read_text_file:"fs/read_text_file",fs_write_text_file:"fs/write_text_file",session_request_permission:"session/request_permission",session_update:"session/update",terminal_create:"terminal/create",terminal_kill:"terminal/kill",terminal_output:"terminal/output",terminal_release:"terminal/release",terminal_wait_for_exit:"terminal/wait_for_exit"},y_=1,k_=p({_meta:k(u(),_()).nullish(),terminal:_e().optional().default(!1)}),w_=p({_meta:k(u(),_()).nullish(),label:u().nullish(),name:u(),optional:_e().optional().default(!1),secret:_e().optional().default(!0)}),b_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),name:u()}),S_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),link:u().nullish(),name:u(),vars:R(w_)}),x_=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),description:u().nullish(),env:k(u(),u()).optional(),id:u(),name:u()}),E_=W([S_.and(p({type:S("env_var")})),x_.and(p({type:S("terminal")})),b_]),A_=p({_meta:k(u(),_()).nullish(),methodId:u()}),T_=p({_meta:k(u(),_()).nullish()}),I_=p({_meta:k(u(),_()).nullish(),blob:u(),mimeType:u().nullish(),uri:u()}),C_=p({default:_e().nullish(),description:u().nullish(),title:u().nullish()}),z_=p({_meta:k(u(),_()).nullish()}),$_=p({_meta:k(u(),_()).nullish()}),R_=p({amount:N(),currency:u()}),P_=p({_meta:k(u(),_()).nullish(),terminalId:u()}),D_=p({_meta:k(u(),_()).nullish(),newText:u(),oldText:u().nullish(),path:u()}),L_=W([u(),N(),N(),_e(),R(u())]),M_=p({content:k(u(),L_).nullish()}),O_=W([M_.and(p({action:S("accept")})),p({action:S("decline")}),p({action:S("cancel")})]),N_=p({_meta:k(u(),_()).nullish()}),xu=u(),W_=p({_meta:k(u(),_()).nullish(),elicitationId:xu}),F_=p({_meta:k(u(),_()).nullish(),action:O_}),U_=S("object"),Z_=S("string"),j_=p({_meta:k(u(),_()).nullish()}),H_=p({_meta:k(u(),_()).nullish(),form:N_.nullish(),url:j_.nullish()}),B_=p({elicitationId:xu,url:u().url()}),Eu=p({const:u(),title:u()}),Au=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),V_=W([S(-32700),S(-32600),S(-32601),S(-32602),S(-32603),S(-32800),S(-32e3),S(-32002),S(-32042),N().int().min(-2147483648,{message:"Invalid value: Expected int32 to be >= -2147483648"}).max(2147483647,{message:"Invalid value: Expected int32 to be <= 2147483647"})]),Tu=p({code:V_,data:_().optional(),message:u()}),Iu=_(),Cu=_(),zu=_(),G_=p({_meta:k(u(),_()).nullish(),readTextFile:_e().optional().default(!1),writeTextFile:_e().optional().default(!1)}),$u=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),Ru=p({_meta:k(u(),_()).nullish(),name:u(),title:u().nullish(),version:u()}),q_=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),K_=p({_meta:k(u(),_()).nullish()}),Y_=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cursor:u().nullish(),cwd:u().nullish()}),X_=p({_meta:k(u(),_()).nullish()}),J_=p({_meta:k(u(),_()).nullish(),logout:X_.nullish()}),Q_=p({_meta:k(u(),_()).nullish()}),ey=p({_meta:k(u(),_()).nullish()}),ty=p({_meta:k(u(),_()).nullish(),http:_e().optional().default(!1),sse:_e().optional().default(!1)}),ny=p({_meta:k(u(),_()).nullish(),headers:R($u),name:u(),url:u()}),sy=p({_meta:k(u(),_()).nullish(),headers:R($u),name:u(),url:u()}),ry=p({_meta:k(u(),_()).nullish(),args:R(u()),command:u(),env:R(Au),name:u()}),ci=W([ny.and(p({type:S("http")})),sy.and(p({type:S("sse")})),ry]),ea=u(),iy=p({_meta:k(u(),_()).nullish(),description:u().nullish(),modelId:ea,name:u()}),oy=W([S("error"),S("warning"),S("information"),S("hint")]),ay=p({_meta:k(u(),_()).nullish()}),cy=p({_meta:k(u(),_()).nullish()}),ly=p({_meta:k(u(),_()).nullish()}),uy=p({_meta:k(u(),_()).nullish()}),hy=p({_meta:k(u(),_()).nullish()}),dy=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),py=p({diff:u(),uri:u()}),fy=p({endLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),startLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),text:u()}),gy=p({_meta:k(u(),_()).nullish()}),my=p({_meta:k(u(),_()).nullish()}),vy=p({languageId:u(),text:u(),uri:u()}),_y=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),yy=W([S("rejected"),S("ignored"),S("replaced"),S("cancelled")]),ky=p({excerpts:R(fy),uri:u()}),wy=p({_meta:k(u(),_()).nullish()}),by=p({_meta:k(u(),_()).nullish()}),Sy=p({name:u(),owner:u(),remoteUrl:u()}),xy=p({_meta:k(u(),_()).nullish()}),Ey=p({_meta:k(u(),_()).nullish(),jump:gy.nullish(),rename:by.nullish(),searchAndReplace:xy.nullish()}),Ay=p({id:u(),isRegex:_e().nullish(),replace:u(),search:u(),uri:u()}),Ty=W([S("automatic"),S("diagnostic"),S("manual")]),Iy=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),Cy=p({_meta:k(u(),_()).nullish(),diagnostics:ay.nullish(),editHistory:dy.nullish(),openFiles:my.nullish(),recentFiles:_y.nullish(),relatedSnippets:wy.nullish(),userActions:Iy.nullish()}),zy=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci)}),$y=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),Pu=u(),Ry=W([S("allow_once"),S("allow_always"),S("reject_once"),S("reject_always")]),Py=p({_meta:k(u(),_()).nullish(),kind:Ry,name:u(),optionId:Pu}),Dy=W([S("high"),S("medium"),S("low")]),Ly=W([S("pending"),S("in_progress"),S("completed")]),My=p({_meta:k(u(),_()).nullish(),content:u(),priority:Dy,status:Ly}),Oy=p({_meta:k(u(),_()).nullish(),entries:R(My)}),$t=p({character:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"})}),Ny=p({id:u(),position:$t,uri:u()}),Wy=p({id:u(),newName:u(),position:$t,uri:u()}),Fy=p({action:u(),position:$t,timestampMs:N(),uri:u()}),Du=W([S("utf-16"),S("utf-32"),S("utf-8")]),Uy=p({_meta:k(u(),_()).nullish(),auth:k_.optional().default({terminal:!1}),elicitation:H_.nullish(),fs:G_.optional().default({readTextFile:!1,writeTextFile:!1}),nes:Ey.nullish(),positionEncodings:R(Du).optional(),terminal:_e().optional().default(!1)}),Zy=p({_meta:k(u(),_()).nullish(),audio:_e().optional().default(!1),embeddedContext:_e().optional().default(!1),image:_e().optional().default(!1)}),Lu=N().int().gte(0).lte(65535),jy=p({_meta:k(u(),_()).nullish(),clientCapabilities:Uy.optional().default({auth:{terminal:!1},fs:{readTextFile:!1,writeTextFile:!1},terminal:!1}),clientInfo:Ru.nullish(),protocolVersion:Lu}),Vn=p({end:$t,start:$t}),Hy=p({message:u(),range:Vn,severity:oy,uri:u()}),By=p({languageId:u(),lastFocusedMs:N().nullish(),uri:u(),visibleRange:Vn.nullish()}),Vy=p({_meta:k(u(),_()).nullish(),diagnostics:R(Hy).nullish(),editHistory:R(py).nullish(),openFiles:R(By).nullish(),recentFiles:R(vy).nullish(),relatedSnippets:R(ky).nullish(),userActions:R(Fy).nullish()}),Gy=p({newText:u(),range:Vn}),qy=p({cursorPosition:$t.nullish(),edits:R(Gy),id:u(),uri:u()}),Ky=W([qy.and(p({kind:S("edit")})),Ny.and(p({kind:S("jump")})),Wy.and(p({kind:S("rename")})),Ay.and(p({kind:S("searchAndReplace")}))]),Yy=p({_meta:k(u(),_()).nullish(),content:u()}),Xy=p({_meta:k(u(),_()).nullish()}),sn=W([N(),u()]).nullable();p({_meta:k(u(),_()).nullish(),requestId:sn});const Jy=eu(["assistant","user"]),Xs=p({_meta:k(u(),_()).nullish(),audience:R(Jy).nullish(),lastModified:u().nullish(),priority:N().nullish()}),Qy=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),data:u(),mimeType:u()}),ek=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),data:u(),mimeType:u(),uri:u().nullish()}),tk=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),description:u().nullish(),mimeType:u().nullish(),name:u(),size:N().nullish(),title:u().nullish(),uri:u()}),nk=p({_meta:k(u(),_()).nullish(),optionId:Pu}),sk=W([p({outcome:S("cancelled")}),nk.and(p({outcome:S("selected")}))]),rk=p({_meta:k(u(),_()).nullish(),outcome:sk}),ik=p({_meta:k(u(),_()).nullish()}),ok=p({_meta:k(u(),_()).nullish()}),ak=p({currentValue:_e()}),ck=u(),Mu=u(),lk=W([S("mode"),S("model"),S("thought_level"),u()]),ta=u(),Ou=p({_meta:k(u(),_()).nullish(),description:u().nullish(),name:u(),value:ta}),uk=p({_meta:k(u(),_()).nullish(),group:ck,name:u(),options:R(Ou)}),hk=W([R(Ou),R(uk)]),dk=p({currentValue:ta,options:hk}),Gn=ri(W([dk.and(p({type:S("select")})),ak.and(p({type:S("boolean")}))]),p({_meta:k(u(),_()).nullish(),category:lk.nullish(),description:u().nullish(),id:Mu,name:u()})),pk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn)}),fk=p({_meta:k(u(),_()).nullish()}),V=u(),gk=p({_meta:k(u(),_()).nullish(),id:u(),sessionId:V}),mk=p({_meta:k(u(),_()).nullish(),sessionId:V}),vk=p({_meta:k(u(),_()).nullish(),sessionId:V}),_k=p({_meta:k(u(),_()).nullish(),sessionId:V}),Nu=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),command:u(),cwd:u().nullish(),env:R(Au).optional(),outputByteLimit:N().nullish(),sessionId:V}),yk=p({_meta:k(u(),_()).nullish(),sessionId:V,uri:u()}),kk=p({_meta:k(u(),_()).nullish(),position:$t,sessionId:V,uri:u(),version:N(),visibleRange:Vn}),wk=p({_meta:k(u(),_()).nullish(),languageId:u(),sessionId:V,text:u(),uri:u(),version:N()}),bk=p({_meta:k(u(),_()).nullish(),sessionId:V,uri:u()}),Sk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci).optional(),sessionId:V}),Wu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),xk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci),sessionId:V}),Fu=p({_meta:k(u(),_()).nullish(),limit:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u(),sessionId:V}),Ek=p({_meta:k(u(),_()).nullish(),id:u(),reason:yy.nullish(),sessionId:V}),Uu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Ak=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci).optional(),sessionId:V}),Tk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),sessionId:V,title:u().nullish(),updatedAt:u().nullish()}),Ik=p({_meta:k(u(),_()).nullish(),nextCursor:u().nullish(),sessions:R(Tk)}),Ck=p({_meta:k(u(),_()).nullish(),title:u().nullish(),updatedAt:u().nullish()}),zk=p({_meta:k(u(),_()).nullish()}),li=u(),$k=p({_meta:k(u(),_()).nullish(),currentModeId:li}),Rk=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:li,name:u()}),ui=p({_meta:k(u(),_()).nullish(),availableModes:R(Rk),currentModeId:li}),hi=p({_meta:k(u(),_()).nullish(),availableModels:R(iy),currentModelId:ea}),Pk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish(),sessionId:V}),Dk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish()}),Lk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish(),sessionId:V}),Mk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish()}),Ok=p({_meta:k(u(),_()).nullish()}),Nk=p({_meta:k(u(),_()).nullish(),additionalDirectories:ik.nullish(),close:ok.nullish(),fork:fk.nullish(),list:zk.nullish(),resume:Ok.nullish()}),Wk=ri(W([p({type:S("boolean"),value:_e()}),p({value:ta})]),p({_meta:k(u(),_()).nullish(),configId:Mu,sessionId:V})),Fk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn)}),Uk=p({_meta:k(u(),_()).nullish(),modeId:li,sessionId:V}),Zk=p({_meta:k(u(),_()).nullish()}),jk=p({_meta:k(u(),_()).nullish(),modelId:ea,sessionId:V}),Hk=p({_meta:k(u(),_()).nullish()}),Bk=p({_meta:k(u(),_()).nullish(),sessionId:V}),Vk=W([S("end_turn"),S("max_tokens"),S("max_turn_requests"),S("refusal"),S("cancelled")]),Gk=W([S("email"),S("uri"),S("date"),S("date-time")]),qk=p({default:u().nullish(),description:u().nullish(),enum:R(u()).nullish(),format:Gk.nullish(),maxLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),minLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),oneOf:R(Eu).nullish(),pattern:u().nullish(),title:u().nullish()}),Kk=p({_meta:k(u(),_()).nullish(),context:Vy.nullish(),position:$t,selection:Vn.nullish(),sessionId:V,triggerKind:Ty,uri:u(),version:N()}),Yk=p({_meta:k(u(),_()).nullish(),suggestions:R(Ky)}),Xk=p({_meta:k(u(),_()).nullish(),terminalId:u()}),Jk=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Zu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Qk=p({_meta:k(u(),_()).nullish(),exitStatus:Jk.nullish(),output:u(),truncated:_e()}),ew=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),text:u()}),tw=p({range:Vn.nullish(),text:u()}),nw=p({_meta:k(u(),_()).nullish(),contentChanges:R(tw),sessionId:V,uri:u(),version:N()});p({method:u(),params:W([mk,wk,nw,yk,bk,kk,gk,Ek,Iu]).nullish()});const sw=W([S("full"),S("incremental")]),rw=p({_meta:k(u(),_()).nullish(),syncKind:sw}),iw=p({_meta:k(u(),_()).nullish(),didChange:rw.nullish(),didClose:cy.nullish(),didFocus:ly.nullish(),didOpen:uy.nullish(),didSave:hy.nullish()}),ow=p({_meta:k(u(),_()).nullish(),document:iw.nullish()}),aw=p({_meta:k(u(),_()).nullish(),context:Cy.nullish(),events:ow.nullish()}),cw=p({_meta:k(u(),_()).nullish(),auth:J_.optional().default({}),loadSession:_e().optional().default(!1),mcpCapabilities:ty.optional().default({http:!1,sse:!1}),nes:aw.nullish(),positionEncoding:Du.nullish(),promptCapabilities:Zy.optional().default({audio:!1,embeddedContext:!1,image:!1}),sessionCapabilities:Nk.optional().default({})}),lw=p({_meta:k(u(),_()).nullish(),agentCapabilities:cw.optional().default({auth:{},loadSession:!1,mcpCapabilities:{http:!1,sse:!1},promptCapabilities:{audio:!1,embeddedContext:!1,image:!1},sessionCapabilities:{}}),agentInfo:Ru.nullish(),authMethods:R(E_).optional().default([]),protocolVersion:Lu}),uw=p({_meta:k(u(),_()).nullish(),mimeType:u().nullish(),text:u(),uri:u()}),hw=W([uw,I_]),dw=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),resource:hw}),na=W([ew.and(p({type:S("text")})),ek.and(p({type:S("image")})),Qy.and(p({type:S("audio")})),tk.and(p({type:S("resource_link")})),dw.and(p({type:S("resource")}))]),pw=p({_meta:k(u(),_()).nullish(),content:na}),Oi=p({_meta:k(u(),_()).nullish(),content:na,messageId:u().nullish()}),fw=p({_meta:k(u(),_()).nullish(),messageId:u().nullish(),prompt:R(na),sessionId:V}),gw=p({anyOf:R(Eu)}),ju=W([pw.and(p({type:S("content")})),D_.and(p({type:S("diff")})),Xk.and(p({type:S("terminal")}))]),Hu=u(),Bu=p({_meta:k(u(),_()).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u()}),Vu=W([S("pending"),S("in_progress"),S("completed"),S("failed")]),Gu=W([S("read"),S("edit"),S("delete"),S("move"),S("search"),S("execute"),S("think"),S("fetch"),S("switch_mode"),S("other")]),mw=p({_meta:k(u(),_()).nullish(),content:R(ju).optional(),kind:Gu.optional(),locations:R(Bu).optional(),rawInput:_().optional(),rawOutput:_().optional(),status:Vu.optional(),title:u(),toolCallId:Hu}),qu=p({_meta:k(u(),_()).nullish(),content:R(ju).nullish(),kind:Gu.nullish(),locations:R(Bu).nullish(),rawInput:_().optional(),rawOutput:_().optional(),status:Vu.nullish(),title:u().nullish(),toolCallId:Hu}),Ku=p({_meta:k(u(),_()).nullish(),options:R(Py),sessionId:V,toolCall:qu}),vw=p({_meta:k(u(),_()).nullish(),hint:u()}),_w=vw,yw=p({_meta:k(u(),_()).nullish(),description:u(),input:_w.nullish(),name:u()}),kw=p({_meta:k(u(),_()).nullish(),availableCommands:R(yw)}),ww=p({enum:R(u()),type:Z_}),bw=W([ww,gw]),Sw=p({default:R(u()).nullish(),description:u().nullish(),items:bw,maxItems:N().nullish(),minItems:N().nullish(),title:u().nullish()}),xw=W([qk.and(p({type:S("string")})),$y.and(p({type:S("number")})),q_.and(p({type:S("integer")})),C_.and(p({type:S("boolean")})),Sw.and(p({type:S("array")}))]),Ew=p({description:u().nullish(),properties:k(u(),xw).optional().default({}),required:R(u()).nullish(),title:u().nullish(),type:U_.optional().default("object")}),Aw=p({requestedSchema:Ew}),Tw=ri(W([Aw.and(p({mode:S("form")})),B_.and(p({mode:S("url")}))]),p({_meta:k(u(),_()).nullish(),message:u(),sessionId:V})),Iw=p({cachedReadTokens:N().nullish(),cachedWriteTokens:N().nullish(),inputTokens:N(),outputTokens:N(),thoughtTokens:N().nullish(),totalTokens:N()}),Cw=p({_meta:k(u(),_()).nullish(),stopReason:Vk,usage:Iw.nullish(),userMessageId:u().nullish()});W([p({id:sn,result:W([lw,T_,ey,Lk,Dk,Ik,Pk,Mk,$_,Zk,Fk,Cw,Hk,Bk,Yk,z_,zu])}),p({error:Tu,id:sn})]);const zw=p({_meta:k(u(),_()).nullish(),cost:R_.nullish(),size:N(),used:N()}),$w=W([Oi.and(p({sessionUpdate:S("user_message_chunk")})),Oi.and(p({sessionUpdate:S("agent_message_chunk")})),Oi.and(p({sessionUpdate:S("agent_thought_chunk")})),mw.and(p({sessionUpdate:S("tool_call")})),qu.and(p({sessionUpdate:S("tool_call_update")})),Oy.and(p({sessionUpdate:S("plan")})),kw.and(p({sessionUpdate:S("available_commands_update")})),$k.and(p({sessionUpdate:S("current_mode_update")})),pk.and(p({sessionUpdate:S("config_option_update")})),Ck.and(p({sessionUpdate:S("session_info_update")})),zw.and(p({sessionUpdate:S("usage_update")}))]),Yu=p({_meta:k(u(),_()).nullish(),sessionId:V,update:$w});p({method:u(),params:W([Yu,W_,Iu]).nullish()});const Xu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Rw=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Pw=p({name:u(),uri:u()}),Dw=p({_meta:k(u(),_()).nullish(),repository:Sy.nullish(),workspaceFolders:R(Pw).nullish(),workspaceUri:u().nullish()});p({id:sn,method:u(),params:W([jy,A_,Q_,zy,xk,Y_,Sk,Ak,_k,Uk,Wk,fw,jk,Dw,Kk,vk,Cu]).nullish()});const Ju=p({_meta:k(u(),_()).nullish(),content:u(),path:u(),sessionId:V});p({id:sn,method:u(),params:W([Ju,Fu,Ku,Nu,Zu,Uu,Xu,Wu,Tw,Cu]).nullish()});const Lw=p({_meta:k(u(),_()).nullish()});W([p({id:sn,result:W([Lw,Yy,rk,P_,Qk,Xy,Rw,K_,F_,zu])}),p({error:Tu,id:sn})]);var H;class Mw{constructor(t,n){I(this,H);const s=t(this),r=async(o,a)=>{var c,l,h,f,w,v,E;switch(o){case ct.fs_write_text_file:{const x=Ju.parse(a);return(c=s.writeTextFile)==null?void 0:c.call(s,x)}case ct.fs_read_text_file:{const x=Fu.parse(a);return(l=s.readTextFile)==null?void 0:l.call(s,x)}case ct.session_request_permission:{const x=Ku.parse(a);return s.requestPermission(x)}case ct.terminal_create:{const x=Nu.parse(a);return(h=s.createTerminal)==null?void 0:h.call(s,x)}case ct.terminal_output:{const x=Zu.parse(a);return(f=s.terminalOutput)==null?void 0:f.call(s,x)}case ct.terminal_release:{const x=Uu.parse(a);return await((w=s.releaseTerminal)==null?void 0:w.call(s,x))??{}}case ct.terminal_wait_for_exit:{const x=Xu.parse(a);return(v=s.waitForTerminalExit)==null?void 0:v.call(s,x)}case ct.terminal_kill:{const x=Wu.parse(a);return await((E=s.killTerminal)==null?void 0:E.call(s,x))??{}}default:if(s.extMethod)return s.extMethod(o,a);throw ge.methodNotFound(o)}},i=async(o,a)=>{switch(o){case ct.session_update:{const c=Yu.parse(a);return s.sessionUpdate(c)}default:if(s.extNotification)return s.extNotification(o,a);throw ge.methodNotFound(o)}};C(this,H,new Ow(r,i,n))}async initialize(t){return await d(this,H).sendRequest(te.initialize,t)}async newSession(t){return await d(this,H).sendRequest(te.session_new,t)}async loadSession(t){return await d(this,H).sendRequest(te.session_load,t)??{}}async unstable_forkSession(t){return await d(this,H).sendRequest(te.session_fork,t)}async listSessions(t){return await d(this,H).sendRequest(te.session_list,t)}async unstable_resumeSession(t){return await d(this,H).sendRequest(te.session_resume,t)}async unstable_closeSession(t){return await d(this,H).sendRequest(te.session_close,t)}async setSessionMode(t){return await d(this,H).sendRequest(te.session_set_mode,t)??{}}async unstable_setSessionModel(t){return await d(this,H).sendRequest(te.session_set_model,t)??{}}async setSessionConfigOption(t){return await d(this,H).sendRequest(te.session_set_config_option,t)}async authenticate(t){return await d(this,H).sendRequest(te.authenticate,t)??{}}async unstable_logout(t){return await d(this,H).sendRequest(te.logout,t)??{}}async prompt(t){return await d(this,H).sendRequest(te.session_prompt,t)}async cancel(t){return await d(this,H).sendNotification(te.session_cancel,t)}async unstable_startNes(t){return await d(this,H).sendRequest(te.nes_start,t)}async unstable_suggestNes(t){return await d(this,H).sendRequest(te.nes_suggest,t)}async unstable_closeNes(t){return await d(this,H).sendRequest(te.nes_close,t)??{}}async unstable_didOpenDocument(t){return await d(this,H).sendNotification(te.document_did_open,t)}async unstable_didChangeDocument(t){return await d(this,H).sendNotification(te.document_did_change,t)}async unstable_didCloseDocument(t){return await d(this,H).sendNotification(te.document_did_close,t)}async unstable_didSaveDocument(t){return await d(this,H).sendNotification(te.document_did_save,t)}async unstable_didFocusDocument(t){return await d(this,H).sendNotification(te.document_did_focus,t)}async unstable_acceptNes(t){return await d(this,H).sendNotification(te.nes_accept,t)}async unstable_rejectNes(t){return await d(this,H).sendNotification(te.nes_reject,t)}async extMethod(t,n){return await d(this,H).sendRequest(t,n)}async extNotification(t,n){return await d(this,H).sendNotification(t,n)}get signal(){return d(this,H).signal}get closed(){return d(this,H).closed}}H=new WeakMap;var bt,Vr,zs,$s,$n,Rn,tt,Rs,re,Qu,po,eh,th,nh,sh,fo,ds;class Ow{constructor(t,n,s){I(this,re);I(this,bt,new Map);I(this,Vr,0);I(this,zs);I(this,$s);I(this,$n);I(this,Rn,Promise.resolve());I(this,tt,new AbortController);I(this,Rs);C(this,zs,t),C(this,$s,n),C(this,$n,s),C(this,Rs,new Promise(r=>{d(this,tt).signal.addEventListener("abort",()=>r())})),y(this,re,Qu).call(this)}get signal(){return d(this,tt).signal}get closed(){return d(this,Rs)}async sendRequest(t,n){y(this,re,fo).call(this);const s=Xa(this,Vr)._++,r=new Promise((i,o)=>{d(this,bt).set(s,{resolve:i,reject:o})});return await y(this,re,ds).call(this,{jsonrpc:"2.0",id:s,method:t,params:n}),r}async sendNotification(t,n){y(this,re,fo).call(this),await y(this,re,ds).call(this,{jsonrpc:"2.0",method:t,params:n})}}bt=new WeakMap,Vr=new WeakMap,zs=new WeakMap,$s=new WeakMap,$n=new WeakMap,Rn=new WeakMap,tt=new WeakMap,Rs=new WeakMap,re=new WeakSet,Qu=async function(){let t;try{const n=d(this,$n).readable.getReader();try{for(;!d(this,tt).signal.aborted;){const{value:s,done:r}=await n.read();if(r)break;if(s)try{y(this,re,eh).call(this,s)}catch(i){console.error("Unexpected error during message processing:",s,i),"id"in s&&s.id!==void 0&&y(this,re,ds).call(this,{jsonrpc:"2.0",id:s.id,error:{code:-32700,message:"Parse error"}})}}}finally{n.releaseLock()}}catch(n){t=n}finally{y(this,re,po).call(this,t)}},po=function(t){if(d(this,tt).signal.aborted)return;const n=t??new Error("ACP connection closed");for(const s of d(this,bt).values())s.reject(n);d(this,bt).clear(),d(this,tt).abort(n)},eh=async function(t){if("method"in t&&"id"in t){const n=await y(this,re,th).call(this,t.method,t.params);"error"in n&&console.error("Error handling request",t,n.error),await y(this,re,ds).call(this,{jsonrpc:"2.0",id:t.id,...n})}else if("method"in t){const n=await y(this,re,nh).call(this,t.method,t.params);"error"in n&&console.error("Error handling notification",t,n.error)}else"id"in t?y(this,re,sh).call(this,t):console.error("Invalid message",{message:t})},th=async function(t,n){try{return{result:await d(this,zs).call(this,t,n)??null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof vc)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},nh=async function(t,n){try{return await d(this,$s).call(this,t,n),{result:null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof vc)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},sh=function(t){const n=d(this,bt).get(t.id);if(n){if("result"in t)n.resolve(t.result);else if("error"in t){const{code:s,message:r,data:i}=t.error;n.reject(new ge(s,r,i))}d(this,bt).delete(t.id)}else console.error("Got response to unknown request",t.id)},fo=function(){if(d(this,tt).signal.aborted)throw d(this,tt).signal.reason??new Error("ACP connection closed")},ds=async function(t){return C(this,Rn,d(this,Rn).then(async()=>{const n=d(this,$n).writable.getWriter();try{await n.write(t)}finally{n.releaseLock()}}).catch(n=>{y(this,re,po).call(this,n)})),d(this,Rn)};class ge extends Error{constructor(n,s,r){super(s);m(this,"code");m(this,"data");this.code=n,this.name="RequestError",this.data=r}static parseError(n,s){return new ge(-32700,`Parse error${s?`: ${s}`:""}`,n)}static invalidRequest(n,s){return new ge(-32600,`Invalid request${s?`: ${s}`:""}`,n)}static methodNotFound(n){return new ge(-32601,`"Method not found": ${n}`,{method:n})}static invalidParams(n,s){return new ge(-32602,`Invalid params${s?`: ${s}`:""}`,n)}static internalError(n,s){return new ge(-32603,`Internal error${s?`: ${s}`:""}`,n)}static authRequired(n,s){return new ge(-32e3,`Authentication required${s?`: ${s}`:""}`,n)}static resourceNotFound(n){return new ge(-32002,`Resource not found${n?`: ${n}`:""}`,n&&{uri:n})}toResult(){return{error:{code:this.code,message:this.message,data:this.data}}}toErrorResponse(){return{code:this.code,message:this.message,data:this.data}}}const Nw=/^Sender \(untrusted metadata\):\n```json\n[\s\S]*?\n```\n\n?/,Ww=/^\[[^\n]*Working directory:[^\n]*\]\n\n?/,Fw=/\[Television workspace context\][\s\S]*?\[\/Television workspace context\]\n*/,Uw=/\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+|audio_as_voice)\s*\]\]\s*/gi,Zw="single_session",jw={name:"television-acp-client",version:"0.0.0"},rh="agent:main:television";var Q,ut,Pn,ht,Gt,qt,St,Dn,nt,Be,xt,Kt,dt,Et,Ps,pt,Ve,Gr,ft,Yt,T,ih,oh,go,ah,ch,lh,uh,hh,dh,ph,Ft,kn,wn,Me,fh,bn,mo,vo,xr,gh,Ds,Ls,_o,Sn,mh,vh;class Hw extends ln{constructor(n){super();I(this,T);I(this,Q,Bw());I(this,ut,null);I(this,Pn,null);I(this,ht,null);I(this,Gt,null);I(this,qt,null);I(this,St,null);I(this,Dn,1);I(this,nt,null);I(this,Be,null);I(this,xt,!1);I(this,Kt,!1);I(this,dt,null);I(this,Et,new Set);I(this,Ps);I(this,pt);I(this,Ve);I(this,Gr,n=>{y(this,T,oh).call(this,n)});I(this,ft,null);I(this,Yt,!1);I(this,Ds,()=>{y(this,T,Sn).call(this,"ACP bridge websocket closed")});I(this,Ls,()=>{y(this,T,Sn).call(this,"ACP bridge websocket error")});C(this,pt,n),C(this,Ve,n.sessionMode??Zw),C(this,Ps,n.createSocket??(s=>new WebSocket(s)))}getState(){return d(this,Q)}async connect(){if(d(this,Yt))throw new Error("ACPClientService has been disposed");if(d(this,Q).lifecycle.status!=="ready"){y(this,T,Me).call(this,{lifecycle:{status:"connecting"}}),d(this,Pn)??C(this,Pn,y(this,T,ih).call(this));try{await d(this,Pn),await y(this,T,go).call(this)}catch(n){throw y(this,T,Sn).call(this,mr(n)),n}}}async dispose(){d(this,Yt)||(C(this,Yt,!0),y(this,T,_o).call(this),y(this,T,Me).call(this,{lifecycle:{status:"disposed"},run:{status:"idle",stopReason:null,canCancel:!1,error:null}}))}async sendMessage(n){if(await this.connect(),d(this,Q).lifecycle.status!=="ready"||d(this,Q).run.status==="running"||d(this,Q).run.status==="cancelling")throw new Error("ACPClientService is not ready to send a new message");const s=n.text.trim();if(!s)throw new Error("Cannot send an empty message");y(this,T,kn).call(this,{id:y(this,T,bn).call(this,"user"),kind:"user",text:s,status:"final"}),y(this,T,Me).call(this,{run:{status:"running",stopReason:null,canCancel:!0,error:null}});try{const r=await y(this,T,xr).call(this).prompt({sessionId:y(this,T,vo).call(this),prompt:[{type:"text",text:y(this,T,fh).call(this,s)}]});y(this,T,Ft).call(this,r.stopReason==="cancelled"?"cancelled":"final"),y(this,T,Me).call(this,{run:{status:r.stopReason==="cancelled"?"cancelled":"completed",stopReason:r.stopReason,canCancel:!1,error:null}})}catch(r){throw y(this,T,vh).call(this)||(y(this,T,Ft).call(this,"error"),y(this,T,Me).call(this,{run:{status:"error",stopReason:null,canCancel:!1,error:mr(r)}})),r}}async cancel(){if(await this.connect(),!d(this,Q).run.canCancel||d(this,Q).run.status!=="running")throw new Error("No active cancellable run");y(this,T,Me).call(this,{run:{...d(this,Q).run,status:"cancelling"}}),await y(this,T,xr).call(this).cancel({sessionId:y(this,T,vo).call(this)})}setWorkspaceContext(n){var i,o,a;const s={workspaceID:n.workspaceID,workspaceName:n.workspaceName};if(((i=d(this,Be))==null?void 0:i.workspaceID)===s.workspaceID&&((o=d(this,Be))==null?void 0:o.workspaceName)===s.workspaceName)return;const r=((a=d(this,Be))==null?void 0:a.workspaceID)??null;if(C(this,Be,s),d(this,Ve)==="single_session"){(!d(this,St)||r!==s.workspaceID)&&C(this,xt,!0);return}d(this,St)!==Rc(d(this,Ve),s.workspaceID,d(this,pt).clientGUID??"default-client")&&(C(this,ht,null),C(this,Gt,null),d(this,ut)&&d(this,Q).run.status==="idle"&&y(this,T,go).call(this).catch(c=>{y(this,T,Sn).call(this,mr(c))}))}}Q=new WeakMap,ut=new WeakMap,Pn=new WeakMap,ht=new WeakMap,Gt=new WeakMap,qt=new WeakMap,St=new WeakMap,Dn=new WeakMap,nt=new WeakMap,Be=new WeakMap,xt=new WeakMap,Kt=new WeakMap,dt=new WeakMap,Et=new WeakMap,Ps=new WeakMap,pt=new WeakMap,Ve=new WeakMap,Gr=new WeakMap,ft=new WeakMap,Yt=new WeakMap,T=new WeakSet,ih=async function(){try{y(this,T,Me).call(this,{lifecycle:{status:"connecting"}});const{stream:n,socket:s}=await qw({serverURL:d(this,pt).serverURL,token:d(this,pt).token,createSocket:d(this,Ps),onDisconnect:d(this,Gr)});C(this,ft,s),s.addEventListener("close",d(this,Ds)),s.addEventListener("error",d(this,Ls)),C(this,ut,new Mw(r=>({connection:r,sessionUpdate:async i=>{await y(this,T,ch).call(this,i)},requestPermission:async i=>y(this,T,lh).call(this,i)}),n)),await d(this,ut).initialize({protocolVersion:y_,clientCapabilities:{},clientInfo:jw})}catch(n){throw n}},oh=function(n){y(this,T,Sn).call(this,mr(n))},go=async function(){const n=y(this,T,gh).call(this);if(d(this,ht)&&d(this,Gt)===n){await d(this,ht);return}C(this,Gt,n),C(this,ht,y(this,T,ah).call(this,n)),await d(this,ht)},ah=async function(n){const s=y(this,T,xr).call(this);y(this,T,mh).call(this);let r,i=!1;try{C(this,Kt,!0),C(this,dt,null),await s.loadSession({sessionId:n,cwd:"/",mcpServers:[],_meta:{sessionKey:n}}),r=n,i=d(this,Q).messageOrder.length>0}catch{r=(await s.newSession({cwd:"/",mcpServers:[],_meta:{sessionKey:n}})).sessionId,i=!1}finally{C(this,Kt,!1),C(this,dt,null),y(this,T,Ft).call(this,"final")}await s.setSessionConfigOption({sessionId:r,configId:"verbose_level",value:"full"}),C(this,qt,r),C(this,St,n),i?(d(this,Et).add(n),d(this,Ve)==="single_session"&&C(this,xt,!1)):(d(this,Et).delete(n),C(this,xt,d(this,Ve)==="single_session")),y(this,T,Me).call(this,{lifecycle:{status:"ready"}})},ch=async function(n){const s=n.update;switch(s.sessionUpdate){case"user_message_chunk":s.content.type==="text"&&y(this,T,ph).call(this,s.content.text);return;case"agent_message_chunk":s.content.type==="text"&&y(this,T,uh).call(this,s.content.text);return;case"tool_call":y(this,T,hh).call(this,s);return;case"tool_call_update":y(this,T,dh).call(this,s);return;case"agent_thought_chunk":return;default:return}},lh=async function(n){return{outcome:{outcome:"cancelled"}}},uh=function(n){C(this,dt,null);const s=Vw(n);if(!s)return;if(!d(this,nt)){const i={id:y(this,T,bn).call(this,"assistant"),kind:"assistant",text:s,status:"streaming"};C(this,nt,i.id),y(this,T,kn).call(this,i);return}const r=d(this,Q).messagesById[d(this,nt)];if(!r||r.kind!=="assistant")throw new Error("Open assistant message invariant violated");y(this,T,wn).call(this,{...r,text:`${r.text}${s}`,status:"streaming"})},hh=function(n){y(this,T,Ft).call(this,"final");const s=y(this,T,mo).call(this,n.toolCallId),r={id:(s==null?void 0:s.id)??y(this,T,bn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:n.title,toolKind:n.kind??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:(s==null?void 0:s.text)??"",locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,wn).call(this,r);return}y(this,T,kn).call(this,r)},dh=function(n){const s=y(this,T,mo).call(this,n.toolCallId),r=(s==null?void 0:s.text)??"",i=Gw(n.content),o=i?`${r}${i}`:r,a={id:(s==null?void 0:s.id)??y(this,T,bn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:(s==null?void 0:s.title)??n.toolCallId,toolKind:(s==null?void 0:s.toolKind)??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:o,locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,wn).call(this,a);return}y(this,T,kn).call(this,a)},ph=function(n){if(y(this,T,Ft).call(this,"final"),!n)return;const s=d(this,Kt)?d(this,dt):null;if(!s){const i=Pc(n);if(!i)return;const o={id:y(this,T,bn).call(this,"user"),kind:"user",text:i,status:"final"};y(this,T,kn).call(this,o),d(this,Kt)&&C(this,dt,o.id);return}const r=d(this,Q).messagesById[s];if(!r||r.kind!=="user")throw new Error("Replay user message invariant violated");y(this,T,wn).call(this,{...r,text:Pc(`${r.text}${n}`)})},Ft=function(n){if(!d(this,nt))return;const s=d(this,Q).messagesById[d(this,nt)];(s==null?void 0:s.kind)==="assistant"&&y(this,T,wn).call(this,{...s,status:n}),C(this,nt,null)},kn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n},messageOrder:[...d(this,Q).messageOrder,n.id]})},wn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n}})},Me=function(n){const s={...d(this,Q),...n};C(this,Q,{...s,sendDisabled:s.lifecycle.status!=="ready"||s.run.status==="running"||s.run.status==="cancelling",cancelDisabled:!(s.run.status==="running"||s.run.status==="cancelling")||!s.run.canCancel}),this.dispatchEvent(new B("change"))},fh=function(n){const s=d(this,St);return!d(this,Be)||!s||!(d(this,Ve)==="single_session"?d(this,xt)||!d(this,Et).has(s):!d(this,Et).has(s))?n:(C(this,xt,!1),d(this,Et).add(s),["[Television workspace context]","This chat session is coming from a Television client in the workspace below.",`workspace_id: ${d(this,Be).workspaceID}`,`workspace_name: ${d(this,Be).workspaceName??""}`,"When the user asks to inspect or change Television state with the tv CLI, use this workspace ID with the --workspace argument.","[/Television workspace context]","",n].join(`
39
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const h of e.seen.entries()){const f=h[1];if(t===h[0]){i(h);continue}if(e.external){const v=(c=e.external.registry.get(h[0]))==null?void 0:c.id;if(t!==h[0]&&v){i(h);continue}}if((l=e.metadataRegistry.get(h[0]))==null?void 0:l.id){i(h);continue}if(f.cycle){i(h);continue}if(f.count>1&&e.reused==="ref"){i(h);continue}}}function Vl(e,t){var o,a,c;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=l=>{const h=e.seen.get(l);if(h.ref===null)return;const f=h.def??h.schema,w={...f},v=h.ref;if(h.ref=null,v){s(v);const x=e.seen.get(v),z=x.schema;if(z.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(z)):Object.assign(f,z),Object.assign(f,w),l._zod.parent===v)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in w||delete f[Z];if(z.$ref&&x.def)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in x.def&&JSON.stringify(f[Z])===JSON.stringify(x.def[Z])&&delete f[Z]}const E=l._zod.parent;if(E&&E!==v){s(E);const x=e.seen.get(E);if(x!=null&&x.schema.$ref&&(f.$ref=x.schema.$ref,x.def))for(const z in f)z==="$ref"||z==="allOf"||z in x.def&&JSON.stringify(f[z])===JSON.stringify(x.def[z])&&delete f[z]}e.override({zodSchema:l,jsonSchema:f,path:h.path??[]})};for(const l of[...e.seen.entries()].reverse())s(l[0]);const r={};if(e.target==="draft-2020-12"?r.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?r.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?r.$schema="http://json-schema.org/draft-04/schema#":e.target,(o=e.external)!=null&&o.uri){const l=(a=e.external.registry.get(t))==null?void 0:a.id;if(!l)throw new Error("Schema is missing an `id` property");r.$id=e.external.uri(l)}Object.assign(r,n.def??n.schema);const i=((c=e.external)==null?void 0:c.defs)??{};for(const l of e.seen.entries()){const h=l[1];h.def&&h.defId&&(i[h.defId]=h.def)}e.external||Object.keys(i).length>0&&(e.target==="draft-2020-12"?r.$defs=i:r.definitions=i);try{const l=JSON.parse(JSON.stringify(r));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:Mr(t,"input",e.processors),output:Mr(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function Ce(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const s=e._zod.def;if(s.type==="transform")return!0;if(s.type==="array")return Ce(s.element,n);if(s.type==="set")return Ce(s.valueType,n);if(s.type==="lazy")return Ce(s.getter(),n);if(s.type==="promise"||s.type==="optional"||s.type==="nonoptional"||s.type==="nullable"||s.type==="readonly"||s.type==="default"||s.type==="prefault")return Ce(s.innerType,n);if(s.type==="intersection")return Ce(s.left,n)||Ce(s.right,n);if(s.type==="record"||s.type==="map")return Ce(s.keyType,n)||Ce(s.valueType,n);if(s.type==="pipe")return Ce(s.in,n)||Ce(s.out,n);if(s.type==="object"){for(const r in s.shape)if(Ce(s.shape[r],n))return!0;return!1}if(s.type==="union"){for(const r of s.options)if(Ce(r,n))return!0;return!1}if(s.type==="tuple"){for(const r of s.items)if(Ce(r,n))return!0;return!!(s.rest&&Ce(s.rest,n))}return!1}const Gg=(e,t={})=>n=>{const s=Hl({...n,processors:t});return pe(e,s),Bl(s,e),Vl(s,e)},Mr=(e,t,n={})=>s=>{const{libraryOptions:r,target:i}=s??{},o=Hl({...r??{},target:i,io:t,processors:n});return pe(e,o),Bl(o,e),Vl(o,e)},qg={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Kg=(e,t,n,s)=>{const r=n;r.type="string";const{minimum:i,maximum:o,format:a,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof i=="number"&&(r.minLength=i),typeof o=="number"&&(r.maxLength=o),a&&(r.format=qg[a]??a,r.format===""&&delete r.format,a==="time"&&delete r.format),l&&(r.contentEncoding=l),c&&c.size>0){const h=[...c];h.length===1?r.pattern=h[0].source:h.length>1&&(r.allOf=[...h.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},Yg=(e,t,n,s)=>{const r=n,{minimum:i,maximum:o,format:a,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:h}=e._zod.bag;typeof a=="string"&&a.includes("int")?r.type="integer":r.type="number",typeof h=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.minimum=h,r.exclusiveMinimum=!0):r.exclusiveMinimum=h),typeof i=="number"&&(r.minimum=i,typeof h=="number"&&t.target!=="draft-04"&&(h>=i?delete r.minimum:delete r.exclusiveMinimum)),typeof l=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.maximum=l,r.exclusiveMaximum=!0):r.exclusiveMaximum=l),typeof o=="number"&&(r.maximum=o,typeof l=="number"&&t.target!=="draft-04"&&(l<=o?delete r.maximum:delete r.exclusiveMaximum)),typeof c=="number"&&(r.multipleOf=c)},Xg=(e,t,n,s)=>{n.type="boolean"},Jg=(e,t,n,s)=>{n.not={}},Qg=(e,t,n,s)=>{},em=(e,t,n,s)=>{const r=e._zod.def,i=Sl(r.entries);i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},tm=(e,t,n,s)=>{const r=e._zod.def,i=[];for(const o of r.values)if(o===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},nm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},sm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},rm=(e,t,n,s)=>{const r=n,i=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(r.minItems=o),typeof a=="number"&&(r.maxItems=a),r.type="array",r.items=pe(i.element,t,{...s,path:[...s.path,"items"]})},im=(e,t,n,s)=>{var l;const r=n,i=e._zod.def;r.type="object",r.properties={};const o=i.shape;for(const h in o)r.properties[h]=pe(o[h],t,{...s,path:[...s.path,"properties",h]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(h=>{const f=i.shape[h]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(r.required=Array.from(c)),((l=i.catchall)==null?void 0:l._zod.def.type)==="never"?r.additionalProperties=!1:i.catchall?i.catchall&&(r.additionalProperties=pe(i.catchall,t,{...s,path:[...s.path,"additionalProperties"]})):t.io==="output"&&(r.additionalProperties=!1)},om=(e,t,n,s)=>{const r=e._zod.def,i=r.inclusive===!1,o=r.options.map((a,c)=>pe(a,t,{...s,path:[...s.path,i?"oneOf":"anyOf",c]}));i?n.oneOf=o:n.anyOf=o},am=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.left,t,{...s,path:[...s.path,"allOf",0]}),o=pe(r.right,t,{...s,path:[...s.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,c=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=c},cm=(e,t,n,s)=>{const r=n,i=e._zod.def;r.type="object";const o=i.keyType,a=o._zod.bag,c=a==null?void 0:a.patterns;if(i.mode==="loose"&&c&&c.size>0){const h=pe(i.valueType,t,{...s,path:[...s.path,"patternProperties","*"]});r.patternProperties={};for(const f of c)r.patternProperties[f.source]=h}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(r.propertyNames=pe(i.keyType,t,{...s,path:[...s.path,"propertyNames"]})),r.additionalProperties=pe(i.valueType,t,{...s,path:[...s.path,"additionalProperties"]});const l=o._zod.values;if(l){const h=[...l].filter(f=>typeof f=="string"||typeof f=="number");h.length>0&&(r.required=h)}},lm=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.innerType,t,s),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=r.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},um=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},hm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},dm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(r.defaultValue)))},pm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType;let o;try{o=r.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},fm=(e,t,n,s)=>{const r=e._zod.def,i=t.io==="input"?r.in._zod.def.type==="transform"?r.out:r.in:r.out;pe(i,t,s);const o=t.seen.get(e);o.ref=i},gm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.readOnly=!0},Gl=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},mm=b("ZodISODateTime",(e,t)=>{vf.init(e,t),ae.init(e,t)});function vm(e){return Sg(mm,e)}const _m=b("ZodISODate",(e,t)=>{_f.init(e,t),ae.init(e,t)});function ym(e){return xg(_m,e)}const km=b("ZodISOTime",(e,t)=>{yf.init(e,t),ae.init(e,t)});function wm(e){return Eg(km,e)}const bm=b("ZodISODuration",(e,t)=>{kf.init(e,t),ae.init(e,t)});function Sm(e){return Ag(bm,e)}const ql=(e,t)=>{Tl.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>lp(e,n)},flatten:{value:n=>cp(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Xi,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Xi,2)}},isEmpty:{get(){return e.issues.length===0}}})},vc=b("ZodError",ql),He=b("ZodError",ql,{Parent:Error}),xm=Vo(He),Em=Go(He),Am=ti(He),Tm=ni(He),Im=dp(He),Cm=pp(He),zm=fp(He),$m=gp(He),Rm=mp(He),Pm=vp(He),Dm=_p(He),Lm=yp(He),oe=b("ZodType",(e,t)=>(ie.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Mr(e,"input"),output:Mr(e,"output")}}),e.toJSONSchema=Gg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Pt(t,{checks:[...t.checks??[],...n.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0}),e.with=e.check,e.clone=(n,s)=>Dt(e,n,s),e.brand=()=>e,e.register=(n,s)=>(n.add(e,s),e),e.parse=(n,s)=>xm(e,n,s,{callee:e.parse}),e.safeParse=(n,s)=>Am(e,n,s),e.parseAsync=async(n,s)=>Em(e,n,s,{callee:e.parseAsync}),e.safeParseAsync=async(n,s)=>Tm(e,n,s),e.spa=e.safeParseAsync,e.encode=(n,s)=>Im(e,n,s),e.decode=(n,s)=>Cm(e,n,s),e.encodeAsync=async(n,s)=>zm(e,n,s),e.decodeAsync=async(n,s)=>$m(e,n,s),e.safeEncode=(n,s)=>Rm(e,n,s),e.safeDecode=(n,s)=>Pm(e,n,s),e.safeEncodeAsync=async(n,s)=>Dm(e,n,s),e.safeDecodeAsync=async(n,s)=>Lm(e,n,s),e.refine=(n,s)=>e.check(Tv(n,s)),e.superRefine=n=>e.check(Iv(n)),e.overwrite=n=>e.check(Bn(n)),e.optional=()=>kc(e),e.exactOptional=()=>fv(e),e.nullable=()=>wc(e),e.nullish=()=>kc(wc(e)),e.nonoptional=n=>kv(e,n),e.array=()=>R(e),e.or=n=>W([e,n]),e.and=n=>ri(e,n),e.transform=n=>bc(e,dv(n)),e.default=n=>vv(e,n),e.prefault=n=>yv(e,n),e.catch=n=>bv(e,n),e.pipe=n=>bc(e,n),e.readonly=()=>Ev(e),e.describe=n=>{const s=e.clone();return hs.add(s,{description:n}),s},Object.defineProperty(e,"description",{get(){var n;return(n=hs.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return hs.get(e);const s=e.clone();return hs.add(s,n[0]),s},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),Kl=b("_ZodString",(e,t)=>{qo.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Kg(e,s,r);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...s)=>e.check(Rg(...s)),e.includes=(...s)=>e.check(Lg(...s)),e.startsWith=(...s)=>e.check(Mg(...s)),e.endsWith=(...s)=>e.check(Og(...s)),e.min=(...s)=>e.check(Lr(...s)),e.max=(...s)=>e.check(Zl(...s)),e.length=(...s)=>e.check(jl(...s)),e.nonempty=(...s)=>e.check(Lr(1,...s)),e.lowercase=s=>e.check(Pg(s)),e.uppercase=s=>e.check(Dg(s)),e.trim=()=>e.check(Wg()),e.normalize=(...s)=>e.check(Ng(...s)),e.toLowerCase=()=>e.check(Fg()),e.toUpperCase=()=>e.check(Ug()),e.slugify=()=>e.check(Zg())}),Mm=b("ZodString",(e,t)=>{qo.init(e,t),Kl.init(e,t),e.email=n=>e.check(ng(Om,n)),e.url=n=>e.check(ag(Nm,n)),e.jwt=n=>e.check(bg(Qm,n)),e.emoji=n=>e.check(cg(Wm,n)),e.guid=n=>e.check(pc(_c,n)),e.uuid=n=>e.check(sg(hr,n)),e.uuidv4=n=>e.check(rg(hr,n)),e.uuidv6=n=>e.check(ig(hr,n)),e.uuidv7=n=>e.check(og(hr,n)),e.nanoid=n=>e.check(lg(Fm,n)),e.guid=n=>e.check(pc(_c,n)),e.cuid=n=>e.check(ug(Um,n)),e.cuid2=n=>e.check(hg(Zm,n)),e.ulid=n=>e.check(dg(jm,n)),e.base64=n=>e.check(yg(Ym,n)),e.base64url=n=>e.check(kg(Xm,n)),e.xid=n=>e.check(pg(Hm,n)),e.ksuid=n=>e.check(fg(Bm,n)),e.ipv4=n=>e.check(gg(Vm,n)),e.ipv6=n=>e.check(mg(Gm,n)),e.cidrv4=n=>e.check(vg(qm,n)),e.cidrv6=n=>e.check(_g(Km,n)),e.e164=n=>e.check(wg(Jm,n)),e.datetime=n=>e.check(vm(n)),e.date=n=>e.check(ym(n)),e.time=n=>e.check(wm(n)),e.duration=n=>e.check(Sm(n))});function u(e){return tg(Mm,e)}const ae=b("ZodStringFormat",(e,t)=>{se.init(e,t),Kl.init(e,t)}),Om=b("ZodEmail",(e,t)=>{cf.init(e,t),ae.init(e,t)}),_c=b("ZodGUID",(e,t)=>{of.init(e,t),ae.init(e,t)}),hr=b("ZodUUID",(e,t)=>{af.init(e,t),ae.init(e,t)}),Nm=b("ZodURL",(e,t)=>{lf.init(e,t),ae.init(e,t)}),Wm=b("ZodEmoji",(e,t)=>{uf.init(e,t),ae.init(e,t)}),Fm=b("ZodNanoID",(e,t)=>{hf.init(e,t),ae.init(e,t)}),Um=b("ZodCUID",(e,t)=>{df.init(e,t),ae.init(e,t)}),Zm=b("ZodCUID2",(e,t)=>{pf.init(e,t),ae.init(e,t)}),jm=b("ZodULID",(e,t)=>{ff.init(e,t),ae.init(e,t)}),Hm=b("ZodXID",(e,t)=>{gf.init(e,t),ae.init(e,t)}),Bm=b("ZodKSUID",(e,t)=>{mf.init(e,t),ae.init(e,t)}),Vm=b("ZodIPv4",(e,t)=>{wf.init(e,t),ae.init(e,t)}),Gm=b("ZodIPv6",(e,t)=>{bf.init(e,t),ae.init(e,t)}),qm=b("ZodCIDRv4",(e,t)=>{Sf.init(e,t),ae.init(e,t)}),Km=b("ZodCIDRv6",(e,t)=>{xf.init(e,t),ae.init(e,t)}),Ym=b("ZodBase64",(e,t)=>{Ef.init(e,t),ae.init(e,t)}),Xm=b("ZodBase64URL",(e,t)=>{Tf.init(e,t),ae.init(e,t)}),Jm=b("ZodE164",(e,t)=>{If.init(e,t),ae.init(e,t)}),Qm=b("ZodJWT",(e,t)=>{zf.init(e,t),ae.init(e,t)}),Yl=b("ZodNumber",(e,t)=>{Ol.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Yg(e,s,r),e.gt=(s,r)=>e.check(gc(s,r)),e.gte=(s,r)=>e.check($i(s,r)),e.min=(s,r)=>e.check($i(s,r)),e.lt=(s,r)=>e.check(fc(s,r)),e.lte=(s,r)=>e.check(zi(s,r)),e.max=(s,r)=>e.check(zi(s,r)),e.int=s=>e.check(yc(s)),e.safe=s=>e.check(yc(s)),e.positive=s=>e.check(gc(0,s)),e.nonnegative=s=>e.check($i(0,s)),e.negative=s=>e.check(fc(0,s)),e.nonpositive=s=>e.check(zi(0,s)),e.multipleOf=(s,r)=>e.check(mc(s,r)),e.step=(s,r)=>e.check(mc(s,r)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function N(e){return Tg(Yl,e)}const ev=b("ZodNumberFormat",(e,t)=>{$f.init(e,t),Yl.init(e,t)});function yc(e){return Ig(ev,e)}const tv=b("ZodBoolean",(e,t)=>{Rf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Xg(e,n,s)});function _e(e){return Cg(tv,e)}const nv=b("ZodUnknown",(e,t)=>{Pf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Qg()});function _(){return zg(nv)}const sv=b("ZodNever",(e,t)=>{Df.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Jg(e,n,s)});function rv(e){return $g(sv,e)}const iv=b("ZodArray",(e,t)=>{Lf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>rm(e,n,s,r),e.element=t.element,e.min=(n,s)=>e.check(Lr(n,s)),e.nonempty=n=>e.check(Lr(1,n)),e.max=(n,s)=>e.check(Zl(n,s)),e.length=(n,s)=>e.check(jl(n,s)),e.unwrap=()=>e.element});function R(e,t){return jg(iv,e,t)}const Xl=b("ZodObject",(e,t)=>{Of.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>im(e,n,s,r),q(e,"shape",()=>t.shape),e.keyof=()=>Ql(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:_()}),e.loose=()=>e.clone({...e._zod.def,catchall:_()}),e.strict=()=>e.clone({...e._zod.def,catchall:rv()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>sp(e,n),e.safeExtend=n=>rp(e,n),e.merge=n=>ip(e,n),e.pick=n=>tp(e,n),e.omit=n=>np(e,n),e.partial=(...n)=>op(eu,e,n[0]),e.required=(...n)=>ap(tu,e,n[0])});function Ko(e,t){const n={type:"object",shape:e??{},...P(t)};return new Xl(n)}function p(e,t){return new Xl({type:"object",shape:e,catchall:_(),...P(t)})}const Jl=b("ZodUnion",(e,t)=>{Fl.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>om(e,n,s,r),e.options=t.options});function W(e,t){return new Jl({type:"union",options:e,...P(t)})}const ov=b("ZodDiscriminatedUnion",(e,t)=>{Jl.init(e,t),Nf.init(e,t)});function av(e,t,n){return new ov({type:"union",options:t,discriminator:e,...P(n)})}const cv=b("ZodIntersection",(e,t)=>{Wf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>am(e,n,s,r)});function ri(e,t){return new cv({type:"intersection",left:e,right:t})}const lv=b("ZodRecord",(e,t)=>{Ff.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>cm(e,n,s,r),e.keyType=t.keyType,e.valueType=t.valueType});function k(e,t,n){return new lv({type:"record",keyType:e,valueType:t,...P(n)})}const Qi=b("ZodEnum",(e,t)=>{Uf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>em(e,s,r),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(s,r)=>{const i={};for(const o of s)if(n.has(o))i[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new Qi({...t,checks:[],...P(r),entries:i})},e.exclude=(s,r)=>{const i={...t.entries};for(const o of s)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new Qi({...t,checks:[],...P(r),entries:i})}});function Ql(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(s=>[s,s])):e;return new Qi({type:"enum",entries:n,...P(t)})}const uv=b("ZodLiteral",(e,t)=>{Zf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>tm(e,n,s),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function S(e,t){return new uv({type:"literal",values:Array.isArray(e)?e:[e],...P(t)})}const hv=b("ZodTransform",(e,t)=>{jf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>sm(e,n),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new wl(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(ks(i,n.value,t));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(ks(o))}};const r=t.transform(n.value,n);return r instanceof Promise?r.then(i=>(n.value=i,n)):(n.value=r,n)}});function dv(e){return new hv({type:"transform",transform:e})}const eu=b("ZodOptional",(e,t)=>{Ul.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Gl(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function kc(e){return new eu({type:"optional",innerType:e})}const pv=b("ZodExactOptional",(e,t)=>{Hf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Gl(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function fv(e){return new pv({type:"optional",innerType:e})}const gv=b("ZodNullable",(e,t)=>{Bf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>lm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function wc(e){return new gv({type:"nullable",innerType:e})}const mv=b("ZodDefault",(e,t)=>{Vf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>hm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function vv(e,t){return new mv({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():El(t)}})}const _v=b("ZodPrefault",(e,t)=>{Gf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>dm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function yv(e,t){return new _v({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():El(t)}})}const tu=b("ZodNonOptional",(e,t)=>{qf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>um(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function kv(e,t){return new tu({type:"nonoptional",innerType:e,...P(t)})}const wv=b("ZodCatch",(e,t)=>{Kf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>pm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function bv(e,t){return new wv({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Sv=b("ZodPipe",(e,t)=>{Yf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>fm(e,n,s,r),e.in=t.in,e.out=t.out});function bc(e,t){return new Sv({type:"pipe",in:e,out:t})}const xv=b("ZodReadonly",(e,t)=>{Xf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>gm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function Ev(e){return new xv({type:"readonly",innerType:e})}const Av=b("ZodCustom",(e,t)=>{Jf.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>nm(e,n)});function Tv(e,t={}){return Hg(Av,e,t)}function Iv(e){return Bg(e)}const nu=Ko({kind:S("file"),path:u()}),Cv=Ko({id:u(),type:S("markdown"),title:u(),token:u(),source:nu}),zv=Ko({id:u(),type:S("html"),title:u(),token:u(),source:nu});av("type",[Cv,zv]);const su="markdown";function $v(e){const t=e.type??su;return{id:e.id??en(),type:t,title:e.title,token:e.token??en(),source:e.source}}const st=4,We=6,ru=2,eo=2,Rv=st,Pv=We,Yo="auto",zt="auto",Zt=120,Sc=75,ce=16,Tt=Zt*st+ce*(st-1),In=Zt*We+ce*(We-1),Dv=200,Lv=4,dr=150,Mv=10,xc=2,Ov=4,Nv=/^[0-9A-HJKMNP-TV-Z]{26}$/;function iu(e){return cu(e)}function ou(e,t){return cu(e.flatMap(n=>uu(n,t)))}function au(e){const t=[],n=new Set;for(const s of e){if(s.type==="row"){t.push(`Top-level rows are invalid: ${s.id}`);continue}hu(s,"strip",t,n)}return{valid:t.length===0,errors:t}}function zn(e){const t=iu(e),n=au(t);if(!n.valid)throw new Error(`Invalid layout: ${n.errors.join("; ")}`);return{totalNodes:t.length,nodes:t.filter(s=>s.type!=="row").map(Zv)}}function cu(e){const t=[];for(const n of e){const s=lu(n);for(const r of s){if(r.type==="row"){t.push(...r.children.map(_t));continue}t.push(r)}}return t}function lu(e){switch(e.type){case"card":return[_t(e)];case"row":{const t=e.children.map(_t);return t.length===0?[]:t.length===1?[t[0]]:[{...e,children:t}]}case"stack":{const t=[];for(const n of e.children){const s=lu(n);for(const r of s){if(r.type==="stack"){t.push(...r.children.map(to));continue}if(r.type==="row"){t.push({...r,children:r.children.map(_t)});continue}t.push(_t(r))}}return t.length===0?[]:t.length===1?[to(t[0])]:[{...e,children:t}]}}}function uu(e,t){switch(e.type){case"card":return e.artifactID===t?[]:[_t(e)];case"row":{const n=e.children.filter(s=>s.artifactID!==t).map(_t);return n.length===0?[]:n.length===1?[n[0]]:[{...e,children:n}]}case"stack":{const n=e.children.flatMap(s=>uu(s,t).filter(i=>i.type!=="stack"));return n.length===0?[]:n.length===1?[to(n[0])]:[{...e,children:n}]}}}function hu(e,t,n,s){switch(e.type){case"card":du(e,t,n,s);return;case"row":Wv(e,t,n,s);return;case"stack":Fv(e,t,n,s);return}}function du(e,t,n,s){Xo(e.id,n),typeof e.artifactID!="string"||e.artifactID.length===0?n.push(`Card ${e.id} is missing artifactID`):s.has(e.artifactID)?n.push(`Duplicate artifactID in layout: ${e.artifactID}`):s.add(e.artifactID),Uv(e.width)||n.push(`Card ${e.id} width must be an integer in the range 2-4`),pu(e.height)||n.push(`Card ${e.id} height must be an integer in the range 2-6 or "auto"`);const r=jt(e.width);t==="row"&&r<ru&&n.push(`Row child ${e.id} must be at least 2 columns wide`)}function Wv(e,t,n,s){if(Xo(e.id,n),t!=="stack"&&n.push(`Row ${e.id} may only appear inside a stack`),pu(e.height,Ov)||n.push(`Row ${e.id} height must be an integer in the range 2-4 or "auto"`),!Array.isArray(e.children)||e.children.length===0){n.push(`Row ${e.id} must contain card nodes`);return}let r=0;for(const i of e.children){if(i.type!=="card"){n.push(`Row ${e.id} must contain only card nodes`);continue}du(i,"row",n,s),r+=jt(i.width)}r!==st&&n.push(`Row ${e.id} children must sum to 4 columns`)}function Fv(e,t,n,s){if(Xo(e.id,n),t!=="strip"&&n.push(`Invalid nested stack at ${e.id}; stack children cannot contain another nested stack`),!Array.isArray(e.children)||e.children.length===0){n.push(`Stack ${e.id} must contain at least one child`);return}let r=0,i=0;for(const a of e.children){if(a.type==="stack"){n.push(`Stack ${e.id} cannot contain another nested stack`);continue}if(hu(a,"stack",n,s),a.height===zt){i+=1;continue}r+=a.height}if(r>We&&n.push(`Stack ${e.id} exceeds the 6-row budget`),i===0)return;const o=We-r;if(o<i*eo||o%i!==0){n.push(`Stack ${e.id} has auto-height children that cannot resolve to whole height >= 2`);return}o/i<eo&&n.push(`Stack ${e.id} has auto-height children below the minimum row size`)}function Xo(e,t){(typeof e!="string"||!Nv.test(e))&&t.push(`Node id must be a ULID: ${String(e)}`)}function Uv(e){return e===Yo||Number.isInteger(e)&&e>=ru&&e<=Rv}function pu(e,t=Pv){return e===zt||Number.isInteger(e)&&e>=eo&&e<=t}function jt(e){return e===Yo?st:e}function Zv(e){if(e.type==="card")return{id:e.id,type:"card",width:jt(e.width),cards:[{id:e.id,artifactID:e.artifactID,col:1,row:1,width:jt(e.width),height:fu(e.height,We)}]};const t=jv(e.children),n=[];let s=1;for(let r=0;r<e.children.length;r+=1){const i=e.children[r],o=t[r];if(i.type==="card")n.push({id:i.id,artifactID:i.artifactID,col:1,row:s,width:jt(i.width),height:o});else{let a=1;for(const c of i.children)n.push({id:c.id,artifactID:c.artifactID,col:a,row:s,width:jt(c.width),height:o}),a+=jt(c.width)}s+=o}return{id:e.id,type:"stack",width:n.reduce((r,i)=>Math.max(r,i.col+i.width-1),1),cards:n}}function jv(e){let t=0,n=0;for(const r of e)r.height===zt?n+=1:t+=r.height;const s=n>0?(We-t)/n:0;return e.map(r=>fu(r.height,s))}function fu(e,t){return e===zt?t:e}function _t(e){return{...e}}function to(e){return e.type==="card"?_t(e):{...e,children:e.children.map(_t)}}function no(e,t={}){return{id:t.id??en(),type:"card",artifactID:e,width:t.width??Yo,height:t.height??zt}}function so(e,t){return e.some(n=>gu(n,t))}function gu(e,t){switch(e.type){case"card":return e.artifactID===t;case"row":return e.children.some(n=>n.artifactID===t);case"stack":return e.children.some(n=>gu(n,t))}}function Ri(e){return e.layout.flatMap(mu)}function mu(e){switch(e.type){case"card":return[e.artifactID];case"row":return e.children.map(t=>t.artifactID);case"stack":return e.children.flatMap(mu)}}const B=rt(),vu=rt(),es=rt(),Pi="create-artifact",Di="remove-artifact",pr="update-layout";class Hv extends ln{constructor(n){var r;super();m(this,"artifacts",new Map);m(this,"activeWorkspaceID",null);m(this,"scrollPosition",0);m(this,"artifactReloadVersions",new Map);m(this,"activeWorkspaceData",null);m(this,"clientStore");m(this,"serverManager");m(this,"pendingMutations",new Map);m(this,"pendingWorkspaceCreates",new Map);m(this,"pendingWorkspaceDeletes",new Map);this.clientStore=n.clientStore,this.serverManager=n.serverManager;const s=this.clientStore.get();this.activeWorkspaceID=(s==null?void 0:s.lastWorkspaceID)??null,this.activeWorkspaceID&&(this.scrollPosition=((r=s==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0)}get workspaces(){return[...this.serverManager.servers.values()].flatMap(n=>[...n.workspaces.values()])}get activeWorkspace(){return this.activeWorkspaceData}get activeWorkspaceServerURL(){var n;return this.activeWorkspaceID?((n=this.findWorkspace(this.activeWorkspaceID))==null?void 0:n.serverURL)??null:null}get activeArtifacts(){return(this.activeWorkspaceData?Ri(this.activeWorkspaceData):[]).map(n=>this.artifacts.get(n)).filter(n=>n!==void 0)}getArtifactURL(n){const s=this.activeWorkspaceServerURL;if(!s)return null;const r=this.serverManager.servers.get(s),i=this.artifacts.get(n);if(!(r!=null&&r.getArtifactURL)||!i)return null;const o=r.getArtifactURL(i);if(i.type!=="html")return o;const a=this.artifactReloadVersions.get(n)??0,c=new URL(o);return c.searchParams.set("rev",String(a)),c.toString()}setActiveWorkspace(n){this.selectWorkspace(n)}setScrollPosition(n){const s=Math.max(0,n);this.scrollPosition!==s&&(this.scrollPosition=s,this.persistWorkspaceViewState(),this.dispatchEvent(new B("change")))}createArtifact(n){var c;const s=this.activeWorkspaceData;if(!s)return;const r=this.snapshotState(),i=$v({id:en(),type:n.type??su,title:n.title,source:{kind:"file",path:n.path}});so(s.layout,i.id)||(s.layout=[...s.layout,no(i.id)]),this.artifacts.set(i.id,i),this.scrollPosition=Bv(s.layout),this.persistWorkspaceViewState(),this.dispatchEvent(new B("change"));const o=((c=this.findWorkspace(s.id))==null?void 0:c.server)??null,a=this.getMutationKey(Pi,i.id);this.pendingMutations.set(a,r),this.sendServerMessage(o,{type:"create-artifact",id:i.id,path:n.path,artifactType:i.type,workspaceID:s.id})||(this.pendingMutations.delete(a),this.restoreState(r),this.dispatchEvent(new B("change")))}removeArtifact(n){var a;const s=this.activeWorkspaceData;if(!s||!this.artifacts.has(n))return;const r=this.snapshotState();this.removeArtifactLocally(n),this.dispatchEvent(new B("change"));const i=((a=this.findWorkspace(s.id))==null?void 0:a.server)??null,o=this.getMutationKey(Di,n);this.pendingMutations.set(o,r),this.sendServerMessage(i,{type:"remove-artifact",artifactID:n,workspaceID:s.id})||(this.pendingMutations.delete(o),this.restoreState(r),this.dispatchEvent(new B("change")))}handleServerEvent(n,s){var r;switch(s.type){case"workspace-list":this.syncActiveWorkspaceState(n,!0);break;case"workspace-updated":this.syncActiveWorkspaceState(n,!1),Array.isArray(s.fields.layout)&&this.pendingMutations.delete(this.getMutationKey(pr,s.workspaceID));break;case"workspace-removed":{this.syncActiveWorkspaceState(n,!1);const i=this.pendingWorkspaceDeletes.get(s.workspaceID);i&&(this.pendingWorkspaceDeletes.delete(s.workspaceID),i.resolve());break}case"workspace-created":if(this.pendingWorkspaceCreates.has(s.workspace.id)){const i=this.pendingWorkspaceCreates.get(s.workspace.id);this.pendingWorkspaceCreates.delete(s.workspace.id),this.selectWorkspace(s.workspace.id),i==null||i.resolve();return}this.syncActiveWorkspaceState(n,!1);break;case"workspace":this.applyWorkspaceSnapshot(s.workspace,s.artifacts);break;case"artifact-created":this.pendingMutations.delete(this.getMutationKey(Pi,s.artifact.id)),this.applyArtifactCreated(s);break;case"artifact-updated":this.applyArtifactUpdated(s);break;case"artifact-removed":if(this.pendingMutations.delete(this.getMutationKey(Di,s.artifactID)),((r=this.activeWorkspaceData)==null?void 0:r.id)!==s.workspaceID)return;this.removeArtifactLocally(s.artifactID)&&this.dispatchEvent(new B("change"));break;case"error":this.handleServerError(s);break}}createWorkspace(n,s){const r=this.serverManager.servers.get(n)??null,i=en(),o=Ec();return this.pendingWorkspaceCreates.set(i,o),this.sendServerMessage(r,{type:"create-workspace",id:i,name:s})||(this.pendingWorkspaceCreates.delete(i),o.reject(new Error(`Server unavailable: ${n}`))),o.promise}deleteWorkspace(){var o;const n=this.activeWorkspaceData;if(!n)return Promise.reject(new Error("No active workspace"));const s=this.pendingWorkspaceDeletes.get(n.id);if(s)return s.promise;const r=((o=this.findWorkspace(n.id))==null?void 0:o.server)??null,i=Ec();return this.pendingWorkspaceDeletes.set(n.id,i),this.sendServerMessage(r,{type:"delete-workspace",workspaceID:n.id})||(this.pendingWorkspaceDeletes.delete(n.id),i.reject(new Error(`Server unavailable: ${n.id}`))),i.promise}renameWorkspace(n){var i;const s=this.activeWorkspaceData;if(!s)return;const r=((i=this.findWorkspace(s.id))==null?void 0:i.server)??null;s.name=n,this.dispatchEvent(new B("change")),this.sendServerMessage(r,{type:"update-workspace",workspaceID:s.id,fields:{name:n}})}setLayout(n){var l;const s=this.activeWorkspaceData;if(!s)return;const r=iu(n);if(!au(r).valid)return;const o=this.snapshotState();s.layout=r,this.dispatchEvent(new B("change"));const a=((l=this.findWorkspace(s.id))==null?void 0:l.server)??null,c=this.getMutationKey(pr,s.id);this.pendingMutations.set(c,o),this.sendServerMessage(a,{type:"update-workspace",workspaceID:s.id,fields:{layout:r.map(h=>structuredClone(h))}})||(this.pendingMutations.delete(c),this.restoreState(o),this.dispatchEvent(new B("change")))}syncActiveWorkspaceState(n,s){const r=this.activeWorkspaceID?this.findWorkspace(this.activeWorkspaceID):null;if(!r){const i=this.pickNextWorkspace();if(!i){const o=this.activeWorkspaceID!==null||this.activeWorkspaceData!==null||this.artifacts.size>0;this.activeWorkspaceID=null,this.activeWorkspaceData=null,this.artifacts.clear(),this.scrollPosition=0,o&&this.dispatchEvent(new B("change"));return}this.selectWorkspace(i.workspace.id);return}this.applyServerWorkspaceState(r.workspace),s&&r.serverURL===n&&this.requestWorkspace(r.serverURL,r.workspace.id)}hasPendingLayoutMutation(n){return this.pendingMutations.has(this.getMutationKey(pr,n))}selectWorkspace(n){const s=this.findWorkspace(n);s&&(this.activeWorkspaceID=n,this.activeWorkspaceData=structuredClone(s.workspace),this.artifacts.clear(),this.restoreWorkspaceViewState(),this.persistActiveWorkspace(),this.requestWorkspace(s.serverURL,n),this.dispatchEvent(new B("change")))}requestWorkspace(n,s){const r=this.serverManager.servers.get(n);this.sendServerMessage(r??null,{type:"get-workspace",workspaceID:s})}applyWorkspaceSnapshot(n,s){if(n.id===this.activeWorkspaceID){this.applyServerWorkspaceState(n),this.artifacts.clear();for(const r of s)this.artifacts.set(r.id,structuredClone(r));this.restoreWorkspaceViewState(),this.dispatchEvent(new B("change"))}}applyServerWorkspaceState(n){if(!this.activeWorkspaceData||this.activeWorkspaceData.id!==n.id){this.activeWorkspaceData=structuredClone(n);return}this.activeWorkspaceData.name=n.name,this.hasPendingLayoutMutation(n.id)||(this.activeWorkspaceData.layout=n.layout.map(s=>structuredClone(s)))}applyArtifactCreated(n){var s;((s=this.activeWorkspaceData)==null?void 0:s.id)===n.workspaceID&&(so(this.activeWorkspaceData.layout,n.artifact.id)||(this.activeWorkspaceData.layout=[...this.activeWorkspaceData.layout,no(n.artifact.id)]),this.artifacts.set(n.artifact.id,n.artifact),this.dispatchEvent(new B("change")))}applyArtifactUpdated(n){const s=this.artifacts.get(n.artifactID);s&&(Object.assign(s,n.fields),s.type==="html"&&this.artifactReloadVersions.set(n.artifactID,(this.artifactReloadVersions.get(n.artifactID)??0)+1),this.dispatchEvent(new B("change")))}removeArtifactLocally(n){if(!this.activeWorkspaceData)return!1;const s=this.artifacts.delete(n);this.artifactReloadVersions.delete(n);const r=Ri(this.activeWorkspaceData).length;return this.activeWorkspaceData.layout=ou(this.activeWorkspaceData.layout,n),!(!s&&r===Ri(this.activeWorkspaceData).length)}snapshotState(){return{activeWorkspaceData:this.activeWorkspaceData?structuredClone(this.activeWorkspaceData):null,scrollPosition:this.scrollPosition,artifacts:new Map([...this.artifacts.entries()].map(([n,s])=>[n,structuredClone(s)]))}}restoreState(n){this.activeWorkspaceData=n.activeWorkspaceData?structuredClone(n.activeWorkspaceData):null,this.scrollPosition=n.scrollPosition,this.artifacts.clear();for(const[s,r]of n.artifacts.entries())this.artifacts.set(s,structuredClone(r));this.persistWorkspaceViewState()}handleServerError(n){const s=n.request;if(s){if(s.type==="create-artifact"){const r=this.getMutationKey(Pi,s.id),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="create-workspace"){const r=this.pendingWorkspaceCreates.get(s.id);if(!r)return;this.pendingWorkspaceCreates.delete(s.id),r.reject(new Error(n.message));return}if(s.type==="delete-workspace"){const r=this.pendingWorkspaceDeletes.get(s.workspaceID);if(!r)return;this.pendingWorkspaceDeletes.delete(s.workspaceID),r.reject(new Error(n.message));return}if(s.type==="update-workspace"&&Array.isArray(s.fields.layout)){const r=this.getMutationKey(pr,s.workspaceID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="remove-artifact"){const r=this.getMutationKey(Di,s.artifactID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"))}}}restoreWorkspaceViewState(){var s,r;if(!this.activeWorkspaceID){this.scrollPosition=0;return}const n=((r=(s=this.clientStore.get())==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0;this.scrollPosition=Math.max(0,n),this.persistWorkspaceViewState()}persistActiveWorkspace(){this.clientStore.update(n=>{n.lastWorkspaceID=this.activeWorkspaceID})}persistWorkspaceViewState(){this.activeWorkspaceID&&this.clientStore.update(n=>{var s,r;(s=n.workspaces)[r=this.activeWorkspaceID]??(s[r]={scrollPosition:0}),n.workspaces[this.activeWorkspaceID].scrollPosition=this.scrollPosition})}findWorkspace(n){for(const[s,r]of this.serverManager.servers){const i=r.workspaces.get(n);if(i)return{serverURL:s,server:r,workspace:i}}return null}pickNextWorkspace(){var s;const n=(s=this.clientStore.get())==null?void 0:s.lastWorkspaceID;if(n){const r=this.findWorkspace(n);if(r)return r}for(const[r,i]of this.serverManager.servers){const o=i.workspaces.values().next().value;if(o)return{serverURL:r,server:i,workspace:o}}return null}sendServerMessage(n,s){return n?n.send(s):!1}getServers(){return this.serverManager.servers}getMutationKey(n,s){return`${n}:${s}`}}function Bv(e){var s;const t=zn(e);if(t.nodes.length<=1)return 0;let n=0;for(let r=0;r<t.nodes.length-1;r+=1)n+=((s=t.nodes[r])==null?void 0:s.width)??0;return n}function Ec(){let e,t;return{promise:new Promise((s,r)=>{e=s,t=r}),resolve:e,reject:t}}var _u=Symbol.for("immer-nothing"),Ac=Symbol.for("immer-draftable"),Fe=Symbol.for("immer-state");function Ye(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var ws=Object.getPrototypeOf;function Zn(e){return!!e&&!!e[Fe]}function tn(e){var t;return e?yu(e)||Array.isArray(e)||!!e[Ac]||!!((t=e.constructor)!=null&&t[Ac])||Ys(e)||oi(e):!1}var Vv=Object.prototype.constructor.toString(),Tc=new WeakMap;function yu(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let s=Tc.get(n);return s===void 0&&(s=Function.toString.call(n),Tc.set(n,s)),s===Vv}function Or(e,t,n=!0){ii(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((s,r)=>t(r,s,e))}function ii(e){const t=e[Fe];return t?t.type_:Array.isArray(e)?1:Ys(e)?2:oi(e)?3:0}function ro(e,t){return ii(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function ku(e,t,n){const s=ii(e);s===2?e.set(t,n):s===3?e.add(n):e[t]=n}function Gv(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Ys(e){return e instanceof Map}function oi(e){return e instanceof Set}function Wt(e){return e.copy_||e.base_}function io(e,t){if(Ys(e))return new Map(e);if(oi(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const n=yu(e);if(t===!0||t==="class_only"&&!n){const s=Object.getOwnPropertyDescriptors(e);delete s[Fe];let r=Reflect.ownKeys(s);for(let i=0;i<r.length;i++){const o=r[i],a=s[o];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(s[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[o]})}return Object.create(ws(e),s)}else{const s=ws(e);if(s!==null&&n)return{...e};const r=Object.create(s);return Object.assign(r,e)}}function Jo(e,t=!1){return ai(e)||Zn(e)||!tn(e)||(ii(e)>1&&Object.defineProperties(e,{set:fr,add:fr,clear:fr,delete:fr}),Object.freeze(e),t&&Object.values(e).forEach(n=>Jo(n,!0))),e}function qv(){Ye(2)}var fr={value:qv};function ai(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var Kv={};function nn(e){const t=Kv[e];return t||Ye(0,e),t}var bs;function wu(){return bs}function Yv(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ic(e,t){t&&(nn("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function oo(e){ao(e),e.drafts_.forEach(Xv),e.drafts_=null}function ao(e){e===bs&&(bs=e.parent_)}function Cc(e){return bs=Yv(bs,e)}function Xv(e){const t=e[Fe];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function zc(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return e!==void 0&&e!==n?(n[Fe].modified_&&(oo(t),Ye(4)),tn(e)&&(e=Nr(t,e),t.parent_||Wr(t,e)),t.patches_&&nn("Patches").generateReplacementPatches_(n[Fe].base_,e,t.patches_,t.inversePatches_)):e=Nr(t,n,[]),oo(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==_u?e:void 0}function Nr(e,t,n){if(ai(t))return t;const s=e.immer_.shouldUseStrictIteration(),r=t[Fe];if(!r)return Or(t,(i,o)=>$c(e,r,t,i,o,n),s),t;if(r.scope_!==e)return t;if(!r.modified_)return Wr(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;const i=r.copy_;let o=i,a=!1;r.type_===3&&(o=new Set(i),i.clear(),a=!0),Or(o,(c,l)=>$c(e,r,i,c,l,n,a),s),Wr(e,i,!1),n&&e.patches_&&nn("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function $c(e,t,n,s,r,i,o){if(r==null||typeof r!="object"&&!o)return;const a=ai(r);if(!(a&&!o)){if(Zn(r)){const c=i&&t&&t.type_!==3&&!ro(t.assigned_,s)?i.concat(s):void 0,l=Nr(e,r,c);if(ku(n,s,l),Zn(l))e.canAutoFreeze_=!1;else return}else o&&n.add(r);if(tn(r)&&!a){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[s]===r&&a)return;Nr(e,r),(!t||!t.scope_.parent_)&&typeof s!="symbol"&&(Ys(n)?n.has(s):Object.prototype.propertyIsEnumerable.call(n,s))&&Wr(e,r)}}}function Wr(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Jo(t,n)}function Jv(e,t){const n=Array.isArray(e),s={type_:n?1:0,scope_:t?t.scope_:wu(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let r=s,i=Qo;n&&(r=[s],i=Ss);const{revoke:o,proxy:a}=Proxy.revocable(r,i);return s.draft_=a,s.revoke_=o,a}var Qo={get(e,t){if(t===Fe)return e;const n=Wt(e);if(!ro(n,t))return Qv(e,n,t);const s=n[t];return e.finalized_||!tn(s)?s:s===Li(e.base_,t)?(Mi(e),e.copy_[t]=lo(s,e)):s},has(e,t){return t in Wt(e)},ownKeys(e){return Reflect.ownKeys(Wt(e))},set(e,t,n){const s=bu(Wt(e),t);if(s!=null&&s.set)return s.set.call(e.draft_,n),!0;if(!e.modified_){const r=Li(Wt(e),t),i=r==null?void 0:r[Fe];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(Gv(n,r)&&(n!==void 0||ro(e.base_,t)))return!0;Mi(e),co(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Li(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Mi(e),co(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=Wt(e),s=Reflect.getOwnPropertyDescriptor(n,t);return s&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:s.enumerable,value:n[t]}},defineProperty(){Ye(11)},getPrototypeOf(e){return ws(e.base_)},setPrototypeOf(){Ye(12)}},Ss={};Or(Qo,(e,t)=>{Ss[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});Ss.deleteProperty=function(e,t){return Ss.set.call(this,e,t,void 0)};Ss.set=function(e,t,n){return Qo.set.call(this,e[0],t,n,e[0])};function Li(e,t){const n=e[Fe];return(n?Wt(n):e)[t]}function Qv(e,t,n){var r;const s=bu(t,n);return s?"value"in s?s.value:(r=s.get)==null?void 0:r.call(e.draft_):void 0}function bu(e,t){if(!(t in e))return;let n=ws(e);for(;n;){const s=Object.getOwnPropertyDescriptor(n,t);if(s)return s;n=ws(n)}}function co(e){e.modified_||(e.modified_=!0,e.parent_&&co(e.parent_))}function Mi(e){e.copy_||(e.copy_=io(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var e_=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,s)=>{if(typeof t=="function"&&typeof n!="function"){const i=n;n=t;const o=this;return function(c=i,...l){return o.produce(c,h=>n.call(this,h,...l))}}typeof n!="function"&&Ye(6),s!==void 0&&typeof s!="function"&&Ye(7);let r;if(tn(t)){const i=Cc(this),o=lo(t,void 0);let a=!0;try{r=n(o),a=!1}finally{a?oo(i):ao(i)}return Ic(i,s),zc(r,i)}else if(!t||typeof t!="object"){if(r=n(t),r===void 0&&(r=t),r===_u&&(r=void 0),this.autoFreeze_&&Jo(r,!0),s){const i=[],o=[];nn("Patches").generateReplacementPatches_(t,r,i,o),s(i,o)}return r}else Ye(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(o,...a)=>this.produceWithPatches(o,c=>t(c,...a));let s,r;return[this.produce(t,n,(o,a)=>{s=o,r=a}),s,r]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){tn(e)||Ye(8),Zn(e)&&(e=t_(e));const t=Cc(this),n=lo(e,void 0);return n[Fe].isManual_=!0,ao(t),n}finishDraft(e,t){const n=e&&e[Fe];(!n||!n.isManual_)&&Ye(9);const{scope_:s}=n;return Ic(s,t),zc(void 0,s)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(r.path.length===0&&r.op==="replace"){e=r.value;break}}n>-1&&(t=t.slice(n+1));const s=nn("Patches").applyPatches_;return Zn(e)?s(e,t):this.produce(e,r=>s(r,t))}};function lo(e,t){const n=Ys(e)?nn("MapSet").proxyMap_(e,t):oi(e)?nn("MapSet").proxySet_(e,t):Jv(e,t);return(t?t.scope_:wu()).drafts_.push(n),n}function t_(e){return Zn(e)||Ye(10,e),Su(e)}function Su(e){if(!tn(e)||ai(e))return e;const t=e[Fe];let n,s=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=io(e,t.scope_.immer_.useStrictShallowCopy_),s=t.scope_.immer_.shouldUseStrictIteration()}else n=io(e,!0);return Or(n,(r,i)=>{ku(n,r,Su(i))},s),t&&(t.finalized_=!1),n}var n_=new e_,s_=n_.produce,r_=Object.defineProperty,i_=(e,t,n)=>t in e?r_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gr=(e,t,n)=>i_(e,typeof t!="symbol"?t+"":t,n);function o_(e){return{all:e=e||new Map,on:function(t,n){var s=e.get(t);s?s.push(n):e.set(t,[n])},off:function(t,n){var s=e.get(t);s&&(n?s.splice(s.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var s=e.get(t);s&&s.slice().map(function(r){r(n)}),(s=e.get("*"))&&s.slice().map(function(r){r(t,n)})}}}var a_=class{constructor(){gr(this,"emitter",o_()),gr(this,"on",(e,t)=>(this.emitter.on(e,t),{dispose:()=>this.emitter.off(e,t)})),gr(this,"once",(e,t)=>{const n=s=>{t(s),this.emitter.off(e,n)};return this.emitter.on(e,n),{dispose:()=>this.emitter.off(e,n)}}),gr(this,"off",this.emitter.off)}emit(e,...[t]){this.emitter.emit(e,t)}},c_="store-",l_=class extends a_{emitChange(e){this.emit("change",{state:e})}},u_=class{constructor(e,t,n){this.emitter=new l_,this.id=e,this.initValue=t,this.key=`${c_}${e}`,this.storage=(n==null?void 0:n.storage)==="session"?sessionStorage:localStorage,this.get()===void 0&&this.storage.setItem(this.key,JSON.stringify(t))}get(){const e=this.storage.getItem(this.key);return e===null?void 0:JSON.parse(e)}update(e){const t=this.get()??{},n=s_(t,e);this.storage.setItem(this.key,JSON.stringify(n)),this.emitter.emitChange(n)}reset(){this.storage.setItem(this.key,JSON.stringify(this.initValue)),this.emitter.emitChange(this.initValue)}on(e,t){return this.emitter.on(e,({state:n})=>t(n))}subscribe(e){const t=this.on("change",e),n=this.get();return n!==void 0&&e(n),t}};const h_="Local";function kt(e){return new URL(e).origin}function d_(e){return{servers:[{url:kt(e),name:h_}],lastWorkspaceID:null,workspaces:{}}}function p_(e,t){return new u_(e,d_(t))}const f_=4401;class uo extends Error{constructor(t="Authentication required"){super(t),this.name="AuthError"}}class ho extends ln{constructor(n){super();m(this,"url");m(this,"name");m(this,"token");m(this,"status","disconnected");m(this,"workspaces",new Map);m(this,"createSocket");m(this,"socket",null);m(this,"connectAttempt",0);this.url=kt(n.url),this.name=n.name,this.token=n.token??null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}async connect(){var r;this.connectAttempt+=1;const n=this.connectAttempt;(r=this.socket)==null||r.close(),this.status="connecting",this.dispatchEvent(new B("change"));const s=this.createSocket(g_(this.url,this.token));return this.socket=s,await new Promise((i,o)=>{let a=!1;const c=()=>{a||this.connectAttempt!==n||(a=!0,this.status="connected",this.dispatchEvent(new B("change")),i())},l=h=>{a||this.connectAttempt!==n||(a=!0,this.status="disconnected",this.dispatchEvent(new B("change")),o(h))};s.addEventListener("message",h=>{const f=v_(h);this.applyServerMessage(f),this.dispatchEvent(new vu("server-message",{serverURL:this.url,message:f})),a||c()}),s.addEventListener("close",h=>{if(this.connectAttempt===n){if(this.socket=null,m_(h)===f_){l(new uo);return}if(!a){l(new Error("Connection closed before initialization"));return}this.status="disconnected",this.dispatchEvent(new B("change"))}}),s.addEventListener("error",()=>{l(new Error("WebSocket connection failed"))})})}disconnect(){var n;this.connectAttempt+=1,(n=this.socket)==null||n.close(),this.socket=null,this.status="disconnected",this.dispatchEvent(new B("change"))}send(n){return!this.socket||this.socket.readyState!==1?!1:(this.socket.send(JSON.stringify(n)),!0)}getArtifactURL(n){const s=new URL(this.url);return s.pathname=`/artifact/${n.id}`,s.search="",s.searchParams.set("token",n.token),s.hash="",s.toString()}applyServerMessage(n){switch(n.type){case"workspace-list":this.workspaces=new Map(n.workspaces.map(s=>[s.id,structuredClone(s)]));break;case"workspace-created":this.workspaces.set(n.workspace.id,structuredClone(n.workspace));break;case"workspace-updated":{const s=this.workspaces.get(n.workspaceID);s&&(typeof n.fields.name=="string"&&(s.name=n.fields.name),Array.isArray(n.fields.layout)&&(s.layout=n.fields.layout));break}case"workspace-removed":this.workspaces.delete(n.workspaceID);break;case"artifact-created":{const s=this.workspaces.get(n.workspaceID);s&&!so(s.layout,n.artifact.id)&&(s.layout=[...s.layout,no(n.artifact.id)]);break}case"artifact-removed":{const s=this.workspaces.get(n.workspaceID);s&&(s.layout=ou(s.layout,n.artifactID));break}}}}function g_(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname="/ws",n.search="",t&&n.searchParams.set("token",t),n.hash="",n.toString()}function m_(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="number"?e.code:null}function v_(e){const t=typeof e=="string"?e:typeof e=="object"&&e!==null&&"data"in e&&typeof e.data=="string"?e.data:"";return JSON.parse(t)}class __ extends ln{constructor(n){super();m(this,"servers",new Map);m(this,"localServerURL");m(this,"activeServer",null);m(this,"clientStore");m(this,"createSocket");m(this,"serverListeners",new Map);this.clientStore=n.clientStore,this.localServerURL=n.localServerURL?kt(n.localServerURL):null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}add(n){const s=kt(n.url);this.servers.get(s)&&this.remove(s),this.servers.set(s,n);const i=()=>{this.dispatchEvent(new B("change"))},o=a=>{this.dispatchEvent(new vu("server-message",{serverURL:a.serverURL,message:a.message}))};n.addEventListener("change",i),n.addEventListener("server-message",o),this.serverListeners.set(s,{onServerChange:i,onServerMessage:o}),this.dispatchEvent(new B("change"))}remove(n){const s=kt(n);if(this.localServerURL&&s===this.localServerURL)return;const r=this.servers.get(s);if(!r)return;const i=this.serverListeners.get(s);i&&(r.removeEventListener("change",i.onServerChange),r.removeEventListener("server-message",i.onServerMessage),this.serverListeners.delete(s)),r.disconnect(),this.servers.delete(s),this.activeServer===r&&(this.activeServer=null),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>a.url!==s)}),this.dispatchEvent(new B("change"))}setActive(n){this.activeServer=n,this.dispatchEvent(new B("change"))}connectConfiguredServers(n){var i;const s=((i=this.clientStore.get())==null?void 0:i.servers)??[];for(const o of s){const a=new ho({url:o.url,name:o.name,createSocket:this.createSocket});this.add(a),a.connect().catch(()=>{})}const r=n?this.servers.get(kt(n))??null:null;this.setActive(r??this.servers.values().next().value??null)}addServer(n,s){const r=kt(n);this.remove(r),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>kt(a.url)!==r),o.servers.push({url:r,name:s})});const i=new ho({url:r,name:s,createSocket:this.createSocket});this.add(i),this.setActive(i),i.connect().catch(()=>{})}removeServer(n){this.remove(n)}}const te={authenticate:"authenticate",document_did_change:"document/didChange",document_did_close:"document/didClose",document_did_focus:"document/didFocus",document_did_open:"document/didOpen",document_did_save:"document/didSave",initialize:"initialize",logout:"logout",nes_accept:"nes/accept",nes_close:"nes/close",nes_reject:"nes/reject",nes_start:"nes/start",nes_suggest:"nes/suggest",session_cancel:"session/cancel",session_close:"session/close",session_fork:"session/fork",session_list:"session/list",session_load:"session/load",session_new:"session/new",session_prompt:"session/prompt",session_resume:"session/resume",session_set_config_option:"session/set_config_option",session_set_mode:"session/set_mode",session_set_model:"session/set_model"},ct={fs_read_text_file:"fs/read_text_file",fs_write_text_file:"fs/write_text_file",session_request_permission:"session/request_permission",session_update:"session/update",terminal_create:"terminal/create",terminal_kill:"terminal/kill",terminal_output:"terminal/output",terminal_release:"terminal/release",terminal_wait_for_exit:"terminal/wait_for_exit"},y_=1,k_=p({_meta:k(u(),_()).nullish(),terminal:_e().optional().default(!1)}),w_=p({_meta:k(u(),_()).nullish(),label:u().nullish(),name:u(),optional:_e().optional().default(!1),secret:_e().optional().default(!0)}),b_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),name:u()}),S_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),link:u().nullish(),name:u(),vars:R(w_)}),x_=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),description:u().nullish(),env:k(u(),u()).optional(),id:u(),name:u()}),E_=W([S_.and(p({type:S("env_var")})),x_.and(p({type:S("terminal")})),b_]),A_=p({_meta:k(u(),_()).nullish(),methodId:u()}),T_=p({_meta:k(u(),_()).nullish()}),I_=p({_meta:k(u(),_()).nullish(),blob:u(),mimeType:u().nullish(),uri:u()}),C_=p({default:_e().nullish(),description:u().nullish(),title:u().nullish()}),z_=p({_meta:k(u(),_()).nullish()}),$_=p({_meta:k(u(),_()).nullish()}),R_=p({amount:N(),currency:u()}),P_=p({_meta:k(u(),_()).nullish(),terminalId:u()}),D_=p({_meta:k(u(),_()).nullish(),newText:u(),oldText:u().nullish(),path:u()}),L_=W([u(),N(),N(),_e(),R(u())]),M_=p({content:k(u(),L_).nullish()}),O_=W([M_.and(p({action:S("accept")})),p({action:S("decline")}),p({action:S("cancel")})]),N_=p({_meta:k(u(),_()).nullish()}),xu=u(),W_=p({_meta:k(u(),_()).nullish(),elicitationId:xu}),F_=p({_meta:k(u(),_()).nullish(),action:O_}),U_=S("object"),Z_=S("string"),j_=p({_meta:k(u(),_()).nullish()}),H_=p({_meta:k(u(),_()).nullish(),form:N_.nullish(),url:j_.nullish()}),B_=p({elicitationId:xu,url:u().url()}),Eu=p({const:u(),title:u()}),Au=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),V_=W([S(-32700),S(-32600),S(-32601),S(-32602),S(-32603),S(-32800),S(-32e3),S(-32002),S(-32042),N().int().min(-2147483648,{message:"Invalid value: Expected int32 to be >= -2147483648"}).max(2147483647,{message:"Invalid value: Expected int32 to be <= 2147483647"})]),Tu=p({code:V_,data:_().optional(),message:u()}),Iu=_(),Cu=_(),zu=_(),G_=p({_meta:k(u(),_()).nullish(),readTextFile:_e().optional().default(!1),writeTextFile:_e().optional().default(!1)}),$u=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),Ru=p({_meta:k(u(),_()).nullish(),name:u(),title:u().nullish(),version:u()}),q_=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),K_=p({_meta:k(u(),_()).nullish()}),Y_=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cursor:u().nullish(),cwd:u().nullish()}),X_=p({_meta:k(u(),_()).nullish()}),J_=p({_meta:k(u(),_()).nullish(),logout:X_.nullish()}),Q_=p({_meta:k(u(),_()).nullish()}),ey=p({_meta:k(u(),_()).nullish()}),ty=p({_meta:k(u(),_()).nullish(),http:_e().optional().default(!1),sse:_e().optional().default(!1)}),ny=p({_meta:k(u(),_()).nullish(),headers:R($u),name:u(),url:u()}),sy=p({_meta:k(u(),_()).nullish(),headers:R($u),name:u(),url:u()}),ry=p({_meta:k(u(),_()).nullish(),args:R(u()),command:u(),env:R(Au),name:u()}),ci=W([ny.and(p({type:S("http")})),sy.and(p({type:S("sse")})),ry]),ea=u(),iy=p({_meta:k(u(),_()).nullish(),description:u().nullish(),modelId:ea,name:u()}),oy=W([S("error"),S("warning"),S("information"),S("hint")]),ay=p({_meta:k(u(),_()).nullish()}),cy=p({_meta:k(u(),_()).nullish()}),ly=p({_meta:k(u(),_()).nullish()}),uy=p({_meta:k(u(),_()).nullish()}),hy=p({_meta:k(u(),_()).nullish()}),dy=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),py=p({diff:u(),uri:u()}),fy=p({endLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),startLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),text:u()}),gy=p({_meta:k(u(),_()).nullish()}),my=p({_meta:k(u(),_()).nullish()}),vy=p({languageId:u(),text:u(),uri:u()}),_y=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),yy=W([S("rejected"),S("ignored"),S("replaced"),S("cancelled")]),ky=p({excerpts:R(fy),uri:u()}),wy=p({_meta:k(u(),_()).nullish()}),by=p({_meta:k(u(),_()).nullish()}),Sy=p({name:u(),owner:u(),remoteUrl:u()}),xy=p({_meta:k(u(),_()).nullish()}),Ey=p({_meta:k(u(),_()).nullish(),jump:gy.nullish(),rename:by.nullish(),searchAndReplace:xy.nullish()}),Ay=p({id:u(),isRegex:_e().nullish(),replace:u(),search:u(),uri:u()}),Ty=W([S("automatic"),S("diagnostic"),S("manual")]),Iy=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),Cy=p({_meta:k(u(),_()).nullish(),diagnostics:ay.nullish(),editHistory:dy.nullish(),openFiles:my.nullish(),recentFiles:_y.nullish(),relatedSnippets:wy.nullish(),userActions:Iy.nullish()}),zy=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci)}),$y=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),Pu=u(),Ry=W([S("allow_once"),S("allow_always"),S("reject_once"),S("reject_always")]),Py=p({_meta:k(u(),_()).nullish(),kind:Ry,name:u(),optionId:Pu}),Dy=W([S("high"),S("medium"),S("low")]),Ly=W([S("pending"),S("in_progress"),S("completed")]),My=p({_meta:k(u(),_()).nullish(),content:u(),priority:Dy,status:Ly}),Oy=p({_meta:k(u(),_()).nullish(),entries:R(My)}),$t=p({character:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"})}),Ny=p({id:u(),position:$t,uri:u()}),Wy=p({id:u(),newName:u(),position:$t,uri:u()}),Fy=p({action:u(),position:$t,timestampMs:N(),uri:u()}),Du=W([S("utf-16"),S("utf-32"),S("utf-8")]),Uy=p({_meta:k(u(),_()).nullish(),auth:k_.optional().default({terminal:!1}),elicitation:H_.nullish(),fs:G_.optional().default({readTextFile:!1,writeTextFile:!1}),nes:Ey.nullish(),positionEncodings:R(Du).optional(),terminal:_e().optional().default(!1)}),Zy=p({_meta:k(u(),_()).nullish(),audio:_e().optional().default(!1),embeddedContext:_e().optional().default(!1),image:_e().optional().default(!1)}),Lu=N().int().gte(0).lte(65535),jy=p({_meta:k(u(),_()).nullish(),clientCapabilities:Uy.optional().default({auth:{terminal:!1},fs:{readTextFile:!1,writeTextFile:!1},terminal:!1}),clientInfo:Ru.nullish(),protocolVersion:Lu}),Vn=p({end:$t,start:$t}),Hy=p({message:u(),range:Vn,severity:oy,uri:u()}),By=p({languageId:u(),lastFocusedMs:N().nullish(),uri:u(),visibleRange:Vn.nullish()}),Vy=p({_meta:k(u(),_()).nullish(),diagnostics:R(Hy).nullish(),editHistory:R(py).nullish(),openFiles:R(By).nullish(),recentFiles:R(vy).nullish(),relatedSnippets:R(ky).nullish(),userActions:R(Fy).nullish()}),Gy=p({newText:u(),range:Vn}),qy=p({cursorPosition:$t.nullish(),edits:R(Gy),id:u(),uri:u()}),Ky=W([qy.and(p({kind:S("edit")})),Ny.and(p({kind:S("jump")})),Wy.and(p({kind:S("rename")})),Ay.and(p({kind:S("searchAndReplace")}))]),Yy=p({_meta:k(u(),_()).nullish(),content:u()}),Xy=p({_meta:k(u(),_()).nullish()}),sn=W([N(),u()]).nullable();p({_meta:k(u(),_()).nullish(),requestId:sn});const Jy=Ql(["assistant","user"]),Xs=p({_meta:k(u(),_()).nullish(),audience:R(Jy).nullish(),lastModified:u().nullish(),priority:N().nullish()}),Qy=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),data:u(),mimeType:u()}),ek=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),data:u(),mimeType:u(),uri:u().nullish()}),tk=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),description:u().nullish(),mimeType:u().nullish(),name:u(),size:N().nullish(),title:u().nullish(),uri:u()}),nk=p({_meta:k(u(),_()).nullish(),optionId:Pu}),sk=W([p({outcome:S("cancelled")}),nk.and(p({outcome:S("selected")}))]),rk=p({_meta:k(u(),_()).nullish(),outcome:sk}),ik=p({_meta:k(u(),_()).nullish()}),ok=p({_meta:k(u(),_()).nullish()}),ak=p({currentValue:_e()}),ck=u(),Mu=u(),lk=W([S("mode"),S("model"),S("thought_level"),u()]),ta=u(),Ou=p({_meta:k(u(),_()).nullish(),description:u().nullish(),name:u(),value:ta}),uk=p({_meta:k(u(),_()).nullish(),group:ck,name:u(),options:R(Ou)}),hk=W([R(Ou),R(uk)]),dk=p({currentValue:ta,options:hk}),Gn=ri(W([dk.and(p({type:S("select")})),ak.and(p({type:S("boolean")}))]),p({_meta:k(u(),_()).nullish(),category:lk.nullish(),description:u().nullish(),id:Mu,name:u()})),pk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn)}),fk=p({_meta:k(u(),_()).nullish()}),V=u(),gk=p({_meta:k(u(),_()).nullish(),id:u(),sessionId:V}),mk=p({_meta:k(u(),_()).nullish(),sessionId:V}),vk=p({_meta:k(u(),_()).nullish(),sessionId:V}),_k=p({_meta:k(u(),_()).nullish(),sessionId:V}),Nu=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),command:u(),cwd:u().nullish(),env:R(Au).optional(),outputByteLimit:N().nullish(),sessionId:V}),yk=p({_meta:k(u(),_()).nullish(),sessionId:V,uri:u()}),kk=p({_meta:k(u(),_()).nullish(),position:$t,sessionId:V,uri:u(),version:N(),visibleRange:Vn}),wk=p({_meta:k(u(),_()).nullish(),languageId:u(),sessionId:V,text:u(),uri:u(),version:N()}),bk=p({_meta:k(u(),_()).nullish(),sessionId:V,uri:u()}),Sk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci).optional(),sessionId:V}),Wu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),xk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci),sessionId:V}),Fu=p({_meta:k(u(),_()).nullish(),limit:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u(),sessionId:V}),Ek=p({_meta:k(u(),_()).nullish(),id:u(),reason:yy.nullish(),sessionId:V}),Uu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Ak=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ci).optional(),sessionId:V}),Tk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),sessionId:V,title:u().nullish(),updatedAt:u().nullish()}),Ik=p({_meta:k(u(),_()).nullish(),nextCursor:u().nullish(),sessions:R(Tk)}),Ck=p({_meta:k(u(),_()).nullish(),title:u().nullish(),updatedAt:u().nullish()}),zk=p({_meta:k(u(),_()).nullish()}),li=u(),$k=p({_meta:k(u(),_()).nullish(),currentModeId:li}),Rk=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:li,name:u()}),ui=p({_meta:k(u(),_()).nullish(),availableModes:R(Rk),currentModeId:li}),hi=p({_meta:k(u(),_()).nullish(),availableModels:R(iy),currentModelId:ea}),Pk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish(),sessionId:V}),Dk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish()}),Lk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish(),sessionId:V}),Mk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn).nullish(),models:hi.nullish(),modes:ui.nullish()}),Ok=p({_meta:k(u(),_()).nullish()}),Nk=p({_meta:k(u(),_()).nullish(),additionalDirectories:ik.nullish(),close:ok.nullish(),fork:fk.nullish(),list:zk.nullish(),resume:Ok.nullish()}),Wk=ri(W([p({type:S("boolean"),value:_e()}),p({value:ta})]),p({_meta:k(u(),_()).nullish(),configId:Mu,sessionId:V})),Fk=p({_meta:k(u(),_()).nullish(),configOptions:R(Gn)}),Uk=p({_meta:k(u(),_()).nullish(),modeId:li,sessionId:V}),Zk=p({_meta:k(u(),_()).nullish()}),jk=p({_meta:k(u(),_()).nullish(),modelId:ea,sessionId:V}),Hk=p({_meta:k(u(),_()).nullish()}),Bk=p({_meta:k(u(),_()).nullish(),sessionId:V}),Vk=W([S("end_turn"),S("max_tokens"),S("max_turn_requests"),S("refusal"),S("cancelled")]),Gk=W([S("email"),S("uri"),S("date"),S("date-time")]),qk=p({default:u().nullish(),description:u().nullish(),enum:R(u()).nullish(),format:Gk.nullish(),maxLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),minLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),oneOf:R(Eu).nullish(),pattern:u().nullish(),title:u().nullish()}),Kk=p({_meta:k(u(),_()).nullish(),context:Vy.nullish(),position:$t,selection:Vn.nullish(),sessionId:V,triggerKind:Ty,uri:u(),version:N()}),Yk=p({_meta:k(u(),_()).nullish(),suggestions:R(Ky)}),Xk=p({_meta:k(u(),_()).nullish(),terminalId:u()}),Jk=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Zu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Qk=p({_meta:k(u(),_()).nullish(),exitStatus:Jk.nullish(),output:u(),truncated:_e()}),ew=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),text:u()}),tw=p({range:Vn.nullish(),text:u()}),nw=p({_meta:k(u(),_()).nullish(),contentChanges:R(tw),sessionId:V,uri:u(),version:N()});p({method:u(),params:W([mk,wk,nw,yk,bk,kk,gk,Ek,Iu]).nullish()});const sw=W([S("full"),S("incremental")]),rw=p({_meta:k(u(),_()).nullish(),syncKind:sw}),iw=p({_meta:k(u(),_()).nullish(),didChange:rw.nullish(),didClose:cy.nullish(),didFocus:ly.nullish(),didOpen:uy.nullish(),didSave:hy.nullish()}),ow=p({_meta:k(u(),_()).nullish(),document:iw.nullish()}),aw=p({_meta:k(u(),_()).nullish(),context:Cy.nullish(),events:ow.nullish()}),cw=p({_meta:k(u(),_()).nullish(),auth:J_.optional().default({}),loadSession:_e().optional().default(!1),mcpCapabilities:ty.optional().default({http:!1,sse:!1}),nes:aw.nullish(),positionEncoding:Du.nullish(),promptCapabilities:Zy.optional().default({audio:!1,embeddedContext:!1,image:!1}),sessionCapabilities:Nk.optional().default({})}),lw=p({_meta:k(u(),_()).nullish(),agentCapabilities:cw.optional().default({auth:{},loadSession:!1,mcpCapabilities:{http:!1,sse:!1},promptCapabilities:{audio:!1,embeddedContext:!1,image:!1},sessionCapabilities:{}}),agentInfo:Ru.nullish(),authMethods:R(E_).optional().default([]),protocolVersion:Lu}),uw=p({_meta:k(u(),_()).nullish(),mimeType:u().nullish(),text:u(),uri:u()}),hw=W([uw,I_]),dw=p({_meta:k(u(),_()).nullish(),annotations:Xs.nullish(),resource:hw}),na=W([ew.and(p({type:S("text")})),ek.and(p({type:S("image")})),Qy.and(p({type:S("audio")})),tk.and(p({type:S("resource_link")})),dw.and(p({type:S("resource")}))]),pw=p({_meta:k(u(),_()).nullish(),content:na}),Oi=p({_meta:k(u(),_()).nullish(),content:na,messageId:u().nullish()}),fw=p({_meta:k(u(),_()).nullish(),messageId:u().nullish(),prompt:R(na),sessionId:V}),gw=p({anyOf:R(Eu)}),ju=W([pw.and(p({type:S("content")})),D_.and(p({type:S("diff")})),Xk.and(p({type:S("terminal")}))]),Hu=u(),Bu=p({_meta:k(u(),_()).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u()}),Vu=W([S("pending"),S("in_progress"),S("completed"),S("failed")]),Gu=W([S("read"),S("edit"),S("delete"),S("move"),S("search"),S("execute"),S("think"),S("fetch"),S("switch_mode"),S("other")]),mw=p({_meta:k(u(),_()).nullish(),content:R(ju).optional(),kind:Gu.optional(),locations:R(Bu).optional(),rawInput:_().optional(),rawOutput:_().optional(),status:Vu.optional(),title:u(),toolCallId:Hu}),qu=p({_meta:k(u(),_()).nullish(),content:R(ju).nullish(),kind:Gu.nullish(),locations:R(Bu).nullish(),rawInput:_().optional(),rawOutput:_().optional(),status:Vu.nullish(),title:u().nullish(),toolCallId:Hu}),Ku=p({_meta:k(u(),_()).nullish(),options:R(Py),sessionId:V,toolCall:qu}),vw=p({_meta:k(u(),_()).nullish(),hint:u()}),_w=vw,yw=p({_meta:k(u(),_()).nullish(),description:u(),input:_w.nullish(),name:u()}),kw=p({_meta:k(u(),_()).nullish(),availableCommands:R(yw)}),ww=p({enum:R(u()),type:Z_}),bw=W([ww,gw]),Sw=p({default:R(u()).nullish(),description:u().nullish(),items:bw,maxItems:N().nullish(),minItems:N().nullish(),title:u().nullish()}),xw=W([qk.and(p({type:S("string")})),$y.and(p({type:S("number")})),q_.and(p({type:S("integer")})),C_.and(p({type:S("boolean")})),Sw.and(p({type:S("array")}))]),Ew=p({description:u().nullish(),properties:k(u(),xw).optional().default({}),required:R(u()).nullish(),title:u().nullish(),type:U_.optional().default("object")}),Aw=p({requestedSchema:Ew}),Tw=ri(W([Aw.and(p({mode:S("form")})),B_.and(p({mode:S("url")}))]),p({_meta:k(u(),_()).nullish(),message:u(),sessionId:V})),Iw=p({cachedReadTokens:N().nullish(),cachedWriteTokens:N().nullish(),inputTokens:N(),outputTokens:N(),thoughtTokens:N().nullish(),totalTokens:N()}),Cw=p({_meta:k(u(),_()).nullish(),stopReason:Vk,usage:Iw.nullish(),userMessageId:u().nullish()});W([p({id:sn,result:W([lw,T_,ey,Lk,Dk,Ik,Pk,Mk,$_,Zk,Fk,Cw,Hk,Bk,Yk,z_,zu])}),p({error:Tu,id:sn})]);const zw=p({_meta:k(u(),_()).nullish(),cost:R_.nullish(),size:N(),used:N()}),$w=W([Oi.and(p({sessionUpdate:S("user_message_chunk")})),Oi.and(p({sessionUpdate:S("agent_message_chunk")})),Oi.and(p({sessionUpdate:S("agent_thought_chunk")})),mw.and(p({sessionUpdate:S("tool_call")})),qu.and(p({sessionUpdate:S("tool_call_update")})),Oy.and(p({sessionUpdate:S("plan")})),kw.and(p({sessionUpdate:S("available_commands_update")})),$k.and(p({sessionUpdate:S("current_mode_update")})),pk.and(p({sessionUpdate:S("config_option_update")})),Ck.and(p({sessionUpdate:S("session_info_update")})),zw.and(p({sessionUpdate:S("usage_update")}))]),Yu=p({_meta:k(u(),_()).nullish(),sessionId:V,update:$w});p({method:u(),params:W([Yu,W_,Iu]).nullish()});const Xu=p({_meta:k(u(),_()).nullish(),sessionId:V,terminalId:u()}),Rw=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Pw=p({name:u(),uri:u()}),Dw=p({_meta:k(u(),_()).nullish(),repository:Sy.nullish(),workspaceFolders:R(Pw).nullish(),workspaceUri:u().nullish()});p({id:sn,method:u(),params:W([jy,A_,Q_,zy,xk,Y_,Sk,Ak,_k,Uk,Wk,fw,jk,Dw,Kk,vk,Cu]).nullish()});const Ju=p({_meta:k(u(),_()).nullish(),content:u(),path:u(),sessionId:V});p({id:sn,method:u(),params:W([Ju,Fu,Ku,Nu,Zu,Uu,Xu,Wu,Tw,Cu]).nullish()});const Lw=p({_meta:k(u(),_()).nullish()});W([p({id:sn,result:W([Lw,Yy,rk,P_,Qk,Xy,Rw,K_,F_,zu])}),p({error:Tu,id:sn})]);var H;class Mw{constructor(t,n){I(this,H);const s=t(this),r=async(o,a)=>{var c,l,h,f,w,v,E;switch(o){case ct.fs_write_text_file:{const x=Ju.parse(a);return(c=s.writeTextFile)==null?void 0:c.call(s,x)}case ct.fs_read_text_file:{const x=Fu.parse(a);return(l=s.readTextFile)==null?void 0:l.call(s,x)}case ct.session_request_permission:{const x=Ku.parse(a);return s.requestPermission(x)}case ct.terminal_create:{const x=Nu.parse(a);return(h=s.createTerminal)==null?void 0:h.call(s,x)}case ct.terminal_output:{const x=Zu.parse(a);return(f=s.terminalOutput)==null?void 0:f.call(s,x)}case ct.terminal_release:{const x=Uu.parse(a);return await((w=s.releaseTerminal)==null?void 0:w.call(s,x))??{}}case ct.terminal_wait_for_exit:{const x=Xu.parse(a);return(v=s.waitForTerminalExit)==null?void 0:v.call(s,x)}case ct.terminal_kill:{const x=Wu.parse(a);return await((E=s.killTerminal)==null?void 0:E.call(s,x))??{}}default:if(s.extMethod)return s.extMethod(o,a);throw ge.methodNotFound(o)}},i=async(o,a)=>{switch(o){case ct.session_update:{const c=Yu.parse(a);return s.sessionUpdate(c)}default:if(s.extNotification)return s.extNotification(o,a);throw ge.methodNotFound(o)}};C(this,H,new Ow(r,i,n))}async initialize(t){return await d(this,H).sendRequest(te.initialize,t)}async newSession(t){return await d(this,H).sendRequest(te.session_new,t)}async loadSession(t){return await d(this,H).sendRequest(te.session_load,t)??{}}async unstable_forkSession(t){return await d(this,H).sendRequest(te.session_fork,t)}async listSessions(t){return await d(this,H).sendRequest(te.session_list,t)}async unstable_resumeSession(t){return await d(this,H).sendRequest(te.session_resume,t)}async unstable_closeSession(t){return await d(this,H).sendRequest(te.session_close,t)}async setSessionMode(t){return await d(this,H).sendRequest(te.session_set_mode,t)??{}}async unstable_setSessionModel(t){return await d(this,H).sendRequest(te.session_set_model,t)??{}}async setSessionConfigOption(t){return await d(this,H).sendRequest(te.session_set_config_option,t)}async authenticate(t){return await d(this,H).sendRequest(te.authenticate,t)??{}}async unstable_logout(t){return await d(this,H).sendRequest(te.logout,t)??{}}async prompt(t){return await d(this,H).sendRequest(te.session_prompt,t)}async cancel(t){return await d(this,H).sendNotification(te.session_cancel,t)}async unstable_startNes(t){return await d(this,H).sendRequest(te.nes_start,t)}async unstable_suggestNes(t){return await d(this,H).sendRequest(te.nes_suggest,t)}async unstable_closeNes(t){return await d(this,H).sendRequest(te.nes_close,t)??{}}async unstable_didOpenDocument(t){return await d(this,H).sendNotification(te.document_did_open,t)}async unstable_didChangeDocument(t){return await d(this,H).sendNotification(te.document_did_change,t)}async unstable_didCloseDocument(t){return await d(this,H).sendNotification(te.document_did_close,t)}async unstable_didSaveDocument(t){return await d(this,H).sendNotification(te.document_did_save,t)}async unstable_didFocusDocument(t){return await d(this,H).sendNotification(te.document_did_focus,t)}async unstable_acceptNes(t){return await d(this,H).sendNotification(te.nes_accept,t)}async unstable_rejectNes(t){return await d(this,H).sendNotification(te.nes_reject,t)}async extMethod(t,n){return await d(this,H).sendRequest(t,n)}async extNotification(t,n){return await d(this,H).sendNotification(t,n)}get signal(){return d(this,H).signal}get closed(){return d(this,H).closed}}H=new WeakMap;var bt,Vr,zs,$s,$n,Rn,tt,Rs,re,Qu,po,eh,th,nh,sh,fo,ds;class Ow{constructor(t,n,s){I(this,re);I(this,bt,new Map);I(this,Vr,0);I(this,zs);I(this,$s);I(this,$n);I(this,Rn,Promise.resolve());I(this,tt,new AbortController);I(this,Rs);C(this,zs,t),C(this,$s,n),C(this,$n,s),C(this,Rs,new Promise(r=>{d(this,tt).signal.addEventListener("abort",()=>r())})),y(this,re,Qu).call(this)}get signal(){return d(this,tt).signal}get closed(){return d(this,Rs)}async sendRequest(t,n){y(this,re,fo).call(this);const s=Xa(this,Vr)._++,r=new Promise((i,o)=>{d(this,bt).set(s,{resolve:i,reject:o})});return await y(this,re,ds).call(this,{jsonrpc:"2.0",id:s,method:t,params:n}),r}async sendNotification(t,n){y(this,re,fo).call(this),await y(this,re,ds).call(this,{jsonrpc:"2.0",method:t,params:n})}}bt=new WeakMap,Vr=new WeakMap,zs=new WeakMap,$s=new WeakMap,$n=new WeakMap,Rn=new WeakMap,tt=new WeakMap,Rs=new WeakMap,re=new WeakSet,Qu=async function(){let t;try{const n=d(this,$n).readable.getReader();try{for(;!d(this,tt).signal.aborted;){const{value:s,done:r}=await n.read();if(r)break;if(s)try{y(this,re,eh).call(this,s)}catch(i){console.error("Unexpected error during message processing:",s,i),"id"in s&&s.id!==void 0&&y(this,re,ds).call(this,{jsonrpc:"2.0",id:s.id,error:{code:-32700,message:"Parse error"}})}}}finally{n.releaseLock()}}catch(n){t=n}finally{y(this,re,po).call(this,t)}},po=function(t){if(d(this,tt).signal.aborted)return;const n=t??new Error("ACP connection closed");for(const s of d(this,bt).values())s.reject(n);d(this,bt).clear(),d(this,tt).abort(n)},eh=async function(t){if("method"in t&&"id"in t){const n=await y(this,re,th).call(this,t.method,t.params);"error"in n&&console.error("Error handling request",t,n.error),await y(this,re,ds).call(this,{jsonrpc:"2.0",id:t.id,...n})}else if("method"in t){const n=await y(this,re,nh).call(this,t.method,t.params);"error"in n&&console.error("Error handling notification",t,n.error)}else"id"in t?y(this,re,sh).call(this,t):console.error("Invalid message",{message:t})},th=async function(t,n){try{return{result:await d(this,zs).call(this,t,n)??null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof vc)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},nh=async function(t,n){try{return await d(this,$s).call(this,t,n),{result:null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof vc)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},sh=function(t){const n=d(this,bt).get(t.id);if(n){if("result"in t)n.resolve(t.result);else if("error"in t){const{code:s,message:r,data:i}=t.error;n.reject(new ge(s,r,i))}d(this,bt).delete(t.id)}else console.error("Got response to unknown request",t.id)},fo=function(){if(d(this,tt).signal.aborted)throw d(this,tt).signal.reason??new Error("ACP connection closed")},ds=async function(t){return C(this,Rn,d(this,Rn).then(async()=>{const n=d(this,$n).writable.getWriter();try{await n.write(t)}finally{n.releaseLock()}}).catch(n=>{y(this,re,po).call(this,n)})),d(this,Rn)};class ge extends Error{constructor(n,s,r){super(s);m(this,"code");m(this,"data");this.code=n,this.name="RequestError",this.data=r}static parseError(n,s){return new ge(-32700,`Parse error${s?`: ${s}`:""}`,n)}static invalidRequest(n,s){return new ge(-32600,`Invalid request${s?`: ${s}`:""}`,n)}static methodNotFound(n){return new ge(-32601,`"Method not found": ${n}`,{method:n})}static invalidParams(n,s){return new ge(-32602,`Invalid params${s?`: ${s}`:""}`,n)}static internalError(n,s){return new ge(-32603,`Internal error${s?`: ${s}`:""}`,n)}static authRequired(n,s){return new ge(-32e3,`Authentication required${s?`: ${s}`:""}`,n)}static resourceNotFound(n){return new ge(-32002,`Resource not found${n?`: ${n}`:""}`,n&&{uri:n})}toResult(){return{error:{code:this.code,message:this.message,data:this.data}}}toErrorResponse(){return{code:this.code,message:this.message,data:this.data}}}const Nw=/^Sender \(untrusted metadata\):\n```json\n[\s\S]*?\n```\n\n?/,Ww=/^\[[^\n]*Working directory:[^\n]*\]\n\n?/,Fw=/\[Television workspace context\][\s\S]*?\[\/Television workspace context\]\n*/,Uw=/\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+|audio_as_voice)\s*\]\]\s*/gi,Zw="single_session",jw={name:"television-acp-client",version:"0.0.0"},rh="agent:main:television";var Q,ut,Pn,ht,Gt,qt,St,Dn,nt,Be,xt,Kt,dt,Et,Ps,pt,Ve,Gr,ft,Yt,T,ih,oh,go,ah,ch,lh,uh,hh,dh,ph,Ft,kn,wn,Me,fh,bn,mo,vo,xr,gh,Ds,Ls,_o,Sn,mh,vh;class Hw extends ln{constructor(n){super();I(this,T);I(this,Q,Bw());I(this,ut,null);I(this,Pn,null);I(this,ht,null);I(this,Gt,null);I(this,qt,null);I(this,St,null);I(this,Dn,1);I(this,nt,null);I(this,Be,null);I(this,xt,!1);I(this,Kt,!1);I(this,dt,null);I(this,Et,new Set);I(this,Ps);I(this,pt);I(this,Ve);I(this,Gr,n=>{y(this,T,oh).call(this,n)});I(this,ft,null);I(this,Yt,!1);I(this,Ds,()=>{y(this,T,Sn).call(this,"ACP bridge websocket closed")});I(this,Ls,()=>{y(this,T,Sn).call(this,"ACP bridge websocket error")});C(this,pt,n),C(this,Ve,n.sessionMode??Zw),C(this,Ps,n.createSocket??(s=>new WebSocket(s)))}getState(){return d(this,Q)}async connect(){if(d(this,Yt))throw new Error("ACPClientService has been disposed");if(d(this,Q).lifecycle.status!=="ready"){y(this,T,Me).call(this,{lifecycle:{status:"connecting"}}),d(this,Pn)??C(this,Pn,y(this,T,ih).call(this));try{await d(this,Pn),await y(this,T,go).call(this)}catch(n){throw y(this,T,Sn).call(this,mr(n)),n}}}async dispose(){d(this,Yt)||(C(this,Yt,!0),y(this,T,_o).call(this),y(this,T,Me).call(this,{lifecycle:{status:"disposed"},run:{status:"idle",stopReason:null,canCancel:!1,error:null}}))}async sendMessage(n){if(await this.connect(),d(this,Q).lifecycle.status!=="ready"||d(this,Q).run.status==="running"||d(this,Q).run.status==="cancelling")throw new Error("ACPClientService is not ready to send a new message");const s=n.text.trim();if(!s)throw new Error("Cannot send an empty message");y(this,T,kn).call(this,{id:y(this,T,bn).call(this,"user"),kind:"user",text:s,status:"final"}),y(this,T,Me).call(this,{run:{status:"running",stopReason:null,canCancel:!0,error:null}});try{const r=await y(this,T,xr).call(this).prompt({sessionId:y(this,T,vo).call(this),prompt:[{type:"text",text:y(this,T,fh).call(this,s)}]});y(this,T,Ft).call(this,r.stopReason==="cancelled"?"cancelled":"final"),y(this,T,Me).call(this,{run:{status:r.stopReason==="cancelled"?"cancelled":"completed",stopReason:r.stopReason,canCancel:!1,error:null}})}catch(r){throw y(this,T,vh).call(this)||(y(this,T,Ft).call(this,"error"),y(this,T,Me).call(this,{run:{status:"error",stopReason:null,canCancel:!1,error:mr(r)}})),r}}async cancel(){if(await this.connect(),!d(this,Q).run.canCancel||d(this,Q).run.status!=="running")throw new Error("No active cancellable run");y(this,T,Me).call(this,{run:{...d(this,Q).run,status:"cancelling"}}),await y(this,T,xr).call(this).cancel({sessionId:y(this,T,vo).call(this)})}setWorkspaceContext(n){var i,o,a;const s={workspaceID:n.workspaceID,workspaceName:n.workspaceName};if(((i=d(this,Be))==null?void 0:i.workspaceID)===s.workspaceID&&((o=d(this,Be))==null?void 0:o.workspaceName)===s.workspaceName)return;const r=((a=d(this,Be))==null?void 0:a.workspaceID)??null;if(C(this,Be,s),d(this,Ve)==="single_session"){(!d(this,St)||r!==s.workspaceID)&&C(this,xt,!0);return}d(this,St)!==Rc(d(this,Ve),s.workspaceID,d(this,pt).clientGUID??"default-client")&&(C(this,ht,null),C(this,Gt,null),d(this,ut)&&d(this,Q).run.status==="idle"&&y(this,T,go).call(this).catch(c=>{y(this,T,Sn).call(this,mr(c))}))}}Q=new WeakMap,ut=new WeakMap,Pn=new WeakMap,ht=new WeakMap,Gt=new WeakMap,qt=new WeakMap,St=new WeakMap,Dn=new WeakMap,nt=new WeakMap,Be=new WeakMap,xt=new WeakMap,Kt=new WeakMap,dt=new WeakMap,Et=new WeakMap,Ps=new WeakMap,pt=new WeakMap,Ve=new WeakMap,Gr=new WeakMap,ft=new WeakMap,Yt=new WeakMap,T=new WeakSet,ih=async function(){try{y(this,T,Me).call(this,{lifecycle:{status:"connecting"}});const{stream:n,socket:s}=await qw({serverURL:d(this,pt).serverURL,token:d(this,pt).token,createSocket:d(this,Ps),onDisconnect:d(this,Gr)});C(this,ft,s),s.addEventListener("close",d(this,Ds)),s.addEventListener("error",d(this,Ls)),C(this,ut,new Mw(r=>({connection:r,sessionUpdate:async i=>{await y(this,T,ch).call(this,i)},requestPermission:async i=>y(this,T,lh).call(this,i)}),n)),await d(this,ut).initialize({protocolVersion:y_,clientCapabilities:{},clientInfo:jw})}catch(n){throw n}},oh=function(n){y(this,T,Sn).call(this,mr(n))},go=async function(){const n=y(this,T,gh).call(this);if(d(this,ht)&&d(this,Gt)===n){await d(this,ht);return}C(this,Gt,n),C(this,ht,y(this,T,ah).call(this,n)),await d(this,ht)},ah=async function(n){const s=y(this,T,xr).call(this);y(this,T,mh).call(this);let r,i=!1;try{C(this,Kt,!0),C(this,dt,null),await s.loadSession({sessionId:n,cwd:"/",mcpServers:[],_meta:{sessionKey:n}}),r=n,i=d(this,Q).messageOrder.length>0}catch{r=(await s.newSession({cwd:"/",mcpServers:[],_meta:{sessionKey:n}})).sessionId,i=!1}finally{C(this,Kt,!1),C(this,dt,null),y(this,T,Ft).call(this,"final")}await s.setSessionConfigOption({sessionId:r,configId:"verbose_level",value:"full"}),C(this,qt,r),C(this,St,n),i?(d(this,Et).add(n),d(this,Ve)==="single_session"&&C(this,xt,!1)):(d(this,Et).delete(n),C(this,xt,d(this,Ve)==="single_session")),y(this,T,Me).call(this,{lifecycle:{status:"ready"}})},ch=async function(n){const s=n.update;switch(s.sessionUpdate){case"user_message_chunk":s.content.type==="text"&&y(this,T,ph).call(this,s.content.text);return;case"agent_message_chunk":s.content.type==="text"&&y(this,T,uh).call(this,s.content.text);return;case"tool_call":y(this,T,hh).call(this,s);return;case"tool_call_update":y(this,T,dh).call(this,s);return;case"agent_thought_chunk":return;default:return}},lh=async function(n){return{outcome:{outcome:"cancelled"}}},uh=function(n){C(this,dt,null);const s=Vw(n);if(!s)return;if(!d(this,nt)){const i={id:y(this,T,bn).call(this,"assistant"),kind:"assistant",text:s,status:"streaming"};C(this,nt,i.id),y(this,T,kn).call(this,i);return}const r=d(this,Q).messagesById[d(this,nt)];if(!r||r.kind!=="assistant")throw new Error("Open assistant message invariant violated");y(this,T,wn).call(this,{...r,text:`${r.text}${s}`,status:"streaming"})},hh=function(n){y(this,T,Ft).call(this,"final");const s=y(this,T,mo).call(this,n.toolCallId),r={id:(s==null?void 0:s.id)??y(this,T,bn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:n.title,toolKind:n.kind??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:(s==null?void 0:s.text)??"",locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,wn).call(this,r);return}y(this,T,kn).call(this,r)},dh=function(n){const s=y(this,T,mo).call(this,n.toolCallId),r=(s==null?void 0:s.text)??"",i=Gw(n.content),o=i?`${r}${i}`:r,a={id:(s==null?void 0:s.id)??y(this,T,bn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:(s==null?void 0:s.title)??n.toolCallId,toolKind:(s==null?void 0:s.toolKind)??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:o,locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,wn).call(this,a);return}y(this,T,kn).call(this,a)},ph=function(n){if(y(this,T,Ft).call(this,"final"),!n)return;const s=d(this,Kt)?d(this,dt):null;if(!s){const i=Pc(n);if(!i)return;const o={id:y(this,T,bn).call(this,"user"),kind:"user",text:i,status:"final"};y(this,T,kn).call(this,o),d(this,Kt)&&C(this,dt,o.id);return}const r=d(this,Q).messagesById[s];if(!r||r.kind!=="user")throw new Error("Replay user message invariant violated");y(this,T,wn).call(this,{...r,text:Pc(`${r.text}${n}`)})},Ft=function(n){if(!d(this,nt))return;const s=d(this,Q).messagesById[d(this,nt)];(s==null?void 0:s.kind)==="assistant"&&y(this,T,wn).call(this,{...s,status:n}),C(this,nt,null)},kn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n},messageOrder:[...d(this,Q).messageOrder,n.id]})},wn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n}})},Me=function(n){const s={...d(this,Q),...n};C(this,Q,{...s,sendDisabled:s.lifecycle.status!=="ready"||s.run.status==="running"||s.run.status==="cancelling",cancelDisabled:!(s.run.status==="running"||s.run.status==="cancelling")||!s.run.canCancel}),this.dispatchEvent(new B("change"))},fh=function(n){const s=d(this,St);return!d(this,Be)||!s||!(d(this,Ve)==="single_session"?d(this,xt)||!d(this,Et).has(s):!d(this,Et).has(s))?n:(C(this,xt,!1),d(this,Et).add(s),["[Television workspace context]","This chat session is coming from a Television client in the workspace below.",`workspace_id: ${d(this,Be).workspaceID}`,`workspace_name: ${d(this,Be).workspaceName??""}`,"When the user asks to inspect or change Television state with the tv CLI, use this workspace ID with the --workspace argument.","[/Television workspace context]","",n].join(`
40
40
  `))},bn=function(n){const s=`${n}-${d(this,Dn)}`;return C(this,Dn,d(this,Dn)+1),s},mo=function(n){for(const s of d(this,Q).messageOrder){const r=d(this,Q).messagesById[s];if((r==null?void 0:r.kind)==="tool_call"&&r.toolCallId===n)return r}return null},vo=function(){if(!d(this,qt))throw new Error("ACP session is not ready");return d(this,qt)},xr=function(){if(!d(this,ut))throw new Error("ACP connection is not ready");return d(this,ut)},gh=function(){var s;if(d(this,Ve)==="single_session")return`${rh}-${(d(this,pt).clientGUID??"default-client").toLowerCase()}`;const n=(s=d(this,Be))==null?void 0:s.workspaceID;if(!n)throw new Error("Workspace context is required for per-workspace session mode");return Rc(d(this,Ve),n,d(this,pt).clientGUID??"default-client")},Ds=new WeakMap,Ls=new WeakMap,_o=function(){C(this,ut,null),C(this,Pn,null),C(this,ht,null),C(this,Gt,null),C(this,qt,null),C(this,St,null),d(this,ft)&&(d(this,ft).removeEventListener("close",d(this,Ds)),d(this,ft).removeEventListener("error",d(this,Ls)),d(this,ft).close(),C(this,ft,null))},Sn=function(n){d(this,Yt)||d(this,Q).lifecycle.status==="disconnected"||(y(this,T,Ft).call(this,"error"),y(this,T,_o).call(this),y(this,T,Me).call(this,{lifecycle:{status:"disconnected",...n?{error:n}:{}},run:{status:"idle",stopReason:null,canCancel:!1,error:null}}))},mh=function(){C(this,nt,null),C(this,dt,null),C(this,Dn,1),y(this,T,Me).call(this,{run:{status:"idle",stopReason:null,canCancel:!1,error:null},messagesById:{},messageOrder:[]})},vh=function(){return d(this,Q).lifecycle.status==="disconnected"};function Bw(){return{lifecycle:{status:"connecting"},run:{status:"idle",stopReason:null,canCancel:!1,error:null},messagesById:{},messageOrder:[],sendDisabled:!0,cancelDisabled:!0}}function Rc(e,t,n){return e==="single_session"?`${rh}-${n.toLowerCase()}`:`agent:main:television-${n.toLowerCase()}-${t.toLowerCase()}`}function _h(e){return e.replace(/^(?:\s*\n)+/,"")}function Pc(e){let t=e;return t=t.replace(Nw,""),t=t.replace(Ww,""),t=t.replace(Fw,""),t=_h(t),t}function Vw(e){let t=e;return t=t.replace(Uw,""),t=_h(t),t}function Gw(e){return!e||e.length===0?"":e.flatMap(t=>t.type==="content"&&t.content.type==="text"?[t.content.text]:[]).join("")}async function qw(e){const t=e.createSocket(Yw(e.serverURL,e.token));let n=!1,s,r;const i=new Promise((c,l)=>{s=c,r=l}),o=new ReadableStream({start(c){let l=!1;const h=()=>{t.send(JSON.stringify({type:"acp-bridge-connect"}))},f=E=>{const x=Kw(E);if(!x)return;let z;try{z=JSON.parse(x)}catch(K){const Z=K instanceof Error?K:new Error(String(K));r(Z),c.error(Z);return}switch(z.type){case"acp-bridge-status":if(z.status==="ready"){n||(n=!0,s());return}if(z.status==="error"||z.status==="exited"){const K=new Error(z.error??`ACP bridge ${z.status}`);n||r(K),c.error(K)}return;case"acp-bridge-message":c.enqueue(z.message);return}},w=()=>{var x;if(l)return;l=!0;const E=new Error("ACP bridge websocket closed");n||r(E),(x=e.onDisconnect)==null||x.call(e,E),c.close()},v=()=>{var x;if(l)return;l=!0;const E=new Error("ACP bridge websocket error");n||r(E),(x=e.onDisconnect)==null||x.call(e,E),c.error(E)};t.addEventListener("open",h),t.addEventListener("message",f),t.addEventListener("close",w),t.addEventListener("error",v)}}),a=new WritableStream({async write(c){await i,t.send(JSON.stringify({type:"acp-bridge-message",message:c}))},close(){t.close()},abort(){t.close()}});return await i,{stream:{readable:o,writable:a},socket:t}}function Kw(e){if(typeof e=="string")return e;if(e instanceof Uint8Array)return new TextDecoder().decode(e);if(typeof Buffer<"u"&&e instanceof Buffer)return e.toString("utf8");if(typeof e=="object"&&e!==null&&"data"in e){const t=e.data;if(typeof t=="string")return t;if(t instanceof Uint8Array)return new TextDecoder().decode(t);if(Array.isArray(t))return Buffer.concat(t).toString("utf8")}return null}function Yw(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname="/ws",n.search="",n.searchParams.set("token",t),n.hash="",n.toString()}function mr(e){return e instanceof Error?e.message:String(e)}const Dc="television.acpClientGUID";class Xw extends ln{constructor(n){super();m(this,"workspaceService");m(this,"services",new Map);m(this,"options");m(this,"sessionMode");m(this,"clientGUID");m(this,"activeService",null);m(this,"handleWorkspaceChange",()=>{this.syncActiveService()});this.workspaceService=n.workspaceService,this.sessionMode=n.sessionMode??"single_session",this.options={serverURL:n.serverURL,token:n.token,...n.createSocket?{createSocket:n.createSocket}:{},...n.sessionMode?{sessionMode:n.sessionMode}:{}},this.clientGUID=n.clientGUID??Jw(n.storage??window.localStorage),this.workspaceService.addEventListener("change",this.handleWorkspaceChange),this.syncActiveService()}getActiveService(){return this.activeService}dispose(){this.workspaceService.removeEventListener("change",this.handleWorkspaceChange);for(const n of this.services.values())n.dispose();this.services.clear(),this.activeService=null}syncActiveService(){const n=this.workspaceService.activeWorkspace,s=n?this.getServiceForWorkspace(n):null;this.activeService!==s&&(this.activeService=s,this.dispatchEvent(new B("change")))}getServiceForWorkspace(n){const s=this.sessionMode==="single_session"?"single_session":n.id;let r=this.services.get(s);return r||(r=new Hw({...this.options,sessionMode:this.sessionMode,clientGUID:this.clientGUID}),this.services.set(s,r)),r.setWorkspaceContext({workspaceID:n.id,workspaceName:n.name}),r}}function Jw(e){const t=e.getItem(Dc);if(t)return t;const n=en().toLowerCase();return e.setItem(Dc,n),n}const Qw="serverURL",eb="token",tb="mode",nb="electron";function yh(e=window.location.search,t=window.location.origin){const s=new URLSearchParams(e).get(Qw);return s?new URL(s).origin:new URL(t).origin}function kh(e=window.location.search){return new URLSearchParams(e).get(eb)}function wh(e=window.location.search){return new URLSearchParams(e).get(tb)===nb}/**
41
41
  * @license
42
42
  * Copyright 2017 Google LLC