libre-webui 0.8.4 → 0.8.5
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/frontend/dist/assets/{index-DW8C1vVk.js → index-fnpCaKr_.js} +4 -4
- package/frontend/dist/index.html +1 -1
- package/frontend/dist/js/{ArtifactContainer-Bm-Y-U-r.js → ArtifactContainer-CW_iHjsN.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-C8k9scC2.js → ArtifactDemoPage-DkERDKtR.js} +1 -1
- package/frontend/dist/js/{ChatPage-Ct1Kuyoh.js → ChatPage-D9dmPf4t.js} +2 -2
- package/frontend/dist/js/{GalleryPage-Ci46MnQP.js → GalleryPage-xkvacK1Y.js} +1 -1
- package/frontend/dist/js/{ModelsPage-Bmk7Bjt4.js → ModelsPage-CwUkhy1d.js} +1 -1
- package/frontend/dist/js/{PersonasPage-B4ZtuJcO.js → PersonasPage-R8wVg6rE.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-B5I2sjsB.js → UserManagementPage-BbST0j99.js} +1 -1
- package/package.json +3 -2
package/frontend/dist/index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<meta name="description" content="A modern, minimalist WebUI for interacting with local LLMs through Ollama API" />
|
|
10
10
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
11
11
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
12
|
-
<script type="module" crossorigin src="/assets/index-
|
|
12
|
+
<script type="module" crossorigin src="/assets/index-fnpCaKr_.js"></script>
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/js/router-vendor-DdQhGl5t.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/js/markdown-vendor-B0lXrrRZ.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/js/ui-vendor-C4ZcWovR.js">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as c}from"./router-vendor-DdQhGl5t.js";import{a as D,u as I,B as t,c as R,O as y}from"../assets/index-
|
|
1
|
+
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as c}from"./router-vendor-DdQhGl5t.js";import{a as D,u as I,B as t,c as R,O as y}from"../assets/index-fnpCaKr_.js";import{a as w,N as k,C as f,O as N,k as C,aB as z,f as J,Q as S,W as T,G as B,Y as M}from"./ui-vendor-C4ZcWovR.js";const P=({artifact:s,className:d})=>{const{t:r}=D(),[h,m]=c.useState(!1),[n,i]=c.useState("preview"),A=c.useRef(null),{theme:x,openArtifactPanel:g}=I(),p=async a=>{try{await navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}catch(l){console.error("Failed to copy:",l)}},u=()=>{const a=new Blob([s.content],{type:L(s.type)}),l=URL.createObjectURL(a),o=document.createElement("a");o.href=l,o.download=`${s.title}.${O(s.type)}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l)},L=a=>{switch(a){case"html":return"text/html";case"react":return"text/javascript";case"svg":return"image/svg+xml";case"css":return"text/css";case"json":return"application/json";default:return"text/plain"}},O=a=>{switch(a){case"html":return"html";case"react":return"jsx";case"svg":return"svg";case"css":return"css";case"json":return"json";default:return"txt"}},b=()=>{switch(s.type){case"html":return e.jsx(B,{className:"h-4 w-4"});case"react":return e.jsx(T,{className:"h-4 w-4"});case"svg":return e.jsx(S,{className:"h-4 w-4"});case"code":return e.jsx(T,{className:"h-4 w-4"});default:return e.jsx(S,{className:"h-4 w-4"})}},E=()=>{const a=`
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html>
|
|
4
4
|
<head>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as d}from"./router-vendor-DdQhGl5t.js";import{A as c}from"./ArtifactContainer-
|
|
1
|
+
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as d}from"./router-vendor-DdQhGl5t.js";import{A as c}from"./ArtifactContainer-CW_iHjsN.js";import{B as l}from"../assets/index-fnpCaKr_.js";import"./ui-vendor-C4ZcWovR.js";import"./utils-vendor-BFlGJDIj.js";const i=[{id:"demo-html-1",type:"html",title:"Interactive Button Demo",description:"A simple HTML page with interactive elements",content:`<div style="text-align: center; padding: 20px;">
|
|
2
2
|
<h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
|
|
3
3
|
<p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
|
|
4
4
|
<button
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as L0,f as tt,m as k0,s as Mn,a as Nn,c as Tn,v as An,S as zn,j as u,M as jn}from"./markdown-vendor-B0lXrrRZ.js";import{R as ur,r as A,e as Tr,c as rs,d as Cn,u as Dn}from"./router-vendor-DdQhGl5t.js";import{u as C0,O as Bn,c as Y,a as Ze,t as gt,b as Ar,d as je,p as ra,f as In,e as cr,S as En,T as Fn,B as a0,o as $0,h as aa,i as as,g as sa,j as vt,w as ye,k as na}from"../assets/index-
|
|
1
|
+
import{o as L0,f as tt,m as k0,s as Mn,a as Nn,c as Tn,v as An,S as zn,j as u,M as jn}from"./markdown-vendor-B0lXrrRZ.js";import{R as ur,r as A,e as Tr,c as rs,d as Cn,u as Dn}from"./router-vendor-DdQhGl5t.js";import{u as C0,O as Bn,c as Y,a as Ze,t as gt,b as Ar,d as je,p as ra,f as In,e as cr,S as En,T as Fn,B as a0,o as $0,h as aa,i as as,g as sa,j as vt,w as ye,k as na}from"../assets/index-fnpCaKr_.js";import{C as Nt,O as ss,d as Rn,j as D0,s as qn,L as ns,l as is,a2 as Pn,V as On,q as dr,a3 as hr,w as ls,S as Hn,X as p0,v as Ln,i as ia,a4 as xt,a5 as $n,a6 as Lt,D as la,I as zr,Q as W0,G as oa,a7 as Gn,a8 as os,a9 as Un,N as Vn,U as us,aa as Wn,z as ue,h as Xn,W as Yn,B as $t,$ as z0,ab as Kn,ac as Gt,u as cs,ad as Zn,t as jr,ae as Ut,k as rt,f as Vt,af as Jn,ag as ds,ah as hs,ai as ms,F as at,aj as Qn,M as _n,ak as ua}from"./ui-vendor-C4ZcWovR.js";import{A as ei}from"./ArtifactContainer-CW_iHjsN.js";import"./utils-vendor-BFlGJDIj.js";function ti(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 ri(){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 m={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[m]}},d)}function e(){this.buffer()}function t(){const d=this.resume(),m=this.stack[this.stack.length-1];L0(m.type==="math"),m.meta=d}function a(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function s(d){const m=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),f=this.stack[this.stack.length-1];L0(f.type==="math"),this.exit(d),f.value=m;const x=f.data.hChildren[0];L0(x.type==="element"),L0(x.tagName==="code"),x.children.push({type:"text",value:m}),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 m=this.resume(),f=this.stack[this.stack.length-1];L0(f.type==="inlineMath"),this.exit(d),f.value=m,f.data.hChildren.push({type:"text",value:m})}function c(d){this.config.enter.data.call(this,d),this.config.exit.data.call(this,d)}}function ai(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 m=n.value||"",f=c.createTracker(d),x="$".repeat(Math.max(ti(m,"$")+1,2)),y=c.enter("mathFlow");let b=f.move(x);if(n.meta){const k=c.enter("mathFlowMeta");b+=f.move(c.safe(n.meta,{after:`
|
|
3
3
|
`,before:b,encode:["$"],...f.current()})),k()}return b+=f.move(`
|
|
4
4
|
`),m&&(b+=f.move(m+`
|
|
@@ -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(a0,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),u.jsx(a0,{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(W0,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},Mt=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:c=!1,onModelsRefresh:d})=>{const{t:m}=Ze(),[f,x]=A.useState(!1),[y,b]=A.useState(""),[k,S]=A.useState("installed"),z=A.useRef(null),E=A.useRef(null),T=rs(),{user:H,systemInfo:V}=Ar(),B=H?.role==="admin"||(V?.allowUserModelPull??!0),[G,W]=A.useState([]),[$,N]=A.useState(!1),[j,C]=A.useState("all"),[F,Z]=A.useState(""),[X,O]=A.useState([]),[re,Q]=A.useState(!1),[le,Me]=A.useState("text-generation"),[Ne,Ie]=A.useState("downloads"),[ee,ne]=A.useState(""),[ge,Ce]=A.useState(null),[u0,Xe]=A.useState({}),[N0,se]=A.useState(null),[me,de]=A.useState(null),[Ge,Te]=A.useState(null),[et,e0]=A.useState(null),q0=["all","popular","chat","code","vision","embedding"],P0=[{type:"personas",label:m("modelSelector.personas"),icon:u.jsx(dr,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>M.isPersona),color:"purple"},{type:"ollama",label:m("modelSelector.ollamaModels"),icon:u.jsx($t,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>!M.isPersona&&!M.isPlugin&&!M.name.includes("embed")),color:"green"},{type:"plugins",label:m("modelSelector.pluginModels"),icon:u.jsx(z0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>M.isPlugin),color:"green"}].filter(M=>M.models.length>0).map(M=>({...M,models:M.models.filter(te=>te.name.toLowerCase().includes(y.toLowerCase())||te.personaName&&te.personaName.toLowerCase().includes(y.toLowerCase())||te.pluginName&&te.pluginName.toLowerCase().includes(y.toLowerCase()))})).filter(M=>M.models.length>0),T0=G.filter(M=>{const te=!y||M.name.toLowerCase().includes(y.toLowerCase())||M.description.toLowerCase().includes(y.toLowerCase()),ce=j==="all"||M.category===j;return te&&ce}),Pe=r.find(M=>M.name===e||e.startsWith("persona:")&&M.name===e),c0=A.useCallback(async()=>{N(!0);try{const M=await $0.getLibraryModels({search:F||void 0,sort:"popular"});M.success&&M.data&&W(M.data)}catch(M){console.error("Failed to load library:",M)}finally{N(!1)}},[F]),qt=A.useCallback(async()=>{Q(!0);try{const M=await aa.getModels({task:le,search:ee||void 0,sort:Ne,limit:30});M.success&&M.data&&O(M.data)}catch(M){console.error("Failed to load HuggingFace models:",M)}finally{Q(!1)}},[le,ee,Ne]),Qr=A.useCallback(async M=>{const[te,ce]=M.split("/");if(!(!te||!ce)){se(M);try{const ze=await aa.getGgufFiles(te,ce);ze.success&&ze.data&&Xe(De=>({...De,[M]:ze.data}))}catch(ze){console.error("Failed to load GGUF files:",ze)}finally{se(null)}}},[]),gn=A.useCallback(M=>{ge===M?Ce(null):(Ce(M),u0[M]||Qr(M))},[ge,u0,Qr]),vn=A.useCallback((M,te)=>{if(!B){ue.error(m("modelSelector.pullRestricted"));return}if(!me){de(M),Te({status:"starting"});try{const ce=$0.pullModelStream(M,ze=>{Te(ze)},()=>{Te(null),de(null),e0(null),ue.success(`Downloaded ${te}`),d?.()},ze=>{Te(null),de(null),e0(null),ue.error(`Failed to download: ${ze}`)});e0(()=>ce)}catch{Te(null),de(null),ue.error("Failed to start download")}}},[B,d,me,m]);A.useEffect(()=>{const M=setTimeout(()=>{k==="huggingface"?ne(y):k==="ollama"&&Z(y)},300);return()=>clearTimeout(M)},[y,k]),A.useEffect(()=>{f&&k==="ollama"&&c0()},[f,k,F,c0]),A.useEffect(()=>{f&&k==="huggingface"&&qt()},[f,k,le,ee,Ne,qt]),A.useEffect(()=>{const M=te=>{z.current&&!z.current.contains(te.target)&&(x(!1),b(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),A.useEffect(()=>{f&&E.current&&E.current.focus()},[f]);const _r=async M=>{x(!1),b("");try{const ce=await $0.listRunningModels();if(ce.success&&ce.data){const ze=ce.data;ze.length>0&&(ze.some(Ht=>Ht.name===M||M.startsWith("persona:"))||await $0.unloadAllModels())}}catch(ce){console.warn("Failed to unload models before switch:",ce)}t({target:{value:M}})},xn=async M=>{if(!B){ue.error(m("modelSelector.pullRestricted"));return}if(!me){de(M),Te({status:"starting"});try{const te=$0.pullModelStream(M,ce=>{Te(ce)},()=>{Te(null),de(null),e0(null),ue.success(`Downloaded ${M}`),d?.()},ce=>{Te(null),de(null),e0(null),ue.error(`Failed to download: ${ce}`)});e0(()=>te)}catch{Te(null),de(null),ue.error("Failed to start download")}}},ea=()=>{et&&(et(),e0(null),de(null),Te(null),ue.success("Download cancelled"))},bn=M=>r.some(te=>te.name===M||te.name.startsWith(M+":")),Pt=M=>M.isPersona?u.jsx(dr,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):M.isPlugin?u.jsx(z0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):u.jsx($t,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),O0=M=>M.isPersona?M.personaName||M.name:M.isPlugin?`${M.name}`:M.name,Ot=M=>M.isPersona?`via ${M.model}`:M.isPlugin?`via ${M.pluginName}`:null,ta=M=>M>=1e6?`${(M/1e6).toFixed(1)}M`:M>=1e3?`${(M/1e3).toFixed(1)}K`:M.toString(),yn=()=>{if(!Pe)return l?u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx($t,{className:"h-4 w-4"}),u.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:m("modelSelector.selectModel")})]}):m("modelSelector.selectModel");if(l){const ce=O0(Pe);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[Pt(Pe),u.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:ce})]})}const M=O0(Pe),te=Ot(Pe);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[Pt(Pe),u.jsxs("div",{className:"flex flex-col min-w-0",children:[u.jsx("span",{className:"text-sm font-medium truncate",children:M}),te&&u.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:te})]}),Pe.isPersona&&a&&u.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[u.jsx(xt,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&u.jsx(cs,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})},wn=()=>u.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400",children:[P0.length>0?P0.map(M=>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:[M.icon,M.label," (",M.models.length,")"]})}),M.models.map(te=>u.jsx("div",{onMouseDown:ce=>{ce.preventDefault(),_r(te.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===te.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:[Pt(te),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:O0(te)}),Ot(te)&&u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:Ot(te)})]}),e===te.name&&u.jsx(Nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},te.name))]},M.type)):u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(Zn,{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:m("models.noModelsFound")})]}),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(jr,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),m("modelSelector.actions")]})}),u.jsx("div",{onMouseDown:M=>{M.preventDefault(),x(!1),T("/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(zr,{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:m("gallery.generate")}),u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:m("gallery.generateDescription")})]})]})})]})]}),kn=()=>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:q0.map(M=>u.jsx("button",{onMouseDown:te=>{te.preventDefault(),te.stopPropagation(),C(M)},className:Y("px-2.5 py-1 rounded-full text-xs font-medium transition-colors",j===M?"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:M.charAt(0).toUpperCase()+M.slice(1)},M))})}),u.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!B&&u.jsx("div",{className:"mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",children:m("modelSelector.pullRestricted")}),$?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):T0.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(Gt,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:m("models.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:T0.slice(0,50).map(M=>{const te=bn(M.name),ce=me===M.name;return u.jsxs("div",{className:Y("px-3 py-3 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",te&&"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(Gt,{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:M.name}),te&&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:m("modelSelector.installed")})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] line-clamp-1 mt-0.5",children:M.description}),u.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[M.sizes.slice(0,3).map(ze=>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:ze},ze)),M.pulls&&u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1",children:[u.jsx(rt,{className:"h-3 w-3"}),M.pulls]})]})]}),u.jsx("div",{className:"flex-shrink-0",children:ce?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:Ge?.percent!==void 0?`${Ge.percent}%`:"..."}),u.jsx("button",{onClick:ea,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(p0,{className:"h-4 w-4"})})]}):te?u.jsx("button",{onClick:()=>_r(M.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:m("modelSelector.use")}):B?u.jsxs("button",{onClick:()=>xn(M.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(rt,{className:"h-3 w-3 inline mr-1"}),m("modelSelector.pull")]}):u.jsx("span",{className:"px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:m("modelSelector.adminOnlyPull")})})]}),ce&&Ge?.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:`${Ge.percent}%`}})})]},M.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:M=>M.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(Vt,{className:"h-3 w-3"}),m("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),W([]),c0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(hr,{className:Y("h-3.5 w-3.5 text-gray-400",$&&"animate-spin")})})]})]}),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 space-y-2",children:u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("select",{value:le,onChange:M=>Me(M.target.value),onMouseDown:M=>M.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:m("modelManager.huggingface.taskTextGeneration")}),u.jsx("option",{value:"text-to-speech",children:m("modelManager.huggingface.taskTextToSpeech")}),u.jsx("option",{value:"text-to-image",children:m("modelManager.huggingface.taskTextToImage")}),u.jsx("option",{value:"automatic-speech-recognition",children:m("modelManager.huggingface.taskSpeechRecognition")})]}),u.jsxs("select",{value:Ne,onChange:M=>Ie(M.target.value),onMouseDown:M=>M.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:m("modelManager.huggingface.sortDownloads")}),u.jsx("option",{value:"likes",children:m("modelManager.huggingface.sortLikes")}),u.jsx("option",{value:"lastModified",children:m("modelManager.huggingface.sortRecent")})]})]})}),u.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!B&&u.jsx("div",{className:"mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",children:m("modelSelector.pullRestricted")}),re?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):X.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(z0,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:m("modelManager.huggingface.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:X.map(M=>{const te=ge===M.id,ce=u0[M.id]||[],ze=N0===M.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:De=>{De.preventDefault(),De.stopPropagation(),gn(M.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(z0,{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:M.id}),M.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 ",M.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(rt,{className:"h-3 w-3"}),ta(M.downloads)]}),u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(Jn,{className:"h-3 w-3"}),ta(M.likes)]}),M.pipeline_tag&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]",children:M.pipeline_tag})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u.jsx("a",{href:`https://huggingface.co/${M.id}`,target:"_blank",rel:"noopener noreferrer",onMouseDown:De=>De.stopPropagation(),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(Vt,{className:"h-4 w-4 text-gray-400"})}),u.jsx(D0,{className:Y("h-4 w-4 text-gray-400 transition-transform",te&&"rotate-180")})]})]})}),te&&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:ze?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ut,{className:"h-4 w-4 animate-spin text-gray-400"}),u.jsx("span",{className:"ml-2 text-xs text-gray-500",children:m("modelManager.huggingface.checkingGguf")})]}):ce.length===0?u.jsx("div",{className:"py-4 text-center text-xs text-gray-500 dark:text-gray-400",children:m("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:m("modelManager.huggingface.ggufFilesCount",{count:ce.length})}),ce.map(De=>{const Ht=me===De.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:De.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:De.sizeFormatted}),De.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:De.quantization})]})]}),Ht?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:Ge?.percent!==void 0?`${Ge.percent}%`:"..."}),u.jsx("button",{onMouseDown:H0=>{H0.preventDefault(),H0.stopPropagation(),ea()},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(p0,{className:"h-4 w-4"})})]}):B?u.jsxs("button",{onMouseDown:H0=>{H0.preventDefault(),H0.stopPropagation(),vn(De.ollamaCommand,De.filename)},disabled:!!me,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(rt,{className:"h-3 w-3 inline mr-1"}),m("models.pull")]}):u.jsx("span",{className:"px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:m("modelSelector.adminOnlyPull")})]},De.filename)}),me?.startsWith("hf.co/")&&me.includes(M.id)&&Ge?.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:`${Ge.percent}%`}})})]})})]},M.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:M=>M.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(Vt,{className:"h-3 w-3"}),m("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),qt()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(hr,{className:Y("h-3.5 w-3.5 text-gray-400",re&&"animate-spin")})})]})]});return u.jsxs("div",{className:Y("relative",s),ref:z,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?Pe?O0(Pe):m("modelSelector.selectModel"):void 0,children:[yn(),u.jsx(D0,{className:Y(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",f&&"rotate-180")})]}),f&&Tr.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:M=>M.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(os,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),u.jsx("input",{ref:E,type:"text",placeholder:m(k==="installed"?"modelSelector.searchInstalled":k==="ollama"?"modelSelector.searchOllama":"modelSelector.searchHuggingFace"),value:y,onChange:M=>b(M.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:M=>{M.preventDefault(),M.stopPropagation(),S("installed")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(Kn,{className:"h-4 w-4 inline mr-1.5"}),m("modelSelector.installed")]}),u.jsxs("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),S("ollama")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(Gt,{className:"h-4 w-4 inline mr-1.5"}),"Ollama"]}),u.jsxs("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),S("huggingface")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(z0,{className:"h-4 w-4 inline mr-1.5"}),"HuggingFace"]})]})]}),k==="installed"&&wn(),k==="ollama"&&kn(),k==="huggingface"&&Sn()]})]}),document.body),u.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(M=>u.jsx("option",{value:M.name,children:O0(M)},M.name))})]})},Xo=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=Ze(),[s,n]=A.useState(""),[l,c]=A.useState([]),[d,m]=A.useState(null),[f,x]=A.useState(!1),[y,b]=A.useState(null),[k,S]=A.useState(!1),{isGenerating:z,setBackgroundImage:E}=C0(),{currentSession:T,models:H}=je(),V=A.useRef(null);A.useEffect(()=>{(async()=>{try{const C=await as.getPlugins();S(!!(C.success&&C.data&&C.data.length>0))}catch{S(!1)}})()},[]);const B=j=>{j.preventDefault(),!(!s.trim()||z)&&(r(s.trim(),l.length>0?l:void 0,d||void 0),n(""),c([]))},G=j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),B(j))},W=()=>{e()};A.useEffect(()=>{const j=V.current;j&&(j.style.height="auto",j.style.height=Math.min(j.scrollHeight,200)+"px")},[s]),A.useEffect(()=>{(async()=>{if(T?.personaId)try{const C=await sa.getPersona(T.personaId);if(C.success&&C.data)b(C.data);else{console.warn(`Persona ${T.personaId} not found, clearing reference`),b(null);const{setCurrentSession:F}=je.getState();F({...T,personaId:void 0})}}catch(C){if(console.error("Failed to load current persona:",C),b(null),T){const{setCurrentSession:F}=je.getState();F({...T,personaId:void 0})}}else b(null)})()},[T?.personaId]);const $=async j=>{const C=j.target.value;if(T)try{if(C.startsWith("persona:")){const F=C.replace("persona:",""),Z=await sa.getPersona(F);if(!Z.success||!Z.data){at.error("Failed to load persona details");return}const X=Z.data,O=await vt.updateSession(T.id,{personaId:F,model:C});if(O.success&&O.data){const{sessions:re}=je.getState(),Q=re.map(le=>le.id===T.id?O.data:le);je.setState({sessions:Q,currentSession:O.data}),X.background&&E(X.background),at.success(a("chat.persona.applied"))}}else{const F=await vt.updateSession(T.id,{model:C,personaId:void 0});if(F.success&&F.data){const{sessions:Z}=je.getState(),X=Z.map(O=>O.id===T.id?F.data:O);je.setState({sessions:X,currentSession:F.data}),E(null),at.success(a("chat.model.updated"))}}}catch(F){console.error("Failed to update session:",F),at.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(Go,{images:l,onImagesChange:c,maxImages:5,sessionId:T?.id,disabled:t}),u.jsx(Wo,{format:d,onFormatChange:m})]}),u.jsxs("div",{className:"py-2 sm:py-3",children:[u.jsx("form",{onSubmit:B,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(a0,{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(ds,{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(hs,{className:"h-4 w-4"}):u.jsx(jr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Jr,{ref:V,value:s,onChange:j=>n(j.target.value),onKeyDown:G,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:[T&&H.length>0&&u.jsx("div",{className:"hidden sm:block",children:u.jsx(Mt,{models:H,selectedModel:T.personaId?`persona:${T.personaId}`:T.model,onModelChange:$,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:k})}),z?u.jsx(a0,{type:"button",variant:"ghost",size:"sm",onClick:W,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(is,{className:"h-4 w-4"})}):u.jsx(a0,{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(ms,{className:"h-4 w-4"})})]})]})}),T&&H.length>0&&u.jsx("div",{className:"sm:hidden mt-3",children:u.jsx(Mt,{models:H,selectedModel:T.personaId?`persona:${T.personaId}`:T.model,onModelChange:$,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:k})}),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(Uo,{sessionId:T?.id}),u.jsxs("div",{className:"text-center",children:[u.jsxs("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 ",u.jsx("span",{style:{fontSize:"0.85em"},children:"WebUI"})]})," ",u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.8.4"]})," ",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")]})]})]})]})]})})},Yo=({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),m=()=>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:m(),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(cs,{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&&Tr.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(p0,{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(xt,{className:"h-3 w-3"}),"Enhanced"]})]}),u.jsx("div",{className:"relative px-4 -mt-6",children:u.jsx("img",{src:m(),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(_n,{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(z0,{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(xt,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},Ko=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const{t:s}=Ze(),n=A.useRef(null),[l,c]=A.useState(!1),d=k=>{if(!k)return;const S=[],z=t-r.length;for(let E=0;E<Math.min(k.length,z);E++){const T=k[E];if(!T.type.startsWith("image/")){ue.error(`File ${T.name} is not an image`);continue}if(T.size>10*1024*1024){ue.error(`Image ${T.name} is too large (max 10MB)`);continue}const H=new FileReader;H.onload=V=>{V.target?.result&&(S.push(V.target.result),S.length===Math.min(k.length,z)&&e([...r,...S]))},H.readAsDataURL(T)}k.length>z&&ue.error(`Only ${z} more images can be added`)},m=k=>{k.preventDefault(),c(!0)},f=k=>{k.preventDefault(),c(!1)},x=k=>{k.preventDefault(),c(!1),d(k.dataTransfer.files)},y=k=>{const S=r.filter((z,E)=>E!==k);e(S)},b=r.length<t;return u.jsxs("div",{className:Y("space-y-3",a),children:[b&&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",l&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:m,onDragLeave:f,onDrop:x,children:[u.jsx("input",{ref:n,type:"file",multiple:!0,accept:"image/*",onChange:k=>d(k.target.files),className:"hidden"}),u.jsxs("div",{className:"flex flex-col items-center text-center",children:[u.jsx(us,{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:[s("chat.mediaUpload.dropImagesHere")," ",u.jsx("button",{onClick:()=>n.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:s("chat.mediaUpload.browse")})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:s("chat.mediaUpload.supportedFormats")})]})]}),r.length>0&&u.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((k,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:k,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(a0,{variant:"ghost",size:"sm",onClick:()=>y(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(p0,{className:"h-4 w-4"})})})]},S))}),b&&r.length>0&&u.jsxs(a0,{variant:"outline",size:"sm",onClick:()=>n.current?.click(),className:"w-full sm:w-auto",children:[u.jsx(zr,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},Zo=r=>{const[e,t]=A.useState(""),[a,s]=A.useState(null),[n,l]=A.useState(!1),[c,d]=A.useState([]),{addMessage:m,updateMessage:f,updateMessageWithStatistics:x,updateSessionTitle:y,setGeneratingTitleForSession:b}=je(),{setIsGenerating:k,preferences:S}=C0(),z=A.useRef(null),E=A.useRef(null),T=A.useRef(""),H=A.useRef(0),V=A.useRef();A.useEffect(()=>()=>{ye.offMessage("user_message"),ye.offMessage("assistant_chunk"),ye.offMessage("assistant_complete"),ye.offMessage("tool_status"),ye.offMessage("error")},[r]),A.useEffect(()=>{if(!r){ye.offMessage("user_message"),ye.offMessage("assistant_chunk"),ye.offMessage("assistant_complete"),ye.offMessage("tool_status"),ye.offMessage("error");return}return ye.onMessage("user_message",()=>{}),ye.onMessage("assistant_chunk",j=>{const C=j,F=C.messageId||z.current;F&&(T.current=C.total,t(C.total),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{f(r,F,T.current),H.current=Date.now()},C.done?0:200))}),ye.onMessage("tool_status",j=>{const C=j;d(F=>F.find(X=>X.toolCallId===C.toolCallId)?F.map(X=>X.toolCallId===C.toolCallId?{...X,phase:C.phase}:X):[...F,{toolCallId:C.toolCallId,name:C.name,phase:C.phase,startedAt:Date.now()}])}),ye.onMessage("assistant_complete",j=>{const C=j;console.log("Hook: Received assistant_complete for session:",r,"messageId:",C.messageId,"with statistics:",!!C.statistics),l(!1),t(""),k(!1),d([]);const F=C.messageId||z.current;if(C&&F){const Q=T.current||C.content;x(r,F,Q,C.statistics)}const X=C0.getState().preferences.titleSettings,O=je.getState().currentSession,re=E.current;console.log("Auto-title check:",{firstMessage:re,autoTitle:X?.autoTitle,taskModel:X?.taskModel,sessionTitle:O?.title}),re&&X?.autoTitle&&X?.taskModel&&O?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),b(r),vt.generateTitle(r,X.taskModel,re).then(Q=>{console.log("Title generation response:",Q),Q.success&&Q.data?.title&&y(r,Q.data.title)}).catch(Q=>{console.error("Failed to generate title:",Q)}).finally(()=>{b(null)}),E.current=null),z.current=null,T.current="",V.current&&clearTimeout(V.current),H.current=0}),ye.onMessage("error",j=>{const C=j;if(l(!1),t(""),k(!1),z.current=null,C.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(C.error)}),l(!1),t(""),z.current=null,()=>{V.current&&clearTimeout(V.current)}},[r,f,x,k,y,b]);const B=A.useCallback(async(N,j,C)=>{if(!(!r||!N.trim()&&(!j||j.length===0)))try{k(!0),l(!0),t(""),V.current&&clearTimeout(V.current),H.current=Date.now();const F=je.getState().currentSession,Z=F?.isPrivate===!0,X=F?.messages?.some(Q=>Q.role==="user");!Z&&!X&&F?.title==="New Chat"&&(E.current=N.trim()),m(r,{role:"user",content:N.trim(),images:j});const O=na();z.current=O,s(O),m(r,{role:"assistant",content:"",id:O}),ye.isConnected||await ye.connect();const re=Z?F?.messages?.filter(Q=>Q.role!=="system"&&Q.id!==O).map(Q=>({role:Q.role,content:Q.content,images:Q.images})):void 0;ye.send({type:"chat_stream",data:{sessionId:r,content:N.trim(),images:j,format:C,options:S.generationOptions,assistantMessageId:O,isPrivate:Z,model:Z?F?.model:void 0,messageHistory:re}})}catch(F){console.error("Failed to send message:",F),l(!1),t(""),s(null),k(!1),z.current=null,ue.error("Failed to send message")}},[r,m,k,S.generationOptions]),G=A.useCallback(()=>{l(!1),t(""),s(null),k(!1),z.current=null},[k]),W=A.useCallback(async()=>{const N=je.getState().currentSession;if(!N||!r)return;const j=N.messages;let C=-1,F=-1;for(let O=j.length-1;O>=0;O--)if(j[O].role==="assistant"){F=O;break}if(F>0){for(let O=F-1;O>=0;O--)if(j[O].role==="user"){C=O;break}}if(C===-1||F===-1){ue.error("No message to regenerate");return}const Z=j[C],X=j[F];try{k(!0),l(!0),t(""),V.current&&clearTimeout(V.current),H.current=Date.now();const O=na();z.current=O,s(O),m(r,{role:"assistant",content:"",id:O,parentId:X.parentId||X.id,branchIndex:X.siblingCount||1,isActive:!0}),ye.isConnected||await ye.connect(),ye.send({type:"chat_stream",data:{sessionId:r,content:Z.content,images:Z.images,options:S.generationOptions,assistantMessageId:O,regenerate:!0,originalMessageId:X.id}})}catch(O){console.error("Failed to regenerate message:",O),l(!1),t(""),k(!1),z.current=null,ue.error("Failed to regenerate message")}},[r,k,m,S.generationOptions]),$=A.useCallback(async N=>{const C=je.getState().currentSession;if(!C||!r)return;const F=C.messages.find(O=>O.id===N);if(!F){ue.error("Message not found");return}if(F.isActive!==!1)return;const Z=F.parentId||F.id,X=F.branchIndex||0;try{const O=await vt.switchMessageBranch(r,N,X);if(O.success&&O.data){const re=C.messages.map(le=>le.id===Z||le.parentId===Z?{...le,isActive:le.id===N}:le),Q={...C,messages:re,updatedAt:Date.now()};je.setState(le=>({sessions:le.sessions.map(Me=>Me.id===r?Q:Me),currentSession:Q})),ue.success(`Switched to variant ${X+1}`)}else ue.error(O.error||"Failed to select branch")}catch(O){console.error("Failed to select branch:",O),ue.error("Failed to select branch")}},[r]);return{sendMessage:B,stopGeneration:G,regenerateLastMessage:W,selectBranch:$,isStreaming:n,streamingMessage:e,streamingMessageId:a,toolActivities:c}},Jo=(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"}},s1=()=>{const{t:r}=Ze(),{sessionId:e}=Cn(),t=rs(),a=Dn(),{currentSession:s,sessions:n,models:l,selectedModel:c,setSelectedModel:d,createSession:m,setCurrentSession:f,loadSessions:x,getCurrentPersona:y}=je(),{user:b}=Ar(),{sendMessage:k,stopGeneration:S,regenerateLastMessage:z,selectBranch:E,isStreaming:T,streamingMessage:H,streamingMessageId:V,toolActivities:B}=Zo(s?.id||""),G=y(),{greeting:W,timeSuffix:$}=A.useMemo(()=>Jo(b?.username,r),[b?.username,r]),[N,j]=A.useState(""),[C,F]=A.useState([]),[Z,X]=A.useState(!1),O=A.useRef(null),[re,Q]=A.useState(!1);A.useEffect(()=>{n.length===0&&x()},[x,n.length]),A.useEffect(()=>{(async()=>{try{const ne=await as.getPlugins();Q(!!(ne.success&&ne.data&&ne.data.length>0))}catch{Q(!1)}})()},[]),A.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const ge=n.find(Ce=>Ce.id===e);ge&&ge.id!==s?.id?f(ge):ge||(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 ee=sessionStorage.getItem("pendingMessage");if(ee){sessionStorage.removeItem("pendingMessage");try{const ne=JSON.parse(ee);setTimeout(()=>{k(ne.content,ne.images)},100)}catch(ne){console.error("Failed to parse pending message:",ne)}}}},[s?.id,k]),A.useEffect(()=>{const ee=O.current;ee&&(ee.style.height="auto",ee.style.height=Math.min(ee.scrollHeight,200)+"px")},[N]);const le=async ee=>{if(ee.preventDefault(),!N.trim()||!c)return;const ne={content:N.trim(),images:C.length>0?C:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(ne)),j(""),F([]);const ge=await m(c);ge&&t(`/c/${ge.id}`,{replace:!0})},Me=ee=>{ee.key==="Enter"&&!ee.shiftKey&&(ee.preventDefault(),le(ee))},Ne=async ee=>{const ne=ee.target.value;d(ne)},Ie=(ee,ne,ge)=>{s&&k(ee,ne,ge)};if(!s){const ee=C.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 ne=Date.now(),ge={id:`private-${ne}`,title:r("chat.session.private"),model:c||l[0]?.name||"",messages:[],createdAt:ne,updatedAt:ne,isPrivate:!0};f(ge)},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(ua,{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:W}),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($==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?u.jsxs("div",{className:"w-full",children:[Z&&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(Ko,{images:C,onImagesChange:F,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(a0,{type:"button",variant:"ghost",size:"sm",onClick:()=>X(!Z),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",ee&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",Z&&"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:ee?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(ds,{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"})]}):Z?u.jsx(hs,{className:"h-4 w-4"}):u.jsx(jr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Jr,{ref:O,value:N,onChange:ne=>j(ne.target.value),onKeyDown:Me,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(Mt,{models:l,selectedModel:c,onModelChange:Ne,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:re})}),u.jsx(a0,{type:"submit",variant:"ghost",size:"sm",disabled:!N.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",N.trim()&&c&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:u.jsx(ms,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"sm:hidden mt-4",children:u.jsx(Mt,{models:l,selectedModel:c,onModelChange:Ne,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:re})}),u.jsxs("div",{className:"mt-4 text-center",children:[u.jsxs("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 ",u.jsx("span",{style:{fontSize:"0.6rem"},children:"WebUI"})]})," ",u.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.8.4"]})," ",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:G?.background?{backgroundImage:`url(${G.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[G?.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(ua,{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")]})]})}),G&&!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(Yo,{persona:G,onClear:()=>{if(s){const{sessions:ee}=je.getState(),ne={...s,model:G.model,personaId:void 0},ge=ee.map(Ce=>Ce.id===s.id?ne:Ce);je.setState({sessions:ge,currentSession:ne})}}})}),u.jsx(Lo,{messages:s.messages,streamingMessage:H,streamingMessageId:V,isStreaming:T,toolActivities:B,onRegenerate:z,onSelectBranch:E,className:"flex-1"}),u.jsx(Xo,{onSendMessage:Ie,onStopGeneration:S,disabled:!s})]})]})};export{s1 as ChatPage,s1 as default};
|
|
281
|
+
}`,rows:8,className:"font-mono text-sm"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(a0,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),u.jsx(a0,{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(W0,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},Mt=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:c=!1,onModelsRefresh:d})=>{const{t:m}=Ze(),[f,x]=A.useState(!1),[y,b]=A.useState(""),[k,S]=A.useState("installed"),z=A.useRef(null),E=A.useRef(null),T=rs(),{user:H,systemInfo:V}=Ar(),B=H?.role==="admin"||(V?.allowUserModelPull??!0),[G,W]=A.useState([]),[$,N]=A.useState(!1),[j,C]=A.useState("all"),[F,Z]=A.useState(""),[X,O]=A.useState([]),[re,Q]=A.useState(!1),[le,Me]=A.useState("text-generation"),[Ne,Ie]=A.useState("downloads"),[ee,ne]=A.useState(""),[ge,Ce]=A.useState(null),[u0,Xe]=A.useState({}),[N0,se]=A.useState(null),[me,de]=A.useState(null),[Ge,Te]=A.useState(null),[et,e0]=A.useState(null),q0=["all","popular","chat","code","vision","embedding"],P0=[{type:"personas",label:m("modelSelector.personas"),icon:u.jsx(dr,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>M.isPersona),color:"purple"},{type:"ollama",label:m("modelSelector.ollamaModels"),icon:u.jsx($t,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>!M.isPersona&&!M.isPlugin&&!M.name.includes("embed")),color:"green"},{type:"plugins",label:m("modelSelector.pluginModels"),icon:u.jsx(z0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>M.isPlugin),color:"green"}].filter(M=>M.models.length>0).map(M=>({...M,models:M.models.filter(te=>te.name.toLowerCase().includes(y.toLowerCase())||te.personaName&&te.personaName.toLowerCase().includes(y.toLowerCase())||te.pluginName&&te.pluginName.toLowerCase().includes(y.toLowerCase()))})).filter(M=>M.models.length>0),T0=G.filter(M=>{const te=!y||M.name.toLowerCase().includes(y.toLowerCase())||M.description.toLowerCase().includes(y.toLowerCase()),ce=j==="all"||M.category===j;return te&&ce}),Pe=r.find(M=>M.name===e||e.startsWith("persona:")&&M.name===e),c0=A.useCallback(async()=>{N(!0);try{const M=await $0.getLibraryModels({search:F||void 0,sort:"popular"});M.success&&M.data&&W(M.data)}catch(M){console.error("Failed to load library:",M)}finally{N(!1)}},[F]),qt=A.useCallback(async()=>{Q(!0);try{const M=await aa.getModels({task:le,search:ee||void 0,sort:Ne,limit:30});M.success&&M.data&&O(M.data)}catch(M){console.error("Failed to load HuggingFace models:",M)}finally{Q(!1)}},[le,ee,Ne]),Qr=A.useCallback(async M=>{const[te,ce]=M.split("/");if(!(!te||!ce)){se(M);try{const ze=await aa.getGgufFiles(te,ce);ze.success&&ze.data&&Xe(De=>({...De,[M]:ze.data}))}catch(ze){console.error("Failed to load GGUF files:",ze)}finally{se(null)}}},[]),gn=A.useCallback(M=>{ge===M?Ce(null):(Ce(M),u0[M]||Qr(M))},[ge,u0,Qr]),vn=A.useCallback((M,te)=>{if(!B){ue.error(m("modelSelector.pullRestricted"));return}if(!me){de(M),Te({status:"starting"});try{const ce=$0.pullModelStream(M,ze=>{Te(ze)},()=>{Te(null),de(null),e0(null),ue.success(`Downloaded ${te}`),d?.()},ze=>{Te(null),de(null),e0(null),ue.error(`Failed to download: ${ze}`)});e0(()=>ce)}catch{Te(null),de(null),ue.error("Failed to start download")}}},[B,d,me,m]);A.useEffect(()=>{const M=setTimeout(()=>{k==="huggingface"?ne(y):k==="ollama"&&Z(y)},300);return()=>clearTimeout(M)},[y,k]),A.useEffect(()=>{f&&k==="ollama"&&c0()},[f,k,F,c0]),A.useEffect(()=>{f&&k==="huggingface"&&qt()},[f,k,le,ee,Ne,qt]),A.useEffect(()=>{const M=te=>{z.current&&!z.current.contains(te.target)&&(x(!1),b(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),A.useEffect(()=>{f&&E.current&&E.current.focus()},[f]);const _r=async M=>{x(!1),b("");try{const ce=await $0.listRunningModels();if(ce.success&&ce.data){const ze=ce.data;ze.length>0&&(ze.some(Ht=>Ht.name===M||M.startsWith("persona:"))||await $0.unloadAllModels())}}catch(ce){console.warn("Failed to unload models before switch:",ce)}t({target:{value:M}})},xn=async M=>{if(!B){ue.error(m("modelSelector.pullRestricted"));return}if(!me){de(M),Te({status:"starting"});try{const te=$0.pullModelStream(M,ce=>{Te(ce)},()=>{Te(null),de(null),e0(null),ue.success(`Downloaded ${M}`),d?.()},ce=>{Te(null),de(null),e0(null),ue.error(`Failed to download: ${ce}`)});e0(()=>te)}catch{Te(null),de(null),ue.error("Failed to start download")}}},ea=()=>{et&&(et(),e0(null),de(null),Te(null),ue.success("Download cancelled"))},bn=M=>r.some(te=>te.name===M||te.name.startsWith(M+":")),Pt=M=>M.isPersona?u.jsx(dr,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):M.isPlugin?u.jsx(z0,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):u.jsx($t,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),O0=M=>M.isPersona?M.personaName||M.name:M.isPlugin?`${M.name}`:M.name,Ot=M=>M.isPersona?`via ${M.model}`:M.isPlugin?`via ${M.pluginName}`:null,ta=M=>M>=1e6?`${(M/1e6).toFixed(1)}M`:M>=1e3?`${(M/1e3).toFixed(1)}K`:M.toString(),yn=()=>{if(!Pe)return l?u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx($t,{className:"h-4 w-4"}),u.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:m("modelSelector.selectModel")})]}):m("modelSelector.selectModel");if(l){const ce=O0(Pe);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[Pt(Pe),u.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:ce})]})}const M=O0(Pe),te=Ot(Pe);return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[Pt(Pe),u.jsxs("div",{className:"flex flex-col min-w-0",children:[u.jsx("span",{className:"text-sm font-medium truncate",children:M}),te&&u.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:te})]}),Pe.isPersona&&a&&u.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[u.jsx(xt,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&u.jsx(cs,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})},wn=()=>u.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400",children:[P0.length>0?P0.map(M=>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:[M.icon,M.label," (",M.models.length,")"]})}),M.models.map(te=>u.jsx("div",{onMouseDown:ce=>{ce.preventDefault(),_r(te.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===te.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:[Pt(te),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:O0(te)}),Ot(te)&&u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:Ot(te)})]}),e===te.name&&u.jsx(Nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},te.name))]},M.type)):u.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[u.jsx(Zn,{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:m("models.noModelsFound")})]}),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(jr,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),m("modelSelector.actions")]})}),u.jsx("div",{onMouseDown:M=>{M.preventDefault(),x(!1),T("/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(zr,{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:m("gallery.generate")}),u.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:m("gallery.generateDescription")})]})]})})]})]}),kn=()=>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:q0.map(M=>u.jsx("button",{onMouseDown:te=>{te.preventDefault(),te.stopPropagation(),C(M)},className:Y("px-2.5 py-1 rounded-full text-xs font-medium transition-colors",j===M?"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:M.charAt(0).toUpperCase()+M.slice(1)},M))})}),u.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!B&&u.jsx("div",{className:"mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",children:m("modelSelector.pullRestricted")}),$?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):T0.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(Gt,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:m("models.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:T0.slice(0,50).map(M=>{const te=bn(M.name),ce=me===M.name;return u.jsxs("div",{className:Y("px-3 py-3 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",te&&"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(Gt,{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:M.name}),te&&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:m("modelSelector.installed")})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] line-clamp-1 mt-0.5",children:M.description}),u.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[M.sizes.slice(0,3).map(ze=>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:ze},ze)),M.pulls&&u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1",children:[u.jsx(rt,{className:"h-3 w-3"}),M.pulls]})]})]}),u.jsx("div",{className:"flex-shrink-0",children:ce?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:Ge?.percent!==void 0?`${Ge.percent}%`:"..."}),u.jsx("button",{onClick:ea,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(p0,{className:"h-4 w-4"})})]}):te?u.jsx("button",{onClick:()=>_r(M.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:m("modelSelector.use")}):B?u.jsxs("button",{onClick:()=>xn(M.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(rt,{className:"h-3 w-3 inline mr-1"}),m("modelSelector.pull")]}):u.jsx("span",{className:"px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:m("modelSelector.adminOnlyPull")})})]}),ce&&Ge?.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:`${Ge.percent}%`}})})]},M.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:M=>M.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(Vt,{className:"h-3 w-3"}),m("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),W([]),c0()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(hr,{className:Y("h-3.5 w-3.5 text-gray-400",$&&"animate-spin")})})]})]}),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 space-y-2",children:u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("select",{value:le,onChange:M=>Me(M.target.value),onMouseDown:M=>M.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:m("modelManager.huggingface.taskTextGeneration")}),u.jsx("option",{value:"text-to-speech",children:m("modelManager.huggingface.taskTextToSpeech")}),u.jsx("option",{value:"text-to-image",children:m("modelManager.huggingface.taskTextToImage")}),u.jsx("option",{value:"automatic-speech-recognition",children:m("modelManager.huggingface.taskSpeechRecognition")})]}),u.jsxs("select",{value:Ne,onChange:M=>Ie(M.target.value),onMouseDown:M=>M.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:m("modelManager.huggingface.sortDownloads")}),u.jsx("option",{value:"likes",children:m("modelManager.huggingface.sortLikes")}),u.jsx("option",{value:"lastModified",children:m("modelManager.huggingface.sortRecent")})]})]})}),u.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!B&&u.jsx("div",{className:"mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",children:m("modelSelector.pullRestricted")}),re?u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx(Ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):X.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(z0,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600"}),u.jsx("p",{className:"text-sm",children:m("modelManager.huggingface.noModelsFound")})]}):u.jsx("div",{className:"divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]",children:X.map(M=>{const te=ge===M.id,ce=u0[M.id]||[],ze=N0===M.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:De=>{De.preventDefault(),De.stopPropagation(),gn(M.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(z0,{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:M.id}),M.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 ",M.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(rt,{className:"h-3 w-3"}),ta(M.downloads)]}),u.jsxs("span",{className:"flex items-center gap-1",children:[u.jsx(Jn,{className:"h-3 w-3"}),ta(M.likes)]}),M.pipeline_tag&&u.jsx("span",{className:"px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]",children:M.pipeline_tag})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[u.jsx("a",{href:`https://huggingface.co/${M.id}`,target:"_blank",rel:"noopener noreferrer",onMouseDown:De=>De.stopPropagation(),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(Vt,{className:"h-4 w-4 text-gray-400"})}),u.jsx(D0,{className:Y("h-4 w-4 text-gray-400 transition-transform",te&&"rotate-180")})]})]})}),te&&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:ze?u.jsxs("div",{className:"flex items-center justify-center py-4",children:[u.jsx(Ut,{className:"h-4 w-4 animate-spin text-gray-400"}),u.jsx("span",{className:"ml-2 text-xs text-gray-500",children:m("modelManager.huggingface.checkingGguf")})]}):ce.length===0?u.jsx("div",{className:"py-4 text-center text-xs text-gray-500 dark:text-gray-400",children:m("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:m("modelManager.huggingface.ggufFilesCount",{count:ce.length})}),ce.map(De=>{const Ht=me===De.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:De.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:De.sizeFormatted}),De.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:De.quantization})]})]}),Ht?u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("div",{className:"text-xs text-gray-500 w-12 text-right",children:Ge?.percent!==void 0?`${Ge.percent}%`:"..."}),u.jsx("button",{onMouseDown:H0=>{H0.preventDefault(),H0.stopPropagation(),ea()},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:u.jsx(p0,{className:"h-4 w-4"})})]}):B?u.jsxs("button",{onMouseDown:H0=>{H0.preventDefault(),H0.stopPropagation(),vn(De.ollamaCommand,De.filename)},disabled:!!me,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(rt,{className:"h-3 w-3 inline mr-1"}),m("models.pull")]}):u.jsx("span",{className:"px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:m("modelSelector.adminOnlyPull")})]},De.filename)}),me?.startsWith("hf.co/")&&me.includes(M.id)&&Ge?.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:`${Ge.percent}%`}})})]})})]},M.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:M=>M.stopPropagation(),className:"text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1",children:[u.jsx(Vt,{className:"h-3 w-3"}),m("modelManager.huggingface.browseAllLink")]}),u.jsx("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),qt()},className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:u.jsx(hr,{className:Y("h-3.5 w-3.5 text-gray-400",re&&"animate-spin")})})]})]});return u.jsxs("div",{className:Y("relative",s),ref:z,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?Pe?O0(Pe):m("modelSelector.selectModel"):void 0,children:[yn(),u.jsx(D0,{className:Y(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",f&&"rotate-180")})]}),f&&Tr.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:M=>M.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(os,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),u.jsx("input",{ref:E,type:"text",placeholder:m(k==="installed"?"modelSelector.searchInstalled":k==="ollama"?"modelSelector.searchOllama":"modelSelector.searchHuggingFace"),value:y,onChange:M=>b(M.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:M=>{M.preventDefault(),M.stopPropagation(),S("installed")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(Kn,{className:"h-4 w-4 inline mr-1.5"}),m("modelSelector.installed")]}),u.jsxs("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),S("ollama")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(Gt,{className:"h-4 w-4 inline mr-1.5"}),"Ollama"]}),u.jsxs("button",{onMouseDown:M=>{M.preventDefault(),M.stopPropagation(),S("huggingface")},className:Y("flex-1 px-4 py-2.5 text-sm font-medium transition-colors",k==="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(z0,{className:"h-4 w-4 inline mr-1.5"}),"HuggingFace"]})]})]}),k==="installed"&&wn(),k==="ollama"&&kn(),k==="huggingface"&&Sn()]})]}),document.body),u.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(M=>u.jsx("option",{value:M.name,children:O0(M)},M.name))})]})},Xo=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=Ze(),[s,n]=A.useState(""),[l,c]=A.useState([]),[d,m]=A.useState(null),[f,x]=A.useState(!1),[y,b]=A.useState(null),[k,S]=A.useState(!1),{isGenerating:z,setBackgroundImage:E}=C0(),{currentSession:T,models:H}=je(),V=A.useRef(null);A.useEffect(()=>{(async()=>{try{const C=await as.getPlugins();S(!!(C.success&&C.data&&C.data.length>0))}catch{S(!1)}})()},[]);const B=j=>{j.preventDefault(),!(!s.trim()||z)&&(r(s.trim(),l.length>0?l:void 0,d||void 0),n(""),c([]))},G=j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),B(j))},W=()=>{e()};A.useEffect(()=>{const j=V.current;j&&(j.style.height="auto",j.style.height=Math.min(j.scrollHeight,200)+"px")},[s]),A.useEffect(()=>{(async()=>{if(T?.personaId)try{const C=await sa.getPersona(T.personaId);if(C.success&&C.data)b(C.data);else{console.warn(`Persona ${T.personaId} not found, clearing reference`),b(null);const{setCurrentSession:F}=je.getState();F({...T,personaId:void 0})}}catch(C){if(console.error("Failed to load current persona:",C),b(null),T){const{setCurrentSession:F}=je.getState();F({...T,personaId:void 0})}}else b(null)})()},[T?.personaId]);const $=async j=>{const C=j.target.value;if(T)try{if(C.startsWith("persona:")){const F=C.replace("persona:",""),Z=await sa.getPersona(F);if(!Z.success||!Z.data){at.error("Failed to load persona details");return}const X=Z.data,O=await vt.updateSession(T.id,{personaId:F,model:C});if(O.success&&O.data){const{sessions:re}=je.getState(),Q=re.map(le=>le.id===T.id?O.data:le);je.setState({sessions:Q,currentSession:O.data}),X.background&&E(X.background),at.success(a("chat.persona.applied"))}}else{const F=await vt.updateSession(T.id,{model:C,personaId:void 0});if(F.success&&F.data){const{sessions:Z}=je.getState(),X=Z.map(O=>O.id===T.id?F.data:O);je.setState({sessions:X,currentSession:F.data}),E(null),at.success(a("chat.model.updated"))}}}catch(F){console.error("Failed to update session:",F),at.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(Go,{images:l,onImagesChange:c,maxImages:5,sessionId:T?.id,disabled:t}),u.jsx(Wo,{format:d,onFormatChange:m})]}),u.jsxs("div",{className:"py-2 sm:py-3",children:[u.jsx("form",{onSubmit:B,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(a0,{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(ds,{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(hs,{className:"h-4 w-4"}):u.jsx(jr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Jr,{ref:V,value:s,onChange:j=>n(j.target.value),onKeyDown:G,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:[T&&H.length>0&&u.jsx("div",{className:"hidden sm:block",children:u.jsx(Mt,{models:H,selectedModel:T.personaId?`persona:${T.personaId}`:T.model,onModelChange:$,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:k})}),z?u.jsx(a0,{type:"button",variant:"ghost",size:"sm",onClick:W,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(is,{className:"h-4 w-4"})}):u.jsx(a0,{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(ms,{className:"h-4 w-4"})})]})]})}),T&&H.length>0&&u.jsx("div",{className:"sm:hidden mt-3",children:u.jsx(Mt,{models:H,selectedModel:T.personaId?`persona:${T.personaId}`:T.model,onModelChange:$,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:k})}),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(Uo,{sessionId:T?.id}),u.jsxs("div",{className:"text-center",children:[u.jsxs("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 ",u.jsx("span",{style:{fontSize:"0.85em"},children:"WebUI"})]})," ",u.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.8.5"]})," ",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")]})]})]})]})]})})},Yo=({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),m=()=>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:m(),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(cs,{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&&Tr.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(p0,{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(xt,{className:"h-3 w-3"}),"Enhanced"]})]}),u.jsx("div",{className:"relative px-4 -mt-6",children:u.jsx("img",{src:m(),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(_n,{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(z0,{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(xt,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},Ko=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const{t:s}=Ze(),n=A.useRef(null),[l,c]=A.useState(!1),d=k=>{if(!k)return;const S=[],z=t-r.length;for(let E=0;E<Math.min(k.length,z);E++){const T=k[E];if(!T.type.startsWith("image/")){ue.error(`File ${T.name} is not an image`);continue}if(T.size>10*1024*1024){ue.error(`Image ${T.name} is too large (max 10MB)`);continue}const H=new FileReader;H.onload=V=>{V.target?.result&&(S.push(V.target.result),S.length===Math.min(k.length,z)&&e([...r,...S]))},H.readAsDataURL(T)}k.length>z&&ue.error(`Only ${z} more images can be added`)},m=k=>{k.preventDefault(),c(!0)},f=k=>{k.preventDefault(),c(!1)},x=k=>{k.preventDefault(),c(!1),d(k.dataTransfer.files)},y=k=>{const S=r.filter((z,E)=>E!==k);e(S)},b=r.length<t;return u.jsxs("div",{className:Y("space-y-3",a),children:[b&&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",l&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:m,onDragLeave:f,onDrop:x,children:[u.jsx("input",{ref:n,type:"file",multiple:!0,accept:"image/*",onChange:k=>d(k.target.files),className:"hidden"}),u.jsxs("div",{className:"flex flex-col items-center text-center",children:[u.jsx(us,{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:[s("chat.mediaUpload.dropImagesHere")," ",u.jsx("button",{onClick:()=>n.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:s("chat.mediaUpload.browse")})]}),u.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:s("chat.mediaUpload.supportedFormats")})]})]}),r.length>0&&u.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((k,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:k,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(a0,{variant:"ghost",size:"sm",onClick:()=>y(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(p0,{className:"h-4 w-4"})})})]},S))}),b&&r.length>0&&u.jsxs(a0,{variant:"outline",size:"sm",onClick:()=>n.current?.click(),className:"w-full sm:w-auto",children:[u.jsx(zr,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},Zo=r=>{const[e,t]=A.useState(""),[a,s]=A.useState(null),[n,l]=A.useState(!1),[c,d]=A.useState([]),{addMessage:m,updateMessage:f,updateMessageWithStatistics:x,updateSessionTitle:y,setGeneratingTitleForSession:b}=je(),{setIsGenerating:k,preferences:S}=C0(),z=A.useRef(null),E=A.useRef(null),T=A.useRef(""),H=A.useRef(0),V=A.useRef();A.useEffect(()=>()=>{ye.offMessage("user_message"),ye.offMessage("assistant_chunk"),ye.offMessage("assistant_complete"),ye.offMessage("tool_status"),ye.offMessage("error")},[r]),A.useEffect(()=>{if(!r){ye.offMessage("user_message"),ye.offMessage("assistant_chunk"),ye.offMessage("assistant_complete"),ye.offMessage("tool_status"),ye.offMessage("error");return}return ye.onMessage("user_message",()=>{}),ye.onMessage("assistant_chunk",j=>{const C=j,F=C.messageId||z.current;F&&(T.current=C.total,t(C.total),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{f(r,F,T.current),H.current=Date.now()},C.done?0:200))}),ye.onMessage("tool_status",j=>{const C=j;d(F=>F.find(X=>X.toolCallId===C.toolCallId)?F.map(X=>X.toolCallId===C.toolCallId?{...X,phase:C.phase}:X):[...F,{toolCallId:C.toolCallId,name:C.name,phase:C.phase,startedAt:Date.now()}])}),ye.onMessage("assistant_complete",j=>{const C=j;console.log("Hook: Received assistant_complete for session:",r,"messageId:",C.messageId,"with statistics:",!!C.statistics),l(!1),t(""),k(!1),d([]);const F=C.messageId||z.current;if(C&&F){const Q=T.current||C.content;x(r,F,Q,C.statistics)}const X=C0.getState().preferences.titleSettings,O=je.getState().currentSession,re=E.current;console.log("Auto-title check:",{firstMessage:re,autoTitle:X?.autoTitle,taskModel:X?.taskModel,sessionTitle:O?.title}),re&&X?.autoTitle&&X?.taskModel&&O?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),b(r),vt.generateTitle(r,X.taskModel,re).then(Q=>{console.log("Title generation response:",Q),Q.success&&Q.data?.title&&y(r,Q.data.title)}).catch(Q=>{console.error("Failed to generate title:",Q)}).finally(()=>{b(null)}),E.current=null),z.current=null,T.current="",V.current&&clearTimeout(V.current),H.current=0}),ye.onMessage("error",j=>{const C=j;if(l(!1),t(""),k(!1),z.current=null,C.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(C.error)}),l(!1),t(""),z.current=null,()=>{V.current&&clearTimeout(V.current)}},[r,f,x,k,y,b]);const B=A.useCallback(async(N,j,C)=>{if(!(!r||!N.trim()&&(!j||j.length===0)))try{k(!0),l(!0),t(""),V.current&&clearTimeout(V.current),H.current=Date.now();const F=je.getState().currentSession,Z=F?.isPrivate===!0,X=F?.messages?.some(Q=>Q.role==="user");!Z&&!X&&F?.title==="New Chat"&&(E.current=N.trim()),m(r,{role:"user",content:N.trim(),images:j});const O=na();z.current=O,s(O),m(r,{role:"assistant",content:"",id:O}),ye.isConnected||await ye.connect();const re=Z?F?.messages?.filter(Q=>Q.role!=="system"&&Q.id!==O).map(Q=>({role:Q.role,content:Q.content,images:Q.images})):void 0;ye.send({type:"chat_stream",data:{sessionId:r,content:N.trim(),images:j,format:C,options:S.generationOptions,assistantMessageId:O,isPrivate:Z,model:Z?F?.model:void 0,messageHistory:re}})}catch(F){console.error("Failed to send message:",F),l(!1),t(""),s(null),k(!1),z.current=null,ue.error("Failed to send message")}},[r,m,k,S.generationOptions]),G=A.useCallback(()=>{l(!1),t(""),s(null),k(!1),z.current=null},[k]),W=A.useCallback(async()=>{const N=je.getState().currentSession;if(!N||!r)return;const j=N.messages;let C=-1,F=-1;for(let O=j.length-1;O>=0;O--)if(j[O].role==="assistant"){F=O;break}if(F>0){for(let O=F-1;O>=0;O--)if(j[O].role==="user"){C=O;break}}if(C===-1||F===-1){ue.error("No message to regenerate");return}const Z=j[C],X=j[F];try{k(!0),l(!0),t(""),V.current&&clearTimeout(V.current),H.current=Date.now();const O=na();z.current=O,s(O),m(r,{role:"assistant",content:"",id:O,parentId:X.parentId||X.id,branchIndex:X.siblingCount||1,isActive:!0}),ye.isConnected||await ye.connect(),ye.send({type:"chat_stream",data:{sessionId:r,content:Z.content,images:Z.images,options:S.generationOptions,assistantMessageId:O,regenerate:!0,originalMessageId:X.id}})}catch(O){console.error("Failed to regenerate message:",O),l(!1),t(""),k(!1),z.current=null,ue.error("Failed to regenerate message")}},[r,k,m,S.generationOptions]),$=A.useCallback(async N=>{const C=je.getState().currentSession;if(!C||!r)return;const F=C.messages.find(O=>O.id===N);if(!F){ue.error("Message not found");return}if(F.isActive!==!1)return;const Z=F.parentId||F.id,X=F.branchIndex||0;try{const O=await vt.switchMessageBranch(r,N,X);if(O.success&&O.data){const re=C.messages.map(le=>le.id===Z||le.parentId===Z?{...le,isActive:le.id===N}:le),Q={...C,messages:re,updatedAt:Date.now()};je.setState(le=>({sessions:le.sessions.map(Me=>Me.id===r?Q:Me),currentSession:Q})),ue.success(`Switched to variant ${X+1}`)}else ue.error(O.error||"Failed to select branch")}catch(O){console.error("Failed to select branch:",O),ue.error("Failed to select branch")}},[r]);return{sendMessage:B,stopGeneration:G,regenerateLastMessage:W,selectBranch:$,isStreaming:n,streamingMessage:e,streamingMessageId:a,toolActivities:c}},Jo=(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"}},s1=()=>{const{t:r}=Ze(),{sessionId:e}=Cn(),t=rs(),a=Dn(),{currentSession:s,sessions:n,models:l,selectedModel:c,setSelectedModel:d,createSession:m,setCurrentSession:f,loadSessions:x,getCurrentPersona:y}=je(),{user:b}=Ar(),{sendMessage:k,stopGeneration:S,regenerateLastMessage:z,selectBranch:E,isStreaming:T,streamingMessage:H,streamingMessageId:V,toolActivities:B}=Zo(s?.id||""),G=y(),{greeting:W,timeSuffix:$}=A.useMemo(()=>Jo(b?.username,r),[b?.username,r]),[N,j]=A.useState(""),[C,F]=A.useState([]),[Z,X]=A.useState(!1),O=A.useRef(null),[re,Q]=A.useState(!1);A.useEffect(()=>{n.length===0&&x()},[x,n.length]),A.useEffect(()=>{(async()=>{try{const ne=await as.getPlugins();Q(!!(ne.success&&ne.data&&ne.data.length>0))}catch{Q(!1)}})()},[]),A.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const ge=n.find(Ce=>Ce.id===e);ge&&ge.id!==s?.id?f(ge):ge||(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 ee=sessionStorage.getItem("pendingMessage");if(ee){sessionStorage.removeItem("pendingMessage");try{const ne=JSON.parse(ee);setTimeout(()=>{k(ne.content,ne.images)},100)}catch(ne){console.error("Failed to parse pending message:",ne)}}}},[s?.id,k]),A.useEffect(()=>{const ee=O.current;ee&&(ee.style.height="auto",ee.style.height=Math.min(ee.scrollHeight,200)+"px")},[N]);const le=async ee=>{if(ee.preventDefault(),!N.trim()||!c)return;const ne={content:N.trim(),images:C.length>0?C:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(ne)),j(""),F([]);const ge=await m(c);ge&&t(`/c/${ge.id}`,{replace:!0})},Me=ee=>{ee.key==="Enter"&&!ee.shiftKey&&(ee.preventDefault(),le(ee))},Ne=async ee=>{const ne=ee.target.value;d(ne)},Ie=(ee,ne,ge)=>{s&&k(ee,ne,ge)};if(!s){const ee=C.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 ne=Date.now(),ge={id:`private-${ne}`,title:r("chat.session.private"),model:c||l[0]?.name||"",messages:[],createdAt:ne,updatedAt:ne,isPrivate:!0};f(ge)},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(ua,{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:W}),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($==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?u.jsxs("div",{className:"w-full",children:[Z&&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(Ko,{images:C,onImagesChange:F,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(a0,{type:"button",variant:"ghost",size:"sm",onClick:()=>X(!Z),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",ee&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",Z&&"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:ee?u.jsxs("div",{className:"relative flex items-center justify-center",children:[u.jsx(ds,{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"})]}):Z?u.jsx(hs,{className:"h-4 w-4"}):u.jsx(jr,{className:"h-4 w-4"})}),u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(Jr,{ref:O,value:N,onChange:ne=>j(ne.target.value),onKeyDown:Me,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(Mt,{models:l,selectedModel:c,onModelChange:Ne,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:re})}),u.jsx(a0,{type:"submit",variant:"ghost",size:"sm",disabled:!N.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",N.trim()&&c&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:u.jsx(ms,{className:"h-4 w-4"})})]})}),u.jsx("div",{className:"sm:hidden mt-4",children:u.jsx(Mt,{models:l,selectedModel:c,onModelChange:Ne,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:re})}),u.jsxs("div",{className:"mt-4 text-center",children:[u.jsxs("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 ",u.jsx("span",{style:{fontSize:"0.6rem"},children:"WebUI"})]})," ",u.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.8.5"]})," ",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:G?.background?{backgroundImage:`url(${G.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[G?.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(ua,{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")]})]})}),G&&!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(Yo,{persona:G,onClear:()=>{if(s){const{sessions:ee}=je.getState(),ne={...s,model:G.model,personaId:void 0},ge=ee.map(Ce=>Ce.id===s.id?ne:Ce);je.setState({sessions:ge,currentSession:ne})}}})}),u.jsx(Lo,{messages:s.messages,streamingMessage:H,streamingMessageId:V,isStreaming:T,toolActivities:B,onRegenerate:z,onSelectBranch:E,className:"flex-1"}),u.jsx(Xo,{onSendMessage:Ie,onStopGeneration:S,disabled:!s})]})]})};export{s1 as ChatPage,s1 as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as l,e as A}from"./router-vendor-DdQhGl5t.js";import{a as q,c as d,i as E,B as T}from"../assets/index-DW8C1vVk.js";import{X as Q,ad as H,aB as U,aq as W,k as M,T as $,F as k,L,aC as X,I as F,u as J,t as O}from"./ui-vendor-C4ZcWovR.js";import"./utils-vendor-BFlGJDIj.js";const V=({image:r,onClose:o,onDelete:h,onDownload:s})=>{const{t:i}=q();l.useEffect(()=>{const n=m=>{m.key==="Escape"&&o()};return document.addEventListener("keydown",n),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",n),document.body.style.overflow=""}},[o]);const j=n=>new Date(n).toLocaleString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}),f=()=>{if(s)s(r);else{const n=document.createElement("a");n.href=r.imageData,n.download=`generated-${r.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)}};return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center",onClick:o,children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-sm"}),e.jsxs("div",{className:"relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4",onClick:n=>n.stopPropagation(),children:[e.jsx("button",{onClick:o,className:d("absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10","p-2 rounded-full","bg-white/10 hover:bg-white/20","transition-colors"),children:e.jsx(Q,{className:"h-6 w-6 text-white"})}),e.jsx("div",{className:"flex-1 flex items-center justify-center min-h-0",children:e.jsx("img",{src:r.imageData,alt:r.prompt,className:"max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg"})}),e.jsxs("div",{className:d("w-full lg:w-80 flex-shrink-0","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","rounded-xl p-4 lg:p-5","overflow-y-auto max-h-[25vh] lg:max-h-[90vh]"),children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-1",children:i("gallery.prompt")}),e.jsx("p",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] text-sm leading-relaxed",children:r.prompt})]}),e.jsxs("div",{className:"space-y-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(H,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.model"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.model})]}),r.size&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(U,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.size"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.size})]}),r.quality&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 ophelia:text-[#525252] text-xs font-bold",children:"Q"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.quality"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] capitalize",children:r.quality})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(W,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.created"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:j(r.createdAt)})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#262626]",children:[e.jsxs("button",{onClick:f,className:d("flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white font-medium text-sm","transition-colors"),children:[e.jsx(M,{className:"h-4 w-4"}),i("gallery.download")]}),h&&e.jsx("button",{onClick:()=>h(r.id),className:d("p-2.5 rounded-lg","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/30","text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3]","hover:text-red-600 dark:hover:text-red-400 ophelia:hover:text-red-400","transition-colors"),title:"Delete image",children:e.jsx($,{className:"h-4 w-4"})})]})]})]})]}),document.body)},Y=({onImageCountChange:r})=>{const{t:o}=q(),[h,s]=l.useState([]),[i,j]=l.useState(0),[f,n]=l.useState(!0),[m,G]=l.useState(!1),[p,S]=l.useState(null),[b,C]=l.useState(null),P=20,N=l.useCallback(async(t=0,u=!1)=>{try{t===0?n(!0):G(!0);const c=await E.getGallery({limit:P,offset:t});c.success&&c.data&&(s(u?v=>[...v,...c.data.images]:c.data.images),j(c.data.total),r?.(c.data.total))}catch(c){console.error("Failed to load gallery:",c),k.error(o("imageGallery.loadFailed"))}finally{n(!1),G(!1)}},[r,o]);l.useEffect(()=>{N()},[N]);const D=()=>{N(h.length,!0)},z=async(t,u)=>{if(u.stopPropagation(),!b){C(t);try{(await E.deleteGalleryImage(t)).success?(s(v=>v.filter(y=>y.id!==t)),j(v=>v-1),r?.(i-1),k.success(o("imageGallery.deleteSuccess")),p?.id===t&&S(null)):k.error(o("imageGallery.deleteFailed"))}catch(c){console.error("Failed to delete image:",c),k.error(o("imageGallery.deleteFailed"))}finally{C(null)}}},w=(t,u)=>{u.stopPropagation();const c=document.createElement("a");c.href=t.imageData,c.download=`generated-${t.id}.png`,document.body.appendChild(c),c.click(),document.body.removeChild(c)},I=t=>new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return f?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(L,{className:"h-8 w-8 animate-spin text-gray-400 dark:text-gray-500"})}):h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(X,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 ophelia:text-[#404040] mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] mb-2",children:o("imageGallery.noImages")}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm",children:o("imageGallery.noImagesHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:d("columns-1 sm:columns-2 lg:columns-3 xl:columns-4","gap-4 space-y-4"),children:h.map(t=>e.jsxs("div",{className:d("break-inside-avoid group relative cursor-pointer","rounded-xl overflow-hidden","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#404040]","transition-all duration-200","hover:shadow-lg dark:hover:shadow-dark-400/20 ophelia:hover:shadow-[#9333ea]/10"),onClick:()=>S(t),children:[e.jsx("img",{src:t.imageData,alt:t.prompt,className:"w-full h-auto object-cover",loading:"lazy"}),e.jsxs("div",{className:d("absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent","opacity-0 group-hover:opacity-100 transition-opacity duration-200","flex flex-col justify-end p-3"),children:[e.jsx("p",{className:"text-white text-sm line-clamp-2 mb-2",children:t.prompt}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-white/70 text-xs",children:I(t.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:u=>w(t,u),className:d("p-1.5 rounded-lg","bg-white/20 hover:bg-white/30","transition-colors"),title:o("imageGallery.download"),children:e.jsx(M,{className:"h-4 w-4 text-white"})}),e.jsx("button",{onClick:u=>z(t.id,u),disabled:b===t.id,className:d("p-1.5 rounded-lg","bg-white/20 hover:bg-red-500/80","transition-colors",b===t.id&&"opacity-50 cursor-not-allowed"),title:o("imageGallery.delete"),children:b===t.id?e.jsx(L,{className:"h-4 w-4 text-white animate-spin"}):e.jsx($,{className:"h-4 w-4 text-white"})})]})]})]})]},t.id))}),h.length<i&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:D,disabled:m,className:d("px-6 py-2.5 rounded-xl font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]","text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 animate-spin"}),o("common.loading")]}):o("imageGallery.loadMore",{current:h.length,total:i})})}),p&&e.jsx(V,{image:p,onClose:()=>S(null),onDelete:t=>{z(t,{stopPropagation:()=>{}})},onDownload:t=>{w(t,{stopPropagation:()=>{}})}})]})},Z=({isOpen:r,onClose:o,onImageGenerated:h})=>{const{t:s}=q(),[i,j]=l.useState([]),[f,n]=l.useState(""),[m,G]=l.useState(""),[p,S]=l.useState(""),[b,C]=l.useState("1024x1024"),[P,N]=l.useState("standard"),[D,z]=l.useState(!1),[w,I]=l.useState(null),[t,u]=l.useState(["512x512","768x768","1024x1024"]),[c,v]=l.useState(["standard","high"]),[y,_]=l.useState(null);l.useEffect(()=>{r&&(async()=>{try{const x=await E.getPlugins();if(x.success&&x.data&&(j(x.data),x.data.length>0)){const g=x.data[0];n(g.id),g.models.length>0&&G(g.models[0]),g.config?.sizes&&(u(g.config.sizes),C(g.config.default_size||g.config.sizes[0]||"1024x1024")),g.config?.qualities&&(v(g.config.qualities),N(g.config.default_quality||g.config.qualities[0]||"standard")),_(g.config?.max_prompt_length??null)}}catch(x){console.error("Failed to load image generation plugins:",x)}})()},[r]),l.useEffect(()=>{const a=i.find(x=>x.id===f);a&&(a.models.length>0&&!a.models.includes(m)&&G(a.models[0]),a.config?.sizes&&(u(a.config.sizes),a.config.sizes.includes(b)||C(a.config.default_size||a.config.sizes[0])),a.config?.qualities&&(v(a.config.qualities),a.config.qualities.includes(P)||N(a.config.default_quality||a.config.qualities[0])),_(a.config?.max_prompt_length??null))},[f,i,m,b,P]);const B=async()=>{if(!m||!p.trim()){k.error(s("imageGeneration.enterPrompt"));return}if(y&&p.length>y){k.error(s("imageGeneration.promptTooLong",{max:y.toLocaleString()}));return}z(!0),I(null);try{const a=await E.generate({model:m,prompt:p.trim(),size:b,quality:P});if(a.success&&a.data?.images&&a.data.images.length>0){const x=a.data.images[0];let g=null;x.b64_json?g=`data:image/png;base64,${x.b64_json}`:x.url&&(g=x.url),g&&(k.success(s("imageGeneration.success")),h?(h(g,p.trim(),m),S(""),I(null),o()):I(g))}else k.error(s("imageGeneration.failed"))}catch(a){console.error("Image generation failed:",a);const x=a instanceof Error?a.message:s("imageGeneration.failed");k.error(x)}finally{z(!1)}},K=()=>{if(!w)return;const a=document.createElement("a");a.href=w,a.download=`generated-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a)};if(!r)return null;const R=i.find(a=>a.id===f);return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:o}),e.jsxs("div",{className:d("relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]","rounded-2xl shadow-2xl","w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col"),onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:s("imageGeneration.title")})]}),e.jsx("button",{onClick:o,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors",children:e.jsx(Q,{className:"h-5 w-5 text-gray-500 dark:text-gray-400"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:i.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:s("imageGeneration.noModels")}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:s("imageGeneration.configurePlugin")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("settings.plugins.title")}),e.jsx("select",{value:f,onChange:a=>n(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:i.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.model")}),e.jsx("select",{value:m,onChange:a=>G(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:R?.models.map(a=>e.jsx("option",{value:a,children:a},a))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.size")}),e.jsx("select",{value:b,onChange:a=>C(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:t.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.quality")}),e.jsx("select",{value:P,onChange:a=>N(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:c.map(a=>e.jsx("option",{value:a,children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.prompt")}),e.jsx("textarea",{value:p,onChange:a=>S(a.target.value),placeholder:s("imageGeneration.promptPlaceholder"),rows:5,className:d("w-full px-3 py-2 rounded-lg text-sm resize-none","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 dark:placeholder-gray-400 ophelia:placeholder-[#737373]","focus:outline-none focus:ring-2 focus:ring-primary-500/20",y&&p.length>y&&"border-red-500 dark:border-red-500 ophelia:border-red-500")}),y&&e.jsxs("div",{className:d("text-xs mt-1 text-right",p.length>y?"text-red-500":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]"),children:[p.length.toLocaleString()," /"," ",y.toLocaleString()]})]}),w&&e.jsxs("div",{className:"relative rounded-xl overflow-hidden border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]",children:[e.jsx("img",{src:w,alt:"Generated",className:"w-full h-auto"}),e.jsx("button",{onClick:K,className:d("absolute bottom-3 right-3 p-2 rounded-lg","bg-white/90 dark:bg-dark-100/90 ophelia:bg-[#0a0a0a]/90","hover:bg-white dark:hover:bg-dark-100 ophelia:hover:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors"),title:s("imageGallery.download"),children:e.jsx(M,{className:"h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]"})})]})]})}),i.length>0&&e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:e.jsx(T,{onClick:B,disabled:D||!p.trim()||!m,className:d("w-full py-2.5 rounded-xl font-medium","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors"),children:D?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 animate-spin"}),s("imageGeneration.generating")]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(J,{className:"h-4 w-4"}),s("imageGeneration.generate")]})})})]})]}),document.body)},le=()=>{const{t:r}=q(),[o,h]=l.useState(null),[s,i]=l.useState(!1),[j,f]=l.useState(0),n=l.useCallback(()=>{f(m=>m+1)},[]);return e.jsxs("div",{className:"h-full overflow-auto",children:[e.jsxs("div",{className:"max-w-7xl mx-auto p-6",children:[e.jsxs("div",{className:"text-center max-w-md mx-auto mb-8",children:[e.jsx("h2",{className:"libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa] mb-3",style:{fontWeight:300,letterSpacing:"0.01em"},children:r("sidebar.navigation.imagine")}),e.jsxs("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:[r("gallery.subtitle"),o!==null&&o>0&&e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:[" ","· ",r("gallery.imageCount",{count:o})]})]}),e.jsxs(T,{onClick:()=>i(!0),className:d("mt-4 px-6 py-2.5 rounded-xl font-medium","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white","transition-colors"),children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),r("gallery.generate")]})]}),e.jsx(Y,{onImageCountChange:h},j)]}),e.jsx(Z,{isOpen:s,onClose:()=>i(!1),onImageGenerated:n})]})};export{le as GalleryPage,le as default};
|
|
1
|
+
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as l,e as A}from"./router-vendor-DdQhGl5t.js";import{a as q,c as d,i as E,B as T}from"../assets/index-fnpCaKr_.js";import{X as Q,ad as H,aB as U,aq as W,k as M,T as $,F as k,L,aC as X,I as F,u as J,t as O}from"./ui-vendor-C4ZcWovR.js";import"./utils-vendor-BFlGJDIj.js";const V=({image:r,onClose:o,onDelete:h,onDownload:s})=>{const{t:i}=q();l.useEffect(()=>{const n=m=>{m.key==="Escape"&&o()};return document.addEventListener("keydown",n),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",n),document.body.style.overflow=""}},[o]);const j=n=>new Date(n).toLocaleString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}),f=()=>{if(s)s(r);else{const n=document.createElement("a");n.href=r.imageData,n.download=`generated-${r.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)}};return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center",onClick:o,children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-sm"}),e.jsxs("div",{className:"relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4",onClick:n=>n.stopPropagation(),children:[e.jsx("button",{onClick:o,className:d("absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10","p-2 rounded-full","bg-white/10 hover:bg-white/20","transition-colors"),children:e.jsx(Q,{className:"h-6 w-6 text-white"})}),e.jsx("div",{className:"flex-1 flex items-center justify-center min-h-0",children:e.jsx("img",{src:r.imageData,alt:r.prompt,className:"max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg"})}),e.jsxs("div",{className:d("w-full lg:w-80 flex-shrink-0","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","rounded-xl p-4 lg:p-5","overflow-y-auto max-h-[25vh] lg:max-h-[90vh]"),children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-1",children:i("gallery.prompt")}),e.jsx("p",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] text-sm leading-relaxed",children:r.prompt})]}),e.jsxs("div",{className:"space-y-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(H,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.model"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.model})]}),r.size&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(U,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.size"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.size})]}),r.quality&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 ophelia:text-[#525252] text-xs font-bold",children:"Q"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.quality"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] capitalize",children:r.quality})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(W,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[i("gallery.created"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:j(r.createdAt)})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#262626]",children:[e.jsxs("button",{onClick:f,className:d("flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white font-medium text-sm","transition-colors"),children:[e.jsx(M,{className:"h-4 w-4"}),i("gallery.download")]}),h&&e.jsx("button",{onClick:()=>h(r.id),className:d("p-2.5 rounded-lg","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/30","text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3]","hover:text-red-600 dark:hover:text-red-400 ophelia:hover:text-red-400","transition-colors"),title:"Delete image",children:e.jsx($,{className:"h-4 w-4"})})]})]})]})]}),document.body)},Y=({onImageCountChange:r})=>{const{t:o}=q(),[h,s]=l.useState([]),[i,j]=l.useState(0),[f,n]=l.useState(!0),[m,G]=l.useState(!1),[p,S]=l.useState(null),[b,C]=l.useState(null),P=20,N=l.useCallback(async(t=0,u=!1)=>{try{t===0?n(!0):G(!0);const c=await E.getGallery({limit:P,offset:t});c.success&&c.data&&(s(u?v=>[...v,...c.data.images]:c.data.images),j(c.data.total),r?.(c.data.total))}catch(c){console.error("Failed to load gallery:",c),k.error(o("imageGallery.loadFailed"))}finally{n(!1),G(!1)}},[r,o]);l.useEffect(()=>{N()},[N]);const D=()=>{N(h.length,!0)},z=async(t,u)=>{if(u.stopPropagation(),!b){C(t);try{(await E.deleteGalleryImage(t)).success?(s(v=>v.filter(y=>y.id!==t)),j(v=>v-1),r?.(i-1),k.success(o("imageGallery.deleteSuccess")),p?.id===t&&S(null)):k.error(o("imageGallery.deleteFailed"))}catch(c){console.error("Failed to delete image:",c),k.error(o("imageGallery.deleteFailed"))}finally{C(null)}}},w=(t,u)=>{u.stopPropagation();const c=document.createElement("a");c.href=t.imageData,c.download=`generated-${t.id}.png`,document.body.appendChild(c),c.click(),document.body.removeChild(c)},I=t=>new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return f?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(L,{className:"h-8 w-8 animate-spin text-gray-400 dark:text-gray-500"})}):h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(X,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 ophelia:text-[#404040] mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] mb-2",children:o("imageGallery.noImages")}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm",children:o("imageGallery.noImagesHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:d("columns-1 sm:columns-2 lg:columns-3 xl:columns-4","gap-4 space-y-4"),children:h.map(t=>e.jsxs("div",{className:d("break-inside-avoid group relative cursor-pointer","rounded-xl overflow-hidden","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#404040]","transition-all duration-200","hover:shadow-lg dark:hover:shadow-dark-400/20 ophelia:hover:shadow-[#9333ea]/10"),onClick:()=>S(t),children:[e.jsx("img",{src:t.imageData,alt:t.prompt,className:"w-full h-auto object-cover",loading:"lazy"}),e.jsxs("div",{className:d("absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent","opacity-0 group-hover:opacity-100 transition-opacity duration-200","flex flex-col justify-end p-3"),children:[e.jsx("p",{className:"text-white text-sm line-clamp-2 mb-2",children:t.prompt}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-white/70 text-xs",children:I(t.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:u=>w(t,u),className:d("p-1.5 rounded-lg","bg-white/20 hover:bg-white/30","transition-colors"),title:o("imageGallery.download"),children:e.jsx(M,{className:"h-4 w-4 text-white"})}),e.jsx("button",{onClick:u=>z(t.id,u),disabled:b===t.id,className:d("p-1.5 rounded-lg","bg-white/20 hover:bg-red-500/80","transition-colors",b===t.id&&"opacity-50 cursor-not-allowed"),title:o("imageGallery.delete"),children:b===t.id?e.jsx(L,{className:"h-4 w-4 text-white animate-spin"}):e.jsx($,{className:"h-4 w-4 text-white"})})]})]})]})]},t.id))}),h.length<i&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:D,disabled:m,className:d("px-6 py-2.5 rounded-xl font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]","text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 animate-spin"}),o("common.loading")]}):o("imageGallery.loadMore",{current:h.length,total:i})})}),p&&e.jsx(V,{image:p,onClose:()=>S(null),onDelete:t=>{z(t,{stopPropagation:()=>{}})},onDownload:t=>{w(t,{stopPropagation:()=>{}})}})]})},Z=({isOpen:r,onClose:o,onImageGenerated:h})=>{const{t:s}=q(),[i,j]=l.useState([]),[f,n]=l.useState(""),[m,G]=l.useState(""),[p,S]=l.useState(""),[b,C]=l.useState("1024x1024"),[P,N]=l.useState("standard"),[D,z]=l.useState(!1),[w,I]=l.useState(null),[t,u]=l.useState(["512x512","768x768","1024x1024"]),[c,v]=l.useState(["standard","high"]),[y,_]=l.useState(null);l.useEffect(()=>{r&&(async()=>{try{const x=await E.getPlugins();if(x.success&&x.data&&(j(x.data),x.data.length>0)){const g=x.data[0];n(g.id),g.models.length>0&&G(g.models[0]),g.config?.sizes&&(u(g.config.sizes),C(g.config.default_size||g.config.sizes[0]||"1024x1024")),g.config?.qualities&&(v(g.config.qualities),N(g.config.default_quality||g.config.qualities[0]||"standard")),_(g.config?.max_prompt_length??null)}}catch(x){console.error("Failed to load image generation plugins:",x)}})()},[r]),l.useEffect(()=>{const a=i.find(x=>x.id===f);a&&(a.models.length>0&&!a.models.includes(m)&&G(a.models[0]),a.config?.sizes&&(u(a.config.sizes),a.config.sizes.includes(b)||C(a.config.default_size||a.config.sizes[0])),a.config?.qualities&&(v(a.config.qualities),a.config.qualities.includes(P)||N(a.config.default_quality||a.config.qualities[0])),_(a.config?.max_prompt_length??null))},[f,i,m,b,P]);const B=async()=>{if(!m||!p.trim()){k.error(s("imageGeneration.enterPrompt"));return}if(y&&p.length>y){k.error(s("imageGeneration.promptTooLong",{max:y.toLocaleString()}));return}z(!0),I(null);try{const a=await E.generate({model:m,prompt:p.trim(),size:b,quality:P});if(a.success&&a.data?.images&&a.data.images.length>0){const x=a.data.images[0];let g=null;x.b64_json?g=`data:image/png;base64,${x.b64_json}`:x.url&&(g=x.url),g&&(k.success(s("imageGeneration.success")),h?(h(g,p.trim(),m),S(""),I(null),o()):I(g))}else k.error(s("imageGeneration.failed"))}catch(a){console.error("Image generation failed:",a);const x=a instanceof Error?a.message:s("imageGeneration.failed");k.error(x)}finally{z(!1)}},K=()=>{if(!w)return;const a=document.createElement("a");a.href=w,a.download=`generated-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a)};if(!r)return null;const R=i.find(a=>a.id===f);return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:o}),e.jsxs("div",{className:d("relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]","rounded-2xl shadow-2xl","w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col"),onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:s("imageGeneration.title")})]}),e.jsx("button",{onClick:o,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors",children:e.jsx(Q,{className:"h-5 w-5 text-gray-500 dark:text-gray-400"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:i.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:s("imageGeneration.noModels")}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:s("imageGeneration.configurePlugin")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("settings.plugins.title")}),e.jsx("select",{value:f,onChange:a=>n(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:i.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.model")}),e.jsx("select",{value:m,onChange:a=>G(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:R?.models.map(a=>e.jsx("option",{value:a,children:a},a))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.size")}),e.jsx("select",{value:b,onChange:a=>C(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:t.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.quality")}),e.jsx("select",{value:P,onChange:a=>N(a.target.value),className:d("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:c.map(a=>e.jsx("option",{value:a,children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.prompt")}),e.jsx("textarea",{value:p,onChange:a=>S(a.target.value),placeholder:s("imageGeneration.promptPlaceholder"),rows:5,className:d("w-full px-3 py-2 rounded-lg text-sm resize-none","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 dark:placeholder-gray-400 ophelia:placeholder-[#737373]","focus:outline-none focus:ring-2 focus:ring-primary-500/20",y&&p.length>y&&"border-red-500 dark:border-red-500 ophelia:border-red-500")}),y&&e.jsxs("div",{className:d("text-xs mt-1 text-right",p.length>y?"text-red-500":"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]"),children:[p.length.toLocaleString()," /"," ",y.toLocaleString()]})]}),w&&e.jsxs("div",{className:"relative rounded-xl overflow-hidden border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]",children:[e.jsx("img",{src:w,alt:"Generated",className:"w-full h-auto"}),e.jsx("button",{onClick:K,className:d("absolute bottom-3 right-3 p-2 rounded-lg","bg-white/90 dark:bg-dark-100/90 ophelia:bg-[#0a0a0a]/90","hover:bg-white dark:hover:bg-dark-100 ophelia:hover:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors"),title:s("imageGallery.download"),children:e.jsx(M,{className:"h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]"})})]})]})}),i.length>0&&e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:e.jsx(T,{onClick:B,disabled:D||!p.trim()||!m,className:d("w-full py-2.5 rounded-xl font-medium","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors"),children:D?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 animate-spin"}),s("imageGeneration.generating")]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(J,{className:"h-4 w-4"}),s("imageGeneration.generate")]})})})]})]}),document.body)},le=()=>{const{t:r}=q(),[o,h]=l.useState(null),[s,i]=l.useState(!1),[j,f]=l.useState(0),n=l.useCallback(()=>{f(m=>m+1)},[]);return e.jsxs("div",{className:"h-full overflow-auto",children:[e.jsxs("div",{className:"max-w-7xl mx-auto p-6",children:[e.jsxs("div",{className:"text-center max-w-md mx-auto mb-8",children:[e.jsx("h2",{className:"libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa] mb-3",style:{fontWeight:300,letterSpacing:"0.01em"},children:r("sidebar.navigation.imagine")}),e.jsxs("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:[r("gallery.subtitle"),o!==null&&o>0&&e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:[" ","· ",r("gallery.imageCount",{count:o})]})]}),e.jsxs(T,{onClick:()=>i(!0),className:d("mt-4 px-6 py-2.5 rounded-xl font-medium","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white","transition-colors"),children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),r("gallery.generate")]})]}),e.jsx(Y,{onImageCountChange:h},j)]}),e.jsx(Z,{isOpen:s,onClose:()=>i(!1),onImageGenerated:n})]})};export{le as GalleryPage,le as default};
|