@mcpcloud/runtime 0.12.3 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,18 @@
1
1
  import type { Server } from 'node:http';
2
2
  import type { RuntimeEnv } from '../config';
3
3
  import type { GeneratedServer } from '../server';
4
+ import { registerNodeCodeModeEngine } from './codeModeHost';
5
+ /**
6
+ * Re-exported so a host that does NOT use `serve()` can still offer an engine.
7
+ *
8
+ * `serve()` calls this itself, but the CLI's `--local` boot wraps the bundle's
9
+ * Cloudflare entry in its own HTTP server — and that entry registers nothing,
10
+ * correctly, because on the edge dispatch serves `codemode_execute`. Without a
11
+ * public way to register, a pulled tree whose operator enabled Code Mode
12
+ * answered "Unknown tool" locally while the deployed server had it: exactly the
13
+ * divergence `--local` exists to rule out.
14
+ */
15
+ export { registerNodeCodeModeEngine };
4
16
  export interface NodeServeOptions {
5
17
  port?: number;
6
18
  hostname?: string;
@@ -1,4 +1,4 @@
1
- /*! @mcpcloud/runtime v0.12.3 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
1
+ /*! @mcpcloud/runtime v0.12.4 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
2
  var x3=Object.defineProperty;var c3=(W)=>W;function u3(W,Q){this[W]=c3.bind(null,Q)}var HY=(W,Q)=>{for(var Y in Q)x3(W,Y,{get:Q[Y],enumerable:!0,configurable:!0,set:u3.bind(Q,Y)})};import k3 from"node:process";var wY;function K(W,Q,Y){function X(w,q){if(!w._zod)Object.defineProperty(w,"_zod",{value:{def:q,constr:H,traits:new Set},enumerable:!1});if(w._zod.traits.has(W))return;w._zod.traits.add(W),Q(w,q);let L=H.prototype,B=Object.keys(L);for(let z=0;z<B.length;z++){let V=B[z];if(!(V in w))w[V]=L[V].bind(w)}}let G=Y?.Parent??Object;class J extends G{}Object.defineProperty(J,"name",{value:W});function H(w){var q;let L=Y?.Parent?new J:this;X(L,w),(q=L._zod).deferred??(q.deferred=[]);for(let B of L._zod.deferred)B();return L}return Object.defineProperty(H,"init",{value:X}),Object.defineProperty(H,Symbol.hasInstance,{value:(w)=>{if(Y?.Parent&&w instanceof Y.Parent)return!0;return w?._zod?.traits?.has(W)}}),Object.defineProperty(H,"name",{value:W}),H}var N8=Symbol("zod_brand");class a extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class DW extends Error{constructor(W){super(`Encountered unidirectional transform during encode: ${W}`);this.name="ZodEncodeError"}}(wY=globalThis).__zod_globalConfig??(wY.__zod_globalConfig={});var AW=globalThis.__zod_globalConfig;function l(W){if(W)Object.assign(AW,W);return AW}var F={};HY(F,{unwrapMessage:()=>UW,uint8ArrayToHex:()=>K9,uint8ArrayToBase64url:()=>A9,uint8ArrayToBase64:()=>MY,stringifyPrimitive:()=>uW,slugify:()=>AQ,shallowClone:()=>qY,safeExtend:()=>Y9,required:()=>J9,randomString:()=>i3,propertyKeyTypes:()=>KQ,promiseAllObject:()=>n3,primitiveTypes:()=>KY,prefixIssues:()=>QW,pick:()=>s3,partial:()=>G9,parsedType:()=>MQ,optionalKeys:()=>LQ,omit:()=>W9,objectClone:()=>r3,numKeys:()=>t3,nullish:()=>IW,normalizeParams:()=>U,mergeDefs:()=>s,merge:()=>X9,jsonStringifyReplacer:()=>qW,joinValues:()=>hW,issue:()=>LW,isPlainObject:()=>XW,isObject:()=>HW,hexToUint8Array:()=>q9,getSizableOrigin:()=>BY,getParsedType:()=>e3,getLengthableOrigin:()=>$W,getEnumValues:()=>VW,getElementAtPath:()=>d3,floatSafeRemainder:()=>wQ,finalizeIssue:()=>d,extend:()=>Q9,explicitlyAborted:()=>NQ,escapeRegex:()=>WW,esc:()=>xW,defineLazy:()=>$,createTransparentProxy:()=>a3,cloneDef:()=>p3,clone:()=>t,cleanRegex:()=>FW,cleanEnum:()=>H9,captureStackTrace:()=>cW,cached:()=>KW,base64urlToUint8Array:()=>w9,base64ToUint8Array:()=>NY,assignProp:()=>YW,assertNotEqual:()=>m3,assertNever:()=>o3,assertIs:()=>f3,assertEqual:()=>y3,assert:()=>l3,allowsEval:()=>qQ,aborted:()=>GW,NUMBER_FORMAT_RANGES:()=>BQ,Class:()=>zY,BIGINT_FORMAT_RANGES:()=>LY});function y3(W){return W}function m3(W){return W}function f3(W){}function o3(W){throw Error("Unexpected value in exhaustive check")}function l3(W){}function VW(W){let Q=Object.values(W).filter((X)=>typeof X==="number");return Object.entries(W).filter(([X,G])=>Q.indexOf(+X)===-1).map(([X,G])=>G)}function hW(W,Q="|"){return W.map((Y)=>uW(Y)).join(Q)}function qW(W,Q){if(typeof Q==="bigint")return Q.toString();return Q}function KW(W){return{get value(){{let Y=W();return Object.defineProperty(this,"value",{value:Y}),Y}throw Error("cached value already set")}}}function IW(W){return W===null||W===void 0}function FW(W){let Q=W.startsWith("^")?1:0,Y=W.endsWith("$")?W.length-1:W.length;return W.slice(Q,Y)}function wQ(W,Q){let Y=W/Q,X=Math.round(Y),G=Number.EPSILON*Math.max(Math.abs(Y),1);if(Math.abs(Y-X)<G)return 0;return Y-X}var AY=Symbol("evaluating");function $(W,Q,Y){let X=void 0;Object.defineProperty(W,Q,{get(){if(X===AY)return;if(X===void 0)X=AY,X=Y();return X},set(G){Object.defineProperty(W,Q,{value:G})},configurable:!0})}function r3(W){return Object.create(Object.getPrototypeOf(W),Object.getOwnPropertyDescriptors(W))}function YW(W,Q,Y){Object.defineProperty(W,Q,{value:Y,writable:!0,enumerable:!0,configurable:!0})}function s(...W){let Q={};for(let Y of W){let X=Object.getOwnPropertyDescriptors(Y);Object.assign(Q,X)}return Object.defineProperties({},Q)}function p3(W){return s(W._zod.def)}function d3(W,Q){if(!Q)return W;return Q.reduce((Y,X)=>Y?.[X],W)}function n3(W){let Q=Object.keys(W),Y=Q.map((X)=>W[X]);return Promise.all(Y).then((X)=>{let G={};for(let J=0;J<Q.length;J++)G[Q[J]]=X[J];return G})}function i3(W=10){let Y="";for(let X=0;X<W;X++)Y+="abcdefghijklmnopqrstuvwxyz"[Math.floor(Math.random()*26)];return Y}function xW(W){return JSON.stringify(W)}function AQ(W){return W.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var cW="captureStackTrace"in Error?Error.captureStackTrace:(...W)=>{};function HW(W){return typeof W==="object"&&W!==null&&!Array.isArray(W)}var qQ=KW(()=>{if(AW.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(W){return!1}});function XW(W){if(HW(W)===!1)return!1;let Q=W.constructor;if(Q===void 0)return!0;if(typeof Q!=="function")return!0;let Y=Q.prototype;if(HW(Y)===!1)return!1;if(Object.prototype.hasOwnProperty.call(Y,"isPrototypeOf")===!1)return!1;return!0}function qY(W){if(XW(W))return{...W};if(Array.isArray(W))return[...W];if(W instanceof Map)return new Map(W);if(W instanceof Set)return new Set(W);return W}function t3(W){let Q=0;for(let Y in W)if(Object.prototype.hasOwnProperty.call(W,Y))Q++;return Q}var e3=(W)=>{let Q=typeof W;switch(Q){case"undefined":return"undefined";case"string":return"string";case"number":return Number.isNaN(W)?"nan":"number";case"boolean":return"boolean";case"function":return"function";case"bigint":return"bigint";case"symbol":return"symbol";case"object":if(Array.isArray(W))return"array";if(W===null)return"null";if(W.then&&typeof W.then==="function"&&W.catch&&typeof W.catch==="function")return"promise";if(typeof Map<"u"&&W instanceof Map)return"map";if(typeof Set<"u"&&W instanceof Set)return"set";if(typeof Date<"u"&&W instanceof Date)return"date";if(typeof File<"u"&&W instanceof File)return"file";return"object";default:throw Error(`Unknown data type: ${Q}`)}},KQ=new Set(["string","number","symbol"]),KY=new Set(["string","number","bigint","boolean","symbol","undefined"]);function WW(W){return W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function t(W,Q,Y){let X=new W._zod.constr(Q??W._zod.def);if(!Q||Y?.parent)X._zod.parent=W;return X}function U(W){let Q=W;if(!Q)return{};if(typeof Q==="string")return{error:()=>Q};if(Q?.message!==void 0){if(Q?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");Q.error=Q.message}if(delete Q.message,typeof Q.error==="string")return{...Q,error:()=>Q.error};return Q}function a3(W){let Q;return new Proxy({},{get(Y,X,G){return Q??(Q=W()),Reflect.get(Q,X,G)},set(Y,X,G,J){return Q??(Q=W()),Reflect.set(Q,X,G,J)},has(Y,X){return Q??(Q=W()),Reflect.has(Q,X)},deleteProperty(Y,X){return Q??(Q=W()),Reflect.deleteProperty(Q,X)},ownKeys(Y){return Q??(Q=W()),Reflect.ownKeys(Q)},getOwnPropertyDescriptor(Y,X){return Q??(Q=W()),Reflect.getOwnPropertyDescriptor(Q,X)},defineProperty(Y,X,G){return Q??(Q=W()),Reflect.defineProperty(Q,X,G)}})}function uW(W){if(typeof W==="bigint")return W.toString()+"n";if(typeof W==="string")return`"${W}"`;return`${W}`}function LQ(W){return Object.keys(W).filter((Q)=>{return W[Q]._zod.optin==="optional"&&W[Q]._zod.optout==="optional"})}var BQ={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},LY={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function s3(W,Q){let Y=W._zod.def,X=Y.checks;if(X&&X.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let J=s(W._zod.def,{get shape(){let H={};for(let w in Q){if(!(w in Y.shape))throw Error(`Unrecognized key: "${w}"`);if(!Q[w])continue;H[w]=Y.shape[w]}return YW(this,"shape",H),H},checks:[]});return t(W,J)}function W9(W,Q){let Y=W._zod.def,X=Y.checks;if(X&&X.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let J=s(W._zod.def,{get shape(){let H={...W._zod.def.shape};for(let w in Q){if(!(w in Y.shape))throw Error(`Unrecognized key: "${w}"`);if(!Q[w])continue;delete H[w]}return YW(this,"shape",H),H},checks:[]});return t(W,J)}function Q9(W,Q){if(!XW(Q))throw Error("Invalid input to extend: expected a plain object");let Y=W._zod.def.checks;if(Y&&Y.length>0){let J=W._zod.def.shape;for(let H in Q)if(Object.getOwnPropertyDescriptor(J,H)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}let G=s(W._zod.def,{get shape(){let J={...W._zod.def.shape,...Q};return YW(this,"shape",J),J}});return t(W,G)}function Y9(W,Q){if(!XW(Q))throw Error("Invalid input to safeExtend: expected a plain object");let Y=s(W._zod.def,{get shape(){let X={...W._zod.def.shape,...Q};return YW(this,"shape",X),X}});return t(W,Y)}function X9(W,Q){if(W._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let Y=s(W._zod.def,{get shape(){let X={...W._zod.def.shape,...Q._zod.def.shape};return YW(this,"shape",X),X},get catchall(){return Q._zod.def.catchall},checks:Q._zod.def.checks??[]});return t(W,Y)}function G9(W,Q,Y){let G=Q._zod.def.checks;if(G&&G.length>0)throw Error(".partial() cannot be used on object schemas containing refinements");let H=s(Q._zod.def,{get shape(){let w=Q._zod.def.shape,q={...w};if(Y)for(let L in Y){if(!(L in w))throw Error(`Unrecognized key: "${L}"`);if(!Y[L])continue;q[L]=W?new W({type:"optional",innerType:w[L]}):w[L]}else for(let L in w)q[L]=W?new W({type:"optional",innerType:w[L]}):w[L];return YW(this,"shape",q),q},checks:[]});return t(Q,H)}function J9(W,Q,Y){let X=s(Q._zod.def,{get shape(){let G=Q._zod.def.shape,J={...G};if(Y)for(let H in Y){if(!(H in J))throw Error(`Unrecognized key: "${H}"`);if(!Y[H])continue;J[H]=new W({type:"nonoptional",innerType:G[H]})}else for(let H in G)J[H]=new W({type:"nonoptional",innerType:G[H]});return YW(this,"shape",J),J}});return t(Q,X)}function GW(W,Q=0){if(W.aborted===!0)return!0;for(let Y=Q;Y<W.issues.length;Y++)if(W.issues[Y]?.continue!==!0)return!0;return!1}function NQ(W,Q=0){if(W.aborted===!0)return!0;for(let Y=Q;Y<W.issues.length;Y++)if(W.issues[Y]?.continue===!1)return!0;return!1}function QW(W,Q){return Q.map((Y)=>{var X;return(X=Y).path??(X.path=[]),Y.path.unshift(W),Y})}function UW(W){return typeof W==="string"?W:W?.message}function d(W,Q,Y){let X=W.message?W.message:UW(W.inst?._zod.def?.error?.(W))??UW(Q?.error?.(W))??UW(Y.customError?.(W))??UW(Y.localeError?.(W))??"Invalid input",{inst:G,continue:J,input:H,...w}=W;if(w.path??(w.path=[]),w.message=X,Q?.reportInput)w.input=H;return w}function BY(W){if(W instanceof Set)return"set";if(W instanceof Map)return"map";if(W instanceof File)return"file";return"unknown"}function $W(W){if(Array.isArray(W))return"array";if(typeof W==="string")return"string";return"unknown"}function MQ(W){let Q=typeof W;switch(Q){case"number":return Number.isNaN(W)?"nan":"number";case"object":{if(W===null)return"null";if(Array.isArray(W))return"array";let Y=W;if(Y&&Object.getPrototypeOf(Y)!==Object.prototype&&"constructor"in Y&&Y.constructor)return Y.constructor.name}}return Q}function LW(...W){let[Q,Y,X]=W;if(typeof Q==="string")return{message:Q,code:"custom",input:Y,inst:X};return{...Q}}function H9(W){return Object.entries(W).filter(([Q,Y])=>{return Number.isNaN(Number.parseInt(Q,10))}).map((Q)=>Q[1])}function NY(W){let Q=atob(W),Y=new Uint8Array(Q.length);for(let X=0;X<Q.length;X++)Y[X]=Q.charCodeAt(X);return Y}function MY(W){let Q="";for(let Y=0;Y<W.length;Y++)Q+=String.fromCharCode(W[Y]);return btoa(Q)}function w9(W){let Q=W.replace(/-/g,"+").replace(/_/g,"/"),Y="=".repeat((4-Q.length%4)%4);return NY(Q+Y)}function A9(W){return MY(W).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function q9(W){let Q=W.replace(/^0x/,"");if(Q.length%2!==0)throw Error("Invalid hex string length");let Y=new Uint8Array(Q.length/2);for(let X=0;X<Q.length;X+=2)Y[X/2]=Number.parseInt(Q.slice(X,X+2),16);return Y}function K9(W){return Array.from(W).map((Q)=>Q.toString(16).padStart(2,"0")).join("")}class zY{constructor(...W){}}var DY=(W,Q)=>{W.name="$ZodError",Object.defineProperty(W,"_zod",{value:W._zod,enumerable:!1}),Object.defineProperty(W,"issues",{value:Q,enumerable:!1}),W.message=JSON.stringify(Q,qW,2),Object.defineProperty(W,"toString",{value:()=>W.message,enumerable:!1})},yW=K("$ZodError",DY),zQ=K("$ZodError",DY,{Parent:Error});function UY(W,Q=(Y)=>Y.message){let Y={},X=[];for(let G of W.issues)if(G.path.length>0)Y[G.path[0]]=Y[G.path[0]]||[],Y[G.path[0]].push(Q(G));else X.push(Q(G));return{formErrors:X,fieldErrors:Y}}function VY(W,Q=(Y)=>Y.message){let Y={_errors:[]},X=(G,J=[])=>{for(let H of G.issues)if(H.code==="invalid_union"&&H.errors.length)H.errors.map((w)=>X({issues:w},[...J,...H.path]));else if(H.code==="invalid_key")X({issues:H.issues},[...J,...H.path]);else if(H.code==="invalid_element")X({issues:H.issues},[...J,...H.path]);else{let w=[...J,...H.path];if(w.length===0)Y._errors.push(Q(H));else{let q=Y,L=0;while(L<w.length){let B=w[L];if(L!==w.length-1)q[B]=q[B]||{_errors:[]};else q[B]=q[B]||{_errors:[]},q[B]._errors.push(Q(H));q=q[B],L++}}}};return X(W),Y}var mW=(W)=>(Q,Y,X,G)=>{let J=X?{...X,async:!1}:{async:!1},H=Q._zod.run({value:Y,issues:[]},J);if(H instanceof Promise)throw new a;if(H.issues.length){let w=new(G?.Err??W)(H.issues.map((q)=>d(q,J,l())));throw cW(w,G?.callee),w}return H.value};var fW=(W)=>async(Q,Y,X,G)=>{let J=X?{...X,async:!0}:{async:!0},H=Q._zod.run({value:Y,issues:[]},J);if(H instanceof Promise)H=await H;if(H.issues.length){let w=new(G?.Err??W)(H.issues.map((q)=>d(q,J,l())));throw cW(w,G?.callee),w}return H.value};var EW=(W)=>(Q,Y,X)=>{let G=X?{...X,async:!1}:{async:!1},J=Q._zod.run({value:Y,issues:[]},G);if(J instanceof Promise)throw new a;return J.issues.length?{success:!1,error:new(W??yW)(J.issues.map((H)=>d(H,G,l())))}:{success:!0,data:J.value}},IY=EW(zQ),OW=(W)=>async(Q,Y,X)=>{let G=X?{...X,async:!0}:{async:!0},J=Q._zod.run({value:Y,issues:[]},G);if(J instanceof Promise)J=await J;return J.issues.length?{success:!1,error:new W(J.issues.map((H)=>d(H,G,l())))}:{success:!0,data:J.value}},FY=OW(zQ),$Y=(W)=>(Q,Y,X)=>{let G=X?{...X,direction:"backward"}:{direction:"backward"};return mW(W)(Q,Y,G)};var EY=(W)=>(Q,Y,X)=>{return mW(W)(Q,Y,X)};var OY=(W)=>async(Q,Y,X)=>{let G=X?{...X,direction:"backward"}:{direction:"backward"};return fW(W)(Q,Y,G)};var PY=(W)=>async(Q,Y,X)=>{return fW(W)(Q,Y,X)};var RY=(W)=>(Q,Y,X)=>{let G=X?{...X,direction:"backward"}:{direction:"backward"};return EW(W)(Q,Y,G)};var SY=(W)=>(Q,Y,X)=>{return EW(W)(Q,Y,X)};var bY=(W)=>async(Q,Y,X)=>{let G=X?{...X,direction:"backward"}:{direction:"backward"};return OW(W)(Q,Y,G)};var TY=(W)=>async(Q,Y,X)=>{return OW(W)(Q,Y,X)};var _Y=/^[cC][0-9a-z]{6,}$/,ZY=/^[0-9a-z]+$/,CY=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,jY=/^[0-9a-vA-V]{20}$/,kY=/^[A-Za-z0-9]{27}$/,vY=/^[a-zA-Z0-9_-]{21}$/,gY=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var hY=/^([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})$/,DQ=(W)=>{if(!W)return/^([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)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${W}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var xY=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var B9="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function cY(){return new RegExp(B9,"u")}var uY=/^(?:(?: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])$/,yY=/^(([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}|:))$/;var mY=/^((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])$/,fY=/^(([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])$/,oY=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,UQ=/^[A-Za-z0-9_-]*$/;var lY=/^https?$/,rY=/^\+[1-9]\d{6,14}$/,pY="(?:(?:\\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])))",dY=new RegExp(`^${pY}$`);function nY(W){return typeof W.precision==="number"?W.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":W.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${W.precision}}`:"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function iY(W){return new RegExp(`^${nY(W)}$`)}function tY(W){let Q=nY({precision:W.precision}),Y=["Z"];if(W.local)Y.push("");if(W.offset)Y.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let X=`${Q}(?:${Y.join("|")})`;return new RegExp(`^${pY}T(?:${X})$`)}var eY=(W)=>{let Q=W?`[\\s\\S]{${W?.minimum??0},${W?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${Q}$`)};var aY=/^-?\d+$/,oW=/^-?\d+(?:\.\d+)?$/,sY=/^(?:true|false)$/i,W0=/^null$/i;var Q0=/^[^A-Z]*$/,Y0=/^[^a-z]*$/;var c=K("$ZodCheck",(W,Q)=>{var Y;W._zod??(W._zod={}),W._zod.def=Q,(Y=W._zod).onattach??(Y.onattach=[])}),X0={number:"number",bigint:"bigint",object:"date"},VQ=K("$ZodCheckLessThan",(W,Q)=>{c.init(W,Q);let Y=X0[typeof Q.value];W._zod.onattach.push((X)=>{let G=X._zod.bag,J=(Q.inclusive?G.maximum:G.exclusiveMaximum)??Number.POSITIVE_INFINITY;if(Q.value<J)if(Q.inclusive)G.maximum=Q.value;else G.exclusiveMaximum=Q.value}),W._zod.check=(X)=>{if(Q.inclusive?X.value<=Q.value:X.value<Q.value)return;X.issues.push({origin:Y,code:"too_big",maximum:typeof Q.value==="object"?Q.value.getTime():Q.value,input:X.value,inclusive:Q.inclusive,inst:W,continue:!Q.abort})}}),IQ=K("$ZodCheckGreaterThan",(W,Q)=>{c.init(W,Q);let Y=X0[typeof Q.value];W._zod.onattach.push((X)=>{let G=X._zod.bag,J=(Q.inclusive?G.minimum:G.exclusiveMinimum)??Number.NEGATIVE_INFINITY;if(Q.value>J)if(Q.inclusive)G.minimum=Q.value;else G.exclusiveMinimum=Q.value}),W._zod.check=(X)=>{if(Q.inclusive?X.value>=Q.value:X.value>Q.value)return;X.issues.push({origin:Y,code:"too_small",minimum:typeof Q.value==="object"?Q.value.getTime():Q.value,input:X.value,inclusive:Q.inclusive,inst:W,continue:!Q.abort})}}),G0=K("$ZodCheckMultipleOf",(W,Q)=>{c.init(W,Q),W._zod.onattach.push((Y)=>{var X;(X=Y._zod.bag).multipleOf??(X.multipleOf=Q.value)}),W._zod.check=(Y)=>{if(typeof Y.value!==typeof Q.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof Y.value==="bigint"?Y.value%Q.value===BigInt(0):wQ(Y.value,Q.value)===0)return;Y.issues.push({origin:typeof Y.value,code:"not_multiple_of",divisor:Q.value,input:Y.value,inst:W,continue:!Q.abort})}}),J0=K("$ZodCheckNumberFormat",(W,Q)=>{c.init(W,Q),Q.format=Q.format||"float64";let Y=Q.format?.includes("int"),X=Y?"int":"number",[G,J]=BQ[Q.format];W._zod.onattach.push((H)=>{let w=H._zod.bag;if(w.format=Q.format,w.minimum=G,w.maximum=J,Y)w.pattern=aY}),W._zod.check=(H)=>{let w=H.value;if(Y){if(!Number.isInteger(w)){H.issues.push({expected:X,format:Q.format,code:"invalid_type",continue:!1,input:w,inst:W});return}if(!Number.isSafeInteger(w)){if(w>0)H.issues.push({input:w,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:W,origin:X,inclusive:!0,continue:!Q.abort});else H.issues.push({input:w,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:W,origin:X,inclusive:!0,continue:!Q.abort});return}}if(w<G)H.issues.push({origin:"number",input:w,code:"too_small",minimum:G,inclusive:!0,inst:W,continue:!Q.abort});if(w>J)H.issues.push({origin:"number",input:w,code:"too_big",maximum:J,inclusive:!0,inst:W,continue:!Q.abort})}});var H0=K("$ZodCheckMaxLength",(W,Q)=>{var Y;c.init(W,Q),(Y=W._zod.def).when??(Y.when=(X)=>{let G=X.value;return!IW(G)&&G.length!==void 0}),W._zod.onattach.push((X)=>{let G=X._zod.bag.maximum??Number.POSITIVE_INFINITY;if(Q.maximum<G)X._zod.bag.maximum=Q.maximum}),W._zod.check=(X)=>{let G=X.value;if(G.length<=Q.maximum)return;let H=$W(G);X.issues.push({origin:H,code:"too_big",maximum:Q.maximum,inclusive:!0,input:G,inst:W,continue:!Q.abort})}}),w0=K("$ZodCheckMinLength",(W,Q)=>{var Y;c.init(W,Q),(Y=W._zod.def).when??(Y.when=(X)=>{let G=X.value;return!IW(G)&&G.length!==void 0}),W._zod.onattach.push((X)=>{let G=X._zod.bag.minimum??Number.NEGATIVE_INFINITY;if(Q.minimum>G)X._zod.bag.minimum=Q.minimum}),W._zod.check=(X)=>{let G=X.value;if(G.length>=Q.minimum)return;let H=$W(G);X.issues.push({origin:H,code:"too_small",minimum:Q.minimum,inclusive:!0,input:G,inst:W,continue:!Q.abort})}}),A0=K("$ZodCheckLengthEquals",(W,Q)=>{var Y;c.init(W,Q),(Y=W._zod.def).when??(Y.when=(X)=>{let G=X.value;return!IW(G)&&G.length!==void 0}),W._zod.onattach.push((X)=>{let G=X._zod.bag;G.minimum=Q.length,G.maximum=Q.length,G.length=Q.length}),W._zod.check=(X)=>{let G=X.value,J=G.length;if(J===Q.length)return;let H=$W(G),w=J>Q.length;X.issues.push({origin:H,...w?{code:"too_big",maximum:Q.length}:{code:"too_small",minimum:Q.length},inclusive:!0,exact:!0,input:X.value,inst:W,continue:!Q.abort})}}),PW=K("$ZodCheckStringFormat",(W,Q)=>{var Y,X;if(c.init(W,Q),W._zod.onattach.push((G)=>{let J=G._zod.bag;if(J.format=Q.format,Q.pattern)J.patterns??(J.patterns=new Set),J.patterns.add(Q.pattern)}),Q.pattern)(Y=W._zod).check??(Y.check=(G)=>{if(Q.pattern.lastIndex=0,Q.pattern.test(G.value))return;G.issues.push({origin:"string",code:"invalid_format",format:Q.format,input:G.value,...Q.pattern?{pattern:Q.pattern.toString()}:{},inst:W,continue:!Q.abort})});else(X=W._zod).check??(X.check=()=>{})}),q0=K("$ZodCheckRegex",(W,Q)=>{PW.init(W,Q),W._zod.check=(Y)=>{if(Q.pattern.lastIndex=0,Q.pattern.test(Y.value))return;Y.issues.push({origin:"string",code:"invalid_format",format:"regex",input:Y.value,pattern:Q.pattern.toString(),inst:W,continue:!Q.abort})}}),K0=K("$ZodCheckLowerCase",(W,Q)=>{Q.pattern??(Q.pattern=Q0),PW.init(W,Q)}),L0=K("$ZodCheckUpperCase",(W,Q)=>{Q.pattern??(Q.pattern=Y0),PW.init(W,Q)}),B0=K("$ZodCheckIncludes",(W,Q)=>{c.init(W,Q);let Y=WW(Q.includes),X=new RegExp(typeof Q.position==="number"?`^.{${Q.position}}${Y}`:Y);Q.pattern=X,W._zod.onattach.push((G)=>{let J=G._zod.bag;J.patterns??(J.patterns=new Set),J.patterns.add(X)}),W._zod.check=(G)=>{if(G.value.includes(Q.includes,Q.position))return;G.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:Q.includes,input:G.value,inst:W,continue:!Q.abort})}}),N0=K("$ZodCheckStartsWith",(W,Q)=>{c.init(W,Q);let Y=new RegExp(`^${WW(Q.prefix)}.*`);Q.pattern??(Q.pattern=Y),W._zod.onattach.push((X)=>{let G=X._zod.bag;G.patterns??(G.patterns=new Set),G.patterns.add(Y)}),W._zod.check=(X)=>{if(X.value.startsWith(Q.prefix))return;X.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:Q.prefix,input:X.value,inst:W,continue:!Q.abort})}}),M0=K("$ZodCheckEndsWith",(W,Q)=>{c.init(W,Q);let Y=new RegExp(`.*${WW(Q.suffix)}$`);Q.pattern??(Q.pattern=Y),W._zod.onattach.push((X)=>{let G=X._zod.bag;G.patterns??(G.patterns=new Set),G.patterns.add(Y)}),W._zod.check=(X)=>{if(X.value.endsWith(Q.suffix))return;X.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:Q.suffix,input:X.value,inst:W,continue:!Q.abort})}});var z0=K("$ZodCheckOverwrite",(W,Q)=>{c.init(W,Q),W._zod.check=(Y)=>{Y.value=Q.tx(Y.value)}});class FQ{constructor(W=[]){if(this.content=[],this.indent=0,this)this.args=W}indented(W){this.indent+=1,W(this),this.indent-=1}write(W){if(typeof W==="function"){W(this,{execution:"sync"}),W(this,{execution:"async"});return}let Y=W.split(`
3
3
  `).filter((J)=>J),X=Math.min(...Y.map((J)=>J.length-J.trimStart().length)),G=Y.map((J)=>J.slice(X)).map((J)=>" ".repeat(this.indent*2)+J);for(let J of G)this.content.push(J)}compile(){let W=Function,Q=this?.args,X=[...(this?.content??[""]).map((G)=>` ${G}`)];return new W(...Q,X.join(`
4
4
  `))}}var U0={major:4,minor:4,patch:3};var R=K("$ZodType",(W,Q)=>{var Y;W??(W={}),W._zod.def=Q,W._zod.bag=W._zod.bag||{},W._zod.version=U0;let X=[...W._zod.def.checks??[]];if(W._zod.traits.has("$ZodCheck"))X.unshift(W);for(let G of X)for(let J of G._zod.onattach)J(W);if(X.length===0)(Y=W._zod).deferred??(Y.deferred=[]),W._zod.deferred?.push(()=>{W._zod.run=W._zod.parse});else{let G=(H,w,q)=>{let L=GW(H),B;for(let z of w){if(z._zod.def.when){if(NQ(H))continue;if(!z._zod.def.when(H))continue}else if(L)continue;let V=H.issues.length,D=z._zod.check(H);if(D instanceof Promise&&q?.async===!1)throw new a;if(B||D instanceof Promise)B=(B??Promise.resolve()).then(async()=>{if(await D,H.issues.length===V)return;if(!L)L=GW(H,V)});else{if(H.issues.length===V)continue;if(!L)L=GW(H,V)}}if(B)return B.then(()=>{return H});return H},J=(H,w,q)=>{if(GW(H))return H.aborted=!0,H;let L=G(w,X,q);if(L instanceof Promise){if(q.async===!1)throw new a;return L.then((B)=>W._zod.parse(B,q))}return W._zod.parse(L,q)};W._zod.run=(H,w)=>{if(w.skipChecks)return W._zod.parse(H,w);if(w.direction==="backward"){let L=W._zod.parse({value:H.value,issues:[]},{...w,skipChecks:!0});if(L instanceof Promise)return L.then((B)=>{return J(B,H,w)});return J(L,H,w)}let q=W._zod.parse(H,w);if(q instanceof Promise){if(w.async===!1)throw new a;return q.then((L)=>G(L,X,w))}return G(q,X,w)}}$(W,"~standard",()=>({validate:(G)=>{try{let J=IY(W,G);return J.success?{value:J.data}:{issues:J.error?.issues}}catch(J){return FY(W,G).then((H)=>H.success?{value:H.data}:{issues:H.error?.issues})}},vendor:"zod",version:1}))}),dW=K("$ZodString",(W,Q)=>{R.init(W,Q),W._zod.pattern=[...W?._zod.bag?.patterns??[]].pop()??eY(W._zod.bag),W._zod.parse=(Y,X)=>{if(Q.coerce)try{Y.value=String(Y.value)}catch(G){}if(typeof Y.value==="string")return Y;return Y.issues.push({expected:"string",code:"invalid_type",input:Y.value,inst:W}),Y}}),S=K("$ZodStringFormat",(W,Q)=>{PW.init(W,Q),dW.init(W,Q)}),S0=K("$ZodGUID",(W,Q)=>{Q.pattern??(Q.pattern=hY),S.init(W,Q)}),b0=K("$ZodUUID",(W,Q)=>{if(Q.version){let X={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[Q.version];if(X===void 0)throw Error(`Invalid UUID version: "${Q.version}"`);Q.pattern??(Q.pattern=DQ(X))}else Q.pattern??(Q.pattern=DQ());S.init(W,Q)}),T0=K("$ZodEmail",(W,Q)=>{Q.pattern??(Q.pattern=xY),S.init(W,Q)}),_0=K("$ZodURL",(W,Q)=>{S.init(W,Q),W._zod.check=(Y)=>{try{let X=Y.value.trim();if(!Q.normalize&&Q.protocol?.source===lY.source){if(!/^https?:\/\//i.test(X)){Y.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:Y.value,inst:W,continue:!Q.abort});return}}let G=new URL(X);if(Q.hostname){if(Q.hostname.lastIndex=0,!Q.hostname.test(G.hostname))Y.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Q.hostname.source,input:Y.value,inst:W,continue:!Q.abort})}if(Q.protocol){if(Q.protocol.lastIndex=0,!Q.protocol.test(G.protocol.endsWith(":")?G.protocol.slice(0,-1):G.protocol))Y.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:Q.protocol.source,input:Y.value,inst:W,continue:!Q.abort})}if(Q.normalize)Y.value=G.href;else Y.value=X;return}catch(X){Y.issues.push({code:"invalid_format",format:"url",input:Y.value,inst:W,continue:!Q.abort})}}}),Z0=K("$ZodEmoji",(W,Q)=>{Q.pattern??(Q.pattern=cY()),S.init(W,Q)}),C0=K("$ZodNanoID",(W,Q)=>{Q.pattern??(Q.pattern=vY),S.init(W,Q)}),j0=K("$ZodCUID",(W,Q)=>{Q.pattern??(Q.pattern=_Y),S.init(W,Q)}),k0=K("$ZodCUID2",(W,Q)=>{Q.pattern??(Q.pattern=ZY),S.init(W,Q)}),v0=K("$ZodULID",(W,Q)=>{Q.pattern??(Q.pattern=CY),S.init(W,Q)}),g0=K("$ZodXID",(W,Q)=>{Q.pattern??(Q.pattern=jY),S.init(W,Q)}),h0=K("$ZodKSUID",(W,Q)=>{Q.pattern??(Q.pattern=kY),S.init(W,Q)}),x0=K("$ZodISODateTime",(W,Q)=>{Q.pattern??(Q.pattern=tY(Q)),S.init(W,Q)}),c0=K("$ZodISODate",(W,Q)=>{Q.pattern??(Q.pattern=dY),S.init(W,Q)}),u0=K("$ZodISOTime",(W,Q)=>{Q.pattern??(Q.pattern=iY(Q)),S.init(W,Q)}),y0=K("$ZodISODuration",(W,Q)=>{Q.pattern??(Q.pattern=gY),S.init(W,Q)}),m0=K("$ZodIPv4",(W,Q)=>{Q.pattern??(Q.pattern=uY),S.init(W,Q),W._zod.bag.format="ipv4"}),f0=K("$ZodIPv6",(W,Q)=>{Q.pattern??(Q.pattern=yY),S.init(W,Q),W._zod.bag.format="ipv6",W._zod.check=(Y)=>{try{new URL(`http://[${Y.value}]`)}catch{Y.issues.push({code:"invalid_format",format:"ipv6",input:Y.value,inst:W,continue:!Q.abort})}}});var o0=K("$ZodCIDRv4",(W,Q)=>{Q.pattern??(Q.pattern=mY),S.init(W,Q)}),l0=K("$ZodCIDRv6",(W,Q)=>{Q.pattern??(Q.pattern=fY),S.init(W,Q),W._zod.check=(Y)=>{let X=Y.value.split("/");try{if(X.length!==2)throw Error();let[G,J]=X;if(!J)throw Error();let H=Number(J);if(`${H}`!==J)throw Error();if(H<0||H>128)throw Error();new URL(`http://[${G}]`)}catch{Y.issues.push({code:"invalid_format",format:"cidrv6",input:Y.value,inst:W,continue:!Q.abort})}}});function r0(W){if(W==="")return!0;if(/\s/.test(W))return!1;if(W.length%4!==0)return!1;try{return atob(W),!0}catch{return!1}}var p0=K("$ZodBase64",(W,Q)=>{Q.pattern??(Q.pattern=oY),S.init(W,Q),W._zod.bag.contentEncoding="base64",W._zod.check=(Y)=>{if(r0(Y.value))return;Y.issues.push({code:"invalid_format",format:"base64",input:Y.value,inst:W,continue:!Q.abort})}});function N9(W){if(!UQ.test(W))return!1;let Q=W.replace(/[-_]/g,(X)=>X==="-"?"+":"/"),Y=Q.padEnd(Math.ceil(Q.length/4)*4,"=");return r0(Y)}var d0=K("$ZodBase64URL",(W,Q)=>{Q.pattern??(Q.pattern=UQ),S.init(W,Q),W._zod.bag.contentEncoding="base64url",W._zod.check=(Y)=>{if(N9(Y.value))return;Y.issues.push({code:"invalid_format",format:"base64url",input:Y.value,inst:W,continue:!Q.abort})}}),n0=K("$ZodE164",(W,Q)=>{Q.pattern??(Q.pattern=rY),S.init(W,Q)});function M9(W,Q=null){try{let Y=W.split(".");if(Y.length!==3)return!1;let[X]=Y;if(!X)return!1;let G=JSON.parse(atob(X));if("typ"in G&&G?.typ!=="JWT")return!1;if(!G.alg)return!1;if(Q&&(!("alg"in G)||G.alg!==Q))return!1;return!0}catch{return!1}}var i0=K("$ZodJWT",(W,Q)=>{S.init(W,Q),W._zod.check=(Y)=>{if(M9(Y.value,Q.alg))return;Y.issues.push({code:"invalid_format",format:"jwt",input:Y.value,inst:W,continue:!Q.abort})}});var EQ=K("$ZodNumber",(W,Q)=>{R.init(W,Q),W._zod.pattern=W._zod.bag.pattern??oW,W._zod.parse=(Y,X)=>{if(Q.coerce)try{Y.value=Number(Y.value)}catch(H){}let G=Y.value;if(typeof G==="number"&&!Number.isNaN(G)&&Number.isFinite(G))return Y;let J=typeof G==="number"?Number.isNaN(G)?"NaN":!Number.isFinite(G)?"Infinity":void 0:void 0;return Y.issues.push({expected:"number",code:"invalid_type",input:G,inst:W,...J?{received:J}:{}}),Y}}),t0=K("$ZodNumberFormat",(W,Q)=>{J0.init(W,Q),EQ.init(W,Q)}),e0=K("$ZodBoolean",(W,Q)=>{R.init(W,Q),W._zod.pattern=sY,W._zod.parse=(Y,X)=>{if(Q.coerce)try{Y.value=Boolean(Y.value)}catch(J){}let G=Y.value;if(typeof G==="boolean")return Y;return Y.issues.push({expected:"boolean",code:"invalid_type",input:G,inst:W}),Y}});var a0=K("$ZodNull",(W,Q)=>{R.init(W,Q),W._zod.pattern=W0,W._zod.values=new Set([null]),W._zod.parse=(Y,X)=>{let G=Y.value;if(G===null)return Y;return Y.issues.push({expected:"null",code:"invalid_type",input:G,inst:W}),Y}});var s0=K("$ZodUnknown",(W,Q)=>{R.init(W,Q),W._zod.parse=(Y)=>Y}),W4=K("$ZodNever",(W,Q)=>{R.init(W,Q),W._zod.parse=(Y,X)=>{return Y.issues.push({expected:"never",code:"invalid_type",input:Y.value,inst:W}),Y}});function V0(W,Q,Y){if(W.issues.length)Q.issues.push(...QW(Y,W.issues));Q.value[Y]=W.value}var Q4=K("$ZodArray",(W,Q)=>{R.init(W,Q),W._zod.parse=(Y,X)=>{let G=Y.value;if(!Array.isArray(G))return Y.issues.push({expected:"array",code:"invalid_type",input:G,inst:W}),Y;Y.value=Array(G.length);let J=[];for(let H=0;H<G.length;H++){let w=G[H],q=Q.element._zod.run({value:w,issues:[]},X);if(q instanceof Promise)J.push(q.then((L)=>V0(L,Y,H)));else V0(q,Y,H)}if(J.length)return Promise.all(J).then(()=>Y);return Y}});function pW(W,Q,Y,X,G,J){let H=Y in X;if(W.issues.length){if(G&&J&&!H)return;Q.issues.push(...QW(Y,W.issues))}if(!H&&!G){if(!W.issues.length)Q.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[Y]});return}if(W.value===void 0){if(H)Q.value[Y]=void 0}else Q.value[Y]=W.value}function Y4(W){let Q=Object.keys(W.shape);for(let X of Q)if(!W.shape?.[X]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${X}": expected a Zod schema`);let Y=LQ(W.shape);return{...W,keys:Q,keySet:new Set(Q),numKeys:Q.length,optionalKeys:new Set(Y)}}function X4(W,Q,Y,X,G,J){let H=[],w=G.keySet,q=G.catchall._zod,L=q.def.type,B=q.optin==="optional",z=q.optout==="optional";for(let V in Q){if(V==="__proto__")continue;if(w.has(V))continue;if(L==="never"){H.push(V);continue}let D=q.run({value:Q[V],issues:[]},X);if(D instanceof Promise)W.push(D.then((O)=>pW(O,Y,V,Q,B,z)));else pW(D,Y,V,Q,B,z)}if(H.length)Y.issues.push({code:"unrecognized_keys",keys:H,input:Q,inst:J});if(!W.length)return Y;return Promise.all(W).then(()=>{return Y})}var z9=K("$ZodObject",(W,Q)=>{if(R.init(W,Q),!Object.getOwnPropertyDescriptor(Q,"shape")?.get){let w=Q.shape;Object.defineProperty(Q,"shape",{get:()=>{let q={...w};return Object.defineProperty(Q,"shape",{value:q}),q}})}let X=KW(()=>Y4(Q));$(W._zod,"propValues",()=>{let w=Q.shape,q={};for(let L in w){let B=w[L]._zod;if(B.values){q[L]??(q[L]=new Set);for(let z of B.values)q[L].add(z)}}return q});let G=HW,J=Q.catchall,H;W._zod.parse=(w,q)=>{H??(H=X.value);let L=w.value;if(!G(L))return w.issues.push({expected:"object",code:"invalid_type",input:L,inst:W}),w;w.value={};let B=[],z=H.shape;for(let V of H.keys){let D=z[V],O=D._zod.optin==="optional",zW=D._zod.optout==="optional",g=D._zod.run({value:L[V],issues:[]},q);if(g instanceof Promise)B.push(g.then((JQ)=>pW(JQ,w,V,L,O,zW)));else pW(g,w,V,L,O,zW)}if(!J)return B.length?Promise.all(B).then(()=>w):w;return X4(B,L,w,q,X.value,W)}}),G4=K("$ZodObjectJIT",(W,Q)=>{z9.init(W,Q);let Y=W._zod.parse,X=KW(()=>Y4(Q)),G=(V)=>{let D=new FQ(["shape","payload","ctx"]),O=X.value,zW=(e)=>{let j=xW(e);return`shape[${j}]._zod.run({ value: input[${j}], issues: [] }, ctx)`};D.write("const input = payload.value;");let g=Object.create(null),JQ=0;for(let e of O.keys)g[e]=`key_${JQ++}`;D.write("const newResult = {};");for(let e of O.keys){let j=g[e],x=xW(e),GY=V[e],JY=GY?._zod?.optin==="optional",h3=GY?._zod?.optout==="optional";if(D.write(`const ${j} = ${zW(e)};`),JY&&h3)D.write(`
@@ -1,4 +1,4 @@
1
- /*! @mcpcloud/runtime v0.12.3 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
1
+ /*! @mcpcloud/runtime v0.12.4 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
2
  var pK=Object.create;var{getPrototypeOf:dK,defineProperty:m9,getOwnPropertyNames:oK}=Object;var tK=Object.prototype.hasOwnProperty;function aK($){return this[$]}var sK,eK,bz=($,v,U)=>{var J=$!=null&&typeof $==="object";if(J){var z=v?sK??=new WeakMap:eK??=new WeakMap,W=z.get($);if(W)return W}U=$!=null?pK(dK($)):{};let X=v||!$||!$.__esModule?m9(U,"default",{value:$,enumerable:!0}):U;for(let Q of oK($))if(!tK.call(X,Q))m9(X,Q,{get:aK.bind($,Q),enumerable:!0});if(J)z.set($,X);return X};var K=($,v)=>()=>(v||$((v={exports:{}}).exports,v),v.exports);var $F=($)=>$;function vF($,v){this[$]=$F.bind(null,v)}var s4=($,v)=>{for(var U in v)m9($,U,{get:v[U],enumerable:!0,configurable:!0,set:vF.bind(v,U)})};var j0=K(($B)=>{Object.defineProperty($B,"__esModule",{value:!0});$B.regexpCode=$B.getEsmExportName=$B.getProperty=$B.safeStringify=$B.stringify=$B.strConcat=$B.addCodeArg=$B.str=$B._=$B.nil=$B._Code=$B.Name=$B.IDENTIFIER=$B._CodeOrName=void 0;class kX{}$B._CodeOrName=kX;$B.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class A1 extends kX{constructor($){super();if(!$B.IDENTIFIER.test($))throw Error("CodeGen: name must be a valid identifier");this.str=$}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}$B.Name=A1;class E4 extends kX{constructor($){super();this._items=typeof $==="string"?[$]:$}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;let $=this._items[0];return $===""||$==='""'}get str(){var $;return($=this._str)!==null&&$!==void 0?$:this._str=this._items.reduce((v,U)=>`${v}${U}`,"")}get names(){var $;return($=this._names)!==null&&$!==void 0?$:this._names=this._items.reduce((v,U)=>{if(U instanceof A1)v[U.str]=(v[U.str]||0)+1;return v},{})}}$B._Code=E4;$B.nil=new E4("");function s3($,...v){let U=[$[0]],J=0;while(J<v.length)yY(U,v[J]),U.push($[++J]);return new E4(U)}$B._=s3;var xY=new E4("+");function e3($,...v){let U=[V0($[0])],J=0;while(J<v.length)U.push(xY),yY(U,v[J]),U.push(xY,V0($[++J]));return hS(U),new E4(U)}$B.str=e3;function yY($,v){if(v instanceof E4)$.push(...v._items);else if(v instanceof A1)$.push(v);else $.push(rS(v))}$B.addCodeArg=yY;function hS($){let v=1;while(v<$.length-1){if($[v]===xY){let U=nS($[v-1],$[v+1]);if(U!==void 0){$.splice(v-1,3,U);continue}$[v++]="+"}v++}}function nS($,v){if(v==='""')return $;if($==='""')return v;if(typeof $=="string"){if(v instanceof A1||$[$.length-1]!=='"')return;if(typeof v!="string")return`${$.slice(0,-1)}${v}"`;if(v[0]==='"')return $.slice(0,-1)+v.slice(1);return}if(typeof v=="string"&&v[0]==='"'&&!($ instanceof A1))return`"${$}${v.slice(1)}`;return}function mS($,v){return v.emptyStr()?$:$.emptyStr()?v:e3`${$}${v}`}$B.strConcat=mS;function rS($){return typeof $=="number"||typeof $=="boolean"||$===null?$:V0(Array.isArray($)?$.join(","):$)}function cS($){return new E4(V0($))}$B.stringify=cS;function V0($){return JSON.stringify($).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}$B.safeStringify=V0;function pS($){return typeof $=="string"&&$B.IDENTIFIER.test($)?new E4(`.${$}`):s3`[${$}]`}$B.getProperty=pS;function dS($){if(typeof $=="string"&&$B.IDENTIFIER.test($))return new E4(`${$}`);throw Error(`CodeGen: invalid export name: ${$}, use explicit $id name mapping`)}$B.getEsmExportName=dS;function oS($){return new E4($.toString())}$B.regexpCode=oS});var nY=K((JB)=>{Object.defineProperty(JB,"__esModule",{value:!0});JB.ValueScope=JB.ValueScopeName=JB.Scope=JB.varKinds=JB.UsedValueState=void 0;var z4=j0();class UB extends Error{constructor($){super(`CodeGen: "code" for ${$} not defined`);this.value=$.value}}var ZX;(function($){$[$.Started=0]="Started",$[$.Completed=1]="Completed"})(ZX||(JB.UsedValueState=ZX={}));JB.varKinds={const:new z4.Name("const"),let:new z4.Name("let"),var:new z4.Name("var")};class iY{constructor({prefixes:$,parent:v}={}){this._names={},this._prefixes=$,this._parent=v}toName($){return $ instanceof z4.Name?$:this.name($)}name($){return new z4.Name(this._newName($))}_newName($){let v=this._names[$]||this._nameGroup($);return`${$}${v.index++}`}_nameGroup($){var v,U;if(((U=(v=this._parent)===null||v===void 0?void 0:v._prefixes)===null||U===void 0?void 0:U.has($))||this._prefixes&&!this._prefixes.has($))throw Error(`CodeGen: prefix "${$}" is not allowed in this scope`);return this._names[$]={prefix:$,index:0}}}JB.Scope=iY;class hY extends z4.Name{constructor($,v){super(v);this.prefix=$}setValue($,{property:v,itemIndex:U}){this.value=$,this.scopePath=z4._`.${new z4.Name(v)}[${U}]`}}JB.ValueScopeName=hY;var GE=z4._`\n`;class zB extends iY{constructor($){super($);this._values={},this._scope=$.scope,this.opts={...$,_n:$.lines?GE:z4.nil}}get(){return this._scope}name($){return new hY($,this._newName($))}value($,v){var U;if(v.ref===void 0)throw Error("CodeGen: ref must be passed in value");let J=this.toName($),{prefix:z}=J,W=(U=v.key)!==null&&U!==void 0?U:v.ref,X=this._values[z];if(X){let D=X.get(W);if(D)return D}else X=this._values[z]=new Map;X.set(W,J);let Q=this._scope[z]||(this._scope[z]=[]),G=Q.length;return Q[G]=v.ref,J.setValue(v,{property:z,itemIndex:G}),J}getValue($,v){let U=this._values[$];if(!U)return;return U.get(v)}scopeRefs($,v=this._values){return this._reduceValues(v,(U)=>{if(U.scopePath===void 0)throw Error(`CodeGen: name "${U}" has no value`);return z4._`${$}${U.scopePath}`})}scopeCode($=this._values,v,U){return this._reduceValues($,(J)=>{if(J.value===void 0)throw Error(`CodeGen: name "${J}" has no value`);return J.value.code},v,U)}_reduceValues($,v,U={},J){let z=z4.nil;for(let W in $){let X=$[W];if(!X)continue;let Q=U[W]=U[W]||new Map;X.forEach((G)=>{if(Q.has(G))return;Q.set(G,ZX.Started);let D=v(G);if(D){let Y=this.opts.es5?JB.varKinds.var:JB.varKinds.const;z=z4._`${z}${Y} ${G} = ${D};${this.opts._n}`}else if(D=J===null||J===void 0?void 0:J(G))z=z4._`${z}${D}${this.opts._n}`;else throw new UB(G);Q.set(G,ZX.Completed)})}return z}}JB.ValueScope=zB});var v$=K((J4)=>{Object.defineProperty(J4,"__esModule",{value:!0});J4.or=J4.and=J4.not=J4.CodeGen=J4.operators=J4.varKinds=J4.ValueScopeName=J4.ValueScope=J4.Scope=J4.Name=J4.regexpCode=J4.stringify=J4.getProperty=J4.nil=J4.strConcat=J4.str=J4._=void 0;var J$=j0(),P4=nY(),g6=j0();Object.defineProperty(J4,"_",{enumerable:!0,get:function(){return g6._}});Object.defineProperty(J4,"str",{enumerable:!0,get:function(){return g6.str}});Object.defineProperty(J4,"strConcat",{enumerable:!0,get:function(){return g6.strConcat}});Object.defineProperty(J4,"nil",{enumerable:!0,get:function(){return g6.nil}});Object.defineProperty(J4,"getProperty",{enumerable:!0,get:function(){return g6.getProperty}});Object.defineProperty(J4,"stringify",{enumerable:!0,get:function(){return g6.stringify}});Object.defineProperty(J4,"regexpCode",{enumerable:!0,get:function(){return g6.regexpCode}});Object.defineProperty(J4,"Name",{enumerable:!0,get:function(){return g6.Name}});var fX=nY();Object.defineProperty(J4,"Scope",{enumerable:!0,get:function(){return fX.Scope}});Object.defineProperty(J4,"ValueScope",{enumerable:!0,get:function(){return fX.ValueScope}});Object.defineProperty(J4,"ValueScopeName",{enumerable:!0,get:function(){return fX.ValueScopeName}});Object.defineProperty(J4,"varKinds",{enumerable:!0,get:function(){return fX.varKinds}});J4.operators={GT:new J$._Code(">"),GTE:new J$._Code(">="),LT:new J$._Code("<"),LTE:new J$._Code("<="),EQ:new J$._Code("==="),NEQ:new J$._Code("!=="),NOT:new J$._Code("!"),OR:new J$._Code("||"),AND:new J$._Code("&&"),ADD:new J$._Code("+")};class f6{optimizeNodes(){return this}optimizeNames($,v){return this}}class XB extends f6{constructor($,v,U){super();this.varKind=$,this.name=v,this.rhs=U}render({es5:$,_n:v}){let U=$?P4.varKinds.var:this.varKind,J=this.rhs===void 0?"":` = ${this.rhs}`;return`${U} ${this.name}${J};`+v}optimizeNames($,v){if(!$[this.name.str])return;if(this.rhs)this.rhs=M1(this.rhs,$,v);return this}get names(){return this.rhs instanceof J$._CodeOrName?this.rhs.names:{}}}class cY extends f6{constructor($,v,U){super();this.lhs=$,this.rhs=v,this.sideEffects=U}render({_n:$}){return`${this.lhs} = ${this.rhs};`+$}optimizeNames($,v){if(this.lhs instanceof J$.Name&&!$[this.lhs.str]&&!this.sideEffects)return;return this.rhs=M1(this.rhs,$,v),this}get names(){let $=this.lhs instanceof J$.Name?{}:{...this.lhs.names};return gX($,this.rhs)}}class QB extends cY{constructor($,v,U,J){super($,U,J);this.op=v}render({_n:$}){return`${this.lhs} ${this.op}= ${this.rhs};`+$}}class GB extends f6{constructor($){super();this.label=$,this.names={}}render({_n:$}){return`${this.label}:`+$}}class DB extends f6{constructor($){super();this.label=$,this.names={}}render({_n:$}){return`break${this.label?` ${this.label}`:""};`+$}}class YB extends f6{constructor($){super();this.error=$}render({_n:$}){return`throw ${this.error};`+$}get names(){return this.error.names}}class bB extends f6{constructor($){super();this.code=$}render({_n:$}){return`${this.code};`+$}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames($,v){return this.code=M1(this.code,$,v),this}get names(){return this.code instanceof J$._CodeOrName?this.code.names:{}}}class xX extends f6{constructor($=[]){super();this.nodes=$}render($){return this.nodes.reduce((v,U)=>v+U.render($),"")}optimizeNodes(){let{nodes:$}=this,v=$.length;while(v--){let U=$[v].optimizeNodes();if(Array.isArray(U))$.splice(v,1,...U);else if(U)$[v]=U;else $.splice(v,1)}return $.length>0?this:void 0}optimizeNames($,v){let{nodes:U}=this,J=U.length;while(J--){let z=U[J];if(z.optimizeNames($,v))continue;HE($,z.names),U.splice(J,1)}return U.length>0?this:void 0}get names(){return this.nodes.reduce(($,v)=>Bv($,v.names),{})}}class x6 extends xX{render($){return"{"+$._n+super.render($)+"}"+$._n}}class HB extends xX{}class K0 extends x6{}K0.kind="else";class G6 extends x6{constructor($,v){super(v);this.condition=$}render($){let v=`if(${this.condition})`+super.render($);if(this.else)v+="else "+this.else.render($);return v}optimizeNodes(){super.optimizeNodes();let $=this.condition;if($===!0)return this.nodes;let v=this.else;if(v){let U=v.optimizeNodes();v=this.else=Array.isArray(U)?new K0(U):U}if(v){if($===!1)return v instanceof G6?v:v.nodes;if(this.nodes.length)return this;return new G6(LB($),v instanceof G6?[v]:v.nodes)}if($===!1||!this.nodes.length)return;return this}optimizeNames($,v){var U;if(this.else=(U=this.else)===null||U===void 0?void 0:U.optimizeNames($,v),!(super.optimizeNames($,v)||this.else))return;return this.condition=M1(this.condition,$,v),this}get names(){let $=super.names;if(gX($,this.condition),this.else)Bv($,this.else.names);return $}}G6.kind="if";class q1 extends x6{}q1.kind="for";class BB extends q1{constructor($){super();this.iteration=$}render($){return`for(${this.iteration})`+super.render($)}optimizeNames($,v){if(!super.optimizeNames($,v))return;return this.iteration=M1(this.iteration,$,v),this}get names(){return Bv(super.names,this.iteration.names)}}class wB extends q1{constructor($,v,U,J){super();this.varKind=$,this.name=v,this.from=U,this.to=J}render($){let v=$.es5?P4.varKinds.var:this.varKind,{name:U,from:J,to:z}=this;return`for(${v} ${U}=${J}; ${U}<${z}; ${U}++)`+super.render($)}get names(){let $=gX(super.names,this.from);return gX($,this.to)}}class mY extends q1{constructor($,v,U,J){super();this.loop=$,this.varKind=v,this.name=U,this.iterable=J}render($){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render($)}optimizeNames($,v){if(!super.optimizeNames($,v))return;return this.iterable=M1(this.iterable,$,v),this}get names(){return Bv(super.names,this.iterable.names)}}class TX extends x6{constructor($,v,U){super();this.name=$,this.args=v,this.async=U}render($){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render($)}}TX.kind="func";class CX extends xX{render($){return"return "+super.render($)}}CX.kind="return";class OB extends x6{render($){let v="try"+super.render($);if(this.catch)v+=this.catch.render($);if(this.finally)v+=this.finally.render($);return v}optimizeNodes(){var $,v;return super.optimizeNodes(),($=this.catch)===null||$===void 0||$.optimizeNodes(),(v=this.finally)===null||v===void 0||v.optimizeNodes(),this}optimizeNames($,v){var U,J;return super.optimizeNames($,v),(U=this.catch)===null||U===void 0||U.optimizeNames($,v),(J=this.finally)===null||J===void 0||J.optimizeNames($,v),this}get names(){let $=super.names;if(this.catch)Bv($,this.catch.names);if(this.finally)Bv($,this.finally.names);return $}}class uX extends x6{constructor($){super();this.error=$}render($){return`catch(${this.error})`+super.render($)}}uX.kind="catch";class _X extends x6{render($){return"finally"+super.render($)}}_X.kind="finally";class IB{constructor($,v={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...v,_n:v.lines?`
3
3
  `:""},this._extScope=$,this._scope=new P4.Scope({parent:$}),this._nodes=[new HB]}toString(){return this._root.render(this.opts)}name($){return this._scope.name($)}scopeName($){return this._extScope.name($)}scopeValue($,v){let U=this._extScope.value($,v);return(this._values[U.prefix]||(this._values[U.prefix]=new Set)).add(U),U}getScopeValue($,v){return this._extScope.getValue($,v)}scopeRefs($){return this._extScope.scopeRefs($,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def($,v,U,J){let z=this._scope.toName(v);if(U!==void 0&&J)this._constants[z.str]=U;return this._leafNode(new XB($,z,U)),z}const($,v,U){return this._def(P4.varKinds.const,$,v,U)}let($,v,U){return this._def(P4.varKinds.let,$,v,U)}var($,v,U){return this._def(P4.varKinds.var,$,v,U)}assign($,v,U){return this._leafNode(new cY($,v,U))}add($,v){return this._leafNode(new QB($,J4.operators.ADD,v))}code($){if(typeof $=="function")$();else if($!==J$.nil)this._leafNode(new bB($));return this}object(...$){let v=["{"];for(let[U,J]of $){if(v.length>1)v.push(",");if(v.push(U),U!==J||this.opts.es5)v.push(":"),(0,J$.addCodeArg)(v,J)}return v.push("}"),new J$._Code(v)}if($,v,U){if(this._blockNode(new G6($)),v&&U)this.code(v).else().code(U).endIf();else if(v)this.code(v).endIf();else if(U)throw Error('CodeGen: "else" body without "then" body');return this}elseIf($){return this._elseNode(new G6($))}else(){return this._elseNode(new K0)}endIf(){return this._endBlockNode(G6,K0)}_for($,v){if(this._blockNode($),v)this.code(v).endFor();return this}for($,v){return this._for(new BB($),v)}forRange($,v,U,J,z=this.opts.es5?P4.varKinds.var:P4.varKinds.let){let W=this._scope.toName($);return this._for(new wB(z,W,v,U),()=>J(W))}forOf($,v,U,J=P4.varKinds.const){let z=this._scope.toName($);if(this.opts.es5){let W=v instanceof J$.Name?v:this.var("_arr",v);return this.forRange("_i",0,J$._`${W}.length`,(X)=>{this.var(z,J$._`${W}[${X}]`),U(z)})}return this._for(new mY("of",J,z,v),()=>U(z))}forIn($,v,U,J=this.opts.es5?P4.varKinds.var:P4.varKinds.const){if(this.opts.ownProperties)return this.forOf($,J$._`Object.keys(${v})`,U);let z=this._scope.toName($);return this._for(new mY("in",J,z,v),()=>U(z))}endFor(){return this._endBlockNode(q1)}label($){return this._leafNode(new GB($))}break($){return this._leafNode(new DB($))}return($){let v=new CX;if(this._blockNode(v),this.code($),v.nodes.length!==1)throw Error('CodeGen: "return" should have one node');return this._endBlockNode(CX)}try($,v,U){if(!v&&!U)throw Error('CodeGen: "try" without "catch" and "finally"');let J=new OB;if(this._blockNode(J),this.code($),v){let z=this.name("e");this._currNode=J.catch=new uX(z),v(z)}if(U)this._currNode=J.finally=new _X,this.code(U);return this._endBlockNode(uX,_X)}throw($){return this._leafNode(new YB($))}block($,v){if(this._blockStarts.push(this._nodes.length),$)this.code($).endBlock(v);return this}endBlock($){let v=this._blockStarts.pop();if(v===void 0)throw Error("CodeGen: not in self-balancing block");let U=this._nodes.length-v;if(U<0||$!==void 0&&U!==$)throw Error(`CodeGen: wrong number of nodes: ${U} vs ${$} expected`);return this._nodes.length=v,this}func($,v=J$.nil,U,J){if(this._blockNode(new TX($,v,U)),J)this.code(J).endFunc();return this}endFunc(){return this._endBlockNode(TX)}optimize($=1){while($-- >0)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode($){return this._currNode.nodes.push($),this}_blockNode($){this._currNode.nodes.push($),this._nodes.push($)}_endBlockNode($,v){let U=this._currNode;if(U instanceof $||v&&U instanceof v)return this._nodes.pop(),this;throw Error(`CodeGen: not in block "${v?`${$.kind}/${v.kind}`:$.kind}"`)}_elseNode($){let v=this._currNode;if(!(v instanceof G6))throw Error('CodeGen: "else" without "if"');return this._currNode=v.else=$,this}get _root(){return this._nodes[0]}get _currNode(){let $=this._nodes;return $[$.length-1]}set _currNode($){let v=this._nodes;v[v.length-1]=$}}J4.CodeGen=IB;function Bv($,v){for(let U in v)$[U]=($[U]||0)+(v[U]||0);return $}function gX($,v){return v instanceof J$._CodeOrName?Bv($,v.names):$}function M1($,v,U){if($ instanceof J$.Name)return J($);if(!z($))return $;return new J$._Code($._items.reduce((W,X)=>{if(X instanceof J$.Name)X=J(X);if(X instanceof J$._Code)W.push(...X._items);else W.push(X);return W},[]));function J(W){let X=U[W.str];if(X===void 0||v[W.str]!==1)return W;return delete v[W.str],X}function z(W){return W instanceof J$._Code&&W._items.some((X)=>X instanceof J$.Name&&v[X.str]===1&&U[X.str]!==void 0)}}function HE($,v){for(let U in v)$[U]=($[U]||0)-(v[U]||0)}function LB($){return typeof $=="boolean"||typeof $=="number"||$===null?!$:J$._`!${rY($)}`}J4.not=LB;var BE=NB(J4.operators.AND);function wE(...$){return $.reduce(BE)}J4.and=wE;var OE=NB(J4.operators.OR);function IE(...$){return $.reduce(OE)}J4.or=IE;function NB($){return(v,U)=>v===J$.nil?U:U===J$.nil?v:J$._`${rY(v)} ${$} ${rY(U)}`}function rY($){return $ instanceof J$.Name?$:J$._`(${$})`}});var X$=K((EB)=>{Object.defineProperty(EB,"__esModule",{value:!0});EB.checkStrictMode=EB.getErrorPath=EB.Type=EB.useFunc=EB.setEvaluated=EB.evaluatedPropsToName=EB.mergeEvaluated=EB.eachItem=EB.unescapeJsonPointer=EB.escapeJsonPointer=EB.escapeFragment=EB.unescapeFragment=EB.schemaRefOrVal=EB.schemaHasRulesButRef=EB.schemaHasRules=EB.checkUnknownRules=EB.alwaysValidSchema=EB.toHash=void 0;var V$=v$(),jE=j0();function KE($){let v={};for(let U of $)v[U]=!0;return v}EB.toHash=KE;function FE($,v){if(typeof v=="boolean")return v;if(Object.keys(v).length===0)return!0;return FB($,v),!AB(v,$.self.RULES.all)}EB.alwaysValidSchema=FE;function FB($,v=$.schema){let{opts:U,self:J}=$;if(!U.strictSchema)return;if(typeof v==="boolean")return;let z=J.RULES.keywords;for(let W in v)if(!z[W])SB($,`unknown keyword: "${W}"`)}EB.checkUnknownRules=FB;function AB($,v){if(typeof $=="boolean")return!$;for(let U in $)if(v[U])return!0;return!1}EB.schemaHasRules=AB;function AE($,v){if(typeof $=="boolean")return!$;for(let U in $)if(U!=="$ref"&&v.all[U])return!0;return!1}EB.schemaHasRulesButRef=AE;function qE({topSchemaRef:$,schemaPath:v},U,J,z){if(!z){if(typeof U=="number"||typeof U=="boolean")return U;if(typeof U=="string")return V$._`${U}`}return V$._`${$}${v}${(0,V$.getProperty)(J)}`}EB.schemaRefOrVal=qE;function ME($){return qB(decodeURIComponent($))}EB.unescapeFragment=ME;function SE($){return encodeURIComponent(dY($))}EB.escapeFragment=SE;function dY($){if(typeof $=="number")return`${$}`;return $.replace(/~/g,"~0").replace(/\//g,"~1")}EB.escapeJsonPointer=dY;function qB($){return $.replace(/~1/g,"/").replace(/~0/g,"~")}EB.unescapeJsonPointer=qB;function EE($,v){if(Array.isArray($))for(let U of $)v(U);else v($)}EB.eachItem=EE;function jB({mergeNames:$,mergeToName:v,mergeValues:U,resultToName:J}){return(z,W,X,Q)=>{let G=X===void 0?W:X instanceof V$.Name?(W instanceof V$.Name?$(z,W,X):v(z,W,X),X):W instanceof V$.Name?(v(z,X,W),W):U(W,X);return Q===V$.Name&&!(G instanceof V$.Name)?J(z,G):G}}EB.mergeEvaluated={props:jB({mergeNames:($,v,U)=>$.if(V$._`${U} !== true && ${v} !== undefined`,()=>{$.if(V$._`${v} === true`,()=>$.assign(U,!0),()=>$.assign(U,V$._`${U} || {}`).code(V$._`Object.assign(${U}, ${v})`))}),mergeToName:($,v,U)=>$.if(V$._`${U} !== true`,()=>{if(v===!0)$.assign(U,!0);else $.assign(U,V$._`${U} || {}`),oY($,U,v)}),mergeValues:($,v)=>$===!0?!0:{...$,...v},resultToName:MB}),items:jB({mergeNames:($,v,U)=>$.if(V$._`${U} !== true && ${v} !== undefined`,()=>$.assign(U,V$._`${v} === true ? true : ${U} > ${v} ? ${U} : ${v}`)),mergeToName:($,v,U)=>$.if(V$._`${U} !== true`,()=>$.assign(U,v===!0?!0:V$._`${U} > ${v} ? ${U} : ${v}`)),mergeValues:($,v)=>$===!0?!0:Math.max($,v),resultToName:($,v)=>$.var("items",v)})};function MB($,v){if(v===!0)return $.var("props",!0);let U=$.var("props",V$._`{}`);if(v!==void 0)oY($,U,v);return U}EB.evaluatedPropsToName=MB;function oY($,v,U){Object.keys(U).forEach((J)=>$.assign(V$._`${v}${(0,V$.getProperty)(J)}`,!0))}EB.setEvaluated=oY;var KB={};function PE($,v){return $.scopeValue("func",{ref:v,code:KB[v.code]||(KB[v.code]=new jE._Code(v.code))})}EB.useFunc=PE;var pY;(function($){$[$.Num=0]="Num",$[$.Str=1]="Str"})(pY||(EB.Type=pY={}));function kE($,v,U){if($ instanceof V$.Name){let J=v===pY.Num;return U?J?V$._`"[" + ${$} + "]"`:V$._`"['" + ${$} + "']"`:J?V$._`"/" + ${$}`:V$._`"/" + ${$}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return U?(0,V$.getProperty)($).toString():"/"+dY($)}EB.getErrorPath=kE;function SB($,v,U=$.opts.strictSchema){if(!U)return;if(v=`strict mode: ${v}`,U===!0)throw Error(v);$.self.logger.warn(v)}EB.checkStrictMode=SB});var D6=K((kB)=>{Object.defineProperty(kB,"__esModule",{value:!0});var h$=v$(),pE={data:new h$.Name("data"),valCxt:new h$.Name("valCxt"),instancePath:new h$.Name("instancePath"),parentData:new h$.Name("parentData"),parentDataProperty:new h$.Name("parentDataProperty"),rootData:new h$.Name("rootData"),dynamicAnchors:new h$.Name("dynamicAnchors"),vErrors:new h$.Name("vErrors"),errors:new h$.Name("errors"),this:new h$.Name("this"),self:new h$.Name("self"),scope:new h$.Name("scope"),json:new h$.Name("json"),jsonPos:new h$.Name("jsonPos"),jsonLen:new h$.Name("jsonLen"),jsonPart:new h$.Name("jsonPart")};kB.default=pE});var F0=K((CB)=>{Object.defineProperty(CB,"__esModule",{value:!0});CB.extendErrors=CB.resetErrorsCount=CB.reportExtraError=CB.reportError=CB.keyword$DataError=CB.keywordError=void 0;var Q$=v$(),lX=X$(),o$=D6();CB.keywordError={message:({keyword:$})=>Q$.str`must pass "${$}" keyword validation`};CB.keyword$DataError={message:({keyword:$,schemaType:v})=>v?Q$.str`"${$}" keyword must be ${v} ($data)`:Q$.str`"${$}" keyword is invalid ($data)`};function oE($,v=CB.keywordError,U,J){let{it:z}=$,{gen:W,compositeRule:X,allErrors:Q}=z,G=TB($,v,U);if(J!==null&&J!==void 0?J:X||Q)RB(W,G);else ZB(z,Q$._`[${G}]`)}CB.reportError=oE;function tE($,v=CB.keywordError,U){let{it:J}=$,{gen:z,compositeRule:W,allErrors:X}=J,Q=TB($,v,U);if(RB(z,Q),!(W||X))ZB(J,o$.default.vErrors)}CB.reportExtraError=tE;function aE($,v){$.assign(o$.default.errors,v),$.if(Q$._`${o$.default.vErrors} !== null`,()=>$.if(v,()=>$.assign(Q$._`${o$.default.vErrors}.length`,v),()=>$.assign(o$.default.vErrors,null)))}CB.resetErrorsCount=aE;function sE({gen:$,keyword:v,schemaValue:U,data:J,errsCount:z,it:W}){if(z===void 0)throw Error("ajv implementation error");let X=$.name("err");$.forRange("i",z,o$.default.errors,(Q)=>{if($.const(X,Q$._`${o$.default.vErrors}[${Q}]`),$.if(Q$._`${X}.instancePath === undefined`,()=>$.assign(Q$._`${X}.instancePath`,(0,Q$.strConcat)(o$.default.instancePath,W.errorPath))),$.assign(Q$._`${X}.schemaPath`,Q$.str`${W.errSchemaPath}/${v}`),W.opts.verbose)$.assign(Q$._`${X}.schema`,U),$.assign(Q$._`${X}.data`,J)})}CB.extendErrors=sE;function RB($,v){let U=$.const("err",v);$.if(Q$._`${o$.default.vErrors} === null`,()=>$.assign(o$.default.vErrors,Q$._`[${U}]`),Q$._`${o$.default.vErrors}.push(${U})`),$.code(Q$._`${o$.default.errors}++`)}function ZB($,v){let{gen:U,validateName:J,schemaEnv:z}=$;if(z.$async)U.throw(Q$._`new ${$.ValidationError}(${v})`);else U.assign(Q$._`${J}.errors`,v),U.return(!1)}var wv={keyword:new Q$.Name("keyword"),schemaPath:new Q$.Name("schemaPath"),params:new Q$.Name("params"),propertyName:new Q$.Name("propertyName"),message:new Q$.Name("message"),schema:new Q$.Name("schema"),parentSchema:new Q$.Name("parentSchema")};function TB($,v,U){let{createErrors:J}=$.it;if(J===!1)return Q$._`{}`;return eE($,v,U)}function eE($,v,U={}){let{gen:J,it:z}=$,W=[$P(z,U),vP($,U)];return UP($,v,W),J.object(...W)}function $P({errorPath:$},{instancePath:v}){let U=v?Q$.str`${$}${(0,lX.getErrorPath)(v,lX.Type.Str)}`:$;return[o$.default.instancePath,(0,Q$.strConcat)(o$.default.instancePath,U)]}function vP({keyword:$,it:{errSchemaPath:v}},{schemaPath:U,parentSchema:J}){let z=J?v:Q$.str`${v}/${$}`;if(U)z=Q$.str`${z}${(0,lX.getErrorPath)(U,lX.Type.Str)}`;return[wv.schemaPath,z]}function UP($,{params:v,message:U},J){let{keyword:z,data:W,schemaValue:X,it:Q}=$,{opts:G,propertyName:D,topSchemaRef:Y,schemaPath:b}=Q;if(J.push([wv.keyword,z],[wv.params,typeof v=="function"?v($):v||Q$._`{}`]),G.messages)J.push([wv.message,typeof U=="function"?U($):U]);if(G.verbose)J.push([wv.schema,X],[wv.parentSchema,Q$._`${Y}${b}`],[o$.default.data,W]);if(D)J.push([wv.propertyName,D])}});var xB=K((gB)=>{Object.defineProperty(gB,"__esModule",{value:!0});gB.boolOrEmptySchema=gB.topBoolOrEmptySchema=void 0;var QP=F0(),GP=v$(),DP=D6(),YP={message:"boolean schema is false"};function bP($){let{gen:v,schema:U,validateName:J}=$;if(U===!1)_B($,!1);else if(typeof U=="object"&&U.$async===!0)v.return(DP.default.data);else v.assign(GP._`${J}.errors`,null),v.return(!0)}gB.topBoolOrEmptySchema=bP;function HP($,v){let{gen:U,schema:J}=$;if(J===!1)U.var(v,!1),_B($);else U.var(v,!0)}gB.boolOrEmptySchema=HP;function _B($,v){let{gen:U,data:J}=$,z={gen:U,keyword:"false schema",data:J,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:$};(0,QP.reportError)(z,YP,void 0,v)}});var aY=K((yB)=>{Object.defineProperty(yB,"__esModule",{value:!0});yB.getRules=yB.isJSONType=void 0;var wP=["string","number","integer","boolean","null","object","array"],OP=new Set(wP);function IP($){return typeof $=="string"&&OP.has($)}yB.isJSONType=IP;function LP(){let $={number:{type:"number",rules:[]},string:{type:"string",rules:[]},array:{type:"array",rules:[]},object:{type:"object",rules:[]}};return{types:{...$,integer:!0,boolean:!0,null:!0},rules:[{rules:[]},$.number,$.string,$.array,$.object],post:{rules:[]},all:{},keywords:{}}}yB.getRules=LP});var sY=K((nB)=>{Object.defineProperty(nB,"__esModule",{value:!0});nB.shouldUseRule=nB.shouldUseGroup=nB.schemaHasRulesForType=void 0;function VP({schema:$,self:v},U){let J=v.RULES.types[U];return J&&J!==!0&&iB($,J)}nB.schemaHasRulesForType=VP;function iB($,v){return v.rules.some((U)=>hB($,U))}nB.shouldUseGroup=iB;function hB($,v){var U;return $[v.keyword]!==void 0||((U=v.definition.implements)===null||U===void 0?void 0:U.some((J)=>$[J]!==void 0))}nB.shouldUseRule=hB});var A0=K((dB)=>{Object.defineProperty(dB,"__esModule",{value:!0});dB.reportTypeError=dB.checkDataTypes=dB.checkDataType=dB.coerceAndCheckDataType=dB.getJSONTypes=dB.getSchemaTypes=dB.DataType=void 0;var FP=aY(),AP=sY(),qP=F0(),t=v$(),rB=X$(),S1;(function($){$[$.Correct=0]="Correct",$[$.Wrong=1]="Wrong"})(S1||(dB.DataType=S1={}));function MP($){let v=cB($.type);if(v.includes("null")){if($.nullable===!1)throw Error("type: null contradicts nullable: false")}else{if(!v.length&&$.nullable!==void 0)throw Error('"nullable" cannot be used without "type"');if($.nullable===!0)v.push("null")}return v}dB.getSchemaTypes=MP;function cB($){let v=Array.isArray($)?$:$?[$]:[];if(v.every(FP.isJSONType))return v;throw Error("type must be JSONType or JSONType[]: "+v.join(","))}dB.getJSONTypes=cB;function SP($,v){let{gen:U,data:J,opts:z}=$,W=EP(v,z.coerceTypes),X=v.length>0&&!(W.length===0&&v.length===1&&(0,AP.schemaHasRulesForType)($,v[0]));if(X){let Q=$b(v,J,z.strictNumbers,S1.Wrong);U.if(Q,()=>{if(W.length)PP($,v,W);else vb($)})}return X}dB.coerceAndCheckDataType=SP;var pB=new Set(["string","number","integer","boolean","null"]);function EP($,v){return v?$.filter((U)=>pB.has(U)||v==="array"&&U==="array"):[]}function PP($,v,U){let{gen:J,data:z,opts:W}=$,X=J.let("dataType",t._`typeof ${z}`),Q=J.let("coerced",t._`undefined`);if(W.coerceTypes==="array")J.if(t._`${X} == 'object' && Array.isArray(${z}) && ${z}.length == 1`,()=>J.assign(z,t._`${z}[0]`).assign(X,t._`typeof ${z}`).if($b(v,z,W.strictNumbers),()=>J.assign(Q,z)));J.if(t._`${Q} !== undefined`);for(let D of U)if(pB.has(D)||D==="array"&&W.coerceTypes==="array")G(D);J.else(),vb($),J.endIf(),J.if(t._`${Q} !== undefined`,()=>{J.assign(z,Q),kP($,Q)});function G(D){switch(D){case"string":J.elseIf(t._`${X} == "number" || ${X} == "boolean"`).assign(Q,t._`"" + ${z}`).elseIf(t._`${z} === null`).assign(Q,t._`""`);return;case"number":J.elseIf(t._`${X} == "boolean" || ${z} === null
4
4
  || (${X} == "string" && ${z} && ${z} == +${z})`).assign(Q,t._`+${z}`);return;case"integer":J.elseIf(t._`${X} === "boolean" || ${z} === null
@@ -1,12 +1,12 @@
1
- /*! @mcpcloud/runtime v0.12.3 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
- var _9=Object.create;var{getPrototypeOf:w9,defineProperty:$8,getOwnPropertyNames:P9}=Object;var N9=Object.prototype.hasOwnProperty;function E9(Z){return this[Z]}var S9,I9,x9=(Z,$,X)=>{var Y=Z!=null&&typeof Z==="object";if(Y){var B=$?S9??=new WeakMap:I9??=new WeakMap,C=B.get(Z);if(C)return C}X=Z!=null?_9(w9(Z)):{};let U=$||!Z||!Z.__esModule?$8(X,"default",{value:Z,enumerable:!0}):X;for(let z of P9(Z))if(!N9.call(U,z))$8(U,z,{get:E9.bind(Z,z),enumerable:!0});if(Y)B.set(Z,U);return U};var A9=(Z,$)=>()=>($||Z(($={exports:{}}).exports,$),$.exports);var b9=(Z)=>Z;function T9(Z,$){this[Z]=b9.bind(null,$)}var f9=(Z,$)=>{for(var X in $)$8(Z,X,{get:$[X],enumerable:!0,configurable:!0,set:T9.bind($,X)})};var X8=(Z,$)=>()=>(Z&&($=Z(Z=0)),$);var k,W8,l,h,c;var i=X8(()=>{k={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_TYPE_DIRECT:2,JS_EVAL_TYPE_INDIRECT:3,JS_EVAL_TYPE_MASK:3,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},W8={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},l={Pending:0,Fulfilled:1,Rejected:2},h={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,JS_GPN_SET_ENUM:32,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},c={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2}});function m(...Z){B8&&console.log("quickjs-emscripten:",...Z)}function*K9(Z){return yield Z}function m9(Z){return K9(q8(Z))}function u8(Z,$){return(...X)=>{let Y=$.call(Z,J8,...X);return q8(Y)}}function d9(Z,$){let X=$.call(Z,J8);return q8(X)}function q8(Z){function $(X){return X.done?X.value:X.value instanceof Promise?X.value.then((Y)=>$(Z.next(Y)),(Y)=>$(Z.throw(Y))):$(Z.next(X.value))}return $(Z.next())}function K8(Z,$){let X;try{Z.dispose()}catch(Y){X=Y}if($&&X)throw Object.assign($,{message:`${$.message}
3
- Then, failed to dispose scope: ${X.message}`,disposeError:X}),$;if($||X)throw $||X}function p9(Z){let $=Z?Array.from(Z):[];function X(){return $.forEach((B)=>B.alive?B.dispose():void 0)}function Y(){return $.some((B)=>B.alive)}return Object.defineProperty($,G8,{configurable:!0,enumerable:!1,value:X}),Object.defineProperty($,"dispose",{configurable:!0,enumerable:!1,value:X}),Object.defineProperty($,"alive",{configurable:!0,enumerable:!1,get:Y}),$}function n(Z){return!!(Z&&(typeof Z=="object"||typeof Z=="function")&&("alive"in Z)&&typeof Z.alive=="boolean"&&("dispose"in Z)&&typeof Z.dispose=="function")}function o9(Z){if(!Z)return 0;let $=0;for(let[X,Y]of Object.entries(Z)){if(!(X in W8))throw new Z9(X);Y&&($|=W8[X])}return $}function n9(Z){if(typeof Z=="number")return Z;if(Z===void 0)return 0;let{type:$,strict:X,strip:Y,compileOnly:B,backtraceBarrier:C}=Z,U=0;return $==="global"&&(U|=k.JS_EVAL_TYPE_GLOBAL),$==="module"&&(U|=k.JS_EVAL_TYPE_MODULE),X&&(U|=k.JS_EVAL_FLAG_STRICT),Y&&(U|=k.JS_EVAL_FLAG_STRIP),B&&(U|=k.JS_EVAL_FLAG_COMPILE_ONLY),C&&(U|=k.JS_EVAL_FLAG_BACKTRACE_BARRIER),U}function a9(Z){if(typeof Z=="number")return Z;if(Z===void 0)return 0;let{strings:$,symbols:X,quickjsPrivate:Y,onlyEnumerable:B,numbers:C,numbersAsStrings:U}=Z,z=0;return $&&(z|=h.JS_GPN_STRING_MASK),X&&(z|=h.JS_GPN_SYMBOL_MASK),Y&&(z|=h.JS_GPN_PRIVATE_MASK),B&&(z|=h.JS_GPN_ENUM_ONLY),C&&(z|=h.QTS_GPN_NUMBER_MASK),U&&(z|=h.QTS_STANDARD_COMPLIANT_NUMBER),z}function s9(...Z){let $=[];for(let X of Z)X!==void 0&&($=$.concat(X));return $}function z8(Z){return Z>>8}function H8(Z,$){$.interruptHandler&&Z.setInterruptHandler($.interruptHandler),$.maxStackSizeBytes!==void 0&&Z.setMaxStackSize($.maxStackSizeBytes),$.memoryLimitBytes!==void 0&&Z.setMemoryLimit($.memoryLimitBytes)}function j8(Z,$){$.moduleLoader&&Z.setModuleLoader($.moduleLoader),$.shouldInterrupt&&Z.setInterruptHandler($.shouldInterrupt),$.memoryLimitBytes!==void 0&&Z.setMemoryLimit($.memoryLimitBytes),$.maxStackSizeBytes!==void 0&&Z.setMaxStackSize($.maxStackSizeBytes)}var k9,h9=(Z,$)=>{for(var X in $)k9(Z,X,{get:$[X],enumerable:!0})},B8=!1,v9,Y8,s8,Q8,t8,r8,e8,g9,c9,Z9,$9,X9,W9,f,J8,A,G8,l8,w,v,i8,I,C8,u9,l9,g,i9,z9=class{constructor(Z){this.module=Z}toPointerArray(Z){let $=new Int32Array(Z.map((B)=>B.value)),X=$.length*$.BYTES_PER_ELEMENT,Y=this.module._malloc(X);return new Uint8Array(this.module.HEAPU8.buffer,Y,X).set(new Uint8Array($.buffer)),new w(Y,void 0,(B)=>this.module._free(B))}newTypedArray(Z,$){let X=new Z(Array($).fill(0)),Y=X.length*X.BYTES_PER_ELEMENT,B=this.module._malloc(Y),C=new Z(this.module.HEAPU8.buffer,B,$);return C.set(X),new w({typedArray:C,ptr:B},void 0,(U)=>this.module._free(U.ptr))}newMutablePointerArray(Z){return this.newTypedArray(Int32Array,Z)}newHeapCharPointer(Z){let $=this.module.lengthBytesUTF8(Z),X=$+1,Y=this.module._malloc(X);return this.module.stringToUTF8(Z,Y,X),new w({ptr:Y,strlen:$},void 0,(B)=>this.module._free(B.ptr))}newHeapBufferPointer(Z){let $=Z.byteLength,X=this.module._malloc($);return this.module.HEAPU8.set(Z,X),new w({pointer:X,numBytes:$},void 0,(Y)=>this.module._free(Y.pointer))}consumeHeapCharPointer(Z){let $=this.module.UTF8ToString(Z);return this.module._free(Z),$}},fZ,yZ,t9,o8=-2147483648,n8=2147483647,o=0,r9=class{constructor(){this.nextId=o8,this.freelist=[],this.groups=new Map}put(Z){let $=this.allocateId(),X=z8($),Y=this.groups.get(X);return Y||(Y=new Map,this.groups.set(X,Y)),Y.set($,Z),$}get(Z){if(Z===o)throw new f("no host reference id defined");let $=z8(Z),X=this.groups.get($);if(!X)throw new f(`host reference id ${Z} is not defined`);let Y=X.get(Z);if(!Y)throw new f(`host reference id ${Z} is not defined`);return Y}delete(Z){if(Z===o)throw new f("no host reference id defined");let $=z8(Z),X=this.groups.get($);if(!X)throw new f(`host reference id ${Z} is not defined`);X.delete(Z),X.size===0&&this.groups.delete($),this.freelist.push(Z)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===o&&this.nextId++,this.nextId>n8)throw new W9(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${n8-o8}`);return this.nextId++}},a8,e9,ZZ,$Z,XZ=class{constructor(Z){this.freeHostRef=Z.freeHostRef,this.callFunction=Z.callFunction,this.shouldInterrupt=Z.shouldInterrupt,this.loadModuleSource=Z.loadModuleSource,this.normalizeModule=Z.normalizeModule}},U8=class{constructor(Z){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new XZ({freeHostRef:($,X,Y)=>{let B=this.runtimeCallbacks.get(X);if(!B)throw Error(`QuickJSRuntime(rt = ${X}) not found when trying to free HostRef(id = ${Y})`);B.freeHostRef(X,Y)},callFunction:($,X,Y,B,C,U)=>this.handleAsyncify($,()=>{try{let z=this.contextCallbacks.get(X);if(!z)throw Error(`QuickJSContext(ctx = ${X}) not found for C function call "${U}"`);return z.callFunction(X,Y,B,C,U)}catch(z){return console.error("[C to host error: returning null]",z),0}}),shouldInterrupt:($,X)=>this.handleAsyncify($,()=>{try{let Y=this.runtimeCallbacks.get(X);if(!Y)throw Error(`QuickJSRuntime(rt = ${X}) not found for C interrupt`);return Y.shouldInterrupt(X)}catch(Y){return console.error("[C to host interrupt: returning error]",Y),1}}),loadModuleSource:($,X,Y,B)=>this.handleAsyncify($,()=>{try{let C=this.runtimeCallbacks.get(X);if(!C)throw Error(`QuickJSRuntime(rt = ${X}) not found for C module loader`);let U=C.loadModuleSource;if(!U)throw Error(`QuickJSRuntime(rt = ${X}) does not support module loading`);return U(X,Y,B)}catch(C){return console.error("[C to host module loader error: returning null]",C),0}}),normalizeModule:($,X,Y,B,C)=>this.handleAsyncify($,()=>{try{let U=this.runtimeCallbacks.get(X);if(!U)throw Error(`QuickJSRuntime(rt = ${X}) not found for C module loader`);let z=U.normalizeModule;if(!z)throw Error(`QuickJSRuntime(rt = ${X}) does not support module loading`);return z(X,Y,B,C)}catch(U){return console.error("[C to host module loader error: returning null]",U),0}})}),this.module=Z,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(Z,$){this.runtimeCallbacks.set(Z,$)}deleteRuntime(Z){this.runtimeCallbacks.delete(Z)}setContextCallbacks(Z,$){this.contextCallbacks.set(Z,$)}deleteContext(Z){this.contextCallbacks.delete(Z)}handleAsyncify(Z,$){if(Z)return Z.handleSleep((Y)=>{try{let B=$();if(!(B instanceof Promise)){m("asyncify.handleSleep: not suspending:",B),Y(B);return}if(this.suspended)throw new r8(`Already suspended at: ${this.suspended.stack}
4
- Attempted to suspend at:`);this.suspended=new e8(`(${this.suspendedCount++})`),m("asyncify.handleSleep: suspending:",this.suspended),B.then((C)=>{this.suspended=void 0,m("asyncify.handleSleep: resolved:",C),Y(C)},(C)=>{m("asyncify.handleSleep: rejected:",C),console.error("QuickJS: cannot handle error in suspended function",C),this.suspended=void 0})}catch(B){throw m("asyncify.handleSleep: error:",B),this.suspended=void 0,B}});let X=$();if(X instanceof Promise)throw Error("Promise return value not supported in non-asyncify context.");return X}},Y9=class{constructor(Z,$){this.module=Z,this.ffi=$,this.callbacks=new U8(Z)}newRuntime(Z={}){let $=new w(this.ffi.QTS_NewRuntime(),void 0,(Y)=>{this.ffi.QTS_FreeRuntime(Y),this.callbacks.deleteRuntime(Y)}),X=new $Z({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:$});return H8(X,Z),Z.moduleLoader&&X.setModuleLoader(Z.moduleLoader),X}newContext(Z={}){let $=this.newRuntime(),X=$.newContext({...Z,ownedLifetimes:s9($,Z.ownedLifetimes)});return $.context=X,X}evalCode(Z,$={}){return I.withScope((X)=>{let Y=X.manage(this.newContext());j8(Y.runtime,$);let B=Y.evalCode(Z,"eval.js");if($.memoryLimitBytes!==void 0&&Y.runtime.setMemoryLimit(-1),B.error)throw Y.dump(X.manage(B.error));return Y.dump(X.manage(B.value))})}getWasmMemory(){let Z=this.module.quickjsEmscriptenInit?.(()=>{})?.getWasmMemory?.();if(!Z)throw Error("Variant does not support getting WebAssembly.Memory");return Z}getFFI(){return this.ffi}};var Q9=X8(()=>{i();i();k9=Object.defineProperty;v9={};h9(v9,{QuickJSAsyncifyError:()=>r8,QuickJSAsyncifySuspended:()=>e8,QuickJSEmptyGetOwnPropertyNames:()=>X9,QuickJSEmscriptenModuleError:()=>c9,QuickJSHostRefInvalid:()=>f,QuickJSHostRefRangeExceeded:()=>W9,QuickJSMemoryLeakDetected:()=>g9,QuickJSNotImplemented:()=>t8,QuickJSPromisePending:()=>$9,QuickJSUnknownIntrinsic:()=>Z9,QuickJSUnwrapError:()=>Y8,QuickJSUseAfterFree:()=>Q8,QuickJSWrongOwner:()=>s8});Y8=class extends Error{constructor(Z,$){let X=typeof Z=="object"&&Z&&"message"in Z?String(Z.message):String(Z);super(X);this.cause=Z,this.context=$,this.name="QuickJSUnwrapError"}},s8=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},Q8=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},t8=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},r8=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},e8=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},g9=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},c9=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},Z9=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}},$9=class extends Error{constructor(){super(...arguments);this.name="QuickJSPromisePending"}},X9=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmptyGetOwnPropertyNames"}},W9=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefRangeExceeded"}},f=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefInvalid"}};J8=K9;J8.of=m9;A=class{[Symbol.dispose](){return this.dispose()}},G8=Symbol.dispose??Symbol.for("Symbol.dispose"),l8=A.prototype;l8[G8]||(l8[G8]=function(){return this.dispose()});w=class Z extends A{constructor($,X,Y,B){super();this._value=$,this.copier=X,this.disposer=Y,this._owner=B,this._alive=!0,this._constructorStack=B8?Error("Lifetime constructed").stack:void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw Error("Non-dupable lifetime");return new Z(this.copier(this._value),this.copier,this.disposer,this._owner)}consume($){this.assertAlive();let X=$(this);return this.dispose(),X}map($){return this.assertAlive(),$(this)}tap($){return $(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new Q8(`Lifetime not alive
1
+ /*! @mcpcloud/runtime v0.12.4 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
+ var _9=Object.create;var{getPrototypeOf:w9,defineProperty:$8,getOwnPropertyNames:P9}=Object;var N9=Object.prototype.hasOwnProperty;function E9(Z){return this[Z]}var S9,I9,x9=(Z,$,X)=>{var Q=Z!=null&&typeof Z==="object";if(Q){var B=$?S9??=new WeakMap:I9??=new WeakMap,C=B.get(Z);if(C)return C}X=Z!=null?_9(w9(Z)):{};let U=$||!Z||!Z.__esModule?$8(X,"default",{value:Z,enumerable:!0}):X;for(let z of P9(Z))if(!N9.call(U,z))$8(U,z,{get:E9.bind(Z,z),enumerable:!0});if(Q)B.set(Z,U);return U};var A9=(Z,$)=>()=>($||Z(($={exports:{}}).exports,$),$.exports);var b9=(Z)=>Z;function T9(Z,$){this[Z]=b9.bind(null,$)}var f9=(Z,$)=>{for(var X in $)$8(Z,X,{get:$[X],enumerable:!0,configurable:!0,set:T9.bind($,X)})};var X8=(Z,$)=>()=>(Z&&($=Z(Z=0)),$);var k,W8,l,h,c;var i=X8(()=>{k={JS_EVAL_TYPE_GLOBAL:0,JS_EVAL_TYPE_MODULE:1,JS_EVAL_TYPE_DIRECT:2,JS_EVAL_TYPE_INDIRECT:3,JS_EVAL_TYPE_MASK:3,JS_EVAL_FLAG_STRICT:8,JS_EVAL_FLAG_STRIP:16,JS_EVAL_FLAG_COMPILE_ONLY:32,JS_EVAL_FLAG_BACKTRACE_BARRIER:64},W8={BaseObjects:1,Date:2,Eval:4,StringNormalize:8,RegExp:16,RegExpCompiler:32,JSON:64,Proxy:128,MapSet:256,TypedArrays:512,Promise:1024,BigInt:2048,BigFloat:4096,BigDecimal:8192,OperatorOverloading:16384,BignumExt:32768},l={Pending:0,Fulfilled:1,Rejected:2},h={JS_GPN_STRING_MASK:1,JS_GPN_SYMBOL_MASK:2,JS_GPN_PRIVATE_MASK:4,JS_GPN_ENUM_ONLY:16,JS_GPN_SET_ENUM:32,QTS_GPN_NUMBER_MASK:64,QTS_STANDARD_COMPLIANT_NUMBER:128},c={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2}});function m(...Z){B8&&console.log("quickjs-emscripten:",...Z)}function*K9(Z){return yield Z}function m9(Z){return K9(q8(Z))}function u8(Z,$){return(...X)=>{let Q=$.call(Z,J8,...X);return q8(Q)}}function d9(Z,$){let X=$.call(Z,J8);return q8(X)}function q8(Z){function $(X){return X.done?X.value:X.value instanceof Promise?X.value.then((Q)=>$(Z.next(Q)),(Q)=>$(Z.throw(Q))):$(Z.next(X.value))}return $(Z.next())}function K8(Z,$){let X;try{Z.dispose()}catch(Q){X=Q}if($&&X)throw Object.assign($,{message:`${$.message}
3
+ Then, failed to dispose scope: ${X.message}`,disposeError:X}),$;if($||X)throw $||X}function p9(Z){let $=Z?Array.from(Z):[];function X(){return $.forEach((B)=>B.alive?B.dispose():void 0)}function Q(){return $.some((B)=>B.alive)}return Object.defineProperty($,G8,{configurable:!0,enumerable:!1,value:X}),Object.defineProperty($,"dispose",{configurable:!0,enumerable:!1,value:X}),Object.defineProperty($,"alive",{configurable:!0,enumerable:!1,get:Q}),$}function n(Z){return!!(Z&&(typeof Z=="object"||typeof Z=="function")&&("alive"in Z)&&typeof Z.alive=="boolean"&&("dispose"in Z)&&typeof Z.dispose=="function")}function o9(Z){if(!Z)return 0;let $=0;for(let[X,Q]of Object.entries(Z)){if(!(X in W8))throw new Z9(X);Q&&($|=W8[X])}return $}function n9(Z){if(typeof Z=="number")return Z;if(Z===void 0)return 0;let{type:$,strict:X,strip:Q,compileOnly:B,backtraceBarrier:C}=Z,U=0;return $==="global"&&(U|=k.JS_EVAL_TYPE_GLOBAL),$==="module"&&(U|=k.JS_EVAL_TYPE_MODULE),X&&(U|=k.JS_EVAL_FLAG_STRICT),Q&&(U|=k.JS_EVAL_FLAG_STRIP),B&&(U|=k.JS_EVAL_FLAG_COMPILE_ONLY),C&&(U|=k.JS_EVAL_FLAG_BACKTRACE_BARRIER),U}function a9(Z){if(typeof Z=="number")return Z;if(Z===void 0)return 0;let{strings:$,symbols:X,quickjsPrivate:Q,onlyEnumerable:B,numbers:C,numbersAsStrings:U}=Z,z=0;return $&&(z|=h.JS_GPN_STRING_MASK),X&&(z|=h.JS_GPN_SYMBOL_MASK),Q&&(z|=h.JS_GPN_PRIVATE_MASK),B&&(z|=h.JS_GPN_ENUM_ONLY),C&&(z|=h.QTS_GPN_NUMBER_MASK),U&&(z|=h.QTS_STANDARD_COMPLIANT_NUMBER),z}function s9(...Z){let $=[];for(let X of Z)X!==void 0&&($=$.concat(X));return $}function z8(Z){return Z>>8}function H8(Z,$){$.interruptHandler&&Z.setInterruptHandler($.interruptHandler),$.maxStackSizeBytes!==void 0&&Z.setMaxStackSize($.maxStackSizeBytes),$.memoryLimitBytes!==void 0&&Z.setMemoryLimit($.memoryLimitBytes)}function j8(Z,$){$.moduleLoader&&Z.setModuleLoader($.moduleLoader),$.shouldInterrupt&&Z.setInterruptHandler($.shouldInterrupt),$.memoryLimitBytes!==void 0&&Z.setMemoryLimit($.memoryLimitBytes),$.maxStackSizeBytes!==void 0&&Z.setMaxStackSize($.maxStackSizeBytes)}var k9,h9=(Z,$)=>{for(var X in $)k9(Z,X,{get:$[X],enumerable:!0})},B8=!1,v9,Q8,s8,Y8,t8,r8,e8,g9,c9,Z9,$9,X9,W9,f,J8,A,G8,l8,w,v,i8,I,C8,u9,l9,g,i9,z9=class{constructor(Z){this.module=Z}toPointerArray(Z){let $=new Int32Array(Z.map((B)=>B.value)),X=$.length*$.BYTES_PER_ELEMENT,Q=this.module._malloc(X);return new Uint8Array(this.module.HEAPU8.buffer,Q,X).set(new Uint8Array($.buffer)),new w(Q,void 0,(B)=>this.module._free(B))}newTypedArray(Z,$){let X=new Z(Array($).fill(0)),Q=X.length*X.BYTES_PER_ELEMENT,B=this.module._malloc(Q),C=new Z(this.module.HEAPU8.buffer,B,$);return C.set(X),new w({typedArray:C,ptr:B},void 0,(U)=>this.module._free(U.ptr))}newMutablePointerArray(Z){return this.newTypedArray(Int32Array,Z)}newHeapCharPointer(Z){let $=this.module.lengthBytesUTF8(Z),X=$+1,Q=this.module._malloc(X);return this.module.stringToUTF8(Z,Q,X),new w({ptr:Q,strlen:$},void 0,(B)=>this.module._free(B.ptr))}newHeapBufferPointer(Z){let $=Z.byteLength,X=this.module._malloc($);return this.module.HEAPU8.set(Z,X),new w({pointer:X,numBytes:$},void 0,(Q)=>this.module._free(Q.pointer))}consumeHeapCharPointer(Z){let $=this.module.UTF8ToString(Z);return this.module._free(Z),$}},fZ,yZ,t9,o8=-2147483648,n8=2147483647,o=0,r9=class{constructor(){this.nextId=o8,this.freelist=[],this.groups=new Map}put(Z){let $=this.allocateId(),X=z8($),Q=this.groups.get(X);return Q||(Q=new Map,this.groups.set(X,Q)),Q.set($,Z),$}get(Z){if(Z===o)throw new f("no host reference id defined");let $=z8(Z),X=this.groups.get($);if(!X)throw new f(`host reference id ${Z} is not defined`);let Q=X.get(Z);if(!Q)throw new f(`host reference id ${Z} is not defined`);return Q}delete(Z){if(Z===o)throw new f("no host reference id defined");let $=z8(Z),X=this.groups.get($);if(!X)throw new f(`host reference id ${Z} is not defined`);X.delete(Z),X.size===0&&this.groups.delete($),this.freelist.push(Z)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===o&&this.nextId++,this.nextId>n8)throw new W9(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${n8-o8}`);return this.nextId++}},a8,e9,ZZ,$Z,XZ=class{constructor(Z){this.freeHostRef=Z.freeHostRef,this.callFunction=Z.callFunction,this.shouldInterrupt=Z.shouldInterrupt,this.loadModuleSource=Z.loadModuleSource,this.normalizeModule=Z.normalizeModule}},U8=class{constructor(Z){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new XZ({freeHostRef:($,X,Q)=>{let B=this.runtimeCallbacks.get(X);if(!B)throw Error(`QuickJSRuntime(rt = ${X}) not found when trying to free HostRef(id = ${Q})`);B.freeHostRef(X,Q)},callFunction:($,X,Q,B,C,U)=>this.handleAsyncify($,()=>{try{let z=this.contextCallbacks.get(X);if(!z)throw Error(`QuickJSContext(ctx = ${X}) not found for C function call "${U}"`);return z.callFunction(X,Q,B,C,U)}catch(z){return console.error("[C to host error: returning null]",z),0}}),shouldInterrupt:($,X)=>this.handleAsyncify($,()=>{try{let Q=this.runtimeCallbacks.get(X);if(!Q)throw Error(`QuickJSRuntime(rt = ${X}) not found for C interrupt`);return Q.shouldInterrupt(X)}catch(Q){return console.error("[C to host interrupt: returning error]",Q),1}}),loadModuleSource:($,X,Q,B)=>this.handleAsyncify($,()=>{try{let C=this.runtimeCallbacks.get(X);if(!C)throw Error(`QuickJSRuntime(rt = ${X}) not found for C module loader`);let U=C.loadModuleSource;if(!U)throw Error(`QuickJSRuntime(rt = ${X}) does not support module loading`);return U(X,Q,B)}catch(C){return console.error("[C to host module loader error: returning null]",C),0}}),normalizeModule:($,X,Q,B,C)=>this.handleAsyncify($,()=>{try{let U=this.runtimeCallbacks.get(X);if(!U)throw Error(`QuickJSRuntime(rt = ${X}) not found for C module loader`);let z=U.normalizeModule;if(!z)throw Error(`QuickJSRuntime(rt = ${X}) does not support module loading`);return z(X,Q,B,C)}catch(U){return console.error("[C to host module loader error: returning null]",U),0}})}),this.module=Z,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(Z,$){this.runtimeCallbacks.set(Z,$)}deleteRuntime(Z){this.runtimeCallbacks.delete(Z)}setContextCallbacks(Z,$){this.contextCallbacks.set(Z,$)}deleteContext(Z){this.contextCallbacks.delete(Z)}handleAsyncify(Z,$){if(Z)return Z.handleSleep((Q)=>{try{let B=$();if(!(B instanceof Promise)){m("asyncify.handleSleep: not suspending:",B),Q(B);return}if(this.suspended)throw new r8(`Already suspended at: ${this.suspended.stack}
4
+ Attempted to suspend at:`);this.suspended=new e8(`(${this.suspendedCount++})`),m("asyncify.handleSleep: suspending:",this.suspended),B.then((C)=>{this.suspended=void 0,m("asyncify.handleSleep: resolved:",C),Q(C)},(C)=>{m("asyncify.handleSleep: rejected:",C),console.error("QuickJS: cannot handle error in suspended function",C),this.suspended=void 0})}catch(B){throw m("asyncify.handleSleep: error:",B),this.suspended=void 0,B}});let X=$();if(X instanceof Promise)throw Error("Promise return value not supported in non-asyncify context.");return X}},Q9=class{constructor(Z,$){this.module=Z,this.ffi=$,this.callbacks=new U8(Z)}newRuntime(Z={}){let $=new w(this.ffi.QTS_NewRuntime(),void 0,(Q)=>{this.ffi.QTS_FreeRuntime(Q),this.callbacks.deleteRuntime(Q)}),X=new $Z({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:$});return H8(X,Z),Z.moduleLoader&&X.setModuleLoader(Z.moduleLoader),X}newContext(Z={}){let $=this.newRuntime(),X=$.newContext({...Z,ownedLifetimes:s9($,Z.ownedLifetimes)});return $.context=X,X}evalCode(Z,$={}){return I.withScope((X)=>{let Q=X.manage(this.newContext());j8(Q.runtime,$);let B=Q.evalCode(Z,"eval.js");if($.memoryLimitBytes!==void 0&&Q.runtime.setMemoryLimit(-1),B.error)throw Q.dump(X.manage(B.error));return Q.dump(X.manage(B.value))})}getWasmMemory(){let Z=this.module.quickjsEmscriptenInit?.(()=>{})?.getWasmMemory?.();if(!Z)throw Error("Variant does not support getting WebAssembly.Memory");return Z}getFFI(){return this.ffi}};var Y9=X8(()=>{i();i();k9=Object.defineProperty;v9={};h9(v9,{QuickJSAsyncifyError:()=>r8,QuickJSAsyncifySuspended:()=>e8,QuickJSEmptyGetOwnPropertyNames:()=>X9,QuickJSEmscriptenModuleError:()=>c9,QuickJSHostRefInvalid:()=>f,QuickJSHostRefRangeExceeded:()=>W9,QuickJSMemoryLeakDetected:()=>g9,QuickJSNotImplemented:()=>t8,QuickJSPromisePending:()=>$9,QuickJSUnknownIntrinsic:()=>Z9,QuickJSUnwrapError:()=>Q8,QuickJSUseAfterFree:()=>Y8,QuickJSWrongOwner:()=>s8});Q8=class extends Error{constructor(Z,$){let X=typeof Z=="object"&&Z&&"message"in Z?String(Z.message):String(Z);super(X);this.cause=Z,this.context=$,this.name="QuickJSUnwrapError"}},s8=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},Y8=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},t8=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},r8=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},e8=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},g9=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},c9=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},Z9=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}},$9=class extends Error{constructor(){super(...arguments);this.name="QuickJSPromisePending"}},X9=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmptyGetOwnPropertyNames"}},W9=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefRangeExceeded"}},f=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefInvalid"}};J8=K9;J8.of=m9;A=class{[Symbol.dispose](){return this.dispose()}},G8=Symbol.dispose??Symbol.for("Symbol.dispose"),l8=A.prototype;l8[G8]||(l8[G8]=function(){return this.dispose()});w=class Z extends A{constructor($,X,Q,B){super();this._value=$,this.copier=X,this.disposer=Q,this._owner=B,this._alive=!0,this._constructorStack=B8?Error("Lifetime constructed").stack:void 0}get alive(){return this._alive}get value(){return this.assertAlive(),this._value}get owner(){return this._owner}get dupable(){return!!this.copier}dup(){if(this.assertAlive(),!this.copier)throw Error("Non-dupable lifetime");return new Z(this.copier(this._value),this.copier,this.disposer,this._owner)}consume($){this.assertAlive();let X=$(this);return this.dispose(),X}map($){return this.assertAlive(),$(this)}tap($){return $(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new Y8(`Lifetime not alive
5
5
  ${this._constructorStack}
6
- Lifetime used`):new Q8("Lifetime not alive")}},v=class extends w{constructor(Z,$){super(Z,void 0,void 0,$)}get dupable(){return!0}dup(){return this}dispose(){}},i8=class extends w{constructor(Z,$,X,Y){super(Z,$,X,Y)}dispose(){this._alive=!1}};I=class Z extends A{constructor(){super(...arguments);this._disposables=new w(new Set),this.manage=($)=>(this._disposables.value.add($),$)}static withScope($){let X=new Z,Y;try{return $(X)}catch(B){throw Y=B,B}finally{K8(X,Y)}}static withScopeMaybeAsync($,X){return d9(void 0,function*(Y){let B=new Z,C;try{return yield*Y.of(X.call($,Y,B))}catch(U){throw C=U,U}finally{K8(B,C)}})}static async withScopeAsync($){let X=new Z,Y;try{return await $(X)}catch(B){throw Y=B,B}finally{K8(X,Y)}}get alive(){return this._disposables.alive}dispose(){let $=Array.from(this._disposables.value.values()).reverse();for(let X of $)X.alive&&X.dispose();this._disposables.dispose()}};C8=class Z extends A{static success($){return new u9($)}static fail($,X){return new l9($,X)}static is($){return $ instanceof Z}},u9=class extends C8{constructor(Z){super();this.value=Z}get alive(){return n(this.value)?this.value.alive:!0}dispose(){n(this.value)&&this.value.dispose()}unwrap(){return this.value}unwrapOr(Z){return this.value}},l9=class extends C8{constructor(Z,$){super();this.error=Z,this.onUnwrap=$}get alive(){return n(this.error)?this.error.alive:!0}dispose(){n(this.error)&&this.error.dispose()}unwrap(){throw this.onUnwrap(this),this.error}unwrapOr(Z){return Z}},g=C8,i9=class extends A{constructor(Z){super();this.resolve=($)=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,$||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.reject=($)=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,$||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()},this.context=Z.context,this.owner=Z.context.runtime,this.handle=Z.promiseHandle,this.settled=new Promise(($)=>{this.onSettled=$}),this.resolveHandle=Z.resolveHandle,this.rejectHandle=Z.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}},fZ=Symbol("Unstable"),yZ=Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0});t9=class extends A{constructor(Z,$){super();this.handle=Z,this.context=$,this._isDone=!1,this.owner=$.runtime}[Symbol.iterator](){return this}next(Z){if(!this.alive||this._isDone)return{done:!0,value:void 0};let $=this._next??(this._next=this.context.getProp(this.handle,"next"));return this.callIteratorMethod($,Z)}return(Z){if(!this.alive)return{done:!0,value:void 0};let $=this.context.getProp(this.handle,"return");if($===this.context.undefined&&Z===void 0)return this.dispose(),{done:!0,value:void 0};let X=this.callIteratorMethod($,Z);return $.dispose(),this.dispose(),X}throw(Z){if(!this.alive)return{done:!0,value:void 0};let $=Z instanceof w?Z:this.context.newError(Z),X=this.context.getProp(this.handle,"throw"),Y=this.callIteratorMethod(X,Z);return $.alive&&$.dispose(),X.dispose(),this.dispose(),Y}get alive(){return this.handle.alive}dispose(){this._isDone=!0,this.handle.dispose(),this._next?.dispose()}callIteratorMethod(Z,$){let X=$?this.context.callFunction(Z,this.handle,$):this.context.callFunction(Z,this.handle);if(X.error)return this.dispose(),{value:X};let Y=this.context.getProp(X.value,"done").consume((C)=>this.context.dump(C)),B=this.context.getProp(X.value,"value");return X.value.dispose(),Y&&this.dispose(),{value:g.success(B),done:Y}}};a8=class extends A{constructor(Z,$,X){if(X===o)throw new f("cannot create HostRef with undefined id");super();this.runtime=Z,this.handle=$,this.id=X}get alive(){return this.handle.alive}dispose(){this.handle.dispose()}get value(){return this.runtime.hostRefs.get(this.id)}},e9=class extends z9{constructor(Z){super(Z.module);this.scope=new I,this.copyJSValue=($)=>this.ffi.QTS_DupValuePointer(this.ctx.value,$),this.freeJSValue=($)=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,$)},Z.ownedLifetimes?.forEach(($)=>this.scope.manage($)),this.owner=Z.owner,this.module=Z.module,this.ffi=Z.ffi,this.rt=Z.rt,this.ctx=this.scope.manage(Z.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage(Z){return this.scope.manage(Z)}consumeJSCharPointer(Z){let $=this.module.UTF8ToString(Z);return this.ffi.QTS_FreeCString(this.ctx.value,Z),$}heapValueHandle(Z,$){let X=$?(Y)=>{$(),this.freeJSValue(Y)}:this.freeJSValue;return new w(Z,this.copyJSValue,X,this.owner)}staticHeapValueHandle(Z){return this.manage(this.heapValueHandle(Z)),new v(Z,this.owner)}},ZZ=class extends A{constructor(Z){super();this._undefined=void 0,this._null=void 0,this._false=void 0,this._true=void 0,this._global=void 0,this._BigInt=void 0,this._Symbol=void 0,this._SymbolIterator=void 0,this._SymbolAsyncIterator=void 0,this.cToHostCallbacks={callFunction:($,X,Y,B,C)=>{if($!==this.ctx.value)throw Error("QuickJSContext instance received C -> JS call with mismatched ctx");let U=this.getFunction(C);return I.withScopeMaybeAsync(this,function*(z,D){let P=D.manage(new i8(X,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),x=Array(Y);for(let M=0;M<Y;M++){let b=this.ffi.QTS_ArgvGetJSValueConstPointer(B,M);x[M]=D.manage(new i8(b,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let M=yield*z(U.apply(P,x));if(M){if("error"in M&&M.error)throw this.runtime.debugLog("throw error",M.error),M.error;let b=D.manage(M instanceof w?M:M.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,b.value)}return 0}catch(M){return this.errorToHandle(M).consume((b)=>this.ffi.QTS_Throw(this.ctx.value,b.value))}})}},this.runtime=Z.runtime,this.module=Z.module,this.ffi=Z.ffi,this.rt=Z.rt,this.ctx=Z.ctx,this.memory=new e9({...Z,owner:this.runtime}),Z.callbacks.setContextCallbacks(this.ctx.value,this.cToHostCallbacks),this.dump=this.dump.bind(this),this.getString=this.getString.bind(this),this.getNumber=this.getNumber.bind(this),this.resolvePromise=this.resolvePromise.bind(this),this.uint32Out=this.memory.manage(this.memory.newTypedArray(Uint32Array,1))}get alive(){return this.memory.alive}dispose(){this.memory.dispose()}get undefined(){if(this._undefined)return this._undefined;let Z=this.ffi.QTS_GetUndefined();return this._undefined=new v(Z)}get null(){if(this._null)return this._null;let Z=this.ffi.QTS_GetNull();return this._null=new v(Z)}get true(){if(this._true)return this._true;let Z=this.ffi.QTS_GetTrue();return this._true=new v(Z)}get false(){if(this._false)return this._false;let Z=this.ffi.QTS_GetFalse();return this._false=new v(Z)}get global(){if(this._global)return this._global;let Z=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this._global=this.memory.staticHeapValueHandle(Z),this._global}newNumber(Z){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,Z))}newString(Z){let $=this.memory.newHeapCharPointer(Z).consume((X)=>this.ffi.QTS_NewString(this.ctx.value,X.value.ptr));return this.memory.heapValueHandle($)}newUniqueSymbol(Z){let $=(typeof Z=="symbol"?Z.description:Z)??"",X=this.memory.newHeapCharPointer($).consume((Y)=>this.ffi.QTS_NewSymbol(this.ctx.value,Y.value.ptr,0));return this.memory.heapValueHandle(X)}newSymbolFor(Z){let $=(typeof Z=="symbol"?Z.description:Z)??"",X=this.memory.newHeapCharPointer($).consume((Y)=>this.ffi.QTS_NewSymbol(this.ctx.value,Y.value.ptr,1));return this.memory.heapValueHandle(X)}getWellKnownSymbol(Z){return this._Symbol??(this._Symbol=this.memory.manage(this.getProp(this.global,"Symbol"))),this.getProp(this._Symbol,Z)}newBigInt(Z){if(!this._BigInt){let Y=this.getProp(this.global,"BigInt");this.memory.manage(Y),this._BigInt=new v(Y.value,this.runtime)}let $=this._BigInt,X=String(Z);return this.newString(X).consume((Y)=>this.unwrapResult(this.callFunction($,this.undefined,Y)))}newObject(Z){Z&&this.runtime.assertOwned(Z);let $=Z?this.ffi.QTS_NewObjectProto(this.ctx.value,Z.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle($)}newArray(){let Z=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(Z)}newArrayBuffer(Z){let $=new Uint8Array(Z),X=this.memory.newHeapBufferPointer($),Y=this.ffi.QTS_NewArrayBuffer(this.ctx.value,X.value.pointer,$.length);return this.memory.heapValueHandle(Y)}newPromise(Z){let $=I.withScope((X)=>{let Y=X.manage(this.memory.newMutablePointerArray(2)),B=this.ffi.QTS_NewPromiseCapability(this.ctx.value,Y.value.ptr),C=this.memory.heapValueHandle(B),[U,z]=Array.from(Y.value.typedArray).map((D)=>this.memory.heapValueHandle(D));return new i9({context:this,promiseHandle:C,resolveHandle:U,rejectHandle:z})});return Z&&typeof Z=="function"&&(Z=new Promise(Z)),Z&&Promise.resolve(Z).then($.resolve,(X)=>X instanceof w?$.reject(X):this.newError(X).consume($.reject)),$}newFunction(Z,$){let X=typeof Z=="function"?Z:$;if(!X)throw TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof Z=="string"?Z:void 0,length:X.length,isConstructor:!1,fn:X})}newConstructorFunction(Z,$){let X=typeof Z=="function"?Z:$;if(!X)throw TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof Z=="string"?Z:void 0,length:X.length,isConstructor:!0,fn:X})}newFunctionWithOptions(Z){let{name:$,length:X,isConstructor:Y,fn:B}=Z,C=this.runtime.hostRefs.put(B);try{return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,$??"",X,Y,C))}catch(U){throw this.runtime.hostRefs.delete(C),U}}newError(Z){let $=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return Z&&typeof Z=="object"?(Z.name!==void 0&&this.newString(Z.name).consume((X)=>this.setProp($,"name",X)),Z.message!==void 0&&this.newString(Z.message).consume((X)=>this.setProp($,"message",X))):typeof Z=="string"?this.newString(Z).consume((X)=>this.setProp($,"message",X)):Z!==void 0&&this.newString(String(Z)).consume((X)=>this.setProp($,"message",X)),$}newHostRef(Z){let $=this.runtime.hostRefs.put(Z);try{let X=this.memory.heapValueHandle(this.ffi.QTS_NewHostRef(this.ctx.value,$));return new a8(this.runtime,X,$)}catch(X){throw this.runtime.hostRefs.delete($),X}}toHostRef(Z){let $=this.ffi.QTS_GetHostRefId(Z.value);if($!==0)return this.runtime.hostRefs.get($),new a8(this.runtime,Z.dup(),$)}unwrapHostRef(Z){let $=this.ffi.QTS_GetHostRefId(Z.value);if($===0)throw new f("handle is not a HostRef");return this.runtime.hostRefs.get($)}typeof(Z){return this.runtime.assertOwned(Z),this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value,Z.value))}getNumber(Z){return this.runtime.assertOwned(Z),this.ffi.QTS_GetFloat64(this.ctx.value,Z.value)}getString(Z){return this.runtime.assertOwned(Z),this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value,Z.value))}getSymbol(Z){this.runtime.assertOwned(Z);let $=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,Z.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,Z.value)?Symbol.for($):Symbol($)}getBigInt(Z){this.runtime.assertOwned(Z);let $=this.getString(Z);return BigInt($)}getArrayBuffer(Z){this.runtime.assertOwned(Z);let $=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,Z.value),X=this.ffi.QTS_GetArrayBuffer(this.ctx.value,Z.value);if(!X)throw Error("Couldn't allocate memory to get ArrayBuffer");return new w(this.module.HEAPU8.subarray(X,X+$),void 0,()=>this.module._free(X))}getPromiseState(Z){this.runtime.assertOwned(Z);let $=this.ffi.QTS_PromiseState(this.ctx.value,Z.value);if($<0)return{type:"fulfilled",value:Z,notAPromise:!0};if($===l.Pending)return{type:"pending",get error(){return new $9("Cannot unwrap a pending promise")}};let X=this.ffi.QTS_PromiseResult(this.ctx.value,Z.value),Y=this.memory.heapValueHandle(X);if($===l.Fulfilled)return{type:"fulfilled",value:Y};if($===l.Rejected)return{type:"rejected",error:Y};throw Y.dispose(),Error(`Unknown JSPromiseStateEnum: ${$}`)}resolvePromise(Z){this.runtime.assertOwned(Z);let $=I.withScope((X)=>{let Y=X.manage(this.getProp(this.global,"Promise")),B=X.manage(this.getProp(Y,"resolve"));return this.callFunction(B,Y,Z)});return $.error?Promise.resolve($):new Promise((X)=>{I.withScope((Y)=>{let B=Y.manage(this.newFunction("resolve",(D)=>{X(this.success(D&&D.dup()))})),C=Y.manage(this.newFunction("reject",(D)=>{X(this.fail(D&&D.dup()))})),U=Y.manage($.value),z=Y.manage(this.getProp(U,"then"));this.callFunction(z,U,B,C).unwrap().dispose()})})}isEqual(Z,$,X=c.IsStrictlyEqual){if(Z===$)return!0;this.runtime.assertOwned(Z),this.runtime.assertOwned($);let Y=this.ffi.QTS_IsEqual(this.ctx.value,Z.value,$.value,X);if(Y===-1)throw new t8("WASM variant does not expose equality");return!!Y}eq(Z,$){return this.isEqual(Z,$,c.IsStrictlyEqual)}sameValue(Z,$){return this.isEqual(Z,$,c.IsSameValue)}sameValueZero(Z,$){return this.isEqual(Z,$,c.IsSameValueZero)}getProp(Z,$){this.runtime.assertOwned(Z);let X;return typeof $=="number"&&$>=0?X=this.ffi.QTS_GetPropNumber(this.ctx.value,Z.value,$):X=this.borrowPropertyKey($).consume((Y)=>this.ffi.QTS_GetProp(this.ctx.value,Z.value,Y.value)),this.memory.heapValueHandle(X)}getLength(Z){if(this.runtime.assertOwned(Z),!(this.ffi.QTS_GetLength(this.ctx.value,this.uint32Out.value.ptr,Z.value)<0))return this.uint32Out.value.typedArray[0]}getOwnPropertyNames(Z,$={strings:!0,numbersAsStrings:!0}){this.runtime.assertOwned(Z),Z.value;let X=a9($);if(X===0)throw new X9("No options set, will return an empty array");return I.withScope((Y)=>{let B=Y.manage(this.memory.newMutablePointerArray(1)),C=this.ffi.QTS_GetOwnPropertyNames(this.ctx.value,B.value.ptr,this.uint32Out.value.ptr,Z.value,X);if(C)return this.fail(this.memory.heapValueHandle(C));let U=this.uint32Out.value.typedArray[0],z=B.value.typedArray[0],D=new Uint32Array(this.module.HEAP8.buffer,z,U),P=Array.from(D).map((x)=>this.memory.heapValueHandle(x));return this.ffi.QTS_FreeVoidPointer(this.ctx.value,z),this.success(p9(P))})}getIterator(Z){let $=this._SymbolIterator??(this._SymbolIterator=this.memory.manage(this.getWellKnownSymbol("iterator")));return I.withScope((X)=>{let Y=X.manage(this.getProp(Z,$)),B=this.callFunction(Y,Z);return B.error?B:this.success(new t9(B.value,this))})}setProp(Z,$,X){this.runtime.assertOwned(Z),this.borrowPropertyKey($).consume((Y)=>this.ffi.QTS_SetProp(this.ctx.value,Z.value,Y.value,X.value))}defineProp(Z,$,X){this.runtime.assertOwned(Z),I.withScope((Y)=>{let B=Y.manage(this.borrowPropertyKey($)),C=X.value||this.undefined,U=!!X.configurable,z=!!X.enumerable,D=!!X.value,P=X.get?Y.manage(this.newFunction(X.get.name,X.get)):this.undefined,x=X.set?Y.manage(this.newFunction(X.set.name,X.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,Z.value,B.value,C.value,P.value,x.value,U,z,D)})}callFunction(Z,$,...X){this.runtime.assertOwned(Z);let Y,B=X[0];B===void 0||Array.isArray(B)?Y=B??[]:Y=X;let C=this.memory.toPointerArray(Y).consume((z)=>this.ffi.QTS_Call(this.ctx.value,Z.value,$.value,Y.length,z.value)),U=this.ffi.QTS_ResolveException(this.ctx.value,C);return U?(this.ffi.QTS_FreeValuePointer(this.ctx.value,C),this.fail(this.memory.heapValueHandle(U))):this.success(this.memory.heapValueHandle(C))}callMethod(Z,$,X=[]){return this.getProp(Z,$).consume((Y)=>this.callFunction(Y,Z,X))}evalCode(Z,$="eval.js",X){let Y=X===void 0?1:0,B=n9(X),C=this.memory.newHeapCharPointer(Z).consume((z)=>this.ffi.QTS_Eval(this.ctx.value,z.value.ptr,z.value.strlen,$,Y,B)),U=this.ffi.QTS_ResolveException(this.ctx.value,C);return U?(this.ffi.QTS_FreeValuePointer(this.ctx.value,C),this.fail(this.memory.heapValueHandle(U))):this.success(this.memory.heapValueHandle(C))}throw(Z){return this.errorToHandle(Z).consume(($)=>this.ffi.QTS_Throw(this.ctx.value,$.value))}borrowPropertyKey(Z){return typeof Z=="number"?this.newNumber(Z):typeof Z=="string"?this.newString(Z):new v(Z.value,this.runtime)}getMemory(Z){if(Z===this.rt.value)return this.memory;throw Error("Private API. Cannot get memory from a different runtime")}dump(Z){this.runtime.assertOwned(Z);let $=this.typeof(Z);if($==="string")return this.getString(Z);if($==="number")return this.getNumber(Z);if($==="bigint")return this.getBigInt(Z);if($==="undefined")return;if($==="symbol")return this.getSymbol(Z);let X=this.getPromiseState(Z);if(X.type==="fulfilled"&&!X.notAPromise)return Z.dispose(),{type:X.type,value:X.value.consume(this.dump)};if(X.type==="pending")return Z.dispose(),{type:X.type};if(X.type==="rejected")return Z.dispose(),{type:X.type,error:X.error.consume(this.dump)};let Y=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,Z.value));try{return JSON.parse(Y)}catch{return Y}}unwrapResult(Z){if(Z.error){let $="context"in Z.error?Z.error.context:this,X=Z.error.consume((Y)=>this.dump(Y));if(X&&typeof X=="object"&&typeof X.message=="string"){let{message:Y,name:B,stack:C,...U}=X,z=new Y8(X,$);typeof B=="string"&&(z.name=X.name),z.message=Y;let D=z.stack;throw typeof C=="string"&&(z.stack=`${B}: ${Y}
7
- ${X.stack}Host: ${D}`),Object.assign(z,U),z}throw new Y8(X)}return Z.value}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getFunction(Z){let $=this.runtime.hostRefs.get(Z);if(typeof $!="function")throw Error(`Host reference ${Z} is not a function`);return $}errorToHandle(Z){return Z instanceof w?Z:this.newError(Z)}encodeBinaryJSON(Z){let $=this.ffi.QTS_bjson_encode(this.ctx.value,Z.value);return this.memory.heapValueHandle($)}decodeBinaryJSON(Z){let $=this.ffi.QTS_bjson_decode(this.ctx.value,Z.value);return this.memory.heapValueHandle($)}success(Z){return g.success(Z)}fail(Z){return g.fail(Z,($)=>this.unwrapResult($))}},$Z=class extends A{constructor(Z){super();this.scope=new I,this.contextMap=new Map,this.hostRefs=new r9,this._debugMode=!1,this.cToHostCallbacks={freeHostRef:($,X)=>{if($!==this.rt.value)throw Error("Runtime pointer mismatch");this.hostRefs.delete(X)},shouldInterrupt:($)=>{if($!==this.rt.value)throw Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let X=this.interruptHandler;if(!X)throw Error("QuickJSContext had no interrupt handler");return X(this)?1:0},loadModuleSource:u8(this,function*($,X,Y,B){let C=this.moduleLoader;if(!C)throw Error("Runtime has no module loader");if(X!==this.rt.value)throw Error("Runtime pointer mismatch");let U=this.contextMap.get(Y)??this.newContext({contextPointer:Y});try{let z=yield*$(C(B,U));if(typeof z=="object"&&"error"in z&&z.error)throw this.debugLog("cToHostLoadModule: loader returned error",z.error),z.error;let D=typeof z=="string"?z:("value"in z)?z.value:z;return this.memory.newHeapCharPointer(D).value.ptr}catch(z){return this.debugLog("cToHostLoadModule: caught error",z),U.throw(z),0}}),normalizeModule:u8(this,function*($,X,Y,B,C){let U=this.moduleNormalizer;if(!U)throw Error("Runtime has no module normalizer");if(X!==this.rt.value)throw Error("Runtime pointer mismatch");let z=this.contextMap.get(Y)??this.newContext({contextPointer:Y});try{let D=yield*$(U(B,C,z));if(typeof D=="object"&&"error"in D&&D.error)throw this.debugLog("cToHostNormalizeModule: normalizer returned error",D.error),D.error;let P=typeof D=="string"?D:D.value;return z.getMemory(this.rt.value).newHeapCharPointer(P).value.ptr}catch(D){return this.debugLog("normalizeModule: caught error",D),z.throw(D),0}})},Z.ownedLifetimes?.forEach(($)=>this.scope.manage($)),this.module=Z.module,this.memory=new z9(this.module),this.ffi=Z.ffi,this.rt=Z.rt,this.callbacks=Z.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this),B8&&this.setDebugMode(!0)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext(Z={}){let $=o9(Z.intrinsics),X=new w(Z.contextPointer||this.ffi.QTS_NewContext(this.rt.value,$),void 0,(B)=>{this.contextMap.delete(B),this.callbacks.deleteContext(B),this.ffi.QTS_FreeContext(B)}),Y=new ZZ({module:this.module,ctx:X,ffi:this.ffi,rt:this.rt,ownedLifetimes:Z.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(X.value,Y),Y}setModuleLoader(Z,$){this.moduleLoader=Z,this.moduleNormalizer=$,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler(Z){let $=this.interruptHandler;this.interruptHandler=Z,$||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs(Z=-1){let $=this.memory.newMutablePointerArray(1),X=this.ffi.QTS_ExecutePendingJob(this.rt.value,Z??-1,$.value.ptr),Y=$.value.typedArray[0];if($.dispose(),Y===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,X),g.success(0);let B=this.contextMap.get(Y)??this.newContext({contextPointer:Y}),C=B.getMemory(this.rt.value).heapValueHandle(X);if(B.typeof(C)==="number"){let U=B.getNumber(C);return C.dispose(),g.success(U)}else{let U=Object.assign(C,{context:B});return g.fail(U,(z)=>B.unwrapResult(z))}}setMemoryLimit(Z){if(Z<0&&Z!==-1)throw Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,Z)}computeMemoryUsage(){let Z=this.getSystemContext().getMemory(this.rt.value);return Z.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,Z.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize(Z){if(Z<0)throw Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,Z)}assertOwned(Z){if(Z.owner&&Z.owner.rt!==this.rt)throw new s8(`Handle is not owned by this runtime: ${Z.owner.rt.value} != ${this.rt.value}`)}setDebugMode(Z){this._debugMode=Z,this.ffi.DEBUG&&this.rt.alive&&this.ffi.QTS_SetDebugLogEnabled(this.rt.value,Z?1:0)}isDebugMode(){return this._debugMode}debugLog(...Z){this._debugMode&&console.log("quickjs-emscripten:",...Z)}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}}});var G9={};f9(G9,{applyModuleEvalRuntimeOptions:()=>j8,applyBaseRuntimeOptions:()=>H8,QuickJSWASMModule:()=>Y9,QuickJSModuleCallbacks:()=>U8});var B9=X8(()=>{Q9()});var j9=A9((a,H9)=>{(function(Z,$){typeof a==="object"&&typeof H9<"u"?$(a):typeof define==="function"&&define.amd?define(["exports"],$):(Z=typeof globalThis<"u"?globalThis:Z||self,$(Z.jmespath={}))})(a,function(Z){let $=(W)=>{return W!==null&&Object.prototype.toString.call(W)==="[object Object]"},X=(W,K)=>{if(W===K)return!0;if(typeof W!==typeof K)return!1;if(Array.isArray(W)&&Array.isArray(K)){if(W.length!==K.length)return!1;for(let Q=0;Q<W.length;Q+=1)if(!X(W[Q],K[Q]))return!1;return!0}if($(W)&&$(K)){let Q=Object.entries(W),G=new Set(Object.keys(K));if(Q.length!==G.size)return!1;for(let[q,H]of Q){if(!X(H,K[q]))return!1;G.delete(q)}return G.size===0}return!1},Y=(W)=>{if(W===""||W===!1||W===null||W===void 0)return!0;if(Array.isArray(W)&&W.length===0)return!0;if($(W)){for(let K in W)if(W.hasOwnProperty(K))return!1;return!0}return!1},B=(W)=>{return W>="a"&&W<="z"||W>="A"&&W<="Z"||W==="_"},C=(W)=>{return W>="0"&&W<="9"||W==="-"},U=(W)=>{return W>="a"&&W<="z"||W>="A"&&W<="Z"||W>="0"&&W<="9"||W==="_"};var z;(function(W){W.TOK_EOF="EOF",W.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",W.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",W.TOK_RBRACKET="Rbracket",W.TOK_RPAREN="Rparen",W.TOK_COMMA="Comma",W.TOK_COLON="Colon",W.TOK_RBRACE="Rbrace",W.TOK_NUMBER="Number",W.TOK_CURRENT="Current",W.TOK_ROOT="Root",W.TOK_EXPREF="Expref",W.TOK_PIPE="Pipe",W.TOK_OR="Or",W.TOK_AND="And",W.TOK_EQ="EQ",W.TOK_GT="GT",W.TOK_LT="LT",W.TOK_GTE="GTE",W.TOK_LTE="LTE",W.TOK_NE="NE",W.TOK_FLATTEN="Flatten",W.TOK_STAR="Star",W.TOK_FILTER="Filter",W.TOK_DOT="Dot",W.TOK_NOT="Not",W.TOK_LBRACE="Lbrace",W.TOK_LBRACKET="Lbracket",W.TOK_LPAREN="Lparen",W.TOK_LITERAL="Literal"})(z||(z={}));let D={"(":z.TOK_LPAREN,")":z.TOK_RPAREN,"*":z.TOK_STAR,",":z.TOK_COMMA,".":z.TOK_DOT,":":z.TOK_COLON,"@":z.TOK_CURRENT,["$"]:z.TOK_ROOT,"]":z.TOK_RBRACKET,"{":z.TOK_LBRACE,"}":z.TOK_RBRACE},P={"!":!0,"<":!0,"=":!0,">":!0},x={"\t":!0,"\n":!0,"\r":!0," ":!0};class M{constructor(){this._current=0}tokenize(W){let K=[];this._current=0;let Q,G,q;while(this._current<W.length)if(B(W[this._current]))Q=this._current,G=this.consumeUnquotedIdentifier(W),K.push({start:Q,type:z.TOK_UNQUOTEDIDENTIFIER,value:G});else if(D[W[this._current]]!==void 0)K.push({start:this._current,type:D[W[this._current]],value:W[this._current]}),this._current+=1;else if(C(W[this._current]))q=this.consumeNumber(W),K.push(q);else if(W[this._current]==="[")q=this.consumeLBracket(W),K.push(q);else if(W[this._current]==='"')Q=this._current,G=this.consumeQuotedIdentifier(W),K.push({start:Q,type:z.TOK_QUOTEDIDENTIFIER,value:G});else if(W[this._current]==="'")Q=this._current,G=this.consumeRawStringLiteral(W),K.push({start:Q,type:z.TOK_LITERAL,value:G});else if(W[this._current]==="`"){Q=this._current;let H=this.consumeLiteral(W);K.push({start:Q,type:z.TOK_LITERAL,value:H})}else if(P[W[this._current]]!==void 0)q=this.consumeOperator(W),q&&K.push(q);else if(x[W[this._current]]!==void 0)this._current+=1;else if(W[this._current]==="&")if(Q=this._current,this._current+=1,W[this._current]==="&")this._current+=1,K.push({start:Q,type:z.TOK_AND,value:"&&"});else K.push({start:Q,type:z.TOK_EXPREF,value:"&"});else if(W[this._current]==="|")if(Q=this._current,this._current+=1,W[this._current]==="|")this._current+=1,K.push({start:Q,type:z.TOK_OR,value:"||"});else K.push({start:Q,type:z.TOK_PIPE,value:"|"});else{let H=Error(`Unknown character: ${W[this._current]}`);throw H.name="LexerError",H}return K}consumeUnquotedIdentifier(W){let K=this._current;this._current+=1;while(this._current<W.length&&U(W[this._current]))this._current+=1;return W.slice(K,this._current)}consumeQuotedIdentifier(W){let K=this._current;this._current+=1;let Q=W.length;while(W[this._current]!=='"'&&this._current<Q){let G=this._current;if(W[G]==="\\"&&(W[G+1]==="\\"||W[G+1]==='"'))G+=2;else G+=1;this._current=G}return this._current+=1,JSON.parse(W.slice(K,this._current))}consumeRawStringLiteral(W){let K=this._current;this._current+=1;let Q=W.length;while(W[this._current]!=="'"&&this._current<Q){let q=this._current;if(W[q]==="\\"&&(W[q+1]==="\\"||W[q+1]==="'"))q+=2;else q+=1;this._current=q}return this._current+=1,W.slice(K+1,this._current-1).replace("\\'","'")}consumeNumber(W){let K=this._current;this._current+=1;let Q=W.length;while(C(W[this._current])&&this._current<Q)this._current+=1;let G=parseInt(W.slice(K,this._current),10);return{start:K,value:G,type:z.TOK_NUMBER}}consumeLBracket(W){let K=this._current;if(this._current+=1,W[this._current]==="?")return this._current+=1,{start:K,type:z.TOK_FILTER,value:"[?"};if(W[this._current]==="]")return this._current+=1,{start:K,type:z.TOK_FLATTEN,value:"[]"};return{start:K,type:z.TOK_LBRACKET,value:"["}}consumeOperator(W){let K=this._current,Q=W[K];if(this._current+=1,Q==="!"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_NE,value:"!="};return{start:K,type:z.TOK_NOT,value:"!"}}if(Q==="<"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_LTE,value:"<="};return{start:K,type:z.TOK_LT,value:"<"}}if(Q===">"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_GTE,value:">="};return{start:K,type:z.TOK_GT,value:">"}}if(Q==="="&&W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_EQ,value:"=="}}consumeLiteral(W){this._current+=1;let K=this._current,Q=W.length;while(W[this._current]!=="`"&&this._current<Q){let H=this._current;if(W[H]==="\\"&&(W[H+1]==="\\"||W[H+1]==="`"))H+=2;else H+=1;this._current=H}let G=W.slice(K,this._current).trimLeft();G=G.replace("\\`","`");let q=this.looksLikeJSON(G)?JSON.parse(G):JSON.parse(`"${G}"`);return this._current+=1,q}looksLikeJSON(W){let Q=["true","false","null"],G="-0123456789";if(W==="")return!1;if('[{"'.includes(W[0]))return!0;if(Q.includes(W))return!0;if("-0123456789".includes(W[0]))try{return JSON.parse(W),!0}catch(q){return!1}return!1}}let b=new M,_={[z.TOK_EOF]:0,[z.TOK_UNQUOTEDIDENTIFIER]:0,[z.TOK_QUOTEDIDENTIFIER]:0,[z.TOK_RBRACKET]:0,[z.TOK_RPAREN]:0,[z.TOK_COMMA]:0,[z.TOK_RBRACE]:0,[z.TOK_NUMBER]:0,[z.TOK_CURRENT]:0,[z.TOK_EXPREF]:0,[z.TOK_ROOT]:0,[z.TOK_PIPE]:1,[z.TOK_OR]:2,[z.TOK_AND]:3,[z.TOK_EQ]:5,[z.TOK_GT]:5,[z.TOK_LT]:5,[z.TOK_GTE]:5,[z.TOK_LTE]:5,[z.TOK_NE]:5,[z.TOK_FLATTEN]:9,[z.TOK_STAR]:20,[z.TOK_FILTER]:21,[z.TOK_DOT]:40,[z.TOK_NOT]:45,[z.TOK_LBRACE]:50,[z.TOK_LBRACKET]:55,[z.TOK_LPAREN]:60};class O8{constructor(){this.index=0,this.tokens=[]}parse(W){this.loadTokens(W),this.index=0;let K=this.expression(0);if(this.lookahead(0)!==z.TOK_EOF){let Q=this.lookaheadToken(0);this.errorToken(Q,`Unexpected token type: ${Q.type}, value: ${Q.value}`)}return K}loadTokens(W){this.tokens=[...b.tokenize(W),{type:z.TOK_EOF,value:"",start:W.length}]}expression(W){let K=this.lookaheadToken(0);this.advance();let Q=this.nud(K),G=this.lookahead(0);while(W<_[G])this.advance(),Q=this.led(G,Q),G=this.lookahead(0);return Q}lookahead(W){return this.tokens[this.index+W].type}lookaheadToken(W){return this.tokens[this.index+W]}advance(){this.index+=1}nud(W){let K,Q,G;switch(W.type){case z.TOK_LITERAL:return{type:"Literal",value:W.value};case z.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:W.value};case z.TOK_QUOTEDIDENTIFIER:let q={type:"Field",name:W.value};if(this.lookahead(0)===z.TOK_LPAREN)throw Error("Quoted identifier not allowed for function names.");else return q;case z.TOK_NOT:return Q=this.expression(_.Not),{type:"NotExpression",children:[Q]};case z.TOK_STAR:return K={type:"Identity"},Q=this.lookahead(0)===z.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(_.Star),{type:"ValueProjection",children:[K,Q]};case z.TOK_FILTER:return this.led(W.type,{type:"Identity"});case z.TOK_LBRACE:return this.parseMultiselectHash();case z.TOK_FLATTEN:return K={type:z.TOK_FLATTEN,children:[{type:"Identity"}]},Q=this.parseProjectionRHS(_.Flatten),{type:"Projection",children:[K,Q]};case z.TOK_LBRACKET:if(this.lookahead(0)===z.TOK_NUMBER||this.lookahead(0)===z.TOK_COLON)return Q=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},Q);if(this.lookahead(0)===z.TOK_STAR&&this.lookahead(1)===z.TOK_RBRACKET)return this.advance(),this.advance(),Q=this.parseProjectionRHS(_.Star),{children:[{type:"Identity"},Q],type:"Projection"};return this.parseMultiselectList();case z.TOK_CURRENT:return{type:z.TOK_CURRENT};case z.TOK_ROOT:return{type:z.TOK_ROOT};case z.TOK_EXPREF:return G=this.expression(_.Expref),{type:"ExpressionReference",children:[G]};case z.TOK_LPAREN:let H=[];while(this.lookahead(0)!==z.TOK_RPAREN){if(this.lookahead(0)===z.TOK_CURRENT)G={type:z.TOK_CURRENT},this.advance();else G=this.expression(0);H.push(G)}return this.match(z.TOK_RPAREN),H[0];default:this.errorToken(W)}}led(W,K){let Q;switch(W){case z.TOK_DOT:let G=_.Dot;if(this.lookahead(0)!==z.TOK_STAR)return Q=this.parseDotRHS(G),{type:"Subexpression",children:[K,Q]};return this.advance(),Q=this.parseProjectionRHS(G),{type:"ValueProjection",children:[K,Q]};case z.TOK_PIPE:return Q=this.expression(_.Pipe),{type:z.TOK_PIPE,children:[K,Q]};case z.TOK_OR:return Q=this.expression(_.Or),{type:"OrExpression",children:[K,Q]};case z.TOK_AND:return Q=this.expression(_.And),{type:"AndExpression",children:[K,Q]};case z.TOK_LPAREN:let q=K.name,H=[],L;while(this.lookahead(0)!==z.TOK_RPAREN){if(this.lookahead(0)===z.TOK_CURRENT)L={type:z.TOK_CURRENT},this.advance();else L=this.expression(0);if(this.lookahead(0)===z.TOK_COMMA)this.match(z.TOK_COMMA);H.push(L)}return this.match(z.TOK_RPAREN),{name:q,type:"Function",children:H};case z.TOK_FILTER:let O=this.expression(0);return this.match(z.TOK_RBRACKET),Q=this.lookahead(0)===z.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(_.Filter),{type:"FilterProjection",children:[K,Q,O]};case z.TOK_FLATTEN:let N={type:z.TOK_FLATTEN,children:[K]},R=this.parseProjectionRHS(_.Flatten);return{type:"Projection",children:[N,R]};case z.TOK_EQ:case z.TOK_NE:case z.TOK_GT:case z.TOK_GTE:case z.TOK_LT:case z.TOK_LTE:return this.parseComparator(K,W);case z.TOK_LBRACKET:let j=this.lookaheadToken(0);if(j.type===z.TOK_NUMBER||j.type===z.TOK_COLON)return Q=this.parseIndexExpression(),this.projectIfSlice(K,Q);return this.match(z.TOK_STAR),this.match(z.TOK_RBRACKET),Q=this.parseProjectionRHS(_.Star),{type:"Projection",children:[K,Q]};default:return this.errorToken(this.lookaheadToken(0))}}match(W){if(this.lookahead(0)===W){this.advance();return}else{let K=this.lookaheadToken(0);this.errorToken(K,`Expected ${W}, got: ${K.type}`)}}errorToken(W,K=""){let Q=Error(K||`Invalid token (${W.type}): "${W.value}"`);throw Q.name="ParserError",Q}parseIndexExpression(){if(this.lookahead(0)===z.TOK_COLON||this.lookahead(1)===z.TOK_COLON)return this.parseSliceExpression();let W={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(z.TOK_RBRACKET),W}projectIfSlice(W,K){let Q={type:"IndexExpression",children:[W,K]};if(K.type==="Slice")return{children:[Q,this.parseProjectionRHS(_.Star)],type:"Projection"};return Q}parseSliceExpression(){let W=[null,null,null],K=0,Q=this.lookahead(0);while(Q!==z.TOK_RBRACKET&&K<3){if(Q===z.TOK_COLON)K+=1,this.advance();else if(Q===z.TOK_NUMBER)W[K]=this.lookaheadToken(0).value,this.advance();else{let G=this.lookaheadToken(0);this.errorToken(G,`Syntax error, unexpected token: ${G.value}(${G.type})`)}Q=this.lookahead(0)}return this.match(z.TOK_RBRACKET),{children:W,type:"Slice"}}parseComparator(W,K){let Q=this.expression(_[K]);return{type:"Comparator",name:K,children:[W,Q]}}parseDotRHS(W){let K=this.lookahead(0);if([z.TOK_UNQUOTEDIDENTIFIER,z.TOK_QUOTEDIDENTIFIER,z.TOK_STAR].includes(K))return this.expression(W);if(K===z.TOK_LBRACKET)return this.match(z.TOK_LBRACKET),this.parseMultiselectList();if(K===z.TOK_LBRACE)return this.match(z.TOK_LBRACE),this.parseMultiselectHash();let G=this.lookaheadToken(0);this.errorToken(G,`Syntax error, unexpected token: ${G.value}(${G.type})`)}parseProjectionRHS(W){if(_[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===z.TOK_LBRACKET)return this.expression(W);if(this.lookahead(0)===z.TOK_FILTER)return this.expression(W);if(this.lookahead(0)===z.TOK_DOT)return this.match(z.TOK_DOT),this.parseDotRHS(W);let K=this.lookaheadToken(0);this.errorToken(K,`Syntax error, unexpected token: ${K.value}(${K.type})`)}parseMultiselectList(){let W=[];while(this.lookahead(0)!==z.TOK_RBRACKET){let K=this.expression(0);if(W.push(K),this.lookahead(0)===z.TOK_COMMA){if(this.match(z.TOK_COMMA),this.lookahead(0)===z.TOK_RBRACKET)throw Error("Unexpected token Rbracket")}}return this.match(z.TOK_RBRACKET),{type:"MultiSelectList",children:W}}parseMultiselectHash(){let W=[],K=[z.TOK_UNQUOTEDIDENTIFIER,z.TOK_QUOTEDIDENTIFIER],Q,G,q;for(;;){if(Q=this.lookaheadToken(0),!K.includes(Q.type))throw Error(`Expecting an identifier token, got: ${Q.type}`);if(G=Q.value,this.advance(),this.match(z.TOK_COLON),q=this.expression(0),W.push({value:q,type:"KeyValuePair",name:G}),this.lookahead(0)===z.TOK_COMMA)this.match(z.TOK_COMMA);else if(this.lookahead(0)===z.TOK_RBRACE){this.match(z.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:W}}}let R8=new O8;var J;(function(W){W[W.TYPE_NUMBER=0]="TYPE_NUMBER",W[W.TYPE_ANY=1]="TYPE_ANY",W[W.TYPE_STRING=2]="TYPE_STRING",W[W.TYPE_ARRAY=3]="TYPE_ARRAY",W[W.TYPE_OBJECT=4]="TYPE_OBJECT",W[W.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",W[W.TYPE_EXPREF=6]="TYPE_EXPREF",W[W.TYPE_NULL=7]="TYPE_NULL",W[W.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",W[W.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"})(J||(J={}));class M8{constructor(W){this.TYPE_NAME_TABLE={[J.TYPE_NUMBER]:"number",[J.TYPE_ANY]:"any",[J.TYPE_STRING]:"string",[J.TYPE_ARRAY]:"array",[J.TYPE_OBJECT]:"object",[J.TYPE_BOOLEAN]:"boolean",[J.TYPE_EXPREF]:"expression",[J.TYPE_NULL]:"null",[J.TYPE_ARRAY_NUMBER]:"Array<number>",[J.TYPE_ARRAY_STRING]:"Array<string>"},this.functionAbs=([K])=>{return Math.abs(K)},this.functionAvg=([K])=>{let Q=0;for(let G=0;G<K.length;G+=1)Q+=K[G];return Q/K.length},this.functionCeil=([K])=>{return Math.ceil(K)},this.functionContains=(K)=>{let[Q,G]=K;return Q.includes(G)},this.functionEndsWith=(K)=>{let[Q,G]=K;return Q.includes(G,Q.length-G.length)},this.functionFloor=([K])=>{return Math.floor(K)},this.functionJoin=(K)=>{let[Q,G]=K;return G.join(Q)},this.functionKeys=([K])=>{return Object.keys(K)},this.functionLength=([K])=>{if(!$(K))return K.length;return Object.keys(K).length},this.functionMap=(K)=>{if(!this._interpreter)return[];let Q=[],G=this._interpreter,q=K[0],H=K[1];for(let L=0;L<H.length;L+=1)Q.push(G.visit(q,H[L]));return Q},this.functionMax=([K])=>{if(!K.length)return null;if(this.getTypeName(K[0])===J.TYPE_NUMBER)return Math.max(...K);let G=K,q=G[0];for(let H=1;H<G.length;H+=1)if(q.localeCompare(G[H])<0)q=G[H];return q},this.functionMaxBy=(K)=>{let Q=K[1],G=K[0],q=this.createKeyFunction(Q,[J.TYPE_NUMBER,J.TYPE_STRING]),H=-1/0,L,F;for(let O=0;O<G.length;O+=1)if(F=q&&q(G[O]),F!==void 0&&F>H)H=F,L=G[O];return L},this.functionMerge=(K)=>{let Q={};for(let G=0;G<K.length;G+=1){let q=K[G];Q=Object.assign(Q,q)}return Q},this.functionMin=([K])=>{if(!K.length)return null;if(this.getTypeName(K[0])===J.TYPE_NUMBER)return Math.min(...K);let G=K,q=G[0];for(let H=1;H<G.length;H+=1)if(G[H].localeCompare(q)<0)q=G[H];return q},this.functionMinBy=(K)=>{let Q=K[1],G=K[0],q=this.createKeyFunction(Q,[J.TYPE_NUMBER,J.TYPE_STRING]),H=1/0,L,F;for(let O=0;O<G.length;O+=1)if(F=q&&q(G[O]),F!==void 0&&F<H)H=F,L=G[O];return L},this.functionNotNull=(K)=>{for(let Q=0;Q<K.length;Q+=1)if(this.getTypeName(K[Q])!==J.TYPE_NULL)return K[Q];return null},this.functionReverse=([K])=>{if(this.getTypeName(K)===J.TYPE_STRING){let q=K,H="";for(let L=q.length-1;L>=0;L-=1)H+=q[L];return H}let G=K.slice(0);return G.reverse(),G},this.functionSort=([K])=>{return[...K].sort()},this.functionSortBy=(K)=>{if(!this._interpreter)return[];let Q=K[0].slice(0);if(Q.length===0)return Q;let G=this._interpreter,q=K[1],H=this.getTypeName(G.visit(q,Q[0]));if(H!==void 0&&![J.TYPE_NUMBER,J.TYPE_STRING].includes(H))throw Error(`TypeError: unexpected type (${this.TYPE_NAME_TABLE[H]})`);let L=[];for(let F=0;F<Q.length;F+=1)L.push([F,Q[F]]);L.sort((F,O)=>{let N=G.visit(q,F[1]),R=G.visit(q,O[1]);if(this.getTypeName(N)!==H)throw Error(`TypeError: expected (${this.TYPE_NAME_TABLE[H]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(N)]}`);else if(this.getTypeName(R)!==H)throw Error(`TypeError: expected (${this.TYPE_NAME_TABLE[H]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(R)]}`);if(N>R)return 1;return N<R?-1:F[0]-O[0]});for(let F=0;F<L.length;F+=1)Q[F]=L[F][1];return Q},this.functionStartsWith=([K,Q])=>{return K.startsWith(Q)},this.functionSum=([K])=>{return K.reduce((Q,G)=>Q+G,0)},this.functionToArray=([K])=>{if(this.getTypeName(K)===J.TYPE_ARRAY)return K;return[K]},this.functionToNumber=([K])=>{let Q=this.getTypeName(K),G;if(Q===J.TYPE_NUMBER)return K;if(Q===J.TYPE_STRING){if(G=+K,!isNaN(G))return G}return null},this.functionToString=([K])=>{if(this.getTypeName(K)===J.TYPE_STRING)return K;return JSON.stringify(K)},this.functionType=([K])=>{switch(this.getTypeName(K)){case J.TYPE_NUMBER:return"number";case J.TYPE_STRING:return"string";case J.TYPE_ARRAY:return"array";case J.TYPE_OBJECT:return"object";case J.TYPE_BOOLEAN:return"boolean";case J.TYPE_EXPREF:return"expref";case J.TYPE_NULL:return"null";default:return}},this.functionValues=([K])=>{return Object.values(K)},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[J.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[J.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[J.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY]},{types:[J.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[J.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[J.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY,J.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[J.TYPE_EXPREF]},{types:[J.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[J.TYPE_ARRAY_NUMBER,J.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[J.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[J.TYPE_ARRAY_NUMBER,J.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[J.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[J.TYPE_ARRAY_STRING,J.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[J.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[J.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[J.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[J.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[J.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[J.TYPE_OBJECT]}]}},this._interpreter=W}registerFunction(W,K,Q){if(W in this.functionTable)throw Error(`Function already defined: ${W}()`);this.functionTable[W]={_func:K.bind(this),_signature:Q}}callFunction(W,K){let Q=this.functionTable[W];if(Q===void 0)throw Error(`Unknown function: ${W}()`);return this.validateArgs(W,K,Q._signature),Q._func.call(this,K)}validateInputSignatures(W,K){for(let Q=0;Q<K.length;Q+=1)if("variadic"in K[Q]&&Q!==K.length-1)throw Error(`ArgumentError: ${W}() 'variadic' argument ${Q+1} must occur last`)}validateArgs(W,K,Q){var G,q;let H;this.validateInputSignatures(W,Q);let L=Q.filter((E)=>{var S;return(S=!E.optional)!==null&&S!==void 0?S:!1}).length,F=(q=(G=Q[Q.length-1])===null||G===void 0?void 0:G.variadic)!==null&&q!==void 0?q:!1,O=K.length<L,N=K.length>Q.length,R=O&&(!F&&L>1||F)?"at least ":"";if(F&&O||!F&&(O||N))throw H=Q.length>1,Error(`ArgumentError: ${W}() takes ${R}${L} argument${H&&"s"||""} but received ${K.length}`);let j,V,T;for(let E=0;E<Q.length;E+=1){T=!1,j=Q[E].types,V=this.getTypeName(K[E]);let S;for(S=0;S<j.length;S+=1)if(V!==void 0&&this.typeMatches(V,j[S],K[E])){T=!0;break}if(!T&&V!==void 0){let d=j.map((p)=>{return this.TYPE_NAME_TABLE[p]}).join(" | ");throw Error(`TypeError: ${W}() expected argument ${E+1} to be type (${d}) but received type ${this.TYPE_NAME_TABLE[V]} instead.`)}}}typeMatches(W,K,Q){if(K===J.TYPE_ANY)return!0;if(K===J.TYPE_ARRAY_STRING||K===J.TYPE_ARRAY_NUMBER||K===J.TYPE_ARRAY){if(K===J.TYPE_ARRAY)return W===J.TYPE_ARRAY;if(W===J.TYPE_ARRAY){let G;if(K===J.TYPE_ARRAY_NUMBER)G=J.TYPE_NUMBER;else if(K===J.TYPE_ARRAY_STRING)G=J.TYPE_STRING;for(let q=0;q<Q.length;q+=1){let H=this.getTypeName(Q[q]);if(H!==void 0&&G!==void 0&&!this.typeMatches(H,G,Q[q]))return!1}return!0}}else return W===K;return!1}getTypeName(W){switch(Object.prototype.toString.call(W)){case"[object String]":return J.TYPE_STRING;case"[object Number]":return J.TYPE_NUMBER;case"[object Array]":return J.TYPE_ARRAY;case"[object Boolean]":return J.TYPE_BOOLEAN;case"[object Null]":return J.TYPE_NULL;case"[object Object]":if(W.jmespathType===z.TOK_EXPREF)return J.TYPE_EXPREF;return J.TYPE_OBJECT;default:return}}createKeyFunction(W,K){if(!this._interpreter)return;let Q=this._interpreter;return(q)=>{let H=Q.visit(W,q);if(!K.includes(this.getTypeName(H))){let L=`TypeError: expected one of (${K.map((F)=>this.TYPE_NAME_TABLE[F]).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(H)]}`;throw Error(L)}return H}}}class V8{constructor(){this._rootValue=null,this.runtime=new M8(this)}search(W,K){return this._rootValue=K,this.visit(W,K)}visit(W,K){let Q,G,q,H,L,F,O,N,R,j,V;switch(W.type){case"Field":if(K===null)return null;if($(K)){if(F=K[W.name],F===void 0)return null;return F}return null;case"Subexpression":q=this.visit(W.children[0],K);for(j=1;j<W.children.length;j+=1)if(q=this.visit(W.children[1],q),q===null)return null;return q;case"IndexExpression":return O=this.visit(W.children[0],K),N=this.visit(W.children[1],O),N;case"Index":if(!Array.isArray(K))return null;let T=W.value;if(T<0)T=K.length+T;if(q=K[T],q===void 0)q=null;return q;case"Slice":if(!Array.isArray(K))return null;let E=[...W.children],S=this.computeSliceParams(K.length,E),[d,p,t]=S;if(q=[],t>0)for(j=d;j<p;j+=t)q.push(K[j]);else for(j=d;j>p;j+=t)q.push(K[j]);return q;case"Projection":if(V=this.visit(W.children[0],K),!Array.isArray(V))return null;R=[];for(j=0;j<V.length;j+=1)if(G=this.visit(W.children[1],V[j]),G!==null)R.push(G);return R;case"ValueProjection":if(V=this.visit(W.children[0],K),!$(V))return null;R=[];let g8=Object.values(V);for(j=0;j<g8.length;j+=1)if(G=this.visit(W.children[1],g8[j]),G!==null)R.push(G);return R;case"FilterProjection":if(V=this.visit(W.children[0],K),!Array.isArray(V))return null;let r=[],c8=[];for(j=0;j<V.length;j+=1)if(Q=this.visit(W.children[2],V[j]),!Y(Q))r.push(V[j]);for(let y=0;y<r.length;y+=1)if(G=this.visit(W.children[1],r[y]),G!==null)c8.push(G);return c8;case"Comparator":switch(H=this.visit(W.children[0],K),L=this.visit(W.children[1],K),W.name){case z.TOK_EQ:q=X(H,L);break;case z.TOK_NE:q=!X(H,L);break;case z.TOK_GT:q=H>L;break;case z.TOK_GTE:q=H>=L;break;case z.TOK_LT:q=H<L;break;case z.TOK_LTE:q=H<=L;break;default:throw Error(`Unknown comparator: ${W.name}`)}return q;case z.TOK_FLATTEN:let e=this.visit(W.children[0],K);if(!Array.isArray(e))return null;let u=[];for(j=0;j<e.length;j+=1)if(G=e[j],Array.isArray(G))u=[...u,...G];else u.push(G);return u;case"Identity":return K;case"MultiSelectList":if(K===null)return null;R=[];for(j=0;j<W.children.length;j+=1)R.push(this.visit(W.children[j],K));return R;case"MultiSelectHash":if(K===null)return null;R={};let Z8;for(j=0;j<W.children.length;j+=1)Z8=W.children[j],R[Z8.name]=this.visit(Z8.value,K);return R;case"OrExpression":if(Q=this.visit(W.children[0],K),Y(Q))Q=this.visit(W.children[1],K);return Q;case"AndExpression":if(H=this.visit(W.children[0],K),Y(H))return H;return this.visit(W.children[1],K);case"NotExpression":return H=this.visit(W.children[0],K),Y(H);case"Literal":return W.value;case z.TOK_PIPE:return O=this.visit(W.children[0],K),this.visit(W.children[1],O);case z.TOK_CURRENT:return K;case z.TOK_ROOT:return this._rootValue;case"Function":let m8=[];for(let y=0;y<W.children.length;y+=1)m8.push(this.visit(W.children[y],K));return this.runtime.callFunction(W.name,m8);case"ExpressionReference":let d8=W.children[0];return d8.jmespathType=z.TOK_EXPREF,d8;default:throw Error(`Unknown node type: ${W.type}`)}}computeSliceParams(W,K){let[Q,G,q]=K;if(q===null)q=1;else if(q===0){let L=Error("Invalid slice, step cannot be 0");throw L.name="RuntimeError",L}let H=q<0?!0:!1;return Q=Q===null?H?W-1:0:this.capSliceRange(W,Q,q),G=G===null?H?-1:W:this.capSliceRange(W,G,q),[Q,G,q]}capSliceRange(W,K,Q){let G=K;if(G<0){if(G+=W,G<0)G=Q<0?-1:0}else if(G>=W)G=Q<0?W-1:W;return G}}let s=new V8,_8=J.TYPE_ANY,w8=J.TYPE_ARRAY,P8=J.TYPE_ARRAY_NUMBER,N8=J.TYPE_ARRAY_STRING,E8=J.TYPE_BOOLEAN,S8=J.TYPE_EXPREF,I8=J.TYPE_NULL,x8=J.TYPE_NUMBER,A8=J.TYPE_OBJECT,b8=J.TYPE_STRING;function T8(W){return R8.parse(W)}function f8(W){return b.tokenize(W)}let y8=(W,K,Q)=>{s.runtime.registerFunction(W,K,Q)};function k8(W,K){let Q=R8.parse(K);return s.search(Q,W)}let h8=s,v8={compile:T8,registerFunction:y8,search:k8,tokenize:f8,TreeInterpreter:h8,TYPE_ANY:_8,TYPE_ARRAY_NUMBER:P8,TYPE_ARRAY_STRING:N8,TYPE_ARRAY:w8,TYPE_BOOLEAN:E8,TYPE_EXPREF:S8,TYPE_NULL:I8,TYPE_NUMBER:x8,TYPE_OBJECT:A8,TYPE_STRING:b8};Z.TYPE_ANY=_8,Z.TYPE_ARRAY=w8,Z.TYPE_ARRAY_NUMBER=P8,Z.TYPE_ARRAY_STRING=N8,Z.TYPE_BOOLEAN=E8,Z.TYPE_EXPREF=S8,Z.TYPE_NULL=I8,Z.TYPE_NUMBER=x8,Z.TYPE_OBJECT=A8,Z.TYPE_STRING=b8,Z.TreeInterpreter=h8,Z.compile=T8,Z.default=v8,Z.jmespath=v8,Z.registerFunction=y8,Z.search=k8,Z.tokenize=f8,Object.defineProperty(Z,"__esModule",{value:!0})})});import{mkdirSync as RZ,mkdtempSync as MZ,writeFileSync as VZ}from"node:fs";import{tmpdir as _Z}from"node:os";import{dirname as wZ,join as L8}from"node:path";import{pathToFileURL as PZ}from"node:url";import{timingSafeEqual as UZ}from"node:crypto";import{createServer as HZ}from"node:http";import{Readable as jZ}from"node:stream";function y9(){return typeof process>"u"?{}:process.env}function p8(Z=y9()){return Z.MCP_BEARER_TOKEN?.trim()||null}import{existsSync as qZ}from"node:fs";i();async function J9(Z){let $=D8(await Z),[X,Y,{QuickJSWASMModule:B}]=await Promise.all([$.importModuleLoader().then(D8),$.importFFI(),Promise.resolve().then(() => (B9(),G9)).then(D8)]),C=await X();C.type="sync";let U=new Y(C);return new B(C,U)}function D8(Z){return Z&&"default"in Z&&Z.default?Z.default&&"default"in Z.default&&Z.default.default?Z.default.default:Z.default:Z}var C9="engine";function WZ(Z){let $=(X)=>new URL(X,Z).href;return{type:"sync",importFFI:()=>import($("ffi.mjs")).then((X)=>X.QuickJSFFI),importModuleLoader:()=>import($("emscripten-module.mjs")).then((X)=>X.default)}}var q9=null;function U9(Z){return()=>{return q9??=J9(WZ(Z)),q9}}var KZ=x9(j9(),1);var YZ="__mcpcloud_call_tool",_1=`globalThis.tool = (name, args) =>
8
- globalThis.${YZ}(String(name), JSON.stringify(args ?? {}))
9
- .then((json) => JSON.parse(json));`;var QZ=6,GZ=["log","warn","error","info","debug"],BZ="__mcpcloud_console",N1=`globalThis.console = {
10
- ${GZ.map((Z)=>` ${Z}: (...args) => globalThis.${BZ}(${JSON.stringify(Z)}, JSON.stringify(args.slice(0, ${QZ}).map((value) => (value instanceof Error ? { __mcpcloudError: value.name + ': ' + value.message } : value)))),`).join(`
6
+ Lifetime used`):new Y8("Lifetime not alive")}},v=class extends w{constructor(Z,$){super(Z,void 0,void 0,$)}get dupable(){return!0}dup(){return this}dispose(){}},i8=class extends w{constructor(Z,$,X,Q){super(Z,$,X,Q)}dispose(){this._alive=!1}};I=class Z extends A{constructor(){super(...arguments);this._disposables=new w(new Set),this.manage=($)=>(this._disposables.value.add($),$)}static withScope($){let X=new Z,Q;try{return $(X)}catch(B){throw Q=B,B}finally{K8(X,Q)}}static withScopeMaybeAsync($,X){return d9(void 0,function*(Q){let B=new Z,C;try{return yield*Q.of(X.call($,Q,B))}catch(U){throw C=U,U}finally{K8(B,C)}})}static async withScopeAsync($){let X=new Z,Q;try{return await $(X)}catch(B){throw Q=B,B}finally{K8(X,Q)}}get alive(){return this._disposables.alive}dispose(){let $=Array.from(this._disposables.value.values()).reverse();for(let X of $)X.alive&&X.dispose();this._disposables.dispose()}};C8=class Z extends A{static success($){return new u9($)}static fail($,X){return new l9($,X)}static is($){return $ instanceof Z}},u9=class extends C8{constructor(Z){super();this.value=Z}get alive(){return n(this.value)?this.value.alive:!0}dispose(){n(this.value)&&this.value.dispose()}unwrap(){return this.value}unwrapOr(Z){return this.value}},l9=class extends C8{constructor(Z,$){super();this.error=Z,this.onUnwrap=$}get alive(){return n(this.error)?this.error.alive:!0}dispose(){n(this.error)&&this.error.dispose()}unwrap(){throw this.onUnwrap(this),this.error}unwrapOr(Z){return Z}},g=C8,i9=class extends A{constructor(Z){super();this.resolve=($)=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,$||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.reject=($)=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,$||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()},this.context=Z.context,this.owner=Z.context.runtime,this.handle=Z.promiseHandle,this.settled=new Promise(($)=>{this.onSettled=$}),this.resolveHandle=Z.resolveHandle,this.rejectHandle=Z.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}},fZ=Symbol("Unstable"),yZ=Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0});t9=class extends A{constructor(Z,$){super();this.handle=Z,this.context=$,this._isDone=!1,this.owner=$.runtime}[Symbol.iterator](){return this}next(Z){if(!this.alive||this._isDone)return{done:!0,value:void 0};let $=this._next??(this._next=this.context.getProp(this.handle,"next"));return this.callIteratorMethod($,Z)}return(Z){if(!this.alive)return{done:!0,value:void 0};let $=this.context.getProp(this.handle,"return");if($===this.context.undefined&&Z===void 0)return this.dispose(),{done:!0,value:void 0};let X=this.callIteratorMethod($,Z);return $.dispose(),this.dispose(),X}throw(Z){if(!this.alive)return{done:!0,value:void 0};let $=Z instanceof w?Z:this.context.newError(Z),X=this.context.getProp(this.handle,"throw"),Q=this.callIteratorMethod(X,Z);return $.alive&&$.dispose(),X.dispose(),this.dispose(),Q}get alive(){return this.handle.alive}dispose(){this._isDone=!0,this.handle.dispose(),this._next?.dispose()}callIteratorMethod(Z,$){let X=$?this.context.callFunction(Z,this.handle,$):this.context.callFunction(Z,this.handle);if(X.error)return this.dispose(),{value:X};let Q=this.context.getProp(X.value,"done").consume((C)=>this.context.dump(C)),B=this.context.getProp(X.value,"value");return X.value.dispose(),Q&&this.dispose(),{value:g.success(B),done:Q}}};a8=class extends A{constructor(Z,$,X){if(X===o)throw new f("cannot create HostRef with undefined id");super();this.runtime=Z,this.handle=$,this.id=X}get alive(){return this.handle.alive}dispose(){this.handle.dispose()}get value(){return this.runtime.hostRefs.get(this.id)}},e9=class extends z9{constructor(Z){super(Z.module);this.scope=new I,this.copyJSValue=($)=>this.ffi.QTS_DupValuePointer(this.ctx.value,$),this.freeJSValue=($)=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,$)},Z.ownedLifetimes?.forEach(($)=>this.scope.manage($)),this.owner=Z.owner,this.module=Z.module,this.ffi=Z.ffi,this.rt=Z.rt,this.ctx=this.scope.manage(Z.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage(Z){return this.scope.manage(Z)}consumeJSCharPointer(Z){let $=this.module.UTF8ToString(Z);return this.ffi.QTS_FreeCString(this.ctx.value,Z),$}heapValueHandle(Z,$){let X=$?(Q)=>{$(),this.freeJSValue(Q)}:this.freeJSValue;return new w(Z,this.copyJSValue,X,this.owner)}staticHeapValueHandle(Z){return this.manage(this.heapValueHandle(Z)),new v(Z,this.owner)}},ZZ=class extends A{constructor(Z){super();this._undefined=void 0,this._null=void 0,this._false=void 0,this._true=void 0,this._global=void 0,this._BigInt=void 0,this._Symbol=void 0,this._SymbolIterator=void 0,this._SymbolAsyncIterator=void 0,this.cToHostCallbacks={callFunction:($,X,Q,B,C)=>{if($!==this.ctx.value)throw Error("QuickJSContext instance received C -> JS call with mismatched ctx");let U=this.getFunction(C);return I.withScopeMaybeAsync(this,function*(z,D){let P=D.manage(new i8(X,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime)),x=Array(Q);for(let M=0;M<Q;M++){let b=this.ffi.QTS_ArgvGetJSValueConstPointer(B,M);x[M]=D.manage(new i8(b,this.memory.copyJSValue,this.memory.freeJSValue,this.runtime))}try{let M=yield*z(U.apply(P,x));if(M){if("error"in M&&M.error)throw this.runtime.debugLog("throw error",M.error),M.error;let b=D.manage(M instanceof w?M:M.value);return this.ffi.QTS_DupValuePointer(this.ctx.value,b.value)}return 0}catch(M){return this.errorToHandle(M).consume((b)=>this.ffi.QTS_Throw(this.ctx.value,b.value))}})}},this.runtime=Z.runtime,this.module=Z.module,this.ffi=Z.ffi,this.rt=Z.rt,this.ctx=Z.ctx,this.memory=new e9({...Z,owner:this.runtime}),Z.callbacks.setContextCallbacks(this.ctx.value,this.cToHostCallbacks),this.dump=this.dump.bind(this),this.getString=this.getString.bind(this),this.getNumber=this.getNumber.bind(this),this.resolvePromise=this.resolvePromise.bind(this),this.uint32Out=this.memory.manage(this.memory.newTypedArray(Uint32Array,1))}get alive(){return this.memory.alive}dispose(){this.memory.dispose()}get undefined(){if(this._undefined)return this._undefined;let Z=this.ffi.QTS_GetUndefined();return this._undefined=new v(Z)}get null(){if(this._null)return this._null;let Z=this.ffi.QTS_GetNull();return this._null=new v(Z)}get true(){if(this._true)return this._true;let Z=this.ffi.QTS_GetTrue();return this._true=new v(Z)}get false(){if(this._false)return this._false;let Z=this.ffi.QTS_GetFalse();return this._false=new v(Z)}get global(){if(this._global)return this._global;let Z=this.ffi.QTS_GetGlobalObject(this.ctx.value);return this._global=this.memory.staticHeapValueHandle(Z),this._global}newNumber(Z){return this.memory.heapValueHandle(this.ffi.QTS_NewFloat64(this.ctx.value,Z))}newString(Z){let $=this.memory.newHeapCharPointer(Z).consume((X)=>this.ffi.QTS_NewString(this.ctx.value,X.value.ptr));return this.memory.heapValueHandle($)}newUniqueSymbol(Z){let $=(typeof Z=="symbol"?Z.description:Z)??"",X=this.memory.newHeapCharPointer($).consume((Q)=>this.ffi.QTS_NewSymbol(this.ctx.value,Q.value.ptr,0));return this.memory.heapValueHandle(X)}newSymbolFor(Z){let $=(typeof Z=="symbol"?Z.description:Z)??"",X=this.memory.newHeapCharPointer($).consume((Q)=>this.ffi.QTS_NewSymbol(this.ctx.value,Q.value.ptr,1));return this.memory.heapValueHandle(X)}getWellKnownSymbol(Z){return this._Symbol??(this._Symbol=this.memory.manage(this.getProp(this.global,"Symbol"))),this.getProp(this._Symbol,Z)}newBigInt(Z){if(!this._BigInt){let Q=this.getProp(this.global,"BigInt");this.memory.manage(Q),this._BigInt=new v(Q.value,this.runtime)}let $=this._BigInt,X=String(Z);return this.newString(X).consume((Q)=>this.unwrapResult(this.callFunction($,this.undefined,Q)))}newObject(Z){Z&&this.runtime.assertOwned(Z);let $=Z?this.ffi.QTS_NewObjectProto(this.ctx.value,Z.value):this.ffi.QTS_NewObject(this.ctx.value);return this.memory.heapValueHandle($)}newArray(){let Z=this.ffi.QTS_NewArray(this.ctx.value);return this.memory.heapValueHandle(Z)}newArrayBuffer(Z){let $=new Uint8Array(Z),X=this.memory.newHeapBufferPointer($),Q=this.ffi.QTS_NewArrayBuffer(this.ctx.value,X.value.pointer,$.length);return this.memory.heapValueHandle(Q)}newPromise(Z){let $=I.withScope((X)=>{let Q=X.manage(this.memory.newMutablePointerArray(2)),B=this.ffi.QTS_NewPromiseCapability(this.ctx.value,Q.value.ptr),C=this.memory.heapValueHandle(B),[U,z]=Array.from(Q.value.typedArray).map((D)=>this.memory.heapValueHandle(D));return new i9({context:this,promiseHandle:C,resolveHandle:U,rejectHandle:z})});return Z&&typeof Z=="function"&&(Z=new Promise(Z)),Z&&Promise.resolve(Z).then($.resolve,(X)=>X instanceof w?$.reject(X):this.newError(X).consume($.reject)),$}newFunction(Z,$){let X=typeof Z=="function"?Z:$;if(!X)throw TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof Z=="string"?Z:void 0,length:X.length,isConstructor:!1,fn:X})}newConstructorFunction(Z,$){let X=typeof Z=="function"?Z:$;if(!X)throw TypeError("Expected a function");return this.newFunctionWithOptions({name:typeof Z=="string"?Z:void 0,length:X.length,isConstructor:!0,fn:X})}newFunctionWithOptions(Z){let{name:$,length:X,isConstructor:Q,fn:B}=Z,C=this.runtime.hostRefs.put(B);try{return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value,$??"",X,Q,C))}catch(U){throw this.runtime.hostRefs.delete(C),U}}newError(Z){let $=this.memory.heapValueHandle(this.ffi.QTS_NewError(this.ctx.value));return Z&&typeof Z=="object"?(Z.name!==void 0&&this.newString(Z.name).consume((X)=>this.setProp($,"name",X)),Z.message!==void 0&&this.newString(Z.message).consume((X)=>this.setProp($,"message",X))):typeof Z=="string"?this.newString(Z).consume((X)=>this.setProp($,"message",X)):Z!==void 0&&this.newString(String(Z)).consume((X)=>this.setProp($,"message",X)),$}newHostRef(Z){let $=this.runtime.hostRefs.put(Z);try{let X=this.memory.heapValueHandle(this.ffi.QTS_NewHostRef(this.ctx.value,$));return new a8(this.runtime,X,$)}catch(X){throw this.runtime.hostRefs.delete($),X}}toHostRef(Z){let $=this.ffi.QTS_GetHostRefId(Z.value);if($!==0)return this.runtime.hostRefs.get($),new a8(this.runtime,Z.dup(),$)}unwrapHostRef(Z){let $=this.ffi.QTS_GetHostRefId(Z.value);if($===0)throw new f("handle is not a HostRef");return this.runtime.hostRefs.get($)}typeof(Z){return this.runtime.assertOwned(Z),this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value,Z.value))}getNumber(Z){return this.runtime.assertOwned(Z),this.ffi.QTS_GetFloat64(this.ctx.value,Z.value)}getString(Z){return this.runtime.assertOwned(Z),this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value,Z.value))}getSymbol(Z){this.runtime.assertOwned(Z);let $=this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value,Z.value));return this.ffi.QTS_IsGlobalSymbol(this.ctx.value,Z.value)?Symbol.for($):Symbol($)}getBigInt(Z){this.runtime.assertOwned(Z);let $=this.getString(Z);return BigInt($)}getArrayBuffer(Z){this.runtime.assertOwned(Z);let $=this.ffi.QTS_GetArrayBufferLength(this.ctx.value,Z.value),X=this.ffi.QTS_GetArrayBuffer(this.ctx.value,Z.value);if(!X)throw Error("Couldn't allocate memory to get ArrayBuffer");return new w(this.module.HEAPU8.subarray(X,X+$),void 0,()=>this.module._free(X))}getPromiseState(Z){this.runtime.assertOwned(Z);let $=this.ffi.QTS_PromiseState(this.ctx.value,Z.value);if($<0)return{type:"fulfilled",value:Z,notAPromise:!0};if($===l.Pending)return{type:"pending",get error(){return new $9("Cannot unwrap a pending promise")}};let X=this.ffi.QTS_PromiseResult(this.ctx.value,Z.value),Q=this.memory.heapValueHandle(X);if($===l.Fulfilled)return{type:"fulfilled",value:Q};if($===l.Rejected)return{type:"rejected",error:Q};throw Q.dispose(),Error(`Unknown JSPromiseStateEnum: ${$}`)}resolvePromise(Z){this.runtime.assertOwned(Z);let $=I.withScope((X)=>{let Q=X.manage(this.getProp(this.global,"Promise")),B=X.manage(this.getProp(Q,"resolve"));return this.callFunction(B,Q,Z)});return $.error?Promise.resolve($):new Promise((X)=>{I.withScope((Q)=>{let B=Q.manage(this.newFunction("resolve",(D)=>{X(this.success(D&&D.dup()))})),C=Q.manage(this.newFunction("reject",(D)=>{X(this.fail(D&&D.dup()))})),U=Q.manage($.value),z=Q.manage(this.getProp(U,"then"));this.callFunction(z,U,B,C).unwrap().dispose()})})}isEqual(Z,$,X=c.IsStrictlyEqual){if(Z===$)return!0;this.runtime.assertOwned(Z),this.runtime.assertOwned($);let Q=this.ffi.QTS_IsEqual(this.ctx.value,Z.value,$.value,X);if(Q===-1)throw new t8("WASM variant does not expose equality");return!!Q}eq(Z,$){return this.isEqual(Z,$,c.IsStrictlyEqual)}sameValue(Z,$){return this.isEqual(Z,$,c.IsSameValue)}sameValueZero(Z,$){return this.isEqual(Z,$,c.IsSameValueZero)}getProp(Z,$){this.runtime.assertOwned(Z);let X;return typeof $=="number"&&$>=0?X=this.ffi.QTS_GetPropNumber(this.ctx.value,Z.value,$):X=this.borrowPropertyKey($).consume((Q)=>this.ffi.QTS_GetProp(this.ctx.value,Z.value,Q.value)),this.memory.heapValueHandle(X)}getLength(Z){if(this.runtime.assertOwned(Z),!(this.ffi.QTS_GetLength(this.ctx.value,this.uint32Out.value.ptr,Z.value)<0))return this.uint32Out.value.typedArray[0]}getOwnPropertyNames(Z,$={strings:!0,numbersAsStrings:!0}){this.runtime.assertOwned(Z),Z.value;let X=a9($);if(X===0)throw new X9("No options set, will return an empty array");return I.withScope((Q)=>{let B=Q.manage(this.memory.newMutablePointerArray(1)),C=this.ffi.QTS_GetOwnPropertyNames(this.ctx.value,B.value.ptr,this.uint32Out.value.ptr,Z.value,X);if(C)return this.fail(this.memory.heapValueHandle(C));let U=this.uint32Out.value.typedArray[0],z=B.value.typedArray[0],D=new Uint32Array(this.module.HEAP8.buffer,z,U),P=Array.from(D).map((x)=>this.memory.heapValueHandle(x));return this.ffi.QTS_FreeVoidPointer(this.ctx.value,z),this.success(p9(P))})}getIterator(Z){let $=this._SymbolIterator??(this._SymbolIterator=this.memory.manage(this.getWellKnownSymbol("iterator")));return I.withScope((X)=>{let Q=X.manage(this.getProp(Z,$)),B=this.callFunction(Q,Z);return B.error?B:this.success(new t9(B.value,this))})}setProp(Z,$,X){this.runtime.assertOwned(Z),this.borrowPropertyKey($).consume((Q)=>this.ffi.QTS_SetProp(this.ctx.value,Z.value,Q.value,X.value))}defineProp(Z,$,X){this.runtime.assertOwned(Z),I.withScope((Q)=>{let B=Q.manage(this.borrowPropertyKey($)),C=X.value||this.undefined,U=!!X.configurable,z=!!X.enumerable,D=!!X.value,P=X.get?Q.manage(this.newFunction(X.get.name,X.get)):this.undefined,x=X.set?Q.manage(this.newFunction(X.set.name,X.set)):this.undefined;this.ffi.QTS_DefineProp(this.ctx.value,Z.value,B.value,C.value,P.value,x.value,U,z,D)})}callFunction(Z,$,...X){this.runtime.assertOwned(Z);let Q,B=X[0];B===void 0||Array.isArray(B)?Q=B??[]:Q=X;let C=this.memory.toPointerArray(Q).consume((z)=>this.ffi.QTS_Call(this.ctx.value,Z.value,$.value,Q.length,z.value)),U=this.ffi.QTS_ResolveException(this.ctx.value,C);return U?(this.ffi.QTS_FreeValuePointer(this.ctx.value,C),this.fail(this.memory.heapValueHandle(U))):this.success(this.memory.heapValueHandle(C))}callMethod(Z,$,X=[]){return this.getProp(Z,$).consume((Q)=>this.callFunction(Q,Z,X))}evalCode(Z,$="eval.js",X){let Q=X===void 0?1:0,B=n9(X),C=this.memory.newHeapCharPointer(Z).consume((z)=>this.ffi.QTS_Eval(this.ctx.value,z.value.ptr,z.value.strlen,$,Q,B)),U=this.ffi.QTS_ResolveException(this.ctx.value,C);return U?(this.ffi.QTS_FreeValuePointer(this.ctx.value,C),this.fail(this.memory.heapValueHandle(U))):this.success(this.memory.heapValueHandle(C))}throw(Z){return this.errorToHandle(Z).consume(($)=>this.ffi.QTS_Throw(this.ctx.value,$.value))}borrowPropertyKey(Z){return typeof Z=="number"?this.newNumber(Z):typeof Z=="string"?this.newString(Z):new v(Z.value,this.runtime)}getMemory(Z){if(Z===this.rt.value)return this.memory;throw Error("Private API. Cannot get memory from a different runtime")}dump(Z){this.runtime.assertOwned(Z);let $=this.typeof(Z);if($==="string")return this.getString(Z);if($==="number")return this.getNumber(Z);if($==="bigint")return this.getBigInt(Z);if($==="undefined")return;if($==="symbol")return this.getSymbol(Z);let X=this.getPromiseState(Z);if(X.type==="fulfilled"&&!X.notAPromise)return Z.dispose(),{type:X.type,value:X.value.consume(this.dump)};if(X.type==="pending")return Z.dispose(),{type:X.type};if(X.type==="rejected")return Z.dispose(),{type:X.type,error:X.error.consume(this.dump)};let Q=this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value,Z.value));try{return JSON.parse(Q)}catch{return Q}}unwrapResult(Z){if(Z.error){let $="context"in Z.error?Z.error.context:this,X=Z.error.consume((Q)=>this.dump(Q));if(X&&typeof X=="object"&&typeof X.message=="string"){let{message:Q,name:B,stack:C,...U}=X,z=new Q8(X,$);typeof B=="string"&&(z.name=X.name),z.message=Q;let D=z.stack;throw typeof C=="string"&&(z.stack=`${B}: ${Q}
7
+ ${X.stack}Host: ${D}`),Object.assign(z,U),z}throw new Q8(X)}return Z.value}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getFunction(Z){let $=this.runtime.hostRefs.get(Z);if(typeof $!="function")throw Error(`Host reference ${Z} is not a function`);return $}errorToHandle(Z){return Z instanceof w?Z:this.newError(Z)}encodeBinaryJSON(Z){let $=this.ffi.QTS_bjson_encode(this.ctx.value,Z.value);return this.memory.heapValueHandle($)}decodeBinaryJSON(Z){let $=this.ffi.QTS_bjson_decode(this.ctx.value,Z.value);return this.memory.heapValueHandle($)}success(Z){return g.success(Z)}fail(Z){return g.fail(Z,($)=>this.unwrapResult($))}},$Z=class extends A{constructor(Z){super();this.scope=new I,this.contextMap=new Map,this.hostRefs=new r9,this._debugMode=!1,this.cToHostCallbacks={freeHostRef:($,X)=>{if($!==this.rt.value)throw Error("Runtime pointer mismatch");this.hostRefs.delete(X)},shouldInterrupt:($)=>{if($!==this.rt.value)throw Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let X=this.interruptHandler;if(!X)throw Error("QuickJSContext had no interrupt handler");return X(this)?1:0},loadModuleSource:u8(this,function*($,X,Q,B){let C=this.moduleLoader;if(!C)throw Error("Runtime has no module loader");if(X!==this.rt.value)throw Error("Runtime pointer mismatch");let U=this.contextMap.get(Q)??this.newContext({contextPointer:Q});try{let z=yield*$(C(B,U));if(typeof z=="object"&&"error"in z&&z.error)throw this.debugLog("cToHostLoadModule: loader returned error",z.error),z.error;let D=typeof z=="string"?z:("value"in z)?z.value:z;return this.memory.newHeapCharPointer(D).value.ptr}catch(z){return this.debugLog("cToHostLoadModule: caught error",z),U.throw(z),0}}),normalizeModule:u8(this,function*($,X,Q,B,C){let U=this.moduleNormalizer;if(!U)throw Error("Runtime has no module normalizer");if(X!==this.rt.value)throw Error("Runtime pointer mismatch");let z=this.contextMap.get(Q)??this.newContext({contextPointer:Q});try{let D=yield*$(U(B,C,z));if(typeof D=="object"&&"error"in D&&D.error)throw this.debugLog("cToHostNormalizeModule: normalizer returned error",D.error),D.error;let P=typeof D=="string"?D:D.value;return z.getMemory(this.rt.value).newHeapCharPointer(P).value.ptr}catch(D){return this.debugLog("normalizeModule: caught error",D),z.throw(D),0}})},Z.ownedLifetimes?.forEach(($)=>this.scope.manage($)),this.module=Z.module,this.memory=new z9(this.module),this.ffi=Z.ffi,this.rt=Z.rt,this.callbacks=Z.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this),B8&&this.setDebugMode(!0)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext(Z={}){let $=o9(Z.intrinsics),X=new w(Z.contextPointer||this.ffi.QTS_NewContext(this.rt.value,$),void 0,(B)=>{this.contextMap.delete(B),this.callbacks.deleteContext(B),this.ffi.QTS_FreeContext(B)}),Q=new ZZ({module:this.module,ctx:X,ffi:this.ffi,rt:this.rt,ownedLifetimes:Z.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(X.value,Q),Q}setModuleLoader(Z,$){this.moduleLoader=Z,this.moduleNormalizer=$,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler(Z){let $=this.interruptHandler;this.interruptHandler=Z,$||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs(Z=-1){let $=this.memory.newMutablePointerArray(1),X=this.ffi.QTS_ExecutePendingJob(this.rt.value,Z??-1,$.value.ptr),Q=$.value.typedArray[0];if($.dispose(),Q===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,X),g.success(0);let B=this.contextMap.get(Q)??this.newContext({contextPointer:Q}),C=B.getMemory(this.rt.value).heapValueHandle(X);if(B.typeof(C)==="number"){let U=B.getNumber(C);return C.dispose(),g.success(U)}else{let U=Object.assign(C,{context:B});return g.fail(U,(z)=>B.unwrapResult(z))}}setMemoryLimit(Z){if(Z<0&&Z!==-1)throw Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,Z)}computeMemoryUsage(){let Z=this.getSystemContext().getMemory(this.rt.value);return Z.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,Z.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize(Z){if(Z<0)throw Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,Z)}assertOwned(Z){if(Z.owner&&Z.owner.rt!==this.rt)throw new s8(`Handle is not owned by this runtime: ${Z.owner.rt.value} != ${this.rt.value}`)}setDebugMode(Z){this._debugMode=Z,this.ffi.DEBUG&&this.rt.alive&&this.ffi.QTS_SetDebugLogEnabled(this.rt.value,Z?1:0)}isDebugMode(){return this._debugMode}debugLog(...Z){this._debugMode&&console.log("quickjs-emscripten:",...Z)}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getSystemContext(){return this.context||(this.context=this.scope.manage(this.newContext())),this.context}}});var G9={};f9(G9,{applyModuleEvalRuntimeOptions:()=>j8,applyBaseRuntimeOptions:()=>H8,QuickJSWASMModule:()=>Q9,QuickJSModuleCallbacks:()=>U8});var B9=X8(()=>{Y9()});var j9=A9((a,H9)=>{(function(Z,$){typeof a==="object"&&typeof H9<"u"?$(a):typeof define==="function"&&define.amd?define(["exports"],$):(Z=typeof globalThis<"u"?globalThis:Z||self,$(Z.jmespath={}))})(a,function(Z){let $=(W)=>{return W!==null&&Object.prototype.toString.call(W)==="[object Object]"},X=(W,K)=>{if(W===K)return!0;if(typeof W!==typeof K)return!1;if(Array.isArray(W)&&Array.isArray(K)){if(W.length!==K.length)return!1;for(let Y=0;Y<W.length;Y+=1)if(!X(W[Y],K[Y]))return!1;return!0}if($(W)&&$(K)){let Y=Object.entries(W),G=new Set(Object.keys(K));if(Y.length!==G.size)return!1;for(let[q,H]of Y){if(!X(H,K[q]))return!1;G.delete(q)}return G.size===0}return!1},Q=(W)=>{if(W===""||W===!1||W===null||W===void 0)return!0;if(Array.isArray(W)&&W.length===0)return!0;if($(W)){for(let K in W)if(W.hasOwnProperty(K))return!1;return!0}return!1},B=(W)=>{return W>="a"&&W<="z"||W>="A"&&W<="Z"||W==="_"},C=(W)=>{return W>="0"&&W<="9"||W==="-"},U=(W)=>{return W>="a"&&W<="z"||W>="A"&&W<="Z"||W>="0"&&W<="9"||W==="_"};var z;(function(W){W.TOK_EOF="EOF",W.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",W.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",W.TOK_RBRACKET="Rbracket",W.TOK_RPAREN="Rparen",W.TOK_COMMA="Comma",W.TOK_COLON="Colon",W.TOK_RBRACE="Rbrace",W.TOK_NUMBER="Number",W.TOK_CURRENT="Current",W.TOK_ROOT="Root",W.TOK_EXPREF="Expref",W.TOK_PIPE="Pipe",W.TOK_OR="Or",W.TOK_AND="And",W.TOK_EQ="EQ",W.TOK_GT="GT",W.TOK_LT="LT",W.TOK_GTE="GTE",W.TOK_LTE="LTE",W.TOK_NE="NE",W.TOK_FLATTEN="Flatten",W.TOK_STAR="Star",W.TOK_FILTER="Filter",W.TOK_DOT="Dot",W.TOK_NOT="Not",W.TOK_LBRACE="Lbrace",W.TOK_LBRACKET="Lbracket",W.TOK_LPAREN="Lparen",W.TOK_LITERAL="Literal"})(z||(z={}));let D={"(":z.TOK_LPAREN,")":z.TOK_RPAREN,"*":z.TOK_STAR,",":z.TOK_COMMA,".":z.TOK_DOT,":":z.TOK_COLON,"@":z.TOK_CURRENT,["$"]:z.TOK_ROOT,"]":z.TOK_RBRACKET,"{":z.TOK_LBRACE,"}":z.TOK_RBRACE},P={"!":!0,"<":!0,"=":!0,">":!0},x={"\t":!0,"\n":!0,"\r":!0," ":!0};class M{constructor(){this._current=0}tokenize(W){let K=[];this._current=0;let Y,G,q;while(this._current<W.length)if(B(W[this._current]))Y=this._current,G=this.consumeUnquotedIdentifier(W),K.push({start:Y,type:z.TOK_UNQUOTEDIDENTIFIER,value:G});else if(D[W[this._current]]!==void 0)K.push({start:this._current,type:D[W[this._current]],value:W[this._current]}),this._current+=1;else if(C(W[this._current]))q=this.consumeNumber(W),K.push(q);else if(W[this._current]==="[")q=this.consumeLBracket(W),K.push(q);else if(W[this._current]==='"')Y=this._current,G=this.consumeQuotedIdentifier(W),K.push({start:Y,type:z.TOK_QUOTEDIDENTIFIER,value:G});else if(W[this._current]==="'")Y=this._current,G=this.consumeRawStringLiteral(W),K.push({start:Y,type:z.TOK_LITERAL,value:G});else if(W[this._current]==="`"){Y=this._current;let H=this.consumeLiteral(W);K.push({start:Y,type:z.TOK_LITERAL,value:H})}else if(P[W[this._current]]!==void 0)q=this.consumeOperator(W),q&&K.push(q);else if(x[W[this._current]]!==void 0)this._current+=1;else if(W[this._current]==="&")if(Y=this._current,this._current+=1,W[this._current]==="&")this._current+=1,K.push({start:Y,type:z.TOK_AND,value:"&&"});else K.push({start:Y,type:z.TOK_EXPREF,value:"&"});else if(W[this._current]==="|")if(Y=this._current,this._current+=1,W[this._current]==="|")this._current+=1,K.push({start:Y,type:z.TOK_OR,value:"||"});else K.push({start:Y,type:z.TOK_PIPE,value:"|"});else{let H=Error(`Unknown character: ${W[this._current]}`);throw H.name="LexerError",H}return K}consumeUnquotedIdentifier(W){let K=this._current;this._current+=1;while(this._current<W.length&&U(W[this._current]))this._current+=1;return W.slice(K,this._current)}consumeQuotedIdentifier(W){let K=this._current;this._current+=1;let Y=W.length;while(W[this._current]!=='"'&&this._current<Y){let G=this._current;if(W[G]==="\\"&&(W[G+1]==="\\"||W[G+1]==='"'))G+=2;else G+=1;this._current=G}return this._current+=1,JSON.parse(W.slice(K,this._current))}consumeRawStringLiteral(W){let K=this._current;this._current+=1;let Y=W.length;while(W[this._current]!=="'"&&this._current<Y){let q=this._current;if(W[q]==="\\"&&(W[q+1]==="\\"||W[q+1]==="'"))q+=2;else q+=1;this._current=q}return this._current+=1,W.slice(K+1,this._current-1).replace("\\'","'")}consumeNumber(W){let K=this._current;this._current+=1;let Y=W.length;while(C(W[this._current])&&this._current<Y)this._current+=1;let G=parseInt(W.slice(K,this._current),10);return{start:K,value:G,type:z.TOK_NUMBER}}consumeLBracket(W){let K=this._current;if(this._current+=1,W[this._current]==="?")return this._current+=1,{start:K,type:z.TOK_FILTER,value:"[?"};if(W[this._current]==="]")return this._current+=1,{start:K,type:z.TOK_FLATTEN,value:"[]"};return{start:K,type:z.TOK_LBRACKET,value:"["}}consumeOperator(W){let K=this._current,Y=W[K];if(this._current+=1,Y==="!"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_NE,value:"!="};return{start:K,type:z.TOK_NOT,value:"!"}}if(Y==="<"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_LTE,value:"<="};return{start:K,type:z.TOK_LT,value:"<"}}if(Y===">"){if(W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_GTE,value:">="};return{start:K,type:z.TOK_GT,value:">"}}if(Y==="="&&W[this._current]==="=")return this._current+=1,{start:K,type:z.TOK_EQ,value:"=="}}consumeLiteral(W){this._current+=1;let K=this._current,Y=W.length;while(W[this._current]!=="`"&&this._current<Y){let H=this._current;if(W[H]==="\\"&&(W[H+1]==="\\"||W[H+1]==="`"))H+=2;else H+=1;this._current=H}let G=W.slice(K,this._current).trimLeft();G=G.replace("\\`","`");let q=this.looksLikeJSON(G)?JSON.parse(G):JSON.parse(`"${G}"`);return this._current+=1,q}looksLikeJSON(W){let Y=["true","false","null"],G="-0123456789";if(W==="")return!1;if('[{"'.includes(W[0]))return!0;if(Y.includes(W))return!0;if("-0123456789".includes(W[0]))try{return JSON.parse(W),!0}catch(q){return!1}return!1}}let b=new M,_={[z.TOK_EOF]:0,[z.TOK_UNQUOTEDIDENTIFIER]:0,[z.TOK_QUOTEDIDENTIFIER]:0,[z.TOK_RBRACKET]:0,[z.TOK_RPAREN]:0,[z.TOK_COMMA]:0,[z.TOK_RBRACE]:0,[z.TOK_NUMBER]:0,[z.TOK_CURRENT]:0,[z.TOK_EXPREF]:0,[z.TOK_ROOT]:0,[z.TOK_PIPE]:1,[z.TOK_OR]:2,[z.TOK_AND]:3,[z.TOK_EQ]:5,[z.TOK_GT]:5,[z.TOK_LT]:5,[z.TOK_GTE]:5,[z.TOK_LTE]:5,[z.TOK_NE]:5,[z.TOK_FLATTEN]:9,[z.TOK_STAR]:20,[z.TOK_FILTER]:21,[z.TOK_DOT]:40,[z.TOK_NOT]:45,[z.TOK_LBRACE]:50,[z.TOK_LBRACKET]:55,[z.TOK_LPAREN]:60};class O8{constructor(){this.index=0,this.tokens=[]}parse(W){this.loadTokens(W),this.index=0;let K=this.expression(0);if(this.lookahead(0)!==z.TOK_EOF){let Y=this.lookaheadToken(0);this.errorToken(Y,`Unexpected token type: ${Y.type}, value: ${Y.value}`)}return K}loadTokens(W){this.tokens=[...b.tokenize(W),{type:z.TOK_EOF,value:"",start:W.length}]}expression(W){let K=this.lookaheadToken(0);this.advance();let Y=this.nud(K),G=this.lookahead(0);while(W<_[G])this.advance(),Y=this.led(G,Y),G=this.lookahead(0);return Y}lookahead(W){return this.tokens[this.index+W].type}lookaheadToken(W){return this.tokens[this.index+W]}advance(){this.index+=1}nud(W){let K,Y,G;switch(W.type){case z.TOK_LITERAL:return{type:"Literal",value:W.value};case z.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:W.value};case z.TOK_QUOTEDIDENTIFIER:let q={type:"Field",name:W.value};if(this.lookahead(0)===z.TOK_LPAREN)throw Error("Quoted identifier not allowed for function names.");else return q;case z.TOK_NOT:return Y=this.expression(_.Not),{type:"NotExpression",children:[Y]};case z.TOK_STAR:return K={type:"Identity"},Y=this.lookahead(0)===z.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(_.Star),{type:"ValueProjection",children:[K,Y]};case z.TOK_FILTER:return this.led(W.type,{type:"Identity"});case z.TOK_LBRACE:return this.parseMultiselectHash();case z.TOK_FLATTEN:return K={type:z.TOK_FLATTEN,children:[{type:"Identity"}]},Y=this.parseProjectionRHS(_.Flatten),{type:"Projection",children:[K,Y]};case z.TOK_LBRACKET:if(this.lookahead(0)===z.TOK_NUMBER||this.lookahead(0)===z.TOK_COLON)return Y=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},Y);if(this.lookahead(0)===z.TOK_STAR&&this.lookahead(1)===z.TOK_RBRACKET)return this.advance(),this.advance(),Y=this.parseProjectionRHS(_.Star),{children:[{type:"Identity"},Y],type:"Projection"};return this.parseMultiselectList();case z.TOK_CURRENT:return{type:z.TOK_CURRENT};case z.TOK_ROOT:return{type:z.TOK_ROOT};case z.TOK_EXPREF:return G=this.expression(_.Expref),{type:"ExpressionReference",children:[G]};case z.TOK_LPAREN:let H=[];while(this.lookahead(0)!==z.TOK_RPAREN){if(this.lookahead(0)===z.TOK_CURRENT)G={type:z.TOK_CURRENT},this.advance();else G=this.expression(0);H.push(G)}return this.match(z.TOK_RPAREN),H[0];default:this.errorToken(W)}}led(W,K){let Y;switch(W){case z.TOK_DOT:let G=_.Dot;if(this.lookahead(0)!==z.TOK_STAR)return Y=this.parseDotRHS(G),{type:"Subexpression",children:[K,Y]};return this.advance(),Y=this.parseProjectionRHS(G),{type:"ValueProjection",children:[K,Y]};case z.TOK_PIPE:return Y=this.expression(_.Pipe),{type:z.TOK_PIPE,children:[K,Y]};case z.TOK_OR:return Y=this.expression(_.Or),{type:"OrExpression",children:[K,Y]};case z.TOK_AND:return Y=this.expression(_.And),{type:"AndExpression",children:[K,Y]};case z.TOK_LPAREN:let q=K.name,H=[],L;while(this.lookahead(0)!==z.TOK_RPAREN){if(this.lookahead(0)===z.TOK_CURRENT)L={type:z.TOK_CURRENT},this.advance();else L=this.expression(0);if(this.lookahead(0)===z.TOK_COMMA)this.match(z.TOK_COMMA);H.push(L)}return this.match(z.TOK_RPAREN),{name:q,type:"Function",children:H};case z.TOK_FILTER:let O=this.expression(0);return this.match(z.TOK_RBRACKET),Y=this.lookahead(0)===z.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(_.Filter),{type:"FilterProjection",children:[K,Y,O]};case z.TOK_FLATTEN:let N={type:z.TOK_FLATTEN,children:[K]},R=this.parseProjectionRHS(_.Flatten);return{type:"Projection",children:[N,R]};case z.TOK_EQ:case z.TOK_NE:case z.TOK_GT:case z.TOK_GTE:case z.TOK_LT:case z.TOK_LTE:return this.parseComparator(K,W);case z.TOK_LBRACKET:let j=this.lookaheadToken(0);if(j.type===z.TOK_NUMBER||j.type===z.TOK_COLON)return Y=this.parseIndexExpression(),this.projectIfSlice(K,Y);return this.match(z.TOK_STAR),this.match(z.TOK_RBRACKET),Y=this.parseProjectionRHS(_.Star),{type:"Projection",children:[K,Y]};default:return this.errorToken(this.lookaheadToken(0))}}match(W){if(this.lookahead(0)===W){this.advance();return}else{let K=this.lookaheadToken(0);this.errorToken(K,`Expected ${W}, got: ${K.type}`)}}errorToken(W,K=""){let Y=Error(K||`Invalid token (${W.type}): "${W.value}"`);throw Y.name="ParserError",Y}parseIndexExpression(){if(this.lookahead(0)===z.TOK_COLON||this.lookahead(1)===z.TOK_COLON)return this.parseSliceExpression();let W={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(z.TOK_RBRACKET),W}projectIfSlice(W,K){let Y={type:"IndexExpression",children:[W,K]};if(K.type==="Slice")return{children:[Y,this.parseProjectionRHS(_.Star)],type:"Projection"};return Y}parseSliceExpression(){let W=[null,null,null],K=0,Y=this.lookahead(0);while(Y!==z.TOK_RBRACKET&&K<3){if(Y===z.TOK_COLON)K+=1,this.advance();else if(Y===z.TOK_NUMBER)W[K]=this.lookaheadToken(0).value,this.advance();else{let G=this.lookaheadToken(0);this.errorToken(G,`Syntax error, unexpected token: ${G.value}(${G.type})`)}Y=this.lookahead(0)}return this.match(z.TOK_RBRACKET),{children:W,type:"Slice"}}parseComparator(W,K){let Y=this.expression(_[K]);return{type:"Comparator",name:K,children:[W,Y]}}parseDotRHS(W){let K=this.lookahead(0);if([z.TOK_UNQUOTEDIDENTIFIER,z.TOK_QUOTEDIDENTIFIER,z.TOK_STAR].includes(K))return this.expression(W);if(K===z.TOK_LBRACKET)return this.match(z.TOK_LBRACKET),this.parseMultiselectList();if(K===z.TOK_LBRACE)return this.match(z.TOK_LBRACE),this.parseMultiselectHash();let G=this.lookaheadToken(0);this.errorToken(G,`Syntax error, unexpected token: ${G.value}(${G.type})`)}parseProjectionRHS(W){if(_[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===z.TOK_LBRACKET)return this.expression(W);if(this.lookahead(0)===z.TOK_FILTER)return this.expression(W);if(this.lookahead(0)===z.TOK_DOT)return this.match(z.TOK_DOT),this.parseDotRHS(W);let K=this.lookaheadToken(0);this.errorToken(K,`Syntax error, unexpected token: ${K.value}(${K.type})`)}parseMultiselectList(){let W=[];while(this.lookahead(0)!==z.TOK_RBRACKET){let K=this.expression(0);if(W.push(K),this.lookahead(0)===z.TOK_COMMA){if(this.match(z.TOK_COMMA),this.lookahead(0)===z.TOK_RBRACKET)throw Error("Unexpected token Rbracket")}}return this.match(z.TOK_RBRACKET),{type:"MultiSelectList",children:W}}parseMultiselectHash(){let W=[],K=[z.TOK_UNQUOTEDIDENTIFIER,z.TOK_QUOTEDIDENTIFIER],Y,G,q;for(;;){if(Y=this.lookaheadToken(0),!K.includes(Y.type))throw Error(`Expecting an identifier token, got: ${Y.type}`);if(G=Y.value,this.advance(),this.match(z.TOK_COLON),q=this.expression(0),W.push({value:q,type:"KeyValuePair",name:G}),this.lookahead(0)===z.TOK_COMMA)this.match(z.TOK_COMMA);else if(this.lookahead(0)===z.TOK_RBRACE){this.match(z.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:W}}}let R8=new O8;var J;(function(W){W[W.TYPE_NUMBER=0]="TYPE_NUMBER",W[W.TYPE_ANY=1]="TYPE_ANY",W[W.TYPE_STRING=2]="TYPE_STRING",W[W.TYPE_ARRAY=3]="TYPE_ARRAY",W[W.TYPE_OBJECT=4]="TYPE_OBJECT",W[W.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",W[W.TYPE_EXPREF=6]="TYPE_EXPREF",W[W.TYPE_NULL=7]="TYPE_NULL",W[W.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",W[W.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"})(J||(J={}));class M8{constructor(W){this.TYPE_NAME_TABLE={[J.TYPE_NUMBER]:"number",[J.TYPE_ANY]:"any",[J.TYPE_STRING]:"string",[J.TYPE_ARRAY]:"array",[J.TYPE_OBJECT]:"object",[J.TYPE_BOOLEAN]:"boolean",[J.TYPE_EXPREF]:"expression",[J.TYPE_NULL]:"null",[J.TYPE_ARRAY_NUMBER]:"Array<number>",[J.TYPE_ARRAY_STRING]:"Array<string>"},this.functionAbs=([K])=>{return Math.abs(K)},this.functionAvg=([K])=>{let Y=0;for(let G=0;G<K.length;G+=1)Y+=K[G];return Y/K.length},this.functionCeil=([K])=>{return Math.ceil(K)},this.functionContains=(K)=>{let[Y,G]=K;return Y.includes(G)},this.functionEndsWith=(K)=>{let[Y,G]=K;return Y.includes(G,Y.length-G.length)},this.functionFloor=([K])=>{return Math.floor(K)},this.functionJoin=(K)=>{let[Y,G]=K;return G.join(Y)},this.functionKeys=([K])=>{return Object.keys(K)},this.functionLength=([K])=>{if(!$(K))return K.length;return Object.keys(K).length},this.functionMap=(K)=>{if(!this._interpreter)return[];let Y=[],G=this._interpreter,q=K[0],H=K[1];for(let L=0;L<H.length;L+=1)Y.push(G.visit(q,H[L]));return Y},this.functionMax=([K])=>{if(!K.length)return null;if(this.getTypeName(K[0])===J.TYPE_NUMBER)return Math.max(...K);let G=K,q=G[0];for(let H=1;H<G.length;H+=1)if(q.localeCompare(G[H])<0)q=G[H];return q},this.functionMaxBy=(K)=>{let Y=K[1],G=K[0],q=this.createKeyFunction(Y,[J.TYPE_NUMBER,J.TYPE_STRING]),H=-1/0,L,F;for(let O=0;O<G.length;O+=1)if(F=q&&q(G[O]),F!==void 0&&F>H)H=F,L=G[O];return L},this.functionMerge=(K)=>{let Y={};for(let G=0;G<K.length;G+=1){let q=K[G];Y=Object.assign(Y,q)}return Y},this.functionMin=([K])=>{if(!K.length)return null;if(this.getTypeName(K[0])===J.TYPE_NUMBER)return Math.min(...K);let G=K,q=G[0];for(let H=1;H<G.length;H+=1)if(G[H].localeCompare(q)<0)q=G[H];return q},this.functionMinBy=(K)=>{let Y=K[1],G=K[0],q=this.createKeyFunction(Y,[J.TYPE_NUMBER,J.TYPE_STRING]),H=1/0,L,F;for(let O=0;O<G.length;O+=1)if(F=q&&q(G[O]),F!==void 0&&F<H)H=F,L=G[O];return L},this.functionNotNull=(K)=>{for(let Y=0;Y<K.length;Y+=1)if(this.getTypeName(K[Y])!==J.TYPE_NULL)return K[Y];return null},this.functionReverse=([K])=>{if(this.getTypeName(K)===J.TYPE_STRING){let q=K,H="";for(let L=q.length-1;L>=0;L-=1)H+=q[L];return H}let G=K.slice(0);return G.reverse(),G},this.functionSort=([K])=>{return[...K].sort()},this.functionSortBy=(K)=>{if(!this._interpreter)return[];let Y=K[0].slice(0);if(Y.length===0)return Y;let G=this._interpreter,q=K[1],H=this.getTypeName(G.visit(q,Y[0]));if(H!==void 0&&![J.TYPE_NUMBER,J.TYPE_STRING].includes(H))throw Error(`TypeError: unexpected type (${this.TYPE_NAME_TABLE[H]})`);let L=[];for(let F=0;F<Y.length;F+=1)L.push([F,Y[F]]);L.sort((F,O)=>{let N=G.visit(q,F[1]),R=G.visit(q,O[1]);if(this.getTypeName(N)!==H)throw Error(`TypeError: expected (${this.TYPE_NAME_TABLE[H]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(N)]}`);else if(this.getTypeName(R)!==H)throw Error(`TypeError: expected (${this.TYPE_NAME_TABLE[H]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(R)]}`);if(N>R)return 1;return N<R?-1:F[0]-O[0]});for(let F=0;F<L.length;F+=1)Y[F]=L[F][1];return Y},this.functionStartsWith=([K,Y])=>{return K.startsWith(Y)},this.functionSum=([K])=>{return K.reduce((Y,G)=>Y+G,0)},this.functionToArray=([K])=>{if(this.getTypeName(K)===J.TYPE_ARRAY)return K;return[K]},this.functionToNumber=([K])=>{let Y=this.getTypeName(K),G;if(Y===J.TYPE_NUMBER)return K;if(Y===J.TYPE_STRING){if(G=+K,!isNaN(G))return G}return null},this.functionToString=([K])=>{if(this.getTypeName(K)===J.TYPE_STRING)return K;return JSON.stringify(K)},this.functionType=([K])=>{switch(this.getTypeName(K)){case J.TYPE_NUMBER:return"number";case J.TYPE_STRING:return"string";case J.TYPE_ARRAY:return"array";case J.TYPE_OBJECT:return"object";case J.TYPE_BOOLEAN:return"boolean";case J.TYPE_EXPREF:return"expref";case J.TYPE_NULL:return"null";default:return}},this.functionValues=([K])=>{return Object.values(K)},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[J.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[J.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[J.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY]},{types:[J.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[J.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[J.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY,J.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[J.TYPE_EXPREF]},{types:[J.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[J.TYPE_ARRAY_NUMBER,J.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[J.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[J.TYPE_ARRAY_NUMBER,J.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[J.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[J.TYPE_STRING,J.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[J.TYPE_ARRAY_STRING,J.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[J.TYPE_ARRAY]},{types:[J.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[J.TYPE_STRING]},{types:[J.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[J.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[J.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[J.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[J.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[J.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[J.TYPE_OBJECT]}]}},this._interpreter=W}registerFunction(W,K,Y){if(W in this.functionTable)throw Error(`Function already defined: ${W}()`);this.functionTable[W]={_func:K.bind(this),_signature:Y}}callFunction(W,K){let Y=this.functionTable[W];if(Y===void 0)throw Error(`Unknown function: ${W}()`);return this.validateArgs(W,K,Y._signature),Y._func.call(this,K)}validateInputSignatures(W,K){for(let Y=0;Y<K.length;Y+=1)if("variadic"in K[Y]&&Y!==K.length-1)throw Error(`ArgumentError: ${W}() 'variadic' argument ${Y+1} must occur last`)}validateArgs(W,K,Y){var G,q;let H;this.validateInputSignatures(W,Y);let L=Y.filter((E)=>{var S;return(S=!E.optional)!==null&&S!==void 0?S:!1}).length,F=(q=(G=Y[Y.length-1])===null||G===void 0?void 0:G.variadic)!==null&&q!==void 0?q:!1,O=K.length<L,N=K.length>Y.length,R=O&&(!F&&L>1||F)?"at least ":"";if(F&&O||!F&&(O||N))throw H=Y.length>1,Error(`ArgumentError: ${W}() takes ${R}${L} argument${H&&"s"||""} but received ${K.length}`);let j,V,T;for(let E=0;E<Y.length;E+=1){T=!1,j=Y[E].types,V=this.getTypeName(K[E]);let S;for(S=0;S<j.length;S+=1)if(V!==void 0&&this.typeMatches(V,j[S],K[E])){T=!0;break}if(!T&&V!==void 0){let d=j.map((p)=>{return this.TYPE_NAME_TABLE[p]}).join(" | ");throw Error(`TypeError: ${W}() expected argument ${E+1} to be type (${d}) but received type ${this.TYPE_NAME_TABLE[V]} instead.`)}}}typeMatches(W,K,Y){if(K===J.TYPE_ANY)return!0;if(K===J.TYPE_ARRAY_STRING||K===J.TYPE_ARRAY_NUMBER||K===J.TYPE_ARRAY){if(K===J.TYPE_ARRAY)return W===J.TYPE_ARRAY;if(W===J.TYPE_ARRAY){let G;if(K===J.TYPE_ARRAY_NUMBER)G=J.TYPE_NUMBER;else if(K===J.TYPE_ARRAY_STRING)G=J.TYPE_STRING;for(let q=0;q<Y.length;q+=1){let H=this.getTypeName(Y[q]);if(H!==void 0&&G!==void 0&&!this.typeMatches(H,G,Y[q]))return!1}return!0}}else return W===K;return!1}getTypeName(W){switch(Object.prototype.toString.call(W)){case"[object String]":return J.TYPE_STRING;case"[object Number]":return J.TYPE_NUMBER;case"[object Array]":return J.TYPE_ARRAY;case"[object Boolean]":return J.TYPE_BOOLEAN;case"[object Null]":return J.TYPE_NULL;case"[object Object]":if(W.jmespathType===z.TOK_EXPREF)return J.TYPE_EXPREF;return J.TYPE_OBJECT;default:return}}createKeyFunction(W,K){if(!this._interpreter)return;let Y=this._interpreter;return(q)=>{let H=Y.visit(W,q);if(!K.includes(this.getTypeName(H))){let L=`TypeError: expected one of (${K.map((F)=>this.TYPE_NAME_TABLE[F]).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(H)]}`;throw Error(L)}return H}}}class V8{constructor(){this._rootValue=null,this.runtime=new M8(this)}search(W,K){return this._rootValue=K,this.visit(W,K)}visit(W,K){let Y,G,q,H,L,F,O,N,R,j,V;switch(W.type){case"Field":if(K===null)return null;if($(K)){if(F=K[W.name],F===void 0)return null;return F}return null;case"Subexpression":q=this.visit(W.children[0],K);for(j=1;j<W.children.length;j+=1)if(q=this.visit(W.children[1],q),q===null)return null;return q;case"IndexExpression":return O=this.visit(W.children[0],K),N=this.visit(W.children[1],O),N;case"Index":if(!Array.isArray(K))return null;let T=W.value;if(T<0)T=K.length+T;if(q=K[T],q===void 0)q=null;return q;case"Slice":if(!Array.isArray(K))return null;let E=[...W.children],S=this.computeSliceParams(K.length,E),[d,p,t]=S;if(q=[],t>0)for(j=d;j<p;j+=t)q.push(K[j]);else for(j=d;j>p;j+=t)q.push(K[j]);return q;case"Projection":if(V=this.visit(W.children[0],K),!Array.isArray(V))return null;R=[];for(j=0;j<V.length;j+=1)if(G=this.visit(W.children[1],V[j]),G!==null)R.push(G);return R;case"ValueProjection":if(V=this.visit(W.children[0],K),!$(V))return null;R=[];let g8=Object.values(V);for(j=0;j<g8.length;j+=1)if(G=this.visit(W.children[1],g8[j]),G!==null)R.push(G);return R;case"FilterProjection":if(V=this.visit(W.children[0],K),!Array.isArray(V))return null;let r=[],c8=[];for(j=0;j<V.length;j+=1)if(Y=this.visit(W.children[2],V[j]),!Q(Y))r.push(V[j]);for(let y=0;y<r.length;y+=1)if(G=this.visit(W.children[1],r[y]),G!==null)c8.push(G);return c8;case"Comparator":switch(H=this.visit(W.children[0],K),L=this.visit(W.children[1],K),W.name){case z.TOK_EQ:q=X(H,L);break;case z.TOK_NE:q=!X(H,L);break;case z.TOK_GT:q=H>L;break;case z.TOK_GTE:q=H>=L;break;case z.TOK_LT:q=H<L;break;case z.TOK_LTE:q=H<=L;break;default:throw Error(`Unknown comparator: ${W.name}`)}return q;case z.TOK_FLATTEN:let e=this.visit(W.children[0],K);if(!Array.isArray(e))return null;let u=[];for(j=0;j<e.length;j+=1)if(G=e[j],Array.isArray(G))u=[...u,...G];else u.push(G);return u;case"Identity":return K;case"MultiSelectList":if(K===null)return null;R=[];for(j=0;j<W.children.length;j+=1)R.push(this.visit(W.children[j],K));return R;case"MultiSelectHash":if(K===null)return null;R={};let Z8;for(j=0;j<W.children.length;j+=1)Z8=W.children[j],R[Z8.name]=this.visit(Z8.value,K);return R;case"OrExpression":if(Y=this.visit(W.children[0],K),Q(Y))Y=this.visit(W.children[1],K);return Y;case"AndExpression":if(H=this.visit(W.children[0],K),Q(H))return H;return this.visit(W.children[1],K);case"NotExpression":return H=this.visit(W.children[0],K),Q(H);case"Literal":return W.value;case z.TOK_PIPE:return O=this.visit(W.children[0],K),this.visit(W.children[1],O);case z.TOK_CURRENT:return K;case z.TOK_ROOT:return this._rootValue;case"Function":let m8=[];for(let y=0;y<W.children.length;y+=1)m8.push(this.visit(W.children[y],K));return this.runtime.callFunction(W.name,m8);case"ExpressionReference":let d8=W.children[0];return d8.jmespathType=z.TOK_EXPREF,d8;default:throw Error(`Unknown node type: ${W.type}`)}}computeSliceParams(W,K){let[Y,G,q]=K;if(q===null)q=1;else if(q===0){let L=Error("Invalid slice, step cannot be 0");throw L.name="RuntimeError",L}let H=q<0?!0:!1;return Y=Y===null?H?W-1:0:this.capSliceRange(W,Y,q),G=G===null?H?-1:W:this.capSliceRange(W,G,q),[Y,G,q]}capSliceRange(W,K,Y){let G=K;if(G<0){if(G+=W,G<0)G=Y<0?-1:0}else if(G>=W)G=Y<0?W-1:W;return G}}let s=new V8,_8=J.TYPE_ANY,w8=J.TYPE_ARRAY,P8=J.TYPE_ARRAY_NUMBER,N8=J.TYPE_ARRAY_STRING,E8=J.TYPE_BOOLEAN,S8=J.TYPE_EXPREF,I8=J.TYPE_NULL,x8=J.TYPE_NUMBER,A8=J.TYPE_OBJECT,b8=J.TYPE_STRING;function T8(W){return R8.parse(W)}function f8(W){return b.tokenize(W)}let y8=(W,K,Y)=>{s.runtime.registerFunction(W,K,Y)};function k8(W,K){let Y=R8.parse(K);return s.search(Y,W)}let h8=s,v8={compile:T8,registerFunction:y8,search:k8,tokenize:f8,TreeInterpreter:h8,TYPE_ANY:_8,TYPE_ARRAY_NUMBER:P8,TYPE_ARRAY_STRING:N8,TYPE_ARRAY:w8,TYPE_BOOLEAN:E8,TYPE_EXPREF:S8,TYPE_NULL:I8,TYPE_NUMBER:x8,TYPE_OBJECT:A8,TYPE_STRING:b8};Z.TYPE_ANY=_8,Z.TYPE_ARRAY=w8,Z.TYPE_ARRAY_NUMBER=P8,Z.TYPE_ARRAY_STRING=N8,Z.TYPE_BOOLEAN=E8,Z.TYPE_EXPREF=S8,Z.TYPE_NULL=I8,Z.TYPE_NUMBER=x8,Z.TYPE_OBJECT=A8,Z.TYPE_STRING=b8,Z.TreeInterpreter=h8,Z.compile=T8,Z.default=v8,Z.jmespath=v8,Z.registerFunction=y8,Z.search=k8,Z.tokenize=f8,Object.defineProperty(Z,"__esModule",{value:!0})})});import{mkdirSync as RZ,mkdtempSync as MZ,writeFileSync as VZ}from"node:fs";import{tmpdir as _Z}from"node:os";import{dirname as wZ,join as L8}from"node:path";import{pathToFileURL as PZ}from"node:url";import{timingSafeEqual as UZ}from"node:crypto";import{createServer as HZ}from"node:http";import{Readable as jZ}from"node:stream";function y9(){return typeof process>"u"?{}:process.env}function p8(Z=y9()){return Z.MCP_BEARER_TOKEN?.trim()||null}import{existsSync as qZ}from"node:fs";i();async function J9(Z){let $=D8(await Z),[X,Q,{QuickJSWASMModule:B}]=await Promise.all([$.importModuleLoader().then(D8),$.importFFI(),Promise.resolve().then(() => (B9(),G9)).then(D8)]),C=await X();C.type="sync";let U=new Q(C);return new B(C,U)}function D8(Z){return Z&&"default"in Z&&Z.default?Z.default&&"default"in Z.default&&Z.default.default?Z.default.default:Z.default:Z}var C9="engine";function WZ(Z){let $=(X)=>new URL(X,Z).href;return{type:"sync",importFFI:()=>import($("ffi.mjs")).then((X)=>X.QuickJSFFI),importModuleLoader:()=>import($("emscripten-module.mjs")).then((X)=>X.default)}}var q9=null;function U9(Z){return()=>{return q9??=J9(WZ(Z)),q9}}var KZ=x9(j9(),1);var QZ="__mcpcloud_call_tool",_1=`globalThis.tool = (name, args) =>
8
+ globalThis.${QZ}(String(name), JSON.stringify(args ?? {}))
9
+ .then((json) => JSON.parse(json));`;var YZ=6,GZ=["log","warn","error","info","debug"],BZ="__mcpcloud_console",N1=`globalThis.console = {
10
+ ${GZ.map((Z)=>` ${Z}: (...args) => globalThis.${BZ}(${JSON.stringify(Z)}, JSON.stringify(args.slice(0, ${YZ}).map((value) => (value instanceof Error ? { __mcpcloudError: value.name + ': ' + value.message } : value)))),`).join(`
11
11
  `)}
12
- };`;var JZ=null;function D9(Z){JZ=Z}var L9=[`./${C9}/`,"../engine/vendor/","../../engine/vendor/"];function CZ(Z=new URL(import.meta.url)){for(let $ of L9){let X=new URL($,Z);if(qZ(new URL("emscripten-module.wasm",X)))return X}throw Error(`Code Mode engine not found. Looked for emscripten-module.wasm in: ${L9.join(", ")} (relative to ${Z.href}).`)}function F9(){D9(()=>U9(CZ())())}function DZ(Z,$){let X=Buffer.from(Z),Y=Buffer.from($);return X.length===Y.length&&UZ(X,Y)}function LZ(Z,$){let X=p8($);if(!X)return null;if(new URL(Z.url).pathname==="/health")return null;let Y=Z.headers.get("authorization")??"",B=/^Bearer\s+(.+)$/i.exec(Y.trim());if(B&&DZ(B[1].trim(),X))return null;return Response.json({error:"unauthorized",message:"This MCP endpoint requires a bearer token (set in Authorization: Bearer <token>)."},{status:401,headers:{"www-authenticate":"Bearer"}})}function FZ(Z,$){let X=new URL(Z.url??"/",$),Y=new Headers;for(let[U,z]of Object.entries(Z.headers))if(Array.isArray(z))for(let D of z)Y.append(U,D);else if(typeof z==="string")Y.set(U,z);let B=Z.method??"GET",C=B==="GET"||B==="HEAD"?void 0:jZ.toWeb(Z);return new Request(X,{method:B,headers:Y,body:C,...C?{duplex:"half"}:{}})}async function OZ(Z,$){if($.statusCode=Z.status,Z.headers.forEach((Y,B)=>{$.setHeader(B,Y)}),!Z.body){$.end();return}let X=Z.body.getReader();for(;;){let{done:Y,value:B}=await X.read();if(Y)break;$.write(B)}$.end()}function O9(Z,$={}){F9();let X=$.port??Number(process.env.PORT??8080),Y=$.hostname??"0.0.0.0",B=HZ((C,U)=>{let z=`http://${C.headers.host??`${Y}:${X}`}`,D=FZ(C,z),P=LZ(D,$.env);(P?Promise.resolve(P):Z.handleRequest(D,$.env)).then((M)=>OZ(M,U)).catch(()=>{U.statusCode=500,U.end(JSON.stringify({error:"internal_error"}))})});return B.listen(X,Y),B}var F8=1;function R9(Z=process.env){let $=Z.BUNDLE_URL?.trim(),X=Z.BUNDLE_SHA256?.trim();if(!$)throw Error("BUNDLE_URL is not set; the runtime host has no code to run.");if(!X)throw Error("BUNDLE_SHA256 is not set; refusing to boot unverified code.");let Y=Number(Z.PORT??8080);if(!Number.isInteger(Y)||Y<=0)throw Error(`Invalid PORT: ${String(Z.PORT)}`);return{bundleUrl:$,bundleSha256:X,port:Y}}async function NZ(Z){let $=Z.buffer.slice(Z.byteOffset,Z.byteOffset+Z.byteLength),X=await crypto.subtle.digest("SHA-256",$);return Array.from(new Uint8Array(X)).map((Y)=>Y.toString(16).padStart(2,"0")).join("")}function EZ(Z){let $=JSON.parse(new TextDecoder().decode(Z));if(!$||typeof $!=="object")throw Error("Boot artifact must be a JSON object.");let X=$;if(X.schemaVersion!==F8)throw Error(`Unsupported boot artifact schemaVersion: ${String(X.schemaVersion)}.`);if(typeof X.runtimeVersion!=="string"||typeof X.mainEntry!=="string"||!Array.isArray(X.files))throw Error("Boot artifact is malformed.");let Y=X.files.map((B)=>{if(!B||typeof B!=="object"||typeof B.path!=="string"||typeof B.content!=="string")throw Error("Boot artifact files must be { path, content }.");let C=B;return{path:C.path,content:C.content}});return{schemaVersion:F8,runtimeVersion:X.runtimeVersion,mainEntry:X.mainEntry,files:Y}}async function M9(Z,$=fetch){let X=await $(Z.bundleUrl);if(!X.ok)throw Error(`Bundle fetch failed (HTTP ${X.status}).`);let Y=new Uint8Array(await X.arrayBuffer()),B=await NZ(Y);if(B!==Z.bundleSha256.toLowerCase())throw Error(`Bundle sha256 mismatch (expected ${Z.bundleSha256}, got ${B}).`);return EZ(Y)}function V9(Z,$){for(let X of Z.files){let Y=L8($,X.path);RZ(wZ(Y),{recursive:!0}),VZ(Y,X.content)}return{entryPath:L8($,Z.mainEntry)}}async function SZ(Z={}){let $=Z.bootConfig??R9(),X=await M9($,Z.fetchImpl),Y=Z.workDir??MZ(L8(_Z(),"mcpcloud-server-")),{entryPath:B}=V9(X,Y),C=await import(PZ(B).href),U=C.server??C.default;if(!U)throw Error(`Boot module ${X.mainEntry} does not export a \`server\`.`);let z={port:$.port,...Z.hostname?{hostname:Z.hostname}:{},...Z.env?{env:Z.env}:{}};return O9(U,z)}export{SZ as serveFromBundle,R9 as resolveBootConfig,V9 as materializeBundle,M9 as fetchAndVerifyBundle,F8 as BOOT_ARTIFACT_SCHEMA_VERSION};
12
+ };`;var JZ=Symbol.for("@mcpcloud/runtime.codeModeEngineProvider");function D9(Z){globalThis[JZ]=Z}var L9=[`./${C9}/`,"../engine/vendor/","../../engine/vendor/"];function CZ(Z=new URL(import.meta.url)){for(let $ of L9){let X=new URL($,Z);if(qZ(new URL("emscripten-module.wasm",X)))return X}throw Error(`Code Mode engine not found. Looked for emscripten-module.wasm in: ${L9.join(", ")} (relative to ${Z.href}).`)}function F9(){D9(()=>U9(CZ())())}function DZ(Z,$){let X=Buffer.from(Z),Q=Buffer.from($);return X.length===Q.length&&UZ(X,Q)}function LZ(Z,$){let X=p8($);if(!X)return null;if(new URL(Z.url).pathname==="/health")return null;let Q=Z.headers.get("authorization")??"",B=/^Bearer\s+(.+)$/i.exec(Q.trim());if(B&&DZ(B[1].trim(),X))return null;return Response.json({error:"unauthorized",message:"This MCP endpoint requires a bearer token (set in Authorization: Bearer <token>)."},{status:401,headers:{"www-authenticate":"Bearer"}})}function FZ(Z,$){let X=new URL(Z.url??"/",$),Q=new Headers;for(let[U,z]of Object.entries(Z.headers))if(Array.isArray(z))for(let D of z)Q.append(U,D);else if(typeof z==="string")Q.set(U,z);let B=Z.method??"GET",C=B==="GET"||B==="HEAD"?void 0:jZ.toWeb(Z);return new Request(X,{method:B,headers:Q,body:C,...C?{duplex:"half"}:{}})}async function OZ(Z,$){if($.statusCode=Z.status,Z.headers.forEach((Q,B)=>{$.setHeader(B,Q)}),!Z.body){$.end();return}let X=Z.body.getReader();for(;;){let{done:Q,value:B}=await X.read();if(Q)break;$.write(B)}$.end()}function O9(Z,$={}){F9();let X=$.port??Number(process.env.PORT??8080),Q=$.hostname??"0.0.0.0",B=HZ((C,U)=>{let z=`http://${C.headers.host??`${Q}:${X}`}`,D=FZ(C,z),P=LZ(D,$.env);(P?Promise.resolve(P):Z.handleRequest(D,$.env)).then((M)=>OZ(M,U)).catch(()=>{U.statusCode=500,U.end(JSON.stringify({error:"internal_error"}))})});return B.listen(X,Q),B}var F8=1;function R9(Z=process.env){let $=Z.BUNDLE_URL?.trim(),X=Z.BUNDLE_SHA256?.trim();if(!$)throw Error("BUNDLE_URL is not set; the runtime host has no code to run.");if(!X)throw Error("BUNDLE_SHA256 is not set; refusing to boot unverified code.");let Q=Number(Z.PORT??8080);if(!Number.isInteger(Q)||Q<=0)throw Error(`Invalid PORT: ${String(Z.PORT)}`);return{bundleUrl:$,bundleSha256:X,port:Q}}async function NZ(Z){let $=Z.buffer.slice(Z.byteOffset,Z.byteOffset+Z.byteLength),X=await crypto.subtle.digest("SHA-256",$);return Array.from(new Uint8Array(X)).map((Q)=>Q.toString(16).padStart(2,"0")).join("")}function EZ(Z){let $=JSON.parse(new TextDecoder().decode(Z));if(!$||typeof $!=="object")throw Error("Boot artifact must be a JSON object.");let X=$;if(X.schemaVersion!==F8)throw Error(`Unsupported boot artifact schemaVersion: ${String(X.schemaVersion)}.`);if(typeof X.runtimeVersion!=="string"||typeof X.mainEntry!=="string"||!Array.isArray(X.files))throw Error("Boot artifact is malformed.");let Q=X.files.map((B)=>{if(!B||typeof B!=="object"||typeof B.path!=="string"||typeof B.content!=="string")throw Error("Boot artifact files must be { path, content }.");let C=B;return{path:C.path,content:C.content}});return{schemaVersion:F8,runtimeVersion:X.runtimeVersion,mainEntry:X.mainEntry,files:Q}}async function M9(Z,$=fetch){let X=await $(Z.bundleUrl);if(!X.ok)throw Error(`Bundle fetch failed (HTTP ${X.status}).`);let Q=new Uint8Array(await X.arrayBuffer()),B=await NZ(Q);if(B!==Z.bundleSha256.toLowerCase())throw Error(`Bundle sha256 mismatch (expected ${Z.bundleSha256}, got ${B}).`);return EZ(Q)}function V9(Z,$){for(let X of Z.files){let Q=L8($,X.path);RZ(wZ(Q),{recursive:!0}),VZ(Q,X.content)}return{entryPath:L8($,Z.mainEntry)}}async function SZ(Z={}){let $=Z.bootConfig??R9(),X=await M9($,Z.fetchImpl),Q=Z.workDir??MZ(L8(_Z(),"mcpcloud-server-")),{entryPath:B}=V9(X,Q),C=await import(PZ(B).href),U=C.server??C.default;if(!U)throw Error(`Boot module ${X.mainEntry} does not export a \`server\`.`);let z={port:$.port,...Z.hostname?{hostname:Z.hostname}:{},...Z.env?{env:Z.env}:{}};return O9(U,z)}export{SZ as serveFromBundle,R9 as resolveBootConfig,V9 as materializeBundle,M9 as fetchAndVerifyBundle,F8 as BOOT_ARTIFACT_SCHEMA_VERSION};