@mediapipe/tasks-genai 0.10.14 → 0.10.15-rc.20240515
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 +3 -1
- 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 +1 -1
- package/wasm/genai_wasm_internal.js +0 -0
- package/wasm/genai_wasm_internal.wasm +0 -0
- package/wasm/genai_wasm_nosimd_internal.js +0 -0
- package/wasm/genai_wasm_nosimd_internal.wasm +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,9 @@ The MediaPipe LLM Inference task generates text response from input text.
|
|
|
8
8
|
|
|
9
9
|
In order to begin, you must have a model available. You can download [Gemma
|
|
10
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)
|
|
11
|
+
(TensorFlow Lite 2b-it-gpu-int4 or 2b-it-gpu-int8) and [Gemma
|
|
12
|
+
7B](https://www.kaggle.com/models/google/gemma/tfLite/gemma-1.1-7b-it-gpu-int8)
|
|
13
|
+
(TensorFlow Lite 7b-it-gpu-int8) or convert an external LLM
|
|
12
14
|
(Phi-2, Falcon, or StableLM) following the
|
|
13
15
|
[guide](https://developers.google.com/mediapipe/solutions/genai/llm_inference/web_js#convert-model).
|
|
14
16
|
Note that only models encoded for the GPU backend are currently supported.
|
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 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 E(t){return v&&null!=t&&t instanceof Uint8Array}let I;var P={};let O;function L(t){if(t!==P)throw Error("illegal external caller")}function U(){return O||=new x(null,P)}var x=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 k(t){if("string"==typeof t)return{buffer:T(t),v:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),v:!1};if(t.constructor===Uint8Array)return{buffer:t,v:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),v:!1};if(t.constructor===x){L(P);var e=t.i;return{buffer:(null==(e=null==e||E(e)?e:"string"==typeof e?T(e):null)?e:t.i=e)||(I||=new Uint8Array(0)),v:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),v:!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 B(){return"function"==typeof BigInt}let N,j=0,D=0;function F(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}j=r>>>0,D=t>>>0}function V(t,e){if(t>>>=0,2097151>=(e>>>=0))var r=""+(4294967296*e+t);else B()?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+M(r)+M(t));return r}function M(t){return t=String(t),"0000000".slice(t.length)+t}function C(t){if(16>t.length)F(Number(t));else if(B())t=BigInt(t),j=Number(t&BigInt(4294967295))>>>0,D=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);D=j=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));D*=1e6,j=1e6*j+e,4294967296<=j&&(D+=Math.trunc(j/4294967296),D>>>=0,j>>>=0)}if(e){const[t,e]=G(j,D);j=t,D=e}}}function G(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function R(t){return t?/^\d+$/.test(t)?(C(t),new z(j,D)):null:W||=new z(0,0)}var z=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let W;function $(t){return t?/^-?\d+$/.test(t)?(C(t),new H(j,D)):null:q||=new H(0,0)}var H=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.N=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=nt("0dg"),at=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}})},ut=it?(t,e)=>{t[it]&=~e}:(t,e)=>{void 0!==t.i&&(t.i&=~e)};function ct(t,e,r){return r?t|e:t&~e}var lt=it?t=>0|t[it]:t=>0|t.i,ht=it?t=>t[it]:t=>t.i,ft=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 dt(t,e){ft(e,-14591&(0|t))}function pt(t,e){ft(e,-14557&(34|t))}function gt(t){return 0===(t=t>>14&1023)?536870912:t}var mt,_t={},vt={};function yt(t){return!(!t||"object"!=typeof t||t.i!==vt)}function bt(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function wt(t,e,r){if(!Array.isArray(t)||t.length)return!1;const n=lt(t);return!!(1&n)||!(!e||!(Array.isArray(e)?e.includes(r):e.has(r)))&&(ft(t,1|n),!0)}const St=[];function At(t){if(2&t)throw Error()}ft(St,55),mt=Object.freeze(St);function Tt(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let Et;function It(){const e=Error();Tt(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function Pt(t){return Tt(t=Error(t),"warning"),t}function Ot(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 Lt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Ut(t){const e=typeof t;return"number"===e?Number.isFinite(t):"string"===e&&Lt.test(t)}function xt(t){if("number"!=typeof t)throw Pt("int32");if(!Number.isFinite(t))throw Pt("int32");return 0|t}function kt(t){return null==t?t:xt(t)}function Bt(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function Nt(t){if(null!=t){if("number"!=typeof t)throw Pt("uint32");if(!Number.isFinite(t))throw Pt("uint32");t>>>=0}return t}function jt(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 Dt(t){return"-"!==t[0]&&(20>t.length||20===t.length&&184467>Number(t.substring(0,6)))}function Ft(t){return null==t||"string"==typeof t?t:void 0}function Vt(t,e,r){if(null!=t&&"object"==typeof t&&t.K===_t)return t;if(Array.isArray(t)){var n=lt(t),i=n;return 0===i&&(i|=32&r),(i|=2&r)!==n&&ft(t,i),new e(t)}}let Mt,Ct,Gt;function Rt(t,e,r){if(null==t&&(t=Mt),Mt=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=lt(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(bt(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 ft(t,n),t}function zt(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=wt(t,void 0,0)?void 0:i&&2<(t)?t:Wt(t,e,r,void 0!==n,i);else if(bt(t)){const o={};for(let s in t)o[s]=zt(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function Wt(t,e,r,n,i){const o=n||r?lt(t):0;n=n?!!(32&o):void 0,t=rt(t);for(let o=0;o<t.length;o++)t[o]=zt(t[o],e,r,n,i);return r&&r(o,t),t}function $t(t){return t.K===_t?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(wt(t,void 0,0))return}else{if(E(t))return b(t);if(t instanceof x){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=b(e)}}}return t}(t)}function Ht(t,e,r=pt){if(null!=t){if(v&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=lt(t);return 2&n||(e&&=0===n||!!(32&n)&&!(64&n||!(16&n)),t=e?ft(t,-12293&(34|n)):Wt(t,Ht,4&n?pt:r,!0,!0)),t}return t.K===_t&&(r=t.m,t=2&(n=ht(r))?t:qt(t,r,n,!0)),t}}function qt(t,e,r,n){return t=t.constructor,Mt=e=function(t,e,r){const n=r||2&e?pt:dt,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=>Ht(t,i,n))),at(t,32|(r?2:0)),t}(e,r,n),e=new t(e),Mt=void 0,e}function Kt(t){const e=t.m,r=ht(e);return 2&r?qt(t,e,r,!1):t}function Yt(t,e,r,n){return!(4&e)||null!=r&&(!n&&0===r&&(4096&e||8192&e)&&5>(t.constructor[st]=1+(0|t.constructor[st]))&&It(),0!==r&&!(r&e))}function Jt(t){return Qt(t=t.m,ht(t),2)}function Xt(t,e,r,n){if(!(0>(e=n+(+!!(512&e)-1))||e>=t.length||e>=r))return t[e]}function Qt(t,e,r,n){if(-1===r)return null;const i=gt(e);if(!(r>=i)){var o=t.length;return n&&256&e&&null!=(n=t[o-1][r])?(Xt(t,e,i,r)&&null!=ot&&(4<=(e=(t=Et??={})[ot]||0)||(t[ot]=e+1,It())),n):Xt(t,e,i,r)}return 256&e?t[t.length-1][r]:void 0}function Zt(t,e,r){const n=t.m;let i=ht(n);return At(i),te(n,i,e,r),t}function te(t,e,r,n,i){const o=gt(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&&ft(t,s),s}return t[r+(+!!(512&e)-1)]=n,256&e&&(r in(t=t[t.length-1])&&delete t[r]),e}function ee(t,e,r){return t=Qt(t,e,r),Array.isArray(t)?t:mt}function re(t,e){return 0===t&&(t=ue(t,e)),ct(t,1,!0)}function ne(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function ie(t,e,r){{const a=t.m;let u=ht(a);if(At(u),null==r)te(a,u,e);else{var n,i=lt(r),o=i,s=!!(2&i)||Object.isFrozen(r);if((n=!s)&&(n=!1),Yt(t,i))for(i=21,s&&(r=rt(r),o=0,i=ce(i=ue(i,u),u,!0)),t=0;t<r.length;t++)r[t]=xt(r[t]);n&&(r=rt(r),o=0,i=ce(i=ue(i,u),u,!0)),i!==o&&ft(r,i),te(a,u,e,r)}}}function oe(t,e,r,n){t=t.m;let i=ht(t);At(i),te(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function se(t,e,r){var n=t.m,i=ht(n),o=Qt(n,i,r,!1);return(e=Vt(o,e,i))!==o&&null!=e&&te(n,i,r,e,!1),null==(n=e)||(t=t.m,2&(i=ht(t))||(o=Kt(n))!==n&&te(t,i,r,n=o,!1)),n}function ae(t,e,r){return null==r&&(r=void 0),Zt(t,e,r)}function ue(t,e){return t=ct(t,2,!!(2&e)),t=ct(t,32,!0),ct(t,2048,!1)}function ce(t,e,r){return 32&e&&r||(t=ct(t,32,!1)),t}function le(t,e,r,n){t=t.m;var i=ht(t);At(i);var o=!!(2&i);const s=o?1:2;f&&=!o,o=ee(t,i,e);var a=lt(o);const u=!!(4&a);if(!u){var c=o,l=i,h=!!(2&(a=re(a,i)));h&&(l=ct(l,2,!0));let t=!h,e=!0,n=0,s=0;for(;n<c.length;n++){const i=Vt(c[n],r,l);if(i instanceof r){if(!h){const r=!!(2<(i.m));t&&=!r,e&&=r}c[s++]=i}}s<n&&(c.length=s),a=ct(a,4,!0),a=ct(a,16,e),a=ct(a,8,t),ft(c,a),h&&Object.freeze(c)}if(f&&!(8&a||!o.length&&(1===s||4===s&&32&a))){ne(a)&&(o=rt(o),a=ue(a,i),i=te(t,i,e,o));var f=o;for(c=a,a=0;a<f.length;a++)(l=f[a])!==(h=Kt(l))&&(f[a]=h);c=ct(c,8,!0),c=ct(c,16,!f.length),ft(f,c),a=c}ne(a)||(f=a,(a=(c=1===s||4===s&&!!(32&a))?ct(a,!o.length||16&a&&(!u||32&a)?2:2048,!0):ce(a,i,!0))!==f&&ft(o,a),c&&Object.freeze(o)),2===s&&ne(a)&&(o=rt(o),a=ce(a=ue(a,i),i,!0),ft(o,a),te(t,i,e,o)),e=o,r=null!=n?n:new r,e.push(r),2<(r.m)?ut(e,8):ut(e,16)}function he(t,e,r){oe(t,e,kt(r),0)}function fe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();oe(t,e,r,"")}function de(t,e,r){t=t.m;const n=ht(t);At(n);var i=2&n;let o=Qt(t,n,e);Array.isArray(o)||(o=mt);const s=!!(32&n);let a=lt(o);if(0===a&&s&&!i?(a|=33,ft(o,a)):1&a||(a|=1,ft(o,a)),i?(2&a||at(o,34),Object.freeze(o)):(2&a||2048&a)&&(o=rt(o),i=1,s&&(i|=32),ft(o,i),te(t,n,e,o)),"string"!=typeof r)throw Error();o.push(r)}var pe=class{constructor(t,e){this.m=Rt(t,e)}toJSON(){return ge(this,Wt(this.m,$t,void 0,void 0,!1),!0)}v(){return!!(2<(this.m))}};function ge(t,e,r){var n=a?void 0:t.constructor.A;const i=ht(r?t.m:e);if(!(t=e.length))return e;let o,s;if(bt(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;(wt(r,n,+c)||yt(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||wt(r,n,l)||yt(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 me(t,e){if(Array.isArray(e)){var r=lt(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),ft(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}pe.prototype.K=_t,pe.prototype.toString=function(){return ge(this,this.m,!1).toString()};const _e=Symbol(),ve=Symbol();function ye(t){let e=t[ve];if(!e){const r=Ae(t);e=(t,e)=>Ie(t,e,r),t[ve]=e}return e}const be=Symbol();function we(t){return t.i}function Se(t,e){let r,n;const i=t.i;return(t,o,s)=>i(t,o,s,n||=Ae(e).i,r||=ye(e))}function Ae(t){var e=t[be];if(e)return e;var r=we,n=Se;(e=t[be]={}).i=function(t){switch(typeof t){case"boolean":return Ct||=[0,void 0,!0];case"number":return 0<t?void 0:0===t?Gt||=[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.R=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=Ke,i--),f.N){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 Te in t&&_e in t&&be in t&&(t.length=0),e}const Te=Symbol();function Ee(t,e){var r=t[e];if(r)return r;if((r=t.R)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof et?r:[qe,r]:[r,void 0])[0].i;if(r=r[1]){const e=ye(r),i=Ae(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 Ie(t,e,r){var n=ht(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=Ee(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=Ee(r,n))&&o(e,i,n)}}function Pe(t){return new et(t,!1)}function Oe(t,e,r){null!=(e=Bt(e))&&null!=e&&(Y(t.i,8*r),J(t.i,e))}function Le(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 Ue(t,e,r){null!=(e=Ft(e))&&tt(t,r,i(e))}function xe(t,e,r,n,i){null!=(e=e instanceof pe?e.m:Array.isArray(e)?Rt(e,n[0],n[1]):void 0)&&(r=Q(t,r),i(e,t),Z(t,r))}function ke(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),Y(t.i,8*r),J(t.i,e))}var Be,Ne=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=N||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),D=0,e=j=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))})),je=Pe((function(t,e,r){t:if(null!=e){if(Ut(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(C(e),e=j,2147483648&(n=D))if(B())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)){F(e),n=j;var i=D;(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&&$(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,F(e),K(t,j,D)):(r=$(e),K(t.i,r.j,r.i))))})),De=Pe((function(t,e,r){t:if(null!=e){if(Ut(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)),Dt(e)||(C(e),e=V(j,D)));break t}if("number"==typeof e){e=0<=(e=Math.trunc(e))&&Number.isSafeInteger(e)?e:function(t){if(0>t){F(t);const e=V(j,D);return t=Number(e),Number.isSafeInteger(t)?t:e}return Dt(String(t))?t:(F(t),4294967296*D+(j>>>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,F(e),K(t,j,D)):(r=R(e),K(t.i,r.j,r.i))))})),Fe=Pe(Oe),Ve=new et((function(t,e,r){if(null!=(e=me(Bt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Me=Pe(Oe),Ce=Pe(Oe),Ge=Pe(Le),Re=Pe(Le),ze=new et((function(t,e,r){if(null!=(e=me(Ft,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),We=Pe(Ue),$e=Pe(Ue),He=Pe(Ue),qe=new et(xe,!0),Ke=new et(xe,!0);Be=new et((function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)xe(t,e[o],r,n,i)}),!0);var Ye=new et(xe,!0),Je=Pe(ke),Xe=new et((function(t,e,r){if(null!=(e=me(Bt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Qe=Pe(ke);function Ze(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}}}};Ie(this.m,e,Ae(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 tr(t,e){if(null!=e)if(Array.isArray(e))Zt(t,2,Wt(e,$t,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof x||E(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new x(e,P):U();else if(e.constructor!==x){if(!E(e))throw Error();e=e.length?new x(new Uint8Array(e),P):U()}oe(t,2,e,U())}}var er=class extends pe{constructor(t){super(t)}},rr=[0,We,Pe((function(t,e,r){if(null!=e){if(e instanceof pe){const n=e.Y;return void(n&&(e=n(e),null!=e&&tt(t,r,k(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||E(e)||e instanceof x?e:void 0)&&tt(t,r,k(e).buffer)}))],nr={},ir=[-2,nr,Ge];nr[336783863]=[0,He,Ge,-1,Fe,[0,[1,2,3,4,5,6],Ye,[0],Ye,[0,Ge,He,Ge,Je,-1,Xe,He,-1,[0,Ge,-1],Je],Ye,[0,He,-2],Ye,[0,Fe,Ge,-4],Ye,[0,Fe,Je,Ge,-1,Ve,Je,-1],Ye,[0,He]],[0,He],Ge,[0,[1,3],[2,4],Ye,[0,Ve],-1,Ye,[0,ze],-1,Be,[0,He,-1]],He];var or=class extends pe{constructor(t){super(t)}},sr=[0,We,Re],ar=[0,je,-1,Re,-3,je,Ve,We,Me,je,-1,Re,Me,Re,-2,We],ur=[-1,{}],cr=[0,He,1,ur],lr=[0,He,ze,ur],hr=class extends pe{constructor(t){super(t,500)}J(t){return ae(this,7,t)}};hr.A=[3,4,5,6,8,13,17,1005];var fr=[-500,We,-1,ze,-3,ir,Be,rr,Me,-1,cr,lr,Be,sr,We,ar,Me,ze,987,ze],dr=[0,We,-1,ur],pr=[-500,He,-1,[-1,{}],998,He],gr=[-500,He,ze,-1,[-2,{},Ge],997,ze,-1],mr=[-500,He,ze,ur,998,ze];function _r(t,e){le(t,1,hr,e)}var vr=class extends pe{constructor(){super(void 0,500)}J(t){return ae(this,1001,t)}};vr.A=[1,6,7,9,10,15,16,17,14,1002],vr.prototype.i=Ze([-500,Be,fr,4,Be,pr,Be,gr,Me,Be,mr,ze,Me,cr,lr,Be,dr,ze,-2,ar,We,-1,Re,979,ur,Be,rr]);var yr=class extends pe{constructor(t){super(t)}};let br;const wr=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===br)try{await WebAssembly.instantiate(wr),br=!0}catch{br=!1}return br}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 Tr=class{};function Er(){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/))&&1<=t.length&&17<=Number(t[1])))}async function Ir(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())}Tr.forVisionTasks=function(t){return Ar("vision",t)},Tr.forTextTasks=function(t){return Ar("text",t)},Tr.forGenAiExperimentalTasks=function(t){return Ar("genai_experimental",t)},Tr.forGenAiTasks=function(t){return Ar("genai",t)},Tr.forAudioTasks=function(t){return Ar("audio",t)},Tr.isSimdSupported=function(){return Sr()};function Pr(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 Or(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 Lr(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function Ur(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 xr=(kr=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:Er()?this.h.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas"))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),Pr(this,n||"input_audio",(n=>{Pr(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),Pr(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){Pr(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){Pr(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){Pr(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){Pr(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){Pr(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){Pr(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){Pr(this,e,(e=>{Pr(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){Pr(this,e,(e=>{Or(this,Object.keys(t),(n=>{Or(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){Pr(this,r,(r=>{Pr(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){Pr(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){Pr(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){Pr(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){Pr(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){Pr(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)}))}addUintVectorToStream(t,e,r){Pr(this,e,(e=>{const n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputStream(n,e,r)}))}addStringVectorToStream(t,e,r){Pr(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)Pr(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){Pr(this,e,(e=>{Pr(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){Pr(this,r,(r=>{Pr(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){Pr(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){Pr(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){Pr(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){Pr(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)}))}addUintVectorToInputSidePacket(t,e){Pr(this,e,(e=>{const r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)}))}addStringVectorToInputSidePacket(t,e){Pr(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)Pr(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){Ur(this,t,e),Pr(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?'),Lr(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),Pr(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 kr{V(){this.h._registerModelResourcesGraphService()}});var kr;async function Br(t,e){const r=await(async(t,e,r)=>{var n=mn;if(t&&await Ir(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await Ir(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&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.J(e),r}async function Nr(t,e){return Br(t,e)}function jr(t){try{const e=t.D.length;if(1===e)throw Error(t.D[0].message);if(1<e)throw Error("Encountered multiple errors: "+t.D.map((t=>t.message)).join(", "))}finally{t.D=[]}}function Dr(t,e){t.B=Math.max(t.B,e)}var Fr=class{constructor(t){this.i=t,this.D=[],this.B=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.D.push(Error(e))})),this.i.V(),this.i.setGraph(t,e),jr(this)}finishProcessing(){this.i.finishProcessing(),jr(this)}close(){this.i.closeGraph()}};Fr.prototype.close=Fr.prototype.close;var Vr=class extends pe{constructor(t){super(t)}},Mr=[0,Qe,Me,Ne,-1,Fe];function Cr(t,e){ae(t,1,e)}var Gr=class extends pe{constructor(){super()}};function Rr(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}}Gr.A=[4];class zr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Wr=class{constructor(t,e,r){this.i=t,this.j=e,this.l=r}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function $r(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Hr=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))}},qr=class extends pe{constructor(){super()}};qr.A=[4],qr.prototype.i=Ze([0,We,2,ze,Me]);var Kr=class extends pe{constructor(){super()}},Yr=[0,Re,-5],Jr=[0,We,De,-1,Qe],Xr=class extends pe{constructor(){super()}},Qr=[0,Me,-6,1,Me,1,[0,Re,Qe,-2],[0,Re,Ne],Qe,-2,[0,Re,-1,Qe,Ne,Je],1,Re],Zr=class extends pe{constructor(){super()}};Zr.A=[5,7];var tn=[0,[4,6],Qr,Me,1,Ce,ze,$e,Xe],en=[0,Be,Jr,tn,Me],rn=[0,Me,Re,-1],nn=class extends pe{constructor(){super()}};nn.A=[29],nn.prototype.i=Ze([0,We,8,Yr,1,Me,1,Me,en,rn,1,Qe,We,tn,en,Me,5,Qe,Ve,1,Mr]);var on=class extends pe{constructor(){super()}},sn=class extends pe{constructor(){super()}},an=[2,4];sn.prototype.i=Ze([0,an,Me,$e,Me,Ye,[0,1,We]]);const un=function(t){return class e extends t{static async W(t,r){let n;r||=await e.M();const i=[];for(const e of t?.requiredFeatures??[])r.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{n=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return r=await r.requestAdapterInfo(),n.adapterInfo=r,n}static async M(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}T(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}P(){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 zr(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=Rr(u,r,c,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+s),r=0,s+=c,0==(n-=c))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}(t,this.h,e,r,n)),e)}}}(function(t){return class extends t{O(t,e){Pr(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends xr{})));class cn extends un{}var ln=class{constructor(t){this.j=t,this.i=hn,hn++}},hn=0;class fn{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.i=t,this.j=e}}async function dn(){const t=await cn.M({powerPreference:"high-performance"});var e=t.limits.maxBufferSize;if(524550144>t.limits.maxStorageBufferBindingSize)throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxStorageBufferBindingSize is at least 524550144 but your device only supports maxStorageBufferBindingSize of ${e}`);if(786825216<=e)e=786825216;else{if(!(524550144<=e))throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxBufferSize is at least 524550144 but your device only supports maxBufferSize of ${e}`);e=524550144}return cn.W({requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:e}},t)}function pn(t){const e=function(t){const e=new vr;de(e,10,"text_in"),de(e,10,"token_cost_in"),de(e,10,"lora_model_id_to_apply_in"),de(e,10,"lora_model_ref_in"),de(e,10,"lora_model_id_to_load_in"),de(e,16,"streaming_reader"),de(e,15,"text_out"),de(e,15,"text_end"),de(e,15,"token_cost_out");var r=new hr;fe(r,2,"TokenizerInputBuildCalculator"),de(r,3,"PROMPT:text_in"),de(r,3,"LORA_ID:lora_model_id_to_apply_in"),de(r,4,"prompt"),_r(e,r),fe(r=new hr,2,"ModelDataCalculator"),de(r,6,"MODEL_DATA:__side_packet_1"),de(r,6,"MODEL_TYPE:model_type"),de(r,5,"READ_DATA_FN:streaming_reader"),de(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),de(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),de(r,4,"LORA_DATA:lora_model_data"),_r(e,r),fe(r=new hr,2,"Gpt2UnicodeMappingCalculator"),de(r,5,"MODEL_TYPE:model_type"),de(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_r(e,r),fe(r=new er,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new sn,i=jt(Jt(t.l))??0;he(n,1,i),fe(i=new on,2,"spm_vocab_model"),null==i&&(i=void 0);var o=n.m,s=ht(o);At(s);for(var a=s,u=0,c=0;c<an.length;c++){var l=an[c];null!=Qt(o,a,l)&&(0!==u&&(a=te(o,a,u)),u=l)}if((a=u)&&4!==a&&null!=i&&(s=te(o,s,a)),te(o,s,4,i),he(n,3,2),tr(r,n.i()),fe(n=new hr,2,"TokenizerCalculator"),le(n,8,er,r),de(n,5,"MODEL_DATA:__side_packet_1"),de(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),de(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(n,6,"PROCESSOR_GETTER:__input_side_1"),de(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),_r(e,n),fe(r=new er,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),he(n=new nn,12,3),fe(n,1,"llm.tflite"),he(n,14,0),he(n,22,1),i=se(t.l,Vr,3),ae(n,31,i),oe(i=new Kr,1,!0,!1),oe(i,2,!0,!1),oe(i,5,!0,!1),ae(n,10,i),c=t.l,i=c.m,o=ht(i),s=2&o?1:2,a=ee(i,o,4),u=lt(a),Yt(c,u,void 0,!1)){for((4&u||Object.isFrozen(a))&&(a=rt(a),u=ue(u,o),o=te(i,o,4,a)),l=c=0;c<a.length;c++){const t=Bt(a[c]);null!=t&&(a[l++]=t)}l<c&&(a.length=l),u=ct(u=re(u,o),20,!0),u=ct(u,4096,!1),u=ct(u,8192,!1),ft(a,u),2&u&&Object.freeze(a)}return ne(u)||(c=u,(u=(l=1===s||4===s&&!!(32&u))?ct(u,2,!0):ce(u,o,!1))!==c&&ft(a,u),l&&Object.freeze(a)),2===s&&ne(u)&&(a=rt(a),u=ce(u=ue(u,o),o,!1),ft(a,u),te(i,o,4,a)),ie(n,29,a),i=new Zr,he(o=new Xr,1,1),t=jt(Jt(t.l))??0,he(o,2,t),ae(i,1,o),ae(n,20,i),tr(r,n.i()),fe(t=new hr,2,"LlmGpuCalculator"),le(t,8,er,r),de(t,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),de(t,3,"FINISH:finish"),de(t,3,"LORA_DATA:lora_model_data"),de(t,5,"MODEL_DATA:__side_packet_1"),de(t,4,"DECODED_IDS:__stream_3"),de(t,4,"OUTPUT_END:__stream_4"),fe(r=new or,1,"FINISH"),oe(r,2,!0,!1),le(t,13,or,r),_r(e,t),fe(t=new hr,2,"IsPacketPresentCalculator"),de(t,3,"__stream_4"),de(t,4,"text_end"),_r(e,t),fe(t=new er,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),he(r=new qr,5,1),de(r,4,"<eos>"),de(r,4,"<|endoftext|>"),tr(t,r.i()),fe(r=new hr,2,"DetokenizerCalculator"),le(r,8,er,t),de(r,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),de(r,5,"PROCESSOR_GETTER:__input_side_1"),de(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(r,5,"MODEL_DATA:__side_packet_1"),de(r,4,"FINISH_AND_INPUT_OPTIONS:finish"),de(r,4,"WORDS:text_out"),_r(e,r),fe(t=new hr,2,"TokenCostCalculator"),de(t,3,"PROMPT:token_cost_in"),de(t,5,"PROCESSOR_GETTER:__input_side_1"),de(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(t,4,"NUM_TOKENS:token_cost_out"),_r(e,t),e}(t);t.i.attachStringVectorListener("text_out",((e,r)=>{var n=0===t.G.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.G.push(n),t.I&&0===t.C.length&&t.I(n,!1),Dr(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{Dr(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{t.j=!1,Dr(t,r),gn(t),t.o&&(t.o.i(t.G.join("")),t.o=void 0),t.I&&t.I("",!0)})),t.i.attachEmptyPacketListener("text_end",(e=>{t.j=!1,Dr(t,e),gn(t),t.o&&(t.o.i(t.G.join("")),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,r)=>{t.L=e,Dr(t,r)})),t.H&&t.i.addStreamingReaderToInputSidePacket(t.H,"streaming_reader");const r=e.i();return t.u?.removeEventListener("uncapturederror",t.F),t.i.P().then((()=>{t.u?.addEventListener("uncapturederror",t.F),t.C.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function gn(t){if(0<t.C.length){const e=[...t.C];if(t.C.length=0,!t.o)throw e;t.o.j(e),t.o=void 0}}var mn=class extends Fr{constructor(t,e){if(super(new cn(t,e)),this.G=[],this.j=!1,this.C=[],this.F=t=>{const e=(t=t.error).message.match(/exceeds the max buffer size limit \(([0-9]+)\)\./);e&&524550144<Number(e[1])?t=Error(`Failed to run this LLM model, but you could try a smaller LLM model. WebGPU throws: "${t.message}"`):t.message.match(/is larger than the maximum binding size/)&&(t=Error(`Failed to run LLM inference, the supported max binding size is smaller than the required size. WebGPU throws: "${t.message}"`)),this.C.push(t)},this.l=new Gr,Cr(this.l,new yr),this.s=new Vr,ae(this.l,3,this.s),Zt(this.l,2,Nt(512)),t=this.s,!Number.isFinite(2))throw Pt("enum");oe(t,1,2,0),he(this.s,2,1),oe(this.s,3,Ot(1),0),oe(this.s,4,Ot(1),0)}J(t){if(this.j)throw Error("Cannot set options while loading or processing.");let e;this.j=!0,t.baseOptions?.gpuOptions?.device&&(this.u&&this.u.removeEventListener("uncapturederror",this.F),this.u=t.baseOptions.gpuOptions.device,this.i.T(this.u),this.u.addEventListener("uncapturederror",this.F)),"maxTokens"in t&&Zt(this.l,2,Nt(t.maxTokens??512)),"topK"in t&&(he(this.s,2,t.topK??1),t.topK&&!t.randomSeed&&console.warn("'topK' option ignored; it requires randomSeed to be set.")),"temperature"in t&&(oe(this.s,4,Ot(t.temperature??1),0),t.temperature&&!t.randomSeed&&console.warn("'temperature' option ignored; it requires randomSeed to be set.")),t.randomSeed&&Zt(this.s,5,kt(t.randomSeed)),"loraRanks"in t&&function(t,e){ie(t,4,e)}(this.l,t.loraRanks??[]);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");let r=!1;t.baseOptions.modelAssetPath?this.H=function(t,e){const r=fetch(t.toString()).then((t=>t?.body?.getReader()));return new Wr([],(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 instanceof Uint8Array?(this.H=function(t,e){return new Wr([new zr(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,e),r=!0):t.baseOptions.modelAssetBuffer?(this.H=function(t,e){return new Wr([],(async()=>{const{value:e,done:r}=await t.read();if(!r)return e}),e)}(t.baseOptions.modelAssetBuffer,e),r=!0):e(),r&&(t.baseOptions.modelAssetBuffer=void 0)}return t=pn(this).then((()=>{})),Promise.all([r,t]).then((()=>{this.j=!1,gn(this)}))}get baseOptions(){return se(this.l,yr,1)}set baseOptions(t){Cr(this.l,t)}S(t,e,r){if(this.j)throw Error("Previous invocation or loading is still ongoing.");if(this.I="function"==typeof e?e:r,this.G.length=0,this.j=!0,r=this.B+1,this.i.addStringToStream(t,"text_in",r),e instanceof ln){if(e.j!==this)throw this.j=!1,Error("The LoRA model was not loaded by this LLM Inference task.");this.i.addUintToStream(e.i,"lora_model_id_to_apply_in",r)}else this.i.addEmptyPacketToStream("lora_model_id_to_apply_in",r);return this.finishProcessing(),this.o=new fn,this.o.promise}X(t){if(this.j)throw Error("Previous invocation or loading is still ongoing.");return this.j=!0,this.L=void 0,this.i.addStringToStream(t,"token_cost_in",this.B+1),this.finishProcessing(),this.j=!1,this.L}async U(t){if(this.j)throw Error("Cannot load LoRA model while loading or processing.");if(this.j=!0,t instanceof Uint8Array){var e=new Hr(this.i.h,t.length);e.set(t),t=e}else t=await async function(t,e){var r=await fetch(e.toString());e=Number(r.headers.get("content-length")),t=new Hr(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 $r(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${e} bytes before failure`);return t}(this.i.h,t);return e=new ln(this),this.i.O(t,this.B+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.B+1),this.finishProcessing(),$r(t),this.j=!1,e}close(){this.u?.removeEventListener("uncapturederror",this.F),super.close()}};mn.prototype.loadLoraModel=mn.prototype.U,mn.prototype.sizeInTokens=mn.prototype.X,mn.prototype.generateResponse=mn.prototype.S,mn.prototype.setOptions=mn.prototype.J,mn.createWebGpuDevice=dn,mn.createFromModelPath=async function(t,e){return Nr(t,e={baseOptions:{gpuOptions:{device:await dn()},modelAssetPath:e}})},mn.createFromModelBuffer=async function(t,e){return Nr(t,e={baseOptions:{gpuOptions:{device:await dn()},modelAssetBuffer:e}})},mn.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await dn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Nr(t,e)},exports.FilesetResolver=Tr,exports.LlmInference=mn,exports.TaskRunner=Fr;
|
|
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 E(t){return v&&null!=t&&t instanceof Uint8Array}let I;var P={};let O;function L(t){if(t!==P)throw Error("illegal external caller")}function U(){return O||=new x(null,P)}var x=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 k(t){if("string"==typeof t)return{buffer:T(t),v:!1};if(Array.isArray(t))return{buffer:new Uint8Array(t),v:!1};if(t.constructor===Uint8Array)return{buffer:t,v:!1};if(t.constructor===ArrayBuffer)return{buffer:new Uint8Array(t),v:!1};if(t.constructor===x){L(P);var e=t.i;return{buffer:(null==(e=null==e||E(e)?e:"string"==typeof e?T(e):null)?e:t.i=e)||(I||=new Uint8Array(0)),v:!0}}if(t instanceof Uint8Array)return{buffer:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),v:!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 B(){return"function"==typeof BigInt}let N,j=0,D=0;function F(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}j=r>>>0,D=t>>>0}function V(t,e){if(t>>>=0,2097151>=(e>>>=0))var r=""+(4294967296*e+t);else B()?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+M(r)+M(t));return r}function M(t){return t=String(t),"0000000".slice(t.length)+t}function C(t){if(16>t.length)F(Number(t));else if(B())t=BigInt(t),j=Number(t&BigInt(4294967295))>>>0,D=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);D=j=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));D*=1e6,j=1e6*j+e,4294967296<=j&&(D+=Math.trunc(j/4294967296),D>>>=0,j>>>=0)}if(e){const[t,e]=G(j,D);j=t,D=e}}}function G(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function R(t){return t?/^\d+$/.test(t)?(C(t),new z(j,D)):null:W||=new z(0,0)}var z=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let W;function $(t){return t?/^-?\d+$/.test(t)?(C(t),new H(j,D)):null:q||=new H(0,0)}var H=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.N=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=nt("0dg"),at=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}})},ut=it?(t,e)=>{t[it]&=~e}:(t,e)=>{void 0!==t.i&&(t.i&=~e)};function ct(t,e,r){return r?t|e:t&~e}var lt=it?t=>0|t[it]:t=>0|t.i,ht=it?t=>t[it]:t=>t.i,ft=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 dt(t,e){ft(e,-14591&(0|t))}function pt(t,e){ft(e,-14557&(34|t))}function gt(t){return 0===(t=t>>14&1023)?536870912:t}var mt,_t={},vt={};function yt(t){return!(!t||"object"!=typeof t||t.i!==vt)}function bt(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&t.constructor===Object}function wt(t,e,r){if(!Array.isArray(t)||t.length)return!1;const n=lt(t);return!!(1&n)||!(!e||!(Array.isArray(e)?e.includes(r):e.has(r)))&&(ft(t,1|n),!0)}const St=[];function At(t){if(2&t)throw Error()}ft(St,55),mt=Object.freeze(St);function Tt(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}let Et;function It(){const e=Error();Tt(e,"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e)}function Pt(t){return Tt(t=Error(t),"warning"),t}function Ot(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 Lt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Ut(t){const e=typeof t;return"number"===e?Number.isFinite(t):"string"===e&&Lt.test(t)}function xt(t){if("number"!=typeof t)throw Pt("int32");if(!Number.isFinite(t))throw Pt("int32");return 0|t}function kt(t){return null==t?t:xt(t)}function Bt(t){if(null==t)return t;if("string"==typeof t){if(!t)return;t=+t}return"number"==typeof t&&Number.isFinite(t)?0|t:void 0}function Nt(t){if(null!=t){if("number"!=typeof t)throw Pt("uint32");if(!Number.isFinite(t))throw Pt("uint32");t>>>=0}return t}function jt(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 Dt(t){return"-"!==t[0]&&(20>t.length||20===t.length&&184467>Number(t.substring(0,6)))}function Ft(t){return null==t||"string"==typeof t?t:void 0}function Vt(t,e,r){if(null!=t&&"object"==typeof t&&t.K===_t)return t;if(Array.isArray(t)){var n=lt(t),i=n;return 0===i&&(i|=32&r),(i|=2&r)!==n&&ft(t,i),new e(t)}}let Mt,Ct,Gt;function Rt(t,e,r){if(null==t&&(t=Mt),Mt=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=lt(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(bt(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 ft(t,n),t}function zt(t,e,r,n,i){if(null!=t){if(Array.isArray(t))t=wt(t,void 0,0)?void 0:i&&2<(t)?t:Wt(t,e,r,void 0!==n,i);else if(bt(t)){const o={};for(let s in t)o[s]=zt(t[s],e,r,n,i);t=o}else t=e(t,n);return t}}function Wt(t,e,r,n,i){const o=n||r?lt(t):0;n=n?!!(32&o):void 0,t=rt(t);for(let o=0;o<t.length;o++)t[o]=zt(t[o],e,r,n,i);return r&&r(o,t),t}function $t(t){return t.K===_t?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(wt(t,void 0,0))return}else{if(E(t))return b(t);if(t instanceof x){const e=t.i;return null==e?"":"string"==typeof e?e:t.i=b(e)}}}return t}(t)}function Ht(t,e,r=pt){if(null!=t){if(v&&t instanceof Uint8Array)return e?t:new Uint8Array(t);if(Array.isArray(t)){var n=lt(t);return 2&n||(e&&=0===n||!!(32&n)&&!(64&n||!(16&n)),t=e?ft(t,-12293&(34|n)):Wt(t,Ht,4&n?pt:r,!0,!0)),t}return t.K===_t&&(r=t.m,t=2&(n=ht(r))?t:qt(t,r,n,!0)),t}}function qt(t,e,r,n){return t=t.constructor,Mt=e=function(t,e,r){const n=r||2&e?pt:dt,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=>Ht(t,i,n))),at(t,32|(r?2:0)),t}(e,r,n),e=new t(e),Mt=void 0,e}function Kt(t){const e=t.m,r=ht(e);return 2&r?qt(t,e,r,!1):t}function Yt(t,e,r,n){return!(4&e)||null!=r&&(!n&&0===r&&(4096&e||8192&e)&&5>(t.constructor[st]=1+(0|t.constructor[st]))&&It(),0!==r&&!(r&e))}function Jt(t){return Qt(t=t.m,ht(t),2)}function Xt(t,e,r,n){if(!(0>(e=n+(+!!(512&e)-1))||e>=t.length||e>=r))return t[e]}function Qt(t,e,r,n){if(-1===r)return null;const i=gt(e);if(!(r>=i)){var o=t.length;return n&&256&e&&null!=(n=t[o-1][r])?(Xt(t,e,i,r)&&null!=ot&&(4<=(e=(t=Et??={})[ot]||0)||(t[ot]=e+1,It())),n):Xt(t,e,i,r)}return 256&e?t[t.length-1][r]:void 0}function Zt(t,e,r){const n=t.m;let i=ht(n);return At(i),te(n,i,e,r),t}function te(t,e,r,n,i){const o=gt(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&&ft(t,s),s}return t[r+(+!!(512&e)-1)]=n,256&e&&(r in(t=t[t.length-1])&&delete t[r]),e}function ee(t,e,r){return t=Qt(t,e,r),Array.isArray(t)?t:mt}function re(t,e){return 0===t&&(t=ue(t,e)),ct(t,1,!0)}function ne(t){return!!(2&t)&&!!(4&t)||!!(2048&t)}function ie(t,e,r){{const a=t.m;let u=ht(a);if(At(u),null==r)te(a,u,e);else{var n,i=lt(r),o=i,s=!!(2&i)||Object.isFrozen(r);if((n=!s)&&(n=!1),Yt(t,i))for(i=21,s&&(r=rt(r),o=0,i=ce(i=ue(i,u),u,!0)),t=0;t<r.length;t++)r[t]=xt(r[t]);n&&(r=rt(r),o=0,i=ce(i=ue(i,u),u,!0)),i!==o&&ft(r,i),te(a,u,e,r)}}}function oe(t,e,r,n){t=t.m;let i=ht(t);At(i),te(t,i,e,("0"===n?0===Number(r):r===n)?void 0:r)}function se(t,e,r){var n=t.m,i=ht(n),o=Qt(n,i,r,!1);return(e=Vt(o,e,i))!==o&&null!=e&&te(n,i,r,e,!1),null==(n=e)||(t=t.m,2&(i=ht(t))||(o=Kt(n))!==n&&te(t,i,r,n=o,!1)),n}function ae(t,e,r){return null==r&&(r=void 0),Zt(t,e,r)}function ue(t,e){return t=ct(t,2,!!(2&e)),t=ct(t,32,!0),ct(t,2048,!1)}function ce(t,e,r){return 32&e&&r||(t=ct(t,32,!1)),t}function le(t,e,r,n){t=t.m;var i=ht(t);At(i);var o=!!(2&i);const s=o?1:2;f&&=!o,o=ee(t,i,e);var a=lt(o);const u=!!(4&a);if(!u){var c=o,l=i,h=!!(2&(a=re(a,i)));h&&(l=ct(l,2,!0));let t=!h,e=!0,n=0,s=0;for(;n<c.length;n++){const i=Vt(c[n],r,l);if(i instanceof r){if(!h){const r=!!(2<(i.m));t&&=!r,e&&=r}c[s++]=i}}s<n&&(c.length=s),a=ct(a,4,!0),a=ct(a,16,e),a=ct(a,8,t),ft(c,a),h&&Object.freeze(c)}if(f&&!(8&a||!o.length&&(1===s||4===s&&32&a))){ne(a)&&(o=rt(o),a=ue(a,i),i=te(t,i,e,o));var f=o;for(c=a,a=0;a<f.length;a++)(l=f[a])!==(h=Kt(l))&&(f[a]=h);c=ct(c,8,!0),c=ct(c,16,!f.length),ft(f,c),a=c}ne(a)||(f=a,(a=(c=1===s||4===s&&!!(32&a))?ct(a,!o.length||16&a&&(!u||32&a)?2:2048,!0):ce(a,i,!0))!==f&&ft(o,a),c&&Object.freeze(o)),2===s&&ne(a)&&(o=rt(o),a=ce(a=ue(a,i),i,!0),ft(o,a),te(t,i,e,o)),e=o,r=null!=n?n:new r,e.push(r),2<(r.m)?ut(e,8):ut(e,16)}function he(t,e,r){oe(t,e,kt(r),0)}function fe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();oe(t,e,r,"")}function de(t,e,r){t=t.m;const n=ht(t);At(n);var i=2&n;let o=Qt(t,n,e);Array.isArray(o)||(o=mt);const s=!!(32&n);let a=lt(o);if(0===a&&s&&!i?(a|=33,ft(o,a)):1&a||(a|=1,ft(o,a)),i?(2&a||at(o,34),Object.freeze(o)):(2&a||2048&a)&&(o=rt(o),i=1,s&&(i|=32),ft(o,i),te(t,n,e,o)),"string"!=typeof r)throw Error();o.push(r)}var pe=class{constructor(t,e){this.m=Rt(t,e)}toJSON(){return ge(this,Wt(this.m,$t,void 0,void 0,!1),!0)}v(){return!!(2<(this.m))}};function ge(t,e,r){var n=a?void 0:t.constructor.A;const i=ht(r?t.m:e);if(!(t=e.length))return e;let o,s;if(bt(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;(wt(r,n,+c)||yt(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||wt(r,n,l)||yt(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 me(t,e){if(Array.isArray(e)){var r=lt(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),ft(e,-12289&(5|r)),2&r&&Object.freeze(e),e}}pe.prototype.K=_t,pe.prototype.toString=function(){return ge(this,this.m,!1).toString()};const _e=Symbol(),ve=Symbol();function ye(t){let e=t[ve];if(!e){const r=Ae(t);e=(t,e)=>Ie(t,e,r),t[ve]=e}return e}const be=Symbol();function we(t){return t.i}function Se(t,e){let r,n;const i=t.i;return(t,o,s)=>i(t,o,s,n||=Ae(e).i,r||=ye(e))}function Ae(t){var e=t[be];if(e)return e;var r=we,n=Se;(e=t[be]={}).i=function(t){switch(typeof t){case"boolean":return Ct||=[0,void 0,!0];case"number":return 0<t?void 0:0===t?Gt||=[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.R=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=Ke,i--),f.N){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 Te in t&&_e in t&&be in t&&(t.length=0),e}const Te=Symbol();function Ee(t,e){var r=t[e];if(r)return r;if((r=t.R)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof et?r:[qe,r]:[r,void 0])[0].i;if(r=r[1]){const e=ye(r),i=Ae(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 Ie(t,e,r){var n=ht(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=Ee(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=Ee(r,n))&&o(e,i,n)}}function Pe(t){return new et(t,!1)}function Oe(t,e,r){null!=(e=Bt(e))&&null!=e&&(Y(t.i,8*r),J(t.i,e))}function Le(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 Ue(t,e,r){null!=(e=Ft(e))&&tt(t,r,i(e))}function xe(t,e,r,n,i){null!=(e=e instanceof pe?e.m:Array.isArray(e)?Rt(e,n[0],n[1]):void 0)&&(r=Q(t,r),i(e,t),Z(t,r))}function ke(t,e,r){null!=(e=Bt(e))&&(e=parseInt(e,10),Y(t.i,8*r),J(t.i,e))}var Be,Ne=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=N||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),D=0,e=j=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))})),je=Pe((function(t,e,r){t:if(null!=e){if(Ut(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(C(e),e=j,2147483648&(n=D))if(B())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)){F(e),n=j;var i=D;(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&&$(e),null!=e&&(Y(t.i,8*r),"number"==typeof e?(t=t.i,F(e),K(t,j,D)):(r=$(e),K(t.i,r.j,r.i))))})),De=Pe((function(t,e,r){t:if(null!=e){if(Ut(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)),Dt(e)||(C(e),e=V(j,D)));break t}if("number"==typeof e){e=0<=(e=Math.trunc(e))&&Number.isSafeInteger(e)?e:function(t){if(0>t){F(t);const e=V(j,D);return t=Number(e),Number.isSafeInteger(t)?t:e}return Dt(String(t))?t:(F(t),4294967296*D+(j>>>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,F(e),K(t,j,D)):(r=R(e),K(t.i,r.j,r.i))))})),Fe=Pe(Oe),Ve=new et((function(t,e,r){if(null!=(e=me(Bt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Me=Pe(Oe),Ce=Pe(Oe),Ge=Pe(Le),Re=Pe(Le),ze=new et((function(t,e,r){if(null!=(e=me(Ft,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),We=Pe(Ue),$e=Pe(Ue),He=Pe(Ue),qe=new et(xe,!0),Ke=new et(xe,!0);Be=new et((function(t,e,r,n,i){if(Array.isArray(e))for(let o=0;o<e.length;o++)xe(t,e[o],r,n,i)}),!0);var Ye=new et(xe,!0),Je=Pe(ke),Xe=new et((function(t,e,r){if(null!=(e=me(Bt,e))&&e.length){r=Q(t,r);for(let r=0;r<e.length;r++)J(t.i,e[r]);Z(t,r)}}),!1),Qe=Pe(ke);function Ze(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}}}};Ie(this.m,e,Ae(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 tr(t,e){if(null!=e)if(Array.isArray(e))Zt(t,2,Wt(e,$t,void 0,void 0,!1));else{if(!("string"==typeof e||e instanceof x||E(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new x(e,P):U();else if(e.constructor!==x){if(!E(e))throw Error();e=e.length?new x(new Uint8Array(e),P):U()}oe(t,2,e,U())}}var er=class extends pe{constructor(t){super(t)}},rr=[0,We,Pe((function(t,e,r){if(null!=e){if(e instanceof pe){const n=e.Y;return void(n&&(e=n(e),null!=e&&tt(t,r,k(e).buffer)))}if(Array.isArray(e))return}null!=(e=null==e||"string"==typeof e||E(e)||e instanceof x?e:void 0)&&tt(t,r,k(e).buffer)}))],nr={},ir=[-2,nr,Ge];nr[336783863]=[0,He,Ge,-1,Fe,[0,[1,2,3,4,5,6],Ye,[0],Ye,[0,Ge,He,Ge,Je,-1,Xe,He,-1,[0,Ge,-1],Je],Ye,[0,He,-2],Ye,[0,Fe,Ge,-5],Ye,[0,Fe,Je,Ge,-1,Ve,Je,-1],Ye,[0,He]],[0,He],Ge,[0,[1,3],[2,4],Ye,[0,Ve],-1,Ye,[0,ze],-1,Be,[0,He,-1]],He];var or=class extends pe{constructor(t){super(t)}},sr=[0,We,Re],ar=[0,je,-1,Re,-3,je,Ve,We,Me,je,-1,Re,Me,Re,-2,We],ur=[-1,{}],cr=[0,He,1,ur],lr=[0,He,ze,ur],hr=class extends pe{constructor(t){super(t,500)}J(t){return ae(this,7,t)}};hr.A=[3,4,5,6,8,13,17,1005];var fr=[-500,We,-1,ze,-3,ir,Be,rr,Me,-1,cr,lr,Be,sr,We,ar,Me,ze,987,ze],dr=[0,We,-1,ur],pr=[-500,He,-1,[-1,{}],998,He],gr=[-500,He,ze,-1,[-2,{},Ge],997,ze,-1],mr=[-500,He,ze,ur,998,ze];function _r(t,e){le(t,1,hr,e)}var vr=class extends pe{constructor(){super(void 0,500)}J(t){return ae(this,1001,t)}};vr.A=[1,6,7,9,10,15,16,17,14,1002],vr.prototype.i=Ze([-500,Be,fr,4,Be,pr,Be,gr,Me,Be,mr,ze,Me,cr,lr,Be,dr,ze,-2,ar,We,-1,Re,979,ur,Be,rr]);var yr=class extends pe{constructor(t){super(t)}};let br;const wr=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===br)try{await WebAssembly.instantiate(wr),br=!0}catch{br=!1}return br}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 Tr=class{};function Er(){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/))&&1<=t.length&&17<=Number(t[1])))}async function Ir(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())}Tr.forVisionTasks=function(t){return Ar("vision",t)},Tr.forTextTasks=function(t){return Ar("text",t)},Tr.forGenAiExperimentalTasks=function(t){return Ar("genai_experimental",t)},Tr.forGenAiTasks=function(t){return Ar("genai",t)},Tr.forAudioTasks=function(t){return Ar("audio",t)},Tr.isSimdSupported=function(){return Sr()};function Pr(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 Or(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 Lr(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function Ur(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 xr=(kr=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:Er()?this.h.canvas=new OffscreenCanvas(1,1):(console.warn("OffscreenCanvas not supported and GraphRunner constructor glCanvas parameter is undefined. Creating backup canvas."),this.h.canvas=document.createElement("canvas"))}async initializeGraph(t){const e=await(await fetch(t)).arrayBuffer();t=!(t.endsWith(".pbtxt")||t.endsWith(".textproto")),this.setGraph(new Uint8Array(e),t)}setGraphFromString(t){this.setGraph((new TextEncoder).encode(t),!1)}setGraph(t,e){const r=t.length,n=this.h._malloc(r);this.h.HEAPU8.set(t,n),e?this.h._changeBinaryGraph(r,n):this.h._changeTextGraph(r,n),this.h._free(n)}configureAudio(t,e,r,n,i){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),Pr(this,n||"input_audio",(n=>{Pr(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),Pr(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){Pr(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){Pr(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){Pr(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){Pr(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){Pr(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){Pr(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){Pr(this,e,(e=>{Pr(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){Pr(this,e,(e=>{Or(this,Object.keys(t),(n=>{Or(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){Pr(this,r,(r=>{Pr(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){Pr(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){Pr(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){Pr(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){Pr(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){Pr(this,e,(e=>{const n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)}))}addUintVectorToStream(t,e,r){Pr(this,e,(e=>{const n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputStream(n,e,r)}))}addStringVectorToStream(t,e,r){Pr(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)Pr(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){Pr(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){Pr(this,e,(e=>{Pr(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){Pr(this,r,(r=>{Pr(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){Pr(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){Pr(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){Pr(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){Pr(this,e,(e=>{const r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(const e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)}))}addUintVectorToInputSidePacket(t,e){Pr(this,e,(e=>{const r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(const e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)}))}addStringVectorToInputSidePacket(t,e){Pr(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)Pr(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){Ur(this,t,e),Pr(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){Lr(this,t,e),Pr(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){Ur(this,t,e),Pr(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?'),Lr(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),Pr(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 kr{V(){this.h._registerModelResourcesGraphService()}});var kr;async function Br(t,e){const r=await(async(t,e,r)=>{var n=mn;if(t&&await Ir(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await Ir(e),!self.ModuleFactory))throw Error("ModuleFactory not set.");return self.Module&&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.J(e),r}async function Nr(t,e){return Br(t,e)}function jr(t){try{const e=t.D.length;if(1===e)throw Error(t.D[0].message);if(1<e)throw Error("Encountered multiple errors: "+t.D.map((t=>t.message)).join(", "))}finally{t.D=[]}}function Dr(t,e){t.B=Math.max(t.B,e)}var Fr=class{constructor(t){this.i=t,this.D=[],this.B=0,this.i.setAutoRenderToScreen(!1)}setGraph(t,e){this.i.attachErrorListener(((t,e)=>{this.D.push(Error(e))})),this.i.V(),this.i.setGraph(t,e),jr(this)}finishProcessing(){this.i.finishProcessing(),jr(this)}close(){this.i.closeGraph()}};Fr.prototype.close=Fr.prototype.close;var Vr=class extends pe{constructor(t){super(t)}},Mr=[0,Qe,Me,Ne,-1,Fe];function Cr(t,e){ae(t,1,e)}var Gr=class extends pe{constructor(){super()}};function Rr(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}}Gr.A=[4];class zr{constructor(t){this.i=[],this.data=t,this.length=t.length}}var Wr=class{constructor(t,e,r){this.i=t,this.j=e,this.l=r}get size(){let t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function $r(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Hr=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))}},qr=class extends pe{constructor(){super()}};qr.A=[4],qr.prototype.i=Ze([0,We,2,ze,Me]);var Kr=class extends pe{constructor(){super()}},Yr=[0,Re,-5],Jr=[0,We,De,-1,Qe],Xr=class extends pe{constructor(){super()}},Qr=[0,Me,-6,1,Me,1,[0,Re,Qe,-2],[0,Re,Ne],Qe,-2,[0,Re,-1,Qe,Ne,Je],1,Re],Zr=class extends pe{constructor(){super()}};Zr.A=[5,7];var tn=[0,[4,6],Qr,Me,1,Ce,ze,$e,Xe],en=[0,Be,Jr,tn,Me],rn=[0,Me,Re,-1],nn=class extends pe{constructor(){super()}};nn.A=[29],nn.prototype.i=Ze([0,We,8,Yr,1,Me,1,Me,en,rn,1,Qe,We,tn,en,Me,5,Qe,Ve,1,Mr]);var on=class extends pe{constructor(){super()}},sn=class extends pe{constructor(){super()}},an=[2,4];sn.prototype.i=Ze([0,an,Me,$e,Me,Ye,[0,1,We]]);const un=function(t){return class e extends t{static async W(t,r){let n;r||=await e.M();const i=[];for(const e of t?.requiredFeatures??[])r.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{n=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return r=await r.requestAdapterInfo(),n.adapterInfo=r,n}static async M(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}T(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}P(){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 zr(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=Rr(u,r,c,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+s),r=0,s+=c,0==(n-=c))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}(t,this.h,e,r,n)),e)}}}(function(t){return class extends t{O(t,e){Pr(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends xr{})));class cn extends un{}var ln=class{constructor(t){this.j=t,this.i=hn,hn++}},hn=0;class fn{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.i=t,this.j=e}}async function dn(){const t=await cn.M({powerPreference:"high-performance"});var e=t.limits.maxBufferSize;if(524550144>t.limits.maxStorageBufferBindingSize)throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxStorageBufferBindingSize is at least 524550144 but your device only supports maxStorageBufferBindingSize of ${e}`);if(786825216<=e)e=786825216;else{if(!(524550144<=e))throw Error(`The WebGPU device is unable to execute LLM tasks, because the required maxBufferSize is at least 524550144 but your device only supports maxBufferSize of ${e}`);e=524550144}return cn.W({requiredFeatures:["shader-f16"],requiredLimits:{maxStorageBufferBindingSize:524550144,maxBufferSize:e}},t)}function pn(t){const e=function(t){const e=new vr;de(e,10,"text_in"),de(e,10,"token_cost_in"),de(e,10,"lora_model_id_to_apply_in"),de(e,10,"lora_model_ref_in"),de(e,10,"lora_model_id_to_load_in"),de(e,16,"streaming_reader"),de(e,15,"text_out"),de(e,15,"text_end"),de(e,15,"token_cost_out");var r=new hr;fe(r,2,"TokenizerInputBuildCalculator"),de(r,3,"PROMPT:text_in"),de(r,3,"LORA_ID:lora_model_id_to_apply_in"),de(r,4,"prompt"),_r(e,r),fe(r=new hr,2,"ModelDataCalculator"),de(r,6,"MODEL_DATA:__side_packet_1"),de(r,6,"MODEL_TYPE:model_type"),de(r,5,"READ_DATA_FN:streaming_reader"),de(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),de(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),de(r,4,"LORA_DATA:lora_model_data"),_r(e,r),fe(r=new hr,2,"Gpt2UnicodeMappingCalculator"),de(r,5,"MODEL_TYPE:model_type"),de(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_r(e,r),fe(r=new er,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new sn,i=jt(Jt(t.l))??0;he(n,1,i),fe(i=new on,2,"spm_vocab_model"),null==i&&(i=void 0);var o=n.m,s=ht(o);At(s);for(var a=s,u=0,c=0;c<an.length;c++){var l=an[c];null!=Qt(o,a,l)&&(0!==u&&(a=te(o,a,u)),u=l)}if((a=u)&&4!==a&&null!=i&&(s=te(o,s,a)),te(o,s,4,i),he(n,3,2),tr(r,n.i()),fe(n=new hr,2,"TokenizerCalculator"),le(n,8,er,r),de(n,5,"MODEL_DATA:__side_packet_1"),de(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),de(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(n,6,"PROCESSOR_GETTER:__input_side_1"),de(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),_r(e,n),fe(r=new er,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),he(n=new nn,12,3),fe(n,1,"llm.tflite"),he(n,14,0),he(n,22,1),i=se(t.l,Vr,3),ae(n,31,i),oe(i=new Kr,1,!0,!1),oe(i,2,!0,!1),oe(i,5,!0,!1),ae(n,10,i),c=t.l,i=c.m,o=ht(i),s=2&o?1:2,a=ee(i,o,4),u=lt(a),Yt(c,u,void 0,!1)){for((4&u||Object.isFrozen(a))&&(a=rt(a),u=ue(u,o),o=te(i,o,4,a)),l=c=0;c<a.length;c++){const t=Bt(a[c]);null!=t&&(a[l++]=t)}l<c&&(a.length=l),u=ct(u=re(u,o),20,!0),u=ct(u,4096,!1),u=ct(u,8192,!1),ft(a,u),2&u&&Object.freeze(a)}return ne(u)||(c=u,(u=(l=1===s||4===s&&!!(32&u))?ct(u,2,!0):ce(u,o,!1))!==c&&ft(a,u),l&&Object.freeze(a)),2===s&&ne(u)&&(a=rt(a),u=ce(u=ue(u,o),o,!1),ft(a,u),te(i,o,4,a)),ie(n,29,a),i=new Zr,he(o=new Xr,1,1),t=jt(Jt(t.l))??0,he(o,2,t),ae(i,1,o),ae(n,20,i),tr(r,n.i()),fe(t=new hr,2,"LlmGpuCalculator"),le(t,8,er,r),de(t,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),de(t,3,"FINISH:finish"),de(t,3,"LORA_DATA:lora_model_data"),de(t,5,"MODEL_DATA:__side_packet_1"),de(t,4,"DECODED_IDS:__stream_3"),de(t,4,"OUTPUT_END:__stream_4"),fe(r=new or,1,"FINISH"),oe(r,2,!0,!1),le(t,13,or,r),_r(e,t),fe(t=new hr,2,"IsPacketPresentCalculator"),de(t,3,"__stream_4"),de(t,4,"text_end"),_r(e,t),fe(t=new er,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),he(r=new qr,5,1),de(r,4,"<eos>"),de(r,4,"<|endoftext|>"),tr(t,r.i()),fe(r=new hr,2,"DetokenizerCalculator"),le(r,8,er,t),de(r,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),de(r,5,"PROCESSOR_GETTER:__input_side_1"),de(r,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(r,5,"MODEL_DATA:__side_packet_1"),de(r,4,"FINISH_AND_INPUT_OPTIONS:finish"),de(r,4,"WORDS:text_out"),_r(e,r),fe(t=new hr,2,"TokenCostCalculator"),de(t,3,"PROMPT:token_cost_in"),de(t,5,"PROCESSOR_GETTER:__input_side_1"),de(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),de(t,4,"NUM_TOKENS:token_cost_out"),_r(e,t),e}(t);t.i.attachStringVectorListener("text_out",((e,r)=>{var n=0===t.G.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.G.push(n),t.I&&0===t.C.length&&t.I(n,!1),Dr(t,r)})),t.i.attachEmptyPacketListener("text_out",(e=>{Dr(t,e)})),t.i.attachBoolListener("text_end",((e,r)=>{t.j=!1,Dr(t,r),gn(t),t.o&&(t.o.i(t.G.join("")),t.o=void 0),t.I&&t.I("",!0)})),t.i.attachEmptyPacketListener("text_end",(e=>{t.j=!1,Dr(t,e),gn(t),t.o&&(t.o.i(t.G.join("")),t.o=void 0)})),t.i.attachIntListener("token_cost_out",((e,r)=>{t.L=e,Dr(t,r)})),t.H&&t.i.addStreamingReaderToInputSidePacket(t.H,"streaming_reader");const r=e.i();return t.u?.removeEventListener("uncapturederror",t.F),t.i.P().then((()=>{t.u?.addEventListener("uncapturederror",t.F),t.C.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function gn(t){if(0<t.C.length){const e=[...t.C];if(t.C.length=0,!t.o)throw e;t.o.j(e),t.o=void 0}}var mn=class extends Fr{constructor(t,e){if(super(new cn(t,e)),this.G=[],this.j=!1,this.C=[],this.F=t=>{const e=(t=t.error).message.match(/exceeds the max buffer size limit \(([0-9]+)\)\./);e&&524550144<Number(e[1])?t=Error(`Failed to run this LLM model, but you could try a smaller LLM model. WebGPU throws: "${t.message}"`):t.message.match(/is larger than the maximum binding size/)&&(t=Error(`Failed to run LLM inference, the supported max binding size is smaller than the required size. WebGPU throws: "${t.message}"`)),this.C.push(t)},this.l=new Gr,Cr(this.l,new yr),this.s=new Vr,ae(this.l,3,this.s),Zt(this.l,2,Nt(512)),t=this.s,!Number.isFinite(2))throw Pt("enum");oe(t,1,2,0),he(this.s,2,1),oe(this.s,3,Ot(1),0),oe(this.s,4,Ot(1),0)}J(t){if(this.j)throw Error("Cannot set options while loading or processing.");let e;this.j=!0,t.baseOptions?.gpuOptions?.device&&(this.u&&this.u.removeEventListener("uncapturederror",this.F),this.u=t.baseOptions.gpuOptions.device,this.i.T(this.u),this.u.addEventListener("uncapturederror",this.F)),"maxTokens"in t&&Zt(this.l,2,Nt(t.maxTokens??512)),"topK"in t&&(he(this.s,2,t.topK??1),t.topK&&!t.randomSeed&&console.warn("'topK' option ignored; it requires randomSeed to be set.")),"temperature"in t&&(oe(this.s,4,Ot(t.temperature??1),0),t.temperature&&!t.randomSeed&&console.warn("'temperature' option ignored; it requires randomSeed to be set.")),t.randomSeed&&Zt(this.s,5,kt(t.randomSeed)),"loraRanks"in t&&function(t,e){ie(t,4,e)}(this.l,t.loraRanks??[]);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");let r=!1;t.baseOptions.modelAssetPath?this.H=function(t,e){const r=fetch(t.toString()).then((t=>t?.body?.getReader()));return new Wr([],(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 instanceof Uint8Array?(this.H=function(t,e){return new Wr([new zr(t)],(()=>Promise.resolve(void 0)),e)}(t.baseOptions.modelAssetBuffer,e),r=!0):t.baseOptions.modelAssetBuffer?(this.H=function(t,e){return new Wr([],(async()=>{const{value:e,done:r}=await t.read();if(!r)return e}),e)}(t.baseOptions.modelAssetBuffer,e),r=!0):e(),r&&(t.baseOptions.modelAssetBuffer=void 0)}return t=pn(this).then((()=>{})),Promise.all([r,t]).then((()=>{this.j=!1,gn(this)}))}get baseOptions(){return se(this.l,yr,1)}set baseOptions(t){Cr(this.l,t)}S(t,e,r){if(this.j)throw Error("Previous invocation or loading is still ongoing.");if(this.I="function"==typeof e?e:r,this.G.length=0,this.j=!0,r=this.B+1,this.i.addStringToStream(t,"text_in",r),e instanceof ln){if(e.j!==this)throw this.j=!1,Error("The LoRA model was not loaded by this LLM Inference task.");this.i.addUintToStream(e.i,"lora_model_id_to_apply_in",r)}else this.i.addEmptyPacketToStream("lora_model_id_to_apply_in",r);return this.finishProcessing(),this.o=new fn,this.o.promise}X(t){if(this.j)throw Error("Previous invocation or loading is still ongoing.");return this.j=!0,this.L=void 0,this.i.addStringToStream(t,"token_cost_in",this.B+1),this.finishProcessing(),this.j=!1,this.L}async U(t){if(this.j)throw Error("Cannot load LoRA model while loading or processing.");if(this.j=!0,t instanceof Uint8Array){var e=new Hr(this.i.h,t.length);e.set(t),t=e}else t=await async function(t,e){var r=await fetch(e.toString());e=Number(r.headers.get("content-length")),t=new Hr(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 $r(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${e} bytes before failure`);return t}(this.i.h,t);return e=new ln(this),this.i.O(t,this.B+1),this.i.addUintToStream(e.i,"lora_model_id_to_load_in",this.B+1),this.finishProcessing(),$r(t),this.j=!1,e}close(){this.u?.removeEventListener("uncapturederror",this.F),super.close()}};mn.prototype.loadLoraModel=mn.prototype.U,mn.prototype.sizeInTokens=mn.prototype.X,mn.prototype.generateResponse=mn.prototype.S,mn.prototype.setOptions=mn.prototype.J,mn.createWebGpuDevice=dn,mn.createFromModelPath=async function(t,e){return Nr(t,e={baseOptions:{gpuOptions:{device:await dn()},modelAssetPath:e}})},mn.createFromModelBuffer=async function(t,e){return Nr(t,e={baseOptions:{gpuOptions:{device:await dn()},modelAssetBuffer:e}})},mn.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await dn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Nr(t,e)},exports.FilesetResolver=Tr,exports.LlmInference=mn,exports.TaskRunner=Fr;
|
|
2
2
|
//# sourceMappingURL=genai_bundle_cjs.js.map
|