@mcpcloud/runtime 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @mcpcloud/runtime v0.14.0 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
1
+ /*! @mcpcloud/runtime v0.15.0 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
2
  var Tt=Object.create;var{getPrototypeOf:Et,defineProperty:re,getOwnPropertyNames:yt}=Object;var St=Object.prototype.hasOwnProperty;function Rt(e){return this[e]}var wt,At,Pt=(e,t,n)=>{var a=e!=null&&typeof e==="object";if(a){var l=t?wt??=new WeakMap:At??=new WeakMap,d=l.get(e);if(d)return d}n=e!=null?Tt(Et(e)):{};let m=t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let s of yt(e))if(!St.call(m,s))re(m,s,{get:Rt.bind(e,s),enumerable:!0})}if(a)l.set(e,m);return m};var bt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ot=(e)=>e;function Mt(e,t){this[e]=Ot.bind(null,t)}var vt=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0,configurable:!0,set:Mt.bind(t,n)})};var ne=(e,t)=>()=>(e&&(t=e(e=0)),t);var U,ie,j,K,J;var V=ne(()=>{U={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},ie={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},j={Pending:0,Fulfilled:1,Rejected:2},K={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},J={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2}});function H(...e){ce&&console.log("quickjs-emscripten:",...e)}function*it(e){return yield e}function Ut(e){return it(de(e))}function De(e,t){return(...n)=>{let a=t.call(e,he,...n);return de(a)}}function Kt(e,t){let n=t.call(e,he);return de(n)}function de(e){function t(n){return n.done?n.value:n.value instanceof Promise?n.value.then((a)=>t(e.next(a)),(a)=>t(e.throw(a))):t(e.next(n.value))}return t(e.next())}function se(e,t){let n;try{e.dispose()}catch(a){n=a}if(t&&n)throw Object.assign(t,{message:`${t.message}
3
3
  Then, failed to dispose scope: ${n.message}`,disposeError:n}),t;if(t||n)throw t||n}function Yt(e){let t=e?Array.from(e):[];function n(){return t.forEach((l)=>l.alive?l.dispose():void 0)}function a(){return t.some((l)=>l.alive)}return Object.defineProperty(t,le,{configurable:!0,enumerable:!1,value:n}),Object.defineProperty(t,"dispose",{configurable:!0,enumerable:!1,value:n}),Object.defineProperty(t,"alive",{configurable:!0,enumerable:!1,get:a}),t}function W(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&("alive"in e)&&typeof e.alive=="boolean"&&("dispose"in e)&&typeof e.dispose=="function")}function Ft(e){if(!e)return 0;let t=0;for(let[n,a]of Object.entries(e)){if(!(n in ie))throw new et(n);a&&(t|=ie[n])}return t}function Qt(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{type:t,strict:n,strip:a,compileOnly:l,backtraceBarrier:d}=e,m=0;return t==="global"&&(m|=U.JS_EVAL_TYPE_GLOBAL),t==="module"&&(m|=U.JS_EVAL_TYPE_MODULE),n&&(m|=U.JS_EVAL_FLAG_STRICT),a&&(m|=U.JS_EVAL_FLAG_STRIP),l&&(m|=U.JS_EVAL_FLAG_COMPILE_ONLY),d&&(m|=U.JS_EVAL_FLAG_BACKTRACE_BARRIER),m}function Dt(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{strings:t,symbols:n,quickjsPrivate:a,onlyEnumerable:l,numbers:d,numbersAsStrings:m}=e,s=0;return t&&(s|=K.JS_GPN_STRING_MASK),n&&(s|=K.JS_GPN_SYMBOL_MASK),a&&(s|=K.JS_GPN_PRIVATE_MASK),l&&(s|=K.JS_GPN_ENUM_ONLY),d&&(s|=K.QTS_GPN_NUMBER_MASK),m&&(s|=K.QTS_STANDARD_COMPLIANT_NUMBER),s}function jt(...e){let t=[];for(let n of e)n!==void 0&&(t=t.concat(n));return t}function oe(e){return e>>8}function pe(e,t){t.interruptHandler&&e.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes)}function _e(e,t){t.moduleLoader&&e.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&e.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes)}var Nt,kt=(e,t)=>{for(var n in t)Nt(e,n,{get:t[n],enumerable:!0})},ce=!1,It,ae,qe,ue,ze,Xe,Ze,Ct,Lt,et,tt,rt,nt,C,he,N,le,je,A,Y,$e,v,fe,Bt,Jt,B,Ht,st=class{constructor(e){this.module=e}toPointerArray(e){let t=new Int32Array(e.map((l)=>l.value)),n=t.length*t.BYTES_PER_ELEMENT,a=this.module._malloc(n);return new Uint8Array(this.module.HEAPU8.buffer,a,n).set(new Uint8Array(t.buffer)),new A(a,void 0,(l)=>this.module._free(l))}newTypedArray(e,t){let n=new e(Array(t).fill(0)),a=n.length*n.BYTES_PER_ELEMENT,l=this.module._malloc(a),d=new e(this.module.HEAPU8.buffer,l,t);return d.set(n),new A({typedArray:d,ptr:l},void 0,(m)=>this.module._free(m.ptr))}newMutablePointerArray(e){return this.newTypedArray(Int32Array,e)}newHeapCharPointer(e){let t=this.module.lengthBytesUTF8(e),n=t+1,a=this.module._malloc(n);return this.module.stringToUTF8(e,a,n),new A({ptr:a,strlen:t},void 0,(l)=>this.module._free(l.ptr))}newHeapBufferPointer(e){let t=e.byteLength,n=this.module._malloc(t);return this.module.HEAPU8.set(e,n),new A({pointer:n,numBytes:t},void 0,(a)=>this.module._free(a.pointer))}consumeHeapCharPointer(e){let t=this.module.UTF8ToString(e);return this.module._free(e),t}},Sr,Rr,$t,Ve=-2147483648,Ge=2147483647,G=0,Vt=class{constructor(){this.nextId=Ve,this.freelist=[],this.groups=new Map}put(e){let t=this.allocateId(),n=oe(t),a=this.groups.get(n);return a||(a=new Map,this.groups.set(n,a)),a.set(t,e),t}get(e){if(e===G)throw new C("no host reference id defined");let t=oe(e),n=this.groups.get(t);if(!n)throw new C(`host reference id ${e} is not defined`);let a=n.get(e);if(!a)throw new C(`host reference id ${e} is not defined`);return a}delete(e){if(e===G)throw new C("no host reference id defined");let t=oe(e),n=this.groups.get(t);if(!n)throw new C(`host reference id ${e} is not defined`);n.delete(e),n.size===0&&this.groups.delete(t),this.freelist.push(e)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===G&&this.nextId++,this.nextId>Ge)throw new nt(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${Ge-Ve}`);return this.nextId++}},We,Gt,Wt,qt,zt=class{constructor(e){this.freeHostRef=e.freeHostRef,this.callFunction=e.callFunction,this.shouldInterrupt=e.shouldInterrupt,this.loadModuleSource=e.loadModuleSource,this.normalizeModule=e.normalizeModule}},me=class{constructor(e){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new zt({freeHostRef:(t,n,a)=>{let l=this.runtimeCallbacks.get(n);if(!l)throw Error(`QuickJSRuntime(rt = ${n}) not found when trying to free HostRef(id = ${a})`);l.freeHostRef(n,a)},callFunction:(t,n,a,l,d,m)=>this.handleAsyncify(t,()=>{try{let s=this.contextCallbacks.get(n);if(!s)throw Error(`QuickJSContext(ctx = ${n}) not found for C function call "${m}"`);return s.callFunction(n,a,l,d,m)}catch(s){return console.error("[C to host error: returning null]",s),0}}),shouldInterrupt:(t,n)=>this.handleAsyncify(t,()=>{try{let a=this.runtimeCallbacks.get(n);if(!a)throw Error(`QuickJSRuntime(rt = ${n}) not found for C interrupt`);return a.shouldInterrupt(n)}catch(a){return console.error("[C to host interrupt: returning error]",a),1}}),loadModuleSource:(t,n,a,l)=>this.handleAsyncify(t,()=>{try{let d=this.runtimeCallbacks.get(n);if(!d)throw Error(`QuickJSRuntime(rt = ${n}) not found for C module loader`);let m=d.loadModuleSource;if(!m)throw Error(`QuickJSRuntime(rt = ${n}) does not support module loading`);return m(n,a,l)}catch(d){return console.error("[C to host module loader error: returning null]",d),0}}),normalizeModule:(t,n,a,l,d)=>this.handleAsyncify(t,()=>{try{let m=this.runtimeCallbacks.get(n);if(!m)throw Error(`QuickJSRuntime(rt = ${n}) not found for C module loader`);let s=m.normalizeModule;if(!s)throw Error(`QuickJSRuntime(rt = ${n}) does not support module loading`);return s(n,a,l,d)}catch(m){return console.error("[C to host module loader error: returning null]",m),0}})}),this.module=e,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(e,t){this.runtimeCallbacks.set(e,t)}deleteRuntime(e){this.runtimeCallbacks.delete(e)}setContextCallbacks(e,t){this.contextCallbacks.set(e,t)}deleteContext(e){this.contextCallbacks.delete(e)}handleAsyncify(e,t){if(e)return e.handleSleep((a)=>{try{let l=t();if(!(l instanceof Promise)){H("asyncify.handleSleep: not suspending:",l),a(l);return}if(this.suspended)throw new Xe(`Already suspended at: ${this.suspended.stack}
4
4
  Attempted to suspend at:`);this.suspended=new Ze(`(${this.suspendedCount++})`),H("asyncify.handleSleep: suspending:",this.suspended),l.then((d)=>{this.suspended=void 0,H("asyncify.handleSleep: resolved:",d),a(d)},(d)=>{H("asyncify.handleSleep: rejected:",d),console.error("QuickJS: cannot handle error in suspended function",d),this.suspended=void 0})}catch(l){throw H("asyncify.handleSleep: error:",l),this.suspended=void 0,l}});let n=t();if(n instanceof Promise)throw Error("Promise return value not supported in non-asyncify context.");return n}},ot=class{constructor(e,t){this.module=e,this.ffi=t,this.callbacks=new me(e)}newRuntime(e={}){let t=new A(this.ffi.QTS_NewRuntime(),void 0,(a)=>{this.ffi.QTS_FreeRuntime(a),this.callbacks.deleteRuntime(a)}),n=new qt({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:t});return pe(n,e),e.moduleLoader&&n.setModuleLoader(e.moduleLoader),n}newContext(e={}){let t=this.newRuntime(),n=t.newContext({...e,ownedLifetimes:jt(t,e.ownedLifetimes)});return t.context=n,n}evalCode(e,t={}){return v.withScope((n)=>{let a=n.manage(this.newContext());_e(a.runtime,t);let l=a.evalCode(e,"eval.js");if(t.memoryLimitBytes!==void 0&&a.runtime.setMemoryLimit(-1),l.error)throw a.dump(n.manage(l.error));return a.dump(n.manage(l.value))})}getWasmMemory(){let e=this.module.quickjsEmscriptenInit?.(()=>{})?.getWasmMemory?.();if(!e)throw Error("Variant does not support getting WebAssembly.Memory");return e}getFFI(){return this.ffi}};var at=ne(()=>{V();V();Nt=Object.defineProperty;It={};kt(It,{QuickJSAsyncifyError:()=>Xe,QuickJSAsyncifySuspended:()=>Ze,QuickJSEmptyGetOwnPropertyNames:()=>rt,QuickJSEmscriptenModuleError:()=>Lt,QuickJSHostRefInvalid:()=>C,QuickJSHostRefRangeExceeded:()=>nt,QuickJSMemoryLeakDetected:()=>Ct,QuickJSNotImplemented:()=>ze,QuickJSPromisePending:()=>tt,QuickJSUnknownIntrinsic:()=>et,QuickJSUnwrapError:()=>ae,QuickJSUseAfterFree:()=>ue,QuickJSWrongOwner:()=>qe});ae=class extends Error{constructor(e,t){let n=typeof e=="object"&&e&&"message"in e?String(e.message):String(e);super(n);this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},qe=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},ue=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},ze=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},Xe=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},Ze=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},Ct=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},Lt=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},et=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}},tt=class extends Error{constructor(){super(...arguments);this.name="QuickJSPromisePending"}},rt=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmptyGetOwnPropertyNames"}},nt=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefRangeExceeded"}},C=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefInvalid"}};he=it;he.of=Ut;N=class{[Symbol.dispose](){return this.dispose()}},le=Symbol.dispose??Symbol.for("Symbol.dispose"),je=N.prototype;je[le]||(je[le]=function(){return this.dispose()});A=class e extends N{constructor(t,n,a,l){super();this._value=t,this.copier=n,this.disposer=a,this._owner=l,this._alive=!0,this._constructorStack=ce?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 e(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(t){this.assertAlive();let n=t(this);return this.dispose(),n}map(t){return this.assertAlive(),t(this)}tap(t){return t(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new ue(`Lifetime not alive
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The version of `@mcpcloud/runtime` COMPILED INTO this bundle.
3
+ *
4
+ * This exists because the platform previously had no way to ask a deployed
5
+ * server what it was actually running. `x-mcpcloud-runtime-version` and the
6
+ * dashboard's runtime badge are both read from `policy.runtimeVersion`, which
7
+ * Convex stamps at deploy time — a control-plane CLAIM about what should have
8
+ * shipped, never an observation of what did. When a deploy silently failed to
9
+ * replace a worker's script, every surface still reported the new version, and
10
+ * the obvious way to verify ("check the runtime version header") returned a
11
+ * false pass. That is not hypothetical: a staging server reported 0.14.0 while
12
+ * serving bytes older than 0.12.5, and had been drifting for several releases
13
+ * before anyone noticed.
14
+ *
15
+ * Because this constant travels INSIDE the bundle, it answers the different
16
+ * question: not "what did we intend to deploy?" but "what is running?".
17
+ * Comparing the two makes a failed-but-successful-looking deploy detectable.
18
+ */
19
+ export declare const RUNTIME_VERSION = "0.15.0";
package/dist/stdio.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @mcpcloud/runtime v0.14.0 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
1
+ /*! @mcpcloud/runtime v0.15.0 — (c) MCPCloud.sh. All rights reserved. SEE LICENSE: https://www.npmjs.com/package/@mcpcloud/runtime */
2
2
  var sg=Object.create;var{getPrototypeOf:ig,defineProperty:ga,getOwnPropertyNames:ag}=Object;var cg=Object.prototype.hasOwnProperty;function ug(e){return this[e]}var lg,dg,mg=(e,t,r)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?lg??=new WeakMap:dg??=new WeakMap,s=o.get(e);if(s)return s}r=e!=null?sg(ig(e)):{};let a=t||!e||!e.__esModule?ga(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let i of ag(e))if(!cg.call(a,i))ga(a,i,{get:ug.bind(e,i),enumerable:!0})}if(n)o.set(e,a);return a};var pg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var hg=(e)=>e;function fg(e,t){this[e]=hg.bind(null,t)}var Uo=(e,t)=>{for(var r in t)ga(e,r,{get:t[r],enumerable:!0,configurable:!0,set:fg.bind(t,r)})};var _a=(e,t)=>()=>(e&&(t=e(e=0)),t);var ir,Ku,la,ar,Ro;var da=_a(()=>{ir={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},Ku={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},la={Pending:0,Fulfilled:1,Rejected:2},ar={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},Ro={IsStrictlyEqual:0,IsSameValue:1,IsSameValueZero:2}});function zo(...e){Xu&&console.log("quickjs-emscripten:",...e)}function*Zf(e){return yield e}function mb(e){return Zf(tl(e))}function kf(e,t){return(...r)=>{let n=t.call(e,el,...r);return tl(n)}}function pb(e,t){let r=t.call(e,el);return tl(r)}function tl(e){function t(r){return r.done?r.value:r.value instanceof Promise?r.value.then((n)=>t(e.next(n)),(n)=>t(e.throw(n))):t(e.next(r.value))}return t(e.next())}function Bu(e,t){let r;try{e.dispose()}catch(n){r=n}if(t&&r)throw Object.assign(t,{message:`${t.message}
3
3
  Then, failed to dispose scope: ${r.message}`,disposeError:r}),t;if(t||r)throw t||r}function hb(e){let t=e?Array.from(e):[];function r(){return t.forEach((o)=>o.alive?o.dispose():void 0)}function n(){return t.some((o)=>o.alive)}return Object.defineProperty(t,Wu,{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"dispose",{configurable:!0,enumerable:!1,value:r}),Object.defineProperty(t,"alive",{configurable:!0,enumerable:!1,get:n}),t}function pa(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&("alive"in e)&&typeof e.alive=="boolean"&&("dispose"in e)&&typeof e.dispose=="function")}function Sb(e){if(!e)return 0;let t=0;for(let[r,n]of Object.entries(e)){if(!(r in Ku))throw new Lf(r);n&&(t|=Ku[r])}return t}function yb(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{type:t,strict:r,strip:n,compileOnly:o,backtraceBarrier:s}=e,a=0;return t==="global"&&(a|=ir.JS_EVAL_TYPE_GLOBAL),t==="module"&&(a|=ir.JS_EVAL_TYPE_MODULE),r&&(a|=ir.JS_EVAL_FLAG_STRICT),n&&(a|=ir.JS_EVAL_FLAG_STRIP),o&&(a|=ir.JS_EVAL_FLAG_COMPILE_ONLY),s&&(a|=ir.JS_EVAL_FLAG_BACKTRACE_BARRIER),a}function vb(e){if(typeof e=="number")return e;if(e===void 0)return 0;let{strings:t,symbols:r,quickjsPrivate:n,onlyEnumerable:o,numbers:s,numbersAsStrings:a}=e,i=0;return t&&(i|=ar.JS_GPN_STRING_MASK),r&&(i|=ar.JS_GPN_SYMBOL_MASK),n&&(i|=ar.JS_GPN_PRIVATE_MASK),o&&(i|=ar.JS_GPN_ENUM_ONLY),s&&(i|=ar.QTS_GPN_NUMBER_MASK),a&&(i|=ar.QTS_STANDARD_COMPLIANT_NUMBER),i}function bb(...e){let t=[];for(let r of e)r!==void 0&&(t=t.concat(r));return t}function Yu(e){return e>>8}function ol(e,t){t.interruptHandler&&e.setInterruptHandler(t.interruptHandler),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes)}function sl(e,t){t.moduleLoader&&e.setModuleLoader(t.moduleLoader),t.shouldInterrupt&&e.setInterruptHandler(t.shouldInterrupt),t.memoryLimitBytes!==void 0&&e.setMemoryLimit(t.memoryLimitBytes),t.maxStackSizeBytes!==void 0&&e.setMaxStackSize(t.maxStackSizeBytes)}var ab,cb=(e,t)=>{for(var r in t)ab(e,r,{get:t[r],enumerable:!0})},Xu=!1,ub,Gu,Af,Qu,jf,Mf,qf,lb,db,Lf,Df,Uf,Ff,Ft,el,bt,Wu,Of,Ye,cr,Cf,mt,rl,fb,gb,Yr,_b,Vf=class{constructor(e){this.module=e}toPointerArray(e){let t=new Int32Array(e.map((o)=>o.value)),r=t.length*t.BYTES_PER_ELEMENT,n=this.module._malloc(r);return new Uint8Array(this.module.HEAPU8.buffer,n,r).set(new Uint8Array(t.buffer)),new Ye(n,void 0,(o)=>this.module._free(o))}newTypedArray(e,t){let r=new e(Array(t).fill(0)),n=r.length*r.BYTES_PER_ELEMENT,o=this.module._malloc(n),s=new e(this.module.HEAPU8.buffer,o,t);return s.set(r),new Ye({typedArray:s,ptr:o},void 0,(a)=>this.module._free(a.ptr))}newMutablePointerArray(e){return this.newTypedArray(Int32Array,e)}newHeapCharPointer(e){let t=this.module.lengthBytesUTF8(e),r=t+1,n=this.module._malloc(r);return this.module.stringToUTF8(e,n,r),new Ye({ptr:n,strlen:t},void 0,(o)=>this.module._free(o.ptr))}newHeapBufferPointer(e){let t=e.byteLength,r=this.module._malloc(t);return this.module.HEAPU8.set(e,r),new Ye({pointer:r,numBytes:t},void 0,(n)=>this.module._free(n.pointer))}consumeHeapCharPointer(e){let t=this.module.UTF8ToString(e);return this.module._free(e),t}},Cw,Nw,Rb,Nf=-2147483648,xf=2147483647,ma=0,zb=class{constructor(){this.nextId=Nf,this.freelist=[],this.groups=new Map}put(e){let t=this.allocateId(),r=Yu(t),n=this.groups.get(r);return n||(n=new Map,this.groups.set(r,n)),n.set(t,e),t}get(e){if(e===ma)throw new Ft("no host reference id defined");let t=Yu(e),r=this.groups.get(t);if(!r)throw new Ft(`host reference id ${e} is not defined`);let n=r.get(e);if(!n)throw new Ft(`host reference id ${e} is not defined`);return n}delete(e){if(e===ma)throw new Ft("no host reference id defined");let t=Yu(e),r=this.groups.get(t);if(!r)throw new Ft(`host reference id ${e} is not defined`);r.delete(e),r.size===0&&this.groups.delete(t),this.freelist.push(e)}allocateId(){if(this.freelist.length>0)return this.freelist.shift();if(this.nextId===ma&&this.nextId++,this.nextId>xf)throw new Ff(`HostRefMap: too many host refs created without disposing. Max simultaneous host refs: ${xf-Nf}`);return this.nextId++}},If,wb,$b,Eb,Tb=class{constructor(e){this.freeHostRef=e.freeHostRef,this.callFunction=e.callFunction,this.shouldInterrupt=e.shouldInterrupt,this.loadModuleSource=e.loadModuleSource,this.normalizeModule=e.normalizeModule}},nl=class{constructor(e){this.contextCallbacks=new Map,this.runtimeCallbacks=new Map,this.suspendedCount=0,this.cToHostCallbacks=new Tb({freeHostRef:(t,r,n)=>{let o=this.runtimeCallbacks.get(r);if(!o)throw Error(`QuickJSRuntime(rt = ${r}) not found when trying to free HostRef(id = ${n})`);o.freeHostRef(r,n)},callFunction:(t,r,n,o,s,a)=>this.handleAsyncify(t,()=>{try{let i=this.contextCallbacks.get(r);if(!i)throw Error(`QuickJSContext(ctx = ${r}) not found for C function call "${a}"`);return i.callFunction(r,n,o,s,a)}catch(i){return console.error("[C to host error: returning null]",i),0}}),shouldInterrupt:(t,r)=>this.handleAsyncify(t,()=>{try{let n=this.runtimeCallbacks.get(r);if(!n)throw Error(`QuickJSRuntime(rt = ${r}) not found for C interrupt`);return n.shouldInterrupt(r)}catch(n){return console.error("[C to host interrupt: returning error]",n),1}}),loadModuleSource:(t,r,n,o)=>this.handleAsyncify(t,()=>{try{let s=this.runtimeCallbacks.get(r);if(!s)throw Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let a=s.loadModuleSource;if(!a)throw Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return a(r,n,o)}catch(s){return console.error("[C to host module loader error: returning null]",s),0}}),normalizeModule:(t,r,n,o,s)=>this.handleAsyncify(t,()=>{try{let a=this.runtimeCallbacks.get(r);if(!a)throw Error(`QuickJSRuntime(rt = ${r}) not found for C module loader`);let i=a.normalizeModule;if(!i)throw Error(`QuickJSRuntime(rt = ${r}) does not support module loading`);return i(r,n,o,s)}catch(a){return console.error("[C to host module loader error: returning null]",a),0}})}),this.module=e,this.module.callbacks=this.cToHostCallbacks}setRuntimeCallbacks(e,t){this.runtimeCallbacks.set(e,t)}deleteRuntime(e){this.runtimeCallbacks.delete(e)}setContextCallbacks(e,t){this.contextCallbacks.set(e,t)}deleteContext(e){this.contextCallbacks.delete(e)}handleAsyncify(e,t){if(e)return e.handleSleep((n)=>{try{let o=t();if(!(o instanceof Promise)){zo("asyncify.handleSleep: not suspending:",o),n(o);return}if(this.suspended)throw new Mf(`Already suspended at: ${this.suspended.stack}
4
4
  Attempted to suspend at:`);this.suspended=new qf(`(${this.suspendedCount++})`),zo("asyncify.handleSleep: suspending:",this.suspended),o.then((s)=>{this.suspended=void 0,zo("asyncify.handleSleep: resolved:",s),n(s)},(s)=>{zo("asyncify.handleSleep: rejected:",s),console.error("QuickJS: cannot handle error in suspended function",s),this.suspended=void 0})}catch(o){throw zo("asyncify.handleSleep: error:",o),this.suspended=void 0,o}});let r=t();if(r instanceof Promise)throw Error("Promise return value not supported in non-asyncify context.");return r}},Jf=class{constructor(e,t){this.module=e,this.ffi=t,this.callbacks=new nl(e)}newRuntime(e={}){let t=new Ye(this.ffi.QTS_NewRuntime(),void 0,(n)=>{this.ffi.QTS_FreeRuntime(n),this.callbacks.deleteRuntime(n)}),r=new Eb({module:this.module,callbacks:this.callbacks,ffi:this.ffi,rt:t});return ol(r,e),e.moduleLoader&&r.setModuleLoader(e.moduleLoader),r}newContext(e={}){let t=this.newRuntime(),r=t.newContext({...e,ownedLifetimes:bb(t,e.ownedLifetimes)});return t.context=r,r}evalCode(e,t={}){return mt.withScope((r)=>{let n=r.manage(this.newContext());sl(n.runtime,t);let o=n.evalCode(e,"eval.js");if(t.memoryLimitBytes!==void 0&&n.runtime.setMemoryLimit(-1),o.error)throw n.dump(r.manage(o.error));return n.dump(r.manage(o.value))})}getWasmMemory(){let e=this.module.quickjsEmscriptenInit?.(()=>{})?.getWasmMemory?.();if(!e)throw Error("Variant does not support getting WebAssembly.Memory");return e}getFFI(){return this.ffi}};var Hf=_a(()=>{da();da();ab=Object.defineProperty;ub={};cb(ub,{QuickJSAsyncifyError:()=>Mf,QuickJSAsyncifySuspended:()=>qf,QuickJSEmptyGetOwnPropertyNames:()=>Uf,QuickJSEmscriptenModuleError:()=>db,QuickJSHostRefInvalid:()=>Ft,QuickJSHostRefRangeExceeded:()=>Ff,QuickJSMemoryLeakDetected:()=>lb,QuickJSNotImplemented:()=>jf,QuickJSPromisePending:()=>Df,QuickJSUnknownIntrinsic:()=>Lf,QuickJSUnwrapError:()=>Gu,QuickJSUseAfterFree:()=>Qu,QuickJSWrongOwner:()=>Af});Gu=class extends Error{constructor(e,t){let r=typeof e=="object"&&e&&"message"in e?String(e.message):String(e);super(r);this.cause=e,this.context=t,this.name="QuickJSUnwrapError"}},Af=class extends Error{constructor(){super(...arguments);this.name="QuickJSWrongOwner"}},Qu=class extends Error{constructor(){super(...arguments);this.name="QuickJSUseAfterFree"}},jf=class extends Error{constructor(){super(...arguments);this.name="QuickJSNotImplemented"}},Mf=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifyError"}},qf=class extends Error{constructor(){super(...arguments);this.name="QuickJSAsyncifySuspended"}},lb=class extends Error{constructor(){super(...arguments);this.name="QuickJSMemoryLeakDetected"}},db=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmscriptenModuleError"}},Lf=class extends TypeError{constructor(){super(...arguments);this.name="QuickJSUnknownIntrinsic"}},Df=class extends Error{constructor(){super(...arguments);this.name="QuickJSPromisePending"}},Uf=class extends Error{constructor(){super(...arguments);this.name="QuickJSEmptyGetOwnPropertyNames"}},Ff=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefRangeExceeded"}},Ft=class extends Error{constructor(){super(...arguments);this.name="QuickJSHostRefInvalid"}};el=Zf;el.of=mb;bt=class{[Symbol.dispose](){return this.dispose()}},Wu=Symbol.dispose??Symbol.for("Symbol.dispose"),Of=bt.prototype;Of[Wu]||(Of[Wu]=function(){return this.dispose()});Ye=class e extends bt{constructor(t,r,n,o){super();this._value=t,this.copier=r,this.disposer=n,this._owner=o,this._alive=!0,this._constructorStack=Xu?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 e(this.copier(this._value),this.copier,this.disposer,this._owner)}consume(t){this.assertAlive();let r=t(this);return this.dispose(),r}map(t){return this.assertAlive(),t(this)}tap(t){return t(this),this}dispose(){this.assertAlive(),this.disposer&&this.disposer(this._value),this._alive=!1}assertAlive(){if(!this.alive)throw this._constructorStack?new Qu(`Lifetime not alive
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpcloud/runtime",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "MCPCloud generated-server runtime: transports, config, upstream auth/HTTP, validation, projection, and discovery for MCP servers built on MCPCloud.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",