@mediapipe/tasks-genai 0.10.28 → 0.10.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/genai.d.ts +11 -0
- package/genai_bundle.cjs +1 -1
- package/genai_bundle.cjs.map +1 -1
- package/genai_bundle.js +1 -1
- package/genai_bundle.mjs +1 -1
- package/genai_bundle.mjs.map +1 -1
- package/package.json +2 -2
- package/wasm/genai_wasm_internal.js +247 -242
- package/wasm/genai_wasm_internal.wasm +0 -0
- package/wasm/genai_wasm_module_internal.js +247 -242
- package/wasm/genai_wasm_module_internal.wasm +0 -0
- package/wasm/genai_wasm_nosimd_internal.js +247 -242
- package/wasm/genai_wasm_nosimd_internal.wasm +0 -0
package/genai_bundle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GenAI=function(t){"use strict";var e="undefined"!=typeof self?self:{};function r(t,r){t:{for(var n=["CLOSURE_FLAGS"],i=e,o=0;o<n.length;o++)if(null==(i=i[n[o]])){n=null;break t}n=i}return null!=(t=n&&n[t])?t:r}var n,i="undefined"!=typeof TextEncoder;function o(t){if(i)t=(n||=new TextEncoder).encode(t);else{let r=0,n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var e=t.charCodeAt(i);if(e<128)n[r++]=e;else{if(e<2048)n[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&i<t.length){let o=t.charCodeAt(++i);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}i--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var a=r(610401301,!1),s=r(748402147,!0);function l(){var t=e.navigator;return t&&(t=t.userAgent)?t:""}var u,h=e.navigator;u=h&&h.userAgentData||null;var c={},f=null;function d(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var n=new Uint8Array(r),i=0;return function(t,e){function r(e){for(;n<t.length;){let e=t.charAt(n++),r=f[e];if(null!=r)return r;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}p();for(var n=0;;){let t=r(-1),n=r(0),i=r(64),o=r(64);if(64===o&&-1===t)break;e(t<<2|n>>4),64!=i&&(e(n<<4&240|i>>2),64!=o&&e(i<<6&192|o))}}(t,function(t){n[i++]=t}),i!==r?n.subarray(0,i):n}function p(){if(!f){f={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=t.concat(e[r].split(""));c[r]=n;for(let t=0;t<n.length;t++){let e=n[t];void 0===f[e]&&(f[e]=t)}}}}var m="undefined"!=typeof Uint8Array,g=!(!(a&&u&&u.brands.length>0)&&(-1!=l().indexOf("Trident")||-1!=l().indexOf("MSIE")))&&"function"==typeof btoa,v=/[-_.]/g,_={"-":"+",_:"/",".":"="};function y(t){return _[t]||""}function w(t){if(!g)return d(t);t=v.test(t)?t.replace(v,y):t,t=atob(t);var e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function b(t){return m&&null!=t&&t instanceof Uint8Array}var S={};function A(){return E||=new I(null,S)}var E,I=class{constructor(t,e){if(T(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function T(t){if(t!==S)throw Error("illegal external caller")}function L(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}var P=void 0;function O(t){return L(t=Error(t),"warning"),t}function j(t,r){if(null!=t){var n=P??={},i=n[t]||0;i>=r||(n[t]=i+1,L(t=Error(),"incident"),function(t){e.setTimeout(()=>{throw t},0)}(t))}}function k(){return"function"==typeof BigInt}var U="function"==typeof Symbol&&"symbol"==typeof Symbol();function x(t,e,r=!1){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?r&&Symbol.for&&t?Symbol.for(t):null!=t?Symbol(t):Symbol():e}var B,N=x("jas",void 0,!0),F=x(void 0,"1oa"),R=x(void 0,"0ubsb"),D=x(void 0,"0actk"),M=x("m_m","qa",!0),C={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},V=Object.defineProperties,G=U?N:"ha",z=[];function W(t,e){U||G in t||V(t,C),t[G]|=e}function H(t,e){U||G in t||V(t,C),t[G]=e}H(z,7),B=Object.freeze(z);var $={};function q(t,e){return void 0===e?t.i!==K&&!!(2&t.m[G]):!!(2&e)&&t.i!==K}var K={},Y=Object.freeze({});function J(t){return t.pa=!0,t}var X=J(t=>"number"==typeof t),Q=J(t=>"string"==typeof t),Z=J(t=>"boolean"==typeof t),tt="function"==typeof e.BigInt&&"bigint"==typeof e.BigInt(0),et=J(t=>tt?t>=nt&&t<=ot:"-"===t[0]?at(t,rt):at(t,it)),rt=Number.MIN_SAFE_INTEGER.toString(),nt=tt?BigInt(Number.MIN_SAFE_INTEGER):void 0,it=Number.MAX_SAFE_INTEGER.toString(),ot=tt?BigInt(Number.MAX_SAFE_INTEGER):void 0;function at(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){let n=t[r],i=e[r];if(n>i)return!1;if(n<i)return!0}}var st,lt=0,ut=0;function ht(t){var e=t>>>0;lt=e,ut=(t-e)/4294967296>>>0}function ct(t){if(t<0){ht(-t);let[e,r]=gt(lt,ut);lt=e>>>0,ut=r>>>0}else ht(t)}function ft(t,e){var r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:dt(t,e)}function dt(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else k()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,t>=1e7&&(r+=t/1e7>>>0,t%=1e7),r>=1e7&&(e+=r/1e7>>>0,r%=1e7),r=e+pt(r)+pt(t));return r}function pt(t){return t=String(t),"0000000".slice(t.length)+t}function mt(t){if(t.length<16)ct(Number(t));else if(k())t=BigInt(t),lt=Number(t&BigInt(4294967295))>>>0,ut=Number(t>>BigInt(32)&BigInt(4294967295));else{let e=+("-"===t[0]);ut=lt=0;let r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){let e=Number(t.slice(n,i));ut*=1e6,(lt=1e6*lt+e)>=4294967296&&(ut+=Math.trunc(lt/4294967296),ut>>>=0,lt>>>=0)}if(e){let[t,e]=gt(lt,ut);lt=t,ut=e}}}function gt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function vt(t){return Array.prototype.slice.call(t)}var _t="function"==typeof BigInt?BigInt.asIntN:void 0,yt="function"==typeof BigInt?BigInt.asUintN:void 0,wt=Number.isSafeInteger,bt=Number.isFinite,St=Math.trunc;function At(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 It(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 Tt(t){return null==t||"boolean"==typeof t?t:"number"==typeof t?!!t:void 0}var Lt,Pt,Ot,jt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function kt(t){switch(typeof t){case"bigint":return!0;case"number":return bt(t);case"string":return jt.test(t);default:return!1}}function Ut(t){if("number"!=typeof t)throw O("int32");if(!bt(t))throw O("int32");return 0|t}function xt(t){return null==t?t:Ut(t)}function Bt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return bt(t)?0|t:void 0}function Nt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return bt(t)?t>>>0:void 0}function Ft(t){return null==t||"string"==typeof t?t:void 0}function Rt(t,e,r){if(null!=t&&t[M]===$)return t;if(Array.isArray(t)){var n=0|t[G];return(r=n|32&r|2&r)!==n&&H(t,r),new e(t)}}function Dt(t){return t}function Mt(t,e,r,n){var i=void 0!==n;n=!!n;var o=[],a=t.length,s=4294967295,l=!1,u=!!(64&e),h=u?128&e?0:-1:void 0;if(!(1&e)){var c=a&&t[a-1];null!=c&&"object"==typeof c&&c.constructor===Object?s=--a:c=void 0,!u||128&e||i||(l=!0,s=(Lt??Dt)(s-h,h,t,c,void 0)+h)}for(e=void 0,i=0;i<a;i++){let a=t[i];if(null!=a&&null!=(a=r(a,n)))if(u&&i>=s){let t=i-h;(e??={})[t]=a}else o[i]=a}if(c)for(let i in c){if(null==(t=c[i])||null==(t=r(t,n)))continue;let l;a=+i,u&&!Number.isNaN(a)&&(l=a+h)<s?o[l]=t:(e??={})[i]=t}return e&&(l?o.push(e):o[s]=e),o}function Ct(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return et(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[G];return 0===t.length&&1&e?void 0:Mt(t,e,Ct)}if(null!=t&&t[M]===$)return Vt(t);if(t instanceof I){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(g){for(var r="",n=0,i=e.length-10240;n<i;)r+=String.fromCharCode.apply(null,e.subarray(n,n+=10240));r+=String.fromCharCode.apply(null,n?e.subarray(n):e),e=btoa(r)}else{void 0===r&&(r=0),p(),r=c[r],n=Array(Math.floor(e.length/3)),i=r[64]||"";let t=0,u=0;for(;t<e.length-2;t+=3){var o=e[t],a=e[t+1],s=e[t+2],l=r[o>>2];o=r[(3&o)<<4|a>>4],a=r[(15&a)<<2|s>>6],s=r[63&s],n[u++]=l+o+a+s}switch(l=0,s=i,e.length-t){case 2:s=r[(15&(l=e[t+1]))<<2]||i;case 1:e=e[t],n[u]=r[e>>2]+r[(3&e)<<4|l>>4]+s+i}e=n.join("")}t=t.i=e}return t}return}return t}function Vt(t){return Mt(t=t.m,0|t[G],Ct)}function Gt(t,e,r,n=0){if(null==t){var i=32;r?(t=[r],i|=128):t=[],e&&(i=-16760833&i|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(i=0|t[G],s&&1&i)throw Error("rfarr");if(2048&i&&!(2&i)&&function(){if(s)throw Error("carr");j(D,5)}(),256&i)throw Error("farr");if(64&i)return(i|n)!==i&&H(t,i|n),t;if(r&&(i|=128,r!==t[0]))throw Error("mid");t:{i|=64;var o=(r=t).length;if(o){var a=o-1;let t=r[a];if(null!=t&&"object"==typeof t&&t.constructor===Object){if((a-=e=128&i?0:-1)>=1024)throw Error("pvtlmt");for(var l in t)(o=+l)<a&&(r[o+e]=t[l],delete t[l]);i=-16760833&i|(1023&a)<<14;break t}}if(e){if((l=Math.max(e,o-(128&i?0:-1)))>1024)throw Error("spvt");i=-16760833&i|(1023&l)<<14}}}return H(t,64|i|n),t}function zt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var r=0|t[G];return 0===t.length&&1&r?t=void 0:2&r||(!e||4096&r||16&r?t=Ht(t,r,!1,e&&!(16&r)):(W(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[M]===$?q(t,r=0|(e=t.m)[G])?t:Yt(t,e,r)?Wt(t,e):Ht(e,r):t instanceof I?t:void 0}function Wt(t,e,r){return t=new t.constructor(e),r&&(t.i=K),t.o=K,t}function Ht(t,e,r,n){return n??=!!(34&e),t=Mt(t,e,zt,n),n=32,r&&(n|=2),H(t,e=16769217&e|n),t}function $t(t){if(t.i!==K)return!1;var e=t.m;return W(e=Ht(e,0|e[G]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function qt(t){if(!$t(t)&&q(t,0|t.m[G]))throw Error()}function Kt(t,e){void 0===e&&(e=0|t[G]),32&e&&!(4096&e)&&H(t,4096|e)}function Yt(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(H(e,2|r),t.i=K,!0)}function Jt(t,e,r){if(null!==(t=Xt(t.m,e,void 0,r)))return t}function Xt(t,e,r,n){if(-1===e)return null;var i=e+(r?0:-1),o=t.length-1;if(!(o<1+(r?0:-1))){if(i>=o){var a=t[o];if(null!=a&&"object"==typeof a&&a.constructor===Object){r=a[e];var s=!0}else{if(i!==o)return;r=a}}else r=t[i];if(n&&null!=r){if(null==(n=n(r)))return n;if(!Object.is(n,r))return s?a[e]=n:t[i]=n,n}return r}}function Qt(t,e,r){qt(t),Zt(t=t.m,0|t[G],e,r)}function Zt(t,e,r,n,i){var o=r+(i?0:-1),a=t.length-1;if(a>=1+(i?0:-1)&&o>=a){let i=t[a];if(null!=i&&"object"==typeof i&&i.constructor===Object)return i[r]=n,e}return o<=a?(t[o]=n,e):(void 0!==n&&(r>=(a=(e??=0|t[G])>>14&1023||536870912)?null!=n&&(t[a+(i?0:-1)]={[r]:n}):t[o]=n),e)}function te(t,e,r,n,i){var o=t.m,a=0|o[G];n=q(t,a)?1:n,i=!!i||3===n,2===n&&$t(t)&&(a=0|(o=t.m)[G]);var s=(t=re(o,e))===B?7:0|t[G],l=ne(s,a),u=!(4&l);if(u){4&l&&(t=vt(t),s=0,l=fe(l,a),a=Zt(o,a,e,t));let n=0,i=0;for(;n<t.length;n++){let e=r(t[n]);null!=e&&(t[i++]=e)}i<n&&(t.length=i),r=-513&l|4,l=r&=-1025,l&=-4097}return l!==s&&(H(t,l),2&l&&Object.freeze(t)),ee(t,l,o,a,e,n,u,i)}function ee(t,e,r,n,i,o,a,s){var l=e;return 1===o||4===o&&(2&e||!(16&e)&&32&n)?ie(e)||((e|=!t.length||a&&!(4096&e)||32&n&&!(4096&e||16&e)?2:256)!==l&&H(t,e),Object.freeze(t)):(2===o&&ie(e)&&(t=vt(t),l=0,e=fe(e,n),n=Zt(r,n,i,t)),ie(e)||(s||(e|=16),e!==l&&H(t,e))),2&e||!(4096&e||16&e)||Kt(r,n),t}function re(t,e,r){return t=Xt(t,e,r),Array.isArray(t)?t:B}function ne(t,e){return 2&e&&(t|=2),1|t}function ie(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function oe(t,e,r){qt(t);var n=0|(t=t.m)[G];if(null==r)Zt(t,n,e);else{var i=r===B?7:0|r[G],o=i,a=ie(i),s=a||Object.isFrozen(r);for(a||(i=0),s||(r=vt(r),o=0,i=fe(i,n),s=!1),i|=5,i|=(4&i?512&i?512:1024&i?1024:0:void 0)??1024,a=0;a<r.length;a++){let t=r[a],e=Ut(t);Object.is(t,e)||(s&&(r=vt(r),o=0,i=fe(i,n),s=!1),r[a]=e)}i!==o&&(s&&(r=vt(r),i=fe(i,n)),H(r,i)),Zt(t,n,e,r)}}function ae(t,e,r,n){qt(t),Zt(t=t.m,0|t[G],e,("0"===n?0===Number(r):r===n)?void 0:r)}function se(t){if(U)return t[F]??(t[F]=new Map);if(F in t)return t[F];var e=new Map;return Object.defineProperty(t,F,{value:e}),e}function le(t,e,r){var n=hi,i=t.get(n);if(null!=i)return i;i=0;for(let t=0;t<n.length;t++){let o=n[t];null!=Xt(e,o)&&(0!==i&&(r=Zt(e,r,i)),i=o)}return t.set(n,i),i}function ue(t,e,r){var n=t.m,i=0|n[G];if(e=function(t,e,r,n){var i=!1;if(null!=(n=Xt(t,n,void 0,t=>{var n=Rt(t,r,e);return i=n!==t&&null!=n,n})))return i&&!q(n)&&Kt(t,e),n}(n,i,e,r),null==e)return e;if(!q(t,i=0|n[G])){var o,a=e;let s=a.m,l=0|s[G];(o=q(a,l)?Yt(a,s,l)?Wt(a,s,!0):new a.constructor(Ht(s,l,!1)):a)!==e&&($t(t)&&(i=0|(n=t.m)[G]),Kt(n,i=Zt(n,i,r,e=o)))}return e}function he(t){return null==t&&(t=void 0),t}function ce(t,e,r){return Qt(t,e,r=he(r)),r&&!q(r)&&Kt(t.m),t}function fe(t,e){return-273&(2&e?2|t:-3&t)}function de(t,e,r,n){var i=n;qt(t);var o=n=t.m,a=0|n[G],s=q(t,a)?1:2;2===s&&$t(t)&&(a=0|(o=t.m)[G]);var l=(t=re(o,e))===B?7:0|t[G],u=ne(l,a),h=!(4&u);if(h){var c=t,f=a;let e=!!(2&u);e&&(f|=2);let n=!e,i=!0,o=0,s=0;for(;o<c.length;o++){let t=Rt(c[o],r,f);if(t instanceof r){if(!e){let e=q(t);n&&=!e,i&&=e}c[s++]=t}}s<o&&(c.length=s),u|=4,u=i?-4097&u:4096|u,u=n?8|u:-9&u}u!==l&&(H(t,u),2&u&&Object.freeze(t)),e=t=ee(t,u,o,a,e,s,h,!0),i=null!=i?i:new r,e.push(i),o=r=e===B?7:0|e[G],(i=q(i))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&H(e,r),i||Kt(n)}function pe(t,e){return Nt(Jt(t,e))??0}function me(t,e,r){ae(t,e,xt(r),0)}function ge(t,e,r){if(null!=r){if("number"!=typeof r)throw O("uint32");if(!bt(r))throw O("uint32");r>>>=0}Qt(t,e,r)}function ve(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();ae(t,e,r,"")}function _e(t,e,r){if(qt(t),e=(t=te(t,e,Ft,2,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}var ye=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function we(t){if("string"==typeof t)return new ye(w(t),!0);if(Array.isArray(t))return new ye(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new ye(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new ye(t,!1);if(t.constructor===I){T(S);var e=t.i;return e=(null==(e=null==e||b(e)?e:"string"==typeof e?w(e):null)?e:t.i=e)||new Uint8Array(0),new ye(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new ye(t,!1);throw Error()}function be(t){return new Ee(4294967295&t,Math.floor(t/4294967296))}function Se(t){return t?/^\d+$/.test(t)?(mt(t),new Ee(lt,ut)):null:Ae||=new Ee(0,0)}var Ae,Ee=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Ie(t){return new Ne(4294967295&t,Math.floor(t/4294967296))}function Te(t){return t?/^-?\d+$/.test(t)?(mt(t),new Ne(lt,ut)):null:Le||=new Ne(0,0)}var Le,Pe,Oe,je,ke,Ue,xe,Be,Ne=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Fe(t,e,r){return"undefined"!=typeof BigInt64Array?(xe||(xe=new BigInt64Array(1),Be=new Uint32Array(xe.buffer),xe[0]=BigInt(1),Ue=1===Be[0]),xe[0]=t,new e(Be[t=Ue?0:1],Be[1-t])):(ke||(Pe=BigInt(Number.MIN_SAFE_INTEGER),Oe=BigInt(Number.MAX_SAFE_INTEGER),je=BigInt(4294967295),ke=BigInt(32)),t>=Pe&&t<=Oe?r(Number(t)):(t=BigInt.asUintN(64,t),new e(Number(t&je),Number(t>>ke))))}function Re(t,e,r){for(;r>0||e>127;)t.i.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.i.push(e)}function De(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Me(t,e){if(e>=0)De(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}var Ce=class{constructor(){this.i=[]}length(){return this.i.length}end(){var t=this.i;return this.i=[],t}};function Ve(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Ge(t,e,r){De(t.i,8*e+r)}function ze(t,e){return Ge(t,e,2),e=t.i.end(),Ve(t,e),e.push(t.j),e}function We(t,e){var r=e.pop();for(r=t.j+t.i.length()-r;r>127;)e.push(127&r|128),r>>>=7,t.j++;e.push(r),t.j++}function He(t,e,r){Ge(t,e,2),De(t.i,r.length),Ve(t,t.i.end()),Ve(t,r)}var $e=class{constructor(){this.l=[],this.j=0,this.i=new Ce}};function qe(){var t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Ke=qe(),Ye=qe(),Je=qe(),Xe=qe(),Qe=qe(),Ze=qe(),tr=qe(),er=qe(),rr=qe(),nr=qe(),ir=class{constructor(t,e){this.m=Gt(t,e,void 0,2048)}toJSON(){return Vt(this)}};ir.prototype[M]=$,ir.prototype.toString=function(){return this.m.toString()};var or=class{constructor(t,e){this.i=t,t=Ke,this.j=!!t&&e===t||!1}};function ar(t,e,r,n,i){null!=(e=pr(e,n))&&(r=ze(t,r),i(e,t),We(t,r))}var sr,lr,ur=new or(ar,Ke),hr=new or(ar,Ke),cr=Symbol(),fr=Symbol();function dr(t){var e=mr,r=gr,n=t[cr];if(n)return n;(n={}).oa=t,n.W=function(t){switch(typeof t){case"boolean":return Pt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Ot||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);var i=t[1],o=1;i&&i.constructor===Object&&(n.ca=i,"function"==typeof(i=t[++o])&&(n.ia=!0,sr??=i,lr??=t[o+1],i=t[o+=2]));for(var a={};i&&Array.isArray(i)&&i.length&&"number"==typeof i[0]&&i[0]>0;){for(var s=0;s<i.length;s++)a[i[s]]=i;i=t[++o]}for(s=1;void 0!==i;){let h;"number"==typeof i&&(s+=i,i=t[++o]);var l=void 0;if(i instanceof or?h=i:(h=ur,o--),h?.j){i=t[++o],l=t;var u=o;"function"==typeof i&&(i=i(),l[u]=i),l=i}for(u=s+1,"number"==typeof(i=t[++o])&&i<0&&(u-=i,i=t[++o]);s<u;s++){let t=a[s];l?r(n,s,h,l,t):e(n,s,h,t)}}return t[cr]=n}function pr(t,e){return t instanceof ir?t.m:Array.isArray(t)?Gt(t,e[0],e[1]):void 0}function mr(t,e,r){t[e]=r.i}function gr(t,e,r,n){var i,o,a=r.i;t[e]=(t,e,r)=>a(t,e,r,o||=dr(n).W,i||=vr(n))}function vr(t){var e=t[fr];if(!e){let r=dr(t);e=(t,e)=>_r(t,e,r),t[fr]=e}return e}function _r(t,e,r){!function(t,e,r){var n,i=128&e?0:-1,o=t.length;(n=!!o)&&(n=null!=(n=t[o-1])&&"object"==typeof n&&n.constructor===Object);var a=o+(n?-1:0);for(e=128&e?1:0;e<a;e++)r(e-i,t[e]);if(n){t=t[o-1];for(let e in t)!isNaN(e)&&r(+e,t[e])}}(t,0|t[G],(t,n)=>{if(null!=n){var i=function(t,e){var r=t[e];if(r)return r;if((r=t.ca)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof or?r:[hr,r]:[r,void 0])[0].i;if(r=r[1]){let e=vr(r),i=dr(r).W;r=t.ia?lr(i,e):(t,r,o)=>n(t,r,o,i,e)}else r=n;return t[e]=r}}(r,t);i?i(e,n,t):t<500||j(R,3)}})}var yr,wr=0,br=wr;if(Q(br)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(br))throw Error(String(br))}else if((yr=X(br))&&(yr=!Number.isSafeInteger(br)),yr)throw Error(String(br));function Sr(t,e){if(Array.isArray(e)){var r=0|e[G];if(4&r)return e;for(var n=0,i=0;n<e.length;n++){let r=t(e[n]);null!=r&&(e[i++]=r)}return i<n&&(e.length=i),(t=-1537&r|5)!==r&&H(e,t),2&t&&Object.freeze(e),e}}function Ar(t,e){return new or(t,e)}function Er(t,e,r){null!=(e=Et(e))&&(Ge(t,r,5),t=t.i,(r=st||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ut=0,e=lt=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))}function Ir(t,e,r){null!=(e=Bt(e))&&null!=e&&(Ge(t,r,0),Me(t.i,e))}function Tr(t,e,r){null!=(e=Tt(e))&&(Ge(t,r,0),t.i.i.push(e?1:0))}function Lr(t,e,r){null!=(e=Ft(e))&&He(t,r,o(e))}function Pr(t,e,r,n,i){null!=(e=pr(e,n))&&(r=ze(t,r),i(e,t),We(t,r))}function Or(t,e,r){null!=(e=Nt(e))&&null!=e&&(Ge(t,r,0),De(t.i,e))}function jr(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),Ge(t,r,0),Me(t.i,e))}tt||(wr=Z(wr)?wr?"1":"0":Q(wr)?wr.trim()||"0":String(wr));var kr,Ur=Ar(Er,er),xr=Ar(Er,er),Br=Ar(function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(_t(64,t));if(kt(t)){if("string"===e){if(e=St(Number(t)),wt(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),e=t.length,!("-"===t[0]?e<20||20===e&&t<="-9223372036854775808":e<19||19===e&&t<="9223372036854775807"))if(mt(t),t=lt,2147483648&(e=ut))if(k())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,n]=gt(t,e);t="-"+dt(r,n)}else t=dt(t,e);return t}if("number"===e){if(t=St(t),!wt(t)){ct(t),e=lt;var r=ut;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),t="number"==typeof(e=ft(e,r))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)Te(e);if(null!=e)switch(Ge(t,r,0),typeof e){case"number":t=t.i,ct(e),Re(t,lt,ut);break;case"bigint":r=Fe(e,Ne,Ie),Re(t.i,r.j,r.i);break;default:r=Te(e),Re(t.i,r.j,r.i)}}},Ze),Nr=Ar(function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(yt(64,t));if(kt(t)){if("string"===e)return e=St(Number(t)),wt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),(e="-"!==t[0]&&((e=t.length)<20||20===e&&t<="18446744073709551615"))||(mt(t),t=dt(lt,ut))),t;if("number"===e)return(t=St(t))>=0&&wt(t)||(ct(t),t=ft(lt,ut)),t}}(e),null!=e){if("string"==typeof e)Se(e);if(null!=e)switch(Ge(t,r,0),typeof e){case"number":t=t.i,ct(e),Re(t,lt,ut);break;case"bigint":r=Fe(e,Ee,be),Re(t.i,r.j,r.i);break;default:r=Se(e),Re(t.i,r.j,r.i)}}},tr),Fr=Ar(Ir,Xe);kr=new or(function(t,e,r){if(null!=(e=Sr(Bt,e))&&e.length){r=ze(t,r);for(let r=0;r<e.length;r++)Me(t.i,e[r]);We(t,r)}},Xe);var Rr,Dr=Ar(Ir,Xe),Mr=Ar(Ir,Xe),Cr=Ar(Tr,Ye),Vr=Ar(Tr,Ye),Gr=Ar(Lr,Je);Rr=new or(function(t,e,r){if(null!=(e=Sr(Ft,e)))for(let s=0;s<e.length;s++){var n=t,i=r,a=e[s];null!=a&&He(n,i,o(a))}},Je);var zr,Wr=Ar(Lr,Je),Hr=Ar(Lr,Je),$r=function(t,e,r=Ke){return new or(e,r)}(0,function(t,e,r,n,i){if(Array.isArray(e)){for(let o=0;o<e.length;o++)Pr(t,e[o],r,n,i);1&(t=0|e[G])||H(e,1|t)}}),qr=new or(Pr,Ke),Kr=Ar(Or,Qe),Yr=Ar(jr,nr);zr=new or(function(t,e,r){if(null!=(e=Sr(Bt,e))&&e.length){r=ze(t,r);for(let r=0;r<e.length;r++)Me(t.i,e[r]);We(t,r)}},nr);var Jr=Ar(jr,nr);function Xr(t){return function(){var e=new $e;_r(this.m,e,dr(t)),Ve(e,e.i.end());var r=new Uint8Array(e.j),n=e.l,i=n.length,o=0;for(let t=0;t<i;t++){let e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function Qr(t,e){if(null!=e)if(Array.isArray(e))Qt(t,2,Mt(e,0,Ct));else{if(!("string"==typeof e||e instanceof I||b(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,S):A();else if(e.constructor!==I){if(!b(e))throw Error();e=e.length?new I(new Uint8Array(e),S):A()}ae(t,2,e,A())}}var Zr,tn=class extends ir{constructor(t){super(t)}},en=[0,Wr,Ar(function(t,e,r){if(null!=e){if(e instanceof ir){let n=e.ra;return void(n?(e=n(e),null!=e&&He(t,r,we(e).buffer)):j(R,3))}if(Array.isArray(e))return void j(R,3)}null!=(e=null==e||"string"==typeof e||e instanceof I?e:void 0)&&He(t,r,we(e).buffer)},rr)],rn=globalThis.trustedTypes;var nn=class{constructor(t){this.i=t}toString(){return this.i+""}};function on(t){var e;return void 0===Zr&&(Zr=function(){var t=null;if(!rn)return t;try{let e=t=>t;t=rn.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=Zr)?e.createScriptURL(t):t,new nn(t)}function an(t,...e){if(0===e.length)return on(t[0]);var r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return on(r)}var sn=[0,Yr,-1,Cr],ln={};ln[336783863]=[0,Gr,Cr,-1,Fr,[0,[1,2,3,4,5,6,7,8,9],qr,[0],qr,[0,Cr,Gr,Cr,Yr,-1,zr,Gr,-1,[0,Cr,-1],Yr,Cr,-1,sn],qr,[0,Gr,-2],qr,[0,Fr,Cr,1,Cr,-4],qr,[0,Fr,Yr,Cr,-1,kr,Yr,-1,Cr,-1],qr,[0,Gr,-2],qr,[0,Gr,Yr],qr,[0,3,Cr,-1,2,[0,[2],Fr,qr,[0,Ar(Or,Qe)]],[0,Yr,Cr,Yr,Cr,Yr,Cr,Gr,-1],[0,[3,4],Gr,-1,qr,[0,Fr],qr,[0,Yr]],[0]],qr,sn],[0,Gr],Cr,[0,[1,3],[2,4],qr,[0,kr],-1,qr,[0,Rr],-1,$r,[0,Gr,-1]],Gr];var un=class extends ir{constructor(t){super(t)}},hn=[0,Br,-1,Vr,-3,Br,kr,Wr,Dr,Br,-1,Vr,Dr,Vr,-2,Wr],cn=class extends ir{constructor(t){super(t,500)}N(t){return ce(this,7,t)}},fn=[-1,{}],dn=[0,Gr,1,fn],pn=[0,Gr,Rr,fn];function mn(t,e){de(t,1,cn,e)}var gn=class extends ir{constructor(t){super(t,500)}N(t){return ce(this,1001,t)}};gn.prototype.j=Xr([-500,$r,[-500,Wr,-1,Rr,-3,[-2,ln,Cr],$r,en,Dr,-1,dn,pn,$r,[0,Wr,Vr],Wr,hn,Dr,Rr,987,Rr],4,$r,[-500,Gr,-1,[-1,{}],998,Gr],$r,[-500,Gr,Rr,-1,[-2,{},Cr],997,Rr,-1],Dr,$r,[-500,Gr,Rr,fn,998,Rr],Rr,Dr,dn,pn,$r,[0,Wr,-1,fn],Rr,-2,hn,Wr,-1,Vr,[0,Vr,Kr],978,fn,$r,en]);var vn,_n=class extends ir{constructor(t){super(t)}},yn=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 wn(t){if(t)return!0;if(void 0===vn)try{await WebAssembly.instantiate(yn),vn=!0}catch{vn=!1}return vn}async function bn(t,e,r){return{wasmLoaderPath:`${e}/${t}_${r=`wasm${r?"_module":""}${await wn(r)?"":"_nosimd"}_internal`}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var Sn=class{};Sn.forVisionTasks=function(t,e=!1){return bn("vision",t??an``,e)},Sn.forTextTasks=function(t,e=!1){return bn("text",t??an``,e)},Sn.forGenAiTasks=function(t,e=!1){return bn("genai",t??an``,e)},Sn.forAudioTasks=function(t,e=!1){return bn("audio",t??an``,e)},Sn.isSimdSupported=function(t=!1){return wn(t)};var An=class{close(){}};function En(t){function e(e,r){return new ReadableStream({start(){},async pull(n){i=i.then(async()=>{if(e.cache.length>0)n.enqueue(e.cache.shift());else{var{value:i,done:o}=await t.read();i&&(r.active&&r.cache.push(i),e.active&&n.enqueue(i)),o&&n.close()}}),await i},cancel(){e.active=!1,e.cache.length=0,r.active||t.cancel()}})}var r={cache:[],active:!0},n={cache:[],active:!0},i=Promise.resolve(),o=e(r,n);return r=e(n,r),[o.getReader(),r.getReader()]}async function In(t,e){for(var r=new Uint8Array(e),n=0;n<e;){let{value:i,done:o}=await t.read();if(i){let t=i.subarray(0,e-n);r.set(t,n),n+=t.length}if(o)throw Error(`Expected ${e} bytes, but stream ended after reading ${n} bytes.`)}return await t.cancel(),r}var Tn=[[0,async t=>{var e=(new TextEncoder).encode("TFL3").length;return t=await In(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await In(t,6))[4]&&75===t[5]]];function Ln(){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 Pn(t){if("function"!=typeof importScripts){let e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise((t,r)=>{e.addEventListener("load",()=>{t()},!1),e.addEventListener("error",t=>{r(t)},!1),document.body.appendChild(e)})}try{importScripts(t.toString())}catch(e){if(!(e instanceof TypeError))throw e;{let e=self.import;e?await e(t.toString()):await import(t.toString())}}}function On(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function jn(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");var n=new Uint32Array(e.length);for(let r=0;r<e.length;r++)n[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*n.length),t.h.HEAPU32.set(n,e>>2),r(e);for(let e of n)t.h._free(e);t.h._free(e)}function kn(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function Un(t,e,r){var n=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(r(n,i),n=[]):n.push(t)}}var xn,Bn=(xn=class{constructor(t,e){this.l=!0,this.h=t,this.i=null,this.j=0,this.o="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:Ln()?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){var 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){var r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),On(this,n||"input_audio",n=>{On(this,i=i||"audio_header",i=>{this.h._configureAudio(n,i,t,e??0,r)})})}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,i){var o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),On(this,n,t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)})}addGpuBufferToStream(t,e,r){On(this,e,e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();var n=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!n)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1);var[i,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||i===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=i,this.h.canvas.height=o);var[a,s]=[i,o];this.h._addBoundTextureToStream(e,a,s,r)})}addBoolToStream(t,e,r){On(this,e,e=>{this.h._addBoolToInputStream(t,e,r)})}addDoubleToStream(t,e,r){On(this,e,e=>{this.h._addDoubleToInputStream(t,e,r)})}addFloatToStream(t,e,r){On(this,e,e=>{this.h._addFloatToInputStream(t,e,r)})}addIntToStream(t,e,r){On(this,e,e=>{this.h._addIntToInputStream(t,e,r)})}addUintToStream(t,e,r){On(this,e,e=>{this.h._addUintToInputStream(t,e,r)})}addStringToStream(t,e,r){On(this,e,e=>{On(this,t,t=>{this.h._addStringToInputStream(t,e,r)})})}addStringRecordToStream(t,e,r){On(this,e,e=>{jn(this,Object.keys(t),n=>{jn(this,Object.values(t),i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)})})})}addProtoToStream(t,e,r,n){On(this,r,r=>{On(this,e,e=>{var i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputStream(i,t.length,e,r,n),this.h._free(i)})})}addEmptyPacketToStream(t,e){On(this,t,t=>{this.h._addEmptyPacketToInputStream(t,e)})}addBoolVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputStream(n,e,r)})}addDoubleVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputStream(n,e,r)})}addFloatVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputStream(n,e,r)})}addIntVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)})}addUintVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputStream(n,e,r)})}addStringVectorToStream(t,e,r){On(this,e,e=>{var n=this.h._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(let e of t)On(this,e,t=>{this.h._addStringVectorEntry(n,t)});this.h._addStringVectorToInputStream(n,e,r)})}addBoolToInputSidePacket(t,e){On(this,e,e=>{this.h._addBoolToInputSidePacket(t,e)})}addDoubleToInputSidePacket(t,e){On(this,e,e=>{this.h._addDoubleToInputSidePacket(t,e)})}addFloatToInputSidePacket(t,e){On(this,e,e=>{this.h._addFloatToInputSidePacket(t,e)})}addIntToInputSidePacket(t,e){On(this,e,e=>{this.h._addIntToInputSidePacket(t,e)})}addUintToInputSidePacket(t,e){On(this,e,e=>{this.h._addUintToInputSidePacket(t,e)})}addStringToInputSidePacket(t,e){On(this,e,e=>{On(this,t,t=>{this.h._addStringToInputSidePacket(t,e)})})}addProtoToInputSidePacket(t,e,r){On(this,r,r=>{On(this,e,e=>{var n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputSidePacket(n,t.length,e,r),this.h._free(n)})})}addBoolVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)})}addDoubleVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)})}addFloatVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)})}addIntVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)})}addUintVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)})}addStringVectorToInputSidePacket(t,e){On(this,e,e=>{var r=this.h._allocateStringVector(t.length);if(!r)throw Error("Unable to allocate new string vector on heap.");for(let e of t)On(this,e,t=>{this.h._addStringVectorEntry(r,t)});this.h._addStringVectorToInputSidePacket(r,e)})}attachBoolListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachBoolListener(t)})}attachBoolVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachBoolVectorListener(t)})}attachIntListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachIntListener(t)})}attachIntVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachIntVectorListener(t)})}attachUintListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachUintListener(t)})}attachUintVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachUintVectorListener(t)})}attachDoubleListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachDoubleListener(t)})}attachDoubleVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachDoubleVectorListener(t)})}attachFloatListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachFloatListener(t)})}attachFloatVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachFloatVectorListener(t)})}attachStringListener(t,e){kn(this,t,e),On(this,t,t=>{this.h._attachStringListener(t)})}attachStringVectorListener(t,e){Un(this,t,e),On(this,t,t=>{this.h._attachStringVectorListener(t)})}attachProtoListener(t,e,r){kn(this,t,e),On(this,t,t=>{this.h._attachProtoListener(t,r||!1)})}attachProtoVectorListener(t,e,r){Un(this,t,e),On(this,t,t=>{this.h._attachProtoVectorListener(t,r||!1)})}attachAudioListener(t,e,r){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),kn(this,t,(t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)}),On(this,t,t=>{this.h._attachAudioListener(t,r||!1)})}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends xn{la(){this.h._registerModelResourcesGraphService()}});async function Nn(t,e){var r=await(async(t,e,r)=>{var n=bi;if(t&&await Pn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await Pn(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&r&&((t=self.Module).locateFile=r.locateFile,r.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=r.mainScriptUrlOrBlob)),r=await self.ModuleFactory(self.Module||r),self.ModuleFactory=self.Module=void 0,new n(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return r.ka=new An,await r.N(e),r}async function Fn(t,e){return Nn(t,e)}function Rn(t){try{let e=t.J.length;if(1===e)throw Error(t.J[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.J.map(t=>t.message).join(", "))}finally{t.J=[]}}function Dn(t,e){t.I=Math.max(t.I,e)}var Mn=class{constructor(t){this.j=t,this.J=[],this.I=0,this.j.setAutoRenderToScreen(!1)}setGraph(t,e){this.j.attachErrorListener((t,e)=>{this.J.push(Error(e))}),this.j.la(),this.j.setGraph(t,e),Rn(this)}finishProcessing(){this.j.finishProcessing(),Rn(this)}close(){this.ka?.close(),this.j.closeGraph()}};Mn.prototype.close=Mn.prototype.close;var Cn=class extends ir{constructor(t){super(t)}j(){return Bt(Jt(this,2))??0}};function Vn(t,e){ce(t,1,e)}var Gn=class extends ir{constructor(t){super(t)}},zn=[0,Jr,Dr,xr,-1,Fr];function Wn(t,e,r,n){if(void 0!==t.data){var i=new Uint8Array(t.data.buffer,e,r);return 1===n&&function(t,e,r){t.i.push([e,r]),t.i.sort((t,e)=>t[0]-e[0]),e=0;for(let[n,i]of t.i){let t=i;(r=n)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),i}}Cn.prototype.l=Xr(zn);class Hn{constructor(t){this.i=[],this.data=t,this.length=t.length}}function $n(t,e){return new Kn(async()=>{var{value:e,done:r}=await t.read();return r?void 0:e},e)}async function qn(t,e,r,n,i){if(2===i)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout(()=>{t.l()},0),Promise.resolve(0);for(;t.size<r+n;){var o=await t.j();if(void 0===o)break;t.i.push(new Hn(o))}if(t.size<r+n)throw Error(`Data size is too small: ${t.size}, expected at least ${r+n}.`);o=e._malloc(n)>>>0;var a=0;for(let s=0;s<t.i.length;s++){let l=t.i[s];if(r>=l.length){r-=l.length;continue}let u=Math.min(n,l.length-r);if(void 0===(r=Wn(l,r,u,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+a),r=0,a+=u,0===(n-=u))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}var Kn=class{constructor(t,e){this.i=[],this.j=t,this.l=e}get size(){var t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function Yn(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function Jn(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function Xn(t,e,r){t=new Zn(t,r);var n=0;for(e=e.getReader();;){let{value:r,done:i}=await e.read();if(i)break;t.set(r,n),n+=r.byteLength}if(r!==n)throw Qn(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${r} bytes before failure`);return t}function Qn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Zn=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))}},ti=class extends ir{constructor(t){super(t)}};ti.prototype.j=Xr([0,Wr,2,Rr,Dr,Vr]);var ei=class extends ir{constructor(t){super(t)}},ri=class extends ir{constructor(t){super(t)}},ni=class extends ir{constructor(t){super(t)}},ii=class extends ir{constructor(t){super(t)}},oi=[0,Dr,-6,1,Dr,1,[0,Vr,Jr,-2],[0,Vr,xr],Jr,-2,[0,Vr,-1,Jr,xr,Yr,Fr,Cr,-2],1,Vr,Dr,Fr,-1,[0,Jr,Dr],Vr,-1,Ur,Dr,-5,Ur,-1,[0,Fr,Ur],Fr,Cr,[0,Fr,-2],Ur,[0,Dr],[0,Dr,-4],Cr,Fr,-2,Cr,-1,xr,Ur,Cr,Dr,-1,[0,Fr,-2],Vr,Dr,Fr,Cr,[0,Fr,-1],Fr,Cr],ai=[0,Wr,-2],si=[0,[4,6],oi,Dr,1,Mr,Rr,Hr,zr,ai,Fr,[0,[0,Dr,-1,$r,[0,Dr,[0,Dr,-1],-1,[0,Jr,-1],Vr],Vr,-2,Dr,-1],[0,Dr,-1,Vr],oi,Vr,Dr,[0,Dr],-1],Gr,-3,[0,Dr,Vr],oi,[0,ai,-2],kr,$r,[0,Wr,-2],kr];ii.prototype.j=Xr([0,Wr,8,[0,Vr,-6],1,Dr,1,Dr,[0,$r,[0,Wr,Nr,-1,Jr],si,Dr],[0,Dr,Vr,-3],1,Jr,1,si,1,Dr,5,Jr,kr,1,zn,Vr,Dr,Vr]);var li=class extends ir{constructor(t){super(t)}},ui=class extends ir{constructor(t){super(t)}},hi=[2,4];ui.prototype.j=Xr([0,hi,Dr,Hr,Dr,qr,[0,1,Wr]]);var ci=function(t){return class extends t{constructor(){super(...arguments),this.P=!1,this.F=this.H=0}M(){if(this.P)throw Error("Cannot process because LLM inference engine is currently loading or processing.");this.P=!0}L(){this.P=!1}async createLlmInferenceEngine(t,e){this.M();try{let r=$n(t,()=>{});await this.h.createLlmInferenceEngine(pe(e,2)??512,ue(e,Cn,3)?.j()??40,Tt(Jt(e,6))??!1??!1,pe(e,7)??0,Tt(Jt(e,8))??!1??!1,(t,e,n)=>qn(r,this.h,t,e,n))}finally{this.L()}}async ba(t,e){this.M();try{await this.na(t),await this.h.ccall("CreateLlmInferenceEngineConverted","void",["number","number","boolean"],[pe(e,2)??512,ue(e,Cn,3)?.j()??40,Tt(Jt(e,6))??!1??!1],{async:!0})}finally{this.L()}}V(){this.M();try{let t=this.h;t.ccall("DeleteLlmInferenceEngine","void",[],[],{async:!1}),this.H&&(t._FreeSession(this.H),this.F===this.H&&(this.F=0),this.H=0),this.F&&(t._FreeSession(this.F),this.F=0)}finally{this.L()}}async R(t,e,r){this.M();try{let n=[],i=this.h;i._userProgressListener=(t,e)=>{t&&n.push(t),r&&r(t,e)};let o=e.l(),a=o.length,s=this.h._malloc(a);this.h.HEAPU8.set(o,s);let l=t.some(Jn),u=t.some(Yn);i.ccallNum=i.ccall;let h=await i.ccallNum("MakeSessionForPredict","number",["number","number","boolean","boolean"],[s,a,u,l],{async:!0});e=[];for(let r of t)if("string"==typeof r)On(this,r,t=>{i._AddTextQueryChunk(h,t)});else if(Yn(r)){let{image:t,width:n,height:o}=await this.fa(r.imageSource),a="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(n,o):document.createElement("canvas");a.width=n,a.height=o;let s=a.getContext("2d");s.drawImage(t,0,0);let l=s.getImageData(0,0,n,o),u=this.h._malloc(l.width*l.height*4);this.h.HEAPU8.set(l.data,u),i._AddImageQueryChunk(h,u,l.width,l.height),e.push(u)}else{if(!Jn(r))throw Error("Unsupported PromptPart type in query.");{let t=await this.ea(r.audioSource),n=this.h._malloc(t.audioSamples.byteLength);this.h.HEAPF32.set(t.audioSamples,n/4),i._AddAudioQueryChunk(h,t.audioSampleRateHz,n,t.audioSamples.length),e.push(n)}}await i.ccall("PredictSession","void",["number"],[h],{async:!0}),t=!0,u&&0===this.F&&(this.F=h,t=!1),l&&0===this.H&&(this.H=h,t=!1),t&&i._FreeSession(h);for(let t of e)this.h._free(t);return e.length=0,r&&r("",!0),this.h._free(s),i._userProgressListener=void 0,n.join("")}finally{this.L()}}S(t){this.M();var e=0,r="";for(let n of t)"string"==typeof n?r+=n:Yn(n)?e+=260:Jn(n)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return On(this,r,e=>{t=this.h._GetSizeInTokens(e)}),e+t}finally{this.L()}}async na(t){t=await async function(t){for(var e=[],r=0;;){let{done:n,value:i}=await t.read();if(n)break;e.push(i),r+=i.length}if(0===e.length)return new Uint8Array(0);if(1===e.length)return e[0];t=new Uint8Array(r),r=0;for(let n of e)t.set(n,r),r+=n.length;return t}(t);try{this.h.FS_unlink("llm.task")}catch{}this.h.FS_createDataFile("/","llm.task",t,!0,!1,!1)}async fa(t){if("string"==typeof t){let e=new Image;e.src=t,e.crossOrigin="Anonymous";try{await e.decode()}catch{throw Error(`Image from URL ${t} failed to load`)}return{image:e,width:e.naturalWidth,height:e.naturalHeight}}if(t instanceof HTMLImageElement){try{await t.decode()}catch{throw Error("Image from HTMLImageElement failed to load")}return{image:t,width:t.naturalWidth,height:t.naturalHeight}}return t instanceof HTMLVideoElement?{image:t,width:t.videoWidth,height:t.videoHeight}:t instanceof VideoFrame?{image:t,width:t.displayWidth,height:t.displayHeight}:{image:t,width:t.width,height:t.height}}async ea(t){if("string"==typeof t){let e=await fetch(t);if(!e.ok)throw Error(`Audio fetch for ${t} had error: ${e.status}`);return t=await e.arrayBuffer(),{audioSamples:(t=await new AudioContext({sampleRate:16e3}).decodeAudioData(t)).getChannelData(0),audioSampleRateHz:t.sampleRate}}return"object"==typeof t&&null!=t&&"audioSamples"in t&&"audioSampleRateHz"in t?t:{audioSamples:t.getChannelData(0),audioSampleRateHz:t.sampleRate}}}}(function(t){var e=class extends t{static async ma(t,r){r||=await e.X();var n=[];for(let e of t?.requiredFeatures??[])r.features.has(e)?n.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:n};try{var i=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return(t=i).adapterInfo||(t.adapterInfo=r.info),i}static async X(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}ga(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}aa(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}};return e}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket((e,r,n)=>qn(t,this.h,e,r,n),e)}}}(function(t){return class extends t{Y(t,e){On(this,"lora_model_ref_in",r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)})}}}(class extends Bn{}))));class fi extends ci{}var di=class{constructor(t){this.j=t,this.i=pi,pi++}},pi=1;class mi{constructor(){var t,e;this.promise=new Promise((r,n)=>{t=r,e=n}),this.resolve=t,this.reject=e}}function gi(t){return 1===t?1:t+t%2}async function vi(){var t=await fi.X({powerPreference:"high-performance"}),e=t.limits.maxBufferSize,r=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}`),r<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 ${r}`),e={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:r,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."),e.requiredFeatures=["shader-f16","subgroups"]),fi.ma(e,t)}function _i(t){if(t.D.length>0){let e=[...t.D];if(t.D.length=0,!t.o)throw e;t.o.reject(e),t.o=void 0}}function yi(t){var e=function(t){var e=new gn;_e(e,10,"text_in"),_e(e,10,"token_cost_in"),_e(e,10,"lora_model_id_to_apply_in"),_e(e,10,"lora_model_ref_in"),_e(e,10,"lora_model_id_to_load_in"),_e(e,16,"streaming_reader"),_e(e,15,"text_out"),_e(e,15,"text_end"),_e(e,15,"token_cost_out");var r=new cn;ve(r,2,"TokenizerInputBuildCalculator"),_e(r,3,"PROMPT:text_in"),_e(r,3,"LORA_ID:lora_model_id_to_apply_in"),_e(r,4,"prompt"),mn(e,r),r=new cn,ve(r,2,"ModelDataCalculator"),_e(r,6,"MODEL_DATA:__side_packet_1"),_e(r,6,"MODEL_TYPE:model_type"),_e(r,5,"READ_DATA_FN:streaming_reader"),_e(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),_e(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),_e(r,4,"LORA_DATA:lora_model_data"),mn(e,r),r=new cn,ve(r,2,"Gpt2UnicodeMappingCalculator"),_e(r,5,"MODEL_TYPE:model_type"),_e(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),mn(e,r),r=new tn,ve(r,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new ui,i=pe(t.i,2);me(n,1,i),ve(i=new li,2,"spm_vocab_model"),i=he(i);t:{qt(n);var o=n.m,a=0|o[G];if(null==i){var s=se(o);if(4!==le(s,o,a))break t;s.set(hi,0)}else{let t=se(s=o),e=le(t,s,a);4!==e&&(e&&(a=Zt(s,a,e)),t.set(hi,4))}Zt(o,a,4,i)}return i&&!q(i)&&Kt(n.m),me(n,3,2),Qr(r,n.j()),ve(n=new cn,2,"TokenizerCalculator"),de(n,8,tn,r),_e(n,5,"MODEL_DATA:__side_packet_1"),_e(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),_e(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(n,6,"PROCESSOR_GETTER:__input_side_1"),_e(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),mn(e,n),r=new tn,ve(r,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),me(n=new ii,12,3),ve(n,1,"llm.tflite"),me(n,14,0),i=gi(pe(t.i,5)),me(n,22,i),i=ue(t.i,Cn,3),ce(n,31,i),ae(i=new ei,1,It(!0),!1),null!=Tt(Jt(t.i,6))&&(Tt(Jt(t.i,6))??!1)&&ae(i,1,It(!1),!1),ae(i,2,It(!0),!1),ae(i,5,It(!0),!1),ce(n,10,i),i=te(t.i,4,Bt,void 0===Y?2:4),oe(n,29,i),i=new ni,me(o=new ri,1,1),s=pe(t.i,2),me(o,2,s),ce(i,1,o),ce(n,20,i),Qr(r,n.j()),ve(n=new cn,2,"LlmGpuCalculator"),de(n,8,tn,r),_e(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),_e(n,3,"FINISH:finish"),_e(n,3,"LORA_DATA:lora_model_data"),_e(n,5,"MODEL_DATA:__side_packet_1"),_e(n,4,"DECODED_IDS:__stream_3"),_e(n,4,"OUTPUT_END:__stream_4"),r=new un,ve(r,1,"FINISH"),ae(r,2,It(!0),!1),de(n,13,un,r),mn(e,n),r=new cn,ve(r,2,"IsPacketPresentCalculator"),_e(r,3,"__stream_4"),_e(r,4,"text_end"),mn(e,r),r=new tn,ve(r,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new ti,t=gi(pe(t.i,5)),me(n,5,t),_e(n,4,"<eos>"),_e(n,4,"<|endoftext|>"),Qr(r,n.j()),t=new cn,ve(t,2,"DetokenizerCalculator"),de(t,8,tn,r),_e(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),_e(t,5,"PROCESSOR_GETTER:__input_side_1"),_e(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(t,5,"MODEL_DATA:__side_packet_1"),_e(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),_e(t,4,"WORDS:text_out"),mn(e,t),t=new cn,ve(t,2,"TokenCostCalculator"),_e(t,3,"PROMPT:token_cost_in"),_e(t,5,"PROCESSOR_GETTER:__input_side_1"),_e(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(t,4,"NUM_TOKENS:token_cost_out"),mn(e,t),e}(t);t.j.attachStringVectorListener("text_out",(e,r)=>{e=function(t,e){return null==t||0===t.length?[]:t.map(t=>(t=(t=t.replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),e&&(t=t.trimStart()),t.split("\\[eod\\]",1)[0]))}(e,0===t.G.length),e.forEach((e,r)=>{r<pe(t.i,5)&&t.G[r].push(e)}),t.A&&0===t.D.length&&(t.B?(e.length>pe(t.i,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),Dn(t,r)}),t.j.attachEmptyPacketListener("text_out",e=>{Dn(t,e)}),t.j.attachBoolListener("text_end",(e,r)=>{Dn(t,r);try{_i(t)}catch(e){throw t.l=!1,e}if(t.o&&(t.o.resolve(t.G.map(t=>t.join(""))),t.o=void 0),t.A)if(t.B){for(e=[],r=0;r<pe(t.i,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.l=!1,t.B=void 0}),t.j.attachEmptyPacketListener("text_end",e=>{t.l=!1,t.B=void 0,Dn(t,e),_i(t),t.o&&(t.o.resolve(t.G.map(t=>t.join(""))),t.o=void 0)}),t.j.attachIntListener("token_cost_out",(e,r)=>{t.T=e,Dn(t,r)}),t.U&&t.j.addStreamingReaderToInputSidePacket(t.U,"streaming_reader");var r=e.j();return t.C?.removeEventListener("uncapturederror",t.K),t.j.aa().then(()=>{t.C?.addEventListener("uncapturederror",t.K),t.D.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()})}function wi(t,e,r,n){if(t.A="function"==typeof r?r:n,(n=(e=Array.isArray(e)?e:[e]).filter(t=>Yn(t)).length)>0&&(null==Nt(Jt(t.i,7))||pe(t.i,7)<n))throw Error(`maxNumImages is set to ${null!=Nt(Jt(t.i,7))?pe(t.i,7):0}, but the query included ${n} images.`);if((n=e.filter(t=>Jn(t)).length)>0&&(null==Tt(Jt(t.i,8))||!Tt(Jt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${n} audio chunks.`);if(t.v){if(t.B&&pe(t.i,5)>1)throw Error("Multi-response generation is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality or request only one response.");if(r instanceof di)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality to use LoRA.");return t.j.h.LLM_CANCEL_FLAG=void 0,t.j.R(e,t.u,(e,r)=>{0===t.D.length&&t.A&&(t.B?t.A([e],r):t.A(e,r))}).then(e=>(_i(t),[e]))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.j.h.LLM_CANCEL_FLAG=void 0,t.G.length=0,n=0;n<pe(t.i,5);n++)t.G[n]=[];if(n=t.I+1,t.j.addStringToStream(e.join(""),"text_in",n),r instanceof di){if(r.j!==t)throw t.l=!1,t.B=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.j.addUintToStream(r.i,"lora_model_id_to_apply_in",n)}else t.j.addEmptyPacketToStream("lora_model_id_to_apply_in",n);return t.finishProcessing(),t.o=new mi,t.o.promise}var bi=class extends Mn{constructor(t,e){if(super(new fi(t,e)),this.G=[],this.O=this.v=this.l=!1,this.D=[],this.K=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.D.push(t)},this.i=new Gn,Vn(this.i,new _n),this.u=new Cn,ce(this.i,3,this.u),ge(this.i,2,512),t=this.u,!bt(2))throw O("enum");ae(t,1,2,0),me(this.u,2,40),ae(this.u,3,At(1),0),Qt(this.u,5,xt(0)),ae(this.u,4,At(.8),0),ge(this.i,5,1)}async N(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");var e,r=new Promise(t=>{e=t});if(t.baseOptions?.modelAssetPath){var n=await fetch(t.baseOptions.modelAssetPath.toString());if(!n.ok)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (${n.status})`);if(!n.body)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (no body)`);n=n.body.getReader()}else t.baseOptions?.modelAssetBuffer instanceof Uint8Array?n=function(t){return new ReadableStream({start(){},async pull(e){e.enqueue(t),e.close()}})}(t.baseOptions.modelAssetBuffer).getReader():t.baseOptions?.modelAssetBuffer instanceof ReadableStreamDefaultReader?(n=t.baseOptions.modelAssetBuffer,t.baseOptions.modelAssetBuffer=void 0):e();if(!n)throw Error("No model asset provided.");{let[r,a]=En(n);this.O=1===await async function(t){var e,r=[];for(let[i,o]of Tn){let a=i;var n=o;[t,e]=En(t),n=await n(e),await e.cancel(),n&&r.push(a)}if(await t.cancel(),0===r.length)throw Error("No model format matched.");if(1===r.length)return r[0];throw Error(`Multiple model formats matched: ${r}`)}(a);var i="maxNumImages"in t&&t.maxNumImages?t.maxNumImages:0;ge(this.i,7,i);var o="supportAudio"in t&&!!t.supportAudio;Qt(this.i,8,It(o)),this.O||i>0||o?(this.v=!0,n=r):(this.v=!1,this.U=$n(r,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.K),this.C=t.baseOptions.gpuOptions.device,this.j.ga(this.C),this.C.addEventListener("uncapturederror",this.K)),"maxTokens"in t&&ge(this.i,2,t.maxTokens??512),"topK"in t&&me(this.u,2,t.topK??40),"temperature"in t&&ae(this.u,4,At(t.temperature??.8),0),"randomSeed"in t&&Qt(this.u,5,xt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){oe(t,4,e)}(this.i,t.loraRanks??[]),"numResponses"in t){if((i=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&i>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet, and is also not supported with multimodality.");ge(this.i,5,i),o=ue(this.i,Cn,3),i>1&&o&&(o.j()<=1||(Jt(o,4,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&&void 0!==t.forceF32&&Qt(this.i,6,It(t.forceF32)),this.v?(this.j.V(),this.O?this.j.ba(n,this.i).then(()=>{_i(this)}):this.j.createLlmInferenceEngine(n,this.i).then(()=>{_i(this)})):(this.l=!0,t=yi(this).then(()=>{}),Promise.all([r,t]).then(()=>{this.l=!1,_i(this)}))}get baseOptions(){return ue(this.i,_n,1)}set baseOptions(t){Vn(this.i,t)}get isIdle(){return!this.l&&!this.o}R(t,e,r){return pe(this.i,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.B=!1,wi(this,t,e,r).then(t=>t[0])}da(t,e,r){return this.B=!0,wi(this,t,e,r)}S(t){if(t=Array.isArray(t)?t:[t],this.v)return this.j.S(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");if(t.some(Yn))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(Jn))throw Error("sizeInTokens requires supportAudio for audio.");return t=t.join(""),this.l=!0,this.T=void 0,this.j.addStringToStream(t,"token_cost_in",this.I+1),this.finishProcessing(),this.l=!1,this.T}Z(){var t=this.j.h;(this.v||this.l)&&(t.LLM_CANCEL_FLAG=1)}async ja(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the old format (.bin) without multimodality 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 Zn(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return Xn(t,e.stream(),e.size)}(this.j.h,t):await async function(t,e){e=await fetch(e.toString());var r=Number(e.headers.get("content-length"));if(!e.body)throw Error("Response body is not available.");if(!r)throw Error("File size is 0.");return Xn(t,e.body,r)}(this.j.h,t);e=new di(this);var r=this.I+1;return this.j.Y(t,r),this.j.addUintToStream(e.i,"lora_model_id_to_load_in",r),this.finishProcessing(),Qn(t),Dn(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};return bi.prototype.loadLoraModel=bi.prototype.ja,bi.prototype.cancelProcessing=bi.prototype.Z,bi.prototype.sizeInTokens=bi.prototype.S,bi.prototype.generateResponses=bi.prototype.da,bi.prototype.generateResponse=bi.prototype.R,bi.prototype.setOptions=bi.prototype.N,bi.createWebGpuDevice=vi,bi.createFromModelPath=async function(t,e){return Fn(t,e={baseOptions:{gpuOptions:{device:await vi()},modelAssetPath:e}})},bi.createFromModelBuffer=async function(t,e){return Fn(t,e={baseOptions:{gpuOptions:{device:await vi()},modelAssetBuffer:e}})},bi.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){let t=await vi();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Fn(t,e)},t.FilesetResolver=Sn,t.LlmInference=bi,t.TaskRunner=Mn,t}({});
|
|
1
|
+
var GenAI=function(t){"use strict";var e="undefined"!=typeof self?self:{};function r(t,r){t:{for(var i=["CLOSURE_FLAGS"],n=e,o=0;o<i.length;o++)if(null==(n=n[i[o]])){i=null;break t}i=n}return null!=(t=i&&i[t])?t:r}var i,n="undefined"!=typeof TextEncoder;function o(t){if(n)t=(i||=new TextEncoder).encode(t);else{let r=0,i=new Uint8Array(3*t.length);for(let n=0;n<t.length;n++){var e=t.charCodeAt(n);if(e<128)i[r++]=e;else{if(e<2048)i[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&n<t.length){let o=t.charCodeAt(++n);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,i[r++]=e>>18|240,i[r++]=e>>12&63|128,i[r++]=e>>6&63|128,i[r++]=63&e|128;continue}n--}e=65533}i[r++]=e>>12|224,i[r++]=e>>6&63|128}i[r++]=63&e|128}}t=r===i.length?i:i.subarray(0,r)}return t}var a=r(610401301,!1),s=r(748402147,!0);function l(){var t=e.navigator;return t&&(t=t.userAgent)?t:""}var u,h=e.navigator;u=h&&h.userAgentData||null;var c={},f=null;function d(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var i=new Uint8Array(r),n=0;return function(t,e){function r(e){for(;i<t.length;){let e=t.charAt(i++),r=f[e];if(null!=r)return r;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}p();for(var i=0;;){let t=r(-1),i=r(0),n=r(64),o=r(64);if(64===o&&-1===t)break;e(t<<2|i>>4),64!=n&&(e(i<<4&240|n>>2),64!=o&&e(n<<6&192|o))}}(t,function(t){i[n++]=t}),n!==r?i.subarray(0,n):i}function p(){if(!f){f={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let i=t.concat(e[r].split(""));c[r]=i;for(let t=0;t<i.length;t++){let e=i[t];void 0===f[e]&&(f[e]=t)}}}}var m="undefined"!=typeof Uint8Array,g=!(!(a&&u&&u.brands.length>0)&&(-1!=l().indexOf("Trident")||-1!=l().indexOf("MSIE")))&&"function"==typeof btoa,v=/[-_.]/g,y={"-":"+",_:"/",".":"="};function _(t){return y[t]||""}function w(t){if(!g)return d(t);t=v.test(t)?t.replace(v,_):t,t=atob(t);var e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function b(t){return m&&null!=t&&t instanceof Uint8Array}var S={};function E(){return A||=new I(null,S)}var A,I=class{constructor(t,e){if(T(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function T(t){if(t!==S)throw Error("illegal external caller")}function L(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}var P=void 0;function O(t){return L(t=Error(t),"warning"),t}function j(t,r){if(null!=t){var i=P??={},n=i[t]||0;n>=r||(i[t]=n+1,L(t=Error(),"incident"),function(t){e.setTimeout(()=>{throw t},0)}(t))}}function k(){return"function"==typeof BigInt}var U="function"==typeof Symbol&&"symbol"==typeof Symbol();function x(t,e,r=!1){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?r&&Symbol.for&&t?Symbol.for(t):null!=t?Symbol(t):Symbol():e}var B,N=x("jas",void 0,!0),F=x(void 0,"1oa"),R=x(void 0,"0ubsb"),M=x(void 0,"0actk"),D=x("m_m","qa",!0),C={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},V=Object.defineProperties,G=U?N:"ha",z=[];function H(t,e){U||G in t||V(t,C),t[G]|=e}function W(t,e){U||G in t||V(t,C),t[G]=e}W(z,7),B=Object.freeze(z);var $={};function q(t,e){return void 0===e?t.i!==K&&!!(2&t.m[G]):!!(2&e)&&t.i!==K}var K={},Y=Object.freeze({});function J(t){return t.pa=!0,t}var X=J(t=>"number"==typeof t),Q=J(t=>"string"==typeof t),Z=J(t=>"boolean"==typeof t),tt="function"==typeof e.BigInt&&"bigint"==typeof e.BigInt(0),et=J(t=>tt?t>=it&&t<=ot:"-"===t[0]?at(t,rt):at(t,nt)),rt=Number.MIN_SAFE_INTEGER.toString(),it=tt?BigInt(Number.MIN_SAFE_INTEGER):void 0,nt=Number.MAX_SAFE_INTEGER.toString(),ot=tt?BigInt(Number.MAX_SAFE_INTEGER):void 0;function at(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){let i=t[r],n=e[r];if(i>n)return!1;if(i<n)return!0}}var st,lt=0,ut=0;function ht(t){var e=t>>>0;lt=e,ut=(t-e)/4294967296>>>0}function ct(t){if(t<0){ht(-t);let[e,r]=gt(lt,ut);lt=e>>>0,ut=r>>>0}else ht(t)}function ft(t,e){var r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:dt(t,e)}function dt(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else k()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,t>=1e7&&(r+=t/1e7>>>0,t%=1e7),r>=1e7&&(e+=r/1e7>>>0,r%=1e7),r=e+pt(r)+pt(t));return r}function pt(t){return t=String(t),"0000000".slice(t.length)+t}function mt(t){if(t.length<16)ct(Number(t));else if(k())t=BigInt(t),lt=Number(t&BigInt(4294967295))>>>0,ut=Number(t>>BigInt(32)&BigInt(4294967295));else{let e=+("-"===t[0]);ut=lt=0;let r=t.length;for(let i=e,n=(r-e)%6+e;n<=r;i=n,n+=6){let e=Number(t.slice(i,n));ut*=1e6,(lt=1e6*lt+e)>=4294967296&&(ut+=Math.trunc(lt/4294967296),ut>>>=0,lt>>>=0)}if(e){let[t,e]=gt(lt,ut);lt=t,ut=e}}}function gt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function vt(t){return Array.prototype.slice.call(t)}var yt="function"==typeof BigInt?BigInt.asIntN:void 0,_t="function"==typeof BigInt?BigInt.asUintN:void 0,wt=Number.isSafeInteger,bt=Number.isFinite,St=Math.trunc;function Et(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}function It(t){if("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 Tt(t){return null==t||"boolean"==typeof t?t:"number"==typeof t?!!t:void 0}var Lt,Pt,Ot,jt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function kt(t){switch(typeof t){case"bigint":return!0;case"number":return bt(t);case"string":return jt.test(t);default:return!1}}function Ut(t){if("number"!=typeof t)throw O("int32");if(!bt(t))throw O("int32");return 0|t}function xt(t){return null==t?t:Ut(t)}function Bt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return bt(t)?0|t:void 0}function Nt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return bt(t)?t>>>0:void 0}function Ft(t){return null==t||"string"==typeof t?t:void 0}function Rt(t,e,r){if(null!=t&&t[D]===$)return t;if(Array.isArray(t)){var i=0|t[G];return(r=i|32&r|2&r)!==i&&W(t,r),new e(t)}}function Mt(t){return t}function Dt(t,e,r,i){var n=void 0!==i;i=!!i;var o=[],a=t.length,s=4294967295,l=!1,u=!!(64&e),h=u?128&e?0:-1:void 0;if(!(1&e)){var c=a&&t[a-1];null!=c&&"object"==typeof c&&c.constructor===Object?s=--a:c=void 0,!u||128&e||n||(l=!0,s=(Lt??Mt)(s-h,h,t,c,void 0)+h)}for(e=void 0,n=0;n<a;n++){let a=t[n];if(null!=a&&null!=(a=r(a,i)))if(u&&n>=s){let t=n-h;(e??={})[t]=a}else o[n]=a}if(c)for(let n in c){if(null==(t=c[n])||null==(t=r(t,i)))continue;let l;a=+n,u&&!Number.isNaN(a)&&(l=a+h)<s?o[l]=t:(e??={})[n]=t}return e&&(l?o.push(e):o[s]=e),o}function Ct(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return et(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[G];return 0===t.length&&1&e?void 0:Dt(t,e,Ct)}if(null!=t&&t[D]===$)return Vt(t);if(t instanceof I){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(g){for(var r="",i=0,n=e.length-10240;i<n;)r+=String.fromCharCode.apply(null,e.subarray(i,i+=10240));r+=String.fromCharCode.apply(null,i?e.subarray(i):e),e=btoa(r)}else{void 0===r&&(r=0),p(),r=c[r],i=Array(Math.floor(e.length/3)),n=r[64]||"";let t=0,u=0;for(;t<e.length-2;t+=3){var o=e[t],a=e[t+1],s=e[t+2],l=r[o>>2];o=r[(3&o)<<4|a>>4],a=r[(15&a)<<2|s>>6],s=r[63&s],i[u++]=l+o+a+s}switch(l=0,s=n,e.length-t){case 2:s=r[(15&(l=e[t+1]))<<2]||n;case 1:e=e[t],i[u]=r[e>>2]+r[(3&e)<<4|l>>4]+s+n}e=i.join("")}t=t.i=e}return t}return}return t}function Vt(t){return Dt(t=t.m,0|t[G],Ct)}function Gt(t,e,r,i=0){if(null==t){var n=32;r?(t=[r],n|=128):t=[],e&&(n=-16760833&n|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(n=0|t[G],s&&1&n)throw Error("rfarr");if(2048&n&&!(2&n)&&function(){if(s)throw Error("carr");j(M,5)}(),256&n)throw Error("farr");if(64&n)return(n|i)!==n&&W(t,n|i),t;if(r&&(n|=128,r!==t[0]))throw Error("mid");t:{n|=64;var o=(r=t).length;if(o){var a=o-1;let t=r[a];if(null!=t&&"object"==typeof t&&t.constructor===Object){if((a-=e=128&n?0:-1)>=1024)throw Error("pvtlmt");for(var l in t)(o=+l)<a&&(r[o+e]=t[l],delete t[l]);n=-16760833&n|(1023&a)<<14;break t}}if(e){if((l=Math.max(e,o-(128&n?0:-1)))>1024)throw Error("spvt");n=-16760833&n|(1023&l)<<14}}}return W(t,64|n|i),t}function zt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var r=0|t[G];return 0===t.length&&1&r?t=void 0:2&r||(!e||4096&r||16&r?t=Wt(t,r,!1,e&&!(16&r)):(H(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[D]===$?q(t,r=0|(e=t.m)[G])?t:Yt(t,e,r)?Ht(t,e):Wt(e,r):t instanceof I?t:void 0}function Ht(t,e,r){return t=new t.constructor(e),r&&(t.i=K),t.o=K,t}function Wt(t,e,r,i){return i??=!!(34&e),t=Dt(t,e,zt,i),i=32,r&&(i|=2),W(t,e=16769217&e|i),t}function $t(t){if(t.i!==K)return!1;var e=t.m;return H(e=Wt(e,0|e[G]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function qt(t){if(!$t(t)&&q(t,0|t.m[G]))throw Error()}function Kt(t,e){void 0===e&&(e=0|t[G]),32&e&&!(4096&e)&&W(t,4096|e)}function Yt(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(W(e,2|r),t.i=K,!0)}function Jt(t,e,r){if(null!==(t=Xt(t.m,e,void 0,r)))return t}function Xt(t,e,r,i){if(-1===e)return null;var n=e+(r?0:-1),o=t.length-1;if(!(o<1+(r?0:-1))){if(n>=o){var a=t[o];if(null!=a&&"object"==typeof a&&a.constructor===Object){r=a[e];var s=!0}else{if(n!==o)return;r=a}}else r=t[n];if(i&&null!=r){if(null==(i=i(r)))return i;if(!Object.is(i,r))return s?a[e]=i:t[n]=i,i}return r}}function Qt(t,e,r){qt(t),Zt(t=t.m,0|t[G],e,r)}function Zt(t,e,r,i,n){var o=r+(n?0:-1),a=t.length-1;if(a>=1+(n?0:-1)&&o>=a){let n=t[a];if(null!=n&&"object"==typeof n&&n.constructor===Object)return n[r]=i,e}return o<=a?(t[o]=i,e):(void 0!==i&&(r>=(a=(e??=0|t[G])>>14&1023||536870912)?null!=i&&(t[a+(n?0:-1)]={[r]:i}):t[o]=i),e)}function te(t,e,r,i,n){var o=t.m,a=0|o[G];i=q(t,a)?1:i,n=!!n||3===i,2===i&&$t(t)&&(a=0|(o=t.m)[G]);var s=(t=re(o,e))===B?7:0|t[G],l=ie(s,a),u=!(4&l);if(u){4&l&&(t=vt(t),s=0,l=fe(l,a),a=Zt(o,a,e,t));let i=0,n=0;for(;i<t.length;i++){let e=r(t[i]);null!=e&&(t[n++]=e)}n<i&&(t.length=n),r=-513&l|4,l=r&=-1025,l&=-4097}return l!==s&&(W(t,l),2&l&&Object.freeze(t)),ee(t,l,o,a,e,i,u,n)}function ee(t,e,r,i,n,o,a,s){var l=e;return 1===o||4===o&&(2&e||!(16&e)&&32&i)?ne(e)||((e|=!t.length||a&&!(4096&e)||32&i&&!(4096&e||16&e)?2:256)!==l&&W(t,e),Object.freeze(t)):(2===o&&ne(e)&&(t=vt(t),l=0,e=fe(e,i),i=Zt(r,i,n,t)),ne(e)||(s||(e|=16),e!==l&&W(t,e))),2&e||!(4096&e||16&e)||Kt(r,i),t}function re(t,e,r){return t=Xt(t,e,r),Array.isArray(t)?t:B}function ie(t,e){return 2&e&&(t|=2),1|t}function ne(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function oe(t,e,r){qt(t);var i=0|(t=t.m)[G];if(null==r)Zt(t,i,e);else{var n=r===B?7:0|r[G],o=n,a=ne(n),s=a||Object.isFrozen(r);for(a||(n=0),s||(r=vt(r),o=0,n=fe(n,i),s=!1),n|=5,n|=(4&n?512&n?512:1024&n?1024:0:void 0)??1024,a=0;a<r.length;a++){let t=r[a],e=Ut(t);Object.is(t,e)||(s&&(r=vt(r),o=0,n=fe(n,i),s=!1),r[a]=e)}n!==o&&(s&&(r=vt(r),n=fe(n,i)),W(r,n)),Zt(t,i,e,r)}}function ae(t,e,r,i){qt(t),Zt(t=t.m,0|t[G],e,("0"===i?0===Number(r):r===i)?void 0:r)}function se(t){if(U)return t[F]??(t[F]=new Map);if(F in t)return t[F];var e=new Map;return Object.defineProperty(t,F,{value:e}),e}function le(t,e,r){var i=pn,n=t.get(i);if(null!=n)return n;n=0;for(let t=0;t<i.length;t++){let o=i[t];null!=Xt(e,o)&&(0!==n&&(r=Zt(e,r,n)),n=o)}return t.set(i,n),n}function ue(t,e,r){var i=t.m,n=0|i[G];if(e=function(t,e,r,i){var n=!1;if(null!=(i=Xt(t,i,void 0,t=>{var i=Rt(t,r,e);return n=i!==t&&null!=i,i})))return n&&!q(i)&&Kt(t,e),i}(i,n,e,r),null==e)return e;if(!q(t,n=0|i[G])){var o,a=e;let s=a.m,l=0|s[G];(o=q(a,l)?Yt(a,s,l)?Ht(a,s,!0):new a.constructor(Wt(s,l,!1)):a)!==e&&($t(t)&&(n=0|(i=t.m)[G]),Kt(i,n=Zt(i,n,r,e=o)))}return e}function he(t){return null==t&&(t=void 0),t}function ce(t,e,r){return Qt(t,e,r=he(r)),r&&!q(r)&&Kt(t.m),t}function fe(t,e){return-273&(2&e?2|t:-3&t)}function de(t,e,r,i){var n=i;qt(t);var o=i=t.m,a=0|i[G],s=q(t,a)?1:2;2===s&&$t(t)&&(a=0|(o=t.m)[G]);var l=(t=re(o,e))===B?7:0|t[G],u=ie(l,a),h=!(4&u);if(h){var c=t,f=a;let e=!!(2&u);e&&(f|=2);let i=!e,n=!0,o=0,s=0;for(;o<c.length;o++){let t=Rt(c[o],r,f);if(t instanceof r){if(!e){let e=q(t);i&&=!e,n&&=e}c[s++]=t}}s<o&&(c.length=s),u|=4,u=n?-4097&u:4096|u,u=i?8|u:-9&u}u!==l&&(W(t,u),2&u&&Object.freeze(t)),e=t=ee(t,u,o,a,e,s,h,!0),n=null!=n?n:new r,e.push(n),o=r=e===B?7:0|e[G],(n=q(n))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&W(e,r),n||Kt(i)}function pe(t,e){return Nt(Jt(t,e))??0}function me(t,e,r){Qt(t,e,null==r?r:It(r))}function ge(t,e,r){ae(t,e,null==r?r:It(r),!1)}function ve(t,e,r){ae(t,e,xt(r),0)}function ye(t,e,r){if(null!=r){if("number"!=typeof r)throw O("uint32");if(!bt(r))throw O("uint32");r>>>=0}Qt(t,e,r)}function _e(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();ae(t,e,r,"")}function we(t,e,r){if(qt(t),e=(t=te(t,e,Ft,2,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}var be=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function Se(t){if("string"==typeof t)return new be(w(t),!0);if(Array.isArray(t))return new be(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new be(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new be(t,!1);if(t.constructor===I){T(S);var e=t.i;return e=(null==(e=null==e||b(e)?e:"string"==typeof e?w(e):null)?e:t.i=e)||new Uint8Array(0),new be(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new be(t,!1);throw Error()}function Ee(t){return new Te(4294967295&t,Math.floor(t/4294967296))}function Ae(t){return t?/^\d+$/.test(t)?(mt(t),new Te(lt,ut)):null:Ie||=new Te(0,0)}var Ie,Te=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Le(t){return new Re(4294967295&t,Math.floor(t/4294967296))}function Pe(t){return t?/^-?\d+$/.test(t)?(mt(t),new Re(lt,ut)):null:Oe||=new Re(0,0)}var Oe,je,ke,Ue,xe,Be,Ne,Fe,Re=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Me(t,e,r){return"undefined"!=typeof BigInt64Array?(Ne||(Ne=new BigInt64Array(1),Fe=new Uint32Array(Ne.buffer),Ne[0]=BigInt(1),Be=1===Fe[0]),Ne[0]=t,new e(Fe[t=Be?0:1],Fe[1-t])):(xe||(je=BigInt(Number.MIN_SAFE_INTEGER),ke=BigInt(Number.MAX_SAFE_INTEGER),Ue=BigInt(4294967295),xe=BigInt(32)),t>=je&&t<=ke?r(Number(t)):(t=BigInt.asUintN(64,t),new e(Number(t&Ue),Number(t>>xe))))}function De(t,e,r){for(;r>0||e>127;)t.i.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.i.push(e)}function Ce(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Ve(t,e){if(e>=0)Ce(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}var Ge=class{constructor(){this.i=[]}length(){return this.i.length}end(){var t=this.i;return this.i=[],t}};function ze(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function He(t,e,r){Ce(t.i,8*e+r)}function We(t,e){return He(t,e,2),e=t.i.end(),ze(t,e),e.push(t.j),e}function $e(t,e){var r=e.pop();for(r=t.j+t.i.length()-r;r>127;)e.push(127&r|128),r>>>=7,t.j++;e.push(r),t.j++}function qe(t,e,r){He(t,e,2),Ce(t.i,r.length),ze(t,t.i.end()),ze(t,r)}var Ke=class{constructor(){this.l=[],this.j=0,this.i=new Ge}};function Ye(){var t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Je=Ye(),Xe=Ye(),Qe=Ye(),Ze=Ye(),tr=Ye(),er=Ye(),rr=Ye(),ir=Ye(),nr=Ye(),or=Ye(),ar=class{constructor(t,e){this.m=Gt(t,e,void 0,2048)}toJSON(){return Vt(this)}};ar.prototype[D]=$,ar.prototype.toString=function(){return this.m.toString()};var sr=class{constructor(t,e){this.i=t,t=Je,this.j=!!t&&e===t||!1}};function lr(t,e,r,i,n){null!=(e=gr(e,i))&&(r=We(t,r),n(e,t),$e(t,r))}var ur,hr,cr=new sr(lr,Je),fr=new sr(lr,Je),dr=Symbol(),pr=Symbol();function mr(t){var e=vr,r=yr,i=t[dr];if(i)return i;(i={}).oa=t,i.W=function(t){switch(typeof t){case"boolean":return Pt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Ot||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);var n=t[1],o=1;n&&n.constructor===Object&&(i.ca=n,"function"==typeof(n=t[++o])&&(i.ia=!0,ur??=n,hr??=t[o+1],n=t[o+=2]));for(var a={};n&&Array.isArray(n)&&n.length&&"number"==typeof n[0]&&n[0]>0;){for(var s=0;s<n.length;s++)a[n[s]]=n;n=t[++o]}for(s=1;void 0!==n;){let h;"number"==typeof n&&(s+=n,n=t[++o]);var l=void 0;if(n instanceof sr?h=n:(h=cr,o--),h?.j){n=t[++o],l=t;var u=o;"function"==typeof n&&(n=n(),l[u]=n),l=n}for(u=s+1,"number"==typeof(n=t[++o])&&n<0&&(u-=n,n=t[++o]);s<u;s++){let t=a[s];l?r(i,s,h,l,t):e(i,s,h,t)}}return t[dr]=i}function gr(t,e){return t instanceof ar?t.m:Array.isArray(t)?Gt(t,e[0],e[1]):void 0}function vr(t,e,r){t[e]=r.i}function yr(t,e,r,i){var n,o,a=r.i;t[e]=(t,e,r)=>a(t,e,r,o||=mr(i).W,n||=_r(i))}function _r(t){var e=t[pr];if(!e){let r=mr(t);e=(t,e)=>wr(t,e,r),t[pr]=e}return e}function wr(t,e,r){!function(t,e,r){var i,n=128&e?0:-1,o=t.length;(i=!!o)&&(i=null!=(i=t[o-1])&&"object"==typeof i&&i.constructor===Object);var a=o+(i?-1:0);for(e=128&e?1:0;e<a;e++)r(e-n,t[e]);if(i){t=t[o-1];for(let e in t)!isNaN(e)&&r(+e,t[e])}}(t,0|t[G],(t,i)=>{if(null!=i){var n=function(t,e){var r=t[e];if(r)return r;if((r=t.ca)&&(r=r[e])){var i=(r=Array.isArray(r)?r[0]instanceof sr?r:[fr,r]:[r,void 0])[0].i;if(r=r[1]){let e=_r(r),n=mr(r).W;r=t.ia?hr(n,e):(t,r,o)=>i(t,r,o,n,e)}else r=i;return t[e]=r}}(r,t);n?n(e,i,t):t<500||j(R,3)}})}var br,Sr=0,Er=Sr;if(Q(Er)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(Er))throw Error(String(Er))}else if((br=X(Er))&&(br=!Number.isSafeInteger(Er)),br)throw Error(String(Er));function Ar(t,e){if(Array.isArray(e)){var r=0|e[G];if(4&r)return e;for(var i=0,n=0;i<e.length;i++){let r=t(e[i]);null!=r&&(e[n++]=r)}return n<i&&(e.length=n),(t=-1537&r|5)!==r&&W(e,t),2&t&&Object.freeze(e),e}}function Ir(t,e){return new sr(t,e)}function Tr(t,e,r){null!=(e=At(e))&&(He(t,r,5),t=t.i,(r=st||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ut=0,e=lt=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))}function Lr(t,e,r){null!=(e=Bt(e))&&null!=e&&(He(t,r,0),Ve(t.i,e))}function Pr(t,e,r){null!=(e=Tt(e))&&(He(t,r,0),t.i.i.push(e?1:0))}function Or(t,e,r){null!=(e=Ft(e))&&qe(t,r,o(e))}function jr(t,e,r,i,n){null!=(e=gr(e,i))&&(r=We(t,r),n(e,t),$e(t,r))}function kr(t,e,r){null!=(e=Nt(e))&&null!=e&&(He(t,r,0),Ce(t.i,e))}function Ur(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),He(t,r,0),Ve(t.i,e))}tt||(Sr=Z(Sr)?Sr?"1":"0":Q(Sr)?Sr.trim()||"0":String(Sr));var xr,Br=Ir(Tr,ir),Nr=Ir(Tr,ir),Fr=Ir(function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(yt(64,t));if(kt(t)){if("string"===e){if(e=St(Number(t)),wt(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),e=t.length,!("-"===t[0]?e<20||20===e&&t<="-9223372036854775808":e<19||19===e&&t<="9223372036854775807"))if(mt(t),t=lt,2147483648&(e=ut))if(k())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,i]=gt(t,e);t="-"+dt(r,i)}else t=dt(t,e);return t}if("number"===e){if(t=St(t),!wt(t)){ct(t),e=lt;var r=ut;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),t="number"==typeof(e=ft(e,r))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)Pe(e);if(null!=e)switch(He(t,r,0),typeof e){case"number":t=t.i,ct(e),De(t,lt,ut);break;case"bigint":r=Me(e,Re,Le),De(t.i,r.j,r.i);break;default:r=Pe(e),De(t.i,r.j,r.i)}}},er),Rr=Ir(function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(_t(64,t));if(kt(t)){if("string"===e)return e=St(Number(t)),wt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),(e="-"!==t[0]&&((e=t.length)<20||20===e&&t<="18446744073709551615"))||(mt(t),t=dt(lt,ut))),t;if("number"===e)return(t=St(t))>=0&&wt(t)||(ct(t),t=ft(lt,ut)),t}}(e),null!=e){if("string"==typeof e)Ae(e);if(null!=e)switch(He(t,r,0),typeof e){case"number":t=t.i,ct(e),De(t,lt,ut);break;case"bigint":r=Me(e,Te,Ee),De(t.i,r.j,r.i);break;default:r=Ae(e),De(t.i,r.j,r.i)}}},rr),Mr=Ir(Lr,Ze);xr=new sr(function(t,e,r){if(null!=(e=Ar(Bt,e))&&e.length){r=We(t,r);for(let r=0;r<e.length;r++)Ve(t.i,e[r]);$e(t,r)}},Ze);var Dr,Cr=Ir(Lr,Ze),Vr=Ir(Lr,Ze),Gr=Ir(Pr,Xe),zr=Ir(Pr,Xe),Hr=Ir(Or,Qe);Dr=new sr(function(t,e,r){if(null!=(e=Ar(Ft,e)))for(let s=0;s<e.length;s++){var i=t,n=r,a=e[s];null!=a&&qe(i,n,o(a))}},Qe);var Wr,$r=Ir(Or,Qe),qr=Ir(Or,Qe),Kr=function(t,e,r=Je){return new sr(e,r)}(0,function(t,e,r,i,n){if(Array.isArray(e)){for(let o=0;o<e.length;o++)jr(t,e[o],r,i,n);1&(t=0|e[G])||W(e,1|t)}}),Yr=new sr(jr,Je),Jr=Ir(kr,tr),Xr=Ir(Ur,or);Wr=new sr(function(t,e,r){if(null!=(e=Ar(Bt,e))&&e.length){r=We(t,r);for(let r=0;r<e.length;r++)Ve(t.i,e[r]);$e(t,r)}},or);var Qr=Ir(Ur,or);function Zr(t){return function(){var e=new Ke;wr(this.m,e,mr(t)),ze(e,e.i.end());var r=new Uint8Array(e.j),i=e.l,n=i.length,o=0;for(let t=0;t<n;t++){let e=i[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function ti(t,e){if(null!=e)if(Array.isArray(e))Qt(t,2,Dt(e,0,Ct));else{if(!("string"==typeof e||e instanceof I||b(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,S):E();else if(e.constructor!==I){if(!b(e))throw Error();e=e.length?new I(new Uint8Array(e),S):E()}ae(t,2,e,E())}}var ei,ri=class extends ar{constructor(t){super(t)}},ii=[0,$r,Ir(function(t,e,r){if(null!=e){if(e instanceof ar){let i=e.ra;return void(i?(e=i(e),null!=e&&qe(t,r,Se(e).buffer)):j(R,3))}if(Array.isArray(e))return void j(R,3)}null!=(e=null==e||"string"==typeof e||e instanceof I?e:void 0)&&qe(t,r,Se(e).buffer)},nr)],ni=globalThis.trustedTypes;var oi=class{constructor(t){this.i=t}toString(){return this.i+""}};function ai(t){var e;return void 0===ei&&(ei=function(){var t=null;if(!ni)return t;try{let e=t=>t;t=ni.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=ei)?e.createScriptURL(t):t,new oi(t)}function si(t,...e){if(0===e.length)return ai(t[0]);var r=t[0];for(let i=0;i<e.length;i++)r+=encodeURIComponent(e[i])+t[i+1];return ai(r)}var li=[0,Xr,-1,Gr],ui={};ui[336783863]=[0,Hr,Gr,-1,Mr,[0,[1,2,3,4,5,6,7,8,9],Yr,[0],Yr,[0,Gr,Hr,Gr,Xr,-1,Wr,Hr,-1,[0,Gr,-1],Xr,Gr,-1,li],Yr,[0,Hr,-2],Yr,[0,Mr,Gr,1,Gr,-4],Yr,[0,Mr,Xr,Gr,-1,xr,Xr,-1,Gr,-1],Yr,[0,Hr,-2],Yr,[0,Hr,Xr],Yr,[0,3,Gr,-1,2,[0,[2],Mr,Yr,[0,Ir(kr,tr)]],[0,Xr,Gr,Xr,Gr,Xr,Gr,Hr,-1],[0,[3,4],Hr,-1,Yr,[0,Mr],Yr,[0,Xr]],[0]],Yr,li],[0,Hr],Gr,[0,[1,3],[2,4],Yr,[0,xr],-1,Yr,[0,Dr],-1,Kr,[0,Hr,-1]],Hr];var hi=class extends ar{constructor(t){super(t)}},ci=[0,Fr,-1,zr,-3,Fr,xr,$r,Cr,Fr,-1,zr,Cr,zr,-2,$r],fi=class extends ar{constructor(t){super(t,500)}N(t){return ce(this,7,t)}},di=[-1,{}],pi=[0,Hr,1,di],mi=[0,Hr,Dr,di];function gi(t,e){de(t,1,fi,e)}var vi=class extends ar{constructor(t){super(t,500)}N(t){return ce(this,1001,t)}};vi.prototype.j=Zr([-500,Kr,[-500,$r,-1,Dr,-3,[-2,ui,Gr],Kr,ii,Cr,-1,pi,mi,Kr,[0,$r,zr],$r,ci,Cr,Dr,987,Dr],4,Kr,[-500,Hr,-1,[-1,{}],998,Hr],Kr,[-500,Hr,Dr,-1,[-2,{},Gr],997,Dr,-1],Cr,Kr,[-500,Hr,Dr,di,998,Dr],Dr,Cr,pi,mi,Kr,[0,$r,-1,di],Dr,-2,ci,$r,-1,zr,[0,zr,Jr],978,di,Kr,ii]);var yi,_i=class extends ar{constructor(t){super(t)}},wi=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 bi(t){if(t)return!0;if(void 0===yi)try{await WebAssembly.instantiate(wi),yi=!0}catch{yi=!1}return yi}async function Si(t,e,r){return{wasmLoaderPath:`${e}/${t}_${r=`wasm${r?"_module":""}${await bi(r)?"":"_nosimd"}_internal`}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var Ei=class{};Ei.forVisionTasks=function(t,e=!1){return Si("vision",t??si``,e)},Ei.forTextTasks=function(t,e=!1){return Si("text",t??si``,e)},Ei.forGenAiTasks=function(t,e=!1){return Si("genai",t??si``,e)},Ei.forAudioTasks=function(t,e=!1){return Si("audio",t??si``,e)},Ei.isSimdSupported=function(t=!1){return bi(t)};var Ai=class{close(){}};function Ii(t){function e(e,r){return new ReadableStream({start(){},async pull(i){n=n.then(async()=>{if(e.cache.length>0)i.enqueue(e.cache.shift());else{var{value:n,done:o}=await t.read();n&&(r.active&&r.cache.push(n),e.active&&i.enqueue(n)),o&&i.close()}}),await n},cancel(){e.active=!1,e.cache.length=0,r.active||t.cancel()}})}var r={cache:[],active:!0},i={cache:[],active:!0},n=Promise.resolve(),o=e(r,i);return r=e(i,r),[o.getReader(),r.getReader()]}async function Ti(t,e){for(var r=new Uint8Array(e),i=0;i<e;){let{value:n,done:o}=await t.read();if(n){let t=n.subarray(0,e-i);r.set(t,i),i+=t.length}if(o)throw Error(`Expected ${e} bytes, but stream ended after reading ${i} bytes.`)}return await t.cancel(),r}var Li=[[0,async t=>{var e=(new TextEncoder).encode("TFL3").length;return t=await Ti(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await Ti(t,6))[4]&&75===t[5]],[2,async t=>(t=await Ti(t,8),"LITERTLM"===new TextDecoder("utf-8").decode(t))]];async function Pi(t,e){var r=new Uint8Array(e),i=0;if(t.i){var n=Math.min(e,t.i.length);r.set(t.i.subarray(0,n),0),(i+=n)<t.i.length?t.i=t.i.subarray(i):t.i=void 0}for(;i<e;){let{value:o,done:a}=await t.stream.read();if(o&&(n=o.subarray(0,e-i),r.set(n,i),o.length>n.length&&(t.i=o.subarray(e-i)),i+=n.length),a)throw Error(`Expected ${e} bytes, but stream ended after reading ${i} bytes.`)}return r}class Oi{constructor(t){this.stream=t,this.i=void 0,this.closed=this.stream.closed}async read(){if(this.i){let t=this.i.slice();return this.i=void 0,{value:t,done:!1}}return this.stream.read()}cancel(t){return this.stream.cancel(t)}releaseLock(){return this.stream.releaseLock()}}function ji(){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 ki(t){if("function"!=typeof importScripts){let e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise((t,r)=>{e.addEventListener("load",()=>{t()},!1),e.addEventListener("error",t=>{r(t)},!1),document.body.appendChild(e)})}try{importScripts(t.toString())}catch(e){if(!(e instanceof TypeError))throw e;{let e=self.import;e?await e(t.toString()):await import(t.toString())}}}function Ui(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function xi(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");var i=new Uint32Array(e.length);for(let r=0;r<e.length;r++)i[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*i.length),t.h.HEAPU32.set(i,e>>2),r(e);for(let e of i)t.h._free(e);t.h._free(e)}function Bi(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function Ni(t,e,r){var i=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,n)=>{e?(r(i,n),i=[]):i.push(t)}}var Fi,Ri=(Fi=class{constructor(t,e){this.l=!0,this.h=t,this.i=null,this.j=0,this.o="function"==typeof this.h._addIntToInputStream,void 0!==e?this.h.canvas=e:ji()?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){var 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){var r=t.length,i=this.h._malloc(r);this.h.HEAPU8.set(t,i),e?this.h._changeBinaryGraph(r,i):this.h._changeTextGraph(r,i),this.h._free(i)}configureAudio(t,e,r,i,n){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),Ui(this,i||"input_audio",i=>{Ui(this,n=n||"audio_header",n=>{this.h._configureAudio(i,n,t,e??0,r)})})}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,i,n){var o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),Ui(this,i,t=>{this.h._addAudioToInputStream(this.i,e,r,t,n)})}addGpuBufferToStream(t,e,r){Ui(this,e,e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();var i=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!i)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1);var[n,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||n===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=n,this.h.canvas.height=o);var[a,s]=[n,o];this.h._addBoundTextureToStream(e,a,s,r)})}addBoolToStream(t,e,r){Ui(this,e,e=>{this.h._addBoolToInputStream(t,e,r)})}addDoubleToStream(t,e,r){Ui(this,e,e=>{this.h._addDoubleToInputStream(t,e,r)})}addFloatToStream(t,e,r){Ui(this,e,e=>{this.h._addFloatToInputStream(t,e,r)})}addIntToStream(t,e,r){Ui(this,e,e=>{this.h._addIntToInputStream(t,e,r)})}addUintToStream(t,e,r){Ui(this,e,e=>{this.h._addUintToInputStream(t,e,r)})}addStringToStream(t,e,r){Ui(this,e,e=>{Ui(this,t,t=>{this.h._addStringToInputStream(t,e,r)})})}addStringRecordToStream(t,e,r){Ui(this,e,e=>{xi(this,Object.keys(t),i=>{xi(this,Object.values(t),n=>{this.h._addFlatHashMapToInputStream(i,n,Object.keys(t).length,e,r)})})})}addProtoToStream(t,e,r,i){Ui(this,r,r=>{Ui(this,e,e=>{var n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputStream(n,t.length,e,r,i),this.h._free(n)})})}addEmptyPacketToStream(t,e){Ui(this,t,t=>{this.h._addEmptyPacketToInputStream(t,e)})}addBoolVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateBoolVector(t.length);if(!i)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(i,e);this.h._addBoolVectorToInputStream(i,e,r)})}addDoubleVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateDoubleVector(t.length);if(!i)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(i,e);this.h._addDoubleVectorToInputStream(i,e,r)})}addFloatVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateFloatVector(t.length);if(!i)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(i,e);this.h._addFloatVectorToInputStream(i,e,r)})}addIntVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateIntVector(t.length);if(!i)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(i,e);this.h._addIntVectorToInputStream(i,e,r)})}addUintVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateUintVector(t.length);if(!i)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(i,e);this.h._addUintVectorToInputStream(i,e,r)})}addStringVectorToStream(t,e,r){Ui(this,e,e=>{var i=this.h._allocateStringVector(t.length);if(!i)throw Error("Unable to allocate new string vector on heap.");for(let e of t)Ui(this,e,t=>{this.h._addStringVectorEntry(i,t)});this.h._addStringVectorToInputStream(i,e,r)})}addBoolToInputSidePacket(t,e){Ui(this,e,e=>{this.h._addBoolToInputSidePacket(t,e)})}addDoubleToInputSidePacket(t,e){Ui(this,e,e=>{this.h._addDoubleToInputSidePacket(t,e)})}addFloatToInputSidePacket(t,e){Ui(this,e,e=>{this.h._addFloatToInputSidePacket(t,e)})}addIntToInputSidePacket(t,e){Ui(this,e,e=>{this.h._addIntToInputSidePacket(t,e)})}addUintToInputSidePacket(t,e){Ui(this,e,e=>{this.h._addUintToInputSidePacket(t,e)})}addStringToInputSidePacket(t,e){Ui(this,e,e=>{Ui(this,t,t=>{this.h._addStringToInputSidePacket(t,e)})})}addProtoToInputSidePacket(t,e,r){Ui(this,r,r=>{Ui(this,e,e=>{var i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputSidePacket(i,t.length,e,r),this.h._free(i)})})}addBoolVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)})}addDoubleVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)})}addFloatVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)})}addIntVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)})}addUintVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)})}addStringVectorToInputSidePacket(t,e){Ui(this,e,e=>{var r=this.h._allocateStringVector(t.length);if(!r)throw Error("Unable to allocate new string vector on heap.");for(let e of t)Ui(this,e,t=>{this.h._addStringVectorEntry(r,t)});this.h._addStringVectorToInputSidePacket(r,e)})}attachBoolListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachBoolListener(t)})}attachBoolVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachBoolVectorListener(t)})}attachIntListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachIntListener(t)})}attachIntVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachIntVectorListener(t)})}attachUintListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachUintListener(t)})}attachUintVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachUintVectorListener(t)})}attachDoubleListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachDoubleListener(t)})}attachDoubleVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachDoubleVectorListener(t)})}attachFloatListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachFloatListener(t)})}attachFloatVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachFloatVectorListener(t)})}attachStringListener(t,e){Bi(this,t,e),Ui(this,t,t=>{this.h._attachStringListener(t)})}attachStringVectorListener(t,e){Ni(this,t,e),Ui(this,t,t=>{this.h._attachStringVectorListener(t)})}attachProtoListener(t,e,r){Bi(this,t,e),Ui(this,t,t=>{this.h._attachProtoListener(t,r||!1)})}attachProtoVectorListener(t,e,r){Ni(this,t,e),Ui(this,t,t=>{this.h._attachProtoVectorListener(t,r||!1)})}attachAudioListener(t,e,r){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),Bi(this,t,(t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)}),Ui(this,t,t=>{this.h._attachAudioListener(t,r||!1)})}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends Fi{la(){this.h._registerModelResourcesGraphService()}});async function Mi(t,e){var r=await(async(t,e,r)=>{var i=In;if(t&&await ki(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await ki(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&r&&((t=self.Module).locateFile=r.locateFile,r.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=r.mainScriptUrlOrBlob)),r=await self.ModuleFactory(self.Module||r),self.ModuleFactory=self.Module=void 0,new i(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return r.ka=new Ai,await r.N(e),r}async function Di(t,e){return Mi(t,e)}function Ci(t){try{let e=t.J.length;if(1===e)throw Error(t.J[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.J.map(t=>t.message).join(", "))}finally{t.J=[]}}function Vi(t,e){t.I=Math.max(t.I,e)}var Gi=class{constructor(t){this.j=t,this.J=[],this.I=0,this.j.setAutoRenderToScreen(!1)}setGraph(t,e){this.j.attachErrorListener((t,e)=>{this.J.push(Error(e))}),this.j.la(),this.j.setGraph(t,e),Ci(this)}finishProcessing(){this.j.finishProcessing(),Ci(this)}close(){this.ka?.close(),this.j.closeGraph()}};Gi.prototype.close=Gi.prototype.close;var zi=class extends ar{constructor(t){super(t)}j(){return Bt(Jt(this,2))??0}};function Hi(t,e){ce(t,1,e)}var Wi=class extends ar{constructor(t){super(t)}},$i=[0,Qr,Cr,Nr,-1,Mr];function qi(t,e,r,i){if(void 0!==t.data){var n=new Uint8Array(t.data.buffer,e,r);return 1===i&&function(t,e,r){t.i.push([e,r]),t.i.sort((t,e)=>t[0]-e[0]),e=0;for(let[i,n]of t.i){let t=n;(r=i)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),n}}zi.prototype.l=Zr($i);class Ki{constructor(t){this.i=[],this.data=t,this.length=t.length}}function Yi(t,e){return new Xi(async()=>{var{value:e,done:r}=await t.read();return r?void 0:e},e)}async function Ji(t,e,r,i,n){if(2===n)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout(()=>{t.l()},0),Promise.resolve(0);for(;t.size<r+i;){var o=await t.j();if(void 0===o)break;t.i.push(new Ki(o))}if(t.size<r+i)throw Error(`Data size is too small: ${t.size}, expected at least ${r+i}.`);o=e._malloc(i)>>>0;var a=0;for(let s=0;s<t.i.length;s++){let l=t.i[s];if(r>=l.length){r-=l.length;continue}let u=Math.min(i,l.length-r);if(void 0===(r=qi(l,r,u,n)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+a),r=0,a+=u,0===(i-=u))break}if(0!==i)throw Error("Data not found.");return Promise.resolve(o)}var Xi=class{constructor(t,e){this.i=[],this.j=t,this.l=e}get size(){var t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function Qi(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function Zi(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function tn(t,e,r){t=new rn(t,r);var i=0;for(e=e.getReader();;){let{value:r,done:n}=await e.read();if(n)break;t.set(r,i),i+=r.byteLength}if(r!==i)throw en(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${i}/${r} bytes before failure`);return t}function en(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var rn=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))}},nn=class extends ar{constructor(t){super(t)}};nn.prototype.j=Zr([0,$r,2,Dr,Cr,zr]);var on=class extends ar{constructor(t){super(t)}},an=class extends ar{constructor(t){super(t)}},sn=class extends ar{constructor(t){super(t)}},ln=class extends ar{constructor(t){super(t)}},un=[0,Cr,-6,1,Cr,1,[0,zr,Qr,-2],[0,zr,Nr],Qr,-2,[0,zr,-1,Qr,Nr,Xr,Mr,Gr,-2],1,zr,Cr,Mr,-1,[0,Qr,Cr],zr,-1,Br,Cr,-5,Br,-1,[0,Mr,Br],Mr,Gr,[0,Mr,-2],Br,[0,Cr],[0,Cr,-4],Gr,Mr,-2,Gr,-1,Nr,Br,Gr,Cr,-1,[0,Mr,-2],zr,Cr,Mr,Gr,[0,Mr,-1],Mr,Gr,-1],hn=[0,$r,-2],cn=[0,[4,6],un,Cr,1,Vr,Dr,qr,Wr,hn,Mr,[0,[0,Cr,-1,Kr,[0,Cr,[0,Cr,-1],-1,[0,Qr,-1],zr],zr,-2,Cr,-1],[0,Cr,-1,zr],un,zr,Cr,[0,Cr],-1],Hr,-3,[0,Cr,zr],un,[0,hn,-2],xr,Kr,[0,$r,-2],xr];ln.prototype.j=Zr([0,$r,8,[0,zr,-6],1,Cr,1,Cr,[0,Kr,[0,$r,Rr,-1,Qr],cn,Cr],[0,Cr,zr,-3],1,Qr,1,cn,1,Cr,5,Qr,xr,1,$i,zr,Cr,zr,-1]);var fn=class extends ar{constructor(t){super(t)}},dn=class extends ar{constructor(t){super(t)}},pn=[2,4];dn.prototype.j=Zr([0,pn,Cr,qr,Cr,Yr,[0,1,$r]]);var mn=function(t){return class extends t{constructor(){super(...arguments),this.P=!1,this.F=this.H=0}M(){if(this.P)throw Error("Cannot process because LLM inference engine is currently loading or processing.");this.P=!0}L(){this.P=!1}async createLlmInferenceEngine(t,e){this.M();try{let r=Yi(t,()=>{});await this.h.createLlmInferenceEngine(pe(e,2)??512,ue(e,zi,3)?.j()??40,Tt(Jt(e,6))??!1??!1,pe(e,7)??0,Tt(Jt(e,8))??!1??!1,(t,e,i)=>Ji(r,this.h,t,e,i))}finally{this.L()}}async ba(t,e){this.M();try{await this.na(t),await this.h.ccall("CreateLlmInferenceEngineConverted","void",["number","number","boolean"],[pe(e,2)??512,ue(e,zi,3)?.j()??40,Tt(Jt(e,6))??!1??!1],{async:!0})}finally{this.L()}}V(){this.M();try{let t=this.h;t.ccall("DeleteLlmInferenceEngine","void",[],[],{async:!1}),this.H&&(t._FreeSession(this.H),this.F===this.H&&(this.F=0),this.H=0),this.F&&(t._FreeSession(this.F),this.F=0)}finally{this.L()}}async R(t,e,r){this.M();try{let i=[],n=this.h;n._userProgressListener=(t,e)=>{t&&i.push(t),r&&r(t,e)};let o=e.l(),a=o.length,s=this.h._malloc(a);this.h.HEAPU8.set(o,s);let l=t.some(Zi),u=t.some(Qi);n.ccallNum=n.ccall;let h=await n.ccallNum("MakeSessionForPredict","number",["number","number","boolean","boolean"],[s,a,u,l],{async:!0});e=[];for(let r of t)if("string"==typeof r)Ui(this,r,t=>{n._AddTextQueryChunk(h,t)});else if(Qi(r)){let{image:t,width:i,height:o}=await this.fa(r.imageSource),a="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(i,o):document.createElement("canvas");a.width=i,a.height=o;let s=a.getContext("2d");s.drawImage(t,0,0);let l=s.getImageData(0,0,i,o),u=this.h._malloc(l.width*l.height*4);this.h.HEAPU8.set(l.data,u),n._AddImageQueryChunk(h,u,l.width,l.height),e.push(u)}else{if(!Zi(r))throw Error("Unsupported PromptPart type in query.");{let t=await this.ea(r.audioSource),i=this.h._malloc(t.audioSamples.byteLength);this.h.HEAPF32.set(t.audioSamples,i/4),n._AddAudioQueryChunk(h,t.audioSampleRateHz,i,t.audioSamples.length),e.push(i)}}await n.ccall("PredictSession","void",["number"],[h],{async:!0}),t=!0,u&&0===this.F&&(this.F=h,t=!1),l&&0===this.H&&(this.H=h,t=!1),t&&n._FreeSession(h);for(let t of e)this.h._free(t);return e.length=0,r&&r("",!0),this.h._free(s),n._userProgressListener=void 0,i.join("")}finally{this.L()}}S(t){this.M();var e=0,r="";for(let i of t)"string"==typeof i?r+=i:Qi(i)?e+=260:Zi(i)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return Ui(this,r,e=>{t=this.h._GetSizeInTokens(e)}),e+t}finally{this.L()}}async na(t){t=await async function(t){for(var e=[],r=0;;){let{done:i,value:n}=await t.read();if(i)break;e.push(n),r+=n.length}if(0===e.length)return new Uint8Array(0);if(1===e.length)return e[0];t=new Uint8Array(r),r=0;for(let i of e)t.set(i,r),r+=i.length;return t}(t);try{this.h.FS_unlink("llm.task")}catch{}this.h.FS_createDataFile("/","llm.task",t,!0,!1,!1)}async fa(t){if("string"==typeof t){let e=new Image;e.src=t,e.crossOrigin="Anonymous";try{await e.decode()}catch{throw Error(`Image from URL ${t} failed to load`)}return{image:e,width:e.naturalWidth,height:e.naturalHeight}}if(t instanceof HTMLImageElement){try{await t.decode()}catch{throw Error("Image from HTMLImageElement failed to load")}return{image:t,width:t.naturalWidth,height:t.naturalHeight}}return t instanceof HTMLVideoElement?{image:t,width:t.videoWidth,height:t.videoHeight}:t instanceof VideoFrame?{image:t,width:t.displayWidth,height:t.displayHeight}:{image:t,width:t.width,height:t.height}}async ea(t){if("string"==typeof t){let e=await fetch(t);if(!e.ok)throw Error(`Audio fetch for ${t} had error: ${e.status}`);return t=await e.arrayBuffer(),{audioSamples:(t=await new AudioContext({sampleRate:16e3}).decodeAudioData(t)).getChannelData(0),audioSampleRateHz:t.sampleRate}}return"object"==typeof t&&null!=t&&"audioSamples"in t&&"audioSampleRateHz"in t?t:{audioSamples:t.getChannelData(0),audioSampleRateHz:t.sampleRate}}}}(function(t){var e=class extends t{static async ma(t,r){r||=await e.X();var i=[];for(let e of t?.requiredFeatures??[])r.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{var n=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return(t=n).adapterInfo||(t.adapterInfo=r.info),n}static async X(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}ga(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}aa(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}};return e}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket((e,r,i)=>Ji(t,this.h,e,r,i),e)}}}(function(t){return class extends t{Y(t,e){Ui(this,"lora_model_ref_in",r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)})}}}(class extends Ri{}))));class gn extends mn{}var vn=class{constructor(t){this.j=t,this.i=yn,yn++}},yn=1;class _n{constructor(){var t,e;this.promise=new Promise((r,i)=>{t=r,e=i}),this.resolve=t,this.reject=e}}function wn(t){return 1===t?1:t+t%2}async function bn(){var t=await gn.X({powerPreference:"high-performance"}),e=t.limits.maxBufferSize,r=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}`),r<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 ${r}`),e={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:r,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."),e.requiredFeatures=["shader-f16","subgroups"]),gn.ma(e,t)}function Sn(t){if(t.D.length>0){let e=[...t.D];if(t.D.length=0,!t.o)throw e;t.o.reject(e),t.o=void 0}}function En(t){var e=function(t){var e=new vi;we(e,10,"text_in"),we(e,10,"token_cost_in"),we(e,10,"lora_model_id_to_apply_in"),we(e,10,"lora_model_ref_in"),we(e,10,"lora_model_id_to_load_in"),we(e,16,"streaming_reader"),we(e,15,"text_out"),we(e,15,"text_end"),we(e,15,"token_cost_out");var r=new fi;_e(r,2,"TokenizerInputBuildCalculator"),we(r,3,"PROMPT:text_in"),we(r,3,"LORA_ID:lora_model_id_to_apply_in"),we(r,4,"prompt"),gi(e,r),r=new fi,_e(r,2,"ModelDataCalculator"),we(r,6,"MODEL_DATA:__side_packet_1"),we(r,6,"MODEL_TYPE:model_type"),we(r,5,"READ_DATA_FN:streaming_reader"),we(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),we(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),we(r,4,"LORA_DATA:lora_model_data"),gi(e,r),r=new fi,_e(r,2,"Gpt2UnicodeMappingCalculator"),we(r,5,"MODEL_TYPE:model_type"),we(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),gi(e,r),r=new ri,_e(r,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var i=new dn,n=pe(t.i,2);ve(i,1,n),_e(n=new fn,2,"spm_vocab_model"),n=he(n);t:{qt(i);var o=i.m,a=0|o[G];if(null==n){var s=se(o);if(4!==le(s,o,a))break t;s.set(pn,0)}else{let t=se(s=o),e=le(t,s,a);4!==e&&(e&&(a=Zt(s,a,e)),t.set(pn,4))}Zt(o,a,4,n)}return n&&!q(n)&&Kt(i.m),ve(i,3,2),ti(r,i.j()),_e(i=new fi,2,"TokenizerCalculator"),de(i,8,ri,r),we(i,5,"MODEL_DATA:__side_packet_1"),we(i,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),we(i,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),we(i,6,"PROCESSOR_GETTER:__input_side_1"),we(i,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),gi(e,i),r=new ri,_e(r,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),ve(i=new ln,12,3),_e(i,1,"llm.tflite"),ve(i,14,0),n=wn(pe(t.i,5)),ve(i,22,n),n=ue(t.i,zi,3),ce(i,31,n),ge(n=new on,1,!0),null!=Tt(Jt(t.i,6))&&(Tt(Jt(t.i,6))??!1)&&ge(n,1,!1),ge(n,2,!0),ge(n,5,!0),ce(i,10,n),n=te(t.i,4,Bt,void 0===Y?2:4),oe(i,29,n),n=new sn,ve(o=new an,1,1),s=pe(t.i,2),ve(o,2,s),null!=Tt(Jt(t.i,9))&&(Tt(Jt(t.i,9))??!1)&&(ge(i,35,!0),me(o,60,!0)),ce(n,1,o),ce(i,20,n),ti(r,i.j()),_e(i=new fi,2,"LlmGpuCalculator"),de(i,8,ri,r),we(i,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),we(i,3,"FINISH:finish"),we(i,3,"LORA_DATA:lora_model_data"),we(i,5,"MODEL_DATA:__side_packet_1"),we(i,4,"DECODED_IDS:__stream_3"),we(i,4,"OUTPUT_END:__stream_4"),r=new hi,_e(r,1,"FINISH"),ge(r,2,!0),de(i,13,hi,r),gi(e,i),r=new fi,_e(r,2,"IsPacketPresentCalculator"),we(r,3,"__stream_4"),we(r,4,"text_end"),gi(e,r),r=new ri,_e(r,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),i=new nn,t=wn(pe(t.i,5)),ve(i,5,t),we(i,4,"<eos>"),we(i,4,"<|endoftext|>"),ti(r,i.j()),t=new fi,_e(t,2,"DetokenizerCalculator"),de(t,8,ri,r),we(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),we(t,5,"PROCESSOR_GETTER:__input_side_1"),we(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),we(t,5,"MODEL_DATA:__side_packet_1"),we(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),we(t,4,"WORDS:text_out"),gi(e,t),t=new fi,_e(t,2,"TokenCostCalculator"),we(t,3,"PROMPT:token_cost_in"),we(t,5,"PROCESSOR_GETTER:__input_side_1"),we(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),we(t,4,"NUM_TOKENS:token_cost_out"),gi(e,t),e}(t);t.j.attachStringVectorListener("text_out",(e,r)=>{e=function(t,e){return null==t||0===t.length?[]:t.map(t=>(t=(t=t.replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),e&&(t=t.trimStart()),t.split("\\[eod\\]",1)[0]))}(e,0===t.G.length),e.forEach((e,r)=>{r<pe(t.i,5)&&t.G[r].push(e)}),t.A&&0===t.D.length&&(t.B?(e.length>pe(t.i,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),Vi(t,r)}),t.j.attachEmptyPacketListener("text_out",e=>{Vi(t,e)}),t.j.attachBoolListener("text_end",(e,r)=>{Vi(t,r);try{Sn(t)}catch(e){throw t.l=!1,e}if(t.o&&(t.o.resolve(t.G.map(t=>t.join(""))),t.o=void 0),t.A)if(t.B){for(e=[],r=0;r<pe(t.i,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.l=!1,t.B=void 0}),t.j.attachEmptyPacketListener("text_end",e=>{t.l=!1,t.B=void 0,Vi(t,e),Sn(t),t.o&&(t.o.resolve(t.G.map(t=>t.join(""))),t.o=void 0)}),t.j.attachIntListener("token_cost_out",(e,r)=>{t.T=e,Vi(t,r)}),t.U&&t.j.addStreamingReaderToInputSidePacket(t.U,"streaming_reader");var r=e.j();return t.C?.removeEventListener("uncapturederror",t.K),t.j.aa().then(()=>{t.C?.addEventListener("uncapturederror",t.K),t.D.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()})}function An(t,e,r,i){if(t.A="function"==typeof r?r:i,(i=(e=Array.isArray(e)?e:[e]).filter(t=>Qi(t)).length)>0&&(null==Nt(Jt(t.i,7))||pe(t.i,7)<i))throw Error(`maxNumImages is set to ${null!=Nt(Jt(t.i,7))?pe(t.i,7):0}, but the query included ${i} images.`);if((i=e.filter(t=>Zi(t)).length)>0&&(null==Tt(Jt(t.i,8))||!Tt(Jt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${i} audio chunks.`);if(t.v){if(t.B&&pe(t.i,5)>1)throw Error("Multi-response generation is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality or request only one response.");if(r instanceof vn)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality to use LoRA.");return t.j.h.LLM_CANCEL_FLAG=void 0,t.j.R(e,t.u,(e,r)=>{0===t.D.length&&t.A&&(t.B?t.A([e],r):t.A(e,r))}).then(e=>(Sn(t),[e]))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.j.h.LLM_CANCEL_FLAG=void 0,t.G.length=0,i=0;i<pe(t.i,5);i++)t.G[i]=[];if(i=t.I+1,t.j.addStringToStream(e.join(""),"text_in",i),r instanceof vn){if(r.j!==t)throw t.l=!1,t.B=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.j.addUintToStream(r.i,"lora_model_id_to_apply_in",i)}else t.j.addEmptyPacketToStream("lora_model_id_to_apply_in",i);return t.finishProcessing(),t.o=new _n,t.o.promise}var In=class extends Gi{constructor(t,e){if(super(new gn(t,e)),this.G=[],this.O=this.v=this.l=!1,this.D=[],this.K=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.D.push(t)},this.i=new Wi,Hi(this.i,new _i),this.u=new zi,ce(this.i,3,this.u),ye(this.i,2,512),t=this.u,!bt(2))throw O("enum");ae(t,1,2,0),ve(this.u,2,40),ae(this.u,3,Et(1),0),Qt(this.u,5,xt(0)),ae(this.u,4,Et(.8),0),ye(this.i,5,1)}async N(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");var e,r=new Promise(t=>{e=t});if(t.baseOptions?.modelAssetPath){var i=await fetch(t.baseOptions.modelAssetPath.toString());if(!i.ok)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (${i.status})`);if(!i.body)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (no body)`);i=i.body.getReader()}else t.baseOptions?.modelAssetBuffer instanceof Uint8Array?i=function(t){return new ReadableStream({start(){},async pull(e){e.enqueue(t),e.close()}})}(t.baseOptions.modelAssetBuffer).getReader():t.baseOptions?.modelAssetBuffer instanceof ReadableStreamDefaultReader?(i=t.baseOptions.modelAssetBuffer,t.baseOptions.modelAssetBuffer=void 0):e();if(!i)throw Error("No model asset provided.");{let[r,a]=Ii(i);var n=await async function(t){var e,r=[];for(let[n,o]of Li){let a=n;var i=o;[t,e]=Ii(t),i=await i(e),await e.cancel(),i&&r.push(a)}if(await t.cancel(),0===r.length)throw Error("No model format matched.");if(1===r.length)return r[0];throw Error(`Multiple model formats matched: ${r}`)}(a);this.O=1===n;var o=null;if(2===n){let t=this.j.h;o=await async function(t,e){t=new Oi(t);var r=await Pi(t,32);if(r=new DataView(r.buffer),r=Number(r.getBigUint64(24,!0)),(e=e(await Pi(t,r-32)))<0)throw Error(".litertlm file could not be read or did not contain a web-formatted LLM");return await Pi(t,e-r),t}(r,e=>{var r=t._malloc(e.length);return t.HEAPU8.set(e,r),e=t._GetLiteRtModelOffset(r),t._free(r),e})}n="maxNumImages"in t&&t.maxNumImages?t.maxNumImages:0,ye(this.i,7,n);let s="supportAudio"in t&&!!t.supportAudio;me(this.i,8,s),this.O||n>0||s?(this.v=!0,i=o||r):(this.v=!1,this.U=Yi(o||r,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.K),this.C=t.baseOptions.gpuOptions.device,this.j.ga(this.C),this.C.addEventListener("uncapturederror",this.K)),"maxTokens"in t&&ye(this.i,2,t.maxTokens??512),"topK"in t&&ve(this.u,2,t.topK??40),"temperature"in t&&ae(this.u,4,Et(t.temperature??.8),0),"randomSeed"in t&&Qt(this.u,5,xt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){oe(t,4,e)}(this.i,t.loraRanks??[]),"numResponses"in t){if((o=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&o>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet, and is also not supported with multimodality.");ye(this.i,5,o),n=ue(this.i,zi,3),o>1&&n&&(n.j()<=1||(Jt(n,4,At)??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.")}if("forceF32"in t&&void 0!==t.forceF32&&me(this.i,6,t.forceF32),"disableRewinding"in t&&void 0!==t.disableRewinding){if(this.v&&t.disableRewinding)throw Error("'disableRewinding' is not supported for converted LLM models yet, and is also not supported with multimodality.");me(this.i,9,t.disableRewinding)}return this.v?(this.j.V(),this.O?this.j.ba(i,this.i).then(()=>{Sn(this)}):this.j.createLlmInferenceEngine(i,this.i).then(()=>{Sn(this)})):(this.l=!0,t=En(this).then(()=>{}),Promise.all([r,t]).then(()=>{this.l=!1,Sn(this)}))}get baseOptions(){return ue(this.i,_i,1)}set baseOptions(t){Hi(this.i,t)}get isIdle(){return!this.l&&!this.o}R(t,e,r){return pe(this.i,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.B=!1,An(this,t,e,r).then(t=>t[0])}da(t,e,r){return this.B=!0,An(this,t,e,r)}S(t){if(t=Array.isArray(t)?t:[t],this.v)return this.j.S(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");if(t.some(Qi))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(Zi))throw Error("sizeInTokens requires supportAudio for audio.");return t=t.join(""),this.l=!0,this.T=void 0,this.j.addStringToStream(t,"token_cost_in",this.I+1),this.finishProcessing(),this.l=!1,this.T}Z(){var t=this.j.h;(this.v||this.l)&&(t.LLM_CANCEL_FLAG=1)}async ja(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the old format (.bin) without multimodality 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 rn(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return tn(t,e.stream(),e.size)}(this.j.h,t):await async function(t,e){e=await fetch(e.toString());var r=Number(e.headers.get("content-length"));if(!e.body)throw Error("Response body is not available.");if(!r)throw Error("File size is 0.");return tn(t,e.body,r)}(this.j.h,t);e=new vn(this);var r=this.I+1;return this.j.Y(t,r),this.j.addUintToStream(e.i,"lora_model_id_to_load_in",r),this.finishProcessing(),en(t),Vi(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};return In.prototype.loadLoraModel=In.prototype.ja,In.prototype.cancelProcessing=In.prototype.Z,In.prototype.sizeInTokens=In.prototype.S,In.prototype.generateResponses=In.prototype.da,In.prototype.generateResponse=In.prototype.R,In.prototype.setOptions=In.prototype.N,In.createWebGpuDevice=bn,In.createFromModelPath=async function(t,e){return Di(t,e={baseOptions:{gpuOptions:{device:await bn()},modelAssetPath:e}})},In.createFromModelBuffer=async function(t,e){return Di(t,e={baseOptions:{gpuOptions:{device:await bn()},modelAssetBuffer:e}})},In.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){let t=await bn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Di(t,e)},t.FilesetResolver=Ei,t.LlmInference=In,t.TaskRunner=Gi,t}({});
|
|
2
2
|
//# sourceMappingURL=genai_bundle_iife.js.map
|