libre-webui 0.4.0 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,12 +9,11 @@
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-DMCEMy0k.js"></script>
13
- <link rel="modulepreload" crossorigin href="/js/react-vendor-N--QU9DW.js">
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-CAOY-5dA.js">
17
- <link rel="modulepreload" crossorigin href="/js/utils-vendor-DEeF42mN.js">
12
+ <script type="module" crossorigin src="/assets/index-BNamR47C.js"></script>
13
+ <link rel="modulepreload" crossorigin href="/js/router-vendor-CYqbjR9t.js">
14
+ <link rel="modulepreload" crossorigin href="/js/markdown-vendor-DeGQOJEA.js">
15
+ <link rel="modulepreload" crossorigin href="/js/ui-vendor-C0aUE8gv.js">
16
+ <link rel="modulepreload" crossorigin href="/js/utils-vendor-COrKO_vV.js">
18
17
  <link rel="stylesheet" crossorigin href="/css/index-D6GvpwoJ.css">
19
18
  </head>
20
19
  <body>
@@ -1,4 +1,4 @@
1
- import{j as e}from"./markdown-vendor-YWiGftdn.js";import{r as c}from"./router-vendor-CnU0qKrY.js";import{a as _,u as D,c as R,B as t,O as y}from"../assets/index-DMCEMy0k.js";import{i as w,H as k,C as f,J as N,g as C,aw as z,E as I,N as S,O as T,G as B,Q as M}from"./ui-vendor-CAOY-5dA.js";const H=({artifact:s,className:d})=>{const{t:r}=_(),[h,m]=c.useState(!1),[n,i]=c.useState("preview"),A=c.useRef(null),{theme:x,openArtifactPanel:g}=D(),p=async a=>{try{await navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}catch(l){console.error("Failed to copy:",l)}},u=()=>{const a=new Blob([s.content],{type:E(s.type)}),l=URL.createObjectURL(a),o=document.createElement("a");o.href=l,o.download=`${s.title}.${L(s.type)}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l)},E=a=>{switch(a){case"html":return"text/html";case"react":return"text/javascript";case"svg":return"image/svg+xml";case"css":return"text/css";case"json":return"application/json";default:return"text/plain"}},L=a=>{switch(a){case"html":return"html";case"react":return"jsx";case"svg":return"svg";case"css":return"css";case"json":return"json";default:return"txt"}},b=()=>{switch(s.type){case"html":return e.jsx(B,{className:"h-4 w-4"});case"react":return e.jsx(T,{className:"h-4 w-4"});case"svg":return e.jsx(S,{className:"h-4 w-4"});case"code":return e.jsx(T,{className:"h-4 w-4"});default:return e.jsx(S,{className:"h-4 w-4"})}},O=()=>{const a=`
1
+ import{j as e}from"./markdown-vendor-DeGQOJEA.js";import{r as c}from"./router-vendor-CYqbjR9t.js";import{a as _,u as D,B as t,c as R,O as y}from"../assets/index-BNamR47C.js";import{i as w,H as k,C as f,J as N,g as C,aw as z,E as I,N as S,O as T,G as B,Q as M}from"./ui-vendor-C0aUE8gv.js";const H=({artifact:s,className:d})=>{const{t:r}=_(),[h,m]=c.useState(!1),[n,i]=c.useState("preview"),A=c.useRef(null),{theme:x,openArtifactPanel:g}=D(),p=async a=>{try{await navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}catch(l){console.error("Failed to copy:",l)}},u=()=>{const a=new Blob([s.content],{type:E(s.type)}),l=URL.createObjectURL(a),o=document.createElement("a");o.href=l,o.download=`${s.title}.${L(s.type)}`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(l)},E=a=>{switch(a){case"html":return"text/html";case"react":return"text/javascript";case"svg":return"image/svg+xml";case"css":return"text/css";case"json":return"application/json";default:return"text/plain"}},L=a=>{switch(a){case"html":return"html";case"react":return"jsx";case"svg":return"svg";case"css":return"css";case"json":return"json";default:return"txt"}},b=()=>{switch(s.type){case"html":return e.jsx(B,{className:"h-4 w-4"});case"react":return e.jsx(T,{className:"h-4 w-4"});case"svg":return e.jsx(S,{className:"h-4 w-4"});case"code":return e.jsx(T,{className:"h-4 w-4"});default:return e.jsx(S,{className:"h-4 w-4"})}},O=()=>{const a=`
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head>
@@ -1,4 +1,4 @@
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-DlsMdXjn.js";import{B as l}from"../assets/index-DMCEMy0k.js";import"./react-vendor-N--QU9DW.js";import"./ui-vendor-CAOY-5dA.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;">
1
+ import{j as e}from"./markdown-vendor-DeGQOJEA.js";import{r as d}from"./router-vendor-CYqbjR9t.js";import{A as c}from"./ArtifactContainer-Bf_RPKu5.js";import{B as l}from"../assets/index-BNamR47C.js";import"./ui-vendor-C0aUE8gv.js";import"./utils-vendor-COrKO_vV.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
@@ -95,4 +95,4 @@ def process_data(filename):
95
95
  if __name__ == "__main__":
96
96
  result = process_data('data.csv')
97
97
  print("Data processing results:")
98
- print(result)`,createdAt:Date.now(),updatedAt:Date.now()}],m=()=>{const[s,a]=d.useState([i[0]]),n=t=>{s.find(r=>r.id===t.id)||a([...s,t])},o=t=>{a(s.filter(r=>r.id!==t))};return e.jsxs("div",{className:"max-w-6xl mx-auto p-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100 mb-4",children:"Artifacts Demo"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-lg",children:"This demonstrates the Artifacts feature - interactive content that can be rendered alongside chat messages. Try the different artifact types below."})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4",children:"Available Artifacts"}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:t.title}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 uppercase",children:t.type})]}),e.jsx(l,{size:"sm",variant:s.find(r=>r.id===t.id)?"outline":"primary",onClick:()=>{s.find(r=>r.id===t.id)?o(t.id):n(t)},children:s.find(r=>r.id===t.id)?"Remove":"Add"})]},t.id))})]}),e.jsxs("div",{className:"lg:col-span-3",children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4",children:["Selected Artifacts (",s.length,")"]}),s.length>0?e.jsx(c,{artifacts:s}):e.jsx("div",{className:"text-center py-12 text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"No artifacts selected. Choose some from the left panel to see them in action."})})]})]}),e.jsxs("div",{className:"mt-12 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-blue-900 dark:text-blue-100 mb-3",children:"How Artifacts Work"}),e.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Automatic Detection:"})," When an AI model returns code blocks with specific languages (HTML, SVG, Python, etc.), they are automatically converted into interactive artifacts."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Supported Types:"})," HTML pages, SVG graphics, JSON data, code snippets, React components, and more."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Interactive Features:"})," View in fullscreen, copy content, download files, and open in new windows."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Safe Rendering:"})," All artifacts are rendered in sandboxed environments for security."]})]})]})]})},b=()=>e.jsx("div",{className:"min-h-screen bg-gray-50 dark:bg-gray-900",children:e.jsx(m,{})});export{b as default};
98
+ print(result)`,createdAt:Date.now(),updatedAt:Date.now()}],m=()=>{const[s,r]=d.useState([i[0]]),n=t=>{s.find(a=>a.id===t.id)||r([...s,t])},o=t=>{r(s.filter(a=>a.id!==t))};return e.jsxs("div",{className:"max-w-6xl mx-auto p-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100 mb-4",children:"Artifacts Demo"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-lg",children:"This demonstrates the Artifacts feature - interactive content that can be rendered alongside chat messages. Try the different artifact types below."})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4",children:"Available Artifacts"}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:t.title}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 uppercase",children:t.type})]}),e.jsx(l,{size:"sm",variant:s.find(a=>a.id===t.id)?"outline":"primary",onClick:()=>{s.find(a=>a.id===t.id)?o(t.id):n(t)},children:s.find(a=>a.id===t.id)?"Remove":"Add"})]},t.id))})]}),e.jsxs("div",{className:"lg:col-span-3",children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4",children:["Selected Artifacts (",s.length,")"]}),s.length>0?e.jsx(c,{artifacts:s}):e.jsx("div",{className:"text-center py-12 text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"No artifacts selected. Choose some from the left panel to see them in action."})})]})]}),e.jsxs("div",{className:"mt-12 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-blue-900 dark:text-blue-100 mb-3",children:"How Artifacts Work"}),e.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Automatic Detection:"})," When an AI model returns code blocks with specific languages (HTML, SVG, Python, etc.), they are automatically converted into interactive artifacts."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Supported Types:"})," HTML pages, SVG graphics, JSON data, code snippets, React components, and more."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Interactive Features:"})," View in fullscreen, copy content, download files, and open in new windows."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Safe Rendering:"})," All artifacts are rendered in sandboxed environments for security."]})]})]})]})},y=()=>e.jsx("div",{className:"min-h-screen bg-gray-50 dark:bg-gray-900",children:e.jsx(m,{})});export{y as default};
@@ -1,4 +1,4 @@
1
- import{o as S0,f as R0,m as d0,s as Bs,a as Is,c as Es,v as Fs,S as qs,j as d,M as Rs}from"./markdown-vendor-YWiGftdn.js";import{R as It,r as E,c as Yt,a as va,b as Os,u as Ps}from"./router-vendor-CnU0qKrY.js";import{u as x0,c as Z,O as Ls,a as o0,t as Kt,b as xa,d as be,p as wr,f as Hs,e as Et,S as Gs,T as $s,B as We,i as ba,g as kr,h as J0,w as ve,j as Sr}from"../assets/index-DMCEMy0k.js";import{C as nt,J as ya,b as Vs,f as A0,r as Us,L as wa,j as ka,a0 as Ws,V as Xs,p as Ft,a1 as Ys,u as Sa,a2 as Ks,X as b0,t as Zs,e as Mr,a3 as Q0,a4 as Js,a5 as Qs,H as _s,U as Ma,N as Na,a6 as en,z as he,a7 as tn,O as rn,B as gt,Z as qt,l as an,s as Zt,I as Ta,o as za,a8 as Aa,a9 as Ca,aa as ja,y as O0,ab as sn,d as nn,ac as Nr}from"./ui-vendor-CAOY-5dA.js";import{A as ln}from"./ArtifactContainer-DlsMdXjn.js";import"./react-vendor-N--QU9DW.js";import"./utils-vendor-DEeF42mN.js";function on(r,e){const t=String(r);let a=t.indexOf(e),s=a,n=0,l=0;for(;a!==-1;)a===s?++n>l&&(l=n):n=1,s=a+e.length,a=t.indexOf(e,s);return l}function un(){return{enter:{mathFlow:r,mathFlowFenceMeta:e,mathText:n},exit:{mathFlow:s,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];S0(p.type==="math"),p.meta=c}function a(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function s(c){const p=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),f=this.stack[this.stack.length-1];S0(f.type==="math"),this.exit(c),f.value=p;const x=f.data.hChildren[0];S0(x.type==="element"),S0(x.tagName==="code"),x.children.push({type:"text",value:p}),this.data.mathFlowInside=void 0}function n(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];S0(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 cn(r){let e=(r||{}).singleDollarTextMath;return e==null&&(e=!0),a.peek=s,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
1
+ import{o as S0,f as R0,m as d0,s as Bs,a as Is,c as Es,v as Fs,S as qs,j as d,M as Rs}from"./markdown-vendor-DeGQOJEA.js";import{R as It,r as E,e as Yt,c as va,d as Os,u as Ps}from"./router-vendor-CYqbjR9t.js";import{u as x0,O as Ls,c as Z,a as o0,t as Kt,b as xa,d as be,p as wr,f as Hs,e as Et,S as Gs,T as $s,B as We,i as ba,g as kr,h as J0,w as ve,j as Sr}from"../assets/index-BNamR47C.js";import{C as nt,J as ya,b as Vs,f as A0,r as Us,L as wa,j as ka,a0 as Ws,V as Xs,p as Ft,a1 as Ys,u as Sa,a2 as Ks,X as b0,t as Zs,e as Mr,a3 as Q0,a4 as Js,a5 as Qs,H as _s,U as Ma,N as Na,a6 as en,z as he,a7 as tn,O as rn,B as gt,Z as qt,l as an,s as Zt,I as Ta,o as za,a8 as Aa,a9 as Ca,aa as ja,y as O0,ab as sn,d as nn,ac as Nr}from"./ui-vendor-C0aUE8gv.js";import{A as ln}from"./ArtifactContainer-Bf_RPKu5.js";import"./utils-vendor-COrKO_vV.js";function on(r,e){const t=String(r);let a=t.indexOf(e),s=a,n=0,l=0;for(;a!==-1;)a===s?++n>l&&(l=n):n=1,s=a+e.length,a=t.indexOf(e,s);return l}function un(){return{enter:{mathFlow:r,mathFlowFenceMeta:e,mathText:n},exit:{mathFlow:s,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];S0(p.type==="math"),p.meta=c}function a(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function s(c){const p=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),f=this.stack[this.stack.length-1];S0(f.type==="math"),this.exit(c),f.value=p;const x=f.data.hChildren[0];S0(x.type==="element"),S0(x.tagName==="code"),x.children.push({type:"text",value:p}),this.data.mathFlowInside=void 0}function n(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];S0(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 cn(r){let e=(r||{}).singleDollarTextMath;return e==null&&(e=!0),a.peek=s,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
2
2
  `,inConstruct:"mathFlowMeta"},{character:"$",after:e?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:t,inlineMath:a}};function t(n,l,u,c){const p=n.value||"",f=u.createTracker(c),x="$".repeat(Math.max(on(p,"$")+1,2)),w=u.enter("mathFlow");let b=f.move(x);if(n.meta){const T=u.enter("mathFlowMeta");b+=f.move(u.safe(n.meta,{after:`
3
3
  `,before:b,encode:["$"],...f.current()})),T()}return b+=f.move(`
4
4
  `),p&&(b+=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(We,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),d.jsx(We,{onClick:()=>{n(!1),u("")},variant:"outline",size:"sm",children:a("chat.structuredOutput.cancel")})]})]}),w(),r&&d.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[d.jsx(Na,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},st=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:u=!1})=>{const{t:c}=o0(),[p,f]=E.useState(!1),[x,w]=E.useState(""),b=E.useRef(null),T=E.useRef(null),k=va(),B=[{type:"personas",label:"Personas",icon:d.jsx(Ft,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>z.isPersona),color:"purple"},{type:"ollama",label:"Ollama Models",icon:d.jsx(gt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>!z.isPersona&&!z.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:d.jsx(qt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>z.isPlugin),color:"green"}].filter(z=>z.models.length>0).map(z=>({...z,models:z.models.filter(S=>S.name.toLowerCase().includes(x.toLowerCase())||S.personaName&&S.personaName.toLowerCase().includes(x.toLowerCase())||S.pluginName&&S.pluginName.toLowerCase().includes(x.toLowerCase()))})).filter(z=>z.models.length>0),M=r.find(z=>z.name===e||e.startsWith("persona:")&&z.name===e);E.useEffect(()=>{const z=S=>{b.current&&!b.current.contains(S.target)&&(f(!1),w(""))};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),E.useEffect(()=>{p&&T.current&&T.current.focus()},[p]);const P=z=>{t({target:{value:z}}),f(!1),w("")},q=z=>z.isPersona?d.jsx(Ft,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):z.isPlugin?d.jsx(qt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):d.jsx(gt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),R=z=>z.isPersona?z.personaName||z.name:z.isPlugin?`${z.name}`:z.name,V=z=>z.isPersona?`via ${z.model}`:z.isPlugin?`via ${z.pluginName}`:null,D=()=>{if(!M)return l?d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(gt,{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 A=R(M);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[q(M),d.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:A})]})}const z=R(M),S=V(M);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[q(M),d.jsxs("div",{className:"flex flex-col min-w-0",children:[d.jsx("span",{className:"text-sm font-medium truncate",children:z}),S&&d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:S})]}),M.isPersona&&a&&d.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[d.jsx(Q0,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&d.jsx(za,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})};return d.jsxs("div",{className:Z("relative",s),ref:b,children:[d.jsxs("button",{type:"button",onClick:()=>!n&&f(!p),disabled:n,className:Z(l?"h-[44px] sm:h-[52px] px-3 flex items-center justify-between text-left w-full ":"w-full flex items-center justify-between gap-2 px-3 py-2 text-left ","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","rounded-lg text-sm hover:bg-gray-100 dark:hover:bg-dark-100 ophelia:hover:bg-[#1a1a1a]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20 focus:border-primary-500 ophelia:focus:border-[#9333ea]",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?M?R(M):"Select Model":void 0,children:[D(),d.jsx(A0,{className:Z(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",p&&"rotate-180")})]}),p&&Yt.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:()=>f(!1)}),d.jsxs("div",{className:Z("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:z=>z.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:T,type:"text",placeholder:"Search models...",value:x,onChange:z=>w(z.target.value),onClick:z=>z.stopPropagation(),onMouseDown:z=>z.stopPropagation(),className:Z("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(z=>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:[z.icon,z.label," (",z.models.length,")"]})}),z.models.map(S=>d.jsx("div",{onMouseDown:A=>{A.preventDefault(),P(S.name)},onTouchStart:A=>{A.preventDefault(),P(S.name)},className:Z("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===S.name||e.startsWith("persona:")&&S.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:[q(S),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:R(S)}),V(S)&&d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:V(S)})]}),(e===S.name||e.startsWith("persona:")&&S.name===e)&&d.jsx(nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},S.name))]},z.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(an,{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(Zt,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),"Actions"]})}),d.jsx("div",{onMouseDown:z=>{z.preventDefault(),f(!1),k("/gallery")},onTouchStart:z=>{z.preventDefault(),f(!1),k("/gallery")},className:Z("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(Ta,{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:c("gallery.generate")}),d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:c("gallery.generateDescription")})]})]})})]})]})]})]}),document.body),d.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(z=>d.jsx("option",{value:z.name,children:R(z)},z.name))})]})},oo=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=o0(),[s,n]=E.useState(""),[l,u]=E.useState([]),[c,p]=E.useState(null),[f,x]=E.useState(!1),[w,b]=E.useState(null),[T,k]=E.useState(!1),{isGenerating:j,setBackgroundImage:B}=x0(),{currentSession:M,models:P}=be(),q=E.useRef(null);E.useEffect(()=>{(async()=>{try{const H=await ba.getPlugins();k(!!(H.success&&H.data&&H.data.length>0))}catch{k(!1)}})()},[]);const R=A=>{A.preventDefault(),!(!s.trim()||j)&&(r(s.trim(),l.length>0?l:void 0,c||void 0),n(""),u([]))},V=A=>{A.key==="Enter"&&!A.shiftKey&&(A.preventDefault(),R(A))},D=()=>{e()};E.useEffect(()=>{const A=q.current;A&&(A.style.height="auto",A.style.height=Math.min(A.scrollHeight,200)+"px")},[s]),E.useEffect(()=>{(async()=>{if(M?.personaId)try{const H=await kr.getPersona(M.personaId);if(H.success&&H.data)b(H.data);else{console.warn(`Persona ${M.personaId} not found, clearing reference`),b(null);const{setCurrentSession:G}=be.getState();G({...M,personaId:void 0})}}catch(H){if(console.error("Failed to load current persona:",H),b(null),M){const{setCurrentSession:G}=be.getState();G({...M,personaId:void 0})}}else b(null)})()},[M?.personaId]);const z=async A=>{const H=A.target.value;if(M)try{if(H.startsWith("persona:")){const G=H.replace("persona:",""),U=await kr.getPersona(G);if(!U.success||!U.data){O0.error("Failed to load persona details");return}const te=U.data,K=await J0.updateSession(M.id,{personaId:G,model:H});if(K.success&&K.data){const{sessions:ne}=be.getState(),ge=ne.map(Se=>Se.id===M.id?K.data:Se);be.setState({sessions:ge,currentSession:K.data}),te.background&&B(te.background),O0.success(a("chat.persona.applied"))}}else{const G=await J0.updateSession(M.id,{model:H,personaId:void 0});if(G.success&&G.data){const{sessions:U}=be.getState(),te=U.map(K=>K.id===M.id?G.data:K);be.setState({sessions:te,currentSession:G.data}),B(null),O0.success(a("chat.model.updated"))}}}catch(G){console.error("Failed to update session:",G),O0.error("Failed to update session")}},S=l.length>0||c!==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:[f&&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(so,{images:l,onImagesChange:u,maxImages:5,sessionId:M?.id,disabled:t}),d.jsx(lo,{format:c,onFormatChange:p})]}),d.jsxs("div",{className:"py-2 sm:py-3",children:[d.jsx("form",{onSubmit:R,children:d.jsxs("div",{className:Z("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(We,{type:"button",variant:"ghost",size:"sm",onClick:()=>x(!f),className:Z("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",S&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",f&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:a("chat.input.attachments"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:S?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Aa,{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]"})]}):f?d.jsx(Ca,{className:"h-4 w-4"}):d.jsx(Zt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(xr,{ref:q,value:s,onChange:A=>n(A.target.value),onKeyDown:V,placeholder:a("chat.input.placeholder"),disabled:t,className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),d.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[M&&P.length>0&&d.jsx("div",{className:"hidden sm:block",children:d.jsx(st,{models:P,selectedModel:M.personaId?`persona:${M.personaId}`:M.model,onModelChange:z,currentPersona:w,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:T})}),j?d.jsx(We,{type:"button",variant:"ghost",size:"sm",onClick:D,className:Z("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","bg-red-50 dark:bg-red-900/20 ophelia:bg-red-900/30","text-red-500 dark:text-red-400 ophelia:text-red-400","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/40","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95"),title:a("chat.input.stopGeneration"),children:d.jsx(ka,{className:"h-4 w-4"})}):d.jsx(We,{type:"submit",variant:"ghost",size:"sm",disabled:!s.trim()||t,className:Z("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","text-gray-400 dark:text-dark-500 ophelia:text-[#525252]","disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed","transition-all duration-200 touch-manipulation",s.trim()&&!t&&["bg-primary-500 dark:bg-primary-600 ophelia:bg-[#9333ea]","text-white dark:text-white ophelia:text-white","hover:bg-primary-600 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","shadow-md hover:shadow-lg","hover:scale-105 active:scale-95"]),title:a("chat.input.sendMessage"),children:d.jsx(ja,{className:"h-4 w-4"})})]})]})}),M&&P.length>0&&d.jsx("div",{className:"sm:hidden mt-3",children:d.jsx(st,{models:P,selectedModel:M.personaId?`persona:${M.personaId}`:M.model,onModelChange:z,currentPersona:w,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:T})}),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(no,{sessionId:M?.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.4.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:a("chat.footer.disclaimer")}),S&&d.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",l.length>0&&a("chat.footer.images",{count:l.length}),l.length>0&&c&&" • ",c&&a("chat.footer.structuredOutput")]})]})]})]})]})})},uo=({persona:r,onClear:e,className:t})=>{const[a,s]=E.useState(!1),n=E.useRef(null),[l,u]=E.useState({top:0,left:0});E.useEffect(()=>{if(a&&n.current){const f=n.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:Z("relative",t),children:[d.jsxs("button",{ref:n,onClick:()=>s(!a),className:Z("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(za,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),d.jsx(A0,{className:Z("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&Yt.createPortal(d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>s(!1)}),d.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:d.jsxs("div",{className:Z("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(),s(!1)},className:"absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors",title:"Remove persona",children:d.jsx(b0,{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(Q0,{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(sn,{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(nn,{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(qt,{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(Q0,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},co=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const s=E.useRef(null),[n,l]=E.useState(!1),u=b=>{if(!b)return;const T=[],k=t-r.length;for(let j=0;j<Math.min(b.length,k);j++){const B=b[j];if(!B.type.startsWith("image/")){he.error(`File ${B.name} is not an image`);continue}if(B.size>10*1024*1024){he.error(`Image ${B.name} is too large (max 10MB)`);continue}const M=new FileReader;M.onload=P=>{P.target?.result&&(T.push(P.target.result),T.length===Math.min(b.length,k)&&e([...r,...T]))},M.readAsDataURL(B)}b.length>k&&he.error(`Only ${k} more images can be added`)},c=b=>{b.preventDefault(),l(!0)},p=b=>{b.preventDefault(),l(!1)},f=b=>{b.preventDefault(),l(!1),u(b.dataTransfer.files)},x=b=>{const T=r.filter((k,j)=>j!==b);e(T)},w=r.length<t;return d.jsxs("div",{className:Z("space-y-3",a),children:[w&&d.jsxs("div",{className:Z("border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors","hover:border-primary-400 dark:hover:border-primary-500",n&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:c,onDragLeave:p,onDrop:f,children:[d.jsx("input",{ref:s,type:"file",multiple:!0,accept:"image/*",onChange:b=>u(b.target.files),className:"hidden"}),d.jsxs("div",{className:"flex flex-col items-center text-center",children:[d.jsx(Ma,{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:()=>s.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((b,T)=>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:b,alt:`Upload ${T+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(We,{variant:"ghost",size:"sm",onClick:()=>x(T),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(b0,{className:"h-4 w-4"})})})]},T))}),w&&r.length>0&&d.jsxs(We,{variant:"outline",size:"sm",onClick:()=>s.current?.click(),className:"w-full sm:w-auto",children:[d.jsx(Ta,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},ho=r=>{const[e,t]=E.useState(""),[a,s]=E.useState(null),[n,l]=E.useState(!1),{addMessage:u,updateMessage:c,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:x}=be(),{setIsGenerating:w,preferences:b}=x0(),T=E.useRef(null),k=E.useRef(null),j=E.useRef(""),B=E.useRef(0),M=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",z=>{const S=z,A=S.messageId||T.current;A&&(j.current=S.total,t(S.total),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{c(r,A,j.current),B.current=Date.now()},S.done?0:200))}),ve.onMessage("assistant_complete",z=>{const S=z;console.log("Hook: Received assistant_complete for session:",r,"messageId:",S.messageId,"with statistics:",!!S.statistics),l(!1),t(""),w(!1);const A=S.messageId||T.current;if(S&&A){const K=j.current||S.content;p(r,A,K,S.statistics)}const G=x0.getState().preferences.titleSettings,U=be.getState().currentSession,te=k.current;console.log("Auto-title check:",{firstMessage:te,autoTitle:G?.autoTitle,taskModel:G?.taskModel,sessionTitle:U?.title}),te&&G?.autoTitle&&G?.taskModel&&U?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),x(r),J0.generateTitle(r,G.taskModel,te).then(K=>{console.log("Title generation response:",K),K.success&&K.data?.title&&f(r,K.data.title)}).catch(K=>{console.error("Failed to generate title:",K)}).finally(()=>{x(null)}),k.current=null),T.current=null,j.current="",M.current&&clearTimeout(M.current),B.current=0}),ve.onMessage("error",z=>{const S=z;if(l(!1),t(""),w(!1),T.current=null,S.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),he.error("Session not found. Creating a new session..."),window.location.href="/";return}he.error(S.error)}),l(!1),t(""),T.current=null,()=>{M.current&&clearTimeout(M.current)}},[r,c,p,w,f,x]);const P=E.useCallback(async(D,z,S)=>{if(!(!r||!D.trim()&&(!z||z.length===0)))try{w(!0),l(!0),t(""),M.current&&clearTimeout(M.current),B.current=Date.now();const A=be.getState().currentSession,H=A?.isPrivate===!0,G=A?.messages?.some(K=>K.role==="user");!H&&!G&&A?.title==="New Chat"&&(k.current=D.trim()),u(r,{role:"user",content:D.trim(),images:z});const U=Sr();T.current=U,s(U),u(r,{role:"assistant",content:"",id:U}),ve.isConnected||await ve.connect();const te=H?A?.messages?.filter(K=>K.role!=="system"&&K.id!==U).map(K=>({role:K.role,content:K.content,images:K.images})):void 0;ve.send({type:"chat_stream",data:{sessionId:r,content:D.trim(),images:z,format:S,options:b.generationOptions,assistantMessageId:U,isPrivate:H,model:H?A?.model:void 0,messageHistory:te}})}catch(A){console.error("Failed to send message:",A),l(!1),t(""),s(null),w(!1),T.current=null,he.error("Failed to send message")}},[r,u,w,b.generationOptions]),q=E.useCallback(()=>{l(!1),t(""),s(null),w(!1),T.current=null},[w]),R=E.useCallback(async()=>{const D=be.getState().currentSession;if(!D||!r)return;const z=D.messages;let S=-1,A=-1;for(let U=z.length-1;U>=0;U--)if(z[U].role==="assistant"){A=U;break}if(A>0){for(let U=A-1;U>=0;U--)if(z[U].role==="user"){S=U;break}}if(S===-1||A===-1){he.error("No message to regenerate");return}const H=z[S],G=z[A];try{w(!0),l(!0),t(""),M.current&&clearTimeout(M.current),B.current=Date.now();const U=Sr();T.current=U,s(U),u(r,{role:"assistant",content:"",id:U,parentId:G.parentId||G.id,branchIndex:G.siblingCount||1,isActive:!0}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:H.content,images:H.images,options:b.generationOptions,assistantMessageId:U,regenerate:!0,originalMessageId:G.id}})}catch(U){console.error("Failed to regenerate message:",U),l(!1),t(""),w(!1),T.current=null,he.error("Failed to regenerate message")}},[r,w,u,b.generationOptions]),V=E.useCallback(async D=>{const S=be.getState().currentSession;if(!S||!r)return;const A=S.messages.find(U=>U.id===D);if(!A){he.error("Message not found");return}if(A.isActive!==!1)return;const H=A.parentId||A.id,G=A.branchIndex||0;try{const U=await J0.switchMessageBranch(r,D,G);if(U.success&&U.data){const te=S.messages.map(ne=>ne.id===H||ne.parentId===H?{...ne,isActive:ne.id===D}:ne),K={...S,messages:te,updatedAt:Date.now()};be.setState(ne=>({sessions:ne.sessions.map(ge=>ge.id===r?K:ge),currentSession:K})),he.success(`Switched to variant ${G+1}`)}else he.error(U.error||"Failed to select branch")}catch(U){console.error("Failed to select branch:",U),he.error("Failed to select branch")}},[r]);return{sendMessage:P,stopGeneration:q,regenerateLastMessage:R,selectBranch:V,isStreaming:n,streamingMessage:e,streamingMessageId:a}},mo=(r,e)=>{const t=new Date().getHours(),a=r?`, ${r}`:"";return t>=5&&t<12?{greeting:`${e?e("chat.greeting.morning"):"Good morning"}${a}`,timeSuffix:"today"}:t>=12&&t<17?{greeting:`${e?e("chat.greeting.afternoon"):"Good afternoon"}${a}`,timeSuffix:"today"}:t>=17&&t<21?{greeting:`${e?e("chat.greeting.evening"):"Good evening"}${a}`,timeSuffix:"tonight"}:{greeting:`${e?e("chat.greeting.night"):"Good night"}${a}`,timeSuffix:"tonight"}},wo=()=>{const{t:r}=o0(),{sessionId:e}=Os(),t=va(),a=Ps(),{currentSession:s,sessions:n,models:l,selectedModel:u,setSelectedModel:c,createSession:p,setCurrentSession:f,loadSessions:x,getCurrentPersona:w}=be(),{user:b}=xa(),{sendMessage:T,stopGeneration:k,regenerateLastMessage:j,selectBranch:B,isStreaming:M,streamingMessage:P,streamingMessageId:q}=ho(s?.id||""),R=w(),{greeting:V,timeSuffix:D}=E.useMemo(()=>mo(b?.username,r),[b?.username,r]),[z,S]=E.useState(""),[A,H]=E.useState([]),[G,U]=E.useState(!1),te=E.useRef(null),[K,ne]=E.useState(!1);E.useEffect(()=>{n.length===0&&x()},[x,n.length]),E.useEffect(()=>{(async()=>{try{const Q=await ba.getPlugins();ne(!!(Q.success&&Q.data&&Q.data.length>0))}catch{ne(!1)}})()},[]),E.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const de=n.find(Re=>Re.id===e);de&&de.id!==s?.id?f(de):de||(console.warn(`Session ${e} not found for current user, redirecting...`),n.length>0?t(`/c/${n[0].id}`,{replace:!0}):t("/",{replace:!0}))}else!e&&n.length>0&&a.pathname==="/"&&t(`/c/${n[0].id}`,{replace:!0})})()},[e,n,f,t,s?.id,s?.isPrivate,a.pathname]),E.useEffect(()=>{if(s?.id){const _=sessionStorage.getItem("pendingMessage");if(_){sessionStorage.removeItem("pendingMessage");try{const Q=JSON.parse(_);setTimeout(()=>{T(Q.content,Q.images)},100)}catch(Q){console.error("Failed to parse pending message:",Q)}}}},[s?.id,T]),E.useEffect(()=>{const _=te.current;_&&(_.style.height="auto",_.style.height=Math.min(_.scrollHeight,200)+"px")},[z]);const ge=async _=>{if(_.preventDefault(),!z.trim()||!u)return;const Q={content:z.trim(),images:A.length>0?A:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(Q)),S(""),H([]);const de=await p(u);de&&t(`/c/${de.id}`,{replace:!0})},Se=_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),ge(_))},Ae=async _=>{const Q=_.target.value;c(Q)},Ce=(_,Q,de)=>{s&&T(_,Q,de)};if(!s){const _=A.length>0;return d.jsxs("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative",children:[d.jsxs("button",{onClick:()=>{if(!u&&l.length===0)return;const Q=Date.now(),de={id:`private-${Q}`,title:r("chat.session.private"),model:u||l[0]?.name||"",messages:[],createdAt:Q,updatedAt:Q,isPrivate:!0};f(de)},disabled:!u&&l.length===0,className:"absolute top-4 right-4 flex items-center gap-2 px-3 py-1.5 rounded-full border border-gray-300 dark:border-dark-400 ophelia:border-[#3f3f46] bg-transparent hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",title:r("chat.session.privateTooltip"),children:[d.jsx(Nr,{className:"h-4 w-4"}),d.jsx("span",{className:"text-sm",children:r("chat.session.private")})]}),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:V}),d.jsx("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:r(D==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?d.jsxs("div",{className:"w-full",children:[G&&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(co,{images:A,onImagesChange:H,maxImages:5})}),d.jsx("form",{onSubmit:ge,children:d.jsxs("div",{className:Z("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(We,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(!G),className:Z("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",_&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",G&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:r("chat.input.attachImages"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:_?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Aa,{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"})]}):G?d.jsx(Ca,{className:"h-4 w-4"}):d.jsx(Zt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(xr,{ref:te,value:z,onChange:Q=>S(Q.target.value),onKeyDown:Se,placeholder:r("chat.input.messagePlaceholder"),className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 ophelia:scrollbar-thumb-[#3f3f46] focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 ophelia:placeholder:text-[#737373] text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),d.jsx("div",{className:"hidden sm:block",children:d.jsx(st,{models:l,selectedModel:u,onModelChange:Ae,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:K})}),d.jsx(We,{type:"submit",variant:"ghost",size:"sm",disabled:!z.trim()||!u,className:Z("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",z.trim()&&u&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:d.jsx(ja,{className:"h-4 w-4"})})]})}),d.jsx("div",{className:"sm:hidden mt-4",children:d.jsx(st,{models:l,selectedModel:u,onModelChange:Ae,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:K})}),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.4.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:r("chat.footer.disclaimer")})]})]}):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:r("chat.model.noModelsDescription")}),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:r("chat.model.pullCommand")})]})})]})]})}return d.jsxs("div",{className:"flex flex-col h-full relative",style:R?.background?{backgroundImage:`url(${R.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[R?.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:[s?.isPrivate&&d.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#262626] bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#0a0a0a]/80 backdrop-blur-sm",children:d.jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[d.jsx(Nr,{className:"h-4 w-4"}),d.jsx("span",{className:"text-sm font-medium",children:r("chat.session.privateMode")}),d.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-500 ophelia:text-[#737373]",children:["— ",r("chat.session.privateDescription")]})]})}),R&&!s?.isPrivate&&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(uo,{persona:R,onClear:()=>{if(s){const{sessions:_}=be.getState(),Q={...s,model:R.model,personaId:void 0},de=_.map(Re=>Re.id===s.id?Q:Re);be.setState({sessions:de,currentSession:Q})}}})}),d.jsx(ro,{messages:s.messages,streamingMessage:P,streamingMessageId:q,isStreaming:M,onRegenerate:j,onSelectBranch:B,className:"flex-1"}),d.jsx(oo,{onSendMessage:Ce,onStopGeneration:k,disabled:!s})]})]})};export{wo as ChatPage,wo as default};
281
+ }`,rows:8,className:"font-mono text-sm"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(We,{onClick:x,size:"sm",disabled:!l.trim(),children:a("chat.structuredOutput.applySchema")}),d.jsx(We,{onClick:()=>{n(!1),u("")},variant:"outline",size:"sm",children:a("chat.structuredOutput.cancel")})]})]}),w(),r&&d.jsxs("div",{className:"flex items-center text-xs text-green-600 dark:text-green-400",children:[d.jsx(Na,{className:"h-3 w-3 mr-1"}),a("chat.structuredOutput.enabled")]})]})},st=({models:r,selectedModel:e,onModelChange:t,currentPersona:a,className:s,disabled:n=!1,compact:l=!1,showImageGen:u=!1})=>{const{t:c}=o0(),[p,f]=E.useState(!1),[x,w]=E.useState(""),b=E.useRef(null),T=E.useRef(null),k=va(),B=[{type:"personas",label:"Personas",icon:d.jsx(Ft,{className:"h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>z.isPersona),color:"purple"},{type:"ollama",label:"Ollama Models",icon:d.jsx(gt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>!z.isPersona&&!z.isPlugin),color:"green"},{type:"plugins",label:"Plugin Models",icon:d.jsx(qt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),models:r.filter(z=>z.isPlugin),color:"green"}].filter(z=>z.models.length>0).map(z=>({...z,models:z.models.filter(S=>S.name.toLowerCase().includes(x.toLowerCase())||S.personaName&&S.personaName.toLowerCase().includes(x.toLowerCase())||S.pluginName&&S.pluginName.toLowerCase().includes(x.toLowerCase()))})).filter(z=>z.models.length>0),M=r.find(z=>z.name===e||e.startsWith("persona:")&&z.name===e);E.useEffect(()=>{const z=S=>{b.current&&!b.current.contains(S.target)&&(f(!1),w(""))};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),E.useEffect(()=>{p&&T.current&&T.current.focus()},[p]);const P=z=>{t({target:{value:z}}),f(!1),w("")},q=z=>z.isPersona?d.jsx(Ft,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}):z.isPlugin?d.jsx(qt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}):d.jsx(gt,{className:"h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]"}),R=z=>z.isPersona?z.personaName||z.name:z.isPlugin?`${z.name}`:z.name,V=z=>z.isPersona?`via ${z.model}`:z.isPlugin?`via ${z.pluginName}`:null,D=()=>{if(!M)return l?d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(gt,{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 A=R(M);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[q(M),d.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate",children:A})]})}const z=R(M),S=V(M);return d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[q(M),d.jsxs("div",{className:"flex flex-col min-w-0",children:[d.jsx("span",{className:"text-sm font-medium truncate",children:z}),S&&d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:S})]}),M.isPersona&&a&&d.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[d.jsx(Q0,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),a.embedding_model&&d.jsx(za,{className:"h-3 w-3 text-purple-500 dark:text-purple-300"})]})]})};return d.jsxs("div",{className:Z("relative",s),ref:b,children:[d.jsxs("button",{type:"button",onClick:()=>!n&&f(!p),disabled:n,className:Z(l?"h-[44px] sm:h-[52px] px-3 flex items-center justify-between text-left w-full ":"w-full flex items-center justify-between gap-2 px-3 py-2 text-left ","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","rounded-lg text-sm hover:bg-gray-100 dark:hover:bg-dark-100 ophelia:hover:bg-[#1a1a1a]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20 focus:border-primary-500 ophelia:focus:border-[#9333ea]",n?"opacity-50 cursor-not-allowed":"cursor-pointer"),title:l?M?R(M):"Select Model":void 0,children:[D(),d.jsx(A0,{className:Z(l?"h-3 w-3":"h-4 w-4","text-gray-400 flex-shrink-0",p&&"rotate-180")})]}),p&&Yt.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:()=>f(!1)}),d.jsxs("div",{className:Z("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:z=>z.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:T,type:"text",placeholder:"Search models...",value:x,onChange:z=>w(z.target.value),onClick:z=>z.stopPropagation(),onMouseDown:z=>z.stopPropagation(),className:Z("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(z=>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:[z.icon,z.label," (",z.models.length,")"]})}),z.models.map(S=>d.jsx("div",{onMouseDown:A=>{A.preventDefault(),P(S.name)},onTouchStart:A=>{A.preventDefault(),P(S.name)},className:Z("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===S.name||e.startsWith("persona:")&&S.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:[q(S),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:R(S)}),V(S)&&d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate",children:V(S)})]}),(e===S.name||e.startsWith("persona:")&&S.name===e)&&d.jsx(nt,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0"})]})},S.name))]},z.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(an,{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(Zt,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"}),"Actions"]})}),d.jsx("div",{onMouseDown:z=>{z.preventDefault(),f(!1),k("/gallery")},onTouchStart:z=>{z.preventDefault(),f(!1),k("/gallery")},className:Z("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(Ta,{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:c("gallery.generate")}),d.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:c("gallery.generateDescription")})]})]})})]})]})]})]}),document.body),d.jsx("select",{value:e,onChange:t,className:"sr-only",tabIndex:-1,children:r.map(z=>d.jsx("option",{value:z.name,children:R(z)},z.name))})]})},oo=({onSendMessage:r,onStopGeneration:e,disabled:t=!1})=>{const{t:a}=o0(),[s,n]=E.useState(""),[l,u]=E.useState([]),[c,p]=E.useState(null),[f,x]=E.useState(!1),[w,b]=E.useState(null),[T,k]=E.useState(!1),{isGenerating:j,setBackgroundImage:B}=x0(),{currentSession:M,models:P}=be(),q=E.useRef(null);E.useEffect(()=>{(async()=>{try{const H=await ba.getPlugins();k(!!(H.success&&H.data&&H.data.length>0))}catch{k(!1)}})()},[]);const R=A=>{A.preventDefault(),!(!s.trim()||j)&&(r(s.trim(),l.length>0?l:void 0,c||void 0),n(""),u([]))},V=A=>{A.key==="Enter"&&!A.shiftKey&&(A.preventDefault(),R(A))},D=()=>{e()};E.useEffect(()=>{const A=q.current;A&&(A.style.height="auto",A.style.height=Math.min(A.scrollHeight,200)+"px")},[s]),E.useEffect(()=>{(async()=>{if(M?.personaId)try{const H=await kr.getPersona(M.personaId);if(H.success&&H.data)b(H.data);else{console.warn(`Persona ${M.personaId} not found, clearing reference`),b(null);const{setCurrentSession:G}=be.getState();G({...M,personaId:void 0})}}catch(H){if(console.error("Failed to load current persona:",H),b(null),M){const{setCurrentSession:G}=be.getState();G({...M,personaId:void 0})}}else b(null)})()},[M?.personaId]);const z=async A=>{const H=A.target.value;if(M)try{if(H.startsWith("persona:")){const G=H.replace("persona:",""),U=await kr.getPersona(G);if(!U.success||!U.data){O0.error("Failed to load persona details");return}const te=U.data,K=await J0.updateSession(M.id,{personaId:G,model:H});if(K.success&&K.data){const{sessions:ne}=be.getState(),ge=ne.map(Se=>Se.id===M.id?K.data:Se);be.setState({sessions:ge,currentSession:K.data}),te.background&&B(te.background),O0.success(a("chat.persona.applied"))}}else{const G=await J0.updateSession(M.id,{model:H,personaId:void 0});if(G.success&&G.data){const{sessions:U}=be.getState(),te=U.map(K=>K.id===M.id?G.data:K);be.setState({sessions:te,currentSession:G.data}),B(null),O0.success(a("chat.model.updated"))}}}catch(G){console.error("Failed to update session:",G),O0.error("Failed to update session")}},S=l.length>0||c!==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:[f&&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(so,{images:l,onImagesChange:u,maxImages:5,sessionId:M?.id,disabled:t}),d.jsx(lo,{format:c,onFormatChange:p})]}),d.jsxs("div",{className:"py-2 sm:py-3",children:[d.jsx("form",{onSubmit:R,children:d.jsxs("div",{className:Z("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(We,{type:"button",variant:"ghost",size:"sm",onClick:()=>x(!f),className:Z("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",S&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",f&&"bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]"),title:a("chat.input.attachments"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:S?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Aa,{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]"})]}):f?d.jsx(Ca,{className:"h-4 w-4"}):d.jsx(Zt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(xr,{ref:q,value:s,onChange:A=>n(A.target.value),onKeyDown:V,placeholder:a("chat.input.placeholder"),disabled:t,className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),d.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[M&&P.length>0&&d.jsx("div",{className:"hidden sm:block",children:d.jsx(st,{models:P,selectedModel:M.personaId?`persona:${M.personaId}`:M.model,onModelChange:z,currentPersona:w,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:T})}),j?d.jsx(We,{type:"button",variant:"ghost",size:"sm",onClick:D,className:Z("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","bg-red-50 dark:bg-red-900/20 ophelia:bg-red-900/30","text-red-500 dark:text-red-400 ophelia:text-red-400","hover:bg-red-100 dark:hover:bg-red-900/30 ophelia:hover:bg-red-900/40","transition-all duration-200 touch-manipulation","hover:scale-105 active:scale-95"),title:a("chat.input.stopGeneration"),children:d.jsx(ka,{className:"h-4 w-4"})}):d.jsx(We,{type:"submit",variant:"ghost",size:"sm",disabled:!s.trim()||t,className:Z("h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center","text-gray-400 dark:text-dark-500 ophelia:text-[#525252]","disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed","transition-all duration-200 touch-manipulation",s.trim()&&!t&&["bg-primary-500 dark:bg-primary-600 ophelia:bg-[#9333ea]","text-white dark:text-white ophelia:text-white","hover:bg-primary-600 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","shadow-md hover:shadow-lg","hover:scale-105 active:scale-95"]),title:a("chat.input.sendMessage"),children:d.jsx(ja,{className:"h-4 w-4"})})]})]})}),M&&P.length>0&&d.jsx("div",{className:"sm:hidden mt-3",children:d.jsx(st,{models:P,selectedModel:M.personaId?`persona:${M.personaId}`:M.model,onModelChange:z,currentPersona:w,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:T})}),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(no,{sessionId:M?.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.4.3"]})," ",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:a("chat.footer.disclaimer")}),S&&d.jsxs("span",{className:"ml-2 text-primary-600 dark:text-primary-400",children:["•"," ",l.length>0&&a("chat.footer.images",{count:l.length}),l.length>0&&c&&" • ",c&&a("chat.footer.structuredOutput")]})]})]})]})]})})},uo=({persona:r,onClear:e,className:t})=>{const[a,s]=E.useState(!1),n=E.useRef(null),[l,u]=E.useState({top:0,left:0});E.useEffect(()=>{if(a&&n.current){const f=n.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:Z("relative",t),children:[d.jsxs("button",{ref:n,onClick:()=>s(!a),className:Z("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(za,{className:"h-3 w-3 text-purple-500 dark:text-purple-400"}),d.jsx(A0,{className:Z("h-3.5 w-3.5 transition-transform duration-200",a&&"rotate-180")})]}),a&&Yt.createPortal(d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>s(!1)}),d.jsx("div",{className:"fixed w-72 z-[9999]",style:{top:l.top,left:l.left},children:d.jsxs("div",{className:Z("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(),s(!1)},className:"absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors",title:"Remove persona",children:d.jsx(b0,{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(Q0,{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(sn,{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(nn,{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(qt,{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(Q0,{className:"h-2.5 w-2.5"}),"Memory"]})]})]})]})})]}),document.body)]})},co=({images:r,onImagesChange:e,maxImages:t=5,className:a})=>{const s=E.useRef(null),[n,l]=E.useState(!1),u=b=>{if(!b)return;const T=[],k=t-r.length;for(let j=0;j<Math.min(b.length,k);j++){const B=b[j];if(!B.type.startsWith("image/")){he.error(`File ${B.name} is not an image`);continue}if(B.size>10*1024*1024){he.error(`Image ${B.name} is too large (max 10MB)`);continue}const M=new FileReader;M.onload=P=>{P.target?.result&&(T.push(P.target.result),T.length===Math.min(b.length,k)&&e([...r,...T]))},M.readAsDataURL(B)}b.length>k&&he.error(`Only ${k} more images can be added`)},c=b=>{b.preventDefault(),l(!0)},p=b=>{b.preventDefault(),l(!1)},f=b=>{b.preventDefault(),l(!1),u(b.dataTransfer.files)},x=b=>{const T=r.filter((k,j)=>j!==b);e(T)},w=r.length<t;return d.jsxs("div",{className:Z("space-y-3",a),children:[w&&d.jsxs("div",{className:Z("border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors","hover:border-primary-400 dark:hover:border-primary-500",n&&"border-primary-500 bg-primary-50 dark:bg-primary-900/20"),onDragOver:c,onDragLeave:p,onDrop:f,children:[d.jsx("input",{ref:s,type:"file",multiple:!0,accept:"image/*",onChange:b=>u(b.target.files),className:"hidden"}),d.jsxs("div",{className:"flex flex-col items-center text-center",children:[d.jsx(Ma,{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:()=>s.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((b,T)=>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:b,alt:`Upload ${T+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(We,{variant:"ghost",size:"sm",onClick:()=>x(T),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(b0,{className:"h-4 w-4"})})})]},T))}),w&&r.length>0&&d.jsxs(We,{variant:"outline",size:"sm",onClick:()=>s.current?.click(),className:"w-full sm:w-auto",children:[d.jsx(Ta,{className:"h-4 w-4 mr-2"}),"Add More Images (",r.length,"/",t,")"]})]})},ho=r=>{const[e,t]=E.useState(""),[a,s]=E.useState(null),[n,l]=E.useState(!1),{addMessage:u,updateMessage:c,updateMessageWithStatistics:p,updateSessionTitle:f,setGeneratingTitleForSession:x}=be(),{setIsGenerating:w,preferences:b}=x0(),T=E.useRef(null),k=E.useRef(null),j=E.useRef(""),B=E.useRef(0),M=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",z=>{const S=z,A=S.messageId||T.current;A&&(j.current=S.total,t(S.total),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{c(r,A,j.current),B.current=Date.now()},S.done?0:200))}),ve.onMessage("assistant_complete",z=>{const S=z;console.log("Hook: Received assistant_complete for session:",r,"messageId:",S.messageId,"with statistics:",!!S.statistics),l(!1),t(""),w(!1);const A=S.messageId||T.current;if(S&&A){const K=j.current||S.content;p(r,A,K,S.statistics)}const G=x0.getState().preferences.titleSettings,U=be.getState().currentSession,te=k.current;console.log("Auto-title check:",{firstMessage:te,autoTitle:G?.autoTitle,taskModel:G?.taskModel,sessionTitle:U?.title}),te&&G?.autoTitle&&G?.taskModel&&U?.title==="New Chat"&&(console.log("Triggering auto-title generation..."),x(r),J0.generateTitle(r,G.taskModel,te).then(K=>{console.log("Title generation response:",K),K.success&&K.data?.title&&f(r,K.data.title)}).catch(K=>{console.error("Failed to generate title:",K)}).finally(()=>{x(null)}),k.current=null),T.current=null,j.current="",M.current&&clearTimeout(M.current),B.current=0}),ve.onMessage("error",z=>{const S=z;if(l(!1),t(""),w(!1),T.current=null,S.code==="SESSION_NOT_FOUND"){console.warn("Session not found, redirecting to create new session..."),he.error("Session not found. Creating a new session..."),window.location.href="/";return}he.error(S.error)}),l(!1),t(""),T.current=null,()=>{M.current&&clearTimeout(M.current)}},[r,c,p,w,f,x]);const P=E.useCallback(async(D,z,S)=>{if(!(!r||!D.trim()&&(!z||z.length===0)))try{w(!0),l(!0),t(""),M.current&&clearTimeout(M.current),B.current=Date.now();const A=be.getState().currentSession,H=A?.isPrivate===!0,G=A?.messages?.some(K=>K.role==="user");!H&&!G&&A?.title==="New Chat"&&(k.current=D.trim()),u(r,{role:"user",content:D.trim(),images:z});const U=Sr();T.current=U,s(U),u(r,{role:"assistant",content:"",id:U}),ve.isConnected||await ve.connect();const te=H?A?.messages?.filter(K=>K.role!=="system"&&K.id!==U).map(K=>({role:K.role,content:K.content,images:K.images})):void 0;ve.send({type:"chat_stream",data:{sessionId:r,content:D.trim(),images:z,format:S,options:b.generationOptions,assistantMessageId:U,isPrivate:H,model:H?A?.model:void 0,messageHistory:te}})}catch(A){console.error("Failed to send message:",A),l(!1),t(""),s(null),w(!1),T.current=null,he.error("Failed to send message")}},[r,u,w,b.generationOptions]),q=E.useCallback(()=>{l(!1),t(""),s(null),w(!1),T.current=null},[w]),R=E.useCallback(async()=>{const D=be.getState().currentSession;if(!D||!r)return;const z=D.messages;let S=-1,A=-1;for(let U=z.length-1;U>=0;U--)if(z[U].role==="assistant"){A=U;break}if(A>0){for(let U=A-1;U>=0;U--)if(z[U].role==="user"){S=U;break}}if(S===-1||A===-1){he.error("No message to regenerate");return}const H=z[S],G=z[A];try{w(!0),l(!0),t(""),M.current&&clearTimeout(M.current),B.current=Date.now();const U=Sr();T.current=U,s(U),u(r,{role:"assistant",content:"",id:U,parentId:G.parentId||G.id,branchIndex:G.siblingCount||1,isActive:!0}),ve.isConnected||await ve.connect(),ve.send({type:"chat_stream",data:{sessionId:r,content:H.content,images:H.images,options:b.generationOptions,assistantMessageId:U,regenerate:!0,originalMessageId:G.id}})}catch(U){console.error("Failed to regenerate message:",U),l(!1),t(""),w(!1),T.current=null,he.error("Failed to regenerate message")}},[r,w,u,b.generationOptions]),V=E.useCallback(async D=>{const S=be.getState().currentSession;if(!S||!r)return;const A=S.messages.find(U=>U.id===D);if(!A){he.error("Message not found");return}if(A.isActive!==!1)return;const H=A.parentId||A.id,G=A.branchIndex||0;try{const U=await J0.switchMessageBranch(r,D,G);if(U.success&&U.data){const te=S.messages.map(ne=>ne.id===H||ne.parentId===H?{...ne,isActive:ne.id===D}:ne),K={...S,messages:te,updatedAt:Date.now()};be.setState(ne=>({sessions:ne.sessions.map(ge=>ge.id===r?K:ge),currentSession:K})),he.success(`Switched to variant ${G+1}`)}else he.error(U.error||"Failed to select branch")}catch(U){console.error("Failed to select branch:",U),he.error("Failed to select branch")}},[r]);return{sendMessage:P,stopGeneration:q,regenerateLastMessage:R,selectBranch:V,isStreaming:n,streamingMessage:e,streamingMessageId:a}},mo=(r,e)=>{const t=new Date().getHours(),a=r?`, ${r}`:"";return t>=5&&t<12?{greeting:`${e?e("chat.greeting.morning"):"Good morning"}${a}`,timeSuffix:"today"}:t>=12&&t<17?{greeting:`${e?e("chat.greeting.afternoon"):"Good afternoon"}${a}`,timeSuffix:"today"}:t>=17&&t<21?{greeting:`${e?e("chat.greeting.evening"):"Good evening"}${a}`,timeSuffix:"tonight"}:{greeting:`${e?e("chat.greeting.night"):"Good night"}${a}`,timeSuffix:"tonight"}},yo=()=>{const{t:r}=o0(),{sessionId:e}=Os(),t=va(),a=Ps(),{currentSession:s,sessions:n,models:l,selectedModel:u,setSelectedModel:c,createSession:p,setCurrentSession:f,loadSessions:x,getCurrentPersona:w}=be(),{user:b}=xa(),{sendMessage:T,stopGeneration:k,regenerateLastMessage:j,selectBranch:B,isStreaming:M,streamingMessage:P,streamingMessageId:q}=ho(s?.id||""),R=w(),{greeting:V,timeSuffix:D}=E.useMemo(()=>mo(b?.username,r),[b?.username,r]),[z,S]=E.useState(""),[A,H]=E.useState([]),[G,U]=E.useState(!1),te=E.useRef(null),[K,ne]=E.useState(!1);E.useEffect(()=>{n.length===0&&x()},[x,n.length]),E.useEffect(()=>{(async()=>{try{const Q=await ba.getPlugins();ne(!!(Q.success&&Q.data&&Q.data.length>0))}catch{ne(!1)}})()},[]),E.useEffect(()=>{(()=>{if(sessionStorage.getItem("forceWelcomeScreen")){sessionStorage.removeItem("forceWelcomeScreen");return}if(!s?.isPrivate&&n.length!==0)if(e){const de=n.find(Re=>Re.id===e);de&&de.id!==s?.id?f(de):de||(console.warn(`Session ${e} not found for current user, redirecting...`),n.length>0?t(`/c/${n[0].id}`,{replace:!0}):t("/",{replace:!0}))}else!e&&n.length>0&&a.pathname==="/"&&t(`/c/${n[0].id}`,{replace:!0})})()},[e,n,f,t,s?.id,s?.isPrivate,a.pathname]),E.useEffect(()=>{if(s?.id){const _=sessionStorage.getItem("pendingMessage");if(_){sessionStorage.removeItem("pendingMessage");try{const Q=JSON.parse(_);setTimeout(()=>{T(Q.content,Q.images)},100)}catch(Q){console.error("Failed to parse pending message:",Q)}}}},[s?.id,T]),E.useEffect(()=>{const _=te.current;_&&(_.style.height="auto",_.style.height=Math.min(_.scrollHeight,200)+"px")},[z]);const ge=async _=>{if(_.preventDefault(),!z.trim()||!u)return;const Q={content:z.trim(),images:A.length>0?A:void 0};sessionStorage.setItem("pendingMessage",JSON.stringify(Q)),S(""),H([]);const de=await p(u);de&&t(`/c/${de.id}`,{replace:!0})},Se=_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),ge(_))},Ae=async _=>{const Q=_.target.value;c(Q)},Ce=(_,Q,de)=>{s&&T(_,Q,de)};if(!s){const _=A.length>0;return d.jsxs("div",{className:"h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative",children:[d.jsxs("button",{onClick:()=>{if(!u&&l.length===0)return;const Q=Date.now(),de={id:`private-${Q}`,title:r("chat.session.private"),model:u||l[0]?.name||"",messages:[],createdAt:Q,updatedAt:Q,isPrivate:!0};f(de)},disabled:!u&&l.length===0,className:"absolute top-4 right-4 flex items-center gap-2 px-3 py-1.5 rounded-full border border-gray-300 dark:border-dark-400 ophelia:border-[#3f3f46] bg-transparent hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",title:r("chat.session.privateTooltip"),children:[d.jsx(Nr,{className:"h-4 w-4"}),d.jsx("span",{className:"text-sm",children:r("chat.session.private")})]}),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:V}),d.jsx("p",{className:"text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center",children:r(D==="today"?"chat.welcome.helpToday":"chat.welcome.helpTonight")}),l.length>0?d.jsxs("div",{className:"w-full",children:[G&&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(co,{images:A,onImagesChange:H,maxImages:5})}),d.jsx("form",{onSubmit:ge,children:d.jsxs("div",{className:Z("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(We,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(!G),className:Z("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",_&&"text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]",G&&"bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),title:r("chat.input.attachImages"),style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0"},children:_?d.jsxs("div",{className:"relative flex items-center justify-center",children:[d.jsx(Aa,{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"})]}):G?d.jsx(Ca,{className:"h-4 w-4"}):d.jsx(Zt,{className:"h-4 w-4"})}),d.jsx("div",{className:"flex-1 min-w-0",children:d.jsx(xr,{ref:te,value:z,onChange:Q=>S(Q.target.value),onKeyDown:Se,placeholder:r("chat.input.messagePlaceholder"),className:"!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 ophelia:scrollbar-thumb-[#3f3f46] focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 ophelia:placeholder:text-[#737373] text-base sm:text-sm leading-none touch-manipulation",rows:1,style:{boxShadow:"none !important",border:"none !important",outline:"none !important",padding:"0 !important",margin:"0 !important",lineHeight:"1.2 !important",verticalAlign:"middle"}})}),d.jsx("div",{className:"hidden sm:block",children:d.jsx(st,{models:l,selectedModel:u,onModelChange:Ae,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:K})}),d.jsx(We,{type:"submit",variant:"ghost",size:"sm",disabled:!z.trim()||!u,className:Z("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",z.trim()&&u&&"hover:scale-105 active:scale-95"),title:r("chat.input.sendMessage"),children:d.jsx(ja,{className:"h-4 w-4"})})]})}),d.jsx("div",{className:"sm:hidden mt-4",children:d.jsx(st,{models:l,selectedModel:u,onModelChange:Ae,className:"w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0",compact:!0,showImageGen:K})}),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.4.3"]})," ",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:r("chat.footer.disclaimer")})]})]}):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:r("chat.model.noModelsDescription")}),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:r("chat.model.pullCommand")})]})})]})]})}return d.jsxs("div",{className:"flex flex-col h-full relative",style:R?.background?{backgroundImage:`url(${R.background})`,backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat"}:void 0,children:[R?.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:[s?.isPrivate&&d.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#262626] bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#0a0a0a]/80 backdrop-blur-sm",children:d.jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[d.jsx(Nr,{className:"h-4 w-4"}),d.jsx("span",{className:"text-sm font-medium",children:r("chat.session.privateMode")}),d.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-500 ophelia:text-[#737373]",children:["— ",r("chat.session.privateDescription")]})]})}),R&&!s?.isPrivate&&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(uo,{persona:R,onClear:()=>{if(s){const{sessions:_}=be.getState(),Q={...s,model:R.model,personaId:void 0},de=_.map(Re=>Re.id===s.id?Q:Re);be.setState({sessions:de,currentSession:Q})}}})}),d.jsx(ro,{messages:s.messages,streamingMessage:P,streamingMessageId:q,isStreaming:M,onRegenerate:j,onSelectBranch:B,className:"flex-1"}),d.jsx(oo,{onSendMessage:Ce,onStopGeneration:k,disabled:!s})]})]})};export{yo as ChatPage,yo as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-vendor-DeGQOJEA.js";import{r as l,e as A}from"./router-vendor-CYqbjR9t.js";import{a as L,c,i as E,B as _}from"../assets/index-BNamR47C.js";import{X as T,l as B,aw as R,al as H,g as M,T as Q,y as j,L as D,ax as U,I as F,o as W,s as X}from"./ui-vendor-C0aUE8gv.js";import"./utils-vendor-COrKO_vV.js";const J=({image:r,onClose:i,onDelete:h,onDownload:s})=>{const{t:o}=L();l.useEffect(()=>{const n=m=>{m.key==="Escape"&&i()};return document.addEventListener("keydown",n),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",n),document.body.style.overflow=""}},[i]);const b=n=>new Date(n).toLocaleString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}),u=()=>{if(s)s(r);else{const n=document.createElement("a");n.href=r.imageData,n.download=`generated-${r.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)}};return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center",onClick:i,children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-sm"}),e.jsxs("div",{className:"relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4",onClick:n=>n.stopPropagation(),children:[e.jsx("button",{onClick:i,className:c("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(T,{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:c("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:o("gallery.prompt")}),e.jsx("p",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] text-sm leading-relaxed",children:r.prompt})]}),e.jsxs("div",{className:"space-y-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[o("gallery.model"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.model})]}),r.size&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(R,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[o("gallery.size"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r.size})]}),r.quality&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 ophelia:text-[#525252] text-xs font-bold",children:"Q"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[o("gallery.quality"),":"]}),e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] capitalize",children:r.quality})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(H,{className:"h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:[o("gallery.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:u,className:c("flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg","bg-primary-600 dark:bg-primary-600 ophelia:bg-[#9333ea]","hover:bg-primary-700 dark:hover:bg-primary-500 ophelia:hover:bg-[#a855f7]","text-white font-medium text-sm","transition-colors"),children:[e.jsx(M,{className:"h-4 w-4"}),o("gallery.download")]}),h&&e.jsx("button",{onClick:()=>h(r.id),className:c("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)},O=({onImageCountChange:r})=>{const{t:i}=L(),[h,s]=l.useState([]),[o,b]=l.useState(0),[u,n]=l.useState(!0),[m,w]=l.useState(!1),[f,G]=l.useState(null),[y,S]=l.useState(null),C=20,v=l.useCallback(async(t=0,p=!1)=>{try{t===0?n(!0):w(!0);const d=await E.getGallery({limit:C,offset:t});d.success&&d.data&&(s(p?k=>[...k,...d.data.images]:d.data.images),b(d.data.total),r?.(d.data.total))}catch(d){console.error("Failed to load gallery:",d),j.error(i("imageGallery.loadFailed"))}finally{n(!1),w(!1)}},[r,i]);l.useEffect(()=>{v()},[v]);const P=()=>{v(h.length,!0)},z=async(t,p)=>{if(p.stopPropagation(),!y){S(t);try{(await E.deleteGalleryImage(t)).success?(s(k=>k.filter(q=>q.id!==t)),b(k=>k-1),r?.(o-1),j.success(i("imageGallery.deleteSuccess")),f?.id===t&&G(null)):j.error(i("imageGallery.deleteFailed"))}catch(d){console.error("Failed to delete image:",d),j.error(i("imageGallery.deleteFailed"))}finally{S(null)}}},N=(t,p)=>{p.stopPropagation();const d=document.createElement("a");d.href=t.imageData,d.download=`generated-${t.id}.png`,document.body.appendChild(d),d.click(),document.body.removeChild(d)},I=t=>new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});return u?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-gray-400 dark:text-gray-500"})}):h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(U,{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:i("imageGallery.noImages")}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm",children:i("imageGallery.noImagesHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:c("columns-1 sm:columns-2 lg:columns-3 xl:columns-4","gap-4 space-y-4"),children:h.map(t=>e.jsxs("div",{className:c("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:()=>G(t),children:[e.jsx("img",{src:t.imageData,alt:t.prompt,className:"w-full h-auto object-cover",loading:"lazy"}),e.jsxs("div",{className:c("absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent","opacity-0 group-hover:opacity-100 transition-opacity duration-200","flex flex-col justify-end p-3"),children:[e.jsx("p",{className:"text-white text-sm line-clamp-2 mb-2",children:t.prompt}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-white/70 text-xs",children:I(t.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:p=>N(t,p),className:c("p-1.5 rounded-lg","bg-white/20 hover:bg-white/30","transition-colors"),title:i("imageGallery.download"),children:e.jsx(M,{className:"h-4 w-4 text-white"})}),e.jsx("button",{onClick:p=>z(t.id,p),disabled:y===t.id,className:c("p-1.5 rounded-lg","bg-white/20 hover:bg-red-500/80","transition-colors",y===t.id&&"opacity-50 cursor-not-allowed"),title:i("imageGallery.delete"),children:y===t.id?e.jsx(D,{className:"h-4 w-4 text-white animate-spin"}):e.jsx(Q,{className:"h-4 w-4 text-white"})})]})]})]})]},t.id))}),h.length<o&&e.jsx("div",{className:"flex justify-center mt-8",children:e.jsx("button",{onClick:P,disabled:m,className:c("px-6 py-2.5 rounded-xl font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]","text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-4 w-4 animate-spin"}),i("common.loading")]}):i("imageGallery.loadMore",{current:h.length,total:o})})}),f&&e.jsx(J,{image:f,onClose:()=>G(null),onDelete:t=>{z(t,{stopPropagation:()=>{}})},onDownload:t=>{N(t,{stopPropagation:()=>{}})}})]})},V=({isOpen:r,onClose:i,onImageGenerated:h})=>{const{t:s}=L(),[o,b]=l.useState([]),[u,n]=l.useState(""),[m,w]=l.useState(""),[f,G]=l.useState(""),[y,S]=l.useState("1024x1024"),[C,v]=l.useState("standard"),[P,z]=l.useState(!1),[N,I]=l.useState(null),[t,p]=l.useState(["512x512","768x768","1024x1024"]),[d,k]=l.useState(["standard","high"]);l.useEffect(()=>{r&&(async()=>{try{const x=await E.getPlugins();if(x.success&&x.data&&(b(x.data),x.data.length>0)){const g=x.data[0];n(g.id),g.models.length>0&&w(g.models[0]),g.config?.sizes&&(p(g.config.sizes),S(g.config.default_size||g.config.sizes[0]||"1024x1024")),g.config?.qualities&&(k(g.config.qualities),v(g.config.default_quality||g.config.qualities[0]||"standard"))}}catch(x){console.error("Failed to load image generation plugins:",x)}})()},[r]),l.useEffect(()=>{const a=o.find(x=>x.id===u);a&&(a.models.length>0&&!a.models.includes(m)&&w(a.models[0]),a.config?.sizes&&(p(a.config.sizes),a.config.sizes.includes(y)||S(a.config.default_size||a.config.sizes[0])),a.config?.qualities&&(k(a.config.qualities),a.config.qualities.includes(C)||v(a.config.default_quality||a.config.qualities[0])))},[u,o,m,y,C]);const q=async()=>{if(!m||!f.trim()){j.error(s("imageGeneration.enterPrompt"));return}z(!0),I(null);try{const a=await E.generate({model:m,prompt:f.trim(),size:y,quality:C});if(a.success&&a.data?.images&&a.data.images.length>0){const x=a.data.images[0];let g=null;x.b64_json?g=`data:image/png;base64,${x.b64_json}`:x.url&&(g=x.url),g&&(j.success(s("imageGeneration.success")),h?(h(g,f.trim(),m),G(""),I(null),i()):I(g))}else j.error(s("imageGeneration.failed"))}catch(a){console.error("Image generation failed:",a);const x=a instanceof Error?a.message:s("imageGeneration.failed");j.error(x)}finally{z(!1)}},$=()=>{if(!N)return;const a=document.createElement("a");a.href=N,a.download=`generated-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a)};if(!r)return null;const K=o.find(a=>a.id===u);return A.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:i}),e.jsxs("div",{className:c("relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]","rounded-2xl shadow-2xl","w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col"),onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:s("imageGeneration.title")})]}),e.jsx("button",{onClick:i,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors",children:e.jsx(T,{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:o.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 ophelia:text-[#737373]",children:s("imageGeneration.noModels")}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:s("imageGeneration.configurePlugin")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("settings.plugins.title")}),e.jsx("select",{value:u,onChange:a=>n(a.target.value),className:c("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.id,children:a.name},a.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.model")}),e.jsx("select",{value:m,onChange:a=>w(a.target.value),className:c("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:K?.models.map(a=>e.jsx("option",{value:a,children:a},a))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.size")}),e.jsx("select",{value:y,onChange:a=>S(a.target.value),className:c("w-full px-3 py-2 rounded-lg text-sm","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","focus:outline-none focus:ring-2 focus:ring-primary-500/20"),children:t.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.quality")}),e.jsx("select",{value:C,onChange:a=>v(a.target.value),className:c("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:d.map(a=>e.jsx("option",{value:a,children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1",children:s("imageGeneration.prompt")}),e.jsx("textarea",{value:f,onChange:a=>G(a.target.value),placeholder:s("imageGeneration.promptPlaceholder"),rows:3,className:c("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")})]}),N&&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:N,alt:"Generated",className:"w-full h-auto"}),e.jsx("button",{onClick:$,className:c("absolute bottom-3 right-3 p-2 rounded-lg","bg-white/90 dark:bg-dark-100/90 ophelia:bg-[#0a0a0a]/90","hover:bg-white dark:hover:bg-dark-100 ophelia:hover:bg-[#0a0a0a]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","transition-colors"),title:s("imageGallery.download"),children:e.jsx(M,{className:"h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]"})})]})]})}),o.length>0&&e.jsx("div",{className:"p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]",children:e.jsx(_,{onClick:q,disabled:P||!f.trim()||!m,className:c("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:P?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(D,{className:"h-4 w-4 animate-spin"}),s("imageGeneration.generating")]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(W,{className:"h-4 w-4"}),s("imageGeneration.generate")]})})})]})]}),document.body)},re=()=>{const{t:r}=L(),[i,h]=l.useState(null),[s,o]=l.useState(!1),[b,u]=l.useState(0),n=l.useCallback(()=>{u(m=>m+1)},[]);return e.jsxs("div",{className:"h-full overflow-auto",children:[e.jsxs("div",{className:"max-w-7xl mx-auto p-6",children:[e.jsxs("div",{className:"text-center max-w-md mx-auto mb-8",children:[e.jsx("h2",{className:"libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa] mb-3",style:{fontWeight:300,letterSpacing:"0.01em"},children:r("sidebar.navigation.imagine")}),e.jsxs("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:[r("gallery.subtitle"),i!==null&&i>0&&e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:[" ","· ",r("gallery.imageCount",{count:i})]})]}),e.jsxs(_,{onClick:()=>o(!0),className:c("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(X,{className:"h-4 w-4 mr-2"}),r("gallery.generate")]})]}),e.jsx(O,{onImageCountChange:h},b)]}),e.jsx(V,{isOpen:s,onClose:()=>o(!1),onImageGenerated:n})]})};export{re as GalleryPage,re as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-vendor-DeGQOJEA.js";import{r as l,e as T}from"./router-vendor-CYqbjR9t.js";import{a as fe,c as s,B as c,o as x}from"../assets/index-BNamR47C.js";import{a1 as p,ad as Oe,ae as C,af as Xe,ag as he,g as q,e as H,f as I,ah as pe,X as z,E as Qe,ai as Ye,aj as ea,C as aa,ak as ra,Z as sa,l as ta,al as la,am as da,b as oa,J as X,T as ia,u as na,an as be,ao as ue,ap as ca,z as d}from"./ui-vendor-C0aUE8gv.js";import"./utils-vendor-COrKO_vV.js";const xa=()=>{const{t:r}=fe(),[g,ye]=l.useState([]),[m,ke]=l.useState([]),[V,je]=l.useState([]),[G,Q]=l.useState(!1),[$,ve]=l.useState("all"),[E,Ne]=l.useState(""),[we,Y]=l.useState(!1),[j,D]=l.useState(""),[u,v]=l.useState(!1),[n,f]=l.useState(null),[ee,N]=l.useState(null),[o,Me]=l.useState(null),[Se,Ce]=l.useState(""),[ze,U]=l.useState(!1),[Ee,ae]=l.useState(!1),[De,w]=l.useState(!1),[L,W]=l.useState(""),[M,re]=l.useState(""),[Z,se]=l.useState(!1),[Le,P]=l.useState(!1),[S,te]=l.useState(""),[B,le]=l.useState(""),[J,de]=l.useState(!1),[Pe,K]=l.useState(!1),[_,Be]=l.useState(""),[R,_e]=l.useState(""),[A,oe]=l.useState(null),[O,ie]=l.useState(!1),[ne,Re]=l.useState(null),[ce,F]=l.useState(null),[h,Ae]=l.useState(new Set(["pull","local"])),y=a=>{Ae(t=>{const i=new Set(t);return i.has(a)?i.delete(a):i.add(a),i})},k=async()=>{Y(!0);try{const[a,t,i,Ke]=await Promise.all([x.getModels(),x.listRunningModels(),x.getVersion(),x.checkHealth()]);a.success&&ye(a.data||[]),t.success&&ke(Array.isArray(t.data)?t.data:[]),i.success&&i.data&&Re(i.data.version),F(Ke.success)}catch(a){const t=a instanceof Error?a.message:String(a);d.error(r("modelManager.pull.failed")+": "+t),F(!1)}finally{Y(!1)}},xe=async()=>{Q(!0);try{const a=await x.getLibraryModels();a.success&&a.data&&je(a.data)}catch(a){console.error("Failed to load library models:",a)}finally{Q(!1)}};l.useEffect(()=>{k(),xe()},[]);const ge=async()=>{if(!j.trim()){d.error(r("modelManager.pull.enterName"));return}v(!0),f({status:"starting"});try{const a=x.pullModelStream(j.trim(),t=>{f(t)},()=>{f(null),v(!1),N(null),d.success(r("modelManager.pull.success",{name:j})),D(""),k()},t=>{f(null),v(!1),N(null),d.error(r("modelManager.pull.failed")+": "+t)});N(()=>a)}catch(a){const t=a instanceof Error?a.message:String(a);d.error(r("modelManager.pull.failed")+": "+t),f(null),v(!1),N(null)}},Fe=()=>{ee&&(ee(),N(null),v(!1),f(null),d.success(r("modelManager.pull.cancelled")))},Te=async a=>{if(confirm(r("modelManager.local.deleteConfirm",{name:a})))try{await x.deleteModel(a),d.success(r("modelManager.local.deleteSuccess",{name:a})),await k()}catch(t){const i=t instanceof Error?t.message:String(t);d.error(r("modelManager.local.deleteFailed")+": "+i)}},qe=async a=>{ae(!0),Ce(a),U(!0);try{const t=await x.showModel(a,!0);t.success&&t.data?Me(t.data):d.error(r("modelManager.modals.details.noDetails"))}catch(t){const i=t instanceof Error?t.message:String(t);d.error(r("modelManager.modals.details.noDetails")+": "+i)}finally{ae(!1)}},He=async()=>{if(!L.trim()||!M.trim()){d.error(r("modelManager.modals.copy.enterBoth"));return}se(!0);try{await x.copyModel(L.trim(),M.trim()),d.success(r("modelManager.modals.copy.success",{name:M})),w(!1),W(""),re(""),await k()}catch(a){const t=a instanceof Error?a.message:String(a);d.error(r("modelManager.modals.copy.failed")+": "+t)}finally{se(!1)}},Ie=async()=>{if(!S.trim()||!B.trim()){d.error(r("modelManager.modals.create.enterBoth"));return}de(!0);try{await x.createModel({model:S.trim(),modelfile:B.trim()}),d.success(r("modelManager.modals.create.success",{name:S})),P(!1),te(""),le(""),await k()}catch(a){const t=a instanceof Error?a.message:String(a);d.error(r("modelManager.modals.create.failed")+": "+t)}finally{de(!1)}},Ve=async()=>{if(!_.trim()||!R.trim()){d.error(r("modelManager.modals.embeddings.enterBoth"));return}ie(!0),oe(null);try{const a=await x.generateEmbeddings({model:_.trim(),input:R.trim()});if(a.success&&a.data){const t=a.data.embeddings?.[0]||[];oe(t),d.success(r("modelManager.modals.embeddings.success",{count:t.length}))}}catch(a){const t=a instanceof Error?a.message:String(a);d.error(r("modelManager.modals.embeddings.failed")+": "+t)}finally{ie(!1)}},b=a=>{const t=a/1073741824;return t>=1?`${t.toFixed(2)} GB`:`${(a/(1024*1024)).toFixed(1)} MB`},Ge=a=>Array.isArray(m)&&m.some(t=>t.name===a),$e=()=>g.reduce((a,t)=>a+t.size,0),Ue=()=>m.reduce((a,t)=>a+(t.size_vram||0),0),We=a=>g.some(t=>t.name===a||t.name.startsWith(a+":")),me=V.filter(a=>{const t=$==="all"||a.category===$,i=!E||a.name.toLowerCase().includes(E.toLowerCase())||a.description.toLowerCase().includes(E.toLowerCase());return t&&i}),Ze=["all",...new Set(V.map(a=>a.category))],Je=[{name:"deepseek-r1",category:"reasoning",size:"7B"},{name:"llama3.2",category:"general",size:"3B"},{name:"gemma3",category:"general",size:"4B"},{name:"qwen2.5",category:"general",size:"7B"},{name:"mistral",category:"general",size:"7B"},{name:"codellama",category:"coding",size:"7B"},{name:"nomic-embed-text",category:"embedding",size:"137M"},{name:"llava",category:"vision",size:"7B"},{name:"phi3",category:"general",size:"3.8B"},{name:"gemma2",category:"general",size:"9B"}];return we?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsxs("div",{className:"flex items-center gap-3 text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]",children:[e.jsx(p,{className:"h-5 w-5 animate-spin"}),r("modelManager.loading")]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:s("rounded-xl p-4 border","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:s("w-2.5 h-2.5 rounded-full",ce?"bg-green-500 ophelia:bg-[#4ade80]":"bg-red-500 ophelia:bg-[#f87171]")}),e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]",children:r(ce?"modelManager.systemStatus.online":"modelManager.systemStatus.offline")})]}),ne&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[e.jsx(Oe,{className:"h-4 w-4"}),e.jsxs("span",{children:["v",ne]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[e.jsx(C,{className:"h-4 w-4"}),e.jsxs("span",{children:[g.length," ",g.length!==1?r("modelManager.systemStatus.models_plural"):r("modelManager.systemStatus.models")]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]",children:[e.jsx(Xe,{className:"h-4 w-4"}),e.jsx("span",{children:b($e())})]}),m.length>0&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400 ophelia:text-[#4ade80]",children:[e.jsx(he,{className:"h-4 w-4"}),e.jsxs("span",{children:[m.length," ",r("modelManager.systemStatus.running")," (",b(Ue())," ",r("modelManager.systemStatus.vram"),")"]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(c,{onClick:k,variant:"outline",size:"sm",className:s("gap-1.5","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(p,{className:"h-3.5 w-3.5"}),r("common.refresh")]})})]})}),e.jsxs("div",{className:s("rounded-xl border overflow-hidden","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("button",{onClick:()=>y("pull"),className:s("w-full flex items-center justify-between p-4","hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#121212]","transition-colors"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:s("p-2 rounded-lg","bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20"),children:e.jsx(q,{className:"h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:r("modelManager.sections.pull")})]}),h.has("pull")?e.jsx(H,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"}):e.jsx(I,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})]}),h.has("pull")&&e.jsxs("div",{className:"p-4 pt-0 space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(pe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("input",{type:"text",value:j,onChange:a=>D(a.target.value),placeholder:r("modelManager.pull.placeholder"),className:s("w-full pl-10 pr-4 py-2.5 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-dark-700 ophelia:text-[#fafafa]","placeholder-gray-500 dark:placeholder-gray-400 ophelia:placeholder-[#525252]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20","focus:border-primary-500 ophelia:focus:border-[#9333ea]"),disabled:u,onKeyDown:a=>a.key==="Enter"&&!u&&ge()})]}),u?e.jsxs(c,{onClick:Fe,variant:"outline",className:s("px-4 py-2.5 gap-2","text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300","ophelia:text-[#f87171] ophelia:hover:text-[#fca5a5]","ophelia:border-[#262626] ophelia:hover:bg-[#1a1a1a]"),children:[e.jsx(z,{className:"h-4 w-4"}),r("modelManager.pull.cancel")]}):e.jsxs(c,{onClick:ge,disabled:!j.trim(),className:s("px-4 py-2.5 gap-2","ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white"),children:[e.jsx(q,{className:"h-4 w-4"}),r("modelManager.pull.button")]})]}),u&&n&&e.jsxs("div",{className:s("p-4 rounded-lg border","bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-dark-700 ophelia:text-[#e5e5e5]",children:n.status==="starting"?r("modelManager.progress.starting"):n.status==="pulling"?r("modelManager.progress.pulling"):n.status==="verifying sha256"?r("modelManager.progress.verifying"):n.status==="writing manifest"?r("modelManager.progress.writing"):n.status==="removing any unused layers"?r("modelManager.progress.cleaning"):n.status}),n.percent!==void 0&&e.jsxs("span",{className:"text-sm font-mono text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]",children:[n.percent,"%"]})]}),n.percent!==void 0&&e.jsx("div",{className:"w-full bg-gray-200 dark:bg-dark-400 ophelia:bg-[#262626] rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:s("h-2 rounded-full transition-all duration-300","bg-primary-500 dark:bg-primary-400 ophelia:bg-[#9333ea]"),style:{width:`${n.percent}%`}})}),n.total&&n.completed&&e.jsxs("div",{className:"mt-2 text-xs text-gray-600 dark:text-dark-600 ophelia:text-[#737373]",children:[b(n.completed)," /"," ",b(n.total)]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-2",children:r("modelManager.pull.popular")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Je.map(a=>e.jsxs("button",{onClick:()=>D(a.name),disabled:u,className:s("px-3 py-1.5 rounded-full text-xs font-medium transition-colors","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3]","hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]","border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","disabled:opacity-50 disabled:cursor-not-allowed"),children:[a.name,e.jsx("span",{className:"ml-1 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]",children:a.size})]},a.name))})]}),e.jsxs("a",{href:"https://ollama.com/library",target:"_blank",rel:"noopener noreferrer",className:s("inline-flex items-center gap-1.5 text-xs","text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]","hover:underline"),children:[e.jsx(Qe,{className:"h-3 w-3"}),r("modelManager.pull.browseAll")]})]})]}),e.jsxs("div",{className:s("rounded-xl border overflow-hidden","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("button",{onClick:()=>y("library"),className:s("w-full flex items-center justify-between p-4","hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#121212]","transition-colors"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:s("p-2 rounded-lg","bg-cyan-100 dark:bg-cyan-900/30 ophelia:bg-[#06b6d4]/20"),children:e.jsx(Ye,{className:"h-5 w-5 text-cyan-600 dark:text-cyan-400 ophelia:text-[#22d3ee]"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:r("modelManager.sections.library")}),e.jsxs("span",{className:s("px-2 py-0.5 rounded-full text-xs font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]"),children:[V.length," ",r("modelManager.library.available")]})]}),h.has("library")?e.jsx(H,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"}):e.jsx(I,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})]}),h.has("library")&&e.jsxs("div",{className:"p-4 pt-0 space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(pe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]"}),e.jsx("input",{type:"text",value:E,onChange:a=>Ne(a.target.value),placeholder:r("modelManager.library.search"),className:s("w-full pl-10 pr-4 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-dark-700 ophelia:text-[#fafafa]","placeholder-gray-500 dark:placeholder-gray-400 ophelia:placeholder-[#525252]","focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20","focus:border-primary-500 ophelia:focus:border-[#9333ea]")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ea,{className:"h-4 w-4 text-gray-400 ophelia:text-[#525252]"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Ze.map(a=>e.jsx("button",{onClick:()=>ve(a),className:s("px-2.5 py-1 rounded-full text-xs font-medium transition-colors",$===a?"bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]":"bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626]"),children:a.charAt(0).toUpperCase()+a.slice(1)},a))})]})]}),G?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(p,{className:"h-5 w-5 animate-spin text-gray-400 ophelia:text-[#737373]"})}):me.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500 ophelia:text-[#737373]",children:r("modelManager.library.noResults")}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:me.map(a=>{const t=We(a.name);return e.jsxs("div",{className:s("p-4 rounded-lg border transition-all","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]",t?"border-green-200 dark:border-green-800/50 ophelia:border-[#22c55e]/30":"border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]","hover:shadow-md hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#262626]"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsx("h4",{className:"font-medium text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:a.name}),t&&e.jsxs("span",{className:s("flex items-center gap-1 px-1.5 py-0.5 rounded text-xs","bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/20","text-green-700 dark:text-green-400 ophelia:text-[#4ade80]"),children:[e.jsx(aa,{className:"h-3 w-3"}),r("modelManager.library.installed")]})]}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] mb-3 line-clamp-2",children:a.description}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[a.sizes.slice(0,4).map(i=>e.jsx("span",{className:s("px-1.5 py-0.5 rounded text-xs","bg-gray-200 dark:bg-dark-300 ophelia:bg-[#262626]","text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]"),children:i},i)),a.sizes.length>4&&e.jsx("span",{className:"text-xs text-gray-400 ophelia:text-[#737373]",children:r("modelManager.library.more",{count:a.sizes.length-4})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 ophelia:text-[#737373]",children:[a.pulls&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(q,{className:"h-3 w-3"}),a.pulls]}),e.jsx("span",{className:s("px-1.5 py-0.5 rounded capitalize","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]"),children:a.category})]}),e.jsxs(c,{onClick:()=>{D(a.name),y("pull"),h.has("pull")||y("pull")},variant:"outline",size:"sm",disabled:u,className:s("gap-1 text-xs","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(q,{className:"h-3 w-3"}),r("modelManager.pull.button")]})]})]},a.name)})}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(c,{onClick:xe,variant:"outline",size:"sm",disabled:G,className:s("gap-1.5","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(p,{className:s("h-3.5 w-3.5",G&&"animate-spin")}),r("modelManager.library.refresh")]})})]})]}),Array.isArray(m)&&m.length>0&&e.jsxs("div",{className:s("rounded-xl p-4 border","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:s("p-2 rounded-lg","bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/20"),children:e.jsx(he,{className:"h-5 w-5 text-green-600 dark:text-green-400 ophelia:text-[#4ade80]"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:r("modelManager.sections.running")}),e.jsxs("span",{className:s("ml-auto px-2 py-0.5 rounded-full text-xs font-medium","bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/20","text-green-700 dark:text-green-400 ophelia:text-[#4ade80]"),children:[m.length," ",r("modelManager.systemStatus.running")]})]}),e.jsx("div",{className:"space-y-2",children:m.map(a=>e.jsxs("div",{className:s("flex items-center justify-between p-4 rounded-lg border","bg-green-50 dark:bg-green-900/10 ophelia:bg-[#22c55e]/5","border-green-200 dark:border-green-800/50 ophelia:border-[#22c55e]/20"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:s("w-2 h-2 rounded-full animate-pulse","bg-green-500 ophelia:bg-[#4ade80]")}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-green-800 dark:text-green-400 ophelia:text-[#4ade80]",children:a.name}),e.jsxs("div",{className:"flex items-center gap-3 text-sm text-green-600 dark:text-green-500 ophelia:text-[#22c55e]/80",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ra,{className:"h-3 w-3"}),r("modelManager.systemStatus.vram"),":"," ",b(a.size_vram||0)]}),a.size&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(C,{className:"h-3 w-3"}),r("models.size"),": ",b(a.size)]})]})]})]}),e.jsxs("div",{className:s("flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium","bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/10","text-green-700 dark:text-green-400 ophelia:text-[#4ade80]"),children:[e.jsx(sa,{className:"h-3 w-3"}),r("modelManager.local.running")]})]},a.name))})]}),e.jsxs("div",{className:s("rounded-xl border overflow-hidden","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("button",{onClick:()=>y("local"),className:s("w-full flex items-center justify-between p-4","hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#121212]","transition-colors"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:s("p-2 rounded-lg","bg-blue-100 dark:bg-blue-900/30 ophelia:bg-[#a855f7]/20"),children:e.jsx(C,{className:"h-5 w-5 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:r("modelManager.sections.local")}),e.jsxs("span",{className:s("px-2 py-0.5 rounded-full text-xs font-medium","bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]","text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]"),children:[g.length," ",r("modelManager.local.installed")]})]}),h.has("local")?e.jsx(H,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"}):e.jsx(I,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})]}),h.has("local")&&e.jsx("div",{className:"p-4 pt-0",children:g.length===0?e.jsxs("div",{className:s("text-center py-12 rounded-lg border-2 border-dashed","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]"),children:[e.jsx(C,{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-600 dark:text-dark-600 ophelia:text-[#737373] mb-2",children:r("modelManager.local.noModels")}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 ophelia:text-[#525252]",children:r("modelManager.local.pullToStart")})]}):e.jsx("div",{className:"space-y-3",children:g.map(a=>e.jsx("div",{className:s("p-4 rounded-lg border transition-colors","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]","hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]"),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h4",{className:"font-medium text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:a.name}),Ge(a.name)&&e.jsxs("span",{className:s("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium","bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/20","text-green-700 dark:text-green-400 ophelia:text-[#4ade80]"),children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 ophelia:bg-[#4ade80] animate-pulse"}),r("modelManager.local.running")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-sm text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] mt-2",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(C,{className:"h-3.5 w-3.5"}),b(a.size)]}),a.details?.parameter_size&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ta,{className:"h-3.5 w-3.5"}),a.details.parameter_size]}),a.details?.quantization_level&&e.jsx("span",{className:s("px-1.5 py-0.5 rounded text-xs","bg-gray-200 dark:bg-dark-300 ophelia:bg-[#262626]","text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]"),children:a.details.quantization_level}),a.details?.family&&e.jsx("span",{className:"text-gray-500 dark:text-gray-500 ophelia:text-[#737373]",children:a.details.family})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-400 dark:text-dark-500 ophelia:text-[#525252] mt-2",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(la,{className:"h-3 w-3"}),new Date(a.modified_at).toLocaleDateString()]}),e.jsxs("span",{className:"flex items-center gap-1 font-mono truncate max-w-[200px]",title:a.digest,children:[e.jsx(da,{className:"h-3 w-3"}),a.digest.slice(0,12),"..."]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(c,{onClick:()=>qe(a.name),variant:"outline",size:"sm",className:s("gap-1.5","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(oa,{className:"h-3.5 w-3.5"}),r("modelManager.local.info")]}),e.jsxs(c,{onClick:()=>{W(a.name),w(!0)},variant:"outline",size:"sm",className:s("gap-1.5","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(X,{className:"h-3.5 w-3.5"}),r("modelManager.local.copy")]}),e.jsxs(c,{onClick:()=>Te(a.name),variant:"outline",size:"sm",className:s("gap-1.5","text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300","ophelia:text-[#f87171] ophelia:hover:text-[#fca5a5]","ophelia:border-[#262626] ophelia:hover:bg-[#1a1a1a]"),children:[e.jsx(ia,{className:"h-3.5 w-3.5"}),r("modelManager.local.delete")]})]})]})},a.name))})})]}),e.jsxs("div",{className:s("rounded-xl border overflow-hidden","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("button",{onClick:()=>y("advanced"),className:s("w-full flex items-center justify-between p-4","hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#121212]","transition-colors"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:s("p-2 rounded-lg","bg-amber-100 dark:bg-amber-900/30 ophelia:bg-[#f59e0b]/20"),children:e.jsx(na,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 ophelia:text-[#fbbf24]"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]",children:r("modelManager.sections.advanced")})]}),h.has("advanced")?e.jsx(H,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"}):e.jsx(I,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})]}),h.has("advanced")&&e.jsx("div",{className:"p-4 pt-0",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsxs(c,{onClick:()=>P(!0),variant:"outline",className:s("w-full gap-2 justify-start h-auto py-3 px-4","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(be,{className:"h-5 w-5 text-purple-500 ophelia:text-[#a855f7]"}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:r("modelManager.advanced.createModel")}),e.jsx("div",{className:"text-xs opacity-70",children:r("modelManager.advanced.fromModelfile")})]})]}),e.jsxs(c,{onClick:()=>w(!0),variant:"outline",className:s("w-full gap-2 justify-start h-auto py-3 px-4","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(X,{className:"h-5 w-5 text-blue-500 ophelia:text-[#60a5fa]"}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:r("modelManager.advanced.copyModel")}),e.jsx("div",{className:"text-xs opacity-70",children:r("modelManager.advanced.duplicateExisting")})]})]}),e.jsxs(c,{onClick:()=>K(!0),variant:"outline",className:s("w-full gap-2 justify-start h-auto py-3 px-4","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(ue,{className:"h-5 w-5 text-green-500 ophelia:text-[#4ade80]"}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:r("modelManager.advanced.testEmbeddings")}),e.jsx("div",{className:"text-xs opacity-70",children:r("modelManager.advanced.generateVectors")})]})]}),e.jsxs(c,{onClick:async()=>{try{(await x.checkHealth()).success&&(F(!0),d.success(r("modelManager.advanced.healthy")))}catch{F(!1),d.error(r("modelManager.systemStatus.offline"))}},variant:"outline",className:s("w-full gap-2 justify-start h-auto py-3 px-4","ophelia:border-[#262626] ophelia:text-[#a3a3a3]","ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]"),children:[e.jsx(ca,{className:"h-5 w-5 text-rose-500 ophelia:text-[#fb7185]"}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:r("modelManager.advanced.healthCheck")}),e.jsx("div",{className:"text-xs opacity-70",children:r("modelManager.advanced.testConnection")})]})]})]})})]}),ze&&T.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>U(!1)}),e.jsxs("div",{className:s("relative w-full max-w-2xl max-h-[85vh] overflow-hidden rounded-xl border shadow-2xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("div",{className:s("flex items-center justify-between p-4 border-b","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:[r("modelManager.modals.details.title"),": ",Se]}),e.jsx("button",{onClick:()=>U(!1),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:e.jsx(z,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})})]}),e.jsx("div",{className:"overflow-y-auto max-h-[calc(85vh-60px)] p-4 space-y-4",children:Ee?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(p,{className:"h-6 w-6 animate-spin text-gray-400 ophelia:text-[#737373]"})}):o?e.jsxs(e.Fragment,{children:[o.details&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.info")}),e.jsx("div",{className:s("p-3 rounded-lg text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]"),children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.details.family&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-gray-500 ophelia:text-[#737373]",children:[r("modelManager.modals.details.family"),":"]})," ",e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:o.details.family})]}),o.details.parameter_size&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-gray-500 ophelia:text-[#737373]",children:[r("modelManager.modals.details.parameters"),":"]})," ",e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:o.details.parameter_size})]}),o.details.quantization_level&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-gray-500 ophelia:text-[#737373]",children:[r("modelManager.modals.details.quantization"),":"]})," ",e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:o.details.quantization_level})]}),o.details.format&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-gray-500 ophelia:text-[#737373]",children:[r("modelManager.modals.details.format"),":"]})," ",e.jsx("span",{className:"text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:o.details.format})]})]})})]}),o.system&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.systemPrompt")}),e.jsx("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:o.system})]}),o.template&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.template")}),e.jsx("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto max-h-40","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:o.template})]}),o.parameters&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.parameters")}),e.jsx("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:o.parameters})]}),o.license&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.license")}),e.jsx("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto max-h-32","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:o.license})]}),o.modelfile&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2",children:r("modelManager.modals.details.modelfile")}),e.jsx("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto max-h-60","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:o.modelfile})]})]}):e.jsx("p",{className:"text-center text-gray-500 ophelia:text-[#737373]",children:r("modelManager.modals.details.noDetails")})})]})]}),document.body),De&&T.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>w(!1)}),e.jsxs("div",{className:s("relative w-full max-w-md rounded-xl border shadow-2xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("div",{className:s("flex items-center justify-between p-4 border-b","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r("modelManager.modals.copy.title")}),e.jsx("button",{onClick:()=>w(!1),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:e.jsx(z,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})})]}),e.jsxs("div",{className:"p-4 space-y-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:r("modelManager.modals.copy.source")}),e.jsxs("select",{value:L,onChange:a=>W(a.target.value),className:s("w-full px-3 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]"),children:[e.jsx("option",{value:"",children:r("modelManager.modals.copy.selectModel")}),g.map(a=>e.jsx("option",{value:a.name,children:a.name},a.name))]})]}),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:r("modelManager.modals.copy.newName")}),e.jsx("input",{type:"text",value:M,onChange:a=>re(a.target.value),placeholder:r("modelManager.modals.copy.placeholder"),className:s("w-full px-3 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#525252]")})]}),e.jsxs(c,{onClick:He,disabled:!L.trim()||!M.trim()||Z,className:s("w-full gap-2","ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white"),children:[Z?e.jsx(p,{className:"h-4 w-4 animate-spin"}):e.jsx(X,{className:"h-4 w-4"}),r(Z?"modelManager.modals.copy.copying":"modelManager.modals.copy.button")]})]})]})]}),document.body),Le&&T.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>P(!1)}),e.jsxs("div",{className:s("relative w-full max-w-lg rounded-xl border shadow-2xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("div",{className:s("flex items-center justify-between p-4 border-b","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r("modelManager.modals.create.title")}),e.jsx("button",{onClick:()=>P(!1),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:e.jsx(z,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})})]}),e.jsxs("div",{className:"p-4 space-y-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:r("modelManager.modals.create.name")}),e.jsx("input",{type:"text",value:S,onChange:a=>te(a.target.value),placeholder:r("modelManager.modals.create.namePlaceholder"),className:s("w-full px-3 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#525252]")})]}),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:r("modelManager.modals.create.modelfile")}),e.jsx("textarea",{value:B,onChange:a=>le(a.target.value),placeholder:r("modelManager.modals.create.modelfilePlaceholder"),rows:8,className:s("w-full px-3 py-2 rounded-lg border text-sm font-mono","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#525252]","resize-none")}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 ophelia:text-[#737373]",children:["See"," ",e.jsx("a",{href:"https://github.com/ollama/ollama/blob/main/docs/modelfile.md",target:"_blank",rel:"noopener noreferrer",className:"text-primary-600 ophelia:text-[#a855f7] hover:underline",children:r("modelManager.modals.create.docs")})," ",r("modelManager.modals.create.docsLink")]})]}),e.jsxs(c,{onClick:Ie,disabled:!S.trim()||!B.trim()||J,className:s("w-full gap-2","ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white"),children:[J?e.jsx(p,{className:"h-4 w-4 animate-spin"}):e.jsx(be,{className:"h-4 w-4"}),r(J?"modelManager.modals.create.creating":"modelManager.modals.create.button")]})]})]})]}),document.body),Pe&&T.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>K(!1)}),e.jsxs("div",{className:s("relative w-full max-w-lg rounded-xl border shadow-2xl","bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsxs("div",{className:s("flex items-center justify-between p-4 border-b","border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]"),children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]",children:r("modelManager.modals.embeddings.title")}),e.jsx("button",{onClick:()=>K(!1),className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]",children:e.jsx(z,{className:"h-5 w-5 text-gray-500 ophelia:text-[#737373]"})})]}),e.jsxs("div",{className:"p-4 space-y-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:r("modelManager.modals.embeddings.model")}),e.jsxs("select",{value:_,onChange:a=>Be(a.target.value),className:s("w-full px-3 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]"),children:[e.jsx("option",{value:"",children:r("modelManager.modals.embeddings.selectModel")}),g.map(a=>e.jsx("option",{value:a.name,children:a.name},a.name))]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 ophelia:text-[#737373]",children:r("modelManager.modals.embeddings.recommended")})]}),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:r("modelManager.modals.embeddings.input")}),e.jsx("textarea",{value:R,onChange:a=>_e(a.target.value),placeholder:r("modelManager.modals.embeddings.placeholder"),rows:3,className:s("w-full px-3 py-2 rounded-lg border text-sm","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","border-gray-200 dark:border-dark-300 ophelia:border-[#262626]","text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]","placeholder-gray-500 ophelia:placeholder-[#525252]","resize-none")})]}),e.jsxs(c,{onClick:Ve,disabled:!_.trim()||!R.trim()||O,className:s("w-full gap-2","ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white"),children:[O?e.jsx(p,{className:"h-4 w-4 animate-spin"}):e.jsx(ue,{className:"h-4 w-4"}),r(O?"modelManager.modals.embeddings.generating":"modelManager.modals.embeddings.button")]}),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:r("modelManager.modals.embeddings.result",{count:A.length})}),e.jsxs("pre",{className:s("p-3 rounded-lg text-xs overflow-x-auto max-h-32","bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]","text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]"),children:["[",A.slice(0,10).join(", "),A.length>10&&", ..."," ]"]})]})]})]})]}),document.body)]})},ua=()=>{const{t:r}=fe();return e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("div",{className:"max-w-6xl mx-auto p-6",children:[e.jsxs("div",{className:"text-center max-w-md mx-auto mb-8",children:[e.jsx("h2",{className:"libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa] mb-3",style:{fontWeight:300,letterSpacing:"0.01em"},children:r("models.title")}),e.jsx("p",{className:"text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed",children:r("models.subtitle")})]}),e.jsx(xa,{})]})})};export{ua as ModelsPage,ua as default};