@runmedev/react-components 3.15.3 → 3.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app/index.js CHANGED
@@ -6656,7 +6656,7 @@ Open Dashboard to configure it`)},N=function(){var De;const He=(0,Y.getContext)(
6656
6656
  `)}function ue(T,O,V,H){this.failures=O,this.failedKeys=H,this.successCount=V,this.message=ae(T,O)}function te(T,O){this.name="BulkError",this.failures=Object.keys(O).map(function(V){return O[V]}),this.failuresByPos=O,this.message=ae(T,this.failures)}m(F).from(Error).extend({toString:function(){return this.name+": "+this.message}}),m(ue).from(F),m(te).from(F);var W=Jr.reduce(function(T,O){return T[O]=O+"Error",T},{}),be=F,ce=Jr.reduce(function(T,O){var V=O+"Error";function H(Q,re){this.name=V,Q?typeof Q=="string"?(this.message="".concat(Q).concat(re?`
6657
6657
  `+re:""),this.inner=re||null):typeof Q=="object"&&(this.message="".concat(Q.name," ").concat(Q.message),this.inner=Q):(this.message=X[O]||V,this.inner=null)}return m(H).from(be),T[O]=H,T},{});ce.Syntax=SyntaxError,ce.Type=TypeError,ce.Range=RangeError;var Ke=yt.reduce(function(T,O){return T[O+"Error"]=ce[O],T},{}),Te=Jr.reduce(function(T,O){return["Syntax","Type","Range"].indexOf(O)===-1&&(T[O+"Error"]=ce[O]),T},{});function Xe(){}function nt(T){return T}function xt(T,O){return T==null||T===nt?O:function(V){return O(T(V))}}function De(T,O){return function(){T.apply(this,arguments),O.apply(this,arguments)}}function He(T,O){return T===Xe?O:function(){var V=T.apply(this,arguments);V!==void 0&&(arguments[0]=V);var H=this.onsuccess,Q=this.onerror;this.onsuccess=null,this.onerror=null;var re=O.apply(this,arguments);return H&&(this.onsuccess=this.onsuccess?De(H,this.onsuccess):H),Q&&(this.onerror=this.onerror?De(Q,this.onerror):Q),re!==void 0?re:V}}function he(T,O){return T===Xe?O:function(){T.apply(this,arguments);var V=this.onsuccess,H=this.onerror;this.onsuccess=this.onerror=null,O.apply(this,arguments),V&&(this.onsuccess=this.onsuccess?De(V,this.onsuccess):V),H&&(this.onerror=this.onerror?De(H,this.onerror):H)}}function fe(T,O){return T===Xe?O:function(V){var H=T.apply(this,arguments);u(V,H);var Q=this.onsuccess,re=this.onerror;return this.onsuccess=null,this.onerror=null,V=O.apply(this,arguments),Q&&(this.onsuccess=this.onsuccess?De(Q,this.onsuccess):Q),re&&(this.onerror=this.onerror?De(re,this.onerror):re),H===void 0?V===void 0?void 0:V:u(H,V)}}function _e(T,O){return T===Xe?O:function(){return O.apply(this,arguments)!==!1&&T.apply(this,arguments)}}function Le(T,O){return T===Xe?O:function(){var V=T.apply(this,arguments);if(V&&typeof V.then=="function"){for(var H=this,Q=arguments.length,re=new Array(Q);Q--;)re[Q]=arguments[Q];return V.then(function(){return O.apply(H,re)})}return O.apply(this,arguments)}}Te.ModifyError=ue,Te.DexieError=F,Te.BulkError=te;var Be=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function Ye(T){Be=T}var Ct={},kt=100,Re=typeof Promise>"u"?[]:function(){var T=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[T,l(T),T];var O=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[O,l(O),T]}(),yt=Re[0],Jr=Re[1],Re=Re[2],Jr=Jr&&Jr.then,me=yt&&yt.constructor,dt=!!Re,ft=function(T,O){Qt.push([T,O]),jt&&(queueMicrotask(St),jt=!1)},Ot=!0,jt=!0,qt=[],Kt=[],fn=nt,Jt={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Xe,pgp:!1,env:{},finalize:Xe},at=Jt,Qt=[],en=0,En=[];function Ze(T){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var O=this._PSD=at;if(typeof T!="function"){if(T!==Ct)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&lt(this,this._value))}this._state=null,this._value=null,++O.ref,function V(H,Q){try{Q(function(re){if(H._state===null){if(re===H)throw new TypeError("A promise cannot be resolved with itself.");var de=H._lib&&Mt();re&&typeof re.then=="function"?V(H,function(ve,Se){re instanceof Ze?re._then(ve,Se):re.then(ve,Se)}):(H._state=!0,H._value=re,gt(H)),de&&Wt()}},lt.bind(null,H))}catch(re){lt(H,re)}}(this,T)}var ke={get:function(){var T=at,O=Zr;function V(H,Q){var re=this,de=!T.global&&(T!==at||O!==Zr),ve=de&&!Bn(),Se=new Ze(function(Ce,Ie){Tt(re,new tt(gr(H,T,de,ve),gr(Q,T,de,ve),Ce,Ie,T))});return this._consoleTask&&(Se._consoleTask=this._consoleTask),Se}return V.prototype=Ct,V},set:function(T){v(this,"then",T&&T.prototype===Ct?ke:{get:function(){return T},set:ke.set})}};function tt(T,O,V,H,Q){this.onFulfilled=typeof T=="function"?T:null,this.onRejected=typeof O=="function"?O:null,this.resolve=V,this.reject=H,this.psd=Q}function lt(T,O){var V,H;Kt.push(O),T._state===null&&(V=T._lib&&Mt(),O=fn(O),T._state=!1,T._value=O,H=T,qt.some(function(Q){return Q._value===H._value})||qt.push(H),gt(T),V&&Wt())}function gt(T){var O=T._listeners;T._listeners=[];for(var V=0,H=O.length;V<H;++V)Tt(T,O[V]);var Q=T._PSD;--Q.ref||Q.finalize(),en===0&&(++en,ft(function(){--en==0&&cn()},[]))}function Tt(T,O){if(T._state!==null){var V=T._state?O.onFulfilled:O.onRejected;if(V===null)return(T._state?O.resolve:O.reject)(T._value);++O.psd.ref,++en,ft(wt,[V,T,O])}else T._listeners.push(O)}function wt(T,O,V){try{var H,Q=O._value;!O._state&&Kt.length&&(Kt=[]),H=Be&&O._consoleTask?O._consoleTask.run(function(){return T(Q)}):T(Q),O._state||Kt.indexOf(Q)!==-1||function(re){for(var de=qt.length;de;)if(qt[--de]._value===re._value)return qt.splice(de,1)}(O),V.resolve(H)}catch(re){V.reject(re)}finally{--en==0&&cn(),--V.psd.ref||V.psd.finalize()}}function St(){vr(Jt,function(){Mt()&&Wt()})}function Mt(){var T=Ot;return jt=Ot=!1,T}function Wt(){var T,O,V;do for(;0<Qt.length;)for(T=Qt,Qt=[],V=T.length,O=0;O<V;++O){var H=T[O];H[0].apply(null,H[1])}while(0<Qt.length);jt=Ot=!0}function cn(){var T=qt;qt=[],T.forEach(function(H){H._PSD.onunhandled.call(null,H._value,H)});for(var O=En.slice(0),V=O.length;V;)O[--V]()}function Lt(T){return new Ze(Ct,!1,T)}function It(T,O){var V=at;return function(){var H=Mt(),Q=at;try{return un(V,!0),T.apply(this,arguments)}catch(re){O&&O(re)}finally{un(Q,!1),H&&Wt()}}}h(Ze.prototype,{then:ke,_then:function(T,O){Tt(this,new tt(null,null,T,O,at))},catch:function(T){if(arguments.length===1)return this.then(null,T);var O=T,V=arguments[1];return typeof O=="function"?this.then(null,function(H){return(H instanceof O?V:Lt)(H)}):this.then(null,function(H){return(H&&H.name===O?V:Lt)(H)})},finally:function(T){return this.then(function(O){return Ze.resolve(T()).then(function(){return O})},function(O){return Ze.resolve(T()).then(function(){return Lt(O)})})},timeout:function(T,O){var V=this;return T<1/0?new Ze(function(H,Q){var re=setTimeout(function(){return Q(new ce.Timeout(O))},T);V.then(H,Q).finally(clearTimeout.bind(null,re))}):this}}),typeof Symbol<"u"&&Symbol.toStringTag&&v(Ze.prototype,Symbol.toStringTag,"Dexie.Promise"),Jt.env=ms(),h(Ze,{all:function(){var T=R.apply(null,arguments).map(mr);return new Ze(function(O,V){T.length===0&&O([]);var H=T.length;T.forEach(function(Q,re){return Ze.resolve(Q).then(function(de){T[re]=de,--H||O(T)},V)})})},resolve:function(T){return T instanceof Ze?T:T&&typeof T.then=="function"?new Ze(function(O,V){T.then(O,V)}):new Ze(Ct,!0,T)},reject:Lt,race:function(){var T=R.apply(null,arguments).map(mr);return new Ze(function(O,V){T.map(function(H){return Ze.resolve(H).then(O,V)})})},PSD:{get:function(){return at},set:function(T){return at=T}},totalEchoes:{get:function(){return Zr}},newPSD:rr,usePSD:vr,scheduler:{get:function(){return ft},set:function(T){ft=T}},rejectionMapper:{get:function(){return fn},set:function(T){fn=T}},follow:function(T,O){return new Ze(function(V,H){return rr(function(Q,re){var de=at;de.unhandleds=[],de.onunhandled=re,de.finalize=De(function(){var ve,Se=this;ve=function(){Se.unhandleds.length===0?Q():re(Se.unhandleds[0])},En.push(function Ce(){ve(),En.splice(En.indexOf(Ce),1)}),++en,ft(function(){--en==0&&cn()},[])},de.finalize),T()},O,V,H)})}}),me&&(me.allSettled&&v(Ze,"allSettled",function(){var T=R.apply(null,arguments).map(mr);return new Ze(function(O){T.length===0&&O([]);var V=T.length,H=new Array(V);T.forEach(function(Q,re){return Ze.resolve(Q).then(function(de){return H[re]={status:"fulfilled",value:de}},function(de){return H[re]={status:"rejected",reason:de}}).then(function(){return--V||O(H)})})})}),me.any&&typeof AggregateError<"u"&&v(Ze,"any",function(){var T=R.apply(null,arguments).map(mr);return new Ze(function(O,V){T.length===0&&V(new AggregateError([]));var H=T.length,Q=new Array(H);T.forEach(function(re,de){return Ze.resolve(re).then(function(ve){return O(ve)},function(ve){Q[de]=ve,--H||V(new AggregateError(Q))})})})}),me.withResolvers&&(Ze.withResolvers=me.withResolvers));var je={awaits:0,echoes:0,id:0},Zn=0,es=[],ts=0,Zr=0,Kr=0;function rr(T,O,V,H){var Q=at,re=Object.create(Q);return re.parent=Q,re.ref=0,re.global=!1,re.id=++Kr,Jt.env,re.env=dt?{Promise:Ze,PromiseProp:{value:Ze,configurable:!0,writable:!0},all:Ze.all,race:Ze.race,allSettled:Ze.allSettled,any:Ze.any,resolve:Ze.resolve,reject:Ze.reject}:{},O&&u(re,O),++Q.ref,re.finalize=function(){--this.parent.ref||this.parent.finalize()},H=vr(re,T,V,H),re.ref===0&&re.finalize(),H}function Kn(){return je.id||(je.id=++Zn),++je.awaits,je.echoes+=kt,je.id}function Bn(){return!!je.awaits&&(--je.awaits==0&&(je.id=0),je.echoes=je.awaits*kt,!0)}function mr(T){return je.echoes&&T&&T.constructor===me?(Kn(),T.then(function(O){return Bn(),O},function(O){return Bn(),mn(O)})):T}function Ur(){var T=es[es.length-1];es.pop(),un(T,!1)}function un(T,O){var V,H=at;(O?!je.echoes||ts++&&T===at:!ts||--ts&&T===at)||queueMicrotask(O?(function(Q){++Zr,je.echoes&&--je.echoes!=0||(je.echoes=je.awaits=je.id=0),es.push(at),un(Q,!0)}).bind(null,T):Ur),T!==at&&(at=T,H===Jt&&(Jt.env=ms()),dt&&(V=Jt.env.Promise,O=T.env,(H.global||T.global)&&(Object.defineProperty(c,"Promise",O.PromiseProp),V.all=O.all,V.race=O.race,V.resolve=O.resolve,V.reject=O.reject,O.allSettled&&(V.allSettled=O.allSettled),O.any&&(V.any=O.any))))}function ms(){var T=c.Promise;return dt?{Promise:T,PromiseProp:Object.getOwnPropertyDescriptor(c,"Promise"),all:T.all,race:T.race,allSettled:T.allSettled,any:T.any,resolve:T.resolve,reject:T.reject}:{}}function vr(T,O,V,H,Q){var re=at;try{return un(T,!0),O(V,H,Q)}finally{un(re,!1)}}function gr(T,O,V,H){return typeof T!="function"?T:function(){var Q=at;V&&Kn(),un(O,!0);try{return T.apply(this,arguments)}finally{un(Q,!1),H&&queueMicrotask(Bn)}}}function br(T){Promise===me&&je.echoes===0?ts===0?T():enqueueNativeMicroTask(T):setTimeout(T,0)}(""+Jr).indexOf("[native code]")===-1&&(Kn=Bn=Xe);var mn=Ze.reject,yr="￿",sr="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",Is="String expected.",dr=[],Or="__dbnames",Yn="readonly",Yr="readwrite";function _r(T,O){return T?O?function(){return T.apply(this,arguments)&&O.apply(this,arguments)}:T:O}var wr={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function Vr(T){return typeof T!="string"||/\./.test(T)?function(O){return O}:function(O){return O[T]===void 0&&T in O&&delete(O=Z(O))[T],O}}function Os(){throw ce.Type()}function Gt(T,O){try{var V=Ys(T),H=Ys(O);if(V!==H)return V==="Array"?1:H==="Array"?-1:V==="binary"?1:H==="binary"?-1:V==="string"?1:H==="string"?-1:V==="Date"?1:H!=="Date"?NaN:-1;switch(V){case"number":case"Date":case"string":return O<T?1:T<O?-1:0;case"binary":return function(Q,re){for(var de=Q.length,ve=re.length,Se=de<ve?de:ve,Ce=0;Ce<Se;++Ce)if(Q[Ce]!==re[Ce])return Q[Ce]<re[Ce]?-1:1;return de===ve?0:de<ve?-1:1}(Xn(T),Xn(O));case"Array":return function(Q,re){for(var de=Q.length,ve=re.length,Se=de<ve?de:ve,Ce=0;Ce<Se;++Ce){var Ie=Gt(Q[Ce],re[Ce]);if(Ie!==0)return Ie}return de===ve?0:de<ve?-1:1}(T,O)}}catch{}return NaN}function Ys(T){var O=typeof T;return O!="object"?O:ArrayBuffer.isView(T)?"binary":(T=G(T),T==="ArrayBuffer"?"binary":T)}function Xn(T){return T instanceof Uint8Array?T:ArrayBuffer.isView(T)?new Uint8Array(T.buffer,T.byteOffset,T.byteLength):new Uint8Array(T)}var Xs=(hn.prototype._trans=function(T,O,V){var H=this._tx||at.trans,Q=this.name,re=Be&&typeof console<"u"&&console.createTask&&console.createTask("Dexie: ".concat(T==="readonly"?"read":"write"," ").concat(this.name));function de(Ce,Ie,ye){if(!ye.schema[Q])throw new ce.NotFound("Table "+Q+" not part of transaction");return O(ye.idbtrans,ye)}var ve=Mt();try{var Se=H&&H.db._novip===this.db._novip?H===at.trans?H._promise(T,de,V):rr(function(){return H._promise(T,de,V)},{trans:H,transless:at.transless||at}):function Ce(Ie,ye,Ne,we){if(Ie.idbdb&&(Ie._state.openComplete||at.letThrough||Ie._vip)){var Ae=Ie._createTransaction(ye,Ne,Ie._dbSchema);try{Ae.create(),Ie._state.PR1398_maxLoop=3}catch(Me){return Me.name===W.InvalidState&&Ie.isOpen()&&0<--Ie._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),Ie.close({disableAutoOpen:!1}),Ie.open().then(function(){return Ce(Ie,ye,Ne,we)})):mn(Me)}return Ae._promise(ye,function(Me,Ee){return rr(function(){return at.trans=Ae,we(Me,Ee,Ae)})}).then(function(Me){if(ye==="readwrite")try{Ae.idbtrans.commit()}catch{}return ye==="readonly"?Me:Ae._completion.then(function(){return Me})})}if(Ie._state.openComplete)return mn(new ce.DatabaseClosed(Ie._state.dbOpenError));if(!Ie._state.isBeingOpened){if(!Ie._state.autoOpen)return mn(new ce.DatabaseClosed);Ie.open().catch(Xe)}return Ie._state.dbReadyPromise.then(function(){return Ce(Ie,ye,Ne,we)})}(this.db,T,[this.name],de);return re&&(Se._consoleTask=re,Se=Se.catch(function(Ce){return console.trace(Ce),mn(Ce)})),Se}finally{ve&&Wt()}},hn.prototype.get=function(T,O){var V=this;return T&&T.constructor===Object?this.where(T).first(O):T==null?mn(new ce.Type("Invalid argument to Table.get()")):this._trans("readonly",function(H){return V.core.get({trans:H,key:T}).then(function(Q){return V.hook.reading.fire(Q)})}).then(O)},hn.prototype.where=function(T){if(typeof T=="string")return new this.db.WhereClause(this,T);if(o(T))return new this.db.WhereClause(this,"[".concat(T.join("+"),"]"));var O=i(T);if(O.length===1)return this.where(O[0]).equals(T[O[0]]);var V=this.schema.indexes.concat(this.schema.primKey).filter(function(ve){if(ve.compound&&O.every(function(Ce){return 0<=ve.keyPath.indexOf(Ce)})){for(var Se=0;Se<O.length;++Se)if(O.indexOf(ve.keyPath[Se])===-1)return!1;return!0}return!1}).sort(function(ve,Se){return ve.keyPath.length-Se.keyPath.length})[0];if(V&&this.db._maxKey!==yr){var re=V.keyPath.slice(0,O.length);return this.where(re).equals(re.map(function(Se){return T[Se]}))}!V&&Be&&console.warn("The query ".concat(JSON.stringify(T)," on ").concat(this.name," would benefit from a ")+"compound index [".concat(O.join("+"),"]"));var H=this.schema.idxByName;function Q(ve,Se){return Gt(ve,Se)===0}var de=O.reduce(function(ye,Se){var Ce=ye[0],Ie=ye[1],ye=H[Se],Ne=T[Se];return[Ce||ye,Ce||!ye?_r(Ie,ye&&ye.multi?function(we){return we=j(we,Se),o(we)&&we.some(function(Ae){return Q(Ne,Ae)})}:function(we){return Q(Ne,j(we,Se))}):Ie]},[null,null]),re=de[0],de=de[1];return re?this.where(re.name).equals(T[re.keyPath]).filter(de):V?this.filter(de):this.where(O).equals("")},hn.prototype.filter=function(T){return this.toCollection().and(T)},hn.prototype.count=function(T){return this.toCollection().count(T)},hn.prototype.offset=function(T){return this.toCollection().offset(T)},hn.prototype.limit=function(T){return this.toCollection().limit(T)},hn.prototype.each=function(T){return this.toCollection().each(T)},hn.prototype.toArray=function(T){return this.toCollection().toArray(T)},hn.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},hn.prototype.orderBy=function(T){return new this.db.Collection(new this.db.WhereClause(this,o(T)?"[".concat(T.join("+"),"]"):T))},hn.prototype.reverse=function(){return this.toCollection().reverse()},hn.prototype.mapToClass=function(T){var O,V=this.db,H=this.name;function Q(){return O!==null&&O.apply(this,arguments)||this}(this.schema.mappedClass=T).prototype instanceof Os&&(function(Se,Ce){if(typeof Ce!="function"&&Ce!==null)throw new TypeError("Class extends value "+String(Ce)+" is not a constructor or null");function Ie(){this.constructor=Se}n(Se,Ce),Se.prototype=Ce===null?Object.create(Ce):(Ie.prototype=Ce.prototype,new Ie)}(Q,O=T),Object.defineProperty(Q.prototype,"db",{get:function(){return V},enumerable:!1,configurable:!0}),Q.prototype.table=function(){return H},T=Q);for(var re=new Set,de=T.prototype;de;de=l(de))Object.getOwnPropertyNames(de).forEach(function(Se){return re.add(Se)});function ve(Se){if(!Se)return Se;var Ce,Ie=Object.create(T.prototype);for(Ce in Se)if(!re.has(Ce))try{Ie[Ce]=Se[Ce]}catch{}return Ie}return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=ve,this.hook("reading",ve),T},hn.prototype.defineClass=function(){return this.mapToClass(function(T){u(this,T)})},hn.prototype.add=function(T,O){var V=this,H=this.schema.primKey,Q=H.auto,re=H.keyPath,de=T;return re&&Q&&(de=Vr(re)(T)),this._trans("readwrite",function(ve){return V.core.mutate({trans:ve,type:"add",keys:O!=null?[O]:null,values:[de]})}).then(function(ve){return ve.numFailures?Ze.reject(ve.failures[0]):ve.lastResult}).then(function(ve){if(re)try{k(T,re,ve)}catch{}return ve})},hn.prototype.update=function(T,O){return typeof T!="object"||o(T)?this.where(":id").equals(T).modify(O):(T=j(T,this.schema.primKey.keyPath),T===void 0?mn(new ce.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(T).modify(O))},hn.prototype.put=function(T,O){var V=this,H=this.schema.primKey,Q=H.auto,re=H.keyPath,de=T;return re&&Q&&(de=Vr(re)(T)),this._trans("readwrite",function(ve){return V.core.mutate({trans:ve,type:"put",values:[de],keys:O!=null?[O]:null})}).then(function(ve){return ve.numFailures?Ze.reject(ve.failures[0]):ve.lastResult}).then(function(ve){if(re)try{k(T,re,ve)}catch{}return ve})},hn.prototype.delete=function(T){var O=this;return this._trans("readwrite",function(V){return O.core.mutate({trans:V,type:"delete",keys:[T]})}).then(function(V){return V.numFailures?Ze.reject(V.failures[0]):void 0})},hn.prototype.clear=function(){var T=this;return this._trans("readwrite",function(O){return T.core.mutate({trans:O,type:"deleteRange",range:wr})}).then(function(O){return O.numFailures?Ze.reject(O.failures[0]):void 0})},hn.prototype.bulkGet=function(T){var O=this;return this._trans("readonly",function(V){return O.core.getMany({keys:T,trans:V}).then(function(H){return H.map(function(Q){return O.hook.reading.fire(Q)})})})},hn.prototype.bulkAdd=function(T,O,V){var H=this,Q=Array.isArray(O)?O:void 0,re=(V=V||(Q?void 0:O))?V.allKeys:void 0;return this._trans("readwrite",function(de){var Ce=H.schema.primKey,ve=Ce.auto,Ce=Ce.keyPath;if(Ce&&Q)throw new ce.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(Q&&Q.length!==T.length)throw new ce.InvalidArgument("Arguments objects and keys must have the same length");var Se=T.length,Ce=Ce&&ve?T.map(Vr(Ce)):T;return H.core.mutate({trans:de,type:"add",keys:Q,values:Ce,wantResults:re}).then(function(Ae){var ye=Ae.numFailures,Ne=Ae.results,we=Ae.lastResult,Ae=Ae.failures;if(ye===0)return re?Ne:we;throw new te("".concat(H.name,".bulkAdd(): ").concat(ye," of ").concat(Se," operations failed"),Ae)})})},hn.prototype.bulkPut=function(T,O,V){var H=this,Q=Array.isArray(O)?O:void 0,re=(V=V||(Q?void 0:O))?V.allKeys:void 0;return this._trans("readwrite",function(de){var Ce=H.schema.primKey,ve=Ce.auto,Ce=Ce.keyPath;if(Ce&&Q)throw new ce.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(Q&&Q.length!==T.length)throw new ce.InvalidArgument("Arguments objects and keys must have the same length");var Se=T.length,Ce=Ce&&ve?T.map(Vr(Ce)):T;return H.core.mutate({trans:de,type:"put",keys:Q,values:Ce,wantResults:re}).then(function(Ae){var ye=Ae.numFailures,Ne=Ae.results,we=Ae.lastResult,Ae=Ae.failures;if(ye===0)return re?Ne:we;throw new te("".concat(H.name,".bulkPut(): ").concat(ye," of ").concat(Se," operations failed"),Ae)})})},hn.prototype.bulkUpdate=function(T){var O=this,V=this.core,H=T.map(function(de){return de.key}),Q=T.map(function(de){return de.changes}),re=[];return this._trans("readwrite",function(de){return V.getMany({trans:de,keys:H,cache:"clone"}).then(function(ve){var Se=[],Ce=[];T.forEach(function(ye,Ne){var we=ye.key,Ae=ye.changes,Me=ve[Ne];if(Me){for(var Ee=0,Ve=Object.keys(Ae);Ee<Ve.length;Ee++){var Ge=Ve[Ee],We=Ae[Ge];if(Ge===O.schema.primKey.keyPath){if(Gt(We,we)!==0)throw new ce.Constraint("Cannot update primary key in bulkUpdate()")}else k(Me,Ge,We)}re.push(Ne),Se.push(we),Ce.push(Me)}});var Ie=Se.length;return V.mutate({trans:de,type:"put",keys:Se,values:Ce,updates:{keys:H,changeSpecs:Q}}).then(function(ye){var Ne=ye.numFailures,we=ye.failures;if(Ne===0)return Ie;for(var Ae=0,Me=Object.keys(we);Ae<Me.length;Ae++){var Ee,Ve=Me[Ae],Ge=re[Number(Ve)];Ge!=null&&(Ee=we[Ve],delete we[Ve],we[Ge]=Ee)}throw new te("".concat(O.name,".bulkUpdate(): ").concat(Ne," of ").concat(Ie," operations failed"),we)})})})},hn.prototype.bulkDelete=function(T){var O=this,V=T.length;return this._trans("readwrite",function(H){return O.core.mutate({trans:H,type:"delete",keys:T})}).then(function(de){var Q=de.numFailures,re=de.lastResult,de=de.failures;if(Q===0)return re;throw new te("".concat(O.name,".bulkDelete(): ").concat(Q," of ").concat(V," operations failed"),de)})},hn);function hn(){}function pe(T){function O(de,ve){if(ve){for(var Se=arguments.length,Ce=new Array(Se-1);--Se;)Ce[Se-1]=arguments[Se];return V[de].subscribe.apply(null,Ce),T}if(typeof de=="string")return V[de]}var V={};O.addEventType=re;for(var H=1,Q=arguments.length;H<Q;++H)re(arguments[H]);return O;function re(de,ve,Se){if(typeof de!="object"){var Ce;ve=ve||_e;var Ie={subscribers:[],fire:Se=Se||Xe,subscribe:function(ye){Ie.subscribers.indexOf(ye)===-1&&(Ie.subscribers.push(ye),Ie.fire=ve(Ie.fire,ye))},unsubscribe:function(ye){Ie.subscribers=Ie.subscribers.filter(function(Ne){return Ne!==ye}),Ie.fire=Ie.subscribers.reduce(ve,Se)}};return V[de]=O[de]=Ie}i(Ce=de).forEach(function(ye){var Ne=Ce[ye];if(o(Ne))re(ye,Ce[ye][0],Ce[ye][1]);else{if(Ne!=="asap")throw new ce.InvalidArgument("Invalid event config");var we=re(ye,nt,function(){for(var Ae=arguments.length,Me=new Array(Ae);Ae--;)Me[Ae]=arguments[Ae];we.subscribers.forEach(function(Ee){x(function(){Ee.apply(null,Me)})})})}})}}function P(T,O){return m(O).from({prototype:T}),O}function K(T,O){return!(T.filter||T.algorithm||T.or)&&(O?T.justLimit:!T.replayFilter)}function se(T,O){T.filter=_r(T.filter,O)}function le(T,O,V){var H=T.replayFilter;T.replayFilter=H?function(){return _r(H(),O())}:O,T.justLimit=V&&!H}function it(T,O){if(T.isPrimKey)return O.primaryKey;var V=O.getIndexByKeyPath(T.index);if(!V)throw new ce.Schema("KeyPath "+T.index+" on object store "+O.name+" is not indexed");return V}function ot(T,O,V){var H=it(T,O.schema);return O.openCursor({trans:V,values:!T.keysOnly,reverse:T.dir==="prev",unique:!!T.unique,query:{index:H,range:T.range}})}function Qe(T,O,V,H){var Q=T.replayFilter?_r(T.filter,T.replayFilter()):T.filter;if(T.or){var re={},de=function(ve,Se,Ce){var Ie,ye;Q&&!Q(Se,Ce,function(Ne){return Se.stop(Ne)},function(Ne){return Se.fail(Ne)})||((ye=""+(Ie=Se.primaryKey))=="[object ArrayBuffer]"&&(ye=""+new Uint8Array(Ie)),d(re,ye)||(re[ye]=!0,O(ve,Se,Ce)))};return Promise.all([T.or._iterate(de,V),bt(ot(T,H,V),T.algorithm,de,!T.keysOnly&&T.valueMapper)])}return bt(ot(T,H,V),_r(T.algorithm,Q),O,!T.keysOnly&&T.valueMapper)}function bt(T,O,V,H){var Q=It(H?function(re,de,ve){return V(H(re),de,ve)}:V);return T.then(function(re){if(re)return re.start(function(){var de=function(){return re.continue()};O&&!O(re,function(ve){return de=ve},function(ve){re.stop(ve),de=Xe},function(ve){re.fail(ve),de=Xe})||Q(re.value,re,function(ve){return de=ve}),de()})})}var Rt=(sn.prototype.execute=function(T){var O=this["@@propmod"];if(O.add!==void 0){var V=O.add;if(o(V))return s(s([],o(T)?T:[],!0),V).sort();if(typeof V=="number")return(Number(T)||0)+V;if(typeof V=="bigint")try{return BigInt(T)+V}catch{return BigInt(0)+V}throw new TypeError("Invalid term ".concat(V))}if(O.remove!==void 0){var H=O.remove;if(o(H))return o(T)?T.filter(function(Q){return!H.includes(Q)}).sort():[];if(typeof H=="number")return Number(T)-H;if(typeof H=="bigint")try{return BigInt(T)-H}catch{return BigInt(0)-H}throw new TypeError("Invalid subtrahend ".concat(H))}return V=(V=O.replacePrefix)===null||V===void 0?void 0:V[0],V&&typeof T=="string"&&T.startsWith(V)?O.replacePrefix[1]+T.substring(V.length):T},sn);function sn(T){this["@@propmod"]=T}var qn=(Zt.prototype._read=function(T,O){var V=this._ctx;return V.error?V.table._trans(null,mn.bind(null,V.error)):V.table._trans("readonly",T).then(O)},Zt.prototype._write=function(T){var O=this._ctx;return O.error?O.table._trans(null,mn.bind(null,O.error)):O.table._trans("readwrite",T,"locked")},Zt.prototype._addAlgorithm=function(T){var O=this._ctx;O.algorithm=_r(O.algorithm,T)},Zt.prototype._iterate=function(T,O){return Qe(this._ctx,T,O,this._ctx.table.core)},Zt.prototype.clone=function(T){var O=Object.create(this.constructor.prototype),V=Object.create(this._ctx);return T&&u(V,T),O._ctx=V,O},Zt.prototype.raw=function(){return this._ctx.valueMapper=null,this},Zt.prototype.each=function(T){var O=this._ctx;return this._read(function(V){return Qe(O,T,V,O.table.core)})},Zt.prototype.count=function(T){var O=this;return this._read(function(V){var H=O._ctx,Q=H.table.core;if(K(H,!0))return Q.count({trans:V,query:{index:it(H,Q.schema),range:H.range}}).then(function(de){return Math.min(de,H.limit)});var re=0;return Qe(H,function(){return++re,!1},V,Q).then(function(){return re})}).then(T)},Zt.prototype.sortBy=function(T,O){var V=T.split(".").reverse(),H=V[0],Q=V.length-1;function re(Se,Ce){return Ce?re(Se[V[Ce]],Ce-1):Se[H]}var de=this._ctx.dir==="next"?1:-1;function ve(Se,Ce){return Gt(re(Se,Q),re(Ce,Q))*de}return this.toArray(function(Se){return Se.sort(ve)}).then(O)},Zt.prototype.toArray=function(T){var O=this;return this._read(function(V){var H=O._ctx;if(H.dir==="next"&&K(H,!0)&&0<H.limit){var Q=H.valueMapper,re=it(H,H.table.core.schema);return H.table.core.query({trans:V,limit:H.limit,values:!0,query:{index:re,range:H.range}}).then(function(ve){return ve=ve.result,Q?ve.map(Q):ve})}var de=[];return Qe(H,function(ve){return de.push(ve)},V,H.table.core).then(function(){return de})},T)},Zt.prototype.offset=function(T){var O=this._ctx;return T<=0||(O.offset+=T,K(O)?le(O,function(){var V=T;return function(H,Q){return V===0||(V===1?--V:Q(function(){H.advance(V),V=0}),!1)}}):le(O,function(){var V=T;return function(){return--V<0}})),this},Zt.prototype.limit=function(T){return this._ctx.limit=Math.min(this._ctx.limit,T),le(this._ctx,function(){var O=T;return function(V,H,Q){return--O<=0&&H(Q),0<=O}},!0),this},Zt.prototype.until=function(T,O){return se(this._ctx,function(V,H,Q){return!T(V.value)||(H(Q),O)}),this},Zt.prototype.first=function(T){return this.limit(1).toArray(function(O){return O[0]}).then(T)},Zt.prototype.last=function(T){return this.reverse().first(T)},Zt.prototype.filter=function(T){var O;return se(this._ctx,function(V){return T(V.value)}),(O=this._ctx).isMatch=_r(O.isMatch,T),this},Zt.prototype.and=function(T){return this.filter(T)},Zt.prototype.or=function(T){return new this.db.WhereClause(this._ctx.table,T,this)},Zt.prototype.reverse=function(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},Zt.prototype.desc=function(){return this.reverse()},Zt.prototype.eachKey=function(T){var O=this._ctx;return O.keysOnly=!O.isMatch,this.each(function(V,H){T(H.key,H)})},Zt.prototype.eachUniqueKey=function(T){return this._ctx.unique="unique",this.eachKey(T)},Zt.prototype.eachPrimaryKey=function(T){var O=this._ctx;return O.keysOnly=!O.isMatch,this.each(function(V,H){T(H.primaryKey,H)})},Zt.prototype.keys=function(T){var O=this._ctx;O.keysOnly=!O.isMatch;var V=[];return this.each(function(H,Q){V.push(Q.key)}).then(function(){return V}).then(T)},Zt.prototype.primaryKeys=function(T){var O=this._ctx;if(O.dir==="next"&&K(O,!0)&&0<O.limit)return this._read(function(H){var Q=it(O,O.table.core.schema);return O.table.core.query({trans:H,values:!1,limit:O.limit,query:{index:Q,range:O.range}})}).then(function(H){return H.result}).then(T);O.keysOnly=!O.isMatch;var V=[];return this.each(function(H,Q){V.push(Q.primaryKey)}).then(function(){return V}).then(T)},Zt.prototype.uniqueKeys=function(T){return this._ctx.unique="unique",this.keys(T)},Zt.prototype.firstKey=function(T){return this.limit(1).keys(function(O){return O[0]}).then(T)},Zt.prototype.lastKey=function(T){return this.reverse().firstKey(T)},Zt.prototype.distinct=function(){var T=this._ctx,T=T.index&&T.table.schema.idxByName[T.index];if(!T||!T.multi)return this;var O={};return se(this._ctx,function(Q){var H=Q.primaryKey.toString(),Q=d(O,H);return O[H]=!0,!Q}),this},Zt.prototype.modify=function(T){var O=this,V=this._ctx;return this._write(function(H){var Q,re,de;de=typeof T=="function"?T:(Q=i(T),re=Q.length,function(Ee){for(var Ve=!1,Ge=0;Ge<re;++Ge){var We=Q[Ge],qe=T[We],ht=j(Ee,We);qe instanceof Rt?(k(Ee,We,qe.execute(ht)),Ve=!0):ht!==qe&&(k(Ee,We,qe),Ve=!0)}return Ve});var ve=V.table.core,ye=ve.schema.primaryKey,Se=ye.outbound,Ce=ye.extractKey,Ie=200,ye=O.db._options.modifyChunkSize;ye&&(Ie=typeof ye=="object"?ye[ve.name]||ye["*"]||200:ye);function Ne(Ee,We){var Ge=We.failures,We=We.numFailures;Ae+=Ee-We;for(var qe=0,ht=i(Ge);qe<ht.length;qe++){var vt=ht[qe];we.push(Ge[vt])}}var we=[],Ae=0,Me=[];return O.clone().primaryKeys().then(function(Ee){function Ve(We){var qe=Math.min(Ie,Ee.length-We);return ve.getMany({trans:H,keys:Ee.slice(We,We+qe),cache:"immutable"}).then(function(ht){for(var vt=[],ct=[],mt=Se?[]:null,_t=[],ut=0;ut<qe;++ut){var Et=ht[ut],Dt={value:Z(Et),primKey:Ee[We+ut]};de.call(Dt,Dt.value,Dt)!==!1&&(Dt.value==null?_t.push(Ee[We+ut]):Se||Gt(Ce(Et),Ce(Dt.value))===0?(ct.push(Dt.value),Se&&mt.push(Ee[We+ut])):(_t.push(Ee[We+ut]),vt.push(Dt.value)))}return Promise.resolve(0<vt.length&&ve.mutate({trans:H,type:"add",values:vt}).then(function(Pt){for(var Ht in Pt.failures)_t.splice(parseInt(Ht),1);Ne(vt.length,Pt)})).then(function(){return(0<ct.length||Ge&&typeof T=="object")&&ve.mutate({trans:H,type:"put",keys:mt,values:ct,criteria:Ge,changeSpec:typeof T!="function"&&T,isAdditionalChunk:0<We}).then(function(Pt){return Ne(ct.length,Pt)})}).then(function(){return(0<_t.length||Ge&&T===mi)&&ve.mutate({trans:H,type:"delete",keys:_t,criteria:Ge,isAdditionalChunk:0<We}).then(function(Pt){return Ne(_t.length,Pt)})}).then(function(){return Ee.length>We+qe&&Ve(We+Ie)})})}var Ge=K(V)&&V.limit===1/0&&(typeof T!="function"||T===mi)&&{index:V.index,range:V.range};return Ve(0).then(function(){if(0<we.length)throw new ue("Error modifying one or more objects",we,Ae,Me);return Ee.length})})})},Zt.prototype.delete=function(){var T=this._ctx,O=T.range;return K(T)&&(T.isPrimKey||O.type===3)?this._write(function(V){var H=T.table.core.schema.primaryKey,Q=O;return T.table.core.count({trans:V,query:{index:H,range:Q}}).then(function(re){return T.table.core.mutate({trans:V,type:"deleteRange",range:Q}).then(function(de){var ve=de.failures;if(de.lastResult,de.results,de=de.numFailures,de)throw new ue("Could not delete some values",Object.keys(ve).map(function(Se){return ve[Se]}),re-de);return re-de})})}):this.modify(mi)},Zt);function Zt(){}var mi=function(T,O){return O.value=null};function xo(T,O){return T<O?-1:T===O?0:1}function Vi(T,O){return O<T?-1:T===O?0:1}function fr(T,O,V){return T=T instanceof Js?new T.Collection(T):T,T._ctx.error=new(V||TypeError)(O),T}function Rs(T){return new T.Collection(T,function(){return Co("")}).limit(0)}function qs(T,O,V,H){var Q,re,de,ve,Se,Ce,Ie,ye=V.length;if(!V.every(function(Ae){return typeof Ae=="string"}))return fr(T,Is);function Ne(Ae){Q=Ae==="next"?function(Ee){return Ee.toUpperCase()}:function(Ee){return Ee.toLowerCase()},re=Ae==="next"?function(Ee){return Ee.toLowerCase()}:function(Ee){return Ee.toUpperCase()},de=Ae==="next"?xo:Vi;var Me=V.map(function(Ee){return{lower:re(Ee),upper:Q(Ee)}}).sort(function(Ee,Ve){return de(Ee.lower,Ve.lower)});ve=Me.map(function(Ee){return Ee.upper}),Se=Me.map(function(Ee){return Ee.lower}),Ie=(Ce=Ae)==="next"?"":H}Ne("next"),T=new T.Collection(T,function(){return ns(ve[0],Se[ye-1]+H)}),T._ondirectionchange=function(Ae){Ne(Ae)};var we=0;return T._addAlgorithm(function(Ae,Me,Ee){var Ve=Ae.key;if(typeof Ve!="string")return!1;var Ge=re(Ve);if(O(Ge,Se,we))return!0;for(var We=null,qe=we;qe<ye;++qe){var ht=function(vt,ct,mt,_t,ut,Et){for(var Dt=Math.min(vt.length,_t.length),Pt=-1,Ht=0;Ht<Dt;++Ht){var Rr=ct[Ht];if(Rr!==_t[Ht])return ut(vt[Ht],mt[Ht])<0?vt.substr(0,Ht)+mt[Ht]+mt.substr(Ht+1):ut(vt[Ht],_t[Ht])<0?vt.substr(0,Ht)+_t[Ht]+mt.substr(Ht+1):0<=Pt?vt.substr(0,Pt)+ct[Pt]+mt.substr(Pt+1):null;ut(vt[Ht],Rr)<0&&(Pt=Ht)}return Dt<_t.length&&Et==="next"?vt+mt.substr(vt.length):Dt<vt.length&&Et==="prev"?vt.substr(0,mt.length):Pt<0?null:vt.substr(0,Pt)+_t[Pt]+mt.substr(Pt+1)}(Ve,Ge,ve[qe],Se[qe],de,Ce);ht===null&&We===null?we=qe+1:(We===null||0<de(We,ht))&&(We=ht)}return Me(We!==null?function(){Ae.continue(We+Ie)}:Ee),!1}),T}function ns(T,O,V,H){return{type:2,lower:T,upper:O,lowerOpen:V,upperOpen:H}}function Co(T){return{type:1,lower:T,upper:T}}var Js=(Object.defineProperty(jn.prototype,"Collection",{get:function(){return this._ctx.table.db.Collection},enumerable:!1,configurable:!0}),jn.prototype.between=function(T,O,V,H){V=V!==!1,H=H===!0;try{return 0<this._cmp(T,O)||this._cmp(T,O)===0&&(V||H)&&(!V||!H)?Rs(this):new this.Collection(this,function(){return ns(T,O,!V,!H)})}catch{return fr(this,sr)}},jn.prototype.equals=function(T){return T==null?fr(this,sr):new this.Collection(this,function(){return Co(T)})},jn.prototype.above=function(T){return T==null?fr(this,sr):new this.Collection(this,function(){return ns(T,void 0,!0)})},jn.prototype.aboveOrEqual=function(T){return T==null?fr(this,sr):new this.Collection(this,function(){return ns(T,void 0,!1)})},jn.prototype.below=function(T){return T==null?fr(this,sr):new this.Collection(this,function(){return ns(void 0,T,!1,!0)})},jn.prototype.belowOrEqual=function(T){return T==null?fr(this,sr):new this.Collection(this,function(){return ns(void 0,T)})},jn.prototype.startsWith=function(T){return typeof T!="string"?fr(this,Is):this.between(T,T+yr,!0,!0)},jn.prototype.startsWithIgnoreCase=function(T){return T===""?this.startsWith(T):qs(this,function(O,V){return O.indexOf(V[0])===0},[T],yr)},jn.prototype.equalsIgnoreCase=function(T){return qs(this,function(O,V){return O===V[0]},[T],"")},jn.prototype.anyOfIgnoreCase=function(){var T=R.apply(z,arguments);return T.length===0?Rs(this):qs(this,function(O,V){return V.indexOf(O)!==-1},T,"")},jn.prototype.startsWithAnyOfIgnoreCase=function(){var T=R.apply(z,arguments);return T.length===0?Rs(this):qs(this,function(O,V){return V.some(function(H){return O.indexOf(H)===0})},T,yr)},jn.prototype.anyOf=function(){var T=this,O=R.apply(z,arguments),V=this._cmp;try{O.sort(V)}catch{return fr(this,sr)}if(O.length===0)return Rs(this);var H=new this.Collection(this,function(){return ns(O[0],O[O.length-1])});H._ondirectionchange=function(re){V=re==="next"?T._ascending:T._descending,O.sort(V)};var Q=0;return H._addAlgorithm(function(re,de,ve){for(var Se=re.key;0<V(Se,O[Q]);)if(++Q===O.length)return de(ve),!1;return V(Se,O[Q])===0||(de(function(){re.continue(O[Q])}),!1)}),H},jn.prototype.notEqual=function(T){return this.inAnyRange([[-1/0,T],[T,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})},jn.prototype.noneOf=function(){var T=R.apply(z,arguments);if(T.length===0)return new this.Collection(this);try{T.sort(this._ascending)}catch{return fr(this,sr)}var O=T.reduce(function(V,H){return V?V.concat([[V[V.length-1][1],H]]):[[-1/0,H]]},null);return O.push([T[T.length-1],this.db._maxKey]),this.inAnyRange(O,{includeLowers:!1,includeUppers:!1})},jn.prototype.inAnyRange=function(Ve,O){var V=this,H=this._cmp,Q=this._ascending,re=this._descending,de=this._min,ve=this._max;if(Ve.length===0)return Rs(this);if(!Ve.every(function(Ge){return Ge[0]!==void 0&&Ge[1]!==void 0&&Q(Ge[0],Ge[1])<=0}))return fr(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",ce.InvalidArgument);var Se=!O||O.includeLowers!==!1,Ce=O&&O.includeUppers===!0,Ie,ye=Q;function Ne(Ge,We){return ye(Ge[0],We[0])}try{(Ie=Ve.reduce(function(Ge,We){for(var qe=0,ht=Ge.length;qe<ht;++qe){var vt=Ge[qe];if(H(We[0],vt[1])<0&&0<H(We[1],vt[0])){vt[0]=de(vt[0],We[0]),vt[1]=ve(vt[1],We[1]);break}}return qe===ht&&Ge.push(We),Ge},[])).sort(Ne)}catch{return fr(this,sr)}var we=0,Ae=Ce?function(Ge){return 0<Q(Ge,Ie[we][1])}:function(Ge){return 0<=Q(Ge,Ie[we][1])},Me=Se?function(Ge){return 0<re(Ge,Ie[we][0])}:function(Ge){return 0<=re(Ge,Ie[we][0])},Ee=Ae,Ve=new this.Collection(this,function(){return ns(Ie[0][0],Ie[Ie.length-1][1],!Se,!Ce)});return Ve._ondirectionchange=function(Ge){ye=Ge==="next"?(Ee=Ae,Q):(Ee=Me,re),Ie.sort(Ne)},Ve._addAlgorithm(function(Ge,We,qe){for(var ht,vt=Ge.key;Ee(vt);)if(++we===Ie.length)return We(qe),!1;return!Ae(ht=vt)&&!Me(ht)||(V._cmp(vt,Ie[we][1])===0||V._cmp(vt,Ie[we][0])===0||We(function(){ye===Q?Ge.continue(Ie[we][0]):Ge.continue(Ie[we][1])}),!1)}),Ve},jn.prototype.startsWithAnyOf=function(){var T=R.apply(z,arguments);return T.every(function(O){return typeof O=="string"})?T.length===0?Rs(this):this.inAnyRange(T.map(function(O){return[O,O+yr]})):fr(this,"startsWithAnyOf() only works with strings")},jn);function jn(){}function Xr(T){return It(function(O){return Qs(O),T(O.target.error),!1})}function Qs(T){T.stopPropagation&&T.stopPropagation(),T.preventDefault&&T.preventDefault()}var vi="storagemutated",ei="x-storagemutated-1",ir=pe(null,vi),ga=(Sr.prototype._lock=function(){return C(!at.global),++this._reculock,this._reculock!==1||at.global||(at.lockOwnerFor=this),this},Sr.prototype._unlock=function(){if(C(!at.global),--this._reculock==0)for(at.global||(at.lockOwnerFor=null);0<this._blockedFuncs.length&&!this._locked();){var T=this._blockedFuncs.shift();try{vr(T[1],T[0])}catch{}}return this},Sr.prototype._locked=function(){return this._reculock&&at.lockOwnerFor!==this},Sr.prototype.create=function(T){var O=this;if(!this.mode)return this;var V=this.db.idbdb,H=this.db._state.dbOpenError;if(C(!this.idbtrans),!T&&!V)switch(H&&H.name){case"DatabaseClosedError":throw new ce.DatabaseClosed(H);case"MissingAPIError":throw new ce.MissingAPI(H.message,H);default:throw new ce.OpenFailed(H)}if(!this.active)throw new ce.TransactionInactive;return C(this._completion._state===null),(T=this.idbtrans=T||(this.db.core||V).transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability})).onerror=It(function(Q){Qs(Q),O._reject(T.error)}),T.onabort=It(function(Q){Qs(Q),O.active&&O._reject(new ce.Abort(T.error)),O.active=!1,O.on("abort").fire(Q)}),T.oncomplete=It(function(){O.active=!1,O._resolve(),"mutatedParts"in T&&ir.storagemutated.fire(T.mutatedParts)}),this},Sr.prototype._promise=function(T,O,V){var H=this;if(T==="readwrite"&&this.mode!=="readwrite")return mn(new ce.ReadOnly("Transaction is readonly"));if(!this.active)return mn(new ce.TransactionInactive);if(this._locked())return new Ze(function(re,de){H._blockedFuncs.push([function(){H._promise(T,O,V).then(re,de)},at])});if(V)return rr(function(){var re=new Ze(function(de,ve){H._lock();var Se=O(de,ve,H);Se&&Se.then&&Se.then(de,ve)});return re.finally(function(){return H._unlock()}),re._lib=!0,re});var Q=new Ze(function(re,de){var ve=O(re,de,H);ve&&ve.then&&ve.then(re,de)});return Q._lib=!0,Q},Sr.prototype._root=function(){return this.parent?this.parent._root():this},Sr.prototype.waitFor=function(T){var O,V=this._root(),H=Ze.resolve(T);V._waitingFor?V._waitingFor=V._waitingFor.then(function(){return H}):(V._waitingFor=H,V._waitingQueue=[],O=V.idbtrans.objectStore(V.storeNames[0]),function re(){for(++V._spinCount;V._waitingQueue.length;)V._waitingQueue.shift()();V._waitingFor&&(O.get(-1/0).onsuccess=re)}());var Q=V._waitingFor;return new Ze(function(re,de){H.then(function(ve){return V._waitingQueue.push(It(re.bind(null,ve)))},function(ve){return V._waitingQueue.push(It(de.bind(null,ve)))}).finally(function(){V._waitingFor===Q&&(V._waitingFor=null)})})},Sr.prototype.abort=function(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new ce.Abort))},Sr.prototype.table=function(T){var O=this._memoizedTables||(this._memoizedTables={});if(d(O,T))return O[T];var V=this.schema[T];if(!V)throw new ce.NotFound("Table "+T+" not part of transaction");return V=new this.db.Table(T,V,this),V.core=this.db.core.table(T),O[T]=V},Sr);function Sr(){}function rs(T,O,V,H,Q,re,de){return{name:T,keyPath:O,unique:V,multi:H,auto:Q,compound:re,src:(V&&!de?"&":"")+(H?"*":"")+(Q?"++":"")+Eo(O)}}function Eo(T){return typeof T=="string"?T:T?"["+[].join.call(T,"+")+"]":""}function gi(T,O,V){return{name:T,primKey:O,indexes:V,mappedClass:null,idxByName:(H=function(Q){return[Q.name,Q]},V.reduce(function(Q,re,de){return de=H(re,de),de&&(Q[de[0]]=de[1]),Q},{}))};var H}var bi=function(T){try{return T.only([[]]),bi=function(){return[[]]},[[]]}catch{return bi=function(){return yr},yr}};function yi(T){return T==null?function(){}:typeof T=="string"?(O=T).split(".").length===1?function(V){return V[O]}:function(V){return j(V,O)}:function(V){return j(V,T)};var O}function Fi(T){return[].slice.call(T)}var qa=0;function Fn(T){return T==null?":id":typeof T=="string"?T:"[".concat(T.join("+"),"]")}function ti(T,O,Se){function H(Ee){if(Ee.type===3)return null;if(Ee.type===4)throw new Error("Cannot convert never type to IDBKeyRange");var we=Ee.lower,Ae=Ee.upper,Me=Ee.lowerOpen,Ee=Ee.upperOpen;return we===void 0?Ae===void 0?null:O.upperBound(Ae,!!Ee):Ae===void 0?O.lowerBound(we,!!Me):O.bound(we,Ae,!!Me,!!Ee)}function Q(Ne){var we,Ae=Ne.name;return{name:Ae,schema:Ne,mutate:function(Me){var Ee=Me.trans,Ve=Me.type,Ge=Me.keys,We=Me.values,qe=Me.range;return new Promise(function(ht,vt){ht=It(ht);var ct=Ee.objectStore(Ae),mt=ct.keyPath==null,_t=Ve==="put"||Ve==="add";if(!_t&&Ve!=="delete"&&Ve!=="deleteRange")throw new Error("Invalid operation type: "+Ve);var ut,Et=(Ge||We||{length:1}).length;if(Ge&&We&&Ge.length!==We.length)throw new Error("Given keys array must have same length as given values array.");if(Et===0)return ht({numFailures:0,failures:{},results:[],lastResult:void 0});function Dt(Cr){++Rr,Qs(Cr)}var Pt=[],Ht=[],Rr=0;if(Ve==="deleteRange"){if(qe.type===4)return ht({numFailures:Rr,failures:Ht,results:[],lastResult:void 0});qe.type===3?Pt.push(ut=ct.clear()):Pt.push(ut=ct.delete(H(qe)))}else{var mt=_t?mt?[We,Ge]:[We,null]:[Ge,null],Ut=mt[0],Jn=mt[1];if(_t)for(var or=0;or<Et;++or)Pt.push(ut=Jn&&Jn[or]!==void 0?ct[Ve](Ut[or],Jn[or]):ct[Ve](Ut[or])),ut.onerror=Dt;else for(or=0;or<Et;++or)Pt.push(ut=ct[Ve](Ut[or])),ut.onerror=Dt}function ri(Cr){Cr=Cr.target.result,Pt.forEach(function(Ds,Si){return Ds.error!=null&&(Ht[Si]=Ds.error)}),ht({numFailures:Rr,failures:Ht,results:Ve==="delete"?Ge:Pt.map(function(Ds){return Ds.result}),lastResult:Cr})}ut.onerror=function(Cr){Dt(Cr),ri(Cr)},ut.onsuccess=ri})},getMany:function(Me){var Ee=Me.trans,Ve=Me.keys;return new Promise(function(Ge,We){Ge=It(Ge);for(var qe,ht=Ee.objectStore(Ae),vt=Ve.length,ct=new Array(vt),mt=0,_t=0,ut=function(Pt){Pt=Pt.target,ct[Pt._pos]=Pt.result,++_t===mt&&Ge(ct)},Et=Xr(We),Dt=0;Dt<vt;++Dt)Ve[Dt]!=null&&((qe=ht.get(Ve[Dt]))._pos=Dt,qe.onsuccess=ut,qe.onerror=Et,++mt);mt===0&&Ge(ct)})},get:function(Me){var Ee=Me.trans,Ve=Me.key;return new Promise(function(Ge,We){Ge=It(Ge);var qe=Ee.objectStore(Ae).get(Ve);qe.onsuccess=function(ht){return Ge(ht.target.result)},qe.onerror=Xr(We)})},query:(we=Ce,function(Me){return new Promise(function(Ee,Ve){Ee=It(Ee);var Ge,We,qe,mt=Me.trans,ht=Me.values,vt=Me.limit,ut=Me.query,ct=vt===1/0?void 0:vt,_t=ut.index,ut=ut.range,mt=mt.objectStore(Ae),_t=_t.isPrimaryKey?mt:mt.index(_t.name),ut=H(ut);if(vt===0)return Ee({result:[]});we?((ct=ht?_t.getAll(ut,ct):_t.getAllKeys(ut,ct)).onsuccess=function(Et){return Ee({result:Et.target.result})},ct.onerror=Xr(Ve)):(Ge=0,We=!ht&&"openKeyCursor"in _t?_t.openKeyCursor(ut):_t.openCursor(ut),qe=[],We.onsuccess=function(Et){var Dt=We.result;return Dt?(qe.push(ht?Dt.value:Dt.primaryKey),++Ge===vt?Ee({result:qe}):void Dt.continue()):Ee({result:qe})},We.onerror=Xr(Ve))})}),openCursor:function(Me){var Ee=Me.trans,Ve=Me.values,Ge=Me.query,We=Me.reverse,qe=Me.unique;return new Promise(function(ht,vt){ht=It(ht);var _t=Ge.index,ct=Ge.range,mt=Ee.objectStore(Ae),mt=_t.isPrimaryKey?mt:mt.index(_t.name),_t=We?qe?"prevunique":"prev":qe?"nextunique":"next",ut=!Ve&&"openKeyCursor"in mt?mt.openKeyCursor(H(ct),_t):mt.openCursor(H(ct),_t);ut.onerror=Xr(vt),ut.onsuccess=It(function(Et){var Dt,Pt,Ht,Rr,Ut=ut.result;Ut?(Ut.___id=++qa,Ut.done=!1,Dt=Ut.continue.bind(Ut),Pt=(Pt=Ut.continuePrimaryKey)&&Pt.bind(Ut),Ht=Ut.advance.bind(Ut),Rr=function(){throw new Error("Cursor not stopped")},Ut.trans=Ee,Ut.stop=Ut.continue=Ut.continuePrimaryKey=Ut.advance=function(){throw new Error("Cursor not started")},Ut.fail=It(vt),Ut.next=function(){var Jn=this,or=1;return this.start(function(){return or--?Jn.continue():Jn.stop()}).then(function(){return Jn})},Ut.start=function(Jn){function or(){if(ut.result)try{Jn()}catch(Cr){Ut.fail(Cr)}else Ut.done=!0,Ut.start=function(){throw new Error("Cursor behind last entry")},Ut.stop()}var ri=new Promise(function(Cr,Ds){Cr=It(Cr),ut.onerror=Xr(Ds),Ut.fail=Ds,Ut.stop=function(Si){Ut.stop=Ut.continue=Ut.continuePrimaryKey=Ut.advance=Rr,Cr(Si)}});return ut.onsuccess=It(function(Cr){ut.onsuccess=or,or()}),Ut.continue=Dt,Ut.continuePrimaryKey=Pt,Ut.advance=Ht,or(),ri},ht(Ut)):ht(null)},vt)})},count:function(Me){var Ee=Me.query,Ve=Me.trans,Ge=Ee.index,We=Ee.range;return new Promise(function(qe,ht){var vt=Ve.objectStore(Ae),ct=Ge.isPrimaryKey?vt:vt.index(Ge.name),vt=H(We),ct=vt?ct.count(vt):ct.count();ct.onsuccess=It(function(mt){return qe(mt.target.result)}),ct.onerror=Xr(ht)})}}}var re,de,ve,Ie=(de=Se,ve=Fi((re=T).objectStoreNames),{schema:{name:re.name,tables:ve.map(function(Ne){return de.objectStore(Ne)}).map(function(Ne){var we=Ne.keyPath,Ee=Ne.autoIncrement,Ae=o(we),Me={},Ee={name:Ne.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:we==null,compound:Ae,keyPath:we,autoIncrement:Ee,unique:!0,extractKey:yi(we)},indexes:Fi(Ne.indexNames).map(function(Ve){return Ne.index(Ve)}).map(function(qe){var Ge=qe.name,We=qe.unique,ht=qe.multiEntry,qe=qe.keyPath,ht={name:Ge,compound:o(qe),keyPath:qe,unique:We,multiEntry:ht,extractKey:yi(qe)};return Me[Fn(qe)]=ht}),getIndexByKeyPath:function(Ve){return Me[Fn(Ve)]}};return Me[":id"]=Ee.primaryKey,we!=null&&(Me[Fn(we)]=Ee.primaryKey),Ee})},hasGetAll:0<ve.length&&"getAll"in de.objectStore(ve[0])&&!(typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}),Se=Ie.schema,Ce=Ie.hasGetAll,Ie=Se.tables.map(Q),ye={};return Ie.forEach(function(Ne){return ye[Ne.name]=Ne}),{stack:"dbcore",transaction:T.transaction.bind(T),table:function(Ne){if(!ye[Ne])throw new Error("Table '".concat(Ne,"' not found"));return ye[Ne]},MIN_KEY:-1/0,MAX_KEY:bi(O),schema:Se}}function jo(T,O,V,H){var Q=V.IDBKeyRange;return V.indexedDB,{dbcore:(H=ti(O,Q,H),T.dbcore.reduce(function(re,de){return de=de.create,r(r({},re),de(re))},H))}}function Ns(T,H){var V=H.db,H=jo(T._middlewares,V,T._deps,H);T.core=H.dbcore,T.tables.forEach(function(Q){var re=Q.name;T.core.schema.tables.some(function(de){return de.name===re})&&(Q.core=T.core.table(re),T[re]instanceof T.Table&&(T[re].core=Q.core))})}function ko(T,O,V,H){V.forEach(function(Q){var re=H[Q];O.forEach(function(de){var ve=function Se(Ce,Ie){return b(Ce,Ie)||(Ce=l(Ce))&&Se(Ce,Ie)}(de,Q);(!ve||"value"in ve&&ve.value===void 0)&&(de===T.Transaction.prototype||de instanceof T.Transaction?v(de,Q,{get:function(){return this.table(Q)},set:function(Se){p(this,Q,{value:Se,writable:!0,configurable:!0,enumerable:!0})}}):de[Q]=new T.Table(Q,re))})})}function zi(T,O){O.forEach(function(V){for(var H in V)V[H]instanceof T.Table&&delete V[H]})}function ba(T,O){return T._cfg.version-O._cfg.version}function Hi(T,O,V,H){var Q=T._dbSchema;V.objectStoreNames.contains("$meta")&&!Q.$meta&&(Q.$meta=gi("$meta",ss("")[0],[]),T._storeNames.push("$meta"));var re=T._createTransaction("readwrite",T._storeNames,Q);re.create(V),re._completion.catch(H);var de=re._reject.bind(re),ve=at.transless||at;rr(function(){return at.trans=re,at.transless=ve,O!==0?(Ns(T,V),Ce=O,((Se=re).storeNames.includes("$meta")?Se.table("$meta").get("version").then(function(Ie){return Ie??Ce}):Ze.resolve(Ce)).then(function(Ie){return Ne=Ie,we=re,Ae=V,Me=[],Ie=(ye=T)._versions,Ee=ye._dbSchema=qr(0,ye.idbdb,Ae),(Ie=Ie.filter(function(Ve){return Ve._cfg.version>=Ne})).length!==0?(Ie.forEach(function(Ve){Me.push(function(){var Ge=Ee,We=Ve._cfg.dbschema;vs(ye,Ge,Ae),vs(ye,We,Ae),Ee=ye._dbSchema=We;var qe=Ao(Ge,We);qe.add.forEach(function(_t){ya(Ae,_t[0],_t[1].primKey,_t[1].indexes)}),qe.change.forEach(function(_t){if(_t.recreate)throw new ce.Upgrade("Not yet support for changing primary key");var ut=Ae.objectStore(_t.name);_t.add.forEach(function(Et){return Io(ut,Et)}),_t.change.forEach(function(Et){ut.deleteIndex(Et.name),Io(ut,Et)}),_t.del.forEach(function(Et){return ut.deleteIndex(Et)})});var ht=Ve._cfg.contentUpgrade;if(ht&&Ve._cfg.version>Ne){Ns(ye,Ae),we._memoizedTables={};var vt=A(We);qe.del.forEach(function(_t){vt[_t]=Ge[_t]}),zi(ye,[ye.Transaction.prototype]),ko(ye,[ye.Transaction.prototype],i(vt),vt),we.schema=vt;var ct,mt=Y(ht);return mt&&Kn(),qe=Ze.follow(function(){var _t;(ct=ht(we))&&mt&&(_t=Bn.bind(null,null),ct.then(_t,_t))}),ct&&typeof ct.then=="function"?Ze.resolve(ct):qe.then(function(){return ct})}}),Me.push(function(Ge){var We,qe,ht=Ve._cfg.dbschema;We=ht,qe=Ge,[].slice.call(qe.db.objectStoreNames).forEach(function(vt){return We[vt]==null&&qe.db.deleteObjectStore(vt)}),zi(ye,[ye.Transaction.prototype]),ko(ye,[ye.Transaction.prototype],ye._storeNames,ye._dbSchema),we.schema=ye._dbSchema}),Me.push(function(Ge){ye.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(ye.idbdb.version/10)===Ve._cfg.version?(ye.idbdb.deleteObjectStore("$meta"),delete ye._dbSchema.$meta,ye._storeNames=ye._storeNames.filter(function(We){return We!=="$meta"})):Ge.objectStore("$meta").put(Ve._cfg.version,"version"))})}),function Ve(){return Me.length?Ze.resolve(Me.shift()(we.idbtrans)).then(Ve):Ze.resolve()}().then(function(){Ja(Ee,Ae)})):Ze.resolve();var ye,Ne,we,Ae,Me,Ee}).catch(de)):(i(Q).forEach(function(Ie){ya(V,Ie,Q[Ie].primKey,Q[Ie].indexes)}),Ns(T,V),void Ze.follow(function(){return T.on.populate.fire(re)}).catch(de));var Se,Ce})}function To(T,O){Ja(T._dbSchema,O),O.db.version%10!=0||O.objectStoreNames.contains("$meta")||O.db.createObjectStore("$meta").add(Math.ceil(O.db.version/10-1),"version");var V=qr(0,T.idbdb,O);vs(T,T._dbSchema,O);for(var H=0,Q=Ao(V,T._dbSchema).change;H<Q.length;H++){var re=function(de){if(de.change.length||de.recreate)return console.warn("Unable to patch indexes of table ".concat(de.name," because it has changes on the type of index or primary key.")),{value:void 0};var ve=O.objectStore(de.name);de.add.forEach(function(Se){Be&&console.debug("Dexie upgrade patch: Creating missing index ".concat(de.name,".").concat(Se.src)),Io(ve,Se)})}(Q[H]);if(typeof re=="object")return re.value}}function Ao(T,O){var V,H={del:[],add:[],change:[]};for(V in T)O[V]||H.del.push(V);for(V in O){var Q=T[V],re=O[V];if(Q){var de={name:V,def:re,recreate:!1,del:[],add:[],change:[]};if(""+(Q.primKey.keyPath||"")!=""+(re.primKey.keyPath||"")||Q.primKey.auto!==re.primKey.auto)de.recreate=!0,H.change.push(de);else{var ve=Q.idxByName,Se=re.idxByName,Ce=void 0;for(Ce in ve)Se[Ce]||de.del.push(Ce);for(Ce in Se){var Ie=ve[Ce],ye=Se[Ce];Ie?Ie.src!==ye.src&&de.change.push(ye):de.add.push(ye)}(0<de.del.length||0<de.add.length||0<de.change.length)&&H.change.push(de)}}else H.add.push([V,re])}return H}function ya(T,O,V,H){var Q=T.db.createObjectStore(O,V.keyPath?{keyPath:V.keyPath,autoIncrement:V.auto}:{autoIncrement:V.auto});return H.forEach(function(re){return Io(Q,re)}),Q}function Ja(T,O){i(T).forEach(function(V){O.db.objectStoreNames.contains(V)||(Be&&console.debug("Dexie: Creating missing table",V),ya(O,V,T[V].primKey,T[V].indexes))})}function Io(T,O){T.createIndex(O.name,O.keyPath,{unique:O.unique,multiEntry:O.multi})}function qr(T,O,V){var H={};return _(O.objectStoreNames,0).forEach(function(Q){for(var re=V.objectStore(Q),de=rs(Eo(Ce=re.keyPath),Ce||"",!0,!1,!!re.autoIncrement,Ce&&typeof Ce!="string",!0),ve=[],Se=0;Se<re.indexNames.length;++Se){var Ie=re.index(re.indexNames[Se]),Ce=Ie.keyPath,Ie=rs(Ie.name,Ce,!!Ie.unique,!!Ie.multiEntry,!1,Ce&&typeof Ce!="string",!1);ve.push(Ie)}H[Q]=gi(Q,de,ve)}),H}function vs(T,O,V){for(var H=V.db.objectStoreNames,Q=0;Q<H.length;++Q){var re=H[Q],de=V.objectStore(re);T._hasGetAll="getAll"in de;for(var ve=0;ve<de.indexNames.length;++ve){var Se=de.indexNames[ve],Ce=de.index(Se).keyPath,Ie=typeof Ce=="string"?Ce:"["+_(Ce).join("+")+"]";!O[re]||(Ce=O[re].idxByName[Ie])&&(Ce.name=Se,delete O[re].idxByName[Ie],O[re].idxByName[Se]=Ce)}}typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&c.WorkerGlobalScope&&c instanceof c.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(T._hasGetAll=!1)}function ss(T){return T.split(",").map(function(O,V){var H=(O=O.trim()).replace(/([&*]|\+\+)/g,""),Q=/^\[/.test(H)?H.match(/^\[(.*)\]$/)[1].split("+"):H;return rs(H,Q||null,/\&/.test(O),/\*/.test(O),/\+\+/.test(O),o(Q),V===0)})}var ni=(Qa.prototype._parseStoresSpec=function(T,O){i(T).forEach(function(V){if(T[V]!==null){var H=ss(T[V]),Q=H.shift();if(Q.unique=!0,Q.multi)throw new ce.Schema("Primary key cannot be multi-valued");H.forEach(function(re){if(re.auto)throw new ce.Schema("Only primary key can be marked as autoIncrement (++)");if(!re.keyPath)throw new ce.Schema("Index must have a name and cannot be an empty string")}),O[V]=gi(V,Q,H)}})},Qa.prototype.stores=function(V){var O=this.db;this._cfg.storesSource=this._cfg.storesSource?u(this._cfg.storesSource,V):V;var V=O._versions,H={},Q={};return V.forEach(function(re){u(H,re._cfg.storesSource),Q=re._cfg.dbschema={},re._parseStoresSpec(H,Q)}),O._dbSchema=Q,zi(O,[O._allTables,O,O.Transaction.prototype]),ko(O,[O._allTables,O,O.Transaction.prototype,this._cfg.tables],i(Q),Q),O._storeNames=i(Q),this},Qa.prototype.upgrade=function(T){return this._cfg.contentUpgrade=Le(this._cfg.contentUpgrade||Xe,T),this},Qa);function Qa(){}function mc(T,O){var V=T._dbNamesDB;return V||(V=T._dbNamesDB=new Ls(Or,{addons:[],indexedDB:T,IDBKeyRange:O})).version(1).stores({dbnames:"name"}),V.table("dbnames")}function el(T){return T&&typeof T.databases=="function"}function vc(T){return rr(function(){return at.letThrough=!0,T()})}function gc(T){return!("from"in T)}var xr=function(T,O){if(!this){var V=new xr;return T&&"d"in T&&u(V,T),V}u(this,arguments.length?{d:1,from:T,to:1<arguments.length?O:T}:{d:0})};function _a(T,O,V){var H=Gt(O,V);if(!isNaN(H)){if(0<H)throw RangeError();if(gc(T))return u(T,{from:O,to:V,d:1});var Q=T.l,H=T.r;if(Gt(V,T.from)<0)return Q?_a(Q,O,V):T.l={from:O,to:V,d:1,l:null,r:null},Ed(T);if(0<Gt(O,T.to))return H?_a(H,O,V):T.r={from:O,to:V,d:1,l:null,r:null},Ed(T);Gt(O,T.from)<0&&(T.from=O,T.l=null,T.d=H?H.d+1:1),0<Gt(V,T.to)&&(T.to=V,T.r=null,T.d=T.l?T.l.d+1:1),V=!T.r,Q&&!T.l&&Gi(T,Q),H&&V&&Gi(T,H)}}function Gi(T,O){gc(O)||function V(H,Se){var re=Se.from,de=Se.to,ve=Se.l,Se=Se.r;_a(H,re,de),ve&&V(H,ve),Se&&V(H,Se)}(T,O)}function Cd(T,O){var V=tl(O),H=V.next();if(H.done)return!1;for(var Q=H.value,re=tl(T),de=re.next(Q.from),ve=de.value;!H.done&&!de.done;){if(Gt(ve.from,Q.to)<=0&&0<=Gt(ve.to,Q.from))return!0;Gt(Q.from,ve.from)<0?Q=(H=V.next(ve.from)).value:ve=(de=re.next(Q.from)).value}return!1}function tl(T){var O=gc(T)?null:{s:0,n:T};return{next:function(V){for(var H=0<arguments.length;O;)switch(O.s){case 0:if(O.s=1,H)for(;O.n.l&&Gt(V,O.n.from)<0;)O={up:O,n:O.n.l,s:1};else for(;O.n.l;)O={up:O,n:O.n.l,s:1};case 1:if(O.s=2,!H||Gt(V,O.n.to)<=0)return{value:O.n,done:!1};case 2:if(O.n.r){O.s=3,O={up:O,n:O.n.r,s:0};continue}case 3:O=O.up}return{done:!0}}}}function Ed(T){var O,V,H=(((O=T.r)===null||O===void 0?void 0:O.d)||0)-(((V=T.l)===null||V===void 0?void 0:V.d)||0),Q=1<H?"r":H<-1?"l":"";Q&&(O=Q=="r"?"l":"r",V=r({},T),H=T[Q],T.from=H.from,T.to=H.to,T[Q]=H[Q],V[Q]=H[O],(T[O]=V).d=bc(V)),T.d=bc(T)}function bc(V){var O=V.r,V=V.l;return(O?V?Math.max(O.d,V.d):O.d:V?V.d:0)+1}function nl(T,O){return i(O).forEach(function(V){T[V]?Gi(T[V],O[V]):T[V]=function H(Q){var re,de,ve={};for(re in Q)d(Q,re)&&(de=Q[re],ve[re]=!de||typeof de!="object"||M.has(de.constructor)?de:H(de));return ve}(O[V])}),T}function yc(T,O){return T.all||O.all||Object.keys(T).some(function(V){return O[V]&&Cd(O[V],T[V])})}h(xr.prototype,((Jr={add:function(T){return Gi(this,T),this},addKey:function(T){return _a(this,T,T),this},addKeys:function(T){var O=this;return T.forEach(function(V){return _a(O,V,V)}),this},hasKey:function(T){var O=tl(this).next(T).value;return O&&Gt(O.from,T)<=0&&0<=Gt(O.to,T)}})[q]=function(){return tl(this)},Jr));var Wi={},_c={},wc=!1;function rl(T){nl(_c,T),wc||(wc=!0,setTimeout(function(){wc=!1,Sc(_c,!(_c={}))},0))}function Sc(T,O){O===void 0&&(O=!1);var V=new Set;if(T.all)for(var H=0,Q=Object.values(Wi);H<Q.length;H++)jd(de=Q[H],T,V,O);else for(var re in T){var de,ve=/^idb\:\/\/(.*)\/(.*)\//.exec(re);ve&&(re=ve[1],ve=ve[2],(de=Wi["idb://".concat(re,"/").concat(ve)])&&jd(de,T,V,O))}V.forEach(function(Se){return Se()})}function jd(T,O,V,H){for(var Q=[],re=0,de=Object.entries(T.queries.query);re<de.length;re++){for(var ve=de[re],Se=ve[0],Ce=[],Ie=0,ye=ve[1];Ie<ye.length;Ie++){var Ne=ye[Ie];yc(O,Ne.obsSet)?Ne.subscribers.forEach(function(Ee){return V.add(Ee)}):H&&Ce.push(Ne)}H&&Q.push([Se,Ce])}if(H)for(var we=0,Ae=Q;we<Ae.length;we++){var Me=Ae[we],Se=Me[0],Ce=Me[1];T.queries.query[Se]=Ce}}function Ep(T){var O=T._state,V=T._deps.indexedDB;if(O.isBeingOpened||T.idbdb)return O.dbReadyPromise.then(function(){return O.dbOpenError?mn(O.dbOpenError):T});O.isBeingOpened=!0,O.dbOpenError=null,O.openComplete=!1;var H=O.openCanceller,Q=Math.round(10*T.verno),re=!1;function de(){if(O.openCanceller!==H)throw new ce.DatabaseClosed("db.open() was cancelled")}function ve(){return new Ze(function(Ne,we){if(de(),!V)throw new ce.MissingAPI;var Ae=T.name,Me=O.autoSchema||!Q?V.open(Ae):V.open(Ae,Q);if(!Me)throw new ce.MissingAPI;Me.onerror=Xr(we),Me.onblocked=It(T._fireOnBlocked),Me.onupgradeneeded=It(function(Ee){var Ve;Ie=Me.transaction,O.autoSchema&&!T._options.allowEmptyDB?(Me.onerror=Qs,Ie.abort(),Me.result.close(),(Ve=V.deleteDatabase(Ae)).onsuccess=Ve.onerror=It(function(){we(new ce.NoSuchDatabase("Database ".concat(Ae," doesnt exist")))})):(Ie.onerror=Xr(we),Ee=Ee.oldVersion>Math.pow(2,62)?0:Ee.oldVersion,ye=Ee<1,T.idbdb=Me.result,re&&To(T,Ie),Hi(T,Ee/10,Ie,we))},we),Me.onsuccess=It(function(){Ie=null;var Ee,Ve,Ge,We,qe,ht=T.idbdb=Me.result,vt=_(ht.objectStoreNames);if(0<vt.length)try{var ct=ht.transaction((We=vt).length===1?We[0]:We,"readonly");if(O.autoSchema)Ve=ht,Ge=ct,(Ee=T).verno=Ve.version/10,Ge=Ee._dbSchema=qr(0,Ve,Ge),Ee._storeNames=_(Ve.objectStoreNames,0),ko(Ee,[Ee._allTables],i(Ge),Ge);else if(vs(T,T._dbSchema,ct),((qe=Ao(qr(0,(qe=T).idbdb,ct),qe._dbSchema)).add.length||qe.change.some(function(mt){return mt.add.length||mt.change.length}))&&!re)return console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this."),ht.close(),Q=ht.version+1,re=!0,Ne(ve());Ns(T,ct)}catch{}dr.push(T),ht.onversionchange=It(function(mt){O.vcFired=!0,T.on("versionchange").fire(mt)}),ht.onclose=It(function(mt){T.on("close").fire(mt)}),ye&&(qe=T._deps,ct=Ae,ht=qe.indexedDB,qe=qe.IDBKeyRange,el(ht)||ct===Or||mc(ht,qe).put({name:ct}).catch(Xe)),Ne()},we)}).catch(function(Ne){switch(Ne==null?void 0:Ne.name){case"UnknownError":if(0<O.PR1398_maxLoop)return O.PR1398_maxLoop--,console.warn("Dexie: Workaround for Chrome UnknownError on open()"),ve();break;case"VersionError":if(0<Q)return Q=0,ve()}return Ze.reject(Ne)})}var Se,Ce=O.dbReadyResolve,Ie=null,ye=!1;return Ze.race([H,(typeof navigator>"u"?Ze.resolve():!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(Ne){function we(){return indexedDB.databases().finally(Ne)}Se=setInterval(we,100),we()}).finally(function(){return clearInterval(Se)}):Promise.resolve()).then(ve)]).then(function(){return de(),O.onReadyBeingFired=[],Ze.resolve(vc(function(){return T.on.ready.fire(T.vip)})).then(function Ne(){if(0<O.onReadyBeingFired.length){var we=O.onReadyBeingFired.reduce(Le,Xe);return O.onReadyBeingFired=[],Ze.resolve(vc(function(){return we(T.vip)})).then(Ne)}})}).finally(function(){O.openCanceller===H&&(O.onReadyBeingFired=null,O.isBeingOpened=!1)}).catch(function(Ne){O.dbOpenError=Ne;try{Ie&&Ie.abort()}catch{}return H===O.openCanceller&&T._close(),mn(Ne)}).finally(function(){O.openComplete=!0,Ce()}).then(function(){var Ne;return ye&&(Ne={},T.tables.forEach(function(we){we.schema.indexes.forEach(function(Ae){Ae.name&&(Ne["idb://".concat(T.name,"/").concat(we.name,"/").concat(Ae.name)]=new xr(-1/0,[[[]]]))}),Ne["idb://".concat(T.name,"/").concat(we.name,"/")]=Ne["idb://".concat(T.name,"/").concat(we.name,"/:dels")]=new xr(-1/0,[[[]]])}),ir(vi).fire(Ne),Sc(Ne,!0)),T})}function wa(T){function O(re){return T.next(re)}var V=Q(O),H=Q(function(re){return T.throw(re)});function Q(re){return function(Se){var ve=re(Se),Se=ve.value;return ve.done?Se:Se&&typeof Se.then=="function"?Se.then(V,H):o(Se)?Promise.all(Se).then(V,H):V(Se)}}return Q(O)()}function _i(T,O,V){for(var H=o(T)?T.slice():[T],Q=0;Q<V;++Q)H.push(O);return H}var jp={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(T){return r(r({},T),{table:function(O){var V=T.table(O),H=V.schema,Q={},re=[];function de(ye,Ne,we){var Ae=Fn(ye),Me=Q[Ae]=Q[Ae]||[],Ee=ye==null?0:typeof ye=="string"?1:ye.length,Ve=0<Ne,Ve=r(r({},we),{name:Ve?"".concat(Ae,"(virtual-from:").concat(we.name,")"):we.name,lowLevelIndex:we,isVirtual:Ve,keyTail:Ne,keyLength:Ee,extractKey:yi(ye),unique:!Ve&&we.unique});return Me.push(Ve),Ve.isPrimaryKey||re.push(Ve),1<Ee&&de(Ee===2?ye[0]:ye.slice(0,Ee-1),Ne+1,we),Me.sort(function(Ge,We){return Ge.keyTail-We.keyTail}),Ve}O=de(H.primaryKey.keyPath,0,H.primaryKey),Q[":id"]=[O];for(var ve=0,Se=H.indexes;ve<Se.length;ve++){var Ce=Se[ve];de(Ce.keyPath,0,Ce)}function Ie(ye){var Ne,we=ye.query.index;return we.isVirtual?r(r({},ye),{query:{index:we.lowLevelIndex,range:(Ne=ye.query.range,we=we.keyTail,{type:Ne.type===1?2:Ne.type,lower:_i(Ne.lower,Ne.lowerOpen?T.MAX_KEY:T.MIN_KEY,we),lowerOpen:!0,upper:_i(Ne.upper,Ne.upperOpen?T.MIN_KEY:T.MAX_KEY,we),upperOpen:!0})}}):ye}return r(r({},V),{schema:r(r({},H),{primaryKey:O,indexes:re,getIndexByKeyPath:function(ye){return(ye=Q[Fn(ye)])&&ye[0]}}),count:function(ye){return V.count(Ie(ye))},query:function(ye){return V.query(Ie(ye))},openCursor:function(ye){var Ne=ye.query.index,we=Ne.keyTail,Ae=Ne.isVirtual,Me=Ne.keyLength;return Ae?V.openCursor(Ie(ye)).then(function(Ve){return Ve&&Ee(Ve)}):V.openCursor(ye);function Ee(Ve){return Object.create(Ve,{continue:{value:function(Ge){Ge!=null?Ve.continue(_i(Ge,ye.reverse?T.MAX_KEY:T.MIN_KEY,we)):ye.unique?Ve.continue(Ve.key.slice(0,Me).concat(ye.reverse?T.MIN_KEY:T.MAX_KEY,we)):Ve.continue()}},continuePrimaryKey:{value:function(Ge,We){Ve.continuePrimaryKey(_i(Ge,T.MAX_KEY,we),We)}},primaryKey:{get:function(){return Ve.primaryKey}},key:{get:function(){var Ge=Ve.key;return Me===1?Ge[0]:Ge.slice(0,Me)}},value:{get:function(){return Ve.value}}})}}})}})}};function sl(T,O,V,H){return V=V||{},H=H||"",i(T).forEach(function(Q){var re,de,ve;d(O,Q)?(re=T[Q],de=O[Q],typeof re=="object"&&typeof de=="object"&&re&&de?(ve=G(re))!==G(de)?V[H+Q]=O[Q]:ve==="Object"?sl(re,de,V,H+Q+"."):re!==de&&(V[H+Q]=O[Q]):re!==de&&(V[H+Q]=O[Q])):V[H+Q]=void 0}),i(O).forEach(function(Q){d(T,Q)||(V[H+Q]=O[Q])}),V}function il(T,O){return O.type==="delete"?O.keys:O.keys||O.values.map(T.extractKey)}var kd={stack:"dbcore",name:"HooksMiddleware",level:2,create:function(T){return r(r({},T),{table:function(O){var V=T.table(O),H=V.schema.primaryKey;return r(r({},V),{mutate:function(Q){var re=at.trans,de=re.table(O).hook,ve=de.deleting,Se=de.creating,Ce=de.updating;switch(Q.type){case"add":if(Se.fire===Xe)break;return re._promise("readwrite",function(){return Ie(Q)},!0);case"put":if(Se.fire===Xe&&Ce.fire===Xe)break;return re._promise("readwrite",function(){return Ie(Q)},!0);case"delete":if(ve.fire===Xe)break;return re._promise("readwrite",function(){return Ie(Q)},!0);case"deleteRange":if(ve.fire===Xe)break;return re._promise("readwrite",function(){return function ye(Ne,we,Ae){return V.query({trans:Ne,values:!1,query:{index:H,range:we},limit:Ae}).then(function(Me){var Ee=Me.result;return Ie({type:"delete",keys:Ee,trans:Ne}).then(function(Ve){return 0<Ve.numFailures?Promise.reject(Ve.failures[0]):Ee.length<Ae?{failures:[],numFailures:0,lastResult:void 0}:ye(Ne,r(r({},we),{lower:Ee[Ee.length-1],lowerOpen:!0}),Ae)})})}(Q.trans,Q.range,1e4)},!0)}return V.mutate(Q);function Ie(ye){var Ne,we,Ae,Me=at.trans,Ee=ye.keys||il(H,ye);if(!Ee)throw new Error("Keys missing");return(ye=ye.type==="add"||ye.type==="put"?r(r({},ye),{keys:Ee}):r({},ye)).type!=="delete"&&(ye.values=s([],ye.values)),ye.keys&&(ye.keys=s([],ye.keys)),Ne=V,Ae=Ee,((we=ye).type==="add"?Promise.resolve([]):Ne.getMany({trans:we.trans,keys:Ae,cache:"immutable"})).then(function(Ve){var Ge=Ee.map(function(We,qe){var ht,vt,ct,mt=Ve[qe],_t={onerror:null,onsuccess:null};return ye.type==="delete"?ve.fire.call(_t,We,mt,Me):ye.type==="add"||mt===void 0?(ht=Se.fire.call(_t,We,ye.values[qe],Me),We==null&&ht!=null&&(ye.keys[qe]=We=ht,H.outbound||k(ye.values[qe],H.keyPath,We))):(ht=sl(mt,ye.values[qe]),(vt=Ce.fire.call(_t,ht,We,mt,Me))&&(ct=ye.values[qe],Object.keys(vt).forEach(function(ut){d(ct,ut)?ct[ut]=vt[ut]:k(ct,ut,vt[ut])}))),_t});return V.mutate(ye).then(function(We){for(var qe=We.failures,ht=We.results,vt=We.numFailures,We=We.lastResult,ct=0;ct<Ee.length;++ct){var mt=(ht||Ee)[ct],_t=Ge[ct];mt==null?_t.onerror&&_t.onerror(qe[ct]):_t.onsuccess&&_t.onsuccess(ye.type==="put"&&Ve[ct]?ye.values[ct]:mt)}return{failures:qe,results:ht,numFailures:vt,lastResult:We}}).catch(function(We){return Ge.forEach(function(qe){return qe.onerror&&qe.onerror(We)}),Promise.reject(We)})})}}})}})}};function xc(T,O,V){try{if(!O||O.keys.length<T.length)return null;for(var H=[],Q=0,re=0;Q<O.keys.length&&re<T.length;++Q)Gt(O.keys[Q],T[re])===0&&(H.push(V?Z(O.values[Q]):O.values[Q]),++re);return H.length===T.length?H:null}catch{return null}}var Td={stack:"dbcore",level:-1,create:function(T){return{table:function(O){var V=T.table(O);return r(r({},V),{getMany:function(H){if(!H.cache)return V.getMany(H);var Q=xc(H.keys,H.trans._cache,H.cache==="clone");return Q?Ze.resolve(Q):V.getMany(H).then(function(re){return H.trans._cache={keys:H.keys,values:H.cache==="clone"?Z(re):re},re})},mutate:function(H){return H.type!=="add"&&(H.trans._cache=null),V.mutate(H)}})}}}};function Zi(T,O){return T.trans.mode==="readonly"&&!!T.subscr&&!T.trans.explicit&&T.trans.db._options.cache!=="disabled"&&!O.schema.primaryKey.outbound}function Ad(T,O){switch(T){case"query":return O.values&&!O.unique;case"get":case"getMany":case"count":case"openCursor":return!1}}var kp={stack:"dbcore",level:0,name:"Observability",create:function(T){var O=T.schema.name,V=new xr(T.MIN_KEY,T.MAX_KEY);return r(r({},T),{transaction:function(H,Q,re){if(at.subscr&&Q!=="readonly")throw new ce.ReadOnly("Readwrite transaction in liveQuery context. Querier source: ".concat(at.querier));return T.transaction(H,Q,re)},table:function(H){var Q=T.table(H),re=Q.schema,de=re.primaryKey,ye=re.indexes,ve=de.extractKey,Se=de.outbound,Ce=de.autoIncrement&&ye.filter(function(we){return we.compound&&we.keyPath.includes(de.keyPath)}),Ie=r(r({},Q),{mutate:function(we){function Ae(ut){return ut="idb://".concat(O,"/").concat(H,"/").concat(ut),We[ut]||(We[ut]=new xr)}var Me,Ee,Ve,Ge=we.trans,We=we.mutatedParts||(we.mutatedParts={}),qe=Ae(""),ht=Ae(":dels"),vt=we.type,_t=we.type==="deleteRange"?[we.range]:we.type==="delete"?[we.keys]:we.values.length<50?[il(de,we).filter(function(ut){return ut}),we.values]:[],ct=_t[0],mt=_t[1],_t=we.trans._cache;return o(ct)?(qe.addKeys(ct),(_t=vt==="delete"||ct.length===mt.length?xc(ct,_t):null)||ht.addKeys(ct),(_t||mt)&&(Me=Ae,Ee=_t,Ve=mt,re.indexes.forEach(function(ut){var Et=Me(ut.name||"");function Dt(Ht){return Ht!=null?ut.extractKey(Ht):null}function Pt(Ht){return ut.multiEntry&&o(Ht)?Ht.forEach(function(Rr){return Et.addKey(Rr)}):Et.addKey(Ht)}(Ee||Ve).forEach(function(Ht,Jn){var Ut=Ee&&Dt(Ee[Jn]),Jn=Ve&&Dt(Ve[Jn]);Gt(Ut,Jn)!==0&&(Ut!=null&&Pt(Ut),Jn!=null&&Pt(Jn))})}))):ct?(mt={from:(mt=ct.lower)!==null&&mt!==void 0?mt:T.MIN_KEY,to:(mt=ct.upper)!==null&&mt!==void 0?mt:T.MAX_KEY},ht.add(mt),qe.add(mt)):(qe.add(V),ht.add(V),re.indexes.forEach(function(ut){return Ae(ut.name).add(V)})),Q.mutate(we).then(function(ut){return!ct||we.type!=="add"&&we.type!=="put"||(qe.addKeys(ut.results),Ce&&Ce.forEach(function(Et){for(var Dt=we.values.map(function(Ut){return Et.extractKey(Ut)}),Pt=Et.keyPath.findIndex(function(Ut){return Ut===de.keyPath}),Ht=0,Rr=ut.results.length;Ht<Rr;++Ht)Dt[Ht][Pt]=ut.results[Ht];Ae(Et.name).addKeys(Dt)})),Ge.mutatedParts=nl(Ge.mutatedParts||{},We),ut})}}),ye=function(Ae){var Me=Ae.query,Ae=Me.index,Me=Me.range;return[Ae,new xr((Ae=Me.lower)!==null&&Ae!==void 0?Ae:T.MIN_KEY,(Me=Me.upper)!==null&&Me!==void 0?Me:T.MAX_KEY)]},Ne={get:function(we){return[de,new xr(we.key)]},getMany:function(we){return[de,new xr().addKeys(we.keys)]},count:ye,query:ye,openCursor:ye};return i(Ne).forEach(function(we){Ie[we]=function(Ae){var Me=at.subscr,Ee=!!Me,Ve=Zi(at,Q)&&Ad(we,Ae)?Ae.obsSet={}:Me;if(Ee){var Ge=function(mt){return mt="idb://".concat(O,"/").concat(H,"/").concat(mt),Ve[mt]||(Ve[mt]=new xr)},We=Ge(""),qe=Ge(":dels"),Me=Ne[we](Ae),Ee=Me[0],Me=Me[1];if((we==="query"&&Ee.isPrimaryKey&&!Ae.values?qe:Ge(Ee.name||"")).add(Me),!Ee.isPrimaryKey){if(we!=="count"){var ht=we==="query"&&Se&&Ae.values&&Q.query(r(r({},Ae),{values:!1}));return Q[we].apply(this,arguments).then(function(mt){if(we==="query"){if(Se&&Ae.values)return ht.then(function(Dt){return Dt=Dt.result,We.addKeys(Dt),mt});var _t=Ae.values?mt.result.map(ve):mt.result;(Ae.values?We:qe).addKeys(_t)}else if(we==="openCursor"){var ut=mt,Et=Ae.values;return ut&&Object.create(ut,{key:{get:function(){return qe.addKey(ut.primaryKey),ut.key}},primaryKey:{get:function(){var Dt=ut.primaryKey;return qe.addKey(Dt),Dt}},value:{get:function(){return Et&&We.addKey(ut.primaryKey),ut.value}}})}return mt})}qe.add(V)}}return Q[we].apply(this,arguments)}}),Ie}})}};function Id(T,O,V){if(V.numFailures===0)return O;if(O.type==="deleteRange")return null;var H=O.keys?O.keys.length:"values"in O&&O.values?O.values.length:1;return V.numFailures===H?null:(O=r({},O),o(O.keys)&&(O.keys=O.keys.filter(function(Q,re){return!(re in V.failures)})),"values"in O&&o(O.values)&&(O.values=O.values.filter(function(Q,re){return!(re in V.failures)})),O)}function ol(T,O){return V=T,((H=O).lower===void 0||(H.lowerOpen?0<Gt(V,H.lower):0<=Gt(V,H.lower)))&&(T=T,(O=O).upper===void 0||(O.upperOpen?Gt(T,O.upper)<0:Gt(T,O.upper)<=0));var V,H}function Cc(T,O,Ne,H,Q,re){if(!Ne||Ne.length===0)return T;var de=O.query.index,ve=de.multiEntry,Se=O.query.range,Ce=H.schema.primaryKey.extractKey,Ie=de.extractKey,ye=(de.lowLevelIndex||de).extractKey,Ne=Ne.reduce(function(we,Ae){var Me=we,Ee=[];if(Ae.type==="add"||Ae.type==="put")for(var Ve=new xr,Ge=Ae.values.length-1;0<=Ge;--Ge){var We,qe=Ae.values[Ge],ht=Ce(qe);Ve.hasKey(ht)||(We=Ie(qe),(ve&&o(We)?We.some(function(ut){return ol(ut,Se)}):ol(We,Se))&&(Ve.addKey(ht),Ee.push(qe)))}switch(Ae.type){case"add":var vt=new xr().addKeys(O.values?we.map(function(Et){return Ce(Et)}):we),Me=we.concat(O.values?Ee.filter(function(Et){return Et=Ce(Et),!vt.hasKey(Et)&&(vt.addKey(Et),!0)}):Ee.map(function(Et){return Ce(Et)}).filter(function(Et){return!vt.hasKey(Et)&&(vt.addKey(Et),!0)}));break;case"put":var ct=new xr().addKeys(Ae.values.map(function(Et){return Ce(Et)}));Me=we.filter(function(Et){return!ct.hasKey(O.values?Ce(Et):Et)}).concat(O.values?Ee:Ee.map(function(Et){return Ce(Et)}));break;case"delete":var mt=new xr().addKeys(Ae.keys);Me=we.filter(function(Et){return!mt.hasKey(O.values?Ce(Et):Et)});break;case"deleteRange":var _t=Ae.range;Me=we.filter(function(Et){return!ol(Ce(Et),_t)})}return Me},T);return Ne===T?T:(Ne.sort(function(we,Ae){return Gt(ye(we),ye(Ae))||Gt(Ce(we),Ce(Ae))}),O.limit&&O.limit<1/0&&(Ne.length>O.limit?Ne.length=O.limit:T.length===O.limit&&Ne.length<O.limit&&(Q.dirty=!0)),re?Object.freeze(Ne):Ne)}function Oo(T,O){return Gt(T.lower,O.lower)===0&&Gt(T.upper,O.upper)===0&&!!T.lowerOpen==!!O.lowerOpen&&!!T.upperOpen==!!O.upperOpen}function Sa(T,O){return function(V,H,Q,re){if(V===void 0)return H!==void 0?-1:0;if(H===void 0)return 1;if((H=Gt(V,H))===0){if(Q&&re)return 0;if(Q)return 1;if(re)return-1}return H}(T.lower,O.lower,T.lowerOpen,O.lowerOpen)<=0&&0<=function(V,H,Q,re){if(V===void 0)return H!==void 0?1:0;if(H===void 0)return-1;if((H=Gt(V,H))===0){if(Q&&re)return 0;if(Q)return-1;if(re)return 1}return H}(T.upper,O.upper,T.upperOpen,O.upperOpen)}function Tp(T,O,V,H){T.subscribers.add(V),H.addEventListener("abort",function(){var Q,re;T.subscribers.delete(V),T.subscribers.size===0&&(Q=T,re=O,setTimeout(function(){Q.subscribers.size===0&&U(re,Q)},3e3))})}var al={stack:"dbcore",level:0,name:"Cache",create:function(T){var O=T.schema.name;return r(r({},T),{transaction:function(V,H,Q){var re,de,ve=T.transaction(V,H,Q);return H==="readwrite"&&(de=(re=new AbortController).signal,Q=function(Se){return function(){if(re.abort(),H==="readwrite"){for(var Ce=new Set,Ie=0,ye=V;Ie<ye.length;Ie++){var Ne=ye[Ie],we=Wi["idb://".concat(O,"/").concat(Ne)];if(we){var Ae=T.table(Ne),Me=we.optimisticOps.filter(function(Et){return Et.trans===ve});if(ve._explicit&&Se&&ve.mutatedParts)for(var Ee=0,Ve=Object.values(we.queries.query);Ee<Ve.length;Ee++)for(var Ge=0,We=(vt=Ve[Ee]).slice();Ge<We.length;Ge++)yc((ct=We[Ge]).obsSet,ve.mutatedParts)&&(U(vt,ct),ct.subscribers.forEach(function(Et){return Ce.add(Et)}));else if(0<Me.length){we.optimisticOps=we.optimisticOps.filter(function(Et){return Et.trans!==ve});for(var qe=0,ht=Object.values(we.queries.query);qe<ht.length;qe++)for(var vt,ct,mt,_t=0,ut=(vt=ht[qe]).slice();_t<ut.length;_t++)(ct=ut[_t]).res!=null&&ve.mutatedParts&&(Se&&!ct.dirty?(mt=Object.isFrozen(ct.res),mt=Cc(ct.res,ct.req,Me,Ae,ct,mt),ct.dirty?(U(vt,ct),ct.subscribers.forEach(function(Et){return Ce.add(Et)})):mt!==ct.res&&(ct.res=mt,ct.promise=Ze.resolve({result:mt}))):(ct.dirty&&U(vt,ct),ct.subscribers.forEach(function(Et){return Ce.add(Et)})))}}}Ce.forEach(function(Et){return Et()})}}},ve.addEventListener("abort",Q(!1),{signal:de}),ve.addEventListener("error",Q(!1),{signal:de}),ve.addEventListener("complete",Q(!0),{signal:de})),ve},table:function(V){var H=T.table(V),Q=H.schema.primaryKey;return r(r({},H),{mutate:function(re){var de=at.trans;if(Q.outbound||de.db._options.cache==="disabled"||de.explicit||de.idbtrans.mode!=="readwrite")return H.mutate(re);var ve=Wi["idb://".concat(O,"/").concat(V)];return ve?(de=H.mutate(re),re.type!=="add"&&re.type!=="put"||!(50<=re.values.length||il(Q,re).some(function(Se){return Se==null}))?(ve.optimisticOps.push(re),re.mutatedParts&&rl(re.mutatedParts),de.then(function(Se){0<Se.numFailures&&(U(ve.optimisticOps,re),(Se=Id(0,re,Se))&&ve.optimisticOps.push(Se),re.mutatedParts&&rl(re.mutatedParts))}),de.catch(function(){U(ve.optimisticOps,re),re.mutatedParts&&rl(re.mutatedParts)})):de.then(function(Se){var Ce=Id(0,r(r({},re),{values:re.values.map(function(Ie,ye){var Ne;return Se.failures[ye]?Ie:(Ie=(Ne=Q.keyPath)!==null&&Ne!==void 0&&Ne.includes(".")?Z(Ie):r({},Ie),k(Ie,Q.keyPath,Se.results[ye]),Ie)})}),Se);ve.optimisticOps.push(Ce),queueMicrotask(function(){return re.mutatedParts&&rl(re.mutatedParts)})}),de):H.mutate(re)},query:function(re){if(!Zi(at,H)||!Ad("query",re))return H.query(re);var de=((Ce=at.trans)===null||Ce===void 0?void 0:Ce.db._options.cache)==="immutable",ye=at,ve=ye.requery,Se=ye.signal,Ce=function(Ae,Me,Ee,Ve){var Ge=Wi["idb://".concat(Ae,"/").concat(Me)];if(!Ge)return[];if(!(Me=Ge.queries[Ee]))return[null,!1,Ge,null];var We=Me[(Ve.query?Ve.query.index.name:null)||""];if(!We)return[null,!1,Ge,null];switch(Ee){case"query":var qe=We.find(function(ht){return ht.req.limit===Ve.limit&&ht.req.values===Ve.values&&Oo(ht.req.query.range,Ve.query.range)});return qe?[qe,!0,Ge,We]:[We.find(function(ht){return("limit"in ht.req?ht.req.limit:1/0)>=Ve.limit&&(!Ve.values||ht.req.values)&&Sa(ht.req.query.range,Ve.query.range)}),!1,Ge,We];case"count":return qe=We.find(function(ht){return Oo(ht.req.query.range,Ve.query.range)}),[qe,!!qe,Ge,We]}}(O,V,"query",re),Ie=Ce[0],ye=Ce[1],Ne=Ce[2],we=Ce[3];return Ie&&ye?Ie.obsSet=re.obsSet:(ye=H.query(re).then(function(Ae){var Me=Ae.result;if(Ie&&(Ie.res=Me),de){for(var Ee=0,Ve=Me.length;Ee<Ve;++Ee)Object.freeze(Me[Ee]);Object.freeze(Me)}else Ae.result=Z(Me);return Ae}).catch(function(Ae){return we&&Ie&&U(we,Ie),Promise.reject(Ae)}),Ie={obsSet:re.obsSet,promise:ye,subscribers:new Set,type:"query",req:re,dirty:!1},we?we.push(Ie):(we=[Ie],(Ne=Ne||(Wi["idb://".concat(O,"/").concat(V)]={queries:{query:{},count:{}},objs:new Map,optimisticOps:[],unsignaledParts:{}})).queries.query[re.query.index.name||""]=we)),Tp(Ie,we,ve,Se),Ie.promise.then(function(Ae){return{result:Cc(Ae.result,re,Ne==null?void 0:Ne.optimisticOps,H,Ie,de)}})}})}})}};function xa(T,O){return new Proxy(T,{get:function(V,H,Q){return H==="db"?O:Reflect.get(V,H,Q)}})}var Ls=(Nn.prototype.version=function(T){if(isNaN(T)||T<.1)throw new ce.Type("Given version is not a positive number");if(T=Math.round(10*T)/10,this.idbdb||this._state.isBeingOpened)throw new ce.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,T);var O=this._versions,V=O.filter(function(H){return H._cfg.version===T})[0];return V||(V=new this.Version(T),O.push(V),O.sort(ba),V.stores({}),this._state.autoSchema=!1,V)},Nn.prototype._whenReady=function(T){var O=this;return this.idbdb&&(this._state.openComplete||at.letThrough||this._vip)?T():new Ze(function(V,H){if(O._state.openComplete)return H(new ce.DatabaseClosed(O._state.dbOpenError));if(!O._state.isBeingOpened){if(!O._state.autoOpen)return void H(new ce.DatabaseClosed);O.open().catch(Xe)}O._state.dbReadyPromise.then(V,H)}).then(T)},Nn.prototype.use=function(T){var O=T.stack,V=T.create,H=T.level,Q=T.name;return Q&&this.unuse({stack:O,name:Q}),T=this._middlewares[O]||(this._middlewares[O]=[]),T.push({stack:O,create:V,level:H??10,name:Q}),T.sort(function(re,de){return re.level-de.level}),this},Nn.prototype.unuse=function(T){var O=T.stack,V=T.name,H=T.create;return O&&this._middlewares[O]&&(this._middlewares[O]=this._middlewares[O].filter(function(Q){return H?Q.create!==H:!!V&&Q.name!==V})),this},Nn.prototype.open=function(){var T=this;return vr(Jt,function(){return Ep(T)})},Nn.prototype._close=function(){var T=this._state,O=dr.indexOf(this);if(0<=O&&dr.splice(O,1),this.idbdb){try{this.idbdb.close()}catch{}this.idbdb=null}T.isBeingOpened||(T.dbReadyPromise=new Ze(function(V){T.dbReadyResolve=V}),T.openCanceller=new Ze(function(V,H){T.cancelOpen=H}))},Nn.prototype.close=function(V){var O=(V===void 0?{disableAutoOpen:!0}:V).disableAutoOpen,V=this._state;O?(V.isBeingOpened&&V.cancelOpen(new ce.DatabaseClosed),this._close(),V.autoOpen=!1,V.dbOpenError=new ce.DatabaseClosed):(this._close(),V.autoOpen=this._options.autoOpen||V.isBeingOpened,V.openComplete=!1,V.dbOpenError=null)},Nn.prototype.delete=function(T){var O=this;T===void 0&&(T={disableAutoOpen:!0});var V=0<arguments.length&&typeof arguments[0]!="object",H=this._state;return new Ze(function(Q,re){function de(){O.close(T);var ve=O._deps.indexedDB.deleteDatabase(O.name);ve.onsuccess=It(function(){var Se,Ce,Ie;Se=O._deps,Ce=O.name,Ie=Se.indexedDB,Se=Se.IDBKeyRange,el(Ie)||Ce===Or||mc(Ie,Se).delete(Ce).catch(Xe),Q()}),ve.onerror=Xr(re),ve.onblocked=O._fireOnBlocked}if(V)throw new ce.InvalidArgument("Invalid closeOptions argument to db.delete()");H.isBeingOpened?H.dbReadyPromise.then(de):de()})},Nn.prototype.backendDB=function(){return this.idbdb},Nn.prototype.isOpen=function(){return this.idbdb!==null},Nn.prototype.hasBeenClosed=function(){var T=this._state.dbOpenError;return T&&T.name==="DatabaseClosed"},Nn.prototype.hasFailed=function(){return this._state.dbOpenError!==null},Nn.prototype.dynamicallyOpened=function(){return this._state.autoSchema},Object.defineProperty(Nn.prototype,"tables",{get:function(){var T=this;return i(this._allTables).map(function(O){return T._allTables[O]})},enumerable:!1,configurable:!0}),Nn.prototype.transaction=function(){var T=(function(O,V,H){var Q=arguments.length;if(Q<2)throw new ce.InvalidArgument("Too few arguments");for(var re=new Array(Q-1);--Q;)re[Q-1]=arguments[Q];return H=re.pop(),[O,D(re),H]}).apply(this,arguments);return this._transaction.apply(this,T)},Nn.prototype._transaction=function(T,O,V){var H=this,Q=at.trans;Q&&Q.db===this&&T.indexOf("!")===-1||(Q=null);var re,de,ve=T.indexOf("?")!==-1;T=T.replace("!","").replace("?","");try{if(de=O.map(function(Ce){if(Ce=Ce instanceof H.Table?Ce.name:Ce,typeof Ce!="string")throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return Ce}),T=="r"||T===Yn)re=Yn;else{if(T!="rw"&&T!=Yr)throw new ce.InvalidArgument("Invalid transaction mode: "+T);re=Yr}if(Q){if(Q.mode===Yn&&re===Yr){if(!ve)throw new ce.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");Q=null}Q&&de.forEach(function(Ce){if(Q&&Q.storeNames.indexOf(Ce)===-1){if(!ve)throw new ce.SubTransaction("Table "+Ce+" not included in parent transaction.");Q=null}}),ve&&Q&&!Q.active&&(Q=null)}}catch(Ce){return Q?Q._promise(null,function(Ie,ye){ye(Ce)}):mn(Ce)}var Se=(function Ce(Ie,ye,Ne,we,Ae){return Ze.resolve().then(function(){var Me=at.transless||at,Ee=Ie._createTransaction(ye,Ne,Ie._dbSchema,we);if(Ee.explicit=!0,Me={trans:Ee,transless:Me},we)Ee.idbtrans=we.idbtrans;else try{Ee.create(),Ee.idbtrans._explicit=!0,Ie._state.PR1398_maxLoop=3}catch(We){return We.name===W.InvalidState&&Ie.isOpen()&&0<--Ie._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),Ie.close({disableAutoOpen:!1}),Ie.open().then(function(){return Ce(Ie,ye,Ne,null,Ae)})):mn(We)}var Ve,Ge=Y(Ae);return Ge&&Kn(),Me=Ze.follow(function(){var We;(Ve=Ae.call(Ee,Ee))&&(Ge?(We=Bn.bind(null,null),Ve.then(We,We)):typeof Ve.next=="function"&&typeof Ve.throw=="function"&&(Ve=wa(Ve)))},Me),(Ve&&typeof Ve.then=="function"?Ze.resolve(Ve).then(function(We){return Ee.active?We:mn(new ce.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))}):Me.then(function(){return Ve})).then(function(We){return we&&Ee._resolve(),Ee._completion.then(function(){return We})}).catch(function(We){return Ee._reject(We),mn(We)})})}).bind(null,this,re,de,Q,V);return Q?Q._promise(re,Se,"lock"):at.trans?vr(at.transless,function(){return H._whenReady(Se)}):this._whenReady(Se)},Nn.prototype.table=function(T){if(!d(this._allTables,T))throw new ce.InvalidTable("Table ".concat(T," does not exist"));return this._allTables[T]},Nn);function Nn(T,O){var V=this;this._middlewares={},this.verno=0;var H=Nn.dependencies;this._options=O=r({addons:Nn.addons,autoOpen:!0,indexedDB:H.indexedDB,IDBKeyRange:H.IDBKeyRange,cache:"cloned"},O),this._deps={indexedDB:O.indexedDB,IDBKeyRange:O.IDBKeyRange},H=O.addons,this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;var Q,re,de,ve,Se,Ce={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:Xe,dbReadyPromise:null,cancelOpen:Xe,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3,autoOpen:O.autoOpen};Ce.dbReadyPromise=new Ze(function(ye){Ce.dbReadyResolve=ye}),Ce.openCanceller=new Ze(function(ye,Ne){Ce.cancelOpen=Ne}),this._state=Ce,this.name=T,this.on=pe(this,"populate","blocked","versionchange","close",{ready:[Le,Xe]}),this.on.ready.subscribe=S(this.on.ready.subscribe,function(ye){return function(Ne,we){Nn.vip(function(){var Ae,Me=V._state;Me.openComplete?(Me.dbOpenError||Ze.resolve().then(Ne),we&&ye(Ne)):Me.onReadyBeingFired?(Me.onReadyBeingFired.push(Ne),we&&ye(Ne)):(ye(Ne),Ae=V,we||ye(function Ee(){Ae.on.ready.unsubscribe(Ne),Ae.on.ready.unsubscribe(Ee)}))})}}),this.Collection=(Q=this,P(qn.prototype,function(Ve,Ee){this.db=Q;var we=wr,Ae=null;if(Ee)try{we=Ee()}catch(Ge){Ae=Ge}var Me=Ve._ctx,Ee=Me.table,Ve=Ee.hook.reading.fire;this._ctx={table:Ee,index:Me.index,isPrimKey:!Me.index||Ee.schema.primKey.keyPath&&Me.index===Ee.schema.primKey.name,range:we,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:Ae,or:Me.or,valueMapper:Ve!==nt?Ve:null}})),this.Table=(re=this,P(Xs.prototype,function(ye,Ne,we){this.db=re,this._tx=we,this.name=ye,this.schema=Ne,this.hook=re._allTables[ye]?re._allTables[ye].hook:pe(null,{creating:[He,Xe],reading:[xt,nt],updating:[fe,Xe],deleting:[he,Xe]})})),this.Transaction=(de=this,P(ga.prototype,function(ye,Ne,we,Ae,Me){var Ee=this;this.db=de,this.mode=ye,this.storeNames=Ne,this.schema=we,this.chromeTransactionDurability=Ae,this.idbtrans=null,this.on=pe(this,"complete","error","abort"),this.parent=Me||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new Ze(function(Ve,Ge){Ee._resolve=Ve,Ee._reject=Ge}),this._completion.then(function(){Ee.active=!1,Ee.on.complete.fire()},function(Ve){var Ge=Ee.active;return Ee.active=!1,Ee.on.error.fire(Ve),Ee.parent?Ee.parent._reject(Ve):Ge&&Ee.idbtrans&&Ee.idbtrans.abort(),mn(Ve)})})),this.Version=(ve=this,P(ni.prototype,function(ye){this.db=ve,this._cfg={version:ye,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})),this.WhereClause=(Se=this,P(Js.prototype,function(ye,Ne,we){if(this.db=Se,this._ctx={table:ye,index:Ne===":id"?null:Ne,or:we},this._cmp=this._ascending=Gt,this._descending=function(Ae,Me){return Gt(Me,Ae)},this._max=function(Ae,Me){return 0<Gt(Ae,Me)?Ae:Me},this._min=function(Ae,Me){return Gt(Ae,Me)<0?Ae:Me},this._IDBKeyRange=Se._deps.IDBKeyRange,!this._IDBKeyRange)throw new ce.MissingAPI})),this.on("versionchange",function(ye){0<ye.newVersion?console.warn("Another connection wants to upgrade database '".concat(V.name,"'. Closing db now to resume the upgrade.")):console.warn("Another connection wants to delete database '".concat(V.name,"'. Closing db now to resume the delete request.")),V.close({disableAutoOpen:!1})}),this.on("blocked",function(ye){!ye.newVersion||ye.newVersion<ye.oldVersion?console.warn("Dexie.delete('".concat(V.name,"') was blocked")):console.warn("Upgrade '".concat(V.name,"' blocked by other connection holding version ").concat(ye.oldVersion/10))}),this._maxKey=bi(O.IDBKeyRange),this._createTransaction=function(ye,Ne,we,Ae){return new V.Transaction(ye,Ne,we,V._options.chromeTransactionDurability,Ae)},this._fireOnBlocked=function(ye){V.on("blocked").fire(ye),dr.filter(function(Ne){return Ne.name===V.name&&Ne!==V&&!Ne._state.vcFired}).map(function(Ne){return Ne.on("versionchange").fire(ye)})},this.use(Td),this.use(al),this.use(kp),this.use(jp),this.use(kd);var Ie=new Proxy(this,{get:function(ye,Ne,we){if(Ne==="_vip")return!0;if(Ne==="table")return function(Me){return xa(V.table(Me),Ie)};var Ae=Reflect.get(ye,Ne,we);return Ae instanceof Xs?xa(Ae,Ie):Ne==="tables"?Ae.map(function(Me){return xa(Me,Ie)}):Ne==="_createTransaction"?function(){return xa(Ae.apply(this,arguments),Ie)}:Ae}});this.vip=Ie,H.forEach(function(ye){return ye(V)})}var Ro,Jr=typeof Symbol<"u"&&"observable"in Symbol?Symbol.observable:"@@observable",Od=(ll.prototype.subscribe=function(T,O,V){return this._subscribe(T&&typeof T!="function"?T:{next:T,error:O,complete:V})},ll.prototype[Jr]=function(){return this},ll);function ll(T){this._subscribe=T}try{Ro={indexedDB:c.indexedDB||c.mozIndexedDB||c.webkitIndexedDB||c.msIndexedDB,IDBKeyRange:c.IDBKeyRange||c.webkitIDBKeyRange}}catch{Ro={indexedDB:null,IDBKeyRange:null}}function Rd(T){var O,V=!1,H=new Od(function(Q){var re=Y(T),de,ve=!1,Se={},Ce={},Ie={get closed(){return ve},unsubscribe:function(){ve||(ve=!0,de&&de.abort(),ye&&ir.storagemutated.unsubscribe(we))}};Q.start&&Q.start(Ie);var ye=!1,Ne=function(){return br(Ae)},we=function(Me){nl(Se,Me),yc(Ce,Se)&&Ne()},Ae=function(){var Me,Ee,Ve;!ve&&Ro.indexedDB&&(Se={},Me={},de&&de.abort(),de=new AbortController,Ve=function(Ge){var We=Mt();try{re&&Kn();var qe=rr(T,Ge);return qe=re?qe.finally(Bn):qe}finally{We&&Wt()}}(Ee={subscr:Me,signal:de.signal,requery:Ne,querier:T,trans:null}),Promise.resolve(Ve).then(function(Ge){V=!0,O=Ge,ve||Ee.signal.aborted||(Se={},function(We){for(var qe in We)if(d(We,qe))return;return 1}(Ce=Me)||ye||(ir(vi,we),ye=!0),br(function(){return!ve&&Q.next&&Q.next(Ge)}))},function(Ge){V=!1,["DatabaseClosedError","AbortError"].includes(Ge==null?void 0:Ge.name)||ve||br(function(){ve||Q.error&&Q.error(Ge)})}))};return setTimeout(Ne,0),Ie});return H.hasValue=function(){return V},H.getValue=function(){return O},H}var Ki=Ls;function Ec(T){var O=wi;try{wi=!0,ir.storagemutated.fire(T),Sc(T,!0)}finally{wi=O}}h(Ki,r(r({},Te),{delete:function(T){return new Ki(T,{addons:[]}).delete()},exists:function(T){return new Ki(T,{addons:[]}).open().then(function(O){return O.close(),!0}).catch("NoSuchDatabaseError",function(){return!1})},getDatabaseNames:function(T){try{return O=Ki.dependencies,V=O.indexedDB,O=O.IDBKeyRange,(el(V)?Promise.resolve(V.databases()).then(function(H){return H.map(function(Q){return Q.name}).filter(function(Q){return Q!==Or})}):mc(V,O).toCollection().primaryKeys()).then(T)}catch{return mn(new ce.MissingAPI)}var O,V},defineClass:function(){return function(T){u(this,T)}},ignoreTransaction:function(T){return at.trans?vr(at.transless,T):T()},vip:vc,async:function(T){return function(){try{var O=wa(T.apply(this,arguments));return O&&typeof O.then=="function"?O:Ze.resolve(O)}catch(V){return mn(V)}}},spawn:function(T,O,V){try{var H=wa(T.apply(V,O||[]));return H&&typeof H.then=="function"?H:Ze.resolve(H)}catch(Q){return mn(Q)}},currentTransaction:{get:function(){return at.trans||null}},waitFor:function(T,O){return O=Ze.resolve(typeof T=="function"?Ki.ignoreTransaction(T):T).timeout(O||6e4),at.trans?at.trans.waitFor(O):O},Promise:Ze,debug:{get:function(){return Be},set:function(T){Ye(T)}},derive:m,extend:u,props:h,override:S,Events:pe,on:ir,liveQuery:Rd,extendObservabilitySet:nl,getByKeyPath:j,setByKeyPath:k,delByKeyPath:function(T,O){typeof O=="string"?k(T,O,void 0):"length"in O&&[].map.call(O,function(V){k(T,V,void 0)})},shallowClone:A,deepClone:Z,getObjectDiff:sl,cmp:Gt,asap:x,minKey:-1/0,addons:[],connections:dr,errnames:W,dependencies:Ro,cache:Wi,semVer:"4.0.11",version:"4.0.11".split(".").map(function(T){return parseInt(T)}).reduce(function(T,O,V){return T+O/Math.pow(10,2*V)})})),Ki.maxKey=bi(Ki.dependencies.IDBKeyRange),typeof dispatchEvent<"u"&&typeof addEventListener<"u"&&(ir(vi,function(T){wi||(T=new CustomEvent(ei,{detail:T}),wi=!0,dispatchEvent(T),wi=!1)}),addEventListener(ei,function(T){T=T.detail,wi||Ec(T)}));var No,wi=!1,Fr=function(){};return typeof BroadcastChannel<"u"&&((Fr=function(){(No=new BroadcastChannel(ei)).onmessage=function(T){return T.data&&Ec(T.data)}})(),typeof No.unref=="function"&&No.unref(),ir(vi,function(T){wi||No.postMessage(T)})),typeof addEventListener<"u"&&(addEventListener("pagehide",function(T){if(!Ls.disableBfCache&&T.persisted){Be&&console.debug("Dexie: handling persisted pagehide"),No!=null&&No.close();for(var O=0,V=dr;O<V.length;O++)V[O].close({disableAutoOpen:!1})}}),addEventListener("pageshow",function(T){!Ls.disableBfCache&&T.persisted&&(Be&&console.debug("Dexie: handling persisted pageshow"),Fr(),Ec({all:new xr(-1/0,[[]])}))})),Ze.rejectionMapper=function(T,O){return!T||T instanceof F||T instanceof TypeError||T instanceof SyntaxError||!T.name||!Ke[T.name]?T:(O=new Ke[T.name](O||T.message,T),"stack"in T&&v(O,"stack",{get:function(){return this.inner.stack}}),O)},Ye(Be),r(Ls,Object.freeze({__proto__:null,Dexie:Ls,liveQuery:Rd,Entity:Os,cmp:Gt,PropModification:Rt,replacePrefix:function(T,O){return new Rt({replacePrefix:[T,O]})},add:function(T){return new Rt({add:T})},remove:function(T){return new Rt({remove:T})},default:Ls,RangeSet:xr,mergeRanges:Gi,rangesOverlap:Cd}),{default:Ls}),Ls})}(oh)),oh.exports}var kB=jB();const Xg=oc(kB),Q2=Symbol.for("Dexie"),Rh=globalThis[Q2]||(globalThis[Q2]=Xg);if(Xg.semVer!==Rh.semVer)throw new Error(`Two different versions of Dexie loaded in the same app: ${Xg.semVer} and ${Rh.semVer}`);const{liveQuery:OG,mergeRanges:RG,rangesOverlap:NG,RangeSet:LG,cmp:DG,Entity:MG,PropModification:PG,replacePrefix:BG,add:$G,remove:UG}=Rh;function Li(t){return typeof t=="function"}function ik(t){var e=function(r){Error.call(r),r.stack=new Error().stack},n=t(e);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var eg=ik(function(t){return function(n){t(this),this.message=n?n.length+` errors occurred during unsubscription:
6658
6658
  `+n.map(function(r,s){return s+1+") "+r.toString()}).join(`
6659
- `):"",this.name="UnsubscriptionError",this.errors=n}});function Nh(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var _d=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,r,s,c;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var o=kg(i),u=o.next();!u.done;u=o.next()){var l=u.value;l.remove(this)}}catch(m){e={error:m}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(Li(a))try{a()}catch(m){c=m instanceof eg?m.errors:[m]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var h=kg(d),p=h.next();!p.done;p=h.next()){var v=p.value;try{ex(v)}catch(m){c=c??[],m instanceof eg?c=Fu(Fu([],uh(c)),uh(m.errors)):c.push(m)}}}catch(m){r={error:m}}finally{try{p&&!p.done&&(s=h.return)&&s.call(h)}finally{if(r)throw r.error}}}if(c)throw new eg(c)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)ex(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&Nh(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&Nh(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}(),ok=_d.EMPTY;function ak(t){return t instanceof _d||t&&"closed"in t&&Li(t.remove)&&Li(t.add)&&Li(t.unsubscribe)}function ex(t){Li(t)?t():t.unsubscribe()}var TB={Promise:void 0},AB={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Fu([t,e],uh(n)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function IB(t){AB.setTimeout(function(){throw t})}function tx(){}function ah(t){t()}var B0=function(t){ha(e,t);function e(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,ak(n)&&n.add(r)):r.destination=NB,r}return e.create=function(n,r,s){return new qg(n,r,s)},e.prototype.next=function(n){this.isStopped||this._next(n)},e.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(n){this.destination.next(n)},e.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(_d),OB=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var n=this.partialObserver;if(n.next)try{n.next(e)}catch(r){Hf(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){Hf(r)}else Hf(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){Hf(n)}},t}(),qg=function(t){ha(e,t);function e(n,r,s){var c=t.call(this)||this,i;return Li(n)||!n?i={next:n??void 0,error:r??void 0,complete:s??void 0}:i=n,c.destination=new OB(i),c}return e}(B0);function Hf(t){IB(t)}function RB(t){throw t}var NB={closed:!0,next:tx,error:RB,complete:tx},LB=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function DB(t){return t}function MB(t){return t.length===0?DB:t.length===1?t[0]:function(n){return t.reduce(function(r,s){return s(r)},n)}}var nx=function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(e,n,r){var s=this,c=BB(e)?e:new qg(e,n,r);return ah(function(){var i=s,o=i.operator,u=i.source;c.add(o?o.call(c,u):u?s._subscribe(c):s._trySubscribe(c))}),c},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},t.prototype.forEach=function(e,n){var r=this;return n=rx(n),new n(function(s,c){var i=new qg({next:function(o){try{e(o)}catch(u){c(u),i.unsubscribe()}},error:c,complete:s});r.subscribe(i)})},t.prototype._subscribe=function(e){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(e)},t.prototype[LB]=function(){return this},t.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return MB(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=rx(e),new e(function(r,s){var c;n.subscribe(function(i){return c=i},function(i){return s(i)},function(){return r(c)})})},t.create=function(e){return new t(e)},t}();function rx(t){var e;return(e=t??TB.Promise)!==null&&e!==void 0?e:Promise}function PB(t){return t&&Li(t.next)&&Li(t.error)&&Li(t.complete)}function BB(t){return t&&t instanceof B0||PB(t)&&ak(t)}function $B(t){return Li(t==null?void 0:t.lift)}function UB(t){return function(e){if($B(e))return e.lift(function(n){try{return t(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function VB(t,e,n,r,s){return new FB(t,e,n,r,s)}var FB=function(t){ha(e,t);function e(n,r,s,c,i,o){var u=t.call(this,n)||this;return u.onFinalize=i,u.shouldUnsubscribe=o,u._next=r?function(l){try{r(l)}catch(a){n.error(a)}}:t.prototype._next,u._error=c?function(l){try{c(l)}catch(a){n.error(a)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=s?function(){try{s()}catch(l){n.error(l)}finally{this.unsubscribe()}}:t.prototype._complete,u}return e.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},e}(B0),zB=ik(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),lk=function(t){ha(e,t);function e(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return e.prototype.lift=function(n){var r=new sx(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new zB},e.prototype.next=function(n){var r=this;ah(function(){var s,c;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var i=kg(r.currentObservers),o=i.next();!o.done;o=i.next()){var u=o.value;u.next(n)}}catch(l){s={error:l}}finally{try{o&&!o.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}}})},e.prototype.error=function(n){var r=this;ah(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},e.prototype.complete=function(){var n=this;ah(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},e.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},e.prototype._innerSubscribe=function(n){var r=this,s=this,c=s.hasError,i=s.isStopped,o=s.observers;return c||i?ok:(this.currentObservers=null,o.push(n),new _d(function(){r.currentObservers=null,Nh(o,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,c=r.thrownError,i=r.isStopped;s?n.error(c):i&&n.complete()},e.prototype.asObservable=function(){var n=new nx;return n.source=this,n},e.create=function(n,r){return new sx(n,r)},e}(nx),sx=function(t){ha(e,t);function e(n,r){var s=t.call(this)||this;return s.destination=n,s.source=r,s}return e.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},e.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},e.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},e.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:ok},e}(lk),HB={now:function(){return Date.now()}},GB=function(t){ha(e,t);function e(n,r){return t.call(this)||this}return e.prototype.schedule=function(n,r){return this},e}(_d),ix={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Fu([t,e],uh(n)))},clearInterval:function(t){return clearInterval(t)},delegate:void 0},WB=function(t){ha(e,t);function e(n,r){var s=t.call(this,n,r)||this;return s.scheduler=n,s.work=r,s.pending=!1,s}return e.prototype.schedule=function(n,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var c=this.id,i=this.scheduler;return c!=null&&(this.id=this.recycleAsyncId(i,c,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(i,this.id,r),this},e.prototype.requestAsyncId=function(n,r,s){return s===void 0&&(s=0),ix.setInterval(n.flush.bind(n,this),s)},e.prototype.recycleAsyncId=function(n,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&ix.clearInterval(r)},e.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(n,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(n,r){var s=!1,c;try{this.work(n)}catch(i){s=!0,c=i||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),c},e.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,s=n.scheduler,c=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Nh(c,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(GB),ox=function(){function t(e,n){n===void 0&&(n=t.now),this.schedulerActionCtor=e,this.now=n}return t.prototype.schedule=function(e,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,e).schedule(r,n)},t.now=HB.now,t}(),ZB=function(t){ha(e,t);function e(n,r){r===void 0&&(r=ox.now);var s=t.call(this,n,r)||this;return s.actions=[],s._active=!1,s}return e.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var s;this._active=!0;do if(s=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,s){for(;n=r.shift();)n.unsubscribe();throw s}},e}(ox),KB=new ZB(WB);function YB(t,e){return e===void 0&&(e=KB),UB(function(n,r){var s=null,c=null,i=null,o=function(){if(s){s.unsubscribe(),s=null;var l=c;c=null,r.next(l)}};function u(){var l=i+t,a=e.now();if(a<l){s=this.schedule(void 0,l-a),r.add(s);return}o()}n.subscribe(VB(r,function(l){c=l,i=e.now(),s||(s=e.schedule(u,t),r.add(s))},function(){o(),r.complete()},void 0,function(){c=s=null}))})}class XB extends Rh{constructor(n,r,s){super(n);cu(this,"sessions");cu(this,"principal");cu(this,"client");cu(this,"saveSubject",new lk);this.principal=r,this.client=s,this.version(1).stores({sessions:"id, principal, name, created, updated"}),this.saveSubject.pipe(YB(200)).subscribe(async({id:c,notebook:i})=>{const o={id:c,principal:this.principal,name:ck(),created:Date.now(),updated:Date.now(),data:i};console.log(new Date().toISOString(),"saving Notebook",c,i),await this.sessions.put(o)})}async saveNotebook(n,r){this.saveSubject.next({id:n,notebook:r})}async loadSession(n){return this.sessions.get(n)}async loadSessions(n){return(await this.sessions.bulkGet(n)).filter(s=>!!s)}async listSessions(){return this.sessions.orderBy("updated").reverse().toArray()}query(){return this.sessions.where("principal").equals(this.principal)}async listActiveSessions(){const n=Date.now(),r=n-1440*60*1e3,s=await this.query().and(o=>o.updated>=r).and(o=>o.updated<=n).reverse().primaryKeys();let c=[];try{c=await Promise.all(s.map(o=>this.client.getSession(tn(BP,{id:o})).catch(u=>{const l=xn.from(u);if(!(l.code===ln.Unknown&&l.message.includes("session not found")))throw u})))}catch(o){return console.error("Error listing active sessions",o),[]}return c.map(o=>{var u;return(u=o==null?void 0:o.session)==null?void 0:u.id}).filter(o=>!!o)}async deleteSession(n){await this.sessions.delete(n)}async createSession(){var n;try{return(n=(await this.client.createSession({project:tn(DP,{root:".",envLoadOrder:[".env",".env.local",".env.development",".env.dev"]}),config:{envStoreSeeding:PP.SYSTEM}})).session)==null?void 0:n.id}catch(r){console.error("Error creating session",r);return}}}function ck(){return new Date().toISOString()}class Eu extends Error{}Eu.prototype.name="InvalidTokenError";function qB(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,n)=>{let r=n.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}function JB(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return qB(e)}catch{return atob(e)}}function uk(t,e){if(typeof t!="string")throw new Eu("Invalid token specified: must be a string");e||(e={});const n=e.header===!0?0:1,r=t.split(".")[n];if(typeof r!="string")throw new Eu(`Invalid token specified: missing part #${n+1}`);let s;try{s=JB(r)}catch(c){throw new Eu(`Invalid token specified: invalid base64 for part #${n+1} (${c.message})`)}try{return JSON.parse(s)}catch(c){throw new Eu(`Invalid token specified: invalid json for part #${n+1} (${c.message})`)}}const dk="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Lh=32,QB=16,fk=10,ax=0xffffffffffff;var Ga;(function(t){t.Base32IncorrectEncoding="B32_ENC_INVALID",t.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",t.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",t.EncodeTimeNegative="ENC_TIME_NEG",t.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",t.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",t.PRNGDetectFailure="PRNG_DETECT",t.ULIDInvalid="ULID_INVALID",t.Unexpected="UNEXPECTED",t.UUIDInvalid="UUID_INVALID"})(Ga||(Ga={}));class ju extends Error{constructor(e,n){super(`${n} (${e})`),this.name="ULIDError",this.code=e}}function e$(t){const e=Math.floor(t()*Lh)%Lh;return dk.charAt(e)}function t$(t){const e=n$(),n=e&&(e.crypto||e.msCrypto)||null;if(typeof(n==null?void 0:n.getRandomValues)=="function")return()=>{const r=new Uint8Array(1);return n.getRandomValues(r),r[0]/255};if(typeof(n==null?void 0:n.randomBytes)=="function")return()=>n.randomBytes(1).readUInt8()/255;throw new ju(Ga.PRNGDetectFailure,"Failed to find a reliable PRNG")}function n$(){return i$()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function r$(t,e){let n="";for(;t>0;t--)n=e$(e)+n;return n}function s$(t,e=fk){if(isNaN(t))throw new ju(Ga.EncodeTimeValueMalformed,`Time must be a number: ${t}`);if(t>ax)throw new ju(Ga.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ax}: ${t}`);if(t<0)throw new ju(Ga.EncodeTimeNegative,`Time must be positive: ${t}`);if(Number.isInteger(t)===!1)throw new ju(Ga.EncodeTimeValueMalformed,`Time must be an integer: ${t}`);let n,r="";for(let s=e;s>0;s--)n=t%Lh,r=dk.charAt(n)+r,t=(t-n)/Lh;return r}function i$(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function o$(t,e){const n=t$(),r=Date.now();return s$(r,fk)+r$(QB,n)}const hk=$.createContext(void 0),pi=()=>{const t=$.useContext(hk);if(!t)throw new Error("useSettings must be used within a SettingsProvider");return t},a$=({children:t,requireAuth:e,webApp:n})=>{const[r,s]=$.useState(null),c=$.useMemo(()=>{const h=Ih();if(!h)return"unauthenticated";let p;try{return p=uk(h),p.email||p.sub||"unauthenticated"}catch(v){return console.error("Error decoding token",v),"unauthenticated"}},[]),i=$.useMemo(()=>{const h=window.location.hostname==="localhost",p=window.location.protocol==="http:",v=window.location.port==="4173"||window.location.port==="5173",m=h&&p&&v;let b=new URL(window.location.href);n!=null&&n.runner&&(b=new URL(n.runner));const y={requireAuth:!1,agentEndpoint:m?"http://localhost:8080":window.location.origin,webApp:{runner:m?"ws://localhost:8080/ws":`${b.protocol==="https:"?"wss:":"ws:"}//${b.host}/ws`,reconnect:(n==null?void 0:n.reconnect)??!0,invertedOrder:(n==null?void 0:n.invertedOrder)??!1}};return e!==void 0&&(y.requireAuth=e),y},[e,n]),[o,u]=$.useState(()=>{const h=localStorage.getItem("cloudAssistantSettings"),p=h?JSON.parse(h):{};return p&&p.webApp&&p.webApp.reconnect!==void 0&&(p.webApp.reconnect=i.webApp.reconnect),h?{...i,...p}:i});$.useEffect(()=>{localStorage.setItem("cloudAssistantSettings",JSON.stringify(o))},[o]);const l=$.useCallback(h=>{const p=v=>{const m=xn.from(v);m.code===ln.Unauthenticated&&(window.location.href=`/login?error=${encodeURIComponent(m.name)}&error_description=${encodeURIComponent(m.message)}`)};return[v=>async m=>{const b=Ih();return b&&m.header.set("Authorization",`Bearer ${b}`),h?v(m).catch(y=>{throw p(y),y}):v(m)}]},[]),a=$.useCallback(async()=>{if(!o.webApp.runner)return;s(null);const h=new W5({knownID:`check_${o$()}`,runID:Z5(),sequence:0,options:{runnerEndpoint:o.webApp.runner,interceptors:l(!1),autoReconnect:!1}}),p=[];return p.push(h.errors.subscribe({next:v=>s(v)})),p.push(h.connect(G5.INITIAL).subscribe(v=>{v!==null&&(console.log(`Initial heartbeat latency for streamID ${v.streamID} (${v.readyState===1?"open":"closed"}): ${v.latency}ms`),h.close())})),()=>{p.forEach(v=>v.unsubscribe())}},[l,o.webApp.runner]);$.useEffect(()=>{a()},[a]);const d=h=>{u(p=>({...p,...h,webApp:{...p.webApp,...h.webApp}}))};return ie.jsx(hk.Provider,{value:{principal:c,checkRunnerAuth:a,createAuthInterceptors:l,defaultSettings:i,runnerError:r,settings:o,updateSettings:d},children:t})},pk=$.createContext(void 0),l$=()=>{const t=$.useContext(pk);if(!t)throw new Error("useClient must be used within a ClientProvider");return t},c$=({children:t})=>{const[e,n]=$.useState(),{settings:r,createAuthInterceptors:s}=pi();return $.useEffect(()=>{n(u$(r.agentEndpoint,s(!0)))},[r.agentEndpoint,s]),ie.jsx(pk.Provider,{value:{client:e,setClient:n},children:t})};function u$(t,e){console.log(`initializing the client: baseURL ${t}`);const n=sk({baseUrl:t,interceptors:e});return X5(AP,n)}const mk=$.createContext(void 0),ma=()=>{const t=$.useContext(mk);if(!t)throw new Error("useCell must be used within a CellProvider");return t};function lx(t,e){if(!t)return[];const n=t.positions.map(r=>{const s=t.cells[r];return s.languageId="sh",s});return n.length===0?[]:e?n.reverse():n}const d$=({children:t})=>{const{settings:e,principal:n}=pi(),[r,s]=$.useState(0),[c,i]=$.useState(!1),[o,u]=$.useState(!1),[l,a]=$.useState(),d=$.useMemo(()=>{if(n)return new XB("agent",n,q2($P,e.agentEndpoint))},[e.agentEndpoint,n]),h=()=>{s(G=>G+1)},p=$.useMemo(()=>e.webApp.invertedOrder,[e.webApp.invertedOrder]),{client:v}=l$(),[m,b]=$.useState(void 0),y=$.useCallback(()=>{if(!m)return;const G=lx(m,p),q=tn(I2,{cells:G});l&&(q.metadata[Yg.PreviousResponseId]=l),d==null||d.saveNotebook(m.runmeSession,q)},[m,p,l,d]),_=$.useCallback(async({attemptRestore:G})=>{if(!d)return;s(0),a(void 0);const q=d.createSession();let ne;if(!G)ne=await q;else{const U=await d.listActiveSessions(),R=(await d.loadSessions(U)).filter(Y=>Y.data.cells.length!==0);if(R.length===0)ne=await q;else{const Y=R[0];let X=Y.data.cells.map(ae=>ae.refId);p&&(X=X.reverse());const F=Y.data.metadata[Yg.PreviousResponseId];F&&a(F),b({runmeSession:Y.id,cells:Y.data.cells.reduce((ae,ue)=>(ae[ue.refId]=ue,ae),{}),positions:X});return}}b({runmeSession:ne,cells:{},positions:[]})},[p,d]);$.useEffect(()=>{y()},[m,d,p,y]),$.useEffect(()=>{b(G=>({runmeSession:(G==null?void 0:G.runmeSession)??"",cells:(G==null?void 0:G.cells)??{},positions:[...(G==null?void 0:G.positions)??[]].reverse()}))},[p]),$.useEffect(()=>{_&&_({attemptRestore:!0})},[_]);const S=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&(G.kind===zs.MARKUP||G.kind===zs.CODE)):[],[m]),C=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&G.kind===zs.CODE):[],[m]),x=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&G.kind===zs.DOC_RESULTS):[],[m]),j=()=>({chat:S,actions:C,files:x}),k=G=>H8(Lu,G),A=async G=>{const q=CB(),ne=tn(TP,{cells:G,previousResponseId:l});ne.openaiAccessToken=q.accessToken,q.accessToken||console.error("No access token found");try{const U=v.generate(ne);for await(const z of U){for(const R of z.cells)u(!1),M(R);a(z.responseId)}}catch(U){console.log(U)}finally{u(!1),i(!1)}},N=async G=>{if(!G.trim())return;const q=tn(Lu,{refId:`user_${L2()}`,role:yo.USER,kind:zs.MARKUP,value:G});M(q),i(!0),u(!0),await A([q])},D=async G=>{G.outputs.length!==0&&(console.log("sending output cell",G.refId,"previousResponseId",l),i(!0),u(!0),await A([G]))},M=G=>{b(q=>{if(q){if(!q.cells[G.refId]){const ne=p?[G.refId,...q.positions]:[...q.positions,G.refId];return{runmeSession:q.runmeSession,cells:{...q.cells,[G.refId]:G},positions:ne}}return{...q,runmeSession:q.runmeSession,cells:{...q.cells,[G.refId]:G}}}})},B=()=>{const G=`code_${L2().replace(/-/g,"")}`,q=tn(Lu,{metadata:{[oi.ID]:G,[oi.RunmeID]:G},refId:G,role:yo.USER,kind:zs.CODE,value:""});M(q)},Z=G=>{if(C.find(ne=>ne.refId===G.refId)){const ne=new CustomEvent("runCodeCell",{detail:{cellId:G.refId}});window.dispatchEvent(ne)}},ee=async({asSessionRecord:G})=>{var ue;const q=lx(m,p);if(!m||q.length===0)return;const ne=tn(I2,{cells:q}),U=q2(kP,e.agentEndpoint),z=tn(CP,{notebook:ne,options:tn(xP,{outputs:tn(SP,{enabled:!1,summary:!1})})});G&&((ue=z.options)!=null&&ue.outputs)&&(z.options.outputs.enabled=!0,z.options.outputs.summary=!0,z.options.session=tn(wP,{id:m.runmeSession}));const R=await U.serialize(z),Y=new Blob([R.result],{type:"text/plain"}),X=URL.createObjectURL(Y),F=document.createElement("a");F.href=X;const ae=G?"Session":"Notebook";F.download=`${ae}-${ck()}.md`,document.body.appendChild(F),F.click(),document.body.removeChild(F),URL.revokeObjectURL(X)};return ie.jsx(mk.Provider,{value:{useColumns:j,sequence:r,incrementSequence:h,saveState:y,exportDocument:ee,sendOutputCell:D,createOutputCell:k,sendUserCell:N,addCodeCell:B,isInputDisabled:c,isTyping:o,runCodeCell:Z,resetSession:_},children:t})},cx=new TextEncoder;function f$({pid:t,exitCode:e},n,r,s){let c;return t!==null&&e!==null&&(c=tn(yP,{pid:BigInt(t),exitReason:tn(bP,{type:"exit",code:e})})),[tn(R2,{items:[tn(O2,{mime:Oh.VSCodeNotebookStdOut,type:"Buffer",data:cx.encode(n)})],processInfo:c}),tn(R2,{items:[tn(O2,{mime:Oh.VSCodeNotebookStdErr,type:"Buffer",data:cx.encode(r)})]})]}const h$=tn(Lu,{kind:zs.MARKUP,role:yo.ASSISTANT,value:"..."}),p$=$.memo(({cellID:t,runID:e,sequence:n,value:r,content:s,settings:c={},onStdout:i,onStderr:o,onExitCode:u,onPid:l,onMimeType:a})=>{const{createAuthInterceptors:d,settings:{webApp:h}}=pi();return(r!=""&&e!=""||s&&s.length>0)&&ie.jsx(pP,{cellID:t,runID:e,sequence:n,commands:r.split(`
6659
+ `):"",this.name="UnsubscriptionError",this.errors=n}});function Nh(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var _d=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,r,s,c;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var o=kg(i),u=o.next();!u.done;u=o.next()){var l=u.value;l.remove(this)}}catch(m){e={error:m}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(Li(a))try{a()}catch(m){c=m instanceof eg?m.errors:[m]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var h=kg(d),p=h.next();!p.done;p=h.next()){var v=p.value;try{ex(v)}catch(m){c=c??[],m instanceof eg?c=Fu(Fu([],uh(c)),uh(m.errors)):c.push(m)}}}catch(m){r={error:m}}finally{try{p&&!p.done&&(s=h.return)&&s.call(h)}finally{if(r)throw r.error}}}if(c)throw new eg(c)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)ex(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&Nh(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&Nh(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}(),ok=_d.EMPTY;function ak(t){return t instanceof _d||t&&"closed"in t&&Li(t.remove)&&Li(t.add)&&Li(t.unsubscribe)}function ex(t){Li(t)?t():t.unsubscribe()}var TB={Promise:void 0},AB={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Fu([t,e],uh(n)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function IB(t){AB.setTimeout(function(){throw t})}function tx(){}function ah(t){t()}var B0=function(t){ha(e,t);function e(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,ak(n)&&n.add(r)):r.destination=NB,r}return e.create=function(n,r,s){return new qg(n,r,s)},e.prototype.next=function(n){this.isStopped||this._next(n)},e.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(n){this.destination.next(n)},e.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(_d),OB=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var n=this.partialObserver;if(n.next)try{n.next(e)}catch(r){Hf(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){Hf(r)}else Hf(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){Hf(n)}},t}(),qg=function(t){ha(e,t);function e(n,r,s){var c=t.call(this)||this,i;return Li(n)||!n?i={next:n??void 0,error:r??void 0,complete:s??void 0}:i=n,c.destination=new OB(i),c}return e}(B0);function Hf(t){IB(t)}function RB(t){throw t}var NB={closed:!0,next:tx,error:RB,complete:tx},LB=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function DB(t){return t}function MB(t){return t.length===0?DB:t.length===1?t[0]:function(n){return t.reduce(function(r,s){return s(r)},n)}}var nx=function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(e,n,r){var s=this,c=BB(e)?e:new qg(e,n,r);return ah(function(){var i=s,o=i.operator,u=i.source;c.add(o?o.call(c,u):u?s._subscribe(c):s._trySubscribe(c))}),c},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},t.prototype.forEach=function(e,n){var r=this;return n=rx(n),new n(function(s,c){var i=new qg({next:function(o){try{e(o)}catch(u){c(u),i.unsubscribe()}},error:c,complete:s});r.subscribe(i)})},t.prototype._subscribe=function(e){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(e)},t.prototype[LB]=function(){return this},t.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return MB(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=rx(e),new e(function(r,s){var c;n.subscribe(function(i){return c=i},function(i){return s(i)},function(){return r(c)})})},t.create=function(e){return new t(e)},t}();function rx(t){var e;return(e=t??TB.Promise)!==null&&e!==void 0?e:Promise}function PB(t){return t&&Li(t.next)&&Li(t.error)&&Li(t.complete)}function BB(t){return t&&t instanceof B0||PB(t)&&ak(t)}function $B(t){return Li(t==null?void 0:t.lift)}function UB(t){return function(e){if($B(e))return e.lift(function(n){try{return t(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function VB(t,e,n,r,s){return new FB(t,e,n,r,s)}var FB=function(t){ha(e,t);function e(n,r,s,c,i,o){var u=t.call(this,n)||this;return u.onFinalize=i,u.shouldUnsubscribe=o,u._next=r?function(l){try{r(l)}catch(a){n.error(a)}}:t.prototype._next,u._error=c?function(l){try{c(l)}catch(a){n.error(a)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=s?function(){try{s()}catch(l){n.error(l)}finally{this.unsubscribe()}}:t.prototype._complete,u}return e.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},e}(B0),zB=ik(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),lk=function(t){ha(e,t);function e(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return e.prototype.lift=function(n){var r=new sx(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new zB},e.prototype.next=function(n){var r=this;ah(function(){var s,c;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var i=kg(r.currentObservers),o=i.next();!o.done;o=i.next()){var u=o.value;u.next(n)}}catch(l){s={error:l}}finally{try{o&&!o.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}}})},e.prototype.error=function(n){var r=this;ah(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},e.prototype.complete=function(){var n=this;ah(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},e.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},e.prototype._innerSubscribe=function(n){var r=this,s=this,c=s.hasError,i=s.isStopped,o=s.observers;return c||i?ok:(this.currentObservers=null,o.push(n),new _d(function(){r.currentObservers=null,Nh(o,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,c=r.thrownError,i=r.isStopped;s?n.error(c):i&&n.complete()},e.prototype.asObservable=function(){var n=new nx;return n.source=this,n},e.create=function(n,r){return new sx(n,r)},e}(nx),sx=function(t){ha(e,t);function e(n,r){var s=t.call(this)||this;return s.destination=n,s.source=r,s}return e.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},e.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},e.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},e.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:ok},e}(lk),HB={now:function(){return Date.now()}},GB=function(t){ha(e,t);function e(n,r){return t.call(this)||this}return e.prototype.schedule=function(n,r){return this},e}(_d),ix={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Fu([t,e],uh(n)))},clearInterval:function(t){return clearInterval(t)},delegate:void 0},WB=function(t){ha(e,t);function e(n,r){var s=t.call(this,n,r)||this;return s.scheduler=n,s.work=r,s.pending=!1,s}return e.prototype.schedule=function(n,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var c=this.id,i=this.scheduler;return c!=null&&(this.id=this.recycleAsyncId(i,c,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(i,this.id,r),this},e.prototype.requestAsyncId=function(n,r,s){return s===void 0&&(s=0),ix.setInterval(n.flush.bind(n,this),s)},e.prototype.recycleAsyncId=function(n,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&ix.clearInterval(r)},e.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(n,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(n,r){var s=!1,c;try{this.work(n)}catch(i){s=!0,c=i||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),c},e.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,s=n.scheduler,c=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Nh(c,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(GB),ox=function(){function t(e,n){n===void 0&&(n=t.now),this.schedulerActionCtor=e,this.now=n}return t.prototype.schedule=function(e,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,e).schedule(r,n)},t.now=HB.now,t}(),ZB=function(t){ha(e,t);function e(n,r){r===void 0&&(r=ox.now);var s=t.call(this,n,r)||this;return s.actions=[],s._active=!1,s}return e.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var s;this._active=!0;do if(s=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,s){for(;n=r.shift();)n.unsubscribe();throw s}},e}(ox),KB=new ZB(WB);function YB(t,e){return e===void 0&&(e=KB),UB(function(n,r){var s=null,c=null,i=null,o=function(){if(s){s.unsubscribe(),s=null;var l=c;c=null,r.next(l)}};function u(){var l=i+t,a=e.now();if(a<l){s=this.schedule(void 0,l-a),r.add(s);return}o()}n.subscribe(VB(r,function(l){c=l,i=e.now(),s||(s=e.schedule(u,t),r.add(s))},function(){o(),r.complete()},void 0,function(){c=s=null}))})}class XB extends Rh{constructor(n,r,s){super(n);cu(this,"sessions");cu(this,"principal");cu(this,"client");cu(this,"saveSubject",new lk);this.principal=r,this.client=s,this.version(1).stores({sessions:"id, principal, name, created, updated"}),this.saveSubject.pipe(YB(200)).subscribe(async({id:c,notebook:i})=>{const o={id:c,principal:this.principal,name:ck(),created:Date.now(),updated:Date.now(),data:i};console.log(new Date().toISOString(),"saving Notebook",c,i),await this.sessions.put(o)})}async saveNotebook(n,r){this.saveSubject.next({id:n,notebook:r})}async loadSession(n){return this.sessions.get(n)}async loadSessions(n){return(await this.sessions.bulkGet(n)).filter(s=>!!s)}async listSessions(){return this.sessions.orderBy("updated").reverse().toArray()}query(){return this.sessions.where("principal").equals(this.principal)}async listActiveSessions(){const n=Date.now(),r=n-1440*60*1e3,s=await this.query().and(o=>o.updated>=r).and(o=>o.updated<=n).reverse().primaryKeys();let c=[];try{c=await Promise.all(s.map(o=>this.client.getSession(tn(BP,{id:o})).catch(u=>{const l=xn.from(u);if(!(l.code===ln.Unknown&&l.message.includes("session not found")))throw u})))}catch(o){return console.error("Error listing active sessions",o),[]}return c.map(o=>{var u;return(u=o==null?void 0:o.session)==null?void 0:u.id}).filter(o=>!!o)}async deleteSession(n){await this.sessions.delete(n)}async createSession(){var n;try{return(n=(await this.client.createSession({project:tn(DP,{root:".",envLoadOrder:[".env",".env.local",".env.development",".env.dev"]}),config:{envStoreSeeding:PP.SYSTEM}})).session)==null?void 0:n.id}catch(r){console.error("Error creating session",r);return}}}function ck(){return new Date().toISOString()}class Eu extends Error{}Eu.prototype.name="InvalidTokenError";function qB(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,n)=>{let r=n.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}function JB(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return qB(e)}catch{return atob(e)}}function uk(t,e){if(typeof t!="string")throw new Eu("Invalid token specified: must be a string");e||(e={});const n=e.header===!0?0:1,r=t.split(".")[n];if(typeof r!="string")throw new Eu(`Invalid token specified: missing part #${n+1}`);let s;try{s=JB(r)}catch(c){throw new Eu(`Invalid token specified: invalid base64 for part #${n+1} (${c.message})`)}try{return JSON.parse(s)}catch(c){throw new Eu(`Invalid token specified: invalid json for part #${n+1} (${c.message})`)}}const dk="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Lh=32,QB=16,fk=10,ax=0xffffffffffff;var Ga;(function(t){t.Base32IncorrectEncoding="B32_ENC_INVALID",t.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",t.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",t.EncodeTimeNegative="ENC_TIME_NEG",t.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",t.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",t.PRNGDetectFailure="PRNG_DETECT",t.ULIDInvalid="ULID_INVALID",t.Unexpected="UNEXPECTED",t.UUIDInvalid="UUID_INVALID"})(Ga||(Ga={}));class ju extends Error{constructor(e,n){super(`${n} (${e})`),this.name="ULIDError",this.code=e}}function e$(t){const e=Math.floor(t()*Lh)%Lh;return dk.charAt(e)}function t$(t){const e=n$(),n=e&&(e.crypto||e.msCrypto)||null;if(typeof(n==null?void 0:n.getRandomValues)=="function")return()=>{const r=new Uint8Array(1);return n.getRandomValues(r),r[0]/255};if(typeof(n==null?void 0:n.randomBytes)=="function")return()=>n.randomBytes(1).readUInt8()/255;throw new ju(Ga.PRNGDetectFailure,"Failed to find a reliable PRNG")}function n$(){return i$()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function r$(t,e){let n="";for(;t>0;t--)n=e$(e)+n;return n}function s$(t,e=fk){if(isNaN(t))throw new ju(Ga.EncodeTimeValueMalformed,`Time must be a number: ${t}`);if(t>ax)throw new ju(Ga.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ax}: ${t}`);if(t<0)throw new ju(Ga.EncodeTimeNegative,`Time must be positive: ${t}`);if(Number.isInteger(t)===!1)throw new ju(Ga.EncodeTimeValueMalformed,`Time must be an integer: ${t}`);let n,r="";for(let s=e;s>0;s--)n=t%Lh,r=dk.charAt(n)+r,t=(t-n)/Lh;return r}function i$(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function o$(t,e){const n=t$(),r=Date.now();return s$(r,fk)+r$(QB,n)}const hk=$.createContext(void 0),pi=()=>{const t=$.useContext(hk);if(!t)throw new Error("useSettings must be used within a SettingsProvider");return t},a$=({children:t,requireAuth:e,webApp:n})=>{const[r,s]=$.useState(null),c=$.useMemo(()=>{const h=Ih();if(!h)return"unauthenticated";let p;try{return p=uk(h),p.email||p.sub||"unauthenticated"}catch(v){return console.error("Error decoding token",v),"unauthenticated"}},[]),i=$.useMemo(()=>{const h=window.location.hostname==="localhost",p=window.location.protocol==="http:",v=window.location.port==="4173"||window.location.port==="5173",m=h&&p&&v;let b=new URL(window.location.href);n!=null&&n.runner&&(b=new URL(n.runner));const y={requireAuth:!1,agentEndpoint:m?"http://localhost:8080":window.location.origin,webApp:{runner:m?"ws://localhost:8080/ws":`${b.protocol==="https:"?"wss:":"ws:"}//${b.host}/ws`,reconnect:(n==null?void 0:n.reconnect)??!0,invertedOrder:(n==null?void 0:n.invertedOrder)??!1}};return e!==void 0&&(y.requireAuth=e),y},[e,n]),[o,u]=$.useState(()=>{const h=localStorage.getItem("cloudAssistantSettings"),p=h?JSON.parse(h):{};return p&&p.webApp&&p.webApp.reconnect!==void 0&&(p.webApp.reconnect=i.webApp.reconnect),h?{...i,...p}:i});$.useEffect(()=>{localStorage.setItem("cloudAssistantSettings",JSON.stringify(o))},[o]);const l=$.useCallback(h=>{const p=v=>{const m=xn.from(v);m.code===ln.Unauthenticated&&(window.location.href=`/login?error=${encodeURIComponent(m.name)}&error_description=${encodeURIComponent(m.message)}`)};return[v=>async m=>{const b=Ih();return b&&m.header.set("Authorization",`Bearer ${b}`),h?v(m).catch(y=>{throw p(y),y}):v(m)}]},[]),a=$.useCallback(async()=>{if(!o.webApp.runner)return;s(null);const h=new W5({knownID:`check_${o$()}`,runID:Z5(),sequence:0,options:{runnerEndpoint:o.webApp.runner,interceptors:l(!1),autoReconnect:!1}}),p=[];return p.push(h.errors.subscribe({next:v=>s(v)})),p.push(h.connect(G5.INITIAL).subscribe(v=>{v!==null&&(console.log(`Initial heartbeat latency for streamID ${v.streamID} (${v.readyState===1?"open":"closed"}): ${v.latency}ms`),h.close())})),()=>{p.forEach(v=>v.unsubscribe())}},[l,o.webApp.runner]);$.useEffect(()=>{a()},[a]);const d=h=>{u(p=>({...p,...h,webApp:{...p.webApp,...h.webApp}}))};return ie.jsx(hk.Provider,{value:{principal:c,checkRunnerAuth:a,createAuthInterceptors:l,defaultSettings:i,runnerError:r,settings:o,updateSettings:d},children:t})},pk=$.createContext(void 0),l$=()=>{const t=$.useContext(pk);if(!t)throw new Error("useClient must be used within a ClientProvider");return t},c$=({children:t})=>{const[e,n]=$.useState(),{settings:r,createAuthInterceptors:s}=pi();return $.useEffect(()=>{n(u$(r.agentEndpoint,s(!0)))},[r.agentEndpoint,s]),ie.jsx(pk.Provider,{value:{client:e,setClient:n},children:t})};function u$(t,e){console.log(`initializing the client: baseURL ${t}`);const n=sk({baseUrl:t,interceptors:e});return X5(AP,n)}const mk=$.createContext(void 0),ma=()=>{const t=$.useContext(mk);if(!t)throw new Error("useCell must be used within a CellProvider");return t};function lx(t,e){if(!t)return[];const n=t.positions.map(r=>{const s=t.cells[r];return s.languageId="sh",s});return n.length===0?[]:e?n.reverse():n}const d$=({children:t})=>{const{settings:e,principal:n}=pi(),[r,s]=$.useState(0),[c,i]=$.useState(!1),[o,u]=$.useState(!1),[l,a]=$.useState(),d=$.useMemo(()=>{if(n)return new XB("agent",n,q2($P,e.webApp.runner))},[e.agentEndpoint,n]),h=()=>{s(G=>G+1)},p=$.useMemo(()=>e.webApp.invertedOrder,[e.webApp.invertedOrder]),{client:v}=l$(),[m,b]=$.useState(void 0),y=$.useCallback(()=>{if(!m)return;const G=lx(m,p),q=tn(I2,{cells:G});l&&(q.metadata[Yg.PreviousResponseId]=l),d==null||d.saveNotebook(m.runmeSession,q)},[m,p,l,d]),_=$.useCallback(async({attemptRestore:G})=>{if(!d)return;s(0),a(void 0);const q=d.createSession();let ne;if(!G)ne=await q;else{const U=await d.listActiveSessions(),R=(await d.loadSessions(U)).filter(Y=>Y.data.cells.length!==0);if(R.length===0)ne=await q;else{const Y=R[0];let X=Y.data.cells.map(ae=>ae.refId);p&&(X=X.reverse());const F=Y.data.metadata[Yg.PreviousResponseId];F&&a(F),b({runmeSession:Y.id,cells:Y.data.cells.reduce((ae,ue)=>(ae[ue.refId]=ue,ae),{}),positions:X});return}}b({runmeSession:ne,cells:{},positions:[]})},[p,d]);$.useEffect(()=>{y()},[m,d,p,y]),$.useEffect(()=>{b(G=>({runmeSession:(G==null?void 0:G.runmeSession)??"",cells:(G==null?void 0:G.cells)??{},positions:[...(G==null?void 0:G.positions)??[]].reverse()}))},[p]),$.useEffect(()=>{_&&_({attemptRestore:!0})},[_]);const S=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&(G.kind===zs.MARKUP||G.kind===zs.CODE)):[],[m]),C=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&G.kind===zs.CODE):[],[m]),x=$.useMemo(()=>m?m.positions.map(G=>m.cells[G]).filter(G=>!!G&&G.kind===zs.DOC_RESULTS):[],[m]),j=()=>({chat:S,actions:C,files:x}),k=G=>H8(Lu,G),A=async G=>{const q=CB(),ne=tn(TP,{cells:G,previousResponseId:l});ne.openaiAccessToken=q.accessToken,q.accessToken||console.error("No access token found");try{const U=v.generate(ne);for await(const z of U){for(const R of z.cells)u(!1),M(R);a(z.responseId)}}catch(U){console.log(U)}finally{u(!1),i(!1)}},N=async G=>{if(!G.trim())return;const q=tn(Lu,{refId:`user_${L2()}`,role:yo.USER,kind:zs.MARKUP,value:G});M(q),i(!0),u(!0),await A([q])},D=async G=>{G.outputs.length!==0&&(console.log("sending output cell",G.refId,"previousResponseId",l),i(!0),u(!0),await A([G]))},M=G=>{b(q=>{if(q){if(!q.cells[G.refId]){const ne=p?[G.refId,...q.positions]:[...q.positions,G.refId];return{runmeSession:q.runmeSession,cells:{...q.cells,[G.refId]:G},positions:ne}}return{...q,runmeSession:q.runmeSession,cells:{...q.cells,[G.refId]:G}}}})},B=()=>{const G=`code_${L2().replace(/-/g,"")}`,q=tn(Lu,{metadata:{[oi.ID]:G,[oi.RunmeID]:G},refId:G,role:yo.USER,kind:zs.CODE,value:""});M(q)},Z=G=>{if(C.find(ne=>ne.refId===G.refId)){const ne=new CustomEvent("runCodeCell",{detail:{cellId:G.refId}});window.dispatchEvent(ne)}},ee=async({asSessionRecord:G})=>{var ue;const q=lx(m,p);if(!m||q.length===0)return;const ne=tn(I2,{cells:q}),U=q2(kP,e.webApp.runner),z=tn(CP,{notebook:ne,options:tn(xP,{outputs:tn(SP,{enabled:!1,summary:!1})})});G&&((ue=z.options)!=null&&ue.outputs)&&(z.options.outputs.enabled=!0,z.options.outputs.summary=!0,z.options.session=tn(wP,{id:m.runmeSession}));const R=await U.serialize(z),Y=new Blob([R.result],{type:"text/plain"}),X=URL.createObjectURL(Y),F=document.createElement("a");F.href=X;const ae=G?"Session":"Notebook";F.download=`${ae}-${ck()}.md`,document.body.appendChild(F),F.click(),document.body.removeChild(F),URL.revokeObjectURL(X)};return ie.jsx(mk.Provider,{value:{useColumns:j,sequence:r,incrementSequence:h,saveState:y,exportDocument:ee,sendOutputCell:D,createOutputCell:k,sendUserCell:N,addCodeCell:B,isInputDisabled:c,isTyping:o,runCodeCell:Z,resetSession:_},children:t})},cx=new TextEncoder;function f$({pid:t,exitCode:e},n,r,s){let c;return t!==null&&e!==null&&(c=tn(yP,{pid:BigInt(t),exitReason:tn(bP,{type:"exit",code:e})})),[tn(R2,{items:[tn(O2,{mime:Oh.VSCodeNotebookStdOut,type:"Buffer",data:cx.encode(n)})],processInfo:c}),tn(R2,{items:[tn(O2,{mime:Oh.VSCodeNotebookStdErr,type:"Buffer",data:cx.encode(r)})]})]}const h$=tn(Lu,{kind:zs.MARKUP,role:yo.ASSISTANT,value:"..."}),p$=$.memo(({cellID:t,runID:e,sequence:n,value:r,content:s,settings:c={},onStdout:i,onStderr:o,onExitCode:u,onPid:l,onMimeType:a})=>{const{createAuthInterceptors:d,settings:{webApp:h}}=pi();return(r!=""&&e!=""||s&&s.length>0)&&ie.jsx(pP,{cellID:t,runID:e,sequence:n,commands:r.split(`
6660
6660
  `),content:s,runner:{endpoint:h.runner,reconnect:h.reconnect,interceptors:d(!1)},settings:c,onPid:l,onStdout:i,onStderr:o,onExitCode:u,onMimeType:a})},(t,e)=>t.cellID===e.cellID&&JSON.stringify(t.value)===JSON.stringify(e.value)&&t.runID===e.runID);function m$(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ux(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function dx(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?ux(Object(n),!0).forEach(function(r){m$(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ux(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function v$(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,c;for(c=0;c<r.length;c++)s=r[c],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function g$(t,e){if(t==null)return{};var n=v$(t,e),r,s;if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);for(s=0;s<c.length;s++)r=c[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function b$(t,e){return y$(t)||_$(t,e)||w$(t,e)||S$()}function y$(t){if(Array.isArray(t))return t}function _$(t,e){if(!(typeof Symbol>"u"||!(Symbol.iterator in Object(t)))){var n=[],r=!0,s=!1,c=void 0;try{for(var i=t[Symbol.iterator](),o;!(r=(o=i.next()).done)&&(n.push(o.value),!(e&&n.length===e));r=!0);}catch(u){s=!0,c=u}finally{try{!r&&i.return!=null&&i.return()}finally{if(s)throw c}}return n}}function w$(t,e){if(t){if(typeof t=="string")return fx(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return fx(t,e)}}function fx(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function S$(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
6661
6661
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function x$(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function hx(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function px(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?hx(Object(n),!0).forEach(function(r){x$(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):hx(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function C$(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return function(r){return e.reduceRight(function(s,c){return c(s)},r)}}function ku(t){return function e(){for(var n=this,r=arguments.length,s=new Array(r),c=0;c<r;c++)s[c]=arguments[c];return s.length>=t.length?t.apply(this,s):function(){for(var i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];return e.apply(n,[].concat(s,o))}}}function Dh(t){return{}.toString.call(t).includes("Object")}function E$(t){return!Object.keys(t).length}function id(t){return typeof t=="function"}function j$(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function k$(t,e){return Dh(e)||oa("changeType"),Object.keys(e).some(function(n){return!j$(t,n)})&&oa("changeField"),e}function T$(t){id(t)||oa("selectorType")}function A$(t){id(t)||Dh(t)||oa("handlerType"),Dh(t)&&Object.values(t).some(function(e){return!id(e)})&&oa("handlersType")}function I$(t){t||oa("initialIsRequired"),Dh(t)||oa("initialType"),E$(t)&&oa("initialContent")}function O$(t,e){throw new Error(t[e]||t.default)}var R$={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},oa=ku(O$)(R$),Gf={changes:k$,selector:T$,handler:A$,initial:I$};function N$(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Gf.initial(t),Gf.handler(e);var n={current:t},r=ku(M$)(n,e),s=ku(D$)(n),c=ku(Gf.changes)(t),i=ku(L$)(n);function o(){var l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(a){return a};return Gf.selector(l),l(n.current)}function u(l){C$(r,s,c,i)(l)}return[o,u]}function L$(t,e){return id(e)?e(t.current):e}function D$(t,e){return t.current=px(px({},t.current),e),e}function M$(t,e,n){return id(e)?e(t.current):Object.keys(n).forEach(function(r){var s;return(s=e[r])===null||s===void 0?void 0:s.call(e,t.current[r])}),n}var P$={create:N$},B$={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs"}};function $$(t){return function e(){for(var n=this,r=arguments.length,s=new Array(r),c=0;c<r;c++)s[c]=arguments[c];return s.length>=t.length?t.apply(this,s):function(){for(var i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];return e.apply(n,[].concat(s,o))}}}function U$(t){return{}.toString.call(t).includes("Object")}function V$(t){return t||mx("configIsRequired"),U$(t)||mx("configType"),t.urls?(F$(),{paths:{vs:t.urls.monacoBase}}):t}function F$(){console.warn(vk.deprecation)}function z$(t,e){throw new Error(t[e]||t.default)}var vk={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
6662
6662
  You are using deprecated way of configuration.
@@ -6545,7 +6545,7 @@ Open Dashboard to configure it`)},k=function(){var Se;const Ie=(0,K.getContext)(
6545
6545
  `)}function se(C,E,A,N){this.failures=E,this.failedKeys=N,this.successCount=A,this.message=te(C,E)}function G(C,E){this.name="BulkError",this.failures=Object.keys(E).map(function(A){return E[A]}),this.failuresByPos=E,this.message=te(C,this.failures)}f(z).from(Error).extend({toString:function(){return this.name+": "+this.message}}),f(se).from(z),f(G).from(z);var D=jr.reduce(function(C,E){return C[E]=E+"Error",C},{}),he=z,J=jr.reduce(function(C,E){var A=E+"Error";function N(M,V){this.name=A,M?typeof M=="string"?(this.message="".concat(M).concat(V?`
6546
6546
  `+V:""),this.inner=V||null):typeof M=="object"&&(this.message="".concat(M.name," ").concat(M.message),this.inner=M):(this.message=U[E]||A,this.inner=null)}return f(N).from(he),C[E]=N,C},{});J.Syntax=SyntaxError,J.Type=TypeError,J.Range=RangeError;var Oe=Ye.reduce(function(C,E){return C[E+"Error"]=J[E],C},{}),be=jr.reduce(function(C,E){return["Syntax","Type","Range"].indexOf(E)===-1&&(C[E+"Error"]=J[E]),C},{});function Le(){}function $e(C){return C}function st(C,E){return C==null||C===$e?E:function(A){return E(C(A))}}function Se(C,E){return function(){C.apply(this,arguments),E.apply(this,arguments)}}function Ie(C,E){return C===Le?E:function(){var A=C.apply(this,arguments);A!==void 0&&(arguments[0]=A);var N=this.onsuccess,M=this.onerror;this.onsuccess=null,this.onerror=null;var V=E.apply(this,arguments);return N&&(this.onsuccess=this.onsuccess?Se(N,this.onsuccess):N),M&&(this.onerror=this.onerror?Se(M,this.onerror):M),V!==void 0?V:A}}function re(C,E){return C===Le?E:function(){C.apply(this,arguments);var A=this.onsuccess,N=this.onerror;this.onsuccess=this.onerror=null,E.apply(this,arguments),A&&(this.onsuccess=this.onsuccess?Se(A,this.onsuccess):A),N&&(this.onerror=this.onerror?Se(N,this.onerror):N)}}function Q(C,E){return C===Le?E:function(A){var N=C.apply(this,arguments);c(A,N);var M=this.onsuccess,V=this.onerror;return this.onsuccess=null,this.onerror=null,A=E.apply(this,arguments),M&&(this.onsuccess=this.onsuccess?Se(M,this.onsuccess):M),V&&(this.onerror=this.onerror?Se(V,this.onerror):V),N===void 0?A===void 0?void 0:A:c(N,A)}}function le(C,E){return C===Le?E:function(){return E.apply(this,arguments)!==!1&&C.apply(this,arguments)}}function _e(C,E){return C===Le?E:function(){var A=C.apply(this,arguments);if(A&&typeof A.then=="function"){for(var N=this,M=arguments.length,V=new Array(M);M--;)V[M]=arguments[M];return A.then(function(){return E.apply(N,V)})}return E.apply(this,arguments)}}be.ModifyError=se,be.DexieError=z,be.BulkError=G;var xe=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function Ae(C){xe=C}var nt={},it=100,lt=typeof Promise>"u"?[]:function(){var C=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[C,i(C),C];var E=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[E,i(E),C]}(),Ye=lt[0],jr=lt[1],lt=lt[2],jr=jr&&jr.then,Ce=Ye&&Ye.constructor,gt=!!lt,ht=function(C,E){Lt.push([C,E]),ct&&(queueMicrotask(et),ct=!1)},Et=!0,ct=!0,It=[],Nt=[],$t=$e,Pt={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Le,pgp:!1,env:{},finalize:Le},ze=Pt,Lt=[],Ot=0,Bt=[];function Te(C){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var E=this._PSD=ze;if(typeof C!="function"){if(C!==nt)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&Ue(this,this._value))}this._state=null,this._value=null,++E.ref,function A(N,M){try{M(function(V){if(N._state===null){if(V===N)throw new TypeError("A promise cannot be resolved with itself.");var Y=N._lib&&ut();V&&typeof V.then=="function"?A(N,function(ie,ce){V instanceof Te?V._then(ie,ce):V.then(ie,ce)}):(N._state=!0,N._value=V,Xe(N)),Y&&bt()}},Ue.bind(null,N))}catch(V){Ue(N,V)}}(this,C)}var fe={get:function(){var C=ze,E=br;function A(N,M){var V=this,Y=!C.global&&(C!==ze||E!==br),ie=Y&&!tr(),ce=new Te(function(de,ge){ot(V,new Pe(Ur(N,C,Y,ie),Ur(M,C,Y,ie),de,ge,C))});return this._consoleTask&&(ce._consoleTask=this._consoleTask),ce}return A.prototype=nt,A},set:function(C){m(this,"then",C&&C.prototype===nt?fe:{get:function(){return C},set:fe.set})}};function Pe(C,E,A,N,M){this.onFulfilled=typeof C=="function"?C:null,this.onRejected=typeof E=="function"?E:null,this.resolve=A,this.reject=N,this.psd=M}function Ue(C,E){var A,N;Nt.push(E),C._state===null&&(A=C._lib&&ut(),E=$t(E),C._state=!1,C._value=E,N=C,It.some(function(M){return M._value===N._value})||It.push(N),Xe(C),A&&bt())}function Xe(C){var E=C._listeners;C._listeners=[];for(var A=0,N=E.length;A<N;++A)ot(C,E[A]);var M=C._PSD;--M.ref||M.finalize(),Ot===0&&(++Ot,ht(function(){--Ot==0&&Dt()},[]))}function ot(C,E){if(C._state!==null){var A=C._state?E.onFulfilled:E.onRejected;if(A===null)return(C._state?E.resolve:E.reject)(C._value);++E.psd.ref,++Ot,ht(Qe,[A,C,E])}else C._listeners.push(E)}function Qe(C,E,A){try{var N,M=E._value;!E._state&&Nt.length&&(Nt=[]),N=xe&&E._consoleTask?E._consoleTask.run(function(){return C(M)}):C(M),E._state||Nt.indexOf(M)!==-1||function(V){for(var Y=It.length;Y;)if(It[--Y]._value===V._value)return It.splice(Y,1)}(E),A.resolve(N)}catch(V){A.reject(V)}finally{--Ot==0&&Dt(),--A.psd.ref||A.psd.finalize()}}function et(){ar(Pt,function(){ut()&&bt()})}function ut(){var C=Et;return ct=Et=!1,C}function bt(){var C,E,A;do for(;0<Lt.length;)for(C=Lt,Lt=[],A=C.length,E=0;E<A;++E){var N=C[E];N[0].apply(null,N[1])}while(0<Lt.length);ct=Et=!0}function Dt(){var C=It;It=[],C.forEach(function(N){N._PSD.onunhandled.call(null,N._value,N)});for(var E=Bt.slice(0),A=E.length;A;)E[--A]()}function _t(C){return new Te(nt,!1,C)}function dt(C,E){var A=ze;return function(){var N=ut(),M=ze;try{return rr(A,!0),C.apply(this,arguments)}catch(V){E&&E(V)}finally{rr(M,!1),N&&bt()}}}h(Te.prototype,{then:fe,_then:function(C,E){ot(this,new Pe(null,null,C,E,ze))},catch:function(C){if(arguments.length===1)return this.then(null,C);var E=C,A=arguments[1];return typeof E=="function"?this.then(null,function(N){return(N instanceof E?A:_t)(N)}):this.then(null,function(N){return(N&&N.name===E?A:_t)(N)})},finally:function(C){return this.then(function(E){return Te.resolve(C()).then(function(){return E})},function(E){return Te.resolve(C()).then(function(){return _t(E)})})},timeout:function(C,E){var A=this;return C<1/0?new Te(function(N,M){var V=setTimeout(function(){return M(new J.Timeout(E))},C);A.then(N,M).finally(clearTimeout.bind(null,V))}):this}}),typeof Symbol<"u"&&Symbol.toStringTag&&m(Te.prototype,Symbol.toStringTag,"Dexie.Promise"),Pt.env=Vr(),h(Te,{all:function(){var C=B.apply(null,arguments).map(yr);return new Te(function(E,A){C.length===0&&E([]);var N=C.length;C.forEach(function(M,V){return Te.resolve(M).then(function(Y){C[V]=Y,--N||E(C)},A)})})},resolve:function(C){return C instanceof Te?C:C&&typeof C.then=="function"?new Te(function(E,A){C.then(E,A)}):new Te(nt,!0,C)},reject:_t,race:function(){var C=B.apply(null,arguments).map(yr);return new Te(function(E,A){C.map(function(N){return Te.resolve(N).then(E,A)})})},PSD:{get:function(){return ze},set:function(C){return ze=C}},totalEchoes:{get:function(){return br}},newPSD:er,usePSD:ar,scheduler:{get:function(){return ht},set:function(C){ht=C}},rejectionMapper:{get:function(){return $t},set:function(C){$t=C}},follow:function(C,E){return new Te(function(A,N){return er(function(M,V){var Y=ze;Y.unhandleds=[],Y.onunhandled=V,Y.finalize=Se(function(){var ie,ce=this;ie=function(){ce.unhandleds.length===0?M():V(ce.unhandleds[0])},Bt.push(function de(){ie(),Bt.splice(Bt.indexOf(de),1)}),++Ot,ht(function(){--Ot==0&&Dt()},[])},Y.finalize),C()},E,A,N)})}}),Ce&&(Ce.allSettled&&m(Te,"allSettled",function(){var C=B.apply(null,arguments).map(yr);return new Te(function(E){C.length===0&&E([]);var A=C.length,N=new Array(A);C.forEach(function(M,V){return Te.resolve(M).then(function(Y){return N[V]={status:"fulfilled",value:Y}},function(Y){return N[V]={status:"rejected",reason:Y}}).then(function(){return--A||E(N)})})})}),Ce.any&&typeof AggregateError<"u"&&m(Te,"any",function(){var C=B.apply(null,arguments).map(yr);return new Te(function(E,A){C.length===0&&A(new AggregateError([]));var N=C.length,M=new Array(N);C.forEach(function(V,Y){return Te.resolve(V).then(function(ie){return E(ie)},function(ie){M[Y]=ie,--N||A(new AggregateError(M))})})})}),Ce.withResolvers&&(Te.withResolvers=Ce.withResolvers));var pe={awaits:0,echoes:0,id:0},Kt=0,vr=[],gr=0,br=0,Kr=0;function er(C,E,A,N){var M=ze,V=Object.create(M);return V.parent=M,V.ref=0,V.global=!1,V.id=++Kr,Pt.env,V.env=gt?{Promise:Te,PromiseProp:{value:Te,configurable:!0,writable:!0},all:Te.all,race:Te.race,allSettled:Te.allSettled,any:Te.any,resolve:Te.resolve,reject:Te.reject}:{},E&&c(V,E),++M.ref,V.finalize=function(){--this.parent.ref||this.parent.finalize()},N=ar(V,C,A,N),V.ref===0&&V.finalize(),N}function dr(){return pe.id||(pe.id=++Kt),++pe.awaits,pe.echoes+=it,pe.id}function tr(){return!!pe.awaits&&(--pe.awaits==0&&(pe.id=0),pe.echoes=pe.awaits*it,!0)}function yr(C){return pe.echoes&&C&&C.constructor===Ce?(dr(),C.then(function(E){return tr(),E},function(E){return tr(),Tt(E)})):C}function Xr(){var C=vr[vr.length-1];vr.pop(),rr(C,!1)}function rr(C,E){var A,N=ze;(E?!pe.echoes||gr++&&C===ze:!gr||--gr&&C===ze)||queueMicrotask(E?(function(M){++br,pe.echoes&&--pe.echoes!=0||(pe.echoes=pe.awaits=pe.id=0),vr.push(ze),rr(M,!0)}).bind(null,C):Xr),C!==ze&&(ze=C,N===Pt&&(Pt.env=Vr()),gt&&(A=Pt.env.Promise,E=C.env,(N.global||C.global)&&(Object.defineProperty(d,"Promise",E.PromiseProp),A.all=E.all,A.race=E.race,A.resolve=E.resolve,A.reject=E.reject,E.allSettled&&(A.allSettled=E.allSettled),E.any&&(A.any=E.any))))}function Vr(){var C=d.Promise;return gt?{Promise:C,PromiseProp:Object.getOwnPropertyDescriptor(d,"Promise"),all:C.all,race:C.race,allSettled:C.allSettled,any:C.any,resolve:C.resolve,reject:C.reject}:{}}function ar(C,E,A,N,M){var V=ze;try{return rr(C,!0),E(A,N,M)}finally{rr(V,!1)}}function Ur(C,E,A,N){return typeof C!="function"?C:function(){var M=ze;A&&dr(),rr(E,!0);try{return C.apply(this,arguments)}finally{rr(M,!1),N&&queueMicrotask(tr)}}}function Or(C){Promise===Ce&&pe.echoes===0?gr===0?C():enqueueNativeMicroTask(C):setTimeout(C,0)}(""+jr).indexOf("[native code]")===-1&&(dr=tr=Le);var Tt=Te.reject,lr="￿",Xt="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",Wr="String expected.",hr=[],_r="__dbnames",Ar="readonly",Rr="readwrite";function cr(C,E){return C?E?function(){return C.apply(this,arguments)&&E.apply(this,arguments)}:C:E}var Lr={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function wr(C){return typeof C!="string"||/\./.test(C)?function(E){return E}:function(E){return E[C]===void 0&&C in E&&delete(E=F(E))[C],E}}function ln(){throw J.Type()}function mt(C,E){try{var A=cn(C),N=cn(E);if(A!==N)return A==="Array"?1:N==="Array"?-1:A==="binary"?1:N==="binary"?-1:A==="string"?1:N==="string"?-1:A==="Date"?1:N!=="Date"?NaN:-1;switch(A){case"number":case"Date":case"string":return E<C?1:C<E?-1:0;case"binary":return function(M,V){for(var Y=M.length,ie=V.length,ce=Y<ie?Y:ie,de=0;de<ce;++de)if(M[de]!==V[de])return M[de]<V[de]?-1:1;return Y===ie?0:Y<ie?-1:1}(un(C),un(E));case"Array":return function(M,V){for(var Y=M.length,ie=V.length,ce=Y<ie?Y:ie,de=0;de<ce;++de){var ge=mt(M[de],V[de]);if(ge!==0)return ge}return Y===ie?0:Y<ie?-1:1}(C,E)}}catch{}return NaN}function cn(C){var E=typeof C;return E!="object"?E:ArrayBuffer.isView(C)?"binary":(C=W(C),C==="ArrayBuffer"?"binary":C)}function un(C){return C instanceof Uint8Array?C:ArrayBuffer.isView(C)?new Uint8Array(C.buffer,C.byteOffset,C.byteLength):new Uint8Array(C)}var dn=(kt.prototype._trans=function(C,E,A){var N=this._tx||ze.trans,M=this.name,V=xe&&typeof console<"u"&&console.createTask&&console.createTask("Dexie: ".concat(C==="readonly"?"read":"write"," ").concat(this.name));function Y(de,ge,oe){if(!oe.schema[M])throw new J.NotFound("Table "+M+" not part of transaction");return E(oe.idbtrans,oe)}var ie=ut();try{var ce=N&&N.db._novip===this.db._novip?N===ze.trans?N._promise(C,Y,A):er(function(){return N._promise(C,Y,A)},{trans:N,transless:ze.transless||ze}):function de(ge,oe,we,ue){if(ge.idbdb&&(ge._state.openComplete||ze.letThrough||ge._vip)){var ve=ge._createTransaction(oe,we,ge._dbSchema);try{ve.create(),ge._state.PR1398_maxLoop=3}catch(ye){return ye.name===D.InvalidState&&ge.isOpen()&&0<--ge._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),ge.close({disableAutoOpen:!1}),ge.open().then(function(){return de(ge,oe,we,ue)})):Tt(ye)}return ve._promise(oe,function(ye,me){return er(function(){return ze.trans=ve,ue(ye,me,ve)})}).then(function(ye){if(oe==="readwrite")try{ve.idbtrans.commit()}catch{}return oe==="readonly"?ye:ve._completion.then(function(){return ye})})}if(ge._state.openComplete)return Tt(new J.DatabaseClosed(ge._state.dbOpenError));if(!ge._state.isBeingOpened){if(!ge._state.autoOpen)return Tt(new J.DatabaseClosed);ge.open().catch(Le)}return ge._state.dbReadyPromise.then(function(){return de(ge,oe,we,ue)})}(this.db,C,[this.name],Y);return V&&(ce._consoleTask=V,ce=ce.catch(function(de){return console.trace(de),Tt(de)})),ce}finally{ie&&bt()}},kt.prototype.get=function(C,E){var A=this;return C&&C.constructor===Object?this.where(C).first(E):C==null?Tt(new J.Type("Invalid argument to Table.get()")):this._trans("readonly",function(N){return A.core.get({trans:N,key:C}).then(function(M){return A.hook.reading.fire(M)})}).then(E)},kt.prototype.where=function(C){if(typeof C=="string")return new this.db.WhereClause(this,C);if(o(C))return new this.db.WhereClause(this,"[".concat(C.join("+"),"]"));var E=a(C);if(E.length===1)return this.where(E[0]).equals(C[E[0]]);var A=this.schema.indexes.concat(this.schema.primKey).filter(function(ie){if(ie.compound&&E.every(function(de){return 0<=ie.keyPath.indexOf(de)})){for(var ce=0;ce<E.length;++ce)if(E.indexOf(ie.keyPath[ce])===-1)return!1;return!0}return!1}).sort(function(ie,ce){return ie.keyPath.length-ce.keyPath.length})[0];if(A&&this.db._maxKey!==lr){var V=A.keyPath.slice(0,E.length);return this.where(V).equals(V.map(function(ce){return C[ce]}))}!A&&xe&&console.warn("The query ".concat(JSON.stringify(C)," on ").concat(this.name," would benefit from a ")+"compound index [".concat(E.join("+"),"]"));var N=this.schema.idxByName;function M(ie,ce){return mt(ie,ce)===0}var Y=E.reduce(function(oe,ce){var de=oe[0],ge=oe[1],oe=N[ce],we=C[ce];return[de||oe,de||!oe?cr(ge,oe&&oe.multi?function(ue){return ue=x(ue,ce),o(ue)&&ue.some(function(ve){return M(we,ve)})}:function(ue){return M(we,x(ue,ce))}):ge]},[null,null]),V=Y[0],Y=Y[1];return V?this.where(V.name).equals(C[V.keyPath]).filter(Y):A?this.filter(Y):this.where(E).equals("")},kt.prototype.filter=function(C){return this.toCollection().and(C)},kt.prototype.count=function(C){return this.toCollection().count(C)},kt.prototype.offset=function(C){return this.toCollection().offset(C)},kt.prototype.limit=function(C){return this.toCollection().limit(C)},kt.prototype.each=function(C){return this.toCollection().each(C)},kt.prototype.toArray=function(C){return this.toCollection().toArray(C)},kt.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},kt.prototype.orderBy=function(C){return new this.db.Collection(new this.db.WhereClause(this,o(C)?"[".concat(C.join("+"),"]"):C))},kt.prototype.reverse=function(){return this.toCollection().reverse()},kt.prototype.mapToClass=function(C){var E,A=this.db,N=this.name;function M(){return E!==null&&E.apply(this,arguments)||this}(this.schema.mappedClass=C).prototype instanceof ln&&(function(ce,de){if(typeof de!="function"&&de!==null)throw new TypeError("Class extends value "+String(de)+" is not a constructor or null");function ge(){this.constructor=ce}t(ce,de),ce.prototype=de===null?Object.create(de):(ge.prototype=de.prototype,new ge)}(M,E=C),Object.defineProperty(M.prototype,"db",{get:function(){return A},enumerable:!1,configurable:!0}),M.prototype.table=function(){return N},C=M);for(var V=new Set,Y=C.prototype;Y;Y=i(Y))Object.getOwnPropertyNames(Y).forEach(function(ce){return V.add(ce)});function ie(ce){if(!ce)return ce;var de,ge=Object.create(C.prototype);for(de in ce)if(!V.has(de))try{ge[de]=ce[de]}catch{}return ge}return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=ie,this.hook("reading",ie),C},kt.prototype.defineClass=function(){return this.mapToClass(function(C){c(this,C)})},kt.prototype.add=function(C,E){var A=this,N=this.schema.primKey,M=N.auto,V=N.keyPath,Y=C;return V&&M&&(Y=wr(V)(C)),this._trans("readwrite",function(ie){return A.core.mutate({trans:ie,type:"add",keys:E!=null?[E]:null,values:[Y]})}).then(function(ie){return ie.numFailures?Te.reject(ie.failures[0]):ie.lastResult}).then(function(ie){if(V)try{S(C,V,ie)}catch{}return ie})},kt.prototype.update=function(C,E){return typeof C!="object"||o(C)?this.where(":id").equals(C).modify(E):(C=x(C,this.schema.primKey.keyPath),C===void 0?Tt(new J.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(C).modify(E))},kt.prototype.put=function(C,E){var A=this,N=this.schema.primKey,M=N.auto,V=N.keyPath,Y=C;return V&&M&&(Y=wr(V)(C)),this._trans("readwrite",function(ie){return A.core.mutate({trans:ie,type:"put",values:[Y],keys:E!=null?[E]:null})}).then(function(ie){return ie.numFailures?Te.reject(ie.failures[0]):ie.lastResult}).then(function(ie){if(V)try{S(C,V,ie)}catch{}return ie})},kt.prototype.delete=function(C){var E=this;return this._trans("readwrite",function(A){return E.core.mutate({trans:A,type:"delete",keys:[C]})}).then(function(A){return A.numFailures?Te.reject(A.failures[0]):void 0})},kt.prototype.clear=function(){var C=this;return this._trans("readwrite",function(E){return C.core.mutate({trans:E,type:"deleteRange",range:Lr})}).then(function(E){return E.numFailures?Te.reject(E.failures[0]):void 0})},kt.prototype.bulkGet=function(C){var E=this;return this._trans("readonly",function(A){return E.core.getMany({keys:C,trans:A}).then(function(N){return N.map(function(M){return E.hook.reading.fire(M)})})})},kt.prototype.bulkAdd=function(C,E,A){var N=this,M=Array.isArray(E)?E:void 0,V=(A=A||(M?void 0:E))?A.allKeys:void 0;return this._trans("readwrite",function(Y){var de=N.schema.primKey,ie=de.auto,de=de.keyPath;if(de&&M)throw new J.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(M&&M.length!==C.length)throw new J.InvalidArgument("Arguments objects and keys must have the same length");var ce=C.length,de=de&&ie?C.map(wr(de)):C;return N.core.mutate({trans:Y,type:"add",keys:M,values:de,wantResults:V}).then(function(ve){var oe=ve.numFailures,we=ve.results,ue=ve.lastResult,ve=ve.failures;if(oe===0)return V?we:ue;throw new G("".concat(N.name,".bulkAdd(): ").concat(oe," of ").concat(ce," operations failed"),ve)})})},kt.prototype.bulkPut=function(C,E,A){var N=this,M=Array.isArray(E)?E:void 0,V=(A=A||(M?void 0:E))?A.allKeys:void 0;return this._trans("readwrite",function(Y){var de=N.schema.primKey,ie=de.auto,de=de.keyPath;if(de&&M)throw new J.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(M&&M.length!==C.length)throw new J.InvalidArgument("Arguments objects and keys must have the same length");var ce=C.length,de=de&&ie?C.map(wr(de)):C;return N.core.mutate({trans:Y,type:"put",keys:M,values:de,wantResults:V}).then(function(ve){var oe=ve.numFailures,we=ve.results,ue=ve.lastResult,ve=ve.failures;if(oe===0)return V?we:ue;throw new G("".concat(N.name,".bulkPut(): ").concat(oe," of ").concat(ce," operations failed"),ve)})})},kt.prototype.bulkUpdate=function(C){var E=this,A=this.core,N=C.map(function(Y){return Y.key}),M=C.map(function(Y){return Y.changes}),V=[];return this._trans("readwrite",function(Y){return A.getMany({trans:Y,keys:N,cache:"clone"}).then(function(ie){var ce=[],de=[];C.forEach(function(oe,we){var ue=oe.key,ve=oe.changes,ye=ie[we];if(ye){for(var me=0,je=Object.keys(ve);me<je.length;me++){var Ee=je[me],ke=ve[Ee];if(Ee===E.schema.primKey.keyPath){if(mt(ke,ue)!==0)throw new J.Constraint("Cannot update primary key in bulkUpdate()")}else S(ye,Ee,ke)}V.push(we),ce.push(ue),de.push(ye)}});var ge=ce.length;return A.mutate({trans:Y,type:"put",keys:ce,values:de,updates:{keys:N,changeSpecs:M}}).then(function(oe){var we=oe.numFailures,ue=oe.failures;if(we===0)return ge;for(var ve=0,ye=Object.keys(ue);ve<ye.length;ve++){var me,je=ye[ve],Ee=V[Number(je)];Ee!=null&&(me=ue[je],delete ue[je],ue[Ee]=me)}throw new G("".concat(E.name,".bulkUpdate(): ").concat(we," of ").concat(ge," operations failed"),ue)})})})},kt.prototype.bulkDelete=function(C){var E=this,A=C.length;return this._trans("readwrite",function(N){return E.core.mutate({trans:N,type:"delete",keys:C})}).then(function(Y){var M=Y.numFailures,V=Y.lastResult,Y=Y.failures;if(M===0)return V;throw new G("".concat(E.name,".bulkDelete(): ").concat(M," of ").concat(A," operations failed"),Y)})},kt);function kt(){}function ee(C){function E(Y,ie){if(ie){for(var ce=arguments.length,de=new Array(ce-1);--ce;)de[ce-1]=arguments[ce];return A[Y].subscribe.apply(null,de),C}if(typeof Y=="string")return A[Y]}var A={};E.addEventType=V;for(var N=1,M=arguments.length;N<M;++N)V(arguments[N]);return E;function V(Y,ie,ce){if(typeof Y!="object"){var de;ie=ie||le;var ge={subscribers:[],fire:ce=ce||Le,subscribe:function(oe){ge.subscribers.indexOf(oe)===-1&&(ge.subscribers.push(oe),ge.fire=ie(ge.fire,oe))},unsubscribe:function(oe){ge.subscribers=ge.subscribers.filter(function(we){return we!==oe}),ge.fire=ge.subscribers.reduce(ie,ce)}};return A[Y]=E[Y]=ge}a(de=Y).forEach(function(oe){var we=de[oe];if(o(we))V(oe,de[oe][0],de[oe][1]);else{if(we!=="asap")throw new J.InvalidArgument("Invalid event config");var ue=V(oe,$e,function(){for(var ve=arguments.length,ye=new Array(ve);ve--;)ye[ve]=arguments[ve];ue.subscribers.forEach(function(me){w(function(){me.apply(null,ye)})})})}})}}function I(C,E){return f(E).from({prototype:C}),E}function P(C,E){return!(C.filter||C.algorithm||C.or)&&(E?C.justLimit:!C.replayFilter)}function Z(C,E){C.filter=cr(C.filter,E)}function X(C,E,A){var N=C.replayFilter;C.replayFilter=N?function(){return cr(N(),E())}:E,C.justLimit=A&&!N}function Fe(C,E){if(C.isPrimKey)return E.primaryKey;var A=E.getIndexByKeyPath(C.index);if(!A)throw new J.Schema("KeyPath "+C.index+" on object store "+E.name+" is not indexed");return A}function Ve(C,E,A){var N=Fe(C,E.schema);return E.openCursor({trans:A,values:!C.keysOnly,reverse:C.dir==="prev",unique:!!C.unique,query:{index:N,range:C.range}})}function Ne(C,E,A,N){var M=C.replayFilter?cr(C.filter,C.replayFilter()):C.filter;if(C.or){var V={},Y=function(ie,ce,de){var ge,oe;M&&!M(ce,de,function(we){return ce.stop(we)},function(we){return ce.fail(we)})||((oe=""+(ge=ce.primaryKey))=="[object ArrayBuffer]"&&(oe=""+new Uint8Array(ge)),l(V,oe)||(V[oe]=!0,E(ie,ce,de)))};return Promise.all([C.or._iterate(Y,A),qe(Ve(C,N,A),C.algorithm,Y,!C.keysOnly&&C.valueMapper)])}return qe(Ve(C,N,A),cr(C.algorithm,M),E,!C.keysOnly&&C.valueMapper)}function qe(C,E,A,N){var M=dt(N?function(V,Y,ie){return A(N(V),Y,ie)}:A);return C.then(function(V){if(V)return V.start(function(){var Y=function(){return V.continue()};E&&!E(V,function(ie){return Y=ie},function(ie){V.stop(ie),Y=Le},function(ie){V.fail(ie),Y=Le})||M(V.value,V,function(ie){return Y=ie}),Y()})})}var at=(Ct.prototype.execute=function(C){var E=this["@@propmod"];if(E.add!==void 0){var A=E.add;if(o(A))return u(u([],o(C)?C:[],!0),A).sort();if(typeof A=="number")return(Number(C)||0)+A;if(typeof A=="bigint")try{return BigInt(C)+A}catch{return BigInt(0)+A}throw new TypeError("Invalid term ".concat(A))}if(E.remove!==void 0){var N=E.remove;if(o(N))return o(C)?C.filter(function(M){return!N.includes(M)}).sort():[];if(typeof N=="number")return Number(C)-N;if(typeof N=="bigint")try{return BigInt(C)-N}catch{return BigInt(0)-N}throw new TypeError("Invalid subtrahend ".concat(N))}return A=(A=E.replacePrefix)===null||A===void 0?void 0:A[0],A&&typeof C=="string"&&C.startsWith(A)?E.replacePrefix[1]+C.substring(A.length):C},Ct);function Ct(C){this["@@propmod"]=C}var fr=(yt.prototype._read=function(C,E){var A=this._ctx;return A.error?A.table._trans(null,Tt.bind(null,A.error)):A.table._trans("readonly",C).then(E)},yt.prototype._write=function(C){var E=this._ctx;return E.error?E.table._trans(null,Tt.bind(null,E.error)):E.table._trans("readwrite",C,"locked")},yt.prototype._addAlgorithm=function(C){var E=this._ctx;E.algorithm=cr(E.algorithm,C)},yt.prototype._iterate=function(C,E){return Ne(this._ctx,C,E,this._ctx.table.core)},yt.prototype.clone=function(C){var E=Object.create(this.constructor.prototype),A=Object.create(this._ctx);return C&&c(A,C),E._ctx=A,E},yt.prototype.raw=function(){return this._ctx.valueMapper=null,this},yt.prototype.each=function(C){var E=this._ctx;return this._read(function(A){return Ne(E,C,A,E.table.core)})},yt.prototype.count=function(C){var E=this;return this._read(function(A){var N=E._ctx,M=N.table.core;if(P(N,!0))return M.count({trans:A,query:{index:Fe(N,M.schema),range:N.range}}).then(function(Y){return Math.min(Y,N.limit)});var V=0;return Ne(N,function(){return++V,!1},A,M).then(function(){return V})}).then(C)},yt.prototype.sortBy=function(C,E){var A=C.split(".").reverse(),N=A[0],M=A.length-1;function V(ce,de){return de?V(ce[A[de]],de-1):ce[N]}var Y=this._ctx.dir==="next"?1:-1;function ie(ce,de){return mt(V(ce,M),V(de,M))*Y}return this.toArray(function(ce){return ce.sort(ie)}).then(E)},yt.prototype.toArray=function(C){var E=this;return this._read(function(A){var N=E._ctx;if(N.dir==="next"&&P(N,!0)&&0<N.limit){var M=N.valueMapper,V=Fe(N,N.table.core.schema);return N.table.core.query({trans:A,limit:N.limit,values:!0,query:{index:V,range:N.range}}).then(function(ie){return ie=ie.result,M?ie.map(M):ie})}var Y=[];return Ne(N,function(ie){return Y.push(ie)},A,N.table.core).then(function(){return Y})},C)},yt.prototype.offset=function(C){var E=this._ctx;return C<=0||(E.offset+=C,P(E)?X(E,function(){var A=C;return function(N,M){return A===0||(A===1?--A:M(function(){N.advance(A),A=0}),!1)}}):X(E,function(){var A=C;return function(){return--A<0}})),this},yt.prototype.limit=function(C){return this._ctx.limit=Math.min(this._ctx.limit,C),X(this._ctx,function(){var E=C;return function(A,N,M){return--E<=0&&N(M),0<=E}},!0),this},yt.prototype.until=function(C,E){return Z(this._ctx,function(A,N,M){return!C(A.value)||(N(M),E)}),this},yt.prototype.first=function(C){return this.limit(1).toArray(function(E){return E[0]}).then(C)},yt.prototype.last=function(C){return this.reverse().first(C)},yt.prototype.filter=function(C){var E;return Z(this._ctx,function(A){return C(A.value)}),(E=this._ctx).isMatch=cr(E.isMatch,C),this},yt.prototype.and=function(C){return this.filter(C)},yt.prototype.or=function(C){return new this.db.WhereClause(this._ctx.table,C,this)},yt.prototype.reverse=function(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},yt.prototype.desc=function(){return this.reverse()},yt.prototype.eachKey=function(C){var E=this._ctx;return E.keysOnly=!E.isMatch,this.each(function(A,N){C(N.key,N)})},yt.prototype.eachUniqueKey=function(C){return this._ctx.unique="unique",this.eachKey(C)},yt.prototype.eachPrimaryKey=function(C){var E=this._ctx;return E.keysOnly=!E.isMatch,this.each(function(A,N){C(N.primaryKey,N)})},yt.prototype.keys=function(C){var E=this._ctx;E.keysOnly=!E.isMatch;var A=[];return this.each(function(N,M){A.push(M.key)}).then(function(){return A}).then(C)},yt.prototype.primaryKeys=function(C){var E=this._ctx;if(E.dir==="next"&&P(E,!0)&&0<E.limit)return this._read(function(N){var M=Fe(E,E.table.core.schema);return E.table.core.query({trans:N,values:!1,limit:E.limit,query:{index:M,range:E.range}})}).then(function(N){return N.result}).then(C);E.keysOnly=!E.isMatch;var A=[];return this.each(function(N,M){A.push(M.primaryKey)}).then(function(){return A}).then(C)},yt.prototype.uniqueKeys=function(C){return this._ctx.unique="unique",this.keys(C)},yt.prototype.firstKey=function(C){return this.limit(1).keys(function(E){return E[0]}).then(C)},yt.prototype.lastKey=function(C){return this.reverse().firstKey(C)},yt.prototype.distinct=function(){var C=this._ctx,C=C.index&&C.table.schema.idxByName[C.index];if(!C||!C.multi)return this;var E={};return Z(this._ctx,function(M){var N=M.primaryKey.toString(),M=l(E,N);return E[N]=!0,!M}),this},yt.prototype.modify=function(C){var E=this,A=this._ctx;return this._write(function(N){var M,V,Y;Y=typeof C=="function"?C:(M=a(C),V=M.length,function(me){for(var je=!1,Ee=0;Ee<V;++Ee){var ke=M[Ee],Re=C[ke],We=x(me,ke);Re instanceof at?(S(me,ke,Re.execute(We)),je=!0):We!==Re&&(S(me,ke,Re),je=!0)}return je});var ie=A.table.core,oe=ie.schema.primaryKey,ce=oe.outbound,de=oe.extractKey,ge=200,oe=E.db._options.modifyChunkSize;oe&&(ge=typeof oe=="object"?oe[ie.name]||oe["*"]||200:oe);function we(me,ke){var Ee=ke.failures,ke=ke.numFailures;ve+=me-ke;for(var Re=0,We=a(Ee);Re<We.length;Re++){var Ke=We[Re];ue.push(Ee[Ke])}}var ue=[],ve=0,ye=[];return E.clone().primaryKeys().then(function(me){function je(ke){var Re=Math.min(ge,me.length-ke);return ie.getMany({trans:N,keys:me.slice(ke,ke+Re),cache:"immutable"}).then(function(We){for(var Ke=[],Ze=[],Ge=ce?[]:null,Je=[],He=0;He<Re;++He){var rt=We[He],pt={value:F(rt),primKey:me[ke+He]};Y.call(pt,pt.value,pt)!==!1&&(pt.value==null?Je.push(me[ke+He]):ce||mt(de(rt),de(pt.value))===0?(Ze.push(pt.value),ce&&Ge.push(me[ke+He])):(Je.push(me[ke+He]),Ke.push(pt.value)))}return Promise.resolve(0<Ke.length&&ie.mutate({trans:N,type:"add",values:Ke}).then(function(wt){for(var St in wt.failures)Je.splice(parseInt(St),1);we(Ke.length,wt)})).then(function(){return(0<Ze.length||Ee&&typeof C=="object")&&ie.mutate({trans:N,type:"put",keys:Ge,values:Ze,criteria:Ee,changeSpec:typeof C!="function"&&C,isAdditionalChunk:0<ke}).then(function(wt){return we(Ze.length,wt)})}).then(function(){return(0<Je.length||Ee&&C===bn)&&ie.mutate({trans:N,type:"delete",keys:Je,criteria:Ee,isAdditionalChunk:0<ke}).then(function(wt){return we(Je.length,wt)})}).then(function(){return me.length>ke+Re&&je(ke+ge)})})}var Ee=P(A)&&A.limit===1/0&&(typeof C!="function"||C===bn)&&{index:A.index,range:A.range};return je(0).then(function(){if(0<ue.length)throw new se("Error modifying one or more objects",ue,ve,ye);return me.length})})})},yt.prototype.delete=function(){var C=this._ctx,E=C.range;return P(C)&&(C.isPrimKey||E.type===3)?this._write(function(A){var N=C.table.core.schema.primaryKey,M=E;return C.table.core.count({trans:A,query:{index:N,range:M}}).then(function(V){return C.table.core.mutate({trans:A,type:"deleteRange",range:M}).then(function(Y){var ie=Y.failures;if(Y.lastResult,Y.results,Y=Y.numFailures,Y)throw new se("Could not delete some values",Object.keys(ie).map(function(ce){return ie[ce]}),V-Y);return V-Y})})}):this.modify(bn)},yt);function yt(){}var bn=function(C,E){return E.value=null};function qn(C,E){return C<E?-1:C===E?0:1}function Qn(C,E){return E<C?-1:C===E?0:1}function Yt(C,E,A){return C=C instanceof Bs?new C.Collection(C):C,C._ctx.error=new(A||TypeError)(E),C}function Zr(C){return new C.Collection(C,function(){return Ms("")}).limit(0)}function Rn(C,E,A,N){var M,V,Y,ie,ce,de,ge,oe=A.length;if(!A.every(function(ve){return typeof ve=="string"}))return Yt(C,Wr);function we(ve){M=ve==="next"?function(me){return me.toUpperCase()}:function(me){return me.toLowerCase()},V=ve==="next"?function(me){return me.toLowerCase()}:function(me){return me.toUpperCase()},Y=ve==="next"?qn:Qn;var ye=A.map(function(me){return{lower:V(me),upper:M(me)}}).sort(function(me,je){return Y(me.lower,je.lower)});ie=ye.map(function(me){return me.upper}),ce=ye.map(function(me){return me.lower}),ge=(de=ve)==="next"?"":N}we("next"),C=new C.Collection(C,function(){return Gr(ie[0],ce[oe-1]+N)}),C._ondirectionchange=function(ve){we(ve)};var ue=0;return C._addAlgorithm(function(ve,ye,me){var je=ve.key;if(typeof je!="string")return!1;var Ee=V(je);if(E(Ee,ce,ue))return!0;for(var ke=null,Re=ue;Re<oe;++Re){var We=function(Ke,Ze,Ge,Je,He,rt){for(var pt=Math.min(Ke.length,Je.length),wt=-1,St=0;St<pt;++St){var pr=Ze[St];if(pr!==Je[St])return He(Ke[St],Ge[St])<0?Ke.substr(0,St)+Ge[St]+Ge.substr(St+1):He(Ke[St],Je[St])<0?Ke.substr(0,St)+Je[St]+Ge.substr(St+1):0<=wt?Ke.substr(0,wt)+Ze[wt]+Ge.substr(wt+1):null;He(Ke[St],pr)<0&&(wt=St)}return pt<Je.length&&rt==="next"?Ke+Ge.substr(Ke.length):pt<Ke.length&&rt==="prev"?Ke.substr(0,Ge.length):wt<0?null:Ke.substr(0,wt)+Je[wt]+Ge.substr(wt+1)}(je,Ee,ie[Re],ce[Re],Y,de);We===null&&ke===null?ue=Re+1:(ke===null||0<Y(ke,We))&&(ke=We)}return ye(ke!==null?function(){ve.continue(ke+ge)}:me),!1}),C}function Gr(C,E,A,N){return{type:2,lower:C,upper:E,lowerOpen:A,upperOpen:N}}function Ms(C){return{type:1,lower:C,upper:C}}var Bs=(Object.defineProperty(Zt.prototype,"Collection",{get:function(){return this._ctx.table.db.Collection},enumerable:!1,configurable:!0}),Zt.prototype.between=function(C,E,A,N){A=A!==!1,N=N===!0;try{return 0<this._cmp(C,E)||this._cmp(C,E)===0&&(A||N)&&(!A||!N)?Zr(this):new this.Collection(this,function(){return Gr(C,E,!A,!N)})}catch{return Yt(this,Xt)}},Zt.prototype.equals=function(C){return C==null?Yt(this,Xt):new this.Collection(this,function(){return Ms(C)})},Zt.prototype.above=function(C){return C==null?Yt(this,Xt):new this.Collection(this,function(){return Gr(C,void 0,!0)})},Zt.prototype.aboveOrEqual=function(C){return C==null?Yt(this,Xt):new this.Collection(this,function(){return Gr(C,void 0,!1)})},Zt.prototype.below=function(C){return C==null?Yt(this,Xt):new this.Collection(this,function(){return Gr(void 0,C,!1,!0)})},Zt.prototype.belowOrEqual=function(C){return C==null?Yt(this,Xt):new this.Collection(this,function(){return Gr(void 0,C)})},Zt.prototype.startsWith=function(C){return typeof C!="string"?Yt(this,Wr):this.between(C,C+lr,!0,!0)},Zt.prototype.startsWithIgnoreCase=function(C){return C===""?this.startsWith(C):Rn(this,function(E,A){return E.indexOf(A[0])===0},[C],lr)},Zt.prototype.equalsIgnoreCase=function(C){return Rn(this,function(E,A){return E===A[0]},[C],"")},Zt.prototype.anyOfIgnoreCase=function(){var C=B.apply($,arguments);return C.length===0?Zr(this):Rn(this,function(E,A){return A.indexOf(E)!==-1},C,"")},Zt.prototype.startsWithAnyOfIgnoreCase=function(){var C=B.apply($,arguments);return C.length===0?Zr(this):Rn(this,function(E,A){return A.some(function(N){return E.indexOf(N)===0})},C,lr)},Zt.prototype.anyOf=function(){var C=this,E=B.apply($,arguments),A=this._cmp;try{E.sort(A)}catch{return Yt(this,Xt)}if(E.length===0)return Zr(this);var N=new this.Collection(this,function(){return Gr(E[0],E[E.length-1])});N._ondirectionchange=function(V){A=V==="next"?C._ascending:C._descending,E.sort(A)};var M=0;return N._addAlgorithm(function(V,Y,ie){for(var ce=V.key;0<A(ce,E[M]);)if(++M===E.length)return Y(ie),!1;return A(ce,E[M])===0||(Y(function(){V.continue(E[M])}),!1)}),N},Zt.prototype.notEqual=function(C){return this.inAnyRange([[-1/0,C],[C,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})},Zt.prototype.noneOf=function(){var C=B.apply($,arguments);if(C.length===0)return new this.Collection(this);try{C.sort(this._ascending)}catch{return Yt(this,Xt)}var E=C.reduce(function(A,N){return A?A.concat([[A[A.length-1][1],N]]):[[-1/0,N]]},null);return E.push([C[C.length-1],this.db._maxKey]),this.inAnyRange(E,{includeLowers:!1,includeUppers:!1})},Zt.prototype.inAnyRange=function(je,E){var A=this,N=this._cmp,M=this._ascending,V=this._descending,Y=this._min,ie=this._max;if(je.length===0)return Zr(this);if(!je.every(function(Ee){return Ee[0]!==void 0&&Ee[1]!==void 0&&M(Ee[0],Ee[1])<=0}))return Yt(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",J.InvalidArgument);var ce=!E||E.includeLowers!==!1,de=E&&E.includeUppers===!0,ge,oe=M;function we(Ee,ke){return oe(Ee[0],ke[0])}try{(ge=je.reduce(function(Ee,ke){for(var Re=0,We=Ee.length;Re<We;++Re){var Ke=Ee[Re];if(N(ke[0],Ke[1])<0&&0<N(ke[1],Ke[0])){Ke[0]=Y(Ke[0],ke[0]),Ke[1]=ie(Ke[1],ke[1]);break}}return Re===We&&Ee.push(ke),Ee},[])).sort(we)}catch{return Yt(this,Xt)}var ue=0,ve=de?function(Ee){return 0<M(Ee,ge[ue][1])}:function(Ee){return 0<=M(Ee,ge[ue][1])},ye=ce?function(Ee){return 0<V(Ee,ge[ue][0])}:function(Ee){return 0<=V(Ee,ge[ue][0])},me=ve,je=new this.Collection(this,function(){return Gr(ge[0][0],ge[ge.length-1][1],!ce,!de)});return je._ondirectionchange=function(Ee){oe=Ee==="next"?(me=ve,M):(me=ye,V),ge.sort(we)},je._addAlgorithm(function(Ee,ke,Re){for(var We,Ke=Ee.key;me(Ke);)if(++ue===ge.length)return ke(Re),!1;return!ve(We=Ke)&&!ye(We)||(A._cmp(Ke,ge[ue][1])===0||A._cmp(Ke,ge[ue][0])===0||ke(function(){oe===M?Ee.continue(ge[ue][0]):Ee.continue(ge[ue][1])}),!1)}),je},Zt.prototype.startsWithAnyOf=function(){var C=B.apply($,arguments);return C.every(function(E){return typeof E=="string"})?C.length===0?Zr(this):this.inAnyRange(C.map(function(E){return[E,E+lr]})):Yt(this,"startsWithAnyOf() only works with strings")},Zt);function Zt(){}function Sr(C){return dt(function(E){return yn(E),C(E.target.error),!1})}function yn(C){C.stopPropagation&&C.stopPropagation(),C.preventDefault&&C.preventDefault()}var _n="storagemutated",es="x-storagemutated-1",Hr=ee(null,_n),Di=(xr.prototype._lock=function(){return _(!ze.global),++this._reculock,this._reculock!==1||ze.global||(ze.lockOwnerFor=this),this},xr.prototype._unlock=function(){if(_(!ze.global),--this._reculock==0)for(ze.global||(ze.lockOwnerFor=null);0<this._blockedFuncs.length&&!this._locked();){var C=this._blockedFuncs.shift();try{ar(C[1],C[0])}catch{}}return this},xr.prototype._locked=function(){return this._reculock&&ze.lockOwnerFor!==this},xr.prototype.create=function(C){var E=this;if(!this.mode)return this;var A=this.db.idbdb,N=this.db._state.dbOpenError;if(_(!this.idbtrans),!C&&!A)switch(N&&N.name){case"DatabaseClosedError":throw new J.DatabaseClosed(N);case"MissingAPIError":throw new J.MissingAPI(N.message,N);default:throw new J.OpenFailed(N)}if(!this.active)throw new J.TransactionInactive;return _(this._completion._state===null),(C=this.idbtrans=C||(this.db.core||A).transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability})).onerror=dt(function(M){yn(M),E._reject(C.error)}),C.onabort=dt(function(M){yn(M),E.active&&E._reject(new J.Abort(C.error)),E.active=!1,E.on("abort").fire(M)}),C.oncomplete=dt(function(){E.active=!1,E._resolve(),"mutatedParts"in C&&Hr.storagemutated.fire(C.mutatedParts)}),this},xr.prototype._promise=function(C,E,A){var N=this;if(C==="readwrite"&&this.mode!=="readwrite")return Tt(new J.ReadOnly("Transaction is readonly"));if(!this.active)return Tt(new J.TransactionInactive);if(this._locked())return new Te(function(V,Y){N._blockedFuncs.push([function(){N._promise(C,E,A).then(V,Y)},ze])});if(A)return er(function(){var V=new Te(function(Y,ie){N._lock();var ce=E(Y,ie,N);ce&&ce.then&&ce.then(Y,ie)});return V.finally(function(){return N._unlock()}),V._lib=!0,V});var M=new Te(function(V,Y){var ie=E(V,Y,N);ie&&ie.then&&ie.then(V,Y)});return M._lib=!0,M},xr.prototype._root=function(){return this.parent?this.parent._root():this},xr.prototype.waitFor=function(C){var E,A=this._root(),N=Te.resolve(C);A._waitingFor?A._waitingFor=A._waitingFor.then(function(){return N}):(A._waitingFor=N,A._waitingQueue=[],E=A.idbtrans.objectStore(A.storeNames[0]),function V(){for(++A._spinCount;A._waitingQueue.length;)A._waitingQueue.shift()();A._waitingFor&&(E.get(-1/0).onsuccess=V)}());var M=A._waitingFor;return new Te(function(V,Y){N.then(function(ie){return A._waitingQueue.push(dt(V.bind(null,ie)))},function(ie){return A._waitingQueue.push(dt(Y.bind(null,ie)))}).finally(function(){A._waitingFor===M&&(A._waitingFor=null)})})},xr.prototype.abort=function(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new J.Abort))},xr.prototype.table=function(C){var E=this._memoizedTables||(this._memoizedTables={});if(l(E,C))return E[C];var A=this.schema[C];if(!A)throw new J.NotFound("Table "+C+" not part of transaction");return A=new this.db.Table(C,A,this),A.core=this.db.core.table(C),E[C]=A},xr);function xr(){}function ts(C,E,A,N,M,V,Y){return{name:C,keyPath:E,unique:A,multi:N,auto:M,compound:V,src:(A&&!Y?"&":"")+(N?"*":"")+(M?"++":"")+$s(E)}}function $s(C){return typeof C=="string"?C:C?"["+[].join.call(C,"+")+"]":""}function rs(C,E,A){return{name:C,primKey:E,indexes:A,mappedClass:null,idxByName:(N=function(M){return[M.name,M]},A.reduce(function(M,V,Y){return Y=N(V,Y),Y&&(M[Y[0]]=Y[1]),M},{}))};var N}var wn=function(C){try{return C.only([[]]),wn=function(){return[[]]},[[]]}catch{return wn=function(){return lr},lr}};function ns(C){return C==null?function(){}:typeof C=="string"?(E=C).split(".").length===1?function(A){return A[E]}:function(A){return x(A,E)}:function(A){return x(A,C)};var E}function Fs(C){return[].slice.call(C)}var Mi=0;function Sn(C){return C==null?":id":typeof C=="string"?C:"[".concat(C.join("+"),"]")}function Bi(C,E,ce){function N(me){if(me.type===3)return null;if(me.type===4)throw new Error("Cannot convert never type to IDBKeyRange");var ue=me.lower,ve=me.upper,ye=me.lowerOpen,me=me.upperOpen;return ue===void 0?ve===void 0?null:E.upperBound(ve,!!me):ve===void 0?E.lowerBound(ue,!!ye):E.bound(ue,ve,!!ye,!!me)}function M(we){var ue,ve=we.name;return{name:ve,schema:we,mutate:function(ye){var me=ye.trans,je=ye.type,Ee=ye.keys,ke=ye.values,Re=ye.range;return new Promise(function(We,Ke){We=dt(We);var Ze=me.objectStore(ve),Ge=Ze.keyPath==null,Je=je==="put"||je==="add";if(!Je&&je!=="delete"&&je!=="deleteRange")throw new Error("Invalid operation type: "+je);var He,rt=(Ee||ke||{length:1}).length;if(Ee&&ke&&Ee.length!==ke.length)throw new Error("Given keys array must have same length as given values array.");if(rt===0)return We({numFailures:0,failures:{},results:[],lastResult:void 0});function pt(ur){++pr,yn(ur)}var wt=[],St=[],pr=0;if(je==="deleteRange"){if(Re.type===4)return We({numFailures:pr,failures:St,results:[],lastResult:void 0});Re.type===3?wt.push(He=Ze.clear()):wt.push(He=Ze.delete(N(Re)))}else{var Ge=Je?Ge?[ke,Ee]:[ke,null]:[Ee,null],ft=Ge[0],sr=Ge[1];if(Je)for(var ir=0;ir<rt;++ir)wt.push(He=sr&&sr[ir]!==void 0?Ze[je](ft[ir],sr[ir]):Ze[je](ft[ir])),He.onerror=pt;else for(ir=0;ir<rt;++ir)wt.push(He=Ze[je](ft[ir])),He.onerror=pt}function Xs(ur){ur=ur.target.result,wt.forEach(function(jn,no){return jn.error!=null&&(St[no]=jn.error)}),We({numFailures:pr,failures:St,results:je==="delete"?Ee:wt.map(function(jn){return jn.result}),lastResult:ur})}He.onerror=function(ur){pt(ur),Xs(ur)},He.onsuccess=Xs})},getMany:function(ye){var me=ye.trans,je=ye.keys;return new Promise(function(Ee,ke){Ee=dt(Ee);for(var Re,We=me.objectStore(ve),Ke=je.length,Ze=new Array(Ke),Ge=0,Je=0,He=function(wt){wt=wt.target,Ze[wt._pos]=wt.result,++Je===Ge&&Ee(Ze)},rt=Sr(ke),pt=0;pt<Ke;++pt)je[pt]!=null&&((Re=We.get(je[pt]))._pos=pt,Re.onsuccess=He,Re.onerror=rt,++Ge);Ge===0&&Ee(Ze)})},get:function(ye){var me=ye.trans,je=ye.key;return new Promise(function(Ee,ke){Ee=dt(Ee);var Re=me.objectStore(ve).get(je);Re.onsuccess=function(We){return Ee(We.target.result)},Re.onerror=Sr(ke)})},query:(ue=de,function(ye){return new Promise(function(me,je){me=dt(me);var Ee,ke,Re,Ge=ye.trans,We=ye.values,Ke=ye.limit,He=ye.query,Ze=Ke===1/0?void 0:Ke,Je=He.index,He=He.range,Ge=Ge.objectStore(ve),Je=Je.isPrimaryKey?Ge:Ge.index(Je.name),He=N(He);if(Ke===0)return me({result:[]});ue?((Ze=We?Je.getAll(He,Ze):Je.getAllKeys(He,Ze)).onsuccess=function(rt){return me({result:rt.target.result})},Ze.onerror=Sr(je)):(Ee=0,ke=!We&&"openKeyCursor"in Je?Je.openKeyCursor(He):Je.openCursor(He),Re=[],ke.onsuccess=function(rt){var pt=ke.result;return pt?(Re.push(We?pt.value:pt.primaryKey),++Ee===Ke?me({result:Re}):void pt.continue()):me({result:Re})},ke.onerror=Sr(je))})}),openCursor:function(ye){var me=ye.trans,je=ye.values,Ee=ye.query,ke=ye.reverse,Re=ye.unique;return new Promise(function(We,Ke){We=dt(We);var Je=Ee.index,Ze=Ee.range,Ge=me.objectStore(ve),Ge=Je.isPrimaryKey?Ge:Ge.index(Je.name),Je=ke?Re?"prevunique":"prev":Re?"nextunique":"next",He=!je&&"openKeyCursor"in Ge?Ge.openKeyCursor(N(Ze),Je):Ge.openCursor(N(Ze),Je);He.onerror=Sr(Ke),He.onsuccess=dt(function(rt){var pt,wt,St,pr,ft=He.result;ft?(ft.___id=++Mi,ft.done=!1,pt=ft.continue.bind(ft),wt=(wt=ft.continuePrimaryKey)&&wt.bind(ft),St=ft.advance.bind(ft),pr=function(){throw new Error("Cursor not stopped")},ft.trans=me,ft.stop=ft.continue=ft.continuePrimaryKey=ft.advance=function(){throw new Error("Cursor not started")},ft.fail=dt(Ke),ft.next=function(){var sr=this,ir=1;return this.start(function(){return ir--?sr.continue():sr.stop()}).then(function(){return sr})},ft.start=function(sr){function ir(){if(He.result)try{sr()}catch(ur){ft.fail(ur)}else ft.done=!0,ft.start=function(){throw new Error("Cursor behind last entry")},ft.stop()}var Xs=new Promise(function(ur,jn){ur=dt(ur),He.onerror=Sr(jn),ft.fail=jn,ft.stop=function(no){ft.stop=ft.continue=ft.continuePrimaryKey=ft.advance=pr,ur(no)}});return He.onsuccess=dt(function(ur){He.onsuccess=ir,ir()}),ft.continue=pt,ft.continuePrimaryKey=wt,ft.advance=St,ir(),Xs},We(ft)):We(null)},Ke)})},count:function(ye){var me=ye.query,je=ye.trans,Ee=me.index,ke=me.range;return new Promise(function(Re,We){var Ke=je.objectStore(ve),Ze=Ee.isPrimaryKey?Ke:Ke.index(Ee.name),Ke=N(ke),Ze=Ke?Ze.count(Ke):Ze.count();Ze.onsuccess=dt(function(Ge){return Re(Ge.target.result)}),Ze.onerror=Sr(We)})}}}var V,Y,ie,ge=(Y=ce,ie=Fs((V=C).objectStoreNames),{schema:{name:V.name,tables:ie.map(function(we){return Y.objectStore(we)}).map(function(we){var ue=we.keyPath,me=we.autoIncrement,ve=o(ue),ye={},me={name:we.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:ue==null,compound:ve,keyPath:ue,autoIncrement:me,unique:!0,extractKey:ns(ue)},indexes:Fs(we.indexNames).map(function(je){return we.index(je)}).map(function(Re){var Ee=Re.name,ke=Re.unique,We=Re.multiEntry,Re=Re.keyPath,We={name:Ee,compound:o(Re),keyPath:Re,unique:ke,multiEntry:We,extractKey:ns(Re)};return ye[Sn(Re)]=We}),getIndexByKeyPath:function(je){return ye[Sn(je)]}};return ye[":id"]=me.primaryKey,ue!=null&&(ye[Sn(ue)]=me.primaryKey),me})},hasGetAll:0<ie.length&&"getAll"in Y.objectStore(ie[0])&&!(typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}),ce=ge.schema,de=ge.hasGetAll,ge=ce.tables.map(M),oe={};return ge.forEach(function(we){return oe[we.name]=we}),{stack:"dbcore",transaction:C.transaction.bind(C),table:function(we){if(!oe[we])throw new Error("Table '".concat(we,"' not found"));return oe[we]},MIN_KEY:-1/0,MAX_KEY:wn(E),schema:ce}}function $i(C,E,A,N){var M=A.IDBKeyRange;return A.indexedDB,{dbcore:(N=Bi(E,M,N),C.dbcore.reduce(function(V,Y){return Y=Y.create,s(s({},V),Y(V))},N))}}function Ln(C,N){var A=N.db,N=$i(C._middlewares,A,C._deps,N);C.core=N.dbcore,C.tables.forEach(function(M){var V=M.name;C.core.schema.tables.some(function(Y){return Y.name===V})&&(M.core=C.core.table(V),C[V]instanceof C.Table&&(C[V].core=M.core))})}function Nn(C,E,A,N){A.forEach(function(M){var V=N[M];E.forEach(function(Y){var ie=function ce(de,ge){return v(de,ge)||(de=i(de))&&ce(de,ge)}(Y,M);(!ie||"value"in ie&&ie.value===void 0)&&(Y===C.Transaction.prototype||Y instanceof C.Transaction?m(Y,M,{get:function(){return this.table(M)},set:function(ce){p(this,M,{value:ce,writable:!0,configurable:!0,enumerable:!0})}}):Y[M]=new C.Table(M,V))})})}function ss(C,E){E.forEach(function(A){for(var N in A)A[N]instanceof C.Table&&delete A[N]})}function Fi(C,E){return C._cfg.version-E._cfg.version}function Vi(C,E,A,N){var M=C._dbSchema;A.objectStoreNames.contains("$meta")&&!M.$meta&&(M.$meta=rs("$meta",Cr("")[0],[]),C._storeNames.push("$meta"));var V=C._createTransaction("readwrite",C._storeNames,M);V.create(A),V._completion.catch(N);var Y=V._reject.bind(V),ie=ze.transless||ze;er(function(){return ze.trans=V,ze.transless=ie,E!==0?(Ln(C,A),de=E,((ce=V).storeNames.includes("$meta")?ce.table("$meta").get("version").then(function(ge){return ge??de}):Te.resolve(de)).then(function(ge){return we=ge,ue=V,ve=A,ye=[],ge=(oe=C)._versions,me=oe._dbSchema=Nr(0,oe.idbdb,ve),(ge=ge.filter(function(je){return je._cfg.version>=we})).length!==0?(ge.forEach(function(je){ye.push(function(){var Ee=me,ke=je._cfg.dbschema;Pr(oe,Ee,ve),Pr(oe,ke,ve),me=oe._dbSchema=ke;var Re=is(Ee,ke);Re.add.forEach(function(Je){os(ve,Je[0],Je[1].primKey,Je[1].indexes)}),Re.change.forEach(function(Je){if(Je.recreate)throw new J.Upgrade("Not yet support for changing primary key");var He=ve.objectStore(Je.name);Je.add.forEach(function(rt){return Pn(He,rt)}),Je.change.forEach(function(rt){He.deleteIndex(rt.name),Pn(He,rt)}),Je.del.forEach(function(rt){return He.deleteIndex(rt)})});var We=je._cfg.contentUpgrade;if(We&&je._cfg.version>we){Ln(oe,ve),ue._memoizedTables={};var Ke=j(ke);Re.del.forEach(function(Je){Ke[Je]=Ee[Je]}),ss(oe,[oe.Transaction.prototype]),Nn(oe,[oe.Transaction.prototype],a(Ke),Ke),ue.schema=Ke;var Ze,Ge=K(We);return Ge&&dr(),Re=Te.follow(function(){var Je;(Ze=We(ue))&&Ge&&(Je=tr.bind(null,null),Ze.then(Je,Je))}),Ze&&typeof Ze.then=="function"?Te.resolve(Ze):Re.then(function(){return Ze})}}),ye.push(function(Ee){var ke,Re,We=je._cfg.dbschema;ke=We,Re=Ee,[].slice.call(Re.db.objectStoreNames).forEach(function(Ke){return ke[Ke]==null&&Re.db.deleteObjectStore(Ke)}),ss(oe,[oe.Transaction.prototype]),Nn(oe,[oe.Transaction.prototype],oe._storeNames,oe._dbSchema),ue.schema=oe._dbSchema}),ye.push(function(Ee){oe.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(oe.idbdb.version/10)===je._cfg.version?(oe.idbdb.deleteObjectStore("$meta"),delete oe._dbSchema.$meta,oe._storeNames=oe._storeNames.filter(function(ke){return ke!=="$meta"})):Ee.objectStore("$meta").put(je._cfg.version,"version"))})}),function je(){return ye.length?Te.resolve(ye.shift()(ue.idbtrans)).then(je):Te.resolve()}().then(function(){Vs(me,ve)})):Te.resolve();var oe,we,ue,ve,ye,me}).catch(Y)):(a(M).forEach(function(ge){os(A,ge,M[ge].primKey,M[ge].indexes)}),Ln(C,A),void Te.follow(function(){return C.on.populate.fire(V)}).catch(Y));var ce,de})}function Ui(C,E){Vs(C._dbSchema,E),E.db.version%10!=0||E.objectStoreNames.contains("$meta")||E.db.createObjectStore("$meta").add(Math.ceil(E.db.version/10-1),"version");var A=Nr(0,C.idbdb,E);Pr(C,C._dbSchema,E);for(var N=0,M=is(A,C._dbSchema).change;N<M.length;N++){var V=function(Y){if(Y.change.length||Y.recreate)return console.warn("Unable to patch indexes of table ".concat(Y.name," because it has changes on the type of index or primary key.")),{value:void 0};var ie=E.objectStore(Y.name);Y.add.forEach(function(ce){xe&&console.debug("Dexie upgrade patch: Creating missing index ".concat(Y.name,".").concat(ce.src)),Pn(ie,ce)})}(M[N]);if(typeof V=="object")return V.value}}function is(C,E){var A,N={del:[],add:[],change:[]};for(A in C)E[A]||N.del.push(A);for(A in E){var M=C[A],V=E[A];if(M){var Y={name:A,def:V,recreate:!1,del:[],add:[],change:[]};if(""+(M.primKey.keyPath||"")!=""+(V.primKey.keyPath||"")||M.primKey.auto!==V.primKey.auto)Y.recreate=!0,N.change.push(Y);else{var ie=M.idxByName,ce=V.idxByName,de=void 0;for(de in ie)ce[de]||Y.del.push(de);for(de in ce){var ge=ie[de],oe=ce[de];ge?ge.src!==oe.src&&Y.change.push(oe):Y.add.push(oe)}(0<Y.del.length||0<Y.add.length||0<Y.change.length)&&N.change.push(Y)}}else N.add.push([A,V])}return N}function os(C,E,A,N){var M=C.db.createObjectStore(E,A.keyPath?{keyPath:A.keyPath,autoIncrement:A.auto}:{autoIncrement:A.auto});return N.forEach(function(V){return Pn(M,V)}),M}function Vs(C,E){a(C).forEach(function(A){E.db.objectStoreNames.contains(A)||(xe&&console.debug("Dexie: Creating missing table",A),os(E,A,C[A].primKey,C[A].indexes))})}function Pn(C,E){C.createIndex(E.name,E.keyPath,{unique:E.unique,multiEntry:E.multi})}function Nr(C,E,A){var N={};return b(E.objectStoreNames,0).forEach(function(M){for(var V=A.objectStore(M),Y=ts($s(de=V.keyPath),de||"",!0,!1,!!V.autoIncrement,de&&typeof de!="string",!0),ie=[],ce=0;ce<V.indexNames.length;++ce){var ge=V.index(V.indexNames[ce]),de=ge.keyPath,ge=ts(ge.name,de,!!ge.unique,!!ge.multiEntry,!1,de&&typeof de!="string",!1);ie.push(ge)}N[M]=rs(M,Y,ie)}),N}function Pr(C,E,A){for(var N=A.db.objectStoreNames,M=0;M<N.length;++M){var V=N[M],Y=A.objectStore(V);C._hasGetAll="getAll"in Y;for(var ie=0;ie<Y.indexNames.length;++ie){var ce=Y.indexNames[ie],de=Y.index(ce).keyPath,ge=typeof de=="string"?de:"["+b(de).join("+")+"]";!E[V]||(de=E[V].idxByName[ge])&&(de.name=ce,delete E[V].idxByName[ge],E[V].idxByName[ce]=de)}}typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&d.WorkerGlobalScope&&d instanceof d.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(C._hasGetAll=!1)}function Cr(C){return C.split(",").map(function(E,A){var N=(E=E.trim()).replace(/([&*]|\+\+)/g,""),M=/^\[/.test(N)?N.match(/^\[(.*)\]$/)[1].split("+"):N;return ts(N,M||null,/\&/.test(E),/\*/.test(E),/\+\+/.test(E),o(M),A===0)})}var Yr=(Us.prototype._parseStoresSpec=function(C,E){a(C).forEach(function(A){if(C[A]!==null){var N=Cr(C[A]),M=N.shift();if(M.unique=!0,M.multi)throw new J.Schema("Primary key cannot be multi-valued");N.forEach(function(V){if(V.auto)throw new J.Schema("Only primary key can be marked as autoIncrement (++)");if(!V.keyPath)throw new J.Schema("Index must have a name and cannot be an empty string")}),E[A]=rs(A,M,N)}})},Us.prototype.stores=function(A){var E=this.db;this._cfg.storesSource=this._cfg.storesSource?c(this._cfg.storesSource,A):A;var A=E._versions,N={},M={};return A.forEach(function(V){c(N,V._cfg.storesSource),M=V._cfg.dbschema={},V._parseStoresSpec(N,M)}),E._dbSchema=M,ss(E,[E._allTables,E,E.Transaction.prototype]),Nn(E,[E._allTables,E,E.Transaction.prototype,this._cfg.tables],a(M),M),E._storeNames=a(M),this},Us.prototype.upgrade=function(C){return this._cfg.contentUpgrade=_e(this._cfg.contentUpgrade||Le,C),this},Us);function Us(){}function Wi(C,E){var A=C._dbNamesDB;return A||(A=C._dbNamesDB=new Jr(_r,{addons:[],indexedDB:C,IDBKeyRange:E})).version(1).stores({dbnames:"name"}),A.table("dbnames")}function Zi(C){return C&&typeof C.databases=="function"}function Gi(C){return er(function(){return ze.letThrough=!0,C()})}function Hi(C){return!("from"in C)}var nr=function(C,E){if(!this){var A=new nr;return C&&"d"in C&&c(A,C),A}c(this,arguments.length?{d:1,from:C,to:1<arguments.length?E:C}:{d:0})};function as(C,E,A){var N=mt(E,A);if(!isNaN(N)){if(0<N)throw RangeError();if(Hi(C))return c(C,{from:E,to:A,d:1});var M=C.l,N=C.r;if(mt(A,C.from)<0)return M?as(M,E,A):C.l={from:E,to:A,d:1,l:null,r:null},Ma(C);if(0<mt(E,C.to))return N?as(N,E,A):C.r={from:E,to:A,d:1,l:null,r:null},Ma(C);mt(E,C.from)<0&&(C.from=E,C.l=null,C.d=N?N.d+1:1),0<mt(A,C.to)&&(C.to=A,C.r=null,C.d=C.l?C.l.d+1:1),A=!C.r,M&&!C.l&&ls(C,M),N&&A&&ls(C,N)}}function ls(C,E){Hi(E)||function A(N,ce){var V=ce.from,Y=ce.to,ie=ce.l,ce=ce.r;as(N,V,Y),ie&&A(N,ie),ce&&A(N,ce)}(C,E)}function Da(C,E){var A=Ws(E),N=A.next();if(N.done)return!1;for(var M=N.value,V=Ws(C),Y=V.next(M.from),ie=Y.value;!N.done&&!Y.done;){if(mt(ie.from,M.to)<=0&&0<=mt(ie.to,M.from))return!0;mt(M.from,ie.from)<0?M=(N=A.next(ie.from)).value:ie=(Y=V.next(M.from)).value}return!1}function Ws(C){var E=Hi(C)?null:{s:0,n:C};return{next:function(A){for(var N=0<arguments.length;E;)switch(E.s){case 0:if(E.s=1,N)for(;E.n.l&&mt(A,E.n.from)<0;)E={up:E,n:E.n.l,s:1};else for(;E.n.l;)E={up:E,n:E.n.l,s:1};case 1:if(E.s=2,!N||mt(A,E.n.to)<=0)return{value:E.n,done:!1};case 2:if(E.n.r){E.s=3,E={up:E,n:E.n.r,s:0};continue}case 3:E=E.up}return{done:!0}}}}function Ma(C){var E,A,N=(((E=C.r)===null||E===void 0?void 0:E.d)||0)-(((A=C.l)===null||A===void 0?void 0:A.d)||0),M=1<N?"r":N<-1?"l":"";M&&(E=M=="r"?"l":"r",A=s({},C),N=C[M],C.from=N.from,C.to=N.to,C[M]=N[M],A[M]=N[E],(C[E]=A).d=Ba(A)),C.d=Ba(C)}function Ba(A){var E=A.r,A=A.l;return(E?A?Math.max(E.d,A.d):E.d:A?A.d:0)+1}function Zs(C,E){return a(E).forEach(function(A){C[A]?ls(C[A],E[A]):C[A]=function N(M){var V,Y,ie={};for(V in M)l(M,V)&&(Y=M[V],ie[V]=!Y||typeof Y!="object"||T.has(Y.constructor)?Y:N(Y));return ie}(E[A])}),C}function zi(C,E){return C.all||E.all||Object.keys(C).some(function(A){return E[A]&&Da(E[A],C[A])})}h(nr.prototype,((jr={add:function(C){return ls(this,C),this},addKey:function(C){return as(this,C,C),this},addKeys:function(C){var E=this;return C.forEach(function(A){return as(E,A,A)}),this},hasKey:function(C){var E=Ws(this).next(C).value;return E&&mt(E.from,C)<=0&&0<=mt(E.to,C)}})[ne]=function(){return Ws(this)},jr));var xn={},Ki={},Xi=!1;function Gs(C){Zs(Ki,C),Xi||(Xi=!0,setTimeout(function(){Xi=!1,Yi(Ki,!(Ki={}))},0))}function Yi(C,E){E===void 0&&(E=!1);var A=new Set;if(C.all)for(var N=0,M=Object.values(xn);N<M.length;N++)$a(Y=M[N],C,A,E);else for(var V in C){var Y,ie=/^idb\:\/\/(.*)\/(.*)\//.exec(V);ie&&(V=ie[1],ie=ie[2],(Y=xn["idb://".concat(V,"/").concat(ie)])&&$a(Y,C,A,E))}A.forEach(function(ce){return ce()})}function $a(C,E,A,N){for(var M=[],V=0,Y=Object.entries(C.queries.query);V<Y.length;V++){for(var ie=Y[V],ce=ie[0],de=[],ge=0,oe=ie[1];ge<oe.length;ge++){var we=oe[ge];zi(E,we.obsSet)?we.subscribers.forEach(function(me){return A.add(me)}):N&&de.push(we)}N&&M.push([ce,de])}if(N)for(var ue=0,ve=M;ue<ve.length;ue++){var ye=ve[ue],ce=ye[0],de=ye[1];C.queries.query[ce]=de}}function Vh(C){var E=C._state,A=C._deps.indexedDB;if(E.isBeingOpened||C.idbdb)return E.dbReadyPromise.then(function(){return E.dbOpenError?Tt(E.dbOpenError):C});E.isBeingOpened=!0,E.dbOpenError=null,E.openComplete=!1;var N=E.openCanceller,M=Math.round(10*C.verno),V=!1;function Y(){if(E.openCanceller!==N)throw new J.DatabaseClosed("db.open() was cancelled")}function ie(){return new Te(function(we,ue){if(Y(),!A)throw new J.MissingAPI;var ve=C.name,ye=E.autoSchema||!M?A.open(ve):A.open(ve,M);if(!ye)throw new J.MissingAPI;ye.onerror=Sr(ue),ye.onblocked=dt(C._fireOnBlocked),ye.onupgradeneeded=dt(function(me){var je;ge=ye.transaction,E.autoSchema&&!C._options.allowEmptyDB?(ye.onerror=yn,ge.abort(),ye.result.close(),(je=A.deleteDatabase(ve)).onsuccess=je.onerror=dt(function(){ue(new J.NoSuchDatabase("Database ".concat(ve," doesnt exist")))})):(ge.onerror=Sr(ue),me=me.oldVersion>Math.pow(2,62)?0:me.oldVersion,oe=me<1,C.idbdb=ye.result,V&&Ui(C,ge),Vi(C,me/10,ge,ue))},ue),ye.onsuccess=dt(function(){ge=null;var me,je,Ee,ke,Re,We=C.idbdb=ye.result,Ke=b(We.objectStoreNames);if(0<Ke.length)try{var Ze=We.transaction((ke=Ke).length===1?ke[0]:ke,"readonly");if(E.autoSchema)je=We,Ee=Ze,(me=C).verno=je.version/10,Ee=me._dbSchema=Nr(0,je,Ee),me._storeNames=b(je.objectStoreNames,0),Nn(me,[me._allTables],a(Ee),Ee);else if(Pr(C,C._dbSchema,Ze),((Re=is(Nr(0,(Re=C).idbdb,Ze),Re._dbSchema)).add.length||Re.change.some(function(Ge){return Ge.add.length||Ge.change.length}))&&!V)return console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this."),We.close(),M=We.version+1,V=!0,we(ie());Ln(C,Ze)}catch{}hr.push(C),We.onversionchange=dt(function(Ge){E.vcFired=!0,C.on("versionchange").fire(Ge)}),We.onclose=dt(function(Ge){C.on("close").fire(Ge)}),oe&&(Re=C._deps,Ze=ve,We=Re.indexedDB,Re=Re.IDBKeyRange,Zi(We)||Ze===_r||Wi(We,Re).put({name:Ze}).catch(Le)),we()},ue)}).catch(function(we){switch(we==null?void 0:we.name){case"UnknownError":if(0<E.PR1398_maxLoop)return E.PR1398_maxLoop--,console.warn("Dexie: Workaround for Chrome UnknownError on open()"),ie();break;case"VersionError":if(0<M)return M=0,ie()}return Te.reject(we)})}var ce,de=E.dbReadyResolve,ge=null,oe=!1;return Te.race([N,(typeof navigator>"u"?Te.resolve():!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(we){function ue(){return indexedDB.databases().finally(we)}ce=setInterval(ue,100),ue()}).finally(function(){return clearInterval(ce)}):Promise.resolve()).then(ie)]).then(function(){return Y(),E.onReadyBeingFired=[],Te.resolve(Gi(function(){return C.on.ready.fire(C.vip)})).then(function we(){if(0<E.onReadyBeingFired.length){var ue=E.onReadyBeingFired.reduce(_e,Le);return E.onReadyBeingFired=[],Te.resolve(Gi(function(){return ue(C.vip)})).then(we)}})}).finally(function(){E.openCanceller===N&&(E.onReadyBeingFired=null,E.isBeingOpened=!1)}).catch(function(we){E.dbOpenError=we;try{ge&&ge.abort()}catch{}return N===E.openCanceller&&C._close(),Tt(we)}).finally(function(){E.openComplete=!0,de()}).then(function(){var we;return oe&&(we={},C.tables.forEach(function(ue){ue.schema.indexes.forEach(function(ve){ve.name&&(we["idb://".concat(C.name,"/").concat(ue.name,"/").concat(ve.name)]=new nr(-1/0,[[[]]]))}),we["idb://".concat(C.name,"/").concat(ue.name,"/")]=we["idb://".concat(C.name,"/").concat(ue.name,"/:dels")]=new nr(-1/0,[[[]]])}),Hr(_n).fire(we),Yi(we,!0)),C})}function Ji(C){function E(V){return C.next(V)}var A=M(E),N=M(function(V){return C.throw(V)});function M(V){return function(ce){var ie=V(ce),ce=ie.value;return ie.done?ce:ce&&typeof ce.then=="function"?ce.then(A,N):o(ce)?Promise.all(ce).then(A,N):A(ce)}}return M(E)()}function Hs(C,E,A){for(var N=o(C)?C.slice():[C],M=0;M<A;++M)N.push(E);return N}var Uh={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(C){return s(s({},C),{table:function(E){var A=C.table(E),N=A.schema,M={},V=[];function Y(oe,we,ue){var ve=Sn(oe),ye=M[ve]=M[ve]||[],me=oe==null?0:typeof oe=="string"?1:oe.length,je=0<we,je=s(s({},ue),{name:je?"".concat(ve,"(virtual-from:").concat(ue.name,")"):ue.name,lowLevelIndex:ue,isVirtual:je,keyTail:we,keyLength:me,extractKey:ns(oe),unique:!je&&ue.unique});return ye.push(je),je.isPrimaryKey||V.push(je),1<me&&Y(me===2?oe[0]:oe.slice(0,me-1),we+1,ue),ye.sort(function(Ee,ke){return Ee.keyTail-ke.keyTail}),je}E=Y(N.primaryKey.keyPath,0,N.primaryKey),M[":id"]=[E];for(var ie=0,ce=N.indexes;ie<ce.length;ie++){var de=ce[ie];Y(de.keyPath,0,de)}function ge(oe){var we,ue=oe.query.index;return ue.isVirtual?s(s({},oe),{query:{index:ue.lowLevelIndex,range:(we=oe.query.range,ue=ue.keyTail,{type:we.type===1?2:we.type,lower:Hs(we.lower,we.lowerOpen?C.MAX_KEY:C.MIN_KEY,ue),lowerOpen:!0,upper:Hs(we.upper,we.upperOpen?C.MIN_KEY:C.MAX_KEY,ue),upperOpen:!0})}}):oe}return s(s({},A),{schema:s(s({},N),{primaryKey:E,indexes:V,getIndexByKeyPath:function(oe){return(oe=M[Sn(oe)])&&oe[0]}}),count:function(oe){return A.count(ge(oe))},query:function(oe){return A.query(ge(oe))},openCursor:function(oe){var we=oe.query.index,ue=we.keyTail,ve=we.isVirtual,ye=we.keyLength;return ve?A.openCursor(ge(oe)).then(function(je){return je&&me(je)}):A.openCursor(oe);function me(je){return Object.create(je,{continue:{value:function(Ee){Ee!=null?je.continue(Hs(Ee,oe.reverse?C.MAX_KEY:C.MIN_KEY,ue)):oe.unique?je.continue(je.key.slice(0,ye).concat(oe.reverse?C.MIN_KEY:C.MAX_KEY,ue)):je.continue()}},continuePrimaryKey:{value:function(Ee,ke){je.continuePrimaryKey(Hs(Ee,C.MAX_KEY,ue),ke)}},primaryKey:{get:function(){return je.primaryKey}},key:{get:function(){var Ee=je.key;return ye===1?Ee[0]:Ee.slice(0,ye)}},value:{get:function(){return je.value}}})}}})}})}};function qi(C,E,A,N){return A=A||{},N=N||"",a(C).forEach(function(M){var V,Y,ie;l(E,M)?(V=C[M],Y=E[M],typeof V=="object"&&typeof Y=="object"&&V&&Y?(ie=W(V))!==W(Y)?A[N+M]=E[M]:ie==="Object"?qi(V,Y,A,N+M+"."):V!==Y&&(A[N+M]=E[M]):V!==Y&&(A[N+M]=E[M])):A[N+M]=void 0}),a(E).forEach(function(M){l(C,M)||(A[N+M]=E[M])}),A}function Qi(C,E){return E.type==="delete"?E.keys:E.keys||E.values.map(C.extractKey)}var Wh={stack:"dbcore",name:"HooksMiddleware",level:2,create:function(C){return s(s({},C),{table:function(E){var A=C.table(E),N=A.schema.primaryKey;return s(s({},A),{mutate:function(M){var V=ze.trans,Y=V.table(E).hook,ie=Y.deleting,ce=Y.creating,de=Y.updating;switch(M.type){case"add":if(ce.fire===Le)break;return V._promise("readwrite",function(){return ge(M)},!0);case"put":if(ce.fire===Le&&de.fire===Le)break;return V._promise("readwrite",function(){return ge(M)},!0);case"delete":if(ie.fire===Le)break;return V._promise("readwrite",function(){return ge(M)},!0);case"deleteRange":if(ie.fire===Le)break;return V._promise("readwrite",function(){return function oe(we,ue,ve){return A.query({trans:we,values:!1,query:{index:N,range:ue},limit:ve}).then(function(ye){var me=ye.result;return ge({type:"delete",keys:me,trans:we}).then(function(je){return 0<je.numFailures?Promise.reject(je.failures[0]):me.length<ve?{failures:[],numFailures:0,lastResult:void 0}:oe(we,s(s({},ue),{lower:me[me.length-1],lowerOpen:!0}),ve)})})}(M.trans,M.range,1e4)},!0)}return A.mutate(M);function ge(oe){var we,ue,ve,ye=ze.trans,me=oe.keys||Qi(N,oe);if(!me)throw new Error("Keys missing");return(oe=oe.type==="add"||oe.type==="put"?s(s({},oe),{keys:me}):s({},oe)).type!=="delete"&&(oe.values=u([],oe.values)),oe.keys&&(oe.keys=u([],oe.keys)),we=A,ve=me,((ue=oe).type==="add"?Promise.resolve([]):we.getMany({trans:ue.trans,keys:ve,cache:"immutable"})).then(function(je){var Ee=me.map(function(ke,Re){var We,Ke,Ze,Ge=je[Re],Je={onerror:null,onsuccess:null};return oe.type==="delete"?ie.fire.call(Je,ke,Ge,ye):oe.type==="add"||Ge===void 0?(We=ce.fire.call(Je,ke,oe.values[Re],ye),ke==null&&We!=null&&(oe.keys[Re]=ke=We,N.outbound||S(oe.values[Re],N.keyPath,ke))):(We=qi(Ge,oe.values[Re]),(Ke=de.fire.call(Je,We,ke,Ge,ye))&&(Ze=oe.values[Re],Object.keys(Ke).forEach(function(He){l(Ze,He)?Ze[He]=Ke[He]:S(Ze,He,Ke[He])}))),Je});return A.mutate(oe).then(function(ke){for(var Re=ke.failures,We=ke.results,Ke=ke.numFailures,ke=ke.lastResult,Ze=0;Ze<me.length;++Ze){var Ge=(We||me)[Ze],Je=Ee[Ze];Ge==null?Je.onerror&&Je.onerror(Re[Ze]):Je.onsuccess&&Je.onsuccess(oe.type==="put"&&je[Ze]?oe.values[Ze]:Ge)}return{failures:Re,results:We,numFailures:Ke,lastResult:ke}}).catch(function(ke){return Ee.forEach(function(Re){return Re.onerror&&Re.onerror(ke)}),Promise.reject(ke)})})}}})}})}};function Fa(C,E,A){try{if(!E||E.keys.length<C.length)return null;for(var N=[],M=0,V=0;M<E.keys.length&&V<C.length;++M)mt(E.keys[M],C[V])===0&&(N.push(A?F(E.values[M]):E.values[M]),++V);return N.length===C.length?N:null}catch{return null}}var Zh={stack:"dbcore",level:-1,create:function(C){return{table:function(E){var A=C.table(E);return s(s({},A),{getMany:function(N){if(!N.cache)return A.getMany(N);var M=Fa(N.keys,N.trans._cache,N.cache==="clone");return M?Te.resolve(M):A.getMany(N).then(function(V){return N.trans._cache={keys:N.keys,values:N.cache==="clone"?F(V):V},V})},mutate:function(N){return N.type!=="add"&&(N.trans._cache=null),A.mutate(N)}})}}}};function Va(C,E){return C.trans.mode==="readonly"&&!!C.subscr&&!C.trans.explicit&&C.trans.db._options.cache!=="disabled"&&!E.schema.primaryKey.outbound}function Ua(C,E){switch(C){case"query":return E.values&&!E.unique;case"get":case"getMany":case"count":case"openCursor":return!1}}var Gh={stack:"dbcore",level:0,name:"Observability",create:function(C){var E=C.schema.name,A=new nr(C.MIN_KEY,C.MAX_KEY);return s(s({},C),{transaction:function(N,M,V){if(ze.subscr&&M!=="readonly")throw new J.ReadOnly("Readwrite transaction in liveQuery context. Querier source: ".concat(ze.querier));return C.transaction(N,M,V)},table:function(N){var M=C.table(N),V=M.schema,Y=V.primaryKey,oe=V.indexes,ie=Y.extractKey,ce=Y.outbound,de=Y.autoIncrement&&oe.filter(function(ue){return ue.compound&&ue.keyPath.includes(Y.keyPath)}),ge=s(s({},M),{mutate:function(ue){function ve(He){return He="idb://".concat(E,"/").concat(N,"/").concat(He),ke[He]||(ke[He]=new nr)}var ye,me,je,Ee=ue.trans,ke=ue.mutatedParts||(ue.mutatedParts={}),Re=ve(""),We=ve(":dels"),Ke=ue.type,Je=ue.type==="deleteRange"?[ue.range]:ue.type==="delete"?[ue.keys]:ue.values.length<50?[Qi(Y,ue).filter(function(He){return He}),ue.values]:[],Ze=Je[0],Ge=Je[1],Je=ue.trans._cache;return o(Ze)?(Re.addKeys(Ze),(Je=Ke==="delete"||Ze.length===Ge.length?Fa(Ze,Je):null)||We.addKeys(Ze),(Je||Ge)&&(ye=ve,me=Je,je=Ge,V.indexes.forEach(function(He){var rt=ye(He.name||"");function pt(St){return St!=null?He.extractKey(St):null}function wt(St){return He.multiEntry&&o(St)?St.forEach(function(pr){return rt.addKey(pr)}):rt.addKey(St)}(me||je).forEach(function(St,sr){var ft=me&&pt(me[sr]),sr=je&&pt(je[sr]);mt(ft,sr)!==0&&(ft!=null&&wt(ft),sr!=null&&wt(sr))})}))):Ze?(Ge={from:(Ge=Ze.lower)!==null&&Ge!==void 0?Ge:C.MIN_KEY,to:(Ge=Ze.upper)!==null&&Ge!==void 0?Ge:C.MAX_KEY},We.add(Ge),Re.add(Ge)):(Re.add(A),We.add(A),V.indexes.forEach(function(He){return ve(He.name).add(A)})),M.mutate(ue).then(function(He){return!Ze||ue.type!=="add"&&ue.type!=="put"||(Re.addKeys(He.results),de&&de.forEach(function(rt){for(var pt=ue.values.map(function(ft){return rt.extractKey(ft)}),wt=rt.keyPath.findIndex(function(ft){return ft===Y.keyPath}),St=0,pr=He.results.length;St<pr;++St)pt[St][wt]=He.results[St];ve(rt.name).addKeys(pt)})),Ee.mutatedParts=Zs(Ee.mutatedParts||{},ke),He})}}),oe=function(ve){var ye=ve.query,ve=ye.index,ye=ye.range;return[ve,new nr((ve=ye.lower)!==null&&ve!==void 0?ve:C.MIN_KEY,(ye=ye.upper)!==null&&ye!==void 0?ye:C.MAX_KEY)]},we={get:function(ue){return[Y,new nr(ue.key)]},getMany:function(ue){return[Y,new nr().addKeys(ue.keys)]},count:oe,query:oe,openCursor:oe};return a(we).forEach(function(ue){ge[ue]=function(ve){var ye=ze.subscr,me=!!ye,je=Va(ze,M)&&Ua(ue,ve)?ve.obsSet={}:ye;if(me){var Ee=function(Ge){return Ge="idb://".concat(E,"/").concat(N,"/").concat(Ge),je[Ge]||(je[Ge]=new nr)},ke=Ee(""),Re=Ee(":dels"),ye=we[ue](ve),me=ye[0],ye=ye[1];if((ue==="query"&&me.isPrimaryKey&&!ve.values?Re:Ee(me.name||"")).add(ye),!me.isPrimaryKey){if(ue!=="count"){var We=ue==="query"&&ce&&ve.values&&M.query(s(s({},ve),{values:!1}));return M[ue].apply(this,arguments).then(function(Ge){if(ue==="query"){if(ce&&ve.values)return We.then(function(pt){return pt=pt.result,ke.addKeys(pt),Ge});var Je=ve.values?Ge.result.map(ie):Ge.result;(ve.values?ke:Re).addKeys(Je)}else if(ue==="openCursor"){var He=Ge,rt=ve.values;return He&&Object.create(He,{key:{get:function(){return Re.addKey(He.primaryKey),He.key}},primaryKey:{get:function(){var pt=He.primaryKey;return Re.addKey(pt),pt}},value:{get:function(){return rt&&ke.addKey(He.primaryKey),He.value}}})}return Ge})}Re.add(A)}}return M[ue].apply(this,arguments)}}),ge}})}};function Wa(C,E,A){if(A.numFailures===0)return E;if(E.type==="deleteRange")return null;var N=E.keys?E.keys.length:"values"in E&&E.values?E.values.length:1;return A.numFailures===N?null:(E=s({},E),o(E.keys)&&(E.keys=E.keys.filter(function(M,V){return!(V in A.failures)})),"values"in E&&o(E.values)&&(E.values=E.values.filter(function(M,V){return!(V in A.failures)})),E)}function eo(C,E){return A=C,((N=E).lower===void 0||(N.lowerOpen?0<mt(A,N.lower):0<=mt(A,N.lower)))&&(C=C,(E=E).upper===void 0||(E.upperOpen?mt(C,E.upper)<0:mt(C,E.upper)<=0));var A,N}function Za(C,E,we,N,M,V){if(!we||we.length===0)return C;var Y=E.query.index,ie=Y.multiEntry,ce=E.query.range,de=N.schema.primaryKey.extractKey,ge=Y.extractKey,oe=(Y.lowLevelIndex||Y).extractKey,we=we.reduce(function(ue,ve){var ye=ue,me=[];if(ve.type==="add"||ve.type==="put")for(var je=new nr,Ee=ve.values.length-1;0<=Ee;--Ee){var ke,Re=ve.values[Ee],We=de(Re);je.hasKey(We)||(ke=ge(Re),(ie&&o(ke)?ke.some(function(He){return eo(He,ce)}):eo(ke,ce))&&(je.addKey(We),me.push(Re)))}switch(ve.type){case"add":var Ke=new nr().addKeys(E.values?ue.map(function(rt){return de(rt)}):ue),ye=ue.concat(E.values?me.filter(function(rt){return rt=de(rt),!Ke.hasKey(rt)&&(Ke.addKey(rt),!0)}):me.map(function(rt){return de(rt)}).filter(function(rt){return!Ke.hasKey(rt)&&(Ke.addKey(rt),!0)}));break;case"put":var Ze=new nr().addKeys(ve.values.map(function(rt){return de(rt)}));ye=ue.filter(function(rt){return!Ze.hasKey(E.values?de(rt):rt)}).concat(E.values?me:me.map(function(rt){return de(rt)}));break;case"delete":var Ge=new nr().addKeys(ve.keys);ye=ue.filter(function(rt){return!Ge.hasKey(E.values?de(rt):rt)});break;case"deleteRange":var Je=ve.range;ye=ue.filter(function(rt){return!eo(de(rt),Je)})}return ye},C);return we===C?C:(we.sort(function(ue,ve){return mt(oe(ue),oe(ve))||mt(de(ue),de(ve))}),E.limit&&E.limit<1/0&&(we.length>E.limit?we.length=E.limit:C.length===E.limit&&we.length<E.limit&&(M.dirty=!0)),V?Object.freeze(we):we)}function Ga(C,E){return mt(C.lower,E.lower)===0&&mt(C.upper,E.upper)===0&&!!C.lowerOpen==!!E.lowerOpen&&!!C.upperOpen==!!E.upperOpen}function Hh(C,E){return function(A,N,M,V){if(A===void 0)return N!==void 0?-1:0;if(N===void 0)return 1;if((N=mt(A,N))===0){if(M&&V)return 0;if(M)return 1;if(V)return-1}return N}(C.lower,E.lower,C.lowerOpen,E.lowerOpen)<=0&&0<=function(A,N,M,V){if(A===void 0)return N!==void 0?1:0;if(N===void 0)return-1;if((N=mt(A,N))===0){if(M&&V)return 0;if(M)return-1;if(V)return 1}return N}(C.upper,E.upper,C.upperOpen,E.upperOpen)}function zh(C,E,A,N){C.subscribers.add(A),N.addEventListener("abort",function(){var M,V;C.subscribers.delete(A),C.subscribers.size===0&&(M=C,V=E,setTimeout(function(){M.subscribers.size===0&&L(V,M)},3e3))})}var Kh={stack:"dbcore",level:0,name:"Cache",create:function(C){var E=C.schema.name;return s(s({},C),{transaction:function(A,N,M){var V,Y,ie=C.transaction(A,N,M);return N==="readwrite"&&(Y=(V=new AbortController).signal,M=function(ce){return function(){if(V.abort(),N==="readwrite"){for(var de=new Set,ge=0,oe=A;ge<oe.length;ge++){var we=oe[ge],ue=xn["idb://".concat(E,"/").concat(we)];if(ue){var ve=C.table(we),ye=ue.optimisticOps.filter(function(rt){return rt.trans===ie});if(ie._explicit&&ce&&ie.mutatedParts)for(var me=0,je=Object.values(ue.queries.query);me<je.length;me++)for(var Ee=0,ke=(Ke=je[me]).slice();Ee<ke.length;Ee++)zi((Ze=ke[Ee]).obsSet,ie.mutatedParts)&&(L(Ke,Ze),Ze.subscribers.forEach(function(rt){return de.add(rt)}));else if(0<ye.length){ue.optimisticOps=ue.optimisticOps.filter(function(rt){return rt.trans!==ie});for(var Re=0,We=Object.values(ue.queries.query);Re<We.length;Re++)for(var Ke,Ze,Ge,Je=0,He=(Ke=We[Re]).slice();Je<He.length;Je++)(Ze=He[Je]).res!=null&&ie.mutatedParts&&(ce&&!Ze.dirty?(Ge=Object.isFrozen(Ze.res),Ge=Za(Ze.res,Ze.req,ye,ve,Ze,Ge),Ze.dirty?(L(Ke,Ze),Ze.subscribers.forEach(function(rt){return de.add(rt)})):Ge!==Ze.res&&(Ze.res=Ge,Ze.promise=Te.resolve({result:Ge}))):(Ze.dirty&&L(Ke,Ze),Ze.subscribers.forEach(function(rt){return de.add(rt)})))}}}de.forEach(function(rt){return rt()})}}},ie.addEventListener("abort",M(!1),{signal:Y}),ie.addEventListener("error",M(!1),{signal:Y}),ie.addEventListener("complete",M(!0),{signal:Y})),ie},table:function(A){var N=C.table(A),M=N.schema.primaryKey;return s(s({},N),{mutate:function(V){var Y=ze.trans;if(M.outbound||Y.db._options.cache==="disabled"||Y.explicit||Y.idbtrans.mode!=="readwrite")return N.mutate(V);var ie=xn["idb://".concat(E,"/").concat(A)];return ie?(Y=N.mutate(V),V.type!=="add"&&V.type!=="put"||!(50<=V.values.length||Qi(M,V).some(function(ce){return ce==null}))?(ie.optimisticOps.push(V),V.mutatedParts&&Gs(V.mutatedParts),Y.then(function(ce){0<ce.numFailures&&(L(ie.optimisticOps,V),(ce=Wa(0,V,ce))&&ie.optimisticOps.push(ce),V.mutatedParts&&Gs(V.mutatedParts))}),Y.catch(function(){L(ie.optimisticOps,V),V.mutatedParts&&Gs(V.mutatedParts)})):Y.then(function(ce){var de=Wa(0,s(s({},V),{values:V.values.map(function(ge,oe){var we;return ce.failures[oe]?ge:(ge=(we=M.keyPath)!==null&&we!==void 0&&we.includes(".")?F(ge):s({},ge),S(ge,M.keyPath,ce.results[oe]),ge)})}),ce);ie.optimisticOps.push(de),queueMicrotask(function(){return V.mutatedParts&&Gs(V.mutatedParts)})}),Y):N.mutate(V)},query:function(V){if(!Va(ze,N)||!Ua("query",V))return N.query(V);var Y=((de=ze.trans)===null||de===void 0?void 0:de.db._options.cache)==="immutable",oe=ze,ie=oe.requery,ce=oe.signal,de=function(ve,ye,me,je){var Ee=xn["idb://".concat(ve,"/").concat(ye)];if(!Ee)return[];if(!(ye=Ee.queries[me]))return[null,!1,Ee,null];var ke=ye[(je.query?je.query.index.name:null)||""];if(!ke)return[null,!1,Ee,null];switch(me){case"query":var Re=ke.find(function(We){return We.req.limit===je.limit&&We.req.values===je.values&&Ga(We.req.query.range,je.query.range)});return Re?[Re,!0,Ee,ke]:[ke.find(function(We){return("limit"in We.req?We.req.limit:1/0)>=je.limit&&(!je.values||We.req.values)&&Hh(We.req.query.range,je.query.range)}),!1,Ee,ke];case"count":return Re=ke.find(function(We){return Ga(We.req.query.range,je.query.range)}),[Re,!!Re,Ee,ke]}}(E,A,"query",V),ge=de[0],oe=de[1],we=de[2],ue=de[3];return ge&&oe?ge.obsSet=V.obsSet:(oe=N.query(V).then(function(ve){var ye=ve.result;if(ge&&(ge.res=ye),Y){for(var me=0,je=ye.length;me<je;++me)Object.freeze(ye[me]);Object.freeze(ye)}else ve.result=F(ye);return ve}).catch(function(ve){return ue&&ge&&L(ue,ge),Promise.reject(ve)}),ge={obsSet:V.obsSet,promise:oe,subscribers:new Set,type:"query",req:V,dirty:!1},ue?ue.push(ge):(ue=[ge],(we=we||(xn["idb://".concat(E,"/").concat(A)]={queries:{query:{},count:{}},objs:new Map,optimisticOps:[],unsignaledParts:{}})).queries.query[V.query.index.name||""]=ue)),zh(ge,ue,ie,ce),ge.promise.then(function(ve){return{result:Za(ve.result,V,we==null?void 0:we.optimisticOps,N,ge,Y)}})}})}})}};function zs(C,E){return new Proxy(C,{get:function(A,N,M){return N==="db"?E:Reflect.get(A,N,M)}})}var Jr=(Ut.prototype.version=function(C){if(isNaN(C)||C<.1)throw new J.Type("Given version is not a positive number");if(C=Math.round(10*C)/10,this.idbdb||this._state.isBeingOpened)throw new J.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,C);var E=this._versions,A=E.filter(function(N){return N._cfg.version===C})[0];return A||(A=new this.Version(C),E.push(A),E.sort(Fi),A.stores({}),this._state.autoSchema=!1,A)},Ut.prototype._whenReady=function(C){var E=this;return this.idbdb&&(this._state.openComplete||ze.letThrough||this._vip)?C():new Te(function(A,N){if(E._state.openComplete)return N(new J.DatabaseClosed(E._state.dbOpenError));if(!E._state.isBeingOpened){if(!E._state.autoOpen)return void N(new J.DatabaseClosed);E.open().catch(Le)}E._state.dbReadyPromise.then(A,N)}).then(C)},Ut.prototype.use=function(C){var E=C.stack,A=C.create,N=C.level,M=C.name;return M&&this.unuse({stack:E,name:M}),C=this._middlewares[E]||(this._middlewares[E]=[]),C.push({stack:E,create:A,level:N??10,name:M}),C.sort(function(V,Y){return V.level-Y.level}),this},Ut.prototype.unuse=function(C){var E=C.stack,A=C.name,N=C.create;return E&&this._middlewares[E]&&(this._middlewares[E]=this._middlewares[E].filter(function(M){return N?M.create!==N:!!A&&M.name!==A})),this},Ut.prototype.open=function(){var C=this;return ar(Pt,function(){return Vh(C)})},Ut.prototype._close=function(){var C=this._state,E=hr.indexOf(this);if(0<=E&&hr.splice(E,1),this.idbdb){try{this.idbdb.close()}catch{}this.idbdb=null}C.isBeingOpened||(C.dbReadyPromise=new Te(function(A){C.dbReadyResolve=A}),C.openCanceller=new Te(function(A,N){C.cancelOpen=N}))},Ut.prototype.close=function(A){var E=(A===void 0?{disableAutoOpen:!0}:A).disableAutoOpen,A=this._state;E?(A.isBeingOpened&&A.cancelOpen(new J.DatabaseClosed),this._close(),A.autoOpen=!1,A.dbOpenError=new J.DatabaseClosed):(this._close(),A.autoOpen=this._options.autoOpen||A.isBeingOpened,A.openComplete=!1,A.dbOpenError=null)},Ut.prototype.delete=function(C){var E=this;C===void 0&&(C={disableAutoOpen:!0});var A=0<arguments.length&&typeof arguments[0]!="object",N=this._state;return new Te(function(M,V){function Y(){E.close(C);var ie=E._deps.indexedDB.deleteDatabase(E.name);ie.onsuccess=dt(function(){var ce,de,ge;ce=E._deps,de=E.name,ge=ce.indexedDB,ce=ce.IDBKeyRange,Zi(ge)||de===_r||Wi(ge,ce).delete(de).catch(Le),M()}),ie.onerror=Sr(V),ie.onblocked=E._fireOnBlocked}if(A)throw new J.InvalidArgument("Invalid closeOptions argument to db.delete()");N.isBeingOpened?N.dbReadyPromise.then(Y):Y()})},Ut.prototype.backendDB=function(){return this.idbdb},Ut.prototype.isOpen=function(){return this.idbdb!==null},Ut.prototype.hasBeenClosed=function(){var C=this._state.dbOpenError;return C&&C.name==="DatabaseClosed"},Ut.prototype.hasFailed=function(){return this._state.dbOpenError!==null},Ut.prototype.dynamicallyOpened=function(){return this._state.autoSchema},Object.defineProperty(Ut.prototype,"tables",{get:function(){var C=this;return a(this._allTables).map(function(E){return C._allTables[E]})},enumerable:!1,configurable:!0}),Ut.prototype.transaction=function(){var C=(function(E,A,N){var M=arguments.length;if(M<2)throw new J.InvalidArgument("Too few arguments");for(var V=new Array(M-1);--M;)V[M-1]=arguments[M];return N=V.pop(),[E,O(V),N]}).apply(this,arguments);return this._transaction.apply(this,C)},Ut.prototype._transaction=function(C,E,A){var N=this,M=ze.trans;M&&M.db===this&&C.indexOf("!")===-1||(M=null);var V,Y,ie=C.indexOf("?")!==-1;C=C.replace("!","").replace("?","");try{if(Y=E.map(function(de){if(de=de instanceof N.Table?de.name:de,typeof de!="string")throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return de}),C=="r"||C===Ar)V=Ar;else{if(C!="rw"&&C!=Rr)throw new J.InvalidArgument("Invalid transaction mode: "+C);V=Rr}if(M){if(M.mode===Ar&&V===Rr){if(!ie)throw new J.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");M=null}M&&Y.forEach(function(de){if(M&&M.storeNames.indexOf(de)===-1){if(!ie)throw new J.SubTransaction("Table "+de+" not included in parent transaction.");M=null}}),ie&&M&&!M.active&&(M=null)}}catch(de){return M?M._promise(null,function(ge,oe){oe(de)}):Tt(de)}var ce=(function de(ge,oe,we,ue,ve){return Te.resolve().then(function(){var ye=ze.transless||ze,me=ge._createTransaction(oe,we,ge._dbSchema,ue);if(me.explicit=!0,ye={trans:me,transless:ye},ue)me.idbtrans=ue.idbtrans;else try{me.create(),me.idbtrans._explicit=!0,ge._state.PR1398_maxLoop=3}catch(ke){return ke.name===D.InvalidState&&ge.isOpen()&&0<--ge._state.PR1398_maxLoop?(console.warn("Dexie: Need to reopen db"),ge.close({disableAutoOpen:!1}),ge.open().then(function(){return de(ge,oe,we,null,ve)})):Tt(ke)}var je,Ee=K(ve);return Ee&&dr(),ye=Te.follow(function(){var ke;(je=ve.call(me,me))&&(Ee?(ke=tr.bind(null,null),je.then(ke,ke)):typeof je.next=="function"&&typeof je.throw=="function"&&(je=Ji(je)))},ye),(je&&typeof je.then=="function"?Te.resolve(je).then(function(ke){return me.active?ke:Tt(new J.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))}):ye.then(function(){return je})).then(function(ke){return ue&&me._resolve(),me._completion.then(function(){return ke})}).catch(function(ke){return me._reject(ke),Tt(ke)})})}).bind(null,this,V,Y,M,A);return M?M._promise(V,ce,"lock"):ze.trans?ar(ze.transless,function(){return N._whenReady(ce)}):this._whenReady(ce)},Ut.prototype.table=function(C){if(!l(this._allTables,C))throw new J.InvalidTable("Table ".concat(C," does not exist"));return this._allTables[C]},Ut);function Ut(C,E){var A=this;this._middlewares={},this.verno=0;var N=Ut.dependencies;this._options=E=s({addons:Ut.addons,autoOpen:!0,indexedDB:N.indexedDB,IDBKeyRange:N.IDBKeyRange,cache:"cloned"},E),this._deps={indexedDB:E.indexedDB,IDBKeyRange:E.IDBKeyRange},N=E.addons,this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;var M,V,Y,ie,ce,de={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:Le,dbReadyPromise:null,cancelOpen:Le,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3,autoOpen:E.autoOpen};de.dbReadyPromise=new Te(function(oe){de.dbReadyResolve=oe}),de.openCanceller=new Te(function(oe,we){de.cancelOpen=we}),this._state=de,this.name=C,this.on=ee(this,"populate","blocked","versionchange","close",{ready:[_e,Le]}),this.on.ready.subscribe=y(this.on.ready.subscribe,function(oe){return function(we,ue){Ut.vip(function(){var ve,ye=A._state;ye.openComplete?(ye.dbOpenError||Te.resolve().then(we),ue&&oe(we)):ye.onReadyBeingFired?(ye.onReadyBeingFired.push(we),ue&&oe(we)):(oe(we),ve=A,ue||oe(function me(){ve.on.ready.unsubscribe(we),ve.on.ready.unsubscribe(me)}))})}}),this.Collection=(M=this,I(fr.prototype,function(je,me){this.db=M;var ue=Lr,ve=null;if(me)try{ue=me()}catch(Ee){ve=Ee}var ye=je._ctx,me=ye.table,je=me.hook.reading.fire;this._ctx={table:me,index:ye.index,isPrimKey:!ye.index||me.schema.primKey.keyPath&&ye.index===me.schema.primKey.name,range:ue,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:ve,or:ye.or,valueMapper:je!==$e?je:null}})),this.Table=(V=this,I(dn.prototype,function(oe,we,ue){this.db=V,this._tx=ue,this.name=oe,this.schema=we,this.hook=V._allTables[oe]?V._allTables[oe].hook:ee(null,{creating:[Ie,Le],reading:[st,$e],updating:[Q,Le],deleting:[re,Le]})})),this.Transaction=(Y=this,I(Di.prototype,function(oe,we,ue,ve,ye){var me=this;this.db=Y,this.mode=oe,this.storeNames=we,this.schema=ue,this.chromeTransactionDurability=ve,this.idbtrans=null,this.on=ee(this,"complete","error","abort"),this.parent=ye||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new Te(function(je,Ee){me._resolve=je,me._reject=Ee}),this._completion.then(function(){me.active=!1,me.on.complete.fire()},function(je){var Ee=me.active;return me.active=!1,me.on.error.fire(je),me.parent?me.parent._reject(je):Ee&&me.idbtrans&&me.idbtrans.abort(),Tt(je)})})),this.Version=(ie=this,I(Yr.prototype,function(oe){this.db=ie,this._cfg={version:oe,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})),this.WhereClause=(ce=this,I(Bs.prototype,function(oe,we,ue){if(this.db=ce,this._ctx={table:oe,index:we===":id"?null:we,or:ue},this._cmp=this._ascending=mt,this._descending=function(ve,ye){return mt(ye,ve)},this._max=function(ve,ye){return 0<mt(ve,ye)?ve:ye},this._min=function(ve,ye){return mt(ve,ye)<0?ve:ye},this._IDBKeyRange=ce._deps.IDBKeyRange,!this._IDBKeyRange)throw new J.MissingAPI})),this.on("versionchange",function(oe){0<oe.newVersion?console.warn("Another connection wants to upgrade database '".concat(A.name,"'. Closing db now to resume the upgrade.")):console.warn("Another connection wants to delete database '".concat(A.name,"'. Closing db now to resume the delete request.")),A.close({disableAutoOpen:!1})}),this.on("blocked",function(oe){!oe.newVersion||oe.newVersion<oe.oldVersion?console.warn("Dexie.delete('".concat(A.name,"') was blocked")):console.warn("Upgrade '".concat(A.name,"' blocked by other connection holding version ").concat(oe.oldVersion/10))}),this._maxKey=wn(E.IDBKeyRange),this._createTransaction=function(oe,we,ue,ve){return new A.Transaction(oe,we,ue,A._options.chromeTransactionDurability,ve)},this._fireOnBlocked=function(oe){A.on("blocked").fire(oe),hr.filter(function(we){return we.name===A.name&&we!==A&&!we._state.vcFired}).map(function(we){return we.on("versionchange").fire(oe)})},this.use(Zh),this.use(Kh),this.use(Gh),this.use(Uh),this.use(Wh);var ge=new Proxy(this,{get:function(oe,we,ue){if(we==="_vip")return!0;if(we==="table")return function(ye){return zs(A.table(ye),ge)};var ve=Reflect.get(oe,we,ue);return ve instanceof dn?zs(ve,ge):we==="tables"?ve.map(function(ye){return zs(ye,ge)}):we==="_createTransaction"?function(){return zs(ve.apply(this,arguments),ge)}:ve}});this.vip=ge,N.forEach(function(oe){return oe(A)})}var Ks,jr=typeof Symbol<"u"&&"observable"in Symbol?Symbol.observable:"@@observable",Xh=(to.prototype.subscribe=function(C,E,A){return this._subscribe(C&&typeof C!="function"?C:{next:C,error:E,complete:A})},to.prototype[jr]=function(){return this},to);function to(C){this._subscribe=C}try{Ks={indexedDB:d.indexedDB||d.mozIndexedDB||d.webkitIndexedDB||d.msIndexedDB,IDBKeyRange:d.IDBKeyRange||d.webkitIDBKeyRange}}catch{Ks={indexedDB:null,IDBKeyRange:null}}function Ha(C){var E,A=!1,N=new Xh(function(M){var V=K(C),Y,ie=!1,ce={},de={},ge={get closed(){return ie},unsubscribe:function(){ie||(ie=!0,Y&&Y.abort(),oe&&Hr.storagemutated.unsubscribe(ue))}};M.start&&M.start(ge);var oe=!1,we=function(){return Or(ve)},ue=function(ye){Zs(ce,ye),zi(de,ce)&&we()},ve=function(){var ye,me,je;!ie&&Ks.indexedDB&&(ce={},ye={},Y&&Y.abort(),Y=new AbortController,je=function(Ee){var ke=ut();try{V&&dr();var Re=er(C,Ee);return Re=V?Re.finally(tr):Re}finally{ke&&bt()}}(me={subscr:ye,signal:Y.signal,requery:we,querier:C,trans:null}),Promise.resolve(je).then(function(Ee){A=!0,E=Ee,ie||me.signal.aborted||(ce={},function(ke){for(var Re in ke)if(l(ke,Re))return;return 1}(de=ye)||oe||(Hr(_n,ue),oe=!0),Or(function(){return!ie&&M.next&&M.next(Ee)}))},function(Ee){A=!1,["DatabaseClosedError","AbortError"].includes(Ee==null?void 0:Ee.name)||ie||Or(function(){ie||M.error&&M.error(Ee)})}))};return setTimeout(we,0),ge});return N.hasValue=function(){return A},N.getValue=function(){return E},N}var Cn=Jr;function ro(C){var E=hn;try{hn=!0,Hr.storagemutated.fire(C),Yi(C,!0)}finally{hn=E}}h(Cn,s(s({},be),{delete:function(C){return new Cn(C,{addons:[]}).delete()},exists:function(C){return new Cn(C,{addons:[]}).open().then(function(E){return E.close(),!0}).catch("NoSuchDatabaseError",function(){return!1})},getDatabaseNames:function(C){try{return E=Cn.dependencies,A=E.indexedDB,E=E.IDBKeyRange,(Zi(A)?Promise.resolve(A.databases()).then(function(N){return N.map(function(M){return M.name}).filter(function(M){return M!==_r})}):Wi(A,E).toCollection().primaryKeys()).then(C)}catch{return Tt(new J.MissingAPI)}var E,A},defineClass:function(){return function(C){c(this,C)}},ignoreTransaction:function(C){return ze.trans?ar(ze.transless,C):C()},vip:Gi,async:function(C){return function(){try{var E=Ji(C.apply(this,arguments));return E&&typeof E.then=="function"?E:Te.resolve(E)}catch(A){return Tt(A)}}},spawn:function(C,E,A){try{var N=Ji(C.apply(A,E||[]));return N&&typeof N.then=="function"?N:Te.resolve(N)}catch(M){return Tt(M)}},currentTransaction:{get:function(){return ze.trans||null}},waitFor:function(C,E){return E=Te.resolve(typeof C=="function"?Cn.ignoreTransaction(C):C).timeout(E||6e4),ze.trans?ze.trans.waitFor(E):E},Promise:Te,debug:{get:function(){return xe},set:function(C){Ae(C)}},derive:f,extend:c,props:h,override:y,Events:ee,on:Hr,liveQuery:Ha,extendObservabilitySet:Zs,getByKeyPath:x,setByKeyPath:S,delByKeyPath:function(C,E){typeof E=="string"?S(C,E,void 0):"length"in E&&[].map.call(E,function(A){S(C,A,void 0)})},shallowClone:j,deepClone:F,getObjectDiff:qi,cmp:mt,asap:w,minKey:-1/0,addons:[],connections:hr,errnames:D,dependencies:Ks,cache:xn,semVer:"4.0.11",version:"4.0.11".split(".").map(function(C){return parseInt(C)}).reduce(function(C,E,A){return C+E/Math.pow(10,2*A)})})),Cn.maxKey=wn(Cn.dependencies.IDBKeyRange),typeof dispatchEvent<"u"&&typeof addEventListener<"u"&&(Hr(_n,function(C){hn||(C=new CustomEvent(es,{detail:C}),hn=!0,dispatchEvent(C),hn=!1)}),addEventListener(es,function(C){C=C.detail,hn||ro(C)}));var Dn,hn=!1,za=function(){};return typeof BroadcastChannel<"u"&&((za=function(){(Dn=new BroadcastChannel(es)).onmessage=function(C){return C.data&&ro(C.data)}})(),typeof Dn.unref=="function"&&Dn.unref(),Hr(_n,function(C){hn||Dn.postMessage(C)})),typeof addEventListener<"u"&&(addEventListener("pagehide",function(C){if(!Jr.disableBfCache&&C.persisted){xe&&console.debug("Dexie: handling persisted pagehide"),Dn!=null&&Dn.close();for(var E=0,A=hr;E<A.length;E++)A[E].close({disableAutoOpen:!1})}}),addEventListener("pageshow",function(C){!Jr.disableBfCache&&C.persisted&&(xe&&console.debug("Dexie: handling persisted pageshow"),za(),ro({all:new nr(-1/0,[[]])}))})),Te.rejectionMapper=function(C,E){return!C||C instanceof z||C instanceof TypeError||C instanceof SyntaxError||!C.name||!Oe[C.name]?C:(E=new Oe[C.name](E||C.message,C),"stack"in C&&m(E,"stack",{get:function(){return this.inner.stack}}),E)},Ae(xe),s(Jr,Object.freeze({__proto__:null,Dexie:Jr,liveQuery:Ha,Entity:ln,cmp:mt,PropModification:at,replacePrefix:function(C,E){return new at({replacePrefix:[C,E]})},add:function(C){return new at({add:C})},remove:function(C){return new at({remove:C})},default:Jr,RangeSet:nr,mergeRanges:ls,rangesOverlap:Da}),{default:Jr}),Jr})}(ui)),ui.exports}var Ib=kb();const Zo=fh(Ib),qc=Symbol.for("Dexie"),Si=globalThis[qc]||(globalThis[qc]=Zo);if(Zo.semVer!==Si.semVer)throw new Error(`Two different versions of Dexie loaded in the same app: ${Zo.semVer} and ${Si.semVer}`);const{liveQuery:oy,mergeRanges:ay,rangesOverlap:ly,RangeSet:cy,cmp:uy,Entity:dy,PropModification:hy,replacePrefix:fy,add:py,remove:my}=Si;var Go=function(r,e){return Go=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,s){t.__proto__=s}||function(t,s){for(var u in s)Object.prototype.hasOwnProperty.call(s,u)&&(t[u]=s[u])},Go(r,e)};function gn(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Go(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function Ho(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],s=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&s>=r.length&&(r=void 0),{value:r&&r[s++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function xi(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var s=t.call(r),u,d=[],a;try{for(;(e===void 0||e-- >0)&&!(u=s.next()).done;)d.push(u.value)}catch(o){a={error:o}}finally{try{u&&!u.done&&(t=s.return)&&t.call(s)}finally{if(a)throw a.error}}return d}function Ci(r,e,t){if(t||arguments.length===2)for(var s=0,u=e.length,d;s<u;s++)(d||!(s in e))&&(d||(d=Array.prototype.slice.call(e,0,s)),d[s]=e[s]);return r.concat(d||Array.prototype.slice.call(e))}function zr(r){return typeof r=="function"}function ph(r){var e=function(s){Error.call(s),s.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var jo=ph(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
6547
6547
  `+t.map(function(s,u){return u+1+") "+s.toString()}).join(`
6548
- `):"",this.name="UnsubscriptionError",this.errors=t}});function ji(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var Ds=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,s,u,d;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var o=Ho(a),c=o.next();!c.done;c=o.next()){var i=c.value;i.remove(this)}}catch(f){e={error:f}}finally{try{c&&!c.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}else a.remove(this);var n=this.initialTeardown;if(zr(n))try{n()}catch(f){d=f instanceof jo?f.errors:[f]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var h=Ho(l),p=h.next();!p.done;p=h.next()){var m=p.value;try{Qc(m)}catch(f){d=d??[],f instanceof jo?d=Ci(Ci([],xi(d)),xi(f.errors)):d.push(f)}}}catch(f){s={error:f}}finally{try{p&&!p.done&&(u=h.return)&&u.call(h)}finally{if(s)throw s.error}}}if(d)throw new jo(d)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Qc(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ji(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&ji(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}(),mh=Ds.EMPTY;function vh(r){return r instanceof Ds||r&&"closed"in r&&zr(r.remove)&&zr(r.add)&&zr(r.unsubscribe)}function Qc(r){zr(r)?r():r.unsubscribe()}var Tb={Promise:void 0},Ob={setTimeout:function(r,e){for(var t=[],s=2;s<arguments.length;s++)t[s-2]=arguments[s];return setTimeout.apply(void 0,Ci([r,e],xi(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function Ab(r){Ob.setTimeout(function(){throw r})}function eu(){}function di(r){r()}var La=function(r){gn(e,r);function e(t){var s=r.call(this)||this;return s.isStopped=!1,t?(s.destination=t,vh(t)&&t.add(s)):s.destination=Nb,s}return e.create=function(t,s,u){return new zo(t,s,u)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Ds),Rb=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(s){ni(s)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(s){ni(s)}else ni(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){ni(t)}},r}(),zo=function(r){gn(e,r);function e(t,s,u){var d=r.call(this)||this,a;return zr(t)||!t?a={next:t??void 0,error:s??void 0,complete:u??void 0}:a=t,d.destination=new Rb(a),d}return e}(La);function ni(r){Ab(r)}function Lb(r){throw r}var Nb={closed:!0,next:eu,error:Lb,complete:eu},Pb=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Db(r){return r}function Mb(r){return r.length===0?Db:r.length===1?r[0]:function(t){return r.reduce(function(s,u){return u(s)},t)}}var tu=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,s){var u=this,d=$b(e)?e:new zo(e,t,s);return di(function(){var a=u,o=a.operator,c=a.source;d.add(o?o.call(d,c):c?u._subscribe(d):u._trySubscribe(d))}),d},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var s=this;return t=ru(t),new t(function(u,d){var a=new zo({next:function(o){try{e(o)}catch(c){d(c),a.unsubscribe()}},error:d,complete:u});s.subscribe(a)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Pb]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Mb(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=ru(e),new e(function(s,u){var d;t.subscribe(function(a){return d=a},function(a){return u(a)},function(){return s(d)})})},r.create=function(e){return new r(e)},r}();function ru(r){var e;return(e=r??Tb.Promise)!==null&&e!==void 0?e:Promise}function Bb(r){return r&&zr(r.next)&&zr(r.error)&&zr(r.complete)}function $b(r){return r&&r instanceof La||Bb(r)&&vh(r)}function Fb(r){return zr(r==null?void 0:r.lift)}function Vb(r){return function(e){if(Fb(e))return e.lift(function(t){try{return r(t,this)}catch(s){this.error(s)}});throw new TypeError("Unable to lift unknown Observable type")}}function Ub(r,e,t,s,u){return new Wb(r,e,t,s,u)}var Wb=function(r){gn(e,r);function e(t,s,u,d,a,o){var c=r.call(this,t)||this;return c.onFinalize=a,c.shouldUnsubscribe=o,c._next=s?function(i){try{s(i)}catch(n){t.error(n)}}:r.prototype._next,c._error=d?function(i){try{d(i)}catch(n){t.error(n)}finally{this.unsubscribe()}}:r.prototype._error,c._complete=u?function(){try{u()}catch(i){t.error(i)}finally{this.unsubscribe()}}:r.prototype._complete,c}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;r.prototype.unsubscribe.call(this),!s&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(La),Zb=ph(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),gh=function(r){gn(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var s=new nu(this,this);return s.operator=t,s},e.prototype._throwIfClosed=function(){if(this.closed)throw new Zb},e.prototype.next=function(t){var s=this;di(function(){var u,d;if(s._throwIfClosed(),!s.isStopped){s.currentObservers||(s.currentObservers=Array.from(s.observers));try{for(var a=Ho(s.currentObservers),o=a.next();!o.done;o=a.next()){var c=o.value;c.next(t)}}catch(i){u={error:i}}finally{try{o&&!o.done&&(d=a.return)&&d.call(a)}finally{if(u)throw u.error}}}})},e.prototype.error=function(t){var s=this;di(function(){if(s._throwIfClosed(),!s.isStopped){s.hasError=s.isStopped=!0,s.thrownError=t;for(var u=s.observers;u.length;)u.shift().error(t)}})},e.prototype.complete=function(){var t=this;di(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var s=t.observers;s.length;)s.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var s=this,u=this,d=u.hasError,a=u.isStopped,o=u.observers;return d||a?mh:(this.currentObservers=null,o.push(t),new Ds(function(){s.currentObservers=null,ji(o,t)}))},e.prototype._checkFinalizedStatuses=function(t){var s=this,u=s.hasError,d=s.thrownError,a=s.isStopped;u?t.error(d):a&&t.complete()},e.prototype.asObservable=function(){var t=new tu;return t.source=this,t},e.create=function(t,s){return new nu(t,s)},e}(tu),nu=function(r){gn(e,r);function e(t,s){var u=r.call(this)||this;return u.destination=t,u.source=s,u}return e.prototype.next=function(t){var s,u;(u=(s=this.destination)===null||s===void 0?void 0:s.next)===null||u===void 0||u.call(s,t)},e.prototype.error=function(t){var s,u;(u=(s=this.destination)===null||s===void 0?void 0:s.error)===null||u===void 0||u.call(s,t)},e.prototype.complete=function(){var t,s;(s=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||s===void 0||s.call(t)},e.prototype._subscribe=function(t){var s,u;return(u=(s=this.source)===null||s===void 0?void 0:s.subscribe(t))!==null&&u!==void 0?u:mh},e}(gh),Gb={now:function(){return Date.now()}},Hb=function(r){gn(e,r);function e(t,s){return r.call(this)||this}return e.prototype.schedule=function(t,s){return this},e}(Ds),su={setInterval:function(r,e){for(var t=[],s=2;s<arguments.length;s++)t[s-2]=arguments[s];return setInterval.apply(void 0,Ci([r,e],xi(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},zb=function(r){gn(e,r);function e(t,s){var u=r.call(this,t,s)||this;return u.scheduler=t,u.work=s,u.pending=!1,u}return e.prototype.schedule=function(t,s){var u;if(s===void 0&&(s=0),this.closed)return this;this.state=t;var d=this.id,a=this.scheduler;return d!=null&&(this.id=this.recycleAsyncId(a,d,s)),this.pending=!0,this.delay=s,this.id=(u=this.id)!==null&&u!==void 0?u:this.requestAsyncId(a,this.id,s),this},e.prototype.requestAsyncId=function(t,s,u){return u===void 0&&(u=0),su.setInterval(t.flush.bind(t,this),u)},e.prototype.recycleAsyncId=function(t,s,u){if(u===void 0&&(u=0),u!=null&&this.delay===u&&this.pending===!1)return s;s!=null&&su.clearInterval(s)},e.prototype.execute=function(t,s){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var u=this._execute(t,s);if(u)return u;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,s){var u=!1,d;try{this.work(t)}catch(a){u=!0,d=a||new Error("Scheduled action threw falsy error")}if(u)return this.unsubscribe(),d},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,s=t.id,u=t.scheduler,d=u.actions;this.work=this.state=this.scheduler=null,this.pending=!1,ji(d,this),s!=null&&(this.id=this.recycleAsyncId(u,s,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e}(Hb),iu=function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,s){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(s,t)},r.now=Gb.now,r}(),Kb=function(r){gn(e,r);function e(t,s){s===void 0&&(s=iu.now);var u=r.call(this,t,s)||this;return u.actions=[],u._active=!1,u}return e.prototype.flush=function(t){var s=this.actions;if(this._active){s.push(t);return}var u;this._active=!0;do if(u=t.execute(t.state,t.delay))break;while(t=s.shift());if(this._active=!1,u){for(;t=s.shift();)t.unsubscribe();throw u}},e}(iu),Xb=new Kb(zb);function Yb(r,e){return e===void 0&&(e=Xb),Vb(function(t,s){var u=null,d=null,a=null,o=function(){if(u){u.unsubscribe(),u=null;var i=d;d=null,s.next(i)}};function c(){var i=a+r,n=e.now();if(n<i){u=this.schedule(void 0,i-n),s.add(u);return}o()}t.subscribe(Ub(s,function(i){d=i,a=e.now(),u||(u=e.schedule(c,r),s.add(u))},function(){o(),s.complete()},void 0,function(){d=u=null}))})}class Jb extends Si{constructor(t,s,u){super(t);cs(this,"sessions");cs(this,"principal");cs(this,"client");cs(this,"saveSubject",new gh);this.principal=s,this.client=u,this.version(1).stores({sessions:"id, principal, name, created, updated"}),this.saveSubject.pipe(Yb(200)).subscribe(async({id:d,notebook:a})=>{const o={id:d,principal:this.principal,name:bh(),created:Date.now(),updated:Date.now(),data:a};console.log(new Date().toISOString(),"saving Notebook",d,a),await this.sessions.put(o)})}async saveNotebook(t,s){this.saveSubject.next({id:t,notebook:s})}async loadSession(t){return this.sessions.get(t)}async loadSessions(t){return(await this.sessions.bulkGet(t)).filter(u=>!!u)}async listSessions(){return this.sessions.orderBy("updated").reverse().toArray()}query(){return this.sessions.where("principal").equals(this.principal)}async listActiveSessions(){const t=Date.now(),s=t-1440*60*1e3,u=await this.query().and(o=>o.updated>=s).and(o=>o.updated<=t).reverse().primaryKeys();let d=[];try{d=await Promise.all(u.map(o=>this.client.getSession(vt.create(Bg,{id:o})).catch(c=>{const i=At.from(c);if(!(i.code===xt.Unknown&&i.message.includes("session not found")))throw c})))}catch(o){return console.error("Error listing active sessions",o),[]}return d.map(o=>{var c;return(c=o==null?void 0:o.session)==null?void 0:c.id}).filter(o=>!!o)}async deleteSession(t){await this.sessions.delete(t)}async createSession(){var t;try{return(t=(await this.client.createSession({project:vt.create(Pg,{root:".",envLoadOrder:[".env",".env.local",".env.development",".env.dev"]}),config:{envStoreSeeding:Mg.SYSTEM}})).session)==null?void 0:t.id}catch(s){console.error("Error creating session",s);return}}}function bh(){return new Date().toISOString()}class ps extends Error{}ps.prototype.name="InvalidTokenError";function qb(r){return decodeURIComponent(atob(r).replace(/(.)/g,(e,t)=>{let s=t.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}function Qb(r){let e=r.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return qb(e)}catch{return atob(e)}}function yh(r,e){if(typeof r!="string")throw new ps("Invalid token specified: must be a string");e||(e={});const t=e.header===!0?0:1,s=r.split(".")[t];if(typeof s!="string")throw new ps(`Invalid token specified: missing part #${t+1}`);let u;try{u=Qb(s)}catch(d){throw new ps(`Invalid token specified: invalid base64 for part #${t+1} (${d.message})`)}try{return JSON.parse(u)}catch(d){throw new ps(`Invalid token specified: invalid json for part #${t+1} (${d.message})`)}}const _h="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Ei=32,e0=16,wh=10,ou=0xffffffffffff;var On;(function(r){r.Base32IncorrectEncoding="B32_ENC_INVALID",r.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",r.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",r.EncodeTimeNegative="ENC_TIME_NEG",r.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",r.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",r.PRNGDetectFailure="PRNG_DETECT",r.ULIDInvalid="ULID_INVALID",r.Unexpected="UNEXPECTED",r.UUIDInvalid="UUID_INVALID"})(On||(On={}));class ms extends Error{constructor(e,t){super(`${t} (${e})`),this.name="ULIDError",this.code=e}}function t0(r){const e=Math.floor(r()*Ei)%Ei;return _h.charAt(e)}function r0(r){const e=n0(),t=e&&(e.crypto||e.msCrypto)||null;if(typeof(t==null?void 0:t.getRandomValues)=="function")return()=>{const s=new Uint8Array(1);return t.getRandomValues(s),s[0]/255};if(typeof(t==null?void 0:t.randomBytes)=="function")return()=>t.randomBytes(1).readUInt8()/255;throw new ms(On.PRNGDetectFailure,"Failed to find a reliable PRNG")}function n0(){return o0()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function s0(r,e){let t="";for(;r>0;r--)t=t0(e)+t;return t}function i0(r,e=wh){if(isNaN(r))throw new ms(On.EncodeTimeValueMalformed,`Time must be a number: ${r}`);if(r>ou)throw new ms(On.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ou}: ${r}`);if(r<0)throw new ms(On.EncodeTimeNegative,`Time must be positive: ${r}`);if(Number.isInteger(r)===!1)throw new ms(On.EncodeTimeValueMalformed,`Time must be an integer: ${r}`);let t,s="";for(let u=e;u>0;u--)t=r%Ei,s=_h.charAt(t)+s,r=(r-t)/Ei;return s}function o0(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function a0(r,e){const t=r0(),s=Date.now();return i0(s,wh)+s0(e0,t)}const Sh=Be.createContext(void 0),Tr=()=>{const r=Be.useContext(Sh);if(!r)throw new Error("useSettings must be used within a SettingsProvider");return r},xh=({children:r,requireAuth:e,webApp:t})=>{const[s,u]=Be.useState(null),d=Be.useMemo(()=>{const h=_i();if(!h)return"unauthenticated";let p;try{return p=yh(h),p.email||p.sub||"unauthenticated"}catch(m){return console.error("Error decoding token",m),"unauthenticated"}},[]),a=Be.useMemo(()=>{const h=window.location.hostname==="localhost",p=window.location.protocol==="http:",m=window.location.port==="4173"||window.location.port==="5173",f=h&&p&&m;let v=new URL(window.location.href);t!=null&&t.runner&&(v=new URL(t.runner));const g={requireAuth:!1,agentEndpoint:f?"http://localhost:8080":window.location.origin,webApp:{runner:f?"ws://localhost:8080/ws":`${v.protocol==="https:"?"wss:":"ws:"}//${v.host}/ws`,reconnect:(t==null?void 0:t.reconnect)??!0,invertedOrder:(t==null?void 0:t.invertedOrder)??!1}};return e!==void 0&&(g.requireAuth=e),g},[e,t]),[o,c]=Be.useState(()=>{const h=localStorage.getItem("cloudAssistantSettings"),p=h?JSON.parse(h):{};return p&&p.webApp&&p.webApp.reconnect!==void 0&&(p.webApp.reconnect=a.webApp.reconnect),h?{...a,...p}:a});Be.useEffect(()=>{localStorage.setItem("cloudAssistantSettings",JSON.stringify(o))},[o]);const i=Be.useCallback(h=>{const p=m=>{const f=At.from(m);f.code===xt.Unauthenticated&&(window.location.href=`/login?error=${encodeURIComponent(f.name)}&error_description=${encodeURIComponent(f.message)}`)};return[m=>async f=>{const v=_i();return v&&f.header.set("Authorization",`Bearer ${v}`),h?m(f).catch(g=>{throw p(g),g}):m(f)}]},[]),n=Be.useCallback(async()=>{if(!o.webApp.runner)return;u(null);const h=new kd({knownID:`check_${a0()}`,runID:Id(),sequence:0,options:{runnerEndpoint:o.webApp.runner,interceptors:i(!1),autoReconnect:!1}}),p=[];return p.push(h.errors.subscribe({next:m=>u(m)})),p.push(h.connect(Ed.INITIAL).subscribe(m=>{m!==null&&(console.log(`Initial heartbeat latency for streamID ${m.streamID} (${m.readyState===1?"open":"closed"}): ${m.latency}ms`),h.close())})),()=>{p.forEach(m=>m.unsubscribe())}},[i,o.webApp.runner]);Be.useEffect(()=>{n()},[n]);const l=h=>{c(p=>({...p,...h,webApp:{...p.webApp,...h.webApp}}))};return ae.jsx(Sh.Provider,{value:{principal:d,checkRunnerAuth:n,createAuthInterceptors:i,defaultSettings:a,runnerError:s,settings:o,updateSettings:l},children:r})},Ch=Be.createContext(void 0),jh=()=>{const r=Be.useContext(Ch);if(!r)throw new Error("useClient must be used within a ClientProvider");return r},Eh=({children:r})=>{const[e,t]=Be.useState(),{settings:s,createAuthInterceptors:u}=Tr();return Be.useEffect(()=>{t(l0(s.agentEndpoint,u(!0)))},[s.agentEndpoint,u]),ae.jsx(Ch.Provider,{value:{client:e,setClient:t},children:r})};function l0(r,e){console.log(`initializing the client: baseURL ${r}`);const t=hh({baseUrl:r,interceptors:e});return sh(Tg,t)}const kh=Be.createContext(void 0),an=()=>{const r=Be.useContext(kh);if(!r)throw new Error("useCell must be used within a CellProvider");return r};function au(r,e){if(!r)return[];const t=r.positions.map(s=>{const u=r.cells[s];return u.languageId="sh",u});return t.length===0?[]:e?t.reverse():t}const Ih=({children:r})=>{const{settings:e,principal:t}=Tr(),[s,u]=Be.useState(0),[d,a]=Be.useState(!1),[o,c]=Be.useState(!1),[i,n]=Be.useState(),l=Be.useMemo(()=>{if(t)return new Jb("agent",t,Yc($g,e.agentEndpoint))},[e.agentEndpoint,t]),h=()=>{u(W=>W+1)},p=Be.useMemo(()=>e.webApp.invertedOrder,[e.webApp.invertedOrder]),{client:m}=jh(),[f,v]=Be.useState(void 0),g=Be.useCallback(()=>{if(!f)return;const W=au(f,p),ne=vt.create(Tc,{cells:W});i&&(ne.metadata[Wo.PreviousResponseId]=i),l==null||l.saveNotebook(f.runmeSession,ne)},[f,p,i,l]),b=Be.useCallback(async({attemptRestore:W})=>{if(!l)return;u(0),n(void 0);const ne=l.createSession();let q;if(!W)q=await ne;else{const L=await l.listActiveSessions(),B=(await l.loadSessions(L)).filter(K=>K.data.cells.length!==0);if(B.length===0)q=await ne;else{const K=B[0];let U=K.data.cells.map(te=>te.refId);p&&(U=U.reverse());const z=K.data.metadata[Wo.PreviousResponseId];z&&n(z),v({runmeSession:K.id,cells:K.data.cells.reduce((te,se)=>(te[se.refId]=se,te),{}),positions:U});return}}v({runmeSession:q,cells:{},positions:[]})},[p,l]);Be.useEffect(()=>{g()},[f,l,p,g]),Be.useEffect(()=>{v(W=>({runmeSession:(W==null?void 0:W.runmeSession)??"",cells:(W==null?void 0:W.cells)??{},positions:[...(W==null?void 0:W.positions)??[]].reverse()}))},[p]),Be.useEffect(()=>{b&&b({attemptRestore:!0})},[b]);const y=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&(W.kind===Ir.MARKUP||W.kind===Ir.CODE)):[],[f]),_=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&W.kind===Ir.CODE):[],[f]),w=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&W.kind===Ir.DOC_RESULTS):[],[f]),x=()=>({chat:y,actions:_,files:w}),S=W=>vt.clone(_s,W),j=async W=>{const ne=Cb(),q=vt.create(Ig,{cells:W,previousResponseId:i});q.openaiAccessToken=ne.accessToken,ne.accessToken||console.error("No access token found");try{const L=m.generate(q);for await(const $ of L){for(const B of $.cells)c(!1),T(B);n($.responseId)}}catch(L){console.log(L)}finally{c(!1),a(!1)}},k=async W=>{if(!W.trim())return;const ne=vt.create(_s,{refId:`user_${Lc()}`,role:on.USER,kind:Ir.MARKUP,value:W});T(ne),a(!0),c(!0),await j([ne])},O=async W=>{W.outputs.length!==0&&(console.log("sending output cell",W.refId,"previousResponseId",i),a(!0),c(!0),await j([W]))},T=W=>{v(ne=>{if(ne){if(!ne.cells[W.refId]){const q=p?[W.refId,...ne.positions]:[...ne.positions,W.refId];return{runmeSession:ne.runmeSession,cells:{...ne.cells,[W.refId]:W},positions:q}}return{...ne,runmeSession:ne.runmeSession,cells:{...ne.cells,[W.refId]:W}}}})},R=()=>{const W=`code_${Lc().replace(/-/g,"")}`,ne=vt.create(_s,{metadata:{[Dr.ID]:W,[Dr.RunmeID]:W},refId:W,role:on.USER,kind:Ir.CODE,value:""});T(ne)},F=W=>{if(_.find(q=>q.refId===W.refId)){const q=new CustomEvent("runCodeCell",{detail:{cellId:W.refId}});window.dispatchEvent(q)}},H=async({asSessionRecord:W})=>{var se;const ne=au(f,p);if(!f||ne.length===0)return;const q=vt.create(Tc,{cells:ne}),L=Yc(kg,e.agentEndpoint),$=vt.create(Cg,{notebook:q,options:vt.create(xg,{outputs:vt.create(Sg,{enabled:!1,summary:!1})})});W&&((se=$.options)!=null&&se.outputs)&&($.options.outputs.enabled=!0,$.options.outputs.summary=!0,$.options.session=vt.create(wg,{id:f.runmeSession}));const B=await L.serialize($),K=new Blob([B.result],{type:"text/plain"}),U=URL.createObjectURL(K),z=document.createElement("a");z.href=U;const te=W?"Session":"Notebook";z.download=`${te}-${bh()}.md`,document.body.appendChild(z),z.click(),document.body.removeChild(z),URL.revokeObjectURL(U)};return ae.jsx(kh.Provider,{value:{useColumns:x,sequence:s,incrementSequence:h,saveState:g,exportDocument:H,sendOutputCell:O,createOutputCell:S,sendUserCell:k,addCodeCell:R,isInputDisabled:d,isTyping:o,runCodeCell:F,resetSession:b},children:r})},lu=new TextEncoder;function c0({pid:r,exitCode:e},t,s,u){let d;return r!==null&&e!==null&&(d=vt.create(yg,{pid:BigInt(r),exitReason:vt.create(bg,{type:"exit",code:e})})),[vt.create(Ac,{items:[vt.create(Oc,{mime:wi.VSCodeNotebookStdOut,type:"Buffer",data:lu.encode(t)})],processInfo:d}),vt.create(Ac,{items:[vt.create(Oc,{mime:wi.VSCodeNotebookStdErr,type:"Buffer",data:lu.encode(s)})]})]}const u0=vt.create(_s,{kind:Ir.MARKUP,role:on.ASSISTANT,value:"..."}),d0=Be.memo(({cellID:r,runID:e,sequence:t,value:s,content:u,settings:d={},onStdout:a,onStderr:o,onExitCode:c,onPid:i,onMimeType:n})=>{const{createAuthInterceptors:l,settings:{webApp:h}}=Tr();return(s!=""&&e!=""||u&&u.length>0)&&ae.jsx(ev,{cellID:r,runID:e,sequence:t,commands:s.split(`
6548
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function ji(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var Ds=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,s,u,d;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var o=Ho(a),c=o.next();!c.done;c=o.next()){var i=c.value;i.remove(this)}}catch(f){e={error:f}}finally{try{c&&!c.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}else a.remove(this);var n=this.initialTeardown;if(zr(n))try{n()}catch(f){d=f instanceof jo?f.errors:[f]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var h=Ho(l),p=h.next();!p.done;p=h.next()){var m=p.value;try{Qc(m)}catch(f){d=d??[],f instanceof jo?d=Ci(Ci([],xi(d)),xi(f.errors)):d.push(f)}}}catch(f){s={error:f}}finally{try{p&&!p.done&&(u=h.return)&&u.call(h)}finally{if(s)throw s.error}}}if(d)throw new jo(d)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Qc(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ji(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&ji(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}(),mh=Ds.EMPTY;function vh(r){return r instanceof Ds||r&&"closed"in r&&zr(r.remove)&&zr(r.add)&&zr(r.unsubscribe)}function Qc(r){zr(r)?r():r.unsubscribe()}var Tb={Promise:void 0},Ob={setTimeout:function(r,e){for(var t=[],s=2;s<arguments.length;s++)t[s-2]=arguments[s];return setTimeout.apply(void 0,Ci([r,e],xi(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function Ab(r){Ob.setTimeout(function(){throw r})}function eu(){}function di(r){r()}var La=function(r){gn(e,r);function e(t){var s=r.call(this)||this;return s.isStopped=!1,t?(s.destination=t,vh(t)&&t.add(s)):s.destination=Nb,s}return e.create=function(t,s,u){return new zo(t,s,u)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Ds),Rb=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(s){ni(s)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(s){ni(s)}else ni(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){ni(t)}},r}(),zo=function(r){gn(e,r);function e(t,s,u){var d=r.call(this)||this,a;return zr(t)||!t?a={next:t??void 0,error:s??void 0,complete:u??void 0}:a=t,d.destination=new Rb(a),d}return e}(La);function ni(r){Ab(r)}function Lb(r){throw r}var Nb={closed:!0,next:eu,error:Lb,complete:eu},Pb=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Db(r){return r}function Mb(r){return r.length===0?Db:r.length===1?r[0]:function(t){return r.reduce(function(s,u){return u(s)},t)}}var tu=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,s){var u=this,d=$b(e)?e:new zo(e,t,s);return di(function(){var a=u,o=a.operator,c=a.source;d.add(o?o.call(d,c):c?u._subscribe(d):u._trySubscribe(d))}),d},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var s=this;return t=ru(t),new t(function(u,d){var a=new zo({next:function(o){try{e(o)}catch(c){d(c),a.unsubscribe()}},error:d,complete:u});s.subscribe(a)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Pb]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Mb(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=ru(e),new e(function(s,u){var d;t.subscribe(function(a){return d=a},function(a){return u(a)},function(){return s(d)})})},r.create=function(e){return new r(e)},r}();function ru(r){var e;return(e=r??Tb.Promise)!==null&&e!==void 0?e:Promise}function Bb(r){return r&&zr(r.next)&&zr(r.error)&&zr(r.complete)}function $b(r){return r&&r instanceof La||Bb(r)&&vh(r)}function Fb(r){return zr(r==null?void 0:r.lift)}function Vb(r){return function(e){if(Fb(e))return e.lift(function(t){try{return r(t,this)}catch(s){this.error(s)}});throw new TypeError("Unable to lift unknown Observable type")}}function Ub(r,e,t,s,u){return new Wb(r,e,t,s,u)}var Wb=function(r){gn(e,r);function e(t,s,u,d,a,o){var c=r.call(this,t)||this;return c.onFinalize=a,c.shouldUnsubscribe=o,c._next=s?function(i){try{s(i)}catch(n){t.error(n)}}:r.prototype._next,c._error=d?function(i){try{d(i)}catch(n){t.error(n)}finally{this.unsubscribe()}}:r.prototype._error,c._complete=u?function(){try{u()}catch(i){t.error(i)}finally{this.unsubscribe()}}:r.prototype._complete,c}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;r.prototype.unsubscribe.call(this),!s&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(La),Zb=ph(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),gh=function(r){gn(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var s=new nu(this,this);return s.operator=t,s},e.prototype._throwIfClosed=function(){if(this.closed)throw new Zb},e.prototype.next=function(t){var s=this;di(function(){var u,d;if(s._throwIfClosed(),!s.isStopped){s.currentObservers||(s.currentObservers=Array.from(s.observers));try{for(var a=Ho(s.currentObservers),o=a.next();!o.done;o=a.next()){var c=o.value;c.next(t)}}catch(i){u={error:i}}finally{try{o&&!o.done&&(d=a.return)&&d.call(a)}finally{if(u)throw u.error}}}})},e.prototype.error=function(t){var s=this;di(function(){if(s._throwIfClosed(),!s.isStopped){s.hasError=s.isStopped=!0,s.thrownError=t;for(var u=s.observers;u.length;)u.shift().error(t)}})},e.prototype.complete=function(){var t=this;di(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var s=t.observers;s.length;)s.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var s=this,u=this,d=u.hasError,a=u.isStopped,o=u.observers;return d||a?mh:(this.currentObservers=null,o.push(t),new Ds(function(){s.currentObservers=null,ji(o,t)}))},e.prototype._checkFinalizedStatuses=function(t){var s=this,u=s.hasError,d=s.thrownError,a=s.isStopped;u?t.error(d):a&&t.complete()},e.prototype.asObservable=function(){var t=new tu;return t.source=this,t},e.create=function(t,s){return new nu(t,s)},e}(tu),nu=function(r){gn(e,r);function e(t,s){var u=r.call(this)||this;return u.destination=t,u.source=s,u}return e.prototype.next=function(t){var s,u;(u=(s=this.destination)===null||s===void 0?void 0:s.next)===null||u===void 0||u.call(s,t)},e.prototype.error=function(t){var s,u;(u=(s=this.destination)===null||s===void 0?void 0:s.error)===null||u===void 0||u.call(s,t)},e.prototype.complete=function(){var t,s;(s=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||s===void 0||s.call(t)},e.prototype._subscribe=function(t){var s,u;return(u=(s=this.source)===null||s===void 0?void 0:s.subscribe(t))!==null&&u!==void 0?u:mh},e}(gh),Gb={now:function(){return Date.now()}},Hb=function(r){gn(e,r);function e(t,s){return r.call(this)||this}return e.prototype.schedule=function(t,s){return this},e}(Ds),su={setInterval:function(r,e){for(var t=[],s=2;s<arguments.length;s++)t[s-2]=arguments[s];return setInterval.apply(void 0,Ci([r,e],xi(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},zb=function(r){gn(e,r);function e(t,s){var u=r.call(this,t,s)||this;return u.scheduler=t,u.work=s,u.pending=!1,u}return e.prototype.schedule=function(t,s){var u;if(s===void 0&&(s=0),this.closed)return this;this.state=t;var d=this.id,a=this.scheduler;return d!=null&&(this.id=this.recycleAsyncId(a,d,s)),this.pending=!0,this.delay=s,this.id=(u=this.id)!==null&&u!==void 0?u:this.requestAsyncId(a,this.id,s),this},e.prototype.requestAsyncId=function(t,s,u){return u===void 0&&(u=0),su.setInterval(t.flush.bind(t,this),u)},e.prototype.recycleAsyncId=function(t,s,u){if(u===void 0&&(u=0),u!=null&&this.delay===u&&this.pending===!1)return s;s!=null&&su.clearInterval(s)},e.prototype.execute=function(t,s){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var u=this._execute(t,s);if(u)return u;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,s){var u=!1,d;try{this.work(t)}catch(a){u=!0,d=a||new Error("Scheduled action threw falsy error")}if(u)return this.unsubscribe(),d},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,s=t.id,u=t.scheduler,d=u.actions;this.work=this.state=this.scheduler=null,this.pending=!1,ji(d,this),s!=null&&(this.id=this.recycleAsyncId(u,s,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e}(Hb),iu=function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,s){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(s,t)},r.now=Gb.now,r}(),Kb=function(r){gn(e,r);function e(t,s){s===void 0&&(s=iu.now);var u=r.call(this,t,s)||this;return u.actions=[],u._active=!1,u}return e.prototype.flush=function(t){var s=this.actions;if(this._active){s.push(t);return}var u;this._active=!0;do if(u=t.execute(t.state,t.delay))break;while(t=s.shift());if(this._active=!1,u){for(;t=s.shift();)t.unsubscribe();throw u}},e}(iu),Xb=new Kb(zb);function Yb(r,e){return e===void 0&&(e=Xb),Vb(function(t,s){var u=null,d=null,a=null,o=function(){if(u){u.unsubscribe(),u=null;var i=d;d=null,s.next(i)}};function c(){var i=a+r,n=e.now();if(n<i){u=this.schedule(void 0,i-n),s.add(u);return}o()}t.subscribe(Ub(s,function(i){d=i,a=e.now(),u||(u=e.schedule(c,r),s.add(u))},function(){o(),s.complete()},void 0,function(){d=u=null}))})}class Jb extends Si{constructor(t,s,u){super(t);cs(this,"sessions");cs(this,"principal");cs(this,"client");cs(this,"saveSubject",new gh);this.principal=s,this.client=u,this.version(1).stores({sessions:"id, principal, name, created, updated"}),this.saveSubject.pipe(Yb(200)).subscribe(async({id:d,notebook:a})=>{const o={id:d,principal:this.principal,name:bh(),created:Date.now(),updated:Date.now(),data:a};console.log(new Date().toISOString(),"saving Notebook",d,a),await this.sessions.put(o)})}async saveNotebook(t,s){this.saveSubject.next({id:t,notebook:s})}async loadSession(t){return this.sessions.get(t)}async loadSessions(t){return(await this.sessions.bulkGet(t)).filter(u=>!!u)}async listSessions(){return this.sessions.orderBy("updated").reverse().toArray()}query(){return this.sessions.where("principal").equals(this.principal)}async listActiveSessions(){const t=Date.now(),s=t-1440*60*1e3,u=await this.query().and(o=>o.updated>=s).and(o=>o.updated<=t).reverse().primaryKeys();let d=[];try{d=await Promise.all(u.map(o=>this.client.getSession(vt.create(Bg,{id:o})).catch(c=>{const i=At.from(c);if(!(i.code===xt.Unknown&&i.message.includes("session not found")))throw c})))}catch(o){return console.error("Error listing active sessions",o),[]}return d.map(o=>{var c;return(c=o==null?void 0:o.session)==null?void 0:c.id}).filter(o=>!!o)}async deleteSession(t){await this.sessions.delete(t)}async createSession(){var t;try{return(t=(await this.client.createSession({project:vt.create(Pg,{root:".",envLoadOrder:[".env",".env.local",".env.development",".env.dev"]}),config:{envStoreSeeding:Mg.SYSTEM}})).session)==null?void 0:t.id}catch(s){console.error("Error creating session",s);return}}}function bh(){return new Date().toISOString()}class ps extends Error{}ps.prototype.name="InvalidTokenError";function qb(r){return decodeURIComponent(atob(r).replace(/(.)/g,(e,t)=>{let s=t.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}function Qb(r){let e=r.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return qb(e)}catch{return atob(e)}}function yh(r,e){if(typeof r!="string")throw new ps("Invalid token specified: must be a string");e||(e={});const t=e.header===!0?0:1,s=r.split(".")[t];if(typeof s!="string")throw new ps(`Invalid token specified: missing part #${t+1}`);let u;try{u=Qb(s)}catch(d){throw new ps(`Invalid token specified: invalid base64 for part #${t+1} (${d.message})`)}try{return JSON.parse(u)}catch(d){throw new ps(`Invalid token specified: invalid json for part #${t+1} (${d.message})`)}}const _h="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Ei=32,e0=16,wh=10,ou=0xffffffffffff;var On;(function(r){r.Base32IncorrectEncoding="B32_ENC_INVALID",r.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",r.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",r.EncodeTimeNegative="ENC_TIME_NEG",r.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",r.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",r.PRNGDetectFailure="PRNG_DETECT",r.ULIDInvalid="ULID_INVALID",r.Unexpected="UNEXPECTED",r.UUIDInvalid="UUID_INVALID"})(On||(On={}));class ms extends Error{constructor(e,t){super(`${t} (${e})`),this.name="ULIDError",this.code=e}}function t0(r){const e=Math.floor(r()*Ei)%Ei;return _h.charAt(e)}function r0(r){const e=n0(),t=e&&(e.crypto||e.msCrypto)||null;if(typeof(t==null?void 0:t.getRandomValues)=="function")return()=>{const s=new Uint8Array(1);return t.getRandomValues(s),s[0]/255};if(typeof(t==null?void 0:t.randomBytes)=="function")return()=>t.randomBytes(1).readUInt8()/255;throw new ms(On.PRNGDetectFailure,"Failed to find a reliable PRNG")}function n0(){return o0()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function s0(r,e){let t="";for(;r>0;r--)t=t0(e)+t;return t}function i0(r,e=wh){if(isNaN(r))throw new ms(On.EncodeTimeValueMalformed,`Time must be a number: ${r}`);if(r>ou)throw new ms(On.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ou}: ${r}`);if(r<0)throw new ms(On.EncodeTimeNegative,`Time must be positive: ${r}`);if(Number.isInteger(r)===!1)throw new ms(On.EncodeTimeValueMalformed,`Time must be an integer: ${r}`);let t,s="";for(let u=e;u>0;u--)t=r%Ei,s=_h.charAt(t)+s,r=(r-t)/Ei;return s}function o0(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function a0(r,e){const t=r0(),s=Date.now();return i0(s,wh)+s0(e0,t)}const Sh=Be.createContext(void 0),Tr=()=>{const r=Be.useContext(Sh);if(!r)throw new Error("useSettings must be used within a SettingsProvider");return r},xh=({children:r,requireAuth:e,webApp:t})=>{const[s,u]=Be.useState(null),d=Be.useMemo(()=>{const h=_i();if(!h)return"unauthenticated";let p;try{return p=yh(h),p.email||p.sub||"unauthenticated"}catch(m){return console.error("Error decoding token",m),"unauthenticated"}},[]),a=Be.useMemo(()=>{const h=window.location.hostname==="localhost",p=window.location.protocol==="http:",m=window.location.port==="4173"||window.location.port==="5173",f=h&&p&&m;let v=new URL(window.location.href);t!=null&&t.runner&&(v=new URL(t.runner));const g={requireAuth:!1,agentEndpoint:f?"http://localhost:8080":window.location.origin,webApp:{runner:f?"ws://localhost:8080/ws":`${v.protocol==="https:"?"wss:":"ws:"}//${v.host}/ws`,reconnect:(t==null?void 0:t.reconnect)??!0,invertedOrder:(t==null?void 0:t.invertedOrder)??!1}};return e!==void 0&&(g.requireAuth=e),g},[e,t]),[o,c]=Be.useState(()=>{const h=localStorage.getItem("cloudAssistantSettings"),p=h?JSON.parse(h):{};return p&&p.webApp&&p.webApp.reconnect!==void 0&&(p.webApp.reconnect=a.webApp.reconnect),h?{...a,...p}:a});Be.useEffect(()=>{localStorage.setItem("cloudAssistantSettings",JSON.stringify(o))},[o]);const i=Be.useCallback(h=>{const p=m=>{const f=At.from(m);f.code===xt.Unauthenticated&&(window.location.href=`/login?error=${encodeURIComponent(f.name)}&error_description=${encodeURIComponent(f.message)}`)};return[m=>async f=>{const v=_i();return v&&f.header.set("Authorization",`Bearer ${v}`),h?m(f).catch(g=>{throw p(g),g}):m(f)}]},[]),n=Be.useCallback(async()=>{if(!o.webApp.runner)return;u(null);const h=new kd({knownID:`check_${a0()}`,runID:Id(),sequence:0,options:{runnerEndpoint:o.webApp.runner,interceptors:i(!1),autoReconnect:!1}}),p=[];return p.push(h.errors.subscribe({next:m=>u(m)})),p.push(h.connect(Ed.INITIAL).subscribe(m=>{m!==null&&(console.log(`Initial heartbeat latency for streamID ${m.streamID} (${m.readyState===1?"open":"closed"}): ${m.latency}ms`),h.close())})),()=>{p.forEach(m=>m.unsubscribe())}},[i,o.webApp.runner]);Be.useEffect(()=>{n()},[n]);const l=h=>{c(p=>({...p,...h,webApp:{...p.webApp,...h.webApp}}))};return ae.jsx(Sh.Provider,{value:{principal:d,checkRunnerAuth:n,createAuthInterceptors:i,defaultSettings:a,runnerError:s,settings:o,updateSettings:l},children:r})},Ch=Be.createContext(void 0),jh=()=>{const r=Be.useContext(Ch);if(!r)throw new Error("useClient must be used within a ClientProvider");return r},Eh=({children:r})=>{const[e,t]=Be.useState(),{settings:s,createAuthInterceptors:u}=Tr();return Be.useEffect(()=>{t(l0(s.agentEndpoint,u(!0)))},[s.agentEndpoint,u]),ae.jsx(Ch.Provider,{value:{client:e,setClient:t},children:r})};function l0(r,e){console.log(`initializing the client: baseURL ${r}`);const t=hh({baseUrl:r,interceptors:e});return sh(Tg,t)}const kh=Be.createContext(void 0),an=()=>{const r=Be.useContext(kh);if(!r)throw new Error("useCell must be used within a CellProvider");return r};function au(r,e){if(!r)return[];const t=r.positions.map(s=>{const u=r.cells[s];return u.languageId="sh",u});return t.length===0?[]:e?t.reverse():t}const Ih=({children:r})=>{const{settings:e,principal:t}=Tr(),[s,u]=Be.useState(0),[d,a]=Be.useState(!1),[o,c]=Be.useState(!1),[i,n]=Be.useState(),l=Be.useMemo(()=>{if(t)return new Jb("agent",t,Yc($g,e.webApp.runner))},[e.agentEndpoint,t]),h=()=>{u(W=>W+1)},p=Be.useMemo(()=>e.webApp.invertedOrder,[e.webApp.invertedOrder]),{client:m}=jh(),[f,v]=Be.useState(void 0),g=Be.useCallback(()=>{if(!f)return;const W=au(f,p),ne=vt.create(Tc,{cells:W});i&&(ne.metadata[Wo.PreviousResponseId]=i),l==null||l.saveNotebook(f.runmeSession,ne)},[f,p,i,l]),b=Be.useCallback(async({attemptRestore:W})=>{if(!l)return;u(0),n(void 0);const ne=l.createSession();let q;if(!W)q=await ne;else{const L=await l.listActiveSessions(),B=(await l.loadSessions(L)).filter(K=>K.data.cells.length!==0);if(B.length===0)q=await ne;else{const K=B[0];let U=K.data.cells.map(te=>te.refId);p&&(U=U.reverse());const z=K.data.metadata[Wo.PreviousResponseId];z&&n(z),v({runmeSession:K.id,cells:K.data.cells.reduce((te,se)=>(te[se.refId]=se,te),{}),positions:U});return}}v({runmeSession:q,cells:{},positions:[]})},[p,l]);Be.useEffect(()=>{g()},[f,l,p,g]),Be.useEffect(()=>{v(W=>({runmeSession:(W==null?void 0:W.runmeSession)??"",cells:(W==null?void 0:W.cells)??{},positions:[...(W==null?void 0:W.positions)??[]].reverse()}))},[p]),Be.useEffect(()=>{b&&b({attemptRestore:!0})},[b]);const y=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&(W.kind===Ir.MARKUP||W.kind===Ir.CODE)):[],[f]),_=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&W.kind===Ir.CODE):[],[f]),w=Be.useMemo(()=>f?f.positions.map(W=>f.cells[W]).filter(W=>!!W&&W.kind===Ir.DOC_RESULTS):[],[f]),x=()=>({chat:y,actions:_,files:w}),S=W=>vt.clone(_s,W),j=async W=>{const ne=Cb(),q=vt.create(Ig,{cells:W,previousResponseId:i});q.openaiAccessToken=ne.accessToken,ne.accessToken||console.error("No access token found");try{const L=m.generate(q);for await(const $ of L){for(const B of $.cells)c(!1),T(B);n($.responseId)}}catch(L){console.log(L)}finally{c(!1),a(!1)}},k=async W=>{if(!W.trim())return;const ne=vt.create(_s,{refId:`user_${Lc()}`,role:on.USER,kind:Ir.MARKUP,value:W});T(ne),a(!0),c(!0),await j([ne])},O=async W=>{W.outputs.length!==0&&(console.log("sending output cell",W.refId,"previousResponseId",i),a(!0),c(!0),await j([W]))},T=W=>{v(ne=>{if(ne){if(!ne.cells[W.refId]){const q=p?[W.refId,...ne.positions]:[...ne.positions,W.refId];return{runmeSession:ne.runmeSession,cells:{...ne.cells,[W.refId]:W},positions:q}}return{...ne,runmeSession:ne.runmeSession,cells:{...ne.cells,[W.refId]:W}}}})},R=()=>{const W=`code_${Lc().replace(/-/g,"")}`,ne=vt.create(_s,{metadata:{[Dr.ID]:W,[Dr.RunmeID]:W},refId:W,role:on.USER,kind:Ir.CODE,value:""});T(ne)},F=W=>{if(_.find(q=>q.refId===W.refId)){const q=new CustomEvent("runCodeCell",{detail:{cellId:W.refId}});window.dispatchEvent(q)}},H=async({asSessionRecord:W})=>{var se;const ne=au(f,p);if(!f||ne.length===0)return;const q=vt.create(Tc,{cells:ne}),L=Yc(kg,e.webApp.runner),$=vt.create(Cg,{notebook:q,options:vt.create(xg,{outputs:vt.create(Sg,{enabled:!1,summary:!1})})});W&&((se=$.options)!=null&&se.outputs)&&($.options.outputs.enabled=!0,$.options.outputs.summary=!0,$.options.session=vt.create(wg,{id:f.runmeSession}));const B=await L.serialize($),K=new Blob([B.result],{type:"text/plain"}),U=URL.createObjectURL(K),z=document.createElement("a");z.href=U;const te=W?"Session":"Notebook";z.download=`${te}-${bh()}.md`,document.body.appendChild(z),z.click(),document.body.removeChild(z),URL.revokeObjectURL(U)};return ae.jsx(kh.Provider,{value:{useColumns:x,sequence:s,incrementSequence:h,saveState:g,exportDocument:H,sendOutputCell:O,createOutputCell:S,sendUserCell:k,addCodeCell:R,isInputDisabled:d,isTyping:o,runCodeCell:F,resetSession:b},children:r})},lu=new TextEncoder;function c0({pid:r,exitCode:e},t,s,u){let d;return r!==null&&e!==null&&(d=vt.create(yg,{pid:BigInt(r),exitReason:vt.create(bg,{type:"exit",code:e})})),[vt.create(Ac,{items:[vt.create(Oc,{mime:wi.VSCodeNotebookStdOut,type:"Buffer",data:lu.encode(t)})],processInfo:d}),vt.create(Ac,{items:[vt.create(Oc,{mime:wi.VSCodeNotebookStdErr,type:"Buffer",data:lu.encode(s)})]})]}const u0=vt.create(_s,{kind:Ir.MARKUP,role:on.ASSISTANT,value:"..."}),d0=Be.memo(({cellID:r,runID:e,sequence:t,value:s,content:u,settings:d={},onStdout:a,onStderr:o,onExitCode:c,onPid:i,onMimeType:n})=>{const{createAuthInterceptors:l,settings:{webApp:h}}=Tr();return(s!=""&&e!=""||u&&u.length>0)&&ae.jsx(ev,{cellID:r,runID:e,sequence:t,commands:s.split(`
6549
6549
  `),content:u,runner:{endpoint:h.runner,reconnect:h.reconnect,interceptors:l(!1)},settings:d,onPid:i,onStdout:a,onStderr:o,onExitCode:c,onMimeType:n})},(r,e)=>r.cellID===e.cellID&&JSON.stringify(r.value)===JSON.stringify(e.value)&&r.runID===e.runID),cu="vs-dark",h0=Be.memo(({id:r,value:e,language:t,fontSize:s=14,fontFamily:u="monospace",onChange:d,onEnter:a})=>{const o=Be.useRef(a),c=Be.useRef(null),i=Be.useRef(null),[n,l]=Be.useState("140px"),[h,p]=Be.useState(!1),m=Be.useRef(0),f=Be.useRef(0);Be.useEffect(()=>{o.current=a},[a]),Be.useEffect(()=>{const b=_=>{if(!h)return;const w=_.clientY-m.current,x=Math.max(100,f.current+w);l(`${x}px`),c.current&&c.current.layout()},y=()=>{p(!1),document.body.style.cursor="default"};return h&&(document.addEventListener("mousemove",b),document.addEventListener("mouseup",y)),()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",y)}},[h]);const v=(b,y)=>{c.current=b,y!=null&&y.editor&&(y.editor.setTheme(cu),b&&(b.onKeyDown(_=>{_.ctrlKey&&_.keyCode===3&&o.current()}),e===""&&b.focus()))},g=b=>{var y;p(!0),m.current=b.clientY,f.current=((y=i.current)==null?void 0:y.clientHeight)||140,document.body.style.cursor="ns-resize",b.preventDefault()};return ae.jsxs("div",{className:"pb-1 w-full",ref:i,children:[ae.jsx("div",{className:"rounded-md overflow-hidden",children:ae.jsx(qh,{height:n,width:"100%",defaultLanguage:t,value:e,options:{scrollbar:{alwaysConsumeMouseWheel:!1},minimap:{enabled:!1},theme:cu,wordWrap:"wordWrapColumn",fontSize:s,fontFamily:u,lineHeight:20},onChange:b=>{b&&(e=b,d==null||d(b))},onMount:v,className:"rounded-lg",wrapperProps:{className:"rounded-lg"}},r)}),ae.jsx("div",{className:"h-2 w-full cursor-ns-resize",onMouseDown:g})]})},(r,e)=>r.value===e.value),f0=()=>ae.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ae.jsx("path",{d:"M3.24182 2.32181C3.3919 2.23132 3.5784 2.22601 3.73338 2.30781L12.7334 7.05781C12.8974 7.14436 13 7.31457 13 7.5C13 7.68543 12.8974 7.85564 12.7334 7.94219L3.73338 12.6922C3.5784 12.774 3.3919 12.7687 3.24182 12.6782C3.09175 12.5877 3 12.4252 3 12.25V2.75C3 2.57476 3.09175 2.4123 3.24182 2.32181ZM4 3.57925V11.4207L11.4338 7.5L4 3.57925Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd",stroke:"currentColor",strokeWidth:"0.5"})}),p0=()=>ae.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ae.jsx("path",{d:"M7.5 1.5C4.5 1.5 2 4 2 7C2 8.9 3 10.5 4.5 11.5L4 12.5C2 11.5 1 9.2 1 7C1 3.5 4 0.5 7.5 0.5C11 0.5 14 3.5 14 7C14 9.2 13 11.5 11 12.5L10.5 11.5C12 10.5 13 8.9 13 7C13 4 10.5 1.5 7.5 1.5Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"})}),m0=()=>ae.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ae.jsx("path",{d:"M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z",fill:"#22c55e",fillRule:"evenodd",clipRule:"evenodd",stroke:"#22c55e",strokeWidth:"1"})}),v0=({exitCode:r})=>ae.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[ae.jsx("circle",{cx:"12",cy:"12",r:"20",fill:"#ef4444",fillOpacity:"0.3"}),ae.jsx("text",{x:"50%",y:"50%",dominantBaseline:"middle",textAnchor:"middle",fill:"#ef4444",fontSize:"10",fontWeight:"bold",children:r})]});function g0(){return ae.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ae.jsx("path",{d:"M7.5 0.75C7.91421 0.75 8.25 1.08579 8.25 1.5V7.25H14C14.4142 7.25 14.75 7.58579 14.75 8C14.75 8.41421 14.4142 8.75 14 8.75H8.25V14.5C8.25 14.9142 7.91421 15.25 7.5 15.25C7.08579 15.25 6.75 14.9142 6.75 14.5V8.75H1C0.585786 8.75 0.25 8.41421 0.25 8C0.25 7.58579 0.585786 7.25 1 7.25H6.75V1.5C6.75 1.08579 7.08579 0.75 7.5 0.75Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd",strokeWidth:"0.5"})})}function b0(){return ae.jsx("svg",{width:"28",height:"28",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:ae.jsx("path",{d:"M10 6.5C10 8.433 8.433 10 6.5 10C4.567 10 3 8.433 3 6.5C3 4.567 4.567 3 6.5 3C8.433 3 10 4.567 10 6.5ZM9.30884 10.0159C8.53901 10.6318 7.56251 11 6.5 11C4.01472 11 2 8.98528 2 6.5C2 4.01472 4.01472 2 6.5 2C8.98528 2 11 4.01472 11 6.5C11 7.56251 10.6318 8.53901 10.0159 9.30884L12.8536 12.1464C13.0488 12.3417 13.0488 12.6583 12.8536 12.8536C12.6583 13.0488 12.3417 13.0488 12.1464 12.8536L9.30884 10.0159Z",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.3",fillRule:"evenodd",clipRule:"evenodd"})})}const uu=14,du="monospace",y0=new TextDecoder;function _0({pid:r,exitCode:e,onClick:t}){return ae.jsxs(tt.Button,{variant:"soft",onClick:t,children:[e===null&&r===null&&ae.jsx(f0,{}),e===null&&r!==null&&ae.jsx("div",{className:"animate-spin",children:ae.jsx(p0,{})}),e!==null&&e===0&&ae.jsx(m0,{}),e!==null&&e>0&&ae.jsx(v0,{exitCode:e})]})}function w0({cell:r}){const{settings:e}=Tr(),t=e.webApp.invertedOrder,{sendOutputCell:s,saveState:u,incrementSequence:d,sequence:a}=an(),[o,c]=Be.useState(r.value),[i,n]=Be.useState(!1),[l,h]=Be.useState({value:"",runID:""}),[p,m]=Be.useState(null),[f,v]=Be.useState(null),[g,b]=Be.useState(null),[y,_]=Be.useState(null),[w,x]=Be.useState(""),[S,j]=Be.useState(""),[k,O]=Be.useState(""),[T,R]=Be.useState(null),F=Be.useCallback(($=!1)=>{v(BigInt(Date.now())),r.executionSummary=void 0,r.outputs=[],x(""),j(""),m(null),b(null),n($),d(),h({value:o,runID:Id()})},[r,o,d]);Be.useEffect(()=>{const $=B=>{B.detail.cellId===r.refId&&F()};return window.addEventListener("runCodeCell",$),()=>{window.removeEventListener("runCodeCell",$)}},[r.refId,F]);const H=Be.useMemo(()=>c0({pid:p,exitCode:g},w,S),[p,g,w,S,y]);Be.useEffect(()=>{f!==null&&(r.outputs=H,r.executionSummary=vt.create(_g,{timing:vt.create(gg,{startTime:f,endTime:BigInt(Date.now())}),executionOrder:a,success:Number.isFinite(g)&&g===0}))},[r,H,g,a,f]);const W=Be.useMemo(()=>p===null||g===null||l.runID===""||!Number.isFinite(p)||!Number.isInteger(g)?null:r,[r,l.runID,g,p]);Be.useEffect(()=>{!W||k===l.runID||(O(l.runID),s(W))},[s,W,l.runID,k]),Be.useEffect(()=>{k!==l.runID&&R(a)},[a,l.runID,k]),Be.useEffect(()=>{c(r.value)},[r.value]),Be.useEffect(()=>{r.kind===Ir.CODE&&(l.runID!==""&&(r.metadata[Dr.LastRunID]=l.runID),p?r.metadata[Dr.Pid]=p.toString():delete r.metadata[Dr.Pid],g!==null&&Number.isFinite(g)?(delete r.metadata[Dr.Pid],r.metadata[Dr.ExitCode]=g.toString()):delete r.metadata[Dr.ExitCode],u())},[p,g,r,u,l.runID]);const ne=Be.useMemo(()=>{if(r.kind!==Ir.CODE||k!=="")return;const $=r.outputs.flatMap(B=>B.items).find(B=>B.mime===wi.VSCodeNotebookStdOut);if($)return y0.decode($.data)},[r.kind,r.outputs,k]),q=Be.useMemo(()=>r.metadata[Dr.Pid]??""?r.metadata[Dr.LastRunID]??"":"",[r.metadata]),L=Be.useMemo(()=>T?T.toString():" ",[T]);return ae.jsx("div",{children:ae.jsx(tt.Box,{className:"w-full p-2",children:ae.jsxs("div",{className:"flex justify-between items-top",children:[ae.jsxs("div",{className:"flex flex-col items-center",children:[ae.jsx(_0,{pid:p,exitCode:g,onClick:()=>{F(!0)}}),ae.jsxs(tt.Text,{size:"2",className:"mt-1 p-2 font-bold text-gray-400 font-mono",children:["[",L,"]"]})]}),ae.jsxs(tt.Card,{className:"whitespace-nowrap overflow-hidden flex-1 ml-2",children:[ae.jsx(h0,{id:r.refId,value:o,language:"shellscript",fontSize:uu,fontFamily:du,onChange:$=>{m(null),b(null),c($),r.value=$,u()},onEnter:()=>F()},r.refId),ae.jsx(d0,{runID:l.runID||q,cellID:r.refId,sequence:T||0,value:l.value,content:ne,settings:{takeFocus:i,scrollToFit:!t,className:"rounded-md overflow-hidden",rows:14,fontSize:uu,fontFamily:du},onStdout:$=>x(B=>B+new TextDecoder().decode($)),onStderr:$=>j(B=>B+new TextDecoder().decode($)),onPid:m,onExitCode:b,onMimeType:_},l.runID)]})]})})})}function Ko(){const{useColumns:r,addCodeCell:e}=an(),{settings:t}=Tr(),{actions:s}=r(),u=Be.useRef(null),d=Be.useRef(null);return Be.useEffect(()=>{var a,o;if(t.webApp.invertedOrder){(a=u.current)==null||a.scrollIntoView({behavior:"smooth"});return}(o=d.current)==null||o.scrollIntoView({behavior:"smooth"})},[s,t.webApp.invertedOrder]),ae.jsxs("div",{className:"flex flex-col h-full",children:[ae.jsxs("div",{className:"flex items-center mb-2",children:[ae.jsx(tt.Text,{size:"5",weight:"bold",className:"pr-2",children:"Actions"}),ae.jsx(tt.Button,{variant:"ghost",size:"1",className:"cursor-pointer",onClick:e,children:ae.jsx(g0,{})})]}),ae.jsxs(tt.ScrollArea,{type:"auto",scrollbars:"vertical",className:"flex-1 p-2",children:[ae.jsx("div",{ref:u}),s.map(a=>ae.jsx(w0,{cell:a},a.refId)),ae.jsx("div",{ref:d})]})]})}const Th=({role:r,children:e})=>{const t=r===on.USER?"self-end":"self-start",s=r===on.USER?"indigo":"gray";return ae.jsx(tt.Callout.Root,{highContrast:!0,color:s,className:`${t} max-w-[80%] break-words m-1`,children:ae.jsx(tt.Callout.Text,{children:e})})},S0=({cell:r})=>ae.jsx(Th,{role:on.USER,children:r.value}),x0=({cell:r})=>ae.jsx(Th,{role:on.ASSISTANT,children:ae.jsx(Qh,{components:{code:({children:e,...t})=>ae.jsx("pre",{className:"whitespace-pre-wrap",children:ae.jsx("code",{...t,children:String(e).replace(/\n$/,"")})})},children:r.value})}),C0=Be.memo(({cell:r,isRecentCodeCell:e,onClick:t})=>{var i,n;const{runCodeCell:s}=an(),{settings:u}=Tr(),d=((n=(i=r.value)==null?void 0:i.split(/&&|;|\n|\\n/)[0])==null?void 0:n.substring(0,50))||"",a=()=>{t?t():s(r)},o=u.webApp.invertedOrder?"justify-end":"justify-start",c=ae.jsx("span",{className:"text-xs text-gray-400 p-2",children:"Press CTRL+ENTER to run"});return ae.jsxs("div",{className:`flex ${o} items-center h-full`,children:[e&&u.webApp.invertedOrder&&c,ae.jsxs("div",{className:"flex items-center m-1 p-2 bg-[#1e1e1e] rounded-md max-w-[60%] cursor-pointer",onClick:a,children:[ae.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#d4d4d4",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:ae.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),ae.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#d4d4d4",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"ml-1",children:[ae.jsx("polyline",{points:"4 17 10 11 4 5"}),ae.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),ae.jsx("span",{className:"text-sm text-[#d4d4d4] italic truncate max-w-4/5",children:d})]}),e&&!u.webApp.invertedOrder&&c]})},(r,e)=>r.cell.refId===e.cell.refId&&JSON.stringify(r.cell.value)===JSON.stringify(e.cell.value)&&r.isRecentCodeCell===e.isRecentCodeCell),hu=({cell:r,isRecentCodeCell:e})=>{if(r.kind===Ir.CODE)return ae.jsx(C0,{cell:r,isRecentCodeCell:e},r.refId);switch(r.role){case on.USER:return ae.jsx(S0,{cell:r});case on.ASSISTANT:return ae.jsx(x0,{cell:r});default:return null}},fu=()=>{const{useColumns:r,isTyping:e}=an(),{settings:t}=Tr(),{chat:s}=r(),u=Be.useRef(null);Be.useEffect(()=>{var c;t.webApp.invertedOrder||(c=u.current)==null||c.scrollIntoView({behavior:"smooth"})},[s,t.webApp.invertedOrder]);const d=t.webApp.invertedOrder?0:s.length-1,o=ae.jsx("div",{className:"flex justify-start items-center h-full",children:ae.jsx(hu,{cell:u0})});return ae.jsxs("div",{className:"overflow-y-clip p-1 flex flex-col whitespace-pre-wrap",children:[e&&t.webApp.invertedOrder&&o,s.map((c,i)=>ae.jsx(hu,{cell:c,isRecentCodeCell:c.kind===Ir.CODE&&i===d&&!e},i)),e&&!t.webApp.invertedOrder&&o,ae.jsx("div",{ref:u})]})},pu=()=>{const{sendUserCell:r,isInputDisabled:e}=an(),[t,s]=Be.useState(""),u=Be.useRef(null);Be.useEffect(()=>{var o;(o=u.current)==null||o.focus()},[]);const d=o=>{o.preventDefault(),t.trim()&&(r(t),s(""))},a=o=>{if(o.key==="Enter"&&!o.shiftKey){o.preventDefault();const c=o.currentTarget.form;c&&c.requestSubmit()}};return ae.jsx("form",{onSubmit:d,className:"flex w-full",children:ae.jsxs(tt.Flex,{className:"w-full flex flex-nowrap items-start gap-4 m-2",children:[ae.jsx(tt.TextArea,{name:"userInput",value:t,onChange:o=>s(o.target.value),onKeyDown:a,placeholder:"Enter your question",size:"3",className:"flex-grow min-w-0",ref:u,rows:2,style:{resize:"vertical"}}),ae.jsx(tt.Button,{type:"submit",disabled:e,children:ae.jsx(b0,{})})]})})};function Xo(){const{useColumns:r,runCodeCell:e}=an(),{settings:t}=Tr(),{chat:s}=r(),u=Be.useRef(null);Be.useEffect(()=>{const a=c=>{if(c.ctrlKey&&c.key==="Enter"){const i=t.webApp.invertedOrder?s[0]:s[s.length-1];(i==null?void 0:i.kind)===Ir.CODE&&e(i)}},o=u.current;if(o)return o.addEventListener("keydown",a),()=>o.removeEventListener("keydown",a)},[s,e,t.webApp.invertedOrder]);const d=t.webApp.invertedOrder?"flex-col":"flex-col-reverse";return ae.jsxs("div",{ref:u,className:"flex flex-col h-full",children:[ae.jsx(tt.Text,{size:"5",weight:"bold",className:"mb-2",children:"How can I help you?"}),ae.jsx(tt.ScrollArea,{type:"auto",scrollbars:"vertical",className:"flex-1 p-4",children:ae.jsx("div",{className:`flex ${d} h-full w-full`,children:t.webApp.invertedOrder?ae.jsxs(ae.Fragment,{children:[ae.jsx(pu,{}),ae.jsx(fu,{})]}):ae.jsxs(ae.Fragment,{children:[ae.jsx(pu,{}),ae.jsx(fu,{})]})})})]})}const Oh=()=>{const{useColumns:r}=an(),{files:e}=r(),t=Be.useRef(null),s=()=>{var a;(a=t.current)==null||a.scrollIntoView({behavior:"smooth"})},u=Be.useMemo(()=>{let a=vt.create(_s,{});return e.length>0&&(a=e[e.length-1]),a},[e]);Be.useEffect(()=>{s()},[u]);const d=u.docResults.length>0;return ae.jsxs("div",{className:"flex flex-col h-full",children:[ae.jsx(tt.Text,{size:"5",weight:"bold",className:"mb-2",children:"Files"}),ae.jsx(tt.ScrollArea,{type:"auto",scrollbars:"vertical",className:"flex-1 pt-4",children:d?ae.jsxs("div",{className:"grow",children:[u.docResults.map(a=>ae.jsx("div",{className:"mb-2",children:ae.jsx(tt.Box,{p:"2",style:{borderRadius:"6px",border:"1px solid var(--gray-5)"},children:ae.jsx(tt.Text,{size:"2",weight:"medium",children:ae.jsx(tt.Link,{href:a.link,target:"_blank",className:"text-blue-500 hover:underline",children:a.fileName})})})},a.fileId)),ae.jsx("div",{ref:t,className:"h-1"})]}):ae.jsxs("div",{children:[ae.jsx("div",{children:"No search results yet"}),ae.jsx("div",{ref:t,className:"h-1"})]})})]})},j0=vn("ChVnb29nbGUvcnBjL2NvZGUucHJvdG8SCmdvb2dsZS5ycGMqtwIKBENvZGUSBgoCT0sQABINCglDQU5DRUxMRUQQARILCgdVTktOT1dOEAISFAoQSU5WQUxJRF9BUkdVTUVOVBADEhUKEURFQURMSU5FX0VYQ0VFREVEEAQSDQoJTk9UX0ZPVU5EEAUSEgoOQUxSRUFEWV9FWElTVFMQBhIVChFQRVJNSVNTSU9OX0RFTklFRBAHEhMKD1VOQVVUSEVOVElDQVRFRBAQEhYKElJFU09VUkNFX0VYSEFVU1RFRBAIEhcKE0ZBSUxFRF9QUkVDT05ESVRJT04QCRILCgdBQk9SVEVEEAoSEAoMT1VUX09GX1JBTkdFEAsSEQoNVU5JTVBMRU1FTlRFRBAMEgwKCElOVEVSTkFMEA0SDwoLVU5BVkFJTEFCTEUQDhINCglEQVRBX0xPU1MQD0JYCg5jb20uZ29vZ2xlLnJwY0IJQ29kZVByb3RvUAFaM2dvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL2dvb2dsZWFwaXMvcnBjL2NvZGU7Y29kZaICA1JQQ2IGcHJvdG8z"),E0=Li(j0,0),Yo=Ni(E0);function Ah(){const{runnerError:r}=Tr(),[e]=mr.useSearchParams(),t=Be.useMemo(()=>r&&!(r instanceof Error)?Yo[r.code]??r.code:e.get("error"),[r,e]),s=Be.useMemo(()=>r&&!(r instanceof Error)?r.message:e.get("error_description"),[r,e]),u=()=>{window.location.href="/oidc/login"};return ae.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4",children:[t&&ae.jsxs(tt.Callout.Root,{color:"red",children:[ae.jsxs(tt.Callout.Text,{className:"font-bold",children:["Error: ",t]}),s&&ae.jsx(tt.Callout.Text,{children:s})]}),ae.jsx(tt.Button,{size:"4",onClick:u,className:"cursor-pointer",children:"Login"})]})}const Rh=()=>ae.jsxs(tt.Container,{size:"3",style:{padding:"2rem",textAlign:"center"},children:[ae.jsx(tt.Heading,{size:"8",mb:"4",children:"404"}),ae.jsx(tt.Text,{size:"5",color:"gray",children:"Page not found"}),ae.jsx(tt.Text,{as:"p",mt:"4",children:"The page you're looking for doesn't exist or has been moved."}),ae.jsxs(tt.Text,{as:"p",mt:"4",children:["Click"," ",ae.jsx(tt.Link,{href:"/",underline:"always",children:"here"})," ","to go back home."]})]});function Lh(){const r=mr.useNavigate(),{settings:e,updateSettings:t,runnerError:s,defaultSettings:u}=Tr(),[d,a]=Be.useState(!1),[o,c]=Be.useState(e.agentEndpoint),[i,n]=Be.useState(e.webApp.runner),[l,h]=Be.useState(e.webApp.invertedOrder),p=()=>{t({agentEndpoint:o,webApp:{runner:i,reconnect:e.webApp.reconnect,invertedOrder:l}}),a(!0)};Be.useEffect(()=>{d&&(a(!1),s&&r("/"))},[s,d,r]);const m=()=>{c(u.agentEndpoint),n(u.webApp.runner),h(u.webApp.invertedOrder)},f=Be.useMemo(()=>{if(s&&!(!s||typeof s!="object"||!("message"in s)))return s.message},[s]),v=o!==e.agentEndpoint||i!==e.webApp.runner||l!==e.webApp.invertedOrder;return ae.jsxs(tt.Box,{className:"w-full mx-auto",children:[ae.jsx(tt.Text,{size:"5",weight:"bold",className:"mb-2",children:"Settings"}),ae.jsxs(tt.Box,{className:"mt-4",children:[ae.jsxs(tt.Flex,{direction:"column",gap:"4",children:[ae.jsxs(tt.Flex,{direction:"column",gap:"2",children:[ae.jsx(tt.Text,{size:"3",weight:"bold",children:"Agent Endpoint Configuration"}),ae.jsx(tt.Text,{size:"2",color:"gray",children:"Configure the endpoint URL for the AI agent. Changes will take effect after saving."}),ae.jsx(tt.TextArea,{size:"3",placeholder:"Enter AI endpoint URL",value:o,onChange:g=>c(g.target.value)})]}),ae.jsxs(tt.Flex,{direction:"column",gap:"2",children:[ae.jsx(tt.Text,{size:"3",weight:"bold",children:"Runner Endpoint Configuration"}),ae.jsx(tt.Text,{size:"2",color:"gray",children:"Configure the WebSocket endpoint URL for the runner. Changes will take effect after saving."}),s&&ae.jsx(tt.Callout.Root,{color:"red",children:ae.jsxs(tt.Callout.Text,{className:"font-bold",children:["Runner error",f?": "+f:""]})}),ae.jsx(tt.TextArea,{size:"3",placeholder:"Enter Runner WebSocket endpoint URL",value:i,onChange:g=>n(g.target.value)}),ae.jsx(tt.Text,{size:"2",color:"gray",children:"Revert will reset endpoints to the default values, including protocol http(s), based on the current page."})]}),ae.jsxs(tt.Flex,{direction:"column",gap:"2",children:[ae.jsx(tt.Text,{size:"3",weight:"bold",children:"User Experience Mode"}),ae.jsx(tt.Text,{as:"label",size:"2",children:ae.jsxs(tt.Flex,{gap:"2",children:["Document Mode",ae.jsx(tt.Switch,{checked:l,onCheckedChange:h}),"Console Mode"]})})]})]}),ae.jsxs(tt.Flex,{gap:"3",justify:"end",mt:"4",children:[ae.jsx(tt.Button,{size:"2",variant:"soft",onClick:()=>r("/"),children:"Back"}),ae.jsx(tt.Button,{size:"2",variant:"soft",onClick:m,children:"Revert"}),ae.jsx(tt.Button,{size:"2",onClick:p,disabled:!v,children:"Save"})]})]})]})}function k0(r,e=[]){let t=[];function s(d,a){const o=jt.createContext(a),c=t.length;t=[...t,a];const i=l=>{var g;const{scope:h,children:p,...m}=l,f=((g=h==null?void 0:h[r])==null?void 0:g[c])||o,v=jt.useMemo(()=>m,Object.values(m));return ae.jsx(f.Provider,{value:v,children:p})};i.displayName=d+"Provider";function n(l,h){var f;const p=((f=h==null?void 0:h[r])==null?void 0:f[c])||o,m=jt.useContext(p);if(m)return m;if(a!==void 0)return a;throw new Error(`\`${l}\` must be used within \`${d}\``)}return[i,n]}const u=()=>{const d=t.map(a=>jt.createContext(a));return function(o){const c=(o==null?void 0:o[r])||d;return jt.useMemo(()=>({[`__scope${r}`]:{...o,[r]:c}}),[o,c])}};return u.scopeName=r,[s,I0(u,...e)]}function I0(...r){const e=r[0];if(r.length===1)return e;const t=()=>{const s=r.map(u=>({useScope:u(),scopeName:u.scopeName}));return function(d){const a=s.reduce((o,{useScope:c,scopeName:i})=>{const l=c(d)[`__scope${i}`];return{...o,...l}},{});return jt.useMemo(()=>({[`__scope${e.scopeName}`]:a}),[a])}};return t.scopeName=e.scopeName,t}function T0(r){const e=jt.useRef(r);return jt.useEffect(()=>{e.current=r}),jt.useMemo(()=>(...t)=>{var s;return(s=e.current)==null?void 0:s.call(e,...t)},[])}var Jo=globalThis!=null&&globalThis.document?jt.useLayoutEffect:()=>{};function mu(r,e){if(typeof r=="function")return r(e);r!=null&&(r.current=e)}function O0(...r){return e=>{let t=!1;const s=r.map(u=>{const d=mu(u,e);return!t&&typeof d=="function"&&(t=!0),d});if(t)return()=>{for(let u=0;u<s.length;u++){const d=s[u];typeof d=="function"?d():mu(r[u],null)}}}}function A0(r){const e=R0(r),t=jt.forwardRef((s,u)=>{const{children:d,...a}=s,o=jt.Children.toArray(d),c=o.find(N0);if(c){const i=c.props.children,n=o.map(l=>l===c?jt.Children.count(i)>1?jt.Children.only(null):jt.isValidElement(i)?i.props.children:null:l);return ae.jsx(e,{...a,ref:u,children:jt.isValidElement(i)?jt.cloneElement(i,void 0,n):null})}return ae.jsx(e,{...a,ref:u,children:d})});return t.displayName=`${r}.Slot`,t}function R0(r){const e=jt.forwardRef((t,s)=>{const{children:u,...d}=t;if(jt.isValidElement(u)){const a=D0(u),o=P0(d,u.props);return u.type!==jt.Fragment&&(o.ref=s?O0(s,a):a),jt.cloneElement(u,o)}return jt.Children.count(u)>1?jt.Children.only(null):null});return e.displayName=`${r}.SlotClone`,e}var L0=Symbol("radix.slottable");function N0(r){return jt.isValidElement(r)&&typeof r.type=="function"&&"__radixId"in r.type&&r.type.__radixId===L0}function P0(r,e){const t={...e};for(const s in e){const u=r[s],d=e[s];/^on[A-Z]/.test(s)?u&&d?t[s]=(...o)=>{const c=d(...o);return u(...o),c}:u&&(t[s]=u):s==="style"?t[s]={...u,...d}:s==="className"&&(t[s]=[u,d].filter(Boolean).join(" "))}return{...r,...t}}function D0(r){var s,u;let e=(s=Object.getOwnPropertyDescriptor(r.props,"ref"))==null?void 0:s.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?r.ref:(e=(u=Object.getOwnPropertyDescriptor(r,"ref"))==null?void 0:u.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?r.props.ref:r.props.ref||r.ref)}var M0=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Na=M0.reduce((r,e)=>{const t=A0(`Primitive.${e}`),s=jt.forwardRef((u,d)=>{const{asChild:a,...o}=u,c=a?t:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),ae.jsx(c,{...o,ref:d})});return s.displayName=`Primitive.${e}`,{...r,[e]:s}},{}),si={exports:{}},Eo={};/**
6550
6550
  * @license React
6551
6551
  * use-sync-external-store-shim.production.js
@@ -69259,7 +69259,7 @@ const M0 = ({ children: r }) => {
69259
69259
  return new S0(
69260
69260
  "agent",
69261
69261
  t,
69262
- du(ub, e.agentEndpoint)
69262
+ du(ub, e.webApp.runner)
69263
69263
  );
69264
69264
  }, [e.agentEndpoint, t]), h = () => {
69265
69265
  u((W) => W + 1);
@@ -69419,7 +69419,7 @@ const M0 = ({ children: r }) => {
69419
69419
  cells: ne
69420
69420
  }), L = du(
69421
69421
  qg,
69422
- e.agentEndpoint
69422
+ e.webApp.runner
69423
69423
  ), $ = Et(Xg, {
69424
69424
  notebook: q,
69425
69425
  options: Et(Kg, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runmedev/react-components",
3
- "version": "3.15.3",
3
+ "version": "3.15.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "private": false,
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "devDependencies": {
22
- "@runmedev/react-console": "3.15.3"
22
+ "@runmedev/react-console": "3.15.4"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@monaco-editor/react": "^4.7.0",