@mediapipe/tasks-genai 0.10.12 → 0.10.13-rc.20240412

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,12 @@ This package contains the GenAI tasks for MediaPipe.
6
6
 
7
7
  The MediaPipe LLM Inference task generates text response from input text.
8
8
 
9
+ In order to begin, you must have a model available. You can download [Gemma
10
+ 2B](https://www.kaggle.com/models/google/gemma/frameworks/tfLite/variations/gemma-2b-it-gpu-int4)
11
+ (TensorFlow Lite 2b-it-gpu-int4 or 2b-it-gpu-int8) or convert an external LLM
12
+ (Phi-2, Falcon, or StableLM) following the
13
+ [guide](https://developers.google.com/mediapipe/solutions/genai/llm_inference/web_js#convert-model).
14
+ Note that only models encoded for the GPU backend are currently supported.
9
15
  ```
10
16
  const genai = await FilesetResolver.forGenAiTasks(
11
17
  "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai/wasm"
package/genai.d.ts CHANGED
@@ -177,6 +177,17 @@ export declare class LlmInference extends TaskRunner {
177
177
  * @return The generated text result.
178
178
  */
179
179
  generateResponse(text: string, progressListener: ProgressListener): Promise<string>;
180
+ /**
181
+ * Runs an invocation of *only* the tokenization for the LLM, and returns
182
+ * the size (in tokens) of the result. Cannot be called while
183
+ * a `generateResponse()` query is active. Runs synchronously.
184
+ *
185
+ * @export
186
+ * @param text The text to tokenize.
187
+ * @return The number of tokens in the resulting tokenization of the text.
188
+ * May return undefined if an error occurred.
189
+ */
190
+ sizeInTokens(text: string): number | undefined;
180
191
  close(): void;
181
192
  }
182
193
 
package/genai_bundle.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="undefined"!=typeof self?self:{};function e(e){t:{for(var r=["CLOSURE_FLAGS"],n=t,i=0;i<r.length;i++)if(null==(n=n[r[i]])){r=null;break t}r=n}return null!=(e=r&&r[e])&&e}let r;const n="undefined"!=typeof TextEncoder;function i(t){if(n)t=(r||=new TextEncoder).encode(t);else{let r=0;const n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var e=t.charCodeAt(i);if(128>e)n[r++]=e;else{if(2048>e)n[r++]=e>>6|192;else{if(55296<=e&&57343>=e){if(56319>=e&&i<t.length){const o=t.charCodeAt(++i);if(56320<=o&&57343>=o){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}i--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var o,s=e(610401301),a=e(188588736);const u=t.navigator;function c(t){return!!s&&(!!o&&o.brands.some((({brand:e})=>e&&-1!=e.indexOf(t))))}function l(e){var r;return(r=t.navigator)&&(r=r.userAgent)||(r=""),-1!=r.indexOf(e)}function h(){return!!s&&(!!o&&0<o.brands.length)}function f(){return h()?c("Chromium"):(l("Chrome")||l("CriOS"))&&!(!h()&&l("Edge"))||l("Silk")}o=u&&u.userAgentData||null;var d=!h()&&(l("Trident")||l("MSIE"));!l("Android")||f(),f(),l("Safari")&&(f()||!h()&&l("Coast")||!h()&&l("Opera")||!h()&&l("Edge")||(h()?c("Microsoft Edge"):l("Edg/"))||h()&&c("Opera"));var p={},g=null;function m(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var n=new Uint8Array(r),i=0;return function(t,e){function r(e){for(;n<t.length;){var r=t.charAt(n++),i=g[r];if(null!=i)return i;if(!/^[\s\xa0]*$/.test(r))throw Error("Unknown base64 encoding at char: "+r)}return e}_();for(var n=0;;){var i=r(-1),o=r(0),s=r(64),a=r(64);if(64===a&&-1===i)break;e(i<<2|o>>4),64!=s&&(e(o<<4&240|s>>2),64!=a&&e(s<<6&192|a))}}(t,(function(t){n[i++]=t})),i!==r?n.subarray(0,i):n}function _(){if(!g){g={};for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"],r=0;5>r;r++){var n=t.concat(e[r].split(""));p[r]=n;for(var i=0;i<n.length;i++){var o=n[i];void 0===g[o]&&(g[o]=i)}}}}var y="undefined"!=typeof Uint8Array,b=!d&&"function"==typeof btoa;function v(t){if(!b){var e;void 0===e&&(e=0),_(),e=p[e];var r=Array(Math.floor(t.length/3)),n=e[64]||"";let u=0,c=0;for(;u<t.length-2;u+=3){var i=t[u],o=t[u+1],s=t[u+2],a=e[i>>2];i=e[(3&i)<<4|o>>4],o=e[(15&o)<<2|s>>6],s=e[63&s],r[c++]=a+i+o+s}switch(a=0,s=n,t.length-u){case 2:s=e[(15&(a=t[u+1]))<<2]||n;case 1:t=t[u],r[c]=e[t>>2]+e[(3&t)<<4|a>>4]+s+n}return r.join("")}for(e="",r=0,n=t.length-10240;r<n;)e+=String.fromCharCode.apply(null,t.subarray(r,r+=10240));return e+=String.fromCharCode.apply(null,r?t.subarray(r):t),btoa(e)}const w=/[-_.]/g,S={"-":"+",_:"/",".":"="};function A(t){return S[t]||""}function I(t){if(!b)return m(t);w.test(t)&&(t=t.replace(w,A)),t=atob(t);const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function T(t){return y&&null!=t&&t instanceof Uint8Array}let E;var P={};let O;function L(t){if(t!==P)throw Error("illegal external caller")}function x(){return O||=new B(null,P)}var B=class{constructor(t,e){if(L(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function F(t){if("string"==typeof t)return{buffer:I(t),s:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),s:!1};if(t.constructor===Uint8Array)return{buffer:t,s:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),s:!1};if(t.constructor===B){L(P);var e=t.i;return{buffer:(null==(e=null==e||T(e)?e:"string"==typeof e?I(e):null)?e:t.i=e)||(E||=new Uint8Array(0)),s:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),s:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}function k(){return"function"==typeof BigInt}let U,V=0,j=0;function N(t){const e=0>t;let r=(t=Math.abs(t))>>>0;if(t=Math.floor((t-r)/4294967296),e){const[e,n]=G(r,t);t=n,r=e}V=r>>>0,j=t>>>0}function C(t,e){if(t>>>=0,2097151>=(e>>>=0))var r=""+(4294967296*e+t);else k()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,1e7<=t&&(r+=Math.floor(t/1e7),t%=1e7),1e7<=r&&(e+=Math.floor(r/1e7),r%=1e7),r=e+D(r)+D(t));return r}function D(t){return t=String(t),"0000000".slice(t.length)+t}function M(t){if(16>t.length)N(Number(t));else if(k())t=BigInt(t),V=Number(t&BigInt(4294967295))>>>0,j=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);j=V=0;const r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){const e=Number(t.slice(n,i));j*=1e6,V=1e6*V+e,4294967296<=V&&(j+=Math.trunc(V/4294967296),j>>>=0,V>>>=0)}if(e){const[t,e]=G(V,j);V=t,j=e}}}function G(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function R(t){return t?/^\d+$/.test(t)?(M(t),new W(V,j)):null:z||=new W(0,0)}var W=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let z;function H(t){return t?/^-?\d+$/.test(t)?(M(t),new $(V,j)):null:q||=new $(0,0)}var $=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let q;function K(t,e,r){for(;0<r||127<e;)t.i.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.i.push(e)}function Y(t,e){for(;127<e;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function J(t,e){if(0<=e)Y(t,e);else{for(let r=0;9>r;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function X(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Q(t,e){return Y(t.i,8*e+2),e=t.i.end(),X(t,e),e.push(t.j),e}function Z(t,e){var r=e.pop();for(r=t.j+t.i.length()-r;127<r;)e.push(127&r|128),r>>>=7,t.j++;e.push(r),t.j++}function tt(t,e,r){Y(t.i,8*e+2),Y(t.i,r.length),X(t,t.i.end()),X(t,r)}var et;class rt{constructor(t,e){this.i=t,this.I=e}}function nt(t){return Array.prototype.slice.call(t)}var it=(et="function"==typeof Symbol&&"symbol"==typeof Symbol()?Symbol():void 0)?(t,e)=>{t[et]|=e}:(t,e)=>{void 0!==t.i?t.i|=e:Object.defineProperties(t,{i:{value:e,configurable:!0,writable:!0,enumerable:!1}})},ot=et?(t,e)=>{t[et]&=~e}:(t,e)=>{void 0!==t.i&&(t.i&=~e)};function st(t,e,r){return r?t|e:t&~e}var at=et?t=>0|t[et]:t=>0|t.i,ut=et?t=>t[et]:t=>t.i,ct=et?(t,e)=>(t[et]=e,t):(t,e)=>(void 0!==t.i?t.i=e:Object.defineProperties(t,{i:{value:e,configurable:!0,writable:!0,enumerable:!1}}),t);function lt(t,e){ct(e,-14591&(0|t))}function ht(t,e){ct(e,-14557&(34|t))}function ft(t){return 0===(t=t>>14&1023)?536870912:t}var dt,pt={},gt={};function mt(t){return!(!t||"object"!=typeof t||t.i!==gt)}function _t(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function yt(t,e,r){if(!Array.isArray(t)||t.length)return!1;const n=at(t);return!!(1&n)||!(!e||!(Array.isArray(e)?e.includes(r):e.has(r)))&&(ct(t,1|n),!0)}const bt=[];function vt(t){if(2&t)throw Error()}ct(bt,55),dt=Object.freeze(bt);function wt(t){return(t=Error(t)).__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity="warning",t}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}Object.freeze(new class{}),Object.freeze(new class{});const At=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function It(t){const e=typeof t;return"number"===e?Number.isFinite(t):"string"===e&&At.test(t)}function Tt(t){if(null!=t){if("number"!=typeof t)throw wt("int32");if(!Number.isFinite(t))throw wt("int32");t|=0}return t}function Et(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function Pt(t){if(null!=t){if("number"!=typeof t)throw wt("uint32");if(!Number.isFinite(t))throw wt("uint32");t>>>=0}return t}function Ot(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?t>>>0:void 0}function Lt(t){return"-"!==t[0]&&(20>t.length||20===t.length&&184467>Number(t.substring(0,6)))}function xt(t){return null==t||"string"==typeof t?t:void 0}function Bt(t,e,r){if(null!=t&&"object"==typeof t&&t.D===pt)return t;if(Array.isArray(t)){var n=at(t),i=n;return 0===i&&(i|=32&r),(i|=2&r)!==n&&ct(t,i),new e(t)}}let Ft,kt,Ut;function Vt(t,e,r){if(null==t&&(t=Ft),Ft=void 0,null==t){var n=96;r?(t=[r],n|=512):t=[],e&&(n=-16760833&n|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error();if(2048&(n=at(t)))throw Error();if(64&n)return t;if(n|=64,r&&(n|=512,r!==t[0]))throw Error();t:{const i=(r=t).length;if(i){const t=i-1;if(_t(r[t])){if(1024<=(e=t-(+!!(512&(n|=256))-1)))throw Error();n=-16760833&n|(1023&e)<<14;break t}}if(e){if(1024<(e=Math.max(e,i-(+!!(512&n)-1))))throw Error();n=-16760833&n|(1023&e)<<14}}}return ct(t,n),t}function jt(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=yt(t,void 0,0)?void 0:i&&2&at(t)?t:Nt(t,e,r,void 0!==n,i);else if(_t(t)){const o={};for(let s in t)o[s]=jt(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function Nt(t,e,r,n,i){const o=n||r?at(t):0;n=n?!!(32&o):void 0,t=nt(t);for(let o=0;o<t.length;o++)t[o]=jt(t[o],e,r,n,i);return r&&r(o,t),t}function Ct(t){return t.D===pt?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"boolean":return t?1:0;case"object":if(t)if(Array.isArray(t)){if(yt(t,void 0,0))return}else{if(T(t))return v(t);if(t instanceof B){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=v(e)}}}return t}(t)}function Dt(t,e,r=ht){if(null!=t){if(y&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=at(t);return 2&n?t:(e&&=0===n||!!(32&n)&&!(64&n||!(16&n)),e?ct(t,-12293&(34|n)):Nt(t,Dt,4&n?ht:r,!0,!0))}return t.D===pt&&(r=t.m,t=2&(n=ut(r))?t:Mt(t,r,n,!0)),t}}function Mt(t,e,r,n){return t=t.constructor,Ft=e=function(t,e,r){const n=r||2&e?ht:lt,i=!!(32&e);return t=function(t,e,r){var n=(t=nt(t)).length;const i=256&e?t[n-1]:void 0;for(n+=i?-1:0,e=512&e?1:0;e<n;e++)t[e]=r(t[e]);if(i){e=t[e]={};for(const t in i)e[t]=r(i[t])}return t}(t,e,(t=>Dt(t,i,n))),it(t,32|(r?2:0)),t}(e,r,n),e=new t(e),Ft=void 0,e}function Gt(t){const e=t.m,r=ut(e);return 2&r?Mt(t,e,r,!1):t}function Rt(t){return Wt(t=t.m,ut(t),2)}function Wt(t,e,r,n){if(-1===r)return null;if(r>=ft(e)){if(256&e)return t[t.length-1][r]}else{var i=t.length;if(n&&256&e&&null!=(n=t[i-1][r]))return n;if((e=r+(+!!(512&e)-1))<i)return t[e]}}function zt(t,e,r){const n=t.m;let i=ut(n);return vt(i),Ht(n,i,e,r),t}function Ht(t,e,r,n,i){const o=ft(e);if(r>=o||i){let s=e;if(256&e)i=t[t.length-1];else{if(null==n)return s;i=t[o+(+!!(512&e)-1)]={},s|=256}return i[r]=n,r<o&&(t[r+(+!!(512&e)-1)]=void 0),s!==e&&ct(t,s),s}return t[r+(+!!(512&e)-1)]=n,256&e&&(r in(t=t[t.length-1])&&delete t[r]),e}function $t(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function qt(t,e,r,n){t=t.m;let i=ut(t);vt(i),Ht(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function Kt(t,e,r){var n=t.m,i=ut(n),o=Wt(n,i,r,!1);return(e=Bt(o,e,i))!==o&&null!=e&&Ht(n,i,r,e,!1),null==(n=e)||(t=t.m,2&(i=ut(t))||(o=Gt(n))!==n&&Ht(t,i,r,n=o,!1)),n}function Yt(t,e,r){return null==r&&(r=void 0),zt(t,e,r)}function Jt(t,e){return t=st(t,2,!!(2&e)),t=st(t,32,!!(32&e)&&!0),st(t,2048,!1)}function Xt(t,e,r,n){t=t.m;var i=ut(t);vt(i);var o=!!(2&i),s=o?1:2;const a=1===s;s=2===s,d&&=!o,o=Wt(t,i,e),o=Array.isArray(o)?o:dt;var u=at(o);const c=!!(4&u);if(!c){var l=u;0===l&&(l=Jt(l,i)),u=o;var h=i,f=!!(2&(l=st(l,1,!0)));f&&(h=st(h,2,!0));let t=!f,e=!0,n=0,s=0;for(;n<u.length;n++){const i=Bt(u[n],r,h);if(i instanceof r){if(!f){const r=!!(2&at(i.m));t&&=!r,e&&=r}u[s++]=i}}s<n&&(u.length=s),l=st(l,4,!0),l=st(l,16,e),l=st(l,8,t),ct(u,l),f&&Object.freeze(u),u=l}if(l=!!(8&u)||a&&!o.length,d&&!l){$t(u)&&(o=nt(o),u=Jt(u,i),i=Ht(t,i,e,o));var d=o;for(l=0;l<d.length;l++)(h=d[l])!==(f=Gt(h))&&(d[l]=f);u=st(u,8,!0),u=st(u,16,!d.length),ct(d,u)}$t(u)||(d=u,a&&(u=st(u,!o.length||16&u&&(!c||32&u)?2:2048,!0)),u!==d&&ct(o,u),a&&Object.freeze(o)),s&&$t(u)&&(o=nt(o),u=Jt(u,i),ct(o,u),Ht(t,i,e,o)),e=o,r=null!=n?n:new r,e.push(r),2&at(r.m)?ot(e,8):ot(e,16)}function Qt(t,e,r){qt(t,e,Tt(r),0)}function Zt(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();qt(t,e,r,"")}function te(t,e,r){t=t.m;const n=ut(t);vt(n);var i=2&n;let o=Wt(t,n,e);Array.isArray(o)||(o=dt);const s=!!(32&n);let a=at(o);if(0===a&&s&&!i?(a|=33,ct(o,a)):1&a||(a|=1,ct(o,a)),i?(2&a||it(o,34),Object.freeze(o)):(2&a||2048&a)&&(o=nt(o),i=1,s&&(i|=32),ct(o,i),Ht(t,n,e,o)),"string"!=typeof r)throw Error();o.push(r)}var ee=class{constructor(t,e){this.m=Vt(t,e)}toJSON(){return re(this,Nt(this.m,Ct,void 0,void 0,!1),!0)}s(){return!!(2&at(this.m))}};function re(t,e,r){var n=a?void 0:t.constructor.v;const i=ut(r?t.m:e);if(!(t=e.length))return e;let o,s;if(_t(r=e[t-1])){t:{var u=r;let t={},e=!1;for(var c in u){let r=u[c];if(Array.isArray(r)){let t=r;(yt(r,n,+c)||mt(r)&&0===r.size)&&(r=null),r!=t&&(e=!0)}null!=r?t[c]=r:e=!0}if(e){for(var l in t){u=t;break t}u=null}}u!=r&&(o=!0),t--}for(c=+!!(512&i)-1;0<t&&(r=e[l=t-1],l-=c,null==r||yt(r,n,l)||mt(r)&&0===r.size);t--)s=!0;return o||s?(e=Array.prototype.slice.call(e,0,t),u&&e.push(u),e):e}function ne(t,e){if(Array.isArray(e)){var r=at(e);if(4&r)return e;for(var n=0,i=0;n<e.length;n++){const r=t(e[n]);null!=r&&(e[i++]=r)}return i<n&&(e.length=i),ct(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}ee.prototype.D=pt,ee.prototype.toString=function(){return re(this,this.m,!1).toString()};const ie=Symbol(),oe=Symbol();function se(t){let e=t[oe];if(!e){const r=le(t);e=(t,e)=>de(t,e,r),t[oe]=e}return e}const ae=Symbol();function ue(t){return t.i}function ce(t,e){let r,n;const i=t.i;return(t,o,s)=>i(t,o,s,n||=le(e).i,r||=se(e))}function le(t){var e=t[ae];if(e)return e;var r=ue,n=ce;(e=t[ae]={}).i=function(t){switch(typeof t){case"boolean":return kt||=[0,void 0,!0];case"number":return 0<t?void 0:0===t?Ut||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);let i=0;var o=t[++i];o&&o.constructor===Object&&(e.K=o,"function"==typeof(o=t[++i])&&(e.l=o,e.j=t[++i],o=t[++i]));const s={};for(;Array.isArray(o)&&"number"==typeof o[0]&&0<o[0];){for(var a=0;a<o.length;a++)s[o[a]]=o;o=t[++i]}for(a=1;void 0!==o;){let f;"number"==typeof o&&(a+=o,o=t[++i]);var u=void 0;if(o instanceof rt?f=o:(f=Ue,i--),f.I){o=t[++i],u=t;var c=i;"function"==typeof o&&(o=o(),u[c]=o),u=o}let d=a+1;for("number"==typeof(o=t[++i])&&0>o&&(d-=o,o=t[++i]);a<d;a++){var l=s[a];c=e;var h=a;l=u?n(f,u):r(f),c[h]=l}}return he in t&&ie in t&&ae in t&&(t.length=0),e}const he=Symbol();function fe(t,e){var r=t[e];if(r)return r;if((r=t.K)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof rt?r:[ke,r]:[r,void 0])[0].i;if(r=r[1]){const e=se(r),i=le(r).i;r=(r=t.j)?r(i,e):(t,r,o)=>n(t,r,o,i,e)}else r=n;return t[e]=r}}function de(t,e,r){var n=ut(t),i=+!!(512&n)-1,o=t.length,s=512&n?1:0;const a=o+(256&n?-1:0);for(;s<a;s++){const n=t[s];if(null==n)continue;const o=s-i,a=fe(r,o);a&&a(e,n,o)}if(256&n){t=t[o-1];for(let s in t)n=+s,Number.isNaN(n)||null!=(i=t[s])&&(o=fe(r,n))&&o(e,i,n)}}function pe(t){return new rt(t,!1)}function ge(t,e,r){null!=(e=Et(e))&&null!=e&&(Y(t.i,8*r),J(t.i,e))}function me(t,e,r){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(Y(t.i,8*r),t.i.i.push(e?1:0))}function _e(t,e,r){null!=(e=xt(e))&&tt(t,r,i(e))}function ye(t,e,r,n,i){null!=(e=e instanceof ee?e.m:Array.isArray(e)?Vt(e,n[0],n[1]):void 0)&&(r=Q(t,r),i(e,t),Z(t,r))}function be(t,e,r){null!=(e=Et(e))&&(e=parseInt(e,10),Y(t.i,8*r),J(t.i,e))}var ve,we=pe((function(t,e,r){null!=(e=null==e||"number"==typeof e?e:"NaN"===e||"Infinity"===e||"-Infinity"===e?Number(e):void 0)&&(Y(t.i,8*r+5),t=t.i,(r=U||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),j=0,e=V=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))})),Se=pe((function(t,e,r){t:if(null!=e){if(It(e)){if("string"==typeof e){var n=Math.trunc(Number(e));if(Number.isSafeInteger(n))e=String(n);else if(-1!==(n=e.indexOf("."))&&(e=e.substring(0,n)),!("-"===e[0]?20>e.length||20===e.length&&-922337<Number(e.substring(0,7)):19>e.length||19===e.length&&922337>Number(e.substring(0,6))))if(M(e),e=V,2147483648&(n=j))if(k())e=""+(BigInt(0|n)<<BigInt(32)|BigInt(e>>>0));else{const[t,r]=G(e,n);e="-"+C(t,r)}else e=C(e,n);break t}if("number"==typeof e){if(e=Math.trunc(e),!Number.isSafeInteger(e)){N(e),n=V;var i=j;(e=2147483648&i)&&(i=~i>>>0,0==(n=1+~n>>>0)&&(i=i+1>>>0)),n=4294967296*i+(n>>>0),e=e?-n:n}break t}}e=void 0}null!=e&&("string"==typeof e&&H(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,N(e),K(t,V,j)):(r=H(e),K(t.i,r.j,r.i))))})),Ae=pe((function(t,e,r){t:if(null!=e){if(It(e)){if("string"==typeof e){var n=Math.trunc(Number(e));Number.isSafeInteger(n)&&0<=n?e=String(n):(-1!==(n=e.indexOf("."))&&(e=e.substring(0,n)),Lt(e)||(M(e),e=C(V,j)));break t}if("number"==typeof e){e=0<=(e=Math.trunc(e))&&Number.isSafeInteger(e)?e:function(t){if(0>t){N(t);const e=C(V,j);return t=Number(e),Number.isSafeInteger(t)?t:e}return Lt(String(t))?t:(N(t),4294967296*j+(V>>>0))}(e);break t}}e=void 0}null!=e&&("string"==typeof e&&R(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,N(e),K(t,V,j)):(r=R(e),K(t.i,r.j,r.i))))})),Ie=pe(ge),Te=new rt((function(t,e,r){if(null!=(e=ne(Et,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Ee=pe(ge),Pe=pe(me),Oe=pe(me),Le=new rt((function(t,e,r){if(null!=(e=ne(xt,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&tt(n,o,i(s))}}),!1),xe=pe(_e),Be=pe(_e),Fe=pe(_e),ke=new rt(ye,!0),Ue=new rt(ye,!0);ve=new rt((function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)ye(t,e[o],r,n,i)}),!0);var Ve=new rt(ye,!0),je=pe(be),Ne=pe(be);function Ce(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}}}};de(this.m,e,le(t)),X(e,e.i.end());const r=new Uint8Array(e.j),n=e.l,i=n.length;let o=0;for(let t=0;t<i;t++){const e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function De(t,e){if(null!=e)if(Array.isArray(e))zt(t,2,Nt(e,Ct,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof B||T(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 B(e,P):x();else if(e.constructor!==B){if(!T(e))throw Error();e=e.length?new B(new Uint8Array(e),P):x()}qt(t,2,e,x())}}var Me=class extends ee{constructor(t){super(t)}},Ge=[0,xe,pe((function(t,e,r){if(null!=e){if(e instanceof ee){const n=e.P;return void(n&&(e=n(e),null!=e&&tt(t,r,F(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||T(e)||e instanceof B?e:void 0)&&tt(t,r,F(e).buffer)}))],Re={},We=[-2,Re,Pe];Re[336783863]=[0,Fe,Pe,-1,Ie,[0,[1,2,3,4,5],Ve,[0],Ve,[0,Pe,Fe,Pe,je,-1,new rt((function(t,e,r){if(null!=(e=ne(Et,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Fe,-1,[0,Pe,-1],je],Ve,[0,Fe,-2],Ve,[0,Ie,Pe,-3],Ve,[0,Ie,je,Pe,-1,Te,je,-1]],[0,Fe]];var ze=class extends ee{constructor(t){super(t)}},He=[0,xe,Oe],$e=[0,Se,-1,Oe,-3,Se,Te,xe,Ee,Se,-1,Oe,Ee,Oe,-2,xe],qe=[-1,{}],Ke=[0,Fe,1,qe],Ye=[0,Fe,Le,qe],Je=class extends ee{constructor(t){super(t,500)}C(t){return Yt(this,7,t)}};Je.v=[3,4,5,6,8,13,17,1005];var Xe=[-500,xe,-1,Le,-3,We,ve,Ge,Ee,-1,Ke,Ye,ve,He,xe,$e,Ee,Le,987,Le],Qe=[0,xe,-1,qe],Ze=[-500,Fe,-1,[-1,{}],998,Fe],tr=[-500,Fe,Le,-1,[-2,{},Pe],997,Le,-1],er=[-500,Fe,Le,qe,998,Le],rr=class extends ee{constructor(){super(void 0,500)}C(t){return Yt(this,1001,t)}};rr.v=[1,6,7,9,10,15,16,17,14,1002],rr.prototype.i=Ce([-500,ve,Xe,4,ve,Ze,ve,tr,Ee,ve,er,Le,Ee,Ke,Ye,ve,Qe,Le,-2,$e,xe,-1,Oe,979,qe,ve,Ge]);var nr=class extends ee{constructor(t){super(t)}};let ir;const or=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 sr(){if(void 0===ir)try{await WebAssembly.instantiate(or),ir=!0}catch{ir=!1}return ir}async function ar(t,e=""){const r=await sr()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var ur=class{};async function cr(t){if("function"!=typeof importScripts){const e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((t,r)=>{e.addEventListener("load",(()=>{t()}),!1),e.addEventListener("error",(t=>{r(t)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}ur.forVisionTasks=function(t){return ar("vision",t)},ur.forTextTasks=function(t){return ar("text",t)},ur.forGenAiTasks=function(t){return ar("genai",t)},ur.forAudioTasks=function(t){return ar("audio",t)},ur.isSimdSupported=function(){return sr()};function lr(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function hr(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");const n=new Uint32Array(e.length);for(let r=0;r<e.length;r++)n[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*n.length),t.h.HEAPU32.set(n,e>>2),r(e);for(const e of n)t.h._free(e);t.h._free(e)}function fr(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function dr(t,e,r){let n=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(r(n,i),n=[]):n.push(t)}}const pr=(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:((t="undefined"==typeof OffscreenCanvas)||(t=(t=navigator.userAgent).includes("Safari")&&!t.includes("Chrome")),t?(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas")):this.h.canvas=new OffscreenCanvas(1,1))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),lr(this,n||"input_audio",(n=>{lr(this,i=i||"audio_header",(i=>{this.h._configureAudio(n,i,t,e,r)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,i){const o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),lr(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){lr(this,e,(e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();const n=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!n)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1);const[i,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||i===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=i,this.h.canvas.height=o);const[s,a]=[i,o];this.h._addBoundTextureToStream(e,s,a,r)}))}addBoolToStream(t,e,r){lr(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){lr(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){lr(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){lr(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addStringToStream(t,e,r){lr(this,e,(e=>{lr(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){lr(this,e,(e=>{hr(this,Object.keys(t),(n=>{hr(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){lr(this,r,(r=>{lr(this,e,(e=>{const i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputStream(i,t.length,e,r,n),this.h._free(i)}))}))}addEmptyPacketToStream(t,e){lr(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){lr(this,e,(e=>{const n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputStream(n,e,r)}))}addDoubleVectorToStream(t,e,r){lr(this,e,(e=>{const n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputStream(n,e,r)}))}addFloatVectorToStream(t,e,r){lr(this,e,(e=>{const n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputStream(n,e,r)}))}addIntVectorToStream(t,e,r){lr(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)}))}addStringVectorToStream(t,e,r){lr(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)lr(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){lr(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){lr(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){lr(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){lr(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){lr(this,e,(e=>{lr(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){lr(this,r,(r=>{lr(this,e,(e=>{const n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputSidePacket(n,t.length,e,r),this.h._free(n)}))}))}addBoolVectorToInputSidePacket(t,e){lr(this,e,(e=>{const r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)}))}addDoubleVectorToInputSidePacket(t,e){lr(this,e,(e=>{const r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)}))}addFloatVectorToInputSidePacket(t,e){lr(this,e,(e=>{const r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)}))}addIntVectorToInputSidePacket(t,e){lr(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)}))}addStringVectorToInputSidePacket(t,e){lr(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)lr(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){fr(this,t,e),lr(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){dr(this,t,e),lr(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){fr(this,t,e),lr(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){dr(this,t,e),lr(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachDoubleListener(t,e){fr(this,t,e),lr(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){dr(this,t,e),lr(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){fr(this,t,e),lr(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){dr(this,t,e),lr(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){fr(this,t,e),lr(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){dr(this,t,e),lr(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){fr(this,t,e),lr(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){dr(this,t,e),lr(this,t,(t=>{this.h._attachProtoVectorListener(t,r||!1)}))}attachAudioListener(t,e,r){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),fr(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),lr(this,t,(t=>{this.h._attachAudioListener(t,r||!1)}))}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends gr{N(){this.h._registerModelResourcesGraphService()}});var gr;async function mr(t,e){const r=await(async(t,e,r)=>{var n=zr;if(t&&await cr(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await cr(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&r&&((t=self.Module).locateFile=r.locateFile,r.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=r.mainScriptUrlOrBlob)),r=await self.ModuleFactory(self.Module||r),self.ModuleFactory=self.Module=void 0,new n(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return await r.C(e),r}async function _r(t,e){return mr(t,e)}function yr(t){try{const e=t.u.length;if(1===e)throw Error(t.u[0].message);if(1<e)throw Error("Encountered multiple errors: "+t.u.map((t=>t.message)).join(", "))}finally{t.u=[]}}function br(t,e){t.G=Math.max(t.G,e)}var vr=class{constructor(t){this.i=t,this.u=[],this.G=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.u.push(Error(e))})),this.i.N(),this.i.setGraph(t,e),yr(this)}finishProcessing(){this.i.finishProcessing(),yr(this)}close(){this.i.closeGraph()}};vr.prototype.close=vr.prototype.close;var wr=class extends ee{constructor(t){super(t)}},Sr=[0,Ne,Ee,we,-1,Ie],Ar=class extends ee{constructor(){super()}};function Ir(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Tr=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))}},Er=class extends ee{constructor(){super()}};Er.v=[4],Er.prototype.i=Ce([0,xe,2,Le,Ee]);var Pr=class extends ee{constructor(){super()}},Or=[0,Oe,-5],Lr=[0,xe,Ae,-1,Ne],xr=class extends ee{constructor(){super()}},Br=[0,Ee,-6,1,Ee,1,[0,Oe,Ne,-2],[0,Oe,we],Ne,-2,[0,Oe,-1,Ne,we,je],1,Oe],Fr=class extends ee{constructor(){super()}};Fr.v=[5];var kr=[0,Br,Ee,1,Ee,Le],Ur=[0,ve,Lr,kr,Ee],Vr=[0,Ee,Oe],jr=class extends ee{constructor(){super()}};jr.v=[29],jr.prototype.i=Ce([0,xe,8,Or,1,Ee,1,Ee,Ur,Vr,1,Ne,xe,kr,Ur,Ee,5,Ne,Te,je,Sr]);var Nr=class extends ee{constructor(){super()}},Cr=class extends ee{constructor(){super()}},Dr=[2,4];Cr.prototype.i=Ce([0,Dr,Ee,Be,Ee,Ve,[0,xe,-1],Oe]);const Mr=function(t){return class extends t{static async O(){var t={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:524550144}},e=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!e)throw Error("Unable to request adapter from navigator.gpu; ensure WebGPU is enabled.");let r;const n=[];for(const r of t?.requiredFeatures??[])e.features.has(r)?n.push(r):console.warn(`WebGPU feature ${r} is not supported.`);t={...t,requiredFeatures:n};try{r=await e.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return e=await e.requestAdapterInfo(),r.adapterInfo=e,r}M(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}}}(function(t){return class extends t{J(t){lr(this,"model_file_reference",(e=>{this.h._addRawDataSpanToInputSidePacket(t.offset,t.size,e)}))}}}(class extends pr{}));class Gr extends Mr{}function Rr(){return Gr.O()}function Wr(t){var e=function(t){const e=new rr;te(e,10,"text_in"),te(e,16,"model_file_reference"),te(e,15,"text_out"),te(e,15,"text_end");var r=new Je;Zt(r,2,"TokenizerInputBuildCalculator"),te(r,3,"text_in"),te(r,4,"prompt"),Xt(e,1,Je,r),Zt(r=new Je,2,"TfLiteModelCalculator"),te(r,5,"MODEL_SPAN:model_file_reference"),te(r,6,"SHARED_MODEL:__side_packet_0"),Xt(e,1,Je,r),Zt(r=new Me,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new Cr,i=Ot(Rt(t.j))??0;Qt(n,1,i),Zt(i=new Nr,2,"spm_vocab_model"),null==i&&(i=void 0);var o=n.m;let s=ut(o);vt(s);var a=s;let u=0;for(let t=0;t<Dr.length;t++){const e=Dr[t];null!=Wt(o,a,e)&&(0!==u&&(a=Ht(o,a,u)),u=e)}return(a=u)&&4!==a&&null!=i&&(s=Ht(o,s,a)),Ht(o,s,4,i),Qt(n,3,2),De(r,n.i()),Zt(n=new Je,2,"TokenizerCalculator"),Xt(n,8,Me,r),te(n,5,"TFLITE_MODEL:__side_packet_0"),te(n,3,"PROMPT:prompt"),te(n,6,"PROCESSOR:__input_side_1"),te(n,6,"BYTES_TO_UNICODE_MAPPING:__input_side_2"),te(n,4,"IDS:__stream_0"),Xt(e,1,Je,n),Zt(r=new Me,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),Qt(n=new jr,12,3),Zt(n,1,"llm.tflite"),Qt(n,14,0),Qt(n,22,1),i=Kt(t.j,wr,3),Yt(n,31,i),qt(i=new Pr,1,!0,!1),qt(i,2,!0,!1),qt(i,5,!0,!1),Yt(n,10,i),i=new Fr,Qt(o=new xr,1,1),t=Ot(Rt(t.j))??0,Qt(o,2,t),Yt(i,1,o),Yt(n,20,i),De(r,n.i()),Zt(t=new Je,2,"LlmGpuCalculator"),Xt(t,8,Me,r),te(t,3,"INPUT_PROMPT_IDS:__stream_0"),te(t,3,"FINISH:finish"),te(t,5,"SHARED_MODEL:__side_packet_0"),te(t,4,"DECODED_IDS:__stream_3"),te(t,4,"OUTPUT_END:__stream_4"),Zt(r=new ze,1,"FINISH"),qt(r,2,!0,!1),Xt(t,13,ze,r),Xt(e,1,Je,t),Zt(t=new Je,2,"IsPacketPresentCalculator"),te(t,3,"__stream_4"),te(t,4,"text_end"),Xt(e,1,Je,t),Zt(t=new Me,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),Qt(r=new Er,5,1),te(r,4,"<eos>"),te(r,4,"<|endoftext|>"),De(t,r.i()),Zt(r=new Je,2,"DetokenizerCalculator"),Xt(r,8,Me,t),te(r,3,"IDS:__stream_3"),te(r,5,"PROCESSOR:__input_side_1"),te(r,5,"BYTES_TO_UNICODE_MAPPING:__input_side_2"),te(r,4,"FINISH:finish"),te(r,4,"WORDS:text_out"),Xt(e,1,Je,r),e}(t);t.i.attachStringVectorListener("text_out",((e,r)=>{var n=0===t.A.length;null==e||0===e.length?n="":(e=(e=(e=e[0]).replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),n&&(e=e.trimStart()),n=e.split("\\[eod\\]",1)[0]),t.A.push(n),t.B&&t.B(n,!1),br(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{br(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{t.F=!1,t.H&&t.H(t.A.join("")),t.B&&t.B("",!0),br(t,r)})),t.i.attachEmptyPacketListener("text_end",(e=>{br(t,e)})),t.l&&t.i.J(t.l),e=e.i(),t.setGraph(new Uint8Array(e),!0),t.finishProcessing(),t.l&&Ir(t.l)}var zr=class extends vr{constructor(t,e){if(super(new Gr(t,e)),this.A=[],this.F=!1,Yt(t=this.j=new Ar,1,e=new nr),this.o=new wr,Yt(this.j,3,this.o),zt(this.j,2,Pt(512)),t=this.o,!Number.isFinite(1))throw wt("enum");qt(t,1,1,0),Qt(this.o,2,1),qt(this.o,4,St(1),0)}C(t){if(t.baseOptions?.gpuOptions?.device&&this.i.M(t.baseOptions.gpuOptions.device),"maxTokens"in t&&zt(this.j,2,Pt(t.maxTokens??512)),"topK"in t&&(Qt(this.o,2,t.topK??1),t.topK&&!t.randomSeed&&console.warn("'topK' option ignored; it requires randomSeed to be set.")),"temperature"in t&&(qt(this.o,4,St(t.temperature??1),0),t.temperature&&!t.randomSeed&&console.warn("'temperature' option ignored; it requires randomSeed to be set.")),t.randomSeed&&zt(this.o,5,Tt(t.randomSeed)),t.baseOptions?.modelAssetPath||t.baseOptions?.modelAssetBuffer){if(t.baseOptions.modelAssetPath&&t.baseOptions.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");if(this.l&&Ir(this.l),t.baseOptions.modelAssetPath)return async function(t,e){var r=await fetch(e.toString());e=Number(r.headers.get("content-length")),t=new Tr(t,e);let n=0;for(r=r?.body?.getReader();;){const{value:e,done:i}=await r.read();if(i)break;t.set(e,n),n+=e.byteLength}if(e!==n)throw Ir(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${e} bytes before failure`);return t}(this.i.h,t.baseOptions.modelAssetPath).then((t=>{this.l=t,Wr(this)}));t.baseOptions.modelAssetBuffer&&(this.l=function(t,e){return(t=new Tr(t,e.length)).set(e),t}(this.i.h,t.baseOptions.modelAssetBuffer),t.baseOptions.modelAssetBuffer=void 0)}return Wr(this),Promise.resolve()}get baseOptions(){return Kt(this.j,nr,1)}set baseOptions(t){Yt(this.j,1,t)}L(t,e){if(this.F)throw Error("Previous invocation is still processing.");return e&&(this.B=e),this.A.length=0,this.F=!0,this.i.addStringToStream(t,"text_in",this.G+1),this.finishProcessing(),new Promise((t=>{this.H=t}))}close(){this.l&&Ir(this.l),super.close()}};zr.prototype.generateResponse=zr.prototype.L,zr.prototype.setOptions=zr.prototype.C,zr.createWebGpuDevice=Rr,zr.createFromModelPath=async function(t,e){return _r(t,e={baseOptions:{gpuOptions:{device:await Rr()},modelAssetPath:e}})},zr.createFromModelBuffer=async function(t,e){return _r(t,e={baseOptions:{gpuOptions:{device:await Rr()},modelAssetBuffer:e}})},zr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Rr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return _r(t,e)},exports.FilesetResolver=ur,exports.LlmInference=zr,exports.TaskRunner=vr;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="undefined"!=typeof self?self:{};function e(e){t:{for(var r=["CLOSURE_FLAGS"],n=t,i=0;i<r.length;i++)if(null==(n=n[r[i]])){r=null;break t}r=n}return null!=(e=r&&r[e])&&e}let r;const n="undefined"!=typeof TextEncoder;function i(t){if(n)t=(r||=new TextEncoder).encode(t);else{let r=0;const n=new Uint8Array(3*t.length);for(let i=0;i<t.length;i++){var e=t.charCodeAt(i);if(128>e)n[r++]=e;else{if(2048>e)n[r++]=e>>6|192;else{if(55296<=e&&57343>=e){if(56319>=e&&i<t.length){const o=t.charCodeAt(++i);if(56320<=o&&57343>=o){e=1024*(e-55296)+o-56320+65536,n[r++]=e>>18|240,n[r++]=e>>12&63|128,n[r++]=e>>6&63|128,n[r++]=63&e|128;continue}i--}e=65533}n[r++]=e>>12|224,n[r++]=e>>6&63|128}n[r++]=63&e|128}}t=r===n.length?n:n.subarray(0,r)}return t}var o,s=e(610401301),a=e(188588736);const u=t.navigator;function c(t){return!!s&&(!!o&&o.brands.some((({brand:e})=>e&&-1!=e.indexOf(t))))}function l(e){var r;return(r=t.navigator)&&(r=r.userAgent)||(r=""),-1!=r.indexOf(e)}function h(){return!!s&&(!!o&&0<o.brands.length)}function f(){return h()?c("Chromium"):(l("Chrome")||l("CriOS"))&&!(!h()&&l("Edge"))||l("Silk")}o=u&&u.userAgentData||null;var d=!h()&&(l("Trident")||l("MSIE"));!l("Android")||f(),f(),l("Safari")&&(f()||!h()&&l("Coast")||!h()&&l("Opera")||!h()&&l("Edge")||(h()?c("Microsoft Edge"):l("Edg/"))||h()&&c("Opera"));var p={},g=null;function m(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var n=new Uint8Array(r),i=0;return function(t,e){function r(e){for(;n<t.length;){var r=t.charAt(n++),i=g[r];if(null!=i)return i;if(!/^[\s\xa0]*$/.test(r))throw Error("Unknown base64 encoding at char: "+r)}return e}_();for(var n=0;;){var i=r(-1),o=r(0),s=r(64),a=r(64);if(64===a&&-1===i)break;e(i<<2|o>>4),64!=s&&(e(o<<4&240|s>>2),64!=a&&e(s<<6&192|a))}}(t,(function(t){n[i++]=t})),i!==r?n.subarray(0,i):n}function _(){if(!g){g={};for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"],r=0;5>r;r++){var n=t.concat(e[r].split(""));p[r]=n;for(var i=0;i<n.length;i++){var o=n[i];void 0===g[o]&&(g[o]=i)}}}}var v="undefined"!=typeof Uint8Array,y=!d&&"function"==typeof btoa;function b(t){if(!y){var e;void 0===e&&(e=0),_(),e=p[e];var r=Array(Math.floor(t.length/3)),n=e[64]||"";let u=0,c=0;for(;u<t.length-2;u+=3){var i=t[u],o=t[u+1],s=t[u+2],a=e[i>>2];i=e[(3&i)<<4|o>>4],o=e[(15&o)<<2|s>>6],s=e[63&s],r[c++]=a+i+o+s}switch(a=0,s=n,t.length-u){case 2:s=e[(15&(a=t[u+1]))<<2]||n;case 1:t=t[u],r[c]=e[t>>2]+e[(3&t)<<4|a>>4]+s+n}return r.join("")}for(e="",r=0,n=t.length-10240;r<n;)e+=String.fromCharCode.apply(null,t.subarray(r,r+=10240));return e+=String.fromCharCode.apply(null,r?t.subarray(r):t),btoa(e)}const w=/[-_.]/g,S={"-":"+",_:"/",".":"="};function A(t){return S[t]||""}function T(t){if(!y)return m(t);w.test(t)&&(t=t.replace(w,A)),t=atob(t);const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function I(t){return v&&null!=t&&t instanceof Uint8Array}let P;var E={};let O;function x(t){if(t!==E)throw Error("illegal external caller")}function L(){return O||=new k(null,E)}var k=class{constructor(t,e){if(x(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function B(t){if("string"==typeof t)return{buffer:T(t),s:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),s:!1};if(t.constructor===Uint8Array)return{buffer:t,s:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),s:!1};if(t.constructor===k){x(E);var e=t.i;return{buffer:(null==(e=null==e||I(e)?e:"string"==typeof e?T(e):null)?e:t.i=e)||(P||=new Uint8Array(0)),s:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),s:!1};throw Error("Type not convertible to a Uint8Array, expected a Uint8Array, an ArrayBuffer, a base64 encoded string, a ByteString or an Array of numbers")}function U(){return"function"==typeof BigInt}let N,D=0,F=0;function C(t){const e=0>t;let r=(t=Math.abs(t))>>>0;if(t=Math.floor((t-r)/4294967296),e){const[e,n]=G(r,t);t=n,r=e}D=r>>>0,F=t>>>0}function V(t,e){if(t>>>=0,2097151>=(e>>>=0))var r=""+(4294967296*e+t);else U()?r=""+(BigInt(e)<<BigInt(32)|BigInt(t)):(t=(16777215&t)+6777216*(r=16777215&(t>>>24|e<<8))+6710656*(e=e>>16&65535),r+=8147497*e,e*=2,1e7<=t&&(r+=Math.floor(t/1e7),t%=1e7),1e7<=r&&(e+=Math.floor(r/1e7),r%=1e7),r=e+j(r)+j(t));return r}function j(t){return t=String(t),"0000000".slice(t.length)+t}function M(t){if(16>t.length)C(Number(t));else if(U())t=BigInt(t),D=Number(t&BigInt(4294967295))>>>0,F=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);F=D=0;const r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){const e=Number(t.slice(n,i));F*=1e6,D=1e6*D+e,4294967296<=D&&(F+=Math.trunc(D/4294967296),F>>>=0,D>>>=0)}if(e){const[t,e]=G(D,F);D=t,F=e}}}function G(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function R(t){return t?/^\d+$/.test(t)?(M(t),new z(D,F)):null:W||=new z(0,0)}var z=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let W;function H(t){return t?/^-?\d+$/.test(t)?(M(t),new $(D,F)):null:q||=new $(0,0)}var $=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let q;function K(t,e,r){for(;0<r||127<e;)t.i.push(127&e|128),e=(e>>>7|r<<25)>>>0,r>>>=7;t.i.push(e)}function Y(t,e){for(;127<e;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function J(t,e){if(0<=e)Y(t,e);else{for(let r=0;9>r;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function X(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Q(t,e){return Y(t.i,8*e+2),e=t.i.end(),X(t,e),e.push(t.j),e}function Z(t,e){var r=e.pop();for(r=t.j+t.i.length()-r;127<r;)e.push(127&r|128),r>>>=7,t.j++;e.push(r),t.j++}function tt(t,e,r){Y(t.i,8*e+2),Y(t.i,r.length),X(t,t.i.end()),X(t,r)}class et{constructor(t,e){this.i=t,this.J=e}}function rt(t){return Array.prototype.slice.call(t)}function nt(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol()?Symbol():t}var it=nt(),ot=nt("2ex"),st=it?(t,e)=>{t[it]|=e}:(t,e)=>{void 0!==t.i?t.i|=e:Object.defineProperties(t,{i:{value:e,configurable:!0,writable:!0,enumerable:!1}})},at=it?(t,e)=>{t[it]&=~e}:(t,e)=>{void 0!==t.i&&(t.i&=~e)};function ut(t,e,r){return r?t|e:t&~e}var ct=it?t=>0|t[it]:t=>0|t.i,lt=it?t=>t[it]:t=>t.i,ht=it?(t,e)=>(t[it]=e,t):(t,e)=>(void 0!==t.i?t.i=e:Object.defineProperties(t,{i:{value:e,configurable:!0,writable:!0,enumerable:!1}}),t);function ft(t,e){ht(e,-14591&(0|t))}function dt(t,e){ht(e,-14557&(34|t))}function pt(t){return 0===(t=t>>14&1023)?536870912:t}var gt,mt={},_t={};function vt(t){return!(!t||"object"!=typeof t||t.i!==_t)}function yt(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function bt(t,e,r){if(!Array.isArray(t)||t.length)return!1;const n=ct(t);return!!(1&n)||!(!e||!(Array.isArray(e)?e.includes(r):e.has(r)))&&(ht(t,1|n),!0)}const wt=[];function St(t){if(2&t)throw Error()}ht(wt,55),gt=Object.freeze(wt);function At(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let Tt;function It(t){return At(t=Error(t),"warning"),t}function Pt(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}Object.freeze(new class{}),Object.freeze(new class{});const Et=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Ot(t){const e=typeof t;return"number"===e?Number.isFinite(t):"string"===e&&Et.test(t)}function xt(t){if(null!=t){if("number"!=typeof t)throw It("int32");if(!Number.isFinite(t))throw It("int32");t|=0}return t}function Lt(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function kt(t){if(null!=t){if("number"!=typeof t)throw It("uint32");if(!Number.isFinite(t))throw It("uint32");t>>>=0}return t}function Bt(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?t>>>0:void 0}function Ut(t){return"-"!==t[0]&&(20>t.length||20===t.length&&184467>Number(t.substring(0,6)))}function Nt(t){return null==t||"string"==typeof t?t:void 0}function Dt(t,e,r){if(null!=t&&"object"==typeof t&&t.F===mt)return t;if(Array.isArray(t)){var n=ct(t),i=n;return 0===i&&(i|=32&r),(i|=2&r)!==n&&ht(t,i),new e(t)}}let Ft,Ct,Vt;function jt(t,e,r){if(null==t&&(t=Ft),Ft=void 0,null==t){var n=96;r?(t=[r],n|=512):t=[],e&&(n=-16760833&n|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(2048&(n=ct(t)))throw Error("farr");if(64&n)return t;if(n|=64,r&&(n|=512,r!==t[0]))throw Error("mid");t:{const i=(r=t).length;if(i){const t=i-1;if(yt(r[t])){if(1024<=(e=t-(+!!(512&(n|=256))-1)))throw Error("pvtlmt");n=-16760833&n|(1023&e)<<14;break t}}if(e){if(1024<(e=Math.max(e,i-(+!!(512&n)-1))))throw Error("spvt");n=-16760833&n|(1023&e)<<14}}}return ht(t,n),t}function Mt(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=bt(t,void 0,0)?void 0:i&&2&ct(t)?t:Gt(t,e,r,void 0!==n,i);else if(yt(t)){const o={};for(let s in t)o[s]=Mt(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function Gt(t,e,r,n,i){const o=n||r?ct(t):0;n=n?!!(32&o):void 0,t=rt(t);for(let o=0;o<t.length;o++)t[o]=Mt(t[o],e,r,n,i);return r&&r(o,t),t}function Rt(t){return t.F===mt?t.toJSON():function(t){switch(typeof t){case"number":return isFinite(t)?t:String(t);case"boolean":return t?1:0;case"object":if(t)if(Array.isArray(t)){if(bt(t,void 0,0))return}else{if(I(t))return b(t);if(t instanceof k){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=b(e)}}}return t}(t)}function zt(t,e,r=dt){if(null!=t){if(v&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=ct(t);return 2&n?t:(e&&=0===n||!!(32&n)&&!(64&n||!(16&n)),e?ht(t,-12293&(34|n)):Gt(t,zt,4&n?dt:r,!0,!0))}return t.F===mt&&(r=t.m,t=2&(n=lt(r))?t:Wt(t,r,n,!0)),t}}function Wt(t,e,r,n){return t=t.constructor,Ft=e=function(t,e,r){const n=r||2&e?dt:ft,i=!!(32&e);return t=function(t,e,r){var n=(t=rt(t)).length;const i=256&e?t[n-1]:void 0;for(n+=i?-1:0,e=512&e?1:0;e<n;e++)t[e]=r(t[e]);if(i){e=t[e]={};for(const t in i)e[t]=r(i[t])}return t}(t,e,(t=>zt(t,i,n))),st(t,32|(r?2:0)),t}(e,r,n),e=new t(e),Ft=void 0,e}function Ht(t){const e=t.m,r=lt(e);return 2&r?Wt(t,e,r,!1):t}function $t(t){return Kt(t=t.m,lt(t),2)}function qt(t,e,r,n){if(!(0>(e=n+(+!!(512&e)-1))||e>=t.length||e>=r))return t[e]}function Kt(e,r,n,i){if(-1===n)return null;const o=pt(r);if(!(n>=o)){var s=e.length;return i&&256&r&&null!=(i=e[s-1][n])?(qt(e,r,o,n)&&null!=ot&&(4<=(r=(e=Tt??={})[ot]||0)||(e[ot]=r+1,At(e=Error(),"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e))),i):qt(e,r,o,n)}return 256&r?e[e.length-1][n]:void 0}function Yt(t,e,r){const n=t.m;let i=lt(n);return St(i),Jt(n,i,e,r),t}function Jt(t,e,r,n,i){const o=pt(e);if(r>=o||i){let s=e;if(256&e)i=t[t.length-1];else{if(null==n)return s;i=t[o+(+!!(512&e)-1)]={},s|=256}return i[r]=n,r<o&&(t[r+(+!!(512&e)-1)]=void 0),s!==e&&ht(t,s),s}return t[r+(+!!(512&e)-1)]=n,256&e&&(r in(t=t[t.length-1])&&delete t[r]),e}function Xt(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function Qt(t,e,r,n){t=t.m;let i=lt(t);St(i),Jt(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function Zt(t,e,r){var n=t.m,i=lt(n),o=Kt(n,i,r,!1);return(e=Dt(o,e,i))!==o&&null!=e&&Jt(n,i,r,e,!1),null==(n=e)||(t=t.m,2&(i=lt(t))||(o=Ht(n))!==n&&Jt(t,i,r,n=o,!1)),n}function te(t,e,r){return null==r&&(r=void 0),Yt(t,e,r)}function ee(t,e){return t=ut(t,2,!!(2&e)),t=ut(t,32,!0),ut(t,2048,!1)}function re(t,e){return 32&e||(t=ut(t,32,!1)),t}function ne(t,e,r,n){t=t.m;var i=lt(t);St(i);var o=!!(2&i),s=o?1:2;const a=1===s;s=2===s,d&&=!o,o=Kt(t,i,e),o=Array.isArray(o)?o:gt;var u=ct(o);const c=!!(4&u);if(!c){var l=u;0===l&&(l=ee(l,i)),u=o;var h=i,f=!!(2&(l=ut(l,1,!0)));f&&(h=ut(h,2,!0));let t=!f,e=!0,n=0,s=0;for(;n<u.length;n++){const i=Dt(u[n],r,h);if(i instanceof r){if(!f){const r=!!(2&ct(i.m));t&&=!r,e&&=r}u[s++]=i}}s<n&&(u.length=s),l=ut(l,4,!0),l=ut(l,16,e),l=ut(l,8,t),ht(u,l),f&&Object.freeze(u),u=l}if(l=!!(8&u)||a&&!o.length,d&&!l){Xt(u)&&(o=rt(o),u=ee(u,i),i=Jt(t,i,e,o));var d=o;for(l=0;l<d.length;l++)(h=d[l])!==(f=Ht(h))&&(d[l]=f);u=ut(u,8,!0),u=ut(u,16,!d.length),ht(d,u)}Xt(u)||(d=u,a?((l=!!(32&u))||(d=0,i=Jt(t,i,e,o=rt(o))),u=ut(u,!o.length||16&u&&(!c||l)?2:2048,!0)):u=re(u,i),u!==d&&ht(o,u),a&&Object.freeze(o)),s&&Xt(u)&&(o=rt(o),u=re(u=ee(u,i),i),ht(o,u),Jt(t,i,e,o)),e=o,r=null!=n?n:new r,e.push(r),2&ct(r.m)?at(e,8):at(e,16)}function ie(t,e,r){Qt(t,e,xt(r),0)}function oe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();Qt(t,e,r,"")}function se(t,e,r){t=t.m;const n=lt(t);St(n);var i=2&n;let o=Kt(t,n,e);Array.isArray(o)||(o=gt);const s=!!(32&n);let a=ct(o);if(0===a&&s&&!i?(a|=33,ht(o,a)):1&a||(a|=1,ht(o,a)),i?(2&a||st(o,34),Object.freeze(o)):(2&a||2048&a)&&(o=rt(o),i=1,s&&(i|=32),ht(o,i),Jt(t,n,e,o)),"string"!=typeof r)throw Error();o.push(r)}var ae=class{constructor(t,e){this.m=jt(t,e)}toJSON(){return ue(this,Gt(this.m,Rt,void 0,void 0,!1),!0)}s(){return!!(2&ct(this.m))}};function ue(t,e,r){var n=a?void 0:t.constructor.v;const i=lt(r?t.m:e);if(!(t=e.length))return e;let o,s;if(yt(r=e[t-1])){t:{var u=r;let t={},e=!1;for(var c in u){let r=u[c];if(Array.isArray(r)){let t=r;(bt(r,n,+c)||vt(r)&&0===r.size)&&(r=null),r!=t&&(e=!0)}null!=r?t[c]=r:e=!0}if(e){for(var l in t){u=t;break t}u=null}}u!=r&&(o=!0),t--}for(c=+!!(512&i)-1;0<t&&(r=e[l=t-1],l-=c,null==r||bt(r,n,l)||vt(r)&&0===r.size);t--)s=!0;return o||s?(e=Array.prototype.slice.call(e,0,t),u&&e.push(u),e):e}function ce(t,e){if(Array.isArray(e)){var r=ct(e);if(4&r)return e;for(var n=0,i=0;n<e.length;n++){const r=t(e[n]);null!=r&&(e[i++]=r)}return i<n&&(e.length=i),ht(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}ae.prototype.F=mt,ae.prototype.toString=function(){return ue(this,this.m,!1).toString()};const le=Symbol(),he=Symbol();function fe(t){let e=t[he];if(!e){const r=me(t);e=(t,e)=>ye(t,e,r),t[he]=e}return e}const de=Symbol();function pe(t){return t.i}function ge(t,e){let r,n;const i=t.i;return(t,o,s)=>i(t,o,s,n||=me(e).i,r||=fe(e))}function me(t){var e=t[de];if(e)return e;var r=pe,n=ge;(e=t[de]={}).i=function(t){switch(typeof t){case"boolean":return Ct||=[0,void 0,!0];case"number":return 0<t?void 0:0===t?Vt||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);let i=0;var o=t[++i];o&&o.constructor===Object&&(e.L=o,"function"==typeof(o=t[++i])&&(e.l=o,e.j=t[++i],o=t[++i]));const s={};for(;Array.isArray(o)&&"number"==typeof o[0]&&0<o[0];){for(var a=0;a<o.length;a++)s[o[a]]=o;o=t[++i]}for(a=1;void 0!==o;){let f;"number"==typeof o&&(a+=o,o=t[++i]);var u=void 0;if(o instanceof et?f=o:(f=Me,i--),f.J){o=t[++i],u=t;var c=i;"function"==typeof o&&(o=o(),u[c]=o),u=o}let d=a+1;for("number"==typeof(o=t[++i])&&0>o&&(d-=o,o=t[++i]);a<d;a++){var l=s[a];c=e;var h=a;l=u?n(f,u):r(f),c[h]=l}}return _e in t&&le in t&&de in t&&(t.length=0),e}const _e=Symbol();function ve(t,e){var r=t[e];if(r)return r;if((r=t.L)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof et?r:[je,r]:[r,void 0])[0].i;if(r=r[1]){const e=fe(r),i=me(r).i;r=(r=t.j)?r(i,e):(t,r,o)=>n(t,r,o,i,e)}else r=n;return t[e]=r}}function ye(t,e,r){var n=lt(t),i=+!!(512&n)-1,o=t.length,s=512&n?1:0;const a=o+(256&n?-1:0);for(;s<a;s++){const n=t[s];if(null==n)continue;const o=s-i,a=ve(r,o);a&&a(e,n,o)}if(256&n){t=t[o-1];for(let s in t)n=+s,Number.isNaN(n)||null!=(i=t[s])&&(o=ve(r,n))&&o(e,i,n)}}function be(t){return new et(t,!1)}function we(t,e,r){null!=(e=Lt(e))&&null!=e&&(Y(t.i,8*r),J(t.i,e))}function Se(t,e,r){null!=(e=null==e||"boolean"==typeof e?e:"number"==typeof e?!!e:void 0)&&(Y(t.i,8*r),t.i.i.push(e?1:0))}function Ae(t,e,r){null!=(e=Nt(e))&&tt(t,r,i(e))}function Te(t,e,r,n,i){null!=(e=e instanceof ae?e.m:Array.isArray(e)?jt(e,n[0],n[1]):void 0)&&(r=Q(t,r),i(e,t),Z(t,r))}function Ie(t,e,r){null!=(e=Lt(e))&&(e=parseInt(e,10),Y(t.i,8*r),J(t.i,e))}var Pe,Ee=be((function(t,e,r){null!=(e=null==e||"number"==typeof e?e:"NaN"===e||"Infinity"===e||"-Infinity"===e?Number(e):void 0)&&(Y(t.i,8*r+5),t=t.i,(r=N||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),F=0,e=D=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))})),Oe=be((function(t,e,r){t:if(null!=e){if(Ot(e)){if("string"==typeof e){var n=Math.trunc(Number(e));if(Number.isSafeInteger(n))e=String(n);else if(-1!==(n=e.indexOf("."))&&(e=e.substring(0,n)),!("-"===e[0]?20>e.length||20===e.length&&-922337<Number(e.substring(0,7)):19>e.length||19===e.length&&922337>Number(e.substring(0,6))))if(M(e),e=D,2147483648&(n=F))if(U())e=""+(BigInt(0|n)<<BigInt(32)|BigInt(e>>>0));else{const[t,r]=G(e,n);e="-"+V(t,r)}else e=V(e,n);break t}if("number"==typeof e){if(e=Math.trunc(e),!Number.isSafeInteger(e)){C(e),n=D;var i=F;(e=2147483648&i)&&(i=~i>>>0,0==(n=1+~n>>>0)&&(i=i+1>>>0)),n=4294967296*i+(n>>>0),e=e?-n:n}break t}}e=void 0}null!=e&&("string"==typeof e&&H(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,C(e),K(t,D,F)):(r=H(e),K(t.i,r.j,r.i))))})),xe=be((function(t,e,r){t:if(null!=e){if(Ot(e)){if("string"==typeof e){var n=Math.trunc(Number(e));Number.isSafeInteger(n)&&0<=n?e=String(n):(-1!==(n=e.indexOf("."))&&(e=e.substring(0,n)),Ut(e)||(M(e),e=V(D,F)));break t}if("number"==typeof e){e=0<=(e=Math.trunc(e))&&Number.isSafeInteger(e)?e:function(t){if(0>t){C(t);const e=V(D,F);return t=Number(e),Number.isSafeInteger(t)?t:e}return Ut(String(t))?t:(C(t),4294967296*F+(D>>>0))}(e);break t}}e=void 0}null!=e&&("string"==typeof e&&R(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,C(e),K(t,D,F)):(r=R(e),K(t.i,r.j,r.i))))})),Le=be(we),ke=new et((function(t,e,r){if(null!=(e=ce(Lt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Be=be(we),Ue=be(Se),Ne=be(Se),De=new et((function(t,e,r){if(null!=(e=ce(Nt,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&tt(n,o,i(s))}}),!1),Fe=be(Ae),Ce=be(Ae),Ve=be(Ae),je=new et(Te,!0),Me=new et(Te,!0);Pe=new et((function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)Te(t,e[o],r,n,i)}),!0);var Ge=new et(Te,!0),Re=be(Ie),ze=be(Ie);function We(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}}}};ye(this.m,e,me(t)),X(e,e.i.end());const r=new Uint8Array(e.j),n=e.l,i=n.length;let o=0;for(let t=0;t<i;t++){const e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function He(t,e){if(null!=e)if(Array.isArray(e))Yt(t,2,Gt(e,Rt,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof k||I(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new k(e,E):L();else if(e.constructor!==k){if(!I(e))throw Error();e=e.length?new k(new Uint8Array(e),E):L()}Qt(t,2,e,L())}}var $e=class extends ae{constructor(t){super(t)}},qe=[0,Fe,be((function(t,e,r){if(null!=e){if(e instanceof ae){const n=e.S;return void(n&&(e=n(e),null!=e&&tt(t,r,B(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||I(e)||e instanceof k?e:void 0)&&tt(t,r,B(e).buffer)}))],Ke={},Ye=[-2,Ke,Ue];Ke[336783863]=[0,Ve,Ue,-1,Le,[0,[1,2,3,4,5,6],Ge,[0],Ge,[0,Ue,Ve,Ue,Re,-1,new et((function(t,e,r){if(null!=(e=ce(Lt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Ve,-1,[0,Ue,-1],Re],Ge,[0,Ve,-2],Ge,[0,Le,Ue,-4],Ge,[0,Le,Re,Ue,-1,ke,Re,-1],Ge,[0,Ve]],[0,Ve],Ue,[0,[0,ke],-1],Ve];var Je=class extends ae{constructor(t){super(t)}},Xe=[0,Fe,Ne],Qe=[0,Oe,-1,Ne,-3,Oe,ke,Fe,Be,Oe,-1,Ne,Be,Ne,-2,Fe],Ze=[-1,{}],tr=[0,Ve,1,Ze],er=[0,Ve,De,Ze],rr=class extends ae{constructor(t){super(t,500)}C(t){return te(this,7,t)}};rr.v=[3,4,5,6,8,13,17,1005];var nr=[-500,Fe,-1,De,-3,Ye,Pe,qe,Be,-1,tr,er,Pe,Xe,Fe,Qe,Be,De,987,De],ir=[0,Fe,-1,Ze],or=[-500,Ve,-1,[-1,{}],998,Ve],sr=[-500,Ve,De,-1,[-2,{},Ue],997,De,-1],ar=[-500,Ve,De,Ze,998,De];function ur(t,e){ne(t,1,rr,e)}var cr=class extends ae{constructor(){super(void 0,500)}C(t){return te(this,1001,t)}};cr.v=[1,6,7,9,10,15,16,17,14,1002],cr.prototype.i=We([-500,Pe,nr,4,Pe,or,Pe,sr,Be,Pe,ar,De,Be,tr,er,Pe,ir,De,-2,Qe,Fe,-1,Ne,979,Ze,Pe,qe]);var lr=class extends ae{constructor(t){super(t)}};let hr;const fr=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 dr(){if(void 0===hr)try{await WebAssembly.instantiate(fr),hr=!0}catch{hr=!1}return hr}async function pr(t,e=""){const r=await dr()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var gr=class{};async function mr(t){if("function"!=typeof importScripts){const e=document.createElement("script");return e.src=t.toString(),e.crossOrigin="anonymous",new Promise(((t,r)=>{e.addEventListener("load",(()=>{t()}),!1),e.addEventListener("error",(t=>{r(t)}),!1),document.body.appendChild(e)}))}importScripts(t.toString())}gr.forVisionTasks=function(t){return pr("vision",t)},gr.forTextTasks=function(t){return pr("text",t)},gr.forGenAiTasks=function(t){return pr("genai",t)},gr.forAudioTasks=function(t){return pr("audio",t)},gr.isSimdSupported=function(){return dr()};function _r(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target"),r(e=t.h.stringToNewUTF8(e)),t.h._free(e)}function vr(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");const n=new Uint32Array(e.length);for(let r=0;r<e.length;r++)n[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*n.length),t.h.HEAPU32.set(n,e>>2),r(e);for(const e of n)t.h._free(e);t.h._free(e)}function yr(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function br(t,e,r){let n=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(r(n,i),n=[]):n.push(t)}}const wr=(Sr=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:((t="undefined"==typeof OffscreenCanvas)||(t=(t=navigator.userAgent).includes("Safari")&&!t.includes("Chrome")),t?(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas")):this.h.canvas=new OffscreenCanvas(1,1))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),_r(this,n||"input_audio",(n=>{_r(this,i=i||"audio_header",(i=>{this.h._configureAudio(n,i,t,e,r)}))}))}setAutoResizeCanvas(t){this.l=t}setAutoRenderToScreen(t){this.h._setAutoRenderToScreen(t)}setGpuBufferVerticalFlip(t){this.h.gpuOriginForWebTexturesIsBottomLeft=t}attachErrorListener(t){this.h.errorListener=t}attachEmptyPacketListener(t,e){this.h.emptyPacketListeners=this.h.emptyPacketListeners||{},this.h.emptyPacketListeners[t]=e}addAudioToStream(t,e,r){this.addAudioToStreamWithShape(t,0,0,e,r)}addAudioToStreamWithShape(t,e,r,n,i){const o=4*t.length;this.j!==o&&(this.i&&this.h._free(this.i),this.i=this.h._malloc(o),this.j=o),this.h.HEAPF32.set(t,this.i/4),_r(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){_r(this,e,(e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();const n=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!n)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1);const[i,o]=void 0!==t.videoWidth?[t.videoWidth,t.videoHeight]:void 0!==t.naturalWidth?[t.naturalWidth,t.naturalHeight]:void 0!==t.displayWidth?[t.displayWidth,t.displayHeight]:[t.width,t.height];!this.l||i===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=i,this.h.canvas.height=o);const[s,a]=[i,o];this.h._addBoundTextureToStream(e,s,a,r)}))}addBoolToStream(t,e,r){_r(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){_r(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){_r(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){_r(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addStringToStream(t,e,r){_r(this,e,(e=>{_r(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){_r(this,e,(e=>{vr(this,Object.keys(t),(n=>{vr(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){_r(this,r,(r=>{_r(this,e,(e=>{const i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputStream(i,t.length,e,r,n),this.h._free(i)}))}))}addEmptyPacketToStream(t,e){_r(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){_r(this,e,(e=>{const n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputStream(n,e,r)}))}addDoubleVectorToStream(t,e,r){_r(this,e,(e=>{const n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputStream(n,e,r)}))}addFloatVectorToStream(t,e,r){_r(this,e,(e=>{const n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputStream(n,e,r)}))}addIntVectorToStream(t,e,r){_r(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)}))}addStringVectorToStream(t,e,r){_r(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)_r(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){_r(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){_r(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){_r(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){_r(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){_r(this,e,(e=>{_r(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){_r(this,r,(r=>{_r(this,e,(e=>{const n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputSidePacket(n,t.length,e,r),this.h._free(n)}))}))}addBoolVectorToInputSidePacket(t,e){_r(this,e,(e=>{const r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(const e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)}))}addDoubleVectorToInputSidePacket(t,e){_r(this,e,(e=>{const r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(const e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)}))}addFloatVectorToInputSidePacket(t,e){_r(this,e,(e=>{const r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(const e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)}))}addIntVectorToInputSidePacket(t,e){_r(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)}))}addStringVectorToInputSidePacket(t,e){_r(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)_r(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){yr(this,t,e),_r(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){br(this,t,e),_r(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){yr(this,t,e),_r(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){br(this,t,e),_r(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachDoubleListener(t,e){yr(this,t,e),_r(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){br(this,t,e),_r(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){yr(this,t,e),_r(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){br(this,t,e),_r(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){yr(this,t,e),_r(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){br(this,t,e),_r(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){yr(this,t,e),_r(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){br(this,t,e),_r(this,t,(t=>{this.h._attachProtoVectorListener(t,r||!1)}))}attachAudioListener(t,e,r){this.h._attachAudioListener||console.warn('Attempting to use attachAudioListener without support for output audio. Is build dep ":gl_graph_runner_audio_out" missing?'),yr(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),_r(this,t,(t=>{this.h._attachAudioListener(t,r||!1)}))}finishProcessing(){this.h._waitUntilIdle()}closeGraph(){this.h._closeGraph(),this.h.simpleListeners=void 0,this.h.emptyPacketListeners=void 0}},class extends Sr{O(){this.h._registerModelResourcesGraphService()}});var Sr;async function Ar(t,e){const r=await(async(t,e,r)=>{var n=Qr;if(t&&await mr(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await mr(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&r&&((t=self.Module).locateFile=r.locateFile,r.mainScriptUrlOrBlob&&(t.mainScriptUrlOrBlob=r.mainScriptUrlOrBlob)),r=await self.ModuleFactory(self.Module||r),self.ModuleFactory=self.Module=void 0,new n(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return await r.C(e),r}async function Tr(t,e){return Ar(t,e)}function Ir(t){try{const e=t.u.length;if(1===e)throw Error(t.u[0].message);if(1<e)throw Error("Encountered multiple errors: "+t.u.map((t=>t.message)).join(", "))}finally{t.u=[]}}function Pr(t,e){t.B=Math.max(t.B,e)}var Er=class{constructor(t){this.i=t,this.u=[],this.B=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.u.push(Error(e))})),this.i.O(),this.i.setGraph(t,e),Ir(this)}finishProcessing(){this.i.finishProcessing(),Ir(this)}close(){this.i.closeGraph()}};Er.prototype.close=Er.prototype.close;var Or=class extends ae{constructor(t){super(t)}},xr=[0,ze,Be,Ee,-1,Le],Lr=class extends ae{constructor(){super()}};function kr(t,e,r,n){if(void 0!==t.data){var i=new Uint8Array(t.data.buffer,e,r);return 1===n&&function(t,e,r){t.i.push([e,r]),t.i.sort(((t,e)=>t[0]-e[0])),e=0;for(const[n,i]of t.i){const t=i;(r=n)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),i}}class Br{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Ur=class{constructor(t,e,r){this.i=t,this.j=e,this.l=r}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}},Nr=class extends ae{constructor(){super()}};Nr.v=[4],Nr.prototype.i=We([0,Fe,2,De,Be]);var Dr=class extends ae{constructor(){super()}},Fr=[0,Ne,-5],Cr=[0,Fe,xe,-1,ze],Vr=class extends ae{constructor(){super()}},jr=[0,Be,-6,1,Be,1,[0,Ne,ze,-2],[0,Ne,Ee],ze,-2,[0,Ne,-1,ze,Ee,Re],1,Ne],Mr=class extends ae{constructor(){super()}};Mr.v=[5];var Gr=[0,jr,Be,1,Be,De],Rr=[0,Pe,Cr,Gr,Be],zr=[0,Be,Ne,-1],Wr=class extends ae{constructor(){super()}};Wr.v=[29],Wr.prototype.i=We([0,Fe,8,Fr,1,Be,1,Be,Rr,zr,1,ze,Fe,Gr,Rr,Be,5,ze,ke,1,xr]);var Hr=class extends ae{constructor(){super()}},$r=class extends ae{constructor(){super()}},qr=[2,4];$r.prototype.i=We([0,qr,Be,Ce,Be,Ge,[0,1,Fe],Ne]);const Kr=function(t){return class extends t{static async P(){var t={requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:524550144}},e=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!e)throw Error("Unable to request adapter from navigator.gpu; ensure WebGPU is enabled.");let r;const n=[];for(const r of t?.requiredFeatures??[])e.features.has(r)?n.push(r):console.warn(`WebGPU feature ${r} is not supported.`);t={...t,requiredFeatures:n};try{r=await e.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return e=await e.requestAdapterInfo(),r.adapterInfo=e,r}N(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}K(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}}}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket(((e,r,n)=>async function(t,e,r,n,i){if(2===i)return t.i=[],t.j=()=>Promise.resolve(void 0),t.l(),Promise.resolve(0);for(;t.size<r+n;){var o=await t.j();if(void 0===o)break;t.i.push(new Br(o))}if(t.size<r+n)throw Error(`Data size is too small: ${t.size}, expected at least ${r+n}.`);o=e._malloc(n)>>>0;let s=0;for(let a=0;a<t.i.length;a++){const u=t.i[a];if(r>=u.length){r-=u.length;continue}const c=Math.min(n,u.length-r);if(void 0===(r=kr(u,r,c,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+s),r=0,s+=c,0==(n-=c))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}(t,this.h,e,r,n)),e)}}}(class extends wr{}));class Yr extends Kr{}function Jr(){return Yr.P()}function Xr(t){const e=function(t){const e=new cr;se(e,10,"text_in"),se(e,10,"token_cost_in"),se(e,16,"streaming_reader"),se(e,15,"text_out"),se(e,15,"text_end"),se(e,15,"token_cost_out");var r=new rr;oe(r,2,"TokenizerInputBuildCalculator"),se(r,3,"text_in"),se(r,4,"prompt"),ur(e,r),oe(r=new rr,2,"ModelDataCalculator"),se(r,6,"MODEL_DATA:__side_packet_1"),se(r,6,"MODEL_TYPE:model_type"),se(r,5,"READ_DATA_FN:streaming_reader"),ur(e,r),oe(r=new rr,2,"Gpt2UnicodeMappingCalculator"),se(r,5,"MODEL_DATA:model_type"),se(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),oe(r=new $e,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new $r,i=Bt($t(t.l))??0;ie(n,1,i),oe(i=new Hr,2,"spm_vocab_model"),null==i&&(i=void 0);var o=n.m;let s=lt(o);St(s);var a=s;let u=0;for(let t=0;t<qr.length;t++){const e=qr[t];null!=Kt(o,a,e)&&(0!==u&&(a=Jt(o,a,u)),u=e)}return(a=u)&&4!==a&&null!=i&&(s=Jt(o,s,a)),Jt(o,s,4,i),ie(n,3,2),He(r,n.i()),oe(n=new rr,2,"TokenizerCalculator"),ne(n,8,$e,r),se(n,5,"MODEL_DATA:__side_packet_1"),se(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),se(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),se(n,6,"PROCESSOR_GETTER:__input_side_1"),se(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),ur(e,n),oe(r=new $e,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),ie(n=new Wr,12,3),oe(n,1,"llm.tflite"),ie(n,14,0),ie(n,22,1),i=Zt(t.l,Or,3),te(n,31,i),Qt(i=new Dr,1,!0,!1),Qt(i,2,!0,!1),Qt(i,5,!0,!1),te(n,10,i),i=new Mr,ie(o=new Vr,1,1),t=Bt($t(t.l))??0,ie(o,2,t),te(i,1,o),te(n,20,i),He(r,n.i()),oe(t=new rr,2,"LlmGpuCalculator"),ne(t,8,$e,r),se(t,3,"INPUT_PROMPT_IDS:__stream_0"),se(t,3,"FINISH:finish"),se(t,5,"MODEL_DATA:__side_packet_1"),se(t,4,"DECODED_IDS:__stream_3"),se(t,4,"OUTPUT_END:__stream_4"),oe(r=new Je,1,"FINISH"),Qt(r,2,!0,!1),ne(t,13,Je,r),ur(e,t),oe(t=new rr,2,"IsPacketPresentCalculator"),se(t,3,"__stream_4"),se(t,4,"text_end"),ur(e,t),oe(t=new $e,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),ie(r=new Nr,5,1),se(r,4,"<eos>"),se(r,4,"<|endoftext|>"),He(t,r.i()),oe(r=new rr,2,"DetokenizerCalculator"),ne(r,8,$e,t),se(r,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),se(r,5,"PROCESSOR_GETTER:__input_side_1"),se(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),se(r,5,"MODEL_DATA:__side_packet_1"),se(r,4,"FINISH_AND_INPUT_OPTIONS:finish"),se(r,4,"WORDS:text_out"),ur(e,r),oe(t=new rr,2,"TokenCostCalculator"),se(t,3,"PROMPT:token_cost_in"),se(t,5,"PROCESSOR_GETTER:__input_side_1"),se(t,5,"BYTES_TO_UNICODE_MAPPING:__input_side_2"),se(t,4,"NUM_TOKENS:token_cost_out"),ur(e,t),e}(t);t.i.attachStringVectorListener("text_out",((e,r)=>{var n=0===t.A.length;null==e||0===e.length?n="":(e=(e=(e=e[0]).replaceAll("▁"," ")).replaceAll("<0x0A>","\n"),n&&(e=e.trimStart()),n=e.split("\\[eod\\]",1)[0]),t.A.push(n),t.D&&t.D(n,!1),Pr(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{Pr(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{t.j=!1,t.I&&t.I(t.A.join("")),t.D&&t.D("",!0),Pr(t,r)})),t.i.attachEmptyPacketListener("text_end",(e=>{t.j=!1,Pr(t,e)})),t.i.attachIntListener("token_cost_out",((e,r)=>{t.H=e,Pr(t,r)})),t.G&&t.i.addStreamingReaderToInputSidePacket(t.G,"streaming_reader");const r=e.i();return t.i.K().then((()=>{t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}var Qr=class extends Er{constructor(t,e){if(super(new Yr(t,e)),this.A=[],this.j=!1,te(t=this.l=new Lr,1,e=new lr),this.o=new Or,te(this.l,3,this.o),Yt(this.l,2,kt(512)),t=this.o,!Number.isFinite(2))throw It("enum");Qt(t,1,2,0),ie(this.o,2,1),Qt(this.o,3,Pt(1),0),Qt(this.o,4,Pt(1),0)}C(t){if(this.j)throw Error("Cannot set options while loading or processing.");let e;this.j=!0,t.baseOptions?.gpuOptions?.device&&this.i.N(t.baseOptions.gpuOptions.device),"maxTokens"in t&&Yt(this.l,2,kt(t.maxTokens??512)),"topK"in t&&(ie(this.o,2,t.topK??1),t.topK&&!t.randomSeed&&console.warn("'topK' option ignored; it requires randomSeed to be set.")),"temperature"in t&&(Qt(this.o,4,Pt(t.temperature??1),0),t.temperature&&!t.randomSeed&&console.warn("'temperature' option ignored; it requires randomSeed to be set.")),t.randomSeed&&Yt(this.o,5,xt(t.randomSeed));const r=new Promise((t=>{e=t}));if(t.baseOptions?.modelAssetPath||t.baseOptions?.modelAssetBuffer){if(t.baseOptions.modelAssetPath&&t.baseOptions.modelAssetBuffer)throw Error("Cannot set both baseOptions.modelAssetPath and baseOptions.modelAssetBuffer");t.baseOptions.modelAssetPath?this.G=function(t,e){const r=fetch(t.toString()).then((t=>t?.body?.getReader()));return new Ur([],(async()=>{let e;try{e=await r}catch(e){throw Error(`Error loading model from "${t.toString()}": ${e}`)}const{value:n,done:i}=await e.read();if(!i)return n}),e)}(t.baseOptions.modelAssetPath,e):t.baseOptions.modelAssetBuffer?(this.G=function(t,e){return new Ur([new Br(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,e),t.baseOptions.modelAssetBuffer=void 0):e()}const n=Xr(this).then((()=>{}));return r.then((()=>{n.then((()=>{this.j=!1}))}))}get baseOptions(){return Zt(this.l,lr,1)}set baseOptions(t){te(this.l,1,t)}M(t,e){if(this.j)throw Error("Previous invocation or loading is still ongoing.");return e&&(this.D=e),this.A.length=0,this.j=!0,this.i.addStringToStream(t,"text_in",this.B+1),this.finishProcessing(),new Promise((t=>{this.I=t}))}R(t){if(this.j)throw Error("Previous invocation or loading is still ongoing.");return this.j=!0,this.H=void 0,this.i.addStringToStream(t,"token_cost_in",this.B+1),this.finishProcessing(),this.j=!1,this.H}close(){super.close()}};Qr.prototype.sizeInTokens=Qr.prototype.R,Qr.prototype.generateResponse=Qr.prototype.M,Qr.prototype.setOptions=Qr.prototype.C,Qr.createWebGpuDevice=Jr,Qr.createFromModelPath=async function(t,e){return Tr(t,e={baseOptions:{gpuOptions:{device:await Jr()},modelAssetPath:e}})},Qr.createFromModelBuffer=async function(t,e){return Tr(t,e={baseOptions:{gpuOptions:{device:await Jr()},modelAssetBuffer:e}})},Qr.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Jr();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Tr(t,e)},exports.FilesetResolver=gr,exports.LlmInference=Qr,exports.TaskRunner=Er;
2
2
  //# sourceMappingURL=genai_bundle_cjs.js.map