@mediapipe/tasks-genai 0.10.27 → 0.10.29
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 +4 -2
- package/genai.d.ts +16 -4
- package/genai_bundle.cjs +1 -1
- package/genai_bundle.cjs.map +1 -1
- package/genai_bundle.js +2 -0
- package/genai_bundle.mjs +1 -1
- package/genai_bundle.mjs.map +1 -1
- package/package.json +2 -1
- package/wasm/genai_wasm_internal.js +661 -557
- package/wasm/genai_wasm_internal.wasm +0 -0
- package/wasm/genai_wasm_module_internal.js +664 -560
- package/wasm/genai_wasm_module_internal.wasm +0 -0
- package/wasm/genai_wasm_nosimd_internal.js +660 -556
- package/wasm/genai_wasm_nosimd_internal.wasm +0 -0
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ 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 one of
|
|
10
|
+
In order to begin, you must have a model available. You can download one of
|
|
11
|
+
these:
|
|
11
12
|
|
|
12
13
|
- [Gemma 4 E2B](https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/blob/main/gemma-4-E2B-it-web.task)
|
|
13
14
|
- [Gemma 4 E4B](https://huggingface.co/litert-community/gemma-4-E4B-it-litert-lm/blob/main/gemma-4-E4B-it-web.task)
|
|
@@ -15,7 +16,7 @@ In order to begin, you must have a model available. You can download one of thes
|
|
|
15
16
|
E2B](https://huggingface.co/google/gemma-3n-E2B-it-litert-lm/blob/main/gemma-3n-E2B-it-int4-Web.litertlm)
|
|
16
17
|
- [Gemma 3n E4B](https://huggingface.co/google/gemma-3n-E4B-it-litert-lm/blob/main/gemma-3n-E4B-it-int4-Web.litertlm)
|
|
17
18
|
|
|
18
|
-
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
|
|
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" (and sometimes "-web.litertlm") are
|
|
19
20
|
specially converted to run optimally in the browser. All text-only variants of
|
|
20
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
|
|
21
22
|
our web inference [guide](https://developers.google.com/mediapipe/solutions/genai/llm_inference/web_js) for more information.
|
|
@@ -28,3 +29,4 @@ const genai = await FilesetResolver.forGenAiTasks(
|
|
|
28
29
|
const llmInference = await LlmInference.createFromModelPath(genai, MODEL_URL);
|
|
29
30
|
const response = await llmInference.generateResponse(inputText);
|
|
30
31
|
```
|
|
32
|
+
|
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
|
|
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.
|
|
@@ -133,7 +133,7 @@ declare type ImageSource = Exclude<CanvasImageSource, SVGElement> | string;
|
|
|
133
133
|
/**
|
|
134
134
|
* Options to configure the model loading and processing for LLM Inference task.
|
|
135
135
|
*/
|
|
136
|
-
export declare interface LlmBaseOptions extends
|
|
136
|
+
export declare interface LlmBaseOptions extends BaseOptions {
|
|
137
137
|
gpuOptions?: WebGpuOptions;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -352,6 +352,10 @@ declare class LlmInferenceGraphOptions extends jspb.Message {
|
|
|
352
352
|
clearSupportAudio(): void;
|
|
353
353
|
getSupportAudio(): boolean;
|
|
354
354
|
setSupportAudio(value: boolean): void;
|
|
355
|
+
hasDisableRewinding(): boolean;
|
|
356
|
+
clearDisableRewinding(): void;
|
|
357
|
+
getDisableRewinding(): boolean;
|
|
358
|
+
setDisableRewinding(value: boolean): void;
|
|
355
359
|
serializeBinary(): Uint8Array;
|
|
356
360
|
toObject(includeInstance?: boolean): LlmInferenceGraphOptions.AsObject;
|
|
357
361
|
static toObject(includeInstance: boolean, msg: LlmInferenceGraphOptions): LlmInferenceGraphOptions.AsObject;
|
|
@@ -376,6 +380,7 @@ declare namespace LlmInferenceGraphOptions {
|
|
|
376
380
|
forceF32: boolean;
|
|
377
381
|
maxNumImages: number;
|
|
378
382
|
supportAudio: boolean;
|
|
383
|
+
disableRewinding: boolean;
|
|
379
384
|
};
|
|
380
385
|
}
|
|
381
386
|
|
|
@@ -431,6 +436,12 @@ export declare interface LlmInferenceOptions extends TaskRunnerOptions {
|
|
|
431
436
|
* streaming loading, and therefore is not compatible with "converted" models.
|
|
432
437
|
*/
|
|
433
438
|
supportAudio?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* When set to true, will disable optimizations for fast rewinding, but will
|
|
441
|
+
* consequently use much less memory for long contexts. Default is false, to
|
|
442
|
+
* allow for fast rewinding and shared prefix reuse.
|
|
443
|
+
*/
|
|
444
|
+
disableRewinding?: boolean;
|
|
434
445
|
}
|
|
435
446
|
|
|
436
447
|
/**
|
|
@@ -443,7 +454,7 @@ export declare class LoraModel {
|
|
|
443
454
|
}
|
|
444
455
|
|
|
445
456
|
declare namespace mediapipe_tasks_cc_core_proto_base_options_pb {
|
|
446
|
-
export { BaseOptions };
|
|
457
|
+
export { BaseOptions_2 as BaseOptions };
|
|
447
458
|
}
|
|
448
459
|
|
|
449
460
|
declare namespace mediapipe_tasks_web_genai_llm_inference_proto_sampler_params_pb {
|
|
@@ -477,6 +488,7 @@ declare abstract class TaskRunner {
|
|
|
477
488
|
protected constructor();
|
|
478
489
|
/** Configures the task with custom options. */
|
|
479
490
|
abstract setOptions(options: TaskRunnerOptions): Promise<void>;
|
|
491
|
+
enableLogging(taskName: string, options: TaskRunnerOptions): void;
|
|
480
492
|
/**
|
|
481
493
|
* Closes and cleans up the resources held by this task.
|
|
482
494
|
* @export
|
|
@@ -487,7 +499,7 @@ declare abstract class TaskRunner {
|
|
|
487
499
|
/** Options to configure MediaPipe Tasks in general. */
|
|
488
500
|
declare interface TaskRunnerOptions {
|
|
489
501
|
/** Options to configure the loading of the model assets. */
|
|
490
|
-
baseOptions?:
|
|
502
|
+
baseOptions?: BaseOptions;
|
|
491
503
|
}
|
|
492
504
|
|
|
493
505
|
/**
|
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);function u(){var e=t.navigator;return e&&(e=e.userAgent)?e:""}const c=t.navigator;o=c&&c.userAgentData||null;const l={};let h=null;function f(t){const e=t.length;let r=3*e/4;r%3?r=Math.floor(r):-1!="=.".indexOf(t[e-1])&&(r=-1!="=.".indexOf(t[e-2])?r-2:r-1);const n=new Uint8Array(r);let i=0;return function(t,e){function r(e){for(;n<t.length;){const e=t.charAt(n++),r=h[e];if(null!=r)return r;if(!/^[\s\xa0]*$/.test(e))throw Error("Unknown base64 encoding at char: "+e)}return e}d();let n=0;for(;;){const t=r(-1),n=r(0),i=r(64),o=r(64);if(64===o&&-1===t)break;e(t<<2|n>>4),64!=i&&(e(n<<4&240|i>>2),64!=o&&e(i<<6&192|o))}}(t,(function(t){n[i++]=t})),i!==r?n.subarray(0,i):n}function d(){if(!h){h={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){const n=t.concat(e[r].split(""));l[r]=n;for(let t=0;t<n.length;t++){const e=n[t];void 0===h[e]&&(h[e]=t)}}}}var p="undefined"!=typeof Uint8Array,m=!(!(s&&o&&o.brands.length>0)&&(-1!=u().indexOf("Trident")||-1!=u().indexOf("MSIE")))&&"function"==typeof btoa;const g=/[-_.]/g,_={"-":"+",_:"/",".":"="};function y(t){return _[t]||""}function w(t){if(!m)return f(t);t=g.test(t)?t.replace(g,y):t,t=atob(t);const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}function v(t){return p&&null!=t&&t instanceof Uint8Array}var b={};function S(){return A||=new E(null,b)}var E=class{constructor(t,e){if(T(e),this.i=t,null!=t&&0===t.length)throw Error("ByteString should be constructed with non-empty values")}};let A,I;function T(t){if(t!==b)throw Error("illegal external caller")}function L(t,e){t.__closure__error__context__984382||(t.__closure__error__context__984382={}),t.__closure__error__context__984382.severity=e}function P(t){return L(t=Error(t),"warning"),t}function O(e,r){if(null!=e){var n=I??={},i=n[e]||0;i>=r||(n[e]=i+1,L(e=Error(),"incident"),function(e){t.setTimeout((()=>{throw e}),0)}(e))}}function j(){return"function"==typeof BigInt}var x="function"==typeof Symbol&&"symbol"==typeof Symbol();function k(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=k("jas",void 0,!0),B=k(void 0,"1oa"),N=k(void 0,"0ubsb"),F=k(void 0,"0actk"),R=k("m_m","pa",!0);const D={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},M=Object.defineProperties,C=x?U:"ha";var V;const G=[];function z(t,e){x||C in t||M(t,D),t[C]|=e}function W(t,e){x||C in t||M(t,D),t[C]=e}W(G,7),V=Object.freeze(G);var H={};function $(t,e){return void 0===e?t.i!==q&&!!(2&(0|t.m[C])):!!(2&e)&&t.i!==q}const q={};var 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)));const et=Number.MIN_SAFE_INTEGER.toString(),rt=Z?BigInt(Number.MIN_SAFE_INTEGER):void 0,nt=Number.MAX_SAFE_INTEGER.toString(),it=Z?BigInt(Number.MAX_SAFE_INTEGER):void 0;function ot(t,e){if(t.length>e.length)return!1;if(t.length<e.length||t===e)return!0;for(let r=0;r<t.length;r++){const n=t[r],i=e[r];if(n>i)return!1;if(n<i)return!0}}let st,at=0,ut=0;function ct(t){const e=t>>>0;at=e,ut=(t-e)/4294967296>>>0}function lt(t){if(t<0){ct(-t);const[e,r]=mt(at,ut);at=e>>>0,ut=r>>>0}else ct(t)}function ht(t,e){const r=4294967296*e+(t>>>0);return Number.isSafeInteger(r)?r:ft(t,e)}function ft(t,e){if(t>>>=0,(e>>>=0)<=2097151)var r=""+(4294967296*e+t);else 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)lt(Number(t));else if(j())t=BigInt(t),at=Number(t&BigInt(4294967295))>>>0,ut=Number(t>>BigInt(32)&BigInt(4294967295));else{const e=+("-"===t[0]);ut=at=0;const r=t.length;for(let n=e,i=(r-e)%6+e;i<=r;n=i,i+=6){const e=Number(t.slice(n,i));ut*=1e6,at=1e6*at+e,at>=4294967296&&(ut+=Math.trunc(at/4294967296),ut>>>=0,at>>>=0)}if(e){const[t,e]=mt(at,ut);at=t,ut=e}}}function mt(t,e){return e=~e,t?t=1+~t:e+=1,[t,e]}function gt(t){return Array.prototype.slice.call(t)}const _t="function"==typeof BigInt?BigInt.asIntN:void 0,yt="function"==typeof BigInt?BigInt.asUintN:void 0,wt=Number.isSafeInteger,vt=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}const Tt=/^-?([1-9][0-9]*|0)(\.[0-9]+)?$/;function Lt(t){switch(typeof t){case"bigint":return!0;case"number":return vt(t);case"string":return Tt.test(t);default:return!1}}function Pt(t){if("number"!=typeof t)throw P("int32");if(!vt(t))throw P("int32");return 0|t}function Ot(t){return null==t?t:Pt(t)}function jt(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 xt(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 kt(t){return null==t||"string"==typeof t?t:void 0}function Ut(t,e,r){if(null!=t&&t[R]===H)return t;if(Array.isArray(t)){var n=0|t[C];return(r=n|32&r|2&r)!==n&&W(t,r),new e(t)}}function Bt(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 Nt(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[C];return 0===t.length&&1&e?void 0:Bt(t,e,Nt)}if(null!=t&&t[R]===H)return Dt(t);if(t instanceof E){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(m){for(var r="",n=0,i=e.length-10240;n<i;)r+=String.fromCharCode.apply(null,e.subarray(n,n+=10240));r+=String.fromCharCode.apply(null,n?e.subarray(n):e),e=btoa(r)}else{void 0===r&&(r=0),d(),r=l[r],n=Array(Math.floor(e.length/3)),i=r[64]||"";let t=0,c=0;for(;t<e.length-2;t+=3){var o=e[t],s=e[t+1],a=e[t+2],u=r[o>>2];o=r[(3&o)<<4|s>>4],s=r[(15&s)<<2|a>>6],a=r[63&a],n[c++]=u+o+s+a}switch(u=0,a=i,e.length-t){case 2:a=r[(15&(u=e[t+1]))<<2]||i;case 1:e=e[t],n[c]=r[e>>2]+r[(3&e)<<4|u>>4]+a+i}e=n.join("")}t=t.i=e}return t}return}return t}let Ft,Rt;function Dt(t){return Bt(t=t.m,0|t[C],Nt)}function Mt(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[C],a&&1&i)throw Error("rfarr");if(2048&i&&!(2&i)&&function(){if(a)throw Error("carr");O(F,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;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 W(t,64|i|n),t}function Ct(t,e){if("object"!=typeof t)return t;if(Array.isArray(t)){var r=0|t[C];return 0===t.length&&1&r?t=void 0:2&r||(!e||4096&r||16&r?t=Gt(t,r,!1,e&&!(16&r)):(z(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[R]===H?$(t,r=0|(e=t.m)[C])?t:$t(t,e,r)?Vt(t,e):Gt(e,r):t instanceof E?t:void 0}function Vt(t,e,r){return t=new t.constructor(e),r&&(t.i=q),t.o=q,t}function Gt(t,e,r,n){return n??=!!(34&e),t=Bt(t,e,Ct,n),n=32,r&&(n|=2),W(t,e=16769217&e|n),t}function zt(t){if(t.i!==q)return!1;var e=t.m;return z(e=Gt(e,0|e[C]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function Wt(t){if(!zt(t)&&$(t,0|t.m[C]))throw Error()}function Ht(t,e){void 0===e&&(e=0|t[C]),32&e&&!(4096&e)&&W(t,4096|e)}function $t(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(W(e,2|r),t.i=q,!0)}function qt(t,e,r){if(null!==(t=Kt(t.m,e,void 0,r)))return t}function Kt(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 Yt(t,e,r){Wt(t),Jt(t=t.m,0|t[C],e,r)}function Jt(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[C])>>14&1023||536870912)?null!=n&&(t[s+(i?0:-1)]={[r]:n}):t[o]=n),e)}function Xt(t,e,r,n,i){let o=t.m,s=0|o[C];n=$(t,s)?1:n,i=!!i||3===n,2===n&&zt(t)&&(o=t.m,s=0|o[C]);let a=(t=Zt(o,e))===V?7:0|t[C],u=te(a,s);var c=!(4&u);if(c){4&u&&(t=gt(t),a=0,u=ce(u,s),s=Jt(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&&(W(t,u),2&u&&Object.freeze(t)),Qt(t,u,o,s,e,n,c,i)}function Qt(t,e,r,n,i,o,s,a){let u=e;return 1===o||4===o&&(2&e||!(16&e)&&32&n)?ee(e)||((e|=!t.length||s&&!(4096&e)||32&n&&!(4096&e||16&e)?2:256)!==u&&W(t,e),Object.freeze(t)):(2===o&&ee(e)&&(t=gt(t),u=0,e=ce(e,n),n=Jt(r,n,i,t)),ee(e)||(a||(e|=16),e!==u&&W(t,e))),2&e||!(4096&e||16&e)||Ht(r,n),t}function Zt(t,e,r){return t=Kt(t,e,r),Array.isArray(t)?t:V}function te(t,e){return 2&e&&(t|=2),1|t}function ee(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function re(t,e,r){Wt(t);let n=0|(t=t.m)[C];if(null==r)Jt(t,n,e);else{var i=r===V?7:0|r[C],o=i,s=ee(i),a=s||Object.isFrozen(r);for(s||(i=0),a||(r=gt(r),o=0,i=ce(i,n),a=!1),i|=5,i|=(4&i?512&i?512:1024&i?1024:0:void 0)??1024,s=0;s<r.length;s++){const t=r[s],e=Pt(t);Object.is(t,e)||(a&&(r=gt(r),o=0,i=ce(i,n),a=!1),r[s]=e)}i!==o&&(a&&(r=gt(r),i=ce(i,n)),W(r,i)),Jt(t,n,e,r)}}function ne(t,e,r,n){Wt(t),Jt(t=t.m,0|t[C],e,("0"===n?0===Number(r):r===n)?void 0:r)}function ie(t){if(x)return t[B]??(t[B]=new Map);if(B in t)return t[B];const e=new Map;return Object.defineProperty(t,B,{value:e}),e}function oe(t,e,r){var n=$n;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!=Kt(e,o)&&(0!==i&&(r=Jt(e,r,i)),i=o)}return t.set(n,i),i}function se(t,e,r){let n=t.m,i=0|n[C];if(e=function(t,e,r,n){let i=!1;if(null!=(n=Kt(t,n,void 0,(t=>{const n=Ut(t,r,e);return i=n!==t&&null!=n,n}))))return i&&!$(n)&&Ht(t,e),n}(n,i,e,r),null==e)return e;if(i=0|n[C],!$(t,i)){var o,s=e;const a=s.m,u=0|a[C];(o=$(s,u)?$t(s,a,u)?Vt(s,a,!0):new s.constructor(Gt(a,u,!1)):s)!==e&&(zt(t)&&(n=t.m,i=0|n[C]),i=Jt(n,i,r,e=o),Ht(n,i))}return e}function ae(t){return null==t&&(t=void 0),t}function ue(t,e,r){return Yt(t,e,r=ae(r)),r&&!$(r)&&Ht(t.m),t}function ce(t,e){return-273&(2&e?2|t:-3&t)}function le(t,e,r,n){var i=n;Wt(t);var o=n=t.m,s=0|n[C];const a=$(t,s)?1:2;2===a&&zt(t)&&(s=0|(o=t.m)[C]);let u=(t=Zt(o,e))===V?7:0|t[C];var c=te(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=Ut(h[o],r,f);if(t instanceof r){if(!e){const e=$(t);n&&=!e,i&&=e}h[a++]=t}}a<o&&(h.length=a),c|=4,c=i?-4097&c:4096|c,c=n?8|c:-9&c}c!==u&&(W(t,c),2&c&&Object.freeze(t)),e=t=Qt(t,c,o,s,e,a,l,!0),i=null!=i?i:new r,e.push(i),o=r=e===V?7:0|e[C],(i=$(i))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&W(e,r),i||Ht(n)}function he(t,e){return xt(qt(t,e))??0}function fe(t,e,r){ne(t,e,Ot(r),0)}function de(t,e,r){if(null!=r){if("number"!=typeof r)throw P("uint32");if(!vt(r))throw P("uint32");r>>>=0}Yt(t,e,r)}function pe(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();ne(t,e,r,"")}function me(t,e,r){if(Wt(t),e=(t=Xt(t,e,kt,2,!0)).push,"string"!=typeof r)throw Error();e.call(t,r)}var ge=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function _e(t){if("string"==typeof t)return new ge(w(t),!0);if(Array.isArray(t))return new ge(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new ge(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new ge(t,!1);if(t.constructor===E){T(b);var e=t.i;return e=(null==(e=null==e||v(e)?e:"string"==typeof e?w(e):null)?e:t.i=e)||new Uint8Array(0),new ge(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new ge(t,!1);throw Error()}function ye(t){return t?/^\d+$/.test(t)?(pt(t),new we(at,ut)):null:ve||=new we(0,0)}var we=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let ve;function be(t){return t?/^-?\d+$/.test(t)?(pt(t),new Se(at,ut)):null:Ee||=new Se(0,0)}var Se=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};let Ee;function Ae(t,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 Ie(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Te(t,e){if(e>=0)Ie(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}function Le(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function Pe(t,e,r){Ie(t.i,8*e+r)}function Oe(t,e){return Pe(t,e,2),e=t.i.end(),Le(t,e),e.push(t.j),e}function je(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 xe(t,e,r){Pe(t,e,2),Ie(t.i,r.length),Le(t,t.i.end()),Le(t,r)}function ke(){const t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Ue=ke(),Be=ke(),Ne=ke(),Fe=ke(),Re=ke(),De=ke(),Me=ke(),Ce=ke(),Ve=ke(),Ge=ke(),ze=class{constructor(t,e){this.m=Mt(t,e,void 0,2048)}toJSON(){return Dt(this)}};ze.prototype[R]=H,ze.prototype.toString=function(){return this.m.toString()};var We=class{constructor(t,e){this.i=t,t=Ue,this.j=!!t&&e===t||!1}};function He(t,e,r,n,i){null!=(e=Ze(e,n))&&(r=Oe(t,r),i(e,t),je(t,r))}const $e=new We(He,Ue),qe=new We(He,Ue);var Ke=Symbol(),Ye=Symbol();let Je,Xe;function Qe(t){var e=tr,r=er,n=t[Ke];if(n)return n;(n={}).na=t,n.W=function(t){switch(typeof t){case"boolean":return Ft||=[0,void 0,!0];case"number":return t>0?void 0:0===t?Rt||=[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,Je??=i,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 l;"number"==typeof i&&(a+=i,i=t[++o]);var u=void 0;if(i instanceof We?l=i:(l=$e,o--),l?.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++){const t=s[a];u?r(n,a,l,u,t):e(n,a,l,t)}}return t[Ke]=n}function Ze(t,e){return t instanceof ze?t.m:Array.isArray(t)?Mt(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[Ye];if(!e){const r=Qe(t);e=(t,e)=>nr(t,e,r),t[Ye]=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[C],((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 We?r:[qe,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||O(N,3)}}))}var ir,or=0,sr=or;if(X(sr)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(sr))throw Error(String(sr))}else if((ir=J(sr))&&(ir=!Number.isSafeInteger(sr)),ir)throw Error(String(sr));function ar(t,e){if(Array.isArray(e)){var r=0|e[C];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&&W(e,t),2&t&&Object.freeze(e),e}}function ur(t,e){return new We(t,e)}function cr(t,e,r){null!=(e=Et(e))&&(Pe(t,r,5),t=t.i,(r=st||=new DataView(new ArrayBuffer(8))).setFloat32(0,+e,!0),ut=0,e=at=r.getUint32(0,!0),t.i.push(e>>>0&255),t.i.push(e>>>8&255),t.i.push(e>>>16&255),t.i.push(e>>>24&255))}function lr(t,e,r){null!=(e=jt(e))&&null!=e&&(Pe(t,r,0),Te(t.i,e))}function hr(t,e,r){null!=(e=It(e))&&(Pe(t,r,0),t.i.i.push(e?1:0))}function fr(t,e,r){null!=(e=kt(e))&&xe(t,r,i(e))}function dr(t,e,r,n,i){null!=(e=Ze(e,n))&&(r=Oe(t,r),i(e,t),je(t,r))}function pr(t,e,r){null!=(e=xt(e))&&null!=e&&(Pe(t,r,0),Ie(t.i,e))}function mr(t,e,r){null!=(e=jt(e))&&(e=parseInt(e,10),Pe(t,r,0),Te(t.i,e))}Z||(or=Q(or)?or?"1":"0":X(or)?or.trim()||"0":String(or));var gr,_r=ur(cr,Ce),yr=ur(cr,Ce),wr=ur((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(Lt(t)){if("string"===e){if(e=bt(Number(t)),wt(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=at,2147483648&(e=ut))if(j())t=""+(BigInt(0|e)<<BigInt(32)|BigInt(t>>>0));else{const[r,n]=mt(t,e);t="-"+ft(r,n)}else t=ft(t,e);return t}if("number"===e){if(t=bt(t),!wt(t)){lt(t),e=at;var r=ut;(t=2147483648&r)&&(r=~r>>>0,0==(e=1+~e>>>0)&&(r=r+1>>>0)),t="number"==typeof(e=ht(e,r))?t?-e:e:t?"-"+e:e}return t}}}(e),null!=e){if("string"==typeof e)be(e);if(null!=e)switch(Pe(t,r,0),typeof e){case"number":t=t.i,lt(e),Ae(t,at,ut);break;case"bigint":r=BigInt.asUintN(64,e),r=new Se(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Ae(t.i,r.j,r.i);break;default:r=be(e),Ae(t.i,r.j,r.i)}}}),De),vr=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(Lt(t)){if("string"===e)return e=bt(Number(t)),wt(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(at,ut))),t;if("number"===e)return(t=bt(t))>=0&&wt(t)||(lt(t),t=ht(at,ut)),t}}(e),null!=e){if("string"==typeof e)ye(e);if(null!=e)switch(Pe(t,r,0),typeof e){case"number":t=t.i,lt(e),Ae(t,at,ut);break;case"bigint":r=BigInt.asUintN(64,e),r=new we(Number(r&BigInt(4294967295)),Number(r>>BigInt(32))),Ae(t.i,r.j,r.i);break;default:r=ye(e),Ae(t.i,r.j,r.i)}}}),Me),br=ur(lr,Fe);gr=new We((function(t,e,r){if(null!=(e=ar(jt,e))&&e.length){r=Oe(t,r);for(let r=0;r<e.length;r++)Te(t.i,e[r]);je(t,r)}}),Fe);var Sr,Er=ur(lr,Fe),Ar=ur(lr,Fe),Ir=ur(hr,Be),Tr=ur(hr,Be),Lr=ur(fr,Ne);Sr=new We((function(t,e,r){if(null!=(e=ar(kt,e)))for(let a=0;a<e.length;a++){var n=t,o=r,s=e[a];null!=s&&xe(n,o,i(s))}}),Ne);var Pr,Or=ur(fr,Ne),jr=ur(fr,Ne),xr=function(t,e,r=Ue){return new We(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[C])||W(e,1|t)}})),kr=new We(dr,Ue),Ur=ur(pr,Re),Br=ur(mr,Ge);Pr=new We((function(t,e,r){if(null!=(e=ar(jt,e))&&e.length){r=Oe(t,r);for(let r=0;r<e.length;r++)Te(t.i,e[r]);je(t,r)}}),Ge);var Nr=ur(mr,Ge);function Fr(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)),Le(e,e.i.end());const r=new Uint8Array(e.j),n=e.l,i=n.length;let o=0;for(let t=0;t<i;t++){const e=n[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function Rr(t,e){if(null!=e)if(Array.isArray(e))Yt(t,2,Bt(e,0,Nt));else{if(!("string"==typeof e||e instanceof E||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 E(e,b):S();else if(e.constructor!==E){if(!v(e))throw Error();e=e.length?new E(new Uint8Array(e),b):S()}ne(t,2,e,S())}}var Dr=class extends ze{constructor(t){super(t)}},Mr=[0,Or,ur((function(t,e,r){if(null!=e){if(e instanceof ze){const n=e.qa;return void(n?(e=n(e),null!=e&&xe(t,r,_e(e).buffer)):O(N,3))}if(Array.isArray(e))return void O(N,3)}null!=(e=null==e||"string"==typeof e||e instanceof E?e:void 0)&&xe(t,r,_e(e).buffer)}),Ve)];let Cr,Vr=globalThis.trustedTypes;function Gr(t){var e;return void 0===Cr&&(Cr=function(){let t=null;if(!Vr)return t;try{const e=t=>t;t=Vr.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=Cr)?e.createScriptURL(t):t,new class{constructor(t){this.i=t}toString(){return this.i+""}}(t)}function zr(t,...e){if(0===e.length)return Gr(t[0]);let r=t[0];for(let n=0;n<e.length;n++)r+=encodeURIComponent(e[n])+t[n+1];return Gr(r)}var Wr={};Wr[336783863]=[0,Lr,Ir,-1,br,[0,[1,2,3,4,5,6,7,8,9],kr,[0],kr,[0,Ir,Lr,Ir,Br,-1,Pr,Lr,-1,[0,Ir,-1],Br,Ir,-1],kr,[0,Lr,-2],kr,[0,br,Ir,1,Ir,-4],kr,[0,br,Br,Ir,-1,gr,Br,-1,Ir],kr,[0,Lr,-2],kr,[0,Lr,Br],kr,[0,3,Ir,-1,2,[0,[2],br,kr,[0,ur(pr,Re)]],[0,Br,Ir,Br,Ir,Br,Ir,Lr,-1],[0,[3,4],Lr,-1,kr,[0,br],kr,[0,Br]],[0]],kr,[0,Br,-1,Ir]],[0,Lr],Ir,[0,[1,3],[2,4],kr,[0,gr],-1,kr,[0,Sr],-1,xr,[0,Lr,-1]],Lr];var Hr=class extends ze{constructor(t){super(t)}},$r=[0,wr,-1,Tr,-3,wr,gr,Or,Er,wr,-1,Tr,Er,Tr,-2,Or],qr=class extends ze{constructor(t){super(t,500)}N(t){return ue(this,7,t)}},Kr=[-1,{}],Yr=[0,Lr,1,Kr],Jr=[0,Lr,Sr,Kr];function Xr(t,e){le(t,1,qr,e)}var Qr=class extends ze{constructor(t){super(t,500)}N(t){return ue(this,1001,t)}};Qr.prototype.j=Fr([-500,xr,[-500,Or,-1,Sr,-3,[-2,Wr,Ir],xr,Mr,Er,-1,Yr,Jr,xr,[0,Or,Tr],Or,$r,Er,Sr,987,Sr],4,xr,[-500,Lr,-1,[-1,{}],998,Lr],xr,[-500,Lr,Sr,-1,[-2,{},Ir],997,Sr,-1],Er,xr,[-500,Lr,Sr,Kr,998,Sr],Sr,Er,Yr,Jr,xr,[0,Or,-1,Kr],Sr,-2,$r,Or,-1,Tr,[0,Tr,Ur],978,Kr,xr,Mr]);var Zr=class extends ze{constructor(t){super(t)}};let tn;const en=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 rn(t){if(t)return!0;if(void 0===tn)try{await WebAssembly.instantiate(en),tn=!0}catch{tn=!1}return tn}async function nn(t,e,r){return{wasmLoaderPath:`${e}/${t}_${r=`wasm${r?"_module":""}${await rn(r)?"":"_nosimd"}_internal`}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var on=class{};function sn(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 an(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}on.forVisionTasks=function(t,e=!1){return nn("vision",t??zr``,e)},on.forTextTasks=function(t,e=!1){return nn("text",t??zr``,e)},on.forGenAiTasks=function(t,e=!1){return nn("genai",t??zr``,e)},on.forAudioTasks=function(t,e=!1){return nn("audio",t??zr``,e)},on.isSimdSupported=function(t=!1){return rn(t)};const un=[[0,async t=>{const e=(new TextEncoder).encode("TFL3").length;return t=await an(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await an(t,6))[4]&&75===t[5]]];function cn(){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 ln(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 hn(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 fn(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 dn(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function pn(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 mn=(gn=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:cn()?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?'),hn(this,n||"input_audio",(n=>{hn(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),hn(this,n,(t=>{this.h._addAudioToInputStream(this.i,e,r,t,i)}))}addGpuBufferToStream(t,e,r){hn(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){hn(this,e,(e=>{this.h._addBoolToInputStream(t,e,r)}))}addDoubleToStream(t,e,r){hn(this,e,(e=>{this.h._addDoubleToInputStream(t,e,r)}))}addFloatToStream(t,e,r){hn(this,e,(e=>{this.h._addFloatToInputStream(t,e,r)}))}addIntToStream(t,e,r){hn(this,e,(e=>{this.h._addIntToInputStream(t,e,r)}))}addUintToStream(t,e,r){hn(this,e,(e=>{this.h._addUintToInputStream(t,e,r)}))}addStringToStream(t,e,r){hn(this,e,(e=>{hn(this,t,(t=>{this.h._addStringToInputStream(t,e,r)}))}))}addStringRecordToStream(t,e,r){hn(this,e,(e=>{fn(this,Object.keys(t),(n=>{fn(this,Object.values(t),(i=>{this.h._addFlatHashMapToInputStream(n,i,Object.keys(t).length,e,r)}))}))}))}addProtoToStream(t,e,r,n){hn(this,r,(r=>{hn(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){hn(this,t,(t=>{this.h._addEmptyPacketToInputStream(t,e)}))}addBoolVectorToStream(t,e,r){hn(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){hn(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){hn(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){hn(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){hn(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){hn(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)hn(this,e,(t=>{this.h._addStringVectorEntry(n,t)}));this.h._addStringVectorToInputStream(n,e,r)}))}addBoolToInputSidePacket(t,e){hn(this,e,(e=>{this.h._addBoolToInputSidePacket(t,e)}))}addDoubleToInputSidePacket(t,e){hn(this,e,(e=>{this.h._addDoubleToInputSidePacket(t,e)}))}addFloatToInputSidePacket(t,e){hn(this,e,(e=>{this.h._addFloatToInputSidePacket(t,e)}))}addIntToInputSidePacket(t,e){hn(this,e,(e=>{this.h._addIntToInputSidePacket(t,e)}))}addUintToInputSidePacket(t,e){hn(this,e,(e=>{this.h._addUintToInputSidePacket(t,e)}))}addStringToInputSidePacket(t,e){hn(this,e,(e=>{hn(this,t,(t=>{this.h._addStringToInputSidePacket(t,e)}))}))}addProtoToInputSidePacket(t,e,r){hn(this,r,(r=>{hn(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){hn(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){hn(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){hn(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){hn(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){hn(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){hn(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)hn(this,e,(t=>{this.h._addStringVectorEntry(r,t)}));this.h._addStringVectorToInputSidePacket(r,e)}))}attachBoolListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachBoolListener(t)}))}attachBoolVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachBoolVectorListener(t)}))}attachIntListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachIntListener(t)}))}attachIntVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachIntVectorListener(t)}))}attachUintListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachUintListener(t)}))}attachUintVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachUintVectorListener(t)}))}attachDoubleListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachDoubleListener(t)}))}attachDoubleVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachDoubleVectorListener(t)}))}attachFloatListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachFloatListener(t)}))}attachFloatVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachFloatVectorListener(t)}))}attachStringListener(t,e){dn(this,t,e),hn(this,t,(t=>{this.h._attachStringListener(t)}))}attachStringVectorListener(t,e){pn(this,t,e),hn(this,t,(t=>{this.h._attachStringVectorListener(t)}))}attachProtoListener(t,e,r){dn(this,t,e),hn(this,t,(t=>{this.h._attachProtoListener(t,r||!1)}))}attachProtoVectorListener(t,e,r){pn(this,t,e),hn(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?'),dn(this,t,((t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)})),hn(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 gn{ka(){this.h._registerModelResourcesGraphService()}});var gn;async function _n(t,e){const r=await(async(t,e,r)=>{var n=ni;if(t&&await ln(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await ln(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 yn(t,e){return _n(t,e)}function wn(t){try{const e=t.J.length;if(1===e)throw Error(t.J[0].message);if(e>1)throw Error("Encountered multiple errors: "+t.J.map((t=>t.message)).join(", "))}finally{t.J=[]}}function vn(t,e){t.I=Math.max(t.I,e)}var 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),wn(this)}finishProcessing(){this.j.finishProcessing(),wn(this)}close(){this.j.closeGraph()}};bn.prototype.close=bn.prototype.close;var Sn=class extends ze{constructor(t){super(t)}j(){return jt(qt(this,2))??0}};function En(t,e){ue(t,1,e)}var An=class extends ze{constructor(t){super(t)}},In=[0,Nr,Er,yr,-1,br];function Tn(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}}Sn.prototype.l=Fr(In);class Ln{constructor(t){this.i=[],this.data=t,this.length=t.length}}function Pn(t,e){return new jn((async()=>{const{value:e,done:r}=await t.read();return r?void 0:e}),e)}async function On(t,e,r,n,i){if(2===i)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout((()=>{t.l()}),0),Promise.resolve(0);for(;t.size<r+n;){var o=await t.j();if(void 0===o)break;t.i.push(new Ln(o))}if(t.size<r+n)throw Error(`Data size is too small: ${t.size}, expected at least ${r+n}.`);o=e._malloc(n)>>>0;let s=0;for(let a=0;a<t.i.length;a++){const u=t.i[a];if(r>=u.length){r-=u.length;continue}const c=Math.min(n,u.length-r);if(void 0===(r=Tn(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 jn=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 xn(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function kn(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function Un(t,e,r){t=new Nn(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 Bn(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${n}/${r} bytes before failure`);return t}function Bn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var Nn=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))}},Fn=class extends ze{constructor(t){super(t)}};Fn.prototype.j=Fr([0,Or,2,Sr,Er,Tr]);var Rn=class extends ze{constructor(t){super(t)}},Dn=class extends ze{constructor(t){super(t)}},Mn=class extends ze{constructor(t){super(t)}},Cn=class extends ze{constructor(t){super(t)}},Vn=[0,Er,-6,1,Er,1,[0,Tr,Nr,-2],[0,Tr,yr],Nr,-2,[0,Tr,-1,Nr,yr,Br,br,Ir,-1],1,Tr,Er,br,-1,[0,Nr,Er],Tr,-1,_r,Er,-5,_r,-1,[0,br,_r],br,Ir,[0,br,-2],_r,[0,Er],[0,Er,-4],Ir,br,-2,Ir,-1,yr,_r,Ir,Er,-1,1,Tr,Er],Gn=[0,Or,-2],zn=[0,[4,6],Vn,Er,1,Ar,Sr,jr,Pr,Gn,br,[0,[0,Er,-1,xr,[0,Er,[0,Er,-1],-1,[0,Nr,-1],Tr],Tr,-2,Er,-1],[0,Er,-1,Tr],Vn,Tr,Er,[0,Er],-1],Lr,-3,[0,Er,Tr],Vn,[0,Gn,-2],gr];Cn.prototype.j=Fr([0,Or,8,[0,Tr,-6],1,Er,1,Er,[0,xr,[0,Or,vr,-1,Nr],zn,Er],[0,Er,Tr,-3],1,Nr,1,zn,1,Er,5,Nr,gr,1,In,Tr,Er,Tr]);var Wn=class extends ze{constructor(t){super(t)}},Hn=class extends ze{constructor(t){super(t)}},$n=[2,4];Hn.prototype.j=Fr([0,$n,Er,jr,Er,kr,[0,1,Or]]);const 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{const r=Pn(t,(()=>{}));await this.h.createLlmInferenceEngine(he(e,2)??512,se(e,Sn,3)?.j()??40,It(qt(e,6))??!1??!1,he(e,7)??0,It(qt(e,8))??!1??!1,((t,e,n)=>On(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"],[he(e,2)??512,se(e,Sn,3)?.j()??40,It(qt(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(kn),c=t.some(xn);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)hn(this,r,(t=>{i._AddTextQueryChunk(l,t)}));else if(xn(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(!kn(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:xn(n)?e+=260:kn(n)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return hn(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)=>On(t,this.h,e,r,n)),e)}}}(function(t){return class extends t{Y(t,e){hn(this,"lora_model_ref_in",(r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)}))}}}(class extends mn{}))));class Kn extends qn{}var Yn=class{constructor(t){this.j=t,this.i=Jn,Jn++}},Jn=1;class Xn{constructor(){let t,e;this.promise=new Promise(((r,n)=>{t=r,e=n})),this.resolve=t,this.reject=e}}function Qn(t){return 1===t?1:t+t%2}async function Zn(){const t=await Kn.X({powerPreference:"high-performance"});var e=t.limits.maxBufferSize;const 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"]),Kn.la(e,t)}function ti(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 ei(t){const e=function(t){const e=new Qr;me(e,10,"text_in"),me(e,10,"token_cost_in"),me(e,10,"lora_model_id_to_apply_in"),me(e,10,"lora_model_ref_in"),me(e,10,"lora_model_id_to_load_in"),me(e,16,"streaming_reader"),me(e,15,"text_out"),me(e,15,"text_end"),me(e,15,"token_cost_out");var r=new qr;pe(r,2,"TokenizerInputBuildCalculator"),me(r,3,"PROMPT:text_in"),me(r,3,"LORA_ID:lora_model_id_to_apply_in"),me(r,4,"prompt"),Xr(e,r),pe(r=new qr,2,"ModelDataCalculator"),me(r,6,"MODEL_DATA:__side_packet_1"),me(r,6,"MODEL_TYPE:model_type"),me(r,5,"READ_DATA_FN:streaming_reader"),me(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),me(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),me(r,4,"LORA_DATA:lora_model_data"),Xr(e,r),pe(r=new qr,2,"Gpt2UnicodeMappingCalculator"),me(r,5,"MODEL_TYPE:model_type"),me(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),Xr(e,r),pe(r=new Dr,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var n=new Hn,i=he(t.i,2);fe(n,1,i),pe(i=new Wn,2,"spm_vocab_model"),i=ae(i);t:{Wt(n);var o=n.m,s=0|o[C];if(null==i){var a=ie(o);if(4!==oe(a,o,s))break t;a.set($n,0)}else{const t=ie(a=o),e=oe(t,a,s);4!==e&&(e&&(s=Jt(a,s,e)),t.set($n,4))}Jt(o,s,4,i)}return i&&!$(i)&&Ht(n.m),fe(n,3,2),Rr(r,n.j()),pe(n=new qr,2,"TokenizerCalculator"),le(n,8,Dr,r),me(n,5,"MODEL_DATA:__side_packet_1"),me(n,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),me(n,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),me(n,6,"PROCESSOR_GETTER:__input_side_1"),me(n,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),Xr(e,n),pe(r=new Dr,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),fe(n=new Cn,12,3),pe(n,1,"llm.tflite"),fe(n,14,0),i=Qn(he(t.i,5)),fe(n,22,i),i=se(t.i,Sn,3),ue(n,31,i),ne(i=new Rn,1,At(!0),!1),null!=It(qt(t.i,6))&&(It(qt(t.i,6))??!1)&&ne(i,1,At(!1),!1),ne(i,2,At(!0),!1),ne(i,5,At(!0),!1),ue(n,10,i),i=Xt(t.i,4,jt,void 0===K?2:4),re(n,29,i),i=new Mn,fe(o=new Dn,1,1),a=he(t.i,2),fe(o,2,a),ue(i,1,o),ue(n,20,i),Rr(r,n.j()),pe(n=new qr,2,"LlmGpuCalculator"),le(n,8,Dr,r),me(n,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),me(n,3,"FINISH:finish"),me(n,3,"LORA_DATA:lora_model_data"),me(n,5,"MODEL_DATA:__side_packet_1"),me(n,4,"DECODED_IDS:__stream_3"),me(n,4,"OUTPUT_END:__stream_4"),pe(r=new Hr,1,"FINISH"),ne(r,2,At(!0),!1),le(n,13,Hr,r),Xr(e,n),pe(r=new qr,2,"IsPacketPresentCalculator"),me(r,3,"__stream_4"),me(r,4,"text_end"),Xr(e,r),pe(r=new Dr,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),n=new Fn,t=Qn(he(t.i,5)),fe(n,5,t),me(n,4,"<eos>"),me(n,4,"<|endoftext|>"),Rr(r,n.j()),pe(t=new qr,2,"DetokenizerCalculator"),le(t,8,Dr,r),me(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),me(t,5,"PROCESSOR_GETTER:__input_side_1"),me(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),me(t,5,"MODEL_DATA:__side_packet_1"),me(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),me(t,4,"WORDS:text_out"),Xr(e,t),pe(t=new qr,2,"TokenCostCalculator"),me(t,3,"PROMPT:token_cost_in"),me(t,5,"PROCESSOR_GETTER:__input_side_1"),me(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),me(t,4,"NUM_TOKENS:token_cost_out"),Xr(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<he(t.i,5)&&t.G[r].push(e)})),t.A&&0===t.D.length&&(t.B?(e.length>he(t.i,5)&&e.pop(),t.A(e,!1)):t.A(e[0],!1)),vn(t,r)})),t.j.attachEmptyPacketListener("text_out",(e=>{vn(t,e)})),t.j.attachBoolListener("text_end",((e,r)=>{vn(t,r);try{ti(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<he(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,vn(t,e),ti(t),t.o&&(t.o.resolve(t.G.map((t=>t.join("")))),t.o=void 0)})),t.j.attachIntListener("token_cost_out",((e,r)=>{t.T=e,vn(t,r)})),t.U&&t.j.addStreamingReaderToInputSidePacket(t.U,"streaming_reader");const r=e.j();return t.C?.removeEventListener("uncapturederror",t.K),t.j.aa().then((()=>{t.C?.addEventListener("uncapturederror",t.K),t.D.length=0,t.setGraph(new Uint8Array(r),!0),t.finishProcessing()}))}function ri(t,e,r,n){if(t.A="function"==typeof r?r:n,(n=(e=Array.isArray(e)?e:[e]).filter((t=>xn(t))).length)>0&&(null==xt(qt(t.i,7))||he(t.i,7)<n))throw Error(`maxNumImages is set to ${null!=xt(qt(t.i,7))?he(t.i,7):0}, but the query included ${n} images.`);if((n=e.filter((t=>kn(t))).length)>0&&(null==It(qt(t.i,8))||!It(qt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${n} audio chunks.`);if(t.v){if(t.B&&he(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 Yn)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=>(ti(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<he(t.i,5);n++)t.G[n]=[];if(n=t.I+1,t.j.addStringToStream(e.join(""),"text_in",n),r instanceof Yn){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 Xn,t.o.promise}var ni=class extends bn{constructor(t,e){if(super(new Kn(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 An,En(this.i,new Zr),this.u=new Sn,ue(this.i,3,this.u),de(this.i,2,512),t=this.u,!vt(2))throw P("enum");ne(t,1,2,0),fe(this.u,2,40),ne(this.u,3,St(1),0),Yt(this.u,5,Ot(0)),ne(this.u,4,St(.8),0),de(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]=sn(n);this.O=1===await async function(t){const e=[];let r;for(const[i,o]of un){const s=i;var n=o;[t,r]=sn(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;de(this.i,7,i);var o="supportAudio"in t&&!!t.supportAudio;Yt(this.i,8,At(o)),this.O||i>0||o?(this.v=!0,n=r):(this.v=!1,this.U=Pn(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&&de(this.i,2,t.maxTokens??512),"topK"in t&&fe(this.u,2,t.topK??40),"temperature"in t&&ne(this.u,4,St(t.temperature??.8),0),"randomSeed"in t&&Yt(this.u,5,Ot(t.randomSeed??0)),"loraRanks"in t&&function(t,e){re(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.");de(this.i,5,i),o=se(this.i,Sn,3),i>1&&o&&(o.j()<=1||(qt(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&&Yt(this.i,6,At(t.forceF32)),this.v?(this.j.V(),this.O?this.j.ba(n,this.i).then((()=>{ti(this)})):this.j.createLlmInferenceEngine(n,this.i).then((()=>{ti(this)}))):(this.l=!0,t=ei(this).then((()=>{})),Promise.all([r,t]).then((()=>{this.l=!1,ti(this)})))}get baseOptions(){return se(this.i,Zr,1)}set baseOptions(t){En(this.i,t)}get isIdle(){return!this.l&&!this.o}R(t,e,r){return he(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,ri(this,t,e,r).then((t=>t[0]))}da(t,e,r){return this.B=!0,ri(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(xn))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(kn))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 Nn(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return Un(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 Un(t,e.body,r)}(this.j.h,t);e=new Yn(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(),Bn(t),vn(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};ni.prototype.loadLoraModel=ni.prototype.ja,ni.prototype.cancelProcessing=ni.prototype.Z,ni.prototype.sizeInTokens=ni.prototype.S,ni.prototype.generateResponses=ni.prototype.da,ni.prototype.generateResponse=ni.prototype.R,ni.prototype.setOptions=ni.prototype.N,ni.createWebGpuDevice=Zn,ni.createFromModelPath=async function(t,e){return yn(t,e={baseOptions:{gpuOptions:{device:await Zn()},modelAssetPath:e}})},ni.createFromModelBuffer=async function(t,e){return yn(t,e={baseOptions:{gpuOptions:{device:await Zn()},modelAssetBuffer:e}})},ni.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){const t=await Zn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return yn(t,e)},exports.FilesetResolver=on,exports.LlmInference=ni,exports.TaskRunner=bn;
|
|
1
|
+
"use strict";var t="undefined"!=typeof self?self:{};function e(e,r){t:{for(var i=["CLOSURE_FLAGS"],n=t,o=0;o<i.length;o++)if(null==(n=n[i[o]])){i=null;break t}i=n}return null!=(e=i&&i[e])?e:r}var r,i="undefined"!=typeof TextEncoder;function n(t){if(i)t=(r||=new TextEncoder).encode(t);else{let r=0,i=new Uint8Array(3*t.length);for(let n=0;n<t.length;n++){var e=t.charCodeAt(n);if(e<128)i[r++]=e;else{if(e<2048)i[r++]=e>>6|192;else{if(e>=55296&&e<=57343){if(e<=56319&&n<t.length){let o=t.charCodeAt(++n);if(o>=56320&&o<=57343){e=1024*(e-55296)+o-56320+65536,i[r++]=e>>18|240,i[r++]=e>>12&63|128,i[r++]=e>>6&63|128,i[r++]=63&e|128;continue}n--}e=65533}i[r++]=e>>12|224,i[r++]=e>>6&63|128}i[r++]=63&e|128}}t=r===i.length?i:i.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 i=new Uint8Array(r),n=0;return function(t,e){function r(e){for(;i<t.length;){let e=t.charAt(i++),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 i=0;;){let t=r(-1),i=r(0),n=r(64),o=r(64);if(64===o&&-1===t)break;e(t<<2|i>>4),64!=n&&(e(i<<4&240|n>>2),64!=o&&e(n<<6&192|o))}}(t,function(t){i[n++]=t}),n!==r?i.subarray(0,n):i}function d(){if(!c){c={};var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),e=["+/=","+/","-_=","-_.","-_"];for(let r=0;r<5;r++){let i=t.concat(e[r].split(""));h[r]=i;for(let t=0;t<i.length;t++){let e=i[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 y(t){return v[t]||""}function _(t){if(!m)return f(t);t=g.test(t)?t.replace(g,y):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 i=L??={},n=i[e]||0;n>=r||(i[e]=n+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"),M=x("m_m","qa",!0),D={ha:{value:0,configurable:!0,writable:!0,enumerable:!1}},C=Object.defineProperties,V=k?B:"ha",G=[];function z(t,e){k||V in t||C(t,D),t[V]|=e}function H(t,e){k||V in t||C(t,D),t[V]=e}H(G,7),U=Object.freeze(G);var W={};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.pa=!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<=nt:"-"===t[0]?ot(t,et):ot(t,it)),et=Number.MIN_SAFE_INTEGER.toString(),rt=Z?BigInt(Number.MIN_SAFE_INTEGER):void 0,it=Number.MAX_SAFE_INTEGER.toString(),nt=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 i=t[r],n=e[r];if(i>n)return!1;if(i<n)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 i=e,n=(r-e)%6+e;n<=r;i=n,n+=6){let e=Number(t.slice(i,n));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,yt="function"==typeof BigInt?BigInt.asUintN:void 0,_t=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("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[M]===W)return t;if(Array.isArray(t)){var i=0|t[V];return(r=i|32&r|2&r)!==i&&H(t,r),new e(t)}}function Rt(t){return t}function Mt(t,e,r,i){var n=void 0!==i;i=!!i;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||n||(l=!0,s=(Tt??Rt)(s-h,h,t,c,void 0)+h)}for(e=void 0,n=0;n<a;n++){let a=t[n];if(null!=a&&null!=(a=r(a,i)))if(u&&n>=s){let t=n-h;(e??={})[t]=a}else o[n]=a}if(c)for(let n in c){if(null==(t=c[n])||null==(t=r(t,i)))continue;let l;a=+n,u&&!Number.isNaN(a)&&(l=a+h)<s?o[l]=t:(e??={})[n]=t}return e&&(l?o.push(e):o[s]=e),o}function Dt(t){switch(typeof t){case"number":return Number.isFinite(t)?t:""+t;case"bigint":return tt(t)?Number(t):""+t;case"boolean":return t?1:0;case"object":if(Array.isArray(t)){var e=0|t[V];return 0===t.length&&1&e?void 0:Mt(t,e,Dt)}if(null!=t&&t[M]===W)return Ct(t);if(t instanceof A){if(null==(e=t.i))t="";else if("string"==typeof e)t=e;else{if(m){for(var r="",i=0,n=e.length-10240;i<n;)r+=String.fromCharCode.apply(null,e.subarray(i,i+=10240));r+=String.fromCharCode.apply(null,i?e.subarray(i):e),e=btoa(r)}else{void 0===r&&(r=0),d(),r=h[r],i=Array(Math.floor(e.length/3)),n=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],i[u++]=l+o+a+s}switch(l=0,s=n,e.length-t){case 2:s=r[(15&(l=e[t+1]))<<2]||n;case 1:e=e[t],i[u]=r[e>>2]+r[(3&e)<<4|l>>4]+s+n}e=i.join("")}t=t.i=e}return t}return}return t}function Ct(t){return Mt(t=t.m,0|t[V],Dt)}function Vt(t,e,r,i=0){if(null==t){var n=32;r?(t=[r],n|=128):t=[],e&&(n=-16760833&n|(1023&e)<<14)}else{if(!Array.isArray(t))throw Error("narr");if(n=0|t[V],a&&1&n)throw Error("rfarr");if(2048&n&&!(2&n)&&function(){if(a)throw Error("carr");O(R,5)}(),256&n)throw Error("farr");if(64&n)return(n|i)!==n&&H(t,n|i),t;if(r&&(n|=128,r!==t[0]))throw Error("mid");t:{n|=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&n?0:-1)>=1024)throw Error("pvtlmt");for(var l in t)(o=+l)<s&&(r[o+e]=t[l],delete t[l]);n=-16760833&n|(1023&s)<<14;break t}}if(e){if((l=Math.max(e,o-(128&n?0:-1)))>1024)throw Error("spvt");n=-16760833&n|(1023&l)<<14}}}return H(t,64|n|i),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=Ht(t,r,!1,e&&!(16&r)):(z(t,34),4&r&&Object.freeze(t))),t}return null!=t&&t[M]===W?$(t,r=0|(e=t.m)[V])?t:Kt(t,e,r)?zt(t,e):Ht(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 Ht(t,e,r,i){return i??=!!(34&e),t=Mt(t,e,Gt,i),i=32,r&&(i|=2),H(t,e=16769217&e|i),t}function Wt(t){if(t.i!==q)return!1;var e=t.m;return z(e=Ht(e,0|e[V]),2048),t.m=e,t.i=void 0,t.o=void 0,!0}function $t(t){if(!Wt(t)&&$(t,0|t.m[V]))throw Error()}function qt(t,e){void 0===e&&(e=0|t[V]),32&e&&!(4096&e)&&H(t,4096|e)}function Kt(t,e,r){return!!(2&r)||!(!(32&r)||4096&r)&&(H(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,i){if(-1===e)return null;var n=e+(r?0:-1),o=t.length-1;if(!(o<1+(r?0:-1))){if(n>=o){var a=t[o];if(null!=a&&"object"==typeof a&&a.constructor===Object){r=a[e];var s=!0}else{if(n!==o)return;r=a}}else r=t[n];if(i&&null!=r){if(null==(i=i(r)))return i;if(!Object.is(i,r))return s?a[e]=i:t[n]=i,i}return r}}function Xt(t,e,r){$t(t),Qt(t=t.m,0|t[V],e,r)}function Qt(t,e,r,i,n){var o=r+(n?0:-1),a=t.length-1;if(a>=1+(n?0:-1)&&o>=a){let n=t[a];if(null!=n&&"object"==typeof n&&n.constructor===Object)return n[r]=i,e}return o<=a?(t[o]=i,e):(void 0!==i&&(r>=(a=(e??=0|t[V])>>14&1023||536870912)?null!=i&&(t[a+(n?0:-1)]={[r]:i}):t[o]=i),e)}function Zt(t,e,r,i,n){var o=t.m,a=0|o[V];i=$(t,a)?1:i,n=!!n||3===i,2===i&&Wt(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 i=0,n=0;for(;i<t.length;i++){let e=r(t[i]);null!=e&&(t[n++]=e)}n<i&&(t.length=n),r=-513&l|4,l=r&=-1025,l&=-4097}return l!==s&&(H(t,l),2&l&&Object.freeze(t)),te(t,l,o,a,e,i,u,n)}function te(t,e,r,i,n,o,a,s){var l=e;return 1===o||4===o&&(2&e||!(16&e)&&32&i)?ie(e)||((e|=!t.length||a&&!(4096&e)||32&i&&!(4096&e||16&e)?2:256)!==l&&H(t,e),Object.freeze(t)):(2===o&&ie(e)&&(t=gt(t),l=0,e=ce(e,i),i=Qt(r,i,n,t)),ie(e)||(s||(e|=16),e!==l&&H(t,e))),2&e||!(4096&e||16&e)||qt(r,i),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 ie(t){return!!(2&t)&&!!(4&t)||!!(256&t)}function ne(t,e,r){$t(t);var i=0|(t=t.m)[V];if(null==r)Qt(t,i,e);else{var n=r===U?7:0|r[V],o=n,a=ie(n),s=a||Object.isFrozen(r);for(a||(n=0),s||(r=gt(r),o=0,n=ce(n,i),s=!1),n|=5,n|=(4&n?512&n?512:1024&n?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,n=ce(n,i),s=!1),r[a]=e)}n!==o&&(s&&(r=gt(r),n=ce(n,i)),H(r,n)),Qt(t,i,e,r)}}function oe(t,e,r,i){$t(t),Qt(t=t.m,0|t[V],e,("0"===i?0===Number(r):r===i)?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 i=dn,n=t.get(i);if(null!=n)return n;n=0;for(let t=0;t<i.length;t++){let o=i[t];null!=Jt(e,o)&&(0!==n&&(r=Qt(e,r,n)),n=o)}return t.set(i,n),n}function le(t,e,r){var i=t.m,n=0|i[V];if(e=function(t,e,r,i){var n=!1;if(null!=(i=Jt(t,i,void 0,t=>{var i=Ft(t,r,e);return n=i!==t&&null!=i,i})))return n&&!$(i)&&qt(t,e),i}(i,n,e,r),null==e)return e;if(!$(t,n=0|i[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(Ht(s,l,!1)):a)!==e&&(Wt(t)&&(n=0|(i=t.m)[V]),qt(i,n=Qt(i,n,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,i){var n=i;$t(t);var o=i=t.m,a=0|i[V],s=$(t,a)?1:2;2===s&&Wt(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 i=!e,n=!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);i&&=!e,n&&=e}c[s++]=t}}s<o&&(c.length=s),u|=4,u=n?-4097&u:4096|u,u=i?8|u:-9&u}u!==l&&(H(t,u),2&u&&Object.freeze(t)),e=t=te(t,u,o,a,e,s,h,!0),n=null!=n?n:new r,e.push(n),o=r=e===U?7:0|e[V],(n=$(n))?(r&=-9,1===e.length&&(r&=-4097)):r|=4096,r!==o&&H(e,r),n||qt(i)}function de(t,e){return Bt(Yt(t,e))??0}function pe(t,e,r){Xt(t,e,null==r?r:At(r))}function me(t,e,r){oe(t,e,null==r?r:At(r),!1)}function ge(t,e,r){oe(t,e,xt(r),0)}function ve(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 ye(t,e,r){if(null!=r&&"string"!=typeof r)throw Error();oe(t,e,r,"")}function _e(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 we=class{constructor(t,e,r){if(this.buffer=t,r&&!e)throw Error()}};function be(t){if("string"==typeof t)return new we(_(t),!0);if(Array.isArray(t))return new we(new Uint8Array(t),!0);if(t.constructor===Uint8Array)return new we(t,!1);if(t.constructor===ArrayBuffer)return t=new Uint8Array(t),new we(t,!1);if(t.constructor===A){I(b);var e=t.i;return e=(null==(e=null==e||w(e)?e:"string"==typeof e?_(e):null)?e:t.i=e)||new Uint8Array(0),new we(e,!0,t)}if(t instanceof Uint8Array)return t=t.constructor===Uint8Array?t:new Uint8Array(t.buffer,t.byteOffset,t.byteLength),new we(t,!1);throw Error()}function Se(t){return new Ie(4294967295&t,Math.floor(t/4294967296))}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){return new Fe(4294967295&t,Math.floor(t/4294967296))}function Le(t){return t?/^-?\d+$/.test(t)?(pt(t),new Fe(st,lt)):null:Pe||=new Fe(0,0)}var Pe,Oe,je,ke,xe,Ue,Be,Ne,Fe=class{constructor(t,e){this.j=t>>>0,this.i=e>>>0}};function Re(t,e,r){return"undefined"!=typeof BigInt64Array?(Be||(Be=new BigInt64Array(1),Ne=new Uint32Array(Be.buffer),Be[0]=BigInt(1),Ue=1===Ne[0]),Be[0]=t,new e(Ne[t=Ue?0:1],Ne[1-t])):(xe||(Oe=BigInt(Number.MIN_SAFE_INTEGER),je=BigInt(Number.MAX_SAFE_INTEGER),ke=BigInt(4294967295),xe=BigInt(32)),t>=Oe&&t<=je?r(Number(t)):(t=BigInt.asUintN(64,t),new e(Number(t&ke),Number(t>>xe))))}function Me(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 De(t,e){for(;e>127;)t.i.push(127&e|128),e>>>=7;t.i.push(e)}function Ce(t,e){if(e>=0)De(t,e);else{for(let r=0;r<9;r++)t.i.push(127&e|128),e>>=7;t.i.push(1)}}var Ve=class{constructor(){this.i=[]}length(){return this.i.length}end(){var t=this.i;return this.i=[],t}};function Ge(t,e){0!==e.length&&(t.l.push(e),t.j+=e.length)}function ze(t,e,r){De(t.i,8*e+r)}function He(t,e){return ze(t,e,2),e=t.i.end(),Ge(t,e),e.push(t.j),e}function We(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 $e(t,e,r){ze(t,e,2),De(t.i,r.length),Ge(t,t.i.end()),Ge(t,r)}var qe=class{constructor(){this.l=[],this.j=0,this.i=new Ve}};function Ke(){var t=class{constructor(){throw Error()}};return Object.setPrototypeOf(t,t.prototype),t}var Ye=Ke(),Je=Ke(),Xe=Ke(),Qe=Ke(),Ze=Ke(),tr=Ke(),er=Ke(),rr=Ke(),ir=Ke(),nr=Ke(),or=class{constructor(t,e){this.m=Vt(t,e,void 0,2048)}toJSON(){return Ct(this)}};or.prototype[M]=W,or.prototype.toString=function(){return this.m.toString()};var ar=class{constructor(t,e){this.i=t,t=Ye,this.j=!!t&&e===t||!1}};function sr(t,e,r,i,n){null!=(e=mr(e,i))&&(r=He(t,r),n(e,t),We(t,r))}var lr,ur,hr=new ar(sr,Ye),cr=new ar(sr,Ye),fr=Symbol(),dr=Symbol();function pr(t){var e=gr,r=vr,i=t[fr];if(i)return i;(i={}).oa=t,i.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 n=t[1],o=1;n&&n.constructor===Object&&(i.ca=n,"function"==typeof(n=t[++o])&&(i.ia=!0,lr??=n,ur??=t[o+1],n=t[o+=2]));for(var a={};n&&Array.isArray(n)&&n.length&&"number"==typeof n[0]&&n[0]>0;){for(var s=0;s<n.length;s++)a[n[s]]=n;n=t[++o]}for(s=1;void 0!==n;){let h;"number"==typeof n&&(s+=n,n=t[++o]);var l=void 0;if(n instanceof ar?h=n:(h=hr,o--),h?.j){n=t[++o],l=t;var u=o;"function"==typeof n&&(n=n(),l[u]=n),l=n}for(u=s+1,"number"==typeof(n=t[++o])&&n<0&&(u-=n,n=t[++o]);s<u;s++){let t=a[s];l?r(i,s,h,l,t):e(i,s,h,t)}}return t[fr]=i}function mr(t,e){return t instanceof or?t.m:Array.isArray(t)?Vt(t,e[0],e[1]):void 0}function gr(t,e,r){t[e]=r.i}function vr(t,e,r,i){var n,o,a=r.i;t[e]=(t,e,r)=>a(t,e,r,o||=pr(i).W,n||=yr(i))}function yr(t){var e=t[dr];if(!e){let r=pr(t);e=(t,e)=>_r(t,e,r),t[dr]=e}return e}function _r(t,e,r){!function(t,e,r){var i,n=128&e?0:-1,o=t.length;(i=!!o)&&(i=null!=(i=t[o-1])&&"object"==typeof i&&i.constructor===Object);var a=o+(i?-1:0);for(e=128&e?1:0;e<a;e++)r(e-n,t[e]);if(i){t=t[o-1];for(let e in t)!isNaN(e)&&r(+e,t[e])}}(t,0|t[V],(t,i)=>{if(null!=i){var n=function(t,e){var r=t[e];if(r)return r;if((r=t.ca)&&(r=r[e])){var i=(r=Array.isArray(r)?r[0]instanceof ar?r:[cr,r]:[r,void 0])[0].i;if(r=r[1]){let e=yr(r),n=pr(r).W;r=t.ia?ur(n,e):(t,r,o)=>i(t,r,o,n,e)}else r=i;return t[e]=r}}(r,t);n?n(e,i,t):t<500||O(F,3)}})}var wr,br=0,Sr=br;if(X(Sr)){if(!/^\s*(?:-?[1-9]\d*|0)?\s*$/.test(Sr))throw Error(String(Sr))}else if((wr=J(Sr))&&(wr=!Number.isSafeInteger(Sr)),wr)throw Error(String(Sr));function Er(t,e){if(Array.isArray(e)){var r=0|e[V];if(4&r)return e;for(var i=0,n=0;i<e.length;i++){let r=t(e[i]);null!=r&&(e[n++]=r)}return n<i&&(e.length=n),(t=-1537&r|5)!==r&&H(e,t),2&t&&Object.freeze(e),e}}function Ar(t,e){return new ar(t,e)}function Ir(t,e,r){null!=(e=Et(e))&&(ze(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 Tr(t,e,r){null!=(e=Ut(e))&&null!=e&&(ze(t,r,0),Ce(t.i,e))}function Lr(t,e,r){null!=(e=It(e))&&(ze(t,r,0),t.i.i.push(e?1:0))}function Pr(t,e,r){null!=(e=Nt(e))&&$e(t,r,n(e))}function Or(t,e,r,i,n){null!=(e=mr(e,i))&&(r=He(t,r),n(e,t),We(t,r))}function jr(t,e,r){null!=(e=Bt(e))&&null!=e&&(ze(t,r,0),De(t.i,e))}function kr(t,e,r){null!=(e=Ut(e))&&(e=parseInt(e,10),ze(t,r,0),Ce(t.i,e))}Z||(br=Q(br)?br?"1":"0":X(br)?br.trim()||"0":String(br));var xr,Ur=Ar(Ir,rr),Br=Ar(Ir,rr),Nr=Ar(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)),_t(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,i]=mt(t,e);t="-"+ft(r,i)}else t=ft(t,e);return t}if("number"===e){if(t=bt(t),!_t(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)Le(e);if(null!=e)switch(ze(t,r,0),typeof e){case"number":t=t.i,ht(e),Me(t,st,lt);break;case"bigint":r=Re(e,Fe,Te),Me(t.i,r.j,r.i);break;default:r=Le(e),Me(t.i,r.j,r.i)}}},tr),Fr=Ar(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(jt(t)){if("string"===e)return e=bt(Number(t)),_t(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&&_t(t)||(ht(t),t=ct(st,lt)),t}}(e),null!=e){if("string"==typeof e)Ee(e);if(null!=e)switch(ze(t,r,0),typeof e){case"number":t=t.i,ht(e),Me(t,st,lt);break;case"bigint":r=Re(e,Ie,Se),Me(t.i,r.j,r.i);break;default:r=Ee(e),Me(t.i,r.j,r.i)}}},er),Rr=Ar(Tr,Qe);xr=new ar(function(t,e,r){if(null!=(e=Er(Ut,e))&&e.length){r=He(t,r);for(let r=0;r<e.length;r++)Ce(t.i,e[r]);We(t,r)}},Qe);var Mr,Dr=Ar(Tr,Qe),Cr=Ar(Tr,Qe),Vr=Ar(Lr,Je),Gr=Ar(Lr,Je),zr=Ar(Pr,Xe);Mr=new ar(function(t,e,r){if(null!=(e=Er(Nt,e)))for(let s=0;s<e.length;s++){var i=t,o=r,a=e[s];null!=a&&$e(i,o,n(a))}},Xe);var Hr,Wr=Ar(Pr,Xe),$r=Ar(Pr,Xe),qr=function(t,e,r=Ye){return new ar(e,r)}(0,function(t,e,r,i,n){if(Array.isArray(e)){for(let o=0;o<e.length;o++)Or(t,e[o],r,i,n);1&(t=0|e[V])||H(e,1|t)}}),Kr=new ar(Or,Ye),Yr=Ar(jr,Ze),Jr=Ar(kr,nr);Hr=new ar(function(t,e,r){if(null!=(e=Er(Ut,e))&&e.length){r=He(t,r);for(let r=0;r<e.length;r++)Ce(t.i,e[r]);We(t,r)}},nr);var Xr=Ar(kr,nr);function Qr(t){return function(){var e=new qe;_r(this.m,e,pr(t)),Ge(e,e.i.end());var r=new Uint8Array(e.j),i=e.l,n=i.length,o=0;for(let t=0;t<n;t++){let e=i[t];r.set(e,o),o+=e.length}return e.l=[r],r}}function Zr(t,e){if(null!=e)if(Array.isArray(e))Xt(t,2,Mt(e,0,Dt));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 ti,ei=class extends or{constructor(t){super(t)}},ri=[0,Wr,Ar(function(t,e,r){if(null!=e){if(e instanceof or){let i=e.ra;return void(i?(e=i(e),null!=e&&$e(t,r,be(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)&&$e(t,r,be(e).buffer)},ir)],ii=globalThis.trustedTypes;var ni=class{constructor(t){this.i=t}toString(){return this.i+""}};function oi(t){var e;return void 0===ti&&(ti=function(){var t=null;if(!ii)return t;try{let e=t=>t;t=ii.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(t){}return t}()),t=(e=ti)?e.createScriptURL(t):t,new ni(t)}function ai(t,...e){if(0===e.length)return oi(t[0]);var r=t[0];for(let i=0;i<e.length;i++)r+=encodeURIComponent(e[i])+t[i+1];return oi(r)}var si=[0,Jr,-1,Vr],li={};li[336783863]=[0,zr,Vr,-1,Rr,[0,[1,2,3,4,5,6,7,8,9],Kr,[0],Kr,[0,Vr,zr,Vr,Jr,-1,Hr,zr,-1,[0,Vr,-1],Jr,Vr,-1,si],Kr,[0,zr,-2],Kr,[0,Rr,Vr,1,Vr,-4],Kr,[0,Rr,Jr,Vr,-1,xr,Jr,-1,Vr,-1],Kr,[0,zr,-2],Kr,[0,zr,Jr],Kr,[0,3,Vr,-1,2,[0,[2],Rr,Kr,[0,Ar(jr,Ze)]],[0,Jr,Vr,Jr,Vr,Jr,Vr,zr,-1],[0,[3,4],zr,-1,Kr,[0,Rr],Kr,[0,Jr]],[0]],Kr,si],[0,zr],Vr,[0,[1,3],[2,4],Kr,[0,xr],-1,Kr,[0,Mr],-1,qr,[0,zr,-1]],zr];var ui=class extends or{constructor(t){super(t)}},hi=[0,Nr,-1,Gr,-3,Nr,xr,Wr,Dr,Nr,-1,Gr,Dr,Gr,-2,Wr],ci=class extends or{constructor(t){super(t,500)}N(t){return he(this,7,t)}},fi=[-1,{}],di=[0,zr,1,fi],pi=[0,zr,Mr,fi];function mi(t,e){fe(t,1,ci,e)}var gi=class extends or{constructor(t){super(t,500)}N(t){return he(this,1001,t)}};gi.prototype.j=Qr([-500,qr,[-500,Wr,-1,Mr,-3,[-2,li,Vr],qr,ri,Dr,-1,di,pi,qr,[0,Wr,Gr],Wr,hi,Dr,Mr,987,Mr],4,qr,[-500,zr,-1,[-1,{}],998,zr],qr,[-500,zr,Mr,-1,[-2,{},Vr],997,Mr,-1],Dr,qr,[-500,zr,Mr,fi,998,Mr],Mr,Dr,di,pi,qr,[0,Wr,-1,fi],Mr,-2,hi,Wr,-1,Gr,[0,Gr,Yr],978,fi,qr,ri]);var vi,yi=class extends or{constructor(t){super(t)}},_i=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 wi(t){if(t)return!0;if(void 0===vi)try{await WebAssembly.instantiate(_i),vi=!0}catch{vi=!1}return vi}async function bi(t,e,r){return{wasmLoaderPath:`${e}/${t}_${r=`wasm${r?"_module":""}${await wi(r)?"":"_nosimd"}_internal`}.js`,wasmBinaryPath:`${e}/${t}_${r}.wasm`}}var Si=class{};Si.forVisionTasks=function(t,e=!1){return bi("vision",t??ai``,e)},Si.forTextTasks=function(t,e=!1){return bi("text",t??ai``,e)},Si.forGenAiTasks=function(t,e=!1){return bi("genai",t??ai``,e)},Si.forAudioTasks=function(t,e=!1){return bi("audio",t??ai``,e)},Si.isSimdSupported=function(t=!1){return wi(t)};var Ei=class{close(){}};function Ai(t){function e(e,r){return new ReadableStream({start(){},async pull(i){n=n.then(async()=>{if(e.cache.length>0)i.enqueue(e.cache.shift());else{var{value:n,done:o}=await t.read();n&&(r.active&&r.cache.push(n),e.active&&i.enqueue(n)),o&&i.close()}}),await n},cancel(){e.active=!1,e.cache.length=0,r.active||t.cancel()}})}var r={cache:[],active:!0},i={cache:[],active:!0},n=Promise.resolve(),o=e(r,i);return r=e(i,r),[o.getReader(),r.getReader()]}async function Ii(t,e){for(var r=new Uint8Array(e),i=0;i<e;){let{value:n,done:o}=await t.read();if(n){let t=n.subarray(0,e-i);r.set(t,i),i+=t.length}if(o)throw Error(`Expected ${e} bytes, but stream ended after reading ${i} bytes.`)}return await t.cancel(),r}var Ti=[[0,async t=>{var e=(new TextEncoder).encode("TFL3").length;return t=await Ii(t,e+4),"TFL3"===new TextDecoder("utf-8").decode(t.subarray(4,e+4))}],[1,async t=>80===(t=await Ii(t,6))[4]&&75===t[5]],[2,async t=>(t=await Ii(t,8),"LITERTLM"===new TextDecoder("utf-8").decode(t))]];async function Li(t,e){var r=new Uint8Array(e),i=0;if(t.i){var n=Math.min(e,t.i.length);r.set(t.i.subarray(0,n),0),(i+=n)<t.i.length?t.i=t.i.subarray(i):t.i=void 0}for(;i<e;){let{value:o,done:a}=await t.stream.read();if(o&&(n=o.subarray(0,e-i),r.set(n,i),o.length>n.length&&(t.i=o.subarray(e-i)),i+=n.length),a)throw Error(`Expected ${e} bytes, but stream ended after reading ${i} bytes.`)}return r}class Pi{constructor(t){this.stream=t,this.i=void 0,this.closed=this.stream.closed}async read(){if(this.i){let t=this.i.slice();return this.i=void 0,{value:t,done:!1}}return this.stream.read()}cancel(t){return this.stream.cancel(t)}releaseLock(){return this.stream.releaseLock()}}function Oi(){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 ji(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 ki(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 xi(t,e,r){t.o||console.error("No wasm multistream support detected: ensure dependency inclusion of :gl_graph_runner_internal_multi_input target");var i=new Uint32Array(e.length);for(let r=0;r<e.length;r++)i[r]=t.h.stringToNewUTF8(e[r]);e=t.h._malloc(4*i.length),t.h.HEAPU32.set(i,e>>2),r(e);for(let e of i)t.h._free(e);t.h._free(e)}function Ui(t,e,r){t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=r}function Bi(t,e,r){var i=[];t.h.simpleListeners=t.h.simpleListeners||{},t.h.simpleListeners[e]=(t,e,n)=>{e?(r(i,n),i=[]):i.push(t)}}var Ni,Fi=(Ni=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:Oi()?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,i=this.h._malloc(r);this.h.HEAPU8.set(t,i),e?this.h._changeBinaryGraph(r,i):this.h._changeTextGraph(r,i),this.h._free(i)}configureAudio(t,e,r,i,n){this.h._configureAudio||console.warn('Attempting to use configureAudio without support for input audio. Is build dep ":gl_graph_runner_audio" missing?'),ki(this,i||"input_audio",i=>{ki(this,n=n||"audio_header",n=>{this.h._configureAudio(i,n,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,i,n){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),ki(this,i,t=>{this.h._addAudioToInputStream(this.i,e,r,t,n)})}addGpuBufferToStream(t,e,r){ki(this,e,e=>{if(!this.h.canvas)throw Error("No OpenGL canvas configured.");e?this.h._bindTextureToStream(e):this.h._bindTextureToCanvas();var i=this.h.canvas.getContext("webgl2")||this.h.canvas.getContext("webgl");if(!i)throw Error("Failed to obtain WebGL context from the provided canvas. `getContext()` should only be invoked with `webgl` or `webgl2`.");this.h.gpuOriginForWebTexturesIsBottomLeft&&i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),this.h.gpuOriginForWebTexturesIsBottomLeft&&i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1);var[n,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||n===this.h.canvas.width&&o===this.h.canvas.height||(this.h.canvas.width=n,this.h.canvas.height=o);var[a,s]=[n,o];this.h._addBoundTextureToStream(e,a,s,r)})}addBoolToStream(t,e,r){ki(this,e,e=>{this.h._addBoolToInputStream(t,e,r)})}addDoubleToStream(t,e,r){ki(this,e,e=>{this.h._addDoubleToInputStream(t,e,r)})}addFloatToStream(t,e,r){ki(this,e,e=>{this.h._addFloatToInputStream(t,e,r)})}addIntToStream(t,e,r){ki(this,e,e=>{this.h._addIntToInputStream(t,e,r)})}addUintToStream(t,e,r){ki(this,e,e=>{this.h._addUintToInputStream(t,e,r)})}addStringToStream(t,e,r){ki(this,e,e=>{ki(this,t,t=>{this.h._addStringToInputStream(t,e,r)})})}addStringRecordToStream(t,e,r){ki(this,e,e=>{xi(this,Object.keys(t),i=>{xi(this,Object.values(t),n=>{this.h._addFlatHashMapToInputStream(i,n,Object.keys(t).length,e,r)})})})}addProtoToStream(t,e,r,i){ki(this,r,r=>{ki(this,e,e=>{var n=this.h._malloc(t.length);this.h.HEAPU8.set(t,n),this.h._addProtoToInputStream(n,t.length,e,r,i),this.h._free(n)})})}addEmptyPacketToStream(t,e){ki(this,t,t=>{this.h._addEmptyPacketToInputStream(t,e)})}addBoolVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateBoolVector(t.length);if(!i)throw Error("Unable to allocate new bool vector on heap.");for(let e of t)this.h._addBoolVectorEntry(i,e);this.h._addBoolVectorToInputStream(i,e,r)})}addDoubleVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateDoubleVector(t.length);if(!i)throw Error("Unable to allocate new double vector on heap.");for(let e of t)this.h._addDoubleVectorEntry(i,e);this.h._addDoubleVectorToInputStream(i,e,r)})}addFloatVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateFloatVector(t.length);if(!i)throw Error("Unable to allocate new float vector on heap.");for(let e of t)this.h._addFloatVectorEntry(i,e);this.h._addFloatVectorToInputStream(i,e,r)})}addIntVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateIntVector(t.length);if(!i)throw Error("Unable to allocate new int vector on heap.");for(let e of t)this.h._addIntVectorEntry(i,e);this.h._addIntVectorToInputStream(i,e,r)})}addUintVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateUintVector(t.length);if(!i)throw Error("Unable to allocate new unsigned int vector on heap.");for(let e of t)this.h._addUintVectorEntry(i,e);this.h._addUintVectorToInputStream(i,e,r)})}addStringVectorToStream(t,e,r){ki(this,e,e=>{var i=this.h._allocateStringVector(t.length);if(!i)throw Error("Unable to allocate new string vector on heap.");for(let e of t)ki(this,e,t=>{this.h._addStringVectorEntry(i,t)});this.h._addStringVectorToInputStream(i,e,r)})}addBoolToInputSidePacket(t,e){ki(this,e,e=>{this.h._addBoolToInputSidePacket(t,e)})}addDoubleToInputSidePacket(t,e){ki(this,e,e=>{this.h._addDoubleToInputSidePacket(t,e)})}addFloatToInputSidePacket(t,e){ki(this,e,e=>{this.h._addFloatToInputSidePacket(t,e)})}addIntToInputSidePacket(t,e){ki(this,e,e=>{this.h._addIntToInputSidePacket(t,e)})}addUintToInputSidePacket(t,e){ki(this,e,e=>{this.h._addUintToInputSidePacket(t,e)})}addStringToInputSidePacket(t,e){ki(this,e,e=>{ki(this,t,t=>{this.h._addStringToInputSidePacket(t,e)})})}addProtoToInputSidePacket(t,e,r){ki(this,r,r=>{ki(this,e,e=>{var i=this.h._malloc(t.length);this.h.HEAPU8.set(t,i),this.h._addProtoToInputSidePacket(i,t.length,e,r),this.h._free(i)})})}addBoolVectorToInputSidePacket(t,e){ki(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){ki(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){ki(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){ki(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){ki(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){ki(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)ki(this,e,t=>{this.h._addStringVectorEntry(r,t)});this.h._addStringVectorToInputSidePacket(r,e)})}attachBoolListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachBoolListener(t)})}attachBoolVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachBoolVectorListener(t)})}attachIntListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachIntListener(t)})}attachIntVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachIntVectorListener(t)})}attachUintListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachUintListener(t)})}attachUintVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachUintVectorListener(t)})}attachDoubleListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachDoubleListener(t)})}attachDoubleVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachDoubleVectorListener(t)})}attachFloatListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachFloatListener(t)})}attachFloatVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachFloatVectorListener(t)})}attachStringListener(t,e){Ui(this,t,e),ki(this,t,t=>{this.h._attachStringListener(t)})}attachStringVectorListener(t,e){Bi(this,t,e),ki(this,t,t=>{this.h._attachStringVectorListener(t)})}attachProtoListener(t,e,r){Ui(this,t,e),ki(this,t,t=>{this.h._attachProtoListener(t,r||!1)})}attachProtoVectorListener(t,e,r){Bi(this,t,e),ki(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?'),Ui(this,t,(t,r)=>{t=new Float32Array(t.buffer,t.byteOffset,t.length/4),e(t,r)}),ki(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 Ni{la(){this.h._registerModelResourcesGraphService()}});async function Ri(t,e){var r=await(async(t,e,r)=>{var i=An;if(t&&await ji(t),!self.ModuleFactory)throw Error("ModuleFactory not set.");if(e&&(await ji(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 i(r,null)})(t.wasmLoaderPath,t.assetLoaderPath,{locateFile:e=>e.endsWith(".wasm")?t.wasmBinaryPath.toString():t.assetBinaryPath&&e.endsWith(".data")?t.assetBinaryPath.toString():e});return r.ka=new Ei,await r.N(e),r}async function Mi(t,e){return Ri(t,e)}function Di(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 Ci(t,e){t.I=Math.max(t.I,e)}var Vi=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.la(),this.j.setGraph(t,e),Di(this)}finishProcessing(){this.j.finishProcessing(),Di(this)}close(){this.ka?.close(),this.j.closeGraph()}};Vi.prototype.close=Vi.prototype.close;var Gi=class extends or{constructor(t){super(t)}j(){return Ut(Yt(this,2))??0}};function zi(t,e){he(t,1,e)}var Hi=class extends or{constructor(t){super(t)}},Wi=[0,Xr,Dr,Br,-1,Rr];function $i(t,e,r,i){if(void 0!==t.data){var n=new Uint8Array(t.data.buffer,e,r);return 1===i&&function(t,e,r){t.i.push([e,r]),t.i.sort((t,e)=>t[0]-e[0]),e=0;for(let[i,n]of t.i){let t=n;(r=i)<=e&&(e=Math.max(e,r+t))}e===t.length&&(t.data=void 0)}(t,e,r),n}}Gi.prototype.l=Qr(Wi);class qi{constructor(t){this.i=[],this.data=t,this.length=t.length}}function Ki(t,e){return new Ji(async()=>{var{value:e,done:r}=await t.read();return r?void 0:e},e)}async function Yi(t,e,r,i,n){if(2===n)return t.i=[],t.j=()=>Promise.resolve(void 0),setTimeout(()=>{t.l()},0),Promise.resolve(0);for(;t.size<r+i;){var o=await t.j();if(void 0===o)break;t.i.push(new qi(o))}if(t.size<r+i)throw Error(`Data size is too small: ${t.size}, expected at least ${r+i}.`);o=e._malloc(i)>>>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(i,l.length-r);if(void 0===(r=$i(l,r,u,n)))throw Error("Data has already been released.");if(e.HEAPU8.set(r,o+a),r=0,a+=u,0===(i-=u))break}if(0!==i)throw Error("Data not found.");return Promise.resolve(o)}var Ji=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 Xi(t){return"object"==typeof t&&null!=t&&"imageSource"in t}function Qi(t){return"object"==typeof t&&null!=t&&"audioSource"in t}async function Zi(t,e,r){t=new en(t,r);var i=0;for(e=e.getReader();;){let{value:r,done:n}=await e.read();if(n)break;t.set(r,i),i+=r.byteLength}if(r!==i)throw tn(t),Error(`File could not be fully loaded to memory, so was not retained. Loaded ${i}/${r} bytes before failure`);return t}function tn(t){if(t.i)try{t.h._free(t.j)}catch{}finally{t.i=!1}}var en=class{constructor(t,e){this.h=t,this.l=e,this.j=this.h._malloc(e)>>>0,this.o=this.h.HEAPU8,this.i=!!this.j}get offset(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.j}get size(){if(!this.i)throw Error("WasmFileReference has been freed.");return this.l}set(t,e){this.o.set(t,this.j+(e??0))}},rn=class extends or{constructor(t){super(t)}};rn.prototype.j=Qr([0,Wr,2,Mr,Dr,Gr]);var nn=class extends or{constructor(t){super(t)}},on=class extends or{constructor(t){super(t)}},an=class extends or{constructor(t){super(t)}},sn=class extends or{constructor(t){super(t)}},ln=[0,Dr,-6,1,Dr,1,[0,Gr,Xr,-2],[0,Gr,Br],Xr,-2,[0,Gr,-1,Xr,Br,Jr,Rr,Vr,-2],1,Gr,Dr,Rr,-1,[0,Xr,Dr],Gr,-1,Ur,Dr,-5,Ur,-1,[0,Rr,Ur],Rr,Vr,[0,Rr,-2],Ur,[0,Dr],[0,Dr,-4],Vr,Rr,-2,Vr,-1,Br,Ur,Vr,Dr,-1,[0,Rr,-2],Gr,Dr,Rr,Vr,[0,Rr,-1],Rr,Vr,-1],un=[0,Wr,-2],hn=[0,[4,6],ln,Dr,1,Cr,Mr,$r,Hr,un,Rr,[0,[0,Dr,-1,qr,[0,Dr,[0,Dr,-1],-1,[0,Xr,-1],Gr],Gr,-2,Dr,-1],[0,Dr,-1,Gr],ln,Gr,Dr,[0,Dr],-1],zr,-3,[0,Dr,Gr],ln,[0,un,-2],xr,qr,[0,Wr,-2],xr];sn.prototype.j=Qr([0,Wr,8,[0,Gr,-6],1,Dr,1,Dr,[0,qr,[0,Wr,Fr,-1,Xr],hn,Dr],[0,Dr,Gr,-3],1,Xr,1,hn,1,Dr,5,Xr,xr,1,Wi,Gr,Dr,Gr,-1]);var cn=class extends or{constructor(t){super(t)}},fn=class extends or{constructor(t){super(t)}},dn=[2,4];fn.prototype.j=Qr([0,dn,Dr,$r,Dr,Kr,[0,1,Wr]]);var pn=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=Ki(t,()=>{});await this.h.createLlmInferenceEngine(de(e,2)??512,le(e,Gi,3)?.j()??40,It(Yt(e,6))??!1??!1,de(e,7)??0,It(Yt(e,8))??!1??!1,(t,e,i)=>Yi(r,this.h,t,e,i))}finally{this.L()}}async ba(t,e){this.M();try{await this.na(t),await this.h.ccall("CreateLlmInferenceEngineConverted","void",["number","number","boolean"],[de(e,2)??512,le(e,Gi,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 i=[],n=this.h;n._userProgressListener=(t,e)=>{t&&i.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(Qi),u=t.some(Xi);n.ccallNum=n.ccall;let h=await n.ccallNum("MakeSessionForPredict","number",["number","number","boolean","boolean"],[s,a,u,l],{async:!0});e=[];for(let r of t)if("string"==typeof r)ki(this,r,t=>{n._AddTextQueryChunk(h,t)});else if(Xi(r)){let{image:t,width:i,height:o}=await this.fa(r.imageSource),a="undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(i,o):document.createElement("canvas");a.width=i,a.height=o;let s=a.getContext("2d");s.drawImage(t,0,0);let l=s.getImageData(0,0,i,o),u=this.h._malloc(l.width*l.height*4);this.h.HEAPU8.set(l.data,u),n._AddImageQueryChunk(h,u,l.width,l.height),e.push(u)}else{if(!Qi(r))throw Error("Unsupported PromptPart type in query.");{let t=await this.ea(r.audioSource),i=this.h._malloc(t.audioSamples.byteLength);this.h.HEAPF32.set(t.audioSamples,i/4),n._AddAudioQueryChunk(h,t.audioSampleRateHz,i,t.audioSamples.length),e.push(i)}}await n.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&&n._FreeSession(h);for(let t of e)this.h._free(t);return e.length=0,r&&r("",!0),this.h._free(s),n._userProgressListener=void 0,i.join("")}finally{this.L()}}S(t){this.M();var e=0,r="";for(let i of t)"string"==typeof i?r+=i:Xi(i)?e+=260:Qi(i)&&console.warn("sizeInTokens is not yet implemented for audio; audio tokens will not be counted");try{let t;return ki(this,r,e=>{t=this.h._GetSizeInTokens(e)}),e+t}finally{this.L()}}async na(t){t=await async function(t){for(var e=[],r=0;;){let{done:i,value:n}=await t.read();if(i)break;e.push(n),r+=n.length}if(0===e.length)return new Uint8Array(0);if(1===e.length)return e[0];t=new Uint8Array(r),r=0;for(let i of e)t.set(i,r),r+=i.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 ma(t,r){r||=await e.X();var i=[];for(let e of t?.requiredFeatures??[])r.features.has(e)?i.push(e):console.warn(`WebGPU feature ${e} is not supported.`);t={...t,requiredFeatures:i};try{var 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,i)=>Yi(t,this.h,e,r,i),e)}}}(function(t){return class extends t{Y(t,e){ki(this,"lora_model_ref_in",r=>{this.h._addRawDataSpanToInputStream(t.offset,t.size,r,e)})}}}(class extends Fi{}))));class mn extends pn{}var gn=class{constructor(t){this.j=t,this.i=vn,vn++}},vn=1;class yn{constructor(){var t,e;this.promise=new Promise((r,i)=>{t=r,e=i}),this.resolve=t,this.reject=e}}function _n(t){return 1===t?1:t+t%2}async function wn(){var t=await mn.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"]),mn.ma(e,t)}function bn(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 Sn(t){var e=function(t){var e=new gi;_e(e,10,"text_in"),_e(e,10,"token_cost_in"),_e(e,10,"lora_model_id_to_apply_in"),_e(e,10,"lora_model_ref_in"),_e(e,10,"lora_model_id_to_load_in"),_e(e,16,"streaming_reader"),_e(e,15,"text_out"),_e(e,15,"text_end"),_e(e,15,"token_cost_out");var r=new ci;ye(r,2,"TokenizerInputBuildCalculator"),_e(r,3,"PROMPT:text_in"),_e(r,3,"LORA_ID:lora_model_id_to_apply_in"),_e(r,4,"prompt"),mi(e,r),r=new ci,ye(r,2,"ModelDataCalculator"),_e(r,6,"MODEL_DATA:__side_packet_1"),_e(r,6,"MODEL_TYPE:model_type"),_e(r,5,"READ_DATA_FN:streaming_reader"),_e(r,3,"LORA_MODEL_SPAN:lora_model_ref_in"),_e(r,3,"LORA_MODEL_ID:lora_model_id_to_load_in"),_e(r,4,"LORA_DATA:lora_model_data"),mi(e,r),r=new ci,ye(r,2,"Gpt2UnicodeMappingCalculator"),_e(r,5,"MODEL_TYPE:model_type"),_e(r,6,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),mi(e,r),r=new ei,ye(r,1,"type.googleapis.com/odml.infra.proto.TokenizerCalculatorOptions");var i=new fn,n=de(t.i,2);ge(i,1,n),ye(n=new cn,2,"spm_vocab_model"),n=ue(n);t:{$t(i);var o=i.m,a=0|o[V];if(null==n){var s=ae(o);if(4!==se(s,o,a))break t;s.set(dn,0)}else{let t=ae(s=o),e=se(t,s,a);4!==e&&(e&&(a=Qt(s,a,e)),t.set(dn,4))}Qt(o,a,4,n)}return n&&!$(n)&&qt(i.m),ge(i,3,2),Zr(r,i.j()),ye(i=new ci,2,"TokenizerCalculator"),fe(i,8,ei,r),_e(i,5,"MODEL_DATA:__side_packet_1"),_e(i,3,"PROMPT_AND_INPUT_OPTIONS:prompt"),_e(i,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(i,6,"PROCESSOR_GETTER:__input_side_1"),_e(i,4,"IDS_AND_INPUT_OPTIONS:__stream_0"),mi(e,i),r=new ei,ye(r,1,"type.googleapis.com/odml.infra.proto.LlmGpuCalculatorOptions"),ge(i=new sn,12,3),ye(i,1,"llm.tflite"),ge(i,14,0),n=_n(de(t.i,5)),ge(i,22,n),n=le(t.i,Gi,3),he(i,31,n),me(n=new nn,1,!0),null!=It(Yt(t.i,6))&&(It(Yt(t.i,6))??!1)&&me(n,1,!1),me(n,2,!0),me(n,5,!0),he(i,10,n),n=Zt(t.i,4,Ut,void 0===K?2:4),ne(i,29,n),n=new an,ge(o=new on,1,1),s=de(t.i,2),ge(o,2,s),null!=It(Yt(t.i,9))&&(It(Yt(t.i,9))??!1)&&(me(i,35,!0),pe(o,60,!0)),he(n,1,o),he(i,20,n),Zr(r,i.j()),ye(i=new ci,2,"LlmGpuCalculator"),fe(i,8,ei,r),_e(i,3,"IDS_AND_INPUT_OPTIONS:__stream_0"),_e(i,3,"FINISH:finish"),_e(i,3,"LORA_DATA:lora_model_data"),_e(i,5,"MODEL_DATA:__side_packet_1"),_e(i,4,"DECODED_IDS:__stream_3"),_e(i,4,"OUTPUT_END:__stream_4"),r=new ui,ye(r,1,"FINISH"),me(r,2,!0),fe(i,13,ui,r),mi(e,i),r=new ci,ye(r,2,"IsPacketPresentCalculator"),_e(r,3,"__stream_4"),_e(r,4,"text_end"),mi(e,r),r=new ei,ye(r,1,"type.googleapis.com/odml.infra.proto.DetokenizerCalculatorOptions"),i=new rn,t=_n(de(t.i,5)),ge(i,5,t),_e(i,4,"<eos>"),_e(i,4,"<|endoftext|>"),Zr(r,i.j()),t=new ci,ye(t,2,"DetokenizerCalculator"),fe(t,8,ei,r),_e(t,3,"IDS_AND_INPUT_OPTIONS:__stream_3"),_e(t,5,"PROCESSOR_GETTER:__input_side_1"),_e(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(t,5,"MODEL_DATA:__side_packet_1"),_e(t,4,"FINISH_AND_INPUT_OPTIONS:finish"),_e(t,4,"WORDS:text_out"),mi(e,t),t=new ci,ye(t,2,"TokenCostCalculator"),_e(t,3,"PROMPT:token_cost_in"),_e(t,5,"PROCESSOR_GETTER:__input_side_1"),_e(t,5,"BYTES_TO_UNICODE_MAPPING:tokenizer_mapping"),_e(t,4,"NUM_TOKENS:token_cost_out"),mi(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)),Ci(t,r)}),t.j.attachEmptyPacketListener("text_out",e=>{Ci(t,e)}),t.j.attachBoolListener("text_end",(e,r)=>{Ci(t,r);try{bn(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,Ci(t,e),bn(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,Ci(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 En(t,e,r,i){if(t.A="function"==typeof r?r:i,(i=(e=Array.isArray(e)?e:[e]).filter(t=>Xi(t)).length)>0&&(null==Bt(Yt(t.i,7))||de(t.i,7)<i))throw Error(`maxNumImages is set to ${null!=Bt(Yt(t.i,7))?de(t.i,7):0}, but the query included ${i} images.`);if((i=e.filter(t=>Qi(t)).length)>0&&(null==It(Yt(t.i,8))||!It(Yt(t.i,8))))throw Error(`supportAudio was not enabled, but the query included ${i} 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 gn)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=>(bn(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,i=0;i<de(t.i,5);i++)t.G[i]=[];if(i=t.I+1,t.j.addStringToStream(e.join(""),"text_in",i),r instanceof gn){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",i)}else t.j.addEmptyPacketToStream("lora_model_id_to_apply_in",i);return t.finishProcessing(),t.o=new yn,t.o.promise}var An=class extends Vi{constructor(t,e){if(super(new mn(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 Hi,zi(this.i,new yi),this.u=new Gi,he(this.i,3,this.u),ve(this.i,2,512),t=this.u,!wt(2))throw P("enum");oe(t,1,2,0),ge(this.u,2,40),oe(this.u,3,St(1),0),Xt(this.u,5,xt(0)),oe(this.u,4,St(.8),0),ve(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 i=await fetch(t.baseOptions.modelAssetPath.toString());if(!i.ok)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (${i.status})`);if(!i.body)throw Error(`Failed to fetch model: ${t.baseOptions.modelAssetPath} (no body)`);i=i.body.getReader()}else t.baseOptions?.modelAssetBuffer instanceof Uint8Array?i=function(t){return new ReadableStream({start(){},async pull(e){e.enqueue(t),e.close()}})}(t.baseOptions.modelAssetBuffer).getReader():t.baseOptions?.modelAssetBuffer instanceof ReadableStreamDefaultReader?(i=t.baseOptions.modelAssetBuffer,t.baseOptions.modelAssetBuffer=void 0):e();if(!i)throw Error("No model asset provided.");{let[r,a]=Ai(i);var n=await async function(t){var e,r=[];for(let[n,o]of Ti){let a=n;var i=o;[t,e]=Ai(t),i=await i(e),await e.cancel(),i&&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);this.O=1===n;var o=null;if(2===n){let t=this.j.h;o=await async function(t,e){t=new Pi(t);var r=await Li(t,32);if(r=new DataView(r.buffer),r=Number(r.getBigUint64(24,!0)),(e=e(await Li(t,r-32)))<0)throw Error(".litertlm file could not be read or did not contain a web-formatted LLM");return await Li(t,e-r),t}(r,e=>{var r=t._malloc(e.length);return t.HEAPU8.set(e,r),e=t._GetLiteRtModelOffset(r),t._free(r),e})}n="maxNumImages"in t&&t.maxNumImages?t.maxNumImages:0,ve(this.i,7,n);let s="supportAudio"in t&&!!t.supportAudio;pe(this.i,8,s),this.O||n>0||s?(this.v=!0,i=o||r):(this.v=!1,this.U=Ki(o||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&&ve(this.i,2,t.maxTokens??512),"topK"in t&&ge(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){ne(t,4,e)}(this.i,t.loraRanks??[]),"numResponses"in t){if((o=t.numResponses??1)<1)throw Error("'numResponses' must be at least 1.");if(this.v&&o>1)throw Error("'numResponses > 1' is not supported for converted LLM models yet, and is also not supported with multimodality.");ve(this.i,5,o),n=le(this.i,Gi,3),o>1&&n&&(n.j()<=1||(Yt(n,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.")}if("forceF32"in t&&void 0!==t.forceF32&&pe(this.i,6,t.forceF32),"disableRewinding"in t&&void 0!==t.disableRewinding){if(this.v&&t.disableRewinding)throw Error("'disableRewinding' is not supported for converted LLM models yet, and is also not supported with multimodality.");pe(this.i,9,t.disableRewinding)}return this.v?(this.j.V(),this.O?this.j.ba(i,this.i).then(()=>{bn(this)}):this.j.createLlmInferenceEngine(i,this.i).then(()=>{bn(this)})):(this.l=!0,t=Sn(this).then(()=>{}),Promise.all([r,t]).then(()=>{this.l=!1,bn(this)}))}get baseOptions(){return le(this.i,yi,1)}set baseOptions(t){zi(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,En(this,t,e,r).then(t=>t[0])}da(t,e,r){return this.B=!0,En(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(Xi))throw Error("sizeInTokens requires maxNumImages > 0 for images.");if(t.some(Qi))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 en(this.j.h,t.length);e.set(t),t=e}else t=t instanceof Blob?await async function(t,e){return Zi(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 Zi(t,e.body,r)}(this.j.h,t);e=new gn(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(),tn(t),Ci(this,r),this.l=!1,e}close(){this.v&&this.j.V(),this.C?.removeEventListener("uncapturederror",this.K),super.close()}};An.prototype.loadLoraModel=An.prototype.ja,An.prototype.cancelProcessing=An.prototype.Z,An.prototype.sizeInTokens=An.prototype.S,An.prototype.generateResponses=An.prototype.da,An.prototype.generateResponse=An.prototype.R,An.prototype.setOptions=An.prototype.N,An.createWebGpuDevice=wn,An.createFromModelPath=async function(t,e){return Mi(t,e={baseOptions:{gpuOptions:{device:await wn()},modelAssetPath:e}})},An.createFromModelBuffer=async function(t,e){return Mi(t,e={baseOptions:{gpuOptions:{device:await wn()},modelAssetBuffer:e}})},An.createFromOptions=async function(t,e){if(!e.baseOptions?.gpuOptions?.device){let t=await wn();e.baseOptions=e.baseOptions??{},e.baseOptions.gpuOptions=e?.baseOptions?.gpuOptions??{},e.baseOptions.gpuOptions.device=t}return Mi(t,e)},exports.FilesetResolver=Si,exports.LlmInference=An,exports.TaskRunner=Vi;
|
|
2
2
|
//# sourceMappingURL=genai_bundle_cjs.js.map
|