@mediapipe/tasks-genai 0.10.26 → 0.10.36-rc.20260507

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,13 +7,21 @@ This package contains the GenAI tasks for MediaPipe.
7
7
  The MediaPipe LLM Inference task generates text responses from input text. For
8
8
  Gemma 3n models, it can process input images and audio as well.
9
9
 
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
10
+ In order to begin, you must have a model available. You can download one of
11
+ these:
12
+
13
+ - [Gemma 4 E2B](https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/blob/main/gemma-4-E2B-it-web.task)
14
+ - [Gemma 4 E4B](https://huggingface.co/litert-community/gemma-4-E4B-it-litert-lm/blob/main/gemma-4-E4B-it-web.task)
15
+ - [Gemma 3n
16
+ E2B](https://huggingface.co/google/gemma-3n-E2B-it-litert-lm/blob/main/gemma-3n-E2B-it-int4-Web.litertlm)
17
+ - [Gemma 3n E4B](https://huggingface.co/google/gemma-3n-E4B-it-litert-lm/blob/main/gemma-3n-E4B-it-int4-Web.litertlm)
18
+
19
+ Alternatively, you can browse for more pre-converted models on our [LiteRT HuggingFace community](https://huggingface.co/litert-community/models), where files named "-web.task" are
13
20
  specially converted to run optimally in the browser. All text-only variants of
14
21
  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
22
  our web inference [guide](https://developers.google.com/mediapipe/solutions/genai/llm_inference/web_js) for more information.
16
23
  Note that only models encoded for the GPU backend are currently supported.
24
+
17
25
  ```
18
26
  const genai = await FilesetResolver.forGenAiTasks(
19
27
  "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai/wasm"
package/genai.d.ts CHANGED
@@ -33,7 +33,7 @@ declare type AudioSource = string | AudioBuffer | AudioChunk;
33
33
  * limitations under the License.
34
34
  */
35
35
  /** Options to configure MediaPipe model loading and processing. */
36
- declare interface BaseOptions_2 {
36
+ declare interface BaseOptions {
37
37
  /**
38
38
  * The model path to the model asset file. Only one of `modelAssetPath` or
39
39
  * `modelAssetBuffer` can be set.
@@ -63,12 +63,13 @@ export declare class FilesetResolver {
63
63
  *
64
64
  * If your environment requires custom locations for the MediaPipe Wasm files,
65
65
  * you can use `isSimdSupported()` to decide whether to load the SIMD-based
66
- * assets.
66
+ * assets. Note that for ES6 Modules, SIMD is assumed to be always supported.
67
67
  *
68
+ * @param useModule Whether to use ES6 Modules for the Wasm files.
68
69
  * @export
69
70
  * @return Whether SIMD support was detected in the current environment.
70
71
  */
71
- static isSimdSupported(): Promise<boolean>;
72
+ static isSimdSupported(useModule?: boolean): Promise<boolean>;
72
73
  /**
73
74
  * Creates a fileset for the MediaPipe Audio tasks.
74
75
  *
@@ -76,10 +77,11 @@ export declare class FilesetResolver {
76
77
  * @param basePath An optional base path to specify the directory the Wasm
77
78
  * files should be loaded from. If not specified, the Wasm files are
78
79
  * loaded from the host's root directory.
80
+ * @param useModule Whether to use ES6 Modules for the Wasm files.
79
81
  * @return A `WasmFileset` that can be used to initialize MediaPipe Audio
80
82
  * tasks.
81
83
  */
82
- static forAudioTasks(basePath?: string): Promise<WasmFileset>;
84
+ static forAudioTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>;
83
85
  /**
84
86
  * Creates a fileset for the MediaPipe GenAI tasks.
85
87
  *
@@ -87,21 +89,11 @@ export declare class FilesetResolver {
87
89
  * @param basePath An optional base path to specify the directory the Wasm
88
90
  * files should be loaded from. If not specified, the Wasm files are
89
91
  * loaded from the host's root directory.
92
+ * @param useModule Whether to use ES6 Modules for the Wasm files.
90
93
  * @return A `WasmFileset` that can be used to initialize MediaPipe GenAI
91
94
  * tasks.
92
95
  */
93
- static forGenAiTasks(basePath?: string): Promise<WasmFileset>;
94
- /**
95
- * Creates a fileset for the MediaPipe GenAI Experimental tasks.
96
- *
97
- * @export
98
- * @param basePath An optional base path to specify the directory the Wasm
99
- * files should be loaded from. If not specified, the Wasm files are
100
- * loaded from the host's root directory.
101
- * @return A `WasmFileset` that can be used to initialize MediaPipe GenAI
102
- * tasks.
103
- */
104
- static forGenAiExperimentalTasks(basePath?: string): Promise<WasmFileset>;
96
+ static forGenAiTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>;
105
97
  /**
106
98
  * Creates a fileset for the MediaPipe Text tasks.
107
99
  *
@@ -109,10 +101,11 @@ export declare class FilesetResolver {
109
101
  * @param basePath An optional base path to specify the directory the Wasm
110
102
  * files should be loaded from. If not specified, the Wasm files are
111
103
  * loaded from the host's root directory.
104
+ * @param useModule Whether to use ES6 Modules for the Wasm files.
112
105
  * @return A `WasmFileset` that can be used to initialize MediaPipe Text
113
106
  * tasks.
114
107
  */
115
- static forTextTasks(basePath?: string): Promise<WasmFileset>;
108
+ static forTextTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>;
116
109
  /**
117
110
  * Creates a fileset for the MediaPipe Vision tasks.
118
111
  *
@@ -120,10 +113,11 @@ export declare class FilesetResolver {
120
113
  * @param basePath An optional base path to specify the directory the Wasm
121
114
  * files should be loaded from. If not specified, the Wasm files are
122
115
  * loaded from the host's root directory.
116
+ * @param useModule Whether to use ES6 Modules for the Wasm files.
123
117
  * @return A `WasmFileset` that can be used to initialize MediaPipe Vision
124
118
  * tasks.
125
119
  */
126
- static forVisionTasks(basePath?: string): Promise<WasmFileset>;
120
+ static forVisionTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>;
127
121
  }
128
122
 
129
123
  /**
@@ -139,7 +133,7 @@ declare type ImageSource = Exclude<CanvasImageSource, SVGElement> | string;
139
133
  /**
140
134
  * Options to configure the model loading and processing for LLM Inference task.
141
135
  */
142
- export declare interface LlmBaseOptions extends BaseOptions_2 {
136
+ export declare interface LlmBaseOptions extends BaseOptions {
143
137
  gpuOptions?: WebGpuOptions;
144
138
  }
145
139
 
@@ -336,8 +330,8 @@ declare class LlmInferenceGraphOptions extends jspb.Message {
336
330
  setMaxTokens(value: number): void;
337
331
  hasSamplerParams(): boolean;
338
332
  clearSamplerParams(): void;
339
- getSamplerParams(): mediapipe_tasks_cc_genai_inference_proto_sampler_params_pb.SamplerParameters | undefined;
340
- setSamplerParams(value?: mediapipe_tasks_cc_genai_inference_proto_sampler_params_pb.SamplerParameters): void;
333
+ getSamplerParams(): mediapipe_tasks_web_genai_llm_inference_proto_sampler_params_pb.SamplerParameters | undefined;
334
+ setSamplerParams(value?: mediapipe_tasks_web_genai_llm_inference_proto_sampler_params_pb.SamplerParameters): void;
341
335
  clearLoraRanksList(): void;
342
336
  getLoraRanksList(): Array<number>;
343
337
  setLoraRanksList(value: Array<number>): void;
@@ -376,7 +370,7 @@ declare namespace LlmInferenceGraphOptions {
376
370
  type AsObject = {
377
371
  baseOptions?: mediapipe_tasks_cc_core_proto_base_options_pb.BaseOptions.AsObject;
378
372
  maxTokens: number;
379
- samplerParams?: mediapipe_tasks_cc_genai_inference_proto_sampler_params_pb.SamplerParameters.AsObject;
373
+ samplerParams?: mediapipe_tasks_web_genai_llm_inference_proto_sampler_params_pb.SamplerParameters.AsObject;
380
374
  loraRanksList: Array<number>;
381
375
  numResponses: number;
382
376
  forceF32: boolean;
@@ -449,11 +443,11 @@ export declare class LoraModel {
449
443
  }
450
444
 
451
445
  declare namespace mediapipe_tasks_cc_core_proto_base_options_pb {
452
- { BaseOptions };
446
+ export { BaseOptions_2 as BaseOptions };
453
447
  }
454
448
 
455
- declare namespace mediapipe_tasks_cc_genai_inference_proto_sampler_params_pb {
456
- { SamplerParameters };
449
+ declare namespace mediapipe_tasks_web_genai_llm_inference_proto_sampler_params_pb {
450
+ export { SamplerParameters };
457
451
  }
458
452
 
459
453
  /**
@@ -493,7 +487,7 @@ declare abstract class TaskRunner {
493
487
  /** Options to configure MediaPipe Tasks in general. */
494
488
  declare interface TaskRunnerOptions {
495
489
  /** Options to configure the loading of the model assets. */
496
- baseOptions?: BaseOptions_2;
490
+ baseOptions?: BaseOptions;
497
491
  }
498
492
 
499
493
  /**
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,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,!0),u=e(824656860,e(1,!0));function c(){var e=t.navigator;return e&&(e=e.userAgent)?e:""}const l=t.navigator;o=l&&l.userAgentData||null;const h={};let f=null;function d(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=f[e];if(null!=r)return r;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}p();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 p(){if(!f){f={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){const n=t.concat(e[r].split(""));h[r]=n;for(let t=0;t<n.length;t++){const e=n[t];void 0===f[e]&&(f[e]=t)}}}}var m="undefined"!=typeof Uint8Array,g=!(!(s&&o&&o.brands.length>0)&&(-1!=c().indexOf("Trident")||-1!=c().indexOf("MSIE")))&&"function"==typeof btoa;const _=/[-_.]/g,y={"-":"+",_:"/",".":"="};function w(t){return y[t]||""}function b(t){if(!g)return d(t);t=_.test(t)?t.replace(_,w):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 v(t){return m&&null!=t&&t instanceof Uint8Array}var S={};function E(){return I||=new A(null,S)}var A=class{constructor(t,e){if(L(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};let I,T;function L(t){if(t!==S)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 O(t){return P(t=Error(t),"warning"),t}function j(e,r){if(null!=e){var n=T??={},i=n[e]||0;i>=r||(n[e]=i+1,P(e=Error(),"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e))}}function x(){return"function"==typeof BigInt}var k="function"==typeof Symbol&&"symbol"==typeof Symbol();function U(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 B=U("jas",void 0,!0),N=U(void 0,"1oa"),F=U(void 0,"0ubsb"),R=U(void 0,"0actk"),D=U("m_m","pa",!0);const M={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},C=Object.defineProperties,V=k?B:"ha";var G;const z=[];function W(t,e){k||V in t||C(t,M),t[V]|=e}function H(t,e){k||V in t||C(t,M),t[V]=e}H(z,7),G=Object.freeze(z);var $={};function q(t,e){return void 0===e?t.i!==K&&!!(2&(0|t.m[V])):!!(2&e)&&t.i!==K}const K={};var Y=Object.freeze({});function J(t){return t.oa=!0,t}var X=J((t=>"number"==typeof t)),Q=J((t=>"string"==typeof t)),Z=J((t=>"boolean"==typeof t)),tt="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),et=J((t=>tt?t>=nt&&t<=ot:"-"===t[0]?st(t,rt):st(t,it)));const rt=Number.MIN_SAFE_INTEGER.toString(),nt=tt?BigInt(Number.MIN_SAFE_INTEGER):void 0,it=Number.MAX_SAFE_INTEGER.toString(),ot=tt?BigInt(Number.MAX_SAFE_INTEGER):void 0;function st(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 at,ut=0,ct=0;function lt(t){const e=t>>>0;ut=e,ct=(t-e)/4294967296>>>0}function ht(t){if(t<0){lt(-t);const[e,r]=gt(ut,ct);ut=e>>>0,ct=r>>>0}else lt(t)}function ft(t,e){const r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:dt(t,e)}function dt(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else x()?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+pt(r)+pt(t));return r}function pt(t){return t=String(t),"0000000".slice(t.length)+t}function mt(t){if(t.length<16)ht(Number(t));else if(x())t=BigInt(t),ut=Number(t&BigInt(4294967295))>>>0,ct=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);ct=ut=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));ct*=1e6,ut=1e6*ut+e,ut>=4294967296&&(ct+=Math.trunc(ut/4294967296),ct>>>=0,ut>>>=0)}if(e){const[t,e]=gt(ut,ct);ut=t,ct=e}}}function gt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function _t(t){return Array.prototype.slice.call(t)}const yt="function"==typeof BigInt?BigInt.asIntN:void 0,wt="function"==typeof BigInt?BigInt.asUintN:void 0,bt=Number.isSafeInteger,vt=Number.isFinite,St=Math.trunc;function Et(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 At(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}function It(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 Tt(t){return null==t||"boolean"==typeof t?t:"number"==typeof t?!!t:void 0}const Lt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Pt(t){switch(typeof t){case"bigint":return!0;case"number":return vt(t);case"string":return Lt.test(t);default:return!1}}function Ot(t){if("number"!=typeof t)throw O("int32");if(!vt(t))throw O("int32");return 0|t}function jt(t){return null==t?t:Ot(t)}function xt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?0|t:void 0}function kt(t){if(null==t)return t;if("string"==typeof t&&t)t=+t;else if("number"!=typeof t)return;return vt(t)?t>>>0:void 0}function Ut(t){return null==t||"string"==typeof t?t:void 0}function Bt(t,e,r){if(null!=t&&t[D]===$)return t;if(Array.isArray(t)){var n=0|t[V];return(r=n|32&r|2&r)!==n&&H(t,r),new e(t)}}function Nt(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 Ft(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return et(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[V];return 0===t.length&&1&e?void 0:Nt(t,e,Ft)}if(null!=t&&t[D]===$)return Rt(t);if(t instanceof A){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(g){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),p(),r=h[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 Nt(t=t.m,0|t[V],Ft)}let Dt,Mt;function Ct(t,e,r,n=0){if(null==t){var i=32;r?(t=[r],i|=128):t=[],e&&(i=-16760833&i|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(i=0|t[V],a&&1&i)throw Error("rfarr");if(2048&i&&!(2&i)&&function(){if(a)throw Error("carr");j(R,5)}(),256&i)throw Error("farr");if(64&i)return(i|n)!==i&&H(t,i|n),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=-16760833&i|(1023&s)<<14;break t}}if(e){if((u=Math.max(e,o-(128&i?0:-1)))>1024)throw Error("spvt");i=-16760833&i|(1023&u)<<14}}}return H(t,64|i|n),t}function Vt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var r=0|t[V];return 0===t.length&&1&r?t=void 0:2&r||(!e||4096&r||16&r?t=zt(t,r,!1,e&&!(16&r)):(W(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[D]===$?q(t,r=0|(e=t.m)[V])?t:qt(t,e,r)?Gt(t,e):zt(e,r):t instanceof A?t:void 0}function Gt(t,e,r){return t=new t.constructor(e),r&&(t.i=K),t.o=K,t}function zt(t,e,r,n){return n??=!!(34&e),t=Nt(t,e,Vt,n),n=32,r&&(n|=2),H(t,e=16769217&e|n),t}function Wt(t){if(t.i!==K)return!1;var e=t.m;return W(e=zt(e,0|e[V]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function Ht(t){if(!Wt(t)&&q(t,0|t.m[V]))throw Error()}function $t(t,e){void 0===e&&(e=0|t[V]),32&e&&!(4096&e)&&H(t,4096|e)}function qt(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(H(e,2|r),t.i=K,!0)}function Kt(t,e,r){if(null!==(t=Yt(t.m,e,void 0,r)))return t}function Yt(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 Jt(t,e,r){Ht(t),Xt(t=t.m,0|t[V],e,r)}function Xt(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[V])>>14&1023||536870912)?null!=n&&(t[s+(i?0:-1)]={[r]:n}):t[o]=n),e)}function Qt(t,e,r,n,i){let o=t.m,s=0|o[V];n=q(t,s)?1:n,i=!!i||3===n,2===n&&Wt(t)&&(o=t.m,s=0|o[V]);let a=(t=te(o,e))===G?7:0|t[V],u=ee(a,s);var c=!(4&u);if(c){4&u&&(t=_t(t),a=0,u=le(u,s),s=Xt(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&&(H(t,u),2&u&&Object.freeze(t)),Zt(t,u,o,s,e,n,c,i)}function Zt(t,e,r,n,i,o,s,a){let u=e;return 1===o||4===o&&(2&e||!(16&e)&&32&n)?re(e)||((e|=!t.length||s&&!(4096&e)||32&n&&!(4096&e||16&e)?2:256)!==u&&H(t,e),Object.freeze(t)):(2===o&&re(e)&&(t=_t(t),u=0,e=le(e,n),n=Xt(r,n,i,t)),re(e)||(a||(e|=16),e!==u&&H(t,e))),2&e||!(4096&e||16&e)||$t(r,n),t}function te(t,e,r){return t=Yt(t,e,r),Array.isArray(t)?t:G}function ee(t,e){return 2&e&&(t|=2),1|t}function re(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function ne(t,e,r){Ht(t);let n=0|(t=t.m)[V];if(null==r)Xt(t,n,e);else{var i=r===G?7:0|r[V],o=i,s=re(i),a=s||Object.isFrozen(r);for(s||(i=0),a||(r=_t(r),o=0,i=le(i,n),a=!1),i|=5,i|=(4&i?512&i?512:1024&i?1024:0:void 0)??(u?1024:0),s=0;s<r.length;s++){const t=r[s],e=Ot(t);Object.is(t,e)||(a&&(r=_t(r),o=0,i=le(i,n),a=!1),r[s]=e)}i!==o&&(a&&(r=_t(r),i=le(i,n)),H(r,i)),Xt(t,n,e,r)}}function ie(t,e,r,n){Ht(t),Xt(t=t.m,0|t[V],e,("0"===n?0===Number(r):r===n)?void 0:r)}function oe(t){if(k)return t[N]??(t[N]=new Map);if(N in t)return t[N];const e=new Map;return Object.defineProperty(t,N,{value:e}),e}function se(t,e,r){var n=Hn;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!=Yt(e,o)&&(0!==i&&(r=Xt(e,r,i)),i=o)}return t.set(n,i),i}function ae(t,e,r){let n=t.m,i=0|n[V];if(e=function(t,e,r,n){let i=!1;if(null!=(n=Yt(t,n,void 0,(t=>{const n=Bt(t,r,e);return i=n!==t&&null!=n,n}))))return i&&!q(n)&&$t(t,e),n}(n,i,e,r),null==e)return e;if(i=0|n[V],!q(t,i)){var o,s=e;const a=s.m,u=0|a[V];(o=q(s,u)?qt(s,a,u)?Gt(s,a,!0):new s.constructor(zt(a,u,!1)):s)!==e&&(Wt(t)&&(n=t.m,i=0|n[V]),i=Xt(n,i,r,e=o),$t(n,i))}return e}function ue(t){return null==t&&(t=void 0),t}function ce(t,e,r){return Jt(t,e,r=ue(r)),r&&!q(r)&&$t(t.m),t}function le(t,e){return-273&(2&e?2|t:-3&t)}function he(t,e,r,n){var i=n;Ht(t);var o=n=t.m,s=0|n[V];const a=q(t,s)?1:2;2===a&&Wt(t)&&(s=0|(o=t.m)[V]);let u=(t=te(o,e))===G?7:0|t[V];var c=ee(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=Bt(h[o],r,f);if(t instanceof r){if(!e){const e=q(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&&(H(t,c),2&c&&Object.freeze(t)),e=t=Zt(t,c,o,s,e,a,l,!0),i=null!=i?i:new r,e.push(i),o=r=e===G?7:0|e[V],(i=q(i))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&H(e,r),i||$t(n)}function fe(t,e){return kt(Kt(t,e))??0}function de(t,e,r){ie(t,e,jt(r),0)}function pe(t,e,r){if(null!=r){if("number"!=typeof r)throw O("uint32");if(!vt(r))throw O("uint32");r>>>=0}Jt(t,e,r)}function me(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();ie(t,e,r,"")}function ge(t,e,r){if(Ht(t),e=(t=Qt(t,e,Ut,2,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}var _e=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function ye(t){if("string"==typeof t)return new _e(b(t),!0);if(Array.isArray(t))return new _e(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new _e(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new _e(t,!1);if(t.constructor===A){L(S);var e=t.i;return e=(null==(e=null==e||v(e)?e:"string"==typeof e?b(e):null)?e:t.i=e)||new Uint8Array(0),new _e(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new _e(t,!1);throw Error()}function we(t){return t?/^\d+$/.test(t)?(mt(t),new be(ut,ct)):null:ve||=new be(0,0)}var be=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ve;function Se(t){return t?/^-?\d+$/.test(t)?(mt(t),new Ee(ut,ct)):null:Ae||=new Ee(0,0)}var Ee=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Ae;function Ie(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 Te(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Le(t,e){if(e>=0)Te(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function Pe(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Oe(t,e,r){Te(t.i,8*e+r)}function je(t,e){return Oe(t,e,2),e=t.i.end(),Pe(t,e),e.push(t.j),e}function xe(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 ke(t,e,r){Oe(t,e,2),Te(t.i,r.length),Pe(t,t.i.end()),Pe(t,r)}function Ue(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Be=Ue(),Ne=Ue(),Fe=Ue(),Re=Ue(),De=Ue(),Me=Ue(),Ce=Ue(),Ve=Ue(),Ge=Ue(),ze=Ue(),We=class{constructor(t,e){this.m=Ct(t,e,void 0,2048)}toJSON(){return Rt(this)}};We.prototype[D]=$,We.prototype.toString=function(){return this.m.toString()};var He=class{constructor(t,e){this.i=t,t=Be,this.j=!!t&&e===t||!1}};function $e(t,e,r,n,i){null!=(e=Ze(e,n))&&(r=je(t,r),i(e,t),xe(t,r))}const qe=new He($e,Be),Ke=new He($e,Be);var Ye=Symbol(),Je=Symbol();let Xe;function Qe(t){var e=tr,r=er,n=t[Ye];if(n)return n;(n={}).na=t,n.W=function(t){switch(typeof t){case"boolean":return Dt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Mt||=[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.ca=i,"function"==typeof(i=t[++o])&&(n.ia=!0,Xe??=t[o+1],i=t[o+=2]));const s={};for(;i&&Array.isArray(i)&&i.length&&"number"==typeof i[0]&&i[0]>0;){for(var a=0;a<i.length;a++)s[i[a]]=i;i=t[++o]}for(a=1;void 0!==i;){let s;"number"==typeof i&&(a+=i,i=t[++o]);var u=void 0;if(i instanceof He?s=i:(s=qe,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[Ye]=n}function Ze(t,e){return t instanceof We?t.m:Array.isArray(t)?Ct(t,e[0],e[1]):void 0}function tr(t,e,r){t[e]=r.i}function er(t,e,r,n){let i,o;const s=r.i;t[e]=(t,e,r)=>s(t,e,r,o||=Qe(n).W,i||=rr(n))}function rr(t){let e=t[Je];if(!e){const r=Qe(t);e=(t,e)=>nr(t,e,r),t[Je]=e}return e}function nr(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[V],((t,n)=>{if(null!=n){var i=function(t,e){var r=t[e];if(r)return r;if((r=t.ca)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof He?r:[Ke,r]:[r,void 0])[0].i;if(r=r[1]){const e=rr(r),i=Qe(r).W;r=t.ia?Xe(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||j(F,3)}}))}var ir,or=0,sr=or;if(Q(sr)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(sr))throw Error(String(sr))}else if((ir=X(sr))&&(ir=!Number.isSafeInteger(sr)),ir)throw Error(String(sr));function ar(t,e){if(Array.isArray(e)){var r=0|e[V];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),(t=-1537&(5|r))!==r&&H(e,t),2&t&&Object.freeze(e),e}}function ur(t,e){return new He(t,e)}function cr(t,e,r){null!=(e=At(e))&&(Oe(t,r,5),t=t.i,(r=at||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ct=0,e=ut=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 lr(t,e,r){null!=(e=xt(e))&&null!=e&&(Oe(t,r,0),Le(t.i,e))}function hr(t,e,r){null!=(e=Tt(e))&&(Oe(t,r,0),t.i.i.push(e?1:0))}function fr(t,e,r){null!=(e=Ut(e))&&ke(t,r,i(e))}function dr(t,e,r,n,i){null!=(e=Ze(e,n))&&(r=je(t,r),i(e,t),xe(t,r))}function pr(t,e,r){null!=(e=xt(e))&&(e=parseInt(e,10),Oe(t,r,0),Le(t.i,e))}tt||(or=Z(or)?or?"1":"0":Q(or)?or.trim()||"0":String(or));var mr,gr=ur(cr,Ve),_r=ur(cr,Ve),yr=ur((function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(yt(64,t));if(Pt(t)){if("string"===e){if(e=St(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&&t<="-9223372036854775808":e<19||19===e&&t<="9223372036854775807"))if(mt(t),t=ut,2147483648&(e=ct))if(x())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[r,n]=gt(t,e);t="-"+dt(r,n)}else t=dt(t,e);return t}if("number"===e){if(t=St(t),!bt(t)){ht(t),e=ut;var r=ct;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),t="number"==typeof(e=ft(e,r))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)Se(e);if(null!=e)switch(Oe(t,r,0),typeof e){case"number":t=t.i,ht(e),Ie(t,ut,ct);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ee(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Ie(t.i,r.j,r.i);break;default:r=Se(e),Ie(t.i,r.j,r.i)}}}),Me),wr=ur((function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(wt(64,t));if(Pt(t)){if("string"===e)return e=St(Number(t)),bt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),(e="-"!==t[0]&&((e=t.length)<20||20===e&&t<="18446744073709551615"))||(mt(t),t=dt(ut,ct))),t;if("number"===e)return(t=St(t))>=0&&bt(t)||(ht(t),t=ft(ut,ct)),t}}(e),null!=e){if("string"==typeof e)we(e);if(null!=e)switch(Oe(t,r,0),typeof e){case"number":t=t.i,ht(e),Ie(t,ut,ct);break;case"bigint":r=BigInt.asUintN(64,e),r=new be(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Ie(t.i,r.j,r.i);break;default:r=we(e),Ie(t.i,r.j,r.i)}}}),Ce),br=ur(lr,Re);mr=new He((function(t,e,r){if(null!=(e=ar(xt,e))&&e.length){r=je(t,r);for(let r=0;r<e.length;r++)Le(t.i,e[r]);xe(t,r)}}),Re);var vr,Sr=ur(lr,Re),Er=ur(lr,Re),Ar=ur(hr,Ne),Ir=ur(hr,Ne),Tr=ur(fr,Fe);vr=new He((function(t,e,r){if(null!=(e=ar(Ut,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&ke(n,o,i(s))}}),Fe);var Lr,Pr=ur(fr,Fe),Or=ur(fr,Fe),jr=function(t,e,r=Be){return new He(e,r)}(0,(function(t,e,r,n,i){if(Array.isArray(e)){for(let o=0;o<e.length;o++)dr(t,e[o],r,n,i);1&(t=0|e[V])||H(e,1|t)}})),xr=new He(dr,Be),kr=ur((function(t,e,r){null!=(e=kt(e))&&null!=e&&(Oe(t,r,0),Te(t.i,e))}),De),Ur=ur(pr,ze);Lr=new He((function(t,e,r){if(null!=(e=ar(xt,e))&&e.length){r=je(t,r);for(let r=0;r<e.length;r++)Le(t.i,e[r]);xe(t,r)}}),ze);var Br=ur(pr,ze);function Nr(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}}}};nr(this.m,e,Qe(t)),Pe(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 Fr(t,e){if(null!=e)if(Array.isArray(e))Jt(t,2,Nt(e,0,Ft));else{if(!("string"==typeof e||e instanceof A||v(e)))throw Error("invalid value in Any.value field: "+e+" expected a ByteString, a base64 encoded string, a Uint8Array or a jspb array");if(null!=e)if("string"==typeof e)e=e?new A(e,S):E();else if(e.constructor!==A){if(!v(e))throw Error();e=e.length?new A(new Uint8Array(e),S):E()}ie(t,2,e,E())}}var Rr=class extends We{constructor(t){super(t)}},Dr=[0,Pr,ur((function(t,e,r){if(null!=e){if(e instanceof We){const n=e.qa;return void(n?(e=n(e),null!=e&&ke(t,r,ye(e).buffer)):j(F,3))}if(Array.isArray(e))return void j(F,3)}null!=(e=null==e||"string"==typeof e||e instanceof A?e:void 0)&&ke(t,r,ye(e).buffer)}),Ge)];let Mr,Cr=globalThis.trustedTypes;function Vr(t){var e;return void 0===Mr&&(Mr=function(){let t=null;if(!Cr)return t;try{const e=t=>t;t=Cr.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=Mr)?e.createScriptURL(t):t,new class{constructor(t){this.i=t}toString(){return this.i+""}}(t)}function Gr(t,...e){if(0===e.length)return Vr(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return Vr(r)}var zr={};zr[336783863]=[0,Tr,Ar,-1,br,[0,[1,2,3,4,5,6,7,8,9],xr,[0],xr,[0,Ar,Tr,Ar,Ur,-1,Lr,Tr,-1,[0,Ar,-1],Ur,Ar,-1],xr,[0,Tr,-2],xr,[0,br,Ar,1,Ar,-4],xr,[0,br,Ur,Ar,-1,mr,Ur,-1,Ar],xr,[0,Tr,-2],xr,[0,Tr,Ur],xr,[0,3,Ar,-1,2,[0,br],[0,Ur,Ar],[0,Tr,-1],[0]],xr,[0,Ur,-1,Ar]],[0,Tr],Ar,[0,[1,3],[2,4],xr,[0,mr],-1,xr,[0,vr],-1,jr,[0,Tr,-1]],Tr];var Wr=class extends We{constructor(t){super(t)}},Hr=[0,yr,-1,Ir,-3,yr,mr,Pr,Sr,yr,-1,Ir,Sr,Ir,-2,Pr],$r=class extends We{constructor(t){super(t,500)}N(t){return ce(this,7,t)}},qr=[-1,{}],Kr=[0,Tr,1,qr],Yr=[0,Tr,vr,qr];function Jr(t,e){he(t,1,$r,e)}var Xr=class extends We{constructor(t){super(t,500)}N(t){return ce(this,1001,t)}};Xr.prototype.j=Nr([-500,jr,[-500,Pr,-1,vr,-3,[-2,zr,Ar],jr,Dr,Sr,-1,Kr,Yr,jr,[0,Pr,Ir],Pr,Hr,Sr,vr,987,vr],4,jr,[-500,Tr,-1,[-1,{}],998,Tr],jr,[-500,Tr,vr,-1,[-2,{},Ar],997,vr,-1],Sr,jr,[-500,Tr,vr,qr,998,vr],vr,Sr,Kr,Yr,jr,[0,Pr,-1,qr],vr,-2,Hr,Pr,-1,Ir,[0,Ir,kr],978,qr,jr,Dr]);var Qr=class extends We{constructor(t){super(t)}};let Zr;const tn=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 en(){if(void 0===Zr)try{await WebAssembly.instantiate(tn),Zr=!0}catch{Zr=!1}return Zr}async function rn(t,e=Gr``){const r=await en()?"wasm_internal":"wasm_nosimd_internal";return{wasmLoaderPath:`${e}/${t}_${r}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var nn=class{};function on(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 sn(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}nn.forVisionTasks=function(t){return rn("vision",t)},nn.forTextTasks=function(t){return rn("text",t)},nn.forGenAiExperimentalTasks=function(t){return rn("genai_experimental",t)},nn.forGenAiTasks=function(t){return rn("genai",t)},nn.forAudioTasks=function(t){return rn("audio",t)},nn.isSimdSupported=function(){return en()};const an=[[0,async t=>{const e=(new TextEncoder).encode("TFL3").length;return t=await sn(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await sn(t,6))[4]&&75===t[5]]];function un(){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 cn(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)}))}try{importScripts(t.toString())}catch(e){if(!(e instanceof TypeError))throw e;await self.import(t.toString())}}function ln(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 hn(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 fn(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function dn(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 pn=(mn=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:un()?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?'),ln(this,n||"input_audio",(n=>{ln(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),ln(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){ln(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){ln(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){ln(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){ln(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){ln(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){ln(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){ln(this,e,(e=>{ln(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){ln(this,e,(e=>{hn(this,Object.keys(t),(n=>{hn(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){ln(this,r,(r=>{ln(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){ln(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){ln(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){ln(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){ln(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){ln(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){ln(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){ln(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)ln(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){ln(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){ln(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){ln(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){ln(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){ln(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){ln(this,e,(e=>{ln(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){ln(this,r,(r=>{ln(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){ln(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){ln(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){ln(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){ln(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){ln(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){ln(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)ln(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){fn(this,t,e),ln(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){dn(this,t,e),ln(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){fn(this,t,e),ln(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){dn(this,t,e),ln(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?'),fn(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),ln(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 mn{ka(){this.h._registerModelResourcesGraphService()}});var mn;async function gn(t,e){const r=await(async(t,e,r)=>{var n=ri;if(t&&await cn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await cn(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 _n(t,e){return gn(t,e)}function yn(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 wn(t,e){t.I=Math.max(t.I,e)}var bn=class{constructor(t){this.j=t,this.J=[],this.I=0,this.j.setAutoRenderToScreen(!1)}setGraph(t,e){this.j.attachErrorListener(((t,e)=>{this.J.push(Error(e))})),this.j.ka(),this.j.setGraph(t,e),yn(this)}finishProcessing(){this.j.finishProcessing(),yn(this)}close(){this.j.closeGraph()}};bn.prototype.close=bn.prototype.close;var vn=class extends We{constructor(t){super(t)}j(){return xt(Kt(this,2))??0}};function Sn(t,e){ce(t,1,e)}var En=class extends We{constructor(t){super(t)}},An=[0,Br,Sr,_r,-1,br];function In(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}}vn.prototype.l=Nr(An);class Tn{constructor(t){this.i=[],this.data=t,this.length=t.length}}function Ln(t,e){return new On((async()=>{const{value:e,done:r}=await t.read();return r?void 0:e}),e)}async function Pn(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 Tn(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=In(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 On=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 jn(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function xn(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function kn(t,e,r){t=new Bn(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 Un(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${r} bytes before failure`);return t}function Un(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Bn=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))}},Nn=class extends We{constructor(t){super(t)}};Nn.prototype.j=Nr([0,Pr,2,vr,Sr,Ir]);var Fn=class extends We{constructor(t){super(t)}},Rn=class extends We{constructor(t){super(t)}},Dn=class extends We{constructor(t){super(t)}},Mn=class extends We{constructor(t){super(t)}},Cn=[0,Sr,-6,1,Sr,1,[0,Ir,Br,-2],[0,Ir,_r],Br,-2,[0,Ir,-1,Br,_r,Ur,br,Ar,-1],1,Ir,Sr,br,-1,[0,Br,Sr],Ir,-1,gr,Sr,-5,gr,-1,[0,br,gr],br,Ar,[0,br,-2],gr,[0,Sr],[0,Sr,-4],Ar,br,-2,Ar,-1],Vn=[0,Pr,-2],Gn=[0,[4,6],Cn,Sr,1,Er,vr,Or,Lr,Vn,br,[0,[0,Sr,-1,jr,[0,Sr,[0,Sr,-1],-1,[0,Br,-1],Ir],Ir,-2,Sr,-1],[0,Sr,-1,Ir],Cn,Ir,Sr,[0,Sr],-1],Tr,-3,[0,Sr,Ir],Cn,[0,Vn,-2],mr];Mn.prototype.j=Nr([0,Pr,8,[0,Ir,-6],1,Sr,1,Sr,[0,jr,[0,Pr,wr,-1,Br],Gn,Sr],[0,Sr,Ir,-3],1,Br,1,Gn,1,Sr,5,Br,mr,1,An,Ir,Sr,Ir]);var zn=class extends We{constructor(t){super(t)}},Wn=class extends We{constructor(t){super(t)}},Hn=[2,4];Wn.prototype.j=Nr([0,Hn,Sr,Or,Sr,xr,[0,1,Pr]]);const $n=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=Ln(t,(()=>{}));await this.h.createLlmInferenceEngine(fe(e,2)??512,ae(e,vn,3)?.j()??40,Tt(Kt(e,6))??!1??!1,fe(e,7)??0,Tt(Kt(e,8))??!1??!1,((t,e,n)=>Pn(r,this.h,t,e,n)))}finally{this.L()}}async ba(t,e){this.M();try{await this.ma(t),await this.h.ccall("CreateLlmInferenceEngineConverted","void",["number","number","boolean"],[fe(e,2)??512,ae(e,vn,3)?.j()??40,Tt(Kt(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(xn),c=t.some(jn);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)ln(this,r,(t=>{i._AddTextQueryChunk(l,t)}));else if(jn(r)){const{image:t,width:n,height:o}=await this.fa(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(!xn(r))throw Error("Unsupported PromptPart type in query.");{const t=await this.ea(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:jn(n)?e+=260:xn(n)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return ln(this,r,(e=>{t=this.h._GetSizeInTokens(e)})),e+t}finally{this.L()}}async ma(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 fa(t){if("string"==typeof t){const e=new Image;e.src=t,e.crossOrigin="Anonymous";try{await e.decode()}catch{throw Error(`Image from URL ${t} failed to load`)}return{image:e,width:e.naturalWidth,height:e.naturalHeight}}if(t instanceof HTMLImageElement){try{await t.decode()}catch{throw Error("Image from HTMLImageElement failed to load")}return{image:t,width:t.naturalWidth,height:t.naturalHeight}}return t instanceof HTMLVideoElement?{image:t,width:t.videoWidth,height:t.videoHeight}:t instanceof VideoFrame?{image:t,width:t.displayWidth,height:t.displayHeight}:{image:t,width:t.width,height:t.height}}async ea(t){if("string"==typeof t){const e=await fetch(t);if(!e.ok)throw Error(`Audio fetch for ${t} had error: ${e.status}`);return t=await e.arrayBuffer(),{audioSamples:(t=await new AudioContext({sampleRate:16e3}).decodeAudioData(t)).getChannelData(0),audioSampleRateHz:t.sampleRate}}return"object"==typeof t&&null!=t&&"audioSamples"in t&&"audioSampleRateHz"in t?t:{audioSamples:t.getChannelData(0),audioSampleRateHz:t.sampleRate}}}}(function(t){const e=class extends t{static async la(t,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}ga(t){if(e)"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id="canvas_webgpu");else var e=new OffscreenCanvas(1,1);e.getContext("webgpu").configure({device:t,format:navigator.gpu.getPreferredCanvasFormat()}),this.h.preinitializedWebGPUDevice=t}aa(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}};return e}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket(((e,r,n)=>Pn(t,this.h,e,r,n)),e)}}}(function(t){return class extends t{Y(t,e){ln(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends pn{}))));class qn extends $n{}var Kn=class{constructor(t){this.j=t,this.i=Yn,Yn++}},Yn=1;class Jn{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.resolve=t,this.reject=e}}function Xn(t){return 1===t?1:t+t%2}async function Qn(){const t=await qn.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),qn.la(e,t)}function Zn(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 ti(t){const e=function(t){const e=new Xr;ge(e,10,"text_in"),ge(e,10,"token_cost_in"),ge(e,10,"lora_model_id_to_apply_in"),ge(e,10,"lora_model_ref_in"),ge(e,10,"lora_model_id_to_load_in"),ge(e,16,"streaming_reader"),ge(e,15,"text_out"),ge(e,15,"text_end"),ge(e,15,"token_cost_out");var r=new $r;me(r,2,"TokenizerInputBuildCalculator"),ge(r,3,"PROMPT:text_in"),ge(r,3,"LORA_ID:lora_model_id_to_apply_in"),ge(r,4,"prompt"),Jr(e,r),me(r=new $r,2,"ModelDataCalculator"),ge(r,6,"MODEL_DATA:__side_packet_1"),ge(r,6,"MODEL_TYPE:model_type"),ge(r,5,"READ_DATA_FN:streaming_reader"),ge(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),ge(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),ge(r,4,"LORA_DATA:lora_model_data"),Jr(e,r),me(r=new $r,2,"Gpt2UnicodeMappingCalculator"),ge(r,5,"MODEL_TYPE:model_type"),ge(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Jr(e,r),me(r=new Rr,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new Wn,i=fe(t.i,2);de(n,1,i),me(i=new zn,2,"spm_vocab_model"),i=ue(i);t:{Ht(n);var o=n.m,s=0|o[V];if(null==i){var a=oe(o);if(4!==se(a,o,s))break t;a.set(Hn,0)}else{const t=oe(a=o),e=se(t,a,s);4!==e&&(e&&(s=Xt(a,s,e)),t.set(Hn,4))}Xt(o,s,4,i)}return i&&!q(i)&&$t(n.m),de(n,3,2),Fr(r,n.j()),me(n=new $r,2,"TokenizerCalculator"),he(n,8,Rr,r),ge(n,5,"MODEL_DATA:__side_packet_1"),ge(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),ge(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(n,6,"PROCESSOR_GETTER:__input_side_1"),ge(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),Jr(e,n),me(r=new Rr,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),de(n=new Mn,12,3),me(n,1,"llm.tflite"),de(n,14,0),i=Xn(fe(t.i,5)),de(n,22,i),i=ae(t.i,vn,3),ce(n,31,i),ie(i=new Fn,1,It(!0),!1),null!=Tt(Kt(t.i,6))&&(Tt(Kt(t.i,6))??!1)&&ie(i,1,It(!1),!1),ie(i,2,It(!0),!1),ie(i,5,It(!0),!1),ce(n,10,i),i=Qt(t.i,4,xt,void 0===Y?2:4),ne(n,29,i),i=new Dn,de(o=new Rn,1,1),a=fe(t.i,2),de(o,2,a),ce(i,1,o),ce(n,20,i),Fr(r,n.j()),me(n=new $r,2,"LlmGpuCalculator"),he(n,8,Rr,r),ge(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),ge(n,3,"FINISH:finish"),ge(n,3,"LORA_DATA:lora_model_data"),ge(n,5,"MODEL_DATA:__side_packet_1"),ge(n,4,"DECODED_IDS:__stream_3"),ge(n,4,"OUTPUT_END:__stream_4"),me(r=new Wr,1,"FINISH"),ie(r,2,It(!0),!1),he(n,13,Wr,r),Jr(e,n),me(r=new $r,2,"IsPacketPresentCalculator"),ge(r,3,"__stream_4"),ge(r,4,"text_end"),Jr(e,r),me(r=new Rr,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new Nn,t=Xn(fe(t.i,5)),de(n,5,t),ge(n,4,"<eos>"),ge(n,4,"<|endoftext|>"),Fr(r,n.j()),me(t=new $r,2,"DetokenizerCalculator"),he(t,8,Rr,r),ge(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),ge(t,5,"PROCESSOR_GETTER:__input_side_1"),ge(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(t,5,"MODEL_DATA:__side_packet_1"),ge(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),ge(t,4,"WORDS:text_out"),Jr(e,t),me(t=new $r,2,"TokenCostCalculator"),ge(t,3,"PROMPT:token_cost_in"),ge(t,5,"PROCESSOR_GETTER:__input_side_1"),ge(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ge(t,4,"NUM_TOKENS:token_cost_out"),Jr(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<fe(t.i,5)&&t.G[r].push(e)})),t.A&&0===t.D.length&&(t.B?(e.length>fe(t.i,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),wn(t,r)})),t.j.attachEmptyPacketListener("text_out",(e=>{wn(t,e)})),t.j.attachBoolListener("text_end",((e,r)=>{wn(t,r);try{Zn(t)}catch(e){throw t.l=!1,e}if(t.o&&(t.o.resolve(t.G.map((t=>t.join("")))),t.o=void 0),t.A)if(t.B){for(e=[],r=0;r<fe(t.i,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.l=!1,t.B=void 0})),t.j.attachEmptyPacketListener("text_end",(e=>{t.l=!1,t.B=void 0,wn(t,e),Zn(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,wn(t,r)})),t.U&&t.j.addStreamingReaderToInputSidePacket(t.U,"streaming_reader");const r=e.j();return t.C?.removeEventListener("uncapturederror",t.K),t.j.aa().then((()=>{t.C?.addEventListener("uncapturederror",t.K),t.D.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function ei(t,e,r,n){if(t.A="function"==typeof r?r:n,(n=(e=Array.isArray(e)?e:[e]).filter((t=>jn(t))).length)>0&&(null==kt(Kt(t.i,7))||fe(t.i,7)<n))throw Error(`maxNumImages is set to ${null!=kt(Kt(t.i,7))?fe(t.i,7):0}, but the query included ${n} images.`);if((n=e.filter((t=>xn(t))).length)>0&&(null==Tt(Kt(t.i,8))||!Tt(Kt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${n} audio chunks.`);if(t.v){if(t.B&&fe(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 Kn)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality to use LoRA.");return t.j.h.LLM_CANCEL_FLAG=void 0,t.j.R(e,t.u,((e,r)=>{0===t.D.length&&t.A&&(t.B?t.A([e],r):t.A(e,r))})).then((e=>(Zn(t),[e])))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.j.h.LLM_CANCEL_FLAG=void 0,t.G.length=0,n=0;n<fe(t.i,5);n++)t.G[n]=[];if(n=t.I+1,t.j.addStringToStream(e.join(""),"text_in",n),r instanceof Kn){if(r.j!==t)throw t.l=!1,t.B=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.j.addUintToStream(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 Jn,t.o.promise}var ri=class extends bn{constructor(t,e){if(super(new qn(t,e)),this.G=[],this.O=this.v=this.l=!1,this.D=[],this.K=t=>{if((t=t.error).message.match(/exceeds the max buffer size limit/))throw Error(`Failed to run this LLM model because it requires a buffer size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);if(t.message.match(/is larger than the maximum storage buffer binding size/))throw Error(`Failed to run this LLM model because it requires a storage buffer binding size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);this.D.push(t)},this.i=new En,Sn(this.i,new Qr),this.u=new vn,ce(this.i,3,this.u),pe(this.i,2,512),t=this.u,!vt(2))throw O("enum");ie(t,1,2,0),de(this.u,2,40),ie(this.u,3,Et(1),0),Jt(this.u,5,jt(0)),ie(this.u,4,Et(.8),0),pe(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]=on(n);this.O=1===await async function(t){const e=[];let r;for(const[i,o]of an){const s=i;var n=o;[t,r]=on(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;pe(this.i,7,i);var o="supportAudio"in t&&!!t.supportAudio;Jt(this.i,8,It(o)),this.O||i>0||o?(this.v=!0,n=r):(this.v=!1,this.U=Ln(r,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.K),this.C=t.baseOptions.gpuOptions.device,this.j.ga(this.C),this.C.addEventListener("uncapturederror",this.K)),"maxTokens"in t&&pe(this.i,2,t.maxTokens??512),"topK"in t&&de(this.u,2,t.topK??40),"temperature"in t&&ie(this.u,4,Et(t.temperature??.8),0),"randomSeed"in t&&Jt(this.u,5,jt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){ne(t,4,e)}(this.i,t.loraRanks??[]),"numResponses"in t){if((i=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&i>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet, and is also not supported with multimodality.");pe(this.i,5,i),o=ae(this.i,vn,3),i>1&&o&&(o.j()<=1||(Kt(o,4,At)??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&&Jt(this.i,6,It(t.forceF32)),this.v?(this.j.V(),this.O?this.j.ba(n,this.i).then((()=>{Zn(this)})):this.j.createLlmInferenceEngine(n,this.i).then((()=>{Zn(this)}))):(this.l=!0,t=ti(this).then((()=>{})),Promise.all([r,t]).then((()=>{this.l=!1,Zn(this)})))}get baseOptions(){return ae(this.i,Qr,1)}set baseOptions(t){Sn(this.i,t)}get isIdle(){return!this.l&&!this.o}R(t,e,r){return fe(this.i,5)>1&&console.warn("'numResponses' is set larger than 1 and this function only returns the first response, so we recommend either using 'generateResponses()' to obtain multiple responses, or else setting 'numResponses' to 1 for better performance."),this.B=!1,ei(this,t,e,r).then((t=>t[0]))}da(t,e,r){return this.B=!0,ei(this,t,e,r)}S(t){if(t=Array.isArray(t)?t:[t],this.v)return this.j.S(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");if(t.some(jn))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(xn))throw Error("sizeInTokens requires supportAudio for audio.");return t=t.join(""),this.l=!0,this.T=void 0,this.j.addStringToStream(t,"token_cost_in",this.I+1),this.finishProcessing(),this.l=!1,this.T}Z(){const t=this.j.h;(this.v||this.l)&&(t.LLM_CANCEL_FLAG=1)}async ja(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the old format (.bin) without multimodality to use LoRA.");if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new Bn(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return kn(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 kn(t,e.body,r)}(this.j.h,t);e=new Kn(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(),Un(t),wn(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};ri.prototype.loadLoraModel=ri.prototype.ja,ri.prototype.cancelProcessing=ri.prototype.Z,ri.prototype.sizeInTokens=ri.prototype.S,ri.prototype.generateResponses=ri.prototype.da,ri.prototype.generateResponse=ri.prototype.R,ri.prototype.setOptions=ri.prototype.N,ri.createWebGpuDevice=Qn,ri.createFromModelPath=async function(t,e){return _n(t,e={baseOptions:{gpuOptions:{device:await Qn()},modelAssetPath:e}})},ri.createFromModelBuffer=async function(t,e){return _n(t,e={baseOptions:{gpuOptions:{device:await Qn()},modelAssetBuffer:e}})},ri.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Qn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return _n(t,e)},exports.FilesetResolver=nn,exports.LlmInference=ri,exports.TaskRunner=bn;
1
+ "use strict";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}var r,n="undefined"!=typeof TextEncoder;function i(t){if(n)t=(r||=new TextEncoder).encode(t);else{let r=0,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){let 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=e(610401301,!1),a=e(748402147,!0);function s(){var e=t.navigator;return e&&(e=e.userAgent)?e:""}var l,u=t.navigator;l=u&&u.userAgentData||null;var h={},c=null;function f(t){var e=t.length,r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);var n=new Uint8Array(r),i=0;return function(t,e){function r(e){for(;n<t.length;){let e=t.charAt(n++),r=c[e];if(null!=r)return r;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}d();for(var n=0;;){let 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(!c){c={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let n=t.concat(e[r].split(""));h[r]=n;for(let t=0;t<n.length;t++){let e=n[t];void 0===c[e]&&(c[e]=t)}}}}var p="undefined"!=typeof Uint8Array,m=!(!(o&&l&&l.brands.length>0)&&(-1!=s().indexOf("Trident")||-1!=s().indexOf("MSIE")))&&"function"==typeof btoa,g=/[-_.]/g,v={"-":"+",_:"/",".":"="};function _(t){return v[t]||""}function y(t){if(!m)return f(t);t=g.test(t)?t.replace(g,_):t,t=atob(t);var 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 b={};function S(){return E||=new A(null,b)}var E,A=class{constructor(t,e){if(I(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};function I(t){if(t!==b)throw Error("illegal external caller")}function T(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}var L=void 0;function P(t){return T(t=Error(t),"warning"),t}function O(e,r){if(null!=e){var n=L??={},i=n[e]||0;i>=r||(n[e]=i+1,T(e=Error(),"incident"),function(e){t.setTimeout(()=>{throw e},0)}(e))}}function j(){return"function"==typeof BigInt}var k="function"==typeof Symbol&&"symbol"==typeof Symbol();function 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 U,B=x("jas",void 0,!0),N=x(void 0,"1oa"),F=x(void 0,"0ubsb"),R=x(void 0,"0actk"),D=x("m_m","pa",!0),C={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},M=Object.defineProperties,V=k?B:"ha",G=[];function z(t,e){k||V in t||M(t,C),t[V]|=e}function W(t,e){k||V in t||M(t,C),t[V]=e}W(G,7),U=Object.freeze(G);var H={};function $(t,e){return void 0===e?t.i!==q&&!!(2&t.m[V]):!!(2&e)&&t.i!==q}var q={},K=Object.freeze({});function Y(t){return t.oa=!0,t}var J=Y(t=>"number"==typeof t),X=Y(t=>"string"==typeof t),Q=Y(t=>"boolean"==typeof t),Z="function"==typeof t.BigInt&&"bigint"==typeof t.BigInt(0),tt=Y(t=>Z?t>=rt&&t<=it:"-"===t[0]?ot(t,et):ot(t,nt)),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++){let n=t[r],i=e[r];if(n>i)return!1;if(n<i)return!0}}var at,st=0,lt=0;function ut(t){var e=t>>>0;st=e,lt=(t-e)/4294967296>>>0}function ht(t){if(t<0){ut(-t);let[e,r]=mt(st,lt);st=e>>>0,lt=r>>>0}else ut(t)}function ct(t,e){var 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 j()?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)ht(Number(t));else if(j())t=BigInt(t),st=Number(t&BigInt(4294967295))>>>0,lt=Number(t>>BigInt(32)&BigInt(4294967295));else{let e=+("-"===t[0]);lt=st=0;let r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){let e=Number(t.slice(n,i));lt*=1e6,(st=1e6*st+e)>=4294967296&&(lt+=Math.trunc(st/4294967296),lt>>>=0,st>>>=0)}if(e){let[t,e]=mt(st,lt);st=t,lt=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)}var vt="function"==typeof BigInt?BigInt.asIntN:void 0,_t="function"==typeof BigInt?BigInt.asUintN:void 0,yt=Number.isSafeInteger,wt=Number.isFinite,bt=Math.trunc;function St(t){if(null!=t&&"number"!=typeof t)throw Error(`Value of float/double field must be a number, found ${typeof t}: ${t}`);return t}function Et(t){return null==t||"number"==typeof t?t:"NaN"===t||"Infinity"===t||"-Infinity"===t?Number(t):void 0}function At(t){if(null!=t&&"boolean"!=typeof t){var e=typeof t;throw Error(`Expected boolean but got ${"object"!=e?e:t?Array.isArray(t)?"array":e:"null"}: ${t}`)}return t}function It(t){return null==t||"boolean"==typeof t?t:"number"==typeof t?!!t:void 0}var Tt,Lt,Pt,Ot=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function jt(t){switch(typeof t){case"bigint":return!0;case"number":return wt(t);case"string":return Ot.test(t);default:return!1}}function kt(t){if("number"!=typeof t)throw P("int32");if(!wt(t))throw P("int32");return 0|t}function xt(t){return null==t?t:kt(t)}function Ut(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 Bt(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 Nt(t){return null==t||"string"==typeof t?t:void 0}function Ft(t,e,r){if(null!=t&&t[D]===H)return t;if(Array.isArray(t)){var n=0|t[V];return(r=n|32&r|2&r)!==n&&W(t,r),new e(t)}}function Rt(t){return t}function Dt(t,e,r,n){var i=void 0!==n;n=!!n;var o=[],a=t.length,s=4294967295,l=!1,u=!!(64&e),h=u?128&e?0:-1:void 0;if(!(1&e)){var c=a&&t[a-1];null!=c&&"object"==typeof c&&c.constructor===Object?s=--a:c=void 0,!u||128&e||i||(l=!0,s=(Tt??Rt)(s-h,h,t,c,void 0)+h)}for(e=void 0,i=0;i<a;i++){let a=t[i];if(null!=a&&null!=(a=r(a,n)))if(u&&i>=s){let t=i-h;(e??={})[t]=a}else o[i]=a}if(c)for(let i in c){if(null==(t=c[i])||null==(t=r(t,n)))continue;let l;a=+i,u&&!Number.isNaN(a)&&(l=a+h)<s?o[l]=t:(e??={})[i]=t}return e&&(l?o.push(e):o[s]=e),o}function Ct(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[V];return 0===t.length&&1&e?void 0:Dt(t,e,Ct)}if(null!=t&&t[D]===H)return Mt(t);if(t instanceof A){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=h[r],n=Array(Math.floor(e.length/3)),i=r[64]||"";let t=0,u=0;for(;t<e.length-2;t+=3){var o=e[t],a=e[t+1],s=e[t+2],l=r[o>>2];o=r[(3&o)<<4|a>>4],a=r[(15&a)<<2|s>>6],s=r[63&s],n[u++]=l+o+a+s}switch(l=0,s=i,e.length-t){case 2:s=r[(15&(l=e[t+1]))<<2]||i;case 1:e=e[t],n[u]=r[e>>2]+r[(3&e)<<4|l>>4]+s+i}e=n.join("")}t=t.i=e}return t}return}return t}function Mt(t){return Dt(t=t.m,0|t[V],Ct)}function Vt(t,e,r,n=0){if(null==t){var i=32;r?(t=[r],i|=128):t=[],e&&(i=-16760833&i|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(i=0|t[V],a&&1&i)throw Error("rfarr");if(2048&i&&!(2&i)&&function(){if(a)throw Error("carr");O(R,5)}(),256&i)throw Error("farr");if(64&i)return(i|n)!==i&&W(t,i|n),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;let 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 l in t)(o=+l)<s&&(r[o+e]=t[l],delete t[l]);i=-16760833&i|(1023&s)<<14;break t}}if(e){if((l=Math.max(e,o-(128&i?0:-1)))>1024)throw Error("spvt");i=-16760833&i|(1023&l)<<14}}}return W(t,64|i|n),t}function Gt(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var r=0|t[V];return 0===t.length&&1&r?t=void 0:2&r||(!e||4096&r||16&r?t=Wt(t,r,!1,e&&!(16&r)):(z(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[D]===H?$(t,r=0|(e=t.m)[V])?t:Kt(t,e,r)?zt(t,e):Wt(e,r):t instanceof A?t:void 0}function zt(t,e,r){return t=new t.constructor(e),r&&(t.i=q),t.o=q,t}function Wt(t,e,r,n){return n??=!!(34&e),t=Dt(t,e,Gt,n),n=32,r&&(n|=2),W(t,e=16769217&e|n),t}function Ht(t){if(t.i!==q)return!1;var e=t.m;return z(e=Wt(e,0|e[V]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function $t(t){if(!Ht(t)&&$(t,0|t.m[V]))throw Error()}function qt(t,e){void 0===e&&(e=0|t[V]),32&e&&!(4096&e)&&W(t,4096|e)}function Kt(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(W(e,2|r),t.i=q,!0)}function Yt(t,e,r){if(null!==(t=Jt(t.m,e,void 0,r)))return t}function Jt(t,e,r,n){if(-1===e)return null;var i=e+(r?0:-1),o=t.length-1;if(!(o<1+(r?0:-1))){if(i>=o){var a=t[o];if(null!=a&&"object"==typeof a&&a.constructor===Object){r=a[e];var s=!0}else{if(i!==o)return;r=a}}else r=t[i];if(n&&null!=r){if(null==(n=n(r)))return n;if(!Object.is(n,r))return s?a[e]=n:t[i]=n,n}return r}}function Xt(t,e,r){$t(t),Qt(t=t.m,0|t[V],e,r)}function Qt(t,e,r,n,i){var o=r+(i?0:-1),a=t.length-1;if(a>=1+(i?0:-1)&&o>=a){let i=t[a];if(null!=i&&"object"==typeof i&&i.constructor===Object)return i[r]=n,e}return o<=a?(t[o]=n,e):(void 0!==n&&(r>=(a=(e??=0|t[V])>>14&1023||536870912)?null!=n&&(t[a+(i?0:-1)]={[r]:n}):t[o]=n),e)}function Zt(t,e,r,n,i){var o=t.m,a=0|o[V];n=$(t,a)?1:n,i=!!i||3===n,2===n&&Ht(t)&&(a=0|(o=t.m)[V]);var s=(t=ee(o,e))===U?7:0|t[V],l=re(s,a),u=!(4&l);if(u){4&l&&(t=gt(t),s=0,l=ce(l,a),a=Qt(o,a,e,t));let n=0,i=0;for(;n<t.length;n++){let e=r(t[n]);null!=e&&(t[i++]=e)}i<n&&(t.length=i),r=-513&l|4,l=r&=-1025,l&=-4097}return l!==s&&(W(t,l),2&l&&Object.freeze(t)),te(t,l,o,a,e,n,u,i)}function te(t,e,r,n,i,o,a,s){var l=e;return 1===o||4===o&&(2&e||!(16&e)&&32&n)?ne(e)||((e|=!t.length||a&&!(4096&e)||32&n&&!(4096&e||16&e)?2:256)!==l&&W(t,e),Object.freeze(t)):(2===o&&ne(e)&&(t=gt(t),l=0,e=ce(e,n),n=Qt(r,n,i,t)),ne(e)||(s||(e|=16),e!==l&&W(t,e))),2&e||!(4096&e||16&e)||qt(r,n),t}function ee(t,e,r){return t=Jt(t,e,r),Array.isArray(t)?t:U}function re(t,e){return 2&e&&(t|=2),1|t}function ne(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function ie(t,e,r){$t(t);var n=0|(t=t.m)[V];if(null==r)Qt(t,n,e);else{var i=r===U?7:0|r[V],o=i,a=ne(i),s=a||Object.isFrozen(r);for(a||(i=0),s||(r=gt(r),o=0,i=ce(i,n),s=!1),i|=5,i|=(4&i?512&i?512:1024&i?1024:0:void 0)??1024,a=0;a<r.length;a++){let t=r[a],e=kt(t);Object.is(t,e)||(s&&(r=gt(r),o=0,i=ce(i,n),s=!1),r[a]=e)}i!==o&&(s&&(r=gt(r),i=ce(i,n)),W(r,i)),Qt(t,n,e,r)}}function oe(t,e,r,n){$t(t),Qt(t=t.m,0|t[V],e,("0"===n?0===Number(r):r===n)?void 0:r)}function ae(t){if(k)return t[N]??(t[N]=new Map);if(N in t)return t[N];var e=new Map;return Object.defineProperty(t,N,{value:e}),e}function se(t,e,r){var n=Xn,i=t.get(n);if(null!=i)return i;i=0;for(let t=0;t<n.length;t++){let o=n[t];null!=Jt(e,o)&&(0!==i&&(r=Qt(e,r,i)),i=o)}return t.set(n,i),i}function le(t,e,r){var n=t.m,i=0|n[V];if(e=function(t,e,r,n){var i=!1;if(null!=(n=Jt(t,n,void 0,t=>{var n=Ft(t,r,e);return i=n!==t&&null!=n,n})))return i&&!$(n)&&qt(t,e),n}(n,i,e,r),null==e)return e;if(!$(t,i=0|n[V])){var o,a=e;let s=a.m,l=0|s[V];(o=$(a,l)?Kt(a,s,l)?zt(a,s,!0):new a.constructor(Wt(s,l,!1)):a)!==e&&(Ht(t)&&(i=0|(n=t.m)[V]),qt(n,i=Qt(n,i,r,e=o)))}return e}function ue(t){return null==t&&(t=void 0),t}function he(t,e,r){return Xt(t,e,r=ue(r)),r&&!$(r)&&qt(t.m),t}function ce(t,e){return-273&(2&e?2|t:-3&t)}function fe(t,e,r,n){var i=n;$t(t);var o=n=t.m,a=0|n[V],s=$(t,a)?1:2;2===s&&Ht(t)&&(a=0|(o=t.m)[V]);var l=(t=ee(o,e))===U?7:0|t[V],u=re(l,a),h=!(4&u);if(h){var c=t,f=a;let e=!!(2&u);e&&(f|=2);let n=!e,i=!0,o=0,s=0;for(;o<c.length;o++){let t=Ft(c[o],r,f);if(t instanceof r){if(!e){let e=$(t);n&&=!e,i&&=e}c[s++]=t}}s<o&&(c.length=s),u|=4,u=i?-4097&u:4096|u,u=n?8|u:-9&u}u!==l&&(W(t,u),2&u&&Object.freeze(t)),e=t=te(t,u,o,a,e,s,h,!0),i=null!=i?i:new r,e.push(i),o=r=e===U?7:0|e[V],(i=$(i))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&W(e,r),i||qt(n)}function de(t,e){return Bt(Yt(t,e))??0}function pe(t,e,r){oe(t,e,xt(r),0)}function me(t,e,r){if(null!=r){if("number"!=typeof r)throw P("uint32");if(!wt(r))throw P("uint32");r>>>=0}Xt(t,e,r)}function ge(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();oe(t,e,r,"")}function ve(t,e,r){if($t(t),e=(t=Zt(t,e,Nt,2,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}var _e=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function ye(t){if("string"==typeof t)return new _e(y(t),!0);if(Array.isArray(t))return new _e(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new _e(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new _e(t,!1);if(t.constructor===A){I(b);var e=t.i;return e=(null==(e=null==e||w(e)?e:"string"==typeof e?y(e):null)?e:t.i=e)||new Uint8Array(0),new _e(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new _e(t,!1);throw Error()}function we(t){return t?/^\d+$/.test(t)?(pt(t),new Se(st,lt)):null:be||=new Se(0,0)}var be,Se=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Ee(t){return t?/^-?\d+$/.test(t)?(pt(t),new Ie(st,lt)):null:Ae||=new Ie(0,0)}var Ae,Ie=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Te(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 Pe(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)}}var Oe=class{constructor(){this.i=[]}length(){return this.i.length}end(){var t=this.i;return this.i=[],t}};function je(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function ke(t,e,r){Le(t.i,8*e+r)}function xe(t,e){return ke(t,e,2),e=t.i.end(),je(t,e),e.push(t.j),e}function Ue(t,e){var 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){ke(t,e,2),Le(t.i,r.length),je(t,t.i.end()),je(t,r)}var Ne=class{constructor(){this.l=[],this.j=0,this.i=new Oe}};function Fe(){var t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Re=Fe(),De=Fe(),Ce=Fe(),Me=Fe(),Ve=Fe(),Ge=Fe(),ze=Fe(),We=Fe(),He=Fe(),$e=Fe(),qe=class{constructor(t,e){this.m=Vt(t,e,void 0,2048)}toJSON(){return Mt(this)}};qe.prototype[D]=H,qe.prototype.toString=function(){return this.m.toString()};var Ke=class{constructor(t,e){this.i=t,t=Re,this.j=!!t&&e===t||!1}};function Ye(t,e,r,n,i){null!=(e=nr(e,n))&&(r=xe(t,r),i(e,t),Ue(t,r))}var Je,Xe,Qe=new Ke(Ye,Re),Ze=new Ke(Ye,Re),tr=Symbol(),er=Symbol();function rr(t){var e=ir,r=or,n=t[tr];if(n)return n;(n={}).na=t,n.W=function(t){switch(typeof t){case"boolean":return Lt||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Pt||=[0,void 0]:[-t,void 0];case"string":return[0,t];case"object":return t}}(t[0]);var i=t[1],o=1;i&&i.constructor===Object&&(n.ca=i,"function"==typeof(i=t[++o])&&(n.ia=!0,Je??=i,Xe??=t[o+1],i=t[o+=2]));for(var a={};i&&Array.isArray(i)&&i.length&&"number"==typeof i[0]&&i[0]>0;){for(var s=0;s<i.length;s++)a[i[s]]=i;i=t[++o]}for(s=1;void 0!==i;){let h;"number"==typeof i&&(s+=i,i=t[++o]);var l=void 0;if(i instanceof Ke?h=i:(h=Qe,o--),h?.j){i=t[++o],l=t;var u=o;"function"==typeof i&&(i=i(),l[u]=i),l=i}for(u=s+1,"number"==typeof(i=t[++o])&&i<0&&(u-=i,i=t[++o]);s<u;s++){let t=a[s];l?r(n,s,h,l,t):e(n,s,h,t)}}return t[tr]=n}function nr(t,e){return t instanceof qe?t.m:Array.isArray(t)?Vt(t,e[0],e[1]):void 0}function ir(t,e,r){t[e]=r.i}function or(t,e,r,n){var i,o,a=r.i;t[e]=(t,e,r)=>a(t,e,r,o||=rr(n).W,i||=ar(n))}function ar(t){var e=t[er];if(!e){let r=rr(t);e=(t,e)=>sr(t,e,r),t[er]=e}return e}function sr(t,e,r){!function(t,e,r){var n,i=128&e?0:-1,o=t.length;(n=!!o)&&(n=null!=(n=t[o-1])&&"object"==typeof n&&n.constructor===Object);var a=o+(n?-1:0);for(e=128&e?1:0;e<a;e++)r(e-i,t[e]);if(n){t=t[o-1];for(let e in t)!isNaN(e)&&r(+e,t[e])}}(t,0|t[V],(t,n)=>{if(null!=n){var i=function(t,e){var r=t[e];if(r)return r;if((r=t.ca)&&(r=r[e])){var n=(r=Array.isArray(r)?r[0]instanceof Ke?r:[Ze,r]:[r,void 0])[0].i;if(r=r[1]){let e=ar(r),i=rr(r).W;r=t.ia?Xe(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(F,3)}})}var lr,ur=0,hr=ur;if(X(hr)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(hr))throw Error(String(hr))}else if((lr=J(hr))&&(lr=!Number.isSafeInteger(hr)),lr)throw Error(String(hr));function cr(t,e){if(Array.isArray(e)){var r=0|e[V];if(4&r)return e;for(var n=0,i=0;n<e.length;n++){let r=t(e[n]);null!=r&&(e[i++]=r)}return i<n&&(e.length=i),(t=-1537&r|5)!==r&&W(e,t),2&t&&Object.freeze(e),e}}function fr(t,e){return new Ke(t,e)}function dr(t,e,r){null!=(e=Et(e))&&(ke(t,r,5),t=t.i,(r=at||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),lt=0,e=st=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 pr(t,e,r){null!=(e=Ut(e))&&null!=e&&(ke(t,r,0),Pe(t.i,e))}function mr(t,e,r){null!=(e=It(e))&&(ke(t,r,0),t.i.i.push(e?1:0))}function gr(t,e,r){null!=(e=Nt(e))&&Be(t,r,i(e))}function vr(t,e,r,n,i){null!=(e=nr(e,n))&&(r=xe(t,r),i(e,t),Ue(t,r))}function _r(t,e,r){null!=(e=Bt(e))&&null!=e&&(ke(t,r,0),Le(t.i,e))}function yr(t,e,r){null!=(e=Ut(e))&&(e=parseInt(e,10),ke(t,r,0),Pe(t.i,e))}Z||(ur=Q(ur)?ur?"1":"0":X(ur)?ur.trim()||"0":String(ur));var wr,br=fr(dr,We),Sr=fr(dr,We),Er=fr(function(t,e,r){if(e=function(t){if(null==t)return t;var e=typeof t;if("bigint"===e)return String(vt(64,t));if(jt(t)){if("string"===e){if(e=bt(Number(t)),yt(e))t=String(e);else if(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),e=t.length,!("-"===t[0]?e<20||20===e&&t<="-9223372036854775808":e<19||19===e&&t<="9223372036854775807"))if(pt(t),t=st,2147483648&(e=lt))if(j())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{let[r,n]=mt(t,e);t="-"+ft(r,n)}else t=ft(t,e);return t}if("number"===e){if(t=bt(t),!yt(t)){ht(t),e=st;var r=lt;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),t="number"==typeof(e=ct(e,r))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)Ee(e);if(null!=e)switch(ke(t,r,0),typeof e){case"number":t=t.i,ht(e),Te(t,st,lt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Ie(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Te(t.i,r.j,r.i);break;default:r=Ee(e),Te(t.i,r.j,r.i)}}},Ge),Ar=fr(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(jt(t)){if("string"===e)return e=bt(Number(t)),yt(e)&&e>=0?t=String(e):(-1!==(e=t.indexOf("."))&&(t=t.substring(0,e)),(e="-"!==t[0]&&((e=t.length)<20||20===e&&t<="18446744073709551615"))||(pt(t),t=ft(st,lt))),t;if("number"===e)return(t=bt(t))>=0&&yt(t)||(ht(t),t=ct(st,lt)),t}}(e),null!=e){if("string"==typeof e)we(e);if(null!=e)switch(ke(t,r,0),typeof e){case"number":t=t.i,ht(e),Te(t,st,lt);break;case"bigint":r=BigInt.asUintN(64,e),r=new Se(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Te(t.i,r.j,r.i);break;default:r=we(e),Te(t.i,r.j,r.i)}}},ze),Ir=fr(pr,Me);wr=new Ke(function(t,e,r){if(null!=(e=cr(Ut,e))&&e.length){r=xe(t,r);for(let r=0;r<e.length;r++)Pe(t.i,e[r]);Ue(t,r)}},Me);var Tr,Lr=fr(pr,Me),Pr=fr(pr,Me),Or=fr(mr,De),jr=fr(mr,De),kr=fr(gr,Ce);Tr=new Ke(function(t,e,r){if(null!=(e=cr(Nt,e)))for(let s=0;s<e.length;s++){var n=t,o=r,a=e[s];null!=a&&Be(n,o,i(a))}},Ce);var xr,Ur=fr(gr,Ce),Br=fr(gr,Ce),Nr=function(t,e,r=Re){return new Ke(e,r)}(0,function(t,e,r,n,i){if(Array.isArray(e)){for(let o=0;o<e.length;o++)vr(t,e[o],r,n,i);1&(t=0|e[V])||W(e,1|t)}}),Fr=new Ke(vr,Re),Rr=fr(_r,Ve),Dr=fr(yr,$e);xr=new Ke(function(t,e,r){if(null!=(e=cr(Ut,e))&&e.length){r=xe(t,r);for(let r=0;r<e.length;r++)Pe(t.i,e[r]);Ue(t,r)}},$e);var Cr=fr(yr,$e);function Mr(t){return function(){var e=new Ne;sr(this.m,e,rr(t)),je(e,e.i.end());var r=new Uint8Array(e.j),n=e.l,i=n.length,o=0;for(let t=0;t<i;t++){let e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function Vr(t,e){if(null!=e)if(Array.isArray(e))Xt(t,2,Dt(e,0,Ct));else{if(!("string"==typeof e||e instanceof A||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 A(e,b):S();else if(e.constructor!==A){if(!w(e))throw Error();e=e.length?new A(new Uint8Array(e),b):S()}oe(t,2,e,S())}}var Gr,zr=class extends qe{constructor(t){super(t)}},Wr=[0,Ur,fr(function(t,e,r){if(null!=e){if(e instanceof qe){let n=e.qa;return void(n?(e=n(e),null!=e&&Be(t,r,ye(e).buffer)):O(F,3))}if(Array.isArray(e))return void O(F,3)}null!=(e=null==e||"string"==typeof e||e instanceof A?e:void 0)&&Be(t,r,ye(e).buffer)},He)],Hr=globalThis.trustedTypes;var $r=class{constructor(t){this.i=t}toString(){return this.i+""}};function qr(t){var e;return void 0===Gr&&(Gr=function(){var t=null;if(!Hr)return t;try{let e=t=>t;t=Hr.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=Gr)?e.createScriptURL(t):t,new $r(t)}function Kr(t,...e){if(0===e.length)return qr(t[0]);var r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return qr(r)}var Yr={};Yr[336783863]=[0,kr,Or,-1,Ir,[0,[1,2,3,4,5,6,7,8,9],Fr,[0],Fr,[0,Or,kr,Or,Dr,-1,xr,kr,-1,[0,Or,-1],Dr,Or,-1],Fr,[0,kr,-2],Fr,[0,Ir,Or,1,Or,-4],Fr,[0,Ir,Dr,Or,-1,wr,Dr,-1,Or],Fr,[0,kr,-2],Fr,[0,kr,Dr],Fr,[0,3,Or,-1,2,[0,[2],Ir,Fr,[0,fr(_r,Ve)]],[0,Dr,Or,Dr,Or,Dr,Or,kr,-1],[0,[3,4],kr,-1,Fr,[0,Ir],Fr,[0,Dr]],[0]],Fr,[0,Dr,-1,Or]],[0,kr],Or,[0,[1,3],[2,4],Fr,[0,wr],-1,Fr,[0,Tr],-1,Nr,[0,kr,-1]],kr];var Jr=class extends qe{constructor(t){super(t)}},Xr=[0,Er,-1,jr,-3,Er,wr,Ur,Lr,Er,-1,jr,Lr,jr,-2,Ur],Qr=class extends qe{constructor(t){super(t,500)}N(t){return he(this,7,t)}},Zr=[-1,{}],tn=[0,kr,1,Zr],en=[0,kr,Tr,Zr];function rn(t,e){fe(t,1,Qr,e)}var nn=class extends qe{constructor(t){super(t,500)}N(t){return he(this,1001,t)}};nn.prototype.j=Mr([-500,Nr,[-500,Ur,-1,Tr,-3,[-2,Yr,Or],Nr,Wr,Lr,-1,tn,en,Nr,[0,Ur,jr],Ur,Xr,Lr,Tr,987,Tr],4,Nr,[-500,kr,-1,[-1,{}],998,kr],Nr,[-500,kr,Tr,-1,[-2,{},Or],997,Tr,-1],Lr,Nr,[-500,kr,Tr,Zr,998,Tr],Tr,Lr,tn,en,Nr,[0,Ur,-1,Zr],Tr,-2,Xr,Ur,-1,jr,[0,jr,Rr],978,Zr,Nr,Wr]);var on,an=class extends qe{constructor(t){super(t)}},sn=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 ln(t){if(t)return!0;if(void 0===on)try{await WebAssembly.instantiate(sn),on=!0}catch{on=!1}return on}async function un(t,e,r){return{wasmLoaderPath:`${e}/${t}_${r=`wasm${r?"_module":""}${await ln(r)?"":"_nosimd"}_internal`}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var hn=class{};function cn(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},n={cache:[],active:!0},i=Promise.resolve(),o=e(r,n);return r=e(n,r),[o.getReader(),r.getReader()]}async function fn(t,e){for(var r=new Uint8Array(e),n=0;n<e;){let{value:i,done:o}=await t.read();if(i){let 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}hn.forVisionTasks=function(t,e=!1){return un("vision",t??Kr``,e)},hn.forTextTasks=function(t,e=!1){return un("text",t??Kr``,e)},hn.forGenAiTasks=function(t,e=!1){return un("genai",t??Kr``,e)},hn.forAudioTasks=function(t,e=!1){return un("audio",t??Kr``,e)},hn.isSimdSupported=function(t=!1){return ln(t)};var dn=[[0,async t=>{var e=(new TextEncoder).encode("TFL3").length;return t=await fn(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await fn(t,6))[4]&&75===t[5]]];function pn(){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 mn(t){if("function"!=typeof importScripts){let 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)})}try{importScripts(t.toString())}catch(e){if(!(e instanceof TypeError))throw e;{let e=self.import;e?await e(t.toString()):await import(t.toString())}}}function gn(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 vn(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");var 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(let e of n)t.h._free(e);t.h._free(e)}function _n(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function yn(t,e,r){var n=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,i)=>{e?(r(n,i),n=[]):n.push(t)}}var wn,bn=(wn=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:pn()?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){var 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){var 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?'),gn(this,n||"input_audio",n=>{gn(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){var 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),gn(this,n,t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)})}addGpuBufferToStream(t,e,r){gn(this,e,e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();var 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);var[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);var[a,s]=[i,o];this.h._addBoundTextureToStream(e,a,s,r)})}addBoolToStream(t,e,r){gn(this,e,e=>{this.h._addBoolToInputStream(t,e,r)})}addDoubleToStream(t,e,r){gn(this,e,e=>{this.h._addDoubleToInputStream(t,e,r)})}addFloatToStream(t,e,r){gn(this,e,e=>{this.h._addFloatToInputStream(t,e,r)})}addIntToStream(t,e,r){gn(this,e,e=>{this.h._addIntToInputStream(t,e,r)})}addUintToStream(t,e,r){gn(this,e,e=>{this.h._addUintToInputStream(t,e,r)})}addStringToStream(t,e,r){gn(this,e,e=>{gn(this,t,t=>{this.h._addStringToInputStream(t,e,r)})})}addStringRecordToStream(t,e,r){gn(this,e,e=>{vn(this,Object.keys(t),n=>{vn(this,Object.values(t),i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)})})})}addProtoToStream(t,e,r,n){gn(this,r,r=>{gn(this,e,e=>{var 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){gn(this,t,t=>{this.h._addEmptyPacketToInputStream(t,e)})}addBoolVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateBoolVector(t.length);if(!n)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(n,e);this.h._addBoolVectorToInputStream(n,e,r)})}addDoubleVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateDoubleVector(t.length);if(!n)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(n,e);this.h._addDoubleVectorToInputStream(n,e,r)})}addFloatVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateFloatVector(t.length);if(!n)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(n,e);this.h._addFloatVectorToInputStream(n,e,r)})}addIntVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateIntVector(t.length);if(!n)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(n,e);this.h._addIntVectorToInputStream(n,e,r)})}addUintVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateUintVector(t.length);if(!n)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(n,e);this.h._addUintVectorToInputStream(n,e,r)})}addStringVectorToStream(t,e,r){gn(this,e,e=>{var n=this.h._allocateStringVector(t.length);if(!n)throw Error("Unable to allocate new string vector on heap.");for(let e of t)gn(this,e,t=>{this.h._addStringVectorEntry(n,t)});this.h._addStringVectorToInputStream(n,e,r)})}addBoolToInputSidePacket(t,e){gn(this,e,e=>{this.h._addBoolToInputSidePacket(t,e)})}addDoubleToInputSidePacket(t,e){gn(this,e,e=>{this.h._addDoubleToInputSidePacket(t,e)})}addFloatToInputSidePacket(t,e){gn(this,e,e=>{this.h._addFloatToInputSidePacket(t,e)})}addIntToInputSidePacket(t,e){gn(this,e,e=>{this.h._addIntToInputSidePacket(t,e)})}addUintToInputSidePacket(t,e){gn(this,e,e=>{this.h._addUintToInputSidePacket(t,e)})}addStringToInputSidePacket(t,e){gn(this,e,e=>{gn(this,t,t=>{this.h._addStringToInputSidePacket(t,e)})})}addProtoToInputSidePacket(t,e,r){gn(this,r,r=>{gn(this,e,e=>{var 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){gn(this,e,e=>{var r=this.h._allocateBoolVector(t.length);if(!r)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(r,e);this.h._addBoolVectorToInputSidePacket(r,e)})}addDoubleVectorToInputSidePacket(t,e){gn(this,e,e=>{var r=this.h._allocateDoubleVector(t.length);if(!r)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(r,e);this.h._addDoubleVectorToInputSidePacket(r,e)})}addFloatVectorToInputSidePacket(t,e){gn(this,e,e=>{var r=this.h._allocateFloatVector(t.length);if(!r)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(r,e);this.h._addFloatVectorToInputSidePacket(r,e)})}addIntVectorToInputSidePacket(t,e){gn(this,e,e=>{var r=this.h._allocateIntVector(t.length);if(!r)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(r,e);this.h._addIntVectorToInputSidePacket(r,e)})}addUintVectorToInputSidePacket(t,e){gn(this,e,e=>{var r=this.h._allocateUintVector(t.length);if(!r)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(r,e);this.h._addUintVectorToInputSidePacket(r,e)})}addStringVectorToInputSidePacket(t,e){gn(this,e,e=>{var r=this.h._allocateStringVector(t.length);if(!r)throw Error("Unable to allocate new string vector on heap.");for(let e of t)gn(this,e,t=>{this.h._addStringVectorEntry(r,t)});this.h._addStringVectorToInputSidePacket(r,e)})}attachBoolListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachBoolListener(t)})}attachBoolVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachBoolVectorListener(t)})}attachIntListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachIntListener(t)})}attachIntVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachIntVectorListener(t)})}attachUintListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachUintListener(t)})}attachUintVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachUintVectorListener(t)})}attachDoubleListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachDoubleListener(t)})}attachDoubleVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachDoubleVectorListener(t)})}attachFloatListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachFloatListener(t)})}attachFloatVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachFloatVectorListener(t)})}attachStringListener(t,e){_n(this,t,e),gn(this,t,t=>{this.h._attachStringListener(t)})}attachStringVectorListener(t,e){yn(this,t,e),gn(this,t,t=>{this.h._attachStringVectorListener(t)})}attachProtoListener(t,e,r){_n(this,t,e),gn(this,t,t=>{this.h._attachProtoListener(t,r||!1)})}attachProtoVectorListener(t,e,r){yn(this,t,e),gn(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?'),_n(this,t,(t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)}),gn(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 wn{ka(){this.h._registerModelResourcesGraphService()}});async function Sn(t,e){var r=await(async(t,e,r)=>{var n=li;if(t&&await mn(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await mn(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 En(t,e){return Sn(t,e)}function An(t){try{let 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 In(t,e){t.I=Math.max(t.I,e)}var Tn=class{constructor(t){this.j=t,this.J=[],this.I=0,this.j.setAutoRenderToScreen(!1)}setGraph(t,e){this.j.attachErrorListener((t,e)=>{this.J.push(Error(e))}),this.j.ka(),this.j.setGraph(t,e),An(this)}finishProcessing(){this.j.finishProcessing(),An(this)}close(){this.j.closeGraph()}};Tn.prototype.close=Tn.prototype.close;var Ln=class extends qe{constructor(t){super(t)}j(){return Ut(Yt(this,2))??0}};function Pn(t,e){he(t,1,e)}var On=class extends qe{constructor(t){super(t)}},jn=[0,Cr,Lr,Sr,-1,Ir];function kn(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(let[n,i]of t.i){let t=i;(r=n)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),i}}Ln.prototype.l=Mr(jn);class xn{constructor(t){this.i=[],this.data=t,this.length=t.length}}function Un(t,e){return new Nn(async()=>{var{value:e,done:r}=await t.read();return r?void 0:e},e)}async function Bn(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 xn(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;var a=0;for(let s=0;s<t.i.length;s++){let l=t.i[s];if(r>=l.length){r-=l.length;continue}let u=Math.min(n,l.length-r);if(void 0===(r=kn(l,r,u,i)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+a),r=0,a+=u,0===(n-=u))break}if(0!==n)throw Error("Data not found.");return Promise.resolve(o)}var Nn=class{constructor(t,e){this.i=[],this.j=t,this.l=e}get size(){var t=0;for(let e=0;e<this.i.length;e++)t+=this.i[e].length;return t}};function Fn(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function Rn(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function Dn(t,e,r){t=new Mn(t,r);var n=0;for(e=e.getReader();;){let{value:r,done:i}=await e.read();if(i)break;t.set(r,n),n+=r.byteLength}if(r!==n)throw Cn(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${r} bytes before failure`);return t}function Cn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Mn=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))}},Vn=class extends qe{constructor(t){super(t)}};Vn.prototype.j=Mr([0,Ur,2,Tr,Lr,jr]);var Gn=class extends qe{constructor(t){super(t)}},zn=class extends qe{constructor(t){super(t)}},Wn=class extends qe{constructor(t){super(t)}},Hn=class extends qe{constructor(t){super(t)}},$n=[0,Lr,-6,1,Lr,1,[0,jr,Cr,-2],[0,jr,Sr],Cr,-2,[0,jr,-1,Cr,Sr,Dr,Ir,Or,-1],1,jr,Lr,Ir,-1,[0,Cr,Lr],jr,-1,br,Lr,-5,br,-1,[0,Ir,br],Ir,Or,[0,Ir,-2],br,[0,Lr],[0,Lr,-4],Or,Ir,-2,Or,-1,Sr,br,Or,Lr,-1,[0,Ir,-2],jr,Lr,Ir,Or],qn=[0,Ur,-2],Kn=[0,[4,6],$n,Lr,1,Pr,Tr,Br,xr,qn,Ir,[0,[0,Lr,-1,Nr,[0,Lr,[0,Lr,-1],-1,[0,Cr,-1],jr],jr,-2,Lr,-1],[0,Lr,-1,jr],$n,jr,Lr,[0,Lr],-1],kr,-3,[0,Lr,jr],$n,[0,qn,-2],wr];Hn.prototype.j=Mr([0,Ur,8,[0,jr,-6],1,Lr,1,Lr,[0,Nr,[0,Ur,Ar,-1,Cr],Kn,Lr],[0,Lr,jr,-3],1,Cr,1,Kn,1,Lr,5,Cr,wr,1,jn,jr,Lr,jr]);var Yn=class extends qe{constructor(t){super(t)}},Jn=class extends qe{constructor(t){super(t)}},Xn=[2,4];Jn.prototype.j=Mr([0,Xn,Lr,Br,Lr,Fr,[0,1,Ur]]);var Qn=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{let r=Un(t,()=>{});await this.h.createLlmInferenceEngine(de(e,2)??512,le(e,Ln,3)?.j()??40,It(Yt(e,6))??!1??!1,de(e,7)??0,It(Yt(e,8))??!1??!1,(t,e,n)=>Bn(r,this.h,t,e,n))}finally{this.L()}}async ba(t,e){this.M();try{await this.ma(t),await this.h.ccall("CreateLlmInferenceEngineConverted","void",["number","number","boolean"],[de(e,2)??512,le(e,Ln,3)?.j()??40,It(Yt(e,6))??!1??!1],{async:!0})}finally{this.L()}}V(){this.M();try{let 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{let n=[],i=this.h;i._userProgressListener=(t,e)=>{t&&n.push(t),r&&r(t,e)};let o=e.l(),a=o.length,s=this.h._malloc(a);this.h.HEAPU8.set(o,s);let l=t.some(Rn),u=t.some(Fn);i.ccallNum=i.ccall;let h=await i.ccallNum("MakeSessionForPredict","number",["number","number","boolean","boolean"],[s,a,u,l],{async:!0});e=[];for(let r of t)if("string"==typeof r)gn(this,r,t=>{i._AddTextQueryChunk(h,t)});else if(Fn(r)){let{image:t,width:n,height:o}=await this.fa(r.imageSource),a="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(n,o):document.createElement("canvas");a.width=n,a.height=o;let s=a.getContext("2d");s.drawImage(t,0,0);let l=s.getImageData(0,0,n,o),u=this.h._malloc(l.width*l.height*4);this.h.HEAPU8.set(l.data,u),i._AddImageQueryChunk(h,u,l.width,l.height),e.push(u)}else{if(!Rn(r))throw Error("Unsupported PromptPart type in query.");{let t=await this.ea(r.audioSource),n=this.h._malloc(t.audioSamples.byteLength);this.h.HEAPF32.set(t.audioSamples,n/4),i._AddAudioQueryChunk(h,t.audioSampleRateHz,n,t.audioSamples.length),e.push(n)}}await i.ccall("PredictSession","void",["number"],[h],{async:!0}),t=!0,u&&0===this.F&&(this.F=h,t=!1),l&&0===this.H&&(this.H=h,t=!1),t&&i._FreeSession(h);for(let t of e)this.h._free(t);return e.length=0,r&&r("",!0),this.h._free(s),i._userProgressListener=void 0,n.join("")}finally{this.L()}}S(t){this.M();var e=0,r="";for(let n of t)"string"==typeof n?r+=n:Fn(n)?e+=260:Rn(n)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return gn(this,r,e=>{t=this.h._GetSizeInTokens(e)}),e+t}finally{this.L()}}async ma(t){t=await async function(t){for(var e=[],r=0;;){let{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(let 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 fa(t){if("string"==typeof t){let e=new Image;e.src=t,e.crossOrigin="Anonymous";try{await e.decode()}catch{throw Error(`Image from URL ${t} failed to load`)}return{image:e,width:e.naturalWidth,height:e.naturalHeight}}if(t instanceof HTMLImageElement){try{await t.decode()}catch{throw Error("Image from HTMLImageElement failed to load")}return{image:t,width:t.naturalWidth,height:t.naturalHeight}}return t instanceof HTMLVideoElement?{image:t,width:t.videoWidth,height:t.videoHeight}:t instanceof VideoFrame?{image:t,width:t.displayWidth,height:t.displayHeight}:{image:t,width:t.width,height:t.height}}async ea(t){if("string"==typeof t){let 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){var e=class extends t{static async la(t,r){r||=await e.X();var n=[];for(let e of t?.requiredFeatures??[])r.features.has(e)?n.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:n};try{var i=await r.requestDevice(t)}catch(t){throw console.error("Unable to initialize WebGPU with the requested features."),t}return(t=i).adapterInfo||(t.adapterInfo=r.info),i}static async X(t){if(!(t=await navigator.gpu.requestAdapter(t)))throw Error("Unable to request adapter from navigator.gpu; Ensure WebGPU is enabled.");return t}ga(t){if(e)"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.id="canvas_webgpu");else var e=new OffscreenCanvas(1,1);e.getContext("webgpu").configure({device:t,format:navigator.gpu.getPreferredCanvasFormat()}),this.h.preinitializedWebGPUDevice=t}aa(){return this.h.ccall("closeGraph","void",[],[],{async:!0})}};return e}(function(t){return class extends t{addStreamingReaderToInputSidePacket(t,e){this.h.addStreamingReaderToInputSidePacket((e,r,n)=>Bn(t,this.h,e,r,n),e)}}}(function(t){return class extends t{Y(t,e){gn(this,"lora_model_ref_in",r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)})}}}(class extends bn{}))));class Zn extends Qn{}var ti=class{constructor(t){this.j=t,this.i=ei,ei++}},ei=1;class ri{constructor(){var t,e;this.promise=new Promise((r,n)=>{t=r,e=n}),this.resolve=t,this.reject=e}}function ni(t){return 1===t?1:t+t%2}async function ii(){var t=await Zn.X({powerPreference:"high-performance"}),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."),e.requiredFeatures=["shader-f16","subgroups"]),Zn.la(e,t)}function oi(t){if(t.D.length>0){let e=[...t.D];if(t.D.length=0,!t.o)throw e;t.o.reject(e),t.o=void 0}}function ai(t){var e=function(t){var e=new nn;ve(e,10,"text_in"),ve(e,10,"token_cost_in"),ve(e,10,"lora_model_id_to_apply_in"),ve(e,10,"lora_model_ref_in"),ve(e,10,"lora_model_id_to_load_in"),ve(e,16,"streaming_reader"),ve(e,15,"text_out"),ve(e,15,"text_end"),ve(e,15,"token_cost_out");var r=new Qr;ge(r,2,"TokenizerInputBuildCalculator"),ve(r,3,"PROMPT:text_in"),ve(r,3,"LORA_ID:lora_model_id_to_apply_in"),ve(r,4,"prompt"),rn(e,r),r=new Qr,ge(r,2,"ModelDataCalculator"),ve(r,6,"MODEL_DATA:__side_packet_1"),ve(r,6,"MODEL_TYPE:model_type"),ve(r,5,"READ_DATA_FN:streaming_reader"),ve(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),ve(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),ve(r,4,"LORA_DATA:lora_model_data"),rn(e,r),r=new Qr,ge(r,2,"Gpt2UnicodeMappingCalculator"),ve(r,5,"MODEL_TYPE:model_type"),ve(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),rn(e,r),r=new zr,ge(r,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new Jn,i=de(t.i,2);pe(n,1,i),ge(i=new Yn,2,"spm_vocab_model"),i=ue(i);t:{$t(n);var o=n.m,a=0|o[V];if(null==i){var s=ae(o);if(4!==se(s,o,a))break t;s.set(Xn,0)}else{let t=ae(s=o),e=se(t,s,a);4!==e&&(e&&(a=Qt(s,a,e)),t.set(Xn,4))}Qt(o,a,4,i)}return i&&!$(i)&&qt(n.m),pe(n,3,2),Vr(r,n.j()),ge(n=new Qr,2,"TokenizerCalculator"),fe(n,8,zr,r),ve(n,5,"MODEL_DATA:__side_packet_1"),ve(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),ve(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ve(n,6,"PROCESSOR_GETTER:__input_side_1"),ve(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),rn(e,n),r=new zr,ge(r,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),pe(n=new Hn,12,3),ge(n,1,"llm.tflite"),pe(n,14,0),i=ni(de(t.i,5)),pe(n,22,i),i=le(t.i,Ln,3),he(n,31,i),oe(i=new Gn,1,At(!0),!1),null!=It(Yt(t.i,6))&&(It(Yt(t.i,6))??!1)&&oe(i,1,At(!1),!1),oe(i,2,At(!0),!1),oe(i,5,At(!0),!1),he(n,10,i),i=Zt(t.i,4,Ut,void 0===K?2:4),ie(n,29,i),i=new Wn,pe(o=new zn,1,1),s=de(t.i,2),pe(o,2,s),he(i,1,o),he(n,20,i),Vr(r,n.j()),ge(n=new Qr,2,"LlmGpuCalculator"),fe(n,8,zr,r),ve(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),ve(n,3,"FINISH:finish"),ve(n,3,"LORA_DATA:lora_model_data"),ve(n,5,"MODEL_DATA:__side_packet_1"),ve(n,4,"DECODED_IDS:__stream_3"),ve(n,4,"OUTPUT_END:__stream_4"),r=new Jr,ge(r,1,"FINISH"),oe(r,2,At(!0),!1),fe(n,13,Jr,r),rn(e,n),r=new Qr,ge(r,2,"IsPacketPresentCalculator"),ve(r,3,"__stream_4"),ve(r,4,"text_end"),rn(e,r),r=new zr,ge(r,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new Vn,t=ni(de(t.i,5)),pe(n,5,t),ve(n,4,"<eos>"),ve(n,4,"<|endoftext|>"),Vr(r,n.j()),t=new Qr,ge(t,2,"DetokenizerCalculator"),fe(t,8,zr,r),ve(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),ve(t,5,"PROCESSOR_GETTER:__input_side_1"),ve(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ve(t,5,"MODEL_DATA:__side_packet_1"),ve(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),ve(t,4,"WORDS:text_out"),rn(e,t),t=new Qr,ge(t,2,"TokenCostCalculator"),ve(t,3,"PROMPT:token_cost_in"),ve(t,5,"PROCESSOR_GETTER:__input_side_1"),ve(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),ve(t,4,"NUM_TOKENS:token_cost_out"),rn(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<de(t.i,5)&&t.G[r].push(e)}),t.A&&0===t.D.length&&(t.B?(e.length>de(t.i,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),In(t,r)}),t.j.attachEmptyPacketListener("text_out",e=>{In(t,e)}),t.j.attachBoolListener("text_end",(e,r)=>{In(t,r);try{oi(t)}catch(e){throw t.l=!1,e}if(t.o&&(t.o.resolve(t.G.map(t=>t.join(""))),t.o=void 0),t.A)if(t.B){for(e=[],r=0;r<de(t.i,5);r++)e.push("");t.A(e,!0)}else t.A("",!0);t.l=!1,t.B=void 0}),t.j.attachEmptyPacketListener("text_end",e=>{t.l=!1,t.B=void 0,In(t,e),oi(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,In(t,r)}),t.U&&t.j.addStreamingReaderToInputSidePacket(t.U,"streaming_reader");var r=e.j();return t.C?.removeEventListener("uncapturederror",t.K),t.j.aa().then(()=>{t.C?.addEventListener("uncapturederror",t.K),t.D.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()})}function si(t,e,r,n){if(t.A="function"==typeof r?r:n,(n=(e=Array.isArray(e)?e:[e]).filter(t=>Fn(t)).length)>0&&(null==Bt(Yt(t.i,7))||de(t.i,7)<n))throw Error(`maxNumImages is set to ${null!=Bt(Yt(t.i,7))?de(t.i,7):0}, but the query included ${n} images.`);if((n=e.filter(t=>Rn(t)).length)>0&&(null==It(Yt(t.i,8))||!It(Yt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${n} audio chunks.`);if(t.v){if(t.B&&de(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 ti)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the .bin format without multimodality to use LoRA.");return t.j.h.LLM_CANCEL_FLAG=void 0,t.j.R(e,t.u,(e,r)=>{0===t.D.length&&t.A&&(t.B?t.A([e],r):t.A(e,r))}).then(e=>(oi(t),[e]))}if(t.l)throw Error("Previous invocation or loading is still ongoing.");for(t.l=!0,t.j.h.LLM_CANCEL_FLAG=void 0,t.G.length=0,n=0;n<de(t.i,5);n++)t.G[n]=[];if(n=t.I+1,t.j.addStringToStream(e.join(""),"text_in",n),r instanceof ti){if(r.j!==t)throw t.l=!1,t.B=void 0,Error("The LoRA model was not loaded by this LLM Inference task.");t.j.addUintToStream(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 ri,t.o.promise}var li=class extends Tn{constructor(t,e){if(super(new Zn(t,e)),this.G=[],this.O=this.v=this.l=!1,this.D=[],this.K=t=>{if((t=t.error).message.match(/exceeds the max buffer size limit/))throw Error(`Failed to run this LLM model because it requires a buffer size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);if(t.message.match(/is larger than the maximum storage buffer binding size/))throw Error(`Failed to run this LLM model because it requires a storage buffer binding size that exceeds the maximum size your device supports, but you could try a smaller LLM model or different device.\nWebGPU throws: "${t.message}"`);this.D.push(t)},this.i=new On,Pn(this.i,new an),this.u=new Ln,he(this.i,3,this.u),me(this.i,2,512),t=this.u,!wt(2))throw P("enum");oe(t,1,2,0),pe(this.u,2,40),oe(this.u,3,St(1),0),Xt(this.u,5,xt(0)),oe(this.u,4,St(.8),0),me(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");var e,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.");{let[r,a]=cn(n);this.O=1===await async function(t){var e,r=[];for(let[i,o]of dn){let a=i;var n=o;[t,e]=cn(t),n=await n(e),await e.cancel(),n&&r.push(a)}if(await t.cancel(),0===r.length)throw Error("No model format matched.");if(1===r.length)return r[0];throw Error(`Multiple model formats matched: ${r}`)}(a);var i="maxNumImages"in t&&t.maxNumImages?t.maxNumImages:0;me(this.i,7,i);var o="supportAudio"in t&&!!t.supportAudio;Xt(this.i,8,At(o)),this.O||i>0||o?(this.v=!0,n=r):(this.v=!1,this.U=Un(r,e))}if(t.baseOptions?.gpuOptions?.device&&(this.C&&this.C.removeEventListener("uncapturederror",this.K),this.C=t.baseOptions.gpuOptions.device,this.j.ga(this.C),this.C.addEventListener("uncapturederror",this.K)),"maxTokens"in t&&me(this.i,2,t.maxTokens??512),"topK"in t&&pe(this.u,2,t.topK??40),"temperature"in t&&oe(this.u,4,St(t.temperature??.8),0),"randomSeed"in t&&Xt(this.u,5,xt(t.randomSeed??0)),"loraRanks"in t&&function(t,e){ie(t,4,e)}(this.i,t.loraRanks??[]),"numResponses"in t){if((i=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&i>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet, and is also not supported with multimodality.");me(this.i,5,i),o=le(this.i,Ln,3),i>1&&o&&(o.j()<=1||(Yt(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&&Xt(this.i,6,At(t.forceF32)),this.v?(this.j.V(),this.O?this.j.ba(n,this.i).then(()=>{oi(this)}):this.j.createLlmInferenceEngine(n,this.i).then(()=>{oi(this)})):(this.l=!0,t=ai(this).then(()=>{}),Promise.all([r,t]).then(()=>{this.l=!1,oi(this)}))}get baseOptions(){return le(this.i,an,1)}set baseOptions(t){Pn(this.i,t)}get isIdle(){return!this.l&&!this.o}R(t,e,r){return de(this.i,5)>1&&console.warn("'numResponses' is set larger than 1 and this function only returns the first response, so we recommend either using 'generateResponses()' to obtain multiple responses, or else setting 'numResponses' to 1 for better performance."),this.B=!1,si(this,t,e,r).then(t=>t[0])}da(t,e,r){return this.B=!0,si(this,t,e,r)}S(t){if(t=Array.isArray(t)?t:[t],this.v)return this.j.S(t);if(this.l)throw Error("Previous invocation or loading is still ongoing.");if(t.some(Fn))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(Rn))throw Error("sizeInTokens requires supportAudio for audio.");return t=t.join(""),this.l=!0,this.T=void 0,this.j.addStringToStream(t,"token_cost_in",this.I+1),this.finishProcessing(),this.l=!1,this.T}Z(){var t=this.j.h;(this.v||this.l)&&(t.LLM_CANCEL_FLAG=1)}async ja(t){if(this.v)throw Error("LoRA is not supported for converted LLM models (.task format) yet, nor is it supported for multimodality. Please use the old format (.bin) without multimodality to use LoRA.");if(this.l)throw Error("Cannot load LoRA model while loading or processing.");if(this.l=!0,t instanceof Uint8Array){var e=new Mn(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return Dn(t,e.stream(),e.size)}(this.j.h,t):await async function(t,e){e=await fetch(e.toString());var 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 Dn(t,e.body,r)}(this.j.h,t);e=new ti(this);var r=this.I+1;return this.j.Y(t,r),this.j.addUintToStream(e.i,"lora_model_id_to_load_in",r),this.finishProcessing(),Cn(t),In(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};li.prototype.loadLoraModel=li.prototype.ja,li.prototype.cancelProcessing=li.prototype.Z,li.prototype.sizeInTokens=li.prototype.S,li.prototype.generateResponses=li.prototype.da,li.prototype.generateResponse=li.prototype.R,li.prototype.setOptions=li.prototype.N,li.createWebGpuDevice=ii,li.createFromModelPath=async function(t,e){return En(t,e={baseOptions:{gpuOptions:{device:await ii()},modelAssetPath:e}})},li.createFromModelBuffer=async function(t,e){return En(t,e={baseOptions:{gpuOptions:{device:await ii()},modelAssetBuffer:e}})},li.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){let t=await ii();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return En(t,e)},exports.FilesetResolver=hn,exports.LlmInference=li,exports.TaskRunner=Tn;
2
2
  //# sourceMappingURL=genai_bundle_cjs.js.map