libre-webui 0.6.1 → 0.6.3
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/electron/main.js +31 -1
- package/frontend/dist/assets/index-DUg4kgBT.js +51 -0
- package/frontend/dist/css/{index-Dh5G0uFZ.css → index-wpq7d2po.css} +1 -1
- package/frontend/dist/index.html +6 -6
- package/frontend/dist/js/{ArtifactContainer-DgTQ_olm.js → ArtifactContainer-3CkpcYwD.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-4yH7f5fF.js → ArtifactDemoPage-oSYi__50.js} +1 -1
- package/frontend/dist/js/{ChatPage-B8EA-6cd.js → ChatPage-Cz0C9idF.js} +3 -3
- package/frontend/dist/js/{GalleryPage-DTG6jrPZ.js → GalleryPage-cCtfDEU2.js} +1 -1
- package/frontend/dist/js/{ModelsPage-CoTztrhR.js → ModelsPage-CPrYNnp9.js} +1 -1
- package/frontend/dist/js/PersonasPage-5vnLrOBA.js +13 -0
- package/frontend/dist/js/{UserManagementPage-DQt2VA0t.js → UserManagementPage-BSrxERfr.js} +1 -1
- package/frontend/dist/js/{markdown-vendor-DeGQOJEA.js → markdown-vendor-QwEm2Xso.js} +1 -1
- package/frontend/dist/js/{router-vendor-CYqbjR9t.js → router-vendor-CmbUVdlE.js} +5 -5
- package/frontend/dist/js/ui-vendor-mY5_zojY.js +177 -0
- package/frontend/dist/js/utils-vendor-DBPpO82s.js +6 -0
- package/package.json +6 -3
- package/frontend/dist/assets/index-DbWB0QlN.js +0 -51
- package/frontend/dist/js/PersonasPage-CVQMhfJr.js +0 -13
- package/frontend/dist/js/ui-vendor-DnQP3_cJ.js +0 -177
- package/frontend/dist/js/utils-vendor-COrKO_vV.js +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as O0,f as Z0,m as M0,s as on,a as un,c as cn,v as dn,S as hn,j as u,M as mn}from"./markdown-vendor-
|
|
1
|
+
import{o as O0,f as Z0,m as M0,s as on,a as un,c as cn,v as dn,S as hn,j as u,M as mn}from"./markdown-vendor-QwEm2Xso.js";import{R as Jt,r as A,e as hr,c as Ra,d as pn,u as fn}from"./router-vendor-CmbUVdlE.js";import{u as C0,O as gn,c as Y,a as b0,t as dt,b as Pa,d as ze,p as Lr,f as vn,e as Qt,S as xn,T as bn,B as r0,o as Ct,h as Hr,i as Oa,g as $r,j as ht,w as Me,k as Gr}from"../assets/index-DUg4kgBT.js";import{C as yt,H as La,b as yn,e as D0,p as wn,L as Ha,i as $a,$ as kn,V as Sn,n as _t,a0 as er,t as Ga,a1 as Mn,X as f0,s as Nn,d as Ur,a2 as mt,a3 as Tn,a4 as zn,F as An,U as Ua,J as Va,a5 as jn,z as ue,a6 as Cn,N as Dn,B as Dt,Z as A0,a7 as Bn,a8 as Fn,a9 as Bt,r as Wa,aa as In,q as mr,I as Xa,ab as Ft,f as J0,E as It,ac as En,ad as Ya,ae as Ka,af as Za,x as Q0,ag as qn,M as Rn,ah as Vr}from"./ui-vendor-mY5_zojY.js";import{A as Pn}from"./ArtifactContainer-3CkpcYwD.js";import"./utils-vendor-DBPpO82s.js";function On(r,e){const t=String(r);let a=t.indexOf(e),s=a,n=0,l=0;for(;a!==-1;)a===s?++n>l&&(l=n):n=1,s=a+e.length,a=t.indexOf(e,s);return l}function Ln(){return{enter:{mathFlow:r,mathFlowFenceMeta:e,mathText:n},exit:{mathFlow:s,mathFlowFence:a,mathFlowFenceMeta:t,mathFlowValue:c,mathText:l,mathTextData:c}};function r(d){const p={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[p]}},d)}function e(){this.buffer()}function t(){const d=this.resume(),p=this.stack[this.stack.length-1];O0(p.type==="math"),p.meta=d}function a(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function s(d){const p=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),f=this.stack[this.stack.length-1];O0(f.type==="math"),this.exit(d),f.value=p;const x=f.data.hChildren[0];O0(x.type==="element"),O0(x.tagName==="code"),x.children.push({type:"text",value:p}),this.data.mathFlowInside=void 0}function n(d){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},d),this.buffer()}function l(d){const p=this.resume(),f=this.stack[this.stack.length-1];O0(f.type==="inlineMath"),this.exit(d),f.value=p,f.data.hChildren.push({type:"text",value:p})}function c(d){this.config.enter.data.call(this,d),this.config.exit.data.call(this,d)}}function Hn(r){let e=(r||{}).singleDollarTextMath;return e==null&&(e=!0),a.peek=s,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
|
|
2
2
|
`,inConstruct:"mathFlowMeta"},{character:"$",after:e?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:t,inlineMath:a}};function t(n,l,c,d){const p=n.value||"",f=c.createTracker(d),x="$".repeat(Math.max(On(p,"$")+1,2)),y=c.enter("mathFlow");let b=f.move(x);if(n.meta){const S=c.enter("mathFlowMeta");b+=f.move(c.safe(n.meta,{after:`
|
|
3
3
|
`,before:b,encode:["$"],...f.current()})),S()}return b+=f.move(`
|
|
4
4
|
`),p&&(b+=f.move(p+`
|
|
@@ -262,7 +262,7 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
262
262
|
|[ \r ]+
|
|
263
263
|
?)[ \r ]*`,ur="[̀-ͯ]",Pl=new RegExp(ur+"+$"),Ol="("+Ls+"+)|"+(Rl+"|")+"([!-\\[\\]-‧-豈-]"+(ur+"*")+"|[\uD800-\uDBFF][\uDC00-\uDFFF]"+(ur+"*")+"|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5"+("|"+ql)+("|"+El+")");class ka{constructor(e,t){this.input=void 0,this.settings=void 0,this.tokenRegex=void 0,this.catcodes=void 0,this.input=e,this.settings=t,this.tokenRegex=new RegExp(Ol,"g"),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){var e=this.input,t=this.tokenRegex.lastIndex;if(t===e.length)return new Oe("EOF",new Ee(this,t,t));var a=this.tokenRegex.exec(e);if(a===null||a.index!==t)throw new E("Unexpected character: '"+e[t]+"'",new Oe(e[t],new Ee(this,t,t+1)));var s=a[6]||a[3]||(a[2]?"\\ ":" ");if(this.catcodes[s]===14){var n=e.indexOf(`
|
|
264
264
|
`,this.tokenRegex.lastIndex);return n===-1?(this.tokenRegex.lastIndex=e.length,this.settings.reportNonstrict("commentAtEnd","% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode (e.g. $)")):this.tokenRegex.lastIndex=n+1,this.lex()}return new Oe(s,new Ee(this,t,this.tokenRegex.lastIndex))}}class Ll{constructor(e,t){e===void 0&&(e={}),t===void 0&&(t={}),this.current=void 0,this.builtins=void 0,this.undefStack=void 0,this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new E("Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug");var e=this.undefStack.pop();for(var t in e)e.hasOwnProperty(t)&&(e[t]==null?delete this.current[t]:this.current[t]=e[t])}endGroups(){for(;this.undefStack.length>0;)this.endGroup()}has(e){return this.current.hasOwnProperty(e)||this.builtins.hasOwnProperty(e)}get(e){return this.current.hasOwnProperty(e)?this.current[e]:this.builtins[e]}set(e,t,a){if(a===void 0&&(a=!1),a){for(var s=0;s<this.undefStack.length;s++)delete this.undefStack[s][e];this.undefStack.length>0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{var n=this.undefStack[this.undefStack.length-1];n&&!n.hasOwnProperty(e)&&(n[e]=this.current[e])}t==null?delete this.current[e]:this.current[e]=t}}var Hl=js;m("\\noexpand",function(r){var e=r.popToken();return r.isExpandable(e.text)&&(e.noexpand=!0,e.treatAsRelax=!0),{tokens:[e],numArgs:0}});m("\\expandafter",function(r){var e=r.popToken();return r.expandOnce(!0),{tokens:[e],numArgs:0}});m("\\@firstoftwo",function(r){var e=r.consumeArgs(2);return{tokens:e[0],numArgs:0}});m("\\@secondoftwo",function(r){var e=r.consumeArgs(2);return{tokens:e[1],numArgs:0}});m("\\@ifnextchar",function(r){var e=r.consumeArgs(3);r.consumeSpaces();var t=r.future();return e[0].length===1&&e[0][0].text===t.text?{tokens:e[1],numArgs:0}:{tokens:e[2],numArgs:0}});m("\\@ifstar","\\@ifnextchar *{\\@firstoftwo{#1}}");m("\\TextOrMath",function(r){var e=r.consumeArgs(2);return r.mode==="text"?{tokens:e[0],numArgs:0}:{tokens:e[1],numArgs:0}});var Sa={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};m("\\char",function(r){var e=r.popToken(),t,a="";if(e.text==="'")t=8,e=r.popToken();else if(e.text==='"')t=16,e=r.popToken();else if(e.text==="`")if(e=r.popToken(),e.text[0]==="\\")a=e.text.charCodeAt(1);else{if(e.text==="EOF")throw new E("\\char` missing argument");a=e.text.charCodeAt(0)}else t=10;if(t){if(a=Sa[e.text],a==null||a>=t)throw new E("Invalid base-"+t+" digit "+e.text);for(var s;(s=Sa[r.future().text])!=null&&s<t;)a*=t,a+=s,r.popToken()}return"\\@char{"+a+"}"});var Cr=(r,e,t,a)=>{var s=r.consumeArg().tokens;if(s.length!==1)throw new E("\\newcommand's first argument must be a macro name");var n=s[0].text,l=r.isDefined(n);if(l&&!e)throw new E("\\newcommand{"+n+"} attempting to redefine "+(n+"; use \\renewcommand"));if(!l&&!t)throw new E("\\renewcommand{"+n+"} when command "+n+" does not yet exist; use \\newcommand");var c=0;if(s=r.consumeArg().tokens,s.length===1&&s[0].text==="["){for(var d="",p=r.expandNextToken();p.text!=="]"&&p.text!=="EOF";)d+=p.text,p=r.expandNextToken();if(!d.match(/^\s*[0-9]+\s*$/))throw new E("Invalid number of arguments: "+d);c=parseInt(d),s=r.consumeArg().tokens}return l&&a||r.macros.set(n,{tokens:s,numArgs:c}),""};m("\\newcommand",r=>Cr(r,!1,!0,!1));m("\\renewcommand",r=>Cr(r,!0,!1,!1));m("\\providecommand",r=>Cr(r,!0,!0,!0));m("\\message",r=>{var e=r.consumeArgs(1)[0];return console.log(e.reverse().map(t=>t.text).join("")),""});m("\\errmessage",r=>{var e=r.consumeArgs(1)[0];return console.error(e.reverse().map(t=>t.text).join("")),""});m("\\show",r=>{var e=r.popToken(),t=e.text;return console.log(e,r.macros.get(t),p0[t],de.math[t],de.text[t]),""});m("\\bgroup","{");m("\\egroup","}");m("~","\\nobreakspace");m("\\lq","`");m("\\rq","'");m("\\aa","\\r a");m("\\AA","\\r A");m("\\textcopyright","\\html@mathml{\\textcircled{c}}{\\char`©}");m("\\copyright","\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");m("\\textregistered","\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}");m("ℬ","\\mathscr{B}");m("ℰ","\\mathscr{E}");m("ℱ","\\mathscr{F}");m("ℋ","\\mathscr{H}");m("ℐ","\\mathscr{I}");m("ℒ","\\mathscr{L}");m("ℳ","\\mathscr{M}");m("ℛ","\\mathscr{R}");m("ℭ","\\mathfrak{C}");m("ℌ","\\mathfrak{H}");m("ℨ","\\mathfrak{Z}");m("\\Bbbk","\\Bbb{k}");m("·","\\cdotp");m("\\llap","\\mathllap{\\textrm{#1}}");m("\\rlap","\\mathrlap{\\textrm{#1}}");m("\\clap","\\mathclap{\\textrm{#1}}");m("\\mathstrut","\\vphantom{(}");m("\\underbar","\\underline{\\text{#1}}");m("\\not",'\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}');m("\\neq","\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");m("\\ne","\\neq");m("≠","\\neq");m("\\notin","\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}");m("∉","\\notin");m("≘","\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}");m("≙","\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`≘}}");m("≚","\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`≚}}");m("≛","\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}");m("≝","\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}");m("≞","\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}");m("≟","\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`≟}}");m("⟂","\\perp");m("‼","\\mathclose{!\\mkern-0.8mu!}");m("∌","\\notni");m("⌜","\\ulcorner");m("⌝","\\urcorner");m("⌞","\\llcorner");m("⌟","\\lrcorner");m("©","\\copyright");m("®","\\textregistered");m("️","\\textregistered");m("\\ulcorner",'\\html@mathml{\\@ulcorner}{\\mathop{\\char"231c}}');m("\\urcorner",'\\html@mathml{\\@urcorner}{\\mathop{\\char"231d}}');m("\\llcorner",'\\html@mathml{\\@llcorner}{\\mathop{\\char"231e}}');m("\\lrcorner",'\\html@mathml{\\@lrcorner}{\\mathop{\\char"231f}}');m("\\vdots","{\\varvdots\\rule{0pt}{15pt}}");m("⋮","\\vdots");m("\\varGamma","\\mathit{\\Gamma}");m("\\varDelta","\\mathit{\\Delta}");m("\\varTheta","\\mathit{\\Theta}");m("\\varLambda","\\mathit{\\Lambda}");m("\\varXi","\\mathit{\\Xi}");m("\\varPi","\\mathit{\\Pi}");m("\\varSigma","\\mathit{\\Sigma}");m("\\varUpsilon","\\mathit{\\Upsilon}");m("\\varPhi","\\mathit{\\Phi}");m("\\varPsi","\\mathit{\\Psi}");m("\\varOmega","\\mathit{\\Omega}");m("\\substack","\\begin{subarray}{c}#1\\end{subarray}");m("\\colon","\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax");m("\\boxed","\\fbox{$\\displaystyle{#1}$}");m("\\iff","\\DOTSB\\;\\Longleftrightarrow\\;");m("\\implies","\\DOTSB\\;\\Longrightarrow\\;");m("\\impliedby","\\DOTSB\\;\\Longleftarrow\\;");m("\\dddot","{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}");m("\\ddddot","{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}");var Ma={",":"\\dotsc","\\not":"\\dotsb","+":"\\dotsb","=":"\\dotsb","<":"\\dotsb",">":"\\dotsb","-":"\\dotsb","*":"\\dotsb",":":"\\dotsb","\\DOTSB":"\\dotsb","\\coprod":"\\dotsb","\\bigvee":"\\dotsb","\\bigwedge":"\\dotsb","\\biguplus":"\\dotsb","\\bigcap":"\\dotsb","\\bigcup":"\\dotsb","\\prod":"\\dotsb","\\sum":"\\dotsb","\\bigotimes":"\\dotsb","\\bigoplus":"\\dotsb","\\bigodot":"\\dotsb","\\bigsqcup":"\\dotsb","\\And":"\\dotsb","\\longrightarrow":"\\dotsb","\\Longrightarrow":"\\dotsb","\\longleftarrow":"\\dotsb","\\Longleftarrow":"\\dotsb","\\longleftrightarrow":"\\dotsb","\\Longleftrightarrow":"\\dotsb","\\mapsto":"\\dotsb","\\longmapsto":"\\dotsb","\\hookrightarrow":"\\dotsb","\\doteq":"\\dotsb","\\mathbin":"\\dotsb","\\mathrel":"\\dotsb","\\relbar":"\\dotsb","\\Relbar":"\\dotsb","\\xrightarrow":"\\dotsb","\\xleftarrow":"\\dotsb","\\DOTSI":"\\dotsi","\\int":"\\dotsi","\\oint":"\\dotsi","\\iint":"\\dotsi","\\iiint":"\\dotsi","\\iiiint":"\\dotsi","\\idotsint":"\\dotsi","\\DOTSX":"\\dotsx"};m("\\dots",function(r){var e="\\dotso",t=r.expandAfterFuture().text;return t in Ma?e=Ma[t]:(t.slice(0,4)==="\\not"||t in de.math&&["bin","rel"].includes(de.math[t].group))&&(e="\\dotsb"),e});var Dr={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};m("\\dotso",function(r){var e=r.future().text;return e in Dr?"\\ldots\\,":"\\ldots"});m("\\dotsc",function(r){var e=r.future().text;return e in Dr&&e!==","?"\\ldots\\,":"\\ldots"});m("\\cdots",function(r){var e=r.future().text;return e in Dr?"\\@cdots\\,":"\\@cdots"});m("\\dotsb","\\cdots");m("\\dotsm","\\cdots");m("\\dotsi","\\!\\cdots");m("\\dotsx","\\ldots\\,");m("\\DOTSI","\\relax");m("\\DOTSB","\\relax");m("\\DOTSX","\\relax");m("\\tmspace","\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");m("\\,","\\tmspace+{3mu}{.1667em}");m("\\thinspace","\\,");m("\\>","\\mskip{4mu}");m("\\:","\\tmspace+{4mu}{.2222em}");m("\\medspace","\\:");m("\\;","\\tmspace+{5mu}{.2777em}");m("\\thickspace","\\;");m("\\!","\\tmspace-{3mu}{.1667em}");m("\\negthinspace","\\!");m("\\negmedspace","\\tmspace-{4mu}{.2222em}");m("\\negthickspace","\\tmspace-{5mu}{.277em}");m("\\enspace","\\kern.5em ");m("\\enskip","\\hskip.5em\\relax");m("\\quad","\\hskip1em\\relax");m("\\qquad","\\hskip2em\\relax");m("\\tag","\\@ifstar\\tag@literal\\tag@paren");m("\\tag@paren","\\tag@literal{({#1})}");m("\\tag@literal",r=>{if(r.macros.get("\\df@tag"))throw new E("Multiple \\tag");return"\\gdef\\df@tag{\\text{#1}}"});m("\\bmod","\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");m("\\pod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");m("\\pmod","\\pod{{\\rm mod}\\mkern6mu#1}");m("\\mod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1");m("\\newline","\\\\\\relax");m("\\TeX","\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}");var Hs=P(Ke["Main-Regular"][84][1]-.7*Ke["Main-Regular"][65][1]);m("\\LaTeX","\\textrm{\\html@mathml{"+("L\\kern-.36em\\raisebox{"+Hs+"}{\\scriptstyle A}")+"\\kern-.15em\\TeX}{LaTeX}}");m("\\KaTeX","\\textrm{\\html@mathml{"+("K\\kern-.17em\\raisebox{"+Hs+"}{\\scriptstyle A}")+"\\kern-.15em\\TeX}{KaTeX}}");m("\\hspace","\\@ifstar\\@hspacer\\@hspace");m("\\@hspace","\\hskip #1\\relax");m("\\@hspacer","\\rule{0pt}{0pt}\\hskip #1\\relax");m("\\ordinarycolon",":");m("\\vcentcolon","\\mathrel{\\mathop\\ordinarycolon}");m("\\dblcolon",'\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}');m("\\coloneqq",'\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}');m("\\Coloneqq",'\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}');m("\\coloneq",'\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}');m("\\Coloneq",'\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}');m("\\eqqcolon",'\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}');m("\\Eqqcolon",'\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}');m("\\eqcolon",'\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}');m("\\Eqcolon",'\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}');m("\\colonapprox",'\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}');m("\\Colonapprox",'\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}');m("\\colonsim",'\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}');m("\\Colonsim",'\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}');m("∷","\\dblcolon");m("∹","\\eqcolon");m("≔","\\coloneqq");m("≕","\\eqqcolon");m("⩴","\\Coloneqq");m("\\ratio","\\vcentcolon");m("\\coloncolon","\\dblcolon");m("\\colonequals","\\coloneqq");m("\\coloncolonequals","\\Coloneqq");m("\\equalscolon","\\eqqcolon");m("\\equalscoloncolon","\\Eqqcolon");m("\\colonminus","\\coloneq");m("\\coloncolonminus","\\Coloneq");m("\\minuscolon","\\eqcolon");m("\\minuscoloncolon","\\Eqcolon");m("\\coloncolonapprox","\\Colonapprox");m("\\coloncolonsim","\\Colonsim");m("\\simcolon","\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");m("\\simcoloncolon","\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");m("\\approxcolon","\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");m("\\approxcoloncolon","\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}");m("\\notni","\\html@mathml{\\not\\ni}{\\mathrel{\\char`∌}}");m("\\limsup","\\DOTSB\\operatorname*{lim\\,sup}");m("\\liminf","\\DOTSB\\operatorname*{lim\\,inf}");m("\\injlim","\\DOTSB\\operatorname*{inj\\,lim}");m("\\projlim","\\DOTSB\\operatorname*{proj\\,lim}");m("\\varlimsup","\\DOTSB\\operatorname*{\\overline{lim}}");m("\\varliminf","\\DOTSB\\operatorname*{\\underline{lim}}");m("\\varinjlim","\\DOTSB\\operatorname*{\\underrightarrow{lim}}");m("\\varprojlim","\\DOTSB\\operatorname*{\\underleftarrow{lim}}");m("\\gvertneqq","\\html@mathml{\\@gvertneqq}{≩}");m("\\lvertneqq","\\html@mathml{\\@lvertneqq}{≨}");m("\\ngeqq","\\html@mathml{\\@ngeqq}{≱}");m("\\ngeqslant","\\html@mathml{\\@ngeqslant}{≱}");m("\\nleqq","\\html@mathml{\\@nleqq}{≰}");m("\\nleqslant","\\html@mathml{\\@nleqslant}{≰}");m("\\nshortmid","\\html@mathml{\\@nshortmid}{∤}");m("\\nshortparallel","\\html@mathml{\\@nshortparallel}{∦}");m("\\nsubseteqq","\\html@mathml{\\@nsubseteqq}{⊈}");m("\\nsupseteqq","\\html@mathml{\\@nsupseteqq}{⊉}");m("\\varsubsetneq","\\html@mathml{\\@varsubsetneq}{⊊}");m("\\varsubsetneqq","\\html@mathml{\\@varsubsetneqq}{⫋}");m("\\varsupsetneq","\\html@mathml{\\@varsupsetneq}{⊋}");m("\\varsupsetneqq","\\html@mathml{\\@varsupsetneqq}{⫌}");m("\\imath","\\html@mathml{\\@imath}{ı}");m("\\jmath","\\html@mathml{\\@jmath}{ȷ}");m("\\llbracket","\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}");m("\\rrbracket","\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}");m("⟦","\\llbracket");m("⟧","\\rrbracket");m("\\lBrace","\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}");m("\\rBrace","\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}");m("⦃","\\lBrace");m("⦄","\\rBrace");m("\\minuso","\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}");m("⦵","\\minuso");m("\\darr","\\downarrow");m("\\dArr","\\Downarrow");m("\\Darr","\\Downarrow");m("\\lang","\\langle");m("\\rang","\\rangle");m("\\uarr","\\uparrow");m("\\uArr","\\Uparrow");m("\\Uarr","\\Uparrow");m("\\N","\\mathbb{N}");m("\\R","\\mathbb{R}");m("\\Z","\\mathbb{Z}");m("\\alef","\\aleph");m("\\alefsym","\\aleph");m("\\Alpha","\\mathrm{A}");m("\\Beta","\\mathrm{B}");m("\\bull","\\bullet");m("\\Chi","\\mathrm{X}");m("\\clubs","\\clubsuit");m("\\cnums","\\mathbb{C}");m("\\Complex","\\mathbb{C}");m("\\Dagger","\\ddagger");m("\\diamonds","\\diamondsuit");m("\\empty","\\emptyset");m("\\Epsilon","\\mathrm{E}");m("\\Eta","\\mathrm{H}");m("\\exist","\\exists");m("\\harr","\\leftrightarrow");m("\\hArr","\\Leftrightarrow");m("\\Harr","\\Leftrightarrow");m("\\hearts","\\heartsuit");m("\\image","\\Im");m("\\infin","\\infty");m("\\Iota","\\mathrm{I}");m("\\isin","\\in");m("\\Kappa","\\mathrm{K}");m("\\larr","\\leftarrow");m("\\lArr","\\Leftarrow");m("\\Larr","\\Leftarrow");m("\\lrarr","\\leftrightarrow");m("\\lrArr","\\Leftrightarrow");m("\\Lrarr","\\Leftrightarrow");m("\\Mu","\\mathrm{M}");m("\\natnums","\\mathbb{N}");m("\\Nu","\\mathrm{N}");m("\\Omicron","\\mathrm{O}");m("\\plusmn","\\pm");m("\\rarr","\\rightarrow");m("\\rArr","\\Rightarrow");m("\\Rarr","\\Rightarrow");m("\\real","\\Re");m("\\reals","\\mathbb{R}");m("\\Reals","\\mathbb{R}");m("\\Rho","\\mathrm{P}");m("\\sdot","\\cdot");m("\\sect","\\S");m("\\spades","\\spadesuit");m("\\sub","\\subset");m("\\sube","\\subseteq");m("\\supe","\\supseteq");m("\\Tau","\\mathrm{T}");m("\\thetasym","\\vartheta");m("\\weierp","\\wp");m("\\Zeta","\\mathrm{Z}");m("\\argmin","\\DOTSB\\operatorname*{arg\\,min}");m("\\argmax","\\DOTSB\\operatorname*{arg\\,max}");m("\\plim","\\DOTSB\\mathop{\\operatorname{plim}}\\limits");m("\\bra","\\mathinner{\\langle{#1}|}");m("\\ket","\\mathinner{|{#1}\\rangle}");m("\\braket","\\mathinner{\\langle{#1}\\rangle}");m("\\Bra","\\left\\langle#1\\right|");m("\\Ket","\\left|#1\\right\\rangle");var $s=r=>e=>{var t=e.consumeArg().tokens,a=e.consumeArg().tokens,s=e.consumeArg().tokens,n=e.consumeArg().tokens,l=e.macros.get("|"),c=e.macros.get("\\|");e.macros.beginGroup();var d=x=>y=>{r&&(y.macros.set("|",l),s.length&&y.macros.set("\\|",c));var b=x;if(!x&&s.length){var S=y.future();S.text==="|"&&(y.popToken(),b=!0)}return{tokens:b?s:a,numArgs:0}};e.macros.set("|",d(!1)),s.length&&e.macros.set("\\|",d(!0));var p=e.consumeArg().tokens,f=e.expandTokens([...n,...p,...t]);return e.macros.endGroup(),{tokens:f.reverse(),numArgs:0}};m("\\bra@ket",$s(!1));m("\\bra@set",$s(!0));m("\\Braket","\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");m("\\Set","\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");m("\\set","\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");m("\\angln","{\\angl n}");m("\\blue","\\textcolor{##6495ed}{#1}");m("\\orange","\\textcolor{##ffa500}{#1}");m("\\pink","\\textcolor{##ff00af}{#1}");m("\\red","\\textcolor{##df0030}{#1}");m("\\green","\\textcolor{##28ae7b}{#1}");m("\\gray","\\textcolor{gray}{#1}");m("\\purple","\\textcolor{##9d38bd}{#1}");m("\\blueA","\\textcolor{##ccfaff}{#1}");m("\\blueB","\\textcolor{##80f6ff}{#1}");m("\\blueC","\\textcolor{##63d9ea}{#1}");m("\\blueD","\\textcolor{##11accd}{#1}");m("\\blueE","\\textcolor{##0c7f99}{#1}");m("\\tealA","\\textcolor{##94fff5}{#1}");m("\\tealB","\\textcolor{##26edd5}{#1}");m("\\tealC","\\textcolor{##01d1c1}{#1}");m("\\tealD","\\textcolor{##01a995}{#1}");m("\\tealE","\\textcolor{##208170}{#1}");m("\\greenA","\\textcolor{##b6ffb0}{#1}");m("\\greenB","\\textcolor{##8af281}{#1}");m("\\greenC","\\textcolor{##74cf70}{#1}");m("\\greenD","\\textcolor{##1fab54}{#1}");m("\\greenE","\\textcolor{##0d923f}{#1}");m("\\goldA","\\textcolor{##ffd0a9}{#1}");m("\\goldB","\\textcolor{##ffbb71}{#1}");m("\\goldC","\\textcolor{##ff9c39}{#1}");m("\\goldD","\\textcolor{##e07d10}{#1}");m("\\goldE","\\textcolor{##a75a05}{#1}");m("\\redA","\\textcolor{##fca9a9}{#1}");m("\\redB","\\textcolor{##ff8482}{#1}");m("\\redC","\\textcolor{##f9685d}{#1}");m("\\redD","\\textcolor{##e84d39}{#1}");m("\\redE","\\textcolor{##bc2612}{#1}");m("\\maroonA","\\textcolor{##ffbde0}{#1}");m("\\maroonB","\\textcolor{##ff92c6}{#1}");m("\\maroonC","\\textcolor{##ed5fa6}{#1}");m("\\maroonD","\\textcolor{##ca337c}{#1}");m("\\maroonE","\\textcolor{##9e034e}{#1}");m("\\purpleA","\\textcolor{##ddd7ff}{#1}");m("\\purpleB","\\textcolor{##c6b9fc}{#1}");m("\\purpleC","\\textcolor{##aa87ff}{#1}");m("\\purpleD","\\textcolor{##7854ab}{#1}");m("\\purpleE","\\textcolor{##543b78}{#1}");m("\\mintA","\\textcolor{##f5f9e8}{#1}");m("\\mintB","\\textcolor{##edf2df}{#1}");m("\\mintC","\\textcolor{##e0e5cc}{#1}");m("\\grayA","\\textcolor{##f6f7f7}{#1}");m("\\grayB","\\textcolor{##f0f1f2}{#1}");m("\\grayC","\\textcolor{##e3e5e6}{#1}");m("\\grayD","\\textcolor{##d6d8da}{#1}");m("\\grayE","\\textcolor{##babec2}{#1}");m("\\grayF","\\textcolor{##888d93}{#1}");m("\\grayG","\\textcolor{##626569}{#1}");m("\\grayH","\\textcolor{##3b3e40}{#1}");m("\\grayI","\\textcolor{##21242c}{#1}");m("\\kaBlue","\\textcolor{##314453}{#1}");m("\\kaGreen","\\textcolor{##71B307}{#1}");var Gs={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0};class $l{constructor(e,t,a){this.settings=void 0,this.expansionCount=void 0,this.lexer=void 0,this.macros=void 0,this.stack=void 0,this.mode=void 0,this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new Ll(Hl,t.macros),this.mode=a,this.stack=[]}feed(e){this.lexer=new ka(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}endGroups(){this.macros.endGroups()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){var t,a,s;if(e){if(this.consumeSpaces(),this.future().text!=="[")return null;t=this.popToken(),{tokens:s,end:a}=this.consumeArg(["]"])}else({tokens:s,start:t,end:a}=this.consumeArg());return this.pushToken(new Oe("EOF",a.loc)),this.pushTokens(s),new Oe("",Ee.range(t,a))}consumeSpaces(){for(;;){var e=this.future();if(e.text===" ")this.stack.pop();else break}}consumeArg(e){var t=[],a=e&&e.length>0;a||this.consumeSpaces();var s=this.future(),n,l=0,c=0;do{if(n=this.popToken(),t.push(n),n.text==="{")++l;else if(n.text==="}"){if(--l,l===-1)throw new E("Extra }",n)}else if(n.text==="EOF")throw new E("Unexpected end of input in a macro argument, expected '"+(e&&a?e[c]:"}")+"'",n);if(e&&a)if((l===0||l===1&&e[c]==="{")&&n.text===e[c]){if(++c,c===e.length){t.splice(-c,c);break}}else c=0}while(l!==0||a);return s.text==="{"&&t[t.length-1].text==="}"&&(t.pop(),t.shift()),t.reverse(),{tokens:t,start:s,end:n}}consumeArgs(e,t){if(t){if(t.length!==e+1)throw new E("The length of delimiters doesn't match the number of args!");for(var a=t[0],s=0;s<a.length;s++){var n=this.popToken();if(a[s]!==n.text)throw new E("Use of the macro doesn't match its definition",n)}}for(var l=[],c=0;c<e;c++)l.push(this.consumeArg(t&&t[c+1]).tokens);return l}countExpansion(e){if(this.expansionCount+=e,this.expansionCount>this.settings.maxExpand)throw new E("Too many expansions: infinite loop or need to increase maxExpand setting")}expandOnce(e){var t=this.popToken(),a=t.text,s=t.noexpand?null:this._getExpansion(a);if(s==null||e&&s.unexpandable){if(e&&s==null&&a[0]==="\\"&&!this.isDefined(a))throw new E("Undefined control sequence: "+a);return this.pushToken(t),!1}this.countExpansion(1);var n=s.tokens,l=this.consumeArgs(s.numArgs,s.delimiters);if(s.numArgs){n=n.slice();for(var c=n.length-1;c>=0;--c){var d=n[c];if(d.text==="#"){if(c===0)throw new E("Incomplete placeholder at end of macro body",d);if(d=n[--c],d.text==="#")n.splice(c+1,1);else if(/^[1-9]$/.test(d.text))n.splice(c,2,...l[+d.text-1]);else throw new E("Not a valid argument number",d)}}}return this.pushTokens(n),n.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){var e=this.stack.pop();return e.treatAsRelax&&(e.text="\\relax"),e}throw new Error}expandMacro(e){return this.macros.has(e)?this.expandTokens([new Oe(e)]):void 0}expandTokens(e){var t=[],a=this.stack.length;for(this.pushTokens(e);this.stack.length>a;)if(this.expandOnce(!0)===!1){var s=this.stack.pop();s.treatAsRelax&&(s.noexpand=!1,s.treatAsRelax=!1),t.push(s)}return this.countExpansion(t.length),t}expandMacroAsText(e){var t=this.expandMacro(e);return t&&t.map(a=>a.text).join("")}_getExpansion(e){var t=this.macros.get(e);if(t==null)return t;if(e.length===1){var a=this.lexer.catcodes[e];if(a!=null&&a!==13)return}var s=typeof t=="function"?t(this):t;if(typeof s=="string"){var n=0;if(s.indexOf("#")!==-1)for(var l=s.replace(/##/g,"");l.indexOf("#"+(n+1))!==-1;)++n;for(var c=new ka(s,this.settings),d=[],p=c.lex();p.text!=="EOF";)d.push(p),p=c.lex();d.reverse();var f={tokens:d,numArgs:n};return f}return s}isDefined(e){return this.macros.has(e)||p0.hasOwnProperty(e)||de.math.hasOwnProperty(e)||de.text.hasOwnProperty(e)||Gs.hasOwnProperty(e)}isExpandable(e){var t=this.macros.get(e);return t!=null?typeof t=="string"||typeof t=="function"||!t.unexpandable:p0.hasOwnProperty(e)&&!p0[e].primitive}}var Na=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,lt=Object.freeze({"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","₀":"0","₁":"1","₂":"2","₃":"3","₄":"4","₅":"5","₆":"6","₇":"7","₈":"8","₉":"9","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x","ᵦ":"β","ᵧ":"γ","ᵨ":"ρ","ᵩ":"ϕ","ᵪ":"χ","⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","⁰":"0","¹":"1","²":"2","³":"3","⁴":"4","⁵":"5","⁶":"6","⁷":"7","⁸":"8","⁹":"9","ᴬ":"A","ᴮ":"B","ᴰ":"D","ᴱ":"E","ᴳ":"G","ᴴ":"H","ᴵ":"I","ᴶ":"J","ᴷ":"K","ᴸ":"L","ᴹ":"M","ᴺ":"N","ᴼ":"O","ᴾ":"P","ᴿ":"R","ᵀ":"T","ᵁ":"U","ⱽ":"V","ᵂ":"W","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g",ʰ:"h","ⁱ":"i",ʲ:"j","ᵏ":"k",ˡ:"l","ᵐ":"m",ⁿ:"n","ᵒ":"o","ᵖ":"p",ʳ:"r",ˢ:"s","ᵗ":"t","ᵘ":"u","ᵛ":"v",ʷ:"w",ˣ:"x",ʸ:"y","ᶻ":"z","ᵝ":"β","ᵞ":"γ","ᵟ":"δ","ᵠ":"ϕ","ᵡ":"χ","ᶿ":"θ"}),Kt={"́":{text:"\\'",math:"\\acute"},"̀":{text:"\\`",math:"\\grave"},"̈":{text:'\\"',math:"\\ddot"},"̃":{text:"\\~",math:"\\tilde"},"̄":{text:"\\=",math:"\\bar"},"̆":{text:"\\u",math:"\\breve"},"̌":{text:"\\v",math:"\\check"},"̂":{text:"\\^",math:"\\hat"},"̇":{text:"\\.",math:"\\dot"},"̊":{text:"\\r",math:"\\mathring"},"̋":{text:"\\H"},"̧":{text:"\\c"}},Ta={á:"á",à:"à",ä:"ä",ǟ:"ǟ",ã:"ã",ā:"ā",ă:"ă",ắ:"ắ",ằ:"ằ",ẵ:"ẵ",ǎ:"ǎ",â:"â",ấ:"ấ",ầ:"ầ",ẫ:"ẫ",ȧ:"ȧ",ǡ:"ǡ",å:"å",ǻ:"ǻ",ḃ:"ḃ",ć:"ć",ḉ:"ḉ",č:"č",ĉ:"ĉ",ċ:"ċ",ç:"ç",ď:"ď",ḋ:"ḋ",ḑ:"ḑ",é:"é",è:"è",ë:"ë",ẽ:"ẽ",ē:"ē",ḗ:"ḗ",ḕ:"ḕ",ĕ:"ĕ",ḝ:"ḝ",ě:"ě",ê:"ê",ế:"ế",ề:"ề",ễ:"ễ",ė:"ė",ȩ:"ȩ",ḟ:"ḟ",ǵ:"ǵ",ḡ:"ḡ",ğ:"ğ",ǧ:"ǧ",ĝ:"ĝ",ġ:"ġ",ģ:"ģ",ḧ:"ḧ",ȟ:"ȟ",ĥ:"ĥ",ḣ:"ḣ",ḩ:"ḩ",í:"í",ì:"ì",ï:"ï",ḯ:"ḯ",ĩ:"ĩ",ī:"ī",ĭ:"ĭ",ǐ:"ǐ",î:"î",ǰ:"ǰ",ĵ:"ĵ",ḱ:"ḱ",ǩ:"ǩ",ķ:"ķ",ĺ:"ĺ",ľ:"ľ",ļ:"ļ",ḿ:"ḿ",ṁ:"ṁ",ń:"ń",ǹ:"ǹ",ñ:"ñ",ň:"ň",ṅ:"ṅ",ņ:"ņ",ó:"ó",ò:"ò",ö:"ö",ȫ:"ȫ",õ:"õ",ṍ:"ṍ",ṏ:"ṏ",ȭ:"ȭ",ō:"ō",ṓ:"ṓ",ṑ:"ṑ",ŏ:"ŏ",ǒ:"ǒ",ô:"ô",ố:"ố",ồ:"ồ",ỗ:"ỗ",ȯ:"ȯ",ȱ:"ȱ",ő:"ő",ṕ:"ṕ",ṗ:"ṗ",ŕ:"ŕ",ř:"ř",ṙ:"ṙ",ŗ:"ŗ",ś:"ś",ṥ:"ṥ",š:"š",ṧ:"ṧ",ŝ:"ŝ",ṡ:"ṡ",ş:"ş",ẗ:"ẗ",ť:"ť",ṫ:"ṫ",ţ:"ţ",ú:"ú",ù:"ù",ü:"ü",ǘ:"ǘ",ǜ:"ǜ",ǖ:"ǖ",ǚ:"ǚ",ũ:"ũ",ṹ:"ṹ",ū:"ū",ṻ:"ṻ",ŭ:"ŭ",ǔ:"ǔ",û:"û",ů:"ů",ű:"ű",ṽ:"ṽ",ẃ:"ẃ",ẁ:"ẁ",ẅ:"ẅ",ŵ:"ŵ",ẇ:"ẇ",ẘ:"ẘ",ẍ:"ẍ",ẋ:"ẋ",ý:"ý",ỳ:"ỳ",ÿ:"ÿ",ỹ:"ỹ",ȳ:"ȳ",ŷ:"ŷ",ẏ:"ẏ",ẙ:"ẙ",ź:"ź",ž:"ž",ẑ:"ẑ",ż:"ż",Á:"Á",À:"À",Ä:"Ä",Ǟ:"Ǟ",Ã:"Ã",Ā:"Ā",Ă:"Ă",Ắ:"Ắ",Ằ:"Ằ",Ẵ:"Ẵ",Ǎ:"Ǎ",Â:"Â",Ấ:"Ấ",Ầ:"Ầ",Ẫ:"Ẫ",Ȧ:"Ȧ",Ǡ:"Ǡ",Å:"Å",Ǻ:"Ǻ",Ḃ:"Ḃ",Ć:"Ć",Ḉ:"Ḉ",Č:"Č",Ĉ:"Ĉ",Ċ:"Ċ",Ç:"Ç",Ď:"Ď",Ḋ:"Ḋ",Ḑ:"Ḑ",É:"É",È:"È",Ë:"Ë",Ẽ:"Ẽ",Ē:"Ē",Ḗ:"Ḗ",Ḕ:"Ḕ",Ĕ:"Ĕ",Ḝ:"Ḝ",Ě:"Ě",Ê:"Ê",Ế:"Ế",Ề:"Ề",Ễ:"Ễ",Ė:"Ė",Ȩ:"Ȩ",Ḟ:"Ḟ",Ǵ:"Ǵ",Ḡ:"Ḡ",Ğ:"Ğ",Ǧ:"Ǧ",Ĝ:"Ĝ",Ġ:"Ġ",Ģ:"Ģ",Ḧ:"Ḧ",Ȟ:"Ȟ",Ĥ:"Ĥ",Ḣ:"Ḣ",Ḩ:"Ḩ",Í:"Í",Ì:"Ì",Ï:"Ï",Ḯ:"Ḯ",Ĩ:"Ĩ",Ī:"Ī",Ĭ:"Ĭ",Ǐ:"Ǐ",Î:"Î",İ:"İ",Ĵ:"Ĵ",Ḱ:"Ḱ",Ǩ:"Ǩ",Ķ:"Ķ",Ĺ:"Ĺ",Ľ:"Ľ",Ļ:"Ļ",Ḿ:"Ḿ",Ṁ:"Ṁ",Ń:"Ń",Ǹ:"Ǹ",Ñ:"Ñ",Ň:"Ň",Ṅ:"Ṅ",Ņ:"Ņ",Ó:"Ó",Ò:"Ò",Ö:"Ö",Ȫ:"Ȫ",Õ:"Õ",Ṍ:"Ṍ",Ṏ:"Ṏ",Ȭ:"Ȭ",Ō:"Ō",Ṓ:"Ṓ",Ṑ:"Ṑ",Ŏ:"Ŏ",Ǒ:"Ǒ",Ô:"Ô",Ố:"Ố",Ồ:"Ồ",Ỗ:"Ỗ",Ȯ:"Ȯ",Ȱ:"Ȱ",Ő:"Ő",Ṕ:"Ṕ",Ṗ:"Ṗ",Ŕ:"Ŕ",Ř:"Ř",Ṙ:"Ṙ",Ŗ:"Ŗ",Ś:"Ś",Ṥ:"Ṥ",Š:"Š",Ṧ:"Ṧ",Ŝ:"Ŝ",Ṡ:"Ṡ",Ş:"Ş",Ť:"Ť",Ṫ:"Ṫ",Ţ:"Ţ",Ú:"Ú",Ù:"Ù",Ü:"Ü",Ǘ:"Ǘ",Ǜ:"Ǜ",Ǖ:"Ǖ",Ǚ:"Ǚ",Ũ:"Ũ",Ṹ:"Ṹ",Ū:"Ū",Ṻ:"Ṻ",Ŭ:"Ŭ",Ǔ:"Ǔ",Û:"Û",Ů:"Ů",Ű:"Ű",Ṽ:"Ṽ",Ẃ:"Ẃ",Ẁ:"Ẁ",Ẅ:"Ẅ",Ŵ:"Ŵ",Ẇ:"Ẇ",Ẍ:"Ẍ",Ẋ:"Ẋ",Ý:"Ý",Ỳ:"Ỳ",Ÿ:"Ÿ",Ỹ:"Ỹ",Ȳ:"Ȳ",Ŷ:"Ŷ",Ẏ:"Ẏ",Ź:"Ź",Ž:"Ž",Ẑ:"Ẑ",Ż:"Ż",ά:"ά",ὰ:"ὰ",ᾱ:"ᾱ",ᾰ:"ᾰ",έ:"έ",ὲ:"ὲ",ή:"ή",ὴ:"ὴ",ί:"ί",ὶ:"ὶ",ϊ:"ϊ",ΐ:"ΐ",ῒ:"ῒ",ῑ:"ῑ",ῐ:"ῐ",ό:"ό",ὸ:"ὸ",ύ:"ύ",ὺ:"ὺ",ϋ:"ϋ",ΰ:"ΰ",ῢ:"ῢ",ῡ:"ῡ",ῠ:"ῠ",ώ:"ώ",ὼ:"ὼ",Ύ:"Ύ",Ὺ:"Ὺ",Ϋ:"Ϋ",Ῡ:"Ῡ",Ῠ:"Ῠ",Ώ:"Ώ",Ὼ:"Ὼ"};class zt{constructor(e,t){this.mode=void 0,this.gullet=void 0,this.settings=void 0,this.leftrightDepth=void 0,this.nextToken=void 0,this.mode="math",this.gullet=new $l(e,t,this.mode),this.settings=t,this.leftrightDepth=0}expect(e,t){if(t===void 0&&(t=!0),this.fetch().text!==e)throw new E("Expected '"+e+"', got '"+this.fetch().text+"'",this.fetch());t&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken==null&&(this.nextToken=this.gullet.expandNextToken()),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.settings.globalGroup||this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set("\\color","\\textcolor");try{var e=this.parseExpression(!1);return this.expect("EOF"),this.settings.globalGroup||this.gullet.endGroup(),e}finally{this.gullet.endGroups()}}subparse(e){var t=this.nextToken;this.consume(),this.gullet.pushToken(new Oe("}")),this.gullet.pushTokens(e);var a=this.parseExpression(!1);return this.expect("}"),this.nextToken=t,a}parseExpression(e,t){for(var a=[];;){this.mode==="math"&&this.consumeSpaces();var s=this.fetch();if(zt.endOfExpression.indexOf(s.text)!==-1||t&&s.text===t||e&&p0[s.text]&&p0[s.text].infix)break;var n=this.parseAtom(t);if(n){if(n.type==="internal")continue}else break;a.push(n)}return this.mode==="text"&&this.formLigatures(a),this.handleInfixNodes(a)}handleInfixNodes(e){for(var t=-1,a,s=0;s<e.length;s++)if(e[s].type==="infix"){if(t!==-1)throw new E("only one infix operator per group",e[s].token);t=s,a=e[s].replaceWith}if(t!==-1&&a){var n,l,c=e.slice(0,t),d=e.slice(t+1);c.length===1&&c[0].type==="ordgroup"?n=c[0]:n={type:"ordgroup",mode:this.mode,body:c},d.length===1&&d[0].type==="ordgroup"?l=d[0]:l={type:"ordgroup",mode:this.mode,body:d};var p;return a==="\\\\abovefrac"?p=this.callFunction(a,[n,e[t],l],[]):p=this.callFunction(a,[n,l],[]),[p]}else return e}handleSupSubscript(e){var t=this.fetch(),a=t.text;this.consume(),this.consumeSpaces();var s;do{var n;s=this.parseGroup(e)}while(((n=s)==null?void 0:n.type)==="internal");if(!s)throw new E("Expected group after '"+a+"'",t);return s}formatUnsupportedCmd(e){for(var t=[],a=0;a<e.length;a++)t.push({type:"textord",mode:"text",text:e[a]});var s={type:"text",mode:this.mode,body:t},n={type:"color",mode:this.mode,color:this.settings.errorColor,body:[s]};return n}parseAtom(e){var t=this.parseGroup("atom",e);if(t?.type==="internal"||this.mode==="text")return t;for(var a,s;;){this.consumeSpaces();var n=this.fetch();if(n.text==="\\limits"||n.text==="\\nolimits"){if(t&&t.type==="op"){var l=n.text==="\\limits";t.limits=l,t.alwaysHandleSupSub=!0}else if(t&&t.type==="operatorname")t.alwaysHandleSupSub&&(t.limits=n.text==="\\limits");else throw new E("Limit controls must follow a math operator",n);this.consume()}else if(n.text==="^"){if(a)throw new E("Double superscript",n);a=this.handleSupSubscript("superscript")}else if(n.text==="_"){if(s)throw new E("Double subscript",n);s=this.handleSupSubscript("subscript")}else if(n.text==="'"){if(a)throw new E("Double superscript",n);var c={type:"textord",mode:this.mode,text:"\\prime"},d=[c];for(this.consume();this.fetch().text==="'";)d.push(c),this.consume();this.fetch().text==="^"&&d.push(this.handleSupSubscript("superscript")),a={type:"ordgroup",mode:this.mode,body:d}}else if(lt[n.text]){var p=Na.test(n.text),f=[];for(f.push(new Oe(lt[n.text])),this.consume();;){var x=this.fetch().text;if(!lt[x]||Na.test(x)!==p)break;f.unshift(new Oe(lt[x])),this.consume()}var y=this.subparse(f);p?s={type:"ordgroup",mode:"math",body:y}:a={type:"ordgroup",mode:"math",body:y}}else break}return a||s?{type:"supsub",mode:this.mode,base:t,sup:a,sub:s}:t}parseFunction(e,t){var a=this.fetch(),s=a.text,n=p0[s];if(!n)return null;if(this.consume(),t&&t!=="atom"&&!n.allowedInArgument)throw new E("Got function '"+s+"' with no arguments"+(t?" as "+t:""),a);if(this.mode==="text"&&!n.allowedInText)throw new E("Can't use function '"+s+"' in text mode",a);if(this.mode==="math"&&n.allowedInMath===!1)throw new E("Can't use function '"+s+"' in math mode",a);var{args:l,optArgs:c}=this.parseArguments(s,n);return this.callFunction(s,l,c,a,e)}callFunction(e,t,a,s,n){var l={funcName:e,parser:this,token:s,breakOnTokenText:n},c=p0[e];if(c&&c.handler)return c.handler(l,t,a);throw new E("No function handler for "+e)}parseArguments(e,t){var a=t.numArgs+t.numOptionalArgs;if(a===0)return{args:[],optArgs:[]};for(var s=[],n=[],l=0;l<a;l++){var c=t.argTypes&&t.argTypes[l],d=l<t.numOptionalArgs;(t.primitive&&c==null||t.type==="sqrt"&&l===1&&n[0]==null)&&(c="primitive");var p=this.parseGroupOfType("argument to '"+e+"'",c,d);if(d)n.push(p);else if(p!=null)s.push(p);else throw new E("Null argument, please report this as a bug")}return{args:s,optArgs:n}}parseGroupOfType(e,t,a){switch(t){case"color":return this.parseColorGroup(a);case"size":return this.parseSizeGroup(a);case"url":return this.parseUrlGroup(a);case"math":case"text":return this.parseArgumentGroup(a,t);case"hbox":{var s=this.parseArgumentGroup(a,"text");return s!=null?{type:"styling",mode:s.mode,body:[s],style:"text"}:null}case"raw":{var n=this.parseStringGroup("raw",a);return n!=null?{type:"raw",mode:"text",string:n.text}:null}case"primitive":{if(a)throw new E("A primitive argument cannot be optional");var l=this.parseGroup(e);if(l==null)throw new E("Expected group as "+e,this.fetch());return l}case"original":case null:case void 0:return this.parseArgumentGroup(a);default:throw new E("Unknown group type as "+e,this.fetch())}}consumeSpaces(){for(;this.fetch().text===" ";)this.consume()}parseStringGroup(e,t){var a=this.gullet.scanArgument(t);if(a==null)return null;for(var s="",n;(n=this.fetch()).text!=="EOF";)s+=n.text,this.consume();return this.consume(),a.text=s,a}parseRegexGroup(e,t){for(var a=this.fetch(),s=a,n="",l;(l=this.fetch()).text!=="EOF"&&e.test(n+l.text);)s=l,n+=s.text,this.consume();if(n==="")throw new E("Invalid "+t+": '"+a.text+"'",a);return a.range(s,n)}parseColorGroup(e){var t=this.parseStringGroup("color",e);if(t==null)return null;var a=/^(#[a-f0-9]{3,4}|#[a-f0-9]{6}|#[a-f0-9]{8}|[a-f0-9]{6}|[a-z]+)$/i.exec(t.text);if(!a)throw new E("Invalid color: '"+t.text+"'",t);var s=a[0];return/^[0-9a-f]{6}$/i.test(s)&&(s="#"+s),{type:"color-token",mode:this.mode,color:s}}parseSizeGroup(e){var t,a=!1;if(this.gullet.consumeSpaces(),!e&&this.gullet.future().text!=="{"?t=this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/,"size"):t=this.parseStringGroup("size",e),!t)return null;!e&&t.text.length===0&&(t.text="0pt",a=!0);var s=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(t.text);if(!s)throw new E("Invalid size: '"+t.text+"'",t);var n={number:+(s[1]+s[2]),unit:s[3]};if(!_a(n))throw new E("Invalid unit: '"+n.unit+"'",t);return{type:"size",mode:this.mode,value:n,isBlank:a}}parseUrlGroup(e){this.gullet.lexer.setCatcode("%",13),this.gullet.lexer.setCatcode("~",12);var t=this.parseStringGroup("url",e);if(this.gullet.lexer.setCatcode("%",14),this.gullet.lexer.setCatcode("~",13),t==null)return null;var a=t.text.replace(/\\([#$%&~_^{}])/g,"$1");return{type:"url",mode:this.mode,url:a}}parseArgumentGroup(e,t){var a=this.gullet.scanArgument(e);if(a==null)return null;var s=this.mode;t&&this.switchMode(t),this.gullet.beginGroup();var n=this.parseExpression(!1,"EOF");this.expect("EOF"),this.gullet.endGroup();var l={type:"ordgroup",mode:this.mode,loc:a.loc,body:n};return t&&this.switchMode(s),l}parseGroup(e,t){var a=this.fetch(),s=a.text,n;if(s==="{"||s==="\\begingroup"){this.consume();var l=s==="{"?"}":"\\endgroup";this.gullet.beginGroup();var c=this.parseExpression(!1,l),d=this.fetch();this.expect(l),this.gullet.endGroup(),n={type:"ordgroup",mode:this.mode,loc:Ee.range(a,d),body:c,semisimple:s==="\\begingroup"||void 0}}else if(n=this.parseFunction(t,e)||this.parseSymbol(),n==null&&s[0]==="\\"&&!Gs.hasOwnProperty(s)){if(this.settings.throwOnError)throw new E("Undefined control sequence: "+s,a);n=this.formatUnsupportedCmd(s),this.consume()}return n}formLigatures(e){for(var t=e.length-1,a=0;a<t;++a){var s=e[a],n=s.text;n==="-"&&e[a+1].text==="-"&&(a+1<t&&e[a+2].text==="-"?(e.splice(a,3,{type:"textord",mode:"text",loc:Ee.range(s,e[a+2]),text:"---"}),t-=2):(e.splice(a,2,{type:"textord",mode:"text",loc:Ee.range(s,e[a+1]),text:"--"}),t-=1)),(n==="'"||n==="`")&&e[a+1].text===n&&(e.splice(a,2,{type:"textord",mode:"text",loc:Ee.range(s,e[a+1]),text:n+n}),t-=1)}}parseSymbol(){var e=this.fetch(),t=e.text;if(/^\\verb[^a-zA-Z]/.test(t)){this.consume();var a=t.slice(5),s=a.charAt(0)==="*";if(s&&(a=a.slice(1)),a.length<2||a.charAt(0)!==a.slice(-1))throw new E(`\\verb assertion failed --
|
|
265
|
-
please report what input caused this bug`);return a=a.slice(1,-1),{type:"verb",mode:"text",body:a,star:s}}Ta.hasOwnProperty(t[0])&&!de[this.mode][t[0]]&&(this.settings.strict&&this.mode==="math"&&this.settings.reportNonstrict("unicodeTextInMathMode",'Accented Unicode text character "'+t[0]+'" used in math mode',e),t=Ta[t[0]]+t.slice(1));var n=Pl.exec(t);n&&(t=t.substring(0,n.index),t==="i"?t="ı":t==="j"&&(t="ȷ"));var l;if(de[this.mode][t]){this.settings.strict&&this.mode==="math"&&sr.indexOf(t)>=0&&this.settings.reportNonstrict("unicodeTextInMathMode",'Latin-1/Unicode text character "'+t[0]+'" used in math mode',e);var c=de[this.mode][t].group,d=Ee.range(e),p;if(Ci.hasOwnProperty(c)){var f=c;p={type:"atom",mode:this.mode,family:f,loc:d,text:t}}else p={type:c,mode:this.mode,loc:d,text:t};l=p}else if(t.charCodeAt(0)>=128)this.settings.strict&&(Qa(t.charCodeAt(0))?this.mode==="math"&&this.settings.reportNonstrict("unicodeTextInMathMode",'Unicode text character "'+t[0]+'" used in math mode',e):this.settings.reportNonstrict("unknownSymbol",'Unrecognized Unicode character "'+t[0]+'"'+(" ("+t.charCodeAt(0)+")"),e)),l={type:"textord",mode:"text",loc:Ee.range(e),text:t};else return null;if(this.consume(),n)for(var x=0;x<n[0].length;x++){var y=n[0][x];if(!Kt[y])throw new E("Unknown accent ' "+y+"'",e);var b=Kt[y][this.mode]||Kt[y].text;if(!b)throw new E("Accent "+y+" unsupported in "+this.mode+" mode",e);l={type:"accent",mode:this.mode,loc:Ee.range(e),label:b,isStretchy:!1,isShifty:!0,base:l}}return l}}zt.endOfExpression=["}","\\endgroup","\\end","\\right","&"];var Br=function(e,t){if(!(typeof e=="string"||e instanceof String))throw new TypeError("KaTeX can only parse string typed expression");var a=new zt(e,t);delete a.gullet.macros.current["\\df@tag"];var s=a.parse();if(delete a.gullet.macros.current["\\current@color"],delete a.gullet.macros.current["\\color"],a.gullet.macros.get("\\df@tag")){if(!t.displayMode)throw new E("\\tag works only in display equations");s=[{type:"tag",mode:"text",body:s,tag:a.subparse([new Oe("\\df@tag")])}]}return s},Us=function(e,t,a){t.textContent="";var s=Fr(e,a).toNode();t.appendChild(s)};typeof document<"u"&&document.compatMode!=="CSS1Compat"&&(typeof console<"u"&&console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your website has a suitable doctype."),Us=function(){throw new E("KaTeX doesn't work in quirks mode.")});var Gl=function(e,t){var a=Fr(e,t).toMarkup();return a},Ul=function(e,t){var a=new pr(t);return Br(e,a)},Vs=function(e,t,a){if(a.throwOnError||!(e instanceof E))throw e;var s=M.makeSpan(["katex-error"],[new Ge(t)]);return s.setAttribute("title",e.toString()),s.setAttribute("style","color:"+a.errorColor),s},Fr=function(e,t){var a=new pr(t);try{var s=Br(e,a);return _i(s,e,a)}catch(n){return Vs(n,e,a)}},Vl=function(e,t){var a=new pr(t);try{var s=Br(e,a);return el(s,e,a)}catch(n){return Vs(n,e,a)}},Wl="0.16.
|
|
265
|
+
please report what input caused this bug`);return a=a.slice(1,-1),{type:"verb",mode:"text",body:a,star:s}}Ta.hasOwnProperty(t[0])&&!de[this.mode][t[0]]&&(this.settings.strict&&this.mode==="math"&&this.settings.reportNonstrict("unicodeTextInMathMode",'Accented Unicode text character "'+t[0]+'" used in math mode',e),t=Ta[t[0]]+t.slice(1));var n=Pl.exec(t);n&&(t=t.substring(0,n.index),t==="i"?t="ı":t==="j"&&(t="ȷ"));var l;if(de[this.mode][t]){this.settings.strict&&this.mode==="math"&&sr.indexOf(t)>=0&&this.settings.reportNonstrict("unicodeTextInMathMode",'Latin-1/Unicode text character "'+t[0]+'" used in math mode',e);var c=de[this.mode][t].group,d=Ee.range(e),p;if(Ci.hasOwnProperty(c)){var f=c;p={type:"atom",mode:this.mode,family:f,loc:d,text:t}}else p={type:c,mode:this.mode,loc:d,text:t};l=p}else if(t.charCodeAt(0)>=128)this.settings.strict&&(Qa(t.charCodeAt(0))?this.mode==="math"&&this.settings.reportNonstrict("unicodeTextInMathMode",'Unicode text character "'+t[0]+'" used in math mode',e):this.settings.reportNonstrict("unknownSymbol",'Unrecognized Unicode character "'+t[0]+'"'+(" ("+t.charCodeAt(0)+")"),e)),l={type:"textord",mode:"text",loc:Ee.range(e),text:t};else return null;if(this.consume(),n)for(var x=0;x<n[0].length;x++){var y=n[0][x];if(!Kt[y])throw new E("Unknown accent ' "+y+"'",e);var b=Kt[y][this.mode]||Kt[y].text;if(!b)throw new E("Accent "+y+" unsupported in "+this.mode+" mode",e);l={type:"accent",mode:this.mode,loc:Ee.range(e),label:b,isStretchy:!1,isShifty:!0,base:l}}return l}}zt.endOfExpression=["}","\\endgroup","\\end","\\right","&"];var Br=function(e,t){if(!(typeof e=="string"||e instanceof String))throw new TypeError("KaTeX can only parse string typed expression");var a=new zt(e,t);delete a.gullet.macros.current["\\df@tag"];var s=a.parse();if(delete a.gullet.macros.current["\\current@color"],delete a.gullet.macros.current["\\color"],a.gullet.macros.get("\\df@tag")){if(!t.displayMode)throw new E("\\tag works only in display equations");s=[{type:"tag",mode:"text",body:s,tag:a.subparse([new Oe("\\df@tag")])}]}return s},Us=function(e,t,a){t.textContent="";var s=Fr(e,a).toNode();t.appendChild(s)};typeof document<"u"&&document.compatMode!=="CSS1Compat"&&(typeof console<"u"&&console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your website has a suitable doctype."),Us=function(){throw new E("KaTeX doesn't work in quirks mode.")});var Gl=function(e,t){var a=Fr(e,t).toMarkup();return a},Ul=function(e,t){var a=new pr(t);return Br(e,a)},Vs=function(e,t,a){if(a.throwOnError||!(e instanceof E))throw e;var s=M.makeSpan(["katex-error"],[new Ge(t)]);return s.setAttribute("title",e.toString()),s.setAttribute("style","color:"+a.errorColor),s},Fr=function(e,t){var a=new pr(t);try{var s=Br(e,a);return _i(s,e,a)}catch(n){return Vs(n,e,a)}},Vl=function(e,t){var a=new pr(t);try{var s=Br(e,a);return el(s,e,a)}catch(n){return Vs(n,e,a)}},Wl="0.16.28",Xl={Span:X0,Anchor:vr,SymbolNode:Ge,SvgNode:n0,PathNode:v0,LineNode:ar},za={version:Wl,render:Us,renderToString:Gl,ParseError:E,SETTINGS_SCHEMA:ut,__parse:Ul,__renderToDomTree:Fr,__renderToHTMLTree:Vl,__setFontMetrics:ki,__defineSymbol:i,__defineFunction:$,__defineMacro:m,__domTree:Xl};const Yl={};function Kl(r){const e=this,t=r||Yl,a=e.data(),s=a.micromarkExtensions||(a.micromarkExtensions=[]),n=a.fromMarkdownExtensions||(a.fromMarkdownExtensions=[]),l=a.toMarkdownExtensions||(a.toMarkdownExtensions=[]);s.push(Yn(t)),n.push(Ln()),l.push(Hn(t))}const Zt={html:"http://www.w3.org/1999/xhtml",svg:"http://www.w3.org/2000/svg"};function Zl(r,e){return Ws(r,{})||{type:"root",children:[]}}function Ws(r,e){const t=Jl(r,e);return t&&e.afterTransform&&e.afterTransform(r,t),t}function Jl(r,e){switch(r.nodeType){case 1:return to(r,e);case 3:return _l(r);case 8:return eo(r);case 9:return Aa(r,e);case 10:return Ql();case 11:return Aa(r,e);default:return}}function Aa(r,e){return{type:"root",children:Xs(r,e)}}function Ql(){return{type:"doctype"}}function _l(r){return{type:"text",value:r.nodeValue||""}}function eo(r){return{type:"comment",value:r.nodeValue||""}}function to(r,e){const t=r.namespaceURI,a=t===Zt.svg?on:un,s=t===Zt.html?r.tagName.toLowerCase():r.tagName,n=t===Zt.html&&s==="template"?r.content:r,l=r.getAttributeNames(),c={};let d=-1;for(;++d<l.length;)c[l[d]]=r.getAttribute(l[d])||"";return a(s,c,Xs(n,e))}function Xs(r,e){const t=r.childNodes,a=[];let s=-1;for(;++s<t.length;){const n=Ws(t[s],e);n!==void 0&&a.push(n)}return a}new DOMParser;function ro(r,e){const t=ao(r);return Zl(t)}function ao(r){const e=document.createElement("template");return e.innerHTML=r,e.content}const ja=(function(r,e,t){const a=cn(t);if(!r||!r.type||!r.children)throw new Error("Expected parent node");if(typeof e=="number"){if(e<0||e===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(e=r.children.indexOf(e),e<0)throw new Error("Expected child node or index");for(;++e<r.children.length;)if(a(r.children[e],e,r))return r.children[e]}),T0=(function(r){if(r==null)return io;if(typeof r=="string")return no(r);if(typeof r=="object")return so(r);if(typeof r=="function")return Ir(r);throw new Error("Expected function, string, or array as `test`")});function so(r){const e=[];let t=-1;for(;++t<r.length;)e[t]=T0(r[t]);return Ir(a);function a(...s){let n=-1;for(;++n<e.length;)if(e[n].apply(this,s))return!0;return!1}}function no(r){return Ir(e);function e(t){return t.tagName===r}}function Ir(r){return e;function e(t,a,s){return!!(lo(t)&&r.call(this,t,typeof a=="number"?a:void 0,s||void 0))}}function io(r){return!!(r&&typeof r=="object"&&"type"in r&&r.type==="element"&&"tagName"in r&&typeof r.tagName=="string")}function lo(r){return r!==null&&typeof r=="object"&&"type"in r&&"tagName"in r}const Ca=/\n/g,Da=/[\t ]+/g,cr=T0("br"),Ba=T0(go),oo=T0("p"),Fa=T0("tr"),uo=T0(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",fo,vo]),Ys=T0(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function co(r,e){const t=e||{},a="children"in r?r.children:[],s=Ys(r),n=Js(r,{whitespace:t.whitespace||"normal"}),l=[];(r.type==="text"||r.type==="comment")&&l.push(...Zs(r,{breakBefore:!0,breakAfter:!0}));let c=-1;for(;++c<a.length;)l.push(...Ks(a[c],r,{whitespace:n,breakBefore:c?void 0:s,breakAfter:c<a.length-1?cr(a[c+1]):s}));const d=[];let p;for(c=-1;++c<l.length;){const f=l[c];typeof f=="number"?p!==void 0&&f>p&&(p=f):f&&(p!==void 0&&p>-1&&d.push(`
|
|
266
266
|
`.repeat(p)||" "),p=-1,d.push(f))}return d.join("")}function Ks(r,e,t){return r.type==="element"?ho(r,e,t):r.type==="text"?t.whitespace==="normal"?Zs(r,t):mo(r):[]}function ho(r,e,t){const a=Js(r,t),s=r.children||[];let n=-1,l=[];if(uo(r))return l;let c,d;for(cr(r)||Fa(r)&&ja(e,r,Fa)?d=`
|
|
267
267
|
`:oo(r)?(c=2,d=2):Ys(r)&&(c=1,d=1);++n<s.length;)l=l.concat(Ks(s[n],r,{whitespace:a,breakBefore:n?void 0:c,breakAfter:n<s.length-1?cr(s[n+1]):d}));return Ba(r)&&ja(e,r,Ba)&&l.push(" "),c&&l.unshift(c),d&&l.push(d),l}function Zs(r,e){const t=String(r.value),a=[],s=[];let n=0;for(;n<=t.length;){Ca.lastIndex=n;const d=Ca.exec(t),p=d&&"index"in d?d.index:t.length;a.push(po(t.slice(n,p).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),n===0?e.breakBefore:!0,p===t.length?e.breakAfter:!0)),n=p+1}let l=-1,c;for(;++l<a.length;)a[l].charCodeAt(a[l].length-1)===8203||l<a.length-1&&a[l+1].charCodeAt(0)===8203?(s.push(a[l]),c=void 0):a[l]?(typeof c=="number"&&s.push(c),s.push(a[l]),c=0):(l===0||l===a.length-1)&&s.push(0);return s}function mo(r){return[String(r.value)]}function po(r,e,t){const a=[];let s=0,n;for(;s<r.length;){Da.lastIndex=s;const l=Da.exec(r);n=l?l.index:r.length,!s&&!n&&l&&!e&&a.push(""),s!==n&&a.push(r.slice(s,n)),s=l?n+l[0].length:n}return s!==n&&!t&&a.push(""),a.join(" ")}function Js(r,e){if(r.type==="element"){const t=r.properties||{};switch(r.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return t.wrap?"pre-wrap":"pre";case"td":case"th":return t.noWrap?"nowrap":e.whitespace;case"textarea":return"pre-wrap"}}return e.whitespace}function fo(r){return!!(r.properties||{}).hidden}function go(r){return r.tagName==="td"||r.tagName==="th"}function vo(r){return r.tagName==="dialog"&&!(r.properties||{}).open}const xo={},bo=[];function yo(r){const e=r||xo;return function(t,a){dn(t,"element",function(s,n){const l=Array.isArray(s.properties.className)?s.properties.className:bo,c=l.includes("language-math"),d=l.includes("math-display"),p=l.includes("math-inline");let f=d;if(!c&&!d&&!p)return;let x=n[n.length-1],y=s;if(s.tagName==="code"&&c&&x&&x.type==="element"&&x.tagName==="pre"&&(y=x,x=n[n.length-2],f=!0),!x)return;const b=co(y,{whitespace:"pre"});let S;try{S=za.renderToString(b,{...e,displayMode:f,throwOnError:!0})}catch(C){const B=C,z=B.name.toLowerCase();a.message("Could not render math with KaTeX",{ancestors:[...n,s],cause:B,place:s.position,ruleId:z,source:"rehype-katex"});try{S=za.renderToString(b,{...e,displayMode:f,strict:"ignore",throwOnError:!1})}catch{S=[{type:"element",tagName:"span",properties:{className:["katex-error"],style:"color:"+(e.errorColor||"#cc0000"),title:String(C)},children:[{type:"text",value:b}]}]}}typeof S=="string"&&(S=ro(S).children);const k=x.children.indexOf(y);return x.children.splice(k,1,...S),hn})}}const wo=r=>{const e=[];let t=r.replace(/```[\s\S]*?```|`[^`\n]+`/g,a=>(e.push(a),`__CODE_BLOCK_${e.length-1}__`));return t=t.replace(/\\\[([\s\S]*?)\\\]/g,(a,s)=>`$$${s}$$`),t=t.replace(/\\\(([\s\S]*?)\\\)/g,(a,s)=>`$${s}$`),e.forEach((a,s)=>{t=t.replace(`__CODE_BLOCK_${s}__`,a)}),t},ko=({content:r,className:e})=>{const{theme:t}=C0(),[a,s]=Jt.useState(null),n=Jt.useMemo(()=>wo(r),[r]),l=async c=>{try{await navigator.clipboard.writeText(c),s(c),setTimeout(()=>s(null),2e3)}catch(d){console.error("Failed to copy text:",d)}};return u.jsx("div",{className:Y("prose prose-sm max-w-none dark:prose-invert prose-gray","[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2","[&_.katex]:text-inherit",e),children:u.jsx(mn,{remarkPlugins:[Kl],rehypePlugins:[yo],components:{code({inline:c,className:d,children:p,...f}){const x=/language-(\w+)/.exec(d||""),y=String(p).replace(/\n$/,""),b=x?x[1]:null;return c?u.jsx("code",{className:Y("px-2 py-1 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800","font-mono text-sm border border-gray-200 dark:border-dark-300",d),...f,children:p}):u.jsxs("div",{className:"relative group my-4 overflow-hidden rounded-xl border border-gray-200 dark:border-dark-300 shadow-sm",children:[u.jsxs("div",{className:"flex items-center justify-between bg-gray-50 dark:bg-dark-100 px-4 py-3 border-b border-gray-200 dark:border-dark-300",children:[u.jsx("span",{className:"text-xs font-semibold text-gray-700 dark:text-dark-700 uppercase tracking-wide",children:b||"text"}),u.jsx("button",{onClick:()=>l(y),className:"opacity-0 group-hover:opacity-100 transition-all duration-200 p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-300 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1",title:"Copy code",children:a===y?u.jsx(yt,{className:"h-4 w-4 text-success-600 dark:text-success-400"}):u.jsx(La,{className:"h-4 w-4 text-gray-500 dark:text-dark-600"})})]}),u.jsx("div",{className:"overflow-x-auto",children:u.jsx(gn,{language:b||"text",isDark:t.mode==="dark",className:"!m-0 !rounded-none !border-none",children:y})})]})},pre({children:c,...d}){return u.jsx("pre",{...d,children:c})},p({children:c,...d}){return u.jsx("p",{className:"mb-4 last:mb-0 leading-relaxed",...d,children:c})},ul({children:c,...d}){return u.jsx("ul",{className:"list-disc list-inside mb-4 space-y-2 pl-4",...d,children:c})},ol({children:c,...d}){return u.jsx("ol",{className:"list-decimal list-inside mb-4 space-y-2 pl-4",...d,children:c})},li({children:c,...d}){return u.jsx("li",{className:"text-gray-700 dark:text-dark-700 leading-relaxed",...d,children:c})},blockquote({children:c,...d}){return u.jsx("blockquote",{className:"border-l-4 border-primary-400 dark:border-primary-500 ophelia:border-[#a855f7] bg-primary-25 dark:bg-primary-950/30 ophelia:bg-[rgba(168,85,247,0.1)] pl-4 py-3 my-4 rounded-r-lg italic text-gray-700 dark:text-dark-700 ophelia:text-[#d4d4d4]",...d,children:c})},h1({children:c,...d}){return u.jsx("h1",{className:"text-2xl font-bold mb-4 mt-6 first:mt-0 text-gray-900 dark:text-dark-800 border-b border-gray-200 dark:border-dark-300 pb-2",...d,children:c})},h2({children:c,...d}){return u.jsx("h2",{className:"text-xl font-semibold mb-3 mt-6 first:mt-0 text-gray-900 dark:text-dark-800",...d,children:c})},h3({children:c,...d}){return u.jsx("h3",{className:"text-lg font-medium mb-3 mt-4 first:mt-0 text-gray-900 dark:text-dark-800",...d,children:c})}},children:n})})},So=({statistics:r,className:e=""})=>{const[t,a]=A.useState(!1),s=x=>{if(x==null)return"N/A";const y=x/1e6;return y<1e3?`${Math.round(y)}ms`:`${(y/1e3).toFixed(2)}s`},n=x=>x?`${x.toFixed(1)} t/s`:"N/A",l=r.prompt_eval_count||0,c=r.eval_count||0,d=l+c,p=s(r.total_duration),f=n(r.tokens_per_second);return u.jsxs("div",{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${e}`,children:[u.jsxs("div",{className:"flex items-center gap-4 mb-1",children:[u.jsxs("span",{className:"flex items-center gap-1 text-gray-600 dark:text-dark-600",children:[u.jsx(yn,{size:12,className:"text-primary-500"}),c," tokens"]}),u.jsx("span",{className:"text-gray-500 dark:text-dark-500",children:f}),u.jsx("span",{className:"text-gray-500 dark:text-dark-500",children:p}),r.model&&u.jsx("span",{className:"text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48",title:r.model,children:r.model})]}),u.jsxs("button",{onClick:()=>a(!t),className:"flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors",children:[t?u.jsx(D0,{size:12}):u.jsx(wn,{size:12}),u.jsx("span",{children:"Details"})]}),t&&u.jsxs("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:[u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Prompt tokens:"})," ",l]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Generated tokens:"})," ",c]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Total tokens:"})," ",d]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Speed:"})," ",f]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Prompt eval:"})," ",s(r.prompt_eval_duration)]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Generation:"})," ",s(r.eval_duration)]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Model load:"})," ",s(r.load_duration)]}),u.jsxs("div",{className:"text-gray-700 dark:text-dark-700",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Total time:"})," ",p]})]}),r.created_at&&u.jsxs("div",{className:"pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600",children:[u.jsx("span",{className:"font-medium text-gray-800 dark:text-dark-800",children:"Generated at:"})," ",new Date(r.created_at).toLocaleTimeString()]})]})]})};let L0=null,H0=null,ot=0;const Mo=300*1e3;async function No(){const r=Date.now();return L0!==null&&r-ot<Mo?L0:H0||(H0=(async()=>{try{const e=await dt.getModels();return e.success&&e.data&&e.data.length>0?(L0=e.data,ot=r,e.data):(L0=[],ot=r,[])}catch{return L0=[],ot=r,[]}finally{H0=null}})(),H0)}function To(r){return r.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(t=>t.trim()).filter(t=>t.length>0)}const zo=({text:r,className:e,size:t="sm"})=>{const{t:a}=b0(),{preferences:s}=C0(),[n,l]=A.useState(!1),[c,d]=A.useState(!1),[p,f]=A.useState(null),[x,y]=A.useState([]),[b,S]=A.useState(null),k=A.useRef(null),C=A.useRef(!1),B=A.useRef([]),z=A.useRef(0);A.useEffect(()=>{let N=!0;return No().then(j=>{N&&(y(j),S(j.length>0))}),()=>{N=!1}},[]);const U=A.useCallback(async(N,j,L,H)=>{const V=await dt.generateBase64({model:j,input:N,voice:L,speed:H,response_format:"mp3"});if(!V.success||!V.data?.audio)throw new Error(V.message||a("ttsButton.generateFailed"));const Q=`data:${V.data.mimeType};base64,${V.data.audio}`,W=new Audio(Q);return k.current=W,new Promise((te,le)=>{W.onended=()=>{k.current=null,te()},W.onerror=()=>{k.current=null,le(new Error(a("ttsButton.playbackFailed")))},W.play().catch(le)})},[a]),R=A.useCallback(async(N,j,L,H)=>{B.current=N,z.current=0,C.current=!1;let V=null;const Q=async W=>{try{const te=await dt.generateBase64({model:j,input:W,voice:L,speed:H,response_format:"mp3"});return!te.success||!te.data?.audio?null:{audioUrl:`data:${te.data.mimeType};base64,${te.data.audio}`,mimeType:te.data.mimeType}}catch{return null}};N.length>0&&(V=Q(N[0]));for(let W=0;W<N.length&&!C.current;W++){z.current=W;try{const te=await V;if(C.current)break;if(W+1<N.length?V=Q(N[W+1]):V=null,!te){console.warn(`Failed to generate audio for sentence ${W+1}, skipping`);continue}const le=new Audio(te.audioUrl);k.current=le,await new Promise((be,ke)=>{le.onended=()=>{k.current=null,be()},le.onerror=()=>{k.current=null,be()},le.play().catch(()=>{be()})})}catch(te){console.error(`Error playing sentence ${W+1}:`,te)}}},[]),O=A.useCallback(()=>{C.current=!0,k.current&&(k.current.pause(),k.current.currentTime=0,k.current=null),l(!1),d(!1)},[]),X=async()=>{if(!c){if(n){O();return}d(!0),f(null),C.current=!1;try{const N=s.ttsSettings,j=N?.model||x[0]?.model||"tts-1",L=N?.voice||x[0]?.config?.default_voice||"alloy",H=N?.speed||1;if(N?.streamSentences||!1){const Q=To(r);if(Q.length===0)throw new Error(a("ttsButton.generateFailed"));d(!1),l(!0),await R(Q,j,L,H),C.current||l(!1)}else await U(r,j,L,H),d(!1),l(!0),k.current&&(k.current.onended=()=>{l(!1),k.current=null},k.current.onerror=()=>{f(a("ttsButton.playbackFailed")),l(!1),k.current=null})}catch(N){const j=N instanceof Error?N.message:a("ttsButton.generateFailed");f(j),console.error("TTS error:",N),l(!1),d(!1)}}};if(A.useEffect(()=>()=>{C.current=!0,k.current&&(k.current.pause(),k.current=null)},[]),b===!1||b===null)return null;const F={sm:"h-6 w-6 p-1",md:"h-8 w-8 p-1.5",lg:"h-10 w-10 p-2"},q={sm:"h-3.5 w-3.5",md:"h-4 w-4",lg:"h-5 w-5"};return u.jsx("button",{onClick:X,disabled:c||!r,title:p||a(n?"ttsButton.stopSpeaking":c?"ttsButton.generatingSpeech":"ttsButton.readAloud"),className:Y("rounded-full transition-all duration-200","hover:bg-gray-100 dark:hover:bg-dark-200","focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1","disabled:opacity-50 disabled:cursor-not-allowed",p?"text-red-500 dark:text-red-400":n?"text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20":"text-gray-500 dark:text-gray-400",F[t],e),children:c?u.jsx(Ha,{className:Y(q[t],"animate-spin")}):n?u.jsx($a,{className:q[t]}):p?u.jsx(kn,{className:q[t]}):u.jsx(Sn,{className:q[t]})})},Ao=[{regex:/```html\s*\n([\s\S]*?)\n```/gi,type:"html",getTitle:r=>Co(r)||"HTML Document"},{regex:/```svg\s*\n([\s\S]*?)\n```/gi,type:"svg",getTitle:r=>"SVG Image"},{regex:/```(?:react|jsx)\s*\n([\s\S]*?)\n```/gi,type:"react",getTitle:r=>Do(r)||"React Component"},{regex:/```json\s*\n([\s\S]*?)\n```/gi,type:"json",getTitle:r=>"JSON Data"},{regex:/```python\s*\n([\s\S]*?)\n```/gi,type:"code",language:"python",getTitle:r=>Bo(r)||"Python Code"},{regex:/```(?:javascript|js)\s*\n([\s\S]*?)\n```/gi,type:"code",language:"javascript",getTitle:r=>Fo(r)||"JavaScript Code"},{regex:/```css\s*\n([\s\S]*?)\n```/gi,type:"code",language:"css",getTitle:r=>"CSS Styles"},{regex:/```(\w+)\s*\n([\s\S]*?)\n```/gi,type:"code",getTitle:(r,e)=>`${e.toUpperCase()} Code`}],jo=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:r=>({type:r[1],title:r[2],content:r[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:r=>({type:r[1],title:`${r[1].toUpperCase()} Artifact`,content:r[2].trim()})}];function Ia(r){const e=document.createElement("div");return e.innerHTML=r,e.textContent||e.innerText||""}function Co(r){const e=r.match(/<title[^>]*>(.*?)<\/title>/i);if(e)return Ia(e[1]).trim();const t=r.match(/<h1[^>]*>(.*?)<\/h1>/i);return t?Ia(t[1]).trim():null}function Do(r){const e=r.match(/(?:function|const)\s+(\w+)/);if(e)return e[1];const t=r.match(/class\s+(\w+)/);return t?t[1]:null}function Bo(r){if(r.includes("def main("))return"Python Script";const e=r.match(/class\s+(\w+)/);if(e)return`${e[1]} Class`;const t=r.match(/def\s+(\w+)/);return t&&t[1]!=="__init__"?`${t[1]} Function`:null}function Fo(r){const e=r.match(/function\s+(\w+)/);if(e)return`${e[1]} Function`;const t=r.match(/(?:const|let)\s+(\w+)\s*=/);return t?t[1]:null}function Ea(r,e){if(e==="html")return/<[^>]+>/.test(r)&&r.trim().length>200;if(e==="svg")return/<svg[^>]*>/.test(r);if(e==="react")return/<[A-Z][^>]*>/.test(r)||/return\s*\(/.test(r);if(e==="json")try{return JSON.parse(r),r.trim().length>100}catch{return!1}if(e==="code"){const t=r.split(`
|
|
268
268
|
`).length,a=r.trim().length,s=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(r);return(a>500||t>15)&&s}return!1}function qa(r){const e=[];let t=r;for(const a of jo){let s;for(;(s=a.regex.exec(t))!==null;){const n=a.extract(s);if(Ea(n.content,n.type)){const l={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:n.type,title:n.title,content:n.content,createdAt:Date.now(),updatedAt:Date.now()};e.push(l),t=t.replace(s[0],"")}}}for(const a of Ao){let s;for(a.regex.lastIndex=0;(s=a.regex.exec(t))!==null;){const n=s[1]||s[2],l=a.language||(s[1]&&s[2]?s[1]:void 0);if(Ea(n,a.type)){const c={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:a.type,title:a.getTitle(n,l||"code"),content:n,language:l,createdAt:Date.now(),updatedAt:Date.now()};e.push(c),t=t.replace(s[0],"")}}}return{content:t.trim(),artifacts:e}}const dr=({message:r,isStreaming:e=!1,className:t,isLastAssistantMessage:a=!1,onRegenerate:s})=>{const{t:n}=b0(),l=r.role==="user",c=r.role==="system",{preferences:d}=C0(),{user:p}=Pa(),{setSystemMessage:f,getCurrentPersona:x}=ze(),y=x(),[b,S]=A.useState(!1),[k,C]=A.useState(r.content),[B,z]=A.useState(null),[U,R]=A.useState(!1),[O,X]=A.useState(r.content),[F,q]=A.useState(!1),[N,j]=A.useState(r.artifacts||[]),[L,H]=A.useState(null),[V,Q]=A.useState(!1),[W,te]=A.useState(!1),[le,be]=A.useState(!1),ke=A.useRef(null),Ae=A.useRef(e),re=A.useRef(!1),ee=async()=>{try{await navigator.clipboard.writeText(r.content),be(!0),setTimeout(()=>be(!1),2e3)}catch(se){console.error("Failed to copy message:",se)}};A.useEffect(()=>{if(!l&&!c&&r.content){const se=Lr(r.content);H(se.thinking);const oe=se.content;if(r.artifacts&&r.artifacts.length>0)X(oe),j(r.artifacts);else if(e)X(oe),j([]);else{const Te=qa(oe);X(Te.content),j(Te.artifacts)}}},[r.content,r.artifacts,l,c,e]),A.useEffect(()=>{if(!l&&!c&&r.content&&!e){const se=Lr(r.content);H(se.thinking);const oe=se.content;if(!r.artifacts||r.artifacts.length===0){const Te=qa(oe);X(Te.content),j(Te.artifacts)}}},[e,r.content,r.artifacts,l,c]),A.useEffect(()=>{const se=Ae.current&&!e;return Ae.current=e,se&&!re.current&&!l&&!c&&O&&d.ttsSettings?.enabled&&d.ttsSettings?.autoPlay&&(re.current=!0,(async()=>{te(!0);try{const Te=await dt.generateBase64({model:d.ttsSettings?.model||"tts-1",input:O,voice:d.ttsSettings?.voice||"alloy",speed:d.ttsSettings?.speed||1,response_format:"mp3"});if(Te.success&&Te.data?.audio){const Ve=`data:${Te.data.mimeType};base64,${Te.data.audio}`,u0=new Audio(Ve);ke.current=u0,u0.onended=()=>{te(!1),ke.current=null},u0.onerror=()=>{te(!1),ke.current=null},await u0.play()}}catch(Te){console.error("Auto-play TTS failed:",Te),te(!1)}})()),()=>{ke.current&&(ke.current.pause(),ke.current=null)}},[e,l,c,O,d.ttsSettings]);const he=()=>c?n("chatMessage.system"):l?d.showUsername&&p?.username?p.username:n("chatMessage.you"):y?.name?y.name:r.model||n("chatMessage.assistant"),He=()=>{S(!0),C(r.content)},Xe=async()=>{R(!0);try{f(k),S(!1),console.log("✅ System message updated:",k)}catch(se){console.error("Failed to save system message:",se)}finally{R(!1)}},w0=()=>{S(!1),C(r.content)},Ne=(se,oe=100)=>se.length<=oe?se:se.substring(0,oe)+"...",Se=c&&r.content.length>100;return u.jsxs("div",{className:Y("flex transition-colors group my-2",l?"justify-end":"justify-start",t),children:[u.jsxs("div",{className:Y("flex gap-3 sm:gap-4",l?"flex-row-reverse max-w-[85%] sm:max-w-[75%]":c?"w-full":"max-w-[85%] sm:max-w-[75%]"),children:[!c&&u.jsx("div",{className:Y("flex shrink-0 items-center justify-center shadow-sm overflow-hidden mt-1",l?"h-8 w-8 rounded-full bg-primary-600 ophelia:bg-[#9333ea] text-white":y?.avatar?"h-8 w-8 rounded-full bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]":"h-8 px-2 rounded-full bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]"),children:l?p?.avatar?u.jsx("img",{src:p.avatar,alt:p.username,className:"w-full h-full object-cover"}):u.jsx(_t,{className:"h-4 w-4"}):y?.avatar?u.jsx("img",{src:y.avatar,alt:y.name||"Assistant",className:"w-full h-full object-cover"}):u.jsx("span",{className:"libre-brand text-xs text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5]",children:"Libre"})}),u.jsxs("div",{className:Y("flex-1 min-w-0 rounded-2xl sm:rounded-3xl p-4 sm:p-5",l?"bg-primary-600/90 dark:bg-primary-700/90 ophelia:bg-[#9333ea]/90 text-white":c?"bg-transparent p-2 py-3":"bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md shadow-sm border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60"),children:[!c&&u.jsxs("div",{className:Y("flex items-center gap-3 mb-2",l&&"flex-row-reverse"),children:[u.jsx("span",{className:Y("text-sm font-semibold",l?"text-white/90":"text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]"),children:he()}),r.model&&!l&&y?.name&&u.jsx("span",{className:"text-xs text-gray-500 dark:text-dark-600 ophelia:text-[#737373] bg-gray-100 dark:bg-dark-200 ophelia:bg-[#121212] px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48",title:r.model,children:r.model}),u.jsx("span",{className:Y("text-xs",l?"text-white/60":"text-gray-400 dark:text-dark-500 ophelia:text-[#525252]"),children:vn(r.timestamp)}),!l&&!c&&!e&&O&&u.jsx(zo,{text:O,size:"sm",className:Y("transition-opacity",W?"opacity-100 text-primary-600 dark:text-primary-400":"opacity-0 group-hover:opacity-100")}),!c&&!e&&u.jsx("button",{onClick:ee,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] transition-opacity opacity-0 group-hover:opacity-100",title:n(le?"chatMessage.copied":"chatMessage.copyMessage"),children:le?u.jsx(yt,{className:"h-3.5 w-3.5 text-green-500 dark:text-green-400"}):u.jsx(La,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]"})}),!l&&!c&&!e&&a&&s&&u.jsx("button",{onClick:s,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] transition-opacity opacity-0 group-hover:opacity-100",title:n("chatMessage.regenerateResponse"),children:u.jsx(er,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]"})})]}),u.jsxs("div",{className:Y(l?"text-white":"text-gray-700 dark:text-dark-700 ophelia:text-[#e5e5e5]"),children:[r.images&&r.images.length>0&&u.jsx("div",{className:"mb-3 grid grid-cols-2 sm:grid-cols-3 gap-2 max-w-lg",children:r.images.map((se,oe)=>u.jsx("div",{className:"aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:u.jsx("img",{src:se,alt:`Uploaded image ${oe+1}`,className:"w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>z(se)})},oe))}),l?u.jsx("p",{className:"whitespace-pre-wrap leading-relaxed",children:r.content}):c?u.jsxs("div",{className:"bg-gray-50/30 dark:bg-dark-50/30 ophelia:bg-[rgba(5,5,5,0.8)] rounded-md p-2 border border-gray-100/50 dark:border-dark-200/50 ophelia:border-[rgba(26,26,26,0.5)] relative z-0",children:[u.jsxs("div",{className:"text-xs font-medium mb-1 text-gray-500 dark:text-gray-400 ophelia:text-[#737373] flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Ga,{className:"h-2.5 w-2.5 opacity-50"}),n("chatMessage.system")]}),u.jsx("div",{className:"flex items-center gap-1",children:b?u.jsxs(u.Fragment,{children:[u.jsx("button",{onClick:Xe,disabled:U,className:"p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] rounded transition-colors disabled:opacity-50",title:n("chatMessage.saveChanges"),children:u.jsx(Mn,{className:"h-3 w-3 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"})}),u.jsx("button",{onClick:w0,disabled:U,className:"p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(239,68,68,0.15)] rounded transition-colors disabled:opacity-50",title:n("chatMessage.cancelEditing"),children:u.jsx(f0,{className:"h-3 w-3 text-red-600 dark:text-red-400 ophelia:text-[#f87171]"})})]}):u.jsx("button",{onClick:He,className:"p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] rounded transition-colors",title:n("chatMessage.editSystemMessage"),children:u.jsx(Nn,{className:"h-3 w-3 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] ophelia:hover:text-[#c084fc]"})})})]}),b?u.jsx("textarea",{value:k,onChange:se=>C(se.target.value),className:"w-full min-h-[100px] p-3 text-sm text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] bg-gray-50 dark:bg-dark-50 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-400 ophelia:focus:ring-[#a855f7] focus:border-transparent",placeholder:n("chatMessage.systemMessagePlaceholder"),disabled:U}):u.jsxs("div",{children:[u.jsx("p",{className:"whitespace-pre-wrap leading-relaxed text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:F?r.content:Ne(r.content)}),Se&&u.jsx("button",{onClick:()=>q(!F),className:"mt-1 flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#737373] hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#c084fc] transition-colors",children:F?u.jsxs(u.Fragment,{children:[u.jsx(Ur,{className:"h-3 w-3"}),n("chatMessage.showLess")]}):u.jsxs(u.Fragment,{children:[u.jsx(D0,{className:"h-3 w-3"}),n("chatMessage.showMore")]})})]})]}):u.jsxs("div",{className:"relative",children:[L&&u.jsxs("div",{className:"mb-3",children:[u.jsxs("button",{onClick:()=>Q(!V),className:"flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#c084fc] transition-colors",children:[u.jsx(mt,{className:"h-4 w-4"}),u.jsx("span",{className:"font-medium",children:n("chatMessage.thinking")}),V?u.jsx(Ur,{className:"h-4 w-4"}):u.jsx(D0,{className:"h-4 w-4"})]}),V&&u.jsx("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#0a0a0a] rounded-lg border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:u.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] whitespace-pre-wrap leading-relaxed",children:L})})]}),u.jsx(ko,{content:O}),e&&u.jsx("div",{className:"inline-block w-2 h-5 bg-primary-500 animate-pulse ml-1 rounded-sm"})]}),!l&&!c&&N.length>0&&u.jsx("div",{className:"mt-4",children:u.jsx(Pn,{artifacts:N})}),!l&&!c&&r.statistics&&u.jsx("div",{className:"mt-3",children:u.jsx(So,{statistics:r.statistics})})]})]})]}),B&&hr.createPortal(u.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>z(null),children:[u.jsx("button",{className:"absolute top-6 right-6 p-3 bg-white/20 hover:bg-white/40 rounded-full text-white transition-all shadow-lg border border-white/30",onClick:se=>{se.stopPropagation(),z(null)},children:u.jsx(f0,{className:"h-7 w-7"})}),u.jsx("img",{src:B,alt:n("chatMessage.fullSizeImage"),className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:se=>se.stopPropagation()})]}),document.body)]})},Io=({messages:r,isStreaming:e=!1,streamingMessage:t,streamingMessageId:a,isLastAssistantMessage:s=!1,onRegenerate:n,onSelectBranch:l,className:c})=>{if(r.length===1){const d=r[0],p=e&&a===d.id,f=p&&t?{...d,content:t}:d;return u.jsx(dr,{message:f,isStreaming:p,isLastAssistantMessage:s,onRegenerate:n,className:c})}return u.jsxs("div",{className:Y("relative py-1",c),children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-4 pb-2 text-[10px] text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:[u.jsx(Tn,{className:"h-3 w-3"}),u.jsxs("span",{children:[r.length," variants"]})]}),u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 px-4",children:r.map((d,p)=>{const f=d.isActive!==!1,x=e&&a===d.id,y=x&&t?{...d,content:t}:d;return u.jsxs("div",{className:Y("relative rounded-lg overflow-hidden transition-all duration-200","border shadow-sm",f||x?"border-primary-300 dark:border-primary-600 ophelia:border-[#7c3aed] shadow-primary-100 dark:shadow-primary-900/20 ophelia:shadow-[#9333ea]/10":"border-gray-200 dark:border-dark-300 ophelia:border-[#262626] hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]",!f&&!x&&"cursor-pointer hover:shadow-md"),onClick:()=>!f&&!x&&l?.(d.id),children:[u.jsxs("div",{className:Y("flex items-center justify-between px-2.5 py-1 text-[11px]",f||x?"bg-primary-50/80 dark:bg-primary-900/20 ophelia:bg-[#9333ea]/10 text-primary-600 dark:text-primary-400 ophelia:text-[#c084fc]":"bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#121212]/80 text-gray-500 dark:text-gray-500 ophelia:text-[#737373]"),children:[u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"font-medium",children:p+1}),x&&u.jsx("span",{className:"text-[10px] opacity-70 animate-pulse",children:"generating..."})]}),f&&!x&&u.jsx(yt,{className:"h-3 w-3"}),!f&&!x&&u.jsx("span",{className:"text-[10px] opacity-50",children:"select"})]}),u.jsx("div",{className:Y("bg-white dark:bg-dark-50 ophelia:bg-[#0a0a0a]",!f&&!x&&"opacity-80"),children:u.jsx(dr,{message:y,isStreaming:x,isLastAssistantMessage:s&&(f||x),onRegenerate:f&&!e?n:void 0,className:"!bg-transparent !p-3 !text-sm"})})]},d.id)})})]})},Eo=({messages:r,streamingMessage:e,streamingMessageId:t,isStreaming:a=!1,className:s,onRegenerate:n,onSelectBranch:l})=>{const{t:c}=b0(),d=A.useRef(null),p=A.useRef(),f=A.useRef(null),x=A.useRef(!1),[y,b]=A.useState(!1),S=A.useMemo(()=>{const R=[],O=new Set;console.log("[ChatMessages] Grouping messages:",r.map(F=>({id:F.id?.substring(0,8),role:F.role,parentId:F.parentId?.substring(0,8),branchIndex:F.branchIndex,isActive:F.isActive})));const X=[...r].sort((F,q)=>F.role==="system"&&q.role!=="system"?-1:q.role==="system"&&F.role!=="system"?1:F.parentId===q.parentId?(F.branchIndex||0)-(q.branchIndex||0):F.timestamp-q.timestamp);for(const F of X){if(O.has(F.id))continue;const q=F.parentId;if(q){const N=R.findIndex(j=>j.id===q);if(N>=0)R[N].messages.push(F);else{const j=r.find(L=>L.id===q);j&&!O.has(q)?(R.push({id:q,messages:[j,F],messageIndex:R.length}),O.add(q)):R.push({id:F.id,messages:[F],messageIndex:R.length})}O.add(F.id)}else{const N=r.filter(j=>j.parentId===F.id);N.length>0?(R.push({id:F.id,messages:[F,...N],messageIndex:R.length}),O.add(F.id),N.forEach(j=>O.add(j.id))):(R.push({id:F.id,messages:[F],messageIndex:R.length}),O.add(F.id))}}return R.sort((F,q)=>{const N=F.messages[0],j=q.messages[0];return N.role==="system"&&j.role!=="system"?-1:j.role==="system"&&N.role!=="system"?1:N.timestamp-j.timestamp})},[r]),k=A.useCallback((R=!1)=>{x.current&&!R||d.current?.scrollIntoView({behavior:"smooth"})},[]),C=A.useCallback(()=>{const R=f.current;if(!R)return;const{scrollTop:O,scrollHeight:X,clientHeight:F}=R,N=X-O-F<100;x.current=!N,b(!N&&r.length>0)},[r.length]),B=A.useRef(r.length);if(A.useEffect(()=>{r.length>B.current&&!x.current&&k(),B.current=r.length},[r.length,k]),A.useEffect(()=>{a&&e&&!x.current&&requestAnimationFrame(()=>{const R=f.current;R&&(R.scrollTop=R.scrollHeight)})},[a,e]),A.useEffect(()=>{const R=p.current;return()=>{R&&clearTimeout(R)}},[]),r.length===0&&!a)return u.jsx("div",{className:Y("flex-1 flex items-center justify-center p-4 sm:p-8",s),children:u.jsxs("div",{className:"text-center text-gray-500 dark:text-dark-600 max-w-md",children:[u.jsx("div",{className:"text-5xl sm:text-7xl mb-4 sm:mb-6 opacity-60",children:"💬"}),u.jsx("h3",{className:"text-lg sm:text-xl font-semibold mb-2 sm:mb-3 text-gray-700 dark:text-dark-700",children:c("chatMessage.startConversation")}),u.jsx("p",{className:"text-sm leading-relaxed px-4",children:c("chatMessage.startConversationDescription")})]})});let z=-1;for(let R=S.length-1;R>=0;R--)if(S[R].messages.some(O=>O.role==="assistant")){z=R;break}const U=()=>{x.current=!1,d.current?.scrollIntoView({behavior:"smooth"}),b(!1)};return u.jsxs("div",{ref:f,onScroll:C,className:Y("relative flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600","scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500","overscroll-behavior-y-contain","[-webkit-overflow-scrolling:touch]",s),style:{WebkitOverflowScrolling:"touch",overscrollBehaviorY:"contain",WebkitAppRegion:"no-drag"},children:[u.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full min-w-0",children:[S.map((R,O)=>{const X=O===z,F=a&&R.messages.some(q=>q.id===t);if(R.messages.length===1){const q=R.messages[0],N=a&&q.id===t,j=N&&e?{...q,content:e}:q;return u.jsx(dr,{message:j,isStreaming:N,isLastAssistantMessage:X,onRegenerate:X?n:void 0,className:O===0?"mt-3 sm:mt-4 md:mt-6":""},q.id)}return u.jsx(Io,{messages:R.messages,isStreaming:F,streamingMessage:e,streamingMessageId:t||void 0,isLastAssistantMessage:X,onRegenerate:X?n:void 0,onSelectBranch:l,className:O===0?"mt-3 sm:mt-4 md:mt-6":""},R.id)}),u.jsx("div",{ref:d,className:"h-3 sm:h-4 md:h-6"})]}),y&&u.jsxs("button",{onClick:U,className:Y("absolute bottom-4 left-1/2 -translate-x-1/2 z-10","flex items-center justify-center gap-1.5","px-3 py-2 rounded-full","bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95","border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60","shadow-lg backdrop-blur-sm","text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]","hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]","hover:text-gray-900 dark:hover:text-dark-800 ophelia:hover:text-[#fafafa]","transition-all duration-200","hover:shadow-xl hover:scale-105 active:scale-95"),title:c("chatMessage.scrollToBottom"),children:[u.jsx(zn,{className:"h-4 w-4"}),u.jsx("span",{className:"text-xs font-medium",children:c("chatMessage.newMessages")})]})]})};function qo(r){const e=(r.match(/```/g)||[]).length,t=e%2===1;let a=null;if(t){const s=r.lastIndexOf("```");if(s!==-1){const l=r.slice(s+3).match(/^(\w+)/);l&&(a=l[1])}}return{hasCodeBlocks:e>0,isInCodeBlock:t,language:a}}const Er=Jt.forwardRef(({value:r,onChange:e,className:t,placeholder:a,disabled:s,onKeyDown:n,...l},c)=>{const{hasCodeBlocks:d,isInCodeBlock:p,language:f}=A.useMemo(()=>qo(r),[r]);return u.jsxs("div",{className:"relative w-full",children:[u.jsx("textarea",{ref:c,value:r,onChange:e,onKeyDown:n,placeholder:a,disabled:s,className:Y("w-full resize-none transition-all duration-200",p&&["font-mono text-[13px]","bg-gray-50 dark:bg-dark-100/50 ophelia:bg-[#0f0f0f]","rounded-lg"],t),...l}),d&&u.jsx("div",{className:"absolute right-0 top-0 pointer-events-none flex items-center gap-1",children:u.jsxs("div",{className:Y("flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]","border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/50",p&&"animate-pulse"),children:[u.jsx(An,{className:"h-3 w-3"}),f&&u.jsx("span",{children:f}),!f&&p&&u.jsx("span",{children:"code"})]})})]})});Er.displayName="CodeAwareTextarea";const Ro=({images:r,onImagesChange:e,maxImages:t=5,sessionId:a,onDocumentUploaded:s,disabled:n=!1,className:l})=>{const{t:c}=b0(),d=A.useRef(null),[p,f]=A.useState(!1),[x,y]=A.useState(!1),[b,S]=A.useState([]),k=async N=>{if(!(!N||n))for(let j=0;j<N.length;j++){const L=N[j];L.type.startsWith("image/")?await C(L):L.type.includes("pdf")||L.type.includes("text")?await B(L):ue.error(`File type not supported: ${L.name}`)}},C=async N=>{if(t-r.length<=0){ue.error(`Maximum ${t} images allowed`);return}if(N.size>10*1024*1024){ue.error(`Image ${N.name} is too large (max 10MB)`);return}const L=new FileReader;L.onload=H=>{H.target?.result&&e([...r,H.target.result])},L.readAsDataURL(N)},B=async N=>{if(N.size>10*1024*1024){ue.error("File size must be less than 10MB");return}y(!0);try{const j=await Qt.uploadDocument(N,a);if(j.success&&j.data){const L=j.data;S(H=>[...H,L]),s?.(L),ue.success(`Document "${N.name}" uploaded`)}else ue.error(j.error||"Failed to upload document")}catch(j){console.error("Document upload error:",j),ue.error("Failed to upload document")}finally{y(!1)}},z=N=>{N.preventDefault(),n||f(!0)},U=N=>{N.preventDefault(),f(!1)},R=N=>{N.preventDefault(),f(!1),n||k(N.dataTransfer.files)},O=N=>{const j=r.filter((L,H)=>H!==N);e(j)},X=async N=>{try{const j=await Qt.deleteDocument(N);j.success?(S(L=>L.filter(H=>H.id!==N)),ue.success("Document removed")):ue.error(j.error||"Failed to remove document")}catch(j){console.error("Error removing document:",j),ue.error("Failed to remove document")}},F=N=>{if(N===0)return"0 B";const j=1024,L=["B","KB","MB","GB"],H=Math.floor(Math.log(N)/Math.log(j));return parseFloat((N/Math.pow(j,H)).toFixed(1))+" "+L[H]},q=r.length>0||b.length>0;return u.jsxs("div",{className:Y("space-y-3",l),children:[u.jsxs("div",{className:Y("border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer","border-gray-300 dark:border-gray-600 ophelia:border-[#3f3f46]","hover:border-primary-400 dark:hover:border-primary-500 ophelia:hover:border-[#9333ea]",p&&"border-primary-500 dark:border-primary-400 ophelia:border-[#a855f7] bg-primary-50/50 dark:bg-primary-900/10 ophelia:bg-[#9333ea]/10",n&&"opacity-50 cursor-not-allowed"),onDragOver:z,onDragLeave:U,onDrop:R,onClick:()=>!n&&d.current?.click(),children:[u.jsx("input",{ref:d,type:"file",multiple:!0,accept:"image/*,.pdf,.txt",onChange:N=>{k(N.target.files),N.target.value=""},className:"hidden",disabled:n}),u.jsxs("div",{className:"flex flex-col items-center text-center",children:[x?u.jsx(Ha,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 ophelia:text-[#737373] mb-2 animate-spin"}):u.jsx(Ua,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 ophelia:text-[#737373] mb-2"}),u.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 ophelia:text-[#d4d4d4]",children:[c("chat.mediaUpload.dropImagesHere")," ",u.jsx("span",{className:"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] font-medium",children:c("chat.mediaUpload.browse")})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mt-1",children:c("chat.mediaUpload.supportedFormats")})]})]}),q&&u.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.map((N,j)=>u.jsxs("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 ophelia:bg-[#1a1a1a] border border-gray-200 dark:border-gray-700 ophelia:border-[#262626]",children:[u.jsx("img",{src:N,alt:`Upload ${j+1}`,className:"w-full h-full object-cover"}),u.jsx("button",{onClick:L=>{L.stopPropagation(),O(j)},className:"absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity",children:u.jsx(f0,{className:"h-3 w-3"})})]},`img-${j}`)),b.map(N=>u.jsxs("div",{className:"relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 ophelia:bg-[#1a1a1a] border border-gray-200 dark:border-gray-700 ophelia:border-[#262626]",children:[N.fileType==="pdf"?u.jsx(Va,{className:"w-4 h-4 text-red-500 flex-shrink-0"}):u.jsx(jn,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),u.jsxs("div",{className:"min-w-0",children:[u.jsx("p",{className:"text-xs font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate max-w-[100px]",children:N.filename}),u.jsx("p",{className:"text-[10px] text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:F(N.size)})]}),u.jsx("button",{onClick:j=>{j.stopPropagation(),X(N.id)},className:"p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 ophelia:hover:bg-[#262626] text-gray-500 hover:text-red-500 transition-colors",children:u.jsx(f0,{className:"h-3 w-3"})})]},N.id))]})]})},Po=({sessionId:r,className:e=""})=>{const[t,a]=A.useState([]);if(A.useEffect(()=>{if(!r)return;(async()=>{try{const c=await Qt.getDocuments(r);c.success&&c.data&&a(c.data)}catch(c){console.error("Failed to load documents:",c)}})()},[r]),!r||t.length===0)return null;const s=t.reduce((l,c)=>l+c.size,0),n=l=>{if(l===0)return"0 B";const c=1024,d=["B","KB","MB","GB"],p=Math.floor(Math.log(l)/Math.log(c));return parseFloat((l/Math.pow(c,p)).toFixed(1))+" "+d[p]};return u.jsxs("div",{className:`
|
|
@@ -278,4 +278,4 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
278
278
|
"field2": { "type": "number" }
|
|
279
279
|
},
|
|
280
280
|
"required": ["field1"]
|
|
281
|
-
}`,rows:8,className:"font-mono text-sm"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(r0,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),u.jsx(r0,{onClick:()=>{n(!1),c("")},variant:"outline",size:"sm",children:a("chat.structuredOutput.cancel")})]})]}),y(),r&&u.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[u.jsx(Va,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},bt=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:c=!1,onModelsRefresh:d})=>{const{t:p}=b0(),[f,x]=A.useState(!1),[y,b]=A.useState(""),[S,k]=A.useState("installed"),C=A.useRef(null),B=A.useRef(null),z=Ra(),[U,R]=A.useState([]),[O,X]=A.useState(!1),[F,q]=A.useState("all"),[N,j]=A.useState(""),[L,H]=A.useState([]),[V,Q]=A.useState(!1),[W,te]=A.useState("text-generation"),[le,be]=A.useState("downloads"),[ke,Ae]=A.useState(""),[re,ee]=A.useState(null),[he,He]=A.useState({}),[Xe,w0]=A.useState(null),[Ne,Se]=A.useState(null),[se,oe]=A.useState(null),[Te,Ve]=A.useState(null),u0=["all","popular","chat","code","vision","embedding"],E0=[{type:"personas",label:"Personas",icon:u.jsx(_t,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>T.isPersona),color:"purple"},{type:"ollama",label:"Ollama Models",icon:u.jsx(Dt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>!T.isPersona&&!T.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:u.jsx(A0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>T.isPlugin),color:"green"}].filter(T=>T.models.length>0).map(T=>({...T,models:T.models.filter(_=>_.name.toLowerCase().includes(y.toLowerCase())||_.personaName&&_.personaName.toLowerCase().includes(y.toLowerCase())||_.pluginName&&_.pluginName.toLowerCase().includes(y.toLowerCase()))})).filter(T=>T.models.length>0),q0=U.filter(T=>{const _=!y||T.name.toLowerCase().includes(y.toLowerCase())||T.description.toLowerCase().includes(y.toLowerCase()),ge=F==="all"||T.category===F;return _&&ge}),Re=r.find(T=>T.name===e||e.startsWith("persona:")&&T.name===e),c0=A.useCallback(async()=>{X(!0);try{const T=await Ct.getLibraryModels({search:N||void 0,sort:"popular"});T.success&&T.data&&R(T.data)}catch(T){console.error("Failed to load library:",T)}finally{X(!1)}},[N]),d0=A.useCallback(async()=>{Q(!0);try{const T=await Hr.getModels({task:W,search:ke||void 0,sort:le,limit:30});T.success&&T.data&&H(T.data)}catch(T){console.error("Failed to load HuggingFace models:",T)}finally{Q(!1)}},[W,ke,le]),qr=A.useCallback(async T=>{const[_,ge]=T.split("/");if(!(!_||!ge)){w0(T);try{const Fe=await Hr.getGgufFiles(_,ge);Fe.success&&Fe.data&&He(je=>({...je,[T]:Fe.data}))}catch(Fe){console.error("Failed to load GGUF files:",Fe)}finally{w0(null)}}},[]),Qs=A.useCallback(T=>{re===T?ee(null):(ee(T),he[T]||qr(T))},[re,he,qr]),_s=A.useCallback((T,_)=>{if(!Ne){Se(T),oe({status:"starting"});try{const ge=Ct.pullModelStream(T,Fe=>{oe(Fe)},()=>{oe(null),Se(null),Ve(null),ue.success(`Downloaded ${_}`),d?.()},Fe=>{oe(null),Se(null),Ve(null),ue.error(`Failed to download: ${Fe}`)});Ve(()=>ge)}catch{oe(null),Se(null),ue.error("Failed to start download")}}},[Ne,d]);A.useEffect(()=>{const T=setTimeout(()=>{S==="huggingface"?Ae(y):S==="ollama"&&j(y)},300);return()=>clearTimeout(T)},[y,S]),A.useEffect(()=>{f&&S==="ollama"&&c0()},[f,S,N,c0]),A.useEffect(()=>{f&&S==="huggingface"&&d0()},[f,S,W,ke,le,d0]),A.useEffect(()=>{const T=_=>{C.current&&!C.current.contains(_.target)&&(x(!1),b(""))};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),A.useEffect(()=>{f&&B.current&&B.current.focus()},[f]);const Rr=T=>{t({target:{value:T}}),x(!1),b("")},en=async T=>{if(!Ne){Se(T),oe({status:"starting"});try{const _=Ct.pullModelStream(T,ge=>{oe(ge)},()=>{oe(null),Se(null),Ve(null),ue.success(`Downloaded ${T}`),d?.()},ge=>{oe(null),Se(null),Ve(null),ue.error(`Failed to download: ${ge}`)});Ve(()=>_)}catch{oe(null),Se(null),ue.error("Failed to start download")}}},Pr=()=>{Te&&(Te(),Ve(null),Se(null),oe(null),ue.success("Download cancelled"))},tn=T=>r.some(_=>_.name===T||_.name.startsWith(T+":")),At=T=>T.isPersona?u.jsx(_t,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):T.isPlugin?u.jsx(A0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):u.jsx(Dt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),R0=T=>T.isPersona?T.personaName||T.name:T.isPlugin?`${T.name}`:T.name,jt=T=>T.isPersona?`via ${T.model}`:T.isPlugin?`via ${T.pluginName}`:null,Or=T=>T>=1e6?`${(T/1e6).toFixed(1)}M`:T>=1e3?`${(T/1e3).toFixed(1)}K`:T.toString(),rn=()=>{if(!Re)return l?u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx(Dt,{className:"h-4 w-4"}),u.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:"Select Model"})]}):"Select Model";if(l){const ge=R0(Re);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[At(Re),u.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:ge})]})}const T=R0(Re),_=jt(Re);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[At(Re),u.jsxs("div",{className:"flex flex-col min-w-0",children:[u.jsx("span",{className:"text-sm font-medium truncate",children:T}),_&&u.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:_})]}),Re.isPersona&&a&&u.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[u.jsx(mt,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&u.jsx(Wa,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})},an=()=>u.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400",children:[E0.length>0?E0.map(T=>u.jsxs("div",{children:[u.jsx("div",{className:"px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a] border-b border-gray-200 dark:border-dark-400 ophelia:border-[#1a1a1a] sticky top-0",children:u.jsxs("div",{className:"flex items-center gap-2",children:[T.icon,T.label," (",T.models.length,")"]})}),T.models.map(_=>u.jsx("div",{onMouseDown:ge=>{ge.preventDefault(),Rr(_.name)},className:Y("px-3 py-3 cursor-pointer border-b border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] last:border-b-0","hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] transition-colors",e===_.name&&"bg-primary-50 dark:bg-primary-900/30 ophelia:bg-[rgba(147,51,234,0.15)]"),children:u.jsxs("div",{className:"flex items-center gap-3",children:[At(_),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:R0(_)}),jt(_)&&u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:jt(_)})]}),e===_.name&&u.jsx(yt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},_.name))]},T.type)):u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(In,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),u.jsx("p",{className:"text-sm",children:"No models found"})]}),c&&u.jsxs("div",{className:"border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsx("div",{className:"px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a]",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(mr,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),"Actions"]})}),u.jsx("div",{onMouseDown:T=>{T.preventDefault(),x(!1),z("/gallery")},className:"px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 ophelia:hover:bg-[rgba(147,51,234,0.1)] bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(Xa,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:p("gallery.generate")}),u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:p("gallery.generateDescription")})]})]})})]})]}),sn=()=>u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[u.jsx("div",{className:"px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0",children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:u0.map(T=>u.jsx("button",{onMouseDown:_=>{_.preventDefault(),_.stopPropagation(),q(T)},className:Y("px-2.5 py-1 rounded-full text-xs font-medium transition-colors",F===T?"bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]":"bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]"),children:T.charAt(0).toUpperCase()+T.slice(1)},T))})}),u.jsx("div",{className:"flex-1 overflow-y-auto",children:O?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ft,{className:"h-6 w-6 animate-spin text-gray-400"})}):q0.length===0?u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(Bt,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:"No models found"})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:q0.slice(0,50).map(T=>{const _=tn(T.name),ge=Ne===T.name;return u.jsxs("div",{className:Y("px-3 py-3 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",_&&"bg-green-50/50 dark:bg-green-900/10"),children:[u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("div",{className:"p-2 rounded-lg bg-cyan-100 dark:bg-cyan-900/30 ophelia:bg-[#06b6d4]/20 flex-shrink-0",children:u.jsx(Bt,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-400"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:T.name}),_&&u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:"Installed"})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] line-clamp-1 mt-0.5",children:T.description}),u.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[T.sizes.slice(0,3).map(Fe=>u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:Fe},Fe)),T.pulls&&u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1",children:[u.jsx(J0,{className:"h-3 w-3"}),T.pulls]})]})]}),u.jsx("div",{className:"flex-shrink-0",children:ge?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:se?.percent!==void 0?`${se.percent}%`:"..."}),u.jsx("button",{onClick:Pr,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(f0,{className:"h-4 w-4"})})]}):_?u.jsx("button",{onClick:()=>Rr(T.name),className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50",children:"Use"}):u.jsxs("button",{onClick:()=>en(T.name),className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7] hover:bg-primary-200 dark:hover:bg-primary-900/50",children:[u.jsx(J0,{className:"h-3 w-3 inline mr-1"}),"Pull"]})})]}),ge&&se?.percent!==void 0&&u.jsx("div",{className:"mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden",children:u.jsx("div",{className:"h-1.5 rounded-full bg-primary-500 transition-all duration-300",style:{width:`${se.percent}%`}})})]},T.name)})})}),u.jsxs("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0",children:[u.jsxs("a",{href:"https://ollama.com/library",target:"_blank",rel:"noopener noreferrer",onMouseDown:T=>T.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(It,{className:"h-3 w-3"}),p("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),R([]),c0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(er,{className:Y("h-3.5 w-3.5 text-gray-400",O&&"animate-spin")})})]})]}),nn=()=>u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[u.jsx("div",{className:"px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0 space-y-2",children:u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("select",{value:W,onChange:T=>te(T.target.value),onMouseDown:T=>T.stopPropagation(),className:"flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:[u.jsx("option",{value:"text-generation",children:p("modelManager.huggingface.taskTextGeneration")}),u.jsx("option",{value:"text-to-speech",children:p("modelManager.huggingface.taskTextToSpeech")}),u.jsx("option",{value:"text-to-image",children:p("modelManager.huggingface.taskTextToImage")}),u.jsx("option",{value:"automatic-speech-recognition",children:p("modelManager.huggingface.taskSpeechRecognition")})]}),u.jsxs("select",{value:le,onChange:T=>be(T.target.value),onMouseDown:T=>T.stopPropagation(),className:"px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:[u.jsx("option",{value:"downloads",children:p("modelManager.huggingface.sortDownloads")}),u.jsx("option",{value:"likes",children:p("modelManager.huggingface.sortLikes")}),u.jsx("option",{value:"lastModified",children:p("modelManager.huggingface.sortRecent")})]})]})}),u.jsx("div",{className:"flex-1 overflow-y-auto",children:V?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ft,{className:"h-6 w-6 animate-spin text-gray-400"})}):L.length===0?u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(A0,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:p("modelManager.huggingface.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:L.map(T=>{const _=re===T.id,ge=he[T.id]||[],Fe=Xe===T.id;return u.jsxs("div",{className:"bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:[u.jsx("div",{className:"px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]",onMouseDown:je=>{je.preventDefault(),je.stopPropagation(),Qs(T.id)},children:u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("div",{className:"p-2 rounded-lg bg-yellow-100 dark:bg-yellow-900/30 ophelia:bg-[#eab308]/20 flex-shrink-0",children:u.jsx(A0,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-400"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:T.id}),T.gated&&u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400",children:"Gated"})]}),u.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mt-0.5",children:["by ",T.author]}),u.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500",children:[u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(J0,{className:"h-3 w-3"}),Or(T.downloads)]}),u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(En,{className:"h-3 w-3"}),Or(T.likes)]}),T.pipeline_tag&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]",children:T.pipeline_tag})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u.jsx("a",{href:`https://huggingface.co/${T.id}`,target:"_blank",rel:"noopener noreferrer",onMouseDown:je=>je.stopPropagation(),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(It,{className:"h-4 w-4 text-gray-400"})}),u.jsx(D0,{className:Y("h-4 w-4 text-gray-400 transition-transform",_&&"rotate-180")})]})]})}),_&&u.jsx("div",{className:"px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] bg-gray-50 dark:bg-dark-200 ophelia:bg-[#0d0d0d]",children:Fe?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ft,{className:"h-4 w-4 animate-spin text-gray-400"}),u.jsx("span",{className:"ml-2 text-xs text-gray-500",children:p("modelManager.huggingface.checkingGguf")})]}):ge.length===0?u.jsx("div",{className:"py-4 text-center text-xs text-gray-500 dark:text-gray-400",children:p("modelManager.huggingface.noGgufAvailable")}):u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-xs font-medium text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:p("modelManager.huggingface.ggufFilesCount",{count:ge.length})}),ge.map(je=>{const ln=Ne===je.ollamaCommand;return u.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-xs font-medium text-gray-800 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:je.filename}),u.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:[u.jsx("span",{children:je.sizeFormatted}),je.quantization&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-400 ophelia:text-[#a855f7]",children:je.quantization})]})]}),ln?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:se?.percent!==void 0?`${se.percent}%`:"..."}),u.jsx("button",{onMouseDown:P0=>{P0.preventDefault(),P0.stopPropagation(),Pr()},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(f0,{className:"h-4 w-4"})})]}):u.jsxs("button",{onMouseDown:P0=>{P0.preventDefault(),P0.stopPropagation(),_s(je.ollamaCommand,je.filename)},disabled:!!Ne,className:Y("px-3 py-1.5 rounded-lg text-xs font-medium","bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20","text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]","hover:bg-primary-200 dark:hover:bg-primary-900/50","disabled:opacity-50 disabled:cursor-not-allowed"),children:[u.jsx(J0,{className:"h-3 w-3 inline mr-1"}),p("models.pull")]})]},je.filename)}),Ne?.startsWith("hf.co/")&&Ne.includes(T.id)&&se?.percent!==void 0&&u.jsx("div",{className:"w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2",children:u.jsx("div",{className:"h-1.5 rounded-full bg-primary-500 transition-all duration-300",style:{width:`${se.percent}%`}})})]})})]},T.id)})})}),u.jsxs("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0",children:[u.jsxs("a",{href:"https://huggingface.co/models",target:"_blank",rel:"noopener noreferrer",onMouseDown:T=>T.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(It,{className:"h-3 w-3"}),p("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),d0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(er,{className:Y("h-3.5 w-3.5 text-gray-400",V&&"animate-spin")})})]})]});return u.jsxs("div",{className:Y("relative",s),ref:C,children:[u.jsxs("button",{type:"button",onClick:()=>!n&&x(!f),disabled:n,className:Y(l?"h-[44px] sm:h-[52px] px-3 flex items-center justify-between text-left w-full ":"w-full flex items-center justify-between gap-2 px-3 py-2 text-left ","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","rounded-lg text-sm hover:bg-gray-100 dark:hover:bg-dark-100 ophelia:hover:bg-[#1a1a1a]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20 focus:border-primary-500 ophelia:focus:border-[#9333ea]",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?Re?R0(Re):"Select Model":void 0,children:[rn(),u.jsx(D0,{className:Y(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",f&&"rotate-180")})]}),f&&hr.createPortal(u.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4",children:[u.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>x(!1)}),u.jsxs("div",{className:Y("relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] shadow-2xl","w-full max-w-md sm:w-[480px] sm:max-w-[90vw]","mt-2 sm:mt-0 rounded-xl","h-[85vh] sm:h-[600px] flex flex-col"),onClick:T=>T.stopPropagation(),children:[u.jsxs("div",{className:"flex-shrink-0",children:[u.jsx("div",{className:"p-3 border-b border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:u.jsxs("div",{className:"relative",children:[u.jsx(Bn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),u.jsx("input",{ref:B,type:"text",placeholder:S==="installed"?"Search installed models...":S==="ollama"?"Search Ollama library...":"Search HuggingFace...",value:y,onChange:T=>b(T.target.value),className:Y("w-full pl-10 pr-4 py-2.5 text-sm bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-lg","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#737373]")})]})}),u.jsxs("div",{className:"flex border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("installed")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="installed"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(Fn,{className:"h-4 w-4 inline mr-1.5"}),"Installed"]}),u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("ollama")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="ollama"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(Bt,{className:"h-4 w-4 inline mr-1.5"}),"Ollama"]}),u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("huggingface")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="huggingface"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(A0,{className:"h-4 w-4 inline mr-1.5"}),"HuggingFace"]})]})]}),S==="installed"&&an(),S==="ollama"&&sn(),S==="huggingface"&&nn()]})]}),document.body),u.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(T=>u.jsx("option",{value:T.name,children:R0(T)},T.name))})]})},Ho=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=b0(),[s,n]=A.useState(""),[l,c]=A.useState([]),[d,p]=A.useState(null),[f,x]=A.useState(!1),[y,b]=A.useState(null),[S,k]=A.useState(!1),{isGenerating:C,setBackgroundImage:B}=C0(),{currentSession:z,models:U}=ze(),R=A.useRef(null);A.useEffect(()=>{(async()=>{try{const L=await Oa.getPlugins();k(!!(L.success&&L.data&&L.data.length>0))}catch{k(!1)}})()},[]);const O=j=>{j.preventDefault(),!(!s.trim()||C)&&(r(s.trim(),l.length>0?l:void 0,d||void 0),n(""),c([]))},X=j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),O(j))},F=()=>{e()};A.useEffect(()=>{const j=R.current;j&&(j.style.height="auto",j.style.height=Math.min(j.scrollHeight,200)+"px")},[s]),A.useEffect(()=>{(async()=>{if(z?.personaId)try{const L=await $r.getPersona(z.personaId);if(L.success&&L.data)b(L.data);else{console.warn(`Persona ${z.personaId} not found, clearing reference`),b(null);const{setCurrentSession:H}=ze.getState();H({...z,personaId:void 0})}}catch(L){if(console.error("Failed to load current persona:",L),b(null),z){const{setCurrentSession:H}=ze.getState();H({...z,personaId:void 0})}}else b(null)})()},[z?.personaId]);const q=async j=>{const L=j.target.value;if(z)try{if(L.startsWith("persona:")){const H=L.replace("persona:",""),V=await $r.getPersona(H);if(!V.success||!V.data){Q0.error("Failed to load persona details");return}const Q=V.data,W=await ht.updateSession(z.id,{personaId:H,model:L});if(W.success&&W.data){const{sessions:te}=ze.getState(),le=te.map(be=>be.id===z.id?W.data:be);ze.setState({sessions:le,currentSession:W.data}),Q.background&&B(Q.background),Q0.success(a("chat.persona.applied"))}}else{const H=await ht.updateSession(z.id,{model:L,personaId:void 0});if(H.success&&H.data){const{sessions:V}=ze.getState(),Q=V.map(W=>W.id===z.id?H.data:W);ze.setState({sessions:Q,currentSession:H.data}),B(null),Q0.success(a("chat.model.updated"))}}}catch(H){console.error("Failed to update session:",H),Q0.error("Failed to update session")}},N=l.length>0||d!==null;return u.jsx("div",{className:"pointer-events-none",children:u.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto",children:[f&&u.jsxs("div",{className:"mb-2 p-3 rounded-2xl bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/50 shadow-lg",children:[u.jsx(Ro,{images:l,onImagesChange:c,maxImages:5,sessionId:z?.id,disabled:t}),u.jsx(Lo,{format:d,onFormatChange:p})]}),u.jsxs("div",{className:"py-2 sm:py-3",children:[u.jsx("form",{onSubmit:O,children:u.jsxs("div",{className:Y("flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-300 ease-out shadow-lg","bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md","border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60","hover:border-gray-300/70 dark:hover:border-dark-400/70 ophelia:hover:border-[#3f3f46]/80","focus-within:border-primary-400/70 dark:focus-within:border-primary-500/70 ophelia:focus-within:border-[#9333ea]/70","focus-within:shadow-xl"),children:[u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:()=>x(!f),className:Y("h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0","hover:bg-gray-100 dark:hover:bg-dark-200/80 ophelia:hover:bg-[#1a1a1a]","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95",N&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",f&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:a("chat.input.attachments"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:N?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(Ya,{className:"h-4 w-4"}),u.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 ophelia:bg-[#a855f7] rounded-full ring-2 ring-white dark:ring-dark-50 ophelia:ring-[#0a0a0a]"})]}):f?u.jsx(Ka,{className:"h-4 w-4"}):u.jsx(mr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Er,{ref:R,value:s,onChange:j=>n(j.target.value),onKeyDown:X,placeholder:a("chat.input.placeholder"),disabled:t,className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),u.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[z&&U.length>0&&u.jsx("div",{className:"hidden sm:block",children:u.jsx(bt,{models:U,selectedModel:z.personaId?`persona:${z.personaId}`:z.model,onModelChange:q,currentPersona:y,className:"min-w-[160px] max-w-[240px] border-0 bg-gray-100/80 dark:bg-dark-100/80 ophelia:bg-[#1a1a1a]/80 rounded-xl text-sm hover:bg-gray-200/80 dark:hover:bg-dark-200/60 ophelia:hover:bg-[#262626]/80 transition-colors duration-200",compact:!0,showImageGen:S})}),C?u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:F,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","bg-red-50 dark:bg-red-900/20 ophelia:bg-red-900/30","text-red-500 dark:text-red-400 ophelia:text-red-400","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/40","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95"),title:a("chat.input.stopGeneration"),children:u.jsx($a,{className:"h-4 w-4"})}):u.jsx(r0,{type:"submit",variant:"ghost",size:"sm",disabled:!s.trim()||t,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","text-gray-400 dark:text-dark-500 ophelia:text-[#525252]","disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed","transition-all duration-200 touch-manipulation",s.trim()&&!t&&["bg-primary-500 dark:bg-primary-600 ophelia:bg-[#9333ea]","text-white dark:text-white ophelia:text-white","hover:bg-primary-600 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","shadow-md hover:shadow-lg","hover:scale-105 active:scale-95"]),title:a("chat.input.sendMessage"),children:u.jsx(Za,{className:"h-4 w-4"})})]})]})}),z&&U.length>0&&u.jsx("div",{className:"sm:hidden mt-3",children:u.jsx(bt,{models:U,selectedModel:z.personaId?`persona:${z.personaId}`:z.model,onModelChange:q,currentPersona:y,className:"w-full rounded-xl bg-gray-100/80 dark:bg-dark-100/80 ophelia:bg-[#1a1a1a]/80 border-0 transition-colors duration-200",compact:!0,showImageGen:S})}),u.jsxs("div",{className:"mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600",children:[u.jsx(Po,{sessionId:z?.id}),u.jsxs("div",{className:"text-center",children:[u.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors",style:{fontSize:"1.1em",lineHeight:1},children:"Libre WebUI"})," ",u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.6.1"]})," ",u.jsx("span",{className:"text-gray-300 dark:text-gray-600 opacity-50",children:"•"})," ",u.jsx("span",{className:"text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:a("chat.footer.disclaimer")}),N&&u.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",l.length>0&&a("chat.footer.images",{count:l.length}),l.length>0&&d&&" • ",d&&a("chat.footer.structuredOutput")]})]})]})]})]})})},$o=({persona:r,onClear:e,className:t})=>{const[a,s]=A.useState(!1),n=A.useRef(null),[l,c]=A.useState({top:0,left:0});A.useEffect(()=>{if(a&&n.current){const f=n.current.getBoundingClientRect();c({top:f.bottom+8,left:f.left})}},[a]);const d=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),p=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=64`;return u.jsxs("div",{className:Y("relative",t),children:[u.jsxs("button",{ref:n,onClick:()=>s(!a),className:Y("flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200","bg-primary-50 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/15","border border-primary-200 dark:border-primary-700/50 ophelia:border-[#7c3aed]/30","hover:bg-primary-100 dark:hover:bg-primary-900/40 ophelia:hover:bg-[#9333ea]/20","text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc]"),children:[u.jsx("img",{src:p(),alt:r.name,className:"w-5 h-5 rounded-full object-cover"}),u.jsx("span",{className:"text-sm font-medium max-w-[120px] truncate",children:r.name}),d&&u.jsx(Wa,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),u.jsx(D0,{className:Y("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&hr.createPortal(u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>s(!1)}),u.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:u.jsxs("div",{className:Y("rounded-xl overflow-hidden shadow-xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]"),children:[u.jsxs("div",{className:"relative h-16",children:[r.background?u.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):u.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800 ophelia:from-[#9333ea] ophelia:via-[#7c3aed] ophelia:to-[#6d28d9]"}),u.jsx("div",{className:"absolute inset-0 bg-black/10"}),e&&u.jsx("button",{onClick:f=>{f.stopPropagation(),e(),s(!1)},className:"absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors",title:"Remove persona",children:u.jsx(f0,{className:"h-3.5 w-3.5 text-white"})}),d&&u.jsxs("div",{className:"absolute top-2 left-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium",children:[u.jsx(mt,{className:"h-3 w-3"}),"Enhanced"]})]}),u.jsx("div",{className:"relative px-4 -mt-6",children:u.jsx("img",{src:p(),alt:r.name,className:"w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-md"})}),u.jsxs("div",{className:"px-4 pt-2 pb-4",children:[u.jsx("h4",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.name}),u.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1 mt-0.5",children:[u.jsx(qn,{className:"h-3 w-3"}),r.model]}),r.description&&u.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] mt-2 line-clamp-2",children:r.description}),r.parameters.system_prompt&&u.jsxs("div",{className:"mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:[u.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[u.jsx(Rn,{className:"h-2.5 w-2.5 text-gray-400"}),u.jsx("span",{className:"text-[9px] uppercase tracking-wider font-medium text-gray-400",children:"System"})]}),u.jsxs("p",{className:"text-[11px] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),u.jsxs("div",{className:"flex flex-wrap gap-1 mt-3",children:[u.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[u.jsx(A0,{className:"h-2.5 w-2.5"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),u.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:["Top-P ",r.parameters.top_p?.toFixed(1)||"0.9"]}),r.memory_settings?.enabled&&u.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-300 ophelia:text-[#c084fc]",children:[u.jsx(mt,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},Go=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const s=A.useRef(null),[n,l]=A.useState(!1),c=b=>{if(!b)return;const S=[],k=t-r.length;for(let C=0;C<Math.min(b.length,k);C++){const B=b[C];if(!B.type.startsWith("image/")){ue.error(`File ${B.name} is not an image`);continue}if(B.size>10*1024*1024){ue.error(`Image ${B.name} is too large (max 10MB)`);continue}const z=new FileReader;z.onload=U=>{U.target?.result&&(S.push(U.target.result),S.length===Math.min(b.length,k)&&e([...r,...S]))},z.readAsDataURL(B)}b.length>k&&ue.error(`Only ${k} more images can be added`)},d=b=>{b.preventDefault(),l(!0)},p=b=>{b.preventDefault(),l(!1)},f=b=>{b.preventDefault(),l(!1),c(b.dataTransfer.files)},x=b=>{const S=r.filter((k,C)=>C!==b);e(S)},y=r.length<t;return u.jsxs("div",{className:Y("space-y-3",a),children:[y&&u.jsxs("div",{className:Y("border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors","hover:border-primary-400 dark:hover:border-primary-500",n&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:d,onDragLeave:p,onDrop:f,children:[u.jsx("input",{ref:s,type:"file",multiple:!0,accept:"image/*",onChange:b=>c(b.target.files),className:"hidden"}),u.jsxs("div",{className:"flex flex-col items-center text-center",children:[u.jsx(Ua,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 mb-2"}),u.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:["Drop images here or"," ",u.jsx("button",{onClick:()=>s.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:"browse"})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Supports: JPG, PNG, GIF, WebP (max 10MB each)"})]})]}),r.length>0&&u.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((b,S)=>u.jsxs("div",{className:"relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:[u.jsx("img",{src:b,alt:`Upload ${S+1}`,className:"w-full h-full object-cover"}),u.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center",children:u.jsx(r0,{variant:"ghost",size:"sm",onClick:()=>x(S),className:"opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full",children:u.jsx(f0,{className:"h-4 w-4"})})})]},S))}),y&&r.length>0&&u.jsxs(r0,{variant:"outline",size:"sm",onClick:()=>s.current?.click(),className:"w-full sm:w-auto",children:[u.jsx(Xa,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},Uo=r=>{const[e,t]=A.useState(""),[a,s]=A.useState(null),[n,l]=A.useState(!1),{addMessage:c,updateMessage:d,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:x}=ze(),{setIsGenerating:y,preferences:b}=C0(),S=A.useRef(null),k=A.useRef(null),C=A.useRef(""),B=A.useRef(0),z=A.useRef();A.useEffect(()=>()=>{Me.offMessage("user_message"),Me.offMessage("assistant_chunk"),Me.offMessage("assistant_complete"),Me.offMessage("error")},[r]),A.useEffect(()=>{if(!r){Me.offMessage("user_message"),Me.offMessage("assistant_chunk"),Me.offMessage("assistant_complete"),Me.offMessage("error");return}return Me.onMessage("user_message",()=>{}),Me.onMessage("assistant_chunk",q=>{const N=q,j=N.messageId||S.current;j&&(C.current=N.total,t(N.total),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{d(r,j,C.current),B.current=Date.now()},N.done?0:200))}),Me.onMessage("assistant_complete",q=>{const N=q;console.log("Hook: Received assistant_complete for session:",r,"messageId:",N.messageId,"with statistics:",!!N.statistics),l(!1),t(""),y(!1);const j=N.messageId||S.current;if(N&&j){const W=C.current||N.content;p(r,j,W,N.statistics)}const H=C0.getState().preferences.titleSettings,V=ze.getState().currentSession,Q=k.current;console.log("Auto-title check:",{firstMessage:Q,autoTitle:H?.autoTitle,taskModel:H?.taskModel,sessionTitle:V?.title}),Q&&H?.autoTitle&&H?.taskModel&&V?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),x(r),ht.generateTitle(r,H.taskModel,Q).then(W=>{console.log("Title generation response:",W),W.success&&W.data?.title&&f(r,W.data.title)}).catch(W=>{console.error("Failed to generate title:",W)}).finally(()=>{x(null)}),k.current=null),S.current=null,C.current="",z.current&&clearTimeout(z.current),B.current=0}),Me.onMessage("error",q=>{const N=q;if(l(!1),t(""),y(!1),S.current=null,N.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),ue.error("Session not found. Creating a new session..."),window.location.href="/";return}ue.error(N.error)}),l(!1),t(""),S.current=null,()=>{z.current&&clearTimeout(z.current)}},[r,d,p,y,f,x]);const U=A.useCallback(async(F,q,N)=>{if(!(!r||!F.trim()&&(!q||q.length===0)))try{y(!0),l(!0),t(""),z.current&&clearTimeout(z.current),B.current=Date.now();const j=ze.getState().currentSession,L=j?.isPrivate===!0,H=j?.messages?.some(W=>W.role==="user");!L&&!H&&j?.title==="New Chat"&&(k.current=F.trim()),c(r,{role:"user",content:F.trim(),images:q});const V=Gr();S.current=V,s(V),c(r,{role:"assistant",content:"",id:V}),Me.isConnected||await Me.connect();const Q=L?j?.messages?.filter(W=>W.role!=="system"&&W.id!==V).map(W=>({role:W.role,content:W.content,images:W.images})):void 0;Me.send({type:"chat_stream",data:{sessionId:r,content:F.trim(),images:q,format:N,options:b.generationOptions,assistantMessageId:V,isPrivate:L,model:L?j?.model:void 0,messageHistory:Q}})}catch(j){console.error("Failed to send message:",j),l(!1),t(""),s(null),y(!1),S.current=null,ue.error("Failed to send message")}},[r,c,y,b.generationOptions]),R=A.useCallback(()=>{l(!1),t(""),s(null),y(!1),S.current=null},[y]),O=A.useCallback(async()=>{const F=ze.getState().currentSession;if(!F||!r)return;const q=F.messages;let N=-1,j=-1;for(let V=q.length-1;V>=0;V--)if(q[V].role==="assistant"){j=V;break}if(j>0){for(let V=j-1;V>=0;V--)if(q[V].role==="user"){N=V;break}}if(N===-1||j===-1){ue.error("No message to regenerate");return}const L=q[N],H=q[j];try{y(!0),l(!0),t(""),z.current&&clearTimeout(z.current),B.current=Date.now();const V=Gr();S.current=V,s(V),c(r,{role:"assistant",content:"",id:V,parentId:H.parentId||H.id,branchIndex:H.siblingCount||1,isActive:!0}),Me.isConnected||await Me.connect(),Me.send({type:"chat_stream",data:{sessionId:r,content:L.content,images:L.images,options:b.generationOptions,assistantMessageId:V,regenerate:!0,originalMessageId:H.id}})}catch(V){console.error("Failed to regenerate message:",V),l(!1),t(""),y(!1),S.current=null,ue.error("Failed to regenerate message")}},[r,y,c,b.generationOptions]),X=A.useCallback(async F=>{const N=ze.getState().currentSession;if(!N||!r)return;const j=N.messages.find(V=>V.id===F);if(!j){ue.error("Message not found");return}if(j.isActive!==!1)return;const L=j.parentId||j.id,H=j.branchIndex||0;try{const V=await ht.switchMessageBranch(r,F,H);if(V.success&&V.data){const Q=N.messages.map(te=>te.id===L||te.parentId===L?{...te,isActive:te.id===F}:te),W={...N,messages:Q,updatedAt:Date.now()};ze.setState(te=>({sessions:te.sessions.map(le=>le.id===r?W:le),currentSession:W})),ue.success(`Switched to variant ${H+1}`)}else ue.error(V.error||"Failed to select branch")}catch(V){console.error("Failed to select branch:",V),ue.error("Failed to select branch")}},[r]);return{sendMessage:U,stopGeneration:R,regenerateLastMessage:O,selectBranch:X,isStreaming:n,streamingMessage:e,streamingMessageId:a}},Vo=(r,e)=>{const t=new Date().getHours(),a=r?`, ${r}`:"";return t>=5&&t<12?{greeting:`${e?e("chat.greeting.morning"):"Good morning"}${a}`,timeSuffix:"today"}:t>=12&&t<17?{greeting:`${e?e("chat.greeting.afternoon"):"Good afternoon"}${a}`,timeSuffix:"today"}:t>=17&&t<21?{greeting:`${e?e("chat.greeting.evening"):"Good evening"}${a}`,timeSuffix:"tonight"}:{greeting:`${e?e("chat.greeting.night"):"Good night"}${a}`,timeSuffix:"tonight"}},Qo=()=>{const{t:r}=b0(),{sessionId:e}=pn(),t=Ra(),a=fn(),{currentSession:s,sessions:n,models:l,selectedModel:c,setSelectedModel:d,createSession:p,setCurrentSession:f,loadSessions:x,getCurrentPersona:y}=ze(),{user:b}=Pa(),{sendMessage:S,stopGeneration:k,regenerateLastMessage:C,selectBranch:B,isStreaming:z,streamingMessage:U,streamingMessageId:R}=Uo(s?.id||""),O=y(),{greeting:X,timeSuffix:F}=A.useMemo(()=>Vo(b?.username,r),[b?.username,r]),[q,N]=A.useState(""),[j,L]=A.useState([]),[H,V]=A.useState(!1),Q=A.useRef(null),[W,te]=A.useState(!1);A.useEffect(()=>{n.length===0&&x()},[x,n.length]),A.useEffect(()=>{(async()=>{try{const ee=await Oa.getPlugins();te(!!(ee.success&&ee.data&&ee.data.length>0))}catch{te(!1)}})()},[]),A.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const he=n.find(He=>He.id===e);he&&he.id!==s?.id?f(he):he||(console.warn(`Session ${e} not found for current user, redirecting...`),n.length>0?t(`/c/${n[0].id}`,{replace:!0}):t("/",{replace:!0}))}else!e&&n.length>0&&a.pathname==="/"&&t(`/c/${n[0].id}`,{replace:!0})})()},[e,n,f,t,s?.id,s?.isPrivate,a.pathname]),A.useEffect(()=>{if(s?.id){const re=sessionStorage.getItem("pendingMessage");if(re){sessionStorage.removeItem("pendingMessage");try{const ee=JSON.parse(re);setTimeout(()=>{S(ee.content,ee.images)},100)}catch(ee){console.error("Failed to parse pending message:",ee)}}}},[s?.id,S]),A.useEffect(()=>{const re=Q.current;re&&(re.style.height="auto",re.style.height=Math.min(re.scrollHeight,200)+"px")},[q]);const le=async re=>{if(re.preventDefault(),!q.trim()||!c)return;const ee={content:q.trim(),images:j.length>0?j:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(ee)),N(""),L([]);const he=await p(c);he&&t(`/c/${he.id}`,{replace:!0})},be=re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),le(re))},ke=async re=>{const ee=re.target.value;d(ee)},Ae=(re,ee,he)=>{s&&S(re,ee,he)};if(!s){const re=j.length>0;return u.jsxs("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative",children:[u.jsxs("button",{onClick:()=>{if(!c&&l.length===0)return;const ee=Date.now(),he={id:`private-${ee}`,title:r("chat.session.private"),model:c||l[0]?.name||"",messages:[],createdAt:ee,updatedAt:ee,isPrivate:!0};f(he)},disabled:!c&&l.length===0,className:"absolute top-4 right-4 flex items-center gap-2 px-3 py-1.5 rounded-full border border-gray-300 dark:border-dark-400 ophelia:border-[#3f3f46] bg-transparent hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",title:r("chat.session.privateTooltip"),children:[u.jsx(Vr,{className:"h-4 w-4"}),u.jsx("span",{className:"text-sm",children:r("chat.session.private")})]}),u.jsxs("div",{className:"w-full max-w-2xl mx-auto flex flex-col items-center justify-center",children:[u.jsx("h1",{className:"text-2xl sm:text-3xl font-medium text-gray-800 dark:text-gray-100 ophelia:text-[#fafafa] mb-2 text-center",style:{fontWeight:400},children:X}),u.jsx("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:r(F==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?u.jsxs("div",{className:"w-full",children:[H&&u.jsx("div",{className:"mb-4 p-4 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-2xl",children:u.jsx(Go,{images:j,onImagesChange:L,maxImages:5})}),u.jsx("form",{onSubmit:le,children:u.jsxs("div",{className:Y("flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-200","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#0a0a0a] border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]","focus-within:border-primary-400 dark:focus-within:border-primary-500 ophelia:focus-within:border-[#9333ea] focus-within:bg-white dark:focus-within:bg-dark-50 ophelia:focus-within:bg-[#0a0a0a]","shadow-sm hover:shadow-md focus-within:shadow-lg"),children:[u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:()=>V(!H),className:Y("h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0","hover:bg-gray-200 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors touch-manipulation",re&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",H&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:r("chat.input.attachImages"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:re?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(Ya,{className:"h-4 w-4"}),u.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 ophelia:bg-[#9333ea] rounded-full"})]}):H?u.jsx(Ka,{className:"h-4 w-4"}):u.jsx(mr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Er,{ref:Q,value:q,onChange:ee=>N(ee.target.value),onKeyDown:be,placeholder:r("chat.input.messagePlaceholder"),className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 ophelia:scrollbar-thumb-[#3f3f46] focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 ophelia:placeholder:text-[#737373] text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),u.jsx("div",{className:"hidden sm:block",children:u.jsx(bt,{models:l,selectedModel:c,onModelChange:ke,className:"min-w-[140px] max-w-[200px] border-0 bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] rounded-xl text-sm",compact:!0,showImageGen:W})}),u.jsx(r0,{type:"submit",variant:"ghost",size:"sm",disabled:!q.trim()||!c,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","hover:bg-primary-100 dark:hover:bg-primary-900/30 ophelia:hover:bg-[rgba(147,51,234,0.2)] text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]","disabled:text-gray-400 dark:disabled:text-dark-500 ophelia:disabled:text-[#525252] disabled:hover:bg-transparent","transition-all duration-150 touch-manipulation",q.trim()&&c&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:u.jsx(Za,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"sm:hidden mt-4",children:u.jsx(bt,{models:l,selectedModel:c,onModelChange:ke,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:W})}),u.jsxs("div",{className:"mt-4 text-center",children:[u.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#a855f7] transition-colors text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",style:{fontSize:"0.75rem",lineHeight:1},children:"Libre WebUI"})," ",u.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.6.1"]})," ",u.jsx("span",{className:"text-gray-300 dark:text-gray-600 ophelia:text-[#3f3f46] opacity-50",children:"•"})," ",u.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:r("chat.footer.disclaimer")})]})]}):u.jsx("div",{className:"w-full max-w-md",children:u.jsxs("div",{className:"p-6 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-xl",children:[u.jsx("p",{className:"text-sm text-gray-700 dark:text-dark-700 ophelia:text-[#a3a3a3] mb-4",children:r("chat.model.noModelsDescription")}),u.jsx("code",{className:"block text-xs bg-gray-100 dark:bg-dark-200 ophelia:bg-[#0a0a0a] p-3 rounded-lg font-mono text-gray-800 dark:text-dark-600 ophelia:text-[#737373]",children:r("chat.model.pullCommand")})]})})]})]})}return u.jsxs("div",{className:"flex flex-col h-full relative",style:O?.background?{backgroundImage:`url(${O.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[O?.background&&u.jsx("div",{className:"absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm"}),u.jsxs("div",{className:"flex flex-col h-full relative z-10",children:[s?.isPrivate&&u.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#262626] bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#0a0a0a]/80 backdrop-blur-sm",children:u.jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[u.jsx(Vr,{className:"h-4 w-4"}),u.jsx("span",{className:"text-sm font-medium",children:r("chat.session.privateMode")}),u.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-500 ophelia:text-[#737373]",children:["— ",r("chat.session.privateDescription")]})]})}),O&&!s?.isPrivate&&u.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-100 dark:border-dark-200 ophelia:border-[#262626] bg-white/50 dark:bg-dark-100/50 ophelia:bg-[#0a0a0a]/50 backdrop-blur-sm",children:u.jsx($o,{persona:O,onClear:()=>{if(s){const{sessions:re}=ze.getState(),ee={...s,model:O.model,personaId:void 0},he=re.map(He=>He.id===s.id?ee:He);ze.setState({sessions:he,currentSession:ee})}}})}),u.jsx(Eo,{messages:s.messages,streamingMessage:U,streamingMessageId:R,isStreaming:z,onRegenerate:C,onSelectBranch:B,className:"flex-1"}),u.jsx(Ho,{onSendMessage:Ae,onStopGeneration:k,disabled:!s})]})]})};export{Qo as ChatPage,Qo as default};
|
|
281
|
+
}`,rows:8,className:"font-mono text-sm"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(r0,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),u.jsx(r0,{onClick:()=>{n(!1),c("")},variant:"outline",size:"sm",children:a("chat.structuredOutput.cancel")})]})]}),y(),r&&u.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[u.jsx(Va,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},bt=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:c=!1,onModelsRefresh:d})=>{const{t:p}=b0(),[f,x]=A.useState(!1),[y,b]=A.useState(""),[S,k]=A.useState("installed"),C=A.useRef(null),B=A.useRef(null),z=Ra(),[U,R]=A.useState([]),[O,X]=A.useState(!1),[F,q]=A.useState("all"),[N,j]=A.useState(""),[L,H]=A.useState([]),[V,Q]=A.useState(!1),[W,te]=A.useState("text-generation"),[le,be]=A.useState("downloads"),[ke,Ae]=A.useState(""),[re,ee]=A.useState(null),[he,He]=A.useState({}),[Xe,w0]=A.useState(null),[Ne,Se]=A.useState(null),[se,oe]=A.useState(null),[Te,Ve]=A.useState(null),u0=["all","popular","chat","code","vision","embedding"],E0=[{type:"personas",label:"Personas",icon:u.jsx(_t,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>T.isPersona),color:"purple"},{type:"ollama",label:"Ollama Models",icon:u.jsx(Dt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>!T.isPersona&&!T.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:u.jsx(A0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(T=>T.isPlugin),color:"green"}].filter(T=>T.models.length>0).map(T=>({...T,models:T.models.filter(_=>_.name.toLowerCase().includes(y.toLowerCase())||_.personaName&&_.personaName.toLowerCase().includes(y.toLowerCase())||_.pluginName&&_.pluginName.toLowerCase().includes(y.toLowerCase()))})).filter(T=>T.models.length>0),q0=U.filter(T=>{const _=!y||T.name.toLowerCase().includes(y.toLowerCase())||T.description.toLowerCase().includes(y.toLowerCase()),ge=F==="all"||T.category===F;return _&&ge}),Re=r.find(T=>T.name===e||e.startsWith("persona:")&&T.name===e),c0=A.useCallback(async()=>{X(!0);try{const T=await Ct.getLibraryModels({search:N||void 0,sort:"popular"});T.success&&T.data&&R(T.data)}catch(T){console.error("Failed to load library:",T)}finally{X(!1)}},[N]),d0=A.useCallback(async()=>{Q(!0);try{const T=await Hr.getModels({task:W,search:ke||void 0,sort:le,limit:30});T.success&&T.data&&H(T.data)}catch(T){console.error("Failed to load HuggingFace models:",T)}finally{Q(!1)}},[W,ke,le]),qr=A.useCallback(async T=>{const[_,ge]=T.split("/");if(!(!_||!ge)){w0(T);try{const Fe=await Hr.getGgufFiles(_,ge);Fe.success&&Fe.data&&He(je=>({...je,[T]:Fe.data}))}catch(Fe){console.error("Failed to load GGUF files:",Fe)}finally{w0(null)}}},[]),Qs=A.useCallback(T=>{re===T?ee(null):(ee(T),he[T]||qr(T))},[re,he,qr]),_s=A.useCallback((T,_)=>{if(!Ne){Se(T),oe({status:"starting"});try{const ge=Ct.pullModelStream(T,Fe=>{oe(Fe)},()=>{oe(null),Se(null),Ve(null),ue.success(`Downloaded ${_}`),d?.()},Fe=>{oe(null),Se(null),Ve(null),ue.error(`Failed to download: ${Fe}`)});Ve(()=>ge)}catch{oe(null),Se(null),ue.error("Failed to start download")}}},[Ne,d]);A.useEffect(()=>{const T=setTimeout(()=>{S==="huggingface"?Ae(y):S==="ollama"&&j(y)},300);return()=>clearTimeout(T)},[y,S]),A.useEffect(()=>{f&&S==="ollama"&&c0()},[f,S,N,c0]),A.useEffect(()=>{f&&S==="huggingface"&&d0()},[f,S,W,ke,le,d0]),A.useEffect(()=>{const T=_=>{C.current&&!C.current.contains(_.target)&&(x(!1),b(""))};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),A.useEffect(()=>{f&&B.current&&B.current.focus()},[f]);const Rr=T=>{t({target:{value:T}}),x(!1),b("")},en=async T=>{if(!Ne){Se(T),oe({status:"starting"});try{const _=Ct.pullModelStream(T,ge=>{oe(ge)},()=>{oe(null),Se(null),Ve(null),ue.success(`Downloaded ${T}`),d?.()},ge=>{oe(null),Se(null),Ve(null),ue.error(`Failed to download: ${ge}`)});Ve(()=>_)}catch{oe(null),Se(null),ue.error("Failed to start download")}}},Pr=()=>{Te&&(Te(),Ve(null),Se(null),oe(null),ue.success("Download cancelled"))},tn=T=>r.some(_=>_.name===T||_.name.startsWith(T+":")),At=T=>T.isPersona?u.jsx(_t,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):T.isPlugin?u.jsx(A0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):u.jsx(Dt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),R0=T=>T.isPersona?T.personaName||T.name:T.isPlugin?`${T.name}`:T.name,jt=T=>T.isPersona?`via ${T.model}`:T.isPlugin?`via ${T.pluginName}`:null,Or=T=>T>=1e6?`${(T/1e6).toFixed(1)}M`:T>=1e3?`${(T/1e3).toFixed(1)}K`:T.toString(),rn=()=>{if(!Re)return l?u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx(Dt,{className:"h-4 w-4"}),u.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:"Select Model"})]}):"Select Model";if(l){const ge=R0(Re);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[At(Re),u.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:ge})]})}const T=R0(Re),_=jt(Re);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[At(Re),u.jsxs("div",{className:"flex flex-col min-w-0",children:[u.jsx("span",{className:"text-sm font-medium truncate",children:T}),_&&u.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:_})]}),Re.isPersona&&a&&u.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[u.jsx(mt,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&u.jsx(Wa,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})},an=()=>u.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400",children:[E0.length>0?E0.map(T=>u.jsxs("div",{children:[u.jsx("div",{className:"px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a] border-b border-gray-200 dark:border-dark-400 ophelia:border-[#1a1a1a] sticky top-0",children:u.jsxs("div",{className:"flex items-center gap-2",children:[T.icon,T.label," (",T.models.length,")"]})}),T.models.map(_=>u.jsx("div",{onMouseDown:ge=>{ge.preventDefault(),Rr(_.name)},className:Y("px-3 py-3 cursor-pointer border-b border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] last:border-b-0","hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] transition-colors",e===_.name&&"bg-primary-50 dark:bg-primary-900/30 ophelia:bg-[rgba(147,51,234,0.15)]"),children:u.jsxs("div",{className:"flex items-center gap-3",children:[At(_),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:R0(_)}),jt(_)&&u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:jt(_)})]}),e===_.name&&u.jsx(yt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},_.name))]},T.type)):u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(In,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),u.jsx("p",{className:"text-sm",children:"No models found"})]}),c&&u.jsxs("div",{className:"border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsx("div",{className:"px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a]",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(mr,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),"Actions"]})}),u.jsx("div",{onMouseDown:T=>{T.preventDefault(),x(!1),z("/gallery")},className:"px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 ophelia:hover:bg-[rgba(147,51,234,0.1)] bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(Xa,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),u.jsxs("div",{className:"flex-1",children:[u.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:p("gallery.generate")}),u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:p("gallery.generateDescription")})]})]})})]})]}),sn=()=>u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[u.jsx("div",{className:"px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0",children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:u0.map(T=>u.jsx("button",{onMouseDown:_=>{_.preventDefault(),_.stopPropagation(),q(T)},className:Y("px-2.5 py-1 rounded-full text-xs font-medium transition-colors",F===T?"bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]":"bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]"),children:T.charAt(0).toUpperCase()+T.slice(1)},T))})}),u.jsx("div",{className:"flex-1 overflow-y-auto",children:O?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ft,{className:"h-6 w-6 animate-spin text-gray-400"})}):q0.length===0?u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(Bt,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:"No models found"})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:q0.slice(0,50).map(T=>{const _=tn(T.name),ge=Ne===T.name;return u.jsxs("div",{className:Y("px-3 py-3 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",_&&"bg-green-50/50 dark:bg-green-900/10"),children:[u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("div",{className:"p-2 rounded-lg bg-cyan-100 dark:bg-cyan-900/30 ophelia:bg-[#06b6d4]/20 flex-shrink-0",children:u.jsx(Bt,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-400"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:T.name}),_&&u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:"Installed"})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] line-clamp-1 mt-0.5",children:T.description}),u.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[T.sizes.slice(0,3).map(Fe=>u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:Fe},Fe)),T.pulls&&u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1",children:[u.jsx(J0,{className:"h-3 w-3"}),T.pulls]})]})]}),u.jsx("div",{className:"flex-shrink-0",children:ge?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:se?.percent!==void 0?`${se.percent}%`:"..."}),u.jsx("button",{onClick:Pr,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(f0,{className:"h-4 w-4"})})]}):_?u.jsx("button",{onClick:()=>Rr(T.name),className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50",children:"Use"}):u.jsxs("button",{onClick:()=>en(T.name),className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7] hover:bg-primary-200 dark:hover:bg-primary-900/50",children:[u.jsx(J0,{className:"h-3 w-3 inline mr-1"}),"Pull"]})})]}),ge&&se?.percent!==void 0&&u.jsx("div",{className:"mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden",children:u.jsx("div",{className:"h-1.5 rounded-full bg-primary-500 transition-all duration-300",style:{width:`${se.percent}%`}})})]},T.name)})})}),u.jsxs("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0",children:[u.jsxs("a",{href:"https://ollama.com/library",target:"_blank",rel:"noopener noreferrer",onMouseDown:T=>T.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(It,{className:"h-3 w-3"}),p("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),R([]),c0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(er,{className:Y("h-3.5 w-3.5 text-gray-400",O&&"animate-spin")})})]})]}),nn=()=>u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[u.jsx("div",{className:"px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0 space-y-2",children:u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("select",{value:W,onChange:T=>te(T.target.value),onMouseDown:T=>T.stopPropagation(),className:"flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:[u.jsx("option",{value:"text-generation",children:p("modelManager.huggingface.taskTextGeneration")}),u.jsx("option",{value:"text-to-speech",children:p("modelManager.huggingface.taskTextToSpeech")}),u.jsx("option",{value:"text-to-image",children:p("modelManager.huggingface.taskTextToImage")}),u.jsx("option",{value:"automatic-speech-recognition",children:p("modelManager.huggingface.taskSpeechRecognition")})]}),u.jsxs("select",{value:le,onChange:T=>be(T.target.value),onMouseDown:T=>T.stopPropagation(),className:"px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:[u.jsx("option",{value:"downloads",children:p("modelManager.huggingface.sortDownloads")}),u.jsx("option",{value:"likes",children:p("modelManager.huggingface.sortLikes")}),u.jsx("option",{value:"lastModified",children:p("modelManager.huggingface.sortRecent")})]})]})}),u.jsx("div",{className:"flex-1 overflow-y-auto",children:V?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ft,{className:"h-6 w-6 animate-spin text-gray-400"})}):L.length===0?u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(A0,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:p("modelManager.huggingface.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:L.map(T=>{const _=re===T.id,ge=he[T.id]||[],Fe=Xe===T.id;return u.jsxs("div",{className:"bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:[u.jsx("div",{className:"px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]",onMouseDown:je=>{je.preventDefault(),je.stopPropagation(),Qs(T.id)},children:u.jsxs("div",{className:"flex items-start gap-3",children:[u.jsx("div",{className:"p-2 rounded-lg bg-yellow-100 dark:bg-yellow-900/30 ophelia:bg-[#eab308]/20 flex-shrink-0",children:u.jsx(A0,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-400"})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:T.id}),T.gated&&u.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400",children:"Gated"})]}),u.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mt-0.5",children:["by ",T.author]}),u.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500",children:[u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(J0,{className:"h-3 w-3"}),Or(T.downloads)]}),u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(En,{className:"h-3 w-3"}),Or(T.likes)]}),T.pipeline_tag&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]",children:T.pipeline_tag})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u.jsx("a",{href:`https://huggingface.co/${T.id}`,target:"_blank",rel:"noopener noreferrer",onMouseDown:je=>je.stopPropagation(),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(It,{className:"h-4 w-4 text-gray-400"})}),u.jsx(D0,{className:Y("h-4 w-4 text-gray-400 transition-transform",_&&"rotate-180")})]})]})}),_&&u.jsx("div",{className:"px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] bg-gray-50 dark:bg-dark-200 ophelia:bg-[#0d0d0d]",children:Fe?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ft,{className:"h-4 w-4 animate-spin text-gray-400"}),u.jsx("span",{className:"ml-2 text-xs text-gray-500",children:p("modelManager.huggingface.checkingGguf")})]}):ge.length===0?u.jsx("div",{className:"py-4 text-center text-xs text-gray-500 dark:text-gray-400",children:p("modelManager.huggingface.noGgufAvailable")}):u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-xs font-medium text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:p("modelManager.huggingface.ggufFilesCount",{count:ge.length})}),ge.map(je=>{const ln=Ne===je.ollamaCommand;return u.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-xs font-medium text-gray-800 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:je.filename}),u.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:[u.jsx("span",{children:je.sizeFormatted}),je.quantization&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-400 ophelia:text-[#a855f7]",children:je.quantization})]})]}),ln?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:se?.percent!==void 0?`${se.percent}%`:"..."}),u.jsx("button",{onMouseDown:P0=>{P0.preventDefault(),P0.stopPropagation(),Pr()},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(f0,{className:"h-4 w-4"})})]}):u.jsxs("button",{onMouseDown:P0=>{P0.preventDefault(),P0.stopPropagation(),_s(je.ollamaCommand,je.filename)},disabled:!!Ne,className:Y("px-3 py-1.5 rounded-lg text-xs font-medium","bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20","text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]","hover:bg-primary-200 dark:hover:bg-primary-900/50","disabled:opacity-50 disabled:cursor-not-allowed"),children:[u.jsx(J0,{className:"h-3 w-3 inline mr-1"}),p("models.pull")]})]},je.filename)}),Ne?.startsWith("hf.co/")&&Ne.includes(T.id)&&se?.percent!==void 0&&u.jsx("div",{className:"w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2",children:u.jsx("div",{className:"h-1.5 rounded-full bg-primary-500 transition-all duration-300",style:{width:`${se.percent}%`}})})]})})]},T.id)})})}),u.jsxs("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0",children:[u.jsxs("a",{href:"https://huggingface.co/models",target:"_blank",rel:"noopener noreferrer",onMouseDown:T=>T.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(It,{className:"h-3 w-3"}),p("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),d0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(er,{className:Y("h-3.5 w-3.5 text-gray-400",V&&"animate-spin")})})]})]});return u.jsxs("div",{className:Y("relative",s),ref:C,children:[u.jsxs("button",{type:"button",onClick:()=>!n&&x(!f),disabled:n,className:Y(l?"h-[44px] sm:h-[52px] px-3 flex items-center justify-between text-left w-full ":"w-full flex items-center justify-between gap-2 px-3 py-2 text-left ","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","rounded-lg text-sm hover:bg-gray-100 dark:hover:bg-dark-100 ophelia:hover:bg-[#1a1a1a]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20 focus:border-primary-500 ophelia:focus:border-[#9333ea]",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?Re?R0(Re):"Select Model":void 0,children:[rn(),u.jsx(D0,{className:Y(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",f&&"rotate-180")})]}),f&&hr.createPortal(u.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4",children:[u.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>x(!1)}),u.jsxs("div",{className:Y("relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] shadow-2xl","w-full max-w-md sm:w-[480px] sm:max-w-[90vw]","mt-2 sm:mt-0 rounded-xl","h-[85vh] sm:h-[600px] flex flex-col"),onClick:T=>T.stopPropagation(),children:[u.jsxs("div",{className:"flex-shrink-0",children:[u.jsx("div",{className:"p-3 border-b border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:u.jsxs("div",{className:"relative",children:[u.jsx(Bn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),u.jsx("input",{ref:B,type:"text",placeholder:S==="installed"?"Search installed models...":S==="ollama"?"Search Ollama library...":"Search HuggingFace...",value:y,onChange:T=>b(T.target.value),className:Y("w-full pl-10 pr-4 py-2.5 text-sm bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-lg","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#737373]")})]})}),u.jsxs("div",{className:"flex border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("installed")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="installed"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(Fn,{className:"h-4 w-4 inline mr-1.5"}),"Installed"]}),u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("ollama")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="ollama"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(Bt,{className:"h-4 w-4 inline mr-1.5"}),"Ollama"]}),u.jsxs("button",{onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),k("huggingface")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",S==="huggingface"?"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300"),children:[u.jsx(A0,{className:"h-4 w-4 inline mr-1.5"}),"HuggingFace"]})]})]}),S==="installed"&&an(),S==="ollama"&&sn(),S==="huggingface"&&nn()]})]}),document.body),u.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(T=>u.jsx("option",{value:T.name,children:R0(T)},T.name))})]})},Ho=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=b0(),[s,n]=A.useState(""),[l,c]=A.useState([]),[d,p]=A.useState(null),[f,x]=A.useState(!1),[y,b]=A.useState(null),[S,k]=A.useState(!1),{isGenerating:C,setBackgroundImage:B}=C0(),{currentSession:z,models:U}=ze(),R=A.useRef(null);A.useEffect(()=>{(async()=>{try{const L=await Oa.getPlugins();k(!!(L.success&&L.data&&L.data.length>0))}catch{k(!1)}})()},[]);const O=j=>{j.preventDefault(),!(!s.trim()||C)&&(r(s.trim(),l.length>0?l:void 0,d||void 0),n(""),c([]))},X=j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),O(j))},F=()=>{e()};A.useEffect(()=>{const j=R.current;j&&(j.style.height="auto",j.style.height=Math.min(j.scrollHeight,200)+"px")},[s]),A.useEffect(()=>{(async()=>{if(z?.personaId)try{const L=await $r.getPersona(z.personaId);if(L.success&&L.data)b(L.data);else{console.warn(`Persona ${z.personaId} not found, clearing reference`),b(null);const{setCurrentSession:H}=ze.getState();H({...z,personaId:void 0})}}catch(L){if(console.error("Failed to load current persona:",L),b(null),z){const{setCurrentSession:H}=ze.getState();H({...z,personaId:void 0})}}else b(null)})()},[z?.personaId]);const q=async j=>{const L=j.target.value;if(z)try{if(L.startsWith("persona:")){const H=L.replace("persona:",""),V=await $r.getPersona(H);if(!V.success||!V.data){Q0.error("Failed to load persona details");return}const Q=V.data,W=await ht.updateSession(z.id,{personaId:H,model:L});if(W.success&&W.data){const{sessions:te}=ze.getState(),le=te.map(be=>be.id===z.id?W.data:be);ze.setState({sessions:le,currentSession:W.data}),Q.background&&B(Q.background),Q0.success(a("chat.persona.applied"))}}else{const H=await ht.updateSession(z.id,{model:L,personaId:void 0});if(H.success&&H.data){const{sessions:V}=ze.getState(),Q=V.map(W=>W.id===z.id?H.data:W);ze.setState({sessions:Q,currentSession:H.data}),B(null),Q0.success(a("chat.model.updated"))}}}catch(H){console.error("Failed to update session:",H),Q0.error("Failed to update session")}},N=l.length>0||d!==null;return u.jsx("div",{className:"pointer-events-none",children:u.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto",children:[f&&u.jsxs("div",{className:"mb-2 p-3 rounded-2xl bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/50 shadow-lg",children:[u.jsx(Ro,{images:l,onImagesChange:c,maxImages:5,sessionId:z?.id,disabled:t}),u.jsx(Lo,{format:d,onFormatChange:p})]}),u.jsxs("div",{className:"py-2 sm:py-3",children:[u.jsx("form",{onSubmit:O,children:u.jsxs("div",{className:Y("flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-300 ease-out shadow-lg","bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md","border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60","hover:border-gray-300/70 dark:hover:border-dark-400/70 ophelia:hover:border-[#3f3f46]/80","focus-within:border-primary-400/70 dark:focus-within:border-primary-500/70 ophelia:focus-within:border-[#9333ea]/70","focus-within:shadow-xl"),children:[u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:()=>x(!f),className:Y("h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0","hover:bg-gray-100 dark:hover:bg-dark-200/80 ophelia:hover:bg-[#1a1a1a]","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95",N&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",f&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:a("chat.input.attachments"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:N?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(Ya,{className:"h-4 w-4"}),u.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 ophelia:bg-[#a855f7] rounded-full ring-2 ring-white dark:ring-dark-50 ophelia:ring-[#0a0a0a]"})]}):f?u.jsx(Ka,{className:"h-4 w-4"}):u.jsx(mr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Er,{ref:R,value:s,onChange:j=>n(j.target.value),onKeyDown:X,placeholder:a("chat.input.placeholder"),disabled:t,className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),u.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[z&&U.length>0&&u.jsx("div",{className:"hidden sm:block",children:u.jsx(bt,{models:U,selectedModel:z.personaId?`persona:${z.personaId}`:z.model,onModelChange:q,currentPersona:y,className:"min-w-[160px] max-w-[240px] border-0 bg-gray-100/80 dark:bg-dark-100/80 ophelia:bg-[#1a1a1a]/80 rounded-xl text-sm hover:bg-gray-200/80 dark:hover:bg-dark-200/60 ophelia:hover:bg-[#262626]/80 transition-colors duration-200",compact:!0,showImageGen:S})}),C?u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:F,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","bg-red-50 dark:bg-red-900/20 ophelia:bg-red-900/30","text-red-500 dark:text-red-400 ophelia:text-red-400","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/40","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95"),title:a("chat.input.stopGeneration"),children:u.jsx($a,{className:"h-4 w-4"})}):u.jsx(r0,{type:"submit",variant:"ghost",size:"sm",disabled:!s.trim()||t,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","text-gray-400 dark:text-dark-500 ophelia:text-[#525252]","disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed","transition-all duration-200 touch-manipulation",s.trim()&&!t&&["bg-primary-500 dark:bg-primary-600 ophelia:bg-[#9333ea]","text-white dark:text-white ophelia:text-white","hover:bg-primary-600 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","shadow-md hover:shadow-lg","hover:scale-105 active:scale-95"]),title:a("chat.input.sendMessage"),children:u.jsx(Za,{className:"h-4 w-4"})})]})]})}),z&&U.length>0&&u.jsx("div",{className:"sm:hidden mt-3",children:u.jsx(bt,{models:U,selectedModel:z.personaId?`persona:${z.personaId}`:z.model,onModelChange:q,currentPersona:y,className:"w-full rounded-xl bg-gray-100/80 dark:bg-dark-100/80 ophelia:bg-[#1a1a1a]/80 border-0 transition-colors duration-200",compact:!0,showImageGen:S})}),u.jsxs("div",{className:"mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600",children:[u.jsx(Po,{sessionId:z?.id}),u.jsxs("div",{className:"text-center",children:[u.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors",style:{fontSize:"1.1em",lineHeight:1},children:"Libre WebUI"})," ",u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.6.3"]})," ",u.jsx("span",{className:"text-gray-300 dark:text-gray-600 opacity-50",children:"•"})," ",u.jsx("span",{className:"text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:a("chat.footer.disclaimer")}),N&&u.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",l.length>0&&a("chat.footer.images",{count:l.length}),l.length>0&&d&&" • ",d&&a("chat.footer.structuredOutput")]})]})]})]})]})})},$o=({persona:r,onClear:e,className:t})=>{const[a,s]=A.useState(!1),n=A.useRef(null),[l,c]=A.useState({top:0,left:0});A.useEffect(()=>{if(a&&n.current){const f=n.current.getBoundingClientRect();c({top:f.bottom+8,left:f.left})}},[a]);const d=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),p=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=64`;return u.jsxs("div",{className:Y("relative",t),children:[u.jsxs("button",{ref:n,onClick:()=>s(!a),className:Y("flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200","bg-primary-50 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/15","border border-primary-200 dark:border-primary-700/50 ophelia:border-[#7c3aed]/30","hover:bg-primary-100 dark:hover:bg-primary-900/40 ophelia:hover:bg-[#9333ea]/20","text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc]"),children:[u.jsx("img",{src:p(),alt:r.name,className:"w-5 h-5 rounded-full object-cover"}),u.jsx("span",{className:"text-sm font-medium max-w-[120px] truncate",children:r.name}),d&&u.jsx(Wa,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),u.jsx(D0,{className:Y("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&hr.createPortal(u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>s(!1)}),u.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:u.jsxs("div",{className:Y("rounded-xl overflow-hidden shadow-xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]"),children:[u.jsxs("div",{className:"relative h-16",children:[r.background?u.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):u.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800 ophelia:from-[#9333ea] ophelia:via-[#7c3aed] ophelia:to-[#6d28d9]"}),u.jsx("div",{className:"absolute inset-0 bg-black/10"}),e&&u.jsx("button",{onClick:f=>{f.stopPropagation(),e(),s(!1)},className:"absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors",title:"Remove persona",children:u.jsx(f0,{className:"h-3.5 w-3.5 text-white"})}),d&&u.jsxs("div",{className:"absolute top-2 left-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium",children:[u.jsx(mt,{className:"h-3 w-3"}),"Enhanced"]})]}),u.jsx("div",{className:"relative px-4 -mt-6",children:u.jsx("img",{src:p(),alt:r.name,className:"w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-md"})}),u.jsxs("div",{className:"px-4 pt-2 pb-4",children:[u.jsx("h4",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.name}),u.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1 mt-0.5",children:[u.jsx(qn,{className:"h-3 w-3"}),r.model]}),r.description&&u.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] mt-2 line-clamp-2",children:r.description}),r.parameters.system_prompt&&u.jsxs("div",{className:"mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:[u.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[u.jsx(Rn,{className:"h-2.5 w-2.5 text-gray-400"}),u.jsx("span",{className:"text-[9px] uppercase tracking-wider font-medium text-gray-400",children:"System"})]}),u.jsxs("p",{className:"text-[11px] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),u.jsxs("div",{className:"flex flex-wrap gap-1 mt-3",children:[u.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[u.jsx(A0,{className:"h-2.5 w-2.5"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),u.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:["Top-P ",r.parameters.top_p?.toFixed(1)||"0.9"]}),r.memory_settings?.enabled&&u.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-300 ophelia:text-[#c084fc]",children:[u.jsx(mt,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},Go=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const s=A.useRef(null),[n,l]=A.useState(!1),c=b=>{if(!b)return;const S=[],k=t-r.length;for(let C=0;C<Math.min(b.length,k);C++){const B=b[C];if(!B.type.startsWith("image/")){ue.error(`File ${B.name} is not an image`);continue}if(B.size>10*1024*1024){ue.error(`Image ${B.name} is too large (max 10MB)`);continue}const z=new FileReader;z.onload=U=>{U.target?.result&&(S.push(U.target.result),S.length===Math.min(b.length,k)&&e([...r,...S]))},z.readAsDataURL(B)}b.length>k&&ue.error(`Only ${k} more images can be added`)},d=b=>{b.preventDefault(),l(!0)},p=b=>{b.preventDefault(),l(!1)},f=b=>{b.preventDefault(),l(!1),c(b.dataTransfer.files)},x=b=>{const S=r.filter((k,C)=>C!==b);e(S)},y=r.length<t;return u.jsxs("div",{className:Y("space-y-3",a),children:[y&&u.jsxs("div",{className:Y("border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors","hover:border-primary-400 dark:hover:border-primary-500",n&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:d,onDragLeave:p,onDrop:f,children:[u.jsx("input",{ref:s,type:"file",multiple:!0,accept:"image/*",onChange:b=>c(b.target.files),className:"hidden"}),u.jsxs("div",{className:"flex flex-col items-center text-center",children:[u.jsx(Ua,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 mb-2"}),u.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:["Drop images here or"," ",u.jsx("button",{onClick:()=>s.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:"browse"})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Supports: JPG, PNG, GIF, WebP (max 10MB each)"})]})]}),r.length>0&&u.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((b,S)=>u.jsxs("div",{className:"relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:[u.jsx("img",{src:b,alt:`Upload ${S+1}`,className:"w-full h-full object-cover"}),u.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center",children:u.jsx(r0,{variant:"ghost",size:"sm",onClick:()=>x(S),className:"opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full",children:u.jsx(f0,{className:"h-4 w-4"})})})]},S))}),y&&r.length>0&&u.jsxs(r0,{variant:"outline",size:"sm",onClick:()=>s.current?.click(),className:"w-full sm:w-auto",children:[u.jsx(Xa,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},Uo=r=>{const[e,t]=A.useState(""),[a,s]=A.useState(null),[n,l]=A.useState(!1),{addMessage:c,updateMessage:d,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:x}=ze(),{setIsGenerating:y,preferences:b}=C0(),S=A.useRef(null),k=A.useRef(null),C=A.useRef(""),B=A.useRef(0),z=A.useRef();A.useEffect(()=>()=>{Me.offMessage("user_message"),Me.offMessage("assistant_chunk"),Me.offMessage("assistant_complete"),Me.offMessage("error")},[r]),A.useEffect(()=>{if(!r){Me.offMessage("user_message"),Me.offMessage("assistant_chunk"),Me.offMessage("assistant_complete"),Me.offMessage("error");return}return Me.onMessage("user_message",()=>{}),Me.onMessage("assistant_chunk",q=>{const N=q,j=N.messageId||S.current;j&&(C.current=N.total,t(N.total),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{d(r,j,C.current),B.current=Date.now()},N.done?0:200))}),Me.onMessage("assistant_complete",q=>{const N=q;console.log("Hook: Received assistant_complete for session:",r,"messageId:",N.messageId,"with statistics:",!!N.statistics),l(!1),t(""),y(!1);const j=N.messageId||S.current;if(N&&j){const W=C.current||N.content;p(r,j,W,N.statistics)}const H=C0.getState().preferences.titleSettings,V=ze.getState().currentSession,Q=k.current;console.log("Auto-title check:",{firstMessage:Q,autoTitle:H?.autoTitle,taskModel:H?.taskModel,sessionTitle:V?.title}),Q&&H?.autoTitle&&H?.taskModel&&V?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),x(r),ht.generateTitle(r,H.taskModel,Q).then(W=>{console.log("Title generation response:",W),W.success&&W.data?.title&&f(r,W.data.title)}).catch(W=>{console.error("Failed to generate title:",W)}).finally(()=>{x(null)}),k.current=null),S.current=null,C.current="",z.current&&clearTimeout(z.current),B.current=0}),Me.onMessage("error",q=>{const N=q;if(l(!1),t(""),y(!1),S.current=null,N.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),ue.error("Session not found. Creating a new session..."),window.location.href="/";return}ue.error(N.error)}),l(!1),t(""),S.current=null,()=>{z.current&&clearTimeout(z.current)}},[r,d,p,y,f,x]);const U=A.useCallback(async(F,q,N)=>{if(!(!r||!F.trim()&&(!q||q.length===0)))try{y(!0),l(!0),t(""),z.current&&clearTimeout(z.current),B.current=Date.now();const j=ze.getState().currentSession,L=j?.isPrivate===!0,H=j?.messages?.some(W=>W.role==="user");!L&&!H&&j?.title==="New Chat"&&(k.current=F.trim()),c(r,{role:"user",content:F.trim(),images:q});const V=Gr();S.current=V,s(V),c(r,{role:"assistant",content:"",id:V}),Me.isConnected||await Me.connect();const Q=L?j?.messages?.filter(W=>W.role!=="system"&&W.id!==V).map(W=>({role:W.role,content:W.content,images:W.images})):void 0;Me.send({type:"chat_stream",data:{sessionId:r,content:F.trim(),images:q,format:N,options:b.generationOptions,assistantMessageId:V,isPrivate:L,model:L?j?.model:void 0,messageHistory:Q}})}catch(j){console.error("Failed to send message:",j),l(!1),t(""),s(null),y(!1),S.current=null,ue.error("Failed to send message")}},[r,c,y,b.generationOptions]),R=A.useCallback(()=>{l(!1),t(""),s(null),y(!1),S.current=null},[y]),O=A.useCallback(async()=>{const F=ze.getState().currentSession;if(!F||!r)return;const q=F.messages;let N=-1,j=-1;for(let V=q.length-1;V>=0;V--)if(q[V].role==="assistant"){j=V;break}if(j>0){for(let V=j-1;V>=0;V--)if(q[V].role==="user"){N=V;break}}if(N===-1||j===-1){ue.error("No message to regenerate");return}const L=q[N],H=q[j];try{y(!0),l(!0),t(""),z.current&&clearTimeout(z.current),B.current=Date.now();const V=Gr();S.current=V,s(V),c(r,{role:"assistant",content:"",id:V,parentId:H.parentId||H.id,branchIndex:H.siblingCount||1,isActive:!0}),Me.isConnected||await Me.connect(),Me.send({type:"chat_stream",data:{sessionId:r,content:L.content,images:L.images,options:b.generationOptions,assistantMessageId:V,regenerate:!0,originalMessageId:H.id}})}catch(V){console.error("Failed to regenerate message:",V),l(!1),t(""),y(!1),S.current=null,ue.error("Failed to regenerate message")}},[r,y,c,b.generationOptions]),X=A.useCallback(async F=>{const N=ze.getState().currentSession;if(!N||!r)return;const j=N.messages.find(V=>V.id===F);if(!j){ue.error("Message not found");return}if(j.isActive!==!1)return;const L=j.parentId||j.id,H=j.branchIndex||0;try{const V=await ht.switchMessageBranch(r,F,H);if(V.success&&V.data){const Q=N.messages.map(te=>te.id===L||te.parentId===L?{...te,isActive:te.id===F}:te),W={...N,messages:Q,updatedAt:Date.now()};ze.setState(te=>({sessions:te.sessions.map(le=>le.id===r?W:le),currentSession:W})),ue.success(`Switched to variant ${H+1}`)}else ue.error(V.error||"Failed to select branch")}catch(V){console.error("Failed to select branch:",V),ue.error("Failed to select branch")}},[r]);return{sendMessage:U,stopGeneration:R,regenerateLastMessage:O,selectBranch:X,isStreaming:n,streamingMessage:e,streamingMessageId:a}},Vo=(r,e)=>{const t=new Date().getHours(),a=r?`, ${r}`:"";return t>=5&&t<12?{greeting:`${e?e("chat.greeting.morning"):"Good morning"}${a}`,timeSuffix:"today"}:t>=12&&t<17?{greeting:`${e?e("chat.greeting.afternoon"):"Good afternoon"}${a}`,timeSuffix:"today"}:t>=17&&t<21?{greeting:`${e?e("chat.greeting.evening"):"Good evening"}${a}`,timeSuffix:"tonight"}:{greeting:`${e?e("chat.greeting.night"):"Good night"}${a}`,timeSuffix:"tonight"}},Qo=()=>{const{t:r}=b0(),{sessionId:e}=pn(),t=Ra(),a=fn(),{currentSession:s,sessions:n,models:l,selectedModel:c,setSelectedModel:d,createSession:p,setCurrentSession:f,loadSessions:x,getCurrentPersona:y}=ze(),{user:b}=Pa(),{sendMessage:S,stopGeneration:k,regenerateLastMessage:C,selectBranch:B,isStreaming:z,streamingMessage:U,streamingMessageId:R}=Uo(s?.id||""),O=y(),{greeting:X,timeSuffix:F}=A.useMemo(()=>Vo(b?.username,r),[b?.username,r]),[q,N]=A.useState(""),[j,L]=A.useState([]),[H,V]=A.useState(!1),Q=A.useRef(null),[W,te]=A.useState(!1);A.useEffect(()=>{n.length===0&&x()},[x,n.length]),A.useEffect(()=>{(async()=>{try{const ee=await Oa.getPlugins();te(!!(ee.success&&ee.data&&ee.data.length>0))}catch{te(!1)}})()},[]),A.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const he=n.find(He=>He.id===e);he&&he.id!==s?.id?f(he):he||(console.warn(`Session ${e} not found for current user, redirecting...`),n.length>0?t(`/c/${n[0].id}`,{replace:!0}):t("/",{replace:!0}))}else!e&&n.length>0&&a.pathname==="/"&&t(`/c/${n[0].id}`,{replace:!0})})()},[e,n,f,t,s?.id,s?.isPrivate,a.pathname]),A.useEffect(()=>{if(s?.id){const re=sessionStorage.getItem("pendingMessage");if(re){sessionStorage.removeItem("pendingMessage");try{const ee=JSON.parse(re);setTimeout(()=>{S(ee.content,ee.images)},100)}catch(ee){console.error("Failed to parse pending message:",ee)}}}},[s?.id,S]),A.useEffect(()=>{const re=Q.current;re&&(re.style.height="auto",re.style.height=Math.min(re.scrollHeight,200)+"px")},[q]);const le=async re=>{if(re.preventDefault(),!q.trim()||!c)return;const ee={content:q.trim(),images:j.length>0?j:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(ee)),N(""),L([]);const he=await p(c);he&&t(`/c/${he.id}`,{replace:!0})},be=re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),le(re))},ke=async re=>{const ee=re.target.value;d(ee)},Ae=(re,ee,he)=>{s&&S(re,ee,he)};if(!s){const re=j.length>0;return u.jsxs("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative",children:[u.jsxs("button",{onClick:()=>{if(!c&&l.length===0)return;const ee=Date.now(),he={id:`private-${ee}`,title:r("chat.session.private"),model:c||l[0]?.name||"",messages:[],createdAt:ee,updatedAt:ee,isPrivate:!0};f(he)},disabled:!c&&l.length===0,className:"absolute top-4 right-4 flex items-center gap-2 px-3 py-1.5 rounded-full border border-gray-300 dark:border-dark-400 ophelia:border-[#3f3f46] bg-transparent hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",title:r("chat.session.privateTooltip"),children:[u.jsx(Vr,{className:"h-4 w-4"}),u.jsx("span",{className:"text-sm",children:r("chat.session.private")})]}),u.jsxs("div",{className:"w-full max-w-2xl mx-auto flex flex-col items-center justify-center",children:[u.jsx("h1",{className:"text-2xl sm:text-3xl font-medium text-gray-800 dark:text-gray-100 ophelia:text-[#fafafa] mb-2 text-center",style:{fontWeight:400},children:X}),u.jsx("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:r(F==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?u.jsxs("div",{className:"w-full",children:[H&&u.jsx("div",{className:"mb-4 p-4 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-2xl",children:u.jsx(Go,{images:j,onImagesChange:L,maxImages:5})}),u.jsx("form",{onSubmit:le,children:u.jsxs("div",{className:Y("flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-200","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#0a0a0a] border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]","focus-within:border-primary-400 dark:focus-within:border-primary-500 ophelia:focus-within:border-[#9333ea] focus-within:bg-white dark:focus-within:bg-dark-50 ophelia:focus-within:bg-[#0a0a0a]","shadow-sm hover:shadow-md focus-within:shadow-lg"),children:[u.jsx(r0,{type:"button",variant:"ghost",size:"sm",onClick:()=>V(!H),className:Y("h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0","hover:bg-gray-200 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors touch-manipulation",re&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",H&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:r("chat.input.attachImages"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:re?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(Ya,{className:"h-4 w-4"}),u.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 ophelia:bg-[#9333ea] rounded-full"})]}):H?u.jsx(Ka,{className:"h-4 w-4"}):u.jsx(mr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Er,{ref:Q,value:q,onChange:ee=>N(ee.target.value),onKeyDown:be,placeholder:r("chat.input.messagePlaceholder"),className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 ophelia:scrollbar-thumb-[#3f3f46] focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 ophelia:placeholder:text-[#737373] text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),u.jsx("div",{className:"hidden sm:block",children:u.jsx(bt,{models:l,selectedModel:c,onModelChange:ke,className:"min-w-[140px] max-w-[200px] border-0 bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] rounded-xl text-sm",compact:!0,showImageGen:W})}),u.jsx(r0,{type:"submit",variant:"ghost",size:"sm",disabled:!q.trim()||!c,className:Y("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","hover:bg-primary-100 dark:hover:bg-primary-900/30 ophelia:hover:bg-[rgba(147,51,234,0.2)] text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]","disabled:text-gray-400 dark:disabled:text-dark-500 ophelia:disabled:text-[#525252] disabled:hover:bg-transparent","transition-all duration-150 touch-manipulation",q.trim()&&c&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:u.jsx(Za,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"sm:hidden mt-4",children:u.jsx(bt,{models:l,selectedModel:c,onModelChange:ke,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:W})}),u.jsxs("div",{className:"mt-4 text-center",children:[u.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#a855f7] transition-colors text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",style:{fontSize:"0.75rem",lineHeight:1},children:"Libre WebUI"})," ",u.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.6.3"]})," ",u.jsx("span",{className:"text-gray-300 dark:text-gray-600 ophelia:text-[#3f3f46] opacity-50",children:"•"})," ",u.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:r("chat.footer.disclaimer")})]})]}):u.jsx("div",{className:"w-full max-w-md",children:u.jsxs("div",{className:"p-6 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-xl",children:[u.jsx("p",{className:"text-sm text-gray-700 dark:text-dark-700 ophelia:text-[#a3a3a3] mb-4",children:r("chat.model.noModelsDescription")}),u.jsx("code",{className:"block text-xs bg-gray-100 dark:bg-dark-200 ophelia:bg-[#0a0a0a] p-3 rounded-lg font-mono text-gray-800 dark:text-dark-600 ophelia:text-[#737373]",children:r("chat.model.pullCommand")})]})})]})]})}return u.jsxs("div",{className:"flex flex-col h-full relative",style:O?.background?{backgroundImage:`url(${O.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[O?.background&&u.jsx("div",{className:"absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm"}),u.jsxs("div",{className:"flex flex-col h-full relative z-10",children:[s?.isPrivate&&u.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#262626] bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#0a0a0a]/80 backdrop-blur-sm",children:u.jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[u.jsx(Vr,{className:"h-4 w-4"}),u.jsx("span",{className:"text-sm font-medium",children:r("chat.session.privateMode")}),u.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-500 ophelia:text-[#737373]",children:["— ",r("chat.session.privateDescription")]})]})}),O&&!s?.isPrivate&&u.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-100 dark:border-dark-200 ophelia:border-[#262626] bg-white/50 dark:bg-dark-100/50 ophelia:bg-[#0a0a0a]/50 backdrop-blur-sm",children:u.jsx($o,{persona:O,onClear:()=>{if(s){const{sessions:re}=ze.getState(),ee={...s,model:O.model,personaId:void 0},he=re.map(He=>He.id===s.id?ee:He);ze.setState({sessions:he,currentSession:ee})}}})}),u.jsx(Eo,{messages:s.messages,streamingMessage:U,streamingMessageId:R,isStreaming:z,onRegenerate:C,onSelectBranch:B,className:"flex-1"}),u.jsx(Ho,{onSendMessage:Ae,onStopGeneration:k,disabled:!s})]})]})};export{Qo as ChatPage,Qo as default};
|