@qoder-ai/qodercli 1.1.81 → 1.1.83
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/bundle/codemode-worker.mjs +4 -4
- package/bundle/qoder-worker-runtime.mjs +2 -2
- package/bundle/qodercli.js +2 -2
- package/package.json +7 -7
- package/postinstall.cjs +170 -142
- package/bundle/proto/chat.proto +0 -322
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{parentPort as $,workerData as qe}from"node:worker_threads";function le(a){return{clock_time_get(i,o,c){let u=a(),l=new DataView(u.buffer);if(i===0||i===1){let d=BigInt(Date.now())*1000000n;return l.setBigUint64(c,d,!0),0}return 52},fd_write(i,o,c,u){let l=a(),d=new DataView(l.buffer),h=new Uint8Array(l.buffer),w=0;if(i!==1&&i!==2)return 8;for(let g=0;g<c;g++){let _=d.getUint32(o+g*8,!0),I=d.getUint32(o+g*8+4,!0),O=h.slice(_,_+I),x=new TextDecoder().decode(O);i===1?typeof process<"u"&&process.stdout?process.stdout.write(x):console.log(x):typeof process<"u"&&process.stderr?process.stderr.write(x):console.error(x),w+=I}return d.setUint32(u,w,!0),0},fd_close(i){return 52},fd_fdstat_get(i,o){let c=a(),u=new DataView(c.buffer);return i===1||i===2?(u.setUint8(o,2),u.setUint16(o+2,0,!0),u.setBigUint64(o+8,0n,!0),u.setBigUint64(o+16,0n,!0),0):8},fd_seek(i,o,c,u){return 52},random_get(i,o){let c=a(),u=new Uint8Array(c.buffer,i,o);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(u);else for(let l=0;l<o;l++)u[l]=Math.floor(Math.random()*256);return 0}}}var be=new TextDecoder;function xe(a,e){let t=new Uint8Array(a.buffer),r=e;for(;t[r]!==0;)r++;if(r===e)return{};let s=be.decode(t.slice(e,r)),n={};for(let i of s.split(`
|
|
2
|
-
`)){let o=i.indexOf("=");o>0&&(n[i.slice(0,o)]=i.slice(o+1))}return n}function Se(a,e){let t=`qjs_ext_${a.name.replace(/-/g,"_")}_versions`,r=a.instance.exports[t];if(typeof r!="function")return;let s=r();if(s!==0)return xe(e,s)}function M(a,e){let t=0,r=0;for(;e.value<a.length;){let s=a[e.value++];if(t|=(s&127)<<r,(s&128)===0)break;r+=7}return t}function Ee(a){let e=WebAssembly.Module.customSections(a,"dylink.0");if(e.length===0)return null;let t=new Uint8Array(e[0]),r={value:0},s={memorySize:0,memoryAlignment:0,tableSize:0,tableAlignment:0,needed:[]};for(;r.value<t.length;){let n=M(t,r),i=M(t,r),o=r.value+i;if(n===1)s.memorySize=M(t,r),s.memoryAlignment=M(t,r),s.tableSize=M(t,r),s.tableAlignment=M(t,r);else if(n===2){let c=M(t,r);for(let u=0;u<c;u++){let l=M(t,r),d=new TextDecoder().decode(t.slice(r.value,r.value+l));r.value+=l,s.needed.push(d)}}r.value=o}return s}async function Z(a,e,t,r,s,n){let i;a.wasm instanceof WebAssembly.Module?i=a.wasm:i=await WebAssembly.compile(a.wasm);let o=Ee(i);if(!o)throw new Error(`Extension "${a.name}" is not a WASM shared library (missing dylink.0 section)`);let c=e.memory,u=e.__indirect_function_table,l=e.__stack_pointer,d=e.malloc;if(!c)throw new Error("Main module does not export memory");if(!u)throw new Error("Main module does not export __indirect_function_table");if(!d)throw new Error("Main module does not export malloc");let h,w;if(n)h=n.memoryBase,w=n.tableBase;else if(o.memorySize>0){if(h=d(o.memorySize),h===0)throw new Error(`Failed to allocate ${o.memorySize} bytes for extension "${a.name}"`);new Uint8Array(c.buffer,h,o.memorySize).fill(0)}else h=0;n?(w=n.tableBase,w+o.tableSize>u.length&&u.grow(w+o.tableSize-u.length)):(w=u.length,o.tableSize>0&&u.grow(o.tableSize));let g=WebAssembly.Module.imports(i),_={env:{},"GOT.mem":{},"GOT.func":{}};if(g.some(f=>f.module==="wasi_snapshot_preview1")){let f=a.wasi&&s?a.wasi(s):void 0;_.wasi_snapshot_preview1={...t,...f,...r}}let O=new Set(WebAssembly.Module.exports(i).filter(f=>f.kind==="function").map(f=>f.name)),x=new Set;for(let f of g)if(f.module==="env"){if(f.name==="memory"&&f.kind==="memory")_.env.memory=c;else if(f.name==="__indirect_function_table"&&f.kind==="table")_.env.__indirect_function_table=u;else if(f.name==="__memory_base"&&f.kind==="global")_.env.__memory_base=new WebAssembly.Global({value:"i32",mutable:!1},h);else if(f.name==="__table_base"&&f.kind==="global")_.env.__table_base=new WebAssembly.Global({value:"i32",mutable:!1},w);else if(f.name==="__stack_pointer"&&f.kind==="global")_.env.__stack_pointer=l;else if(f.kind==="function"){let P=e[f.name];P&&typeof P=="function"?_.env[f.name]=P:(x.add(f.name),_.env[f.name]=()=>{throw new Error(`Extension "${a.name}" called unresolved symbol: env.${f.name}`)})}else if(f.kind==="global"){let P=e[f.name];P instanceof WebAssembly.Global?_.env[f.name]=P:_.env[f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0)}}else if(f.module==="GOT.mem"&&f.kind==="global")_["GOT.mem"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0);else if(f.module==="GOT.func"&&f.kind==="global"){let P=e[f.name];if(P&&typeof P=="function"){let L=u.length;u.grow(1),u.set(L,P),_["GOT.func"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},L)}else _["GOT.func"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0)}let E=[...x].filter(f=>O.has(f)),v={};for(let f of E){let P={target:null};v[f]=P,_.env[f]=(...L)=>{if(!P.target)throw new Error(`Extension "${a.name}" called unresolved symbol during init: env.${f}`);return P.target(...L)}}let S=await WebAssembly.instantiate(i,_),k=S.exports;for(let f of E){let P=k[f];typeof P=="function"&&(v[f].target=P)}typeof k.__wasm_apply_data_relocs=="function"&&k.__wasm_apply_data_relocs(),typeof k.__wasm_call_ctors=="function"&&k.__wasm_call_ctors();let B=a.initFn??`qjs_ext_${a.name.replace(/-/g,"_")}_init`,y={name:a.name,module:i,instance:S,dylink:o,memoryBase:h,tableBase:w,initFn:B};return y.versions=Se(y,c),y}function ce(a,e){let t=a.instance.exports[a.initFn];if(typeof t!="function")throw new Error(`Extension "${a.name}" does not export init function "${a.initFn}"`);let r=e.qjs_get_context_ptr(),s=e.qjs_get_runtime_ptr(),n=t(r,s);if(n!==0)throw new Error(`Extension "${a.name}" init function returned error code ${n}`)}async function ue(a,e,t,r,s,n){let i=[];for(let o of e){let c=a.find(l=>l.name===o.name);if(!c)throw new Error(`Extension "${o.name}" required by snapshot but not provided`);let u=await Z(c,t,r,s,n,{memoryBase:o.memoryBase,tableBase:o.tableBase});u.initFn=o.initFn,i.push(u)}return i}var pe="3.6.2";var H=function(a,e,t){if(e!=null){if(typeof e!="object"&&typeof e!="function")throw new TypeError("Object expected.");var r,s;if(t){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=e[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=e[Symbol.dispose],t&&(s=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");s&&(r=function(){try{s.call(this)}catch(n){return Promise.reject(n)}}),a.stack.push({value:e,dispose:r,async:t})}else t&&a.stack.push({async:!0});return e},F=function(a){return function(e){function t(i){e.error=e.hasError?new a(i,e.error,"An error was suppressed during disposal."):i,e.hasError=!0}var r,s=0;function n(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(n);if(r.dispose){var i=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(i).then(n,function(o){return t(o),n()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return n()}}(typeof SuppressedError=="function"?SuppressedError:function(a,e,t){var r=new Error(t);return r.name="SuppressedError",r.error=a,r.suppressed=e,r}),G=512*1024;var ee=1363825491,te=2,V=24,Y=class a{exports;module;instance;encoder=new TextEncoder;decoder=new TextDecoder;disposed=!1;hostCallbacks=new Map;nextInternalId=1;interruptHandler=null;unhandledRejectionHandler=null;moduleNormalizeHandler=null;moduleLoadHandler=null;timezoneOffsetHandler=null;_global=null;_versions=null;_undefined=null;_null=null;_true=null;_false=null;_ownedHandles=new Set;_activeScope=null;loadedExtensions=[];constructor(e){this.module=e,this.instance=null,this.exports=null}setInstance(e){this.instance=e,this.exports=e.exports}get versions(){if(this.assertNotDisposed(),!this._versions){let e={"quickjs-wasi":pe,quickjs:this.readCString(this.exports.qjs_get_quickjs_version())};for(let t of this.loadedExtensions)t.versions&&Object.assign(e,t.versions);this._versions=e}return this._versions}get global(){return this._global||(this._global=new m(this,this.exports.qjs_get_global(),!0)),this._global}get undefined(){return this._undefined||(this._undefined=new m(this,this.exports.qjs_get_undefined(),!0)),this._undefined}get null(){return this._null||(this._null=new m(this,this.exports.qjs_get_null(),!0)),this._null}get true(){return this._true||(this._true=new m(this,this.exports.qjs_get_true(),!0)),this._true}get false(){return this._false||(this._false=new m(this,this.exports.qjs_get_false(),!0)),this._false}static async create(e){let t=a.normalizeOptions(e),r=await a.resolveModule(t.wasm),s=new a(r),{instance:n,wasiBuiltins:i,wasiUserOverrides:o,memoryProxy:c}=await a.instantiate(r,s,t.wasi);if(s.setInstance(n),s.exports._initialize(),(t.intrinsics!==void 0?s.exports.qjs_init2(t.intrinsics):s.exports.qjs_init())!==0)throw new Error("Failed to initialize QuickJS runtime");if(t.extensions){let l=n.exports;for(let d of t.extensions){let h=await Z(d,l,i,o,c);s.loadedExtensions.push(h),ce(h,l)}}return a.applyLimits(s,t),s}static async restore(e,t){let r=a.normalizeOptions(t),s=await a.resolveModule(r.wasm),n=new a(s),{instance:i,wasiBuiltins:o,wasiUserOverrides:c,memoryProxy:u}=await a.instantiate(s,n,r.wasi);n.setInstance(i);let l=i.exports,d=n.exports.memory,h=d.buffer.byteLength/65536,w=Math.ceil(e.memory.byteLength/65536);if(w>h&&d.grow(w-h),e.extensions.length>0){let _=r.extensions??[];n.loadedExtensions=await ue(_,e.extensions,l,o,c,u)}return new Uint8Array(d.buffer).set(e.memory),n.exports.qjs_set_runtime_and_context(e.runtimePtr,e.contextPtr),n.exports.__stack_pointer.value=e.stackPointer,a.applyLimits(n,r),n}static serializeSnapshot(e){let t=new TextEncoder,r=4,s=[],n=[];for(let d of e.extensions){let h=t.encode(d.name),w=t.encode(d.initFn);s.push(h),n.push(w),r+=4+h.length+4+4+4+w.length}let i=V+r+e.memory.byteLength,o=new ArrayBuffer(i),c=new DataView(o),u=new Uint8Array(o);c.setUint32(0,ee,!1),c.setUint8(4,te),c.setUint32(8,e.memory.byteLength,!0),c.setUint32(12,e.stackPointer,!0),c.setUint32(16,e.runtimePtr,!0),c.setUint32(20,e.contextPtr,!0);let l=V;c.setUint32(l,e.extensions.length,!0),l+=4;for(let d=0;d<e.extensions.length;d++){let h=e.extensions[d],w=s[d],g=n[d];c.setUint32(l,w.length,!0),l+=4,u.set(w,l),l+=w.length,c.setUint32(l,h.memoryBase,!0),l+=4,c.setUint32(l,h.tableBase,!0),l+=4,c.setUint32(l,g.length,!0),l+=4,u.set(g,l),l+=g.length}return u.set(e.memory,l),u}static deserializeSnapshot(e){if(e.length<V)throw new Error("Invalid snapshot: too small");let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t.getUint32(0,!1);if(r!==ee)throw new Error(`Invalid snapshot: bad magic (expected 0x${ee.toString(16)}, got 0x${r.toString(16)})`);let s=t.getUint8(4);if(s!==te&&s!==1)throw new Error(`Unsupported snapshot version: ${s} (expected ${te})`);let n=t.getUint32(8,!0),i=t.getUint32(12,!0),o=t.getUint32(16,!0),c=t.getUint32(20,!0),u=[],l=V;if(s>=2){let w=t.getUint32(24,!0),g=28,_=new TextDecoder;for(let I=0;I<w;I++){let O=t.getUint32(g,!0);g+=4;let x=_.decode(e.slice(g,g+O));g+=O;let E=t.getUint32(g,!0);g+=4;let v=t.getUint32(g,!0);g+=4;let S=t.getUint32(g,!0);g+=4;let k=_.decode(e.slice(g,g+S));g+=S,u.push({name:x,memoryBase:E,tableBase:v,initFn:k})}l=g}let d=l+n;if(e.length<d)throw new Error(`Invalid snapshot: expected ${d} bytes, got ${e.length}`);return{memory:e.slice(l,l+n),stackPointer:i,runtimePtr:o,contextPtr:c,extensions:u}}static normalizeOptions(e){if(!e)return{wasm:void 0};if(e instanceof WebAssembly.Module)return{wasm:e};if(typeof e=="object"&&("wasm"in e||"wasi"in e||"memoryLimit"in e||"maxStackSize"in e||"interruptHandler"in e||"onUnhandledRejection"in e||"moduleLoader"in e||"intrinsics"in e||"extensions"in e||"timezoneOffset"in e)){let t=e;if(t.maxStackSize!==void 0&&(!Number.isInteger(t.maxStackSize)||t.maxStackSize<0||t.maxStackSize>G))throw new RangeError(`maxStackSize must be an integer between 0 and ${G}`);return t}return{wasm:e}}static applyLimits(e,t){t.memoryLimit!==void 0&&e.exports.qjs_set_memory_limit(t.memoryLimit),t.maxStackSize!==void 0&&e.exports.qjs_set_max_stack_size(t.maxStackSize),t.interruptHandler&&(e.interruptHandler=t.interruptHandler,e.exports.qjs_set_interrupt_handler(1)),t.onUnhandledRejection&&(e.unhandledRejectionHandler=t.onUnhandledRejection,e.exports.qjs_set_promise_rejection_handler(1)),t.moduleLoader&&(e.moduleLoadHandler=t.moduleLoader.load,e.moduleNormalizeHandler=t.moduleLoader.normalize??null,e.exports.qjs_set_module_loader(1));let r=t.timezoneOffset;if(typeof r=="function")e.timezoneOffsetHandler=s=>-r(s)*60;else if(typeof r=="number"){let s=-r*60;e.timezoneOffsetHandler=()=>s}else e.timezoneOffsetHandler=s=>-new Date(s*1e3).getTimezoneOffset()*60}static async resolveModule(e){if(e instanceof WebAssembly.Module)return e;if(e)return WebAssembly.compile(e);throw new TypeError("QuickJS: `wasm` option is required. Provide WASM bytes or a compiled `WebAssembly.Module`. The binary is shipped at `quickjs-wasi/quickjs.wasm` and can be loaded via your environment's preferred mechanism (e.g. `fetch()`, `node:fs/promises`, or a bundler import like Vite's `?url`).")}static async instantiate(e,t,r){let s=null,n=new Proxy({},{get(x,E){return s[E]}}),i=le(()=>s),o=r?r(n):void 0,c={...i,...o},u=(x,E,v,S,k)=>t.handleHostCall(x,E,v,S,k),l=()=>t.interruptHandler&&t.interruptHandler()?1:0,d=(x,E,v)=>{if(!t.unhandledRejectionHandler){t.exports.qjs_free_value(x),t.exports.qjs_free_value(E);return}let S=new m(t,x),k=new m(t,E);try{t.unhandledRejectionHandler(S,k,v!==0)}finally{S.dispose(),k.dispose()}},h=x=>{let E=t.newError(x instanceof Error?x:String(x));t.exports.qjs_throw(E.ptr),E.dispose()},w=(x,E)=>{if(typeof x=="string")return x;let v=x!==null&&typeof x=="object"&&typeof x.then=="function"?"a Promise":`type ${typeof x}`;throw new TypeError(`moduleLoader.${E} must synchronously return a string (got ${v}). Async module loading is not supported. Pre-fetch module sources instead (see the "ES Modules" section of the quickjs-wasi README).`)},g=(x,E)=>{if(!t.moduleNormalizeHandler){let k=t.readCString(E);return t.writeString(k).ptr}let v=t.readCString(x),S=t.readCString(E);try{let k=w(t.moduleNormalizeHandler(v,S),"normalize");return t.writeString(k).ptr}catch(k){return h(k),0}},_=(x,E)=>{if(!t.moduleLoadHandler)return 0;let v=t.readCString(x);try{let S=w(t.moduleLoadHandler(v),"load"),{ptr:k,len:B}=t.writeString(S);return new Uint32Array(t.exports.memory.buffer,E,1)[0]=B,k}catch(S){return h(S),0}},I=(x,E)=>{let v=Number(BigInt(x)<<32n|BigInt(E>>>0));return t.timezoneOffsetHandler?t.timezoneOffsetHandler(v):0},O=await WebAssembly.instantiate(e,{env:{host_call:u,host_interrupt:l,host_promise_rejection:d,host_module_normalize:g,host_module_load:_,host_get_timezone_offset:I},wasi_snapshot_preview1:c});return s=O.exports.memory,{instance:O,wasiBuiltins:i,wasiUserOverrides:o,memoryProxy:n}}handleHostCall(e,t,r,s,n){let i=this.decoder.decode(new Uint8Array(this.exports.memory.buffer,e,t)),o=this.hostCallbacks.get(i);if(!o){let l=this.newError(`Host callback "${i}" is not registered: it was unregistered, its ephemeral function handle was disposed, or it was never re-registered after a snapshot restore.`);return this.exports.qjs_throw(l.ptr),l.dispose(),0}let c=new m(this,r,!1,!0),u=[];if(s>0&&n!==0){let l=new DataView(this.exports.memory.buffer);for(let d=0;d<s;d++){let h=l.getUint32(n+d*4,!0);u.push(new m(this,h,!1,!0))}}try{let l=o.call(c,...u);return this.exports.qjs_dup_value(l.ptr)}catch(l){let d=this.newError(l instanceof Error?l:String(l));return this.exports.qjs_throw(d.ptr),d.dispose(),0}}writeString(e){let t=ke(e),r=this.exports.wasm_malloc(t.length+1);if(r===0)throw new Error("wasm_malloc failed");let s=new Uint8Array(this.exports.memory.buffer);return s.set(t,r),s[r+t.length]=0,{ptr:r,len:t.length}}readCString(e){let t=new Uint8Array(this.exports.memory.buffer),r=e;for(;t[r]!==0;)r++;return this.decoder.decode(t.slice(e,r))}throwIfException(e){if(this.exports.qjs_is_exception(e.ptr)!==0){let t=this.getException();throw e.dispose(),this._ownedHandles.add(t),new R(t)}return e}evalCode(e,t="<eval>",r=0){this.assertNotDisposed();let s=this.writeString(e),n=this.writeString(t),i=this.exports.qjs_eval(s.ptr,s.len,n.ptr,r);return this.exports.wasm_free(s.ptr),this.exports.wasm_free(n.ptr),this.throwIfException(new m(this,i))}compile(e,t="<compile>",r=0,s=0){this.assertNotDisposed();let n=this.writeString(e),i=this.writeString(t),o=this.exports.wasm_malloc(4),c=this.exports.qjs_compile(n.ptr,n.len,i.ptr,r,s,o);if(this.exports.wasm_free(n.ptr),this.exports.wasm_free(i.ptr),c===0){this.exports.wasm_free(o);let d=this.getException();throw new Error(`Compilation error: ${d.toString()}`)}let u=new Uint32Array(this.exports.memory.buffer,o,1)[0];this.exports.wasm_free(o);let l=new Uint8Array(this.exports.memory.buffer,c,u).slice();return this.exports.wasm_free(c),l}evalBytecode(e){this.assertNotDisposed();let t=this.exports.wasm_malloc(e.byteLength);new Uint8Array(this.exports.memory.buffer,t,e.byteLength).set(e);let r=this.exports.qjs_eval_bytecode(t,e.byteLength);return this.exports.wasm_free(t),this.throwIfException(new m(this,r))}executePendingJobs(){this.assertNotDisposed();let e=0;for(;this.exports.qjs_is_job_pending();){if(this.exports.qjs_execute_pending_job()<0){let r=this.getException();throw new Error(`Job execution error: ${r.toString()}`)}e++}return e}runGC(){this.assertNotDisposed(),this.exports.qjs_run_gc()}get gcThreshold(){return this.assertNotDisposed(),this.exports.qjs_get_gc_threshold()}set gcThreshold(e){this.assertNotDisposed(),this.exports.qjs_set_gc_threshold(e)}getMemoryUsage(){this.assertNotDisposed();let e=this.exports.wasm_malloc(26*8);this.exports.qjs_compute_memory_usage(e);let t=new BigInt64Array(this.exports.memory.buffer,e,26),r={mallocSize:Number(t[0]),mallocLimit:Number(t[1]),memoryUsedSize:Number(t[2]),mallocCount:Number(t[3]),memoryUsedCount:Number(t[4]),atomCount:Number(t[5]),atomSize:Number(t[6]),strCount:Number(t[7]),strSize:Number(t[8]),objCount:Number(t[9]),objSize:Number(t[10]),propCount:Number(t[11]),propSize:Number(t[12]),shapeCount:Number(t[13]),shapeSize:Number(t[14]),jsFuncCount:Number(t[15]),jsFuncSize:Number(t[16]),jsFuncCodeSize:Number(t[17]),jsFuncPc2lineCount:Number(t[18]),jsFuncPc2lineSize:Number(t[19]),cFuncCount:Number(t[20]),arrayCount:Number(t[21]),fastArrayCount:Number(t[22]),fastArrayElements:Number(t[23]),binaryObjectCount:Number(t[24]),binaryObjectSize:Number(t[25])};return this.exports.wasm_free(e),r}getGlobal(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_global())}newString(e){this.assertNotDisposed();let{ptr:t,len:r}=this.writeString(e),s=this.exports.qjs_new_string(t,r);return this.exports.wasm_free(t),new m(this,s)}newNumber(e){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_number(e))}newBigInt(e){this.assertNotDisposed();let t=Number(e&0xffffffffn),r=Number(e>>32n&0xffffffffn);return new m(this,this.exports.qjs_new_big_int64(t,r))}newObject(){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_object())}newArray(){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_array())}newSymbolFor(e){this.assertNotDisposed();let{ptr:t,len:r}=this.writeString(e),s=new m(this,this.exports.qjs_new_symbol(t,r,1));return this.exports.wasm_free(t),s}newArrayBuffer(e){this.assertNotDisposed();let t=e instanceof ArrayBuffer?new Uint8Array(e):e,r=this.exports.wasm_malloc(t.length);if(r===0)throw new Error("wasm_malloc failed");new Uint8Array(this.exports.memory.buffer).set(t,r);let s=new m(this,this.exports.qjs_new_array_buffer(r,t.length));return this.exports.wasm_free(r),s}newUint8Array(e){this.assertNotDisposed();let t=this.exports.wasm_malloc(e.length);if(t===0)throw new Error("wasm_malloc failed");new Uint8Array(this.exports.memory.buffer).set(e,t);let r=new m(this,this.exports.qjs_new_uint8_array(t,e.length));return this.exports.wasm_free(t),r}getUndefined(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_undefined())}getNull(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_null())}getTrue(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_true())}getFalse(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_false())}newFunction(e,t){if(this.assertNotDisposed(),this.hostCallbacks.has(e))throw new Error(`Host callback with name "${e}" is already registered`);this.hostCallbacks.set(e,t);let{ptr:r,len:s}=this.writeString(e),n=this.exports.qjs_new_host_function(r,s,0);return this.exports.wasm_free(r),new m(this,n)}withScope(e){this.assertNotDisposed();let t=this._activeScope,r=new Set;this._activeScope=r;let s={escape:n=>(r.delete(n),t?.add(n),n)};try{return e(s)}finally{this._activeScope=t;for(let n of r)n.dispose()}}exportHandle(e){if(this.assertNotDisposed(),e.vm!==this)throw new Error("exportHandle: handle belongs to a different VM");if(e.disposed)throw new Error("exportHandle: handle is disposed");if(e._isBorrowed)throw new Error("exportHandle: cannot export a borrowed handle (host-callback this/argument); its box is freed when the callback returns. dup() it and export the duplicate.");return e.ptr}importHandle(e){if(this.assertNotDisposed(),!Number.isInteger(e)||e<=0||e>=this.exports.memory.buffer.byteLength)throw new Error(`importHandle: invalid token ${e}`);return new m(this,this.exports.qjs_dup_value(e))}newEphemeralFunction(e){this.assertNotDisposed();let t=`__ephemeral:${this.nextInternalId++}`;this.hostCallbacks.set(t,e);let{ptr:r,len:s}=this.writeString(t),n=this.exports.qjs_new_host_function(r,s,0);this.exports.wasm_free(r);let i=new m(this,n);return i._onDispose=()=>{this.hostCallbacks.delete(t)},i}unregisterHostCallback(e){return this.hostCallbacks.delete(e)}newInternalFunction(e,t){this.hostCallbacks.set(e,t);let{ptr:r,len:s}=this.writeString(e),n=this.exports.qjs_new_host_function(r,s,0);return this.exports.wasm_free(r),new m(this,n)}newPromise(){this.assertNotDisposed();let e=this.exports.wasm_malloc(4),t=this.exports.wasm_malloc(4),r=this.exports.qjs_new_promise(e,t),s=new DataView(this.exports.memory.buffer),n=s.getUint32(e,!0),i=s.getUint32(t,!0);this.exports.wasm_free(e),this.exports.wasm_free(t);let o=new m(this,r),c=new m(this,n),u=new m(this,i),l=this;l._ownedHandles.add(c),l._ownedHandles.add(u);let d=null;return{handle:o,get settled(){if(!d){let h;d=new Promise(_=>{h=_});let w=`__settle:${l.nextInternalId++}`,g=l.newInternalFunction(w,()=>(h(),l.hostCallbacks.delete(w),l.undefined));l.promiseThenRaw(o,g,g).dispose(),g.dispose()}return d},resolve(h){l.callFunctionRaw(c,l.undefined,h).dispose(),l._ownedHandles.delete(c),c.dispose()},reject(h){l.callFunctionRaw(u,l.undefined,h).dispose(),l._ownedHandles.delete(u),u.dispose()}}}resolvePromise(e){if(this.assertNotDisposed(),!this.exports.qjs_is_promise(e.ptr))return Promise.resolve({value:e.dup()});let t=this.exports.qjs_promise_state(e.ptr);return t===1?Promise.resolve({value:new m(this,this.exports.qjs_promise_result(e.ptr))}):t===2?Promise.resolve({error:new m(this,this.exports.qjs_promise_result(e.ptr))}):new Promise(r=>{let s=this.nextInternalId++,n=`__onFulfilled:${s}`,i=`__onRejected:${s}`,o=this.newInternalFunction(n,(...u)=>{let l=u[0]?.dup()??this.undefined;return this.hostCallbacks.delete(n),this.hostCallbacks.delete(i),r({value:l}),this.undefined}),c=this.newInternalFunction(i,(...u)=>{let l=u[0]?.dup()??this.undefined;return this.hostCallbacks.delete(n),this.hostCallbacks.delete(i),r({error:l}),this.undefined});this.promiseThenRaw(e,o,c).dispose(),o.dispose(),c.dispose()})}promiseThenRaw(e,t,r){return new m(this,this.exports.qjs_promise_then(e.ptr,t.ptr,r.ptr))}markPromiseHandled(e){this.assertNotDisposed(),this.exports.qjs_promise_mark_as_handled(e.ptr)}callFunction(e,t,...r){return this.throwIfException(this.callFunctionRaw(e,t,...r))}construct(e,...t){this.assertNotDisposed();let r=t.length,s=0;if(r>0){s=this.exports.wasm_malloc(r*4);let i=new DataView(this.exports.memory.buffer);for(let o=0;o<r;o++)i.setUint32(s+o*4,t[o].ptr,!0)}let n=this.exports.qjs_call_constructor(e.ptr,r,s);return s&&this.exports.wasm_free(s),this.throwIfException(new m(this,n))}callFunctionRaw(e,t,...r){this.assertNotDisposed();let s=r.length,n=0;if(s>0){n=this.exports.wasm_malloc(s*4);let o=new DataView(this.exports.memory.buffer);for(let c=0;c<s;c++)o.setUint32(n+c*4,r[c].ptr,!0)}let i=this.exports.qjs_call(e.ptr,t.ptr,s,n);return n&&this.exports.wasm_free(n),new m(this,i)}setProp(e,t,r){if(this.assertNotDisposed(),typeof t=="string"){let{ptr:s}=this.writeString(t);this.exports.qjs_set_prop_string(e.ptr,s,r.ptr),this.exports.wasm_free(s)}else this.exports.qjs_set_prop_value(e.ptr,t.ptr,r.ptr)}defineProp(e,t,r,s){this.assertNotDisposed();let n=0;if(s?.configurable&&(n|=1),s?.writable&&(n|=2),s?.enumerable&&(n|=4),typeof t=="string"){let{ptr:i}=this.writeString(t);this.exports.qjs_define_prop_string(e.ptr,i,r.ptr,n),this.exports.wasm_free(i)}else this.exports.qjs_define_prop_value(e.ptr,t.ptr,r.ptr,n)}getProp(e,t){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_prop_value(e.ptr,t.ptr))}getException(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_exception())}newError(e){this.assertNotDisposed();let t=this.exports.qjs_new_error(),r=new m(this,t);if(typeof e=="string"){let s=this.newString(e);r.setProp("message",s),s.dispose()}else{let s=this.newString(e.message);if(r.setProp("message",s),s.dispose(),e.name){let n=this.newString(e.name);r.setProp("name",n),n.dispose()}if(e.stack){let n=this.newString(e.stack);r.setProp("stack",n),n.dispose()}}return r}typeof(e){this.assertNotDisposed();let t=this.exports;return t.qjs_is_undefined(e.ptr)?"undefined":t.qjs_is_null(e.ptr)?"object":t.qjs_is_bool(e.ptr)?"boolean":t.qjs_is_number(e.ptr)?"number":t.qjs_is_big_int(e.ptr)?"bigint":t.qjs_is_string(e.ptr)?"string":t.qjs_is_symbol(e.ptr)?"symbol":t.qjs_is_function(e.ptr)?"function":t.qjs_is_object(e.ptr)?"object":"unknown"}dump(e){return this.assertNotDisposed(),this._dump(e,new Map)}_dump(e,t){let r=this.exports;if(!r.qjs_is_undefined(e.ptr)){if(r.qjs_is_null(e.ptr))return null;if(r.qjs_is_bool(e.ptr))return r.qjs_get_bool(e.ptr)!==0;if(r.qjs_is_number(e.ptr))return r.qjs_get_float64(e.ptr);if(r.qjs_is_string(e.ptr))return e.toString();if(r.qjs_is_big_int(e.ptr))return e.toBigInt();if(r.qjs_is_symbol(e.ptr)){let s=r.wasm_malloc(4),n=r.qjs_get_symbol_description(e.ptr,s),o=new DataView(r.memory.buffer).getUint32(s,!0);if(r.wasm_free(s),n===1){let c=new m(this,o),u=c.toString();return c.dispose(),Symbol.for(u)}else if(n===2){new m(this,o).dispose();return}return}if(r.qjs_is_array_buffer(e.ptr))return e.toArrayBuffer();if(r.qjs_is_exception(e.ptr)){let s=this.getException(),n=s.toString();return s.dispose(),new Error(n)}if(!r.qjs_is_function(e.ptr)){if(r.qjs_is_object(e.ptr)){let s=r.qjs_get_value_ptr(e.ptr);if(s){let n=t.get(s);if(n!==void 0)return n}}if(r.qjs_is_object(e.ptr)){let s=r.wasm_malloc(4),n=r.wasm_malloc(4),i=r.wasm_malloc(4),o=r.qjs_get_typed_array_buffer(e.ptr,s,n,i),c=new m(this,o);if(r.qjs_is_exception(c.ptr)===0){let u=new DataView(r.memory.buffer),l=u.getUint32(s,!0),d=u.getUint32(n,!0),h=u.getUint32(i,!0);r.wasm_free(s),r.wasm_free(n),r.wasm_free(i);let w=r.wasm_malloc(4),g=r.qjs_get_array_buffer(c.ptr,w);if(r.wasm_free(w),c.dispose(),g!==0){let _=new Uint8Array(r.memory.buffer,g+l,d).slice();switch(h){case 1:return _;case 2:return new Uint16Array(_.buffer);case 4:return new Uint32Array(_.buffer);case 8:return new Float64Array(_.buffer);default:return _}}}else c.dispose(),r.wasm_free(s),r.wasm_free(n),r.wasm_free(i)}if(r.qjs_is_array(e.ptr)){let s=e.getProp("length"),n=r.qjs_get_float64(s.ptr);s.dispose();let i=[],o=r.qjs_get_value_ptr(e.ptr);o&&t.set(o,i);for(let c=0;c<n;c++){let u=r.qjs_get_prop_uint32(e.ptr,c),l=new m(this,u);i.push(this._dump(l,t)),l.dispose()}return i}if(r.qjs_is_error(e.ptr)){let s=e.getProp("name"),n=e.getProp("message"),i=e.getProp("stack"),o=s.isUndefined?"Error":s.toString(),c=n.isUndefined?"":n.toString(),u=i.isUndefined?void 0:i.toString();s.dispose(),n.dispose(),i.dispose();let l=new Error(c);return l.name=o,u!==void 0&&(l.stack=u),l}if(r.qjs_is_object(e.ptr)){let s=r.qjs_get_own_property_names(e.ptr),n=new m(this,s);if(r.qjs_is_exception(n.ptr)!==0)return n.dispose(),{};let i=n.getProp("length"),o=r.qjs_get_float64(i.ptr);i.dispose();let c={},u=r.qjs_get_value_ptr(e.ptr);u&&t.set(u,c);for(let l=0;l<o;l++){let d=r.qjs_get_prop_uint32(n.ptr,l),h=new m(this,d),w=h.toString();h.dispose();let g=e.getProp(w);c[w]=this._dump(g,t),g.dispose()}return n.dispose(),c}}}}hostToHandle(e){if(this.assertNotDisposed(),e===void 0)return this.undefined;if(e===null)return this.null;if(e===!0)return this.true;if(e===!1)return this.false;if(typeof e=="number")return this.newNumber(e);if(typeof e=="string")return this.newString(e);if(typeof e=="bigint")return this.newBigInt(e);if(typeof e=="symbol"){let t=Symbol.keyFor(e);if(t!==void 0)return this.newSymbolFor(t);throw new Error("Cannot convert local symbol to QuickJS handle. Use Symbol.for() for cross-boundary symbols.")}if(e instanceof Promise){let t=this.newPromise();return e.then(r=>{t.resolve(this.hostToHandle(r)),this.executePendingJobs()},r=>{t.reject(this.hostToHandle(r)),this.executePendingJobs()}),t.handle}if(e instanceof Error)return this.newError(e);if(e instanceof ArrayBuffer)return this.newArrayBuffer(e);if(e instanceof Uint8Array)return this.newUint8Array(e);if(ArrayBuffer.isView(e))return this.newArrayBuffer(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));if(Array.isArray(e)){let t=this.newArray();for(let r=0;r<e.length;r++){let s=this.hostToHandle(e[r]);this.exports.qjs_set_prop_uint32(t.ptr,r,s.ptr),s.dispose()}return t}if(typeof e=="object"&&e!==null){let t=this.newObject();for(let[r,s]of Object.entries(e)){let n=this.hostToHandle(s);t.setProp(r,n),n.dispose()}return t}return this.undefined}snapshot(){return this.assertNotDisposed(),{memory:new Uint8Array(this.exports.memory.buffer).slice(),stackPointer:this.exports.__stack_pointer.value,runtimePtr:this.exports.qjs_get_runtime_ptr(),contextPtr:this.exports.qjs_get_context_ptr(),extensions:this.loadedExtensions.map(e=>({name:e.name,memoryBase:e.memoryBase,tableBase:e.tableBase,initFn:e.initFn}))}}registerHostCallback(e,t){this.hostCallbacks.set(e,t)}dispose(){this.disposed||(this.disposed=!0,this._global=null,this._undefined=null,this._null=null,this._true=null,this._false=null,this._ownedHandles.clear(),this.hostCallbacks.clear(),this._activeScope=null,this.exports=null,this.instance=null,this.module=null)}[Symbol.dispose](){this.dispose()}assertNotDisposed(){if(this.disposed)throw new Error("QuickJS instance has been disposed")}_getExports(){return this.exports}_getMemory(){return this.exports.memory}_writeString(e){return this.writeString(e)}_readCString(e){return this.readCString(e)}};function J(a){return a.includes("\0")||de.test(a)}var ve=new TextDecoder,je=new TextEncoder,de=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF]))|(?:(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])/;function ke(a){if(!de.test(a))return je.encode(a);let e=[];for(let t=0;t<a.length;t++){let r=a.charCodeAt(t);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&t+1<a.length){let s=a.charCodeAt(t+1);if(s>=56320&&s<=57343){let n=65536+(r-55296<<10)+(s-56320);e.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|n&63),t++;continue}e.push(224|r>>12,128|r>>6&63,128|r&63)}else e.push(224|r>>12,128|r>>6&63,128|r&63)}return new Uint8Array(e)}function Pe(a){let e=!1;for(let s=0;s<a.length-1;s++)if(a[s]===237&&a[s+1]>=160&&a[s+1]<=191){e=!0;break}if(!e)return ve.decode(a);let t="",r=0;for(;r<a.length;){let s=a[r];if(s<128)t+=String.fromCharCode(s),r+=1;else if(s<224)t+=String.fromCharCode((s&31)<<6|a[r+1]&63),r+=2;else if(s<240)t+=String.fromCharCode((s&15)<<12|(a[r+1]&63)<<6|a[r+2]&63),r+=3;else{let n=(s&7)<<18|(a[r+1]&63)<<12|(a[r+2]&63)<<6|a[r+3]&63;t+=String.fromCodePoint(n),r+=4}}return t}var R=class extends Error{handle;#e;#t;#r;constructor(e){let t={stack:[],error:void 0,hasError:!1};try{super(),this.handle=e,delete this.stack;let r=H(t,e.getProp("message"),!1);this.#e=e.getProp("name").consume(s=>s.isUndefined?"Error":s.toString()),this.#t=r.isUndefined?e.toString():r.toString(),this.#r=e.getProp("stack").consume(s=>s.isUndefined?void 0:s.toString())}catch(r){t.error=r,t.hasError=!0}finally{F(t)}}get name(){return this.#e}set name(e){this.#e=e}get message(){return this.#t}set message(e){this.#t=e}get stack(){return this.#r}set stack(e){this.#r=e}dispose(){this.handle.dispose()}[Symbol.dispose](){this.handle.dispose()}},m=class a{vm;ptr;disposed_=!1;singleton;borrowed;_onDispose;constructor(e,t,r=!1,s=!1){this.vm=e,this.ptr=t,this.singleton=r,this.borrowed=s,!r&&!s&&e._activeScope?.add(this)}get _isBorrowed(){return this.borrowed}get disposed(){return this.disposed_}get isUndefined(){return this.vm._getExports().qjs_is_undefined(this.ptr)!==0}get isNull(){return this.vm._getExports().qjs_is_null(this.ptr)!==0}get isBool(){return this.vm._getExports().qjs_is_bool(this.ptr)!==0}get isNumber(){return this.vm._getExports().qjs_is_number(this.ptr)!==0}get isString(){return this.vm._getExports().qjs_is_string(this.ptr)!==0}get isSymbol(){return this.vm._getExports().qjs_is_symbol(this.ptr)!==0}get isBigInt(){return this.vm._getExports().qjs_is_big_int(this.ptr)!==0}get isObject(){return this.vm._getExports().qjs_is_object(this.ptr)!==0}get isArray(){return this.vm._getExports().qjs_is_array(this.ptr)!==0}get isFunction(){return this.vm._getExports().qjs_is_function(this.ptr)!==0}get isError(){return this.vm._getExports().qjs_is_error(this.ptr)!==0}get isPromise(){return this.vm._getExports().qjs_is_promise(this.ptr)!==0}get isArrayBuffer(){return this.vm._getExports().qjs_is_array_buffer(this.ptr)!==0}get isProxy(){return this.vm._getExports().qjs_is_proxy(this.ptr)!==0}get isMap(){return this.vm._getExports().qjs_is_map(this.ptr)!==0}get isSet(){return this.vm._getExports().qjs_is_set(this.ptr)!==0}get isDate(){return this.vm._getExports().qjs_is_date(this.ptr)!==0}get isRegExp(){return this.vm._getExports().qjs_is_regexp(this.ptr)!==0}get isWeakRef(){return this.vm._getExports().qjs_is_weak_ref(this.ptr)!==0}get isWeakMap(){return this.vm._getExports().qjs_is_weak_map(this.ptr)!==0}get isWeakSet(){return this.vm._getExports().qjs_is_weak_set(this.ptr)!==0}get isDataView(){return this.vm._getExports().qjs_is_data_view(this.ptr)!==0}get identity(){return this.vm._getExports().qjs_get_value_ptr(this.ptr)}toBoolean(){return this.vm._getExports().qjs_get_bool(this.ptr)!==0}get classId(){return this.vm._getExports().qjs_get_class_id(this.ptr)}get className(){let e=new a(this.vm,this.vm._getExports().qjs_get_class_name(this.ptr));if(this.vm._getExports().qjs_is_exception(e.ptr)!==0)throw e.dispose(),new R(this.vm.getException());try{return e.isUndefined?void 0:e.toString()}finally{e.dispose()}}get promiseState(){return this.vm._getExports().qjs_promise_state(this.ptr)}get typeof(){return this.vm.typeof(this)}get length(){let e=this.getProp("length"),t=e.toNumber();return e.dispose(),t}get constructorName(){let e=this.getProp("constructor");if(e.isUndefined||e.isNull){e.dispose();return}let t=e.getProp("name");if(e.dispose(),t.isUndefined||t.isNull){t.dispose();return}let r=t.toString();return t.dispose(),r}keys(){let e=this.vm._getExports(),t=e.qjs_get_own_property_names(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);i.push(u.toString()),u.dispose()}return r.dispose(),i}getOwnPropertyNames(){let e=this.vm._getExports(),t=e.qjs_get_own_property_names_all(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);i.push(u.toString()),u.dispose()}return r.dispose(),i}getOwnPropertyKeys(){let e=this.vm._getExports(),t=e.qjs_get_own_property_keys(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);u.isSymbol?i.push(u):(i.push(u.toString()),u.dispose())}return r.dispose(),i}getOwnPropertyDescriptor(e){let t={stack:[],error:void 0,hasError:!1};try{let r=this.vm._getExports(),s,n;typeof e=="string"?(s=this.vm.newString(e),n=s.ptr):n=e.ptr;let i=r.qjs_get_own_property_descriptor(this.ptr,n);if(s?.dispose(),i===0)return;let o=H(t,new a(this.vm,i),!1);if(r.qjs_is_exception(o.ptr)!==0)throw new R(this.vm.getException());let c=o.getProp("enumerable").consume(l=>r.qjs_get_bool(l.ptr)!==0),u=o.getProp("configurable").consume(l=>r.qjs_get_bool(l.ptr)!==0);return o.hasOwnProperty("value")?{value:o.getProp("value"),writable:o.getProp("writable").consume(l=>r.qjs_get_bool(l.ptr)!==0),enumerable:c,configurable:u}:{get:o.getProp("get"),set:o.getProp("set"),enumerable:c,configurable:u}}catch(r){t.error=r,t.hasError=!0}finally{F(t)}}hasOwnProperty(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm._getExports().qjs_has_own_property_value(this.ptr,n.ptr)===1}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_has_own_property(this.ptr,t);return this.vm._getExports().wasm_free(t),r===1}propertyIsEnumerable(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm._getExports().qjs_property_is_enumerable_value(this.ptr,n.ptr)===1}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_property_is_enumerable(this.ptr,t);return this.vm._getExports().wasm_free(t),r===1}getPrototypeOf(){let e=this.vm._getExports().qjs_get_prototype_of(this.ptr);return new a(this.vm,e)}getProxyTarget(){let e=this.vm._getExports().qjs_get_proxy_target(this.ptr),t=new a(this.vm,e);if(this.vm._getExports().qjs_is_exception(t.ptr)!==0)throw t.dispose(),new R(this.vm.getException());return t}getProxyHandler(){let e=this.vm._getExports().qjs_get_proxy_handler(this.ptr),t=new a(this.vm,e);if(this.vm._getExports().qjs_is_exception(t.ptr)!==0)throw t.dispose(),new R(this.vm.getException());return t}getProp(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm.getProp(this,n)}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_get_prop_string(this.ptr,t);return this.vm._getExports().wasm_free(t),new a(this.vm,r)}setProp(e,t){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);this.vm.setProp(this,n,t);return}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:r}=this.vm._writeString(e);this.vm._getExports().qjs_set_prop_string(this.ptr,r,t.ptr),this.vm._getExports().wasm_free(r)}defineProp(e,t,r){let s=0;if(r?.configurable&&(s|=1),r?.writable&&(s|=2),r?.enumerable&&(s|=4),typeof e=="string"){if(J(e)){let i={stack:[],error:void 0,hasError:!1};try{let o=H(i,this.vm.newString(e),!1);this.vm._getExports().qjs_define_prop_value(this.ptr,o.ptr,t.ptr,s);return}catch(o){i.error=o,i.hasError=!0}finally{F(i)}}let{ptr:n}=this.vm._writeString(e);this.vm._getExports().qjs_define_prop_string(this.ptr,n,t.ptr,s),this.vm._getExports().wasm_free(n)}else this.vm._getExports().qjs_define_prop_value(this.ptr,e.ptr,t.ptr,s)}toNumber(){return this.vm._getExports().qjs_get_float64(this.ptr)}toBigInt(){let e=this.vm._getExports(),t=e.wasm_malloc(4),r=e.wasm_malloc(4);if(e.qjs_get_big_int64(this.ptr,t,r)!==0)throw e.wasm_free(t),e.wasm_free(r),new Error("Failed to convert value to BigInt");let n=new DataView(e.memory.buffer),i=n.getUint32(t,!0),o=n.getInt32(r,!0);return e.wasm_free(t),e.wasm_free(r),BigInt(o)<<32n|BigInt(i)}toArrayBuffer(){let e=this.vm._getExports(),t=e.wasm_malloc(4);if(e.qjs_is_array_buffer(this.ptr)){let w=e.qjs_get_array_buffer(this.ptr,t);if(w===0)throw e.wasm_free(t),new Error("Failed to get ArrayBuffer data");let _=new DataView(e.memory.buffer).getUint32(t,!0);return e.wasm_free(t),new Uint8Array(e.memory.buffer,w,_).slice().buffer}e.wasm_free(t);let r=e.wasm_malloc(4),s=e.wasm_malloc(4),n=e.wasm_malloc(4),i=e.qjs_get_typed_array_buffer(this.ptr,r,s,n),o=new a(this.vm,i);if(this.vm._getExports().qjs_is_exception(o.ptr)!==0)throw o.dispose(),e.wasm_free(r),e.wasm_free(s),e.wasm_free(n),new Error("Value is not an ArrayBuffer or typed array");let c=new DataView(e.memory.buffer),u=c.getUint32(r,!0),l=c.getUint32(s,!0);e.wasm_free(r),e.wasm_free(s),e.wasm_free(n);let d=e.wasm_malloc(4),h=e.qjs_get_array_buffer(o.ptr,d);if(e.wasm_free(d),o.dispose(),h===0)throw new Error("Failed to get ArrayBuffer data from typed array");return new Uint8Array(e.memory.buffer,h+u,l).slice().buffer}toUint8Array(){return new Uint8Array(this.toArrayBuffer())}toString(){let e=this.vm._getExports(),t=e.wasm_malloc(4);if(t===0)throw new Error("wasm_malloc failed");try{let r=e.qjs_get_string_len(this.ptr,t);if(r===0)return"<null>";let s=new DataView(e.memory.buffer).getUint32(t,!0),n=new Uint8Array(e.memory.buffer,r,s),i=Pe(n);return e.qjs_free_cstring(r),i}finally{e.wasm_free(t)}}consume(e){try{return e(this)}finally{this.dispose()}}dup(){return new a(this.vm,this.vm._getExports().qjs_dup_value(this.ptr))}dispose(){if(!(this.singleton||this.borrowed)&&!this.disposed_){this.disposed_=!0,this._onDispose?.(),this._onDispose=void 0;let e=this.vm._getExports();e&&e.qjs_free_value(this.ptr)}}[Symbol.dispose](){this.dispose()}};var re=["image/png","image/jpeg","image/gif","image/webp"],Me=new Set(re);var Fe=Object.freeze({modelOnly:!0}),Be=Object.freeze({defaultDeferred:!0}),U=Object.freeze({codeBytes:128*1024,memoryBytes:128*1024*1024,workers:4,workerWaitMs:6e4,calls:128,concurrency:4,argumentBytes:256*1024,summaryArgumentBytes:4*1024,resultBytes:1024*1024,totalResultBytes:8*1024*1024,outputBytes:1024*1024,outputItems:1e3,images:8,imageBytes:8*1024*1024,minOutputTokens:200,defaultOutputTokens:1e4,maxOutputTokens:16e3,cellTimeoutMs:30*6e4,defaultYieldMs:1e4,maxYieldMs:6e4,maxSyncMs:6e4,searches:256,cleanupMs:5e3}),fe=Object.freeze({keys:256,keyChars:200,totalBytes:4*1024*1024});var Q=re,me={calls:"Tool call limit exceeded",result:"Cumulative tool result limit exceeded",output:"Script output limit exceeded",images:"Script image limit exceeded",searches:"Tool search limit exceeded"};var he=String.raw`
|
|
2
|
+
`)){let o=i.indexOf("=");o>0&&(n[i.slice(0,o)]=i.slice(o+1))}return n}function Se(a,e){let t=`qjs_ext_${a.name.replace(/-/g,"_")}_versions`,r=a.instance.exports[t];if(typeof r!="function")return;let s=r();if(s!==0)return xe(e,s)}function M(a,e){let t=0,r=0;for(;e.value<a.length;){let s=a[e.value++];if(t|=(s&127)<<r,(s&128)===0)break;r+=7}return t}function Ee(a){let e=WebAssembly.Module.customSections(a,"dylink.0");if(e.length===0)return null;let t=new Uint8Array(e[0]),r={value:0},s={memorySize:0,memoryAlignment:0,tableSize:0,tableAlignment:0,needed:[]};for(;r.value<t.length;){let n=M(t,r),i=M(t,r),o=r.value+i;if(n===1)s.memorySize=M(t,r),s.memoryAlignment=M(t,r),s.tableSize=M(t,r),s.tableAlignment=M(t,r);else if(n===2){let c=M(t,r);for(let u=0;u<c;u++){let l=M(t,r),d=new TextDecoder().decode(t.slice(r.value,r.value+l));r.value+=l,s.needed.push(d)}}r.value=o}return s}async function Z(a,e,t,r,s,n){let i;a.wasm instanceof WebAssembly.Module?i=a.wasm:i=await WebAssembly.compile(a.wasm);let o=Ee(i);if(!o)throw new Error(`Extension "${a.name}" is not a WASM shared library (missing dylink.0 section)`);let c=e.memory,u=e.__indirect_function_table,l=e.__stack_pointer,d=e.malloc;if(!c)throw new Error("Main module does not export memory");if(!u)throw new Error("Main module does not export __indirect_function_table");if(!d)throw new Error("Main module does not export malloc");let h,w;if(n)h=n.memoryBase,w=n.tableBase;else if(o.memorySize>0){if(h=d(o.memorySize),h===0)throw new Error(`Failed to allocate ${o.memorySize} bytes for extension "${a.name}"`);new Uint8Array(c.buffer,h,o.memorySize).fill(0)}else h=0;n?(w=n.tableBase,w+o.tableSize>u.length&&u.grow(w+o.tableSize-u.length)):(w=u.length,o.tableSize>0&&u.grow(o.tableSize));let g=WebAssembly.Module.imports(i),_={env:{},"GOT.mem":{},"GOT.func":{}};if(g.some(f=>f.module==="wasi_snapshot_preview1")){let f=a.wasi&&s?a.wasi(s):void 0;_.wasi_snapshot_preview1={...t,...f,...r}}let O=new Set(WebAssembly.Module.exports(i).filter(f=>f.kind==="function").map(f=>f.name)),x=new Set;for(let f of g)if(f.module==="env"){if(f.name==="memory"&&f.kind==="memory")_.env.memory=c;else if(f.name==="__indirect_function_table"&&f.kind==="table")_.env.__indirect_function_table=u;else if(f.name==="__memory_base"&&f.kind==="global")_.env.__memory_base=new WebAssembly.Global({value:"i32",mutable:!1},h);else if(f.name==="__table_base"&&f.kind==="global")_.env.__table_base=new WebAssembly.Global({value:"i32",mutable:!1},w);else if(f.name==="__stack_pointer"&&f.kind==="global")_.env.__stack_pointer=l;else if(f.kind==="function"){let P=e[f.name];P&&typeof P=="function"?_.env[f.name]=P:(x.add(f.name),_.env[f.name]=()=>{throw new Error(`Extension "${a.name}" called unresolved symbol: env.${f.name}`)})}else if(f.kind==="global"){let P=e[f.name];P instanceof WebAssembly.Global?_.env[f.name]=P:_.env[f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0)}}else if(f.module==="GOT.mem"&&f.kind==="global")_["GOT.mem"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0);else if(f.module==="GOT.func"&&f.kind==="global"){let P=e[f.name];if(P&&typeof P=="function"){let L=u.length;u.grow(1),u.set(L,P),_["GOT.func"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},L)}else _["GOT.func"][f.name]=new WebAssembly.Global({value:"i32",mutable:!0},0)}let E=[...x].filter(f=>O.has(f)),j={};for(let f of E){let P={target:null};j[f]=P,_.env[f]=(...L)=>{if(!P.target)throw new Error(`Extension "${a.name}" called unresolved symbol during init: env.${f}`);return P.target(...L)}}let S=await WebAssembly.instantiate(i,_),k=S.exports;for(let f of E){let P=k[f];typeof P=="function"&&(j[f].target=P)}typeof k.__wasm_apply_data_relocs=="function"&&k.__wasm_apply_data_relocs(),typeof k.__wasm_call_ctors=="function"&&k.__wasm_call_ctors();let B=a.initFn??`qjs_ext_${a.name.replace(/-/g,"_")}_init`,y={name:a.name,module:i,instance:S,dylink:o,memoryBase:h,tableBase:w,initFn:B};return y.versions=Se(y,c),y}function ce(a,e){let t=a.instance.exports[a.initFn];if(typeof t!="function")throw new Error(`Extension "${a.name}" does not export init function "${a.initFn}"`);let r=e.qjs_get_context_ptr(),s=e.qjs_get_runtime_ptr(),n=t(r,s);if(n!==0)throw new Error(`Extension "${a.name}" init function returned error code ${n}`)}async function ue(a,e,t,r,s,n){let i=[];for(let o of e){let c=a.find(l=>l.name===o.name);if(!c)throw new Error(`Extension "${o.name}" required by snapshot but not provided`);let u=await Z(c,t,r,s,n,{memoryBase:o.memoryBase,tableBase:o.tableBase});u.initFn=o.initFn,i.push(u)}return i}var pe="3.6.2";var H=function(a,e,t){if(e!=null){if(typeof e!="object"&&typeof e!="function")throw new TypeError("Object expected.");var r,s;if(t){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=e[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=e[Symbol.dispose],t&&(s=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");s&&(r=function(){try{s.call(this)}catch(n){return Promise.reject(n)}}),a.stack.push({value:e,dispose:r,async:t})}else t&&a.stack.push({async:!0});return e},F=function(a){return function(e){function t(i){e.error=e.hasError?new a(i,e.error,"An error was suppressed during disposal."):i,e.hasError=!0}var r,s=0;function n(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(n);if(r.dispose){var i=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(i).then(n,function(o){return t(o),n()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return n()}}(typeof SuppressedError=="function"?SuppressedError:function(a,e,t){var r=new Error(t);return r.name="SuppressedError",r.error=a,r.suppressed=e,r}),G=512*1024;var ee=1363825491,te=2,V=24,Y=class a{exports;module;instance;encoder=new TextEncoder;decoder=new TextDecoder;disposed=!1;hostCallbacks=new Map;nextInternalId=1;interruptHandler=null;unhandledRejectionHandler=null;moduleNormalizeHandler=null;moduleLoadHandler=null;timezoneOffsetHandler=null;_global=null;_versions=null;_undefined=null;_null=null;_true=null;_false=null;_ownedHandles=new Set;_activeScope=null;loadedExtensions=[];constructor(e){this.module=e,this.instance=null,this.exports=null}setInstance(e){this.instance=e,this.exports=e.exports}get versions(){if(this.assertNotDisposed(),!this._versions){let e={"quickjs-wasi":pe,quickjs:this.readCString(this.exports.qjs_get_quickjs_version())};for(let t of this.loadedExtensions)t.versions&&Object.assign(e,t.versions);this._versions=e}return this._versions}get global(){return this._global||(this._global=new m(this,this.exports.qjs_get_global(),!0)),this._global}get undefined(){return this._undefined||(this._undefined=new m(this,this.exports.qjs_get_undefined(),!0)),this._undefined}get null(){return this._null||(this._null=new m(this,this.exports.qjs_get_null(),!0)),this._null}get true(){return this._true||(this._true=new m(this,this.exports.qjs_get_true(),!0)),this._true}get false(){return this._false||(this._false=new m(this,this.exports.qjs_get_false(),!0)),this._false}static async create(e){let t=a.normalizeOptions(e),r=await a.resolveModule(t.wasm),s=new a(r),{instance:n,wasiBuiltins:i,wasiUserOverrides:o,memoryProxy:c}=await a.instantiate(r,s,t.wasi);if(s.setInstance(n),s.exports._initialize(),(t.intrinsics!==void 0?s.exports.qjs_init2(t.intrinsics):s.exports.qjs_init())!==0)throw new Error("Failed to initialize QuickJS runtime");if(t.extensions){let l=n.exports;for(let d of t.extensions){let h=await Z(d,l,i,o,c);s.loadedExtensions.push(h),ce(h,l)}}return a.applyLimits(s,t),s}static async restore(e,t){let r=a.normalizeOptions(t),s=await a.resolveModule(r.wasm),n=new a(s),{instance:i,wasiBuiltins:o,wasiUserOverrides:c,memoryProxy:u}=await a.instantiate(s,n,r.wasi);n.setInstance(i);let l=i.exports,d=n.exports.memory,h=d.buffer.byteLength/65536,w=Math.ceil(e.memory.byteLength/65536);if(w>h&&d.grow(w-h),e.extensions.length>0){let _=r.extensions??[];n.loadedExtensions=await ue(_,e.extensions,l,o,c,u)}return new Uint8Array(d.buffer).set(e.memory),n.exports.qjs_set_runtime_and_context(e.runtimePtr,e.contextPtr),n.exports.__stack_pointer.value=e.stackPointer,a.applyLimits(n,r),n}static serializeSnapshot(e){let t=new TextEncoder,r=4,s=[],n=[];for(let d of e.extensions){let h=t.encode(d.name),w=t.encode(d.initFn);s.push(h),n.push(w),r+=4+h.length+4+4+4+w.length}let i=V+r+e.memory.byteLength,o=new ArrayBuffer(i),c=new DataView(o),u=new Uint8Array(o);c.setUint32(0,ee,!1),c.setUint8(4,te),c.setUint32(8,e.memory.byteLength,!0),c.setUint32(12,e.stackPointer,!0),c.setUint32(16,e.runtimePtr,!0),c.setUint32(20,e.contextPtr,!0);let l=V;c.setUint32(l,e.extensions.length,!0),l+=4;for(let d=0;d<e.extensions.length;d++){let h=e.extensions[d],w=s[d],g=n[d];c.setUint32(l,w.length,!0),l+=4,u.set(w,l),l+=w.length,c.setUint32(l,h.memoryBase,!0),l+=4,c.setUint32(l,h.tableBase,!0),l+=4,c.setUint32(l,g.length,!0),l+=4,u.set(g,l),l+=g.length}return u.set(e.memory,l),u}static deserializeSnapshot(e){if(e.length<V)throw new Error("Invalid snapshot: too small");let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t.getUint32(0,!1);if(r!==ee)throw new Error(`Invalid snapshot: bad magic (expected 0x${ee.toString(16)}, got 0x${r.toString(16)})`);let s=t.getUint8(4);if(s!==te&&s!==1)throw new Error(`Unsupported snapshot version: ${s} (expected ${te})`);let n=t.getUint32(8,!0),i=t.getUint32(12,!0),o=t.getUint32(16,!0),c=t.getUint32(20,!0),u=[],l=V;if(s>=2){let w=t.getUint32(24,!0),g=28,_=new TextDecoder;for(let I=0;I<w;I++){let O=t.getUint32(g,!0);g+=4;let x=_.decode(e.slice(g,g+O));g+=O;let E=t.getUint32(g,!0);g+=4;let j=t.getUint32(g,!0);g+=4;let S=t.getUint32(g,!0);g+=4;let k=_.decode(e.slice(g,g+S));g+=S,u.push({name:x,memoryBase:E,tableBase:j,initFn:k})}l=g}let d=l+n;if(e.length<d)throw new Error(`Invalid snapshot: expected ${d} bytes, got ${e.length}`);return{memory:e.slice(l,l+n),stackPointer:i,runtimePtr:o,contextPtr:c,extensions:u}}static normalizeOptions(e){if(!e)return{wasm:void 0};if(e instanceof WebAssembly.Module)return{wasm:e};if(typeof e=="object"&&("wasm"in e||"wasi"in e||"memoryLimit"in e||"maxStackSize"in e||"interruptHandler"in e||"onUnhandledRejection"in e||"moduleLoader"in e||"intrinsics"in e||"extensions"in e||"timezoneOffset"in e)){let t=e;if(t.maxStackSize!==void 0&&(!Number.isInteger(t.maxStackSize)||t.maxStackSize<0||t.maxStackSize>G))throw new RangeError(`maxStackSize must be an integer between 0 and ${G}`);return t}return{wasm:e}}static applyLimits(e,t){t.memoryLimit!==void 0&&e.exports.qjs_set_memory_limit(t.memoryLimit),t.maxStackSize!==void 0&&e.exports.qjs_set_max_stack_size(t.maxStackSize),t.interruptHandler&&(e.interruptHandler=t.interruptHandler,e.exports.qjs_set_interrupt_handler(1)),t.onUnhandledRejection&&(e.unhandledRejectionHandler=t.onUnhandledRejection,e.exports.qjs_set_promise_rejection_handler(1)),t.moduleLoader&&(e.moduleLoadHandler=t.moduleLoader.load,e.moduleNormalizeHandler=t.moduleLoader.normalize??null,e.exports.qjs_set_module_loader(1));let r=t.timezoneOffset;if(typeof r=="function")e.timezoneOffsetHandler=s=>-r(s)*60;else if(typeof r=="number"){let s=-r*60;e.timezoneOffsetHandler=()=>s}else e.timezoneOffsetHandler=s=>-new Date(s*1e3).getTimezoneOffset()*60}static async resolveModule(e){if(e instanceof WebAssembly.Module)return e;if(e)return WebAssembly.compile(e);throw new TypeError("QuickJS: `wasm` option is required. Provide WASM bytes or a compiled `WebAssembly.Module`. The binary is shipped at `quickjs-wasi/quickjs.wasm` and can be loaded via your environment's preferred mechanism (e.g. `fetch()`, `node:fs/promises`, or a bundler import like Vite's `?url`).")}static async instantiate(e,t,r){let s=null,n=new Proxy({},{get(x,E){return s[E]}}),i=le(()=>s),o=r?r(n):void 0,c={...i,...o},u=(x,E,j,S,k)=>t.handleHostCall(x,E,j,S,k),l=()=>t.interruptHandler&&t.interruptHandler()?1:0,d=(x,E,j)=>{if(!t.unhandledRejectionHandler){t.exports.qjs_free_value(x),t.exports.qjs_free_value(E);return}let S=new m(t,x),k=new m(t,E);try{t.unhandledRejectionHandler(S,k,j!==0)}finally{S.dispose(),k.dispose()}},h=x=>{let E=t.newError(x instanceof Error?x:String(x));t.exports.qjs_throw(E.ptr),E.dispose()},w=(x,E)=>{if(typeof x=="string")return x;let j=x!==null&&typeof x=="object"&&typeof x.then=="function"?"a Promise":`type ${typeof x}`;throw new TypeError(`moduleLoader.${E} must synchronously return a string (got ${j}). Async module loading is not supported. Pre-fetch module sources instead (see the "ES Modules" section of the quickjs-wasi README).`)},g=(x,E)=>{if(!t.moduleNormalizeHandler){let k=t.readCString(E);return t.writeString(k).ptr}let j=t.readCString(x),S=t.readCString(E);try{let k=w(t.moduleNormalizeHandler(j,S),"normalize");return t.writeString(k).ptr}catch(k){return h(k),0}},_=(x,E)=>{if(!t.moduleLoadHandler)return 0;let j=t.readCString(x);try{let S=w(t.moduleLoadHandler(j),"load"),{ptr:k,len:B}=t.writeString(S);return new Uint32Array(t.exports.memory.buffer,E,1)[0]=B,k}catch(S){return h(S),0}},I=(x,E)=>{let j=Number(BigInt(x)<<32n|BigInt(E>>>0));return t.timezoneOffsetHandler?t.timezoneOffsetHandler(j):0},O=await WebAssembly.instantiate(e,{env:{host_call:u,host_interrupt:l,host_promise_rejection:d,host_module_normalize:g,host_module_load:_,host_get_timezone_offset:I},wasi_snapshot_preview1:c});return s=O.exports.memory,{instance:O,wasiBuiltins:i,wasiUserOverrides:o,memoryProxy:n}}handleHostCall(e,t,r,s,n){let i=this.decoder.decode(new Uint8Array(this.exports.memory.buffer,e,t)),o=this.hostCallbacks.get(i);if(!o){let l=this.newError(`Host callback "${i}" is not registered: it was unregistered, its ephemeral function handle was disposed, or it was never re-registered after a snapshot restore.`);return this.exports.qjs_throw(l.ptr),l.dispose(),0}let c=new m(this,r,!1,!0),u=[];if(s>0&&n!==0){let l=new DataView(this.exports.memory.buffer);for(let d=0;d<s;d++){let h=l.getUint32(n+d*4,!0);u.push(new m(this,h,!1,!0))}}try{let l=o.call(c,...u);return this.exports.qjs_dup_value(l.ptr)}catch(l){let d=this.newError(l instanceof Error?l:String(l));return this.exports.qjs_throw(d.ptr),d.dispose(),0}}writeString(e){let t=ke(e),r=this.exports.wasm_malloc(t.length+1);if(r===0)throw new Error("wasm_malloc failed");let s=new Uint8Array(this.exports.memory.buffer);return s.set(t,r),s[r+t.length]=0,{ptr:r,len:t.length}}readCString(e){let t=new Uint8Array(this.exports.memory.buffer),r=e;for(;t[r]!==0;)r++;return this.decoder.decode(t.slice(e,r))}throwIfException(e){if(this.exports.qjs_is_exception(e.ptr)!==0){let t=this.getException();throw e.dispose(),this._ownedHandles.add(t),new R(t)}return e}evalCode(e,t="<eval>",r=0){this.assertNotDisposed();let s=this.writeString(e),n=this.writeString(t),i=this.exports.qjs_eval(s.ptr,s.len,n.ptr,r);return this.exports.wasm_free(s.ptr),this.exports.wasm_free(n.ptr),this.throwIfException(new m(this,i))}compile(e,t="<compile>",r=0,s=0){this.assertNotDisposed();let n=this.writeString(e),i=this.writeString(t),o=this.exports.wasm_malloc(4),c=this.exports.qjs_compile(n.ptr,n.len,i.ptr,r,s,o);if(this.exports.wasm_free(n.ptr),this.exports.wasm_free(i.ptr),c===0){this.exports.wasm_free(o);let d=this.getException();throw new Error(`Compilation error: ${d.toString()}`)}let u=new Uint32Array(this.exports.memory.buffer,o,1)[0];this.exports.wasm_free(o);let l=new Uint8Array(this.exports.memory.buffer,c,u).slice();return this.exports.wasm_free(c),l}evalBytecode(e){this.assertNotDisposed();let t=this.exports.wasm_malloc(e.byteLength);new Uint8Array(this.exports.memory.buffer,t,e.byteLength).set(e);let r=this.exports.qjs_eval_bytecode(t,e.byteLength);return this.exports.wasm_free(t),this.throwIfException(new m(this,r))}executePendingJobs(){this.assertNotDisposed();let e=0;for(;this.exports.qjs_is_job_pending();){if(this.exports.qjs_execute_pending_job()<0){let r=this.getException();throw new Error(`Job execution error: ${r.toString()}`)}e++}return e}runGC(){this.assertNotDisposed(),this.exports.qjs_run_gc()}get gcThreshold(){return this.assertNotDisposed(),this.exports.qjs_get_gc_threshold()}set gcThreshold(e){this.assertNotDisposed(),this.exports.qjs_set_gc_threshold(e)}getMemoryUsage(){this.assertNotDisposed();let e=this.exports.wasm_malloc(26*8);this.exports.qjs_compute_memory_usage(e);let t=new BigInt64Array(this.exports.memory.buffer,e,26),r={mallocSize:Number(t[0]),mallocLimit:Number(t[1]),memoryUsedSize:Number(t[2]),mallocCount:Number(t[3]),memoryUsedCount:Number(t[4]),atomCount:Number(t[5]),atomSize:Number(t[6]),strCount:Number(t[7]),strSize:Number(t[8]),objCount:Number(t[9]),objSize:Number(t[10]),propCount:Number(t[11]),propSize:Number(t[12]),shapeCount:Number(t[13]),shapeSize:Number(t[14]),jsFuncCount:Number(t[15]),jsFuncSize:Number(t[16]),jsFuncCodeSize:Number(t[17]),jsFuncPc2lineCount:Number(t[18]),jsFuncPc2lineSize:Number(t[19]),cFuncCount:Number(t[20]),arrayCount:Number(t[21]),fastArrayCount:Number(t[22]),fastArrayElements:Number(t[23]),binaryObjectCount:Number(t[24]),binaryObjectSize:Number(t[25])};return this.exports.wasm_free(e),r}getGlobal(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_global())}newString(e){this.assertNotDisposed();let{ptr:t,len:r}=this.writeString(e),s=this.exports.qjs_new_string(t,r);return this.exports.wasm_free(t),new m(this,s)}newNumber(e){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_number(e))}newBigInt(e){this.assertNotDisposed();let t=Number(e&0xffffffffn),r=Number(e>>32n&0xffffffffn);return new m(this,this.exports.qjs_new_big_int64(t,r))}newObject(){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_object())}newArray(){return this.assertNotDisposed(),new m(this,this.exports.qjs_new_array())}newSymbolFor(e){this.assertNotDisposed();let{ptr:t,len:r}=this.writeString(e),s=new m(this,this.exports.qjs_new_symbol(t,r,1));return this.exports.wasm_free(t),s}newArrayBuffer(e){this.assertNotDisposed();let t=e instanceof ArrayBuffer?new Uint8Array(e):e,r=this.exports.wasm_malloc(t.length);if(r===0)throw new Error("wasm_malloc failed");new Uint8Array(this.exports.memory.buffer).set(t,r);let s=new m(this,this.exports.qjs_new_array_buffer(r,t.length));return this.exports.wasm_free(r),s}newUint8Array(e){this.assertNotDisposed();let t=this.exports.wasm_malloc(e.length);if(t===0)throw new Error("wasm_malloc failed");new Uint8Array(this.exports.memory.buffer).set(e,t);let r=new m(this,this.exports.qjs_new_uint8_array(t,e.length));return this.exports.wasm_free(t),r}getUndefined(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_undefined())}getNull(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_null())}getTrue(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_true())}getFalse(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_false())}newFunction(e,t){if(this.assertNotDisposed(),this.hostCallbacks.has(e))throw new Error(`Host callback with name "${e}" is already registered`);this.hostCallbacks.set(e,t);let{ptr:r,len:s}=this.writeString(e),n=this.exports.qjs_new_host_function(r,s,0);return this.exports.wasm_free(r),new m(this,n)}withScope(e){this.assertNotDisposed();let t=this._activeScope,r=new Set;this._activeScope=r;let s={escape:n=>(r.delete(n),t?.add(n),n)};try{return e(s)}finally{this._activeScope=t;for(let n of r)n.dispose()}}exportHandle(e){if(this.assertNotDisposed(),e.vm!==this)throw new Error("exportHandle: handle belongs to a different VM");if(e.disposed)throw new Error("exportHandle: handle is disposed");if(e._isBorrowed)throw new Error("exportHandle: cannot export a borrowed handle (host-callback this/argument); its box is freed when the callback returns. dup() it and export the duplicate.");return e.ptr}importHandle(e){if(this.assertNotDisposed(),!Number.isInteger(e)||e<=0||e>=this.exports.memory.buffer.byteLength)throw new Error(`importHandle: invalid token ${e}`);return new m(this,this.exports.qjs_dup_value(e))}newEphemeralFunction(e){this.assertNotDisposed();let t=`__ephemeral:${this.nextInternalId++}`;this.hostCallbacks.set(t,e);let{ptr:r,len:s}=this.writeString(t),n=this.exports.qjs_new_host_function(r,s,0);this.exports.wasm_free(r);let i=new m(this,n);return i._onDispose=()=>{this.hostCallbacks.delete(t)},i}unregisterHostCallback(e){return this.hostCallbacks.delete(e)}newInternalFunction(e,t){this.hostCallbacks.set(e,t);let{ptr:r,len:s}=this.writeString(e),n=this.exports.qjs_new_host_function(r,s,0);return this.exports.wasm_free(r),new m(this,n)}newPromise(){this.assertNotDisposed();let e=this.exports.wasm_malloc(4),t=this.exports.wasm_malloc(4),r=this.exports.qjs_new_promise(e,t),s=new DataView(this.exports.memory.buffer),n=s.getUint32(e,!0),i=s.getUint32(t,!0);this.exports.wasm_free(e),this.exports.wasm_free(t);let o=new m(this,r),c=new m(this,n),u=new m(this,i),l=this;l._ownedHandles.add(c),l._ownedHandles.add(u);let d=null;return{handle:o,get settled(){if(!d){let h;d=new Promise(_=>{h=_});let w=`__settle:${l.nextInternalId++}`,g=l.newInternalFunction(w,()=>(h(),l.hostCallbacks.delete(w),l.undefined));l.promiseThenRaw(o,g,g).dispose(),g.dispose()}return d},resolve(h){l.callFunctionRaw(c,l.undefined,h).dispose(),l._ownedHandles.delete(c),c.dispose()},reject(h){l.callFunctionRaw(u,l.undefined,h).dispose(),l._ownedHandles.delete(u),u.dispose()}}}resolvePromise(e){if(this.assertNotDisposed(),!this.exports.qjs_is_promise(e.ptr))return Promise.resolve({value:e.dup()});let t=this.exports.qjs_promise_state(e.ptr);return t===1?Promise.resolve({value:new m(this,this.exports.qjs_promise_result(e.ptr))}):t===2?Promise.resolve({error:new m(this,this.exports.qjs_promise_result(e.ptr))}):new Promise(r=>{let s=this.nextInternalId++,n=`__onFulfilled:${s}`,i=`__onRejected:${s}`,o=this.newInternalFunction(n,(...u)=>{let l=u[0]?.dup()??this.undefined;return this.hostCallbacks.delete(n),this.hostCallbacks.delete(i),r({value:l}),this.undefined}),c=this.newInternalFunction(i,(...u)=>{let l=u[0]?.dup()??this.undefined;return this.hostCallbacks.delete(n),this.hostCallbacks.delete(i),r({error:l}),this.undefined});this.promiseThenRaw(e,o,c).dispose(),o.dispose(),c.dispose()})}promiseThenRaw(e,t,r){return new m(this,this.exports.qjs_promise_then(e.ptr,t.ptr,r.ptr))}markPromiseHandled(e){this.assertNotDisposed(),this.exports.qjs_promise_mark_as_handled(e.ptr)}callFunction(e,t,...r){return this.throwIfException(this.callFunctionRaw(e,t,...r))}construct(e,...t){this.assertNotDisposed();let r=t.length,s=0;if(r>0){s=this.exports.wasm_malloc(r*4);let i=new DataView(this.exports.memory.buffer);for(let o=0;o<r;o++)i.setUint32(s+o*4,t[o].ptr,!0)}let n=this.exports.qjs_call_constructor(e.ptr,r,s);return s&&this.exports.wasm_free(s),this.throwIfException(new m(this,n))}callFunctionRaw(e,t,...r){this.assertNotDisposed();let s=r.length,n=0;if(s>0){n=this.exports.wasm_malloc(s*4);let o=new DataView(this.exports.memory.buffer);for(let c=0;c<s;c++)o.setUint32(n+c*4,r[c].ptr,!0)}let i=this.exports.qjs_call(e.ptr,t.ptr,s,n);return n&&this.exports.wasm_free(n),new m(this,i)}setProp(e,t,r){if(this.assertNotDisposed(),typeof t=="string"){let{ptr:s}=this.writeString(t);this.exports.qjs_set_prop_string(e.ptr,s,r.ptr),this.exports.wasm_free(s)}else this.exports.qjs_set_prop_value(e.ptr,t.ptr,r.ptr)}defineProp(e,t,r,s){this.assertNotDisposed();let n=0;if(s?.configurable&&(n|=1),s?.writable&&(n|=2),s?.enumerable&&(n|=4),typeof t=="string"){let{ptr:i}=this.writeString(t);this.exports.qjs_define_prop_string(e.ptr,i,r.ptr,n),this.exports.wasm_free(i)}else this.exports.qjs_define_prop_value(e.ptr,t.ptr,r.ptr,n)}getProp(e,t){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_prop_value(e.ptr,t.ptr))}getException(){return this.assertNotDisposed(),new m(this,this.exports.qjs_get_exception())}newError(e){this.assertNotDisposed();let t=this.exports.qjs_new_error(),r=new m(this,t);if(typeof e=="string"){let s=this.newString(e);r.setProp("message",s),s.dispose()}else{let s=this.newString(e.message);if(r.setProp("message",s),s.dispose(),e.name){let n=this.newString(e.name);r.setProp("name",n),n.dispose()}if(e.stack){let n=this.newString(e.stack);r.setProp("stack",n),n.dispose()}}return r}typeof(e){this.assertNotDisposed();let t=this.exports;return t.qjs_is_undefined(e.ptr)?"undefined":t.qjs_is_null(e.ptr)?"object":t.qjs_is_bool(e.ptr)?"boolean":t.qjs_is_number(e.ptr)?"number":t.qjs_is_big_int(e.ptr)?"bigint":t.qjs_is_string(e.ptr)?"string":t.qjs_is_symbol(e.ptr)?"symbol":t.qjs_is_function(e.ptr)?"function":t.qjs_is_object(e.ptr)?"object":"unknown"}dump(e){return this.assertNotDisposed(),this._dump(e,new Map)}_dump(e,t){let r=this.exports;if(!r.qjs_is_undefined(e.ptr)){if(r.qjs_is_null(e.ptr))return null;if(r.qjs_is_bool(e.ptr))return r.qjs_get_bool(e.ptr)!==0;if(r.qjs_is_number(e.ptr))return r.qjs_get_float64(e.ptr);if(r.qjs_is_string(e.ptr))return e.toString();if(r.qjs_is_big_int(e.ptr))return e.toBigInt();if(r.qjs_is_symbol(e.ptr)){let s=r.wasm_malloc(4),n=r.qjs_get_symbol_description(e.ptr,s),o=new DataView(r.memory.buffer).getUint32(s,!0);if(r.wasm_free(s),n===1){let c=new m(this,o),u=c.toString();return c.dispose(),Symbol.for(u)}else if(n===2){new m(this,o).dispose();return}return}if(r.qjs_is_array_buffer(e.ptr))return e.toArrayBuffer();if(r.qjs_is_exception(e.ptr)){let s=this.getException(),n=s.toString();return s.dispose(),new Error(n)}if(!r.qjs_is_function(e.ptr)){if(r.qjs_is_object(e.ptr)){let s=r.qjs_get_value_ptr(e.ptr);if(s){let n=t.get(s);if(n!==void 0)return n}}if(r.qjs_is_object(e.ptr)){let s=r.wasm_malloc(4),n=r.wasm_malloc(4),i=r.wasm_malloc(4),o=r.qjs_get_typed_array_buffer(e.ptr,s,n,i),c=new m(this,o);if(r.qjs_is_exception(c.ptr)===0){let u=new DataView(r.memory.buffer),l=u.getUint32(s,!0),d=u.getUint32(n,!0),h=u.getUint32(i,!0);r.wasm_free(s),r.wasm_free(n),r.wasm_free(i);let w=r.wasm_malloc(4),g=r.qjs_get_array_buffer(c.ptr,w);if(r.wasm_free(w),c.dispose(),g!==0){let _=new Uint8Array(r.memory.buffer,g+l,d).slice();switch(h){case 1:return _;case 2:return new Uint16Array(_.buffer);case 4:return new Uint32Array(_.buffer);case 8:return new Float64Array(_.buffer);default:return _}}}else c.dispose(),r.wasm_free(s),r.wasm_free(n),r.wasm_free(i)}if(r.qjs_is_array(e.ptr)){let s=e.getProp("length"),n=r.qjs_get_float64(s.ptr);s.dispose();let i=[],o=r.qjs_get_value_ptr(e.ptr);o&&t.set(o,i);for(let c=0;c<n;c++){let u=r.qjs_get_prop_uint32(e.ptr,c),l=new m(this,u);i.push(this._dump(l,t)),l.dispose()}return i}if(r.qjs_is_error(e.ptr)){let s=e.getProp("name"),n=e.getProp("message"),i=e.getProp("stack"),o=s.isUndefined?"Error":s.toString(),c=n.isUndefined?"":n.toString(),u=i.isUndefined?void 0:i.toString();s.dispose(),n.dispose(),i.dispose();let l=new Error(c);return l.name=o,u!==void 0&&(l.stack=u),l}if(r.qjs_is_object(e.ptr)){let s=r.qjs_get_own_property_names(e.ptr),n=new m(this,s);if(r.qjs_is_exception(n.ptr)!==0)return n.dispose(),{};let i=n.getProp("length"),o=r.qjs_get_float64(i.ptr);i.dispose();let c={},u=r.qjs_get_value_ptr(e.ptr);u&&t.set(u,c);for(let l=0;l<o;l++){let d=r.qjs_get_prop_uint32(n.ptr,l),h=new m(this,d),w=h.toString();h.dispose();let g=e.getProp(w);c[w]=this._dump(g,t),g.dispose()}return n.dispose(),c}}}}hostToHandle(e){if(this.assertNotDisposed(),e===void 0)return this.undefined;if(e===null)return this.null;if(e===!0)return this.true;if(e===!1)return this.false;if(typeof e=="number")return this.newNumber(e);if(typeof e=="string")return this.newString(e);if(typeof e=="bigint")return this.newBigInt(e);if(typeof e=="symbol"){let t=Symbol.keyFor(e);if(t!==void 0)return this.newSymbolFor(t);throw new Error("Cannot convert local symbol to QuickJS handle. Use Symbol.for() for cross-boundary symbols.")}if(e instanceof Promise){let t=this.newPromise();return e.then(r=>{t.resolve(this.hostToHandle(r)),this.executePendingJobs()},r=>{t.reject(this.hostToHandle(r)),this.executePendingJobs()}),t.handle}if(e instanceof Error)return this.newError(e);if(e instanceof ArrayBuffer)return this.newArrayBuffer(e);if(e instanceof Uint8Array)return this.newUint8Array(e);if(ArrayBuffer.isView(e))return this.newArrayBuffer(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));if(Array.isArray(e)){let t=this.newArray();for(let r=0;r<e.length;r++){let s=this.hostToHandle(e[r]);this.exports.qjs_set_prop_uint32(t.ptr,r,s.ptr),s.dispose()}return t}if(typeof e=="object"&&e!==null){let t=this.newObject();for(let[r,s]of Object.entries(e)){let n=this.hostToHandle(s);t.setProp(r,n),n.dispose()}return t}return this.undefined}snapshot(){return this.assertNotDisposed(),{memory:new Uint8Array(this.exports.memory.buffer).slice(),stackPointer:this.exports.__stack_pointer.value,runtimePtr:this.exports.qjs_get_runtime_ptr(),contextPtr:this.exports.qjs_get_context_ptr(),extensions:this.loadedExtensions.map(e=>({name:e.name,memoryBase:e.memoryBase,tableBase:e.tableBase,initFn:e.initFn}))}}registerHostCallback(e,t){this.hostCallbacks.set(e,t)}dispose(){this.disposed||(this.disposed=!0,this._global=null,this._undefined=null,this._null=null,this._true=null,this._false=null,this._ownedHandles.clear(),this.hostCallbacks.clear(),this._activeScope=null,this.exports=null,this.instance=null,this.module=null)}[Symbol.dispose](){this.dispose()}assertNotDisposed(){if(this.disposed)throw new Error("QuickJS instance has been disposed")}_getExports(){return this.exports}_getMemory(){return this.exports.memory}_writeString(e){return this.writeString(e)}_readCString(e){return this.readCString(e)}};function J(a){return a.includes("\0")||de.test(a)}var je=new TextDecoder,ve=new TextEncoder,de=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF]))|(?:(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])/;function ke(a){if(!de.test(a))return ve.encode(a);let e=[];for(let t=0;t<a.length;t++){let r=a.charCodeAt(t);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&t+1<a.length){let s=a.charCodeAt(t+1);if(s>=56320&&s<=57343){let n=65536+(r-55296<<10)+(s-56320);e.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|n&63),t++;continue}e.push(224|r>>12,128|r>>6&63,128|r&63)}else e.push(224|r>>12,128|r>>6&63,128|r&63)}return new Uint8Array(e)}function Pe(a){let e=!1;for(let s=0;s<a.length-1;s++)if(a[s]===237&&a[s+1]>=160&&a[s+1]<=191){e=!0;break}if(!e)return je.decode(a);let t="",r=0;for(;r<a.length;){let s=a[r];if(s<128)t+=String.fromCharCode(s),r+=1;else if(s<224)t+=String.fromCharCode((s&31)<<6|a[r+1]&63),r+=2;else if(s<240)t+=String.fromCharCode((s&15)<<12|(a[r+1]&63)<<6|a[r+2]&63),r+=3;else{let n=(s&7)<<18|(a[r+1]&63)<<12|(a[r+2]&63)<<6|a[r+3]&63;t+=String.fromCodePoint(n),r+=4}}return t}var R=class extends Error{handle;#e;#t;#r;constructor(e){let t={stack:[],error:void 0,hasError:!1};try{super(),this.handle=e,delete this.stack;let r=H(t,e.getProp("message"),!1);this.#e=e.getProp("name").consume(s=>s.isUndefined?"Error":s.toString()),this.#t=r.isUndefined?e.toString():r.toString(),this.#r=e.getProp("stack").consume(s=>s.isUndefined?void 0:s.toString())}catch(r){t.error=r,t.hasError=!0}finally{F(t)}}get name(){return this.#e}set name(e){this.#e=e}get message(){return this.#t}set message(e){this.#t=e}get stack(){return this.#r}set stack(e){this.#r=e}dispose(){this.handle.dispose()}[Symbol.dispose](){this.handle.dispose()}},m=class a{vm;ptr;disposed_=!1;singleton;borrowed;_onDispose;constructor(e,t,r=!1,s=!1){this.vm=e,this.ptr=t,this.singleton=r,this.borrowed=s,!r&&!s&&e._activeScope?.add(this)}get _isBorrowed(){return this.borrowed}get disposed(){return this.disposed_}get isUndefined(){return this.vm._getExports().qjs_is_undefined(this.ptr)!==0}get isNull(){return this.vm._getExports().qjs_is_null(this.ptr)!==0}get isBool(){return this.vm._getExports().qjs_is_bool(this.ptr)!==0}get isNumber(){return this.vm._getExports().qjs_is_number(this.ptr)!==0}get isString(){return this.vm._getExports().qjs_is_string(this.ptr)!==0}get isSymbol(){return this.vm._getExports().qjs_is_symbol(this.ptr)!==0}get isBigInt(){return this.vm._getExports().qjs_is_big_int(this.ptr)!==0}get isObject(){return this.vm._getExports().qjs_is_object(this.ptr)!==0}get isArray(){return this.vm._getExports().qjs_is_array(this.ptr)!==0}get isFunction(){return this.vm._getExports().qjs_is_function(this.ptr)!==0}get isError(){return this.vm._getExports().qjs_is_error(this.ptr)!==0}get isPromise(){return this.vm._getExports().qjs_is_promise(this.ptr)!==0}get isArrayBuffer(){return this.vm._getExports().qjs_is_array_buffer(this.ptr)!==0}get isProxy(){return this.vm._getExports().qjs_is_proxy(this.ptr)!==0}get isMap(){return this.vm._getExports().qjs_is_map(this.ptr)!==0}get isSet(){return this.vm._getExports().qjs_is_set(this.ptr)!==0}get isDate(){return this.vm._getExports().qjs_is_date(this.ptr)!==0}get isRegExp(){return this.vm._getExports().qjs_is_regexp(this.ptr)!==0}get isWeakRef(){return this.vm._getExports().qjs_is_weak_ref(this.ptr)!==0}get isWeakMap(){return this.vm._getExports().qjs_is_weak_map(this.ptr)!==0}get isWeakSet(){return this.vm._getExports().qjs_is_weak_set(this.ptr)!==0}get isDataView(){return this.vm._getExports().qjs_is_data_view(this.ptr)!==0}get identity(){return this.vm._getExports().qjs_get_value_ptr(this.ptr)}toBoolean(){return this.vm._getExports().qjs_get_bool(this.ptr)!==0}get classId(){return this.vm._getExports().qjs_get_class_id(this.ptr)}get className(){let e=new a(this.vm,this.vm._getExports().qjs_get_class_name(this.ptr));if(this.vm._getExports().qjs_is_exception(e.ptr)!==0)throw e.dispose(),new R(this.vm.getException());try{return e.isUndefined?void 0:e.toString()}finally{e.dispose()}}get promiseState(){return this.vm._getExports().qjs_promise_state(this.ptr)}get typeof(){return this.vm.typeof(this)}get length(){let e=this.getProp("length"),t=e.toNumber();return e.dispose(),t}get constructorName(){let e=this.getProp("constructor");if(e.isUndefined||e.isNull){e.dispose();return}let t=e.getProp("name");if(e.dispose(),t.isUndefined||t.isNull){t.dispose();return}let r=t.toString();return t.dispose(),r}keys(){let e=this.vm._getExports(),t=e.qjs_get_own_property_names(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);i.push(u.toString()),u.dispose()}return r.dispose(),i}getOwnPropertyNames(){let e=this.vm._getExports(),t=e.qjs_get_own_property_names_all(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);i.push(u.toString()),u.dispose()}return r.dispose(),i}getOwnPropertyKeys(){let e=this.vm._getExports(),t=e.qjs_get_own_property_keys(this.ptr),r=new a(this.vm,t);if(e.qjs_is_exception(r.ptr)!==0)return r.dispose(),[];let s=r.getProp("length"),n=e.qjs_get_float64(s.ptr);s.dispose();let i=[];for(let o=0;o<n;o++){let c=e.qjs_get_prop_uint32(r.ptr,o),u=new a(this.vm,c);u.isSymbol?i.push(u):(i.push(u.toString()),u.dispose())}return r.dispose(),i}getOwnPropertyDescriptor(e){let t={stack:[],error:void 0,hasError:!1};try{let r=this.vm._getExports(),s,n;typeof e=="string"?(s=this.vm.newString(e),n=s.ptr):n=e.ptr;let i=r.qjs_get_own_property_descriptor(this.ptr,n);if(s?.dispose(),i===0)return;let o=H(t,new a(this.vm,i),!1);if(r.qjs_is_exception(o.ptr)!==0)throw new R(this.vm.getException());let c=o.getProp("enumerable").consume(l=>r.qjs_get_bool(l.ptr)!==0),u=o.getProp("configurable").consume(l=>r.qjs_get_bool(l.ptr)!==0);return o.hasOwnProperty("value")?{value:o.getProp("value"),writable:o.getProp("writable").consume(l=>r.qjs_get_bool(l.ptr)!==0),enumerable:c,configurable:u}:{get:o.getProp("get"),set:o.getProp("set"),enumerable:c,configurable:u}}catch(r){t.error=r,t.hasError=!0}finally{F(t)}}hasOwnProperty(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm._getExports().qjs_has_own_property_value(this.ptr,n.ptr)===1}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_has_own_property(this.ptr,t);return this.vm._getExports().wasm_free(t),r===1}propertyIsEnumerable(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm._getExports().qjs_property_is_enumerable_value(this.ptr,n.ptr)===1}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_property_is_enumerable(this.ptr,t);return this.vm._getExports().wasm_free(t),r===1}getPrototypeOf(){let e=this.vm._getExports().qjs_get_prototype_of(this.ptr);return new a(this.vm,e)}getProxyTarget(){let e=this.vm._getExports().qjs_get_proxy_target(this.ptr),t=new a(this.vm,e);if(this.vm._getExports().qjs_is_exception(t.ptr)!==0)throw t.dispose(),new R(this.vm.getException());return t}getProxyHandler(){let e=this.vm._getExports().qjs_get_proxy_handler(this.ptr),t=new a(this.vm,e);if(this.vm._getExports().qjs_is_exception(t.ptr)!==0)throw t.dispose(),new R(this.vm.getException());return t}getProp(e){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);return this.vm.getProp(this,n)}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:t}=this.vm._writeString(e),r=this.vm._getExports().qjs_get_prop_string(this.ptr,t);return this.vm._getExports().wasm_free(t),new a(this.vm,r)}setProp(e,t){if(J(e)){let s={stack:[],error:void 0,hasError:!1};try{let n=H(s,this.vm.newString(e),!1);this.vm.setProp(this,n,t);return}catch(n){s.error=n,s.hasError=!0}finally{F(s)}}let{ptr:r}=this.vm._writeString(e);this.vm._getExports().qjs_set_prop_string(this.ptr,r,t.ptr),this.vm._getExports().wasm_free(r)}defineProp(e,t,r){let s=0;if(r?.configurable&&(s|=1),r?.writable&&(s|=2),r?.enumerable&&(s|=4),typeof e=="string"){if(J(e)){let i={stack:[],error:void 0,hasError:!1};try{let o=H(i,this.vm.newString(e),!1);this.vm._getExports().qjs_define_prop_value(this.ptr,o.ptr,t.ptr,s);return}catch(o){i.error=o,i.hasError=!0}finally{F(i)}}let{ptr:n}=this.vm._writeString(e);this.vm._getExports().qjs_define_prop_string(this.ptr,n,t.ptr,s),this.vm._getExports().wasm_free(n)}else this.vm._getExports().qjs_define_prop_value(this.ptr,e.ptr,t.ptr,s)}toNumber(){return this.vm._getExports().qjs_get_float64(this.ptr)}toBigInt(){let e=this.vm._getExports(),t=e.wasm_malloc(4),r=e.wasm_malloc(4);if(e.qjs_get_big_int64(this.ptr,t,r)!==0)throw e.wasm_free(t),e.wasm_free(r),new Error("Failed to convert value to BigInt");let n=new DataView(e.memory.buffer),i=n.getUint32(t,!0),o=n.getInt32(r,!0);return e.wasm_free(t),e.wasm_free(r),BigInt(o)<<32n|BigInt(i)}toArrayBuffer(){let e=this.vm._getExports(),t=e.wasm_malloc(4);if(e.qjs_is_array_buffer(this.ptr)){let w=e.qjs_get_array_buffer(this.ptr,t);if(w===0)throw e.wasm_free(t),new Error("Failed to get ArrayBuffer data");let _=new DataView(e.memory.buffer).getUint32(t,!0);return e.wasm_free(t),new Uint8Array(e.memory.buffer,w,_).slice().buffer}e.wasm_free(t);let r=e.wasm_malloc(4),s=e.wasm_malloc(4),n=e.wasm_malloc(4),i=e.qjs_get_typed_array_buffer(this.ptr,r,s,n),o=new a(this.vm,i);if(this.vm._getExports().qjs_is_exception(o.ptr)!==0)throw o.dispose(),e.wasm_free(r),e.wasm_free(s),e.wasm_free(n),new Error("Value is not an ArrayBuffer or typed array");let c=new DataView(e.memory.buffer),u=c.getUint32(r,!0),l=c.getUint32(s,!0);e.wasm_free(r),e.wasm_free(s),e.wasm_free(n);let d=e.wasm_malloc(4),h=e.qjs_get_array_buffer(o.ptr,d);if(e.wasm_free(d),o.dispose(),h===0)throw new Error("Failed to get ArrayBuffer data from typed array");return new Uint8Array(e.memory.buffer,h+u,l).slice().buffer}toUint8Array(){return new Uint8Array(this.toArrayBuffer())}toString(){let e=this.vm._getExports(),t=e.wasm_malloc(4);if(t===0)throw new Error("wasm_malloc failed");try{let r=e.qjs_get_string_len(this.ptr,t);if(r===0)return"<null>";let s=new DataView(e.memory.buffer).getUint32(t,!0),n=new Uint8Array(e.memory.buffer,r,s),i=Pe(n);return e.qjs_free_cstring(r),i}finally{e.wasm_free(t)}}consume(e){try{return e(this)}finally{this.dispose()}}dup(){return new a(this.vm,this.vm._getExports().qjs_dup_value(this.ptr))}dispose(){if(!(this.singleton||this.borrowed)&&!this.disposed_){this.disposed_=!0,this._onDispose?.(),this._onDispose=void 0;let e=this.vm._getExports();e&&e.qjs_free_value(this.ptr)}}[Symbol.dispose](){this.dispose()}};var re=["image/png","image/jpeg","image/gif","image/webp"],Me=new Set(re);var Fe=Object.freeze({modelOnly:!0}),Be=Object.freeze({defaultDeferred:!0}),U=Object.freeze({codeBytes:128*1024,memoryBytes:128*1024*1024,workers:4,workerWaitMs:6e4,calls:128,concurrency:4,argumentBytes:256*1024,summaryArgumentBytes:4*1024,resultBytes:1024*1024,totalResultBytes:8*1024*1024,outputBytes:1024*1024,outputItems:1e3,images:8,imageBytes:8*1024*1024,minOutputTokens:200,defaultOutputTokens:1e4,maxOutputTokens:16e3,cellTimeoutMs:30*6e4,defaultYieldMs:1e4,maxYieldMs:6e4,maxSyncMs:6e4,searches:256,cleanupMs:5e3}),fe=Object.freeze({keys:256,keyChars:200,totalBytes:4*1024*1024});var Q=re,me={calls:"Tool call limit exceeded",result:"Cumulative tool result limit exceeded",output:"Script output limit exceeded",images:"Script image limit exceeded",searches:"Tool search limit exceeded"};var he=String.raw`
|
|
3
3
|
(bridge, namesJSON, directNamesJSON, catalogJSON, storeJSON, storeError, namespacesJSON) => {
|
|
4
4
|
'use strict';
|
|
5
5
|
const parse = JSON.parse;
|
|
@@ -118,7 +118,7 @@ import{parentPort as $,workerData as qe}from"node:worker_threads";function le(a)
|
|
|
118
118
|
define(globalThis, 'image', { value: freeze(value => {
|
|
119
119
|
let mimeType;
|
|
120
120
|
let data;
|
|
121
|
-
if (value && typeof value === 'object' && typeof value.path === 'string'
|
|
121
|
+
if (value && typeof value === 'object' && typeof value.path === 'string')
|
|
122
122
|
return showFile(value.path);
|
|
123
123
|
if (typeof value === 'string') {
|
|
124
124
|
const match = /^data:([^;,]+);base64,/.exec(value);
|
|
@@ -277,9 +277,9 @@ import{parentPort as $,workerData as qe}from"node:worker_threads";function le(a)
|
|
|
277
277
|
};
|
|
278
278
|
}`;function ge(a,e,t){let r=e?.match(/[\s(]codemode\.js:(\d+):(\d+)/);if(!r)return a;let s=Number(r[1])-1,n=t.split(/\r\n|[\n\r\u2028\u2029]/)[s-1];return n===void 0?a:`${a}
|
|
279
279
|
at code:${s}:${r[2]}
|
|
280
|
-
${n.slice(0,500)}`}function Ne(a,e){return a instanceof R?ge(`${a.name}: ${a.message}`,a.stack,e):a instanceof Error?a.message:"Script failed"}async function Te(a){let e,t=!1,r,s=0,n=0,i=0,o=0,c=0,u="",l=!1,d,h=a.maxSyncMs??U.maxSyncMs,w=performance.now(),g=new Set,_=new Set,I=new Set,O=new Set,x=0,E=p=>!Number.isSafeInteger(p)||p<1||p>c||g.has(p)?!1:(g.add(p),_.add(p),!0),
|
|
280
|
+
${n.slice(0,500)}`}function Ne(a,e){return a instanceof R?ge(`${a.name}: ${a.message}`,a.stack,e):a instanceof Error?a.message:"Script failed"}async function Te(a){let e,t=!1,r,s=0,n=0,i=0,o=0,c=0,u="",l=!1,d,h=a.maxSyncMs??U.maxSyncMs,w=performance.now(),g=new Set,_=new Set,I=new Set,O=new Set,x=0,E=p=>!Number.isSafeInteger(p)||p<1||p>c||g.has(p)?!1:(g.add(p),_.add(p),!0),j=p=>$?.postMessage(p),S=(p,b,v={})=>{t||(t=!0,j({type:"done",status:p,...v.errorKind?{errorKind:v.errorKind}:{},...v.limitKind?{limitKind:v.limitKind}:{},...v.storeWrites?.length?{storeWrites:v.storeWrites}:{},...b===void 0?{}:{error:b.slice(0,4e3)},..._.size?{pendingCallIds:[..._]}:{},...d!==void 0&&p==="completed"?{returnValue:d}:{}}))},k=[],B=!1;$?.on("message",p=>{B?ie(p):k.push(p)});let y=await Y.create({wasm:a.wasm,memoryLimit:U.memoryBytes,maxStackSize:G,interruptHandler:()=>t||e!==void 0&&Atomics.load(e,0)!==0?!0:performance.now()-w<=h?!1:(t=!0,j({type:"done",status:"timeout",error:`Script ran ${Math.round(h/1e3)}s without awaiting a tool call or returning; interrupted as a runaway loop. Await each call and split long computations.`,..._.size?{pendingCallIds:[..._]}:{}}),!0),onUnhandledRejection:(p,b,v)=>{r&&y.withScope(()=>y.callFunction(r,y.undefined,p,b,v?y.true:y.false))},wasi:p=>({fd_write:(b,v,D,q)=>{let N=new DataView(p.buffer),T=0;for(let A=0;A<D;A++)T+=N.getUint32(v+A*8+4,!0);return N.setUint32(q,T,!0),0}})}),f=p=>S("limit",me[p],{limitKind:p}),P=p=>(s+=Buffer.byteLength(p),s>U.outputBytes||++n>U.outputItems?(f("output"),!1):!0),L=p=>{P(p)&&j({type:"output",text:p})},_e=y.newFunction("codeModeBridge",(p,b,v,D)=>{if(t)return y.undefined;switch(p.toString()){case"attempt":c=b.toNumber(),c>U.calls&&f("calls");break;case"output":L(b.toString());break;case"search":{let q=b.toNumber(),N;try{N=JSON.parse(v.toString())}catch{N=void 0}let{query:T,limit:A,namespace:z}=N??{};if(q!==++x||typeof T!="string"||!Number.isSafeInteger(A)||z!==void 0&&typeof z!="string"){S("error","Invalid search bridge call");break}O.add(q),j({type:"search",id:q,query:T,limit:A,...z===void 0?{}:{namespace:z}});break}case"image":{let q=b.toString(),N=v.toString();if(o+=N.length,!Q.includes(q)||++i>U.images||o>U.imageBytes){f("images");break}j({type:"image",mimeType:q,data:N});break}case"imageFile":{let q=b.toNumber(),N=v.toString();if(!E(q)){S("error","Invalid image bridge call");break}j({type:"imageFile",id:q,path:N});break}case"call":{let q=b.toNumber(),N=v.toString(),T=D.toString();if(!I.has(N)||!E(q)){S("error","Invalid tool bridge call");break}j(Buffer.byteLength(T)>U.argumentBytes?{type:"call",id:q,name:N,args:"",argumentError:"Tool arguments exceed the byte limit"}:{type:"call",id:q,name:N,args:T});break}default:S("error","Invalid bridge message")}return y.undefined}),W=p=>{let b=p instanceof R&&p.name==="SyntaxError";S("error",Ne(p,u)+(b&&u.includes("`")?"\nIn template literals, escape embedded backticks as \\` and ${ as \\${.":""),{errorKind:b?"syntax":"script_exception"})},se,ne,oe,C,X=()=>{try{y.executePendingJobs(),setImmediate(()=>{!t&&_.size===0&&O.size===0&&S("incomplete","Script is waiting on a promise with no pending tool calls")})}catch(p){W(p)}},ye=p=>{l=!0,u=p.code,e=new Int32Array(p.interrupt);for(let v of p.tools)I.add(v);C=y.withScope(v=>v.escape(y.callFunction(y.evalCode(he,"codemode-prelude.js"),y.undefined,_e,y.newString(JSON.stringify(p.tools)),y.newString(JSON.stringify(p.directTools??[])),y.newString(JSON.stringify(p.toolCatalog??[])),y.newString(JSON.stringify(p.storeSnapshot??{})),y.newString(p.storeError??""),y.newString(JSON.stringify(p.namespaces??[]))))),se=C.getProp("settle"),ne=C.getProp("settleSearch"),oe=C.getProp("format"),r=C.getProp("trackRejection");let b=y.evalCode(`(async () => {
|
|
281
281
|
${u}
|
|
282
|
-
})()`,"codemode.js");y.markPromiseHandled(b),y.resolvePromise(b).then(
|
|
282
|
+
})()`,"codemode.js");y.markPromiseHandled(b),y.resolvePromise(b).then(v=>{if(!t)try{let D=(T,A=!1)=>{let z,K;try{y.withScope(()=>{let ae=T.getProp("stack");z=ae.isUndefined?void 0:ae.toString(),K=T.getProp("name").toString()})}catch{}let we=K==="StoreRestoreError"?"store_restore":A?"unhandled_rejection":K==="SyntaxError"?"syntax":K==="ToolCallError"?"tool_call":"script_exception";S("error",ge((A?"Unhandled promise rejection: ":"")+T.toString(),z,u),{errorKind:we})};if("error"in v){D(v.error);return}let q=y.withScope(T=>T.escape(y.callFunction(C.getProp("rejection"),C)));if(!q.isUndefined){y.withScope(()=>D(q.getProp("reason"),!0)),q.dispose();return}if(q.dispose(),_.size>0){S("incomplete","Script returned with pending tool calls");return}v.value.isUndefined||y.withScope(()=>{let T=y.callFunction(oe,C,v.value);if(T.isUndefined)return;let A=T.toString();P(A)&&(d=A)});let N=y.withScope(()=>y.callFunction(C.getProp("storeWrites"),C).toString());S("completed",void 0,{storeWrites:JSON.parse(N)})}catch(D){W(D)}},W),b.dispose(),X()},ie=p=>{if(!t){if(w=performance.now(),p?.type==="start"){if(l||typeof p.code!="string"||!Array.isArray(p.tools)||p.directTools!==void 0&&!Array.isArray(p.directTools)||p.toolCatalog!==void 0&&(!Array.isArray(p.toolCatalog)||!p.toolCatalog.every(b=>b&&typeof b.name=="string"&&typeof b.description=="string"))||p.namespaces!==void 0&&(!Array.isArray(p.namespaces)||!p.namespaces.every(b=>b&&typeof b.name=="string"&&Array.isArray(b.tools)))||!(p.interrupt instanceof SharedArrayBuffer)){S("error","Invalid start message");return}try{ye(p)}catch(b){W(b)}return}if(l&&p?.type==="searched"){if(!O.delete(p.id)||!Array.isArray(p.names)||!p.names.every(b=>typeof b=="string")){S("error","Invalid host search result");return}try{y.withScope(()=>y.callFunction(ne,C,y.newNumber(p.id),y.newString(JSON.stringify(p.names)))),X()}catch(b){W(b)}return}if(!l||!p||p.type!=="settle"||typeof p.ok!="boolean"||typeof p.payload!="string"||!_.delete(p.id)||Buffer.byteLength(p.payload)>U.resultBytes){S("error","Invalid host result");return}try{y.withScope(()=>y.callFunction(se,C,y.newNumber(p.id),p.ok?y.true:y.false,y.newString(p.payload))),p.ok&&j({type:"received",id:p.id}),X()}catch(b){W(b)}}};B=!0;for(let p of k.splice(0))ie(p)}$&&Te(qe).catch(()=>{$?.postMessage({type:"done",status:"error",error:"Unable to initialize the script VM",errorKind:"runtime_start"}),$?.close()});
|
|
283
283
|
/**
|
|
284
284
|
* @license
|
|
285
285
|
* Copyright 2026 Google LLC
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bundle/qoder-worker-runtime.mjs
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 35331108 bytes
|
|
4
|
+
sha256: c2d1af7ffcd911b95857891d435401b015cfebf14ea969dcd4456841ab4a691f
|
package/bundle/qodercli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bundle/qodercli.js
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 35117732 bytes
|
|
4
|
+
sha256: 66699ea0d17b4080445a8b22e628f150bbfbe137ee4acb57a4041fbc3a50f4d6
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qoder-ai/qodercli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.83",
|
|
4
4
|
"description": "Qoder AI CLI - AI-powered coding assistant",
|
|
5
5
|
"author": "Qoder AI",
|
|
6
6
|
"type": "module",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"sharp": "^0.34.5"
|
|
21
21
|
},
|
|
22
22
|
"optionalDependencies": {
|
|
23
|
-
"@qoder-ai/qodercli-ripgrep-darwin-arm64": "1.1.
|
|
24
|
-
"@qoder-ai/qodercli-ripgrep-darwin-x64": "1.1.
|
|
25
|
-
"@qoder-ai/qodercli-ripgrep-linux-arm64": "1.1.
|
|
26
|
-
"@qoder-ai/qodercli-ripgrep-linux-x64": "1.1.
|
|
27
|
-
"@qoder-ai/qodercli-ripgrep-win32-arm64": "1.1.
|
|
28
|
-
"@qoder-ai/qodercli-ripgrep-win32-x64": "1.1.
|
|
23
|
+
"@qoder-ai/qodercli-ripgrep-darwin-arm64": "1.1.83",
|
|
24
|
+
"@qoder-ai/qodercli-ripgrep-darwin-x64": "1.1.83",
|
|
25
|
+
"@qoder-ai/qodercli-ripgrep-linux-arm64": "1.1.83",
|
|
26
|
+
"@qoder-ai/qodercli-ripgrep-linux-x64": "1.1.83",
|
|
27
|
+
"@qoder-ai/qodercli-ripgrep-win32-arm64": "1.1.83",
|
|
28
|
+
"@qoder-ai/qodercli-ripgrep-win32-x64": "1.1.83"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=20.0.0"
|
package/postinstall.cjs
CHANGED
|
@@ -1,215 +1,243 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
|
|
24
|
+
// packages/cli/src/installation/install/windowsRegistryPath.ts
|
|
25
|
+
var windowsRegistryPath_exports = {};
|
|
26
|
+
__export(windowsRegistryPath_exports, {
|
|
27
|
+
readWindowsRegistryPath: () => readWindowsRegistryPath
|
|
28
|
+
});
|
|
29
|
+
function readWindowsRegistryPath(runReg) {
|
|
30
|
+
const directory = (0, import_node_fs.mkdtempSync)((0, import_node_path.join)((0, import_node_os.tmpdir)(), "qoder-registry-path-"));
|
|
31
|
+
try {
|
|
32
|
+
const file = (0, import_node_path.join)(directory, "environment.reg");
|
|
33
|
+
runReg(["export", "HKCU\\Environment", file, "/y"]);
|
|
34
|
+
return parseRegistryPathExport((0, import_node_fs.readFileSync)(file));
|
|
35
|
+
} finally {
|
|
36
|
+
(0, import_node_fs.rmSync)(directory, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function parseRegistryPathExport(bytes) {
|
|
40
|
+
if (bytes.length % 2 !== 0 || bytes[0] !== 255 || bytes[1] !== 254) {
|
|
41
|
+
throw new Error("Registry export is not BOM-marked UTF-16LE");
|
|
42
|
+
}
|
|
43
|
+
const text = new TextDecoder("utf-16le", { fatal: true }).decode(bytes);
|
|
44
|
+
if (!text.startsWith("Windows Registry Editor Version 5.00\r\n") || !text.endsWith("\r\n\r\n")) {
|
|
45
|
+
throw new Error("Unexpected registry export header");
|
|
46
|
+
}
|
|
47
|
+
const lines = text.replace(/\\\r?\n[ \t]*/g, "").split(/\r?\n/);
|
|
48
|
+
let inEnvironment = false;
|
|
49
|
+
let foundEnvironment = false;
|
|
50
|
+
let entry = null;
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
if (line.startsWith("[")) {
|
|
53
|
+
inEnvironment = /^\[HKEY_CURRENT_USER\\Environment\]$/i.test(line);
|
|
54
|
+
foundEnvironment ||= inEnvironment;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!inEnvironment || !/^"Path"/i.test(line)) continue;
|
|
58
|
+
if (!/^"Path"=/i.test(line)) {
|
|
59
|
+
throw new Error("Malformed PATH entry in registry export");
|
|
60
|
+
}
|
|
61
|
+
if (entry !== null) throw new Error("Duplicate PATH in registry export");
|
|
62
|
+
const data = line.slice('"Path"='.length);
|
|
63
|
+
if (data.startsWith('"')) {
|
|
64
|
+
const value2 = JSON.parse(data);
|
|
65
|
+
if (typeof value2 !== "string" || value2.includes("\0")) {
|
|
66
|
+
throw new Error("Invalid registry PATH string");
|
|
67
|
+
}
|
|
68
|
+
entry = { value: value2, type: "REG_SZ" };
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const hex = /^hex\(([12])\):((?:[0-9a-f]{2},)*[0-9a-f]{2})$/i.exec(data);
|
|
72
|
+
if (!hex) throw new Error("Unsupported or malformed registry PATH value");
|
|
73
|
+
const valueBytes = Buffer.from(hex[2].replace(/,/g, ""), "hex");
|
|
74
|
+
if (valueBytes.length < 2 || valueBytes.length % 2 !== 0 || valueBytes.readUInt16LE(valueBytes.length - 2) !== 0) {
|
|
75
|
+
throw new Error("Invalid registry PATH string terminator");
|
|
76
|
+
}
|
|
77
|
+
const value = new TextDecoder("utf-16le", {
|
|
78
|
+
fatal: true,
|
|
79
|
+
ignoreBOM: true
|
|
80
|
+
}).decode(valueBytes.subarray(0, -2));
|
|
81
|
+
if (value.includes("\0")) throw new Error("Invalid registry PATH string");
|
|
82
|
+
entry = { value, type: hex[1] === "2" ? "REG_EXPAND_SZ" : "REG_SZ" };
|
|
83
|
+
}
|
|
84
|
+
if (!foundEnvironment) throw new Error("Registry export omitted Environment");
|
|
85
|
+
return entry;
|
|
86
|
+
}
|
|
87
|
+
var import_node_fs, import_node_os, import_node_path;
|
|
88
|
+
var init_windowsRegistryPath = __esm({
|
|
89
|
+
"packages/cli/src/installation/install/windowsRegistryPath.ts"() {
|
|
90
|
+
"use strict";
|
|
91
|
+
import_node_fs = require("node:fs");
|
|
92
|
+
import_node_os = require("node:os");
|
|
93
|
+
import_node_path = require("node:path");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
25
96
|
|
|
97
|
+
// scripts/postinstall-npm-bundle.cjs
|
|
26
98
|
try {
|
|
27
99
|
warnIfRipgrepUnavailable();
|
|
28
100
|
} catch {
|
|
29
|
-
// Silent — never break npm install
|
|
30
101
|
}
|
|
31
|
-
|
|
32
|
-
// --- Windows PATH registration ---
|
|
33
|
-
if (process.platform === 'win32') {
|
|
102
|
+
if (process.platform === "win32") {
|
|
34
103
|
try {
|
|
35
104
|
ensureNpmBinOnPath();
|
|
36
105
|
} catch {
|
|
37
|
-
// Silent — never break npm install
|
|
38
106
|
}
|
|
39
107
|
}
|
|
40
|
-
|
|
41
|
-
// --- Dispatcher + PATH configuration (all platforms) ---
|
|
42
|
-
// `qoder` should resolve to the entry-point dispatcher rather than the npm
|
|
43
|
-
// shim so multi-channel users (npm + IDE) get consistent routing. We invoke
|
|
44
|
-
// the freshly-installed CLI's hidden `configure-path` subcommand which
|
|
45
|
-
// writes `~/.qoder/entry/<brand>` and prepends the entry dir onto PATH.
|
|
46
|
-
//
|
|
47
|
-
// Brand-neutral: we read the CLI bin path from the package's own
|
|
48
|
-
// package.json `bin` field so the same script handles Global (qodercli) and
|
|
49
|
-
// CN (qoderclicn) without publish-time sed rendering.
|
|
50
108
|
try {
|
|
51
109
|
configurePathBestEffort();
|
|
52
110
|
} catch {
|
|
53
|
-
// Never break npm install
|
|
54
111
|
}
|
|
55
|
-
|
|
56
112
|
function configurePathBestEffort() {
|
|
57
|
-
const fs = require(
|
|
58
|
-
const path = require(
|
|
59
|
-
const { spawnSync } = require(
|
|
60
|
-
|
|
61
|
-
const pkgJsonPath = path.resolve(__dirname, 'package.json');
|
|
113
|
+
const fs = require("node:fs");
|
|
114
|
+
const path = require("node:path");
|
|
115
|
+
const { spawnSync } = require("node:child_process");
|
|
116
|
+
const pkgJsonPath = path.resolve(__dirname, "package.json");
|
|
62
117
|
if (!fs.existsSync(pkgJsonPath)) return;
|
|
63
|
-
|
|
64
|
-
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
118
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
65
119
|
const bins = pkgJson.bin || {};
|
|
66
|
-
const cliBinName = [
|
|
120
|
+
const cliBinName = ["qodercli", "qoderclicn"].find((name) => bins[name]);
|
|
67
121
|
if (!cliBinName) return;
|
|
68
|
-
|
|
69
122
|
const cliPath = path.resolve(__dirname, bins[cliBinName]);
|
|
70
123
|
if (!fs.existsSync(cliPath)) return;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// returns exit code 0, and its stdout banner is the user-facing signal.
|
|
75
|
-
spawnSync(process.execPath, [cliPath, 'configure-path'], {
|
|
76
|
-
stdio: 'inherit',
|
|
77
|
-
timeout: 30_000,
|
|
124
|
+
spawnSync(process.execPath, [cliPath, "configure-path"], {
|
|
125
|
+
stdio: "inherit",
|
|
126
|
+
timeout: 3e4
|
|
78
127
|
});
|
|
79
128
|
}
|
|
80
|
-
|
|
81
129
|
function warnIfRipgrepUnavailable() {
|
|
82
|
-
const { execFileSync } = require(
|
|
83
|
-
const { readFileSync } = require(
|
|
84
|
-
const path = require(
|
|
130
|
+
const { execFileSync } = require("node:child_process");
|
|
131
|
+
const { readFileSync: readFileSync2 } = require("node:fs");
|
|
132
|
+
const path = require("node:path");
|
|
85
133
|
const manifest = JSON.parse(
|
|
86
|
-
|
|
134
|
+
readFileSync2(path.join(__dirname, "package.json"), "utf8")
|
|
87
135
|
);
|
|
88
136
|
const packageSuffix = `-ripgrep-${process.platform}-${process.arch}`;
|
|
89
137
|
const ripgrepPackage = Object.keys(manifest.optionalDependencies || {}).find(
|
|
90
|
-
(packageName) => packageName.endsWith(packageSuffix)
|
|
138
|
+
(packageName) => packageName.endsWith(packageSuffix)
|
|
91
139
|
);
|
|
92
|
-
const binaryName = process.platform ===
|
|
93
|
-
|
|
140
|
+
const binaryName = process.platform === "win32" ? "rg.exe" : "rg";
|
|
94
141
|
if (ripgrepPackage) {
|
|
95
142
|
try {
|
|
96
143
|
require.resolve(`${ripgrepPackage}/bin/${binaryName}`, {
|
|
97
|
-
paths: [__dirname]
|
|
144
|
+
paths: [__dirname]
|
|
98
145
|
});
|
|
99
146
|
return;
|
|
100
147
|
} catch {
|
|
101
|
-
// The optional dependency may have been explicitly omitted.
|
|
102
148
|
}
|
|
103
149
|
}
|
|
104
|
-
|
|
105
150
|
try {
|
|
106
|
-
execFileSync(
|
|
107
|
-
stdio:
|
|
108
|
-
windowsHide: true
|
|
151
|
+
execFileSync("rg", ["--version"], {
|
|
152
|
+
stdio: "ignore",
|
|
153
|
+
windowsHide: true
|
|
109
154
|
});
|
|
110
155
|
return;
|
|
111
156
|
} catch {
|
|
112
|
-
// Fall through to an actionable, non-fatal warning.
|
|
113
157
|
}
|
|
114
|
-
|
|
115
158
|
console.log(
|
|
116
|
-
|
|
117
|
-
'\n Glob and Grep require ripgrep.\n',
|
|
159
|
+
"\n ripgrep is unavailable. Reinstall without --omit=optional, or install rg on PATH.\n Glob and Grep require ripgrep.\n"
|
|
118
160
|
);
|
|
119
161
|
}
|
|
120
|
-
|
|
121
162
|
function ensureNpmBinOnPath() {
|
|
122
|
-
const { execSync } = require(
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// (not in a /bin subfolder like Unix).
|
|
163
|
+
const { execFileSync, execSync } = require("node:child_process");
|
|
164
|
+
const {
|
|
165
|
+
readWindowsRegistryPath: readWindowsRegistryPath2
|
|
166
|
+
} = (init_windowsRegistryPath(), __toCommonJS(windowsRegistryPath_exports));
|
|
167
|
+
const path = require("node:path");
|
|
128
168
|
let npmBinDir;
|
|
129
169
|
if (process.env.npm_config_prefix) {
|
|
130
|
-
// npm sets this env var during lifecycle scripts
|
|
131
170
|
npmBinDir = process.env.npm_config_prefix;
|
|
132
171
|
} else {
|
|
133
|
-
// Fallback: ask npm directly
|
|
134
172
|
try {
|
|
135
|
-
npmBinDir = execSync(
|
|
136
|
-
encoding:
|
|
137
|
-
timeout:
|
|
173
|
+
npmBinDir = execSync("npm prefix -g", {
|
|
174
|
+
encoding: "utf-8",
|
|
175
|
+
timeout: 1e4
|
|
138
176
|
}).trim();
|
|
139
177
|
} catch {
|
|
140
|
-
return;
|
|
178
|
+
return;
|
|
141
179
|
}
|
|
142
180
|
}
|
|
143
|
-
|
|
144
181
|
if (!npmBinDir) return;
|
|
145
|
-
|
|
146
|
-
// Normalize path for consistent comparison
|
|
147
182
|
npmBinDir = path.normalize(npmBinDir);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// HKEY_CURRENT_USER\Environment
|
|
158
|
-
// Path REG_EXPAND_SZ value
|
|
159
|
-
const match = output.match(/Path\s+REG_(?:EXPAND_SZ|SZ)\s+(.*)/i);
|
|
160
|
-
if (match) currentPath = match[1].trim();
|
|
161
|
-
} catch {
|
|
162
|
-
// Key might not exist — start fresh
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// 3. Check if already present (case-insensitive, normalized comparison)
|
|
166
|
-
const entries = currentPath
|
|
167
|
-
.split(';')
|
|
168
|
-
.map((p) => path.normalize(p.trim()).toLowerCase())
|
|
169
|
-
.filter((p) => p.length > 0);
|
|
170
|
-
|
|
183
|
+
const registry = readWindowsRegistryPath2(
|
|
184
|
+
(args) => execFileSync("reg.exe", args, {
|
|
185
|
+
timeout: 1e4,
|
|
186
|
+
windowsHide: true,
|
|
187
|
+
stdio: "ignore"
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
const currentPath = registry?.value ?? "";
|
|
191
|
+
const entries = currentPath.split(";").map((p) => path.normalize(p.trim()).toLowerCase()).filter((p) => p.length > 0);
|
|
171
192
|
if (entries.includes(npmBinDir.toLowerCase())) {
|
|
172
|
-
return;
|
|
193
|
+
return;
|
|
173
194
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
const newPath = currentPath ? currentPath + ";" + npmBinDir : npmBinDir;
|
|
196
|
+
execFileSync(
|
|
197
|
+
"reg.exe",
|
|
198
|
+
[
|
|
199
|
+
"add",
|
|
200
|
+
"HKCU\\Environment",
|
|
201
|
+
"/v",
|
|
202
|
+
"Path",
|
|
203
|
+
"/t",
|
|
204
|
+
registry?.type ?? "REG_EXPAND_SZ",
|
|
205
|
+
"/d",
|
|
206
|
+
newPath,
|
|
207
|
+
"/f"
|
|
208
|
+
],
|
|
209
|
+
{ timeout: 1e4, stdio: "ignore", windowsHide: true }
|
|
184
210
|
);
|
|
185
|
-
|
|
186
|
-
// 6. Broadcast WM_SETTINGCHANGE so new Explorer/shell windows pick up
|
|
187
|
-
// the change without requiring a reboot.
|
|
188
|
-
// Note: Already-open PowerShell/CMD windows will NOT refresh.
|
|
189
211
|
try {
|
|
190
212
|
const ps = [
|
|
191
213
|
"Add-Type -Namespace Win32 -Name NM -MemberDefinition '",
|
|
192
214
|
'[DllImport("user32.dll",SetLastError=true,CharSet=CharSet.Auto)]',
|
|
193
|
-
|
|
194
|
-
|
|
215
|
+
"public static extern IntPtr SendMessageTimeout(",
|
|
216
|
+
"IntPtr hWnd,uint Msg,UIntPtr wParam,string lParam,",
|
|
195
217
|
"uint fuFlags,uint uTimeout,out UIntPtr lpdwResult);';",
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
"$r=[UIntPtr]::Zero;",
|
|
219
|
+
"[Win32.NM]::SendMessageTimeout(",
|
|
198
220
|
'[IntPtr]0xFFFF,0x001A,[UIntPtr]::Zero,"Environment",',
|
|
199
|
-
|
|
200
|
-
].join(
|
|
221
|
+
"2,5000,[ref]$r)|Out-Null"
|
|
222
|
+
].join(" ");
|
|
201
223
|
execSync(`powershell -NoProfile -Command "${ps}"`, {
|
|
202
|
-
encoding:
|
|
203
|
-
timeout:
|
|
204
|
-
stdio:
|
|
224
|
+
encoding: "utf-8",
|
|
225
|
+
timeout: 15e3,
|
|
226
|
+
stdio: "ignore"
|
|
205
227
|
});
|
|
206
228
|
} catch {
|
|
207
|
-
// Non-fatal — PATH change is persisted in registry regardless
|
|
208
229
|
}
|
|
209
|
-
|
|
210
|
-
// 7. User-facing hint
|
|
211
230
|
console.log(
|
|
212
|
-
'\n \u2713 Added npm global bin directory to PATH
|
|
213
|
-
'\n Please restart your terminal to use "qodercli".\n',
|
|
231
|
+
'\n \u2713 Added npm global bin directory to PATH.\n Please restart your terminal to use "qodercli".\n'
|
|
214
232
|
);
|
|
215
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* @license
|
|
236
|
+
* Copyright 2026 Google LLC
|
|
237
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
238
|
+
*/
|
|
239
|
+
/**
|
|
240
|
+
* @license
|
|
241
|
+
* Copyright 2025 Google LLC
|
|
242
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
243
|
+
*/
|
package/bundle/proto/chat.proto
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
package model.chat;
|
|
4
|
-
|
|
5
|
-
import "google/protobuf/struct.proto";
|
|
6
|
-
import "google/protobuf/wrappers.proto";
|
|
7
|
-
|
|
8
|
-
option java_multiple_files = true;
|
|
9
|
-
option java_package = "com.qoder.grpc.model.chat";
|
|
10
|
-
option java_outer_classname = "ChatProto";
|
|
11
|
-
|
|
12
|
-
// Reasoning effort level for model reasoning
|
|
13
|
-
enum ReasoningEffort {
|
|
14
|
-
REASONING_EFFORT_UNSPECIFIED = 0;
|
|
15
|
-
REASONING_EFFORT_NONE = 1;
|
|
16
|
-
REASONING_EFFORT_LOW = 2;
|
|
17
|
-
REASONING_EFFORT_MEDIUM = 3;
|
|
18
|
-
REASONING_EFFORT_HIGH = 4;
|
|
19
|
-
REASONING_EFFORT_XHIGH = 5;
|
|
20
|
-
REASONING_EFFORT_MAX = 6;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ─── Request messages ────────────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
// Chat completion request matching OpenAI-compatible API
|
|
26
|
-
message ChatCompletionRequest {
|
|
27
|
-
string model = 1;
|
|
28
|
-
repeated ChatMessage messages = 2;
|
|
29
|
-
google.protobuf.DoubleValue temperature = 3;
|
|
30
|
-
google.protobuf.DoubleValue top_p = 4;
|
|
31
|
-
google.protobuf.Int32Value max_tokens = 5;
|
|
32
|
-
bool stream = 6;
|
|
33
|
-
repeated string stop = 7;
|
|
34
|
-
google.protobuf.DoubleValue presence_penalty = 8;
|
|
35
|
-
google.protobuf.DoubleValue frequency_penalty = 9;
|
|
36
|
-
google.protobuf.Int32Value n = 10;
|
|
37
|
-
google.protobuf.StringValue user = 11;
|
|
38
|
-
google.protobuf.Int32Value seed = 12;
|
|
39
|
-
Reasoning reasoning = 13;
|
|
40
|
-
google.protobuf.BoolValue parallel_tool_calls = 14;
|
|
41
|
-
map<string, double> logit_bias = 15;
|
|
42
|
-
repeated Tool tools = 16;
|
|
43
|
-
google.protobuf.Value tool_choice = 17;
|
|
44
|
-
ResponseFormat response_format = 18;
|
|
45
|
-
repeated string modalities = 19;
|
|
46
|
-
StreamOptions stream_options = 20;
|
|
47
|
-
map<string, ChatPatchList> patches = 21;
|
|
48
|
-
ChatMetadata metadata = 22;
|
|
49
|
-
google.protobuf.Struct extras = 23;
|
|
50
|
-
CustomModelConfig custom_model = 24;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Wrapper for repeated ChatPatch (used in patches map value)
|
|
54
|
-
message ChatPatchList {
|
|
55
|
-
repeated ChatPatch patches = 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Chat message in the conversation (request side)
|
|
59
|
-
message ChatMessage {
|
|
60
|
-
string cache_id = 1;
|
|
61
|
-
string role = 2;
|
|
62
|
-
// content can be plain text or a list of multimodal content parts
|
|
63
|
-
oneof content_type {
|
|
64
|
-
string text_content = 3;
|
|
65
|
-
ContentPartList parts_content = 12;
|
|
66
|
-
}
|
|
67
|
-
google.protobuf.StringValue name = 4;
|
|
68
|
-
repeated ToolCall tool_calls = 5;
|
|
69
|
-
google.protobuf.StringValue tool_call_id = 6;
|
|
70
|
-
google.protobuf.StringValue tool_call_call_id = 7;
|
|
71
|
-
google.protobuf.StringValue reasoning_content = 8;
|
|
72
|
-
ReasoningItem reasoning_item = 9;
|
|
73
|
-
google.protobuf.Struct extends = 10;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Wrapper for repeated ContentPart
|
|
77
|
-
message ContentPartList {
|
|
78
|
-
repeated ContentPart parts = 1;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Content part for multimodal messages
|
|
82
|
-
message ContentPart {
|
|
83
|
-
string type = 1;
|
|
84
|
-
google.protobuf.StringValue text = 2;
|
|
85
|
-
ImageUrl image_url = 3;
|
|
86
|
-
InputAudio input_audio = 4;
|
|
87
|
-
CacheControl cache_control = 5;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Cache control configuration for content parts
|
|
91
|
-
message CacheControl {
|
|
92
|
-
string type = 1;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Image URL in message content
|
|
96
|
-
message ImageUrl {
|
|
97
|
-
string url = 1;
|
|
98
|
-
google.protobuf.StringValue detail = 2;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Audio input in message content
|
|
102
|
-
message InputAudio {
|
|
103
|
-
string data = 1;
|
|
104
|
-
string format = 2;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Reasoning item for model series (e.g. gpt-5)
|
|
108
|
-
message ReasoningItem {
|
|
109
|
-
string id = 1;
|
|
110
|
-
google.protobuf.StringValue encrypted_content = 2;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Streaming options
|
|
114
|
-
message StreamOptions {
|
|
115
|
-
google.protobuf.BoolValue include_usage = 1;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Tool available for the model to call
|
|
119
|
-
message Tool {
|
|
120
|
-
string cache_id = 1;
|
|
121
|
-
string type = 2;
|
|
122
|
-
Function function = 3;
|
|
123
|
-
Advisor advisor = 4;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Function definition
|
|
127
|
-
message Function {
|
|
128
|
-
string name = 1;
|
|
129
|
-
google.protobuf.StringValue description = 2;
|
|
130
|
-
google.protobuf.Struct parameters = 3;
|
|
131
|
-
google.protobuf.BoolValue strict = 4;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Advisor definition
|
|
135
|
-
message Advisor {
|
|
136
|
-
string name = 1;
|
|
137
|
-
string model = 2;
|
|
138
|
-
int32 max_uses = 3;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Tool call made by the assistant
|
|
142
|
-
message ToolCall {
|
|
143
|
-
google.protobuf.StringValue id = 1;
|
|
144
|
-
google.protobuf.StringValue call_id = 2;
|
|
145
|
-
google.protobuf.StringValue type = 3;
|
|
146
|
-
FunctionCall function = 4;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Function call details
|
|
150
|
-
message FunctionCall {
|
|
151
|
-
string name = 1;
|
|
152
|
-
google.protobuf.Value arguments = 2;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Reasoning configuration
|
|
156
|
-
message Reasoning {
|
|
157
|
-
ReasoningEffort effort = 1;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Response format specification
|
|
161
|
-
message ResponseFormat {
|
|
162
|
-
string type = 1;
|
|
163
|
-
JsonSchema json_schema = 2;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// JSON schema for structured outputs
|
|
167
|
-
message JsonSchema {
|
|
168
|
-
string name = 1;
|
|
169
|
-
google.protobuf.StringValue description = 2;
|
|
170
|
-
google.protobuf.Struct schema = 3;
|
|
171
|
-
google.protobuf.BoolValue strict = 4;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Metadata attached to the chat request
|
|
175
|
-
message ChatMetadata {
|
|
176
|
-
WorkspaceMetadata workspace = 1;
|
|
177
|
-
BusinessMetadata business = 2;
|
|
178
|
-
ContextMetadata context = 3;
|
|
179
|
-
UserMetadata user = 4;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Workspace metadata
|
|
183
|
-
message WorkspaceMetadata {
|
|
184
|
-
int32 file_count = 1;
|
|
185
|
-
repeated string languages = 2;
|
|
186
|
-
string codebase_status = 3;
|
|
187
|
-
string codebase_soft_status = 4;
|
|
188
|
-
string codebase_external_id = 5;
|
|
189
|
-
string data_policy = 6;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Business metadata
|
|
193
|
-
message BusinessMetadata {
|
|
194
|
-
string id = 1;
|
|
195
|
-
string name = 2;
|
|
196
|
-
int64 begin_at = 3;
|
|
197
|
-
string product = 4;
|
|
198
|
-
string version = 5;
|
|
199
|
-
string type = 6;
|
|
200
|
-
string stage = 7;
|
|
201
|
-
string sub_task = 8;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Context metadata for request tracing and client identification
|
|
205
|
-
message ContextMetadata {
|
|
206
|
-
string request_id = 1;
|
|
207
|
-
string session_id = 2;
|
|
208
|
-
string task_id = 3;
|
|
209
|
-
string request_set_id = 4;
|
|
210
|
-
string machine_id = 5;
|
|
211
|
-
string client_type = 6;
|
|
212
|
-
string source_session_id = 7;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// User metadata
|
|
216
|
-
message UserMetadata {
|
|
217
|
-
string user_id = 1;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Custom model configuration (bring-your-own-key)
|
|
221
|
-
message CustomModelConfig {
|
|
222
|
-
string name = 1;
|
|
223
|
-
string url = 2;
|
|
224
|
-
string style = 3;
|
|
225
|
-
string provider = 4;
|
|
226
|
-
string type = 5;
|
|
227
|
-
string model = 6;
|
|
228
|
-
google.protobuf.Struct parameters = 7;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Patch to apply to the chat request
|
|
232
|
-
message ChatPatch {
|
|
233
|
-
string cache_id = 1;
|
|
234
|
-
string action = 2;
|
|
235
|
-
google.protobuf.Int32Value position = 3;
|
|
236
|
-
google.protobuf.StringValue content = 4;
|
|
237
|
-
google.protobuf.StringValue name = 5;
|
|
238
|
-
google.protobuf.StringValue rename_to = 6;
|
|
239
|
-
google.protobuf.StringValue description = 7;
|
|
240
|
-
google.protobuf.Struct parameters = 8;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ─── Response messages ───────────────────────────────────────────────────────
|
|
244
|
-
|
|
245
|
-
// Shared response chat message type (used in both streaming delta and
|
|
246
|
-
// non-streaming message fields)
|
|
247
|
-
message ResponseChatMessage {
|
|
248
|
-
string role = 1;
|
|
249
|
-
string content = 2;
|
|
250
|
-
string reasoning_content = 3;
|
|
251
|
-
repeated google.protobuf.Struct tool_calls = 4;
|
|
252
|
-
google.protobuf.Value reasoning_item = 5;
|
|
253
|
-
google.protobuf.Struct extends = 6;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Single choice in the non-streaming response
|
|
257
|
-
message NonStreamChoice {
|
|
258
|
-
int32 index = 1;
|
|
259
|
-
ResponseChatMessage message = 2;
|
|
260
|
-
string finish_reason = 3;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Chat completion response (non-streaming)
|
|
264
|
-
message ChatCompletionResponse {
|
|
265
|
-
int64 code = 1;
|
|
266
|
-
string id = 2;
|
|
267
|
-
string object = 3;
|
|
268
|
-
int64 created = 4;
|
|
269
|
-
string model = 5;
|
|
270
|
-
repeated NonStreamChoice choices = 6;
|
|
271
|
-
Usage usage = 7;
|
|
272
|
-
google.protobuf.Struct extras = 8;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Single choice in the streaming chunk
|
|
276
|
-
message StreamChoice {
|
|
277
|
-
int32 index = 1;
|
|
278
|
-
ResponseChatMessage delta = 2;
|
|
279
|
-
string finish_reason = 3;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Streaming response chunk
|
|
283
|
-
message ChatCompletionChunk {
|
|
284
|
-
int64 code = 1;
|
|
285
|
-
string id = 2;
|
|
286
|
-
string object = 3;
|
|
287
|
-
int64 created = 4;
|
|
288
|
-
string model = 5;
|
|
289
|
-
repeated StreamChoice choices = 6;
|
|
290
|
-
Usage usage = 7;
|
|
291
|
-
google.protobuf.Struct extras = 8;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Token usage statistics
|
|
295
|
-
message Usage {
|
|
296
|
-
int32 prompt_tokens = 1;
|
|
297
|
-
int32 completion_tokens = 2;
|
|
298
|
-
int32 total_tokens = 3;
|
|
299
|
-
PromptTokensDetails prompt_tokens_details = 4;
|
|
300
|
-
CompletionTokensDetails completion_tokens_details = 5;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Prompt token details
|
|
304
|
-
message PromptTokensDetails {
|
|
305
|
-
int32 cached_tokens = 1;
|
|
306
|
-
int32 cacheable_tokens = 2;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Completion token details
|
|
310
|
-
message CompletionTokensDetails {
|
|
311
|
-
int32 reasoning_tokens = 1;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// ─── Service definition ──────────────────────────────────────────────────────
|
|
315
|
-
|
|
316
|
-
service ChatService {
|
|
317
|
-
// Unary non-streaming chat completion
|
|
318
|
-
rpc ChatCompletion(ChatCompletionRequest) returns (ChatCompletionResponse);
|
|
319
|
-
|
|
320
|
-
// Server-streaming chat completion; each message is one SSE chunk
|
|
321
|
-
rpc ChatCompletionStream(ChatCompletionRequest) returns (stream ChatCompletionChunk);
|
|
322
|
-
}
|