@mediapipe/tasks-genai 0.10.22 → 0.10.23

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/genai_bundle.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var t="undefined"!=typeof self?self:{};let e;const n="undefined"!=typeof TextEncoder;function r(t){if(n)t=(e||=new TextEncoder).encode(t);else{let e=0;const n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var r=t.charCodeAt(i);if(r<128)n[e++]=r;else{if(r<2048)n[e++]=r>>6|192;else{if(r>=55296&&r<=57343){if(r<=56319&&i<t.length){const o=t.charCodeAt(++i);if(o>=56320&&o<=57343){r=1024*(r-55296)+o-56320+65536,n[e++]=r>>18|240,n[e++]=r>>12&63|128,n[e++]=r>>6&63|128,n[e++]=63&r|128;continue}i--}r=65533}n[e++]=r>>12|224,n[e++]=r>>6&63|128}n[e++]=63&r|128}}t=e===n.length?n:n.subarray(0,e)}return t}var i,o;t:{for(var s=["CLOSURE_FLAGS"],a=t,c=0;c<s.length;c++)if(null==(a=a[s[c]])){o=null;break t}o=a}var u,l=o&&o[610401301];function h(){var e=t.navigator;return e&&(e=e.userAgent)?e:""}i=null!=l&&l;const f=t.navigator;u=f&&f.userAgentData||null;var d={},p=null;function g(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=p[e];if(null!=n)return n;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}m();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 m(){if(!p){p={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let n=0;n<5;n++){const r=t.concat(e[n].split(""));d[n]=r;for(let t=0;t<r.length;t++){const e=r[t];void 0===p[e]&&(p[e]=t)}}}}var _="undefined"!=typeof Uint8Array,y=!(!(i&&u&&u.brands.length>0)&&(-1!=h().indexOf("Trident")||-1!=h().indexOf("MSIE")))&&"function"==typeof btoa;const b=/[-_.]/g,v={"-":"+",_:"/",".":"="};function w(t){return v[t]||""}function S(t){if(!y)return g(t);b.test(t)&&(t=t.replace(b,w)),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 A(t){return _&&null!=t&&t instanceof Uint8Array}var E={};function T(){return P||=new I(null,E)}var I=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")}};let P,L;function O(t){if(t!==E)throw Error("illegal external caller")}function U(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function B(t){return U(t=Error(t),"warning"),t}var k="function"==typeof Symbol&&"symbol"==typeof Symbol();function x(t,e,n=!1){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?n&&Symbol.for&&t?Symbol.for(t):null!=t?Symbol(t):Symbol():e}var N=x("jas",void 0,!0),j=x(void 0,"1oa"),F=x(void 0,"0actk");const D=k?N:"ca",R={ca:{value:0,configurable:!0,writable:!0,enumerable:!1}},V=Object.defineProperties;function M(t,e){k||D in t||V(t,R),t[D]|=e}function C(t,e){k||D in t||V(t,R),t[D]=e}var G,z={};function W(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}const $=[];function H(t){if(2&t)throw Error()}C($,55),G=Object.freeze($);var q=Object.freeze({});function K(){return"function"==typeof BigInt}function Y(t){return t.ja=!0,t}var J=Y((t=>"number"==typeof t)),X=Y((t=>"string"==typeof t)),Z=Y((t=>"boolean"==typeof t)),Q="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),tt=Y((t=>Q?t>=nt&&t<=it:"-"===t[0]?ot(t,et):ot(t,rt)));const et=Number.MIN_SAFE_INTEGER.toString(),nt=Q?BigInt(Number.MIN_SAFE_INTEGER):void 0,rt=Number.MAX_SAFE_INTEGER.toString(),it=Q?BigInt(Number.MAX_SAFE_INTEGER):void 0;function ot(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 st,at=0,ct=0;function ut(t){const e=t>>>0;at=e,ct=(t-e)/4294967296>>>0}function lt(t){if(t<0){ut(-t);const[e,n]=gt(at,ct);at=e>>>0,ct=n>>>0}else ut(t)}function ht(t,e){const n=4294967296*e+(t>>>0);return Number.isSafeInteger(n)?n:ft(t,e)}function ft(t,e){if(t>>>=0,(e>>>=0)<=2097151)var n=""+(4294967296*e+t);else K()?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+dt(n)+dt(t));return n}function dt(t){return t=String(t),"0000000".slice(t.length)+t}function pt(t){if(t.length<16)lt(Number(t));else if(K())t=BigInt(t),at=Number(t&BigInt(4294967295))>>>0,ct=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);ct=at=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));ct*=1e6,at=1e6*at+e,at>=4294967296&&(ct+=Math.trunc(at/4294967296),ct>>>=0,at>>>=0)}if(e){const[t,e]=gt(at,ct);at=t,ct=e}}}function gt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function mt(t){return Array.prototype.slice.call(t)}const _t="function"==typeof BigInt?BigInt.asIntN:void 0,yt="function"==typeof BigInt?BigInt.asUintN:void 0,bt=Number.isSafeInteger,vt=Number.isFinite,wt=Math.trunc;function St(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}function At(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}const Et=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Tt(t){switch(typeof t){case"bigint":return!0;case"number":return vt(t);case"string":return Et.test(t);default:return!1}}function It(t){if("number"!=typeof t)throw B("int32");if(!vt(t))throw B("int32");return 0|t}function Pt(t){return null==t?t:It(t)}function Lt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?0|t:void 0}function Ot(t){if(null!=t){if("number"!=typeof t)throw B("uint32");if(!vt(t))throw B("uint32");t>>>=0}return t}function Ut(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?t>>>0:void 0}function Bt(t){if("-"===t[0])return!1;const e=t.length;return e<20||20===e&&Number(t.substring(0,6))<184467}function kt(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(yt(64,t));if(Tt(t)){if("string"===e)return e=wt(Number(t)),bt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),Bt(t)||(pt(t),t=ft(at,ct))),t;if("number"===e)return(t=wt(t))>=0&&bt(t)?t:function(t){if(t<0){lt(t);var e=ft(at,ct);return t=Number(e),bt(t)?t:e}return Bt(e=String(t))?e:(lt(t),ht(at,ct))}(t)}}function xt(t){return null==t||"string"==typeof t?t:void 0}function Nt(t,e,n){if(null!=t&&"object"==typeof t&&t.P===z)return t;if(Array.isArray(t)){var r=0|t[D],i=r;return 0===i&&(i|=32&n),(i|=2&n)!==r&&C(t,i),new e(t)}}function jt(t,e,n,r,i){r=r?!!(32&e):void 0;const o=[];var s=t.length;let a,c,u,l,h=!1;64&e?(256&e?(a=t[--s],c=s):(c=4294967295,a=void 0),i||512&e||(h=!0,u=a?c- -1:e>>15&1023||536870912,c=u+-1)):(c=4294967295,1&e||(a=s&&t[s-1],W(a)?(c=--s,u=0):a=void 0));for(let e=0;e<s;e++){let i=t[e];null!=i&&null!=(i=n(i,r))&&(e>=c?(l??={})[e- -1]=i:o[e]=i)}if(a)for(let e in a)null!=(t=a[e])&&null!=(t=n(t,r))&&((s=+e)<u?o[s+-1]=t:(l??={})[e]=t);return l&&(h?o.push(l):o[c]=l),i&&C(o,33522241&e|(null!=l?290:34)),o}function Ft(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return tt(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[D];return 0===t.length&&1&e?void 0:jt(t,e,Ft,!1,!1)}if(t.P===z)return Dt(t);if(t instanceof I){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(y){for(var n="",r=0,i=e.length-10240;r<i;)n+=String.fromCharCode.apply(null,e.subarray(r,r+=10240));n+=String.fromCharCode.apply(null,r?e.subarray(r):e),e=btoa(n)}else{void 0===n&&(n=0),m(),n=d[n],r=Array(Math.floor(e.length/3)),i=n[64]||"";let t=0,u=0;for(;t<e.length-2;t+=3){var o=e[t],s=e[t+1],a=e[t+2],c=n[o>>2];o=n[(3&o)<<4|s>>4],s=n[(15&s)<<2|a>>6],a=n[63&a],r[u++]=c+o+s+a}switch(c=0,a=i,e.length-t){case 2:a=n[(15&(c=e[t+1]))<<2]||i;case 1:e=e[t],r[u]=n[e>>2]+n[(3&e)<<4|c>>4]+a+i}e=r.join("")}t=t.i=e}return t}return}return t}function Dt(t){return jt(t=t.m,0|t[D],Ft,void 0,!1)}let Rt,Vt;function Mt(t,e,n){return t=Ct(t,e[0],e[1],n?1:2),e!==Rt&&n&&M(t,8192),t}function Ct(e,n,r,i){if(null==e){var o=96;r?(e=[r],o|=512):e=[],n&&(o=-33521665&o|(1023&n)<<15)}else{if(!Array.isArray(e))throw Error("narr");if(8192&(o=0|e[D])||!(64&o)||2&o||function(){if(null!=F){var e=L??={},n=e[F]||0;n>=5||(e[F]=n+1,U(e=Error(),"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e))}}(),1024&o)throw Error("farr");if(64&o)return 3!==i||16384&o||C(e,16384|o),e;if(1===i||2===i||(o|=64),r&&(o|=512,r!==e[0]))throw Error("mid");t:{var s=(r=e).length;if(s){var a=s-1;const t=r[a];if(W(t)){if((a-=n=512&(o|=256)?0:-1)>=1024)throw Error("pvtlmt");for(var c in t)(s=+c)<a&&(r[s+n]=t[c],delete t[c]);o=-33521665&o|(1023&a)<<15;break t}}if(n){if((c=Math.max(n,s-(512&o?0:-1)))>1024)throw Error("spvt");o=-33521665&o|(1023&c)<<15}}}return 3===i&&(o|=16384),C(e,o),e}function Gt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){const r=0|t[D];if(0===t.length&&1&r)return;return 2&r?t:((n=e)&&(n=0===r||!!(32&r)&&!(64&r||!(16&r))),n?(M(t,34),4&r&&Object.freeze(t),t):jt(t,r,Gt,void 0!==e,!0));var n}return t.P===z?2&(n=0|(e=t.m)[D])?t:jt(e,n,Gt,!0,!0):t instanceof I?t:void 0}function zt(t){var e=t.m;return 2&(0|e[D])?((e=(t=new t.constructor(jt(e,0|e[D],Gt,!0,!0))).m)[D]&=-3,t):t}function Wt(t,e){return $t(t=t.m,0|t[D],e)}function $t(t,e,n){if(-1===n)return null;const r=n+(512&e?0:-1),i=t.length-1;return r>=i&&256&e?t[i][n]:r<=i?t[r]:void 0}function Ht(t,e,n){const r=t.m;let i=0|r[D];return H(i),qt(r,i,e,n),t}function qt(t,e,n,r){const i=512&e?0:-1,o=n+i;var s=t.length-1;return o>=s&&256&e?(t[s][n]=r,e):o<=s?(t[o]=r,e):(void 0!==r&&(n>=(s=e>>15&1023||536870912)?null!=r&&(t[s+i]={[n]:r},C(t,e|=256)):t[o]=r),e)}function Kt(t,e,n,r,i){const o=t.m,s=2&(t=0|o[D])?1:r;i=!!i;let a=0|(r=Yt(o,t,e))[D];if(!(4&a)){4&a&&(r=mt(r),a=ie(a,t),t=qt(o,t,e,r));let i=0,s=0;for(;i<r.length;i++){const t=n(r[i]);null!=t&&(r[s++]=t)}s<i&&(r.length=s),a=Jt(a,t),n=-2049&(20|a),a=n&=-4097,C(r,a),2&a&&Object.freeze(r)}return 1===s||4===s&&32&a?Xt(a)||(i=a,a|=2,a!==i&&C(r,a),Object.freeze(r)):(2===s&&Xt(a)&&(r=mt(r),a=ie(a,t),a=oe(a,t,i),C(r,a),t=qt(o,t,e,r)),Xt(a)||(e=a,a=oe(a,t,i),a!==e&&C(r,a))),r}function Yt(t,e,n){return t=$t(t,e,n),Array.isArray(t)?t:G}function Jt(t,e){return 0===t&&(t=ie(t,e)),1|t}function Xt(t){return!!(2&t)&&!!(4&t)||!!(1024&t)}function Zt(t,e,n){let r=0|(t=t.m)[D];if(H(r),null==n)qt(t,r,e);else{var i=0|n[D],o=i,s=Xt(i),a=s||Object.isFrozen(n);for(s||(i=0),a||(n=mt(n),o=0,i=oe(i=ie(i,r),r,!0),a=!1),i|=21,s=0;s<n.length;s++){const t=n[s],e=It(t);Object.is(t,e)||(a&&(n=mt(n),o=0,i=oe(i=ie(i,r),r,!0),a=!1),n[s]=e)}i!==o&&(a&&(n=mt(n),i=oe(i=ie(i,r),r,!0)),C(n,i)),qt(t,r,e,n)}}function Qt(t,e,n,r){let i=0|(t=t.m)[D];H(i),qt(t,i,e,("0"===r?0===Number(n):n===r)?void 0:n)}function te(t){if(k)return t[j]??(t[j]=new Map);if(j in t)return t[j];const e=new Map;return Object.defineProperty(t,j,{value:e}),e}function ee(t,e,n){var r=Ur;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!=$t(e,n,o)&&(0!==i&&(n=qt(e,n,i)),i=o)}return t.set(r,i),i}function ne(t,e,n){var r=t.m,i=0|r[D],o=$t(r,i,n);return(e=Nt(o,e,i))!==o&&null!=e&&qt(r,i,n,e),null==(r=e)||2&(i=0|(t=t.m)[D])||(o=zt(r))!==r&&qt(t,i,n,r=o),r}function re(t,e,n){return null==n&&(n=void 0),Ht(t,e,n)}function ie(t,e){return-1025&(t=32|(2&e?2|t:-3&t))}function oe(t,e,n){return 32&e&&n||(t&=-33),t}function se(t,e,n){if(H(0|t.m[D]),e=(t=Kt(t,e,xt,2,!0)).push,"string"!=typeof n)throw Error();e.call(t,n)}function ae(t,e,n,r){var i=0|t.m[D];H(i);const o=t.m,s=(t=!!(2&i))?1:2;f&&=!t;var a=0|(t=Yt(o,i,e))[D];const c=!!(4&a);if(!c){var u=t,l=i,h=!!(2&(a=Jt(a,i)));h&&(l|=2);let e=!h,r=!0,o=0,s=0;for(;o<u.length;o++){const t=Nt(u[o],n,l);if(t instanceof n){if(!h){const n=!!(2&(0|t.m[D]));e&&=!n,r&&=n}u[s++]=t}}s<o&&(u.length=s),a|=4,a=r?16|a:-17&a,C(u,a=e?8|a:-9&a),h&&Object.freeze(u)}if(f&&!(8&a||!t.length&&(1===s||4===s&&32&a))){Xt(a)&&(t=mt(t),a=ie(a,i),i=qt(o,i,e,t));var f=t;for(u=a,a=0;a<f.length;a++)(l=f[a])!==(h=zt(l))&&(f[a]=h);u|=8,C(f,u=f.length?-17&u:16|u),a=u}1===s||4===s&&32&a?Xt(a)||(e=a,(a|=!t.length||16&a&&(!c||32&a)?2:1024)!==e&&C(t,a),Object.freeze(t)):(2===s&&Xt(a)&&(C(t=mt(t),a=oe(a=ie(a,i),i,!0)),i=qt(o,i,e,t)),Xt(a)||(e=a,(a=oe(a,i,!0))!==e&&C(t,a))),e=t,r=null!=r?r:new n,e.push(r),e[D]=2&(0|r.m[D])?-9&e[D]:-17&e[D]}function ce(t,e){return Ut(Wt(t,e))??0}function ue(t,e,n){Qt(t,e,Pt(n),0)}function le(t,e,n){if(null!=n&&"string"!=typeof n)throw Error();Qt(t,e,n,"")}function he(t){if("string"==typeof t)return{buffer:S(t),F:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),F:!1};if(t.constructor===Uint8Array)return{buffer:t,F:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),F:!1};if(t.constructor===I){O(E);var e=t.i;return{buffer:(null==(e=null==e||A(e)?e:"string"==typeof e?S(e):null)?e:t.i=e)||new Uint8Array(0),F:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),F:!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=Ct(t,e,void 0,3)}toJSON(){return Dt(this)}F(){return!!(2&(0|this.m[D]))}};function de(t){return t?/^\d+$/.test(t)?(pt(t),new pe(at,ct)):null:ge||=new pe(0,0)}fe.prototype.P=z,fe.prototype.toString=function(){return this.m.toString()};var pe=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ge;function me(t){return t?/^-?\d+$/.test(t)?(pt(t),new _e(at,ct)):null:ye||=new _e(0,0)}var _e=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ye;function be(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 we(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 Se(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Ae(t,e,n){ve(t.i,8*e+n)}function Ee(t,e){return Ae(t,e,2),e=t.i.end(),Se(t,e),e.push(t.j),e}function Te(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 Ie(t,e,n){Ae(t,e,2),ve(t.i,n.length),Se(t,t.i.end()),Se(t,n)}function Pe(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Le=Pe(),Oe=Pe(),Ue=Pe(),Be=Pe(),ke=Pe(),xe=Pe(),Ne=class{constructor(t,e){this.i=t,t=Le,this.j=!!t&&e===t||!1}};function je(t,e,n,r,i){null!=(e=Ge(e,r))&&(n=Ee(t,n),i(e,t),Te(t,n))}const Fe=new Ne(je,Le),De=new Ne(je,Le);var Re=Symbol(),Ve=Symbol();let Me;function Ce(t){var e=ze,n=We,r=t[Re];if(r)return r;(r={}).ia=t,r.O=function(t){switch(typeof t){case"boolean":return Rt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Vt||=[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.Z=i,"function"==typeof(i=t[++o])&&(r.da=!0,Me??=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 c=void 0;if(i instanceof Ne?s=i:(s=Fe,o--),s?.j){i=t[++o],c=t;var u=o;"function"==typeof i&&(i=i(),c[u]=i),c=i}for(u=a+1,"number"==typeof(i=t[++o])&&i<0&&(u-=i,i=t[++o]);a<u;a++)c?n(r,a,s,c):e(r,a,s)}return t[Re]=r}function Ge(t,e){return t instanceof fe?t.m:Array.isArray(t)?Mt(t,e,!1):void 0}function ze(t,e,n){t[e]=n.i}function We(t,e,n,r){let i,o;const s=n.i;t[e]=(t,e,n)=>s(t,e,n,o||=Ce(r).O,i||=$e(r))}function $e(t){let e=t[Ve];if(!e){const n=Ce(t);e=(t,e)=>He(t,e,n),t[Ve]=e}return e}function He(t,e,n){!function(t,e,n){const r=512&e?0:-1,i=t.length,o=i+((e=64&e?256&e:!!i&&W(t[i-1]))?-1:0);for(let e=0;e<o;e++)n(e-r,t[e]);if(e){t=t[i-1];for(const e in t)!isNaN(e)&&n(+e,t[e])}}(t,0|t[D]|(n.O[1]?512:0),((t,r)=>{if(null!=r){var i=function(t,e){var n=t[e];if(n)return n;if((n=t.Z)&&(n=n[e])){var r=(n=Array.isArray(n)?n[0]instanceof Ne?n:[De,n]:[n,void 0])[0].i;if(n=n[1]){const e=$e(n),i=Ce(n).O;n=t.da?Me(i,e):(t,n,o)=>r(t,n,o,i,e)}else n=r;return t[e]=n}}(n,t);i&&i(e,r,t)}}))}var qe,Ke=0,Ye=Ke;if(X(Ye)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(Ye))throw Error(String(Ye))}else if((qe=J(Ye))&&(qe=!Number.isSafeInteger(Ye)),qe)throw Error(String(Ye));function Je(t,e){if(Array.isArray(e)){var n=0|e[D];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),C(e,-6145&(5|n)),2&n&&Object.freeze(e),e}}function Xe(t,e){return new Ne(t,e)}function Ze(t,e,n){null!=(e=At(e))&&(Ae(t,n,5),t=t.i,(n=st||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ct=0,e=at=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 Qe(t,e,n){null!=(e=Lt(e))&&null!=e&&(Ae(t,n,0),we(t.i,e))}function tn(t,e,n){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(Ae(t,n,0),t.i.i.push(e?1:0))}function en(t,e,n){null!=(e=xt(e))&&Ie(t,n,r(e))}function nn(t,e,n,r,i){null!=(e=Ge(e,r))&&(n=Ee(t,n),i(e,t),Te(t,n))}function rn(t,e,n){null!=(e=Lt(e))&&(e=parseInt(e,10),Ae(t,n,0),we(t.i,e))}Q||(Ke=Z(Ke)?Ke?"1":"0":X(Ke)?Ke.trim()||"0":String(Ke));var on,sn=Xe(Ze,ke),an=Xe(Ze,ke),cn=Xe((function(t,e,n){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(_t(64,t));if(Tt(t)){if("string"===e){if(e=wt(Number(t)),bt(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),e=t.length,!("-"===t[0]?e<20||20===e&&Number(t.substring(0,7))>-922337:e<19||19===e&&Number(t.substring(0,6))<922337))if(pt(t),t=at,2147483648&(e=ct))if(K())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[n,r]=gt(t,e);t="-"+ft(n,r)}else t=ft(t,e);return t}if("number"===e){if(t=wt(t),!bt(t)){lt(t),e=at;var n=ct;(t=2147483648&n)&&(n=~n>>>0,0==(e=1+~e>>>0)&&(n=n+1>>>0)),t="number"==typeof(e=ht(e,n))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)me(e);if(null!=e)switch(Ae(t,n,0),typeof e){case"number":t=t.i,lt(e),be(t,at,ct);break;case"bigint":n=BigInt.asUintN(64,e),n=new _e(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),be(t.i,n.j,n.i);break;default:n=me(e),be(t.i,n.j,n.i)}}}),Pe()),un=Xe((function(t,e,n){if(null!=(e=kt(e))){if("string"==typeof e)de(e);if(null!=e)switch(Ae(t,n,0),typeof e){case"number":t=t.i,lt(e),be(t,at,ct);break;case"bigint":n=BigInt.asUintN(64,e),n=new pe(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),be(t.i,n.j,n.i);break;default:n=de(e),be(t.i,n.j,n.i)}}}),Pe()),ln=Xe(Qe,Be);on=new Ne((function(t,e,n){if(null!=(e=Je(Lt,e))&&e.length){n=Ee(t,n);for(let n=0;n<e.length;n++)we(t.i,e[n]);Te(t,n)}}),Be);var hn,fn=Xe(Qe,Be),dn=Xe(Qe,Be),pn=Xe(tn,Oe),gn=Xe(tn,Oe),mn=Xe(en,Ue);hn=new Ne((function(t,e,n){if(null!=(e=Je(xt,e)))for(let a=0;a<e.length;a++){var i=t,o=n,s=e[a];null!=s&&Ie(i,o,r(s))}}),Ue);var _n,yn=Xe(en,Ue),bn=Xe(en,Ue),vn=function(t,e,n=Le){return new Ne(e,n)}(0,(function(t,e,n,r,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)nn(t,e[o],n,r,i)})),wn=new Ne(nn,Le),Sn=Xe((function(t,e,n){null!=(e=Ut(e))&&null!=e&&(Ae(t,n,0),ve(t.i,e))}),Pe()),An=Xe(rn,xe);_n=new Ne((function(t,e,n){if(null!=(e=Je(Lt,e))&&e.length){n=Ee(t,n);for(let n=0;n<e.length;n++)we(t.i,e[n]);Te(t,n)}}),xe);var En=Xe(rn,xe);function Tn(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}}}};He(this.m,e,Ce(t)),Se(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 In(t,e){if(null!=e)if(Array.isArray(e))Ht(t,2,jt(e,0,Ft,void 0,!1));else{if(!("string"==typeof e||e instanceof I||A(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 I(e,E):T();else if(e.constructor!==I){if(!A(e))throw Error();e=e.length?new I(new Uint8Array(e),E):T()}Qt(t,2,e,T())}}var Pn=class extends fe{constructor(t){super(t)}},Ln=[0,yn,Xe((function(t,e,n){if(null!=e){if(e instanceof fe){const r=e.ka;return void(r&&(e=r(e),null!=e&&Ie(t,n,he(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||e instanceof I?e:void 0)&&Ie(t,n,he(e).buffer)}),Pe())];let On,Un=globalThis.trustedTypes;function Bn(t){void 0===On&&(On=function(){let t=null;if(!Un)return t;try{const e=t=>t;t=Un.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}());var e=On;return new class{constructor(t){this.i=t}toString(){return this.i+""}}(e?e.createScriptURL(t):t)}function kn(t,...e){if(0===e.length)return Bn(t[0]);let n=t[0];for(let r=0;r<e.length;r++)n+=encodeURIComponent(e[r])+t[r+1];return Bn(n)}var xn={};xn[336783863]=[0,mn,pn,-1,ln,[0,[1,2,3,4,5,6,7,8,9],wn,[0],wn,[0,pn,mn,pn,An,-1,_n,mn,-1,[0,pn,-1],An,pn,-1],wn,[0,mn,-2],wn,[0,ln,pn,1,pn,-3],wn,[0,ln,An,pn,-1,on,An,-1],wn,[0,mn,-2],wn,[0,mn,An],wn,[0,An,mn,-1],wn,[0,An,-1]],[0,mn],pn,[0,[1,3],[2,4],wn,[0,on],-1,wn,[0,hn],-1,vn,[0,mn,-1]],mn];var Nn=class extends fe{constructor(t){super(t)}},jn=[0,cn,-1,gn,-3,cn,on,yn,fn,cn,-1,gn,fn,gn,-2,yn],Fn=class extends fe{constructor(t){super(t,500)}L(t){return re(this,7,t)}},Dn=[-1,{}],Rn=[0,mn,1,Dn],Vn=[0,mn,hn,Dn];function Mn(t,e){ae(t,1,Fn,e)}var Cn=class extends fe{constructor(t){super(t,500)}L(t){return re(this,1001,t)}};Cn.prototype.i=Tn([-500,vn,[-500,yn,-1,hn,-3,[-2,xn,pn],vn,Ln,fn,-1,Rn,Vn,vn,[0,yn,gn],yn,jn,fn,hn,987,hn],4,vn,[-500,mn,-1,[-1,{}],998,mn],vn,[-500,mn,hn,-1,[-2,{},pn],997,hn,-1],fn,vn,[-500,mn,hn,Dn,998,hn],hn,fn,Rn,Vn,vn,[0,yn,-1,Dn],hn,-2,jn,yn,-1,gn,[0,gn,Sn],978,Dn,vn,Ln]);var Gn=class extends fe{constructor(t){super(t)}};let zn;const Wn=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 $n(){if(void 0===zn)try{await WebAssembly.instantiate(Wn),zn=!0}catch{zn=!1}return zn}async function Hn(t,e=kn``){const n=await $n()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${n}.js`,wasmBinaryPath:`${e}/${t}_${n}.wasm`}}var qn=class{};function Kn(t){function e(e,n){return new ReadableStream({start(){},async pull(r){i=i.then((async()=>{if(e.cache.length>0)r.enqueue(e.cache.shift());else{var{value:i,done:o}=await t.read();i&&(n.active&&n.cache.push(i),e.active&&r.enqueue(i)),o&&r.close()}})),await i},cancel(){e.active=!1,e.cache.length=0,n.active||t.cancel()}})}var n={cache:[],active:!0};const r={cache:[],active:!0};let i=Promise.resolve();const o=e(n,r);return n=e(r,n),[o.getReader(),n.getReader()]}async function Yn(t,e){const n=new Uint8Array(e);let r=0;for(;r<e;){const{value:i,done:o}=await t.read();if(i){const t=i.subarray(0,e-r);n.set(t,r),r+=t.length}if(o)throw Error(`Expected ${e} bytes, but stream ended after reading ${r} bytes.`)}return await t.cancel(),n}qn.forVisionTasks=function(t){return Hn("vision",t)},qn.forTextTasks=function(t){return Hn("text",t)},qn.forGenAiExperimentalTasks=function(t){return Hn("genai_experimental",t)},qn.forGenAiTasks=function(t){return Hn("genai",t)},qn.forAudioTasks=function(t){return Hn("audio",t)},qn.isSimdSupported=function(){return $n()};const Jn=[[0,async t=>{const e=(new TextEncoder).encode("TFL3").length;return t=await Yn(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await Yn(t,6))[4]&&75===t[5]]];function Xn(){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 Zn(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())}function Qn(t,e,n){t.j||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 tr(t,e,n){t.j||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 er(t,e,n){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=n}function nr(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 rr=(ir=class{constructor(t,e){this.o=!0,this.h=t,this.i=null,this.l=0,this.j="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:Xn()?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?'),Qn(this,r||"input_audio",(r=>{Qn(this,i=i||"audio_header",(i=>{this.h._configureAudio(r,i,t,e??0,n)}))}))}setAutoResizeCanvas(t){this.o=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.l!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.l=o),this.h.HEAPF32.set(t,this.i/4),Qn(this,r,(t=>{this.h._addAudioToInputStream(this.i,e,n,t,i)}))}addGpuBufferToStream(t,e,n){Qn(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.o||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){Qn(this,e,(e=>{this.h._addBoolToInputStream(t,e,n)}))}addDoubleToStream(t,e,n){Qn(this,e,(e=>{this.h._addDoubleToInputStream(t,e,n)}))}addFloatToStream(t,e,n){Qn(this,e,(e=>{this.h._addFloatToInputStream(t,e,n)}))}addIntToStream(t,e,n){Qn(this,e,(e=>{this.h._addIntToInputStream(t,e,n)}))}addUintToStream(t,e,n){Qn(this,e,(e=>{this.h._addUintToInputStream(t,e,n)}))}addStringToStream(t,e,n){Qn(this,e,(e=>{Qn(this,t,(t=>{this.h._addStringToInputStream(t,e,n)}))}))}addStringRecordToStream(t,e,n){Qn(this,e,(e=>{tr(this,Object.keys(t),(r=>{tr(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(r,i,Object.keys(t).length,e,n)}))}))}))}addProtoToStream(t,e,n,r){Qn(this,n,(n=>{Qn(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){Qn(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,n){Qn(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){Qn(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){Qn(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){Qn(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){Qn(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){Qn(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)Qn(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputStream(r,e,n)}))}addBoolToInputSidePacket(t,e){Qn(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){Qn(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){Qn(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){Qn(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){Qn(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){Qn(this,e,(e=>{Qn(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,n){Qn(this,n,(n=>{Qn(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){Qn(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){Qn(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){Qn(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){Qn(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){Qn(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){Qn(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)Qn(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputSidePacket(n,e)}))}attachBoolListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){er(this,t,e),Qn(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){nr(this,t,e),Qn(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,n){er(this,t,e),Qn(this,t,(t=>{this.h._attachProtoListener(t,n||!1)}))}attachProtoVectorListener(t,e,n){nr(this,t,e),Qn(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?'),er(this,t,((t,n)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,n)})),Qn(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 ir{fa(){this.h._registerModelResourcesGraphService()}});var ir;async function or(t,e){const n=await(async(t,e,n)=>{var r=Cr;if(t&&await Zn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await Zn(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&n&&((t=self.Module).locateFile=n.locateFile,n.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=n.mainScriptUrlOrBlob)),n=await self.ModuleFactory(self.Module||n),self.ModuleFactory=self.Module=void 0,new r(n,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return await n.L(e),n}async function sr(t,e){return or(t,e)}function ar(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 cr(t,e){t.G=Math.max(t.G,e)}var ur=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.fa(),this.i.setGraph(t,e),ar(this)}finishProcessing(){this.i.finishProcessing(),ar(this)}close(){this.i.closeGraph()}};ur.prototype.close=ur.prototype.close;var lr=class extends fe{constructor(t){super(t)}i(){return Lt(Wt(this,2))??0}};function hr(t,e){re(t,1,e)}var fr=class extends fe{constructor(t){super(t)}},dr=[0,En,fn,an,-1,ln];function pr(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}}lr.prototype.j=Tn(dr);class gr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var mr=class{constructor(t,e){this.i=[],this.j=t,this.l=e}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};async function _r(t,e,n){t=new br(t,n);let r=0;for(e=e.getReader();;){const{value:n,done:i}=await e.read();if(i)break;t.set(n,r),r+=n.byteLength}if(n!==r)throw yr(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${r}/${n} bytes before failure`);return t}function yr(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))}},vr=class extends fe{constructor(t){super(t)}};vr.prototype.i=Tn([0,yn,2,hn,fn,gn]);var wr=class extends fe{constructor(t){super(t)}},Sr=class extends fe{constructor(t){super(t)}},Ar=class extends fe{constructor(t){super(t)}},Er=class extends fe{constructor(t){super(t)}},Tr=[0,fn,-6,1,fn,1,[0,gn,En,-2],[0,gn,an],En,-2,[0,gn,-1,En,an,An,ln],1,gn,fn,ln,-1,[0,En,fn],gn,-1,sn,fn,-5],Ir=[0,yn,-2],Pr=[0,[4,6],Tr,fn,1,dn,hn,bn,_n,Ir,ln,[0,[0,fn,-1,vn,[0,fn,[0,fn,-1],-1,[0,En,-1],gn],gn,-2,fn,-1],[0,fn,-1,gn],Tr,gn,fn],mn,-3,[0,fn,gn],Tr,[0,Ir,-2]];Er.prototype.i=Tn([0,yn,8,[0,gn,-6],1,fn,1,fn,[0,vn,[0,yn,un,-1,En],Pr,fn],[0,fn,gn,-3],1,En,1,Pr,1,fn,5,En,on,1,dr,gn]);var Lr=class extends fe{constructor(t){super(t)}},Or=class extends fe{constructor(t){super(t)}},Ur=[2,4];Or.prototype.i=Tn([0,Ur,fn,bn,fn,wn,[0,1,yn]]);const Br=function(t){return class extends t{constructor(){super(...arguments),this.M=!1}K(){if(this.M)throw Error("Cannot process because LLM inference engine is currently loading or processing.");this.M=!0}J(){this.M=!1}async Y(t,e){this.K();try{await this.ha(t),await this.h.ccall("CreateLlmInferenceEngine","void",["number","number"],[ce(e,2)??512,ne(e,lr,3)?.i()??40],{async:!0})}finally{this.J()}}U(){this.K();try{this.h.ccall("DeleteLlmInferenceEngine","void",[],[],{async:!1})}finally{this.J()}}async N(t,e,n){this.K();try{const r=[];this.h._userProgressListener=(t,e)=>{t&&r.push(t),n&&n(t,e)};const i=e.j(),o=this.h._malloc(i.length);return this.h.HEAPU8.set(i,o),await async function(t,e,n){t.j||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),e=t.h.stringToNewUTF8(e),await n(e),t.h._free(e)}(this,t,(t=>this.h.ccall("GenerateResponse","void",["number","number","number"],[t,o,i.length],{async:!0}))),n&&n("",!0),this.h._free(o),this.h._userProgressListener=void 0,r.join("")}finally{this.J()}}R(t){this.K();try{let e;return Qn(this,t,(t=>{e=this.h._GetSizeInTokens(t)})),e}finally{this.J()}}async ha(t){t=await async function(t){const e=[];for(var n=0;;){const{done:r,value:i}=await t.read();if(r)break;e.push(i),n+=i.length}if(0===e.length)return new Uint8Array(0);if(1===e.length)return e[0];t=new Uint8Array(n),n=0;for(const r of e)t.set(r,n),n+=r.length;return t}(t);try{this.h.FS_unlink("llm.task")}catch{}this.h.FS_createDataFile("/","llm.task",t,!0,!1,!1)}}}(function(t){return class e extends t{static async ga(t,n){let r;n||=await e.V();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(t=r).adapterInfo||(t.adapterInfo=n.info),r}static async V(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}ba(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}X(){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 gr(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 c=t.i[a];if(n>=c.length){n-=c.length;continue}const u=Math.min(r,c.length-n);if(void 0===(n=pr(c,n,u,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(n,o+s),n=0,s+=u,0==(r-=u))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{W(t,e){Qn(this,"lora_model_ref_in",(n=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,n,e)}))}}}(class extends rr{}))));class kr extends Br{}var xr=class{constructor(t){this.j=t,this.i=Nr,Nr++}},Nr=1;class jr{constructor(){let t,e;this.promise=new Promise(((n,r)=>{t=n,e=r})),this.resolve=t,this.reject=e}}function Fr(t){return 1===t?1:t+t%2}async function Dr(){const t=await kr.V({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 kr.ga(e,t)}function Rr(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 Vr(t){const e=function(t){const e=new Cn;se(e,10,"text_in"),se(e,10,"token_cost_in"),se(e,10,"lora_model_id_to_apply_in"),se(e,10,"lora_model_ref_in"),se(e,10,"lora_model_id_to_load_in"),se(e,16,"streaming_reader"),se(e,15,"text_out"),se(e,15,"text_end"),se(e,15,"token_cost_out");var n=new Fn;le(n,2,"TokenizerInputBuildCalculator"),se(n,3,"PROMPT:text_in"),se(n,3,"LORA_ID:lora_model_id_to_apply_in"),se(n,4,"prompt"),Mn(e,n),le(n=new Fn,2,"ModelDataCalculator"),se(n,6,"MODEL_DATA:__side_packet_1"),se(n,6,"MODEL_TYPE:model_type"),se(n,5,"READ_DATA_FN:streaming_reader"),se(n,3,"LORA_MODEL_SPAN:lora_model_ref_in"),se(n,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),se(n,4,"LORA_DATA:lora_model_data"),Mn(e,n),le(n=new Fn,2,"Gpt2UnicodeMappingCalculator"),se(n,5,"MODEL_TYPE:model_type"),se(n,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Mn(e,n),le(n=new Pn,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var r=new Or,i=ce(t.j,2);ue(r,1,i),le(i=new Lr,2,"spm_vocab_model"),null==i&&(i=void 0);t:{var o=r.m,s=0|o[D];if(H(s),null==i){var a=te(o);if(4!==ee(a,o,s))break t;a.set(Ur,0)}else{const t=te(a=o),e=ee(t,a,s);4!==e&&(e&&(s=qt(a,s,e)),t.set(Ur,4))}qt(o,s,4,i)}return ue(r,3,2),In(n,r.i()),le(r=new Fn,2,"TokenizerCalculator"),ae(r,8,Pn,n),se(r,5,"MODEL_DATA:__side_packet_1"),se(r,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),se(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),se(r,6,"PROCESSOR_GETTER:__input_side_1"),se(r,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),Mn(e,r),le(n=new Pn,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),ue(r=new Er,12,3),le(r,1,"llm.tflite"),ue(r,14,0),i=Fr(ce(t.j,5)),ue(r,22,i),i=ne(t.j,lr,3),re(r,31,i),Qt(i=new wr,1,!0,!1),Qt(i,2,!0,!1),Qt(i,5,!0,!1),re(r,10,i),i=Kt(t.j,4,Lt,void 0===q?2:4),Zt(r,29,i),i=new Ar,ue(o=new Sr,1,1),a=ce(t.j,2),ue(o,2,a),re(i,1,o),re(r,20,i),In(n,r.i()),le(r=new Fn,2,"LlmGpuCalculator"),ae(r,8,Pn,n),se(r,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),se(r,3,"FINISH:finish"),se(r,3,"LORA_DATA:lora_model_data"),se(r,5,"MODEL_DATA:__side_packet_1"),se(r,4,"DECODED_IDS:__stream_3"),se(r,4,"OUTPUT_END:__stream_4"),le(n=new Nn,1,"FINISH"),Qt(n,2,!0,!1),ae(r,13,Nn,n),Mn(e,r),le(n=new Fn,2,"IsPacketPresentCalculator"),se(n,3,"__stream_4"),se(n,4,"text_end"),Mn(e,n),le(n=new Pn,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),r=new vr,t=Fr(ce(t.j,5)),ue(r,5,t),se(r,4,"<eos>"),se(r,4,"<|endoftext|>"),In(n,r.i()),le(t=new Fn,2,"DetokenizerCalculator"),ae(t,8,Pn,n),se(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),se(t,5,"PROCESSOR_GETTER:__input_side_1"),se(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),se(t,5,"MODEL_DATA:__side_packet_1"),se(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),se(t,4,"WORDS:text_out"),Mn(e,t),le(t=new Fn,2,"TokenCostCalculator"),se(t,3,"PROMPT:token_cost_in"),se(t,5,"PROCESSOR_GETTER:__input_side_1"),se(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),se(t,4,"NUM_TOKENS:token_cost_out"),Mn(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<ce(t.j,5)&&t.D[n].push(e)})),t.u&&0===t.B.length&&(t.A?(e.length>ce(t.j,5)&&e.pop(),t.u(e,!1)):t.u(e[0],!1)),cr(t,n)})),t.i.attachEmptyPacketListener("text_out",(e=>{cr(t,e)})),t.i.attachBoolListener("text_end",((e,n)=>{if(t.l=!1,cr(t,n),Rr(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0),t.u)if(t.A){for(e=[],n=0;n<ce(t.j,5);n++)e.push("");t.u(e,!0)}else t.u("",!0);t.A=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.A=void 0,cr(t,e),Rr(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.S=e,cr(t,n)})),t.T&&t.i.addStreamingReaderToInputSidePacket(t.T,"streaming_reader");const n=e.i();return t.C?.removeEventListener("uncapturederror",t.I),t.i.X().then((()=>{t.C?.addEventListener("uncapturederror",t.I),t.B.length=0,t.setGraph(new Uint8Array(n),!0),t.finishProcessing()}))}function Mr(t,e,n,r){if(t.u="function"==typeof n?n:r,t.v){if(t.A&&ce(t.j,5)>1)throw Error("Multi-response generation is not supported for converted LLM models (.task format) yet. Please use the .bin format.");if(n instanceof xr)throw Error("LoRA is not supported for converted LLM models (.task format) yet. Please use the .bin format.");return t.i.N(e,t.s,((e,n)=>{0===t.B.length&&t.u&&(t.A?t.u([e],n):t.u(e,n))})).then((e=>(Rr(t),[e])))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.D.length=0,r=0;r<ce(t.j,5);r++)t.D[r]=[];if(r=t.G+1,t.i.addStringToStream(e,"text_in",r),n instanceof xr){if(n.j!==t)throw t.l=!1,t.A=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.i.addUintToStream(n.i,"lora_model_id_to_apply_in",r)}else t.i.addEmptyPacketToStream("lora_model_id_to_apply_in",r);return t.finishProcessing(),t.o=new jr,t.o.promise}var Cr=class extends ur{constructor(t,e){if(super(new kr(t,e)),this.D=[],this.v=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 fr,hr(this.j,new Gn),this.s=new lr,re(this.j,3,this.s),Ht(this.j,2,Ot(512)),t=this.s,!vt(2))throw B("enum");Qt(t,1,2,0),ue(this.s,2,40),Qt(this.s,3,St(1),0),Ht(this.s,5,Pt(0)),Qt(this.s,4,St(.8),0),Ht(this.j,5,Ot(1))}async L(t){if(this.l)throw Error("Cannot set options while loading or processing.");if(t.baseOptions?.modelAssetPath&&t.baseOptions?.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");let e;const n=new Promise((t=>{e=t}));if(t.baseOptions?.modelAssetPath){var r=await fetch(t.baseOptions.modelAssetPath.toString());if(!r.ok)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (${r.status})`);if(!r.body)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (no body)`);r=r.body.getReader()}else t.baseOptions?.modelAssetBuffer instanceof Uint8Array?r=function(t){return new ReadableStream({start(){},async pull(e){e.enqueue(t),e.close()}})}(t.baseOptions.modelAssetBuffer).getReader():t.baseOptions?.modelAssetBuffer instanceof ReadableStreamDefaultReader?(r=t.baseOptions.modelAssetBuffer,t.baseOptions.modelAssetBuffer=void 0):e();if(!r)throw Error("No model asset provided.");{const[t,n]=Kn(r);1===await async function(t){const e=[];let n;for(const[i,o]of Jn){const s=i;var r=o;[t,n]=Kn(t),r=await r(n),await n.cancel(),r&&e.push(s)}if(await t.cancel(),0===e.length)throw Error("No model format matched.");if(1===e.length)return e[0];throw Error(`Multiple model formats matched: ${e}`)}(n)?(this.v=!0,r=t):(this.v=!1,this.T=function(t,e){return new mr((async()=>{const{value:e,done:n}=await t.read();return n?void 0:e}),e)}(t,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.I),this.C=t.baseOptions.gpuOptions.device,this.i.ba(this.C),this.C.addEventListener("uncapturederror",this.I)),"maxTokens"in t&&Ht(this.j,2,Ot(t.maxTokens??512)),"topK"in t&&ue(this.s,2,t.topK??40),"temperature"in t&&Qt(this.s,4,St(t.temperature??.8),0),"randomSeed"in t&&Ht(this.s,5,Pt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){Zt(t,4,e)}(this.j,t.loraRanks??[]),"numResponses"in t){if((t=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&t>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet.");Ht(this.j,5,Ot(t));const e=ne(this.j,lr,3);t>1&&e&&(e.i()<=1||(function(t){let e=0|(t=t.m)[D];const n=$t(t,e,4),r=At(n);return null!=r&&r!==n&&qt(t,e,4,r),r}(e)??0)<=0)&&console.warn("To generate multiple responses, it is expected topK > 1 and temperature > 0; otherwise, all the generated responses may be the same.")}return this.v?(this.i.U(),this.i.Y(r,this.j).then((()=>{Rr(this)}))):(this.l=!0,r=Vr(this).then((()=>{})),Promise.all([n,r]).then((()=>{this.l=!1,Rr(this)})))}get baseOptions(){return ne(this.j,Gn,1)}set baseOptions(t){hr(this.j,t)}get isIdle(){return!this.l&&!this.o}N(t,e,n){return ce(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.A=!1,Mr(this,t,e,n).then((t=>t[0]))}aa(t,e,n){return this.A=!0,Mr(this,t,e,n)}R(t){if(this.v)return this.i.R(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.S=void 0,this.i.addStringToStream(t,"token_cost_in",this.G+1),this.finishProcessing(),this.l=!1,this.S}async ea(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet. Please use the old foramat (.bin) to use LoRA.");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=t instanceof Blob?await async function(t,e){return _r(t,e.stream(),e.size)}(this.i.h,t):await async function(t,e){e=await fetch(e.toString());const n=Number(e.headers.get("content-length"));if(!e.body)throw Error("Response body is not available.");if(!n)throw Error("File size is 0.");return _r(t,e.body,n)}(this.i.h,t);e=new xr(this);const n=this.G+1;return this.i.W(t,n),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",n),this.finishProcessing(),yr(t),cr(this,n),this.l=!1,e}close(){this.v&&this.i.U(),this.C?.removeEventListener("uncapturederror",this.I),super.close()}};Cr.prototype.loadLoraModel=Cr.prototype.ea,Cr.prototype.sizeInTokens=Cr.prototype.R,Cr.prototype.generateResponses=Cr.prototype.aa,Cr.prototype.generateResponse=Cr.prototype.N,Cr.prototype.setOptions=Cr.prototype.L,Cr.createWebGpuDevice=Dr,Cr.createFromModelPath=async function(t,e){return sr(t,e={baseOptions:{gpuOptions:{device:await Dr()},modelAssetPath:e}})},Cr.createFromModelBuffer=async function(t,e){return sr(t,e={baseOptions:{gpuOptions:{device:await Dr()},modelAssetBuffer:e}})},Cr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Dr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return sr(t,e)};export{qn as FilesetResolver,Cr as LlmInference,ur as TaskRunner};
1
+ var t="undefined"!=typeof self?self:{};let e;const n="undefined"!=typeof TextEncoder;function r(t){if(n)t=(e||=new TextEncoder).encode(t);else{let e=0;const n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var r=t.charCodeAt(i);if(r<128)n[e++]=r;else{if(r<2048)n[e++]=r>>6|192;else{if(r>=55296&&r<=57343){if(r<=56319&&i<t.length){const o=t.charCodeAt(++i);if(o>=56320&&o<=57343){r=1024*(r-55296)+o-56320+65536,n[e++]=r>>18|240,n[e++]=r>>12&63|128,n[e++]=r>>6&63|128,n[e++]=63&r|128;continue}i--}r=65533}n[e++]=r>>12|224,n[e++]=r>>6&63|128}n[e++]=63&r|128}}t=e===n.length?n:n.subarray(0,e)}return t}var i,o;t:{for(var s=["CLOSURE_FLAGS"],a=t,c=0;c<s.length;c++)if(null==(a=a[s[c]])){o=null;break t}o=a}var u,l=o&&o[610401301];function h(){var e=t.navigator;return e&&(e=e.userAgent)?e:""}i=null!=l&&l;const f=t.navigator;u=f&&f.userAgentData||null;var d={},p=null;function g(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=p[e];if(null!=n)return n;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}m();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 m(){if(!p){p={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let n=0;n<5;n++){const r=t.concat(e[n].split(""));d[n]=r;for(let t=0;t<r.length;t++){const e=r[t];void 0===p[e]&&(p[e]=t)}}}}var _="undefined"!=typeof Uint8Array,y=!(!(i&&u&&u.brands.length>0)&&(-1!=h().indexOf("Trident")||-1!=h().indexOf("MSIE")))&&"function"==typeof btoa;const b=/[-_.]/g,v={"-":"+",_:"/",".":"="};function w(t){return v[t]||""}function S(t){if(!y)return g(t);t=b.test(t)?t.replace(b,w):t,t=atob(t);const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}function E(t){return _&&null!=t&&t instanceof Uint8Array}var T={};function A(){return P||=new I(null,T)}var I=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")}};let P,L;function O(t){if(t!==T)throw Error("illegal external caller")}function j(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function U(t){return j(t=Error(t),"warning"),t}var x="function"==typeof Symbol&&"symbol"==typeof Symbol();function B(t,e,n=!1){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?n&&Symbol.for&&t?Symbol.for(t):null!=t?Symbol(t):Symbol():e}var k=B("jas",void 0,!0),N=B(void 0,"1oa"),F=B(void 0,"0actk"),D=B("m_m","ia",!0);const R={aa:{value:0,configurable:!0,writable:!0,enumerable:!1}},V=Object.defineProperties,M=x?k:"aa";var C;const G=[];function z(t,e){x||M in t||V(t,R),t[M]=e}function W(){return"function"==typeof BigInt}z(G,7),C=Object.freeze(G);var $={};function H(t,e){return void 0===e?t.i!==q&&!!(2&(0|t.m[M])):!!(2&e)&&t.i!==q}const q={};var K=Object.freeze({});function Y(t){return t.ha=!0,t}var J=Y((t=>"number"==typeof t)),X=Y((t=>"string"==typeof t)),Z=Y((t=>"boolean"==typeof t)),Q="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),tt=Y((t=>Q?t>=nt&&t<=it:"-"===t[0]?ot(t,et):ot(t,rt)));const et=Number.MIN_SAFE_INTEGER.toString(),nt=Q?BigInt(Number.MIN_SAFE_INTEGER):void 0,rt=Number.MAX_SAFE_INTEGER.toString(),it=Q?BigInt(Number.MAX_SAFE_INTEGER):void 0;function ot(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 st,at=0,ct=0;function ut(t){const e=t>>>0;at=e,ct=(t-e)/4294967296>>>0}function lt(t){if(t<0){ut(-t);const[e,n]=gt(at,ct);at=e>>>0,ct=n>>>0}else ut(t)}function ht(t,e){const n=4294967296*e+(t>>>0);return Number.isSafeInteger(n)?n:ft(t,e)}function ft(t,e){if(t>>>=0,(e>>>=0)<=2097151)var n=""+(4294967296*e+t);else W()?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+dt(n)+dt(t));return n}function dt(t){return t=String(t),"0000000".slice(t.length)+t}function pt(t){if(t.length<16)lt(Number(t));else if(W())t=BigInt(t),at=Number(t&BigInt(4294967295))>>>0,ct=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);ct=at=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));ct*=1e6,at=1e6*at+e,at>=4294967296&&(ct+=Math.trunc(at/4294967296),ct>>>=0,at>>>=0)}if(e){const[t,e]=gt(at,ct);at=t,ct=e}}}function gt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function mt(t){return Array.prototype.slice.call(t)}const _t="function"==typeof BigInt?BigInt.asIntN:void 0,yt="function"==typeof BigInt?BigInt.asUintN:void 0,bt=Number.isSafeInteger,vt=Number.isFinite,wt=Math.trunc;function St(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}function Et(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}function Tt(t){if(null!=t&&"boolean"!=typeof t){var e=typeof t;throw Error(`Expected boolean but got ${"object"!=e?e:t?Array.isArray(t)?"array":e:"null"}: ${t}`)}return t}function At(t){return null==t||"boolean"==typeof t?t:"number"==typeof t?!!t:void 0}const It=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Pt(t){switch(typeof t){case"bigint":return!0;case"number":return vt(t);case"string":return It.test(t);default:return!1}}function Lt(t){if("number"!=typeof t)throw U("int32");if(!vt(t))throw U("int32");return 0|t}function Ot(t){return null==t?t:Lt(t)}function jt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?0|t:void 0}function Ut(t){if(null!=t){if("number"!=typeof t)throw U("uint32");if(!vt(t))throw U("uint32");t>>>=0}return t}function xt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?t>>>0:void 0}function Bt(t){if("-"===t[0])return!1;const e=t.length;return e<20||20===e&&Number(t.substring(0,6))<184467}function kt(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(yt(64,t));if(Pt(t)){if("string"===e)return e=wt(Number(t)),bt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),Bt(t)||(pt(t),t=ft(at,ct))),t;if("number"===e)return(t=wt(t))>=0&&bt(t)?t:function(t){if(t<0){lt(t);var e=ft(at,ct);return t=Number(e),bt(t)?t:e}return Bt(e=String(t))?e:(lt(t),ht(at,ct))}(t)}}function Nt(t){return null==t||"string"==typeof t?t:void 0}function Ft(t,e,n){if(null!=t&&"object"==typeof t&&t[D]===$)return t;if(Array.isArray(t)){var r=0|t[M];return(n=r|32&n|2&n)!==r&&z(t,n),new e(t)}}function Dt(t,e,n,r){var i=void 0!==r;r=!!r;const o=[];var s=t.length;let a,c=4294967295,u=!1;const l=!!(64&e),h=l?128&e?0:-1:void 0;for(1&e||(a=s&&t[s-1],null!=a&&"object"==typeof a&&a.constructor===Object?c=--s:a=void 0,!l||128&e||i||(u=!0,c=c-h+h)),e=void 0,i=0;i<s;i++){let s=t[i];if(null!=s&&null!=(s=n(s,r)))if(l&&i>=c){const t=i-h;(e??={})[t]=s}else o[i]=s}if(a)for(let i in a){if(null==(t=a[i])||null==(t=n(t,r)))continue;let u;s=+i,l&&!Number.isNaN(s)&&(u=s+h)<c?o[u]=t:(e??={})[i]=t}return e&&(u?o.push(e):o[c]=e),o}function Rt(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return tt(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[M];return 0===t.length&&1&e?void 0:Dt(t,e,Rt)}if(t[D]===$)return Vt(t);if(t instanceof I){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(y){for(var n="",r=0,i=e.length-10240;r<i;)n+=String.fromCharCode.apply(null,e.subarray(r,r+=10240));n+=String.fromCharCode.apply(null,r?e.subarray(r):e),e=btoa(n)}else{void 0===n&&(n=0),m(),n=d[n],r=Array(Math.floor(e.length/3)),i=n[64]||"";let t=0,u=0;for(;t<e.length-2;t+=3){var o=e[t],s=e[t+1],a=e[t+2],c=n[o>>2];o=n[(3&o)<<4|s>>4],s=n[(15&s)<<2|a>>6],a=n[63&a],r[u++]=c+o+s+a}switch(c=0,a=i,e.length-t){case 2:a=n[(15&(c=e[t+1]))<<2]||i;case 1:e=e[t],r[u]=n[e>>2]+n[(3&e)<<4|c>>4]+a+i}e=r.join("")}t=t.i=e}return t}return}return t}function Vt(t){return Dt(t=t.m,0|t[M],Rt)}let Mt,Ct;function Gt(t,e,n){return zt(t,e[0],e[1],n?1:2)}function zt(e,n,r,i=0){if(null==e){var o=32;r?(e=[r],o|=128):e=[],n&&(o=-8380417&o|(1023&n)<<13)}else{if(!Array.isArray(e))throw Error("narr");if(2048&(o=0|e[M])&&!(2&o)&&function(){if(null!=F){var e=L??={},n=e[F]||0;n>=5||(e[F]=n+1,j(e=Error(),"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e))}}(),256&o)throw Error("farr");if(64&o)return 0!==i||2048&o||z(e,2048|o),e;if(r&&(o|=128,r!==e[0]))throw Error("mid");t:{o|=64;var s=(r=e).length;if(s){var a=s-1;const t=r[a];if(null!=t&&"object"==typeof t&&t.constructor===Object){if((a-=n=128&o?0:-1)>=1024)throw Error("pvtlmt");for(var c in t)(s=+c)<a&&(r[s+n]=t[c],delete t[c]);o=-8380417&o|(1023&a)<<13;break t}}if(n){if((c=Math.max(n,s-(128&o?0:-1)))>1024)throw Error("spvt");o=-8380417&o|(1023&c)<<13}}}return o|=64,0===i&&(o|=2048),z(e,o),e}function Wt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var n=0|t[M];return 0===t.length&&1&n?t=void 0:2&n||(!e||4096&n||16&n?t=$t(t,n,!1,e&&!(16&n)):(e=t,x||M in e||V(e,R),e[M]|=34,4&n&&Object.freeze(t))),t}if(t[D]===$){const r=0|(e=t.m)[M];return n=H(t,r)?t:$t(e,r)}return t instanceof I?t:void 0}function $t(t,e,n,r){return r??=!!(34&e),t=Dt(t,e,Wt,r),r=32,n&&(r|=2),z(t,e=8380609&e|r),t}function Ht(t){if(t.i!==q)return!1;let e=t.m;return e=$t(e,0|e[M]),t.m=e,t.i=void 0,t.o=void 0,!0}function qt(t){if(!Ht(t)&&H(t,0|t.m[M]))throw Error()}function Kt(t,e,n,r){if(null!==(t=Yt(t.m,e,n,r)))return t}function Yt(t,e,n,r){if(-1===e)return null;const i=e+(n?0:-1),o=t.length-1;let s,a;if(!(o<1+(n?0:-1))){if(i>=o)if(s=t[o],null!=s&&"object"==typeof s&&s.constructor===Object)n=s[e],a=!0;else{if(i!==o)return;n=s}else n=t[i];if(r&&null!=n){if(null==(r=r(n)))return r;if(!Object.is(r,n))return a?s[e]=r:t[i]=r,r}return n}}function Jt(t,e,n){qt(t),Xt(t=t.m,0|t[M],e,n)}function Xt(t,e,n,r,i){const o=n+(i?0:-1);var s=t.length-1;if(s>=1+(i?0:-1)&&o>=s){const i=t[s];if(null!=i&&"object"==typeof i&&i.constructor===Object)return i[n]=r,e}return o<=s?(t[o]=r,e):(void 0!==r&&(n>=(s=(e??=0|t[M])>>13&1023||536870912)?null!=r&&(t[s+(i?0:-1)]={[n]:r}):t[o]=r),e)}function Zt(t,e,n,r,i){let o=t.m,s=0|o[M];r=H(t,s)?1:r,i=!!i||3===r,2===r&&Ht(t)&&(o=t.m,s=0|o[M]);let a=(t=te(o,e))===C?7:0|t[M],c=ee(a,s);var u=!(4&c);if(u){4&c&&(t=mt(t),a=0,c=le(c,s),s=Xt(o,s,e,t));let r=0,i=0;for(;r<t.length;r++){const e=n(t[r]);null!=e&&(t[i++]=e)}i<r&&(t.length=i),n=-513&(4|c),c=n&=-1025,c&=-4097}return c!==a&&(z(t,c),2&c&&Object.freeze(t)),Qt(t,c,o,s,e,r,u,i)}function Qt(t,e,n,r,i,o,s,a){let c=e;return 1===o||4===o&&(2&e||!(16&e)&&32&r)?ne(e)||((e|=!t.length||s&&!(4096&e)||32&r&&!(4096&e||16&e)?2:256)!==c&&z(t,e),Object.freeze(t)):(2===o&&ne(e)&&(t=mt(t),c=0,e=le(e,r),Xt(n,r,i,t)),ne(e)||(a||(e|=16),e!==c&&z(t,e))),t}function te(t,e,n){return t=Yt(t,e,n),Array.isArray(t)?t:C}function ee(t,e){return 2&e&&(t|=2),1|t}function ne(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function re(t,e,n){qt(t);let r=0|(t=t.m)[M];if(null==n)Xt(t,r,e);else{var i=n===C?7:0|n[M],o=i,s=ne(i),a=s||Object.isFrozen(n);for(s||(i=0),a||(n=mt(n),o=0,i=le(i,r),a=!1),i|=5,s=0;s<n.length;s++){const t=n[s],e=Lt(t);Object.is(t,e)||(a&&(n=mt(n),o=0,i=le(i,r),a=!1),n[s]=e)}i!==o&&(a&&(n=mt(n),i=le(i,r)),z(n,i)),Xt(t,r,e,n)}}function ie(t,e,n,r){qt(t),Xt(t=t.m,0|t[M],e,("0"===r?0===Number(n):n===r)?void 0:n)}function oe(t){if(x)return t[N]??(t[N]=new Map);if(N in t)return t[N];const e=new Map;return Object.defineProperty(t,N,{value:e}),e}function se(t,e,n){var r=Fr;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!=Yt(e,o)&&(0!==i&&(n=Xt(e,n,i)),i=o)}return t.set(r,i),i}function ae(t,e,n){let r=t.m,i=0|r[M];if(e=function(t,e,n,r){if(null!=(t=Yt(t,r,void 0,(t=>Ft(t,n,e)))))return t}(r,i,e,n),null==e)return e;if(i=0|r[M],!H(t,i)){var o,s=e;const a=s.m,c=0|a[M];(o=H(s,c)?new s.constructor($t(a,c,!1)):s)!==e&&(Ht(t)&&(r=t.m,i=0|r[M]),Xt(r,i,n,e=o))}return e}function ce(t){return null==t&&(t=void 0),t}function ue(t,e,n){return Jt(t,e,n=ce(n)),t}function le(t,e){return-273&(2&e?2|t:-3&t)}function he(t,e,n,r){qt(t);var i=t.m,o=i;const s=H(t,i=0|i[M])?1:2;2===s&&Ht(t)&&(i=0|(o=t.m)[M]);let a=(t=te(o,e))===C?7:0|t[M];var c=ee(a,i);const u=!(4&c);if(u){var l=t,h=i;const e=!!(2&c);e&&(h|=2);let r=!e,o=!0,s=0,a=0;for(;s<l.length;s++){const t=Ft(l[s],n,h);if(t instanceof n){if(!e){const e=H(t);r&&=!e,o&&=e}l[a++]=t}}a<s&&(l.length=a),c|=4,c=o?-4097&c:4096|c,c=r?8|c:-9&c}c!==a&&(z(t,c),2&c&&Object.freeze(t)),e=t=Qt(t,c,o,i,e,s,u,!0),r=null!=r?r:new n,e.push(r),o=n=e===C?7:0|e[M],H(r)?(n&=-9,1===e.length&&(n&=-4097)):n|=4096,n!==o&&z(e,n)}function fe(t,e){return xt(Kt(t,e))??0}function de(t,e,n){ie(t,e,Ot(n),0)}function pe(t,e,n){if(null!=n&&"string"!=typeof n)throw Error();ie(t,e,n,"")}function ge(t,e,n){if(qt(t),e=(t=Zt(t,e,Nt,2,!0)).push,"string"!=typeof n)throw Error();e.call(t,n)}var me=class{constructor(t,e,n){if(this.buffer=t,n&&!e)throw Error()}};function _e(t){if("string"==typeof t)return new me(S(t),!0);if(Array.isArray(t))return new me(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new me(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new me(t,!1);if(t.constructor===I){O(T);var e=t.i;return e=(null==(e=null==e||E(e)?e:"string"==typeof e?S(e):null)?e:t.i=e)||new Uint8Array(0),new me(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new me(t,!1);throw Error()}var ye=class{constructor(t,e){this.m=zt(t,e)}toJSON(){return Vt(this)}};function be(t){return t?/^\d+$/.test(t)?(pt(t),new ve(at,ct)):null:we||=new ve(0,0)}ye.prototype[D]=$,ye.prototype.toString=function(){return this.m.toString()};var ve=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let we;function Se(t){return t?/^-?\d+$/.test(t)?(pt(t),new Ee(at,ct)):null:Te||=new Ee(0,0)}var Ee=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Te;function Ae(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 Ie(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Pe(t,e){if(e>=0)Ie(t,e);else{for(let n=0;n<9;n++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function Le(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Oe(t,e,n){Ie(t.i,8*e+n)}function je(t,e){return Oe(t,e,2),e=t.i.end(),Le(t,e),e.push(t.j),e}function Ue(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 xe(t,e,n){Oe(t,e,2),Ie(t.i,n.length),Le(t,t.i.end()),Le(t,n)}function Be(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var ke=Be(),Ne=Be(),Fe=Be(),De=Be(),Re=Be(),Ve=Be(),Me=class{constructor(t,e){this.i=t,t=ke,this.j=!!t&&e===t||!1}};function Ce(t,e,n,r,i){null!=(e=Ke(e,r))&&(n=je(t,n),i(e,t),Ue(t,n))}const Ge=new Me(Ce,ke),ze=new Me(Ce,ke);var We=Symbol(),$e=Symbol();let He;function qe(t){var e=Ye,n=Je,r=t[We];if(r)return r;(r={}).ga=t,r.S=function(t){switch(typeof t){case"boolean":return Mt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Ct||=[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.X=i,"function"==typeof(i=t[++o])&&(r.ba=!0,He??=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 c=void 0;if(i instanceof Me?s=i:(s=Ge,o--),s?.j){i=t[++o],c=t;var u=o;"function"==typeof i&&(i=i(),c[u]=i),c=i}for(u=a+1,"number"==typeof(i=t[++o])&&i<0&&(u-=i,i=t[++o]);a<u;a++)c?n(r,a,s,c):e(r,a,s)}return t[We]=r}function Ke(t,e){return t instanceof ye?t.m:Array.isArray(t)?Gt(t,e,!1):void 0}function Ye(t,e,n){t[e]=n.i}function Je(t,e,n,r){let i,o;const s=n.i;t[e]=(t,e,n)=>s(t,e,n,o||=qe(r).S,i||=Xe(r))}function Xe(t){let e=t[$e];if(!e){const n=qe(t);e=(t,e)=>Ze(t,e,n),t[$e]=e}return e}function Ze(t,e,n){!function(t,e,n){e=128&e?0:-1;const r=t.length;var i;(i=!!r)&&(i=null!=(i=t[r-1])&&"object"==typeof i&&i.constructor===Object);const o=r+(i?-1:0);for(let r=0;r<o;r++)n(r-e,t[r]);if(i){t=t[r-1];for(const e in t)!isNaN(e)&&n(+e,t[e])}}(t,0|t[M],((t,r)=>{if(null!=r){var i=function(t,e){var n=t[e];if(n)return n;if((n=t.X)&&(n=n[e])){var r=(n=Array.isArray(n)?n[0]instanceof Me?n:[ze,n]:[n,void 0])[0].i;if(n=n[1]){const e=Xe(n),i=qe(n).S;n=t.ba?He(i,e):(t,n,o)=>r(t,n,o,i,e)}else n=r;return t[e]=n}}(n,t);i&&i(e,r,t)}}))}var Qe,tn=0,en=tn;if(X(en)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(en))throw Error(String(en))}else if((Qe=J(en))&&(Qe=!Number.isSafeInteger(en)),Qe)throw Error(String(en));function nn(t,e){if(Array.isArray(e)){var n=0|e[M];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),z(e,-1537&(5|n)),2&n&&Object.freeze(e),e}}function rn(t,e){return new Me(t,e)}function on(t,e,n){null!=(e=Et(e))&&(Oe(t,n,5),t=t.i,(n=st||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ct=0,e=at=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 sn(t,e,n){null!=(e=jt(e))&&null!=e&&(Oe(t,n,0),Pe(t.i,e))}function an(t,e,n){null!=(e=At(e))&&(Oe(t,n,0),t.i.i.push(e?1:0))}function cn(t,e,n){null!=(e=Nt(e))&&xe(t,n,r(e))}function un(t,e,n,r,i){null!=(e=Ke(e,r))&&(n=je(t,n),i(e,t),Ue(t,n))}function ln(t,e,n){null!=(e=jt(e))&&(e=parseInt(e,10),Oe(t,n,0),Pe(t.i,e))}Q||(tn=Z(tn)?tn?"1":"0":X(tn)?tn.trim()||"0":String(tn));var hn,fn=rn(on,Re),dn=rn(on,Re),pn=rn((function(t,e,n){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(_t(64,t));if(Pt(t)){if("string"===e){if(e=wt(Number(t)),bt(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),e=t.length,!("-"===t[0]?e<20||20===e&&Number(t.substring(0,7))>-922337:e<19||19===e&&Number(t.substring(0,6))<922337))if(pt(t),t=at,2147483648&(e=ct))if(W())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[n,r]=gt(t,e);t="-"+ft(n,r)}else t=ft(t,e);return t}if("number"===e){if(t=wt(t),!bt(t)){lt(t),e=at;var n=ct;(t=2147483648&n)&&(n=~n>>>0,0==(e=1+~e>>>0)&&(n=n+1>>>0)),t="number"==typeof(e=ht(e,n))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)Se(e);if(null!=e)switch(Oe(t,n,0),typeof e){case"number":t=t.i,lt(e),Ae(t,at,ct);break;case"bigint":n=BigInt.asUintN(64,e),n=new Ee(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),Ae(t.i,n.j,n.i);break;default:n=Se(e),Ae(t.i,n.j,n.i)}}}),Be()),gn=rn((function(t,e,n){if(null!=(e=kt(e))){if("string"==typeof e)be(e);if(null!=e)switch(Oe(t,n,0),typeof e){case"number":t=t.i,lt(e),Ae(t,at,ct);break;case"bigint":n=BigInt.asUintN(64,e),n=new ve(Number(n&BigInt(4294967295)),Number(n>>BigInt(32))),Ae(t.i,n.j,n.i);break;default:n=be(e),Ae(t.i,n.j,n.i)}}}),Be()),mn=rn(sn,De);hn=new Me((function(t,e,n){if(null!=(e=nn(jt,e))&&e.length){n=je(t,n);for(let n=0;n<e.length;n++)Pe(t.i,e[n]);Ue(t,n)}}),De);var _n,yn=rn(sn,De),bn=rn(sn,De),vn=rn(an,Ne),wn=rn(an,Ne),Sn=rn(cn,Fe);_n=new Me((function(t,e,n){if(null!=(e=nn(Nt,e)))for(let a=0;a<e.length;a++){var i=t,o=n,s=e[a];null!=s&&xe(i,o,r(s))}}),Fe);var En,Tn=rn(cn,Fe),An=rn(cn,Fe),In=function(t,e,n=ke){return new Me(e,n)}(0,(function(t,e,n,r,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)un(t,e[o],n,r,i)})),Pn=new Me(un,ke),Ln=rn((function(t,e,n){null!=(e=xt(e))&&null!=e&&(Oe(t,n,0),Ie(t.i,e))}),Be()),On=rn(ln,Ve);En=new Me((function(t,e,n){if(null!=(e=nn(jt,e))&&e.length){n=je(t,n);for(let n=0;n<e.length;n++)Pe(t.i,e[n]);Ue(t,n)}}),Ve);var jn=rn(ln,Ve);function Un(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}}}};Ze(this.m,e,qe(t)),Le(e,e.i.end());const n=new Uint8Array(e.j),r=e.l,i=r.length;let o=0;for(let t=0;t<i;t++){const e=r[t];n.set(e,o),o+=e.length}return e.l=[n],n}}function xn(t,e){if(null!=e)if(Array.isArray(e))Jt(t,2,Dt(e,0,Rt));else{if(!("string"==typeof e||e instanceof I||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 I(e,T):A();else if(e.constructor!==I){if(!E(e))throw Error();e=e.length?new I(new Uint8Array(e),T):A()}ie(t,2,e,A())}}var Bn=class extends ye{constructor(t){super(t)}},kn=[0,Tn,rn((function(t,e,n){if(null!=e){if(e instanceof ye){const r=e.ja;return void(r&&(e=r(e),null!=e&&xe(t,n,_e(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||e instanceof I?e:void 0)&&xe(t,n,_e(e).buffer)}),Be())];let Nn,Fn=globalThis.trustedTypes;function Dn(t){var e;return void 0===Nn&&(Nn=function(){let t=null;if(!Fn)return t;try{const e=t=>t;t=Fn.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=Nn)?e.createScriptURL(t):t,new class{constructor(t){this.i=t}toString(){return this.i+""}}(t)}function Rn(t,...e){if(0===e.length)return Dn(t[0]);let n=t[0];for(let r=0;r<e.length;r++)n+=encodeURIComponent(e[r])+t[r+1];return Dn(n)}var Vn={};Vn[336783863]=[0,Sn,vn,-1,mn,[0,[1,2,3,4,5,6,7,8,9],Pn,[0],Pn,[0,vn,Sn,vn,On,-1,En,Sn,-1,[0,vn,-1],On,vn,-1],Pn,[0,Sn,-2],Pn,[0,mn,vn,1,vn,-3],Pn,[0,mn,On,vn,-1,hn,On,-1],Pn,[0,Sn,-2],Pn,[0,Sn,On],Pn,[0,On,Sn,-1,vn],Pn,[0,On,-1]],[0,Sn],vn,[0,[1,3],[2,4],Pn,[0,hn],-1,Pn,[0,_n],-1,In,[0,Sn,-1]],Sn];var Mn=class extends ye{constructor(t){super(t)}},Cn=[0,pn,-1,wn,-3,pn,hn,Tn,yn,pn,-1,wn,yn,wn,-2,Tn],Gn=class extends ye{constructor(t){super(t,500)}K(t){return ue(this,7,t)}},zn=[-1,{}],Wn=[0,Sn,1,zn],$n=[0,Sn,_n,zn];function Hn(t,e){he(t,1,Gn,e)}var qn=class extends ye{constructor(t){super(t,500)}K(t){return ue(this,1001,t)}};qn.prototype.j=Un([-500,In,[-500,Tn,-1,_n,-3,[-2,Vn,vn],In,kn,yn,-1,Wn,$n,In,[0,Tn,wn],Tn,Cn,yn,_n,987,_n],4,In,[-500,Sn,-1,[-1,{}],998,Sn],In,[-500,Sn,_n,-1,[-2,{},vn],997,_n,-1],yn,In,[-500,Sn,_n,zn,998,_n],_n,yn,Wn,$n,In,[0,Tn,-1,zn],_n,-2,Cn,Tn,-1,wn,[0,wn,Ln],978,zn,In,kn]);var Kn=class extends ye{constructor(t){super(t)}};let Yn;const Jn=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 Xn(){if(void 0===Yn)try{await WebAssembly.instantiate(Jn),Yn=!0}catch{Yn=!1}return Yn}async function Zn(t,e=Rn``){const n=await Xn()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${n}.js`,wasmBinaryPath:`${e}/${t}_${n}.wasm`}}var Qn=class{};function tr(t){function e(e,n){return new ReadableStream({start(){},async pull(r){i=i.then((async()=>{if(e.cache.length>0)r.enqueue(e.cache.shift());else{var{value:i,done:o}=await t.read();i&&(n.active&&n.cache.push(i),e.active&&r.enqueue(i)),o&&r.close()}})),await i},cancel(){e.active=!1,e.cache.length=0,n.active||t.cancel()}})}var n={cache:[],active:!0};const r={cache:[],active:!0};let i=Promise.resolve();const o=e(n,r);return n=e(r,n),[o.getReader(),n.getReader()]}async function er(t,e){const n=new Uint8Array(e);let r=0;for(;r<e;){const{value:i,done:o}=await t.read();if(i){const t=i.subarray(0,e-r);n.set(t,r),r+=t.length}if(o)throw Error(`Expected ${e} bytes, but stream ended after reading ${r} bytes.`)}return await t.cancel(),n}Qn.forVisionTasks=function(t){return Zn("vision",t)},Qn.forTextTasks=function(t){return Zn("text",t)},Qn.forGenAiExperimentalTasks=function(t){return Zn("genai_experimental",t)},Qn.forGenAiTasks=function(t){return Zn("genai",t)},Qn.forAudioTasks=function(t){return Zn("audio",t)},Qn.isSimdSupported=function(){return Xn()};const nr=[[0,async t=>{const e=(new TextEncoder).encode("TFL3").length;return t=await er(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await er(t,6))[4]&&75===t[5]]];function rr(){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 ir(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())}function or(t,e,n){t.j||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 sr(t,e,n){t.j||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 ar(t,e,n){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=n}function cr(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 ur=(lr=class{constructor(t,e){this.o=!0,this.h=t,this.i=null,this.l=0,this.j="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:rr()?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?'),or(this,r||"input_audio",(r=>{or(this,i=i||"audio_header",(i=>{this.h._configureAudio(r,i,t,e??0,n)}))}))}setAutoResizeCanvas(t){this.o=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.l!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.l=o),this.h.HEAPF32.set(t,this.i/4),or(this,r,(t=>{this.h._addAudioToInputStream(this.i,e,n,t,i)}))}addGpuBufferToStream(t,e,n){or(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.o||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){or(this,e,(e=>{this.h._addBoolToInputStream(t,e,n)}))}addDoubleToStream(t,e,n){or(this,e,(e=>{this.h._addDoubleToInputStream(t,e,n)}))}addFloatToStream(t,e,n){or(this,e,(e=>{this.h._addFloatToInputStream(t,e,n)}))}addIntToStream(t,e,n){or(this,e,(e=>{this.h._addIntToInputStream(t,e,n)}))}addUintToStream(t,e,n){or(this,e,(e=>{this.h._addUintToInputStream(t,e,n)}))}addStringToStream(t,e,n){or(this,e,(e=>{or(this,t,(t=>{this.h._addStringToInputStream(t,e,n)}))}))}addStringRecordToStream(t,e,n){or(this,e,(e=>{sr(this,Object.keys(t),(r=>{sr(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(r,i,Object.keys(t).length,e,n)}))}))}))}addProtoToStream(t,e,n,r){or(this,n,(n=>{or(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){or(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,n){or(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){or(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){or(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){or(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){or(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){or(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)or(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputStream(r,e,n)}))}addBoolToInputSidePacket(t,e){or(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){or(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){or(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){or(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){or(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){or(this,e,(e=>{or(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,n){or(this,n,(n=>{or(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){or(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){or(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){or(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){or(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){or(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){or(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)or(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputSidePacket(n,e)}))}attachBoolListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){ar(this,t,e),or(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){cr(this,t,e),or(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,n){ar(this,t,e),or(this,t,(t=>{this.h._attachProtoListener(t,n||!1)}))}attachProtoVectorListener(t,e,n){cr(this,t,e),or(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?'),ar(this,t,((t,n)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,n)})),or(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 lr{da(){this.h._registerModelResourcesGraphService()}});var lr;async function hr(t,e){const n=await(async(t,e,n)=>{var r=qr;if(t&&await ir(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await ir(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 fr(t,e){return hr(t,e)}function dr(t){try{const e=t.G.length;if(1===e)throw Error(t.G[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.G.map((t=>t.message)).join(", "))}finally{t.G=[]}}function pr(t,e){t.F=Math.max(t.F,e)}var gr=class{constructor(t){this.i=t,this.G=[],this.F=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.G.push(Error(e))})),this.i.da(),this.i.setGraph(t,e),dr(this)}finishProcessing(){this.i.finishProcessing(),dr(this)}close(){this.i.closeGraph()}};gr.prototype.close=gr.prototype.close;var mr=class extends ye{constructor(t){super(t)}j(){return jt(Kt(this,2))??0}};function _r(t,e){ue(t,1,e)}var yr=class extends ye{constructor(t){super(t)}},br=[0,jn,yn,dn,-1,mn];function vr(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}}mr.prototype.l=Un(br);class wr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Sr=class{constructor(t,e){this.i=[],this.j=t,this.l=e}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};async function Er(t,e,n){t=new Ar(t,n);let r=0;for(e=e.getReader();;){const{value:n,done:i}=await e.read();if(i)break;t.set(n,r),r+=n.byteLength}if(n!==r)throw Tr(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${r}/${n} bytes before failure`);return t}function Tr(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Ar=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))}},Ir=class extends ye{constructor(t){super(t)}};Ir.prototype.j=Un([0,Tn,2,_n,yn,wn]);var Pr=class extends ye{constructor(t){super(t)}},Lr=class extends ye{constructor(t){super(t)}},Or=class extends ye{constructor(t){super(t)}},jr=class extends ye{constructor(t){super(t)}},Ur=[0,yn,-6,1,yn,1,[0,wn,jn,-2],[0,wn,dn],jn,-2,[0,wn,-1,jn,dn,On,mn,vn],1,wn,yn,mn,-1,[0,jn,yn],wn,-1,fn,yn,-5,fn,-1,[0,mn,fn],mn,vn,[0,mn,-2],fn,[0,yn],[0,dn,-1]],xr=[0,Tn,-2],Br=[0,[4,6],Ur,yn,1,bn,_n,An,En,xr,mn,[0,[0,yn,-1,In,[0,yn,[0,yn,-1],-1,[0,jn,-1],wn],wn,-2,yn,-1],[0,yn,-1,wn],Ur,wn,yn],Sn,-3,[0,yn,wn],Ur,[0,xr,-2]];jr.prototype.j=Un([0,Tn,8,[0,wn,-6],1,yn,1,yn,[0,In,[0,Tn,gn,-1,jn],Br,yn],[0,yn,wn,-3],1,jn,1,Br,1,yn,5,jn,hn,1,br,wn]);var kr=class extends ye{constructor(t){super(t)}},Nr=class extends ye{constructor(t){super(t)}},Fr=[2,4];Nr.prototype.j=Un([0,Fr,yn,An,yn,Pn,[0,1,Tn]]);const Dr=function(t){return class extends t{constructor(){super(...arguments),this.L=!1}J(){if(this.L)throw Error("Cannot process because LLM inference engine is currently loading or processing.");this.L=!0}I(){this.L=!1}async W(t,e){this.J();try{await this.fa(t),await this.h.ccall("CreateLlmInferenceEngine","void",["number","number","boolean"],[fe(e,2)??512,ae(e,mr,3)?.j()??40,At(Kt(e,6))??!1??!1],{async:!0})}finally{this.I()}}R(){this.J();try{this.h.ccall("DeleteLlmInferenceEngine","void",[],[],{async:!1})}finally{this.I()}}async M(t,e,n){this.J();try{const r=[];this.h._userProgressListener=(t,e)=>{t&&r.push(t),n&&n(t,e)};const i=e.l(),o=this.h._malloc(i.length);return this.h.HEAPU8.set(i,o),await async function(t,e,n){t.j||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),e=t.h.stringToNewUTF8(e),await n(e),t.h._free(e)}(this,t,(t=>this.h.ccall("GenerateResponse","void",["number","number","number"],[t,o,i.length],{async:!0}))),n&&n("",!0),this.h._free(o),this.h._userProgressListener=void 0,r.join("")}finally{this.I()}}N(t){this.J();try{let e;return or(this,t,(t=>{e=this.h._GetSizeInTokens(t)})),e}finally{this.I()}}async fa(t){t=await async function(t){const e=[];for(var n=0;;){const{done:r,value:i}=await t.read();if(r)break;e.push(i),n+=i.length}if(0===e.length)return new Uint8Array(0);if(1===e.length)return e[0];t=new Uint8Array(n),n=0;for(const r of e)t.set(r,n),n+=r.length;return t}(t);try{this.h.FS_unlink("llm.task")}catch{}this.h.FS_createDataFile("/","llm.task",t,!0,!1,!1)}}}(function(t){return class e extends t{static async ea(t,n){let r;n||=await e.T();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(t=r).adapterInfo||(t.adapterInfo=n.info),r}static async T(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}Z(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}V(){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 wr(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 c=t.i[a];if(n>=c.length){n-=c.length;continue}const u=Math.min(r,c.length-n);if(void 0===(n=vr(c,n,u,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(n,o+s),n=0,s+=u,0==(r-=u))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{U(t,e){or(this,"lora_model_ref_in",(n=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,n,e)}))}}}(class extends ur{}))));class Rr extends Dr{}var Vr=class{constructor(t){this.j=t,this.i=Mr,Mr++}},Mr=1;class Cr{constructor(){let t,e;this.promise=new Promise(((n,r)=>{t=n,e=r})),this.resolve=t,this.reject=e}}function Gr(t){return 1===t?1:t+t%2}async function zr(){const t=await Rr.T({powerPreference:"high-performance"});var e=t.limits.maxBufferSize,n=t.limits.maxStorageBufferBindingSize;return e<524550144&&console.warn(`This WebGPU device is unable to execute most LLM tasks, because the required maxBufferSize is usually at least 524550144, but your device only supports maxBufferSize of ${e}`),n<524550144&&console.warn(`The WebGPU device is unable to execute LLM tasks, because the required maxStorageBufferBindingSize is usually at least 524550144, but your device only supports maxStorageBufferBindingSize of ${n}`),e={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:n,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."),n=["shader-f16","subgroups"],t.features.has("subgroups-f16")&&n.push("subgroups-f16"),e.requiredFeatures=n),Rr.ea(e,t)}function Wr(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 $r(t){const e=function(t){const e=new qn;ge(e,10,"text_in"),ge(e,10,"token_cost_in"),ge(e,10,"lora_model_id_to_apply_in"),ge(e,10,"lora_model_ref_in"),ge(e,10,"lora_model_id_to_load_in"),ge(e,16,"streaming_reader"),ge(e,15,"text_out"),ge(e,15,"text_end"),ge(e,15,"token_cost_out");var n=new Gn;pe(n,2,"TokenizerInputBuildCalculator"),ge(n,3,"PROMPT:text_in"),ge(n,3,"LORA_ID:lora_model_id_to_apply_in"),ge(n,4,"prompt"),Hn(e,n),pe(n=new Gn,2,"ModelDataCalculator"),ge(n,6,"MODEL_DATA:__side_packet_1"),ge(n,6,"MODEL_TYPE:model_type"),ge(n,5,"READ_DATA_FN:streaming_reader"),ge(n,3,"LORA_MODEL_SPAN:lora_model_ref_in"),ge(n,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),ge(n,4,"LORA_DATA:lora_model_data"),Hn(e,n),pe(n=new Gn,2,"Gpt2UnicodeMappingCalculator"),ge(n,5,"MODEL_TYPE:model_type"),ge(n,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Hn(e,n),pe(n=new Bn,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var r=new Nr,i=fe(t.j,2);de(r,1,i),pe(i=new kr,2,"spm_vocab_model");t:{i=ce(i),qt(r);var o=r.m,s=0|o[M];if(null==i){var a=oe(o);if(4!==se(a,o,s))break t;a.set(Fr,0)}else{const t=oe(a=o),e=se(t,a,s);4!==e&&(e&&(s=Xt(a,s,e)),t.set(Fr,4))}Xt(o,s,4,i)}return de(r,3,2),xn(n,r.j()),pe(r=new Gn,2,"TokenizerCalculator"),he(r,8,Bn,n),ge(r,5,"MODEL_DATA:__side_packet_1"),ge(r,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),ge(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(r,6,"PROCESSOR_GETTER:__input_side_1"),ge(r,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),Hn(e,r),pe(n=new Bn,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),de(r=new jr,12,3),pe(r,1,"llm.tflite"),de(r,14,0),i=Gr(fe(t.j,5)),de(r,22,i),i=ae(t.j,mr,3),ue(r,31,i),ie(i=new Pr,1,Tt(!0),!1),null!=At(Kt(t.j,6))&&(At(Kt(t.j,6))??!1)&&ie(i,1,Tt(!1),!1),ie(i,2,Tt(!0),!1),ie(i,5,Tt(!0),!1),ue(r,10,i),i=Zt(t.j,4,jt,void 0===K?2:4),re(r,29,i),i=new Or,de(o=new Lr,1,1),a=fe(t.j,2),de(o,2,a),ue(i,1,o),ue(r,20,i),xn(n,r.j()),pe(r=new Gn,2,"LlmGpuCalculator"),he(r,8,Bn,n),ge(r,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),ge(r,3,"FINISH:finish"),ge(r,3,"LORA_DATA:lora_model_data"),ge(r,5,"MODEL_DATA:__side_packet_1"),ge(r,4,"DECODED_IDS:__stream_3"),ge(r,4,"OUTPUT_END:__stream_4"),pe(n=new Mn,1,"FINISH"),ie(n,2,Tt(!0),!1),he(r,13,Mn,n),Hn(e,r),pe(n=new Gn,2,"IsPacketPresentCalculator"),ge(n,3,"__stream_4"),ge(n,4,"text_end"),Hn(e,n),pe(n=new Bn,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),r=new Ir,t=Gr(fe(t.j,5)),de(r,5,t),ge(r,4,"<eos>"),ge(r,4,"<|endoftext|>"),xn(n,r.j()),pe(t=new Gn,2,"DetokenizerCalculator"),he(t,8,Bn,n),ge(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),ge(t,5,"PROCESSOR_GETTER:__input_side_1"),ge(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(t,5,"MODEL_DATA:__side_packet_1"),ge(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),ge(t,4,"WORDS:text_out"),Hn(e,t),pe(t=new Gn,2,"TokenCostCalculator"),ge(t,3,"PROMPT:token_cost_in"),ge(t,5,"PROCESSOR_GETTER:__input_side_1"),ge(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(t,4,"NUM_TOKENS:token_cost_out"),Hn(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<fe(t.j,5)&&t.D[n].push(e)})),t.u&&0===t.B.length&&(t.A?(e.length>fe(t.j,5)&&e.pop(),t.u(e,!1)):t.u(e[0],!1)),pr(t,n)})),t.i.attachEmptyPacketListener("text_out",(e=>{pr(t,e)})),t.i.attachBoolListener("text_end",((e,n)=>{if(t.l=!1,pr(t,n),Wr(t),t.o&&(t.o.resolve(t.D.map((t=>t.join("")))),t.o=void 0),t.u)if(t.A){for(e=[],n=0;n<fe(t.j,5);n++)e.push("");t.u(e,!0)}else t.u("",!0);t.A=void 0})),t.i.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.A=void 0,pr(t,e),Wr(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.O=e,pr(t,n)})),t.P&&t.i.addStreamingReaderToInputSidePacket(t.P,"streaming_reader");const n=e.j();return t.C?.removeEventListener("uncapturederror",t.H),t.i.V().then((()=>{t.C?.addEventListener("uncapturederror",t.H),t.B.length=0,t.setGraph(new Uint8Array(n),!0),t.finishProcessing()}))}function Hr(t,e,n,r){if(t.u="function"==typeof n?n:r,t.v){if(t.A&&fe(t.j,5)>1)throw Error("Multi-response generation is not supported for converted LLM models (.task format) yet. Please use the .bin format.");if(n instanceof Vr)throw Error("LoRA is not supported for converted LLM models (.task format) yet. Please use the .bin format.");return t.i.M(e,t.s,((e,n)=>{0===t.B.length&&t.u&&(t.A?t.u([e],n):t.u(e,n))})).then((e=>(Wr(t),[e])))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.D.length=0,r=0;r<fe(t.j,5);r++)t.D[r]=[];if(r=t.F+1,t.i.addStringToStream(e,"text_in",r),n instanceof Vr){if(n.j!==t)throw t.l=!1,t.A=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 Cr,t.o.promise}var qr=class extends gr{constructor(t,e){if(super(new Rr(t,e)),this.D=[],this.v=this.l=!1,this.B=[],this.H=t=>{if((t=t.error).message.match(/exceeds the max buffer size limit/))throw Error(`Failed to run this LLM model because it requires a buffer size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);if(t.message.match(/is larger than the maximum storage buffer binding size/))throw Error(`Failed to run this LLM model because it requires a storage buffer binding size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);this.B.push(t)},this.j=new yr,_r(this.j,new Kn),this.s=new mr,ue(this.j,3,this.s),Jt(this.j,2,Ut(512)),t=this.s,!vt(2))throw U("enum");ie(t,1,2,0),de(this.s,2,40),ie(this.s,3,St(1),0),Jt(this.s,5,Ot(0)),ie(this.s,4,St(.8),0),Jt(this.j,5,Ut(1))}async K(t){if(this.l)throw Error("Cannot set options while loading or processing.");if(t.baseOptions?.modelAssetPath&&t.baseOptions?.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");let e;const n=new Promise((t=>{e=t}));if(t.baseOptions?.modelAssetPath){var r=await fetch(t.baseOptions.modelAssetPath.toString());if(!r.ok)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (${r.status})`);if(!r.body)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (no body)`);r=r.body.getReader()}else t.baseOptions?.modelAssetBuffer instanceof Uint8Array?r=function(t){return new ReadableStream({start(){},async pull(e){e.enqueue(t),e.close()}})}(t.baseOptions.modelAssetBuffer).getReader():t.baseOptions?.modelAssetBuffer instanceof ReadableStreamDefaultReader?(r=t.baseOptions.modelAssetBuffer,t.baseOptions.modelAssetBuffer=void 0):e();if(!r)throw Error("No model asset provided.");{const[t,n]=tr(r);1===await async function(t){const e=[];let n;for(const[i,o]of nr){const s=i;var r=o;[t,n]=tr(t),r=await r(n),await n.cancel(),r&&e.push(s)}if(await t.cancel(),0===e.length)throw Error("No model format matched.");if(1===e.length)return e[0];throw Error(`Multiple model formats matched: ${e}`)}(n)?(this.v=!0,r=t):(this.v=!1,this.P=function(t,e){return new Sr((async()=>{const{value:e,done:n}=await t.read();return n?void 0:e}),e)}(t,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.H),this.C=t.baseOptions.gpuOptions.device,this.i.Z(this.C),this.C.addEventListener("uncapturederror",this.H)),"maxTokens"in t&&Jt(this.j,2,Ut(t.maxTokens??512)),"topK"in t&&de(this.s,2,t.topK??40),"temperature"in t&&ie(this.s,4,St(t.temperature??.8),0),"randomSeed"in t&&Jt(this.s,5,Ot(t.randomSeed??0)),"loraRanks"in t&&function(t,e){re(t,4,e)}(this.j,t.loraRanks??[]),"numResponses"in t){const e=t.numResponses??1;if(e<1)throw Error("'numResponses' must be at least 1.");if(this.v&&e>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet.");Jt(this.j,5,Ut(e));const n=ae(this.j,mr,3);e>1&&n&&(n.j()<=1||(Kt(n,4,void 0,Et)??0)<=0)&&console.warn("To generate multiple responses, it is expected topK > 1 and temperature > 0; otherwise, all the generated responses may be the same.")}return"forceF32"in t&&Jt(this.j,6,Tt(t.forceF32)),this.v?(this.i.R(),this.i.W(r,this.j).then((()=>{Wr(this)}))):(this.l=!0,t=$r(this).then((()=>{})),Promise.all([n,t]).then((()=>{this.l=!1,Wr(this)})))}get baseOptions(){return ae(this.j,Kn,1)}set baseOptions(t){_r(this.j,t)}get isIdle(){return!this.l&&!this.o}M(t,e,n){return fe(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.A=!1,Hr(this,t,e,n).then((t=>t[0]))}Y(t,e,n){return this.A=!0,Hr(this,t,e,n)}N(t){if(this.v)return this.i.N(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");return this.l=!0,this.O=void 0,this.i.addStringToStream(t,"token_cost_in",this.F+1),this.finishProcessing(),this.l=!1,this.O}async ca(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet. Please use the old foramat (.bin) to use LoRA.");if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new Ar(this.i.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return Er(t,e.stream(),e.size)}(this.i.h,t):await async function(t,e){e=await fetch(e.toString());const n=Number(e.headers.get("content-length"));if(!e.body)throw Error("Response body is not available.");if(!n)throw Error("File size is 0.");return Er(t,e.body,n)}(this.i.h,t);e=new Vr(this);const n=this.F+1;return this.i.U(t,n),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",n),this.finishProcessing(),Tr(t),pr(this,n),this.l=!1,e}close(){this.v&&this.i.R(),this.C?.removeEventListener("uncapturederror",this.H),super.close()}};qr.prototype.loadLoraModel=qr.prototype.ca,qr.prototype.sizeInTokens=qr.prototype.N,qr.prototype.generateResponses=qr.prototype.Y,qr.prototype.generateResponse=qr.prototype.M,qr.prototype.setOptions=qr.prototype.K,qr.createWebGpuDevice=zr,qr.createFromModelPath=async function(t,e){return fr(t,e={baseOptions:{gpuOptions:{device:await zr()},modelAssetPath:e}})},qr.createFromModelBuffer=async function(t,e){return fr(t,e={baseOptions:{gpuOptions:{device:await zr()},modelAssetBuffer:e}})},qr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await zr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return fr(t,e)};export{Qn as FilesetResolver,qr as LlmInference,gr as TaskRunner};
2
2
  //# sourceMappingURL=genai_bundle_mjs.js.map