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