@bitte-ai/chat
Version:
Bitte AI chat component
1 lines • 192 kB
JavaScript
'use strict';var ai=require('ai'),he=require('react'),jotai=require('jotai'),react=require('@ai-sdk/react'),Ko=require('swr'),clsx=require('clsx'),format_js=require('near-api-js/lib/utils/format.js'),tailwindMerge=require('tailwind-merge'),lucideReact=require('lucide-react'),jsxRuntime=require('react/jsx-runtime'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),Ft=require('@radix-ui/react-dialog'),vaul=require('vaul'),Wr=require('@radix-ui/react-label'),Em=require('fast-deep-equal'),framerMotion=require('framer-motion'),yi=require('recharts'),sc=require('react-markdown'),lc=require('remark-gfm'),cc=require('remark-math'),Yt=require('@radix-ui/react-accordion'),viem=require('viem'),utils=require('jotai/utils'),nearSafe=require('near-safe'),Jc=require('randombytes'),getLatestGasPrice_js=require('@mintbase-js/rpc/lib/methods/getLatestGasPrice.js'),transactions=require('@mysten/sui/transactions');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var he__namespace=/*#__PURE__*/_interopNamespace(he);var Ko__default=/*#__PURE__*/_interopDefault(Ko);var Ft__namespace=/*#__PURE__*/_interopNamespace(Ft);var Wr__namespace=/*#__PURE__*/_interopNamespace(Wr);var Em__default=/*#__PURE__*/_interopDefault(Em);var yi__namespace=/*#__PURE__*/_interopNamespace(yi);var sc__default=/*#__PURE__*/_interopDefault(sc);var lc__default=/*#__PURE__*/_interopDefault(lc);var cc__default=/*#__PURE__*/_interopDefault(cc);var Yt__namespace=/*#__PURE__*/_interopNamespace(Yt);var Jc__default=/*#__PURE__*/_interopDefault(Jc);var ps=Object.create;var Wo=Object.defineProperty;var bs=Object.getOwnPropertyDescriptor;var hs=Object.getOwnPropertyNames;var gs=Object.getPrototypeOf,vs=Object.prototype.hasOwnProperty;var xs=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var ys=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var ws=(i,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of hs(e))!vs.call(i,a)&&a!==o&&Wo(i,a,{get:()=>e[a],enumerable:!(s=bs(e,a))||s.enumerable});return i};var _i=(i,e,o)=>(o=i!=null?ps(gs(i)):{},ws(!i||!i.__esModule?Wo(o,"default",{value:i,enumerable:true}):o,i));var pi=ys((ta,Sr)=>{(function(i,e){function o(f,t){if(!f)throw new Error(t||"Assertion failed")}function s(f,t){f.super_=t;var n=function(){};n.prototype=t.prototype,f.prototype=new n,f.prototype.constructor=f;}function a(f,t,n){if(a.isBN(f))return f;this.negative=0,this.words=null,this.length=0,this.red=null,f!==null&&((t==="le"||t==="be")&&(n=t,t=10),this._init(f||0,t||10,n||"be"));}typeof i=="object"?i.exports=a:e.BN=a,a.BN=a,a.wordSize=26;var b;try{typeof window<"u"&&typeof window.Buffer<"u"?b=window.Buffer:b=xs("buffer").Buffer;}catch{}a.isBN=function(t){return t instanceof a?true:t!==null&&typeof t=="object"&&t.constructor.wordSize===a.wordSize&&Array.isArray(t.words)},a.max=function(t,n){return t.cmp(n)>0?t:n},a.min=function(t,n){return t.cmp(n)<0?t:n},a.prototype._init=function(t,n,l){if(typeof t=="number")return this._initNumber(t,n,l);if(typeof t=="object")return this._initArray(t,n,l);n==="hex"&&(n=16),o(n===(n|0)&&n>=2&&n<=36),t=t.toString().replace(/\s+/g,"");var m=0;t[0]==="-"&&(m++,this.negative=1),m<t.length&&(n===16?this._parseHex(t,m,l):(this._parseBase(t,n,m),l==="le"&&this._initArray(this.toArray(),n,l)));},a.prototype._initNumber=function(t,n,l){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(o(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),n,l);},a.prototype._initArray=function(t,n,l){if(o(typeof t.length=="number"),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var c,h,g=0;if(l==="be")for(m=t.length-1,c=0;m>=0;m-=3)h=t[m]|t[m-1]<<8|t[m-2]<<16,this.words[c]|=h<<g&67108863,this.words[c+1]=h>>>26-g&67108863,g+=24,g>=26&&(g-=26,c++);else if(l==="le")for(m=0,c=0;m<t.length;m+=3)h=t[m]|t[m+1]<<8|t[m+2]<<16,this.words[c]|=h<<g&67108863,this.words[c+1]=h>>>26-g&67108863,g+=24,g>=26&&(g-=26,c++);return this._strip()};function p(f,t){var n=f.charCodeAt(t);if(n>=48&&n<=57)return n-48;if(n>=65&&n<=70)return n-55;if(n>=97&&n<=102)return n-87;o(false,"Invalid character in "+f);}function v(f,t,n){var l=p(f,n);return n-1>=t&&(l|=p(f,n-1)<<4),l}a.prototype._parseHex=function(t,n,l){this.length=Math.ceil((t.length-n)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var c=0,h=0,g;if(l==="be")for(m=t.length-1;m>=n;m-=2)g=v(t,n,m)<<c,this.words[h]|=g&67108863,c>=18?(c-=18,h+=1,this.words[h]|=g>>>26):c+=8;else {var d=t.length-n;for(m=d%2===0?n+1:n;m<t.length;m+=2)g=v(t,n,m)<<c,this.words[h]|=g&67108863,c>=18?(c-=18,h+=1,this.words[h]|=g>>>26):c+=8;}this._strip();};function x(f,t,n,l){for(var m=0,c=0,h=Math.min(f.length,n),g=t;g<h;g++){var d=f.charCodeAt(g)-48;m*=l,d>=49?c=d-49+10:d>=17?c=d-17+10:c=d,o(d>=0&&c<l,"Invalid character"),m+=c;}return m}a.prototype._parseBase=function(t,n,l){this.words=[0],this.length=1;for(var m=0,c=1;c<=67108863;c*=n)m++;m--,c=c/n|0;for(var h=t.length-l,g=h%m,d=Math.min(h,h-g)+l,r=0,u=l;u<d;u+=m)r=x(t,u,u+m,n),this.imuln(c),this.words[0]+r<67108864?this.words[0]+=r:this._iaddn(r);if(g!==0){var B=1;for(r=x(t,u,t.length,n),u=0;u<g;u++)B*=n;this.imuln(B),this.words[0]+r<67108864?this.words[0]+=r:this._iaddn(r);}this._strip();},a.prototype.copy=function(t){t.words=new Array(this.length);for(var n=0;n<this.length;n++)t.words[n]=this.words[n];t.length=this.length,t.negative=this.negative,t.red=this.red;};function y(f,t){f.words=t.words,f.length=t.length,f.negative=t.negative,f.red=t.red;}if(a.prototype._move=function(t){y(t,this);},a.prototype.clone=function(){var t=new a(null);return this.copy(t),t},a.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=M;}catch{a.prototype.inspect=M;}else a.prototype.inspect=M;function M(){return (this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var w=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],C=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],S=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(t,n){t=t||10,n=n|0||1;var l;if(t===16||t==="hex"){l="";for(var m=0,c=0,h=0;h<this.length;h++){var g=this.words[h],d=((g<<m|c)&16777215).toString(16);c=g>>>24-m&16777215,m+=2,m>=26&&(m-=26,h--),c!==0||h!==this.length-1?l=w[6-d.length]+d+l:l=d+l;}for(c!==0&&(l=c.toString(16)+l);l.length%n!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(t===(t|0)&&t>=2&&t<=36){var r=C[t],u=S[t];l="";var B=this.clone();for(B.negative=0;!B.isZero();){var R=B.modrn(u).toString(t);B=B.idivn(u),B.isZero()?l=R+l:l=w[r-R.length]+R+l;}for(this.isZero()&&(l="0"+l);l.length%n!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}o(false,"Base should be between 2 and 36");},a.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&o(false,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},a.prototype.toJSON=function(){return this.toString(16,2)},b&&(a.prototype.toBuffer=function(t,n){return this.toArrayLike(b,t,n)}),a.prototype.toArray=function(t,n){return this.toArrayLike(Array,t,n)};var k=function(t,n){return t.allocUnsafe?t.allocUnsafe(n):new t(n)};a.prototype.toArrayLike=function(t,n,l){this._strip();var m=this.byteLength(),c=l||Math.max(1,m);o(m<=c,"byte array longer than desired length"),o(c>0,"Requested array length <= 0");var h=k(t,c),g=n==="le"?"LE":"BE";return this["_toArrayLike"+g](h,m),h},a.prototype._toArrayLikeLE=function(t,n){for(var l=0,m=0,c=0,h=0;c<this.length;c++){var g=this.words[c]<<h|m;t[l++]=g&255,l<t.length&&(t[l++]=g>>8&255),l<t.length&&(t[l++]=g>>16&255),h===6?(l<t.length&&(t[l++]=g>>24&255),m=0,h=0):(m=g>>>24,h+=2);}if(l<t.length)for(t[l++]=m;l<t.length;)t[l++]=0;},a.prototype._toArrayLikeBE=function(t,n){for(var l=t.length-1,m=0,c=0,h=0;c<this.length;c++){var g=this.words[c]<<h|m;t[l--]=g&255,l>=0&&(t[l--]=g>>8&255),l>=0&&(t[l--]=g>>16&255),h===6?(l>=0&&(t[l--]=g>>24&255),m=0,h=0):(m=g>>>24,h+=2);}if(l>=0)for(t[l--]=m;l>=0;)t[l--]=0;},Math.clz32?a.prototype._countBits=function(t){return 32-Math.clz32(t)}:a.prototype._countBits=function(t){var n=t,l=0;return n>=4096&&(l+=13,n>>>=13),n>=64&&(l+=7,n>>>=7),n>=8&&(l+=4,n>>>=4),n>=2&&(l+=2,n>>>=2),l+n},a.prototype._zeroBits=function(t){if(t===0)return 26;var n=t,l=0;return (n&8191)===0&&(l+=13,n>>>=13),(n&127)===0&&(l+=7,n>>>=7),(n&15)===0&&(l+=4,n>>>=4),(n&3)===0&&(l+=2,n>>>=2),(n&1)===0&&l++,l},a.prototype.bitLength=function(){var t=this.words[this.length-1],n=this._countBits(t);return (this.length-1)*26+n};function A(f){for(var t=new Array(f.bitLength()),n=0;n<t.length;n++){var l=n/26|0,m=n%26;t[n]=f.words[l]>>>m&1;}return t}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,n=0;n<this.length;n++){var l=this._zeroBits(this.words[n]);if(t+=l,l!==26)break}return t},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},a.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var n=0;n<t.length;n++)this.words[n]=this.words[n]|t.words[n];return this._strip()},a.prototype.ior=function(t){return o((this.negative|t.negative)===0),this.iuor(t)},a.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},a.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},a.prototype.iuand=function(t){var n;this.length>t.length?n=t:n=this;for(var l=0;l<n.length;l++)this.words[l]=this.words[l]&t.words[l];return this.length=n.length,this._strip()},a.prototype.iand=function(t){return o((this.negative|t.negative)===0),this.iuand(t)},a.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},a.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},a.prototype.iuxor=function(t){var n,l;this.length>t.length?(n=this,l=t):(n=t,l=this);for(var m=0;m<l.length;m++)this.words[m]=n.words[m]^l.words[m];if(this!==n)for(;m<n.length;m++)this.words[m]=n.words[m];return this.length=n.length,this._strip()},a.prototype.ixor=function(t){return o((this.negative|t.negative)===0),this.iuxor(t)},a.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},a.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},a.prototype.inotn=function(t){o(typeof t=="number"&&t>=0);var n=Math.ceil(t/26)|0,l=t%26;this._expand(n),l>0&&n--;for(var m=0;m<n;m++)this.words[m]=~this.words[m]&67108863;return l>0&&(this.words[m]=~this.words[m]&67108863>>26-l),this._strip()},a.prototype.notn=function(t){return this.clone().inotn(t)},a.prototype.setn=function(t,n){o(typeof t=="number"&&t>=0);var l=t/26|0,m=t%26;return this._expand(l+1),n?this.words[l]=this.words[l]|1<<m:this.words[l]=this.words[l]&~(1<<m),this._strip()},a.prototype.iadd=function(t){var n;if(this.negative!==0&&t.negative===0)return this.negative=0,n=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,n=this.isub(t),t.negative=1,n._normSign();var l,m;this.length>t.length?(l=this,m=t):(l=t,m=this);for(var c=0,h=0;h<m.length;h++)n=(l.words[h]|0)+(m.words[h]|0)+c,this.words[h]=n&67108863,c=n>>>26;for(;c!==0&&h<l.length;h++)n=(l.words[h]|0)+c,this.words[h]=n&67108863,c=n>>>26;if(this.length=l.length,c!==0)this.words[this.length]=c,this.length++;else if(l!==this)for(;h<l.length;h++)this.words[h]=l.words[h];return this},a.prototype.add=function(t){var n;return t.negative!==0&&this.negative===0?(t.negative=0,n=this.sub(t),t.negative^=1,n):t.negative===0&&this.negative!==0?(this.negative=0,n=t.sub(this),this.negative=1,n):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},a.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var n=this.iadd(t);return t.negative=1,n._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var l=this.cmp(t);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,c;l>0?(m=this,c=t):(m=t,c=this);for(var h=0,g=0;g<c.length;g++)n=(m.words[g]|0)-(c.words[g]|0)+h,h=n>>26,this.words[g]=n&67108863;for(;h!==0&&g<m.length;g++)n=(m.words[g]|0)+h,h=n>>26,this.words[g]=n&67108863;if(h===0&&g<m.length&&m!==this)for(;g<m.length;g++)this.words[g]=m.words[g];return this.length=Math.max(this.length,g),m!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(t){return this.clone().isub(t)};function E(f,t,n){n.negative=t.negative^f.negative;var l=f.length+t.length|0;n.length=l,l=l-1|0;var m=f.words[0]|0,c=t.words[0]|0,h=m*c,g=h&67108863,d=h/67108864|0;n.words[0]=g;for(var r=1;r<l;r++){for(var u=d>>>26,B=d&67108863,R=Math.min(r,t.length-1),L=Math.max(0,r-f.length+1);L<=R;L++){var W=r-L|0;m=f.words[W]|0,c=t.words[L]|0,h=m*c+B,u+=h/67108864|0,B=h&67108863;}n.words[r]=B|0,d=u|0;}return d!==0?n.words[r]=d|0:n.length--,n._strip()}var N=function(t,n,l){var m=t.words,c=n.words,h=l.words,g=0,d,r,u,B=m[0]|0,R=B&8191,L=B>>>13,W=m[1]|0,q=W&8191,K=W>>>13,Ut=m[2]|0,X=Ut&8191,Q=Ut>>>13,Kt=m[3]|0,it=Kt&8191,rt=Kt>>>13,Li=m[4]|0,nt=Li&8191,st=Li>>>13,Bi=m[5]|0,lt=Bi&8191,J=Bi>>>13,me=m[6]|0,ot=me&8191,at=me>>>13,So=m[7]|0,dt=So&8191,ft=So>>>13,Ro=m[8]|0,ut=Ro&8191,pt=Ro>>>13,ko=m[9]|0,bt=ko&8191,ht=ko>>>13,Io=c[0]|0,gt=Io&8191,vt=Io>>>13,Eo=c[1]|0,xt=Eo&8191,yt=Eo>>>13,Po=c[2]|0,wt=Po&8191,Ct=Po>>>13,Do=c[3]|0,Mt=Do&8191,Tt=Do>>>13,Lo=c[4]|0,Nt=Lo&8191,At=Lo>>>13,Bo=c[5]|0,St=Bo&8191,Rt=Bo>>>13,_o=c[6]|0,kt=_o&8191,It=_o>>>13,Fo=c[7]|0,Et=Fo&8191,Pt=Fo>>>13,Ho=c[8]|0,Dt=Ho&8191,Lt=Ho>>>13,Oo=c[9]|0,Bt=Oo&8191,_t=Oo>>>13;l.negative=t.negative^n.negative,l.length=19,d=Math.imul(R,gt),r=Math.imul(R,vt),r=r+Math.imul(L,gt)|0,u=Math.imul(L,vt);var lr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(lr>>>26)|0,lr&=67108863,d=Math.imul(q,gt),r=Math.imul(q,vt),r=r+Math.imul(K,gt)|0,u=Math.imul(K,vt),d=d+Math.imul(R,xt)|0,r=r+Math.imul(R,yt)|0,r=r+Math.imul(L,xt)|0,u=u+Math.imul(L,yt)|0;var cr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(cr>>>26)|0,cr&=67108863,d=Math.imul(X,gt),r=Math.imul(X,vt),r=r+Math.imul(Q,gt)|0,u=Math.imul(Q,vt),d=d+Math.imul(q,xt)|0,r=r+Math.imul(q,yt)|0,r=r+Math.imul(K,xt)|0,u=u+Math.imul(K,yt)|0,d=d+Math.imul(R,wt)|0,r=r+Math.imul(R,Ct)|0,r=r+Math.imul(L,wt)|0,u=u+Math.imul(L,Ct)|0;var mr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(mr>>>26)|0,mr&=67108863,d=Math.imul(it,gt),r=Math.imul(it,vt),r=r+Math.imul(rt,gt)|0,u=Math.imul(rt,vt),d=d+Math.imul(X,xt)|0,r=r+Math.imul(X,yt)|0,r=r+Math.imul(Q,xt)|0,u=u+Math.imul(Q,yt)|0,d=d+Math.imul(q,wt)|0,r=r+Math.imul(q,Ct)|0,r=r+Math.imul(K,wt)|0,u=u+Math.imul(K,Ct)|0,d=d+Math.imul(R,Mt)|0,r=r+Math.imul(R,Tt)|0,r=r+Math.imul(L,Mt)|0,u=u+Math.imul(L,Tt)|0;var dr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(dr>>>26)|0,dr&=67108863,d=Math.imul(nt,gt),r=Math.imul(nt,vt),r=r+Math.imul(st,gt)|0,u=Math.imul(st,vt),d=d+Math.imul(it,xt)|0,r=r+Math.imul(it,yt)|0,r=r+Math.imul(rt,xt)|0,u=u+Math.imul(rt,yt)|0,d=d+Math.imul(X,wt)|0,r=r+Math.imul(X,Ct)|0,r=r+Math.imul(Q,wt)|0,u=u+Math.imul(Q,Ct)|0,d=d+Math.imul(q,Mt)|0,r=r+Math.imul(q,Tt)|0,r=r+Math.imul(K,Mt)|0,u=u+Math.imul(K,Tt)|0,d=d+Math.imul(R,Nt)|0,r=r+Math.imul(R,At)|0,r=r+Math.imul(L,Nt)|0,u=u+Math.imul(L,At)|0;var fr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(fr>>>26)|0,fr&=67108863,d=Math.imul(lt,gt),r=Math.imul(lt,vt),r=r+Math.imul(J,gt)|0,u=Math.imul(J,vt),d=d+Math.imul(nt,xt)|0,r=r+Math.imul(nt,yt)|0,r=r+Math.imul(st,xt)|0,u=u+Math.imul(st,yt)|0,d=d+Math.imul(it,wt)|0,r=r+Math.imul(it,Ct)|0,r=r+Math.imul(rt,wt)|0,u=u+Math.imul(rt,Ct)|0,d=d+Math.imul(X,Mt)|0,r=r+Math.imul(X,Tt)|0,r=r+Math.imul(Q,Mt)|0,u=u+Math.imul(Q,Tt)|0,d=d+Math.imul(q,Nt)|0,r=r+Math.imul(q,At)|0,r=r+Math.imul(K,Nt)|0,u=u+Math.imul(K,At)|0,d=d+Math.imul(R,St)|0,r=r+Math.imul(R,Rt)|0,r=r+Math.imul(L,St)|0,u=u+Math.imul(L,Rt)|0;var ur=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(ur>>>26)|0,ur&=67108863,d=Math.imul(ot,gt),r=Math.imul(ot,vt),r=r+Math.imul(at,gt)|0,u=Math.imul(at,vt),d=d+Math.imul(lt,xt)|0,r=r+Math.imul(lt,yt)|0,r=r+Math.imul(J,xt)|0,u=u+Math.imul(J,yt)|0,d=d+Math.imul(nt,wt)|0,r=r+Math.imul(nt,Ct)|0,r=r+Math.imul(st,wt)|0,u=u+Math.imul(st,Ct)|0,d=d+Math.imul(it,Mt)|0,r=r+Math.imul(it,Tt)|0,r=r+Math.imul(rt,Mt)|0,u=u+Math.imul(rt,Tt)|0,d=d+Math.imul(X,Nt)|0,r=r+Math.imul(X,At)|0,r=r+Math.imul(Q,Nt)|0,u=u+Math.imul(Q,At)|0,d=d+Math.imul(q,St)|0,r=r+Math.imul(q,Rt)|0,r=r+Math.imul(K,St)|0,u=u+Math.imul(K,Rt)|0,d=d+Math.imul(R,kt)|0,r=r+Math.imul(R,It)|0,r=r+Math.imul(L,kt)|0,u=u+Math.imul(L,It)|0;var pr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(pr>>>26)|0,pr&=67108863,d=Math.imul(dt,gt),r=Math.imul(dt,vt),r=r+Math.imul(ft,gt)|0,u=Math.imul(ft,vt),d=d+Math.imul(ot,xt)|0,r=r+Math.imul(ot,yt)|0,r=r+Math.imul(at,xt)|0,u=u+Math.imul(at,yt)|0,d=d+Math.imul(lt,wt)|0,r=r+Math.imul(lt,Ct)|0,r=r+Math.imul(J,wt)|0,u=u+Math.imul(J,Ct)|0,d=d+Math.imul(nt,Mt)|0,r=r+Math.imul(nt,Tt)|0,r=r+Math.imul(st,Mt)|0,u=u+Math.imul(st,Tt)|0,d=d+Math.imul(it,Nt)|0,r=r+Math.imul(it,At)|0,r=r+Math.imul(rt,Nt)|0,u=u+Math.imul(rt,At)|0,d=d+Math.imul(X,St)|0,r=r+Math.imul(X,Rt)|0,r=r+Math.imul(Q,St)|0,u=u+Math.imul(Q,Rt)|0,d=d+Math.imul(q,kt)|0,r=r+Math.imul(q,It)|0,r=r+Math.imul(K,kt)|0,u=u+Math.imul(K,It)|0,d=d+Math.imul(R,Et)|0,r=r+Math.imul(R,Pt)|0,r=r+Math.imul(L,Et)|0,u=u+Math.imul(L,Pt)|0;var br=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(br>>>26)|0,br&=67108863,d=Math.imul(ut,gt),r=Math.imul(ut,vt),r=r+Math.imul(pt,gt)|0,u=Math.imul(pt,vt),d=d+Math.imul(dt,xt)|0,r=r+Math.imul(dt,yt)|0,r=r+Math.imul(ft,xt)|0,u=u+Math.imul(ft,yt)|0,d=d+Math.imul(ot,wt)|0,r=r+Math.imul(ot,Ct)|0,r=r+Math.imul(at,wt)|0,u=u+Math.imul(at,Ct)|0,d=d+Math.imul(lt,Mt)|0,r=r+Math.imul(lt,Tt)|0,r=r+Math.imul(J,Mt)|0,u=u+Math.imul(J,Tt)|0,d=d+Math.imul(nt,Nt)|0,r=r+Math.imul(nt,At)|0,r=r+Math.imul(st,Nt)|0,u=u+Math.imul(st,At)|0,d=d+Math.imul(it,St)|0,r=r+Math.imul(it,Rt)|0,r=r+Math.imul(rt,St)|0,u=u+Math.imul(rt,Rt)|0,d=d+Math.imul(X,kt)|0,r=r+Math.imul(X,It)|0,r=r+Math.imul(Q,kt)|0,u=u+Math.imul(Q,It)|0,d=d+Math.imul(q,Et)|0,r=r+Math.imul(q,Pt)|0,r=r+Math.imul(K,Et)|0,u=u+Math.imul(K,Pt)|0,d=d+Math.imul(R,Dt)|0,r=r+Math.imul(R,Lt)|0,r=r+Math.imul(L,Dt)|0,u=u+Math.imul(L,Lt)|0;var hr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(hr>>>26)|0,hr&=67108863,d=Math.imul(bt,gt),r=Math.imul(bt,vt),r=r+Math.imul(ht,gt)|0,u=Math.imul(ht,vt),d=d+Math.imul(ut,xt)|0,r=r+Math.imul(ut,yt)|0,r=r+Math.imul(pt,xt)|0,u=u+Math.imul(pt,yt)|0,d=d+Math.imul(dt,wt)|0,r=r+Math.imul(dt,Ct)|0,r=r+Math.imul(ft,wt)|0,u=u+Math.imul(ft,Ct)|0,d=d+Math.imul(ot,Mt)|0,r=r+Math.imul(ot,Tt)|0,r=r+Math.imul(at,Mt)|0,u=u+Math.imul(at,Tt)|0,d=d+Math.imul(lt,Nt)|0,r=r+Math.imul(lt,At)|0,r=r+Math.imul(J,Nt)|0,u=u+Math.imul(J,At)|0,d=d+Math.imul(nt,St)|0,r=r+Math.imul(nt,Rt)|0,r=r+Math.imul(st,St)|0,u=u+Math.imul(st,Rt)|0,d=d+Math.imul(it,kt)|0,r=r+Math.imul(it,It)|0,r=r+Math.imul(rt,kt)|0,u=u+Math.imul(rt,It)|0,d=d+Math.imul(X,Et)|0,r=r+Math.imul(X,Pt)|0,r=r+Math.imul(Q,Et)|0,u=u+Math.imul(Q,Pt)|0,d=d+Math.imul(q,Dt)|0,r=r+Math.imul(q,Lt)|0,r=r+Math.imul(K,Dt)|0,u=u+Math.imul(K,Lt)|0,d=d+Math.imul(R,Bt)|0,r=r+Math.imul(R,_t)|0,r=r+Math.imul(L,Bt)|0,u=u+Math.imul(L,_t)|0;var gr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(gr>>>26)|0,gr&=67108863,d=Math.imul(bt,xt),r=Math.imul(bt,yt),r=r+Math.imul(ht,xt)|0,u=Math.imul(ht,yt),d=d+Math.imul(ut,wt)|0,r=r+Math.imul(ut,Ct)|0,r=r+Math.imul(pt,wt)|0,u=u+Math.imul(pt,Ct)|0,d=d+Math.imul(dt,Mt)|0,r=r+Math.imul(dt,Tt)|0,r=r+Math.imul(ft,Mt)|0,u=u+Math.imul(ft,Tt)|0,d=d+Math.imul(ot,Nt)|0,r=r+Math.imul(ot,At)|0,r=r+Math.imul(at,Nt)|0,u=u+Math.imul(at,At)|0,d=d+Math.imul(lt,St)|0,r=r+Math.imul(lt,Rt)|0,r=r+Math.imul(J,St)|0,u=u+Math.imul(J,Rt)|0,d=d+Math.imul(nt,kt)|0,r=r+Math.imul(nt,It)|0,r=r+Math.imul(st,kt)|0,u=u+Math.imul(st,It)|0,d=d+Math.imul(it,Et)|0,r=r+Math.imul(it,Pt)|0,r=r+Math.imul(rt,Et)|0,u=u+Math.imul(rt,Pt)|0,d=d+Math.imul(X,Dt)|0,r=r+Math.imul(X,Lt)|0,r=r+Math.imul(Q,Dt)|0,u=u+Math.imul(Q,Lt)|0,d=d+Math.imul(q,Bt)|0,r=r+Math.imul(q,_t)|0,r=r+Math.imul(K,Bt)|0,u=u+Math.imul(K,_t)|0;var vr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(vr>>>26)|0,vr&=67108863,d=Math.imul(bt,wt),r=Math.imul(bt,Ct),r=r+Math.imul(ht,wt)|0,u=Math.imul(ht,Ct),d=d+Math.imul(ut,Mt)|0,r=r+Math.imul(ut,Tt)|0,r=r+Math.imul(pt,Mt)|0,u=u+Math.imul(pt,Tt)|0,d=d+Math.imul(dt,Nt)|0,r=r+Math.imul(dt,At)|0,r=r+Math.imul(ft,Nt)|0,u=u+Math.imul(ft,At)|0,d=d+Math.imul(ot,St)|0,r=r+Math.imul(ot,Rt)|0,r=r+Math.imul(at,St)|0,u=u+Math.imul(at,Rt)|0,d=d+Math.imul(lt,kt)|0,r=r+Math.imul(lt,It)|0,r=r+Math.imul(J,kt)|0,u=u+Math.imul(J,It)|0,d=d+Math.imul(nt,Et)|0,r=r+Math.imul(nt,Pt)|0,r=r+Math.imul(st,Et)|0,u=u+Math.imul(st,Pt)|0,d=d+Math.imul(it,Dt)|0,r=r+Math.imul(it,Lt)|0,r=r+Math.imul(rt,Dt)|0,u=u+Math.imul(rt,Lt)|0,d=d+Math.imul(X,Bt)|0,r=r+Math.imul(X,_t)|0,r=r+Math.imul(Q,Bt)|0,u=u+Math.imul(Q,_t)|0;var xr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(xr>>>26)|0,xr&=67108863,d=Math.imul(bt,Mt),r=Math.imul(bt,Tt),r=r+Math.imul(ht,Mt)|0,u=Math.imul(ht,Tt),d=d+Math.imul(ut,Nt)|0,r=r+Math.imul(ut,At)|0,r=r+Math.imul(pt,Nt)|0,u=u+Math.imul(pt,At)|0,d=d+Math.imul(dt,St)|0,r=r+Math.imul(dt,Rt)|0,r=r+Math.imul(ft,St)|0,u=u+Math.imul(ft,Rt)|0,d=d+Math.imul(ot,kt)|0,r=r+Math.imul(ot,It)|0,r=r+Math.imul(at,kt)|0,u=u+Math.imul(at,It)|0,d=d+Math.imul(lt,Et)|0,r=r+Math.imul(lt,Pt)|0,r=r+Math.imul(J,Et)|0,u=u+Math.imul(J,Pt)|0,d=d+Math.imul(nt,Dt)|0,r=r+Math.imul(nt,Lt)|0,r=r+Math.imul(st,Dt)|0,u=u+Math.imul(st,Lt)|0,d=d+Math.imul(it,Bt)|0,r=r+Math.imul(it,_t)|0,r=r+Math.imul(rt,Bt)|0,u=u+Math.imul(rt,_t)|0;var yr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(yr>>>26)|0,yr&=67108863,d=Math.imul(bt,Nt),r=Math.imul(bt,At),r=r+Math.imul(ht,Nt)|0,u=Math.imul(ht,At),d=d+Math.imul(ut,St)|0,r=r+Math.imul(ut,Rt)|0,r=r+Math.imul(pt,St)|0,u=u+Math.imul(pt,Rt)|0,d=d+Math.imul(dt,kt)|0,r=r+Math.imul(dt,It)|0,r=r+Math.imul(ft,kt)|0,u=u+Math.imul(ft,It)|0,d=d+Math.imul(ot,Et)|0,r=r+Math.imul(ot,Pt)|0,r=r+Math.imul(at,Et)|0,u=u+Math.imul(at,Pt)|0,d=d+Math.imul(lt,Dt)|0,r=r+Math.imul(lt,Lt)|0,r=r+Math.imul(J,Dt)|0,u=u+Math.imul(J,Lt)|0,d=d+Math.imul(nt,Bt)|0,r=r+Math.imul(nt,_t)|0,r=r+Math.imul(st,Bt)|0,u=u+Math.imul(st,_t)|0;var wr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(wr>>>26)|0,wr&=67108863,d=Math.imul(bt,St),r=Math.imul(bt,Rt),r=r+Math.imul(ht,St)|0,u=Math.imul(ht,Rt),d=d+Math.imul(ut,kt)|0,r=r+Math.imul(ut,It)|0,r=r+Math.imul(pt,kt)|0,u=u+Math.imul(pt,It)|0,d=d+Math.imul(dt,Et)|0,r=r+Math.imul(dt,Pt)|0,r=r+Math.imul(ft,Et)|0,u=u+Math.imul(ft,Pt)|0,d=d+Math.imul(ot,Dt)|0,r=r+Math.imul(ot,Lt)|0,r=r+Math.imul(at,Dt)|0,u=u+Math.imul(at,Lt)|0,d=d+Math.imul(lt,Bt)|0,r=r+Math.imul(lt,_t)|0,r=r+Math.imul(J,Bt)|0,u=u+Math.imul(J,_t)|0;var Cr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(Cr>>>26)|0,Cr&=67108863,d=Math.imul(bt,kt),r=Math.imul(bt,It),r=r+Math.imul(ht,kt)|0,u=Math.imul(ht,It),d=d+Math.imul(ut,Et)|0,r=r+Math.imul(ut,Pt)|0,r=r+Math.imul(pt,Et)|0,u=u+Math.imul(pt,Pt)|0,d=d+Math.imul(dt,Dt)|0,r=r+Math.imul(dt,Lt)|0,r=r+Math.imul(ft,Dt)|0,u=u+Math.imul(ft,Lt)|0,d=d+Math.imul(ot,Bt)|0,r=r+Math.imul(ot,_t)|0,r=r+Math.imul(at,Bt)|0,u=u+Math.imul(at,_t)|0;var Mr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(Mr>>>26)|0,Mr&=67108863,d=Math.imul(bt,Et),r=Math.imul(bt,Pt),r=r+Math.imul(ht,Et)|0,u=Math.imul(ht,Pt),d=d+Math.imul(ut,Dt)|0,r=r+Math.imul(ut,Lt)|0,r=r+Math.imul(pt,Dt)|0,u=u+Math.imul(pt,Lt)|0,d=d+Math.imul(dt,Bt)|0,r=r+Math.imul(dt,_t)|0,r=r+Math.imul(ft,Bt)|0,u=u+Math.imul(ft,_t)|0;var Tr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(Tr>>>26)|0,Tr&=67108863,d=Math.imul(bt,Dt),r=Math.imul(bt,Lt),r=r+Math.imul(ht,Dt)|0,u=Math.imul(ht,Lt),d=d+Math.imul(ut,Bt)|0,r=r+Math.imul(ut,_t)|0,r=r+Math.imul(pt,Bt)|0,u=u+Math.imul(pt,_t)|0;var Nr=(g+d|0)+((r&8191)<<13)|0;g=(u+(r>>>13)|0)+(Nr>>>26)|0,Nr&=67108863,d=Math.imul(bt,Bt),r=Math.imul(bt,_t),r=r+Math.imul(ht,Bt)|0,u=Math.imul(ht,_t);var Ar=(g+d|0)+((r&8191)<<13)|0;return g=(u+(r>>>13)|0)+(Ar>>>26)|0,Ar&=67108863,h[0]=lr,h[1]=cr,h[2]=mr,h[3]=dr,h[4]=fr,h[5]=ur,h[6]=pr,h[7]=br,h[8]=hr,h[9]=gr,h[10]=vr,h[11]=xr,h[12]=yr,h[13]=wr,h[14]=Cr,h[15]=Mr,h[16]=Tr,h[17]=Nr,h[18]=Ar,g!==0&&(h[19]=g,l.length++),l};Math.imul||(N=E);function D(f,t,n){n.negative=t.negative^f.negative,n.length=f.length+t.length;for(var l=0,m=0,c=0;c<n.length-1;c++){var h=m;m=0;for(var g=l&67108863,d=Math.min(c,t.length-1),r=Math.max(0,c-f.length+1);r<=d;r++){var u=c-r,B=f.words[u]|0,R=t.words[r]|0,L=B*R,W=L&67108863;h=h+(L/67108864|0)|0,W=W+g|0,g=W&67108863,h=h+(W>>>26)|0,m+=h>>>26,h&=67108863;}n.words[c]=g,l=h,h=m;}return l!==0?n.words[c]=l:n.length--,n._strip()}function _(f,t,n){return D(f,t,n)}a.prototype.mulTo=function(t,n){var l,m=this.length+t.length;return this.length===10&&t.length===10?l=N(this,t,n):m<63?l=E(this,t,n):m<1024?l=D(this,t,n):l=_(this,t,n),l};a.prototype.mul=function(t){var n=new a(null);return n.words=new Array(this.length+t.length),this.mulTo(t,n)},a.prototype.mulf=function(t){var n=new a(null);return n.words=new Array(this.length+t.length),_(this,t,n)},a.prototype.imul=function(t){return this.clone().mulTo(t,this)},a.prototype.imuln=function(t){var n=t<0;n&&(t=-t),o(typeof t=="number"),o(t<67108864);for(var l=0,m=0;m<this.length;m++){var c=(this.words[m]|0)*t,h=(c&67108863)+(l&67108863);l>>=26,l+=c/67108864|0,l+=h>>>26,this.words[m]=h&67108863;}return l!==0&&(this.words[m]=l,this.length++),n?this.ineg():this},a.prototype.muln=function(t){return this.clone().imuln(t)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(t){var n=A(t);if(n.length===0)return new a(1);for(var l=this,m=0;m<n.length&&n[m]===0;m++,l=l.sqr());if(++m<n.length)for(var c=l.sqr();m<n.length;m++,c=c.sqr())n[m]!==0&&(l=l.mul(c));return l},a.prototype.iushln=function(t){o(typeof t=="number"&&t>=0);var n=t%26,l=(t-n)/26,m=67108863>>>26-n<<26-n,c;if(n!==0){var h=0;for(c=0;c<this.length;c++){var g=this.words[c]&m,d=(this.words[c]|0)-g<<n;this.words[c]=d|h,h=g>>>26-n;}h&&(this.words[c]=h,this.length++);}if(l!==0){for(c=this.length-1;c>=0;c--)this.words[c+l]=this.words[c];for(c=0;c<l;c++)this.words[c]=0;this.length+=l;}return this._strip()},a.prototype.ishln=function(t){return o(this.negative===0),this.iushln(t)},a.prototype.iushrn=function(t,n,l){o(typeof t=="number"&&t>=0);var m;n?m=(n-n%26)/26:m=0;var c=t%26,h=Math.min((t-c)/26,this.length),g=67108863^67108863>>>c<<c,d=l;if(m-=h,m=Math.max(0,m),d){for(var r=0;r<h;r++)d.words[r]=this.words[r];d.length=h;}if(h!==0)if(this.length>h)for(this.length-=h,r=0;r<this.length;r++)this.words[r]=this.words[r+h];else this.words[0]=0,this.length=1;var u=0;for(r=this.length-1;r>=0&&(u!==0||r>=m);r--){var B=this.words[r]|0;this.words[r]=u<<26-c|B>>>c,u=B&g;}return d&&u!==0&&(d.words[d.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(t,n,l){return o(this.negative===0),this.iushrn(t,n,l)},a.prototype.shln=function(t){return this.clone().ishln(t)},a.prototype.ushln=function(t){return this.clone().iushln(t)},a.prototype.shrn=function(t){return this.clone().ishrn(t)},a.prototype.ushrn=function(t){return this.clone().iushrn(t)},a.prototype.testn=function(t){o(typeof t=="number"&&t>=0);var n=t%26,l=(t-n)/26,m=1<<n;if(this.length<=l)return false;var c=this.words[l];return !!(c&m)},a.prototype.imaskn=function(t){o(typeof t=="number"&&t>=0);var n=t%26,l=(t-n)/26;if(o(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(n!==0&&l++,this.length=Math.min(l,this.length),n!==0){var m=67108863^67108863>>>n<<n;this.words[this.length-1]&=m;}return this._strip()},a.prototype.maskn=function(t){return this.clone().imaskn(t)},a.prototype.iaddn=function(t){return o(typeof t=="number"),o(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},a.prototype._iaddn=function(t){this.words[0]+=t;for(var n=0;n<this.length&&this.words[n]>=67108864;n++)this.words[n]-=67108864,n===this.length-1?this.words[n+1]=1:this.words[n+1]++;return this.length=Math.max(this.length,n+1),this},a.prototype.isubn=function(t){if(o(typeof t=="number"),o(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var n=0;n<this.length&&this.words[n]<0;n++)this.words[n]+=67108864,this.words[n+1]-=1;return this._strip()},a.prototype.addn=function(t){return this.clone().iaddn(t)},a.prototype.subn=function(t){return this.clone().isubn(t)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(t,n,l){var m=t.length+l,c;this._expand(m);var h,g=0;for(c=0;c<t.length;c++){h=(this.words[c+l]|0)+g;var d=(t.words[c]|0)*n;h-=d&67108863,g=(h>>26)-(d/67108864|0),this.words[c+l]=h&67108863;}for(;c<this.length-l;c++)h=(this.words[c+l]|0)+g,g=h>>26,this.words[c+l]=h&67108863;if(g===0)return this._strip();for(o(g===-1),g=0,c=0;c<this.length;c++)h=-(this.words[c]|0)+g,g=h>>26,this.words[c]=h&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(t,n){var l=this.length-t.length,m=this.clone(),c=t,h=c.words[c.length-1]|0,g=this._countBits(h);l=26-g,l!==0&&(c=c.ushln(l),m.iushln(l),h=c.words[c.length-1]|0);var d=m.length-c.length,r;if(n!=="mod"){r=new a(null),r.length=d+1,r.words=new Array(r.length);for(var u=0;u<r.length;u++)r.words[u]=0;}var B=m.clone()._ishlnsubmul(c,1,d);B.negative===0&&(m=B,r&&(r.words[d]=1));for(var R=d-1;R>=0;R--){var L=(m.words[c.length+R]|0)*67108864+(m.words[c.length+R-1]|0);for(L=Math.min(L/h|0,67108863),m._ishlnsubmul(c,L,R);m.negative!==0;)L--,m.negative=0,m._ishlnsubmul(c,1,R),m.isZero()||(m.negative^=1);r&&(r.words[R]=L);}return r&&r._strip(),m._strip(),n!=="div"&&l!==0&&m.iushrn(l),{div:r||null,mod:m}},a.prototype.divmod=function(t,n,l){if(o(!t.isZero()),this.isZero())return {div:new a(0),mod:new a(0)};var m,c,h;return this.negative!==0&&t.negative===0?(h=this.neg().divmod(t,n),n!=="mod"&&(m=h.div.neg()),n!=="div"&&(c=h.mod.neg(),l&&c.negative!==0&&c.iadd(t)),{div:m,mod:c}):this.negative===0&&t.negative!==0?(h=this.divmod(t.neg(),n),n!=="mod"&&(m=h.div.neg()),{div:m,mod:h.mod}):(this.negative&t.negative)!==0?(h=this.neg().divmod(t.neg(),n),n!=="div"&&(c=h.mod.neg(),l&&c.negative!==0&&c.isub(t)),{div:h.div,mod:c}):t.length>this.length||this.cmp(t)<0?{div:new a(0),mod:this}:t.length===1?n==="div"?{div:this.divn(t.words[0]),mod:null}:n==="mod"?{div:null,mod:new a(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new a(this.modrn(t.words[0]))}:this._wordDiv(t,n)},a.prototype.div=function(t){return this.divmod(t,"div",false).div},a.prototype.mod=function(t){return this.divmod(t,"mod",false).mod},a.prototype.umod=function(t){return this.divmod(t,"mod",true).mod},a.prototype.divRound=function(t){var n=this.divmod(t);if(n.mod.isZero())return n.div;var l=n.div.negative!==0?n.mod.isub(t):n.mod,m=t.ushrn(1),c=t.andln(1),h=l.cmp(m);return h<0||c===1&&h===0?n.div:n.div.negative!==0?n.div.isubn(1):n.div.iaddn(1)},a.prototype.modrn=function(t){var n=t<0;n&&(t=-t),o(t<=67108863);for(var l=(1<<26)%t,m=0,c=this.length-1;c>=0;c--)m=(l*m+(this.words[c]|0))%t;return n?-m:m},a.prototype.modn=function(t){return this.modrn(t)},a.prototype.idivn=function(t){var n=t<0;n&&(t=-t),o(t<=67108863);for(var l=0,m=this.length-1;m>=0;m--){var c=(this.words[m]|0)+l*67108864;this.words[m]=c/t|0,l=c%t;}return this._strip(),n?this.ineg():this},a.prototype.divn=function(t){return this.clone().idivn(t)},a.prototype.egcd=function(t){o(t.negative===0),o(!t.isZero());var n=this,l=t.clone();n.negative!==0?n=n.umod(t):n=n.clone();for(var m=new a(1),c=new a(0),h=new a(0),g=new a(1),d=0;n.isEven()&&l.isEven();)n.iushrn(1),l.iushrn(1),++d;for(var r=l.clone(),u=n.clone();!n.isZero();){for(var B=0,R=1;(n.words[0]&R)===0&&B<26;++B,R<<=1);if(B>0)for(n.iushrn(B);B-- >0;)(m.isOdd()||c.isOdd())&&(m.iadd(r),c.isub(u)),m.iushrn(1),c.iushrn(1);for(var L=0,W=1;(l.words[0]&W)===0&&L<26;++L,W<<=1);if(L>0)for(l.iushrn(L);L-- >0;)(h.isOdd()||g.isOdd())&&(h.iadd(r),g.isub(u)),h.iushrn(1),g.iushrn(1);n.cmp(l)>=0?(n.isub(l),m.isub(h),c.isub(g)):(l.isub(n),h.isub(m),g.isub(c));}return {a:h,b:g,gcd:l.iushln(d)}},a.prototype._invmp=function(t){o(t.negative===0),o(!t.isZero());var n=this,l=t.clone();n.negative!==0?n=n.umod(t):n=n.clone();for(var m=new a(1),c=new a(0),h=l.clone();n.cmpn(1)>0&&l.cmpn(1)>0;){for(var g=0,d=1;(n.words[0]&d)===0&&g<26;++g,d<<=1);if(g>0)for(n.iushrn(g);g-- >0;)m.isOdd()&&m.iadd(h),m.iushrn(1);for(var r=0,u=1;(l.words[0]&u)===0&&r<26;++r,u<<=1);if(r>0)for(l.iushrn(r);r-- >0;)c.isOdd()&&c.iadd(h),c.iushrn(1);n.cmp(l)>=0?(n.isub(l),m.isub(c)):(l.isub(n),c.isub(m));}var B;return n.cmpn(1)===0?B=m:B=c,B.cmpn(0)<0&&B.iadd(t),B},a.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var n=this.clone(),l=t.clone();n.negative=0,l.negative=0;for(var m=0;n.isEven()&&l.isEven();m++)n.iushrn(1),l.iushrn(1);do{for(;n.isEven();)n.iushrn(1);for(;l.isEven();)l.iushrn(1);var c=n.cmp(l);if(c<0){var h=n;n=l,l=h;}else if(c===0||l.cmpn(1)===0)break;n.isub(l);}while(true);return l.iushln(m)},a.prototype.invm=function(t){return this.egcd(t).a.umod(t)},a.prototype.isEven=function(){return (this.words[0]&1)===0},a.prototype.isOdd=function(){return (this.words[0]&1)===1},a.prototype.andln=function(t){return this.words[0]&t},a.prototype.bincn=function(t){o(typeof t=="number");var n=t%26,l=(t-n)/26,m=1<<n;if(this.length<=l)return this._expand(l+1),this.words[l]|=m,this;for(var c=m,h=l;c!==0&&h<this.length;h++){var g=this.words[h]|0;g+=c,c=g>>>26,g&=67108863,this.words[h]=g;}return c!==0&&(this.words[h]=c,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(t){var n=t<0;if(this.negative!==0&&!n)return -1;if(this.negative===0&&n)return 1;this._strip();var l;if(this.length>1)l=1;else {n&&(t=-t),o(t<=67108863,"Number is too big");var m=this.words[0]|0;l=m===t?0:m<t?-1:1;}return this.negative!==0?-l|0:l},a.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return -1;if(this.negative===0&&t.negative!==0)return 1;var n=this.ucmp(t);return this.negative!==0?-n|0:n},a.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return -1;for(var n=0,l=this.length-1;l>=0;l--){var m=this.words[l]|0,c=t.words[l]|0;if(m!==c){m<c?n=-1:m>c&&(n=1);break}}return n},a.prototype.gtn=function(t){return this.cmpn(t)===1},a.prototype.gt=function(t){return this.cmp(t)===1},a.prototype.gten=function(t){return this.cmpn(t)>=0},a.prototype.gte=function(t){return this.cmp(t)>=0},a.prototype.ltn=function(t){return this.cmpn(t)===-1},a.prototype.lt=function(t){return this.cmp(t)===-1},a.prototype.lten=function(t){return this.cmpn(t)<=0},a.prototype.lte=function(t){return this.cmp(t)<=0},a.prototype.eqn=function(t){return this.cmpn(t)===0},a.prototype.eq=function(t){return this.cmp(t)===0},a.red=function(t){return new $(t)},a.prototype.toRed=function(t){return o(!this.red,"Already a number in reduction context"),o(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},a.prototype.fromRed=function(){return o(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(t){return this.red=t,this},a.prototype.forceRed=function(t){return o(!this.red,"Already a number in reduction context"),this._forceRed(t)},a.prototype.redAdd=function(t){return o(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},a.prototype.redIAdd=function(t){return o(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},a.prototype.redSub=function(t){return o(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},a.prototype.redISub=function(t){return o(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},a.prototype.redShl=function(t){return o(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},a.prototype.redMul=function(t){return o(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},a.prototype.redIMul=function(t){return o(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},a.prototype.redSqr=function(){return o(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return o(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return o(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return o(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return o(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(t){return o(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var P={k256:null,p224:null,p192:null,p25519:null};function H(f,t){this.name=f,this.p=new a(t,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp();}H.prototype._tmp=function(){var t=new a(null);return t.words=new Array(Math.ceil(this.n/13)),t},H.prototype.ireduce=function(t){var n=t,l;do this.split(n,this.tmp),n=this.imulK(n),n=n.iadd(this.tmp),l=n.bitLength();while(l>this.n);var m=l<this.n?-1:n.ucmp(this.p);return m===0?(n.words[0]=0,n.length=1):m>0?n.isub(this.p):n.strip!==void 0?n.strip():n._strip(),n},H.prototype.split=function(t,n){t.iushrn(this.n,0,n);},H.prototype.imulK=function(t){return t.imul(this.k)};function I(){H.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}s(I,H),I.prototype.split=function(t,n){for(var l=4194303,m=Math.min(t.length,9),c=0;c<m;c++)n.words[c]=t.words[c];if(n.length=m,t.length<=9){t.words[0]=0,t.length=1;return}var h=t.words[9];for(n.words[n.length++]=h&l,c=10;c<t.length;c++){var g=t.words[c]|0;t.words[c-10]=(g&l)<<4|h>>>22,h=g;}h>>>=22,t.words[c-10]=h,h===0&&t.length>10?t.length-=10:t.length-=9;},I.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var n=0,l=0;l<t.length;l++){var m=t.words[l]|0;n+=m*977,t.words[l]=n&67108863,n=m*64+(n/67108864|0);}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function O(){H.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}s(O,H);function U(){H.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}s(U,H);function G(){H.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}s(G,H),G.prototype.imulK=function(t){for(var n=0,l=0;l<t.length;l++){var m=(t.words[l]|0)*19+n,c=m&67108863;m>>>=26,t.words[l]=c,n=m;}return n!==0&&(t.words[t.length++]=n),t},a._prime=function(t){if(P[t])return P[t];var n;if(t==="k256")n=new I;else if(t==="p224")n=new O;else if(t==="p192")n=new U;else if(t==="p25519")n=new G;else throw new Error("Unknown prime "+t);return P[t]=n,n};function $(f){if(typeof f=="string"){var t=a._prime(f);this.m=t.p,this.prime=t;}else o(f.gtn(1),"modulus must be greater than 1"),this.m=f,this.prime=null;}$.prototype._verify1=function(t){o(t.negative===0,"red works only with positives"),o(t.red,"red works only with red numbers");},$.prototype._verify2=function(t,n){o((t.negative|n.negative)===0,"red works only with positives"),o(t.red&&t.red===n.red,"red works only with red numbers");},$.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(y(t,t.umod(this.m)._forceRed(this)),t)},$.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},$.prototype.add=function(t,n){this._verify2(t,n);var l=t.add(n);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},$.prototype.iadd=function(t,n){this._verify2(t,n);var l=t.iadd(n);return l.cmp(this.m)>=0&&l.isub(this.m),l},$.prototype.sub=function(t,n){this._verify2(t,n);var l=t.sub(n);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},$.prototype.isub=function(t,n){this._verify2(t,n);var l=t.isub(n);return l.cmpn(0)<0&&l.iadd(this.m),l},$.prototype.shl=function(t,n){return this._verify1(t),this.imod(t.ushln(n))},$.prototype.imul=function(t,n){return this._verify2(t,n),this.imod(t.imul(n))},$.prototype.mul=function(t,n){return this._verify2(t,n),this.imod(t.mul(n))},$.prototype.isqr=function(t){return this.imul(t,t.clone())},$.prototype.sqr=function(t){return this.mul(t,t)},$.prototype.sqrt=function(t){if(t.isZero())return t.clone();var n=this.m.andln(3);if(o(n%2===1),n===3){var l=this.m.add(new a(1)).iushrn(2);return this.pow(t,l)}for(var m=this.m.subn(1),c=0;!m.isZero()&&m.andln(1)===0;)c++,m.iushrn(1);o(!m.isZero());var h=new a(1).toRed(this),g=h.redNeg(),d=this.m.subn(1).iushrn(1),r=this.m.bitLength();for(r=new a(2*r*r).toRed(this);this.pow(r,d).cmp(g)!==0;)r.redIAdd(g);for(var u=this.pow(r,m),B=this.pow(t,m.addn(1).iushrn(1)),R=this.pow(t,m),L=c;R.cmp(h)!==0;){for(var W=R,q=0;W.cmp(h)!==0;q++)W=W.redSqr();o(q<L);var K=this.pow(u,new a(1).iushln(L-q-1));B=B.redMul(K),u=K.redSqr(),R=R.redMul(u),L=q;}return B},$.prototype.invm=function(t){var n=t._invmp(this.m);return n.negative!==0?(n.negative=0,this.imod(n).redNeg()):this.imod(n)},$.prototype.pow=function(t,n){if(n.isZero())return new a(1).toRed(this);if(n.cmpn(1)===0)return t.clone();var l=4,m=new Array(1<<l);m[0]=new a(1).toRed(this),m[1]=t;for(var c=2;c<m.length;c++)m[c]=this.mul(m[c-1],t);var h=m[0],g=0,d=0,r=n.bitLength()%26;for(r===0&&(r=26),c=n.length-1;c>=0;c--){for(var u=n.words[c],B=r-1;B>=0;B--){var R=u>>B&1;if(h!==m[0]&&(h=this.sqr(h)),R===0&&g===0){d=0;continue}g<<=1,g|=R,d++,!(d!==l&&(c!==0||B!==0))&&(h=this.mul(h,m[g]),d=0,g=0);}r=26;}return h},$.prototype.convertTo=function(t){var n=t.umod(this.m);return n===t?n.clone():n},$.prototype.convertFrom=function(t){var n=t.clone();return n.red=null,n},a.mont=function(t){return new j(t)};function j(f){$.call(this,f),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv);}s(j,$),j.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},j.prototype.convertFrom=function(t){var n=this.imod(t.mul(this.rinv));return n.red=null,n},j.prototype.imul=function(t,n){if(t.isZero()||n.isZero())return t.words[0]=0,t.length=1,t;var l=t.imul(n),m=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),c=l.isub(m).iushrn(this.shift),h=c;return c.cmp(this.m)>=0?h=c.isub(this.m):c.cmpn(0)<0&&(h=c.iadd(this.m)),h._forceRed(this)},j.prototype.mul=function(t,n){if(t.isZero()||n.isZero())return new a(0)._forceRed(this);var l=t.mul(n),m=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),c=l.isub(m).iushrn(this.shift),h=c;return c.cmp(this.m)>=0?h=c.isub(this.m):c.cmpn(0)<0&&(h=c.iadd(this.m)),h._forceRed(this)},j.prototype.invm=function(t){var n=this.imod(t._invmp(this.m).mul(this.r2));return n._forceRed(this)};})(typeof Sr>"u"||Sr,ta);});var $o=i=>{let{annotations:e}=i,o=e?.[0];if(o&&typeof o=="object"&&"agentId"in o&&typeof o.agentId=="string")return o.agentId};function Ms({toolMessage:i,messages:e}){return e.map(o=>o.parts?{...o,parts:o.parts.map(s=>{if(s.type==="tool-invocation"){let a=typeof i.content=="string"?null:Array.isArray(i.content)?i.content.find(b=>b.toolCallId===s.toolInvocation.toolCallId):null;return a?{...s,state:"result",result:a.result}:s}return s}),annotations:o.agentId?[{agentId:o.agentId}]:void 0}:o)}function Vo(i){return i.reduce((e,o)=>{let s=o.agentId?[{agentId:o.agentId}]:void 0;if(o.role==="tool"||o.role==="function")return Ms({toolMessage:o,messages:e});let a="",b=[];if(typeof o.content=="string")a=o.content;else if(Array.isArray(o.content))for(let x of o.content)x.type==="text"?a+=x.text:x.type==="tool-call"&&b.push({state:"call",toolCallId:x.toolCallId,toolName:x.toolName,args:x.args});let v=["user","assistant","system","data"].includes(o.role)?o.role:"user";return e.push({id:o.id||ai.generateId(),role:v,content:a,toolInvocations:b,annotations:s}),e},[])}var ui=i=>i.replace(".vercel.app","");var Uo=async(i,e)=>{try{let o=await fetch(`${e}?id=${i}`,{method:"GET",headers:{"Content-Type":"application/json"}});return o.ok?await o.json():(console.error("Failed to fetch chat history:",o.statusText),null)}catch(o){return console.error("Error fetching chat history:",o),null}};var Go=jotai.atom({wallet:void 0,nearWalletId:void 0,account:void 0,accountId:null,evmWallet:void 0,evmAddress:void 0,chainId:void 0,suiWallet:void 0,suiAddress:void 0});function ne(){return jotai.useAtomValue(Go)}function qo(){let i=jotai.useSetAtom(Go);return async(e={})=>{let{near:o,evm:s,sui:a}=e;function b(){i({wallet:o?.wallet,account:o?.account,nearWalletId:o?.nearWalletId||void 0,accountId:o?.accountId||null,evmWallet:s,evmAddress:s?.address,chainId:s?.chainId,suiWallet:a?.wallet,suiAddress:a?.wallet?.address});}b(),!o?.account&&!o?.wallet&&!s&&!a?.wallet&&console.warn("No wallet or account configured - users will not be able to send transactions");}}function Fi(){let i=he.useRef(null),e=he.useRef(null),{data:o=false,mutate:s}=Ko__default.default("messages:is-at-bottom",null,{fallbackData:false}),{data:a=false,mutate:b}=Ko__default.default("messages:should-scroll",null,{fallbackData:false});he.useEffect(()=>{a&&(e.current?.scrollIntoView({behavior:a}),b(false));},[b,a]);let p=he.useCallback((y="smooth")=>{b(y);},[b]);function v(){s(true);}function x(){s(false);}return {containerRef:i,endRef:e,isAtBottom:o,scrollToBottom:p,onViewportEnter:v,onViewportLeave:x}}function Zo({chatId:i,status:e,isAutoPrompt:o=false}){let{containerRef:s,endRef:a,isAtBottom:b,scrollToBottom:p,onViewportEnter:v,onViewportLeave:x}=Fi(),[y,M]=he.useState(false);return he.useEffect(()=>{i&&(p("instant"),M(false));},[i,p]),he.useEffect(()=>{e==="submitted"&&M(true);},[e]),{containerRef:s,endRef:a,isAtBottom:b,scrollToBottom:p,onViewportEnter:v,onViewportLeave:x,hasSentMessage:y}}var Xo="https://rpc.mainnet.near.org";var Qo="bitte-assistant";var Hi={generalBackground:"#18181A",messageBackground:"#0A0A0A",textColor:"#FAFAFA",buttonColor:"#000000",borderColor:"#334155"};var Yo={DEBUG:"debug"};var jo=async({localAgent:i,toolCall:e,metadata:o})=>{let s=i.spec.servers?.[0]?.url;if(!s)return;let{toolPath:a,httpMethod:b}=Is(i,e.toolName);if(!a||!b){console.error("Tool path or method not found for:",e.toolName);return}try{let p=e.args?JSON.parse(JSON.stringify(e.args)):{},{url:v,remainingArgs:x}=Es(s,a,p),{options:y}=Ps({httpMethod:b,remainingArgs:x,metadata:o}),M=b==="GET"?Ds(v,x):v,w=await fetch(M,y);if(!w.ok)throw new Error(`HTTP error during tool execution: ${w.status} ${w.statusText}`);return {data:{result:await Ls(w)}}}catch(p){let v=p instanceof Error?p.message:"Unknown error";return console.error("Error executing tool call:",v),{error:v}}},Is=(i,e)=>{let o,s;return Object.entries(i.spec.paths).forEach(([a,b])=>{Object.entries(b).forEach(([p,v])=>{v.operationId===e&&(o=a,s=p.toUpperCase());});}),{toolPath:o,httpMethod:s}},Es=(i,e,o)=>{let s=`${i}${e}`,a={...o};return s=s.replace(/\{(\w+)\}/g,(b,p)=>{if(a[p]===void 0)throw new Error(`Missing required path parameter: ${p}`);let v=a[p];return delete a[p],encodeURIComponent(String(v))}),{url:s,remainingArgs:a}},Ps=({httpMethod:i,remainingArgs:e,metadata:o})=>{let s={"Content-Type":"application/json",...o?{"mb-metadata":JSON.stringify(o)}:{}},a={met