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