agent-comms 8.15.17 → 8.15.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/dist/bridges/user/web/dist/bundle.js +1 -1
- package/dist/bridges/user/web/dist/mesh-worker.js +4 -4
- package/dist/bridges/user/web/dist/sw.js +1 -1
- package/package.json +3 -3
- package/src/bridges/user/web/dist/bundle.js +1 -1
- package/src/bridges/user/web/dist/mesh-worker.js +4 -4
- package/src/bridges/user/web/dist/sw.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var AgentCommsMeshWorker=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return Array.isArray(e)?e:e==null?[]:[e]}var n=class extends Error{constructor(...e){super(...e),this.name=`AbortError`}};function r(e){let t=Promise.resolve();return(...n)=>t=t.catch(()=>{}).then(()=>e(...n))}var i=class{index=BigInt(1);generate(){let e=this.index.toString(36);return this.index++,e}};function a(e){return!e||typeof e!=`object`?!1:`next`in e&&typeof e.next==`function`&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]==`function`}var o=Symbol.asyncDispose??Symbol.for(`asyncDispose`),s=class{isDone=!1;isExecuteComplete=!1;cleanup;next;constructor(e,t){this.cleanup=t,this.next=r(async()=>{if(this.isDone)return{done:!0,value:void 0};let t;try{let t=await e();return t.done&&(this.isDone=!0),t}catch(e){throw t={value:e},this.isDone=!0,e}finally{this.isDone&&!this.isExecuteComplete&&(this.isExecuteComplete=!0,await this.cleanup(t?{kind:`error`,error:t.value}:{kind:`success`}))}})}async return(e){return this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`})),{done:!0,value:e}}async throw(e){throw this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`,error:e})),e}async[o](){this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`}))}[Symbol.asyncIterator](){return this}};function c(e){return JSON.stringify(e)}function l(e){for(let t of Object.values(e))if(t!==void 0)return!0;return!1}function u(e){if(!e)return!1;let t=typeof e;return t===`object`||t===`function`}var d=new WeakMap;function f(e,t,{bind:n=!0}={}){let r=Reflect.get(e,t);if(!n||typeof r!=`function`)return r;let i=d.get(r);i||d.set(r,i=new WeakMap);let a=i.get(e);return a||i.set(e,a=r.bind(e)),a}var p=class{items=[];pendingPulls=[];closed;push(e){if(this.closed)throw this.closed.reason;let t=this.pendingPulls.shift();t?t[0](e):this.items.push(e)}async pull(){if(this.items.length>0)return this.items.shift();if(this.closed)throw this.closed.reason;return new Promise((e,t)=>{this.pendingPulls.push([e,t])})}close(e){this.closed||(e??=new n(`Queue was closed.`),this.closed={reason:e},this.pendingPulls.forEach(([,t])=>t(e)),this.pendingPulls.length=0)}abort(e){e??=new n(`Queue was aborted.`),this.items.length=0,this.close(e)}};function ee(e,{signal:t}={}){return new Promise((n,r)=>{if(t?.aborted){r(t.reason);return}let i=null,a=setTimeout(()=>{i&&t?.removeEventListener(`abort`,i),n()},e);t&&t.addEventListener(`abort`,i=()=>{clearTimeout(a),r(t?.reason)},{once:!0})})}var te=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;function m(e){try{return encodeURIComponent(e)}catch{return encodeURIComponent(e.replace(te,`�`))}}function ne(e){if(!e.includes(`%`))return e;try{return decodeURIComponent(e)}catch{return e}}function re(e){return e[0]??{}}async function ie(e){return typeof e.bytes==`function`?e.bytes():new Uint8Array(await e.arrayBuffer())}function ae(e){return typeof e==`string`?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?se(e):e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function oe(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof ArrayBuffer?new Uint8Array(e):e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function se(e){let t=e.map(oe),n=t.reduce((e,t)=>e+t.byteLength,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.byteLength;return r}var ce=`orpc`;function le(e){return e instanceof Error&&e.name.includes(`Abort`)}Object.getPrototypeOf(async function*(){}).constructor;function ue(e){let t;return()=>{if(t)return t.result;let n=e();return t={result:n},n}}function de(e){return`/${e.map(m).join(`/`)}`}var fe=Symbol.for(`ORPC_TRACER`);function h(){return globalThis[fe]}function pe(e){let t=h();if(t)return typeof e==`string`?t.startSpan(e):t.startSpan(e.name,e.parent)}function me(e,t){e&&e.recordException(le(t)?`info`:`error`,he(t))}function he(e){if(e instanceof Error){let t={message:e.message,name:e.name,stack:e.stack};return`code`in e&&(typeof e.code==`string`||typeof e.code==`number`)&&(t.code=e.code),t}return{message:String(e)}}async function ge(e,t){let n=h();if(!n)return t();let r=typeof e==`string`?e:e.name,i=typeof e==`string`?void 0:e.parent;return n.startActiveSpan(r,i,async e=>{try{return await t(e)}catch(t){throw me(e,t),t}finally{e.end()}})}function _e(e,t){let n=h();return!e||!n?t():n.withActiveSpan(e,t)}function ve(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o;return new s(async()=>{try{let r;try{r=await t(()=>e.next()),o=r.done}catch(e){throw o=!0,e}return n?await n(r):r}catch(e){throw await i?.(e),r?await r(e):e}},async n=>{try{if(!o)try{await t(async()=>e.return?.())}catch(e){throw await i?.(e),e}}finally{await a?.()}})}function ye(e,t){let n=ue(()=>pe(e));return ve(t,{runWith:e=>_e(n(),e),mapResult(e){return n()?.addEvent(e.done?`completed`:`yielded`),e},onError(e){me(n(),e)},onFinish(){n()?.end()}})}function g(e,...t){return typeof e==`function`?e(...t):e}function be(e,t){return new Proxy(typeof e==`function`?t:e,{get(n,r){return f(r in t?t:g(e),r)},has(n,r){return Reflect.has(t,r)||Reflect.has(g(e),r)}})}function*xe(e){if(!u(e))return;let t=Object.getPrototypeOf(e);for(;t!=null;)t.constructor&&(yield t.constructor),t=Object.getPrototypeOf(t)}function Se(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||!t||!t.constructor}function Ce(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function we(e,t,n){let r=e[t];if(r!==n)return r;let i;if(Array.isArray(r))i=r.slice();else if(Se(r))i={...r};else return r;return Ce(e,t,i),i}var Te=(()=>{let e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})();function Ee(){let e={};return e.promise=new Promise((t,n)=>{e.resolve=t,e.reject=n}),e}function De(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o=ue(()=>e.getReader()),s=ue(async()=>a?.());return new ReadableStream({async pull(e){let a;try{let e=await t(()=>o().read());a=n?await n(e):e}catch(t){try{await i?.(t),e.error(r?await r(t):t)}finally{await s()}return}a.done?(e.close(),await s()):e.enqueue(a.value)},async cancel(e){try{try{await t(()=>o().cancel(e))}catch(e){throw await i?.(e),e}}finally{await s()}}})}function Oe(e,t){let n=ue(()=>pe(e));return De(t,{runWith:e=>_e(n(),e),mapResult(e){return n()?.addEvent(e.done?`closed`:`enqueued`),e},onError(e){me(n(),e)},onFinish(){n()?.end()}})}function ke(e,t,n){if(!e?.length)return n(t);let r=(t,i)=>{let a=e[i];return a?a({...t,next:(e=t)=>r(e,i+1)}):n(t)};return r(t,0)}function Ae(e){let t=e.length,n=new Map;for(let r=0;r<t;r++){let t=e[r],i=n.get(t.name);i===void 0?n.set(t.name,[r]):i.push(r)}let r=Array.from({length:t},()=>[]);for(let i=0;i<t;i++){let t=e[i];if(t.before!==void 0)for(let e of t.before){let t=n.get(e);if(t!==void 0)for(let e of t)r[e].push(i)}if(t.after!==void 0)for(let e of t.after){let t=n.get(e);if(t!==void 0)for(let e of t)r[i].push(e)}}let i=[],a=new Set;for(;i.length<t;){let t=e.findIndex((e,t)=>!a.has(t)&&r[t].every(e=>a.has(e)));if(t===-1)throw Error(`Circular dependency detected involving plugin "${je(e,r,a).name}"`);a.add(t),i.push(e[t])}return i}function je(e,t,n){let r=new Set,i=e.findIndex((e,t)=>!n.has(t));for(;!r.has(i);)r.add(i),i=t[i].find(e=>!n.has(e));return e[i]}async function Me(e,t){if(!e)return t();e.throwIfAborted();let{promise:n,reject:r,resolve:i}=Ee(),a;e.addEventListener(`abort`,a=()=>{r(e.reason),a=void 0});try{return t().then(i,r),await n}finally{a&&e.removeEventListener(`abort`,a)}}var Ne=class extends TypeError{},Pe=class extends Error{constructor(e,t={}){super(t?.message??`Error Event`,t),this.data=e}},Fe=/\r\n|[\n\r]/;function Ie(e){return Fe.test(e)}function Le(e){if(Ie(e))throw new Ne(`Event's id must not contain a carriage return or newline character`)}function Re(e){if(!Number.isInteger(e)||e<0)throw new Ne(`Event's retry must be a integer and >= 0`)}function ze(e){if(Ie(e))throw new Ne(`Event's comment must not contain a carriage return or newline character`)}var Be=Symbol.for(`STANDARD_SERVER_EVENT_META`),Ve=Symbol.for(`STANDARD_SERVER_EVENT_SOURCE`);function He(e,t){let n;if(t.id!==void 0&&(Le(t.id),n??={},n.id=t.id),t.retry!==void 0&&(Re(t.retry),n??={},n.retry=t.retry),t.comments!==void 0){for(let e of t.comments)ze(e);n??={},n.comments=t.comments}return n?new Proxy(e,{get(e,t,r){return t===Ve?e:t===Be?n:f(e,t)}}):e}function Ue(e){if(!u(e))return[e,void 0];let t=e[Be];return[e[Ve]??e,t]}function We(e){if(u(e))return e[Be]}function Ge(e,t=`inline`){return`${t}; filename="${e.replace(/[^\x20-\x7E]/g,`_`).replace(/[\\"]/g,`\\$&`)}"; filename*=utf-8''${m(e).replace(/['()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(7C|60|5E)/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}`}function Ke(e){let t=e.match(/(?:^|;)\s*filename\*=([^;]*)/i)?.[1]?.trim(),n=t?.match(/^([^']*)'[^']*'(.*)$/);if(n){let[,e=``,t=``]=n;if(/^(?:utf-8|us-ascii)$/i.test(e))return ne(t)}else if(t)return ne(t);let r=e.match(/(?:^|;)\s*filename=(?:"((?:\\.|[^"\\])*)"|([^";]*))/i);return r?.[1]===void 0?r?.[2]?.trim()||void 0:r[1].replace(/\\(.)/g,`$1`)}function qe(e){if(typeof e==`string`||e===void 0)return e;if(e.length!==0)return e.join(`, `)}function Je(e,n){let r={...e,...n};for(let i of Object.keys(n)){if(!Object.hasOwn(e,i))continue;let a=e[i],o=n[i];r[i]=a===void 0||o===void 0?a??o:[...t(a),...t(o)]}return r}function Ye(e){let t=e.indexOf(`#`),n=e.indexOf(`?`),r=n!==-1&&(t===-1||n<t),i=r?n:t===-1?e.length:t,a=t===-1?e.length:t;return[e.slice(0,i),r?e.slice(n,a):void 0,t===-1?void 0:e.slice(t)]}function Xe(e){return u(e)?Object.values(e).every(e=>e===void 0||typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`)):!1}function Ze(e){return Number.isInteger(e)}var Qe={BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,NOT_ACCEPTABLE:406,TIMEOUT:408,CONFLICT:409,GONE:410,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNSUPPORTED_MEDIA_TYPE:415,UNPROCESSABLE_CONTENT:422,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},$e,et=class e extends Error{static{let t=Symbol.for(`ORPC_ERROR_CONSTRUCTORS`);globalThis[t]??=new WeakSet,$e=globalThis[t],$e.add(e)}name=`ORPCError`;defined=!1;code;data;constructor(e,...t){let n=re(t),r=n.message??e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `);super(r,n),this.code=e,this.data=n.data}toJSON(){return{defined:this.defined,code:this.code,message:this.message,data:this.data}}static[Symbol.hasInstance](e){if(!$e.has(this))return super[Symbol.hasInstance](e);for(let t of xe(e))if($e.has(t))return!0;return!1}},tt=class extends Error{name=`MalformedResponseError`;response;constructor(e){super(e.message,e),this.response=e.response}};function nt(e){return e instanceof et?e:new et(`INTERNAL_SERVER_ERROR`,{cause:e})}function rt(e){if(!Se(e))return!1;let t=[`defined`,`code`,`message`,`data`];return!Object.keys(e).some(e=>!t.includes(e))&&`defined`in e&&typeof e.defined==`boolean`&&`code`in e&&typeof e.code==`string`&&`message`in e&&typeof e.message==`string`}function it(e,t={}){let n=new et(e.code,{...e,...t});return n.defined=e.defined,n}function at(e){let t=new et(`MALFORMED_ORPC_RESPONSE`,{message:e.message??lt(e.response),data:e.response});return t.cause=new tt({...e,message:t.message}),t}var ot=1,st=256;function ct(e){return e.length>=ot&&e.length<=st}function lt(e){return typeof e.body==`string`&&ct(e.body)?e.body:Se(e.body)&&typeof e.body.message==`string`&&ct(e.body.message)?e.body.message:(Object.entries(Qe).find(([,t])=>t===e.status)?.[0])?.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `)}function ut(e,{mapResult:t,mapError:n,...r}){return ve(e,{...r,mapResult:t&&(async e=>{let n=await t(e);if(n.value!==e.value){let t=We(e.value);if(t&&u(n.value))return{done:n.done,value:He(n.value,t)}}return n}),mapError:n&&(async e=>{let t=await n(e);if(t!==e){let n=We(e);if(n&&u(t))return He(t,n)}return t})})}function dt(e){return TypeError(`Invalid RPC serialized data: ${e}`)}function ft(e,t,n){if(!e)throw dt(`type "${t}" expects ${n}.`)}var pt={undefined:{condition(e){return e===void 0},serialize(){return null},deserialize(e){ft(e===null,`undefined`,`null`)},isTerminal:!0},bigint:{condition(e){return typeof e==`bigint`},serialize(e){return e.toString()},deserialize(e){return ft(typeof e==`string`,`bigint`,`a string`),BigInt(e)},isTerminal:!0},date:{condition(e){return e instanceof Date},serialize(e){return Number.isNaN(e.getTime())?null:e.toISOString()},deserialize(e){return ft(typeof e==`string`||e===null,`date`,`a string or null`),new Date(e??NaN)},isTerminal:!0},nan:{condition(e){return typeof e==`number`&&Number.isNaN(e)},serialize(){return null},deserialize(e){return ft(e===null,`nan`,`null`),NaN},isTerminal:!0},url:{condition(e){return e instanceof URL},serialize(e){return e.toString()},deserialize(e){return ft(typeof e==`string`,`url`,`a string`),new URL(e)},isTerminal:!0},set:{condition(e){return e instanceof Set},serialize(e){return Array.from(e)},deserialize(e){return ft(Array.isArray(e),`set`,`an array`),new Set(e)}},map:{condition(e){return e instanceof Map},serialize(e){return Array.from(e.entries())},deserialize(e){return ft(Array.isArray(e),`map`,`an array`),new Map(e)}}},mt=class{handlers;inlineBuiltInHandlers;handlerEntries;omitUndefinedProperties;constructor(e={}){this.omitUndefinedProperties=e.omitUndefinedProperties!==!1,this.handlers=Object.assign(new Te,pt);let t=e.handlers;if(t===void 0){this.inlineBuiltInHandlers=!0;return}let n=!0,r=[];for(let e of Object.keys(t)){let i=t[e];this.handlers[e]=i,n&&e in pt&&(n=!1),n&&i!==void 0&&r.push([e,i])}if(!n){r=[];for(let e of Object.keys(this.handlers)){let t=this.handlers[e];t!==void 0&&r.push([e,t])}}this.inlineBuiltInHandlers=n,this.handlerEntries=r}serialize(e){let t=[],n=[],r=[],i=this.serializeValue(e,[],t,n,r);return t=t.length===0?void 0:t,n.length===0?{json:i,meta:t}:{json:i,meta:t,maps:n,blobs:r}}serializeValue(e,t,n,r,i){if(this.inlineBuiltInHandlers)switch(typeof e){case`string`:case`boolean`:return e;case`number`:return Number.isNaN(e)?(n.push([`nan`,...t]),null):e;case`undefined`:return n.push([`undefined`,...t]),null;case`bigint`:return n.push([`bigint`,...t]),e.toString();case`object`:if(e===null)return e;if(e instanceof Date)return n.push([`date`,...t]),Number.isNaN(e.getTime())?null:e.toISOString();if(e instanceof URL)return n.push([`url`,...t]),e.toString();if(e instanceof Set){let a=this.serializeValue(Array.from(e),t,n,r,i);return n.push([`set`,...t]),a}if(e instanceof Map){let a=this.serializeValue(Array.from(e.entries()),t,n,r,i);return n.push([`map`,...t]),a}}let a=this.handlerEntries;if(a)for(let o=0;o<a.length;o++){let s=a[o],c=s[1];if(c.condition(e)){let a=c.serialize(e);if(c.isTerminal)return n.push([s[0],...t]),a instanceof Blob&&(r.push(t.slice()),i.push(a)),a;let o=this.serializeValue(a,t,n,r,i);return n.push([s[0],...t]),o}}if(e instanceof Blob)return r.push(t.slice()),i.push(e),e;if(Array.isArray(e)){let a=[];for(let o=0;o<e.length;o++)t.push(o),a.push(this.serializeValue(e[o],t,n,r,i)),t.pop();return a}if(Se(e)){let a=new Te;for(let o of Object.keys(e)){let s=e[o];(o!==`toJSON`||typeof s!=`function`)&&(s===void 0&&this.omitUndefinedProperties||(t.push(o),a[o]=this.serializeValue(s,t,n,r,i),t.pop()))}return a}return e}deserialize(e){let t={json:e.json};if(e.blobs?.length)for(let n=0;n<e.maps.length;n++){let r=e.blobs[n];if(!(r instanceof Blob))throw dt(`blob ${n} is not a Blob.`);let i=e.maps[n],a=e,o=t,s=`json`;for(let e=0;e<i.length;e++)if(a=a[s],o=we(o,s,a),s=i[e],!Object.hasOwn(o,s))throw dt(`segment "${s}" does not exist.`);o[s]=r}if(e.meta)for(let n of e.meta){let r=n[0],i=this.handlers[r];if(i===void 0)throw dt(`type "${r}" is not supported.`);let a=e,o=t,s=`json`;for(let e=1;e<n.length;e++)if(a=a[s],o=we(o,s,a),s=n[e],!Object.hasOwn(o,s))throw dt(`segment "${s}" does not exist.`);o[s]=i.deserialize(o[s])}return t.json}},ht=class{jsonSerializer;defaultSerializeOptions;constructor(e={}){this.jsonSerializer=new mt(e),this.defaultSerializeOptions=e.serialize}serialize(e,t={}){if(e===void 0||e instanceof ReadableStream||e instanceof Blob)return e;if(a(e))return ut(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.serializeValue(e.value,!1)},mapError:e=>new Pe(this.serializeValue(nt(e).toJSON(),!1),{cause:e})});let n=t.useFormDataForBlobFields??this.defaultSerializeOptions?.useFormDataForBlobFields??!0;return this.serializeValue(e,n)}serializeValue(e,t){let{json:n,meta:r,maps:i,blobs:a}=this.jsonSerializer.serialize(e);if(!t||!a?.length)return{json:n,meta:r};let o=new FormData;return o.set(`data`,c({json:n,meta:r,maps:i})),a.forEach((e,t)=>{o.set(t.toString(),e)}),o}deserialize(e){return e===void 0||e instanceof ReadableStream||e instanceof Blob?e:a(e)?ut(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.deserializeValue(e.value)},mapError:e=>{if(!(e instanceof Pe))return e;let t=this.deserializeValue(e.data);return rt(t)?it(t,{cause:e}):new Pe(t,{cause:e})}}):this.deserializeValue(e)}deserializeValue(e){if(!(e instanceof FormData))return this.jsonSerializer.deserialize(e);let t=JSON.parse(e.get(`data`)),n=[];for(let[t,r]of e)r instanceof Blob&&(n[Number(t)]=r);return this.jsonSerializer.deserialize({...t,blobs:n})}},gt=new Set([`then`,`bind`,`call`,`apply`,`valueOf`,`toString`,`toJSON`]);function _t(e){return{...e,context:e.context??{}}}function vt(e){return[e[0],_t(e[1]??{})]}function yt(e,{path:n=[],...r}={}){let i=(...i)=>{let[a,o]=vt(i);return ke([...t(r.interceptors),...t(r.scoped?.interceptors)],{...o,input:a,path:n},({path:t,input:n,...r})=>e.call(t,n,r))},a=new Map;return new Proxy(i,{get(t,i){if(typeof i!=`string`||gt.has(i))return Reflect.get(t,i);let o=a.get(i);return o===void 0&&(o=yt(e,{...r,path:[...n,i],scoped:r.scoped?.[i]}),a.set(i,o)),o}})}function bt(e,t){return new s(async()=>{for(;;){let{json:t}=await e.pull();switch(t.event){case void 0:case`message`:{let e=t.data;return u(e)&&(e=He(e,t)),{value:e,done:!1}}case`error`:throw He(new Pe(t.data),t);case`close`:{let e=t.data;return u(e)&&(e=He(e,t)),{value:e,done:!0}}}}},t)}var xt=class{constructor(e,t,n){this.iterator=e,this.messageId=t,this.send=n}isDone=!1;async cancel(){this.isDone||(this.isDone=!0,await this.iterator.return?.())}async transmit(){for(;;)try{let e=await this.iterator.next();if(this.isDone)return;e.done&&(this.isDone=!0);try{let[t,n]=Ue(e.value);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:e.done?`close`:void 0,data:t}})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){if(e instanceof Pe){if(!this.isDone){this.isDone=!0;let[t,n]=Ue(e);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:`error`,data:t.data}})}return}throw this.isDone=!0,e}}};function St(e,t){return new ReadableStream({async pull(n){try{let{json:r,binary:i}=await e.pull();i&&n.enqueue(i instanceof Uint8Array?i:new Uint8Array(await i.arrayBuffer())),r.close&&(await t({kind:`success`}),n.close())}catch(e){await t({kind:`error`,error:e}),n.error(e)}},async cancel(e){await t({kind:`cancelled`,error:e})}})}var Ct=class{constructor(e,t,n){this.messageId=t,this.send=n,this.reader=e.getReader()}isDone=!1;reader;async cancel(){this.isDone||(this.isDone=!0,await this.reader.cancel())}async transmit(){for(;;)try{let e=await this.reader.read();if(this.isDone)return;e.done&&(this.isDone=!0);try{await this.send({json:{close:e.done?!0:void 0},binary:e.value,kind:`octet-stream`,id:this.messageId})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){throw this.isDone=!0,e}}};function wt(e,t){let n=qe(e.json.headers?.[`content-type`]),r=qe(e.json.headers?.[`standard-server`]);if(e.json.body===void 0&&e.binary===void 0){if(n===void 0&&r===`event-stream`){let e=new p;return{resolveBody:async()=>bt(e,t),eventStreamMessageQueue:e}}if(n!==void 0){let e=new p;return{resolveBody:async()=>St(e,t),octetStreamMessageQueue:e}}}return{resolveBody:async()=>{let i;try{if(e.binary){if(r===`form-data`){let t={};return n!==void 0&&(t[`content-type`]=n),await new Response(e.binary,{headers:t}).formData()}let t=qe(e.json.headers?.[`content-disposition`]),i=t===void 0?void 0:Ke(t);return new File([e.binary],i??`blob`,{type:n??`application/octet-stream`})}if(r===`url-search-params`){if(typeof e.json.body!=`string`)throw TypeError(`Expected body to be a string for url-search-params bodyHint`);return new URLSearchParams(e.json.body)}return e.json.body}catch(e){throw i={value:e},e}finally{await t(i?{kind:`error`,error:i.value}:{kind:`success`})}}}}async function Tt(e,t){if(t={...t},e instanceof ReadableStream)return t[`content-type`]??=`application/octet-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof Blob)return t[`content-type`]=e.type,t[`content-disposition`]??=Ge(e instanceof File?e.name??``:`blob`),Number.isFinite(e.size)&&(t[`content-length`]=e.size.toString()),{jsonBody:void 0,headers:t,binary:e};if(t[`standard-server`]=void 0,t[`content-type`]=void 0,a(e))return t[`standard-server`]=`event-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof FormData){let n=await new Response(e).blob();return t[`standard-server`]=`form-data`,t[`content-type`]=n.type,t[`content-length`]=n.size.toString(),{jsonBody:void 0,headers:t,binary:n}}return e instanceof URLSearchParams?(t[`standard-server`]=`url-search-params`,{jsonBody:e.toString(),headers:t,binary:void 0}):{jsonBody:e,headers:t,binary:void 0}}var Et=class{constructor(e){this.send=e}idGenerator=new i;requests=new Map;request(e){return new Promise((t,n)=>{let r=e.signal;r?.throwIfAborted();let i=this.idGenerator.generate(),a={resolve:t,reject:n};if(this.requests.set(i,a),r){let e=()=>{this.abortById(i,r.reason).catch(()=>{})};r.addEventListener(`abort`,e),a.removeAbortListener=()=>r.removeEventListener(`abort`,e)}this.transmitRequest(i,a,e)})}async transmitRequest(e,t,n){try{let r=await Tt(n.body,n.headers);if(n.signal?.throwIfAborted(),this.requests.get(e)!==t)return;if(await this.send({id:e,kind:`request`,json:{method:n.method===`POST`?void 0:n.method,url:n.url,headers:l(r.headers)?r.headers:void 0,body:r.jsonBody},binary:r.binary}),a(n.body)){let r=new xt(n.body,e,this.send);this.requests.get(e)===t?(t.eventStreamTransmitter=r,await r.transmit().catch(n=>{if(t.eventStreamTransmitter)return this.abortById(e,n)})):await r.cancel()}else if(n.body instanceof ReadableStream){let r=new Ct(n.body,e,this.send);this.requests.get(e)===t?(t.octetStreamTransmitter=r,await r.transmit().catch(n=>{if(t.octetStreamTransmitter)return this.abortById(e,n)})):await r.cancel()}}catch(t){await this.closeById(e,t)}}async message(e){let t=e.id,r=this.requests.get(t);if(!r)return;if(e.kind===`stream/cancel`){let e=Promise.all([r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()]);r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,await e;return}if(e.kind===`cancel`){await this.closeById(t,new n(`Server canceled the request`));return}if(e.kind===`event-stream`){r.eventStreamMessageQueue?.push(e);return}if(e.kind===`octet-stream`){r.octetStreamMessageQueue?.push(e);return}if(!r.resolve)return;let i=r.resolve;r.resolve=void 0;try{let n=wt(e,async e=>{e.kind===`cancelled`?await this.abortById(t,e.error):(r.eventStreamMessageQueue||r.octetStreamMessageQueue)&&await this.closeById(t,e.error)});r.eventStreamMessageQueue=n.eventStreamMessageQueue,r.octetStreamMessageQueue=n.octetStreamMessageQueue,i({headers:e.json.headers??{},status:e.json.status??200,resolveBody:n.resolveBody}),r.reject=void 0,!r.eventStreamMessageQueue&&!r.octetStreamMessageQueue&&await this.closeById(t)}catch(e){await this.closeById(t,e)}}async close(e){e??=new n(`Peer was closed`),await Promise.all(Array.from(this.requests.keys()).map(t=>this.closeById(t,e)))}async closeById(e,t){let r=this.requests.get(e);if(!r)return;this.requests.delete(e),(r.reject||r.eventStreamMessageQueue||r.octetStreamMessageQueue)&&(t??=new n(`Request was closed`)),r.reject?.(t),r.resolve=void 0,r.reject=void 0,r.eventStreamMessageQueue?.close(t),r.octetStreamMessageQueue?.close(t),r.eventStreamMessageQueue=void 0,r.octetStreamMessageQueue=void 0;let i=[r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()];r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,r.removeAbortListener?.(),r.removeAbortListener=void 0,await Promise.all(i)}async abortById(e,t){let r=this.requests.get(e);if(!r)return;this.requests.delete(e),t??=new n(`Request was aborted`),r.reject?.(t),r.resolve=void 0,r.reject=void 0,r.eventStreamMessageQueue?.abort(t),r.octetStreamMessageQueue?.abort(t),r.eventStreamMessageQueue=void 0,r.octetStreamMessageQueue=void 0;let i=[this.send({id:e,kind:`cancel`}),r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()];r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,r.removeAbortListener?.(),r.removeAbortListener=void 0,await Promise.all(i)}};function Dt(e){return!(!u(e)||typeof e.id!=`string`||typeof e.kind!=`string`||e.binary!==void 0&&!(e.binary instanceof Uint8Array)&&!(e.binary instanceof Blob))}function Ot(e){return!(e.kind!==`response`||!u(e.json)||e.json.status!==void 0&&!Ze(e.json.status)||e.json.headers!==void 0&&!Xe(e.json.headers))}function kt(e){return e.kind===`cancel`&&e.json===void 0&&e.binary===void 0}function At(e){return!(e.kind!==`event-stream`||e.binary!==void 0||!u(e.json)||e.json.id!==void 0&&typeof e.json.id!=`string`||e.json.event!==void 0&&e.json.event!==`message`&&e.json.event!==`error`&&e.json.event!==`close`||e.json.retry!==void 0&&!Number.isFinite(e.json.retry)||e.json.comments!==void 0&&!(Array.isArray(e.json.comments)&&e.json.comments.every(e=>typeof e==`string`)))}function jt(e){return e.kind===`octet-stream`&&u(e.json)&&(e.json.close===void 0||typeof e.json.close==`boolean`)}function Mt(e){return e.kind===`stream/cancel`&&e.json===void 0&&e.binary===void 0}function Nt(e){return Ot(e)||kt(e)||At(e)||jt(e)||Mt(e)}var Pt=255,Ft=new TextEncoder,It=new TextDecoder;async function Lt(e,t={}){if(e.binary===void 0){let n=c(e);return t.prefix?t.prefix+n:n}let n=c({...e,binary:void 0}),r=Ft.encode(t.prefix?t.prefix+n:n),i=e.binary instanceof Blob?new Uint8Array(await e.binary.arrayBuffer()):e.binary,a=new Uint8Array(r.length+1+i.length);return a.set(r,0),a[r.length]=Pt,a.set(i,r.length+1),a}function Rt(e,t={}){try{if(typeof e==`string`){if(t.prefix){if(!e.startsWith(t.prefix))return{matched:!1};e=e.slice(t.prefix.length)}let n=JSON.parse(e);return Dt(n)?{matched:!0,message:n}:{matched:!1}}if(t.prefix){let n=Ft.encode(t.prefix);for(let t=0;t<n.length;t++)if(e[t]!==n[t])return{matched:!1};e=e.subarray(n.length)}let n=e.indexOf(Pt);if(n===-1){let t=JSON.parse(It.decode(e));return Dt(t)?{matched:!0,message:t}:{matched:!1}}let r=e.subarray(0,n),i=e.subarray(n+1),a=JSON.parse(It.decode(r));return Dt(a)?(a.binary=i,{matched:!0,message:a}):{matched:!1}}catch{return{matched:!1}}}function zt(e){let t=Object.create(null);return e.forEach((e,n)=>{Array.isArray(t[n])?t[n].push(e):t[n]===void 0?t[n]=e:t[n]=[t[n],e]}),t}var Bt=class{name=`~composite`;plugins;constructor(e=[]){this.plugins=Ae(e)}init(e){for(let t of this.plugins)t.init&&(e=t.init(e));return e}},Vt=class{constructor(e,t,n={}){this.codec=e,this.transport=t,n=new Bt(n.plugins).init(n),this.interceptors=n.interceptors,this.transportInterceptors=n.transportInterceptors}interceptors;transportInterceptors;call(e,t,n){return ge(`${ce}.${e.join(`/`)}`,r=>(r?.setAttribute(`rpc.system`,ce),r?.setAttribute(`rpc.method`,e.join(`.`)),h()&&a(t)?t=be(t,ye(`consume_async_iterator_object_input`,t)):h()&&t instanceof ReadableStream&&(t=be(t,Oe(`consume_octet_stream_input`,t))),ke(this.interceptors,{...n,path:e,input:t},async({path:e,input:t,...n})=>{let i=h(),o=i?.getActiveSpan()??r,s=await ge({name:`encode_input`,parent:o},()=>this.codec.encodeInput(t,e,n));if(o&&i?.inject){let e={...s.headers};i.inject(o,e),s={...s,headers:e}}let c=await ke(this.transportInterceptors,{...n,path:e,request:s},({path:e,request:t,...n})=>ge({name:`send_request`,parent:i?.getActiveSpan()??o},()=>this.transport.send(t,e,n))),l=await ge({name:`decode_response`,parent:o},()=>this.codec.decodeResponse(c,e,n));if(l.kind===`error`)throw l.error;let u=l.output;return h()&&a(u)?be(u,ye(`consume_async_iterator_object_output`,u)):h()&&u instanceof ReadableStream?be(u,Oe(`consume_octet_stream_output`,u)):u})))}},Ht=/\/$/,Ut=class{baseUrl;maxUrlLength;fallbackMethod;expectedMethod;headers;serializer;constructor(e){this.baseUrl=e.url??`/`,this.maxUrlLength=e.maxUrlLength??2083,this.fallbackMethod=e.fallbackMethod??`POST`,this.expectedMethod=e.method??this.fallbackMethod,this.headers=e.headers??{},this.serializer=e.serializer??new ht}async encodeInput(e,t,n){let r=Wt(await g(this.headers,n,t,e));n.lastEventId!==void 0&&(r=Je(r,{"last-event-id":n.lastEventId}));let i=await g(this.expectedMethod,n,t,e),[o,s,l]=Ye(await g(this.baseUrl,n,t,e)),u=`${o.replace(Ht,``)}${de(t)}`,d=this.serializer.serialize(e);if(i===`GET`&&!(d instanceof Blob)&&!(d instanceof ReadableStream)&&!(d instanceof FormData)&&!a(d)){let a=await g(this.maxUrlLength,n,t,e),o=new URLSearchParams(s);o.append(`data`,c(d)??``);let f=`${u}?${o}${l??``}`;if(f.length<=a)return{body:void 0,method:i,headers:r,url:f,signal:n.signal}}return{url:`${u}${s??``}${l??``}`,method:i===`GET`?this.fallbackMethod:i,headers:r,body:d,signal:n.signal}}async decodeResponse(e){let t=e.status<400,n=await e.resolveBody(),r=await(async()=>{try{return this.serializer.deserialize(n)}catch(t){throw at({message:`Invalid RPC response format.`,response:{status:e.status,headers:e.headers,body:n},cause:t})}})();return t?{kind:`output`,output:r}:rt(r)?{kind:`error`,error:it(r)}:{kind:`error`,error:at({response:{headers:e.headers,status:e.status,body:n}})}}};function Wt(e){return typeof e.forEach==`function`?zt(e):e}var Gt=0,Kt=1,qt=class{connect;reconnectEnabled;reconnectDelay;reconnectMaxAttempt;reconnectOnCloseEnabled;reconnectOnCloseDelay;encodePeerMessageOptions;decodePeerMessageOptions;constructor(e){this.connect=e.connect,this.reconnectEnabled=e.reconnect?.enabled??!1,this.reconnectDelay=e.reconnect?.delay??(e=>e.attempt===1?0:2e3),this.reconnectMaxAttempt=e.reconnect?.maxAttempt??1/0,this.reconnectOnCloseEnabled=this.reconnectEnabled&&(e.reconnect?.onClose?.enabled??!1),this.reconnectOnCloseDelay=e.reconnect?.onClose?.delay??0,this.encodePeerMessageOptions=e.encodePeerMessage,this.decodePeerMessageOptions=e.decodePeerMessage,e.connectOnInit&&this.getConnectedPeer().catch(()=>{})}async send(e,t,n){return(await Me(e.signal,()=>this.getConnectedPeer())).request(e)}totalAttempt=0;attempt=0;current;async getConnectedPeer(){let e=this.current,t=await e;if(t&&(!this.reconnectEnabled||t.websocket.readyState===Kt))return this.attempt=0,t.peer;if(e!==this.current)return this.getConnectedPeer();if(this.attempt>=this.reconnectMaxAttempt)throw new n(`WebSocket reconnect failed after ${this.attempt} attempt(s)`);return this.current=(async()=>{this.totalAttempt+=1,this.attempt+=1;let e={totalAttempt:this.totalAttempt,attempt:this.attempt};await ee(this.reconnectDelay(e));let t=await this.connect(e),i=new Et(async e=>{let n=await Lt(e,this.encodePeerMessageOptions);return t.send(n)}),a;return t.readyState===Gt&&(a=Ee(),t.addEventListener(`open`,()=>{a?.resolve()})),t.addEventListener(`message`,r(async e=>{let t=Rt(e.data instanceof Blob?await ie(e.data):ae(e.data),this.decodePeerMessageOptions);t.matched&&Nt(t.message)&&i.message(t.message)})),t.addEventListener(`close`,async e=>{a?.resolve(),this.reconnectOnCloseEnabled&&ee(this.reconnectOnCloseDelay).then(()=>this.getConnectedPeer()).catch(()=>{});let t=new n(`WebSocket closed (code ${e.code}: ${e.reason})`);await i.close(t)}),await a?.promise,a=void 0,{websocket:t,peer:i}})().catch(e=>{if(!this.reconnectEnabled)throw e}),this.getConnectedPeer()}},Jt=class extends Vt{constructor(e){let t=new Ut(e),n=new qt(e);super(t,n,e)}},Yt=class{defaultRetry;defaultRetryDelay;defaultShouldRetry;defaultOnRetry;name=`~retry`;constructor(e={}){this.defaultRetry=e.default?.retry??0,this.defaultRetryDelay=e.default?.retryDelay??(e=>e.lastEventRetry??2e3),this.defaultShouldRetry=e.default?.shouldRetry??!0,this.defaultOnRetry=e.default?.onRetry}init(e){let n=async e=>{let{next:t,...n}=e,r=await g(n.context.retry??this.defaultRetry,n),i=n.context.retryDelay??this.defaultRetryDelay,o=n.context.shouldRetry??this.defaultShouldRetry,c=n.context.onRetry??this.defaultOnRetry;if(r<=0)return t(n);let l=n.lastEventId,u,d,f=1,p=async e=>{let a=e;for(;;){let e={...n,lastEventId:l};if(a){if(f>r)throw a.error;let t={...e,attempt:f,error:a.error,lastEventRetry:u};if(!await g(o,t))throw a.error;d=c?.(t)}try{return a&&(await ee(await g(i,{...e,attempt:f,error:a.error,lastEventRetry:u}),{signal:e.signal}),f++),a=void 0,await t(e)}catch(t){if(a={error:t},e.signal?.aborted)throw t}finally{d?.(!a),d=void 0}}},te=await p();if(!a(te))return te;let m=te,ne=!1;return be(()=>m,new s(async()=>{for(;;)try{let e=await m.next(),t=We(e.value);return l=t?.id??l,u=t?.retry??u,e}catch(e){let t=We(e);l=t?.id??l,u=t?.retry??u;let n=await p({error:e});if(!a(n))throw TypeError(`RetryLinkPlugin: Expected an AsyncIteratorObject, got a different type.`);if(m=n,ne)throw await m.return?.(),e}},async({kind:e})=>{ne=!0,e===`cancelled`&&await m.return?.()}))};return{...e,interceptors:[n,...t(e.interceptors)]}}};function _(e){return Array.isArray(e)?e:e==null?[]:[e]}var Xt=class extends Error{constructor(...e){super(...e),this.name=`AbortError`}};function Zt(e){let t=Promise.resolve();return(...n)=>t=t.catch(()=>{}).then(()=>e(...n))}function Qt(e){return!e||typeof e!=`object`?!1:`next`in e&&typeof e.next==`function`&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]==`function`}var $t=Symbol.asyncDispose??Symbol.for(`asyncDispose`),en=class{isDone=!1;isExecuteComplete=!1;cleanup;next;constructor(e,t){this.cleanup=t,this.next=Zt(async()=>{if(this.isDone)return{done:!0,value:void 0};let t;try{let t=await e();return t.done&&(this.isDone=!0),t}catch(e){throw t={value:e},this.isDone=!0,e}finally{this.isDone&&!this.isExecuteComplete&&(this.isExecuteComplete=!0,await this.cleanup(t?{kind:`error`,error:t.value}:{kind:`success`}))}})}async return(e){return this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`})),{done:!0,value:e}}async throw(e){throw this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`,error:e})),e}async[$t](){this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`}))}[Symbol.asyncIterator](){return this}};function tn(e){if(e)return JSON.parse(e)}function nn(e){return JSON.stringify(e)}function rn(e){for(let t of Object.values(e))if(t!==void 0)return!0;return!1}function v(e){if(!e)return!1;let t=typeof e;return t===`object`||t===`function`}var an=new WeakMap;function on(e,t,{bind:n=!0}={}){let r=Reflect.get(e,t);if(!n||typeof r!=`function`)return r;let i=an.get(r);i||an.set(r,i=new WeakMap);let a=i.get(e);return a||i.set(e,a=r.bind(e)),a}var sn=class{items=[];pendingPulls=[];closed;push(e){if(this.closed)throw this.closed.reason;let t=this.pendingPulls.shift();t?t[0](e):this.items.push(e)}async pull(){if(this.items.length>0)return this.items.shift();if(this.closed)throw this.closed.reason;return new Promise((e,t)=>{this.pendingPulls.push([e,t])})}close(e){this.closed||(e??=new Xt(`Queue was closed.`),this.closed={reason:e},this.pendingPulls.forEach(([,t])=>t(e)),this.pendingPulls.length=0)}abort(e){e??=new Xt(`Queue was aborted.`),this.items.length=0,this.close(e)}},cn=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;function ln(e){try{return encodeURIComponent(e)}catch{return encodeURIComponent(e.replace(cn,`�`))}}function un(e){if(!e.includes(`%`))return e;try{return decodeURIComponent(e)}catch{return e}}function dn(e){return e[0]??{}}var fn=`orpc`;function pn(e){return e instanceof Error&&e.name.includes(`Abort`)}Object.getPrototypeOf(async function*(){}).constructor;function mn(e){let t;return()=>{if(t)return t.result;let n=e();return t={result:n},n}}function hn(e){try{return decodeURIComponent(e)}catch{return e}}function gn(e){return`/${e.map(encodeURIComponent).join(`/`)}`}function _n(e){let t=e.split(`/`);return t.at(0)===``&&t.shift(),gn(t.map(hn))}function vn(e,t){if(!e.startsWith(t))return!1;let n=e[t.length];return n===`/`||n===`?`||n===`#`||n===void 0||t[t.length-1]===`/`}var yn=Symbol.for(`ORPC_TRACER`);function y(){return globalThis[yn]}function bn(e){let t=y();if(t)return typeof e==`string`?t.startSpan(e):t.startSpan(e.name,e.parent)}function xn(e,t){e&&e.recordException(pn(t)?`info`:`error`,Sn(t))}function Sn(e){if(e instanceof Error){let t={message:e.message,name:e.name,stack:e.stack};return`code`in e&&(typeof e.code==`string`||typeof e.code==`number`)&&(t.code=e.code),t}return{message:String(e)}}async function b(e,t){let n=y();if(!n)return t();let r=typeof e==`string`?e:e.name,i=typeof e==`string`?void 0:e.parent;return n.startActiveSpan(r,i,async e=>{try{return await t(e)}catch(t){throw xn(e,t),t}finally{e.end()}})}function Cn(e,t){let n=y();return!e||!n?t():n.withActiveSpan(e,t)}function wn(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o;return new en(async()=>{try{let r;try{r=await t(()=>e.next()),o=r.done}catch(e){throw o=!0,e}return n?await n(r):r}catch(e){throw await i?.(e),r?await r(e):e}},async n=>{try{if(!o)try{await t(async()=>e.return?.())}catch(e){throw await i?.(e),e}}finally{await a?.()}})}function Tn(e,t){let n=mn(()=>bn(e));return wn(t,{runWith:e=>Cn(n(),e),mapResult(e){return n()?.addEvent(e.done?`completed`:`yielded`),e},onError(e){xn(n(),e)},onFinish(){n()?.end()}})}function En(e,...t){return typeof e==`function`?e(...t):e}function Dn(e,t){return new Proxy(typeof e==`function`?t:e,{get(n,r){return on(r in t?t:En(e),r)},has(n,r){return Reflect.has(t,r)||Reflect.has(En(e),r)}})}function On(e){return v(e)?Object.getPrototypeOf(e)?.constructor:null}function*kn(e){if(!v(e))return;let t=Object.getPrototypeOf(e);for(;t!=null;)t.constructor&&(yield t.constructor),t=Object.getPrototypeOf(t)}function An(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||!t||!t.constructor}function jn(e,t){return Object.hasOwn(e,t)?e[t]:void 0}function Mn(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function Nn(e,t){if(!An(e)||!An(t))return t;let n={...e,...t};for(let r in t){if(!Object.hasOwn(e,r))continue;let i=e[r],a=t[r];An(i)&&An(a)&&Mn(n,r,{...i,...a})}return n}function Pn(e,t){let n={...e};for(let e of t)delete n[e];return n}var Fn=(()=>{let e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})();function In(e,t={}){let n=new Set(t.unbound),r=new Fn,i=e;for(;i&&i!==Object.prototype;){for(let t of Object.getOwnPropertyNames(i)){if(t===`constructor`||t in r)continue;let i=on(e,t,{bind:!n.has(t)});typeof i==`function`&&(r[t]=i)}for(let t of Object.getOwnPropertySymbols(i)){if(t in r)continue;let i=on(e,t,{bind:!n.has(t)});typeof i==`function`&&(r[t]=i)}i=Object.getPrototypeOf(i)}return r}function Ln(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o=mn(()=>e.getReader()),s=mn(async()=>a?.());return new ReadableStream({async pull(e){let a;try{let e=await t(()=>o().read());a=n?await n(e):e}catch(t){try{await i?.(t),e.error(r?await r(t):t)}finally{await s()}return}a.done?(e.close(),await s()):e.enqueue(a.value)},async cancel(e){try{try{await t(()=>o().cancel(e))}catch(e){throw await i?.(e),e}}finally{await s()}}})}function Rn(e,t){let n=mn(()=>bn(e));return Ln(t,{runWith:e=>Cn(n(),e),mapResult(e){return n()?.addEvent(e.done?`closed`:`enqueued`),e},onError(e){xn(n(),e)},onFinish(){n()?.end()}})}function zn(e,t,n){if(!e?.length)return n(t);let r=(t,i)=>{let a=e[i];return a?a({...t,next:(e=t)=>r(e,i+1)}):n(t)};return r(t,0)}function Bn(e){let t=e.length,n=new Map;for(let r=0;r<t;r++){let t=e[r],i=n.get(t.name);i===void 0?n.set(t.name,[r]):i.push(r)}let r=Array.from({length:t},()=>new Set);for(let i=0;i<t;i++){let t=e[i],a=t.before;if(a!==void 0)for(let e of a){let t=n.get(e);if(t!==void 0)for(let e of t){let t=r[e];t!==void 0&&t.add(i)}}let o=t.after;if(o!==void 0){let e=r[i];if(e!==void 0)for(let t of o){let r=n.get(t);if(r!==void 0)for(let t of r)e.add(t)}}}let i=[],a=new Set,o=new Set;function s(t){if(o.has(t))return;if(a.has(t)){let n=e[t],r=n===void 0?`unknown`:n.name;throw Error(`Circular dependency detected involving plugin "${r}"`)}a.add(t);let n=r[t];if(n!==void 0)for(let e of n)s(e);a.delete(t),o.add(t);let c=e[t];c!==void 0&&i.push(c)}for(let e=0;e<t;e++)s(e);return i}var Vn=class extends TypeError{},Hn=class extends Error{constructor(e,t={}){super(t?.message??`Error Event`,t),this.data=e}},Un=/\r\n|[\n\r]/;function Wn(e){return Un.test(e)}function Gn(e){if(Wn(e))throw new Vn(`Event's id must not contain a carriage return or newline character`)}function Kn(e){if(!Number.isInteger(e)||e<0)throw new Vn(`Event's retry must be a integer and >= 0`)}function qn(e){if(Wn(e))throw new Vn(`Event's comment must not contain a carriage return or newline character`)}var Jn=Symbol.for(`STANDARD_SERVER_EVENT_META`),Yn=Symbol.for(`STANDARD_SERVER_EVENT_SOURCE`);function Xn(e,t){let n;if(t.id!==void 0&&(Gn(t.id),n??={},n.id=t.id),t.retry!==void 0&&(Kn(t.retry),n??={},n.retry=t.retry),t.comments!==void 0){for(let e of t.comments)qn(e);n??={},n.comments=t.comments}return n?new Proxy(e,{get(e,t,r){return t===Yn?e:t===Jn?n:on(e,t)}}):e}function Zn(e){if(!v(e))return[e,void 0];let t=e[Jn];return[e[Yn]??e,t]}function Qn(e){if(v(e))return e[Jn]}function $n(e,t=`inline`){return`${t}; filename="${e.replace(/[^\x20-\x7E]/g,`_`).replace(/[\\"]/g,`\\$&`)}"; filename*=utf-8''${ln(e).replace(/['()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(7C|60|5E)/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}`}function er(e){let t=e.match(/(?:^|;)\s*filename\*=([^;]*)/i)?.[1]?.trim(),n=t?.match(/^([^']*)'[^']*'(.*)$/);if(n){let[,e=``,t=``]=n;if(/^(?:utf-8|us-ascii)$/i.test(e))return un(t)}else if(t)return un(t);let r=e.match(/(?:^|;)\s*filename=(?:"((?:\\.|[^"\\])*)"|([^";]*))/i);return r?.[1]===void 0?r?.[2]?.trim()||void 0:r[1].replace(/\\(.)/g,`$1`)}function tr(e){if(typeof e==`string`||e===void 0)return e;if(e.length!==0)return e.join(`, `)}function nr(e){let t=e.indexOf(`#`),n=e.indexOf(`?`),r=n!==-1&&(t===-1||n<t),i=r?n:t===-1?e.length:t,a=t===-1?e.length:t;return[e.slice(0,i),r?e.slice(n,a):void 0,t===-1?void 0:e.slice(t)]}function rr(e){return typeof e==`string`}function ir(e){return typeof e==`string`&&e.startsWith(`/`)}function ar(e){return v(e)?Object.values(e).every(e=>e===void 0||typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`)):!1}var or={BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,NOT_ACCEPTABLE:406,TIMEOUT:408,CONFLICT:409,GONE:410,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNSUPPORTED_MEDIA_TYPE:415,UNPROCESSABLE_CONTENT:422,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},sr,x=class e extends Error{static{let t=Symbol.for(`ORPC_ERROR_CONSTRUCTORS`);globalThis[t]??=new WeakSet,sr=globalThis[t],sr.add(e)}name=`ORPCError`;defined=!1;code;data;constructor(e,...t){let n=dn(t),r=n.message??e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `);super(r,n),this.code=e,this.data=n.data}toJSON(){return{defined:this.defined,code:this.code,message:this.message,data:this.data}}static[Symbol.hasInstance](e){if(!sr.has(this))return super[Symbol.hasInstance](e);for(let t of kn(e))if(sr.has(t))return!0;return!1}};function cr(e){return e instanceof x?e:new x(`INTERNAL_SERVER_ERROR`,{cause:e})}function lr(e){if(!An(e))return!1;let t=[`defined`,`code`,`message`,`data`];return!Object.keys(e).some(e=>!t.includes(e))&&`defined`in e&&typeof e.defined==`boolean`&&`code`in e&&typeof e.code==`string`&&`message`in e&&typeof e.message==`string`}function ur(e,t={}){let n=new x(e.code,{...e,...t});return n.defined=e.defined,n}function dr(e){let t=new x(e.code,{message:e.message,data:e.data,cause:e.cause});return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)),t.stack=e.stack,t}function fr(e,{mapResult:t,mapError:n,...r}){return wn(e,{...r,mapResult:t&&(async e=>{let n=await t(e);if(n.value!==e.value){let t=Qn(e.value);if(t&&v(n.value))return{done:n.done,value:Xn(n.value,t)}}return n}),mapError:n&&(async e=>{let t=await n(e);if(t!==e){let n=Qn(e);if(n&&v(t))return Xn(t,n)}return t})})}var pr=/^\/([\s\S]*)\/([a-z]*)$/,mr={undefined:{condition(e){return e===void 0},serialize(){return null},deserialize(){},isTerminal:!0},bigint:{condition(e){return typeof e==`bigint`},serialize(e){return e.toString()},deserialize(e){return BigInt(e)},isTerminal:!0},date:{condition(e){return e instanceof Date},serialize(e){return Number.isNaN(e.getTime())?null:e.toISOString()},deserialize(e){return new Date(e??`Invalid Date`)},isTerminal:!0},nan:{condition(e){return typeof e==`number`&&Number.isNaN(e)},serialize(){return null},deserialize(){return NaN},isTerminal:!0},url:{condition(e){return e instanceof URL},serialize(e){return e.toString()},deserialize(e){return new URL(e)},isTerminal:!0},regexp:{condition(e){return e instanceof RegExp},serialize(e){return e.toString()},deserialize(e){let[,t,n]=e.match(pr);return new RegExp(t,n)},isTerminal:!0},set:{condition(e){return e instanceof Set},serialize(e){return Array.from(e)},deserialize(e){return new Set(e)}},map:{condition(e){return e instanceof Map},serialize(e){return Array.from(e.entries())},deserialize(e){return new Map(e)}}},hr=class{handlers;inlineBuiltInHandlers;handlerEntries;omitUndefinedProperties;constructor(e={}){this.omitUndefinedProperties=e.omitUndefinedProperties!==!1,this.handlers=Object.assign(new Fn,mr);let t=e.handlers;if(t===void 0){this.inlineBuiltInHandlers=!0;return}let n=!0,r=[];for(let e in t){let i=t[e];this.handlers[e]=i,n&&e in mr&&(n=!1),n&&i!==void 0&&r.push([e,i])}if(!n){r=[];for(let e in this.handlers){let t=this.handlers[e];t!==void 0&&r.push([e,t])}}this.inlineBuiltInHandlers=n,this.handlerEntries=r}serialize(e){let t=[],n=[],r=[],i=this.serializeValue(e,[],t,n,r);return t=t.length===0?void 0:t,n.length===0?{json:i,meta:t}:{json:i,meta:t,maps:n,blobs:r}}serializeValue(e,t,n,r,i){if(this.inlineBuiltInHandlers)switch(typeof e){case`string`:case`boolean`:return e;case`number`:return Number.isNaN(e)?(n.push([`nan`,...t]),null):e;case`undefined`:return n.push([`undefined`,...t]),null;case`bigint`:return n.push([`bigint`,...t]),e.toString();case`object`:if(e===null)return e;if(e instanceof Date)return n.push([`date`,...t]),Number.isNaN(e.getTime())?null:e.toISOString();if(e instanceof URL)return n.push([`url`,...t]),e.toString();if(e instanceof RegExp)return n.push([`regexp`,...t]),e.toString();if(e instanceof Set){let a=this.serializeValue(Array.from(e),t,n,r,i);return n.push([`set`,...t]),a}if(e instanceof Map){let a=this.serializeValue(Array.from(e.entries()),t,n,r,i);return n.push([`map`,...t]),a}}let a=this.handlerEntries;if(a)for(let o=0;o<a.length;o++){let s=a[o],c=s[1];if(c.condition(e)){let a=c.serialize(e);if(c.isTerminal)return n.push([s[0],...t]),a instanceof Blob&&(r.push(t.slice()),i.push(a)),a;let o=this.serializeValue(a,t,n,r,i);return n.push([s[0],...t]),o}}if(e instanceof Blob)return r.push(t.slice()),i.push(e),e;if(Array.isArray(e)){let a=[];for(let o=0;o<e.length;o++)t.push(o),a.push(this.serializeValue(e[o],t,n,r,i)),t.pop();return a}if(An(e)){let a=new Fn;for(let o in e){let s=e[o];(o!==`toJSON`||typeof s!=`function`)&&(s===void 0&&this.omitUndefinedProperties||(t.push(o),a[o]=this.serializeValue(s,t,n,r,i),t.pop()))}return a}return e}deserialize(e){let t={data:e.json};if(e.blobs?.length)for(let n=0;n<e.maps.length;n++){let r=e.maps[n],i=t,a=`data`;for(let e=0;e<r.length;e++)if(i=i[a],a=r[e],!Object.hasOwn(i,a))throw Error(`Security error: Invalid serialized data. Segment "${a}" does not exist.`);i[a]=e.blobs[n]}if(e.meta)for(let n of e.meta){let e=n[0],r=t,i=`data`;for(let e=1;e<n.length;e++)if(r=r[i],i=n[e],!Object.hasOwn(r,i))throw Error(`Security error: Invalid serialized data. Segment "${i}" does not exist.`);r[i]=this.handlers[e].deserialize(r[i])}return t.data}},gr=class{jsonSerializer;defaultSerializeOptions;constructor(e={}){this.jsonSerializer=new hr(e),this.defaultSerializeOptions=e.serialize}serialize(e,t={}){if(e===void 0||e instanceof ReadableStream||e instanceof Blob)return e;if(Qt(e))return fr(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.serializeValue(e.value,!1)},mapError:e=>new Hn(this.serializeValue(cr(e).toJSON(),!1),{cause:e})});let n=t.useFormDataForBlobFields??this.defaultSerializeOptions?.useFormDataForBlobFields??!0;return this.serializeValue(e,n)}serializeValue(e,t){let{json:n,meta:r,maps:i,blobs:a}=this.jsonSerializer.serialize(e);if(!t||!a?.length)return{json:n,meta:r};let o=new FormData;return o.set(`data`,nn({json:n,meta:r,maps:i})),a.forEach((e,t)=>{o.set(t.toString(),e)}),o}deserialize(e){return e===void 0||e instanceof ReadableStream||e instanceof Blob?e:Qt(e)?fr(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.deserializeValue(e.value)},mapError:e=>{if(!(e instanceof Hn))return e;let t=this.deserializeValue(e.data);return lr(t)?ur(t,{cause:e}):new Hn(t,{cause:e})}}):this.deserializeValue(e)}deserializeValue(e){if(!(e instanceof FormData))return this.jsonSerializer.deserialize(e);let t=JSON.parse(e.get(`data`)),n=[];for(let[t,r]of e)r instanceof Blob&&(n[Number(t)]=r);return this.jsonSerializer.deserialize({...t,blobs:n})}};function S(e,t){return{...e,...t}}async function _r(e,t){let n=jn(e,t.code);if(!n){if(!t.defined)return t;let e=dr(t);return e.defined=!1,e}if(!n.data){if(t.defined)return t;let e=dr(t);return e.defined=!0,e}let r=await n.data[`~standard`].validate(t.data);if(r.issues){if(!t.defined)return t;let e=dr(t);return e.defined=!1,e}if(t.data===r.value&&t.defined)return t;let i=dr(t);return i.data=r.value,i.defined=!0,i}function vr(e,t,n){t=_(t),n=_(n);let r=e;for(let e of n)e.init&&(r=e.init(r));let i=[...t,...n];for(let e of i)e.apply&&(r=e.apply(r));return[r,i]}var yr=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?On(t)===e||v(t)&&v(t[`~orpc`])&&v(t[`~orpc`].errorMap)&&v(t[`~orpc`].meta)&&(t[`~orpc`].inputSchemas===void 0||Array.isArray(t[`~orpc`].inputSchemas))&&(t[`~orpc`].outputSchemas===void 0||Array.isArray(t[`~orpc`].outputSchemas)):Function.prototype[Symbol.hasInstance].call(this,t)}};function br(e,t){if(e instanceof yr){let[n,r]=vr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new yr({...e[`~orpc`],errorMap:S(t.errorMap,e[`~orpc`].errorMap),meta:n,metaPlugins:r})}if(!v(e))return e;let n={};for(let r in e)n[r]=br(e[r],t);return n}var xr=class extends Error{name=`ValidationError`;issues;invalidData;constructor(e){super(e.message,e),this.issues=e.issues,this.invalidData=e.invalidData}},Sr=Symbol.for(`ORPC_HIDDEN_META_PLUGINS`);function C(e){if(v(e))return e[Sr]}var w=class e extends yr{constructor(e){super(e)}static create(){return new e({errorMap:{},meta:{}})}meta(...t){let[n,r]=vr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}input(t){let n=new e({...this[`~orpc`],inputSchemas:[..._(this[`~orpc`].inputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}output(t){let n=new e({...this[`~orpc`],outputSchemas:[..._(this[`~orpc`].outputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}router(e){return br(e,this[`~orpc`])}}.create();function Cr(e){return new Proxy(e,{get(t,n){return typeof n==`string`?(...t)=>{let r=dn(t),i=jn(e,n),a=new x(n,{message:r.message??i?.message,data:r.data,cause:r.cause});return i&&(a.defined=!0),a}:Reflect.get(t,n)}})}var wr=Symbol.for(`ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS`);function Tr(e,t){return{"~standard":{[wr]:{yieldSchema:e,returnSchema:t},vendor:fn,version:1,validate(n){return Qt(n)?{value:fr(n,{async mapResult(n){let r=n.done?t:e;if(!r)return n;let i=await r[`~standard`].validate(n.value);if(i.issues)throw new x(`ASYNC_ITERATOR_OBJECT_VALIDATION_FAILED`,{message:`AsyncIteratorObject validation failed`,cause:new xr({issues:i.issues,message:`AsyncIteratorObject validation failed`,invalidData:n.value})});return{done:n.done,value:i.value}}})}:{issues:[{message:`Expect AsyncIteratorObject`,path:[]}]}}}}}var T=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?On(t)===e||v(t)&&v(t[`~orpc`])&&v(t[`~orpc`].meta)&&(t[`~orpc`].metaPlugins===void 0||Array.isArray(t[`~orpc`].metaPlugins))&&typeof t[`~orpc`].loader==`function`:Function.prototype[Symbol.hasInstance].call(this,t)}};function E(e){return e instanceof T?e[`~orpc`].loader():Promise.resolve({default:e})}function Er(e,...t){let n=dn(t);return async(...[t,r])=>{let i=_(n.path),{default:a}=await E(e),o=r?.context??{},s=await En(n.context,o)??{},c=Cr(a[`~orpc`].errorMap),l=async e=>e instanceof x?await _r(a[`~orpc`].errorMap,e):e;try{let e=await b(`call_procedure`,e=>(e?.setAttribute(`procedure.path`,i),zn(n.interceptors,{context:s,input:t,errors:c,path:i,procedure:a,signal:r?.signal,lastEventId:r?.lastEventId},e=>Ar(e.procedure,e))));return Qt(e)?Dn(e,fr(y()?Tn(`consume_async_iterator_object_output`,e):e,{mapError:l})):y()&&e instanceof ReadableStream?Dn(e,Rn(`consume_octet_stream_output`,e)):e}catch(e){throw await l(e)}}}async function Dr(e,t,n){return b(`validate_input.${e}`,async r=>{r?.setAttribute(`input_schema.index`,e);let i=await t[`~standard`].validate(n);if(i.issues)throw new x(`BAD_REQUEST`,{message:`Input validation failed`,data:{issues:i.issues},cause:new xr({message:`Input validation failed`,issues:i.issues,invalidData:n})});return i.value})}async function Or(e,t,n){return b(`validate_output.${e}`,async r=>{r?.setAttribute(`output_schema.index`,e);let i=await t[`~standard`].validate(n);if(i.issues)throw new x(`INTERNAL_SERVER_ERROR`,{message:`Output validation failed`,cause:new xr({message:`Output validation failed`,issues:i.issues,invalidData:n})});return i.value})}var kr=(...e)=>{let t=dn(e);return{output:t.output,context:t.context??{}}};async function Ar(e,t){let n=_(e[`~orpc`].inputSchemas),r=_(e[`~orpc`].outputSchemas),i=e[`~orpc`].orderedMiddlewares,a=async(o,s,c)=>{let l=c,u=c,d=o===0?0:i[o-1].inputSchemasLengthAtUse??0,f=o===i.length?n.length:i[o].inputSchemasLengthAtUse??0;if(!e[`~orpc`].disableInputValidation){for(let e=d;e<f;e++){let r=await Dr(e,n[e],n.length>1&&An(l)?t.input:l);l=e===0?r:Nn(l,r)}u=f>0&&f<n.length?Nn(t.input,l):l}let p,ee=s;if(o<i.length){let{middleware:e}=i[o],n=await b(`middleware.${e.name}`,async n=>(n?.setAttribute(`middleware.index`,o),await e({...t,context:s,next:(...e)=>{let t=dn(e).context??{};return a(o+1,{...s,...t},l)},lastEventId:t.lastEventId},u,kr)));p=n.output,ee={...s,...n.context}}else p=await b(`handler`,()=>e[`~orpc`].handler({...t,context:s,input:l},l));let te=o===0?0:i[o-1].outputSchemasLengthAtUse??0,m=o===i.length?r.length:i[o].outputSchemasLengthAtUse??0;if(!e[`~orpc`].disableOutputValidation)for(let e=m-1;e>=te;e--)p=await Or(e,r[e],p);return{output:p,context:ee}},{output:o}=await a(0,t.context,t.input);return o}var D=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?On(t)===e||t instanceof yr&&Array.isArray(t[`~orpc`].orderedMiddlewares)&&typeof t[`~orpc`].handler==`function`:Function.prototype[Symbol.hasInstance].call(this,t)}},jr=class e extends D{meta(...t){let[n,r]=vr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}use(t){let n=new e({...this[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap,this[`~orpc`].errorMap),orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]});return t[`~orpc`]?.metaPlugins&&(n=n.meta(...t[`~orpc`]?.metaPlugins)),n}};function Mr(e,t){return new D({...e[`~orpc`],errorMap:t[`~orpc`].errorMap,meta:t[`~orpc`].meta,metaPlugins:t[`~orpc`].metaPlugins})}var Nr=Symbol.for(`ORPC_HIDDEN_ROUTER_CONTRACT`);function Pr(e,t){return new Proxy(e,{get(e,n){return n===Nr?t:Reflect.get(e,n)}})}function Fr(e){return e[Nr]}function Ir(e,t){if(e instanceof T){let[n,r]=vr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new T({meta:n,metaPlugins:r,async loader(){let{default:n}=await E(e);return E(Ir(n,t))}})}if(e instanceof D){let[n,r]=vr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new D({...Pn(t,[`middlewares`,`errorMap`,`meta`,`metaPlugins`]),...e[`~orpc`],meta:n,metaPlugins:r,errorMap:S(t.errorMap,e[`~orpc`].errorMap),orderedMiddlewares:[...t.middlewares.map(e=>({middleware:e,inputSchemasLengthAtUse:0,outputSchemasLengthAtUse:0})),...e[`~orpc`].orderedMiddlewares]})}if(!v(e))return e;let n={};for(let r in e)n[r]=Ir(e[r],t);return n}function Lr(e,t){if(e instanceof T)return new T({...e[`~orpc`],async loader(){let{default:n}=await E(e);return E(Lr(n,t))}});if(e instanceof D)return new D({...Pn(t,[`middlewares`]),...e[`~orpc`],orderedMiddlewares:[...t.middlewares.map(e=>({middleware:e,inputSchemasLengthAtUse:0,outputSchemasLengthAtUse:0})),...e[`~orpc`].orderedMiddlewares]});if(!v(e))return e;let n={};for(let r in e)n[r]=Lr(e[r],t);return n}function Rr(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e];if(!v(n)||n instanceof D)return;if(!(n instanceof T)){n=n[r];continue}let i=n,a=t.slice(e);return new T({...i[`~orpc`],async loader(){return await E(Rr((await E(i)).default,a))}})}if(v(n))return n}function zr(e,t,n=[]){let r=[];return Br(e,t,n.slice(),r),r}function Br(e,t,n,r){let i=Fr(e);if(i!==void 0&&(e=i),e instanceof yr){t(e,n.slice());return}if(v(e))for(let i in e){let a=e[i];n.push(i),a instanceof T?r.push({router:a,path:n.slice()}):Br(a,t,n,r),n.pop()}}function Vr(e){let t=((...t)=>e(...t));return t[`~orpc`]=e[`~orpc`],Object.defineProperty(t,"name",{value:e.name}),t.adaptInput=t=>{let n=Vr((n,r,...i)=>e(n,t(r),...i));return n[`~orpc`]=e[`~orpc`],Object.defineProperty(n,"name",{value:e.name}),n},t.errors=e=>{let n=Vr(t);return n[`~orpc`]={...t[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap,e)},n},t.use=n=>{let r=Vr((t,...r)=>e({...t,async next(e){let i=await n({...t,context:{...t.context,...e?.context},next(n,...r){return t.next({...t,context:{...e?.context,...n?.context}},...r)}},...r);return{...i,context:{...e?.context,...i.context}}}},...r));return r[`~orpc`]={...t[`~orpc`],errorMap:S(n[`~orpc`]?.errorMap,t[`~orpc`]?.errorMap),metaPlugins:[..._(e[`~orpc`]?.metaPlugins),..._(n[`~orpc`]?.metaPlugins)]},Object.defineProperty(r,"name",{value:`${e.name} + ${n.name}`}),r},t}(class e{"~orpc";constructor(e){this[`~orpc`]=e}static create(){return new e({errorMap:{},meta:{},orderedMiddlewares:[]})}$context(){return this}$config(t){return new e({...this[`~orpc`],...t})}meta(...t){let[n,r]=vr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}use(t){let n=new e({...this[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap??{},this[`~orpc`].errorMap),orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]});return t[`~orpc`]?.metaPlugins&&(n=n.meta(...t[`~orpc`]?.metaPlugins)),n}middleware(e){let t=[...this[`~orpc`].orderedMiddlewares.map(({middleware:e})=>e),e],n=Vr(t.shift());for(let e of t)n=n.use(e);return n[`~orpc`]={...n[`~orpc`],errorMap:this[`~orpc`].errorMap,metaPlugins:[..._(this[`~orpc`].metaPlugins),..._(e[`~orpc`]?.metaPlugins)]},n}input(t){let n=new e({...this[`~orpc`],inputSchemas:[..._(this[`~orpc`].inputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}output(t){let n=new e({...this[`~orpc`],outputSchemas:[..._(this[`~orpc`].outputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}handler(e){let t=new jr({...this[`~orpc`],handler:e}),n=C(e);return n&&(t=t.meta(...n)),t}router(e){return Ir(e,{...this[`~orpc`],middlewares:this[`~orpc`].orderedMiddlewares.map(({middleware:e})=>e)})}lazy(e){return new T({loader:async()=>{let{default:t}=await e();return{default:this.router(t)}},meta:this[`~orpc`].meta,metaPlugins:this[`~orpc`].metaPlugins})}}).create();var Hr=class e{"~orpc";constructor(e){this[`~orpc`]=e}use(t){return new e({...this[`~orpc`],orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]})}handler(e){return new Ur({...this[`~orpc`],handler:e})}},Ur=class e extends D{use(t){return new e({...this[`~orpc`],orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]})}},Wr=class e{constructor(e,t,n){this.contract=e,this.config=t,this.middlewares=n}static create(t,n,r=[]){return new e(t,n,r)}use(e){return Kr(this.contract,this.config,[...this.middlewares,e])}middleware(e){let t=[...this.middlewares,e],n=Vr(t.shift());for(let e of t)n=n.use(e);return n}router(e){return this.middlewares.length&&(e=Lr(e,{...this.config,middlewares:this.middlewares})),Pr(e,this.contract)}lazy(e){if(this.middlewares.length){let t=e;e=async()=>{let{default:e}=await t();return{default:Lr(e,{...this.config,middlewares:this.middlewares})}}}return new T({loader:e,meta:{}})}};function Gr(e,t){return Kr(e,t,[])}function Kr(e,t,n){if(e instanceof yr)return new Hr({...t,...e[`~orpc`],orderedMiddlewares:n.map(e=>({middleware:e}))});let r={};for(let i in e){let a=e[i];r[i]=Kr(a,t,n)}let i=In(Wr.create(e,t,n));for(let e in i){let t=i[e];if(e in r){let n=r[e];r[e]=new Proxy(t,{get(e,t){return Reflect.get(n,t)}})}else r[e]=t}return r}function qr(e,t={}){let n=Gr(e,t),r=new Proxy(n,{get(i,a){let o;a===`$context`?o=()=>r:a===`$config`&&(o=n=>qr(e,{...t,...n}));let s=Reflect.get(n,a);return o?v(s)?new Proxy(o,{get(e,t){return Reflect.get(s,t)}}):o:s}});return r}function Jr(e,t){return new en(async()=>{for(;;){let{json:t}=await e.pull();switch(t.event){case void 0:case`message`:{let e=t.data;return v(e)&&(e=Xn(e,t)),{value:e,done:!1}}case`error`:throw Xn(new Hn(t.data),t);case`close`:{let e=t.data;return v(e)&&(e=Xn(e,t)),{value:e,done:!0}}}}},t)}var Yr=class{constructor(e,t,n){this.iterator=e,this.messageId=t,this.send=n}isDone=!1;async cancel(){this.isDone||(this.isDone=!0,await this.iterator.return?.())}async transmit(){for(;;)try{let e=await this.iterator.next();if(this.isDone)return;e.done&&(this.isDone=!0);try{let[t,n]=Zn(e.value);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:e.done?`close`:void 0,data:t}})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){if(e instanceof Hn){if(!this.isDone){this.isDone=!0;let[t,n]=Zn(e);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:`error`,data:t.data}})}return}throw this.isDone=!0,e}}};function Xr(e,t){return new ReadableStream({async pull(n){try{let{json:r,binary:i}=await e.pull();i&&n.enqueue(i instanceof Uint8Array?i:new Uint8Array(await i.arrayBuffer())),r.close&&(await t({kind:`success`}),n.close())}catch(e){await t({kind:`error`,error:e}),n.error(e)}},async cancel(e){await t({kind:`cancelled`,error:e})}})}var Zr=class{constructor(e,t,n){this.messageId=t,this.send=n,this.reader=e.getReader()}isDone=!1;reader;async cancel(){this.isDone||(this.isDone=!0,await this.reader.cancel())}async transmit(){for(;;)try{let e=await this.reader.read();if(this.isDone)return;e.done&&(this.isDone=!0);try{await this.send({json:{close:e.done?!0:void 0},binary:e.value,kind:`octet-stream`,id:this.messageId})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){throw this.isDone=!0,e}}};function Qr(e,t){let n=tr(e.json.headers?.[`content-type`]),r=tr(e.json.headers?.[`standard-server`]);if(e.json.body===void 0&&e.binary===void 0){if(n===void 0&&r===`event-stream`){let e=new sn;return{resolveBody:async()=>Jr(e,t),eventStreamMessageQueue:e}}if(n!==void 0){let e=new sn;return{resolveBody:async()=>Xr(e,t),octetStreamMessageQueue:e}}}return{resolveBody:async()=>{let i;try{if(e.binary){if(r===`form-data`){let t={};return n!==void 0&&(t[`content-type`]=n),await new Response(e.binary,{headers:t}).formData()}let t=tr(e.json.headers?.[`content-disposition`]),i=t===void 0?void 0:er(t);return new File([e.binary],i??`blob`,{type:n??`application/octet-stream`})}if(r===`url-search-params`){if(typeof e.json.body!=`string`)throw TypeError(`Expected body to be a string for url-search-params bodyHint`);return new URLSearchParams(e.json.body)}return e.json.body}catch(e){throw i={value:e},e}finally{await t(i?{kind:`error`,error:i.value}:{kind:`success`})}}}}async function $r(e,t){if(t={...t},e instanceof ReadableStream)return t[`content-type`]??=`application/octet-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof Blob)return t[`content-type`]=e.type,t[`content-disposition`]??=$n(e instanceof File?e.name??``:`blob`),Number.isFinite(e.size)&&(t[`content-length`]=e.size.toString()),{jsonBody:void 0,headers:t,binary:e};if(t[`standard-server`]=void 0,t[`content-type`]=void 0,Qt(e))return t[`standard-server`]=`event-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof FormData){let n=await new Response(e).blob();return t[`standard-server`]=`form-data`,t[`content-type`]=n.type,t[`content-length`]=n.size.toString(),{jsonBody:void 0,headers:t,binary:n}}return e instanceof URLSearchParams?(t[`standard-server`]=`url-search-params`,{jsonBody:e.toString(),headers:t,binary:void 0}):{jsonBody:e,headers:t,binary:void 0}}function ei(e){return!(!v(e)||typeof e.id!=`string`||typeof e.kind!=`string`||e.binary!==void 0&&!(e.binary instanceof Uint8Array)&&!(e.binary instanceof Blob))}function ti(e){return e.kind!==`request`||!v(e.json)||e.json.method!==void 0&&!rr(e.json.method)||e.json.headers!==void 0&&!ar(e.json.headers)?!1:ir(e.json.url)}function ni(e){return e.kind===`cancel`&&e.json===void 0&&e.binary===void 0}function ri(e){return!(e.kind!==`event-stream`||e.binary!==void 0||!v(e.json)||e.json.id!==void 0&&typeof e.json.id!=`string`||e.json.event!==void 0&&e.json.event!==`message`&&e.json.event!==`error`&&e.json.event!==`close`||e.json.retry!==void 0&&!Number.isFinite(e.json.retry)||e.json.comments!==void 0&&!(Array.isArray(e.json.comments)&&e.json.comments.every(e=>typeof e==`string`)))}function ii(e){return e.kind===`octet-stream`&&v(e.json)&&(e.json.close===void 0||typeof e.json.close==`boolean`)}function ai(e){return ti(e)||ni(e)||ri(e)||ii(e)}var oi=255,si=new TextEncoder,ci=new TextDecoder;async function li(e,t={}){if(e.binary===void 0){let n=nn(e);return t.prefix?t.prefix+n:n}let n=nn({...e,binary:void 0}),r=si.encode(t.prefix?t.prefix+n:n),i=e.binary instanceof Blob?new Uint8Array(await e.binary.arrayBuffer()):e.binary,a=new Uint8Array(r.length+1+i.length);return a.set(r,0),a[r.length]=oi,a.set(i,r.length+1),a}function ui(e,t={}){try{if(typeof e==`string`){if(t.prefix){if(!e.startsWith(t.prefix))return{matched:!1};e=e.slice(t.prefix.length)}let n=JSON.parse(e);return ei(n)?{matched:!0,message:n}:{matched:!1}}if(t.prefix){let n=si.encode(t.prefix);for(let t=0;t<n.length;t++)if(e[t]!==n[t])return{matched:!1};e=e.subarray(n.length)}let n=e.indexOf(oi);if(n===-1){let t=JSON.parse(ci.decode(e));return ei(t)?{matched:!0,message:t}:{matched:!1}}let r=e.subarray(0,n),i=e.subarray(n+1),a=JSON.parse(ci.decode(r));return ei(a)?(a.binary=i,{matched:!0,message:a}):{matched:!1}}catch{return{matched:!1}}}var di=class extends en{"~callback";constructor(e){super(async()=>{throw Error(`Cannot use hibernating iterator directly`)},async()=>{}),this[`~callback`]=e}},fi=class{constructor(e){this.send=e}requests=new Map;async message(e,t){let n=e.id;if(e.kind===`cancel`){await this.closeById(n,new Xt(`Client aborted the request`));return}if(e.kind===`event-stream`){this.requests.get(n)?.eventStreamMessageQueue?.push(e);return}if(e.kind===`octet-stream`){this.requests.get(n)?.octetStreamMessageQueue?.push(e);return}if(this.requests.has(n))return;let r=new AbortController,i={controller:r};this.requests.set(n,i);let a=r.signal;try{let r=Qr(e,async({kind:e})=>{let t=i.eventStreamMessageQueue!==void 0||i.octetStreamMessageQueue!==void 0;i.eventStreamMessageQueue=void 0,i.octetStreamMessageQueue=void 0,e===`cancelled`&&t&&await this.send({id:n,kind:`stream/cancel`})});i.eventStreamMessageQueue=r.eventStreamMessageQueue,i.octetStreamMessageQueue=r.octetStreamMessageQueue;let o=await t({url:e.json.url,method:e.json.method??`POST`,headers:e.json.headers??{},resolveBody:r.resolveBody,signal:a});if(a.aborted)return;let s=await $r(o.body,o.headers);if(a.aborted)return;let c={id:n,kind:`response`,json:{status:o.status===200?void 0:o.status,headers:rn(s.headers)?s.headers:void 0,body:s.jsonBody},binary:s.binary};if(await this.send(c),a.aborted)return;if(Qt(o.body)){if(o.body instanceof di)try{await o.body[`~callback`]?.(n)}finally{await o.body.return()}else{let e=new Yr(o.body,n,this.send);i.eventStreamTransmitter=e,await e.transmit().catch(async e=>{i.eventStreamTransmitter&&await this.cancelById(n,e)})}}else if(o.body instanceof ReadableStream){let e=new Zr(o.body,n,this.send);i.octetStreamTransmitter=e,await e.transmit().catch(async e=>{i.octetStreamTransmitter&&await this.cancelById(n,e)})}i.controller=void 0,await this.closeById(n)}catch(e){throw await this.cancelById(n,e),e}}async close(e){e??=new Xt(`Peer was closed`),await Promise.all(Array.from(this.requests.keys()).map(t=>this.closeById(t,e)))}async closeById(e,t){let n=this.requests.get(e);if(!n)return;this.requests.delete(e),(n.controller||n.eventStreamMessageQueue||n.octetStreamMessageQueue)&&(t??=new Xt(`Request was closed`)),n.controller?.abort(t),n.controller=void 0,n.eventStreamMessageQueue?.close(t),n.octetStreamMessageQueue?.close(t),n.eventStreamMessageQueue=void 0,n.octetStreamMessageQueue=void 0;let r=[n.eventStreamTransmitter?.cancel(),n.octetStreamTransmitter?.cancel()];n.eventStreamTransmitter=void 0,n.octetStreamTransmitter=void 0,await Promise.all(r)}async cancelById(e,t){await Promise.all([this.requests.has(e)?this.send({id:e,kind:`cancel`}):void 0,this.closeById(e,t)])}};function pi(e,t,n){n?e.postMessage(t,n):e.postMessage(t)}function mi(e,t){if(`addEventListener`in e)e.addEventListener(`message`,e=>{t(e.data)});else if(`on`in e)e.on(`message`,e=>{t(e?.data)});else if(`onMessage`in e)e.onMessage.addListener(e=>{t(e)});else throw Error(`Cannot find a addEventListener/on/onMessage method on the port`)}function hi(e,t){if(`addEventListener`in e)e.addEventListener(`close`,()=>{t()});else if(`on`in e)e.on(`close`,()=>{t()});else if(`onDisconnect`in e)e.onDisconnect.addListener(()=>{t()});else throw Error(`Cannot find a addEventListener/on/onDisconnect method on the port`)}function gi(e,t){return async n=>{let r=await En(t.context??{},n),{response:i}=await e.handle(n,{...t,context:r});return i??{status:404,headers:{},body:`No procedure matched`}}}var _i=class{name=`~composite`;plugins;constructor(e=[]){this.plugins=Bn(e)}init(e){for(let t of this.plugins)t.init&&(e=t.init(e));return e}},vi=class{constructor(e,t){this.codec=e,t=new _i([new yi,..._(t.plugins)]).init(t),this.routingInterceptors=t.routingInterceptors,this.interceptors=t.interceptors,this.clientInterceptors=t.clientInterceptors}routingInterceptors;interceptors;clientInterceptors;async handle(e,{context:t,prefix:n}){return n&&!vn(e.url,n)?{matched:!1,response:void 0}:zn(this.routingInterceptors,{context:t,prefix:n,request:e},async({context:e,prefix:t,request:n})=>{let r=y()?.getActiveSpan(),i,a=await b(`find_procedure`,()=>this.codec.resolveProcedure(n,{context:e,prefix:t}));if(!a)return r?.updateName(`${fn}_no_match`),r?.setAttribute(`http.request.method`,n.method),r?.setAttribute(`url.path`,n.url),{matched:!1};let{path:o,procedure:s,decodeInput:c}=a;r?.updateName(`${fn}.${o.join(`/`)}`),r?.setAttribute(`rpc.system`,fn),r?.setAttribute(`rpc.method`,o.join(`.`));try{return{matched:!0,response:await zn(this.interceptors,{context:e,prefix:t,request:n,path:o,procedure:s,decodeInput:c},async({context:e,prefix:t,request:n,path:r,procedure:a,decodeInput:o})=>{i=`decode_input`;let s=await b(`decode_input`,o);i=void 0,y()&&Qt(s)?s=Dn(s,Tn(`consume_async_iterator_object_input`,s)):y()&&s instanceof ReadableStream&&(s=Dn(s,Rn(`consume_octet_stream_input`,s)));let c=Er(a,{context:e,path:r,interceptors:this.clientInterceptors});i=`call_procedure`;let l=await c(s,{signal:n.signal,lastEventId:tr(n.headers[`last-event-id`])});return i=void 0,await this.codec.encodeOutput(l,a,r,{context:e,prefix:t})})}}catch(n){i!==`call_procedure`&&xn(r,n);let a=i===`decode_input`&&!(n instanceof x)?new x(`BAD_REQUEST`,{message:`Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,cause:n}):cr(n);return{matched:!0,response:await this.codec.encodeError(a,s,o,{context:e,prefix:t})}}})}},yi=class{name=`~tracing`;init(e){return{...e,routingInterceptors:[async({next:e,request:t})=>{let n=y()?.extract?.(t.headers),[r]=nr(t.url);return b({name:`${t.method} ${r}`,parent:n},()=>e())},..._(e.routingInterceptors)]}}},bi=[`POST`,`PUT`,`PATCH`,`DELETE`],xi=class{filter;allowMethodsSet;allowMethodsFn;rootRouter;tree=new Map;pendingLazyRouters=new Map;constructor(e,t={}){this.filter=t.filter??!0;let n=t.allowMethods??bi;typeof n==`function`?this.allowMethodsFn=n:this.allowMethodsSet=new Set(n),this.rootRouter=e,this.index(e)}index(e,t=[]){let n=zr(e,(e,t)=>{En(this.filter,e,t)&&this.tree.set(gn(t),{path:t,contract:e,procedure:e instanceof D?e:void 0})},t);for(let e of n)this.pendingLazyRouters.set(gn(e.path),e)}async match(e,t,n){if(this.allowMethodsSet&&!this.allowMethodsSet.has(e))return;if(t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),n){if(!t.startsWith(n))return;let e=t[n.length];if(e===`/`)t=t.slice(n.length);else if(e===void 0)t=`/`;else if(n[n.length-1]===`/`)t=t.slice(n.length-1);else return}let r=this.resolvePendingLazyRouters(t);r!==void 0&&await r;let i=this.tree.get(t);if(i===void 0&&t.includes(`%`)){let e=_n(t),n=this.resolvePendingLazyRouters(e);n!==void 0&&await n,i=this.tree.get(e)}if(i===void 0)return;let a=i.procedure??await this.resolveProcedure(i);if(!this.allowMethodsFn||this.allowMethodsFn(e,a,i.path))return{path:i.path,procedure:a}}resolvePendingLazyRouters(e){if(this.pendingLazyRouters.size===0)return;let t=0;for(;t!==-1;){let n=e.indexOf(`/`,t+1),r=n===-1?e:e.slice(0,n);if(this.pendingLazyRouters.has(r))return this.loadPendingLazyRouters(e,t);t=n}}async loadPendingLazyRouters(e,t){for(;t!==-1;){let n=e.indexOf(`/`,t+1),r=n===-1?e:e.slice(0,n),i=this.pendingLazyRouters.get(r);i!==void 0&&await this.loadPendingLazyRouter(r,i),t=n}}loadPendingLazyRouter(e,t){return t.loading===void 0&&(t.loading=this.indexPendingLazyRouter(e,t).catch(e=>{throw t.loading=void 0,e})),t.loading}async indexPendingLazyRouter(e,t){let{default:n}=await E(t.router);this.index(n,t.path),this.pendingLazyRouters.delete(e)}async resolveProcedure(e){let{default:t}=await E(Rr(this.rootRouter,e.path));if(!(t instanceof D))throw TypeError(`[Contract-First] Missing or invalid implementation for procedure at path: "${e.path.join(`.`)}". Ensure the procedure is correctly implemented and matches its contract.`);return e.procedure=Mr(t,e.contract),e.procedure}},Si=class{matcher;serializer;errorStatusMap;outputStatus;constructor(e,t={}){this.matcher=new xi(e,t),this.serializer=t.serializer??new gr,this.errorStatusMap=t.errorStatusMap??or,this.outputStatus=t.outputStatus}async resolveProcedure(e,t){let[n,r]=nr(e.url),i=await this.matcher.match(e.method,n,t.prefix);if(i)return{procedure:i.procedure,path:i.path,decodeInput:async()=>{if(e.method===`GET`){let e=new URLSearchParams(r).getAll(`data`).at(-1);return this.serializer.deserialize(tn(e))}let t=await e.resolveBody();return this.serializer.deserialize(t)}}}encodeOutput(e,t,n,r){return{headers:{},status:En(this.outputStatus,e,t,n,r)??200,body:this.serializer.serialize(e)}}encodeError(e,t,n,r){return{headers:{},status:jn(this.errorStatusMap,e.code)??500,body:this.serializer.serialize(e.toJSON())}}},Ci=class{constructor(e,t={}){this.handler=e,this.transfer=t.experimental_transfer,this.encodePeerMessageOptions=t.encodePeerMessage,this.decodePeerMessageOptions=t.decodePeerMessage}peers=new WeakMap;transfer;encodePeerMessageOptions;decodePeerMessageOptions;upgrade(e,...t){mi(e,n=>this.message(e,n,...t)),hi(e,()=>this.close(e))}async message(e,t,...n){let r=this.peers.get(e);r||this.peers.set(e,r=new fi(async t=>{let n=await En(this.transfer,t,e);n?pi(e,t,n):pi(e,await li(t,this.encodePeerMessageOptions))}));let i;if(typeof t==`string`||t instanceof Uint8Array){let e=ui(t,this.decodePeerMessageOptions);e.matched&&ai(e.message)&&(i=e.message)}else ei(t)&&ai(t)&&(i=t);return i===void 0?{matched:!1}:(await r.message(i,gi(this.handler,dn(n))),{matched:!0})}async close(e){let t=this.peers.get(e);t&&(this.peers.delete(e),await t.close())}},wi=class extends Ci{constructor(e,t={}){let n=new vi(new Si(e,t),t);super(n,t)}};function Ti(e){return e?.aborted===!0}var Ei=6e4,Di=class{seq=0;buffer=[];listeners=new Set;retentionMs;constructor(e={}){this.retentionMs=e.retentionMs??Ei}publish(e){this.prune();let t=String(++this.seq),n=Xn(e,{id:t});this.buffer.push({id:t,event:n,publishedAt:Date.now()});for(let e of this.listeners)e(n)}prune(){let e=Date.now()-this.retentionMs;for(;this.buffer.length>0&&(this.buffer[0]?.publishedAt??1/0)<e;)this.buffer.shift()}async*subscribe(e={}){let{signal:t,lastEventId:n}=e;if(this.prune(),n!==void 0){let e=this.buffer.findIndex(e=>e.id===n),r=e===-1?this.buffer:this.buffer.slice(e+1);for(let e of r){if(Ti(t))return;yield e.event}}let r=[],i,a=e=>{r.push(e),i?.()};this.listeners.add(a);try{for(;;){if(Ti(t)||r.length===0&&(await new Promise(e=>{i=e,t?.addEventListener(`abort`,()=>{e()},{once:!0})}),i=void 0,Ti(t)))return;let e=r.shift();e!==void 0&&(yield e)}}finally{this.listeners.delete(a)}}},Oi;function O(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var ki=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Ai=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Oi=globalThis).__zod_globalConfig??(Oi.__zod_globalConfig={});var ji=globalThis.__zod_globalConfig;function k(e){return e&&Object.assign(ji,e),ji}function Mi(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Ni(e,t){return typeof t==`bigint`?t.toString():t}function Pi(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Fi(e){return e==null}function Ii(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Li(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}var Ri=Symbol(`evaluating`);function A(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Ri)return r===void 0&&(r=Ri,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function zi(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function j(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Bi(e){return JSON.stringify(e)}function Vi(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var Hi=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Ui(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Wi=Pi(()=>{if(ji.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Gi(e){if(Ui(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return Ui(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function Ki(e){return Gi(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var qi=new Set([`string`,`number`,`symbol`]);function Ji(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function M(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function N(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw 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 Yi(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var Xi={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Zi(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return M(e,j(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return zi(this,`shape`,e),e},checks:[]}))}function Qi(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return M(e,j(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return zi(this,`shape`,r),r},checks:[]}))}function $i(e,t){if(!Gi(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return zi(this,`shape`,n),n}}))}function ea(e,t){if(!Gi(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return zi(this,`shape`,n),n}}))}function ta(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return zi(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function na(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return M(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return zi(this,`shape`,i),i},checks:[]}))}function ra(e,t,n){return M(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return zi(this,`shape`,i),i}}))}function ia(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function aa(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function oa(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function sa(e){return typeof e==`string`?e:e?.message}function P(e,t,n){let r=e.message?e.message:sa(e.inst?._zod.def?.error?.(e))??sa(t?.error?.(e))??sa(n.customError?.(e))??sa(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function ca(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function la(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ua=(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,Ni,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},da=O(`$ZodError`,ua),fa=O(`$ZodError`,ua,{Parent:Error});function pa(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function ma(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}var ha=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new ki;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>P(e,a,k())));throw Hi(t,i?.callee),t}return o.value},ga=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>P(e,a,k())));throw Hi(t,i?.callee),t}return o.value},_a=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new ki;return a.issues.length?{success:!1,error:new(e??da)(a.issues.map(e=>P(e,i,k())))}:{success:!0,data:a.value}},va=_a(fa),ya=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>P(e,i,k())))}:{success:!0,data:a.value}},ba=ya(fa),xa=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ha(e)(t,n,i)},Sa=e=>(t,n,r)=>ha(e)(t,n,r),Ca=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ga(e)(t,n,i)},wa=e=>async(t,n,r)=>ga(e)(t,n,r),Ta=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return _a(e)(t,n,i)},Ea=e=>(t,n,r)=>_a(e)(t,n,r),Da=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ya(e)(t,n,i)},Oa=e=>async(t,n,r)=>ya(e)(t,n,r),ka=/^[cC][0-9a-z]{6,}$/,Aa=/^[0-9a-z]+$/,ja=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Ma=/^[0-9a-vA-V]{20}$/,Na=/^[A-Za-z0-9]{27}$/,Pa=/^[a-zA-Z0-9_-]{21}$/,Fa=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ia=/^([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})$/,La=e=>e?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)$/,Ra=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,za=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Ba(){return new RegExp(za,`u`)}var Va=/^(?:(?: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])$/,Ha=/^(([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}|:))$/,Ua=/^((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])$/,Wa=/^(([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])$/,Ga=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Ka=/^[A-Za-z0-9_-]*$/,qa=/^https?$/,Ja=/^\+[1-9]\d{6,14}$/,Ya=`(?:(?:\\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])))`,Xa=RegExp(`^${Ya}$`);function Za(e){let 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 Qa(e){return RegExp(`^${Za(e)}$`)}function $a(e){let t=Za({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Ya}T(?:${r})$`)}var eo=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},to=/^-?\d+$/,no=/^-?\d+(?:\.\d+)?$/,ro=/^(?:true|false)$/i,io=/^[^A-Z]*$/,ao=/^[^a-z]*$/,F=O(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),oo={number:`number`,bigint:`bigint`,object:`date`},so=O(`$ZodCheckLessThan`,(e,t)=>{F.init(e,t);let n=oo[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),co=O(`$ZodCheckGreaterThan`,(e,t)=>{F.init(e,t);let n=oo[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),lo=O(`$ZodCheckMultipleOf`,(e,t)=>{F.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):Li(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})}}),uo=O(`$ZodCheckNumberFormat`,(e,t)=>{F.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Xi[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=to)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),fo=O(`$ZodCheckMaxLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Fi(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=ca(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),po=O(`$ZodCheckMinLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Fi(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=ca(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),mo=O(`$ZodCheckLengthEquals`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Fi(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=ca(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ho=O(`$ZodCheckStringFormat`,(e,t)=>{var n,r;F.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),go=O(`$ZodCheckRegex`,(e,t)=>{ho.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})}}),_o=O(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=io,ho.init(e,t)}),vo=O(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=ao,ho.init(e,t)}),yo=O(`$ZodCheckIncludes`,(e,t)=>{F.init(e,t);let n=Ji(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),bo=O(`$ZodCheckStartsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`^${Ji(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),xo=O(`$ZodCheckEndsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`.*${Ji(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),So=O(`$ZodCheckOverwrite`,(e,t)=>{F.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),Co=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
1
|
+
var AgentCommsMeshWorker=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return Array.isArray(e)?e:e==null?[]:[e]}var n=class extends Error{constructor(...e){super(...e),this.name=`AbortError`}};function r(e){let t=Promise.resolve();return(...n)=>t=t.catch(()=>{}).then(()=>e(...n))}var i=class{index=BigInt(1);generate(){let e=this.index.toString(36);return this.index++,e}};function a(e){return!e||typeof e!=`object`?!1:`next`in e&&typeof e.next==`function`&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]==`function`}var o=Symbol.asyncDispose??Symbol.for(`Symbol.asyncDispose`),s=class{isDone=!1;isExecuteComplete=!1;cleanup;next;constructor(e,t){this.cleanup=t,this.next=r(async()=>{if(this.isDone)return{done:!0,value:void 0};let t;try{let t=await e();return this.isDone?{done:!0,value:void 0}:(t.done&&(this.isDone=!0),t)}catch(e){if(this.isDone)return{done:!0,value:void 0};throw t={value:e},this.isDone=!0,e}finally{this.isDone&&!this.isExecuteComplete&&(this.isExecuteComplete=!0,await this.cleanup(t?{kind:`error`,error:t.value}:{kind:`success`}))}})}async return(e){return this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`})),{done:!0,value:e}}async throw(e){throw this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`,error:e})),e}async[o](){this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`}))}[Symbol.asyncIterator](){return this}};function c(e){return JSON.stringify(e)}function l(e){for(let t of Object.values(e))if(t!==void 0)return!0;return!1}function u(e){if(!e)return!1;let t=typeof e;return t===`object`||t===`function`}var d=new WeakMap;function f(e,t,{bind:n=!0}={}){let r=Reflect.get(e,t);if(!n||typeof r!=`function`)return r;let i=d.get(r);i||d.set(r,i=new WeakMap);let a=i.get(e);return a||i.set(e,a=r.bind(e)),a}var p=1024,m=class{items=[];head=0;pendingPulls=[];closed;push(e){if(this.closed)throw this.closed.reason;let t=this.pendingPulls.shift();t?t[0](e):this.items.push(e)}async pull(){if(this.head<this.items.length){let e=this.items[this.head];return this.items[this.head++]=void 0,this.head>=p&&this.head*2>=this.items.length&&(this.head===this.items.length?this.items.length=0:this.items.splice(0,this.head),this.head=0),e}if(this.closed)throw this.closed.reason;return new Promise((e,t)=>{this.pendingPulls.push([e,t])})}close(e){this.closed||(e??=new n(`Queue was closed.`),this.closed={reason:e},this.pendingPulls.forEach(([,t])=>t(e)),this.pendingPulls.length=0)}abort(e){e??=new n(`Queue was aborted.`),this.items.length=0,this.head=0,this.close(e)}};function ee(e){if(e?.aborted)throw e.reason}function te(e,{signal:t}={}){return new Promise((n,r)=>{ee(t);let i=null,a=setTimeout(()=>{i&&t?.removeEventListener(`abort`,i),n()},e);t&&t.addEventListener(`abort`,i=()=>{clearTimeout(a),r(t?.reason)},{once:!0})})}var ne=/[\uD800-\uDFFF]/gu;function re(e){try{return encodeURIComponent(e)}catch{return encodeURIComponent(e.replace(ne,`�`))}}function ie(e){if(!e.includes(`%`))return e;try{return decodeURIComponent(e)}catch{return e}}function ae(e){return e[0]??{}}var oe=4300,se=/^-?(?:0|[1-9]\d*)$/;function ce(e,t){if(!((e.startsWith(`-`)?e.length-1:e.length)>t||!se.test(e)))return BigInt(e)}async function le(e){return typeof e.bytes==`function`?e.bytes():new Uint8Array(await e.arrayBuffer())}function ue(e){return typeof e==`string`?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?fe(e):e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function de(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof ArrayBuffer?new Uint8Array(e):e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function fe(e){let t=e.map(de),n=t.reduce((e,t)=>e+t.byteLength,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.byteLength;return r}function*pe(e){if(!u(e))return;let t=Object.getPrototypeOf(e);for(;t!=null;)t.constructor&&(yield t.constructor),t=Object.getPrototypeOf(t)}function me(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||!t||!t.constructor}function he(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function ge(e,t,n){let r=e[t];if(r!==n)return r;let i;if(Array.isArray(r))i=r.slice();else if(me(r))i={...r};else return r;return he(e,t,i),i}var _e=(()=>{let e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})(),ve=`orpc`;function ye(e){return e instanceof Error&&e.name.includes(`Abort`)}Object.getPrototypeOf(async function*(){}).constructor;function be(e){let t;return()=>{if(t)return t.result;let n=e();return t={result:n},n}}function xe(e){return`/${e.map(re).join(`/`)}`}var Se=Symbol.for(`ORPC_TRACER`);function Ce(){return globalThis[Se]}function we(e){let t=Ce();if(t)return typeof e==`string`?t.startSpan(e):t.startSpan(e.name,e.parent)}function Te(e,t){e&&e.recordException(ye(t)?`info`:`error`,Ee(t))}function Ee(e){if(e instanceof Error){let t={message:e.message,name:e.name,stack:e.stack};return`code`in e&&(typeof e.code==`string`||typeof e.code==`number`)&&(t.code=e.code),t}return{message:String(e)}}async function De(e,t){let n=Ce();if(!n)return t();let r=typeof e==`string`?e:e.name,i=typeof e==`string`?void 0:e.parent;return n.startActiveSpan(r,i,async e=>{try{return await t(e)}catch(t){throw Te(e,t),t}finally{e.end()}})}function Oe(e,t){let n=Ce();return!e||!n?t():n.withActiveSpan(e,t)}function ke(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o;return new s(async()=>{try{let r;try{r=await t(()=>e.next()),o=r.done}catch(e){throw o=!0,e}return n?await n(r):r}catch(e){throw await i?.(e),r?await r(e):e}},async n=>{try{if(!o)try{await t(async()=>e.return?.())}catch(e){throw await i?.(e),e}}finally{await a?.()}})}function Ae(e,t){let n=be(()=>we(e));return ke(t,{runWith:e=>Oe(n(),e),mapResult(e){return n()?.addEvent(e.done?`completed`:`yielded`),e},onError(e){Te(n(),e)},onFinish(){n()?.end()}})}function h(e,...t){return typeof e==`function`?e(...t):e}function je(e,t){return new Proxy(typeof e==`function`?t:e,{get(n,r){return f(r in t?t:h(e),r)},has(n,r){return Reflect.has(t,r)||Reflect.has(h(e),r)}})}function Me(){let e={};return e.promise=new Promise((t,n)=>{e.resolve=t,e.reject=n}),e}function Ne(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o=be(()=>e.getReader()),s=be(async()=>a?.());return new ReadableStream({async pull(e){let a;try{let e=await t(()=>o().read());a=n?await n(e):e}catch(t){try{await i?.(t),e.error(r?await r(t):t)}finally{await s()}return}a.done?(e.close(),await s()):e.enqueue(a.value)},async cancel(e){try{try{await t(()=>o().cancel(e))}catch(e){throw await i?.(e),e}}finally{await s()}}})}function Pe(e,t){let n=be(()=>we(e));return Ne(t,{runWith:e=>Oe(n(),e),mapResult(e){return n()?.addEvent(e.done?`closed`:`enqueued`),e},onError(e){Te(n(),e)},onFinish(){n()?.end()}})}function Fe(e,t,n){if(!e?.length)return n(t);let r=(t,i)=>{let a=e[i];return a?a({...t,next:(e=t)=>r(e,i+1)}):n(t)};return r(t,0)}function Ie(e){let t=e.length,n=new Map;for(let r=0;r<t;r++){let t=e[r],i=n.get(t.name);i===void 0?n.set(t.name,[r]):i.push(r)}let r=Array.from({length:t},()=>[]);for(let i=0;i<t;i++){let t=e[i];if(t.before!==void 0)for(let e of t.before){let t=n.get(e);if(t!==void 0)for(let e of t)r[e].push(i)}if(t.after!==void 0)for(let e of t.after){let t=n.get(e);if(t!==void 0)for(let e of t)r[i].push(e)}}let i=[],a=new Set;for(;i.length<t;){let t=e.findIndex((e,t)=>!a.has(t)&&r[t].every(e=>a.has(e)));if(t===-1)throw Error(`Circular dependency detected involving plugin "${Le(e,r,a).name}"`);a.add(t),i.push(e[t])}return i}function Le(e,t,n){let r=new Set,i=e.findIndex((e,t)=>!n.has(t));for(;!r.has(i);)r.add(i),i=t[i].find(e=>!n.has(e));return e[i]}async function Re(e,t){if(!e)return t();ee(e);let{promise:n,reject:r,resolve:i}=Me(),a;e.addEventListener(`abort`,a=()=>{r(e.reason),a=void 0});try{return t().then(i,r),await n}finally{a&&e.removeEventListener(`abort`,a)}}var ze=class extends TypeError{},Be=class extends Error{constructor(e,t={}){super(t?.message??`Error Event`,t),this.data=e}},Ve=/\r\n|[\n\r]/,He=/[\r\n\0]/;function Ue(e){return Ve.test(e)}function We(e){return typeof e==`string`&&!He.test(e)}function Ge(e){return Number.isInteger(e)&&e>=0}function Ke(e){return typeof e==`string`&&!Ue(e)}function qe(e){if(!We(e))throw new ze(`Event's id must not contain a carriage return, newline or NULL character`)}function Je(e){if(!Ge(e))throw new ze(`Event's retry must be a integer and >= 0`)}function Ye(e){if(!Ke(e))throw new ze(`Event's comment must not contain a carriage return or newline character`)}var Xe=Symbol.for(`STANDARD_SERVER_EVENT_META`),Ze=Symbol.for(`STANDARD_SERVER_EVENT_SOURCE`);function Qe(e,t){let n;if(t.id!==void 0&&(qe(t.id),n??={},n.id=t.id),t.retry!==void 0&&(Je(t.retry),n??={},n.retry=t.retry),t.comments!==void 0){for(let e of t.comments)Ye(e);n??={},n.comments=t.comments}return n?new Proxy(e,{get(e,t,r){return t===Ze?e:t===Xe?n:f(e,t,{bind:t!==`constructor`})}}):e}function $e(e){if(!u(e))return[e,void 0];let t=e[Xe];return[e[Ze]??e,t]}function et(e){if(u(e))return e[Xe]}var tt=/[^\x20-\x7E]|[;=]/g,nt=/[\\"]/g,rt=/\\(.)/g,it=/['()*]/g,at=/%(7C|60|5E)/g,ot=/^([^']*)'[^']*'(.*)$/,st=/^(?:utf-8|us-ascii)$/i,ct=/[\s;]*([^;=]*)(?:=\s*(?:"((?:\\.|[^"\\])*)"[^;]*|"[\s\S]*|([^;]*)))?/y;function lt(e,t=`inline`){return`${t}; filename="${e.replace(tt,`_`).replace(nt,`\\$&`)}"; filename*=utf-8''${re(e).replace(it,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`).replace(at,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}`}function ut(e,t){for(ct.lastIndex=0;ct.lastIndex<e.length;){let[,n=``,r,i]=ct.exec(e);if(n.trimEnd().toLowerCase()===t)return r===void 0?i?.trim()||void 0:r.replace(rt,`$1`)}}function dt(e){let t=ut(e,`filename*`),n=t?.match(ot);if(n){let[,e=``,t=``]=n;if(st.test(e))return ie(t)}else if(t)return ie(t);return ut(e,`filename`)}function ft(e){if(typeof e==`string`||e===void 0)return e;if(e.length!==0)return e.join(`, `)}async function pt(e,t){e instanceof ReadableStream?await e.cancel(t):a(e)&&await e.return?.()}function mt(e,n){let r={...e,...n};for(let i of Object.keys(n)){if(!Object.hasOwn(e,i))continue;let a=e[i],o=n[i];r[i]=a===void 0||o===void 0?a??o:[...t(a),...t(o)]}return r}function ht(e){let t=e.indexOf(`#`),n=e.indexOf(`?`),r=n!==-1&&(t===-1||n<t),i=r?n:t===-1?e.length:t,a=t===-1?e.length:t;return[e.slice(0,i),r?e.slice(n,a):void 0,t===-1?void 0:e.slice(t)]}function gt(e){return u(e)?Object.values(e).every(e=>e===void 0||typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`)):!1}function _t(e){return Number.isInteger(e)}var vt={BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,NOT_ACCEPTABLE:406,TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNSUPPORTED_MEDIA_TYPE:415,UNPROCESSABLE_CONTENT:422,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},yt,bt=class e extends Error{static{let t=Symbol.for(`ORPC_ERROR_CONSTRUCTORS`);globalThis[t]??=new WeakSet,yt=globalThis[t],yt.add(e)}name=`ORPCError`;defined=!1;code;data;constructor(e,...t){let n=ae(t),r=n.message??wt(e);super(r,n),this.code=e,this.data=n.data}toJSON(){return{defined:this.defined,code:this.code,message:this.message,data:this.data}}static[Symbol.hasInstance](e){if(!yt.has(this))return super[Symbol.hasInstance](e);for(let t of pe(e))if(yt.has(t))return!0;return!1}},xt=class extends Error{name=`MalformedResponseError`;response;constructor(e){super(e.message??Ct(e.response),e),this.response=e.response}},St=256;function Ct(e){let t=me(e.body)?e.body.message:e.body;if(typeof t==`string`&&t.length>0&&t.length<=St)return t;let n=Object.entries(vt).find(([,t])=>t===e.status)?.[0];return n?wt(n):`Malformed oRPC Response`}function wt(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `)}function Tt(e){return e instanceof bt?e:new bt(`INTERNAL_SERVER_ERROR`,{cause:e})}function Et(e){if(!me(e))return!1;let t=[`defined`,`code`,`message`,`data`];return!Object.keys(e).some(e=>!t.includes(e))&&`defined`in e&&typeof e.defined==`boolean`&&`code`in e&&typeof e.code==`string`&&`message`in e&&typeof e.message==`string`}function Dt(e,t={}){let n=new bt(e.code,{...e,...t});return n.defined=e.defined,n}function Ot(e,{mapResult:t,mapError:n,...r}){return ke(e,{...r,mapResult:t&&(async e=>{let n=await t(e);if(n.value!==e.value){let t=et(e.value);if(t&&u(n.value))return{done:n.done,value:Qe(n.value,t)}}return n}),mapError:n&&(async e=>{let t=await n(e);if(t!==e){let n=et(e);if(n&&u(t))return Qe(t,n)}return t})})}function g(e){return TypeError(`Invalid RPC serialized data: ${e}`)}function kt(e,t,n){if(!e)throw g(`type "${t}" expects ${n}.`)}function At(e){return Array.isArray(e)||me(e)}function jt(e,t,n,r){let i=e[t];if(!At(i)||r?.has(i))throw g(`segment "${t}" cannot be walked into.`);return i===n?ge(e,t,n):i}var Mt={undefined:{condition(e){return e===void 0},serialize(){return null},deserialize(e){kt(e===null,`undefined`,`null`)},isTerminal:!0},bigint:{condition(e){return typeof e==`bigint`},serialize(e){return e.toString()},deserialize(e){kt(typeof e==`string`,`bigint`,`a string`);let t=ce(e,oe);if(t===void 0)throw g(`type "bigint" expects a decimal integer string of at most ${oe} digits.`);return t},isTerminal:!0},date:{condition(e){return e instanceof Date},serialize(e){return Number.isNaN(e.getTime())?null:e.toISOString()},deserialize(e){return kt(typeof e==`string`||e===null,`date`,`a string or null`),new Date(e??NaN)},isTerminal:!0},nan:{condition(e){return typeof e==`number`&&Number.isNaN(e)},serialize(){return null},deserialize(e){return kt(e===null,`nan`,`null`),NaN},isTerminal:!0},infinity:{condition(e){return e===1/0||e===-1/0},serialize(e){return e>0?`Infinity`:`-Infinity`},deserialize(e){return kt(e===`Infinity`||e===`-Infinity`,`infinity`,`"Infinity" or "-Infinity"`),e===`Infinity`?1/0:-1/0},isTerminal:!0},url:{condition(e){return e instanceof URL},serialize(e){return e.toString()},deserialize(e){return kt(typeof e==`string`,`url`,`a string`),new URL(e)},isTerminal:!0},set:{condition(e){return e instanceof Set},serialize(e){return Array.from(e)},deserialize(e){return kt(Array.isArray(e),`set`,`an array`),new Set(e)}},map:{condition(e){return e instanceof Map},serialize(e){return Array.from(e.entries())},deserialize(e){return kt(Array.isArray(e),`map`,`an array`),new Map(e)}}},Nt=class{handlers;inlineBuiltInHandlers;handlerEntries;omitUndefinedProperties;constructor(e={}){this.omitUndefinedProperties=e.omitUndefinedProperties!==!1,this.handlers=Object.assign(new _e,Mt);let t=e.handlers;if(t===void 0){this.inlineBuiltInHandlers=!0;return}let n=!0,r=[];for(let e of Object.keys(t)){let i=t[e];this.handlers[e]=i,n&&e in Mt&&(n=!1),n&&i!==void 0&&r.push([e,i])}if(!n){r=[];for(let e of Object.keys(this.handlers)){let t=this.handlers[e];t!==void 0&&r.push([e,t])}}this.inlineBuiltInHandlers=n,this.handlerEntries=r}serialize(e){let t=[],n=[],r=[],i=this.serializeValue(e,[],t,n,r);return t=t.length===0?void 0:t,n.length===0?{json:i,meta:t}:{json:i,meta:t,maps:n,blobs:r}}serializeValue(e,t,n,r,i){if(this.inlineBuiltInHandlers)switch(typeof e){case`string`:case`boolean`:return e;case`number`:return Number.isFinite(e)?e:Number.isNaN(e)?(n.push([`nan`,...t]),null):(n.push([`infinity`,...t]),e>0?`Infinity`:`-Infinity`);case`undefined`:return n.push([`undefined`,...t]),null;case`bigint`:return n.push([`bigint`,...t]),e.toString();case`object`:if(e===null)return e;if(e instanceof Date)return n.push([`date`,...t]),Number.isNaN(e.getTime())?null:e.toISOString();if(e instanceof URL)return n.push([`url`,...t]),e.toString();if(e instanceof Set){let a=this.serializeValue(Array.from(e),t,n,r,i);return n.push([`set`,...t]),a}if(e instanceof Map){let a=this.serializeValue(Array.from(e.entries()),t,n,r,i);return n.push([`map`,...t]),a}}let a=this.handlerEntries;if(a)for(let o=0;o<a.length;o++){let s=a[o],c=s[1];if(c.condition(e)){let a=c.serialize(e);if(c.isTerminal)return n.push([s[0],...t]),a instanceof Blob&&(r.push(t.slice()),i.push(a)),a;let o=this.serializeValue(a,t,n,r,i);return n.push([s[0],...t]),o}}if(e instanceof Blob)return r.push(t.slice()),i.push(e),e;if(Array.isArray(e)){let a=[];for(let o=0;o<e.length;o++)t.push(o),a.push(this.serializeValue(e[o],t,n,r,i)),t.pop();return a}if(me(e)){let a=new _e;for(let o of Object.keys(e)){let s=e[o];(o!==`toJSON`||typeof s!=`function`)&&(s===void 0&&this.omitUndefinedProperties||(t.push(o),a[o]=this.serializeValue(s,t,n,r,i),t.pop()))}return a}return e}deserialize(e){let t={json:e.json};if(e.blobs?.length)for(let n=0;n<e.maps.length;n++){let r=e.blobs[n];if(!(r instanceof Blob))throw g(`blob ${n} is not a Blob.`);let i=e.maps[n],a=e,o=t,s=`json`;for(let e=0;e<i.length;e++)if(a=a[s],o=jt(o,s,a),s=i[e],!Object.hasOwn(o,s))throw g(`segment "${s}" does not exist.`);o[s]=r}let n=e.meta;if(n){let r,i=n.length===1?void 0:[],a=0;for(let o of n){let n=o[0],s=this.handlers[n];if(s===void 0)throw g(`type "${n}" is not supported.`);let c=o.length-1,l=Math.min(c,a),u=0,d=e,f=t,p=`json`;if(i!==void 0&&l>0){for(u=1;u<l&&i[3*u]===o[u];)u++;if(f=i[3*u-2],d=i[3*u-1],p=o[u],!Object.hasOwn(f,p))throw g(`segment "${p}" does not exist.`)}for(;u<c;)if(d=d[p],f=jt(f,p,d,r),i!==void 0&&(i[3*u]=p,i[3*u+1]=f,i[3*u+2]=d),p=o[++u],!Object.hasOwn(f,p))throw g(`segment "${p}" does not exist.`);a=c;let m=s.deserialize(f[p]);f[p]=m,At(m)&&(r??=new Set).add(m)}}return t.json}},Pt=class{jsonSerializer;defaultSerializeOptions;constructor(e={}){this.jsonSerializer=new Nt(e),this.defaultSerializeOptions=e.serialize}serialize(e,t={}){if(e===void 0||e instanceof ReadableStream||e instanceof Blob)return e;if(a(e))return Ot(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.serializeValue(e.value,!1)},mapError:e=>new Be(this.serializeValue(Tt(e).toJSON(),!1),{cause:e})});let n=t.useFormDataForBlobFields??this.defaultSerializeOptions?.useFormDataForBlobFields??!0;return this.serializeValue(e,n)}serializeValue(e,t){let{json:n,meta:r,maps:i,blobs:a}=this.jsonSerializer.serialize(e);if(!t||!a?.length)return{json:n,meta:r};let o=new FormData;return o.set(`data`,c({json:n,meta:r,maps:i})),a.forEach((e,t)=>{o.set(t.toString(),e)}),o}deserialize(e){return e===void 0||e instanceof ReadableStream||e instanceof Blob?e:a(e)?Ot(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.deserializeValue(e.value)},mapError:e=>{if(!(e instanceof Be))return e;let t=this.deserializeValue(e.data);return Et(t)?Dt(t,{cause:e}):new Be(t,{cause:e})}}):this.deserializeValue(e)}deserializeValue(e){if(!(e instanceof FormData))return this.jsonSerializer.deserialize(e);let t=JSON.parse(e.get(`data`)),n=[];for(let[t,r]of e)r instanceof Blob&&(n[Number(t)]=r);return this.jsonSerializer.deserialize({...t,blobs:n})}},Ft=new Set([`then`,`bind`,`call`,`apply`,`valueOf`,`toString`,`toJSON`]);function It(e){return{...e,context:e.context??{}}}function Lt(e){return[e[0],It(e[1]??{})]}function Rt(e,{path:n=[],...r}={}){let i=(...i)=>{let[a,o]=Lt(i);return Fe([...t(r.interceptors),...t(r.scoped?.interceptors)],{...o,input:a,path:n},({path:t,input:n,...r})=>e.call(t,n,r))},a=new Map;return new Proxy(i,{get(t,i){if(typeof i!=`string`||Ft.has(i))return Reflect.get(t,i);let o=a.get(i);return o===void 0&&(o=Rt(e,{...r,path:[...n,i],scoped:r.scoped?.[i]}),a.set(i,o)),o}})}function zt(e,t){return new s(async()=>{for(;;){let{json:t}=await e.pull();switch(t.event){case void 0:case`message`:{let e=t.data;return u(e)&&(e=Qe(e,t)),{value:e,done:!1}}case`error`:throw Qe(new Be(t.data),t);case`close`:{let e=t.data;return u(e)&&(e=Qe(e,t)),{value:e,done:!0}}}}},t)}var Bt=class{constructor(e,t,n){this.iterator=e,this.messageId=t,this.send=n}isDone=!1;async cancel(){this.isDone||(this.isDone=!0,await this.iterator.return?.())}async transmit(){for(;;)try{let e=await this.iterator.next();if(this.isDone)return;e.done&&(this.isDone=!0);try{let[t,n]=$e(e.value);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:e.done?`close`:void 0,data:t}})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){if(e instanceof Be){if(!this.isDone){this.isDone=!0;let[t,n]=$e(e);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:`error`,data:t.data}})}return}throw this.isDone=!0,e}}};function Vt(e,t){return new ReadableStream({async pull(n){try{let r;do r=await e.pull();while(!r.binary&&!r.json.close);let{json:i,binary:a}=r;a&&n.enqueue(a instanceof Uint8Array?a:new Uint8Array(await a.arrayBuffer())),i.close&&(await t({kind:`success`}),n.close())}catch(e){await t({kind:`error`,error:e}),n.error(e)}},async cancel(e){await t({kind:`cancelled`,error:e})}})}function Ht(e){return e.byteLength===e.buffer.byteLength?e:new Uint8Array(e)}var Ut=class{constructor(e,t,n){this.messageId=t,this.send=n,this.reader=e.getReader()}isDone=!1;reader;async cancel(){this.isDone||(this.isDone=!0,await this.reader.cancel())}async transmit(){for(;;)try{let e=await this.reader.read();if(this.isDone)return;e.done&&(this.isDone=!0);try{await this.send({json:{close:e.done?!0:void 0},binary:e.value&&Ht(e.value),kind:`octet-stream`,id:this.messageId})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){throw this.isDone=!0,e}}};function Wt(e,t){let n=e.json.headers?.[`content-type`],r=ft(n),i=ft(e.json.headers?.[`standard-server`]);if(e.json.body===void 0&&e.binary===void 0){if(n===void 0&&i===`event-stream`){let e=new m;return{resolveBody:Gt(()=>zt(e,t)),eventStreamMessageQueue:e}}if(n!==void 0){let e=new m;return{resolveBody:Gt(()=>Vt(e,t)),octetStreamMessageQueue:e}}}return{resolveBody:async()=>{let n;try{if(e.binary){if(i===`form-data`){let t={};return r!==void 0&&(t[`content-type`]=r),await new Response(e.binary,{headers:t}).formData()}let t=ft(e.json.headers?.[`content-disposition`]),n=t===void 0?void 0:dt(t);return new File([e.binary],n??`blob`,{type:r??`application/octet-stream`})}if(i===`url-search-params`){if(typeof e.json.body!=`string`)throw TypeError(`Expected body to be a string for url-search-params bodyHint`);return new URLSearchParams(e.json.body)}return e.json.body}catch(e){throw n={value:e},e}finally{await t(n?{kind:`error`,error:n.value}:{kind:`success`})}}}}function Gt(e){let t=!1;return async()=>{if(t)throw TypeError(`Failed to read body: body stream already read`);return t=!0,e()}}async function Kt(e,t){if(t={...t},e instanceof ReadableStream)return t[`content-type`]??=`application/octet-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof Blob)return t[`content-type`]??=e.type,t[`content-disposition`]??=lt(e instanceof File?e.name??``:`blob`),Number.isFinite(e.size)&&(t[`content-length`]=e.size.toString()),{jsonBody:void 0,headers:t,binary:e};if(t[`standard-server`]=void 0,t[`content-type`]=void 0,a(e))return t[`standard-server`]=`event-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof FormData){let n=await new Response(e).blob();return t[`standard-server`]=`form-data`,t[`content-type`]=n.type,t[`content-length`]=n.size.toString(),{jsonBody:void 0,headers:t,binary:n}}return e instanceof URLSearchParams?(t[`standard-server`]=`url-search-params`,{jsonBody:e.toString(),headers:t,binary:void 0}):{jsonBody:e,headers:t,binary:void 0}}var qt=class{constructor(e){this.send=e}idGenerator=new i;requests=new Map;request(e){return new Promise((t,n)=>{let r=e.signal,i=this.idGenerator.generate(),a={resolve:t,reject:n};if(this.requests.set(i,a),r){let e=()=>{this.abortById(i,r.reason).catch(()=>{})};r.addEventListener(`abort`,e),a.removeAbortListener=()=>r.removeEventListener(`abort`,e)}this.transmitRequest(i,a,e).catch(()=>{})})}async transmitRequest(e,t,n){let r=n.body,i;try{ee(n.signal);let i=await Kt(n.body,n.headers);if(ee(n.signal),this.requests.get(e)!==t)return;if(await this.send({id:e,kind:`request`,json:{method:n.method===`POST`?void 0:n.method,url:n.url,headers:l(i.headers)?i.headers:void 0,body:i.jsonBody},binary:i.binary}),t.requestSent=!0,this.requests.get(e)!==t){n.signal?.aborted&&await this.send({id:e,kind:`cancel`});return}if(t.streamCancelled)return;if(r=void 0,a(n.body)){let r=new Bt(n.body,e,this.send);t.eventStreamTransmitter=r,await r.transmit()}else if(n.body instanceof ReadableStream){let r=new Ut(n.body,e,this.send);t.octetStreamTransmitter=r,await r.transmit()}}catch(n){i=n,t.requestSent?t.streamCancelled||await this.abortById(e,n):await this.closeById(e,n)}finally{r!==void 0&&await pt(r,i??n.signal?.reason).catch(()=>{})}}async message(e){let t=e.id,r=this.requests.get(t);if(!r)return;if(e.kind===`stream/cancel`){r.streamCancelled=!0;let e=Promise.all([r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()]);r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,await e;return}if(e.kind===`cancel`){await this.closeById(t,new n(`Server canceled the request`));return}if(e.kind===`event-stream`){let n=r.eventStreamMessageQueue;n?.push(e),n&&(e.json.event===`close`||e.json.event===`error`)&&await this.closeById(t);return}if(e.kind===`octet-stream`){let n=r.octetStreamMessageQueue;n?.push(e),n&&e.json.close&&await this.closeById(t);return}if(!r.resolve)return;let i=r.resolve;r.resolve=void 0;try{let n=Wt(e,async e=>{e.kind===`cancelled`?await this.abortById(t,e.error):(r.eventStreamMessageQueue||r.octetStreamMessageQueue)&&await this.closeById(t,e.error)});r.eventStreamMessageQueue=n.eventStreamMessageQueue,r.octetStreamMessageQueue=n.octetStreamMessageQueue,i({headers:e.json.headers??{},status:e.json.status??200,resolveBody:n.resolveBody}),r.reject=void 0,!r.eventStreamMessageQueue&&!r.octetStreamMessageQueue&&await this.closeById(t)}catch(e){await this.closeById(t,e)}}async close(e){e??=new n(`Peer was closed`),await Promise.all(Array.from(this.requests.keys()).map(t=>this.closeById(t,e)))}async closeById(e,t){let r=this.requests.get(e);if(!r)return;this.requests.delete(e),(r.reject||r.eventStreamMessageQueue||r.octetStreamMessageQueue)&&(t??=new n(`Request was closed`)),r.reject?.(t),r.resolve=void 0,r.reject=void 0,r.eventStreamMessageQueue?.close(t),r.octetStreamMessageQueue?.close(t),r.eventStreamMessageQueue=void 0,r.octetStreamMessageQueue=void 0;let i=[r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()];r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,r.removeAbortListener?.(),r.removeAbortListener=void 0,await Promise.all(i)}async abortById(e,t){let r=this.requests.get(e);if(!r)return;this.requests.delete(e),t??=new n(`Request was aborted`),r.reject?.(t),r.resolve=void 0,r.reject=void 0,r.eventStreamMessageQueue?.abort(t),r.octetStreamMessageQueue?.abort(t),r.eventStreamMessageQueue=void 0,r.octetStreamMessageQueue=void 0;let i=[r.requestSent?this.send({id:e,kind:`cancel`}):void 0,r.eventStreamTransmitter?.cancel(),r.octetStreamTransmitter?.cancel()];r.eventStreamTransmitter=void 0,r.octetStreamTransmitter=void 0,r.removeAbortListener?.(),r.removeAbortListener=void 0,await Promise.all(i)}};function Jt(e){return!(!u(e)||typeof e.id!=`string`||typeof e.kind!=`string`||e.binary!==void 0&&!(e.binary instanceof Uint8Array)&&!(e.binary instanceof Blob))}function Yt(e){return!(e.kind!==`response`||!u(e.json)||e.json.status!==void 0&&!_t(e.json.status)||e.json.headers!==void 0&&!gt(e.json.headers))}function Xt(e){return e.kind===`cancel`&&e.json===void 0&&e.binary===void 0}function Zt(e){return!(e.kind!==`event-stream`||e.binary!==void 0||!u(e.json)||e.json.id!==void 0&&!We(e.json.id)||e.json.event!==void 0&&e.json.event!==`message`&&e.json.event!==`error`&&e.json.event!==`close`||e.json.retry!==void 0&&!Ge(e.json.retry)||e.json.comments!==void 0&&!(Array.isArray(e.json.comments)&&e.json.comments.every(Ke)))}function Qt(e){return e.kind===`octet-stream`&&u(e.json)&&(e.json.close===void 0||typeof e.json.close==`boolean`)}function $t(e){return e.kind===`stream/cancel`&&e.json===void 0&&e.binary===void 0}function en(e){return Yt(e)||Xt(e)||Zt(e)||Qt(e)||$t(e)}var tn=255,nn=new TextEncoder,rn=new TextDecoder;async function an(e,t={}){if(e.binary===void 0){let n=c(e);return t.prefix?t.prefix+n:n}let n=c({...e,binary:void 0}),r=nn.encode(t.prefix?t.prefix+n:n),i=e.binary instanceof Blob?new Uint8Array(await e.binary.arrayBuffer()):e.binary,a=new Uint8Array(r.length+1+i.length);return a.set(r,0),a[r.length]=tn,a.set(i,r.length+1),a}function on(e,t={}){try{if(typeof e==`string`){if(t.prefix){if(!e.startsWith(t.prefix))return{matched:!1};e=e.slice(t.prefix.length)}let n=JSON.parse(e);return Jt(n)?{matched:!0,message:n}:{matched:!1}}if(t.prefix){let n=nn.encode(t.prefix);for(let t=0;t<n.length;t++)if(e[t]!==n[t])return{matched:!1};e=e.subarray(n.length)}let n=e.indexOf(tn);if(n===-1){let t=JSON.parse(rn.decode(e));return Jt(t)?{matched:!0,message:t}:{matched:!1}}let r=e.subarray(0,n),i=e.subarray(n+1),a=JSON.parse(rn.decode(r));return Jt(a)?(a.binary=i,{matched:!0,message:a}):{matched:!1}}catch{return{matched:!1}}}function sn(e){let t=Object.create(null);return e.forEach((e,n)=>{Array.isArray(t[n])?t[n].push(e):t[n]===void 0?t[n]=e:t[n]=[t[n],e]}),t}var cn=class{name=`~composite`;plugins;constructor(e=[]){this.plugins=Ie(e)}init(e){for(let t of this.plugins)t.init&&(e=t.init(e));return e}},ln=class{constructor(e,t,n={}){this.codec=e,this.transport=t,n=new cn(n.plugins).init(n),this.interceptors=n.interceptors,this.transportInterceptors=n.transportInterceptors}interceptors;transportInterceptors;call(e,t,n){return De(`${ve}.${e.join(`/`)}`,r=>(r?.setAttribute(`rpc.system`,ve),r?.setAttribute(`rpc.method`,e.join(`.`)),Ce()&&a(t)?t=je(t,Ae(`consume_async_iterator_object_input`,t)):Ce()&&t instanceof ReadableStream&&(t=je(t,Pe(`consume_octet_stream_input`,t))),Fe(this.interceptors,{...n,path:e,input:t},async({path:e,input:t,...n})=>{let i=Ce(),o=i?.getActiveSpan()??r,s=await De({name:`encode_input`,parent:o},()=>this.codec.encodeInput(t,e,n));if(o&&i?.inject){let e={...s.headers};i.inject(o,e),s={...s,headers:e}}let c=await Fe(this.transportInterceptors,{...n,path:e,request:s},({path:e,request:t,...n})=>De({name:`send_request`,parent:i?.getActiveSpan()??o},()=>this.transport.send(t,e,n))),l=await De({name:`decode_response`,parent:o},()=>this.codec.decodeResponse(c,e,n));if(l.kind===`error`)throw l.error;let u=l.output;return Ce()&&a(u)?je(u,Ae(`consume_async_iterator_object_output`,u)):Ce()&&u instanceof ReadableStream?je(u,Pe(`consume_octet_stream_output`,u)):u})))}},un=/\/$/,dn=class{baseUrl;maxUrlLength;fallbackMethod;expectedMethod;headers;serializer;constructor(e){this.baseUrl=e.url??`/`,this.maxUrlLength=e.maxUrlLength??2083,this.fallbackMethod=e.fallbackMethod??`POST`,this.expectedMethod=e.method??this.fallbackMethod,this.headers=e.headers??{},this.serializer=e.serializer??new Pt}async encodeInput(e,t,n){let r=fn(await h(this.headers,n,t,e));n.lastEventId!==void 0&&(r=mt(r,{"last-event-id":n.lastEventId}));let i=await h(this.expectedMethod,n,t,e),[o,s,l]=ht(await h(this.baseUrl,n,t,e)),u=`${o.replace(un,``)}${xe(t)}`,d=this.serializer.serialize(e);if(i===`GET`&&!(d instanceof Blob)&&!(d instanceof ReadableStream)&&!(d instanceof FormData)&&!a(d)){let a=await h(this.maxUrlLength,n,t,e),o=new URLSearchParams(s);o.append(`data`,c(d)??``);let f=`${u}?${o}${l??``}`;if(f.length<=a)return{body:void 0,method:i,headers:r,url:f,signal:n.signal}}return{url:`${u}${s??``}${l??``}`,method:i===`GET`?this.fallbackMethod:i,headers:r,body:d,signal:n.signal}}async decodeResponse(e){let t=e.status<400,n=await e.resolveBody(),r=await(async()=>{try{return this.serializer.deserialize(n)}catch(t){throw new xt({message:`Invalid RPC response format.`,response:{status:e.status,headers:e.headers,body:n},cause:t})}})();if(!t){if(Et(r))return{kind:`error`,error:Dt(r)};throw new xt({response:{headers:e.headers,status:e.status,body:n}})}return{kind:`output`,output:r}}};function fn(e){return typeof e.forEach==`function`?sn(e):e}var pn=0,mn=1,hn=class{connect;reconnectEnabled;reconnectDelay;reconnectMaxAttempt;reconnectMaxTotalAttempt;reconnectOnCloseEnabled;reconnectOnCloseDelay;encodePeerMessageOptions;decodePeerMessageOptions;constructor(e){this.connect=e.connect,this.reconnectEnabled=e.reconnect?.enabled??!1,this.reconnectDelay=e.reconnect?.delay??(e=>e.attempt===1?0:2e3),this.reconnectMaxAttempt=e.reconnect?.maxAttempt??1/0,this.reconnectMaxTotalAttempt=e.reconnect?.maxTotalAttempt??1/0,this.reconnectOnCloseEnabled=this.reconnectEnabled&&(e.reconnect?.onClose?.enabled??!1),this.reconnectOnCloseDelay=e.reconnect?.onClose?.delay??0,this.encodePeerMessageOptions=e.encodePeerMessage,this.decodePeerMessageOptions=e.decodePeerMessage,e.connectOnInit&&this.getConnectedPeer().catch(()=>{})}async send(e,t,n){return(await Re(e.signal,()=>this.getConnectedPeer())).request(e)}totalAttempt=0;attempt=0;current;async getConnectedPeer(){let e=this.current,t=await e;if(t&&(!this.reconnectEnabled||t.websocket.readyState===mn))return t.peer;if(e!==this.current)return this.getConnectedPeer();if(this.totalAttempt>=this.reconnectMaxTotalAttempt)throw new n(`WebSocket reconnect stopped after ${this.totalAttempt} total attempt(s)`);return this.current=(async()=>{this.totalAttempt+=1,this.attempt+=1;let e={totalAttempt:this.totalAttempt,attempt:this.attempt};await te(this.reconnectDelay(e));let t=await this.connect(e);if(t.readyState!==pn&&t.readyState!==mn)throw new n(`WebSocket is already closing or closed`);let i,a=new qt(async e=>{if(i)throw i;let n=await an(e,this.encodePeerMessageOptions);return t.send(n)}),o;if(t.readyState===pn&&(o=Me(),t.addEventListener(`open`,()=>{o?.resolve()})),t.addEventListener(`message`,r(async e=>{let t=on(e.data instanceof Blob?await le(e.data):ue(e.data),this.decodePeerMessageOptions);t.matched&&en(t.message)&&a.message(t.message)})),t.addEventListener(`close`,async e=>{i=new n(`WebSocket closed (code ${e.code}: ${e.reason})`),o?.resolve(),await a.close(i)}),t.addEventListener(`error`,()=>{}),await o?.promise,i)throw i;return this.reconnectOnCloseEnabled&&t.addEventListener(`close`,()=>{te(this.reconnectOnCloseDelay).then(()=>this.getConnectedPeer()).catch(()=>{})}),this.attempt=0,{websocket:t,peer:a}})().catch(e=>{if(!this.reconnectEnabled)throw e;if(this.attempt>=this.reconnectMaxAttempt){let t=this.attempt;throw this.attempt=0,this.current=void 0,new n(`WebSocket reconnect failed after ${t} attempt(s)`,{cause:e})}}),this.getConnectedPeer()}},gn=class extends ln{constructor(e){let t=new dn(e),n=new hn(e);super(t,n,e)}},_n=class{defaultRetry;defaultRetryDelay;defaultShouldRetry;defaultOnRetry;name=`~retry`;constructor(e={}){this.defaultRetry=e.default?.retry??0,this.defaultRetryDelay=e.default?.retryDelay??(e=>e.lastEventRetry??2e3),this.defaultShouldRetry=e.default?.shouldRetry??!0,this.defaultOnRetry=e.default?.onRetry}init(e){let n=async e=>{let{next:t,...n}=e,r=await h(n.context.retry??this.defaultRetry,n),i=n.context.retryDelay??this.defaultRetryDelay,o=n.context.shouldRetry??this.defaultShouldRetry,c=n.context.onRetry??this.defaultOnRetry;if(r<=0)return t(n);let l=n.lastEventId,u,d,f=1,p=!1,m=async e=>{let a=e;for(;;){let e={...n,lastEventId:l},s=0;if(a){if(p||f>r)throw a.error;let t={...e,attempt:f,error:a.error,lastEventRetry:u};if(!await h(o,t))throw a.error;s=await h(i,t),d=c?.(t)}try{if(a){if(await te(s,{signal:e.signal}),p)throw a.error;f++}return a=void 0,await t(e)}catch(t){if(a={error:t},e.signal?.aborted)throw t}finally{d?.(!a),d=void 0}}},ee=await m();if(!a(ee))return ee;let ne=ee;return je(()=>ne,new s(async()=>{for(;;)try{let e=await ne.next(),t=et(e.value);return l=t?.id??l,u=t?.retry??u,e}catch(e){let t=et(e);l=t?.id??l,u=t?.retry??u;let n=await m({error:e});if(!a(n))throw TypeError(`RetryLinkPlugin: Expected an AsyncIteratorObject, got a different type.`);if(ne=n,p)throw await ne.return?.(),e}},async({kind:e})=>{p=!0,e===`cancelled`&&await ne.return?.()}))};return{...e,interceptors:[n,...t(e.interceptors)]}}};function _(e){return Array.isArray(e)?e:e==null?[]:[e]}var vn=class extends Error{constructor(...e){super(...e),this.name=`AbortError`}};function yn(e){let t=Promise.resolve();return(...n)=>t=t.catch(()=>{}).then(()=>e(...n))}function bn(e){return!e||typeof e!=`object`?!1:`next`in e&&typeof e.next==`function`&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]==`function`}var xn=Symbol.asyncDispose??Symbol.for(`asyncDispose`),Sn=class{isDone=!1;isExecuteComplete=!1;cleanup;next;constructor(e,t){this.cleanup=t,this.next=yn(async()=>{if(this.isDone)return{done:!0,value:void 0};let t;try{let t=await e();return t.done&&(this.isDone=!0),t}catch(e){throw t={value:e},this.isDone=!0,e}finally{this.isDone&&!this.isExecuteComplete&&(this.isExecuteComplete=!0,await this.cleanup(t?{kind:`error`,error:t.value}:{kind:`success`}))}})}async return(e){return this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`})),{done:!0,value:e}}async throw(e){throw this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`,error:e})),e}async[xn](){this.isDone=!0,this.isExecuteComplete||(this.isExecuteComplete=!0,await this.cleanup({kind:`cancelled`}))}[Symbol.asyncIterator](){return this}};function Cn(e){if(e)return JSON.parse(e)}function wn(e){return JSON.stringify(e)}function Tn(e){for(let t of Object.values(e))if(t!==void 0)return!0;return!1}function v(e){if(!e)return!1;let t=typeof e;return t===`object`||t===`function`}var En=new WeakMap;function Dn(e,t,{bind:n=!0}={}){let r=Reflect.get(e,t);if(!n||typeof r!=`function`)return r;let i=En.get(r);i||En.set(r,i=new WeakMap);let a=i.get(e);return a||i.set(e,a=r.bind(e)),a}var On=class{items=[];pendingPulls=[];closed;push(e){if(this.closed)throw this.closed.reason;let t=this.pendingPulls.shift();t?t[0](e):this.items.push(e)}async pull(){if(this.items.length>0)return this.items.shift();if(this.closed)throw this.closed.reason;return new Promise((e,t)=>{this.pendingPulls.push([e,t])})}close(e){this.closed||(e??=new vn(`Queue was closed.`),this.closed={reason:e},this.pendingPulls.forEach(([,t])=>t(e)),this.pendingPulls.length=0)}abort(e){e??=new vn(`Queue was aborted.`),this.items.length=0,this.close(e)}},kn=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;function An(e){try{return encodeURIComponent(e)}catch{return encodeURIComponent(e.replace(kn,`�`))}}function jn(e){if(!e.includes(`%`))return e;try{return decodeURIComponent(e)}catch{return e}}function Mn(e){return e[0]??{}}var Nn=`orpc`;function Pn(e){return e instanceof Error&&e.name.includes(`Abort`)}Object.getPrototypeOf(async function*(){}).constructor;function Fn(e){let t;return()=>{if(t)return t.result;let n=e();return t={result:n},n}}function In(e){try{return decodeURIComponent(e)}catch{return e}}function Ln(e){return`/${e.map(encodeURIComponent).join(`/`)}`}function Rn(e){let t=e.split(`/`);return t.at(0)===``&&t.shift(),Ln(t.map(In))}function zn(e,t){if(!e.startsWith(t))return!1;let n=e[t.length];return n===`/`||n===`?`||n===`#`||n===void 0||t[t.length-1]===`/`}var Bn=Symbol.for(`ORPC_TRACER`);function y(){return globalThis[Bn]}function Vn(e){let t=y();if(t)return typeof e==`string`?t.startSpan(e):t.startSpan(e.name,e.parent)}function Hn(e,t){e&&e.recordException(Pn(t)?`info`:`error`,Un(t))}function Un(e){if(e instanceof Error){let t={message:e.message,name:e.name,stack:e.stack};return`code`in e&&(typeof e.code==`string`||typeof e.code==`number`)&&(t.code=e.code),t}return{message:String(e)}}async function b(e,t){let n=y();if(!n)return t();let r=typeof e==`string`?e:e.name,i=typeof e==`string`?void 0:e.parent;return n.startActiveSpan(r,i,async e=>{try{return await t(e)}catch(t){throw Hn(e,t),t}finally{e.end()}})}function Wn(e,t){let n=y();return!e||!n?t():n.withActiveSpan(e,t)}function Gn(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o;return new Sn(async()=>{try{let r;try{r=await t(()=>e.next()),o=r.done}catch(e){throw o=!0,e}return n?await n(r):r}catch(e){throw await i?.(e),r?await r(e):e}},async n=>{try{if(!o)try{await t(async()=>e.return?.())}catch(e){throw await i?.(e),e}}finally{await a?.()}})}function Kn(e,t){let n=Fn(()=>Vn(e));return Gn(t,{runWith:e=>Wn(n(),e),mapResult(e){return n()?.addEvent(e.done?`completed`:`yielded`),e},onError(e){Hn(n(),e)},onFinish(){n()?.end()}})}function qn(e,...t){return typeof e==`function`?e(...t):e}function Jn(e,t){return new Proxy(typeof e==`function`?t:e,{get(n,r){return Dn(r in t?t:qn(e),r)},has(n,r){return Reflect.has(t,r)||Reflect.has(qn(e),r)}})}function Yn(e){return v(e)?Object.getPrototypeOf(e)?.constructor:null}function*Xn(e){if(!v(e))return;let t=Object.getPrototypeOf(e);for(;t!=null;)t.constructor&&(yield t.constructor),t=Object.getPrototypeOf(t)}function Zn(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||!t||!t.constructor}function Qn(e,t){return Object.hasOwn(e,t)?e[t]:void 0}function $n(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function er(e,t){if(!Zn(e)||!Zn(t))return t;let n={...e,...t};for(let r in t){if(!Object.hasOwn(e,r))continue;let i=e[r],a=t[r];Zn(i)&&Zn(a)&&$n(n,r,{...i,...a})}return n}function tr(e,t){let n={...e};for(let e of t)delete n[e];return n}var nr=(()=>{let e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})();function rr(e,t={}){let n=new Set(t.unbound),r=new nr,i=e;for(;i&&i!==Object.prototype;){for(let t of Object.getOwnPropertyNames(i)){if(t===`constructor`||t in r)continue;let i=Dn(e,t,{bind:!n.has(t)});typeof i==`function`&&(r[t]=i)}for(let t of Object.getOwnPropertySymbols(i)){if(t in r)continue;let i=Dn(e,t,{bind:!n.has(t)});typeof i==`function`&&(r[t]=i)}i=Object.getPrototypeOf(i)}return r}function ir(e,{runWith:t,mapResult:n,mapError:r,onError:i,onFinish:a}){t??=e=>e();let o=Fn(()=>e.getReader()),s=Fn(async()=>a?.());return new ReadableStream({async pull(e){let a;try{let e=await t(()=>o().read());a=n?await n(e):e}catch(t){try{await i?.(t),e.error(r?await r(t):t)}finally{await s()}return}a.done?(e.close(),await s()):e.enqueue(a.value)},async cancel(e){try{try{await t(()=>o().cancel(e))}catch(e){throw await i?.(e),e}}finally{await s()}}})}function ar(e,t){let n=Fn(()=>Vn(e));return ir(t,{runWith:e=>Wn(n(),e),mapResult(e){return n()?.addEvent(e.done?`closed`:`enqueued`),e},onError(e){Hn(n(),e)},onFinish(){n()?.end()}})}function or(e,t,n){if(!e?.length)return n(t);let r=(t,i)=>{let a=e[i];return a?a({...t,next:(e=t)=>r(e,i+1)}):n(t)};return r(t,0)}function sr(e){let t=e.length,n=new Map;for(let r=0;r<t;r++){let t=e[r],i=n.get(t.name);i===void 0?n.set(t.name,[r]):i.push(r)}let r=Array.from({length:t},()=>new Set);for(let i=0;i<t;i++){let t=e[i],a=t.before;if(a!==void 0)for(let e of a){let t=n.get(e);if(t!==void 0)for(let e of t){let t=r[e];t!==void 0&&t.add(i)}}let o=t.after;if(o!==void 0){let e=r[i];if(e!==void 0)for(let t of o){let r=n.get(t);if(r!==void 0)for(let t of r)e.add(t)}}}let i=[],a=new Set,o=new Set;function s(t){if(o.has(t))return;if(a.has(t)){let n=e[t],r=n===void 0?`unknown`:n.name;throw Error(`Circular dependency detected involving plugin "${r}"`)}a.add(t);let n=r[t];if(n!==void 0)for(let e of n)s(e);a.delete(t),o.add(t);let c=e[t];c!==void 0&&i.push(c)}for(let e=0;e<t;e++)s(e);return i}var cr=class extends TypeError{},lr=class extends Error{constructor(e,t={}){super(t?.message??`Error Event`,t),this.data=e}},ur=/\r\n|[\n\r]/;function dr(e){return ur.test(e)}function fr(e){if(dr(e))throw new cr(`Event's id must not contain a carriage return or newline character`)}function pr(e){if(!Number.isInteger(e)||e<0)throw new cr(`Event's retry must be a integer and >= 0`)}function mr(e){if(dr(e))throw new cr(`Event's comment must not contain a carriage return or newline character`)}var hr=Symbol.for(`STANDARD_SERVER_EVENT_META`),gr=Symbol.for(`STANDARD_SERVER_EVENT_SOURCE`);function _r(e,t){let n;if(t.id!==void 0&&(fr(t.id),n??={},n.id=t.id),t.retry!==void 0&&(pr(t.retry),n??={},n.retry=t.retry),t.comments!==void 0){for(let e of t.comments)mr(e);n??={},n.comments=t.comments}return n?new Proxy(e,{get(e,t,r){return t===gr?e:t===hr?n:Dn(e,t)}}):e}function vr(e){if(!v(e))return[e,void 0];let t=e[hr];return[e[gr]??e,t]}function yr(e){if(v(e))return e[hr]}function br(e,t=`inline`){return`${t}; filename="${e.replace(/[^\x20-\x7E]/g,`_`).replace(/[\\"]/g,`\\$&`)}"; filename*=utf-8''${An(e).replace(/['()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(7C|60|5E)/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}`}function xr(e){let t=e.match(/(?:^|;)\s*filename\*=([^;]*)/i)?.[1]?.trim(),n=t?.match(/^([^']*)'[^']*'(.*)$/);if(n){let[,e=``,t=``]=n;if(/^(?:utf-8|us-ascii)$/i.test(e))return jn(t)}else if(t)return jn(t);let r=e.match(/(?:^|;)\s*filename=(?:"((?:\\.|[^"\\])*)"|([^";]*))/i);return r?.[1]===void 0?r?.[2]?.trim()||void 0:r[1].replace(/\\(.)/g,`$1`)}function Sr(e){if(typeof e==`string`||e===void 0)return e;if(e.length!==0)return e.join(`, `)}function Cr(e){let t=e.indexOf(`#`),n=e.indexOf(`?`),r=n!==-1&&(t===-1||n<t),i=r?n:t===-1?e.length:t,a=t===-1?e.length:t;return[e.slice(0,i),r?e.slice(n,a):void 0,t===-1?void 0:e.slice(t)]}function wr(e){return typeof e==`string`}function Tr(e){return typeof e==`string`&&e.startsWith(`/`)}function Er(e){return v(e)?Object.values(e).every(e=>e===void 0||typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`)):!1}var Dr={BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,NOT_ACCEPTABLE:406,TIMEOUT:408,CONFLICT:409,GONE:410,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNSUPPORTED_MEDIA_TYPE:415,UNPROCESSABLE_CONTENT:422,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},Or,x=class e extends Error{static{let t=Symbol.for(`ORPC_ERROR_CONSTRUCTORS`);globalThis[t]??=new WeakSet,Or=globalThis[t],Or.add(e)}name=`ORPCError`;defined=!1;code;data;constructor(e,...t){let n=Mn(t),r=n.message??e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `);super(r,n),this.code=e,this.data=n.data}toJSON(){return{defined:this.defined,code:this.code,message:this.message,data:this.data}}static[Symbol.hasInstance](e){if(!Or.has(this))return super[Symbol.hasInstance](e);for(let t of Xn(e))if(Or.has(t))return!0;return!1}};function kr(e){return e instanceof x?e:new x(`INTERNAL_SERVER_ERROR`,{cause:e})}function Ar(e){if(!Zn(e))return!1;let t=[`defined`,`code`,`message`,`data`];return!Object.keys(e).some(e=>!t.includes(e))&&`defined`in e&&typeof e.defined==`boolean`&&`code`in e&&typeof e.code==`string`&&`message`in e&&typeof e.message==`string`}function jr(e,t={}){let n=new x(e.code,{...e,...t});return n.defined=e.defined,n}function Mr(e){let t=new x(e.code,{message:e.message,data:e.data,cause:e.cause});return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)),t.stack=e.stack,t}function Nr(e,{mapResult:t,mapError:n,...r}){return Gn(e,{...r,mapResult:t&&(async e=>{let n=await t(e);if(n.value!==e.value){let t=yr(e.value);if(t&&v(n.value))return{done:n.done,value:_r(n.value,t)}}return n}),mapError:n&&(async e=>{let t=await n(e);if(t!==e){let n=yr(e);if(n&&v(t))return _r(t,n)}return t})})}var Pr=/^\/([\s\S]*)\/([a-z]*)$/,Fr={undefined:{condition(e){return e===void 0},serialize(){return null},deserialize(){},isTerminal:!0},bigint:{condition(e){return typeof e==`bigint`},serialize(e){return e.toString()},deserialize(e){return BigInt(e)},isTerminal:!0},date:{condition(e){return e instanceof Date},serialize(e){return Number.isNaN(e.getTime())?null:e.toISOString()},deserialize(e){return new Date(e??`Invalid Date`)},isTerminal:!0},nan:{condition(e){return typeof e==`number`&&Number.isNaN(e)},serialize(){return null},deserialize(){return NaN},isTerminal:!0},url:{condition(e){return e instanceof URL},serialize(e){return e.toString()},deserialize(e){return new URL(e)},isTerminal:!0},regexp:{condition(e){return e instanceof RegExp},serialize(e){return e.toString()},deserialize(e){let[,t,n]=e.match(Pr);return new RegExp(t,n)},isTerminal:!0},set:{condition(e){return e instanceof Set},serialize(e){return Array.from(e)},deserialize(e){return new Set(e)}},map:{condition(e){return e instanceof Map},serialize(e){return Array.from(e.entries())},deserialize(e){return new Map(e)}}},Ir=class{handlers;inlineBuiltInHandlers;handlerEntries;omitUndefinedProperties;constructor(e={}){this.omitUndefinedProperties=e.omitUndefinedProperties!==!1,this.handlers=Object.assign(new nr,Fr);let t=e.handlers;if(t===void 0){this.inlineBuiltInHandlers=!0;return}let n=!0,r=[];for(let e in t){let i=t[e];this.handlers[e]=i,n&&e in Fr&&(n=!1),n&&i!==void 0&&r.push([e,i])}if(!n){r=[];for(let e in this.handlers){let t=this.handlers[e];t!==void 0&&r.push([e,t])}}this.inlineBuiltInHandlers=n,this.handlerEntries=r}serialize(e){let t=[],n=[],r=[],i=this.serializeValue(e,[],t,n,r);return t=t.length===0?void 0:t,n.length===0?{json:i,meta:t}:{json:i,meta:t,maps:n,blobs:r}}serializeValue(e,t,n,r,i){if(this.inlineBuiltInHandlers)switch(typeof e){case`string`:case`boolean`:return e;case`number`:return Number.isNaN(e)?(n.push([`nan`,...t]),null):e;case`undefined`:return n.push([`undefined`,...t]),null;case`bigint`:return n.push([`bigint`,...t]),e.toString();case`object`:if(e===null)return e;if(e instanceof Date)return n.push([`date`,...t]),Number.isNaN(e.getTime())?null:e.toISOString();if(e instanceof URL)return n.push([`url`,...t]),e.toString();if(e instanceof RegExp)return n.push([`regexp`,...t]),e.toString();if(e instanceof Set){let a=this.serializeValue(Array.from(e),t,n,r,i);return n.push([`set`,...t]),a}if(e instanceof Map){let a=this.serializeValue(Array.from(e.entries()),t,n,r,i);return n.push([`map`,...t]),a}}let a=this.handlerEntries;if(a)for(let o=0;o<a.length;o++){let s=a[o],c=s[1];if(c.condition(e)){let a=c.serialize(e);if(c.isTerminal)return n.push([s[0],...t]),a instanceof Blob&&(r.push(t.slice()),i.push(a)),a;let o=this.serializeValue(a,t,n,r,i);return n.push([s[0],...t]),o}}if(e instanceof Blob)return r.push(t.slice()),i.push(e),e;if(Array.isArray(e)){let a=[];for(let o=0;o<e.length;o++)t.push(o),a.push(this.serializeValue(e[o],t,n,r,i)),t.pop();return a}if(Zn(e)){let a=new nr;for(let o in e){let s=e[o];(o!==`toJSON`||typeof s!=`function`)&&(s===void 0&&this.omitUndefinedProperties||(t.push(o),a[o]=this.serializeValue(s,t,n,r,i),t.pop()))}return a}return e}deserialize(e){let t={data:e.json};if(e.blobs?.length)for(let n=0;n<e.maps.length;n++){let r=e.maps[n],i=t,a=`data`;for(let e=0;e<r.length;e++)if(i=i[a],a=r[e],!Object.hasOwn(i,a))throw Error(`Security error: Invalid serialized data. Segment "${a}" does not exist.`);i[a]=e.blobs[n]}if(e.meta)for(let n of e.meta){let e=n[0],r=t,i=`data`;for(let e=1;e<n.length;e++)if(r=r[i],i=n[e],!Object.hasOwn(r,i))throw Error(`Security error: Invalid serialized data. Segment "${i}" does not exist.`);r[i]=this.handlers[e].deserialize(r[i])}return t.data}},Lr=class{jsonSerializer;defaultSerializeOptions;constructor(e={}){this.jsonSerializer=new Ir(e),this.defaultSerializeOptions=e.serialize}serialize(e,t={}){if(e===void 0||e instanceof ReadableStream||e instanceof Blob)return e;if(bn(e))return Nr(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.serializeValue(e.value,!1)},mapError:e=>new lr(this.serializeValue(kr(e).toJSON(),!1),{cause:e})});let n=t.useFormDataForBlobFields??this.defaultSerializeOptions?.useFormDataForBlobFields??!0;return this.serializeValue(e,n)}serializeValue(e,t){let{json:n,meta:r,maps:i,blobs:a}=this.jsonSerializer.serialize(e);if(!t||!a?.length)return{json:n,meta:r};let o=new FormData;return o.set(`data`,wn({json:n,meta:r,maps:i})),a.forEach((e,t)=>{o.set(t.toString(),e)}),o}deserialize(e){return e===void 0||e instanceof ReadableStream||e instanceof Blob?e:bn(e)?Nr(e,{mapResult:e=>e.value===void 0?e:{done:e.done,value:this.deserializeValue(e.value)},mapError:e=>{if(!(e instanceof lr))return e;let t=this.deserializeValue(e.data);return Ar(t)?jr(t,{cause:e}):new lr(t,{cause:e})}}):this.deserializeValue(e)}deserializeValue(e){if(!(e instanceof FormData))return this.jsonSerializer.deserialize(e);let t=JSON.parse(e.get(`data`)),n=[];for(let[t,r]of e)r instanceof Blob&&(n[Number(t)]=r);return this.jsonSerializer.deserialize({...t,blobs:n})}};function S(e,t){return{...e,...t}}async function Rr(e,t){let n=Qn(e,t.code);if(!n){if(!t.defined)return t;let e=Mr(t);return e.defined=!1,e}if(!n.data){if(t.defined)return t;let e=Mr(t);return e.defined=!0,e}let r=await n.data[`~standard`].validate(t.data);if(r.issues){if(!t.defined)return t;let e=Mr(t);return e.defined=!1,e}if(t.data===r.value&&t.defined)return t;let i=Mr(t);return i.data=r.value,i.defined=!0,i}function zr(e,t,n){t=_(t),n=_(n);let r=e;for(let e of n)e.init&&(r=e.init(r));let i=[...t,...n];for(let e of i)e.apply&&(r=e.apply(r));return[r,i]}var Br=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?Yn(t)===e||v(t)&&v(t[`~orpc`])&&v(t[`~orpc`].errorMap)&&v(t[`~orpc`].meta)&&(t[`~orpc`].inputSchemas===void 0||Array.isArray(t[`~orpc`].inputSchemas))&&(t[`~orpc`].outputSchemas===void 0||Array.isArray(t[`~orpc`].outputSchemas)):Function.prototype[Symbol.hasInstance].call(this,t)}};function Vr(e,t){if(e instanceof Br){let[n,r]=zr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new Br({...e[`~orpc`],errorMap:S(t.errorMap,e[`~orpc`].errorMap),meta:n,metaPlugins:r})}if(!v(e))return e;let n={};for(let r in e)n[r]=Vr(e[r],t);return n}var Hr=class extends Error{name=`ValidationError`;issues;invalidData;constructor(e){super(e.message,e),this.issues=e.issues,this.invalidData=e.invalidData}},Ur=Symbol.for(`ORPC_HIDDEN_META_PLUGINS`);function C(e){if(v(e))return e[Ur]}var w=class e extends Br{constructor(e){super(e)}static create(){return new e({errorMap:{},meta:{}})}meta(...t){let[n,r]=zr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}input(t){let n=new e({...this[`~orpc`],inputSchemas:[..._(this[`~orpc`].inputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}output(t){let n=new e({...this[`~orpc`],outputSchemas:[..._(this[`~orpc`].outputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}router(e){return Vr(e,this[`~orpc`])}}.create();function Wr(e){return new Proxy(e,{get(t,n){return typeof n==`string`?(...t)=>{let r=Mn(t),i=Qn(e,n),a=new x(n,{message:r.message??i?.message,data:r.data,cause:r.cause});return i&&(a.defined=!0),a}:Reflect.get(t,n)}})}var Gr=Symbol.for(`ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS`);function Kr(e,t){return{"~standard":{[Gr]:{yieldSchema:e,returnSchema:t},vendor:Nn,version:1,validate(n){return bn(n)?{value:Nr(n,{async mapResult(n){let r=n.done?t:e;if(!r)return n;let i=await r[`~standard`].validate(n.value);if(i.issues)throw new x(`ASYNC_ITERATOR_OBJECT_VALIDATION_FAILED`,{message:`AsyncIteratorObject validation failed`,cause:new Hr({issues:i.issues,message:`AsyncIteratorObject validation failed`,invalidData:n.value})});return{done:n.done,value:i.value}}})}:{issues:[{message:`Expect AsyncIteratorObject`,path:[]}]}}}}}var T=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?Yn(t)===e||v(t)&&v(t[`~orpc`])&&v(t[`~orpc`].meta)&&(t[`~orpc`].metaPlugins===void 0||Array.isArray(t[`~orpc`].metaPlugins))&&typeof t[`~orpc`].loader==`function`:Function.prototype[Symbol.hasInstance].call(this,t)}};function E(e){return e instanceof T?e[`~orpc`].loader():Promise.resolve({default:e})}function qr(e,...t){let n=Mn(t);return async(...[t,r])=>{let i=_(n.path),{default:a}=await E(e),o=r?.context??{},s=await qn(n.context,o)??{},c=Wr(a[`~orpc`].errorMap),l=async e=>e instanceof x?await Rr(a[`~orpc`].errorMap,e):e;try{let e=await b(`call_procedure`,e=>(e?.setAttribute(`procedure.path`,i),or(n.interceptors,{context:s,input:t,errors:c,path:i,procedure:a,signal:r?.signal,lastEventId:r?.lastEventId},e=>Zr(e.procedure,e))));return bn(e)?Jn(e,Nr(y()?Kn(`consume_async_iterator_object_output`,e):e,{mapError:l})):y()&&e instanceof ReadableStream?Jn(e,ar(`consume_octet_stream_output`,e)):e}catch(e){throw await l(e)}}}async function Jr(e,t,n){return b(`validate_input.${e}`,async r=>{r?.setAttribute(`input_schema.index`,e);let i=await t[`~standard`].validate(n);if(i.issues)throw new x(`BAD_REQUEST`,{message:`Input validation failed`,data:{issues:i.issues},cause:new Hr({message:`Input validation failed`,issues:i.issues,invalidData:n})});return i.value})}async function Yr(e,t,n){return b(`validate_output.${e}`,async r=>{r?.setAttribute(`output_schema.index`,e);let i=await t[`~standard`].validate(n);if(i.issues)throw new x(`INTERNAL_SERVER_ERROR`,{message:`Output validation failed`,cause:new Hr({message:`Output validation failed`,issues:i.issues,invalidData:n})});return i.value})}var Xr=(...e)=>{let t=Mn(e);return{output:t.output,context:t.context??{}}};async function Zr(e,t){let n=_(e[`~orpc`].inputSchemas),r=_(e[`~orpc`].outputSchemas),i=e[`~orpc`].orderedMiddlewares,a=async(o,s,c)=>{let l=c,u=c,d=o===0?0:i[o-1].inputSchemasLengthAtUse??0,f=o===i.length?n.length:i[o].inputSchemasLengthAtUse??0;if(!e[`~orpc`].disableInputValidation){for(let e=d;e<f;e++){let r=await Jr(e,n[e],n.length>1&&Zn(l)?t.input:l);l=e===0?r:er(l,r)}u=f>0&&f<n.length?er(t.input,l):l}let p,m=s;if(o<i.length){let{middleware:e}=i[o],n=await b(`middleware.${e.name}`,async n=>(n?.setAttribute(`middleware.index`,o),await e({...t,context:s,next:(...e)=>{let t=Mn(e).context??{};return a(o+1,{...s,...t},l)},lastEventId:t.lastEventId},u,Xr)));p=n.output,m={...s,...n.context}}else p=await b(`handler`,()=>e[`~orpc`].handler({...t,context:s,input:l},l));let ee=o===0?0:i[o-1].outputSchemasLengthAtUse??0,te=o===i.length?r.length:i[o].outputSchemasLengthAtUse??0;if(!e[`~orpc`].disableOutputValidation)for(let e=te-1;e>=ee;e--)p=await Yr(e,r[e],p);return{output:p,context:m}},{output:o}=await a(0,t.context,t.input);return o}var D=class e{"~orpc";constructor(e){this[`~orpc`]=e}static[Symbol.hasInstance](t){return this===e?Yn(t)===e||t instanceof Br&&Array.isArray(t[`~orpc`].orderedMiddlewares)&&typeof t[`~orpc`].handler==`function`:Function.prototype[Symbol.hasInstance].call(this,t)}},Qr=class e extends D{meta(...t){let[n,r]=zr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}use(t){let n=new e({...this[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap,this[`~orpc`].errorMap),orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]});return t[`~orpc`]?.metaPlugins&&(n=n.meta(...t[`~orpc`]?.metaPlugins)),n}};function $r(e,t){return new D({...e[`~orpc`],errorMap:t[`~orpc`].errorMap,meta:t[`~orpc`].meta,metaPlugins:t[`~orpc`].metaPlugins})}var ei=Symbol.for(`ORPC_HIDDEN_ROUTER_CONTRACT`);function ti(e,t){return new Proxy(e,{get(e,n){return n===ei?t:Reflect.get(e,n)}})}function ni(e){return e[ei]}function ri(e,t){if(e instanceof T){let[n,r]=zr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new T({meta:n,metaPlugins:r,async loader(){let{default:n}=await E(e);return E(ri(n,t))}})}if(e instanceof D){let[n,r]=zr(t.meta,t.metaPlugins,e[`~orpc`].metaPlugins);return new D({...tr(t,[`middlewares`,`errorMap`,`meta`,`metaPlugins`]),...e[`~orpc`],meta:n,metaPlugins:r,errorMap:S(t.errorMap,e[`~orpc`].errorMap),orderedMiddlewares:[...t.middlewares.map(e=>({middleware:e,inputSchemasLengthAtUse:0,outputSchemasLengthAtUse:0})),...e[`~orpc`].orderedMiddlewares]})}if(!v(e))return e;let n={};for(let r in e)n[r]=ri(e[r],t);return n}function ii(e,t){if(e instanceof T)return new T({...e[`~orpc`],async loader(){let{default:n}=await E(e);return E(ii(n,t))}});if(e instanceof D)return new D({...tr(t,[`middlewares`]),...e[`~orpc`],orderedMiddlewares:[...t.middlewares.map(e=>({middleware:e,inputSchemasLengthAtUse:0,outputSchemasLengthAtUse:0})),...e[`~orpc`].orderedMiddlewares]});if(!v(e))return e;let n={};for(let r in e)n[r]=ii(e[r],t);return n}function ai(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e];if(!v(n)||n instanceof D)return;if(!(n instanceof T)){n=n[r];continue}let i=n,a=t.slice(e);return new T({...i[`~orpc`],async loader(){return await E(ai((await E(i)).default,a))}})}if(v(n))return n}function oi(e,t,n=[]){let r=[];return si(e,t,n.slice(),r),r}function si(e,t,n,r){let i=ni(e);if(i!==void 0&&(e=i),e instanceof Br){t(e,n.slice());return}if(v(e))for(let i in e){let a=e[i];n.push(i),a instanceof T?r.push({router:a,path:n.slice()}):si(a,t,n,r),n.pop()}}function ci(e){let t=((...t)=>e(...t));return t[`~orpc`]=e[`~orpc`],Object.defineProperty(t,"name",{value:e.name}),t.adaptInput=t=>{let n=ci((n,r,...i)=>e(n,t(r),...i));return n[`~orpc`]=e[`~orpc`],Object.defineProperty(n,"name",{value:e.name}),n},t.errors=e=>{let n=ci(t);return n[`~orpc`]={...t[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap,e)},n},t.use=n=>{let r=ci((t,...r)=>e({...t,async next(e){let i=await n({...t,context:{...t.context,...e?.context},next(n,...r){return t.next({...t,context:{...e?.context,...n?.context}},...r)}},...r);return{...i,context:{...e?.context,...i.context}}}},...r));return r[`~orpc`]={...t[`~orpc`],errorMap:S(n[`~orpc`]?.errorMap,t[`~orpc`]?.errorMap),metaPlugins:[..._(e[`~orpc`]?.metaPlugins),..._(n[`~orpc`]?.metaPlugins)]},Object.defineProperty(r,"name",{value:`${e.name} + ${n.name}`}),r},t}(class e{"~orpc";constructor(e){this[`~orpc`]=e}static create(){return new e({errorMap:{},meta:{},orderedMiddlewares:[]})}$context(){return this}$config(t){return new e({...this[`~orpc`],...t})}meta(...t){let[n,r]=zr(this[`~orpc`].meta,this[`~orpc`].metaPlugins,t);return new e({...this[`~orpc`],meta:n,metaPlugins:r})}errors(t){let n=new e({...this[`~orpc`],errorMap:S(this[`~orpc`].errorMap,t)}),r=C(t);return r&&(n=n.meta(...r)),n}use(t){let n=new e({...this[`~orpc`],errorMap:S(t[`~orpc`]?.errorMap??{},this[`~orpc`].errorMap),orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]});return t[`~orpc`]?.metaPlugins&&(n=n.meta(...t[`~orpc`]?.metaPlugins)),n}middleware(e){let t=[...this[`~orpc`].orderedMiddlewares.map(({middleware:e})=>e),e],n=ci(t.shift());for(let e of t)n=n.use(e);return n[`~orpc`]={...n[`~orpc`],errorMap:this[`~orpc`].errorMap,metaPlugins:[..._(this[`~orpc`].metaPlugins),..._(e[`~orpc`]?.metaPlugins)]},n}input(t){let n=new e({...this[`~orpc`],inputSchemas:[..._(this[`~orpc`].inputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}output(t){let n=new e({...this[`~orpc`],outputSchemas:[..._(this[`~orpc`].outputSchemas),t]}),r=C(t);return r&&(n=n.meta(...r)),n}handler(e){let t=new Qr({...this[`~orpc`],handler:e}),n=C(e);return n&&(t=t.meta(...n)),t}router(e){return ri(e,{...this[`~orpc`],middlewares:this[`~orpc`].orderedMiddlewares.map(({middleware:e})=>e)})}lazy(e){return new T({loader:async()=>{let{default:t}=await e();return{default:this.router(t)}},meta:this[`~orpc`].meta,metaPlugins:this[`~orpc`].metaPlugins})}}).create();var li=class e{"~orpc";constructor(e){this[`~orpc`]=e}use(t){return new e({...this[`~orpc`],orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]})}handler(e){return new ui({...this[`~orpc`],handler:e})}},ui=class e extends D{use(t){return new e({...this[`~orpc`],orderedMiddlewares:[...this[`~orpc`].orderedMiddlewares,{middleware:t,inputSchemasLengthAtUse:this[`~orpc`].inputSchemas?.length,outputSchemasLengthAtUse:this[`~orpc`].outputSchemas?.length}]})}},di=class e{constructor(e,t,n){this.contract=e,this.config=t,this.middlewares=n}static create(t,n,r=[]){return new e(t,n,r)}use(e){return pi(this.contract,this.config,[...this.middlewares,e])}middleware(e){let t=[...this.middlewares,e],n=ci(t.shift());for(let e of t)n=n.use(e);return n}router(e){return this.middlewares.length&&(e=ii(e,{...this.config,middlewares:this.middlewares})),ti(e,this.contract)}lazy(e){if(this.middlewares.length){let t=e;e=async()=>{let{default:e}=await t();return{default:ii(e,{...this.config,middlewares:this.middlewares})}}}return new T({loader:e,meta:{}})}};function fi(e,t){return pi(e,t,[])}function pi(e,t,n){if(e instanceof Br)return new li({...t,...e[`~orpc`],orderedMiddlewares:n.map(e=>({middleware:e}))});let r={};for(let i in e){let a=e[i];r[i]=pi(a,t,n)}let i=rr(di.create(e,t,n));for(let e in i){let t=i[e];if(e in r){let n=r[e];r[e]=new Proxy(t,{get(e,t){return Reflect.get(n,t)}})}else r[e]=t}return r}function mi(e,t={}){let n=fi(e,t),r=new Proxy(n,{get(i,a){let o;a===`$context`?o=()=>r:a===`$config`&&(o=n=>mi(e,{...t,...n}));let s=Reflect.get(n,a);return o?v(s)?new Proxy(o,{get(e,t){return Reflect.get(s,t)}}):o:s}});return r}function hi(e,t){return new Sn(async()=>{for(;;){let{json:t}=await e.pull();switch(t.event){case void 0:case`message`:{let e=t.data;return v(e)&&(e=_r(e,t)),{value:e,done:!1}}case`error`:throw _r(new lr(t.data),t);case`close`:{let e=t.data;return v(e)&&(e=_r(e,t)),{value:e,done:!0}}}}},t)}var gi=class{constructor(e,t,n){this.iterator=e,this.messageId=t,this.send=n}isDone=!1;async cancel(){this.isDone||(this.isDone=!0,await this.iterator.return?.())}async transmit(){for(;;)try{let e=await this.iterator.next();if(this.isDone)return;e.done&&(this.isDone=!0);try{let[t,n]=vr(e.value);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:e.done?`close`:void 0,data:t}})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){if(e instanceof lr){if(!this.isDone){this.isDone=!0;let[t,n]=vr(e);await this.send({kind:`event-stream`,id:this.messageId,json:{...n,event:`error`,data:t.data}})}return}throw this.isDone=!0,e}}};function _i(e,t){return new ReadableStream({async pull(n){try{let{json:r,binary:i}=await e.pull();i&&n.enqueue(i instanceof Uint8Array?i:new Uint8Array(await i.arrayBuffer())),r.close&&(await t({kind:`success`}),n.close())}catch(e){await t({kind:`error`,error:e}),n.error(e)}},async cancel(e){await t({kind:`cancelled`,error:e})}})}var vi=class{constructor(e,t,n){this.messageId=t,this.send=n,this.reader=e.getReader()}isDone=!1;reader;async cancel(){this.isDone||(this.isDone=!0,await this.reader.cancel())}async transmit(){for(;;)try{let e=await this.reader.read();if(this.isDone)return;e.done&&(this.isDone=!0);try{await this.send({json:{close:e.done?!0:void 0},binary:e.value,kind:`octet-stream`,id:this.messageId})}catch(e){throw await this.cancel(),e}if(this.isDone)return}catch(e){throw this.isDone=!0,e}}};function yi(e,t){let n=Sr(e.json.headers?.[`content-type`]),r=Sr(e.json.headers?.[`standard-server`]);if(e.json.body===void 0&&e.binary===void 0){if(n===void 0&&r===`event-stream`){let e=new On;return{resolveBody:async()=>hi(e,t),eventStreamMessageQueue:e}}if(n!==void 0){let e=new On;return{resolveBody:async()=>_i(e,t),octetStreamMessageQueue:e}}}return{resolveBody:async()=>{let i;try{if(e.binary){if(r===`form-data`){let t={};return n!==void 0&&(t[`content-type`]=n),await new Response(e.binary,{headers:t}).formData()}let t=Sr(e.json.headers?.[`content-disposition`]),i=t===void 0?void 0:xr(t);return new File([e.binary],i??`blob`,{type:n??`application/octet-stream`})}if(r===`url-search-params`){if(typeof e.json.body!=`string`)throw TypeError(`Expected body to be a string for url-search-params bodyHint`);return new URLSearchParams(e.json.body)}return e.json.body}catch(e){throw i={value:e},e}finally{await t(i?{kind:`error`,error:i.value}:{kind:`success`})}}}}async function bi(e,t){if(t={...t},e instanceof ReadableStream)return t[`content-type`]??=`application/octet-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof Blob)return t[`content-type`]=e.type,t[`content-disposition`]??=br(e instanceof File?e.name??``:`blob`),Number.isFinite(e.size)&&(t[`content-length`]=e.size.toString()),{jsonBody:void 0,headers:t,binary:e};if(t[`standard-server`]=void 0,t[`content-type`]=void 0,bn(e))return t[`standard-server`]=`event-stream`,{jsonBody:void 0,headers:t,binary:void 0};if(e instanceof FormData){let n=await new Response(e).blob();return t[`standard-server`]=`form-data`,t[`content-type`]=n.type,t[`content-length`]=n.size.toString(),{jsonBody:void 0,headers:t,binary:n}}return e instanceof URLSearchParams?(t[`standard-server`]=`url-search-params`,{jsonBody:e.toString(),headers:t,binary:void 0}):{jsonBody:e,headers:t,binary:void 0}}function xi(e){return!(!v(e)||typeof e.id!=`string`||typeof e.kind!=`string`||e.binary!==void 0&&!(e.binary instanceof Uint8Array)&&!(e.binary instanceof Blob))}function Si(e){return e.kind!==`request`||!v(e.json)||e.json.method!==void 0&&!wr(e.json.method)||e.json.headers!==void 0&&!Er(e.json.headers)?!1:Tr(e.json.url)}function Ci(e){return e.kind===`cancel`&&e.json===void 0&&e.binary===void 0}function wi(e){return!(e.kind!==`event-stream`||e.binary!==void 0||!v(e.json)||e.json.id!==void 0&&typeof e.json.id!=`string`||e.json.event!==void 0&&e.json.event!==`message`&&e.json.event!==`error`&&e.json.event!==`close`||e.json.retry!==void 0&&!Number.isFinite(e.json.retry)||e.json.comments!==void 0&&!(Array.isArray(e.json.comments)&&e.json.comments.every(e=>typeof e==`string`)))}function Ti(e){return e.kind===`octet-stream`&&v(e.json)&&(e.json.close===void 0||typeof e.json.close==`boolean`)}function Ei(e){return Si(e)||Ci(e)||wi(e)||Ti(e)}var Di=255,Oi=new TextEncoder,ki=new TextDecoder;async function Ai(e,t={}){if(e.binary===void 0){let n=wn(e);return t.prefix?t.prefix+n:n}let n=wn({...e,binary:void 0}),r=Oi.encode(t.prefix?t.prefix+n:n),i=e.binary instanceof Blob?new Uint8Array(await e.binary.arrayBuffer()):e.binary,a=new Uint8Array(r.length+1+i.length);return a.set(r,0),a[r.length]=Di,a.set(i,r.length+1),a}function ji(e,t={}){try{if(typeof e==`string`){if(t.prefix){if(!e.startsWith(t.prefix))return{matched:!1};e=e.slice(t.prefix.length)}let n=JSON.parse(e);return xi(n)?{matched:!0,message:n}:{matched:!1}}if(t.prefix){let n=Oi.encode(t.prefix);for(let t=0;t<n.length;t++)if(e[t]!==n[t])return{matched:!1};e=e.subarray(n.length)}let n=e.indexOf(Di);if(n===-1){let t=JSON.parse(ki.decode(e));return xi(t)?{matched:!0,message:t}:{matched:!1}}let r=e.subarray(0,n),i=e.subarray(n+1),a=JSON.parse(ki.decode(r));return xi(a)?(a.binary=i,{matched:!0,message:a}):{matched:!1}}catch{return{matched:!1}}}var Mi=class extends Sn{"~callback";constructor(e){super(async()=>{throw Error(`Cannot use hibernating iterator directly`)},async()=>{}),this[`~callback`]=e}},Ni=class{constructor(e){this.send=e}requests=new Map;async message(e,t){let n=e.id;if(e.kind===`cancel`){await this.closeById(n,new vn(`Client aborted the request`));return}if(e.kind===`event-stream`){this.requests.get(n)?.eventStreamMessageQueue?.push(e);return}if(e.kind===`octet-stream`){this.requests.get(n)?.octetStreamMessageQueue?.push(e);return}if(this.requests.has(n))return;let r=new AbortController,i={controller:r};this.requests.set(n,i);let a=r.signal;try{let r=yi(e,async({kind:e})=>{let t=i.eventStreamMessageQueue!==void 0||i.octetStreamMessageQueue!==void 0;i.eventStreamMessageQueue=void 0,i.octetStreamMessageQueue=void 0,e===`cancelled`&&t&&await this.send({id:n,kind:`stream/cancel`})});i.eventStreamMessageQueue=r.eventStreamMessageQueue,i.octetStreamMessageQueue=r.octetStreamMessageQueue;let o=await t({url:e.json.url,method:e.json.method??`POST`,headers:e.json.headers??{},resolveBody:r.resolveBody,signal:a});if(a.aborted)return;let s=await bi(o.body,o.headers);if(a.aborted)return;let c={id:n,kind:`response`,json:{status:o.status===200?void 0:o.status,headers:Tn(s.headers)?s.headers:void 0,body:s.jsonBody},binary:s.binary};if(await this.send(c),a.aborted)return;if(bn(o.body)){if(o.body instanceof Mi)try{await o.body[`~callback`]?.(n)}finally{await o.body.return()}else{let e=new gi(o.body,n,this.send);i.eventStreamTransmitter=e,await e.transmit().catch(async e=>{i.eventStreamTransmitter&&await this.cancelById(n,e)})}}else if(o.body instanceof ReadableStream){let e=new vi(o.body,n,this.send);i.octetStreamTransmitter=e,await e.transmit().catch(async e=>{i.octetStreamTransmitter&&await this.cancelById(n,e)})}i.controller=void 0,await this.closeById(n)}catch(e){throw await this.cancelById(n,e),e}}async close(e){e??=new vn(`Peer was closed`),await Promise.all(Array.from(this.requests.keys()).map(t=>this.closeById(t,e)))}async closeById(e,t){let n=this.requests.get(e);if(!n)return;this.requests.delete(e),(n.controller||n.eventStreamMessageQueue||n.octetStreamMessageQueue)&&(t??=new vn(`Request was closed`)),n.controller?.abort(t),n.controller=void 0,n.eventStreamMessageQueue?.close(t),n.octetStreamMessageQueue?.close(t),n.eventStreamMessageQueue=void 0,n.octetStreamMessageQueue=void 0;let r=[n.eventStreamTransmitter?.cancel(),n.octetStreamTransmitter?.cancel()];n.eventStreamTransmitter=void 0,n.octetStreamTransmitter=void 0,await Promise.all(r)}async cancelById(e,t){await Promise.all([this.requests.has(e)?this.send({id:e,kind:`cancel`}):void 0,this.closeById(e,t)])}};function Pi(e,t,n){n?e.postMessage(t,n):e.postMessage(t)}function Fi(e,t){if(`addEventListener`in e)e.addEventListener(`message`,e=>{t(e.data)});else if(`on`in e)e.on(`message`,e=>{t(e?.data)});else if(`onMessage`in e)e.onMessage.addListener(e=>{t(e)});else throw Error(`Cannot find a addEventListener/on/onMessage method on the port`)}function Ii(e,t){if(`addEventListener`in e)e.addEventListener(`close`,()=>{t()});else if(`on`in e)e.on(`close`,()=>{t()});else if(`onDisconnect`in e)e.onDisconnect.addListener(()=>{t()});else throw Error(`Cannot find a addEventListener/on/onDisconnect method on the port`)}function Li(e,t){return async n=>{let r=await qn(t.context??{},n),{response:i}=await e.handle(n,{...t,context:r});return i??{status:404,headers:{},body:`No procedure matched`}}}var Ri=class{name=`~composite`;plugins;constructor(e=[]){this.plugins=sr(e)}init(e){for(let t of this.plugins)t.init&&(e=t.init(e));return e}},zi=class{constructor(e,t){this.codec=e,t=new Ri([new Bi,..._(t.plugins)]).init(t),this.routingInterceptors=t.routingInterceptors,this.interceptors=t.interceptors,this.clientInterceptors=t.clientInterceptors}routingInterceptors;interceptors;clientInterceptors;async handle(e,{context:t,prefix:n}){return n&&!zn(e.url,n)?{matched:!1,response:void 0}:or(this.routingInterceptors,{context:t,prefix:n,request:e},async({context:e,prefix:t,request:n})=>{let r=y()?.getActiveSpan(),i,a=await b(`find_procedure`,()=>this.codec.resolveProcedure(n,{context:e,prefix:t}));if(!a)return r?.updateName(`${Nn}_no_match`),r?.setAttribute(`http.request.method`,n.method),r?.setAttribute(`url.path`,n.url),{matched:!1};let{path:o,procedure:s,decodeInput:c}=a;r?.updateName(`${Nn}.${o.join(`/`)}`),r?.setAttribute(`rpc.system`,Nn),r?.setAttribute(`rpc.method`,o.join(`.`));try{return{matched:!0,response:await or(this.interceptors,{context:e,prefix:t,request:n,path:o,procedure:s,decodeInput:c},async({context:e,prefix:t,request:n,path:r,procedure:a,decodeInput:o})=>{i=`decode_input`;let s=await b(`decode_input`,o);i=void 0,y()&&bn(s)?s=Jn(s,Kn(`consume_async_iterator_object_input`,s)):y()&&s instanceof ReadableStream&&(s=Jn(s,ar(`consume_octet_stream_input`,s)));let c=qr(a,{context:e,path:r,interceptors:this.clientInterceptors});i=`call_procedure`;let l=await c(s,{signal:n.signal,lastEventId:Sr(n.headers[`last-event-id`])});return i=void 0,await this.codec.encodeOutput(l,a,r,{context:e,prefix:t})})}}catch(n){i!==`call_procedure`&&Hn(r,n);let a=i===`decode_input`&&!(n instanceof x)?new x(`BAD_REQUEST`,{message:`Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,cause:n}):kr(n);return{matched:!0,response:await this.codec.encodeError(a,s,o,{context:e,prefix:t})}}})}},Bi=class{name=`~tracing`;init(e){return{...e,routingInterceptors:[async({next:e,request:t})=>{let n=y()?.extract?.(t.headers),[r]=Cr(t.url);return b({name:`${t.method} ${r}`,parent:n},()=>e())},..._(e.routingInterceptors)]}}},Vi=[`POST`,`PUT`,`PATCH`,`DELETE`],Hi=class{filter;allowMethodsSet;allowMethodsFn;rootRouter;tree=new Map;pendingLazyRouters=new Map;constructor(e,t={}){this.filter=t.filter??!0;let n=t.allowMethods??Vi;typeof n==`function`?this.allowMethodsFn=n:this.allowMethodsSet=new Set(n),this.rootRouter=e,this.index(e)}index(e,t=[]){let n=oi(e,(e,t)=>{qn(this.filter,e,t)&&this.tree.set(Ln(t),{path:t,contract:e,procedure:e instanceof D?e:void 0})},t);for(let e of n)this.pendingLazyRouters.set(Ln(e.path),e)}async match(e,t,n){if(this.allowMethodsSet&&!this.allowMethodsSet.has(e))return;if(t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),n){if(!t.startsWith(n))return;let e=t[n.length];if(e===`/`)t=t.slice(n.length);else if(e===void 0)t=`/`;else if(n[n.length-1]===`/`)t=t.slice(n.length-1);else return}let r=this.resolvePendingLazyRouters(t);r!==void 0&&await r;let i=this.tree.get(t);if(i===void 0&&t.includes(`%`)){let e=Rn(t),n=this.resolvePendingLazyRouters(e);n!==void 0&&await n,i=this.tree.get(e)}if(i===void 0)return;let a=i.procedure??await this.resolveProcedure(i);if(!this.allowMethodsFn||this.allowMethodsFn(e,a,i.path))return{path:i.path,procedure:a}}resolvePendingLazyRouters(e){if(this.pendingLazyRouters.size===0)return;let t=0;for(;t!==-1;){let n=e.indexOf(`/`,t+1),r=n===-1?e:e.slice(0,n);if(this.pendingLazyRouters.has(r))return this.loadPendingLazyRouters(e,t);t=n}}async loadPendingLazyRouters(e,t){for(;t!==-1;){let n=e.indexOf(`/`,t+1),r=n===-1?e:e.slice(0,n),i=this.pendingLazyRouters.get(r);i!==void 0&&await this.loadPendingLazyRouter(r,i),t=n}}loadPendingLazyRouter(e,t){return t.loading===void 0&&(t.loading=this.indexPendingLazyRouter(e,t).catch(e=>{throw t.loading=void 0,e})),t.loading}async indexPendingLazyRouter(e,t){let{default:n}=await E(t.router);this.index(n,t.path),this.pendingLazyRouters.delete(e)}async resolveProcedure(e){let{default:t}=await E(ai(this.rootRouter,e.path));if(!(t instanceof D))throw TypeError(`[Contract-First] Missing or invalid implementation for procedure at path: "${e.path.join(`.`)}". Ensure the procedure is correctly implemented and matches its contract.`);return e.procedure=$r(t,e.contract),e.procedure}},Ui=class{matcher;serializer;errorStatusMap;outputStatus;constructor(e,t={}){this.matcher=new Hi(e,t),this.serializer=t.serializer??new Lr,this.errorStatusMap=t.errorStatusMap??Dr,this.outputStatus=t.outputStatus}async resolveProcedure(e,t){let[n,r]=Cr(e.url),i=await this.matcher.match(e.method,n,t.prefix);if(i)return{procedure:i.procedure,path:i.path,decodeInput:async()=>{if(e.method===`GET`){let e=new URLSearchParams(r).getAll(`data`).at(-1);return this.serializer.deserialize(Cn(e))}let t=await e.resolveBody();return this.serializer.deserialize(t)}}}encodeOutput(e,t,n,r){return{headers:{},status:qn(this.outputStatus,e,t,n,r)??200,body:this.serializer.serialize(e)}}encodeError(e,t,n,r){return{headers:{},status:Qn(this.errorStatusMap,e.code)??500,body:this.serializer.serialize(e.toJSON())}}},Wi=class{constructor(e,t={}){this.handler=e,this.transfer=t.experimental_transfer,this.encodePeerMessageOptions=t.encodePeerMessage,this.decodePeerMessageOptions=t.decodePeerMessage}peers=new WeakMap;transfer;encodePeerMessageOptions;decodePeerMessageOptions;upgrade(e,...t){Fi(e,n=>this.message(e,n,...t)),Ii(e,()=>this.close(e))}async message(e,t,...n){let r=this.peers.get(e);r||this.peers.set(e,r=new Ni(async t=>{let n=await qn(this.transfer,t,e);n?Pi(e,t,n):Pi(e,await Ai(t,this.encodePeerMessageOptions))}));let i;if(typeof t==`string`||t instanceof Uint8Array){let e=ji(t,this.decodePeerMessageOptions);e.matched&&Ei(e.message)&&(i=e.message)}else xi(t)&&Ei(t)&&(i=t);return i===void 0?{matched:!1}:(await r.message(i,Li(this.handler,Mn(n))),{matched:!0})}async close(e){let t=this.peers.get(e);t&&(this.peers.delete(e),await t.close())}},Gi=class extends Wi{constructor(e,t={}){let n=new zi(new Ui(e,t),t);super(n,t)}};function Ki(e){return e?.aborted===!0}var qi=6e4,Ji=class{seq=0;buffer=[];listeners=new Set;retentionMs;constructor(e={}){this.retentionMs=e.retentionMs??qi}publish(e){this.prune();let t=String(++this.seq),n=_r(e,{id:t});this.buffer.push({id:t,event:n,publishedAt:Date.now()});for(let e of this.listeners)e(n)}prune(){let e=Date.now()-this.retentionMs;for(;this.buffer.length>0&&(this.buffer[0]?.publishedAt??1/0)<e;)this.buffer.shift()}async*subscribe(e={}){let{signal:t,lastEventId:n}=e;if(this.prune(),n!==void 0){let e=this.buffer.findIndex(e=>e.id===n),r=e===-1?this.buffer:this.buffer.slice(e+1);for(let e of r){if(Ki(t))return;yield e.event}}let r=[],i,a=e=>{r.push(e),i?.()};this.listeners.add(a);try{for(;;){if(Ki(t)||r.length===0&&(await new Promise(e=>{i=e,t?.addEventListener(`abort`,()=>{e()},{once:!0})}),i=void 0,Ki(t)))return;let e=r.shift();e!==void 0&&(yield e)}}finally{this.listeners.delete(a)}}},Yi;function O(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var Xi=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Zi=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Yi=globalThis).__zod_globalConfig??(Yi.__zod_globalConfig={});var Qi=globalThis.__zod_globalConfig;function k(e){return e&&Object.assign(Qi,e),Qi}function $i(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function ea(e,t){return typeof t==`bigint`?t.toString():t}function ta(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function na(e){return e==null}function ra(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function ia(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}var aa=Symbol(`evaluating`);function A(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==aa)return r===void 0&&(r=aa,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function oa(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function j(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function sa(e){return JSON.stringify(e)}function ca(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var la=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function ua(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var da=ta(()=>{if(Qi.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function fa(e){if(ua(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return ua(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function pa(e){return fa(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var ma=new Set([`string`,`number`,`symbol`]);function ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function M(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function N(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw 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 ga(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var _a={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function va(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return M(e,j(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return oa(this,`shape`,e),e},checks:[]}))}function ya(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return M(e,j(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return oa(this,`shape`,r),r},checks:[]}))}function ba(e,t){if(!fa(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return oa(this,`shape`,n),n}}))}function xa(e,t){if(!fa(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return oa(this,`shape`,n),n}}))}function Sa(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return M(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return oa(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ca(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return M(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return oa(this,`shape`,i),i},checks:[]}))}function wa(e,t,n){return M(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return oa(this,`shape`,i),i}}))}function Ta(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Ea(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function Da(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Oa(e){return typeof e==`string`?e:e?.message}function P(e,t,n){let r=e.message?e.message:Oa(e.inst?._zod.def?.error?.(e))??Oa(t?.error?.(e))??Oa(n.customError?.(e))??Oa(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function ka(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Aa(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ja=(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,ea,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ma=O(`$ZodError`,ja),Na=O(`$ZodError`,ja,{Parent:Error});function Pa(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Fa(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}var Ia=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Xi;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>P(e,a,k())));throw la(t,i?.callee),t}return o.value},La=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>P(e,a,k())));throw la(t,i?.callee),t}return o.value},Ra=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Xi;return a.issues.length?{success:!1,error:new(e??Ma)(a.issues.map(e=>P(e,i,k())))}:{success:!0,data:a.value}},za=Ra(Na),Ba=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>P(e,i,k())))}:{success:!0,data:a.value}},Va=Ba(Na),Ha=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Ia(e)(t,n,i)},Ua=e=>(t,n,r)=>Ia(e)(t,n,r),Wa=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return La(e)(t,n,i)},Ga=e=>async(t,n,r)=>La(e)(t,n,r),Ka=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Ra(e)(t,n,i)},qa=e=>(t,n,r)=>Ra(e)(t,n,r),Ja=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Ba(e)(t,n,i)},Ya=e=>async(t,n,r)=>Ba(e)(t,n,r),Xa=/^[cC][0-9a-z]{6,}$/,Za=/^[0-9a-z]+$/,Qa=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,$a=/^[0-9a-vA-V]{20}$/,eo=/^[A-Za-z0-9]{27}$/,to=/^[a-zA-Z0-9_-]{21}$/,no=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,ro=/^([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})$/,io=e=>e?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)$/,ao=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,oo=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function so(){return new RegExp(oo,`u`)}var co=/^(?:(?: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])$/,lo=/^(([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}|:))$/,uo=/^((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])$/,fo=/^(([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])$/,po=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,mo=/^[A-Za-z0-9_-]*$/,ho=/^https?$/,go=/^\+[1-9]\d{6,14}$/,_o=`(?:(?:\\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])))`,vo=RegExp(`^${_o}$`);function yo(e){let 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 bo(e){return RegExp(`^${yo(e)}$`)}function xo(e){let t=yo({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${_o}T(?:${r})$`)}var So=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Co=/^-?\d+$/,wo=/^-?\d+(?:\.\d+)?$/,To=/^(?:true|false)$/i,Eo=/^[^A-Z]*$/,Do=/^[^a-z]*$/,F=O(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Oo={number:`number`,bigint:`bigint`,object:`date`},ko=O(`$ZodCheckLessThan`,(e,t)=>{F.init(e,t);let n=Oo[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ao=O(`$ZodCheckGreaterThan`,(e,t)=>{F.init(e,t);let n=Oo[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),jo=O(`$ZodCheckMultipleOf`,(e,t)=>{F.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):ia(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})}}),Mo=O(`$ZodCheckNumberFormat`,(e,t)=>{F.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=_a[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Co)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),No=O(`$ZodCheckMaxLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!na(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=ka(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Po=O(`$ZodCheckMinLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!na(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=ka(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Fo=O(`$ZodCheckLengthEquals`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!na(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=ka(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Io=O(`$ZodCheckStringFormat`,(e,t)=>{var n,r;F.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Lo=O(`$ZodCheckRegex`,(e,t)=>{Io.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})}}),Ro=O(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Eo,Io.init(e,t)}),zo=O(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Do,Io.init(e,t)}),Bo=O(`$ZodCheckIncludes`,(e,t)=>{F.init(e,t);let n=ha(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Vo=O(`$ZodCheckStartsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`^${ha(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Ho=O(`$ZodCheckEndsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`.*${ha(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Uo=O(`$ZodCheckOverwrite`,(e,t)=>{F.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),Wo=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
2
2
|
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
|
|
3
|
-
`))}},
|
|
3
|
+
`))}},Go={major:4,minor:4,patch:3},I=O(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Go;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=Ta(e),i;for(let a of t){if(a._zod.def.when){if(Ea(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new Xi;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=Ta(e,t))});else{if(e.issues.length===t)continue;r||=Ta(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(Ta(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new Xi;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new Xi;return o.then(e=>t(e,r,a))}return t(o,r,a)}}A(e,`~standard`,()=>({validate:t=>{try{let n=za(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Va(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Ko=O(`$ZodString`,(e,t)=>{I.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??So(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),L=O(`$ZodStringFormat`,(e,t)=>{Io.init(e,t),Ko.init(e,t)}),qo=O(`$ZodGUID`,(e,t)=>{t.pattern??=ro,L.init(e,t)}),Jo=O(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=io(e)}else t.pattern??=io();L.init(e,t)}),Yo=O(`$ZodEmail`,(e,t)=>{t.pattern??=ao,L.init(e,t)}),Xo=O(`$ZodURL`,(e,t)=>{L.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===ho.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.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(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),n.value=t.normalize?i.href:r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Zo=O(`$ZodEmoji`,(e,t)=>{t.pattern??=so(),L.init(e,t)}),Qo=O(`$ZodNanoID`,(e,t)=>{t.pattern??=to,L.init(e,t)}),$o=O(`$ZodCUID`,(e,t)=>{t.pattern??=Xa,L.init(e,t)}),es=O(`$ZodCUID2`,(e,t)=>{t.pattern??=Za,L.init(e,t)}),ts=O(`$ZodULID`,(e,t)=>{t.pattern??=Qa,L.init(e,t)}),ns=O(`$ZodXID`,(e,t)=>{t.pattern??=$a,L.init(e,t)}),rs=O(`$ZodKSUID`,(e,t)=>{t.pattern??=eo,L.init(e,t)}),is=O(`$ZodISODateTime`,(e,t)=>{t.pattern??=xo(t),L.init(e,t)}),as=O(`$ZodISODate`,(e,t)=>{t.pattern??=vo,L.init(e,t)}),os=O(`$ZodISOTime`,(e,t)=>{t.pattern??=bo(t),L.init(e,t)}),ss=O(`$ZodISODuration`,(e,t)=>{t.pattern??=no,L.init(e,t)}),cs=O(`$ZodIPv4`,(e,t)=>{t.pattern??=co,L.init(e,t),e._zod.bag.format=`ipv4`}),ls=O(`$ZodIPv6`,(e,t)=>{t.pattern??=lo,L.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})}}}),us=O(`$ZodCIDRv4`,(e,t)=>{t.pattern??=uo,L.init(e,t)}),ds=O(`$ZodCIDRv6`,(e,t)=>{t.pattern??=fo,L.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function fs(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var ps=O(`$ZodBase64`,(e,t)=>{t.pattern??=po,L.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{fs(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function ms(e){if(!mo.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return fs(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var hs=O(`$ZodBase64URL`,(e,t)=>{t.pattern??=mo,L.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{ms(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),gs=O(`$ZodE164`,(e,t)=>{t.pattern??=go,L.init(e,t)});function _s(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var vs=O(`$ZodJWT`,(e,t)=>{L.init(e,t),e._zod.check=n=>{_s(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),ys=O(`$ZodNumber`,(e,t)=>{I.init(e,t),e._zod.pattern=e._zod.bag.pattern??wo,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),bs=O(`$ZodNumberFormat`,(e,t)=>{Mo.init(e,t),ys.init(e,t)}),xs=O(`$ZodBoolean`,(e,t)=>{I.init(e,t),e._zod.pattern=To,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Ss=O(`$ZodUnknown`,(e,t)=>{I.init(e,t),e._zod.parse=e=>e}),Cs=O(`$ZodNever`,(e,t)=>{I.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function ws(e,t,n){e.issues.length&&t.issues.push(...Da(n,e.issues)),t.value[n]=e.value}var Ts=O(`$ZodArray`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>ws(t,n,e))):ws(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Es(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...Da(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Ds(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=ga(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Os(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Es(e,n,i,t,u,d))):Es(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}var ks=O(`$ZodObject`,(e,t)=>{if(I.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=ta(()=>Ds(t));A(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=ua,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>Es(n,t,e,s,r,i))):Es(a,t,e,s,r,i)}return i?Os(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),As=O(`$ZodObjectJIT`,(e,t)=>{ks.init(e,t);let n=e._zod.parse,r=ta(()=>Ds(t)),i=e=>{let t=new Wo([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=sa(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=sa(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
|
|
4
4
|
if (${n}.issues.length) {
|
|
5
5
|
if (${o} in input) {
|
|
6
6
|
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
@@ -59,6 +59,6 @@ var AgentCommsMeshWorker=(function(e){Object.defineProperty(e,Symbol.toStringTag
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Ui,s=!ji.jitless,c=s&&Wi.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?ss([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function us(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!ia(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>P(e,r,k())))}),t)}var ds=O(`$ZodUnion`,(e,t)=>{I.init(e,t),A(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),A(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),A(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),A(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>Ii(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>us(t,r,e,i)):us(o,r,e,i)}}),fs=O(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,ds.init(e,t);let n=e._zod.parse;A(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=Pi(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!Ui(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback||a.direction===`backward`?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,options:Array.from(r.value.keys()),input:o,path:[t.discriminator],inst:e}),i)}}),ps=O(`$ZodIntersection`,(e,t)=>{I.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>hs(e,t,n)):hs(e,i,a)}});function ms(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Gi(e)&&Gi(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=ms(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ms(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function hs(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),ia(e))return e;let o=ms(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var gs=O(`$ZodRecord`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Gi(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>P(e,r,k())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...oa(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...oa(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&no.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>P(e,r,k())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...oa(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...oa(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),_s=O(`$ZodEnum`,(e,t)=>{I.init(e,t);let n=Mi(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>qi.has(typeof e)).map(e=>typeof e==`string`?Ji(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),vs=O(`$ZodLiteral`,(e,t)=>{if(I.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?Ji(e):e?Ji(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),ys=O(`$ZodTransform`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ai(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new ki;return n.value=i,n.fallback=!0,n}});function bs(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var xs=O(`$ZodOptional`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),A(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Ii(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>bs(e,r)):bs(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Ss=O(`$ZodExactOptional`,(e,t)=>{xs.init(e,t),A(e._zod,`values`,()=>t.innerType._zod.values),A(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Cs=O(`$ZodNullable`,(e,t)=>{I.init(e,t),A(e._zod,`optin`,()=>t.innerType._zod.optin),A(e._zod,`optout`,()=>t.innerType._zod.optout),A(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Ii(e.source)}|null)$`):void 0}),A(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),ws=O(`$ZodDefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ts(e,t)):Ts(r,t)}});function Ts(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Es=O(`$ZodPrefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Ds=O(`$ZodNonOptional`,(e,t)=>{I.init(e,t),A(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Os(t,e)):Os(i,e)}});function Os(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var ks=O(`$ZodCatch`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`optout`,()=>t.innerType._zod.optout),A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>P(e,n,k()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>P(e,n,k()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),As=O(`$ZodPipe`,(e,t)=>{I.init(e,t),A(e._zod,`values`,()=>t.in._zod.values),A(e._zod,`optin`,()=>t.in._zod.optin),A(e._zod,`optout`,()=>t.out._zod.optout),A(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>js(e,t.in,n)):js(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>js(e,t.out,n)):js(r,t.out,n)}});function js(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var Ms=O(`$ZodReadonly`,(e,t)=>{I.init(e,t),A(e._zod,`propValues`,()=>t.innerType._zod.propValues),A(e._zod,`values`,()=>t.innerType._zod.values),A(e._zod,`optin`,()=>t.innerType?._zod?.optin),A(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ns):Ns(r)}});function Ns(e){return e.value=Object.freeze(e.value),e}var Ps=O(`$ZodCustom`,(e,t)=>{F.init(e,t),I.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Fs(t,n,r,e));Fs(i,n,r,e)}});function Fs(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(la(e))}}var Is,Ls=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Rs(){return new Ls}(Is=globalThis).__zod_globalRegistry??(Is.__zod_globalRegistry=Rs());var zs=globalThis.__zod_globalRegistry;function Bs(e,t){return new e({type:`string`,...N(t)})}function Vs(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function Hs(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function Us(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function Ws(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function Gs(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function Ks(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...N(t)})}function qs(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...N(t)})}function Js(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function Ys(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function Xs(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function Zs(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function Qs(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...N(t)})}function $s(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...N(t)})}function ec(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function tc(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function nc(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function rc(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function ic(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function ac(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function oc(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function sc(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function cc(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function lc(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function uc(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function dc(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function fc(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function pc(e,t){return new e({type:`number`,checks:[],...N(t)})}function mc(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function hc(e,t){return new e({type:`boolean`,...N(t)})}function gc(e){return new e({type:`unknown`})}function _c(e,t){return new e({type:`never`,...N(t)})}function vc(e,t){return new so({check:`less_than`,...N(t),value:e,inclusive:!1})}function yc(e,t){return new so({check:`less_than`,...N(t),value:e,inclusive:!0})}function bc(e,t){return new co({check:`greater_than`,...N(t),value:e,inclusive:!1})}function xc(e,t){return new co({check:`greater_than`,...N(t),value:e,inclusive:!0})}function Sc(e,t){return new lo({check:`multiple_of`,...N(t),value:e})}function Cc(e,t){return new fo({check:`max_length`,...N(t),maximum:e})}function wc(e,t){return new po({check:`min_length`,...N(t),minimum:e})}function Tc(e,t){return new mo({check:`length_equals`,...N(t),length:e})}function Ec(e,t){return new go({check:`string_format`,format:`regex`,...N(t),pattern:e})}function Dc(e){return new _o({check:`string_format`,format:`lowercase`,...N(e)})}function Oc(e){return new vo({check:`string_format`,format:`uppercase`,...N(e)})}function kc(e,t){return new yo({check:`string_format`,format:`includes`,...N(t),includes:e})}function Ac(e,t){return new bo({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function jc(e,t){return new xo({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function Mc(e){return new So({check:`overwrite`,tx:e})}function Nc(e){return Mc(t=>t.normalize(e))}function Pc(){return Mc(e=>e.trim())}function Fc(){return Mc(e=>e.toLowerCase())}function Ic(){return Mc(e=>e.toUpperCase())}function Lc(){return Mc(e=>Vi(e))}function Rc(e,t,n){return new e({type:`array`,element:t,...N(n)})}function zc(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...N(n)})}function Bc(e,t){let n=Vc(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(la(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(la(r))}},e(t.value,t)),t);return n}function Vc(e,t){let n=new F({check:`custom`,...N(t)});return n._zod.check=e,n}function Hc(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??zs,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function R(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,R(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&z(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Uc(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
62
|
+
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=ua,s=!Qi.jitless,c=s&&da.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Os([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function js(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Ta(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>P(e,r,k())))}),t)}var Ms=O(`$ZodUnion`,(e,t)=>{I.init(e,t),A(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),A(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),A(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),A(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>ra(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>js(t,r,e,i)):js(o,r,e,i)}}),Ns=O(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Ms.init(e,t);let n=e._zod.parse;A(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=ta(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!ua(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback||a.direction===`backward`?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,options:Array.from(r.value.keys()),input:o,path:[t.discriminator],inst:e}),i)}}),Ps=O(`$ZodIntersection`,(e,t)=>{I.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Is(e,t,n)):Is(e,i,a)}});function Fs(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(fa(e)&&fa(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Fs(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Fs(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Is(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Ta(e))return e;let o=Fs(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var Ls=O(`$ZodRecord`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!fa(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>P(e,r,k())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...Da(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...Da(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&wo.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>P(e,r,k())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Da(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Da(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Rs=O(`$ZodEnum`,(e,t)=>{I.init(e,t);let n=$i(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>ma.has(typeof e)).map(e=>typeof e==`string`?ha(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),zs=O(`$ZodLiteral`,(e,t)=>{if(I.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?ha(e):e?ha(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Bs=O(`$ZodTransform`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Zi(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new Xi;return n.value=i,n.fallback=!0,n}});function Vs(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Hs=O(`$ZodOptional`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),A(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ra(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>Vs(e,r)):Vs(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Us=O(`$ZodExactOptional`,(e,t)=>{Hs.init(e,t),A(e._zod,`values`,()=>t.innerType._zod.values),A(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Ws=O(`$ZodNullable`,(e,t)=>{I.init(e,t),A(e._zod,`optin`,()=>t.innerType._zod.optin),A(e._zod,`optout`,()=>t.innerType._zod.optout),A(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ra(e.source)}|null)$`):void 0}),A(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Gs=O(`$ZodDefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ks(e,t)):Ks(r,t)}});function Ks(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var qs=O(`$ZodPrefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Js=O(`$ZodNonOptional`,(e,t)=>{I.init(e,t),A(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Ys(t,e)):Ys(i,e)}});function Ys(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var Xs=O(`$ZodCatch`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,A(e._zod,`optout`,()=>t.innerType._zod.optout),A(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>P(e,n,k()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>P(e,n,k()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Zs=O(`$ZodPipe`,(e,t)=>{I.init(e,t),A(e._zod,`values`,()=>t.in._zod.values),A(e._zod,`optin`,()=>t.in._zod.optin),A(e._zod,`optout`,()=>t.out._zod.optout),A(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Qs(e,t.in,n)):Qs(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Qs(e,t.out,n)):Qs(r,t.out,n)}});function Qs(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var $s=O(`$ZodReadonly`,(e,t)=>{I.init(e,t),A(e._zod,`propValues`,()=>t.innerType._zod.propValues),A(e._zod,`values`,()=>t.innerType._zod.values),A(e._zod,`optin`,()=>t.innerType?._zod?.optin),A(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(ec):ec(r)}});function ec(e){return e.value=Object.freeze(e.value),e}var tc=O(`$ZodCustom`,(e,t)=>{F.init(e,t),I.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>nc(t,n,r,e));nc(i,n,r,e)}});function nc(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Aa(e))}}var rc,ic=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function ac(){return new ic}(rc=globalThis).__zod_globalRegistry??(rc.__zod_globalRegistry=ac());var oc=globalThis.__zod_globalRegistry;function sc(e,t){return new e({type:`string`,...N(t)})}function cc(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function lc(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function uc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function dc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function fc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function pc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...N(t)})}function mc(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...N(t)})}function hc(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function gc(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function _c(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function vc(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function yc(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...N(t)})}function bc(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...N(t)})}function xc(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function Sc(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function Cc(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function wc(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function Tc(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function Ec(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function Dc(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function Oc(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function kc(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function Ac(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function jc(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function Mc(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function Nc(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function Pc(e,t){return new e({type:`number`,checks:[],...N(t)})}function Fc(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function Ic(e,t){return new e({type:`boolean`,...N(t)})}function Lc(e){return new e({type:`unknown`})}function Rc(e,t){return new e({type:`never`,...N(t)})}function zc(e,t){return new ko({check:`less_than`,...N(t),value:e,inclusive:!1})}function Bc(e,t){return new ko({check:`less_than`,...N(t),value:e,inclusive:!0})}function Vc(e,t){return new Ao({check:`greater_than`,...N(t),value:e,inclusive:!1})}function Hc(e,t){return new Ao({check:`greater_than`,...N(t),value:e,inclusive:!0})}function Uc(e,t){return new jo({check:`multiple_of`,...N(t),value:e})}function Wc(e,t){return new No({check:`max_length`,...N(t),maximum:e})}function Gc(e,t){return new Po({check:`min_length`,...N(t),minimum:e})}function Kc(e,t){return new Fo({check:`length_equals`,...N(t),length:e})}function qc(e,t){return new Lo({check:`string_format`,format:`regex`,...N(t),pattern:e})}function Jc(e){return new Ro({check:`string_format`,format:`lowercase`,...N(e)})}function Yc(e){return new zo({check:`string_format`,format:`uppercase`,...N(e)})}function Xc(e,t){return new Bo({check:`string_format`,format:`includes`,...N(t),includes:e})}function Zc(e,t){return new Vo({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function Qc(e,t){return new Ho({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function $c(e){return new Uo({check:`overwrite`,tx:e})}function el(e){return $c(t=>t.normalize(e))}function tl(){return $c(e=>e.trim())}function nl(){return $c(e=>e.toLowerCase())}function rl(){return $c(e=>e.toUpperCase())}function il(){return $c(e=>ca(e))}function al(e,t,n){return new e({type:`array`,element:t,...N(n)})}function ol(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...N(n)})}function sl(e,t){let n=cl(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Aa(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Aa(r))}},e(t.value,t)),t);return n}function cl(e,t){let n=new F({check:`custom`,...N(t)});return n._zod.check=e,n}function ll(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??oc,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function R(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,R(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&z(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function ul(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
63
63
|
|
|
64
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Wc(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Kc(t,`input`,e.processors),output:Kc(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function z(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return z(r.element,n);if(r.type===`set`)return z(r.valueType,n);if(r.type===`lazy`)return z(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return z(r.innerType,n);if(r.type===`intersection`)return z(r.left,n)||z(r.right,n);if(r.type===`record`||r.type===`map`)return z(r.keyType,n)||z(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:z(r.in,n)||z(r.out,n);if(r.type===`object`){for(let e in r.shape)if(z(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(z(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(z(e,n))return!0;return!!(r.rest&&z(r.rest,n))}return!1}var Gc=(e,t={})=>n=>{let r=Hc({...n,processors:t});return R(e,r),Uc(r,e),Wc(r,e)},Kc=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Hc({...i??{},target:a,io:t,processors:n});return R(e,o),Uc(o,e),Wc(o,e)},qc={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Jc=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=qc[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Yc=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},Xc=(e,t,n,r)=>{n.type=`boolean`},Zc=(e,t,n,r)=>{n.not={}},Qc=(e,t,n,r)=>{let i=e._zod.def,a=Mi(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},$c=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},el=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},tl=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},nl=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=R(a.element,t,{...r,path:[...r.path,`items`]})},rl=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=R(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=R(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},il=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>R(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},al=(e,t,n,r)=>{let i=e._zod.def,a=R(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=R(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},ol=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=R(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=R(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=R(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},sl=(e,t,n,r)=>{let i=e._zod.def,a=R(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},cl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ll=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},ul=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},dl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},fl=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;R(o,t,r);let s=t.seen.get(e);s.ref=o},pl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},ml=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},hl=O(`ZodISODateTime`,(e,t)=>{Lo.init(e,t),U.init(e,t)});function gl(e){return lc(hl,e)}var _l=O(`ZodISODate`,(e,t)=>{Ro.init(e,t),U.init(e,t)});function vl(e){return uc(_l,e)}var yl=O(`ZodISOTime`,(e,t)=>{zo.init(e,t),U.init(e,t)});function bl(e){return dc(yl,e)}var xl=O(`ZodISODuration`,(e,t)=>{Bo.init(e,t),U.init(e,t)});function Sl(e){return fc(xl,e)}var B=O(`ZodError`,(e,t)=>{da.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>ma(e,t)},flatten:{value:t=>pa(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Ni,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Ni,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Cl=ha(B),wl=ga(B),Tl=_a(B),El=ya(B),Dl=xa(B),Ol=Sa(B),kl=Ca(B),Al=wa(B),jl=Ta(B),Ml=Ea(B),Nl=Da(B),Pl=Oa(B),Fl=new WeakMap;function Il(e,t,n){let r=Object.getPrototypeOf(e),i=Fl.get(r);if(i||(i=new Set,Fl.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var V=O(`ZodType`,(e,t)=>(I.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Kc(e,`input`),output:Kc(e,`output`)}}),e.toJSONSchema=Gc(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>Cl(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Tl(e,t,n),e.parseAsync=async(t,n)=>wl(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>El(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Dl(e,t,n),e.decode=(t,n)=>Ol(e,t,n),e.encodeAsync=async(t,n)=>kl(e,t,n),e.decodeAsync=async(t,n)=>Al(e,t,n),e.safeEncode=(t,n)=>jl(e,t,n),e.safeDecode=(t,n)=>Ml(e,t,n),e.safeEncodeAsync=async(t,n)=>Nl(e,t,n),e.safeDecodeAsync=async(t,n)=>Pl(e,t,n),Il(e,`ZodType`,{check(...e){let t=this.def;return this.clone(j(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return M(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Gu(e,t))},superRefine(e,t){return this.check(Ku(e,t))},overwrite(e){return this.check(Mc(e))},optional(){return Du(this)},exactOptional(){return ku(this)},nullable(){return ju(this)},nullish(){return Du(ju(this))},nonoptional(e){return Lu(this,e)},array(){return G(this)},or(e){return q([this,e])},and(e){return yu(this,e)},transform(e){return Vu(this,Tu(e))},default(e){return Nu(this,e)},prefault(e){return Fu(this,e)},catch(e){return zu(this,e)},pipe(e){return Vu(this,e)},readonly(){return Uu(this)},describe(e){let t=this.clone();return zs.add(t,{description:e}),t},meta(...e){if(e.length===0)return zs.get(this);let t=this.clone();return zs.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return zs.get(e)?.description},configurable:!0}),e)),Ll=O(`_ZodString`,(e,t)=>{To.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jc(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Il(e,`_ZodString`,{regex(...e){return this.check(Ec(...e))},includes(...e){return this.check(kc(...e))},startsWith(...e){return this.check(Ac(...e))},endsWith(...e){return this.check(jc(...e))},min(...e){return this.check(wc(...e))},max(...e){return this.check(Cc(...e))},length(...e){return this.check(Tc(...e))},nonempty(...e){return this.check(wc(1,...e))},lowercase(e){return this.check(Dc(e))},uppercase(e){return this.check(Oc(e))},trim(){return this.check(Pc())},normalize(...e){return this.check(Nc(...e))},toLowerCase(){return this.check(Fc())},toUpperCase(){return this.check(Ic())},slugify(){return this.check(Lc())}})}),Rl=O(`ZodString`,(e,t)=>{To.init(e,t),Ll.init(e,t),e.email=t=>e.check(Vs(zl,t)),e.url=t=>e.check(qs(Hl,t)),e.jwt=t=>e.check(cc(ru,t)),e.emoji=t=>e.check(Js(Ul,t)),e.guid=t=>e.check(Hs(Bl,t)),e.uuid=t=>e.check(Us(Vl,t)),e.uuidv4=t=>e.check(Ws(Vl,t)),e.uuidv6=t=>e.check(Gs(Vl,t)),e.uuidv7=t=>e.check(Ks(Vl,t)),e.nanoid=t=>e.check(Ys(Wl,t)),e.guid=t=>e.check(Hs(Bl,t)),e.cuid=t=>e.check(Xs(Gl,t)),e.cuid2=t=>e.check(Zs(Kl,t)),e.ulid=t=>e.check(Qs(ql,t)),e.base64=t=>e.check(ac(eu,t)),e.base64url=t=>e.check(oc(tu,t)),e.xid=t=>e.check($s(Jl,t)),e.ksuid=t=>e.check(ec(Yl,t)),e.ipv4=t=>e.check(tc(Xl,t)),e.ipv6=t=>e.check(nc(Zl,t)),e.cidrv4=t=>e.check(rc(Ql,t)),e.cidrv6=t=>e.check(ic($l,t)),e.e164=t=>e.check(sc(nu,t)),e.datetime=t=>e.check(gl(t)),e.date=t=>e.check(vl(t)),e.time=t=>e.check(bl(t)),e.duration=t=>e.check(Sl(t))});function H(e){return Bs(Rl,e)}var U=O(`ZodStringFormat`,(e,t)=>{L.init(e,t),Ll.init(e,t)}),zl=O(`ZodEmail`,(e,t)=>{Oo.init(e,t),U.init(e,t)}),Bl=O(`ZodGUID`,(e,t)=>{Eo.init(e,t),U.init(e,t)}),Vl=O(`ZodUUID`,(e,t)=>{Do.init(e,t),U.init(e,t)}),Hl=O(`ZodURL`,(e,t)=>{ko.init(e,t),U.init(e,t)}),Ul=O(`ZodEmoji`,(e,t)=>{Ao.init(e,t),U.init(e,t)}),Wl=O(`ZodNanoID`,(e,t)=>{jo.init(e,t),U.init(e,t)}),Gl=O(`ZodCUID`,(e,t)=>{Mo.init(e,t),U.init(e,t)}),Kl=O(`ZodCUID2`,(e,t)=>{No.init(e,t),U.init(e,t)}),ql=O(`ZodULID`,(e,t)=>{Po.init(e,t),U.init(e,t)}),Jl=O(`ZodXID`,(e,t)=>{Fo.init(e,t),U.init(e,t)}),Yl=O(`ZodKSUID`,(e,t)=>{Io.init(e,t),U.init(e,t)}),Xl=O(`ZodIPv4`,(e,t)=>{Vo.init(e,t),U.init(e,t)}),Zl=O(`ZodIPv6`,(e,t)=>{Ho.init(e,t),U.init(e,t)}),Ql=O(`ZodCIDRv4`,(e,t)=>{Uo.init(e,t),U.init(e,t)}),$l=O(`ZodCIDRv6`,(e,t)=>{Wo.init(e,t),U.init(e,t)}),eu=O(`ZodBase64`,(e,t)=>{Ko.init(e,t),U.init(e,t)}),tu=O(`ZodBase64URL`,(e,t)=>{Jo.init(e,t),U.init(e,t)}),nu=O(`ZodE164`,(e,t)=>{Yo.init(e,t),U.init(e,t)}),ru=O(`ZodJWT`,(e,t)=>{Zo.init(e,t),U.init(e,t)}),iu=O(`ZodNumber`,(e,t)=>{Qo.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yc(e,t,n,r),Il(e,`ZodNumber`,{gt(e,t){return this.check(bc(e,t))},gte(e,t){return this.check(xc(e,t))},min(e,t){return this.check(xc(e,t))},lt(e,t){return this.check(vc(e,t))},lte(e,t){return this.check(yc(e,t))},max(e,t){return this.check(yc(e,t))},int(e){return this.check(ou(e))},safe(e){return this.check(ou(e))},positive(e){return this.check(bc(0,e))},nonnegative(e){return this.check(xc(0,e))},negative(e){return this.check(vc(0,e))},nonpositive(e){return this.check(yc(0,e))},multipleOf(e,t){return this.check(Sc(e,t))},step(e,t){return this.check(Sc(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function W(e){return pc(iu,e)}var au=O(`ZodNumberFormat`,(e,t)=>{$o.init(e,t),iu.init(e,t)});function ou(e){return mc(au,e)}var su=O(`ZodBoolean`,(e,t)=>{es.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xc(e,t,n,r)});function cu(e){return hc(su,e)}var lu=O(`ZodUnknown`,(e,t)=>{ts.init(e,t),V.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function uu(){return gc(lu)}var du=O(`ZodNever`,(e,t)=>{ns.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zc(e,t,n,r)});function fu(e){return _c(du,e)}var pu=O(`ZodArray`,(e,t)=>{is.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>nl(e,t,n,r),e.element=t.element,Il(e,`ZodArray`,{min(e,t){return this.check(wc(e,t))},nonempty(e){return this.check(wc(1,e))},max(e,t){return this.check(Cc(e,t))},length(e,t){return this.check(Tc(e,t))},unwrap(){return this.element}})});function G(e,t){return Rc(pu,e,t)}var mu=O(`ZodObject`,(e,t)=>{ls.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rl(e,t,n,r),A(e,`shape`,()=>t.shape),Il(e,`ZodObject`,{keyof(){return Su(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:uu()})},loose(){return this.clone({...this._zod.def,catchall:uu()})},strict(){return this.clone({...this._zod.def,catchall:fu()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return $i(this,e)},safeExtend(e){return ea(this,e)},merge(e){return ta(this,e)},pick(e){return Zi(this,e)},omit(e){return Qi(this,e)},partial(...e){return na(Eu,this,e[0])},required(...e){return ra(Iu,this,e[0])}})});function K(e,t){return new mu({type:`object`,shape:e??{},...N(t)})}var hu=O(`ZodUnion`,(e,t)=>{ds.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>il(e,t,n,r),e.options=t.options});function q(e,t){return new hu({type:`union`,options:e,...N(t)})}var gu=O(`ZodDiscriminatedUnion`,(e,t)=>{hu.init(e,t),fs.init(e,t)});function _u(e,t,n){return new gu({type:`union`,options:t,discriminator:e,...N(n)})}var vu=O(`ZodIntersection`,(e,t)=>{ps.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>al(e,t,n,r)});function yu(e,t){return new vu({type:`intersection`,left:e,right:t})}var bu=O(`ZodRecord`,(e,t)=>{gs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ol(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function J(e,t,n){return!t||!t._zod?new bu({type:`record`,keyType:H(),valueType:e,...N(t)}):new bu({type:`record`,keyType:e,valueType:t,...N(n)})}var xu=O(`ZodEnum`,(e,t)=>{_s.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qc(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new xu({...t,checks:[],...N(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new xu({...t,checks:[],...N(r),entries:i})}});function Su(e,t){return new xu({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...N(t)})}var Cu=O(`ZodLiteral`,(e,t)=>{vs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$c(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Y(e,t){return new Cu({type:`literal`,values:Array.isArray(e)?e:[e],...N(t)})}var wu=O(`ZodTransform`,(e,t)=>{ys.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>tl(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ai(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(la(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(la(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function Tu(e){return new wu({type:`transform`,transform:e})}var Eu=O(`ZodOptional`,(e,t)=>{xs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ml(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Du(e){return new Eu({type:`optional`,innerType:e})}var Ou=O(`ZodExactOptional`,(e,t)=>{Ss.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ml(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ku(e){return new Ou({type:`optional`,innerType:e})}var Au=O(`ZodNullable`,(e,t)=>{Cs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ju(e){return new Au({type:`nullable`,innerType:e})}var Mu=O(`ZodDefault`,(e,t)=>{ws.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ll(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Nu(e,t){return new Mu({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Ki(t)}})}var Pu=O(`ZodPrefault`,(e,t)=>{Es.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ul(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fu(e,t){return new Pu({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Ki(t)}})}var Iu=O(`ZodNonOptional`,(e,t)=>{Ds.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Lu(e,t){return new Iu({type:`nonoptional`,innerType:e,...N(t)})}var Ru=O(`ZodCatch`,(e,t)=>{ks.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>dl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function zu(e,t){return new Ru({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Bu=O(`ZodPipe`,(e,t)=>{As.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fl(e,t,n,r),e.in=t.in,e.out=t.out});function Vu(e,t){return new Bu({type:`pipe`,in:e,out:t})}var Hu=O(`ZodReadonly`,(e,t)=>{Ms.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uu(e){return new Hu({type:`readonly`,innerType:e})}var Wu=O(`ZodCustom`,(e,t)=>{Ps.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>el(e,t,n,r)});function Gu(e,t={}){return zc(Wu,e,t)}function Ku(e,t){return Bc(e,t)}function qu(e){return`is`in e&&typeof e.is==`function`}function X(e){if(Object.defineProperty(e,"is",{value:t=>e.safeParse(t).success,enumerable:!0}),!qu(e))throw Error(`unreachable: is was just defined above`);return e}var Ju=X(q([Y(`discoverable`),Y(`quiet`),Y(`dark`)])),Yu=X(q([Y(`visible`),Y(`hidden`),Y(`ghost`)])),Xu=X(q([Y(`active`),Y(`idle`),Y(`busy`),Y(`offline`)])),Zu=X(q([Y(`public`),Y(`private`),Y(`secret`)])),Qu=X(q([Y(`steer`),Y(`followUp`),Y(`info`)])),$u=X(K({id:H(),version:W(),name:H(),harness:H(),cwd:H(),pid:W(),startedAt:H(),visibility:Yu,status:Xu,tags:G(H()),subscribedRooms:G(H())})),ed=X(K({id:H(),version:W(),name:H(),type:Zu,owner:H(),createdAt:H(),description:H(),members:G(H()),invited:G(H()),memberJoins:J(H(),W()),memberLeaves:J(H(),W()),invitedJoins:J(H(),W()),invitedLeaves:J(H(),W())})),td=X(K({id:H(),from:H(),room:H(),content:H(),timestamp:H(),replyTo:H().optional(),readBy:G(H()),streamingBehavior:Qu.optional()})),nd=X(K({id:H(),from:H(),to:H(),content:H(),timestamp:H(),readBy:G(H()),streamingBehavior:Qu.optional()})),rd=X(q([Y(`timeout`),Y(`not_connected`),Y(`connection_lost`)])),id=X(_u(`status`,[K({status:Y(`delivered`)}),K({status:Y(`read`)}),K({status:Y(`queued`),reason:rd}),K({status:Y(`refused`),code:H()}),K({status:Y(`dropped`)}),K({status:Y(`expired`)})])),ad=X(K({id:H(),name:H(),status:Xu})),od=X(_u(`type`,[K({type:Y(`room_message`),message:td}),K({type:Y(`dm`),message:nd}),K({type:Y(`room_invite`),room:H(),roomDescription:H(),from:H(),fromName:H(),fromCwd:H()}),K({type:Y(`member_joined`),room:H(),agent:H()}),K({type:Y(`member_left`),room:H(),agent:H()}),K({type:Y(`room_members`),room:H(),members:G(ad)}),K({type:Y(`member_status`),room:H(),agent:H(),status:Xu}),K({type:Y(`delivery_status`),messageId:H(),agent:H(),delivery:id,room:H().optional()}),K({type:Y(`invite_declined`),room:H(),agent:H(),agentName:H(),reason:H()}),K({type:Y(`name_changed`),agent:H(),oldName:H(),newName:H()}),K({type:Y(`connection_request`),connectionId:H(),peerId:H(),dataPort:W(),name:H(),fingerprint:H()}),K({type:Y(`room_join_request`),room:H(),requesterId:H()}),K({type:Y(`capability_request`),requestId:H(),capability:H(),scopeKind:H(),scopePath:H().optional(),requesterDevice:H()})]));X(K({code:H(),expiresAt:H(),deviceId:H(),signature:H().optional()})),X(_u(`action`,[K({action:Y(`register`),name:H(),visibility:Yu,tags:G(H())}),K({action:Y(`update`),visibility:Yu.optional(),status:Xu.optional(),name:H().optional(),tags:G(H()).optional()}),K({action:Y(`whoami`)}),K({action:Y(`web_url`)}),K({action:Y(`create_room`),name:H(),type:Zu,description:H()}),K({action:Y(`list_rooms`)}),K({action:Y(`join_room`),room:H()}),K({action:Y(`leave_room`),room:H()}),K({action:Y(`send`),target:H(),content:H(),replyTo:H().optional(),streamingBehavior:Qu.optional()}),K({action:Y(`dm`),target:H(),content:H(),streamingBehavior:Qu.optional()}),K({action:Y(`list_agents`)}),K({action:Y(`read_room`),room:H(),since:H().optional()}),K({action:Y(`invite`),room:H(),agent:H()}),K({action:Y(`kick`),room:H(),agent:H()}),K({action:Y(`decline_invite`),room:H(),reason:H()}),K({action:Y(`destroy_room`),room:H()}),K({action:Y(`mesh_connect`),host:H(),port:W(),policy:H().optional()}),K({action:Y(`mesh_accept`),connectionId:H()}),K({action:Y(`mesh_reject`),connectionId:H(),reason:H()}),K({action:Y(`mesh_pending`)}),K({action:Y(`room_accept`),room:H(),requesterId:H()}),K({action:Y(`room_reject`),room:H(),requesterId:H(),reason:H().optional()}),K({action:Y(`room_pending`)}),K({action:Y(`capability_accept`),requestId:H(),expires:W(),delegationsRemaining:W().optional(),capability:H().optional()}),K({action:Y(`capability_reject`),requestId:H(),reason:H().optional()}),K({action:Y(`capability_pending`)}),K({action:Y(`mesh_discover`),method:H().optional()}),K({action:Y(`mesh_advertise`),method:H(),name:H(),port:W().optional(),adapter:H().optional()}),K({action:Y(`mesh_unadvertise`),id:H()}),K({action:Y(`mesh_interfaces`)}),K({action:Y(`lan_web_uis`)}),K({action:Y(`mesh_listen`),host:H(),port:W().optional(),policy:H().optional()}),K({action:Y(`mesh_unlisten`),id:H()}),K({action:Y(`mesh_listeners`)}),K({action:Y(`mesh_set_visibility`),visibility:Ju,adapter:H().optional()}),K({action:Y(`mesh_get_visibility`)}),K({action:Y(`gateway_trust`),device:H(),principal:cu().optional(),machine:cu().optional()}),K({action:Y(`gateway_untrust`),device:H(),principal:cu().optional(),machine:cu().optional()}),K({action:Y(`gateway_list_trusted`)}),K({action:Y(`petname_set`),device:H(),name:H()}),K({action:Y(`petname_clear`),device:H()}),K({action:Y(`petname_list`)}),K({action:Y(`machine_name`),name:H().optional()}),K({action:Y(`principal_name`),name:H().optional()}),K({action:Y(`dm_admit`),target:H(),principal:cu().optional()}),K({action:Y(`dm_use_grant`),target:H(),grant:H()}),K({action:Y(`dm_revoke`),target:H()}),K({action:Y(`gateway_generate_connection_code`),ttlMs:W().optional(),privateKey:H().optional(),passphrase:H().optional()}),K({action:Y(`gateway_redeem_connection_code`),code:H(),expiresAt:H(),device:H(),signature:H().optional(),publicKey:H().optional(),fingerprint:H().optional()}),K({action:Y(`query_version`),device:H()}),K({action:Y(`mesh_graph`)}),K({action:Y(`mesh_trace`),target:H(),timeoutMs:W().optional()})]));var Z=K({content:H(),isError:cu()}),sd=q([Y(`public`),Y(`private`),Y(`secret`)]),cd=K({kind:q([Y(`direct`),Y(`relay`)]),from:H(),to:H(),via:H().optional()}),ld=K({nodes:G(H()),edges:G(cd)}),ud=K({id:H(),petname:H().optional(),selfName:H().optional()}),dd=K({relayed:cu(),hubAddress:H().optional()}),fd=K({rttMs:W(),local:dd,remote:dd.optional(),outcome:K({result:H(),code:H().optional()}).loose()}),pd=_u(`type`,[K({type:Y(`agent_upsert`),agent:$u}),K({type:Y(`agent_offline`),agentId:H()}),K({type:Y(`room_upsert`),room:ed}),K({type:Y(`room_delete`),roomId:H()}),K({type:Y(`message_add`),roomId:H(),message:td}),K({type:Y(`dm_add`),key:H(),message:nd}),K({type:Y(`delivery`),agentId:H(),event:od})]),md=K({agents:J(H(),$u),rooms:J(H(),ed),messages:J(H(),G(td)),dms:J(H(),G(nd))}),hd=_u(`kind`,[K({kind:Y(`state_sync`),state:md}),K({kind:Y(`state_patch`),patch:pd}),K({kind:Y(`delivery`),event:od})]),gd=K({endpoint:H(),keys:K({p256dh:H(),auth:H()})}),_d={send:w.input(K({target:H(),content:H()})).output(Z),dm:w.input(K({target:H(),content:H()})).output(Z),joinRoom:w.input(K({room:H()})).output(Z),leaveRoom:w.input(K({room:H().optional()})).output(Z),createRoom:w.input(K({name:H(),type:sd,description:H().optional()})).output(Z),listRooms:w.input(K({})).output(Z),listAgents:w.input(K({})).output(Z),readRoom:w.input(K({room:H().optional()})).output(Z),destroyRoom:w.input(K({room:H()})).output(Z),invite:w.input(K({room:H(),agent:H()})).output(Z),declineInvite:w.input(K({room:H(),reason:H()})).output(Z),kick:w.input(K({room:H(),agent:H()})).output(Z),renameAgent:w.input(K({agent:H(),name:H()})).output(Z),pushSubscribe:w.input(K({subscription:gd,agentId:H().optional()})).output(Z),pushUnsubscribe:w.input(K({agentId:H().optional()})).output(Z),subscribeEvents:w.input(K({lastEventId:H().optional()})).output(Tr(hd)),getRoomMessages:w.input(K({room:H(),since:H().optional()})).output(G(td)),getMeshGraph:w.input(K({})).output(ld),getDisplayNames:w.input(K({})).output(G(ud)),getMeshTrace:w.input(K({target:H(),timeoutMs:W().optional()})).output(fd),disconnect:w.input(K({})).output(K({}))};function vd(e){if(typeof e!=`object`||!e||!(`endpoint`in e)||typeof e.endpoint!=`string`||!(`keys`in e))return!1;let t=e.keys;return!(typeof t!=`object`||!t||!(`p256dh`in t)||typeof t.p256dh!=`string`||!(`auth`in t)||typeof t.auth!=`string`)}async function yd(e,t){let n=e=>{let n=t[e];return typeof n==`string`?n:``},r=e=>{let n=t[e];return typeof n==`string`?n:void 0},i=()=>{let e=t.type;return e===`public`||e===`private`||e===`secret`?e:`public`};switch(t.action){case`send`:return e.send({target:n(`target`),content:n(`content`)});case`dm`:return e.dm({target:n(`target`),content:n(`content`)});case`join_room`:return e.joinRoom({room:n(`room`)});case`leave_room`:return e.leaveRoom({room:r(`room`)});case`create_room`:return e.createRoom({name:n(`name`),type:i(),description:r(`description`)});case`list_rooms`:return e.listRooms({});case`list_agents`:return e.listAgents({});case`read_room`:return e.readRoom({room:r(`room`)});case`destroy_room`:return e.destroyRoom({room:n(`room`)});case`invite`:return e.invite({room:n(`room`),agent:n(`agent`)});case`decline_invite`:return e.declineInvite({room:n(`room`),reason:n(`reason`)});case`kick`:return e.kick({room:n(`room`),agent:n(`agent`)});case`rename_agent`:return e.renameAgent({agent:n(`agent`),name:n(`name`)});case`push_subscribe`:{let n=t.subscription;return vd(n)?e.pushSubscribe({subscription:n,agentId:r(`agentId`)}):{content:`Invalid push subscription`,isError:!0}}case`push_unsubscribe`:return e.pushUnsubscribe({agentId:r(`agentId`)});default:return{content:`Unknown action: ${String(t.action)}`,isError:!0}}}var bd=new Map,xd=new Map,Sd=new Map,Cd=new Map;function wd(e){for(let[t,n]of Object.entries(e.agents))bd.set(t,n);for(let[t,n]of Object.entries(e.rooms))xd.set(t,n);for(let[t,n]of Object.entries(e.messages))Sd.set(t,n);for(let[t,n]of Object.entries(e.dms))Cd.set(t,n)}function Td(e){switch(e.type){case`agent_upsert`:bd.set(e.agent.id,e.agent);break;case`agent_offline`:{let t=bd.get(e.agentId);t&&(t.status=`offline`,bd.set(e.agentId,t));break}case`room_upsert`:xd.set(e.room.id,e.room);break;case`room_delete`:xd.delete(e.roomId);break;case`message_add`:{let t=Sd.get(e.roomId)??[];t.push(e.message),Sd.set(e.roomId,t);break}case`dm_add`:{let t=Cd.get(e.key)??[];t.push(e.message),Cd.set(e.key,t);break}case`delivery`:break;case`message_read`:if(e.room!==void 0){let t=Sd.get(e.room);if(t){let n=t.find(t=>t.id===e.messageId);n&&!n.readBy.includes(e.readBy)&&n.readBy.push(e.readBy)}}else for(let[,t]of Cd){let n=t.find(t=>t.id===e.messageId);n&&!n.readBy.includes(e.readBy)&&n.readBy.push(e.readBy)}}}function Ed(){return{agents:[...bd.values()],rooms:[...xd.values()]}}var Dd,Od=0,kd,Ad=new Di,jd=1e3,Md=3e4;function Nd(e){let t=yt(new Jt({connect:async()=>{let t=new WebSocket(e);return kd=t,t.addEventListener(`open`,()=>{Ld({type:`connected`})}),t.addEventListener(`close`,()=>{Ld({type:`disconnected`})}),new Promise((e,n)=>{t.addEventListener(`open`,()=>{e(t)},{once:!0}),t.addEventListener(`error`,n,{once:!0})})},reconnect:{enabled:!0,delay:e=>e.attempt===1?0:Math.min(jd*2**e.attempt,Md)},plugins:[new Yt]}));Dd=t,Fd(t,++Od)}function Pd(){++Od,Dd=void 0,kd?.close(),kd=void 0}async function Fd(e,t){let n;for(;t===Od;)try{let r=await e.subscribeEvents(n===void 0?{}:{lastEventId:n});for await(let e of r){if(t!==Od)return;let r=We(e);switch(r?.id!==void 0&&(n=r.id),Ad.publish(e),e.kind){case`state_sync`:wd(e.state),Ld({type:`state`,state:Ed()});break;case`state_patch`:Td(e.patch),Ld({type:`patch`,patch:e.patch})}}return}catch{}}var Id=new Set;function Ld(e){let t=JSON.stringify(e);for(let e of Id)try{e.postMessage(t)}catch{}}function Rd(e){switch(e.type){case`init`:Nd(e.url);break;case`action`:{let t=Dd;if(!t)break;let n=e.id;yd(t,e.action).then(e=>{Ld({type:`actionResult`,id:n,result:e})}).catch(e=>{Ld({type:`actionError`,id:n,message:e instanceof Error?e.message:String(e)})});break}case`getState`:Ld({type:`state`,state:Ed()})}}function zd(e){if(typeof e!=`object`||!e||!(`type`in e))return!1;let t=e.type;return typeof t==`string`&&(t===`init`||t===`action`||t===`getState`)}function Bd(){return{agents:Object.fromEntries(bd),rooms:Object.fromEntries(xd),messages:Object.fromEntries(Sd),dms:Object.fromEntries(Cd)}}async function Q(e){return Dd?yd(Dd,e):{content:`Not connected to mesh yet`,isError:!0}}function Vd(){if(!Dd)throw Error(`Not connected to mesh yet`);return Dd}var $=qr(_d).$context(),Hd={};Hd.current=new wi({send:$.send.handler(async({input:e})=>Q({action:`send`,...e})),dm:$.dm.handler(async({input:e})=>Q({action:`dm`,...e})),joinRoom:$.joinRoom.handler(async({input:e})=>Q({action:`join_room`,room:e.room})),leaveRoom:$.leaveRoom.handler(async({input:e})=>Q({action:`leave_room`,room:e.room})),createRoom:$.createRoom.handler(async({input:e})=>Q({action:`create_room`,name:e.name,type:e.type,description:e.description})),listRooms:$.listRooms.handler(async()=>Q({action:`list_rooms`})),listAgents:$.listAgents.handler(async()=>Q({action:`list_agents`})),readRoom:$.readRoom.handler(async({input:e})=>Q({action:`read_room`,room:e.room})),destroyRoom:$.destroyRoom.handler(async({input:e})=>Q({action:`destroy_room`,room:e.room})),invite:$.invite.handler(async({input:e})=>Q({action:`invite`,room:e.room,agent:e.agent})),declineInvite:$.declineInvite.handler(async({input:e})=>Q({action:`decline_invite`,room:e.room,reason:e.reason})),kick:$.kick.handler(async({input:e})=>Q({action:`kick`,room:e.room,agent:e.agent})),renameAgent:$.renameAgent.handler(async({input:e})=>Q({action:`rename_agent`,agent:e.agent,name:e.name})),pushSubscribe:$.pushSubscribe.handler(async({input:e})=>Q({action:`push_subscribe`,subscription:e.subscription,agentId:e.agentId})),pushUnsubscribe:$.pushUnsubscribe.handler(async({input:e})=>Q({action:`push_unsubscribe`,agentId:e.agentId})),getRoomMessages:$.getRoomMessages.handler(async({input:e})=>Vd().getRoomMessages(e)),getMeshGraph:$.getMeshGraph.handler(async()=>Vd().getMeshGraph({})),getDisplayNames:$.getDisplayNames.handler(async()=>Vd().getDisplayNames({})),getMeshTrace:$.getMeshTrace.handler(async({input:e})=>Vd().getMeshTrace(e)),subscribeEvents:$.subscribeEvents.handler(async function*({input:e,signal:t}){e.lastEventId===void 0&&(yield{kind:`state_sync`,state:Bd()}),yield*Ad.subscribe({...t?{signal:t}:{},...e.lastEventId===void 0?{}:{lastEventId:e.lastEventId}})}),disconnect:$.disconnect.handler(({context:e})=>(setTimeout(()=>{Hd.current?.close(e.port)},0),{}))});function Ud(e){Hd.current?.upgrade(e,{context:{port:e}})}return typeof self<`u`&&self.addEventListener(`connect`,e=>{let t=e.ports[0];if(t!==void 0){Id.add(t);try{t.postMessage(JSON.stringify({type:`state`,state:Ed()}))}catch{}t.onmessage=e=>{let t=JSON.parse(typeof e.data==`string`?e.data:String(e.data));zd(t)&&Rd(t)},Ud(t)}}),e.agents=bd,e.applyPatch=Td,e.applyStateSync=wd,e.connect=Nd,e.disconnect=Pd,e.dms=Cd,e.getStateSnapshot=Ed,e.localPublisher=Ad,e.messages=Sd,e.ports=Id,e.rooms=xd,e.upgradeTabRpcPort=Ud,e})({});
|
|
64
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function dl(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:pl(t,`input`,e.processors),output:pl(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function z(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return z(r.element,n);if(r.type===`set`)return z(r.valueType,n);if(r.type===`lazy`)return z(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return z(r.innerType,n);if(r.type===`intersection`)return z(r.left,n)||z(r.right,n);if(r.type===`record`||r.type===`map`)return z(r.keyType,n)||z(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:z(r.in,n)||z(r.out,n);if(r.type===`object`){for(let e in r.shape)if(z(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(z(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(z(e,n))return!0;return!!(r.rest&&z(r.rest,n))}return!1}var fl=(e,t={})=>n=>{let r=ll({...n,processors:t});return R(e,r),ul(r,e),dl(r,e)},pl=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=ll({...i??{},target:a,io:t,processors:n});return R(e,o),ul(o,e),dl(o,e)},ml={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},hl=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ml[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},gl=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},_l=(e,t,n,r)=>{n.type=`boolean`},vl=(e,t,n,r)=>{n.not={}},yl=(e,t,n,r)=>{let i=e._zod.def,a=$i(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},bl=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},xl=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Sl=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Cl=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=R(a.element,t,{...r,path:[...r.path,`items`]})},wl=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=R(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=R(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Tl=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>R(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},El=(e,t,n,r)=>{let i=e._zod.def,a=R(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=R(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Dl=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=R(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=R(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=R(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Ol=(e,t,n,r)=>{let i=e._zod.def,a=R(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},kl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Al=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},jl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Ml=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Nl=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;R(o,t,r);let s=t.seen.get(e);s.ref=o},Pl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Fl=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Il=O(`ZodISODateTime`,(e,t)=>{is.init(e,t),U.init(e,t)});function Ll(e){return Ac(Il,e)}var Rl=O(`ZodISODate`,(e,t)=>{as.init(e,t),U.init(e,t)});function zl(e){return jc(Rl,e)}var Bl=O(`ZodISOTime`,(e,t)=>{os.init(e,t),U.init(e,t)});function Vl(e){return Mc(Bl,e)}var Hl=O(`ZodISODuration`,(e,t)=>{ss.init(e,t),U.init(e,t)});function Ul(e){return Nc(Hl,e)}var B=O(`ZodError`,(e,t)=>{Ma.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Fa(e,t)},flatten:{value:t=>Pa(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ea,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ea,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Wl=Ia(B),Gl=La(B),Kl=Ra(B),ql=Ba(B),Jl=Ha(B),Yl=Ua(B),Xl=Wa(B),Zl=Ga(B),Ql=Ka(B),$l=qa(B),eu=Ja(B),tu=Ya(B),nu=new WeakMap;function ru(e,t,n){let r=Object.getPrototypeOf(e),i=nu.get(r);if(i||(i=new Set,nu.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var V=O(`ZodType`,(e,t)=>(I.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:pl(e,`input`),output:pl(e,`output`)}}),e.toJSONSchema=fl(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>Wl(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Kl(e,t,n),e.parseAsync=async(t,n)=>Gl(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ql(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Jl(e,t,n),e.decode=(t,n)=>Yl(e,t,n),e.encodeAsync=async(t,n)=>Xl(e,t,n),e.decodeAsync=async(t,n)=>Zl(e,t,n),e.safeEncode=(t,n)=>Ql(e,t,n),e.safeDecode=(t,n)=>$l(e,t,n),e.safeEncodeAsync=async(t,n)=>eu(e,t,n),e.safeDecodeAsync=async(t,n)=>tu(e,t,n),ru(e,`ZodType`,{check(...e){let t=this.def;return this.clone(j(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return M(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(fd(e,t))},superRefine(e,t){return this.check(pd(e,t))},overwrite(e){return this.check($c(e))},optional(){return Ju(this)},exactOptional(){return Xu(this)},nullable(){return Qu(this)},nullish(){return Ju(Qu(this))},nonoptional(e){return id(this,e)},array(){return G(this)},or(e){return q([this,e])},and(e){return Bu(this,e)},transform(e){return cd(this,Ku(e))},default(e){return ed(this,e)},prefault(e){return nd(this,e)},catch(e){return od(this,e)},pipe(e){return cd(this,e)},readonly(){return ud(this)},describe(e){let t=this.clone();return oc.add(t,{description:e}),t},meta(...e){if(e.length===0)return oc.get(this);let t=this.clone();return oc.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return oc.get(e)?.description},configurable:!0}),e)),iu=O(`_ZodString`,(e,t)=>{Ko.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hl(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,ru(e,`_ZodString`,{regex(...e){return this.check(qc(...e))},includes(...e){return this.check(Xc(...e))},startsWith(...e){return this.check(Zc(...e))},endsWith(...e){return this.check(Qc(...e))},min(...e){return this.check(Gc(...e))},max(...e){return this.check(Wc(...e))},length(...e){return this.check(Kc(...e))},nonempty(...e){return this.check(Gc(1,...e))},lowercase(e){return this.check(Jc(e))},uppercase(e){return this.check(Yc(e))},trim(){return this.check(tl())},normalize(...e){return this.check(el(...e))},toLowerCase(){return this.check(nl())},toUpperCase(){return this.check(rl())},slugify(){return this.check(il())}})}),au=O(`ZodString`,(e,t)=>{Ko.init(e,t),iu.init(e,t),e.email=t=>e.check(cc(ou,t)),e.url=t=>e.check(mc(lu,t)),e.jwt=t=>e.check(kc(wu,t)),e.emoji=t=>e.check(hc(uu,t)),e.guid=t=>e.check(lc(su,t)),e.uuid=t=>e.check(uc(cu,t)),e.uuidv4=t=>e.check(dc(cu,t)),e.uuidv6=t=>e.check(fc(cu,t)),e.uuidv7=t=>e.check(pc(cu,t)),e.nanoid=t=>e.check(gc(du,t)),e.guid=t=>e.check(lc(su,t)),e.cuid=t=>e.check(_c(fu,t)),e.cuid2=t=>e.check(vc(pu,t)),e.ulid=t=>e.check(yc(mu,t)),e.base64=t=>e.check(Ec(xu,t)),e.base64url=t=>e.check(Dc(Su,t)),e.xid=t=>e.check(bc(hu,t)),e.ksuid=t=>e.check(xc(gu,t)),e.ipv4=t=>e.check(Sc(_u,t)),e.ipv6=t=>e.check(Cc(vu,t)),e.cidrv4=t=>e.check(wc(yu,t)),e.cidrv6=t=>e.check(Tc(bu,t)),e.e164=t=>e.check(Oc(Cu,t)),e.datetime=t=>e.check(Ll(t)),e.date=t=>e.check(zl(t)),e.time=t=>e.check(Vl(t)),e.duration=t=>e.check(Ul(t))});function H(e){return sc(au,e)}var U=O(`ZodStringFormat`,(e,t)=>{L.init(e,t),iu.init(e,t)}),ou=O(`ZodEmail`,(e,t)=>{Yo.init(e,t),U.init(e,t)}),su=O(`ZodGUID`,(e,t)=>{qo.init(e,t),U.init(e,t)}),cu=O(`ZodUUID`,(e,t)=>{Jo.init(e,t),U.init(e,t)}),lu=O(`ZodURL`,(e,t)=>{Xo.init(e,t),U.init(e,t)}),uu=O(`ZodEmoji`,(e,t)=>{Zo.init(e,t),U.init(e,t)}),du=O(`ZodNanoID`,(e,t)=>{Qo.init(e,t),U.init(e,t)}),fu=O(`ZodCUID`,(e,t)=>{$o.init(e,t),U.init(e,t)}),pu=O(`ZodCUID2`,(e,t)=>{es.init(e,t),U.init(e,t)}),mu=O(`ZodULID`,(e,t)=>{ts.init(e,t),U.init(e,t)}),hu=O(`ZodXID`,(e,t)=>{ns.init(e,t),U.init(e,t)}),gu=O(`ZodKSUID`,(e,t)=>{rs.init(e,t),U.init(e,t)}),_u=O(`ZodIPv4`,(e,t)=>{cs.init(e,t),U.init(e,t)}),vu=O(`ZodIPv6`,(e,t)=>{ls.init(e,t),U.init(e,t)}),yu=O(`ZodCIDRv4`,(e,t)=>{us.init(e,t),U.init(e,t)}),bu=O(`ZodCIDRv6`,(e,t)=>{ds.init(e,t),U.init(e,t)}),xu=O(`ZodBase64`,(e,t)=>{ps.init(e,t),U.init(e,t)}),Su=O(`ZodBase64URL`,(e,t)=>{hs.init(e,t),U.init(e,t)}),Cu=O(`ZodE164`,(e,t)=>{gs.init(e,t),U.init(e,t)}),wu=O(`ZodJWT`,(e,t)=>{vs.init(e,t),U.init(e,t)}),Tu=O(`ZodNumber`,(e,t)=>{ys.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gl(e,t,n,r),ru(e,`ZodNumber`,{gt(e,t){return this.check(Vc(e,t))},gte(e,t){return this.check(Hc(e,t))},min(e,t){return this.check(Hc(e,t))},lt(e,t){return this.check(zc(e,t))},lte(e,t){return this.check(Bc(e,t))},max(e,t){return this.check(Bc(e,t))},int(e){return this.check(Du(e))},safe(e){return this.check(Du(e))},positive(e){return this.check(Vc(0,e))},nonnegative(e){return this.check(Hc(0,e))},negative(e){return this.check(zc(0,e))},nonpositive(e){return this.check(Bc(0,e))},multipleOf(e,t){return this.check(Uc(e,t))},step(e,t){return this.check(Uc(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function W(e){return Pc(Tu,e)}var Eu=O(`ZodNumberFormat`,(e,t)=>{bs.init(e,t),Tu.init(e,t)});function Du(e){return Fc(Eu,e)}var Ou=O(`ZodBoolean`,(e,t)=>{xs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_l(e,t,n,r)});function ku(e){return Ic(Ou,e)}var Au=O(`ZodUnknown`,(e,t)=>{Ss.init(e,t),V.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function ju(){return Lc(Au)}var Mu=O(`ZodNever`,(e,t)=>{Cs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vl(e,t,n,r)});function Nu(e){return Rc(Mu,e)}var Pu=O(`ZodArray`,(e,t)=>{Ts.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cl(e,t,n,r),e.element=t.element,ru(e,`ZodArray`,{min(e,t){return this.check(Gc(e,t))},nonempty(e){return this.check(Gc(1,e))},max(e,t){return this.check(Wc(e,t))},length(e,t){return this.check(Kc(e,t))},unwrap(){return this.element}})});function G(e,t){return al(Pu,e,t)}var Fu=O(`ZodObject`,(e,t)=>{As.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wl(e,t,n,r),A(e,`shape`,()=>t.shape),ru(e,`ZodObject`,{keyof(){return Uu(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:ju()})},loose(){return this.clone({...this._zod.def,catchall:ju()})},strict(){return this.clone({...this._zod.def,catchall:Nu()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return ba(this,e)},safeExtend(e){return xa(this,e)},merge(e){return Sa(this,e)},pick(e){return va(this,e)},omit(e){return ya(this,e)},partial(...e){return Ca(qu,this,e[0])},required(...e){return wa(rd,this,e[0])}})});function K(e,t){return new Fu({type:`object`,shape:e??{},...N(t)})}var Iu=O(`ZodUnion`,(e,t)=>{Ms.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Tl(e,t,n,r),e.options=t.options});function q(e,t){return new Iu({type:`union`,options:e,...N(t)})}var Lu=O(`ZodDiscriminatedUnion`,(e,t)=>{Iu.init(e,t),Ns.init(e,t)});function Ru(e,t,n){return new Lu({type:`union`,options:t,discriminator:e,...N(n)})}var zu=O(`ZodIntersection`,(e,t)=>{Ps.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>El(e,t,n,r)});function Bu(e,t){return new zu({type:`intersection`,left:e,right:t})}var Vu=O(`ZodRecord`,(e,t)=>{Ls.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Dl(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function J(e,t,n){return!t||!t._zod?new Vu({type:`record`,keyType:H(),valueType:e,...N(t)}):new Vu({type:`record`,keyType:e,valueType:t,...N(n)})}var Hu=O(`ZodEnum`,(e,t)=>{Rs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yl(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Hu({...t,checks:[],...N(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Hu({...t,checks:[],...N(r),entries:i})}});function Uu(e,t){return new Hu({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...N(t)})}var Wu=O(`ZodLiteral`,(e,t)=>{zs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bl(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Y(e,t){return new Wu({type:`literal`,values:Array.isArray(e)?e:[e],...N(t)})}var Gu=O(`ZodTransform`,(e,t)=>{Bs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sl(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Zi(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Aa(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Aa(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function Ku(e){return new Gu({type:`transform`,transform:e})}var qu=O(`ZodOptional`,(e,t)=>{Hs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ju(e){return new qu({type:`optional`,innerType:e})}var Yu=O(`ZodExactOptional`,(e,t)=>{Us.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Xu(e){return new Yu({type:`optional`,innerType:e})}var Zu=O(`ZodNullable`,(e,t)=>{Ws.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ol(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Qu(e){return new Zu({type:`nullable`,innerType:e})}var $u=O(`ZodDefault`,(e,t)=>{Gs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Al(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ed(e,t){return new $u({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():pa(t)}})}var td=O(`ZodPrefault`,(e,t)=>{qs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function nd(e,t){return new td({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():pa(t)}})}var rd=O(`ZodNonOptional`,(e,t)=>{Js.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>kl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function id(e,t){return new rd({type:`nonoptional`,innerType:e,...N(t)})}var ad=O(`ZodCatch`,(e,t)=>{Xs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ml(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function od(e,t){return new ad({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var sd=O(`ZodPipe`,(e,t)=>{Zs.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Nl(e,t,n,r),e.in=t.in,e.out=t.out});function cd(e,t){return new sd({type:`pipe`,in:e,out:t})}var ld=O(`ZodReadonly`,(e,t)=>{$s.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ud(e){return new ld({type:`readonly`,innerType:e})}var dd=O(`ZodCustom`,(e,t)=>{tc.init(e,t),V.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xl(e,t,n,r)});function fd(e,t={}){return ol(dd,e,t)}function pd(e,t){return sl(e,t)}function md(e){return`is`in e&&typeof e.is==`function`}function X(e){if(Object.defineProperty(e,"is",{value:t=>e.safeParse(t).success,enumerable:!0}),!md(e))throw Error(`unreachable: is was just defined above`);return e}var hd=X(q([Y(`discoverable`),Y(`quiet`),Y(`dark`)])),gd=X(q([Y(`visible`),Y(`hidden`),Y(`ghost`)])),_d=X(q([Y(`active`),Y(`idle`),Y(`busy`),Y(`offline`)])),vd=X(q([Y(`public`),Y(`private`),Y(`secret`)])),yd=X(q([Y(`steer`),Y(`followUp`),Y(`info`)])),bd=X(K({id:H(),version:W(),name:H(),harness:H(),cwd:H(),pid:W(),startedAt:H(),visibility:gd,status:_d,tags:G(H()),subscribedRooms:G(H())})),xd=X(K({id:H(),version:W(),name:H(),type:vd,owner:H(),createdAt:H(),description:H(),members:G(H()),invited:G(H()),memberJoins:J(H(),W()),memberLeaves:J(H(),W()),invitedJoins:J(H(),W()),invitedLeaves:J(H(),W())})),Sd=X(K({id:H(),from:H(),room:H(),content:H(),timestamp:H(),replyTo:H().optional(),readBy:G(H()),streamingBehavior:yd.optional()})),Cd=X(K({id:H(),from:H(),to:H(),content:H(),timestamp:H(),readBy:G(H()),streamingBehavior:yd.optional()})),wd=X(q([Y(`timeout`),Y(`not_connected`),Y(`connection_lost`)])),Td=X(Ru(`status`,[K({status:Y(`delivered`)}),K({status:Y(`read`)}),K({status:Y(`queued`),reason:wd}),K({status:Y(`refused`),code:H()}),K({status:Y(`dropped`)}),K({status:Y(`expired`)})])),Ed=X(K({id:H(),name:H(),status:_d})),Dd=X(Ru(`type`,[K({type:Y(`room_message`),message:Sd}),K({type:Y(`dm`),message:Cd}),K({type:Y(`room_invite`),room:H(),roomDescription:H(),from:H(),fromName:H(),fromCwd:H()}),K({type:Y(`member_joined`),room:H(),agent:H()}),K({type:Y(`member_left`),room:H(),agent:H()}),K({type:Y(`room_members`),room:H(),members:G(Ed)}),K({type:Y(`member_status`),room:H(),agent:H(),status:_d}),K({type:Y(`delivery_status`),messageId:H(),agent:H(),delivery:Td,room:H().optional()}),K({type:Y(`invite_declined`),room:H(),agent:H(),agentName:H(),reason:H()}),K({type:Y(`name_changed`),agent:H(),oldName:H(),newName:H()}),K({type:Y(`connection_request`),connectionId:H(),peerId:H(),dataPort:W(),name:H(),fingerprint:H()}),K({type:Y(`room_join_request`),room:H(),requesterId:H()}),K({type:Y(`capability_request`),requestId:H(),capability:H(),scopeKind:H(),scopePath:H().optional(),requesterDevice:H()})]));X(K({code:H(),expiresAt:H(),deviceId:H(),signature:H().optional()})),X(Ru(`action`,[K({action:Y(`register`),name:H(),visibility:gd,tags:G(H())}),K({action:Y(`update`),visibility:gd.optional(),status:_d.optional(),name:H().optional(),tags:G(H()).optional()}),K({action:Y(`whoami`)}),K({action:Y(`web_url`)}),K({action:Y(`create_room`),name:H(),type:vd,description:H()}),K({action:Y(`list_rooms`)}),K({action:Y(`join_room`),room:H()}),K({action:Y(`leave_room`),room:H()}),K({action:Y(`send`),target:H(),content:H(),replyTo:H().optional(),streamingBehavior:yd.optional()}),K({action:Y(`dm`),target:H(),content:H(),streamingBehavior:yd.optional()}),K({action:Y(`list_agents`)}),K({action:Y(`read_room`),room:H(),since:H().optional()}),K({action:Y(`invite`),room:H(),agent:H()}),K({action:Y(`kick`),room:H(),agent:H()}),K({action:Y(`decline_invite`),room:H(),reason:H()}),K({action:Y(`destroy_room`),room:H()}),K({action:Y(`mesh_connect`),host:H(),port:W(),policy:H().optional()}),K({action:Y(`mesh_accept`),connectionId:H()}),K({action:Y(`mesh_reject`),connectionId:H(),reason:H()}),K({action:Y(`mesh_pending`)}),K({action:Y(`room_accept`),room:H(),requesterId:H()}),K({action:Y(`room_reject`),room:H(),requesterId:H(),reason:H().optional()}),K({action:Y(`room_pending`)}),K({action:Y(`capability_accept`),requestId:H(),expires:W(),delegationsRemaining:W().optional(),capability:H().optional()}),K({action:Y(`capability_reject`),requestId:H(),reason:H().optional()}),K({action:Y(`capability_pending`)}),K({action:Y(`mesh_discover`),method:H().optional()}),K({action:Y(`mesh_advertise`),method:H(),name:H(),port:W().optional(),adapter:H().optional()}),K({action:Y(`mesh_unadvertise`),id:H()}),K({action:Y(`mesh_interfaces`)}),K({action:Y(`lan_web_uis`)}),K({action:Y(`mesh_listen`),host:H(),port:W().optional(),policy:H().optional()}),K({action:Y(`mesh_unlisten`),id:H()}),K({action:Y(`mesh_listeners`)}),K({action:Y(`mesh_set_visibility`),visibility:hd,adapter:H().optional()}),K({action:Y(`mesh_get_visibility`)}),K({action:Y(`gateway_trust`),device:H(),principal:ku().optional(),machine:ku().optional()}),K({action:Y(`gateway_untrust`),device:H(),principal:ku().optional(),machine:ku().optional()}),K({action:Y(`gateway_list_trusted`)}),K({action:Y(`petname_set`),device:H(),name:H()}),K({action:Y(`petname_clear`),device:H()}),K({action:Y(`petname_list`)}),K({action:Y(`machine_name`),name:H().optional()}),K({action:Y(`principal_name`),name:H().optional()}),K({action:Y(`dm_admit`),target:H(),principal:ku().optional()}),K({action:Y(`dm_use_grant`),target:H(),grant:H()}),K({action:Y(`dm_revoke`),target:H()}),K({action:Y(`gateway_generate_connection_code`),ttlMs:W().optional(),privateKey:H().optional(),passphrase:H().optional()}),K({action:Y(`gateway_redeem_connection_code`),code:H(),expiresAt:H(),device:H(),signature:H().optional(),publicKey:H().optional(),fingerprint:H().optional()}),K({action:Y(`query_version`),device:H()}),K({action:Y(`mesh_graph`)}),K({action:Y(`mesh_trace`),target:H(),timeoutMs:W().optional()})]));var Z=K({content:H(),isError:ku()}),Od=q([Y(`public`),Y(`private`),Y(`secret`)]),kd=K({kind:q([Y(`direct`),Y(`relay`)]),from:H(),to:H(),via:H().optional()}),Ad=K({nodes:G(H()),edges:G(kd)}),jd=K({id:H(),petname:H().optional(),selfName:H().optional()}),Md=K({relayed:ku(),hubAddress:H().optional()}),Nd=K({rttMs:W(),local:Md,remote:Md.optional(),outcome:K({result:H(),code:H().optional()}).loose()}),Pd=Ru(`type`,[K({type:Y(`agent_upsert`),agent:bd}),K({type:Y(`agent_offline`),agentId:H()}),K({type:Y(`room_upsert`),room:xd}),K({type:Y(`room_delete`),roomId:H()}),K({type:Y(`message_add`),roomId:H(),message:Sd}),K({type:Y(`dm_add`),key:H(),message:Cd}),K({type:Y(`delivery`),agentId:H(),event:Dd})]),Fd=K({agents:J(H(),bd),rooms:J(H(),xd),messages:J(H(),G(Sd)),dms:J(H(),G(Cd))}),Id=Ru(`kind`,[K({kind:Y(`state_sync`),state:Fd}),K({kind:Y(`state_patch`),patch:Pd}),K({kind:Y(`delivery`),event:Dd})]),Ld=K({endpoint:H(),keys:K({p256dh:H(),auth:H()})}),Rd={send:w.input(K({target:H(),content:H()})).output(Z),dm:w.input(K({target:H(),content:H()})).output(Z),joinRoom:w.input(K({room:H()})).output(Z),leaveRoom:w.input(K({room:H().optional()})).output(Z),createRoom:w.input(K({name:H(),type:Od,description:H().optional()})).output(Z),listRooms:w.input(K({})).output(Z),listAgents:w.input(K({})).output(Z),readRoom:w.input(K({room:H().optional()})).output(Z),destroyRoom:w.input(K({room:H()})).output(Z),invite:w.input(K({room:H(),agent:H()})).output(Z),declineInvite:w.input(K({room:H(),reason:H()})).output(Z),kick:w.input(K({room:H(),agent:H()})).output(Z),renameAgent:w.input(K({agent:H(),name:H()})).output(Z),pushSubscribe:w.input(K({subscription:Ld,agentId:H().optional()})).output(Z),pushUnsubscribe:w.input(K({agentId:H().optional()})).output(Z),subscribeEvents:w.input(K({lastEventId:H().optional()})).output(Kr(Id)),getRoomMessages:w.input(K({room:H(),since:H().optional()})).output(G(Sd)),getMeshGraph:w.input(K({})).output(Ad),getDisplayNames:w.input(K({})).output(G(jd)),getMeshTrace:w.input(K({target:H(),timeoutMs:W().optional()})).output(Nd),disconnect:w.input(K({})).output(K({}))};function zd(e){if(typeof e!=`object`||!e||!(`endpoint`in e)||typeof e.endpoint!=`string`||!(`keys`in e))return!1;let t=e.keys;return!(typeof t!=`object`||!t||!(`p256dh`in t)||typeof t.p256dh!=`string`||!(`auth`in t)||typeof t.auth!=`string`)}async function Bd(e,t){let n=e=>{let n=t[e];return typeof n==`string`?n:``},r=e=>{let n=t[e];return typeof n==`string`?n:void 0},i=()=>{let e=t.type;return e===`public`||e===`private`||e===`secret`?e:`public`};switch(t.action){case`send`:return e.send({target:n(`target`),content:n(`content`)});case`dm`:return e.dm({target:n(`target`),content:n(`content`)});case`join_room`:return e.joinRoom({room:n(`room`)});case`leave_room`:return e.leaveRoom({room:r(`room`)});case`create_room`:return e.createRoom({name:n(`name`),type:i(),description:r(`description`)});case`list_rooms`:return e.listRooms({});case`list_agents`:return e.listAgents({});case`read_room`:return e.readRoom({room:r(`room`)});case`destroy_room`:return e.destroyRoom({room:n(`room`)});case`invite`:return e.invite({room:n(`room`),agent:n(`agent`)});case`decline_invite`:return e.declineInvite({room:n(`room`),reason:n(`reason`)});case`kick`:return e.kick({room:n(`room`),agent:n(`agent`)});case`rename_agent`:return e.renameAgent({agent:n(`agent`),name:n(`name`)});case`push_subscribe`:{let n=t.subscription;return zd(n)?e.pushSubscribe({subscription:n,agentId:r(`agentId`)}):{content:`Invalid push subscription`,isError:!0}}case`push_unsubscribe`:return e.pushUnsubscribe({agentId:r(`agentId`)});default:return{content:`Unknown action: ${String(t.action)}`,isError:!0}}}var Vd=new Map,Hd=new Map,Ud=new Map,Wd=new Map;function Gd(e){for(let[t,n]of Object.entries(e.agents))Vd.set(t,n);for(let[t,n]of Object.entries(e.rooms))Hd.set(t,n);for(let[t,n]of Object.entries(e.messages))Ud.set(t,n);for(let[t,n]of Object.entries(e.dms))Wd.set(t,n)}function Kd(e){switch(e.type){case`agent_upsert`:Vd.set(e.agent.id,e.agent);break;case`agent_offline`:{let t=Vd.get(e.agentId);t&&(t.status=`offline`,Vd.set(e.agentId,t));break}case`room_upsert`:Hd.set(e.room.id,e.room);break;case`room_delete`:Hd.delete(e.roomId);break;case`message_add`:{let t=Ud.get(e.roomId)??[];t.push(e.message),Ud.set(e.roomId,t);break}case`dm_add`:{let t=Wd.get(e.key)??[];t.push(e.message),Wd.set(e.key,t);break}case`delivery`:break;case`message_read`:if(e.room!==void 0){let t=Ud.get(e.room);if(t){let n=t.find(t=>t.id===e.messageId);n&&!n.readBy.includes(e.readBy)&&n.readBy.push(e.readBy)}}else for(let[,t]of Wd){let n=t.find(t=>t.id===e.messageId);n&&!n.readBy.includes(e.readBy)&&n.readBy.push(e.readBy)}}}function qd(){return{agents:[...Vd.values()],rooms:[...Hd.values()]}}var Jd,Yd=0,Xd,Zd=new Ji,Qd=1e3,$d=3e4;function ef(e){let t=Rt(new gn({connect:async()=>{let t=new WebSocket(e);return Xd=t,t.addEventListener(`open`,()=>{af({type:`connected`})}),t.addEventListener(`close`,()=>{af({type:`disconnected`})}),new Promise((e,n)=>{t.addEventListener(`open`,()=>{e(t)},{once:!0}),t.addEventListener(`error`,n,{once:!0})})},reconnect:{enabled:!0,delay:e=>e.attempt===1?0:Math.min(Qd*2**e.attempt,$d)},plugins:[new _n]}));Jd=t,nf(t,++Yd)}function tf(){++Yd,Jd=void 0,Xd?.close(),Xd=void 0}async function nf(e,t){let n;for(;t===Yd;)try{let r=await e.subscribeEvents(n===void 0?{}:{lastEventId:n});for await(let e of r){if(t!==Yd)return;let r=et(e);switch(r?.id!==void 0&&(n=r.id),Zd.publish(e),e.kind){case`state_sync`:Gd(e.state),af({type:`state`,state:qd()});break;case`state_patch`:Kd(e.patch),af({type:`patch`,patch:e.patch})}}return}catch{}}var rf=new Set;function af(e){let t=JSON.stringify(e);for(let e of rf)try{e.postMessage(t)}catch{}}function of(e){switch(e.type){case`init`:ef(e.url);break;case`action`:{let t=Jd;if(!t)break;let n=e.id;Bd(t,e.action).then(e=>{af({type:`actionResult`,id:n,result:e})}).catch(e=>{af({type:`actionError`,id:n,message:e instanceof Error?e.message:String(e)})});break}case`getState`:af({type:`state`,state:qd()})}}function sf(e){if(typeof e!=`object`||!e||!(`type`in e))return!1;let t=e.type;return typeof t==`string`&&(t===`init`||t===`action`||t===`getState`)}function cf(){return{agents:Object.fromEntries(Vd),rooms:Object.fromEntries(Hd),messages:Object.fromEntries(Ud),dms:Object.fromEntries(Wd)}}async function Q(e){return Jd?Bd(Jd,e):{content:`Not connected to mesh yet`,isError:!0}}function lf(){if(!Jd)throw Error(`Not connected to mesh yet`);return Jd}var $=mi(Rd).$context(),uf={};uf.current=new Gi({send:$.send.handler(async({input:e})=>Q({action:`send`,...e})),dm:$.dm.handler(async({input:e})=>Q({action:`dm`,...e})),joinRoom:$.joinRoom.handler(async({input:e})=>Q({action:`join_room`,room:e.room})),leaveRoom:$.leaveRoom.handler(async({input:e})=>Q({action:`leave_room`,room:e.room})),createRoom:$.createRoom.handler(async({input:e})=>Q({action:`create_room`,name:e.name,type:e.type,description:e.description})),listRooms:$.listRooms.handler(async()=>Q({action:`list_rooms`})),listAgents:$.listAgents.handler(async()=>Q({action:`list_agents`})),readRoom:$.readRoom.handler(async({input:e})=>Q({action:`read_room`,room:e.room})),destroyRoom:$.destroyRoom.handler(async({input:e})=>Q({action:`destroy_room`,room:e.room})),invite:$.invite.handler(async({input:e})=>Q({action:`invite`,room:e.room,agent:e.agent})),declineInvite:$.declineInvite.handler(async({input:e})=>Q({action:`decline_invite`,room:e.room,reason:e.reason})),kick:$.kick.handler(async({input:e})=>Q({action:`kick`,room:e.room,agent:e.agent})),renameAgent:$.renameAgent.handler(async({input:e})=>Q({action:`rename_agent`,agent:e.agent,name:e.name})),pushSubscribe:$.pushSubscribe.handler(async({input:e})=>Q({action:`push_subscribe`,subscription:e.subscription,agentId:e.agentId})),pushUnsubscribe:$.pushUnsubscribe.handler(async({input:e})=>Q({action:`push_unsubscribe`,agentId:e.agentId})),getRoomMessages:$.getRoomMessages.handler(async({input:e})=>lf().getRoomMessages(e)),getMeshGraph:$.getMeshGraph.handler(async()=>lf().getMeshGraph({})),getDisplayNames:$.getDisplayNames.handler(async()=>lf().getDisplayNames({})),getMeshTrace:$.getMeshTrace.handler(async({input:e})=>lf().getMeshTrace(e)),subscribeEvents:$.subscribeEvents.handler(async function*({input:e,signal:t}){e.lastEventId===void 0&&(yield{kind:`state_sync`,state:cf()}),yield*Zd.subscribe({...t?{signal:t}:{},...e.lastEventId===void 0?{}:{lastEventId:e.lastEventId}})}),disconnect:$.disconnect.handler(({context:e})=>(setTimeout(()=>{uf.current?.close(e.port)},0),{}))});function df(e){uf.current?.upgrade(e,{context:{port:e}})}return typeof self<`u`&&self.addEventListener(`connect`,e=>{let t=e.ports[0];if(t!==void 0){rf.add(t);try{t.postMessage(JSON.stringify({type:`state`,state:qd()}))}catch{}t.onmessage=e=>{let t=JSON.parse(typeof e.data==`string`?e.data:String(e.data));sf(t)&&of(t)},df(t)}}),e.agents=Vd,e.applyPatch=Kd,e.applyStateSync=Gd,e.connect=ef,e.disconnect=tf,e.dms=Wd,e.getStateSnapshot=qd,e.localPublisher=Zd,e.messages=Ud,e.ports=rf,e.rooms=Hd,e.upgradeTabRpcPort=df,e})({});
|