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