UNPKG

@bitte-ai/chat

Version:
1 lines 250 kB
'use strict';var ai$1=require('ai'),Be=require('react'),react$1=require('@ai-sdk/react'),jotai=require('jotai'),jsxRuntime=require('react/jsx-runtime'),Ln=require('swr'),clsx=require('clsx'),format_js=require('near-api-js/lib/utils/format.js'),tailwindMerge=require('tailwind-merge'),lucideReact=require('lucide-react'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),qt=require('@radix-ui/react-dialog'),vaul=require('vaul'),oo=require('@radix-ui/react-label'),If=require('fast-deep-equal'),react=require('motion/react'),Ma=require('react-markdown'),Aa=require('rehype-highlight'),Sa=require('rehype-raw'),ka=require('remark-gfm'),Li=require('recharts'),viem=require('viem'),nearSafe=require('near-safe'),transactions=require('@mysten/sui/transactions'),utils=require('jotai/utils'),nearApiJs=require('near-api-js'),ye=require('@radix-ui/react-accordion'),web3_js=require('@solana/web3.js');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 Be__namespace=/*#__PURE__*/_interopNamespace(Be);var Ln__default=/*#__PURE__*/_interopDefault(Ln);var qt__namespace=/*#__PURE__*/_interopNamespace(qt);var oo__namespace=/*#__PURE__*/_interopNamespace(oo);var If__default=/*#__PURE__*/_interopDefault(If);var Ma__default=/*#__PURE__*/_interopDefault(Ma);var Aa__default=/*#__PURE__*/_interopDefault(Aa);var Sa__default=/*#__PURE__*/_interopDefault(Sa);var ka__default=/*#__PURE__*/_interopDefault(ka);var Li__namespace=/*#__PURE__*/_interopNamespace(Li);var ye__namespace=/*#__PURE__*/_interopNamespace(ye);var ul=Object.create;var hn=Object.defineProperty;var bl=Object.getOwnPropertyDescriptor;var pl=Object.getOwnPropertyNames;var hl=Object.getPrototypeOf,gl=Object.prototype.hasOwnProperty;var vl=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var xl=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var yl=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pl(t))!gl.call(e,o)&&o!==r&&hn(e,o,{get:()=>t[o],enumerable:!(s=bl(t,o))||s.enumerable});return e};var zi=(e,t,r)=>(r=e!=null?ul(hl(e)):{},yl(!e||!e.__esModule?hn(r,"default",{value:e,enumerable:true}):r,e));var Si=xl((Bn,Gr)=>{(function(e,t){function r(f,i){if(!f)throw new Error(i||"Assertion failed")}function s(f,i){f.super_=i;var a=function(){};a.prototype=i.prototype,f.prototype=new a,f.prototype.constructor=f;}function o(f,i,a){if(o.isBN(f))return f;this.negative=0,this.words=null,this.length=0,this.red=null,f!==null&&((i==="le"||i==="be")&&(a=i,i=10),this._init(f||0,i||10,a||"be"));}typeof e=="object"?e.exports=o:t.BN=o,o.BN=o,o.wordSize=26;var m;try{typeof window<"u"&&typeof window.Buffer<"u"?m=window.Buffer:m=vl("buffer").Buffer;}catch{}o.isBN=function(i){return i instanceof o?true:i!==null&&typeof i=="object"&&i.constructor.wordSize===o.wordSize&&Array.isArray(i.words)},o.max=function(i,a){return i.cmp(a)>0?i:a},o.min=function(i,a){return i.cmp(a)<0?i:a},o.prototype._init=function(i,a,l){if(typeof i=="number")return this._initNumber(i,a,l);if(typeof i=="object")return this._initArray(i,a,l);a==="hex"&&(a=16),r(a===(a|0)&&a>=2&&a<=36),i=i.toString().replace(/\s+/g,"");var c=0;i[0]==="-"&&(c++,this.negative=1),c<i.length&&(a===16?this._parseHex(i,c,l):(this._parseBase(i,a,c),l==="le"&&this._initArray(this.toArray(),a,l)));},o.prototype._initNumber=function(i,a,l){i<0&&(this.negative=1,i=-i),i<67108864?(this.words=[i&67108863],this.length=1):i<4503599627370496?(this.words=[i&67108863,i/67108864&67108863],this.length=2):(r(i<9007199254740992),this.words=[i&67108863,i/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),a,l);},o.prototype._initArray=function(i,a,l){if(r(typeof i.length=="number"),i.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(i.length/3),this.words=new Array(this.length);for(var c=0;c<this.length;c++)this.words[c]=0;var u,v,y=0;if(l==="be")for(c=i.length-1,u=0;c>=0;c-=3)v=i[c]|i[c-1]<<8|i[c-2]<<16,this.words[u]|=v<<y&67108863,this.words[u+1]=v>>>26-y&67108863,y+=24,y>=26&&(y-=26,u++);else if(l==="le")for(c=0,u=0;c<i.length;c+=3)v=i[c]|i[c+1]<<8|i[c+2]<<16,this.words[u]|=v<<y&67108863,this.words[u+1]=v>>>26-y&67108863,y+=24,y>=26&&(y-=26,u++);return this._strip()};function d(f,i){var a=f.charCodeAt(i);if(a>=48&&a<=57)return a-48;if(a>=65&&a<=70)return a-55;if(a>=97&&a<=102)return a-87;r(false,"Invalid character in "+f);}function g(f,i,a){var l=d(f,a);return a-1>=i&&(l|=d(f,a-1)<<4),l}o.prototype._parseHex=function(i,a,l){this.length=Math.ceil((i.length-a)/6),this.words=new Array(this.length);for(var c=0;c<this.length;c++)this.words[c]=0;var u=0,v=0,y;if(l==="be")for(c=i.length-1;c>=a;c-=2)y=g(i,a,c)<<u,this.words[v]|=y&67108863,u>=18?(u-=18,v+=1,this.words[v]|=y>>>26):u+=8;else {var b=i.length-a;for(c=b%2===0?a+1:a;c<i.length;c+=2)y=g(i,a,c)<<u,this.words[v]|=y&67108863,u>=18?(u-=18,v+=1,this.words[v]|=y>>>26):u+=8;}this._strip();};function h(f,i,a,l){for(var c=0,u=0,v=Math.min(f.length,a),y=i;y<v;y++){var b=f.charCodeAt(y)-48;c*=l,b>=49?u=b-49+10:b>=17?u=b-17+10:u=b,r(b>=0&&u<l,"Invalid character"),c+=u;}return c}o.prototype._parseBase=function(i,a,l){this.words=[0],this.length=1;for(var c=0,u=1;u<=67108863;u*=a)c++;c--,u=u/a|0;for(var v=i.length-l,y=v%c,b=Math.min(v,v-y)+l,n=0,p=l;p<b;p+=c)n=h(i,p,p+c,a),this.imuln(u),this.words[0]+n<67108864?this.words[0]+=n:this._iaddn(n);if(y!==0){var O=1;for(n=h(i,p,i.length,a),p=0;p<y;p++)O*=a;this.imuln(O),this.words[0]+n<67108864?this.words[0]+=n:this._iaddn(n);}this._strip();},o.prototype.copy=function(i){i.words=new Array(this.length);for(var a=0;a<this.length;a++)i.words[a]=this.words[a];i.length=this.length,i.negative=this.negative,i.red=this.red;};function x(f,i){f.words=i.words,f.length=i.length,f.negative=i.negative,f.red=i.red;}if(o.prototype._move=function(i){x(i,this);},o.prototype.clone=function(){var i=new o(null);return this.copy(i),i},o.prototype._expand=function(i){for(;this.length<i;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=C;}catch{o.prototype.inspect=C;}else o.prototype.inspect=C;function C(){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"],T=[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],N=[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];o.prototype.toString=function(i,a){i=i||10,a=a|0||1;var l;if(i===16||i==="hex"){l="";for(var c=0,u=0,v=0;v<this.length;v++){var y=this.words[v],b=((y<<c|u)&16777215).toString(16);u=y>>>24-c&16777215,c+=2,c>=26&&(c-=26,v--),u!==0||v!==this.length-1?l=w[6-b.length]+b+l:l=b+l;}for(u!==0&&(l=u.toString(16)+l);l.length%a!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(i===(i|0)&&i>=2&&i<=36){var n=T[i],p=N[i];l="";var O=this.clone();for(O.negative=0;!O.isZero();){var _=O.modrn(p).toString(i);O=O.idivn(p),O.isZero()?l=_+l:l=w[n-_.length]+_+l;}for(this.isZero()&&(l="0"+l);l.length%a!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(false,"Base should be between 2 and 36");},o.prototype.toNumber=function(){var i=this.words[0];return this.length===2?i+=this.words[1]*67108864:this.length===3&&this.words[2]===1?i+=4503599627370496+this.words[1]*67108864:this.length>2&&r(false,"Number can only safely store up to 53 bits"),this.negative!==0?-i:i},o.prototype.toJSON=function(){return this.toString(16,2)},m&&(o.prototype.toBuffer=function(i,a){return this.toArrayLike(m,i,a)}),o.prototype.toArray=function(i,a){return this.toArrayLike(Array,i,a)};var M=function(i,a){return i.allocUnsafe?i.allocUnsafe(a):new i(a)};o.prototype.toArrayLike=function(i,a,l){this._strip();var c=this.byteLength(),u=l||Math.max(1,c);r(c<=u,"byte array longer than desired length"),r(u>0,"Requested array length <= 0");var v=M(i,u),y=a==="le"?"LE":"BE";return this["_toArrayLike"+y](v,c),v},o.prototype._toArrayLikeLE=function(i,a){for(var l=0,c=0,u=0,v=0;u<this.length;u++){var y=this.words[u]<<v|c;i[l++]=y&255,l<i.length&&(i[l++]=y>>8&255),l<i.length&&(i[l++]=y>>16&255),v===6?(l<i.length&&(i[l++]=y>>24&255),c=0,v=0):(c=y>>>24,v+=2);}if(l<i.length)for(i[l++]=c;l<i.length;)i[l++]=0;},o.prototype._toArrayLikeBE=function(i,a){for(var l=i.length-1,c=0,u=0,v=0;u<this.length;u++){var y=this.words[u]<<v|c;i[l--]=y&255,l>=0&&(i[l--]=y>>8&255),l>=0&&(i[l--]=y>>16&255),v===6?(l>=0&&(i[l--]=y>>24&255),c=0,v=0):(c=y>>>24,v+=2);}if(l>=0)for(i[l--]=c;l>=0;)i[l--]=0;},Math.clz32?o.prototype._countBits=function(i){return 32-Math.clz32(i)}:o.prototype._countBits=function(i){var a=i,l=0;return a>=4096&&(l+=13,a>>>=13),a>=64&&(l+=7,a>>>=7),a>=8&&(l+=4,a>>>=4),a>=2&&(l+=2,a>>>=2),l+a},o.prototype._zeroBits=function(i){if(i===0)return 26;var a=i,l=0;return (a&8191)===0&&(l+=13,a>>>=13),(a&127)===0&&(l+=7,a>>>=7),(a&15)===0&&(l+=4,a>>>=4),(a&3)===0&&(l+=2,a>>>=2),(a&1)===0&&l++,l},o.prototype.bitLength=function(){var i=this.words[this.length-1],a=this._countBits(i);return (this.length-1)*26+a};function A(f){for(var i=new Array(f.bitLength()),a=0;a<i.length;a++){var l=a/26|0,c=a%26;i[a]=f.words[l]>>>c&1;}return i}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var i=0,a=0;a<this.length;a++){var l=this._zeroBits(this.words[a]);if(i+=l,l!==26)break}return i},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(i){return this.negative!==0?this.abs().inotn(i).iaddn(1):this.clone()},o.prototype.fromTwos=function(i){return this.testn(i-1)?this.notn(i).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(i){for(;this.length<i.length;)this.words[this.length++]=0;for(var a=0;a<i.length;a++)this.words[a]=this.words[a]|i.words[a];return this._strip()},o.prototype.ior=function(i){return r((this.negative|i.negative)===0),this.iuor(i)},o.prototype.or=function(i){return this.length>i.length?this.clone().ior(i):i.clone().ior(this)},o.prototype.uor=function(i){return this.length>i.length?this.clone().iuor(i):i.clone().iuor(this)},o.prototype.iuand=function(i){var a;this.length>i.length?a=i:a=this;for(var l=0;l<a.length;l++)this.words[l]=this.words[l]&i.words[l];return this.length=a.length,this._strip()},o.prototype.iand=function(i){return r((this.negative|i.negative)===0),this.iuand(i)},o.prototype.and=function(i){return this.length>i.length?this.clone().iand(i):i.clone().iand(this)},o.prototype.uand=function(i){return this.length>i.length?this.clone().iuand(i):i.clone().iuand(this)},o.prototype.iuxor=function(i){var a,l;this.length>i.length?(a=this,l=i):(a=i,l=this);for(var c=0;c<l.length;c++)this.words[c]=a.words[c]^l.words[c];if(this!==a)for(;c<a.length;c++)this.words[c]=a.words[c];return this.length=a.length,this._strip()},o.prototype.ixor=function(i){return r((this.negative|i.negative)===0),this.iuxor(i)},o.prototype.xor=function(i){return this.length>i.length?this.clone().ixor(i):i.clone().ixor(this)},o.prototype.uxor=function(i){return this.length>i.length?this.clone().iuxor(i):i.clone().iuxor(this)},o.prototype.inotn=function(i){r(typeof i=="number"&&i>=0);var a=Math.ceil(i/26)|0,l=i%26;this._expand(a),l>0&&a--;for(var c=0;c<a;c++)this.words[c]=~this.words[c]&67108863;return l>0&&(this.words[c]=~this.words[c]&67108863>>26-l),this._strip()},o.prototype.notn=function(i){return this.clone().inotn(i)},o.prototype.setn=function(i,a){r(typeof i=="number"&&i>=0);var l=i/26|0,c=i%26;return this._expand(l+1),a?this.words[l]=this.words[l]|1<<c:this.words[l]=this.words[l]&~(1<<c),this._strip()},o.prototype.iadd=function(i){var a;if(this.negative!==0&&i.negative===0)return this.negative=0,a=this.isub(i),this.negative^=1,this._normSign();if(this.negative===0&&i.negative!==0)return i.negative=0,a=this.isub(i),i.negative=1,a._normSign();var l,c;this.length>i.length?(l=this,c=i):(l=i,c=this);for(var u=0,v=0;v<c.length;v++)a=(l.words[v]|0)+(c.words[v]|0)+u,this.words[v]=a&67108863,u=a>>>26;for(;u!==0&&v<l.length;v++)a=(l.words[v]|0)+u,this.words[v]=a&67108863,u=a>>>26;if(this.length=l.length,u!==0)this.words[this.length]=u,this.length++;else if(l!==this)for(;v<l.length;v++)this.words[v]=l.words[v];return this},o.prototype.add=function(i){var a;return i.negative!==0&&this.negative===0?(i.negative=0,a=this.sub(i),i.negative^=1,a):i.negative===0&&this.negative!==0?(this.negative=0,a=i.sub(this),this.negative=1,a):this.length>i.length?this.clone().iadd(i):i.clone().iadd(this)},o.prototype.isub=function(i){if(i.negative!==0){i.negative=0;var a=this.iadd(i);return i.negative=1,a._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(i),this.negative=1,this._normSign();var l=this.cmp(i);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var c,u;l>0?(c=this,u=i):(c=i,u=this);for(var v=0,y=0;y<u.length;y++)a=(c.words[y]|0)-(u.words[y]|0)+v,v=a>>26,this.words[y]=a&67108863;for(;v!==0&&y<c.length;y++)a=(c.words[y]|0)+v,v=a>>26,this.words[y]=a&67108863;if(v===0&&y<c.length&&c!==this)for(;y<c.length;y++)this.words[y]=c.words[y];return this.length=Math.max(this.length,y),c!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(i){return this.clone().isub(i)};function E(f,i,a){a.negative=i.negative^f.negative;var l=f.length+i.length|0;a.length=l,l=l-1|0;var c=f.words[0]|0,u=i.words[0]|0,v=c*u,y=v&67108863,b=v/67108864|0;a.words[0]=y;for(var n=1;n<l;n++){for(var p=b>>>26,O=b&67108863,_=Math.min(n,i.length-1),$=Math.max(0,n-f.length+1);$<=_;$++){var V=n-$|0;c=f.words[V]|0,u=i.words[$]|0,v=c*u+O,p+=v/67108864|0,O=v&67108863;}a.words[n]=O|0,b=p|0;}return b!==0?a.words[n]=b|0:a.length--,a._strip()}var S=function(i,a,l){var c=i.words,u=a.words,v=l.words,y=0,b,n,p,O=c[0]|0,_=O&8191,$=O>>>13,V=c[1]|0,J=V&8191,Q=V>>>13,Me=c[2]|0,it=Me&8191,ot=Me>>>13,Gi=c[3]|0,lt=Gi&8191,nt=Gi>>>13,ci=c[4]|0,ft=ci&8191,ut=ci>>>13,tn=c[5]|0,bt=tn&8191,pt=tn>>>13,en=c[6]|0,ht=en&8191,gt=en>>>13,rn=c[7]|0,vt=rn&8191,xt=rn>>>13,on=c[8]|0,yt=on&8191,wt=on>>>13,nn=c[9]|0,Tt=nn&8191,Ct=nn>>>13,an=u[0]|0,Nt=an&8191,Mt=an>>>13,sn=u[1]|0,At=sn&8191,St=sn>>>13,ln=u[2]|0,kt=ln&8191,Rt=ln>>>13,cn=u[3]|0,Et=cn&8191,It=cn>>>13,dn=u[4]|0,Dt=dn&8191,Lt=dn>>>13,mn=u[5]|0,Pt=mn&8191,_t=mn>>>13,fn=u[6]|0,Bt=fn&8191,Ft=fn>>>13,un=u[7]|0,Ht=un&8191,Ot=un>>>13,bn=u[8]|0,$t=bn&8191,Wt=bn>>>13,pn=u[9]|0,Ut=pn&8191,Vt=pn>>>13;l.negative=i.negative^a.negative,l.length=19,b=Math.imul(_,Nt),n=Math.imul(_,Mt),n=n+Math.imul($,Nt)|0,p=Math.imul($,Mt);var Nr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Nr>>>26)|0,Nr&=67108863,b=Math.imul(J,Nt),n=Math.imul(J,Mt),n=n+Math.imul(Q,Nt)|0,p=Math.imul(Q,Mt),b=b+Math.imul(_,At)|0,n=n+Math.imul(_,St)|0,n=n+Math.imul($,At)|0,p=p+Math.imul($,St)|0;var Mr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Mr>>>26)|0,Mr&=67108863,b=Math.imul(it,Nt),n=Math.imul(it,Mt),n=n+Math.imul(ot,Nt)|0,p=Math.imul(ot,Mt),b=b+Math.imul(J,At)|0,n=n+Math.imul(J,St)|0,n=n+Math.imul(Q,At)|0,p=p+Math.imul(Q,St)|0,b=b+Math.imul(_,kt)|0,n=n+Math.imul(_,Rt)|0,n=n+Math.imul($,kt)|0,p=p+Math.imul($,Rt)|0;var Ar=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Ar>>>26)|0,Ar&=67108863,b=Math.imul(lt,Nt),n=Math.imul(lt,Mt),n=n+Math.imul(nt,Nt)|0,p=Math.imul(nt,Mt),b=b+Math.imul(it,At)|0,n=n+Math.imul(it,St)|0,n=n+Math.imul(ot,At)|0,p=p+Math.imul(ot,St)|0,b=b+Math.imul(J,kt)|0,n=n+Math.imul(J,Rt)|0,n=n+Math.imul(Q,kt)|0,p=p+Math.imul(Q,Rt)|0,b=b+Math.imul(_,Et)|0,n=n+Math.imul(_,It)|0,n=n+Math.imul($,Et)|0,p=p+Math.imul($,It)|0;var Sr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Sr>>>26)|0,Sr&=67108863,b=Math.imul(ft,Nt),n=Math.imul(ft,Mt),n=n+Math.imul(ut,Nt)|0,p=Math.imul(ut,Mt),b=b+Math.imul(lt,At)|0,n=n+Math.imul(lt,St)|0,n=n+Math.imul(nt,At)|0,p=p+Math.imul(nt,St)|0,b=b+Math.imul(it,kt)|0,n=n+Math.imul(it,Rt)|0,n=n+Math.imul(ot,kt)|0,p=p+Math.imul(ot,Rt)|0,b=b+Math.imul(J,Et)|0,n=n+Math.imul(J,It)|0,n=n+Math.imul(Q,Et)|0,p=p+Math.imul(Q,It)|0,b=b+Math.imul(_,Dt)|0,n=n+Math.imul(_,Lt)|0,n=n+Math.imul($,Dt)|0,p=p+Math.imul($,Lt)|0;var kr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(kr>>>26)|0,kr&=67108863,b=Math.imul(bt,Nt),n=Math.imul(bt,Mt),n=n+Math.imul(pt,Nt)|0,p=Math.imul(pt,Mt),b=b+Math.imul(ft,At)|0,n=n+Math.imul(ft,St)|0,n=n+Math.imul(ut,At)|0,p=p+Math.imul(ut,St)|0,b=b+Math.imul(lt,kt)|0,n=n+Math.imul(lt,Rt)|0,n=n+Math.imul(nt,kt)|0,p=p+Math.imul(nt,Rt)|0,b=b+Math.imul(it,Et)|0,n=n+Math.imul(it,It)|0,n=n+Math.imul(ot,Et)|0,p=p+Math.imul(ot,It)|0,b=b+Math.imul(J,Dt)|0,n=n+Math.imul(J,Lt)|0,n=n+Math.imul(Q,Dt)|0,p=p+Math.imul(Q,Lt)|0,b=b+Math.imul(_,Pt)|0,n=n+Math.imul(_,_t)|0,n=n+Math.imul($,Pt)|0,p=p+Math.imul($,_t)|0;var Rr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Rr>>>26)|0,Rr&=67108863,b=Math.imul(ht,Nt),n=Math.imul(ht,Mt),n=n+Math.imul(gt,Nt)|0,p=Math.imul(gt,Mt),b=b+Math.imul(bt,At)|0,n=n+Math.imul(bt,St)|0,n=n+Math.imul(pt,At)|0,p=p+Math.imul(pt,St)|0,b=b+Math.imul(ft,kt)|0,n=n+Math.imul(ft,Rt)|0,n=n+Math.imul(ut,kt)|0,p=p+Math.imul(ut,Rt)|0,b=b+Math.imul(lt,Et)|0,n=n+Math.imul(lt,It)|0,n=n+Math.imul(nt,Et)|0,p=p+Math.imul(nt,It)|0,b=b+Math.imul(it,Dt)|0,n=n+Math.imul(it,Lt)|0,n=n+Math.imul(ot,Dt)|0,p=p+Math.imul(ot,Lt)|0,b=b+Math.imul(J,Pt)|0,n=n+Math.imul(J,_t)|0,n=n+Math.imul(Q,Pt)|0,p=p+Math.imul(Q,_t)|0,b=b+Math.imul(_,Bt)|0,n=n+Math.imul(_,Ft)|0,n=n+Math.imul($,Bt)|0,p=p+Math.imul($,Ft)|0;var Er=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Er>>>26)|0,Er&=67108863,b=Math.imul(vt,Nt),n=Math.imul(vt,Mt),n=n+Math.imul(xt,Nt)|0,p=Math.imul(xt,Mt),b=b+Math.imul(ht,At)|0,n=n+Math.imul(ht,St)|0,n=n+Math.imul(gt,At)|0,p=p+Math.imul(gt,St)|0,b=b+Math.imul(bt,kt)|0,n=n+Math.imul(bt,Rt)|0,n=n+Math.imul(pt,kt)|0,p=p+Math.imul(pt,Rt)|0,b=b+Math.imul(ft,Et)|0,n=n+Math.imul(ft,It)|0,n=n+Math.imul(ut,Et)|0,p=p+Math.imul(ut,It)|0,b=b+Math.imul(lt,Dt)|0,n=n+Math.imul(lt,Lt)|0,n=n+Math.imul(nt,Dt)|0,p=p+Math.imul(nt,Lt)|0,b=b+Math.imul(it,Pt)|0,n=n+Math.imul(it,_t)|0,n=n+Math.imul(ot,Pt)|0,p=p+Math.imul(ot,_t)|0,b=b+Math.imul(J,Bt)|0,n=n+Math.imul(J,Ft)|0,n=n+Math.imul(Q,Bt)|0,p=p+Math.imul(Q,Ft)|0,b=b+Math.imul(_,Ht)|0,n=n+Math.imul(_,Ot)|0,n=n+Math.imul($,Ht)|0,p=p+Math.imul($,Ot)|0;var Ir=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Ir>>>26)|0,Ir&=67108863,b=Math.imul(yt,Nt),n=Math.imul(yt,Mt),n=n+Math.imul(wt,Nt)|0,p=Math.imul(wt,Mt),b=b+Math.imul(vt,At)|0,n=n+Math.imul(vt,St)|0,n=n+Math.imul(xt,At)|0,p=p+Math.imul(xt,St)|0,b=b+Math.imul(ht,kt)|0,n=n+Math.imul(ht,Rt)|0,n=n+Math.imul(gt,kt)|0,p=p+Math.imul(gt,Rt)|0,b=b+Math.imul(bt,Et)|0,n=n+Math.imul(bt,It)|0,n=n+Math.imul(pt,Et)|0,p=p+Math.imul(pt,It)|0,b=b+Math.imul(ft,Dt)|0,n=n+Math.imul(ft,Lt)|0,n=n+Math.imul(ut,Dt)|0,p=p+Math.imul(ut,Lt)|0,b=b+Math.imul(lt,Pt)|0,n=n+Math.imul(lt,_t)|0,n=n+Math.imul(nt,Pt)|0,p=p+Math.imul(nt,_t)|0,b=b+Math.imul(it,Bt)|0,n=n+Math.imul(it,Ft)|0,n=n+Math.imul(ot,Bt)|0,p=p+Math.imul(ot,Ft)|0,b=b+Math.imul(J,Ht)|0,n=n+Math.imul(J,Ot)|0,n=n+Math.imul(Q,Ht)|0,p=p+Math.imul(Q,Ot)|0,b=b+Math.imul(_,$t)|0,n=n+Math.imul(_,Wt)|0,n=n+Math.imul($,$t)|0,p=p+Math.imul($,Wt)|0;var Dr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Dr>>>26)|0,Dr&=67108863,b=Math.imul(Tt,Nt),n=Math.imul(Tt,Mt),n=n+Math.imul(Ct,Nt)|0,p=Math.imul(Ct,Mt),b=b+Math.imul(yt,At)|0,n=n+Math.imul(yt,St)|0,n=n+Math.imul(wt,At)|0,p=p+Math.imul(wt,St)|0,b=b+Math.imul(vt,kt)|0,n=n+Math.imul(vt,Rt)|0,n=n+Math.imul(xt,kt)|0,p=p+Math.imul(xt,Rt)|0,b=b+Math.imul(ht,Et)|0,n=n+Math.imul(ht,It)|0,n=n+Math.imul(gt,Et)|0,p=p+Math.imul(gt,It)|0,b=b+Math.imul(bt,Dt)|0,n=n+Math.imul(bt,Lt)|0,n=n+Math.imul(pt,Dt)|0,p=p+Math.imul(pt,Lt)|0,b=b+Math.imul(ft,Pt)|0,n=n+Math.imul(ft,_t)|0,n=n+Math.imul(ut,Pt)|0,p=p+Math.imul(ut,_t)|0,b=b+Math.imul(lt,Bt)|0,n=n+Math.imul(lt,Ft)|0,n=n+Math.imul(nt,Bt)|0,p=p+Math.imul(nt,Ft)|0,b=b+Math.imul(it,Ht)|0,n=n+Math.imul(it,Ot)|0,n=n+Math.imul(ot,Ht)|0,p=p+Math.imul(ot,Ot)|0,b=b+Math.imul(J,$t)|0,n=n+Math.imul(J,Wt)|0,n=n+Math.imul(Q,$t)|0,p=p+Math.imul(Q,Wt)|0,b=b+Math.imul(_,Ut)|0,n=n+Math.imul(_,Vt)|0,n=n+Math.imul($,Ut)|0,p=p+Math.imul($,Vt)|0;var Lr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Lr>>>26)|0,Lr&=67108863,b=Math.imul(Tt,At),n=Math.imul(Tt,St),n=n+Math.imul(Ct,At)|0,p=Math.imul(Ct,St),b=b+Math.imul(yt,kt)|0,n=n+Math.imul(yt,Rt)|0,n=n+Math.imul(wt,kt)|0,p=p+Math.imul(wt,Rt)|0,b=b+Math.imul(vt,Et)|0,n=n+Math.imul(vt,It)|0,n=n+Math.imul(xt,Et)|0,p=p+Math.imul(xt,It)|0,b=b+Math.imul(ht,Dt)|0,n=n+Math.imul(ht,Lt)|0,n=n+Math.imul(gt,Dt)|0,p=p+Math.imul(gt,Lt)|0,b=b+Math.imul(bt,Pt)|0,n=n+Math.imul(bt,_t)|0,n=n+Math.imul(pt,Pt)|0,p=p+Math.imul(pt,_t)|0,b=b+Math.imul(ft,Bt)|0,n=n+Math.imul(ft,Ft)|0,n=n+Math.imul(ut,Bt)|0,p=p+Math.imul(ut,Ft)|0,b=b+Math.imul(lt,Ht)|0,n=n+Math.imul(lt,Ot)|0,n=n+Math.imul(nt,Ht)|0,p=p+Math.imul(nt,Ot)|0,b=b+Math.imul(it,$t)|0,n=n+Math.imul(it,Wt)|0,n=n+Math.imul(ot,$t)|0,p=p+Math.imul(ot,Wt)|0,b=b+Math.imul(J,Ut)|0,n=n+Math.imul(J,Vt)|0,n=n+Math.imul(Q,Ut)|0,p=p+Math.imul(Q,Vt)|0;var Pr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Pr>>>26)|0,Pr&=67108863,b=Math.imul(Tt,kt),n=Math.imul(Tt,Rt),n=n+Math.imul(Ct,kt)|0,p=Math.imul(Ct,Rt),b=b+Math.imul(yt,Et)|0,n=n+Math.imul(yt,It)|0,n=n+Math.imul(wt,Et)|0,p=p+Math.imul(wt,It)|0,b=b+Math.imul(vt,Dt)|0,n=n+Math.imul(vt,Lt)|0,n=n+Math.imul(xt,Dt)|0,p=p+Math.imul(xt,Lt)|0,b=b+Math.imul(ht,Pt)|0,n=n+Math.imul(ht,_t)|0,n=n+Math.imul(gt,Pt)|0,p=p+Math.imul(gt,_t)|0,b=b+Math.imul(bt,Bt)|0,n=n+Math.imul(bt,Ft)|0,n=n+Math.imul(pt,Bt)|0,p=p+Math.imul(pt,Ft)|0,b=b+Math.imul(ft,Ht)|0,n=n+Math.imul(ft,Ot)|0,n=n+Math.imul(ut,Ht)|0,p=p+Math.imul(ut,Ot)|0,b=b+Math.imul(lt,$t)|0,n=n+Math.imul(lt,Wt)|0,n=n+Math.imul(nt,$t)|0,p=p+Math.imul(nt,Wt)|0,b=b+Math.imul(it,Ut)|0,n=n+Math.imul(it,Vt)|0,n=n+Math.imul(ot,Ut)|0,p=p+Math.imul(ot,Vt)|0;var _r=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(_r>>>26)|0,_r&=67108863,b=Math.imul(Tt,Et),n=Math.imul(Tt,It),n=n+Math.imul(Ct,Et)|0,p=Math.imul(Ct,It),b=b+Math.imul(yt,Dt)|0,n=n+Math.imul(yt,Lt)|0,n=n+Math.imul(wt,Dt)|0,p=p+Math.imul(wt,Lt)|0,b=b+Math.imul(vt,Pt)|0,n=n+Math.imul(vt,_t)|0,n=n+Math.imul(xt,Pt)|0,p=p+Math.imul(xt,_t)|0,b=b+Math.imul(ht,Bt)|0,n=n+Math.imul(ht,Ft)|0,n=n+Math.imul(gt,Bt)|0,p=p+Math.imul(gt,Ft)|0,b=b+Math.imul(bt,Ht)|0,n=n+Math.imul(bt,Ot)|0,n=n+Math.imul(pt,Ht)|0,p=p+Math.imul(pt,Ot)|0,b=b+Math.imul(ft,$t)|0,n=n+Math.imul(ft,Wt)|0,n=n+Math.imul(ut,$t)|0,p=p+Math.imul(ut,Wt)|0,b=b+Math.imul(lt,Ut)|0,n=n+Math.imul(lt,Vt)|0,n=n+Math.imul(nt,Ut)|0,p=p+Math.imul(nt,Vt)|0;var Br=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Br>>>26)|0,Br&=67108863,b=Math.imul(Tt,Dt),n=Math.imul(Tt,Lt),n=n+Math.imul(Ct,Dt)|0,p=Math.imul(Ct,Lt),b=b+Math.imul(yt,Pt)|0,n=n+Math.imul(yt,_t)|0,n=n+Math.imul(wt,Pt)|0,p=p+Math.imul(wt,_t)|0,b=b+Math.imul(vt,Bt)|0,n=n+Math.imul(vt,Ft)|0,n=n+Math.imul(xt,Bt)|0,p=p+Math.imul(xt,Ft)|0,b=b+Math.imul(ht,Ht)|0,n=n+Math.imul(ht,Ot)|0,n=n+Math.imul(gt,Ht)|0,p=p+Math.imul(gt,Ot)|0,b=b+Math.imul(bt,$t)|0,n=n+Math.imul(bt,Wt)|0,n=n+Math.imul(pt,$t)|0,p=p+Math.imul(pt,Wt)|0,b=b+Math.imul(ft,Ut)|0,n=n+Math.imul(ft,Vt)|0,n=n+Math.imul(ut,Ut)|0,p=p+Math.imul(ut,Vt)|0;var Fr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,b=Math.imul(Tt,Pt),n=Math.imul(Tt,_t),n=n+Math.imul(Ct,Pt)|0,p=Math.imul(Ct,_t),b=b+Math.imul(yt,Bt)|0,n=n+Math.imul(yt,Ft)|0,n=n+Math.imul(wt,Bt)|0,p=p+Math.imul(wt,Ft)|0,b=b+Math.imul(vt,Ht)|0,n=n+Math.imul(vt,Ot)|0,n=n+Math.imul(xt,Ht)|0,p=p+Math.imul(xt,Ot)|0,b=b+Math.imul(ht,$t)|0,n=n+Math.imul(ht,Wt)|0,n=n+Math.imul(gt,$t)|0,p=p+Math.imul(gt,Wt)|0,b=b+Math.imul(bt,Ut)|0,n=n+Math.imul(bt,Vt)|0,n=n+Math.imul(pt,Ut)|0,p=p+Math.imul(pt,Vt)|0;var Hr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Hr>>>26)|0,Hr&=67108863,b=Math.imul(Tt,Bt),n=Math.imul(Tt,Ft),n=n+Math.imul(Ct,Bt)|0,p=Math.imul(Ct,Ft),b=b+Math.imul(yt,Ht)|0,n=n+Math.imul(yt,Ot)|0,n=n+Math.imul(wt,Ht)|0,p=p+Math.imul(wt,Ot)|0,b=b+Math.imul(vt,$t)|0,n=n+Math.imul(vt,Wt)|0,n=n+Math.imul(xt,$t)|0,p=p+Math.imul(xt,Wt)|0,b=b+Math.imul(ht,Ut)|0,n=n+Math.imul(ht,Vt)|0,n=n+Math.imul(gt,Ut)|0,p=p+Math.imul(gt,Vt)|0;var Or=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Or>>>26)|0,Or&=67108863,b=Math.imul(Tt,Ht),n=Math.imul(Tt,Ot),n=n+Math.imul(Ct,Ht)|0,p=Math.imul(Ct,Ot),b=b+Math.imul(yt,$t)|0,n=n+Math.imul(yt,Wt)|0,n=n+Math.imul(wt,$t)|0,p=p+Math.imul(wt,Wt)|0,b=b+Math.imul(vt,Ut)|0,n=n+Math.imul(vt,Vt)|0,n=n+Math.imul(xt,Ut)|0,p=p+Math.imul(xt,Vt)|0;var $r=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+($r>>>26)|0,$r&=67108863,b=Math.imul(Tt,$t),n=Math.imul(Tt,Wt),n=n+Math.imul(Ct,$t)|0,p=Math.imul(Ct,Wt),b=b+Math.imul(yt,Ut)|0,n=n+Math.imul(yt,Vt)|0,n=n+Math.imul(wt,Ut)|0,p=p+Math.imul(wt,Vt)|0;var Wr=(y+b|0)+((n&8191)<<13)|0;y=(p+(n>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,b=Math.imul(Tt,Ut),n=Math.imul(Tt,Vt),n=n+Math.imul(Ct,Ut)|0,p=Math.imul(Ct,Vt);var Ur=(y+b|0)+((n&8191)<<13)|0;return y=(p+(n>>>13)|0)+(Ur>>>26)|0,Ur&=67108863,v[0]=Nr,v[1]=Mr,v[2]=Ar,v[3]=Sr,v[4]=kr,v[5]=Rr,v[6]=Er,v[7]=Ir,v[8]=Dr,v[9]=Lr,v[10]=Pr,v[11]=_r,v[12]=Br,v[13]=Fr,v[14]=Hr,v[15]=Or,v[16]=$r,v[17]=Wr,v[18]=Ur,y!==0&&(v[19]=y,l.length++),l};Math.imul||(S=E);function R(f,i,a){a.negative=i.negative^f.negative,a.length=f.length+i.length;for(var l=0,c=0,u=0;u<a.length-1;u++){var v=c;c=0;for(var y=l&67108863,b=Math.min(u,i.length-1),n=Math.max(0,u-f.length+1);n<=b;n++){var p=u-n,O=f.words[p]|0,_=i.words[n]|0,$=O*_,V=$&67108863;v=v+($/67108864|0)|0,V=V+y|0,y=V&67108863,v=v+(V>>>26)|0,c+=v>>>26,v&=67108863;}a.words[u]=y,l=v,v=c;}return l!==0?a.words[u]=l:a.length--,a._strip()}function k(f,i,a){return R(f,i,a)}o.prototype.mulTo=function(i,a){var l,c=this.length+i.length;return this.length===10&&i.length===10?l=S(this,i,a):c<63?l=E(this,i,a):c<1024?l=R(this,i,a):l=k(this,i,a),l};o.prototype.mul=function(i){var a=new o(null);return a.words=new Array(this.length+i.length),this.mulTo(i,a)},o.prototype.mulf=function(i){var a=new o(null);return a.words=new Array(this.length+i.length),k(this,i,a)},o.prototype.imul=function(i){return this.clone().mulTo(i,this)},o.prototype.imuln=function(i){var a=i<0;a&&(i=-i),r(typeof i=="number"),r(i<67108864);for(var l=0,c=0;c<this.length;c++){var u=(this.words[c]|0)*i,v=(u&67108863)+(l&67108863);l>>=26,l+=u/67108864|0,l+=v>>>26,this.words[c]=v&67108863;}return l!==0&&(this.words[c]=l,this.length++),a?this.ineg():this},o.prototype.muln=function(i){return this.clone().imuln(i)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(i){var a=A(i);if(a.length===0)return new o(1);for(var l=this,c=0;c<a.length&&a[c]===0;c++,l=l.sqr());if(++c<a.length)for(var u=l.sqr();c<a.length;c++,u=u.sqr())a[c]!==0&&(l=l.mul(u));return l},o.prototype.iushln=function(i){r(typeof i=="number"&&i>=0);var a=i%26,l=(i-a)/26,c=67108863>>>26-a<<26-a,u;if(a!==0){var v=0;for(u=0;u<this.length;u++){var y=this.words[u]&c,b=(this.words[u]|0)-y<<a;this.words[u]=b|v,v=y>>>26-a;}v&&(this.words[u]=v,this.length++);}if(l!==0){for(u=this.length-1;u>=0;u--)this.words[u+l]=this.words[u];for(u=0;u<l;u++)this.words[u]=0;this.length+=l;}return this._strip()},o.prototype.ishln=function(i){return r(this.negative===0),this.iushln(i)},o.prototype.iushrn=function(i,a,l){r(typeof i=="number"&&i>=0);var c;a?c=(a-a%26)/26:c=0;var u=i%26,v=Math.min((i-u)/26,this.length),y=67108863^67108863>>>u<<u,b=l;if(c-=v,c=Math.max(0,c),b){for(var n=0;n<v;n++)b.words[n]=this.words[n];b.length=v;}if(v!==0)if(this.length>v)for(this.length-=v,n=0;n<this.length;n++)this.words[n]=this.words[n+v];else this.words[0]=0,this.length=1;var p=0;for(n=this.length-1;n>=0&&(p!==0||n>=c);n--){var O=this.words[n]|0;this.words[n]=p<<26-u|O>>>u,p=O&y;}return b&&p!==0&&(b.words[b.length++]=p),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(i,a,l){return r(this.negative===0),this.iushrn(i,a,l)},o.prototype.shln=function(i){return this.clone().ishln(i)},o.prototype.ushln=function(i){return this.clone().iushln(i)},o.prototype.shrn=function(i){return this.clone().ishrn(i)},o.prototype.ushrn=function(i){return this.clone().iushrn(i)},o.prototype.testn=function(i){r(typeof i=="number"&&i>=0);var a=i%26,l=(i-a)/26,c=1<<a;if(this.length<=l)return false;var u=this.words[l];return !!(u&c)},o.prototype.imaskn=function(i){r(typeof i=="number"&&i>=0);var a=i%26,l=(i-a)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(a!==0&&l++,this.length=Math.min(l,this.length),a!==0){var c=67108863^67108863>>>a<<a;this.words[this.length-1]&=c;}return this._strip()},o.prototype.maskn=function(i){return this.clone().imaskn(i)},o.prototype.iaddn=function(i){return r(typeof i=="number"),r(i<67108864),i<0?this.isubn(-i):this.negative!==0?this.length===1&&(this.words[0]|0)<=i?(this.words[0]=i-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(i),this.negative=1,this):this._iaddn(i)},o.prototype._iaddn=function(i){this.words[0]+=i;for(var a=0;a<this.length&&this.words[a]>=67108864;a++)this.words[a]-=67108864,a===this.length-1?this.words[a+1]=1:this.words[a+1]++;return this.length=Math.max(this.length,a+1),this},o.prototype.isubn=function(i){if(r(typeof i=="number"),r(i<67108864),i<0)return this.iaddn(-i);if(this.negative!==0)return this.negative=0,this.iaddn(i),this.negative=1,this;if(this.words[0]-=i,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var a=0;a<this.length&&this.words[a]<0;a++)this.words[a]+=67108864,this.words[a+1]-=1;return this._strip()},o.prototype.addn=function(i){return this.clone().iaddn(i)},o.prototype.subn=function(i){return this.clone().isubn(i)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(i,a,l){var c=i.length+l,u;this._expand(c);var v,y=0;for(u=0;u<i.length;u++){v=(this.words[u+l]|0)+y;var b=(i.words[u]|0)*a;v-=b&67108863,y=(v>>26)-(b/67108864|0),this.words[u+l]=v&67108863;}for(;u<this.length-l;u++)v=(this.words[u+l]|0)+y,y=v>>26,this.words[u+l]=v&67108863;if(y===0)return this._strip();for(r(y===-1),y=0,u=0;u<this.length;u++)v=-(this.words[u]|0)+y,y=v>>26,this.words[u]=v&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(i,a){var l=this.length-i.length,c=this.clone(),u=i,v=u.words[u.length-1]|0,y=this._countBits(v);l=26-y,l!==0&&(u=u.ushln(l),c.iushln(l),v=u.words[u.length-1]|0);var b=c.length-u.length,n;if(a!=="mod"){n=new o(null),n.length=b+1,n.words=new Array(n.length);for(var p=0;p<n.length;p++)n.words[p]=0;}var O=c.clone()._ishlnsubmul(u,1,b);O.negative===0&&(c=O,n&&(n.words[b]=1));for(var _=b-1;_>=0;_--){var $=(c.words[u.length+_]|0)*67108864+(c.words[u.length+_-1]|0);for($=Math.min($/v|0,67108863),c._ishlnsubmul(u,$,_);c.negative!==0;)$--,c.negative=0,c._ishlnsubmul(u,1,_),c.isZero()||(c.negative^=1);n&&(n.words[_]=$);}return n&&n._strip(),c._strip(),a!=="div"&&l!==0&&c.iushrn(l),{div:n||null,mod:c}},o.prototype.divmod=function(i,a,l){if(r(!i.isZero()),this.isZero())return {div:new o(0),mod:new o(0)};var c,u,v;return this.negative!==0&&i.negative===0?(v=this.neg().divmod(i,a),a!=="mod"&&(c=v.div.neg()),a!=="div"&&(u=v.mod.neg(),l&&u.negative!==0&&u.iadd(i)),{div:c,mod:u}):this.negative===0&&i.negative!==0?(v=this.divmod(i.neg(),a),a!=="mod"&&(c=v.div.neg()),{div:c,mod:v.mod}):(this.negative&i.negative)!==0?(v=this.neg().divmod(i.neg(),a),a!=="div"&&(u=v.mod.neg(),l&&u.negative!==0&&u.isub(i)),{div:v.div,mod:u}):i.length>this.length||this.cmp(i)<0?{div:new o(0),mod:this}:i.length===1?a==="div"?{div:this.divn(i.words[0]),mod:null}:a==="mod"?{div:null,mod:new o(this.modrn(i.words[0]))}:{div:this.divn(i.words[0]),mod:new o(this.modrn(i.words[0]))}:this._wordDiv(i,a)},o.prototype.div=function(i){return this.divmod(i,"div",false).div},o.prototype.mod=function(i){return this.divmod(i,"mod",false).mod},o.prototype.umod=function(i){return this.divmod(i,"mod",true).mod},o.prototype.divRound=function(i){var a=this.divmod(i);if(a.mod.isZero())return a.div;var l=a.div.negative!==0?a.mod.isub(i):a.mod,c=i.ushrn(1),u=i.andln(1),v=l.cmp(c);return v<0||u===1&&v===0?a.div:a.div.negative!==0?a.div.isubn(1):a.div.iaddn(1)},o.prototype.modrn=function(i){var a=i<0;a&&(i=-i),r(i<=67108863);for(var l=(1<<26)%i,c=0,u=this.length-1;u>=0;u--)c=(l*c+(this.words[u]|0))%i;return a?-c:c},o.prototype.modn=function(i){return this.modrn(i)},o.prototype.idivn=function(i){var a=i<0;a&&(i=-i),r(i<=67108863);for(var l=0,c=this.length-1;c>=0;c--){var u=(this.words[c]|0)+l*67108864;this.words[c]=u/i|0,l=u%i;}return this._strip(),a?this.ineg():this},o.prototype.divn=function(i){return this.clone().idivn(i)},o.prototype.egcd=function(i){r(i.negative===0),r(!i.isZero());var a=this,l=i.clone();a.negative!==0?a=a.umod(i):a=a.clone();for(var c=new o(1),u=new o(0),v=new o(0),y=new o(1),b=0;a.isEven()&&l.isEven();)a.iushrn(1),l.iushrn(1),++b;for(var n=l.clone(),p=a.clone();!a.isZero();){for(var O=0,_=1;(a.words[0]&_)===0&&O<26;++O,_<<=1);if(O>0)for(a.iushrn(O);O-- >0;)(c.isOdd()||u.isOdd())&&(c.iadd(n),u.isub(p)),c.iushrn(1),u.iushrn(1);for(var $=0,V=1;(l.words[0]&V)===0&&$<26;++$,V<<=1);if($>0)for(l.iushrn($);$-- >0;)(v.isOdd()||y.isOdd())&&(v.iadd(n),y.isub(p)),v.iushrn(1),y.iushrn(1);a.cmp(l)>=0?(a.isub(l),c.isub(v),u.isub(y)):(l.isub(a),v.isub(c),y.isub(u));}return {a:v,b:y,gcd:l.iushln(b)}},o.prototype._invmp=function(i){r(i.negative===0),r(!i.isZero());var a=this,l=i.clone();a.negative!==0?a=a.umod(i):a=a.clone();for(var c=new o(1),u=new o(0),v=l.clone();a.cmpn(1)>0&&l.cmpn(1)>0;){for(var y=0,b=1;(a.words[0]&b)===0&&y<26;++y,b<<=1);if(y>0)for(a.iushrn(y);y-- >0;)c.isOdd()&&c.iadd(v),c.iushrn(1);for(var n=0,p=1;(l.words[0]&p)===0&&n<26;++n,p<<=1);if(n>0)for(l.iushrn(n);n-- >0;)u.isOdd()&&u.iadd(v),u.iushrn(1);a.cmp(l)>=0?(a.isub(l),c.isub(u)):(l.isub(a),u.isub(c));}var O;return a.cmpn(1)===0?O=c:O=u,O.cmpn(0)<0&&O.iadd(i),O},o.prototype.gcd=function(i){if(this.isZero())return i.abs();if(i.isZero())return this.abs();var a=this.clone(),l=i.clone();a.negative=0,l.negative=0;for(var c=0;a.isEven()&&l.isEven();c++)a.iushrn(1),l.iushrn(1);do{for(;a.isEven();)a.iushrn(1);for(;l.isEven();)l.iushrn(1);var u=a.cmp(l);if(u<0){var v=a;a=l,l=v;}else if(u===0||l.cmpn(1)===0)break;a.isub(l);}while(true);return l.iushln(c)},o.prototype.invm=function(i){return this.egcd(i).a.umod(i)},o.prototype.isEven=function(){return (this.words[0]&1)===0},o.prototype.isOdd=function(){return (this.words[0]&1)===1},o.prototype.andln=function(i){return this.words[0]&i},o.prototype.bincn=function(i){r(typeof i=="number");var a=i%26,l=(i-a)/26,c=1<<a;if(this.length<=l)return this._expand(l+1),this.words[l]|=c,this;for(var u=c,v=l;u!==0&&v<this.length;v++){var y=this.words[v]|0;y+=u,u=y>>>26,y&=67108863,this.words[v]=y;}return u!==0&&(this.words[v]=u,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(i){var a=i<0;if(this.negative!==0&&!a)return -1;if(this.negative===0&&a)return 1;this._strip();var l;if(this.length>1)l=1;else {a&&(i=-i),r(i<=67108863,"Number is too big");var c=this.words[0]|0;l=c===i?0:c<i?-1:1;}return this.negative!==0?-l|0:l},o.prototype.cmp=function(i){if(this.negative!==0&&i.negative===0)return -1;if(this.negative===0&&i.negative!==0)return 1;var a=this.ucmp(i);return this.negative!==0?-a|0:a},o.prototype.ucmp=function(i){if(this.length>i.length)return 1;if(this.length<i.length)return -1;for(var a=0,l=this.length-1;l>=0;l--){var c=this.words[l]|0,u=i.words[l]|0;if(c!==u){c<u?a=-1:c>u&&(a=1);break}}return a},o.prototype.gtn=function(i){return this.cmpn(i)===1},o.prototype.gt=function(i){return this.cmp(i)===1},o.prototype.gten=function(i){return this.cmpn(i)>=0},o.prototype.gte=function(i){return this.cmp(i)>=0},o.prototype.ltn=function(i){return this.cmpn(i)===-1},o.prototype.lt=function(i){return this.cmp(i)===-1},o.prototype.lten=function(i){return this.cmpn(i)<=0},o.prototype.lte=function(i){return this.cmp(i)<=0},o.prototype.eqn=function(i){return this.cmpn(i)===0},o.prototype.eq=function(i){return this.cmp(i)===0},o.red=function(i){return new W(i)},o.prototype.toRed=function(i){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),i.convertTo(this)._forceRed(i)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(i){return this.red=i,this},o.prototype.forceRed=function(i){return r(!this.red,"Already a number in reduction context"),this._forceRed(i)},o.prototype.redAdd=function(i){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,i)},o.prototype.redIAdd=function(i){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,i)},o.prototype.redSub=function(i){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,i)},o.prototype.redISub=function(i){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,i)},o.prototype.redShl=function(i){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,i)},o.prototype.redMul=function(i){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,i),this.red.mul(this,i)},o.prototype.redIMul=function(i){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,i),this.red.imul(this,i)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(i){return r(this.red&&!i.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,i)};var I={k256:null,p224:null,p192:null,p25519:null};function P(f,i){this.name=f,this.p=new o(i,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp();}P.prototype._tmp=function(){var i=new o(null);return i.words=new Array(Math.ceil(this.n/13)),i},P.prototype.ireduce=function(i){var a=i,l;do this.split(a,this.tmp),a=this.imulK(a),a=a.iadd(this.tmp),l=a.bitLength();while(l>this.n);var c=l<this.n?-1:a.ucmp(this.p);return c===0?(a.words[0]=0,a.length=1):c>0?a.isub(this.p):a.strip!==void 0?a.strip():a._strip(),a},P.prototype.split=function(i,a){i.iushrn(this.n,0,a);},P.prototype.imulK=function(i){return i.imul(this.k)};function L(){P.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}s(L,P),L.prototype.split=function(i,a){for(var l=4194303,c=Math.min(i.length,9),u=0;u<c;u++)a.words[u]=i.words[u];if(a.length=c,i.length<=9){i.words[0]=0,i.length=1;return}var v=i.words[9];for(a.words[a.length++]=v&l,u=10;u<i.length;u++){var y=i.words[u]|0;i.words[u-10]=(y&l)<<4|v>>>22,v=y;}v>>>=22,i.words[u-10]=v,v===0&&i.length>10?i.length-=10:i.length-=9;},L.prototype.imulK=function(i){i.words[i.length]=0,i.words[i.length+1]=0,i.length+=2;for(var a=0,l=0;l<i.length;l++){var c=i.words[l]|0;a+=c*977,i.words[l]=a&67108863,a=c*64+(a/67108864|0);}return i.words[i.length-1]===0&&(i.length--,i.words[i.length-1]===0&&i.length--),i};function G(){P.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}s(G,P);function H(){P.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}s(H,P);function F(){P.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}s(F,P),F.prototype.imulK=function(i){for(var a=0,l=0;l<i.length;l++){var c=(i.words[l]|0)*19+a,u=c&67108863;c>>>=26,i.words[l]=u,a=c;}return a!==0&&(i.words[i.length++]=a),i},o._prime=function(i){if(I[i])return I[i];var a;if(i==="k256")a=new L;else if(i==="p224")a=new G;else if(i==="p192")a=new H;else if(i==="p25519")a=new F;else throw new Error("Unknown prime "+i);return I[i]=a,a};function W(f){if(typeof f=="string"){var i=o._prime(f);this.m=i.p,this.prime=i;}else r(f.gtn(1),"modulus must be greater than 1"),this.m=f,this.prime=null;}W.prototype._verify1=function(i){r(i.negative===0,"red works only with positives"),r(i.red,"red works only with red numbers");},W.prototype._verify2=function(i,a){r((i.negative|a.negative)===0,"red works only with positives"),r(i.red&&i.red===a.red,"red works only with red numbers");},W.prototype.imod=function(i){return this.prime?this.prime.ireduce(i)._forceRed(this):(x(i,i.umod(this.m)._forceRed(this)),i)},W.prototype.neg=function(i){return i.isZero()?i.clone():this.m.sub(i)._forceRed(this)},W.prototype.add=function(i,a){this._verify2(i,a);var l=i.add(a);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},W.prototype.iadd=function(i,a){this._verify2(i,a);var l=i.iadd(a);return l.cmp(this.m)>=0&&l.isub(this.m),l},W.prototype.sub=function(i,a){this._verify2(i,a);var l=i.sub(a);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},W.prototype.isub=function(i,a){this._verify2(i,a);var l=i.isub(a);return l.cmpn(0)<0&&l.iadd(this.m),l},W.prototype.shl=function(i,a){return this._verify1(i),this.imod(i.ushln(a))},W.prototype.imul=function(i,a){return this._verify2(i,a),this.imod(i.imul(a))},W.prototype.mul=function(i,a){return this._verify2(i,a),this.imod(i.mul(a))},W.prototype.isqr=function(i){return this.imul(i,i.clone())},W.prototype.sqr=function(i){return this.mul(i,i)},W.prototype.sqrt=function(i){if(i.isZero())return i.clone();var a=this.m.andln(3);if(r(a%2===1),a===3){var l=this.m.add(new o(1)).iushrn(2);return this.pow(i,l)}for(var c=this.m.subn(1),u=0;!c.isZero()&&c.andln(1)===0;)u++,c.iushrn(1);r(!c.isZero());var v=new o(1).toRed(this),y=v.redNeg(),b=this.m.subn(1).iushrn(1),n=this.m.bitLength();for(n=new o(2*n*n).toRed(this);this.pow(n,b).cmp(y)!==0;)n.redIAdd(y);for(var p=this.pow(n,c),O=this.pow(i,c.addn(1).iushrn(1)),_=this.pow(i,c),$=u;_.cmp(v)!==0;){for(var V=_,J=0;V.cmp(v)!==0;J++)V=V.redSqr();r(J<$);var Q=this.pow(p,new o(1).iushln($-J-1));O=O.redMul(Q),p=Q.redSqr(),_=_.redMul(p),$=J;}return O},W.prototype.invm=function(i){var a=i._invmp(this.m);return a.negative!==0?(a.negative=0,this.imod(a).redNeg()):this.imod(a)},W.prototype.pow=function(i,a){if(a.isZero())return new o(1).toRed(this);if(a.cmpn(1)===0)return i.clone();var l=4,c=new Array(1<<l);c[0]=new o(1).toRed(this),c[1]=i;for(var u=2;u<c.length;u++)c[u]=this.mul(c[u-1],i);var v=c[0],y=0,b=0,n=a.bitLength()%26;for(n===0&&(n=26),u=a.length-1;u>=0;u--){for(var p=a.words[u],O=n-1;O>=0;O--){var _=p>>O&1;if(v!==c[0]&&(v=this.sqr(v)),_===0&&y===0){b=0;continue}y<<=1,y|=_,b++,!(b!==l&&(u!==0||O!==0))&&(v=this.mul(v,c[y]),b=0,y=0);}n=26;}return v},W.prototype.convertTo=function(i){var a=i.umod(this.m);return a===i?a.clone():a},W.prototype.convertFrom=function(i){var a=i.clone();return a.red=null,a},o.mont=function(i){return new K(i)};function K(f){W.call(this,f),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(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(K,W),K.prototype.convertTo=function(i){return this.imod(i.ushln(this.shift))},K.prototype.convertFrom=function(i){var a=this.imod(i.mul(this.rinv));return a.red=null,a},K.prototype.imul=function(i,a){if(i.isZero()||a.isZero())return i.words[0]=0,i.length=1,i;var l=i.imul(a),c=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),u=l.isub(c).iushrn(this.shift),v=u;return u.cmp(this.m)>=0?v=u.isub(this.m):u.cmpn(0)<0&&(v=u.iadd(this.m)),v._forceRed(this)},K.prototype.mul=function(i,a){if(i.isZero()||a.isZero())return new o(0)._forceRed(this);var l=i.mul(a),c=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),u=l.isub(c).iushrn(this.shift),v=u;return u.cmp(this.m)>=0?v=u.isub(this.m):u.cmpn(0)<0&&(v=u.iadd(this.m)),v._forceRed(this)},K.prototype.invm=function(i){var a=this.imod(i._invmp(this.m).mul(this.r2));return a._forceRed(this)};})(typeof Gr>"u"||Gr,Bn);});var gn=e=>{let{annotations:t}=e,r=t?.[0];if(r&&typeof r=="object"&&"agentId"in r&&typeof r.agentId=="string")return r.agentId};function Tl({toolMessage:e,messages:t}){return t.map(r=>r.parts?{...r,parts:r.parts.map(s=>{if(s.type==="tool-invocation"){let o=typeof e.content=="string"?null:Array.isArray(e.content)?e.content.find(m=>m.toolCallId===s.toolInvocation.toolCallId):null;return o?{...s,state:"result",result:o.result}:s}return s}),annotations:r.agentId?[{agentId:r.agentId}]:void 0}:r)}function vn(e){return e.reduce((t,r)=>{let s=r.agentId?[{agentId:r.agentId}]:void 0;if(r.role==="tool"||r.role==="function")return Tl({toolMessage:r,messages:t});let o="",m=[];if(typeof r.content=="string")o=r.content;else if(Array.isArray(r.content))for(let h of r.content)h.type==="text"?o+=h.text:h.type==="tool-call"&&m.push({state:"call",toolCallId:h.toolCallId,toolName:h.toolName,args:h.args});let g=["user","assistant","system","data"].includes(r.role)?r.role:"user";return t.push({id:r.id||ai$1.generateId(),role:g,content:o,toolInvocations:m,annotations:s,parts:r.parts}),t},[])}var xn=e=>e.replace(".vercel.app","");var yn=async(e,t)=>{try{let r=await fetch(`${t}?id=${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});return r.ok?await r.json():(console.error("Failed to fetch chat history:",r.statusText),null)}catch(r){return console.error("Error fetching chat history:",r),null}};var wn="https://rpc.mainnet.near.org";var Tn="bitte-assistant";var Cn={generalBackground:"#18181A",messageBackground:"#0A0A0A",textColor:"#FAFAFA",buttonColor:"#000000",borderColor:"#334155"};var Nn={DEBUG:"debug"};var Mn=async({localAgent:e,toolCall:t,metadata:r})=>{let s=e.spec.servers?.[0]?.url;if(!s)return;let{toolPath:o,httpMethod:m}=Cl(e,t.toolName);if(!o||!m){console.error("Tool path or method not found for:",t.toolName);return}try{let d=t.args||{},{url:g,remainingArgs:h}=Nl(s,o,d),{options:x}=Ml({httpMethod:m,remainingArgs:h,metadata:r}),C=m==="GET"?Al(g,h):g,w=await fetch(C,x);if(!w.ok)throw new Error(`HTTP error during tool execution: ${w.status} ${w.statusText}`);return {data:{result:await Sl(w)}}}catch(d){let g=d instanceof Error?d.message:"Unknown error";return console.error("Error executing tool call:",g),{error:g}}},Cl=(e,t)=>{let r,s;return Object.entries(e.spec.paths).forEach(([o,m])=>{Object.entries(m).forEach(([d,g])=>{g.operationId===t&&(r=o,s=d.toUpperCase());});}),{toolPath:r,httpMethod:s}},Nl=(e,t,r)=>{let s=`${e}${t}`,o={...r};return s=s.replace(/\{(\w+)\}/g,(m,d)=>{if(o[d]===void 0)throw new Error(`Missing required path parameter: ${d}`);let g=o[d];return delete o[d],encodeURIComponent(String(g))}),{url:s,remainingArgs:o}},Ml=({httpMethod:e,remainingArgs:t,metadata:r})=>{let s={"Content-Type":"application/json",...r?{"mb-metadata":JSON.stringify(r)}:{}},o={method:e,headers:s};return e!=="GET"&&(o.body=JSON.stringify(t)),{options:o}},Al=(e,t)=>{if(Object.keys(t).length===0)return e;let r=new URLSearchParams;Object.entries(t).filter(([o,m])=>m!=null).forEach(([o,m])=>r.append(o,String(m)));let s=r.toString();return s&&(e+=(e.includes("?")?"&":"?")+s),e},Sl=async e=>{let t=e.headers.get("Content-Type")||"";return t.includes("application/json")?e.json():t.includes("text")?e.text():e.blob()};var An=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,cardanoWallet:void 0,cardanoAddress:void 0,solanaWallet:void 0,solanaConnection:void 0});function Qt(){return jotai.useAtomValue(An)}function Sn(){let e=jotai.useSetAtom(An);return async(t={})=>{let{near:r,evm:s,sui:o,cardano:m,solana:d}=t;function g(){e({wallet:r?.wallet,account:r?.account,nearWalletId:r?.nearWalletId||void 0,accountId:r?.accountId||null,evmWallet:s,evmAddress:s?.address,chainId:s?.chainId,suiWallet:o?.wallet,suiAddress:o?.wallet?.address,cardanoWallet:m,cardanoAddress:m?.address,solanaWallet:d?.wallet,solanaConnection:d?.connection});}g(),!r?.account&&!r?.wallet&&!s&&!o?.wallet&&!m&&!d&&console.warn("No wallet or account configured - users will not be able to send transactions");}}var qr=jotai.atom({chatId:"",apiUrl:"",apiKey:"",agentId:"",initialMessages:[],localAgent:void 0,mcpServerUrl:"",format:"plaintext"}),Rn=jotai.atom(null);jotai.atom(e=>e(qr).chatId);var Ki=()=>{let e=jotai.useAtomValue(Rn);return e||{messag