From 1e0fbf41e1938765898bb77df5437019ef5e14bf Mon Sep 17 00:00:00 2001 From: morgan9e Date: Wed, 1 Oct 2025 05:31:47 +0000 Subject: [PATCH] deploy: 457915c28746953b10aa646bd4bbbe801bc2e7cc --- assets/{index-5deae729.js => index-ab1d1007.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-5deae729.js => index-ab1d1007.js} (99%) diff --git a/assets/index-5deae729.js b/assets/index-ab1d1007.js similarity index 99% rename from assets/index-5deae729.js rename to assets/index-ab1d1007.js index cdaab5a..ad56c3d 100644 --- a/assets/index-5deae729.js +++ b/assets/index-ab1d1007.js @@ -1,6 +1,6 @@ var B1=Object.defineProperty;var F1=(n,e,t)=>e in n?B1(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Ht=(n,e,t)=>(F1(n,typeof e!="symbol"?e+"":e,t),t);import"https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.mjs";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function t(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=t(a);fetch(a.href,i)}})();function Ve(){}function Pn(n,e){for(const t in e)n[t]=e[t];return n}function G1(n){return!!n&&(typeof n=="object"||typeof n=="function")&&typeof n.then=="function"}function uS(n){return n()}function Wm(){return Object.create(null)}function On(n){n.forEach(uS)}function ga(n){return typeof n=="function"}function Et(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}let Wo;function ka(n,e){return Wo||(Wo=document.createElement("a")),Wo.href=e,n===Wo.href}function q1(n){return Object.keys(n).length===0}function q_(n,...e){if(n==null)return Ve;const t=n.subscribe(...e);return t.unsubscribe?()=>t.unsubscribe():t}function At(n){let e;return q_(n,t=>e=t)(),e}function Gt(n,e,t){n.$$.on_destroy.push(q_(e,t))}function sn(n,e,t,r){if(n){const a=dS(n,e,t,r);return n[0](a)}}function dS(n,e,t,r){return n[1]&&r?Pn(t.ctx.slice(),n[1](r(e))):t.ctx}function ln(n,e,t,r){if(n[2]&&r){const a=n[2](r(t));if(e.dirty===void 0)return a;if(typeof a=="object"){const i=[],o=Math.max(e.dirty.length,a.length);for(let s=0;s32){const e=[],t=n.ctx.length/32;for(let r=0;rn.removeEventListener(e,t,r)}function pt(n){return function(e){return e.preventDefault(),n.call(this,e)}}function Li(n){return function(e){return e.stopPropagation(),n.call(this,e)}}function S(n,e,t){t==null?n.removeAttribute(e):n.getAttribute(e)!==t&&n.setAttribute(e,t)}const Y1=["width","height"];function Km(n,e){const t=Object.getOwnPropertyDescriptors(n.__proto__);for(const r in e)e[r]==null?n.removeAttribute(r):r==="style"?n.style.cssText=e[r]:r==="__value"?n.value=n[r]=e[r]:t[r]&&t[r].set&&Y1.indexOf(r)===-1?n[r]=e[r]:S(n,r,e[r])}function z1(n){return Array.from(n.childNodes)}function Jt(n,e){e=""+e,n.data!==e&&(n.data=e)}function Qm(n,e){n.value=e??""}function La(n,e,t,r){t==null?n.style.removeProperty(e):n.style.setProperty(e,t,r?"important":"")}function Re(n,e,t){n.classList[t?"add":"remove"](e)}function H1(n,e,{bubbles:t=!1,cancelable:r=!1}={}){const a=document.createEvent("CustomEvent");return a.initCustomEvent(n,t,r,e),a}class li{constructor(e=!1){this.is_svg=!1,this.is_svg=e,this.e=this.n=null}c(e){this.h(e)}m(e,t,r=null){this.e||(this.is_svg?this.e=ti(t.nodeName):this.e=A(t.nodeType===11?"TEMPLATE":t.nodeName),this.t=t.tagName!=="TEMPLATE"?t:t.content,this.c(e)),this.i(r)}h(e){this.e.innerHTML=e,this.n=Array.from(this.e.nodeName==="TEMPLATE"?this.e.content.childNodes:this.e.childNodes)}i(e){for(let t=0;t{const a=n.$$.callbacks[e];if(a){const i=H1(e,t,{cancelable:r});return a.slice().forEach(o=>{o.call(n,i)}),!i.defaultPrevented}return!0}}function V1(n,e){return ci().$$.context.set(n,e),e}function $1(n){return ci().$$.context.get(n)}function Xm(n,e){const t=n.$$.callbacks[e.type];t&&t.slice().forEach(r=>r.call(this,e))}const Ci=[],Gr=[];let Ni=[];const b_=[],_S=Promise.resolve();let T_=!1;function mS(){T_||(T_=!0,_S.then(H_))}function pS(){return mS(),_S}function io(n){Ni.push(n)}function ho(n){b_.push(n)}const vl=new Set;let bi=0;function H_(){if(bi!==0)return;const n=ao;do{try{for(;bin.indexOf(r)===-1?e.push(r):t.push(r)),t.forEach(r=>r()),Ni=e}const ls=new Set;let ei;function et(){ei={r:0,c:[],p:ei}}function tt(){ei.r||On(ei.c),ei=ei.p}function L(n,e){n&&n.i&&(ls.delete(n),n.i(e))}function G(n,e,t,r){if(n&&n.o){if(ls.has(n))return;ls.add(n),ei.c.push(()=>{ls.delete(n),r&&(t&&n.d(1),r())}),n.o(e)}else r&&r()}function Zm(n,e){const t=e.token={};function r(a,i,o,s){if(e.token!==t)return;e.resolved=s;let l=e.ctx;o!==void 0&&(l=l.slice(),l[o]=s);const c=a&&(e.current=a)(l);let u=!1;e.block&&(e.blocks?e.blocks.forEach((_,p)=>{p!==i&&_&&(et(),G(_,1,1,()=>{e.blocks[p]===_&&(e.blocks[p]=null)}),tt())}):e.block.d(1),c.c(),L(c,1),c.m(e.mount(),e.anchor),u=!0),e.block=c,e.blocks&&(e.blocks[i]=c),u&&H_()}if(G1(n)){const a=ci();if(n.then(i=>{la(a),r(e.then,1,e.value,i),la(null)},i=>{if(la(a),r(e.catch,2,e.error,i),la(null),!e.hasCatch)throw i}),e.current!==e.pending)return r(e.pending,0),!0}else{if(e.current!==e.then)return r(e.then,1,e.value,n),!0;e.resolved=n}}function Q1(n,e,t){const r=e.slice(),{resolved:a}=n;n.current===n.then&&(r[n.value]=a),n.current===n.catch&&(r[n.error]=a),n.block.p(r,t)}function X1(n,e){G(n,1,1,()=>{e.delete(n.key)})}function Z1(n,e,t,r,a,i,o,s,l,c,u,_){let p=n.length,f=i.length,h=p;const v={};for(;h--;)v[n[h].key]=h;const R=[],O=new Map,x=new Map,M=[];for(h=f;h--;){const U=_(a,i,h),F=t(U);let Z=o.get(F);Z?r&&M.push(()=>Z.p(U,e)):(Z=c(F,U),Z.c()),O.set(F,R[h]=Z),F in v&&x.set(F,Math.abs(h-v[F]))}const D=new Set,P=new Set;function k(U){L(U,1),U.m(s,u),o.set(U.key,U),u=U.first,f--}for(;p&&f;){const U=R[f-1],F=n[p-1],Z=U.key,Y=F.key;U===F?(u=U.first,p--,f--):O.has(Y)?!o.has(Z)||D.has(Z)?k(U):P.has(Y)?p--:x.get(Z)>x.get(Y)?(P.add(Z),k(U)):(D.add(Y),p--):(l(F,o),p--)}for(;p--;){const U=n[p];O.has(U.key)||l(U,o)}for(;f;)k(R[f-1]);return On(M),R}function kr(n,e){const t={},r={},a={$$scope:1};let i=n.length;for(;i--;){const o=n[i],s=e[i];if(s){for(const l in o)l in s||(r[l]=1);for(const l in s)a[l]||(t[l]=s[l],a[l]=1);n[i]=s}else for(const l in o)a[l]=1}for(const o in r)o in t||(t[o]=void 0);return t}function qr(n){return typeof n=="object"&&n!==null?n:{}}function So(n,e,t){const r=n.$$.props[e];r!==void 0&&(n.$$.bound[r]=t,t(n.$$.ctx[r]))}function Ae(n){n&&n.c()}function Ne(n,e,t,r){const{fragment:a,after_update:i}=n.$$;a&&a.m(e,t),r||io(()=>{const o=n.$$.on_mount.map(uS).filter(ga);n.$$.on_destroy?n.$$.on_destroy.push(...o):On(o),n.$$.on_mount=[]}),i.forEach(io)}function Oe(n,e){const t=n.$$;t.fragment!==null&&(K1(t.after_update),On(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function j1(n,e){n.$$.dirty[0]===-1&&(Ci.push(n),mS(),n.$$.dirty.fill(0)),n.$$.dirty[e/31|0]|=1<{const h=f.length?f[0]:p;return c.ctx&&a(c.ctx[_],c.ctx[_]=h)&&(!c.skip_bound&&c.bound[_]&&c.bound[_](h),u&&j1(n,_)),p}):[],c.update(),u=!0,On(c.before_update),c.fragment=r?r(c.ctx):!1,e.target){if(e.hydrate){const _=z1(e.target);c.fragment&&c.fragment.l(_),_.forEach(K)}else c.fragment&&c.fragment.c();e.intro&&L(n.$$.fragment),Ne(n,e.target,e.anchor,e.customElement),H_()}la(l)}class Ot{$destroy(){Oe(this,1),this.$destroy=Ve}$on(e,t){if(!ga(t))return Ve;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(t),()=>{const a=r.indexOf(t);a!==-1&&r.splice(a,1)}}$set(e){this.$$set&&!q1(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ti=[];function fS(n,e){return{subscribe:Hn(n,e).subscribe}}function Hn(n,e=Ve){let t;const r=new Set;function a(s){if(Et(n,s)&&(n=s,t)){const l=!Ti.length;for(const c of r)c[1](),Ti.push(c,n);if(l){for(let c=0;c{r.delete(c),r.size===0&&t&&(t(),t=null)}}return{set:a,update:i,subscribe:o}}function gS(n,e,t){const r=!Array.isArray(n),a=r?[n]:n,i=e.length<2;return fS(t,o=>{let s=!1;const l=[];let c=0,u=Ve;const _=()=>{if(c)return;u();const f=e(r?l[0]:l,o);i?o(f):u=ga(f)?f:Ve},p=a.map((f,h)=>q_(f,v=>{l[h]=v,c&=~(1<{c|=1<{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("routeEvent",s[7]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){s&&K(t),e&&Oe(e,s)}}}function tT(n){let e,t,r;const a=[{params:n[1]},n[2]];var i=n[0];function o(s){let l={};for(let c=0;c{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("routeEvent",s[6]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){s&&K(t),e&&Oe(e,s)}}}function nT(n){let e,t,r,a;const i=[tT,eT],o=[];function s(l,c){return l[1]?0:1}return e=s(n),t=o[e]=i[e](n),{c(){t.c(),r=gt()},m(l,c){o[e].m(l,c),Q(l,r,c),a=!0},p(l,[c]){let u=e;e=s(l),e===u?o[e].p(l,c):(et(),G(o[u],1,1,()=>{o[u]=null}),tt(),t=o[e],t?t.p(l,c):(t=o[e]=i[e](l),t.c()),L(t,1),t.m(r.parentNode,r))},i(l){a||(L(t),a=!0)},o(l){G(t),a=!1},d(l){o[e].d(l),l&&K(r)}}}function jm(){const n=window.location.href.indexOf("#/");let e=n>-1?window.location.href.substr(n+1):"/";const t=e.indexOf("?");let r="";return t>-1&&(r=e.substr(t+1),e=e.substr(0,t)),{location:e,querystring:r}}const V_=fS(null,function(e){e(jm());const t=()=>{e(jm())};return window.addEventListener("hashchange",t,!1),function(){window.removeEventListener("hashchange",t,!1)}}),rT=gS(V_,n=>n.location),ES=gS(V_,n=>n.querystring),gs=Hn(void 0);async function Kr(n){if(!n||n.length<1||n.charAt(0)!="/"&&n.indexOf("#/")!==0)throw Error("Invalid parameter location");await pS();const e=(n.charAt(0)=="#"?"":"#")+n;try{const t={...history.state};delete t.__svelte_spa_router_scrollX,delete t.__svelte_spa_router_scrollY,window.history.replaceState(t,void 0,e)}catch{console.warn("Caught exception while replacing the current page. If you're running this in the Svelte REPL, please note that the `replace` method might not work in this environment.")}window.dispatchEvent(new Event("hashchange"))}function aT(n){n?window.scrollTo(n.__svelte_spa_router_scrollX,n.__svelte_spa_router_scrollY):window.scrollTo(0,0)}function iT(n,e,t){let{routes:r={}}=e,{prefix:a=""}=e,{restoreScrollState:i=!1}=e;class o{constructor(P,k){if(!k||typeof k!="function"&&(typeof k!="object"||k._sveltesparouter!==!0))throw Error("Invalid component object");if(!P||typeof P=="string"&&(P.length<1||P.charAt(0)!="/"&&P.charAt(0)!="*")||typeof P=="object"&&!(P instanceof RegExp))throw Error('Invalid value for "path" argument - strings must start with / or *');const{pattern:U,keys:F}=J1(P);this.path=P,typeof k=="object"&&k._sveltesparouter===!0?(this.component=k.component,this.conditions=k.conditions||[],this.userData=k.userData,this.props=k.props||{}):(this.component=()=>Promise.resolve(k),this.conditions=[],this.props={}),this._pattern=U,this._keys=F}match(P){if(a){if(typeof a=="string")if(P.startsWith(a))P=P.substr(a.length)||"/";else return null;else if(a instanceof RegExp){const Z=P.match(a);if(Z&&Z[0])P=P.substr(Z[0].length)||"/";else return null}}const k=this._pattern.exec(P);if(k===null)return null;if(this._keys===!1)return k;const U={};let F=0;for(;F{s.push(new o(P,D))}):Object.keys(r).forEach(D=>{s.push(new o(D,r[D]))});let l=null,c=null,u={};const _=Eo();async function p(D,P){await pS(),_(D,P)}let f=null,h=null;i&&(h=D=>{D.state&&(D.state.__svelte_spa_router_scrollY||D.state.__svelte_spa_router_scrollX)?f=D.state:f=null},window.addEventListener("popstate",h),ui(()=>{aT(f)}));let v=null,R=null;const O=V_.subscribe(async D=>{v=D;let P=0;for(;P{gs.set(c)});return}t(0,l=null),R=null,gs.set(void 0)});z_(()=>{O(),h&&window.removeEventListener("popstate",h)});function x(D){Xm.call(this,n,D)}function M(D){Xm.call(this,n,D)}return n.$$set=D=>{"routes"in D&&t(3,r=D.routes),"prefix"in D&&t(4,a=D.prefix),"restoreScrollState"in D&&t(5,i=D.restoreScrollState)},n.$$.update=()=>{n.$$.dirty&32&&(history.scrollRestoration=i?"manual":"auto")},[l,c,u,r,a,i,x,M]}class oT extends Ot{constructor(e){super(),Nt(this,e,iT,nT,Et,{routes:3,prefix:4,restoreScrollState:5})}}function Jm(n){if(!n)throw Error("Parameter args is required");if(!n.component==!n.asyncComponent)throw Error("One and only one of component and asyncComponent is required");if(n.component&&(n.asyncComponent=()=>Promise.resolve(n.component)),typeof n.asyncComponent!="function")throw Error("Parameter asyncComponent must be a function");if(n.conditions){Array.isArray(n.conditions)||(n.conditions=[n.conditions]);for(let t=0;t"u"||i.Promise||(i.Promise=Promise);var c=Object.getPrototypeOf,u={}.hasOwnProperty;function _(d,m){return u.call(d,m)}function p(d,m){typeof m=="function"&&(m=m(c(d))),(typeof Reflect>"u"?o:Reflect.ownKeys)(m).forEach(function(E){h(d,E,m[E])})}var f=Object.defineProperty;function h(d,m,E,T){f(d,m,l(E&&_(E,"get")&&typeof E.get=="function"?{get:E.get,set:E.set,configurable:!0}:{value:E,configurable:!0,writable:!0},T))}function v(d){return{from:function(m){return d.prototype=Object.create(m.prototype),h(d.prototype,"constructor",d),{extend:p.bind(null,d.prototype)}}}}var R=Object.getOwnPropertyDescriptor,O=[].slice;function x(d,m,E){return O.call(d,m,E)}function M(d,m){return m(d)}function D(d){if(!d)throw new Error("Assertion Failed")}function P(d){i.setImmediate?setImmediate(d):setTimeout(d,0)}function k(d,m){if(typeof m=="string"&&_(d,m))return d[m];if(!m)return d;if(typeof m!="string"){for(var E=[],T=0,y=m.length;T"u"?[]:function(){var d=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[d,c(d),d];var m=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[m,c(m),d]}(),rn=Pr[0],Nr=Pr[1],Pr=Pr[2],Nr=Nr&&Nr.then,tn=rn&&rn.constructor,$e=!!Pr,Ze=function(d,m){wn.push([d,m]),vt&&(queueMicrotask(Bn),vt=!1)},_t=!0,vt=!0,Lt=[],dn=[],Sn=mt,yn={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Be,pgp:!1,env:{},finalize:Be},at=yn,wn=[],kn=0,It=[];function We(d){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var m=this._PSD=at;if(typeof d!="function"){if(d!==En)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&er(this,this._value))}this._state=null,this._value=null,++m.ref,function E(T,y){try{y(function(I){if(T._state===null){if(I===T)throw new TypeError("A promise cannot be resolved with itself.");var B=T._lib&&tr();I&&typeof I.then=="function"?E(T,function(V,ne){I instanceof We?I._then(V,ne):I.then(V,ne)}):(T._state=!0,T._value=I,Fn(T)),B&&nr()}},er.bind(null,T))}catch(I){er(T,I)}}(this,d)}var Cn={get:function(){var d=at,m=$n;function E(T,y){var I=this,B=!d.global&&(d!==at||m!==$n),V=B&&!Er(),ne=new We(function(j,se){ur(I,new Jn(Jr(T,d,B,V),Jr(y,d,B,V),j,se,d))});return this._consoleTask&&(ne._consoleTask=this._consoleTask),ne}return E.prototype=En,E},set:function(d){h(this,"then",d&&d.prototype===En?Cn:{get:function(){return d},set:Cn.set})}};function Jn(d,m,E,T,y){this.onFulfilled=typeof d=="function"?d:null,this.onRejected=typeof m=="function"?m:null,this.resolve=E,this.reject=T,this.psd=y}function er(d,m){var E,T;dn.push(m),d._state===null&&(E=d._lib&&tr(),m=Sn(m),d._state=!1,d._value=m,T=d,Lt.some(function(y){return y._value===T._value})||Lt.push(T),Fn(d),E&&nr())}function Fn(d){var m=d._listeners;d._listeners=[];for(var E=0,T=m.length;E.",Mn="String expected.",Cr=[],ta="__dbnames",Ta="readonly",mr="readwrite";function Rr(d,m){return d?m?function(){return d.apply(this,arguments)&&m.apply(this,arguments)}:d:m}var it={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function on(d){return typeof d!="string"||/\./.test(d)?function(m){return m}:function(m){return m[d]===void 0&&d in m&&delete(m=J(m))[d],m}}function va(){throw be.Type()}function Yt(d,m){try{var E=No(d),T=No(m);if(E!==T)return E==="Array"?1:T==="Array"?-1:E==="binary"?1:T==="binary"?-1:E==="string"?1:T==="string"?-1:E==="Date"?1:T!=="Date"?NaN:-1;switch(E){case"number":case"Date":case"string":return mTe+Ie&&me(Te+le)})})}var Se=ya(E)&&E.limit===1/0&&(typeof d!="function"||d===zi)&&{index:E.index,range:E.range};return me(0).then(function(){if(0=le})).length!==0?(se.forEach(function(me){ce.push(function(){var Se=ae,Te=me._cfg.dbschema;Bo(W,Se,ie),Bo(W,Te,ie),ae=W._dbSchema=Te;var Ie=il(Se,Te);Ie.add.forEach(function(Je){ol(ie,Je[0],Je[1].primKey,Je[1].indexes)}),Ie.change.forEach(function(Je){if(Je.recreate)throw new be.Upgrade("Not yet support for changing primary key");var Ge=ie.objectStore(Je.name);Je.add.forEach(function(wt){return Po(Ge,wt)}),Je.change.forEach(function(wt){Ge.deleteIndex(wt.name),Po(Ge,wt)}),Je.del.forEach(function(wt){return Ge.deleteIndex(wt)})});var ze=me._cfg.contentUpgrade;if(ze&&me._cfg.version>le){ko(W,ie),te._memoizedTables={};var je=F(Te);Ie.del.forEach(function(Je){je[Je]=Se[Je]}),al(W,[W.Transaction.prototype]),Lo(W,[W.Transaction.prototype],o(je),je),te.schema=je;var He,Xe=we(ze);return Xe&&Lr(),Ie=We.follow(function(){var Je;(He=ze(te))&&Xe&&(Je=Er.bind(null,null),He.then(Je,Je))}),He&&typeof He.then=="function"?We.resolve(He):Ie.then(function(){return He})}}),ce.push(function(Se){var Te,Ie,ze=me._cfg.dbschema;Te=ze,Ie=Se,[].slice.call(Ie.db.objectStoreNames).forEach(function(je){return Te[je]==null&&Ie.db.deleteObjectStore(je)}),al(W,[W.Transaction.prototype]),Lo(W,[W.Transaction.prototype],W._storeNames,W._dbSchema),te.schema=W._dbSchema}),ce.push(function(Se){W.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(W.idbdb.version/10)===me._cfg.version?(W.idbdb.deleteObjectStore("$meta"),delete W._dbSchema.$meta,W._storeNames=W._storeNames.filter(function(Te){return Te!=="$meta"})):Se.objectStore("$meta").put(me._cfg.version,"version"))})}),function me(){return ce.length?We.resolve(ce.shift()(te.idbtrans)).then(me):We.resolve()}().then(function(){xm(ae,ie)})):We.resolve();var W,le,te,ie,ce,ae}).catch(B)):(o(y).forEach(function(se){ol(E,se,y[se].primKey,y[se].indexes)}),ko(d,E),void We.follow(function(){return d.on.populate.fire(I)}).catch(B));var ne,j})}function O1(d,m){xm(d._dbSchema,m),m.db.version%10!=0||m.objectStoreNames.contains("$meta")||m.db.createObjectStore("$meta").add(Math.ceil(m.db.version/10-1),"version");var E=Uo(0,d.idbdb,m);Bo(d,d._dbSchema,m);for(var T=0,y=il(E,d._dbSchema).change;TMath.pow(2,62)?0:ae.oldVersion,W=ae<1,d.idbdb=ce.result,I&&O1(d,se),N1(d,ae/10,se,te))},te),ce.onsuccess=Mt(function(){se=null;var ae,me,Se,Te,Ie,ze=d.idbdb=ce.result,je=x(ze.objectStoreNames);if(0"u"?We.resolve():!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(le){function te(){return indexedDB.databases().finally(le)}ne=setInterval(te,100),te()}).finally(function(){return clearInterval(ne)}):Promise.resolve()).then(V)]).then(function(){return B(),m.onReadyBeingFired=[],We.resolve(cl(function(){return d.on.ready.fire(d.vip)})).then(function le(){if(0m.limit?le.length=m.limit:d.length===m.limit&&le.length=me.limit&&(!me.values||ze.req.values)&&k1(ze.req.query.range,me.query.range)}),!1,Se,Te];case"count":return Ie=Te.find(function(ze){return Hm(ze.req.query.range,me.query.range)}),[Ie,!!Ie,Se,Te]}}(m,E,"query",I),se=j[0],W=j[1],le=j[2],te=j[3];return se&&W?se.obsSet=I.obsSet:(W=T.query(I).then(function(ie){var ce=ie.result;if(se&&(se.res=ce),B){for(var ae=0,me=ce.length;ae{Pa=!1});let oi={};class mT extends y_{constructor(){super("chatImageStore");Ht(this,"images");this.version(1).stores({images:"id"})}}const wi=new mT,SS=async n=>{let e=oi[n];return e||!Pa||(e=await wi.images.get(n),oi[n]=e),e},bS=async(n,e)=>{var r,a,i,o;const t=oi[e];if(t&&(t.chats=(r=t.chats)==null?void 0:r.filter(s=>s!==n)),(a=t==null?void 0:t.chats)!=null&&a.length||delete oi[e],Pa){const s=await wi.images.get({id:e});s&&(s.chats=(i=s.chats)==null?void 0:i.filter(l=>l!==n)),(o=s==null?void 0:s.chats)!=null&&o.length?s&&await W_(n,s):wi.images.delete(e)}},pT=async()=>{oi={},Pa&&wi.images.clear()},W_=async(n,e)=>{e.id=e.id||jn();let t;Pa?t=await wi.images.get({id:e.id}):t=oi[e.id],t=t||e,t.chats=t.chats||[],n in t.chats||t.chats.push(n),oi[t.id]=t,Pa&&wi.images.put(t,t.id);const r=JSON.parse(JSON.stringify(t));return delete r.b64image,delete r.chats,r},ni=Hn(!1),ri=Hn(null),ai=Hn([]),TS=Hn(null);function fT(n=1){var r,a;const e=At(ai).length,t=At(ai)[e-1];return At(ri)||(r=t==null?void 0:t.callbacks)!=null&&r.onBeforeClose&&((a=t==null?void 0:t.callbacks)==null?void 0:a.onBeforeClose())===!1?!1:(At(ni)&&e>0&&ri.set(!0),ni.set(!1),TS.set("pop"),gT(n),!0)}function Di(){return fT(1)}function Vr(n,e,t){At(ri)||(TS.set("push"),At(ni)&&At(ai).length&&ri.set(!0),ni.set(!1),t!=null&&t.replace?ai.update(r=>[...r.slice(0,r.length-1),{component:n,props:e}]):ai.update(r=>[...r,{component:n,props:e}]))}function gT(n=1){ai.update(e=>e.slice(0,Math.max(0,e.length-n)))}function rp(n,e,t){const r=n.slice();return r[9]=e[t],r[11]=t,r}const ET=n=>({}),ap=n=>({}),hT=n=>({}),ip=n=>({});function op(n){let e;const t=n[4].backdrop,r=sn(t,n,n[3],ip);return{c(){r&&r.c()},m(a,i){r&&r.m(a,i),e=!0},p(a,i){r&&r.p&&(!e||i&8)&&cn(r,t,a,a[3],e?ln(t,a[3],i,hT):un(a[3]),ip)},i(a){e||(L(r,a),e=!0)},o(a){G(r,a),e=!1},d(a){r&&r.d(a)}}}function ST(n){let e,t,r;const a=[{isOpen:n[11]===n[0].length-1&&!n[1]},n[9].props];var i=n[9].component;function o(s){let l={};for(let c=0;c{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("introstart",s[7]),e.$on("outroend",s[8]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){s&&K(t),e&&Oe(e,s)}}}function bT(n){let e,t,r,a={ctx:n,current:null,token:null,hasCatch:!1,pending:yT,then:vT,catch:TT,value:12,blocks:[,,,]};return Zm(t=lp(n[9].component),a),{c(){e=gt(),a.block.c()},m(i,o){Q(i,e,o),a.block.m(i,a.anchor=o),a.mount=()=>e.parentNode,a.anchor=e,r=!0},p(i,o){n=i,a.ctx=n,o&1&&t!==(t=lp(n[9].component))&&Zm(t,a)||Q1(a,n,o)},i(i){r||(L(a.block),r=!0)},o(i){for(let o=0;o<3;o+=1){const s=a.blocks[o];G(s)}r=!1},d(i){i&&K(e),a.block.d(i),a.token=null,a=null}}}function TT(n){return{c:Ve,m:Ve,p:Ve,i:Ve,o:Ve,d:Ve}}function vT(n){let e,t,r;const a=[{isOpen:n[11]===n[0].length-1&&!n[1]},n[9].props];var i=n[12];function o(s){let l={};for(let c=0;c{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("introstart",s[5]),e.$on("outroend",s[6]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){e&&Oe(e,s),s&&K(t)}}}function yT(n){let e,t;const r=n[4].loading,a=sn(r,n,n[3],ap);return{c(){a&&a.c(),e=ge()},m(i,o){a&&a.m(i,o),Q(i,e,o),t=!0},p(i,o){a&&a.p&&(!t||o&8)&&cn(a,r,i,i[3],t?ln(r,i[3],o,ET):un(i[3]),ap)},i(i){t||(L(a,i),t=!0)},o(i){G(a,i),t=!1},d(i){a&&a.d(i),i&&K(e)}}}function sp(n,e){let t,r,a,i,o,s;const l=[bT,ST],c=[];function u(_,p){return p&1&&(r=null),r==null&&(r=!!NT(_[9].component)),r?0:1}return a=u(e,-1),i=c[a]=l[a](e),{key:n,first:null,c(){t=gt(),i.c(),o=gt(),this.first=t},m(_,p){Q(_,t,p),c[a].m(_,p),Q(_,o,p),s=!0},p(_,p){e=_;let f=a;a=u(e,p),a===f?c[a].p(e,p):(et(),G(c[f],1,1,()=>{c[f]=null}),tt(),i=c[a],i?i.p(e,p):(i=c[a]=l[a](e),i.c()),L(i,1),i.m(o.parentNode,o))},i(_){s||(L(i),s=!0)},o(_){G(i),s=!1},d(_){_&&K(t),c[a].d(_),_&&K(o)}}}function CT(n){let e=[],t=new Map,r,a,i=n[0];const o=s=>s[11];for(let s=0;s0&&op(n);const a=n[4].default,i=sn(a,n,n[3],null),o=i||CT(n);return{c(){r&&r.c(),e=ge(),o&&o.c()},m(s,l){r&&r.m(s,l),Q(s,e,l),o&&o.m(s,l),t=!0},p(s,[l]){s[0].length>0?r?(r.p(s,l),l&1&&L(r,1)):(r=op(s),r.c(),L(r,1),r.m(e.parentNode,e)):r&&(et(),G(r,1,1,()=>{r=null}),tt()),i?i.p&&(!t||l&8)&&cn(i,a,s,s[3],t?ln(a,s[3],l,null):un(s[3]),null):o&&o.p&&(!t||l&15)&&o.p(s,t?l:-1)},i(s){t||(L(r),L(o,s),t=!0)},o(s){G(r),G(o,s),t=!1},d(s){r&&r.d(s),s&&K(e),o&&o.d(s)}}}function NT(n){return typeof n.prototype>"u"}async function lp(n){return n().then(e=>e.default)}function OT(n,e,t){let r,a,i;Gt(n,ai,p=>t(0,r=p)),Gt(n,ri,p=>t(1,a=p)),Gt(n,ni,p=>t(2,i=p));let{$$slots:o={},$$scope:s}=e;const l=()=>{hn(ni,i=!0,i)},c=()=>{hn(ri,a=!1,a)},u=()=>{hn(ni,i=!0,i)},_=()=>{hn(ri,a=!1,a)};return n.$$set=p=>{"$$scope"in p&&t(3,s=p.$$scope)},[r,a,i,s,o,l,c,u,_]}class AT extends Ot{constructor(e){super(),Nt(this,e,OT,RT,Et,{})}}function cp(n){let e,t,r,a,i,o,s,l,c,u,_,p,f,h,v,R,O,x,M,D,P,k,U,F,Z;function Y(J,pe){return J[3]?wT:IT}let X=Y(n),$=X(n);return{c(){e=A("div"),t=A("div"),r=ge(),a=A("div"),i=A("article"),o=A("div"),s=A("p"),l=lt(n[1]),c=ge(),u=A("button"),_=ge(),p=A("div"),$.c(),f=ge(),h=A("div"),v=A("div"),R=A("div"),O=ge(),x=A("div"),M=A("div"),D=A("button"),P=lt(n[4]),S(t,"class","modal-background"),S(u,"class","delete"),S(u,"aria-label","close"),S(u,"type","button"),S(o,"class","message-header"),S(p,"class","message-body"),S(R,"class","level-right"),S(D,"class",k="button "+n[5]),S(D,"type","button"),S(M,"class","level-item"),S(x,"class","level-right"),S(v,"class","level is-mobile"),S(h,"class","message-footer"),S(i,"class",U="message "+n[6]),S(a,"class","modal-content nomax"),S(e,"class","modal is-active")},m(J,pe){Q(J,e,pe),C(e,t),C(e,r),C(e,a),C(a,i),C(i,o),C(o,s),C(s,l),C(o,c),C(o,u),C(i,_),C(i,p),$.m(p,null),C(i,f),C(i,h),C(h,v),C(v,R),C(v,O),C(v,x),C(x,M),C(M,D),C(D,P),F||(Z=[xe(t,"click",n[7]),xe(u,"click",n[7]),xe(D,"click",n[7]),xe(e,"modal-esc",n[7])],F=!0)},p(J,pe){pe&2&&Jt(l,J[1]),X===(X=Y(J))&&$?$.p(J,pe):($.d(1),$=X(J),$&&($.c(),$.m(p,null))),pe&16&&Jt(P,J[4]),pe&32&&k!==(k="button "+J[5])&&S(D,"class",k),pe&64&&U!==(U="message "+J[6])&&S(i,"class",U)},d(J){J&&K(e),$.d(),F=!1,On(Z)}}}function IT(n){let e;return{c(){e=lt(n[2])},m(t,r){Q(t,e,r)},p(t,r){r&4&&Jt(e,t[2])},d(t){t&&K(e)}}}function wT(n){let e,t;return{c(){e=new li(!1),t=gt(),e.a=t},m(r,a){e.m(n[2],r,a),Q(r,t,a)},p(r,a){a&4&&e.p(r[2])},d(r){r&&K(t),r&&e.d()}}}function DT(n){let e,t=n[0]&&cp(n);return{c(){t&&t.c(),e=gt()},m(r,a){t&&t.m(r,a),Q(r,e,a)},p(r,[a]){r[0]?t?t.p(r,a):(t=cp(r),t.c(),t.m(e.parentNode,e)):t&&(t.d(1),t=null)},i:Ve,o:Ve,d(r){t&&t.d(r),r&&K(e)}}}function MT(n,e,t){let{isOpen:r}=e,{title:a}=e,{message:i}=e,{asHtml:o=!1}=e,{onConfirm:s=null}=e,{confirmButton:l="Close"}=e,{confirmButtonClass:c="is-info"}=e,{class:u=""}=e;const _=()=>{(!s||!s())&&Di()};return n.$$set=p=>{"isOpen"in p&&t(0,r=p.isOpen),"title"in p&&t(1,a=p.title),"message"in p&&t(2,i=p.message),"asHtml"in p&&t(3,o=p.asHtml),"onConfirm"in p&&t(8,s=p.onConfirm),"confirmButton"in p&&t(4,l=p.confirmButton),"confirmButtonClass"in p&&t(5,c=p.confirmButtonClass),"class"in p&&t(6,u=p.class)},[r,a,i,o,l,c,u,_,s]}class xT extends Ot{constructor(e){super(),Nt(this,e,MT,DT,Et,{isOpen:0,title:1,message:2,asHtml:3,onConfirm:8,confirmButton:4,confirmButtonClass:5,class:6})}}function kT(n,e){if(n===e)throw new Error("Cannot compare node with itself");const t={a:_p(n),b:_p(e)};let r;for(;t.a.at(-1)===t.b.at(-1);)n=t.a.pop(),e=t.b.pop(),r=n;const a={a:dp(up(t.a)),b:dp(up(t.b))};if(a.a===a.b){const i=r.childNodes,o={a:t.a.at(-1),b:t.b.at(-1)};let s=i.length;for(;s--;){const l=i[s];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(a.a-a.b)}const LT=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function PT(n){const e=getComputedStyle(vS(n)).display;return e==="flex"||e==="inline-flex"}function UT(n){const e=getComputedStyle(n);return!!(e.position==="fixed"||e.zIndex!=="auto"&&e.position!=="static"||PT(n)||+e.opacity<1||"transform"in e&&e.transform!=="none"||"webkitTransform"in e&&e.webkitTransform!=="none"||"mixBlendMode"in e&&e.mixBlendMode!=="normal"||"filter"in e&&e.filter!=="none"||"webkitFilter"in e&&e.webkitFilter!=="none"||"isolation"in e&&e.isolation==="isolate"||LT.test(e.willChange)||e.webkitOverflowScrolling==="touch")}function up(n){let e=n.length;for(;e--;)if(UT(n[e]))return n[e];return null}function dp(n){return n&&Number(getComputedStyle(n).zIndex)||0}function _p(n){const e=[];for(;n;)e.push(n),n=vS(n);return e}function vS(n){var e;return((e=n.parentNode)==null?void 0:e.host)||n.parentNode}const yS=()=>{const n="0123456789abcdef";let e="";for(let t=0;t<8;t++)e+=n.charAt(Math.floor(Math.random()*n.length));return e};let yl=[],mp=0;const C_=n=>{const e=document.querySelectorAll("textarea.auto-size");(n||e.length!==mp)&&(yl=Array.from(e),mp=e.length);for(let t=0,r=yl.length;t{n.target!==null&&(n.target.__didAutoGrow=!1,CS(n.target))},CS=(n,e)=>{const t=n;(e||!t.__didAutoGrow)&&(n.style.height="38px"),n.style.height=n.scrollHeight+"px",setTimeout(()=>{n.scrollHeight>n.getBoundingClientRect().height+5?n.style.overflowY="auto":n.style.overflowY=""},0),t.__didAutoGrow=!0},BT=(n,e,t=!1,r=!1)=>{const a=t?"instant":"smooth";r?window.scrollTo({behavior:a,top:n.getBoundingClientRect().bottom-document.body.getBoundingClientRect().top-(window.innerHeight-e)}):window.scrollTo({behavior:a,top:n.getBoundingClientRect().top-document.body.getBoundingClientRect().top-e})},Es=(n,e=60,t=!1,r=!1)=>{if(Array.isArray(n)&&(n=n[0]),!n){console.error("Not a valid uuid",n);return}const a=document.getElementById("message-"+n);a?BT(a,e,t,r):console.error("Can't find element with message ID",n)},cs=(n=!1)=>{setTimeout(()=>{var e;return(e=document.querySelector("body"))==null?void 0:e.scrollIntoView({behavior:n?"instant":"smooth",block:"end"})},0)},FT=n=>{!n||n.key!=="Escape"||RS()},RS=()=>{const n=Array.from(document.querySelectorAll(".modal, .has-esc")).filter(t=>window.getComputedStyle(t).getPropertyValue("display")!=="none"),e=n.length===1?n[0]:n.find(t=>n.find(r=>t!==r&&kT(t,r)>0&&t));if(e){const t=new CustomEvent("modal-esc",{detail:e});e.dispatchEvent(t)}},GT=n=>n.replace(/[\u00A0-\u9999<>&]/g,e=>`&#${e.charCodeAt(0)};`),Zn=(n,e=void 0)=>{Vr(xT,{title:"Error",class:"is-danger",message:n+(e?"
"+e.message:""),asHtml:!0,onConfirm:()=>{}})},hs=(n,e)=>{(()=>{const r=Is(e);Kr(`/chat/${r}`)})()},Ja=(n,e)=>typeof e=="function"?e(n):e,qT=()=>{try{const n=localStorage.getItem("chats");if(!n)return console.log("No chat data found to migrate"),!1;const e=JSON.parse(n);if(!Array.isArray(e)||e.length===0)return console.log("No chats to migrate"),!1;let t=0;const r=new Map;if(e.forEach(i=>{if(typeof i.id=="number"){const o=yS();r.set(i.id,o),i.id=o,t++}}),t===0)return console.log("No numeric chat IDs found to migrate"),!1;const a=localStorage.getItem("lastChatId");if(a){const i=JSON.parse(a);typeof i=="number"&&r.has(i)&&localStorage.setItem("lastChatId",JSON.stringify(r.get(i)))}return localStorage.setItem("chats",JSON.stringify(e)),console.log(`Successfully migrated ${t} chats from numeric IDs to hex UUIDs`),!0}catch(n){return console.error("Error during chat data migration:",n),!1}},YT="modulepreload",zT=function(n){return"/"+n},pp={},HT=function(e,t,r){if(!t||t.length===0)return e();const a=document.getElementsByTagName("link");return Promise.all(t.map(i=>{if(i=zT(i),i in pp)return;pp[i]=!0;const o=i.endsWith(".css"),s=o?'[rel="stylesheet"]':"";if(!!r)for(let u=a.length-1;u>=0;u--){const _=a[u];if(_.href===i&&(!o||_.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${i}"]${s}`))return;const c=document.createElement("link");if(c.rel=o?"stylesheet":YT,o||(c.as="script",c.crossOrigin=""),c.href=i,document.head.appendChild(c),o)return new Promise((u,_)=>{c.addEventListener("load",u),c.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${i}`)))})})).then(()=>e()).catch(i=>{const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i})},VT={prompt:15,completion:60,max:2e5,reasoning:!0},$T={prompt:10,completion:40,max:2e5,reasoning:!0},WT={"claude-sonnet-4-20250514":{prompt:3,completion:15,max:2e5},"claude-opus-4-20250514":{prompt:15,completion:75,max:2e5},"claude-3-7-sonnet-20250219":{prompt:3,completion:15,max:2e5},"gpt-5":{prompt:1.25,completion:10,max:2e5,reasoning:!0},"gpt-5-mini":{prompt:.25,completion:2,max:2e5,reasoning:!0},"gpt-5-nano":{prompt:.05,completion:.4,max:2e5,reasoning:!0},"gpt-5-chat-latest":{prompt:1.25,completion:10,max:2e5,reasoning:!0},"gpt-4.1":{prompt:2,completion:8,max:131072},"gpt-4.1-mini":{prompt:.4,completion:1.6,max:131072},"gpt-4.1-nano":{prompt:.1,completion:.03,max:131072},"gpt-4o":{prompt:2.5,completion:10,max:131072},"gpt-4o-mini":{prompt:.15,completion:.6,max:131072},o1:VT,"o1-pro":{prompt:150,completion:600,max:2e5,reasoning:!0},"o3-pro":{prompt:20,completion:80,max:2e5,reasoning:!0},o3:$T,"o4-mini":{prompt:1.1,completion:4.4,max:2e5,reasoning:!0},"o3-mini":{prompt:1.1,completion:4.4,max:2e5,reasoning:!0},"o1-mini":{prompt:1.1,completion:4.4,max:131072,reasoning:!0},"models/gemini-2.5-flash-preview-05-20":{prompt:.15,completion:.6,max:1e6,alias:"gemini-2.5-flash"},"models/gemini-2.5-pro-preview-06-05":{prompt:1.25,completion:10,max:2e5,alias:"gemini-2.5-pro"},"deepseek-r1-distill-qwen-32b":{prompt:.69,completion:.69,max:16384},"deepseek-r1-distill-llama-70b":{prompt:3,completion:3,max:4096}};var Cl={local:{},session:{}};function KT(n){return n==="local"?localStorage:sessionStorage}function Pi(n,e,t){var r,a;const i=(r=t==null?void 0:t.serializer)!=null?r:JSON,o=(a=t==null?void 0:t.storage)!=null?a:"local",s=typeof window<"u"&&typeof document<"u",l=s?KT(o):null;function c(u,_){l==null||l.setItem(u,i.stringify(_))}if(!Cl[o][n]){const u=Hn(e,f=>{const h=l==null?void 0:l.getItem(n);if(h&&f(i.parse(h)),s&&o=="local"){const v=R=>{R.key===n&&f(R.newValue?i.parse(R.newValue):null)};return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)}}),{subscribe:_,set:p}=u;Cl[o][n]={set(f){c(n,f),p(f)},update(f){return u.update(h=>{const v=f(h);return c(n,v),v})},subscribe:_}}return Cl[o][n]}const NS=Pi("apiBase","https://api.openai.com"),QT=At(NS)||"https://api.openai.com",XT={}.VITE_ENDPOINT_COMPLETIONS||"/v1/chat/completions",ZT={}.VITE_ENDPOINT_GENERATIONS||"/v1/images/generations",jT={}.VITE_ENDPOINT_MODELS||"/v1/models",fp=n=>{console.log(n),NS.set(n||"")},Fs=()=>QT,JT=()=>XT,ev=()=>ZT,tv=()=>jT;let wa,gp;const OS=n=>{wa=void 0,To.set(n.apiKey||"")},nv=async()=>{if(wa)return wa;const n=At(To);if(!n)return{};try{return wa=(await(await fetch(Fs()+tv(),{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}})).json()).data.reduce((t,r)=>(t[r.id]=r,t),{}),wa}catch{return wa={},clearTimeout(gp),gp=setTimeout(()=>{wa=void 0},1e3),wa}},AS=async n=>{const e=await nv();n.type==="chat"||n.type==="instruct"?n.enabled=!!e[n.modelQuery||""]:n.enabled=!!Object.keys(e).length},Ss=(n,e)=>{const t=Qt(e);return n.prompt_tokens*(t.prompt||0)+n.completion_tokens*(t.completion||0)},Oa=(n,e,t)=>Qt(e).countPromptTokens(n,e,t),Ri=(n,e,t)=>Qt(e).countMessageTokens(n,e,t),N_=n=>Qt(n).max;class rv{constructor(e){Ht(this,"offsetTotals");Ht(this,"isFill",!1);Ht(this,"didFill",!1);Ht(this,"opts");Ht(this,"chat");Ht(this,"messages");Ht(this,"error");Ht(this,"model");Ht(this,"lastModel");Ht(this,"setModel",e=>{e&&(!this.model&&Ey(this.chat.settings.model,e),this.lastModel=this.model||e,this.model=e)});Ht(this,"finishResolver");Ht(this,"errorResolver");Ht(this,"finishPromise",new Promise((e,t)=>{this.finishResolver=e,this.errorResolver=t}));Ht(this,"promptTokenCount");Ht(this,"finished",!1);Ht(this,"messageChangeListeners",[]);Ht(this,"finishListeners",[]);Ht(this,"onMessageChange",e=>this.messageChangeListeners.push(e));Ht(this,"onFinish",e=>this.finishListeners.push(e));Ht(this,"promiseToFinish",()=>this.finishPromise);Ht(this,"hasFinished",()=>this.finished);Ht(this,"getError",()=>this.error);Ht(this,"hasError",()=>!!this.error);Ht(this,"getMessages",()=>this.messages);Ht(this,"finish",(e="")=>{if(this.finished)return;this.messages.forEach(a=>{a.streaming=!1,e&&(a.finish_reason=e)}),so(this.chat.id),this.finished=!0;const t=this.messages[0],r=this.model||gy(this.chat.settings.model);if(t)this.isFill&&this.lastModel===this.model&&this.offsetTotals&&r&&t.usage&&ly(this.chat.id,this.offsetTotals,r),Rp(this.chat.id,t.usage,r);else if(this.model){const a={prompt_tokens:this.promptTokenCount,completion_tokens:0,total_tokens:this.promptTokenCount};Rp(this.chat.id,a,r)}this.notifyFinish(),this.error?this.errorResolver(this.error):this.finishResolver(this.messages)});this.opts=e,this.chat=e.chat,this.messages=[],e.fillMessage&&(this.messages.push(e.fillMessage),this.offsetTotals=e.fillMessage.usage&&JSON.parse(JSON.stringify(e.fillMessage.usage)),this.isFill=!0),e.onMessageChange&&this.messageChangeListeners.push(e.onMessageChange)}initialFillMerge(e,t){const r=Qt(this.model);return!this.didFill&&this.isFill&&r.preFillMerge&&(e=r.preFillMerge(e,t)),this.didFill=!0,e}setPromptTokenCount(e){this.promptTokenCount=e}getPromptTokenCount(){return this.promptTokenCount}async updateImageFromSyncResponse(e,t,r){this.setModel(r);for(let a=0;a{var l,c,u,_,p;const o=this.messages[i],s=o||a.message;o?(s.content=this.initialFillMerge(s.content,a.message.content),s.content+=a.message.content,s.usage=s.usage||{prompt_tokens:0,completion_tokens:0,total_tokens:0},s.usage.completion_tokens+=((l=e==null?void 0:e.usage)==null?void 0:l.completion_tokens)||0,s.usage.prompt_tokens=(((c=e==null?void 0:e.usage)==null?void 0:c.prompt_tokens)||0)+(((u=this.offsetTotals)==null?void 0:u.prompt_tokens)||0),s.usage.total_tokens=(((_=e==null?void 0:e.usage)==null?void 0:_.total_tokens)||0)+(((p=this.offsetTotals)==null?void 0:p.total_tokens)||0)):(s.content=a.message.content,s.usage=e.usage),s.finish_reason=a.finish_reason,s.role=a.message.role,s.model=e.model,this.messages[i]=s,this.opts.autoAddMessages&&ca(this.chat.id,s)}),this.notifyMessageChange(),this.finish()}updateFromAsyncResponse(e){var o,s,l;let t=0;if(this.setModel(e.model),!e.choices||e!=null&&e.error)return this.updateFromError(((o=e==null?void 0:e.error)==null?void 0:o.message)||"unexpected streaming response from API");(s=e.choices)==null||s.forEach((c,u)=>{var p,f,h;const _=this.messages[u]||{role:"assistant",content:"",uuid:jn()};(p=c.delta)!=null&&p.role&&(_.role=c.delta.role),(f=c.delta)!=null&&f.content&&(_.content=this.initialFillMerge(_.content,(h=c.delta)==null?void 0:h.content),_.content+=c.delta.content),t+=DS(this.model,_.content),_.model=e.model,_.finish_reason=c.finish_reason,_.streaming=!c.finish_reason&&!this.finished,this.messages[u]=_});const r=this.promptTokenCount+(((l=this.offsetTotals)==null?void 0:l.prompt_tokens)||0),a=r+t;this.messages.forEach(c=>{c.usage={completion_tokens:t,total_tokens:a,prompt_tokens:r},this.opts.autoAddMessages&&ca(this.chat.id,c)});const i=!this.messages.find(c=>c.streaming);this.notifyMessageChange(),i&&this.finish()}updateFromError(e){this.finished||this.error||(this.error=e,this.opts.autoAddMessages&&ca(this.chat.id,{role:"error",content:`Error: ${e}`,uuid:jn()}),this.notifyMessageChange(),setTimeout(()=>this.finish("abort"),200))}updateFromClose(e=!1){var t;if(!this.finished&&!this.error&&!((t=this.messages)!=null&&t.find(r=>r.content))){if(!e)return setTimeout(()=>this.updateFromClose(!0),300);if(!this.finished)return this.updateFromError("Unexpected connection termination")}setTimeout(()=>this.finish(),260)}notifyMessageChange(){this.messageChangeListeners.forEach(e=>{e(this.messages)})}notifyFinish(){this.finishListeners.forEach(e=>{e(this.messages)})}}class Ep{constructor(){Ht(this,"chat");Ht(this,"updating",!1);Ht(this,"updatingMessage","");Ht(this,"controller");Ht(this,"providerData",{});this.controller=new AbortController,this.updating=!1,this.updatingMessage=""}setChat(e){this.chat=e,this.chat.settings.model=this.getModel()}getChat(){return this.chat}getChatSettings(){return this.chat.settings}async handleError(e){var r,a,i,o;let t;try{const s=await e.json();t=((r=s==null?void 0:s.error)==null?void 0:r.message)||((a=s==null?void 0:s.error)==null?void 0:a.code),!t&&e.choices&&e.choices[0]&&(t=(o=(i=e.choices[0])==null?void 0:i.message)==null?void 0:o.content),t=t||"Unexpected Response"}catch(s){console.error(s,s.stack),t="Unknown Response"}throw new Error(`${e.status} - ${t}`)}async sendRequest(e,t,r={}){var P,k,U,F,Z;const a=this,i=Dr(a.chat.id);this.setChat(i);const o=a.chat.settings,s=i.id,l=/^\s*(please|can\s+you|will\s+you)*\s*(give|generate|create|show|build|design)\s+(me)*\s*(an|a|set|a\s+set\s+of)*\s*([0-9]+|one|two|three|four)*\s+(image|photo|picture|pic)s*\s*(for\s+me)*\s*(of|[^a-z0-9]+|about|that\s+has|showing|with|having|depicting)\s+[^a-z0-9]*(.*)$/i;t.chat=i,a.updating=!0;const c=e[e.length-1],u=new rv(t);if(a.controller=new AbortController,o.imageGenerationModel&&!t.didSummary&&!t.summaryRequest&&(c==null?void 0:c.role)==="user"){const Y=c.content.match(l);if(Y){let X=parseInt((Y[5]||"").toLowerCase().trim().replace(/one/ig,"1").replace(/two/ig,"2").replace(/three/ig,"3").replace(/four/ig,"4"));return isNaN(X)&&(X=1),X=Math.min(Math.max(1,X),4),c.suppress=!0,await Qt(o.imageGenerationModel).request({},a,u,{...t,prompt:Y[9],count:X})}}const _=this.getModel(),p=Qt(_),f=N_(_),h=["user","assistant"].concat(o.useSystemPrompt?["system"]:[]),v=Y=>!Y.suppress&&h.includes(Y.role)&&Y.content&&!Y.summarized,R=e.filter(v);if(!t.didSummary&&!t.summaryRequest&&o.continuousChat)return await this.doContinuousChat(R,t,r);this.buildHiddenPromptPrefixMessages(R,!0);const O=R.filter(Y=>Y.skipOnce?(delete Y.skipOnce,!1):!0).map(Y=>{const X=Y.content+(Y.appendOnce||[]).join(` + `+I:""),this.inner=I||null):typeof y=="object"&&(this.message="".concat(y.name," ").concat(y.message),this.inner=y):(this.message=he[m]||E,this.inner=null)}return v(T).from(Ce),d[m]=T,d},{});be.Syntax=SyntaxError,be.Type=TypeError,be.Range=RangeError;var ht=rn.reduce(function(d,m){return d[m+"Error"]=be[m],d},{}),ke=Nr.reduce(function(d,m){return["Syntax","Type","Range"].indexOf(m)===-1&&(d[m+"Error"]=be[m]),d},{});function Be(){}function mt(d){return d}function qt(d,m){return d==null||d===mt?m:function(E){return m(d(E))}}function Zt(d,m){return function(){d.apply(this,arguments),m.apply(this,arguments)}}function Ct(d,m){return d===Be?m:function(){var E=d.apply(this,arguments);E!==void 0&&(arguments[0]=E);var T=this.onsuccess,y=this.onerror;this.onsuccess=null,this.onerror=null;var I=m.apply(this,arguments);return T&&(this.onsuccess=this.onsuccess?Zt(T,this.onsuccess):T),y&&(this.onerror=this.onerror?Zt(y,this.onerror):y),I!==void 0?I:E}}function en(d,m){return d===Be?m:function(){d.apply(this,arguments);var E=this.onsuccess,T=this.onerror;this.onsuccess=this.onerror=null,m.apply(this,arguments),E&&(this.onsuccess=this.onsuccess?Zt(E,this.onsuccess):E),T&&(this.onerror=this.onerror?Zt(T,this.onerror):T)}}function Fe(d,m){return d===Be?m:function(E){var T=d.apply(this,arguments);l(E,T);var y=this.onsuccess,I=this.onerror;return this.onsuccess=null,this.onerror=null,E=m.apply(this,arguments),y&&(this.onsuccess=this.onsuccess?Zt(y,this.onsuccess):y),I&&(this.onerror=this.onerror?Zt(I,this.onerror):I),T===void 0?E===void 0?void 0:E:l(T,E)}}function Ue(d,m){return d===Be?m:function(){return m.apply(this,arguments)!==!1&&d.apply(this,arguments)}}function ut(d,m){return d===Be?m:function(){var E=d.apply(this,arguments);if(E&&typeof E.then=="function"){for(var T=this,y=arguments.length,I=new Array(y);y--;)I[y]=arguments[y];return E.then(function(){return m.apply(T,I)})}return m.apply(this,arguments)}}ke.ModifyError=Me,ke.DexieError=qe,ke.BulkError=fe;var dt=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function kt(d){dt=d}var En={},nn=100,Pr=typeof Promise>"u"?[]:function(){var d=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[d,c(d),d];var m=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[m,c(m),d]}(),rn=Pr[0],Nr=Pr[1],Pr=Pr[2],Nr=Nr&&Nr.then,tn=rn&&rn.constructor,$e=!!Pr,Ze=function(d,m){wn.push([d,m]),vt&&(queueMicrotask(Bn),vt=!1)},_t=!0,vt=!0,Lt=[],dn=[],Sn=mt,yn={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Be,pgp:!1,env:{},finalize:Be},at=yn,wn=[],kn=0,It=[];function We(d){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var m=this._PSD=at;if(typeof d!="function"){if(d!==En)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&er(this,this._value))}this._state=null,this._value=null,++m.ref,function E(T,y){try{y(function(I){if(T._state===null){if(I===T)throw new TypeError("A promise cannot be resolved with itself.");var B=T._lib&&tr();I&&typeof I.then=="function"?E(T,function(V,ne){I instanceof We?I._then(V,ne):I.then(V,ne)}):(T._state=!0,T._value=I,Fn(T)),B&&nr()}},er.bind(null,T))}catch(I){er(T,I)}}(this,d)}var Cn={get:function(){var d=at,m=$n;function E(T,y){var I=this,B=!d.global&&(d!==at||m!==$n),V=B&&!Er(),ne=new We(function(j,se){ur(I,new Jn(Jr(T,d,B,V),Jr(y,d,B,V),j,se,d))});return this._consoleTask&&(ne._consoleTask=this._consoleTask),ne}return E.prototype=En,E},set:function(d){h(this,"then",d&&d.prototype===En?Cn:{get:function(){return d},set:Cn.set})}};function Jn(d,m,E,T,y){this.onFulfilled=typeof d=="function"?d:null,this.onRejected=typeof m=="function"?m:null,this.resolve=E,this.reject=T,this.psd=y}function er(d,m){var E,T;dn.push(m),d._state===null&&(E=d._lib&&tr(),m=Sn(m),d._state=!1,d._value=m,T=d,Lt.some(function(y){return y._value===T._value})||Lt.push(T),Fn(d),E&&nr())}function Fn(d){var m=d._listeners;d._listeners=[];for(var E=0,T=m.length;E.",Mn="String expected.",Cr=[],ta="__dbnames",Ta="readonly",mr="readwrite";function Rr(d,m){return d?m?function(){return d.apply(this,arguments)&&m.apply(this,arguments)}:d:m}var it={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function on(d){return typeof d!="string"||/\./.test(d)?function(m){return m}:function(m){return m[d]===void 0&&d in m&&delete(m=J(m))[d],m}}function va(){throw be.Type()}function Yt(d,m){try{var E=No(d),T=No(m);if(E!==T)return E==="Array"?1:T==="Array"?-1:E==="binary"?1:T==="binary"?-1:E==="string"?1:T==="string"?-1:E==="Date"?1:T!=="Date"?NaN:-1;switch(E){case"number":case"Date":case"string":return mTe+Ie&&me(Te+le)})})}var Se=ya(E)&&E.limit===1/0&&(typeof d!="function"||d===zi)&&{index:E.index,range:E.range};return me(0).then(function(){if(0=le})).length!==0?(se.forEach(function(me){ce.push(function(){var Se=ae,Te=me._cfg.dbschema;Bo(W,Se,ie),Bo(W,Te,ie),ae=W._dbSchema=Te;var Ie=il(Se,Te);Ie.add.forEach(function(Je){ol(ie,Je[0],Je[1].primKey,Je[1].indexes)}),Ie.change.forEach(function(Je){if(Je.recreate)throw new be.Upgrade("Not yet support for changing primary key");var Ge=ie.objectStore(Je.name);Je.add.forEach(function(wt){return Po(Ge,wt)}),Je.change.forEach(function(wt){Ge.deleteIndex(wt.name),Po(Ge,wt)}),Je.del.forEach(function(wt){return Ge.deleteIndex(wt)})});var ze=me._cfg.contentUpgrade;if(ze&&me._cfg.version>le){ko(W,ie),te._memoizedTables={};var je=F(Te);Ie.del.forEach(function(Je){je[Je]=Se[Je]}),al(W,[W.Transaction.prototype]),Lo(W,[W.Transaction.prototype],o(je),je),te.schema=je;var He,Xe=we(ze);return Xe&&Lr(),Ie=We.follow(function(){var Je;(He=ze(te))&&Xe&&(Je=Er.bind(null,null),He.then(Je,Je))}),He&&typeof He.then=="function"?We.resolve(He):Ie.then(function(){return He})}}),ce.push(function(Se){var Te,Ie,ze=me._cfg.dbschema;Te=ze,Ie=Se,[].slice.call(Ie.db.objectStoreNames).forEach(function(je){return Te[je]==null&&Ie.db.deleteObjectStore(je)}),al(W,[W.Transaction.prototype]),Lo(W,[W.Transaction.prototype],W._storeNames,W._dbSchema),te.schema=W._dbSchema}),ce.push(function(Se){W.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(W.idbdb.version/10)===me._cfg.version?(W.idbdb.deleteObjectStore("$meta"),delete W._dbSchema.$meta,W._storeNames=W._storeNames.filter(function(Te){return Te!=="$meta"})):Se.objectStore("$meta").put(me._cfg.version,"version"))})}),function me(){return ce.length?We.resolve(ce.shift()(te.idbtrans)).then(me):We.resolve()}().then(function(){xm(ae,ie)})):We.resolve();var W,le,te,ie,ce,ae}).catch(B)):(o(y).forEach(function(se){ol(E,se,y[se].primKey,y[se].indexes)}),ko(d,E),void We.follow(function(){return d.on.populate.fire(I)}).catch(B));var ne,j})}function O1(d,m){xm(d._dbSchema,m),m.db.version%10!=0||m.objectStoreNames.contains("$meta")||m.db.createObjectStore("$meta").add(Math.ceil(m.db.version/10-1),"version");var E=Uo(0,d.idbdb,m);Bo(d,d._dbSchema,m);for(var T=0,y=il(E,d._dbSchema).change;TMath.pow(2,62)?0:ae.oldVersion,W=ae<1,d.idbdb=ce.result,I&&O1(d,se),N1(d,ae/10,se,te))},te),ce.onsuccess=Mt(function(){se=null;var ae,me,Se,Te,Ie,ze=d.idbdb=ce.result,je=x(ze.objectStoreNames);if(0"u"?We.resolve():!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(le){function te(){return indexedDB.databases().finally(le)}ne=setInterval(te,100),te()}).finally(function(){return clearInterval(ne)}):Promise.resolve()).then(V)]).then(function(){return B(),m.onReadyBeingFired=[],We.resolve(cl(function(){return d.on.ready.fire(d.vip)})).then(function le(){if(0m.limit?le.length=m.limit:d.length===m.limit&&le.length=me.limit&&(!me.values||ze.req.values)&&k1(ze.req.query.range,me.query.range)}),!1,Se,Te];case"count":return Ie=Te.find(function(ze){return Hm(ze.req.query.range,me.query.range)}),[Ie,!!Ie,Se,Te]}}(m,E,"query",I),se=j[0],W=j[1],le=j[2],te=j[3];return se&&W?se.obsSet=I.obsSet:(W=T.query(I).then(function(ie){var ce=ie.result;if(se&&(se.res=ce),B){for(var ae=0,me=ce.length;ae{Pa=!1});let oi={};class mT extends y_{constructor(){super("chatImageStore");Ht(this,"images");this.version(1).stores({images:"id"})}}const wi=new mT,SS=async n=>{let e=oi[n];return e||!Pa||(e=await wi.images.get(n),oi[n]=e),e},bS=async(n,e)=>{var r,a,i,o;const t=oi[e];if(t&&(t.chats=(r=t.chats)==null?void 0:r.filter(s=>s!==n)),(a=t==null?void 0:t.chats)!=null&&a.length||delete oi[e],Pa){const s=await wi.images.get({id:e});s&&(s.chats=(i=s.chats)==null?void 0:i.filter(l=>l!==n)),(o=s==null?void 0:s.chats)!=null&&o.length?s&&await W_(n,s):wi.images.delete(e)}},pT=async()=>{oi={},Pa&&wi.images.clear()},W_=async(n,e)=>{e.id=e.id||jn();let t;Pa?t=await wi.images.get({id:e.id}):t=oi[e.id],t=t||e,t.chats=t.chats||[],n in t.chats||t.chats.push(n),oi[t.id]=t,Pa&&wi.images.put(t,t.id);const r=JSON.parse(JSON.stringify(t));return delete r.b64image,delete r.chats,r},ni=Hn(!1),ri=Hn(null),ai=Hn([]),TS=Hn(null);function fT(n=1){var r,a;const e=At(ai).length,t=At(ai)[e-1];return At(ri)||(r=t==null?void 0:t.callbacks)!=null&&r.onBeforeClose&&((a=t==null?void 0:t.callbacks)==null?void 0:a.onBeforeClose())===!1?!1:(At(ni)&&e>0&&ri.set(!0),ni.set(!1),TS.set("pop"),gT(n),!0)}function Di(){return fT(1)}function Vr(n,e,t){At(ri)||(TS.set("push"),At(ni)&&At(ai).length&&ri.set(!0),ni.set(!1),t!=null&&t.replace?ai.update(r=>[...r.slice(0,r.length-1),{component:n,props:e}]):ai.update(r=>[...r,{component:n,props:e}]))}function gT(n=1){ai.update(e=>e.slice(0,Math.max(0,e.length-n)))}function rp(n,e,t){const r=n.slice();return r[9]=e[t],r[11]=t,r}const ET=n=>({}),ap=n=>({}),hT=n=>({}),ip=n=>({});function op(n){let e;const t=n[4].backdrop,r=sn(t,n,n[3],ip);return{c(){r&&r.c()},m(a,i){r&&r.m(a,i),e=!0},p(a,i){r&&r.p&&(!e||i&8)&&cn(r,t,a,a[3],e?ln(t,a[3],i,hT):un(a[3]),ip)},i(a){e||(L(r,a),e=!0)},o(a){G(r,a),e=!1},d(a){r&&r.d(a)}}}function ST(n){let e,t,r;const a=[{isOpen:n[11]===n[0].length-1&&!n[1]},n[9].props];var i=n[9].component;function o(s){let l={};for(let c=0;c{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("introstart",s[7]),e.$on("outroend",s[8]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){s&&K(t),e&&Oe(e,s)}}}function bT(n){let e,t,r,a={ctx:n,current:null,token:null,hasCatch:!1,pending:yT,then:vT,catch:TT,value:12,blocks:[,,,]};return Zm(t=lp(n[9].component),a),{c(){e=gt(),a.block.c()},m(i,o){Q(i,e,o),a.block.m(i,a.anchor=o),a.mount=()=>e.parentNode,a.anchor=e,r=!0},p(i,o){n=i,a.ctx=n,o&1&&t!==(t=lp(n[9].component))&&Zm(t,a)||Q1(a,n,o)},i(i){r||(L(a.block),r=!0)},o(i){for(let o=0;o<3;o+=1){const s=a.blocks[o];G(s)}r=!1},d(i){i&&K(e),a.block.d(i),a.token=null,a=null}}}function TT(n){return{c:Ve,m:Ve,p:Ve,i:Ve,o:Ve,d:Ve}}function vT(n){let e,t,r;const a=[{isOpen:n[11]===n[0].length-1&&!n[1]},n[9].props];var i=n[12];function o(s){let l={};for(let c=0;c{Oe(u,1)}),tt()}i?(e=Xt(i,o()),e.$on("introstart",s[5]),e.$on("outroend",s[6]),Ae(e.$$.fragment),L(e.$$.fragment,1),Ne(e,t.parentNode,t)):e=null}else i&&e.$set(c)},i(s){r||(e&&L(e.$$.fragment,s),r=!0)},o(s){e&&G(e.$$.fragment,s),r=!1},d(s){e&&Oe(e,s),s&&K(t)}}}function yT(n){let e,t;const r=n[4].loading,a=sn(r,n,n[3],ap);return{c(){a&&a.c(),e=ge()},m(i,o){a&&a.m(i,o),Q(i,e,o),t=!0},p(i,o){a&&a.p&&(!t||o&8)&&cn(a,r,i,i[3],t?ln(r,i[3],o,ET):un(i[3]),ap)},i(i){t||(L(a,i),t=!0)},o(i){G(a,i),t=!1},d(i){a&&a.d(i),i&&K(e)}}}function sp(n,e){let t,r,a,i,o,s;const l=[bT,ST],c=[];function u(_,p){return p&1&&(r=null),r==null&&(r=!!NT(_[9].component)),r?0:1}return a=u(e,-1),i=c[a]=l[a](e),{key:n,first:null,c(){t=gt(),i.c(),o=gt(),this.first=t},m(_,p){Q(_,t,p),c[a].m(_,p),Q(_,o,p),s=!0},p(_,p){e=_;let f=a;a=u(e,p),a===f?c[a].p(e,p):(et(),G(c[f],1,1,()=>{c[f]=null}),tt(),i=c[a],i?i.p(e,p):(i=c[a]=l[a](e),i.c()),L(i,1),i.m(o.parentNode,o))},i(_){s||(L(i),s=!0)},o(_){G(i),s=!1},d(_){_&&K(t),c[a].d(_),_&&K(o)}}}function CT(n){let e=[],t=new Map,r,a,i=n[0];const o=s=>s[11];for(let s=0;s0&&op(n);const a=n[4].default,i=sn(a,n,n[3],null),o=i||CT(n);return{c(){r&&r.c(),e=ge(),o&&o.c()},m(s,l){r&&r.m(s,l),Q(s,e,l),o&&o.m(s,l),t=!0},p(s,[l]){s[0].length>0?r?(r.p(s,l),l&1&&L(r,1)):(r=op(s),r.c(),L(r,1),r.m(e.parentNode,e)):r&&(et(),G(r,1,1,()=>{r=null}),tt()),i?i.p&&(!t||l&8)&&cn(i,a,s,s[3],t?ln(a,s[3],l,null):un(s[3]),null):o&&o.p&&(!t||l&15)&&o.p(s,t?l:-1)},i(s){t||(L(r),L(o,s),t=!0)},o(s){G(r),G(o,s),t=!1},d(s){r&&r.d(s),s&&K(e),o&&o.d(s)}}}function NT(n){return typeof n.prototype>"u"}async function lp(n){return n().then(e=>e.default)}function OT(n,e,t){let r,a,i;Gt(n,ai,p=>t(0,r=p)),Gt(n,ri,p=>t(1,a=p)),Gt(n,ni,p=>t(2,i=p));let{$$slots:o={},$$scope:s}=e;const l=()=>{hn(ni,i=!0,i)},c=()=>{hn(ri,a=!1,a)},u=()=>{hn(ni,i=!0,i)},_=()=>{hn(ri,a=!1,a)};return n.$$set=p=>{"$$scope"in p&&t(3,s=p.$$scope)},[r,a,i,s,o,l,c,u,_]}class AT extends Ot{constructor(e){super(),Nt(this,e,OT,RT,Et,{})}}function cp(n){let e,t,r,a,i,o,s,l,c,u,_,p,f,h,v,R,O,x,M,D,P,k,U,F,Z;function Y(J,pe){return J[3]?wT:IT}let X=Y(n),$=X(n);return{c(){e=A("div"),t=A("div"),r=ge(),a=A("div"),i=A("article"),o=A("div"),s=A("p"),l=lt(n[1]),c=ge(),u=A("button"),_=ge(),p=A("div"),$.c(),f=ge(),h=A("div"),v=A("div"),R=A("div"),O=ge(),x=A("div"),M=A("div"),D=A("button"),P=lt(n[4]),S(t,"class","modal-background"),S(u,"class","delete"),S(u,"aria-label","close"),S(u,"type","button"),S(o,"class","message-header"),S(p,"class","message-body"),S(R,"class","level-right"),S(D,"class",k="button "+n[5]),S(D,"type","button"),S(M,"class","level-item"),S(x,"class","level-right"),S(v,"class","level is-mobile"),S(h,"class","message-footer"),S(i,"class",U="message "+n[6]),S(a,"class","modal-content nomax"),S(e,"class","modal is-active")},m(J,pe){Q(J,e,pe),C(e,t),C(e,r),C(e,a),C(a,i),C(i,o),C(o,s),C(s,l),C(o,c),C(o,u),C(i,_),C(i,p),$.m(p,null),C(i,f),C(i,h),C(h,v),C(v,R),C(v,O),C(v,x),C(x,M),C(M,D),C(D,P),F||(Z=[xe(t,"click",n[7]),xe(u,"click",n[7]),xe(D,"click",n[7]),xe(e,"modal-esc",n[7])],F=!0)},p(J,pe){pe&2&&Jt(l,J[1]),X===(X=Y(J))&&$?$.p(J,pe):($.d(1),$=X(J),$&&($.c(),$.m(p,null))),pe&16&&Jt(P,J[4]),pe&32&&k!==(k="button "+J[5])&&S(D,"class",k),pe&64&&U!==(U="message "+J[6])&&S(i,"class",U)},d(J){J&&K(e),$.d(),F=!1,On(Z)}}}function IT(n){let e;return{c(){e=lt(n[2])},m(t,r){Q(t,e,r)},p(t,r){r&4&&Jt(e,t[2])},d(t){t&&K(e)}}}function wT(n){let e,t;return{c(){e=new li(!1),t=gt(),e.a=t},m(r,a){e.m(n[2],r,a),Q(r,t,a)},p(r,a){a&4&&e.p(r[2])},d(r){r&&K(t),r&&e.d()}}}function DT(n){let e,t=n[0]&&cp(n);return{c(){t&&t.c(),e=gt()},m(r,a){t&&t.m(r,a),Q(r,e,a)},p(r,[a]){r[0]?t?t.p(r,a):(t=cp(r),t.c(),t.m(e.parentNode,e)):t&&(t.d(1),t=null)},i:Ve,o:Ve,d(r){t&&t.d(r),r&&K(e)}}}function MT(n,e,t){let{isOpen:r}=e,{title:a}=e,{message:i}=e,{asHtml:o=!1}=e,{onConfirm:s=null}=e,{confirmButton:l="Close"}=e,{confirmButtonClass:c="is-info"}=e,{class:u=""}=e;const _=()=>{(!s||!s())&&Di()};return n.$$set=p=>{"isOpen"in p&&t(0,r=p.isOpen),"title"in p&&t(1,a=p.title),"message"in p&&t(2,i=p.message),"asHtml"in p&&t(3,o=p.asHtml),"onConfirm"in p&&t(8,s=p.onConfirm),"confirmButton"in p&&t(4,l=p.confirmButton),"confirmButtonClass"in p&&t(5,c=p.confirmButtonClass),"class"in p&&t(6,u=p.class)},[r,a,i,o,l,c,u,_,s]}class xT extends Ot{constructor(e){super(),Nt(this,e,MT,DT,Et,{isOpen:0,title:1,message:2,asHtml:3,onConfirm:8,confirmButton:4,confirmButtonClass:5,class:6})}}function kT(n,e){if(n===e)throw new Error("Cannot compare node with itself");const t={a:_p(n),b:_p(e)};let r;for(;t.a.at(-1)===t.b.at(-1);)n=t.a.pop(),e=t.b.pop(),r=n;const a={a:dp(up(t.a)),b:dp(up(t.b))};if(a.a===a.b){const i=r.childNodes,o={a:t.a.at(-1),b:t.b.at(-1)};let s=i.length;for(;s--;){const l=i[s];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(a.a-a.b)}const LT=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function PT(n){const e=getComputedStyle(vS(n)).display;return e==="flex"||e==="inline-flex"}function UT(n){const e=getComputedStyle(n);return!!(e.position==="fixed"||e.zIndex!=="auto"&&e.position!=="static"||PT(n)||+e.opacity<1||"transform"in e&&e.transform!=="none"||"webkitTransform"in e&&e.webkitTransform!=="none"||"mixBlendMode"in e&&e.mixBlendMode!=="normal"||"filter"in e&&e.filter!=="none"||"webkitFilter"in e&&e.webkitFilter!=="none"||"isolation"in e&&e.isolation==="isolate"||LT.test(e.willChange)||e.webkitOverflowScrolling==="touch")}function up(n){let e=n.length;for(;e--;)if(UT(n[e]))return n[e];return null}function dp(n){return n&&Number(getComputedStyle(n).zIndex)||0}function _p(n){const e=[];for(;n;)e.push(n),n=vS(n);return e}function vS(n){var e;return((e=n.parentNode)==null?void 0:e.host)||n.parentNode}const yS=()=>{const n="0123456789abcdef";let e="";for(let t=0;t<8;t++)e+=n.charAt(Math.floor(Math.random()*n.length));return e};let yl=[],mp=0;const C_=n=>{const e=document.querySelectorAll("textarea.auto-size");(n||e.length!==mp)&&(yl=Array.from(e),mp=e.length);for(let t=0,r=yl.length;t{n.target!==null&&(n.target.__didAutoGrow=!1,CS(n.target))},CS=(n,e)=>{const t=n;(e||!t.__didAutoGrow)&&(n.style.height="38px"),n.style.height=n.scrollHeight+"px",setTimeout(()=>{n.scrollHeight>n.getBoundingClientRect().height+5?n.style.overflowY="auto":n.style.overflowY=""},0),t.__didAutoGrow=!0},BT=(n,e,t=!1,r=!1)=>{const a=t?"instant":"smooth";r?window.scrollTo({behavior:a,top:n.getBoundingClientRect().bottom-document.body.getBoundingClientRect().top-(window.innerHeight-e)}):window.scrollTo({behavior:a,top:n.getBoundingClientRect().top-document.body.getBoundingClientRect().top-e})},Es=(n,e=60,t=!1,r=!1)=>{if(Array.isArray(n)&&(n=n[0]),!n){console.error("Not a valid uuid",n);return}const a=document.getElementById("message-"+n);a?BT(a,e,t,r):console.error("Can't find element with message ID",n)},cs=(n=!1)=>{setTimeout(()=>{var e;return(e=document.querySelector("body"))==null?void 0:e.scrollIntoView({behavior:n?"instant":"smooth",block:"end"})},0)},FT=n=>{!n||n.key!=="Escape"||RS()},RS=()=>{const n=Array.from(document.querySelectorAll(".modal, .has-esc")).filter(t=>window.getComputedStyle(t).getPropertyValue("display")!=="none"),e=n.length===1?n[0]:n.find(t=>n.find(r=>t!==r&&kT(t,r)>0&&t));if(e){const t=new CustomEvent("modal-esc",{detail:e});e.dispatchEvent(t)}},GT=n=>n.replace(/[\u00A0-\u9999<>&]/g,e=>`&#${e.charCodeAt(0)};`),Zn=(n,e=void 0)=>{Vr(xT,{title:"Error",class:"is-danger",message:n+(e?"
"+e.message:""),asHtml:!0,onConfirm:()=>{}})},hs=(n,e)=>{(()=>{const r=Is(e);Kr(`/chat/${r}`)})()},Ja=(n,e)=>typeof e=="function"?e(n):e,qT=()=>{try{const n=localStorage.getItem("chats");if(!n)return console.log("No chat data found to migrate"),!1;const e=JSON.parse(n);if(!Array.isArray(e)||e.length===0)return console.log("No chats to migrate"),!1;let t=0;const r=new Map;if(e.forEach(i=>{if(typeof i.id=="number"){const o=yS();r.set(i.id,o),i.id=o,t++}}),t===0)return console.log("No numeric chat IDs found to migrate"),!1;const a=localStorage.getItem("lastChatId");if(a){const i=JSON.parse(a);typeof i=="number"&&r.has(i)&&localStorage.setItem("lastChatId",JSON.stringify(r.get(i)))}return localStorage.setItem("chats",JSON.stringify(e)),console.log(`Successfully migrated ${t} chats from numeric IDs to hex UUIDs`),!0}catch(n){return console.error("Error during chat data migration:",n),!1}},YT="modulepreload",zT=function(n){return"/"+n},pp={},HT=function(e,t,r){if(!t||t.length===0)return e();const a=document.getElementsByTagName("link");return Promise.all(t.map(i=>{if(i=zT(i),i in pp)return;pp[i]=!0;const o=i.endsWith(".css"),s=o?'[rel="stylesheet"]':"";if(!!r)for(let u=a.length-1;u>=0;u--){const _=a[u];if(_.href===i&&(!o||_.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${i}"]${s}`))return;const c=document.createElement("link");if(c.rel=o?"stylesheet":YT,o||(c.as="script",c.crossOrigin=""),c.href=i,document.head.appendChild(c),o)return new Promise((u,_)=>{c.addEventListener("load",u),c.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${i}`)))})})).then(()=>e()).catch(i=>{const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i})},VT={prompt:15,completion:60,max:2e5,reasoning:!0},$T={prompt:10,completion:40,max:2e5,reasoning:!0},WT={"claude-sonnet-4-5-20250929":{prompt:3,completion:15,max:2e5},"claude-sonnet-4-20250514":{prompt:3,completion:15,max:2e5},"claude-opus-4-20250514":{prompt:15,completion:75,max:2e5},"claude-3-7-sonnet-20250219":{prompt:3,completion:15,max:2e5},"gpt-5":{prompt:1.25,completion:10,max:2e5,reasoning:!0},"gpt-5-mini":{prompt:.25,completion:2,max:2e5,reasoning:!0},"gpt-5-nano":{prompt:.05,completion:.4,max:2e5,reasoning:!0},"gpt-5-chat-latest":{prompt:1.25,completion:10,max:2e5,reasoning:!0},"gpt-4.1":{prompt:2,completion:8,max:131072},"gpt-4.1-mini":{prompt:.4,completion:1.6,max:131072},"gpt-4.1-nano":{prompt:.1,completion:.03,max:131072},"gpt-4o":{prompt:2.5,completion:10,max:131072},"gpt-4o-mini":{prompt:.15,completion:.6,max:131072},o1:VT,"o1-pro":{prompt:150,completion:600,max:2e5,reasoning:!0},"o3-pro":{prompt:20,completion:80,max:2e5,reasoning:!0},o3:$T,"o4-mini":{prompt:1.1,completion:4.4,max:2e5,reasoning:!0},"o3-mini":{prompt:1.1,completion:4.4,max:2e5,reasoning:!0},"o1-mini":{prompt:1.1,completion:4.4,max:131072,reasoning:!0},"models/gemini-2.5-flash-preview-05-20":{prompt:.15,completion:.6,max:1e6,alias:"gemini-2.5-flash"},"models/gemini-2.5-pro-preview-06-05":{prompt:1.25,completion:10,max:2e5,alias:"gemini-2.5-pro"},"deepseek-r1-distill-qwen-32b":{prompt:.69,completion:.69,max:16384},"deepseek-r1-distill-llama-70b":{prompt:3,completion:3,max:4096}};var Cl={local:{},session:{}};function KT(n){return n==="local"?localStorage:sessionStorage}function Pi(n,e,t){var r,a;const i=(r=t==null?void 0:t.serializer)!=null?r:JSON,o=(a=t==null?void 0:t.storage)!=null?a:"local",s=typeof window<"u"&&typeof document<"u",l=s?KT(o):null;function c(u,_){l==null||l.setItem(u,i.stringify(_))}if(!Cl[o][n]){const u=Hn(e,f=>{const h=l==null?void 0:l.getItem(n);if(h&&f(i.parse(h)),s&&o=="local"){const v=R=>{R.key===n&&f(R.newValue?i.parse(R.newValue):null)};return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)}}),{subscribe:_,set:p}=u;Cl[o][n]={set(f){c(n,f),p(f)},update(f){return u.update(h=>{const v=f(h);return c(n,v),v})},subscribe:_}}return Cl[o][n]}const NS=Pi("apiBase","https://api.openai.com"),QT=At(NS)||"https://api.openai.com",XT={}.VITE_ENDPOINT_COMPLETIONS||"/v1/chat/completions",ZT={}.VITE_ENDPOINT_GENERATIONS||"/v1/images/generations",jT={}.VITE_ENDPOINT_MODELS||"/v1/models",fp=n=>{console.log(n),NS.set(n||"")},Fs=()=>QT,JT=()=>XT,ev=()=>ZT,tv=()=>jT;let wa,gp;const OS=n=>{wa=void 0,To.set(n.apiKey||"")},nv=async()=>{if(wa)return wa;const n=At(To);if(!n)return{};try{return wa=(await(await fetch(Fs()+tv(),{method:"GET",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"}})).json()).data.reduce((t,r)=>(t[r.id]=r,t),{}),wa}catch{return wa={},clearTimeout(gp),gp=setTimeout(()=>{wa=void 0},1e3),wa}},AS=async n=>{const e=await nv();n.type==="chat"||n.type==="instruct"?n.enabled=!!e[n.modelQuery||""]:n.enabled=!!Object.keys(e).length},Ss=(n,e)=>{const t=Qt(e);return n.prompt_tokens*(t.prompt||0)+n.completion_tokens*(t.completion||0)},Oa=(n,e,t)=>Qt(e).countPromptTokens(n,e,t),Ri=(n,e,t)=>Qt(e).countMessageTokens(n,e,t),N_=n=>Qt(n).max;class rv{constructor(e){Ht(this,"offsetTotals");Ht(this,"isFill",!1);Ht(this,"didFill",!1);Ht(this,"opts");Ht(this,"chat");Ht(this,"messages");Ht(this,"error");Ht(this,"model");Ht(this,"lastModel");Ht(this,"setModel",e=>{e&&(!this.model&&Ey(this.chat.settings.model,e),this.lastModel=this.model||e,this.model=e)});Ht(this,"finishResolver");Ht(this,"errorResolver");Ht(this,"finishPromise",new Promise((e,t)=>{this.finishResolver=e,this.errorResolver=t}));Ht(this,"promptTokenCount");Ht(this,"finished",!1);Ht(this,"messageChangeListeners",[]);Ht(this,"finishListeners",[]);Ht(this,"onMessageChange",e=>this.messageChangeListeners.push(e));Ht(this,"onFinish",e=>this.finishListeners.push(e));Ht(this,"promiseToFinish",()=>this.finishPromise);Ht(this,"hasFinished",()=>this.finished);Ht(this,"getError",()=>this.error);Ht(this,"hasError",()=>!!this.error);Ht(this,"getMessages",()=>this.messages);Ht(this,"finish",(e="")=>{if(this.finished)return;this.messages.forEach(a=>{a.streaming=!1,e&&(a.finish_reason=e)}),so(this.chat.id),this.finished=!0;const t=this.messages[0],r=this.model||gy(this.chat.settings.model);if(t)this.isFill&&this.lastModel===this.model&&this.offsetTotals&&r&&t.usage&&ly(this.chat.id,this.offsetTotals,r),Rp(this.chat.id,t.usage,r);else if(this.model){const a={prompt_tokens:this.promptTokenCount,completion_tokens:0,total_tokens:this.promptTokenCount};Rp(this.chat.id,a,r)}this.notifyFinish(),this.error?this.errorResolver(this.error):this.finishResolver(this.messages)});this.opts=e,this.chat=e.chat,this.messages=[],e.fillMessage&&(this.messages.push(e.fillMessage),this.offsetTotals=e.fillMessage.usage&&JSON.parse(JSON.stringify(e.fillMessage.usage)),this.isFill=!0),e.onMessageChange&&this.messageChangeListeners.push(e.onMessageChange)}initialFillMerge(e,t){const r=Qt(this.model);return!this.didFill&&this.isFill&&r.preFillMerge&&(e=r.preFillMerge(e,t)),this.didFill=!0,e}setPromptTokenCount(e){this.promptTokenCount=e}getPromptTokenCount(){return this.promptTokenCount}async updateImageFromSyncResponse(e,t,r){this.setModel(r);for(let a=0;a{var l,c,u,_,p;const o=this.messages[i],s=o||a.message;o?(s.content=this.initialFillMerge(s.content,a.message.content),s.content+=a.message.content,s.usage=s.usage||{prompt_tokens:0,completion_tokens:0,total_tokens:0},s.usage.completion_tokens+=((l=e==null?void 0:e.usage)==null?void 0:l.completion_tokens)||0,s.usage.prompt_tokens=(((c=e==null?void 0:e.usage)==null?void 0:c.prompt_tokens)||0)+(((u=this.offsetTotals)==null?void 0:u.prompt_tokens)||0),s.usage.total_tokens=(((_=e==null?void 0:e.usage)==null?void 0:_.total_tokens)||0)+(((p=this.offsetTotals)==null?void 0:p.total_tokens)||0)):(s.content=a.message.content,s.usage=e.usage),s.finish_reason=a.finish_reason,s.role=a.message.role,s.model=e.model,this.messages[i]=s,this.opts.autoAddMessages&&ca(this.chat.id,s)}),this.notifyMessageChange(),this.finish()}updateFromAsyncResponse(e){var o,s,l;let t=0;if(this.setModel(e.model),!e.choices||e!=null&&e.error)return this.updateFromError(((o=e==null?void 0:e.error)==null?void 0:o.message)||"unexpected streaming response from API");(s=e.choices)==null||s.forEach((c,u)=>{var p,f,h;const _=this.messages[u]||{role:"assistant",content:"",uuid:jn()};(p=c.delta)!=null&&p.role&&(_.role=c.delta.role),(f=c.delta)!=null&&f.content&&(_.content=this.initialFillMerge(_.content,(h=c.delta)==null?void 0:h.content),_.content+=c.delta.content),t+=DS(this.model,_.content),_.model=e.model,_.finish_reason=c.finish_reason,_.streaming=!c.finish_reason&&!this.finished,this.messages[u]=_});const r=this.promptTokenCount+(((l=this.offsetTotals)==null?void 0:l.prompt_tokens)||0),a=r+t;this.messages.forEach(c=>{c.usage={completion_tokens:t,total_tokens:a,prompt_tokens:r},this.opts.autoAddMessages&&ca(this.chat.id,c)});const i=!this.messages.find(c=>c.streaming);this.notifyMessageChange(),i&&this.finish()}updateFromError(e){this.finished||this.error||(this.error=e,this.opts.autoAddMessages&&ca(this.chat.id,{role:"error",content:`Error: ${e}`,uuid:jn()}),this.notifyMessageChange(),setTimeout(()=>this.finish("abort"),200))}updateFromClose(e=!1){var t;if(!this.finished&&!this.error&&!((t=this.messages)!=null&&t.find(r=>r.content))){if(!e)return setTimeout(()=>this.updateFromClose(!0),300);if(!this.finished)return this.updateFromError("Unexpected connection termination")}setTimeout(()=>this.finish(),260)}notifyMessageChange(){this.messageChangeListeners.forEach(e=>{e(this.messages)})}notifyFinish(){this.finishListeners.forEach(e=>{e(this.messages)})}}class Ep{constructor(){Ht(this,"chat");Ht(this,"updating",!1);Ht(this,"updatingMessage","");Ht(this,"controller");Ht(this,"providerData",{});this.controller=new AbortController,this.updating=!1,this.updatingMessage=""}setChat(e){this.chat=e,this.chat.settings.model=this.getModel()}getChat(){return this.chat}getChatSettings(){return this.chat.settings}async handleError(e){var r,a,i,o;let t;try{const s=await e.json();t=((r=s==null?void 0:s.error)==null?void 0:r.message)||((a=s==null?void 0:s.error)==null?void 0:a.code),!t&&e.choices&&e.choices[0]&&(t=(o=(i=e.choices[0])==null?void 0:i.message)==null?void 0:o.content),t=t||"Unexpected Response"}catch(s){console.error(s,s.stack),t="Unknown Response"}throw new Error(`${e.status} - ${t}`)}async sendRequest(e,t,r={}){var P,k,U,F,Z;const a=this,i=Dr(a.chat.id);this.setChat(i);const o=a.chat.settings,s=i.id,l=/^\s*(please|can\s+you|will\s+you)*\s*(give|generate|create|show|build|design)\s+(me)*\s*(an|a|set|a\s+set\s+of)*\s*([0-9]+|one|two|three|four)*\s+(image|photo|picture|pic)s*\s*(for\s+me)*\s*(of|[^a-z0-9]+|about|that\s+has|showing|with|having|depicting)\s+[^a-z0-9]*(.*)$/i;t.chat=i,a.updating=!0;const c=e[e.length-1],u=new rv(t);if(a.controller=new AbortController,o.imageGenerationModel&&!t.didSummary&&!t.summaryRequest&&(c==null?void 0:c.role)==="user"){const Y=c.content.match(l);if(Y){let X=parseInt((Y[5]||"").toLowerCase().trim().replace(/one/ig,"1").replace(/two/ig,"2").replace(/three/ig,"3").replace(/four/ig,"4"));return isNaN(X)&&(X=1),X=Math.min(Math.max(1,X),4),c.suppress=!0,await Qt(o.imageGenerationModel).request({},a,u,{...t,prompt:Y[9],count:X})}}const _=this.getModel(),p=Qt(_),f=N_(_),h=["user","assistant"].concat(o.useSystemPrompt?["system"]:[]),v=Y=>!Y.suppress&&h.includes(Y.role)&&Y.content&&!Y.summarized,R=e.filter(v);if(!t.didSummary&&!t.summaryRequest&&o.continuousChat)return await this.doContinuousChat(R,t,r);this.buildHiddenPromptPrefixMessages(R,!0);const O=R.filter(Y=>Y.skipOnce?(delete Y.skipOnce,!1):!0).map(Y=>{const X=Y.content+(Y.appendOnce||[]).join(` `);return delete Y.appendOnce,{role:Y.role,content:ny(o,X)}});if(((P=O[0])==null?void 0:P.role)==="system"){const Y=o.sendSystemPromptLast,X=O[0];if(X){const $=X.content.split("::END-PROMPT::");X.content=$[0].trim(),O.length>1?(X.content=X.content.replace(/::STARTUP::[\s\S]*::EOM::/,"::EOM::"),X.content=X.content.replace(/::STARTUP::[\s\S]*::START-PROMPT::/,"::START-PROMPT::"),X.content=X.content.replace(/::STARTUP::[\s\S]*$/,"")):X.content=X.content.replace(/::STARTUP::[\s]*/,"");const J=X.content.split("::START-PROMPT::");if(Y){if(O.shift(),((k=O[O.length-1])==null?void 0:k.role)==="user"?O.splice(-1,0,X):O.push(X),J.length>1){X.content=((U=J.shift())==null?void 0:U.trim())||"";const de=J.join(` `).trim();O.unshift({content:de,role:"system"})}}else X.content=X.content.replace(/::START-PROMPT::[\s]*/,"");const pe=(J.shift()||"").split("::EOM::");if(pe.length>1){X.content=((F=pe.shift())==null?void 0:F.trim())||"";const de=pe.map((z,oe)=>({role:oe%2===0?"user":"assistant",content:z.trim()})).filter(z=>z.content.length);O.splice(Y?0:1,0,...de.concat(J.map(z=>({role:"system",content:z.trim()})).filter(z=>z.content.length)))}const ue=((Z=$[1])==null?void 0:Z.trim())||"";ue.length&&O.push({role:"system",content:ue})}}const x=Oa(O,_,i),M=f-(x+1),D={model:o.model,messages:O,...$v().reduce((Y,X)=>{let $=X.key,J=_y(s,X);return $ in r&&(J=r[$]),typeof X.apiTransform=="function"&&(J=X.apiTransform(s,X,J)),console.log($,J),$==="max_tokens"&&(t.maxTokens&&(J=t.maxTokens),(J>M||J<1)&&(J=null),J&&(J=Math.floor(J)),$="max_completion_tokens"),$==="n"&&(t.streaming||t.summaryRequest)&&(J=1),$==="reasoning_effort"&&p.extparams!=!0||$==="verbosity"&&p.extparams!=!0||J!==null&&(Y[$]=J),Y},{}),stream:p.stream?!1:t.streaming};try{u.setPromptTokenCount(x),await p.request(D,a,u,t)}catch(Y){console.error(Y,Y.stack),a.updating=!1,a.updatingMessage="",u.updateFromError(Y.message)}return u}getModel(){return this.chat.settings.model||FS()}buildHiddenPromptPrefixMessages(e,t=!1){const a=this.chat.settings,i=Hs(a,a.hiddenPromptPrefix).trim(),o=e[e.length-1],s=(o==null?void 0:o.role)==="assistant"&&o.finish_reason==="length",l=(o==null?void 0:o.role)==="user";let c=[],u=!1;if(i&&(l||s)){if(c=i.split(/[\s\r\n]*::EOM::[\s\r\n]*/).reduce((f,h)=>(h=h.trim(),h.length&&(h.match(/\[\[USER_PROMPT\]\]/)&&(u=!0,h=h.replace(/\[\[USER_PROMPT\]\]/g,o.content)),f.push({role:f.length%2===0?"user":"assistant",content:h})),f),[]),t){c.forEach(h=>{e.splice(e.length-(s?2:1),0,h)});const f=e[e.length-2];a.hppContinuePrompt&&s&&f&&f.role==="user"&&(f.appendOnce=f.appendOnce||[],f.appendOnce.push(` `+a.hppContinuePrompt+` diff --git a/index.html b/index.html index 91aca3e..49098de 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ ChatGPT-web - +