libre-webui 0.3.0 → 0.3.2
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/README.md +53 -21
- package/backend/dist/services/pluginService.d.ts.map +1 -1
- package/backend/dist/services/pluginService.js +9 -2
- package/backend/dist/services/pluginService.js.map +1 -1
- package/frontend/dist/assets/{index-BAlYrgVl.js → index-BbJ5OmoO.js} +4 -4
- package/frontend/dist/index.html +5 -5
- package/frontend/dist/js/{ArtifactContainer-DOyRNr2K.js → ArtifactContainer-BeIYvOxW.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-DuHnKjTy.js → ArtifactDemoPage-DLNsXpdK.js} +1 -1
- package/frontend/dist/js/{ChatPage-D4AGvUr9.js → ChatPage-B1ySV3lW.js} +2 -2
- package/frontend/dist/js/{GalleryPage-DPxs-JHF.js → GalleryPage-BRYMP7Q3.js} +1 -1
- package/frontend/dist/js/{ModelsPage-CDx8DvZ8.js → ModelsPage-7lF58OTC.js} +1 -1
- package/frontend/dist/js/{PersonasPage-CHDGv_Lh.js → PersonasPage-Cc_gMLv0.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-COb0e5_w.js → UserManagementPage-DqV3zxVm.js} +1 -1
- package/frontend/dist/js/{markdown-vendor-DRtqGHm3.js → markdown-vendor-YWiGftdn.js} +1 -1
- package/frontend/dist/js/router-vendor-CnU0qKrY.js +3 -0
- package/frontend/dist/js/{ui-vendor-DA07XX1l.js → ui-vendor-CdKqcMKK.js} +1 -1
- package/frontend/dist/js/{utils-vendor-DNzxLBGx.js → utils-vendor-DEeF42mN.js} +1 -1
- package/package.json +1 -2
- package/frontend/dist/js/router-vendor-B-t91v39.js +0 -3
package/frontend/dist/index.html
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
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-BbJ5OmoO.js"></script>
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/js/react-vendor-N--QU9DW.js">
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/js/router-vendor-
|
|
15
|
-
<link rel="modulepreload" crossorigin href="/js/markdown-vendor-
|
|
16
|
-
<link rel="modulepreload" crossorigin href="/js/ui-vendor-
|
|
17
|
-
<link rel="modulepreload" crossorigin href="/js/utils-vendor-
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/js/router-vendor-CnU0qKrY.js">
|
|
15
|
+
<link rel="modulepreload" crossorigin href="/js/markdown-vendor-YWiGftdn.js">
|
|
16
|
+
<link rel="modulepreload" crossorigin href="/js/ui-vendor-CdKqcMKK.js">
|
|
17
|
+
<link rel="modulepreload" crossorigin href="/js/utils-vendor-DEeF42mN.js">
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/css/index-CYRSPYSA.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-
|
|
1
|
+
import{j as e}from"./markdown-vendor-YWiGftdn.js";import{r as c}from"./router-vendor-CnU0qKrY.js";import{u as U,c as T,B as a,O as j}from"../assets/index-BbJ5OmoO.js";import{h as y,F as w,C as k,H as N,f,av as C,E as _,J as z,N as S,O as I,Q as O}from"./ui-vendor-CdKqcMKK.js";const M=({artifact:s,className:i})=>{const[n,h]=c.useState(!1),[l,d]=c.useState("preview"),R=c.useRef(null),{theme:m,openArtifactPanel:x}=U(),g=async r=>{try{await navigator.clipboard.writeText(r),h(!0),setTimeout(()=>h(!1),2e3)}catch(t){console.error("Failed to copy:",t)}},p=()=>{const r=new Blob([s.content],{type:A(s.type)}),t=URL.createObjectURL(r),o=document.createElement("a");o.href=t,o.download=`${s.title}.${D(s.type)}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(t)},A=r=>{switch(r){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"}},D=r=>{switch(r){case"html":return"html";case"react":return"jsx";case"svg":return"svg";case"css":return"css";case"json":return"json";default:return"txt"}},u=()=>{switch(s.type){case"html":return e.jsx(I,{className:"h-4 w-4"});case"react":return e.jsx(S,{className:"h-4 w-4"});case"svg":return e.jsx(z,{className:"h-4 w-4"});case"code":return e.jsx(S,{className:"h-4 w-4"});default:return e.jsx(z,{className:"h-4 w-4"})}},E=()=>{const r=`
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html>
|
|
4
4
|
<head>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-
|
|
1
|
+
import{j as e}from"./markdown-vendor-YWiGftdn.js";import{r as d}from"./router-vendor-CnU0qKrY.js";import{A as c}from"./ArtifactContainer-BeIYvOxW.js";import{B as l}from"../assets/index-BbJ5OmoO.js";import"./react-vendor-N--QU9DW.js";import"./ui-vendor-CdKqcMKK.js";import"./utils-vendor-DEeF42mN.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 k0,f as q0,m as u0,s as Bn,a as In,c as En,v as Fn,S as qn,j as d,M as Rn}from"./markdown-vendor-
|
|
1
|
+
import{o as k0,f as q0,m as u0,s as Bn,a as In,c as En,v as Fn,S as qn,j as d,M as Rn}from"./markdown-vendor-YWiGftdn.js";import{R as Bt,r as E,c as Xt,a as fa,b as On,u as Ln}from"./router-vendor-CnU0qKrY.js";import{u as g0,c as K,O as Pn,t as Yt,a as ga,b as ye,p as yr,f as Hn,d as It,S as Gn,T as $n,B as Ve,i as va,e as wr,g as J0,w as ve,h as kr}from"../assets/index-BbJ5OmoO.js";import{C as nt,H as xa,b as Vn,e as z0,q as Un,L as ba,i as ya,a0 as Wn,V as Xn,o as Et,a1 as Yn,t as wa,a2 as Kn,X as v0,s as Jn,d as Sr,a3 as Z0,a4 as Zn,a5 as Qn,F as _n,U as ka,J as Sa,a6 as es,z as de,a7 as ts,N as rs,B as ft,Z as Ft,k as as,r as Kt,I as Ma,n as Na,a8 as Ta,a9 as za,aa as Aa,x as R0,ab as ns,c as ss}from"./ui-vendor-CdKqcMKK.js";import{A as is}from"./ArtifactContainer-BeIYvOxW.js";import"./react-vendor-N--QU9DW.js";import"./utils-vendor-DEeF42mN.js";function ls(r,e){const t=String(r);let a=t.indexOf(e),n=a,s=0,l=0;for(;a!==-1;)a===n?++s>l&&(l=s):s=1,n=a+e.length,a=t.indexOf(e,n);return l}function os(){return{enter:{mathFlow:r,mathFlowFenceMeta:e,mathText:s},exit:{mathFlow:n,mathFlowFence:a,mathFlowFenceMeta:t,mathFlowValue:u,mathText:l,mathTextData:u}};function r(c){const p={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[p]}},c)}function e(){this.buffer()}function t(){const c=this.resume(),p=this.stack[this.stack.length-1];k0(p.type==="math"),p.meta=c}function a(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function n(c){const p=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),f=this.stack[this.stack.length-1];k0(f.type==="math"),this.exit(c),f.value=p;const g=f.data.hChildren[0];k0(g.type==="element"),k0(g.tagName==="code"),g.children.push({type:"text",value:p}),this.data.mathFlowInside=void 0}function s(c){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},c),this.buffer()}function l(c){const p=this.resume(),f=this.stack[this.stack.length-1];k0(f.type==="inlineMath"),this.exit(c),f.value=p,f.data.hChildren.push({type:"text",value:p})}function u(c){this.config.enter.data.call(this,c),this.config.exit.data.call(this,c)}}function us(r){let e=(r||{}).singleDollarTextMath;return e==null&&(e=!0),a.peek=n,{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(s,l,u,c){const p=s.value||"",f=u.createTracker(c),g="$".repeat(Math.max(ls(p,"$")+1,2)),b=u.enter("mathFlow");let w=f.move(g);if(s.meta){const S=u.enter("mathFlowMeta");w+=f.move(u.safe(s.meta,{after:`
|
|
3
3
|
`,before:w,encode:["$"],...f.current()})),S()}return w+=f.move(`
|
|
4
4
|
`),p&&(w+=f.move(p+`
|
|
@@ -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"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ve,{onClick:p,size:"sm",disabled:!s.trim(),children:"Apply Schema"}),d.jsx(Ve,{onClick:()=>{n(!1),l("")},variant:"outline",size:"sm",children:"Cancel"})]})]}),f(),r&&d.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[d.jsx(Sa,{className:"h-3 w-3 mr-1"}),"Structured output enabled"]})]})},at=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:n,disabled:s=!1,compact:l=!1,showImageGen:u=!1})=>{const[c,p]=E.useState(!1),[f,g]=E.useState(""),b=E.useRef(null),w=E.useRef(null),S=fa(),B=[{type:"personas",label:"Personas",icon:d.jsx(Et,{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:"Ollama Models",icon:d.jsx(ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>!M.isPersona&&!M.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:d.jsx(Ft,{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(A=>A.name.toLowerCase().includes(f.toLowerCase())||A.personaName&&A.personaName.toLowerCase().includes(f.toLowerCase())||A.pluginName&&A.pluginName.toLowerCase().includes(f.toLowerCase()))})).filter(M=>M.models.length>0),C=r.find(M=>M.name===e||e.startsWith("persona:")&&M.name===e);E.useEffect(()=>{const M=A=>{b.current&&!b.current.contains(A.target)&&(p(!1),g(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),E.useEffect(()=>{c&&w.current&&w.current.focus()},[c]);const z=M=>{t({target:{value:M}}),p(!1),g("")},j=M=>M.isPersona?d.jsx(Et,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):M.isPlugin?d.jsx(Ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):d.jsx(ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),O=M=>M.isPersona?M.personaName||M.name:M.isPlugin?`${M.name}`:M.name,G=M=>M.isPersona?`via ${M.model}`:M.isPlugin?`via ${M.pluginName}`:null,q=()=>{if(!C)return l?d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(ft,{className:"h-4 w-4"}),d.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:"Select Model"})]}):"Select Model";if(l){const N=O(C);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j(C),d.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:N})]})}const M=O(C),A=G(C);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j(C),d.jsxs("div",{className:"flex flex-col min-w-0",children:[d.jsx("span",{className:"text-sm font-medium truncate",children:M}),A&&d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:A})]}),C.isPersona&&a&&d.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[d.jsx(Z0,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&d.jsx(Na,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})};return d.jsxs("div",{className:K("relative",n),ref:b,children:[d.jsxs("button",{type:"button",onClick:()=>!s&&p(!c),disabled:s,className:K(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]",s?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?C?O(C):"Select Model":void 0,children:[q(),d.jsx(z0,{className:K(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",c&&"rotate-180")})]}),c&&Xt.createPortal(d.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4",children:[d.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>p(!1)}),d.jsxs("div",{className:K("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-sm sm:w-96 sm:max-w-[90vw]","mt-2 sm:mt-0 rounded-xl sm:rounded-xl","max-h-[85vh] sm:max-h-none flex flex-col"),onClick:M=>M.stopPropagation(),children:[d.jsx("div",{className:"p-3 sm:p-4 border-b border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a] flex-shrink-0",children:d.jsx("input",{ref:w,type:"text",placeholder:"Search models...",value:f,onChange:M=>g(M.target.value),onClick:M=>M.stopPropagation(),onMouseDown:M=>M.stopPropagation(),className:K("w-full px-3 py-2.5 sm:py-2 text-sm bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] ophelia:text-[#fafafa] ophelia:placeholder-[#737373]","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 focus:border-primary-500 ophelia:focus:border-[#9333ea]","touch-manipulation")})}),d.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 max-h-80 sm:max-h-80",children:[B.length>0?B.map(M=>d.jsxs("div",{children:[d.jsx("div",{className:"px-3 sm:px-3 py-2.5 sm: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:d.jsxs("div",{className:"flex items-center gap-2",children:[M.icon,M.label," (",M.models.length,")"]})}),M.models.map(A=>d.jsx("div",{onMouseDown:N=>{N.preventDefault(),z(A.name)},onTouchStart:N=>{N.preventDefault(),z(A.name)},className:K("px-3 sm:px-4 py-3.5 sm: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] active:bg-gray-100 dark:active:bg-dark-100 ophelia:active:bg-[#1a1a1a]","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] touch-manipulation","transition-colors duration-150 ease-in-out",(e===A.name||e.startsWith("persona:")&&A.name===e)&&"bg-primary-50 dark:bg-primary-900 ophelia:bg-[rgba(147,51,234,0.15)] border-l-4 border-primary-500 ophelia:border-l-[#9333ea]"),children:d.jsxs("div",{className:"flex items-center gap-3",children:[j(A),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:O(A)}),G(A)&&d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:G(A)})]}),(e===A.name||e.startsWith("persona:")&&A.name===e)&&d.jsx(nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},A.name))]},M.type)):d.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373] bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:[d.jsx(as,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),d.jsx("p",{className:"text-sm",children:"No models found"})]}),u&&d.jsxs("div",{className:"border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[d.jsx("div",{className:"px-3 sm:px-3 py-2.5 sm: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]",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Kt,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),"Actions"]})}),d.jsx("div",{onMouseDown:M=>{M.preventDefault(),p(!1),S("/gallery")},onTouchStart:M=>{M.preventDefault(),p(!1),S("/gallery")},className:K("px-3 sm:px-4 py-3.5 sm: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] touch-manipulation","transition-colors duration-150 ease-in-out"),children:d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Ma,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:"Generate Image"}),d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"Create images with AI"})]})]})})]})]})]})]}),document.body),d.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(M=>d.jsx("option",{value:M.name,children:O(M)},M.name))})]})},i1=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const[a,n]=E.useState(""),[s,l]=E.useState([]),[u,c]=E.useState(null),[p,f]=E.useState(!1),[g,b]=E.useState(null),[w,S]=E.useState(!1),{isGenerating:T,setBackgroundImage:B}=g0(),{currentSession:C,models:z}=ye(),j=E.useRef(null);E.useEffect(()=>{(async()=>{try{const L=await va.getPlugins();S(!!(L.success&&L.data&&L.data.length>0))}catch{S(!1)}})()},[]);const O=N=>{N.preventDefault(),!(!a.trim()||T)&&(r(a.trim(),s.length>0?s:void 0,u||void 0),n(""),l([]))},G=N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),O(N))},q=()=>{e()};E.useEffect(()=>{const N=j.current;N&&(N.style.height="auto",N.style.height=Math.min(N.scrollHeight,200)+"px")},[a]),E.useEffect(()=>{(async()=>{if(C?.personaId)try{const L=await wr.getPersona(C.personaId);if(L.success&&L.data)b(L.data);else{console.warn(`Persona ${C.personaId} not found, clearing reference`),b(null);const{setCurrentSession:$}=ye.getState();$({...C,personaId:void 0})}}catch(L){if(console.error("Failed to load current persona:",L),b(null),C){const{setCurrentSession:$}=ye.getState();$({...C,personaId:void 0})}}else b(null)})()},[C?.personaId]);const M=async N=>{const L=N.target.value;if(C)try{if(L.startsWith("persona:")){const $=L.replace("persona:",""),W=await wr.getPersona($);if(!W.success||!W.data){R0.error("Failed to load persona details");return}const Y=W.data,Q=await J0.updateSession(C.id,{personaId:$,model:L});if(Q.success&&Q.data){const{sessions:_}=ye.getState(),le=_.map(ge=>ge.id===C.id?Q.data:ge);ye.setState({sessions:le,currentSession:Q.data}),Y.background&&B(Y.background),R0.success("Persona applied")}}else{const $=await J0.updateSession(C.id,{model:L,personaId:void 0});if($.success&&$.data){const{sessions:W}=ye.getState(),Y=W.map(Q=>Q.id===C.id?$.data:Q);ye.setState({sessions:Y,currentSession:$.data}),B(null),R0.success("Model updated")}}}catch($){console.error("Failed to update session:",$),R0.error("Failed to update session")}},A=s.length>0||u!==null;return d.jsx("div",{className:"pointer-events-none",children:d.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto",children:[p&&d.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:[d.jsx(a1,{images:s,onImagesChange:l,maxImages:5,sessionId:C?.id,disabled:t}),d.jsx(s1,{format:u,onFormatChange:c})]}),d.jsxs("div",{className:"py-2 sm:py-3",children:[d.jsx("form",{onSubmit:O,children:d.jsxs("div",{className:K("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:[d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>f(!p),className:K("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",A&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",p&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:"Attachments and advanced features",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:A?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Ta,{className:"h-4 w-4"}),d.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]"})]}):p?d.jsx(za,{className:"h-4 w-4"}):d.jsx(Kt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(vr,{ref:j,value:a,onChange:N=>n(N.target.value),onKeyDown:G,placeholder:"Send a message",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"}})}),d.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[C&&z.length>0&&d.jsx("div",{className:"hidden sm:block",children:d.jsx(at,{models:z,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:M,currentPersona:g,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:w})}),T?d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:q,className:K("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:"Stop generation",children:d.jsx(ya,{className:"h-4 w-4"})}):d.jsx(Ve,{type:"submit",variant:"ghost",size:"sm",disabled:!a.trim()||t,className:K("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",a.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:"Send message",children:d.jsx(Aa,{className:"h-4 w-4"})})]})]})}),C&&z.length>0&&d.jsx("div",{className:"sm:hidden mt-3",children:d.jsx(at,{models:z,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:M,currentPersona:g,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:w})}),d.jsxs("div",{className:"mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600",children:[d.jsx(n1,{sessionId:C?.id}),d.jsxs("div",{className:"text-center",children:[d.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors",style:{fontSize:"1.1em",lineHeight:1},children:"Libre WebUI"})," ",d.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.3.0"]})," ",d.jsx("span",{className:"text-gray-300 dark:text-gray-600 opacity-50",children:"•"})," ",d.jsx("span",{className:"text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:"LLM can make mistakes - verify important information"}),A&&d.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",s.length>0&&`${s.length} image${s.length>1?"s":""}`,s.length>0&&u&&" • ",u&&"Structured output"]})]})]})]})]})})},l1=({persona:r,onClear:e,className:t})=>{const[a,n]=E.useState(!1),s=E.useRef(null),[l,u]=E.useState({top:0,left:0});E.useEffect(()=>{if(a&&s.current){const f=s.current.getBoundingClientRect();u({top:f.bottom+8,left:f.left})}},[a]);const c=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),p=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=64`;return d.jsxs("div",{className:K("relative",t),children:[d.jsxs("button",{ref:s,onClick:()=>n(!a),className:K("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:[d.jsx("img",{src:p(),alt:r.name,className:"w-5 h-5 rounded-full object-cover"}),d.jsx("span",{className:"text-sm font-medium max-w-[120px] truncate",children:r.name}),c&&d.jsx(Na,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),d.jsx(z0,{className:K("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&Xt.createPortal(d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>n(!1)}),d.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:d.jsxs("div",{className:K("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:[d.jsxs("div",{className:"relative h-16",children:[r.background?d.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):d.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]"}),d.jsx("div",{className:"absolute inset-0 bg-black/10"}),e&&d.jsx("button",{onClick:f=>{f.stopPropagation(),e(),n(!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:d.jsx(v0,{className:"h-3.5 w-3.5 text-white"})}),c&&d.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:[d.jsx(Z0,{className:"h-3 w-3"}),"Enhanced"]})]}),d.jsx("div",{className:"relative px-4 -mt-6",children:d.jsx("img",{src:p(),alt:r.name,className:"w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-md"})}),d.jsxs("div",{className:"px-4 pt-2 pb-4",children:[d.jsx("h4",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.name}),d.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1 mt-0.5",children:[d.jsx(ns,{className:"h-3 w-3"}),r.model]}),r.description&&d.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&&d.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:[d.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[d.jsx(ss,{className:"h-2.5 w-2.5 text-gray-400"}),d.jsx("span",{className:"text-[9px] uppercase tracking-wider font-medium text-gray-400",children:"System"})]}),d.jsxs("p",{className:"text-[11px] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),d.jsxs("div",{className:"flex flex-wrap gap-1 mt-3",children:[d.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:[d.jsx(Ft,{className:"h-2.5 w-2.5"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),d.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&&d.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:[d.jsx(Z0,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},o1=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const n=E.useRef(null),[s,l]=E.useState(!1),u=w=>{if(!w)return;const S=[],T=t-r.length;for(let B=0;B<Math.min(w.length,T);B++){const C=w[B];if(!C.type.startsWith("image/")){de.error(`File ${C.name} is not an image`);continue}if(C.size>10*1024*1024){de.error(`Image ${C.name} is too large (max 10MB)`);continue}const z=new FileReader;z.onload=j=>{j.target?.result&&(S.push(j.target.result),S.length===Math.min(w.length,T)&&e([...r,...S]))},z.readAsDataURL(C)}w.length>T&&de.error(`Only ${T} more images can be added`)},c=w=>{w.preventDefault(),l(!0)},p=w=>{w.preventDefault(),l(!1)},f=w=>{w.preventDefault(),l(!1),u(w.dataTransfer.files)},g=w=>{const S=r.filter((T,B)=>B!==w);e(S)},b=r.length<t;return d.jsxs("div",{className:K("space-y-3",a),children:[b&&d.jsxs("div",{className:K("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",s&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:c,onDragLeave:p,onDrop:f,children:[d.jsx("input",{ref:n,type:"file",multiple:!0,accept:"image/*",onChange:w=>u(w.target.files),className:"hidden"}),d.jsxs("div",{className:"flex flex-col items-center text-center",children:[d.jsx(ka,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 mb-2"}),d.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:["Drop images here or"," ",d.jsx("button",{onClick:()=>n.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:"browse"})]}),d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Supports: JPG, PNG, GIF, WebP (max 10MB each)"})]})]}),r.length>0&&d.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((w,S)=>d.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:[d.jsx("img",{src:w,alt:`Upload ${S+1}`,className:"w-full h-full object-cover"}),d.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:d.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>g(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:d.jsx(v0,{className:"h-4 w-4"})})})]},S))}),b&&r.length>0&&d.jsxs(Ve,{variant:"outline",size:"sm",onClick:()=>n.current?.click(),className:"w-full sm:w-auto",children:[d.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},u1=r=>{const[e,t]=E.useState(""),[a,n]=E.useState(null),[s,l]=E.useState(!1),{addMessage:u,updateMessage:c,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:g}=ye(),{setIsGenerating:b,preferences:w}=g0(),S=E.useRef(null),T=E.useRef(null),B=E.useRef(""),C=E.useRef(0),z=E.useRef();E.useEffect(()=>()=>{ve.offMessage("user_message"),ve.offMessage("assistant_chunk"),ve.offMessage("assistant_complete"),ve.offMessage("error")},[r]),E.useEffect(()=>{if(!r){ve.offMessage("user_message"),ve.offMessage("assistant_chunk"),ve.offMessage("assistant_complete"),ve.offMessage("error");return}return ve.onMessage("user_message",()=>{}),ve.onMessage("assistant_chunk",A=>{const N=A,L=N.messageId||S.current;L&&(B.current=N.total,t(N.total),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{c(r,L,B.current),C.current=Date.now()},N.done?0:200))}),ve.onMessage("assistant_complete",A=>{const N=A;console.log("Hook: Received assistant_complete for session:",r,"messageId:",N.messageId,"with statistics:",!!N.statistics),l(!1),t(""),b(!1);const L=N.messageId||S.current;if(N&&L){const _=B.current||N.content;p(r,L,_,N.statistics)}const W=g0.getState().preferences.titleSettings,Y=ye.getState().currentSession,Q=T.current;console.log("Auto-title check:",{firstMessage:Q,autoTitle:W?.autoTitle,taskModel:W?.taskModel,sessionTitle:Y?.title}),Q&&W?.autoTitle&&W?.taskModel&&Y?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),g(r),J0.generateTitle(r,W.taskModel,Q).then(_=>{console.log("Title generation response:",_),_.success&&_.data?.title&&f(r,_.data.title)}).catch(_=>{console.error("Failed to generate title:",_)}).finally(()=>{g(null)}),T.current=null),S.current=null,B.current="",z.current&&clearTimeout(z.current),C.current=0}),ve.onMessage("error",A=>{const N=A;if(l(!1),t(""),b(!1),S.current=null,N.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),de.error("Session not found. Creating a new session..."),window.location.href="/";return}de.error(N.error)}),l(!1),t(""),S.current=null,()=>{z.current&&clearTimeout(z.current)}},[r,c,p,b,f,g]);const j=E.useCallback(async(M,A,N)=>{if(!(!r||!M.trim()&&(!A||A.length===0)))try{b(!0),l(!0),t(""),z.current&&clearTimeout(z.current),C.current=Date.now();const L=ye.getState().currentSession;!L?.messages?.some(Y=>Y.role==="user")&&L?.title==="New Chat"&&(T.current=M.trim()),u(r,{role:"user",content:M.trim(),images:A});const W=kr();S.current=W,n(W),u(r,{role:"assistant",content:"",id:W}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:M.trim(),images:A,format:N,options:w.generationOptions,assistantMessageId:W}})}catch(L){console.error("Failed to send message:",L),l(!1),t(""),n(null),b(!1),S.current=null,de.error("Failed to send message")}},[r,u,b,w.generationOptions]),O=E.useCallback(()=>{l(!1),t(""),n(null),b(!1),S.current=null},[b]),G=E.useCallback(async()=>{const M=ye.getState().currentSession;if(!M||!r)return;const A=M.messages;let N=-1,L=-1;for(let Y=A.length-1;Y>=0;Y--)if(A[Y].role==="assistant"){L=Y;break}if(L>0){for(let Y=L-1;Y>=0;Y--)if(A[Y].role==="user"){N=Y;break}}if(N===-1||L===-1){de.error("No message to regenerate");return}const $=A[N],W=A[L];try{b(!0),l(!0),t(""),z.current&&clearTimeout(z.current),C.current=Date.now();const Y=kr();S.current=Y,n(Y),u(r,{role:"assistant",content:"",id:Y,parentId:W.parentId||W.id,branchIndex:W.siblingCount||1,isActive:!0}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:$.content,images:$.images,options:w.generationOptions,assistantMessageId:Y,regenerate:!0,originalMessageId:W.id}})}catch(Y){console.error("Failed to regenerate message:",Y),l(!1),t(""),b(!1),S.current=null,de.error("Failed to regenerate message")}},[r,b,u,w.generationOptions]),q=E.useCallback(async M=>{const N=ye.getState().currentSession;if(!N||!r)return;const L=N.messages.find(Y=>Y.id===M);if(!L){de.error("Message not found");return}if(L.isActive!==!1)return;const $=L.parentId||L.id,W=L.branchIndex||0;try{const Y=await J0.switchMessageBranch(r,M,W);if(Y.success&&Y.data){const Q=N.messages.map(le=>le.id===$||le.parentId===$?{...le,isActive:le.id===M}:le),_={...N,messages:Q,updatedAt:Date.now()};ye.setState(le=>({sessions:le.sessions.map(ge=>ge.id===r?_:ge),currentSession:_})),de.success(`Switched to variant ${W+1}`)}else de.error(Y.error||"Failed to select branch")}catch(Y){console.error("Failed to select branch:",Y),de.error("Failed to select branch")}},[r]);return{sendMessage:j,stopGeneration:O,regenerateLastMessage:G,selectBranch:q,isStreaming:s,streamingMessage:e,streamingMessageId:a}},c1=r=>{const e=new Date().getHours(),t=r?`, ${r}`:"";return e>=5&&e<12?{greeting:`Good morning${t}`,timeSuffix:"today"}:e>=12&&e<17?{greeting:`Good afternoon${t}`,timeSuffix:"today"}:e>=17&&e<21?{greeting:`Good evening${t}`,timeSuffix:"tonight"}:{greeting:`Good night${t}`,timeSuffix:"tonight"}},x1=()=>{const{sessionId:r}=On(),e=fa(),t=Ln(),{currentSession:a,sessions:n,models:s,selectedModel:l,setSelectedModel:u,createSession:c,setCurrentSession:p,loadSessions:f,getCurrentPersona:g}=ye(),{user:b}=ga(),{sendMessage:w,stopGeneration:S,regenerateLastMessage:T,selectBranch:B,isStreaming:C,streamingMessage:z,streamingMessageId:j}=u1(a?.id||""),O=g(),{greeting:G,timeSuffix:q}=E.useMemo(()=>c1(b?.username),[b?.username]),[M,A]=E.useState(""),[N,L]=E.useState([]),[$,W]=E.useState(!1),Y=E.useRef(null),[Q,_]=E.useState(!1);E.useEffect(()=>{n.length===0&&f()},[f,n.length]),E.useEffect(()=>{(async()=>{try{const re=await va.getPlugins();_(!!(re.success&&re.data&&re.data.length>0))}catch{_(!1)}})()},[]),E.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(n.length!==0)if(r){const se=n.find(De=>De.id===r);se&&se.id!==a?.id?p(se):se||(console.warn(`Session ${r} not found for current user, redirecting...`),n.length>0?e(`/c/${n[0].id}`,{replace:!0}):e("/",{replace:!0}))}else!r&&n.length>0&&t.pathname==="/"&&e(`/c/${n[0].id}`,{replace:!0})})()},[r,n,p,e,a?.id,t.pathname]),E.useEffect(()=>{if(a?.id){const Z=sessionStorage.getItem("pendingMessage");if(Z){sessionStorage.removeItem("pendingMessage");try{const re=JSON.parse(Z);setTimeout(()=>{w(re.content,re.images)},100)}catch(re){console.error("Failed to parse pending message:",re)}}}},[a?.id,w]),E.useEffect(()=>{const Z=Y.current;Z&&(Z.style.height="auto",Z.style.height=Math.min(Z.scrollHeight,200)+"px")},[M]);const le=async Z=>{if(Z.preventDefault(),!M.trim()||!l)return;const re={content:M.trim(),images:N.length>0?N:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(re)),A(""),L([]);const se=await c(l);se&&e(`/c/${se.id}`,{replace:!0})},ge=Z=>{Z.key==="Enter"&&!Z.shiftKey&&(Z.preventDefault(),le(Z))},we=async Z=>{const re=Z.target.value;u(re)},Ze=(Z,re,se)=>{a&&w(Z,re,se)};if(!a){const Z=N.length>0;return d.jsx("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8",children:d.jsxs("div",{className:"w-full max-w-2xl mx-auto flex flex-col items-center justify-center",children:[d.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:G}),d.jsxs("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:["What can I help with ",q,"?"]}),s.length>0?d.jsxs("div",{className:"w-full",children:[$&&d.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:d.jsx(o1,{images:N,onImagesChange:L,maxImages:5})}),d.jsx("form",{onSubmit:le,children:d.jsxs("div",{className:K("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:[d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>W(!$),className:K("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",Z&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",$&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:"Attach images",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:Z?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Ta,{className:"h-4 w-4"}),d.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 ophelia:bg-[#9333ea] rounded-full"})]}):$?d.jsx(za,{className:"h-4 w-4"}):d.jsx(Kt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(vr,{ref:Y,value:M,onChange:re=>A(re.target.value),onKeyDown:ge,placeholder:"Message...",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"}})}),d.jsx("div",{className:"hidden sm:block",children:d.jsx(at,{models:s,selectedModel:l,onModelChange:we,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:Q})}),d.jsx(Ve,{type:"submit",variant:"ghost",size:"sm",disabled:!M.trim()||!l,className:K("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",M.trim()&&l&&"hover:scale-105 active:scale-95"),title:"Send message",children:d.jsx(Aa,{className:"h-4 w-4"})})]})}),d.jsx("div",{className:"sm:hidden mt-4",children:d.jsx(at,{models:s,selectedModel:l,onModelChange:we,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:Q})}),d.jsxs("div",{className:"mt-4 text-center",children:[d.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#a855f7] transition-colors text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",style:{fontSize:"0.75rem",lineHeight:1},children:"Libre WebUI"})," ",d.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.3.0"]})," ",d.jsx("span",{className:"text-gray-300 dark:text-gray-600 ophelia:text-[#3f3f46] opacity-50",children:"•"})," ",d.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:"LLM can make mistakes - verify important information"})]})]}):d.jsx("div",{className:"w-full max-w-md",children:d.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:[d.jsx("p",{className:"text-sm text-gray-700 dark:text-dark-700 ophelia:text-[#a3a3a3] mb-4",children:"No models available. Make sure Ollama is running and has models installed."}),d.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:"ollama pull llama3.2:3b"})]})})]})})}return d.jsxs("div",{className:"flex flex-col h-full relative",style:O?.background?{backgroundImage:`url(${O.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[O?.background&&d.jsx("div",{className:"absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm"}),d.jsxs("div",{className:"flex flex-col h-full relative z-10",children:[O&&d.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:d.jsx(l1,{persona:O,onClear:()=>{if(a){const{sessions:Z}=ye.getState(),re={...a,model:O.model,personaId:void 0},se=Z.map(De=>De.id===a.id?re:De);ye.setState({sessions:se,currentSession:re})}}})}),d.jsx(t1,{messages:a.messages,streamingMessage:z,streamingMessageId:j,isStreaming:C,onRegenerate:T,onSelectBranch:B,className:"flex-1"}),d.jsx(i1,{onSendMessage:Ze,onStopGeneration:S,disabled:!a})]})]})};export{x1 as ChatPage,x1 as default};
|
|
281
|
+
}`,rows:8,className:"font-mono text-sm"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ve,{onClick:p,size:"sm",disabled:!s.trim(),children:"Apply Schema"}),d.jsx(Ve,{onClick:()=>{n(!1),l("")},variant:"outline",size:"sm",children:"Cancel"})]})]}),f(),r&&d.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[d.jsx(Sa,{className:"h-3 w-3 mr-1"}),"Structured output enabled"]})]})},at=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:n,disabled:s=!1,compact:l=!1,showImageGen:u=!1})=>{const[c,p]=E.useState(!1),[f,g]=E.useState(""),b=E.useRef(null),w=E.useRef(null),S=fa(),B=[{type:"personas",label:"Personas",icon:d.jsx(Et,{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:"Ollama Models",icon:d.jsx(ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(M=>!M.isPersona&&!M.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:d.jsx(Ft,{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(A=>A.name.toLowerCase().includes(f.toLowerCase())||A.personaName&&A.personaName.toLowerCase().includes(f.toLowerCase())||A.pluginName&&A.pluginName.toLowerCase().includes(f.toLowerCase()))})).filter(M=>M.models.length>0),C=r.find(M=>M.name===e||e.startsWith("persona:")&&M.name===e);E.useEffect(()=>{const M=A=>{b.current&&!b.current.contains(A.target)&&(p(!1),g(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),E.useEffect(()=>{c&&w.current&&w.current.focus()},[c]);const z=M=>{t({target:{value:M}}),p(!1),g("")},j=M=>M.isPersona?d.jsx(Et,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):M.isPlugin?d.jsx(Ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):d.jsx(ft,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),O=M=>M.isPersona?M.personaName||M.name:M.isPlugin?`${M.name}`:M.name,G=M=>M.isPersona?`via ${M.model}`:M.isPlugin?`via ${M.pluginName}`:null,q=()=>{if(!C)return l?d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(ft,{className:"h-4 w-4"}),d.jsx("span",{className:"text-xs font-medium text-gray-400 dark:text-gray-500 truncate",children:"Select Model"})]}):"Select Model";if(l){const N=O(C);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j(C),d.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:N})]})}const M=O(C),A=G(C);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j(C),d.jsxs("div",{className:"flex flex-col min-w-0",children:[d.jsx("span",{className:"text-sm font-medium truncate",children:M}),A&&d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:A})]}),C.isPersona&&a&&d.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[d.jsx(Z0,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&d.jsx(Na,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})};return d.jsxs("div",{className:K("relative",n),ref:b,children:[d.jsxs("button",{type:"button",onClick:()=>!s&&p(!c),disabled:s,className:K(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]",s?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?C?O(C):"Select Model":void 0,children:[q(),d.jsx(z0,{className:K(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",c&&"rotate-180")})]}),c&&Xt.createPortal(d.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4",children:[d.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>p(!1)}),d.jsxs("div",{className:K("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-sm sm:w-96 sm:max-w-[90vw]","mt-2 sm:mt-0 rounded-xl sm:rounded-xl","max-h-[85vh] sm:max-h-none flex flex-col"),onClick:M=>M.stopPropagation(),children:[d.jsx("div",{className:"p-3 sm:p-4 border-b border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a] flex-shrink-0",children:d.jsx("input",{ref:w,type:"text",placeholder:"Search models...",value:f,onChange:M=>g(M.target.value),onClick:M=>M.stopPropagation(),onMouseDown:M=>M.stopPropagation(),className:K("w-full px-3 py-2.5 sm:py-2 text-sm bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] ophelia:text-[#fafafa] ophelia:placeholder-[#737373]","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 focus:border-primary-500 ophelia:focus:border-[#9333ea]","touch-manipulation")})}),d.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 max-h-80 sm:max-h-80",children:[B.length>0?B.map(M=>d.jsxs("div",{children:[d.jsx("div",{className:"px-3 sm:px-3 py-2.5 sm: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:d.jsxs("div",{className:"flex items-center gap-2",children:[M.icon,M.label," (",M.models.length,")"]})}),M.models.map(A=>d.jsx("div",{onMouseDown:N=>{N.preventDefault(),z(A.name)},onTouchStart:N=>{N.preventDefault(),z(A.name)},className:K("px-3 sm:px-4 py-3.5 sm: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] active:bg-gray-100 dark:active:bg-dark-100 ophelia:active:bg-[#1a1a1a]","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] touch-manipulation","transition-colors duration-150 ease-in-out",(e===A.name||e.startsWith("persona:")&&A.name===e)&&"bg-primary-50 dark:bg-primary-900 ophelia:bg-[rgba(147,51,234,0.15)] border-l-4 border-primary-500 ophelia:border-l-[#9333ea]"),children:d.jsxs("div",{className:"flex items-center gap-3",children:[j(A),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:O(A)}),G(A)&&d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:G(A)})]}),(e===A.name||e.startsWith("persona:")&&A.name===e)&&d.jsx(nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},A.name))]},M.type)):d.jsxs("div",{className:"px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373] bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]",children:[d.jsx(as,{className:"h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),d.jsx("p",{className:"text-sm",children:"No models found"})]}),u&&d.jsxs("div",{className:"border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[d.jsx("div",{className:"px-3 sm:px-3 py-2.5 sm: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]",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Kt,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),"Actions"]})}),d.jsx("div",{onMouseDown:M=>{M.preventDefault(),p(!1),S("/gallery")},onTouchStart:M=>{M.preventDefault(),p(!1),S("/gallery")},className:K("px-3 sm:px-4 py-3.5 sm: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] touch-manipulation","transition-colors duration-150 ease-in-out"),children:d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Ma,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:"Generate Image"}),d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"Create images with AI"})]})]})})]})]})]})]}),document.body),d.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(M=>d.jsx("option",{value:M.name,children:O(M)},M.name))})]})},i1=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const[a,n]=E.useState(""),[s,l]=E.useState([]),[u,c]=E.useState(null),[p,f]=E.useState(!1),[g,b]=E.useState(null),[w,S]=E.useState(!1),{isGenerating:T,setBackgroundImage:B}=g0(),{currentSession:C,models:z}=ye(),j=E.useRef(null);E.useEffect(()=>{(async()=>{try{const L=await va.getPlugins();S(!!(L.success&&L.data&&L.data.length>0))}catch{S(!1)}})()},[]);const O=N=>{N.preventDefault(),!(!a.trim()||T)&&(r(a.trim(),s.length>0?s:void 0,u||void 0),n(""),l([]))},G=N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),O(N))},q=()=>{e()};E.useEffect(()=>{const N=j.current;N&&(N.style.height="auto",N.style.height=Math.min(N.scrollHeight,200)+"px")},[a]),E.useEffect(()=>{(async()=>{if(C?.personaId)try{const L=await wr.getPersona(C.personaId);if(L.success&&L.data)b(L.data);else{console.warn(`Persona ${C.personaId} not found, clearing reference`),b(null);const{setCurrentSession:$}=ye.getState();$({...C,personaId:void 0})}}catch(L){if(console.error("Failed to load current persona:",L),b(null),C){const{setCurrentSession:$}=ye.getState();$({...C,personaId:void 0})}}else b(null)})()},[C?.personaId]);const M=async N=>{const L=N.target.value;if(C)try{if(L.startsWith("persona:")){const $=L.replace("persona:",""),W=await wr.getPersona($);if(!W.success||!W.data){R0.error("Failed to load persona details");return}const Y=W.data,Q=await J0.updateSession(C.id,{personaId:$,model:L});if(Q.success&&Q.data){const{sessions:_}=ye.getState(),le=_.map(ge=>ge.id===C.id?Q.data:ge);ye.setState({sessions:le,currentSession:Q.data}),Y.background&&B(Y.background),R0.success("Persona applied")}}else{const $=await J0.updateSession(C.id,{model:L,personaId:void 0});if($.success&&$.data){const{sessions:W}=ye.getState(),Y=W.map(Q=>Q.id===C.id?$.data:Q);ye.setState({sessions:Y,currentSession:$.data}),B(null),R0.success("Model updated")}}}catch($){console.error("Failed to update session:",$),R0.error("Failed to update session")}},A=s.length>0||u!==null;return d.jsx("div",{className:"pointer-events-none",children:d.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto",children:[p&&d.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:[d.jsx(a1,{images:s,onImagesChange:l,maxImages:5,sessionId:C?.id,disabled:t}),d.jsx(s1,{format:u,onFormatChange:c})]}),d.jsxs("div",{className:"py-2 sm:py-3",children:[d.jsx("form",{onSubmit:O,children:d.jsxs("div",{className:K("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:[d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>f(!p),className:K("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",A&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",p&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:"Attachments and advanced features",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:A?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Ta,{className:"h-4 w-4"}),d.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]"})]}):p?d.jsx(za,{className:"h-4 w-4"}):d.jsx(Kt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(vr,{ref:j,value:a,onChange:N=>n(N.target.value),onKeyDown:G,placeholder:"Send a message",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"}})}),d.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[C&&z.length>0&&d.jsx("div",{className:"hidden sm:block",children:d.jsx(at,{models:z,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:M,currentPersona:g,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:w})}),T?d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:q,className:K("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:"Stop generation",children:d.jsx(ya,{className:"h-4 w-4"})}):d.jsx(Ve,{type:"submit",variant:"ghost",size:"sm",disabled:!a.trim()||t,className:K("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",a.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:"Send message",children:d.jsx(Aa,{className:"h-4 w-4"})})]})]})}),C&&z.length>0&&d.jsx("div",{className:"sm:hidden mt-3",children:d.jsx(at,{models:z,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:M,currentPersona:g,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:w})}),d.jsxs("div",{className:"mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600",children:[d.jsx(n1,{sessionId:C?.id}),d.jsxs("div",{className:"text-center",children:[d.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors",style:{fontSize:"1.1em",lineHeight:1},children:"Libre WebUI"})," ",d.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:["v","0.3.2"]})," ",d.jsx("span",{className:"text-gray-300 dark:text-gray-600 opacity-50",children:"•"})," ",d.jsx("span",{className:"text-gray-400 dark:text-gray-500",style:{fontSize:"0.55rem"},children:"LLM can make mistakes - verify important information"}),A&&d.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",s.length>0&&`${s.length} image${s.length>1?"s":""}`,s.length>0&&u&&" • ",u&&"Structured output"]})]})]})]})]})})},l1=({persona:r,onClear:e,className:t})=>{const[a,n]=E.useState(!1),s=E.useRef(null),[l,u]=E.useState({top:0,left:0});E.useEffect(()=>{if(a&&s.current){const f=s.current.getBoundingClientRect();u({top:f.bottom+8,left:f.left})}},[a]);const c=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),p=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=64`;return d.jsxs("div",{className:K("relative",t),children:[d.jsxs("button",{ref:s,onClick:()=>n(!a),className:K("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:[d.jsx("img",{src:p(),alt:r.name,className:"w-5 h-5 rounded-full object-cover"}),d.jsx("span",{className:"text-sm font-medium max-w-[120px] truncate",children:r.name}),c&&d.jsx(Na,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),d.jsx(z0,{className:K("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&Xt.createPortal(d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>n(!1)}),d.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:d.jsxs("div",{className:K("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:[d.jsxs("div",{className:"relative h-16",children:[r.background?d.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):d.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]"}),d.jsx("div",{className:"absolute inset-0 bg-black/10"}),e&&d.jsx("button",{onClick:f=>{f.stopPropagation(),e(),n(!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:d.jsx(v0,{className:"h-3.5 w-3.5 text-white"})}),c&&d.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:[d.jsx(Z0,{className:"h-3 w-3"}),"Enhanced"]})]}),d.jsx("div",{className:"relative px-4 -mt-6",children:d.jsx("img",{src:p(),alt:r.name,className:"w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-md"})}),d.jsxs("div",{className:"px-4 pt-2 pb-4",children:[d.jsx("h4",{className:"text-base font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.name}),d.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1 mt-0.5",children:[d.jsx(ns,{className:"h-3 w-3"}),r.model]}),r.description&&d.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&&d.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:[d.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[d.jsx(ss,{className:"h-2.5 w-2.5 text-gray-400"}),d.jsx("span",{className:"text-[9px] uppercase tracking-wider font-medium text-gray-400",children:"System"})]}),d.jsxs("p",{className:"text-[11px] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),d.jsxs("div",{className:"flex flex-wrap gap-1 mt-3",children:[d.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:[d.jsx(Ft,{className:"h-2.5 w-2.5"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),d.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&&d.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:[d.jsx(Z0,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},o1=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const n=E.useRef(null),[s,l]=E.useState(!1),u=w=>{if(!w)return;const S=[],T=t-r.length;for(let B=0;B<Math.min(w.length,T);B++){const C=w[B];if(!C.type.startsWith("image/")){de.error(`File ${C.name} is not an image`);continue}if(C.size>10*1024*1024){de.error(`Image ${C.name} is too large (max 10MB)`);continue}const z=new FileReader;z.onload=j=>{j.target?.result&&(S.push(j.target.result),S.length===Math.min(w.length,T)&&e([...r,...S]))},z.readAsDataURL(C)}w.length>T&&de.error(`Only ${T} more images can be added`)},c=w=>{w.preventDefault(),l(!0)},p=w=>{w.preventDefault(),l(!1)},f=w=>{w.preventDefault(),l(!1),u(w.dataTransfer.files)},g=w=>{const S=r.filter((T,B)=>B!==w);e(S)},b=r.length<t;return d.jsxs("div",{className:K("space-y-3",a),children:[b&&d.jsxs("div",{className:K("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",s&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:c,onDragLeave:p,onDrop:f,children:[d.jsx("input",{ref:n,type:"file",multiple:!0,accept:"image/*",onChange:w=>u(w.target.files),className:"hidden"}),d.jsxs("div",{className:"flex flex-col items-center text-center",children:[d.jsx(ka,{className:"h-8 w-8 text-gray-400 dark:text-gray-500 mb-2"}),d.jsxs("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:["Drop images here or"," ",d.jsx("button",{onClick:()=>n.current?.click(),className:"text-primary-600 dark:text-primary-400 hover:underline font-medium",children:"browse"})]}),d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Supports: JPG, PNG, GIF, WebP (max 10MB each)"})]})]}),r.length>0&&d.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((w,S)=>d.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:[d.jsx("img",{src:w,alt:`Upload ${S+1}`,className:"w-full h-full object-cover"}),d.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:d.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>g(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:d.jsx(v0,{className:"h-4 w-4"})})})]},S))}),b&&r.length>0&&d.jsxs(Ve,{variant:"outline",size:"sm",onClick:()=>n.current?.click(),className:"w-full sm:w-auto",children:[d.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},u1=r=>{const[e,t]=E.useState(""),[a,n]=E.useState(null),[s,l]=E.useState(!1),{addMessage:u,updateMessage:c,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:g}=ye(),{setIsGenerating:b,preferences:w}=g0(),S=E.useRef(null),T=E.useRef(null),B=E.useRef(""),C=E.useRef(0),z=E.useRef();E.useEffect(()=>()=>{ve.offMessage("user_message"),ve.offMessage("assistant_chunk"),ve.offMessage("assistant_complete"),ve.offMessage("error")},[r]),E.useEffect(()=>{if(!r){ve.offMessage("user_message"),ve.offMessage("assistant_chunk"),ve.offMessage("assistant_complete"),ve.offMessage("error");return}return ve.onMessage("user_message",()=>{}),ve.onMessage("assistant_chunk",A=>{const N=A,L=N.messageId||S.current;L&&(B.current=N.total,t(N.total),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{c(r,L,B.current),C.current=Date.now()},N.done?0:200))}),ve.onMessage("assistant_complete",A=>{const N=A;console.log("Hook: Received assistant_complete for session:",r,"messageId:",N.messageId,"with statistics:",!!N.statistics),l(!1),t(""),b(!1);const L=N.messageId||S.current;if(N&&L){const _=B.current||N.content;p(r,L,_,N.statistics)}const W=g0.getState().preferences.titleSettings,Y=ye.getState().currentSession,Q=T.current;console.log("Auto-title check:",{firstMessage:Q,autoTitle:W?.autoTitle,taskModel:W?.taskModel,sessionTitle:Y?.title}),Q&&W?.autoTitle&&W?.taskModel&&Y?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),g(r),J0.generateTitle(r,W.taskModel,Q).then(_=>{console.log("Title generation response:",_),_.success&&_.data?.title&&f(r,_.data.title)}).catch(_=>{console.error("Failed to generate title:",_)}).finally(()=>{g(null)}),T.current=null),S.current=null,B.current="",z.current&&clearTimeout(z.current),C.current=0}),ve.onMessage("error",A=>{const N=A;if(l(!1),t(""),b(!1),S.current=null,N.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),de.error("Session not found. Creating a new session..."),window.location.href="/";return}de.error(N.error)}),l(!1),t(""),S.current=null,()=>{z.current&&clearTimeout(z.current)}},[r,c,p,b,f,g]);const j=E.useCallback(async(M,A,N)=>{if(!(!r||!M.trim()&&(!A||A.length===0)))try{b(!0),l(!0),t(""),z.current&&clearTimeout(z.current),C.current=Date.now();const L=ye.getState().currentSession;!L?.messages?.some(Y=>Y.role==="user")&&L?.title==="New Chat"&&(T.current=M.trim()),u(r,{role:"user",content:M.trim(),images:A});const W=kr();S.current=W,n(W),u(r,{role:"assistant",content:"",id:W}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:M.trim(),images:A,format:N,options:w.generationOptions,assistantMessageId:W}})}catch(L){console.error("Failed to send message:",L),l(!1),t(""),n(null),b(!1),S.current=null,de.error("Failed to send message")}},[r,u,b,w.generationOptions]),O=E.useCallback(()=>{l(!1),t(""),n(null),b(!1),S.current=null},[b]),G=E.useCallback(async()=>{const M=ye.getState().currentSession;if(!M||!r)return;const A=M.messages;let N=-1,L=-1;for(let Y=A.length-1;Y>=0;Y--)if(A[Y].role==="assistant"){L=Y;break}if(L>0){for(let Y=L-1;Y>=0;Y--)if(A[Y].role==="user"){N=Y;break}}if(N===-1||L===-1){de.error("No message to regenerate");return}const $=A[N],W=A[L];try{b(!0),l(!0),t(""),z.current&&clearTimeout(z.current),C.current=Date.now();const Y=kr();S.current=Y,n(Y),u(r,{role:"assistant",content:"",id:Y,parentId:W.parentId||W.id,branchIndex:W.siblingCount||1,isActive:!0}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:$.content,images:$.images,options:w.generationOptions,assistantMessageId:Y,regenerate:!0,originalMessageId:W.id}})}catch(Y){console.error("Failed to regenerate message:",Y),l(!1),t(""),b(!1),S.current=null,de.error("Failed to regenerate message")}},[r,b,u,w.generationOptions]),q=E.useCallback(async M=>{const N=ye.getState().currentSession;if(!N||!r)return;const L=N.messages.find(Y=>Y.id===M);if(!L){de.error("Message not found");return}if(L.isActive!==!1)return;const $=L.parentId||L.id,W=L.branchIndex||0;try{const Y=await J0.switchMessageBranch(r,M,W);if(Y.success&&Y.data){const Q=N.messages.map(le=>le.id===$||le.parentId===$?{...le,isActive:le.id===M}:le),_={...N,messages:Q,updatedAt:Date.now()};ye.setState(le=>({sessions:le.sessions.map(ge=>ge.id===r?_:ge),currentSession:_})),de.success(`Switched to variant ${W+1}`)}else de.error(Y.error||"Failed to select branch")}catch(Y){console.error("Failed to select branch:",Y),de.error("Failed to select branch")}},[r]);return{sendMessage:j,stopGeneration:O,regenerateLastMessage:G,selectBranch:q,isStreaming:s,streamingMessage:e,streamingMessageId:a}},c1=r=>{const e=new Date().getHours(),t=r?`, ${r}`:"";return e>=5&&e<12?{greeting:`Good morning${t}`,timeSuffix:"today"}:e>=12&&e<17?{greeting:`Good afternoon${t}`,timeSuffix:"today"}:e>=17&&e<21?{greeting:`Good evening${t}`,timeSuffix:"tonight"}:{greeting:`Good night${t}`,timeSuffix:"tonight"}},x1=()=>{const{sessionId:r}=On(),e=fa(),t=Ln(),{currentSession:a,sessions:n,models:s,selectedModel:l,setSelectedModel:u,createSession:c,setCurrentSession:p,loadSessions:f,getCurrentPersona:g}=ye(),{user:b}=ga(),{sendMessage:w,stopGeneration:S,regenerateLastMessage:T,selectBranch:B,isStreaming:C,streamingMessage:z,streamingMessageId:j}=u1(a?.id||""),O=g(),{greeting:G,timeSuffix:q}=E.useMemo(()=>c1(b?.username),[b?.username]),[M,A]=E.useState(""),[N,L]=E.useState([]),[$,W]=E.useState(!1),Y=E.useRef(null),[Q,_]=E.useState(!1);E.useEffect(()=>{n.length===0&&f()},[f,n.length]),E.useEffect(()=>{(async()=>{try{const re=await va.getPlugins();_(!!(re.success&&re.data&&re.data.length>0))}catch{_(!1)}})()},[]),E.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(n.length!==0)if(r){const se=n.find(De=>De.id===r);se&&se.id!==a?.id?p(se):se||(console.warn(`Session ${r} not found for current user, redirecting...`),n.length>0?e(`/c/${n[0].id}`,{replace:!0}):e("/",{replace:!0}))}else!r&&n.length>0&&t.pathname==="/"&&e(`/c/${n[0].id}`,{replace:!0})})()},[r,n,p,e,a?.id,t.pathname]),E.useEffect(()=>{if(a?.id){const Z=sessionStorage.getItem("pendingMessage");if(Z){sessionStorage.removeItem("pendingMessage");try{const re=JSON.parse(Z);setTimeout(()=>{w(re.content,re.images)},100)}catch(re){console.error("Failed to parse pending message:",re)}}}},[a?.id,w]),E.useEffect(()=>{const Z=Y.current;Z&&(Z.style.height="auto",Z.style.height=Math.min(Z.scrollHeight,200)+"px")},[M]);const le=async Z=>{if(Z.preventDefault(),!M.trim()||!l)return;const re={content:M.trim(),images:N.length>0?N:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(re)),A(""),L([]);const se=await c(l);se&&e(`/c/${se.id}`,{replace:!0})},ge=Z=>{Z.key==="Enter"&&!Z.shiftKey&&(Z.preventDefault(),le(Z))},we=async Z=>{const re=Z.target.value;u(re)},Ze=(Z,re,se)=>{a&&w(Z,re,se)};if(!a){const Z=N.length>0;return d.jsx("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8",children:d.jsxs("div",{className:"w-full max-w-2xl mx-auto flex flex-col items-center justify-center",children:[d.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:G}),d.jsxs("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:["What can I help with ",q,"?"]}),s.length>0?d.jsxs("div",{className:"w-full",children:[$&&d.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:d.jsx(o1,{images:N,onImagesChange:L,maxImages:5})}),d.jsx("form",{onSubmit:le,children:d.jsxs("div",{className:K("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:[d.jsx(Ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>W(!$),className:K("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",Z&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",$&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:"Attach images",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:Z?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Ta,{className:"h-4 w-4"}),d.jsx("div",{className:"absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 ophelia:bg-[#9333ea] rounded-full"})]}):$?d.jsx(za,{className:"h-4 w-4"}):d.jsx(Kt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(vr,{ref:Y,value:M,onChange:re=>A(re.target.value),onKeyDown:ge,placeholder:"Message...",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"}})}),d.jsx("div",{className:"hidden sm:block",children:d.jsx(at,{models:s,selectedModel:l,onModelChange:we,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:Q})}),d.jsx(Ve,{type:"submit",variant:"ghost",size:"sm",disabled:!M.trim()||!l,className:K("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",M.trim()&&l&&"hover:scale-105 active:scale-95"),title:"Send message",children:d.jsx(Aa,{className:"h-4 w-4"})})]})}),d.jsx("div",{className:"sm:hidden mt-4",children:d.jsx(at,{models:s,selectedModel:l,onModelChange:we,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:Q})}),d.jsxs("div",{className:"mt-4 text-center",children:[d.jsx("a",{href:"https://librewebui.org",target:"_blank",rel:"noopener noreferrer",className:"libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#a855f7] transition-colors text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",style:{fontSize:"0.75rem",lineHeight:1},children:"Libre WebUI"})," ",d.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",style:{fontSize:"0.55rem"},children:["v","0.3.2"]})," ",d.jsx("span",{className:"text-gray-300 dark:text-gray-600 ophelia:text-[#3f3f46] opacity-50",children:"•"})," ",d.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:"LLM can make mistakes - verify important information"})]})]}):d.jsx("div",{className:"w-full max-w-md",children:d.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:[d.jsx("p",{className:"text-sm text-gray-700 dark:text-dark-700 ophelia:text-[#a3a3a3] mb-4",children:"No models available. Make sure Ollama is running and has models installed."}),d.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:"ollama pull llama3.2:3b"})]})})]})})}return d.jsxs("div",{className:"flex flex-col h-full relative",style:O?.background?{backgroundImage:`url(${O.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[O?.background&&d.jsx("div",{className:"absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm"}),d.jsxs("div",{className:"flex flex-col h-full relative z-10",children:[O&&d.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:d.jsx(l1,{persona:O,onClear:()=>{if(a){const{sessions:Z}=ye.getState(),re={...a,model:O.model,personaId:void 0},se=Z.map(De=>De.id===a.id?re:De);ye.setState({sessions:se,currentSession:re})}}})}),d.jsx(t1,{messages:a.messages,streamingMessage:z,streamingMessageId:j,isStreaming:C,onRegenerate:T,onSelectBranch:B,className:"flex-1"}),d.jsx(i1,{onSendMessage:Ze,onStopGeneration:S,disabled:!a})]})]})};export{x1 as ChatPage,x1 as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-DRtqGHm3.js";import{r as s,c as M}from"./router-vendor-B-t91v39.js";import{c as i,i as G,B as q}from"../assets/index-BAlYrgVl.js";import{X as A,k as T,av as K,ak as B,f as E,T as Q,x as k,L as P,aw as R,I as F,n as U,r as W}from"./ui-vendor-DA07XX1l.js";import"./react-vendor-N--QU9DW.js";import"./utils-vendor-DNzxLBGx.js";const X=({image:r,onClose:n,onDelete:h,onDownload:c})=>{s.useEffect(()=>{const l=x=>{x.key==="Escape"&&n()};return document.addEventListener("keydown",l),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",l),document.body.style.overflow=""}},[n]);const b=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}),p=()=>{if(c)c(r);else{const l=document.createElement("a");l.href=r.imageData,l.download=`generated-${r.id}.png`,document.body.appendChild(l),l.click(),document.body.removeChild(l)}};return M.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center",onClick:n,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:l=>l.stopPropagation(),children:[e.jsx("button",{onClick:n,className:i("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(A,{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:i("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:"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(T,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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(K,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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(B,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"Created:"}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:b(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:p,className:i("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(E,{className:"h-4 w-4"}),"Download"]}),h&&e.jsx("button",{onClick:()=>h(r.id),className:i("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(Q,{className:"h-4 w-4"})})]})]})]})]}),document.body)},Y=({onImageCountChange:r})=>{const[n,h]=s.useState([]),[c,b]=s.useState(0),[p,l]=s.useState(!0),[x,N]=s.useState(!1),[u,w]=s.useState(null),[f,S]=s.useState(null),C=20,j=s.useCallback(async(t=0,m=!1)=>{try{t===0?l(!0):N(!0);const o=await G.getGallery({limit:C,offset:t});o.success&&o.data&&(h(m?y=>[...y,...o.data.images]:o.data.images),b(o.data.total),r?.(o.data.total))}catch(o){console.error("Failed to load gallery:",o),k.error("Failed to load gallery")}finally{l(!1),N(!1)}},[r]);s.useEffect(()=>{j()},[j]);const z=()=>{j(n.length,!0)},I=async(t,m)=>{if(m.stopPropagation(),!f){S(t);try{(await G.deleteGalleryImage(t)).success?(h(y=>y.filter(L=>L.id!==t)),b(y=>y-1),r?.(c-1),k.success("Image deleted"),u?.id===t&&w(null)):k.error("Failed to delete image")}catch(o){console.error("Failed to delete image:",o),k.error("Failed to delete image")}finally{S(null)}}},v=(t,m)=>{m.stopPropagation();const o=document.createElement("a");o.href=t.imageData,o.download=`generated-${t.id}.png`,document.body.appendChild(o),o.click(),document.body.removeChild(o)},D=t=>new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return p?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(P,{className:"h-8 w-8 animate-spin text-gray-400 dark:text-gray-500"})}):n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(R,{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:"No images yet"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm",children:"Generated images will appear here. Use the image generation feature to create your first image."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:i("columns-1 sm:columns-2 lg:columns-3 xl:columns-4","gap-4 space-y-4"),children:n.map(t=>e.jsxs("div",{className:i("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:()=>w(t),children:[e.jsx("img",{src:t.imageData,alt:t.prompt,className:"w-full h-auto object-cover",loading:"lazy"}),e.jsxs("div",{className:i("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:D(t.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:m=>v(t,m),className:i("p-1.5 rounded-lg","bg-white/20 hover:bg-white/30","transition-colors"),title:"Download",children:e.jsx(E,{className:"h-4 w-4 text-white"})}),e.jsx("button",{onClick:m=>I(t.id,m),disabled:f===t.id,className:i("p-1.5 rounded-lg","bg-white/20 hover:bg-red-500/80","transition-colors",f===t.id&&"opacity-50 cursor-not-allowed"),title:"Delete",children:f===t.id?e.jsx(P,{className:"h-4 w-4 text-white animate-spin"}):e.jsx(Q,{className:"h-4 w-4 text-white"})})]})]})]})]},t.id))}),n.length<c&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:z,disabled:x,className:i("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:x?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),"Loading..."]}):`Load More (${n.length} of ${c})`})}),u&&e.jsx(X,{image:u,onClose:()=>w(null),onDelete:t=>{I(t,{stopPropagation:()=>{}})},onDownload:t=>{v(t,{stopPropagation:()=>{}})}})]})},H=({isOpen:r,onClose:n,onImageGenerated:h})=>{const[c,b]=s.useState([]),[p,l]=s.useState(""),[x,N]=s.useState(""),[u,w]=s.useState(""),[f,S]=s.useState("1024x1024"),[C,j]=s.useState("standard"),[z,I]=s.useState(!1),[v,D]=s.useState(null),[t,m]=s.useState(["512x512","768x768","1024x1024"]),[o,y]=s.useState(["standard","high"]);s.useEffect(()=>{r&&(async()=>{try{const g=await G.getPlugins();if(g.success&&g.data&&(b(g.data),g.data.length>0)){const d=g.data[0];l(d.id),d.models.length>0&&N(d.models[0]),d.config?.sizes&&(m(d.config.sizes),S(d.config.default_size||d.config.sizes[0]||"1024x1024")),d.config?.qualities&&(y(d.config.qualities),j(d.config.default_quality||d.config.qualities[0]||"standard"))}}catch(g){console.error("Failed to load image generation plugins:",g)}})()},[r]),s.useEffect(()=>{const a=c.find(g=>g.id===p);a&&(a.models.length>0&&!a.models.includes(x)&&N(a.models[0]),a.config?.sizes&&(m(a.config.sizes),a.config.sizes.includes(f)||S(a.config.default_size||a.config.sizes[0])),a.config?.qualities&&(y(a.config.qualities),a.config.qualities.includes(C)||j(a.config.default_quality||a.config.qualities[0])))},[p,c,x,f,C]);const L=async()=>{if(!x||!u.trim()){k.error("Please select a model and enter a prompt");return}I(!0),D(null);try{const a=await G.generate({model:x,prompt:u.trim(),size:f,quality:C});if(a.success&&a.data?.images&&a.data.images.length>0){const g=a.data.images[0];let d=null;g.b64_json?d=`data:image/png;base64,${g.b64_json}`:g.url&&(d=g.url),d&&(k.success("Image generated successfully!"),h?(h(d,u.trim(),x),w(""),D(null),n()):D(d))}else k.error("Failed to generate image")}catch(a){console.error("Image generation failed:",a);const g=a instanceof Error?a.message:"Failed to generate image";k.error(g)}finally{I(!1)}},_=()=>{if(!v)return;const a=document.createElement("a");a.href=v,a.download=`generated-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a)};if(!r)return null;const $=c.find(a=>a.id===p);return M.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:n}),e.jsxs("div",{className:i("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:"Image Generation"})]}),e.jsx("button",{onClick:n,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors",children:e.jsx(A,{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:c.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:"No image generation plugins available."}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:"Configure an image plugin in Settings."})]}):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:"Plugin"}),e.jsx("select",{value:p,onChange:a=>l(a.target.value),className:i("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.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:"Model"}),e.jsx("select",{value:x,onChange:a=>N(a.target.value),className:i("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:$?.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:"Size"}),e.jsx("select",{value:f,onChange:a=>S(a.target.value),className:i("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:"Quality"}),e.jsx("select",{value:C,onChange:a=>j(a.target.value),className:i("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:o.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:"Prompt"}),e.jsx("textarea",{value:u,onChange:a=>w(a.target.value),placeholder:"Describe the image you want to generate...",rows:3,className:i("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")})]}),v&&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:v,alt:"Generated",className:"w-full h-auto"}),e.jsx("button",{onClick:_,className:i("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:"Download image",children:e.jsx(E,{className:"h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]"})})]})]})}),c.length>0&&e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:e.jsx(q,{onClick:L,disabled:z||!u.trim()||!x,className:i("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:z?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),"Generating..."]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(U,{className:"h-4 w-4"}),"Generate Image"]})})})]})]}),document.body)},te=()=>{const[r,n]=s.useState(null),[h,c]=s.useState(!1),[b,p]=s.useState(0),l=s.useCallback(()=>{p(x=>x+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:"Imagine"}),e.jsxs("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:["Your AI-generated image gallery",r!==null&&r>0&&e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:[" ","· ",r," ",r===1?"image":"images"]})]}),e.jsxs(q,{onClick:()=>c(!0),className:i("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(W,{className:"h-4 w-4 mr-2"}),"Generate Image"]})]}),e.jsx(Y,{onImageCountChange:n},b)]}),e.jsx(H,{isOpen:h,onClose:()=>c(!1),onImageGenerated:l})]})};export{te as GalleryPage,te as default};
|
|
1
|
+
import{j as e}from"./markdown-vendor-YWiGftdn.js";import{r as s,c as M}from"./router-vendor-CnU0qKrY.js";import{c as i,i as G,B as q}from"../assets/index-BbJ5OmoO.js";import{X as A,k as T,av as K,ak as B,f as E,T as Q,x as k,L as P,aw as R,I as F,n as U,r as W}from"./ui-vendor-CdKqcMKK.js";import"./react-vendor-N--QU9DW.js";import"./utils-vendor-DEeF42mN.js";const X=({image:r,onClose:n,onDelete:h,onDownload:c})=>{s.useEffect(()=>{const l=x=>{x.key==="Escape"&&n()};return document.addEventListener("keydown",l),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",l),document.body.style.overflow=""}},[n]);const b=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}),p=()=>{if(c)c(r);else{const l=document.createElement("a");l.href=r.imageData,l.download=`generated-${r.id}.png`,document.body.appendChild(l),l.click(),document.body.removeChild(l)}};return M.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center",onClick:n,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:l=>l.stopPropagation(),children:[e.jsx("button",{onClick:n,className:i("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(A,{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:i("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:"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(T,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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(K,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"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(B,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:"Created:"}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:b(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:p,className:i("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(E,{className:"h-4 w-4"}),"Download"]}),h&&e.jsx("button",{onClick:()=>h(r.id),className:i("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(Q,{className:"h-4 w-4"})})]})]})]})]}),document.body)},Y=({onImageCountChange:r})=>{const[n,h]=s.useState([]),[c,b]=s.useState(0),[p,l]=s.useState(!0),[x,N]=s.useState(!1),[u,w]=s.useState(null),[f,S]=s.useState(null),C=20,j=s.useCallback(async(t=0,m=!1)=>{try{t===0?l(!0):N(!0);const o=await G.getGallery({limit:C,offset:t});o.success&&o.data&&(h(m?y=>[...y,...o.data.images]:o.data.images),b(o.data.total),r?.(o.data.total))}catch(o){console.error("Failed to load gallery:",o),k.error("Failed to load gallery")}finally{l(!1),N(!1)}},[r]);s.useEffect(()=>{j()},[j]);const z=()=>{j(n.length,!0)},I=async(t,m)=>{if(m.stopPropagation(),!f){S(t);try{(await G.deleteGalleryImage(t)).success?(h(y=>y.filter(L=>L.id!==t)),b(y=>y-1),r?.(c-1),k.success("Image deleted"),u?.id===t&&w(null)):k.error("Failed to delete image")}catch(o){console.error("Failed to delete image:",o),k.error("Failed to delete image")}finally{S(null)}}},v=(t,m)=>{m.stopPropagation();const o=document.createElement("a");o.href=t.imageData,o.download=`generated-${t.id}.png`,document.body.appendChild(o),o.click(),document.body.removeChild(o)},D=t=>new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return p?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(P,{className:"h-8 w-8 animate-spin text-gray-400 dark:text-gray-500"})}):n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(R,{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:"No images yet"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm",children:"Generated images will appear here. Use the image generation feature to create your first image."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:i("columns-1 sm:columns-2 lg:columns-3 xl:columns-4","gap-4 space-y-4"),children:n.map(t=>e.jsxs("div",{className:i("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:()=>w(t),children:[e.jsx("img",{src:t.imageData,alt:t.prompt,className:"w-full h-auto object-cover",loading:"lazy"}),e.jsxs("div",{className:i("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:D(t.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:m=>v(t,m),className:i("p-1.5 rounded-lg","bg-white/20 hover:bg-white/30","transition-colors"),title:"Download",children:e.jsx(E,{className:"h-4 w-4 text-white"})}),e.jsx("button",{onClick:m=>I(t.id,m),disabled:f===t.id,className:i("p-1.5 rounded-lg","bg-white/20 hover:bg-red-500/80","transition-colors",f===t.id&&"opacity-50 cursor-not-allowed"),title:"Delete",children:f===t.id?e.jsx(P,{className:"h-4 w-4 text-white animate-spin"}):e.jsx(Q,{className:"h-4 w-4 text-white"})})]})]})]})]},t.id))}),n.length<c&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:z,disabled:x,className:i("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:x?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),"Loading..."]}):`Load More (${n.length} of ${c})`})}),u&&e.jsx(X,{image:u,onClose:()=>w(null),onDelete:t=>{I(t,{stopPropagation:()=>{}})},onDownload:t=>{v(t,{stopPropagation:()=>{}})}})]})},H=({isOpen:r,onClose:n,onImageGenerated:h})=>{const[c,b]=s.useState([]),[p,l]=s.useState(""),[x,N]=s.useState(""),[u,w]=s.useState(""),[f,S]=s.useState("1024x1024"),[C,j]=s.useState("standard"),[z,I]=s.useState(!1),[v,D]=s.useState(null),[t,m]=s.useState(["512x512","768x768","1024x1024"]),[o,y]=s.useState(["standard","high"]);s.useEffect(()=>{r&&(async()=>{try{const g=await G.getPlugins();if(g.success&&g.data&&(b(g.data),g.data.length>0)){const d=g.data[0];l(d.id),d.models.length>0&&N(d.models[0]),d.config?.sizes&&(m(d.config.sizes),S(d.config.default_size||d.config.sizes[0]||"1024x1024")),d.config?.qualities&&(y(d.config.qualities),j(d.config.default_quality||d.config.qualities[0]||"standard"))}}catch(g){console.error("Failed to load image generation plugins:",g)}})()},[r]),s.useEffect(()=>{const a=c.find(g=>g.id===p);a&&(a.models.length>0&&!a.models.includes(x)&&N(a.models[0]),a.config?.sizes&&(m(a.config.sizes),a.config.sizes.includes(f)||S(a.config.default_size||a.config.sizes[0])),a.config?.qualities&&(y(a.config.qualities),a.config.qualities.includes(C)||j(a.config.default_quality||a.config.qualities[0])))},[p,c,x,f,C]);const L=async()=>{if(!x||!u.trim()){k.error("Please select a model and enter a prompt");return}I(!0),D(null);try{const a=await G.generate({model:x,prompt:u.trim(),size:f,quality:C});if(a.success&&a.data?.images&&a.data.images.length>0){const g=a.data.images[0];let d=null;g.b64_json?d=`data:image/png;base64,${g.b64_json}`:g.url&&(d=g.url),d&&(k.success("Image generated successfully!"),h?(h(d,u.trim(),x),w(""),D(null),n()):D(d))}else k.error("Failed to generate image")}catch(a){console.error("Image generation failed:",a);const g=a instanceof Error?a.message:"Failed to generate image";k.error(g)}finally{I(!1)}},_=()=>{if(!v)return;const a=document.createElement("a");a.href=v,a.download=`generated-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a)};if(!r)return null;const $=c.find(a=>a.id===p);return M.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:n}),e.jsxs("div",{className:i("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:"Image Generation"})]}),e.jsx("button",{onClick:n,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors",children:e.jsx(A,{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:c.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:"No image generation plugins available."}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:"Configure an image plugin in Settings."})]}):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:"Plugin"}),e.jsx("select",{value:p,onChange:a=>l(a.target.value),className:i("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.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:"Model"}),e.jsx("select",{value:x,onChange:a=>N(a.target.value),className:i("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:$?.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:"Size"}),e.jsx("select",{value:f,onChange:a=>S(a.target.value),className:i("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:"Quality"}),e.jsx("select",{value:C,onChange:a=>j(a.target.value),className:i("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:o.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:"Prompt"}),e.jsx("textarea",{value:u,onChange:a=>w(a.target.value),placeholder:"Describe the image you want to generate...",rows:3,className:i("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")})]}),v&&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:v,alt:"Generated",className:"w-full h-auto"}),e.jsx("button",{onClick:_,className:i("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:"Download image",children:e.jsx(E,{className:"h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]"})})]})]})}),c.length>0&&e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:e.jsx(q,{onClick:L,disabled:z||!u.trim()||!x,className:i("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:z?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),"Generating..."]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(U,{className:"h-4 w-4"}),"Generate Image"]})})})]})]}),document.body)},te=()=>{const[r,n]=s.useState(null),[h,c]=s.useState(!1),[b,p]=s.useState(0),l=s.useCallback(()=>{p(x=>x+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:"Imagine"}),e.jsxs("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:["Your AI-generated image gallery",r!==null&&r>0&&e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:[" ","· ",r," ",r===1?"image":"images"]})]}),e.jsxs(q,{onClick:()=>c(!0),className:i("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(W,{className:"h-4 w-4 mr-2"}),"Generate Image"]})]}),e.jsx(Y,{onImageCountChange:n},b)]}),e.jsx(H,{isOpen:h,onClose:()=>c(!1),onImageGenerated:l})]})};export{te as GalleryPage,te as default};
|