@mediapipe/tasks-genai 0.10.21 → 0.10.22-rc.20250304

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