@cristianglezm/vue-chatbot-widget
Version:
[](https://github.com/cristianglezm/vue-chatbot-widget/actions/workflows/cd.yml) [=>Dr in Ds?rE(Ds,Dr,{enumerable:!0,configurable:!0,writable:!0,value:ta}):Ds[Dr]=ta;var X=(Ds,Dr,ta)=>sE(Ds,typeof Dr!="symbol"?Dr+"":Dr,ta);(function(){"use strict";const Ds=new Map,Dr=[],ta=(e,r,t)=>{if(r&&typeof r.init=="function"&&typeof r.createInferenceSessionHandler=="function"){const s=Ds.get(e);if(s===void 0)Ds.set(e,{backend:r,priority:t});else{if(s.priority>t)return;if(s.priority===t&&s.backend!==r)throw new Error(`cannot register backend "${e}" using priority ${t}`)}if(t>=0){const a=Dr.indexOf(e);a!==-1&&Dr.splice(a,1);for(let n=0;n<Dr.length;n++)if(Ds.get(Dr[n]).priority<=t){Dr.splice(n,0,e);return}Dr.push(e)}return}throw new TypeError("not a valid backend")},vv=async e=>{const r=Ds.get(e);if(!r)return"backend not found.";if(r.initialized)return r.backend;if(r.aborted)return r.error;{const t=!!r.initPromise;try{return t||(r.initPromise=r.backend.init(e)),await r.initPromise,r.initialized=!0,r.backend}catch(s){return t||(r.error=`${s}`,r.aborted=!0),r.error}finally{delete r.initPromise}}},dp=async e=>{const r=e.executionProviders||[],t=r.map(l=>typeof l=="string"?l:l.name),s=t.length===0?Dr:t;let a;const n=[],i=new Set;for(const l of s){const c=await vv(l);typeof c=="string"?n.push({name:l,err:c}):(a||(a=c),a===c&&i.add(l))}if(!a)throw new Error(`no available backend found. ERR: ${n.map(l=>`[${l.name}] ${l.err}`).join(", ")}`);for(const{name:l,err:c}of n)t.includes(l)&&console.warn(`removing requested execution provider "${l}" from session options because it is not available: ${c}`);const o=r.filter(l=>i.has(typeof l=="string"?l:l.name));return[a,new Proxy(e,{get:(l,c)=>c==="executionProviders"?o:Reflect.get(l,c)})]},xv="1.20.1";let pp="warning";const ps={wasm:{},webgl:{},webgpu:{},versions:{common:xv},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);pp=e}},get logLevel(){return pp}};Object.defineProperty(ps,"logLevel",{enumerable:!0});const Tv=ps,Ev=(e,r)=>{const t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];const s=t.getContext("2d");if(s!=null){let a,n;(r==null?void 0:r.tensorLayout)!==void 0&&r.tensorLayout==="NHWC"?(a=e.dims[2],n=e.dims[3]):(a=e.dims[3],n=e.dims[2]);const i=(r==null?void 0:r.format)!==void 0?r.format:"RGB",o=r==null?void 0:r.norm;let l,c;o===void 0||o.mean===void 0?l=[255,255,255,255]:typeof o.mean=="number"?l=[o.mean,o.mean,o.mean,o.mean]:(l=[o.mean[0],o.mean[1],o.mean[2],0],o.mean[3]!==void 0&&(l[3]=o.mean[3])),o===void 0||o.bias===void 0?c=[0,0,0,0]:typeof o.bias=="number"?c=[o.bias,o.bias,o.bias,o.bias]:(c=[o.bias[0],o.bias[1],o.bias[2],0],o.bias[3]!==void 0&&(c[3]=o.bias[3]));const p=n*a;let d=0,h=p,g=p*2,_=-1;i==="RGBA"?(d=0,h=p,g=p*2,_=p*3):i==="RGB"?(d=0,h=p,g=p*2):i==="RBG"&&(d=0,g=p,h=p*2);for(let E=0;E<n;E++)for(let A=0;A<a;A++){const M=(e.data[d++]-c[0])*l[0],y=(e.data[h++]-c[1])*l[1],k=(e.data[g++]-c[2])*l[2],P=_===-1?255:(e.data[_++]-c[3])*l[3];s.fillStyle="rgba("+M+","+y+","+k+","+P+")",s.fillRect(A,E,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Pv=(e,r)=>{const t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let s;if(t!=null){let a,n,i;(r==null?void 0:r.tensorLayout)!==void 0&&r.tensorLayout==="NHWC"?(a=e.dims[2],n=e.dims[1],i=e.dims[3]):(a=e.dims[3],n=e.dims[2],i=e.dims[1]);const o=r!==void 0&&r.format!==void 0?r.format:"RGB",l=r==null?void 0:r.norm;let c,p;l===void 0||l.mean===void 0?c=[255,255,255,255]:typeof l.mean=="number"?c=[l.mean,l.mean,l.mean,l.mean]:(c=[l.mean[0],l.mean[1],l.mean[2],255],l.mean[3]!==void 0&&(c[3]=l.mean[3])),l===void 0||l.bias===void 0?p=[0,0,0,0]:typeof l.bias=="number"?p=[l.bias,l.bias,l.bias,l.bias]:(p=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(p[3]=l.bias[3]));const d=n*a;if(r!==void 0&&(r.format!==void 0&&i===4&&r.format!=="RGBA"||i===3&&r.format!=="RGB"&&r.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");const h=4;let g=0,_=1,E=2,A=3,M=0,y=d,k=d*2,P=-1;o==="RGBA"?(M=0,y=d,k=d*2,P=d*3):o==="RGB"?(M=0,y=d,k=d*2):o==="RBG"&&(M=0,k=d,y=d*2),s=t.createImageData(a,n);for(let b=0;b<n*a;g+=h,_+=h,E+=h,A+=h,b++)s.data[g]=(e.data[M++]-p[0])*c[0],s.data[_]=(e.data[y++]-p[1])*c[1],s.data[E]=(e.data[k++]-p[2])*c[2],s.data[A]=P===-1?255:(e.data[P++]-p[3])*c[3]}else throw new Error("Can not access image data");return s},Dc=(e,r)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(r.height===void 0||r.width===void 0)throw new Error("Image height and width must be defined");if(r.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");const{height:t,width:s}=r,a=r.norm??{mean:255,bias:0};let n,i;typeof a.mean=="number"?n=[a.mean,a.mean,a.mean,a.mean]:n=[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],typeof a.bias=="number"?i=[a.bias,a.bias,a.bias,a.bias]:i=[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];const o=r.format!==void 0?r.format:"RGBA",l=r.tensorFormat!==void 0&&r.tensorFormat!==void 0?r.tensorFormat:"RGB",c=t*s,p=l==="RGBA"?new Float32Array(c*4):new Float32Array(c*3);let d=4,h=0,g=1,_=2,E=3,A=0,M=c,y=c*2,k=-1;o==="RGB"&&(d=3,h=0,g=1,_=2,E=-1),l==="RGBA"?k=c*3:l==="RBG"?(A=0,y=c,M=c*2):l==="BGR"&&(y=0,M=c,A=c*2);for(let b=0;b<c;b++,h+=d,_+=d,g+=d,E+=d)p[A++]=(e[h]+i[0])/n[0],p[M++]=(e[g]+i[1])/n[1],p[y++]=(e[_]+i[2])/n[2],k!==-1&&E!==-1&&(p[k++]=(e[E]+i[3])/n[3]);return l==="RGBA"?new ts("float32",p,[1,4,t,s]):new ts("float32",p,[1,3,t,s])},Cv=async(e,r)=>{const t=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,s=typeof ImageData<"u"&&e instanceof ImageData,a=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,n=typeof e=="string";let i,o=r??{};const l=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=p=>typeof HTMLCanvasElement<"u"&&p instanceof HTMLCanvasElement||p instanceof OffscreenCanvas?p.getContext("2d"):null;if(t){const p=l();p.width=e.width,p.height=e.height;const d=c(p);if(d!=null){let h=e.height,g=e.width;if(r!==void 0&&r.resizedHeight!==void 0&&r.resizedWidth!==void 0&&(h=r.resizedHeight,g=r.resizedWidth),r!==void 0){if(o=r,r.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");o.tensorFormat="RGBA",o.height=h,o.width=g}else o.tensorFormat="RGBA",o.height=h,o.width=g;d.drawImage(e,0,0),i=d.getImageData(0,0,g,h).data}else throw new Error("Can not access image data")}else if(s){let p,d;if(r!==void 0&&r.resizedWidth!==void 0&&r.resizedHeight!==void 0?(p=r.resizedHeight,d=r.resizedWidth):(p=e.height,d=e.width),r!==void 0&&(o=r),o.format="RGBA",o.height=p,o.width=d,r!==void 0){const h=l();h.width=d,h.height=p;const g=c(h);if(g!=null)g.putImageData(e,0,0),i=g.getImageData(0,0,d,p).data;else throw new Error("Can not access image data")}else i=e.data}else if(a){if(r===void 0)throw new Error("Please provide image config with format for Imagebitmap");const p=l();p.width=e.width,p.height=e.height;const d=c(p);if(d!=null){const h=e.height,g=e.width;return d.drawImage(e,0,0,g,h),i=d.getImageData(0,0,g,h).data,o.height=h,o.width=g,Dc(i,o)}else throw new Error("Can not access image data")}else{if(n)return new Promise((p,d)=>{const h=l(),g=c(h);if(!e||!g)return d();const _=new Image;_.crossOrigin="Anonymous",_.src=e,_.onload=()=>{h.width=_.width,h.height=_.height,g.drawImage(_,0,0,h.width,h.height);const E=g.getImageData(0,0,h.width,h.height);o.height=h.height,o.width=h.width,p(Dc(E.data,o))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(i!==void 0)return Dc(i,o);throw new Error("Input data provided is not supported - aborted tensor creation")},Sv=(e,r)=>{const{width:t,height:s,download:a,dispose:n}=r,i=[1,s,t,4];return new ts({location:"texture",type:"float32",texture:e,dims:i,download:a,dispose:n})},kv=(e,r)=>{const{dataType:t,dims:s,download:a,dispose:n}=r;return new ts({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:s,download:a,dispose:n})},$v=(e,r)=>{const{dataType:t,dims:s,download:a,dispose:n}=r;return new ts({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:s,download:a,dispose:n})},Av=(e,r,t)=>new ts({location:"cpu-pinned",type:e,data:r,dims:t??[r.length]}),ra=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),Do=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);let hp=!1;const Iv=()=>{if(!hp){hp=!0;const e=typeof BigInt64Array<"u"&&BigInt64Array.from,r=typeof BigUint64Array<"u"&&BigUint64Array.from,t=typeof Float16Array<"u"&&Float16Array.from;e&&(ra.set("int64",BigInt64Array),Do.set(BigInt64Array,"int64")),r&&(ra.set("uint64",BigUint64Array),Do.set(BigUint64Array,"uint64")),t?(ra.set("float16",Float16Array),Do.set(Float16Array,"float16")):ra.set("float16",Uint16Array)}},Ov=e=>{let r=1;for(let t=0;t<e.length;t++){const s=e[t];if(typeof s!="number"||!Number.isSafeInteger(s))throw new TypeError(`dims[${t}] must be an integer, got: ${s}`);if(s<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${s}`);r*=s}return r},Fv=(e,r)=>{switch(e.location){case"cpu":return new ts(e.type,e.data,r);case"cpu-pinned":return new ts({location:"cpu-pinned",data:e.data,type:e.type,dims:r});case"texture":return new ts({location:"texture",texture:e.texture,type:e.type,dims:r});case"gpu-buffer":return new ts({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:r});case"ml-tensor":return new ts({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:r});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}};let ts=class{constructor(r,t,s){Iv();let a,n;if(typeof r=="object"&&"location"in r)switch(this.dataLocation=r.location,a=r.type,n=r.dims,r.location){case"cpu-pinned":{const o=ra.get(a);if(!o)throw new TypeError(`unsupported type "${a}" to create tensor from pinned buffer`);if(!(r.data instanceof o))throw new TypeError(`buffer should be of type ${o.name}`);this.cpuData=r.data;break}case"texture":{if(a!=="float32")throw new TypeError(`unsupported type "${a}" to create tensor from texture`);this.gpuTextureData=r.texture,this.downloader=r.download,this.disposer=r.dispose;break}case"gpu-buffer":{if(a!=="float32"&&a!=="float16"&&a!=="int32"&&a!=="int64"&&a!=="uint32"&&a!=="uint8"&&a!=="bool"&&a!=="uint4"&&a!=="int4")throw new TypeError(`unsupported type "${a}" to create tensor from gpu buffer`);this.gpuBufferData=r.gpuBuffer,this.downloader=r.download,this.disposer=r.dispose;break}case"ml-tensor":{if(a!=="float32"&&a!=="float16"&&a!=="int32"&&a!=="int64"&&a!=="uint32"&&a!=="uint64"&&a!=="int8"&&a!=="uint8"&&a!=="bool")throw new TypeError(`unsupported type "${a}" to create tensor from MLTensor`);this.mlTensorData=r.mlTensor,this.downloader=r.download,this.disposer=r.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let o,l;if(typeof r=="string")if(a=r,l=s,r==="string"){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");o=t}else{const c=ra.get(r);if(c===void 0)throw new TypeError(`Unsupported tensor type: ${r}.`);if(Array.isArray(t)){if(r==="float16"&&c===Uint16Array||r==="uint4"||r==="int4")throw new TypeError(`Creating a ${r} tensor from number array is not supported. Please use ${c.name} as data.`);r==="uint64"||r==="int64"?o=c.from(t,BigInt):o=c.from(t)}else if(t instanceof c)o=t;else if(t instanceof Uint8ClampedArray)if(r==="uint8")o=Uint8Array.from(t);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else throw new TypeError(`A ${a} tensor's data must be type of ${c}`)}else if(l=t,Array.isArray(r)){if(r.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");const c=typeof r[0];if(c==="string")a="string",o=r;else if(c==="boolean")a="bool",o=Uint8Array.from(r);else throw new TypeError(`Invalid element type of data array: ${c}.`)}else if(r instanceof Uint8ClampedArray)a="uint8",o=Uint8Array.from(r);else{const c=Do.get(r.constructor);if(c===void 0)throw new TypeError(`Unsupported type for tensor data: ${r.constructor}.`);a=c,o=r}if(l===void 0)l=[o.length];else if(!Array.isArray(l))throw new TypeError("A tensor's dims must be a number array");n=l,this.cpuData=o,this.dataLocation="cpu"}const i=Ov(n);if(this.cpuData&&i!==this.cpuData.length&&!((a==="uint4"||a==="int4")&&Math.ceil(i/2)===this.cpuData.length))throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);this.type=a,this.dims=n,this.size=i}static async fromImage(r,t){return Cv(r,t)}static fromTexture(r,t){return Sv(r,t)}static fromGpuBuffer(r,t){return kv(r,t)}static fromMLTensor(r,t){return $v(r,t)}static fromPinnedBuffer(r,t,s){return Av(r,t,s)}toDataURL(r){return Ev(this,r)}toImageData(r){return Pv(this,r)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(r){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;const t=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=t,r&&this.disposer&&(this.disposer(),this.disposer=void 0),t}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(r){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Fv(this,r)}};const hs=ts,fp=(e,r)=>{(typeof ps.trace>"u"?!ps.wasm.trace:!ps.trace)||console.timeStamp(`${e}::ORT::${r}`)},mp=(e,r)=>{var a;const t=((a=new Error().stack)==null?void 0:a.split(/\r\n|\r|\n/g))||[];let s=!1;for(let n=0;n<t.length;n++){if(s&&!t[n].includes("TRACE_FUNC")){let i=`FUNC_${e}::${t[n].trim().split(" ")[1]}`;r&&(i+=`::${r}`),fp("CPU",i);return}t[n].includes("TRACE_FUNC")&&(s=!0)}},Lc=e=>{(typeof ps.trace>"u"?!ps.wasm.trace:!ps.trace)||mp("BEGIN",e)},zc=e=>{(typeof ps.trace>"u"?!ps.wasm.trace:!ps.trace)||mp("END",e)},Dv=class wv{constructor(r){this.handler=r}async run(r,t,s){Lc();const a={};let n={};if(typeof r!="object"||r===null||r instanceof hs||Array.isArray(r))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if(typeof t=="object"){if(t===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof hs)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(t.length===0)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(const c of t){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);a[c]=null}if(typeof s=="object"&&s!==null)n=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else{let c=!1;const p=Object.getOwnPropertyNames(t);for(const d of this.outputNames)if(p.indexOf(d)!==-1){const h=t[d];(h===null||h instanceof hs)&&(c=!0,i=!1,a[d]=h)}if(c){if(typeof s=="object"&&s!==null)n=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else n=t}}else if(typeof t<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const c of this.inputNames)if(typeof r[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(i)for(const c of this.outputNames)a[c]=null;const o=await this.handler.run(r,a,n),l={};for(const c in o)if(Object.hasOwnProperty.call(o,c)){const p=o[c];p instanceof hs?l[c]=p:l[c]=new hs(p.type,p.data,p.dims)}return zc(),l}async release(){return this.handler.dispose()}static async create(r,t,s,a){Lc();let n,i={};if(typeof r=="string"){if(n=r,typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(n=r,typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&r instanceof SharedArrayBuffer){const p=r;let d=0,h=r.byteLength;if(typeof t=="object"&&t!==null)i=t;else if(typeof t=="number"){if(d=t,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=p.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${p.byteLength}).`);if(h=r.byteLength-d,typeof s=="number"){if(h=s,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||d+h>p.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${p.byteLength-d}].`);if(typeof a=="object"&&a!==null)i=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(typeof s<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");n=new Uint8Array(p,d,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");const[o,l]=await dp(i),c=await o.createInferenceSessionHandler(n,l);return zc(),new wv(c)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}},Lv="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.";var zv=Object.freeze({__proto__:null,InferenceSession:Dv,TRACE:fp,TRACE_FUNC_BEGIN:Lc,TRACE_FUNC_END:zc,Tensor:hs,TrainingSession:class yv{constructor(r,t,s){this.handler=r,this.hasOptimizerModel=t,this.hasEvalModel=s}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(r,t){const s=r.evalModel||"",a=r.optimizerModel||"",n=t||{},[i,o]=await dp(n);if(i.createTrainingSessionHandler){const l=await i.createTrainingSessionHandler(r.checkpointState,r.trainModel,s,a,o);return new yv(l,!!r.optimizerModel,!!r.evalModel)}else throw new Error(Lv)}typeNarrowingForRunStep(r,t,s,a,n){const i={};let o={};if(typeof s!="object"||s===null||s instanceof hs||Array.isArray(s))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let l=!0;if(typeof a=="object"){if(a===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(a instanceof hs)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(a)){if(a.length===0)throw new TypeError("'fetches' cannot be an empty array.");l=!1;for(const c of a){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(t.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);i[c]=null}if(typeof n=="object"&&n!==null)o=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let c=!1;const p=Object.getOwnPropertyNames(a);for(const d of t)if(p.indexOf(d)!==-1){const h=a[d];(h===null||h instanceof hs)&&(c=!0,l=!1,i[d]=h)}if(c){if(typeof n=="object"&&n!==null)o=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else o=a}}else if(typeof a<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const c of r)if(typeof s[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(l)for(const c of t)i[c]=null;return[i,o]}convertHandlerReturnTypeToMapOfTensors(r){const t={};for(const s in r)if(Object.hasOwnProperty.call(r,s)){const a=r[s];a instanceof hs?t[s]=a:t[s]=new hs(a.type,a.data,a.dims)}return t}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(r,t,s){const[a,n]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,r,t,s),i=await this.handler.runTrainStep(r,a,n);return this.convertHandlerReturnTypeToMapOfTensors(i)}async runOptimizerStep(r){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(r||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(r,t,s){if(this.hasEvalModel){const[a,n]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,r,t,s),i=await this.handler.runEvalStep(r,a,n);return this.convertHandlerReturnTypeToMapOfTensors(i)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(r=!0){return this.handler.getParametersSize(r)}async loadParametersBuffer(r,t=!0){const s=await this.getParametersSize(t);if(r.length!==4*s)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(r,t)}async getContiguousParameters(r=!0){return this.handler.getContiguousParameters(r)}async release(){return this.handler.dispose()}},env:Tv,registerBackend:ta});/*!
* ONNX Runtime Web v1.22.0-dev.20250306-ccf8fdd9ea
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/var Bc=Object.defineProperty,Bv=Object.getOwnPropertyDescriptor,Rv=Object.getOwnPropertyNames,Nv=Object.prototype.hasOwnProperty,jv=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),Ue=(e,r)=>()=>(e&&(r=e(e=0)),r),Ha=(e,r)=>{for(var t in r)Bc(e,t,{get:r[t],enumerable:!0})},Vv=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of Rv(r))!Nv.call(e,a)&&a!==t&&Bc(e,a,{get:()=>r[a],enumerable:!(s=Bv(r,a))||s.enumerable});return e},Lo=e=>Vv(Bc({},"__esModule",{value:!0}),e),qa,on,Cn,_p,gp,wp=Ue(()=>{qa=new Map,on=[],Cn=(e,r,t)=>{if(r&&typeof r.init=="function"&&typeof r.createInferenceSessionHandler=="function"){let s=qa.get(e);if(s===void 0)qa.set(e,{backend:r,priority:t});else{if(s.priority>t)return;if(s.priority===t&&s.backend!==r)throw new Error(`cannot register backend "${e}" using priority ${t}`)}if(t>=0){let a=on.indexOf(e);a!==-1&&on.splice(a,1);for(let n=0;n<on.length;n++)if(qa.get(on[n]).priority<=t){on.splice(n,0,e);return}on.push(e)}return}throw new TypeError("not a valid backend")},_p=async e=>{let r=qa.get(e);if(!r)return"backend not found.";if(r.initialized)return r.backend;if(r.aborted)return r.error;{let t=!!r.initPromise;try{return t||(r.initPromise=r.backend.init(e)),await r.initPromise,r.initialized=!0,r.backend}catch(s){return t||(r.error=`${s}`,r.aborted=!0),r.error}finally{delete r.initPromise}}},gp=async e=>{let r=e.executionProviders||[],t=r.map(l=>typeof l=="string"?l:l.name),s=t.length===0?on:t,a,n=[],i=new Set;for(let l of s){let c=await _p(l);typeof c=="string"?n.push({name:l,err:c}):(a||(a=c),a===c&&i.add(l))}if(!a)throw new Error(`no available backend found. ERR: ${n.map(l=>`[${l.name}] ${l.err}`).join(", ")}`);for(let{name:l,err:c}of n)t.includes(l)&&console.warn(`removing requested execution provider "${l}" from session options because it is not available: ${c}`);let o=r.filter(l=>i.has(typeof l=="string"?l:l.name));return[a,new Proxy(e,{get:(l,c)=>c==="executionProviders"?o:Reflect.get(l,c)})]}}),Uv=Ue(()=>{wp()}),yp,Wv=Ue(()=>{yp="1.22.0-dev.20250306-aafa8d170a"}),Rc,rs,Mp=Ue(()=>{Wv(),Rc="warning",rs={wasm:{},webgl:{},webgpu:{},versions:{common:yp},set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);Rc=e}},get logLevel(){return Rc}},Object.defineProperty(rs,"logLevel",{enumerable:!0})}),qt,Gv=Ue(()=>{Mp(),qt=rs}),bp,vp,Kv=Ue(()=>{bp=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];let s=t.getContext("2d");if(s!=null){let a,n;(r==null?void 0:r.tensorLayout)!==void 0&&r.tensorLayout==="NHWC"?(a=e.dims[2],n=e.dims[3]):(a=e.dims[3],n=e.dims[2]);let i=(r==null?void 0:r.format)!==void 0?r.format:"RGB",o=r==null?void 0:r.norm,l,c;o===void 0||o.mean===void 0?l=[255,255,255,255]:typeof o.mean=="number"?l=[o.mean,o.mean,o.mean,o.mean]:(l=[o.mean[0],o.mean[1],o.mean[2],0],o.mean[3]!==void 0&&(l[3]=o.mean[3])),o===void 0||o.bias===void 0?c=[0,0,0,0]:typeof o.bias=="number"?c=[o.bias,o.bias,o.bias,o.bias]:(c=[o.bias[0],o.bias[1],o.bias[2],0],o.bias[3]!==void 0&&(c[3]=o.bias[3]));let p=n*a,d=0,h=p,g=p*2,_=-1;i==="RGBA"?(d=0,h=p,g=p*2,_=p*3):i==="RGB"?(d=0,h=p,g=p*2):i==="RBG"&&(d=0,g=p,h=p*2);for(let E=0;E<n;E++)for(let A=0;A<a;A++){let M=(e.data[d++]-c[0])*l[0],y=(e.data[h++]-c[1])*l[1],k=(e.data[g++]-c[2])*l[2],P=_===-1?255:(e.data[_++]-c[3])*l[3];s.fillStyle="rgba("+M+","+y+","+k+","+P+")",s.fillRect(A,E,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},vp=(e,r)=>{let t=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),s;if(t!=null){let a,n,i;(r==null?void 0:r.tensorLayout)!==void 0&&r.tensorLayout==="NHWC"?(a=e.dims[2],n=e.dims[1],i=e.dims[3]):(a=e.dims[3],n=e.dims[2],i=e.dims[1]);let o=r!==void 0&&r.format!==void 0?r.format:"RGB",l=r==null?void 0:r.norm,c,p;l===void 0||l.mean===void 0?c=[255,255,255,255]:typeof l.mean=="number"?c=[l.mean,l.mean,l.mean,l.mean]:(c=[l.mean[0],l.mean[1],l.mean[2],255],l.mean[3]!==void 0&&(c[3]=l.mean[3])),l===void 0||l.bias===void 0?p=[0,0,0,0]:typeof l.bias=="number"?p=[l.bias,l.bias,l.bias,l.bias]:(p=[l.bias[0],l.bias[1],l.bias[2],0],l.bias[3]!==void 0&&(p[3]=l.bias[3]));let d=n*a;if(r!==void 0&&(r.format!==void 0&&i===4&&r.format!=="RGBA"||i===3&&r.format!=="RGB"&&r.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let h=4,g=0,_=1,E=2,A=3,M=0,y=d,k=d*2,P=-1;o==="RGBA"?(M=0,y=d,k=d*2,P=d*3):o==="RGB"?(M=0,y=d,k=d*2):o==="RBG"&&(M=0,k=d,y=d*2),s=t.createImageData(a,n);for(let b=0;b<n*a;g+=h,_+=h,E+=h,A+=h,b++)s.data[g]=(e.data[M++]-p[0])*c[0],s.data[_]=(e.data[y++]-p[1])*c[1],s.data[E]=(e.data[k++]-p[2])*c[2],s.data[A]=P===-1?255:(e.data[P++]-p[3])*c[3]}else throw new Error("Can not access image data");return s}}),zo,xp,Tp,Ep,Pp,Cp,Hv=Ue(()=>{jc(),zo=(e,r)=>{if(e===void 0)throw new Error("Image buffer must be defined");if(r.height===void 0||r.width===void 0)throw new Error("Image height and width must be defined");if(r.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:t,width:s}=r,a=r.norm??{mean:255,bias:0},n,i;typeof a.mean=="number"?n=[a.mean,a.mean,a.mean,a.mean]:n=[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],typeof a.bias=="number"?i=[a.bias,a.bias,a.bias,a.bias]:i=[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];let o=r.format!==void 0?r.format:"RGBA",l=r.tensorFormat!==void 0&&r.tensorFormat!==void 0?r.tensorFormat:"RGB",c=t*s,p=l==="RGBA"?new Float32Array(c*4):new Float32Array(c*3),d=4,h=0,g=1,_=2,E=3,A=0,M=c,y=c*2,k=-1;o==="RGB"&&(d=3,h=0,g=1,_=2,E=-1),l==="RGBA"?k=c*3:l==="RBG"?(A=0,y=c,M=c*2):l==="BGR"&&(y=0,M=c,A=c*2);for(let P=0;P<c;P++,h+=d,_+=d,g+=d,E+=d)p[A++]=(e[h]+i[0])/n[0],p[M++]=(e[g]+i[1])/n[1],p[y++]=(e[_]+i[2])/n[2],k!==-1&&E!==-1&&(p[k++]=(e[E]+i[3])/n[3]);return l==="RGBA"?new Kr("float32",p,[1,4,t,s]):new Kr("float32",p,[1,3,t,s])},xp=async(e,r)=>{let t=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,s=typeof ImageData<"u"&&e instanceof ImageData,a=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,n=typeof e=="string",i,o=r??{},l=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=p=>typeof HTMLCanvasElement<"u"&&p instanceof HTMLCanvasElement||p instanceof OffscreenCanvas?p.getContext("2d"):null;if(t){let p=l();p.width=e.width,p.height=e.height;let d=c(p);if(d!=null){let h=e.height,g=e.width;if(r!==void 0&&r.resizedHeight!==void 0&&r.resizedWidth!==void 0&&(h=r.resizedHeight,g=r.resizedWidth),r!==void 0){if(o=r,r.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");o.tensorFormat="RGBA",o.height=h,o.width=g}else o.tensorFormat="RGBA",o.height=h,o.width=g;d.drawImage(e,0,0),i=d.getImageData(0,0,g,h).data}else throw new Error("Can not access image data")}else if(s){let p,d;if(r!==void 0&&r.resizedWidth!==void 0&&r.resizedHeight!==void 0?(p=r.resizedHeight,d=r.resizedWidth):(p=e.height,d=e.width),r!==void 0&&(o=r),o.format="RGBA",o.height=p,o.width=d,r!==void 0){let h=l();h.width=d,h.height=p;let g=c(h);if(g!=null)g.putImageData(e,0,0),i=g.getImageData(0,0,d,p).data;else throw new Error("Can not access image data")}else i=e.data}else if(a){if(r===void 0)throw new Error("Please provide image config with format for Imagebitmap");let p=l();p.width=e.width,p.height=e.height;let d=c(p);if(d!=null){let h=e.height,g=e.width;return d.drawImage(e,0,0,g,h),i=d.getImageData(0,0,g,h).data,o.height=h,o.width=g,zo(i,o)}else throw new Error("Can not access image data")}else{if(n)return new Promise((p,d)=>{let h=l(),g=c(h);if(!e||!g)return d();let _=new Image;_.crossOrigin="Anonymous",_.src=e,_.onload=()=>{h.width=_.width,h.height=_.height,g.drawImage(_,0,0,h.width,h.height);let E=g.getImageData(0,0,h.width,h.height);o.height=h.height,o.width=h.width,p(zo(E.data,o))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(i!==void 0)return zo(i,o);throw new Error("Input data provided is not supported - aborted tensor creation")},Tp=(e,r)=>{let{width:t,height:s,download:a,dispose:n}=r,i=[1,s,t,4];return new Kr({location:"texture",type:"float32",texture:e,dims:i,download:a,dispose:n})},Ep=(e,r)=>{let{dataType:t,dims:s,download:a,dispose:n}=r;return new Kr({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:s,download:a,dispose:n})},Pp=(e,r)=>{let{dataType:t,dims:s,download:a,dispose:n}=r;return new Kr({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:s,download:a,dispose:n})},Cp=(e,r,t)=>new Kr({location:"cpu-pinned",type:e,data:r,dims:t??[r.length]})}),Sn,Qa,Nc,Sp,qv=Ue(()=>{Sn=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),Qa=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Nc=!1,Sp=()=>{if(!Nc){Nc=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,r=typeof BigUint64Array<"u"&&BigUint64Array.from,t=globalThis.Float16Array,s=typeof t<"u"&&t.from;e&&(Sn.set("int64",BigInt64Array),Qa.set(BigInt64Array,"int64")),r&&(Sn.set("uint64",BigUint64Array),Qa.set(BigUint64Array,"uint64")),s?(Sn.set("float16",t),Qa.set(t,"float16")):Sn.set("float16",Uint16Array)}}}),kp,$p,Qv=Ue(()=>{jc(),kp=e=>{let r=1;for(let t=0;t<e.length;t++){let s=e[t];if(typeof s!="number"||!Number.isSafeInteger(s))throw new TypeError(`dims[${t}] must be an integer, got: ${s}`);if(s<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${s}`);r*=s}return r},$p=(e,r)=>{switch(e.location){case"cpu":return new Kr(e.type,e.data,r);case"cpu-pinned":return new Kr({location:"cpu-pinned",data:e.data,type:e.type,dims:r});case"texture":return new Kr({location:"texture",texture:e.texture,type:e.type,dims:r});case"gpu-buffer":return new Kr({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:r});case"ml-tensor":return new Kr({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:r});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}}),Kr,jc=Ue(()=>{Kv(),Hv(),qv(),Qv(),Kr=class{constructor(e,r,t){Sp();let s,a;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,s=e.type,a=e.dims,e.location){case"cpu-pinned":{let i=Sn.get(s);if(!i)throw new TypeError(`unsupported type "${s}" to create tensor from pinned buffer`);if(!(e.data instanceof i))throw new TypeError(`buffer should be of type ${i.name}`);this.cpuData=e.data;break}case"texture":{if(s!=="float32")throw new TypeError(`unsupported type "${s}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(s!=="float32"&&s!=="float16"&&s!=="int32"&&s!=="int64"&&s!=="uint32"&&s!=="uint8"&&s!=="bool"&&s!=="uint4"&&s!=="int4")throw new TypeError(`unsupported type "${s}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}case"ml-tensor":{if(s!=="float32"&&s!=="float16"&&s!=="int32"&&s!=="int64"&&s!=="uint32"&&s!=="uint64"&&s!=="int8"&&s!=="uint8"&&s!=="bool"&&s!=="uint4"&&s!=="int4")throw new TypeError(`unsupported type "${s}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let i,o;if(typeof e=="string")if(s=e,o=t,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");i=r}else{let l=Sn.get(e);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&l===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${l.name} as data.`);e==="uint64"||e==="int64"?i=l.from(r,BigInt):i=l.from(r)}else if(r instanceof l)i=r;else if(r instanceof Uint8ClampedArray)if(e==="uint8")i=Uint8Array.from(r);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(e==="float16"&&r instanceof Uint16Array&&l!==Uint16Array)i=new globalThis.Float16Array(r.buffer,r.byteOffset,r.length);else throw new TypeError(`A ${s} tensor's data must be type of ${l}`)}else if(o=r,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let l=typeof e[0];if(l==="string")s="string",i=e;else if(l==="boolean")s="bool",i=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${l}.`)}else if(e instanceof Uint8ClampedArray)s="uint8",i=Uint8Array.from(e);else{let l=Qa.get(e.constructor);if(l===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);s=l,i=e}if(o===void 0)o=[i.length];else if(!Array.isArray(o))throw new TypeError("A tensor's dims must be a number array");a=o,this.cpuData=i,this.dataLocation="cpu"}let n=kp(a);if(this.cpuData&&n!==this.cpuData.length&&!((s==="uint4"||s==="int4")&&Math.ceil(n/2)===this.cpuData.length))throw new Error(`Tensor's size(${n}) does not match data length(${this.cpuData.length}).`);this.type=s,this.dims=a,this.size=n}static async fromImage(e,r){return xp(e,r)}static fromTexture(e,r){return Tp(e,r)}static fromGpuBuffer(e,r){return Ep(e,r)}static fromMLTensor(e,r){return Pp(e,r)}static fromPinnedBuffer(e,r,t){return Cp(e,r,t)}toDataURL(e){return bp(this,e)}toImageData(e){return vp(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,e&&this.disposer&&(this.disposer(),this.disposer=void 0),r}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return $p(this,e)}}}),fs,Ap=Ue(()=>{jc(),fs=Kr}),Xa,Vc,ms,ss,Ip=Ue(()=>{Mp(),Xa=(e,r)=>{(typeof rs.trace>"u"?!rs.wasm.trace:!rs.trace)||console.timeStamp(`${e}::ORT::${r}`)},Vc=(e,r)=>{var a;let t=((a=new Error().stack)==null?void 0:a.split(/\r\n|\r|\n/g))||[],s=!1;for(let n=0;n<t.length;n++){if(s&&!t[n].includes("TRACE_FUNC")){let i=`FUNC_${e}::${t[n].trim().split(" ")[1]}`;r&&(i+=`::${r}`),Xa("CPU",i);return}t[n].includes("TRACE_FUNC")&&(s=!0)}},ms=e=>{(typeof rs.trace>"u"?!rs.wasm.trace:!rs.trace)||Vc("BEGIN",e)},ss=e=>{(typeof rs.trace>"u"?!rs.wasm.trace:!rs.trace)||Vc("END",e)}}),Op,Xv=Ue(()=>{wp(),Ap(),Ip(),Op=class Mv{constructor(r){this.handler=r}async run(r,t,s){ms();let a={},n={};if(typeof r!="object"||r===null||r instanceof fs||Array.isArray(r))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if(typeof t=="object"){if(t===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof fs)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(t.length===0)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(let c of t){if(typeof c!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(c)===-1)throw new RangeError(`'fetches' contains invalid output name: ${c}.`);a[c]=null}if(typeof s=="object"&&s!==null)n=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else{let c=!1,p=Object.getOwnPropertyNames(t);for(let d of this.outputNames)if(p.indexOf(d)!==-1){let h=t[d];(h===null||h instanceof fs)&&(c=!0,i=!1,a[d]=h)}if(c){if(typeof s=="object"&&s!==null)n=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else n=t}}else if(typeof t<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let c of this.inputNames)if(typeof r[c]>"u")throw new Error(`input '${c}' is missing in 'feeds'.`);if(i)for(let c of this.outputNames)a[c]=null;let o=await this.handler.run(r,a,n),l={};for(let c in o)if(Object.hasOwnProperty.call(o,c)){let p=o[c];p instanceof fs?l[c]=p:l[c]=new fs(p.type,p.data,p.dims)}return ss(),l}async release(){return this.handler.dispose()}static async create(r,t,s,a){ms();let n,i={};if(typeof r=="string"){if(n=r,typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(n=r,typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(r instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&r instanceof SharedArrayBuffer){let p=r,d=0,h=r.byteLength;if(typeof t=="object"&&t!==null)i=t;else if(typeof t=="number"){if(d=t,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=p.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${p.byteLength}).`);if(h=r.byteLength-d,typeof s=="number"){if(h=s,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||d+h>p.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${p.byteLength-d}].`);if(typeof a=="object"&&a!==null)i=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(typeof s<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");n=new Uint8Array(p,d,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[o,l]=await gp(i),c=await o.createInferenceSessionHandler(n,l);return ss(),new Mv(c)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}}),Uc,Jv=Ue(()=>{Xv(),Uc=Op}),Yv=Ue(()=>{}),Zv=Ue(()=>{}),ex=Ue(()=>{}),tx=Ue(()=>{}),Fp={};Ha(Fp,{InferenceSession:()=>Uc,TRACE:()=>Xa,TRACE_FUNC_BEGIN:()=>ms,TRACE_FUNC_END:()=>ss,Tensor:()=>fs,env:()=>qt,registerBackend:()=>Cn});var _s=Ue(()=>{Uv(),Gv(),Jv(),Ap(),Yv(),Zv(),Ip(),ex(),tx()}),Wc=Ue(()=>{}),Dp={};Ha(Dp,{default:()=>Lp});var Gc,Kc,Lp,rx=Ue(()=>{var e;hy(),kn(),eu(),Gc="ort-wasm-proxy-worker",Kc=((e=globalThis.self)==null?void 0:e.name)===Gc,Kc&&(self.onmessage=r=>{let{type:t,in:s}=r.data;try{switch(t){case"init-wasm":su(s.wasm).then(()=>{pd(s).then(()=>{postMessage({type:t})},a=>{postMessage({type:t,err:a})})},a=>{postMessage({type:t,err:a})});break;case"init-ep":{let{epName:a,env:n}=s;hd(n,a).then(()=>{postMessage({type:t})},i=>{postMessage({type:t,err:i})});break}case"copy-from":{let{buffer:a}=s,n=tl(a);postMessage({type:t,out:n});break}case"create":{let{model:a,options:n}=s;fd(a,n).then(i=>{postMessage({type:t,out:i})},i=>{postMessage({type:t,err:i})});break}case"release":md(s),postMessage({type:t});break;case"run":{let{sessionId:a,inputIndices:n,inputs:i,outputIndices:o,options:l}=s;gd(a,n,i,o,new Array(o.length).fill(null),l).then(c=>{c.some(p=>p[3]!=="cpu")?postMessage({type:t,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:t,out:c},yd([...i,...c]))},c=>{postMessage({type:t,err:c})});break}case"end-profiling":wd(s),postMessage({type:t});break;default:}}catch(a){postMessage({type:t,err:a})}}),Lp=Kc?null:r=>new Worker(r??Hr,{type:"module",name:Gc})}),zp={};Ha(zp,{default:()=>Bp});var Hc,qc,Bp,Rp,sx=Ue(()=>{var e,r;qc=(Hc=self.location.href,async function(t={}){var Io;var s,a,n=t,i=new Promise((u,f)=>{s=u,a=f}),o=typeof window=="object",l=typeof WorkerGlobalScope<"u",c=l&&((Io=self.name)==null?void 0:Io.startsWith("em-pthread"));n.mountExternalData=(u,f)=>{u.startsWith("./")&&(u=u.substring(2)),(n.Bd||(n.Bd=new Map)).set(u,f)},n.unmountExternalData=()=>{delete n.Bd};var p=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor;let d=()=>{let u=(x,C,I)=>(...G)=>{let ie=Ut,ye=C==null?void 0:C();G=x(...G);let Pe=C==null?void 0:C();return ye!==Pe&&(x=Pe,I(ye),C=I=null),Ut!=ie?new Promise((Be,Ze)=>{Mn={resolve:Be,reject:Ze}}):G},f=x=>async(...C)=>{var I;try{if(n.Cd)throw Error("Session already started");let G=n.Cd={be:C[0],errors:[]},ie=await x(...C);if(n.Cd!==G)throw Error("Session mismatch");(I=n.Dd)==null||I.flush();let ye=G.errors;if(0<ye.length){let Pe=await Promise.all(ye);if(Pe=Pe.filter(Be=>Be),0<Pe.length)throw Error(Pe.join(`
`))}return ie}finally{n.Cd=null}};n._OrtCreateSession=u(n._OrtCreateSession,()=>n._OrtCreateSession,x=>n._OrtCreateSession=x),n._OrtRun=f(u(n._OrtRun,()=>n._OrtRun,x=>n._OrtRun=x)),n._OrtRunWithBinding=f(u(n._OrtRunWithBinding,()=>n._OrtRunWithBinding,x=>n._OrtRunWithBinding=x)),n._OrtBindInput=u(n._OrtBindInput,()=>n._OrtBindInput,x=>n._OrtBindInput=x),d=void 0};n.jsepInit=(u,f)=>{if(d==null||d(),u==="webgpu"){[n.Dd,n.Rd,n.Vd,n.Hd,n.Ud,n.hc,n.Wd,n.Zd,n.Sd,n.Td,n.Xd]=f;let x=n.Dd;n.jsepRegisterBuffer=(C,I,G,ie)=>x.registerBuffer(C,I,G,ie),n.jsepGetBuffer=C=>x.getBuffer(C),n.jsepCreateDownloader=(C,I,G)=>x.createDownloader(C,I,G),n.jsepOnCreateSession=C=>{x.onCreateSession(C)},n.jsepOnReleaseSession=C=>{x.onReleaseSession(C)},n.jsepOnRunStart=C=>x.onRunStart(C),n.$d=(C,I)=>{x.upload(C,I)}}else if(u==="webnn"){[n.Dd,n.Yd,n.Id,n.jsepEnsureTensor,n.Jd,n.jsepDownloadTensor]=f,n.jsepReleaseTensorId=n.Id,n.jsepUploadTensor=n.Jd;let x=n.Dd;n.jsepOnRunStart=C=>x.onRunStart(C),n.jsepOnRunEnd=x.onRunEnd.bind(x),n.jsepRegisterMLContext=(C,I)=>{x.registerMLContext(C,I)},n.jsepOnReleaseSession=C=>{x.onReleaseSession(C)},n.jsepCreateMLTensorDownloader=(C,I)=>x.createMLTensorDownloader(C,I),n.jsepRegisterMLTensor=(C,I,G,ie)=>x.registerMLTensor(C,I,G,ie),n.jsepCreateMLContext=C=>x.createMLContext(C),n.jsepRegisterMLConstant=(C,I,G,ie,ye)=>x.registerMLConstant(C,I,G,ie,ye,n.Bd),n.jsepRegisterGraphInput=x.registerGraphInput.bind(x),n.jsepIsGraphInput=x.isGraphInput.bind(x),n.jsepCreateTemporaryTensor=x.createTemporaryTensor.bind(x)}};var h,g,_=Object.assign({},n),E=(u,f)=>{throw f},A="";(o||l)&&(l?A=self.location.href:typeof document<"u"&&document.currentScript&&(A=document.currentScript.src),Hc&&(A=Hc),A=A.startsWith("blob:")?"":A.slice(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1),l&&(g=u=>{var f=new XMLHttpRequest;return f.open("GET",u,!1),f.responseType="arraybuffer",f.send(null),new Uint8Array(f.response)}),h=async u=>{if(de(u))return new Promise((x,C)=>{var I=new XMLHttpRequest;I.open("GET",u,!0),I.responseType="arraybuffer",I.onload=()=>{I.status==200||I.status==0&&I.response?x(I.response):C(I.status)},I.onerror=C,I.send(null)});var f=await fetch(u,{credentials:"same-origin"});if(f.ok)return f.arrayBuffer();throw Error(f.status+" : "+f.url)});var M=console.log.bind(console),y=console.error.bind(console),k=M,P=y;Object.assign(n,_),_=null;var b,w,T,$,z,N,Y,J,W,te,H,R,q,ee=n.wasmBinary,le=!1,de=u=>u.startsWith("file://");function j(){return b.buffer!=$.buffer&&Q(),$}function F(){return b.buffer!=$.buffer&&Q(),z}function K(){return b.buffer!=$.buffer&&Q(),N}function ae(){return b.buffer!=$.buffer&&Q(),Y}function Z(){return b.buffer!=$.buffer&&Q(),J}function we(){return b.buffer!=$.buffer&&Q(),W}function _e(){return b.buffer!=$.buffer&&Q(),te}function Ae(){return b.buffer!=$.buffer&&Q(),q}if(c){let u=function(f){try{var x=f.data,C=x.yd;if(C==="load"){let I=[];self.onmessage=G=>I.push(G),self.startWorker=()=>{postMessage({yd:"loaded"});for(let G of I)u(G);self.onmessage=u};for(let G of x.Od)n[G]&&!n[G].proxy||(n[G]=(...ie)=>{postMessage({yd:"callHandler",Nd:G,args:ie})},G=="print"&&(k=n[G]),G=="printErr"&&(P=n[G]));b=x.he,Q(),qe(x.ie)}else if(C==="run"){Xs(x.xd),ba(x.xd,0,0,1,0,0),Gt(),Lt(x.xd),Me||(Ma(),Me=!0);try{Ur(x.de,x.Fd)}catch(I){if(I!="unwind")throw I}}else x.target!=="setimmediate"&&(C==="checkMailbox"?Me&&Ht():C&&(P(`worker: received unknown command ${C}`),P(x)))}catch(I){throw Ii(),I}};var qe,Me=!1;P=function(...f){f=f.join(" "),console.error(f)},self.alert=function(...f){postMessage({yd:"alert",text:f.join(" "),fe:Xn()})},self.onunhandledrejection=f=>{throw f.reason||f},self.onmessage=u}function Q(){var u=b.buffer;n.HEAP8=$=new Int8Array(u),n.HEAP16=N=new Int16Array(u),n.HEAPU8=z=new Uint8Array(u),n.HEAPU16=Y=new Uint16Array(u),n.HEAP32=J=new Int32Array(u),n.HEAPU32=W=new Uint32Array(u),n.HEAPF32=te=new Float32Array(u),n.HEAPF64=q=new Float64Array(u),n.HEAP64=H=new BigInt64Array(u),n.HEAPU64=R=new BigUint64Array(u)}function V(){c?startWorker(n):De.Bb()}c||(b=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),Q());var fe,Ce=0,Ee=null;function Oe(){if(--Ce==0&&Ee){var u=Ee;Ee=null,u()}}function Ie(u){throw P(u="Aborted("+u+")"),le=!0,u=new WebAssembly.RuntimeError(u+". Build with -sASSERTIONS for more info."),a(u),u}function ze(){return{a:{Ta:D,Va:Ge,W:Js,la:ut,b:zs,u:Bs,R:Rs,Za:Ys,d:br,pb:tt,g:Yr,T:zr,Ga:Ps,lb:Ss,nb:ks,Ha:os,Ea:Ns,wb:pn,Da:hn,pa:fn,mb:mn,jb:$s,Fa:_n,kb:gn,Ma:js,za:Un,eb:Wn,cb:Vs,ya:he,V:O,N:U,db:re,ma:ft,fb:kt,zb:It,hb:kr,qb:us,ab:$r,Aa:As,yb:Lt,Ja:Xt,S:ds,Wa:Is,$:pl,H:hl,E:ml,l:cs,F:hi,B:wl,X:fi,J:yl,v:mi,O:Sd,D:Ml,t:_i,A:b