@mediapipe/tasks-genai 0.10.16 → 0.10.17-rc.20241004

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/README.md CHANGED
File without changes
package/genai_bundle.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="undefined"!=typeof self?self:{};function e(e,n){t:{for(var r=["CLOSURE_FLAGS"],i=t,o=0;o<r.length;o++)if(null==(i=i[r[o]])){r=null;break t}r=i}return null!=(e=r&&r[e])?e:n}let n;const r="undefined"!=typeof TextEncoder;function i(t){if(r)t=(n||=new TextEncoder).encode(t);else{let n=0;const r=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var e=t.charCodeAt(i);if(e<128)r[n++]=e;else{if(e<2048)r[n++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&i<t.length){const o=t.charCodeAt(++i);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,r[n++]=e>>18|240,r[n++]=e>>12&63|128,r[n++]=e>>6&63|128,r[n++]=63&e|128;continue}i--}e=65533}r[n++]=e>>12|224,r[n++]=e>>6&63|128}r[n++]=63&e|128}}t=n===r.length?r:r.subarray(0,n)}return t}var o,s=e(610401301,!1),a=e(653718497,e(1,!0)),u=e(660014094,!1);const l=t.navigator;function c(t){return!!s&&(!!o&&o.brands.some((({brand:e})=>e&&-1!=e.indexOf(t))))}function h(e){var n;return(n=t.navigator)&&(n=n.userAgent)||(n=""),-1!=n.indexOf(e)}function f(){return!!s&&(!!o&&o.brands.length>0)}function d(){return f()?c("Chromium"):(h("Chrome")||h("CriOS"))&&!(!f()&&h("Edge"))||h("Silk")}o=l&&l.userAgentData||null;var p=!f()&&(h("Trident")||h("MSIE"));!h("Android")||d(),d(),h("Safari")&&(d()||!f()&&h("Coast")||!f()&&h("Opera")||!f()&&h("Edge")||(f()?c("Microsoft Edge"):h("Edg/"))||f()&&c("Opera"));var g={},m=null;function _(t){var e=t.length,n=3*e/4;n%3?n=Math.floor(n):-1!="=.".indexOf(t[e-1])&&(n=-1!="=.".indexOf(t[e-2])?n-2:n-1);var r=new Uint8Array(n),i=0;return function(t,e){function n(e){for(;r<t.length;){var n=t.charAt(r++),i=m[n];if(null!=i)return i;if(!/^[\s\xa0]*$/.test(n))throw Error("Unknown base64 encoding at char: "+n)}return e}v();for(var r=0;;){var i=n(-1),o=n(0),s=n(64),a=n(64);if(64===a&&-1===i)break;e(i<<2|o>>4),64!=s&&(e(o<<4&240|s>>2),64!=a&&e(s<<6&192|a))}}(t,(function(t){r[i++]=t})),i!==n?r.subarray(0,i):r}function v(){if(!m){m={};for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"],n=0;n<5;n++){var r=t.concat(e[n].split(""));g[n]=r;for(var i=0;i<r.length;i++){var o=r[i];void 0===m[o]&&(m[o]=i)}}}}var b="undefined"!=typeof Uint8Array,y=!p&&"function"==typeof btoa;function w(t){if(!y){var e;void 0===e&&(e=0),v(),e=g[e];var n=Array(Math.floor(t.length/3)),r=e[64]||"";let u=0,l=0;for(;u<t.length-2;u+=3){var i=t[u],o=t[u+1],s=t[u+2],a=e[i>>2];i=e[(3&i)<<4|o>>4],o=e[(15&o)<<2|s>>6],s=e[63&s],n[l++]=a+i+o+s}switch(a=0,s=r,t.length-u){case 2:s=e[(15&(a=t[u+1]))<<2]||r;case 1:t=t[u],n[l]=e[t>>2]+e[(3&t)<<4|a>>4]+s+r}return n.join("")}for(e="",n=0,r=t.length-10240;n<r;)e+=String.fromCharCode.apply(null,t.subarray(n,n+=10240));return e+=String.fromCharCode.apply(null,n?t.subarray(n):t),btoa(e)}const S=/[-_.]/g,A={"-":"+",_:"/",".":"="};function T(t){return A[t]||""}function E(t){if(!y)return _(t);S.test(t)&&(t=t.replace(S,T)),t=atob(t);const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}function I(t){return b&&null!=t&&t instanceof Uint8Array}var P={};let O;function L(t){if(t!==P)throw Error("illegal external caller")}function N(){return O||=new U(null,P)}var U=class{constructor(t,e){if(L(e),this.M=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function x(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let B;function k(){const e=Error();x(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function j(t){return x(t=Error(t),"warning"),t}function F(){return"function"==typeof BigInt}function M(t){return Array.prototype.slice.call(t)}var D="function"==typeof Symbol&&"symbol"==typeof Symbol();function V(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?Symbol():t}var C=V(),G=V("2ex"),R=V("1oa"),z=V("0dg"),W=D?(t,e)=>{t[C]|=e}:(t,e)=>{void 0!==t.s?t.s|=e:Object.defineProperties(t,{s:{value:e,configurable:!0,writable:!0,enumerable:!1}})},H=D?(t,e)=>{t[C]&=~e}:(t,e)=>{void 0!==t.s&&(t.s&=~e)},$=D?t=>0|t[C]:t=>0|t.s,q=D?t=>t[C]:t=>t.s,K=D?(t,e)=>{t[C]=e}:(t,e)=>{void 0!==t.s?t.s=e:Object.defineProperties(t,{s:{value:e,configurable:!0,writable:!0,enumerable:!1}})};function Y(t,e){K(e,-14591&(0|t))}function J(t,e){K(e,-14557&(34|t))}var X,Z={},Q={};function tt(t){return!(!t||"object"!=typeof t||t.i!==Q)}function et(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function nt(t){return!(!Array.isArray(t)||t.length)&&!!(1&$(t))}const rt=[];function it(t){if(2&t)throw Error()}K(rt,55),X=Object.freeze(rt);var ot=Object.freeze({});Object.freeze({});var st=Object.freeze({}),at="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0);const ut=Number.MIN_SAFE_INTEGER.toString(),lt=at?BigInt(Number.MIN_SAFE_INTEGER):void 0,ct=Number.MAX_SAFE_INTEGER.toString(),ht=at?BigInt(Number.MAX_SAFE_INTEGER):void 0;function ft(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let n=0;n<t.length;n++){const r=t[n],i=e[n];if(r>i)return!1;if(r<i)return!0}}let dt,pt=0,gt=0;function mt(t){const e=t>>>0;pt=e,gt=(t-e)/4294967296>>>0}function _t(t){if(t<0){mt(-t);const[e,n]=wt(pt,gt);pt=e>>>0,gt=n>>>0}else mt(t)}function vt(t,e){if(t>>>=0,(e>>>=0)<=2097151)var n=""+(4294967296*e+t);else F()?n=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(n=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),n+=8147497*e,e*=2,t>=1e7&&(n+=t/1e7>>>0,t%=1e7),n>=1e7&&(e+=n/1e7>>>0,n%=1e7),n=e+bt(n)+bt(t));return n}function bt(t){return t=String(t),"0000000".slice(t.length)+t}function yt(t){if(t.length<16)_t(Number(t));else if(F())t=BigInt(t),pt=Number(t&BigInt(4294967295))>>>0,gt=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);gt=pt=0;const n=t.length;for(let r=e,i=(n-e)%6+e;i<=n;r=i,i+=6){const e=Number(t.slice(r,i));gt*=1e6,pt=1e6*pt+e,pt>=4294967296&&(gt+=Math.trunc(pt/4294967296),gt>>>=0,pt>>>=0)}if(e){const[t,e]=wt(pt,gt);pt=t,gt=e}}}function wt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function St(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}function At(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}const Tt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Et(t){const e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return"string"===e&&Tt.test(t)}function It(t){if("number"!=typeof t)throw j("int32");if(!Number.isFinite(t))throw j("int32");return 0|t}function Pt(t){return null==t?t:It(t)}function Ot(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function Lt(t){if(null!=t){if("number"!=typeof t)throw j("uint32");if(!Number.isFinite(t))throw j("uint32");t>>>=0}return t}function Nt(t){return"-"!==t[0]&&(t.length<20||20===t.length&&Number(t.substring(0,6))<184467)}function Ut(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asUintN(64,t));if(Et(t)){if("string"===e)return e=Math.trunc(Number(t)),Number.isSafeInteger(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),Nt(t)||(yt(t),t=vt(pt,gt))),t;if("number"===e)return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:function(t){if(t<0){_t(t);const e=vt(pt,gt);return t=Number(e),Number.isSafeInteger(t)?t:e}return Nt(String(t))?t:(_t(t),4294967296*gt+(pt>>>0))}(t)}}function xt(t){return null==t||"string"==typeof t?t:void 0}function Bt(t,e,n){if(null!=t&&"object"==typeof t&&t.O===Z)return t;if(Array.isArray(t)){var r=$(t),i=r;return 0===i&&(i|=32&n),(i|=2&n)!==r&&K(t,i),new e(t)}}function kt(t){if(void 0===Mt&&(Mt="function"==typeof Proxy?$t(Proxy):null),!Mt||!Ht())return t;let e=jt?.get(t);return e||(Math.random()>.01?t:(function(t){if(void 0===Vt){const t=new Mt([],{});Vt=1===Array.prototype.concat.call([],t).length}Vt&&"function"==typeof Symbol&&Symbol.isConcatSpreadable&&(t[Symbol.isConcatSpreadable]=!0)}(t),e=new Mt(t,{set:(t,e,n)=>(k(),t[e]=n,!0)}),function(t,e){(jt||=new Dt).set(t,e),(Ft||=new Dt).set(e,t)}(t,e),e))}let jt,Ft,Mt,Dt,Vt,Ct,Gt,Rt,zt,Wt;function Ht(){return void 0===Dt&&(Dt="function"==typeof WeakMap?$t(WeakMap):null),Dt}function $t(t){try{return-1!==t.toString().indexOf("[native code]")?t:null}catch{return null}}function qt(t,e,n){if(a&&Ht()){if(Ct?.get(e)?.get(t)){if(n)return}else if(Math.random()>.01)return;var r=t.length;n={length:r};for(var i=0;i<Math.min(r,10);i++){if(r<=10)var o=i;else{o=r/10;const t=Math.floor(i*o);o=t+Math.floor(Math.random()*(Math.floor((i+1)*o)-t))}n[o]=t[o]}Yt(t,n)?((i=(r=Ct||=new Dt).get(e))||(i=new Dt,r.set(e,i)),i.set(t,n)):(k(),Xt(t,e))}}function Kt(t,e){const n=Ct?.get(e)?.get(t);n&&!Yt(t,n)&&(k(),Xt(t,e))}function Yt(t,e){if(t.length!==e.length)return!1;for(const i in e){var n,r=Number(i);if((n=Number.isInteger(r))&&(n=t[r],r=e[r],n=!(Number.isNaN(n)?Number.isNaN(r):n===r)),n)return!1}return!0}function Jt(t){if(t&&Ct?.has(t)){var e=t.m;if(e)for(let n=0;n<e.length;n++){const r=e[n];if(n===e.length-1&&et(r))for(const e in r){const n=r[e];Array.isArray(n)&&Kt(n,t)}else Array.isArray(r)&&Kt(r,t)}}}function Xt(t,e){Ct?.get(e)?.delete(t)}function Zt(t,e,n){if(null==t&&(t=Gt),Gt=void 0,null==t){var r=96;n?(t=[n],r|=512):t=[],e&&(r=-33521665&r|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(r=$(t)))throw Error("farr");if(64&r)return t;if(r|=64,n&&(r|=512,n!==t[0]))throw Error("mid");t:{const i=(n=t).length;if(i){const t=i-1;if(et(n[t])){if((e=t-(+!!(512&(r|=256))-1))>=1024)throw Error("pvtlmt");r=-33521665&r|(1023&e)<<15;break t}}if(e){if((e=Math.max(e,i-(+!!(512&r)-1)))>1024)throw Error("spvt");r=-33521665&r|(1023&e)<<15}}}return K(t,r),t}function Qt(t,e,n,r,i){if(null!=t){if(Array.isArray(t))t=nt(t)?void 0:i&&2&$(t)?t:te(t,e,n,void 0!==r,i);else if(et(t)){const o={};for(let s in t)o[s]=Qt(t[s],e,n,r,i);t=o}else t=e(t,r);return t}}function te(t,e,n,r,i){const o=r||n?$(t):0;r=r?!!(32&o):void 0,t=M(t);for(let o=0;o<t.length;o++)t[o]=Qt(t[o],e,n,r,i);return n&&n(o,t),t}function ee(t){return t.O===Z?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"bigint":return(at?t>=lt&&t<=ht:"-"===t[0]?ft(t,ut):ft(t,ct))?Number(t):String(t);case"boolean":return t?1:0;case"object":if(t)if(Array.isArray(t)){if(nt(t))return}else{if(I(t))return w(t);if(t instanceof U){const e=t.M;return null==e?"":"string"==typeof e?e:t.M=w(e)}}}return t}(t)}function ne(t,e,n=J){if(null!=t){if(b&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var r=$(t);return 2&r?t:(e&&=0===r||!!(32&r)&&!(64&r||!(16&r)),e?(K(t,-12293&(34|r)),t):te(t,ne,4&r?J:n,!0,!0))}return t.O===Z&&(n=t.m,t=2&(r=q(n))?t:re(t,n,r,!0)),t}}function re(t,e,n,r){return Jt(t),t=t.constructor,Gt=e=function(t,e,n){const r=n||2&e?J:Y,i=!!(32&e);return t=function(t,e,n){var r=(t=M(t)).length;const i=256&e?t[r-1]:void 0;for(r+=i?-1:0,e=512&e?1:0;e<r;e++)t[e]=n(t[e]);if(i){e=t[e]={};for(const t in i)e[t]=n(i[t])}return t}(t,e,(t=>ne(t,i,r))),W(t,32|(n?2:0)),t}(e,n,r),e=new t(e),Gt=void 0,e}function ie(t){const e=t.m,n=q(e);return 2&n?re(t,e,n,!1):t}function oe(t,e,n,r){return!(4&e)||null!=n&&(!r&&0===n&&(4096&e||8192&e)&&(t.constructor[z]=1+(0|t.constructor[z]))<5&&k(),0!==n&&!(n&e))}function se(t,e){return ue(t=t.m,q(t),e)}function ae(t,e,n,r){if(!((e=r+(+!!(512&e)-1))<0||e>=t.length||e>=n))return t[e]}function ue(t,e,n,r){if(-1===n)return null;const i=e>>15&1023||536870912;if(!(n>=i)){var o=t.length;return r&&256&e&&null!=(r=t[o-1][n])?(ae(t,e,i,n)&&null!=G&&((e=(t=B??={})[G]||0)>=4||(t[G]=e+1,k())),r):ae(t,e,i,n)}return 256&e?t[t.length-1][n]:void 0}function le(t,e,n){const r=t.m;let i=q(r);return it(i),ce(r,i,e,n),t}function ce(t,e,n,r){const i=e>>15&1023||536870912;if(n>=i){let o,s=e;if(256&e)o=t[t.length-1];else{if(null==r)return s;o=t[i+(+!!(512&e)-1)]={},s|=256}return o[n]=r,n<i&&(t[n+(+!!(512&e)-1)]=void 0),s!==e&&K(t,s),s}return t[n+(+!!(512&e)-1)]=r,256&e&&(n in(t=t[t.length-1])&&delete t[n]),e}function he(t,e,n,r,i,o){const s=t.m;let a=q(s);r=2&a?1:r,o=!!o,i=fe(s,a,e,i);var u=$(i),l=i;if(Kt(l,t),2!==r&&1!==r||Xt(l,t),oe(t,u,void 0,o)){4&u&&(i=M(i),u=ye(u,a),a=ce(s,a,e,i));let t=l=0;for(;l<i.length;l++){const e=n(i[l]);null!=e&&(i[t++]=e)}t<l&&(i.length=t),u=-4097&(20|(u=de(u,a))),K(i,u&=-8193),2&u&&Object.freeze(i)}let c;return 1===r||4===r&&32&u?pe(u)||(t=u,(u|=2)!==t&&K(i,u),Object.freeze(i)):(n=5===r&&(!!(32&u)||pe(u)||!!jt?.get(i)),(2===r||n)&&pe(u)&&(i=M(i),u=we(u=ye(u,a),a,o),K(i,u),a=ce(s,a,e,i)),pe(u)||(e=u,(u=we(u,a,o))!==e&&K(i,u)),n?(c=kt(i),qt(i,t,!0)):2!==r||o||jt?.delete(i)),c||i}function fe(t,e,n,r){return t=ue(t,e,n,r),Array.isArray(t)?t:X}function de(t,e){return 0===t&&(t=ye(t,e)),1|t}function pe(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function ge(t,e,n,r){t=t.m;let i=q(t);it(i),ce(t,i,e,("0"===r?0===Number(n):n===r)?void 0:n)}function me(t){if(D)return t[R]??(t[R]=new Map);if(R in t)return t[R];const e=new Map;return Object.defineProperty(t,R,{value:e}),e}function _e(t,e,n){var r=Nr;let i=t.get(r);if(null!=i)return i;i=0;for(let t=0;t<r.length;t++){const o=r[t];null!=ue(e,n,o)&&(0!==i&&(n=ce(e,n,i)),i=o)}return t.set(r,i),i}function ve(t,e,n){var r=t.m,i=q(r),o=ue(r,i,n,!1);return(e=Bt(o,e,i))!==o&&null!=e&&ce(r,i,n,e),null==(r=e)||(t=t.m,2&(i=q(t))||(o=ie(r))!==r&&ce(t,i,n,r=o)),r}function be(t,e,n){return null==n&&(n=void 0),le(t,e,n)}function ye(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function we(t,e,n){return 32&e&&n||(t&=-33),t}function Se(t,e,n,r){var i=q(t.m);it(i);const o=t.m;var s=!!(2&i);const a=s?1:2;d&&=!s,s=fe(o,i,e);var u=$(s),l=s;if(Kt(l,t),2!==a&&1!==a||Xt(l,t),!(l=!!(4&u))){var c=s,h=i,f=!!(2&(u=de(u,i)));f&&(h|=2);let t=!f,e=!0,r=0,o=0;for(;r<c.length;r++){const i=Bt(c[r],n,h);if(i instanceof n){if(!f){const n=!!(2&$(i.m));t&&=!n,e&&=n}c[o++]=i}}o<r&&(c.length=o),u|=4,u=e?16|u:-17&u,K(c,u=t?8|u:-9&u),f&&Object.freeze(c)}if(d&&!(8&u||!s.length&&(1===a||4===a&&32&u))){pe(u)?(s=M(s),u=ye(u,i),i=ce(o,i,e,s)):Xt(s,t);var d=s;for(c=u,u=0;u<d.length;u++)(h=d[u])!==(f=ie(h))&&(d[u]=f);c|=8,c=d.length?-17&c:16|c,K(d,c),u=c}if(1===a||4===a&&32&u)pe(u)||(t=u,(u|=!s.length||16&u&&(!l||32&u)?2:2048)!==t&&K(s,u),Object.freeze(s));else if(l=5===a&&(!!(32&u)||pe(u)||!!jt?.get(s)),(2===a||l)&&pe(u)&&(s=M(s),u=we(u=ye(u,i),i,!0),K(s,u),i=ce(o,i,e,s)),pe(u)||(e=u,(u=we(u,i,!0))!==e&&K(s,u)),l){var p=kt(s);qt(s,t,!0)}p=p||s,n=null!=r?r:new n,p.push(n),2&$(n.m)?H(p,8):H(p,16)}function Ae(t){return t??0}function Te(t,e){return Ae(function(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?t>>>0:void 0}(se(t,e)))}function Ee(t,e,n){ge(t,e,Pt(n),0)}function Ie(t,e,n){if(null!=n&&"string"!=typeof n)throw Error();ge(t,e,n,"")}function Pe(t,e,n){{const a=t.m;let u=q(a);if(it(u),null==n)ce(a,u,e);else{n=Ft?.get(n)||n;var r,i=$(n),o=i,s=!!(2&i)||Object.isFrozen(n);if((r=!s)&&(r=void 0===st||!1),oe(t,i)){i=21,s&&(n=M(n),o=0,i=we(i=ye(i,u),u,!0));for(let t=0;t<n.length;t++)n[t]=It(n[t])}r?(n=M(n),o=0,i=we(i=ye(i,u),u,!0)):s||qt(n,t),i!==o&&K(n,i),ce(a,u,e,n)}}}function Oe(t,e,n){if(it(q(t.m)),e=(t=he(t,e,xt,2,void 0,!0)).push,"string"!=typeof n)throw Error();e.call(t,n)}function Le(t){if("string"==typeof t)return{buffer:E(t),C:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),C:!1};if(t.constructor===Uint8Array)return{buffer:t,C:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),C:!1};if(t.constructor===U){L(P);var e=t.M;return{buffer:(null==(e=null==e||I(e)?e:"string"==typeof e?E(e):null)?e:t.M=e)||new Uint8Array(0),C:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),C:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}var Ne=class{constructor(t,e){this.m=Zt(t,e)}toJSON(){return Ue(this)}C(){return!!(2&$(this.m))}};function Ue(t){Jt(t),t=Wt?t.m:te(t.m,ee,void 0,void 0,!1);{var e=!Wt;let l=t.length;if(l){var n=t[l-1],r=et(n);r?l--:n=void 0;var i=t;if(r){t:{var o,s=n,a=!1;if(s)for(let t in s)isNaN(+t)?(o??={})[t]=s[t]:(r=s[t],Array.isArray(r)&&(nt(r)||tt(r)&&0===r.size)&&(r=null),null==r&&(a=!0),null!=r&&((o??={})[t]=r));if(a||(o=s),o)for(let t in o){a=o;break t}a=null}s=null==a?null!=n:a!==n}for(;l>0&&(null==(o=i[l-1])||nt(o)||tt(o)&&0===o.size);l--)var u=!0;(i!==t||s||u)&&(e?(u||s||a)&&(i.length=l):i=Array.prototype.slice.call(i,0,l),a&&i.push(a)),u=i}else u=t}return u}function xe(t){return t?/^\d+$/.test(t)?(yt(t),new Be(pt,gt)):null:ke||=new Be(0,0)}Ne.prototype.O=Z,Ne.prototype.toString=function(){try{return Wt=!0,Ue(this).toString()}finally{Wt=!1}};var Be=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ke;function je(t){return t?/^-?\d+$/.test(t)?(yt(t),new Fe(pt,gt)):null:Me||=new Fe(0,0)}var Fe=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Me;function De(t,e,n){for(;n>0||e>127;)t.i.push(127&e|128),e=(e>>>7|n<<25)>>>0,n>>>=7;t.i.push(e)}function Ve(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Ce(t,e){if(e>=0)Ve(t,e);else{for(let n=0;n<9;n++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function Ge(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Re(t,e){return Ve(t.i,8*e+2),e=t.i.end(),Ge(t,e),e.push(t.j),e}function ze(t,e){var n=e.pop();for(n=t.j+t.i.length()-n;n>127;)e.push(127&n|128),n>>>=7,t.j++;e.push(n),t.j++}function We(t,e,n){Ve(t.i,8*e+2),Ve(t.i,n.length),Ge(t,t.i.end()),Ge(t,n)}class He{constructor(t,e){this.i=t,this.S=e}}function $e(t,e){if(Array.isArray(e)){var n=$(e);if(4&n)return e;for(var r=0,i=0;r<e.length;r++){const n=t(e[r]);null!=n&&(e[i++]=n)}return i<r&&(e.length=i),K(e,-12289&(5|n)),2&n&&Object.freeze(e),e}}const qe=Symbol();function Ke(t){let e=t[qe];if(!e){const n=Ze(t);e=(t,e)=>tn(t,e,n),t[qe]=e}return e}const Ye=Symbol();function Je(t){return t.i}function Xe(t,e){let n,r;const i=t.i;return(t,o,s)=>i(t,o,s,r||=Ze(e).i,n||=Ke(e))}function Ze(t){var e=t[Ye];if(e)return e;var n=Je,r=Xe;(e=t[Ye]={}).i=function(t){switch(typeof t){case"boolean":return Rt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?zt||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);let i=0;var o=t[++i];o&&o.constructor===Object&&(e.N=o,"function"==typeof(o=t[++i])&&(e.l=o,e.j=t[++i],o=t[++i]));const s={};for(;Array.isArray(o)&&"number"==typeof o[0]&&o[0]>0;){for(var a=0;a<o.length;a++)s[o[a]]=o;o=t[++i]}for(a=1;void 0!==o;){let f;"number"==typeof o&&(a+=o,o=t[++i]);var u=void 0;if(o instanceof He?f=o:(f=In,i--),f.S){o=t[++i],u=t;var l=i;"function"==typeof o&&(o=o(),u[l]=o),u=o}let d=a+1;for("number"==typeof(o=t[++i])&&o<0&&(d-=o,o=t[++i]);a<d;a++){var c=s[a];l=e;var h=a;c=u?r(f,u):n(f),l[h]=c}}return e}function Qe(t,e){var n=t[e];if(n)return n;if(n=t.N){var r=n[e];if(r){var i=(r=Array.isArray(r)?r[0]instanceof He?r:[En,r]:[r,void 0])[0].i;if(r=r[1],n=n.D?.[e],!u||n){if(r){const e=Ke(r),o=Ze(r).i;n=(n=t.j)?n(o,e):(t,n,r)=>i(t,n,r,o,e)}else n=i;return t[e]=n}}}}function tn(t,e,n){for(var r=q(t),i=+!!(512&r)-1,o=t.length,s=512&r?1:0,a=o+(256&r?-1:0);s<a;s++){const r=t[s];if(null==r)continue;const o=s-i,a=Qe(n,o);if(!a)continue;const u=n.N;u?.[o]&&!u?.D?.[o]&&nn++<5&&k(),a(e,r,o)}if(256&r){t=t[o-1];for(let s in t)r=+s,!Number.isNaN(r)&&(null!=(i=t[s])&&(o=Qe(n,r)))&&((a=n.N)?.[r]&&!a?.D?.[r]&&nn++<5&&k(),o(e,i,r))}}function en(t){return new He(t,!1)}let nn=0;function rn(t,e,n){null!=(e=At(e))&&(Ve(t.i,8*n+5),t=t.i,(n=dt||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),gt=0,e=pt=n.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))}function on(t,e,n){null!=(e=Ot(e))&&null!=e&&(Ve(t.i,8*n),Ce(t.i,e))}function sn(t,e,n){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(Ve(t.i,8*n),t.i.i.push(e?1:0))}function an(t,e,n){null!=(e=xt(e))&&We(t,n,i(e))}function un(t,e,n,r,i){e instanceof Ne?(Jt(e),e=e.m):Array.isArray(e)?(e=Zt(e,r[0],r[1]),W(e,16384)):e=void 0,null!=e&&(n=Re(t,n),i(e,t),ze(t,n))}function ln(t,e,n){null!=(e=Ot(e))&&(e=parseInt(e,10),Ve(t.i,8*n),Ce(t.i,e))}var cn,hn=en(rn),fn=en(rn),dn=en((function(t,e,n){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asIntN(64,t));if(Et(t)){if("string"===e){if(e=Math.trunc(Number(t)),Number.isSafeInteger(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),!("-"===t[0]?t.length<20||20===t.length&&Number(t.substring(0,7))>-922337:t.length<19||19===t.length&&Number(t.substring(0,6))<922337))if(yt(t),t=pt,2147483648&(e=gt))if(F())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[n,r]=wt(t,e);t="-"+vt(n,r)}else t=vt(t,e);return t}if("number"===e){if(t=Math.trunc(t),!Number.isSafeInteger(t)){_t(t),e=pt;var n=gt;(t=2147483648&n)&&(n=~n>>>0,0==(e=1+~e>>>0)&&(n=n+1>>>0)),e=4294967296*n+(e>>>0),t=t?-e:e}return t}}}(e),null!=e){if("string"==typeof e)je(e);if(null!=e)switch(Ve(t.i,8*n),typeof e){case"number":t=t.i,_t(e),De(t,pt,gt);break;case"bigint":n=BigInt.asUintN(64,e),n=new Fe(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),De(t.i,n.j,n.i);break;default:n=je(e),De(t.i,n.j,n.i)}}})),pn=en((function(t,e,n){if(null!=(e=Ut(e))){if("string"==typeof e)xe(e);if(null!=e)switch(Ve(t.i,8*n),typeof e){case"number":t=t.i,_t(e),De(t,pt,gt);break;case"bigint":n=BigInt.asUintN(64,e),n=new Be(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),De(t.i,n.j,n.i);break;default:n=xe(e),De(t.i,n.j,n.i)}}})),gn=en(on),mn=new He((function(t,e,n){if(null!=(e=$e(Ot,e))&&e.length){n=Re(t,n);for(let n=0;n<e.length;n++)Ce(t.i,e[n]);ze(t,n)}}),!1),_n=en(on),vn=en(on),bn=en(sn),yn=en(sn),wn=en(an),Sn=new He((function(t,e,n){if(null!=(e=$e(xt,e)))for(let a=0;a<e.length;a++){var r=t,o=n,s=e[a];null!=s&&We(r,o,i(s))}}),!1),An=en(an),Tn=en(an),En=new He(un,!0),In=new He(un,!0);cn=new He((function(t,e,n,r,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)un(t,e[o],n,r,i)}),!0);var Pn=new He(un,!0),On=en(ln),Ln=new He((function(t,e,n){if(null!=(e=$e(Ot,e))&&e.length){n=Re(t,n);for(let n=0;n<e.length;n++)Ce(t.i,e[n]);ze(t,n)}}),!1),Nn=en(ln);function Un(t){return function(){Jt(this);const e=new class{constructor(){this.l=[],this.j=0,this.i=new class{constructor(){this.i=[]}length(){return this.i.length}end(){const t=this.i;return this.i=[],t}}}};tn(this.m,e,Ze(t)),Ge(e,e.i.end());const n=new Uint8Array(e.j),r=e.l,i=r.length;let o=0;for(let t=0;t<i;t++){const e=r[t];n.set(e,o),o+=e.length}return e.l=[n],n}}function xn(t,e){if(null!=e)if(Array.isArray(e))le(t,2,te(e,ee,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof U||I(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new U(e,P):N();else if(e.constructor!==U){if(!I(e))throw Error();e=e.length?new U(new Uint8Array(e),P):N()}ge(t,2,e,N())}}var Bn=class extends Ne{constructor(t){super(t)}},kn=[0,An,en((function(t,e,n){if(null!=e){if(e instanceof Ne){const r=e.ca;return void(r&&(e=r(e),null!=e&&We(t,n,Le(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||I(e)||e instanceof U?e:void 0)&&We(t,n,Le(e).buffer)}))],jn=[0,wn,bn,-1,gn,[0,[1,2,3,4,5,6,7],Pn,[0],Pn,[0,bn,wn,bn,On,-1,Ln,wn,-1,[0,bn,-1],On,bn,-1],Pn,[0,wn,-2],Pn,[0,gn,bn,1,bn,-3],Pn,[0,gn,On,bn,-1,mn,On,-1],Pn,[0,wn,-2],Pn,[0,wn,On]],[0,wn],bn,[0,[1,3],[2,4],Pn,[0,mn],-1,Pn,[0,Sn],-1,cn,[0,wn,-1]],wn],Fn={},Mn=Fn.D={};Fn[336783863]=jn,Mn[336783863]=1;var Dn=class extends Ne{constructor(t){super(t)}},Vn=[0,dn,-1,yn,-3,dn,mn,An,_n,dn,-1,yn,_n,yn,-2,An],Cn=class extends Ne{constructor(t){super(t,500)}L(t){return be(this,7,t)}},Gn=[-1,{D:{}}],Rn=[0,wn,1,Gn],zn=[0,wn,Sn,Gn];function Wn(t,e){Se(t,1,Cn,e)}var Hn=class extends Ne{constructor(){super(void 0,500)}L(t){return be(this,1001,t)}};Hn.prototype.i=Un([-500,cn,[-500,An,-1,Sn,-3,[-2,Fn,bn],cn,kn,_n,-1,Rn,zn,cn,[0,An,yn],An,Vn,_n,Sn,987,Sn],4,cn,[-500,wn,-1,[-1,{D:{}}],998,wn],cn,[-500,wn,Sn,-1,[-2,{D:{}},bn],997,Sn,-1],_n,cn,[-500,wn,Sn,Gn,998,Sn],Sn,_n,Rn,zn,cn,[0,An,-1,Gn],Sn,-2,Vn,An,-1,yn,979,Gn,cn,kn]);var $n=class extends Ne{constructor(t){super(t)}};let qn;const Kn=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);async function Yn(){if(void 0===qn)try{await WebAssembly.instantiate(Kn),qn=!0}catch{qn=!1}return qn}async function Jn(t,e=""){const n=await Yn()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${n}.js`,wasmBinaryPath:`${e}/${t}_${n}.wasm`}}var Xn=class{};function Zn(){var t=navigator;return"undefined"!=typeof OffscreenCanvas&&(!function(t=navigator){return(t=t.userAgent).includes("Safari")&&!t.includes("Chrome")}(t)||!!((t=t.userAgent.match(/Version\/([\d]+).*Safari/))&&t.length>=1&&Number(t[1])>=17))}async function Qn(t){if("function"!=typeof importScripts){const e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((t,n)=>{e.addEventListener("load",(()=>{t()}),!1),e.addEventListener("error",(t=>{n(t)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}Xn.forVisionTasks=function(t){return Jn("vision",t)},Xn.forTextTasks=function(t){return Jn("text",t)},Xn.forGenAiExperimentalTasks=function(t){return Jn("genai_experimental",t)},Xn.forGenAiTasks=function(t){return Jn("genai",t)},Xn.forAudioTasks=function(t){return Jn("audio",t)},Xn.isSimdSupported=function(){return Yn()};function tr(t,e,n){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),n(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function er(t,e,n){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");const r=new Uint32Array(e.length);for(let n=0;n<e.length;n++)r[n]=t.h.stringToNewUTF8(e[n]);e=t.h._malloc(4*r.length),t.h.HEAPU32.set(r,e>>2),n(e);for(const e of r)t.h._free(e);t.h._free(e)}function nr(t,e,n){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=n}function rr(t,e,n){let r=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(n(r,i),r=[]):r.push(t)}}const ir=(or=class{constructor(t,e){this.l=!0,this.h=t,this.i=null,this.j=0,this.o="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:Zn()?this.h.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas"))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const n=t.length,r=this.h._malloc(n);this.h.HEAPU8.set(t,r),e?this.h._changeBinaryGraph(n,r):this.h._changeTextGraph(n,r),this.h._free(r)}configureAudio(t,e,n,r,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),tr(this,r||"input_audio",(r=>{tr(this,i=i||"audio_header",(i=>{this.h._configureAudio(r,i,t,e,n)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,n){this.addAudioToStreamWithShape(t,0,0,e,n)}addAudioToStreamWithShape(t,e,n,r,i){const o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),tr(this,r,(t=>{this.h._addAudioToInputStream(this.i,e,n,t,i)}))}addGpuBufferToStream(t,e,n){tr(this,e,(e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();const r=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!r)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1);const[i,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||i===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=i,this.h.canvas.height=o);const[s,a]=[i,o];this.h._addBoundTextureToStream(e,s,a,n)}))}addBoolToStream(t,e,n){tr(this,e,(e=>{this.h._addBoolToInputStream(t,e,n)}))}addDoubleToStream(t,e,n){tr(this,e,(e=>{this.h._addDoubleToInputStream(t,e,n)}))}addFloatToStream(t,e,n){tr(this,e,(e=>{this.h._addFloatToInputStream(t,e,n)}))}addIntToStream(t,e,n){tr(this,e,(e=>{this.h._addIntToInputStream(t,e,n)}))}addUintToStream(t,e,n){tr(this,e,(e=>{this.h._addUintToInputStream(t,e,n)}))}addStringToStream(t,e,n){tr(this,e,(e=>{tr(this,t,(t=>{this.h._addStringToInputStream(t,e,n)}))}))}addStringRecordToStream(t,e,n){tr(this,e,(e=>{er(this,Object.keys(t),(r=>{er(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(r,i,Object.keys(t).length,e,n)}))}))}))}addProtoToStream(t,e,n,r){tr(this,n,(n=>{tr(this,e,(e=>{const i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputStream(i,t.length,e,n,r),this.h._free(i)}))}))}addEmptyPacketToStream(t,e){tr(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputStream(r,e,n)}))}addDoubleVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputStream(r,e,n)}))}addFloatVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputStream(r,e,n)}))}addIntVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputStream(r,e,n)}))}addUintVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputStream(r,e,n)}))}addStringVectorToStream(t,e,n){tr(this,e,(e=>{const r=this.h._allocateStringVector(t.length);if(!r)throw Error("Unable to allocate new string vector on heap.");for(const e of t)tr(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputStream(r,e,n)}))}addBoolToInputSidePacket(t,e){tr(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){tr(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){tr(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){tr(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){tr(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){tr(this,e,(e=>{tr(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,n){tr(this,n,(n=>{tr(this,e,(e=>{const r=this.h._malloc(t.length);this.h.HEAPU8.set(t,r),this.h._addProtoToInputSidePacket(r,t.length,e,n),this.h._free(r)}))}))}addBoolVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputSidePacket(n,e)}))}addDoubleVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputSidePacket(n,e)}))}addFloatVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputSidePacket(n,e)}))}addIntVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputSidePacket(n,e)}))}addUintVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputSidePacket(n,e)}))}addStringVectorToInputSidePacket(t,e){tr(this,e,(e=>{const n=this.h._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(const e of t)tr(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputSidePacket(n,e)}))}attachBoolListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){nr(this,t,e),tr(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){rr(this,t,e),tr(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,n){nr(this,t,e),tr(this,t,(t=>{this.h._attachProtoListener(t,n||!1)}))}attachProtoVectorListener(t,e,n){rr(this,t,e),tr(this,t,(t=>{this.h._attachProtoVectorListener(t,n||!1)}))}attachAudioListener(t,e,n){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),nr(this,t,((t,n)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,n)})),tr(this,t,(t=>{this.h._attachAudioListener(t,n||!1)}))}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends or{Z(){this.h._registerModelResourcesGraphService()}});var or;async function sr(t,e){const n=await(async(t,e,n)=>{var r=Gr;if(t&&await Qn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await Qn(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&n&&((t=self.Module).locateFile=n.locateFile,n.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=n.mainScriptUrlOrBlob)),n=await self.ModuleFactory(self.Module||n),self.ModuleFactory=self.Module=void 0,new r(n,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return await n.L(e),n}async function ar(t,e){return sr(t,e)}function ur(t){try{const e=t.I.length;if(1===e)throw Error(t.I[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.I.map((t=>t.message)).join(", "))}finally{t.I=[]}}function lr(t,e){t.H=Math.max(t.H,e)}var cr=class{constructor(t){this.i=t,this.I=[],this.H=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.I.push(Error(e))})),this.i.Z(),this.i.setGraph(t,e),ur(this)}finishProcessing(){this.i.finishProcessing(),ur(this)}close(){this.i.closeGraph()}};cr.prototype.close=cr.prototype.close;var hr=class extends Ne{constructor(t){super(t)}};function fr(t,e){be(t,1,e)}var dr=class extends Ne{constructor(){super()}},pr=[0,Nn,_n,fn,-1,gn];function gr(t,e,n,r){if(void 0!==t.data){var i=new Uint8Array(t.data.buffer,e,n);return 1===r&&function(t,e,n){t.i.push([e,n]),t.i.sort(((t,e)=>t[0]-e[0])),e=0;for(const[r,i]of t.i){const t=i;(n=r)<=e&&(e=Math.max(e,n+t))}e===t.length&&(t.data=void 0)}(t,e,n),i}}class mr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var _r=class{constructor(t,e,n){this.i=t,this.j=e,this.l=n}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function vr(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var br=class{constructor(t,e){this.h=t,this.l=e,this.j=this.h._malloc(e)>>>0,this.o=this.h.HEAPU8,this.i=!!this.j}get offset(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.j}get size(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.l}set(t,e){this.o.set(t,this.j+(e??0))}},yr=class extends Ne{constructor(){super()}};yr.prototype.i=Un([0,An,2,Sn,_n,yn]);var wr=class extends Ne{constructor(){super()}},Sr=class extends Ne{constructor(){super()}},Ar=class extends Ne{constructor(){super()}},Tr=class extends Ne{constructor(){super()}},Er=[0,_n,-6,1,_n,1,[0,yn,Nn,-2],[0,yn,fn],Nn,-2,[0,yn,-1,Nn,fn,On,gn],1,yn,_n,gn,-1,[0,Nn,_n],yn,-1,hn],Ir=[0,[4,6],Er,_n,1,vn,Sn,Tn,Ln,[0,An,-2],gn,[0,[0,_n,-1,cn,[0,_n,[0,_n,-1],-1,[0,Nn,-1],yn],yn,-2,_n,-1],[0,_n,-1,yn],Er,yn,_n],wn,-3],Pr=[0,cn,[0,An,pn,-1,Nn],Ir,_n];Tr.prototype.i=Un([0,An,8,[0,yn,-6],1,_n,1,_n,Pr,[0,_n,yn,-3],1,Nn,An,Ir,Pr,_n,5,Nn,mn,1,pr]);var Or=class extends Ne{constructor(){super()}},Lr=class extends Ne{constructor(){super()}},Nr=[2,4];Lr.prototype.i=Un([0,Nr,_n,Tn,_n,Pn,[0,1,An]]);const Ur=function(t){return class e extends t{static async aa(t,n){let r;n||=await e.R();const i=[];for(const e of t?.requiredFeatures??[])n.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{r=await n.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return n=await n.requestAdapterInfo(),r.adapterInfo=n,r}static async R(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}X(t){if(e)"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id="canvas_webgpu");else var e=new OffscreenCanvas(1,1);e.getContext("webgpu").configure({device:t,format:navigator.gpu.getPreferredCanvasFormat()}),this.h.preinitializedWebGPUDevice=t}U(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}}}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket(((e,n,r)=>async function(t,e,n,r,i){if(2===i)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout((()=>{t.l()}),0),Promise.resolve(0);for(;t.size<n+r;){var o=await t.j();if(void 0===o)break;t.i.push(new mr(o))}if(t.size<n+r)throw Error(`Data size is too small: ${t.size}, expected at least ${n+r}.`);o=e._malloc(r)>>>0;let s=0;for(let a=0;a<t.i.length;a++){const u=t.i[a];if(n>=u.length){n-=u.length;continue}const l=Math.min(r,u.length-n);if(void 0===(n=gr(u,n,l,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(n,o+s),n=0,s+=l,0==(r-=l))break}if(0!==r)throw Error("Data not found.");return Promise.resolve(o)}(t,this.h,e,n,r)),e)}}}(function(t){return class extends t{T(t,e){tr(this,"lora_model_ref_in",(n=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,n,e)}))}}}(class extends ir{})));class xr extends Ur{}var Br=class{constructor(t){this.j=t,this.i=kr,kr++}},kr=0;class jr{constructor(){let t,e;this.promise=new Promise(((n,r)=>{t=n,e=r})),this.resolve=t,this.reject=e}}function Fr(t){return 1===t?1:t+t%2}async function Mr(){const t=await xr.R({powerPreference:"high-performance"});var e=t.limits.maxBufferSize;if(t.limits.maxStorageBufferBindingSize<524550144)throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxStorageBufferBindingSize is at least 524550144 but your device only supports maxStorageBufferBindingSize of ${e}`);if(e>=786825216)e=786825216;else{if(!(e>=524550144))throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxBufferSize is at least 524550144 but your device only supports maxBufferSize of ${e}`);e=524550144}if(e={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:e}},t.features.has("subgroups")){console.warn("Experimental Chromium WGSL subgroup support detected. Enabling this feature in the inference engine.");const n=["shader-f16","subgroups"];t.features.has("subgroups-f16")&&n.push("subgroups-f16"),e.requiredFeatures=n}return xr.aa(e,t)}function Dr(t){const e=function(t){const e=new Hn;Oe(e,10,"text_in"),Oe(e,10,"token_cost_in"),Oe(e,10,"lora_model_id_to_apply_in"),Oe(e,10,"lora_model_ref_in"),Oe(e,10,"lora_model_id_to_load_in"),Oe(e,16,"streaming_reader"),Oe(e,15,"text_out"),Oe(e,15,"text_end"),Oe(e,15,"token_cost_out");var n=new Cn;Ie(n,2,"TokenizerInputBuildCalculator"),Oe(n,3,"PROMPT:text_in"),Oe(n,3,"LORA_ID:lora_model_id_to_apply_in"),Oe(n,4,"prompt"),Wn(e,n),Ie(n=new Cn,2,"ModelDataCalculator"),Oe(n,6,"MODEL_DATA:__side_packet_1"),Oe(n,6,"MODEL_TYPE:model_type"),Oe(n,5,"READ_DATA_FN:streaming_reader"),Oe(n,3,"LORA_MODEL_SPAN:lora_model_ref_in"),Oe(n,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),Oe(n,4,"LORA_DATA:lora_model_data"),Wn(e,n),Ie(n=new Cn,2,"Gpt2UnicodeMappingCalculator"),Oe(n,5,"MODEL_TYPE:model_type"),Oe(n,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Wn(e,n),Ie(n=new Bn,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var r=new Lr,i=Te(t.j,2);Ee(r,1,i),Ie(i=new Or,2,"spm_vocab_model"),null==i&&(i=void 0);t:{var o=r.m,s=q(o);if(it(s),null==i){var a=me(o);if(4!==_e(a,o,s))break t;a.set(Nr,0)}else{const t=me(a=o),e=_e(t,a,s);4!==e&&(e&&(s=ce(a,s,e)),t.set(Nr,4))}ce(o,s,4,i)}return Ee(r,3,2),xn(n,r.i()),Ie(r=new Cn,2,"TokenizerCalculator"),Se(r,8,Bn,n),Oe(r,5,"MODEL_DATA:__side_packet_1"),Oe(r,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),Oe(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Oe(r,6,"PROCESSOR_GETTER:__input_side_1"),Oe(r,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),Wn(e,r),Ie(n=new Bn,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),Ee(r=new Tr,12,3),Ie(r,1,"llm.tflite"),Ee(r,14,0),i=Fr(Te(t.j,5)),Ee(r,22,i),i=ve(t.j,hr,3),be(r,31,i),ge(i=new wr,1,!0,!1),ge(i,2,!0,!1),ge(i,5,!0,!1),be(r,10,i),i=he(t.j,4,Ot,void 0===ot?2:5),Pe(r,29,i),i=new Ar,Ee(o=new Sr,1,1),a=Te(t.j,2),Ee(o,2,a),be(i,1,o),be(r,20,i),xn(n,r.i()),Ie(r=new Cn,2,"LlmGpuCalculator"),Se(r,8,Bn,n),Oe(r,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),Oe(r,3,"FINISH:finish"),Oe(r,3,"LORA_DATA:lora_model_data"),Oe(r,5,"MODEL_DATA:__side_packet_1"),Oe(r,4,"DECODED_IDS:__stream_3"),Oe(r,4,"OUTPUT_END:__stream_4"),Ie(n=new Dn,1,"FINISH"),ge(n,2,!0,!1),Se(r,13,Dn,n),Wn(e,r),Ie(n=new Cn,2,"IsPacketPresentCalculator"),Oe(n,3,"__stream_4"),Oe(n,4,"text_end"),Wn(e,n),Ie(n=new Bn,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),r=new yr,t=Fr(Te(t.j,5)),Ee(r,5,t),Oe(r,4,"<eos>"),Oe(r,4,"<|endoftext|>"),xn(n,r.i()),Ie(t=new Cn,2,"DetokenizerCalculator"),Se(t,8,Bn,n),Oe(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),Oe(t,5,"PROCESSOR_GETTER:__input_side_1"),Oe(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Oe(t,5,"MODEL_DATA:__side_packet_1"),Oe(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),Oe(t,4,"WORDS:text_out"),Wn(e,t),Ie(t=new Cn,2,"TokenCostCalculator"),Oe(t,3,"PROMPT:token_cost_in"),Oe(t,5,"PROCESSOR_GETTER:__input_side_1"),Oe(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Oe(t,4,"NUM_TOKENS:token_cost_out"),Wn(e,t),e}(t);t.i.attachStringVectorListener("text_out",((e,n)=>{e=function(t,e){return null==t||0===t.length?[]:t.map((t=>(t=(t=t.replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),e&&(t=t.trimStart()),t.split("\\[eod\\]",1)[0])))}(e,0===t.F.length),e.forEach(((e,n)=>{n<Te(t.j,5)&&t.F[n].push(e)})),t.A&&0===t.B.length&&(t.G?(e.length>Te(t.j,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),lr(t,n)})),t.i.attachEmptyPacketListener("text_out",(e=>{lr(t,e)})),t.i.attachBoolListener("text_end",((e,n)=>{if(t.l=!1,lr(t,n),Vr(t),t.o&&(t.o.resolve(t.F.map((t=>t.join("")))),t.o=void 0),t.A)if(t.G){for(e=[],n=0;n<Te(t.j,5);n++)e.push("");t.A(e,!0)}else t.A("",!0);t.G=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.G=void 0,lr(t,e),Vr(t),t.o&&(t.o.resolve(t.F.map((t=>t.join("")))),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,n)=>{t.P=e,lr(t,n)})),t.K&&t.i.addStreamingReaderToInputSidePacket(t.K,"streaming_reader");const n=e.i();return t.v?.removeEventListener("uncapturederror",t.J),t.i.U().then((()=>{t.v?.addEventListener("uncapturederror",t.J),t.B.length=0,t.setGraph(new Uint8Array(n),!0),t.finishProcessing()}))}function Vr(t){if(t.B.length>0){const e=[...t.B];if(t.B.length=0,!t.o)throw e;t.o.reject(e),t.o=void 0}}function Cr(t,e,n,r){if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.A="function"==typeof n?n:r,t.l=!0,t.F.length=0,r=0;r<Te(t.j,5);r++)t.F[r]=[];if(r=t.H+1,t.i.addStringToStream(e,"text_in",r),n instanceof Br){if(n.j!==t)throw t.l=!1,t.G=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.i.addUintToStream(n.i,"lora_model_id_to_apply_in",r)}else t.i.addEmptyPacketToStream("lora_model_id_to_apply_in",r);return t.finishProcessing(),t.o=new jr,t.o.promise}var Gr=class extends cr{constructor(t,e){super(new xr(t,e)),this.F=[],this.l=!1,this.B=[],this.J=t=>{const e=(t=t.error).message.match(/exceeds the max buffer size limit \(([0-9]+)\)\./);e&&Number(e[1])>524550144?t=Error(`Failed to run this LLM model, but you could try a smaller LLM model. WebGPU throws: "${t.message}"`):t.message.match(/is larger than the maximum binding size/)&&(t=Error(`Failed to run LLM inference, the supported max binding size is smaller than the required size. WebGPU throws: "${t.message}"`)),this.B.push(t)},this.j=new dr,fr(this.j,new $n),this.u=new hr,be(this.j,3,this.u),le(this.j,2,Lt(512)),ge(this.u,1,2,0),Ee(this.u,2,40),ge(this.u,3,St(1),0),le(this.u,5,Pt(0)),ge(this.u,4,St(.8),0),le(this.j,5,Lt(1))}L(t){if(this.l)throw Error("Cannot set options while loading or processing.");if(this.l=!0,t.baseOptions?.gpuOptions?.device&&(this.v&&this.v.removeEventListener("uncapturederror",this.J),this.v=t.baseOptions.gpuOptions.device,this.i.X(this.v),this.v.addEventListener("uncapturederror",this.J)),"maxTokens"in t&&le(this.j,2,Lt(t.maxTokens??512)),"topK"in t&&Ee(this.u,2,t.topK??40),"temperature"in t&&ge(this.u,4,St(t.temperature??.8),0),"randomSeed"in t&&le(this.u,5,Pt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){Pe(t,4,e)}(this.j,t.loraRanks??[]),"numResponses"in t){var e=t.numResponses??1;if(e<1)throw Error("'numResponses' must be at least 1.");le(this.j,5,Lt(e));var n=ve(this.j,hr,3);e>1&&n&&(Ae(Ot(se(n,2)))<=1||Ae(function(t){t=t.m;let e=q(t);const n=ue(t,e,4),r=At(n);return null!=r&&r!==n&&ce(t,e,4,r),r}(n))<=0)&&console.warn("To generate multiple responses, it is expected topK > 1 and temperature > 0; otherwise, all the generated responses may be the same.")}let r;if(e=new Promise((t=>{r=t})),t.baseOptions?.modelAssetPath||t.baseOptions?.modelAssetBuffer){if(t.baseOptions.modelAssetPath&&t.baseOptions.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");n=!1,t.baseOptions.modelAssetPath?this.K=function(t,e){const n=fetch(t.toString()).then((t=>t?.body?.getReader()));return new _r([],(async()=>{let e;try{e=await n}catch(e){throw Error(`Error loading model from "${t.toString()}": ${e}`)}const{value:r,done:i}=await e.read();return i?void 0:r}),e)}(t.baseOptions.modelAssetPath,r):t.baseOptions.modelAssetBuffer instanceof Uint8Array?(this.K=function(t,e){return new _r([new mr(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,r),n=!0):t.baseOptions.modelAssetBuffer?(this.K=function(t,e){return new _r([],(async()=>{const{value:e,done:n}=await t.read();return n?void 0:e}),e)}(t.baseOptions.modelAssetBuffer,r),n=!0):r(),n&&(t.baseOptions.modelAssetBuffer=void 0)}return t=Dr(this).then((()=>{})),Promise.all([e,t]).then((()=>{this.l=!1,Vr(this)}))}get baseOptions(){return ve(this.j,$n,1)}set baseOptions(t){fr(this.j,t)}V(t,e,n){return Te(this.j,5)>1&&console.warn("'numResponses' is set larger than 1 and this function only returns the first response, so we recommend either using 'generateResponses()' to obtain multiple responses, or else setting 'numResponses' to 1 for better performance."),this.G=!1,Cr(this,t,e,n).then((t=>t[0]))}W(t,e,n){return this.G=!0,Cr(this,t,e,n)}ba(t){if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.P=void 0,this.i.addStringToStream(t,"token_cost_in",this.H+1),this.finishProcessing(),this.l=!1,this.P}async Y(t){if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new br(this.i.h,t.length);e.set(t),t=e}else t=await async function(t,e){var n=await fetch(e.toString());e=Number(n.headers.get("content-length")),t=new br(t,e);let r=0;for(n=n?.body?.getReader();;){const{value:e,done:i}=await n.read();if(i)break;t.set(e,r),r+=e.byteLength}if(e!==r)throw vr(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${r}/${e} bytes before failure`);return t}(this.i.h,t);return e=new Br(this),this.i.T(t,this.H+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.H+1),this.finishProcessing(),vr(t),this.l=!1,e}close(){this.v?.removeEventListener("uncapturederror",this.J),super.close()}};Gr.prototype.loadLoraModel=Gr.prototype.Y,Gr.prototype.sizeInTokens=Gr.prototype.ba,Gr.prototype.generateResponses=Gr.prototype.W,Gr.prototype.generateResponse=Gr.prototype.V,Gr.prototype.setOptions=Gr.prototype.L,Gr.createWebGpuDevice=Mr,Gr.createFromModelPath=async function(t,e){return ar(t,e={baseOptions:{gpuOptions:{device:await Mr()},modelAssetPath:e}})},Gr.createFromModelBuffer=async function(t,e){return ar(t,e={baseOptions:{gpuOptions:{device:await Mr()},modelAssetBuffer:e}})},Gr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Mr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return ar(t,e)},exports.FilesetResolver=Xn,exports.LlmInference=Gr,exports.TaskRunner=cr;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="undefined"!=typeof self?self:{};function e(e,r){t:{for(var n=["CLOSURE_FLAGS"],i=t,o=0;o<n.length;o++)if(null==(i=i[n[o]])){n=null;break t}n=i}return null!=(e=n&&n[e])?e:r}let r;const n="undefined"!=typeof TextEncoder;function i(t){if(n)t=(r||=new TextEncoder).encode(t);else{let r=0;const n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var e=t.charCodeAt(i);if(e<128)n[r++]=e;else{if(e<2048)n[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&i<t.length){const o=t.charCodeAt(++i);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}i--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var o,s=e(610401301,!1),a=e(660014094,e(1,!0));const u=t.navigator;function c(t){return!!s&&(!!o&&o.brands.some((({brand:e})=>e&&-1!=e.indexOf(t))))}function l(e){var r;return(r=t.navigator)&&(r=r.userAgent)||(r=""),-1!=r.indexOf(e)}function h(){return!!s&&(!!o&&o.brands.length>0)}function f(){return h()?c("Chromium"):(l("Chrome")||l("CriOS"))&&!(!h()&&l("Edge"))||l("Silk")}o=u&&u.userAgentData||null;var d=!h()&&(l("Trident")||l("MSIE"));!l("Android")||f(),f(),l("Safari")&&(f()||!h()&&l("Coast")||!h()&&l("Opera")||!h()&&l("Edge")||(h()?c("Microsoft Edge"):l("Edg/"))||h()&&c("Opera"));var p={},g=null;function m(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var n=new Uint8Array(r),i=0;return function(t,e){function r(e){for(;n<t.length;){var r=t.charAt(n++),i=g[r];if(null!=i)return i;if(!/^[\s\xa0]*$/.test(r))throw Error("Unknown base64 encoding at char: "+r)}return e}_();for(var n=0;;){var i=r(-1),o=r(0),s=r(64),a=r(64);if(64===a&&-1===i)break;e(i<<2|o>>4),64!=s&&(e(o<<4&240|s>>2),64!=a&&e(s<<6&192|a))}}(t,(function(t){n[i++]=t})),i!==r?n.subarray(0,i):n}function _(){if(!g){g={};for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"],r=0;r<5;r++){var n=t.concat(e[r].split(""));p[r]=n;for(var i=0;i<n.length;i++){var o=n[i];void 0===g[o]&&(g[o]=i)}}}}var v="undefined"!=typeof Uint8Array,b=!d&&"function"==typeof btoa;function y(t){if(!b){var e;void 0===e&&(e=0),_(),e=p[e];var r=Array(Math.floor(t.length/3)),n=e[64]||"";let u=0,c=0;for(;u<t.length-2;u+=3){var i=t[u],o=t[u+1],s=t[u+2],a=e[i>>2];i=e[(3&i)<<4|o>>4],o=e[(15&o)<<2|s>>6],s=e[63&s],r[c++]=a+i+o+s}switch(a=0,s=n,t.length-u){case 2:s=e[(15&(a=t[u+1]))<<2]||n;case 1:t=t[u],r[c]=e[t>>2]+e[(3&t)<<4|a>>4]+s+n}return r.join("")}for(e="",r=0,n=t.length-10240;r<n;)e+=String.fromCharCode.apply(null,t.subarray(r,r+=10240));return e+=String.fromCharCode.apply(null,r?t.subarray(r):t),btoa(e)}const w=/[-_.]/g,S={"-":"+",_:"/",".":"="};function A(t){return S[t]||""}function T(t){if(!b)return m(t);w.test(t)&&(t=t.replace(w,A)),t=atob(t);const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function E(t){return v&&null!=t&&t instanceof Uint8Array}var I={};let P;function O(t){if(t!==I)throw Error("illegal external caller")}function L(){return P||=new N(null,I)}var N=class{constructor(t,e){if(O(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function x(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let B;function U(){const e=Error();x(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function k(t){return x(t=Error(t),"warning"),t}function j(){return"function"==typeof BigInt}function F(t){return Array.prototype.slice.call(t)}var D="function"==typeof Symbol&&"symbol"==typeof Symbol();function M(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?Symbol():t}var V=M(),C=M("2ex"),G=M("1oa"),R=M("0dg"),z=D?(t,e)=>{t[V]|=e}:(t,e)=>{void 0!==t.s?t.s|=e:Object.defineProperties(t,{s:{value:e,configurable:!0,writable:!0,enumerable:!1}})},W=D?(t,e)=>{t[V]&=~e}:(t,e)=>{void 0!==t.s&&(t.s&=~e)},H=D?t=>0|t[V]:t=>0|t.s,$=D?t=>t[V]:t=>t.s,q=D?(t,e)=>{t[V]=e}:(t,e)=>{void 0!==t.s?t.s=e:Object.defineProperties(t,{s:{value:e,configurable:!0,writable:!0,enumerable:!1}})};function K(t,e){q(e,-14591&(0|t))}function Y(t,e){q(e,-14557&(34|t))}var J,X={},Z={};function Q(t){return!(!t||"object"!=typeof t||t.i!==Z)}function tt(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function et(t){return!(!Array.isArray(t)||t.length)&&!!(1&H(t))}const rt=[];function nt(t){if(2&t)throw Error()}q(rt,55),J=Object.freeze(rt);var it=Object.freeze({});Object.freeze({});var ot=Object.freeze({});function st(t){return t.ca=!0,t}var at=st((t=>"number"==typeof t)),ut=st((t=>"string"==typeof t)),ct=st((t=>"boolean"==typeof t)),lt="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),ht=st((t=>lt?t>=dt&&t<=gt:"-"===t[0]?mt(t,ft):mt(t,pt)));const ft=Number.MIN_SAFE_INTEGER.toString(),dt=lt?BigInt(Number.MIN_SAFE_INTEGER):void 0,pt=Number.MAX_SAFE_INTEGER.toString(),gt=lt?BigInt(Number.MAX_SAFE_INTEGER):void 0;function mt(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){const n=t[r],i=e[r];if(n>i)return!1;if(n<i)return!0}}let _t,vt=0,bt=0;function yt(t){const e=t>>>0;vt=e,bt=(t-e)/4294967296>>>0}function wt(t){if(t<0){yt(-t);const[e,r]=Et(vt,bt);vt=e>>>0,bt=r>>>0}else yt(t)}function St(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else j()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,t>=1e7&&(r+=t/1e7>>>0,t%=1e7),r>=1e7&&(e+=r/1e7>>>0,r%=1e7),r=e+At(r)+At(t));return r}function At(t){return t=String(t),"0000000".slice(t.length)+t}function Tt(t){if(t.length<16)wt(Number(t));else if(j())t=BigInt(t),vt=Number(t&BigInt(4294967295))>>>0,bt=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);bt=vt=0;const r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){const e=Number(t.slice(n,i));bt*=1e6,vt=1e6*vt+e,vt>=4294967296&&(bt+=Math.trunc(vt/4294967296),bt>>>=0,vt>>>=0)}if(e){const[t,e]=Et(vt,bt);vt=t,bt=e}}}function Et(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function It(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}function Pt(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}const Ot=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Lt(t){const e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return"string"===e&&Ot.test(t)}function Nt(t){if("number"!=typeof t)throw k("int32");if(!Number.isFinite(t))throw k("int32");return 0|t}function xt(t){return null==t?t:Nt(t)}function Bt(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function Ut(t){if(null!=t){if("number"!=typeof t)throw k("uint32");if(!Number.isFinite(t))throw k("uint32");t>>>=0}return t}function kt(t){return"-"!==t[0]&&(t.length<20||20===t.length&&Number(t.substring(0,6))<184467)}function jt(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asUintN(64,t));if(Lt(t)){if("string"===e)return e=Math.trunc(Number(t)),Number.isSafeInteger(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),kt(t)||(Tt(t),t=St(vt,bt))),t;if("number"===e)return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:function(t){if(t<0){wt(t);const e=St(vt,bt);return t=Number(e),Number.isSafeInteger(t)?t:e}return kt(String(t))?t:(wt(t),4294967296*bt+(vt>>>0))}(t)}}function Ft(t){return null==t||"string"==typeof t?t:void 0}function Dt(t,e,r){if(null!=t&&"object"==typeof t&&t.N===X)return t;if(Array.isArray(t)){var n=H(t),i=n;return 0===i&&(i|=32&r),(i|=2&r)!==n&&q(t,i),new e(t)}}function Mt(t){if(void 0===Gt&&(Gt="function"==typeof Proxy?Jt(Proxy):null),!Gt||!Yt())return t;let e=Vt?.get(t);return e||(Math.random()>.01?t:(function(t){if(void 0===zt){const t=new Gt([],{});zt=1===Array.prototype.concat.call([],t).length}zt&&"function"==typeof Symbol&&Symbol.isConcatSpreadable&&(t[Symbol.isConcatSpreadable]=!0)}(t),e=new Gt(t,{set:(t,e,r)=>(U(),t[e]=r,!0)}),function(t,e){(Vt||=new Rt).set(t,e),(Ct||=new Rt).set(e,t)}(t,e),e))}let Vt,Ct,Gt,Rt,zt,Wt,Ht,$t,qt,Kt;function Yt(){return void 0===Rt&&(Rt="function"==typeof WeakMap?Jt(WeakMap):null),Rt}function Jt(t){try{return-1!==t.toString().indexOf("[native code]")?t:null}catch{return null}}function Xt(t,e,r){if(Yt()){if(Wt?.get(e)?.get(t)){if(r)return}else if(Math.random()>.01)return;var n=t.length;r={length:n};for(var i=0;i<Math.min(n,10);i++){if(n<=10)var o=i;else{o=n/10;const t=Math.floor(i*o);o=t+Math.floor(Math.random()*(Math.floor((i+1)*o)-t))}r[o]=t[o]}Qt(t,r)?((i=(n=Wt||=new Rt).get(e))||(i=new Rt,n.set(e,i)),i.set(t,r)):(U(),ee(t,e))}}function Zt(t,e){const r=Wt?.get(e)?.get(t);r&&!Qt(t,r)&&(U(),ee(t,e))}function Qt(t,e){if(t.length!==e.length)return!1;for(const i in e){var r,n=Number(i);if((r=Number.isInteger(n))&&(r=t[n],n=e[n],r=!(Number.isNaN(r)?Number.isNaN(n):r===n)),r)return!1}return!0}function te(t){if(t&&Wt?.has(t)){var e=t.m;if(e)for(let r=0;r<e.length;r++){const n=e[r];if(r===e.length-1&&tt(n))for(const e in n){const r=n[e];Array.isArray(r)&&Zt(r,t)}else Array.isArray(n)&&Zt(n,t)}}}function ee(t,e){Wt?.get(e)?.delete(t)}function re(t,e){return t=ne(t,e[0],e[1]),z(t,16384),t}function ne(t,e,r){if(null==t&&(t=Ht),Ht=void 0,null==t){var n=96;r?(t=[r],n|=512):t=[],e&&(n=-33521665&n|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(n=H(t)))throw Error("farr");if(64&n)return t;if(n|=64,r&&(n|=512,r!==t[0]))throw Error("mid");t:{const i=(r=t).length;if(i){const t=i-1;if(tt(r[t])){if((e=t-(+!!(512&(n|=256))-1))>=1024)throw Error("pvtlmt");n=-33521665&n|(1023&e)<<15;break t}}if(e){if((e=Math.max(e,i-(+!!(512&n)-1)))>1024)throw Error("spvt");n=-33521665&n|(1023&e)<<15}}}return q(t,n),t}function ie(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=et(t)?void 0:i&&2&H(t)?t:oe(t,e,r,void 0!==n,i);else if(tt(t)){const o={};for(let s in t)o[s]=ie(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function oe(t,e,r,n,i){const o=n||r?H(t):0;n=n?!!(32&o):void 0,t=F(t);for(let o=0;o<t.length;o++)t[o]=ie(t[o],e,r,n,i);return r&&r(o,t),t}function se(t){return t.N===X?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"bigint":return ht(t)?Number(t):String(t);case"boolean":return t?1:0;case"object":if(t)if(Array.isArray(t)){if(et(t))return}else{if(E(t))return y(t);if(t instanceof N){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=y(e)}}}return t}(t)}function ae(t,e,r=Y){if(null!=t){if(v&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=H(t);return 2&n?t:(e&&=0===n||!!(32&n)&&!(64&n||!(16&n)),e?(q(t,-12293&(34|n)),t):oe(t,ae,4&n?Y:r,!0,!0))}return t.N===X&&(r=t.m,t=2&(n=$(r))?t:ue(t,r,n,!0)),t}}function ue(t,e,r,n){return te(t),t=t.constructor,Ht=e=function(t,e,r){const n=r||2&e?Y:K,i=!!(32&e);return t=function(t,e,r){var n=(t=F(t)).length;const i=256&e?t[n-1]:void 0;for(n+=i?-1:0,e=512&e?1:0;e<n;e++)t[e]=r(t[e]);if(i){e=t[e]={};for(const t in i)e[t]=r(i[t])}return t}(t,e,(t=>ae(t,i,n))),z(t,32|(r?2:0)),t}(e,r,n),e=new t(e),Ht=void 0,e}function ce(t){const e=t.m,r=$(e);return 2&r?ue(t,e,r,!1):t}function le(t,e,r,n){return!(4&e)||null!=r&&(!n&&0===r&&(4096&e||8192&e)&&(t.constructor[R]=1+(0|t.constructor[R]))<5&&U(),0!==r&&!(r&e))}function he(t,e){return de(t=t.m,$(t),e)}function fe(t,e,r,n){if(!((e=n+(+!!(512&e)-1))<0||e>=t.length||e>=r))return t[e]}function de(t,e,r,n){if(-1===r)return null;const i=e>>15&1023||536870912;if(!(r>=i)){var o=t.length;return n&&256&e&&null!=(n=t[o-1][r])?(fe(t,e,i,r)&&null!=C&&((e=(t=B??={})[C]||0)>=4||(t[C]=e+1,U())),n):fe(t,e,i,r)}return 256&e?t[t.length-1][r]:void 0}function pe(t,e,r){const n=t.m;let i=$(n);return nt(i),ge(n,i,e,r),t}function ge(t,e,r,n){const i=e>>15&1023||536870912;if(r>=i){let o,s=e;if(256&e)o=t[t.length-1];else{if(null==n)return s;o=t[i+(+!!(512&e)-1)]={},s|=256}return o[r]=n,r<i&&(t[r+(+!!(512&e)-1)]=void 0),s!==e&&q(t,s),s}return t[r+(+!!(512&e)-1)]=n,256&e&&(r in(t=t[t.length-1])&&delete t[r]),e}function me(t,e,r,n,i,o){const s=t.m;let a=$(s);n=2&a?1:n,o=!!o,i=_e(s,a,e,i);var u=H(i),c=i;if(Zt(c,t),2!==n&&1!==n||ee(c,t),le(t,u,void 0,o)){4&u&&(i=F(i),u=Ee(u,a),a=ge(s,a,e,i));let t=c=0;for(;c<i.length;c++){const e=r(i[c]);null!=e&&(i[t++]=e)}t<c&&(i.length=t),u=-4097&(20|(u=ve(u,a))),q(i,u&=-8193),2&u&&Object.freeze(i)}let l;return 1===n||4===n&&32&u?be(u)||(t=u,(u|=2)!==t&&q(i,u),Object.freeze(i)):(r=5===n&&(!!(32&u)||be(u)||!!Vt?.get(i)),(2===n||r)&&be(u)&&(i=F(i),u=Ie(u=Ee(u,a),a,o),q(i,u),a=ge(s,a,e,i)),be(u)||(e=u,(u=Ie(u,a,o))!==e&&q(i,u)),r?(l=Mt(i),Xt(i,t,!0)):2!==n||o||Vt?.delete(i)),l||i}function _e(t,e,r,n){return t=de(t,e,r,n),Array.isArray(t)?t:J}function ve(t,e){return 0===t&&(t=Ee(t,e)),1|t}function be(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function ye(t,e,r,n){t=t.m;let i=$(t);nt(i),ge(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function we(t){if(D)return t[G]??(t[G]=new Map);if(G in t)return t[G];const e=new Map;return Object.defineProperty(t,G,{value:e}),e}function Se(t,e,r){var n=qn;let i=t.get(n);if(null!=i)return i;i=0;for(let t=0;t<n.length;t++){const o=n[t];null!=de(e,r,o)&&(0!==i&&(r=ge(e,r,i)),i=o)}return t.set(n,i),i}function Ae(t,e,r){var n=t.m,i=$(n),o=de(n,i,r,!1);return(e=Dt(o,e,i))!==o&&null!=e&&ge(n,i,r,e),null==(n=e)||(t=t.m,2&(i=$(t))||(o=ce(n))!==n&&ge(t,i,r,n=o)),n}function Te(t,e,r){return null==r&&(r=void 0),pe(t,e,r)}function Ee(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function Ie(t,e,r){return 32&e&&r||(t&=-33),t}function Pe(t,e,r,n){var i=$(t.m);nt(i);const o=t.m;var s=!!(2&i);const a=s?1:2;d&&=!s,s=_e(o,i,e);var u=H(s),c=s;if(Zt(c,t),2!==a&&1!==a||ee(c,t),!(c=!!(4&u))){var l=s,h=i,f=!!(2&(u=ve(u,i)));f&&(h|=2);let t=!f,e=!0,n=0,o=0;for(;n<l.length;n++){const i=Dt(l[n],r,h);if(i instanceof r){if(!f){const r=!!(2&H(i.m));t&&=!r,e&&=r}l[o++]=i}}o<n&&(l.length=o),u|=4,u=e?16|u:-17&u,q(l,u=t?8|u:-9&u),f&&Object.freeze(l)}if(d&&!(8&u||!s.length&&(1===a||4===a&&32&u))){be(u)?(s=F(s),u=Ee(u,i),i=ge(o,i,e,s)):ee(s,t);var d=s;for(l=u,u=0;u<d.length;u++)(h=d[u])!==(f=ce(h))&&(d[u]=f);l|=8,l=d.length?-17&l:16|l,q(d,l),u=l}if(1===a||4===a&&32&u)be(u)||(t=u,(u|=!s.length||16&u&&(!c||32&u)?2:2048)!==t&&q(s,u),Object.freeze(s));else if(c=5===a&&(!!(32&u)||be(u)||!!Vt?.get(s)),(2===a||c)&&be(u)&&(s=F(s),u=Ie(u=Ee(u,i),i,!0),q(s,u),i=ge(o,i,e,s)),be(u)||(e=u,(u=Ie(u,i,!0))!==e&&q(s,u)),c){var p=Mt(s);Xt(s,t,!0)}p=p||s,n=null!=n?n:new r,p.push(n),2&H(n.m)?W(p,8):W(p,16)}function Oe(t){return t??0}function Le(t,e){return Oe(function(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?t>>>0:void 0}(he(t,e)))}function Ne(t,e,r){ye(t,e,xt(r),0)}function xe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();ye(t,e,r,"")}function Be(t,e,r){{const a=t.m;let u=$(a);if(nt(u),null==r)ge(a,u,e);else{r=Ct?.get(r)||r;var n,i=H(r),o=i,s=!!(2&i)||Object.isFrozen(r);if((n=!s)&&(n=void 0===ot||!1),le(t,i)){i=21,s&&(r=F(r),o=0,i=Ie(i=Ee(i,u),u,!0));for(let t=0;t<r.length;t++)r[t]=Nt(r[t])}n?(r=F(r),o=0,i=Ie(i=Ee(i,u),u,!0)):s||Xt(r,t),i!==o&&q(r,i),ge(a,u,e,r)}}}function Ue(t,e,r){if(nt($(t.m)),e=(t=me(t,e,Ft,2,void 0,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}function ke(t){if("string"==typeof t)return{buffer:T(t),C:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),C:!1};if(t.constructor===Uint8Array)return{buffer:t,C:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),C:!1};if(t.constructor===N){O(I);var e=t.i;return{buffer:(null==(e=null==e||E(e)?e:"string"==typeof e?T(e):null)?e:t.i=e)||new Uint8Array(0),C:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),C:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}var je=class{constructor(t,e){this.m=ne(t,e)}toJSON(){return Fe(this)}C(){return!!(2&H(this.m))}};function Fe(t){te(t),t=Kt?t.m:oe(t.m,se,void 0,void 0,!1);{var e=!Kt;let c=t.length;if(c){var r=t[c-1],n=tt(r);n?c--:r=void 0;var i=t;if(n){t:{var o,s=r,a=!1;if(s)for(let t in s)isNaN(+t)?(o??={})[t]=s[t]:(n=s[t],Array.isArray(n)&&(et(n)||Q(n)&&0===n.size)&&(n=null),null==n&&(a=!0),null!=n&&((o??={})[t]=n));if(a||(o=s),o)for(let t in o){a=o;break t}a=null}s=null==a?null!=r:a!==r}for(;c>0&&(null==(o=i[c-1])||et(o)||Q(o)&&0===o.size);c--)var u=!0;(i!==t||s||u)&&(e?(u||s||a)&&(i.length=c):i=Array.prototype.slice.call(i,0,c),a&&i.push(a)),u=i}else u=t}return u}function De(t){return t?/^\d+$/.test(t)?(Tt(t),new Me(vt,bt)):null:Ve||=new Me(0,0)}je.prototype.N=X,je.prototype.toString=function(){try{return Kt=!0,Fe(this).toString()}finally{Kt=!1}};var Me=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Ve;function Ce(t){return t?/^-?\d+$/.test(t)?(Tt(t),new Ge(vt,bt)):null:Re||=new Ge(0,0)}var Ge=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Re;function ze(t,e,r){for(;r>0||e>127;)t.i.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.i.push(e)}function We(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function He(t,e){if(e>=0)We(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function $e(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function qe(t,e){return We(t.i,8*e+2),e=t.i.end(),$e(t,e),e.push(t.j),e}function Ke(t,e){var r=e.pop();for(r=t.j+t.i.length()-r;r>127;)e.push(127&r|128),r>>>=7,t.j++;e.push(r),t.j++}function Ye(t,e,r){We(t.i,8*e+2),We(t.i,r.length),$e(t,t.i.end()),$e(t,r)}var Je=class{constructor(){}},Xe=class{constructor(){}},Ze=class{constructor(){}},Qe=class{constructor(){}},tr=class{constructor(){}},er=class{constructor(){}},rr=class{constructor(t,e){this.i=t,t=Je,this.j=!!t&&e===t||!1}};function nr(t,e,r,n,i){null!=(e=hr(e,n))&&(r=qe(t,r),i(e,t),Ke(t,r))}const ir=new rr(nr,Je),or=new rr(nr,Je);var sr=Symbol(),ar=Symbol();let ur;function cr(t){var e=fr,r=dr,n=t[sr];if(n)return n;(n={}).P=function(t){switch(typeof t){case"boolean":return $t||=[0,void 0,!0];case"number":return t>0?void 0:0===t?qt||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);var i=t[1];let o=1;i&&i.constructor===Object&&(n.M=i,"function"==typeof(i=t[++o])&&(n.X=!0,ur??=t[o+1],i=t[o+=2]));const s={};for(;i&&Array.isArray(i)&&i.length&&"number"==typeof i[0]&&i[0]>0;){for(var a=0;a<i.length;a++)s[i[a]]=i;i=t[++o]}for(a=1;void 0!==i;){let s;"number"==typeof i&&(a+=i,i=t[++o]);var u=void 0;if(i instanceof rr?s=i:(s=ir,o--),s?.j){i=t[++o],u=t;var c=o;"function"==typeof i&&(i=i(),u[c]=i),u=i}for(c=a+1,"number"==typeof(i=t[++o])&&i<0&&(c-=i,i=t[++o]);a<c;a++)u?r(n,a,s,u):e(n,a,s)}return t[sr]=n}let lr=0;function hr(t,e){return t instanceof je?(te(t),t.m):Array.isArray(t)?re(t,e):void 0}function fr(t,e,r){t[e]=r.i}function dr(t,e,r,n){let i,o;const s=r.i;t[e]=(t,e,r)=>s(t,e,r,o||=cr(n).P,i||=pr(n))}function pr(t){let e=t[ar];if(!e){const r=cr(t);e=(t,e)=>gr(t,e,r),t[ar]=e}return e}function gr(t,e,r){for(var n=$(t),i=+!!(512&n)-1,o=t.length,s=512&n?1:0,a=o+(256&n?-1:0);s<a;s++){const n=t[s];if(null==n)continue;const o=s-i,a=mr(r,o);if(!a)continue;const u=r.M;u?.[o]&&!u?.D?.[o]&&lr++<5&&U(),a(e,n,o)}if(256&n){t=t[o-1];for(const s in t)n=+s,!Number.isNaN(n)&&(null!=(i=t[n])&&(o=mr(r,n)))&&((a=r.M)?.[n]&&!a?.D?.[n]&&lr++<5&&U(),o(e,i,n))}}function mr(t,e){var r=t[e];if(r)return r;if(r=t.M){var n=r[e];if(n){var i=(n=Array.isArray(n)?n[0]instanceof rr?n:[or,n]:[n,void 0])[0].i;if(n=n[1],r=r?.D?.[e],!a||r){if(n){const e=pr(n),o=cr(n).P;r=t.X?ur(o,e):(t,r,n)=>i(t,r,n,o,e)}else r=i;return t[e]=r}}}}var _r,vr=0,br=vr;if(ut(br)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(br))throw Error(String(br))}else if((_r=at(br))&&(_r=!Number.isSafeInteger(br)),_r)throw Error(String(br));function yr(t,e){if(Array.isArray(e)){var r=H(e);if(4&r)return e;for(var n=0,i=0;n<e.length;n++){const r=t(e[n]);null!=r&&(e[i++]=r)}return i<n&&(e.length=i),q(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}function wr(t,e){return new rr(t,e)}function Sr(t,e,r){null!=(e=Pt(e))&&(We(t.i,8*r+5),t=t.i,(r=_t||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),bt=0,e=vt=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))}function Ar(t,e,r){null!=(e=Bt(e))&&null!=e&&(We(t.i,8*r),He(t.i,e))}function Tr(t,e,r){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(We(t.i,8*r),t.i.i.push(e?1:0))}function Er(t,e,r){null!=(e=Ft(e))&&Ye(t,r,i(e))}function Ir(t,e,r,n,i){null!=(e=hr(e,n))&&(r=qe(t,r),i(e,t),Ke(t,r))}function Pr(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),We(t.i,8*r),He(t.i,e))}lt||(vr=ct(vr)?vr?"1":"0":ut(vr)?vr.trim()||"0":String(vr));var Or,Lr=wr(Sr,tr),Nr=wr(Sr,tr),xr=wr((function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asIntN(64,t));if(Lt(t)){if("string"===e){if(e=Math.trunc(Number(t)),Number.isSafeInteger(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),!("-"===t[0]?t.length<20||20===t.length&&Number(t.substring(0,7))>-922337:t.length<19||19===t.length&&Number(t.substring(0,6))<922337))if(Tt(t),t=vt,2147483648&(e=bt))if(j())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[r,n]=Et(t,e);t="-"+St(r,n)}else t=St(t,e);return t}if("number"===e){if(t=Math.trunc(t),!Number.isSafeInteger(t)){wt(t),e=vt;var r=bt;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),e=4294967296*r+(e>>>0),t=t?-e:e}return t}}}(e),null!=e){if("string"==typeof e)Ce(e);if(null!=e)switch(We(t.i,8*r),typeof e){case"number":t=t.i,wt(e),ze(t,vt,bt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ge(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),ze(t.i,r.j,r.i);break;default:r=Ce(e),ze(t.i,r.j,r.i)}}}),class{constructor(){}}),Br=wr((function(t,e,r){if(null!=(e=jt(e))){if("string"==typeof e)De(e);if(null!=e)switch(We(t.i,8*r),typeof e){case"number":t=t.i,wt(e),ze(t,vt,bt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Me(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),ze(t.i,r.j,r.i);break;default:r=De(e),ze(t.i,r.j,r.i)}}}),class{constructor(){}}),Ur=wr(Ar,Qe);Or=new rr((function(t,e,r){if(null!=(e=yr(Bt,e))&&e.length){r=qe(t,r);for(let r=0;r<e.length;r++)He(t.i,e[r]);Ke(t,r)}}),Qe);var kr,jr=wr(Ar,Qe),Fr=wr(Ar,Qe),Dr=wr(Tr,Xe),Mr=wr(Tr,Xe),Vr=wr(Er,Ze);kr=new rr((function(t,e,r){if(null!=(e=yr(Ft,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&Ye(n,o,i(s))}}),Ze);var Cr,Gr=wr(Er,Ze),Rr=wr(Er,Ze),zr=function(t,e,r=Je){return new rr(e,r)}(0,(function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)Ir(t,e[o],r,n,i)})),Wr=new rr(Ir,Je),Hr=wr(Pr,er);Cr=new rr((function(t,e,r){if(null!=(e=yr(Bt,e))&&e.length){r=qe(t,r);for(let r=0;r<e.length;r++)He(t.i,e[r]);Ke(t,r)}}),er);var $r=wr(Pr,er);function qr(t){return function(){te(this);const e=new class{constructor(){this.l=[],this.j=0,this.i=new class{constructor(){this.i=[]}length(){return this.i.length}end(){const t=this.i;return this.i=[],t}}}};gr(this.m,e,cr(t)),$e(e,e.i.end());const r=new Uint8Array(e.j),n=e.l,i=n.length;let o=0;for(let t=0;t<i;t++){const e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function Kr(t,e){if(null!=e)if(Array.isArray(e))pe(t,2,oe(e,se,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof N||E(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new N(e,I):L();else if(e.constructor!==N){if(!E(e))throw Error();e=e.length?new N(new Uint8Array(e),I):L()}ye(t,2,e,L())}}var Yr=class extends je{constructor(t){super(t)}},Jr=[0,Gr,wr((function(t,e,r){if(null!=e){if(e instanceof je){const n=e.da;return void(n&&(e=n(e),null!=e&&Ye(t,r,ke(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||E(e)||e instanceof N?e:void 0)&&Ye(t,r,ke(e).buffer)}),class{constructor(){}})],Xr=[0,Vr,Dr,-1,Ur,[0,[1,2,3,4,5,6,7],Wr,[0],Wr,[0,Dr,Vr,Dr,Hr,-1,Cr,Vr,-1,[0,Dr,-1],Hr,Dr,-1],Wr,[0,Vr,-2],Wr,[0,Ur,Dr,1,Dr,-3],Wr,[0,Ur,Hr,Dr,-1,Or,Hr,-1],Wr,[0,Vr,-2],Wr,[0,Vr,Hr]],[0,Vr],Dr,[0,[1,3],[2,4],Wr,[0,Or],-1,Wr,[0,kr],-1,zr,[0,Vr,-1]],Vr],Zr={},Qr=Zr.D={};Zr[336783863]=Xr,Qr[336783863]=1;var tn=class extends je{constructor(t){super(t)}},en=[0,xr,-1,Mr,-3,xr,Or,Gr,jr,xr,-1,Mr,jr,Mr,-2,Gr],rn=class extends je{constructor(t){super(t,500)}L(t){return Te(this,7,t)}},nn=[-1,{D:{}}],on=[0,Vr,1,nn],sn=[0,Vr,kr,nn];function an(t,e){Pe(t,1,rn,e)}var un=class extends je{constructor(){super(void 0,500)}L(t){return Te(this,1001,t)}};un.prototype.i=qr([-500,zr,[-500,Gr,-1,kr,-3,[-2,Zr,Dr],zr,Jr,jr,-1,on,sn,zr,[0,Gr,Mr],Gr,en,jr,kr,987,kr],4,zr,[-500,Vr,-1,[-1,{D:{}}],998,Vr],zr,[-500,Vr,kr,-1,[-2,{D:{}},Dr],997,kr,-1],jr,zr,[-500,Vr,kr,nn,998,kr],kr,jr,on,sn,zr,[0,Gr,-1,nn],kr,-2,en,Gr,-1,Mr,979,nn,zr,Jr]);var cn=class extends je{constructor(t){super(t)}};let ln;const hn=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]);async function fn(){if(void 0===ln)try{await WebAssembly.instantiate(hn),ln=!0}catch{ln=!1}return ln}async function dn(t,e=""){const r=await fn()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var pn=class{};function gn(){var t=navigator;return"undefined"!=typeof OffscreenCanvas&&(!function(t=navigator){return(t=t.userAgent).includes("Safari")&&!t.includes("Chrome")}(t)||!!((t=t.userAgent.match(/Version\/([\d]+).*Safari/))&&t.length>=1&&Number(t[1])>=17))}async function mn(t){if("function"!=typeof importScripts){const e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((t,r)=>{e.addEventListener("load",(()=>{t()}),!1),e.addEventListener("error",(t=>{r(t)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}pn.forVisionTasks=function(t){return dn("vision",t)},pn.forTextTasks=function(t){return dn("text",t)},pn.forGenAiExperimentalTasks=function(t){return dn("genai_experimental",t)},pn.forGenAiTasks=function(t){return dn("genai",t)},pn.forAudioTasks=function(t){return dn("audio",t)},pn.isSimdSupported=function(){return fn()};function _n(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function vn(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");const n=new Uint32Array(e.length);for(let r=0;r<e.length;r++)n[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*n.length),t.h.HEAPU32.set(n,e>>2),r(e);for(const e of n)t.h._free(e);t.h._free(e)}function bn(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function yn(t,e,r){let n=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(r(n,i),n=[]):n.push(t)}}const wn=(Sn=class{constructor(t,e){this.l=!0,this.h=t,this.i=null,this.j=0,this.o="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:gn()?this.h.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas"))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),_n(this,n||"input_audio",(n=>{_n(this,i=i||"audio_header",(i=>{this.h._configureAudio(n,i,t,e??0,r)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,i){const o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),_n(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){_n(this,e,(e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();const n=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!n)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1);const[i,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||i===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=i,this.h.canvas.height=o);const[s,a]=[i,o];this.h._addBoundTextureToStream(e,s,a,r)}))}addBoolToStream(t,e,r){_n(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){_n(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){_n(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){_n(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){_n(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){_n(this,e,(e=>{_n(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){_n(this,e,(e=>{vn(this,Object.keys(t),(n=>{vn(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){_n(this,r,(r=>{_n(this,e,(e=>{const i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputStream(i,t.length,e,r,n),this.h._free(i)}))}))}addEmptyPacketToStream(t,e){_n(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputStream(n,e,r)}))}addDoubleVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputStream(n,e,r)}))}addFloatVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputStream(n,e,r)}))}addIntVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)}))}addUintVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputStream(n,e,r)}))}addStringVectorToStream(t,e,r){_n(this,e,(e=>{const n=this.h._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(const e of t)_n(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){_n(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){_n(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){_n(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){_n(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){_n(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){_n(this,e,(e=>{_n(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){_n(this,r,(r=>{_n(this,e,(e=>{const n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputSidePacket(n,t.length,e,r),this.h._free(n)}))}))}addBoolVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)}))}addDoubleVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)}))}addFloatVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)}))}addIntVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)}))}addUintVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)}))}addStringVectorToInputSidePacket(t,e){_n(this,e,(e=>{const r=this.h._allocateStringVector(t.length);if(!r)throw Error("Unable to allocate new string vector on heap.");for(const e of t)_n(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){bn(this,t,e),_n(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){yn(this,t,e),_n(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){bn(this,t,e),_n(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){yn(this,t,e),_n(this,t,(t=>{this.h._attachProtoVectorListener(t,r||!1)}))}attachAudioListener(t,e,r){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),bn(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),_n(this,t,(t=>{this.h._attachAudioListener(t,r||!1)}))}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends Sn{Z(){this.h._registerModelResourcesGraphService()}});var Sn;async function An(t,e){const r=await(async(t,e,r)=>{var n=ii;if(t&&await mn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await mn(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&r&&((t=self.Module).locateFile=r.locateFile,r.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=r.mainScriptUrlOrBlob)),r=await self.ModuleFactory(self.Module||r),self.ModuleFactory=self.Module=void 0,new n(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return await r.L(e),r}async function Tn(t,e){return An(t,e)}function En(t){try{const e=t.I.length;if(1===e)throw Error(t.I[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.I.map((t=>t.message)).join(", "))}finally{t.I=[]}}function In(t,e){t.H=Math.max(t.H,e)}var Pn=class{constructor(t){this.i=t,this.I=[],this.H=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.I.push(Error(e))})),this.i.Z(),this.i.setGraph(t,e),En(this)}finishProcessing(){this.i.finishProcessing(),En(this)}close(){this.i.closeGraph()}};Pn.prototype.close=Pn.prototype.close;var On=class extends je{constructor(t){super(t)}};function Ln(t,e){Te(t,1,e)}var Nn=class extends je{constructor(){super()}},xn=[0,$r,jr,Nr,-1,Ur];function Bn(t,e,r,n){if(void 0!==t.data){var i=new Uint8Array(t.data.buffer,e,r);return 1===n&&function(t,e,r){t.i.push([e,r]),t.i.sort(((t,e)=>t[0]-e[0])),e=0;for(const[n,i]of t.i){const t=i;(r=n)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),i}}class Un{constructor(t){this.i=[],this.data=t,this.length=t.length}}var kn=class{constructor(t,e,r){this.i=t,this.j=e,this.l=r}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function jn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Fn=class{constructor(t,e){this.h=t,this.l=e,this.j=this.h._malloc(e)>>>0,this.o=this.h.HEAPU8,this.i=!!this.j}get offset(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.j}get size(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.l}set(t,e){this.o.set(t,this.j+(e??0))}},Dn=class extends je{constructor(){super()}};Dn.prototype.i=qr([0,Gr,2,kr,jr,Mr]);var Mn=class extends je{constructor(){super()}},Vn=class extends je{constructor(){super()}},Cn=class extends je{constructor(){super()}},Gn=class extends je{constructor(){super()}},Rn=[0,jr,-6,1,jr,1,[0,Mr,$r,-2],[0,Mr,Nr],$r,-2,[0,Mr,-1,$r,Nr,Hr,Ur],1,Mr,jr,Ur,-1,[0,$r,jr],Mr,-1,Lr,jr],zn=[0,[4,6],Rn,jr,1,Fr,kr,Rr,Cr,[0,Gr,-2],Ur,[0,[0,jr,-1,zr,[0,jr,[0,jr,-1],-1,[0,$r,-1],Mr],Mr,-2,jr,-1],[0,jr,-1,Mr],Rn,Mr,jr],Vr,-3,[0,jr,Mr]],Wn=[0,zr,[0,Gr,Br,-1,$r],zn,jr];Gn.prototype.i=qr([0,Gr,8,[0,Mr,-6],1,jr,1,jr,Wn,[0,jr,Mr,-3],1,$r,Gr,zn,Wn,jr,5,$r,Or,1,xn]);var Hn=class extends je{constructor(){super()}},$n=class extends je{constructor(){super()}},qn=[2,4];$n.prototype.i=qr([0,qn,jr,Rr,jr,Wr,[0,1,Gr]]);const Kn=function(t){return class e extends t{static async aa(t,r){let n;r||=await e.R();const i=[];for(const e of t?.requiredFeatures??[])r.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{n=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return r=await r.requestAdapterInfo(),n.adapterInfo=r,n}static async R(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}W(t){if(e)"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id="canvas_webgpu");else var e=new OffscreenCanvas(1,1);e.getContext("webgpu").configure({device:t,format:navigator.gpu.getPreferredCanvasFormat()}),this.h.preinitializedWebGPUDevice=t}T(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}}}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket(((e,r,n)=>async function(t,e,r,n,i){if(2===i)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout((()=>{t.l()}),0),Promise.resolve(0);for(;t.size<r+n;){var o=await t.j();if(void 0===o)break;t.i.push(new Un(o))}if(t.size<r+n)throw Error(`Data size is too small: ${t.size}, expected at least ${r+n}.`);o=e._malloc(n)>>>0;let s=0;for(let a=0;a<t.i.length;a++){const u=t.i[a];if(r>=u.length){r-=u.length;continue}const c=Math.min(n,u.length-r);if(void 0===(r=Bn(u,r,c,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+s),r=0,s+=c,0==(n-=c))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}(t,this.h,e,r,n)),e)}}}(function(t){return class extends t{S(t,e){_n(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends wn{})));class Yn extends Kn{}var Jn=class{constructor(t){this.j=t,this.i=Xn,Xn++}},Xn=0;class Zn{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.resolve=t,this.reject=e}}function Qn(t){return 1===t?1:t+t%2}async function ti(){const t=await Yn.R({powerPreference:"high-performance"});var e=t.limits.maxBufferSize;if(t.limits.maxStorageBufferBindingSize<524550144)throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxStorageBufferBindingSize is at least 524550144 but your device only supports maxStorageBufferBindingSize of ${e}`);if(e>=786825216)e=786825216;else{if(!(e>=524550144))throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxBufferSize is at least 524550144 but your device only supports maxBufferSize of ${e}`);e=524550144}if(e={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:e,maxStorageBuffersPerShaderStage:t.limits.maxStorageBuffersPerShaderStage}},t.features.has("subgroups")){console.warn("Experimental Chromium WGSL subgroup support detected. Enabling this feature in the inference engine.");const r=["shader-f16","subgroups"];t.features.has("subgroups-f16")&&r.push("subgroups-f16"),e.requiredFeatures=r}return Yn.aa(e,t)}function ei(t){const e=function(t){const e=new un;Ue(e,10,"text_in"),Ue(e,10,"token_cost_in"),Ue(e,10,"lora_model_id_to_apply_in"),Ue(e,10,"lora_model_ref_in"),Ue(e,10,"lora_model_id_to_load_in"),Ue(e,16,"streaming_reader"),Ue(e,15,"text_out"),Ue(e,15,"text_end"),Ue(e,15,"token_cost_out");var r=new rn;xe(r,2,"TokenizerInputBuildCalculator"),Ue(r,3,"PROMPT:text_in"),Ue(r,3,"LORA_ID:lora_model_id_to_apply_in"),Ue(r,4,"prompt"),an(e,r),xe(r=new rn,2,"ModelDataCalculator"),Ue(r,6,"MODEL_DATA:__side_packet_1"),Ue(r,6,"MODEL_TYPE:model_type"),Ue(r,5,"READ_DATA_FN:streaming_reader"),Ue(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),Ue(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),Ue(r,4,"LORA_DATA:lora_model_data"),an(e,r),xe(r=new rn,2,"Gpt2UnicodeMappingCalculator"),Ue(r,5,"MODEL_TYPE:model_type"),Ue(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),an(e,r),xe(r=new Yr,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new $n,i=Le(t.j,2);Ne(n,1,i),xe(i=new Hn,2,"spm_vocab_model"),null==i&&(i=void 0);t:{var o=n.m,s=$(o);if(nt(s),null==i){var a=we(o);if(4!==Se(a,o,s))break t;a.set(qn,0)}else{const t=we(a=o),e=Se(t,a,s);4!==e&&(e&&(s=ge(a,s,e)),t.set(qn,4))}ge(o,s,4,i)}return Ne(n,3,2),Kr(r,n.i()),xe(n=new rn,2,"TokenizerCalculator"),Pe(n,8,Yr,r),Ue(n,5,"MODEL_DATA:__side_packet_1"),Ue(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),Ue(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Ue(n,6,"PROCESSOR_GETTER:__input_side_1"),Ue(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),an(e,n),xe(r=new Yr,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),Ne(n=new Gn,12,3),xe(n,1,"llm.tflite"),Ne(n,14,0),i=Qn(Le(t.j,5)),Ne(n,22,i),i=Ae(t.j,On,3),Te(n,31,i),ye(i=new Mn,1,!0,!1),ye(i,2,!0,!1),ye(i,5,!0,!1),Te(n,10,i),i=me(t.j,4,Bt,void 0===it?2:5),Be(n,29,i),i=new Cn,Ne(o=new Vn,1,1),a=Le(t.j,2),Ne(o,2,a),Te(i,1,o),Te(n,20,i),Kr(r,n.i()),xe(n=new rn,2,"LlmGpuCalculator"),Pe(n,8,Yr,r),Ue(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),Ue(n,3,"FINISH:finish"),Ue(n,3,"LORA_DATA:lora_model_data"),Ue(n,5,"MODEL_DATA:__side_packet_1"),Ue(n,4,"DECODED_IDS:__stream_3"),Ue(n,4,"OUTPUT_END:__stream_4"),xe(r=new tn,1,"FINISH"),ye(r,2,!0,!1),Pe(n,13,tn,r),an(e,n),xe(r=new rn,2,"IsPacketPresentCalculator"),Ue(r,3,"__stream_4"),Ue(r,4,"text_end"),an(e,r),xe(r=new Yr,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new Dn,t=Qn(Le(t.j,5)),Ne(n,5,t),Ue(n,4,"<eos>"),Ue(n,4,"<|endoftext|>"),Kr(r,n.i()),xe(t=new rn,2,"DetokenizerCalculator"),Pe(t,8,Yr,r),Ue(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),Ue(t,5,"PROCESSOR_GETTER:__input_side_1"),Ue(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Ue(t,5,"MODEL_DATA:__side_packet_1"),Ue(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),Ue(t,4,"WORDS:text_out"),an(e,t),xe(t=new rn,2,"TokenCostCalculator"),Ue(t,3,"PROMPT:token_cost_in"),Ue(t,5,"PROCESSOR_GETTER:__input_side_1"),Ue(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Ue(t,4,"NUM_TOKENS:token_cost_out"),an(e,t),e}(t);t.i.attachStringVectorListener("text_out",((e,r)=>{e=function(t,e){return null==t||0===t.length?[]:t.map((t=>(t=(t=t.replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),e&&(t=t.trimStart()),t.split("\\[eod\\]",1)[0])))}(e,0===t.F.length),e.forEach(((e,r)=>{r<Le(t.j,5)&&t.F[r].push(e)})),t.A&&0===t.B.length&&(t.G?(e.length>Le(t.j,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),In(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{In(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{if(t.l=!1,In(t,r),ri(t),t.o&&(t.o.resolve(t.F.map((t=>t.join("")))),t.o=void 0),t.A)if(t.G){for(e=[],r=0;r<Le(t.j,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.G=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.G=void 0,In(t,e),ri(t),t.o&&(t.o.resolve(t.F.map((t=>t.join("")))),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,r)=>{t.O=e,In(t,r)})),t.K&&t.i.addStreamingReaderToInputSidePacket(t.K,"streaming_reader");const r=e.i();return t.v?.removeEventListener("uncapturederror",t.J),t.i.T().then((()=>{t.v?.addEventListener("uncapturederror",t.J),t.B.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function ri(t){if(t.B.length>0){const e=[...t.B];if(t.B.length=0,!t.o)throw e;t.o.reject(e),t.o=void 0}}function ni(t,e,r,n){if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.A="function"==typeof r?r:n,t.l=!0,t.F.length=0,n=0;n<Le(t.j,5);n++)t.F[n]=[];if(n=t.H+1,t.i.addStringToStream(e,"text_in",n),r instanceof Jn){if(r.j!==t)throw t.l=!1,t.G=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.i.addUintToStream(r.i,"lora_model_id_to_apply_in",n)}else t.i.addEmptyPacketToStream("lora_model_id_to_apply_in",n);return t.finishProcessing(),t.o=new Zn,t.o.promise}var ii=class extends Pn{constructor(t,e){super(new Yn(t,e)),this.F=[],this.l=!1,this.B=[],this.J=t=>{const e=(t=t.error).message.match(/exceeds the max buffer size limit \(([0-9]+)\)\./);e&&Number(e[1])>524550144?t=Error(`Failed to run this LLM model, but you could try a smaller LLM model. WebGPU throws: "${t.message}"`):t.message.match(/is larger than the maximum binding size/)&&(t=Error(`Failed to run LLM inference, the supported max binding size is smaller than the required size. WebGPU throws: "${t.message}"`)),this.B.push(t)},this.j=new Nn,Ln(this.j,new cn),this.u=new On,Te(this.j,3,this.u),pe(this.j,2,Ut(512)),ye(this.u,1,2,0),Ne(this.u,2,40),ye(this.u,3,It(1),0),pe(this.u,5,xt(0)),ye(this.u,4,It(.8),0),pe(this.j,5,Ut(1))}L(t){if(this.l)throw Error("Cannot set options while loading or processing.");if(this.l=!0,t.baseOptions?.gpuOptions?.device&&(this.v&&this.v.removeEventListener("uncapturederror",this.J),this.v=t.baseOptions.gpuOptions.device,this.i.W(this.v),this.v.addEventListener("uncapturederror",this.J)),"maxTokens"in t&&pe(this.j,2,Ut(t.maxTokens??512)),"topK"in t&&Ne(this.u,2,t.topK??40),"temperature"in t&&ye(this.u,4,It(t.temperature??.8),0),"randomSeed"in t&&pe(this.u,5,xt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){Be(t,4,e)}(this.j,t.loraRanks??[]),"numResponses"in t){var e=t.numResponses??1;if(e<1)throw Error("'numResponses' must be at least 1.");pe(this.j,5,Ut(e));var r=Ae(this.j,On,3);e>1&&r&&(Oe(Bt(he(r,2)))<=1||Oe(function(t){t=t.m;let e=$(t);const r=de(t,e,4),n=Pt(r);return null!=n&&n!==r&&ge(t,e,4,n),n}(r))<=0)&&console.warn("To generate multiple responses, it is expected topK > 1 and temperature > 0; otherwise, all the generated responses may be the same.")}let n;if(e=new Promise((t=>{n=t})),t.baseOptions?.modelAssetPath||t.baseOptions?.modelAssetBuffer){if(t.baseOptions.modelAssetPath&&t.baseOptions.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");r=!1,t.baseOptions.modelAssetPath?this.K=function(t,e){const r=fetch(t.toString()).then((t=>t?.body?.getReader()));return new kn([],(async()=>{let e;try{e=await r}catch(e){throw Error(`Error loading model from "${t.toString()}": ${e}`)}const{value:n,done:i}=await e.read();return i?void 0:n}),e)}(t.baseOptions.modelAssetPath,n):t.baseOptions.modelAssetBuffer instanceof Uint8Array?(this.K=function(t,e){return new kn([new Un(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,n),r=!0):t.baseOptions.modelAssetBuffer?(this.K=function(t,e){return new kn([],(async()=>{const{value:e,done:r}=await t.read();return r?void 0:e}),e)}(t.baseOptions.modelAssetBuffer,n),r=!0):n(),r&&(t.baseOptions.modelAssetBuffer=void 0)}return t=ei(this).then((()=>{})),Promise.all([e,t]).then((()=>{this.l=!1,ri(this)}))}get baseOptions(){return Ae(this.j,cn,1)}set baseOptions(t){Ln(this.j,t)}U(t,e,r){return Le(this.j,5)>1&&console.warn("'numResponses' is set larger than 1 and this function only returns the first response, so we recommend either using 'generateResponses()' to obtain multiple responses, or else setting 'numResponses' to 1 for better performance."),this.G=!1,ni(this,t,e,r).then((t=>t[0]))}V(t,e,r){return this.G=!0,ni(this,t,e,r)}ba(t){if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.O=void 0,this.i.addStringToStream(t,"token_cost_in",this.H+1),this.finishProcessing(),this.l=!1,this.O}async Y(t){if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new Fn(this.i.h,t.length);e.set(t),t=e}else t=await async function(t,e){var r=await fetch(e.toString());e=Number(r.headers.get("content-length")),t=new Fn(t,e);let n=0;for(r=r?.body?.getReader();;){const{value:e,done:i}=await r.read();if(i)break;t.set(e,n),n+=e.byteLength}if(e!==n)throw jn(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${e} bytes before failure`);return t}(this.i.h,t);return e=new Jn(this),this.i.S(t,this.H+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.H+1),this.finishProcessing(),jn(t),this.l=!1,e}close(){this.v?.removeEventListener("uncapturederror",this.J),super.close()}};ii.prototype.loadLoraModel=ii.prototype.Y,ii.prototype.sizeInTokens=ii.prototype.ba,ii.prototype.generateResponses=ii.prototype.V,ii.prototype.generateResponse=ii.prototype.U,ii.prototype.setOptions=ii.prototype.L,ii.createWebGpuDevice=ti,ii.createFromModelPath=async function(t,e){return Tn(t,e={baseOptions:{gpuOptions:{device:await ti()},modelAssetPath:e}})},ii.createFromModelBuffer=async function(t,e){return Tn(t,e={baseOptions:{gpuOptions:{device:await ti()},modelAssetBuffer:e}})},ii.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await ti();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Tn(t,e)},exports.FilesetResolver=pn,exports.LlmInference=ii,exports.TaskRunner=Pn;
2
2
  //# sourceMappingURL=genai_bundle_cjs.js.map