@mediapipe/tasks-genai 0.10.18 → 0.10.19-rc.20241109

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,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(653718497,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 U(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let x;function B(){const e=Error();U(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function k(t){return U(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"),R=M("1oa"),G=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,-30975&(0|t))}function Y(t,e){q(e,-30941&(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({}),ot=Object.freeze({}),st=Object.freeze({});function at(t){return t.ba=!0,t}var ut=at((t=>"number"==typeof t)),ct=at((t=>"string"==typeof t)),lt=at((t=>"boolean"==typeof t)),ht="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),ft=at((t=>ht?t>=pt&&t<=mt:"-"===t[0]?_t(t,dt):_t(t,gt)));const dt=Number.MIN_SAFE_INTEGER.toString(),pt=ht?BigInt(Number.MIN_SAFE_INTEGER):void 0,gt=Number.MAX_SAFE_INTEGER.toString(),mt=ht?BigInt(Number.MAX_SAFE_INTEGER):void 0;function _t(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 vt,bt=0,yt=0;function wt(t){const e=t>>>0;bt=e,yt=(t-e)/4294967296>>>0}function St(t){if(t<0){wt(-t);const[e,r]=It(bt,yt);bt=e>>>0,yt=r>>>0}else wt(t)}function At(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+Tt(r)+Tt(t));return r}function Tt(t){return t=String(t),"0000000".slice(t.length)+t}function Et(t){if(t.length<16)St(Number(t));else if(j())t=BigInt(t),bt=Number(t&BigInt(4294967295))>>>0,yt=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);yt=bt=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));yt*=1e6,bt=1e6*bt+e,bt>=4294967296&&(yt+=Math.trunc(bt/4294967296),yt>>>=0,bt>>>=0)}if(e){const[t,e]=It(bt,yt);bt=t,yt=e}}}function It(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function Pt(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 Ot(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}const Lt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Nt(t){const e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return"string"===e&&Lt.test(t)}function Ut(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:Ut(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 kt(t){if(null!=t){if("number"!=typeof t)throw k("uint32");if(!Number.isFinite(t))throw k("uint32");t>>>=0}return t}function jt(t){return"-"!==t[0]&&(t.length<20||20===t.length&&Number(t.substring(0,6))<184467)}function Ft(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asUintN(64,t));if(Nt(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)),jt(t)||(Et(t),t=At(bt,yt))),t;if("number"===e)return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:function(t){if(t<0){St(t);const e=At(bt,yt);return t=Number(e),Number.isSafeInteger(t)?t:e}return jt(String(t))?t:(St(t),4294967296*yt+(bt>>>0))}(t)}}function Dt(t){return null==t||"string"==typeof t?t:void 0}function Mt(t,e,r){if(null!=t&&"object"==typeof t&&t.L===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 Vt(t){if(void 0===Gt&&(Gt="function"==typeof Proxy?Xt(Proxy):null),!Gt||!Jt())return t;let e=Ct?.get(t);return e||(Math.random()>.01?t:(function(t){if(void 0===Wt){const t=new Gt([],{});Wt=1===Array.prototype.concat.call([],t).length}Wt&&"function"==typeof Symbol&&Symbol.isConcatSpreadable&&(t[Symbol.isConcatSpreadable]=!0)}(t),e=new Gt(t,{set:(t,e,r)=>(B(),t[e]=r,!0)}),function(t,e){(Ct||=new zt).set(t,e),(Rt||=new zt).set(e,t)}(t,e),e))}let Ct,Rt,Gt,zt,Wt,Ht,$t,qt,Kt,Yt;function Jt(){return void 0===zt&&(zt="function"==typeof WeakMap?Xt(WeakMap):null),zt}function Xt(t){try{return-1!==t.toString().indexOf("[native code]")?t:null}catch{return null}}function Zt(t,e,r){if(Jt()){if(Ht?.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]}te(t,r)?((i=(n=Ht||=new zt).get(e))||(i=new zt,n.set(e,i)),i.set(t,r)):(B(),re(t,e))}}function Qt(t,e){const r=Ht?.get(e)?.get(t);r&&!te(t,r)&&(B(),re(t,e))}function te(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 ee(t){if(t&&Ht?.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)&&Qt(r,t)}else Array.isArray(n)&&Qt(n,t)}}}function re(t,e){Ht?.get(e)?.delete(t)}function ne(t,e,r){return t=ie(t,e[0],e[1],r?1:2),e!==qt&&r&&z(t,16384),t}function ie(t,e,r,n){if(n=n??0,null==t&&(t=$t),$t=void 0,null==t){var i=96;r?(t=[r],i|=512):t=[],e&&(i=-33521665&i|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(i=H(t)))throw Error("farr");if(64&i)return t;if(1===n||2===n||(i|=64),r&&(i|=512,r!==t[0]))throw Error("mid");t:{if(n=(r=t).length){const t=n-1;if(tt(r[t])){if((e=t-(+!!(512&(i|=256))-1))>=1024)throw Error("pvtlmt");i=-33521665&i|(1023&e)<<15;break t}}if(e){if((e=Math.max(e,n-(+!!(512&i)-1)))>1024)throw Error("spvt");i=-33521665&i|(1023&e)<<15}}}return q(t,i),t}function oe(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=et(t)?void 0:i&&2&H(t)?t:se(t,e,r,void 0!==n,i);else if(tt(t)){const o={};for(let s in t)o[s]=oe(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function se(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]=oe(t[o],e,r,n,i);return r&&r(o,t),t}function ae(t){return t.L===X?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"bigint":return ft(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 ue(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):se(t,ue,4&n?Y:r,!0,!0))}return t.L===X&&(r=t.m,t=2&(n=$(r))?t:ce(t,r,n,!0)),t}}function ce(t,e,r,n){return ee(t),t=t.constructor,$t=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=>ue(t,i,n))),z(t,32|(r?2:0)),t}(e,r,n),e=new t(e),$t=void 0,e}function le(t){const e=t.m,r=$(e);return 2&r?ce(t,e,r,!1):t}function he(t,e,r,n){return!(4&e)||null!=r&&(!n&&0===r&&(4096&e||8192&e)&&(t.constructor[G]=1+(0|t.constructor[G]))<5&&B(),0!==r&&!(r&e))}function fe(t,e){return pe(t=t.m,$(t),e)}function de(t,e,r,n){if(!((e=n+(+!!(512&e)-1))<0||e>=t.length||e>=r))return t[e]}function pe(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])?(de(t,e,i,r)&&null!=C&&((e=(t=x??={})[C]||0)>=4||(t[C]=e+1,B())),n):de(t,e,i,r)}return 256&e?t[t.length-1][r]:void 0}function ge(t,e,r){const n=t.m;let i=$(n);return nt(i),me(n,i,e,r),t}function me(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 _e(t,e,r,n,i,o){const s=t.m;let a=$(s);n=2&a?1:n,o=!!o,i=ve(s,a,e,i);var u=H(i),c=i;if(Qt(c,t),2!==n&&1!==n||re(c,t),he(t,u,void 0,o)){4&u&&(i=F(i),u=Ie(u,a),a=me(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=be(u,a))),q(i,u&=-8193),2&u&&Object.freeze(i)}let l;return 1===n||4===n&&32&u?ye(u)||(t=u,(u|=2)!==t&&q(i,u),Object.freeze(i)):(r=5===n&&(!!(32&u)||ye(u)||!!Ct?.get(i)),(2===n||r)&&ye(u)&&(i=F(i),u=Pe(u=Ie(u,a),a,o),q(i,u),a=me(s,a,e,i)),ye(u)||(e=u,(u=Pe(u,a,o))!==e&&q(i,u)),r?(l=Vt(i),Zt(i,t,!0)):2!==n||o||Ct?.delete(i)),l||i}function ve(t,e,r,n){return t=pe(t,e,r,n),Array.isArray(t)?t:J}function be(t,e){return 0===t&&(t=Ie(t,e)),1|t}function ye(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function we(t,e,r,n){t=t.m;let i=$(t);nt(i),me(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function Se(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 Ae(t,e,r){var n=Yn;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!=pe(e,r,o)&&(0!==i&&(r=me(e,r,i)),i=o)}return t.set(n,i),i}function Te(t,e,r){var n=t.m,i=$(n),o=pe(n,i,r,!1);return(e=Mt(o,e,i))!==o&&null!=e&&me(n,i,r,e),null==(n=e)||(t=t.m,2&(i=$(t))||(o=le(n))!==n&&me(t,i,r,n=o)),n}function Ee(t,e,r){return null==r&&(r=void 0),ge(t,e,r)}function Ie(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function Pe(t,e,r){return 32&e&&r||(t&=-33),t}function Oe(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=ve(o,i,e);var u=H(s),c=s;if(Qt(c,t),2!==a&&1!==a||re(c,t),!(c=!!(4&u))){var l=s,h=i,f=!!(2&(u=be(u,i)));f&&(h|=2);let t=!f,e=!0,n=0,o=0;for(;n<l.length;n++){const i=Mt(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))){ye(u)?(s=F(s),u=Ie(u,i),i=me(o,i,e,s)):re(s,t);var d=s;for(l=u,u=0;u<d.length;u++)(h=d[u])!==(f=le(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)ye(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)||ye(u)||!!Ct?.get(s)),(2===a||c)&&ye(u)&&(s=F(s),u=Pe(u=Ie(u,i),i,!0),q(s,u),i=me(o,i,e,s)),ye(u)||(e=u,(u=Pe(u,i,!0))!==e&&q(s,u)),c){var p=Vt(s);Zt(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 Le(t){return t??0}function Ne(t,e){return Le(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}(fe(t,e)))}function Ue(t,e,r){we(t,e,xt(r),0)}function xe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();we(t,e,r,"")}function Be(t,e,r){{const u=t.m;let c=$(u);if(nt(c),null==r)me(u,c,e);else{r=Rt?.get(r)||r;var n,i=H(r),o=i,s=!!(2&i)||Object.isFrozen(r);if((n=!s)&&((n=void 0===st)||(n=!!a&&void 0!==ot)),he(t,i)){i=21,s&&(r=F(r),o=0,i=Pe(i=Ie(i,c),c,!0));for(let t=0;t<r.length;t++)r[t]=Ut(r[t])}n?(r=F(r),o=0,i=Pe(i=Ie(i,c),c,!0)):s||Zt(r,t),i!==o&&q(r,i),me(u,c,e,r)}}}function ke(t,e,r){if(nt($(t.m)),e=(t=_e(t,e,Dt,2,void 0,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}function je(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 Fe=class{constructor(t,e){this.m=ie(t,e)}toJSON(){return De(this)}C(){return!!(2&H(this.m))}};function De(t){ee(t),t=Yt?t.m:se(t.m,ae,void 0,void 0,!1);{var e=!Yt;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 Me(t){return t?/^\d+$/.test(t)?(Et(t),new Ve(bt,yt)):null:Ce||=new Ve(0,0)}Fe.prototype.L=X,Fe.prototype.toString=function(){try{return Yt=!0,De(this).toString()}finally{Yt=!1}};var Ve=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Ce;function Re(t){return t?/^-?\d+$/.test(t)?(Et(t),new Ge(bt,yt)):null:ze||=new Ge(0,0)}var Ge=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ze;function We(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 He(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function $e(t,e){if(e>=0)He(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function qe(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Ke(t,e){return He(t.i,8*e+2),e=t.i.end(),qe(t,e),e.push(t.j),e}function Ye(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 Je(t,e,r){He(t.i,8*e+2),He(t.i,r.length),qe(t,t.i.end()),qe(t,r)}function Xe(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Ze=Xe(),Qe=Xe(),tr=Xe(),er=Xe(),rr=Xe(),nr=Xe(),ir=class{constructor(t,e){this.i=t,t=Ze,this.j=!!t&&e===t||!1}};function or(t,e,r,n,i){null!=(e=fr(e,n))&&(r=Ke(t,r),i(e,t),Ye(t,r))}const sr=new ir(or,Ze),ar=new ir(or,Ze);var ur=Symbol(),cr=Symbol();let lr;function hr(t){var e=dr,r=pr,n=t[ur];if(n)return n;(n={}).N=function(t){switch(typeof t){case"boolean":return qt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Kt||=[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.S=i,"function"==typeof(i=t[++o])&&(n.W=!0,lr??=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 ir?s=i:(s=sr,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[ur]=n}function fr(t,e){return t instanceof Fe?(ee(t),t.m):Array.isArray(t)?ne(t,e,!1):void 0}function dr(t,e,r){t[e]=r.i}function pr(t,e,r,n){let i,o;const s=r.i;t[e]=(t,e,r)=>s(t,e,r,o||=hr(n).N,i||=gr(n))}function gr(t){let e=t[cr];if(!e){const r=hr(t);e=(t,e)=>mr(t,e,r),t[cr]=e}return e}function mr(t,e,r){var n=H(t),i=+!!(512&n)-1,o=t.length,s=512&n?1:0;const a=o+(256&n?-1:0);for(;s<a;s++){const n=t[s];if(null==n)continue;const o=s-i,a=_r(r,o);a&&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=_r(r,n))&&o(e,i,n)}}function _r(t,e){var r=t[e];if(r)return r;if((r=t.S)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof ir?r:[ar,r]:[r,void 0])[0].i;if(r=r[1]){const e=gr(r),i=hr(r).N;r=t.W?lr(i,e):(t,r,o)=>n(t,r,o,i,e)}else r=n;return t[e]=r}}var vr,br=0,yr=br;if(ct(yr)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(yr))throw Error(String(yr))}else if((vr=ut(yr))&&(vr=!Number.isSafeInteger(yr)),vr)throw Error(String(yr));function wr(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 Sr(t,e){return new ir(t,e)}function Ar(t,e,r){null!=(e=Ot(e))&&(He(t.i,8*r+5),t=t.i,(r=vt||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),yt=0,e=bt=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 Tr(t,e,r){null!=(e=Bt(e))&&null!=e&&(He(t.i,8*r),$e(t.i,e))}function Er(t,e,r){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(He(t.i,8*r),t.i.i.push(e?1:0))}function Ir(t,e,r){null!=(e=Dt(e))&&Je(t,r,i(e))}function Pr(t,e,r,n,i){null!=(e=fr(e,n))&&(r=Ke(t,r),i(e,t),Ye(t,r))}function Or(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),He(t.i,8*r),$e(t.i,e))}ht||(br=lt(br)?br?"1":"0":ct(br)?br.trim()||"0":String(br));var Lr,Nr=Sr(Ar,rr),Ur=Sr(Ar,rr),xr=Sr((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(Nt(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(Et(t),t=bt,2147483648&(e=yt))if(j())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[r,n]=It(t,e);t="-"+At(r,n)}else t=At(t,e);return t}if("number"===e){if(t=Math.trunc(t),!Number.isSafeInteger(t)){St(t),e=bt;var r=yt;(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)Re(e);if(null!=e)switch(He(t.i,8*r),typeof e){case"number":t=t.i,St(e),We(t,bt,yt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ge(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),We(t.i,r.j,r.i);break;default:r=Re(e),We(t.i,r.j,r.i)}}}),Xe()),Br=Sr((function(t,e,r){if(null!=(e=Ft(e))){if("string"==typeof e)Me(e);if(null!=e)switch(He(t.i,8*r),typeof e){case"number":t=t.i,St(e),We(t,bt,yt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ve(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),We(t.i,r.j,r.i);break;default:r=Me(e),We(t.i,r.j,r.i)}}}),Xe()),kr=Sr(Tr,er);Lr=new ir((function(t,e,r){if(null!=(e=wr(Bt,e))&&e.length){r=Ke(t,r);for(let r=0;r<e.length;r++)$e(t.i,e[r]);Ye(t,r)}}),er);var jr,Fr=Sr(Tr,er),Dr=Sr(Tr,er),Mr=Sr(Er,Qe),Vr=Sr(Er,Qe),Cr=Sr(Ir,tr);jr=new ir((function(t,e,r){if(null!=(e=wr(Dt,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&Je(n,o,i(s))}}),tr);var Rr,Gr=Sr(Ir,tr),zr=Sr(Ir,tr),Wr=function(t,e,r=Ze){return new ir(e,r)}(0,(function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)Pr(t,e[o],r,n,i)})),Hr=new ir(Pr,Ze),$r=Sr(Or,nr);Rr=new ir((function(t,e,r){if(null!=(e=wr(Bt,e))&&e.length){r=Ke(t,r);for(let r=0;r<e.length;r++)$e(t.i,e[r]);Ye(t,r)}}),nr);var qr=Sr(Or,nr);function Kr(t){return function(){ee(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}}}};mr(this.m,e,hr(t)),qe(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 Yr(t,e){if(null!=e)if(Array.isArray(e))ge(t,2,se(e,ae,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()}we(t,2,e,L())}}var Jr=class extends Fe{constructor(t){super(t)}},Xr=[0,Gr,Sr((function(t,e,r){if(null!=e){if(e instanceof Fe){const n=e.ca;return void(n&&(e=n(e),null!=e&&Je(t,r,je(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||E(e)||e instanceof N?e:void 0)&&Je(t,r,je(e).buffer)}),Xe())];let Zr,Qr=globalThis.trustedTypes;function tn(t){void 0===Zr&&(Zr=function(){let t=null;if(!Qr)return t;try{const e=t=>t;t=Qr.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}());var e=Zr;return new class{constructor(t){this.i=t}toString(){return this.i+""}}(e?e.createScriptURL(t):t)}function en(t,...e){if(0===e.length)return tn(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return tn(r)}var rn={};rn[336783863]=[0,Cr,Mr,-1,kr,[0,[1,2,3,4,5,6,7],Hr,[0],Hr,[0,Mr,Cr,Mr,$r,-1,Rr,Cr,-1,[0,Mr,-1],$r,Mr,-1],Hr,[0,Cr,-2],Hr,[0,kr,Mr,1,Mr,-3],Hr,[0,kr,$r,Mr,-1,Lr,$r,-1],Hr,[0,Cr,-2],Hr,[0,Cr,$r]],[0,Cr],Mr,[0,[1,3],[2,4],Hr,[0,Lr],-1,Hr,[0,jr],-1,Wr,[0,Cr,-1]],Cr];var nn=class extends Fe{constructor(t){super(t)}},on=[0,xr,-1,Vr,-3,xr,Lr,Gr,Fr,xr,-1,Vr,Fr,Vr,-2,Gr],sn=class extends Fe{constructor(t){super(t,500)}K(t){return Ee(this,7,t)}},an=[-1,{}],un=[0,Cr,1,an],cn=[0,Cr,jr,an];function ln(t,e){Oe(t,1,sn,e)}var hn=class extends Fe{constructor(){super(void 0,500)}K(t){return Ee(this,1001,t)}};hn.prototype.i=Kr([-500,Wr,[-500,Gr,-1,jr,-3,[-2,rn,Mr],Wr,Xr,Fr,-1,un,cn,Wr,[0,Gr,Vr],Gr,on,Fr,jr,987,jr],4,Wr,[-500,Cr,-1,[-1,{}],998,Cr],Wr,[-500,Cr,jr,-1,[-2,{},Mr],997,jr,-1],Fr,Wr,[-500,Cr,jr,an,998,jr],jr,Fr,un,cn,Wr,[0,Gr,-1,an],jr,-2,on,Gr,-1,Vr,979,an,Wr,Xr]);var fn=class extends Fe{constructor(t){super(t)}};let dn;const pn=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 gn(){if(void 0===dn)try{await WebAssembly.instantiate(pn),dn=!0}catch{dn=!1}return dn}async function mn(t,e=en``){const r=await gn()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var _n=class{};function vn(){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 bn(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())}_n.forVisionTasks=function(t){return mn("vision",t)},_n.forTextTasks=function(t){return mn("text",t)},_n.forGenAiExperimentalTasks=function(t){return mn("genai_experimental",t)},_n.forGenAiTasks=function(t){return mn("genai",t)},_n.forAudioTasks=function(t){return mn("audio",t)},_n.isSimdSupported=function(){return gn()};function yn(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 wn(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 Sn(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function An(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 Tn=(En=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:vn()?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?'),yn(this,n||"input_audio",(n=>{yn(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),yn(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){yn(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){yn(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){yn(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){yn(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){yn(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){yn(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){yn(this,e,(e=>{yn(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){yn(this,e,(e=>{wn(this,Object.keys(t),(n=>{wn(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){yn(this,r,(r=>{yn(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){yn(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){yn(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){yn(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){yn(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){yn(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){yn(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){yn(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)yn(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){yn(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){yn(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){yn(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){yn(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){yn(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){yn(this,e,(e=>{yn(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){yn(this,r,(r=>{yn(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){yn(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){yn(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){yn(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){yn(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){yn(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){yn(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)yn(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){Sn(this,t,e),yn(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){An(this,t,e),yn(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){Sn(this,t,e),yn(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){An(this,t,e),yn(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?'),Sn(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),yn(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 En{Y(){this.h._registerModelResourcesGraphService()}});var En;async function In(t,e){const r=await(async(t,e,r)=>{var n=si;if(t&&await bn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await bn(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.K(e),r}async function Pn(t,e){return In(t,e)}function On(t){try{const e=t.H.length;if(1===e)throw Error(t.H[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.H.map((t=>t.message)).join(", "))}finally{t.H=[]}}function Ln(t,e){t.G=Math.max(t.G,e)}var Nn=class{constructor(t){this.i=t,this.H=[],this.G=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.H.push(Error(e))})),this.i.Y(),this.i.setGraph(t,e),On(this)}finishProcessing(){this.i.finishProcessing(),On(this)}close(){this.i.closeGraph()}};Nn.prototype.close=Nn.prototype.close;var Un=class extends Fe{constructor(t){super(t)}};function xn(t,e){Ee(t,1,e)}var Bn=class extends Fe{constructor(){super()}},kn=[0,qr,Fr,Ur,-1,kr];function jn(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 Fn{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Dn=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 Mn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Vn=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))}},Cn=class extends Fe{constructor(){super()}};Cn.prototype.i=Kr([0,Gr,2,jr,Fr,Vr]);var Rn=class extends Fe{constructor(){super()}},Gn=class extends Fe{constructor(){super()}},zn=class extends Fe{constructor(){super()}},Wn=class extends Fe{constructor(){super()}},Hn=[0,Fr,-6,1,Fr,1,[0,Vr,qr,-2],[0,Vr,Ur],qr,-2,[0,Vr,-1,qr,Ur,$r,kr],1,Vr,Fr,kr,-1,[0,qr,Fr],Vr,-1,Nr,Fr],$n=[0,[4,6],Hn,Fr,1,Dr,jr,zr,Rr,[0,Gr,-2],kr,[0,[0,Fr,-1,Wr,[0,Fr,[0,Fr,-1],-1,[0,qr,-1],Vr],Vr,-2,Fr,-1],[0,Fr,-1,Vr],Hn,Vr,Fr],Cr,-3,[0,Fr,Vr]];Wn.prototype.i=Kr([0,Gr,8,[0,Vr,-6],1,Fr,1,Fr,[0,Wr,[0,Gr,Br,-1,qr],$n,Fr],[0,Fr,Vr,-3],1,qr,1,$n,1,Fr,5,qr,Lr,1,kn]);var qn=class extends Fe{constructor(){super()}},Kn=class extends Fe{constructor(){super()}},Yn=[2,4];Kn.prototype.i=Kr([0,Yn,Fr,zr,Fr,Hr,[0,1,Gr]]);const Jn=function(t){return class e extends t{static async Z(t,r){let n;r||=await e.O();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 O(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}V(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}R(){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 Fn(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=jn(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{P(t,e){yn(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends Tn{})));class Xn extends Jn{}var Zn=class{constructor(t){this.j=t,this.i=Qn,Qn++}},Qn=0;class ti{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.resolve=t,this.reject=e}}function ei(t){return 1===t?1:t+t%2}async function ri(){const t=await Xn.O({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 Xn.Z(e,t)}function ni(t){const e=function(t){const e=new hn;ke(e,10,"text_in"),ke(e,10,"token_cost_in"),ke(e,10,"lora_model_id_to_apply_in"),ke(e,10,"lora_model_ref_in"),ke(e,10,"lora_model_id_to_load_in"),ke(e,16,"streaming_reader"),ke(e,15,"text_out"),ke(e,15,"text_end"),ke(e,15,"token_cost_out");var r=new sn;xe(r,2,"TokenizerInputBuildCalculator"),ke(r,3,"PROMPT:text_in"),ke(r,3,"LORA_ID:lora_model_id_to_apply_in"),ke(r,4,"prompt"),ln(e,r),xe(r=new sn,2,"ModelDataCalculator"),ke(r,6,"MODEL_DATA:__side_packet_1"),ke(r,6,"MODEL_TYPE:model_type"),ke(r,5,"READ_DATA_FN:streaming_reader"),ke(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),ke(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),ke(r,4,"LORA_DATA:lora_model_data"),ln(e,r),xe(r=new sn,2,"Gpt2UnicodeMappingCalculator"),ke(r,5,"MODEL_TYPE:model_type"),ke(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ln(e,r),xe(r=new Jr,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new Kn,i=Ne(t.j,2);Ue(n,1,i),xe(i=new qn,2,"spm_vocab_model"),null==i&&(i=void 0);t:{var o=n.m,s=$(o);if(nt(s),null==i){var a=Se(o);if(4!==Ae(a,o,s))break t;a.set(Yn,0)}else{const t=Se(a=o),e=Ae(t,a,s);4!==e&&(e&&(s=me(a,s,e)),t.set(Yn,4))}me(o,s,4,i)}return Ue(n,3,2),Yr(r,n.i()),xe(n=new sn,2,"TokenizerCalculator"),Oe(n,8,Jr,r),ke(n,5,"MODEL_DATA:__side_packet_1"),ke(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),ke(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ke(n,6,"PROCESSOR_GETTER:__input_side_1"),ke(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),ln(e,n),xe(r=new Jr,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),Ue(n=new Wn,12,3),xe(n,1,"llm.tflite"),Ue(n,14,0),i=ei(Ne(t.j,5)),Ue(n,22,i),i=Te(t.j,Un,3),Ee(n,31,i),we(i=new Rn,1,!0,!1),we(i,2,!0,!1),we(i,5,!0,!1),Ee(n,10,i),i=_e(t.j,4,Bt,void 0===it?2:5),Be(n,29,i),i=new zn,Ue(o=new Gn,1,1),a=Ne(t.j,2),Ue(o,2,a),Ee(i,1,o),Ee(n,20,i),Yr(r,n.i()),xe(n=new sn,2,"LlmGpuCalculator"),Oe(n,8,Jr,r),ke(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),ke(n,3,"FINISH:finish"),ke(n,3,"LORA_DATA:lora_model_data"),ke(n,5,"MODEL_DATA:__side_packet_1"),ke(n,4,"DECODED_IDS:__stream_3"),ke(n,4,"OUTPUT_END:__stream_4"),xe(r=new nn,1,"FINISH"),we(r,2,!0,!1),Oe(n,13,nn,r),ln(e,n),xe(r=new sn,2,"IsPacketPresentCalculator"),ke(r,3,"__stream_4"),ke(r,4,"text_end"),ln(e,r),xe(r=new Jr,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new Cn,t=ei(Ne(t.j,5)),Ue(n,5,t),ke(n,4,"<eos>"),ke(n,4,"<|endoftext|>"),Yr(r,n.i()),xe(t=new sn,2,"DetokenizerCalculator"),Oe(t,8,Jr,r),ke(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),ke(t,5,"PROCESSOR_GETTER:__input_side_1"),ke(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ke(t,5,"MODEL_DATA:__side_packet_1"),ke(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),ke(t,4,"WORDS:text_out"),ln(e,t),xe(t=new sn,2,"TokenCostCalculator"),ke(t,3,"PROMPT:token_cost_in"),ke(t,5,"PROCESSOR_GETTER:__input_side_1"),ke(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ke(t,4,"NUM_TOKENS:token_cost_out"),ln(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.D.length),e.forEach(((e,r)=>{r<Ne(t.j,5)&&t.D[r].push(e)})),t.A&&0===t.B.length&&(t.F?(e.length>Ne(t.j,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),Ln(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{Ln(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{if(t.l=!1,Ln(t,r),ii(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0),t.A)if(t.F){for(e=[],r=0;r<Ne(t.j,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.F=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.F=void 0,Ln(t,e),ii(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,r)=>{t.M=e,Ln(t,r)})),t.J&&t.i.addStreamingReaderToInputSidePacket(t.J,"streaming_reader");const r=e.i();return t.v?.removeEventListener("uncapturederror",t.I),t.i.R().then((()=>{t.v?.addEventListener("uncapturederror",t.I),t.B.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function ii(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 oi(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.D.length=0,n=0;n<Ne(t.j,5);n++)t.D[n]=[];if(n=t.G+1,t.i.addStringToStream(e,"text_in",n),r instanceof Zn){if(r.j!==t)throw t.l=!1,t.F=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 ti,t.o.promise}var si=class extends Nn{constructor(t,e){super(new Xn(t,e)),this.D=[],this.l=!1,this.B=[],this.I=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 Bn,xn(this.j,new fn),this.u=new Un,Ee(this.j,3,this.u),ge(this.j,2,kt(512)),we(this.u,1,2,0),Ue(this.u,2,40),we(this.u,3,Pt(1),0),ge(this.u,5,xt(0)),we(this.u,4,Pt(.8),0),ge(this.j,5,kt(1))}K(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.I),this.v=t.baseOptions.gpuOptions.device,this.i.V(this.v),this.v.addEventListener("uncapturederror",this.I)),"maxTokens"in t&&ge(this.j,2,kt(t.maxTokens??512)),"topK"in t&&Ue(this.u,2,t.topK??40),"temperature"in t&&we(this.u,4,Pt(t.temperature??.8),0),"randomSeed"in t&&ge(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.");ge(this.j,5,kt(e));var r=Te(this.j,Un,3);e>1&&r&&(Le(Bt(fe(r,2)))<=1||Le(function(t){t=t.m;let e=$(t);const r=pe(t,e,4),n=Ot(r);return null!=n&&n!==r&&me(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.J=function(t,e){const r=fetch(t.toString()).then((t=>t?.body?.getReader()));return new Dn([],(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.J=function(t,e){return new Dn([new Fn(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,n),r=!0):t.baseOptions.modelAssetBuffer?(this.J=function(t,e){return new Dn([],(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=ni(this).then((()=>{})),Promise.all([e,t]).then((()=>{this.l=!1,ii(this)}))}get baseOptions(){return Te(this.j,fn,1)}set baseOptions(t){xn(this.j,t)}T(t,e,r){return Ne(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.F=!1,oi(this,t,e,r).then((t=>t[0]))}U(t,e,r){return this.F=!0,oi(this,t,e,r)}aa(t){if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.M=void 0,this.i.addStringToStream(t,"token_cost_in",this.G+1),this.finishProcessing(),this.l=!1,this.M}async X(t){if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new Vn(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 Vn(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 Mn(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 Zn(this),this.i.P(t,this.G+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.G+1),this.finishProcessing(),Mn(t),this.l=!1,e}close(){this.v?.removeEventListener("uncapturederror",this.I),super.close()}};si.prototype.loadLoraModel=si.prototype.X,si.prototype.sizeInTokens=si.prototype.aa,si.prototype.generateResponses=si.prototype.U,si.prototype.generateResponse=si.prototype.T,si.prototype.setOptions=si.prototype.K,si.createWebGpuDevice=ri,si.createFromModelPath=async function(t,e){return Pn(t,e={baseOptions:{gpuOptions:{device:await ri()},modelAssetPath:e}})},si.createFromModelBuffer=async function(t,e){return Pn(t,e={baseOptions:{gpuOptions:{device:await ri()},modelAssetBuffer:e}})},si.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await ri();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Pn(t,e)},exports.FilesetResolver=_n,exports.LlmInference=si,exports.TaskRunner=Nn;
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));const u=t.navigator;function c(t){return!!s&&(!!o&&o.brands.some((({brand:e})=>e&&-1!=e.indexOf(t))))}function l(e){var n;return(n=t.navigator)&&(n=n.userAgent)||(n=""),-1!=n.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){const e=t.length;let 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);const r=new Uint8Array(n);let i=0;return function(t,e){function n(e){for(;r<t.length;){const e=t.charAt(r++),n=g[e];if(null!=n)return n;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}_();let r=0;for(;;){const t=n(-1),r=n(0),i=n(64),o=n(64);if(64===o&&-1===t)break;e(t<<2|r>>4),64!=i&&(e(r<<4&240|i>>2),64!=o&&e(i<<6&192|o))}}(t,(function(t){r[i++]=t})),i!==n?r.subarray(0,i):r}function _(){if(!g){g={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let n=0;n<5;n++){const r=t.concat(e[n].split(""));p[n]=r;for(let t=0;t<r.length;t++){const e=r[t];void 0===g[e]&&(g[e]=t)}}}}var b="undefined"!=typeof Uint8Array,y=!d&&"function"==typeof btoa;function v(t){if(!y){var e;void 0===e&&(e=0),_(),e=p[e];var n=Array(Math.floor(t.length/3)),r=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],n[c++]=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[c]=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 w=/[-_.]/g,S={"-":"+",_:"/",".":"="};function A(t){return S[t]||""}function T(t){if(!y)return m(t);w.test(t)&&(t=t.replace(w,A)),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 E(t){return b&&null!=t&&t instanceof Uint8Array}var I={};function P(){return L||=new O(null,I)}var O=class{constructor(t,e){if(x(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};let L,U;function x(t){if(t!==I)throw Error("illegal external caller")}function B(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function N(){const e=Error();B(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function k(t){return B(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 V(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?Symbol():t}var M=V(),C=V("2ex"),R=V("1oa"),G=V("0dg"),z=D?(t,e)=>{t[M]|=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[M]&=~e}:(t,e)=>{void 0!==t.s&&(t.s&=~e)},H=D?t=>0|t[M]:t=>0|t.s,$=D?t=>t[M]:t=>t.s,q=D?(t,e)=>{t[M]=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,-30975&(0|t))}function Y(t,e){q(e,-30941&(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 nt=[];function rt(t){if(2&t)throw Error()}q(nt,55),J=Object.freeze(nt);var it=Object.freeze({}),ot=Object.freeze({}),st=Object.freeze({});function at(t){return t.ba=!0,t}var ut=at((t=>"number"==typeof t)),ct=at((t=>"string"==typeof t)),lt=at((t=>"boolean"==typeof t)),ht="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),ft=at((t=>ht?t>=pt&&t<=mt:"-"===t[0]?_t(t,dt):_t(t,gt)));const dt=Number.MIN_SAFE_INTEGER.toString(),pt=ht?BigInt(Number.MIN_SAFE_INTEGER):void 0,gt=Number.MAX_SAFE_INTEGER.toString(),mt=ht?BigInt(Number.MAX_SAFE_INTEGER):void 0;function _t(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 bt,yt=0,vt=0;function wt(t){const e=t>>>0;yt=e,vt=(t-e)/4294967296>>>0}function St(t){if(t<0){wt(-t);const[e,n]=It(yt,vt);yt=e>>>0,vt=n>>>0}else wt(t)}function At(t,e){if(t>>>=0,(e>>>=0)<=2097151)var n=""+(4294967296*e+t);else j()?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+Tt(n)+Tt(t));return n}function Tt(t){return t=String(t),"0000000".slice(t.length)+t}function Et(t){if(t.length<16)St(Number(t));else if(j())t=BigInt(t),yt=Number(t&BigInt(4294967295))>>>0,vt=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);vt=yt=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));vt*=1e6,yt=1e6*yt+e,yt>=4294967296&&(vt+=Math.trunc(yt/4294967296),vt>>>=0,yt>>>=0)}if(e){const[t,e]=It(yt,vt);yt=t,vt=e}}}function It(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function Pt(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 Ot(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}const Lt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Ut(t){const e=typeof t;switch(e){case"bigint":return!0;case"number":return Number.isFinite(t)}return"string"===e&&Lt.test(t)}function xt(t){if("number"!=typeof t)throw k("int32");if(!Number.isFinite(t))throw k("int32");return 0|t}function Bt(t){return null==t?t:xt(t)}function Nt(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 kt(t){if(null!=t){if("number"!=typeof t)throw k("uint32");if(!Number.isFinite(t))throw k("uint32");t>>>=0}return t}function jt(t){return"-"!==t[0]&&(t.length<20||20===t.length&&Number(t.substring(0,6))<184467)}function Ft(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(BigInt.asUintN(64,t));if(Ut(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)),jt(t)||(Et(t),t=At(yt,vt))),t;if("number"===e)return(t=Math.trunc(t))>=0&&Number.isSafeInteger(t)?t:function(t){if(t<0){St(t);const e=At(yt,vt);return t=Number(e),Number.isSafeInteger(t)?t:e}return jt(String(t))?t:(St(t),4294967296*vt+(yt>>>0))}(t)}}function Dt(t){return null==t||"string"==typeof t?t:void 0}function Vt(t,e,n){if(null!=t&&"object"==typeof t&&t.L===X)return t;if(Array.isArray(t)){var r=H(t),i=r;return 0===i&&(i|=32&n),(i|=2&n)!==r&&q(t,i),new e(t)}}function Mt(t){var e;return void 0===Gt&&(Gt="function"==typeof Proxy?Yt(Proxy):null),(e=!Gt)||(void 0===zt&&(zt="function"==typeof WeakMap?Yt(WeakMap):null),e=!zt),e?t:(e=Ct?.get(t))?e:Math.random()>.01?t:(function(t){if(void 0===Wt){const t=new Gt([],{});Wt=1===Array.prototype.concat.call([],t).length}Wt&&"function"==typeof Symbol&&Symbol.isConcatSpreadable&&(t[Symbol.isConcatSpreadable]=!0)}(t),function(t,e){(Ct||=new zt).set(t,e),(Rt||=new zt).set(e,t)}(t,e=new Gt(t,{set:(t,e,n)=>(N(),t[e]=n,!0)})),e)}let Ct,Rt,Gt,zt,Wt,Ht,$t,qt,Kt;function Yt(t){try{return-1!==t.toString().indexOf("[native code]")?t:null}catch{return null}}function Jt(t,e,n){return t=Xt(t,e[0],e[1],n?1:2),e!==$t&&n&&z(t,16384),t}function Xt(t,e,n,r){if(r=r??0,null==t&&(t=Ht),Ht=void 0,null==t){var i=96;n?(t=[n],i|=512):t=[],e&&(i=-33521665&i|(1023&e)<<15)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(i=H(t)))throw Error("farr");if(64&i)return t;if(1===r||2===r||(i|=64),n&&(i|=512,n!==t[0]))throw Error("mid");t:{if(r=(n=t).length){const t=r-1;if(tt(n[t])){if((e=t-(+!!(512&(i|=256))-1))>=1024)throw Error("pvtlmt");i=-33521665&i|(1023&e)<<15;break t}}if(e){if((e=Math.max(e,r-(+!!(512&i)-1)))>1024)throw Error("spvt");i=-33521665&i|(1023&e)<<15}}}return q(t,i),t}function Zt(t,e,n,r,i){if(null!=t){if(Array.isArray(t))t=et(t)?void 0:i&&2&H(t)?t:Qt(t,e,n,void 0!==r,i);else if(tt(t)){const o={};for(let s in t)o[s]=Zt(t[s],e,n,r,i);t=o}else t=e(t,r);return t}}function Qt(t,e,n,r,i){const o=r||n?H(t):0;r=r?!!(32&o):void 0,t=F(t);for(let o=0;o<t.length;o++)t[o]=Zt(t[o],e,n,r,i);return n&&n(o,t),t}function te(t){return t.L===X?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"bigint":return ft(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 v(t);if(t instanceof O){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=v(e)}}}return t}(t)}function ee(t,e,n=Y){if(null!=t){if(b&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var r=H(t);return 2&r?t:(e&&=0===r||!!(32&r)&&!(64&r||!(16&r)),e?(q(t,-12293&(34|r)),t):Qt(t,ee,4&r?Y:n,!0,!0))}return t.L===X&&(n=t.m,t=2&(r=$(n))?t:ne(t,n,r,!0)),t}}function ne(t,e,n,r){return t=t.constructor,Ht=e=function(t,e,n){const r=n||2&e?Y:K,i=!!(32&e);return t=function(t,e,n){var r=(t=F(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=>ee(t,i,r))),z(t,32|(n?2:0)),t}(e,n,r),e=new t(e),Ht=void 0,e}function re(t){const e=t.m,n=$(e);return 2&n?ne(t,e,n,!1):t}function ie(t,e,n,r){return!(4&e)||null!=n&&(!r&&0===n&&(4096&e||8192&e)&&(t.constructor[G]=1+(0|t.constructor[G]))<5&&N(),0!==n&&!(n&e))}function oe(t,e){return ae(t=t.m,$(t),e)}function se(t,e,n,r){if(!((e=r+(+!!(512&e)-1))<0||e>=t.length||e>=n))return t[e]}function ae(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])?(se(t,e,i,n)&&null!=C&&((e=(t=U??={})[C]||0)>=4||(t[C]=e+1,N())),r):se(t,e,i,n)}return 256&e?t[t.length-1][n]:void 0}function ue(t,e,n){const r=t.m;let i=$(r);return rt(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&&q(t,s),s}return t[n+(+!!(512&e)-1)]=r,256&e&&(n in(t=t[t.length-1])&&delete t[n]),e}function le(t,e,n,r,i){const o=t.m;let s=$(o);const a=2&s?1:r;i=!!i,r=he(o,s,e);var u=H(r);if(ie(t,u,void 0,i)){4&u&&(r=F(r),u=ye(u,s),s=ce(o,s,e,r));let i=t=0;for(;t<r.length;t++){const e=n(r[t]);null!=e&&(r[i++]=e)}i<t&&(r.length=i),u=-4097&(20|(u=fe(u,s))),q(r,u&=-8193),2&u&&Object.freeze(r)}let c;return 1===a||4===a&&32&u?de(u)||(i=u,(u|=2)!==i&&q(r,u),Object.freeze(r)):(n=5===a&&(!!(32&u)||de(u)||!!Ct?.get(r)),(2===a||n)&&de(u)&&(r=F(r),u=ve(u=ye(u,s),s,i),q(r,u),s=ce(o,s,e,r)),de(u)||(e=u,(u=ve(u,s,i))!==e&&q(r,u)),n?c=Mt(r):2!==a||i||Ct?.delete(r)),c||r}function he(t,e,n){return t=ae(t,e,n),Array.isArray(t)?t:J}function fe(t,e){return 0===t&&(t=ye(t,e)),1|t}function de(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function pe(t,e,n,r){t=t.m;let i=$(t);rt(i),ce(t,i,e,("0"===r?0===Number(n):n===r)?void 0:n)}function ge(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 me(t,e,n){var r=Gr;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!=ae(e,n,o)&&(0!==i&&(n=ce(e,n,i)),i=o)}return t.set(r,i),i}function _e(t,e,n){var r=t.m,i=$(r),o=ae(r,i,n,!1);return(e=Vt(o,e,i))!==o&&null!=e&&ce(r,i,n,e),null==(r=e)||(t=t.m,2&(i=$(t))||(o=re(r))!==r&&ce(t,i,n,r=o)),r}function be(t,e,n){return null==n&&(n=void 0),ue(t,e,n)}function ye(t,e){return-2049&(t=32|(2&e?2|t:-3&t))}function ve(t,e,n){return 32&e&&n||(t&=-33),t}function we(t,e,n,r){var i,o=$(t.m);rt(o);const s=t.m,a=(t=!!(2&o))?1:2;d&&=!t,t=he(s,o,e);var u=H(t),c=!!(4&u);if(!c){var l=t,h=o,f=!!(2&(u=fe(u,o)));f&&(h|=2);let e=!f,r=!0,i=0,s=0;for(;i<l.length;i++){const t=Vt(l[i],n,h);if(t instanceof n){if(!f){const n=!!(2&H(t.m));e&&=!n,r&&=n}l[s++]=t}}s<i&&(l.length=s),u|=4,u=r?16|u:-17&u,q(l,u=e?8|u:-9&u),f&&Object.freeze(l)}if(d&&!(8&u||!t.length&&(1===a||4===a&&32&u))){de(u)&&(t=F(t),u=ye(u,o),o=ce(s,o,e,t));var d=t;for(l=u,u=0;u<d.length;u++)(h=d[u])!==(f=re(h))&&(d[u]=f);l|=8,l=d.length?-17&l:16|l,q(d,l),u=l}1===a||4===a&&32&u?de(u)||(e=u,(u|=!t.length||16&u&&(!c||32&u)?2:2048)!==e&&q(t,u),Object.freeze(t)):(c=5===a&&(!!(32&u)||de(u)||!!Ct?.get(t)),(2===a||c)&&de(u)&&(t=F(t),u=ve(u=ye(u,o),o,!0),q(t,u),o=ce(s,o,e,t)),de(u)||(e=u,(u=ve(u,o,!0))!==e&&q(t,u)),c&&(i=Mt(t))),i=i||t,r=null!=r?r:new n,i.push(r),2&H(r.m)?W(i,8):W(i,16)}function Se(t){return t??0}function Ae(t,e){return Se(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}(oe(t,e)))}function Te(t,e,n){pe(t,e,Bt(n),0)}function Ee(t,e,n){if(null!=n&&"string"!=typeof n)throw Error();pe(t,e,n,"")}function Ie(t,e,n){{const a=t.m;let u=$(a);if(rt(u),null==n)ce(a,u,e);else{n=Rt?.get(n)||n;var r,i=H(n),o=i,s=!!(2&i)||Object.isFrozen(n);if((r=!s)&&(r=void 0===st||void 0!==ot),ie(t,i))for(i=21,s&&(n=F(n),o=0,i=ve(i=ye(i,u),u,!0)),t=0;t<n.length;t++)n[t]=xt(n[t]);r&&(n=F(n),o=0,i=ve(i=ye(i,u),u,!0)),i!==o&&q(n,i),ce(a,u,e,n)}}}function Pe(t,e,n){if(rt($(t.m)),e=(t=le(t,e,Dt,2,!0)).push,"string"!=typeof n)throw Error();e.call(t,n)}function Oe(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===O){x(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 Le=class{constructor(t,e){this.m=Xt(t,e)}toJSON(){return Ue(this)}C(){return!!(2&H(this.m))}};function Ue(t){t=Kt?t.m:Qt(t.m,te,void 0,void 0,!1);{var e=!Kt;let c=t.length;if(c){var n=t[c-1],r=tt(n);r?c--: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)&&(et(r)||Q(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(;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 xe(t){return t?/^\d+$/.test(t)?(Et(t),new Be(yt,vt)):null:Ne||=new Be(0,0)}Le.prototype.L=X,Le.prototype.toString=function(){try{return Kt=!0,Ue(this).toString()}finally{Kt=!1}};var Be=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Ne;function ke(t){return t?/^-?\d+$/.test(t)?(Et(t),new je(yt,vt)):null:Fe||=new je(0,0)}var je=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Fe;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 Me(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 Ce(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(),Ce(t,e),e.push(t.j),e}function Ge(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 ze(t,e,n){Ve(t.i,8*e+2),Ve(t.i,n.length),Ce(t,t.i.end()),Ce(t,n)}function We(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var He=We(),$e=We(),qe=We(),Ke=We(),Ye=We(),Je=We(),Xe=class{constructor(t,e){this.i=t,t=He,this.j=!!t&&e===t||!1}};function Ze(t,e,n,r,i){null!=(e=sn(e,r))&&(n=Re(t,n),i(e,t),Ge(t,n))}const Qe=new Xe(Ze,He),tn=new Xe(Ze,He);var en=Symbol(),nn=Symbol();let rn;function on(t){var e=an,n=un,r=t[en];if(r)return r;(r={}).N=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&&(r.S=i,"function"==typeof(i=t[++o])&&(r.W=!0,rn??=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 Xe?s=i:(s=Qe,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?n(r,a,s,u):e(r,a,s)}return t[en]=r}function sn(t,e){return t instanceof Le?t.m:Array.isArray(t)?Jt(t,e,!1):void 0}function an(t,e,n){t[e]=n.i}function un(t,e,n,r){let i,o;const s=n.i;t[e]=(t,e,n)=>s(t,e,n,o||=on(r).N,i||=cn(r))}function cn(t){let e=t[nn];if(!e){const n=on(t);e=(t,e)=>ln(t,e,n),t[nn]=e}return e}function ln(t,e,n){var r=H(t),i=+!!(512&r)-1,o=t.length,s=512&r?1:0;const a=o+(256&r?-1:0);for(;s<a;s++){const r=t[s];if(null==r)continue;const o=s-i,a=hn(n,o);a&&a(e,r,o)}if(256&r){t=t[o-1];for(const s in t)r=+s,Number.isNaN(r)||null!=(i=t[r])&&(o=hn(n,r))&&o(e,i,r)}}function hn(t,e){var n=t[e];if(n)return n;if((n=t.S)&&(n=n[e])){var r=(n=Array.isArray(n)?n[0]instanceof Xe?n:[tn,n]:[n,void 0])[0].i;if(n=n[1]){const e=cn(n),i=on(n).N;n=t.W?rn(i,e):(t,n,o)=>r(t,n,o,i,e)}else n=r;return t[e]=n}}var fn,dn=0,pn=dn;if(ct(pn)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(pn))throw Error(String(pn))}else if((fn=ut(pn))&&(fn=!Number.isSafeInteger(pn)),fn)throw Error(String(pn));function gn(t,e){if(Array.isArray(e)){var n=H(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),q(e,-12289&(5|n)),2&n&&Object.freeze(e),e}}function mn(t,e){return new Xe(t,e)}function _n(t,e,n){null!=(e=Ot(e))&&(Ve(t.i,8*n+5),t=t.i,(n=bt||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),vt=0,e=yt=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 bn(t,e,n){null!=(e=Nt(e))&&null!=e&&(Ve(t.i,8*n),Me(t.i,e))}function yn(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 vn(t,e,n){null!=(e=Dt(e))&&ze(t,n,i(e))}function wn(t,e,n,r,i){null!=(e=sn(e,r))&&(n=Re(t,n),i(e,t),Ge(t,n))}function Sn(t,e,n){null!=(e=Nt(e))&&(e=parseInt(e,10),Ve(t.i,8*n),Me(t.i,e))}ht||(dn=lt(dn)?dn?"1":"0":ct(dn)?dn.trim()||"0":String(dn));var An,Tn=mn(_n,Ye),En=mn(_n,Ye),In=mn((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(Ut(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(Et(t),t=yt,2147483648&(e=vt))if(j())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[n,r]=It(t,e);t="-"+At(n,r)}else t=At(t,e);return t}if("number"===e){if(t=Math.trunc(t),!Number.isSafeInteger(t)){St(t),e=yt;var n=vt;(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)ke(e);if(null!=e)switch(Ve(t.i,8*n),typeof e){case"number":t=t.i,St(e),De(t,yt,vt);break;case"bigint":n=BigInt.asUintN(64,e),n=new je(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),De(t.i,n.j,n.i);break;default:n=ke(e),De(t.i,n.j,n.i)}}}),We()),Pn=mn((function(t,e,n){if(null!=(e=Ft(e))){if("string"==typeof e)xe(e);if(null!=e)switch(Ve(t.i,8*n),typeof e){case"number":t=t.i,St(e),De(t,yt,vt);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)}}}),We()),On=mn(bn,Ke);An=new Xe((function(t,e,n){if(null!=(e=gn(Nt,e))&&e.length){n=Re(t,n);for(let n=0;n<e.length;n++)Me(t.i,e[n]);Ge(t,n)}}),Ke);var Ln,Un=mn(bn,Ke),xn=mn(bn,Ke),Bn=mn(yn,$e),Nn=mn(yn,$e),kn=mn(vn,qe);Ln=new Xe((function(t,e,n){if(null!=(e=gn(Dt,e)))for(let a=0;a<e.length;a++){var r=t,o=n,s=e[a];null!=s&&ze(r,o,i(s))}}),qe);var jn,Fn=mn(vn,qe),Dn=mn(vn,qe),Vn=function(t,e,n=He){return new Xe(e,n)}(0,(function(t,e,n,r,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)wn(t,e[o],n,r,i)})),Mn=new Xe(wn,He),Cn=mn(Sn,Je);jn=new Xe((function(t,e,n){if(null!=(e=gn(Nt,e))&&e.length){n=Re(t,n);for(let n=0;n<e.length;n++)Me(t.i,e[n]);Ge(t,n)}}),Je);var Rn=mn(Sn,Je);function Gn(t){return function(){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}}}};ln(this.m,e,on(t)),Ce(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 zn(t,e){if(null!=e)if(Array.isArray(e))ue(t,2,Qt(e,te,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof O||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 O(e,I):P();else if(e.constructor!==O){if(!E(e))throw Error();e=e.length?new O(new Uint8Array(e),I):P()}pe(t,2,e,P())}}var Wn=class extends Le{constructor(t){super(t)}},Hn=[0,Fn,mn((function(t,e,n){if(null!=e){if(e instanceof Le){const r=e.ca;return void(r&&(e=r(e),null!=e&&ze(t,n,Oe(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||E(e)||e instanceof O?e:void 0)&&ze(t,n,Oe(e).buffer)}),We())];let $n,qn=globalThis.trustedTypes;function Kn(t){void 0===$n&&($n=function(){let t=null;if(!qn)return t;try{const e=t=>t;t=qn.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}());var e=$n;return new class{constructor(t){this.i=t}toString(){return this.i+""}}(e?e.createScriptURL(t):t)}function Yn(t,...e){if(0===e.length)return Kn(t[0]);let n=t[0];for(let r=0;r<e.length;r++)n+=encodeURIComponent(e[r])+t[r+1];return Kn(n)}var Jn={};Jn[336783863]=[0,kn,Bn,-1,On,[0,[1,2,3,4,5,6,7],Mn,[0],Mn,[0,Bn,kn,Bn,Cn,-1,jn,kn,-1,[0,Bn,-1],Cn,Bn,-1],Mn,[0,kn,-2],Mn,[0,On,Bn,1,Bn,-3],Mn,[0,On,Cn,Bn,-1,An,Cn,-1],Mn,[0,kn,-2],Mn,[0,kn,Cn]],[0,kn],Bn,[0,[1,3],[2,4],Mn,[0,An],-1,Mn,[0,Ln],-1,Vn,[0,kn,-1]],kn];var Xn=class extends Le{constructor(t){super(t)}},Zn=[0,In,-1,Nn,-3,In,An,Fn,Un,In,-1,Nn,Un,Nn,-2,Fn],Qn=class extends Le{constructor(t){super(t,500)}K(t){return be(this,7,t)}},tr=[-1,{}],er=[0,kn,1,tr],nr=[0,kn,Ln,tr];function rr(t,e){we(t,1,Qn,e)}var ir=class extends Le{constructor(){super(void 0,500)}K(t){return be(this,1001,t)}};ir.prototype.i=Gn([-500,Vn,[-500,Fn,-1,Ln,-3,[-2,Jn,Bn],Vn,Hn,Un,-1,er,nr,Vn,[0,Fn,Nn],Fn,Zn,Un,Ln,987,Ln],4,Vn,[-500,kn,-1,[-1,{}],998,kn],Vn,[-500,kn,Ln,-1,[-2,{},Bn],997,Ln,-1],Un,Vn,[-500,kn,Ln,tr,998,Ln],Ln,Un,er,nr,Vn,[0,Fn,-1,tr],Ln,-2,Zn,Fn,-1,Nn,979,tr,Vn,Hn]);var or=class extends Le{constructor(t){super(t)}};let sr;const ar=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 ur(){if(void 0===sr)try{await WebAssembly.instantiate(ar),sr=!0}catch{sr=!1}return sr}async function cr(t,e=Yn``){const n=await ur()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${n}.js`,wasmBinaryPath:`${e}/${t}_${n}.wasm`}}var lr=class{};function hr(){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 fr(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())}lr.forVisionTasks=function(t){return cr("vision",t)},lr.forTextTasks=function(t){return cr("text",t)},lr.forGenAiExperimentalTasks=function(t){return cr("genai_experimental",t)},lr.forGenAiTasks=function(t){return cr("genai",t)},lr.forAudioTasks=function(t){return cr("audio",t)},lr.isSimdSupported=function(){return ur()};function dr(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 pr(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 gr(t,e,n){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=n}function mr(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 _r=(br=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:hr()?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?'),dr(this,r||"input_audio",(r=>{dr(this,i=i||"audio_header",(i=>{this.h._configureAudio(r,i,t,e??0,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),dr(this,r,(t=>{this.h._addAudioToInputStream(this.i,e,n,t,i)}))}addGpuBufferToStream(t,e,n){dr(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){dr(this,e,(e=>{this.h._addBoolToInputStream(t,e,n)}))}addDoubleToStream(t,e,n){dr(this,e,(e=>{this.h._addDoubleToInputStream(t,e,n)}))}addFloatToStream(t,e,n){dr(this,e,(e=>{this.h._addFloatToInputStream(t,e,n)}))}addIntToStream(t,e,n){dr(this,e,(e=>{this.h._addIntToInputStream(t,e,n)}))}addUintToStream(t,e,n){dr(this,e,(e=>{this.h._addUintToInputStream(t,e,n)}))}addStringToStream(t,e,n){dr(this,e,(e=>{dr(this,t,(t=>{this.h._addStringToInputStream(t,e,n)}))}))}addStringRecordToStream(t,e,n){dr(this,e,(e=>{pr(this,Object.keys(t),(r=>{pr(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(r,i,Object.keys(t).length,e,n)}))}))}))}addProtoToStream(t,e,n,r){dr(this,n,(n=>{dr(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){dr(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,n){dr(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){dr(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){dr(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){dr(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){dr(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){dr(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)dr(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputStream(r,e,n)}))}addBoolToInputSidePacket(t,e){dr(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){dr(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){dr(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){dr(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){dr(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){dr(this,e,(e=>{dr(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,n){dr(this,n,(n=>{dr(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){dr(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){dr(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){dr(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){dr(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){dr(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){dr(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)dr(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputSidePacket(n,e)}))}attachBoolListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){gr(this,t,e),dr(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){mr(this,t,e),dr(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,n){gr(this,t,e),dr(this,t,(t=>{this.h._attachProtoListener(t,n||!1)}))}attachProtoVectorListener(t,e,n){mr(this,t,e),dr(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?'),gr(this,t,((t,n)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,n)})),dr(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 br{Y(){this.h._registerModelResourcesGraphService()}});var br;async function yr(t,e){const n=await(async(t,e,n)=>{var r=Qr;if(t&&await fr(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await fr(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.K(e),n}async function vr(t,e){return yr(t,e)}function wr(t){try{const e=t.H.length;if(1===e)throw Error(t.H[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.H.map((t=>t.message)).join(", "))}finally{t.H=[]}}function Sr(t,e){t.G=Math.max(t.G,e)}var Ar=class{constructor(t){this.i=t,this.H=[],this.G=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.H.push(Error(e))})),this.i.Y(),this.i.setGraph(t,e),wr(this)}finishProcessing(){this.i.finishProcessing(),wr(this)}close(){this.i.closeGraph()}};Ar.prototype.close=Ar.prototype.close;var Tr=class extends Le{constructor(t){super(t)}};function Er(t,e){be(t,1,e)}var Ir=class extends Le{constructor(){super()}},Pr=[0,Rn,Un,En,-1,On];function Or(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 Lr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Ur=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 xr(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))}},Nr=class extends Le{constructor(){super()}};Nr.prototype.i=Gn([0,Fn,2,Ln,Un,Nn]);var kr=class extends Le{constructor(){super()}},jr=class extends Le{constructor(){super()}},Fr=class extends Le{constructor(){super()}},Dr=class extends Le{constructor(){super()}},Vr=[0,Un,-6,1,Un,1,[0,Nn,Rn,-2],[0,Nn,En],Rn,-2,[0,Nn,-1,Rn,En,Cn,On],1,Nn,Un,On,-1,[0,Rn,Un],Nn,-1,Tn,Un],Mr=[0,[4,6],Vr,Un,1,xn,Ln,Dn,jn,[0,Fn,-2],On,[0,[0,Un,-1,Vn,[0,Un,[0,Un,-1],-1,[0,Rn,-1],Nn],Nn,-2,Un,-1],[0,Un,-1,Nn],Vr,Nn,Un],kn,-3,[0,Un,Nn]];Dr.prototype.i=Gn([0,Fn,8,[0,Nn,-6],1,Un,1,Un,[0,Vn,[0,Fn,Pn,-1,Rn],Mr,Un],[0,Un,Nn,-3],1,Rn,1,Mr,1,Un,5,Rn,An,1,Pr]);var Cr=class extends Le{constructor(){super()}},Rr=class extends Le{constructor(){super()}},Gr=[2,4];Rr.prototype.i=Gn([0,Gr,Un,Dn,Un,Mn,[0,1,Fn]]);const zr=function(t){return class e extends t{static async Z(t,n){let r;n||=await e.O();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 r.adapterInfo=n.info,r}static async O(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}V(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}R(){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 Lr(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 c=Math.min(r,u.length-n);if(void 0===(n=Or(u,n,c,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(n,o+s),n=0,s+=c,0==(r-=c))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{P(t,e){dr(this,"lora_model_ref_in",(n=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,n,e)}))}}}(class extends _r{})));class Wr extends zr{}var Hr=class{constructor(t){this.j=t,this.i=$r,$r++}},$r=0;class qr{constructor(){let t,e;this.promise=new Promise(((n,r)=>{t=n,e=r})),this.resolve=t,this.reject=e}}function Kr(t){return 1===t?1:t+t%2}async function Yr(){const t=await Wr.O({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 n=["shader-f16","subgroups"];t.features.has("subgroups-f16")&&n.push("subgroups-f16"),e.requiredFeatures=n}return Wr.Z(e,t)}function Jr(t){const e=function(t){const e=new ir;Pe(e,10,"text_in"),Pe(e,10,"token_cost_in"),Pe(e,10,"lora_model_id_to_apply_in"),Pe(e,10,"lora_model_ref_in"),Pe(e,10,"lora_model_id_to_load_in"),Pe(e,16,"streaming_reader"),Pe(e,15,"text_out"),Pe(e,15,"text_end"),Pe(e,15,"token_cost_out");var n=new Qn;Ee(n,2,"TokenizerInputBuildCalculator"),Pe(n,3,"PROMPT:text_in"),Pe(n,3,"LORA_ID:lora_model_id_to_apply_in"),Pe(n,4,"prompt"),rr(e,n),Ee(n=new Qn,2,"ModelDataCalculator"),Pe(n,6,"MODEL_DATA:__side_packet_1"),Pe(n,6,"MODEL_TYPE:model_type"),Pe(n,5,"READ_DATA_FN:streaming_reader"),Pe(n,3,"LORA_MODEL_SPAN:lora_model_ref_in"),Pe(n,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),Pe(n,4,"LORA_DATA:lora_model_data"),rr(e,n),Ee(n=new Qn,2,"Gpt2UnicodeMappingCalculator"),Pe(n,5,"MODEL_TYPE:model_type"),Pe(n,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),rr(e,n),Ee(n=new Wn,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var r=new Rr,i=Ae(t.j,2);Te(r,1,i),Ee(i=new Cr,2,"spm_vocab_model"),null==i&&(i=void 0);t:{var o=r.m,s=$(o);if(rt(s),null==i){var u=ge(o);if(4!==me(u,o,s))break t;u.set(Gr,0)}else{const t=ge(u=o),e=me(t,u,s);4!==e&&(e&&(s=ce(u,s,e)),t.set(Gr,4))}ce(o,s,4,i)}return Te(r,3,2),zn(n,r.i()),Ee(r=new Qn,2,"TokenizerCalculator"),we(r,8,Wn,n),Pe(r,5,"MODEL_DATA:__side_packet_1"),Pe(r,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),Pe(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Pe(r,6,"PROCESSOR_GETTER:__input_side_1"),Pe(r,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),rr(e,r),Ee(n=new Wn,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),Te(r=new Dr,12,3),Ee(r,1,"llm.tflite"),Te(r,14,0),i=Kr(Ae(t.j,5)),Te(r,22,i),i=_e(t.j,Tr,3),be(r,31,i),pe(i=new kr,1,!0,!1),pe(i,2,!0,!1),pe(i,5,!0,!1),be(r,10,i),i=le(t.j,4,Nt,void 0===it?2:a?4:5),Ie(r,29,i),i=new Fr,Te(o=new jr,1,1),u=Ae(t.j,2),Te(o,2,u),be(i,1,o),be(r,20,i),zn(n,r.i()),Ee(r=new Qn,2,"LlmGpuCalculator"),we(r,8,Wn,n),Pe(r,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),Pe(r,3,"FINISH:finish"),Pe(r,3,"LORA_DATA:lora_model_data"),Pe(r,5,"MODEL_DATA:__side_packet_1"),Pe(r,4,"DECODED_IDS:__stream_3"),Pe(r,4,"OUTPUT_END:__stream_4"),Ee(n=new Xn,1,"FINISH"),pe(n,2,!0,!1),we(r,13,Xn,n),rr(e,r),Ee(n=new Qn,2,"IsPacketPresentCalculator"),Pe(n,3,"__stream_4"),Pe(n,4,"text_end"),rr(e,n),Ee(n=new Wn,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),r=new Nr,t=Kr(Ae(t.j,5)),Te(r,5,t),Pe(r,4,"<eos>"),Pe(r,4,"<|endoftext|>"),zn(n,r.i()),Ee(t=new Qn,2,"DetokenizerCalculator"),we(t,8,Wn,n),Pe(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),Pe(t,5,"PROCESSOR_GETTER:__input_side_1"),Pe(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Pe(t,5,"MODEL_DATA:__side_packet_1"),Pe(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),Pe(t,4,"WORDS:text_out"),rr(e,t),Ee(t=new Qn,2,"TokenCostCalculator"),Pe(t,3,"PROMPT:token_cost_in"),Pe(t,5,"PROCESSOR_GETTER:__input_side_1"),Pe(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Pe(t,4,"NUM_TOKENS:token_cost_out"),rr(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.D.length),e.forEach(((e,n)=>{n<Ae(t.j,5)&&t.D[n].push(e)})),t.A&&0===t.B.length&&(t.F?(e.length>Ae(t.j,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),Sr(t,n)})),t.i.attachEmptyPacketListener("text_out",(e=>{Sr(t,e)})),t.i.attachBoolListener("text_end",((e,n)=>{if(t.l=!1,Sr(t,n),Xr(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0),t.A)if(t.F){for(e=[],n=0;n<Ae(t.j,5);n++)e.push("");t.A(e,!0)}else t.A("",!0);t.F=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.F=void 0,Sr(t,e),Xr(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,n)=>{t.M=e,Sr(t,n)})),t.J&&t.i.addStreamingReaderToInputSidePacket(t.J,"streaming_reader");const n=e.i();return t.v?.removeEventListener("uncapturederror",t.I),t.i.R().then((()=>{t.v?.addEventListener("uncapturederror",t.I),t.B.length=0,t.setGraph(new Uint8Array(n),!0),t.finishProcessing()}))}function Xr(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 Zr(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.D.length=0,r=0;r<Ae(t.j,5);r++)t.D[r]=[];if(r=t.G+1,t.i.addStringToStream(e,"text_in",r),n instanceof Hr){if(n.j!==t)throw t.l=!1,t.F=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 qr,t.o.promise}var Qr=class extends Ar{constructor(t,e){super(new Wr(t,e)),this.D=[],this.l=!1,this.B=[],this.I=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 Ir,Er(this.j,new or),this.u=new Tr,be(this.j,3,this.u),ue(this.j,2,kt(512)),pe(this.u,1,2,0),Te(this.u,2,40),pe(this.u,3,Pt(1),0),ue(this.u,5,Bt(0)),pe(this.u,4,Pt(.8),0),ue(this.j,5,kt(1))}K(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.I),this.v=t.baseOptions.gpuOptions.device,this.i.V(this.v),this.v.addEventListener("uncapturederror",this.I)),"maxTokens"in t&&ue(this.j,2,kt(t.maxTokens??512)),"topK"in t&&Te(this.u,2,t.topK??40),"temperature"in t&&pe(this.u,4,Pt(t.temperature??.8),0),"randomSeed"in t&&ue(this.u,5,Bt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){Ie(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.");ue(this.j,5,kt(e));var n=_e(this.j,Tr,3);e>1&&n&&(Se(Nt(oe(n,2)))<=1||Se(function(t){t=t.m;let e=$(t);const n=ae(t,e,4),r=Ot(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.J=function(t,e){const n=fetch(t.toString()).then((t=>t?.body?.getReader()));return new Ur([],(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.J=function(t,e){return new Ur([new Lr(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,r),n=!0):t.baseOptions.modelAssetBuffer?(this.J=function(t,e){return new Ur([],(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=Jr(this).then((()=>{})),Promise.all([e,t]).then((()=>{this.l=!1,Xr(this)}))}get baseOptions(){return _e(this.j,or,1)}set baseOptions(t){Er(this.j,t)}T(t,e,n){return Ae(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.F=!1,Zr(this,t,e,n).then((t=>t[0]))}U(t,e,n){return this.F=!0,Zr(this,t,e,n)}aa(t){if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.M=void 0,this.i.addStringToStream(t,"token_cost_in",this.G+1),this.finishProcessing(),this.l=!1,this.M}async X(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 xr(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 Hr(this),this.i.P(t,this.G+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.G+1),this.finishProcessing(),xr(t),this.l=!1,e}close(){this.v?.removeEventListener("uncapturederror",this.I),super.close()}};Qr.prototype.loadLoraModel=Qr.prototype.X,Qr.prototype.sizeInTokens=Qr.prototype.aa,Qr.prototype.generateResponses=Qr.prototype.U,Qr.prototype.generateResponse=Qr.prototype.T,Qr.prototype.setOptions=Qr.prototype.K,Qr.createWebGpuDevice=Yr,Qr.createFromModelPath=async function(t,e){return vr(t,e={baseOptions:{gpuOptions:{device:await Yr()},modelAssetPath:e}})},Qr.createFromModelBuffer=async function(t,e){return vr(t,e={baseOptions:{gpuOptions:{device:await Yr()},modelAssetBuffer:e}})},Qr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Yr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return vr(t,e)},exports.FilesetResolver=lr,exports.LlmInference=Qr,exports.TaskRunner=Ar;
2
2
  //# sourceMappingURL=genai_bundle_cjs.js.map